@vertexvis/viewer 0.16.0 → 0.16.1-canary.1
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/README.template.md +19 -0
- package/dist/cjs/controller-383147c5.js +111 -0
- package/dist/cjs/controller-917f9ebf.js +7508 -0
- package/dist/cjs/dom-d162f898.js +14 -0
- package/dist/cjs/{entities-053d1e65.js → entities-98b08d8a.js} +5 -5
- package/dist/cjs/index.cjs.js +10 -3
- package/dist/cjs/{mapper-767b5f6d.js → mapper-d3855fc8.js} +583 -583
- package/dist/cjs/{dom-92728e58.js → row-3a1861d4.js} +0 -9
- package/dist/cjs/vertex-scene-tree-search_3.cjs.entry.js +5 -4
- package/dist/cjs/vertex-scene-tree.cjs.entry.js +19 -7510
- package/dist/cjs/vertex-viewer-box-query-tool.cjs.entry.js +9 -110
- package/dist/cjs/vertex-viewer-measurement-distance.cjs.entry.js +2 -2
- package/dist/cjs/vertex-viewer-measurement-line_2.cjs.entry.js +2 -2
- package/dist/cjs/vertex-viewer-measurement-precise.cjs.entry.js +4 -4
- package/dist/cjs/vertex-viewer-pin-group.cjs.entry.js +6 -3
- package/dist/collection/collection-manifest.json +4 -4
- package/dist/collection/components/scene-tree/lib/index.js +3 -0
- package/dist/collection/components/scene-tree/scene-tree.js +30 -17
- package/dist/collection/components/scene-tree/types.js +2 -0
- package/dist/collection/components/scene-tree-table-layout/scene-tree-table-layout.js +1 -1
- package/dist/collection/components/viewer-box-query-tool/types.js +2 -0
- package/dist/collection/components/viewer-box-query-tool/viewer-box-query-tool.js +5 -3
- package/dist/collection/components/viewer-default-toolbar/viewer-default-toolbar.js +2 -2
- package/dist/collection/components/viewer-toolbar/types.js +2 -0
- package/dist/collection/components/viewer-toolbar/viewer-toolbar.js +5 -3
- package/dist/collection/components/viewer-toolbar-group/types.js +2 -0
- package/dist/collection/components/viewer-toolbar-group/viewer-toolbar-group.js +3 -2
- package/dist/collection/index.js +8 -1
- package/dist/collection/lib/pins/index.js +2 -0
- package/dist/collection/lib/volume-intersection/index.js +2 -0
- package/dist/custom-elements/index.js +71942 -71942
- package/dist/esm/{bundle.esm-b51ea7fc.js → bundle.esm-c0b261c8.js} +1 -1
- package/dist/esm/{config-def96227.js → config-5a3235d2.js} +1 -1
- package/dist/esm/controller-37e0b32a.js +109 -0
- package/dist/esm/controller-8e9e0b43.js +7503 -0
- package/dist/esm/dom-2111ed19.js +11 -0
- package/dist/esm/{entities-3ff1a7ee.js → entities-f0128903.js} +3 -3
- package/dist/esm/index.js +9 -6
- package/dist/esm/index.mjs +9 -6
- package/dist/esm/{mapper-b2f3424f.js → mapper-36404f5d.js} +2 -2
- package/dist/esm/{dom-e19ee80b.js → row-5ebb8f09.js} +1 -8
- package/dist/esm/{scene-ed248e56.js → scene-d23dff71.js} +2 -2
- package/dist/esm/{streamAttributes-90bcdb58.js → streamAttributes-7bd73748.js} +1 -1
- package/dist/esm/vertex-scene-tree-search_3.entry.js +2 -1
- package/dist/esm/vertex-scene-tree.entry.js +13 -7504
- package/dist/esm/vertex-viewer-box-query-tool.entry.js +3 -104
- package/dist/esm/vertex-viewer-dom-element_2.entry.js +2 -2
- package/dist/esm/vertex-viewer-measurement-details.entry.js +2 -2
- package/dist/esm/vertex-viewer-measurement-distance.entry.js +4 -4
- package/dist/esm/vertex-viewer-measurement-line_2.entry.js +4 -4
- package/dist/esm/vertex-viewer-measurement-precise.entry.js +6 -6
- package/dist/esm/vertex-viewer-pin-group.entry.js +8 -5
- package/dist/esm/vertex-viewer-transform-widget.entry.js +2 -2
- package/dist/esm/vertex-viewer-view-cube.entry.js +2 -2
- package/dist/esm/vertex-viewer.entry.js +4 -4
- package/dist/esm/{grpc-web-client.umd-5409853c.js → wrappers_pb-e7a5f842.js} +5 -5
- package/dist/types/components/scene-tree/lib/controller.d.ts +1 -1
- package/dist/types/components/scene-tree/lib/index.d.ts +2 -0
- package/dist/types/components/scene-tree/lib/row.d.ts +1 -1
- package/dist/types/components/scene-tree/scene-tree.d.ts +1 -31
- package/dist/types/components/scene-tree/types.d.ts +32 -0
- package/dist/types/components/scene-tree-table-layout/scene-tree-table-layout.d.ts +1 -1
- package/dist/types/components/viewer-box-query-tool/types.d.ts +2 -0
- package/dist/types/components/viewer-box-query-tool/viewer-box-query-tool.d.ts +1 -2
- package/dist/types/components/viewer-default-toolbar/viewer-default-toolbar.d.ts +2 -2
- package/dist/types/components/viewer-toolbar/types.d.ts +5 -0
- package/dist/types/components/viewer-toolbar/viewer-toolbar.d.ts +1 -5
- package/dist/types/components/viewer-toolbar-group/types.d.ts +1 -0
- package/dist/types/components/viewer-toolbar-group/viewer-toolbar-group.d.ts +1 -1
- package/dist/types/components.d.ts +6 -10
- package/dist/types/index.d.ts +7 -0
- package/dist/types/lib/pins/index.d.ts +2 -0
- package/dist/types/lib/volume-intersection/index.d.ts +1 -0
- package/dist/types/lib/volume-intersection/model.d.ts +1 -1
- package/dist/viewer/index.esm.js +1 -1
- package/dist/viewer/{p-9f805c70.js → p-2c07b773.js} +1 -1
- package/dist/viewer/p-39535bb0.entry.js +4 -0
- package/dist/viewer/p-3a6fa239.js +4 -0
- package/dist/viewer/{p-e24dbb45.entry.js → p-42acbbaf.entry.js} +1 -1
- package/dist/viewer/p-43f7a708.entry.js +4 -0
- package/dist/viewer/{p-bd314501.js → p-5632192b.js} +1 -1
- package/dist/viewer/{p-01012fee.entry.js → p-58b30f31.entry.js} +1 -1
- package/dist/viewer/{p-f6b6b3d5.entry.js → p-6a4d8fb9.entry.js} +1 -1
- package/dist/viewer/p-6f47fcb9.js +4 -0
- package/dist/viewer/p-76c414a4.js +4 -0
- package/dist/viewer/{p-b283a36b.js → p-787c2987.js} +1 -1
- package/dist/viewer/{p-46f40a43.js → p-817743a4.js} +1 -1
- package/dist/viewer/{p-13e6c657.entry.js → p-886fb3a9.entry.js} +2 -2
- package/dist/viewer/{p-b629cebb.entry.js → p-92a65d2c.entry.js} +1 -1
- package/dist/viewer/p-9cc361f6.entry.js +4 -0
- package/dist/viewer/{p-934cbb97.js → p-a7c29e95.js} +1 -1
- package/dist/viewer/{p-47c4b430.entry.js → p-b4321377.entry.js} +1 -1
- package/dist/viewer/p-bfae3945.js +4 -0
- package/dist/viewer/{p-86759ae2.entry.js → p-d8c578a9.entry.js} +1 -1
- package/dist/viewer/{p-ea183d6e.entry.js → p-db8948a9.entry.js} +1 -1
- package/dist/viewer/{p-a12791aa.js → p-dde5650a.js} +1 -1
- package/dist/viewer/{p-bf688622.entry.js → p-ecd99a3e.entry.js} +1 -1
- package/dist/viewer/p-f5aaf680.js +4 -0
- package/dist/viewer/viewer.esm.js +1 -1
- package/package.json +7 -7
- package/readme.md +19 -0
- package/dist/collection/components/scene-tree/interfaces.js +0 -2
- package/dist/types/components/scene-tree/interfaces.d.ts +0 -1
- package/dist/viewer/p-3296fdf1.entry.js +0 -4
- package/dist/viewer/p-569ed94a.entry.js +0 -4
- package/dist/viewer/p-7ef7d9ce.entry.js +0 -4
- package/dist/viewer/p-92fe4417.js +0 -4
- package/dist/viewer/p-c8c4343b.js +0 -4
- package/dist/cjs/{grpc-web-client.umd-2af20c1b.js → wrappers_pb-04573f90.js} +4 -4
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
/**!
|
|
2
2
|
* Copyright (c) 2023 Vertex Software LLC. All rights reserved.
|
|
3
3
|
*/
|
|
4
|
-
import{h as e,F as i,r as t,H as o}from"./p-d6fce4c1.js";import{v as r,q as a,u as n}from"./p-d216a866.js";import{r as c}from"./p-b74242dc.js";import{O as s,e as d,S as l}from"./p-46f40a43.js";import"./p-df8fbe56.js";import{c as h}from"./p-07aeee89.js";import"./p-934cbb97.js";import"./p-fc7d8c03.js";import"./p-dfe5a97d.js";const b={front:{direction:r.back(),quaternion:a.create()},back:{direction:r.forward(),quaternion:a.fromAxisAngle(r.up(),Math.PI)},left:{direction:r.left(),quaternion:a.fromAxisAngle(r.down(),Math.PI/2)},right:{direction:r.right(),quaternion:a.fromAxisAngle(r.up(),Math.PI/2)},top:{direction:r.up(),quaternion:a.fromAxisAngle(r.right(),-Math.PI/2)},bottom:{direction:r.down(),quaternion:a.fromAxisAngle(r.left(),-Math.PI/2)}},f=({label:t,length:o,rotationAxis:c})=>{const s={width:`${o+5}px`},d=a.fromAxisAngle(c,Math.PI/2),l=r.scale(o+15,r.right());return e(i,null,e("vertex-viewer-dom-group",{quaternion:d},e("vertex-viewer-dom-element",{style:s,billboardOff:!0,interactionsOff:!0},e("div",{class:`triad-axis triad-axis-${t.toLowerCase()}`})),e("vertex-viewer-dom-element",{rotation:n.create({x:Math.PI/2,y:0,z:0}),style:s,billboardOff:!0,interactionsOff:!0},e("div",{class:`triad-axis triad-axis-${t.toLowerCase()}`})),e("vertex-viewer-dom-element",{position:l,interactionsOff:!0},e("div",{class:`triad-label triad-label-${t.toLowerCase()}`},t))))},g=({label:i,length:t,side:o,disabled:a,onPointerDown:n})=>{const{direction:c,quaternion:s}=b[o],d=r.scale(t/2-.1,c);return e("vertex-viewer-dom-element",{class:h("cube-side",{disabled:a}),position:d,quaternion:s,style:{width:`${t}px`,height:`${t}px`},onPointerDown:n,billboardOff:!0},e("div",{class:`cube-side-face cube-side-face-${i.toLowerCase()}`},i))},v=({length:i,face1Side:t,face1Corner:o,face2Side:a,face2Corner:n,face3Side:c,face3Corner:s,disabled:d,onPointerDown:l})=>{const{direction:f,quaternion:g}=b[t],{direction:v,quaternion:u}=b[a],{direction:w,quaternion:p}=b[c],m=r.scale(i/2,f),x=r.scale(i/2,v),S=r.scale(i/2,w),y={width:`${i}px`,height:`${i}px`};return e("vertex-viewer-dom-group",{class:h("cube-corner",{disabled:d}),onPointerDown:l},e("vertex-viewer-dom-element",{position:m,quaternion:g,style:y,billboardOff:!0},e("div",{class:`cube-corner-face ${o}`})),e("vertex-viewer-dom-element",{position:x,quaternion:u,style:y,billboardOff:!0},e("div",{class:`cube-corner-face ${n}`})),e("vertex-viewer-dom-element",{position:S,quaternion:p,style:y,billboardOff:!0},e("div",{class:`cube-corner-face ${s}`})))},u=({length:i,face1Side:t,face2Side:o,face1Edge:a,face2Edge:n,disabled:c,onPointerDown:s})=>{const{direction:d,quaternion:l}=b[t],{direction:f,quaternion:g}=b[o],v=r.scale(i/2,d),u=r.scale(i/2,f),w={width:`${i}px`,height:`${i}px`};return e("vertex-viewer-dom-group",{class:h("cube-edge",{disabled:c}),onPointerDown:s},e("vertex-viewer-dom-element",{position:v,quaternion:l,style:w,billboardOff:!0},e("div",{class:`cube-edge-face ${a}`})),e("vertex-viewer-dom-element",{position:u,quaternion:g,style:w,billboardOff:!0},e("div",{class:`cube-edge-face ${n}`})))},w=({length:i})=>{const{direction:t,quaternion:o}=b.top,a=r.scale(-i/2,t);return e("vertex-viewer-dom-element",{class:"cube-shadow",position:a,quaternion:o,style:{width:`${i}px`,height:`${i}px`},billboardOff:!0,interactionsOff:!0},e("div",{class:"cube-shadow-face"}))},p=class{constructor(e){t(this,e),this.boxLength=80,this.triadPosition=r.origin(),this.xPositiveLabel="Right",this.xNegativeLabel="Left",this.yPositiveLabel="Top",this.yNegativeLabel="Bottom",this.zPositiveLabel="Front",this.zNegativeLabel="Back",this.standardViewsOff=!1,this.animationDuration=500,this.triadOff=!1,this.worldOrientation=s.DEFAULT,this.updateMatrices=()=>{var e;if(null!=(null===(e=this.viewer)||void 0===e?void 0:e.frame)){const{camera:e}=this.viewer.frame.scene,i=this.boxLength/2;this.triadPosition=r.create(-i-5,-i-5,-i-5);const t=21.5;this.camera=new d(r.scale(3.125*this.boxLength,r.negate(e.direction)),r.origin(),e.up,.1,100,1,t),this.worldOrientation=this.viewer.frame.scene.worldOrientation}}}handleViewerChanged(e,i){null==i||i.removeEventListener("frameDrawn",this.updateMatrices),null==e||e.addEventListener("frameDrawn",this.updateMatrices),this.updateMatrices()}handleStandardView(e){return this.standardViewsOff?async()=>{}:async()=>{if(null!=this.viewer){const i=await this.viewer.scene(),t=this.animationDuration>0?{animation:{milliseconds:this.animationDuration}}:{},o=e.transformMatrix(this.worldOrientation.matrix);i.camera().standardView(o).viewAll().render(t)}}}componentWillLoad(){this.handleViewerChanged(this.viewer)}componentDidLoad(){null!=this.rendererEl&&(new ResizeObserver((()=>this.handleRendererResized())).observe(this.rendererEl),this.handleRendererResized())}handleRendererResized(){c((()=>{if(null!=this.rendererEl){const e=this.rendererEl.getBoundingClientRect();this.boxLength=Math.min(e.width,e.height)}}))}render(){return e(o,null,e("vertex-viewer-dom-renderer",{ref:e=>this.rendererEl=e,class:"renderer",camera:this.camera},!this.triadOff&&e("vertex-viewer-dom-group",{class:"triad",position:this.triadPosition},e(f,{label:"X",length:this.boxLength,rotationAxis:r.origin()}),e(f,{label:"Y",length:this.boxLength,rotationAxis:r.back()}),e(f,{label:"Z",length:this.boxLength,rotationAxis:r.down()})),e("vertex-viewer-dom-group",{class:"cube",matrix:this.worldOrientation.matrix},e(w,{length:this.boxLength+10}),e(g,{label:this.zPositiveLabel,length:this.boxLength,side:"front",onPointerDown:this.handleStandardView(l.FRONT),disabled:this.standardViewsOff}),e(g,{label:this.zNegativeLabel,length:this.boxLength,side:"back",onPointerDown:this.handleStandardView(l.BACK),disabled:this.standardViewsOff}),e(g,{label:this.xNegativeLabel,length:this.boxLength,side:"left",onPointerDown:this.handleStandardView(l.RIGHT),disabled:this.standardViewsOff}),e(g,{label:this.xPositiveLabel,length:this.boxLength,side:"right",onPointerDown:this.handleStandardView(l.LEFT),disabled:this.standardViewsOff}),e(g,{label:this.yPositiveLabel,length:this.boxLength,side:"top",onPointerDown:this.handleStandardView(l.TOP),disabled:this.standardViewsOff}),e(g,{label:this.yNegativeLabel,length:this.boxLength,side:"bottom",onPointerDown:this.handleStandardView(l.BOTTOM),disabled:this.standardViewsOff}),e(u,{length:this.boxLength,face1Side:"top",face1Edge:"bottom",face2Side:"front",face2Edge:"top",onPointerDown:this.handleStandardView(l.TOP_FRONT),disabled:this.standardViewsOff}),e(u,{length:this.boxLength,face1Side:"front",face1Edge:"right",face2Side:"right",face2Edge:"left",onPointerDown:this.handleStandardView(l.FRONT_LEFT),disabled:this.standardViewsOff}),e(u,{length:this.boxLength,face1Side:"bottom",face1Edge:"top",face2Side:"front",face2Edge:"bottom",onPointerDown:this.handleStandardView(l.BOTTOM_FRONT),disabled:this.standardViewsOff}),e(u,{length:this.boxLength,face1Side:"front",face1Edge:"left",face2Side:"left",face2Edge:"right",onPointerDown:this.handleStandardView(l.FRONT_RIGHT),disabled:this.standardViewsOff}),e(u,{length:this.boxLength,face1Side:"top",face1Edge:"right",face2Side:"right",face2Edge:"top",onPointerDown:this.handleStandardView(l.TOP_LEFT),disabled:this.standardViewsOff}),e(u,{length:this.boxLength,face1Side:"back",face1Edge:"left",face2Side:"right",face2Edge:"right",onPointerDown:this.handleStandardView(l.BACK_LEFT),disabled:this.standardViewsOff}),e(u,{length:this.boxLength,face1Side:"bottom",face1Edge:"right",face2Side:"right",face2Edge:"bottom",onPointerDown:this.handleStandardView(l.BOTTOM_LEFT),disabled:this.standardViewsOff}),e(u,{length:this.boxLength,face1Side:"top",face1Edge:"top",face2Side:"back",face2Edge:"top",onPointerDown:this.handleStandardView(l.TOP_BACK),disabled:this.standardViewsOff}),e(u,{length:this.boxLength,face1Side:"back",face1Edge:"right",face2Side:"left",face2Edge:"left",onPointerDown:this.handleStandardView(l.BACK_RIGHT),disabled:this.standardViewsOff}),e(u,{length:this.boxLength,face1Side:"bottom",face1Edge:"bottom",face2Side:"back",face2Edge:"bottom",onPointerDown:this.handleStandardView(l.BOTTOM_BACK),disabled:this.standardViewsOff}),e(u,{length:this.boxLength,face1Side:"top",face1Edge:"left",face2Side:"left",face2Edge:"top",onPointerDown:this.handleStandardView(l.TOP_RIGHT),disabled:this.standardViewsOff}),e(u,{length:this.boxLength,face1Side:"bottom",face1Edge:"left",face2Side:"left",face2Edge:"bottom",onPointerDown:this.handleStandardView(l.BOTTOM_RIGHT),disabled:this.standardViewsOff}),e(v,{length:this.boxLength,face1Side:"top",face1Corner:"bottom-left",face2Side:"front",face2Corner:"top-left",face3Side:"left",face3Corner:"top-right",onPointerDown:this.handleStandardView(l.TOP_FRONT_RIGHT),disabled:this.standardViewsOff}),e(v,{length:this.boxLength,face1Side:"top",face1Corner:"bottom-right",face2Side:"front",face2Corner:"top-right",face3Side:"right",face3Corner:"top-left",onPointerDown:this.handleStandardView(l.TOP_FRONT_LEFT),disabled:this.standardViewsOff}),e(v,{length:this.boxLength,face1Side:"bottom",face1Corner:"top-right",face2Side:"front",face2Corner:"bottom-right",face3Side:"right",face3Corner:"bottom-left",onPointerDown:this.handleStandardView(l.BOTTOM_FRONT_LEFT),disabled:this.standardViewsOff}),e(v,{length:this.boxLength,face1Side:"bottom",face1Corner:"top-left",face2Side:"front",face2Corner:"bottom-left",face3Side:"left",face3Corner:"bottom-right",onPointerDown:this.handleStandardView(l.BOTTOM_FRONT_RIGHT),disabled:this.standardViewsOff}),e(v,{length:this.boxLength,face1Side:"top",face1Corner:"top-right",face2Side:"back",face2Corner:"top-left",face3Side:"right",face3Corner:"top-right",onPointerDown:this.handleStandardView(l.TOP_BACK_LEFT),disabled:this.standardViewsOff}),e(v,{length:this.boxLength,face1Side:"top",face1Corner:"top-left",face2Side:"back",face2Corner:"top-right",face3Side:"left",face3Corner:"top-left",onPointerDown:this.handleStandardView(l.TOP_BACK_RIGHT),disabled:this.standardViewsOff}),e(v,{length:this.boxLength,face1Side:"bottom",face1Corner:"bottom-left",face2Side:"back",face2Corner:"bottom-right",face3Side:"left",face3Corner:"bottom-left",onPointerDown:this.handleStandardView(l.BOTTOM_BACK_RIGHT),disabled:this.standardViewsOff}),e(v,{length:this.boxLength,face1Side:"bottom",face1Corner:"bottom-right",face2Side:"back",face2Corner:"bottom-left",face3Side:"right",face3Corner:"bottom-right",onPointerDown:this.handleStandardView(l.BOTTOM_BACK_LEFT),disabled:this.standardViewsOff}))))}static get watchers(){return{viewer:["handleViewerChanged"]}}};p.style=":host{--viewer-view-cube-side-background:var(--white);--viewer-view-cube-side-background-hover:var(--blue-500);--viewer-view-cube-side-background-hover-opacity:0.25;--viewer-view-cube-side-border:1.5px solid var(--neutral-500);--viewer-view-cube-edge-length:12px;--viewer-view-cube-opacity:0.8;--viewer-view-cube-triad-x-axis-color:var(--x-axis-color);--viewer-view-cube-triad-y-axis-color:var(--y-axis-color);--viewer-view-cube-triad-z-axis-color:var(--z-axis-color);color:var(--neutral-700);width:80px;height:80px;margin:20px;position:relative;display:flex;align-items:center;justify-content:center;user-select:none}.renderer{position:unset;width:100%;height:100%;overflow:visible}.reference-point{width:5px;height:5px;border-radius:50%;background-color:black}.triad{pointer-events:none}.triad-axis{width:100%;height:1.5px;outline:1px solid transparent;transform:translateX(50%)}.triad-axis-x{background-color:#ea3324}.triad-axis-y{background-color:#4faf32}.triad-axis-z{background-color:#0000ff}.triad-label{font-family:Arial, Helvetica, sans-serif;font-size:0.6875rem}.triad-label-x{color:var(--viewer-view-cube-triad-x-axis-color)}.triad-label-y{color:var(--viewer-view-cube-triad-y-axis-color)}.triad-label-z{color:var(--viewer-view-cube-triad-z-axis-color)}.cube{pointer-events:initial}.cube:hover .cube-side-face{opacity:1}.cube-side{backface-visibility:hidden;-webkit-backface-visibility:hidden}.cube-side-face{box-sizing:border-box;font-size:0.875rem;text-transform:uppercase;width:100%;height:100%;background-color:var(--viewer-view-cube-side-background);border:var(--viewer-view-cube-side-border);display:flex;align-items:center;justify-content:center;outline:1px solid transparent;opacity:var(--viewer-view-cube-opacity);transition:opacity 0.2s ease-in-out}.cube-side-face::before{content:'';position:absolute;left:calc(var(--viewer-view-cube-edge-length) - 4px);right:calc(var(--viewer-view-cube-edge-length) - 4px);top:calc(var(--viewer-view-cube-edge-length) - 4px);bottom:calc(var(--viewer-view-cube-edge-length) - 4px)}.cube-corner,.cube-edge{position:relative}.cube-corner-face,.cube-edge-face{position:absolute;backface-visibility:hidden;-webkit-backface-visibility:hidden}.cube-edge-face.top{top:0;left:var(--viewer-view-cube-edge-length);right:var(--viewer-view-cube-edge-length);height:var(--viewer-view-cube-edge-length)}.cube-edge-face.bottom{bottom:0;left:var(--viewer-view-cube-edge-length);right:var(--viewer-view-cube-edge-length);height:var(--viewer-view-cube-edge-length)}.cube-edge-face.left{left:0;top:var(--viewer-view-cube-edge-length);bottom:var(--viewer-view-cube-edge-length);width:var(--viewer-view-cube-edge-length)}.cube-edge-face.right{right:0;top:var(--viewer-view-cube-edge-length);bottom:var(--viewer-view-cube-edge-length);width:var(--viewer-view-cube-edge-length)}.cube-corner-face{width:var(--viewer-view-cube-edge-length);height:var(--viewer-view-cube-edge-length)}.cube-corner-face.top-left{top:0;left:0}.cube-corner-face.top-right{top:0;right:0}.cube-corner-face.bottom-right{bottom:0;right:0}.cube-corner-face.bottom-left{bottom:0;left:0}.cube-shadow{backface-visibility:hidden;-webkit-backface-visibility:hidden}.cube-shadow-face{position:absolute;left:4px;right:4px;top:4px;bottom:4px;background-color:black;opacity:0.12;filter:blur(4px)}.cube-corner .cube-corner-face,.cube-edge .cube-edge-face,.cube-side .cube-side-face::before{background:var(--viewer-view-cube-side-background-hover);opacity:0}.cube-corner:hover .cube-corner-face,.cube-edge:hover .cube-edge-face,.cube-side:hover .cube-side-face::before{opacity:var(--viewer-view-cube-side-background-hover-opacity)}.cube-corner.disabled,.cube-edge.disabled,.cube-side.disabled{pointer-events:none}";export{p as vertex_viewer_view_cube}
|
|
4
|
+
import{h as e,F as i,r as t,H as o}from"./p-d6fce4c1.js";import{v as r,q as a,u as n}from"./p-d216a866.js";import{r as c}from"./p-b74242dc.js";import{O as s,e as d,S as l}from"./p-817743a4.js";import"./p-df8fbe56.js";import{c as h}from"./p-07aeee89.js";import"./p-a7c29e95.js";import"./p-fc7d8c03.js";import"./p-dfe5a97d.js";const f={front:{direction:r.back(),quaternion:a.create()},back:{direction:r.forward(),quaternion:a.fromAxisAngle(r.up(),Math.PI)},left:{direction:r.left(),quaternion:a.fromAxisAngle(r.down(),Math.PI/2)},right:{direction:r.right(),quaternion:a.fromAxisAngle(r.up(),Math.PI/2)},top:{direction:r.up(),quaternion:a.fromAxisAngle(r.right(),-Math.PI/2)},bottom:{direction:r.down(),quaternion:a.fromAxisAngle(r.left(),-Math.PI/2)}},b=({label:t,length:o,rotationAxis:c})=>{const s={width:`${o+5}px`},d=a.fromAxisAngle(c,Math.PI/2),l=r.scale(o+15,r.right());return e(i,null,e("vertex-viewer-dom-group",{quaternion:d},e("vertex-viewer-dom-element",{style:s,billboardOff:!0,interactionsOff:!0},e("div",{class:`triad-axis triad-axis-${t.toLowerCase()}`})),e("vertex-viewer-dom-element",{rotation:n.create({x:Math.PI/2,y:0,z:0}),style:s,billboardOff:!0,interactionsOff:!0},e("div",{class:`triad-axis triad-axis-${t.toLowerCase()}`})),e("vertex-viewer-dom-element",{position:l,interactionsOff:!0},e("div",{class:`triad-label triad-label-${t.toLowerCase()}`},t))))},g=({label:i,length:t,side:o,disabled:a,onPointerDown:n})=>{const{direction:c,quaternion:s}=f[o],d=r.scale(t/2-.1,c);return e("vertex-viewer-dom-element",{class:h("cube-side",{disabled:a}),position:d,quaternion:s,style:{width:`${t}px`,height:`${t}px`},onPointerDown:n,billboardOff:!0},e("div",{class:`cube-side-face cube-side-face-${i.toLowerCase()}`},i))},v=({length:i,face1Side:t,face1Corner:o,face2Side:a,face2Corner:n,face3Side:c,face3Corner:s,disabled:d,onPointerDown:l})=>{const{direction:b,quaternion:g}=f[t],{direction:v,quaternion:u}=f[a],{direction:w,quaternion:p}=f[c],m=r.scale(i/2,b),x=r.scale(i/2,v),S=r.scale(i/2,w),y={width:`${i}px`,height:`${i}px`};return e("vertex-viewer-dom-group",{class:h("cube-corner",{disabled:d}),onPointerDown:l},e("vertex-viewer-dom-element",{position:m,quaternion:g,style:y,billboardOff:!0},e("div",{class:`cube-corner-face ${o}`})),e("vertex-viewer-dom-element",{position:x,quaternion:u,style:y,billboardOff:!0},e("div",{class:`cube-corner-face ${n}`})),e("vertex-viewer-dom-element",{position:S,quaternion:p,style:y,billboardOff:!0},e("div",{class:`cube-corner-face ${s}`})))},u=({length:i,face1Side:t,face2Side:o,face1Edge:a,face2Edge:n,disabled:c,onPointerDown:s})=>{const{direction:d,quaternion:l}=f[t],{direction:b,quaternion:g}=f[o],v=r.scale(i/2,d),u=r.scale(i/2,b),w={width:`${i}px`,height:`${i}px`};return e("vertex-viewer-dom-group",{class:h("cube-edge",{disabled:c}),onPointerDown:s},e("vertex-viewer-dom-element",{position:v,quaternion:l,style:w,billboardOff:!0},e("div",{class:`cube-edge-face ${a}`})),e("vertex-viewer-dom-element",{position:u,quaternion:g,style:w,billboardOff:!0},e("div",{class:`cube-edge-face ${n}`})))},w=({length:i})=>{const{direction:t,quaternion:o}=f.top,a=r.scale(-i/2,t);return e("vertex-viewer-dom-element",{class:"cube-shadow",position:a,quaternion:o,style:{width:`${i}px`,height:`${i}px`},billboardOff:!0,interactionsOff:!0},e("div",{class:"cube-shadow-face"}))},p=class{constructor(e){t(this,e),this.boxLength=80,this.triadPosition=r.origin(),this.xPositiveLabel="Right",this.xNegativeLabel="Left",this.yPositiveLabel="Top",this.yNegativeLabel="Bottom",this.zPositiveLabel="Front",this.zNegativeLabel="Back",this.standardViewsOff=!1,this.animationDuration=500,this.triadOff=!1,this.worldOrientation=s.DEFAULT,this.updateMatrices=()=>{var e;if(null!=(null===(e=this.viewer)||void 0===e?void 0:e.frame)){const{camera:e}=this.viewer.frame.scene,i=this.boxLength/2;this.triadPosition=r.create(-i-5,-i-5,-i-5);const t=21.5;this.camera=new d(r.scale(3.125*this.boxLength,r.negate(e.direction)),r.origin(),e.up,.1,100,1,t),this.worldOrientation=this.viewer.frame.scene.worldOrientation}}}handleViewerChanged(e,i){null==i||i.removeEventListener("frameDrawn",this.updateMatrices),null==e||e.addEventListener("frameDrawn",this.updateMatrices),this.updateMatrices()}handleStandardView(e){return this.standardViewsOff?async()=>{}:async()=>{if(null!=this.viewer){const i=await this.viewer.scene(),t=this.animationDuration>0?{animation:{milliseconds:this.animationDuration}}:{},o=e.transformMatrix(this.worldOrientation.matrix);i.camera().standardView(o).viewAll().render(t)}}}componentWillLoad(){this.handleViewerChanged(this.viewer)}componentDidLoad(){null!=this.rendererEl&&(new ResizeObserver((()=>this.handleRendererResized())).observe(this.rendererEl),this.handleRendererResized())}handleRendererResized(){c((()=>{if(null!=this.rendererEl){const e=this.rendererEl.getBoundingClientRect();this.boxLength=Math.min(e.width,e.height)}}))}render(){return e(o,null,e("vertex-viewer-dom-renderer",{ref:e=>this.rendererEl=e,class:"renderer",camera:this.camera},!this.triadOff&&e("vertex-viewer-dom-group",{class:"triad",position:this.triadPosition},e(b,{label:"X",length:this.boxLength,rotationAxis:r.origin()}),e(b,{label:"Y",length:this.boxLength,rotationAxis:r.back()}),e(b,{label:"Z",length:this.boxLength,rotationAxis:r.down()})),e("vertex-viewer-dom-group",{class:"cube",matrix:this.worldOrientation.matrix},e(w,{length:this.boxLength+10}),e(g,{label:this.zPositiveLabel,length:this.boxLength,side:"front",onPointerDown:this.handleStandardView(l.FRONT),disabled:this.standardViewsOff}),e(g,{label:this.zNegativeLabel,length:this.boxLength,side:"back",onPointerDown:this.handleStandardView(l.BACK),disabled:this.standardViewsOff}),e(g,{label:this.xNegativeLabel,length:this.boxLength,side:"left",onPointerDown:this.handleStandardView(l.RIGHT),disabled:this.standardViewsOff}),e(g,{label:this.xPositiveLabel,length:this.boxLength,side:"right",onPointerDown:this.handleStandardView(l.LEFT),disabled:this.standardViewsOff}),e(g,{label:this.yPositiveLabel,length:this.boxLength,side:"top",onPointerDown:this.handleStandardView(l.TOP),disabled:this.standardViewsOff}),e(g,{label:this.yNegativeLabel,length:this.boxLength,side:"bottom",onPointerDown:this.handleStandardView(l.BOTTOM),disabled:this.standardViewsOff}),e(u,{length:this.boxLength,face1Side:"top",face1Edge:"bottom",face2Side:"front",face2Edge:"top",onPointerDown:this.handleStandardView(l.TOP_FRONT),disabled:this.standardViewsOff}),e(u,{length:this.boxLength,face1Side:"front",face1Edge:"right",face2Side:"right",face2Edge:"left",onPointerDown:this.handleStandardView(l.FRONT_LEFT),disabled:this.standardViewsOff}),e(u,{length:this.boxLength,face1Side:"bottom",face1Edge:"top",face2Side:"front",face2Edge:"bottom",onPointerDown:this.handleStandardView(l.BOTTOM_FRONT),disabled:this.standardViewsOff}),e(u,{length:this.boxLength,face1Side:"front",face1Edge:"left",face2Side:"left",face2Edge:"right",onPointerDown:this.handleStandardView(l.FRONT_RIGHT),disabled:this.standardViewsOff}),e(u,{length:this.boxLength,face1Side:"top",face1Edge:"right",face2Side:"right",face2Edge:"top",onPointerDown:this.handleStandardView(l.TOP_LEFT),disabled:this.standardViewsOff}),e(u,{length:this.boxLength,face1Side:"back",face1Edge:"left",face2Side:"right",face2Edge:"right",onPointerDown:this.handleStandardView(l.BACK_LEFT),disabled:this.standardViewsOff}),e(u,{length:this.boxLength,face1Side:"bottom",face1Edge:"right",face2Side:"right",face2Edge:"bottom",onPointerDown:this.handleStandardView(l.BOTTOM_LEFT),disabled:this.standardViewsOff}),e(u,{length:this.boxLength,face1Side:"top",face1Edge:"top",face2Side:"back",face2Edge:"top",onPointerDown:this.handleStandardView(l.TOP_BACK),disabled:this.standardViewsOff}),e(u,{length:this.boxLength,face1Side:"back",face1Edge:"right",face2Side:"left",face2Edge:"left",onPointerDown:this.handleStandardView(l.BACK_RIGHT),disabled:this.standardViewsOff}),e(u,{length:this.boxLength,face1Side:"bottom",face1Edge:"bottom",face2Side:"back",face2Edge:"bottom",onPointerDown:this.handleStandardView(l.BOTTOM_BACK),disabled:this.standardViewsOff}),e(u,{length:this.boxLength,face1Side:"top",face1Edge:"left",face2Side:"left",face2Edge:"top",onPointerDown:this.handleStandardView(l.TOP_RIGHT),disabled:this.standardViewsOff}),e(u,{length:this.boxLength,face1Side:"bottom",face1Edge:"left",face2Side:"left",face2Edge:"bottom",onPointerDown:this.handleStandardView(l.BOTTOM_RIGHT),disabled:this.standardViewsOff}),e(v,{length:this.boxLength,face1Side:"top",face1Corner:"bottom-left",face2Side:"front",face2Corner:"top-left",face3Side:"left",face3Corner:"top-right",onPointerDown:this.handleStandardView(l.TOP_FRONT_RIGHT),disabled:this.standardViewsOff}),e(v,{length:this.boxLength,face1Side:"top",face1Corner:"bottom-right",face2Side:"front",face2Corner:"top-right",face3Side:"right",face3Corner:"top-left",onPointerDown:this.handleStandardView(l.TOP_FRONT_LEFT),disabled:this.standardViewsOff}),e(v,{length:this.boxLength,face1Side:"bottom",face1Corner:"top-right",face2Side:"front",face2Corner:"bottom-right",face3Side:"right",face3Corner:"bottom-left",onPointerDown:this.handleStandardView(l.BOTTOM_FRONT_LEFT),disabled:this.standardViewsOff}),e(v,{length:this.boxLength,face1Side:"bottom",face1Corner:"top-left",face2Side:"front",face2Corner:"bottom-left",face3Side:"left",face3Corner:"bottom-right",onPointerDown:this.handleStandardView(l.BOTTOM_FRONT_RIGHT),disabled:this.standardViewsOff}),e(v,{length:this.boxLength,face1Side:"top",face1Corner:"top-right",face2Side:"back",face2Corner:"top-left",face3Side:"right",face3Corner:"top-right",onPointerDown:this.handleStandardView(l.TOP_BACK_LEFT),disabled:this.standardViewsOff}),e(v,{length:this.boxLength,face1Side:"top",face1Corner:"top-left",face2Side:"back",face2Corner:"top-right",face3Side:"left",face3Corner:"top-left",onPointerDown:this.handleStandardView(l.TOP_BACK_RIGHT),disabled:this.standardViewsOff}),e(v,{length:this.boxLength,face1Side:"bottom",face1Corner:"bottom-left",face2Side:"back",face2Corner:"bottom-right",face3Side:"left",face3Corner:"bottom-left",onPointerDown:this.handleStandardView(l.BOTTOM_BACK_RIGHT),disabled:this.standardViewsOff}),e(v,{length:this.boxLength,face1Side:"bottom",face1Corner:"bottom-right",face2Side:"back",face2Corner:"bottom-left",face3Side:"right",face3Corner:"bottom-right",onPointerDown:this.handleStandardView(l.BOTTOM_BACK_LEFT),disabled:this.standardViewsOff}))))}static get watchers(){return{viewer:["handleViewerChanged"]}}};p.style=":host{--viewer-view-cube-side-background:var(--white);--viewer-view-cube-side-background-hover:var(--blue-500);--viewer-view-cube-side-background-hover-opacity:0.25;--viewer-view-cube-side-border:1.5px solid var(--neutral-500);--viewer-view-cube-edge-length:12px;--viewer-view-cube-opacity:0.8;--viewer-view-cube-triad-x-axis-color:var(--x-axis-color);--viewer-view-cube-triad-y-axis-color:var(--y-axis-color);--viewer-view-cube-triad-z-axis-color:var(--z-axis-color);color:var(--neutral-700);width:80px;height:80px;margin:20px;position:relative;display:flex;align-items:center;justify-content:center;user-select:none}.renderer{position:unset;width:100%;height:100%;overflow:visible}.reference-point{width:5px;height:5px;border-radius:50%;background-color:black}.triad{pointer-events:none}.triad-axis{width:100%;height:1.5px;outline:1px solid transparent;transform:translateX(50%)}.triad-axis-x{background-color:#ea3324}.triad-axis-y{background-color:#4faf32}.triad-axis-z{background-color:#0000ff}.triad-label{font-family:Arial, Helvetica, sans-serif;font-size:0.6875rem}.triad-label-x{color:var(--viewer-view-cube-triad-x-axis-color)}.triad-label-y{color:var(--viewer-view-cube-triad-y-axis-color)}.triad-label-z{color:var(--viewer-view-cube-triad-z-axis-color)}.cube{pointer-events:initial}.cube:hover .cube-side-face{opacity:1}.cube-side{backface-visibility:hidden;-webkit-backface-visibility:hidden}.cube-side-face{box-sizing:border-box;font-size:0.875rem;text-transform:uppercase;width:100%;height:100%;background-color:var(--viewer-view-cube-side-background);border:var(--viewer-view-cube-side-border);display:flex;align-items:center;justify-content:center;outline:1px solid transparent;opacity:var(--viewer-view-cube-opacity);transition:opacity 0.2s ease-in-out}.cube-side-face::before{content:'';position:absolute;left:calc(var(--viewer-view-cube-edge-length) - 4px);right:calc(var(--viewer-view-cube-edge-length) - 4px);top:calc(var(--viewer-view-cube-edge-length) - 4px);bottom:calc(var(--viewer-view-cube-edge-length) - 4px)}.cube-corner,.cube-edge{position:relative}.cube-corner-face,.cube-edge-face{position:absolute;backface-visibility:hidden;-webkit-backface-visibility:hidden}.cube-edge-face.top{top:0;left:var(--viewer-view-cube-edge-length);right:var(--viewer-view-cube-edge-length);height:var(--viewer-view-cube-edge-length)}.cube-edge-face.bottom{bottom:0;left:var(--viewer-view-cube-edge-length);right:var(--viewer-view-cube-edge-length);height:var(--viewer-view-cube-edge-length)}.cube-edge-face.left{left:0;top:var(--viewer-view-cube-edge-length);bottom:var(--viewer-view-cube-edge-length);width:var(--viewer-view-cube-edge-length)}.cube-edge-face.right{right:0;top:var(--viewer-view-cube-edge-length);bottom:var(--viewer-view-cube-edge-length);width:var(--viewer-view-cube-edge-length)}.cube-corner-face{width:var(--viewer-view-cube-edge-length);height:var(--viewer-view-cube-edge-length)}.cube-corner-face.top-left{top:0;left:0}.cube-corner-face.top-right{top:0;right:0}.cube-corner-face.bottom-right{bottom:0;right:0}.cube-corner-face.bottom-left{bottom:0;left:0}.cube-shadow{backface-visibility:hidden;-webkit-backface-visibility:hidden}.cube-shadow-face{position:absolute;left:4px;right:4px;top:4px;bottom:4px;background-color:black;opacity:0.12;filter:blur(4px)}.cube-corner .cube-corner-face,.cube-edge .cube-edge-face,.cube-side .cube-side-face::before{background:var(--viewer-view-cube-side-background-hover);opacity:0}.cube-corner:hover .cube-corner-face,.cube-edge:hover .cube-edge-face,.cube-side:hover .cube-side-face::before{opacity:var(--viewer-view-cube-side-background-hover-opacity)}.cube-corner.disabled,.cube-edge.disabled,.cube-side.disabled{pointer-events:none}";export{p as vertex_viewer_view_cube}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
/**!
|
|
2
|
+
* Copyright (c) 2023 Vertex Software LLC. All rights reserved.
|
|
3
|
+
*/
|
|
4
|
+
import{h as t,F as e,r as i,c as n,f as s,H as o,g as r}from"./p-d6fce4c1.js";import{o as a}from"./p-d216a866.js";import{a as l,w as d,S as h,b as c,c as u}from"./p-6f47fcb9.js";import{p}from"./p-dde5650a.js";import{g as v}from"./p-76c414a4.js";import{i as w}from"./p-bfae3945.js";import"./p-3a6fa239.js";import"./p-dfe5a97d.js";import"./p-fc7d8c03.js";import"./p-440c8174.js";import"./p-817743a4.js";import"./p-a7c29e95.js";import"./p-df8fbe56.js";window.requestIdleCallback=window.requestIdleCallback||function(t){var e=Date.now();return setTimeout((function(){t({didTimeout:!1,timeRemaining:function(){return Math.max(0,50-(Date.now()-e))}})}),1)},window.cancelIdleCallback=window.cancelIdleCallback||function(t){clearTimeout(t)};const m=({details:i},n)=>t("div",{class:"error"},t("div",{class:"error-section error-message"},t("span",null,i.message),i.link&&t(e,null,t("span",null," See our "),t("a",{href:i.link,target:"_blank"},"documentation")," ",t("span",null," for more information."))),t("div",{class:"error-section"},n));async function f(t,e,{suppliedCorrelationId:i}={}){return(await t.scene()).items((t=>t.where((t=>t.withItemId(e))).show())).execute({suppliedCorrelationId:i})}async function y(t,e,{suppliedCorrelationId:i}={}){return(await t.scene()).items((t=>t.where((t=>t.withItemId(e))).hide())).execute({suppliedCorrelationId:i})}const b=class{constructor(t){i(this,t),this.connectionError=n(this,"connectionError",7),this.overScanCount=25,this.configEnv="platprod",this.metadataSearchExactMatch=!1,this.metadataSearchKeys=[],this.metadataKeys=[],this.rows=[],this.totalRows=0,this.showLoader=!1,this.stateMap={componentLoaded:!1},this.attemptingRetry=!1}async invalidateRows(){s(this.getLayoutElement())}async scrollToIndex(t,e={}){const{animate:i,position:n="middle"}=e,s=Math.max(0,Math.min(t,this.totalRows)),o=this.getScrollToPosition(s,n);this.getLayoutElement().scrollToPosition(o,{behavior:i?"smooth":void 0})}async scrollToItem(t,e={}){var i;const n=this.totalRows,s=await(null===(i=this.controller)||void 0===i?void 0:i.expandParentNodes(t));if(null!=s&&n!==this.totalRows)return new Promise((t=>{const i=this.getLayoutElement(),n=async()=>{i.removeEventListener("layoutRendered",n),await this.scrollToIndex(s,e),t()};i.addEventListener("layoutRendered",n)}));null!=s&&await this.scrollToIndex(s,e)}async expandAll(){var t;await(null===(t=this.controller)||void 0===t?void 0:t.expandAll())}async collapseAll(){var t;await(null===(t=this.controller)||void 0===t?void 0:t.collapseAll())}async expandItem(t){await this.performRowOperation(t,(async({id:t,node:e})=>{var i;e.expanded||await(null===(i=this.controller)||void 0===i?void 0:i.expandNode(t))}))}async collapseItem(t){await this.performRowOperation(t,(async({id:t,node:e})=>{var i;e.expanded&&await(null===(i=this.controller)||void 0===i?void 0:i.collapseNode(t))}))}async toggleExpandItem(t){await this.performRowOperation(t,(async({node:t})=>{t.expanded?await this.collapseItem(t):await this.expandItem(t)}))}async toggleItemVisibility(t){await this.performRowOperation(t,(async({viewer:t,id:e,node:i})=>{i.visible||i.partiallyVisible?await y(t,e):await f(t,e)}))}async hideItem(t){await this.performRowOperation(t,(async({viewer:t,id:e,node:i})=>{i.visible&&await y(t,e)}))}async showItem(t){await this.performRowOperation(t,(async({viewer:t,id:e,node:i})=>{i.visible||await f(t,e)}))}async selectItem(t,e={}){var{recurseParent:i}=e,n=a(e,["recurseParent"]);await this.performRowOperation(t,(async({viewer:t,id:e})=>{var s,o,r,a;const l=await(null===(s=this.controller)||void 0===s?void 0:s.fetchNodeAncestors(e))||[],d=null===(o=this.stateMap.selectionPath)||void 0===o?void 0:o.includes(e);if(i&&d){const t=l.find((({selected:t})=>!t));null!=t&&(await this.selectItem(t,n),this.lastSelectedItemId=e)}else if(n.range&&null!=this.lastSelectedItemId){const i=await(null===(r=this.controller)||void 0===r?void 0:r.expandParentNodes(e)),s=await(null===(a=this.controller)||void 0===a?void 0:a.expandParentNodes(this.lastSelectedItemId));if(s&&i){const e=Math.min(s,i),o=Math.max(s,i);await async function(t,e,i,{append:n=!0,suppliedCorrelationId:s}){return(await t.scene()).items((t=>[...n?[]:[t.where((t=>t.all())).deselect()],t.where((t=>t.withSceneTreeRange({start:e,end:i}))).select()])).execute({suppliedCorrelationId:s})}(t,e,o,n)}}else await async function(t,e,{append:i=!1,suppliedCorrelationId:n}){return(await t.scene()).items((t=>[...i?[]:[t.where((t=>t.all())).deselect()],t.where((t=>t.withItemId(e))).select()])).execute({suppliedCorrelationId:n})}(t,e,n),this.lastSelectedItemId=e;this.stateMap.selectionPath=[...l.map((({id:t})=>(null==t?void 0:t.hex)||"")),e]}))}async deselectItem(t){await this.performRowOperation(t,(async({viewer:t,id:e,node:i})=>{i.selected&&(this.lastSelectedItemId=void 0,await async function(t,e,{suppliedCorrelationId:i}={}){return(await t.scene()).items((t=>t.where((t=>t.withItemId(e))).deselect())).execute({suppliedCorrelationId:i})}(t,e))}))}async getRowAtIndex(t){return this.rows[t]}async getRowForEvent(t){const{clientY:e,target:i}=t;return null!=i&&null==this.errorDetails&&v(this.el,i)&&null!=(n=i)&&"VERTEX-SCENE-TREE-TABLE-CELL"===n.nodeName?this.getRowAtClientY(e):void 0;var n}getRowAtClientY(t){const e=this.getLayoutElement(),i=Math.floor((t-e.layoutOffset+e.scrollOffset)/e.rowHeight);return this.getRowAtIndex(i)}async filterItems(t,e={}){var i;return null===(i=this.controller)||void 0===i?void 0:i.filter(t,e)}async selectFilteredItems(t,e){if(null!=this.viewer){const i=this.metadataSearchKeys.length>0?this.metadataSearchKeys:this.metadataKeys;0===i.length&&console.warn("No metadata keys were found to perform the selection. Defaulting to ['VERTEX_SCENE_ITEM_NAME']");const n=i.length>0?i:["VERTEX_SCENE_ITEM_NAME"];await async function(t,e,i,n,{append:s=!1,suppliedCorrelationId:o}){return(await t.scene()).items((t=>[...s?[]:[t.where((t=>t.all())).deselect()],t.where((t=>t.withMetadata(e,i,n))).select()])).execute({suppliedCorrelationId:o})}(this.viewer,t,n,this.metadataSearchExactMatch,Object.assign({append:!1},e))}}async fetchMetadataKeys(){var t,e;return null!==(e=null===(t=this.controller)||void 0===t?void 0:t.fetchMetadataKeys())&&void 0!==e?e:[]}disconnectedCallback(){var t,e;null===(t=this.stateMap.viewerDisposable)||void 0===t||t.dispose(),null===(e=this.controller)||void 0===e||e.cancel()}componentWillLoad(){if(null==this.controller){const{sceneTreeHost:t}=this.getConfig().network,e=new l(t,this.getConfig().flags.grpcUseStreamingWebSocketTransport?{transport:d}:void 0);this.controller=new h(e,100)}this.stateMap.onStateChangeDisposable=this.controller.onStateChange.on((t=>this.handleControllerStateChange(t))),this.connectToViewer()}async componentDidLoad(){var t;this.ensureLayoutDefined(),this.updateLayoutElement();const e=this.getLayoutElement(),i=new ResizeObserver((()=>{this.invalidateRows()}));i.observe(e),this.stateMap.resizeObserver=i,this.stateMap.componentLoaded=!0,null===(t=this.controller)||void 0===t||t.setMetadataKeys(this.metadataKeys),null==this.viewer&&(this.errorDetails=new c("MISSING_VIEWER",u.MISSING_VIEWER))}componentWillRender(){this.updateLayoutElement()}render(){return t(o,null,t("div",{class:"header"},t("slot",{name:"header"},t("vertex-scene-tree-toolbar",{class:"search-toolbar"},t("vertex-scene-tree-search",{controller:this.controller})))),null!=this.errorDetails&&this.renderError(this.errorDetails),null==this.errorDetails&&t("div",{class:"rows-scroll"},this.showLoader&&t("slot",{name:"loading"},t("vertex-viewer-spinner",{class:"loading",size:"md"})),t("slot",null)),t("div",{class:"footer"},t("slot",{name:"footer"})))}renderError(e){return e.code!==u.SCENE_TREE_DISABLED?t(m,{details:e},t("button",{class:"button button-secondary",onClick:()=>this.retryConnectToViewer(),disabled:this.attemptingRetry},"Retry")):t(m,{details:e})}handleViewerChanged(t,e){this.stateMap.componentLoaded&&this.connectToViewer()}handleControllerChanged(t){var e;this.stateMap.componentLoaded&&(null===(e=this.stateMap.onStateChangeDisposable)||void 0===e||e.dispose(),this.stateMap.onStateChangeDisposable=t.onStateChange.on((t=>this.handleControllerStateChange(t))),t.setMetadataKeys(this.metadataKeys))}handleMetadataKeysChanged(){var t;null===(t=this.controller)||void 0===t||t.setMetadataKeys(this.metadataKeys)}retryConnectToViewer(){this.attemptingRetry=!0,this.errorDetails=void 0,this.connectToViewer()}connectToViewer(){var t,e;null===(t=this.stateMap.viewerDisposable)||void 0===t||t.dispose(),null==this.viewer&&null!=this.viewerSelector&&(this.viewer=document.querySelector(this.viewerSelector)),null!=this.viewer?this.stateMap.viewerDisposable=null===(e=this.controller)||void 0===e?void 0:e.connectToViewer(this.viewer):this.attemptingRetry=!1}scheduleClearUnusedData(){null!=this.stateMap.idleCallbackId&&window.cancelIdleCallback(this.stateMap.idleCallbackId),this.stateMap.idleCallbackId=window.requestIdleCallback((t=>{var e,i,n;const s=null===(e=t.timeRemaining)||void 0===e?void 0:e.call(t);if(null==s||s>=25){const t=this.getLayoutElement(),e=t.viewportStartIndex,s=t.viewportEndIndex,[o,r]=(null===(i=this.controller)||void 0===i?void 0:i.getPageIndexesForRange(e,s))||[];null!=o&&null!=r&&(null===(n=this.controller)||void 0===n||n.invalidatePagesOutsideRange(o,r,50))}else this.scheduleClearUnusedData()}))}handleControllerStateChange(t){this.showLoader=!!t.shouldShowLoading,this.rows=t.rows,this.totalRows=t.totalRows,"failure"===t.connection.type?(this.errorDetails=t.connection.details,this.connectionError.emit(t.connection.details)):this.errorDetails="disconnected"===t.connection.type?new c("DISCONNECTED",u.DISCONNECTED):void 0,"connected"!==t.connection.type&&"failure"!==t.connection.type||(this.attemptingRetry=!1)}async performRowOperation(t,e){const i="number"==typeof t?this.rows[t]:t;if(null==i)throw new Error("Cannot perform scene tree operation. Row not found.");const n=w(i)?i.node:i;if(null==n.id)throw new Error("Cannot perform scene tree operation. ID is undefined.");if(null==this.viewer)throw new Error("Cannot perform scene tree operation. Cannot get reference to viewer.");await e({viewer:this.viewer,id:n.id.hex,node:n})}async handleSearch(t){const e=this.metadataSearchKeys.length>0?this.metadataSearchKeys:this.metadataKeys;try{await this.filterItems(t.detail,{columns:e,exactMatch:this.metadataSearchExactMatch})}catch(t){console.error("Failed to filter tree with exception: ",t)}}getScrollToPosition(t,e){var i;const n=this.getLayoutElement(),s=Math.max(0,Math.min(t,this.totalRows-1)),o=null!==(i=n.layoutHeight)&&void 0!==i?i:0,r=n.rowHeight;return"start"===e?s*r:"middle"===e?s*r+r/2-o/2:s*r+r-o}getConfig(){return p(this.configEnv,this.config)}ensureLayoutDefined(){let t=this.el.querySelector("vertex-scene-tree-table-layout");null==t&&(t=document.createElement("vertex-scene-tree-table-layout"),t.innerHTML='\n <vertex-scene-tree-table-column>\n <template>\n <vertex-scene-tree-table-cell prop:value="{{row.node.name}}" expand-toggle visibility-toggle></vertex-scene-tree-table-cell>\n </template>\n </vertex-scene-tree-table-column>\n ',this.el.appendChild(t)),this.stateMap.layoutEl=t}updateLayoutElement(){const t=this.stateMap.layoutEl;null!=t?(t.rows=this.rows,t.tree=this.el,t.totalRows=this.totalRows,t.controller=this.controller,t.rowData=this.rowData):!this.stateMap.componentLoaded&&this.totalRows>0&&console.debug("Scene tree has rows, but the component has not yet rendered")}getLayoutElement(){if(null!=this.stateMap.layoutEl)return this.stateMap.layoutEl;throw new Error("Layout element is undefined")}get el(){return r(this)}static get watchers(){return{viewer:["handleViewerChanged"],controller:["handleControllerChanged"],metadataKeys:["handleMetadataKeysChanged"]}}};b.style="button{border:none;background:transparent;cursor:pointer;margin:0;padding:0}.button{padding:0.5rem;border-radius:0.25rem}.button-secondary{color:var(--neutral-800);background-color:var(--neutral-300)}.button-secondary:hover{color:var(--neutral-900)}.button-secondary:hover:enabled{box-shadow:0 2px 2px rgb(0 0 0 / 20%)}.button-secondary:disabled{opacity:0.8}.button-secondary:hover:disabled{cursor:not-allowed}:host{--scene-tree-toolbar-separator:1px solid var(--neutral-300);width:300px;height:100%;user-select:none;-webkit-user-select:none;cursor:default;display:flex;flex-direction:column}.rows-scroll{position:relative;height:var(--scene-tree-row-height, 0);flex-grow:1}.rows{position:relative}.row{position:absolute;display:flex;align-items:center;width:100%;height:var(--scene-tree-row-height);padding:var(--scene-tree-row-padding);box-sizing:border-box}.row:hover{background-color:var(--scene-tree-row-hover-color)}.row.is-selected{background-color:var(--scene-tree-row-selected-color)}.expand-toggle{cursor:pointer;width:16px}.row-text{margin-left:0.25rem;width:100%;white-space:nowrap;text-overflow:ellipsis;overflow:hidden}.visibility-btn{display:flex;align-items:center;visibility:hidden;padding:4px}.visibility-btn.is-hidden{visibility:visible}.row:hover .visibility-btn{visibility:visible}.error{display:flex;flex-direction:column;align-items:center;font-size:0.875rem;width:100%;height:100%;padding:1rem;box-sizing:border-box;justify-content:center}.error-section{margin-top:1rem}.error-message{text-align:center}.search-toolbar,slot[name='header']::slotted(*){border-bottom:var(--scene-tree-toolbar-separator)}slot[name='footer']::slotted(:not(:last-child)){border-top:var(--scene-tree-toolbar-separator)}.header{display:flex;flex-direction:column}.footer{display:flex;flex-direction:column}.loading{position:absolute;top:150px;left:50%;transform:translate(-50%, -50%);text-align:center}";export{b as vertex_scene_tree}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
/**!
|
|
2
2
|
* Copyright (c) 2023 Vertex Software LLC. All rights reserved.
|
|
3
3
|
*/
|
|
4
|
-
import{c as t,u as e,a as r,b as s}from"./p-fc7d8c03.js";import{I as i,a as n,b as o}from"./p-440c8174.js";import{v as a,b as u,a as h,m as c,q as l,r as d,p,d as w}from"./p-d216a866.js";import{v,t as m,e as f,g as y,d as b,w as x,h as g}from"./p-46f40a43.js";import"./p-df8fbe56.js";import{t as I}from"./p-934cbb97.js";const O={opacity:255,glossiness:4,diffuse:{r:0,g:0,b:0,a:0},ambient:{r:0,g:0,b:0,a:0},specular:{r:0,g:0,b:0,a:0},emissive:{r:0,g:0,b:0,a:0}},j=(e,r)=>{const s=t.fromHexString(e);return Object.assign(Object.assign({},O),{opacity:null!=r?r:O.opacity,diffuse:Object.assign({},null!=s?s:O.diffuse)})},S=Object.freeze({__proto__:null,defaultColor:O,create:(t,e,r,s)=>Object.assign(Object.assign({},O),{opacity:null!=s?s:O.opacity,diffuse:{r:t,g:e,b:r,a:0}}),fromHex:j});function B(t){var r;const s=e.parse(t);if("urn"!==s.scheme||null==s.path)throw new Error("Invalid URN. Expected URN scheme.");const[n,o,a,...u]=s.path.split(/[:/]/);if("vertexvis"!==n)throw new Error("Invalid URN. Expected URN to be vertexvis namespace");switch(o){case"stream-key":const t=null!=(h=s.query)?h.split("&").map((t=>{const[e,r]=t.split("=");switch(e){case"supplied-id":return{type:"supplied-id",id:r};case"scene-view-state":return{type:"scene-view-state",id:r};default:throw new Error("Invalid URN. Unknown query value type")}})):[];return{resource:{type:"stream-key",id:a},subResource:null!==(r=function(t){if(null!=t){const[e,r]=t.split("/");switch(e){case"scene-view-states":return{type:"scene-view-state",id:r};default:return}}}(u.join("/")))&&void 0!==r?r:t.find((t=>"scene-view-state"===t.type)),queries:t.filter((t=>"scene-view-state"!==t.type))};default:throw new i(`Invalid URN. Unknown resource type ${o}`)}var h}const T=Object.freeze({__proto__:null,fromUrn:B});class k{constructor(t,e=new Date){this.knownRemoteTime=t,this.knownLocalTime=e}localOffset(){return this.duration(this.knownLocalTime,this.localNow())}localTime(t){const e="number"==typeof t?new Date(this.knownLocalTime.getTime()+t):t,r=this.duration(this.knownRemoteTime,e);return this.addDuration(this.knownLocalTime,r)}remoteOffset(t=new Date){return this.duration(this.remoteTime(this.knownLocalTime),this.remoteTime(t))}remoteNow(){return this.remoteTime(this.localNow())}remoteTime(t){const e="number"==typeof t?new Date(this.knownLocalTime.getTime()+t):t,r=this.duration(this.knownLocalTime,e);return this.addDuration(this.knownRemoteTime,r)}addDuration(t,e){return new Date(t.getTime()+e)}duration(t,e){return e.getTime()-t.getTime()}localNow(){return new Date(Date.now())}}class A{constructor(t,e,r,s=1e4){this.stream=t,this.predicate=e,this.transform=r,this.timeout=s,this.listeners=[],this.handleMessage=this.handleMessage.bind(this)}on(t){this.listeners=[...this.listeners,t],null!=this.eventDisposable&&null!=this.requestDisposable||this.addListeners()}off(t){this.listeners=this.listeners.filter((e=>e!==t)),0===this.listeners.length&&this.removeListeners()}once(){let t;return r.timeout(this.timeout,new Promise((e=>{t=r=>{e(r),this.off(t)},this.on(t)}))).finally((()=>{this.off(t)}))}handleMessage(t){if(this.predicate(t)){const e=this.transform(t);null!=e&&this.listeners.forEach((t=>t(e)))}}addListeners(){this.eventDisposable=this.stream.onEvent(this.handleMessage),this.requestDisposable=this.stream.onRequest(this.handleMessage)}removeListeners(){var t,e;null===(t=this.eventDisposable)||void 0===t||t.dispose(),null===(e=this.requestDisposable)||void 0===e||e.dispose()}}class V{constructor(t,e,{animationId:r,correlationId:s},i){this.data=void 0,this.onAnimationCompleted=new A(t,(t=>{var e,s,i;return(null===(i=null===(s=null===(e=t.event)||void 0===e?void 0:e.animationCompleted)||void 0===s?void 0:s.animationId)||void 0===i?void 0:i.hex)===r}),(t=>{var e,r,s;return(null===(s=null===(r=null===(e=t.event)||void 0===e?void 0:e.animationCompleted)||void 0===r?void 0:r.animationId)||void 0===s?void 0:s.hex)||void 0}),i),this.onFrameReceived=new A(t,(t=>{var e,r,i;return!!(null===(i=null===(r=null===(e=t.request)||void 0===e?void 0:e.drawFrame)||void 0===r?void 0:r.frameCorrelationIds)||void 0===i?void 0:i.some((t=>t===s)))}),(t=>{var r;return null!=(null===(r=t.request)||void 0===r?void 0:r.drawFrame)?e(t.request.drawFrame):void 0}),i)}}function E(t){if("string"==typeof t)return{sceneViewStateId:{hex:t}};if(function(t){return null!=t.id}(t))return{sceneViewStateId:{hex:t.id}};if(function(t){return null!=t.suppliedId}(t))return{sceneViewStateSuppliedId:{value:t.suppliedId}};throw new Error("Unable to build scene view state identifier, input must be a string or `SceneViewStateIdentifier`.")}function q(t,e){switch(t.type){case"and":case"or":return{operand:{itemCollection:{queries:t.expressions.map((t=>({sceneItemQuery:C(t)})))}}};case"not":return{not:{expression:q(t.query,e)}};case"item-id":case"supplied-id":return{operand:{item:{sceneItemQuery:C(t)}}};case"all":return{operand:{root:{}}};case"scene-tree-range":return{operand:{sceneTreeRange:{start:t.range.start,end:t.range.end}}};case"metadata":return{operand:{metadata:{valueFilter:t.filter,keys:t.keys,exactMatch:t.exactMatch}}};case"all-selected":return{operand:{override:{selection:{}}}};case"point":return{operand:{point:{point:t.point,viewport:e.dimensions}}};case"volume-intersection":return{operand:{volume:{frustumByRectangle:{rectangle:t.rectangle},exclusive:t.exclusive,viewport:e.dimensions}}};default:return{}}}function C(t){switch(t.type){case"item-id":return{id:new v.protobuf.core.Uuid({hex:t.value})};case"supplied-id":return{suppliedId:t.value};default:return{}}}class M{constructor(t){this.flyToOptions=t}build(){return this.flyToOptions}}class R{withItemId(t){return new M({flyTo:{type:"internal",data:t}})}withSuppliedId(t){return new M({flyTo:{type:"supplied",data:t}})}withCamera(t){return new M({flyTo:{type:"camera",data:t}})}withBoundingBox(t){return new M({flyTo:{type:"bounding-box",data:t}})}build(){return this.flyToOptions}}class U{constructor(t,e,r,s,i,n){this.stream=t,this.aspect=e,this.data=r,this.boundingBox=s,this.decodeFrame=i,this.flyToOptions=n}fitCameraToBoundingBox(t,e,r){const s=a.scale(e,a.normalize(r)),i=u.center(t),n=a.subtract(i,s);return this.update({lookAt:i,position:n,viewVector:s})}signedDistanceToBoundingBoxCenter(t){const{position:e,viewVector:r}=x(this.data),s=u.center(null!=t?t:this.boundingBox),i=a.subtract(s,e);return a.dot(r,i)/a.magnitude(r)}flyTo(t){return this.updateFlyToOptions("function"!=typeof t?{flyTo:this.buildFlyToType(t)}:t(new R).build())}viewAll(){return this.fitToBoundingBox(this.boundingBox)}async render(t){var e,r,i;null==this.flyToOptions&&null!=t&&(this.flyToOptions={flyTo:{type:"camera",data:this.data}});try{const n=s.create();if(null!=this.flyToOptions){const s=function(t,e,r){const s={frameCorrelationId:{value:t},animation:r?{duration:I(r.milliseconds)}:void 0};switch(e.flyTo.type){case"supplied":return Object.assign(Object.assign({},s),{itemSuppliedId:e.flyTo.data});case"internal":return Object.assign(Object.assign({},s),{itemId:new v.protobuf.core.Uuid({hex:e.flyTo.data})});case"camera":return Object.assign(Object.assign({},s),{camera:m(e.flyTo.data)});case"bounding-box":return Object.assign(Object.assign({},s),{boundingBox:{xmin:e.flyTo.data.min.x,xmax:e.flyTo.data.max.x,ymin:e.flyTo.data.min.y,ymax:e.flyTo.data.max.y,zmin:e.flyTo.data.min.z,zmax:e.flyTo.data.max.z}});default:return{}}}(n,this.flyToOptions,null==t?void 0:t.animation),o=await this.stream.flyTo(s,!0);return new V(this.stream,this.decodeFrame,{correlationId:n,animationId:(null===(r=null===(e=o.flyTo)||void 0===e?void 0:e.animationId)||void 0===r?void 0:r.hex)||void 0},null!=(null===(i=null==t?void 0:t.animation)||void 0===i?void 0:i.milliseconds)?t.animation.milliseconds+1e4:void 0)}return this.stream.replaceCamera({camera:m(this.data),frameCorrelationId:{value:n}}),new V(this.stream,this.decodeFrame,{correlationId:n})}catch(t){throw console.warn("Error when performing render: ",t),t}}rotateAroundAxis(t,e){return this.rotateAroundAxisAtPoint(t,this.data.lookAt,e)}alignTo(t,e){const r=a.normalize(a.cross(this.up,a.normalize(this.viewVector))),s=a.normalize(a.cross(a.normalize(this.viewVector),r)),i=a.angleTo(e,s)>Math.PI/2?a.negate(s):s,n=a.isEqual(i,e)?r:a.normalize(a.cross(i,e)),o=a.transformMatrix(this.viewVector,c.makeRotation(l.fromAxisAngle(n,a.angleTo(e,i)))),u=d.create({origin:t,direction:a.normalize(o)}),h=d.at(u,a.magnitude(this.viewVector));return this.update({position:t,lookAt:h,up:e})}standardView(t){return this.update({position:t.position,viewVector:a.subtract(a.origin(),t.position),lookAt:a.origin(),up:t.up})}buildFlyToType(t){if(null!=t.boundingBox)return{type:"bounding-box",data:t.boundingBox};if(null!=t.camera)return{type:"camera",data:t.camera};if(null!=t.itemId)return{type:"internal",data:t.itemId};if(null!=t.itemSuppliedId)return{type:"supplied",data:t.itemSuppliedId};throw new Error("Fly to must specify at least one option.")}computeClippingPlanes(t){return g(this.boundingBox,t)}}class _ extends U{constructor(t,e,r,s,i,n){super(t,e,r,s,i,n),this.perspectiveData=r}moveBy(t){return this.update({position:a.add(this.position,t),lookAt:a.add(this.lookAt,t)})}rotateAroundAxisAtPoint(t,e,r){return this.update({position:a.rotateAboutAxis(t,this.position,r,e),lookAt:a.rotateAboutAxis(t,this.lookAt,r,e),up:a.rotateAboutAxis(t,this.up,r,a.origin())})}fitToBoundingBox(t){var e;const r=1.1*a.magnitude(a.subtract(t.max,u.center(t)));let s=Math.tan(.008726646259972*(null!==(e=this.fovY)&&void 0!==e?e:45));this.aspect<1&&(s*=this.aspect);const i=Math.abs(r/s);return super.fitCameraToBoundingBox(t,i,this.viewVector)}update(t){var e;const r=null!==(e=t.fovY)&&void 0!==e?e:this.fovY;return new _(this.stream,this.aspect,Object.assign(Object.assign(Object.assign({},this.perspectiveData),t),{fovY:r}),this.boundingBox,this.decodeFrame,this.flyToOptions)}toFrameCamera(){var t;return new f(this.position,this.lookAt,this.up,this.near,this.far,this.aspectRatio,null!==(t=this.fovY)&&void 0!==t?t:45)}get viewVector(){return a.subtract(this.lookAt,this.position)}get position(){return Object.assign({},this.perspectiveData.position)}get up(){return Object.assign({},this.perspectiveData.up)}get lookAt(){return Object.assign({},this.perspectiveData.lookAt)}get fovY(){return this.perspectiveData.fovY}get aspectRatio(){return this.aspect}get near(){const{near:t}=this.computeClippingPlanes(this.perspectiveData);return t}get far(){const{far:t}=this.computeClippingPlanes(this.perspectiveData);return t}updateFlyToOptions(t){return new _(this.stream,this.aspect,this.perspectiveData,this.boundingBox,this.decodeFrame,t)}}class D extends U{constructor(t,e,r,s,i,n){super(t,e,r,s,i,n),this.orthographicData=r}moveBy(t){return this.update({lookAt:a.add(this.lookAt,t)})}rotateAroundAxisAtPoint(t,e,r){const s=a.rotateAboutAxis(t,this.lookAt,r,e),i=a.rotateAboutAxis(t,this.position,r,e),n=y(a.subtract(s,i),h.create(this.boundingBox));return this.update({viewVector:n,lookAt:s,up:a.rotateAboutAxis(t,this.up,r,a.origin())})}fitToBoundingBox(t){const e=h.create(t),r=super.fitCameraToBoundingBox(t,e.radius,this.viewVector);return this.update({lookAt:r.lookAt,viewVector:r.viewVector,fovHeight:2*e.radius})}update(t){return new D(this.stream,this.aspect,Object.assign(Object.assign({},this.orthographicData),t),this.boundingBox,this.decodeFrame,this.flyToOptions)}toFrameCamera(){return new b(y(this.viewVector,h.create(this.boundingBox)),this.lookAt,this.up,this.near,this.far,this.aspectRatio,this.fovHeight)}get viewVector(){return Object.assign({},this.orthographicData.viewVector)}get position(){return a.add(this.lookAt,a.negate(this.viewVector))}get up(){return Object.assign({},this.orthographicData.up)}get lookAt(){return Object.assign({},this.orthographicData.lookAt)}get fovHeight(){return this.orthographicData.fovHeight}get aspectRatio(){return this.aspect}get near(){const{near:t}=this.computeClippingPlanes(this.orthographicData);return t}get far(){const{far:t}=this.computeClippingPlanes(this.orthographicData);return t}updateFlyToOptions(t){return new D(this.stream,this.aspect,this.orthographicData,this.boundingBox,this.decodeFrame,t)}}class F{constructor(t,e){this.stream=t,this.imageScaleProvider=e}async hitItems(t,e){const r=this.imageScaleProvider();return(await this.stream.hitItems({point:p.scale(t,(null==r?void 0:r.x)||1,(null==r?void 0:r.y)||1),includeMetadata:null==e?void 0:e.includeMetadata},!0)).hitItems||void 0}}class N{constructor(t,e){this.stream=t,this.data=e}async update(t){return(await this.stream.updateCrossSectioning({crossSectioning:t},!0)).updateCrossSectioning||void 0}current(){return this.data}}class z{constructor(t=[]){this.operations=t}build(){return this.operations.concat()}materialOverride(t){return new z(this.operations.concat([{type:"change-material",material:t}]))}show(){return new z(this.operations.concat([{type:"show"}]))}hide(){return new z(this.operations.concat([{type:"hide"}]))}select(){return new z(this.operations.concat([{type:"select"}]))}deselect(){return new z(this.operations.concat([{type:"deselect"}]))}clearMaterialOverrides(){return new z(this.operations.concat([{type:"clear-override"}]))}transform(t){return new z(this.operations.concat([{type:"change-transform",transform:t}]))}clearTransforms(t=!0){return new z(this.operations.concat([{type:"clear-transform",cascade:t}]))}}class P{constructor(t){this.inverted=t}build(){return this.inverted?{type:"not",query:this.queryExpressionBuilder()}:this.queryExpressionBuilder()}}class H{constructor(t=!1){this.inverted=t}all(){return new L}not(){return new Y(!this.inverted)}withItemIds(t){return new W(t,"item-id",this.inverted)}withSuppliedIds(t){return new W(t,"supplied-id",this.inverted)}withItemId(t){return new X({type:"item-id",value:t},this.inverted)}withSuppliedId(t){return new X({type:"supplied-id",value:t},this.inverted)}withSceneTreeRange(t){return new Q(t,this.inverted)}withMetadata(t,e,r){return new $(t,e,r,this.inverted)}withSelected(){return new G(this.inverted)}withPoint(t){return new J(t,this.inverted)}withVolumeIntersection(t,e){return new K(t,this.inverted,e)}}class Y extends H{constructor(t){super(t)}}class L extends P{constructor(t=!1){super(t)}queryExpressionBuilder(){return{type:"all"}}}class Q extends P{constructor(t,e){super(e),this.range=t}queryExpressionBuilder(){return{type:"scene-tree-range",range:this.range}}}class $ extends P{constructor(t,e,r,s){super(s),this.filter=t,this.keys=e,this.exactMatch=r}queryExpressionBuilder(){return{type:"metadata",filter:this.filter,keys:this.keys,exactMatch:this.exactMatch}}}class G extends P{constructor(t){super(t)}queryExpressionBuilder(){return{type:"all-selected"}}}class J extends P{constructor(t,e){super(e),this.point=t}queryExpressionBuilder(){return{type:"point",point:this.point}}}class K extends P{constructor(t,e,r){super(e),this.rectangle=t,this.exclusive=r}queryExpressionBuilder(){return{type:"volume-intersection",rectangle:this.rectangle,exclusive:!!this.exclusive}}}class W extends P{constructor(t,e,r){super(r),this.ids=t,this.type=e}queryExpressionBuilder(){return{type:"or",expressions:this.ids.map((t=>({type:this.type,value:t})))}}}class X extends P{constructor(t,e){super(e),this.query=t}queryExpressionBuilder(){return Object.assign({},this.query)}and(){return new tt([this.query],this.inverted)}or(){return new Z([this.query],this.inverted)}}class Z extends P{constructor(t,e){super(e),this.expressions=t}queryExpressionBuilder(){return{type:"or",expressions:[...this.expressions]}}withItemId(t){return new Z([...this.expressions,{type:"item-id",value:t}],this.inverted)}withSuppliedId(t){return new Z([...this.expressions,{type:"supplied-id",value:t}],this.inverted)}or(){return this}}class tt extends P{constructor(t,e){super(e),this.expressions=t}queryExpressionBuilder(){return{type:"and",expressions:[...this.expressions]}}withItemId(t){return new tt([...this.expressions,{type:"item-id",value:t}],this.inverted)}withSuppliedId(t){return new tt([...this.expressions,{type:"supplied-id",value:t}],this.inverted)}and(){return this}}class et{where(t){const e=t(new H).build();return new rt(e)}}class rt{constructor(t,e){this.query=t,this.builder=null!=e?e:new z}materialOverride(t){return new rt(this.query,this.builder.materialOverride("string"==typeof t?j(t):t))}hide(){return new rt(this.query,this.builder.hide())}show(){return new rt(this.query,this.builder.show())}select(){return new rt(this.query,this.builder.select())}deselect(){return new rt(this.query,this.builder.deselect())}clearMaterialOverrides(){return new rt(this.query,this.builder.clearMaterialOverrides())}transform(t){if(Array.isArray(t)){if(16!==t.length)throw new o("Matrix provided must contain exactly 16 values (4x4).");return new rt(this.query,this.builder.transform({r0:{x:t[0],y:t[1],z:t[2],w:t[3]},r1:{x:t[4],y:t[5],z:t[6],w:t[7]},r2:{x:t[8],y:t[9],z:t[10],w:t[11]},r3:{x:t[12],y:t[13],z:t[14],w:t[15]}}))}return new rt(this.query,this.builder.transform(t))}clearTransforms(t=!0){return new rt(this.query,this.builder.clearTransforms(t))}build(){return{query:this.query,operations:this.builder.build()}}}class st{constructor(t,e,r,s){this.sceneViewId=t,this.stream=e,this.dimensions=r,this.queryOperations=s}async execute(t){const e=this.queryOperations.map((t=>function(t,e,r){const s=function(t){return t.map((t=>{switch(t.type){case"change-material":return{changeMaterial:{material:{d:t.material.opacity,ns:t.material.glossiness,ka:t.material.ambient,kd:t.material.diffuse,ks:t.material.specular,ke:t.material.emissive}}};case"clear-override":return{changeMaterial:{}};case"change-transform":return{changeTransform:{transform:Object.assign({},t.transform)}};case"clear-transform":return{clearTransform:{cascade:t.cascade}};case"hide":return{changeVisibility:{visible:!1}};case"show":return{changeVisibility:{visible:!0}};case"select":return{changeSelection:{selected:!0}};case"deselect":return{changeSelection:{selected:!1}};default:return{}}}))}(e);return{queryExpression:q(t,r),operationTypes:s}}(t.query,t.operations,{dimensions:this.dimensions}))),r={sceneViewId:{hex:this.sceneViewId},operations:e,suppliedCorrelationId:null!=(null==t?void 0:t.suppliedCorrelationId)?{value:null==t?void 0:t.suppliedCorrelationId}:void 0};await this.stream.createSceneAlteration(r)}}class it{constructor(t,e,r,s,i,n,o){this.stream=t,this.frame=e,this.decodeFrame=r,this.imageScaleProvider=s,this.dimensions=i,this.sceneId=n,this.sceneViewId=o}async applySceneViewState(t,e={}){const r=E(t);return await this.stream.loadSceneViewState(Object.assign(Object.assign({},r),{frameCorrelationId:e.suppliedCorrelationId?{value:e.suppliedCorrelationId}:void 0}),!0)}async applyPartialSceneViewState(t,e,r={}){const s=E(t),i=e.map((t=>{switch(t){case"camera":return v.protobuf.stream.SceneViewStateFeature.SCENE_VIEW_STATE_FEATURE_CAMERA;case"material_overrides":return v.protobuf.stream.SceneViewStateFeature.SCENE_VIEW_STATE_FEATURE_MATERIAL_OVERRIDE;case"selection":return v.protobuf.stream.SceneViewStateFeature.SCENE_VIEW_STATE_FEATURE_SELECTION;case"visibility":return v.protobuf.stream.SceneViewStateFeature.SCENE_VIEW_STATE_FEATURE_VISIBILITY;case"transforms":return v.protobuf.stream.SceneViewStateFeature.SCENE_VIEW_STATE_FEATURE_TRANSFORM;case"cross_section":return v.protobuf.stream.SceneViewStateFeature.SCENE_VIEW_STATE_FEATURE_CROSS_SECTION;default:return v.protobuf.stream.SceneViewStateFeature.SCENE_VIEW_STATE_FEATURE_INVALID}}));return await this.stream.loadSceneViewState(Object.assign(Object.assign({},s),{frameCorrelationId:r.suppliedCorrelationId?{value:r.suppliedCorrelationId}:void 0,sceneViewStateFeatureSubset:i}),!0)}async reset(t={}){return await this.stream.resetSceneView({includeCamera:t.includeCamera,frameCorrelationId:t.suppliedCorrelationId?{value:t.suppliedCorrelationId}:void 0},!0)}items(t){const e=t(new et),r=(Array.isArray(e)?e:[e]).reduce(((t,e)=>t.concat(e.build())),[]);return new st(this.sceneViewId,this.stream,this.dimensions,r)}camera(){const{scene:t}=this.frame;if(t.camera.isOrthographic())return new D(this.stream,w.aspectRatio(this.viewport()),{viewVector:t.camera.viewVector,lookAt:t.camera.lookAt,up:t.camera.up,fovHeight:t.camera.fovHeight},this.frame.scene.boundingBox,this.decodeFrame);if(t.camera.isPerspective())return new _(this.stream,w.aspectRatio(this.viewport()),{position:t.camera.position,lookAt:t.camera.lookAt,up:t.camera.up,fovY:t.camera.fovY},this.frame.scene.boundingBox,this.decodeFrame);throw new n("Cannot retrieve camera. Scene has an unknown or invalid camera type.")}boundingBox(){return this.frame.scene.boundingBox}crossSectioning(){return new N(this.stream,this.frame.scene.crossSection)}raycaster(){return new F(this.stream,this.imageScaleProvider)}viewport(){return this.frame.dimensions}scale(){return this.imageScaleProvider()||p.create(1,1)}}export{it as S,k as a,S as c,B as f,T as l}
|
|
4
|
+
import{c as t,u as e,a as r,b as s}from"./p-fc7d8c03.js";import{I as i,a as n,b as o}from"./p-440c8174.js";import{v as a,b as u,a as h,m as c,q as l,r as d,p,d as w}from"./p-d216a866.js";import{v,t as m,e as y,g as f,d as b,w as x,h as g}from"./p-817743a4.js";import"./p-df8fbe56.js";import{t as I}from"./p-a7c29e95.js";const O={opacity:255,glossiness:4,diffuse:{r:0,g:0,b:0,a:0},ambient:{r:0,g:0,b:0,a:0},specular:{r:0,g:0,b:0,a:0},emissive:{r:0,g:0,b:0,a:0}},j=(e,r)=>{const s=t.fromHexString(e);return Object.assign(Object.assign({},O),{opacity:null!=r?r:O.opacity,diffuse:Object.assign({},null!=s?s:O.diffuse)})},S=Object.freeze({__proto__:null,defaultColor:O,create:(t,e,r,s)=>Object.assign(Object.assign({},O),{opacity:null!=s?s:O.opacity,diffuse:{r:t,g:e,b:r,a:0}}),fromHex:j});function B(t){var r;const s=e.parse(t);if("urn"!==s.scheme||null==s.path)throw new Error("Invalid URN. Expected URN scheme.");const[n,o,a,...u]=s.path.split(/[:/]/);if("vertexvis"!==n)throw new Error("Invalid URN. Expected URN to be vertexvis namespace");switch(o){case"stream-key":const t=null!=(h=s.query)?h.split("&").map((t=>{const[e,r]=t.split("=");switch(e){case"supplied-id":return{type:"supplied-id",id:r};case"scene-view-state":return{type:"scene-view-state",id:r};default:throw new Error("Invalid URN. Unknown query value type")}})):[];return{resource:{type:"stream-key",id:a},subResource:null!==(r=function(t){if(null!=t){const[e,r]=t.split("/");switch(e){case"scene-view-states":return{type:"scene-view-state",id:r};default:return}}}(u.join("/")))&&void 0!==r?r:t.find((t=>"scene-view-state"===t.type)),queries:t.filter((t=>"scene-view-state"!==t.type))};default:throw new i(`Invalid URN. Unknown resource type ${o}`)}var h}const T=Object.freeze({__proto__:null,fromUrn:B});class k{constructor(t,e=new Date){this.knownRemoteTime=t,this.knownLocalTime=e}localOffset(){return this.duration(this.knownLocalTime,this.localNow())}localTime(t){const e="number"==typeof t?new Date(this.knownLocalTime.getTime()+t):t,r=this.duration(this.knownRemoteTime,e);return this.addDuration(this.knownLocalTime,r)}remoteOffset(t=new Date){return this.duration(this.remoteTime(this.knownLocalTime),this.remoteTime(t))}remoteNow(){return this.remoteTime(this.localNow())}remoteTime(t){const e="number"==typeof t?new Date(this.knownLocalTime.getTime()+t):t,r=this.duration(this.knownLocalTime,e);return this.addDuration(this.knownRemoteTime,r)}addDuration(t,e){return new Date(t.getTime()+e)}duration(t,e){return e.getTime()-t.getTime()}localNow(){return new Date(Date.now())}}class A{constructor(t,e,r,s=1e4){this.stream=t,this.predicate=e,this.transform=r,this.timeout=s,this.listeners=[],this.handleMessage=this.handleMessage.bind(this)}on(t){this.listeners=[...this.listeners,t],null!=this.eventDisposable&&null!=this.requestDisposable||this.addListeners()}off(t){this.listeners=this.listeners.filter((e=>e!==t)),0===this.listeners.length&&this.removeListeners()}once(){let t;return r.timeout(this.timeout,new Promise((e=>{t=r=>{e(r),this.off(t)},this.on(t)}))).finally((()=>{this.off(t)}))}handleMessage(t){if(this.predicate(t)){const e=this.transform(t);null!=e&&this.listeners.forEach((t=>t(e)))}}addListeners(){this.eventDisposable=this.stream.onEvent(this.handleMessage),this.requestDisposable=this.stream.onRequest(this.handleMessage)}removeListeners(){var t,e;null===(t=this.eventDisposable)||void 0===t||t.dispose(),null===(e=this.requestDisposable)||void 0===e||e.dispose()}}class V{constructor(t,e,{animationId:r,correlationId:s},i){this.data=void 0,this.onAnimationCompleted=new A(t,(t=>{var e,s,i;return(null===(i=null===(s=null===(e=t.event)||void 0===e?void 0:e.animationCompleted)||void 0===s?void 0:s.animationId)||void 0===i?void 0:i.hex)===r}),(t=>{var e,r,s;return(null===(s=null===(r=null===(e=t.event)||void 0===e?void 0:e.animationCompleted)||void 0===r?void 0:r.animationId)||void 0===s?void 0:s.hex)||void 0}),i),this.onFrameReceived=new A(t,(t=>{var e,r,i;return!!(null===(i=null===(r=null===(e=t.request)||void 0===e?void 0:e.drawFrame)||void 0===r?void 0:r.frameCorrelationIds)||void 0===i?void 0:i.some((t=>t===s)))}),(t=>{var r;return null!=(null===(r=t.request)||void 0===r?void 0:r.drawFrame)?e(t.request.drawFrame):void 0}),i)}}function E(t){if("string"==typeof t)return{sceneViewStateId:{hex:t}};if(function(t){return null!=t.id}(t))return{sceneViewStateId:{hex:t.id}};if(function(t){return null!=t.suppliedId}(t))return{sceneViewStateSuppliedId:{value:t.suppliedId}};throw new Error("Unable to build scene view state identifier, input must be a string or `SceneViewStateIdentifier`.")}function q(t,e){switch(t.type){case"and":case"or":return{operand:{itemCollection:{queries:t.expressions.map((t=>({sceneItemQuery:C(t)})))}}};case"not":return{not:{expression:q(t.query,e)}};case"item-id":case"supplied-id":return{operand:{item:{sceneItemQuery:C(t)}}};case"all":return{operand:{root:{}}};case"scene-tree-range":return{operand:{sceneTreeRange:{start:t.range.start,end:t.range.end}}};case"metadata":return{operand:{metadata:{valueFilter:t.filter,keys:t.keys,exactMatch:t.exactMatch}}};case"all-selected":return{operand:{override:{selection:{}}}};case"point":return{operand:{point:{point:t.point,viewport:e.dimensions}}};case"volume-intersection":return{operand:{volume:{frustumByRectangle:{rectangle:t.rectangle},exclusive:t.exclusive,viewport:e.dimensions}}};default:return{}}}function C(t){switch(t.type){case"item-id":return{id:new v.protobuf.core.Uuid({hex:t.value})};case"supplied-id":return{suppliedId:t.value};default:return{}}}class M{constructor(t){this.flyToOptions=t}build(){return this.flyToOptions}}class R{withItemId(t){return new M({flyTo:{type:"internal",data:t}})}withSuppliedId(t){return new M({flyTo:{type:"supplied",data:t}})}withCamera(t){return new M({flyTo:{type:"camera",data:t}})}withBoundingBox(t){return new M({flyTo:{type:"bounding-box",data:t}})}build(){return this.flyToOptions}}class U{constructor(t,e,r,s,i,n){this.stream=t,this.aspect=e,this.data=r,this.boundingBox=s,this.decodeFrame=i,this.flyToOptions=n}fitCameraToBoundingBox(t,e,r){const s=a.scale(e,a.normalize(r)),i=u.center(t),n=a.subtract(i,s);return this.update({lookAt:i,position:n,viewVector:s})}signedDistanceToBoundingBoxCenter(t){const{position:e,viewVector:r}=x(this.data),s=u.center(null!=t?t:this.boundingBox),i=a.subtract(s,e);return a.dot(r,i)/a.magnitude(r)}flyTo(t){return this.updateFlyToOptions("function"!=typeof t?{flyTo:this.buildFlyToType(t)}:t(new R).build())}viewAll(){return this.fitToBoundingBox(this.boundingBox)}async render(t){var e,r,i;null==this.flyToOptions&&null!=t&&(this.flyToOptions={flyTo:{type:"camera",data:this.data}});try{const n=s.create();if(null!=this.flyToOptions){const s=function(t,e,r){const s={frameCorrelationId:{value:t},animation:r?{duration:I(r.milliseconds)}:void 0};switch(e.flyTo.type){case"supplied":return Object.assign(Object.assign({},s),{itemSuppliedId:e.flyTo.data});case"internal":return Object.assign(Object.assign({},s),{itemId:new v.protobuf.core.Uuid({hex:e.flyTo.data})});case"camera":return Object.assign(Object.assign({},s),{camera:m(e.flyTo.data)});case"bounding-box":return Object.assign(Object.assign({},s),{boundingBox:{xmin:e.flyTo.data.min.x,xmax:e.flyTo.data.max.x,ymin:e.flyTo.data.min.y,ymax:e.flyTo.data.max.y,zmin:e.flyTo.data.min.z,zmax:e.flyTo.data.max.z}});default:return{}}}(n,this.flyToOptions,null==t?void 0:t.animation),o=await this.stream.flyTo(s,!0);return new V(this.stream,this.decodeFrame,{correlationId:n,animationId:(null===(r=null===(e=o.flyTo)||void 0===e?void 0:e.animationId)||void 0===r?void 0:r.hex)||void 0},null!=(null===(i=null==t?void 0:t.animation)||void 0===i?void 0:i.milliseconds)?t.animation.milliseconds+1e4:void 0)}return this.stream.replaceCamera({camera:m(this.data),frameCorrelationId:{value:n}}),new V(this.stream,this.decodeFrame,{correlationId:n})}catch(t){throw console.warn("Error when performing render: ",t),t}}rotateAroundAxis(t,e){return this.rotateAroundAxisAtPoint(t,this.data.lookAt,e)}alignTo(t,e){const r=a.normalize(a.cross(this.up,a.normalize(this.viewVector))),s=a.normalize(a.cross(a.normalize(this.viewVector),r)),i=a.angleTo(e,s)>Math.PI/2?a.negate(s):s,n=a.isEqual(i,e)?r:a.normalize(a.cross(i,e)),o=a.transformMatrix(this.viewVector,c.makeRotation(l.fromAxisAngle(n,a.angleTo(e,i)))),u=d.create({origin:t,direction:a.normalize(o)}),h=d.at(u,a.magnitude(this.viewVector));return this.update({position:t,lookAt:h,up:e})}standardView(t){return this.update({position:t.position,viewVector:a.subtract(a.origin(),t.position),lookAt:a.origin(),up:t.up})}buildFlyToType(t){if(null!=t.boundingBox)return{type:"bounding-box",data:t.boundingBox};if(null!=t.camera)return{type:"camera",data:t.camera};if(null!=t.itemId)return{type:"internal",data:t.itemId};if(null!=t.itemSuppliedId)return{type:"supplied",data:t.itemSuppliedId};throw new Error("Fly to must specify at least one option.")}computeClippingPlanes(t){return g(this.boundingBox,t)}}class _ extends U{constructor(t,e,r,s,i,n){super(t,e,r,s,i,n),this.perspectiveData=r}moveBy(t){return this.update({position:a.add(this.position,t),lookAt:a.add(this.lookAt,t)})}rotateAroundAxisAtPoint(t,e,r){return this.update({position:a.rotateAboutAxis(t,this.position,r,e),lookAt:a.rotateAboutAxis(t,this.lookAt,r,e),up:a.rotateAboutAxis(t,this.up,r,a.origin())})}fitToBoundingBox(t){var e;const r=1.1*a.magnitude(a.subtract(t.max,u.center(t)));let s=Math.tan(.008726646259972*(null!==(e=this.fovY)&&void 0!==e?e:45));this.aspect<1&&(s*=this.aspect);const i=Math.abs(r/s);return super.fitCameraToBoundingBox(t,i,this.viewVector)}update(t){var e;const r=null!==(e=t.fovY)&&void 0!==e?e:this.fovY;return new _(this.stream,this.aspect,Object.assign(Object.assign(Object.assign({},this.perspectiveData),t),{fovY:r}),this.boundingBox,this.decodeFrame,this.flyToOptions)}toFrameCamera(){var t;return new y(this.position,this.lookAt,this.up,this.near,this.far,this.aspectRatio,null!==(t=this.fovY)&&void 0!==t?t:45)}get viewVector(){return a.subtract(this.lookAt,this.position)}get position(){return Object.assign({},this.perspectiveData.position)}get up(){return Object.assign({},this.perspectiveData.up)}get lookAt(){return Object.assign({},this.perspectiveData.lookAt)}get fovY(){return this.perspectiveData.fovY}get aspectRatio(){return this.aspect}get near(){const{near:t}=this.computeClippingPlanes(this.perspectiveData);return t}get far(){const{far:t}=this.computeClippingPlanes(this.perspectiveData);return t}updateFlyToOptions(t){return new _(this.stream,this.aspect,this.perspectiveData,this.boundingBox,this.decodeFrame,t)}}class D extends U{constructor(t,e,r,s,i,n){super(t,e,r,s,i,n),this.orthographicData=r}moveBy(t){return this.update({lookAt:a.add(this.lookAt,t)})}rotateAroundAxisAtPoint(t,e,r){const s=a.rotateAboutAxis(t,this.lookAt,r,e),i=a.rotateAboutAxis(t,this.position,r,e),n=f(a.subtract(s,i),h.create(this.boundingBox));return this.update({viewVector:n,lookAt:s,up:a.rotateAboutAxis(t,this.up,r,a.origin())})}fitToBoundingBox(t){const e=h.create(t),r=super.fitCameraToBoundingBox(t,e.radius,this.viewVector);return this.update({lookAt:r.lookAt,viewVector:r.viewVector,fovHeight:2*e.radius})}update(t){return new D(this.stream,this.aspect,Object.assign(Object.assign({},this.orthographicData),t),this.boundingBox,this.decodeFrame,this.flyToOptions)}toFrameCamera(){return new b(f(this.viewVector,h.create(this.boundingBox)),this.lookAt,this.up,this.near,this.far,this.aspectRatio,this.fovHeight)}get viewVector(){return Object.assign({},this.orthographicData.viewVector)}get position(){return a.add(this.lookAt,a.negate(this.viewVector))}get up(){return Object.assign({},this.orthographicData.up)}get lookAt(){return Object.assign({},this.orthographicData.lookAt)}get fovHeight(){return this.orthographicData.fovHeight}get aspectRatio(){return this.aspect}get near(){const{near:t}=this.computeClippingPlanes(this.orthographicData);return t}get far(){const{far:t}=this.computeClippingPlanes(this.orthographicData);return t}updateFlyToOptions(t){return new D(this.stream,this.aspect,this.orthographicData,this.boundingBox,this.decodeFrame,t)}}class F{constructor(t,e){this.stream=t,this.imageScaleProvider=e}async hitItems(t,e){const r=this.imageScaleProvider();return(await this.stream.hitItems({point:p.scale(t,(null==r?void 0:r.x)||1,(null==r?void 0:r.y)||1),includeMetadata:null==e?void 0:e.includeMetadata},!0)).hitItems||void 0}}class N{constructor(t,e){this.stream=t,this.data=e}async update(t){return(await this.stream.updateCrossSectioning({crossSectioning:t},!0)).updateCrossSectioning||void 0}current(){return this.data}}class z{constructor(t=[]){this.operations=t}build(){return this.operations.concat()}materialOverride(t){return new z(this.operations.concat([{type:"change-material",material:t}]))}show(){return new z(this.operations.concat([{type:"show"}]))}hide(){return new z(this.operations.concat([{type:"hide"}]))}select(){return new z(this.operations.concat([{type:"select"}]))}deselect(){return new z(this.operations.concat([{type:"deselect"}]))}clearMaterialOverrides(){return new z(this.operations.concat([{type:"clear-override"}]))}transform(t){return new z(this.operations.concat([{type:"change-transform",transform:t}]))}clearTransforms(t=!0){return new z(this.operations.concat([{type:"clear-transform",cascade:t}]))}}class P{constructor(t){this.inverted=t}build(){return this.inverted?{type:"not",query:this.queryExpressionBuilder()}:this.queryExpressionBuilder()}}class H{constructor(t=!1){this.inverted=t}all(){return new L}not(){return new Y(!this.inverted)}withItemIds(t){return new W(t,"item-id",this.inverted)}withSuppliedIds(t){return new W(t,"supplied-id",this.inverted)}withItemId(t){return new X({type:"item-id",value:t},this.inverted)}withSuppliedId(t){return new X({type:"supplied-id",value:t},this.inverted)}withSceneTreeRange(t){return new Q(t,this.inverted)}withMetadata(t,e,r){return new $(t,e,r,this.inverted)}withSelected(){return new G(this.inverted)}withPoint(t){return new J(t,this.inverted)}withVolumeIntersection(t,e){return new K(t,this.inverted,e)}}class Y extends H{constructor(t){super(t)}}class L extends P{constructor(t=!1){super(t)}queryExpressionBuilder(){return{type:"all"}}}class Q extends P{constructor(t,e){super(e),this.range=t}queryExpressionBuilder(){return{type:"scene-tree-range",range:this.range}}}class $ extends P{constructor(t,e,r,s){super(s),this.filter=t,this.keys=e,this.exactMatch=r}queryExpressionBuilder(){return{type:"metadata",filter:this.filter,keys:this.keys,exactMatch:this.exactMatch}}}class G extends P{constructor(t){super(t)}queryExpressionBuilder(){return{type:"all-selected"}}}class J extends P{constructor(t,e){super(e),this.point=t}queryExpressionBuilder(){return{type:"point",point:this.point}}}class K extends P{constructor(t,e,r){super(e),this.rectangle=t,this.exclusive=r}queryExpressionBuilder(){return{type:"volume-intersection",rectangle:this.rectangle,exclusive:!!this.exclusive}}}class W extends P{constructor(t,e,r){super(r),this.ids=t,this.type=e}queryExpressionBuilder(){return{type:"or",expressions:this.ids.map((t=>({type:this.type,value:t})))}}}class X extends P{constructor(t,e){super(e),this.query=t}queryExpressionBuilder(){return Object.assign({},this.query)}and(){return new tt([this.query],this.inverted)}or(){return new Z([this.query],this.inverted)}}class Z extends P{constructor(t,e){super(e),this.expressions=t}queryExpressionBuilder(){return{type:"or",expressions:[...this.expressions]}}withItemId(t){return new Z([...this.expressions,{type:"item-id",value:t}],this.inverted)}withSuppliedId(t){return new Z([...this.expressions,{type:"supplied-id",value:t}],this.inverted)}or(){return this}}class tt extends P{constructor(t,e){super(e),this.expressions=t}queryExpressionBuilder(){return{type:"and",expressions:[...this.expressions]}}withItemId(t){return new tt([...this.expressions,{type:"item-id",value:t}],this.inverted)}withSuppliedId(t){return new tt([...this.expressions,{type:"supplied-id",value:t}],this.inverted)}and(){return this}}class et{where(t){const e=t(new H).build();return new rt(e)}}class rt{constructor(t,e){this.query=t,this.builder=null!=e?e:new z}materialOverride(t){return new rt(this.query,this.builder.materialOverride("string"==typeof t?j(t):t))}hide(){return new rt(this.query,this.builder.hide())}show(){return new rt(this.query,this.builder.show())}select(){return new rt(this.query,this.builder.select())}deselect(){return new rt(this.query,this.builder.deselect())}clearMaterialOverrides(){return new rt(this.query,this.builder.clearMaterialOverrides())}transform(t){if(Array.isArray(t)){if(16!==t.length)throw new o("Matrix provided must contain exactly 16 values (4x4).");return new rt(this.query,this.builder.transform({r0:{x:t[0],y:t[1],z:t[2],w:t[3]},r1:{x:t[4],y:t[5],z:t[6],w:t[7]},r2:{x:t[8],y:t[9],z:t[10],w:t[11]},r3:{x:t[12],y:t[13],z:t[14],w:t[15]}}))}return new rt(this.query,this.builder.transform(t))}clearTransforms(t=!0){return new rt(this.query,this.builder.clearTransforms(t))}build(){return{query:this.query,operations:this.builder.build()}}}class st{constructor(t,e,r,s){this.sceneViewId=t,this.stream=e,this.dimensions=r,this.queryOperations=s}async execute(t){const e=this.queryOperations.map((t=>function(t,e,r){const s=function(t){return t.map((t=>{switch(t.type){case"change-material":return{changeMaterial:{material:{d:t.material.opacity,ns:t.material.glossiness,ka:t.material.ambient,kd:t.material.diffuse,ks:t.material.specular,ke:t.material.emissive}}};case"clear-override":return{changeMaterial:{}};case"change-transform":return{changeTransform:{transform:Object.assign({},t.transform)}};case"clear-transform":return{clearTransform:{cascade:t.cascade}};case"hide":return{changeVisibility:{visible:!1}};case"show":return{changeVisibility:{visible:!0}};case"select":return{changeSelection:{selected:!0}};case"deselect":return{changeSelection:{selected:!1}};default:return{}}}))}(e);return{queryExpression:q(t,r),operationTypes:s}}(t.query,t.operations,{dimensions:this.dimensions}))),r={sceneViewId:{hex:this.sceneViewId},operations:e,suppliedCorrelationId:null!=(null==t?void 0:t.suppliedCorrelationId)?{value:null==t?void 0:t.suppliedCorrelationId}:void 0};await this.stream.createSceneAlteration(r)}}class it{constructor(t,e,r,s,i,n,o){this.stream=t,this.frame=e,this.decodeFrame=r,this.imageScaleProvider=s,this.dimensions=i,this.sceneId=n,this.sceneViewId=o}async applySceneViewState(t,e={}){const r=E(t);return await this.stream.loadSceneViewState(Object.assign(Object.assign({},r),{frameCorrelationId:e.suppliedCorrelationId?{value:e.suppliedCorrelationId}:void 0}),!0)}async applyPartialSceneViewState(t,e,r={}){const s=E(t),i=e.map((t=>{switch(t){case"camera":return v.protobuf.stream.SceneViewStateFeature.SCENE_VIEW_STATE_FEATURE_CAMERA;case"material_overrides":return v.protobuf.stream.SceneViewStateFeature.SCENE_VIEW_STATE_FEATURE_MATERIAL_OVERRIDE;case"selection":return v.protobuf.stream.SceneViewStateFeature.SCENE_VIEW_STATE_FEATURE_SELECTION;case"visibility":return v.protobuf.stream.SceneViewStateFeature.SCENE_VIEW_STATE_FEATURE_VISIBILITY;case"transforms":return v.protobuf.stream.SceneViewStateFeature.SCENE_VIEW_STATE_FEATURE_TRANSFORM;case"cross_section":return v.protobuf.stream.SceneViewStateFeature.SCENE_VIEW_STATE_FEATURE_CROSS_SECTION;default:return v.protobuf.stream.SceneViewStateFeature.SCENE_VIEW_STATE_FEATURE_INVALID}}));return await this.stream.loadSceneViewState(Object.assign(Object.assign({},s),{frameCorrelationId:r.suppliedCorrelationId?{value:r.suppliedCorrelationId}:void 0,sceneViewStateFeatureSubset:i}),!0)}async reset(t={}){return await this.stream.resetSceneView({includeCamera:t.includeCamera,frameCorrelationId:t.suppliedCorrelationId?{value:t.suppliedCorrelationId}:void 0},!0)}items(t){const e=t(new et),r=(Array.isArray(e)?e:[e]).reduce(((t,e)=>t.concat(e.build())),[]);return new st(this.sceneViewId,this.stream,this.dimensions,r)}camera(){const{scene:t}=this.frame;if(t.camera.isOrthographic())return new D(this.stream,w.aspectRatio(this.viewport()),{viewVector:t.camera.viewVector,lookAt:t.camera.lookAt,up:t.camera.up,fovHeight:t.camera.fovHeight},this.frame.scene.boundingBox,this.decodeFrame);if(t.camera.isPerspective())return new _(this.stream,w.aspectRatio(this.viewport()),{position:t.camera.position,lookAt:t.camera.lookAt,up:t.camera.up,fovY:t.camera.fovY},this.frame.scene.boundingBox,this.decodeFrame);throw new n("Cannot retrieve camera. Scene has an unknown or invalid camera type.")}boundingBox(){return this.frame.scene.boundingBox}crossSectioning(){return new N(this.stream,this.frame.scene.crossSection)}raycaster(){return new F(this.stream,this.imageScaleProvider)}viewport(){return this.frame.dimensions}scale(){return this.imageScaleProvider()||p.create(1,1)}}export{it as S,k as a,S as c,B as f,T as l}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
/**!
|
|
2
2
|
* Copyright (c) 2023 Vertex Software LLC. All rights reserved.
|
|
3
3
|
*/
|
|
4
|
-
import{r as t,c as i,h as s,H as e,g as n}from"./p-d6fce4c1.js";import{p as h,v as o,c as a,f as r,r as l,b as c,s as d,d as u}from"./p-d216a866.js";import{t as v,p as w,S as f,a as p,c as m,W as g}from"./p-934cbb97.js";import{E as y,m as C,c as b,o as I,u as P,a as T,b as D}from"./p-fc7d8c03.js";import{c as S}from"./p-07aeee89.js";import{p as x}from"./p-a12791aa.js";import{C as k}from"./p-1812c82d.js";import{g as E,c as O}from"./p-42760392.js";import{c as M,C as j,W as R,S as A,V as F,d as z,e as B,f as L}from"./p-440c8174.js";import{k as N,l as K,m as $,t as H,n as W,o as V,p as q,q as U,r as G,s as _,u as J,x as X,y as Y}from"./p-46f40a43.js";import{E as Q}from"./p-df8fbe56.js";import{V as Z}from"./p-0a017be7.js";import{f as tt,a as it,S as st}from"./p-bd314501.js";import"./p-dfe5a97d.js";class et{constructor(t){this.viewer=t,this.handleInteractionStarted=()=>{this.invalidateStencilBuffer(),this.pendingInteractionFinished=new Promise((t=>{this.pendingInteractionFinishedResolver=t}))},this.handleInteractionFinished=()=>{var t;null===(t=this.pendingInteractionFinishedResolver)||void 0===t||t.call(this),this.pendingInteractionFinished=void 0,this.pendingInteractionFinishedResolver=void 0},this.invalidateStencilBuffer=()=>{this.pendingStencilBuffer=void 0},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()?await this.viewer.scene():void 0,s=null!=i&&(i.crossSectioning().current().sectionPlanes.length>0||null!=this.viewer.featureLines),e=null===(t=this.viewer.frame)||void 0===t?void 0:t.scene.camera;if(s&&null!=this.viewer.stream&&null!=e){const t=await this.viewer.stream.getStencilBuffer({includeDepthBuffer:!0}),{stencilBuffer:i,depthBuffer:s,imageAttributes:n}=N(t),[h,o]=await Promise.all([K(new Uint8Array(i)),K(new Uint8Array(s))]);return nt.fromPng(h,n,i,$.fromPng(o,e,n))}}latest(){return null==this.pendingStencilBuffer&&(this.pendingStencilBuffer=this.fetch()),this.pendingStencilBuffer}async latestAfterInteraction(){return await this.pendingInteractionFinished,this.latest()}}class nt{constructor(t,i,s,e,n){this.imageAttr=t,this.imageBytes=i,this.pixelBytes=s,this.imageChannels=e,this.depthBuffer=n}static fromPng(t,i,s,e){if(t.data instanceof Uint8Array){if(1!==t.channels)throw new Error("Expected stencil PNG to have 1 color channel");return new nt(i,s,t.data,t.channels,e)}throw new Error("Expected stencil PNG to have depth of 8-bit")}getValue(t){const{width:i,height:s}=this.imageAttr.imageRect,e=h.subtract(t,this.imageAttr.imageRect),n=1/this.imageAttr.imageScale,o=h.scale(e,n,n);if(o.x>=0&&o.y>=0&&o.x<i&&o.y<s){const t=Math.floor(o.x)+Math.floor(o.y)*i;return this.pixelBytes[t]}return 0}hitTest(t){return 0!==this.getValue(t)}snapToNearestPixel(t,i,s=(()=>!0)){const e=2*i,n=h.create(t.x-i,t.y-i),o=[];for(let a=0;a<e*e;a++){const r=a%e,l=Math.floor(a/e),c=h.add(n,{x:r,y:l});if(h.distance(c,t)<=i){const t=this.getValue(c);255===t&&s(t)&&o.push(c)}}const a=o.sort(((i,s)=>h.distance(i,t)-h.distance(s,t)))[0];return null!=a?h.create(Math.floor(a.x)+.5,Math.floor(a.y)+.5):t}}class ht{constructor(t,i,s){this.stream=t,this.configProvider=i,this.imageScaleProvider=s}predicate(t){return t.altKey&&!t.shiftKey}async fn(t){var i;const s=this.imageScaleProvider(),e=await this.stream.hitItems({point:h.scale(t.position,(null==s?void 0:s.x)||1,(null==s?void 0:s.y)||1)},!0);null!=(null===(i=e.hitItems)||void 0===i?void 0:i.hits)&&e.hitItems.hits.length>0?await this.stream.flyTo({itemId:e.hitItems.hits[0].itemId,animation:{duration:v(this.configProvider().animation.durationMs)}}):console.debug(`No hit results found for fly to part [position={x: ${t.position.x}, y: ${t.position.y}}]`)}}class ot{constructor(t,i,s,e,n,h,o,a,r,l,c){this.stream=t,this.cursors=i,this.getConfig=s,this.getScene=e,this.getFrame=n,this.getViewport=h,this.tapEmitter=o,this.doubleTapEmitter=a,this.longPressEmitter=r,this.interactionStartedEmitter=l,this.interactionFinishedEmitter=c,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(),s=this.getFrame();if(null==s)throw new Error("Cannot get world point. Frame is undefined.");const e=await s.depthBuffer();return null!=e?i.transformPointToWorldSpace(t,e,.5):void 0}async getEntityTypeAtPoint(t){var i;const s=this.getViewport(),e=await(null===(i=this.getFrame())||void 0===i?void 0:i.featureMap());if(null!=e){const i=s.transformPointToFrame(t,e);return e.getEntityType(i)}return Q.NO_GEOMETRY}getRayFromPoint(t){const i=this.getViewport(),s=this.getFrame();if(null!=s)return i.transformPointToRay(t,s.image,s.scene.camera);throw new Error("Cannot get camera. Frame is undefined.")}async tap(t,i={},s=0){this.emitTapEvent(this.tapEmitter.emit,t,i,s)}async doubleTap(t,i={},s=0){this.emitTapEvent(this.doubleTapEmitter.emit,t,i,s)}async longPress(t,i={},s=0){this.emitTapEvent(this.longPressEmitter.emit,t,i,s)}async beginInteraction(){this.isInteracting()||(this.interactionStartedEmitter.emit(),this.currentCamera=this.getScene().camera(),await this.stream.beginInteraction())}async transformCamera(t){var i;if(this.isInteracting()){const s=this.getScene(),e=this.getViewport(),n=this.getFrame(),h=await(null==n?void 0:n.depthBuffer());this.currentCamera=null!=this.currentCamera&&null!=e&&null!=n?t({camera:this.currentCamera,viewport:e,scale:s.scale(),boundingBox:s.boundingBox(),frame:n,depthBuffer:h}):void 0,await(null===(i=this.currentCamera)||void 0===i?void 0:i.render())}}async twistCamera(...t){return this.transformCamera((({camera:i,viewport:s})=>{const e=o.normalize(o.subtract(i.lookAt,i.position));if(1===t.length&&"number"==typeof t[0]){const s=a.toRadians(-t[0]);return i.rotateAroundAxis(s,e)}if(1===t.length){const e=h.create(s.width/2,s.height/2),n=a.toDegrees(a.fromPoints(e,t[0])),r=null!=this.lastAngle?n-this.lastAngle:0;this.lastAngle=n;const l=o.normalize(o.subtract(i.lookAt,i.position)),c=a.toRadians(-r);return i.rotateAroundAxis(c,l)}return i}))}async panCameraToScreenPoint(t){return this.transformCamera((({camera:i,frame:s,viewport:e,depthBuffer:n})=>{if(null==this.panData){const h=i.toFrameCamera(),o=h.direction,a=e.transformPointToRay(t,s.image,h),c=r.fromNormalAndCoplanarPoint(o,i.lookAt),d=l.intersectPlane(a,c);if(null==d)return console.warn("Cannot determine fallback for pan. Ray does not intersect plane."),i;const u=null!=n?this.getWorldPoint(t,n,d):d,v=r.fromNormalAndCoplanarPoint(o,u);this.panData={hitPt:u,hitPlane:v,startingCamera:h}}if(null!=this.panData){const{hitPt:n,hitPlane:h,startingCamera:a}=this.panData,r=e.transformPointToRay(t,s.image,a),c=l.intersectPlane(r,h);if(null!=c){const t=o.subtract(n,c);return i.update(a).moveBy(t)}}return i}))}async viewAll(){await this.getScene().camera().viewAll().render()}async rotateCamera(t){return this.transformCamera((({camera:i,viewport:s})=>{const e=o.normalize(i.up),n=o.normalize(o.subtract(i.lookAt,i.position)),h=o.cross(e,n),a=o.cross(n,h),r=o.normalize({x:t.x*h.x+t.y*a.x,y:t.x*h.y+t.y*a.y,z:t.x*h.z+t.y*a.z}),l=o.cross(r,n),c=3*Math.PI*t.x/s.width,d=3*Math.PI*t.y/s.height,u=Math.abs(c)+Math.abs(d);return i.rotateAroundAxis(u,l)}))}async rotateCameraAtPoint(t,i){return this.transformCamera((({camera:s,viewport:e,boundingBox:n,depthBuffer:h})=>{if(null==this.worldRotationPoint){const t=c.center(n);this.worldRotationPoint=null!=h?this.getWorldPoint(i,h,t):s.lookAt}const a=o.normalize(s.up),r=o.normalize(o.subtract(s.lookAt,s.position)),l=o.cross(a,r),d=o.cross(r,l),u=o.normalize({x:t.x*l.x+t.y*d.x,y:t.x*l.y+t.y*d.y,z:t.x*l.z+t.y*d.z}),v=o.cross(u,r),w=3*Math.PI*t.x/e.width,f=3*Math.PI*t.y/e.height,p=Math.abs(w)+Math.abs(f),m=s.rotateAroundAxisAtPoint(p,this.worldRotationPoint,v);return m.update({lookAt:o.add(o.scale(Math.abs(s.signedDistanceToBoundingBoxCenter())/o.magnitude(m.viewVector),m.viewVector),m.position)})}))}async zoomCamera(t){return this.transformCamera((({camera:i,viewport:s})=>{const e=i.viewVector,n=o.normalize(e),h=o.magnitude(e),a=o.add(i.position,o.scale(3*h*t/s.height,n));return i.update({position:a})}))}async zoomCameraToPoint(t,i){return this.transformCamera((({camera:s,viewport:e,frame:n,depthBuffer:h})=>{const a=n.scene.camera,c=a.direction,d=s.toFrameCamera(),u=e.transformPointToRay(t,n.image,d);if(null==this.zoomData){const i=r.fromNormalAndCoplanarPoint(c,a.lookAt),e=l.intersectPlane(u,i);if(null==e)return console.warn("Cannot determine fallback point for zoom. Ray does not intersect plane."),s;const n=null!=h?this.getWorldPoint(t,h,e):e,o=r.fromNormalAndCoplanarPoint(c,n);this.zoomData={hitPt:n,hitPlane:o}}if(null!=this.zoomData){const{hitPt:t,hitPlane:n}=this.zoomData,h=o.distance(s.position,t),a=l.at(u,6*h*i/e.height),c=r.projectPoint(n,a),d=s.update({position:a,lookAt:c});if(o.distance(a,c)>=d.near)return d}return s}))}async pivotCamera(t,i){return this.transformCamera((({camera:s})=>{const{position:e,up:n,lookAt:h}=s,r=o.normalize(n),l=o.normalize(s.viewVector),c=o.cross(r,l),d=o.cross(l,c),u=o.rotateAboutAxis(a.toRadians(t),h,c,e),v=o.rotateAboutAxis(a.toRadians(i),u,d,e);return s.update(Object.assign(Object.assign({},s),{lookAt:v}))}))}async endInteraction(){this.isInteracting()&&(this.currentCamera=void 0,this.worldRotationPoint=void 0,this.panData=void 0,this.zoomData=void 0,this.resetLastAngle(),this.interactionFinishedEmitter.emit(),await this.stream.endInteraction())}resetLastAngle(){this.lastAngle=void 0}isInteracting(){return null!=this.currentCamera}pixelThreshold(t){return(this.isCoarseInputDevice(t)?this.getConfig().coarsePointerThreshold:this.getConfig().finePointerThreshold)*window.devicePixelRatio}async hitItems(t){var i;const s=await this.getScene().raycaster().hitItems(t);return null!==(i=null==s?void 0:s.hits)&&void 0!==i?i:[]}emitTapEvent(t,i,s={},e=0){const{altKey:n=!1,ctrlKey:h=!1,metaKey:o=!1,shiftKey:a=!1}=s;t({position:i,altKey:n,ctrlKey:h,metaKey:o,shiftKey:a,buttons:e})}isCoarseInputDevice(t){return t||window.matchMedia("(pointer: coarse)").matches}getWorldPoint(t,i,s){const e=this.getViewport(),n=e.transformPointToFrame(t,i);return i.hitTest(n)?e.transformPointToWorldSpace(t,i):s}}class at extends ot{constructor(t,i,s,e,n,h,o,a,r,l,c){super(t,i,s,e,n,h,o,a,r,l,c)}async getWorldPointFromViewport(t){const i=this.getViewport(),s=this.getFrame();if(null==s)throw new Error("Cannot get world point. Frame is undefined.");const e=await s.depthBuffer();return null!=e?i.transformPointToOrthographicWorldSpace(t,e,.5):void 0}async panCameraByDelta(t){return this.transformCamera((({camera:i,viewport:s})=>{const e=i.viewVector,n=o.normalize(i.up),h=o.normalize(e),a=o.magnitude(e)*Math.tan(i.fovHeight),r=t.x*a/s.width,l=t.y/s.width*a,c=o.cross(n,h),d=o.cross(h,c),u=o.add(o.scale(r,c),o.scale(l,d));return i.moveBy(u)}))}async panCameraToScreenPoint(t){return this.transformCamera((({camera:i,frame:s,viewport:e})=>{if(null==this.panData){const n=i.toFrameCamera(),h=n.direction,o=e.transformPointToOrthographicRay(t,s.image,n),a=r.fromNormalAndCoplanarPoint(h,i.lookAt),c=l.intersectPlane(o,a);if(null==c)return console.warn("Cannot determine fallback for pan. Ray does not intersect plane."),i;this.panData={hitPt:c,hitPlane:a,startingCamera:n}}if(null!=this.panData){const{hitPt:n,hitPlane:h,startingCamera:a}=this.panData,r=e.transformPointToOrthographicRay(t,s.image,a),c=l.intersectPlane(r,h);if(null!=c){const t=o.subtract(n,c);return i.update({lookAt:o.add(a.lookAt,t)})}}return i}))}async zoomCameraToPoint(t,i){return this.transformCamera((({camera:s,viewport:e,frame:n,depthBuffer:a})=>{if(null==this.orthographicZoomData||h.distance(t,this.orthographicZoomData.startingScreenPt)>2){const i=s.toFrameCamera(),h=i.direction,o=e.transformPointToOrthographicRay(t,n.image,i),c=r.fromNormalAndCoplanarPoint(h,i.lookAt),d=l.intersectPlane(o,c);if(null==d)return console.warn("Cannot determine fallback point for zoom. Ray does not intersect plane."),s;const u=null!=a?this.getWorldPoint(t,a,d):d,v=r.fromNormalAndCoplanarPoint(h,u);this.orthographicZoomData={hitPt:u,hitPlane:v,startingScreenPt:t}}if(null!=this.orthographicZoomData){const{hitPt:t,hitPlane:n}=this.orthographicZoomData,h=s.fovHeight/e.height*2*i,a=Math.max(1,s.fovHeight-h),l=r.projectPoint(n,s.lookAt),c=o.scale((s.fovHeight-a)/s.fovHeight,o.subtract(t,l));return s.update({lookAt:o.add(s.lookAt,c),fovHeight:Math.max(1,s.fovHeight-h)})}return s}))}getWorldPoint(t,i,s){const e=this.getViewport(),n=e.transformPointToFrame(t,i);return i.hitTest(n)?e.transformPointToOrthographicWorldSpace(t,i):s}async transformCamera(t){var i;if(this.isInteracting()){const s=this.getScene(),e=this.getViewport(),n=this.getFrame(),h=await(null==n?void 0:n.depthBuffer());this.currentCamera=null!=this.currentCamera&&null!=e&&null!=n?t({camera:this.currentCamera,viewport:e,scale:s.scale(),boundingBox:s.boundingBox(),frame:n,depthBuffer:h}):void 0,await(null===(i=this.currentCamera)||void 0===i?void 0:i.render())}}}class rt extends ot{constructor(t,i,s,e,n,h,o,a,r,l,c){super(t,i,s,e,n,h,o,a,r,l,c)}async panCameraByDelta(t){return this.transformCamera((({camera:i,viewport:s})=>{var e;const n=i.viewVector,h=o.normalize(i.up),a=o.normalize(n),r=o.magnitude(n)*Math.tan(null!==(e=i.fovY)&&void 0!==e?e:45),l=t.x*r/s.width,c=t.y/s.width*r,d=o.cross(h,a),u=o.cross(a,d),v=o.add(o.scale(l,d),o.scale(c,u));return i.moveBy(v)}))}async transformCamera(t){var i;if(this.isInteracting()){const s=this.getScene(),e=this.getViewport(),n=this.getFrame(),h=await(null==n?void 0:n.depthBuffer());this.currentCamera=null!=this.currentCamera&&null!=e&&null!=n?t({camera:this.currentCamera,viewport:e,scale:s.scale(),boundingBox:s.boundingBox(),frame:n,depthBuffer:h}):void 0,await(null===(i=this.currentCamera)||void 0===i?void 0:i.render())}}}class lt{constructor(t,i,s,e){this.stream=t,this.configProvider=i,this.imageScaleProvider=s,this.sceneProvider=e}predicate(t){return t.altKey&&t.shiftKey}async fn(t){var i,s;const e=this.imageScaleProvider(),n=await this.stream.hitItems({point:h.scale(t.position,(null==e?void 0:e.x)||1,(null==e?void 0:e.y)||1)},!0);if(null!=(null===(i=n.hitItems)||void 0===i?void 0:i.hits)&&n.hitItems.hits.length>0&&null!=n.hitItems.hits[0].hitPoint){const i=this.sceneProvider().camera(),e=n.hitItems.hits[0];null!=e.hitPoint&&null!=e.hitPoint.x&&null!=e.hitPoint.y&&null!=e.hitPoint.z?await this.stream.flyTo({camera:H(i.update({lookAt:o.create(e.hitPoint.x,e.hitPoint.y,e.hitPoint.z)}).toFrameCamera()),animation:{duration:v(this.configProvider().animation.durationMs)}}):console.debug(`No hit position found for fly to position [position={x: ${t.position.x}, y: ${t.position.y}}, hit-id={${null===(s=e.itemId)||void 0===s?void 0:s.hex}}]`)}else console.debug(`No hit results found for fly to position [position={x: ${t.position.x}, y: ${t.position.y}}]`)}}const ct=[.2,.15,.25,.25,.15];class dt{constructor(t,i,s,e,n,h,o,a,r,l){this.downEvent=t,this.upEvent=i,this.moveEvent=s,this.rotateInteraction=e,this.rotatePointInteraction=n,this.zoomInteraction=h,this.panInteraction=o,this.twistInteraction=a,this.pivotInteraction=r,this.getConfig=l,this.primaryInteraction=this.rotateInteraction,this.isDragging=!1,this.keyboardControls=!1,this.disableIndividualInteractions=!1,this.primaryInteractionTypeChange=new y,this.handleDownEvent=this.handleDownEvent.bind(this),this.handleMouseWheel=this.handleMouseWheel.bind(this),this.handleWindowMove=this.handleWindowMove.bind(this),this.handleWindowUp=this.handleWindowUp.bind(this),this.handleDoubleClick=this.handleDoubleClick.bind(this)}initialize(t,i){this.element=t,this.interactionApi=i,t.addEventListener(this.downEvent,this.handleDownEvent),t.addEventListener("mousedown",this.handleDoubleClick),t.addEventListener("wheel",this.handleMouseWheel)}dispose(){var t,i,s;null===(t=this.element)||void 0===t||t.removeEventListener(this.downEvent,this.handleDownEvent),null===(i=this.element)||void 0===i||i.removeEventListener("mousedown",this.handleDoubleClick),null===(s=this.element)||void 0===s||s.removeEventListener("wheel",this.handleMouseWheel),this.element=void 0}onPrimaryInteractionTypeChange(t){return this.primaryInteractionTypeChange.on(t)}setCurrentInteractionType(t){var i;switch(t){case"rotate":this.currentInteraction=this.rotateInteraction;break;case"zoom":this.currentInteraction=this.zoomInteraction;break;case"pan":this.currentInteraction=this.panInteraction;break;case"twist":this.currentInteraction=this.twistInteraction;break;case"rotate-point":this.currentInteraction=this.rotatePointInteraction;break;case"pivot":this.currentInteraction=this.pivotInteraction;break;default:this.currentInteraction=void 0}if(this.draggingInteraction){const t=this.draggingInteraction.getPosition();this.draggingInteraction=this.currentInteraction||this.primaryInteraction,null===(i=this.interactionApi)||void 0===i||i.resetLastAngle(),this.draggingInteraction.setPosition(t)}}getPrimaryInteractionType(){return this.primaryInteraction.getType()}getCurrentInteractionType(){return(this.currentInteraction||this.primaryInteraction).getType()}setPrimaryInteractionType(t){switch(t){case"rotate":this.primaryInteraction=this.rotateInteraction,this.lastPrimaryRotateInteraction=this.rotateInteraction;break;case"rotate-point":this.primaryInteraction=this.rotatePointInteraction,this.lastPrimaryRotateInteraction=this.rotatePointInteraction;break;case"zoom":this.primaryInteraction=this.zoomInteraction;break;case"pan":this.primaryInteraction=this.panInteraction;break;case"pivot":this.primaryInteraction=this.pivotInteraction}this.primaryInteractionTypeChange.emit()}setDefaultKeyboardControls(t){this.keyboardControls=t}handleDownEvent(t){t.preventDefault(),this.interactionTimer=window.setTimeout((()=>{this.downPosition=h.create(t.screenX,t.screenY),this.downPositionCanvas=this.getCanvasPosition(t),this.interactionTimer=void 0,null!=this.lastMoveEvent&&this.handleWindowMove(this.lastMoveEvent)}),this.getConfig().interactions.interactionDelay),window.addEventListener(this.moveEvent,this.handleWindowMove),window.addEventListener(this.upEvent,this.handleWindowUp)}handleWindowMove(t){if(null==this.interactionTimer){if(this.disableIndividualInteractions)return;const i=h.create(t.screenX,t.screenY),s=null!=this.interactionApi?this.interactionApi.pixelThreshold(this.isTouch(t)):2;null!=this.downPosition&&h.distance(i,this.downPosition)>=s&&!this.isDragging&&(this.beginDrag(t),this.isDragging=!0),this.isDragging&&this.drag(t)}this.lastMoveEvent=t}async handleWindowUp(t){this.isDragging&&(this.endDrag(t),this.isDragging=!1),null!=this.interactionTimer&&(window.clearTimeout(this.interactionTimer),this.interactionTimer=void 0),window.removeEventListener(this.moveEvent,this.handleWindowMove),window.removeEventListener(this.upEvent,this.handleWindowUp),this.lastMoveEvent=void 0}async handleDoubleClick(t){2===t.detail&&4===t.buttons&&null!=this.interactionApi&&this.interactionApi.viewAll()}beginDrag(t){var i;this.keyboardControls&&t.metaKey&&t.shiftKey?this.currentInteraction=this.rotatePointInteraction:this.keyboardControls&&t.shiftKey&&t.altKey?this.currentInteraction=this.twistInteraction:this.keyboardControls&&t.shiftKey?this.currentInteraction=this.zoomInteraction:this.keyboardControls&&(t.metaKey||t.ctrlKey)?this.currentInteraction=this.panInteraction:this.keyboardControls&&t.altKey&&(this.currentInteraction=this.rotateInteraction),1===t.buttons?this.draggingInteraction=this.currentInteraction||this.primaryInteraction:2===t.buttons?this.draggingInteraction=this.panInteraction:4===t.buttons&&(this.draggingInteraction=null!==(i=this.lastPrimaryRotateInteraction)&&void 0!==i?i:this.rotateInteraction),null!=this.draggingInteraction&&null!=this.interactionApi&&null!=this.element&&(this.zoomInteraction.endDrag(t,this.interactionApi),this.draggingInteraction.beginDrag(t,this.downPositionCanvas||h.create(t.clientX,t.clientY),this.interactionApi,this.element))}drag(t){this.currentInteraction=this.keyboardControls&&t.altKey&&t.shiftKey?this.twistInteraction:void 0,this.draggingInteraction=this.currentInteraction||this.draggingInteraction||this.primaryInteraction,null!=this.draggingInteraction&&null!=this.interactionApi&&this.draggingInteraction.drag(t,this.interactionApi)}endDrag(t){this.keyboardControls&&this.currentInteraction===this.twistInteraction&&(this.currentInteraction=void 0),null!=this.draggingInteraction&&null!=this.interactionApi&&(this.draggingInteraction.endDrag(t,this.interactionApi),this.draggingInteraction=void 0)}handleMouseWheel(t){if(t.preventDefault(),null!=this.element&&null!=this.interactionApi&&4!==t.buttons){const i=-this.wheelDeltaToPixels(t.deltaY,t.deltaMode)/10,s=this.element.getBoundingClientRect(),e=E(t,s);ct.forEach(((t,s)=>{window.setTimeout((()=>{null!=this.interactionApi&&this.zoomInteraction.zoomToPoint(e,i*t,this.interactionApi)}),2*s)}))}}wheelDeltaToPixels(t,i){null==this.computedBodyStyle&&(this.computedBodyStyle=window.getComputedStyle(document.body));const s=null==this.computedBodyStyle.fontSize||""===this.computedBodyStyle.fontSize||isNaN(parseFloat(this.computedBodyStyle.fontSize))?19.2:1.2*parseFloat(this.computedBodyStyle.fontSize);return 1===i?null==this.computedBodyStyle.lineHeight||""===this.computedBodyStyle.lineHeight||isNaN(parseFloat(this.computedBodyStyle.lineHeight))?t*s:t*parseFloat(this.computedBodyStyle.lineHeight):2===i?null==this.computedBodyStyle.height||""===this.computedBodyStyle.height||isNaN(parseFloat(this.computedBodyStyle.height))?t*window.innerHeight:t*parseFloat(this.computedBodyStyle.height):t}getCanvasPosition(t){var i;const s=null===(i=this.element)||void 0===i?void 0:i.getBoundingClientRect(),e=null!=s?h.create(s.left,s.top):void 0;return null!=e?h.subtract(h.create(t.clientX,t.clientY),e):void 0}isTouch(t){return null!=window.PointerEvent&&t instanceof PointerEvent&&"touch"===t.pointerType}}class ut{setPosition(t){this.currentPosition=t}getPosition(){return this.currentPosition}getType(){return this.type}beginDrag(t,i,s,e){}drag(t,i){}endDrag(t,i){null!=this.currentPosition&&(i.endInteraction(),this.currentPosition=void 0)}zoom(t,i){}}class vt extends ut{constructor(){super(...arguments),this.type="rotate"}beginDrag(t,i,s){null==this.currentPosition&&(this.currentPosition=h.create(t.screenX,t.screenY),s.beginInteraction())}drag(t,i){if(null!=this.currentPosition){const s=h.create(t.screenX,t.screenY),e=h.subtract(s,this.currentPosition);i.rotateCamera(e),this.currentPosition=s}}endDrag(t,i){super.endDrag(t,i)}}class wt extends ut{constructor(){super(...arguments),this.type="rotate-point"}beginDrag(t,i,s){null==this.currentPosition&&(this.currentPosition=h.create(t.screenX,t.screenY),this.startingPosition=i,s.beginInteraction())}drag(t,i){if(null!=this.currentPosition&&null!=this.startingPosition){const s=h.create(t.screenX,t.screenY),e=h.subtract(s,this.currentPosition);i.rotateCameraAtPoint(e,this.startingPosition),this.currentPosition=s}}endDrag(t,i){super.endDrag(t,i)}}class ft extends ut{constructor(t=1e3){super(),this.interactionTimeout=t,this.type="zoom",this.didTransformBegin=!1}beginDrag(t,i,s,e){if(null==this.currentPosition){this.currentPosition=h.create(t.clientX,t.clientY);const i=e.getBoundingClientRect(),n=E(t,i);this.startPt=n,s.beginInteraction()}}drag(t,i){if(null!=this.currentPosition){const s=h.create(t.clientX,t.clientY),e=h.subtract(s,this.currentPosition);null!=this.startPt&&(i.zoomCameraToPoint(this.startPt,e.y),this.currentPosition=s)}}endDrag(t,i){super.endDrag(t,i),this.stopInteractionTimer(),this.didTransformBegin=!1,this.startPt=void 0}zoom(t,i){this.operateWithTimer(i,(()=>i.zoomCamera(t)))}zoomToPoint(t,i,s){this.operateWithTimer(s,(()=>s.zoomCameraToPoint(t,i)))}beginInteraction(t){this.didTransformBegin=!0,t.beginInteraction()}endInteraction(t){this.didTransformBegin=!1,t.endInteraction()}resetInteractionTimer(t){this.stopInteractionTimer(),this.startInteractionTimer(t)}startInteractionTimer(t){this.interactionTimer=window.setTimeout((()=>{this.interactionTimer=void 0,this.endInteraction(t)}),this.interactionTimeout)}stopInteractionTimer(){null!=this.interactionTimer&&(window.clearTimeout(this.interactionTimer),this.interactionTimer=void 0)}operateWithTimer(t,i){this.didTransformBegin||this.beginInteraction(t),this.resetInteractionTimer(t),i()}}class pt extends ut{constructor(){super(...arguments),this.type="pan"}beginDrag(t,i,s,e){null==this.currentPosition&&(this.currentPosition=h.create(t.screenX,t.screenY),this.canvasRect=e.getBoundingClientRect(),s.beginInteraction())}drag(t,i){if(null!=this.currentPosition&&null!=this.canvasRect){const s=E(t,this.canvasRect);i.panCameraToScreenPoint(s),this.currentPosition=s}}endDrag(t,i){super.endDrag(t,i)}}class mt extends ut{constructor(){super(...arguments),this.type="twist"}beginDrag(t,i,s,e){this.currentPosition=h.create(t.offsetX,t.offsetY),this.canvasRect=e.getBoundingClientRect(),s.beginInteraction()}drag(t,i){const s=E(t,this.canvasRect);this.currentPosition=s,i.twistCamera(s)}endDrag(t,i){super.endDrag(t,i)}}class gt extends ut{constructor(){super(...arguments),this.type="pivot"}beginDrag(t,i,s){null==this.currentPosition&&(this.currentPosition=h.create(t.screenX,t.screenY),s.beginInteraction())}drag(t,i){if(null!=this.currentPosition){const s=h.create(t.screenX,t.screenY),e=h.subtract(s,this.currentPosition);i.pivotCamera(-.25*e.y,.25*e.x),this.currentPosition=s}}endDrag(t,i){super.endDrag(t,i)}}class yt extends dt{constructor(t,i=new vt,s=new wt,e=new ft,n=new pt,h=new mt,o=new gt){super("mousedown","mouseup","mousemove",i,s,e,n,h,o,t)}}class Ct{initialize(t,i){this.element=t,this.interactionApi=i}dispose(){this.element=void 0}handleTwoPointTouchMove(t,i){var s,e,n,o;if(null!=this.currentPosition1&&null!=this.currentPosition2){const r=h.scale(h.add(h.subtract(t,this.currentPosition1),h.subtract(i,this.currentPosition2)),.25,.25),l=.5*(h.distance(t,i)-h.distance(this.currentPosition1,this.currentPosition2)),c=d.create(h.subtract(this.currentPosition1,this.currentPosition2),h.subtract(t,i)),u=a.toDegrees(Math.atan2(d.determinant(c),d.dot(c)));null===(s=this.interactionApi)||void 0===s||s.beginInteraction(),null===(e=this.interactionApi)||void 0===e||e.zoomCamera(l),null===(n=this.interactionApi)||void 0===n||n.panCameraByDelta(r),Math.abs(u)>.5&&(null===(o=this.interactionApi)||void 0===o||o.twistCamera(u))}this.currentPosition1=t,this.currentPosition2=i}}class bt extends Ct{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;null===(t=this.element)||void 0===t||t.removeEventListener("pointerdown",this.handlePointerDown),super.dispose()}initialize(t,i){super.initialize(t,i),t.addEventListener("pointerdown",this.handlePointerDown)}handlePointerDown(t){const i=h.create(t.screenX,t.screenY);this.touchPoints=Object.assign(Object.assign({},this.touchPoints),{[t.pointerId]:i}),1===Object.keys(this.touchPoints).length&&(window.addEventListener("pointermove",this.handlePointerMove),window.addEventListener("pointerup",this.handlePointerUp))}handlePointerMove(t){null!=this.touchPoints[t.pointerId]&&(this.touchPoints[t.pointerId]=h.create(t.screenX,t.screenY));const i=Object.keys(this.touchPoints);2===i.length&&this.handleTwoPointTouchMove(this.touchPoints[i[0]],this.touchPoints[i[1]])}handlePointerUp(t){var i;delete this.touchPoints[t.pointerId];const s=Object.keys(this.touchPoints);1===s.length&&(null===(i=this.interactionApi)||void 0===i||i.endInteraction(),this.currentPosition1=void 0,this.currentPosition2=void 0),0===s.length&&(window.removeEventListener("pointermove",this.handlePointerMove),window.removeEventListener("pointerup",this.handlePointerUp))}}class It extends dt{constructor(t){super("pointerdown","pointerup","pointermove",new vt,new wt,new ft,new pt,new mt,new gt,t),this.touchPoints=new Set,this.handlePointerDown=this.handlePointerDown.bind(this),this.handlePointerUp=this.handlePointerUp.bind(this)}initialize(t,i){super.initialize(t,i),t.addEventListener("pointerdown",this.handlePointerDown)}handlePointerDown(t){this.downPosition=h.create(t.screenX,t.screenY),this.touchPoints.add(t.pointerId),1===this.touchPoints.size&&window.addEventListener("pointerup",this.handlePointerUp),2===this.touchPoints.size&&(this.disableIndividualInteractions=!0)}handlePointerUp(t){this.touchPoints.delete(t.pointerId),this.touchPoints.size<2&&(this.disableIndividualInteractions=!1),0===this.touchPoints.size&&window.removeEventListener("pointerup",this.handlePointerUp)}}class Pt{constructor(t,i,s,e){this.downEvent=t,this.upEvent=i,this.moveEvent=s,this.getConfig=e,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;null===(t=this.element)||void 0===t||t.removeEventListener(this.downEvent,this.handleDown),null===(i=this.element)||void 0===i||i.removeEventListener("touchstart",this.handleTouchStart),this.element=void 0,this.clearDoubleTapTimer(),this.clearLongPressTimer()}initialize(t,i){this.element=t,this.interactionApi=i,t.addEventListener(this.downEvent,this.handleDown),t.addEventListener("touchstart",this.handleTouchStart)}handleTouchStart(t){1===t.touches.length&&(this.setPointerPositions(h.create(t.touches[0].clientX,t.touches[0].clientY)),this.restartLongPressTimer(),window.addEventListener("touchend",this.handleTouchEnd),window.addEventListener("touchmove",this.handleTouchMove))}handleTouchMove(t){t.touches.length>0&&this.handlePointerMove(h.create(t.touches[0].clientX,t.touches[0].clientY),!0)}handleTouchEnd(t){null!=this.pointerDownPosition&&(window.removeEventListener("touchend",this.handleTouchEnd),window.removeEventListener("touchmove",this.handleTouchMove)),this.handlePointerEnd(this.pointerDownPosition)}handleDown(t){this.setPointerPositions(h.create(t.clientX,t.clientY)),this.buttons=t.buttons,this.restartLongPressTimer({altKey:t.altKey,ctrlKey:t.ctrlKey,metaKey:t.metaKey,shiftKey:t.shiftKey}),window.addEventListener(this.upEvent,this.handleUp),window.addEventListener(this.moveEvent,this.handleMove)}handleMove(t){this.handlePointerMove(h.create(t.clientX,t.clientY),this.isTouch(t))}handleUp(t){null!=this.pointerDownPosition&&(window.removeEventListener(this.upEvent,this.handleUp),window.removeEventListener(this.moveEvent,this.handleMove)),this.handlePointerEnd(h.create(t.clientX,t.clientY),{altKey:t.altKey,ctrlKey:t.ctrlKey,metaKey:t.metaKey,shiftKey:t.shiftKey},this.buttons,this.isTouch(t)),this.buttons=void 0}handlePointerMove(t,i){var s;const e=(null===(s=this.interactionApi)||void 0===s?void 0:s.pixelThreshold(i))||2;null!=this.pointerDownPosition&&h.distance(t,this.pointerDownPosition)>=e&&null==this.interactionTimer&&this.clearPositions()}handlePointerEnd(t,i={},s=0,e=!1){var n,h;null!=t&&(null!=this.longPressTimer&&this.emit(null===(n=this.interactionApi)||void 0===n?void 0:n.tap)(t,i,s),null!=this.doubleTapTimer&&null!=this.secondPointerDownPosition&&(this.emit(null===(h=this.interactionApi)||void 0===h?void 0:h.doubleTap)(t,i,s,this.secondPointerDownPosition),this.clearDoubleTapTimer())),this.pointerDownPosition=void 0,this.clearLongPressTimer()}emit(t){return(i,s={},e=0,n,o=!1)=>{var a;const r=n||this.pointerDownPosition,l=(null===(a=this.interactionApi)||void 0===a?void 0:a.pixelThreshold(o))||1;let c;null!=this.interactionTimer?c=this.getCanvasPosition(r||i):null!=r&&h.distance(r,i)<=l&&(c=this.getCanvasPosition(i)),null!=c&&null!=t&&t(c,s,e)}}getCanvasPosition(t){var i;const s=null===(i=this.element)||void 0===i?void 0:i.getBoundingClientRect(),e=null!=s?h.create(s.left,s.top):void 0;return null!=e?h.subtract(h.create(t.x,t.y),e):void 0}clearPositions(){this.pointerDownPosition=void 0,this.firstPointerDownPosition=void 0,this.secondPointerDownPosition=void 0,this.clearDoubleTapTimer(),this.clearLongPressTimer(),this.clearInteractionTimer()}clearDoubleTapTimer(){null!=this.doubleTapTimer&&window.clearTimeout(this.doubleTapTimer),this.doubleTapTimer=void 0,this.firstPointerDownPosition=void 0,this.secondPointerDownPosition=void 0}restartDoubleTapTimer(){this.clearDoubleTapTimer(),this.doubleTapTimer=window.setTimeout((()=>this.clearDoubleTapTimer()),this.getConfig().events.doubleTapThreshold)}clearLongPressTimer(){null!=this.longPressTimer&&window.clearTimeout(this.longPressTimer),this.longPressTimer=void 0}restartLongPressTimer(t={}){this.clearLongPressTimer(),this.longPressTimer=window.setTimeout((()=>{var i;this.pointerDownPosition&&this.emit(null===(i=this.interactionApi)||void 0===i?void 0:i.longPress)(this.pointerDownPosition,t,this.buttons),this.clearLongPressTimer()}),this.getConfig().events.longPressThreshold)}restartInteractionTimer(){this.clearInteractionTimer(),this.interactionTimer=window.setTimeout((()=>{this.interactionTimer=void 0}),this.getConfig().interactions.interactionDelay)}clearInteractionTimer(){null!=this.interactionTimer&&(window.clearTimeout(this.interactionTimer),this.interactionTimer=void 0)}setPointerPositions(t){this.pointerDownPosition=t,this.restartInteractionTimer(),null==this.firstPointerDownPosition?(this.restartDoubleTapTimer(),this.firstPointerDownPosition=t):this.secondPointerDownPosition=t}isTouch(t){return null!=window.PointerEvent&&t instanceof PointerEvent&&"touch"===t.pointerType}}class Tt extends Ct{constructor(){super(),this.handleTouchStart=this.handleTouchStart.bind(this),this.handleTouchMove=this.handleTouchMove.bind(this),this.handleTouchEnd=this.handleTouchEnd.bind(this)}dispose(){var t;null===(t=this.element)||void 0===t||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){const i=t.touches[0],s=t.touches[1];this.currentPosition1=h.create(i.screenX,i.screenY),this.currentPosition2=null!=s?h.create(s.screenX,s.screenY):void 0,window.addEventListener("touchmove",this.handleTouchMove,{passive:!1}),window.addEventListener("touchend",this.handleTouchEnd)}}handleTouchMove(t){if(1===t.touches.length)this.handleOnePointTouchMove(t.touches[0]);else if(2===t.touches.length){const i=h.create(t.touches[0].clientX,t.touches[0].clientY),s=h.create(t.touches[1].clientX,t.touches[1].clientY);this.handleTwoPointTouchMove(i,s)}}handleTouchEnd(t){var i;null===(i=this.interactionApi)||void 0===i||i.endInteraction(),this.isInteracting=!1,window.removeEventListener("touchmove",this.handleTouchMove),window.removeEventListener("touchend",this.handleTouchEnd)}handleOnePointTouchMove(t){var i,s,e;const n=h.create(t.screenX,t.screenY);if(null!=this.currentPosition1){const t=h.subtract(n,this.currentPosition1),o=(null===(i=this.interactionApi)||void 0===i?void 0:i.pixelThreshold(!0))||2;(h.distance(n,this.currentPosition1)>=o||this.isInteracting)&&(null===(s=this.interactionApi)||void 0===s||s.beginInteraction(),null===(e=this.interactionApi)||void 0===e||e.rotateCamera(t),this.isInteracting=!0)}this.currentPosition1=n}}const Dt=new class{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(null!=(i=t)&&i.then instanceof Function&&i.catch instanceof Function&&i.finally instanceof Function){const i=this.begin();return t.finally((()=>this.end(i)))}if("function"==typeof t){const i=this.begin(),s=t();return this.end(i),s}throw new Error("Input must be a function or Promise");var i}takeMeasurements(){const t=this.perf.getEntriesByName(this.name);return this.clearMeasurements(),t}takeLastMeasurement(){const t=this.takeMeasurements();return t[t.length-1]}begin(){const t=`${this.name}-${this.nextId++}`;return this.measures.add(t),this.perf.mark(t),t}end(t){this.perf.measure(this.name,t),this.perf.clearMarks(t),this.measures.delete(t)}}("paint_time");function St(t,i,s,e,n=1e3){let h,o,a=0,r=[];return s&&setInterval((()=>{if(null!=o){5===r.length?r=[...r.slice(1),o]:r.push(o);const t=r.reduce(((t,i)=>t+i))/r.length;console.debug(`Paint rate: ${o}fps`),console.debug(`Paint rate (avg): ${t}`),o=void 0}}),1e3),s=>(a++,null==h&&(h=setInterval((()=>{!function(t,i){const s=t.takeMeasurements();s.length>0&&i(s)}(t,e),0===a&&null!=h&&(clearInterval(h),h=void 0)}),n)),t.measure((async()=>{const t=await i(s);return o=null==o?1:o+1,t})).finally((()=>{a--})))}var xt;!function(t){t.DEVICE_ID="vertexvis:device-id"}(xt||(xt={}));class kt extends f{constructor(t,i={}){var s,e,n;super(t,{loggingEnabled:i.loggingEnabled}),this.state={type:"disconnected"},this.stateChanged=new y,this.dimensions=u.create(0,0),this.streamAttributes={},this.frameBgColor=b.create(255,255,255),this.config=x("platprod"),this.options={tokenRefreshOffsetInSeconds:null!==(s=i.tokenRefreshOffsetInSeconds)&&void 0!==s?s:30,offlineThresholdInSeconds:null!==(e=i.offlineThresholdInSeconds)&&void 0!==e?e:30,loadTimeoutInSeconds:null!==(n=i.loadTimeoutInSeconds)&&void 0!==n?n:15}}getState(){return this.state}disconnect(){"disconnected"!==this.state.type&&"connection-failed"!==this.state.type&&(console.debug("Disconnecting websocket"),this.state.connection.dispose(),this.updateState({type:"disconnected"}))}async load(t,i,s,e=x("platprod")){return this.clientId=i,this.deviceId=s,this.config=e,"disconnected"===this.state.type||"connection-failed"===this.state.type?this.loadIfDisconnected(t):this.loadIfConnectingOrConnected(t,this.state)}update(t){this.frameBgColor=t.frameBgColor?t.frameBgColor:this.frameBgColor,null!=t.dimensions&&t.dimensions!==this.dimensions&&(this.dimensions=t.dimensions,this.ifState("connected",(()=>this.updateDimensions({dimensions:this.dimensions})))),null!=t.streamAttributes&&this.streamAttributes!==t.streamAttributes&&(this.streamAttributes=t.streamAttributes,this.ifState("connected",(()=>this.updateStream({streamAttributes:Et(this.streamAttributes)}))))}async loadIfConnectingOrConnected(t,i){var s;const{resource:e,subResource:n}=i.resource,h=tt(t),o=!I.isEqual(e,h.resource),a=!I.isEqual(n,h.subResource),r="connecting"===i.type||"reconnecting"===i.type,l="connected"===i.type,c=h.queries.find((t=>"supplied-id"===t.type));if(o||r&&a)return this.disconnect(),this.loadIfDisconnected(t);if(l&&a&&"scene-view-state"===(null===(s=h.subResource)||void 0===s?void 0:s.type)){const t=Object.assign(Object.assign({},null!=h.subResource.id?{sceneViewStateId:{hex:h.subResource.id}}:{}),null!=c?{sceneViewStateSuppliedId:{value:c.id}}:{});await this.loadSceneViewState(t),this.updateState(Object.assign(Object.assign({},i),{resource:h}))}}async loadIfDisconnected(t){try{await this.connectWithNewStream(tt(t))}catch(t){throw this.updateState(t instanceof j?{type:"connection-failed",message:`Cannot load scene. ${t.message}`,error:t}:t instanceof p?{type:"connection-failed",message:"Cannot load scene. Stream request failed to start stream.",error:t}:{type:"connection-failed",message:"Cannot load scene for unknown reason. See console logs.",error:t}),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,s,{maxRetries:e=3}={}){const n=(h=function(t,i,s,e){return P.appendPath(null!=s?P.toString(P.parseAndAddParams("/ws",{clientId:s,deviceId:e})):`/stream-keys/${i.id}/session`,P.parse(t.network.renderingHost))}(this.config,t.resource,this.clientId,this.deviceId),{url:P.toString(h),protocols:["ws.vertexvis.com"]});var h;console.debug(`Initiating WS connection [uri=${n.url}]`);const o=new AbortController,a=(r=this.config,{EXPERIMENTAL_frameDelivery:Object.assign(Object.assign({},r.EXPERIMENTAL_frameDelivery),{rateLimitingEnabled:r.flags.throttleFrameDelivery}),EXPERIMENTAL_adaptiveRendering:Object.assign(Object.assign({},r.EXPERIMENTAL_adaptiveRendering),{enabled:r.flags.adaptiveRendering}),EXPERIMENTAL_qualityOfService:Object.assign({},r.EXPERIMENTAL_qualityOfService)});var r;this.updateState({type:i,resource:t,connection:{dispose:()=>{this.dispose(),o.abort()}}});const l=await T.abort(o.signal,T.retry((()=>this.connect(n,a)),{maxRetries:e,delaysInMs:kt.WS_RECONNECT_DELAYS})).catch((t=>{throw new R("Websocket connection failed.",t instanceof Error?t:void 0)}));if(!l.aborted)return this.requestNewOrExistingStream(t,l.result,s);this.updateState({type:"disconnected"})}async requestNewOrExistingStream(t,i,s){const e=this.requestClock(),n=await s();console.debug(`Stream connected [stream-id=${n.streamId}, scene-id=${n.sceneId}, scene-view-id=${n.sceneViewId}]`);const h=this.onRequest((t=>{const i=t.request.drawFrame;if(null!=i){const t=q(n.worldOrientation)(i);"connected"===this.state.type&&this.updateState(Object.assign(Object.assign({},this.state),{frame:t}))}})),o=this.reconnectWhenNeeded(),a=this.refreshTokenWhenExpired(n.token),r=this.acknowledgeFrameRequests(),l=null==n.frame?await this.waitForFrame(n.worldOrientation,this.options.loadTimeoutInSeconds):n.frame,c=await e;console.debug(`Synchronized clocks [local-time=${c.knownLocalTime.toISOString()}, remote-time=${c.knownRemoteTime.toISOString()}]`),this.updateState({type:"connected",connection:{dispose:()=>{o.dispose(),h.dispose(),a.dispose(),r.dispose(),i.dispose()}},resource:t,streamId:n.streamId,deviceId:n.deviceId,sceneId:n.sceneId,sceneViewId:n.sceneViewId,worldOrientation:n.worldOrientation,token:n.token,frame:l,clock:c})}async requestNewStream(t){var i,s;const e=t.queries.find((t=>"supplied-id"===t.type)),n=U(await this.startStream({streamKey:{value:t.resource.id},dimensions:this.dimensions,frameBackgroundColor:Ot(this.frameBgColor),streamAttributes:Et(this.streamAttributes),sceneViewStateId:"scene-view-state"===(null===(i=t.subResource)||void 0===i?void 0:i.type)&&null!=t.subResource.id?{hex:t.subResource.id}:void 0,sceneViewStateSuppliedId:"scene-view-state"===(null===(s=t.subResource)||void 0===s?void 0:s.type)&&null!=e?{value:e.id}:void 0}));return{resource:t,streamId:n.streamId,sceneId:n.sceneId,sceneViewId:n.sceneViewId,deviceId:n.sessionId,token:n.token,worldOrientation:n.worldOrientation,frame:void 0}}async requestReconnectStream(t){const i=G(await this.reconnect({streamId:{hex:t.streamId},dimensions:this.dimensions,frameBackgroundColor:Ot(this.frameBgColor),streamAttributes:Et(this.streamAttributes)}));return Object.assign(Object.assign({},t),{token:i.token})}async requestClock(){const t=_(await this.syncTime({requestTime:m()}));return new it(t)}reconnectWhenNeeded(){const t=this.onClose((()=>{"connected"===this.state.type&&this.closeAndReconnect(this.state)})),i=this.onRequest((t=>{null!=t.request.gracefulReconnection&&"connected"===this.state.type&&(console.debug("Received request for graceful reconnect. Closing connection and attempting reconnect."),this.closeAndReconnect(this.state))})),s=this.reconnectWhenOffline();return{dispose:()=>{t.dispose(),i.dispose(),s.dispose()}}}refreshTokenWhenExpired(t){let i;const s=t=>{const{tokenRefreshOffsetInSeconds:e}=this.options,n=t.remainingTimeInMs(e);i=window.setTimeout((async()=>{const t=await this.refreshToken(),i=J(t);s(i),"connected"===this.state.type&&this.updateState(Object.assign(Object.assign({},this.state),{token:i}))}),n)};return s(t),{dispose:()=>clearTimeout(i)}}reconnectWhenOffline(){let t;const i=()=>window.clearTimeout(t),s=()=>{i();const s=this.options.offlineThresholdInSeconds;console.debug(`Detected that host is offline. Will attempt reconnect in ${s}s.`),t=window.setTimeout((()=>{"connected"===this.state.type&&this.closeAndReconnect(this.state)}),1e3*s)};return window.addEventListener("offline",(()=>s())),window.addEventListener("online",(()=>{console.debug("Detected that host is online."),i()})),{dispose:()=>{i(),window.removeEventListener("offline",s),window.removeEventListener("online",i)}}}closeAndReconnect(t){return t.connection.dispose(),this.connectToExistingStream(t)}async waitForFrame(t,i){let s;try{return await T.timeout(1e3*i,new Promise((i=>{s=this.onRequest((e=>{try{const n=e.request.drawFrame;if(null!=n){const s=q(t)(n);i(s)}}finally{null==s||s.dispose()}}))})))}catch(t){throw new A(`Frame timed out after ${i/1e3}s`,t instanceof Error?t:void 0)}finally{null==s||s.dispose()}}acknowledgeFrameRequests(){return this.onRequest(function(t,i){const s=function(t){let i=!1;return s=>{const e=t();if(null!=e){const t=e.remoteTime(new Date(Date.now())),n=v(s,t);return w(n).getTime()>=0?n:void(i||(console.warn(`Possible erroneous send to receive timing. Muting for 60s. [sent-at=${s.toISOString()}, received-at=${t.toISOString()}, remote-time=${e.knownRemoteTime.toISOString()}]`),i=!0,setTimeout((()=>i=!1),6e4)))}}}(i);return e=i=>{return e=()=>e=>{const n=w(e.sentAtTime);null!=n&&t.replyResult(i,{drawFrame:{sendToReceiveDuration:s(n)}})},t=>{const{drawFrame:i}=t.request;null!=i&&e()(t)};var e},t=>{var i;const s=null===(i=t.request.requestId)||void 0===i?void 0:i.value;null!=s&&e(s)(t)};var e}(this,(()=>"connected"===this.state.type?this.state.clock:void 0)))}updateState(t){this.state!==t&&(this.state=t,this.stateChanged.emit(this.state))}ifState(t,i){if(this.state.type===t)return i()}onStateChanged(t){return this.stateChanged.on(t)}}kt.WS_RECONNECT_DELAYS=[0,1e3,1e3,5e3];const Et=C.ifInvalidThrow(W),Ot=C.ifInvalidThrow(V),Mt=class{constructor(s){t(this,s),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.deviceIdChange=i(this,"deviceIdChange",7),this.dimensionschange=i(this,"dimensionschange",7),this.configEnv="platprod",this.cameraControls=!0,this.cameraType="perspective",this.keyboardControls=!0,this.rotateAroundTapPoint=!0,this.experimentalGhostingOpacity=0,this.noDefaultLights=!1,this.experimentalRenderingOptions="",this.resizeDebounce=100,this.stencilBuffer=new et(this.hostElement),this.viewport=Z.fromDimensions(u.create(0,0)),this.stateMap={cursorManager:new k,streamState:{type:"disconnected"}},this.interactionHandlers=[],this.defaultInteractionHandlerDisposables=[],this.tapKeyInteractions=[],this.defaultTapKeyInteractions=[],this.internalFrameDrawnDispatcher=new y,this.handleElementResize=this.handleElementResize.bind(this)}componentWillLoad(){var t;this.updateResolvedConfig(),this.calculateComponentDimensions(),this.resizeObserver=new ResizeObserver(this.handleElementResize),this.registerSlotChangeListeners(),this.stream=null!==(t=this.stream)&&void 0!==t?t:new kt(new g,{loggingEnabled:this.getResolvedConfig().flags.logWsMessages}),this.addStreamListeners(),this.updateStreamAttributes(),this.stateMap.cursorManager.onChanged.on((()=>this.handleCursorChanged()))}componentDidLoad(){var t;this.interactionApi=this.createInteractionApi(),null!=this.containerElement&&(null===(t=this.resizeObserver)||void 0===t||t.observe(this.containerElement)),null!=this.src&&this.load(this.src).catch((t=>{console.error("Error loading scene",t)})),this.initializeDefaultInteractionHandlers(),this.injectViewerApi()}render(){var t;return s(e,null,s("div",{class:"viewer-container",style:{cursor:O(null!==(t=this.cursor)&&void 0!==t?t:"")},onContextMenu:t=>t.preventDefault()},s("div",{ref:t=>this.containerElement=t,class:S("canvas-container",{"enable-pointer-events ":null!=window.PointerEvent})},s("canvas",{ref:t=>{this.canvasElement=t,this.stateMap.interactionTarget=t},class:"canvas"}),null!=this.errorMessage?s("div",{class:"error-message"},this.errorMessage):null),s("slot",null)))}async dispatchFrameDrawn(t){this.frame=t,this.internalFrameDrawnDispatcher.emit(t),this.frameDrawn.emit(t)}async registerInteractionHandler(t){return this.interactionHandlers.push(t),this.initializeInteractionHandler(t),{dispose:()=>{const i=this.interactionHandlers.indexOf(t);-1!==i&&(this.interactionHandlers[i].dispose(),this.interactionHandlers.splice(i,1))}}}async registerTapKeyInteraction(t){this.tapKeyInteractions=[...this.tapKeyInteractions,t]}async getInteractionTarget_DEPRECATED(){if(null!=this.stateMap.interactionTarget)return this.stateMap.interactionTarget;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){null!=t?this.load(t):this.unload()}handleCameraControlsChanged(){this.initializeDefaultCameraInteractionHandlers()}handleKeyboardControlsChanged(){this.initializeDefaultKeyboardInteractionHandlers()}handleRotateAboutTapPointChanged(){var t,i;this.updateStreamAttributes(),this.rotateAroundTapPoint?null===(t=this.baseInteractionHandler)||void 0===t||t.setPrimaryInteractionType("rotate-point"):null===(i=this.baseInteractionHandler)||void 0===i||i.setPrimaryInteractionType("rotate")}handleCameraTypeChanged(t,i){t!==i&&this.updateCameraType()}handleDepthBuffersChanged(){this.updateStreamAttributes()}handleExperimentalGhostingOpacityChanged(){this.updateStreamAttributes()}handleNoDefaultLightsChanged(){this.updateStreamAttributes()}handleExperimentalRenderingOptionsChanged(){this.updateStreamAttributes()}handleFeatureLinesChanged(){this.updateStreamAttributes()}handleSelectionHighlightingChanged(){this.updateStreamAttributes()}handleFeatureHighlightingChanged(){this.updateStreamAttributes()}handleFeatureMapsChanged(){this.updateStreamAttributes()}handleConfigChanged(){this.updateResolvedConfig()}handleConfigEnvChanged(){this.updateResolvedConfig()}async load(t){var i;if(null==this.stream||null==this.dimensions)throw new F("Cannot load scene. Viewer has not been initialized.");this.calculateComponentDimensions(),this.stream.update({streamAttributes:this.getStreamAttributes(),config:x(this.configEnv,this.config),dimensions:this.dimensions,frameBgColor:this.getBackgroundColor()}),await(null===(i=this.stream)||void 0===i?void 0:i.load(t,this.clientId,this.getDeviceId(),this.getResolvedConfig())),this.sceneReady.emit()}async unload(){if(null!=this.stream&&(this.stream.disconnect(),this.frame=void 0,this.errorMessage=void 0),null!=this.canvasElement){const t=this.canvasElement.getContext("2d");null!=t&&t.clearRect(0,0,this.canvasElement.width,this.canvasElement.height)}}async scene(){return this.createScene()}async isSceneReady(){return"connected"===this.stateMap.streamState.type}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){t.length>0&&null!=this.dimensions&&!u.isEqual(t[0].contentRect,this.viewport)&&(null!=this.resizeTimer&&(clearTimeout(this.resizeTimer),this.resizeTimer=void 0),this.isResizing||(this.resizeTimer=setTimeout((()=>{this.isResizing=!0,this.isResizeUpdate=!0,this.recalculateComponentDimensions()}),this.resizeDebounce)))}registerSlotChangeListeners(){this.mutationObserver=new MutationObserver((()=>this.injectViewerApi())),this.mutationObserver.observe(this.hostElement,{childList:!0,subtree:!0})}injectViewerApi(){function t(t){return Array.from(t.querySelectorAll("*"))}t(this.hostElement).filter((t=>t.nodeName.startsWith("VERTEX-"))).reduce(((i,s)=>[...i,s,...t(s)]),[]).forEach((t=>{t.viewer=this.hostElement}))}calculateComponentDimensions(){var t;const i=this.getBounds();if(null!=(null==i?void 0:i.width)&&null!=(null==i?void 0:i.height)){const s=u.create(i.width,i.height),e=u.scaleFit(2073600,s);this.hostDimensions=s,this.dimensions=null!=e?u.create(e.width,e.height):void 0,this.viewport=Z.fromDimensions(null!==(t=this.getCanvasDimensions())&&void 0!==t?t:u.create(0,0))}}recalculateComponentDimensions(){var t;this.isResizing&&(this.calculateComponentDimensions(),this.isResizing=!1,"connected"===(null===(t=this.stream)||void 0===t?void 0:t.getState().type)&&this.updateDimensions(this.dimensions))}reportPerformance(t){if("connected"===this.stateMap.streamState.type){const i={timings:t.map((t=>({receiveToPaintDuration:v(t.duration)})))};this.getStream().recordPerformance(i,!1)}}addStreamListeners(){this.stateMap.streamListeners=this.getStream().stateChanged.on((t=>{this.handleStreamStateChanged(this.stateMap.streamState,t)}))}handleStreamStateChanged(t,i){this.stateMap.streamState=i,"connecting"===i.type?this.handleConnecting(t,i):"connected"===i.type?this.handleConnected(t,i):"connection-failed"===i.type?this.handleConnectionFailed(t,i):"disconnected"===i.type&&this.handleDisconnected(t,i)}handleConnecting(t,i){"connecting"!==t.type&&(this.token=void 0,this.errorMessage=void 0,this.emitConnectionChange({status:"connecting"}))}handleConnected(t,i){this.token=i.token.token,"connected"!==t.type&&(this.errorMessage=void 0,this.canvasRenderer=St(Dt,function(){let t=[];function i(i){if(null!=i){const s=i.copy({correlationIds:[...i.correlationIds,...t.filter((t=>!i.correlationIds.includes(t)))]});return t=[],s}return i}const s=function(){let t=-1;return async i=>{if(i.frame.sequenceNumber>t){const n=await(s=i.frame.image.imageBytes,null!=window.createImageBitmap?async function(t){const i=new Blob([t]),s=await window.createImageBitmap(i);return{image:s,dispose:()=>s.close()}}(s):(e=s,new Promise(((t,i)=>{const s=new Blob([e]),n=URL.createObjectURL(s),h=new Image;h.addEventListener("load",(()=>{t({image:h,dispose:()=>{}}),URL.revokeObjectURL(n)})),h.addEventListener("error",(()=>{i(new M("Failed to load image data")),URL.revokeObjectURL(n)})),h.src=n}))));return t=i.frame.sequenceNumber,n}var s,e}}(),e=function(){let t=-1;return async(i,s)=>{var e;if(null!=s&&i.frame.sequenceNumber>t)return t=i.frame.sequenceNumber,null===(e=i.beforeDraw)||void 0===e||e.call(i),function(t,i){const s=i.viewport.calculateDrawRect(i.frame.image);i.canvas.clearRect(0,0,i.canvasDimensions.width,i.canvasDimensions.height),i.canvas.drawImage(t.image,s.x,s.y,s.width,s.height)}(s,i),s.dispose(),i.frame;null==s||s.dispose()}}();return async n=>{var h,o;const a=null===(o=null===(h=n.predicate)||void 0===h?void 0:h.call(n))||void 0===o||o;if(t=[...t,...n.frame.correlationIds],a)return s(n).then((t=>e(n,t).then(i)))}}(),this.getResolvedConfig().flags.logFrameRate,(t=>this.reportPerformance(t))),this.emitConnectionChange({status:"connected",jwt:i.token.token}),this.deviceIdChange.emit(i.deviceId)),this.frame!==i.frame&&this.updateFrame(i.frame),this.updateDimensions(this.dimensions)}handleConnectionFailed(t,i){"connection-failed"!==t.type&&(this.token=void 0,this.errorMessage=i.message)}handleDisconnected(t,i){"disconnected"!==t.type&&(this.token=void 0,this.errorMessage=void 0,this.emitConnectionChange({status:"disconnected"}))}updateDimensions(t){var i;null===(i=this.stream)||void 0===i||i.update({dimensions:t}),this.dimensionschange.emit(t)}async updateFrame(t){const i=this.getCanvasDimensions();if(null!=this.canvasElement&&null!=i&&this.frame!==t){const s=this.canvasElement.getContext("2d");if(null!=s){const e=this.frame;this.frame=t,this.updateInteractionApi(e);const n={canvas:s,canvasDimensions:i,dimensions:this.dimensions,frame:this.frame,viewport:this.viewport,beforeDraw:()=>{this.updateCanvasDimensions(i),this.isResizeUpdate=!1},predicate:()=>!this.isResizeUpdate||null==this.dimensions||u.isEqual(this.dimensions,n.frame.image.imageAttr.frameDimensions)};this.frameReceived.emit(this.frame),this.frame.scene.hasChanged&&this.sceneChanged.emit();const h=await this.canvasRenderer(n);null!=h&&this.dispatchFrameDrawn(h)}}}async initializeDefaultInteractionHandlers(){var t;await this.initializeDefaultCameraInteractionHandlers(),await this.initializeDefaultTapInteractionHandler(),this.initializeDefaultKeyboardInteractionHandlers(),this.rotateAroundTapPoint&&(null===(t=this.baseInteractionHandler)||void 0===t||t.setPrimaryInteractionType("rotate-point"))}clearDefaultCameraInteractionHandlers(){this.defaultInteractionHandlerDisposables.forEach((t=>t.dispose())),this.defaultInteractionHandlerDisposables=[]}clearDefaultKeyboardInteractions(){this.defaultTapKeyInteractions.forEach((t=>{const i=this.tapKeyInteractions.indexOf(t);-1!==i&&this.tapKeyInteractions.splice(i,1)})),this.tapKeyInteractions=[]}async initializeDefaultCameraInteractionHandlers(){var t,i;if(this.clearDefaultCameraInteractionHandlers(),this.cameraControls)if(null!=window.PointerEvent){this.baseInteractionHandler=null!==(t=this.baseInteractionHandler)&&void 0!==t?t:new It((()=>this.getResolvedConfig()));const i=await this.registerInteractionHandler(this.baseInteractionHandler),s=await this.registerInteractionHandler(new bt);this.defaultInteractionHandlerDisposables=[i,s]}else{this.baseInteractionHandler=null!==(i=this.baseInteractionHandler)&&void 0!==i?i:new yt((()=>this.getResolvedConfig()));const t=await this.registerInteractionHandler(this.baseInteractionHandler),s=await this.registerInteractionHandler(new Tt);this.defaultInteractionHandlerDisposables=[t,s]}}initializeDefaultKeyboardInteractionHandlers(){var t;if(this.clearDefaultKeyboardInteractions(),this.keyboardControls&&null!=this.stream){null===(t=this.baseInteractionHandler)||void 0===t||t.setDefaultKeyboardControls(this.keyboardControls);const i=new ht(this.stream,(()=>this.getResolvedConfig()),(()=>this.getImageScale())),s=new lt(this.stream,(()=>this.getResolvedConfig()),(()=>this.getImageScale()),(()=>this.createScene()));this.registerTapKeyInteraction(i),this.registerTapKeyInteraction(s),this.defaultTapKeyInteractions=[i,s]}}async initializeDefaultTapInteractionHandler(){if(null==this.tapHandlerDisposable)if(null!=window.PointerEvent){const t=new Pt("pointerdown","pointerup","pointermove",(()=>this.getResolvedConfig()));this.tapHandlerDisposable=await this.registerInteractionHandler(t)}else{const t=new Pt("mousedown","mouseup","mousemove",(()=>this.getResolvedConfig()));this.tapHandlerDisposable=await this.registerInteractionHandler(t)}}initializeInteractionHandler(t){if(null==this.stateMap.interactionTarget)throw new z("Cannot initialize interaction handler. Interaction target is undefined.");if(null==this.interactionApi)throw new z("Cannot initialize interaction handler. Interaction APi is undefined.");t.initialize(this.stateMap.interactionTarget,this.interactionApi)}createInteractionApi(){if(null==this.stream)throw new B("Cannot create interaction API. Component has not been initialized.");return null==this.frame||this.frame.scene.camera.isPerspective()?new rt(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 at(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()}))}createScene(){if("connected"!==this.stateMap.streamState.type)throw new L("Cannot create scene. Viewer stream is not connected.");const{frame:t,sceneId:i,sceneViewId:s,worldOrientation:e}=this.stateMap.streamState;return new st(this.getStream(),t,q(e),(()=>this.getImageScale()),this.viewport,i,s)}getBackgroundColor(){if(null!=this.containerElement)return function(t){const i=window.getComputedStyle(t);return b.fromCss(i.backgroundColor)}(this.containerElement)}getBounds(){return this.hostElement.getBoundingClientRect()}getCanvasDimensions(){return this.getResolvedConfig().flags.letterboxFrames?this.dimensions:this.hostDimensions}getImageScale(){const t=this.getCanvasDimensions();if(null!=this.dimensions&&null!=t)return h.create(this.dimensions.width/t.width,this.dimensions.height/t.height)}getStreamAttributes(){return{depthBuffers:this.getDepthBufferStreamAttributesValue(),experimentalGhosting:this.experimentalGhostingOpacity,noDefaultLights:this.noDefaultLights,featureLines:this.featureLines,featureHighlighting:this.featureHighlighting,featureMaps:this.featureMaps,experimentalRenderingOptions:this.experimentalRenderingOptions,selectionHighlighting:this.selectionHighlighting}}updateCanvasDimensions(t){null!=this.canvasElement&&(this.canvasElement.width=t.width,this.canvasElement.height=t.height)}updateStreamAttributes(){var t;null===(t=this.stream)||void 0===t||t.update({streamAttributes:this.getStreamAttributes()})}updateInteractionApi(t){if(null!=this.frame){const i=(null==t||t.scene.camera.isPerspective())&&this.frame.scene.camera.isOrthographic(),s=(null==t||t.scene.camera.isOrthographic())&&this.frame.scene.camera.isPerspective();(i||s)&&(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;null!=this.frame&&("orthographic"===this.cameraType&&this.frame.scene.camera.isPerspective()?null===(t=this.stream)||void 0===t||t.replaceCamera({camera:H(X(this.frame.scene.camera,this.frame.scene.boundingBox))}):"perspective"===this.cameraType&&this.frame.scene.camera.isOrthographic()&&(null===(i=this.stream)||void 0===i||i.replaceCamera({camera:H(Y(this.frame.scene.camera))})))}getDepthBufferStreamAttributesValue(){var t;return null!==(t=this.depthBuffers)&&void 0!==t?t:this.rotateAroundTapPoint?"final":void 0}updateResolvedConfig(){this.resolvedConfig=x(this.configEnv,this.config)}getResolvedConfig(){return jt("Resolved config is undefined",(()=>this.resolvedConfig))}getStream(){return jt("Stream is undefined",(()=>this.stream))}getDeviceId(){if(null==this.deviceId){try{this.deviceId=function(t,i,s=window.localStorage){const e=s.getItem(xt.DEVICE_ID);if(null!=e)return i(JSON.parse(e))}(0,(t=>t["device-id"]))}catch(t){console.warn("Cannot read device ID. Local storage is not supported.")}if(null==this.deviceId){this.deviceId=D.create();try{!function(t,i,s=window.localStorage){const e=s.getItem(t);if(null!=e){const n=Object.assign(Object.assign({},JSON.parse(e)),i);s.setItem(t,JSON.stringify(n))}else s.setItem(t,JSON.stringify(i))}(xt.DEVICE_ID,{"device-id":this.deviceId})}catch(t){console.warn("Cannot write device ID. Local storage is not supported.")}}}return this.deviceId}get hostElement(){return n(this)}static get watchers(){return{src:["handleSrcChanged"],cameraControls:["handleCameraControlsChanged"],keyboardControls:["handleKeyboardControlsChanged"],rotateAroundTapPoint:["handleRotateAboutTapPointChanged"],cameraType:["handleCameraTypeChanged"],depthBuffers:["handleDepthBuffersChanged"],experimentalGhostingOpacity:["handleExperimentalGhostingOpacityChanged"],noDefaultLights:["handleNoDefaultLightsChanged"],experimentalRenderingOptions:["handleExperimentalRenderingOptionsChanged"],featureLines:["handleFeatureLinesChanged"],selectionHighlighting:["handleSelectionHighlightingChanged"],featureHighlighting:["handleFeatureHighlightingChanged"],featureMaps:["handleFeatureMapsChanged"],config:["handleConfigChanged"],configEnv:["handleConfigEnvChanged"]}}};function jt(t,i){const s=i();if(null!=s)return s;throw new Error(t)}Mt.style=":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}.canvas-container{display:flex;justify-content:center;align-items:center;width:100%;height:100%;position:relative;background:var(--image-background, var(--viewer-background, #ffffff))}.enable-pointer-events{touch-action:none}.viewer-container{width:100%;height:100%;overflow:hidden;background:var(--viewer-background, #ffffff)}.error-message{position:absolute;top:50%;width:100%;transform:translateY(-50%);text-align:center}";export{Mt as vertex_viewer}
|
|
4
|
+
import{r as t,c as i,h as s,H as e,g as n}from"./p-d6fce4c1.js";import{p as h,v as o,c as a,f as r,r as l,b as c,s as d,d as u}from"./p-d216a866.js";import{t as v,p as w,a as f,S as p,c as m,W as g}from"./p-a7c29e95.js";import{E as y,m as C,c as b,o as I,u as P,a as T,b as D}from"./p-fc7d8c03.js";import{c as S}from"./p-07aeee89.js";import{p as x}from"./p-dde5650a.js";import{C as k}from"./p-1812c82d.js";import{g as E,c as O}from"./p-42760392.js";import{c as M,C as j,W as R,S as A,V as F,d as z,e as B,f as L}from"./p-440c8174.js";import{k as N,l as K,m as $,t as H,n as W,o as V,p as q,q as U,r as G,s as _,u as J,x as X,y as Y}from"./p-817743a4.js";import{E as Q}from"./p-df8fbe56.js";import{V as Z}from"./p-0a017be7.js";import{f as tt,a as it,S as st}from"./p-5632192b.js";import"./p-dfe5a97d.js";class et{constructor(t){this.viewer=t,this.handleInteractionStarted=()=>{this.invalidateStencilBuffer(),this.pendingInteractionFinished=new Promise((t=>{this.pendingInteractionFinishedResolver=t}))},this.handleInteractionFinished=()=>{var t;null===(t=this.pendingInteractionFinishedResolver)||void 0===t||t.call(this),this.pendingInteractionFinished=void 0,this.pendingInteractionFinishedResolver=void 0},this.invalidateStencilBuffer=()=>{this.pendingStencilBuffer=void 0},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()?await this.viewer.scene():void 0,s=null!=i&&(i.crossSectioning().current().sectionPlanes.length>0||null!=this.viewer.featureLines),e=null===(t=this.viewer.frame)||void 0===t?void 0:t.scene.camera;if(s&&null!=this.viewer.stream&&null!=e){const t=await this.viewer.stream.getStencilBuffer({includeDepthBuffer:!0}),{stencilBuffer:i,depthBuffer:s,imageAttributes:n}=N(t),[h,o]=await Promise.all([K(new Uint8Array(i)),K(new Uint8Array(s))]);return nt.fromPng(h,n,i,$.fromPng(o,e,n))}}latest(){return null==this.pendingStencilBuffer&&(this.pendingStencilBuffer=this.fetch()),this.pendingStencilBuffer}async latestAfterInteraction(){return await this.pendingInteractionFinished,this.latest()}}class nt{constructor(t,i,s,e,n){this.imageAttr=t,this.imageBytes=i,this.pixelBytes=s,this.imageChannels=e,this.depthBuffer=n}static fromPng(t,i,s,e){if(t.data instanceof Uint8Array){if(1!==t.channels)throw new Error("Expected stencil PNG to have 1 color channel");return new nt(i,s,t.data,t.channels,e)}throw new Error("Expected stencil PNG to have depth of 8-bit")}getValue(t){const{width:i,height:s}=this.imageAttr.imageRect,e=h.subtract(t,this.imageAttr.imageRect),n=1/this.imageAttr.imageScale,o=h.scale(e,n,n);if(o.x>=0&&o.y>=0&&o.x<i&&o.y<s){const t=Math.floor(o.x)+Math.floor(o.y)*i;return this.pixelBytes[t]}return 0}hitTest(t){return 0!==this.getValue(t)}snapToNearestPixel(t,i,s=(()=>!0)){const e=2*i,n=h.create(t.x-i,t.y-i),o=[];for(let a=0;a<e*e;a++){const r=a%e,l=Math.floor(a/e),c=h.add(n,{x:r,y:l});if(h.distance(c,t)<=i){const t=this.getValue(c);255===t&&s(t)&&o.push(c)}}const a=o.sort(((i,s)=>h.distance(i,t)-h.distance(s,t)))[0];return null!=a?h.create(Math.floor(a.x)+.5,Math.floor(a.y)+.5):t}}class ht{constructor(t,i,s){this.stream=t,this.configProvider=i,this.imageScaleProvider=s}predicate(t){return t.altKey&&!t.shiftKey}async fn(t){var i;const s=this.imageScaleProvider(),e=await this.stream.hitItems({point:h.scale(t.position,(null==s?void 0:s.x)||1,(null==s?void 0:s.y)||1)},!0);null!=(null===(i=e.hitItems)||void 0===i?void 0:i.hits)&&e.hitItems.hits.length>0?await this.stream.flyTo({itemId:e.hitItems.hits[0].itemId,animation:{duration:v(this.configProvider().animation.durationMs)}}):console.debug(`No hit results found for fly to part [position={x: ${t.position.x}, y: ${t.position.y}}]`)}}class ot{constructor(t,i,s,e,n,h,o,a,r,l,c){this.stream=t,this.cursors=i,this.getConfig=s,this.getScene=e,this.getFrame=n,this.getViewport=h,this.tapEmitter=o,this.doubleTapEmitter=a,this.longPressEmitter=r,this.interactionStartedEmitter=l,this.interactionFinishedEmitter=c,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(),s=this.getFrame();if(null==s)throw new Error("Cannot get world point. Frame is undefined.");const e=await s.depthBuffer();return null!=e?i.transformPointToWorldSpace(t,e,.5):void 0}async getEntityTypeAtPoint(t){var i;const s=this.getViewport(),e=await(null===(i=this.getFrame())||void 0===i?void 0:i.featureMap());if(null!=e){const i=s.transformPointToFrame(t,e);return e.getEntityType(i)}return Q.NO_GEOMETRY}getRayFromPoint(t){const i=this.getViewport(),s=this.getFrame();if(null!=s)return i.transformPointToRay(t,s.image,s.scene.camera);throw new Error("Cannot get camera. Frame is undefined.")}async tap(t,i={},s=0){this.emitTapEvent(this.tapEmitter.emit,t,i,s)}async doubleTap(t,i={},s=0){this.emitTapEvent(this.doubleTapEmitter.emit,t,i,s)}async longPress(t,i={},s=0){this.emitTapEvent(this.longPressEmitter.emit,t,i,s)}async beginInteraction(){this.isInteracting()||(this.interactionStartedEmitter.emit(),this.currentCamera=this.getScene().camera(),await this.stream.beginInteraction())}async transformCamera(t){var i;if(this.isInteracting()){const s=this.getScene(),e=this.getViewport(),n=this.getFrame(),h=await(null==n?void 0:n.depthBuffer());this.currentCamera=null!=this.currentCamera&&null!=e&&null!=n?t({camera:this.currentCamera,viewport:e,scale:s.scale(),boundingBox:s.boundingBox(),frame:n,depthBuffer:h}):void 0,await(null===(i=this.currentCamera)||void 0===i?void 0:i.render())}}async twistCamera(...t){return this.transformCamera((({camera:i,viewport:s})=>{const e=o.normalize(o.subtract(i.lookAt,i.position));if(1===t.length&&"number"==typeof t[0]){const s=a.toRadians(-t[0]);return i.rotateAroundAxis(s,e)}if(1===t.length){const e=h.create(s.width/2,s.height/2),n=a.toDegrees(a.fromPoints(e,t[0])),r=null!=this.lastAngle?n-this.lastAngle:0;this.lastAngle=n;const l=o.normalize(o.subtract(i.lookAt,i.position)),c=a.toRadians(-r);return i.rotateAroundAxis(c,l)}return i}))}async panCameraToScreenPoint(t){return this.transformCamera((({camera:i,frame:s,viewport:e,depthBuffer:n})=>{if(null==this.panData){const h=i.toFrameCamera(),o=h.direction,a=e.transformPointToRay(t,s.image,h),c=r.fromNormalAndCoplanarPoint(o,i.lookAt),d=l.intersectPlane(a,c);if(null==d)return console.warn("Cannot determine fallback for pan. Ray does not intersect plane."),i;const u=null!=n?this.getWorldPoint(t,n,d):d,v=r.fromNormalAndCoplanarPoint(o,u);this.panData={hitPt:u,hitPlane:v,startingCamera:h}}if(null!=this.panData){const{hitPt:n,hitPlane:h,startingCamera:a}=this.panData,r=e.transformPointToRay(t,s.image,a),c=l.intersectPlane(r,h);if(null!=c){const t=o.subtract(n,c);return i.update(a).moveBy(t)}}return i}))}async viewAll(){await this.getScene().camera().viewAll().render()}async rotateCamera(t){return this.transformCamera((({camera:i,viewport:s})=>{const e=o.normalize(i.up),n=o.normalize(o.subtract(i.lookAt,i.position)),h=o.cross(e,n),a=o.cross(n,h),r=o.normalize({x:t.x*h.x+t.y*a.x,y:t.x*h.y+t.y*a.y,z:t.x*h.z+t.y*a.z}),l=o.cross(r,n),c=3*Math.PI*t.x/s.width,d=3*Math.PI*t.y/s.height,u=Math.abs(c)+Math.abs(d);return i.rotateAroundAxis(u,l)}))}async rotateCameraAtPoint(t,i){return this.transformCamera((({camera:s,viewport:e,boundingBox:n,depthBuffer:h})=>{if(null==this.worldRotationPoint){const t=c.center(n);this.worldRotationPoint=null!=h?this.getWorldPoint(i,h,t):s.lookAt}const a=o.normalize(s.up),r=o.normalize(o.subtract(s.lookAt,s.position)),l=o.cross(a,r),d=o.cross(r,l),u=o.normalize({x:t.x*l.x+t.y*d.x,y:t.x*l.y+t.y*d.y,z:t.x*l.z+t.y*d.z}),v=o.cross(u,r),w=3*Math.PI*t.x/e.width,f=3*Math.PI*t.y/e.height,p=Math.abs(w)+Math.abs(f),m=s.rotateAroundAxisAtPoint(p,this.worldRotationPoint,v);return m.update({lookAt:o.add(o.scale(Math.abs(s.signedDistanceToBoundingBoxCenter())/o.magnitude(m.viewVector),m.viewVector),m.position)})}))}async zoomCamera(t){return this.transformCamera((({camera:i,viewport:s})=>{const e=i.viewVector,n=o.normalize(e),h=o.magnitude(e),a=o.add(i.position,o.scale(3*h*t/s.height,n));return i.update({position:a})}))}async zoomCameraToPoint(t,i){return this.transformCamera((({camera:s,viewport:e,frame:n,depthBuffer:h})=>{const a=n.scene.camera,c=a.direction,d=s.toFrameCamera(),u=e.transformPointToRay(t,n.image,d);if(null==this.zoomData){const i=r.fromNormalAndCoplanarPoint(c,a.lookAt),e=l.intersectPlane(u,i);if(null==e)return console.warn("Cannot determine fallback point for zoom. Ray does not intersect plane."),s;const n=null!=h?this.getWorldPoint(t,h,e):e,o=r.fromNormalAndCoplanarPoint(c,n);this.zoomData={hitPt:n,hitPlane:o}}if(null!=this.zoomData){const{hitPt:t,hitPlane:n}=this.zoomData,h=o.distance(s.position,t),a=l.at(u,6*h*i/e.height),c=r.projectPoint(n,a),d=s.update({position:a,lookAt:c});if(o.distance(a,c)>=d.near)return d}return s}))}async pivotCamera(t,i){return this.transformCamera((({camera:s})=>{const{position:e,up:n,lookAt:h}=s,r=o.normalize(n),l=o.normalize(s.viewVector),c=o.cross(r,l),d=o.cross(l,c),u=o.rotateAboutAxis(a.toRadians(t),h,c,e),v=o.rotateAboutAxis(a.toRadians(i),u,d,e);return s.update(Object.assign(Object.assign({},s),{lookAt:v}))}))}async endInteraction(){this.isInteracting()&&(this.currentCamera=void 0,this.worldRotationPoint=void 0,this.panData=void 0,this.zoomData=void 0,this.resetLastAngle(),this.interactionFinishedEmitter.emit(),await this.stream.endInteraction())}resetLastAngle(){this.lastAngle=void 0}isInteracting(){return null!=this.currentCamera}pixelThreshold(t){return(this.isCoarseInputDevice(t)?this.getConfig().coarsePointerThreshold:this.getConfig().finePointerThreshold)*window.devicePixelRatio}async hitItems(t){var i;const s=await this.getScene().raycaster().hitItems(t);return null!==(i=null==s?void 0:s.hits)&&void 0!==i?i:[]}emitTapEvent(t,i,s={},e=0){const{altKey:n=!1,ctrlKey:h=!1,metaKey:o=!1,shiftKey:a=!1}=s;t({position:i,altKey:n,ctrlKey:h,metaKey:o,shiftKey:a,buttons:e})}isCoarseInputDevice(t){return t||window.matchMedia("(pointer: coarse)").matches}getWorldPoint(t,i,s){const e=this.getViewport(),n=e.transformPointToFrame(t,i);return i.hitTest(n)?e.transformPointToWorldSpace(t,i):s}}class at extends ot{constructor(t,i,s,e,n,h,o,a,r,l,c){super(t,i,s,e,n,h,o,a,r,l,c)}async getWorldPointFromViewport(t){const i=this.getViewport(),s=this.getFrame();if(null==s)throw new Error("Cannot get world point. Frame is undefined.");const e=await s.depthBuffer();return null!=e?i.transformPointToOrthographicWorldSpace(t,e,.5):void 0}async panCameraByDelta(t){return this.transformCamera((({camera:i,viewport:s})=>{const e=i.viewVector,n=o.normalize(i.up),h=o.normalize(e),a=o.magnitude(e)*Math.tan(i.fovHeight),r=t.x*a/s.width,l=t.y/s.width*a,c=o.cross(n,h),d=o.cross(h,c),u=o.add(o.scale(r,c),o.scale(l,d));return i.moveBy(u)}))}async panCameraToScreenPoint(t){return this.transformCamera((({camera:i,frame:s,viewport:e})=>{if(null==this.panData){const n=i.toFrameCamera(),h=n.direction,o=e.transformPointToOrthographicRay(t,s.image,n),a=r.fromNormalAndCoplanarPoint(h,i.lookAt),c=l.intersectPlane(o,a);if(null==c)return console.warn("Cannot determine fallback for pan. Ray does not intersect plane."),i;this.panData={hitPt:c,hitPlane:a,startingCamera:n}}if(null!=this.panData){const{hitPt:n,hitPlane:h,startingCamera:a}=this.panData,r=e.transformPointToOrthographicRay(t,s.image,a),c=l.intersectPlane(r,h);if(null!=c){const t=o.subtract(n,c);return i.update({lookAt:o.add(a.lookAt,t)})}}return i}))}async zoomCameraToPoint(t,i){return this.transformCamera((({camera:s,viewport:e,frame:n,depthBuffer:a})=>{if(null==this.orthographicZoomData||h.distance(t,this.orthographicZoomData.startingScreenPt)>2){const i=s.toFrameCamera(),h=i.direction,o=e.transformPointToOrthographicRay(t,n.image,i),c=r.fromNormalAndCoplanarPoint(h,i.lookAt),d=l.intersectPlane(o,c);if(null==d)return console.warn("Cannot determine fallback point for zoom. Ray does not intersect plane."),s;const u=null!=a?this.getWorldPoint(t,a,d):d,v=r.fromNormalAndCoplanarPoint(h,u);this.orthographicZoomData={hitPt:u,hitPlane:v,startingScreenPt:t}}if(null!=this.orthographicZoomData){const{hitPt:t,hitPlane:n}=this.orthographicZoomData,h=s.fovHeight/e.height*2*i,a=Math.max(1,s.fovHeight-h),l=r.projectPoint(n,s.lookAt),c=o.scale((s.fovHeight-a)/s.fovHeight,o.subtract(t,l));return s.update({lookAt:o.add(s.lookAt,c),fovHeight:Math.max(1,s.fovHeight-h)})}return s}))}getWorldPoint(t,i,s){const e=this.getViewport(),n=e.transformPointToFrame(t,i);return i.hitTest(n)?e.transformPointToOrthographicWorldSpace(t,i):s}async transformCamera(t){var i;if(this.isInteracting()){const s=this.getScene(),e=this.getViewport(),n=this.getFrame(),h=await(null==n?void 0:n.depthBuffer());this.currentCamera=null!=this.currentCamera&&null!=e&&null!=n?t({camera:this.currentCamera,viewport:e,scale:s.scale(),boundingBox:s.boundingBox(),frame:n,depthBuffer:h}):void 0,await(null===(i=this.currentCamera)||void 0===i?void 0:i.render())}}}class rt extends ot{constructor(t,i,s,e,n,h,o,a,r,l,c){super(t,i,s,e,n,h,o,a,r,l,c)}async panCameraByDelta(t){return this.transformCamera((({camera:i,viewport:s})=>{var e;const n=i.viewVector,h=o.normalize(i.up),a=o.normalize(n),r=o.magnitude(n)*Math.tan(null!==(e=i.fovY)&&void 0!==e?e:45),l=t.x*r/s.width,c=t.y/s.width*r,d=o.cross(h,a),u=o.cross(a,d),v=o.add(o.scale(l,d),o.scale(c,u));return i.moveBy(v)}))}async transformCamera(t){var i;if(this.isInteracting()){const s=this.getScene(),e=this.getViewport(),n=this.getFrame(),h=await(null==n?void 0:n.depthBuffer());this.currentCamera=null!=this.currentCamera&&null!=e&&null!=n?t({camera:this.currentCamera,viewport:e,scale:s.scale(),boundingBox:s.boundingBox(),frame:n,depthBuffer:h}):void 0,await(null===(i=this.currentCamera)||void 0===i?void 0:i.render())}}}class lt{constructor(t,i,s,e){this.stream=t,this.configProvider=i,this.imageScaleProvider=s,this.sceneProvider=e}predicate(t){return t.altKey&&t.shiftKey}async fn(t){var i,s;const e=this.imageScaleProvider(),n=await this.stream.hitItems({point:h.scale(t.position,(null==e?void 0:e.x)||1,(null==e?void 0:e.y)||1)},!0);if(null!=(null===(i=n.hitItems)||void 0===i?void 0:i.hits)&&n.hitItems.hits.length>0&&null!=n.hitItems.hits[0].hitPoint){const i=this.sceneProvider().camera(),e=n.hitItems.hits[0];null!=e.hitPoint&&null!=e.hitPoint.x&&null!=e.hitPoint.y&&null!=e.hitPoint.z?await this.stream.flyTo({camera:H(i.update({lookAt:o.create(e.hitPoint.x,e.hitPoint.y,e.hitPoint.z)}).toFrameCamera()),animation:{duration:v(this.configProvider().animation.durationMs)}}):console.debug(`No hit position found for fly to position [position={x: ${t.position.x}, y: ${t.position.y}}, hit-id={${null===(s=e.itemId)||void 0===s?void 0:s.hex}}]`)}else console.debug(`No hit results found for fly to position [position={x: ${t.position.x}, y: ${t.position.y}}]`)}}const ct=[.2,.15,.25,.25,.15];class dt{constructor(t,i,s,e,n,h,o,a,r,l){this.downEvent=t,this.upEvent=i,this.moveEvent=s,this.rotateInteraction=e,this.rotatePointInteraction=n,this.zoomInteraction=h,this.panInteraction=o,this.twistInteraction=a,this.pivotInteraction=r,this.getConfig=l,this.primaryInteraction=this.rotateInteraction,this.isDragging=!1,this.keyboardControls=!1,this.disableIndividualInteractions=!1,this.primaryInteractionTypeChange=new y,this.handleDownEvent=this.handleDownEvent.bind(this),this.handleMouseWheel=this.handleMouseWheel.bind(this),this.handleWindowMove=this.handleWindowMove.bind(this),this.handleWindowUp=this.handleWindowUp.bind(this),this.handleDoubleClick=this.handleDoubleClick.bind(this)}initialize(t,i){this.element=t,this.interactionApi=i,t.addEventListener(this.downEvent,this.handleDownEvent),t.addEventListener("mousedown",this.handleDoubleClick),t.addEventListener("wheel",this.handleMouseWheel)}dispose(){var t,i,s;null===(t=this.element)||void 0===t||t.removeEventListener(this.downEvent,this.handleDownEvent),null===(i=this.element)||void 0===i||i.removeEventListener("mousedown",this.handleDoubleClick),null===(s=this.element)||void 0===s||s.removeEventListener("wheel",this.handleMouseWheel),this.element=void 0}onPrimaryInteractionTypeChange(t){return this.primaryInteractionTypeChange.on(t)}setCurrentInteractionType(t){var i;switch(t){case"rotate":this.currentInteraction=this.rotateInteraction;break;case"zoom":this.currentInteraction=this.zoomInteraction;break;case"pan":this.currentInteraction=this.panInteraction;break;case"twist":this.currentInteraction=this.twistInteraction;break;case"rotate-point":this.currentInteraction=this.rotatePointInteraction;break;case"pivot":this.currentInteraction=this.pivotInteraction;break;default:this.currentInteraction=void 0}if(this.draggingInteraction){const t=this.draggingInteraction.getPosition();this.draggingInteraction=this.currentInteraction||this.primaryInteraction,null===(i=this.interactionApi)||void 0===i||i.resetLastAngle(),this.draggingInteraction.setPosition(t)}}getPrimaryInteractionType(){return this.primaryInteraction.getType()}getCurrentInteractionType(){return(this.currentInteraction||this.primaryInteraction).getType()}setPrimaryInteractionType(t){switch(t){case"rotate":this.primaryInteraction=this.rotateInteraction,this.lastPrimaryRotateInteraction=this.rotateInteraction;break;case"rotate-point":this.primaryInteraction=this.rotatePointInteraction,this.lastPrimaryRotateInteraction=this.rotatePointInteraction;break;case"zoom":this.primaryInteraction=this.zoomInteraction;break;case"pan":this.primaryInteraction=this.panInteraction;break;case"pivot":this.primaryInteraction=this.pivotInteraction}this.primaryInteractionTypeChange.emit()}setDefaultKeyboardControls(t){this.keyboardControls=t}handleDownEvent(t){t.preventDefault(),this.interactionTimer=window.setTimeout((()=>{this.downPosition=h.create(t.screenX,t.screenY),this.downPositionCanvas=this.getCanvasPosition(t),this.interactionTimer=void 0,null!=this.lastMoveEvent&&this.handleWindowMove(this.lastMoveEvent)}),this.getConfig().interactions.interactionDelay),window.addEventListener(this.moveEvent,this.handleWindowMove),window.addEventListener(this.upEvent,this.handleWindowUp)}handleWindowMove(t){if(null==this.interactionTimer){if(this.disableIndividualInteractions)return;const i=h.create(t.screenX,t.screenY),s=null!=this.interactionApi?this.interactionApi.pixelThreshold(this.isTouch(t)):2;null!=this.downPosition&&h.distance(i,this.downPosition)>=s&&!this.isDragging&&(this.beginDrag(t),this.isDragging=!0),this.isDragging&&this.drag(t)}this.lastMoveEvent=t}async handleWindowUp(t){this.isDragging&&(this.endDrag(t),this.isDragging=!1),null!=this.interactionTimer&&(window.clearTimeout(this.interactionTimer),this.interactionTimer=void 0),window.removeEventListener(this.moveEvent,this.handleWindowMove),window.removeEventListener(this.upEvent,this.handleWindowUp),this.lastMoveEvent=void 0}async handleDoubleClick(t){2===t.detail&&4===t.buttons&&null!=this.interactionApi&&this.interactionApi.viewAll()}beginDrag(t){var i;this.keyboardControls&&t.metaKey&&t.shiftKey?this.currentInteraction=this.rotatePointInteraction:this.keyboardControls&&t.shiftKey&&t.altKey?this.currentInteraction=this.twistInteraction:this.keyboardControls&&t.shiftKey?this.currentInteraction=this.zoomInteraction:this.keyboardControls&&(t.metaKey||t.ctrlKey)?this.currentInteraction=this.panInteraction:this.keyboardControls&&t.altKey&&(this.currentInteraction=this.rotateInteraction),1===t.buttons?this.draggingInteraction=this.currentInteraction||this.primaryInteraction:2===t.buttons?this.draggingInteraction=this.panInteraction:4===t.buttons&&(this.draggingInteraction=null!==(i=this.lastPrimaryRotateInteraction)&&void 0!==i?i:this.rotateInteraction),null!=this.draggingInteraction&&null!=this.interactionApi&&null!=this.element&&(this.zoomInteraction.endDrag(t,this.interactionApi),this.draggingInteraction.beginDrag(t,this.downPositionCanvas||h.create(t.clientX,t.clientY),this.interactionApi,this.element))}drag(t){this.currentInteraction=this.keyboardControls&&t.altKey&&t.shiftKey?this.twistInteraction:void 0,this.draggingInteraction=this.currentInteraction||this.draggingInteraction||this.primaryInteraction,null!=this.draggingInteraction&&null!=this.interactionApi&&this.draggingInteraction.drag(t,this.interactionApi)}endDrag(t){this.keyboardControls&&this.currentInteraction===this.twistInteraction&&(this.currentInteraction=void 0),null!=this.draggingInteraction&&null!=this.interactionApi&&(this.draggingInteraction.endDrag(t,this.interactionApi),this.draggingInteraction=void 0)}handleMouseWheel(t){if(t.preventDefault(),null!=this.element&&null!=this.interactionApi&&4!==t.buttons){const i=-this.wheelDeltaToPixels(t.deltaY,t.deltaMode)/10,s=this.element.getBoundingClientRect(),e=E(t,s);ct.forEach(((t,s)=>{window.setTimeout((()=>{null!=this.interactionApi&&this.zoomInteraction.zoomToPoint(e,i*t,this.interactionApi)}),2*s)}))}}wheelDeltaToPixels(t,i){null==this.computedBodyStyle&&(this.computedBodyStyle=window.getComputedStyle(document.body));const s=null==this.computedBodyStyle.fontSize||""===this.computedBodyStyle.fontSize||isNaN(parseFloat(this.computedBodyStyle.fontSize))?19.2:1.2*parseFloat(this.computedBodyStyle.fontSize);return 1===i?null==this.computedBodyStyle.lineHeight||""===this.computedBodyStyle.lineHeight||isNaN(parseFloat(this.computedBodyStyle.lineHeight))?t*s:t*parseFloat(this.computedBodyStyle.lineHeight):2===i?null==this.computedBodyStyle.height||""===this.computedBodyStyle.height||isNaN(parseFloat(this.computedBodyStyle.height))?t*window.innerHeight:t*parseFloat(this.computedBodyStyle.height):t}getCanvasPosition(t){var i;const s=null===(i=this.element)||void 0===i?void 0:i.getBoundingClientRect(),e=null!=s?h.create(s.left,s.top):void 0;return null!=e?h.subtract(h.create(t.clientX,t.clientY),e):void 0}isTouch(t){return null!=window.PointerEvent&&t instanceof PointerEvent&&"touch"===t.pointerType}}class ut{setPosition(t){this.currentPosition=t}getPosition(){return this.currentPosition}getType(){return this.type}beginDrag(t,i,s,e){}drag(t,i){}endDrag(t,i){null!=this.currentPosition&&(i.endInteraction(),this.currentPosition=void 0)}zoom(t,i){}}class vt extends ut{constructor(){super(...arguments),this.type="rotate"}beginDrag(t,i,s){null==this.currentPosition&&(this.currentPosition=h.create(t.screenX,t.screenY),s.beginInteraction())}drag(t,i){if(null!=this.currentPosition){const s=h.create(t.screenX,t.screenY),e=h.subtract(s,this.currentPosition);i.rotateCamera(e),this.currentPosition=s}}endDrag(t,i){super.endDrag(t,i)}}class wt extends ut{constructor(){super(...arguments),this.type="rotate-point"}beginDrag(t,i,s){null==this.currentPosition&&(this.currentPosition=h.create(t.screenX,t.screenY),this.startingPosition=i,s.beginInteraction())}drag(t,i){if(null!=this.currentPosition&&null!=this.startingPosition){const s=h.create(t.screenX,t.screenY),e=h.subtract(s,this.currentPosition);i.rotateCameraAtPoint(e,this.startingPosition),this.currentPosition=s}}endDrag(t,i){super.endDrag(t,i)}}class ft extends ut{constructor(t=1e3){super(),this.interactionTimeout=t,this.type="zoom",this.didTransformBegin=!1}beginDrag(t,i,s,e){if(null==this.currentPosition){this.currentPosition=h.create(t.clientX,t.clientY);const i=e.getBoundingClientRect(),n=E(t,i);this.startPt=n,s.beginInteraction()}}drag(t,i){if(null!=this.currentPosition){const s=h.create(t.clientX,t.clientY),e=h.subtract(s,this.currentPosition);null!=this.startPt&&(i.zoomCameraToPoint(this.startPt,e.y),this.currentPosition=s)}}endDrag(t,i){super.endDrag(t,i),this.stopInteractionTimer(),this.didTransformBegin=!1,this.startPt=void 0}zoom(t,i){this.operateWithTimer(i,(()=>i.zoomCamera(t)))}zoomToPoint(t,i,s){this.operateWithTimer(s,(()=>s.zoomCameraToPoint(t,i)))}beginInteraction(t){this.didTransformBegin=!0,t.beginInteraction()}endInteraction(t){this.didTransformBegin=!1,t.endInteraction()}resetInteractionTimer(t){this.stopInteractionTimer(),this.startInteractionTimer(t)}startInteractionTimer(t){this.interactionTimer=window.setTimeout((()=>{this.interactionTimer=void 0,this.endInteraction(t)}),this.interactionTimeout)}stopInteractionTimer(){null!=this.interactionTimer&&(window.clearTimeout(this.interactionTimer),this.interactionTimer=void 0)}operateWithTimer(t,i){this.didTransformBegin||this.beginInteraction(t),this.resetInteractionTimer(t),i()}}class pt extends ut{constructor(){super(...arguments),this.type="pan"}beginDrag(t,i,s,e){null==this.currentPosition&&(this.currentPosition=h.create(t.screenX,t.screenY),this.canvasRect=e.getBoundingClientRect(),s.beginInteraction())}drag(t,i){if(null!=this.currentPosition&&null!=this.canvasRect){const s=E(t,this.canvasRect);i.panCameraToScreenPoint(s),this.currentPosition=s}}endDrag(t,i){super.endDrag(t,i)}}class mt extends ut{constructor(){super(...arguments),this.type="twist"}beginDrag(t,i,s,e){this.currentPosition=h.create(t.offsetX,t.offsetY),this.canvasRect=e.getBoundingClientRect(),s.beginInteraction()}drag(t,i){const s=E(t,this.canvasRect);this.currentPosition=s,i.twistCamera(s)}endDrag(t,i){super.endDrag(t,i)}}class gt extends ut{constructor(){super(...arguments),this.type="pivot"}beginDrag(t,i,s){null==this.currentPosition&&(this.currentPosition=h.create(t.screenX,t.screenY),s.beginInteraction())}drag(t,i){if(null!=this.currentPosition){const s=h.create(t.screenX,t.screenY),e=h.subtract(s,this.currentPosition);i.pivotCamera(-.25*e.y,.25*e.x),this.currentPosition=s}}endDrag(t,i){super.endDrag(t,i)}}class yt extends dt{constructor(t,i=new vt,s=new wt,e=new ft,n=new pt,h=new mt,o=new gt){super("mousedown","mouseup","mousemove",i,s,e,n,h,o,t)}}class Ct{initialize(t,i){this.element=t,this.interactionApi=i}dispose(){this.element=void 0}handleTwoPointTouchMove(t,i){var s,e,n,o;if(null!=this.currentPosition1&&null!=this.currentPosition2){const r=h.scale(h.add(h.subtract(t,this.currentPosition1),h.subtract(i,this.currentPosition2)),.25,.25),l=.5*(h.distance(t,i)-h.distance(this.currentPosition1,this.currentPosition2)),c=d.create(h.subtract(this.currentPosition1,this.currentPosition2),h.subtract(t,i)),u=a.toDegrees(Math.atan2(d.determinant(c),d.dot(c)));null===(s=this.interactionApi)||void 0===s||s.beginInteraction(),null===(e=this.interactionApi)||void 0===e||e.zoomCamera(l),null===(n=this.interactionApi)||void 0===n||n.panCameraByDelta(r),Math.abs(u)>.5&&(null===(o=this.interactionApi)||void 0===o||o.twistCamera(u))}this.currentPosition1=t,this.currentPosition2=i}}class bt extends Ct{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;null===(t=this.element)||void 0===t||t.removeEventListener("pointerdown",this.handlePointerDown),super.dispose()}initialize(t,i){super.initialize(t,i),t.addEventListener("pointerdown",this.handlePointerDown)}handlePointerDown(t){const i=h.create(t.screenX,t.screenY);this.touchPoints=Object.assign(Object.assign({},this.touchPoints),{[t.pointerId]:i}),1===Object.keys(this.touchPoints).length&&(window.addEventListener("pointermove",this.handlePointerMove),window.addEventListener("pointerup",this.handlePointerUp))}handlePointerMove(t){null!=this.touchPoints[t.pointerId]&&(this.touchPoints[t.pointerId]=h.create(t.screenX,t.screenY));const i=Object.keys(this.touchPoints);2===i.length&&this.handleTwoPointTouchMove(this.touchPoints[i[0]],this.touchPoints[i[1]])}handlePointerUp(t){var i;delete this.touchPoints[t.pointerId];const s=Object.keys(this.touchPoints);1===s.length&&(null===(i=this.interactionApi)||void 0===i||i.endInteraction(),this.currentPosition1=void 0,this.currentPosition2=void 0),0===s.length&&(window.removeEventListener("pointermove",this.handlePointerMove),window.removeEventListener("pointerup",this.handlePointerUp))}}class It extends dt{constructor(t){super("pointerdown","pointerup","pointermove",new vt,new wt,new ft,new pt,new mt,new gt,t),this.touchPoints=new Set,this.handlePointerDown=this.handlePointerDown.bind(this),this.handlePointerUp=this.handlePointerUp.bind(this)}initialize(t,i){super.initialize(t,i),t.addEventListener("pointerdown",this.handlePointerDown)}handlePointerDown(t){this.downPosition=h.create(t.screenX,t.screenY),this.touchPoints.add(t.pointerId),1===this.touchPoints.size&&window.addEventListener("pointerup",this.handlePointerUp),2===this.touchPoints.size&&(this.disableIndividualInteractions=!0)}handlePointerUp(t){this.touchPoints.delete(t.pointerId),this.touchPoints.size<2&&(this.disableIndividualInteractions=!1),0===this.touchPoints.size&&window.removeEventListener("pointerup",this.handlePointerUp)}}class Pt{constructor(t,i,s,e){this.downEvent=t,this.upEvent=i,this.moveEvent=s,this.getConfig=e,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;null===(t=this.element)||void 0===t||t.removeEventListener(this.downEvent,this.handleDown),null===(i=this.element)||void 0===i||i.removeEventListener("touchstart",this.handleTouchStart),this.element=void 0,this.clearDoubleTapTimer(),this.clearLongPressTimer()}initialize(t,i){this.element=t,this.interactionApi=i,t.addEventListener(this.downEvent,this.handleDown),t.addEventListener("touchstart",this.handleTouchStart)}handleTouchStart(t){1===t.touches.length&&(this.setPointerPositions(h.create(t.touches[0].clientX,t.touches[0].clientY)),this.restartLongPressTimer(),window.addEventListener("touchend",this.handleTouchEnd),window.addEventListener("touchmove",this.handleTouchMove))}handleTouchMove(t){t.touches.length>0&&this.handlePointerMove(h.create(t.touches[0].clientX,t.touches[0].clientY),!0)}handleTouchEnd(t){null!=this.pointerDownPosition&&(window.removeEventListener("touchend",this.handleTouchEnd),window.removeEventListener("touchmove",this.handleTouchMove)),this.handlePointerEnd(this.pointerDownPosition)}handleDown(t){this.setPointerPositions(h.create(t.clientX,t.clientY)),this.buttons=t.buttons,this.restartLongPressTimer({altKey:t.altKey,ctrlKey:t.ctrlKey,metaKey:t.metaKey,shiftKey:t.shiftKey}),window.addEventListener(this.upEvent,this.handleUp),window.addEventListener(this.moveEvent,this.handleMove)}handleMove(t){this.handlePointerMove(h.create(t.clientX,t.clientY),this.isTouch(t))}handleUp(t){null!=this.pointerDownPosition&&(window.removeEventListener(this.upEvent,this.handleUp),window.removeEventListener(this.moveEvent,this.handleMove)),this.handlePointerEnd(h.create(t.clientX,t.clientY),{altKey:t.altKey,ctrlKey:t.ctrlKey,metaKey:t.metaKey,shiftKey:t.shiftKey},this.buttons,this.isTouch(t)),this.buttons=void 0}handlePointerMove(t,i){var s;const e=(null===(s=this.interactionApi)||void 0===s?void 0:s.pixelThreshold(i))||2;null!=this.pointerDownPosition&&h.distance(t,this.pointerDownPosition)>=e&&null==this.interactionTimer&&this.clearPositions()}handlePointerEnd(t,i={},s=0,e=!1){var n,h;null!=t&&(null!=this.longPressTimer&&this.emit(null===(n=this.interactionApi)||void 0===n?void 0:n.tap)(t,i,s),null!=this.doubleTapTimer&&null!=this.secondPointerDownPosition&&(this.emit(null===(h=this.interactionApi)||void 0===h?void 0:h.doubleTap)(t,i,s,this.secondPointerDownPosition),this.clearDoubleTapTimer())),this.pointerDownPosition=void 0,this.clearLongPressTimer()}emit(t){return(i,s={},e=0,n,o=!1)=>{var a;const r=n||this.pointerDownPosition,l=(null===(a=this.interactionApi)||void 0===a?void 0:a.pixelThreshold(o))||1;let c;null!=this.interactionTimer?c=this.getCanvasPosition(r||i):null!=r&&h.distance(r,i)<=l&&(c=this.getCanvasPosition(i)),null!=c&&null!=t&&t(c,s,e)}}getCanvasPosition(t){var i;const s=null===(i=this.element)||void 0===i?void 0:i.getBoundingClientRect(),e=null!=s?h.create(s.left,s.top):void 0;return null!=e?h.subtract(h.create(t.x,t.y),e):void 0}clearPositions(){this.pointerDownPosition=void 0,this.firstPointerDownPosition=void 0,this.secondPointerDownPosition=void 0,this.clearDoubleTapTimer(),this.clearLongPressTimer(),this.clearInteractionTimer()}clearDoubleTapTimer(){null!=this.doubleTapTimer&&window.clearTimeout(this.doubleTapTimer),this.doubleTapTimer=void 0,this.firstPointerDownPosition=void 0,this.secondPointerDownPosition=void 0}restartDoubleTapTimer(){this.clearDoubleTapTimer(),this.doubleTapTimer=window.setTimeout((()=>this.clearDoubleTapTimer()),this.getConfig().events.doubleTapThreshold)}clearLongPressTimer(){null!=this.longPressTimer&&window.clearTimeout(this.longPressTimer),this.longPressTimer=void 0}restartLongPressTimer(t={}){this.clearLongPressTimer(),this.longPressTimer=window.setTimeout((()=>{var i;this.pointerDownPosition&&this.emit(null===(i=this.interactionApi)||void 0===i?void 0:i.longPress)(this.pointerDownPosition,t,this.buttons),this.clearLongPressTimer()}),this.getConfig().events.longPressThreshold)}restartInteractionTimer(){this.clearInteractionTimer(),this.interactionTimer=window.setTimeout((()=>{this.interactionTimer=void 0}),this.getConfig().interactions.interactionDelay)}clearInteractionTimer(){null!=this.interactionTimer&&(window.clearTimeout(this.interactionTimer),this.interactionTimer=void 0)}setPointerPositions(t){this.pointerDownPosition=t,this.restartInteractionTimer(),null==this.firstPointerDownPosition?(this.restartDoubleTapTimer(),this.firstPointerDownPosition=t):this.secondPointerDownPosition=t}isTouch(t){return null!=window.PointerEvent&&t instanceof PointerEvent&&"touch"===t.pointerType}}class Tt extends Ct{constructor(){super(),this.handleTouchStart=this.handleTouchStart.bind(this),this.handleTouchMove=this.handleTouchMove.bind(this),this.handleTouchEnd=this.handleTouchEnd.bind(this)}dispose(){var t;null===(t=this.element)||void 0===t||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){const i=t.touches[0],s=t.touches[1];this.currentPosition1=h.create(i.screenX,i.screenY),this.currentPosition2=null!=s?h.create(s.screenX,s.screenY):void 0,window.addEventListener("touchmove",this.handleTouchMove,{passive:!1}),window.addEventListener("touchend",this.handleTouchEnd)}}handleTouchMove(t){if(1===t.touches.length)this.handleOnePointTouchMove(t.touches[0]);else if(2===t.touches.length){const i=h.create(t.touches[0].clientX,t.touches[0].clientY),s=h.create(t.touches[1].clientX,t.touches[1].clientY);this.handleTwoPointTouchMove(i,s)}}handleTouchEnd(t){var i;null===(i=this.interactionApi)||void 0===i||i.endInteraction(),this.isInteracting=!1,window.removeEventListener("touchmove",this.handleTouchMove),window.removeEventListener("touchend",this.handleTouchEnd)}handleOnePointTouchMove(t){var i,s,e;const n=h.create(t.screenX,t.screenY);if(null!=this.currentPosition1){const t=h.subtract(n,this.currentPosition1),o=(null===(i=this.interactionApi)||void 0===i?void 0:i.pixelThreshold(!0))||2;(h.distance(n,this.currentPosition1)>=o||this.isInteracting)&&(null===(s=this.interactionApi)||void 0===s||s.beginInteraction(),null===(e=this.interactionApi)||void 0===e||e.rotateCamera(t),this.isInteracting=!0)}this.currentPosition1=n}}const Dt=new class{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(null!=(i=t)&&i.then instanceof Function&&i.catch instanceof Function&&i.finally instanceof Function){const i=this.begin();return t.finally((()=>this.end(i)))}if("function"==typeof t){const i=this.begin(),s=t();return this.end(i),s}throw new Error("Input must be a function or Promise");var i}takeMeasurements(){const t=this.perf.getEntriesByName(this.name);return this.clearMeasurements(),t}takeLastMeasurement(){const t=this.takeMeasurements();return t[t.length-1]}begin(){const t=`${this.name}-${this.nextId++}`;return this.measures.add(t),this.perf.mark(t),t}end(t){this.perf.measure(this.name,t),this.perf.clearMarks(t),this.measures.delete(t)}}("paint_time");function St(t,i,s,e,n=1e3){let h,o,a=0,r=[];return s&&setInterval((()=>{if(null!=o){5===r.length?r=[...r.slice(1),o]:r.push(o);const t=r.reduce(((t,i)=>t+i))/r.length;console.debug(`Paint rate: ${o}fps`),console.debug(`Paint rate (avg): ${t}`),o=void 0}}),1e3),s=>(a++,null==h&&(h=setInterval((()=>{!function(t,i){const s=t.takeMeasurements();s.length>0&&i(s)}(t,e),0===a&&null!=h&&(clearInterval(h),h=void 0)}),n)),t.measure((async()=>{const t=await i(s);return o=null==o?1:o+1,t})).finally((()=>{a--})))}var xt;!function(t){t.DEVICE_ID="vertexvis:device-id"}(xt||(xt={}));class kt extends f{constructor(t,i={}){var s,e,n;super(t,{loggingEnabled:i.loggingEnabled}),this.state={type:"disconnected"},this.stateChanged=new y,this.dimensions=u.create(0,0),this.streamAttributes={},this.frameBgColor=b.create(255,255,255),this.config=x("platprod"),this.options={tokenRefreshOffsetInSeconds:null!==(s=i.tokenRefreshOffsetInSeconds)&&void 0!==s?s:30,offlineThresholdInSeconds:null!==(e=i.offlineThresholdInSeconds)&&void 0!==e?e:30,loadTimeoutInSeconds:null!==(n=i.loadTimeoutInSeconds)&&void 0!==n?n:15}}getState(){return this.state}disconnect(){"disconnected"!==this.state.type&&"connection-failed"!==this.state.type&&(console.debug("Disconnecting websocket"),this.state.connection.dispose(),this.updateState({type:"disconnected"}))}async load(t,i,s,e=x("platprod")){return this.clientId=i,this.deviceId=s,this.config=e,"disconnected"===this.state.type||"connection-failed"===this.state.type?this.loadIfDisconnected(t):this.loadIfConnectingOrConnected(t,this.state)}update(t){this.frameBgColor=t.frameBgColor?t.frameBgColor:this.frameBgColor,null!=t.dimensions&&t.dimensions!==this.dimensions&&(this.dimensions=t.dimensions,this.ifState("connected",(()=>this.updateDimensions({dimensions:this.dimensions})))),null!=t.streamAttributes&&this.streamAttributes!==t.streamAttributes&&(this.streamAttributes=t.streamAttributes,this.ifState("connected",(()=>this.updateStream({streamAttributes:Et(this.streamAttributes)}))))}async loadIfConnectingOrConnected(t,i){var s;const{resource:e,subResource:n}=i.resource,h=tt(t),o=!I.isEqual(e,h.resource),a=!I.isEqual(n,h.subResource),r="connecting"===i.type||"reconnecting"===i.type,l="connected"===i.type,c=h.queries.find((t=>"supplied-id"===t.type));if(o||r&&a)return this.disconnect(),this.loadIfDisconnected(t);if(l&&a&&"scene-view-state"===(null===(s=h.subResource)||void 0===s?void 0:s.type)){const t=Object.assign(Object.assign({},null!=h.subResource.id?{sceneViewStateId:{hex:h.subResource.id}}:{}),null!=c?{sceneViewStateSuppliedId:{value:c.id}}:{});await this.loadSceneViewState(t),this.updateState(Object.assign(Object.assign({},i),{resource:h}))}}async loadIfDisconnected(t){try{await this.connectWithNewStream(tt(t))}catch(t){throw this.updateState(t instanceof j?{type:"connection-failed",message:`Cannot load scene. ${t.message}`,error:t}:t instanceof p?{type:"connection-failed",message:"Cannot load scene. Stream request failed to start stream.",error:t}:{type:"connection-failed",message:"Cannot load scene for unknown reason. See console logs.",error:t}),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,s,{maxRetries:e=3}={}){const n=(h=function(t,i,s,e){return P.appendPath(null!=s?P.toString(P.parseAndAddParams("/ws",{clientId:s,deviceId:e})):`/stream-keys/${i.id}/session`,P.parse(t.network.renderingHost))}(this.config,t.resource,this.clientId,this.deviceId),{url:P.toString(h),protocols:["ws.vertexvis.com"]});var h;console.debug(`Initiating WS connection [uri=${n.url}]`);const o=new AbortController,a=(r=this.config,{EXPERIMENTAL_frameDelivery:Object.assign(Object.assign({},r.EXPERIMENTAL_frameDelivery),{rateLimitingEnabled:r.flags.throttleFrameDelivery}),EXPERIMENTAL_adaptiveRendering:Object.assign(Object.assign({},r.EXPERIMENTAL_adaptiveRendering),{enabled:r.flags.adaptiveRendering}),EXPERIMENTAL_qualityOfService:Object.assign({},r.EXPERIMENTAL_qualityOfService)});var r;this.updateState({type:i,resource:t,connection:{dispose:()=>{this.dispose(),o.abort()}}});const l=await T.abort(o.signal,T.retry((()=>this.connect(n,a)),{maxRetries:e,delaysInMs:kt.WS_RECONNECT_DELAYS})).catch((t=>{throw new R("Websocket connection failed.",t instanceof Error?t:void 0)}));if(!l.aborted)return this.requestNewOrExistingStream(t,l.result,s);this.updateState({type:"disconnected"})}async requestNewOrExistingStream(t,i,s){const e=this.requestClock(),n=await s();console.debug(`Stream connected [stream-id=${n.streamId}, scene-id=${n.sceneId}, scene-view-id=${n.sceneViewId}]`);const h=this.onRequest((t=>{const i=t.request.drawFrame;if(null!=i){const t=q(n.worldOrientation)(i);"connected"===this.state.type&&this.updateState(Object.assign(Object.assign({},this.state),{frame:t}))}})),o=this.reconnectWhenNeeded(),a=this.refreshTokenWhenExpired(n.token),r=this.acknowledgeFrameRequests(),l=null==n.frame?await this.waitForFrame(n.worldOrientation,this.options.loadTimeoutInSeconds):n.frame,c=await e;console.debug(`Synchronized clocks [local-time=${c.knownLocalTime.toISOString()}, remote-time=${c.knownRemoteTime.toISOString()}]`),this.updateState({type:"connected",connection:{dispose:()=>{o.dispose(),h.dispose(),a.dispose(),r.dispose(),i.dispose()}},resource:t,streamId:n.streamId,deviceId:n.deviceId,sceneId:n.sceneId,sceneViewId:n.sceneViewId,worldOrientation:n.worldOrientation,token:n.token,frame:l,clock:c})}async requestNewStream(t){var i,s;const e=t.queries.find((t=>"supplied-id"===t.type)),n=U(await this.startStream({streamKey:{value:t.resource.id},dimensions:this.dimensions,frameBackgroundColor:Ot(this.frameBgColor),streamAttributes:Et(this.streamAttributes),sceneViewStateId:"scene-view-state"===(null===(i=t.subResource)||void 0===i?void 0:i.type)&&null!=t.subResource.id?{hex:t.subResource.id}:void 0,sceneViewStateSuppliedId:"scene-view-state"===(null===(s=t.subResource)||void 0===s?void 0:s.type)&&null!=e?{value:e.id}:void 0}));return{resource:t,streamId:n.streamId,sceneId:n.sceneId,sceneViewId:n.sceneViewId,deviceId:n.sessionId,token:n.token,worldOrientation:n.worldOrientation,frame:void 0}}async requestReconnectStream(t){const i=G(await this.reconnect({streamId:{hex:t.streamId},dimensions:this.dimensions,frameBackgroundColor:Ot(this.frameBgColor),streamAttributes:Et(this.streamAttributes)}));return Object.assign(Object.assign({},t),{token:i.token})}async requestClock(){const t=_(await this.syncTime({requestTime:m()}));return new it(t)}reconnectWhenNeeded(){const t=this.onClose((()=>{"connected"===this.state.type&&this.closeAndReconnect(this.state)})),i=this.onRequest((t=>{null!=t.request.gracefulReconnection&&"connected"===this.state.type&&(console.debug("Received request for graceful reconnect. Closing connection and attempting reconnect."),this.closeAndReconnect(this.state))})),s=this.reconnectWhenOffline();return{dispose:()=>{t.dispose(),i.dispose(),s.dispose()}}}refreshTokenWhenExpired(t){let i;const s=t=>{const{tokenRefreshOffsetInSeconds:e}=this.options,n=t.remainingTimeInMs(e);i=window.setTimeout((async()=>{const t=await this.refreshToken(),i=J(t);s(i),"connected"===this.state.type&&this.updateState(Object.assign(Object.assign({},this.state),{token:i}))}),n)};return s(t),{dispose:()=>clearTimeout(i)}}reconnectWhenOffline(){let t;const i=()=>window.clearTimeout(t),s=()=>{i();const s=this.options.offlineThresholdInSeconds;console.debug(`Detected that host is offline. Will attempt reconnect in ${s}s.`),t=window.setTimeout((()=>{"connected"===this.state.type&&this.closeAndReconnect(this.state)}),1e3*s)};return window.addEventListener("offline",(()=>s())),window.addEventListener("online",(()=>{console.debug("Detected that host is online."),i()})),{dispose:()=>{i(),window.removeEventListener("offline",s),window.removeEventListener("online",i)}}}closeAndReconnect(t){return t.connection.dispose(),this.connectToExistingStream(t)}async waitForFrame(t,i){let s;try{return await T.timeout(1e3*i,new Promise((i=>{s=this.onRequest((e=>{try{const n=e.request.drawFrame;if(null!=n){const s=q(t)(n);i(s)}}finally{null==s||s.dispose()}}))})))}catch(t){throw new A(`Frame timed out after ${i/1e3}s`,t instanceof Error?t:void 0)}finally{null==s||s.dispose()}}acknowledgeFrameRequests(){return this.onRequest(function(t,i){const s=function(t){let i=!1;return s=>{const e=t();if(null!=e){const t=e.remoteTime(new Date(Date.now())),n=v(s,t);return w(n).getTime()>=0?n:void(i||(console.warn(`Possible erroneous send to receive timing. Muting for 60s. [sent-at=${s.toISOString()}, received-at=${t.toISOString()}, remote-time=${e.knownRemoteTime.toISOString()}]`),i=!0,setTimeout((()=>i=!1),6e4)))}}}(i);return e=i=>{return e=()=>e=>{const n=w(e.sentAtTime);null!=n&&t.replyResult(i,{drawFrame:{sendToReceiveDuration:s(n)}})},t=>{const{drawFrame:i}=t.request;null!=i&&e()(t)};var e},t=>{var i;const s=null===(i=t.request.requestId)||void 0===i?void 0:i.value;null!=s&&e(s)(t)};var e}(this,(()=>"connected"===this.state.type?this.state.clock:void 0)))}updateState(t){this.state!==t&&(this.state=t,this.stateChanged.emit(this.state))}ifState(t,i){if(this.state.type===t)return i()}onStateChanged(t){return this.stateChanged.on(t)}}kt.WS_RECONNECT_DELAYS=[0,1e3,1e3,5e3];const Et=C.ifInvalidThrow(W),Ot=C.ifInvalidThrow(V),Mt=class{constructor(s){t(this,s),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.deviceIdChange=i(this,"deviceIdChange",7),this.dimensionschange=i(this,"dimensionschange",7),this.configEnv="platprod",this.cameraControls=!0,this.cameraType="perspective",this.keyboardControls=!0,this.rotateAroundTapPoint=!0,this.experimentalGhostingOpacity=0,this.noDefaultLights=!1,this.experimentalRenderingOptions="",this.resizeDebounce=100,this.stencilBuffer=new et(this.hostElement),this.viewport=Z.fromDimensions(u.create(0,0)),this.stateMap={cursorManager:new k,streamState:{type:"disconnected"}},this.interactionHandlers=[],this.defaultInteractionHandlerDisposables=[],this.tapKeyInteractions=[],this.defaultTapKeyInteractions=[],this.internalFrameDrawnDispatcher=new y,this.handleElementResize=this.handleElementResize.bind(this)}componentWillLoad(){var t;this.updateResolvedConfig(),this.calculateComponentDimensions(),this.resizeObserver=new ResizeObserver(this.handleElementResize),this.registerSlotChangeListeners(),this.stream=null!==(t=this.stream)&&void 0!==t?t:new kt(new g,{loggingEnabled:this.getResolvedConfig().flags.logWsMessages}),this.addStreamListeners(),this.updateStreamAttributes(),this.stateMap.cursorManager.onChanged.on((()=>this.handleCursorChanged()))}componentDidLoad(){var t;this.interactionApi=this.createInteractionApi(),null!=this.containerElement&&(null===(t=this.resizeObserver)||void 0===t||t.observe(this.containerElement)),null!=this.src&&this.load(this.src).catch((t=>{console.error("Error loading scene",t)})),this.initializeDefaultInteractionHandlers(),this.injectViewerApi()}render(){var t;return s(e,null,s("div",{class:"viewer-container",style:{cursor:O(null!==(t=this.cursor)&&void 0!==t?t:"")},onContextMenu:t=>t.preventDefault()},s("div",{ref:t=>this.containerElement=t,class:S("canvas-container",{"enable-pointer-events ":null!=window.PointerEvent})},s("canvas",{ref:t=>{this.canvasElement=t,this.stateMap.interactionTarget=t},class:"canvas"}),null!=this.errorMessage?s("div",{class:"error-message"},this.errorMessage):null),s("slot",null)))}async dispatchFrameDrawn(t){this.frame=t,this.internalFrameDrawnDispatcher.emit(t),this.frameDrawn.emit(t)}async registerInteractionHandler(t){return this.interactionHandlers.push(t),this.initializeInteractionHandler(t),{dispose:()=>{const i=this.interactionHandlers.indexOf(t);-1!==i&&(this.interactionHandlers[i].dispose(),this.interactionHandlers.splice(i,1))}}}async registerTapKeyInteraction(t){this.tapKeyInteractions=[...this.tapKeyInteractions,t]}async getInteractionTarget_DEPRECATED(){if(null!=this.stateMap.interactionTarget)return this.stateMap.interactionTarget;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){null!=t?this.load(t):this.unload()}handleCameraControlsChanged(){this.initializeDefaultCameraInteractionHandlers()}handleKeyboardControlsChanged(){this.initializeDefaultKeyboardInteractionHandlers()}handleRotateAboutTapPointChanged(){var t,i;this.updateStreamAttributes(),this.rotateAroundTapPoint?null===(t=this.baseInteractionHandler)||void 0===t||t.setPrimaryInteractionType("rotate-point"):null===(i=this.baseInteractionHandler)||void 0===i||i.setPrimaryInteractionType("rotate")}handleCameraTypeChanged(t,i){t!==i&&this.updateCameraType()}handleDepthBuffersChanged(){this.updateStreamAttributes()}handleExperimentalGhostingOpacityChanged(){this.updateStreamAttributes()}handleNoDefaultLightsChanged(){this.updateStreamAttributes()}handleExperimentalRenderingOptionsChanged(){this.updateStreamAttributes()}handleFeatureLinesChanged(){this.updateStreamAttributes()}handleSelectionHighlightingChanged(){this.updateStreamAttributes()}handleFeatureHighlightingChanged(){this.updateStreamAttributes()}handleFeatureMapsChanged(){this.updateStreamAttributes()}handleConfigChanged(){this.updateResolvedConfig()}handleConfigEnvChanged(){this.updateResolvedConfig()}async load(t){var i;if(null==this.stream||null==this.dimensions)throw new F("Cannot load scene. Viewer has not been initialized.");this.calculateComponentDimensions(),this.stream.update({streamAttributes:this.getStreamAttributes(),config:x(this.configEnv,this.config),dimensions:this.dimensions,frameBgColor:this.getBackgroundColor()}),await(null===(i=this.stream)||void 0===i?void 0:i.load(t,this.clientId,this.getDeviceId(),this.getResolvedConfig())),this.sceneReady.emit()}async unload(){if(null!=this.stream&&(this.stream.disconnect(),this.frame=void 0,this.errorMessage=void 0),null!=this.canvasElement){const t=this.canvasElement.getContext("2d");null!=t&&t.clearRect(0,0,this.canvasElement.width,this.canvasElement.height)}}async scene(){return this.createScene()}async isSceneReady(){return"connected"===this.stateMap.streamState.type}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){t.length>0&&null!=this.dimensions&&!u.isEqual(t[0].contentRect,this.viewport)&&(null!=this.resizeTimer&&(clearTimeout(this.resizeTimer),this.resizeTimer=void 0),this.isResizing||(this.resizeTimer=setTimeout((()=>{this.isResizing=!0,this.isResizeUpdate=!0,this.recalculateComponentDimensions()}),this.resizeDebounce)))}registerSlotChangeListeners(){this.mutationObserver=new MutationObserver((()=>this.injectViewerApi())),this.mutationObserver.observe(this.hostElement,{childList:!0,subtree:!0})}injectViewerApi(){function t(t){return Array.from(t.querySelectorAll("*"))}t(this.hostElement).filter((t=>t.nodeName.startsWith("VERTEX-"))).reduce(((i,s)=>[...i,s,...t(s)]),[]).forEach((t=>{t.viewer=this.hostElement}))}calculateComponentDimensions(){var t;const i=this.getBounds();if(null!=(null==i?void 0:i.width)&&null!=(null==i?void 0:i.height)){const s=u.create(i.width,i.height),e=u.scaleFit(2073600,s);this.hostDimensions=s,this.dimensions=null!=e?u.create(e.width,e.height):void 0,this.viewport=Z.fromDimensions(null!==(t=this.getCanvasDimensions())&&void 0!==t?t:u.create(0,0))}}recalculateComponentDimensions(){var t;this.isResizing&&(this.calculateComponentDimensions(),this.isResizing=!1,"connected"===(null===(t=this.stream)||void 0===t?void 0:t.getState().type)&&this.updateDimensions(this.dimensions))}reportPerformance(t){if("connected"===this.stateMap.streamState.type){const i={timings:t.map((t=>({receiveToPaintDuration:v(t.duration)})))};this.getStream().recordPerformance(i,!1)}}addStreamListeners(){this.stateMap.streamListeners=this.getStream().stateChanged.on((t=>{this.handleStreamStateChanged(this.stateMap.streamState,t)}))}handleStreamStateChanged(t,i){this.stateMap.streamState=i,"connecting"===i.type?this.handleConnecting(t,i):"connected"===i.type?this.handleConnected(t,i):"connection-failed"===i.type?this.handleConnectionFailed(t,i):"disconnected"===i.type&&this.handleDisconnected(t,i)}handleConnecting(t,i){"connecting"!==t.type&&(this.token=void 0,this.errorMessage=void 0,this.emitConnectionChange({status:"connecting"}))}handleConnected(t,i){this.token=i.token.token,"connected"!==t.type&&(this.errorMessage=void 0,this.canvasRenderer=St(Dt,function(){let t=[];function i(i){if(null!=i){const s=i.copy({correlationIds:[...i.correlationIds,...t.filter((t=>!i.correlationIds.includes(t)))]});return t=[],s}return i}const s=function(){let t=-1;return async i=>{if(i.frame.sequenceNumber>t){const n=await(s=i.frame.image.imageBytes,null!=window.createImageBitmap?async function(t){const i=new Blob([t]),s=await window.createImageBitmap(i);return{image:s,dispose:()=>s.close()}}(s):(e=s,new Promise(((t,i)=>{const s=new Blob([e]),n=URL.createObjectURL(s),h=new Image;h.addEventListener("load",(()=>{t({image:h,dispose:()=>{}}),URL.revokeObjectURL(n)})),h.addEventListener("error",(()=>{i(new M("Failed to load image data")),URL.revokeObjectURL(n)})),h.src=n}))));return t=i.frame.sequenceNumber,n}var s,e}}(),e=function(){let t=-1;return async(i,s)=>{var e;if(null!=s&&i.frame.sequenceNumber>t)return t=i.frame.sequenceNumber,null===(e=i.beforeDraw)||void 0===e||e.call(i),function(t,i){const s=i.viewport.calculateDrawRect(i.frame.image);i.canvas.clearRect(0,0,i.canvasDimensions.width,i.canvasDimensions.height),i.canvas.drawImage(t.image,s.x,s.y,s.width,s.height)}(s,i),s.dispose(),i.frame;null==s||s.dispose()}}();return async n=>{var h,o;const a=null===(o=null===(h=n.predicate)||void 0===h?void 0:h.call(n))||void 0===o||o;if(t=[...t,...n.frame.correlationIds],a)return s(n).then((t=>e(n,t).then(i)))}}(),this.getResolvedConfig().flags.logFrameRate,(t=>this.reportPerformance(t))),this.emitConnectionChange({status:"connected",jwt:i.token.token}),this.deviceIdChange.emit(i.deviceId)),this.frame!==i.frame&&this.updateFrame(i.frame),this.updateDimensions(this.dimensions)}handleConnectionFailed(t,i){"connection-failed"!==t.type&&(this.token=void 0,this.errorMessage=i.message)}handleDisconnected(t,i){"disconnected"!==t.type&&(this.token=void 0,this.errorMessage=void 0,this.emitConnectionChange({status:"disconnected"}))}updateDimensions(t){var i;null===(i=this.stream)||void 0===i||i.update({dimensions:t}),this.dimensionschange.emit(t)}async updateFrame(t){const i=this.getCanvasDimensions();if(null!=this.canvasElement&&null!=i&&this.frame!==t){const s=this.canvasElement.getContext("2d");if(null!=s){const e=this.frame;this.frame=t,this.updateInteractionApi(e);const n={canvas:s,canvasDimensions:i,dimensions:this.dimensions,frame:this.frame,viewport:this.viewport,beforeDraw:()=>{this.updateCanvasDimensions(i),this.isResizeUpdate=!1},predicate:()=>!this.isResizeUpdate||null==this.dimensions||u.isEqual(this.dimensions,n.frame.image.imageAttr.frameDimensions)};this.frameReceived.emit(this.frame),this.frame.scene.hasChanged&&this.sceneChanged.emit();const h=await this.canvasRenderer(n);null!=h&&this.dispatchFrameDrawn(h)}}}async initializeDefaultInteractionHandlers(){var t;await this.initializeDefaultCameraInteractionHandlers(),await this.initializeDefaultTapInteractionHandler(),this.initializeDefaultKeyboardInteractionHandlers(),this.rotateAroundTapPoint&&(null===(t=this.baseInteractionHandler)||void 0===t||t.setPrimaryInteractionType("rotate-point"))}clearDefaultCameraInteractionHandlers(){this.defaultInteractionHandlerDisposables.forEach((t=>t.dispose())),this.defaultInteractionHandlerDisposables=[]}clearDefaultKeyboardInteractions(){this.defaultTapKeyInteractions.forEach((t=>{const i=this.tapKeyInteractions.indexOf(t);-1!==i&&this.tapKeyInteractions.splice(i,1)})),this.tapKeyInteractions=[]}async initializeDefaultCameraInteractionHandlers(){var t,i;if(this.clearDefaultCameraInteractionHandlers(),this.cameraControls)if(null!=window.PointerEvent){this.baseInteractionHandler=null!==(t=this.baseInteractionHandler)&&void 0!==t?t:new It((()=>this.getResolvedConfig()));const i=await this.registerInteractionHandler(this.baseInteractionHandler),s=await this.registerInteractionHandler(new bt);this.defaultInteractionHandlerDisposables=[i,s]}else{this.baseInteractionHandler=null!==(i=this.baseInteractionHandler)&&void 0!==i?i:new yt((()=>this.getResolvedConfig()));const t=await this.registerInteractionHandler(this.baseInteractionHandler),s=await this.registerInteractionHandler(new Tt);this.defaultInteractionHandlerDisposables=[t,s]}}initializeDefaultKeyboardInteractionHandlers(){var t;if(this.clearDefaultKeyboardInteractions(),this.keyboardControls&&null!=this.stream){null===(t=this.baseInteractionHandler)||void 0===t||t.setDefaultKeyboardControls(this.keyboardControls);const i=new ht(this.stream,(()=>this.getResolvedConfig()),(()=>this.getImageScale())),s=new lt(this.stream,(()=>this.getResolvedConfig()),(()=>this.getImageScale()),(()=>this.createScene()));this.registerTapKeyInteraction(i),this.registerTapKeyInteraction(s),this.defaultTapKeyInteractions=[i,s]}}async initializeDefaultTapInteractionHandler(){if(null==this.tapHandlerDisposable)if(null!=window.PointerEvent){const t=new Pt("pointerdown","pointerup","pointermove",(()=>this.getResolvedConfig()));this.tapHandlerDisposable=await this.registerInteractionHandler(t)}else{const t=new Pt("mousedown","mouseup","mousemove",(()=>this.getResolvedConfig()));this.tapHandlerDisposable=await this.registerInteractionHandler(t)}}initializeInteractionHandler(t){if(null==this.stateMap.interactionTarget)throw new z("Cannot initialize interaction handler. Interaction target is undefined.");if(null==this.interactionApi)throw new z("Cannot initialize interaction handler. Interaction APi is undefined.");t.initialize(this.stateMap.interactionTarget,this.interactionApi)}createInteractionApi(){if(null==this.stream)throw new B("Cannot create interaction API. Component has not been initialized.");return null==this.frame||this.frame.scene.camera.isPerspective()?new rt(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 at(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()}))}createScene(){if("connected"!==this.stateMap.streamState.type)throw new L("Cannot create scene. Viewer stream is not connected.");const{frame:t,sceneId:i,sceneViewId:s,worldOrientation:e}=this.stateMap.streamState;return new st(this.getStream(),t,q(e),(()=>this.getImageScale()),this.viewport,i,s)}getBackgroundColor(){if(null!=this.containerElement)return function(t){const i=window.getComputedStyle(t);return b.fromCss(i.backgroundColor)}(this.containerElement)}getBounds(){return this.hostElement.getBoundingClientRect()}getCanvasDimensions(){return this.getResolvedConfig().flags.letterboxFrames?this.dimensions:this.hostDimensions}getImageScale(){const t=this.getCanvasDimensions();if(null!=this.dimensions&&null!=t)return h.create(this.dimensions.width/t.width,this.dimensions.height/t.height)}getStreamAttributes(){return{depthBuffers:this.getDepthBufferStreamAttributesValue(),experimentalGhosting:this.experimentalGhostingOpacity,noDefaultLights:this.noDefaultLights,featureLines:this.featureLines,featureHighlighting:this.featureHighlighting,featureMaps:this.featureMaps,experimentalRenderingOptions:this.experimentalRenderingOptions,selectionHighlighting:this.selectionHighlighting}}updateCanvasDimensions(t){null!=this.canvasElement&&(this.canvasElement.width=t.width,this.canvasElement.height=t.height)}updateStreamAttributes(){var t;null===(t=this.stream)||void 0===t||t.update({streamAttributes:this.getStreamAttributes()})}updateInteractionApi(t){if(null!=this.frame){const i=(null==t||t.scene.camera.isPerspective())&&this.frame.scene.camera.isOrthographic(),s=(null==t||t.scene.camera.isOrthographic())&&this.frame.scene.camera.isPerspective();(i||s)&&(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;null!=this.frame&&("orthographic"===this.cameraType&&this.frame.scene.camera.isPerspective()?null===(t=this.stream)||void 0===t||t.replaceCamera({camera:H(X(this.frame.scene.camera,this.frame.scene.boundingBox))}):"perspective"===this.cameraType&&this.frame.scene.camera.isOrthographic()&&(null===(i=this.stream)||void 0===i||i.replaceCamera({camera:H(Y(this.frame.scene.camera))})))}getDepthBufferStreamAttributesValue(){var t;return null!==(t=this.depthBuffers)&&void 0!==t?t:this.rotateAroundTapPoint?"final":void 0}updateResolvedConfig(){this.resolvedConfig=x(this.configEnv,this.config)}getResolvedConfig(){return jt("Resolved config is undefined",(()=>this.resolvedConfig))}getStream(){return jt("Stream is undefined",(()=>this.stream))}getDeviceId(){if(null==this.deviceId){try{this.deviceId=function(t,i,s=window.localStorage){const e=s.getItem(xt.DEVICE_ID);if(null!=e)return i(JSON.parse(e))}(0,(t=>t["device-id"]))}catch(t){console.warn("Cannot read device ID. Local storage is not supported.")}if(null==this.deviceId){this.deviceId=D.create();try{!function(t,i,s=window.localStorage){const e=s.getItem(t);if(null!=e){const n=Object.assign(Object.assign({},JSON.parse(e)),i);s.setItem(t,JSON.stringify(n))}else s.setItem(t,JSON.stringify(i))}(xt.DEVICE_ID,{"device-id":this.deviceId})}catch(t){console.warn("Cannot write device ID. Local storage is not supported.")}}}return this.deviceId}get hostElement(){return n(this)}static get watchers(){return{src:["handleSrcChanged"],cameraControls:["handleCameraControlsChanged"],keyboardControls:["handleKeyboardControlsChanged"],rotateAroundTapPoint:["handleRotateAboutTapPointChanged"],cameraType:["handleCameraTypeChanged"],depthBuffers:["handleDepthBuffersChanged"],experimentalGhostingOpacity:["handleExperimentalGhostingOpacityChanged"],noDefaultLights:["handleNoDefaultLightsChanged"],experimentalRenderingOptions:["handleExperimentalRenderingOptionsChanged"],featureLines:["handleFeatureLinesChanged"],selectionHighlighting:["handleSelectionHighlightingChanged"],featureHighlighting:["handleFeatureHighlightingChanged"],featureMaps:["handleFeatureMapsChanged"],config:["handleConfigChanged"],configEnv:["handleConfigEnvChanged"]}}};function jt(t,i){const s=i();if(null!=s)return s;throw new Error(t)}Mt.style=":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}.canvas-container{display:flex;justify-content:center;align-items:center;width:100%;height:100%;position:relative;background:var(--image-background, var(--viewer-background, #ffffff))}.enable-pointer-events{touch-action:none}.viewer-container{width:100%;height:100%;overflow:hidden;background:var(--viewer-background, #ffffff)}.error-message{position:absolute;top:50%;width:100%;transform:translateY(-50%);text-align:center}";export{Mt as vertex_viewer}
|