@roomle/web-sdk 2.108.0 → 2.109.0-alpha.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (27) hide show
  1. package/lib/ConfiguratorKernel.wasm +0 -0
  2. package/lib/RoomleCore.wasm +0 -0
  3. package/lib/RoomleToolsCore.wasm +0 -0
  4. package/lib/definitions/web-sdk/packages/typings/planner.d.ts +1 -0
  5. package/lib/main-BWNZ7qEz.js.map +1 -1
  6. package/lib/main-Dv1fpIpy.mjs.map +1 -1
  7. package/lib/{planner-ol3gjqFY.js → planner-CTkUBoTH.js} +2 -2
  8. package/lib/{planner-ol3gjqFY.js.map → planner-CTkUBoTH.js.map} +1 -1
  9. package/lib/{planner-RcUe_egC.mjs → planner-iORwmIyR.mjs} +3 -2
  10. package/lib/{planner-RcUe_egC.mjs.map → planner-iORwmIyR.mjs.map} +1 -1
  11. package/lib/planner.js +1 -1
  12. package/lib/planner.nomodule.js +1 -1
  13. package/lib/roomle-sdk.js +1 -1
  14. package/lib/roomle-sdk.nomodule.js +1 -1
  15. package/lib/static/roomle-core-hsc/ConfiguratorKernel.wasm +0 -0
  16. package/lib/static/roomle-core-hsc/RoomleCore.wasm +0 -0
  17. package/lib/static/roomle-core-hsc/RoomleServiceCore.wasm +0 -0
  18. package/lib/static/roomle-core-hsc/RoomleToolsCore.wasm +0 -0
  19. package/lib/static/roomle-core-hsc/embind/plannerCoreInterface.d.ts +1 -0
  20. package/lib/static/roomle-core-hsc/package.json +1 -1
  21. package/lib/static/roomle-core-hsc/plannerCoreInterface.d.ts +1 -0
  22. package/lib/static/roomle-core-hsc/src/embind/plannerCoreInterface.d.ts +1 -0
  23. package/lib/static/roomle-core-hsc/wasm_modern/ConfiguratorKernel.wasm +0 -0
  24. package/lib/static/roomle-core-hsc/wasm_modern/RoomleCore.wasm +0 -0
  25. package/lib/static/roomle-core-hsc/wasm_modern/RoomleServiceCore.wasm +0 -0
  26. package/lib/static/roomle-core-hsc/wasm_modern/RoomleToolsCore.wasm +0 -0
  27. package/package.json +1 -1
@@ -151,9 +151,9 @@ System.register(["./main-BWNZ7qEz.js","./camera-behaviour-B9RCuOz8.js","./config
151
151
  #include <tonemapping_fragment>
152
152
  #include <colorspace_fragment>
153
153
 
154
- }`};const Wn=async(r,e)=>{const t=[],n=[],a=[],i=[];return await Promise.all(r.map(async s=>{if(s.configurationRuntimeId&&e.kernelInstance?.isExternalPlanObject(s.configurationRuntimeId))i.push([Pe(s.configurationHash),s]),t.push(W(s));else if(s.configurationType?.value!==Y.EXTERNAL){const o=W(s);if(o.configurationHash?a.push(o.configurationHash):o.catalogItemId&&n.push(o.catalogItemId),o.parts){const c=o.configurationHash||o.catalogItemId;o.parts=await e.addUiDataAndPriceToPartList(o.parts,c)}if(o.configuration){const c=await e.getConfigurationData(o.runtimeId);o.configuration=c.configuration}o.data=null,t.push(o)}})),{objects:t,itemIds:n,configurationIds:a,externalConfigurationData:i}},Kn=async(r=[],e=[],t=[],n)=>{const a=t.map(([d,u])=>d),[i,s,o]=await Promise.allSettled([n.getItems(r),n.getConfigurations(e),n.getExternalObjects(a)]),c=[],h=new Map;if(i.status==="fulfilled")for(const d of i.value)h.set(d.id,d);if(o.status==="fulfilled"&&o.value?.length>0)for(const{data:d}of o.value)h.set(d.id,d);if(s.status==="fulfilled")for(const d of s.value)h.set(d.id,d),c.push(d.rootComponentId);else console.warn("Could not fetch configuration for data property. This happens when a configuration has not been saved yet");return{data:h,rootComponentIds:c}},he=async(r,e,t)=>{const{objects:n,itemIds:a,configurationIds:i,externalConfigurationData:s}=await Wn(r,e),{data:o,rootComponentIds:c}=await Kn(a,i,s,t),h=await t.getComponents(c),d=new Map;for(const u of h)d.set(u.id,u);for(const u of n){const g=u.catalogItemId||u.configurationHash,_=o.get(u.catalogItemId)||o.get(u.configurationHash)||null;if(_&&!_.label&&d.has(_.rootComponentId)){const m=d.get(_.rootComponentId);_.label=m.label}_&&!_.label&&(_.label=g),u.data=_}return n};class Nn extends S{constructor(){const e=new Le(1e3,1e3,8,8);e.rotateX(-Math.PI/2);const t=new H;new vt().load(l,a=>{a.wrapS=Ye,a.wrapT=Ye;const i=5;a.repeat.set(1e3/i,1e3/i),t.map=a,t.alphaTest=.3,t.transparent=!0}),super(e,t),this.name="2d paper background",this.position.set(0,-.1,0),this.layers.set(D.BACKGROUND),this.userData.ignoreElementHit=!0}}class Me extends ln{get cameraControl(){return this._cameraControl}}class vn extends Me{get cameraControl(){return this._cameraControl}resetCameraOnPlanCompletelyLoaded(e){this.cameraControl.zoomToFitBounds(Ie(e,this.cameraControl.domHelper.element.clientWidth,this.cameraControl.domHelper.element.clientHeight,1.1),!0)}externalApiResetCameraPosition(e){this.cameraControl.zoomToFitBounds(Ie(e,this.cameraControl.domHelper.element.clientWidth,this.cameraControl.domHelper.element.clientHeight,1.1),!0)}resetCameraOnSwitchTo2d(e){this.cameraControl.zoomToFitBounds(Ie(e,this.cameraControl.domHelper.element.clientWidth,this.cameraControl.domHelper.element.clientHeight,1.1),!0)}updateCameraOnDrawWalls(e){this.cameraControl.zoomToFitBounds(e,!1,!0)}updateCameraOnPlanElementInsertedOutsideCurrentCameraView(e){this.cameraControl.zoomToFitBounds(e,!1,!0)}updateCameraOnPlanElementInsertedInsideCurrentCameraView(e){}updateCameraOnPlanElementDraggedOutsidePlanBounds(e){this.cameraControl.zoomToFitBounds(e,!1,!0)}updateCameraOnPlanElementRemoved(e){}updateCameraOnBackToPlanner(e,t,n){this.cameraControl.zoomToFitBounds(e,!1,!0)}resetCameraOnEnableWallDrawing(e){this.cameraControl.zoomToFitBounds(e,!1,!0)}}class ye extends Me{get cameraControl(){return this._cameraControl}resetCameraOnPlanCompletelyLoaded(e){this.cameraControl.updateAndReset(e,!0)}externalApiResetCameraPosition(e){this.cameraControl.updateAndReset(e,!0)}resetCameraOnSwitchTo3d(e){this.cameraControl.updateAndReset(e,!1)}disablePanningOnShiftRelease(){this.cameraControl.disablePanning()}enablePanningOnShiftClick(){this.cameraControl.enablePanning()}updateCameraOnDrawWalls(e){this.cameraControl.zoomToFitBounds(e,!0)}updateCameraOnPlanElementInsertedOutsideCurrentCameraView(e){this.cameraControl.zoomToFitBounds(e,!1)}updateCameraOnPlanElementDraggedOutsidePlanBounds(e){this.cameraControl.adjustToBoundsWithoutChangingDistance(e)}updateCameraOnPlanElementInsertedInsideCurrentCameraView(e){this.cameraControl.adjustToBoundsWithoutChangingDistance(e)}updateCameraOnPlanElementRemoved(e){this.cameraControl.adjustToBoundsWithoutChangingDistance(e)}async updateCameraOnBackToPlanner(e,t,n){if(!n)return;this.cameraControl.setObjectRotation(0),Math.abs(0-n.targetX)<=.01&&Math.abs(0-n.targetY)<=.01&&Math.abs(0-n.targetZ)<=.01?await this.cameraControl.updateAndReset(e,!0):await this._cameraControl.setToState(t,n)}resetCameraOnEnableWallDrawing(e){this.cameraControl.updateAndReset(e,!0)}async externalApiMoveCamera(e){await this.cameraControl.moveCamera(e),this._onCameraChanged()}}class zn extends Me{get cameraControl(){return this._cameraControl}resetCameraOnPlanCompletelyLoaded(e){this.cameraControl.updateCamera()}externalApiResetCameraPosition(e){this.cameraControl.updateCamera()}updateCameraOnDrawWalls(e){this.cameraControl.updateCamera()}updateCameraOnPlanElementInsertedOutsideCurrentCameraView(e){this.cameraControl.updateCamera()}updateCameraOnPlanElementInsertedInsideCurrentCameraView(e){this.cameraControl.updateCamera()}updateCameraOnPlanElementDraggedOutsidePlanBounds(e){this.cameraControl.updateCamera()}updateCameraOnPlanElementRemoved(e){this.cameraControl.updateCamera()}updateCameraOnBackToPlanner(e,t,n){this.cameraControl.updateCamera()}resetCameraOnEnableWallDrawing(e){this.cameraControl.updateCamera()}resetCameraOnSwitchToFirstPerson(){this.cameraControl.updateCamera()}}class Vn{constructor(e,t,n){this._sceneEventHandler=e,this._roomleRenderer=t,this._planViewModel=n}_processViewModel(e,t){e instanceof A&&e.getKernelObject().getAttachedAttics?.().size()>0?e.getBoundingBox().children.forEach(a=>{a.isChildPlanObject||t.add(a)}):((e instanceof be||e instanceof q)&&e.getTopViewContainer()&&t.add(e.getTopViewContainer()),e.getObject()?.children&&e.getObject().children.forEach(a=>{a.isChildPlanObject||t.add(a)}))}_processSelectedPlanElementIds(e){(this._sceneEventHandler?.getSelectedIds()||[]).forEach(n=>{const a=this._planViewModel.getPlanObjectForId(n);a&&this._processViewModel(a,e)})}_highlightPlanElementsBase(e,t){let n=new Set;t&&this._processViewModel(t,n),e?.forEach(a=>{const i=this._planViewModel.getPlanObjectForId(a);i&&this._processViewModel(i,n)}),this._processSelectedPlanElementIds(n),this._roomleRenderer?.highlightObjects(Array.from(n))}highlightPlanElements(e){this._highlightPlanElementsBase(e)}highlightPlanElement(e){this._highlightPlanElementsBase(void 0,e)}clearHighlighting(){this._highlightPlanElementsBase()}}function Xn(r,e,t,n,a,i,s,o=!0,c=!1){if(!(e.cameraControl instanceof G)||e.cameraControl.isLocked()&&o)return;const h=[],{x:d,y:u}=r.getClientDimensions(),g=a.getWallPlanObjectViewModels(),_=e.cameraControl.getKernelZoomFactor(),m=e.cameraControl.getCamera();for(const O of g){const f=O.getWallDimension(_,d,u);f.isCurrentlyDrawn=n.isCurrentlyDrawing&&O.getPlanElement().getTo().extRef.jsObject===a.latestNodePlanObjectViewModel;const{isVectorWall:F}=O.getKernelObject();f.length<=0&&!F||(Zn(f,m,d,u),f.attic&&qn(f.attic,m,d,u),f.lengthFormatted=i.formatMMValueToUnitString(f.length),c&&Yn(f,s),h.push(wt(f)))}t.onUpdateWallDimensions(h)}function Zn(r,e,t,n){r.fromPosition2d=p(r.fromPosition3d,e,t,n),r.toPosition2d=p(r.toPosition3d,e,t,n),r.textPosition2d=p(r.textPosition3d,e,t,n),r.fromWithoutPadding=p(r.fromWithoutPadding,e,t,n),r.toWithoutPadding=p(r.toWithoutPadding,e,t,n)}function qn(r,e,t,n){r.textPosition2d=r.fromPosition3d?p(r.textPosition3d,e,t,n):void 0,r.fromPosition2d=r.fromPosition3d?p(r.fromPosition3d,e,t,n):void 0,r.toPosition2d=r.toPosition3d?p(r.toPosition3d,e,t,n):void 0,r.atticCenterPosition2d=r.atticCenterPosition3d?p(r.atticCenterPosition3d,e,t,n):void 0,r.wallCenterPosition2d=p(r.wallCenterPosition3d,e,t,n),r.labelCPosition2d=p(r.labelCPosition3d,e,t,n),r.labelHeightPosition2d=p(r.labelHeightPosition3d,e,t,n),r.shiftedWallCenter2d=p(r.shiftedWallCenter3d,e,t,n),r.heightAt2mPosition2d=p(r.heightAt2mPosition3d,e,t,n),r.attic2mCornerFrom2d=p(r.attic2mCornerFrom3d,e,t,n),r.attic2mCornerto2d=p(r.attic2mCornerto3d,e,t,n)}function Yn(r,e){console.log("Wall dimension",r);const t=new Oe(.1,32,16),n=new H({color:16711680}),a=new S(t,n);a.position.copy(r.fromPosition3d);const i=new S(t,n);i.position.copy(r.toPosition3d);const s=new S(t,new H({color:65280}));if(s.position.copy(r.textPosition3d),e.wallPoints.add(a),e.wallPoints.add(i),e.wallPoints.add(s),r.attic){const o=new S(t,new H({color:255}));r.attic.fromPosition3d&&o.position.copy(r.attic.fromPosition3d);const c=new S(t,new H({color:16711935}));r.attic.toPosition3d&&c.position.copy(r.attic.toPosition3d);const h=new S(t,new H({color:16776960}));r.attic.atticCenterPosition3d&&h.position.copy(r.attic.atticCenterPosition3d),e.wallPoints.add(o),e.wallPoints.add(c),e.wallPoints.add(h)}}const st=class st{static hasNativeClipboardWriteSupport(){return!!(navigator.clipboard&&typeof navigator.clipboard.writeText=="function")}static async hasNativeClipboardReadSupport(){return navigator.clipboard&&typeof navigator.clipboard.readText=="function"?(await navigator.permissions.query({name:"clipboard-read"})).state!=="denied":!1}static async copy(e){if(this.hasNativeClipboardWriteSupport())try{await navigator.clipboard.writeText(e)}catch(t){console.warn("Native clipboard writeText failed, attempting localStorage fallback.",t)}try{localStorage.setItem(this.LOCAL_STORAGE_KEY,e)}catch(t){console.error("Failed to copy text using localStorage:",t)}}static async paste(){if(await this.hasNativeClipboardReadSupport())try{return await navigator.clipboard.readText()}catch(e){console.warn("Native clipboard readText failed, attempting localStorage fallback.",e)}try{const e=localStorage.getItem(this.LOCAL_STORAGE_KEY);return e===null?"":e}catch(e){throw console.error("Failed to paste text using native clipboard and localStorage fallback:",e),new Error("Failed to paste text. Both clipboard and localStorage methods failed.")}}};st.LOCAL_STORAGE_KEY="clipboardManagerFallback";let Ue=st;var $n=Object.defineProperty,De=(r,e,t,n)=>{for(var a=void 0,i=r.length-1,s;i>=0;i--)(s=r[i])&&(a=s(e,t,a)||a);return a&&$n(e,t,a),a};function We(r,e){const t=On(r),n=e?.lockPlan,a=r&&"getPlanElement"in r&&r.getPlanElement()&&"getAttachedWall"in r.getPlanElement();return!!(n&&(t==="wall"||t==="floor"||a))}const Jn="rml_plans",Ae={INTERIOR:"interior",EXTERIOR:"exterior"},wn=r=>["altKey","ctrlKey","shiftKey","metaKey"].reduce((e,t)=>(r[t]&&e++,e),0);class de extends mn{constructor(e,t,n,a){super(e,t,a),this._itemsLoadingStatePromises=[],this._staticItemGuard=new Re,this._completelyLoaded=!1,this._configurableItemGuard=new Re,this._planCompletelyLoadedGuard=new Re,this.currentSelection=null,this._paperBackground=null,this._cameraState=null,this._debugSpheres={wallPoints:new Ce,constructionElementsPoints:new Ce,floorPoints:new Ce},this._stopRendering=!0,this._configureInRoom=!!this._initData.configureInRoom,this._configuratorContext.baseContext=b.PLANNER,this._roomlePlannerCallback=n,this._plannerMeshGenerator.maxAnisotropy=this._renderer.capabilities.getMaxAnisotropy(),this._plannerMeshGenerator.maxTextures=this._renderer.capabilities.maxTextures,this._plannerSceneEventHandler=new Se(e,this._scene,this.cameraBehaviour.cameraControl.getCamera(),this._getInputManager()),this._roomleRenderer?.switchToPlanner(oe.Mode3D),this._imageRenderer.switchToPlannerSettings(),this._planElementHighlighter=new Vn(this._plannerSceneEventHandler,this._roomleRenderer,this._getViewModel()),this._plannerSceneEventHandler.addEventListener(y.STATE_CHANGED,({state:i,oldState:s})=>{s===te.ROTATE&&i!==s&&this._roomlePlannerUiCallback.onRotationCancel(),i===te.ROTATE||i===te.DRAG||i===te.MEASURE||i===te.DRAW?(this.cameraBehaviour.cameraControl.lock(),this._onCameraMove()):(this.cameraBehaviour.cameraControl.unlock(),this._onCameraIdle())},this),this._plannerSceneEventHandler.addEventListener(y.INTERACTION,()=>this._renderWithoutShadowsAndAO(),this),this._plannerSceneEventHandler.addEventListener(y.ACTIVATE_PLAN_ELEMENT,i=>this._activateElement(i),this),this._plannerSceneEventHandler.addEventListener(y.SELECT_PLAN_ELEMENT,i=>{this._activateElement(i);const s=i.planElementViewModel;this._sendElementMeasurements(),s instanceof N&&this._initData.debug&&console.log(s.getGLBUrl()),We(s,this._initData)||this._planElementHighlighter.highlightPlanElement(s),this._onSelectionChange(s),this._renderWithoutShadowsAndAO()},this),this._plannerSceneEventHandler.addEventListener(y.DESELECT_PLAN_ELEMENT,({planElementViewModel:i,reason:s})=>{this._planElementHighlighter.clearHighlighting(),this._onSelectionCancel(i,s),this._roomlePlannerUiCallback.onSelectionCancel(s),this._renderWithoutShadowsAndAO()},this),this._plannerSceneEventHandler.addEventListener(y.BEFORE_DRAG_START,()=>{this.cameraBehaviour.cameraControl.lock()},this),this._plannerSceneEventHandler.addEventListener(y.DRAG_START,({planElementViewModel:i})=>{this._getKernelAccess().planInteractionHandler.startInteraction(),this._sendElementMeasurements(),i instanceof A&&this._sendWallDimensions(),this._requestRender(),this._dragStartBounds=this.getBounds()},this),this._plannerSceneEventHandler.addEventListener(y.DRAG_MOVE,({planElementViewModel:i})=>{this.cameraBehaviour.cameraControl.checkNearFarDistance(i.getPosition()),this._requestRender()},this),this._plannerSceneEventHandler.addEventListener(y.DRAG_END,async({planElementViewModel:i})=>{const s=this._getKernelAccess().planInteractionHandler;s.endInteraction(),this.cameraBehaviour.cameraControl.unlock();const o=this._getDragPosition(i.getPosition());o&&s.moveElementTo(i.getPlanElement(),w(o)),this.updateEnvironment(this.getBounds(),!0),this._renderEverything();const c=this.getPlanObject(i.getId());let h;c&&(h=await he([c],this._plannerKernelAccess,this._rapiAccess)),this._roomlePlannerUiCallback.onPlanElementChanged($.MOVED,h.length?h[0]:{...c,data:null});const d=i instanceof A||i instanceof j||i instanceof X;!this._cameraBehaviourState.isWithinPlanBounds(i.getPosition(),this.getBounds())&&!d&&this.plannerCameraBehaviour.updateCameraOnPlanElementDraggedOutsidePlanBounds(this.getBounds())},this),this._plannerSceneEventHandler.addEventListener(y.DRAG_CANCEL,()=>{this.cameraBehaviour.cameraControl.unlock()},this),this._plannerSceneEventHandler.addEventListener(y.ADD_MEASUREMENT_LINE_START,()=>{this.cameraBehaviour.cameraControl.lock()},this),this._plannerSceneEventHandler.addEventListener(y.DRAG_MEASUREMENT_LINE,()=>{this._roomlePlannerUiCallback.onUpdateMeasurementLineDimensions([])},this),this._plannerSceneEventHandler.addEventListener(y.ADD_MEASUREMENT_LINE_END,()=>{this.cameraBehaviour.cameraControl.unlock(),this._roomlePlannerUiCallback.onMeasurementLineStateChange(!1)},this),this._plannerSceneEventHandler.addEventListener(y.DRAWING_START,()=>{this._setKernelZoomFactor(),this._renderWithoutShadowsAndAO(),this._roomleRenderer?.setGroundShadow(!1)},this),this._plannerSceneEventHandler.addEventListener(y.DRAW,()=>this._renderWithoutShadowsAndAO(),this),this._plannerSceneEventHandler.addEventListener(y.DRAWING_END,()=>{this._renderWithoutShadowsAndAO(),this._roomleRenderer?.setGroundShadow(!0)},this),this._getKernelAccess().addPlannerListener(this),this._plannerMeshGenerator.setMaterialLoadedListener(()=>{this._configurableItemGuard.resolve(),this._requestRender()}),window.onbeforeunload=this.clearScene.bind(this),this._getInputManager().addEventListener(v.ZOOM_IN,this._renderListener,this),this._getInputManager().addEventListener(v.ZOOM_OUT,this._renderListener,this),this._getInputManager().addEventListener(v.DOWN,this._onMouseDown,this),this.disableConfiguratorEvents(),a!==P.CAMERA_FP&&this.enablePlannerEvents(),setTimeout(()=>this._updatePaperBackground(),0),this._initData.debug&&(this._debugSpheres.wallPoints.name="Walls debug points",this._debugSpheres.constructionElementsPoints.name="Construction elements debug points",this._debugSpheres.floorPoints.name="Floor debug points",this._scene.add(this._debugSpheres.wallPoints),this._scene.add(this._debugSpheres.constructionElementsPoints),this._scene.add(this._debugSpheres.floorPoints))}get configuratorContext(){return this._configuratorContext}get hasSingleRoom(){const e=this._getViewModel().getFloorPlanObjectViewModels();return new Set(e.map(n=>n.getId())).size===1}get scenePlanElementLightSources(){const e=[];return this._scene.traverse(t=>{if("getAllLightSources"in t&&typeof t.getAllLightSources=="function"){const n=t.getAllLightSources();n.size>0&&e.push(n)}}),e}setAllLightsOnOff(e){for(const t of this.scenePlanElementLightSources)for(const n of Array.from(t.values()))n.setLightOnOff(e);this._renderEverything()}setLightsOnOffByIds(e,t){for(const n of this.scenePlanElementLightSources)for(const a of Array.from(n.values()))e.includes(a.lightSourceId)&&a.setLightOnOff(t);this._renderEverything()}_activateElement({planElementViewModel:e},t=()=>{}){const n=this._plannerSceneEventHandler.isDragIn()?e:null;this._sendElementMeasurements(n),e instanceof N&&this._initData.debug&&console.log(e.getGLBUrl()),We(e,this._initData)||this._planElementHighlighter.highlightPlanElement(e),t(),this._renderWithoutShadowsAndAO()}planCleared(){}planHistoryStateChanged(){if(this._sendRoomMeasurements(),this._completelyLoaded){const{configuratorId:e}=this._globalInitData,n=(this._plannerKernelAccess?.planInteractionHandler).getPlan()?.getPlanXML(!1,2),a=this._idbManager.getKey(Et(),e,this._initData.id);this._idbManager.setValue(a,n,this._idbManager.configStore)}}_getViewModel(){return this._viewModel||(this._viewModel=new pn(this._creator_),this._viewModel.setRequestRenderCallback(()=>this._renderEverything()),this._viewModel.setRequestRenderSceneUpdateCallback(()=>this._roomleRenderer?.clearCache()),this._viewModel.setInvalidateRenderCallback(()=>this._roomleRenderer?.forceShadowUpdates(!0))),this._viewModel}_getDragPosition(e){if(!this._plannerSceneEventHandler.isDragIn())return null;const t=this._dragStartBounds?this._dragStartBounds:this.getBounds(),n=t.getCenter(new E),a=e.distanceTo(n),i=t.getSize(new E),o=Math.max(i.x,i.z)+3;if(a>o){const c=new E().subVectors(e,n).normalize();return n.clone().add(c.multiplyScalar(o))}return null}_hideAllMeasurementsNodeOnElementChange(e){this._getViewModel().getMeasurementLineObjectViewModels().forEach(n=>n.hideDraggableNodes()),e instanceof j&&e.showDraggableNodes()}_onSelectionChange(e){this._hideAllMeasurementsNodeOnElementChange(e);const t={};if(e instanceof N&&(t.item=e.getRapiItem(),t.staticItemRuntimeId=e.getPlanElement().getId(),this._configuratorUiCallbacks.onUpdateParameters([])),e instanceof q&&(t.staticItemRuntimeId=e.getPlanElement().getId()),e instanceof k){const s=e.getId(),o=this.getRootPlanObjectId(s),c=this._getViewModel().getPlanObjectForId(o);t.configurationRuntimeId=c.getConfigurationRuntimeId()}if(e instanceof A){const s=this.cameraBehaviour.cameraControl.getKernelZoomFactor(),{clientWidth:o,clientHeight:c}=this._domHelper.element;t.wall=e.getWallDimension(s,o,c)}e instanceof j&&(t.measurementLine=e.getMeasurementLineDimension()),e instanceof _e&&(t.staticItemRuntimeId=e.getPlanElement().getId());let n=On(e);const i=(async()=>{const s={};if(e instanceof N&&(s.item=e.getRapiItem(),s.staticItemRuntimeId=e.getPlanElement().getId()),e instanceof k){await e.isInitDone();const o=e.getConfigurationRuntimeId();this._getKernelAccess().updatePlanObjectDependencies(o);const c=e.getPlanObject().getCatalogItemId();let h=c;h||(h=this._getKernelAccess().kernelInstance.getHashOfConfiguration(o));const d=this._getKernelAccess().kernelInstance.isExternalPlanObject(o);if(d){const g=this.getRootPlanObjectId(e.getId()),_=this._getViewModel().getPlanObjectForId(g);this._planObjectSelectionChanged(_.getConfigurationRuntimeId(),e.getRootComponentRuntimeId())}this._configuratorContext.planObjectId=o,this._configuratorContext.planElementId=e.getId(),this._configuratorContext.rootComponentId=e.getRootComponentRuntimeId();let u;if(!d)if(c&&ce(c)){const g=await this._rapiAccess.getItem(c);s.item=g,u=g.rootComponentId?g.rootComponentId:null}else try{const g=await this._rapiAccess.getConfiguration(h);s.configuration=g,u=g.rootComponentId?g.rootComponentId:null}catch{console.warn("Could not get RAPI configuration for kernel hash "+h+", saving configuration...");const _=await this._getKernelAccess().getConfigurationData(o),m=await this._rapiAccess.saveConfiguration(_);s.configuration=m,u=m.rootComponentId?m.rootComponentId:null}if(u){const g=await this._rapiAccess.getComponent(u);s.component=g}s.configurationRuntimeId=o,n="configuration"}return s.planElementId=e.getId(),le(s)})();if(this.currentSelection=le(t),this._sendElementMeasurements(),this._sendPlanObjectPositions(),e instanceof k){const s=e.getConfigurationRuntimeId();s&&s!==-1&&this._getKernelAccess().kernelInstance.isExternalPlanObject(s)&&(n="external-configuration",t.externalConfigurationType="tc-config")}this._roomlePlannerUiCallback.onSelectionChange(le(this._plannerSceneEventHandler.getSelectionMode()),le(n),le(t),i,e),(e instanceof A||e instanceof X)&&(this._getViewModel().getNodePlanObjectViewModels().forEach(s=>s.show()),this._updateNodeSize()),this._renderWithoutShadowsAndAO()}_onSelectionCancel(e,t){this._getViewModel().getNodePlanObjectViewModels().forEach(n=>n.hide()),this._renderWithoutShadowsAndAO(),this.resetConfiguratorContext(t),this.cancelComponentSelection(!1,t),this._handleMeasurementLineDraggablePoints(e),this.currentSelection=null}_handleMeasurementLineDraggablePoints(e){this._getViewModel().getMeasurementLineObjectViewModels().forEach(t=>{t.hideDraggableNodes(),t.deselectAllDraggablePoints()}),e instanceof j&&(e.deselectAllDraggablePoints(),e.currentPoint=null)}resetConfiguratorContext(e){try{this._configuratorContext.planObjectId&&this.getPlanObject(this._configuratorContext.planElementId).configurationType?.value===Y.EXTERNAL&&this.notifyPlannerOnComponentSelectionCancel(!0,e)}catch(t){console.error(t)}this._configuratorContext.planObjectId=0,this._configuratorContext.planElementId=0,this._configuratorContext.rootComponentId=0,this._configuratorContext.dockingRootComponentId=0}_setupScene(e,t){super._setupScene(e,t,!0),this._initData.legacyLight&&(this._lightSetting=new In(this._scene,this._lightSetting)),this._initData.moc||this._addSky(),t||this._setEnvironment(new cn(this._scene,this._environment,St(this._initData.colors.DEFAULT_BACKGROUND)))}onBeforeRender(){this.cameraBehaviour.cameraControl instanceof B&&He(this.cameraBehaviour.cameraControl.getCamera(),this._getViewModel().getWallPlanObjectViewModels())&&this._roomleRenderer?.forceShadowUpdates(!0)}_getInputManager(){return this._plannerInputManager}createCameraControl(e,t){this.setMode(e)}startViewing(){this._configuratorContext.baseContext=b.GLB_VIEWER;const e=this._plannerSceneEventHandler.getSelectedIds();if(e.length===1){const t=this._getViewModel().getPlanObjectForId(e[0]);this._setCameraPosition();const n=this.cameraBehaviour.cameraControl.getCurrentCameraParameters();this._changeCameraBehaviour(new bn(this._getCameraControl3D(n),this._cameraBehaviourState)),this.cameraBehaviour.cameraControl instanceof B&&this.cameraBehaviour.cameraControl.setObjectRotation(t.getPlanElement().rotation),this._configureInRoom||this._getViewModel().hideAllExcept(t.getId()),this.cameraBehaviour.updateCameraOnItemLoaded(this.getBounds()).then(()=>{this.updateEnvironment(this.getBounds(),!0)})}this.disablePlannerEvents(),this.updateScene()}startConfiguring(){this._configuratorContext.baseContext=b.CONFIGURATOR;let{planElementId:e}=this._configuratorContext;e=this.getRootPlanObjectId(e),this._configuratorContext.planElementId!==e&&this.selectPlanObject(e),this._selectExternalObjectModule();const t=this._getViewModel().getPlanObjectForId(e);this._setCameraPosition();const n=this.cameraBehaviour.cameraControl.getCurrentCameraParameters();this._changeCameraBehaviour(new nt(this._getCameraControl3D(n),this._cameraBehaviourState));let a=0,i=0;if(t){this.setRootComponentId(t.getRootComponentRuntimeId());const c=t.getPlanElement().getRotationToPreferredFront();a=c.rotationRoundTo90deg,i=c.lookAtSide.value===Mt.LEFT?-1:1,this._componentRaycastHelper?.setObject(t.getObject())}const s=t?.getConfigurationRuntimeId();this._configuratorContext.planObjectId!==s&&(this._configuratorContext.planObjectId=s),this._plannerSceneEventHandler.removeSelection(),this._planElementHighlighter.clearHighlighting(),this._configureInRoom||this._getViewModel().hideAllExcept(e),this.scenePlanElementLightSources.length>0&&this.toggleInteriorLightsSceneSettings(!1),this.configuratorCameraBehaviour.resetCameraOnStartConfiguring(this.getBounds(),n,a,i).then(()=>{this.updateEnvironment(this.getBounds(),!0)}),this.setEventHandlerObject(t.getContainer()),this.disablePlannerEvents(),this.enableConfiguratorEvents(),this._roomleRenderer?.switchToConfigurator(),this._imageRenderer.switchToConfiguratorSettings(),this.updateScene(),this._getKernelAccess().updatePlanObjectDependencies(s),this._getKernelAccess().requestPartListAndUpdatePricesOfParts(),this._getKernelAccess().planObjectUpdated(s,!1),this._plannerKernelAccess?.planInteractionHandler?.startInteraction()}_setCameraPosition(){this._cameraState=this.cameraBehaviour.cameraControl.getCurrentCameraParameters()}_resetCameraPosition(e){if(this.cameraBehaviour.cameraControl instanceof B){if(!this._cameraState)return;this.plannerCameraBehaviour.updateCameraOnBackToPlanner(this.getBounds(),e,this._cameraState)}}async selectPlanObject(e){if(this._plannerSceneEventHandler.getSelectedIds().includes(e))return;e=this.getRootPlanObjectId(e);const n=this._getViewModel().getPlanObjectForId(e);await this._plannerSceneEventHandler.selectPlanElement(n)}backToPlanner(){if(this._configuratorContext.baseContext===b.PLANNER)return;this._configuratorContext.baseContext===b.CONFIGURATOR&&(this._plannerKernelAccess?.planInteractionHandler?.endInteraction(),this._getKernelAccess().kernelInstance.getPlanObject(this.currentSelection?.configurationRuntimeId??0)?.externalObject&&this.notifyPlannerOnComponentSelectionCancel(!0,"isolation_mode_cancelled")),this._configuratorContext.baseContext=b.PLANNER;const e=this.cameraBehaviour.cameraControl.getCurrentCameraParameters(),t=this._getViewModel().cameraType;this._changeCameraBehaviour(t===P.CAMERA_3D||t===P.CAMERA_FP?new ye(this._getCameraControl3D(e),this._cameraBehaviourState):new vn(this._getCameraControl2D(),this._cameraBehaviourState)),this.scenePlanElementLightSources.length>0&&this.toggleInteriorLightsSceneSettings(!0),this._resetCameraPosition(e),this._getViewModel().showAll(),this.setEventHandlerObject(this._scene),this.enablePlannerEvents();const n=this.cameraBehaviour.cameraControl instanceof B||this.cameraBehaviour.cameraControl instanceof J;this._getViewModel().setCameraType(n?P.CAMERA_3D:P.CAMERA_2D),this.disableConfiguratorEvents(),this._roomleRenderer?.switchToPlanner(this.cameraBehaviour.cameraControl instanceof B?oe.Mode3D:oe.Mode2D),this._imageRenderer.switchToPlannerSettings(),this.updateScene()}_getYRotationOfObject(e){let t=e.getWorldDirection(new E).clone();t.y=0,t.lengthSq()<.01&&(t=new E(0,1,0),t.applyQuaternion(e.quaternion),t.y=0),t.normalize();let n=Math.asin(t.x);return t.z<0&&(n=Math.PI-n),n<0&&(n+=Math.PI*2),n}loadStaticPlanObjects(){const e=new Map;this._getViewModel().getStaticPlanObjectViewModels().forEach(t=>{const n=t.getPlanObject();e.has(n.getCatalogItemId())?e.get(n.getCatalogItemId()).push(t):e.set(n.getCatalogItemId(),[t])}),this._rapiAccess.getItems(Array.from(e.keys())).then(t=>{const n=[];t.forEach(a=>{this._getKernelAccess().catalogItemLoaded(a),e.get(a.id).forEach(i=>{n.push(new Promise((s,o)=>{i.setRapiItem(a).then(()=>{this._requestRender(),s()},o)}))})}),Promise.all(n).then(()=>this._staticItemsLoaded())})}requestCatalogItem(e){this._rapiAccess.getItem(e).then(t=>{this._getKernelAccess().catalogItemLoaded(t)})}_staticItemsLoaded(){this._requestRender(),this._staticItemGuard.resolve(),this._roomlePlannerUiCallback.onItemsLoaded()}preload(e){this._planId=e;const t=this._localStorageHelper.getItem(this._planId,Jn);t&&this._loadGLTF(t).then(n=>{this._preloadScene=n,this._preloadScene&&this._scene.add(this._preloadScene),this._requestRender()})}planXMLLoaded(e){this.endPlanConstruction(e),this.loadStaticPlanObjects()}_activateCeilingLight(){this._getViewModel().handleInitialLights(this._renderer.capabilities.maxTextures,this._roomleRenderer.sceneRenderer.getQualityLevel()),this._getViewModel().handleCeilingLights()}planCompletelyLoaded(e){this._stopRendering=!1,this._renderEverything(),setTimeout(()=>this._planCompletelyLoadedGuard.resolve(),0),this.scenePlanElementLightSources.length>0&&(this.toggleInteriorLightsSceneSettings(!0),this._activateCeilingLight()),this._getViewModel().getNodePlanObjectViewModels().forEach(t=>t.hide()),this._getViewModel().getMeasurementLineObjectViewModels().forEach(t=>t.hideDraggableNodes())}handlerSwitchedPlans(e,t){if(this._completelyLoaded=!1,this._roomlePlannerUiCallback.onHandlerSwitchedPlans(),this._getViewModel().setReference(t),this._getKernelAccess().coupleReferences(this._getViewModel(),t),this._getViewModel().setPlannerSceneEventHandler(this._plannerSceneEventHandler),this._getViewModel().setGeometriesMergedListener(()=>{this._renderEverything()}),this._plannerSceneEventHandler.setPlanViewModel(this._getViewModel()),e&&this.clearScene(),!this._initData.moc){this._addSky();const a=new Le(1e3,1e3);a.rotateX(-Math.PI/2);const i=yt.createMeshStandardMaterial({color:"#f0f0f0",roughness:1,metalness:0,depthWrite:!1}),s=new S(a,i);s.name="Ground",s.position.y=-.01,s.userData.isFloor=!0,this._scene.add(s)}this._setCeiling(),this._staticItemGuard.reset(),this._configurableItemGuard.reset(),this._planCompletelyLoadedGuard.reset();const n=this._plannerMeshGenerator.materialQueue.length>0?this._configurableItemGuard.wait():Promise.resolve();Promise.all([this._staticItemGuard.wait(),n,this._planCompletelyLoadedGuard.wait()]).then(this._itemsLoaded.bind(this))}async _itemsLoaded(){const e=this._getViewModel().getCorePlan();if(this._roomleRenderer){const t=Dt(e.getBounds());this._roomleRenderer.updateBounds(t),this._imageRenderer.updateBounds(t)}await Promise.allSettled(this._itemsLoadingStatePromises),this._roomlePlannerUiCallback.onCompletelyLoaded(),this.updateEnvironment(this.getBounds(),!0),this._renderEverything(),this._configuratorContext.baseContext===b.PLANNER&&this.plannerCameraBehaviour.resetCameraOnPlanCompletelyLoaded(this.getBounds()),this._completelyLoaded=!0,this._readyForRender()}beginPlanConstruction(e){}addPlanMesh(e,t,n,a,i,s,o){}endPlanConstruction(e){this._renderLoopFunction=()=>{this._scene.add(this._getViewModel().getConstructionGroup()),this._scene.add(this._getViewModel().getCeilingGroup()),this._scene.add(this._getViewModel().getFloorGroup()),this._scene.add(this._getViewModel().getMeasurementLineGroup()),this._scene.add(this._getViewModel().getWallAtticsGroup()),this._isInteriorLightActive&&this._createCeilingLightGroup(),this._lightSetting?.needsBounds()&&this._lightSetting.updateBounds(this._getViewModel().getBoundingBox()),this._scene.remove(this._preloadScene)}}async addPlanObjectToScene(e){if(!e)return Promise.resolve();let t,n;try{const a=new Promise((h,d)=>(t=h,n=d));this._itemsLoadingStatePromises.push(a);const i=e.getContainer();At(i),this._scene.add(i),this._plannerSceneEventHandler.isDragIn()&&(this._plannerSceneEventHandler.addComponentDragInHandler(e),this._requestRender()),this._roomlePlannerUiCallback.onPlanChanged(),await e.isInitDone(),this.updateEnvironment(this.getBounds()),this._renderEverything();const s=this.getPlanObject(e.getId());let o;s&&(o=await he([s],this._plannerKernelAccess,this._rapiAccess)),this._roomlePlannerUiCallback.onPlanElementChanged($.ADDED,o.length?o[0]:{...s,data:null});const c=e instanceof k||e instanceof N;this._initData.featureFlags.interiorLights&&(Un(e,this._getViewModel(),this._isInteriorLightActive),this.scenePlanElementLightSources.length>0&&this.toggleInteriorLightsSceneSettings(!0)),c&&!this._plannerSceneEventHandler.isDragIn()&&this.cameraBehaviour instanceof Me&&(Lt(this.cameraBehaviour.cameraControl.getCamera(),e.getBounds())?this.plannerCameraBehaviour.updateCameraOnPlanElementInsertedInsideCurrentCameraView(this.getBounds()):this.plannerCameraBehaviour.updateCameraOnPlanElementInsertedOutsideCurrentCameraView(this.getBounds()))}catch(a){console.error(a),n()}t()}removePlanObjectFromScene(e){(e instanceof A||e instanceof X)&&this._sendWallDimensions(),e instanceof j&&this._sendMeasurementLineDimension(),this._scene.remove(e.getContainer()),e.clear(),this.updateEnvironment(this.getBounds(),!0),!(e instanceof A||e instanceof j||e instanceof X)&&this._configuratorContext.baseContext===b.PLANNER&&this.plannerCameraBehaviour.updateCameraOnPlanElementRemoved(this.getBounds()),this._renderEverything()}planElementChanged(e,t){this._drawingEnabled&&this._sendWallDimensions(!1);const n=this._plannerSceneEventHandler.isDragIn()?t:null;if(this._sendElementMeasurements(n),this._sendRoomAreaData(),this.updateEnvironment(this.getBounds(),!0),this._renderEverything(),this._onPlanChanged(),!this._plannerSceneEventHandler.isDragIn()){const a=this.getPlanObject(t.getId());this._roomlePlannerUiCallback.onPlanElementChanged($.MOVED,{...a,data:null})}t instanceof A&&e.extRef&&e.extRef.jsObject&&this._isInteriorLightActive&&e.extRef.jsObject.handleCeilingLights()}exportGLB(e,t){}importGLB(e){this._loadGLB(e).then(t=>this._scene.add(t))}clearScene(){this._plannerMeshGenerator.clear(),this._getViewModel().sceneCleared(),super.clearScene()}_addSky(){const e={distance:4e5,turbidity:10,rayleigh:2,mieCoefficient:.005,mieDirectionalG:.8,inclination:.6,azimuth:0};if(!this._sky){this._sky=new Ge,this._sky.name="Sky",this._sky.scale.setScalar(45e4),this._sky.frustumCulled=!1,this._scene.add(this._sky),this._sky.material.uniforms.turbidity.value=e.turbidity,this._sky.material.uniforms.rayleigh.value=e.rayleigh,this._sky.material.uniforms.mieCoefficient.value=e.mieCoefficient,this._sky.material.uniforms.mieDirectionalG.value=e.mieDirectionalG;const t=Rt(e.distance,e.azimuth,e.inclination);this._sky.material.uniforms.sunPosition.value.copy(t);const n=new S(new Oe(2e4,16,8),new H({color:16777215}));n.name="Sunsphere",n.position.y=-7e5,n.visible=!1,n.position.set(t.x,-t.z,t.y)}this._lightSetting instanceof In&&this._lightSetting.updateSunPosition(e.inclination,e.azimuth)}toggleConfigureInRoom(){this._configureInRoom=!this._configureInRoom,this._roomleRenderer.isConfiguring&&(this._configureInRoom?this._getViewModel().showAll():this._hideAllExceptSelectedElement(),this._renderEverything(),this.updateScene())}switchTo2D(){if(!(this.cameraBehaviour?.cameraControl instanceof G)){this.cameraBehaviour?.cameraControl instanceof J&&this._getCameraControlFirstPerson().cleanUp(),this._roomleRenderer?.setCameraType(P.CAMERA_2D),this._plannerSceneEventHandler?.enable();for(const e of this._getViewModel().getWallPlanObjectViewModels())e.show();this._getViewModel().setCameraType(P.CAMERA_2D).then(()=>this._planElementHighlighter.highlightPlanElement()),this._roomleRenderer?.switchToPlanner(oe.Mode2D),this._renderEverything(),this._changeCameraBehaviour(new vn(this._getCameraControl2D(),this._cameraBehaviourState)),this._onCameraMove(),this.plannerCameraBehaviour.resetCameraOnSwitchTo2d(this.getBounds()),this._addCameraControlListener(),this._setCeiling(),this._roomlePlannerUiCallback.onCameraChanged(P.CAMERA_2D),this._setKernelZoomFactor(),this._onCameraMove(),this._sendRoomMeasurements()}}switchTo3D(){this.cameraBehaviour?.cameraControl instanceof B||(this._roomleRenderer?.setCameraType(P.CAMERA_3D),this._plannerSceneEventHandler?.enable(),this._getViewModel().setCameraType(P.CAMERA_3D),this._roomleRenderer?.switchToPlanner(oe.Mode3D),this._renderEverything(),this._changeCameraBehaviour(new ye(this._getCameraControl3D(),this._cameraBehaviourState)),this._onCameraMove(),this.plannerCameraBehaviour.resetCameraOnSwitchTo3d(this.getBounds()),this._addCameraControlListener(),this._setCeiling(),this._roomlePlannerUiCallback.onCameraChanged(P.CAMERA_3D))}switchToFirstPerson(){this.cameraBehaviour?.cameraControl instanceof J||(this._roomleRenderer?.setCameraType(P.CAMERA_FP),this._plannerSceneEventHandler?.disable(),this._plannerMeshGenerator.wallMeshes.forEach(e=>Ht(e.material,!1,!1)),this._getViewModel().getWallPlanObjectViewModels().forEach(e=>{e.show()}),this._getViewModel().setCameraType(P.CAMERA_FP),this._renderEverything(),this._changeCameraBehaviour(new zn(this._getCameraControlFirstPerson(),this._cameraBehaviourState)),this._addCameraControlListener(),this._setCeiling(),this._roomlePlannerUiCallback.onCameraChanged(P.CAMERA_FP),this.plannerCameraBehaviour.resetCameraOnSwitchToFirstPerson())}onCameraChanged(){}_setCameraControlListeners(){super._setCameraControlListeners(),this.cameraBehaviour instanceof Me&&(this.cameraBehaviour.cameraControl.addEventListener(Q.IDLE,()=>{this._onCameraIdle()},this),this.cameraBehaviour.cameraControl.addEventListener(Q.ORBIT_MOVE,()=>{this._onCameraMove()},this),this.cameraBehaviour.cameraControl.addEventListener(Q.MOVING,()=>{this._onCameraMove()},this),this.cameraBehaviour.cameraControl.addEventListener(Q.ZOOM_IN,()=>{this._onCameraMove()},this),this.cameraBehaviour.cameraControl.addEventListener(Q.ZOOM_OUT,()=>{this._onCameraMove()},this),this.cameraBehaviour.cameraControl.addEventListener(Q.ZOOM_CHANGE,()=>{this._onCameraZoomChange()},this))}_onCameraZoomChange(){this._setKernelZoomFactor()}_setKernelZoomFactor(){const e=this.cameraBehaviour.cameraControl.getKernelZoomFactor();e&&isFinite(e)&&e>=0&&this._getKernelAccess().planInteractionHandler?.setZoomFactor(e),this._plannerSceneEventHandler?.setKernelZoomFactor(e)}_setCeiling(){this._getViewModel()&&(this.cameraBehaviour.cameraControl instanceof J?this._getViewModel().getCeilingGroup().visible=!0:this._getViewModel().getCeilingGroup().visible=!1)}cameraBehaviourChanged(){super.cameraBehaviourChanged(),this._plannerSceneEventHandler?.setCamera(this.cameraBehaviour.cameraControl.getCamera()),this._updatePaperBackground()}_updatePaperBackground(){this.cameraBehaviour.cameraControl instanceof G?(this._paperBackground||(this._paperBackground=new Nn),this._scene?.add(this._paperBackground),this._requestRender()):this._paperBackground&&this._scene?.remove(this._paperBackground)}sceneChanged(){this._plannerSceneEventHandler&&this._plannerSceneEventHandler.setObject(this._scene)}_onKeyDown(e){if(super._onKeyDown(e),this._initData.debug&&this._checkNumKey(e),this._checkCopyPaste(e),this._checkUndoRedo(e),ve(e)){const t=wn(e),n=e.metaKey&&e.key==="Meta"||e.ctrlKey&&e.key==="Control",a=t>1?M.STANDARD:n?M.MULTISELECT:M.STANDARD;this._plannerSceneEventHandler.setSelectionMode(a)}this._checkPanning(e),this._plannerSceneEventHandler&&this._plannerSceneEventHandler.hasSelection()&&e.key&&(e.key==="Backspace"||e.key==="Delete")&&(this.deletePlanElementSelection(),e.preventDefault())}async _checkCopyPaste(e){if(ve(e)&&e.key==="c"){const t=this._plannerSceneEventHandler.getSelectedIds(),n=[];t.forEach(a=>{const s=this._getViewModel().getPlanObjectForId(a).getPlanElement(),o=s.getCatalogItemId()||s.getConfigurationHash();n.push(o)}),Ue.copy(n.join())}if(ve(e)&&e.key==="v"){const t=await Ue.paste();if(t){const a=t.split(",").map(i=>jt(i)||i).filter(i=>i.includes(":"));this._insertRapiItems(a)}}}_checkPanning(e){(e.shiftKey===!0||e.key&&e.key.includes("Shift"))&&this.cameraBehaviour.cameraControl instanceof B&&(this.cameraBehaviour.cameraControl.enablePanning(),e.preventDefault())}_onMouseDown(e){"event"in e&&this._checkPanning(e.event)}_checkNumKey(e){e.key&&e.key==="1"&&(this.switchTo2D(),e.preventDefault()),e.key&&e.key==="2"&&(this.switchTo3D(),e.preventDefault()),e.key&&e.key==="3"&&(this.switchToFirstPerson(),e.preventDefault())}_onKeyUp(e,t=!1){if(super._onKeyUp(e,t),ve(e,!0)){const n=wn(e);let a=M.STANDARD;!xt(e)&&n===1&&(a=M.MULTISELECT),this._plannerSceneEventHandler.setSelectionMode(a),e.preventDefault()}e.key&&e.key.includes("Shift")&&this.cameraBehaviour.cameraControl instanceof B&&(this.cameraBehaviour.cameraControl.disablePanning(),e.preventDefault()),e.key&&(e.key==="Escape"||e.key==="Esc")&&(this._drawingEnabled&&(this.escapeDrawing(!0),this._roomlePlannerUiCallback.onDrawCancel()),this.cancelDragIn())}async undo(){const e=this._getKernelAccess().planInteractionHandler;return e.cancelDrawing(),e.undo(),this.cancelPlanElementSelection("undo"),Promise.resolve()}async redo(){return this._getKernelAccess().planInteractionHandler.redo(),this.cancelPlanElementSelection("redo"),Promise.resolve()}setMode(e){switch(e){case P.CAMERA_2D:this.switchTo2D();break;case P.CAMERA_3D:this.switchTo3D();break;case P.CAMERA_FP:this.switchToFirstPerson();break}}_clearHighlighting(){this._planElementHighlighter.clearHighlighting(),this._renderWithoutShadowsAndAO()}highlightPlanElementsById(e){if(e===null){this._clearHighlighting();return}this._planElementHighlighter.highlightPlanElements(e)}highlightPlanElementById(e){if(e===null){this._clearHighlighting();return}e=this.getRootPlanObjectId(e);const t=this._getViewModel().getPlanObjectForId(e);this._planElementHighlighter.highlightPlanElement(t)}destroy(){super.destroy(),this._plannerMeshGenerator.removeMaterialLoadedListener(),this._getViewModel().removeGeometriesMergedListener()}planObjectConfigurationLoaded(e,t,n){if(n||console.error("Plan object configuration loading failed",t.getCatalogItemId()||t.getConfigurationHash()),e&&e.extRef&&t&&t.extRef){const i=t.extRef.jsObject.getPlanObject().getConfigurationRuntimeId();i>0&&this._getViewModel().constructComponents(i)}}async planObjectConfigurationChanged(e,t){const n=this.getPlanObject(t.getId());let a;n&&!(t instanceof k)&&!(t instanceof q)&&(a=await he([n],this._plannerKernelAccess,this._rapiAccess)),this._roomlePlannerUiCallback.onPlanElementChanged($.CHANGED,a?.length?a[0]:{...n,data:null})}addMesh(e,t,n,a,i,s){}updateCameraOnDrawWalls(){this.plannerCameraBehaviour.updateCameraOnDrawWalls(this.getBounds())}getBounds(){return this._getViewModel()?this._getViewModel().getBoundingBox():null}getGeometryBounds(){return this._configuratorContext.baseContext===b.CONFIGURATOR?super.getGeometryBounds():this.getBounds()}getPlanObject(e){const t=this._getKernelAccess().planInteractionHandler,n=this._plannerKernelAccess.planModelViewHelper,a=t.getPlan();return n.getPlanObject(a,e)}getRootPlanObjectId(e){if(!this._plannerKernelAccess?.kernelContainer)return e;const t=this._getKernelAccess().planInteractionHandler,n=this._plannerKernelAccess.planModelViewHelper,a=t.getPlan();return n.getRootPlanObjectId(a,e)}cancelPlanElementSelection(e){this._plannerSceneEventHandler.cancelSelection(e),this._planElementHighlighter.clearHighlighting(),this._requestRender()}async deletePlanElements(e){this.cancelPlanElementSelection("delete_object");const t=this._getKernelAccess().planInteractionHandler;t.startInteraction(),await this.deletePlanElementByIds(e),t.endInteraction()}async deletePlanElementSelection(){const e=this._plannerSceneEventHandler.getSelectedIds();await this.deletePlanElements(e)}async deletePlanElementByIds(e){for(const t of e){const n=this._getViewModel().getPlanObjectForId(t);if(n&&n.getObject()){const a=this.getPlanObject(n.getId());let i;a&&(i=await he([a],this._plannerKernelAccess,this._rapiAccess)),this._roomlePlannerUiCallback.onPlanElementChanged($.REMOVED,i.length?i[0]:{...a,data:null}),this._getKernelAccess().planInteractionHandler.removeElement(n.getKernelObject())}}}rotatePlanElements(e,t){const n=new(this._getKernelAccess()).kernelContainer.PlanObjectPtrList,a=new re;let i={x:0,y:0,z:0};if(e.forEach(s=>{const o=this._getViewModel().getPlanObjectForId(s);o&&o.getObject()&&(i=o.getPlanElement().getCenter(),n.push_back(o.getPlanElement()),a.expandByObject(o.getContainer()))}),n.size()>1){const s=a.getCenter(new E);i=w(s)}this._getKernelAccess().planInteractionHandler.rotateObjectsBy(n,t,i)}rotatePlanElementSelection(e){const t=this._plannerSceneEventHandler.getSelectedIds();this.rotatePlanElements(t,e)}planBoundsChanged(){this.updateEnvironment(this.getBounds()),this._requestRender()}planElementRemoved(e){this._configuratorContext.planElementId===e.getId()&&(this._roomlePlannerUiCallback.onSelectionCancel("delete_object"),this._configuratorContext.planElementId=0),this._onPlanChanged(),this._renderEverything(),this.scenePlanElementLightSources.length===0&&this.toggleInteriorLightsSceneSettings(!1)}_onPlanChanged(){this._roomlePlannerUiCallback.onPlanChanged()}prepareTopImage(e={},t){return this._configuratorContext.baseContext===b.CONFIGURATOR&&t?super.preparePerspectiveImage(e):new Promise(n=>{this._getViewModel().materialQueue.finished(!0).then(async()=>{const a=e.runtimeIds?we.getCameraTargetForBBox(this._getViewModel().getBoundingBoxFromRuntimeIds(e.runtimeIds),.1):this._calculateBoundingBoxOfAllMeshes(.1);this._lightSetting?.removeFromScene();const i=[];if(this.cameraBehaviour.cameraControl instanceof B){await this._getViewModel().setCameraType(P.CAMERA_2D),this._getViewModel().setNodeVisibility(!1);for(const o of this._getViewModel().getWallPlanObjectViewModels())o.isVisible()||i.push(o),o.show()}e.runtimeIds&&this._getViewModel().hideAllExceptRuntimeIds(e.runtimeIds);const s=await this._imageRenderer.prepareTopImage(this._scene,null,a,e);if(e.runtimeIds&&this._getViewModel().showAll(),this.cameraBehaviour.cameraControl instanceof B&&await this._getViewModel().setCameraType(P.CAMERA_3D),i.length)for(const o of i)o.hide();this._lightSetting?.addToScene(),this._roomleRenderer?.clearCache(),this._requestRender(),n(s)})})}preparePerspectiveImageOf(e,t={}){const n=this._getViewModel().getPlanObjectForId(e);if(!n){const a="Object with runtimeId "+e+" not found";throw console.warn(a),new Error(a)}return this._preparePerspectiveImage({...t,object:n.getObject().clone()})}async _waitForAssets(){await super._waitForAssets(),await this._getViewModel().materialQueue.finished(!0)}_preparePerspectiveImage(e={},t){if(this._configuratorContext.baseContext===b.CONFIGURATOR&&t)return super.preparePerspectiveImage(e);const n=this._handlePlannerIsolationModeState(t);return new Promise((a,i)=>{this._getViewModel().materialQueue.finished(!0).then(async()=>{let s;this.cameraBehaviour.cameraControl instanceof B?s=this.cameraBehaviour.cameraControl.getCamera().clone():(s=this.getPerspectiveOffsetCamera().clone(),this._getViewModel().getCeilingGroup().visible=!1,s.layers.enableAll(),this._getViewModel().setCameraType(P.CAMERA_3D)),s.resetOffset();const o=e.object?we.getCameraTargetForBBox(new re().setFromObject(e.object)):e.runtimeIds?we.getCameraTargetForBBox(this._getViewModel().getBoundingBoxFromRuntimeIds(e.runtimeIds)):this._calculateBoundingBoxOfAllMeshes();this._lightSetting?.removeFromScene();const c=e.object?Tt(this._scene):this._scene;e.object&&c.add(e.object),e.runtimeIds&&this._getViewModel().hideAllExceptRuntimeIds(e.runtimeIds);const h=await this._imageRenderer.preparePerspectiveImage(c,null,s,o,e,void 0,d=>{He(d,this._getViewModel().getWallPlanObjectViewModels())});$e(s),e.runtimeIds&&this._getViewModel().showAll(),e.object&&$e(c),this.cameraBehaviour.cameraControl instanceof G?(this._getViewModel().setCameraType(P.CAMERA_2D),this._getViewModel().getWallPlanObjectViewModels().forEach(d=>d.show())):He(this.cameraBehaviour.cameraControl.getCamera(),this._getViewModel().getWallPlanObjectViewModels()),this._lightSetting?.addToScene(),this._roomleRenderer?.clearCache(),this._requestRender(),this._setCeiling(),n(),a(h)},i)})}_handlePlannerIsolationModeState(e){if(!e){const t=this._configuratorContext.baseContext;return this._getViewModel().showAll(),this._configuratorContext.baseContext=b.PLANNER,()=>{this._configuratorContext.baseContext=t,t===b.CONFIGURATOR&&(this._configureInRoom||this._hideAllExceptSelectedElement())}}return()=>null}_hideAllExceptSelectedElement(){const{planElementId:e}=this._configuratorContext,t=this.getRootPlanObjectId(e);this._getViewModel().hideAllExcept(t)}preparePerspectiveImage(e={},t){return this._preparePerspectiveImage(e,t)}_calculateBoundingBoxOfAllMeshes(e=0){const t=this.getBounds();return we.getCameraTargetForBBox(t,e)}enableRotation(){this._plannerSceneEventHandler.setState(te.ROTATE)}disableRotation(){this._plannerSceneEventHandler.resetState()}enableSnapping(){this._plannerSceneEventHandler.enableSnapping()}disableSnapping(){this._plannerSceneEventHandler.disableSnapping()}enableAdvancedDocking(){this._plannerSceneEventHandler.enableAdvancedDocking()}disableAdvancedDocking(){this._plannerSceneEventHandler.disableAdvancedDocking()}showsChildrenOfPlanObject(e){if(e instanceof k){const t=e.getKernelObject();return this._plannerSceneEventHandler.showsChildrenOfPlanObject(t)}return!1}enableShowChildrenOfPlanObject(e){if(e instanceof k){const t=e.getKernelObject();this._plannerSceneEventHandler.enableShowChildrenOfPlanObject(t)}}disableShowChildrenOfPlanObject(e){if(e instanceof k){const t=e.getKernelObject();this._plannerSceneEventHandler.disableShowChildrenOfPlanObject(t)}}dragIn(e){this._plannerSceneEventHandler.getSelectedIds().length>0&&this._plannerSceneEventHandler.cancelSelection("dragIn"),this._plannerSceneEventHandler.setDragIn(!0,e)}getPlannerSceneEventHandler(){return this._plannerSceneEventHandler}disablePlannerEvents(){this._plannerSceneEventHandler.disable()}enablePlannerEvents(){this._plannerSceneEventHandler.enable()}_onCameraIdle(){return super._onCameraIdle()&&(this._sendRoomMeasurements(),this._sendPlanObjectPositions(),this._roomlePlannerUiCallback.onCameraIdle(),this._sendElementMeasurements(),this._hideAllNodeIfThereAreNoSelections(),this._sendWallDimensions()),!0}_hideAllNodeIfThereAreNoSelections(){!this.currentSelection&&!this.getPlannerSceneEventHandler().isCurrentlyDrawing&&(this._getViewModel().getMeasurementLineObjectViewModels().forEach(e=>e.hideDraggableNodes()),this._getViewModel().getNodePlanObjectViewModels().forEach(e=>e.hide()))}_onCameraMove(){return super._onCameraMove()&&(this._roomlePlannerUiCallback.disableWallDimensions(),this._roomlePlannerUiCallback.cameraStartsMoving()),this._updateNodeSize(),this._renderEverything(),!0}_showWallNodes(){this._getViewModel().getNodePlanObjectViewModels().forEach(e=>e.show())}_updateNodeSize(){if(this.cameraBehaviour.cameraControl instanceof G){const e=1/this.cameraBehaviour.cameraControl.getCamera().zoom;this._getViewModel().setNodeZoom(e)}}_sendPlanObjectPositions(){if(this.cameraBehaviour.cameraControl.isLocked())return;const{clientWidth:e,clientHeight:t}=this._domHelper.element,n=this.cameraBehaviour.cameraControl.getCamera(),a=this._plannerSceneEventHandler.getSelectedIds();a.length>1?this._sendMultiSelectionPosition(a,n,e,t):this._sendSelectedPlanObjectPositions(n,e,t)}_sendMultiSelectionPosition(e,t,n,a){const i=new re;for(const c of e){const h=this._getViewModel().getPlanObjectForId(c);h&&i.expandByObject(h.getContainer())}const s=i.getCenter(new E),o=qe(p(s,t,n,a));this._roomlePlannerUiCallback.onUpdatePlanObjectPositions([{runtimeIds:e,position2d:o}])}_sendSelectedPlanObjectPositions(e,t,n){const a=this._getViewModel(),i=[],s=[...a.getStaticPlanObjectViewModels(),...a.getConfigurablePlanObjectViewModels(),...a.getConfigurableConstructionPlanObjectViewModels(),...a.getConstructionPlanObjectViewModels(),...a.getWallPlanObjectViewModels(),...a.getFloorPlanObjectViewModels(),...a.getNodePlanObjectViewModels()];for(const o of s)i.push(Gn(o,e,t,n));this._roomlePlannerUiCallback.onUpdatePlanObjectPositions(i)}_sendRoomAreaData(){const e=this._getViewModel().getFloorPlanObjectViewModels(),t=this.cameraBehaviour.cameraControl.getCamera(),{clientWidth:n,clientHeight:a}=this._domHelper.element,i=[],s=this.cameraBehaviour.cameraControl.getKernelZoomFactor();this._initData.debug&&this._debugSpheres.floorPoints.children.length&&this._debugSpheres.floorPoints.clear();for(const o of e){const c=o.getFloorData(s);if(!c||!c.textPosition3d)return;if(c.roomLabel=o.getKernelObject().getLabelObject(),c.formattedArea=this._unitFormatter.formatSquareMMValueToUnitString(c.area),c.textPosition2d=p(c.textPosition3d,t,n,a),i.push(kt(c)),this._initData.debug){const h=new Oe(.1,32,16),d=new H({color:255}),u=new S(h,d);u.position.copy(c.textPosition3d),this._debugSpheres.floorPoints.add(u)}}i.length>0&&this._roomlePlannerUiCallback.onFloorPlanAreasUpdated(i)}_updateMeasurementPositions(e,t,n,a){return e.fromPosition3d&&(e.fromPosition2d=p(e.fromPosition3d,t,n,a)),e.toPosition3d&&(e.toPosition2d=p(e.toPosition3d,t,n,a)),e.textPosition3d&&(e.textPosition2d=p(e.textPosition3d,t,n,a)),e}_sendElementMeasurements(e){this.cameraBehaviour.cameraControl instanceof G&&(this._sendConstructionElementDimensions(e),this._sendObjectMeasurements(e),this._sendMeasurementLineDimension())}_sendRoomMeasurements(){this.cameraBehaviour.cameraControl instanceof G&&(this._sendWallDimensions(),this._sendRoomAreaData())}_sendMeasurementLineDimension(){if(!(this.cameraBehaviour.cameraControl instanceof G))return;const e=this.cameraBehaviour.cameraControl.getCamera(),{clientWidth:t,clientHeight:n}=this._domHelper.element,a=[],i=this._getViewModel().getMeasurementLineObjectViewModels();for(const s of i){const o=s.getMeasurementLineDimension();o.fromPosition2d=p(o.fromPosition3d,e,t,n),o.toPosition2d=p(o.toPosition3d,e,t,n),o.textPosition2d=p(o.textPosition3d,e,t,n),o.lengthFormatted=this._unitFormatter.formatMMValueToUnitString(o.length),a.push(Bt(o))}this._roomlePlannerUiCallback.onUpdateMeasurementLineDimensions(a)}_sendObjectMeasurements(e){if(!(this.cameraBehaviour.cameraControl instanceof G)||!this.currentSelection&&!e)return;const t=this._plannerSceneEventHandler.getSelectedIds();if(t.length===0&&!e)return;const n=e||this._getViewModel().getPlanObjectForId(t[0]);if(!n||n instanceof be||n instanceof q||!(n instanceof N)&&!(n instanceof k))return;const a=this.cameraBehaviour.cameraControl.getCamera(),{clientWidth:i,clientHeight:s}=this._domHelper.element,o=this.cameraBehaviour.cameraControl.getKernelZoomFactor(),c=n.getObjectMeasurements(o,i,s),h=this.transformMeasurements(c.rectMeasurements,a,i,s),d=this.transformMeasurements(c.objectMeasurements,a,i,s),u=this.transformMeasurements(c.objectToWallsMeasurements,a,i,s);this._roomlePlannerUiCallback.onUpdateObjectMeasurements({rectMeasurements:h,objectMeasurements:d,objectToWallsMeasurements:u})}transformMeasurements(e,t,n,a){return e.map(i=>{const s=p(i.fromPosition3d,t,n,a),o=p(i.toPosition3d,t,n,a),c=p(i.textPosition3d,t,n,a);return Ft({...i,fromPosition2d:s,toPosition2d:o,textPosition2d:c})})}_sendConstructionElementDimensions(e){if(!this.currentSelection&&!e)return;const t=e||this._getViewModel().getPlanObjectForId(this.currentSelection.staticItemRuntimeId||this.currentSelection.configurationRuntimeId);if(!t||!(t instanceof be||t instanceof q))return;this._initData.debug&&this._debugSpheres.constructionElementsPoints.children.length>0&&this._debugSpheres.constructionElementsPoints.clear();const n=this.cameraBehaviour.cameraControl.getCamera(),{clientWidth:a,clientHeight:i}=this._domHelper.element,s=this.cameraBehaviour.cameraControl.getKernelZoomFactor(),o=t.getConstructionElementMeasurements(s,a,i);if(!o)return;if(this._initData.debug){const h=new H({color:16711680}),d=new H({color:65280}),u=new H({color:255}),g=new Oe(.1,32,16),_=new S(g,h);_.position.copy(o.leftMeasurement.fromPosition3d),_.position.y=5;const m=new S(g,h);m.position.copy(o.leftMeasurement.toPosition3d),m.position.y=5;const O=new S(g,d);O.position.copy(o.rightMeasurement.fromPosition3d),O.position.y=5;const f=new S(g,d);f.position.copy(o.rightMeasurement.toPosition3d),f.position.y=5;const F=new S(g,u);F.position.copy(o.elementRange.fromPosition3d),F.position.y=5;const U=new S(g,u);U.position.copy(o.elementRange.toPosition3d),U.position.y=5,this._debugSpheres.constructionElementsPoints.add(_),this._debugSpheres.constructionElementsPoints.add(m),this._debugSpheres.constructionElementsPoints.add(O),this._debugSpheres.constructionElementsPoints.add(f),this._debugSpheres.constructionElementsPoints.add(F),this._debugSpheres.constructionElementsPoints.add(U)}o.leftMeasurement=this._updateMeasurementPositions(o.leftMeasurement,n,a,i),o.rightMeasurement=this._updateMeasurementPositions(o.rightMeasurement,n,a,i),o.elementRange=this._updateMeasurementPositions(o.elementRange,n,a,i);const c={leftMeasurement:{...je(o.leftMeasurement)},rightMeasurement:{...je(o.rightMeasurement)},elementRange:{...je(o.elementRange)}};this._roomlePlannerUiCallback.onUpdateConstructionElementsMeasurements(c)}_sendWallDimensions(e=!0){this._initData.debug&&this._debugSpheres.wallPoints.children.length>0&&this._debugSpheres.wallPoints.clear(),Xn(this._domHelper,this.cameraBehaviour,this._roomlePlannerUiCallback,this._plannerSceneEventHandler,this._getViewModel(),this._unitFormatter,this._debugSpheres,e,this._initData.debug)}enableWallDrawing(){if(this.cameraBehaviour.cameraControl instanceof G){const e=Ie(this.getBounds(),this._domHelper.element.clientWidth,this._domHelper.element.clientHeight);this.plannerCameraBehaviour.resetCameraOnEnableWallDrawing(e)}this._drawingEnabled||(this._drawingEnabled=!0,this._scene.add(this._plannerSceneEventHandler.enableWallDrawing()))}disableWallDrawing(){this._drawingEnabled=!1,this.cameraBehaviour.cameraControl.unlock(),this._scene.remove(this._plannerSceneEventHandler.cancelWallDrawing())}escapeDrawing(e){this._plannerSceneEventHandler.stopDrawing(e)}cancelDragIn(){if(this._plannerSceneEventHandler.isDragIn()){const e=this._plannerSceneEventHandler.getSelectedIds();this._plannerSceneEventHandler.cancelSelection("delete_object"),this._plannerSceneEventHandler.setDragIn(!1),this._getInputManager().forceMouseUp(),this.deletePlanElements(e)}}setSceneEvents(e){this.cameraBehaviour.cameraControl instanceof J||(e.construction!==void 0&&this._plannerSceneEventHandler?.enableConstructionEvents(e.construction),e.objects!==void 0&&this._plannerSceneEventHandler?.enableObjectEvents(e.objects))}startedDrawing(){this._plannerSceneEventHandler.startDrawing(),this._showWallNodes()}stoppedDrawing(){this._plannerSceneEventHandler.stopDrawing()}disableEvents(){super.disableEvents(),this.disablePlannerEvents()}enableEvents(){super.enableEvents(),this._configuratorContext.baseContext===b.PLANNER&&!(this.cameraBehaviour.cameraControl instanceof J)&&this.enablePlannerEvents()}resetCameraPositionToStart(){this.plannerCameraBehaviour.externalApiResetCameraPosition(this.getBounds())}async moveCamera(e){return this.plannerCameraBehaviour instanceof ye||this.plannerCameraBehaviour instanceof nt?this.plannerCameraBehaviour.externalApiMoveCamera(e):Promise.resolve()}_setInteriorOrExteriorWallMaterial(e,t){const a=this._getViewModel().getWallPlanObjectViewModels();if(!a.length)return;const i=this._getKernelAccess().planInteractionHandler,s=g=>{i.setWallLeftMaterial(g,xe(g.leftMaterial,t))},o=g=>{i.setWallRightMaterial(g,xe(g.rightMaterial,t))},c=a.map(g=>g.getKernelObject()),h=this._plannerKernelAccess.kernelContainer.WallType.InnerWall,d=this._plannerKernelAccess.kernelContainer.WallType.OuterWallLeft,u=this._plannerKernelAccess.kernelContainer.WallType.OuterWallRight;for(const g of c)g.wallType===h&&e===Ae.INTERIOR&&(s(g),o(g)),g.wallType===d&&(e===Ae.INTERIOR?o(g):s(g)),g.wallType===u&&(e===Ae.EXTERIOR?o(g):s(g))}changeInteriorWallsMaterial(e){this._setInteriorOrExteriorWallMaterial(Ae.INTERIOR,e)}changeExteriorWallsMaterial(e){this._setInteriorOrExteriorWallMaterial(Ae.EXTERIOR,e)}changeFloorsMaterial(e){const n=this._getViewModel().getFloorPlanObjectViewModels();if(!n.length)return;const a=this._getKernelAccess().planInteractionHandler,i=n.map(s=>s.getKernelObject());a.startInteraction();for(const s of i)a.setFloorMaterial(s,xe(s.material,e));a.endInteraction()}getWallAngleDegrees(e){if(!(e instanceof A))return 0;const t=this.cameraBehaviour.cameraControl.getCamera(),n=new ue(t.position.x,t.position.z),i=new ue(e.getPosition().x,e.getPosition().z).clone().sub(n).normalize(),s=e.getKernelObject(),o=new ue(Math.sin(s.getAngle()),Math.cos(s.getAngle())),c=i.angle()-o.angle();return Gt.radToDeg(c)}moveElementPosition(e,t){const n=this._getKernelAccess().planInteractionHandler;n.setObjectFixedZ(e.getPlanElement(),!0);const a=e.getPlanElement().getCenter(),i=Z(t).sub(Z(a));n.moveElementBy(e.getPlanElement(),w(i)),n.setObjectFixedZ(e.getPlanElement(),!1),this._sendPlanObjectPositions()}moveElementsPosition(e,t){const n=new this._plannerKernelAccess.kernelContainer.PlanObjectPtrList,a=Z(t).sub(e[e.length-1].getPosition());e.forEach(o=>n.push_back(o.getPlanElement()));const i=w(a);this._getKernelAccess().planInteractionHandler.moveObjectsBy(n,i),this._sendPlanObjectPositions()}get plannerCameraBehaviour(){return this.cameraBehaviour}enableMeasurementLineDrawing(){this._roomlePlannerUiCallback.onMeasurementLineStateChange(!0),this._plannerSceneEventHandler.enableMeasurementLineDrawing()}disableMeasurementLineDrawing(){this._plannerSceneEventHandler.disableMeasurementLineDrawing()}setCompletelyLoaded(e){this._completelyLoaded=e}enablePanning(){this.plannerCameraBehaviour instanceof ye&&this.plannerCameraBehaviour.enablePanningOnShiftClick()}disablePanning(){this.plannerCameraBehaviour instanceof ye&&this.plannerCameraBehaviour.disablePanningOnShiftRelease()}setObjectToWallMeasurementLength(e,t,n){const a=this._getViewModel().getPlanObjectForId(e),i=a.getPlanElement(),o=Ut(i.getWallDistances()).find(m=>Wt(m.angle+"_"+m.length)===t);if(!o)return;const c=Z(o.startPoint),h=Z(o.endPoint),d=c.clone().sub(h).normalize(),u=(n-o.length)/1e3,g=a.getPosition().clone().add(d.multiplyScalar(u));this._getKernelAccess().planInteractionHandler.moveElementToIn2d(i,w(g)),this._sendObjectMeasurements()}setWallMeasurementLength(e,t,n){const a=this.getPlannerSceneEventHandler().isCurrentlyDrawing,i=this._getKernelAccess().planInteractionHandler;let s=this._getViewModel().getPlanObjectForId(e);const o=i.isVectorPreviewModeEnabled();if(a&&!o){const c=this._getViewModel().latestNodePlanObjectViewModel,h=w(c.getPosition());i.endDrawing(h),this.escapeDrawing(!1),s=this._getViewModel().latestWallPlanObjectViewModel}if(s){const c=s.getKernelObject();i.startInteraction(),i.setLengthOfWall(c,t,c.getPreferredSide(),n,!0),i.endInteraction()}if(a&&!o){i.startInteraction();const c=this._getViewModel().latestNodePlanObjectViewModel,h=w(c.getPosition());i.beginDrawing(h,!1),this._plannerSceneEventHandler.startDrawing()}}setMeasurementLineLength(e,t,n){const a=this._getViewModel().getPlanObjectForId(e);this._plannerSceneEventHandler.setMeasurementLineLength(a,t,n)}setEventHandlerObject(e){super.setEventHandlerObject(e),this._plannerSceneEventHandler.setObject(e)}_readyForRender(){console.log("ready_for_render"),this._roomlePlannerUiCallback.onReadyForRender(),this._globalCallback.onReadyForRender()}notifyPlannerOnComponentSelectionCancel(e,t){if(e)if(this.configuratorContext.baseContext===b.CONFIGURATOR){if(t==="click_outside"){const n=this.getObjectComponent(this.configuratorContext.rootComponentId??this.configuratorContext.planObjectId);this._roomlePlannerUiCallback.onExternalObjectModuleSelected(n.externalObjectGroupId,null,null)}}else this._roomlePlannerUiCallback.onExternalObjectSelectionCancel(t);else this._roomlePlannerUiCallback.onComponentSelectionCancel()}_planObjectSelectionChanged(e,t){const n=this.getObjectComponent(t??e);if(n?.configurationType?.value!==Y.EXTERNAL)return;const a=this.getObjectComponent(this.configuratorContext.selectedRuntimeComponentId??this.configuratorContext.planObjectId);a.externalRootModuleId===n.externalRootModuleId&&a.externalSubModuleId===n.externalSubModuleId||this._getKernelAccess().planObjectSelectionChanged(e,t)}highlightExternalObject(e){this.highlightPlanElementById(e.runtimeId),this._renderWithoutShadowsAndAO()}_selectExternalObjectModule(){this._getKernelAccess()?.kernelContainer&&!this._configuratorContext.selectedRuntimeComponentId&&this.getPlanObject(this._configuratorContext.planElementId).configurationType?.value===Y.EXTERNAL&&this.selectComponent(this._configuratorContext.rootComponentId)}getObjectComponent(e){const n=this._getKernelAccess().planInteractionHandler.getPlan();return this._getKernelAccess().planModelViewHelper.getObjectComponent(n,e)}getCameraParameters3d(){return this._getViewModel().cameraType===P.CAMERA_3D?this.cameraBehaviour3d.cameraControl.getCurrentCameraParameters():null}_createCeilingLightGroup(){this._scene.children.find(t=>t.name===fn)||this._scene.add(this._getViewModel().getCeilingLightsGroup())}toggleInteriorLightsSceneSettings(e){this._initData.featureFlags.interiorLights&&(this._isInteriorLightActive=e,this._scene.userData.environmentDefinition.rotation=e?hn:Kt,this._scene.userData.environmentDefinition.intensity=e?dn:Nt,this._isInteriorLightActive&&(this._createCeilingLightGroup(),this._activateCeilingLight()),this._getViewModel().toggleCeilingLights(e),this._requestRender())}async _insertRapiItems(e){const t=e.map((a,i)=>({id:a,index:i})),n=[];for(const{index:a,id:i}of t)n.push({index:a,id:i});return await this.insertRapiObjects(n)}async insertRapiObjects(e){const t=({id:s})=>ce(s)?this._rapiAccess.getItem(s):this._rapiAccess.getConfiguration(s),n=e.map(t),a=await Promise.all(n);return(await this._plannerKernelAccess.insertItems(a)).map((s,o)=>({runtimeId:s,originalIndex:e[o].index}))}}De([C],de.prototype,"_rapiAccess"),De([C],de.prototype,"_plannerMeshGenerator"),De([C],de.prototype,"_plannerInputManager"),De([C],de.prototype,"_roomlePlannerUiCallback"),De([C],de.prototype,"_localStorageHelper");var Qn=Object.defineProperty,R=(r,e,t,n)=>{for(var a=void 0,i=r.length-1,s;i>=0;i--)(s=r[i])&&(a=s(e,t,a)||a);return a&&Qn(e,t,a),a};const En="Could not retrieve configuration for external object! Did you implement onGetConfigurationForExternalObject?",ea={left:0,top:1,right:1,bottom:0};class L{constructor(e,t){this._homagIntelligence=null,this._hscInstance=null,this._glbInstance=null,this._configurator=null,this._currentMode=1,this._creator_=e,this._activePlugins=t||[],this._kernelAccessCallback.addListener(this)}setEnvironmentMap(e){const{url:t,intensity:n,rotation:a,maxLightSources:i}=e;this._sceneManager.setEnvironmentMap(t,n,a,i)}deleteSelection(){this._sceneManager.deletePlanElementSelection()}rotateSelection(e){this._sceneManager.rotatePlanElementSelection(e)}cancelSelection(e="unknown"){this._sceneManager.cancelPlanElementSelection(e)}init(e,t,n){return Je.start("loadingTime"),this._domHelper.setDomElement(e),this._sceneManager?(this._lifeCycleManager.resume(),Promise.resolve()):(this._preloadPlanId=t,this.setOverrides(n),new Promise(this._initPromiseCallback.bind(this)))}async createPlanFromObject(e,t,n){if(!this._planInteractionHandler)throw new Error("no plan interaction handler");t&&(t=w(new E(t.x,t.y,t.z)));const a=await(ce(e)?this._rapiAccess.getItem(e):this._rapiAccess.getConfiguration(e));this._plan=this._plannerKernelAccess.createPlanFromObject(a,t,n),this._sceneManager.planXMLLoaded(this._plan),this._sceneManager.updateScene(),this.resetCameraPosition();const i=W(this._plan.getPlanObjects());return i?.length?i[0].getId():-1}loadPlanXml(e,t){return this._sceneManager.setCompletelyLoaded(!1),this.setOverrides(t),new Promise(n=>{this._plan=this._planInteractionHandler.loadPlanXML(e),this._sceneManager.planXMLLoaded(this._plan),this._roomlePlannerUiCallback.onTotalFloorAreaChanged(this._planInteractionHandler.getPlan().getTotalFloorArea()),this._currentMode=1,this._initData.moc&&(t.id?this._rapiAccess.trackView(t.id,Te.ROOM_DESIGNER):this._rapiAccess.trackView("planXML",Te.ROOM_DESIGNER)),n()})}loadPlan(e,t){return this.setOverrides(t),new Promise((n,a)=>{const i=Qe(e);(i?this._rapiAccess.getPlanSnapshot(e):this._rapiAccess.getPlan(e)).then(o=>{this._sceneManager.backToPlanner(),this._sceneManager.setCompletelyLoaded(!1);const c=i?o.plan:o.planObjects;this._plan=this._planInteractionHandler.loadPlanXML(c),this._sceneManager.planXMLLoaded(this._plan),this._roomlePlannerUiCallback.onTotalFloorAreaChanged(this._planInteractionHandler.getPlan().getTotalFloorArea()),this._configuratorContext.lastLoadedPlanId=e,this._currentMode=1,this._initData.moc&&this._rapiAccess.trackView(e,Te.ROOM_DESIGNER),n(o)},a)})}setOverrides(e){e&&(this._initData.setOverrides(e),this._globalInitData.setOverrides(e))}toggleConfigureInRoom(){this._sceneManager.toggleConfigureInRoom()}switch2D(){this._sceneManager.switchTo2D()}switch3D(){this._sceneManager.switchTo3D()}switchToFirstPerson(){this._sceneManager.switchToFirstPerson()}resetCameraPosition(){this._sceneManager.resetCameraPositionToStart()}exportGLB(){this._sceneManager.exportGLB()}importGLB(e){this._sceneManager.importGLB(e)}_initPromiseCallback(e,t){this._kernelReadyCallback=e;const{dls:n,ls:a,mode:i,stats:s}=this._initData;this._sceneManager||(this._sceneManager=new de(this._creator_,ea,this,i)),this._preloadPlanId&&this._sceneManager.preload(this._preloadPlanId);const o=zt.createDynamicLightSettingSource(n,a);s&&this.showStats(),this._sceneManager.enableHD(o),this._planInteractionHandler&&this._kernelReadyCallback()}isReady(){this._planInteractionHandler=this._plannerKernelAccess.planInteractionHandler,this._kernelReadyCallback&&this._kernelReadyCallback()}showBenchmarks(){Je.showBenchmarks()}getConfiguratorApi(){return this._configurator||(this._configurator=new Vt(this._creator_,this._activePlugins),this._configurator.setOverrides(this._initData),this._configurator.initSceneManager(this._sceneManager)),this._configurator}startViewing(){this._sceneManager.startViewing(),this._roomlePlannerUiCallback.onContextChanged(b.GLB_VIEWER)}startConfiguring(){const e=this._sceneManager.currentSelection,t=e.item?.id||e.configuration?.id;this._sceneManager.startConfiguring(),t&&this._configurator.notifyUiAboutNewLabel(t),this._roomlePlannerUiCallback.onContextChanged(b.CONFIGURATOR)}async selectPlanObjectById(e){return this._sceneManager.selectPlanObject(e)}highlightPlanElements(e){e===null?this._sceneManager.highlightPlanElementsById(null):Array.isArray(e)?this._sceneManager.highlightPlanElementsById(e):this._sceneManager.highlightPlanElementById(e)}backToPlanner(){this._sceneManager.backToPlanner(),this._roomlePlannerUiCallback.onContextChanged(b.PLANNER)}showGUI(){this._sceneManager.showGUI()}async switchToConfigurator(){const e=await this._singlePromiseFactory.create(et.START_HSC,"startHSC",t=>{if(this._hscInstance)return t(this._hscInstance);ae.import("./configurator-DExQ7ygL.js").then(({Configurator:n})=>{const a=new n(this._creator_);a.boot({kernelInstance:this._planInteractionHandler.getConfiguratorKernel(),kernelContainer:this._plannerKernelAccess.kernelContainer}),a.getApi().setOverrides(this._initData),a.getApi().initSceneManager(this._sceneManager),a.getApi().init(this._domHelper.element).then(()=>{this._hscInstance=a,t(this._hscInstance)})})});return this._currentMode=0,this.cancelSelection("isolation_mode_started"),e}async switchToViewer(){const e=await this._singlePromiseFactory.create(et.START_GLB,"startGLB",t=>{if(this._glbInstance)return t(this._glbInstance);ae.import("./glb-viewer-BuaOp37E.js").then(n=>{const a=new n.GlbViewer(this._creator_);a.boot(),a.getApi().setOverrides(this._initData),a.getApi().init(this._domHelper.element).then(()=>{this._glbInstance=a,t(this._glbInstance)})})});return this._currentMode=2,this.cancelSelection("isolation_mode_started"),e}switchToPlanner(e){e&&this.loadPlan(e),this._currentMode=1}updateSize(){this._sceneManager.updateCamera()}getMain(){}update(){this.updateSize(),this._glbInstance&&this._glbInstance.getApi().updateSize(),this._hscInstance&&this._hscInstance.getApi().updateSize()}get callbacks(){return this._roomlePlannerUiCallback}set callbacks(e){this._roomlePlannerUiCallback=e}get hasSingleRoom(){return this._sceneManager.hasSingleRoom}showStats(){this._sceneManager.showStats()}onCloseHSC(){this._hscInstance&&this._hscInstance.getApi().pauseKernelCallbacks()}back(){if(this._currentMode===2&&this._glbInstance&&this._glbInstance.getApi().clearScene(),this._currentMode===0&&this._hscInstance){const e=this._hscInstance.getApi();e.cancelSelection({reason:"isolation_mode_cancelled"}),e.cancelDockings(),e.hideDimensions(),e.disableMultiselect(),this._sceneManager.updateScene()}this._currentMode=1}backTo(e){console.error("backTo in planner Needs to be implemented later")}getConfigurator(){return this._hscInstance}getCurrentSkin(){return this._rapiAccess.getCurrentSkin()}getRuntimeComponentIdOfRootComponent(e){return e?this._plannerKernelAccess.planInteractionHandler?this._plannerKernelAccess.planInteractionHandler.getConfiguratorKernel().getRootPlanComponentIdFromObjectId(e):(console.warn("Can not retrieve runtime id without planInteractionHandler"),0):(console.warn("Can not retrieve runtime id without planObjectId"),0)}resumeTest(e){this._domHelper.setDomElement(e),this._lifeCycleManager.resume()}pauseTest(){this._lifeCycleManager.pause()}syncCatalog(e){return this._dataSyncer.syncCatalog(e)}loadError(e){console.log(e)}getPlanInteractionHandler(){return Promise.resolve(this._planInteractionHandler)}getPlanModelViewHelper(){return Promise.resolve(this._plannerKernelAccess.planModelViewHelper)}async insertObject(e,t,n){if(!this._planInteractionHandler)throw new Error("no plan interaction handler");if(t&&(t=w(new E(t.x,t.y,t.z))),ke(e))return this._insertExternalObject(e,{findFreeSpaceInPlan:!t,position:t,rotation:n});const a=await(ce(e)?this._rapiAccess.getItem(e):this._rapiAccess.getConfiguration(e)),i=await this._plannerKernelAccess.addPlanObjectFromItem(a,t,n);return this._sceneManager.updateScene(),i}async insertItemList(e){if(e.length===0)return[];const t=e.map((d,u)=>({id:d,index:u})),n=async(d,u)=>({runtimeId:await this._insertExternalObject(d),originalIndex:u}),a=[],i=[];for(const{index:d,id:u}of t)ke(u)?a.push(n(u,d)):i.push({index:d,id:u});const s=this._sceneManager.insertRapiObjects(i),[o,c]=await Promise.all([Promise.all(a),s]),h=[...o,...c];return h.sort((d,u)=>d.originalIndex-u.originalIndex),h.map(d=>d.runtimeId)}async insertItems(e){if(e.length===0)return[];const t=e.map(n=>typeof n=="string"?n:n.id);return this.insertItemList(t)}duplicateItems(e){return this._plannerKernelAccess.duplicateItems(e)}getScene(){return this._sceneManager.getScene()}updateScene(){this._sceneManager?.updateScene()}getCameraOffset(){return this._sceneManager.getCameraOffset()}setCameraOffset(e){this._sceneManager.setCameraOffset(e)}async getObjects(){const e=(await this.getPlanModelViewHelper()).getPlanOverview(this._plan),t=W(e.objects);return he(t,this._plannerKernelAccess,this._rapiAccess)}async getPlanOverview(){const e=(await this.getPlanModelViewHelper()).getPlanOverview(this._plan);return W(e)}prepareTopImage(e={}){return this._sceneManager.prepareTopImage(e)}preparePerspectiveImage(e={},t=!1){return this._sceneManager.preparePerspectiveImage(e,t)}enableRotation(){this._sceneManager.enableRotation()}disableRotation(){this._sceneManager.disableRotation()}enableMultiselect(){this._sceneManager.getPlannerSceneEventHandler().setSelectionMode(M.MULTISELECT),this._configuratorContext.selectionMode=M.MULTISELECT}disableMultiselect(){this._sceneManager.getPlannerSceneEventHandler().setSelectionMode(M.STANDARD),this._configuratorContext.selectionMode=M.STANDARD}async _insertExternalObject(e,t={}){let n=e;if(ke(e)&&(n=await this.newPosDataFromId(e),!n))throw new Error(En);if(Xt(e)&&e.externalMeta?.refresh&&(n=await this._roomlePlannerUiCallback.onGetConfigurationForExternalObject(e.id),!n))throw new Error(En);const a=t.findFreeSpaceInPlan??!0,i=t.dragIn??!1;return await this._loadExternalObjectGroup(n,a,i,!1,[],t.position,t.rotation),-1}async dragInObject(e,t,n="rml_id"){if(n==="rml_serialized")throw new Error("dragInObject is not supported for tc_id or rml_serialized");if(this._sceneManager.dragIn(t),n==="rml_id"){const a=ce(e)?await this._rapiAccess.getItem(e):await this._rapiAccess.getConfiguration(e),i=await this.insertItems([a]);if(await this._sceneManager.selectPlanObject(i[0]),i.length!==1)throw new Error("More than one object added, abort");return i[0]}else{if(n==="tc_id"||n==="tc_serialized")return this._insertExternalObject(e,{dragIn:!0});throw new Error("dragInObject is not supported for "+n)}}cancelDragIn(){this._sceneManager.cancelDragIn()}enableSnapping(){this._sceneManager.enableSnapping()}disableSnapping(){this._sceneManager.disableSnapping()}enableAdvancedDocking(){this._sceneManager.enableAdvancedDocking()}disableAdvancedDocking(){this._sceneManager.disableAdvancedDocking()}showsChildrenOfPlanObject(e){return this._sceneManager.showsChildrenOfPlanObject(e)}enableShowChildrenOfPlanObject(e){this._sceneManager.enableShowChildrenOfPlanObject(e)}disableShowChildrenOfPlanObject(e){this._sceneManager.disableShowChildrenOfPlanObject(e)}async getPartlistOf(e){const t=this._plannerKernelAccess.kernelInstance.getHashOfConfiguration(e);if(!t){const i="Object has no partlist because it is not a configuration: "+t;return console.warn(i),Promise.reject(i)}const n=this._plannerKernelAccess.kernelInstance.getPartList(e);return await this._plannerKernelAccess.addUiDataAndPriceToPartList(n,t)}formatValueToUnitString(e,t){return this._unitFormatter.formatValueToUnitString(e,t)}drawWalls(e,t={}){const n=this._planInteractionHandler;n.startInteraction();const a=[];for(const i of e){const s=n.addNode(i.from),o=n.addNode(i.to),c=n.addWall(s,o);i.props?.height!==void 0&&n.setWallHeight(c,i.props.height),i.props?.thickness!==void 0&&n.setWallThickness(c,i.props.thickness),a.push(c)}return t.keepInteractionOpen||n.endInteraction(),this._sceneManager.updateCameraOnDrawWalls(),this._sceneManager.updateScene(),a}async removeElements(e,t={}){this._sceneManager.lockCamera();const n=this._planInteractionHandler;for(const a of e){const i=this._sceneManager.getPlanObject(a.getId());let s;i&&(s=await he([i],this._plannerKernelAccess,this._rapiAccess)),this._roomlePlannerUiCallback.onPlanElementChanged($.REMOVED,s?.length?s[0]:{...i,data:null}),this._planInteractionHandler.removeElement(a)}t.keepInteractionOpen||n.endInteraction(),this._sceneManager.unlockCamera()}hasWalls(){const t=this._planInteractionHandler?.getPlan();return!(!t||t.getWallCount()<1)}enableWallDrawing(){this._sceneManager.enableWallDrawing()}disableWallDrawing(){this._sceneManager.disableWallDrawing()}getUnitFormatter(){return this._unitFormatter}getStorage(){return this._idbManager}getConfiguratorContext(){return this._configuratorContext}get PlannerCoreTypes(){return this._plannerKernelAccess.kernelContainer}setSceneEvents(e){this._sceneManager.setSceneEvents(e)}async saveExternalObjectSnapshot(e){const t=await this.getPlanModelViewHelper(),n=this._planInteractionHandler.getPlan(),a=W(t.getExternalObjectGroups(n));if(a.length===0)return null;const i=await this._savePlanSnapshotExternalObjects(e,a);return{...i,glb:`https://api.roomle.com/v2/planSnapshots/${i.id}/3dAssets/glTF/plan.glb`,usdz:`https://api.roomle.com/v2/planSnapshots/${i.id}/3dAssets/usdz/plan.usdz`}}async _savePlanSnapshotExternalObjects(e,t){const n=t.map(m=>m.uniqueId),a=t.map(m=>m.runtimeId),i=await this.getPlanModelViewHelper(),s=this._planInteractionHandler.getPlan(),o=i.getPlanOverview(s),c=s.createPlanXmlWithObjects(n,!1,2),h={parentId:e||null,planObjects:[],combinedIds:[],plan:c},d=o.objects,u=d.size();for(let m=0;m<u;m++){const O=d.get(m),f=O.configurationHash||O.catalogItemId;if(a.includes(O.runtimeId)){const{center:F,dimensions:U,rotation:ot,rootComponentCenter:fa}=O,Ca=JSON.stringify({center:F,dimensions:U,rotation:ot,rootComponentCenter:fa});h.planObjects.push({combinedId:f,position:Ca})}}const g=await this._rapiAccess.savePlanSnapshot(h);this._plannerKernelAccess.planSnapshotCreated(g);const _=new Promise((m,O)=>{Promise.allSettled([this.preparePerspectiveImage({runtimeIds:a}),this.prepareTopImage({runtimeIds:a})]).then(async([f,F])=>{if(f.status==="rejected"||F.status==="rejected"){O("Could not generate images of plan snapshot");return}try{const U=await this._rapiAccess.savePlanSnapshotImage(g,f.value,"perspectiveImage",F.value,"topImage");m({...U})}catch(U){O(U)}})});try{return await _}catch(m){return console.error(m),g}}async saveCurrentPlanSnapshot(e,t){const n=await this.getPlanModelViewHelper(),a=this._planInteractionHandler.getPlan(),i=n.getPlanOverview(a),s=t?a.createPlanXmlWithObjects(t,!1,2):a.getPlanXML(!1,2),o={parentId:e||null,planObjects:[],combinedIds:[],plan:s},c=i.objects,h=c.size();for(let g=0;g<h;g++){const _=c.get(g),m=_.configurationHash||_.catalogItemId;if(!t||m===t){const{center:O,dimensions:f,rotation:F,rootComponentCenter:U}=_,ot=JSON.stringify({center:O,dimensions:f,rotation:F,rootComponentCenter:U});o.planObjects.push({combinedId:m,position:ot})}}const d=await this._rapiAccess.savePlanSnapshot(o);this._plannerKernelAccess.planSnapshotCreated(d);const u=new Promise((g,_)=>{Promise.allSettled([this.preparePerspectiveImage(),this.prepareTopImage()]).then(async([m,O])=>{if(m.status==="rejected"||O.status==="rejected"){_("Could not generate images of plan snapshot");return}try{const f=await this._rapiAccess.savePlanSnapshotImage(d,m.value,"perspectiveImage",O.value,"topImage");g({...f})}catch(f){_(f)}})});try{return await u}catch(g){return console.error(g),d}}getPlanXmlFrom(e){return e?Qe(e.id)?e.plan:e.planObjects:null}async moveCamera(e){return this._sceneManager.moveCamera(e)}async createNewSerializedConfiguration(e){return Promise.resolve(this._plannerKernelAccess.createNewSerializedConfiguration(e))}changeInteriorWallsMaterial(e){this._sceneManager.changeInteriorWallsMaterial(e)}changeExteriorWallsMaterial(e){this._sceneManager.changeExteriorWallsMaterial(e)}changeFloorsMaterial(e){this._sceneManager.changeFloorsMaterial(e)}getWallAngleDegrees(e){return this._sceneManager.getWallAngleDegrees(e)}calcPartsPriceSum(e){return this._plannerKernelAccess.calcPartsPriceSum(e)}async swapObject(e,t){let n;typeof e=="number"?n=await this.getPlanObjectForRuntimeId(e):n=e;const a=n.getPosition(),i=n.getRotation();return await this._sceneManager.deletePlanElementByIds([n.getPlanElement().getId()]),this.cancelSelection("swap_object"),await this.insertObject(t,a,i)}exportImageFromCamera(e="image",t=!1){return this._sceneManager.clearHighlighting(),this._sceneManager.exportImageFromCamera(e,t)}exportCanvasScreenshot(e){return this._sceneManager.exportCanvasScreenshot(e)}moveElementPosition(e,t){this._sceneManager.moveElementPosition(e,t)}moveElementsPosition(e,t){this._sceneManager.moveElementsPosition(e,t)}preparePerspectiveImageOf(e,t={}){return this._sceneManager.preparePerspectiveImageOf(e,t)}async generateTCExport(e=[]){try{const t=new this._plannerKernelAccess.kernelContainer.StringArray;for(const n of e)t.push(n);return Promise.resolve(JSON.parse(this._planInteractionHandler.generateTCExport(t)))}catch(t){return console.error(t),Promise.reject("Could not create Blue Ocean MVP JSON")}}enableMeasurementLineDrawing(){this._sceneManager.enableMeasurementLineDrawing()}disableMeasurementLineDrawing(){this._sceneManager.disableMeasurementLineDrawing()}setObjectToWallMeasurementLength(e,t,n){this._sceneManager.setObjectToWallMeasurementLength(e,t,n)}setWallMeasurementLength(e,t,n){this._sceneManager.setWallMeasurementLength(e,t,n)}setMeasurementLineLength(e,t,n){this._sceneManager.setMeasurementLineLength(e,t,n)}escapeDrawing(e){this._sceneManager.escapeDrawing(e),this._roomlePlannerUiCallback.onDrawCancel()}isCurrentlyDrawing(){return this._sceneManager.getPlannerSceneEventHandler().isCurrentlyDrawing}async resolveShortUrl(e){const[,,,t]=e.split("/"),n=await this._rapiAccess.resolveShortUrl(t);if(!n)throw new Error("Failed to resolve short URL");const{url:a}=n;return a}enableEvents(){this._sceneManager.enableEvents()}disableEvents(){this._sceneManager.disableEvents()}async downloadHomagIxExportPoC(){const{downloadHomagIxExportPoC:e}=await ae.import("./imos-ix-poc-export-helper-CgY9kOS1.js"),t=(await this.getPlanModelViewHelper()).getPlanOverview(this._plan);return e(t,this._plannerKernelAccess.configurationExporter,this._plannerKernelAccess.kernelInstance)}async configureExternalObjectApi(e){const t=typeof e=="string"?JSON.parse(e):e;await this._plannerKernelAccess.configureExternalObjectApi(t)}loadExternalObjectLibrary(e){const t=this._planInteractionHandler.getConfiguratorKernel(),n=typeof e=="string"?e:JSON.stringify(e);t.loadExternalAttributeDefinition(n),this.updateScene()}async loadExternalObjectGroup(e,t,n=!1,a=[]){return this._loadExternalObjectGroup(e,t,!1,n,a)}async _loadExternalObjectGroup(e,t,n,a,i=[],s,o){this.getConfiguratorContext().baseContext===b.CONFIGURATOR?await this._loadExternalObjectGroupInConfigurator(e,t,n,a,i):await this._loadExternalObjectGroupInPlanner(e,t,n,a,i,s,o)}async _loadExternalObjectGroupInConfigurator(e,t,n,a,i=[]){await this._loadOrUpdateExternalObjectGroup(e,t,n,a,i,!0),this.updateScene()}async _loadExternalObjectGroupInPlanner(e,t,n,a,i=[],s,o){const c=this.getConfiguratorContext(),h=this._sceneManager.getPlanObject(c.planElementId);if(await this._loadOrUpdateExternalObjectGroup(e,t,n,a,i,!1,s,o),h.configurationType?.value===Y.EXTERNAL)if(i.includes(h.configurationHash)){const d=this._createSerializedGroupCollection(e),u=JSON.parse(d[0]).id;await this._selectExternalObjectGroup(u,!1)}else await this._selectExternalObjectGroup(h.configurationHash,!1);this.updateScene()}async _loadOrUpdateExternalObjectGroup(e,t,n,a,i,s,o,c){const h=this._createSerializedGroupCollection(e);n?this._planInteractionHandler.startInteraction():this._planInteractionHandler.resumeInteraction();const d=o??{x:0,y:0,z:0},u=c??(n&&!s?this._getFaceTheCameraAngle(90):0),g={findFreeSpaceInPlan:t,applyGlobalChildMode:!1,isVisible:!n,correctArrangement:a},_=this._planInteractionHandler.addOrUpdateExternalPlanObjects(h,d,u,g,i);n||this._planInteractionHandler.endInteraction();const m=this._planInteractionHandler.getPlan().extRef.jsObject,O=[];for(const f of _)f.hasConfiguration()&&O.push(m.getConfigurablePlanObjectForId(f.getId()));await Promise.all(O.map(async f=>{await f.isInitDone()}))}_createSerializedGroupCollection(e){const t=Array.isArray(e)?e:[e],n=[];for(const a of t){const i=typeof a=="string"?a:JSON.stringify(a);n.push(i)}return n}_getFaceTheCameraAngle(e){const t=this._sceneManager.getCameraParameters3d();if(!t?.yaw)return 0;const n=Zt(t.yaw),a=Math.round(n/e)*e;return qt(a)}async renderImagesOfExternalObjectGroup(e){const t=Array.isArray(e)?e:[e],n={},a=this._initData.animateCamera;this._initData.animateCamera=!1;for(const i of t){try{await this._loadExternalObjectGroup(i,!1,!1,!1),await this._selectExternalObjectModule(i.id,null,!0,!0,!1,!1),this.preparePerspectiveImage(),await this._sceneManager.waitForMaterialQueue(),this.updateScene();const s=await this.exportCanvasScreenshot();n[i.id]=s}catch(s){console.error(s)}this.backToPlanner()}for(const i of t)await this.removeExternalObjectGroup(i.id,!1);return this._initData.animateCamera=a,n}async removeExternalObjectGroup(e,t=!1){const n=await this.getPlanModelViewHelper(),a=this._planInteractionHandler.getPlan(),i=n.getExternalObjectComponent(a,e,"");this.getConfiguratorContext().planElementId===i.runtimeId&&this._sceneManager.cancelPlanElementSelection("delete_object"),i.runtimeId!==0&&(t?(this._planInteractionHandler.resumeInteraction(),this._planInteractionHandler.removeObjectWithId(e),this._planInteractionHandler.endInteraction()):(this._planInteractionHandler.startInteraction(),this._sceneManager.deletePlanElementByIds([i.runtimeId]),this._planInteractionHandler.endInteraction())),this.updateScene()}removeExternalObjectRootModule(e){this._planInteractionHandler.startInteraction(),this._planInteractionHandler.removeObjectWithId(e),this._planInteractionHandler.endInteraction(),this.updateScene()}async selectExternalObjectGroup(e){this.getConfiguratorContext().baseContext===b.CONFIGURATOR||this._planInteractionHandler.setShowChildrenOfExternalObject(e,{value:se.OFF},!1),await this._selectExternalObjectGroup(e,!0),this.updateScene()}async selectExternalObjectRootModule(e){const n=this.getConfiguratorContext().baseContext===b.CONFIGURATOR;n||this._planInteractionHandler.setShowChildrenOfExternalObject(e,{value:se.GROUND_COMPONENTS},!1),await this._selectExternalObjectModule(e,null,!n,n,!0,!0),this.updateScene()}async selectExternalObjectSubModule(e,t){const a=this.getConfiguratorContext().baseContext!==b.CONFIGURATOR;await this._selectExternalObjectModule(e,t,a,!0,!0,!0),this.updateScene()}async openOrCloseGeometryOfExternalObject(e,t,n,a){const i=await this.getPlanModelViewHelper(),s=this._planInteractionHandler.getPlan(),o=i.getExternalObjectComponent(s,e,"");if(o?.configurationRuntimeId){const c=n?"open":"close";this._sceneManager.animateElement(o.configurationRuntimeId,"openClose",c,!0,a),this.updateScene()}}async _selectKernelComponent(e){e.configurationHash&&e.configurationType.value===Y.EXTERNAL&&await this._selectExternalObjectModule(e.configurationHash,e.componentId,!0,!0,!0,!1),this.updateScene()}async _selectExternalObjectGroup(e,t){const n=await this.getPlanModelViewHelper(),a=this._planInteractionHandler.getPlan(),i=n.getExternalObjectComponent(a,e,"");i.runtimeId!==0&&(t&&await this._roomlePlannerUiCallback.onBackToPlanner(),await this._sceneManager.selectPlanObject(i.runtimeId))}async _selectExternalObjectModule(e,t,n,a,i,s){const o=await this.getPlanModelViewHelper(),c=this._planInteractionHandler.getPlan(),h=o.getExternalObjectComponent(c,e,t??"");if(h.runtimeId===0)return;const d=this.getConfiguratorContext().baseContext===b.CONFIGURATOR,u=this._getSelectedPlanObjectComponent();let g=!1,_=n;d&&(g=u?.configurationRuntimeId===h.configurationRuntimeId,_=!g,g||this._sceneManager.backToPlanner()),_&&await this._selectPlanObject(h),a&&!g&&await this._roomlePlannerUiCallback.onStartConfiguring(),h.planComponentRuntimeId!==0&&i&&this._sceneManager.selectComponent(h.planComponentRuntimeId,!1),s&&!d&&this._sceneManager.highlightExternalObject(h)}async _selectPlanObject(e){let t=e.runtimeId;const n=W(this._plan.getPlanObjects());for(const a of n)if(a.getConfigurationRuntimeId()===e.planComponentRuntimeId){t=a.getId();break}await this._sceneManager.selectPlanObject(t)}_getSelectedPlanObjectComponent(){const e=this.getConfiguratorContext(),t=e.selectedRuntimeComponentId??e.planObjectId;return this._sceneManager.getObjectComponent(t)}async getExternalObjectGroups(){const e=await this.getPlanModelViewHelper(),t=this._planInteractionHandler.getPlan(),n=[],a=W(e.getExternalObjectGroups(t));for(const i of a)n.push(JSON.parse(i.serializedDefinition));return n}async getExternalRoomInformation(){const e=await this.getPlanModelViewHelper(),t=this._planInteractionHandler.getPlan();return W(e.getExternalRoomInformation(t))}get globalCallbacks(){return this._globalCallback}_executeWithInteraction(e){const t=this._plannerKernelAccess.planInteractionHandler;t.startInteraction();const n=e();return t.endInteraction(),n}addAtticToWall(e,t,n,a){return this._executeWithInteraction(()=>this._plannerKernelAccess.planInteractionHandler.addAttic(e,t,n,a)||null)}removeAttic(e){this._executeWithInteraction(()=>this._plannerKernelAccess.planInteractionHandler.removeElement(e))}setAtticSide(e,t){this._executeWithInteraction(()=>this._plannerKernelAccess.planInteractionHandler.setAtticSide(e,t))}getAttachedAttic(e){const t=e.getAttachedAttics();return t.size()>0?t.get(0):null}updateAtticKneeHeight(e,t){this._executeWithInteraction(()=>this._plannerKernelAccess.planInteractionHandler.setAtticKneeHeight(e,t))}updateAtticWidth(e,t){this._executeWithInteraction(()=>this._plannerKernelAccess.planInteractionHandler.setAtticWidth(e,t))}async executeWithInteraction(e){const t=this._plannerKernelAccess.planInteractionHandler;t.startInteraction();try{const n=e();return n instanceof Promise?await n:n}finally{t.endInteraction()}}pauseInputListeners(){return this._sceneManager.pause()}resumeInputListeners(){return this._sceneManager.resume()}getScenePlanElementLightSources(){return this._sceneManager.scenePlanElementLightSources}setAllLightsOnOff(e){this._sceneManager.setAllLightsOnOff(e)}setLightsOnOffByIds(e,t){this._sceneManager.setLightsOnOffByIds(e,t)}async getPlanObjectForRuntimeId(e){const t=this._planInteractionHandler.getPlan()?.extRef?.jsObject;return Promise.resolve(t.getPlanObjectForId(e)||null)}async rotateByRuntimeId(e,t){return this._sceneManager.rotatePlanElements([e],t),Promise.resolve()}async deleteByRuntimeId(e){return this._sceneManager.deletePlanElements([e]),Promise.resolve()}async moveByRuntimeId(e,t){const n=await this.getPlanObjectForRuntimeId(e);return this._sceneManager.moveElementPosition(n,t),Promise.resolve()}undo(){return this._sceneManager.undo()}redo(){return this._sceneManager.redo()}setHomagIntelligence(e){this._homagIntelligence=e}newPosDataFromId(e){return this._homagIntelligence.getEmulator().newPosDataFromId(e)}sendToOM(e=!0){return this._homagIntelligence.sendToOM(e)}async fetchPrice(e){return this._homagIntelligence.fetchPrice(e)}async getOrderManagerGroupData(e){return this._homagIntelligence.getEmulator().getGroupDataForOrder(e)}getRapiAccess(){return this._rapiAccess}}R([C],L.prototype,"_configuratorContext"),R([C],L.prototype,"_domHelper"),R([C],L.prototype,"_kernelAccessCallback"),R([C],L.prototype,"_plannerKernelAccess"),R([C],L.prototype,"_rapiAccess"),R([C],L.prototype,"_singlePromiseFactory"),R([C],L.prototype,"_roomlePlannerUiCallback"),R([C],L.prototype,"_lifeCycleManager"),R([C],L.prototype,"_dataSyncer"),R([C],L.prototype,"_initData"),R([C],L.prototype,"_idbManager"),R([C],L.prototype,"_globalInitData"),R([C],L.prototype,"_globalCallback"),R([C],L.prototype,"_unitFormatter");class ta extends Yt{_canDrag(e){return!0}}const na=[new z("script-loader",Pn),new z("planner-input-manager",ta,tt.CONTEXT),new z("logger",$t),new z("planner-mesh-generator",Jt),new z("configurator-view-model",Cn,tt.CONTEXT),new z("rapi-access",Qt),new z("global-init-data",en),new z("planner-selection-handler",Bn)];var aa=Object.defineProperty,Sn=(r,e,t,n)=>{for(var a=void 0,i=r.length-1,s;i>=0;i--)(s=r[i])&&(a=s(e,t,a)||a);return a&&aa(e,t,a),a};const Mn="external:root-tag";class at{constructor(e,t){this._externalItems=new Map,this._externalConfigurations=new Map,this._tagIds=[],this._creator_=e,this._articlesPromise=t,this._init()}setEmulator(e){this._emulator=e}_init(){const e=this._globalCallback.onCheckExternalCache;this._globalCallback.onCheckExternalCache=async(t,n)=>{const a=await e(t,n);return a!==null?a:this._onCheckExternalCache(t)},this._globalCallback.onFetchExternalData=this._onFetchExternalData.bind(this)}async _onCheckExternalCache(e){if(e==="/tags/"+Pe(Mn)){const t=await this._processedArticles();return this._tagIds=[...t.keys()].sort((n,a)=>n.localeCompare(a)),Promise.resolve({tag:{id:Pe(Mn),tags:this._tagIds,sort:1}})}for(const t of this._tagIds){if(e==="/tags/"+t){const n=await this._processedArticles();return Promise.resolve({tag:{id:t,label:n.get(t).label,sort:1}})}if(e==="/tags/"+t+"/items"){const a=(await this._processedArticles()).get(t).items;return a.sort((i,s)=>i.label.localeCompare(s.label)),Promise.resolve({items:a})}}return null}_onFetchExternalData(e,t){const n=Array.isArray(t)?t:[t],a=[];for(const i of n){const s=this._configuratorViewModel.getExternalConfigurationById(i);s?a.push(s):this._externalItems.has(i)?a.push(this._externalItems.get(i)):console.warn("ID",i,"is unknown")}return Array.isArray(t)?Promise.resolve(a):Promise.resolve(a[0])}async _processedArticles(){let e=await this._articlesPromise;return e.articles&&(e=e.articles),e.reduce((t,n)=>{const a=n.category||"Uncategorized",i=Pe(a.toLowerCase());t.has(i)||t.set(i,{id:i,label:a,items:[]});const s=t.get(i),{depth:o,width:c,height:h}=n.roots.reduce((g,{attributes:_})=>(_&&_.forEach(m=>{m.id==="mod_Depth"&&(g.depth+=parseInt(m.value,10)/10),m.id==="mod_Width"&&(g.width+=parseInt(m.value,10)/10),m.id==="mod_Height"&&(g.height+=parseInt(m.value,10)/10)}),g),{depth:0,width:0,height:0}),d=o>0&&c>0&&h>0,u=tn({id:n.articleId,uiLabels:{desktop:{line1:n.name,line2:n.desc,line3:d?`${h}x${c}x${o}`:""},mobile:{line1:n.name,line2:d?`${h}x${c}x${o}`:"",line3:n.desc}},label:n.name??"external-objects.no-name",externalObject:!0,configuration:{imageUrl:n.imageUrl}});return this._externalItems.set(u.id,u),s.items.push(u),t},new Map)}}Sn([C],at.prototype,"_globalCallback"),Sn([C],at.prototype,"_configuratorViewModel");/**
154
+ }`};const Wn=async(r,e)=>{const t=[],n=[],a=[],i=[];return await Promise.all(r.map(async s=>{if(s.configurationRuntimeId&&e.kernelInstance?.isExternalPlanObject(s.configurationRuntimeId))i.push([Pe(s.configurationHash),s]),t.push(W(s));else if(s.configurationType?.value!==Y.EXTERNAL){const o=W(s);if(o.configurationHash?a.push(o.configurationHash):o.catalogItemId&&n.push(o.catalogItemId),o.parts){const c=o.configurationHash||o.catalogItemId;o.parts=await e.addUiDataAndPriceToPartList(o.parts,c)}if(o.configuration){const c=await e.getConfigurationData(o.runtimeId);o.configuration=c.configuration}o.data=null,t.push(o)}})),{objects:t,itemIds:n,configurationIds:a,externalConfigurationData:i}},Kn=async(r=[],e=[],t=[],n)=>{const a=t.map(([d,u])=>d),[i,s,o]=await Promise.allSettled([n.getItems(r),n.getConfigurations(e),n.getExternalObjects(a)]),c=[],h=new Map;if(i.status==="fulfilled")for(const d of i.value)h.set(d.id,d);if(o.status==="fulfilled"&&o.value?.length>0)for(const{data:d}of o.value)h.set(d.id,d);if(s.status==="fulfilled")for(const d of s.value)h.set(d.id,d),c.push(d.rootComponentId);else console.warn("Could not fetch configuration for data property. This happens when a configuration has not been saved yet");return{data:h,rootComponentIds:c}},he=async(r,e,t)=>{const{objects:n,itemIds:a,configurationIds:i,externalConfigurationData:s}=await Wn(r,e),{data:o,rootComponentIds:c}=await Kn(a,i,s,t),h=await t.getComponents(c),d=new Map;for(const u of h)d.set(u.id,u);for(const u of n){const g=u.catalogItemId||u.configurationHash,_=o.get(u.catalogItemId)||o.get(u.configurationHash)||null;if(_&&!_.label&&d.has(_.rootComponentId)){const m=d.get(_.rootComponentId);_.label=m.label}_&&!_.label&&(_.label=g),u.data=_}return n};class Nn extends S{constructor(){const e=new Le(1e3,1e3,8,8);e.rotateX(-Math.PI/2);const t=new H;new vt().load(l,a=>{a.wrapS=Ye,a.wrapT=Ye;const i=5;a.repeat.set(1e3/i,1e3/i),t.map=a,t.alphaTest=.3,t.transparent=!0}),super(e,t),this.name="2d paper background",this.position.set(0,-.1,0),this.layers.set(D.BACKGROUND),this.userData.ignoreElementHit=!0}}class Me extends ln{get cameraControl(){return this._cameraControl}}class vn extends Me{get cameraControl(){return this._cameraControl}resetCameraOnPlanCompletelyLoaded(e){this.cameraControl.zoomToFitBounds(Ie(e,this.cameraControl.domHelper.element.clientWidth,this.cameraControl.domHelper.element.clientHeight,1.1),!0)}externalApiResetCameraPosition(e){this.cameraControl.zoomToFitBounds(Ie(e,this.cameraControl.domHelper.element.clientWidth,this.cameraControl.domHelper.element.clientHeight,1.1),!0)}resetCameraOnSwitchTo2d(e){this.cameraControl.zoomToFitBounds(Ie(e,this.cameraControl.domHelper.element.clientWidth,this.cameraControl.domHelper.element.clientHeight,1.1),!0)}updateCameraOnDrawWalls(e){this.cameraControl.zoomToFitBounds(e,!1,!0)}updateCameraOnPlanElementInsertedOutsideCurrentCameraView(e){this.cameraControl.zoomToFitBounds(e,!1,!0)}updateCameraOnPlanElementInsertedInsideCurrentCameraView(e){}updateCameraOnPlanElementDraggedOutsidePlanBounds(e){this.cameraControl.zoomToFitBounds(e,!1,!0)}updateCameraOnPlanElementRemoved(e){}updateCameraOnBackToPlanner(e,t,n){this.cameraControl.zoomToFitBounds(e,!1,!0)}resetCameraOnEnableWallDrawing(e){this.cameraControl.zoomToFitBounds(e,!1,!0)}}class ye extends Me{get cameraControl(){return this._cameraControl}resetCameraOnPlanCompletelyLoaded(e){this.cameraControl.updateAndReset(e,!0)}externalApiResetCameraPosition(e){this.cameraControl.updateAndReset(e,!0)}resetCameraOnSwitchTo3d(e){this.cameraControl.updateAndReset(e,!1)}disablePanningOnShiftRelease(){this.cameraControl.disablePanning()}enablePanningOnShiftClick(){this.cameraControl.enablePanning()}updateCameraOnDrawWalls(e){this.cameraControl.zoomToFitBounds(e,!0)}updateCameraOnPlanElementInsertedOutsideCurrentCameraView(e){this.cameraControl.zoomToFitBounds(e,!1)}updateCameraOnPlanElementDraggedOutsidePlanBounds(e){this.cameraControl.adjustToBoundsWithoutChangingDistance(e)}updateCameraOnPlanElementInsertedInsideCurrentCameraView(e){this.cameraControl.adjustToBoundsWithoutChangingDistance(e)}updateCameraOnPlanElementRemoved(e){this.cameraControl.adjustToBoundsWithoutChangingDistance(e)}async updateCameraOnBackToPlanner(e,t,n){if(!n)return;this.cameraControl.setObjectRotation(0),Math.abs(0-n.targetX)<=.01&&Math.abs(0-n.targetY)<=.01&&Math.abs(0-n.targetZ)<=.01?await this.cameraControl.updateAndReset(e,!0):await this._cameraControl.setToState(t,n)}resetCameraOnEnableWallDrawing(e){this.cameraControl.updateAndReset(e,!0)}async externalApiMoveCamera(e){await this.cameraControl.moveCamera(e),this._onCameraChanged()}}class zn extends Me{get cameraControl(){return this._cameraControl}resetCameraOnPlanCompletelyLoaded(e){this.cameraControl.updateCamera()}externalApiResetCameraPosition(e){this.cameraControl.updateCamera()}updateCameraOnDrawWalls(e){this.cameraControl.updateCamera()}updateCameraOnPlanElementInsertedOutsideCurrentCameraView(e){this.cameraControl.updateCamera()}updateCameraOnPlanElementInsertedInsideCurrentCameraView(e){this.cameraControl.updateCamera()}updateCameraOnPlanElementDraggedOutsidePlanBounds(e){this.cameraControl.updateCamera()}updateCameraOnPlanElementRemoved(e){this.cameraControl.updateCamera()}updateCameraOnBackToPlanner(e,t,n){this.cameraControl.updateCamera()}resetCameraOnEnableWallDrawing(e){this.cameraControl.updateCamera()}resetCameraOnSwitchToFirstPerson(){this.cameraControl.updateCamera()}}class Vn{constructor(e,t,n){this._sceneEventHandler=e,this._roomleRenderer=t,this._planViewModel=n}_processViewModel(e,t){e instanceof A&&e.getKernelObject().getAttachedAttics?.().size()>0?e.getBoundingBox().children.forEach(a=>{a.isChildPlanObject||t.add(a)}):((e instanceof be||e instanceof q)&&e.getTopViewContainer()&&t.add(e.getTopViewContainer()),e.getObject()?.children&&e.getObject().children.forEach(a=>{a.isChildPlanObject||t.add(a)}))}_processSelectedPlanElementIds(e){(this._sceneEventHandler?.getSelectedIds()||[]).forEach(n=>{const a=this._planViewModel.getPlanObjectForId(n);a&&this._processViewModel(a,e)})}_highlightPlanElementsBase(e,t){let n=new Set;t&&this._processViewModel(t,n),e?.forEach(a=>{const i=this._planViewModel.getPlanObjectForId(a);i&&this._processViewModel(i,n)}),this._processSelectedPlanElementIds(n),this._roomleRenderer?.highlightObjects(Array.from(n))}highlightPlanElements(e){this._highlightPlanElementsBase(e)}highlightPlanElement(e){this._highlightPlanElementsBase(void 0,e)}clearHighlighting(){this._highlightPlanElementsBase()}}function Xn(r,e,t,n,a,i,s,o=!0,c=!1){if(!(e.cameraControl instanceof G)||e.cameraControl.isLocked()&&o)return;const h=[],{x:d,y:u}=r.getClientDimensions(),g=a.getWallPlanObjectViewModels(),_=e.cameraControl.getKernelZoomFactor(),m=e.cameraControl.getCamera();for(const O of g){const f=O.getWallDimension(_,d,u);f.isCurrentlyDrawn=n.isCurrentlyDrawing&&O.getPlanElement().getTo().extRef.jsObject===a.latestNodePlanObjectViewModel;const{isVectorWall:F}=O.getKernelObject();f.length<=0&&!F||(Zn(f,m,d,u),f.attic&&qn(f.attic,m,d,u),f.lengthFormatted=i.formatMMValueToUnitString(f.length),c&&Yn(f,s),h.push(wt(f)))}t.onUpdateWallDimensions(h)}function Zn(r,e,t,n){r.fromPosition2d=p(r.fromPosition3d,e,t,n),r.toPosition2d=p(r.toPosition3d,e,t,n),r.textPosition2d=p(r.textPosition3d,e,t,n),r.fromWithoutPadding=p(r.fromWithoutPadding,e,t,n),r.toWithoutPadding=p(r.toWithoutPadding,e,t,n)}function qn(r,e,t,n){r.textPosition2d=r.fromPosition3d?p(r.textPosition3d,e,t,n):void 0,r.fromPosition2d=r.fromPosition3d?p(r.fromPosition3d,e,t,n):void 0,r.toPosition2d=r.toPosition3d?p(r.toPosition3d,e,t,n):void 0,r.atticCenterPosition2d=r.atticCenterPosition3d?p(r.atticCenterPosition3d,e,t,n):void 0,r.wallCenterPosition2d=p(r.wallCenterPosition3d,e,t,n),r.labelCPosition2d=p(r.labelCPosition3d,e,t,n),r.labelHeightPosition2d=p(r.labelHeightPosition3d,e,t,n),r.shiftedWallCenter2d=p(r.shiftedWallCenter3d,e,t,n),r.heightAt2mPosition2d=p(r.heightAt2mPosition3d,e,t,n),r.attic2mCornerFrom2d=p(r.attic2mCornerFrom3d,e,t,n),r.attic2mCornerto2d=p(r.attic2mCornerto3d,e,t,n)}function Yn(r,e){console.log("Wall dimension",r);const t=new Oe(.1,32,16),n=new H({color:16711680}),a=new S(t,n);a.position.copy(r.fromPosition3d);const i=new S(t,n);i.position.copy(r.toPosition3d);const s=new S(t,new H({color:65280}));if(s.position.copy(r.textPosition3d),e.wallPoints.add(a),e.wallPoints.add(i),e.wallPoints.add(s),r.attic){const o=new S(t,new H({color:255}));r.attic.fromPosition3d&&o.position.copy(r.attic.fromPosition3d);const c=new S(t,new H({color:16711935}));r.attic.toPosition3d&&c.position.copy(r.attic.toPosition3d);const h=new S(t,new H({color:16776960}));r.attic.atticCenterPosition3d&&h.position.copy(r.attic.atticCenterPosition3d),e.wallPoints.add(o),e.wallPoints.add(c),e.wallPoints.add(h)}}const st=class st{static hasNativeClipboardWriteSupport(){return!!(navigator.clipboard&&typeof navigator.clipboard.writeText=="function")}static async hasNativeClipboardReadSupport(){return navigator.clipboard&&typeof navigator.clipboard.readText=="function"?(await navigator.permissions.query({name:"clipboard-read"})).state!=="denied":!1}static async copy(e){if(this.hasNativeClipboardWriteSupport())try{await navigator.clipboard.writeText(e)}catch(t){console.warn("Native clipboard writeText failed, attempting localStorage fallback.",t)}try{localStorage.setItem(this.LOCAL_STORAGE_KEY,e)}catch(t){console.error("Failed to copy text using localStorage:",t)}}static async paste(){if(await this.hasNativeClipboardReadSupport())try{return await navigator.clipboard.readText()}catch(e){console.warn("Native clipboard readText failed, attempting localStorage fallback.",e)}try{const e=localStorage.getItem(this.LOCAL_STORAGE_KEY);return e===null?"":e}catch(e){throw console.error("Failed to paste text using native clipboard and localStorage fallback:",e),new Error("Failed to paste text. Both clipboard and localStorage methods failed.")}}};st.LOCAL_STORAGE_KEY="clipboardManagerFallback";let Ue=st;var $n=Object.defineProperty,De=(r,e,t,n)=>{for(var a=void 0,i=r.length-1,s;i>=0;i--)(s=r[i])&&(a=s(e,t,a)||a);return a&&$n(e,t,a),a};function We(r,e){const t=On(r),n=e?.lockPlan,a=r&&"getPlanElement"in r&&r.getPlanElement()&&"getAttachedWall"in r.getPlanElement();return!!(n&&(t==="wall"||t==="floor"||a))}const Jn="rml_plans",Ae={INTERIOR:"interior",EXTERIOR:"exterior"},wn=r=>["altKey","ctrlKey","shiftKey","metaKey"].reduce((e,t)=>(r[t]&&e++,e),0);class de extends mn{constructor(e,t,n,a){super(e,t,a),this._itemsLoadingStatePromises=[],this._staticItemGuard=new Re,this._completelyLoaded=!1,this._configurableItemGuard=new Re,this._planCompletelyLoadedGuard=new Re,this.currentSelection=null,this._paperBackground=null,this._cameraState=null,this._debugSpheres={wallPoints:new Ce,constructionElementsPoints:new Ce,floorPoints:new Ce},this._stopRendering=!0,this._configureInRoom=!!this._initData.configureInRoom,this._configuratorContext.baseContext=b.PLANNER,this._roomlePlannerCallback=n,this._plannerMeshGenerator.maxAnisotropy=this._renderer.capabilities.getMaxAnisotropy(),this._plannerMeshGenerator.maxTextures=this._renderer.capabilities.maxTextures,this._plannerSceneEventHandler=new Se(e,this._scene,this.cameraBehaviour.cameraControl.getCamera(),this._getInputManager()),this._roomleRenderer?.switchToPlanner(oe.Mode3D),this._imageRenderer.switchToPlannerSettings(),this._planElementHighlighter=new Vn(this._plannerSceneEventHandler,this._roomleRenderer,this._getViewModel()),this._plannerSceneEventHandler.addEventListener(y.STATE_CHANGED,({state:i,oldState:s})=>{s===te.ROTATE&&i!==s&&this._roomlePlannerUiCallback.onRotationCancel(),i===te.ROTATE||i===te.DRAG||i===te.MEASURE||i===te.DRAW?(this.cameraBehaviour.cameraControl.lock(),this._onCameraMove()):(this.cameraBehaviour.cameraControl.unlock(),this._onCameraIdle())},this),this._plannerSceneEventHandler.addEventListener(y.INTERACTION,()=>this._renderWithoutShadowsAndAO(),this),this._plannerSceneEventHandler.addEventListener(y.ACTIVATE_PLAN_ELEMENT,i=>this._activateElement(i),this),this._plannerSceneEventHandler.addEventListener(y.SELECT_PLAN_ELEMENT,i=>{this._activateElement(i);const s=i.planElementViewModel;this._sendElementMeasurements(),s instanceof N&&this._initData.debug&&console.log(s.getGLBUrl()),We(s,this._initData)||this._planElementHighlighter.highlightPlanElement(s),this._onSelectionChange(s),this._renderWithoutShadowsAndAO()},this),this._plannerSceneEventHandler.addEventListener(y.DESELECT_PLAN_ELEMENT,({planElementViewModel:i,reason:s})=>{this._planElementHighlighter.clearHighlighting(),this._onSelectionCancel(i,s),this._roomlePlannerUiCallback.onSelectionCancel(s),this._renderWithoutShadowsAndAO()},this),this._plannerSceneEventHandler.addEventListener(y.BEFORE_DRAG_START,()=>{this.cameraBehaviour.cameraControl.lock()},this),this._plannerSceneEventHandler.addEventListener(y.DRAG_START,({planElementViewModel:i})=>{this._getKernelAccess().planInteractionHandler.startInteraction(),this._sendElementMeasurements(),i instanceof A&&this._sendWallDimensions(),this._requestRender(),this._dragStartBounds=this.getBounds()},this),this._plannerSceneEventHandler.addEventListener(y.DRAG_MOVE,({planElementViewModel:i})=>{this.cameraBehaviour.cameraControl.checkNearFarDistance(i.getPosition()),this._requestRender()},this),this._plannerSceneEventHandler.addEventListener(y.DRAG_END,async({planElementViewModel:i})=>{const s=this._getKernelAccess().planInteractionHandler;s.endInteraction(),this.cameraBehaviour.cameraControl.unlock();const o=this._getDragPosition(i.getPosition());o&&s.moveElementTo(i.getPlanElement(),w(o)),this.updateEnvironment(this.getBounds(),!0),this._renderEverything();const c=this.getPlanObject(i.getId());let h;c&&(h=await he([c],this._plannerKernelAccess,this._rapiAccess)),this._roomlePlannerUiCallback.onPlanElementChanged($.MOVED,h.length?h[0]:{...c,data:null});const d=i instanceof A||i instanceof j||i instanceof X;!this._cameraBehaviourState.isWithinPlanBounds(i.getPosition(),this.getBounds())&&!d&&this.plannerCameraBehaviour.updateCameraOnPlanElementDraggedOutsidePlanBounds(this.getBounds())},this),this._plannerSceneEventHandler.addEventListener(y.DRAG_CANCEL,()=>{this.cameraBehaviour.cameraControl.unlock()},this),this._plannerSceneEventHandler.addEventListener(y.ADD_MEASUREMENT_LINE_START,()=>{this.cameraBehaviour.cameraControl.lock()},this),this._plannerSceneEventHandler.addEventListener(y.DRAG_MEASUREMENT_LINE,()=>{this._roomlePlannerUiCallback.onUpdateMeasurementLineDimensions([])},this),this._plannerSceneEventHandler.addEventListener(y.ADD_MEASUREMENT_LINE_END,()=>{this.cameraBehaviour.cameraControl.unlock(),this._roomlePlannerUiCallback.onMeasurementLineStateChange(!1)},this),this._plannerSceneEventHandler.addEventListener(y.DRAWING_START,()=>{this._setKernelZoomFactor(),this._renderWithoutShadowsAndAO(),this._roomleRenderer?.setGroundShadow(!1)},this),this._plannerSceneEventHandler.addEventListener(y.DRAW,()=>this._renderWithoutShadowsAndAO(),this),this._plannerSceneEventHandler.addEventListener(y.DRAWING_END,()=>{this._renderWithoutShadowsAndAO(),this._roomleRenderer?.setGroundShadow(!0)},this),this._getKernelAccess().addPlannerListener(this),this._plannerMeshGenerator.setMaterialLoadedListener(()=>{this._configurableItemGuard.resolve(),this._requestRender()}),window.onbeforeunload=this.clearScene.bind(this),this._getInputManager().addEventListener(v.ZOOM_IN,this._renderListener,this),this._getInputManager().addEventListener(v.ZOOM_OUT,this._renderListener,this),this._getInputManager().addEventListener(v.DOWN,this._onMouseDown,this),this.disableConfiguratorEvents(),a!==P.CAMERA_FP&&this.enablePlannerEvents(),setTimeout(()=>this._updatePaperBackground(),0),this._initData.debug&&(this._debugSpheres.wallPoints.name="Walls debug points",this._debugSpheres.constructionElementsPoints.name="Construction elements debug points",this._debugSpheres.floorPoints.name="Floor debug points",this._scene.add(this._debugSpheres.wallPoints),this._scene.add(this._debugSpheres.constructionElementsPoints),this._scene.add(this._debugSpheres.floorPoints))}get configuratorContext(){return this._configuratorContext}get hasSingleRoom(){const e=this._getViewModel().getFloorPlanObjectViewModels();return new Set(e.map(n=>n.getId())).size===1}get scenePlanElementLightSources(){const e=[];return this._scene.traverse(t=>{if("getAllLightSources"in t&&typeof t.getAllLightSources=="function"){const n=t.getAllLightSources();n.size>0&&e.push(n)}}),e}setAllLightsOnOff(e){for(const t of this.scenePlanElementLightSources)for(const n of Array.from(t.values()))n.setLightOnOff(e);this._renderEverything()}setLightsOnOffByIds(e,t){for(const n of this.scenePlanElementLightSources)for(const a of Array.from(n.values()))e.includes(a.lightSourceId)&&a.setLightOnOff(t);this._renderEverything()}_activateElement({planElementViewModel:e},t=()=>{}){const n=this._plannerSceneEventHandler.isDragIn()?e:null;this._sendElementMeasurements(n),e instanceof N&&this._initData.debug&&console.log(e.getGLBUrl()),We(e,this._initData)||this._planElementHighlighter.highlightPlanElement(e),t(),this._renderWithoutShadowsAndAO()}planCleared(){}planHistoryStateChanged(){if(this._sendRoomMeasurements(),this._completelyLoaded){const{configuratorId:e}=this._globalInitData,n=(this._plannerKernelAccess?.planInteractionHandler).getPlan()?.getPlanXML(!1,2),a=this._idbManager.getKey(Et(),e,this._initData.id);this._idbManager.setValue(a,n,this._idbManager.configStore)}}_getViewModel(){return this._viewModel||(this._viewModel=new pn(this._creator_),this._viewModel.setRequestRenderCallback(()=>this._renderEverything()),this._viewModel.setRequestRenderSceneUpdateCallback(()=>this._roomleRenderer?.clearCache()),this._viewModel.setInvalidateRenderCallback(()=>this._roomleRenderer?.forceShadowUpdates(!0))),this._viewModel}_getDragPosition(e){if(!this._plannerSceneEventHandler.isDragIn())return null;const t=this._dragStartBounds?this._dragStartBounds:this.getBounds(),n=t.getCenter(new E),a=e.distanceTo(n),i=t.getSize(new E),o=Math.max(i.x,i.z)+3;if(a>o){const c=new E().subVectors(e,n).normalize();return n.clone().add(c.multiplyScalar(o))}return null}_hideAllMeasurementsNodeOnElementChange(e){this._getViewModel().getMeasurementLineObjectViewModels().forEach(n=>n.hideDraggableNodes()),e instanceof j&&e.showDraggableNodes()}_onSelectionChange(e){this._hideAllMeasurementsNodeOnElementChange(e);const t={};if(e instanceof N&&(t.item=e.getRapiItem(),t.staticItemRuntimeId=e.getPlanElement().getId(),this._configuratorUiCallbacks.onUpdateParameters([])),e instanceof q&&(t.staticItemRuntimeId=e.getPlanElement().getId()),e instanceof k){const s=e.getId(),o=this.getRootPlanObjectId(s),c=this._getViewModel().getPlanObjectForId(o);t.configurationRuntimeId=c.getConfigurationRuntimeId()}if(e instanceof A){const s=this.cameraBehaviour.cameraControl.getKernelZoomFactor(),{clientWidth:o,clientHeight:c}=this._domHelper.element;t.wall=e.getWallDimension(s,o,c)}e instanceof j&&(t.measurementLine=e.getMeasurementLineDimension()),e instanceof _e&&(t.staticItemRuntimeId=e.getPlanElement().getId());let n=On(e);const i=(async()=>{const s={};if(e instanceof N&&(s.item=e.getRapiItem(),s.staticItemRuntimeId=e.getPlanElement().getId()),e instanceof k){await e.isInitDone();const o=e.getConfigurationRuntimeId();this._getKernelAccess().updatePlanObjectDependencies(o);const c=e.getPlanObject().getCatalogItemId();let h=c;h||(h=this._getKernelAccess().kernelInstance.getHashOfConfiguration(o));const d=this._getKernelAccess().kernelInstance.isExternalPlanObject(o);if(d){const g=this.getRootPlanObjectId(e.getId()),_=this._getViewModel().getPlanObjectForId(g);this._planObjectSelectionChanged(_.getConfigurationRuntimeId(),e.getRootComponentRuntimeId())}this._configuratorContext.planObjectId=o,this._configuratorContext.planElementId=e.getId(),this._configuratorContext.rootComponentId=e.getRootComponentRuntimeId();let u;if(!d)if(c&&ce(c)){const g=await this._rapiAccess.getItem(c);s.item=g,u=g.rootComponentId?g.rootComponentId:null}else try{const g=await this._rapiAccess.getConfiguration(h);s.configuration=g,u=g.rootComponentId?g.rootComponentId:null}catch{console.warn("Could not get RAPI configuration for kernel hash "+h+", saving configuration...");const _=await this._getKernelAccess().getConfigurationData(o),m=await this._rapiAccess.saveConfiguration(_);s.configuration=m,u=m.rootComponentId?m.rootComponentId:null}if(u){const g=await this._rapiAccess.getComponent(u);s.component=g}s.configurationRuntimeId=o,n="configuration"}return s.planElementId=e.getId(),le(s)})();if(this.currentSelection=le(t),this._sendElementMeasurements(),this._sendPlanObjectPositions(),e instanceof k){const s=e.getConfigurationRuntimeId();s&&s!==-1&&this._getKernelAccess().kernelInstance.isExternalPlanObject(s)&&(n="external-configuration",t.externalConfigurationType="tc-config")}this._roomlePlannerUiCallback.onSelectionChange(le(this._plannerSceneEventHandler.getSelectionMode()),le(n),le(t),i,e),(e instanceof A||e instanceof X)&&(this._getViewModel().getNodePlanObjectViewModels().forEach(s=>s.show()),this._updateNodeSize()),this._renderWithoutShadowsAndAO()}_onSelectionCancel(e,t){this._getViewModel().getNodePlanObjectViewModels().forEach(n=>n.hide()),this._renderWithoutShadowsAndAO(),this.resetConfiguratorContext(t),this.cancelComponentSelection(!1,t),this._handleMeasurementLineDraggablePoints(e),this.currentSelection=null}_handleMeasurementLineDraggablePoints(e){this._getViewModel().getMeasurementLineObjectViewModels().forEach(t=>{t.hideDraggableNodes(),t.deselectAllDraggablePoints()}),e instanceof j&&(e.deselectAllDraggablePoints(),e.currentPoint=null)}resetConfiguratorContext(e){try{this._configuratorContext.planObjectId&&this.getPlanObject(this._configuratorContext.planElementId).configurationType?.value===Y.EXTERNAL&&this.notifyPlannerOnComponentSelectionCancel(!0,e)}catch(t){console.error(t)}this._configuratorContext.planObjectId=0,this._configuratorContext.planElementId=0,this._configuratorContext.rootComponentId=0,this._configuratorContext.dockingRootComponentId=0}_setupScene(e,t){super._setupScene(e,t,!0),this._initData.legacyLight&&(this._lightSetting=new In(this._scene,this._lightSetting)),this._initData.moc||this._addSky(),t||this._setEnvironment(new cn(this._scene,this._environment,St(this._initData.colors.DEFAULT_BACKGROUND)))}onBeforeRender(){this.cameraBehaviour.cameraControl instanceof B&&He(this.cameraBehaviour.cameraControl.getCamera(),this._getViewModel().getWallPlanObjectViewModels())&&this._roomleRenderer?.forceShadowUpdates(!0)}_getInputManager(){return this._plannerInputManager}createCameraControl(e,t){this.setMode(e)}startViewing(){this._configuratorContext.baseContext=b.GLB_VIEWER;const e=this._plannerSceneEventHandler.getSelectedIds();if(e.length===1){const t=this._getViewModel().getPlanObjectForId(e[0]);this._setCameraPosition();const n=this.cameraBehaviour.cameraControl.getCurrentCameraParameters();this._changeCameraBehaviour(new bn(this._getCameraControl3D(n),this._cameraBehaviourState)),this.cameraBehaviour.cameraControl instanceof B&&this.cameraBehaviour.cameraControl.setObjectRotation(t.getPlanElement().rotation),this._configureInRoom||this._getViewModel().hideAllExcept(t.getId()),this.cameraBehaviour.updateCameraOnItemLoaded(this.getBounds()).then(()=>{this.updateEnvironment(this.getBounds(),!0)})}this.disablePlannerEvents(),this.updateScene()}startConfiguring(){this._configuratorContext.baseContext=b.CONFIGURATOR;let{planElementId:e}=this._configuratorContext;e=this.getRootPlanObjectId(e),this._configuratorContext.planElementId!==e&&this.selectPlanObject(e),this._selectExternalObjectModule();const t=this._getViewModel().getPlanObjectForId(e);this._setCameraPosition();const n=this.cameraBehaviour.cameraControl.getCurrentCameraParameters();this._changeCameraBehaviour(new nt(this._getCameraControl3D(n),this._cameraBehaviourState));let a=0,i=0;if(t){this.setRootComponentId(t.getRootComponentRuntimeId());const c=t.getPlanElement().getRotationToPreferredFront();a=c.rotationRoundTo90deg,i=c.lookAtSide.value===Mt.LEFT?-1:1,this._componentRaycastHelper?.setObject(t.getObject())}const s=t?.getConfigurationRuntimeId();this._configuratorContext.planObjectId!==s&&(this._configuratorContext.planObjectId=s),this._plannerSceneEventHandler.removeSelection(),this._planElementHighlighter.clearHighlighting(),this._configureInRoom||this._getViewModel().hideAllExcept(e),this.scenePlanElementLightSources.length>0&&this.toggleInteriorLightsSceneSettings(!1),this.configuratorCameraBehaviour.resetCameraOnStartConfiguring(this.getBounds(),n,a,i).then(()=>{this.updateEnvironment(this.getBounds(),!0)}),this.setEventHandlerObject(t.getContainer()),this.disablePlannerEvents(),this.enableConfiguratorEvents(),this._roomleRenderer?.switchToConfigurator(),this._imageRenderer.switchToConfiguratorSettings(),this.updateScene(),this._getKernelAccess().updatePlanObjectDependencies(s),this._getKernelAccess().requestPartListAndUpdatePricesOfParts(),this._getKernelAccess().planObjectUpdated(s,!1),this._plannerKernelAccess?.planInteractionHandler?.startInteraction()}_setCameraPosition(){this._cameraState=this.cameraBehaviour.cameraControl.getCurrentCameraParameters()}_resetCameraPosition(e){if(this.cameraBehaviour.cameraControl instanceof B){if(!this._cameraState)return;this.plannerCameraBehaviour.updateCameraOnBackToPlanner(this.getBounds(),e,this._cameraState)}}async selectPlanObject(e){if(this._plannerSceneEventHandler.getSelectedIds().includes(e))return;e=this.getRootPlanObjectId(e);const n=this._getViewModel().getPlanObjectForId(e);await this._plannerSceneEventHandler.selectPlanElement(n)}backToPlanner(){if(this._configuratorContext.baseContext===b.PLANNER)return;this._configuratorContext.baseContext===b.CONFIGURATOR&&(this._plannerKernelAccess?.planInteractionHandler?.endInteraction(),this._getKernelAccess().kernelInstance.getPlanObject(this.currentSelection?.configurationRuntimeId??0)?.externalObject&&this.notifyPlannerOnComponentSelectionCancel(!0,"isolation_mode_cancelled")),this._configuratorContext.baseContext=b.PLANNER;const e=this.cameraBehaviour.cameraControl.getCurrentCameraParameters(),t=this._getViewModel().cameraType;this._changeCameraBehaviour(t===P.CAMERA_3D||t===P.CAMERA_FP?new ye(this._getCameraControl3D(e),this._cameraBehaviourState):new vn(this._getCameraControl2D(),this._cameraBehaviourState)),this.scenePlanElementLightSources.length>0&&this.toggleInteriorLightsSceneSettings(!0),this._resetCameraPosition(e),this._getViewModel().showAll(),this.setEventHandlerObject(this._scene),this.enablePlannerEvents();const n=this.cameraBehaviour.cameraControl instanceof B||this.cameraBehaviour.cameraControl instanceof J;this._getViewModel().setCameraType(n?P.CAMERA_3D:P.CAMERA_2D),this.disableConfiguratorEvents(),this._roomleRenderer?.switchToPlanner(this.cameraBehaviour.cameraControl instanceof B?oe.Mode3D:oe.Mode2D),this._imageRenderer.switchToPlannerSettings(),this.updateScene()}_getYRotationOfObject(e){let t=e.getWorldDirection(new E).clone();t.y=0,t.lengthSq()<.01&&(t=new E(0,1,0),t.applyQuaternion(e.quaternion),t.y=0),t.normalize();let n=Math.asin(t.x);return t.z<0&&(n=Math.PI-n),n<0&&(n+=Math.PI*2),n}loadStaticPlanObjects(){const e=new Map;this._getViewModel().getStaticPlanObjectViewModels().forEach(t=>{const n=t.getPlanObject();e.has(n.getCatalogItemId())?e.get(n.getCatalogItemId()).push(t):e.set(n.getCatalogItemId(),[t])}),this._rapiAccess.getItems(Array.from(e.keys())).then(t=>{const n=[];t.forEach(a=>{this._getKernelAccess().catalogItemLoaded(a),e.get(a.id).forEach(i=>{n.push(new Promise((s,o)=>{i.setRapiItem(a).then(()=>{this._requestRender(),s()},o)}))})}),Promise.all(n).then(()=>this._staticItemsLoaded())})}requestCatalogItem(e){this._rapiAccess.getItem(e).then(t=>{this._getKernelAccess().catalogItemLoaded(t)})}_staticItemsLoaded(){this._requestRender(),this._staticItemGuard.resolve(),this._roomlePlannerUiCallback.onItemsLoaded()}preload(e){this._planId=e;const t=this._localStorageHelper.getItem(this._planId,Jn);t&&this._loadGLTF(t).then(n=>{this._preloadScene=n,this._preloadScene&&this._scene.add(this._preloadScene),this._requestRender()})}planXMLLoaded(e){this.endPlanConstruction(e),this.loadStaticPlanObjects()}_activateCeilingLight(){this._getViewModel().handleInitialLights(this._renderer.capabilities.maxTextures,this._roomleRenderer.sceneRenderer.getQualityLevel()),this._getViewModel().handleCeilingLights()}planCompletelyLoaded(e){this._stopRendering=!1,this._renderEverything(),setTimeout(()=>this._planCompletelyLoadedGuard.resolve(),0),this.scenePlanElementLightSources.length>0&&(this.toggleInteriorLightsSceneSettings(!0),this._activateCeilingLight()),this._getViewModel().getNodePlanObjectViewModels().forEach(t=>t.hide()),this._getViewModel().getMeasurementLineObjectViewModels().forEach(t=>t.hideDraggableNodes())}handlerSwitchedPlans(e,t){if(this._completelyLoaded=!1,this._roomlePlannerUiCallback.onHandlerSwitchedPlans(),this._getViewModel().setReference(t),this._getKernelAccess().coupleReferences(this._getViewModel(),t),this._getViewModel().setPlannerSceneEventHandler(this._plannerSceneEventHandler),this._getViewModel().setGeometriesMergedListener(()=>{this._renderEverything()}),this._plannerSceneEventHandler.setPlanViewModel(this._getViewModel()),e&&this.clearScene(),!this._initData.moc){this._addSky();const a=new Le(1e3,1e3);a.rotateX(-Math.PI/2);const i=yt.createMeshStandardMaterial({color:"#f0f0f0",roughness:1,metalness:0,depthWrite:!1}),s=new S(a,i);s.name="Ground",s.position.y=-.01,s.userData.isFloor=!0,this._scene.add(s)}this._setCeiling(),this._staticItemGuard.reset(),this._configurableItemGuard.reset(),this._planCompletelyLoadedGuard.reset();const n=this._plannerMeshGenerator.materialQueue.length>0?this._configurableItemGuard.wait():Promise.resolve();Promise.all([this._staticItemGuard.wait(),n,this._planCompletelyLoadedGuard.wait()]).then(this._itemsLoaded.bind(this))}async _itemsLoaded(){const e=this._getViewModel().getCorePlan();if(this._roomleRenderer){const t=Dt(e.getBounds());this._roomleRenderer.updateBounds(t),this._imageRenderer.updateBounds(t)}await Promise.allSettled(this._itemsLoadingStatePromises),this._roomlePlannerUiCallback.onCompletelyLoaded(),this.updateEnvironment(this.getBounds(),!0),this._renderEverything(),this._configuratorContext.baseContext===b.PLANNER&&this.plannerCameraBehaviour.resetCameraOnPlanCompletelyLoaded(this.getBounds()),this._completelyLoaded=!0,this._readyForRender()}beginPlanConstruction(e){}addPlanMesh(e,t,n,a,i,s,o){}endPlanConstruction(e){this._renderLoopFunction=()=>{this._scene.add(this._getViewModel().getConstructionGroup()),this._scene.add(this._getViewModel().getCeilingGroup()),this._scene.add(this._getViewModel().getFloorGroup()),this._scene.add(this._getViewModel().getMeasurementLineGroup()),this._scene.add(this._getViewModel().getWallAtticsGroup()),this._isInteriorLightActive&&this._createCeilingLightGroup(),this._lightSetting?.needsBounds()&&this._lightSetting.updateBounds(this._getViewModel().getBoundingBox()),this._scene.remove(this._preloadScene)}}async addPlanObjectToScene(e){if(!e)return Promise.resolve();let t,n;try{const a=new Promise((h,d)=>(t=h,n=d));this._itemsLoadingStatePromises.push(a);const i=e.getContainer();At(i),this._scene.add(i),this._plannerSceneEventHandler.isDragIn()&&(this._plannerSceneEventHandler.addComponentDragInHandler(e),this._requestRender()),this._roomlePlannerUiCallback.onPlanChanged(),await e.isInitDone(),this.updateEnvironment(this.getBounds()),this._renderEverything();const s=this.getPlanObject(e.getId());let o;s&&(o=await he([s],this._plannerKernelAccess,this._rapiAccess)),this._roomlePlannerUiCallback.onPlanElementChanged($.ADDED,o.length?o[0]:{...s,data:null});const c=e instanceof k||e instanceof N;this._initData.featureFlags.interiorLights&&(Un(e,this._getViewModel(),this._isInteriorLightActive),this.scenePlanElementLightSources.length>0&&this.toggleInteriorLightsSceneSettings(!0)),c&&!this._plannerSceneEventHandler.isDragIn()&&this.cameraBehaviour instanceof Me&&(Lt(this.cameraBehaviour.cameraControl.getCamera(),e.getBounds())?this.plannerCameraBehaviour.updateCameraOnPlanElementInsertedInsideCurrentCameraView(this.getBounds()):this.plannerCameraBehaviour.updateCameraOnPlanElementInsertedOutsideCurrentCameraView(this.getBounds()))}catch(a){console.error(a),n()}t()}removePlanObjectFromScene(e){(e instanceof A||e instanceof X)&&this._sendWallDimensions(),e instanceof j&&this._sendMeasurementLineDimension(),this._scene.remove(e.getContainer()),e.clear(),this.updateEnvironment(this.getBounds(),!0),!(e instanceof A||e instanceof j||e instanceof X)&&this._configuratorContext.baseContext===b.PLANNER&&this.plannerCameraBehaviour.updateCameraOnPlanElementRemoved(this.getBounds()),this._renderEverything()}planElementChanged(e,t){this._drawingEnabled&&this._sendWallDimensions(!1);const n=this._plannerSceneEventHandler.isDragIn()?t:null;if(this._sendElementMeasurements(n),this._sendRoomAreaData(),this.updateEnvironment(this.getBounds(),!0),this._renderEverything(),this._onPlanChanged(),!this._plannerSceneEventHandler.isDragIn()){const a=this.getPlanObject(t.getId());this._roomlePlannerUiCallback.onPlanElementChanged($.MOVED,{...a,data:null})}t instanceof A&&e.extRef&&e.extRef.jsObject&&this._isInteriorLightActive&&e.extRef.jsObject.handleCeilingLights()}exportGLB(e,t){}importGLB(e){this._loadGLB(e).then(t=>this._scene.add(t))}clearScene(){this._plannerMeshGenerator.clear(),this._getViewModel().sceneCleared(),super.clearScene()}_addSky(){const e={distance:4e5,turbidity:10,rayleigh:2,mieCoefficient:.005,mieDirectionalG:.8,inclination:.6,azimuth:0};if(!this._sky){this._sky=new Ge,this._sky.name="Sky",this._sky.scale.setScalar(45e4),this._sky.frustumCulled=!1,this._scene.add(this._sky),this._sky.material.uniforms.turbidity.value=e.turbidity,this._sky.material.uniforms.rayleigh.value=e.rayleigh,this._sky.material.uniforms.mieCoefficient.value=e.mieCoefficient,this._sky.material.uniforms.mieDirectionalG.value=e.mieDirectionalG;const t=Rt(e.distance,e.azimuth,e.inclination);this._sky.material.uniforms.sunPosition.value.copy(t);const n=new S(new Oe(2e4,16,8),new H({color:16777215}));n.name="Sunsphere",n.position.y=-7e5,n.visible=!1,n.position.set(t.x,-t.z,t.y)}this._lightSetting instanceof In&&this._lightSetting.updateSunPosition(e.inclination,e.azimuth)}toggleConfigureInRoom(){this._configureInRoom=!this._configureInRoom,this._roomleRenderer.isConfiguring&&(this._configureInRoom?this._getViewModel().showAll():this._hideAllExceptSelectedElement(),this._renderEverything(),this.updateScene())}switchTo2D(){if(!(this.cameraBehaviour?.cameraControl instanceof G)){this.cameraBehaviour?.cameraControl instanceof J&&this._getCameraControlFirstPerson().cleanUp(),this._roomleRenderer?.setCameraType(P.CAMERA_2D),this._plannerSceneEventHandler?.enable();for(const e of this._getViewModel().getWallPlanObjectViewModels())e.show();this._getViewModel().setCameraType(P.CAMERA_2D).then(()=>this._planElementHighlighter.highlightPlanElement()),this._roomleRenderer?.switchToPlanner(oe.Mode2D),this._renderEverything(),this._changeCameraBehaviour(new vn(this._getCameraControl2D(),this._cameraBehaviourState)),this._onCameraMove(),this.plannerCameraBehaviour.resetCameraOnSwitchTo2d(this.getBounds()),this._addCameraControlListener(),this._setCeiling(),this._roomlePlannerUiCallback.onCameraChanged(P.CAMERA_2D),this._setKernelZoomFactor(),this._onCameraMove(),this._sendRoomMeasurements()}}switchTo3D(){this.cameraBehaviour?.cameraControl instanceof B||(this._roomleRenderer?.setCameraType(P.CAMERA_3D),this._plannerSceneEventHandler?.enable(),this._getViewModel().setCameraType(P.CAMERA_3D),this._roomleRenderer?.switchToPlanner(oe.Mode3D),this._renderEverything(),this._changeCameraBehaviour(new ye(this._getCameraControl3D(),this._cameraBehaviourState)),this._onCameraMove(),this.plannerCameraBehaviour.resetCameraOnSwitchTo3d(this.getBounds()),this._addCameraControlListener(),this._setCeiling(),this._roomlePlannerUiCallback.onCameraChanged(P.CAMERA_3D))}switchToFirstPerson(){this.cameraBehaviour?.cameraControl instanceof J||(this._roomleRenderer?.setCameraType(P.CAMERA_FP),this._plannerSceneEventHandler?.disable(),this._plannerMeshGenerator.wallMeshes.forEach(e=>Ht(e.material,!1,!1)),this._getViewModel().getWallPlanObjectViewModels().forEach(e=>{e.show()}),this._getViewModel().setCameraType(P.CAMERA_FP),this._renderEverything(),this._changeCameraBehaviour(new zn(this._getCameraControlFirstPerson(),this._cameraBehaviourState)),this._addCameraControlListener(),this._setCeiling(),this._roomlePlannerUiCallback.onCameraChanged(P.CAMERA_FP),this.plannerCameraBehaviour.resetCameraOnSwitchToFirstPerson())}onCameraChanged(){}_setCameraControlListeners(){super._setCameraControlListeners(),this.cameraBehaviour instanceof Me&&(this.cameraBehaviour.cameraControl.addEventListener(Q.IDLE,()=>{this._onCameraIdle()},this),this.cameraBehaviour.cameraControl.addEventListener(Q.ORBIT_MOVE,()=>{this._onCameraMove()},this),this.cameraBehaviour.cameraControl.addEventListener(Q.MOVING,()=>{this._onCameraMove()},this),this.cameraBehaviour.cameraControl.addEventListener(Q.ZOOM_IN,()=>{this._onCameraMove()},this),this.cameraBehaviour.cameraControl.addEventListener(Q.ZOOM_OUT,()=>{this._onCameraMove()},this),this.cameraBehaviour.cameraControl.addEventListener(Q.ZOOM_CHANGE,()=>{this._onCameraZoomChange()},this))}_onCameraZoomChange(){this._setKernelZoomFactor()}_setKernelZoomFactor(){const e=this.cameraBehaviour.cameraControl.getKernelZoomFactor();e&&isFinite(e)&&e>=0&&this._getKernelAccess().planInteractionHandler?.setZoomFactor(e),this._plannerSceneEventHandler?.setKernelZoomFactor(e)}_setCeiling(){this._getViewModel()&&(this.cameraBehaviour.cameraControl instanceof J?this._getViewModel().getCeilingGroup().visible=!0:this._getViewModel().getCeilingGroup().visible=!1)}cameraBehaviourChanged(){super.cameraBehaviourChanged(),this._plannerSceneEventHandler?.setCamera(this.cameraBehaviour.cameraControl.getCamera()),this._updatePaperBackground()}_updatePaperBackground(){this.cameraBehaviour.cameraControl instanceof G?(this._paperBackground||(this._paperBackground=new Nn),this._scene?.add(this._paperBackground),this._requestRender()):this._paperBackground&&this._scene?.remove(this._paperBackground)}sceneChanged(){this._plannerSceneEventHandler&&this._plannerSceneEventHandler.setObject(this._scene)}_onKeyDown(e){if(super._onKeyDown(e),this._initData.debug&&this._checkNumKey(e),this._checkCopyPaste(e),this._checkUndoRedo(e),ve(e)){const t=wn(e),n=e.metaKey&&e.key==="Meta"||e.ctrlKey&&e.key==="Control",a=t>1?M.STANDARD:n?M.MULTISELECT:M.STANDARD;this._plannerSceneEventHandler.setSelectionMode(a)}this._checkPanning(e),this._plannerSceneEventHandler&&this._plannerSceneEventHandler.hasSelection()&&e.key&&(e.key==="Backspace"||e.key==="Delete")&&(this.deletePlanElementSelection(),e.preventDefault())}async _checkCopyPaste(e){if(ve(e)&&e.key==="c"){const t=this._plannerSceneEventHandler.getSelectedIds(),n=[];t.forEach(a=>{const s=this._getViewModel().getPlanObjectForId(a).getPlanElement(),o=s.getCatalogItemId()||s.getConfigurationHash();n.push(o)}),Ue.copy(n.join())}if(ve(e)&&e.key==="v"){const t=await Ue.paste();if(t){const a=t.split(",").map(i=>jt(i)||i).filter(i=>i.includes(":"));this._insertRapiItems(a)}}}_checkPanning(e){(e.shiftKey===!0||e.key&&e.key.includes("Shift"))&&this.cameraBehaviour.cameraControl instanceof B&&(this.cameraBehaviour.cameraControl.enablePanning(),e.preventDefault())}_onMouseDown(e){"event"in e&&this._checkPanning(e.event)}_checkNumKey(e){e.key&&e.key==="1"&&(this.switchTo2D(),e.preventDefault()),e.key&&e.key==="2"&&(this.switchTo3D(),e.preventDefault()),e.key&&e.key==="3"&&(this.switchToFirstPerson(),e.preventDefault())}_onKeyUp(e,t=!1){if(super._onKeyUp(e,t),ve(e,!0)){const n=wn(e);let a=M.STANDARD;!xt(e)&&n===1&&(a=M.MULTISELECT),this._plannerSceneEventHandler.setSelectionMode(a),e.preventDefault()}e.key&&e.key.includes("Shift")&&this.cameraBehaviour.cameraControl instanceof B&&(this.cameraBehaviour.cameraControl.disablePanning(),e.preventDefault()),e.key&&(e.key==="Escape"||e.key==="Esc")&&(this._drawingEnabled&&(this.escapeDrawing(!0),this._roomlePlannerUiCallback.onDrawCancel()),this.cancelDragIn())}async undo(){const e=this._getKernelAccess().planInteractionHandler;return e.cancelDrawing(),e.undo(),this.cancelPlanElementSelection("undo"),Promise.resolve()}async redo(){return this._getKernelAccess().planInteractionHandler.redo(),this.cancelPlanElementSelection("redo"),Promise.resolve()}setMode(e){switch(e){case P.CAMERA_2D:this.switchTo2D();break;case P.CAMERA_3D:this.switchTo3D();break;case P.CAMERA_FP:this.switchToFirstPerson();break}}_clearHighlighting(){this._planElementHighlighter.clearHighlighting(),this._renderWithoutShadowsAndAO()}highlightPlanElementsById(e){if(e===null){this._clearHighlighting();return}this._planElementHighlighter.highlightPlanElements(e)}highlightPlanElementById(e){if(e===null){this._clearHighlighting();return}e=this.getRootPlanObjectId(e);const t=this._getViewModel().getPlanObjectForId(e);this._planElementHighlighter.highlightPlanElement(t)}destroy(){super.destroy(),this._plannerMeshGenerator.removeMaterialLoadedListener(),this._getViewModel().removeGeometriesMergedListener()}planObjectConfigurationLoaded(e,t,n){if(n||console.error("Plan object configuration loading failed",t.getCatalogItemId()||t.getConfigurationHash()),e&&e.extRef&&t&&t.extRef){const i=t.extRef.jsObject.getPlanObject().getConfigurationRuntimeId();i>0&&this._getViewModel().constructComponents(i)}}async planObjectConfigurationChanged(e,t){const n=this.getPlanObject(t.getId());let a;n&&!(t instanceof k)&&!(t instanceof q)&&(a=await he([n],this._plannerKernelAccess,this._rapiAccess)),this._roomlePlannerUiCallback.onPlanElementChanged($.CHANGED,a?.length?a[0]:{...n,data:null})}addMesh(e,t,n,a,i,s){}updateCameraOnDrawWalls(){this.plannerCameraBehaviour.updateCameraOnDrawWalls(this.getBounds())}getBounds(){return this._getViewModel()?this._getViewModel().getBoundingBox():null}getGeometryBounds(){return this._configuratorContext.baseContext===b.CONFIGURATOR?super.getGeometryBounds():this.getBounds()}getPlanObject(e){const t=this._getKernelAccess().planInteractionHandler,n=this._plannerKernelAccess.planModelViewHelper,a=t.getPlan();return n.getPlanObject(a,e)}getRootPlanObjectId(e){if(!this._plannerKernelAccess?.kernelContainer)return e;const t=this._getKernelAccess().planInteractionHandler,n=this._plannerKernelAccess.planModelViewHelper,a=t.getPlan();return n.getRootPlanObjectId(a,e)}cancelPlanElementSelection(e){this._plannerSceneEventHandler.cancelSelection(e),this._planElementHighlighter.clearHighlighting(),this._requestRender()}async deletePlanElements(e){this.cancelPlanElementSelection("delete_object");const t=this._getKernelAccess().planInteractionHandler;t.startInteraction(),await this.deletePlanElementByIds(e),t.endInteraction()}async deletePlanElementSelection(){const e=this._plannerSceneEventHandler.getSelectedIds();await this.deletePlanElements(e)}async deletePlanElementByIds(e){for(const t of e){const n=this._getViewModel().getPlanObjectForId(t);if(n&&n.getObject()){const a=this.getPlanObject(n.getId());let i;a&&(i=await he([a],this._plannerKernelAccess,this._rapiAccess)),this._roomlePlannerUiCallback.onPlanElementChanged($.REMOVED,i.length?i[0]:{...a,data:null}),this._getKernelAccess().planInteractionHandler.removeElement(n.getKernelObject())}}}rotatePlanElements(e,t){const n=new(this._getKernelAccess()).kernelContainer.PlanObjectPtrList,a=new re;let i={x:0,y:0,z:0};if(e.forEach(s=>{const o=this._getViewModel().getPlanObjectForId(s);o&&o.getObject()&&(i=o.getPlanElement().getCenter(),n.push_back(o.getPlanElement()),a.expandByObject(o.getContainer()))}),n.size()>1){const s=a.getCenter(new E);i=w(s)}this._getKernelAccess().planInteractionHandler.rotateObjectsBy(n,t,i)}rotatePlanElementSelection(e){const t=this._plannerSceneEventHandler.getSelectedIds();this.rotatePlanElements(t,e)}planBoundsChanged(){this.updateEnvironment(this.getBounds()),this._requestRender()}planElementRemoved(e){this._configuratorContext.planElementId===e.getId()&&(this._roomlePlannerUiCallback.onSelectionCancel("delete_object"),this._configuratorContext.planElementId=0),this._onPlanChanged(),this._renderEverything(),this.scenePlanElementLightSources.length===0&&this.toggleInteriorLightsSceneSettings(!1)}_onPlanChanged(){this._roomlePlannerUiCallback.onPlanChanged()}prepareTopImage(e={},t){return this._configuratorContext.baseContext===b.CONFIGURATOR&&t?super.preparePerspectiveImage(e):new Promise(n=>{this._getViewModel().materialQueue.finished(!0).then(async()=>{const a=e.runtimeIds?we.getCameraTargetForBBox(this._getViewModel().getBoundingBoxFromRuntimeIds(e.runtimeIds),.1):this._calculateBoundingBoxOfAllMeshes(.1);this._lightSetting?.removeFromScene();const i=[];if(this.cameraBehaviour.cameraControl instanceof B){await this._getViewModel().setCameraType(P.CAMERA_2D),this._getViewModel().setNodeVisibility(!1);for(const o of this._getViewModel().getWallPlanObjectViewModels())o.isVisible()||i.push(o),o.show()}e.runtimeIds&&this._getViewModel().hideAllExceptRuntimeIds(e.runtimeIds);const s=await this._imageRenderer.prepareTopImage(this._scene,null,a,e);if(e.runtimeIds&&this._getViewModel().showAll(),this.cameraBehaviour.cameraControl instanceof B&&await this._getViewModel().setCameraType(P.CAMERA_3D),i.length)for(const o of i)o.hide();this._lightSetting?.addToScene(),this._roomleRenderer?.clearCache(),this._requestRender(),n(s)})})}preparePerspectiveImageOf(e,t={}){const n=this._getViewModel().getPlanObjectForId(e);if(!n){const a="Object with runtimeId "+e+" not found";throw console.warn(a),new Error(a)}return this._preparePerspectiveImage({...t,object:n.getObject().clone()})}async _waitForAssets(){await super._waitForAssets(),await this._getViewModel().materialQueue.finished(!0)}_preparePerspectiveImage(e={},t){if(this._configuratorContext.baseContext===b.CONFIGURATOR&&t)return super.preparePerspectiveImage(e);const n=this._handlePlannerIsolationModeState(t);return new Promise((a,i)=>{this._getViewModel().materialQueue.finished(!0).then(async()=>{let s;this.cameraBehaviour.cameraControl instanceof B?s=this.cameraBehaviour.cameraControl.getCamera().clone():(s=this.getPerspectiveOffsetCamera().clone(),this._getViewModel().getCeilingGroup().visible=!1,s.layers.enableAll(),this._getViewModel().setCameraType(P.CAMERA_3D)),s.resetOffset();const o=e.object?we.getCameraTargetForBBox(new re().setFromObject(e.object)):e.runtimeIds?we.getCameraTargetForBBox(this._getViewModel().getBoundingBoxFromRuntimeIds(e.runtimeIds)):this._calculateBoundingBoxOfAllMeshes();this._lightSetting?.removeFromScene();const c=e.object?Tt(this._scene):this._scene;e.object&&c.add(e.object),e.runtimeIds&&this._getViewModel().hideAllExceptRuntimeIds(e.runtimeIds);const h=await this._imageRenderer.preparePerspectiveImage(c,null,s,o,e,void 0,d=>{He(d,this._getViewModel().getWallPlanObjectViewModels())});$e(s),e.runtimeIds&&this._getViewModel().showAll(),e.object&&$e(c),this.cameraBehaviour.cameraControl instanceof G?(this._getViewModel().setCameraType(P.CAMERA_2D),this._getViewModel().getWallPlanObjectViewModels().forEach(d=>d.show())):He(this.cameraBehaviour.cameraControl.getCamera(),this._getViewModel().getWallPlanObjectViewModels()),this._lightSetting?.addToScene(),this._roomleRenderer?.clearCache(),this._requestRender(),this._setCeiling(),n(),a(h)},i)})}_handlePlannerIsolationModeState(e){if(!e){const t=this._configuratorContext.baseContext;return this._getViewModel().showAll(),this._configuratorContext.baseContext=b.PLANNER,()=>{this._configuratorContext.baseContext=t,t===b.CONFIGURATOR&&(this._configureInRoom||this._hideAllExceptSelectedElement())}}return()=>null}_hideAllExceptSelectedElement(){const{planElementId:e}=this._configuratorContext,t=this.getRootPlanObjectId(e);this._getViewModel().hideAllExcept(t)}preparePerspectiveImage(e={},t){return this._preparePerspectiveImage(e,t)}_calculateBoundingBoxOfAllMeshes(e=0){const t=this.getBounds();return we.getCameraTargetForBBox(t,e)}enableRotation(){this._plannerSceneEventHandler.setState(te.ROTATE)}disableRotation(){this._plannerSceneEventHandler.resetState()}enableSnapping(){this._plannerSceneEventHandler.enableSnapping()}disableSnapping(){this._plannerSceneEventHandler.disableSnapping()}enableAdvancedDocking(){this._plannerSceneEventHandler.enableAdvancedDocking()}disableAdvancedDocking(){this._plannerSceneEventHandler.disableAdvancedDocking()}showsChildrenOfPlanObject(e){if(e instanceof k){const t=e.getKernelObject();return this._plannerSceneEventHandler.showsChildrenOfPlanObject(t)}return!1}enableShowChildrenOfPlanObject(e){if(e instanceof k){const t=e.getKernelObject();this._plannerSceneEventHandler.enableShowChildrenOfPlanObject(t)}}disableShowChildrenOfPlanObject(e){if(e instanceof k){const t=e.getKernelObject();this._plannerSceneEventHandler.disableShowChildrenOfPlanObject(t)}}dragIn(e){this._plannerSceneEventHandler.getSelectedIds().length>0&&this._plannerSceneEventHandler.cancelSelection("dragIn"),this._plannerSceneEventHandler.setDragIn(!0,e)}getPlannerSceneEventHandler(){return this._plannerSceneEventHandler}disablePlannerEvents(){this._plannerSceneEventHandler.disable()}enablePlannerEvents(){this._plannerSceneEventHandler.enable()}_onCameraIdle(){return super._onCameraIdle()&&(this._sendRoomMeasurements(),this._sendPlanObjectPositions(),this._roomlePlannerUiCallback.onCameraIdle(),this._sendElementMeasurements(),this._hideAllNodeIfThereAreNoSelections(),this._sendWallDimensions()),!0}_hideAllNodeIfThereAreNoSelections(){!this.currentSelection&&!this.getPlannerSceneEventHandler().isCurrentlyDrawing&&(this._getViewModel().getMeasurementLineObjectViewModels().forEach(e=>e.hideDraggableNodes()),this._getViewModel().getNodePlanObjectViewModels().forEach(e=>e.hide()))}_onCameraMove(){return super._onCameraMove()&&(this._roomlePlannerUiCallback.disableWallDimensions(),this._roomlePlannerUiCallback.cameraStartsMoving()),this._updateNodeSize(),this._renderEverything(),!0}_showWallNodes(){this._getViewModel().getNodePlanObjectViewModels().forEach(e=>e.show())}_updateNodeSize(){if(this.cameraBehaviour.cameraControl instanceof G){const e=1/this.cameraBehaviour.cameraControl.getCamera().zoom;this._getViewModel().setNodeZoom(e)}}_sendPlanObjectPositions(){if(this.cameraBehaviour.cameraControl.isLocked())return;const{clientWidth:e,clientHeight:t}=this._domHelper.element,n=this.cameraBehaviour.cameraControl.getCamera(),a=this._plannerSceneEventHandler.getSelectedIds();a.length>1?this._sendMultiSelectionPosition(a,n,e,t):this._sendSelectedPlanObjectPositions(n,e,t)}_sendMultiSelectionPosition(e,t,n,a){const i=new re;for(const c of e){const h=this._getViewModel().getPlanObjectForId(c);h&&i.expandByObject(h.getContainer())}const s=i.getCenter(new E),o=qe(p(s,t,n,a));this._roomlePlannerUiCallback.onUpdatePlanObjectPositions([{runtimeIds:e,position2d:o}])}_sendSelectedPlanObjectPositions(e,t,n){const a=this._getViewModel(),i=[],s=[...a.getStaticPlanObjectViewModels(),...a.getConfigurablePlanObjectViewModels(),...a.getConfigurableConstructionPlanObjectViewModels(),...a.getConstructionPlanObjectViewModels(),...a.getWallPlanObjectViewModels(),...a.getFloorPlanObjectViewModels(),...a.getNodePlanObjectViewModels()];for(const o of s)i.push(Gn(o,e,t,n));this._roomlePlannerUiCallback.onUpdatePlanObjectPositions(i)}_sendRoomAreaData(){const e=this._getViewModel().getFloorPlanObjectViewModels(),t=this.cameraBehaviour.cameraControl.getCamera(),{clientWidth:n,clientHeight:a}=this._domHelper.element,i=[],s=this.cameraBehaviour.cameraControl.getKernelZoomFactor();this._initData.debug&&this._debugSpheres.floorPoints.children.length&&this._debugSpheres.floorPoints.clear();for(const o of e){const c=o.getFloorData(s);if(!c||!c.textPosition3d)return;if(c.roomLabel=o.getKernelObject().getLabelObject(),c.formattedArea=this._unitFormatter.formatSquareMMValueToUnitString(c.area),c.textPosition2d=p(c.textPosition3d,t,n,a),i.push(kt(c)),this._initData.debug){const h=new Oe(.1,32,16),d=new H({color:255}),u=new S(h,d);u.position.copy(c.textPosition3d),this._debugSpheres.floorPoints.add(u)}}i.length>0&&this._roomlePlannerUiCallback.onFloorPlanAreasUpdated(i)}_updateMeasurementPositions(e,t,n,a){return e.fromPosition3d&&(e.fromPosition2d=p(e.fromPosition3d,t,n,a)),e.toPosition3d&&(e.toPosition2d=p(e.toPosition3d,t,n,a)),e.textPosition3d&&(e.textPosition2d=p(e.textPosition3d,t,n,a)),e}_sendElementMeasurements(e){this.cameraBehaviour.cameraControl instanceof G&&(this._sendConstructionElementDimensions(e),this._sendObjectMeasurements(e),this._sendMeasurementLineDimension())}_sendRoomMeasurements(){this.cameraBehaviour.cameraControl instanceof G&&(this._sendWallDimensions(),this._sendRoomAreaData())}_sendMeasurementLineDimension(){if(!(this.cameraBehaviour.cameraControl instanceof G))return;const e=this.cameraBehaviour.cameraControl.getCamera(),{clientWidth:t,clientHeight:n}=this._domHelper.element,a=[],i=this._getViewModel().getMeasurementLineObjectViewModels();for(const s of i){const o=s.getMeasurementLineDimension();o.fromPosition2d=p(o.fromPosition3d,e,t,n),o.toPosition2d=p(o.toPosition3d,e,t,n),o.textPosition2d=p(o.textPosition3d,e,t,n),o.lengthFormatted=this._unitFormatter.formatMMValueToUnitString(o.length),a.push(Bt(o))}this._roomlePlannerUiCallback.onUpdateMeasurementLineDimensions(a)}_sendObjectMeasurements(e){if(!(this.cameraBehaviour.cameraControl instanceof G)||!this.currentSelection&&!e)return;const t=this._plannerSceneEventHandler.getSelectedIds();if(t.length===0&&!e)return;const n=e||this._getViewModel().getPlanObjectForId(t[0]);if(!n||n instanceof be||n instanceof q||!(n instanceof N)&&!(n instanceof k))return;const a=this.cameraBehaviour.cameraControl.getCamera(),{clientWidth:i,clientHeight:s}=this._domHelper.element,o=this.cameraBehaviour.cameraControl.getKernelZoomFactor(),c=n.getObjectMeasurements(o,i,s),h=this.transformMeasurements(c.rectMeasurements,a,i,s),d=this.transformMeasurements(c.objectMeasurements,a,i,s),u=this.transformMeasurements(c.objectToWallsMeasurements,a,i,s);this._roomlePlannerUiCallback.onUpdateObjectMeasurements({rectMeasurements:h,objectMeasurements:d,objectToWallsMeasurements:u})}transformMeasurements(e,t,n,a){return e.map(i=>{const s=p(i.fromPosition3d,t,n,a),o=p(i.toPosition3d,t,n,a),c=p(i.textPosition3d,t,n,a);return Ft({...i,fromPosition2d:s,toPosition2d:o,textPosition2d:c})})}_sendConstructionElementDimensions(e){if(!this.currentSelection&&!e)return;const t=e||this._getViewModel().getPlanObjectForId(this.currentSelection.staticItemRuntimeId||this.currentSelection.configurationRuntimeId);if(!t||!(t instanceof be||t instanceof q))return;this._initData.debug&&this._debugSpheres.constructionElementsPoints.children.length>0&&this._debugSpheres.constructionElementsPoints.clear();const n=this.cameraBehaviour.cameraControl.getCamera(),{clientWidth:a,clientHeight:i}=this._domHelper.element,s=this.cameraBehaviour.cameraControl.getKernelZoomFactor(),o=t.getConstructionElementMeasurements(s,a,i);if(!o)return;if(this._initData.debug){const h=new H({color:16711680}),d=new H({color:65280}),u=new H({color:255}),g=new Oe(.1,32,16),_=new S(g,h);_.position.copy(o.leftMeasurement.fromPosition3d),_.position.y=5;const m=new S(g,h);m.position.copy(o.leftMeasurement.toPosition3d),m.position.y=5;const O=new S(g,d);O.position.copy(o.rightMeasurement.fromPosition3d),O.position.y=5;const f=new S(g,d);f.position.copy(o.rightMeasurement.toPosition3d),f.position.y=5;const F=new S(g,u);F.position.copy(o.elementRange.fromPosition3d),F.position.y=5;const U=new S(g,u);U.position.copy(o.elementRange.toPosition3d),U.position.y=5,this._debugSpheres.constructionElementsPoints.add(_),this._debugSpheres.constructionElementsPoints.add(m),this._debugSpheres.constructionElementsPoints.add(O),this._debugSpheres.constructionElementsPoints.add(f),this._debugSpheres.constructionElementsPoints.add(F),this._debugSpheres.constructionElementsPoints.add(U)}o.leftMeasurement=this._updateMeasurementPositions(o.leftMeasurement,n,a,i),o.rightMeasurement=this._updateMeasurementPositions(o.rightMeasurement,n,a,i),o.elementRange=this._updateMeasurementPositions(o.elementRange,n,a,i);const c={leftMeasurement:{...je(o.leftMeasurement)},rightMeasurement:{...je(o.rightMeasurement)},elementRange:{...je(o.elementRange)}};this._roomlePlannerUiCallback.onUpdateConstructionElementsMeasurements(c)}_sendWallDimensions(e=!0){this._initData.debug&&this._debugSpheres.wallPoints.children.length>0&&this._debugSpheres.wallPoints.clear(),Xn(this._domHelper,this.cameraBehaviour,this._roomlePlannerUiCallback,this._plannerSceneEventHandler,this._getViewModel(),this._unitFormatter,this._debugSpheres,e,this._initData.debug)}enableWallDrawing(){if(this.cameraBehaviour.cameraControl instanceof G){const e=Ie(this.getBounds(),this._domHelper.element.clientWidth,this._domHelper.element.clientHeight);this.plannerCameraBehaviour.resetCameraOnEnableWallDrawing(e)}this._drawingEnabled||(this._drawingEnabled=!0,this._scene.add(this._plannerSceneEventHandler.enableWallDrawing()))}disableWallDrawing(){this._drawingEnabled=!1,this.cameraBehaviour.cameraControl.unlock(),this._scene.remove(this._plannerSceneEventHandler.cancelWallDrawing())}escapeDrawing(e){this._plannerSceneEventHandler.stopDrawing(e)}cancelDragIn(){if(this._plannerSceneEventHandler.isDragIn()){const e=this._plannerSceneEventHandler.getSelectedIds();this._plannerSceneEventHandler.cancelSelection("delete_object"),this._plannerSceneEventHandler.setDragIn(!1),this._getInputManager().forceMouseUp(),this.deletePlanElements(e)}}setSceneEvents(e){this.cameraBehaviour.cameraControl instanceof J||(e.construction!==void 0&&this._plannerSceneEventHandler?.enableConstructionEvents(e.construction),e.objects!==void 0&&this._plannerSceneEventHandler?.enableObjectEvents(e.objects))}startedDrawing(){this._plannerSceneEventHandler.startDrawing(),this._showWallNodes()}stoppedDrawing(){this._plannerSceneEventHandler.stopDrawing()}disableEvents(){super.disableEvents(),this.disablePlannerEvents()}enableEvents(){super.enableEvents(),this._configuratorContext.baseContext===b.PLANNER&&!(this.cameraBehaviour.cameraControl instanceof J)&&this.enablePlannerEvents()}resetCameraPositionToStart(){this.plannerCameraBehaviour.externalApiResetCameraPosition(this.getBounds())}async moveCamera(e){return this.plannerCameraBehaviour instanceof ye||this.plannerCameraBehaviour instanceof nt?this.plannerCameraBehaviour.externalApiMoveCamera(e):Promise.resolve()}_setInteriorOrExteriorWallMaterial(e,t){const a=this._getViewModel().getWallPlanObjectViewModels();if(!a.length)return;const i=this._getKernelAccess().planInteractionHandler,s=g=>{i.setWallLeftMaterial(g,xe(g.leftMaterial,t))},o=g=>{i.setWallRightMaterial(g,xe(g.rightMaterial,t))},c=a.map(g=>g.getKernelObject()),h=this._plannerKernelAccess.kernelContainer.WallType.InnerWall,d=this._plannerKernelAccess.kernelContainer.WallType.OuterWallLeft,u=this._plannerKernelAccess.kernelContainer.WallType.OuterWallRight;for(const g of c)g.wallType===h&&e===Ae.INTERIOR&&(s(g),o(g)),g.wallType===d&&(e===Ae.INTERIOR?o(g):s(g)),g.wallType===u&&(e===Ae.EXTERIOR?o(g):s(g))}changeInteriorWallsMaterial(e){this._setInteriorOrExteriorWallMaterial(Ae.INTERIOR,e)}changeExteriorWallsMaterial(e){this._setInteriorOrExteriorWallMaterial(Ae.EXTERIOR,e)}changeFloorsMaterial(e){const n=this._getViewModel().getFloorPlanObjectViewModels();if(!n.length)return;const a=this._getKernelAccess().planInteractionHandler,i=n.map(s=>s.getKernelObject());a.startInteraction();for(const s of i)a.setFloorMaterial(s,xe(s.material,e));a.endInteraction()}getWallAngleDegrees(e){if(!(e instanceof A))return 0;const t=this.cameraBehaviour.cameraControl.getCamera(),n=new ue(t.position.x,t.position.z),i=new ue(e.getPosition().x,e.getPosition().z).clone().sub(n).normalize(),s=e.getKernelObject(),o=new ue(Math.sin(s.getAngle()),Math.cos(s.getAngle())),c=i.angle()-o.angle();return Gt.radToDeg(c)}moveElementPosition(e,t){const n=this._getKernelAccess().planInteractionHandler;n.setObjectFixedZ(e.getPlanElement(),!0);const a=e.getPlanElement().getCenter(),i=Z(t).sub(Z(a));n.moveElementBy(e.getPlanElement(),w(i)),n.setObjectFixedZ(e.getPlanElement(),!1),this._sendPlanObjectPositions()}moveElementsPosition(e,t){const n=new this._plannerKernelAccess.kernelContainer.PlanObjectPtrList,a=Z(t).sub(e[e.length-1].getPosition());e.forEach(o=>n.push_back(o.getPlanElement()));const i=w(a);this._getKernelAccess().planInteractionHandler.moveObjectsBy(n,i),this._sendPlanObjectPositions()}get plannerCameraBehaviour(){return this.cameraBehaviour}enableMeasurementLineDrawing(){this._roomlePlannerUiCallback.onMeasurementLineStateChange(!0),this._plannerSceneEventHandler.enableMeasurementLineDrawing()}disableMeasurementLineDrawing(){this._plannerSceneEventHandler.disableMeasurementLineDrawing()}setCompletelyLoaded(e){this._completelyLoaded=e}enablePanning(){this.plannerCameraBehaviour instanceof ye&&this.plannerCameraBehaviour.enablePanningOnShiftClick()}disablePanning(){this.plannerCameraBehaviour instanceof ye&&this.plannerCameraBehaviour.disablePanningOnShiftRelease()}setObjectToWallMeasurementLength(e,t,n){const a=this._getViewModel().getPlanObjectForId(e),i=a.getPlanElement(),o=Ut(i.getWallDistances()).find(m=>Wt(m.angle+"_"+m.length)===t);if(!o)return;const c=Z(o.startPoint),h=Z(o.endPoint),d=c.clone().sub(h).normalize(),u=(n-o.length)/1e3,g=a.getPosition().clone().add(d.multiplyScalar(u));this._getKernelAccess().planInteractionHandler.moveElementToIn2d(i,w(g)),this._sendObjectMeasurements()}setWallMeasurementLength(e,t,n){const a=this.getPlannerSceneEventHandler().isCurrentlyDrawing,i=this._getKernelAccess().planInteractionHandler;let s=this._getViewModel().getPlanObjectForId(e);const o=i.isVectorPreviewModeEnabled();if(a&&!o){const c=this._getViewModel().latestNodePlanObjectViewModel,h=w(c.getPosition());i.endDrawing(h),this.escapeDrawing(!1),s=this._getViewModel().latestWallPlanObjectViewModel}if(s){const c=s.getKernelObject();i.startInteraction(),i.setLengthOfWall(c,t,c.getPreferredSide(),n,!0),i.endInteraction()}if(a&&!o){i.startInteraction();const c=this._getViewModel().latestNodePlanObjectViewModel,h=w(c.getPosition());i.beginDrawing(h,!1),this._plannerSceneEventHandler.startDrawing()}}setMeasurementLineLength(e,t,n){const a=this._getViewModel().getPlanObjectForId(e);this._plannerSceneEventHandler.setMeasurementLineLength(a,t,n)}setEventHandlerObject(e){super.setEventHandlerObject(e),this._plannerSceneEventHandler.setObject(e)}_readyForRender(){console.log("ready_for_render"),this._roomlePlannerUiCallback.onReadyForRender(),this._globalCallback.onReadyForRender()}notifyPlannerOnComponentSelectionCancel(e,t){if(e)if(this.configuratorContext.baseContext===b.CONFIGURATOR){if(t==="click_outside"){const n=this.getObjectComponent(this.configuratorContext.rootComponentId??this.configuratorContext.planObjectId);this._roomlePlannerUiCallback.onExternalObjectModuleSelected(n.externalObjectGroupId,null,null)}}else this._roomlePlannerUiCallback.onExternalObjectSelectionCancel(t);else this._roomlePlannerUiCallback.onComponentSelectionCancel()}_planObjectSelectionChanged(e,t){const n=this.getObjectComponent(t??e);if(n?.configurationType?.value!==Y.EXTERNAL)return;const a=this.getObjectComponent(this.configuratorContext.selectedRuntimeComponentId??this.configuratorContext.planObjectId);a.externalRootModuleId===n.externalRootModuleId&&a.externalSubModuleId===n.externalSubModuleId||this._getKernelAccess().planObjectSelectionChanged(e,t)}highlightExternalObject(e){this.highlightPlanElementById(e.runtimeId),this._renderWithoutShadowsAndAO()}_selectExternalObjectModule(){this._getKernelAccess()?.kernelContainer&&!this._configuratorContext.selectedRuntimeComponentId&&this.getPlanObject(this._configuratorContext.planElementId).configurationType?.value===Y.EXTERNAL&&this.selectComponent(this._configuratorContext.rootComponentId)}getObjectComponent(e){const n=this._getKernelAccess().planInteractionHandler.getPlan();return this._getKernelAccess().planModelViewHelper.getObjectComponent(n,e)}getCameraParameters3d(){return this._getViewModel().cameraType===P.CAMERA_3D?this.cameraBehaviour3d.cameraControl.getCurrentCameraParameters():null}_createCeilingLightGroup(){this._scene.children.find(t=>t.name===fn)||this._scene.add(this._getViewModel().getCeilingLightsGroup())}toggleInteriorLightsSceneSettings(e){this._initData.featureFlags.interiorLights&&(this._isInteriorLightActive=e,this._scene.userData.environmentDefinition.rotation=e?hn:Kt,this._scene.userData.environmentDefinition.intensity=e?dn:Nt,this._isInteriorLightActive&&(this._createCeilingLightGroup(),this._activateCeilingLight()),this._getViewModel().toggleCeilingLights(e),this._requestRender())}async _insertRapiItems(e){const t=e.map((a,i)=>({id:a,index:i})),n=[];for(const{index:a,id:i}of t)n.push({index:a,id:i});return await this.insertRapiObjects(n)}async insertRapiObjects(e){const t=({id:s})=>ce(s)?this._rapiAccess.getItem(s):this._rapiAccess.getConfiguration(s),n=e.map(t),a=await Promise.all(n);return(await this._plannerKernelAccess.insertItems(a)).map((s,o)=>({runtimeId:s,originalIndex:e[o].index}))}}De([C],de.prototype,"_rapiAccess"),De([C],de.prototype,"_plannerMeshGenerator"),De([C],de.prototype,"_plannerInputManager"),De([C],de.prototype,"_roomlePlannerUiCallback"),De([C],de.prototype,"_localStorageHelper");var Qn=Object.defineProperty,R=(r,e,t,n)=>{for(var a=void 0,i=r.length-1,s;i>=0;i--)(s=r[i])&&(a=s(e,t,a)||a);return a&&Qn(e,t,a),a};const En="Could not retrieve configuration for external object! Did you implement onGetConfigurationForExternalObject?",ea={left:0,top:1,right:1,bottom:0};class L{constructor(e,t){this._homagIntelligence=null,this._hscInstance=null,this._glbInstance=null,this._configurator=null,this._currentMode=1,this._creator_=e,this._activePlugins=t||[],this._kernelAccessCallback.addListener(this)}setEnvironmentMap(e){const{url:t,intensity:n,rotation:a,maxLightSources:i}=e;this._sceneManager.setEnvironmentMap(t,n,a,i)}deleteSelection(){this._sceneManager.deletePlanElementSelection()}rotateSelection(e){this._sceneManager.rotatePlanElementSelection(e)}cancelSelection(e="unknown"){this._sceneManager.cancelPlanElementSelection(e)}init(e,t,n){return Je.start("loadingTime"),this._domHelper.setDomElement(e),this._sceneManager?(this._lifeCycleManager.resume(),Promise.resolve()):(this._preloadPlanId=t,this.setOverrides(n),new Promise(this._initPromiseCallback.bind(this)))}async createPlanFromObject(e,t,n){if(!this._planInteractionHandler)throw new Error("no plan interaction handler");t&&(t=w(new E(t.x,t.y,t.z)));const a=await(ce(e)?this._rapiAccess.getItem(e):this._rapiAccess.getConfiguration(e));this._plan=this._plannerKernelAccess.createPlanFromObject(a,t,n),this._sceneManager.planXMLLoaded(this._plan),this._sceneManager.updateScene(),this.resetCameraPosition();const i=W(this._plan.getPlanObjects());return i?.length?i[0].getId():-1}loadPlanXml(e,t){return this._sceneManager.setCompletelyLoaded(!1),this.setOverrides(t),new Promise(n=>{this._plan=this._planInteractionHandler.loadPlanXML(e),this._sceneManager.planXMLLoaded(this._plan),this._roomlePlannerUiCallback.onTotalFloorAreaChanged(this._planInteractionHandler.getPlan().getTotalFloorArea()),this._currentMode=1,this._initData.moc&&(t.id?this._rapiAccess.trackView(t.id,Te.ROOM_DESIGNER):this._rapiAccess.trackView("planXML",Te.ROOM_DESIGNER)),n()})}loadPlan(e,t){return this.setOverrides(t),new Promise((n,a)=>{const i=Qe(e);(i?this._rapiAccess.getPlanSnapshot(e):this._rapiAccess.getPlan(e)).then(o=>{this._sceneManager.backToPlanner(),this._sceneManager.setCompletelyLoaded(!1);const c=i?o.plan:o.planObjects;this._plan=this._planInteractionHandler.loadPlanXML(c),this._sceneManager.planXMLLoaded(this._plan),this._roomlePlannerUiCallback.onTotalFloorAreaChanged(this._planInteractionHandler.getPlan().getTotalFloorArea()),this._configuratorContext.lastLoadedPlanId=e,this._currentMode=1,this._initData.moc&&this._rapiAccess.trackView(e,Te.ROOM_DESIGNER),n(o)},a)})}setOverrides(e){e&&(this._initData.setOverrides(e),this._globalInitData.setOverrides(e))}toggleConfigureInRoom(){this._sceneManager.toggleConfigureInRoom()}switch2D(){this._sceneManager.switchTo2D()}switch3D(){this._sceneManager.switchTo3D()}switchToFirstPerson(){this._sceneManager.switchToFirstPerson()}resetCameraPosition(){this._sceneManager.resetCameraPositionToStart()}exportGLB(){this._sceneManager.exportGLB()}importGLB(e){this._sceneManager.importGLB(e)}_initPromiseCallback(e,t){this._kernelReadyCallback=e;const{dls:n,ls:a,mode:i,stats:s}=this._initData;this._sceneManager||(this._sceneManager=new de(this._creator_,ea,this,i)),this._preloadPlanId&&this._sceneManager.preload(this._preloadPlanId);const o=zt.createDynamicLightSettingSource(n,a);s&&this.showStats(),this._sceneManager.enableHD(o),this._planInteractionHandler&&this._kernelReadyCallback()}isReady(){this._planInteractionHandler=this._plannerKernelAccess.planInteractionHandler,this._kernelReadyCallback&&this._kernelReadyCallback()}showBenchmarks(){Je.showBenchmarks()}getConfiguratorApi(){return this._configurator||(this._configurator=new Vt(this._creator_,this._activePlugins),this._configurator.setOverrides(this._initData),this._configurator.initSceneManager(this._sceneManager)),this._configurator}startViewing(){this._sceneManager.startViewing(),this._roomlePlannerUiCallback.onContextChanged(b.GLB_VIEWER)}startConfiguring(){const e=this._sceneManager.currentSelection,t=e.item?.id||e.configuration?.id;this._sceneManager.startConfiguring(),t&&this._configurator.notifyUiAboutNewLabel(t),this._roomlePlannerUiCallback.onContextChanged(b.CONFIGURATOR)}async selectPlanObjectById(e){return this._sceneManager.selectPlanObject(e)}highlightPlanElements(e){e===null?this._sceneManager.highlightPlanElementsById(null):Array.isArray(e)?this._sceneManager.highlightPlanElementsById(e):this._sceneManager.highlightPlanElementById(e)}backToPlanner(){this._sceneManager.backToPlanner(),this._roomlePlannerUiCallback.onContextChanged(b.PLANNER)}showGUI(){this._sceneManager.showGUI()}async switchToConfigurator(){const e=await this._singlePromiseFactory.create(et.START_HSC,"startHSC",t=>{if(this._hscInstance)return t(this._hscInstance);ae.import("./configurator-DExQ7ygL.js").then(({Configurator:n})=>{const a=new n(this._creator_);a.boot({kernelInstance:this._planInteractionHandler.getConfiguratorKernel(),kernelContainer:this._plannerKernelAccess.kernelContainer}),a.getApi().setOverrides(this._initData),a.getApi().initSceneManager(this._sceneManager),a.getApi().init(this._domHelper.element).then(()=>{this._hscInstance=a,t(this._hscInstance)})})});return this._currentMode=0,this.cancelSelection("isolation_mode_started"),e}async switchToViewer(){const e=await this._singlePromiseFactory.create(et.START_GLB,"startGLB",t=>{if(this._glbInstance)return t(this._glbInstance);ae.import("./glb-viewer-BuaOp37E.js").then(n=>{const a=new n.GlbViewer(this._creator_);a.boot(),a.getApi().setOverrides(this._initData),a.getApi().init(this._domHelper.element).then(()=>{this._glbInstance=a,t(this._glbInstance)})})});return this._currentMode=2,this.cancelSelection("isolation_mode_started"),e}switchToPlanner(e){e&&this.loadPlan(e),this._currentMode=1}updateSize(){this._sceneManager.updateCamera()}getMain(){}update(){this.updateSize(),this._glbInstance&&this._glbInstance.getApi().updateSize(),this._hscInstance&&this._hscInstance.getApi().updateSize()}get callbacks(){return this._roomlePlannerUiCallback}set callbacks(e){this._roomlePlannerUiCallback=e}get hasSingleRoom(){return this._sceneManager.hasSingleRoom}showStats(){this._sceneManager.showStats()}onCloseHSC(){this._hscInstance&&this._hscInstance.getApi().pauseKernelCallbacks()}back(){if(this._currentMode===2&&this._glbInstance&&this._glbInstance.getApi().clearScene(),this._currentMode===0&&this._hscInstance){const e=this._hscInstance.getApi();e.cancelSelection({reason:"isolation_mode_cancelled"}),e.cancelDockings(),e.hideDimensions(),e.disableMultiselect(),this._sceneManager.updateScene()}this._currentMode=1}backTo(e){console.error("backTo in planner Needs to be implemented later")}getConfigurator(){return this._hscInstance}getCurrentSkin(){return this._rapiAccess.getCurrentSkin()}getRuntimeComponentIdOfRootComponent(e){return e?this._plannerKernelAccess.planInteractionHandler?this._plannerKernelAccess.planInteractionHandler.getConfiguratorKernel().getRootPlanComponentIdFromObjectId(e):(console.warn("Can not retrieve runtime id without planInteractionHandler"),0):(console.warn("Can not retrieve runtime id without planObjectId"),0)}resumeTest(e){this._domHelper.setDomElement(e),this._lifeCycleManager.resume()}pauseTest(){this._lifeCycleManager.pause()}syncCatalog(e){return this._dataSyncer.syncCatalog(e)}loadError(e){console.log(e)}getPlanInteractionHandler(){return Promise.resolve(this._planInteractionHandler)}getPlanModelViewHelper(){return Promise.resolve(this._plannerKernelAccess.planModelViewHelper)}async insertObject(e,t,n){if(!this._planInteractionHandler)throw new Error("no plan interaction handler");if(t&&(t=w(new E(t.x,t.y,t.z))),ke(e))return this._insertExternalObject(e,{findFreeSpaceInPlan:!t,position:t,rotation:n});const a=await(ce(e)?this._rapiAccess.getItem(e):this._rapiAccess.getConfiguration(e)),i=await this._plannerKernelAccess.addPlanObjectFromItem(a,t,n);return this._sceneManager.updateScene(),i}async insertItemList(e){if(e.length===0)return[];const t=e.map((d,u)=>({id:d,index:u})),n=async(d,u)=>({runtimeId:await this._insertExternalObject(d),originalIndex:u}),a=[],i=[];for(const{index:d,id:u}of t)ke(u)?a.push(n(u,d)):i.push({index:d,id:u});const s=this._sceneManager.insertRapiObjects(i),[o,c]=await Promise.all([Promise.all(a),s]),h=[...o,...c];return h.sort((d,u)=>d.originalIndex-u.originalIndex),h.map(d=>d.runtimeId)}async insertItems(e){if(e.length===0)return[];const t=e.map(n=>typeof n=="string"?n:n.id);return this.insertItemList(t)}duplicateItems(e){return this._plannerKernelAccess.duplicateItems(e)}getScene(){return this._sceneManager.getScene()}updateScene(){this._sceneManager?.updateScene()}getCameraOffset(){return this._sceneManager.getCameraOffset()}setCameraOffset(e){this._sceneManager.setCameraOffset(e)}async getObjects(){const e=(await this.getPlanModelViewHelper()).getPlanOverview(this._plan),t=W(e.objects);return he(t,this._plannerKernelAccess,this._rapiAccess)}async getPlanOverview(){const e=(await this.getPlanModelViewHelper()).getPlanOverview(this._plan);return W(e)}prepareTopImage(e={}){return this._sceneManager.prepareTopImage(e)}preparePerspectiveImage(e={},t=!1){return this._sceneManager.preparePerspectiveImage(e,t)}enableRotation(){this._sceneManager.enableRotation()}disableRotation(){this._sceneManager.disableRotation()}enableMultiselect(){this._sceneManager.getPlannerSceneEventHandler().setSelectionMode(M.MULTISELECT),this._configuratorContext.selectionMode=M.MULTISELECT}disableMultiselect(){this._sceneManager.getPlannerSceneEventHandler().setSelectionMode(M.STANDARD),this._configuratorContext.selectionMode=M.STANDARD}async _insertExternalObject(e,t={}){let n=e;if(ke(e)&&(n=await this.newPosDataFromId(e),!n))throw new Error(En);if(Xt(e)&&e.externalMeta?.refresh&&(n=await this._roomlePlannerUiCallback.onGetConfigurationForExternalObject(e.id),!n))throw new Error(En);const a=t.findFreeSpaceInPlan??!0,i=t.dragIn??!1;return await this._loadExternalObjectGroup(n,a,i,!1,[],t.position,t.rotation),-1}async dragInObject(e,t,n="rml_id"){if(n==="rml_serialized")throw new Error("dragInObject is not supported for tc_id or rml_serialized");if(this._sceneManager.dragIn(t),n==="rml_id"){const a=ce(e)?await this._rapiAccess.getItem(e):await this._rapiAccess.getConfiguration(e),i=await this.insertItems([a]);if(await this._sceneManager.selectPlanObject(i[0]),i.length!==1)throw new Error("More than one object added, abort");return i[0]}else{if(n==="tc_id"||n==="tc_serialized")return this._insertExternalObject(e,{dragIn:!0});throw new Error("dragInObject is not supported for "+n)}}cancelDragIn(){this._sceneManager.cancelDragIn()}enableSnapping(){this._sceneManager.enableSnapping()}disableSnapping(){this._sceneManager.disableSnapping()}enableAdvancedDocking(){this._sceneManager.enableAdvancedDocking()}disableAdvancedDocking(){this._sceneManager.disableAdvancedDocking()}showsChildrenOfPlanObject(e){return this._sceneManager.showsChildrenOfPlanObject(e)}enableShowChildrenOfPlanObject(e){this._sceneManager.enableShowChildrenOfPlanObject(e)}disableShowChildrenOfPlanObject(e){this._sceneManager.disableShowChildrenOfPlanObject(e)}async getPartlistOf(e){const t=this._plannerKernelAccess.kernelInstance.getHashOfConfiguration(e);if(!t){const i="Object has no partlist because it is not a configuration: "+t;return console.warn(i),Promise.reject(i)}const n=this._plannerKernelAccess.kernelInstance.getPartList(e);return await this._plannerKernelAccess.addUiDataAndPriceToPartList(n,t)}formatValueToUnitString(e,t){return this._unitFormatter.formatValueToUnitString(e,t)}drawWalls(e,t={}){const n=this._planInteractionHandler;n.startInteraction();const a=[];for(const i of e){const s=n.addNode(i.from),o=n.addNode(i.to),c=n.addWall(s,o);i.props?.height!==void 0&&n.setWallHeight(c,i.props.height),i.props?.thickness!==void 0&&n.setWallThickness(c,i.props.thickness),a.push(c)}return t.keepInteractionOpen||n.endInteraction(),this._sceneManager.updateCameraOnDrawWalls(),this._sceneManager.updateScene(),a}async removeElements(e,t={}){this._sceneManager.lockCamera();const n=this._planInteractionHandler;for(const a of e){const i=this._sceneManager.getPlanObject(a.getId());let s;i&&(s=await he([i],this._plannerKernelAccess,this._rapiAccess)),this._roomlePlannerUiCallback.onPlanElementChanged($.REMOVED,s?.length?s[0]:{...i,data:null}),this._planInteractionHandler.removeElement(a)}t.keepInteractionOpen||n.endInteraction(),this._sceneManager.unlockCamera()}hasWalls(){const t=this._planInteractionHandler?.getPlan();return!(!t||t.getWallCount()<1)}enableWallDrawing(){this._sceneManager.enableWallDrawing()}disableWallDrawing(){this._sceneManager.disableWallDrawing()}getUnitFormatter(){return this._unitFormatter}getStorage(){return this._idbManager}getConfiguratorContext(){return this._configuratorContext}get PlannerCoreTypes(){return this._plannerKernelAccess.kernelContainer}setSceneEvents(e){this._sceneManager.setSceneEvents(e)}async saveExternalObjectSnapshot(e){const t=await this.getPlanModelViewHelper(),n=this._planInteractionHandler.getPlan(),a=W(t.getExternalObjectGroups(n));if(a.length===0)return null;const i=await this._savePlanSnapshotExternalObjects(e,a);return{...i,glb:`https://api.roomle.com/v2/planSnapshots/${i.id}/3dAssets/glTF/plan.glb`,usdz:`https://api.roomle.com/v2/planSnapshots/${i.id}/3dAssets/usdz/plan.usdz`}}async _savePlanSnapshotExternalObjects(e,t){const n=t.map(m=>m.uniqueId),a=t.map(m=>m.runtimeId),i=await this.getPlanModelViewHelper(),s=this._planInteractionHandler.getPlan(),o=i.getPlanOverview(s),c=s.createPlanXmlWithObjects(n,!1,2),h={parentId:e||null,planObjects:[],combinedIds:[],plan:c},d=o.objects,u=d.size();for(let m=0;m<u;m++){const O=d.get(m),f=O.configurationHash||O.catalogItemId;if(a.includes(O.runtimeId)){const{center:F,dimensions:U,rotation:ot,rootComponentCenter:fa}=O,Ca=JSON.stringify({center:F,dimensions:U,rotation:ot,rootComponentCenter:fa});h.planObjects.push({combinedId:f,position:Ca})}}const g=await this._rapiAccess.savePlanSnapshot(h);this._plannerKernelAccess.planSnapshotCreated(g);const _=new Promise((m,O)=>{Promise.allSettled([this.preparePerspectiveImage({runtimeIds:a}),this.prepareTopImage({runtimeIds:a})]).then(async([f,F])=>{if(f.status==="rejected"||F.status==="rejected"){O("Could not generate images of plan snapshot");return}try{const U=await this._rapiAccess.savePlanSnapshotImage(g,f.value,"perspectiveImage",F.value,"topImage");m({...U})}catch(U){O(U)}})});try{return await _}catch(m){return console.error(m),g}}async saveCurrentPlanSnapshot(e,t){const n=await this.getPlanModelViewHelper(),a=this._planInteractionHandler.getPlan(),i=n.getPlanOverview(a),s=t?a.createPlanXmlWithObjects(t,!1,2):a.getPlanXML(!1,2),o={parentId:e||null,planObjects:[],combinedIds:[],plan:s},c=i.objects,h=c.size();for(let g=0;g<h;g++){const _=c.get(g),m=_.configurationHash||_.catalogItemId;if(!t||m===t){const{center:O,dimensions:f,rotation:F,rootComponentCenter:U}=_,ot=JSON.stringify({center:O,dimensions:f,rotation:F,rootComponentCenter:U});o.planObjects.push({combinedId:m,position:ot})}}const d=await this._rapiAccess.savePlanSnapshot(o);this._plannerKernelAccess.planSnapshotCreated(d);const u=new Promise((g,_)=>{Promise.allSettled([this.preparePerspectiveImage(),this.prepareTopImage()]).then(async([m,O])=>{if(m.status==="rejected"||O.status==="rejected"){_("Could not generate images of plan snapshot");return}try{const f=await this._rapiAccess.savePlanSnapshotImage(d,m.value,"perspectiveImage",O.value,"topImage");g({...f})}catch(f){_(f)}})});try{return await u}catch(g){return console.error(g),d}}getPlanXmlFrom(e){return e?Qe(e.id)?e.plan:e.planObjects:null}async moveCamera(e){return this._sceneManager.moveCamera(e)}async createNewSerializedConfiguration(e){return Promise.resolve(this._plannerKernelAccess.createNewSerializedConfiguration(e))}changeInteriorWallsMaterial(e){this._sceneManager.changeInteriorWallsMaterial(e)}changeExteriorWallsMaterial(e){this._sceneManager.changeExteriorWallsMaterial(e)}changeFloorsMaterial(e){this._sceneManager.changeFloorsMaterial(e)}getWallAngleDegrees(e){return this._sceneManager.getWallAngleDegrees(e)}calcPartsPriceSum(e){return this._plannerKernelAccess.calcPartsPriceSum(e)}async swapObject(e,t){let n;typeof e=="number"?n=await this.getPlanObjectForRuntimeId(e):n=e;const a=n.getPosition(),i=n.getRotation();return await this._sceneManager.deletePlanElementByIds([n.getPlanElement().getId()]),this.cancelSelection("swap_object"),await this.insertObject(t,a,i)}exportImageFromCamera(e="image",t=!1){return this._sceneManager.clearHighlighting(),this._sceneManager.exportImageFromCamera(e,t)}exportCanvasScreenshot(e){return this._sceneManager.exportCanvasScreenshot(e)}moveElementPosition(e,t){this._sceneManager.moveElementPosition(e,t)}moveElementsPosition(e,t){this._sceneManager.moveElementsPosition(e,t)}preparePerspectiveImageOf(e,t={}){return this._sceneManager.preparePerspectiveImageOf(e,t)}async generateTCExport(e=[]){try{const t=new this._plannerKernelAccess.kernelContainer.StringArray;for(const n of e)t.push(n);return Promise.resolve(JSON.parse(this._planInteractionHandler.generateTCExport(t)))}catch(t){return console.error(t),Promise.reject("Could not create Blue Ocean MVP JSON")}}enableMeasurementLineDrawing(){this._sceneManager.enableMeasurementLineDrawing()}disableMeasurementLineDrawing(){this._sceneManager.disableMeasurementLineDrawing()}setObjectToWallMeasurementLength(e,t,n){this._sceneManager.setObjectToWallMeasurementLength(e,t,n)}setWallMeasurementLength(e,t,n){this._sceneManager.setWallMeasurementLength(e,t,n)}setMeasurementLineLength(e,t,n){this._sceneManager.setMeasurementLineLength(e,t,n)}escapeDrawing(e){this._sceneManager.escapeDrawing(e),this._roomlePlannerUiCallback.onDrawCancel()}isCurrentlyDrawing(){return this._sceneManager.getPlannerSceneEventHandler().isCurrentlyDrawing}async resolveShortUrl(e){const[,,,t]=e.split("/"),n=await this._rapiAccess.resolveShortUrl(t);if(!n)throw new Error("Failed to resolve short URL");const{url:a}=n;return a}enableEvents(){this._sceneManager.enableEvents()}disableEvents(){this._sceneManager.disableEvents()}async downloadHomagIxExportPoC(){const{downloadHomagIxExportPoC:e}=await ae.import("./imos-ix-poc-export-helper-CgY9kOS1.js"),t=(await this.getPlanModelViewHelper()).getPlanOverview(this._plan);return e(t,this._plannerKernelAccess.configurationExporter,this._plannerKernelAccess.kernelInstance)}async configureExternalObjectApi(e){const t=typeof e=="string"?JSON.parse(e):e;await this._plannerKernelAccess.configureExternalObjectApi(t)}loadExternalObjectLibrary(e){const t=this._planInteractionHandler.getConfiguratorKernel(),n=typeof e=="string"?e:JSON.stringify(e);t.loadExternalAttributeDefinition(n),this.updateScene()}async loadExternalObjectGroup(e,t,n=!1,a=[]){return this._loadExternalObjectGroup(e,t,!1,n,a)}async _loadExternalObjectGroup(e,t,n,a,i=[],s,o){this.getConfiguratorContext().baseContext===b.CONFIGURATOR?await this._loadExternalObjectGroupInConfigurator(e,t,n,a,i):await this._loadExternalObjectGroupInPlanner(e,t,n,a,i,s,o)}async _loadExternalObjectGroupInConfigurator(e,t,n,a,i=[]){await this._loadOrUpdateExternalObjectGroup(e,t,n,a,i,!0),this.updateScene()}async _loadExternalObjectGroupInPlanner(e,t,n,a,i=[],s,o){const c=this.getConfiguratorContext(),h=this._sceneManager.getPlanObject(c.planElementId);if(await this._loadOrUpdateExternalObjectGroup(e,t,n,a,i,!1,s,o),h.configurationType?.value===Y.EXTERNAL)if(i.includes(h.configurationHash)){const d=this._createSerializedGroupCollection(e),u=JSON.parse(d[0]).id;await this._selectExternalObjectGroup(u,!1)}else await this._selectExternalObjectGroup(h.configurationHash,!1);this.updateScene()}async _loadOrUpdateExternalObjectGroup(e,t,n,a,i,s,o,c){const h=this._createSerializedGroupCollection(e);n?this._planInteractionHandler.startInteraction():this._planInteractionHandler.resumeInteraction();const d=o??{x:0,y:0,z:0},u=c??(n&&!s?this._getFaceTheCameraAngle(90):0),g={findFreeSpaceInPlan:t,applyGlobalChildMode:!1,isVisible:!n,correctArrangement:a,respondWithPositionInPlan:!1},_=this._planInteractionHandler.addOrUpdateExternalPlanObjects(h,d,u,g,i);n||this._planInteractionHandler.endInteraction();const m=this._planInteractionHandler.getPlan().extRef.jsObject,O=[];for(const f of _)f.hasConfiguration()&&O.push(m.getConfigurablePlanObjectForId(f.getId()));await Promise.all(O.map(async f=>{await f.isInitDone()}))}_createSerializedGroupCollection(e){const t=Array.isArray(e)?e:[e],n=[];for(const a of t){const i=typeof a=="string"?a:JSON.stringify(a);n.push(i)}return n}_getFaceTheCameraAngle(e){const t=this._sceneManager.getCameraParameters3d();if(!t?.yaw)return 0;const n=Zt(t.yaw),a=Math.round(n/e)*e;return qt(a)}async renderImagesOfExternalObjectGroup(e){const t=Array.isArray(e)?e:[e],n={},a=this._initData.animateCamera;this._initData.animateCamera=!1;for(const i of t){try{await this._loadExternalObjectGroup(i,!1,!1,!1),await this._selectExternalObjectModule(i.id,null,!0,!0,!1,!1),this.preparePerspectiveImage(),await this._sceneManager.waitForMaterialQueue(),this.updateScene();const s=await this.exportCanvasScreenshot();n[i.id]=s}catch(s){console.error(s)}this.backToPlanner()}for(const i of t)await this.removeExternalObjectGroup(i.id,!1);return this._initData.animateCamera=a,n}async removeExternalObjectGroup(e,t=!1){const n=await this.getPlanModelViewHelper(),a=this._planInteractionHandler.getPlan(),i=n.getExternalObjectComponent(a,e,"");this.getConfiguratorContext().planElementId===i.runtimeId&&this._sceneManager.cancelPlanElementSelection("delete_object"),i.runtimeId!==0&&(t?(this._planInteractionHandler.resumeInteraction(),this._planInteractionHandler.removeObjectWithId(e),this._planInteractionHandler.endInteraction()):(this._planInteractionHandler.startInteraction(),this._sceneManager.deletePlanElementByIds([i.runtimeId]),this._planInteractionHandler.endInteraction())),this.updateScene()}removeExternalObjectRootModule(e){this._planInteractionHandler.startInteraction(),this._planInteractionHandler.removeObjectWithId(e),this._planInteractionHandler.endInteraction(),this.updateScene()}async selectExternalObjectGroup(e){this.getConfiguratorContext().baseContext===b.CONFIGURATOR||this._planInteractionHandler.setShowChildrenOfExternalObject(e,{value:se.OFF},!1),await this._selectExternalObjectGroup(e,!0),this.updateScene()}async selectExternalObjectRootModule(e){const n=this.getConfiguratorContext().baseContext===b.CONFIGURATOR;n||this._planInteractionHandler.setShowChildrenOfExternalObject(e,{value:se.GROUND_COMPONENTS},!1),await this._selectExternalObjectModule(e,null,!n,n,!0,!0),this.updateScene()}async selectExternalObjectSubModule(e,t){const a=this.getConfiguratorContext().baseContext!==b.CONFIGURATOR;await this._selectExternalObjectModule(e,t,a,!0,!0,!0),this.updateScene()}async openOrCloseGeometryOfExternalObject(e,t,n,a){const i=await this.getPlanModelViewHelper(),s=this._planInteractionHandler.getPlan(),o=i.getExternalObjectComponent(s,e,"");if(o?.configurationRuntimeId){const c=n?"open":"close";this._sceneManager.animateElement(o.configurationRuntimeId,"openClose",c,!0,a),this.updateScene()}}async _selectKernelComponent(e){e.configurationHash&&e.configurationType.value===Y.EXTERNAL&&await this._selectExternalObjectModule(e.configurationHash,e.componentId,!0,!0,!0,!1),this.updateScene()}async _selectExternalObjectGroup(e,t){const n=await this.getPlanModelViewHelper(),a=this._planInteractionHandler.getPlan(),i=n.getExternalObjectComponent(a,e,"");i.runtimeId!==0&&(t&&await this._roomlePlannerUiCallback.onBackToPlanner(),await this._sceneManager.selectPlanObject(i.runtimeId))}async _selectExternalObjectModule(e,t,n,a,i,s){const o=await this.getPlanModelViewHelper(),c=this._planInteractionHandler.getPlan(),h=o.getExternalObjectComponent(c,e,t??"");if(h.runtimeId===0)return;const d=this.getConfiguratorContext().baseContext===b.CONFIGURATOR,u=this._getSelectedPlanObjectComponent();let g=!1,_=n;d&&(g=u?.configurationRuntimeId===h.configurationRuntimeId,_=!g,g||this._sceneManager.backToPlanner()),_&&await this._selectPlanObject(h),a&&!g&&await this._roomlePlannerUiCallback.onStartConfiguring(),h.planComponentRuntimeId!==0&&i&&this._sceneManager.selectComponent(h.planComponentRuntimeId,!1),s&&!d&&this._sceneManager.highlightExternalObject(h)}async _selectPlanObject(e){let t=e.runtimeId;const n=W(this._plan.getPlanObjects());for(const a of n)if(a.getConfigurationRuntimeId()===e.planComponentRuntimeId){t=a.getId();break}await this._sceneManager.selectPlanObject(t)}_getSelectedPlanObjectComponent(){const e=this.getConfiguratorContext(),t=e.selectedRuntimeComponentId??e.planObjectId;return this._sceneManager.getObjectComponent(t)}async getExternalObjectGroups(){const e=await this.getPlanModelViewHelper(),t=this._planInteractionHandler.getPlan(),n=[],a=W(e.getExternalObjectGroups(t));for(const i of a)n.push(JSON.parse(i.serializedDefinition));return n}async getExternalRoomInformation(){const e=await this.getPlanModelViewHelper(),t=this._planInteractionHandler.getPlan();return W(e.getExternalRoomInformation(t))}get globalCallbacks(){return this._globalCallback}_executeWithInteraction(e){const t=this._plannerKernelAccess.planInteractionHandler;t.startInteraction();const n=e();return t.endInteraction(),n}addAtticToWall(e,t,n,a){return this._executeWithInteraction(()=>this._plannerKernelAccess.planInteractionHandler.addAttic(e,t,n,a)||null)}removeAttic(e){this._executeWithInteraction(()=>this._plannerKernelAccess.planInteractionHandler.removeElement(e))}setAtticSide(e,t){this._executeWithInteraction(()=>this._plannerKernelAccess.planInteractionHandler.setAtticSide(e,t))}getAttachedAttic(e){const t=e.getAttachedAttics();return t.size()>0?t.get(0):null}updateAtticKneeHeight(e,t){this._executeWithInteraction(()=>this._plannerKernelAccess.planInteractionHandler.setAtticKneeHeight(e,t))}updateAtticWidth(e,t){this._executeWithInteraction(()=>this._plannerKernelAccess.planInteractionHandler.setAtticWidth(e,t))}async executeWithInteraction(e){const t=this._plannerKernelAccess.planInteractionHandler;t.startInteraction();try{const n=e();return n instanceof Promise?await n:n}finally{t.endInteraction()}}pauseInputListeners(){return this._sceneManager.pause()}resumeInputListeners(){return this._sceneManager.resume()}getScenePlanElementLightSources(){return this._sceneManager.scenePlanElementLightSources}setAllLightsOnOff(e){this._sceneManager.setAllLightsOnOff(e)}setLightsOnOffByIds(e,t){this._sceneManager.setLightsOnOffByIds(e,t)}async getPlanObjectForRuntimeId(e){const t=this._planInteractionHandler.getPlan()?.extRef?.jsObject;return Promise.resolve(t.getPlanObjectForId(e)||null)}async rotateByRuntimeId(e,t){return this._sceneManager.rotatePlanElements([e],t),Promise.resolve()}async deleteByRuntimeId(e){return this._sceneManager.deletePlanElements([e]),Promise.resolve()}async moveByRuntimeId(e,t){const n=await this.getPlanObjectForRuntimeId(e);return this._sceneManager.moveElementPosition(n,t),Promise.resolve()}undo(){return this._sceneManager.undo()}redo(){return this._sceneManager.redo()}setHomagIntelligence(e){this._homagIntelligence=e}newPosDataFromId(e){return this._homagIntelligence.getEmulator().newPosDataFromId(e)}sendToOM(e=!0){return this._homagIntelligence.sendToOM(e)}async fetchPrice(e){return this._homagIntelligence.fetchPrice(e)}async getOrderManagerGroupData(e){return this._homagIntelligence.getEmulator().getGroupDataForOrder(e)}getRapiAccess(){return this._rapiAccess}}R([C],L.prototype,"_configuratorContext"),R([C],L.prototype,"_domHelper"),R([C],L.prototype,"_kernelAccessCallback"),R([C],L.prototype,"_plannerKernelAccess"),R([C],L.prototype,"_rapiAccess"),R([C],L.prototype,"_singlePromiseFactory"),R([C],L.prototype,"_roomlePlannerUiCallback"),R([C],L.prototype,"_lifeCycleManager"),R([C],L.prototype,"_dataSyncer"),R([C],L.prototype,"_initData"),R([C],L.prototype,"_idbManager"),R([C],L.prototype,"_globalInitData"),R([C],L.prototype,"_globalCallback"),R([C],L.prototype,"_unitFormatter");class ta extends Yt{_canDrag(e){return!0}}const na=[new z("script-loader",Pn),new z("planner-input-manager",ta,tt.CONTEXT),new z("logger",$t),new z("planner-mesh-generator",Jt),new z("configurator-view-model",Cn,tt.CONTEXT),new z("rapi-access",Qt),new z("global-init-data",en),new z("planner-selection-handler",Bn)];var aa=Object.defineProperty,Sn=(r,e,t,n)=>{for(var a=void 0,i=r.length-1,s;i>=0;i--)(s=r[i])&&(a=s(e,t,a)||a);return a&&aa(e,t,a),a};const Mn="external:root-tag";class at{constructor(e,t){this._externalItems=new Map,this._externalConfigurations=new Map,this._tagIds=[],this._creator_=e,this._articlesPromise=t,this._init()}setEmulator(e){this._emulator=e}_init(){const e=this._globalCallback.onCheckExternalCache;this._globalCallback.onCheckExternalCache=async(t,n)=>{const a=await e(t,n);return a!==null?a:this._onCheckExternalCache(t)},this._globalCallback.onFetchExternalData=this._onFetchExternalData.bind(this)}async _onCheckExternalCache(e){if(e==="/tags/"+Pe(Mn)){const t=await this._processedArticles();return this._tagIds=[...t.keys()].sort((n,a)=>n.localeCompare(a)),Promise.resolve({tag:{id:Pe(Mn),tags:this._tagIds,sort:1}})}for(const t of this._tagIds){if(e==="/tags/"+t){const n=await this._processedArticles();return Promise.resolve({tag:{id:t,label:n.get(t).label,sort:1}})}if(e==="/tags/"+t+"/items"){const a=(await this._processedArticles()).get(t).items;return a.sort((i,s)=>i.label.localeCompare(s.label)),Promise.resolve({items:a})}}return null}_onFetchExternalData(e,t){const n=Array.isArray(t)?t:[t],a=[];for(const i of n){const s=this._configuratorViewModel.getExternalConfigurationById(i);s?a.push(s):this._externalItems.has(i)?a.push(this._externalItems.get(i)):console.warn("ID",i,"is unknown")}return Array.isArray(t)?Promise.resolve(a):Promise.resolve(a[0])}async _processedArticles(){let e=await this._articlesPromise;return e.articles&&(e=e.articles),e.reduce((t,n)=>{const a=n.category||"Uncategorized",i=Pe(a.toLowerCase());t.has(i)||t.set(i,{id:i,label:a,items:[]});const s=t.get(i),{depth:o,width:c,height:h}=n.roots.reduce((g,{attributes:_})=>(_&&_.forEach(m=>{m.id==="mod_Depth"&&(g.depth+=parseInt(m.value,10)/10),m.id==="mod_Width"&&(g.width+=parseInt(m.value,10)/10),m.id==="mod_Height"&&(g.height+=parseInt(m.value,10)/10)}),g),{depth:0,width:0,height:0}),d=o>0&&c>0&&h>0,u=tn({id:n.articleId,uiLabels:{desktop:{line1:n.name,line2:n.desc,line3:d?`${h}x${c}x${o}`:""},mobile:{line1:n.name,line2:d?`${h}x${c}x${o}`:"",line3:n.desc}},label:n.name??"external-objects.no-name",externalObject:!0,configuration:{imageUrl:n.imageUrl}});return this._externalItems.set(u.id,u),s.items.push(u),t},new Map)}}Sn([C],at.prototype,"_globalCallback"),Sn([C],at.prototype,"_configuratorViewModel");/**
155
155
  * @license
156
156
  * Copyright 2019 Google LLC
157
157
  * SPDX-License-Identifier: Apache-2.0
158
158
  */const yn=Symbol("Comlink.proxy"),ia=Symbol("Comlink.endpoint"),ra=Symbol("Comlink.releaseProxy"),it=Symbol("Comlink.finalizer"),Ke=Symbol("Comlink.thrown"),Dn=r=>typeof r=="object"&&r!==null||typeof r=="function",sa={canHandle:r=>Dn(r)&&r[yn],serialize(r){const{port1:e,port2:t}=new MessageChannel;return Ln(r,e),[t,[t]]},deserialize(r){return r.start(),Hn(r)}},oa={canHandle:r=>Dn(r)&&Ke in r,serialize({value:r}){let e;return r instanceof Error?e={isError:!0,value:{message:r.message,name:r.name,stack:r.stack}}:e={isError:!1,value:r},[e,[]]},deserialize(r){throw r.isError?Object.assign(new Error(r.value.message),r.value):r.value}},An=new Map([["proxy",sa],["throw",oa]]);function la(r,e){for(const t of r)if(e===t||t==="*"||t instanceof RegExp&&t.test(e))return!0;return!1}function Ln(r,e=globalThis,t=["*"]){e.addEventListener("message",function n(a){if(!a||!a.data)return;if(!la(t,a.origin)){console.warn(`Invalid origin '${a.origin}' for comlink proxy`);return}const{id:i,type:s,path:o}=Object.assign({path:[]},a.data),c=(a.data.argumentList||[]).map(ne);let h;try{const d=o.slice(0,-1).reduce((g,_)=>g[_],r),u=o.reduce((g,_)=>g[_],r);switch(s){case"GET":h=u;break;case"SET":d[o.slice(-1)[0]]=ne(a.data.value),h=!0;break;case"APPLY":h=u.apply(d,c);break;case"CONSTRUCT":{const g=new u(...c);h=_a(g)}break;case"ENDPOINT":{const{port1:g,port2:_}=new MessageChannel;Ln(r,_),h=ua(g,[g])}break;case"RELEASE":h=void 0;break;default:return}}catch(d){h={value:d,[Ke]:0}}Promise.resolve(h).catch(d=>({value:d,[Ke]:0})).then(d=>{const[u,g]=Xe(d);e.postMessage(Object.assign(Object.assign({},u),{id:i}),g),s==="RELEASE"&&(e.removeEventListener("message",n),Rn(e),it in r&&typeof r[it]=="function"&&r[it]())}).catch(d=>{const[u,g]=Xe({value:new TypeError("Unserializable return value"),[Ke]:0});e.postMessage(Object.assign(Object.assign({},u),{id:i}),g)})}),e.start&&e.start()}function ca(r){return r.constructor.name==="MessagePort"}function Rn(r){ca(r)&&r.close()}function Hn(r,e){const t=new Map;return r.addEventListener("message",function(a){const{data:i}=a;if(!i||!i.id)return;const s=t.get(i.id);if(s)try{s(i)}finally{t.delete(i.id)}}),rt(r,t,[],e)}function Ne(r){if(r)throw new Error("Proxy has been released and is not useable")}function jn(r){return ge(r,new Map,{type:"RELEASE"}).then(()=>{Rn(r)})}const ze=new WeakMap,Ve="FinalizationRegistry"in globalThis&&new FinalizationRegistry(r=>{const e=(ze.get(r)||0)-1;ze.set(r,e),e===0&&jn(r)});function ha(r,e){const t=(ze.get(e)||0)+1;ze.set(e,t),Ve&&Ve.register(r,e,r)}function da(r){Ve&&Ve.unregister(r)}function rt(r,e,t=[],n=function(){}){let a=!1;const i=new Proxy(n,{get(s,o){if(Ne(a),o===ra)return()=>{da(i),jn(r),e.clear(),a=!0};if(o==="then"){if(t.length===0)return{then:()=>i};const c=ge(r,e,{type:"GET",path:t.map(h=>h.toString())}).then(ne);return c.then.bind(c)}return rt(r,e,[...t,o])},set(s,o,c){Ne(a);const[h,d]=Xe(c);return ge(r,e,{type:"SET",path:[...t,o].map(u=>u.toString()),value:h},d).then(ne)},apply(s,o,c){Ne(a);const h=t[t.length-1];if(h===ia)return ge(r,e,{type:"ENDPOINT"}).then(ne);if(h==="bind")return rt(r,e,t.slice(0,-1));const[d,u]=xn(c);return ge(r,e,{type:"APPLY",path:t.map(g=>g.toString()),argumentList:d},u).then(ne)},construct(s,o){Ne(a);const[c,h]=xn(o);return ge(r,e,{type:"CONSTRUCT",path:t.map(d=>d.toString()),argumentList:c},h).then(ne)}});return ha(i,r),i}function ga(r){return Array.prototype.concat.apply([],r)}function xn(r){const e=r.map(Xe);return[e.map(t=>t[0]),ga(e.map(t=>t[1]))]}const Tn=new WeakMap;function ua(r,e){return Tn.set(r,e),r}function _a(r){return Object.assign(r,{[yn]:!0})}function Xe(r){for(const[e,t]of An)if(t.canHandle(r)){const[n,a]=t.serialize(r);return[{type:"HANDLER",name:e,value:n},a]}return[{type:"RAW",value:r},Tn.get(r)||[]]}function ne(r){switch(r.type){case"HANDLER":return An.get(r.name).deserialize(r.value);case"RAW":return r.value}}function ge(r,e,t,n){return new Promise(a=>{const i=ma();e.set(i,a),r.start&&r.start(),r.postMessage(Object.assign({id:i},t),n)})}function ma(){return new Array(4).fill(0).map(()=>Math.floor(Math.random()*Number.MAX_SAFE_INTEGER).toString(16)).join("-")}class pa extends nn{constructor(e,t){super(e),this._activePlugins=t||[]}setupGlobals(){}setupDependencies(){an.setup(na),this.lookup("logger",this._context),this.lookup("planner-kernel-access",this._context).init(rn.PLANNER)}cleanUpGlobals(){throw new Error("Method not implemented.")}cleanUpDependencies(){throw new Error("Method not implemented.")}async bootFinished(){this._planner=new L(this._context,this._activePlugins),this._planner.getMain=()=>this,window.RoomlePlanner||(this._activePlugins.length===0?window.RoomlePlanner=this._planner:window.RoomlePlanner=this._planner);const e=this.lookup("init-data",this._context);if(e?.hi&&sn()){const t=new MessageChannel;window.parent.postMessage({type:"connect_hi",port:t.port2},"*",[t.port2]);const n=Hn(t.port1),a=n.onLoadArticleCatalog(e.hi.libraryId),i=new at(this._context,a),s=await ae.import("./homag-intelligence-DNXfORHS.js");await new s.HomagIntelligence().init(a,i,this._planner,e.hi.libraryId,e.hi.serverOptions,n)}}getApi(){return this._planner}getContextName(){return b.PLANNER}}kn("Planner",pa)}}});
159
- //# sourceMappingURL=planner-ol3gjqFY.js.map
159
+ //# sourceMappingURL=planner-CTkUBoTH.js.map