@vertexvis/viewer 0.18.0 → 0.18.1-testing.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (59) hide show
  1. package/dist/cjs/{config-ee5af2fe.js → config-ace9f5d5.js} +2 -1
  2. package/dist/cjs/config-ace9f5d5.js.map +1 -0
  3. package/dist/cjs/{controller-6914028a.js → controller-ee852f01.js} +12 -3
  4. package/dist/cjs/controller-ee852f01.js.map +1 -0
  5. package/dist/cjs/index.cjs.js +1 -1
  6. package/dist/cjs/vertex-scene-tree.cjs.entry.js +2 -2
  7. package/dist/cjs/vertex-viewer-measurement-precise.cjs.entry.js +1 -1
  8. package/dist/cjs/vertex-viewer-pin-group.cjs.entry.js +1 -1
  9. package/dist/cjs/vertex-viewer.cjs.entry.js +103 -35
  10. package/dist/cjs/vertex-viewer.cjs.entry.js.map +1 -1
  11. package/dist/collection/components/scene-tree/lib/controller.js +11 -2
  12. package/dist/collection/components/scene-tree/lib/controller.js.map +1 -1
  13. package/dist/collection/lib/interactions/interactionApi.js +0 -34
  14. package/dist/collection/lib/interactions/interactionApi.js.map +1 -1
  15. package/dist/collection/lib/interactions/interactionApiPerspective.js +103 -1
  16. package/dist/collection/lib/interactions/interactionApiPerspective.js.map +1 -1
  17. package/dist/collection/lib/types/interactions.js +1 -0
  18. package/dist/collection/lib/types/interactions.js.map +1 -1
  19. package/dist/custom-elements/index.js +114 -36
  20. package/dist/custom-elements/index.js.map +1 -1
  21. package/dist/esm/{config-65fd1bba.js → config-2b2e3f66.js} +2 -1
  22. package/dist/esm/config-2b2e3f66.js.map +1 -0
  23. package/dist/esm/{controller-1f6c87ab.js → controller-ea698f9b.js} +12 -3
  24. package/dist/esm/controller-ea698f9b.js.map +1 -0
  25. package/dist/esm/index.js +1 -1
  26. package/dist/esm/index.mjs +1 -1
  27. package/dist/esm/vertex-scene-tree.entry.js +2 -2
  28. package/dist/esm/vertex-viewer-measurement-precise.entry.js +1 -1
  29. package/dist/esm/vertex-viewer-pin-group.entry.js +1 -1
  30. package/dist/esm/vertex-viewer.entry.js +103 -35
  31. package/dist/esm/vertex-viewer.entry.js.map +1 -1
  32. package/dist/types/components/scene-tree/lib/controller.d.ts +1 -0
  33. package/dist/types/lib/interactions/interactionApi.d.ts +1 -1
  34. package/dist/types/lib/interactions/interactionApiPerspective.d.ts +3 -0
  35. package/dist/types/lib/types/interactions.d.ts +7 -0
  36. package/dist/viewer/index.esm.js +1 -1
  37. package/dist/viewer/p-0de95c4d.js +5 -0
  38. package/dist/viewer/p-0de95c4d.js.map +1 -0
  39. package/dist/viewer/{p-e2e7d01b.entry.js → p-2cca6daa.entry.js} +2 -2
  40. package/dist/viewer/{p-d8c70701.entry.js → p-2ce1d5a7.entry.js} +2 -2
  41. package/dist/viewer/{p-31c3b8d6.entry.js → p-4225576d.entry.js} +2 -2
  42. package/dist/viewer/p-5145f091.entry.js +5 -0
  43. package/dist/viewer/p-5145f091.entry.js.map +1 -0
  44. package/dist/viewer/{p-931247b6.js → p-bb131c4a.js} +2 -2
  45. package/dist/viewer/p-bb131c4a.js.map +1 -0
  46. package/dist/viewer/viewer.esm.js +1 -1
  47. package/package.json +7 -7
  48. package/dist/cjs/config-ee5af2fe.js.map +0 -1
  49. package/dist/cjs/controller-6914028a.js.map +0 -1
  50. package/dist/esm/config-65fd1bba.js.map +0 -1
  51. package/dist/esm/controller-1f6c87ab.js.map +0 -1
  52. package/dist/viewer/p-089d11bf.js +0 -5
  53. package/dist/viewer/p-089d11bf.js.map +0 -1
  54. package/dist/viewer/p-931247b6.js.map +0 -1
  55. package/dist/viewer/p-f1e718b4.entry.js +0 -5
  56. package/dist/viewer/p-f1e718b4.entry.js.map +0 -1
  57. /package/dist/viewer/{p-e2e7d01b.entry.js.map → p-2cca6daa.entry.js.map} +0 -0
  58. /package/dist/viewer/{p-d8c70701.entry.js.map → p-2ce1d5a7.entry.js.map} +0 -0
  59. /package/dist/viewer/{p-31c3b8d6.entry.js.map → p-4225576d.entry.js.map} +0 -0
@@ -22,6 +22,7 @@ export interface SceneTreeState {
22
22
  shouldShowEmptyResults?: boolean;
23
23
  filterTerm?: string;
24
24
  handshakeReceived?: boolean;
25
+ firstFetchComplete?: boolean;
25
26
  }
26
27
  interface Page {
27
28
  id: number;
@@ -149,7 +149,6 @@ export declare abstract class InteractionApi {
149
149
  * values zoom out.
150
150
  */
151
151
  zoomCamera(delta: number): Promise<void>;
152
- zoomCameraToPoint(point: Point.Point, delta: number): Promise<void>;
153
152
  /**
154
153
  * Performs a pivot operation of the scene's camera, updating the lookAt
155
154
  * while maintaining the position, and requests a new image for the
@@ -201,4 +200,5 @@ export declare abstract class InteractionApi {
201
200
  * viewer.
202
201
  */
203
202
  abstract panCameraByDelta(delta: Point.Point): Promise<void>;
203
+ abstract zoomCameraToPoint(point: Point.Point, delta: number): Promise<void>;
204
204
  }
@@ -17,5 +17,8 @@ export declare class InteractionApiPerspective extends InteractionApi {
17
17
  * viewer.
18
18
  */
19
19
  panCameraByDelta(delta: Point.Point): Promise<void>;
20
+ zoomCameraToPoint(point: Point.Point, delta: number): Promise<void>;
20
21
  transformCamera(t: CameraTransform<PerspectiveCamera>): Promise<void>;
22
+ private computeZoomDistances;
23
+ private computeZoomMinimumDistance;
21
24
  }
@@ -16,5 +16,12 @@ export interface InteractionConfig {
16
16
  * update the camera.
17
17
  */
18
18
  interactionDelay: number;
19
+ /**
20
+ * Whether the `zoomCameraToPoint` interaction through the `InteractionApiPerspective`
21
+ * will enforce a minimum distance when moving the camera. When set, the camera will be
22
+ * able to move through geometry under the cursor, rather than being restricted by the
23
+ * point under the cursor. Defaults to `true`.
24
+ */
25
+ useMinimumPerspectiveZoomDistance: boolean;
19
26
  }
20
27
  export declare const defaultInteractionConfig: InteractionConfig;
@@ -1,5 +1,5 @@
1
1
  /*!
2
2
  * Copyright (c) 2023 Vertex Software LLC. All rights reserved.
3
3
  */
4
- export{c as ColorMaterial,l as LoadableResource,S as Scene,a as SynchronizedClock}from"./p-5e8d61d9.js";export{S as SceneTreeController}from"./p-931247b6.js";export{f as fromNodeProto,i as isLoadedRow}from"./p-c5381b4a.js";export{C as CursorManager,b as boxQueryCursor,l as labelPinCursor,m as measurementCursor,a as measurementWithArrowCursor,p as pinCursor}from"./p-3a256fe9.js";export{M as MeasurementController,a as MeasurementEntity}from"./p-878d06e9.js";export{M as MeasurementModel}from"./p-867331de.js";export{M as MeasurementOverlayManager}from"./p-db85855d.js";export{m as makeMinimumDistanceResult}from"./p-99f8e7e0.js";export{A as AngleUnits,f as AreaUnits,D as DistanceUnits,F as FrameCameraBase,a as ReceivedFrame,b as ReceivedFrameImage,c as ReceivedFrameScene,d as ReceivedOrthographicCamera,e as ReceivedPerspectiveCamera}from"./p-d80260e3.js";export{E as EntityType}from"./p-e1d82323.js";export{A as ArrowMarkup,C as CircleMarkup,F as FreeformMarkup}from"./p-39d1f26c.js";export{V as Viewport}from"./p-1bb66e64.js";import{v as r,q as o,m as s}from"./p-71fbe522.js";export{T as TransformController}from"./p-4025ad8d.js";export{V as VolumeIntersectionQueryController}from"./p-3ef0121f.js";import"./p-7f54de9d.js";import"./p-d45df0c0.js";import"./p-7578885f.js";import"./p-6320532c.js";import"./p-9acf99ad.js";import"./p-9f177e78.js";const t=.9999;function n(e){const o=r.create(0,e.z,-e.y);const a=r.create(-e.z,0,e.x);const s=r.magnitudeSquared(o)>r.magnitudeSquared(a)?o:a;return r.normalize(r.cross(e,s))}function u(e,a){const p=r.dot(e,a);if(p>t){const r=n(e);const a=o.fromAxisAngle(r,Math.PI);return s.makeRotation(a)}else if(p<=-t){return s.makeIdentity()}else{const t=r.angleTo(a,e);const n=r.normalize(r.cross(e,a));return s.makeRotation(o.fromAxisAngle(n,t+Math.PI))}}function j(e,o,a,t){const n=u(e,a);const p=s.makeTranslation(t);return s.multiply(s.multiply(p,n),s.makeTranslation(r.negate(o)))}const x=Object.freeze({__proto__:null,ALMOST_ONE:t,calculateOrthogonalCoordinate:n,computeRotationMatrix:u,computeTransformationDelta:j});export{x as TransformationDelta};
4
+ export{c as ColorMaterial,l as LoadableResource,S as Scene,a as SynchronizedClock}from"./p-5e8d61d9.js";export{S as SceneTreeController}from"./p-bb131c4a.js";export{f as fromNodeProto,i as isLoadedRow}from"./p-c5381b4a.js";export{C as CursorManager,b as boxQueryCursor,l as labelPinCursor,m as measurementCursor,a as measurementWithArrowCursor,p as pinCursor}from"./p-3a256fe9.js";export{M as MeasurementController,a as MeasurementEntity}from"./p-878d06e9.js";export{M as MeasurementModel}from"./p-867331de.js";export{M as MeasurementOverlayManager}from"./p-db85855d.js";export{m as makeMinimumDistanceResult}from"./p-99f8e7e0.js";export{A as AngleUnits,f as AreaUnits,D as DistanceUnits,F as FrameCameraBase,a as ReceivedFrame,b as ReceivedFrameImage,c as ReceivedFrameScene,d as ReceivedOrthographicCamera,e as ReceivedPerspectiveCamera}from"./p-d80260e3.js";export{E as EntityType}from"./p-e1d82323.js";export{A as ArrowMarkup,C as CircleMarkup,F as FreeformMarkup}from"./p-39d1f26c.js";export{V as Viewport}from"./p-1bb66e64.js";import{v as r,q as o,m as s}from"./p-71fbe522.js";export{T as TransformController}from"./p-4025ad8d.js";export{V as VolumeIntersectionQueryController}from"./p-3ef0121f.js";import"./p-7f54de9d.js";import"./p-d45df0c0.js";import"./p-7578885f.js";import"./p-6320532c.js";import"./p-9acf99ad.js";import"./p-9f177e78.js";const t=.9999;function n(e){const o=r.create(0,e.z,-e.y);const a=r.create(-e.z,0,e.x);const s=r.magnitudeSquared(o)>r.magnitudeSquared(a)?o:a;return r.normalize(r.cross(e,s))}function u(e,a){const p=r.dot(e,a);if(p>t){const r=n(e);const a=o.fromAxisAngle(r,Math.PI);return s.makeRotation(a)}else if(p<=-t){return s.makeIdentity()}else{const t=r.angleTo(a,e);const n=r.normalize(r.cross(e,a));return s.makeRotation(o.fromAxisAngle(n,t+Math.PI))}}function j(e,o,a,t){const n=u(e,a);const p=s.makeTranslation(t);return s.multiply(s.multiply(p,n),s.makeTranslation(r.negate(o)))}const x=Object.freeze({__proto__:null,ALMOST_ONE:t,calculateOrthogonalCoordinate:n,computeRotationMatrix:u,computeTransformationDelta:j});export{x as TransformationDelta};
5
5
  //# sourceMappingURL=index.esm.js.map
@@ -0,0 +1,5 @@
1
+ /*!
2
+ * Copyright (c) 2023 Vertex Software LLC. All rights reserved.
3
+ */
4
+ import{o as e}from"./p-7f54de9d.js";import{d as t}from"./p-d727045f.js";import"./p-d80260e3.js";import"./p-e1d82323.js";const s=500;const r={durationMs:s};const i={throttleFrameDelivery:true,adaptiveRendering:true,logWsMessages:false,logFrameRate:false,letterboxFrames:false,grpcUseStreamingWebSocketTransport:true};const o={finePointerThreshold:1,coarsePointerThreshold:3,interactionDelay:75,useMinimumPerspectiveZoomDistance:true};const n={network:{apiHost:"https://platform.platprod.vertexvis.io",renderingHost:"wss://stream.platprod.vertexvis.io",sceneTreeHost:"https://scene-trees.platprod.vertexvis.io",sceneViewHost:"https://scenes.platprod.vertexvis.io"},flags:i,events:t,animation:r,interactions:o,EXPERIMENTAL_frameDelivery:{},EXPERIMENTAL_adaptiveRendering:{},EXPERIMENTAL_qualityOfService:{}};const a=Object.assign(Object.assign({},n),{network:{apiHost:"https://platform.platdev.vertexvis.io",renderingHost:"wss://stream.platdev.vertexvis.io",sceneTreeHost:"https://scene-trees.platdev.vertexvis.io",sceneViewHost:"https://scenes.platdev.vertexvis.io"}});const p=Object.assign(Object.assign({},n),{network:{apiHost:"https://platform.platstaging.vertexvis.io",renderingHost:"wss://stream.platstaging.vertexvis.io",sceneTreeHost:"https://scene-trees.platstaging.vertexvis.io",sceneViewHost:"https://scenes.platstaging.vertexvis.io"}});function c(e){switch(e){case"platdev":return a;case"platstaging":return p;default:return n}}function l(t="platprod",s){if(typeof s==="string"){s=JSON.parse(s)}const r=c(t);if(s==null){return r}else{return e.defaults(Object.assign({},s),r)}}export{l as p};
5
+ //# sourceMappingURL=p-0de95c4d.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["src/lib/types/animation.ts","src/lib/types/flags.ts","src/lib/types/interactions.ts","src/lib/config.ts"],"names":["DEFAULT_ANIMATION_DURATION","defaultAnimationConfig","durationMs","defaultFlags","throttleFrameDelivery","adaptiveRendering","logWsMessages","logFrameRate","letterboxFrames","grpcUseStreamingWebSocketTransport","defaultInteractionConfig","finePointerThreshold","coarsePointerThreshold","interactionDelay","useMinimumPerspectiveZoomDistance","config","network","apiHost","renderingHost","sceneTreeHost","sceneViewHost","flags","Flags.defaultFlags","events","Events.defaultEventConfig","animation","Animation.defaultAnimationConfig","interactions","Interactions.defaultInteractionConfig","EXPERIMENTAL_frameDelivery","EXPERIMENTAL_adaptiveRendering","EXPERIMENTAL_qualityOfService","platdevConfig","Object","assign","platstagingConfig","getEnvironmentConfig","environment","parseConfig","JSON","parse","envConfig","Objects","defaults"],"mappings":";;;wHAAA,MAAMA,EAA6B,IAgB5B,MAAMC,EAA0C,CACrDC,WAAYF,GC2BP,MAAMG,EAAsB,CACjCC,sBAAuB,KACvBC,kBAAmB,KACnBC,cAAe,MACfC,aAAc,MACdC,gBAAiB,MACjBC,mCAAoC,MCpB/B,MAAMC,EAA8C,CACzDC,qBAAsB,EACtBC,uBAAwB,EACxBC,iBAAkB,GAClBC,kCAAmC,MCCrC,MAAMC,EAAiB,CACrBC,QAAS,CACPC,QAAS,yCACTC,cAAe,qCACfC,cAAe,4CACfC,cAAe,wCAEjBC,MAAOC,EACPC,OAAQC,EACRC,UAAWC,EACXC,aAAcC,EACdC,2BAA4B,GAC5BC,+BAAgC,GAChCC,8BAA+B,IAGjC,MAAMC,EAAaC,OAAAC,OAAAD,OAAAC,OAAA,GACdnB,GAAM,CACTC,QAAS,CACPC,QAAS,wCACTC,cAAe,oCACfC,cAAe,2CACfC,cAAe,yCAInB,MAAMe,EAAiBF,OAAAC,OAAAD,OAAAC,OAAA,GAClBnB,GAAM,CACTC,QAAS,CACPC,QAAS,4CACTC,cAAe,wCACfC,cAAe,+CACfC,cAAe,6CAInB,SAASgB,EAAqBC,GAC5B,OAAQA,GACN,IAAK,UACH,OAAOL,EACT,IAAK,cACH,OAAOG,EACT,QACE,OAAOpB,YAIGuB,EACdD,EAA2B,WAC3BtB,GAEA,UAAWA,IAAW,SAAU,CAC9BA,EAASwB,KAAKC,MAAMzB,GAGtB,MAAM0B,EAAYL,EAAqBC,GAEvC,GAAItB,GAAU,KAAM,CAClB,OAAO0B,MACF,CACL,OAAOC,EAAQC,SAAQV,OAAAC,OAAA,GAAMnB,GAAU0B","sourcesContent":["const DEFAULT_ANIMATION_DURATION = 500;\n\nexport interface Animation {\n milliseconds: number;\n}\n\nexport function create(data: Partial<Animation> = {}): Animation {\n return {\n milliseconds: data.milliseconds || DEFAULT_ANIMATION_DURATION,\n };\n}\n\nexport interface AnimationConfig {\n durationMs: number;\n}\n\nexport const defaultAnimationConfig: AnimationConfig = {\n durationMs: DEFAULT_ANIMATION_DURATION,\n};\n","import { Objects } from '@vertexvis/utils';\n\ntype Flag =\n /**\n * Enables or disables a throttling of image delivery based on detected\n * network conditions.\n */\n | 'throttleFrameDelivery'\n\n /**\n * Enables or disables automatic quality adjustments of rendered frames to\n * improve the performance of delivering frames to the client.\n */\n | 'adaptiveRendering'\n\n /**\n * Enables or disables logging of WS message payloads.\n */\n | 'logWsMessages'\n\n /**\n * Toggles the logging of frame rates.\n */\n | 'logFrameRate'\n\n /**\n * Enables or disables the letterboxing of frames when the host dimensions\n * are larger than the supported maximum image size (1080p). By default\n * this option is disabled, and images will be scaled up to match the host.\n */\n | 'letterboxFrames'\n\n /**\n * Enables or disables the use of the `grpc.WebsocketTransport` for streaming\n * RPCs. By default this transport will be used, and streaming messages will\n * be sent over WebSocket.\n */\n | 'grpcUseStreamingWebSocketTransport';\n/**\n * A set of experimental features that can be enabled through the viewer's\n * config.\n */\nexport type Flags = { [K in Flag]: boolean };\n\nexport const defaultFlags: Flags = {\n throttleFrameDelivery: true,\n adaptiveRendering: true,\n logWsMessages: false,\n logFrameRate: false,\n letterboxFrames: false,\n grpcUseStreamingWebSocketTransport: true,\n};\n\nexport function createFlags(\n features: Partial<Flags>,\n fallbacks: Partial<Flags> = defaultFlags\n): Flags {\n return Objects.defaults(features, fallbacks, defaultFlags);\n}\n","export interface InteractionConfig {\n /**\n * The amount of movement required with a fine (mouse, trackpad, etc) pointer\n * input before an interaction is considered a movement that will update the\n * camera. This threshold is always scaled up based on the device's pixel ratio.\n */\n finePointerThreshold: number;\n\n /**\n * The amount of movement required with a coarse (touch, stylus, etc) pointer\n * input before an interaction is considered a movement that will update the\n * camera. This threshold is always scaled up based on the device's pixel ratio.\n */\n coarsePointerThreshold: number;\n\n /**\n * The amount of time before a movement is considered an interaction and will\n * update the camera.\n */\n interactionDelay: number;\n\n /**\n * Whether the `zoomCameraToPoint` interaction through the `InteractionApiPerspective`\n * will enforce a minimum distance when moving the camera. When set, the camera will be\n * able to move through geometry under the cursor, rather than being restricted by the\n * point under the cursor. Defaults to `true`.\n */\n useMinimumPerspectiveZoomDistance: boolean;\n}\n\nexport const defaultInteractionConfig: InteractionConfig = {\n finePointerThreshold: 1,\n coarsePointerThreshold: 3,\n interactionDelay: 75,\n useMinimumPerspectiveZoomDistance: true,\n};\n","import { FrameDeliverySettings } from '@vertexvis/stream-api';\nimport {\n AdaptiveRenderingSettings,\n QualityOfServiceSettings,\n} from '@vertexvis/stream-api';\nimport { DeepPartial, Objects } from '@vertexvis/utils';\n\nimport { Environment } from './environment';\nimport { Animation, Events, Flags, Interactions } from './types';\n\ninterface NetworkConfig {\n apiHost: string;\n renderingHost: string;\n sceneTreeHost: string;\n sceneViewHost: string;\n}\n\nexport interface Config {\n network: NetworkConfig;\n flags: Flags.Flags;\n events: Events.EventConfig;\n animation: Animation.AnimationConfig;\n interactions: Interactions.InteractionConfig;\n EXPERIMENTAL_frameDelivery: Omit<\n FrameDeliverySettings,\n 'rateLimitingEnabled'\n >;\n EXPERIMENTAL_adaptiveRendering: Omit<AdaptiveRenderingSettings, 'enabled'>;\n EXPERIMENTAL_qualityOfService: QualityOfServiceSettings;\n}\n\nexport type PartialConfig = DeepPartial<Config>;\n\nexport type ConfigProvider = () => Config;\n\nconst config: Config = {\n network: {\n apiHost: 'https://platform.platprod.vertexvis.io',\n renderingHost: 'wss://stream.platprod.vertexvis.io',\n sceneTreeHost: 'https://scene-trees.platprod.vertexvis.io',\n sceneViewHost: 'https://scenes.platprod.vertexvis.io',\n },\n flags: Flags.defaultFlags,\n events: Events.defaultEventConfig,\n animation: Animation.defaultAnimationConfig,\n interactions: Interactions.defaultInteractionConfig,\n EXPERIMENTAL_frameDelivery: {},\n EXPERIMENTAL_adaptiveRendering: {},\n EXPERIMENTAL_qualityOfService: {},\n};\n\nconst platdevConfig: Config = {\n ...config,\n network: {\n apiHost: 'https://platform.platdev.vertexvis.io',\n renderingHost: 'wss://stream.platdev.vertexvis.io',\n sceneTreeHost: 'https://scene-trees.platdev.vertexvis.io',\n sceneViewHost: 'https://scenes.platdev.vertexvis.io',\n },\n};\n\nconst platstagingConfig: Config = {\n ...config,\n network: {\n apiHost: 'https://platform.platstaging.vertexvis.io',\n renderingHost: 'wss://stream.platstaging.vertexvis.io',\n sceneTreeHost: 'https://scene-trees.platstaging.vertexvis.io',\n sceneViewHost: 'https://scenes.platstaging.vertexvis.io',\n },\n};\n\nfunction getEnvironmentConfig(environment: Environment): Config {\n switch (environment) {\n case 'platdev':\n return platdevConfig;\n case 'platstaging':\n return platstagingConfig;\n default:\n return config;\n }\n}\n\nexport function parseConfig(\n environment: Environment = 'platprod',\n config?: string | PartialConfig\n): Config {\n if (typeof config === 'string') {\n config = JSON.parse(config) as PartialConfig;\n }\n\n const envConfig = getEnvironmentConfig(environment);\n\n if (config == null) {\n return envConfig;\n } else {\n return Objects.defaults({ ...config }, envConfig);\n }\n}\n"]}
@@ -1,5 +1,5 @@
1
1
  /*!
2
2
  * Copyright (c) 2023 Vertex Software LLC. All rights reserved.
3
3
  */
4
- import{h as e,F as t,r as i,c as s,f as n,H as o,g as r}from"./p-50533a46.js";import{o as a}from"./p-71fbe522.js";import{a as l,w as d,S as h,b as c,c as u}from"./p-931247b6.js";import{p}from"./p-089d11bf.js";import{g as f}from"./p-8867dab6.js";import{i as v}from"./p-c5381b4a.js";import"./p-6320532c.js";import"./p-9acf99ad.js";import"./p-7f54de9d.js";import"./p-d45df0c0.js";import"./p-d727045f.js";import"./p-d80260e3.js";import"./p-7578885f.js";import"./p-e1d82323.js";window.requestIdleCallback=window.requestIdleCallback||function(e){var t=Date.now();return setTimeout((function(){e({didTimeout:false,timeRemaining:function(){return Math.max(0,50-(Date.now()-t))}})}),1)};window.cancelIdleCallback=window.cancelIdleCallback||function(e){clearTimeout(e)};function w(e){return e!=null&&e.nodeName==="VERTEX-SCENE-TREE-TABLE-CELL"}const m=({details:i},s)=>e("div",{class:"error"},e("div",{class:"error-section error-message"},e("span",null,i.message),i.link&&e(t,null,e("span",null," See our "),e("a",{href:i.link,target:"_blank"},"documentation")," ",e("span",null," for more information."))),e("div",{class:"error-section"},s));async function y(e,t,{suppliedCorrelationId:i}={}){const s=await e.scene();return s.items((e=>e.where((e=>e.withItemId(t))).show())).execute({suppliedCorrelationId:i})}async function b(e,t,{suppliedCorrelationId:i}={}){const s=await e.scene();return s.items((e=>e.where((e=>e.withItemId(t))).hide())).execute({suppliedCorrelationId:i})}async function g(e,t,{append:i=false,suppliedCorrelationId:s}){const n=await e.scene();return n.items((e=>[...i?[]:[e.where((e=>e.all())).deselect()],e.where((e=>e.withItemId(t))).select()])).execute({suppliedCorrelationId:s})}async function x(e,t,i,{append:s=true,suppliedCorrelationId:n}){const o=await e.scene();return o.items((e=>[...s?[]:[e.where((e=>e.all())).deselect()],e.where((e=>e.withSceneTreeRange({start:t,end:i}))).select()])).execute({suppliedCorrelationId:n})}async function C(e,t,i,s,{append:n=false,suppliedCorrelationId:o}){const r=await e.scene();return r.items((e=>[...n?[]:[e.where((e=>e.all())).deselect()],e.where((e=>e.withMetadata(t,i,s))).select()])).execute({suppliedCorrelationId:o})}async function E(e,t,{suppliedCorrelationId:i}={}){const s=await e.scene();return s.items((e=>e.where((e=>e.withItemId(t))).deselect())).execute({suppliedCorrelationId:i})}const I="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,.empty-results{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}";const R=25;const M=class{constructor(e){i(this,e);this.connectionError=s(this,"connectionError",7);this.firstRowRendered=s(this,"firstRowRendered",7);this.overScanCount=25;this.configEnv="platprod";this.metadataSearchExactMatch=false;this.metadataSearchKeys=[];this.metadataKeys=[];this.rows=[];this.totalRows=0;this.showLoader=false;this.showEmptyResults=false;this.stateMap={componentLoaded:false};this.attemptingRetry=false;this.firstCellRendered=false}async invalidateRows(){n(this.getLayoutElement())}async scrollToIndex(e,t={}){const{animate:i,position:s="middle"}=t;const n=Math.max(0,Math.min(e,this.totalRows));const o=this.getScrollToPosition(n,s);this.getLayoutElement().scrollToPosition(o,{behavior:i?"smooth":undefined})}async scrollToItem(e,t={}){var i;const s=this.totalRows;const n=await((i=this.controller)===null||i===void 0?void 0:i.expandParentNodes(e));if(n!=null&&s!==this.totalRows){return new Promise((e=>{const i=this.getLayoutElement();const s=async()=>{i.removeEventListener("layoutRendered",s);await this.scrollToIndex(n,t);e()};i.addEventListener("layoutRendered",s)}))}else if(n!=null){await this.scrollToIndex(n,t)}}async expandAll(){var e;await((e=this.controller)===null||e===void 0?void 0:e.expandAll())}async collapseAll(){var e;await((e=this.controller)===null||e===void 0?void 0:e.collapseAll())}async expandItem(e){await this.performRowOperation(e,(async({id:e,node:t})=>{var i;if(!t.expanded){await((i=this.controller)===null||i===void 0?void 0:i.expandNode(e))}}))}async collapseItem(e){await this.performRowOperation(e,(async({id:e,node:t})=>{var i;if(t.expanded){await((i=this.controller)===null||i===void 0?void 0:i.collapseNode(e))}}))}async toggleExpandItem(e){await this.performRowOperation(e,(async({node:e})=>{if(e.expanded){await this.collapseItem(e)}else{await this.expandItem(e)}}))}async toggleItemVisibility(e){await this.performRowOperation(e,(async({viewer:e,id:t,node:i})=>{if(i.visible||i.partiallyVisible){await b(e,t)}else{await y(e,t)}}))}async hideItem(e){await this.performRowOperation(e,(async({viewer:e,id:t,node:i})=>{if(i.visible){await b(e,t)}}))}async showItem(e){await this.performRowOperation(e,(async({viewer:e,id:t,node:i})=>{if(!i.visible){await y(e,t)}}))}async selectItem(e,t={}){var{recurseParent:i}=t,s=a(t,["recurseParent"]);await this.performRowOperation(e,(async({viewer:e,id:t})=>{var n,o,r,a;const l=await((n=this.controller)===null||n===void 0?void 0:n.fetchNodeAncestors(t))||[];const d=(o=this.stateMap.selectionPath)===null||o===void 0?void 0:o.includes(t);if(i&&d){const e=l.find((({selected:e})=>!e));if(e!=null){await this.selectItem(e,s);this.lastSelectedItemId=t}}else if(s.range&&this.lastSelectedItemId!=null){const i=await((r=this.controller)===null||r===void 0?void 0:r.expandParentNodes(t));const n=await((a=this.controller)===null||a===void 0?void 0:a.expandParentNodes(this.lastSelectedItemId));if(n&&i){const t=Math.min(n,i);const o=Math.max(n,i);await x(e,t,o,s)}}else{await g(e,t,s);this.lastSelectedItemId=t}this.stateMap.selectionPath=[...l.map((({id:e})=>(e===null||e===void 0?void 0:e.hex)||"")),t]}))}async deselectItem(e){await this.performRowOperation(e,(async({viewer:e,id:t,node:i})=>{if(i.selected){this.lastSelectedItemId=undefined;await E(e,t)}}))}async getRowAtIndex(e){return this.rows[e]}async getRowForEvent(e){const{clientY:t,target:i}=e;if(i!=null&&this.errorDetails==null&&f(this.el,i)&&w(i)){return this.getRowAtClientY(t)}else{return undefined}}getRowAtClientY(e){const t=this.getLayoutElement();const i=t.layoutOffset;const s=Math.floor((e-i+t.scrollOffset)/t.rowHeight);return this.getRowAtIndex(s)}async filterItems(e,t={}){var i;return(i=this.controller)===null||i===void 0?void 0:i.filter(e,t)}async selectFilteredItems(e,t){if(this.viewer!=null){const i=this.metadataSearchKeys.length>0?this.metadataSearchKeys:this.metadataKeys;if(i.length===0){console.warn("No metadata keys were found to perform the selection. Defaulting to ['VERTEX_SCENE_ITEM_NAME']")}const s=i.length>0?i:["VERTEX_SCENE_ITEM_NAME"];await C(this.viewer,e,s,this.metadataSearchExactMatch,Object.assign({append:false},t))}}async fetchMetadataKeys(){var e,t;return(t=(e=this.controller)===null||e===void 0?void 0:e.fetchMetadataKeys())!==null&&t!==void 0?t:[]}disconnectedCallback(){var e,t;(e=this.stateMap.viewerDisposable)===null||e===void 0?void 0:e.dispose();(t=this.controller)===null||t===void 0?void 0:t.cancel()}componentWillLoad(){var e;if(this.controller==null){const{sceneTreeHost:t}=this.getConfig().network;const i=new l(t,this.getConfig().flags.grpcUseStreamingWebSocketTransport?{transport:d}:undefined);this.controller=new h(i,100);(e=this.controller)===null||e===void 0?void 0:e.setMetadataKeys(this.metadataKeys)}this.stateMap.onStateChangeDisposable=this.controller.onStateChange.on((e=>this.handleControllerStateChange(e)));this.connectToViewer()}async componentDidLoad(){var e;this.ensureLayoutDefined();this.updateLayoutElement();const t=this.getLayoutElement();const i=new ResizeObserver((()=>{this.invalidateRows()}));i.observe(t);this.stateMap.resizeObserver=i;this.stateMap.componentLoaded=true;(e=this.controller)===null||e===void 0?void 0:e.setMetadataKeys(this.metadataKeys);if(this.viewer==null){this.errorDetails=new c("MISSING_VIEWER",u.MISSING_VIEWER)}}componentWillRender(){this.updateLayoutElement()}render(){return e(o,null,e("div",{class:"header"},e("slot",{name:"header"},e("vertex-scene-tree-toolbar",{class:"search-toolbar"},e("vertex-scene-tree-search",{controller:this.controller})))),this.errorDetails!=null&&this.renderError(this.errorDetails),this.errorDetails==null&&e("div",{class:"rows-scroll"},this.showLoader&&e("slot",{name:"loading"},e("vertex-viewer-spinner",{class:"loading",size:"md"})),this.showEmptyResults&&e("slot",{name:"empty-results"},e("div",{class:"empty-results"},"No Results Found.")),e("slot",null)),e("div",{class:"footer"},e("slot",{name:"footer"})))}renderError(t){if(t.code!==u.SCENE_TREE_DISABLED){return e(m,{details:t},e("button",{class:"button button-secondary",onClick:()=>this.retryConnectToViewer(),disabled:this.attemptingRetry},"Retry"))}else{return e(m,{details:t})}}handleViewerChanged(e,t){if(!this.stateMap.componentLoaded){return}this.connectToViewer()}handleControllerChanged(e){var t;if(!this.stateMap.componentLoaded){return}(t=this.stateMap.onStateChangeDisposable)===null||t===void 0?void 0:t.dispose();this.stateMap.onStateChangeDisposable=e.onStateChange.on((e=>this.handleControllerStateChange(e)));e.setMetadataKeys(this.metadataKeys)}handleMetadataKeysChanged(){var e;(e=this.controller)===null||e===void 0?void 0:e.setMetadataKeys(this.metadataKeys)}retryConnectToViewer(){this.attemptingRetry=true;this.errorDetails=undefined;this.connectToViewer()}connectToViewer(){var e,t;(e=this.stateMap.viewerDisposable)===null||e===void 0?void 0:e.dispose();if(this.viewer==null&&this.viewerSelector!=null){this.viewer=document.querySelector(this.viewerSelector)}if(this.viewer!=null){this.stateMap.viewerDisposable=(t=this.controller)===null||t===void 0?void 0:t.connectToViewer(this.viewer)}else{this.attemptingRetry=false}}scheduleClearUnusedData(){if(this.stateMap.idleCallbackId!=null){window.cancelIdleCallback(this.stateMap.idleCallbackId)}this.stateMap.idleCallbackId=window.requestIdleCallback((e=>{var t,i,s;const n=(t=e.timeRemaining)===null||t===void 0?void 0:t.call(e);if(n==null||n>=R){const e=this.getLayoutElement();const t=e.viewportStartIndex;const n=e.viewportEndIndex;const[o,r]=((i=this.controller)===null||i===void 0?void 0:i.getPageIndexesForRange(t,n))||[];if(o!=null&&r!=null){(s=this.controller)===null||s===void 0?void 0:s.invalidatePagesOutsideRange(o,r,50)}}else{this.scheduleClearUnusedData()}}))}handleControllerStateChange(e){this.showLoader=!!e.shouldShowLoading;this.showEmptyResults=!!e.shouldShowEmptyResults;this.rows=e.rows;this.totalRows=e.totalRows;if(e.connection.type==="failure"){this.errorDetails=e.connection.details;this.connectionError.emit(e.connection.details)}else if(e.connection.type==="disconnected"){this.errorDetails=new c("DISCONNECTED",u.DISCONNECTED)}else{this.errorDetails=undefined}if(e.connection.type==="connected"||e.connection.type==="failure"){this.attemptingRetry=false}}async performRowOperation(e,t){const i=typeof e==="number"?this.rows[e]:e;if(i==null){throw new Error(`Cannot perform scene tree operation. Row not found.`)}const s=v(i)?i.node:i;if(s.id==null){throw new Error(`Cannot perform scene tree operation. ID is undefined.`)}if(this.viewer==null){throw new Error(`Cannot perform scene tree operation. Cannot get reference to viewer.`)}await t({viewer:this.viewer,id:s.id.hex,node:s})}async handleSearch(e){const t=this.metadataSearchKeys.length>0?this.metadataSearchKeys:this.metadataKeys;try{await this.filterItems(e.detail,{columns:t,exactMatch:this.metadataSearchExactMatch})}catch(e){console.error("Failed to filter tree with exception: ",e)}}async handleCellLoaded(){if(!this.firstCellRendered&&this.rows.length>0){this.firstCellRendered=true;this.firstRowRendered.emit()}}getScrollToPosition(e,t){var i;const s=this.getLayoutElement();const n=Math.max(0,Math.min(e,this.totalRows-1));const o=(i=s.layoutHeight)!==null&&i!==void 0?i:0;const r=s.rowHeight;if(t==="start"){return n*r}else if(t==="middle"){const e=n*r+r/2;return e-o/2}else{const e=n*r+r;return e-o}}getConfig(){return p(this.configEnv,this.config)}ensureLayoutDefined(){let e=this.el.querySelector("vertex-scene-tree-table-layout");if(e==null){e=document.createElement("vertex-scene-tree-table-layout");e.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(e)}this.stateMap.layoutEl=e}updateLayoutElement(){const e=this.stateMap.layoutEl;if(e!=null){e.rows=this.rows;e.tree=this.el;e.totalRows=this.totalRows;e.controller=this.controller;e.rowData=this.rowData}else if(!this.stateMap.componentLoaded&&this.totalRows>0){console.debug("Scene tree has rows, but the component has not yet rendered")}}getLayoutElement(){if(this.stateMap.layoutEl!=null){return this.stateMap.layoutEl}else{throw new Error("Layout element is undefined")}}get el(){return r(this)}static get watchers(){return{viewer:["handleViewerChanged"],controller:["handleControllerChanged"],metadataKeys:["handleMetadataKeysChanged"]}}};M.style=I;export{M as vertex_scene_tree};
5
- //# sourceMappingURL=p-e2e7d01b.entry.js.map
4
+ import{h as e,F as t,r as i,c as s,f as n,H as o,g as r}from"./p-50533a46.js";import{o as a}from"./p-71fbe522.js";import{a as l,w as d,S as c,b as h,c as u}from"./p-bb131c4a.js";import{p}from"./p-0de95c4d.js";import{g as f}from"./p-8867dab6.js";import{i as v}from"./p-c5381b4a.js";import"./p-6320532c.js";import"./p-9acf99ad.js";import"./p-7f54de9d.js";import"./p-d45df0c0.js";import"./p-d727045f.js";import"./p-d80260e3.js";import"./p-7578885f.js";import"./p-e1d82323.js";window.requestIdleCallback=window.requestIdleCallback||function(e){var t=Date.now();return setTimeout((function(){e({didTimeout:false,timeRemaining:function(){return Math.max(0,50-(Date.now()-t))}})}),1)};window.cancelIdleCallback=window.cancelIdleCallback||function(e){clearTimeout(e)};function w(e){return e!=null&&e.nodeName==="VERTEX-SCENE-TREE-TABLE-CELL"}const m=({details:i},s)=>e("div",{class:"error"},e("div",{class:"error-section error-message"},e("span",null,i.message),i.link&&e(t,null,e("span",null," See our "),e("a",{href:i.link,target:"_blank"},"documentation")," ",e("span",null," for more information."))),e("div",{class:"error-section"},s));async function y(e,t,{suppliedCorrelationId:i}={}){const s=await e.scene();return s.items((e=>e.where((e=>e.withItemId(t))).show())).execute({suppliedCorrelationId:i})}async function b(e,t,{suppliedCorrelationId:i}={}){const s=await e.scene();return s.items((e=>e.where((e=>e.withItemId(t))).hide())).execute({suppliedCorrelationId:i})}async function g(e,t,{append:i=false,suppliedCorrelationId:s}){const n=await e.scene();return n.items((e=>[...i?[]:[e.where((e=>e.all())).deselect()],e.where((e=>e.withItemId(t))).select()])).execute({suppliedCorrelationId:s})}async function x(e,t,i,{append:s=true,suppliedCorrelationId:n}){const o=await e.scene();return o.items((e=>[...s?[]:[e.where((e=>e.all())).deselect()],e.where((e=>e.withSceneTreeRange({start:t,end:i}))).select()])).execute({suppliedCorrelationId:n})}async function C(e,t,i,s,{append:n=false,suppliedCorrelationId:o}){const r=await e.scene();return r.items((e=>[...n?[]:[e.where((e=>e.all())).deselect()],e.where((e=>e.withMetadata(t,i,s))).select()])).execute({suppliedCorrelationId:o})}async function E(e,t,{suppliedCorrelationId:i}={}){const s=await e.scene();return s.items((e=>e.where((e=>e.withItemId(t))).deselect())).execute({suppliedCorrelationId:i})}const I="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,.empty-results{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}";const R=25;const M=class{constructor(e){i(this,e);this.connectionError=s(this,"connectionError",7);this.firstRowRendered=s(this,"firstRowRendered",7);this.overScanCount=25;this.configEnv="platprod";this.metadataSearchExactMatch=false;this.metadataSearchKeys=[];this.metadataKeys=[];this.rows=[];this.totalRows=0;this.showLoader=false;this.showEmptyResults=false;this.stateMap={componentLoaded:false};this.attemptingRetry=false;this.firstCellRendered=false}async invalidateRows(){n(this.getLayoutElement())}async scrollToIndex(e,t={}){const{animate:i,position:s="middle"}=t;const n=Math.max(0,Math.min(e,this.totalRows));const o=this.getScrollToPosition(n,s);this.getLayoutElement().scrollToPosition(o,{behavior:i?"smooth":undefined})}async scrollToItem(e,t={}){var i;const s=this.totalRows;const n=await((i=this.controller)===null||i===void 0?void 0:i.expandParentNodes(e));if(n!=null&&s!==this.totalRows){return new Promise((e=>{const i=this.getLayoutElement();const s=async()=>{i.removeEventListener("layoutRendered",s);await this.scrollToIndex(n,t);e()};i.addEventListener("layoutRendered",s)}))}else if(n!=null){await this.scrollToIndex(n,t)}}async expandAll(){var e;await((e=this.controller)===null||e===void 0?void 0:e.expandAll())}async collapseAll(){var e;await((e=this.controller)===null||e===void 0?void 0:e.collapseAll())}async expandItem(e){await this.performRowOperation(e,(async({id:e,node:t})=>{var i;if(!t.expanded){await((i=this.controller)===null||i===void 0?void 0:i.expandNode(e))}}))}async collapseItem(e){await this.performRowOperation(e,(async({id:e,node:t})=>{var i;if(t.expanded){await((i=this.controller)===null||i===void 0?void 0:i.collapseNode(e))}}))}async toggleExpandItem(e){await this.performRowOperation(e,(async({node:e})=>{if(e.expanded){await this.collapseItem(e)}else{await this.expandItem(e)}}))}async toggleItemVisibility(e){await this.performRowOperation(e,(async({viewer:e,id:t,node:i})=>{if(i.visible||i.partiallyVisible){await b(e,t)}else{await y(e,t)}}))}async hideItem(e){await this.performRowOperation(e,(async({viewer:e,id:t,node:i})=>{if(i.visible){await b(e,t)}}))}async showItem(e){await this.performRowOperation(e,(async({viewer:e,id:t,node:i})=>{if(!i.visible){await y(e,t)}}))}async selectItem(e,t={}){var{recurseParent:i}=t,s=a(t,["recurseParent"]);await this.performRowOperation(e,(async({viewer:e,id:t})=>{var n,o,r,a;const l=await((n=this.controller)===null||n===void 0?void 0:n.fetchNodeAncestors(t))||[];const d=(o=this.stateMap.selectionPath)===null||o===void 0?void 0:o.includes(t);if(i&&d){const e=l.find((({selected:e})=>!e));if(e!=null){await this.selectItem(e,s);this.lastSelectedItemId=t}}else if(s.range&&this.lastSelectedItemId!=null){const i=await((r=this.controller)===null||r===void 0?void 0:r.expandParentNodes(t));const n=await((a=this.controller)===null||a===void 0?void 0:a.expandParentNodes(this.lastSelectedItemId));if(n&&i){const t=Math.min(n,i);const o=Math.max(n,i);await x(e,t,o,s)}}else{await g(e,t,s);this.lastSelectedItemId=t}this.stateMap.selectionPath=[...l.map((({id:e})=>(e===null||e===void 0?void 0:e.hex)||"")),t]}))}async deselectItem(e){await this.performRowOperation(e,(async({viewer:e,id:t,node:i})=>{if(i.selected){this.lastSelectedItemId=undefined;await E(e,t)}}))}async getRowAtIndex(e){return this.rows[e]}async getRowForEvent(e){const{clientY:t,target:i}=e;if(i!=null&&this.errorDetails==null&&f(this.el,i)&&w(i)){return this.getRowAtClientY(t)}else{return undefined}}getRowAtClientY(e){const t=this.getLayoutElement();const i=t.layoutOffset;const s=Math.floor((e-i+t.scrollOffset)/t.rowHeight);return this.getRowAtIndex(s)}async filterItems(e,t={}){var i;return(i=this.controller)===null||i===void 0?void 0:i.filter(e,t)}async selectFilteredItems(e,t){if(this.viewer!=null){const i=this.metadataSearchKeys.length>0?this.metadataSearchKeys:this.metadataKeys;if(i.length===0){console.warn("No metadata keys were found to perform the selection. Defaulting to ['VERTEX_SCENE_ITEM_NAME']")}const s=i.length>0?i:["VERTEX_SCENE_ITEM_NAME"];await C(this.viewer,e,s,this.metadataSearchExactMatch,Object.assign({append:false},t))}}async fetchMetadataKeys(){var e,t;return(t=(e=this.controller)===null||e===void 0?void 0:e.fetchMetadataKeys())!==null&&t!==void 0?t:[]}disconnectedCallback(){var e,t;(e=this.stateMap.viewerDisposable)===null||e===void 0?void 0:e.dispose();(t=this.controller)===null||t===void 0?void 0:t.cancel()}componentWillLoad(){var e;if(this.controller==null){const{sceneTreeHost:t}=this.getConfig().network;const i=new l(t,this.getConfig().flags.grpcUseStreamingWebSocketTransport?{transport:d}:undefined);this.controller=new c(i,100);(e=this.controller)===null||e===void 0?void 0:e.setMetadataKeys(this.metadataKeys)}this.stateMap.onStateChangeDisposable=this.controller.onStateChange.on((e=>this.handleControllerStateChange(e)));this.connectToViewer()}async componentDidLoad(){var e;this.ensureLayoutDefined();this.updateLayoutElement();const t=this.getLayoutElement();const i=new ResizeObserver((()=>{this.invalidateRows()}));i.observe(t);this.stateMap.resizeObserver=i;this.stateMap.componentLoaded=true;(e=this.controller)===null||e===void 0?void 0:e.setMetadataKeys(this.metadataKeys);if(this.viewer==null){this.errorDetails=new h("MISSING_VIEWER",u.MISSING_VIEWER)}}componentWillRender(){this.updateLayoutElement()}render(){return e(o,null,e("div",{class:"header"},e("slot",{name:"header"},e("vertex-scene-tree-toolbar",{class:"search-toolbar"},e("vertex-scene-tree-search",{controller:this.controller})))),this.errorDetails!=null&&this.renderError(this.errorDetails),this.errorDetails==null&&e("div",{class:"rows-scroll"},this.showLoader&&e("slot",{name:"loading"},e("vertex-viewer-spinner",{class:"loading",size:"md"})),this.showEmptyResults&&e("slot",{name:"empty-results"},e("div",{class:"empty-results"},"No Results Found.")),e("slot",null)),e("div",{class:"footer"},e("slot",{name:"footer"})))}renderError(t){if(t.code!==u.SCENE_TREE_DISABLED){return e(m,{details:t},e("button",{class:"button button-secondary",onClick:()=>this.retryConnectToViewer(),disabled:this.attemptingRetry},"Retry"))}else{return e(m,{details:t})}}handleViewerChanged(e,t){if(!this.stateMap.componentLoaded){return}this.connectToViewer()}handleControllerChanged(e){var t;if(!this.stateMap.componentLoaded){return}(t=this.stateMap.onStateChangeDisposable)===null||t===void 0?void 0:t.dispose();this.stateMap.onStateChangeDisposable=e.onStateChange.on((e=>this.handleControllerStateChange(e)));e.setMetadataKeys(this.metadataKeys)}handleMetadataKeysChanged(){var e;(e=this.controller)===null||e===void 0?void 0:e.setMetadataKeys(this.metadataKeys)}retryConnectToViewer(){this.attemptingRetry=true;this.errorDetails=undefined;this.connectToViewer()}connectToViewer(){var e,t;(e=this.stateMap.viewerDisposable)===null||e===void 0?void 0:e.dispose();if(this.viewer==null&&this.viewerSelector!=null){this.viewer=document.querySelector(this.viewerSelector)}if(this.viewer!=null){this.stateMap.viewerDisposable=(t=this.controller)===null||t===void 0?void 0:t.connectToViewer(this.viewer)}else{this.attemptingRetry=false}}scheduleClearUnusedData(){if(this.stateMap.idleCallbackId!=null){window.cancelIdleCallback(this.stateMap.idleCallbackId)}this.stateMap.idleCallbackId=window.requestIdleCallback((e=>{var t,i,s;const n=(t=e.timeRemaining)===null||t===void 0?void 0:t.call(e);if(n==null||n>=R){const e=this.getLayoutElement();const t=e.viewportStartIndex;const n=e.viewportEndIndex;const[o,r]=((i=this.controller)===null||i===void 0?void 0:i.getPageIndexesForRange(t,n))||[];if(o!=null&&r!=null){(s=this.controller)===null||s===void 0?void 0:s.invalidatePagesOutsideRange(o,r,50)}}else{this.scheduleClearUnusedData()}}))}handleControllerStateChange(e){this.showLoader=!!e.shouldShowLoading;this.showEmptyResults=!!e.shouldShowEmptyResults;this.rows=e.rows;this.totalRows=e.totalRows;if(e.connection.type==="failure"){this.errorDetails=e.connection.details;this.connectionError.emit(e.connection.details)}else if(e.connection.type==="disconnected"){this.errorDetails=new h("DISCONNECTED",u.DISCONNECTED)}else{this.errorDetails=undefined}if(e.connection.type==="connected"||e.connection.type==="failure"){this.attemptingRetry=false}}async performRowOperation(e,t){const i=typeof e==="number"?this.rows[e]:e;if(i==null){throw new Error(`Cannot perform scene tree operation. Row not found.`)}const s=v(i)?i.node:i;if(s.id==null){throw new Error(`Cannot perform scene tree operation. ID is undefined.`)}if(this.viewer==null){throw new Error(`Cannot perform scene tree operation. Cannot get reference to viewer.`)}await t({viewer:this.viewer,id:s.id.hex,node:s})}async handleSearch(e){const t=this.metadataSearchKeys.length>0?this.metadataSearchKeys:this.metadataKeys;try{await this.filterItems(e.detail,{columns:t,exactMatch:this.metadataSearchExactMatch})}catch(e){console.error("Failed to filter tree with exception: ",e)}}async handleCellLoaded(){if(!this.firstCellRendered&&this.rows.length>0){this.firstCellRendered=true;this.firstRowRendered.emit()}}getScrollToPosition(e,t){var i;const s=this.getLayoutElement();const n=Math.max(0,Math.min(e,this.totalRows-1));const o=(i=s.layoutHeight)!==null&&i!==void 0?i:0;const r=s.rowHeight;if(t==="start"){return n*r}else if(t==="middle"){const e=n*r+r/2;return e-o/2}else{const e=n*r+r;return e-o}}getConfig(){return p(this.configEnv,this.config)}ensureLayoutDefined(){let e=this.el.querySelector("vertex-scene-tree-table-layout");if(e==null){e=document.createElement("vertex-scene-tree-table-layout");e.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(e)}this.stateMap.layoutEl=e}updateLayoutElement(){const e=this.stateMap.layoutEl;if(e!=null){e.rows=this.rows;e.tree=this.el;e.totalRows=this.totalRows;e.controller=this.controller;e.rowData=this.rowData}else if(!this.stateMap.componentLoaded&&this.totalRows>0){console.debug("Scene tree has rows, but the component has not yet rendered")}}getLayoutElement(){if(this.stateMap.layoutEl!=null){return this.stateMap.layoutEl}else{throw new Error("Layout element is undefined")}}get el(){return r(this)}static get watchers(){return{viewer:["handleViewerChanged"],controller:["handleControllerChanged"],metadataKeys:["handleMetadataKeysChanged"]}}};M.style=I;export{M as vertex_scene_tree};
5
+ //# sourceMappingURL=p-2cca6daa.entry.js.map
@@ -1,5 +1,5 @@
1
1
  /*!
2
2
  * Copyright (c) 2023 Vertex Software LLC. All rights reserved.
3
3
  */
4
- import{h as i,F as t,r as n}from"./p-50533a46.js";import{p as o,m as e,v as s}from"./p-71fbe522.js";import"./p-931247b6.js";import"./p-3a256fe9.js";import"./p-9f177e78.js";import"./p-6320532c.js";import"./p-d80260e3.js";import"./p-e1d82323.js";import{V as r}from"./p-1bb66e64.js";import{g as l,i as a,b as p,P as h,a as d,c as v}from"./p-3fb73dd5.js";import{c}from"./p-9fe3f791.js";import"./p-9acf99ad.js";import"./p-7f54de9d.js";import"./p-d45df0c0.js";import"./p-c5381b4a.js";import"./p-7578885f.js";const u=({pin:n,selected:o})=>{const{primaryColor:e}=l(n);return i(t,null,p(n)&&i("div",{id:"pin-anchor",class:c("pin-anchor",{selected:o}),style:{background:e}}),a(n)&&i("vertex-viewer-icon",{name:"pin-fill",size:"lg",class:c("pin",{"pin-selected":o}),style:{color:e}}))};function b(i,t,n){const e={x:i.x+n.width/2,y:i.y};const s={x:i.x+n.width/2,y:i.y+n.height};const r={x:i.x+n.width,y:i.y+n.height/2};const l={x:i.x,y:i.y+n.height/2};const a=[e,s,l,r];const p=a.map((i=>o.distance(i,t)));const h=p.indexOf(Math.min(...p));return a[h]}const w=":host{--viewer-annotations-pin-primary-color:var(--blue-700);--viewer-annotations-pin-accent-color:var(--blue-200);--viewer-annotations-pin-dot-color:var(--viewer-annotations-pin-primary-color);--viewer-annotations-pin-color:var(--viewer-annotations-pin-primary-color);--viewer-annotations-pin-font-size:0.75rem;--viewer-annotations-pin-selected-stroke:var(--white);--viewer-annotations-pin-selected-border:2px solid var(--white);--viewer-annotations-pin-label-border:2px solid var(--black);--viewer-annotations-pin-selected-stroke:var(--white);font-size:var(--viewer-annotations-pin-font-size);position:absolute;top:0;bottom:0;left:0;right:0;overflow:hidden;pointer-events:none}.pin-anchor{position:absolute;border-radius:50%;transform:translate(-50%, -50%);display:block;width:9px;height:9px;box-sizing:border-box;border:var(--viewer-annotations-pin-label-border);background:var(--viewer-annotations-pin-dot-color);pointer-events:auto;cursor:pointer}.selected{width:13px;height:13px;border:var(--viewer-annotations-pin-selected-border)}.pin{color:var(--viewer-annotations-pin-color);cursor:pointer}.pin-selected{stroke-width:1;stroke:var(--viewer-annotations-pin-selected-stroke)}";const m=class{constructor(i){n(this,i);this.matrix=e.makeIdentity();this.projectionViewMatrix=e.makeIdentity();this.pinModel=new h;this.selected=false;this.invalidateStateCounter=0;this.invalidateState=()=>{this.invalidateStateCounter=this.invalidateStateCounter+1}}componentDidLoad(){var i;this.setLabelObserver();if(this.pinController==null){this.pinController=new d(this.pinModel)}if(this.selected){(i=this.labelEl)===null||i===void 0?void 0:i.setFocus()}}disconnectedCallback(){var i,t;(i=this.labelEl)===null||i===void 0?void 0:i.removeEventListener("labelChanged",this.invalidateState);(t=this.resizeObserver)===null||t===void 0?void 0:t.disconnect()}render(){var n;if(this.pin==null){throw new Error("Unable to draw pin")}const{pinPoint:o,labelPoint:e}=this.computePinPoints(this.pin);return i(t,null,i("vertex-viewer-dom-element",{"data-testid":`drawn-pin-${this.pin.id}`,position:this.pin.worldPosition,onPointerDown:i=>{if(i.buttons!==2){i.stopPropagation()}this.selectPin();this.handleAnchorPointerDown()}},i(u,{pin:this.pin,selected:this.selected})),p(this.pin)&&i(t,null,i("vertex-viewer-pin-label-line",{id:`pin-label-line-${(n=this.pin)===null||n===void 0?void 0:n.id}`,pinPoint:o,pin:this.pin,labelPoint:e,onPointerDown:()=>this.selectPin()}),i("vertex-viewer-pin-label",{pin:this.pin,ref:i=>this.labelEl=i,elementBounds:this.elementBounds,pinController:this.pinController,onPointerDown:()=>this.selectPin()})))}setLabelObserver(){if(this.labelEl!=null){this.labelEl.addEventListener("labelChanged",this.invalidateState);this.resizeObserver=new ResizeObserver((()=>this.invalidateState()));this.resizeObserver.observe(this.labelEl)}}computePinPoints(i){if(this.elementBounds!=null&&this.pin!=null){return p(this.pin)&&this.pin.label.point!=null?this.computeTextPinPoints(this.pin,this.elementBounds):this.computeDefaultPinPoints(this.pin,this.elementBounds)}return{pinPoint:i.worldPosition}}computeDefaultPinPoints(i,t){return{pinPoint:this.getFromWorldPosition(i.worldPosition,this.projectionViewMatrix,t)}}computeTextPinPoints(i,t){var n,o,e,s;const{pinPoint:r}=this.computeDefaultPinPoints(i,t);const l=v(i.label.point,t);const a=((o=(n=this.labelEl)===null||n===void 0?void 0:n.firstElementChild)===null||o===void 0?void 0:o.clientWidth)||0;const p=((s=(e=this.labelEl)===null||e===void 0?void 0:e.firstElementChild)===null||s===void 0?void 0:s.clientHeight)||0;return{pinPoint:r,labelPoint:b(l,r,{width:a,height:p})}}handleAnchorPointerDown(){var i,t;if(this.elementBounds!=null&&((i=this.pinController)===null||i===void 0?void 0:i.getToolMode())==="edit"&&this.pin!=null){(t=this.pinController)===null||t===void 0?void 0:t.setDraggable({id:this.pin.id})}}selectPin(){var i,t;(i=this.pinController)===null||i===void 0?void 0:i.setSelectedPinId((t=this.pin)===null||t===void 0?void 0:t.id)}getFromWorldPosition(i,t,n){const o=s.transformMatrix(i,t);return r.fromDimensions(n).transformVectorToViewport(o)}};m.style=w;export{m as vertex_viewer_pin_group};
5
- //# sourceMappingURL=p-d8c70701.entry.js.map
4
+ import{h as i,F as t,r as n}from"./p-50533a46.js";import{p as o,m as e,v as s}from"./p-71fbe522.js";import"./p-bb131c4a.js";import"./p-3a256fe9.js";import"./p-9f177e78.js";import"./p-6320532c.js";import"./p-d80260e3.js";import"./p-e1d82323.js";import{V as r}from"./p-1bb66e64.js";import{g as a,i as l,b as p,P as h,a as d,c as v}from"./p-3fb73dd5.js";import{c}from"./p-9fe3f791.js";import"./p-9acf99ad.js";import"./p-7f54de9d.js";import"./p-d45df0c0.js";import"./p-c5381b4a.js";import"./p-7578885f.js";const u=({pin:n,selected:o})=>{const{primaryColor:e}=a(n);return i(t,null,p(n)&&i("div",{id:"pin-anchor",class:c("pin-anchor",{selected:o}),style:{background:e}}),l(n)&&i("vertex-viewer-icon",{name:"pin-fill",size:"lg",class:c("pin",{"pin-selected":o}),style:{color:e}}))};function b(i,t,n){const e={x:i.x+n.width/2,y:i.y};const s={x:i.x+n.width/2,y:i.y+n.height};const r={x:i.x+n.width,y:i.y+n.height/2};const a={x:i.x,y:i.y+n.height/2};const l=[e,s,a,r];const p=l.map((i=>o.distance(i,t)));const h=p.indexOf(Math.min(...p));return l[h]}const w=":host{--viewer-annotations-pin-primary-color:var(--blue-700);--viewer-annotations-pin-accent-color:var(--blue-200);--viewer-annotations-pin-dot-color:var(--viewer-annotations-pin-primary-color);--viewer-annotations-pin-color:var(--viewer-annotations-pin-primary-color);--viewer-annotations-pin-font-size:0.75rem;--viewer-annotations-pin-selected-stroke:var(--white);--viewer-annotations-pin-selected-border:2px solid var(--white);--viewer-annotations-pin-label-border:2px solid var(--black);--viewer-annotations-pin-selected-stroke:var(--white);font-size:var(--viewer-annotations-pin-font-size);position:absolute;top:0;bottom:0;left:0;right:0;overflow:hidden;pointer-events:none}.pin-anchor{position:absolute;border-radius:50%;transform:translate(-50%, -50%);display:block;width:9px;height:9px;box-sizing:border-box;border:var(--viewer-annotations-pin-label-border);background:var(--viewer-annotations-pin-dot-color);pointer-events:auto;cursor:pointer}.selected{width:13px;height:13px;border:var(--viewer-annotations-pin-selected-border)}.pin{color:var(--viewer-annotations-pin-color);cursor:pointer}.pin-selected{stroke-width:1;stroke:var(--viewer-annotations-pin-selected-stroke)}";const m=class{constructor(i){n(this,i);this.matrix=e.makeIdentity();this.projectionViewMatrix=e.makeIdentity();this.pinModel=new h;this.selected=false;this.invalidateStateCounter=0;this.invalidateState=()=>{this.invalidateStateCounter=this.invalidateStateCounter+1}}componentDidLoad(){var i;this.setLabelObserver();if(this.pinController==null){this.pinController=new d(this.pinModel)}if(this.selected){(i=this.labelEl)===null||i===void 0?void 0:i.setFocus()}}disconnectedCallback(){var i,t;(i=this.labelEl)===null||i===void 0?void 0:i.removeEventListener("labelChanged",this.invalidateState);(t=this.resizeObserver)===null||t===void 0?void 0:t.disconnect()}render(){var n;if(this.pin==null){throw new Error("Unable to draw pin")}const{pinPoint:o,labelPoint:e}=this.computePinPoints(this.pin);return i(t,null,i("vertex-viewer-dom-element",{"data-testid":`drawn-pin-${this.pin.id}`,position:this.pin.worldPosition,onPointerDown:i=>{if(i.buttons!==2){i.stopPropagation()}this.selectPin();this.handleAnchorPointerDown()}},i(u,{pin:this.pin,selected:this.selected})),p(this.pin)&&i(t,null,i("vertex-viewer-pin-label-line",{id:`pin-label-line-${(n=this.pin)===null||n===void 0?void 0:n.id}`,pinPoint:o,pin:this.pin,labelPoint:e,onPointerDown:()=>this.selectPin()}),i("vertex-viewer-pin-label",{pin:this.pin,ref:i=>this.labelEl=i,elementBounds:this.elementBounds,pinController:this.pinController,onPointerDown:()=>this.selectPin()})))}setLabelObserver(){if(this.labelEl!=null){this.labelEl.addEventListener("labelChanged",this.invalidateState);this.resizeObserver=new ResizeObserver((()=>this.invalidateState()));this.resizeObserver.observe(this.labelEl)}}computePinPoints(i){if(this.elementBounds!=null&&this.pin!=null){return p(this.pin)&&this.pin.label.point!=null?this.computeTextPinPoints(this.pin,this.elementBounds):this.computeDefaultPinPoints(this.pin,this.elementBounds)}return{pinPoint:i.worldPosition}}computeDefaultPinPoints(i,t){return{pinPoint:this.getFromWorldPosition(i.worldPosition,this.projectionViewMatrix,t)}}computeTextPinPoints(i,t){var n,o,e,s;const{pinPoint:r}=this.computeDefaultPinPoints(i,t);const a=v(i.label.point,t);const l=((o=(n=this.labelEl)===null||n===void 0?void 0:n.firstElementChild)===null||o===void 0?void 0:o.clientWidth)||0;const p=((s=(e=this.labelEl)===null||e===void 0?void 0:e.firstElementChild)===null||s===void 0?void 0:s.clientHeight)||0;return{pinPoint:r,labelPoint:b(a,r,{width:l,height:p})}}handleAnchorPointerDown(){var i,t;if(this.elementBounds!=null&&((i=this.pinController)===null||i===void 0?void 0:i.getToolMode())==="edit"&&this.pin!=null){(t=this.pinController)===null||t===void 0?void 0:t.setDraggable({id:this.pin.id})}}selectPin(){var i,t;(i=this.pinController)===null||i===void 0?void 0:i.setSelectedPinId((t=this.pin)===null||t===void 0?void 0:t.id)}getFromWorldPosition(i,t,n){const o=s.transformMatrix(i,t);return r.fromDimensions(n).transformVectorToViewport(o)}};m.style=w;export{m as vertex_viewer_pin_group};
5
+ //# sourceMappingURL=p-2ce1d5a7.entry.js.map
@@ -1,5 +1,5 @@
1
1
  /*!
2
2
  * Copyright (c) 2023 Vertex Software LLC. All rights reserved.
3
3
  */
4
- import{r as e,h as t,H as i}from"./p-50533a46.js";import{s}from"./p-9f177e78.js";import{a as n}from"./p-6320532c.js";import{p as r}from"./p-089d11bf.js";import{a as o,M as a}from"./p-878d06e9.js";import"./p-d80260e3.js";import{M as h}from"./p-867331de.js";import{M as l}from"./p-db85855d.js";import{p as d}from"./p-71fbe522.js";import{a as u}from"./p-3a256fe9.js";import{g as p}from"./p-c9bbddb8.js";import{E as m}from"./p-cbbe7fa1.js";import{E as c}from"./p-e1d82323.js";import"./p-9acf99ad.js";import"./p-7f54de9d.js";import"./p-d727045f.js";import"./p-7578885f.js";var f=n.grpc;var v=function(){function e(){}e.serviceName="vertexvis.protobuf.sceneview.v1.SceneViewAPI";return e}();v.UpdateModelEntities={methodName:"UpdateModelEntities",service:v,requestStream:false,responseStream:false,requestType:s.UpdateModelEntitiesRequest,responseType:s.UpdateModelEntitiesResponse};v.Measure={methodName:"Measure",service:v,requestStream:false,responseStream:false,requestType:s.MeasureRequest,responseType:s.MeasureResponse};function w(e,t){this.serviceHost=e;this.options=t||{}}w.prototype.updateModelEntities=function e(t,i,s){if(arguments.length===2){s=arguments[1]}var n=f.unary(v.UpdateModelEntities,{request:t,host:this.serviceHost,metadata:i,transport:this.options.transport,debug:this.options.debug,onEnd:function(e){if(s){if(e.status!==f.Code.OK){var t=new Error(e.statusMessage);t.code=e.status;t.metadata=e.trailers;s(t,null)}else{s(null,e.message)}}}});return{cancel:function(){s=null;n.close()}}};w.prototype.measure=function e(t,i,s){if(arguments.length===2){s=arguments[1]}var n=f.unary(v.Measure,{request:t,host:this.serviceHost,metadata:i,transport:this.options.transport,debug:this.options.debug,onEnd:function(e){if(s){if(e.status!==f.Code.OK){var t=new Error(e.statusMessage);t.code=e.status;t.metadata=e.trailers;s(t,null)}else{s(null,e.message)}}}});return{cancel:function(){s=null;n.close()}}};var b=w;class y{constructor(e,t){this.rectObserver=new m;this.handlePointerMove=async e=>{if(await this.isMeasurableEntityUnderPointer(e)){this.clearCursor();this.addCursor(u)}else{this.clearCursor()}};this.handlePointerDown=e=>{this.ifNoInteraction(e,(async()=>{if(await this.isMeasurableEntityUnderPointer(e)){this.measureEntityUnderPointer(e)}else{this.controller.clearEntities()}}))};this.controller=e;this.measurableEntityTypes=t}get elementRect(){return this.rectObserver.rect}initialize(e,t){this.element=e;this.api=t;this.rectObserver.observe(e);e.addEventListener("pointermove",this.handlePointerMove);e.addEventListener("pointerdown",this.handlePointerDown)}dispose(){var e,t,i;this.rectObserver.disconnect();(e=this.measurementInteraction)===null||e===void 0?void 0:e.dispose();this.clearCursor();(t=this.element)===null||t===void 0?void 0:t.removeEventListener("pointermove",this.handlePointerMove);(i=this.element)===null||i===void 0?void 0:i.removeEventListener("pointerdown",this.handlePointerDown);this.element=undefined;this.api=undefined}addCursor(e){this.cursor=this.ifInitialized((({api:t})=>t.addCursor(e)))}clearCursor(){var e;(e=this.cursor)===null||e===void 0?void 0:e.dispose();this.cursor=undefined}async isMeasurableEntityUnderPointer(e){var t;const i=p(e,this.elementRect);const s=await((t=this.api)===null||t===void 0?void 0:t.getEntityTypeAtPoint(i));return s!=null&&this.measurableEntityTypes.includes(s)}measureEntityUnderPointer(e){this.ifInitialized((async({api:t})=>{const i=p(e,this.elementRect);const[s]=await t.hitItems(i);if(s!=null){this.controller.addEntity(o.fromHit(s))}else{this.controller.clearEntities()}}))}ifInitialized(e){if(this.element!=null&&this.api!=null){return e({element:this.element,api:this.api})}else{throw new Error("Measurement interaction handler not initialized.")}}ifNoInteraction(e,t){const i=d.create(e.clientX,e.clientY);let s=false;const n=e=>{const t=d.create(e.clientX,e.clientY);const n=d.distance(i,t);s=n>2};const r=()=>{window.removeEventListener("pointermove",n);window.removeEventListener("pointerup",r);if(!s){t()}};window.addEventListener("pointermove",n);window.addEventListener("pointerup",r)}}const j=":host{display:block;position:absolute;top:0;bottom:0;left:0;right:0;pointer-events:none}";const C=class{constructor(t){e(this,t);this.measurementModel=new h;this.measurementOverlays=new l;this.measurableEntityTypes=[c.PRECISE_SURFACE,c.IMPRECISE_SURFACE];this.configEnv="platprod"}connectedCallback(){this.setupInteractionHandler()}componentWillLoad(){this.setupController();this.setupInteractionHandler()}disconnectedCallback(){this.clearInteractionHandler()}handleMeasurableEntityTypesChanged(){this.setupInteractionHandler()}handleMeasurementControllerChanged(){this.setupInteractionHandler()}handleMeasurementModelChanged(){this.setupController()}handleViewerChanged(){this.setupInteractionHandler()}render(){return t(i,null,t("vertex-viewer-measurement-overlays",{viewer:this.viewer,measurementOverlays:this.measurementOverlays}))}setupController(){var e;const t=r(this.configEnv,this.config);const i=new b(t.network.sceneViewHost);this.measurementController=new a(this.measurementModel,i,(()=>{var e;return(e=this.viewer)===null||e===void 0?void 0:e.token}),(e=this.viewer)===null||e===void 0?void 0:e.deviceId)}clearInteractionHandler(){var e;(e=this.registeredInteractionHandler)===null||e===void 0?void 0:e.then((e=>e.dispose()));this.registeredInteractionHandler=undefined}setupInteractionHandler(){var e;this.clearInteractionHandler();if(this.measurementController!=null){this.registeredInteractionHandler=(e=this.viewer)===null||e===void 0?void 0:e.registerInteractionHandler(new y(this.measurementController,this.measurableEntityTypes))}}static get watchers(){return{measurableEntityTypes:["handleMeasurableEntityTypesChanged"],measurementController:["handleMeasurementControllerChanged"],measurementModel:["handleMeasurementModelChanged"],viewer:["handleViewerChanged"]}}};C.style=j;export{C as vertex_viewer_measurement_precise};
5
- //# sourceMappingURL=p-31c3b8d6.entry.js.map
4
+ import{r as e,h as t,H as i}from"./p-50533a46.js";import{s}from"./p-9f177e78.js";import{a as n}from"./p-6320532c.js";import{p as r}from"./p-0de95c4d.js";import{a as o,M as a}from"./p-878d06e9.js";import"./p-d80260e3.js";import{M as h}from"./p-867331de.js";import{M as l}from"./p-db85855d.js";import{p as d}from"./p-71fbe522.js";import{a as u}from"./p-3a256fe9.js";import{g as p}from"./p-c9bbddb8.js";import{E as m}from"./p-cbbe7fa1.js";import{E as c}from"./p-e1d82323.js";import"./p-9acf99ad.js";import"./p-7f54de9d.js";import"./p-d727045f.js";import"./p-7578885f.js";var f=n.grpc;var v=function(){function e(){}e.serviceName="vertexvis.protobuf.sceneview.v1.SceneViewAPI";return e}();v.UpdateModelEntities={methodName:"UpdateModelEntities",service:v,requestStream:false,responseStream:false,requestType:s.UpdateModelEntitiesRequest,responseType:s.UpdateModelEntitiesResponse};v.Measure={methodName:"Measure",service:v,requestStream:false,responseStream:false,requestType:s.MeasureRequest,responseType:s.MeasureResponse};function w(e,t){this.serviceHost=e;this.options=t||{}}w.prototype.updateModelEntities=function e(t,i,s){if(arguments.length===2){s=arguments[1]}var n=f.unary(v.UpdateModelEntities,{request:t,host:this.serviceHost,metadata:i,transport:this.options.transport,debug:this.options.debug,onEnd:function(e){if(s){if(e.status!==f.Code.OK){var t=new Error(e.statusMessage);t.code=e.status;t.metadata=e.trailers;s(t,null)}else{s(null,e.message)}}}});return{cancel:function(){s=null;n.close()}}};w.prototype.measure=function e(t,i,s){if(arguments.length===2){s=arguments[1]}var n=f.unary(v.Measure,{request:t,host:this.serviceHost,metadata:i,transport:this.options.transport,debug:this.options.debug,onEnd:function(e){if(s){if(e.status!==f.Code.OK){var t=new Error(e.statusMessage);t.code=e.status;t.metadata=e.trailers;s(t,null)}else{s(null,e.message)}}}});return{cancel:function(){s=null;n.close()}}};var b=w;class y{constructor(e,t){this.rectObserver=new m;this.handlePointerMove=async e=>{if(await this.isMeasurableEntityUnderPointer(e)){this.clearCursor();this.addCursor(u)}else{this.clearCursor()}};this.handlePointerDown=e=>{this.ifNoInteraction(e,(async()=>{if(await this.isMeasurableEntityUnderPointer(e)){this.measureEntityUnderPointer(e)}else{this.controller.clearEntities()}}))};this.controller=e;this.measurableEntityTypes=t}get elementRect(){return this.rectObserver.rect}initialize(e,t){this.element=e;this.api=t;this.rectObserver.observe(e);e.addEventListener("pointermove",this.handlePointerMove);e.addEventListener("pointerdown",this.handlePointerDown)}dispose(){var e,t,i;this.rectObserver.disconnect();(e=this.measurementInteraction)===null||e===void 0?void 0:e.dispose();this.clearCursor();(t=this.element)===null||t===void 0?void 0:t.removeEventListener("pointermove",this.handlePointerMove);(i=this.element)===null||i===void 0?void 0:i.removeEventListener("pointerdown",this.handlePointerDown);this.element=undefined;this.api=undefined}addCursor(e){this.cursor=this.ifInitialized((({api:t})=>t.addCursor(e)))}clearCursor(){var e;(e=this.cursor)===null||e===void 0?void 0:e.dispose();this.cursor=undefined}async isMeasurableEntityUnderPointer(e){var t;const i=p(e,this.elementRect);const s=await((t=this.api)===null||t===void 0?void 0:t.getEntityTypeAtPoint(i));return s!=null&&this.measurableEntityTypes.includes(s)}measureEntityUnderPointer(e){this.ifInitialized((async({api:t})=>{const i=p(e,this.elementRect);const[s]=await t.hitItems(i);if(s!=null){this.controller.addEntity(o.fromHit(s))}else{this.controller.clearEntities()}}))}ifInitialized(e){if(this.element!=null&&this.api!=null){return e({element:this.element,api:this.api})}else{throw new Error("Measurement interaction handler not initialized.")}}ifNoInteraction(e,t){const i=d.create(e.clientX,e.clientY);let s=false;const n=e=>{const t=d.create(e.clientX,e.clientY);const n=d.distance(i,t);s=n>2};const r=()=>{window.removeEventListener("pointermove",n);window.removeEventListener("pointerup",r);if(!s){t()}};window.addEventListener("pointermove",n);window.addEventListener("pointerup",r)}}const j=":host{display:block;position:absolute;top:0;bottom:0;left:0;right:0;pointer-events:none}";const C=class{constructor(t){e(this,t);this.measurementModel=new h;this.measurementOverlays=new l;this.measurableEntityTypes=[c.PRECISE_SURFACE,c.IMPRECISE_SURFACE];this.configEnv="platprod"}connectedCallback(){this.setupInteractionHandler()}componentWillLoad(){this.setupController();this.setupInteractionHandler()}disconnectedCallback(){this.clearInteractionHandler()}handleMeasurableEntityTypesChanged(){this.setupInteractionHandler()}handleMeasurementControllerChanged(){this.setupInteractionHandler()}handleMeasurementModelChanged(){this.setupController()}handleViewerChanged(){this.setupInteractionHandler()}render(){return t(i,null,t("vertex-viewer-measurement-overlays",{viewer:this.viewer,measurementOverlays:this.measurementOverlays}))}setupController(){var e;const t=r(this.configEnv,this.config);const i=new b(t.network.sceneViewHost);this.measurementController=new a(this.measurementModel,i,(()=>{var e;return(e=this.viewer)===null||e===void 0?void 0:e.token}),(e=this.viewer)===null||e===void 0?void 0:e.deviceId)}clearInteractionHandler(){var e;(e=this.registeredInteractionHandler)===null||e===void 0?void 0:e.then((e=>e.dispose()));this.registeredInteractionHandler=undefined}setupInteractionHandler(){var e;this.clearInteractionHandler();if(this.measurementController!=null){this.registeredInteractionHandler=(e=this.viewer)===null||e===void 0?void 0:e.registerInteractionHandler(new y(this.measurementController,this.measurableEntityTypes))}}static get watchers(){return{measurableEntityTypes:["handleMeasurableEntityTypesChanged"],measurementController:["handleMeasurementControllerChanged"],measurementModel:["handleMeasurementModelChanged"],viewer:["handleViewerChanged"]}}};C.style=j;export{C as vertex_viewer_measurement_precise};
5
+ //# sourceMappingURL=p-4225576d.entry.js.map
@@ -0,0 +1,5 @@
1
+ /*!
2
+ * Copyright (c) 2023 Vertex Software LLC. All rights reserved.
3
+ */
4
+ import{r as t,c as i,h as s,H as n,g as e}from"./p-50533a46.js";import{p as o,v as h,c as r,f as a,r as c,b as l,s as d,d as u}from"./p-71fbe522.js";import{t as f,p as w,a as p,S as v,c as m,W as g}from"./p-7578885f.js";import{E as y,m as C,c as b,o as P,u as I,a as T,b as D}from"./p-7f54de9d.js";import{c as k}from"./p-9fe3f791.js";import{p as S}from"./p-0de95c4d.js";import{C as M}from"./p-3a256fe9.js";import{g as x,c as E}from"./p-c9bbddb8.js";import{c as O,C as j,W as A,S as R,V as F,d as z,e as B}from"./p-d45df0c0.js";import{k as L,l as N,m as $,t as K,n as H,o as W,p as V,q,r as U,s as _,u as J,x as X,y as G,z as Z}from"./p-d80260e3.js";import{E as Y}from"./p-e1d82323.js";import{V as Q}from"./p-1bb66e64.js";import{f as tt,a as it,S as st}from"./p-5e8d61d9.js";import"./p-9acf99ad.js";import"./p-d727045f.js";const nt=0;const et=255;class ot{constructor(t){this.viewer=t;this.handleInteractionStarted=()=>{this.invalidateStencilBuffer();this.pendingInteractionFinished=new Promise((t=>{this.pendingInteractionFinishedResolver=t}))};this.handleInteractionFinished=()=>{var t;(t=this.pendingInteractionFinishedResolver)===null||t===void 0?void 0:t.call(this);this.pendingInteractionFinished=undefined;this.pendingInteractionFinishedResolver=undefined};this.invalidateStencilBuffer=()=>{this.pendingStencilBuffer=undefined};t.addEventListener("interactionStarted",this.handleInteractionStarted);t.addEventListener("interactionFinished",this.handleInteractionFinished);t.addEventListener("frameReceived",(()=>{this.invalidateStencilBuffer()}))}async fetch(){var t;const i=await this.viewer.isSceneReady();const s=i?await this.viewer.scene():undefined;const n=s!=null?s.crossSectioning().current().sectionPlanes.length>0||this.viewer.featureLines!=null:false;const e=(t=this.viewer.frame)===null||t===void 0?void 0:t.scene.camera;if(n&&this.viewer.stream!=null&&e!=null){const t=await this.viewer.stream.getStencilBuffer({includeDepthBuffer:true});const{stencilBuffer:i,depthBuffer:s,imageAttributes:n}=L(t);const[o,h]=await Promise.all([N(new Uint8Array(i)),N(new Uint8Array(s))]);return ht.fromPng(o,n,i,$.fromPng(h,e,n))}else return undefined}latest(){if(this.pendingStencilBuffer==null){this.pendingStencilBuffer=this.fetch()}return this.pendingStencilBuffer}async latestAfterInteraction(){await this.pendingInteractionFinished;return this.latest()}}class ht{constructor(t,i,s,n,e){this.imageAttr=t;this.imageBytes=i;this.pixelBytes=s;this.imageChannels=n;this.depthBuffer=e}static fromPng(t,i,s,n){if(!(t.data instanceof Uint8Array)){throw new Error("Expected stencil PNG to have depth of 8-bit")}else if(t.channels!==1){throw new Error("Expected stencil PNG to have 1 color channel")}else{return new ht(i,s,t.data,t.channels,n)}}getValue(t){const{width:i,height:s}=this.imageAttr.imageRect;const n=o.subtract(t,this.imageAttr.imageRect);const e=1/this.imageAttr.imageScale;const h=o.scale(n,e,e);if(h.x>=0&&h.y>=0&&h.x<i&&h.y<s){const t=Math.floor(h.x)+Math.floor(h.y)*i;const s=this.pixelBytes[t];return s}else return 0}hitTest(t){return this.getValue(t)!==nt}snapToNearestPixel(t,i,s=(()=>true)){const n=i*2;const e=o.create(t.x-i,t.y-i);const h=[];for(let r=0;r<n*n;r++){const a=r%n;const c=Math.floor(r/n);const l=o.add(e,{x:a,y:c});if(o.distance(l,t)<=i){const t=this.getValue(l);if(t===et&&s(t)){h.push(l)}}}const r=h.sort(((i,s)=>o.distance(i,t)-o.distance(s,t)));const a=r[0];return a!=null?o.create(Math.floor(a.x)+.5,Math.floor(a.y)+.5):t}}function rt(t){return t!=null&&t["then"]instanceof Function&&t["catch"]instanceof Function&&t["finally"]instanceof Function}class at{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();const n=await this.stream.hitItems({point:o.scale(t.position,(s===null||s===void 0?void 0:s.x)||1,(s===null||s===void 0?void 0:s.y)||1)},true);if(((i=n.hitItems)===null||i===void 0?void 0:i.hits)!=null&&n.hitItems.hits.length>0){await this.stream.flyTo({itemId:n.hitItems.hits[0].itemId,animation:{duration:f(this.configProvider().animation.durationMs)}})}else{console.debug(`No hit results found for fly to part [position={x: ${t.position.x}, y: ${t.position.y}}]`)}}}class ct{constructor(t,i,s,n,e,o,h,r,a,c,l){this.stream=t;this.cursors=i;this.getConfig=s;this.getScene=n;this.getFrame=e;this.getViewport=o;this.tapEmitter=h;this.doubleTapEmitter=r;this.longPressEmitter=a;this.interactionStartedEmitter=c;this.interactionFinishedEmitter=l;this.tap=this.tap.bind(this);this.doubleTap=this.doubleTap.bind(this);this.longPress=this.longPress.bind(this);this.emitTapEvent=this.emitTapEvent.bind(this)}addCursor(t,i){return this.cursors.add(t,i)}async getWorldPointFromViewport(t){const i=this.getViewport();const s=this.getFrame();if(s==null){throw new Error("Cannot get world point. Frame is undefined.")}const n=await s.depthBuffer();return n!=null?i.transformPointToWorldSpace(t,n,.5):undefined}async getEntityTypeAtPoint(t){var i;const s=this.getViewport();const n=await((i=this.getFrame())===null||i===void 0?void 0:i.featureMap());if(n!=null){const i=s.transformPointToFrame(t,n);return n.getEntityType(i)}else{return Y.NO_GEOMETRY}}getRayFromPoint(t){const i=this.getViewport();const s=this.getFrame();if(s!=null){return i.transformPointToRay(t,s.image,s.scene.camera)}else 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(){if(!this.isInteracting()){this.interactionStartedEmitter.emit();this.sceneLoadingPromise=this.getScene();this.currentCamera=(await this.sceneLoadingPromise).camera();this.sceneLoadingPromise=undefined;await this.stream.beginInteraction()}}async transformCamera(t){var i;if(this.isInteracting()){const s=await this.getScene();const n=this.getViewport();const e=this.getFrame();const o=await(e===null||e===void 0?void 0:e.depthBuffer());this.currentCamera=this.currentCamera!=null&&n!=null&&e!=null?t({camera:this.currentCamera,viewport:n,scale:s.scale(),boundingBox:s.boundingBox(),frame:e,depthBuffer:o}):undefined;await((i=this.currentCamera)===null||i===void 0?void 0:i.render())}}async twistCamera(...t){return this.transformCamera((({camera:i,viewport:s})=>{const n=h.normalize(h.subtract(i.lookAt,i.position));if(t.length===1&&typeof t[0]==="number"){const s=r.toRadians(-t[0]);return i.rotateAroundAxis(s,n)}else if(t.length===1){const n=o.create(s.width/2,s.height/2);const e=r.toDegrees(r.fromPoints(n,t[0]));const a=this.lastAngle!=null?e-this.lastAngle:0;this.lastAngle=e;const c=h.normalize(h.subtract(i.lookAt,i.position));const l=r.toRadians(-a);return i.rotateAroundAxis(l,c)}return i}))}async panCameraToScreenPoint(t){return this.transformCamera((({camera:i,frame:s,viewport:n,depthBuffer:e})=>{if(this.panData==null){const o=i.toFrameCamera();const h=o.direction;const r=n.transformPointToRay(t,s.image,o);const l=a.fromNormalAndCoplanarPoint(h,i.lookAt);const d=c.intersectPlane(r,l);if(d==null){console.warn("Cannot determine fallback for pan. Ray does not intersect plane.");return i}const u=e!=null?this.getWorldPoint(t,e,d):d;const f=a.fromNormalAndCoplanarPoint(h,u);this.panData={hitPt:u,hitPlane:f,startingCamera:o}}if(this.panData!=null){const{hitPt:e,hitPlane:o,startingCamera:r}=this.panData;const a=n.transformPointToRay(t,s.image,r);const l=c.intersectPlane(a,o);if(l!=null){const t=h.subtract(e,l);return i.update(r).moveBy(t)}}return i}))}async viewAll(){await(await this.getScene()).camera().viewAll().render()}async rotateCamera(t){return this.transformCamera((({camera:i,viewport:s})=>{const n=h.normalize(i.up);const e=h.normalize(h.subtract(i.lookAt,i.position));const o=h.cross(n,e);const r=h.cross(e,o);const a=h.normalize({x:t.x*o.x+t.y*r.x,y:t.x*o.y+t.y*r.y,z:t.x*o.z+t.y*r.z});const c=h.cross(a,e);const l=3*Math.PI*t.x/s.width;const d=3*Math.PI*t.y/s.height;const u=Math.abs(l)+Math.abs(d);return i.rotateAroundAxis(u,c)}))}async rotateCameraAtPoint(t,i){return this.transformCamera((({camera:s,viewport:n,boundingBox:e,depthBuffer:o})=>{if(this.worldRotationPoint==null){const t=l.center(e);this.worldRotationPoint=o!=null?this.getWorldPoint(i,o,t):s.lookAt}const r=h.normalize(s.up);const a=h.normalize(h.subtract(s.lookAt,s.position));const c=h.cross(r,a);const d=h.cross(a,c);const u=h.normalize({x:t.x*c.x+t.y*d.x,y:t.x*c.y+t.y*d.y,z:t.x*c.z+t.y*d.z});const f=h.cross(u,a);const w=3*Math.PI*t.x/n.width;const p=3*Math.PI*t.y/n.height;const v=Math.abs(w)+Math.abs(p);const m=s.rotateAroundAxisAtPoint(v,this.worldRotationPoint,f);return m.update({lookAt:h.add(h.scale(Math.abs(s.signedDistanceToBoundingBoxCenter())/h.magnitude(m.viewVector),m.viewVector),m.position)})}))}async zoomCamera(t){return this.transformCamera((({camera:i,viewport:s})=>{const n=i.viewVector;const e=h.normalize(n);const o=h.magnitude(n);const r=3*o*t/s.height;const a=h.add(i.position,h.scale(r,e));const c=i.update({position:a});return c}))}async pivotCamera(t,i){return this.transformCamera((({camera:s})=>{const{position:n,up:e,lookAt:o}=s;const a=h.normalize(e);const c=h.normalize(s.viewVector);const l=h.cross(a,c);const d=h.cross(c,l);const u=h.rotateAboutAxis(r.toRadians(t),o,l,n);const f=h.rotateAboutAxis(r.toRadians(i),u,d,n);return s.update(Object.assign(Object.assign({},s),{lookAt:f}))}))}async endInteraction(){await this.sceneLoadingPromise;if(this.isInteracting()){this.currentCamera=undefined;this.worldRotationPoint=undefined;this.panData=undefined;this.zoomData=undefined;this.resetLastAngle();this.interactionFinishedEmitter.emit();await this.stream.endInteraction()}}resetLastAngle(){this.lastAngle=undefined}isInteracting(){return this.currentCamera!=null}pixelThreshold(t){const i=this.isCoarseInputDevice(t)?this.getConfig().coarsePointerThreshold:this.getConfig().finePointerThreshold;return i*window.devicePixelRatio}async hitItems(t){var i;const s=await(await this.getScene()).raycaster().hitItems(t);return(i=s===null||s===void 0?void 0:s.hits)!==null&&i!==void 0?i:[]}emitTapEvent(t,i,s={},n=0){const{altKey:e=false,ctrlKey:o=false,metaKey:h=false,shiftKey:r=false}=s;t({position:i,altKey:e,ctrlKey:o,metaKey:h,shiftKey:r,buttons:n})}isCoarseInputDevice(t){return t||window.matchMedia("(pointer: coarse)").matches}getWorldPoint(t,i,s){const n=this.getViewport();const e=n.transformPointToFrame(t,i);const o=i.hitTest(e);return o?n.transformPointToWorldSpace(t,i):s}}class lt extends ct{constructor(t,i,s,n,e,o,h,r,a,c,l){super(t,i,s,n,e,o,h,r,a,c,l)}async getWorldPointFromViewport(t){const i=this.getViewport();const s=this.getFrame();if(s==null){throw new Error("Cannot get world point. Frame is undefined.")}const n=await s.depthBuffer();return n!=null?i.transformPointToOrthographicWorldSpace(t,n,.5):undefined}async panCameraByDelta(t){return this.transformCamera((({camera:i,viewport:s})=>{const n=i.viewVector;const e=h.normalize(i.up);const r=h.normalize(n);const a=o.scale(t,.5,.5);const c=h.magnitude(n);const l=a.x*c/s.width;const d=a.y/s.width*c;const u=h.cross(e,r);const f=h.cross(r,u);const w=h.add(h.scale(l,u),h.scale(d,f));return i.moveBy(w)}))}async panCameraToScreenPoint(t){return this.transformCamera((({camera:i,frame:s,viewport:n})=>{if(this.panData==null){const e=i.toFrameCamera();const o=e.direction;const h=n.transformPointToOrthographicRay(t,s.image,e);const r=a.fromNormalAndCoplanarPoint(o,i.lookAt);const l=c.intersectPlane(h,r);if(l==null){console.warn("Cannot determine fallback for pan. Ray does not intersect plane.");return i}this.panData={hitPt:l,hitPlane:r,startingCamera:e}}if(this.panData!=null){const{hitPt:e,hitPlane:o,startingCamera:r}=this.panData;const a=n.transformPointToOrthographicRay(t,s.image,r);const l=c.intersectPlane(a,o);if(l!=null){const t=h.subtract(e,l);return i.update({lookAt:h.add(r.lookAt,t)})}}return i}))}async zoomCameraToPoint(t,i){return this.transformCamera((({camera:s,viewport:n,frame:e,depthBuffer:r})=>{if(this.orthographicZoomData==null||o.distance(t,this.orthographicZoomData.startingScreenPt)>2){const i=s.toFrameCamera();const o=i.direction;const h=n.transformPointToOrthographicRay(t,e.image,i);const l=a.fromNormalAndCoplanarPoint(o,i.lookAt);const d=c.intersectPlane(h,l);if(d==null){console.warn("Cannot determine fallback point for zoom. Ray does not intersect plane.");return s}const u=r!=null?this.getWorldPoint(t,r,d):d;const f=a.fromNormalAndCoplanarPoint(o,u);this.orthographicZoomData={hitPt:u,hitPlane:f,startingScreenPt:t}}if(this.orthographicZoomData!=null){const{hitPt:t,hitPlane:e}=this.orthographicZoomData;const o=2*(s.fovHeight/n.height)*i*2;const r=Math.max(1,s.fovHeight-o);const c=a.projectPoint(e,s.lookAt);const l=h.scale((s.fovHeight-r)/s.fovHeight,h.subtract(t,c));return s.update({lookAt:h.add(s.lookAt,l),fovHeight:Math.max(1,s.fovHeight-o)})}return s}))}getWorldPoint(t,i,s){const n=this.getViewport();const e=n.transformPointToFrame(t,i);const o=i.hitTest(e);return o?n.transformPointToOrthographicWorldSpace(t,i):s}async transformCamera(t){var i;if(this.isInteracting()){const s=await this.getScene();const n=this.getViewport();const e=this.getFrame();const o=await(e===null||e===void 0?void 0:e.depthBuffer());this.currentCamera=this.currentCamera!=null&&n!=null&&e!=null?t({camera:this.currentCamera,viewport:n,scale:s.scale(),boundingBox:s.boundingBox(),frame:e,depthBuffer:o}):undefined;await((i=this.currentCamera)===null||i===void 0?void 0:i.render())}}}const dt=.2;class ut extends ct{constructor(t,i,s,n,e,o,h,r,a,c,l){super(t,i,s,n,e,o,h,r,a,c,l)}async panCameraByDelta(t){return this.transformCamera((({camera:i,viewport:s})=>{var n;const e=i.viewVector;const r=h.normalize(i.up);const a=h.normalize(e);const c=o.scale(t,.25,.25);const l=h.magnitude(e)*Math.tan((n=i.fovY)!==null&&n!==void 0?n:45);const d=c.x*l/s.width;const u=c.y/s.width*l;const f=h.cross(r,a);const w=h.cross(a,f);const p=h.add(h.scale(d,f),h.scale(u,w));return i.moveBy(p)}))}async zoomCameraToPoint(t,i){return this.transformCamera((({camera:s,viewport:n,frame:e,depthBuffer:o,boundingBox:r})=>{const l=e.scene.camera;const d=l.direction;const u=s.toFrameCamera();const f=n.transformPointToRay(t,e.image,u);if(this.zoomData==null){const i=a.fromNormalAndCoplanarPoint(d,l.lookAt);const n=c.intersectPlane(f,i);if(n==null){console.warn("Cannot determine fallback point for zoom. Ray does not intersect plane.");return s}const e=o!=null?this.getWorldPoint(t,o,n):n;const h=a.fromNormalAndCoplanarPoint(d,e);this.zoomData={hitPt:e,hitPlane:h}}if(this.zoomData!=null){const{hitPlane:t}=this.zoomData;const{position:e,distance:o,isPastHitPlane:l,keepCurrent:d}=this.computeZoomDistances(i,s,n,r,f,this.zoomData);if(l&&!d){const t=c.create({origin:e,direction:h.normalize(s.viewVector)});return s.update({position:e,lookAt:c.at(t,o)})}else if(!d){return s.update({position:e,lookAt:a.projectPoint(t,e)})}}return s}))}async transformCamera(t){var i;if(this.isInteracting()){const s=await this.getScene();const n=this.getViewport();const e=this.getFrame();const o=await(e===null||e===void 0?void 0:e.depthBuffer());this.currentCamera=this.currentCamera!=null&&n!=null&&e!=null?t({camera:this.currentCamera,viewport:n,scale:s.scale(),boundingBox:s.boundingBox(),frame:e,depthBuffer:o}):undefined;await((i=this.currentCamera)===null||i===void 0?void 0:i.render())}}computeZoomDistances(t,i,s,n,e,o){const r=this.getConfig();const{hitPt:a,hitPlane:l}=o;const d=r.useMinimumPerspectiveZoomDistance?this.computeZoomMinimumDistance(i,n):-1;const u=h.distance(i.position,a);const f=Math.max(d,u);const w=6*f*t/s.height;const p=c.at(e,w);const v=c.create({origin:p,direction:h.normalize(i.viewVector)});const m=c.intersectPlane(v,l);if(m==null&&r.useMinimumPerspectiveZoomDistance){const i=6*d*t/s.height;const n=c.at(e,i);return{position:n,distance:d,isPastHitPlane:true,keepCurrent:false}}else if(m==null){return{position:i.position,distance:f,isPastHitPlane:true,keepCurrent:true}}return{position:p,distance:f,isPastHitPlane:false,keepCurrent:false}}computeZoomMinimumDistance(t,i){const s=Math.abs(i.min.x)+Math.abs(i.max.x);const n=Math.abs(i.min.y)+Math.abs(i.max.y);const e=Math.abs(i.min.z)+Math.abs(i.max.z);const o=Math.max(s,n,e);const r=Math.abs(h.dot(h.normalize(t.viewVector),h.right()));const a=Math.abs(h.dot(h.normalize(t.viewVector),h.up()));const c=Math.abs(h.dot(h.normalize(t.viewVector),h.back()));const l=s*r;const d=n*a;const u=e*c;const f=o/s;const w=o/n;const p=o/e;return(l+d+u)/(f+w+p)*dt}}class ft{constructor(t,i,s,n){this.stream=t;this.configProvider=i;this.imageScaleProvider=s;this.sceneProvider=n}predicate(t){return t.altKey&&t.shiftKey}async fn(t){var i,s;const n=this.imageScaleProvider();const e=await this.stream.hitItems({point:o.scale(t.position,(n===null||n===void 0?void 0:n.x)||1,(n===null||n===void 0?void 0:n.y)||1)},true);if(((i=e.hitItems)===null||i===void 0?void 0:i.hits)!=null&&e.hitItems.hits.length>0&&e.hitItems.hits[0].hitPoint!=null){const i=(await this.sceneProvider()).camera();const n=e.hitItems.hits[0];if(n.hitPoint!=null&&n.hitPoint.x!=null&&n.hitPoint.y!=null&&n.hitPoint.z!=null){await this.stream.flyTo({camera:K(i.update({lookAt:h.create(n.hitPoint.x,n.hitPoint.y,n.hitPoint.z)}).toFrameCamera()),animation:{duration:f(this.configProvider().animation.durationMs)}})}else{console.debug(`No hit position found for fly to position [position={x: ${t.position.x}, y: ${t.position.y}}, hit-id={${(s=n.itemId)===null||s===void 0?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 wt=[.2,.15,.25,.25,.15];const pt=16;const vt=1.2;class mt{constructor(t,i,s,n,e,o,h,r,a,c){this.downEvent=t;this.upEvent=i;this.moveEvent=s;this.rotateInteraction=n;this.rotatePointInteraction=e;this.zoomInteraction=o;this.panInteraction=h;this.twistInteraction=r;this.pivotInteraction=a;this.getConfig=c;this.primaryInteraction=this.rotateInteraction;this.isDragging=false;this.keyboardControls=false;this.disableIndividualInteractions=false;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;(t=this.element)===null||t===void 0?void 0:t.removeEventListener(this.downEvent,this.handleDownEvent);(i=this.element)===null||i===void 0?void 0:i.removeEventListener("mousedown",this.handleDoubleClick);(s=this.element)===null||s===void 0?void 0:s.removeEventListener("wheel",this.handleMouseWheel);this.element=undefined}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=undefined}if(this.draggingInteraction){const t=this.draggingInteraction.getPosition();this.draggingInteraction=this.currentInteraction||this.primaryInteraction;(i=this.interactionApi)===null||i===void 0?void 0: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;break}this.primaryInteractionTypeChange.emit()}setDefaultKeyboardControls(t){this.keyboardControls=t}handleDownEvent(t){t.preventDefault();this.interactionTimer=window.setTimeout((()=>{this.downPosition=o.create(t.screenX,t.screenY);this.downPositionCanvas=this.getCanvasPosition(t);this.interactionTimer=undefined;if(this.lastMoveEvent!=null){this.handleWindowMove(this.lastMoveEvent)}}),this.getConfig().interactions.interactionDelay);window.addEventListener(this.moveEvent,this.handleWindowMove);window.addEventListener(this.upEvent,this.handleWindowUp)}handleWindowMove(t){if(this.interactionTimer==null){if(this.disableIndividualInteractions){return}const i=o.create(t.screenX,t.screenY);const s=this.interactionApi!=null?this.interactionApi.pixelThreshold(this.isTouch(t)):2;if(this.downPosition!=null&&o.distance(i,this.downPosition)>=s&&!this.isDragging){this.beginDrag(t);this.isDragging=true}if(this.isDragging){this.drag(t)}}this.lastMoveEvent=t}async handleWindowUp(t){if(this.isDragging){this.endDrag(t);this.isDragging=false}if(this.interactionTimer!=null){window.clearTimeout(this.interactionTimer);this.interactionTimer=undefined}window.removeEventListener(this.moveEvent,this.handleWindowMove);window.removeEventListener(this.upEvent,this.handleWindowUp);this.lastMoveEvent=undefined}async handleDoubleClick(t){if(t.detail===2&&t.buttons===4&&this.interactionApi!=null){this.interactionApi.viewAll()}}beginDrag(t){var i;if(this.keyboardControls&&t.metaKey&&t.shiftKey){this.currentInteraction=this.rotatePointInteraction}else if(this.keyboardControls&&t.shiftKey&&t.altKey){this.currentInteraction=this.twistInteraction}else if(this.keyboardControls&&t.shiftKey){this.currentInteraction=this.zoomInteraction}else if(this.keyboardControls&&(t.metaKey||t.ctrlKey)){this.currentInteraction=this.panInteraction}else if(this.keyboardControls&&t.altKey){this.currentInteraction=this.rotateInteraction}if(t.buttons===1){this.draggingInteraction=this.currentInteraction||this.primaryInteraction}else if(t.buttons===2){this.draggingInteraction=this.panInteraction}else if(t.buttons===4){this.draggingInteraction=(i=this.lastPrimaryRotateInteraction)!==null&&i!==void 0?i:this.rotateInteraction}if(this.draggingInteraction!=null&&this.interactionApi!=null&&this.element!=null){this.zoomInteraction.endDrag(t,this.interactionApi);this.draggingInteraction.beginDrag(t,this.downPositionCanvas||o.create(t.clientX,t.clientY),this.interactionApi,this.element)}}drag(t){if(this.keyboardControls&&t.altKey&&t.shiftKey){this.currentInteraction=this.twistInteraction}else{this.currentInteraction=undefined}this.draggingInteraction=this.currentInteraction||this.draggingInteraction||this.primaryInteraction;if(this.draggingInteraction!=null&&this.interactionApi!=null){this.draggingInteraction.drag(t,this.interactionApi)}}endDrag(t){if(this.keyboardControls&&this.currentInteraction===this.twistInteraction){this.currentInteraction=undefined}if(this.draggingInteraction!=null&&this.interactionApi!=null){this.draggingInteraction.endDrag(t,this.interactionApi);this.draggingInteraction=undefined}}handleMouseWheel(t){t.preventDefault();if(this.element!=null&&this.interactionApi!=null&&t.buttons!==4){const i=-this.wheelDeltaToPixels(t.deltaY,t.deltaMode)/10;const s=this.element.getBoundingClientRect();const n=x(t,s);wt.forEach(((t,s)=>{window.setTimeout((()=>{if(this.interactionApi!=null){const s=i*t;this.zoomInteraction.zoomToPoint(n,s,this.interactionApi)}}),s*2)}))}}wheelDeltaToPixels(t,i){if(this.computedBodyStyle==null){this.computedBodyStyle=window.getComputedStyle(document.body)}const s=this.computedBodyStyle.fontSize!=null&&this.computedBodyStyle.fontSize!==""&&!isNaN(parseFloat(this.computedBodyStyle.fontSize))?parseFloat(this.computedBodyStyle.fontSize)*vt:pt*vt;if(i===1){return this.computedBodyStyle.lineHeight!=null&&this.computedBodyStyle.lineHeight!==""&&!isNaN(parseFloat(this.computedBodyStyle.lineHeight))?t*parseFloat(this.computedBodyStyle.lineHeight):t*s}else if(i===2){return this.computedBodyStyle.height!=null&&this.computedBodyStyle.height!==""&&!isNaN(parseFloat(this.computedBodyStyle.height))?t*parseFloat(this.computedBodyStyle.height):t*window.innerHeight}return t}getCanvasPosition(t){var i;const s=(i=this.element)===null||i===void 0?void 0:i.getBoundingClientRect();const n=s!=null?o.create(s.left,s.top):undefined;return n!=null?o.subtract(o.create(t.clientX,t.clientY),n):undefined}isTouch(t){return window.PointerEvent!=null&&t instanceof PointerEvent?t.pointerType==="touch":false}}class gt{setPosition(t){this.currentPosition=t}getPosition(){return this.currentPosition}getType(){return this.type}beginDrag(t,i,s,n){}drag(t,i){}endDrag(t,i){if(this.currentPosition!=null){i.endInteraction();this.currentPosition=undefined}}zoom(t,i){}}class yt extends gt{constructor(){super(...arguments);this.type="rotate"}beginDrag(t,i,s){if(this.currentPosition==null){this.currentPosition=o.create(t.screenX,t.screenY);s.beginInteraction()}}drag(t,i){if(this.currentPosition!=null){const s=o.create(t.screenX,t.screenY);const n=o.subtract(s,this.currentPosition);i.rotateCamera(n);this.currentPosition=s}}endDrag(t,i){super.endDrag(t,i)}}class Ct extends gt{constructor(){super(...arguments);this.type="rotate-point"}beginDrag(t,i,s){if(this.currentPosition==null){this.currentPosition=o.create(t.screenX,t.screenY);this.startingPosition=i;s.beginInteraction()}}drag(t,i){if(this.currentPosition!=null&&this.startingPosition!=null){const s=o.create(t.screenX,t.screenY);const n=o.subtract(s,this.currentPosition);i.rotateCameraAtPoint(n,this.startingPosition);this.currentPosition=s}}endDrag(t,i){super.endDrag(t,i)}}class bt extends gt{constructor(t=1e3){super();this.interactionTimeout=t;this.type="zoom";this.didTransformBegin=false}beginDrag(t,i,s,n){if(this.currentPosition==null){this.currentPosition=o.create(t.clientX,t.clientY);const i=n.getBoundingClientRect();const e=x(t,i);this.startPt=e;s.beginInteraction()}}drag(t,i){if(this.currentPosition!=null){const s=o.create(t.clientX,t.clientY);const n=o.subtract(s,this.currentPosition);if(this.startPt!=null){i.zoomCameraToPoint(this.startPt,n.y);this.currentPosition=s}}}endDrag(t,i){super.endDrag(t,i);this.stopInteractionTimer();this.didTransformBegin=false;this.startPt=undefined}zoom(t,i){this.operateWithTimer(i,(()=>i.zoomCamera(t)))}zoomToPoint(t,i,s){this.operateWithTimer(s,(()=>s.zoomCameraToPoint(t,i)))}beginInteraction(t){this.didTransformBegin=true;t.beginInteraction()}endInteraction(t){this.didTransformBegin=false;t.endInteraction()}resetInteractionTimer(t){this.stopInteractionTimer();this.startInteractionTimer(t)}startInteractionTimer(t){this.interactionTimer=window.setTimeout((()=>{this.interactionTimer=undefined;this.endInteraction(t)}),this.interactionTimeout)}stopInteractionTimer(){if(this.interactionTimer!=null){window.clearTimeout(this.interactionTimer);this.interactionTimer=undefined}}operateWithTimer(t,i){if(!this.didTransformBegin){this.beginInteraction(t)}this.resetInteractionTimer(t);i()}}class Pt extends gt{constructor(){super(...arguments);this.type="pan"}beginDrag(t,i,s,n){if(this.currentPosition==null){this.currentPosition=o.create(t.screenX,t.screenY);this.canvasRect=n.getBoundingClientRect();s.beginInteraction()}}drag(t,i){if(this.currentPosition!=null&&this.canvasRect!=null){const s=x(t,this.canvasRect);i.panCameraToScreenPoint(s);this.currentPosition=s}}endDrag(t,i){super.endDrag(t,i)}}class It extends gt{constructor(){super(...arguments);this.type="twist"}beginDrag(t,i,s,n){this.currentPosition=o.create(t.offsetX,t.offsetY);this.canvasRect=n.getBoundingClientRect();s.beginInteraction()}drag(t,i){const s=x(t,this.canvasRect);this.currentPosition=s;i.twistCamera(s)}endDrag(t,i){super.endDrag(t,i)}}class Tt extends gt{constructor(){super(...arguments);this.type="pivot"}beginDrag(t,i,s){if(this.currentPosition==null){this.currentPosition=o.create(t.screenX,t.screenY);s.beginInteraction()}}drag(t,i){if(this.currentPosition!=null){const s=o.create(t.screenX,t.screenY);const n=o.subtract(s,this.currentPosition);i.pivotCamera(-.25*n.y,.25*n.x);this.currentPosition=s}}endDrag(t,i){super.endDrag(t,i)}}class Dt extends mt{constructor(t,i=new yt,s=new Ct,n=new bt,e=new Pt,o=new It,h=new Tt){super("mousedown","mouseup","mousemove",i,s,n,e,o,h,t)}}class kt{initialize(t,i){this.element=t;this.interactionApi=i}dispose(){this.element=undefined}handleTwoPointTouchMove(t,i){var s,n,e,h;if(this.currentPosition1!=null&&this.currentPosition2!=null){const a=o.add(o.subtract(t,this.currentPosition1),o.subtract(i,this.currentPosition2));const c=o.distance(t,i)-o.distance(this.currentPosition1,this.currentPosition2);const l=c*.5;const u=d.create(o.subtract(this.currentPosition1,this.currentPosition2),o.subtract(t,i));const f=r.toDegrees(Math.atan2(d.determinant(u),d.dot(u)));const w=o.create((t.x+i.x)/2,(t.y+i.y)/2);(s=this.interactionApi)===null||s===void 0?void 0:s.beginInteraction();(n=this.interactionApi)===null||n===void 0?void 0:n.zoomCameraToPoint(w,l);(e=this.interactionApi)===null||e===void 0?void 0:e.panCameraByDelta(a);if(Math.abs(f)>.5){(h=this.interactionApi)===null||h===void 0?void 0:h.twistCamera(f)}}this.currentPosition1=t;this.currentPosition2=i}}class St extends kt{constructor(){super();this.touchPoints={};this.handlePointerDown=this.handlePointerDown.bind(this);this.handlePointerMove=this.handlePointerMove.bind(this);this.handlePointerUp=this.handlePointerUp.bind(this)}dispose(){var t;(t=this.element)===null||t===void 0?void 0:t.removeEventListener("pointerdown",this.handlePointerDown);super.dispose()}initialize(t,i){super.initialize(t,i);t.addEventListener("pointerdown",this.handlePointerDown)}handlePointerDown(t){const i=o.create(t.screenX,t.screenY);this.touchPoints=Object.assign(Object.assign({},this.touchPoints),{[t.pointerId]:i});const s=Object.keys(this.touchPoints);if(s.length===1){window.addEventListener("pointermove",this.handlePointerMove);window.addEventListener("pointerup",this.handlePointerUp)}}handlePointerMove(t){if(this.touchPoints[t.pointerId]!=null){this.touchPoints[t.pointerId]=o.create(t.screenX,t.screenY)}const i=Object.keys(this.touchPoints);if(i.length===2){const t=this.touchPoints[i[0]];const s=this.touchPoints[i[1]];this.handleTwoPointTouchMove(t,s)}}handlePointerUp(t){var i;delete this.touchPoints[t.pointerId];const s=Object.keys(this.touchPoints);if(s.length===1){(i=this.interactionApi)===null||i===void 0?void 0:i.endInteraction();this.currentPosition1=undefined;this.currentPosition2=undefined}if(s.length===0){window.removeEventListener("pointermove",this.handlePointerMove);window.removeEventListener("pointerup",this.handlePointerUp)}}}class Mt extends mt{constructor(t){super("pointerdown","pointerup","pointermove",new yt,new Ct,new bt,new Pt,new It,new Tt,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=o.create(t.screenX,t.screenY);this.touchPoints.add(t.pointerId);if(this.touchPoints.size===1){window.addEventListener("pointerup",this.handlePointerUp)}if(this.touchPoints.size===2){this.disableIndividualInteractions=true}}handlePointerUp(t){this.touchPoints.delete(t.pointerId);if(this.touchPoints.size<2){this.disableIndividualInteractions=false}if(this.touchPoints.size===0){window.removeEventListener("pointerup",this.handlePointerUp)}}}class xt{constructor(t,i,s,n){this.downEvent=t;this.upEvent=i;this.moveEvent=s;this.getConfig=n;this.handleDown=this.handleDown.bind(this);this.handleUp=this.handleUp.bind(this);this.handleMove=this.handleMove.bind(this);this.handleTouchStart=this.handleTouchStart.bind(this);this.handleTouchMove=this.handleTouchMove.bind(this);this.handleTouchEnd=this.handleTouchEnd.bind(this);this.handlePointerMove=this.handlePointerMove.bind(this);this.handlePointerEnd=this.handlePointerEnd.bind(this);this.clearPositions=this.clearPositions.bind(this);this.restartDoubleTapTimer=this.restartDoubleTapTimer.bind(this);this.clearDoubleTapTimer=this.clearDoubleTapTimer.bind(this);this.restartLongPressTimer=this.restartLongPressTimer.bind(this);this.clearLongPressTimer=this.clearLongPressTimer.bind(this);this.setPointerPositions=this.setPointerPositions.bind(this);this.emit=this.emit.bind(this)}dispose(){var t,i;(t=this.element)===null||t===void 0?void 0:t.removeEventListener(this.downEvent,this.handleDown);(i=this.element)===null||i===void 0?void 0:i.removeEventListener("touchstart",this.handleTouchStart);this.element=undefined;this.clearDoubleTapTimer();this.clearLongPressTimer()}initialize(t,i){this.element=t;this.interactionApi=i;t.addEventListener(this.downEvent,this.handleDown);t.addEventListener("touchstart",this.handleTouchStart)}handleTouchStart(t){if(t.touches.length===1){this.setPointerPositions(o.create(t.touches[0].clientX,t.touches[0].clientY));this.restartLongPressTimer();window.addEventListener("touchend",this.handleTouchEnd);window.addEventListener("touchmove",this.handleTouchMove)}}handleTouchMove(t){if(t.touches.length>0){this.handlePointerMove(o.create(t.touches[0].clientX,t.touches[0].clientY),true)}}handleTouchEnd(t){if(this.pointerDownPosition!=null){window.removeEventListener("touchend",this.handleTouchEnd);window.removeEventListener("touchmove",this.handleTouchMove)}this.handlePointerEnd(this.pointerDownPosition)}handleDown(t){this.setPointerPositions(o.create(t.clientX,t.clientY));this.buttons=t.buttons;const i={altKey:t.altKey,ctrlKey:t.ctrlKey,metaKey:t.metaKey,shiftKey:t.shiftKey};this.restartLongPressTimer(i);window.addEventListener(this.upEvent,this.handleUp);window.addEventListener(this.moveEvent,this.handleMove)}handleMove(t){this.handlePointerMove(o.create(t.clientX,t.clientY),this.isTouch(t))}handleUp(t){if(this.pointerDownPosition!=null){window.removeEventListener(this.upEvent,this.handleUp);window.removeEventListener(this.moveEvent,this.handleMove)}this.handlePointerEnd(o.create(t.clientX,t.clientY),{altKey:t.altKey,ctrlKey:t.ctrlKey,metaKey:t.metaKey,shiftKey:t.shiftKey},this.buttons,this.isTouch(t));this.buttons=undefined}handlePointerMove(t,i){var s;const n=((s=this.interactionApi)===null||s===void 0?void 0:s.pixelThreshold(i))||2;if(this.pointerDownPosition!=null&&o.distance(t,this.pointerDownPosition)>=n&&this.interactionTimer==null){this.clearPositions()}}handlePointerEnd(t,i={},s=0,n=false){var e,o;if(t!=null){if(this.longPressTimer!=null){this.emit((e=this.interactionApi)===null||e===void 0?void 0:e.tap)(t,i,s)}if(this.doubleTapTimer!=null&&this.secondPointerDownPosition!=null){this.emit((o=this.interactionApi)===null||o===void 0?void 0:o.doubleTap)(t,i,s,this.secondPointerDownPosition);this.clearDoubleTapTimer()}}this.pointerDownPosition=undefined;this.clearLongPressTimer()}emit(t){return(i,s={},n=0,e,h=false)=>{var r;const a=e||this.pointerDownPosition;const c=((r=this.interactionApi)===null||r===void 0?void 0:r.pixelThreshold(h))||1;let l;if(this.interactionTimer!=null){l=this.getCanvasPosition(a||i)}else if(a!=null&&o.distance(a,i)<=c){l=this.getCanvasPosition(i)}if(l!=null&&t!=null){t(l,s,n)}}}getCanvasPosition(t){var i;const s=(i=this.element)===null||i===void 0?void 0:i.getBoundingClientRect();const n=s!=null?o.create(s.left,s.top):undefined;return n!=null?o.subtract(o.create(t.x,t.y),n):undefined}clearPositions(){this.pointerDownPosition=undefined;this.firstPointerDownPosition=undefined;this.secondPointerDownPosition=undefined;this.clearDoubleTapTimer();this.clearLongPressTimer();this.clearInteractionTimer()}clearDoubleTapTimer(){if(this.doubleTapTimer!=null){window.clearTimeout(this.doubleTapTimer)}this.doubleTapTimer=undefined;this.firstPointerDownPosition=undefined;this.secondPointerDownPosition=undefined}restartDoubleTapTimer(){this.clearDoubleTapTimer();this.doubleTapTimer=window.setTimeout((()=>this.clearDoubleTapTimer()),this.getConfig().events.doubleTapThreshold)}clearLongPressTimer(){if(this.longPressTimer!=null){window.clearTimeout(this.longPressTimer)}this.longPressTimer=undefined}restartLongPressTimer(t={}){this.clearLongPressTimer();this.longPressTimer=window.setTimeout((()=>{var i;if(this.pointerDownPosition){this.emit((i=this.interactionApi)===null||i===void 0?void 0:i.longPress)(this.pointerDownPosition,t,this.buttons)}this.clearLongPressTimer()}),this.getConfig().events.longPressThreshold)}restartInteractionTimer(){this.clearInteractionTimer();this.interactionTimer=window.setTimeout((()=>{this.interactionTimer=undefined}),this.getConfig().interactions.interactionDelay)}clearInteractionTimer(){if(this.interactionTimer!=null){window.clearTimeout(this.interactionTimer);this.interactionTimer=undefined}}setPointerPositions(t){this.pointerDownPosition=t;this.restartInteractionTimer();if(this.firstPointerDownPosition==null){this.restartDoubleTapTimer();this.firstPointerDownPosition=t}else{this.secondPointerDownPosition=t}}isTouch(t){return window.PointerEvent!=null&&t instanceof PointerEvent?t.pointerType==="touch":false}}class Et extends kt{constructor(){super();this.handleTouchStart=this.handleTouchStart.bind(this);this.handleTouchMove=this.handleTouchMove.bind(this);this.handleTouchEnd=this.handleTouchEnd.bind(this)}dispose(){var t;(t=this.element)===null||t===void 0?void 0:t.removeEventListener("touchstart",this.handleTouchStart);super.dispose()}initialize(t,i){super.initialize(t,i);t.addEventListener("touchstart",this.handleTouchStart)}handleTouchStart(t){if(t.touches.length>=1){const i=t.touches[0];const s=t.touches[1];this.currentPosition1=o.create(i.screenX,i.screenY);this.currentPosition2=s!=null?o.create(s.screenX,s.screenY):undefined;window.addEventListener("touchmove",this.handleTouchMove,{passive:false});window.addEventListener("touchend",this.handleTouchEnd)}}handleTouchMove(t){if(t.touches.length===1){this.handleOnePointTouchMove(t.touches[0])}else if(t.touches.length===2){const i=o.create(t.touches[0].clientX,t.touches[0].clientY);const s=o.create(t.touches[1].clientX,t.touches[1].clientY);this.handleTwoPointTouchMove(i,s)}}handleTouchEnd(t){var i;(i=this.interactionApi)===null||i===void 0?void 0:i.endInteraction();this.isInteracting=false;window.removeEventListener("touchmove",this.handleTouchMove);window.removeEventListener("touchend",this.handleTouchEnd)}handleOnePointTouchMove(t){var i,s,n;const e=o.create(t.screenX,t.screenY);if(this.currentPosition1!=null){const t=o.subtract(e,this.currentPosition1);const h=((i=this.interactionApi)===null||i===void 0?void 0:i.pixelThreshold(true))||2;if(o.distance(e,this.currentPosition1)>=h||this.isInteracting){(s=this.interactionApi)===null||s===void 0?void 0:s.beginInteraction();(n=this.interactionApi)===null||n===void 0?void 0:n.rotateCamera(t);this.isInteracting=true}}this.currentPosition1=e}}class Ot{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(rt(t)){const i=this.begin();return t.finally((()=>this.end(i)))}else if(typeof t==="function"){const i=this.begin();const s=t();this.end(i);return s}else{throw new Error("Input must be a function or Promise")}}takeMeasurements(){const t=this.perf.getEntriesByName(this.name);this.clearMeasurements();return t}takeLastMeasurement(){const t=this.takeMeasurements();return t[t.length-1]}begin(){const t=`${this.name}-${this.nextId++}`;this.measures.add(t);this.perf.mark(t);return t}end(t){this.perf.measure(this.name,t);this.perf.clearMarks(t);this.measures.delete(t)}}const jt=new Ot("paint_time");function At(t){return new Promise(((i,s)=>{const n=new Blob([t]);const e=URL.createObjectURL(n);const o=new Image;o.addEventListener("load",(()=>{i({image:o,dispose:()=>undefined});URL.revokeObjectURL(e)}));o.addEventListener("error",(()=>{s(new O("Failed to load image data"));URL.revokeObjectURL(e)}));o.src=e}))}async function Rt(t){const i=new Blob([t]);const s=await window.createImageBitmap(i);return{image:s,dispose:()=>s.close()}}function Ft(t){if(window.createImageBitmap!=null){return Rt(t)}else{return At(t)}}const zt=1e3;function Bt(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)}function Lt(t,i){const s=t.takeMeasurements();if(s.length>0){i(s)}}function Nt(t,i,s,n,e=zt){let o;let h=0;let r;let a=[];function c(){h++;if(o==null){o=setInterval((()=>{Lt(t,n);if(h===0){d()}}),e)}}function l(){h--}function d(){if(o!=null){clearInterval(o);o=undefined}}if(s){setInterval((()=>{if(r!=null){if(a.length===5){a=[...a.slice(1),r]}else{a.push(r)}const t=a.reduce(((t,i)=>t+i))/a.length;console.debug(`Paint rate: ${r}fps`);console.debug(`Paint rate (avg): ${t}`);r=undefined}}),1e3)}return s=>{c();return t.measure((async()=>{const t=await i(s);r=r==null?1:r+1;return t})).finally((()=>l()))}}function $t(){let t=[];function i(i){if(i!=null){const s=i.copy({correlationIds:[...i.correlationIds,...t.filter((t=>!i.correlationIds.includes(t)))]});t=[];return s}return i}function s(){let t=-1;return async i=>{if(i.frame.sequenceNumber>t){const s=await Ft(i.frame.image.imageBytes);t=i.frame.sequenceNumber;return s}}}function n(){let t=-1;return async(i,s)=>{var n;if(s!=null&&i.frame.sequenceNumber>t){t=i.frame.sequenceNumber;(n=i.beforeDraw)===null||n===void 0?void 0:n.call(i);Bt(s,i);s.dispose();return i.frame}s===null||s===void 0?void 0:s.dispose()}}const e=s();const o=n();return async s=>{var n,h;const r=(h=(n=s.predicate)===null||n===void 0?void 0:n.call(s))!==null&&h!==void 0?h:true;t=[...t,...s.frame.correlationIds];if(r){return e(s).then((t=>o(s,t).then(i)))}}}function Kt(t){return i=>{var s;const n=(s=i.request.requestId)===null||s===void 0?void 0:s.value;if(n!=null){t(n)(i)}}}function Ht(t){return i=>{const{drawFrame:s}=i.request;if(s!=null){t(s)(i)}}}const Wt=1*60;function Vt(t){let i=false;return s=>{const n=t();if(n!=null){const t=n.remoteTime(new Date(Date.now()));const e=f(s,t);const o=w(e).getTime();if(o>=0){return e}else{if(!i){console.warn(`Possible erroneous send to receive timing. Muting for ${Wt}s. [sent-at=${s.toISOString()}, received-at=${t.toISOString()}, remote-time=${n.knownRemoteTime.toISOString()}]`);i=true;setTimeout((()=>i=false),Wt*1e3)}return undefined}}}}function qt(t,i){const s=Vt(i);return Kt((i=>Ht((n=>n=>{const e=w(n.sentAtTime);if(e!=null){t.replyResult(i,{drawFrame:{sendToReceiveDuration:s(e)}})}}))))}var Ut;(function(t){t["DEVICE_ID"]="vertexvis:device-id"})(Ut||(Ut={}));function _t(t,i,s=window.localStorage){const n=s.getItem(t);if(n!=null){const e=Object.assign(Object.assign({},JSON.parse(n)),i);s.setItem(t,JSON.stringify(e))}else{s.setItem(t,JSON.stringify(i))}}function Jt(t,i,s=window.localStorage){const n=s.getItem(t);if(n!=null){return i(JSON.parse(n))}}class Xt extends p{constructor(t,i={}){var s,n,e;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=S("platprod");this.options={tokenRefreshOffsetInSeconds:(s=i.tokenRefreshOffsetInSeconds)!==null&&s!==void 0?s:30,offlineThresholdInSeconds:(n=i.offlineThresholdInSeconds)!==null&&n!==void 0?n:30,loadTimeoutInSeconds:(e=i.loadTimeoutInSeconds)!==null&&e!==void 0?e:15}}getState(){return this.state}disconnect(){if(this.state.type!=="disconnected"&&this.state.type!=="connection-failed"){console.debug("Disconnecting websocket");this.state.connection.dispose();this.updateState({type:"disconnected"})}}async load(t,i,s,n=S("platprod")){this.clientId=i;this.deviceId=s;this.config=n;if(this.state.type==="disconnected"){return this.loadIfDisconnected(t)}else if(this.state.type==="connection-failed"){return this.loadIfDisconnected(t)}else if(this.state.type==="reconnecting"){return this.loadIfConnectingOrConnected(t,this.state)}else if(this.state.type==="connecting"){return this.loadIfConnectingOrConnected(t,this.state)}else{return this.loadIfConnectingOrConnected(t,this.state)}}update(t){this.frameBgColor=t.frameBgColor?t.frameBgColor:this.frameBgColor;if(t.dimensions!=null&&t.dimensions!==this.dimensions){this.dimensions=t.dimensions;this.ifState("connected",(()=>this.updateDimensions({dimensions:this.dimensions})))}if(t.streamAttributes!=null&&this.streamAttributes!==t.streamAttributes){this.streamAttributes=t.streamAttributes;this.ifState("connected",(()=>this.updateStream({streamAttributes:Gt(this.streamAttributes)})))}}async loadIfConnectingOrConnected(t,i){var s;const{resource:n,subResource:e}=i.resource;const o=tt(t);const h=!P.isEqual(n,o.resource);const r=!P.isEqual(e,o.subResource);const a=i.type==="connecting"||i.type==="reconnecting";const c=i.type==="connected";const l=o.queries.find((t=>t.type==="supplied-id"));if(h||a&&r){this.disconnect();return this.loadIfDisconnected(t)}else if(c&&r&&((s=o.subResource)===null||s===void 0?void 0:s.type)==="scene-view-state"){const t=Object.assign(Object.assign({},o.subResource.id!=null?{sceneViewStateId:{hex:o.subResource.id}}:{}),l!=null?{sceneViewStateSuppliedId:{value:l.id}}:{});await this.loadSceneViewState(t);this.updateState(Object.assign(Object.assign({},i),{resource:o}))}}async loadIfDisconnected(t){try{await this.connectWithNewStream(tt(t))}catch(t){if(t instanceof j){this.updateState({type:"connection-failed",message:`Cannot load scene. ${t.message}`,error:t})}else if(t instanceof v){this.updateState({type:"connection-failed",message:`Cannot load scene. Stream request failed to start stream.`,error:t})}else{this.updateState({type:"connection-failed",message:`Cannot load scene for unknown reason. See console logs.`,error:t})}throw t}}connectWithNewStream(t){return this.openWebsocketStream(t,"connecting",(()=>this.requestNewStream(t)))}connectToExistingStream(t){return this.openWebsocketStream(t.resource,"reconnecting",(()=>this.requestReconnectStream(t)),{maxRetries:Number.POSITIVE_INFINITY})}async openWebsocketStream(t,i,s,{maxRetries:n=3}={}){const e=Qt(ti(this.config,t.resource,this.clientId,this.deviceId));console.debug(`Initiating WS connection [uri=${e.url}]`);const o=new AbortController;const h=Yt(this.config);this.updateState({type:i,resource:t,connection:{dispose:()=>{this.dispose();o.abort()}}});const r=await T.abort(o.signal,T.retry((()=>this.connect(e,h)),{maxRetries:n,delaysInMs:Xt.WS_RECONNECT_DELAYS})).catch((t=>{throw new A("Websocket connection failed.",t instanceof Error?t:undefined)}));if(!r.aborted){return this.requestNewOrExistingStream(t,r.result,s)}else{this.updateState({type:"disconnected"})}}async requestNewOrExistingStream(t,i,s){const n=this.requestClock();const e=await s();console.debug(`Stream connected [stream-id=${e.streamId}, scene-id=${e.sceneId}, scene-view-id=${e.sceneViewId}]`);const o=this.onRequest((t=>{const i=t.request.drawFrame;if(i!=null){const t=V(e.worldOrientation)(i);if(this.state.type==="connected"){this.updateState(Object.assign(Object.assign({},this.state),{frame:t}))}}}));const h=this.reconnectWhenNeeded();const r=this.refreshTokenWhenExpired(e.token);const a=this.acknowledgeFrameRequests();const c=e.frame==null?await this.waitForFrame(e.worldOrientation,this.options.loadTimeoutInSeconds):e.frame;const l=await n;console.debug(`Synchronized clocks [local-time=${l.knownLocalTime.toISOString()}, remote-time=${l.knownRemoteTime.toISOString()}]`);this.updateState({type:"connected",connection:{dispose:()=>{h.dispose();o.dispose();r.dispose();a.dispose();i.dispose()}},resource:t,streamId:e.streamId,deviceId:e.deviceId,sceneId:e.sceneId,sceneViewId:e.sceneViewId,worldOrientation:e.worldOrientation,token:e.token,frame:c,clock:l})}async requestNewStream(t){var i,s;const n=t.queries.find((t=>t.type==="supplied-id"));const e=q(await this.startStream({streamKey:{value:t.resource.id},dimensions:this.dimensions,frameBackgroundColor:Zt(this.frameBgColor),streamAttributes:Gt(this.streamAttributes),sceneViewStateId:((i=t.subResource)===null||i===void 0?void 0:i.type)==="scene-view-state"&&t.subResource.id!=null?{hex:t.subResource.id}:undefined,sceneViewStateSuppliedId:((s=t.subResource)===null||s===void 0?void 0:s.type)==="scene-view-state"&&n!=null?{value:n.id}:undefined}));return{resource:t,streamId:e.streamId,sceneId:e.sceneId,sceneViewId:e.sceneViewId,deviceId:e.sessionId,token:e.token,worldOrientation:e.worldOrientation,frame:undefined}}async requestReconnectStream(t){const i=U(await this.reconnect({streamId:{hex:t.streamId},dimensions:this.dimensions,frameBackgroundColor:Zt(this.frameBgColor),streamAttributes:Gt(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((()=>{if(this.state.type==="connected"){this.closeAndReconnect(this.state)}}));const i=this.onRequest((t=>{const i=t.request.gracefulReconnection!=null;if(i&&this.state.type==="connected"){console.debug("Received request for graceful reconnect. Closing connection and attempting reconnect.");this.closeAndReconnect(this.state)}}));const s=this.reconnectWhenOffline();return{dispose:()=>{t.dispose();i.dispose();s.dispose()}}}refreshTokenWhenExpired(t){let i;const s=t=>{const{tokenRefreshOffsetInSeconds:n}=this.options;const e=t.remainingTimeInMs(n);i=window.setTimeout((async()=>{const t=await this.refreshToken();const i=J(t);s(i);if(this.state.type==="connected"){this.updateState(Object.assign(Object.assign({},this.state),{token:i}))}}),e)};s(t);return{dispose:()=>clearTimeout(i)}}reconnectWhenOffline(){let t;const i=()=>window.clearTimeout(t);const s=()=>{i();const s=this.options.offlineThresholdInSeconds;console.debug(`Detected that host is offline. Will attempt reconnect in ${s}s.`);t=window.setTimeout((()=>{if(this.state.type==="connected"){this.closeAndReconnect(this.state)}}),s*1e3)};const n=()=>{console.debug("Detected that host is online.");i()};const e=()=>s();window.addEventListener("offline",e);window.addEventListener("online",n);return{dispose:()=>{i();window.removeEventListener("offline",s);window.removeEventListener("online",i)}}}closeAndReconnect(t){t.connection.dispose();return this.connectToExistingStream(t)}async waitForFrame(t,i){let s;try{return await T.timeout(i*1e3,new Promise((i=>{s=this.onRequest((n=>{try{const e=n.request.drawFrame;if(e!=null){const s=V(t)(e);i(s)}}finally{s===null||s===void 0?void 0:s.dispose()}}))})))}catch(t){throw new R(`Frame timed out after ${i/1e3}s`,t instanceof Error?t:undefined)}finally{s===null||s===void 0?void 0:s.dispose()}}acknowledgeFrameRequests(){return this.onRequest(qt(this,(()=>this.state.type==="connected"?this.state.clock:undefined)))}updateState(t){if(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)}}Xt.WS_RECONNECT_DELAYS=[0,1e3,1e3,5e3];const Gt=C.ifInvalidThrow(H);const Zt=C.ifInvalidThrow(W);function Yt(t){return{EXPERIMENTAL_frameDelivery:Object.assign(Object.assign({},t.EXPERIMENTAL_frameDelivery),{rateLimitingEnabled:t.flags.throttleFrameDelivery}),EXPERIMENTAL_adaptiveRendering:Object.assign(Object.assign({},t.EXPERIMENTAL_adaptiveRendering),{enabled:t.flags.adaptiveRendering}),EXPERIMENTAL_qualityOfService:Object.assign({},t.EXPERIMENTAL_qualityOfService)}}function Qt(t){return{url:I.toString(t),protocols:["ws.vertexvis.com"]}}function ti(t,i,s,n){if(s!=null){return I.appendPath(I.toString(I.parseAndAddParams("/ws",{clientId:s,deviceId:n})),I.parse(t.network.renderingHost))}else{return I.appendPath(`/stream-keys/${i.id}/session`,I.parse(t.network.renderingHost))}}const ii=15e3;function si(t){const i=window.getComputedStyle(t);return b.fromCss(i.backgroundColor)}function ni(t){return t.getBoundingClientRect()}const ei=":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}";const oi=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=true;this.cameraType="perspective";this.keyboardControls=true;this.rotateAroundTapPoint=true;this.phantom={opacity:.1};this.noDefaultLights=false;this.experimentalRenderingOptions="";this.resizeDebounce=100;this.stencilBuffer=new ot(this.hostElement);this.viewport=Q.fromDimensions(u.create(0,0));this.stateMap={cursorManager:new M,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=(t=this.stream)!==null&&t!==void 0?t:new Xt(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();if(this.containerElement!=null){(t=this.resizeObserver)===null||t===void 0?void 0:t.observe(this.containerElement)}if(this.src!=null){this.load(this.src).catch((t=>{console.error("Error loading scene",t)}))}this.initializeDefaultInteractionHandlers();this.injectViewerApi()}render(){var t;return s(n,null,s("div",{class:"viewer-container",style:{cursor:E((t=this.cursor)!==null&&t!==void 0?t:"")},onContextMenu:t=>t.preventDefault()},s("div",{ref:t=>this.containerElement=t,class:k("canvas-container",{"enable-pointer-events ":window.PointerEvent!=null})},s("canvas",{ref:t=>{this.canvasElement=t;this.stateMap.interactionTarget=t},class:"canvas"}),this.errorMessage!=null?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){this.interactionHandlers.push(t);this.initializeInteractionHandler(t);return{dispose:()=>{const i=this.interactionHandlers.indexOf(t);if(i!==-1){this.interactionHandlers[i].dispose();this.interactionHandlers.splice(i,1)}}}}async registerTapKeyInteraction(t){this.tapKeyInteractions=[...this.tapKeyInteractions,t]}async getInteractionTarget_DEPRECATED(){if(this.stateMap.interactionTarget!=null){return this.stateMap.interactionTarget}else throw new Error("Interaction target is undefined.")}async addCursor(t,i){return this.stateMap.cursorManager.add(t,i)}async getInteractionHandlers(){return this.interactionHandlers}async getKeyInteractions(){return this.tapKeyInteractions}async getBaseInteractionHandler(){return this.baseInteractionHandler}async getJwt(){return this.token}handleSrcChanged(t){if(t!=null){this.load(t)}else{this.unload()}}handleCameraControlsChanged(){this.initializeDefaultCameraInteractionHandlers()}handleKeyboardControlsChanged(){this.initializeDefaultKeyboardInteractionHandlers()}handleRotateAboutTapPointChanged(){var t,i;this.updateStreamAttributes();if(this.rotateAroundTapPoint){(t=this.baseInteractionHandler)===null||t===void 0?void 0:t.setPrimaryInteractionType("rotate-point")}else{(i=this.baseInteractionHandler)===null||i===void 0?void 0:i.setPrimaryInteractionType("rotate")}}handleCameraTypeChanged(t,i){if(t!==i){this.updateCameraType()}}handleDepthBuffersChanged(){this.updateStreamAttributes()}handlePhantomChanged(){this.updateStreamAttributes()}handleNoDefaultLightsChanged(){this.updateStreamAttributes()}handleExperimentalRenderingOptionsChanged(){this.updateStreamAttributes()}handleFeatureLinesChanged(){this.updateStreamAttributes()}handleSelectionHighlightingChanged(){this.updateStreamAttributes()}handleFeatureHighlightingChanged(){this.updateStreamAttributes()}handleFeatureMapsChanged(){this.updateStreamAttributes()}handleConfigChanged(){this.updateResolvedConfig()}handleConfigEnvChanged(){this.updateResolvedConfig()}async load(t){var i;if(this.stream!=null&&this.dimensions!=null){this.calculateComponentDimensions();this.stream.update({streamAttributes:this.getStreamAttributes(),config:S(this.configEnv,this.config),dimensions:this.dimensions,frameBgColor:this.getBackgroundColor()});await((i=this.stream)===null||i===void 0?void 0:i.load(t,this.clientId,this.getDeviceId(),this.getResolvedConfig()));this.sceneReady.emit()}else{throw new F("Cannot load scene. Viewer has not been initialized.")}}async unload(){if(this.stream!=null){this.stream.disconnect();this.frame=undefined;this.errorMessage=undefined}if(this.canvasElement!=null){const t=this.canvasElement.getContext("2d");if(t!=null){t.clearRect(0,0,this.canvasElement.width,this.canvasElement.height)}}}async scene(){return this.createScene()}async isSceneReady(){return this.stateMap.streamState.type==="connected"}async handleTapEvent(t){this.tapKeyInteractions.filter((i=>i.predicate(t.detail))).forEach((i=>i.fn(t.detail)))}emitConnectionChange(t){this.connectionChange.emit(t)}handleElementResize(t){const i=t.length>0&&this.dimensions!=null&&!u.isEqual(t[0].contentRect,this.viewport);if(i){if(this.resizeTimer!=null){clearTimeout(this.resizeTimer);this.resizeTimer=undefined}if(!this.isResizing){this.resizeTimer=setTimeout((()=>{this.isResizing=true;this.isResizeUpdate=true;this.recalculateComponentDimensions()}),this.resizeDebounce)}}}registerSlotChangeListeners(){this.mutationObserver=new MutationObserver((t=>this.injectViewerApi()));this.mutationObserver.observe(this.hostElement,{childList:true,subtree:true})}injectViewerApi(){function t(t){return Array.from(t.querySelectorAll("*"))}const i=t(this.hostElement);i.filter((t=>t.nodeName.startsWith("VERTEX-"))).reduce(((i,s)=>[...i,s,...t(s)]),[]).forEach((t=>{t.viewer=this.hostElement}))}calculateComponentDimensions(){var t;const i=2073600;const s=this.getBounds();if((s===null||s===void 0?void 0:s.width)!=null&&(s===null||s===void 0?void 0:s.height)!=null){const n=u.create(s.width,s.height);const e=u.scaleFit(i,n);this.hostDimensions=n;this.dimensions=e!=null?u.create(e.width,e.height):undefined;this.viewport=Q.fromDimensions((t=this.getCanvasDimensions())!==null&&t!==void 0?t:u.create(0,0))}}recalculateComponentDimensions(){var t;if(this.isResizing){this.calculateComponentDimensions();this.isResizing=false;if(((t=this.stream)===null||t===void 0?void 0:t.getState().type)==="connected"){this.updateDimensions(this.dimensions)}}}reportPerformance(t){if(this.stateMap.streamState.type==="connected"){const i={timings:t.map((t=>({receiveToPaintDuration:f(t.duration)})))};this.getStream().recordPerformance(i,false)}}addStreamListeners(){this.stateMap.streamListeners=this.getStream().stateChanged.on((t=>{this.handleStreamStateChanged(this.stateMap.streamState,t)}))}handleStreamStateChanged(t,i){this.stateMap.streamState=i;if(i.type==="connecting"){this.handleConnecting(t,i)}else if(i.type==="connected"){this.handleConnected(t,i)}else if(i.type==="connection-failed"){this.handleConnectionFailed(t,i)}else if(i.type==="disconnected"){this.handleDisconnected(t,i)}}handleConnecting(t,i){if(t.type!=="connecting"){this.token=undefined;this.errorMessage=undefined;this.emitConnectionChange({status:"connecting"})}}handleConnected(t,i){var s;this.token=i.token.token;if(t.type!=="connected"){this.errorMessage=undefined;this.canvasRenderer=Nt(jt,$t(),this.getResolvedConfig().flags.logFrameRate,(t=>this.reportPerformance(t)));this.emitConnectionChange({status:"connected",jwt:i.token.token});this.deviceIdChange.emit(i.deviceId)}if(((s=this.frame)===null||s===void 0?void 0:s.getId())!==i.frame.getId()){this.updateFrame(i.frame)}this.updateDimensions(this.dimensions)}handleConnectionFailed(t,i){if(t.type!=="connection-failed"){this.token=undefined;this.errorMessage=i.message;this.emitConnectionChange({status:"connection-failed",errorMessage:i.message})}}handleDisconnected(t,i){if(t.type!=="disconnected"){this.token=undefined;this.errorMessage=undefined;this.emitConnectionChange({status:"disconnected"})}}updateDimensions(t){var i;(i=this.stream)===null||i===void 0?void 0:i.update({dimensions:t});this.dimensionschange.emit(t)}async updateFrame(t){var i;const s=this.getCanvasDimensions();if(this.canvasElement!=null&&s!=null&&((i=this.frame)===null||i===void 0?void 0:i.getId())!==t.getId()){const i=this.canvasElement.getContext("2d");if(i!=null){const n=this.frame;this.frame=X(t,n);this.updateInteractionApi(n);const e={canvas:i,canvasDimensions:s,dimensions:this.dimensions,frame:this.frame,viewport:this.viewport,beforeDraw:()=>{this.updateCanvasDimensions(s);this.isResizeUpdate=false},predicate:()=>{if(this.isResizeUpdate){return this.dimensions==null||u.isEqual(this.dimensions,e.frame.image.imageAttr.frameDimensions)}return true}};this.frameReceived.emit(this.frame);if(this.frame.scene.hasChanged){this.sceneChanged.emit()}const o=await this.canvasRenderer(e);if(o!=null){this.dispatchFrameDrawn(o)}}}}async initializeDefaultInteractionHandlers(){var t;await this.initializeDefaultCameraInteractionHandlers();await this.initializeDefaultTapInteractionHandler();this.initializeDefaultKeyboardInteractionHandlers();if(this.rotateAroundTapPoint){(t=this.baseInteractionHandler)===null||t===void 0?void 0:t.setPrimaryInteractionType("rotate-point")}}clearDefaultCameraInteractionHandlers(){this.defaultInteractionHandlerDisposables.forEach((t=>t.dispose()));this.defaultInteractionHandlerDisposables=[]}clearDefaultKeyboardInteractions(){this.defaultTapKeyInteractions.forEach((t=>{const i=this.tapKeyInteractions.indexOf(t);if(i!==-1){this.tapKeyInteractions.splice(i,1)}}));this.tapKeyInteractions=[]}async initializeDefaultCameraInteractionHandlers(){var t,i;this.clearDefaultCameraInteractionHandlers();if(this.cameraControls){if(window.PointerEvent!=null){this.baseInteractionHandler=(t=this.baseInteractionHandler)!==null&&t!==void 0?t:new Mt((()=>this.getResolvedConfig()));const i=await this.registerInteractionHandler(this.baseInteractionHandler);const s=await this.registerInteractionHandler(new St);this.defaultInteractionHandlerDisposables=[i,s]}else{this.baseInteractionHandler=(i=this.baseInteractionHandler)!==null&&i!==void 0?i:new Dt((()=>this.getResolvedConfig()));const t=await this.registerInteractionHandler(this.baseInteractionHandler);const s=await this.registerInteractionHandler(new Et);this.defaultInteractionHandlerDisposables=[t,s]}}}initializeDefaultKeyboardInteractionHandlers(){var t;this.clearDefaultKeyboardInteractions();if(this.keyboardControls&&this.stream!=null){(t=this.baseInteractionHandler)===null||t===void 0?void 0:t.setDefaultKeyboardControls(this.keyboardControls);const i=new at(this.stream,(()=>this.getResolvedConfig()),(()=>this.getImageScale()));const s=new ft(this.stream,(()=>this.getResolvedConfig()),(()=>this.getImageScale()),(()=>this.createScene()));this.registerTapKeyInteraction(i);this.registerTapKeyInteraction(s);this.defaultTapKeyInteractions=[i,s]}}async initializeDefaultTapInteractionHandler(){if(this.tapHandlerDisposable==null){if(window.PointerEvent!=null){const t=new xt("pointerdown","pointerup","pointermove",(()=>this.getResolvedConfig()));this.tapHandlerDisposable=await this.registerInteractionHandler(t)}else{const t=new xt("mousedown","mouseup","mousemove",(()=>this.getResolvedConfig()));this.tapHandlerDisposable=await this.registerInteractionHandler(t)}}}initializeInteractionHandler(t){if(this.stateMap.interactionTarget==null){throw new z("Cannot initialize interaction handler. Interaction target is undefined.")}if(this.interactionApi==null){throw new z("Cannot initialize interaction handler. Interaction APi is undefined.")}t.initialize(this.stateMap.interactionTarget,this.interactionApi)}createInteractionApi(){if(this.stream==null){throw new B("Cannot create interaction API. Component has not been initialized.")}return this.frame==null||this.frame.scene.camera.isPerspective()?new ut(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 lt(this.stream,this.stateMap.cursorManager,(()=>this.getResolvedConfig().interactions),(()=>this.createScene()),(()=>this.frame),(()=>this.viewport),this.tap,this.doubletap,this.longpress,this.interactionStarted,this.interactionFinished)}handleCursorChanged(){window.requestAnimationFrame((()=>{this.cursor=this.stateMap.cursorManager.getActiveCursor()}))}async createScene(){const t=await this.waitForConnectedState();const{frame:i,sceneId:s,sceneViewId:n,worldOrientation:e}=t;return new st(this.getStream(),i,V(e),(()=>this.getImageScale()),this.viewport,s,n)}getBackgroundColor(){if(this.containerElement!=null){return si(this.containerElement)}}getBounds(){return ni(this.hostElement)}getCanvasDimensions(){return this.getResolvedConfig().flags.letterboxFrames?this.dimensions:this.hostDimensions}getImageScale(){const t=this.getCanvasDimensions();if(this.dimensions!=null&&t!=null){return o.create(this.dimensions.width/t.width,this.dimensions.height/t.height)}}getStreamAttributes(){return{depthBuffers:this.getDepthBufferStreamAttributesValue(),phantom:this.phantom,noDefaultLights:this.noDefaultLights,featureLines:this.featureLines,featureHighlighting:this.featureHighlighting,featureMaps:this.featureMaps,experimentalRenderingOptions:this.experimentalRenderingOptions,selectionHighlighting:this.selectionHighlighting}}updateCanvasDimensions(t){if(this.canvasElement!=null){this.canvasElement.width=t.width;this.canvasElement.height=t.height}}updateStreamAttributes(){var t;(t=this.stream)===null||t===void 0?void 0:t.update({streamAttributes:this.getStreamAttributes()})}updateInteractionApi(t){if(this.frame!=null){const i=(t==null||t.scene.camera.isPerspective())&&this.frame.scene.camera.isOrthographic();const s=(t==null||t.scene.camera.isOrthographic())&&this.frame.scene.camera.isPerspective();if(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;if(this.frame!=null){if(this.cameraType==="orthographic"&&this.frame.scene.camera.isPerspective()){(t=this.stream)===null||t===void 0?void 0:t.replaceCamera({camera:K(G(this.frame.scene.camera,this.frame.scene.boundingBox))})}else if(this.cameraType==="perspective"&&this.frame.scene.camera.isOrthographic()){(i=this.stream)===null||i===void 0?void 0:i.replaceCamera({camera:K(Z(this.frame.scene.camera))})}}}getDepthBufferStreamAttributesValue(){var t;const i=(t=this.depthBuffers)!==null&&t!==void 0?t:this.rotateAroundTapPoint?"final":undefined;return i}updateResolvedConfig(){this.resolvedConfig=S(this.configEnv,this.config)}getResolvedConfig(){return hi("Resolved config is undefined",(()=>this.resolvedConfig))}getStream(){return hi("Stream is undefined",(()=>this.stream))}getDeviceId(){if(this.deviceId==null){try{this.deviceId=Jt(Ut.DEVICE_ID,(t=>t["device-id"]))}catch(t){console.warn("Cannot read device ID. Local storage is not supported.")}if(this.deviceId==null){this.deviceId=D.create();try{_t(Ut.DEVICE_ID,{["device-id"]:this.deviceId})}catch(t){console.warn("Cannot write device ID. Local storage is not supported.")}}}return this.deviceId}async waitForConnectedState(){if(this.stateMap.streamState.type!=="connected"){console.debug("Stream was not in a connected state. Waiting for successful connection.");return new Promise(((t,i)=>{const s=this.getStream().onStateChanged((i=>{if(i.type==="connected"){t(i)}}));setTimeout((()=>{s.dispose();i(new Error("Timed out waiting for connected state."))}),ii)}))}return this.stateMap.streamState}get hostElement(){return e(this)}static get watchers(){return{src:["handleSrcChanged"],cameraControls:["handleCameraControlsChanged"],keyboardControls:["handleKeyboardControlsChanged"],rotateAroundTapPoint:["handleRotateAboutTapPointChanged"],cameraType:["handleCameraTypeChanged"],depthBuffers:["handleDepthBuffersChanged"],phantom:["handlePhantomChanged"],noDefaultLights:["handleNoDefaultLightsChanged"],experimentalRenderingOptions:["handleExperimentalRenderingOptionsChanged"],featureLines:["handleFeatureLinesChanged"],selectionHighlighting:["handleSelectionHighlightingChanged"],featureHighlighting:["handleFeatureHighlightingChanged"],featureMaps:["handleFeatureMapsChanged"],config:["handleConfigChanged"],configEnv:["handleConfigEnvChanged"]}}};function hi(t,i){const s=i();if(s!=null){return s}else throw new Error(t)}oi.style=ei;export{oi as vertex_viewer};
5
+ //# sourceMappingURL=p-5145f091.entry.js.map