/*!
 * Copyright (c) 2026 Vertex Software LLC. All rights reserved.
 */
import{r as t,h as i,H as e}from"./p-EpnuuCxl.js";import{s}from"./p-BU0JYf18.js";import{p as n}from"./p-CPH3J0oQ.js";import{a as o,M as r}from"./p-Bk0LMLjF.js";import"./p-Cnqnt1lk.js";import"./p-CdO6LFuW.js";import"./p-BNuMPeJ8.js";import"./p-C5iGCYv2.js";import{M as a}from"./p-BpnIh2g8.js";import{M as h}from"./p-CpdzPMuC.js";import{p as l}from"./p-DfdVaPrt.js";import{a as d}from"./p-C-9RlwtF.js";import{g as p}from"./p-p0obU98x.js";import{E as u}from"./p-CFus3r7d.js";import{E as m}from"./p-BAhfr1Nx.js";import"./p-ux1ckSDN.js";import"./p-CG9AChtV.js";import"./p-BuOEMGyM.js";import"./p-CPk-nchx.js";import"./p-CjG1fMh1.js";class c{get elementRect(){return this.rectObserver.rect}constructor(t,i){this.rectObserver=new u;this.handlePointerMove=async t=>{if(await this.isMeasurableEntityUnderPointer(t)){this.clearCursor();this.addCursor(d)}else{this.clearCursor()}};this.handlePointerDown=t=>{this.ifNoInteraction(t,(async()=>{if(await this.isMeasurableEntityUnderPointer(t)){this.measureEntityUnderPointer(t)}else{await this.controller.clearEntities()}}))};this.controller=t;this.measurableEntityTypes=i}initialize(t,i){this.element=t;this.api=i;this.rectObserver.observe(t);t.addEventListener("pointermove",this.handlePointerMove);t.addEventListener("pointerdown",this.handlePointerDown)}dispose(){var t,i,e;this.rectObserver.disconnect();(t=this.measurementInteraction)===null||t===void 0?void 0:t.dispose();this.clearCursor();(i=this.element)===null||i===void 0?void 0:i.removeEventListener("pointermove",this.handlePointerMove);(e=this.element)===null||e===void 0?void 0:e.removeEventListener("pointerdown",this.handlePointerDown);this.element=undefined;this.api=undefined}addCursor(t){this.cursor=this.ifInitialized((({api:i})=>i.addCursor(t)))}clearCursor(){var t;(t=this.cursor)===null||t===void 0?void 0:t.dispose();this.cursor=undefined}async isMeasurableEntityUnderPointer(t){var i;const e=p(t,this.elementRect);const s=await((i=this.api)===null||i===void 0?void 0:i.getEntityTypeAtPoint(e));return s!=null&&this.measurableEntityTypes.includes(s)}measureEntityUnderPointer(t){this.ifInitialized((async({api:i})=>{const e=p(t,this.elementRect);const[s]=await i.hitItems(e);const n=s!=null?o.fromHit(s):undefined;if(n!=null){await this.controller.addEntity(n)}else{await this.controller.clearEntities()}}))}ifInitialized(t){if(this.element!=null&&this.api!=null){return t({element:this.element,api:this.api})}else{throw new Error("Measurement interaction handler not initialized.")}}ifNoInteraction(t,i){const e=l.create(t.clientX,t.clientY);let s=false;const n=t=>{const i=l.create(t.clientX,t.clientY);const n=l.distance(e,i);s=n>2};const o=()=>{window.removeEventListener("pointermove",n);window.removeEventListener("pointerup",o);if(!s){i()}};window.addEventListener("pointermove",n);window.addEventListener("pointerup",o)}}const v=()=>`:host{display:block;position:absolute;top:0;bottom:0;left:0;right:0;pointer-events:none}`;const w=class{constructor(i){t(this,i);this.measurementModel=new a;this.measurementOverlays=new h;this.measurableEntityTypes=[m.PRECISE_SURFACE,m.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 i(e,{key:"2113569601821e742598eae47086b8bbd9198257"},i("vertex-viewer-measurement-overlays",{key:"d5ad40dd490ee2f6e1bddf5190c08907d706e0b9",viewer:this.viewer,measurementOverlays:this.measurementOverlays}))}setupController(){var t;const i=n(this.configEnv,this.config);const e=new s.SceneViewAPIClient(i.network.sceneViewHost);this.measurementController=new r(this.measurementModel,e,(()=>{var t;return(t=this.viewer)===null||t===void 0?void 0:t.token}),(t=this.viewer)===null||t===void 0?void 0:t.deviceId)}clearInteractionHandler(){var t;(t=this.registeredInteractionHandler)===null||t===void 0?void 0:t.then((t=>t.dispose()));this.registeredInteractionHandler=undefined}setupInteractionHandler(){var t;this.clearInteractionHandler();if(this.measurementController!=null){this.registeredInteractionHandler=(t=this.viewer)===null||t===void 0?void 0:t.registerInteractionHandler(new c(this.measurementController,this.measurableEntityTypes))}}static get watchers(){return{measurableEntityTypes:[{handleMeasurableEntityTypesChanged:0}],measurementController:[{handleMeasurementControllerChanged:0}],measurementModel:[{handleMeasurementModelChanged:0}],viewer:[{handleViewerChanged:0}]}}};w.style=v();export{w as vertex_viewer_measurement_precise};
//# sourceMappingURL=p-2484c58a.entry.js.map