From 5c13278a4bbab46f52feeab79ac3af622f06d2be Mon Sep 17 00:00:00 2001 From: Glen Whitney Date: Sun, 17 Sep 2023 19:02:31 -0700 Subject: [PATCH] fix: Expand the world info viewer so you can see content Also update to latest x_ite.d.ts Resolves #22. --- etc/deps/x_ite/x_ite.d.ts | 93 ++++++++++++++++++++++++++++++++------- src/giveAwrl.civet | 19 +++++++- 2 files changed, 96 insertions(+), 16 deletions(-) diff --git a/etc/deps/x_ite/x_ite.d.ts b/etc/deps/x_ite/x_ite.d.ts index e132312..78bb5cc 100644 --- a/etc/deps/x_ite/x_ite.d.ts +++ b/etc/deps/x_ite/x_ite.d.ts @@ -6,10 +6,10 @@ declare module 'https://create3000.github.io/code/x_ite/latest/x_ite.mjs' { export default X3D; export interface X3D { (callback?: () => void, fallback?: (error: Error) => void): Promise; - createBrowser(): HTMLElement; - getBrowser(via?: string | HTMLElement): X3DBrowser; + createBrowser(): X3DCanvasElement; + getBrowser(via?: string | X3DCanvasElement): X3DBrowser; noConflict(): X3D; - X3DConstants: X3DConstant; + X3DConstants: X3DConstants; SFBool(arg: unknown): boolean; // NB. in all of the following `typeof Class` is an expression that // extracts the type of the constructor for Class. @@ -65,6 +65,10 @@ export interface X3D { MFVec4f: typeof X3DArrayField; } +export interface X3DCanvasElement extends HTMLElement { + readonly browser: string; +} + type JSONValue = | string | number @@ -156,6 +160,7 @@ export interface X3DBrowser { op: T, value: BrowserOption[T]): void; getRenderingProperty( prop: T): RenderingProperty[T]; + getContextMenu(): XiteContextMenu; addBrowserCallback(key: unknown, cb?: BrowserCallback): void; addBrowserCallback( key: unknown, event: number, // A Browser Event Constant @@ -194,16 +199,74 @@ type MinimalArray = {[index: number]: T, length: number} type ComponentInfoArray = MinimalArray; interface ComponentInfo { readonly name: string; - readonly level?: number; + readonly level: number; readonly title: string; readonly providerURL: string; } type ProfileInfoArray = MinimalArray; -interface ProfileInfo extends ComponentInfo { +interface ProfileInfo { + readonly name: string; + readonly title: string; + readonly providerURL: string; readonly components: ComponentInfoArray } +type JQueryCtxMenuOpts = { + selector: string, + items: UserMenuItems, + appendTo?: string | HTMLElement, + triggers: string, + hideOnSecondTrigger?: boolean, + selectableSubMenu?: boolean, + reposition?: boolean, + delay?: number, + autoHide?: boolean, + zindex?: number | (($trigger: string, opt: JQueryCtxMenuOpts) => number) + className?: string, + classNames?: Record, + animation?: {duration: number, show: string, hide: string}, + events?: Record boolean>, + position?: (opt: unknown, x?: number|string, y?: number|string) => void, + determinePosition?: (menu: unknown) => void, + callback?: MenuCallback, + build?: ($triggerElement: unknown, e: Event) => JQueryCtxMenuOpts, + itemClickEvent?: string +} + +type UserMenuCallback = () => UserMenuItems +type UserMenuItems = Record +type MenuCallback = ( + itemKey: string, opt: JQueryCtxMenuOpts, event: Event) => (boolean | void) +type MenuIconCallback = ( + opt: JQueryCtxMenuOpts, $itemElement: HTMLElement, + itemKey: string, item: unknown) => string +type MenuBoolCallback = (itemKey: string, opt: JQueryCtxMenuOpts) => boolean +type UserMenuItem = { + name: string, + isHtmlName?: boolean, + callback: MenuCallback, + className?: string, + icon?: string | MenuIconCallback, + disabled?: boolean | MenuBoolCallback, + visible?: boolean | MenuBoolCallback, + type?: string, + events?: Record, + value?: string, + selected?: boolean | string, + radio?: string, + options?: Record, + height?: number, + items?: UserMenuItems, + accesskey?: string, + dataAttr?: Record +} + +interface XiteContextMenu { + getUserMenu(): UserMenuCallback; + setUserMenu(cb: UserMenuCallback): void; +} + export interface X3DScene { readonly specificationVersion: string; readonly encoding: 'ASCII' | 'VRML' | 'XML' | 'BINARY' @@ -274,7 +337,7 @@ export interface X3DExternProtoDeclaration { readonly fields: FieldDefinitionArray; readonly urls: X3DArrayField; isExternProto: false; - readonly loadState: number; // A Load State Constant from X3DConstant + readonly loadState: number; // A Load State Constant from X3DConstants newInstance(): SFNode; loadNow(): Promise; toVRMLString(options?: VRMLOptions): string; @@ -297,7 +360,7 @@ type FieldCallback = (value: unknown) => void assign(other: X3DField): void; setValue(value: unknown): void; getValue(): unknown; - getType(): number; // one of the Field Type Constants from X3DConstant + getType(): number; // one of the Field Type Constants from X3DConstants getAccessType(): number; // one of the Access Type Constants isInitializable(): boolean; isInput(): boolean; @@ -316,12 +379,12 @@ type FieldCallback = (value: unknown) => void addFieldCallback(key: unknown, callback: FieldCallback): void; removeFieldCallback(key: unknown): void; getFieldCallbacks(): Map; - addInputRoute(route: unknown): void; // what's the proper type for route? - removeInputRoute(route: unknown): void; - getInputRoutes(): Set; - addOutputRoute(route: unknown): void; // ditto - removeOutputRoute(route: unknown): void; - getOutputRoutes(): Set; + addInputRoute(route: X3DRoute): void; + removeInputRoute(route: X3DRoute): void; + getInputRoutes(): Set; + addOutputRoute(route: X3DRoute): void; + removeOutputRoute(route: X3DRoute): void; + getOutputRoutes(): Set; addRouteCallback(key: unknown, callback: FieldCallback): void; removeRouteCallback(key: unknown): void; getRouteCallbacks(): Map; @@ -462,7 +525,7 @@ export interface SFNode extends X3DField { getField(name: string): X3DField; getNodeName(): string; getNodeDisplayName(): string; - getNodeType(): number[]; // Array of Node Type constants from X3DConstant + getNodeType(): number[]; // Array of Node Type constants from X3DConstants getNodeTypeName(): string; getNodeUserData(key: unknown): unknown; removeFieldCallback(key: unknown): void; @@ -1765,7 +1828,7 @@ export class X3DArrayField extends X3DField { } // would be better to make these enums... -export interface X3DConstant { +export interface X3DConstants { // Browser Event Constants CONNECTION_ERROR: 0; BROWSER_EVENT: 1; diff --git a/src/giveAwrl.civet b/src/giveAwrl.civet index 8fd14df..8f94b84 100644 --- a/src/giveAwrl.civet +++ b/src/giveAwrl.civet @@ -6,7 +6,24 @@ certainlyHandled := '.x3d .gltf .glb .obj .stl .ply'.split ' ' // The next line will need to change when we handle pages with more than // one link, since we will potentially need a canvas for each one. canvas := X3D.createBrowser() -$(canvas).css width: '150px', height: '150px' + +// Fix up the css so the browser is a nice size and we can see the world info +$(canvas).css width: '150px', height: '150px', overflow: 'visible' +x_ite_shadow := canvas.shadowRoot +if x_ite_shadow + x_ite_style := x_ite_shadow.querySelector('link') + if x_ite_style + $(x_ite_style).after '' + x_ite_browser := x_ite_shadow.querySelector '.x_ite-private-browser' + if x_ite_browser + $(x_ite_browser).css overflow: 'visible' + +// Now get the browser and load the requested VRML, converting if need be browser := X3D.getBrowser canvas browser.setBrowserOption 'StraightenHorizon', false site := $('a[href^="http"]') -- 2.34.1