@virtualdisplay.io/client 4.0.0-alpha.1 → 4.0.0-alpha.3
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 +12 -0
- package/dist/src/attributes/attribute.d.ts +38 -0
- package/dist/src/attributes/attribute.d.ts.map +1 -0
- package/dist/src/attributes/attributes.d.ts +43 -0
- package/dist/src/attributes/attributes.d.ts.map +1 -0
- package/dist/src/attributes/selections.d.ts +16 -0
- package/dist/src/attributes/selections.d.ts.map +1 -0
- package/dist/src/attributes/value.d.ts +13 -0
- package/dist/src/attributes/value.d.ts.map +1 -0
- package/dist/src/camera/camera.d.ts +40 -0
- package/dist/src/camera/camera.d.ts.map +1 -0
- package/dist/src/camera/index.d.ts +4 -0
- package/dist/src/camera/index.d.ts.map +1 -0
- package/dist/src/camera/position.d.ts +43 -0
- package/dist/src/camera/position.d.ts.map +1 -0
- package/dist/src/client/client.d.ts +83 -0
- package/dist/src/client/client.d.ts.map +1 -0
- package/dist/src/client/error.d.ts +26 -0
- package/dist/src/client/error.d.ts.map +1 -0
- package/dist/src/client/iframe-builder.d.ts +25 -0
- package/dist/src/client/iframe-builder.d.ts.map +1 -0
- package/dist/src/client/options.d.ts +17 -0
- package/dist/src/client/options.d.ts.map +1 -0
- package/dist/src/client/ready-state-tracker.d.ts +26 -0
- package/dist/src/client/ready-state-tracker.d.ts.map +1 -0
- package/dist/src/client/types.d.ts +5 -0
- package/dist/src/client/types.d.ts.map +1 -0
- package/dist/src/index.d.ts +11 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/snapshot/index.d.ts +3 -0
- package/dist/src/snapshot/index.d.ts.map +1 -0
- package/dist/src/snapshot/photo.d.ts +47 -0
- package/dist/src/snapshot/photo.d.ts.map +1 -0
- package/dist/src/snapshot/snapshot.d.ts +30 -0
- package/dist/src/snapshot/snapshot.d.ts.map +1 -0
- package/dist/src/ui/viewer-config.d.ts +63 -0
- package/dist/src/ui/viewer-config.d.ts.map +1 -0
- package/dist/src/utils/logger.d.ts +11 -0
- package/dist/src/utils/logger.d.ts.map +1 -0
- package/dist/virtualdisplay.client.cjs.js +1 -2
- package/dist/virtualdisplay.client.es.js +798 -2
- package/dist/virtualdisplay.client.umd.js +1 -2
- package/package.json +3 -3
- package/dist/index.d.ts +0 -415
- package/dist/virtualdisplay.client.cjs.js.map +0 -1
- package/dist/virtualdisplay.client.es.js.map +0 -1
- package/dist/virtualdisplay.client.umd.js.map +0 -1
|
@@ -1,2 +1,798 @@
|
|
|
1
|
-
const e={NO_MAPPING:"NO_MAPPING",ATTRIBUTE_NOT_FOUND:"ATTRIBUTE_NOT_FOUND",VALUE_NOT_FOUND:"VALUE_NOT_FOUND",PARENT_NOT_FOUND:"PARENT_NOT_FOUND",INVALID_PARAMETER:"INVALID_PARAMETER",SNAPSHOT_FAILED:"SNAPSHOT_FAILED"};class t extends Error{code;constructor(e,i){super(e),this.name="VirtualdisplayError",this.code=i,void 0!==Error.captureStackTrace&&Error.captureStackTrace(this,t)}static noMapping(){return new t("No attributes available. Waiting for server metadata.",e.NO_MAPPING)}static attributeNotFound(i){return new t(`Attribute "${i}" not found in mapping`,e.ATTRIBUTE_NOT_FOUND)}static valueNotFound(i,n){return new t(`Value "${n}" not found for attribute "${i}"`,e.VALUE_NOT_FOUND)}static parentNotFound(i){return new t(`Parent element not found: ${i}`,e.PARENT_NOT_FOUND)}static invalidParameter(i){return new t(i,e.INVALID_PARAMETER)}static snapshotFailed(i,n){return new t(`Snapshot failed for "${i}": ${n}`,e.SNAPSHOT_FAILED)}}const i={};class n{defaultServer="https://server.virtualdisplay.io";options;constructor(e){this.options=e}create(){const e=this.createIframe();return this.attachToParent(e),e}createIframe(){const e=document.createElement("iframe");return e.src=this.buildUrl(),Object.assign(e.style,{width:"100%",height:"100%",border:"none"}),e.setAttribute("allow","xr-spatial-tracking; fullscreen"),e}attachToParent(e){this.getParentElement().appendChild(e)}buildUrl(){const e=this.getServerUrl(),t=new URL(e);return t.searchParams.set("license",this.options.license),t.searchParams.set("model",this.options.model),!0===this.options.debug&&t.searchParams.set("debug","true"),void 0!==this.options.language&&t.searchParams.set("language",this.options.language),t.toString()}getServerUrl(){if(void 0===i?.VITE_VIRTUALDISPLAY_SERVER_HOST)return this.defaultServer}getParentElement(){if("string"!=typeof this.options.parent)return this.options.parent;const e=document.querySelector(this.options.parent);if(null===e)throw t.parentNotFound(this.options.parent);return e}}function s(e,t){const i=t?function(e){const t=new Date(e.timestamp).toLocaleTimeString("en-GB",{hour12:!1}),i=e.level.toUpperCase().padEnd(5),n=e.trace_id?.slice(0,8)??"--------",s=e.msg,a=["timestamp","level","msg","service","trace_id","span_id"],r=Object.entries(e).filter(([e])=>!a.includes(e)).map(([e,t])=>`${e}=${JSON.stringify(t)}`).join(" ");return`${t} ${i} [${n}] ${s}${r?" "+r:""}`}(e):function(e){return JSON.stringify(e)}(e);"error"===e.level?console.error(i):"warn"===e.level?console.warn(i):console.log(i)}class a{constructor(e){this.config=e}log(e,t,i={}){const n=this.config.traceProvider?.()??{};var a;s({timestamp:(a=/* @__PURE__ */new Date,a.toISOString()),level:e,msg:t,service:this.config.service,...n,...i},this.config.isDev)}debug(e,t){this.config.isDev&&this.log("debug",e,t)}info(e,t){this.log("info",e,t)}warn(e,t){this.log("warn",e,t)}error(e,t){this.log("error",e,t)}with(e){const t=new a(this.config);return t.log=((t,i,n={})=>{this.log(t,i,{...e,...n})}).bind(this),t}}function r(e,t){const i=void 0!==t?.isDev?t.isDev:"undefined"==typeof process||"production"!==process.env.NODE_ENV;return new a({service:e,isDev:i,traceProvider:t?.traceProvider})}function o(e){if(void 0!==e)return"object"!=typeof e||null===e||Array.isArray(e)||e instanceof Error?e instanceof Error?{error:e.message}:{value:e}:e}function l(e){return{debug:(t,i)=>e.debug(t,o(i)),info:(t,i)=>e.info(t,o(i)),warn:(t,i)=>e.warn(t,o(i)),error:(t,i)=>e.error(t,o(i))}}let d=!1,u=l(r("client",{isDev:!1}));function h(){d=!0,u=l(r("client",{isDev:!0}))}function c(){return d}class g{ready=!1;onReady;constructor(e){this.onReady=e}handleMappingReceived(){this.markReady("Mapping received from server")}handleMutationResult(e){e.isInitial&&this.markReady("Initial mutations processed")}get isReady(){return this.ready}clear(){this.ready=!1}markReady(e){this.ready||(this.ready=!0,u.info(`${e} - client is now ready`),this.onReady?.())}}class f{constructor(e,t){this.value=e,this.attribute=t}isSelectedValue=!1;get isSelected(){return this.isSelectedValue}setSelected(e){this.isSelectedValue=e}}class p{name;defaultValue;values;onSelect;onChangeCallback;constructor(e){this.name=e.name,this.defaultValue=e.defaultValue,this.onSelect=e.onSelect,this.values=this.createValues(e.values)}select(e){if(!this.values.has(e))throw t.valueNotFound(this.name,e);this.onSelect(this.name,e)}getValues(){return Array.from(this.values.values())}getValue(e){return this.values.get(e)}onChange(e){this.onChangeCallback=e}handleResult(e){let t;for(const i of this.values.values()){const n=i.value===e;i.setSelected(n),n&&(t=i)}void 0!==t&&void 0!==this.onChangeCallback&&this.onChangeCallback(t)}createValues(e){const t=/* @__PURE__ */new Map;for(const i of e){const e=new f(i,this.name);i===this.defaultValue&&e.setSelected(!0),t.set(i,e)}return t}}class m{attributes=/* @__PURE__ */new Map;constructor(e,t,i){for(const n of e){const e=this.buildOptions(n,t);this.attributes.set(n.name,new p(e))}this.onMutationFailed=i}onMutationFailed;get(e){return this.attributes.get(e)}defaults(){const e=[];for(const t of this.attributes.values())void 0!==t.defaultValue&&e.push({name:t.name,value:t.defaultValue});return e}handleResults(e){for(const t of e)t.success?this.get(t.name)?.handleResult(t.value):this.onMutationFailed?.(t.name,t.value)}buildOptions(e,t){const i={name:e.name,values:e.values,onSelect:(e,i)=>{t([{name:e,value:i}],!1)}};return void 0!==e.defaultValue?{...i,defaultValue:e.defaultValue}:i}}const b={READY:"ready",MUTATION:"mutation",STATE:"state",CONFIG:"config",CAMERA:"camera",SNAPSHOT:"snapshot",MAPPING:"mapping"},v=new Set(Object.values(b));function y(e){return"object"!=typeof e||null===e?null:e}class A{constructor(e){this.processor=e}pending=[];isReady=!1;enqueue(e){this.isReady?this.processor(e):this.pending.push(e)}markReady(){if(this.isReady)return;if(this.isReady=!0,0===this.pending.length)return;const e=[...this.pending];this.pending.length=0;for(const t of e)this.processor(t)}get ready(){return this.isReady}get pendingCount(){return this.pending.length}hasPending(e){return this.pending.some(t=>t.type===e)}clear(){this.pending.length=0}}class E{constructor(e,t){this.getTarget=e,this.sourceId=`vd-${Math.random().toString(36).slice(2,8)}`,this.publisher=new A(e=>this.post(e)),this.consumer=new A(e=>this.routeToHandler(e)),this.shouldBuffer=t?.shouldBuffer??null,!0!==t?.bufferIncoming&&this.consumer.markReady()}handlers=/* @__PURE__ */new Map;publisher;consumer;shouldBuffer;listener=null;sourceId;on(e,t){this.handlers.set(e,t)}off(e){this.handlers.delete(e)}send(e){this.publisher.enqueue(e)}markReady(){this.publisher.markReady()}markConsumerReady(){this.consumer.markReady()}consumerHasPending(e){return this.consumer.hasPending(e)}start(){null===this.listener&&(this.listener=e=>{const{data:t}=e;if(!function(e){if("object"!=typeof e||null===e)return!1;const t=e;return"string"!=typeof t.target&&"string"==typeof t.type&&v.has(t.type)}(t))return;if(t._source===this.sourceId)return;const i=t;null===this.shouldBuffer||this.shouldBuffer(i)?this.consumer.enqueue(i):this.routeToHandler(i)},window.addEventListener("message",this.listener))}destroy(){null!==this.listener&&(window.removeEventListener("message",this.listener),this.listener=null),this.publisher.clear(),this.consumer.clear(),this.handlers.clear()}get ready(){return this.publisher.ready}get pendingCount(){return this.publisher.pendingCount}post(e){const t=this.getTarget();null!==t&&t.postMessage({...e,_source:this.sourceId},"*")}routeToHandler(e){const t=this.handlers.get(e.type);if(void 0===t)return;const i=t(e);i instanceof Promise&&i.catch(t=>{const i=t instanceof Error?t.message:String(t);console.error(`Virtualdisplay: error handling ${e.type}: ${i}`)})}}class C{constructor(e,t){this.send=e,this.onMutationFailed=t}registry;pendingCallbacks=[];handleMappingReceived(e){u.debug("Initializing from server mapping",{attributeCount:e.attributes.length}),this.registry=new m(e.attributes,(e,t)=>this.sendMutation(e,t),this.onMutationFailed);const t=this.registry.defaults();t.length>0&&this.sendMutation(t,!0),this.replayPendingCallbacks()}handleMutationResult(e){this.registry?.handleResults(e.results)}select(e,t){this.sendMutation([{name:e,value:t}],!1)}getValues(e){return this.registry?.get(e)?.getValues()??[]}getValue(e,t){return this.registry?.get(e)?.getValue(t)}onChange(e,t){if(void 0===this.registry)return void this.pendingCallbacks.push({name:e,callback:t});const i=this.registry.get(e);void 0!==i?i.onChange(t):u.warn(`onChange: attribute "${e}" not found — callback will not fire`)}getAttribute(e){return this.registry?.get(e)}get hasMapping(){return void 0!==this.registry}sendMutation(e,t){const i={type:b.MUTATION,mutations:e,isInitial:t};this.send(i)}replayPendingCallbacks(){for(const{name:e,callback:t}of this.pendingCallbacks){const i=this.registry?.get(e);void 0===i&&u.warn(`onChange: attribute "${e}" not found — buffered callback will not fire`),i?.onChange(t)}this.pendingCallbacks.length=0}}class I{constructor(e){this.send=e}commands=[];rotate(e){return this.validateFiniteNumber(e,"rotate"),this.commands.push({action:"rotate",value:e}),this}tilt(e){return this.validateFiniteNumber(e,"tilt"),this.commands.push({action:"tilt",value:e}),this}zoom(e){return this.validateFiniteNumber(e,"zoom"),this.commands.push({action:"zoom",value:e}),this}set(){if(0===this.commands.length)throw t.invalidParameter("No camera commands to execute. Call rotate(), tilt(), or zoom() before set().");const e={type:b.CAMERA,commands:this.commands};this.send(e),this.commands=[]}validateFiniteNumber(e,i){if(!Number.isFinite(e))throw t.invalidParameter(`${i}() requires a finite number, got ${String(e)}`)}reset(){const e={type:b.CAMERA,commands:[{action:"reset"}]};this.send(e)}}class w{state;changeCallbacks=[];constructor(){this.state={rotation:0,tilt:0,zoom:0}}get rotation(){return this.state.rotation}get tilt(){return this.state.tilt}get zoom(){return this.state.zoom}onChange(e){this.changeCallbacks.push(e)}handlePositionUpdate(e){this.update(e.transforms)}update(e){let t=!1;for(const i of e)switch(i.type){case"rotation":this.state.rotation=i.value,t=!0;break;case"tilt":this.state.tilt=i.value,t=!0;break;case"zoom":this.state.zoom=i.value,t=!0}if(t){const e={rotation:this.rotation,tilt:this.tilt,zoom:this.zoom};for(const t of this.changeCallbacks)t(e)}}}class S{constructor(e){this.filename=e}developedCallbacks=/* @__PURE__ */new Set;errorCallbacks=/* @__PURE__ */new Set;developed=!1;failed=!1;photoData=null;onDeveloped(e){return this.developed&&null!==this.photoData?(e(this.photoData),this):(this.developedCallbacks.add(e),this)}onError(e){return this.errorCallbacks.add(e),this}getFilename(){return this.filename}develop(e){this.developed||this.failed||(this.photoData=e,this.developed=!0,this.developedCallbacks.forEach(e=>{e(this.photoData)}),this.developedCallbacks.clear(),this.errorCallbacks.clear())}fail(e){this.developed||this.failed||(this.failed=!0,this.errorCallbacks.forEach(t=>{t(e)}),this.developedCallbacks.clear(),this.errorCallbacks.clear())}}class R{constructor(e){this.send=e}validExtensions=[".png"];pendingPhotos=/* @__PURE__ */new Map;take(e){this.validateFilename(e),u.debug("Taking snapshot",{filename:e});const t=new S(e);return this.pendingPhotos.set(t.getFilename(),t),this.send({type:b.SNAPSHOT,filename:e}),t}handleSnapshotResult(i){const n=this.pendingPhotos.get(i.filename);void 0!==n?(this.pendingPhotos.delete(i.filename),void 0===i.error?void 0!==i.data&&n.develop({filename:i.filename,data:i.data}):n.fail(new t(i.error,e.SNAPSHOT_FAILED))):u.warn("No pending photo found for filename",{filename:i.filename,pendingFilenames:Array.from(this.pendingPhotos.keys())})}validateFilename(i){if(""===i||"string"!=typeof i)throw new t("Filename must be a non-empty string",e.INVALID_PARAMETER);if(!this.validExtensions.some(e=>i.toLowerCase().endsWith(e)))throw new t(`Invalid filename: "${i}". Filename must end with one of: ${this.validExtensions.join(", ")}`,e.INVALID_PARAMETER);if(i.includes("..")||i.includes("/")||i.includes("\\"))throw new t('Filename cannot contain path separators or ".."',e.INVALID_PARAMETER)}}class N{send;constructor(e){this.send=e}sendInitialConfig(e){const t=this.buildUIConfig(e),i=this.buildViewerConfig(t,e.camera);void 0!==i&&this.sendConfig(i)}buildUIConfig(e){const t=this.extractUIValues(e);if(Object.values(t).some(e=>void 0!==e))return{...void 0!==t.arEnabled&&{arEnabled:t.arEnabled},...void 0!==t.fullscreenEnabled&&{fullscreenEnabled:t.fullscreenEnabled},...void 0!==t.loadingIndicatorEnabled&&{loadingIndicatorEnabled:t.loadingIndicatorEnabled}}}extractUIValues(e){return{arEnabled:e.arEnabled??e.ui?.arEnabled,fullscreenEnabled:e.fullscreenEnabled??e.ui?.fullscreenEnabled,loadingIndicatorEnabled:e.loadingIndicatorEnabled??e.ui?.loadingIndicatorEnabled}}buildViewerConfig(e,t){if(void 0!==e||void 0!==t)return{...void 0!==e&&{ui:e},...void 0!==t&&{camera:t}}}setArEnabled(e){u.debug(`Setting AR button enabled: ${e}`),this.updateUIConfig({arEnabled:e})}setFullscreenEnabled(e){u.debug(`Setting fullscreen button enabled: ${e}`),this.updateUIConfig({fullscreenEnabled:e})}setLoadingIndicatorEnabled(e){u.debug(`Setting loading indicator enabled: ${e}`),this.updateUIConfig({loadingIndicatorEnabled:e})}updateUIConfig(e){u.debug("Updating UI configuration",e),Object.keys(e).length>0&&this.sendConfig({ui:e})}hideAllUI(){u.debug("Hiding all UI elements"),this.sendUIConfig({arEnabled:!1,fullscreenEnabled:!1,loadingIndicatorEnabled:!1})}showAllUI(){u.debug("Showing all UI elements"),this.sendUIConfig({arEnabled:!0,fullscreenEnabled:!0,loadingIndicatorEnabled:!0})}sendUIConfig(e){this.sendConfig({ui:e})}sendConfig(e){const t={type:b.CONFIG,config:e};u.debug("Sending config",t),this.send(t)}}class T{attributes;readyStateTracker;messenger;viewerService;cameraApi;cameraPositionApi;snapshotApi;options;iframe;readyCallbacks=[];mutationFailedCallbacks=[];constructor(e){this.options=e,this.initializeLogging(),this.messenger=new E(()=>this.iframe?.contentWindow??null);const t=e=>{this.messenger.send(e)};this.attributes=new C(t,(e,t)=>{for(const i of this.mutationFailedCallbacks)i({attribute:e,value:t})}),this.readyStateTracker=new g(()=>{const e=this.readyCallbacks;this.readyCallbacks=[];for(const t of e)t(this)}),this.viewerService=new N(t),this.cameraApi=new I(t),this.cameraPositionApi=new w,this.snapshotApi=new R(t),this.registerHandlers(),this.messenger.start(),this.createAndConnectIframe()}registerHandlers(){this.messenger.on(b.READY,e=>{(function(e){const t=y(e);return null!==t&&t.type===b.READY})(e)&&(u.info("Server ready — flushing publisher queue"),this.messenger.markReady(),this.viewerService.sendInitialConfig(this.options))}),this.messenger.on(b.MUTATION,e=>{(function(e){const t=y(e);return null!==t&&t.type===b.MUTATION&&Array.isArray(t.results)})(e)&&(this.attributes.handleMutationResult(e),this.readyStateTracker.handleMutationResult(e))}),this.messenger.on(b.SNAPSHOT,e=>{(function(e){const t=y(e);return null!==t&&t.type===b.SNAPSHOT&&("data"in t||"error"in t)})(e)&&this.snapshotApi.handleSnapshotResult(e)}),this.messenger.on(b.CAMERA,e=>{(function(e){const t=y(e);return null!==t&&t.type===b.CAMERA&&Array.isArray(t.transforms)})(e)&&this.cameraPositionApi.handlePositionUpdate(e)}),this.messenger.on(b.MAPPING,e=>{(function(e){const t=y(e);return null!==t&&t.type===b.MAPPING&&Array.isArray(t.attributes)})(e)&&(this.attributes.handleMappingReceived(e),this.readyStateTracker.handleMappingReceived())})}initializeLogging(){!0===this.options.debug&&h(),u.info("Initializing Virtualdisplay client",{model:this.options.model,debug:this.options.debug,language:this.options.language})}createAndConnectIframe(){u.debug("Creating iframe for Virtualdisplay viewer");const e=new n(this.options);this.iframe=e.create(),u.debug("Iframe created, waiting for server READY")}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)}get viewer(){return this.viewerService}get camera(){return this.cameraApi}get cameraPosition(){return this.cameraPositionApi}get snapshot(){return this.snapshotApi}destroy(){u.info("Destroying Virtualdisplay client"),this.readyStateTracker.clear(),this.readyCallbacks=[],this.messenger.destroy(),null!==this.iframe?.parentElement&&void 0!==this.iframe?.parentElement&&this.iframe.parentElement.removeChild(this.iframe),this.iframe=void 0,u.debug("Virtualdisplay client destroyed")}}export{p as Attribute,f as AttributeValue,I as Camera,e as ERROR_CODES,S as Photo,R as Snapshot,T as VirtualdisplayClient,t as VirtualdisplayError,N as VirtualdisplayViewerService,h as enableDebugMode,c as isDebugMode,u as logger};
|
|
2
|
-
|
|
1
|
+
//#region src/client/error.ts
|
|
2
|
+
var e = {
|
|
3
|
+
NO_MAPPING: "NO_MAPPING",
|
|
4
|
+
ATTRIBUTE_NOT_FOUND: "ATTRIBUTE_NOT_FOUND",
|
|
5
|
+
VALUE_NOT_FOUND: "VALUE_NOT_FOUND",
|
|
6
|
+
PARENT_NOT_FOUND: "PARENT_NOT_FOUND",
|
|
7
|
+
INVALID_PARAMETER: "INVALID_PARAMETER",
|
|
8
|
+
SNAPSHOT_FAILED: "SNAPSHOT_FAILED"
|
|
9
|
+
}, t = class t extends Error {
|
|
10
|
+
code;
|
|
11
|
+
constructor(e, n) {
|
|
12
|
+
super(e), this.name = "VirtualdisplayError", this.code = n, Error.captureStackTrace?.(this, t);
|
|
13
|
+
}
|
|
14
|
+
static noMapping() {
|
|
15
|
+
return new t("No attributes available. Waiting for server metadata.", e.NO_MAPPING);
|
|
16
|
+
}
|
|
17
|
+
static attributeNotFound(n) {
|
|
18
|
+
return new t(`Attribute "${n}" not found in mapping`, e.ATTRIBUTE_NOT_FOUND);
|
|
19
|
+
}
|
|
20
|
+
static valueNotFound(n, r) {
|
|
21
|
+
return new t(`Value "${r}" not found for attribute "${n}"`, e.VALUE_NOT_FOUND);
|
|
22
|
+
}
|
|
23
|
+
static parentNotFound(n) {
|
|
24
|
+
return new t(`Parent element not found: ${n}`, e.PARENT_NOT_FOUND);
|
|
25
|
+
}
|
|
26
|
+
static invalidParameter(n) {
|
|
27
|
+
return new t(n, e.INVALID_PARAMETER);
|
|
28
|
+
}
|
|
29
|
+
static snapshotFailed(n, r) {
|
|
30
|
+
return new t(`Snapshot failed for "${n}": ${r}`, e.SNAPSHOT_FAILED);
|
|
31
|
+
}
|
|
32
|
+
}, n = class {
|
|
33
|
+
defaultServer = "https://server.virtualdisplay.io";
|
|
34
|
+
options;
|
|
35
|
+
constructor(e) {
|
|
36
|
+
this.options = e;
|
|
37
|
+
}
|
|
38
|
+
create() {
|
|
39
|
+
let e = this.createIframe();
|
|
40
|
+
return this.attachToParent(e), e;
|
|
41
|
+
}
|
|
42
|
+
createIframe() {
|
|
43
|
+
let e = document.createElement("iframe");
|
|
44
|
+
return e.src = this.buildUrl(), Object.assign(e.style, {
|
|
45
|
+
width: "100%",
|
|
46
|
+
height: "100%",
|
|
47
|
+
border: "none"
|
|
48
|
+
}), e.setAttribute("allow", "xr-spatial-tracking; fullscreen"), e;
|
|
49
|
+
}
|
|
50
|
+
attachToParent(e) {
|
|
51
|
+
this.getParentElement().appendChild(e);
|
|
52
|
+
}
|
|
53
|
+
buildUrl() {
|
|
54
|
+
let e = this.getServerUrl(), t = new URL(e);
|
|
55
|
+
return t.searchParams.set("license", this.options.license), t.searchParams.set("model", this.options.model), this.options.debug === !0 && t.searchParams.set("debug", "true"), this.options.language !== void 0 && t.searchParams.set("language", this.options.language), t.toString();
|
|
56
|
+
}
|
|
57
|
+
getServerUrl() {
|
|
58
|
+
return this.defaultServer;
|
|
59
|
+
}
|
|
60
|
+
getParentElement() {
|
|
61
|
+
if (typeof this.options.parent != "string") return this.options.parent;
|
|
62
|
+
let e = document.querySelector(this.options.parent);
|
|
63
|
+
if (e === null) throw t.parentNotFound(this.options.parent);
|
|
64
|
+
return e;
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
//#endregion
|
|
68
|
+
//#region ../logger/src/format.ts
|
|
69
|
+
function r(e) {
|
|
70
|
+
let t = new Date(e.timestamp).toLocaleTimeString("en-GB", { hour12: !1 }), n = e.level.toUpperCase().padEnd(5), r = e.trace_id?.slice(0, 8) ?? "--------", i = e.msg, a = [
|
|
71
|
+
"timestamp",
|
|
72
|
+
"level",
|
|
73
|
+
"msg",
|
|
74
|
+
"service",
|
|
75
|
+
"trace_id",
|
|
76
|
+
"span_id"
|
|
77
|
+
], o = Object.entries(e).filter(([e]) => !a.includes(e)).map(([e, t]) => `${e}=${JSON.stringify(t)}`).join(" ");
|
|
78
|
+
return `${t} ${n} [${r}] ${i}${o ? " " + o : ""}`;
|
|
79
|
+
}
|
|
80
|
+
function i(e) {
|
|
81
|
+
return JSON.stringify(e);
|
|
82
|
+
}
|
|
83
|
+
//#endregion
|
|
84
|
+
//#region ../logger/src/write.ts
|
|
85
|
+
function a(e, t) {
|
|
86
|
+
let n = t ? r(e) : i(e);
|
|
87
|
+
e.level === "error" ? console.error(n) : e.level === "warn" ? console.warn(n) : console.log(n);
|
|
88
|
+
}
|
|
89
|
+
//#endregion
|
|
90
|
+
//#region ../utils/src/date.ts
|
|
91
|
+
function o() {
|
|
92
|
+
return /* @__PURE__ */ new Date();
|
|
93
|
+
}
|
|
94
|
+
function s(e) {
|
|
95
|
+
return e.toISOString();
|
|
96
|
+
}
|
|
97
|
+
//#endregion
|
|
98
|
+
//#region ../logger/src/logger.ts
|
|
99
|
+
var c = class e {
|
|
100
|
+
constructor(e) {
|
|
101
|
+
this.config = e;
|
|
102
|
+
}
|
|
103
|
+
log(e, t, n = {}) {
|
|
104
|
+
let r = this.config.traceProvider?.() ?? {};
|
|
105
|
+
a({
|
|
106
|
+
timestamp: s(o()),
|
|
107
|
+
level: e,
|
|
108
|
+
msg: t,
|
|
109
|
+
service: this.config.service,
|
|
110
|
+
...r,
|
|
111
|
+
...n
|
|
112
|
+
}, this.config.isDev);
|
|
113
|
+
}
|
|
114
|
+
debug(e, t) {
|
|
115
|
+
this.config.isDev && this.log("debug", e, t);
|
|
116
|
+
}
|
|
117
|
+
info(e, t) {
|
|
118
|
+
this.log("info", e, t);
|
|
119
|
+
}
|
|
120
|
+
warn(e, t) {
|
|
121
|
+
this.log("warn", e, t);
|
|
122
|
+
}
|
|
123
|
+
error(e, t) {
|
|
124
|
+
this.log("error", e, t);
|
|
125
|
+
}
|
|
126
|
+
with(t) {
|
|
127
|
+
let n = new e(this.config);
|
|
128
|
+
return n.log = ((e, n, r = {}) => {
|
|
129
|
+
this.log(e, n, {
|
|
130
|
+
...t,
|
|
131
|
+
...r
|
|
132
|
+
});
|
|
133
|
+
}).bind(this), n;
|
|
134
|
+
}
|
|
135
|
+
};
|
|
136
|
+
function l(e, t) {
|
|
137
|
+
return new c({
|
|
138
|
+
service: e,
|
|
139
|
+
isDev: t?.isDev === void 0 ? typeof process < "u" ? process.env.NODE_ENV !== "production" : !0 : t.isDev,
|
|
140
|
+
traceProvider: t?.traceProvider
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
//#endregion
|
|
144
|
+
//#region src/utils/logger.ts
|
|
145
|
+
function u(e) {
|
|
146
|
+
if (e !== void 0) return typeof e == "object" && e && !Array.isArray(e) && !(e instanceof Error) ? e : e instanceof Error ? { error: e.message } : { value: e };
|
|
147
|
+
}
|
|
148
|
+
function d(e) {
|
|
149
|
+
return {
|
|
150
|
+
debug: (t, n) => e.debug(t, u(n)),
|
|
151
|
+
info: (t, n) => e.info(t, u(n)),
|
|
152
|
+
warn: (t, n) => e.warn(t, u(n)),
|
|
153
|
+
error: (t, n) => e.error(t, u(n))
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
var f = !1, p = d(l("client", { isDev: !1 }));
|
|
157
|
+
function m() {
|
|
158
|
+
f = !0, p = d(l("client", { isDev: !0 }));
|
|
159
|
+
}
|
|
160
|
+
function h() {
|
|
161
|
+
return f;
|
|
162
|
+
}
|
|
163
|
+
//#endregion
|
|
164
|
+
//#region src/client/ready-state-tracker.ts
|
|
165
|
+
var g = class {
|
|
166
|
+
ready = !1;
|
|
167
|
+
onReady;
|
|
168
|
+
constructor(e) {
|
|
169
|
+
this.onReady = e;
|
|
170
|
+
}
|
|
171
|
+
handleMappingReceived() {
|
|
172
|
+
this.markReady("Mapping received from server");
|
|
173
|
+
}
|
|
174
|
+
handleMutationResult(e) {
|
|
175
|
+
e.isInitial && this.markReady("Initial mutations processed");
|
|
176
|
+
}
|
|
177
|
+
get isReady() {
|
|
178
|
+
return this.ready;
|
|
179
|
+
}
|
|
180
|
+
clear() {
|
|
181
|
+
this.ready = !1;
|
|
182
|
+
}
|
|
183
|
+
markReady(e) {
|
|
184
|
+
this.ready || (this.ready = !0, p.info(`${e} - client is now ready`), this.onReady?.());
|
|
185
|
+
}
|
|
186
|
+
}, _ = class {
|
|
187
|
+
isSelectedValue = !1;
|
|
188
|
+
constructor(e, t) {
|
|
189
|
+
this.value = e, this.attribute = t;
|
|
190
|
+
}
|
|
191
|
+
get isSelected() {
|
|
192
|
+
return this.isSelectedValue;
|
|
193
|
+
}
|
|
194
|
+
setSelected(e) {
|
|
195
|
+
this.isSelectedValue = e;
|
|
196
|
+
}
|
|
197
|
+
}, v = class {
|
|
198
|
+
name;
|
|
199
|
+
defaultValue;
|
|
200
|
+
values;
|
|
201
|
+
onSelect;
|
|
202
|
+
onChangeCallback;
|
|
203
|
+
constructor(e) {
|
|
204
|
+
this.name = e.name, this.defaultValue = e.defaultValue, this.onSelect = e.onSelect, this.values = this.createValues(e.values);
|
|
205
|
+
}
|
|
206
|
+
select(e) {
|
|
207
|
+
if (!this.values.has(e)) throw t.valueNotFound(this.name, e);
|
|
208
|
+
this.onSelect(this.name, e);
|
|
209
|
+
}
|
|
210
|
+
getValues() {
|
|
211
|
+
return Array.from(this.values.values());
|
|
212
|
+
}
|
|
213
|
+
getValue(e) {
|
|
214
|
+
return this.values.get(e);
|
|
215
|
+
}
|
|
216
|
+
onChange(e) {
|
|
217
|
+
this.onChangeCallback = e;
|
|
218
|
+
}
|
|
219
|
+
handleResult(e) {
|
|
220
|
+
let t;
|
|
221
|
+
for (let n of this.values.values()) {
|
|
222
|
+
let r = n.value === e;
|
|
223
|
+
n.setSelected(r), r && (t = n);
|
|
224
|
+
}
|
|
225
|
+
t !== void 0 && this.onChangeCallback !== void 0 && this.onChangeCallback(t);
|
|
226
|
+
}
|
|
227
|
+
createValues(e) {
|
|
228
|
+
let t = /* @__PURE__ */ new Map();
|
|
229
|
+
for (let n of e) {
|
|
230
|
+
let e = new _(n, this.name);
|
|
231
|
+
n === this.defaultValue && e.setSelected(!0), t.set(n, e);
|
|
232
|
+
}
|
|
233
|
+
return t;
|
|
234
|
+
}
|
|
235
|
+
}, y = class {
|
|
236
|
+
attributes = /* @__PURE__ */ new Map();
|
|
237
|
+
constructor(e, t, n) {
|
|
238
|
+
for (let n of e) {
|
|
239
|
+
let e = this.buildOptions(n, t);
|
|
240
|
+
this.attributes.set(n.name, new v(e));
|
|
241
|
+
}
|
|
242
|
+
this.onMutationFailed = n;
|
|
243
|
+
}
|
|
244
|
+
onMutationFailed;
|
|
245
|
+
get(e) {
|
|
246
|
+
return this.attributes.get(e);
|
|
247
|
+
}
|
|
248
|
+
defaults() {
|
|
249
|
+
let e = [];
|
|
250
|
+
for (let t of this.attributes.values()) t.defaultValue !== void 0 && e.push({
|
|
251
|
+
name: t.name,
|
|
252
|
+
value: t.defaultValue
|
|
253
|
+
});
|
|
254
|
+
return e;
|
|
255
|
+
}
|
|
256
|
+
handleResults(e) {
|
|
257
|
+
for (let t of e) {
|
|
258
|
+
if (!t.success) {
|
|
259
|
+
this.onMutationFailed?.(t.name, t.value);
|
|
260
|
+
continue;
|
|
261
|
+
}
|
|
262
|
+
this.get(t.name)?.handleResult(t.value);
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
buildOptions(e, t) {
|
|
266
|
+
let n = {
|
|
267
|
+
name: e.name,
|
|
268
|
+
values: e.values,
|
|
269
|
+
onSelect: (e, n) => {
|
|
270
|
+
t([{
|
|
271
|
+
name: e,
|
|
272
|
+
value: n
|
|
273
|
+
}], !1);
|
|
274
|
+
}
|
|
275
|
+
};
|
|
276
|
+
return e.defaultValue === void 0 ? n : {
|
|
277
|
+
...n,
|
|
278
|
+
defaultValue: e.defaultValue
|
|
279
|
+
};
|
|
280
|
+
}
|
|
281
|
+
}, b = {
|
|
282
|
+
READY: "ready",
|
|
283
|
+
MUTATION: "mutation",
|
|
284
|
+
STATE: "state",
|
|
285
|
+
CONFIG: "config",
|
|
286
|
+
CAMERA: "camera",
|
|
287
|
+
SNAPSHOT: "snapshot",
|
|
288
|
+
MAPPING: "mapping"
|
|
289
|
+
}, x = new Set(Object.values(b));
|
|
290
|
+
function S(e) {
|
|
291
|
+
if (typeof e != "object" || !e) return !1;
|
|
292
|
+
let t = e;
|
|
293
|
+
return typeof t.target == "string" ? !1 : typeof t.type == "string" && x.has(t.type);
|
|
294
|
+
}
|
|
295
|
+
function C(e) {
|
|
296
|
+
let t = O(e);
|
|
297
|
+
return t !== null && t.type === b.READY;
|
|
298
|
+
}
|
|
299
|
+
function w(e) {
|
|
300
|
+
let t = O(e);
|
|
301
|
+
return t !== null && t.type === b.MUTATION && Array.isArray(t.results);
|
|
302
|
+
}
|
|
303
|
+
function T(e) {
|
|
304
|
+
let t = O(e);
|
|
305
|
+
return t !== null && t.type === b.SNAPSHOT && ("data" in t || "error" in t);
|
|
306
|
+
}
|
|
307
|
+
function E(e) {
|
|
308
|
+
let t = O(e);
|
|
309
|
+
return t !== null && t.type === b.CAMERA && Array.isArray(t.transforms);
|
|
310
|
+
}
|
|
311
|
+
function D(e) {
|
|
312
|
+
let t = O(e);
|
|
313
|
+
return t !== null && t.type === b.MAPPING && Array.isArray(t.attributes);
|
|
314
|
+
}
|
|
315
|
+
function O(e) {
|
|
316
|
+
return typeof e != "object" || !e ? null : e;
|
|
317
|
+
}
|
|
318
|
+
//#endregion
|
|
319
|
+
//#region ../messaging/src/queue.ts
|
|
320
|
+
var k = class {
|
|
321
|
+
pending = [];
|
|
322
|
+
isReady = !1;
|
|
323
|
+
constructor(e) {
|
|
324
|
+
this.processor = e;
|
|
325
|
+
}
|
|
326
|
+
enqueue(e) {
|
|
327
|
+
if (this.isReady) {
|
|
328
|
+
this.processor(e);
|
|
329
|
+
return;
|
|
330
|
+
}
|
|
331
|
+
this.pending.push(e);
|
|
332
|
+
}
|
|
333
|
+
markReady() {
|
|
334
|
+
if (this.isReady || (this.isReady = !0, this.pending.length === 0)) return;
|
|
335
|
+
let e = [...this.pending];
|
|
336
|
+
this.pending.length = 0;
|
|
337
|
+
for (let t of e) this.processor(t);
|
|
338
|
+
}
|
|
339
|
+
get ready() {
|
|
340
|
+
return this.isReady;
|
|
341
|
+
}
|
|
342
|
+
get pendingCount() {
|
|
343
|
+
return this.pending.length;
|
|
344
|
+
}
|
|
345
|
+
hasPending(e) {
|
|
346
|
+
return this.pending.some((t) => t.type === e);
|
|
347
|
+
}
|
|
348
|
+
clear() {
|
|
349
|
+
this.pending.length = 0;
|
|
350
|
+
}
|
|
351
|
+
}, A = class {
|
|
352
|
+
handlers = /* @__PURE__ */ new Map();
|
|
353
|
+
publisher;
|
|
354
|
+
consumer;
|
|
355
|
+
shouldBuffer;
|
|
356
|
+
listener = null;
|
|
357
|
+
sourceId;
|
|
358
|
+
constructor(e, t) {
|
|
359
|
+
this.getTarget = e, this.sourceId = `vd-${Math.random().toString(36).slice(2, 8)}`, this.publisher = new k((e) => this.post(e)), this.consumer = new k((e) => this.routeToHandler(e)), this.shouldBuffer = t?.shouldBuffer ?? null, t?.bufferIncoming !== !0 && this.consumer.markReady();
|
|
360
|
+
}
|
|
361
|
+
on(e, t) {
|
|
362
|
+
this.handlers.set(e, t);
|
|
363
|
+
}
|
|
364
|
+
off(e) {
|
|
365
|
+
this.handlers.delete(e);
|
|
366
|
+
}
|
|
367
|
+
send(e) {
|
|
368
|
+
this.publisher.enqueue(e);
|
|
369
|
+
}
|
|
370
|
+
markReady() {
|
|
371
|
+
this.publisher.markReady();
|
|
372
|
+
}
|
|
373
|
+
markConsumerReady() {
|
|
374
|
+
this.consumer.markReady();
|
|
375
|
+
}
|
|
376
|
+
consumerHasPending(e) {
|
|
377
|
+
return this.consumer.hasPending(e);
|
|
378
|
+
}
|
|
379
|
+
start() {
|
|
380
|
+
this.listener === null && (this.listener = (e) => {
|
|
381
|
+
let { data: t } = e;
|
|
382
|
+
if (!S(t) || t._source === this.sourceId) return;
|
|
383
|
+
let n = t;
|
|
384
|
+
if (this.shouldBuffer !== null && !this.shouldBuffer(n)) {
|
|
385
|
+
this.routeToHandler(n);
|
|
386
|
+
return;
|
|
387
|
+
}
|
|
388
|
+
this.consumer.enqueue(n);
|
|
389
|
+
}, window.addEventListener("message", this.listener));
|
|
390
|
+
}
|
|
391
|
+
destroy() {
|
|
392
|
+
this.listener !== null && (window.removeEventListener("message", this.listener), this.listener = null), this.publisher.clear(), this.consumer.clear(), this.handlers.clear();
|
|
393
|
+
}
|
|
394
|
+
get ready() {
|
|
395
|
+
return this.publisher.ready;
|
|
396
|
+
}
|
|
397
|
+
get pendingCount() {
|
|
398
|
+
return this.publisher.pendingCount;
|
|
399
|
+
}
|
|
400
|
+
post(e) {
|
|
401
|
+
let t = this.getTarget();
|
|
402
|
+
t !== null && t.postMessage({
|
|
403
|
+
...e,
|
|
404
|
+
_source: this.sourceId
|
|
405
|
+
}, "*");
|
|
406
|
+
}
|
|
407
|
+
routeToHandler(e) {
|
|
408
|
+
let t = this.handlers.get(e.type);
|
|
409
|
+
if (t === void 0) return;
|
|
410
|
+
let n = t(e);
|
|
411
|
+
n instanceof Promise && n.catch((t) => {
|
|
412
|
+
let n = t instanceof Error ? t.message : String(t);
|
|
413
|
+
console.error(`Virtualdisplay: error handling ${e.type}: ${n}`);
|
|
414
|
+
});
|
|
415
|
+
}
|
|
416
|
+
};
|
|
417
|
+
new Set([b.CAMERA]);
|
|
418
|
+
//#endregion
|
|
419
|
+
//#region src/attributes/attributes.ts
|
|
420
|
+
var j = class {
|
|
421
|
+
registry;
|
|
422
|
+
pendingCallbacks = [];
|
|
423
|
+
constructor(e, t) {
|
|
424
|
+
this.send = e, this.onMutationFailed = t;
|
|
425
|
+
}
|
|
426
|
+
handleMappingReceived(e) {
|
|
427
|
+
p.debug("Initializing from server mapping", { attributeCount: e.attributes.length }), this.registry = new y(e.attributes, (e, t) => this.sendMutation(e, t), this.onMutationFailed);
|
|
428
|
+
let t = this.registry.defaults();
|
|
429
|
+
t.length > 0 && this.sendMutation(t, !0), this.replayPendingCallbacks();
|
|
430
|
+
}
|
|
431
|
+
handleMutationResult(e) {
|
|
432
|
+
this.registry?.handleResults(e.results);
|
|
433
|
+
}
|
|
434
|
+
select(e, t) {
|
|
435
|
+
this.sendMutation([{
|
|
436
|
+
name: e,
|
|
437
|
+
value: t
|
|
438
|
+
}], !1);
|
|
439
|
+
}
|
|
440
|
+
getValues(e) {
|
|
441
|
+
return this.registry?.get(e)?.getValues() ?? [];
|
|
442
|
+
}
|
|
443
|
+
getValue(e, t) {
|
|
444
|
+
return this.registry?.get(e)?.getValue(t);
|
|
445
|
+
}
|
|
446
|
+
onChange(e, t) {
|
|
447
|
+
if (this.registry === void 0) {
|
|
448
|
+
this.pendingCallbacks.push({
|
|
449
|
+
name: e,
|
|
450
|
+
callback: t
|
|
451
|
+
});
|
|
452
|
+
return;
|
|
453
|
+
}
|
|
454
|
+
let n = this.registry.get(e);
|
|
455
|
+
if (n === void 0) {
|
|
456
|
+
p.warn(`onChange: attribute "${e}" not found — callback will not fire`);
|
|
457
|
+
return;
|
|
458
|
+
}
|
|
459
|
+
n.onChange(t);
|
|
460
|
+
}
|
|
461
|
+
getAttribute(e) {
|
|
462
|
+
return this.registry?.get(e);
|
|
463
|
+
}
|
|
464
|
+
get hasMapping() {
|
|
465
|
+
return this.registry !== void 0;
|
|
466
|
+
}
|
|
467
|
+
sendMutation(e, t) {
|
|
468
|
+
let n = {
|
|
469
|
+
type: b.MUTATION,
|
|
470
|
+
mutations: e,
|
|
471
|
+
isInitial: t
|
|
472
|
+
};
|
|
473
|
+
this.send(n);
|
|
474
|
+
}
|
|
475
|
+
replayPendingCallbacks() {
|
|
476
|
+
for (let { name: e, callback: t } of this.pendingCallbacks) {
|
|
477
|
+
let n = this.registry?.get(e);
|
|
478
|
+
n === void 0 && p.warn(`onChange: attribute "${e}" not found — buffered callback will not fire`), n?.onChange(t);
|
|
479
|
+
}
|
|
480
|
+
this.pendingCallbacks.length = 0;
|
|
481
|
+
}
|
|
482
|
+
}, M = class {
|
|
483
|
+
commands = [];
|
|
484
|
+
constructor(e) {
|
|
485
|
+
this.send = e;
|
|
486
|
+
}
|
|
487
|
+
rotate(e) {
|
|
488
|
+
return this.validateFiniteNumber(e, "rotate"), this.commands.push({
|
|
489
|
+
action: "rotate",
|
|
490
|
+
value: e
|
|
491
|
+
}), this;
|
|
492
|
+
}
|
|
493
|
+
tilt(e) {
|
|
494
|
+
return this.validateFiniteNumber(e, "tilt"), this.commands.push({
|
|
495
|
+
action: "tilt",
|
|
496
|
+
value: e
|
|
497
|
+
}), this;
|
|
498
|
+
}
|
|
499
|
+
zoom(e) {
|
|
500
|
+
return this.validateFiniteNumber(e, "zoom"), this.commands.push({
|
|
501
|
+
action: "zoom",
|
|
502
|
+
value: e
|
|
503
|
+
}), this;
|
|
504
|
+
}
|
|
505
|
+
set() {
|
|
506
|
+
if (this.commands.length === 0) throw t.invalidParameter("No camera commands to execute. Call rotate(), tilt(), or zoom() before set().");
|
|
507
|
+
let e = {
|
|
508
|
+
type: b.CAMERA,
|
|
509
|
+
commands: this.commands
|
|
510
|
+
};
|
|
511
|
+
this.send(e), this.commands = [];
|
|
512
|
+
}
|
|
513
|
+
validateFiniteNumber(e, n) {
|
|
514
|
+
if (!Number.isFinite(e)) throw t.invalidParameter(`${n}() requires a finite number, got ${String(e)}`);
|
|
515
|
+
}
|
|
516
|
+
reset() {
|
|
517
|
+
let e = {
|
|
518
|
+
type: b.CAMERA,
|
|
519
|
+
commands: [{ action: "reset" }]
|
|
520
|
+
};
|
|
521
|
+
this.send(e);
|
|
522
|
+
}
|
|
523
|
+
}, N = class {
|
|
524
|
+
state;
|
|
525
|
+
changeCallbacks = [];
|
|
526
|
+
constructor() {
|
|
527
|
+
this.state = {
|
|
528
|
+
rotation: 0,
|
|
529
|
+
tilt: 0,
|
|
530
|
+
zoom: 0
|
|
531
|
+
};
|
|
532
|
+
}
|
|
533
|
+
get rotation() {
|
|
534
|
+
return this.state.rotation;
|
|
535
|
+
}
|
|
536
|
+
get tilt() {
|
|
537
|
+
return this.state.tilt;
|
|
538
|
+
}
|
|
539
|
+
get zoom() {
|
|
540
|
+
return this.state.zoom;
|
|
541
|
+
}
|
|
542
|
+
onChange(e) {
|
|
543
|
+
this.changeCallbacks.push(e);
|
|
544
|
+
}
|
|
545
|
+
handlePositionUpdate(e) {
|
|
546
|
+
this.update(e.transforms);
|
|
547
|
+
}
|
|
548
|
+
update(e) {
|
|
549
|
+
let t = !1;
|
|
550
|
+
for (let n of e) switch (n.type) {
|
|
551
|
+
case "rotation":
|
|
552
|
+
this.state.rotation = n.value, t = !0;
|
|
553
|
+
break;
|
|
554
|
+
case "tilt":
|
|
555
|
+
this.state.tilt = n.value, t = !0;
|
|
556
|
+
break;
|
|
557
|
+
case "zoom":
|
|
558
|
+
this.state.zoom = n.value, t = !0;
|
|
559
|
+
break;
|
|
560
|
+
default: break;
|
|
561
|
+
}
|
|
562
|
+
if (t) {
|
|
563
|
+
let e = {
|
|
564
|
+
rotation: this.rotation,
|
|
565
|
+
tilt: this.tilt,
|
|
566
|
+
zoom: this.zoom
|
|
567
|
+
};
|
|
568
|
+
for (let t of this.changeCallbacks) t(e);
|
|
569
|
+
}
|
|
570
|
+
}
|
|
571
|
+
}, P = class {
|
|
572
|
+
developedCallbacks = /* @__PURE__ */ new Set();
|
|
573
|
+
errorCallbacks = /* @__PURE__ */ new Set();
|
|
574
|
+
developed = !1;
|
|
575
|
+
failed = !1;
|
|
576
|
+
photoData = null;
|
|
577
|
+
constructor(e) {
|
|
578
|
+
this.filename = e;
|
|
579
|
+
}
|
|
580
|
+
onDeveloped(e) {
|
|
581
|
+
return this.developed && this.photoData !== null ? (e(this.photoData), this) : (this.developedCallbacks.add(e), this);
|
|
582
|
+
}
|
|
583
|
+
onError(e) {
|
|
584
|
+
return this.errorCallbacks.add(e), this;
|
|
585
|
+
}
|
|
586
|
+
getFilename() {
|
|
587
|
+
return this.filename;
|
|
588
|
+
}
|
|
589
|
+
develop(e) {
|
|
590
|
+
this.developed || this.failed || (this.photoData = e, this.developed = !0, this.developedCallbacks.forEach((e) => {
|
|
591
|
+
e(this.photoData);
|
|
592
|
+
}), this.developedCallbacks.clear(), this.errorCallbacks.clear());
|
|
593
|
+
}
|
|
594
|
+
fail(e) {
|
|
595
|
+
this.developed || this.failed || (this.failed = !0, this.errorCallbacks.forEach((t) => {
|
|
596
|
+
t(e);
|
|
597
|
+
}), this.developedCallbacks.clear(), this.errorCallbacks.clear());
|
|
598
|
+
}
|
|
599
|
+
}, F = class {
|
|
600
|
+
validExtensions = [".png"];
|
|
601
|
+
pendingPhotos = /* @__PURE__ */ new Map();
|
|
602
|
+
constructor(e) {
|
|
603
|
+
this.send = e;
|
|
604
|
+
}
|
|
605
|
+
take(e) {
|
|
606
|
+
this.validateFilename(e), p.debug("Taking snapshot", { filename: e });
|
|
607
|
+
let t = new P(e);
|
|
608
|
+
return this.pendingPhotos.set(t.getFilename(), t), this.send({
|
|
609
|
+
type: b.SNAPSHOT,
|
|
610
|
+
filename: e
|
|
611
|
+
}), t;
|
|
612
|
+
}
|
|
613
|
+
handleSnapshotResult(n) {
|
|
614
|
+
let r = this.pendingPhotos.get(n.filename);
|
|
615
|
+
if (r === void 0) {
|
|
616
|
+
p.warn("No pending photo found for filename", {
|
|
617
|
+
filename: n.filename,
|
|
618
|
+
pendingFilenames: Array.from(this.pendingPhotos.keys())
|
|
619
|
+
});
|
|
620
|
+
return;
|
|
621
|
+
}
|
|
622
|
+
if (this.pendingPhotos.delete(n.filename), n.error !== void 0) {
|
|
623
|
+
r.fail(new t(n.error, e.SNAPSHOT_FAILED));
|
|
624
|
+
return;
|
|
625
|
+
}
|
|
626
|
+
n.data !== void 0 && r.develop({
|
|
627
|
+
filename: n.filename,
|
|
628
|
+
data: n.data
|
|
629
|
+
});
|
|
630
|
+
}
|
|
631
|
+
validateFilename(n) {
|
|
632
|
+
if (n === "" || typeof n != "string") throw new t("Filename must be a non-empty string", e.INVALID_PARAMETER);
|
|
633
|
+
if (!this.validExtensions.some((e) => n.toLowerCase().endsWith(e))) throw new t(`Invalid filename: "${n}". Filename must end with one of: ${this.validExtensions.join(", ")}`, e.INVALID_PARAMETER);
|
|
634
|
+
if (n.includes("..") || n.includes("/") || n.includes("\\")) throw new t("Filename cannot contain path separators or \"..\"", e.INVALID_PARAMETER);
|
|
635
|
+
}
|
|
636
|
+
}, I = class {
|
|
637
|
+
send;
|
|
638
|
+
constructor(e) {
|
|
639
|
+
this.send = e;
|
|
640
|
+
}
|
|
641
|
+
sendInitialConfig(e) {
|
|
642
|
+
let t = this.buildUIConfig(e), n = this.buildViewerConfig(t, e.camera);
|
|
643
|
+
n !== void 0 && this.sendConfig(n);
|
|
644
|
+
}
|
|
645
|
+
buildUIConfig(e) {
|
|
646
|
+
let t = this.extractUIValues(e);
|
|
647
|
+
if (Object.values(t).some((e) => e !== void 0)) return {
|
|
648
|
+
...t.arEnabled !== void 0 && { arEnabled: t.arEnabled },
|
|
649
|
+
...t.fullscreenEnabled !== void 0 && { fullscreenEnabled: t.fullscreenEnabled },
|
|
650
|
+
...t.loadingIndicatorEnabled !== void 0 && { loadingIndicatorEnabled: t.loadingIndicatorEnabled }
|
|
651
|
+
};
|
|
652
|
+
}
|
|
653
|
+
extractUIValues(e) {
|
|
654
|
+
return {
|
|
655
|
+
arEnabled: e.arEnabled ?? e.ui?.arEnabled,
|
|
656
|
+
fullscreenEnabled: e.fullscreenEnabled ?? e.ui?.fullscreenEnabled,
|
|
657
|
+
loadingIndicatorEnabled: e.loadingIndicatorEnabled ?? e.ui?.loadingIndicatorEnabled
|
|
658
|
+
};
|
|
659
|
+
}
|
|
660
|
+
buildViewerConfig(e, t) {
|
|
661
|
+
if (!(e === void 0 && t === void 0)) return {
|
|
662
|
+
...e !== void 0 && { ui: e },
|
|
663
|
+
...t !== void 0 && { camera: t }
|
|
664
|
+
};
|
|
665
|
+
}
|
|
666
|
+
setArEnabled(e) {
|
|
667
|
+
p.debug(`Setting AR button enabled: ${e}`), this.updateUIConfig({ arEnabled: e });
|
|
668
|
+
}
|
|
669
|
+
setFullscreenEnabled(e) {
|
|
670
|
+
p.debug(`Setting fullscreen button enabled: ${e}`), this.updateUIConfig({ fullscreenEnabled: e });
|
|
671
|
+
}
|
|
672
|
+
setLoadingIndicatorEnabled(e) {
|
|
673
|
+
p.debug(`Setting loading indicator enabled: ${e}`), this.updateUIConfig({ loadingIndicatorEnabled: e });
|
|
674
|
+
}
|
|
675
|
+
updateUIConfig(e) {
|
|
676
|
+
p.debug("Updating UI configuration", e), Object.keys(e).length > 0 && this.sendConfig({ ui: e });
|
|
677
|
+
}
|
|
678
|
+
hideAllUI() {
|
|
679
|
+
p.debug("Hiding all UI elements"), this.sendUIConfig({
|
|
680
|
+
arEnabled: !1,
|
|
681
|
+
fullscreenEnabled: !1,
|
|
682
|
+
loadingIndicatorEnabled: !1
|
|
683
|
+
});
|
|
684
|
+
}
|
|
685
|
+
showAllUI() {
|
|
686
|
+
p.debug("Showing all UI elements"), this.sendUIConfig({
|
|
687
|
+
arEnabled: !0,
|
|
688
|
+
fullscreenEnabled: !0,
|
|
689
|
+
loadingIndicatorEnabled: !0
|
|
690
|
+
});
|
|
691
|
+
}
|
|
692
|
+
sendUIConfig(e) {
|
|
693
|
+
this.sendConfig({ ui: e });
|
|
694
|
+
}
|
|
695
|
+
sendConfig(e) {
|
|
696
|
+
let t = {
|
|
697
|
+
type: b.CONFIG,
|
|
698
|
+
config: e
|
|
699
|
+
};
|
|
700
|
+
p.debug("Sending config", t), this.send(t);
|
|
701
|
+
}
|
|
702
|
+
}, L = class {
|
|
703
|
+
attributes;
|
|
704
|
+
readyStateTracker;
|
|
705
|
+
messenger;
|
|
706
|
+
viewerService;
|
|
707
|
+
cameraApi;
|
|
708
|
+
cameraPositionApi;
|
|
709
|
+
snapshotApi;
|
|
710
|
+
options;
|
|
711
|
+
iframe;
|
|
712
|
+
readyCallbacks = [];
|
|
713
|
+
mutationFailedCallbacks = [];
|
|
714
|
+
constructor(e) {
|
|
715
|
+
this.options = e, this.initializeLogging(), this.messenger = new A(() => this.iframe?.contentWindow ?? null);
|
|
716
|
+
let t = (e) => {
|
|
717
|
+
this.messenger.send(e);
|
|
718
|
+
};
|
|
719
|
+
this.attributes = new j(t, (e, t) => {
|
|
720
|
+
for (let n of this.mutationFailedCallbacks) n({
|
|
721
|
+
attribute: e,
|
|
722
|
+
value: t
|
|
723
|
+
});
|
|
724
|
+
}), this.readyStateTracker = new g(() => {
|
|
725
|
+
let e = this.readyCallbacks;
|
|
726
|
+
this.readyCallbacks = [];
|
|
727
|
+
for (let t of e) t(this);
|
|
728
|
+
}), this.viewerService = new I(t), this.cameraApi = new M(t), this.cameraPositionApi = new N(), this.snapshotApi = new F(t), this.registerHandlers(), this.messenger.start(), this.createAndConnectIframe();
|
|
729
|
+
}
|
|
730
|
+
registerHandlers() {
|
|
731
|
+
this.messenger.on(b.READY, (e) => {
|
|
732
|
+
C(e) && (p.info("Server ready — flushing publisher queue"), this.messenger.markReady(), this.viewerService.sendInitialConfig(this.options));
|
|
733
|
+
}), this.messenger.on(b.MUTATION, (e) => {
|
|
734
|
+
w(e) && (this.attributes.handleMutationResult(e), this.readyStateTracker.handleMutationResult(e));
|
|
735
|
+
}), this.messenger.on(b.SNAPSHOT, (e) => {
|
|
736
|
+
T(e) && this.snapshotApi.handleSnapshotResult(e);
|
|
737
|
+
}), this.messenger.on(b.CAMERA, (e) => {
|
|
738
|
+
E(e) && this.cameraPositionApi.handlePositionUpdate(e);
|
|
739
|
+
}), this.messenger.on(b.MAPPING, (e) => {
|
|
740
|
+
D(e) && (this.attributes.handleMappingReceived(e), this.readyStateTracker.handleMappingReceived());
|
|
741
|
+
});
|
|
742
|
+
}
|
|
743
|
+
initializeLogging() {
|
|
744
|
+
this.options.debug === !0 && m(), p.info("Initializing Virtualdisplay client", {
|
|
745
|
+
model: this.options.model,
|
|
746
|
+
debug: this.options.debug,
|
|
747
|
+
language: this.options.language
|
|
748
|
+
});
|
|
749
|
+
}
|
|
750
|
+
createAndConnectIframe() {
|
|
751
|
+
p.debug("Creating iframe for Virtualdisplay viewer"), this.iframe = new n(this.options).create(), p.debug("Iframe created, waiting for server READY");
|
|
752
|
+
}
|
|
753
|
+
select(e, t) {
|
|
754
|
+
this.attributes.select(e, t);
|
|
755
|
+
}
|
|
756
|
+
getValues(e) {
|
|
757
|
+
return this.attributes.getValues(e);
|
|
758
|
+
}
|
|
759
|
+
getValue(e, t) {
|
|
760
|
+
return this.attributes.getValue(e, t);
|
|
761
|
+
}
|
|
762
|
+
onChange(e, t) {
|
|
763
|
+
this.attributes.onChange(e, t);
|
|
764
|
+
}
|
|
765
|
+
getAttribute(e) {
|
|
766
|
+
return this.attributes.getAttribute(e);
|
|
767
|
+
}
|
|
768
|
+
get isReady() {
|
|
769
|
+
return this.readyStateTracker.isReady;
|
|
770
|
+
}
|
|
771
|
+
onReady(e) {
|
|
772
|
+
if (this.readyStateTracker.isReady) {
|
|
773
|
+
e(this);
|
|
774
|
+
return;
|
|
775
|
+
}
|
|
776
|
+
this.readyCallbacks.push(e);
|
|
777
|
+
}
|
|
778
|
+
onMutationFailed(e) {
|
|
779
|
+
this.mutationFailedCallbacks.push(e);
|
|
780
|
+
}
|
|
781
|
+
get viewer() {
|
|
782
|
+
return this.viewerService;
|
|
783
|
+
}
|
|
784
|
+
get camera() {
|
|
785
|
+
return this.cameraApi;
|
|
786
|
+
}
|
|
787
|
+
get cameraPosition() {
|
|
788
|
+
return this.cameraPositionApi;
|
|
789
|
+
}
|
|
790
|
+
get snapshot() {
|
|
791
|
+
return this.snapshotApi;
|
|
792
|
+
}
|
|
793
|
+
destroy() {
|
|
794
|
+
p.info("Destroying Virtualdisplay client"), this.readyStateTracker.clear(), this.readyCallbacks = [], this.messenger.destroy(), this.iframe?.parentElement !== null && this.iframe?.parentElement !== void 0 && this.iframe.parentElement.removeChild(this.iframe), this.iframe = void 0, p.debug("Virtualdisplay client destroyed");
|
|
795
|
+
}
|
|
796
|
+
};
|
|
797
|
+
//#endregion
|
|
798
|
+
export { v as Attribute, _ as AttributeValue, M as Camera, e as ERROR_CODES, P as Photo, F as Snapshot, L as VirtualdisplayClient, t as VirtualdisplayError, I as VirtualdisplayViewerService, m as enableDebugMode, h as isDebugMode, p as logger };
|