@vertexvis/viewer 0.22.0-canary.3 → 0.22.0-testing.0

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.
Files changed (50) hide show
  1. package/dist/cjs/index.cjs.js +4 -1
  2. package/dist/cjs/index.cjs.js.map +1 -1
  3. package/dist/cjs/multiElementInteractionHandler-93bd9593.js.map +1 -1
  4. package/dist/cjs/{queries-d9cd5ec1.js → queries-918bb133.js} +315 -41
  5. package/dist/cjs/queries-918bb133.js.map +1 -0
  6. package/dist/cjs/vertex-viewer.cjs.entry.js +3 -256
  7. package/dist/cjs/vertex-viewer.cjs.entry.js.map +1 -1
  8. package/dist/collection/index.js +1 -0
  9. package/dist/collection/index.js.map +1 -1
  10. package/dist/collection/lib/interactions/baseInteractionHandler.js.map +1 -1
  11. package/dist/collection/lib/interactions/index.js +1 -0
  12. package/dist/collection/lib/interactions/index.js.map +1 -1
  13. package/dist/collection/lib/interactions/mouseInteractions.js +6 -0
  14. package/dist/collection/lib/interactions/mouseInteractions.js.map +1 -1
  15. package/dist/collection/lib/interactions/pointerInteractionHandler.js +6 -0
  16. package/dist/collection/lib/interactions/pointerInteractionHandler.js.map +1 -1
  17. package/dist/components/index.js +1 -1
  18. package/dist/components/multiElementInteractionHandler.js.map +1 -1
  19. package/dist/components/queries.js +269 -2
  20. package/dist/components/queries.js.map +1 -1
  21. package/dist/components/vertex-viewer.js +3 -256
  22. package/dist/components/vertex-viewer.js.map +1 -1
  23. package/dist/esm/index.js +3 -1
  24. package/dist/esm/index.js.map +1 -1
  25. package/dist/esm/index.mjs +3 -1
  26. package/dist/esm/multiElementInteractionHandler-8b48d16e.js.map +1 -1
  27. package/dist/esm/{queries-2834b01d.js → queries-e3684cb0.js} +270 -3
  28. package/dist/esm/queries-e3684cb0.js.map +1 -0
  29. package/dist/esm/vertex-viewer.entry.js +3 -256
  30. package/dist/esm/vertex-viewer.entry.js.map +1 -1
  31. package/dist/types/index.d.ts +1 -0
  32. package/dist/types/lib/interactions/baseInteractionHandler.d.ts +6 -6
  33. package/dist/types/lib/interactions/index.d.ts +1 -0
  34. package/dist/types/lib/interactions/mouseInteractions.d.ts +2 -0
  35. package/dist/types/lib/interactions/pointerInteractionHandler.d.ts +2 -0
  36. package/dist/viewer/index.esm.js +1 -1
  37. package/dist/viewer/index.esm.js.map +1 -1
  38. package/dist/viewer/p-0ab3b3cc.js +5 -0
  39. package/dist/viewer/p-0ab3b3cc.js.map +1 -0
  40. package/dist/viewer/p-8a56c008.entry.js +5 -0
  41. package/dist/viewer/p-8a56c008.entry.js.map +1 -0
  42. package/dist/viewer/p-bf67f570.js.map +1 -1
  43. package/dist/viewer/viewer.esm.js +1 -1
  44. package/package.json +7 -7
  45. package/dist/cjs/queries-d9cd5ec1.js.map +0 -1
  46. package/dist/esm/queries-2834b01d.js.map +0 -1
  47. package/dist/viewer/p-339774b3.js +0 -5
  48. package/dist/viewer/p-339774b3.js.map +0 -1
  49. package/dist/viewer/p-b8dfa0c1.entry.js +0 -5
  50. package/dist/viewer/p-b8dfa0c1.entry.js.map +0 -1
@@ -0,0 +1,5 @@
1
+ /*!
2
+ * Copyright (c) 2024 Vertex Software LLC. All rights reserved.
3
+ */
4
+ import{r as t,c as i,h as n,H as s,g as e}from"./p-e541044a.js";import{p as o,v as h,c as a,f as r,r as c,b as l,w as u,d}from"./p-26198b53.js";import{S as f}from"./p-3f901c03.js";import{p,t as w,a as m,S as v,c as g,W as y}from"./p-a30a8324.js";import{m as b,b as C,E as P,a as T,c as I,o as S,u as A}from"./p-81d5a971.js";import{c as j}from"./p-5206da6c.js";import{u as k,c as E,C as O,W as D,S as M,V as x,d as R,e as B}from"./p-b33048e2.js";import{s as F,p as L,u as z}from"./p-dc590cd1.js";import{r as $,c as H,a as K}from"./p-ff0bd72b.js";import{l as N,m as V,n as W,o as q,j as U,u as _,t as J,p as X,q as Z,r as G,s as Y,x as Q,y as tt,z as it,B as nt,C as st,E as et}from"./p-762b8987.js";import{p as ot}from"./p-b7feec8b.js";import{C as ht}from"./p-be03d860.js";import{c as at}from"./p-47b8b98d.js";import{E as rt}from"./p-d312d59a.js";import{V as ct}from"./p-f6f74387.js";import{h as lt,i as ut,Z as dt,j as ft,T as pt,k as wt,m as mt,g as vt,P as gt,S as yt}from"./p-0ab3b3cc.js";import{B as bt}from"./p-bf67f570.js";import{w as Ct}from"./p-208c7121.js";import"./p-d4d032c6.js";import"./p-88c19f38.js";import"./p-db5aed84.js";const Pt=0;const Tt=255;class It{constructor(t){this.viewer=t;this.handleInteractionStarted=()=>{this.invalidateStencilBuffer();this.pendingInteractionFinished=new Promise((t=>{this.pendingInteractionFinishedResolver=t}))};this.handleInteractionFinished=()=>{var t;(t=this.pendingInteractionFinishedResolver)===null||t===void 0?void 0:t.call(this);this.pendingInteractionFinished=undefined;this.pendingInteractionFinishedResolver=undefined};this.invalidateStencilBuffer=()=>{this.pendingStencilBuffer=undefined};t.addEventListener("interactionStarted",this.handleInteractionStarted);t.addEventListener("interactionFinished",this.handleInteractionFinished);t.addEventListener("frameReceived",(()=>{this.invalidateStencilBuffer()}))}async fetch(){var t;const i=await this.viewer.isSceneReady();const n=i?await this.viewer.scene():undefined;const s=n!=null?n.crossSectioning().current().sectionPlanes.length>0||this.viewer.featureLines!=null:false;const e=(t=this.viewer.frame)===null||t===void 0?void 0:t.scene.camera;if(s&&this.viewer.stream!=null&&e!=null){const t=await this.viewer.stream.getStencilBuffer({includeDepthBuffer:true});const{stencilBuffer:i,depthBuffer:n,imageAttributes:s}=N(t);const[o,h]=await Promise.all([V(new Uint8Array(i)),V(new Uint8Array(n))]);return St.fromPng(o,s,i,W.fromPng(h,e,s))}else return undefined}latest(){if(this.pendingStencilBuffer==null){this.pendingStencilBuffer=this.fetch()}return this.pendingStencilBuffer}async latestAfterInteraction(){await this.pendingInteractionFinished;return this.latest()}}class St{constructor(t,i,n,s,e){this.imageAttr=t;this.imageBytes=i;this.pixelBytes=n;this.imageChannels=s;this.depthBuffer=e}static fromPng(t,i,n,s){if(!(t.data instanceof Uint8Array)){throw new Error("Expected stencil PNG to have depth of 8-bit")}else if(t.channels!==1){throw new Error("Expected stencil PNG to have 1 color channel")}else{return new St(i,n,t.data,t.channels,s)}}getValue(t){const{width:i,height:n}=this.imageAttr.imageRect;const s=o.subtract(t,this.imageAttr.imageRect);const e=1/this.imageAttr.imageScale;const h=o.scale(s,e,e);if(h.x>=0&&h.y>=0&&h.x<i&&h.y<n){const t=Math.floor(h.x)+Math.floor(h.y)*i;const n=this.pixelBytes[t];return n}else return 0}hitTest(t){return this.getValue(t)!==Pt}snapToNearestPixel(t,i,n=(()=>true)){const s=i*2;const e=o.create(t.x-i,t.y-i);const h=[];for(let a=0;a<s*s;a++){const r=a%s;const c=Math.floor(a/s);const l=o.add(e,{x:r,y:c});if(o.distance(l,t)<=i){const t=this.getValue(l);if(t===Tt&&n(t)){h.push(l)}}}const a=h.sort(((i,n)=>o.distance(i,t)-o.distance(n,t)));const r=a[0];return r!=null?o.create(Math.floor(r.x)+.5,Math.floor(r.y)+.5):t}}function At(t){return t!=null&&t["then"]instanceof Function&&t["catch"]instanceof Function&&t["finally"]instanceof Function}function jt(t){return new Promise((i=>setTimeout(i,t)))}const kt=b.defineMapper(b.read(b.requiredProp("msb"),b.requiredProp("lsb")),(([t,i])=>C.fromMsbLsb(t,i)));const Et=b.defineMapper(b.read(b.requiredProp("seconds"),b.requiredProp("nanos")),(([t,i])=>p({seconds:t,nanos:i})));const Ot=b.defineMapper(b.compose((t=>t.toObject()),b.read(b.mapRequiredProp("id",kt),b.mapRequiredProp("createdAt",Et),b.mapRequiredProp("modifiedAt",Et),b.mapProp("name",q),b.mapProp("suppliedId",q))),(([t,i,n,s,e])=>({id:t,createdAt:i,modifiedAt:n,name:s,suppliedId:e})));const Dt=b.ifInvalidThrow(Ot);const Mt=b.defineMapper(b.compose((t=>t.toObject()),b.read(b.mapRequiredProp("id",kt),b.mapRequiredProp("createdAt",Et),b.mapRequiredProp("modifiedAt",Et),b.mapProp("suppliedId",q),b.mapRequiredProp("data",(t=>{if(t.callout!=null){return Rt(t.callout)}else if(t.customJson!=null){return Bt(t.customJson)}else{throw new Error("Undefined or unknown annotation data.")}})))),(([t,i,n,s,e])=>({id:t,createdAt:i,modifiedAt:n,suppliedId:s,data:e})));const xt=b.ifInvalidThrow(Mt);const Rt=b.defineMapper(b.read(b.mapRequiredProp("position",U),b.mapProp("icon",q),b.mapProp("primaryColor",q),b.mapProp("accentColor",q)),(([t,i,n,s])=>({type:"callout",position:t,icon:i,primaryColor:n,accentColor:s})));const Bt=b.defineMapper(b.read(b.requiredProp("type"),b.mapRequiredProp("jsonData",(t=>JSON.parse(t)))),(([t,i])=>({type:"custom",jsonType:t,jsonData:i})));class Ft{constructor(t,i,n){this.client=t;this.jwtProvider=i;this.deviceIdProvider=n;this.onStateChange=new P}async addAnnotationSet(t){await $((async i=>{const n=this.deviceIdProvider();const s=await H(this.jwtProvider,n);const e=new F.CreateSceneViewAnnotationSetRequest;const o=new k.Uuid;o.setHex(t);e.setSceneAnnotationSetId(o);this.client.createSceneViewAnnotationSet(e,s,i)}));return this.fetch()}disconnect(){if(this.connection!=null){this.connection.dispose();this.connection=undefined}}connect(t=1e4){this.disconnect();const i=this.pollAnnotationState(t);this.connection={dispose:()=>i.abort()}}async fetch(t={}){const i=await this.fetchAnnotationSetsAsArray();const n=await this.fetchAnnotationsAsArray(i);const s=(await Promise.all(n)).reduce(((t,[i,n])=>({annotations:Object.assign(Object.assign({},t.annotations),{[i.id]:n})})),{annotations:{}});if(t.signal==null||!t.signal.aborted){this.updateState(s)}return s}async removeAnnotationSet(t){await $((async i=>{const n=this.deviceIdProvider();const s=await H(this.jwtProvider,n);const e=new F.DeleteSceneViewAnnotationSetRequest;const o=new k.Uuid;o.setHex(t);e.setSceneAnnotationSetId(o);this.client.deleteSceneViewAnnotationSet(e,s,i)}));return this.fetch()}pollAnnotationState(t){const i=new AbortController;const n=async t=>{await this.fetch({signal:i.signal});if(!i.signal.aborted){await jt(t);await n(t)}};T.abort(i.signal,n(t));return i}fetchAnnotationSets(){return K((t=>async i=>{const n=this.deviceIdProvider();const s=await H(this.jwtProvider,n);const e=new F.ListSceneViewAnnotationSetsRequest;if(t!=null){const i=new L.Pager;i.setCursor(t);i.setLimit(100);e.setPage(i)}this.client.listSceneViewAnnotationSets(e,s,i)}),(t=>{var i;return(i=t.toObject().nextCursor)===null||i===void 0?void 0:i.next}))}async fetchAnnotationSetsAsArray(){return(await T.asArray(this.fetchAnnotationSets())).flatMap((t=>t.getSceneAnnotationSetsList())).map((t=>Dt(t)))}fetchAnnotations(t){return K((i=>async n=>{const s=this.deviceIdProvider();const e=await H(this.jwtProvider,s);const o=C.toMsbLsb(t);const h=new z.Uuid2l;h.setMsb(o.msb);h.setLsb(o.lsb);const a=new F.ListSceneAnnotationsRequest;a.setSceneAnnotationSetId(h);if(i!=null){const t=new L.Pager;t.setCursor(i);t.setLimit(100);a.setPage(t)}this.client.listSceneAnnotations(a,e,n)}),(t=>{var i;return(i=t.toObject().nextCursor)===null||i===void 0?void 0:i.next}))}fetchAnnotationsAsArray(t){const i=t.map((async t=>{const i=(await T.asArray(this.fetchAnnotations(t.id))).flatMap((t=>t.getSceneAnnotationsList())).map((t=>xt(t)));return[t,i]}));return Promise.all(i)}updateState(t){this.state=t;this.onStateChange.emit(t)}}class Lt{constructor(t,i,n){this.stream=t;this.configProvider=i;this.imageScaleProvider=n}predicate(t){return t.altKey&&!t.shiftKey}async fn(t){var i;const n=this.imageScaleProvider();const s=await this.stream.hitItems({point:o.scale(t.position,(n===null||n===void 0?void 0:n.x)||1,(n===null||n===void 0?void 0:n.y)||1)},true);if(((i=s.hitItems)===null||i===void 0?void 0:i.hits)!=null&&s.hitItems.hits.length>0){await this.stream.flyTo({itemId:s.hitItems.hits[0].itemId,animation:{duration:w(this.configProvider().animation.durationMs)}})}else{console.debug(`No hit results found for fly to part [position={x: ${t.position.x}, y: ${t.position.y}}]`)}}}class zt{constructor(t,i,n,s,e,o,h,a,r,c,l){this.stream=t;this.cursors=i;this.getConfig=n;this.getScene=s;this.getFrame=e;this.getViewport=o;this.tapEmitter=h;this.doubleTapEmitter=a;this.longPressEmitter=r;this.interactionStartedEmitter=c;this.interactionFinishedEmitter=l;this.tap=this.tap.bind(this);this.doubleTap=this.doubleTap.bind(this);this.longPress=this.longPress.bind(this);this.emitTapEvent=this.emitTapEvent.bind(this)}addCursor(t,i){return this.cursors.add(t,i)}async getWorldPointFromViewport(t){const i=this.getViewport();const n=this.getFrame();if(n==null){throw new Error("Cannot get world point. Frame is undefined.")}const s=await n.depthBuffer();return s!=null?i.transformPointToWorldSpace(t,s,.5):undefined}async getEntityTypeAtPoint(t){var i;const n=this.getViewport();const s=await((i=this.getFrame())===null||i===void 0?void 0:i.featureMap());if(s!=null){const i=n.transformPointToFrame(t,s);return s.getEntityType(i)}else{return rt.NO_GEOMETRY}}getRayFromPoint(t){const i=this.getViewport();const n=this.getFrame();if(n!=null){return i.transformPointToRay(t,n.image,n.scene.camera)}else throw new Error("Cannot get camera. Frame is undefined.")}async tap(t,i={},n=0){this.emitTapEvent(this.tapEmitter.emit,t,i,n)}async doubleTap(t,i={},n=0){this.emitTapEvent(this.doubleTapEmitter.emit,t,i,n)}async longPress(t,i={},n=0){this.emitTapEvent(this.longPressEmitter.emit,t,i,n)}async beginInteraction(){if(!this.isInteracting()){this.interactionStartedEmitter.emit();this.sceneLoadingPromise=this.getScene();this.currentCamera=(await this.sceneLoadingPromise).camera();this.sceneLoadingPromise=undefined;await this.stream.beginInteraction()}}async transformCamera(...t){var i;const n=t[0];const s=t[1];if(this.isInteracting()){const t=await this.getScene();const e=this.getViewport();const o=this.getFrame();const h=await(o===null||o===void 0?void 0:o.depthBuffer());this.currentCamera=this.currentCamera!=null&&e!=null&&o!=null?n({camera:this.currentCamera,viewport:e,scale:t.scale(),boundingBox:t.boundingBox(),frame:o,depthBuffer:h}):undefined;await((i=this.currentCamera)===null||i===void 0?void 0:i.render(s))}}async twistCamera(...t){return this.transformCamera((({camera:i,viewport:n})=>{const s=h.normalize(h.subtract(i.lookAt,i.position));if(t.length===1&&typeof t[0]==="number"){const n=a.toRadians(-t[0]);return i.rotateAroundAxis(n,s)}else if(t.length===1){const s=o.create(n.width/2,n.height/2);const e=a.toDegrees(a.fromPoints(s,t[0]));const r=this.lastAngle!=null?e-this.lastAngle:0;this.lastAngle=e;const c=h.normalize(h.subtract(i.lookAt,i.position));const l=a.toRadians(-r);return i.rotateAroundAxis(l,c)}return i}))}async panCameraToScreenPoint(t){return this.transformCamera((({camera:i,frame:n,viewport:s,depthBuffer:e})=>{if(this.panData==null){const o=i.toFrameCamera();const h=o.direction;const a=s.transformPointToRay(t,n.image,o);const l=r.fromNormalAndCoplanarPoint(h,i.lookAt);const u=c.intersectPlane(a,l);if(u==null){console.warn("Cannot determine fallback for pan. Ray does not intersect plane.");return i}const d=e!=null?this.getWorldPoint(t,e,u):u;const f=r.fromNormalAndCoplanarPoint(h,d);this.panData={hitPt:d,hitPlane:f,startingCamera:o}}if(this.panData!=null){const{hitPt:e,hitPlane:o,startingCamera:a}=this.panData;const r=s.transformPointToRay(t,n.image,a);const l=c.intersectPlane(r,o);if(l!=null){const t=h.subtract(e,l);return i.update(a).moveBy(t)}}return i}))}async viewAll(){await(await this.getScene()).camera().viewAll().render()}async rotateCamera(t){return this.transformCamera((({camera:i,viewport:n,boundingBox:s})=>{const e=h.normalize(i.up);const o=h.normalize(h.subtract(i.lookAt,i.position));const a=h.cross(e,o);const r=h.cross(o,a);const c=h.normalize({x:t.x*a.x+t.y*r.x,y:t.x*a.y+t.y*r.y,z:t.x*a.z+t.y*r.z});const l=h.cross(c,o);const u=9.5*t.x/n.width;const d=9.5*t.y/n.height;const f=Math.abs(u)+Math.abs(d);return i.rotateAroundAxis(f,l)}))}async rotateCameraAtPoint(t,i){return this.transformCamera((({camera:n,viewport:s,boundingBox:e,depthBuffer:o})=>{if(this.worldRotationPoint==null){const t=l.center(e);this.worldRotationPoint=o!=null?this.getWorldPoint(i,o,t):n.lookAt}const a=h.normalize(n.up);const r=h.normalize(h.subtract(n.lookAt,n.position));const c=h.cross(a,r);const u=h.cross(r,c);const d=h.normalize({x:t.x*c.x+t.y*u.x,y:t.x*c.y+t.y*u.y,z:t.x*c.z+t.y*u.z});const f=h.cross(d,r);const p=9.5*t.x/s.width;const w=9.5*t.y/s.height;const m=Math.abs(p)+Math.abs(w);const v=n.rotateAroundAxisAtPoint(m,this.worldRotationPoint,f);return v.update({lookAt:h.add(h.scale(Math.abs(n.signedDistanceToBoundingBoxCenter())/h.magnitude(v.viewVector),v.viewVector),v.position)})}))}async zoomCamera(t){return this.transformCamera((({camera:i,viewport:n})=>{const s=i.viewVector;const e=h.normalize(s);const o=h.magnitude(s);const a=3*o*t/n.height;const r=h.add(i.position,h.scale(a,e));const c=i.update({position:r});return c}))}async pivotCamera(t,i){return this.transformCamera((({camera:n})=>{const{position:s,up:e,lookAt:o}=n;const r=h.normalize(e);const c=h.normalize(n.viewVector);const l=h.cross(r,c);const u=h.cross(c,l);const d=h.rotateAboutAxis(a.toRadians(t),o,l,s);const f=h.rotateAboutAxis(a.toRadians(i),d,u,s);return n.update(Object.assign(Object.assign({},n),{lookAt:f}))}))}async endInteraction(){await this.sceneLoadingPromise;if(this.isInteracting()){this.currentCamera=undefined;this.worldRotationPoint=undefined;this.panData=undefined;this.zoomData=undefined;this.resetLastAngle();this.interactionFinishedEmitter.emit();await this.stream.endInteraction()}}resetLastAngle(){this.lastAngle=undefined}isInteracting(){return this.currentCamera!=null}pixelThreshold(t){const i=this.isCoarseInputDevice(t)?this.getConfig().coarsePointerThreshold:this.getConfig().finePointerThreshold;return i*window.devicePixelRatio}async hitItems(t){var i;const n=await(await this.getScene()).raycaster().hitItems(t);return(i=n===null||n===void 0?void 0:n.hits)!==null&&i!==void 0?i:[]}emitTapEvent(t,i,n={},s=0){const{altKey:e=false,ctrlKey:o=false,metaKey:h=false,shiftKey:a=false}=n;t({position:i,altKey:e,ctrlKey:o,metaKey:h,shiftKey:a,buttons:s})}isCoarseInputDevice(t){return t||window.matchMedia("(pointer: coarse)").matches}getWorldPoint(t,i,n){const s=this.getViewport();const e=s.transformPointToFrame(t,i);const o=i.hitTest(e);return o?s.transformPointToWorldSpace(t,i):n}}class $t extends zt{constructor(t,i,n,s,e,o,h,a,r,c,l){super(t,i,n,s,e,o,h,a,r,c,l)}async getWorldPointFromViewport(t){const i=this.getViewport();const n=this.getFrame();if(n==null){throw new Error("Cannot get world point. Frame is undefined.")}const s=await n.depthBuffer();return s!=null?i.transformPointToWorldSpace(t,s,.5):undefined}async panCameraByDelta(t){return this.transformCamera((({camera:i,viewport:n})=>{const s=i.viewVector;const e=h.normalize(i.up);const a=h.normalize(s);const r=o.scale(t,.5,.5);const c=h.magnitude(s);const l=r.x*c/n.width;const u=r.y*c/n.height;const d=h.cross(e,a);const f=h.cross(a,d);const p=h.add(h.scale(l,d),h.scale(u,f));return i.moveBy(p)}))}async panCameraToScreenPoint(t){return this.transformCamera((({camera:i,frame:n,viewport:s,boundingBox:e})=>{if(this.panData==null){const e=i.toFrameCamera();const o=e.direction;const h=s.transformPointToRay(t,n.image,e);const a=r.fromNormalAndCoplanarPoint(o,i.lookAt);const l=c.intersectPlane(h,a);if(l==null){console.warn("Cannot determine fallback for pan. Ray does not intersect plane.");return i}this.panData={hitPt:l,hitPlane:a,startingCamera:e}}if(this.panData!=null){const{hitPt:e,hitPlane:o,startingCamera:a}=this.panData;const r=s.transformPointToRay(t,n.image,a);const l=c.intersectPlane(r,o);if(l!=null){const t=h.subtract(e,l);const n=h.add(a.lookAt,t);return i.update({lookAt:n,rotationPoint:n})}}return i}))}async zoomCameraToPoint(t,i){return this.transformCamera((({camera:n,viewport:s,frame:e,depthBuffer:a,boundingBox:l})=>{if(this.orthographicZoomData==null||o.distance(t,this.orthographicZoomData.startingScreenPt)>2){const i=n.toFrameCamera();const o=i.direction;const h=s.transformPointToRay(t,e.image,i);const l=r.fromNormalAndCoplanarPoint(o,i.lookAt);const u=c.intersectPlane(h,l);if(u==null){console.warn("Cannot determine fallback point for zoom. Ray does not intersect plane.");return n}const d=a!=null?this.getWorldPoint(t,a,u):u;const f=r.fromNormalAndCoplanarPoint(o,d);this.orthographicZoomData={hitPt:d,hitPlane:f,startingScreenPt:t}}if(this.orthographicZoomData!=null){const{hitPt:t,hitPlane:e}=this.orthographicZoomData;const o=4*(n.fovHeight/s.height)*i;const a=Math.max(1,n.fovHeight-o);const c=r.projectPoint(e,n.lookAt);const l=h.scale((n.fovHeight-a)/n.fovHeight,h.subtract(t,c));const u=h.add(n.lookAt,l);return n.update({lookAt:u,rotationPoint:u,fovHeight:Math.max(1,n.fovHeight-o)})}return n}))}async rotateCamera(t){return this.transformCamera((({camera:i,viewport:n,boundingBox:s})=>{var e;const o=h.normalize(i.up);const a=h.normalize(h.subtract(i.lookAt,i.position));const r=h.cross(o,a);const c=h.cross(a,r);const u=h.normalize({x:t.x*r.x+t.y*c.x,y:t.x*r.y+t.y*c.y,z:t.x*r.z+t.y*c.z});const d=h.cross(u,a);const f=9.5*t.x/n.width;const p=9.5*t.y/n.height;const w=Math.abs(f)+Math.abs(p);const m=i.rotationPoint!=null&&((e=i.rotationPoint)===null||e===void 0?void 0:e.x)!=null?i.rotationPoint:i.lookAt;const v=i.rotateAroundAxisAtPoint(w,m,d);const g=_(v.lookAt,v.viewVector,l.center(s));return v.update({lookAt:g})}))}getWorldPoint(t,i,n){const s=this.getViewport();const e=s.transformPointToFrame(t,i);const o=i.hitTest(e);return o?s.transformPointToWorldSpace(t,i):n}}const Ht=.2;class Kt extends zt{constructor(t,i,n,s,e,o,h,a,r,c,l){super(t,i,n,s,e,o,h,a,r,c,l)}async panCameraByDelta(t){return this.transformCamera((({camera:i,viewport:n})=>{var s;const e=i.viewVector;const a=h.normalize(i.up);const r=h.normalize(e);const c=o.scale(t,.25,.25);const l=h.magnitude(e)*Math.tan((s=i.fovY)!==null&&s!==void 0?s:45);const u=c.x*l/n.width;const d=c.y/n.width*l;const f=h.cross(a,r);const p=h.cross(r,f);const w=h.add(h.scale(u,f),h.scale(d,p));return i.moveBy(w)}))}async zoomCameraToPoint(t,i){return this.transformCamera((({camera:n,viewport:s,frame:e,depthBuffer:o,boundingBox:a})=>{const l=e.scene.camera;const u=l.direction;const d=n.toFrameCamera();const f=s.transformPointToRay(t,e.image,d);if(this.zoomData==null){const i=r.fromNormalAndCoplanarPoint(u,l.lookAt);const s=c.intersectPlane(f,i);if(s==null){console.warn("Cannot determine fallback point for zoom. Ray does not intersect plane.");return n}const e=o!=null?this.getWorldPoint(t,o,s):s;const h=r.fromNormalAndCoplanarPoint(u,e);this.zoomData={hitPt:e,hitPlane:h}}if(this.zoomData!=null){const{hitPlane:t}=this.zoomData;const{position:e,distance:o,isPastHitPlane:l,keepCurrent:u}=this.computeZoomDistances(i,n,s,a,f,this.zoomData);if(l&&!u){const t=c.create({origin:e,direction:h.normalize(n.viewVector)});return n.update({position:e,lookAt:c.at(t,o)})}else if(!u){return n.update({position:e,lookAt:r.projectPoint(t,e)})}}return n}))}walk(t){this.transformCamera((({camera:i,boundingBox:n})=>{const{position:s,up:e,lookAt:o}=i;const a=h.normalize(e);const r=h.normalize(i.viewVector);const c=Math.min(...h.toArray(l.lengths(n)));const u=h.scale(c,t);const d=h.cross(a,r);const f=h.cross(d,a);const p=h.scale(u.x,h.normalize(d));const w=h.scale(u.y,h.normalize(a));const m=h.scale(u.z,h.normalize(f));const v=h.negate(h.add(p,w,m));return i.update(Object.assign(Object.assign({},i),{position:h.add(s,v),lookAt:h.add(o,v)}))}))}computeZoomDistances(t,i,n,s,e,o){const a=this.getConfig();const{hitPt:r,hitPlane:l}=o;const u=a.useMinimumPerspectiveZoomDistance?this.computeZoomMinimumDistance(i,s):-1;const d=h.distance(i.position,r);const f=Math.max(u,d);const p=6*f*t/n.height;const w=c.at(e,p);const m=c.create({origin:w,direction:h.normalize(i.viewVector)});const v=c.intersectPlane(m,l);if(v==null&&a.useMinimumPerspectiveZoomDistance){const i=6*u*t/n.height;const s=c.at(e,i);return{position:s,distance:u,isPastHitPlane:true,keepCurrent:false}}else if(v==null){return{position:i.position,distance:f,isPastHitPlane:true,keepCurrent:true}}return{position:w,distance:f,isPastHitPlane:false,keepCurrent:false}}computeZoomMinimumDistance(t,i){const n=Math.abs(i.min.x)+Math.abs(i.max.x);const s=Math.abs(i.min.y)+Math.abs(i.max.y);const e=Math.abs(i.min.z)+Math.abs(i.max.z);const o=Math.max(n,s,e);const a=Math.abs(h.dot(h.normalize(t.viewVector),h.right()));const r=Math.abs(h.dot(h.normalize(t.viewVector),h.up()));const c=Math.abs(h.dot(h.normalize(t.viewVector),h.back()));const l=n*a;const u=s*r;const d=e*c;const f=o/n;const p=o/s;const w=o/e;return(l+u+d)/(f+p+w)*Ht}}class Nt{constructor(t,i,n,s){this.stream=t;this.configProvider=i;this.imageScaleProvider=n;this.sceneProvider=s}predicate(t){return t.altKey&&t.shiftKey}async fn(t){var i,n;const s=this.imageScaleProvider();const e=await this.stream.hitItems({point:o.scale(t.position,(s===null||s===void 0?void 0:s.x)||1,(s===null||s===void 0?void 0:s.y)||1)},true);if(((i=e.hitItems)===null||i===void 0?void 0:i.hits)!=null&&e.hitItems.hits.length>0&&e.hitItems.hits[0].hitPoint!=null){const i=await this.sceneProvider();const s=(await this.sceneProvider()).camera();const o=e.hitItems.hits[0];if(o.hitPoint!=null&&o.hitPoint.x!=null&&o.hitPoint.y!=null&&o.hitPoint.z!=null){const t=h.create(o.hitPoint.x,o.hitPoint.y,o.hitPoint.z);const n=await this.getLookAtPoint(i,t,s.viewVector);await this.stream.flyTo({camera:J(s.update({lookAt:n,rotationPoint:n}).toFrameCamera()),animation:{duration:w(this.configProvider().animation.durationMs)}})}else{console.debug(`No hit position found for fly to position [position={x: ${t.position.x}, y: ${t.position.y}}, hit-id={${(n=o.itemId)===null||n===void 0?void 0:n.hex}}]`)}}else{console.debug(`No hit results found for fly to position [position={x: ${t.position.x}, y: ${t.position.y}}]`)}}getLookAtPoint(t,i,n){if(t.isOrthographic()){return _(i,n,l.center(t.boundingBox()))}else{return i}}}class Vt extends bt{constructor(t,i=new lt,n=new ut,s=new dt,e=new ft,o=new pt,h=new wt){super("mousedown","mouseup","mousemove",i,n,s,e,o,h,t)}}function Wt(t){window.requestAnimationFrame(t)}class qt{constructor(){this.previousFirstPoints=[];this.previousSecondPoints=[]}initialize(t,i){this.element=t;this.interactionApi=i}dispose(){this.element=undefined}beginTwoPointTouch(t,i){this.previousFirstPoints=[...this.previousFirstPoints,t];this.previousSecondPoints=[...this.previousSecondPoints,i]}handleTwoPointTouchMove(t,i){this.previousFirstPoints=[...this.previousFirstPoints,t];this.previousSecondPoints=[...this.previousSecondPoints,i];Wt((()=>{var t,i,n,s;if(this.previousFirstPoints.length>1&&this.previousSecondPoints.length>1&&this.previousFirstPoints.length===this.previousSecondPoints.length){const e=this.previousFirstPoints;const h=this.previousSecondPoints;this.previousFirstPoints=this.previousFirstPoints.slice(-1);this.previousSecondPoints=this.previousSecondPoints.slice(-1);const a=e.reduce(((t,i,n)=>{if(n<e.length-1){const s=e[n+1];const o=h[n];const a=h[n+1];return{deltas:[...t.deltas,this.computeDelta(i,o,s,a)],zooms:[...t.zooms,this.computeZoom(i,o,s,a)],angles:[...t.angles,this.computeAngle(i,o,s,a)]}}return t}),{deltas:[],zooms:[],angles:[]});const r=a.deltas.reduce(((t,i)=>o.add(t,i)),o.create());const c=a.zooms.reduce(((t,i)=>t+i),0);const l=a.angles.reduce(((t,i)=>t+i),0);const u=o.create((e[e.length-1].x+h[h.length-1].x)/2,(e[e.length-1].y+h[h.length-1].y)/2);(t=this.interactionApi)===null||t===void 0?void 0:t.beginInteraction();(i=this.interactionApi)===null||i===void 0?void 0:i.zoomCameraToPoint(u,c);(n=this.interactionApi)===null||n===void 0?void 0:n.panCameraByDelta(r);(s=this.interactionApi)===null||s===void 0?void 0:s.twistCamera(l)}}))}endTwoPointTouch(){this.previousFirstPoints=[];this.previousSecondPoints=[]}computeDelta(t,i,n,s){return o.add(o.subtract(n,t),o.subtract(s,i))}computeZoom(t,i,n,s){const e=o.distance(n,s)-o.distance(t,i);return e*.5}computeAngle(t,i,n,s){const e=u.create(o.subtract(t,i),o.subtract(n,s));return a.toDegrees(Math.atan2(u.determinant(e),u.dot(e)))}}class Ut extends qt{constructor(){super();this.touchPoints={};this.handlePointerDown=this.handlePointerDown.bind(this);this.handlePointerMove=this.handlePointerMove.bind(this);this.handlePointerUp=this.handlePointerUp.bind(this)}dispose(){var t;(t=this.element)===null||t===void 0?void 0:t.removeEventListener("pointerdown",this.handlePointerDown);super.dispose()}initialize(t,i){super.initialize(t,i);t.addEventListener("pointerdown",this.handlePointerDown)}handlePointerDown(t){const i=o.create(t.screenX,t.screenY);this.touchPoints=Object.assign(Object.assign({},this.touchPoints),{[t.pointerId]:i});const n=Object.keys(this.touchPoints);if(n.length===1){window.addEventListener("pointermove",this.handlePointerMove);window.addEventListener("pointerup",this.handlePointerUp)}else if(n.length===2){this.beginTwoPointTouch(this.touchPoints[0],this.touchPoints[1])}}handlePointerMove(t){if(this.touchPoints[t.pointerId]!=null){this.touchPoints[t.pointerId]=o.create(t.screenX,t.screenY)}const i=Object.keys(this.touchPoints);if(i.length===2){const t=this.touchPoints[i[0]];const n=this.touchPoints[i[1]];this.handleTwoPointTouchMove(t,n)}}handlePointerUp(t){var i;delete this.touchPoints[t.pointerId];const n=Object.keys(this.touchPoints);if(n.length===1){(i=this.interactionApi)===null||i===void 0?void 0:i.endInteraction()}if(n.length===0){window.removeEventListener("pointermove",this.handlePointerMove);window.removeEventListener("pointerup",this.handlePointerUp)}this.endTwoPointTouch()}}class _t{constructor(t,i,n,s){this.downEvent=t;this.upEvent=i;this.moveEvent=n;this.getConfig=s;this.handleDown=this.handleDown.bind(this);this.handleUp=this.handleUp.bind(this);this.handleMove=this.handleMove.bind(this);this.handleTouchStart=this.handleTouchStart.bind(this);this.handleTouchMove=this.handleTouchMove.bind(this);this.handleTouchEnd=this.handleTouchEnd.bind(this);this.handlePointerMove=this.handlePointerMove.bind(this);this.handlePointerEnd=this.handlePointerEnd.bind(this);this.clearPositions=this.clearPositions.bind(this);this.restartDoubleTapTimer=this.restartDoubleTapTimer.bind(this);this.clearDoubleTapTimer=this.clearDoubleTapTimer.bind(this);this.restartLongPressTimer=this.restartLongPressTimer.bind(this);this.clearLongPressTimer=this.clearLongPressTimer.bind(this);this.setPointerPositions=this.setPointerPositions.bind(this);this.emit=this.emit.bind(this)}dispose(){var t,i;(t=this.element)===null||t===void 0?void 0:t.removeEventListener(this.downEvent,this.handleDown);(i=this.element)===null||i===void 0?void 0:i.removeEventListener("touchstart",this.handleTouchStart);this.element=undefined;this.clearDoubleTapTimer();this.clearLongPressTimer()}initialize(t,i){this.element=t;this.interactionApi=i;t.addEventListener(this.downEvent,this.handleDown);t.addEventListener("touchstart",this.handleTouchStart,{passive:true})}handleTouchStart(t){if(t.touches.length===1){this.setPointerPositions(o.create(t.touches[0].clientX,t.touches[0].clientY));this.restartLongPressTimer();window.addEventListener("touchend",this.handleTouchEnd);window.addEventListener("touchmove",this.handleTouchMove)}}handleTouchMove(t){if(t.touches.length>0){this.handlePointerMove(o.create(t.touches[0].clientX,t.touches[0].clientY),true)}}handleTouchEnd(t){if(this.pointerDownPosition!=null){window.removeEventListener("touchend",this.handleTouchEnd);window.removeEventListener("touchmove",this.handleTouchMove)}this.handlePointerEnd(this.pointerDownPosition)}handleDown(t){this.setPointerPositions(o.create(t.clientX,t.clientY));this.buttons=t.buttons;const i={altKey:t.altKey,ctrlKey:t.ctrlKey,metaKey:t.metaKey,shiftKey:t.shiftKey};this.restartLongPressTimer(i);window.addEventListener(this.upEvent,this.handleUp);window.addEventListener(this.moveEvent,this.handleMove)}handleMove(t){this.handlePointerMove(o.create(t.clientX,t.clientY),this.isTouch(t))}handleUp(t){if(this.pointerDownPosition!=null){window.removeEventListener(this.upEvent,this.handleUp);window.removeEventListener(this.moveEvent,this.handleMove)}this.handlePointerEnd(o.create(t.clientX,t.clientY),{altKey:t.altKey,ctrlKey:t.ctrlKey,metaKey:t.metaKey,shiftKey:t.shiftKey},this.buttons,this.isTouch(t));this.buttons=undefined}handlePointerMove(t,i){var n;const s=((n=this.interactionApi)===null||n===void 0?void 0:n.pixelThreshold(i))||2;if(this.pointerDownPosition!=null&&o.distance(t,this.pointerDownPosition)>=s&&this.interactionTimer==null){this.clearPositions()}}handlePointerEnd(t,i={},n=0,s=false){var e,o;if(t!=null){if(this.longPressTimer!=null){this.emit((e=this.interactionApi)===null||e===void 0?void 0:e.tap)(t,i,n)}if(this.doubleTapTimer!=null&&this.secondPointerDownPosition!=null){this.emit((o=this.interactionApi)===null||o===void 0?void 0:o.doubleTap)(t,i,n,this.secondPointerDownPosition);this.clearDoubleTapTimer()}}this.pointerDownPosition=undefined;this.clearLongPressTimer()}emit(t){return(i,n={},s=0,e,h=false)=>{var a;const r=e||this.pointerDownPosition;const c=((a=this.interactionApi)===null||a===void 0?void 0:a.pixelThreshold(h))||1;let l;if(this.interactionTimer!=null){l=this.getCanvasPosition(r||i)}else if(r!=null&&o.distance(r,i)<=c){l=this.getCanvasPosition(i)}if(l!=null&&t!=null){t(l,n,s)}}}getCanvasPosition(t){var i;const n=(i=this.element)===null||i===void 0?void 0:i.getBoundingClientRect();const s=n!=null?o.create(n.left,n.top):undefined;return s!=null?o.subtract(o.create(t.x,t.y),s):undefined}clearPositions(){this.pointerDownPosition=undefined;this.firstPointerDownPosition=undefined;this.secondPointerDownPosition=undefined;this.clearDoubleTapTimer();this.clearLongPressTimer();this.clearInteractionTimer()}clearDoubleTapTimer(){if(this.doubleTapTimer!=null){window.clearTimeout(this.doubleTapTimer)}this.doubleTapTimer=undefined;this.firstPointerDownPosition=undefined;this.secondPointerDownPosition=undefined}restartDoubleTapTimer(){this.clearDoubleTapTimer();this.doubleTapTimer=window.setTimeout((()=>this.clearDoubleTapTimer()),this.getConfig().events.doubleTapThreshold)}clearLongPressTimer(){if(this.longPressTimer!=null){window.clearTimeout(this.longPressTimer)}this.longPressTimer=undefined}restartLongPressTimer(t={}){this.clearLongPressTimer();this.longPressTimer=window.setTimeout((()=>{var i;if(this.pointerDownPosition){this.emit((i=this.interactionApi)===null||i===void 0?void 0:i.longPress)(this.pointerDownPosition,t,this.buttons)}this.clearLongPressTimer()}),this.getConfig().events.longPressThreshold)}restartInteractionTimer(){this.clearInteractionTimer();this.interactionTimer=window.setTimeout((()=>{this.interactionTimer=undefined}),this.getConfig().interactions.interactionDelay)}clearInteractionTimer(){if(this.interactionTimer!=null){window.clearTimeout(this.interactionTimer);this.interactionTimer=undefined}}setPointerPositions(t){this.pointerDownPosition=t;this.restartInteractionTimer();if(this.firstPointerDownPosition==null){this.restartDoubleTapTimer();this.firstPointerDownPosition=t}else{this.secondPointerDownPosition=t}}isTouch(t){return window.PointerEvent!=null&&t instanceof PointerEvent?t.pointerType==="touch":false}}class Jt extends qt{constructor(){super();this.handleTouchStart=this.handleTouchStart.bind(this);this.handleTouchMove=this.handleTouchMove.bind(this);this.handleTouchEnd=this.handleTouchEnd.bind(this)}dispose(){var t;(t=this.element)===null||t===void 0?void 0:t.removeEventListener("touchstart",this.handleTouchStart);super.dispose()}initialize(t,i){super.initialize(t,i);t.addEventListener("touchstart",this.handleTouchStart)}handleTouchStart(t){if(t.touches.length>=1){t.preventDefault();const i=t.touches[0];this.currentPosition1=o.create(i.screenX,i.screenY);if(t.touches[1]!=null){this.beginTwoPointTouch(this.currentPosition1,o.create(t.touches[1].screenX,t.touches[1].screenY))}window.addEventListener("touchmove",this.handleTouchMove,{passive:false});window.addEventListener("touchend",this.handleTouchEnd)}}handleTouchMove(t){t.preventDefault();if(t.touches.length===1){this.handleOnePointTouchMove(t.touches[0])}else if(t.touches.length===2){const i=o.create(t.touches[0].clientX,t.touches[0].clientY);const n=o.create(t.touches[1].clientX,t.touches[1].clientY);this.handleTwoPointTouchMove(i,n)}}handleTouchEnd(t){var i;t.preventDefault();(i=this.interactionApi)===null||i===void 0?void 0:i.endInteraction();this.isInteracting=false;window.removeEventListener("touchmove",this.handleTouchMove);window.removeEventListener("touchend",this.handleTouchEnd);this.endTwoPointTouch()}handleOnePointTouchMove(t){var i,n,s;const e=o.create(t.screenX,t.screenY);if(this.currentPosition1!=null){const t=o.subtract(e,this.currentPosition1);const h=((i=this.interactionApi)===null||i===void 0?void 0:i.pixelThreshold(true))||2;if(o.distance(e,this.currentPosition1)>=h||this.isInteracting){(n=this.interactionApi)===null||n===void 0?void 0:n.beginInteraction();(s=this.interactionApi)===null||s===void 0?void 0:s.rotateCamera(t);this.isInteracting=true}}this.currentPosition1=e}}class Xt{constructor(t,i=window.performance){this.name=t;this.perf=i;this.measures=new Set;this.nextId=0}clearMeasurements(){this.perf.clearMeasures(this.name)}measure(t){if(At(t)){const i=this.begin();return t.finally((()=>this.end(i)))}else if(typeof t==="function"){const i=this.begin();const n=t();this.end(i);return n}else{throw new Error("Input must be a function or Promise")}}takeMeasurements(){const t=this.perf.getEntriesByName(this.name);this.clearMeasurements();return t}takeLastMeasurement(){const t=this.takeMeasurements();return t[t.length-1]}begin(){const t=`${this.name}-${this.nextId++}`;this.measures.add(t);this.perf.mark(t);return t}end(t){this.perf.measure(this.name,t);this.perf.clearMarks(t);this.measures.delete(t)}}const Zt=new Xt("paint_time");function Gt(t){return new Promise(((i,n)=>{const s=new Blob([t]);const e=URL.createObjectURL(s);const o=new Image;o.addEventListener("load",(()=>{i({image:o,dispose:()=>undefined});URL.revokeObjectURL(e)}));o.addEventListener("error",(()=>{n(new E("Failed to load image data"));URL.revokeObjectURL(e)}));o.src=e}))}async function Yt(t){const i=new Blob([t]);const n=await window.createImageBitmap(i);return{image:n,dispose:()=>n.close()}}function Qt(t){if(window.createImageBitmap!=null){return Yt(t)}else{return Gt(t)}}const ti=1e3;function ii(t,i){const n=i.viewport.calculateDrawRect(i.frame.image);i.canvas.clearRect(0,0,i.canvasDimensions.width,i.canvasDimensions.height);i.canvas.drawImage(t.image,n.x,n.y,n.width,n.height)}function ni(t,i){const n=t.takeMeasurements();if(n.length>0){i(n)}}function si(t,i,n,s,e=ti){let o;let h=0;let a;let r=[];function c(){h++;if(o==null){o=setInterval((()=>{ni(t,s);if(h===0){u()}}),e)}}function l(){h--}function u(){if(o!=null){clearInterval(o);o=undefined}}if(n){setInterval((()=>{if(a!=null){if(r.length===5){r=[...r.slice(1),a]}else{r.push(a)}const t=r.reduce(((t,i)=>t+i))/r.length;console.debug(`Paint rate: ${a}fps`);console.debug(`Paint rate (avg): ${t}`);a=undefined}}),1e3)}return n=>{c();return t.measure((async()=>{const t=await i(n);a=a==null?1:a+1;return t})).finally((()=>l()))}}function ei(){let t=[];function i(i){if(i!=null){const n=i.copy({correlationIds:[...i.correlationIds,...t.filter((t=>!i.correlationIds.includes(t)))]});t=[];return n}return i}function n(){let t=-1;return async i=>{if(i.frame.sequenceNumber>t){const n=await Qt(i.frame.image.imageBytes);t=i.frame.sequenceNumber;return n}}}function s(){let t=-1;return async(i,n)=>{var s;if(n!=null&&i.frame.sequenceNumber>t){t=i.frame.sequenceNumber;(s=i.beforeDraw)===null||s===void 0?void 0:s.call(i);ii(n,i);n.dispose();return i.frame}n===null||n===void 0?void 0:n.dispose()}}const e=n();const o=s();return async n=>{var s,h;const a=(h=(s=n.predicate)===null||s===void 0?void 0:s.call(n))!==null&&h!==void 0?h:true;t=[...t,...n.frame.correlationIds];if(a){return e(n).then((t=>o(n,t).then(i)))}}}function oi(t){return i=>{var n;const s=(n=i.request.requestId)===null||n===void 0?void 0:n.value;if(s!=null){t(s)(i)}}}function hi(t){return i=>{const{drawFrame:n}=i.request;if(n!=null){t(n)(i)}}}const ai=1*60;function ri(t){let i=false;return n=>{const s=t();if(s!=null){const t=s.remoteTime(new Date(Date.now()));const e=w(n,t);const o=p(e).getTime();if(o>=0){return e}else{if(!i){console.warn(`Possible erroneous send to receive timing. Muting for ${ai}s. [sent-at=${n.toISOString()}, received-at=${t.toISOString()}, remote-time=${s.knownRemoteTime.toISOString()}]`);i=true;setTimeout((()=>i=false),ai*1e3)}return undefined}}}}function ci(t,i){const n=ri(i);return oi((i=>hi((s=>s=>{const e=p(s.sentAtTime);if(e!=null){t.replyResult(i,{drawFrame:{sendToReceiveDuration:n(e)}})}}))))}var li;(function(t){t["DEVICE_ID"]="vertexvis:device-id"})(li||(li={}));function ui(t,i,n=window.localStorage){const s=n.getItem(t);if(s!=null){const e=Object.assign(Object.assign({},JSON.parse(s)),i);n.setItem(t,JSON.stringify(e))}else{n.setItem(t,JSON.stringify(i))}}function di(t,i,n=window.localStorage){const s=n.getItem(t);if(s!=null){return i(JSON.parse(s))}}var fi=function t(i,n){if(i===n)return true;if(i&&n&&typeof i=="object"&&typeof n=="object"){if(i.constructor!==n.constructor)return false;var s,e,o;if(Array.isArray(i)){s=i.length;if(s!=n.length)return false;for(e=s;e--!==0;)if(!t(i[e],n[e]))return false;return true}if(i.constructor===RegExp)return i.source===n.source&&i.flags===n.flags;if(i.valueOf!==Object.prototype.valueOf)return i.valueOf()===n.valueOf();if(i.toString!==Object.prototype.toString)return i.toString()===n.toString();o=Object.keys(i);s=o.length;if(s!==Object.keys(n).length)return false;for(e=s;e--!==0;)if(!Object.prototype.hasOwnProperty.call(n,o[e]))return false;for(e=s;e--!==0;){var h=o[e];if(!t(i[h],n[h]))return false}return true}return i!==i&&n!==n};class pi extends m{constructor(t,i={}){var n,s,e,o,h;super(t,{loggingEnabled:i.loggingEnabled});this.state={type:"disconnected"};this.stateChanged=new P;this.dimensions=d.create(0,0);this.streamAttributes={};this.enableTemporalRefinement=(n=i.enableTemporalRefinement)!==null&&n!==void 0?n:true;this.frameBgColor=I.create(255,255,255);this.config=ot("platprod");this.options={tokenRefreshOffsetInSeconds:(s=i.tokenRefreshOffsetInSeconds)!==null&&s!==void 0?s:30,offlineThresholdInSeconds:(e=i.offlineThresholdInSeconds)!==null&&e!==void 0?e:30,loadTimeoutInSeconds:(o=i.loadTimeoutInSeconds)!==null&&o!==void 0?o:15,enableTemporalRefinement:(h=i.enableTemporalRefinement)!==null&&h!==void 0?h:true}}getState(){return this.state}disconnect(){if(this.state.type!=="disconnected"&&this.state.type!=="connection-failed"){console.debug("Disconnecting websocket");this.state.connection.dispose();this.updateState({type:"disconnected"})}}async load(t,i,n,s=ot("platprod")){this.clientId=i;this.deviceId=n;this.config=s;if(this.state.type==="disconnected"){return this.loadIfDisconnected(t)}else if(this.state.type==="connection-failed"){return this.loadIfDisconnected(t)}else if(this.state.type==="reconnecting"){return this.loadIfConnectingOrConnected(t,this.state)}else if(this.state.type==="connecting"){return this.loadIfConnectingOrConnected(t,this.state)}else{return this.loadIfConnectingOrConnected(t,this.state)}}update(t){this.frameBgColor=t.frameBgColor?t.frameBgColor:this.frameBgColor;if(t.dimensions!=null&&!fi(t.dimensions,this.dimensions)){this.dimensions=t.dimensions;this.ifState("connected",(()=>this.updateDimensions({dimensions:this.getDimensions()})))}if(t.streamAttributes!=null&&!fi(this.streamAttributes,t.streamAttributes)){this.streamAttributes=t.streamAttributes;this.ifState("connected",(()=>this.updateStream({streamAttributes:wi(this.streamAttributes)})))}if(t.enableTemporalRefinement!=null&&t.enableTemporalRefinement!==this.enableTemporalRefinement){this.enableTemporalRefinement=t.enableTemporalRefinement;if(this.state.type==="connected"){this.closeAndReconnect(this.state)}}}async loadIfConnectingOrConnected(t,i){var n;const{resource:s,subResource:e}=i.resource;const o=mt(t);const h=!S.isEqual(s,o.resource);const a=!S.isEqual(e,o.subResource);const r=i.type==="connecting"||i.type==="reconnecting";const c=i.type==="connected";const l=o.queries.find((t=>t.type==="supplied-id"));if(h||r&&a){this.disconnect();return this.loadIfDisconnected(t)}else if(c&&a&&((n=o.subResource)===null||n===void 0?void 0:n.type)==="scene-view-state"){const t=Object.assign(Object.assign({},o.subResource.id!=null?{sceneViewStateId:{hex:o.subResource.id}}:{}),l!=null?{sceneViewStateSuppliedId:{value:l.id}}:{});await this.loadSceneViewState(t);this.updateState(Object.assign(Object.assign({},i),{resource:o}))}}async loadIfDisconnected(t){try{await this.connectWithNewStream(mt(t))}catch(t){if(t instanceof O){this.updateState({type:"connection-failed",message:`Cannot load scene. ${t.message}`,error:t})}else if(t instanceof v){this.updateState({type:"connection-failed",message:`Cannot load scene. Stream request failed to start stream.`,error:t})}else{this.updateState({type:"connection-failed",message:`Cannot load scene for unknown reason. See console logs.`,error:t})}throw t}}connectWithNewStream(t){return this.openWebsocketStream(t,"connecting",(()=>this.requestNewStream(t)))}connectToExistingStream(t){return this.openWebsocketStream(t.resource,"reconnecting",(()=>this.requestReconnectStream(t)),{maxRetries:Number.POSITIVE_INFINITY})}async openWebsocketStream(t,i,n,{maxRetries:s=3}={}){const e=gi(yi(this.config,t.resource,this.clientId,this.deviceId));console.debug(`Initiating WS connection [uri=${e.url}]`);const o=new AbortController;const h=vi(this.config);this.updateState({type:i,resource:t,connection:{dispose:()=>{this.dispose();o.abort()}}});const a=await T.abort(o.signal,T.retry((()=>this.connect(e,h)),{maxRetries:s,delaysInMs:pi.WS_RECONNECT_DELAYS})).catch((t=>{throw new D("Websocket connection failed.",t instanceof Error?t:undefined)}));if(!a.aborted){return this.requestNewOrExistingStream(t,a.result,n)}else{this.updateState({type:"disconnected"})}}async requestNewOrExistingStream(t,i,n){const s=this.requestClock();const e=await n();console.debug(`Stream connected [stream-id=${e.streamId}, scene-id=${e.sceneId}, scene-view-id=${e.sceneViewId}]`);const o=this.onRequest((t=>{const i=t.request.drawFrame;if(i!=null){const t=G(e.worldOrientation)(i);if(this.state.type==="connected"){if(t.depthBufferBytes!=null||this.state.frame.temporalRefinementCorrelationId!==t.temporalRefinementCorrelationId){this.updateState(Object.assign(Object.assign({},this.state),{frame:t,fallbackDepthBufferBytes:t.depthBufferBytes}))}else{this.updateState(Object.assign(Object.assign({},this.state),{frame:t.copy({depthBufferBytes:this.state.fallbackDepthBufferBytes})}))}}}}));const h=this.reconnectWhenNeeded();const a=this.refreshTokenWhenExpired(e.token);const r=this.acknowledgeFrameRequests();const c=e.frame==null?await this.waitForFrame(e.worldOrientation,this.options.loadTimeoutInSeconds):e.frame;const l=await s;console.debug(`Synchronized clocks [local-time=${l.knownLocalTime.toISOString()}, remote-time=${l.knownRemoteTime.toISOString()}]`);this.updateState({type:"connected",connection:{dispose:()=>{h.dispose();o.dispose();a.dispose();r.dispose();i.dispose()}},resource:t,streamId:e.streamId,deviceId:e.deviceId,sceneId:e.sceneId,sceneViewId:e.sceneViewId,worldOrientation:e.worldOrientation,token:e.token,frame:c,clock:l,fallbackDepthBufferBytes:undefined})}async requestNewStream(t){var i,n;const s=t.queries.find((t=>t.type==="supplied-id"));const e=Y(await this.startStream({streamKey:{value:t.resource.id},dimensions:this.getDimensions(),frameBackgroundColor:mi(this.frameBgColor),clientSupportsTemporalRefinement:this.enableTemporalRefinement,streamAttributes:wi(this.streamAttributes),sceneViewStateId:((i=t.subResource)===null||i===void 0?void 0:i.type)==="scene-view-state"&&t.subResource.id!=null?{hex:t.subResource.id}:undefined,sceneViewStateSuppliedId:((n=t.subResource)===null||n===void 0?void 0:n.type)==="scene-view-state"&&s!=null?{value:s.id}:undefined}));return{resource:t,streamId:e.streamId,sceneId:e.sceneId,sceneViewId:e.sceneViewId,deviceId:e.sessionId,token:e.token,worldOrientation:e.worldOrientation,frame:undefined,fallbackDepthBufferBytes:undefined}}async requestReconnectStream(t){const i=Q(await this.reconnect({streamId:{hex:t.streamId},dimensions:this.getDimensions(),frameBackgroundColor:mi(this.frameBgColor),streamAttributes:wi(this.streamAttributes),clientSupportsTemporalRefinement:this.enableTemporalRefinement}));return Object.assign(Object.assign({},t),{token:i.token})}async requestClock(){const t=tt(await this.syncTime({requestTime:g()}));return new vt(t)}reconnectWhenNeeded(){const t=this.onClose((()=>{if(this.state.type==="connected"){this.closeAndReconnect(this.state)}}));const i=this.onRequest((t=>{const i=t.request.gracefulReconnection!=null;if(i&&this.state.type==="connected"){console.debug("Received request for graceful reconnect. Closing connection and attempting reconnect.");this.closeAndReconnect(this.state)}}));const n=this.reconnectWhenOffline();return{dispose:()=>{t.dispose();i.dispose();n.dispose()}}}refreshTokenWhenExpired(t){let i;const n=t=>{const{tokenRefreshOffsetInSeconds:s}=this.options;const e=t.remainingTimeInMs(s);i=window.setTimeout((async()=>{const t=await this.refreshToken();const i=it(t);n(i);if(this.state.type==="connected"){this.updateState(Object.assign(Object.assign({},this.state),{token:i}))}}),e)};n(t);return{dispose:()=>clearTimeout(i)}}reconnectWhenOffline(){let t;const i=()=>window.clearTimeout(t);const n=()=>{i();const n=this.options.offlineThresholdInSeconds;console.debug(`Detected that host is offline. Will attempt reconnect in ${n}s.`);t=window.setTimeout((()=>{if(this.state.type==="connected"){this.closeAndReconnect(this.state)}}),n*1e3)};const s=()=>{console.debug("Detected that host is online.");i()};const e=()=>n();window.addEventListener("offline",e);window.addEventListener("online",s);return{dispose:()=>{i();window.removeEventListener("offline",n);window.removeEventListener("online",i)}}}closeAndReconnect(t){t.connection.dispose();return this.connectToExistingStream(t)}async waitForFrame(t,i){let n;try{return await T.timeout(i*1e3,new Promise((i=>{n=this.onRequest((s=>{try{const e=s.request.drawFrame;if(e!=null){const n=G(t)(e);i(n)}}finally{n===null||n===void 0?void 0:n.dispose()}}))})))}catch(t){throw new M(`Frame timed out after ${i/1e3}s`,t instanceof Error?t:undefined)}finally{n===null||n===void 0?void 0:n.dispose()}}acknowledgeFrameRequests(){return this.onRequest(ci(this,(()=>this.state.type==="connected"?this.state.clock:undefined)))}updateState(t){if(this.state!==t){this.state=t;this.stateChanged.emit(this.state)}}getDimensions(){if(d.area(this.dimensions)===0){return d.create(1,1)}return this.dimensions}ifState(t,i){if(this.state.type===t){return i()}}onStateChanged(t){return this.stateChanged.on(t)}}pi.WS_RECONNECT_DELAYS=[0,1e3,1e3,5e3];const wi=b.ifInvalidThrow(X);const mi=b.ifInvalidThrow(Z);function vi(t){return{EXPERIMENTAL_frameDelivery:Object.assign(Object.assign({},t.EXPERIMENTAL_frameDelivery),{rateLimitingEnabled:t.flags.throttleFrameDelivery}),EXPERIMENTAL_adaptiveRendering:Object.assign(Object.assign({},t.EXPERIMENTAL_adaptiveRendering),{enabled:t.flags.adaptiveRendering}),EXPERIMENTAL_qualityOfService:Object.assign({},t.EXPERIMENTAL_qualityOfService)}}function gi(t){return{url:A.toString(t),protocols:["ws.vertexvis.com"]}}function yi(t,i,n,s){if(n!=null){return A.appendPath(A.toString(A.parseAndAddParams("/ws",{clientId:n,deviceId:s})),A.parse(t.network.renderingHost))}else{return A.appendPath(`/stream-keys/${i.id}/session`,A.parse(t.network.renderingHost))}}const bi=15e3;function Ci(t){return t.getBoundingClientRect()}function Pi(t,i){const n=window.getComputedStyle(t);const s=n.getPropertyValue(i);return s!==""?s:undefined}const Ti=":host{--image-background:var(--image-background);--viewer-background:var(--viewer-background);display:block;position:relative;width:300px;height:300px;min-width:1px;min-height:1px;user-select:none;-webkit-user-select:none}.canvas-container{display:flex;justify-content:center;align-items:center;width:100%;height:100%;position:relative}.enable-pointer-events{touch-action:none}.viewer-container{width:100%;height:100%;overflow:hidden}.error-message{position:absolute;top:50%;width:100%;transform:translateY(-50%);text-align:center}";const Ii=class{constructor(n){t(this,n);this.tap=i(this,"tap",7);this.doubletap=i(this,"doubletap",7);this.longpress=i(this,"longpress",7);this.frameReceived=i(this,"frameReceived",7);this.frameDrawn=i(this,"frameDrawn",7);this.tokenExpired=i(this,"tokenExpired",7);this.connectionChange=i(this,"connectionChange",7);this.sceneReady=i(this,"sceneReady",7);this.sceneChanged=i(this,"sceneChanged",7);this.interactionStarted=i(this,"interactionStarted",7);this.interactionFinished=i(this,"interactionFinished",7);this.cameraTypeChanged=i(this,"cameraTypeChanged",7);this.annotationStateChanged=i(this,"annotationStateChanged",7);this.deviceIdChange=i(this,"deviceIdChange",7);this.dimensionschange=i(this,"dimensionschange",7);this.configEnv="platprod";this.cameraControls=true;this.cameraType="perspective";this.keyboardControls=true;this.rotateAroundTapPoint=true;this.phantom={opacity:.1};this.noDefaultLights=false;this.enableTemporalRefinement=true;this.experimentalRenderingOptions="";this.resizeDebounce=100;this.stencilBuffer=new It(this.hostElement);this.viewport=ct.fromDimensions(d.create(0,0));this.stateMap={cursorManager:new ht,streamState:{type:"disconnected"}};this.interactionHandlers=[];this.defaultInteractionHandlerDisposables=[];this.tapKeyInteractions=[];this.defaultTapKeyInteractions=[];this.internalFrameDrawnDispatcher=new P;this.handleElementResize=this.handleElementResize.bind(this)}componentWillLoad(){var t;this.updateResolvedConfig();this.calculateComponentDimensions();this.resizeObserver=new ResizeObserver(this.handleElementResize);this.registerSlotChangeListeners();const i=this.getResolvedConfig();const n=new f(i.network.sceneViewHost);this.annotations=new Ft(n,(()=>this.token),(()=>this.deviceId));this.annotations.onStateChange.on((t=>this.annotationStateChanged.emit(t)));this.stream=(t=this.stream)!==null&&t!==void 0?t:new pi(new y,{loggingEnabled:i.flags.logWsMessages,enableTemporalRefinement:this.enableTemporalRefinement});this.addStreamListeners();this.updateStreamAttributes();this.stateMap.cursorManager.onChanged.on((()=>this.handleCursorChanged()))}async componentDidLoad(){var t;this.interactionApi=this.createInteractionApi();if(this.canvasContainerElement!=null){(t=this.resizeObserver)===null||t===void 0?void 0:t.observe(this.canvasContainerElement)}if(this.src!=null){this.load(this.src).catch((t=>{console.error("Error loading scene",t)}))}await this.initializeDefaultInteractionHandlers();this.injectViewerApi()}render(){var t;return n(s,null,n("div",{ref:t=>this.viewerContainerElement=t,class:"viewer-container",style:{cursor:at((t=this.cursor)!==null&&t!==void 0?t:"")},onContextMenu:t=>t.preventDefault()},n("div",{ref:t=>this.canvasContainerElement=t,class:j("canvas-container",{"enable-pointer-events ":window.PointerEvent!=null})},n("canvas",{ref:t=>{this.canvasElement=t;this.stateMap.interactionTarget=t},class:"canvas"}),this.errorMessage!=null?n("div",{class:"error-message"},this.errorMessage):null),n("slot",null)))}async dispatchFrameDrawn(t){this.frame=t;this.internalFrameDrawnDispatcher.emit(t);this.frameDrawn.emit(t)}async registerInteractionHandler(t){this.interactionHandlers.push(t);this.initializeInteractionHandler(t);return{dispose:()=>{const i=this.interactionHandlers.indexOf(t);if(i!==-1){this.interactionHandlers[i].dispose();this.interactionHandlers.splice(i,1)}}}}async registerTapKeyInteraction(t){this.tapKeyInteractions=[...this.tapKeyInteractions,t]}async getInteractionTarget_DEPRECATED(){if(this.stateMap.interactionTarget!=null){return this.stateMap.interactionTarget}else throw new Error("Interaction target is undefined.")}async addCursor(t,i){return this.stateMap.cursorManager.add(t,i)}async getInteractionHandlers(){return this.interactionHandlers}async getKeyInteractions(){return this.tapKeyInteractions}async getBaseInteractionHandler(){return this.baseInteractionHandler}async getJwt(){return this.token}handleSrcChanged(t){if(t!=null){this.load(t)}else{this.unload()}}handleCameraControlsChanged(){this.initializeDefaultCameraInteractionHandlers()}handleKeyboardControlsChanged(){this.initializeDefaultKeyboardInteractionHandlers()}handleRotateAboutTapPointChanged(){var t,i;this.updateStreamAttributes();if(this.rotateAroundTapPoint){(t=this.baseInteractionHandler)===null||t===void 0?void 0:t.setPrimaryInteractionType("rotate-point")}else{(i=this.baseInteractionHandler)===null||i===void 0?void 0:i.setPrimaryInteractionType("rotate")}}handleCameraTypeChanged(t,i){if(t!==i){this.updateCameraType()}}handleDepthBuffersChanged(){this.updateStreamAttributes()}handlePhantomChanged(){this.updateStreamAttributes()}handleNoDefaultLightsChanged(){this.updateStreamAttributes()}handleExperimentalRenderingOptionsChanged(){this.updateStreamAttributes()}handleEnableTemporalRefinementChanged(){this.updateEnableTemporalRefinement()}handleFeatureLinesChanged(){this.updateStreamAttributes()}handleSelectionHighlightingChanged(){this.updateStreamAttributes()}handleFeatureHighlightingChanged(){this.updateStreamAttributes()}handleFeatureMapsChanged(){this.updateStreamAttributes()}handleConfigChanged(){this.updateResolvedConfig()}handleConfigEnvChanged(){this.updateResolvedConfig()}async load(t){var i,n;if(this.stream!=null&&this.dimensions!=null){const{EXPERIMENTAL_annotationPollingIntervalInMs:s}=this.getResolvedConfig();this.calculateComponentDimensions();this.stream.update({streamAttributes:this.getStreamAttributes(),config:ot(this.configEnv,this.config),dimensions:this.dimensions,frameBgColor:this.getBackgroundColor()});await((i=this.stream)===null||i===void 0?void 0:i.load(t,this.clientId,this.getDeviceId(),this.getResolvedConfig()));this.sceneReady.emit();if(s!==undefined){(n=this.annotations)===null||n===void 0?void 0:n.connect(s)}}else{throw new x("Cannot load scene. Viewer has not been initialized.")}}async unload(){var t;if(this.stream!=null){(t=this.annotations)===null||t===void 0?void 0:t.disconnect();this.stream.disconnect();this.frame=undefined;this.errorMessage=undefined}if(this.canvasElement!=null){const t=this.canvasElement.getContext("2d");if(t!=null){t.clearRect(0,0,this.canvasElement.width,this.canvasElement.height)}}}async scene(){return this.createScene()}async isSceneReady(){return this.stateMap.streamState.type==="connected"}async handleTapEvent(t){this.tapKeyInteractions.filter((i=>i.predicate(t.detail))).forEach((i=>i.fn(t.detail)))}emitConnectionChange(t){this.connectionChange.emit(t)}handleElementResize(t){const i=t.length>0&&this.dimensions!=null&&!d.isEqual(t[0].contentRect,this.viewport);if(i){if(this.resizeTimer!=null){clearTimeout(this.resizeTimer);this.resizeTimer=undefined}if(!this.isResizing){this.resizeTimer=setTimeout((()=>{this.isResizing=true;this.isResizeUpdate=true;this.recalculateComponentDimensions()}),this.resizeDebounce)}}}registerSlotChangeListeners(){this.mutationObserver=new MutationObserver((t=>this.injectViewerApi()));this.mutationObserver.observe(this.hostElement,{childList:true,subtree:true});this.styleObserver=new MutationObserver((t=>this.syncViewerStyles()));this.styleObserver.observe(this.hostElement,{attributes:true,attributeFilter:["style"]})}injectViewerApi(){function t(t){return Array.from(t.querySelectorAll("*"))}const i=t(this.hostElement);i.filter((t=>t.nodeName.startsWith("VERTEX-"))).reduce(((i,n)=>[...i,n,...t(n)]),[]).forEach((t=>{t.viewer=this.hostElement}))}syncViewerStyles(){var t;const i=this.getBackgroundColor();(t=this.stream)===null||t===void 0?void 0:t.update({frameBgColor:i,streamAttributes:this.getStreamAttributes()})}calculateComponentDimensions(){var t;const i=2073600;const n=this.getBounds();if((n===null||n===void 0?void 0:n.width)!=null&&(n===null||n===void 0?void 0:n.height)!=null){const s=d.create(n.width,n.height);const e=d.scaleFit(i,s);this.hostDimensions=s;this.dimensions=e!=null?d.create(e.width,e.height):undefined;this.viewport=ct.fromDimensions((t=this.getCanvasDimensions())!==null&&t!==void 0?t:d.create(0,0))}}recalculateComponentDimensions(){var t;if(this.isResizing){this.calculateComponentDimensions();this.isResizing=false;if(((t=this.stream)===null||t===void 0?void 0:t.getState().type)==="connected"){this.updateDimensions(this.dimensions)}}}reportPerformance(t){if(this.stateMap.streamState.type==="connected"){const i={timings:t.map((t=>({receiveToPaintDuration:w(t.duration)})))};this.getStream().recordPerformance(i,false)}}addStreamListeners(){this.stateMap.streamListeners=this.getStream().stateChanged.on((t=>{this.handleStreamStateChanged(this.stateMap.streamState,t)}))}handleStreamStateChanged(t,i){this.stateMap.streamState=i;if(i.type==="connecting"){this.handleConnecting(t,i)}else if(i.type==="connected"){this.handleConnected(t,i)}else if(i.type==="connection-failed"){this.handleConnectionFailed(t,i)}else if(i.type==="disconnected"){this.handleDisconnected(t,i)}}handleConnecting(t,i){if(t.type!=="connecting"){this.token=undefined;this.errorMessage=undefined;this.emitConnectionChange({status:"connecting"})}}handleConnected(t,i){var n;this.token=i.token.token;if(t.type!=="connected"){this.errorMessage=undefined;this.canvasRenderer=si(Zt,ei(),this.getResolvedConfig().flags.logFrameRate,(t=>this.reportPerformance(t)));this.emitConnectionChange({status:"connected",jwt:i.token.token});this.deviceIdChange.emit(i.deviceId)}if(((n=this.frame)===null||n===void 0?void 0:n.getId())!==i.frame.getId()){this.updateFrame(i.frame)}this.updateDimensions(this.dimensions)}handleConnectionFailed(t,i){if(t.type!=="connection-failed"){this.token=undefined;this.errorMessage=i.message;this.emitConnectionChange({status:"connection-failed",errorMessage:i.message})}}handleDisconnected(t,i){if(t.type!=="disconnected"){this.token=undefined;this.errorMessage=undefined;this.emitConnectionChange({status:"disconnected"})}}updateDimensions(t){var i;(i=this.stream)===null||i===void 0?void 0:i.update({dimensions:t});this.dimensionschange.emit(t)}async updateFrame(t){var i;const n=this.getCanvasDimensions();if(this.canvasElement!=null&&n!=null&&((i=this.frame)===null||i===void 0?void 0:i.getId())!==t.getId()){const i=this.canvasElement.getContext("2d");if(i!=null){const s=this.frame;this.frame=nt(t,s);this.updateInteractionApi(s);const e={canvas:i,canvasDimensions:n,dimensions:this.dimensions,frame:this.frame,viewport:this.viewport,beforeDraw:()=>{this.updateCanvasDimensions(n);this.isResizeUpdate=false},predicate:()=>{if(this.isResizeUpdate){return this.dimensions==null||d.isEqual(this.dimensions,e.frame.image.imageAttr.frameDimensions)}return true}};this.frameReceived.emit(this.frame);if(this.frame.scene.hasChanged){this.sceneChanged.emit()}const o=await this.canvasRenderer(e);if(o!=null){this.updateViewerBackground();this.dispatchFrameDrawn(o)}}}}updateViewerBackground(){const t=this.getBackgroundColor();Ct((()=>{var i,n;(i=this.viewerContainerElement)===null||i===void 0?void 0:i.style.setProperty("background",t!=null?I.toHexString(t):"#ffffff");(n=this.canvasContainerElement)===null||n===void 0?void 0:n.style.setProperty("background",t!=null?I.toHexString(t):"#ffffff")}))}async initializeDefaultInteractionHandlers(){var t;await this.initializeDefaultCameraInteractionHandlers();await this.initializeDefaultTapInteractionHandler();this.initializeDefaultKeyboardInteractionHandlers();if(this.rotateAroundTapPoint){(t=this.baseInteractionHandler)===null||t===void 0?void 0:t.setPrimaryInteractionType("rotate-point")}}clearDefaultCameraInteractionHandlers(){this.defaultInteractionHandlerDisposables.forEach((t=>t.dispose()));this.defaultInteractionHandlerDisposables=[]}clearDefaultKeyboardInteractions(){this.defaultTapKeyInteractions.forEach((t=>{const i=this.tapKeyInteractions.indexOf(t);if(i!==-1){this.tapKeyInteractions.splice(i,1)}}));this.tapKeyInteractions=[]}async initializeDefaultCameraInteractionHandlers(){var t,i;this.clearDefaultCameraInteractionHandlers();if(this.cameraControls){if(window.PointerEvent!=null){this.baseInteractionHandler=(t=this.baseInteractionHandler)!==null&&t!==void 0?t:new gt((()=>this.getResolvedConfig()));const i=await this.registerInteractionHandler(this.baseInteractionHandler);const n=await this.registerInteractionHandler(new Ut);this.defaultInteractionHandlerDisposables=[i,n]}else{this.baseInteractionHandler=(i=this.baseInteractionHandler)!==null&&i!==void 0?i:new Vt((()=>this.getResolvedConfig()));const t=await this.registerInteractionHandler(this.baseInteractionHandler);const n=await this.registerInteractionHandler(new Jt);this.defaultInteractionHandlerDisposables=[t,n]}}}initializeDefaultKeyboardInteractionHandlers(){var t;this.clearDefaultKeyboardInteractions();if(this.keyboardControls&&this.stream!=null){(t=this.baseInteractionHandler)===null||t===void 0?void 0:t.setDefaultKeyboardControls(this.keyboardControls);const i=new Lt(this.stream,(()=>this.getResolvedConfig()),(()=>this.getImageScale()));const n=new Nt(this.stream,(()=>this.getResolvedConfig()),(()=>this.getImageScale()),(()=>this.createScene()));this.registerTapKeyInteraction(i);this.registerTapKeyInteraction(n);this.defaultTapKeyInteractions=[i,n]}}async initializeDefaultTapInteractionHandler(){if(this.tapHandlerDisposable==null){if(window.PointerEvent!=null){const t=new _t("pointerdown","pointerup","pointermove",(()=>this.getResolvedConfig()));this.tapHandlerDisposable=await this.registerInteractionHandler(t)}else{const t=new _t("mousedown","mouseup","mousemove",(()=>this.getResolvedConfig()));this.tapHandlerDisposable=await this.registerInteractionHandler(t)}}}initializeInteractionHandler(t){if(this.stateMap.interactionTarget==null){throw new R("Cannot initialize interaction handler. Interaction target is undefined.")}if(this.interactionApi==null){throw new R("Cannot initialize interaction handler. Interaction APi is undefined.")}t.initialize(this.stateMap.interactionTarget,this.interactionApi)}createInteractionApi(){if(this.stream==null){throw new B("Cannot create interaction API. Component has not been initialized.")}return this.frame==null||this.frame.scene.camera.isPerspective()?new Kt(this.stream,this.stateMap.cursorManager,(()=>this.getResolvedConfig().interactions),(()=>this.createScene()),(()=>this.frame),(()=>this.viewport),this.tap,this.doubletap,this.longpress,this.interactionStarted,this.interactionFinished):new $t(this.stream,this.stateMap.cursorManager,(()=>this.getResolvedConfig().interactions),(()=>this.createScene()),(()=>this.frame),(()=>this.viewport),this.tap,this.doubletap,this.longpress,this.interactionStarted,this.interactionFinished)}handleCursorChanged(){window.requestAnimationFrame((()=>{this.cursor=this.stateMap.cursorManager.getActiveCursor()}))}async createScene(){const t=await this.waitForConnectedState();const{frame:i,sceneId:n,sceneViewId:s,worldOrientation:e}=t;return new yt(this.getStream(),i,G(e),(()=>this.getImageScale()),this.viewport,n,s)}getBackgroundColor(){if(this.canvasContainerElement!=null){const t=Pi(this.hostElement,"--image-background");const i=Pi(this.hostElement,"--viewer-background");const n=t!==null&&t!==void 0?t:i;return n!=null?I.fromCss(n):I.create(255,255,255)}}getBounds(){return Ci(this.hostElement)}getCanvasDimensions(){return this.getResolvedConfig().flags.letterboxFrames?this.dimensions:this.hostDimensions}getImageScale(){const t=this.getCanvasDimensions();if(this.dimensions!=null&&t!=null){return o.create(this.dimensions.width/t.width,this.dimensions.height/t.height)}}getStreamAttributes(){return{depthBuffers:this.getDepthBufferStreamAttributesValue(),phantom:this.phantom,noDefaultLights:this.noDefaultLights,featureLines:this.featureLines,featureHighlighting:this.featureHighlighting,featureMaps:this.featureMaps,experimentalRenderingOptions:this.experimentalRenderingOptions,selectionHighlighting:this.selectionHighlighting,frames:{frameBackgroundColor:this.getBackgroundColor()}}}updateCanvasDimensions(t){if(this.canvasElement!=null){this.canvasElement.width=t.width;this.canvasElement.height=t.height}}updateStreamAttributes(){var t;(t=this.stream)===null||t===void 0?void 0:t.update({streamAttributes:this.getStreamAttributes()})}updateEnableTemporalRefinement(){var t;(t=this.stream)===null||t===void 0?void 0:t.update({enableTemporalRefinement:this.enableTemporalRefinement})}updateInteractionApi(t){if(this.frame!=null){const i=(t==null||t.scene.camera.isPerspective())&&this.frame.scene.camera.isOrthographic();const n=(t==null||t.scene.camera.isOrthographic())&&this.frame.scene.camera.isPerspective();if(i||n){this.interactionApi=this.createInteractionApi();this.cameraType=this.frame.scene.camera.isPerspective()?"perspective":"orthographic";this.cameraTypeChanged.emit(this.cameraType);this.interactionHandlers.forEach((t=>this.initializeInteractionHandler(t)))}}}updateCameraType(){var t,i;if(this.frame!=null){if(this.cameraType==="orthographic"&&this.frame.scene.camera.isPerspective()){(t=this.stream)===null||t===void 0?void 0:t.replaceCamera({camera:J(st(this.frame.scene.camera,this.frame.scene.boundingBox))})}else if(this.cameraType==="perspective"&&this.frame.scene.camera.isOrthographic()){(i=this.stream)===null||i===void 0?void 0:i.replaceCamera({camera:J(et(this.frame.scene.camera))})}}}getDepthBufferStreamAttributesValue(){var t;const i=(t=this.depthBuffers)!==null&&t!==void 0?t:this.rotateAroundTapPoint?"final":undefined;return i}updateResolvedConfig(){this.resolvedConfig=ot(this.configEnv,this.config)}getResolvedConfig(){return Si("Resolved config is undefined",(()=>this.resolvedConfig))}getStream(){return Si("Stream is undefined",(()=>this.stream))}getDeviceId(){if(this.deviceId==null){try{this.deviceId=di(li.DEVICE_ID,(t=>t["device-id"]))}catch(t){console.warn("Cannot read device ID. Local storage is not supported.")}if(this.deviceId==null){this.deviceId=C.create();try{ui(li.DEVICE_ID,{["device-id"]:this.deviceId})}catch(t){console.warn("Cannot write device ID. Local storage is not supported.")}}}return this.deviceId}async waitForConnectedState(){if(this.stateMap.streamState.type!=="connected"){console.debug("Stream was not in a connected state. Waiting for successful connection.");return new Promise(((t,i)=>{const n=this.getStream().onStateChanged((i=>{if(i.type==="connected"){t(i)}}));setTimeout((()=>{n.dispose();i(new Error("Timed out waiting for connected state."))}),bi)}))}return this.stateMap.streamState}get hostElement(){return e(this)}static get watchers(){return{src:["handleSrcChanged"],cameraControls:["handleCameraControlsChanged"],keyboardControls:["handleKeyboardControlsChanged"],rotateAroundTapPoint:["handleRotateAboutTapPointChanged"],cameraType:["handleCameraTypeChanged"],depthBuffers:["handleDepthBuffersChanged"],phantom:["handlePhantomChanged"],noDefaultLights:["handleNoDefaultLightsChanged"],experimentalRenderingOptions:["handleExperimentalRenderingOptionsChanged"],enableTemporalRefinement:["handleEnableTemporalRefinementChanged"],featureLines:["handleFeatureLinesChanged"],selectionHighlighting:["handleSelectionHighlightingChanged"],featureHighlighting:["handleFeatureHighlightingChanged"],featureMaps:["handleFeatureMapsChanged"],config:["handleConfigChanged"],configEnv:["handleConfigEnvChanged"]}}};function Si(t,i){const n=i();if(n!=null){return n}else throw new Error(t)}Ii.style=Ti;export{Ii as vertex_viewer};
5
+ //# sourceMappingURL=p-8a56c008.entry.js.map