@virtualdisplay.io/client 4.0.0-alpha.33 → 4.0.0-alpha.34

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # Changelog
2
2
 
3
+ ## 4.0.0-alpha.34
4
+
5
+ ### Patch Changes
6
+
7
+ Fix the options panel, its toggle button and the camera controls staying hidden when the viewer reloads after the page is ready, so Shoppers can use them again.
8
+
3
9
  ## 4.0.0-alpha.33
4
10
 
5
11
  ### Patch Changes
@@ -1,5 +1,5 @@
1
1
  import { t as e } from "./rolldown-runtime-CYdcPHCu.js";
2
- // ../../../../../../../../../pnpm-stores/8781733b65c58a9438de42df3d0608bd3f2928281818079a5b066d40375deb9e/v11/links/@/qrcode/1.5.4/38431ab3ce46851b9c5211f56296031bcdd3ab8a89e17d0d2a55d25922dcc7fe/node_modules/qrcode/lib/can-promise.js
2
+ // ../../../../../../../../../pnpm-stores/e3aff882cdc12f5743094dba4c0352ef7fba83c50787c88540bf1ca2d7880a2f/v11/links/@/qrcode/1.5.4/38431ab3ce46851b9c5211f56296031bcdd3ab8a89e17d0d2a55d25922dcc7fe/node_modules/qrcode/lib/can-promise.js
3
3
  var t = /* @__PURE__ */ e(((e, t) => {
4
4
  t.exports = function() {
5
5
  return typeof Promise == "function" && Promise.prototype && Promise.prototype.then;
@@ -688,4 +688,4 @@ button.vd-annotation-popup-title:focus-visible {
688
688
  color: ${P.white};
689
689
  }
690
690
 
691
- `;function ar(){if(_n(),document.getElementById(`vd-styles`)!==null)return;let e=document.createElement(`style`);e.id=`vd-styles`,e.textContent=ir,document.head.appendChild(e)}function or(e,t){let n=document.createElement(`a`);n.href=`data:image/png;base64,${e}`,n.download=t,n.click()}var sr=class{options;settings={};container=null;loading=null;slots={topRight:null,bottomRight:null};screenshotBtn=null;actionBar=null;cameraControls=null;attributes=null;groupHandles=new Map;lastSelectable=null;layout=null;commerce=null;constructor(e){this.options=e}attach(e){ar(),this.container=e,this.loading=new An(e),this.slots.topRight=this.createSlot(e,`vd-slot-top-right`),this.slots.bottomRight=this.createSlot(e,`vd-slot-bottom-right`)}onReady(){this.loading?.hide(),this.loading=null,this.mountToolbar(),this.cameraControls!==null&&(this.cameraControls.element.style.display=`flex`),this.layout?.setVisible(!0)}mountToolbar(){if(this.actionBar!==null||this.slots.bottomRight===null||this.container===null)return;let e=typeof this.container.requestFullscreen==`function`&&document.fullscreenEnabled!==!1;this.actionBar=new jn({onAr:this.options.onAr,onFullscreen:e?()=>{this.toggleFullscreen()}:void 0,onAnnotationsToggle:this.options.onAnnotationsToggle}),this.actionBar.applySettings(this.settings),this.slots.bottomRight.appendChild(this.actionBar.element),this.syncScreenshotButton(),this.placeScreenshotButton()}toggleFullscreen(){this.container!==null&&(document.fullscreenElement===null?(this.options.onFullscreenEnter?.(),this.container.requestFullscreen().catch(e=>{A.warn(`Fullscreen request refused`,{error:e})})):document.exitFullscreen())}updateProgress(e,t){this.loading?.updateProgress(e,t)}showError(e){this.loading?.showError(e)}viewerAlive(){this.loading?.viewerAlive()}applyViewerSettings(e){this.settings=e,e.language!==void 0&&ye(e.language,{reload:!1}),this.syncScreenshotButton(),this.actionBar?.applySettings(e),this.cameraControls!==null&&(this.cameraControls.element.style.display=e.cameraControls===!0?`flex`:`none`),this.placeScreenshotButton()}renderModelControls(e,t){if(this.container!==null&&this.slots.topRight!==null&&this.slots.bottomRight!==null&&(this.cameraControls?.element.remove(),this.cameraControls=null,this.teardownConfigurator(),this.settings.cameraControls===!0&&(this.cameraControls=new Mn(this.options.cameraApi,this.options.cameraPositionApi),this.cameraControls.element.style.display=`none`,this.slots.topRight.appendChild(this.cameraControls.element)),this.placeScreenshotButton(),t.length!==0)){this.attributes=document.createElement(`div`),this.attributes.className=`vd-attributes`,this.groupHandles=new Map;for(let n of t){let t=Kn(n,e,this.options.eventBus,this.options.onSelect,this.options.onSelectTransient,this.options.onSubscribe);this.groupHandles.set(n.name,t),this.attributes.appendChild(t.element)}this.commerce=new Xn(this.options.configuration),this.attributes.appendChild(this.commerce.element),this.layout=rr(this.settings.configuratorLayout,this.slots.bottomRight),this.layout.attach(this.container,this.attributes),this.lastSelectable!==null&&this.applySelectable(this.lastSelectable)}}applySelectable(e){this.lastSelectable=e;for(let[t,n]of this.groupHandles){let r=e.find(e=>e.name===t);n.setSelectable(r?.selectable??null),n.setHidden(r?.hidden===!0)}}get viewerSettings(){return this.settings}teardownConfigurator(){this.commerce?.destroy(),this.commerce=null,this.attributes?.remove(),this.attributes=null,this.groupHandles=new Map,this.layout?.destroy(),this.layout=null}destroy(){this.loading?.destroy(),this.screenshotBtn?.element.remove(),this.actionBar?.destroy(),this.actionBar?.element.remove(),this.cameraControls?.element.remove(),this.teardownConfigurator();for(let e of Object.values(this.slots))e?.remove();this.container=null}createSlot(e,t){let n=document.createElement(`div`);return n.className=t,e.appendChild(n),n}syncScreenshotButton(){let e=this.settings.screenshot===!0;e&&this.screenshotBtn===null&&(this.screenshotBtn=new N({variant:`outline`,size:`icon`,label:Ht(),icon:M.screenshot(),onClick:()=>{this.takeScreenshot()}})),!e&&this.screenshotBtn!==null&&(this.screenshotBtn.element.remove(),this.screenshotBtn=null)}takeScreenshot(){let e=this.screenshotBtn;e===null||e.element.disabled||(e.element.disabled=!0,this.options.snapshotApi.take(`snapshot.png`).onDeveloped(({data:t,filename:n})=>{e.element.disabled=!1,or(t,n)}).onError(t=>{e.element.disabled=!1,A.warn(`Screenshot failed`,{error:t})}))}placeScreenshotButton(){this.screenshotBtn!==null&&this.slots.topRight!==null&&(this.cameraControls===null?this.slots.topRight.appendChild(this.screenshotBtn.element):this.cameraControls.element.appendChild(this.screenshotBtn.element))}},cr=class{defaultServer=`https://server.virtualdisplay.io`;options;serverHost;extraParams;constructor(e,t,n){this.options=e,this.serverHost=t,this.extraParams=n}create(){let e=this.createContainer(),t=this.createIframe();return e.appendChild(t),this.attachToParent(e),{container:e,iframe:t}}createContainer(){let e=document.createElement(`div`);return e.className=`vd-container`,Object.assign(e.style,{position:`relative`,width:`100%`,height:`100%`,overflow:`hidden`}),e}createIframe(){let e=document.createElement(`iframe`);return e.src=this.buildUrl(),e.setAttribute(`allow`,`xr-spatial-tracking; fullscreen`),e}attachToParent(e){this.getParentElement().appendChild(e)}buildUrl(){let e=this.getServerUrl(),t=new URL(e);this.setAddressParams(t),this.options.language!==void 0&&t.searchParams.set(`language`,this.options.language),this.options.session!==void 0&&t.searchParams.set(`session`,this.options.session),this.options.debug===!0&&t.searchParams.set(`debug`,`true`),this.options.traceparent!==void 0&&t.searchParams.set(`traceparent`,this.options.traceparent);for(let[e,n]of Object.entries(this.extraParams??{}))t.searchParams.set(e,n);return t.toString()}setAddressParams(e){this.options.app===void 0?(e.searchParams.set(`license`,this.options.license),e.searchParams.set(`model`,this.options.model)):(e.searchParams.set(`app`,this.options.app),(this.options.license!==void 0||this.options.model!==void 0)&&A.warn("Both `app` and `license`/`model` were supplied: `app` wins, the pair was ignored"))}getServerUrl(){return this.serverHost===void 0?this.defaultServer:this.serverHost}getParentElement(){if(typeof this.options.parent!=`string`)return this.options.parent;let e=document.querySelector(this.options.parent);if(e===null)throw w.parentNotFound(this.options.parent);return e}};function lr(e){let{messenger:n}=e;n.on(t.HANDSHAKE,t=>{l(t)&&(A.info(`Server handshake received, flushing publisher queue`),n.markReady(),e.ui.viewerAlive())}),n.on(t.SESSION,t=>{u(t)&&e.onSession(t.sessionId)}),n.on(t.MUTATION,t=>{d(t)&&(e.attributes.handleMutationResult(t),e.configuration.handleSelectionChanged(e.attributes.getSelection()))}),n.on(t.SNAPSHOT,t=>{f(t)&&e.snapshot.handleSnapshotResult(t)}),n.on(t.CAMERA,t=>{p(t)&&e.cameraPosition.handlePositionUpdate(t)}),n.on(t.LOADING_INDICATOR,t=>{ne(t)&&(t.error===void 0?e.ui.updateProgress(t.progress,t.phase):e.ui.showError(t.error))}),n.on(t.CONFIG,t=>{ie(t)&&e.applyConfig(t)}),n.on(t.MAPPING,t=>{te(t)&&(e.attributes.handleMappingReceived(t),e.configuration.handleSelectionChanged(e.attributes.getSelection()),e.ui.renderModelControls(e.attributes,t.attributes),e.readyStateTracker.handleMappingReceived())}),ur(e)}function ur(e){let{messenger:n}=e;n.on(t.FOCUS,t=>{ae(t)&&e.focus.handleStateReceived(t)}),n.on(t.PRICING,t=>{oe(t)&&e.configuration.handlePricingReceived(t.pricing)}),n.on(t.SYNC,t=>{m(t)&&e.onSync(t.connected)}),n.on(t.SELECTABLE,t=>{re(t)&&(e.selectable.handleSnapshot(t),e.ui.applySelectable(t.attributes))}),n.on(t.APP_RESOLVED,t=>{ee(t)&&e.onAppResolved(t)})}var dr=class{ready=!1;onReady;constructor(e){this.onReady=e}handleMappingReceived(){this.ready||(this.ready=!0,A.info(`Mapping received from server, client is now ready`),this.onReady?.())}get isReady(){return this.ready}clear(){this.ready=!1}};function fr(e){if(e===void 0)return;let{annotations:t,...n}=e;return t===void 0?n:t===!0?{...n,annotations:`show`}:t===!1?{...n,annotations:`hide`}:{...n,annotations:t}}function pr(e){if(!Array.isArray(e))return{};let t=e.filter(e=>typeof e==`string`);return t.length>0?{features:t}:{}}var mr=class{attributes;selectableState;readyStateTracker;messenger;cameraApi;cameraPositionApi;focusApi;configurationApi;snapshotApi;annotationsApi;eventBus;ui;options;serverHost;iframeParams;arActivation;syncTracker;iframe;container;readyCallbacks=[];mutationFailedCallbacks=[];viewerSessionId;resolvedApp;appResolvedCallbacks=[];constructor(e,t){this.options=e;let r=t??{};this.serverHost=r.serverHost,this.iframeParams=r.iframeParams,this.initializeLogging(),this.messenger=new ce(()=>this.iframe?.contentWindow??null,{onHandlerError:(e,t)=>A.error(`Error handling ${e.type}`,t),...r.messengerOptions});let i=e=>{this.messenger.send(e)};this.attributes=new ct(i,n,(e,t)=>{this.notifyMutationFailed(e,t)}),this.selectableState=new lt,this.snapshotApi=new yt(i),this.annotationsApi=new ue(i,n),this.cameraApi=new ut(i),this.cameraPositionApi=new dt,this.focusApi=new gt(i,e=>{this.dispatchFocusChange(e)},n),this.configurationApi=new ht(e=>{this.dispatchConfigurationChange(e)},e=>{this.dispatchConfigurationSubmit(e)}),this.eventBus=new bt,this.arActivation=r.createArActivation?.(i),this.syncTracker=r.createSyncTracker?.(),this.readyStateTracker=new dr(()=>{this.notifyReady()}),this.ui=this.createStandardInterface(),this.wireIncomingMessages(),r.registerHandlers?.(this.messenger,i),this.messenger.start(),this.mountIframe()}createStandardInterface(){let e=this.arActivation;return new sr({snapshotApi:this.snapshotApi,cameraApi:this.cameraApi,cameraPositionApi:this.cameraPositionApi,eventBus:this.eventBus,configuration:this.configurationApi,onSelect:(e,t)=>this.attributes.select(e,t),onSelectTransient:(e,t)=>this.attributes.selectTransient(e,t),onSubscribe:(e,t)=>this.attributes.onChange(e,t),...e!==void 0&&{onAr:()=>{e.activate()}},onFullscreenEnter:()=>{this.trackFullscreen()},onAnnotationsToggle:e=>{this.sendControlAnnotationToggle(e)}})}sendControlAnnotationToggle(e){this.sendAnnotationToggle(e,`control`)}sendAnnotationToggle(e,n){this.messenger.send({type:t.ANNOTATION_TOGGLE,enabled:e,...n!==void 0&&{origin:n}})}wireIncomingMessages(){lr({messenger:this.messenger,attributes:this.attributes,selectable:this.selectableState,configuration:this.configurationApi,snapshot:this.snapshotApi,cameraPosition:this.cameraPositionApi,focus:this.focusApi,ui:this.ui,readyStateTracker:this.readyStateTracker,applyConfig:e=>{this.handleConfig(e)},onSession:e=>{this.handleSession(e)},onSync:e=>{this.syncTracker?.handleSync(e)},onAppResolved:e=>{this.handleAppResolved({appType:e.appType,name:e.name,...e.slug!==void 0&&{slug:e.slug},...e.submit!==void 0&&{submit:e.submit},...pr(e.features)})}})}handleAppResolved(e){this.resolvedApp=e;for(let t of this.appResolvedCallbacks)t(e)}handleSession(e){this.viewerSessionId=e,this.arActivation?.onSession(e)}notifyMutationFailed(e,t){for(let n of this.mutationFailedCallbacks)n({attribute:e,value:t})}notifyReady(){let e=this.readyCallbacks;this.readyCallbacks=[];for(let t of e)t(this);this.ui.onReady()}dispatchFocusChange(e){this.container?.dispatchEvent(new CustomEvent(X.FOCUS_CHANGE,{detail:e,bubbles:!0}))}dispatchConfigurationChange(e){this.container?.dispatchEvent(new CustomEvent(X.CONFIGURATION_CHANGE,{detail:e??null,bubbles:!0}))}dispatchConfigurationSubmit(e){this.container?.dispatchEvent(new CustomEvent(X.CONFIGURATION_SUBMIT,{detail:e,bubbles:!0}))}handleConfig(e){let t=e.viewerSettings,n=fr(this.options.viewerSettings);if(t!==void 0||n!==void 0){let e=n===void 0?t:{...t??{},...n};if(n!==void 0&&t!==void 0){let e=Object.entries(n).filter(([e,n])=>t[e]!==n).map(([e,n])=>`${e} (metadata: ${t[e]??`undefined`}, override: ${n})`);e.length>0&&A.warn(`Viewer settings override active: ${e.join(`, `)}`)}this.ui.applyViewerSettings(e),this.echoAnnotationsDifference(t?.annotations,e.annotations)}this.cameraPositionApi.applyLimits(e.cameraLimits)}echoAnnotationsDifference(e,t){t!==void 0&&t!==e&&this.sendAnnotationToggle(t===`show`||t===`toggle-shown`)}trackFullscreen(){this.messenger.send({type:t.FULLSCREEN})}initializeLogging(){this.options.debug===!0&&ot(),A.info(`Initializing Virtualdisplay client`,{...this.options.app===void 0?{model:this.options.model}:{app:this.options.app}})}mountIframe(){let e=new cr(this.options,this.serverHost,this.iframeParams).create();this.container=e.container,this.iframe=e.iframe,this.eventBus.attach(this.container),this.ui.attach(this.container);try{let e=new URL(this.iframe.src).origin;this.messenger.setTargetOrigin(e)}catch{}}select(e,t){this.attributes.select(e,t)}getValues(e){return this.attributes.getValues(e)}getValue(e,t){return this.attributes.getValue(e,t)}onChange(e,t){this.attributes.onChange(e,t)}getAttribute(e){return this.attributes.getAttribute(e)}get isReady(){return this.readyStateTracker.isReady}onReady(e){this.readyStateTracker.isReady?e(this):this.readyCallbacks.push(e)}onMutationFailed(e){this.mutationFailedCallbacks.push(e)}onSelectableChange(e){this.selectableState.onChange(e)}onAppResolved(e){this.appResolvedCallbacks.push(e),this.resolvedApp!==void 0&&e(this.resolvedApp)}getSelectable(e){return this.selectableState.selectableFor(e)}activateAr(){this.arActivation?.activate()}on(e,t){this.eventBus.on(e,t)}get annotations(){return this.annotationsApi}get camera(){return this.cameraApi}get focus(){return this.focusApi}get configuration(){return this.configurationApi}get cameraPosition(){return this.cameraPositionApi}get snapshot(){return this.snapshotApi}get sessionId(){return this.viewerSessionId}get viewerSettings(){return this.ui.viewerSettings}destroy(){this.readyStateTracker.clear(),this.readyCallbacks=[],this.mutationFailedCallbacks.length=0,this.snapshotApi.clear(),this.messenger.destroy(),this.arActivation?.destroy(),this.ui.destroy(),this.container?.parentElement!==null&&this.container?.parentElement!==void 0&&this.container.parentElement.removeChild(this.container),this.container=void 0,this.iframe=void 0}},hr=`ar.virtualdisplay.io`;function gr(e){let t=new URL(`https://${hr}/go`);return e.sessionId===void 0?e.app===void 0?e.license!==void 0&&e.model!==void 0&&(t.searchParams.set(`license`,e.license),t.searchParams.set(`model`,e.model)):t.searchParams.set(`app`,e.app):t.searchParams.set(`session`,e.sessionId),t.toString()}var _r=1500,vr=class{options;qrModal=new yn;sessionId;waiters=[];pendingTimers=new Set;destroyed=!1;constructor(e){this.options=e}onSession(e){this.sessionId=e;let t=this.waiters;this.waiters=[];for(let n of t)n(e)}activate(){tt()?this.options.send({type:t.AR_ACTIVATE}):this.showQrCode()}destroy(){this.destroyed=!0;for(let e of this.pendingTimers)clearTimeout(e);this.pendingTimers.clear(),this.waiters=[],this.qrModal.hide()}async showQrCode(){this.qrModal.show();let e=await this.waitForSessionId();if(this.destroyed)return;let n=gr({sessionId:e,app:this.options.app,license:this.options.license,model:this.options.model}),r;try{r=await this.qrModal.update(n)}catch(e){A.warn(`AR QR code could not be rendered`,{error:e});return}this.destroyed?this.qrModal.hide():r&&this.options.send({type:t.QR_SHOWN})}waitForSessionId(){return this.sessionId===void 0?new Promise(e=>{let t=setTimeout(()=>{this.pendingTimers.delete(t),e(void 0)},_r);this.pendingTimers.add(t),this.waiters.push(n=>{this.pendingTimers.delete(t),clearTimeout(t),e(n)})}):Promise.resolve(this.sessionId)}},yr=class{callbacks=[];lastKnown;handleSync(e){this.lastKnown=e;for(let t of this.callbacks)t(e)}onChange(e){this.callbacks.push(e),this.lastKnown!==void 0&&e(this.lastKnown)}},br=class extends mr{syncStatusTracker;constructor(e){let t=new yr;super(e,{createArActivation:t=>new vr({app:e.app,license:e.license,model:e.model,send:t}),createSyncTracker:()=>t}),this.syncStatusTracker=t}onSyncChange(e){this.syncStatusTracker.onChange(e)}};exports.AVAILABILITY=a,exports.Annotations=ue,exports.Attribute=Le,exports.AttributeValue=de,exports.Camera=ut,exports.CameraPosition=dt,exports.Configuration=ht,exports.ERROR_CODES=C,exports.Focus=gt,exports.Photo=_t,exports.Snapshot=yt,exports.VD_EVENTS=X,exports.VirtualdisplayClient=br,exports.VirtualdisplayError=w,exports.enableDebugMode=ot,exports.isDebugMode=st,Object.defineProperty(exports,"logger",{enumerable:!0,get:function(){return A}});
691
+ `;function ar(){if(_n(),document.getElementById(`vd-styles`)!==null)return;let e=document.createElement(`style`);e.id=`vd-styles`,e.textContent=ir,document.head.appendChild(e)}function or(e,t){let n=document.createElement(`a`);n.href=`data:image/png;base64,${e}`,n.download=t,n.click()}var sr=class{options;settings={};container=null;loading=null;slots={topRight:null,bottomRight:null};screenshotBtn=null;actionBar=null;cameraControls=null;attributes=null;groupHandles=new Map;lastSelectable=null;layout=null;commerce=null;ready=!1;constructor(e){this.options=e}attach(e){ar(),this.container=e,this.loading=new An(e),this.slots.topRight=this.createSlot(e,`vd-slot-top-right`),this.slots.bottomRight=this.createSlot(e,`vd-slot-bottom-right`)}onReady(){this.ready=!0,this.loading?.hide(),this.loading=null,this.mountToolbar(),this.cameraControls!==null&&(this.cameraControls.element.style.display=`flex`),this.layout?.setVisible(!0)}mountToolbar(){if(this.actionBar!==null||this.slots.bottomRight===null||this.container===null)return;let e=typeof this.container.requestFullscreen==`function`&&document.fullscreenEnabled!==!1;this.actionBar=new jn({onAr:this.options.onAr,onFullscreen:e?()=>{this.toggleFullscreen()}:void 0,onAnnotationsToggle:this.options.onAnnotationsToggle}),this.actionBar.applySettings(this.settings),this.slots.bottomRight.appendChild(this.actionBar.element),this.syncScreenshotButton(),this.placeScreenshotButton()}toggleFullscreen(){this.container!==null&&(document.fullscreenElement===null?(this.options.onFullscreenEnter?.(),this.container.requestFullscreen().catch(e=>{A.warn(`Fullscreen request refused`,{error:e})})):document.exitFullscreen())}updateProgress(e,t){this.loading?.updateProgress(e,t)}showError(e){this.loading?.showError(e)}viewerAlive(){this.loading?.viewerAlive()}applyViewerSettings(e){this.settings=e,e.language!==void 0&&ye(e.language,{reload:!1}),this.syncScreenshotButton(),this.actionBar?.applySettings(e),this.cameraControls!==null&&(this.cameraControls.element.style.display=e.cameraControls===!0?`flex`:`none`),this.placeScreenshotButton()}renderModelControls(e,t){if(this.container!==null&&this.slots.topRight!==null&&this.slots.bottomRight!==null&&(this.cameraControls?.element.remove(),this.cameraControls=null,this.teardownConfigurator(),this.mountCameraControls(this.slots.topRight),this.placeScreenshotButton(),t.length!==0)){this.attributes=document.createElement(`div`),this.attributes.className=`vd-attributes`,this.groupHandles=new Map;for(let n of t){let t=Kn(n,e,this.options.eventBus,this.options.onSelect,this.options.onSelectTransient,this.options.onSubscribe);this.groupHandles.set(n.name,t),this.attributes.appendChild(t.element)}this.commerce=new Xn(this.options.configuration),this.attributes.appendChild(this.commerce.element),this.layout=rr(this.settings.configuratorLayout,this.slots.bottomRight),this.layout.attach(this.container,this.attributes),this.ready===!0&&this.layout.setVisible(!0),this.lastSelectable!==null&&this.applySelectable(this.lastSelectable)}}mountCameraControls(e){this.settings.cameraControls===!0&&(this.cameraControls=new Mn(this.options.cameraApi,this.options.cameraPositionApi),this.cameraControls.element.style.display=this.ready?`flex`:`none`,e.appendChild(this.cameraControls.element))}applySelectable(e){this.lastSelectable=e;for(let[t,n]of this.groupHandles){let r=e.find(e=>e.name===t);n.setSelectable(r?.selectable??null),n.setHidden(r?.hidden===!0)}}get viewerSettings(){return this.settings}teardownConfigurator(){this.commerce?.destroy(),this.commerce=null,this.attributes?.remove(),this.attributes=null,this.groupHandles=new Map,this.layout?.destroy(),this.layout=null}destroy(){this.loading?.destroy(),this.screenshotBtn?.element.remove(),this.actionBar?.destroy(),this.actionBar?.element.remove(),this.cameraControls?.element.remove(),this.teardownConfigurator();for(let e of Object.values(this.slots))e?.remove();this.container=null}createSlot(e,t){let n=document.createElement(`div`);return n.className=t,e.appendChild(n),n}syncScreenshotButton(){let e=this.settings.screenshot===!0;e&&this.screenshotBtn===null&&(this.screenshotBtn=new N({variant:`outline`,size:`icon`,label:Ht(),icon:M.screenshot(),onClick:()=>{this.takeScreenshot()}})),!e&&this.screenshotBtn!==null&&(this.screenshotBtn.element.remove(),this.screenshotBtn=null)}takeScreenshot(){let e=this.screenshotBtn;e===null||e.element.disabled||(e.element.disabled=!0,this.options.snapshotApi.take(`snapshot.png`).onDeveloped(({data:t,filename:n})=>{e.element.disabled=!1,or(t,n)}).onError(t=>{e.element.disabled=!1,A.warn(`Screenshot failed`,{error:t})}))}placeScreenshotButton(){this.screenshotBtn!==null&&this.slots.topRight!==null&&(this.cameraControls===null?this.slots.topRight.appendChild(this.screenshotBtn.element):this.cameraControls.element.appendChild(this.screenshotBtn.element))}},cr=class{defaultServer=`https://server.virtualdisplay.io`;options;serverHost;extraParams;constructor(e,t,n){this.options=e,this.serverHost=t,this.extraParams=n}create(){let e=this.createContainer(),t=this.createIframe();return e.appendChild(t),this.attachToParent(e),{container:e,iframe:t}}createContainer(){let e=document.createElement(`div`);return e.className=`vd-container`,Object.assign(e.style,{position:`relative`,width:`100%`,height:`100%`,overflow:`hidden`}),e}createIframe(){let e=document.createElement(`iframe`);return e.src=this.buildUrl(),e.setAttribute(`allow`,`xr-spatial-tracking; fullscreen`),e}attachToParent(e){this.getParentElement().appendChild(e)}buildUrl(){let e=this.getServerUrl(),t=new URL(e);this.setAddressParams(t),this.options.language!==void 0&&t.searchParams.set(`language`,this.options.language),this.options.session!==void 0&&t.searchParams.set(`session`,this.options.session),this.options.debug===!0&&t.searchParams.set(`debug`,`true`),this.options.traceparent!==void 0&&t.searchParams.set(`traceparent`,this.options.traceparent);for(let[e,n]of Object.entries(this.extraParams??{}))t.searchParams.set(e,n);return t.toString()}setAddressParams(e){this.options.app===void 0?(e.searchParams.set(`license`,this.options.license),e.searchParams.set(`model`,this.options.model)):(e.searchParams.set(`app`,this.options.app),(this.options.license!==void 0||this.options.model!==void 0)&&A.warn("Both `app` and `license`/`model` were supplied: `app` wins, the pair was ignored"))}getServerUrl(){return this.serverHost===void 0?this.defaultServer:this.serverHost}getParentElement(){if(typeof this.options.parent!=`string`)return this.options.parent;let e=document.querySelector(this.options.parent);if(e===null)throw w.parentNotFound(this.options.parent);return e}};function lr(e){let{messenger:n}=e;n.on(t.HANDSHAKE,t=>{l(t)&&(A.info(`Server handshake received, flushing publisher queue`),n.markReady(),e.ui.viewerAlive())}),n.on(t.SESSION,t=>{u(t)&&e.onSession(t.sessionId)}),n.on(t.MUTATION,t=>{d(t)&&(e.attributes.handleMutationResult(t),e.configuration.handleSelectionChanged(e.attributes.getSelection()))}),n.on(t.SNAPSHOT,t=>{f(t)&&e.snapshot.handleSnapshotResult(t)}),n.on(t.CAMERA,t=>{p(t)&&e.cameraPosition.handlePositionUpdate(t)}),n.on(t.LOADING_INDICATOR,t=>{ne(t)&&(t.error===void 0?e.ui.updateProgress(t.progress,t.phase):e.ui.showError(t.error))}),n.on(t.CONFIG,t=>{ie(t)&&e.applyConfig(t)}),n.on(t.MAPPING,t=>{te(t)&&(e.attributes.handleMappingReceived(t),e.configuration.handleSelectionChanged(e.attributes.getSelection()),e.ui.renderModelControls(e.attributes,t.attributes),e.readyStateTracker.handleMappingReceived())}),ur(e)}function ur(e){let{messenger:n}=e;n.on(t.FOCUS,t=>{ae(t)&&e.focus.handleStateReceived(t)}),n.on(t.PRICING,t=>{oe(t)&&e.configuration.handlePricingReceived(t.pricing)}),n.on(t.SYNC,t=>{m(t)&&e.onSync(t.connected)}),n.on(t.SELECTABLE,t=>{re(t)&&(e.selectable.handleSnapshot(t),e.ui.applySelectable(t.attributes))}),n.on(t.APP_RESOLVED,t=>{ee(t)&&e.onAppResolved(t)})}var dr=class{ready=!1;onReady;constructor(e){this.onReady=e}handleMappingReceived(){this.ready||(this.ready=!0,A.info(`Mapping received from server, client is now ready`),this.onReady?.())}get isReady(){return this.ready}clear(){this.ready=!1}};function fr(e){if(e===void 0)return;let{annotations:t,...n}=e;return t===void 0?n:t===!0?{...n,annotations:`show`}:t===!1?{...n,annotations:`hide`}:{...n,annotations:t}}function pr(e){if(!Array.isArray(e))return{};let t=e.filter(e=>typeof e==`string`);return t.length>0?{features:t}:{}}var mr=class{attributes;selectableState;readyStateTracker;messenger;cameraApi;cameraPositionApi;focusApi;configurationApi;snapshotApi;annotationsApi;eventBus;ui;options;serverHost;iframeParams;arActivation;syncTracker;iframe;container;readyCallbacks=[];mutationFailedCallbacks=[];viewerSessionId;resolvedApp;appResolvedCallbacks=[];constructor(e,t){this.options=e;let r=t??{};this.serverHost=r.serverHost,this.iframeParams=r.iframeParams,this.initializeLogging(),this.messenger=new ce(()=>this.iframe?.contentWindow??null,{onHandlerError:(e,t)=>A.error(`Error handling ${e.type}`,t),...r.messengerOptions});let i=e=>{this.messenger.send(e)};this.attributes=new ct(i,n,(e,t)=>{this.notifyMutationFailed(e,t)}),this.selectableState=new lt,this.snapshotApi=new yt(i),this.annotationsApi=new ue(i,n),this.cameraApi=new ut(i),this.cameraPositionApi=new dt,this.focusApi=new gt(i,e=>{this.dispatchFocusChange(e)},n),this.configurationApi=new ht(e=>{this.dispatchConfigurationChange(e)},e=>{this.dispatchConfigurationSubmit(e)}),this.eventBus=new bt,this.arActivation=r.createArActivation?.(i),this.syncTracker=r.createSyncTracker?.(),this.readyStateTracker=new dr(()=>{this.notifyReady()}),this.ui=this.createStandardInterface(),this.wireIncomingMessages(),r.registerHandlers?.(this.messenger,i),this.messenger.start(),this.mountIframe()}createStandardInterface(){let e=this.arActivation;return new sr({snapshotApi:this.snapshotApi,cameraApi:this.cameraApi,cameraPositionApi:this.cameraPositionApi,eventBus:this.eventBus,configuration:this.configurationApi,onSelect:(e,t)=>this.attributes.select(e,t),onSelectTransient:(e,t)=>this.attributes.selectTransient(e,t),onSubscribe:(e,t)=>this.attributes.onChange(e,t),...e!==void 0&&{onAr:()=>{e.activate()}},onFullscreenEnter:()=>{this.trackFullscreen()},onAnnotationsToggle:e=>{this.sendControlAnnotationToggle(e)}})}sendControlAnnotationToggle(e){this.sendAnnotationToggle(e,`control`)}sendAnnotationToggle(e,n){this.messenger.send({type:t.ANNOTATION_TOGGLE,enabled:e,...n!==void 0&&{origin:n}})}wireIncomingMessages(){lr({messenger:this.messenger,attributes:this.attributes,selectable:this.selectableState,configuration:this.configurationApi,snapshot:this.snapshotApi,cameraPosition:this.cameraPositionApi,focus:this.focusApi,ui:this.ui,readyStateTracker:this.readyStateTracker,applyConfig:e=>{this.handleConfig(e)},onSession:e=>{this.handleSession(e)},onSync:e=>{this.syncTracker?.handleSync(e)},onAppResolved:e=>{this.handleAppResolved({appType:e.appType,name:e.name,...e.slug!==void 0&&{slug:e.slug},...e.submit!==void 0&&{submit:e.submit},...pr(e.features)})}})}handleAppResolved(e){this.resolvedApp=e;for(let t of this.appResolvedCallbacks)t(e)}handleSession(e){this.viewerSessionId=e,this.arActivation?.onSession(e)}notifyMutationFailed(e,t){for(let n of this.mutationFailedCallbacks)n({attribute:e,value:t})}notifyReady(){let e=this.readyCallbacks;this.readyCallbacks=[];for(let t of e)t(this);this.ui.onReady()}dispatchFocusChange(e){this.container?.dispatchEvent(new CustomEvent(X.FOCUS_CHANGE,{detail:e,bubbles:!0}))}dispatchConfigurationChange(e){this.container?.dispatchEvent(new CustomEvent(X.CONFIGURATION_CHANGE,{detail:e??null,bubbles:!0}))}dispatchConfigurationSubmit(e){this.container?.dispatchEvent(new CustomEvent(X.CONFIGURATION_SUBMIT,{detail:e,bubbles:!0}))}handleConfig(e){let t=e.viewerSettings,n=fr(this.options.viewerSettings);if(t!==void 0||n!==void 0){let e=n===void 0?t:{...t??{},...n};if(n!==void 0&&t!==void 0){let e=Object.entries(n).filter(([e,n])=>t[e]!==n).map(([e,n])=>`${e} (metadata: ${t[e]??`undefined`}, override: ${n})`);e.length>0&&A.warn(`Viewer settings override active: ${e.join(`, `)}`)}this.ui.applyViewerSettings(e),this.echoAnnotationsDifference(t?.annotations,e.annotations)}this.cameraPositionApi.applyLimits(e.cameraLimits)}echoAnnotationsDifference(e,t){t!==void 0&&t!==e&&this.sendAnnotationToggle(t===`show`||t===`toggle-shown`)}trackFullscreen(){this.messenger.send({type:t.FULLSCREEN})}initializeLogging(){this.options.debug===!0&&ot(),A.info(`Initializing Virtualdisplay client`,{...this.options.app===void 0?{model:this.options.model}:{app:this.options.app}})}mountIframe(){let e=new cr(this.options,this.serverHost,this.iframeParams).create();this.container=e.container,this.iframe=e.iframe,this.eventBus.attach(this.container),this.ui.attach(this.container);try{let e=new URL(this.iframe.src).origin;this.messenger.setTargetOrigin(e)}catch{}}select(e,t){this.attributes.select(e,t)}getValues(e){return this.attributes.getValues(e)}getValue(e,t){return this.attributes.getValue(e,t)}onChange(e,t){this.attributes.onChange(e,t)}getAttribute(e){return this.attributes.getAttribute(e)}get isReady(){return this.readyStateTracker.isReady}onReady(e){this.readyStateTracker.isReady?e(this):this.readyCallbacks.push(e)}onMutationFailed(e){this.mutationFailedCallbacks.push(e)}onSelectableChange(e){this.selectableState.onChange(e)}onAppResolved(e){this.appResolvedCallbacks.push(e),this.resolvedApp!==void 0&&e(this.resolvedApp)}getSelectable(e){return this.selectableState.selectableFor(e)}activateAr(){this.arActivation?.activate()}on(e,t){this.eventBus.on(e,t)}get annotations(){return this.annotationsApi}get camera(){return this.cameraApi}get focus(){return this.focusApi}get configuration(){return this.configurationApi}get cameraPosition(){return this.cameraPositionApi}get snapshot(){return this.snapshotApi}get sessionId(){return this.viewerSessionId}get viewerSettings(){return this.ui.viewerSettings}destroy(){this.readyStateTracker.clear(),this.readyCallbacks=[],this.mutationFailedCallbacks.length=0,this.snapshotApi.clear(),this.messenger.destroy(),this.arActivation?.destroy(),this.ui.destroy(),this.container?.parentElement!==null&&this.container?.parentElement!==void 0&&this.container.parentElement.removeChild(this.container),this.container=void 0,this.iframe=void 0}},hr=`ar.virtualdisplay.io`;function gr(e){let t=new URL(`https://${hr}/go`);return e.sessionId===void 0?e.app===void 0?e.license!==void 0&&e.model!==void 0&&(t.searchParams.set(`license`,e.license),t.searchParams.set(`model`,e.model)):t.searchParams.set(`app`,e.app):t.searchParams.set(`session`,e.sessionId),t.toString()}var _r=1500,vr=class{options;qrModal=new yn;sessionId;waiters=[];pendingTimers=new Set;destroyed=!1;constructor(e){this.options=e}onSession(e){this.sessionId=e;let t=this.waiters;this.waiters=[];for(let n of t)n(e)}activate(){tt()?this.options.send({type:t.AR_ACTIVATE}):this.showQrCode()}destroy(){this.destroyed=!0;for(let e of this.pendingTimers)clearTimeout(e);this.pendingTimers.clear(),this.waiters=[],this.qrModal.hide()}async showQrCode(){this.qrModal.show();let e=await this.waitForSessionId();if(this.destroyed)return;let n=gr({sessionId:e,app:this.options.app,license:this.options.license,model:this.options.model}),r;try{r=await this.qrModal.update(n)}catch(e){A.warn(`AR QR code could not be rendered`,{error:e});return}this.destroyed?this.qrModal.hide():r&&this.options.send({type:t.QR_SHOWN})}waitForSessionId(){return this.sessionId===void 0?new Promise(e=>{let t=setTimeout(()=>{this.pendingTimers.delete(t),e(void 0)},_r);this.pendingTimers.add(t),this.waiters.push(n=>{this.pendingTimers.delete(t),clearTimeout(t),e(n)})}):Promise.resolve(this.sessionId)}},yr=class{callbacks=[];lastKnown;handleSync(e){this.lastKnown=e;for(let t of this.callbacks)t(e)}onChange(e){this.callbacks.push(e),this.lastKnown!==void 0&&e(this.lastKnown)}},br=class extends mr{syncStatusTracker;constructor(e){let t=new yr;super(e,{createArActivation:t=>new vr({app:e.app,license:e.license,model:e.model,send:t}),createSyncTracker:()=>t}),this.syncStatusTracker=t}onSyncChange(e){this.syncStatusTracker.onChange(e)}};exports.AVAILABILITY=a,exports.Annotations=ue,exports.Attribute=Le,exports.AttributeValue=de,exports.Camera=ut,exports.CameraPosition=dt,exports.Configuration=ht,exports.ERROR_CODES=C,exports.Focus=gt,exports.Photo=_t,exports.Snapshot=yt,exports.VD_EVENTS=X,exports.VirtualdisplayClient=br,exports.VirtualdisplayError=w,exports.enableDebugMode=ot,exports.isDebugMode=st,Object.defineProperty(exports,"logger",{enumerable:!0,get:function(){return A}});
@@ -2028,7 +2028,7 @@ var vn = I.fontFamily.sans.join(", "), yn = class {
2028
2028
  async update(t) {
2029
2029
  let n;
2030
2030
  try {
2031
- this.qrLib ??= await import("./browser-BeOPJLWl.js").then((t) => /* @__PURE__ */ e(t.default, 1)), n = await this.qrLib.toDataURL(t, {
2031
+ this.qrLib ??= await import("./browser-DtVlHXIz.js").then((t) => /* @__PURE__ */ e(t.default, 1)), n = await this.qrLib.toDataURL(t, {
2032
2032
  width: 256,
2033
2033
  margin: 4,
2034
2034
  errorCorrectionLevel: "M",
@@ -2936,6 +2936,7 @@ var sr = class {
2936
2936
  lastSelectable = null;
2937
2937
  layout = null;
2938
2938
  commerce = null;
2939
+ ready = !1;
2939
2940
  constructor(e) {
2940
2941
  this.options = e;
2941
2942
  }
@@ -2943,7 +2944,7 @@ var sr = class {
2943
2944
  ar(), this.container = e, this.loading = new An(e), this.slots.topRight = this.createSlot(e, "vd-slot-top-right"), this.slots.bottomRight = this.createSlot(e, "vd-slot-bottom-right");
2944
2945
  }
2945
2946
  onReady() {
2946
- this.loading?.hide(), this.loading = null, this.mountToolbar(), this.cameraControls !== null && (this.cameraControls.element.style.display = "flex"), this.layout?.setVisible(!0);
2947
+ this.ready = !0, this.loading?.hide(), this.loading = null, this.mountToolbar(), this.cameraControls !== null && (this.cameraControls.element.style.display = "flex"), this.layout?.setVisible(!0);
2947
2948
  }
2948
2949
  mountToolbar() {
2949
2950
  if (this.actionBar !== null || this.slots.bottomRight === null || this.container === null) return;
@@ -2974,15 +2975,18 @@ var sr = class {
2974
2975
  this.settings = e, e.language !== void 0 && ye(e.language, { reload: !1 }), this.syncScreenshotButton(), this.actionBar?.applySettings(e), this.cameraControls !== null && (this.cameraControls.element.style.display = e.cameraControls === !0 ? "flex" : "none"), this.placeScreenshotButton();
2975
2976
  }
2976
2977
  renderModelControls(e, t) {
2977
- if (this.container !== null && this.slots.topRight !== null && this.slots.bottomRight !== null && (this.cameraControls?.element.remove(), this.cameraControls = null, this.teardownConfigurator(), this.settings.cameraControls === !0 && (this.cameraControls = new Mn(this.options.cameraApi, this.options.cameraPositionApi), this.cameraControls.element.style.display = "none", this.slots.topRight.appendChild(this.cameraControls.element)), this.placeScreenshotButton(), t.length !== 0)) {
2978
+ if (this.container !== null && this.slots.topRight !== null && this.slots.bottomRight !== null && (this.cameraControls?.element.remove(), this.cameraControls = null, this.teardownConfigurator(), this.mountCameraControls(this.slots.topRight), this.placeScreenshotButton(), t.length !== 0)) {
2978
2979
  this.attributes = document.createElement("div"), this.attributes.className = "vd-attributes", this.groupHandles = /* @__PURE__ */ new Map();
2979
2980
  for (let n of t) {
2980
2981
  let t = Kn(n, e, this.options.eventBus, this.options.onSelect, this.options.onSelectTransient, this.options.onSubscribe);
2981
2982
  this.groupHandles.set(n.name, t), this.attributes.appendChild(t.element);
2982
2983
  }
2983
- this.commerce = new Xn(this.options.configuration), this.attributes.appendChild(this.commerce.element), this.layout = rr(this.settings.configuratorLayout, this.slots.bottomRight), this.layout.attach(this.container, this.attributes), this.lastSelectable !== null && this.applySelectable(this.lastSelectable);
2984
+ this.commerce = new Xn(this.options.configuration), this.attributes.appendChild(this.commerce.element), this.layout = rr(this.settings.configuratorLayout, this.slots.bottomRight), this.layout.attach(this.container, this.attributes), this.ready === !0 && this.layout.setVisible(!0), this.lastSelectable !== null && this.applySelectable(this.lastSelectable);
2984
2985
  }
2985
2986
  }
2987
+ mountCameraControls(e) {
2988
+ this.settings.cameraControls === !0 && (this.cameraControls = new Mn(this.options.cameraApi, this.options.cameraPositionApi), this.cameraControls.element.style.display = this.ready ? "flex" : "none", e.appendChild(this.cameraControls.element));
2989
+ }
2986
2990
  applySelectable(e) {
2987
2991
  this.lastSelectable = e;
2988
2992
  for (let [t, n] of this.groupHandles) {
@@ -695,4 +695,4 @@ Minimum version required to store current data is: `+c+`.
695
695
  color: ${H.white};
696
696
  }
697
697
 
698
- `;function Hr(){if(vn(),document.getElementById(`vd-styles`)!==null)return;let e=document.createElement(`style`);e.id=`vd-styles`,e.textContent=Vr,document.head.appendChild(e)}function Ur(e,t){let n=document.createElement(`a`);n.href=`data:image/png;base64,${e}`,n.download=t,n.click()}var Wr=class{options;settings={};container=null;loading=null;slots={topRight:null,bottomRight:null};screenshotBtn=null;actionBar=null;cameraControls=null;attributes=null;groupHandles=new Map;lastSelectable=null;layout=null;commerce=null;constructor(e){this.options=e}attach(e){Hr(),this.container=e,this.loading=new ur(e),this.slots.topRight=this.createSlot(e,`vd-slot-top-right`),this.slots.bottomRight=this.createSlot(e,`vd-slot-bottom-right`)}onReady(){this.loading?.hide(),this.loading=null,this.mountToolbar(),this.cameraControls!==null&&(this.cameraControls.element.style.display=`flex`),this.layout?.setVisible(!0)}mountToolbar(){if(this.actionBar!==null||this.slots.bottomRight===null||this.container===null)return;let e=typeof this.container.requestFullscreen==`function`&&document.fullscreenEnabled!==!1;this.actionBar=new dr({onAr:this.options.onAr,onFullscreen:e?()=>{this.toggleFullscreen()}:void 0,onAnnotationsToggle:this.options.onAnnotationsToggle}),this.actionBar.applySettings(this.settings),this.slots.bottomRight.appendChild(this.actionBar.element),this.syncScreenshotButton(),this.placeScreenshotButton()}toggleFullscreen(){this.container!==null&&(document.fullscreenElement===null?(this.options.onFullscreenEnter?.(),this.container.requestFullscreen().catch(e=>{R.warn(`Fullscreen request refused`,{error:e})})):document.exitFullscreen())}updateProgress(e,t){this.loading?.updateProgress(e,t)}showError(e){this.loading?.showError(e)}viewerAlive(){this.loading?.viewerAlive()}applyViewerSettings(e){this.settings=e,e.language!==void 0&&ye(e.language,{reload:!1}),this.syncScreenshotButton(),this.actionBar?.applySettings(e),this.cameraControls!==null&&(this.cameraControls.element.style.display=e.cameraControls===!0?`flex`:`none`),this.placeScreenshotButton()}renderModelControls(e,t){if(this.container!==null&&this.slots.topRight!==null&&this.slots.bottomRight!==null&&(this.cameraControls?.element.remove(),this.cameraControls=null,this.teardownConfigurator(),this.settings.cameraControls===!0&&(this.cameraControls=new fr(this.options.cameraApi,this.options.cameraPositionApi),this.cameraControls.element.style.display=`none`,this.slots.topRight.appendChild(this.cameraControls.element)),this.placeScreenshotButton(),t.length!==0)){this.attributes=document.createElement(`div`),this.attributes.className=`vd-attributes`,this.groupHandles=new Map;for(let n of t){let t=Dr(n,e,this.options.eventBus,this.options.onSelect,this.options.onSelectTransient,this.options.onSubscribe);this.groupHandles.set(n.name,t),this.attributes.appendChild(t.element)}this.commerce=new jr(this.options.configuration),this.attributes.appendChild(this.commerce.element),this.layout=zr(this.settings.configuratorLayout,this.slots.bottomRight),this.layout.attach(this.container,this.attributes),this.lastSelectable!==null&&this.applySelectable(this.lastSelectable)}}applySelectable(e){this.lastSelectable=e;for(let[t,n]of this.groupHandles){let r=e.find(e=>e.name===t);n.setSelectable(r?.selectable??null),n.setHidden(r?.hidden===!0)}}get viewerSettings(){return this.settings}teardownConfigurator(){this.commerce?.destroy(),this.commerce=null,this.attributes?.remove(),this.attributes=null,this.groupHandles=new Map,this.layout?.destroy(),this.layout=null}destroy(){this.loading?.destroy(),this.screenshotBtn?.element.remove(),this.actionBar?.destroy(),this.actionBar?.element.remove(),this.cameraControls?.element.remove(),this.teardownConfigurator();for(let e of Object.values(this.slots))e?.remove();this.container=null}createSlot(e,t){let n=document.createElement(`div`);return n.className=t,e.appendChild(n),n}syncScreenshotButton(){let e=this.settings.screenshot===!0;e&&this.screenshotBtn===null&&(this.screenshotBtn=new V({variant:`outline`,size:`icon`,label:Ut(),icon:B.screenshot(),onClick:()=>{this.takeScreenshot()}})),!e&&this.screenshotBtn!==null&&(this.screenshotBtn.element.remove(),this.screenshotBtn=null)}takeScreenshot(){let e=this.screenshotBtn;e===null||e.element.disabled||(e.element.disabled=!0,this.options.snapshotApi.take(`snapshot.png`).onDeveloped(({data:t,filename:n})=>{e.element.disabled=!1,Ur(t,n)}).onError(t=>{e.element.disabled=!1,R.warn(`Screenshot failed`,{error:t})}))}placeScreenshotButton(){this.screenshotBtn!==null&&this.slots.topRight!==null&&(this.cameraControls===null?this.slots.topRight.appendChild(this.screenshotBtn.element):this.cameraControls.element.appendChild(this.screenshotBtn.element))}},Gr=class{defaultServer=`https://server.virtualdisplay.io`;options;serverHost;extraParams;constructor(e,t,n){this.options=e,this.serverHost=t,this.extraParams=n}create(){let e=this.createContainer(),t=this.createIframe();return e.appendChild(t),this.attachToParent(e),{container:e,iframe:t}}createContainer(){let e=document.createElement(`div`);return e.className=`vd-container`,Object.assign(e.style,{position:`relative`,width:`100%`,height:`100%`,overflow:`hidden`}),e}createIframe(){let e=document.createElement(`iframe`);return e.src=this.buildUrl(),e.setAttribute(`allow`,`xr-spatial-tracking; fullscreen`),e}attachToParent(e){this.getParentElement().appendChild(e)}buildUrl(){let e=this.getServerUrl(),t=new URL(e);this.setAddressParams(t),this.options.language!==void 0&&t.searchParams.set(`language`,this.options.language),this.options.session!==void 0&&t.searchParams.set(`session`,this.options.session),this.options.debug===!0&&t.searchParams.set(`debug`,`true`),this.options.traceparent!==void 0&&t.searchParams.set(`traceparent`,this.options.traceparent);for(let[e,n]of Object.entries(this.extraParams??{}))t.searchParams.set(e,n);return t.toString()}setAddressParams(e){this.options.app===void 0?(e.searchParams.set(`license`,this.options.license),e.searchParams.set(`model`,this.options.model)):(e.searchParams.set(`app`,this.options.app),(this.options.license!==void 0||this.options.model!==void 0)&&R.warn("Both `app` and `license`/`model` were supplied: `app` wins, the pair was ignored"))}getServerUrl(){return this.serverHost===void 0?this.defaultServer:this.serverHost}getParentElement(){if(typeof this.options.parent!=`string`)return this.options.parent;let e=document.querySelector(this.options.parent);if(e===null)throw M.parentNotFound(this.options.parent);return e}};function Kr(e){let{messenger:t}=e;t.on(u.HANDSHAKE,n=>{v(n)&&(R.info(`Server handshake received, flushing publisher queue`),t.markReady(),e.ui.viewerAlive())}),t.on(u.SESSION,t=>{y(t)&&e.onSession(t.sessionId)}),t.on(u.MUTATION,t=>{x(t)&&(e.attributes.handleMutationResult(t),e.configuration.handleSelectionChanged(e.attributes.getSelection()))}),t.on(u.SNAPSHOT,t=>{S(t)&&e.snapshot.handleSnapshotResult(t)}),t.on(u.CAMERA,t=>{C(t)&&e.cameraPosition.handlePositionUpdate(t)}),t.on(u.LOADING_INDICATOR,t=>{te(t)&&(t.error===void 0?e.ui.updateProgress(t.progress,t.phase):e.ui.showError(t.error))}),t.on(u.CONFIG,t=>{ie(t)&&e.applyConfig(t)}),t.on(u.MAPPING,t=>{ee(t)&&(e.attributes.handleMappingReceived(t),e.configuration.handleSelectionChanged(e.attributes.getSelection()),e.ui.renderModelControls(e.attributes,t.attributes),e.readyStateTracker.handleMappingReceived())}),qr(e)}function qr(e){let{messenger:t}=e;t.on(u.FOCUS,t=>{ae(t)&&e.focus.handleStateReceived(t)}),t.on(u.PRICING,t=>{oe(t)&&e.configuration.handlePricingReceived(t.pricing)}),t.on(u.SYNC,t=>{ne(t)&&e.onSync(t.connected)}),t.on(u.SELECTABLE,t=>{re(t)&&(e.selectable.handleSnapshot(t),e.ui.applySelectable(t.attributes))}),t.on(u.APP_RESOLVED,t=>{b(t)&&e.onAppResolved(t)})}var Jr=class{ready=!1;onReady;constructor(e){this.onReady=e}handleMappingReceived(){this.ready||(this.ready=!0,R.info(`Mapping received from server, client is now ready`),this.onReady?.())}get isReady(){return this.ready}clear(){this.ready=!1}};function Yr(e){if(e===void 0)return;let{annotations:t,...n}=e;return t===void 0?n:t===!0?{...n,annotations:`show`}:t===!1?{...n,annotations:`hide`}:{...n,annotations:t}}function Xr(e){if(!Array.isArray(e))return{};let t=e.filter(e=>typeof e==`string`);return t.length>0?{features:t}:{}}var Zr=class{attributes;selectableState;readyStateTracker;messenger;cameraApi;cameraPositionApi;focusApi;configurationApi;snapshotApi;annotationsApi;eventBus;ui;options;serverHost;iframeParams;arActivation;syncTracker;iframe;container;readyCallbacks=[];mutationFailedCallbacks=[];viewerSessionId;resolvedApp;appResolvedCallbacks=[];constructor(e,t){this.options=e;let n=t??{};this.serverHost=n.serverHost,this.iframeParams=n.iframeParams,this.initializeLogging(),this.messenger=new ce(()=>this.iframe?.contentWindow??null,{onHandlerError:(e,t)=>R.error(`Error handling ${e.type}`,t),...n.messengerOptions});let r=e=>{this.messenger.send(e)};this.attributes=new lt(r,d,(e,t)=>{this.notifyMutationFailed(e,t)}),this.selectableState=new ut,this.snapshotApi=new bt(r),this.annotationsApi=new ue(r,d),this.cameraApi=new dt(r),this.cameraPositionApi=new ft,this.focusApi=new _t(r,e=>{this.dispatchFocusChange(e)},d),this.configurationApi=new gt(e=>{this.dispatchConfigurationChange(e)},e=>{this.dispatchConfigurationSubmit(e)}),this.eventBus=new xt,this.arActivation=n.createArActivation?.(r),this.syncTracker=n.createSyncTracker?.(),this.readyStateTracker=new Jr(()=>{this.notifyReady()}),this.ui=this.createStandardInterface(),this.wireIncomingMessages(),n.registerHandlers?.(this.messenger,r),this.messenger.start(),this.mountIframe()}createStandardInterface(){let e=this.arActivation;return new Wr({snapshotApi:this.snapshotApi,cameraApi:this.cameraApi,cameraPositionApi:this.cameraPositionApi,eventBus:this.eventBus,configuration:this.configurationApi,onSelect:(e,t)=>this.attributes.select(e,t),onSelectTransient:(e,t)=>this.attributes.selectTransient(e,t),onSubscribe:(e,t)=>this.attributes.onChange(e,t),...e!==void 0&&{onAr:()=>{e.activate()}},onFullscreenEnter:()=>{this.trackFullscreen()},onAnnotationsToggle:e=>{this.sendControlAnnotationToggle(e)}})}sendControlAnnotationToggle(e){this.sendAnnotationToggle(e,`control`)}sendAnnotationToggle(e,t){this.messenger.send({type:u.ANNOTATION_TOGGLE,enabled:e,...t!==void 0&&{origin:t}})}wireIncomingMessages(){Kr({messenger:this.messenger,attributes:this.attributes,selectable:this.selectableState,configuration:this.configurationApi,snapshot:this.snapshotApi,cameraPosition:this.cameraPositionApi,focus:this.focusApi,ui:this.ui,readyStateTracker:this.readyStateTracker,applyConfig:e=>{this.handleConfig(e)},onSession:e=>{this.handleSession(e)},onSync:e=>{this.syncTracker?.handleSync(e)},onAppResolved:e=>{this.handleAppResolved({appType:e.appType,name:e.name,...e.slug!==void 0&&{slug:e.slug},...e.submit!==void 0&&{submit:e.submit},...Xr(e.features)})}})}handleAppResolved(e){this.resolvedApp=e;for(let t of this.appResolvedCallbacks)t(e)}handleSession(e){this.viewerSessionId=e,this.arActivation?.onSession(e)}notifyMutationFailed(e,t){for(let n of this.mutationFailedCallbacks)n({attribute:e,value:t})}notifyReady(){let e=this.readyCallbacks;this.readyCallbacks=[];for(let t of e)t(this);this.ui.onReady()}dispatchFocusChange(e){this.container?.dispatchEvent(new CustomEvent(Q.FOCUS_CHANGE,{detail:e,bubbles:!0}))}dispatchConfigurationChange(e){this.container?.dispatchEvent(new CustomEvent(Q.CONFIGURATION_CHANGE,{detail:e??null,bubbles:!0}))}dispatchConfigurationSubmit(e){this.container?.dispatchEvent(new CustomEvent(Q.CONFIGURATION_SUBMIT,{detail:e,bubbles:!0}))}handleConfig(e){let t=e.viewerSettings,n=Yr(this.options.viewerSettings);if(t!==void 0||n!==void 0){let e=n===void 0?t:{...t??{},...n};if(n!==void 0&&t!==void 0){let e=Object.entries(n).filter(([e,n])=>t[e]!==n).map(([e,n])=>`${e} (metadata: ${t[e]??`undefined`}, override: ${n})`);e.length>0&&R.warn(`Viewer settings override active: ${e.join(`, `)}`)}this.ui.applyViewerSettings(e),this.echoAnnotationsDifference(t?.annotations,e.annotations)}this.cameraPositionApi.applyLimits(e.cameraLimits)}echoAnnotationsDifference(e,t){t!==void 0&&t!==e&&this.sendAnnotationToggle(t===`show`||t===`toggle-shown`)}trackFullscreen(){this.messenger.send({type:u.FULLSCREEN})}initializeLogging(){this.options.debug===!0&&st(),R.info(`Initializing Virtualdisplay client`,{...this.options.app===void 0?{model:this.options.model}:{app:this.options.app}})}mountIframe(){let e=new Gr(this.options,this.serverHost,this.iframeParams).create();this.container=e.container,this.iframe=e.iframe,this.eventBus.attach(this.container),this.ui.attach(this.container);try{let e=new URL(this.iframe.src).origin;this.messenger.setTargetOrigin(e)}catch{}}select(e,t){this.attributes.select(e,t)}getValues(e){return this.attributes.getValues(e)}getValue(e,t){return this.attributes.getValue(e,t)}onChange(e,t){this.attributes.onChange(e,t)}getAttribute(e){return this.attributes.getAttribute(e)}get isReady(){return this.readyStateTracker.isReady}onReady(e){this.readyStateTracker.isReady?e(this):this.readyCallbacks.push(e)}onMutationFailed(e){this.mutationFailedCallbacks.push(e)}onSelectableChange(e){this.selectableState.onChange(e)}onAppResolved(e){this.appResolvedCallbacks.push(e),this.resolvedApp!==void 0&&e(this.resolvedApp)}getSelectable(e){return this.selectableState.selectableFor(e)}activateAr(){this.arActivation?.activate()}on(e,t){this.eventBus.on(e,t)}get annotations(){return this.annotationsApi}get camera(){return this.cameraApi}get focus(){return this.focusApi}get configuration(){return this.configurationApi}get cameraPosition(){return this.cameraPositionApi}get snapshot(){return this.snapshotApi}get sessionId(){return this.viewerSessionId}get viewerSettings(){return this.ui.viewerSettings}destroy(){this.readyStateTracker.clear(),this.readyCallbacks=[],this.mutationFailedCallbacks.length=0,this.snapshotApi.clear(),this.messenger.destroy(),this.arActivation?.destroy(),this.ui.destroy(),this.container?.parentElement!==null&&this.container?.parentElement!==void 0&&this.container.parentElement.removeChild(this.container),this.container=void 0,this.iframe=void 0}},Qr=`ar.virtualdisplay.io`;function $r(e){let t=new URL(`https://${Qr}/go`);return e.sessionId===void 0?e.app===void 0?e.license!==void 0&&e.model!==void 0&&(t.searchParams.set(`license`,e.license),t.searchParams.set(`model`,e.model)):t.searchParams.set(`app`,e.app):t.searchParams.set(`session`,e.sessionId),t.toString()}var ei=1500,ti=class{options;qrModal=new Gn;sessionId;waiters=[];pendingTimers=new Set;destroyed=!1;constructor(e){this.options=e}onSession(e){this.sessionId=e;let t=this.waiters;this.waiters=[];for(let n of t)n(e)}activate(){nt()?this.options.send({type:u.AR_ACTIVATE}):this.showQrCode()}destroy(){this.destroyed=!0;for(let e of this.pendingTimers)clearTimeout(e);this.pendingTimers.clear(),this.waiters=[],this.qrModal.hide()}async showQrCode(){this.qrModal.show();let e=await this.waitForSessionId();if(this.destroyed)return;let t=$r({sessionId:e,app:this.options.app,license:this.options.license,model:this.options.model}),n;try{n=await this.qrModal.update(t)}catch(e){R.warn(`AR QR code could not be rendered`,{error:e});return}this.destroyed?this.qrModal.hide():n&&this.options.send({type:u.QR_SHOWN})}waitForSessionId(){return this.sessionId===void 0?new Promise(e=>{let t=setTimeout(()=>{this.pendingTimers.delete(t),e(void 0)},ei);this.pendingTimers.add(t),this.waiters.push(n=>{this.pendingTimers.delete(t),clearTimeout(t),e(n)})}):Promise.resolve(this.sessionId)}},ni=class{callbacks=[];lastKnown;handleSync(e){this.lastKnown=e;for(let t of this.callbacks)t(e)}onChange(e){this.callbacks.push(e),this.lastKnown!==void 0&&e(this.lastKnown)}},ri=class extends Zr{syncStatusTracker;constructor(e){let t=new ni;super(e,{createArActivation:t=>new ti({app:e.app,license:e.license,model:e.model,send:t}),createSyncTracker:()=>t}),this.syncStatusTracker=t}onSyncChange(e){this.syncStatusTracker.onChange(e)}};e.AVAILABILITY=m,e.Annotations=ue,e.Attribute=Re,e.AttributeValue=de,e.Camera=dt,e.CameraPosition=ft,e.Configuration=gt,e.ERROR_CODES=j,e.Focus=_t,e.Photo=vt,e.Snapshot=bt,e.VD_EVENTS=Q,e.VirtualdisplayClient=ri,e.VirtualdisplayError=M,e.enableDebugMode=st,e.isDebugMode=ct,Object.defineProperty(e,"logger",{enumerable:!0,get:function(){return R}})});
698
+ `;function Hr(){if(vn(),document.getElementById(`vd-styles`)!==null)return;let e=document.createElement(`style`);e.id=`vd-styles`,e.textContent=Vr,document.head.appendChild(e)}function Ur(e,t){let n=document.createElement(`a`);n.href=`data:image/png;base64,${e}`,n.download=t,n.click()}var Wr=class{options;settings={};container=null;loading=null;slots={topRight:null,bottomRight:null};screenshotBtn=null;actionBar=null;cameraControls=null;attributes=null;groupHandles=new Map;lastSelectable=null;layout=null;commerce=null;ready=!1;constructor(e){this.options=e}attach(e){Hr(),this.container=e,this.loading=new ur(e),this.slots.topRight=this.createSlot(e,`vd-slot-top-right`),this.slots.bottomRight=this.createSlot(e,`vd-slot-bottom-right`)}onReady(){this.ready=!0,this.loading?.hide(),this.loading=null,this.mountToolbar(),this.cameraControls!==null&&(this.cameraControls.element.style.display=`flex`),this.layout?.setVisible(!0)}mountToolbar(){if(this.actionBar!==null||this.slots.bottomRight===null||this.container===null)return;let e=typeof this.container.requestFullscreen==`function`&&document.fullscreenEnabled!==!1;this.actionBar=new dr({onAr:this.options.onAr,onFullscreen:e?()=>{this.toggleFullscreen()}:void 0,onAnnotationsToggle:this.options.onAnnotationsToggle}),this.actionBar.applySettings(this.settings),this.slots.bottomRight.appendChild(this.actionBar.element),this.syncScreenshotButton(),this.placeScreenshotButton()}toggleFullscreen(){this.container!==null&&(document.fullscreenElement===null?(this.options.onFullscreenEnter?.(),this.container.requestFullscreen().catch(e=>{R.warn(`Fullscreen request refused`,{error:e})})):document.exitFullscreen())}updateProgress(e,t){this.loading?.updateProgress(e,t)}showError(e){this.loading?.showError(e)}viewerAlive(){this.loading?.viewerAlive()}applyViewerSettings(e){this.settings=e,e.language!==void 0&&ye(e.language,{reload:!1}),this.syncScreenshotButton(),this.actionBar?.applySettings(e),this.cameraControls!==null&&(this.cameraControls.element.style.display=e.cameraControls===!0?`flex`:`none`),this.placeScreenshotButton()}renderModelControls(e,t){if(this.container!==null&&this.slots.topRight!==null&&this.slots.bottomRight!==null&&(this.cameraControls?.element.remove(),this.cameraControls=null,this.teardownConfigurator(),this.mountCameraControls(this.slots.topRight),this.placeScreenshotButton(),t.length!==0)){this.attributes=document.createElement(`div`),this.attributes.className=`vd-attributes`,this.groupHandles=new Map;for(let n of t){let t=Dr(n,e,this.options.eventBus,this.options.onSelect,this.options.onSelectTransient,this.options.onSubscribe);this.groupHandles.set(n.name,t),this.attributes.appendChild(t.element)}this.commerce=new jr(this.options.configuration),this.attributes.appendChild(this.commerce.element),this.layout=zr(this.settings.configuratorLayout,this.slots.bottomRight),this.layout.attach(this.container,this.attributes),this.ready===!0&&this.layout.setVisible(!0),this.lastSelectable!==null&&this.applySelectable(this.lastSelectable)}}mountCameraControls(e){this.settings.cameraControls===!0&&(this.cameraControls=new fr(this.options.cameraApi,this.options.cameraPositionApi),this.cameraControls.element.style.display=this.ready?`flex`:`none`,e.appendChild(this.cameraControls.element))}applySelectable(e){this.lastSelectable=e;for(let[t,n]of this.groupHandles){let r=e.find(e=>e.name===t);n.setSelectable(r?.selectable??null),n.setHidden(r?.hidden===!0)}}get viewerSettings(){return this.settings}teardownConfigurator(){this.commerce?.destroy(),this.commerce=null,this.attributes?.remove(),this.attributes=null,this.groupHandles=new Map,this.layout?.destroy(),this.layout=null}destroy(){this.loading?.destroy(),this.screenshotBtn?.element.remove(),this.actionBar?.destroy(),this.actionBar?.element.remove(),this.cameraControls?.element.remove(),this.teardownConfigurator();for(let e of Object.values(this.slots))e?.remove();this.container=null}createSlot(e,t){let n=document.createElement(`div`);return n.className=t,e.appendChild(n),n}syncScreenshotButton(){let e=this.settings.screenshot===!0;e&&this.screenshotBtn===null&&(this.screenshotBtn=new V({variant:`outline`,size:`icon`,label:Ut(),icon:B.screenshot(),onClick:()=>{this.takeScreenshot()}})),!e&&this.screenshotBtn!==null&&(this.screenshotBtn.element.remove(),this.screenshotBtn=null)}takeScreenshot(){let e=this.screenshotBtn;e===null||e.element.disabled||(e.element.disabled=!0,this.options.snapshotApi.take(`snapshot.png`).onDeveloped(({data:t,filename:n})=>{e.element.disabled=!1,Ur(t,n)}).onError(t=>{e.element.disabled=!1,R.warn(`Screenshot failed`,{error:t})}))}placeScreenshotButton(){this.screenshotBtn!==null&&this.slots.topRight!==null&&(this.cameraControls===null?this.slots.topRight.appendChild(this.screenshotBtn.element):this.cameraControls.element.appendChild(this.screenshotBtn.element))}},Gr=class{defaultServer=`https://server.virtualdisplay.io`;options;serverHost;extraParams;constructor(e,t,n){this.options=e,this.serverHost=t,this.extraParams=n}create(){let e=this.createContainer(),t=this.createIframe();return e.appendChild(t),this.attachToParent(e),{container:e,iframe:t}}createContainer(){let e=document.createElement(`div`);return e.className=`vd-container`,Object.assign(e.style,{position:`relative`,width:`100%`,height:`100%`,overflow:`hidden`}),e}createIframe(){let e=document.createElement(`iframe`);return e.src=this.buildUrl(),e.setAttribute(`allow`,`xr-spatial-tracking; fullscreen`),e}attachToParent(e){this.getParentElement().appendChild(e)}buildUrl(){let e=this.getServerUrl(),t=new URL(e);this.setAddressParams(t),this.options.language!==void 0&&t.searchParams.set(`language`,this.options.language),this.options.session!==void 0&&t.searchParams.set(`session`,this.options.session),this.options.debug===!0&&t.searchParams.set(`debug`,`true`),this.options.traceparent!==void 0&&t.searchParams.set(`traceparent`,this.options.traceparent);for(let[e,n]of Object.entries(this.extraParams??{}))t.searchParams.set(e,n);return t.toString()}setAddressParams(e){this.options.app===void 0?(e.searchParams.set(`license`,this.options.license),e.searchParams.set(`model`,this.options.model)):(e.searchParams.set(`app`,this.options.app),(this.options.license!==void 0||this.options.model!==void 0)&&R.warn("Both `app` and `license`/`model` were supplied: `app` wins, the pair was ignored"))}getServerUrl(){return this.serverHost===void 0?this.defaultServer:this.serverHost}getParentElement(){if(typeof this.options.parent!=`string`)return this.options.parent;let e=document.querySelector(this.options.parent);if(e===null)throw M.parentNotFound(this.options.parent);return e}};function Kr(e){let{messenger:t}=e;t.on(u.HANDSHAKE,n=>{v(n)&&(R.info(`Server handshake received, flushing publisher queue`),t.markReady(),e.ui.viewerAlive())}),t.on(u.SESSION,t=>{y(t)&&e.onSession(t.sessionId)}),t.on(u.MUTATION,t=>{x(t)&&(e.attributes.handleMutationResult(t),e.configuration.handleSelectionChanged(e.attributes.getSelection()))}),t.on(u.SNAPSHOT,t=>{S(t)&&e.snapshot.handleSnapshotResult(t)}),t.on(u.CAMERA,t=>{C(t)&&e.cameraPosition.handlePositionUpdate(t)}),t.on(u.LOADING_INDICATOR,t=>{te(t)&&(t.error===void 0?e.ui.updateProgress(t.progress,t.phase):e.ui.showError(t.error))}),t.on(u.CONFIG,t=>{ie(t)&&e.applyConfig(t)}),t.on(u.MAPPING,t=>{ee(t)&&(e.attributes.handleMappingReceived(t),e.configuration.handleSelectionChanged(e.attributes.getSelection()),e.ui.renderModelControls(e.attributes,t.attributes),e.readyStateTracker.handleMappingReceived())}),qr(e)}function qr(e){let{messenger:t}=e;t.on(u.FOCUS,t=>{ae(t)&&e.focus.handleStateReceived(t)}),t.on(u.PRICING,t=>{oe(t)&&e.configuration.handlePricingReceived(t.pricing)}),t.on(u.SYNC,t=>{ne(t)&&e.onSync(t.connected)}),t.on(u.SELECTABLE,t=>{re(t)&&(e.selectable.handleSnapshot(t),e.ui.applySelectable(t.attributes))}),t.on(u.APP_RESOLVED,t=>{b(t)&&e.onAppResolved(t)})}var Jr=class{ready=!1;onReady;constructor(e){this.onReady=e}handleMappingReceived(){this.ready||(this.ready=!0,R.info(`Mapping received from server, client is now ready`),this.onReady?.())}get isReady(){return this.ready}clear(){this.ready=!1}};function Yr(e){if(e===void 0)return;let{annotations:t,...n}=e;return t===void 0?n:t===!0?{...n,annotations:`show`}:t===!1?{...n,annotations:`hide`}:{...n,annotations:t}}function Xr(e){if(!Array.isArray(e))return{};let t=e.filter(e=>typeof e==`string`);return t.length>0?{features:t}:{}}var Zr=class{attributes;selectableState;readyStateTracker;messenger;cameraApi;cameraPositionApi;focusApi;configurationApi;snapshotApi;annotationsApi;eventBus;ui;options;serverHost;iframeParams;arActivation;syncTracker;iframe;container;readyCallbacks=[];mutationFailedCallbacks=[];viewerSessionId;resolvedApp;appResolvedCallbacks=[];constructor(e,t){this.options=e;let n=t??{};this.serverHost=n.serverHost,this.iframeParams=n.iframeParams,this.initializeLogging(),this.messenger=new ce(()=>this.iframe?.contentWindow??null,{onHandlerError:(e,t)=>R.error(`Error handling ${e.type}`,t),...n.messengerOptions});let r=e=>{this.messenger.send(e)};this.attributes=new lt(r,d,(e,t)=>{this.notifyMutationFailed(e,t)}),this.selectableState=new ut,this.snapshotApi=new bt(r),this.annotationsApi=new ue(r,d),this.cameraApi=new dt(r),this.cameraPositionApi=new ft,this.focusApi=new _t(r,e=>{this.dispatchFocusChange(e)},d),this.configurationApi=new gt(e=>{this.dispatchConfigurationChange(e)},e=>{this.dispatchConfigurationSubmit(e)}),this.eventBus=new xt,this.arActivation=n.createArActivation?.(r),this.syncTracker=n.createSyncTracker?.(),this.readyStateTracker=new Jr(()=>{this.notifyReady()}),this.ui=this.createStandardInterface(),this.wireIncomingMessages(),n.registerHandlers?.(this.messenger,r),this.messenger.start(),this.mountIframe()}createStandardInterface(){let e=this.arActivation;return new Wr({snapshotApi:this.snapshotApi,cameraApi:this.cameraApi,cameraPositionApi:this.cameraPositionApi,eventBus:this.eventBus,configuration:this.configurationApi,onSelect:(e,t)=>this.attributes.select(e,t),onSelectTransient:(e,t)=>this.attributes.selectTransient(e,t),onSubscribe:(e,t)=>this.attributes.onChange(e,t),...e!==void 0&&{onAr:()=>{e.activate()}},onFullscreenEnter:()=>{this.trackFullscreen()},onAnnotationsToggle:e=>{this.sendControlAnnotationToggle(e)}})}sendControlAnnotationToggle(e){this.sendAnnotationToggle(e,`control`)}sendAnnotationToggle(e,t){this.messenger.send({type:u.ANNOTATION_TOGGLE,enabled:e,...t!==void 0&&{origin:t}})}wireIncomingMessages(){Kr({messenger:this.messenger,attributes:this.attributes,selectable:this.selectableState,configuration:this.configurationApi,snapshot:this.snapshotApi,cameraPosition:this.cameraPositionApi,focus:this.focusApi,ui:this.ui,readyStateTracker:this.readyStateTracker,applyConfig:e=>{this.handleConfig(e)},onSession:e=>{this.handleSession(e)},onSync:e=>{this.syncTracker?.handleSync(e)},onAppResolved:e=>{this.handleAppResolved({appType:e.appType,name:e.name,...e.slug!==void 0&&{slug:e.slug},...e.submit!==void 0&&{submit:e.submit},...Xr(e.features)})}})}handleAppResolved(e){this.resolvedApp=e;for(let t of this.appResolvedCallbacks)t(e)}handleSession(e){this.viewerSessionId=e,this.arActivation?.onSession(e)}notifyMutationFailed(e,t){for(let n of this.mutationFailedCallbacks)n({attribute:e,value:t})}notifyReady(){let e=this.readyCallbacks;this.readyCallbacks=[];for(let t of e)t(this);this.ui.onReady()}dispatchFocusChange(e){this.container?.dispatchEvent(new CustomEvent(Q.FOCUS_CHANGE,{detail:e,bubbles:!0}))}dispatchConfigurationChange(e){this.container?.dispatchEvent(new CustomEvent(Q.CONFIGURATION_CHANGE,{detail:e??null,bubbles:!0}))}dispatchConfigurationSubmit(e){this.container?.dispatchEvent(new CustomEvent(Q.CONFIGURATION_SUBMIT,{detail:e,bubbles:!0}))}handleConfig(e){let t=e.viewerSettings,n=Yr(this.options.viewerSettings);if(t!==void 0||n!==void 0){let e=n===void 0?t:{...t??{},...n};if(n!==void 0&&t!==void 0){let e=Object.entries(n).filter(([e,n])=>t[e]!==n).map(([e,n])=>`${e} (metadata: ${t[e]??`undefined`}, override: ${n})`);e.length>0&&R.warn(`Viewer settings override active: ${e.join(`, `)}`)}this.ui.applyViewerSettings(e),this.echoAnnotationsDifference(t?.annotations,e.annotations)}this.cameraPositionApi.applyLimits(e.cameraLimits)}echoAnnotationsDifference(e,t){t!==void 0&&t!==e&&this.sendAnnotationToggle(t===`show`||t===`toggle-shown`)}trackFullscreen(){this.messenger.send({type:u.FULLSCREEN})}initializeLogging(){this.options.debug===!0&&st(),R.info(`Initializing Virtualdisplay client`,{...this.options.app===void 0?{model:this.options.model}:{app:this.options.app}})}mountIframe(){let e=new Gr(this.options,this.serverHost,this.iframeParams).create();this.container=e.container,this.iframe=e.iframe,this.eventBus.attach(this.container),this.ui.attach(this.container);try{let e=new URL(this.iframe.src).origin;this.messenger.setTargetOrigin(e)}catch{}}select(e,t){this.attributes.select(e,t)}getValues(e){return this.attributes.getValues(e)}getValue(e,t){return this.attributes.getValue(e,t)}onChange(e,t){this.attributes.onChange(e,t)}getAttribute(e){return this.attributes.getAttribute(e)}get isReady(){return this.readyStateTracker.isReady}onReady(e){this.readyStateTracker.isReady?e(this):this.readyCallbacks.push(e)}onMutationFailed(e){this.mutationFailedCallbacks.push(e)}onSelectableChange(e){this.selectableState.onChange(e)}onAppResolved(e){this.appResolvedCallbacks.push(e),this.resolvedApp!==void 0&&e(this.resolvedApp)}getSelectable(e){return this.selectableState.selectableFor(e)}activateAr(){this.arActivation?.activate()}on(e,t){this.eventBus.on(e,t)}get annotations(){return this.annotationsApi}get camera(){return this.cameraApi}get focus(){return this.focusApi}get configuration(){return this.configurationApi}get cameraPosition(){return this.cameraPositionApi}get snapshot(){return this.snapshotApi}get sessionId(){return this.viewerSessionId}get viewerSettings(){return this.ui.viewerSettings}destroy(){this.readyStateTracker.clear(),this.readyCallbacks=[],this.mutationFailedCallbacks.length=0,this.snapshotApi.clear(),this.messenger.destroy(),this.arActivation?.destroy(),this.ui.destroy(),this.container?.parentElement!==null&&this.container?.parentElement!==void 0&&this.container.parentElement.removeChild(this.container),this.container=void 0,this.iframe=void 0}},Qr=`ar.virtualdisplay.io`;function $r(e){let t=new URL(`https://${Qr}/go`);return e.sessionId===void 0?e.app===void 0?e.license!==void 0&&e.model!==void 0&&(t.searchParams.set(`license`,e.license),t.searchParams.set(`model`,e.model)):t.searchParams.set(`app`,e.app):t.searchParams.set(`session`,e.sessionId),t.toString()}var ei=1500,ti=class{options;qrModal=new Gn;sessionId;waiters=[];pendingTimers=new Set;destroyed=!1;constructor(e){this.options=e}onSession(e){this.sessionId=e;let t=this.waiters;this.waiters=[];for(let n of t)n(e)}activate(){nt()?this.options.send({type:u.AR_ACTIVATE}):this.showQrCode()}destroy(){this.destroyed=!0;for(let e of this.pendingTimers)clearTimeout(e);this.pendingTimers.clear(),this.waiters=[],this.qrModal.hide()}async showQrCode(){this.qrModal.show();let e=await this.waitForSessionId();if(this.destroyed)return;let t=$r({sessionId:e,app:this.options.app,license:this.options.license,model:this.options.model}),n;try{n=await this.qrModal.update(t)}catch(e){R.warn(`AR QR code could not be rendered`,{error:e});return}this.destroyed?this.qrModal.hide():n&&this.options.send({type:u.QR_SHOWN})}waitForSessionId(){return this.sessionId===void 0?new Promise(e=>{let t=setTimeout(()=>{this.pendingTimers.delete(t),e(void 0)},ei);this.pendingTimers.add(t),this.waiters.push(n=>{this.pendingTimers.delete(t),clearTimeout(t),e(n)})}):Promise.resolve(this.sessionId)}},ni=class{callbacks=[];lastKnown;handleSync(e){this.lastKnown=e;for(let t of this.callbacks)t(e)}onChange(e){this.callbacks.push(e),this.lastKnown!==void 0&&e(this.lastKnown)}},ri=class extends Zr{syncStatusTracker;constructor(e){let t=new ni;super(e,{createArActivation:t=>new ti({app:e.app,license:e.license,model:e.model,send:t}),createSyncTracker:()=>t}),this.syncStatusTracker=t}onSyncChange(e){this.syncStatusTracker.onChange(e)}};e.AVAILABILITY=m,e.Annotations=ue,e.Attribute=Re,e.AttributeValue=de,e.Camera=dt,e.CameraPosition=ft,e.Configuration=gt,e.ERROR_CODES=j,e.Focus=_t,e.Photo=vt,e.Snapshot=bt,e.VD_EVENTS=Q,e.VirtualdisplayClient=ri,e.VirtualdisplayError=M,e.enableDebugMode=st,e.isDebugMode=ct,Object.defineProperty(e,"logger",{enumerable:!0,get:function(){return R}})});
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@virtualdisplay.io/client",
3
3
  "description": "TypeScript-first 3D model integration library with iframe-based architecture",
4
- "version": "4.0.0-alpha.33",
4
+ "version": "4.0.0-alpha.34",
5
5
  "author": "Virtualdisplay <support@virtualdisplay.io>",
6
6
  "homepage": "https://virtualdisplay.io",
7
7
  "license": "MIT",