iflow-engine-base 3.9.17 → 3.9.20

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.
@@ -1,6 +1,6 @@
1
1
  import { n as S, am as R, h as A, aA as x, j as b, s as E, E as F, Q as k, W as I, a as f, T as v, i as P, J as m, V as p, b as D } from "./three-vendor-Dbcwwhki.js";
2
- import { W as C } from "./sdk-runtime-gCd6dMmU.js";
3
- import { E as y } from "./engine-2d-Di06Ry30.js";
2
+ import { W as C } from "./sdk-runtime-DLvF5IZ2.js";
3
+ import { E as y } from "./engine-2d-mQsokiAx.js";
4
4
  class L {
5
5
  scene;
6
6
  panoramaSphere = null;
@@ -1,5 +1,5 @@
1
1
  import { n as Js, C as st, s as Zs, V as v, b as N, O as $s, W as en, M as J, Q as ge, a as tn, f as qt, j as De, B as sn, h as ft, q as it, aB as Ue, aC as Pt, aD as at, H as Et, aE as ms, aF as yn, aG as xn, aH as In, aI as Tn, z as wn, aJ as Bn, aK as En, l as lt, aL as As, aM as gs, aN as vn, k as Cs, aO as Fn, ap as Je, am as Ss, D as Kt, ab as Dn, aA as ys, p as bn, u as We, aP as qe, au as xs, r as Mn, aQ as Rn, a2 as Pn, aR as On, aS as nn, aT as Is, aU as kn, a7 as Ln, aV as Qe, aW as mt } from "./three-vendor-Dbcwwhki.js";
2
- import { E as Hn } from "./engine-2d-Di06Ry30.js";
2
+ import { E as Hn } from "./engine-2d-mQsokiAx.js";
3
3
  var Ne = /* @__PURE__ */ ((m) => (m.LoadStart = "gaussian-load-start", m.LoadProgress = "gaussian-load-progress", m.Loaded = "gaussian-loaded", m.LoadError = "gaussian-load-error", m.SceneRemoved = "gaussian-scene-removed", m.FpsUpdated = "gaussian-fps-updated", m.ViewChanged = "gaussian-view-changed", m))(Ne || {});
4
4
  class Un {
5
5
  listeners = /* @__PURE__ */ new Map();
@@ -1,6 +1,6 @@
1
- import { g as Ob, c as $L, E as lQ } from "./engine-2d-Di06Ry30.js";
1
+ import { g as Ob, c as $L, E as lQ } from "./engine-2d-mQsokiAx.js";
2
2
  import { aX as Si, aY as uQ } from "./three-vendor-Dbcwwhki.js";
3
- import { l as hQ, L as dQ } from "./sdk-runtime-gCd6dMmU.js";
3
+ import { l as hQ, L as dQ } from "./sdk-runtime-DLvF5IZ2.js";
4
4
  class fQ {
5
5
  listeners = /* @__PURE__ */ new Map();
6
6
  /**
@@ -1,6 +1,6 @@
1
1
  import { R as qn, b as Ke, V as rt, s as Yn, aZ as Zn } from "./three-vendor-Dbcwwhki.js";
2
- import { J as qt } from "./engine-2d-Di06Ry30.js";
3
- import { a as Yt } from "./engine-3d-Dp-2o5Fl.js";
2
+ import { J as qt } from "./engine-2d-mQsokiAx.js";
3
+ import { a as Yt } from "./engine-3d-CeUaONqH.js";
4
4
  class Hu {
5
5
  /**
6
6
  * 构造函数
@@ -8987,7 +8987,7 @@ class Ii {
8987
8987
  this.unsubscribe(), this.el.remove();
8988
8988
  }
8989
8989
  }
8990
- const zi = "3.9.161", Di = {
8990
+ const zi = "3.9.18", Di = {
8991
8991
  version: zi
8992
8992
  }, Bi = Di.version;
8993
8993
  class Ri {
@@ -218,4 +218,4 @@
218
218
  <span class="engine-2d-search__item-name">${this.highlight(n.name,t)}</span>
219
219
  ${n.layer?`<span class="engine-2d-search__item-layer">${this.escapeHtml(n.layer)}</span>`:""}
220
220
  ${n.description?`<span class="engine-2d-search__item-desc">${this.escapeHtml(n.description)}</span>`:""}
221
- `,s.addEventListener("click",()=>this.selectResult(n)),s.addEventListener("mouseenter",()=>{this.activeIndex=r,this.highlightItem(this.resultList.querySelectorAll(".engine-2d-search__item"))}),this.resultList.appendChild(s)})}highlight(e,t){const i=this.escapeHtml(e),n=t.trim();if(!n)return i;const r=this.escapeRegExp(this.escapeHtml(n));return i.replace(new RegExp(`(${r})`,"gi"),'<mark class="engine-2d-search__mark">$1</mark>')}highlightItem(e){e.forEach((t,i)=>{t.classList.toggle("engine-2d-search__item--active",i===this.activeIndex)}),this.activeIndex>=0&&e[this.activeIndex]?.scrollIntoView({block:"nearest"})}selectResult(e){this.manager.onResultSelect(e),this.hide()}clearResults(){this.resultList.innerHTML="",this.resultList.style.display="none",this.statusEl.style.display="none";const e=this.wrapper.querySelector(".engine-2d-search__divider");e.style.display="none",this.currentResults=[],this.activeIndex=-1}escapeHtml(e){return String(e??"").replace(/[&<>"']/g,t=>({"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"})[t]??t)}escapeRegExp(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}show(){this.wrapper.classList.add("engine-2d-search--visible"),requestAnimationFrame(()=>this.input.focus())}hide(){this.wrapper.classList.remove("engine-2d-search--visible"),this.clearResults(),this.input.value="",this.clearBtn.style.opacity="0",this.clearBtn.style.pointerEvents="none"}toggle(){this.wrapper.classList.contains("engine-2d-search--visible")?this.hide():this.show()}dispose(){this.input.removeEventListener("input",this.onInput),this.input.removeEventListener("keydown",this.onKeyDown),this.clearBtn.removeEventListener("click",this.onClear),document.removeEventListener("mousedown",this.onDocMouseDown),document.removeEventListener("keydown",this.onEscape),this.wrapper.parentElement?.removeChild(this.wrapper),this.debounceTimer!==null&&clearTimeout(this.debounceTimer)}}class mi{engine;searchUI=null;constructor(e){this.engine=e;const t=document.getElementById(e?.options?.containerId??"")??e?.container??null;t&&(this.searchUI=new pi(t,this))}search(e){const t=this.normalize(e);return t?(this.engine.loaderModule2d?.model?.textItems??[]).map(n=>{const r=this.getMatchScore(n.text,t);return r==null?null:{id:n.id,name:n.text,type:"文字",layer:n.layer,description:this.getPositionDescription(n),score:r,target:n}}).filter(n=>n!==null).sort((n,r)=>(r.score??0)-(n.score??0)||n.name.length-r.name.length).slice(0,100):[]}onResultSelect(e){const t=e.target;t&&(this.engine.modelToolModule2d?.unhighlightAllModels?.(),this.engine.modelToolModule2d?.highlightModel?.([e.id]),this.fitToText(t))}fitToText(e){const t=e.min?.clone(),i=e.max?.clone(),n=e.anchor?.clone();if((!t||!i||t.distanceTo(i)<1e-6)&&n){const o=Math.max(Number(e.info?.height??100),100);this.engine.cameraModule2d?.fitToExtents({min:[n.x-o,n.y-o,0],max:[n.x+o,n.y+o,0]},2,!0,500);return}if(!t||!i)return;const r=new _.Vector3().subVectors(i,t),s=Math.max(r.x,r.y)<1e-6?2:2.5;this.engine.cameraModule2d?.fitToExtents({min:[t.x,t.y,t.z],max:[i.x,i.y,i.z]},s,!0,500)}getPositionDescription(e){const t=e.anchor??e.min;return t?`X:${t.x.toFixed(0)} Y:${t.y.toFixed(0)}`:""}normalize(e){return String(e??"").trim().toLowerCase().replace(/\s+/g,"")}getMatchScore(e,t){const i=this.normalize(e);if(!i)return null;const n=i.indexOf(t);if(n>=0)return 1e3-n-Math.max(0,i.length-t.length)*.01;let r=0,s=0;for(const o of t){const a=i.indexOf(o,r);if(a<0)return null;s+=a-r,r=a+1}return 500-s-Math.max(0,i.length-t.length)*.01}show(){this.searchUI?.show()}hide(){this.searchUI?.hide()}toggle(){this.searchUI?.toggle()}dispose(){this.searchUI?.dispose(),this.searchUI=null}}const st={dark:{"--e2d-bg":"#1e1f22","--e2d-bg2":"#252526","--e2d-bg3":"#222222","--e2d-bg-hover":"rgba(79,195,247,0.08)","--e2d-bg-accent":"#094771","--e2d-icon-bg":"rgba(255,255,255,0.08)","--e2d-icon-bg-hover":"rgba(255,255,255,0.16)","--e2d-border":"rgba(255,255,255,0.12)","--e2d-border2":"#333333","--e2d-text":"#e0e0e0","--e2d-text2":"#cccccc","--e2d-text3":"rgba(255,255,255,0.35)","--e2d-text4":"#666666","--e2d-text-accent":"#ffffff","--e2d-accent":"#4fc3f7","--e2d-shadow":"rgba(0,0,0,0.50)","--e2d-shadow-lg":"rgba(0,0,0,0.65)","--e2d-cursor":"rgba(255,255,255,0.85)","--e2d-scrollbar":"rgba(255,255,255,0.15)","--e2d-float-bg":"rgba(0,0,0,0.65)","--e2d-float-border":"rgba(255,255,255,0.08)","--e2d-swatch-border":"#444444","--e2d-close":"#aaaaaa","--e2d-close-hover":"#ffffff","--e2d-icon":"rgba(255,255,255,0.4)","--e2d-coord-value":"#76c8ff","--e2d-coord-label":"rgba(255,255,255,0.45)"},light:{"--e2d-bg":"#ffffff","--e2d-bg2":"#ffffff","--e2d-bg3":"#eeeeee","--e2d-bg-hover":"rgba(25,118,210,0.06)","--e2d-bg-accent":"#e3f2fd","--e2d-icon-bg":"rgba(0,0,0,0.06)","--e2d-icon-bg-hover":"rgba(0,0,0,0.12)","--e2d-border":"rgba(0,0,0,0.12)","--e2d-border2":"#e0e0e0","--e2d-text":"#1a1a1a","--e2d-text2":"#444444","--e2d-text3":"rgba(0,0,0,0.40)","--e2d-text4":"#aaaaaa","--e2d-text-accent":"#1565c0","--e2d-accent":"#1976d2","--e2d-shadow":"rgba(0,0,0,0.15)","--e2d-shadow-lg":"rgba(0,0,0,0.22)","--e2d-cursor":"rgba(30,30,30,0.70)","--e2d-scrollbar":"rgba(0,0,0,0.18)","--e2d-float-bg":"#ffffff","--e2d-float-border":"rgba(0,0,0,0.10)","--e2d-swatch-border":"#cccccc","--e2d-close":"#777777","--e2d-close-hover":"#1a1a1a","--e2d-icon":"rgba(0,0,0,0.45)","--e2d-coord-value":"#1976d2","--e2d-coord-label":"rgba(0,0,0,0.50)"}};class gi{container;current;constructor(e,t="dark"){this.container=e,this.current=t,this._apply(t)}_apply(e){const t=st[e];for(const[i,n]of Object.entries(t))this.container.style.setProperty(i,n);this.container.setAttribute("data-e2d-theme",e)}setTheme(e){this.current=e,this._apply(e)}getTheme(){return this.current}toggle(){this.setTheme(this.current==="dark"?"light":"dark")}dispose(){for(const e of Object.keys(st[this.current]))this.container.style.removeProperty(e);this.container.removeAttribute("data-e2d-theme")}}const ot={precision:3,unit:"m",areaUnit:"m²",scale:1};class Ue{manager;points=[];constructor(e){this.manager=e}active(){this.points=[],this.manager.setCurrentTool(this)}disActive(){this.points=[],this.manager.clearPreview()}clearAllPoints(){this.points=[],this.manager.clearPreview()}handleClick(e){this.points.push(e.clone())}handleMove(e){}handleDoubleClick(){}handleRightClick(){this.handleDoubleClick()}handleEnter(){this.handleDoubleClick()}handleEsc(){this.clearAllPoints()}}class yi extends Ue{handleClick(e){super.handleClick(e),this.points.length===2&&(this.manager.addMeasurement("distance",this.points),this.clearAllPoints())}handleMove(e){this.points.length===1&&this.manager.drawPreview("distance",[this.points[0],e])}}class vi extends Ue{handleClick(e){super.handleClick(e),this.manager.drawPreview("area",this.points)}handleMove(e){this.points.length>0&&this.manager.drawPreview("area",[...this.points,e])}handleDoubleClick(){const e=this.manager.removeTrailingDuplicatePoint(this.points);e.length>=3&&this.manager.addMeasurement("area",e),this.clearAllPoints()}}class bi extends Ue{handleClick(e){super.handleClick(e),this.points.length===3&&(this.manager.addMeasurement("angle",this.points),this.clearAllPoints())}handleMove(e){this.points.length>=2&&this.manager.drawPreview("angle",[...this.points,e])}}class wi{distanceMeasure;areaMeasure;angleMeasure;annotationData={distanceAnnotation:[],areaAnnotation:[],angleAnnotation:[]};engine;container;annotationContainer;setting={...ot};isActive=!1;currentTool=null;previewRecord=null;mouseDownPoint=null;hasDraggedAfterMouseDown=!1;currentWorkspaceKey="model";constructor(e){this.engine=e,this.container=e.container,this.distanceMeasure=new yi(this),this.areaMeasure=new vi(this),this.angleMeasure=new bi(this),this.annotationContainer=document.createElement("div"),this.annotationContainer.className="annotation-container",this.annotationContainer.style.pointerEvents="none",this.annotationContainer.style.zIndex="20",this.container.appendChild(this.annotationContainer)}active(){if(this.isActive)return;this.isActive=!0,this.engine.interactionModule2d?.disActive?.();const e=this.engine.renderer.domElement;e.addEventListener("mousedown",this.handleMouseDown,!0),e.addEventListener("click",this.handleClick,!0),e.addEventListener("mousemove",this.handleMove,!0),e.addEventListener("dblclick",this.handleDoubleClick,!0),e.addEventListener("contextmenu",this.handleContextMenu,!0),window.addEventListener("keydown",this.handleKeyDown,!0)}disActive(){if(!this.isActive)return;this.quitDraw(),this.isActive=!1;const e=this.engine.renderer.domElement;e.removeEventListener("mousedown",this.handleMouseDown,!0),e.removeEventListener("click",this.handleClick,!0),e.removeEventListener("mousemove",this.handleMove,!0),e.removeEventListener("dblclick",this.handleDoubleClick,!0),e.removeEventListener("contextmenu",this.handleContextMenu,!0),window.removeEventListener("keydown",this.handleKeyDown,!0),this.engine.interactionModule2d?.active?.(),this.clearAll()}quitDraw(){this.currentTool?.disActive(),this.currentTool=null,this.clearPreview()}activate(e){this.active(),this.disActiveMeasureTools(),e==="distance"&&this.distanceMeasure.active(),e==="area"&&this.areaMeasure.active(),e==="angle"&&this.angleMeasure.active()}clearAllPoints(){this.distanceMeasure.clearAllPoints(),this.areaMeasure.clearAllPoints(),this.angleMeasure.clearAllPoints()}clearAll(){Object.values(this.annotationData).forEach(e=>this.removeRecords(e,t=>t.workspaceKey===this.currentWorkspaceKey)),this.clearPreview()}cancelCurrentSelectedAnnotation(){Object.values(this.annotationData).flat().forEach(e=>{e.highlight=!1,this.applyRecordHighlight(e,!1)})}saveSetting(e){this.setting={...this.setting,...e,precision:this.normalizePrecision(e.precision??this.setting.precision),scale:Number.isFinite(e.scale)&&e.scale>0?e.scale:this.setting.scale},this.refreshLabels()}setPrecision(e){this.saveSetting({precision:e})}getSetting(){return{...this.setting}}update(){this.updateRecords(Object.values(this.annotationData).flat().filter(e=>e.workspaceKey===this.currentWorkspaceKey)),this.previewRecord&&this.updateRecordSvg(this.previewRecord)}setWorkspace(e){!e||e===this.currentWorkspaceKey||(this.clearPreview(),this.cancelCurrentSelectedAnnotation(),this.currentWorkspaceKey=e,this.refreshWorkspaceVisibility())}dispose(){this.disActive(),this.clearAll(),this.annotationContainer.remove()}setCurrentTool(e){this.currentTool=e}drawPreview(e,t){this.clearPreview(),!(t.length<2)&&(this.previewRecord=this.createRecord(e,t,!0),this.annotationContainer.appendChild(this.previewRecord.container),this.updateRecordSvg(this.previewRecord))}clearPreview(){this.previewRecord?.container.remove(),this.previewRecord=null}addMeasurement(e,t){const i=this.createRecord(e,t,!1);return this.annotationContainer.appendChild(i.container),this.getRecords(e).push(i),this.updateRecordSvg(i),this.engine.events?.trigger?.("measure-changed",i),i}deleteSelected(){Object.values(this.annotationData).forEach(e=>{for(let t=e.length-1;t>=0;t--)e[t].workspaceKey===this.currentWorkspaceKey&&e[t].highlight&&(e[t].container.remove(),e.splice(t,1))})}removeTrailingDuplicatePoint(e){if(e.length<2)return e.map(r=>r.clone());const t=e.map(r=>r.clone()),i=t[t.length-1],n=t[t.length-2];return i.distanceTo(n)<1e-6&&t.pop(),t}disActiveMeasureTools(){this.distanceMeasure.disActive(),this.areaMeasure.disActive(),this.angleMeasure.disActive()}handleMouseDown=e=>{this.mouseDownPoint=new _.Vector2(e.clientX,e.clientY),this.hasDraggedAfterMouseDown=!1};handleClick=e=>{!this.currentTool||this.hasDraggedAfterMouseDown||(e.preventDefault(),e.stopImmediatePropagation(),this.currentTool.handleClick(this.eventToWorld(e)))};handleMove=e=>{this.currentTool&&(this.mouseDownPoint&&new _.Vector2(e.clientX,e.clientY).distanceTo(this.mouseDownPoint)>3&&(this.hasDraggedAfterMouseDown=!0),this.currentTool.handleMove(this.eventToWorld(e)))};handleDoubleClick=e=>{this.currentTool&&(e.preventDefault(),e.stopImmediatePropagation(),this.currentTool.handleDoubleClick())};handleContextMenu=e=>{this.currentTool&&(e.preventDefault(),e.stopImmediatePropagation(),this.currentTool.handleRightClick())};handleKeyDown=e=>{this.isActive&&(e.key==="Escape"&&(e.preventDefault(),e.stopImmediatePropagation(),this.currentTool?.handleEsc(),this.disActive(),this.engine.events?.trigger?.("quit_measure_draw",!0),window.dispatchEvent(new CustomEvent("D2MeasureQuit"))),(e.key==="Delete"||e.key==="Backspace")&&(e.preventDefault(),e.stopImmediatePropagation(),this.deleteSelected()),e.key==="Enter"&&this.currentTool&&(e.preventDefault(),this.currentTool.handleEnter()))};eventToWorld(e){const t=this.engine.renderer.domElement.getBoundingClientRect(),i=this.engine.cameraModule2d.screenToWorld(e.clientX-t.left,e.clientY-t.top);return i.z=0,i}createRecord(e,t,i){const n=document.createElement("div");n.className=`${e}-annotation`,n.style.position="absolute",n.style.left="0px",n.style.top="0px",n.style.pointerEvents="none";const r=this.createSvg(e);i&&(r.style.opacity="0.65"),n.appendChild(r);const s=this.computeValue(e,t),o={id:this.createId(),type:e,workspaceKey:this.currentWorkspaceKey,points:t.map(a=>a.clone()),container:n,svg:r,value:s,text:this.formatValue(e,s),isSelect:i};return i||this.bindRecordSelection(o),o}createSvg(e){const t=document.createElementNS("http://www.w3.org/2000/svg","svg");if(t.classList.add("measureSvg"),t.style.left="0",t.style.top="0",t.style.pointerEvents="none",e==="area"){const o=this.svgElement("polygon");o.setAttribute("fill","rgba(0, 155, 234, 0.12)"),o.setAttribute("stroke","none"),t.appendChild(o)}const i=e==="angle"?2:1;for(let o=0;o<i;o++){const a=this.svgElement("polyline");a.classList.add("measureLine"),a.setAttribute("stroke-width","2"),a.setAttribute("style","fill: none; opacity: 1;"),t.appendChild(a)}const n=e==="angle"?3:e==="distance"?2:0;for(let o=0;o<n;o++){const a=this.svgElement("circle");a.classList.add("measurePointer"),a.setAttribute("r","5"),t.appendChild(a)}const r=this.svgElement("rect");r.classList.add("measureBack"),r.setAttribute("width","100"),r.setAttribute("height","25"),r.style.pointerEvents="auto",r.style.cursor="pointer",t.appendChild(r);const s=this.svgElement("text");return s.classList.add("measureLabel"),s.setAttribute("text-anchor","middle"),t.appendChild(s),t}bindRecordSelection(e){e.svg.getElementsByTagName("rect")[0].addEventListener("click",i=>{i.preventDefault(),i.stopPropagation(),this.cancelCurrentSelectedAnnotation(),e.highlight=!0,this.applyRecordHighlight(e,!0),this.engine.events?.trigger?.("measure-click",e)})}applyRecordHighlight(e,t){[e.svg,...Array.from(e.svg.getElementsByTagName("polyline")),...Array.from(e.svg.getElementsByTagName("circle")),...Array.from(e.svg.getElementsByTagName("polygon")),...Array.from(e.svg.getElementsByTagName("rect")),...Array.from(e.svg.getElementsByTagName("text"))].forEach(n=>{n.classList.toggle("Hight",t),n.classList.toggle("measure-2d-selected",t)})}svgElement(e){return document.createElementNS("http://www.w3.org/2000/svg",e)}updateRecords(e){e.forEach(t=>this.updateRecordSvg(t))}updateRecordSvg(e){const t=this.container.clientWidth||1,i=this.container.clientHeight||1;e.svg.setAttribute("width",`${t}`),e.svg.setAttribute("height",`${i}`),e.svg.style.width=`${t}px`,e.svg.style.height=`${i}px`;const n=e.points.map(r=>this.worldToScreen(r));e.type==="distance"&&this.updateDistanceSvg(e,n),e.type==="area"&&this.updateAreaSvg(e,n),e.type==="angle"&&this.updateAngleSvg(e,n)}updateDistanceSvg(e,t){const[i,n]=t,r=e.svg.getElementsByTagName("polyline")[0],s=e.svg.getElementsByTagName("circle");r.setAttribute("points",`${i.x},${i.y} ${n.x},${n.y}`),s[0].setAttribute("cx",`${i.x}`),s[0].setAttribute("cy",`${i.y}`),s[1].setAttribute("cx",`${n.x}`),s[1].setAttribute("cy",`${n.y}`),this.updateLabel(e,(i.x+n.x)/2,(i.y+n.y)/2)}updateAreaSvg(e,t){const i=t.map(o=>`${o.x},${o.y}`).join(" "),r=(t.length>=3?[...t,t[0]]:t).map(o=>`${o.x},${o.y}`).join(" ");e.svg.getElementsByTagName("polygon")[0].setAttribute("points",t.length>=3?i:""),e.svg.getElementsByTagName("polyline")[0].setAttribute("points",r);const s=t.reduce((o,a)=>(o.x+=a.x,o.y+=a.y,o),{x:0,y:0});this.updateLabel(e,s.x/t.length,s.y/t.length)}updateAngleSvg(e,t){const[i,n,r]=t,s=e.svg.getElementsByTagName("polyline"),o=e.svg.getElementsByTagName("circle");s[0].setAttribute("points",`${i.x},${i.y} ${n.x},${n.y}`),s[1].setAttribute("points",`${n.x},${n.y} ${r.x},${r.y}`),[i,n,r].forEach((a,l)=>{o[l].setAttribute("cx",`${a.x}`),o[l].setAttribute("cy",`${a.y}`)}),this.updateLabel(e,n.x,n.y-30)}updateLabel(e,t,i){e.value=this.computeValue(e.type,e.points),e.text=this.formatValue(e.type,e.value);const n=e.svg.getElementsByTagName("rect")[0],r=e.svg.getElementsByTagName("text")[0],s=Math.max(100,e.text.length*9+22);n.setAttribute("x",`${t-s/2}`),n.setAttribute("y",`${i-12.5}`),n.setAttribute("width",`${s}`),r.setAttribute("x",`${t}`),r.setAttribute("y",`${i+4}`),r.textContent=e.text}worldToScreen(e){return this.engine.cameraModule2d.worldToScreen(e.x,e.y)}computeValue(e,t){return e==="distance"?t[0].distanceTo(t[1])*this.setting.scale:e==="angle"?this.computeAngle(t[0],t[1],t[2]):this.computeArea(t)*this.setting.scale*this.setting.scale}computeArea(e){if(e.length<3)return 0;let t=0;for(let i=0;i<e.length;i++){const n=e[i],r=e[(i+1)%e.length];t+=n.x*r.y-r.x*n.y}return Math.abs(t)/2}computeAngle(e,t,i){const n=e.clone().sub(t).normalize(),r=i.clone().sub(t).normalize(),s=_.MathUtils.clamp(n.dot(r),-1,1);return _.MathUtils.radToDeg(Math.acos(s))}formatValue(e,t){return e==="angle"?`${t.toFixed(this.setting.precision)}°`:e==="area"?`${t.toFixed(this.setting.precision)} ${this.setting.areaUnit??`${this.setting.unit}²`}`:`${t.toFixed(this.setting.precision)} ${this.setting.unit}`}refreshLabels(){Object.values(this.annotationData).flat().filter(e=>e.workspaceKey===this.currentWorkspaceKey).forEach(e=>{e.value=this.computeValue(e.type,e.points),e.text=this.formatValue(e.type,e.value),this.updateRecordSvg(e)})}refreshWorkspaceVisibility(){Object.values(this.annotationData).flat().forEach(e=>{e.container.style.display=e.workspaceKey===this.currentWorkspaceKey?"":"none"})}removeRecords(e,t){for(let i=e.length-1;i>=0;i-=1)t(e[i])&&(e[i].container.remove(),e.splice(i,1))}getRecords(e){return e==="distance"?this.annotationData.distanceAnnotation:e==="area"?this.annotationData.areaAnnotation:this.annotationData.angleAnnotation}normalizePrecision(e){return Number.isFinite(e)?Math.max(0,Math.min(8,Math.round(e))):ot.precision}createId(){return`measure-2d-${Date.now()}-${Math.random().toString(16).slice(2)}`}}const Ve={stroke:"#ff4d4f",fill:"rgba(255, 77, 79, 0.08)",strokeWidth:2,fontSize:16,cloudRadius:10},xi={none:xe("/assets/icon/选择.svg",typeof document>"u"&&typeof location>"u"?require("url").pathToFileURL(__filename).href:typeof document>"u"?location.href:se&&se.tagName.toUpperCase()==="SCRIPT"&&se.src||new URL("dwg-preview.umd.js",document.baseURI).href),line:xe("/assets/icon/线.svg",typeof document>"u"&&typeof location>"u"?require("url").pathToFileURL(__filename).href:typeof document>"u"?location.href:se&&se.tagName.toUpperCase()==="SCRIPT"&&se.src||new URL("dwg-preview.umd.js",document.baseURI).href),arrow:xe("/assets/icon/箭头.svg",typeof document>"u"&&typeof location>"u"?require("url").pathToFileURL(__filename).href:typeof document>"u"?location.href:se&&se.tagName.toUpperCase()==="SCRIPT"&&se.src||new URL("dwg-preview.umd.js",document.baseURI).href),rect:xe("/assets/icon/矩形.svg",typeof document>"u"&&typeof location>"u"?require("url").pathToFileURL(__filename).href:typeof document>"u"?location.href:se&&se.tagName.toUpperCase()==="SCRIPT"&&se.src||new URL("dwg-preview.umd.js",document.baseURI).href),ellipse:xe("/assets/icon/圆形.svg",typeof document>"u"&&typeof location>"u"?require("url").pathToFileURL(__filename).href:typeof document>"u"?location.href:se&&se.tagName.toUpperCase()==="SCRIPT"&&se.src||new URL("dwg-preview.umd.js",document.baseURI).href),polygon:xe("/assets/icon/面积.svg",typeof document>"u"&&typeof location>"u"?require("url").pathToFileURL(__filename).href:typeof document>"u"?location.href:se&&se.tagName.toUpperCase()==="SCRIPT"&&se.src||new URL("dwg-preview.umd.js",document.baseURI).href),text:xe("/assets/icon/文字.svg",typeof document>"u"&&typeof location>"u"?require("url").pathToFileURL(__filename).href:typeof document>"u"?location.href:se&&se.tagName.toUpperCase()==="SCRIPT"&&se.src||new URL("dwg-preview.umd.js",document.baseURI).href),cloudline:xe("/assets/icon/云线.svg",typeof document>"u"&&typeof location>"u"?require("url").pathToFileURL(__filename).href:typeof document>"u"?location.href:se&&se.tagName.toUpperCase()==="SCRIPT"&&se.src||new URL("dwg-preview.umd.js",document.baseURI).href)},ki="data:image/svg+xml;utf8,"+encodeURIComponent('<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="#1f2937" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M3 6h18"/><path d="M8 6V4h8v2"/><path d="M6 6l1 16h10l1-16"/><path d="M10 11v6"/><path d="M14 11v6"/></svg>'),Mi="data:image/svg+xml;utf8,"+encodeURIComponent('<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="#1f2937" stroke-width="2" stroke-linecap="round"><path d="M6 6l12 12"/><path d="M18 6L6 18"/></svg>');class _i{engine;container;layer;svg;toolbar;records=[];isActive=!1;currentType=null;style={...Ve};draft=null;draftStart=null;polygonPoints=[];currentWorkspaceKey="model";mouseDownPoint=null;hasDraggedAfterMouseDown=!1;buttons={};constructor(e){this.engine=e,this.container=e.container,getComputedStyle(this.container).position==="static"&&(this.container.style.position="relative"),this.layer=document.createElement("div"),this.layer.className="markup-2d-layer",this.svg=document.createElementNS("http://www.w3.org/2000/svg","svg"),this.svg.classList.add("markup-2d-svg"),this.layer.appendChild(this.svg),this.toolbar=this.createToolbar(),this.layer.appendChild(this.toolbar),this.container.appendChild(this.layer)}active(e){if(this.engine.measure?.quitDraw?.(),!this.isActive){this.isActive=!0,this.engine.interactionModule2d?.disActive?.();const t=this.engine.renderer.domElement;t.addEventListener("mousedown",this.handleMouseDown,!0),t.addEventListener("mousemove",this.handleMouseMove,!0),t.addEventListener("mouseup",this.handleMouseUp,!0),t.addEventListener("click",this.handleClick,!0),t.addEventListener("dblclick",this.handleDoubleClick,!0),t.addEventListener("wheel",this.blockDrawingEvent,!0),t.addEventListener("touchstart",this.blockDrawingEvent,!0),t.addEventListener("touchmove",this.blockDrawingEvent,!0),window.addEventListener("keydown",this.handleKeyDown,!0)}this.showToolbar(),e&&this.setDrawType(e)}show(){this.active()}hide(){this.hideToolbar(),this.disActive()}disActive(){if(!this.isActive)return;this.isActive=!1,this.currentType=null,this.clearDraft(),this.polygonPoints=[],this.syncToolbar();const e=this.engine.renderer.domElement;e.removeEventListener("mousedown",this.handleMouseDown,!0),e.removeEventListener("mousemove",this.handleMouseMove,!0),e.removeEventListener("mouseup",this.handleMouseUp,!0),e.removeEventListener("click",this.handleClick,!0),e.removeEventListener("dblclick",this.handleDoubleClick,!0),e.removeEventListener("wheel",this.blockDrawingEvent,!0),e.removeEventListener("touchstart",this.blockDrawingEvent,!0),e.removeEventListener("touchmove",this.blockDrawingEvent,!0),window.removeEventListener("keydown",this.handleKeyDown,!0),this.engine.interactionModule2d?.active?.()}setDrawType(e){this.currentType=e==="none"?null:e,this.clearDraft(),this.polygonPoints=[],this.syncToolbar()}update(){const e=this.container.clientWidth||1,t=this.container.clientHeight||1;this.svg.setAttribute("width",`${e}`),this.svg.setAttribute("height",`${t}`),this.svg.style.width=`${e}px`,this.svg.style.height=`${t}px`,this.records.forEach(i=>{i.element.style.display=i.data.workspaceKey===this.currentWorkspaceKey?"":"none",this.updateElement(i)}),this.draft&&this.updateElement(this.draft)}setWorkspace(e){!e||e===this.currentWorkspaceKey||(this.currentWorkspaceKey=e,this.clearDraft(),this.polygonPoints=[],this.cancelSelected(),this.update())}getData(){return this.records.map(e=>this.cloneData(e.data))}restoreData(e=[]){this.clearAll(!0),e.forEach(t=>this.addMarkup(t)),this.update()}get(){return{cameraViewState:this.engine.cameraModule2d?.getViewState?.()??null,markupData:this.getData()}}restore(e){e&&(e.cameraViewState&&this.engine.cameraModule2d?.applyViewState?.(e.cameraViewState),this.restoreData(e.markupData??[]))}addMarkup(e){const t={id:e.id??this.createId(),type:e.type,workspaceKey:e.workspaceKey??this.currentWorkspaceKey,points:e.points.map(n=>({x:n.x,y:n.y,z:n.z??0})),text:e.text,style:{...this.style,...e.style??{}}},i=this.createRecord(t);return this.records.push(i),this.svg.appendChild(i.element),this.updateElement(i),this.engine.events?.trigger?.("markup-changed",this.cloneData(t)),this.cloneData(t)}clearAll(e=!1){for(let t=this.records.length-1;t>=0;t-=1){const i=this.records[t];!e&&i.data.workspaceKey!==this.currentWorkspaceKey||(i.element.remove(),this.records.splice(t,1))}this.clearDraft()}deleteSelected(){for(let e=this.records.length-1;e>=0;e-=1)this.records[e].selected&&(this.records[e].element.remove(),this.records.splice(e,1));this.engine.events?.trigger?.("markup-changed",this.getData())}dispose(){this.disActive(),this.records.forEach(e=>e.element.remove()),this.records=[],this.layer.remove()}blockDrawingEvent=e=>{this.currentType&&(e instanceof MouseEvent&&this.engine.cadCursorUI?.updateFromMouseEvent?.(e),e.preventDefault(),e.stopImmediatePropagation())};handleMouseDown=e=>{this.currentType&&(this.blockDrawingEvent(e),this.mouseDownPoint=new _.Vector2(e.clientX,e.clientY),this.hasDraggedAfterMouseDown=!1)};handleMouseMove=e=>{if(this.currentType){if(this.blockDrawingEvent(e),this.mouseDownPoint&&e.buttons!==0){const t=new _.Vector2(e.clientX,e.clientY);this.hasDraggedAfterMouseDown=t.distanceTo(this.mouseDownPoint)>3}if(this.isMultiPointType(this.currentType)&&this.polygonPoints.length>0){this.drawMultiPointDraft(this.eventToWorld(e));return}!this.draft||!this.draftStart||(this.draft.data.points=[this.pointToData(this.draftStart),this.pointToData(this.eventToWorld(e))],this.updateElement(this.draft))}};handleMouseUp=e=>{this.currentType&&(this.blockDrawingEvent(e),this.mouseDownPoint=null)};handleClick=e=>{if(this.currentType&&(this.blockDrawingEvent(e),!this.hasDraggedAfterMouseDown)){if(this.currentType==="text"){const t=window.prompt("请输入标记文字","文字")??"";t.trim()&&this.addMarkup({type:"text",points:[this.pointToData(this.eventToWorld(e))],text:t.trim()});return}if(this.isTwoPointType(this.currentType)){const t=this.eventToWorld(e);this.draftStart?this.finishTwoPointDraft(t):this.startTwoPointDraft(t);return}this.isMultiPointType(this.currentType)&&(this.polygonPoints.push(this.eventToWorld(e)),this.drawMultiPointDraft())}};handleDoubleClick=e=>{if(!this.currentType||!this.isMultiPointType(this.currentType))return;this.blockDrawingEvent(e);const t=this.currentType==="cloudline"?2:3,i=this.removeTrailingDuplicatePoints(this.polygonPoints);i.length>=t&&this.addMarkup({type:this.currentType,points:i.map(n=>this.pointToData(n))}),this.polygonPoints=[],this.clearDraft()};handleKeyDown=e=>{if(this.isActive&&(e.key==="Escape"&&(e.preventDefault(),this.clearDraft(),this.polygonPoints=[],this.setDrawType("none")),(e.key==="Delete"||e.key==="Backspace")&&(e.preventDefault(),this.deleteSelected()),e.key==="Enter"&&this.currentType&&this.isMultiPointType(this.currentType))){e.preventDefault();const t=this.currentType==="cloudline"?2:3,i=this.removeTrailingDuplicatePoints(this.polygonPoints);i.length>=t&&this.addMarkup({type:this.currentType,points:i.map(n=>this.pointToData(n))}),this.polygonPoints=[],this.clearDraft()}};createToolbar(){const e=document.createElement("div");e.className="markup-2d-toolbar",[{type:"none",title:"选择"},{type:"line",title:"直线"},{type:"arrow",title:"箭头"},{type:"rect",title:"矩形"},{type:"ellipse",title:"圆形/椭圆"},{type:"polygon",title:"多边形,双击或 Enter 结束"},{type:"cloudline",title:"云线,双击或 Enter 结束"},{type:"text",title:"文字"}].forEach(a=>{const l=this.createIconButton(a.title,xi[a.type]);l.onclick=()=>{this.active(),this.setDrawType(a.type)},a.type!=="none"&&(this.buttons[a.type]=l),e.appendChild(l)}),e.appendChild(this.createDivider());const i=document.createElement("input");i.type="color",i.value=this.style.stroke,i.title="颜色",i.oninput=()=>{this.style.stroke=i.value,this.style.fill=this.hexToTransparent(i.value)},e.appendChild(i);const n=document.createElement("input");n.type="number",n.min="1",n.max="20",n.value=`${this.style.strokeWidth}`,n.title="线宽",n.onchange=()=>{this.style.strokeWidth=this.normalizeNumber(n.valueAsNumber,1,20,Ve.strokeWidth)},e.appendChild(n);const r=document.createElement("input");r.type="number",r.min="10",r.max="72",r.value=`${this.style.fontSize}`,r.title="字号",r.onchange=()=>{this.style.fontSize=this.normalizeNumber(r.valueAsNumber,10,72,Ve.fontSize)},e.appendChild(r),e.appendChild(this.createDivider());const s=this.createIconButton("清空",ki);s.onclick=()=>this.clearAll(),e.appendChild(s);const o=this.createIconButton("关闭",Mi);return o.onclick=()=>{this.hideToolbar(),this.disActive()},e.appendChild(o),e}createDivider(){const e=document.createElement("div");return e.className="markup-2d-divider",e}createIconButton(e,t){const i=document.createElement("button");i.type="button",i.title=e,i.setAttribute("aria-label",e),i.classList.add("markup-2d-icon-button");const n=document.createElement("img");return n.src=t,n.alt=e,n.draggable=!1,i.appendChild(n),i}showToolbar(){this.toolbar.style.display="flex"}hideToolbar(){this.toolbar.style.display="none"}syncToolbar(){Object.entries(this.buttons).forEach(([e,t])=>{t?.classList.toggle("active",e===this.currentType)})}finishDraft(){if(!this.draft)return;const e=this.draft;this.draft=null,e.element.style.pointerEvents="auto",this.records.push(e),this.updateElement(e),this.engine.events?.trigger?.("markup-changed",this.cloneData(e.data))}clearDraft(){this.draft?.element.remove(),this.draft=null,this.draftStart=null}startTwoPointDraft(e){this.draftStart=e.clone(),this.draft=this.createRecord({id:this.createId(),type:this.currentType,workspaceKey:this.currentWorkspaceKey,points:[this.pointToData(e),this.pointToData(e)],style:{...this.style}}),this.draft.element.setAttribute("opacity","0.65"),this.draft.element.style.pointerEvents="none",this.svg.appendChild(this.draft.element),this.updateElement(this.draft)}finishTwoPointDraft(e){!this.draft||!this.draftStart||this.draftStart.distanceTo(e)<1e-6||(this.draft.data.points=[this.pointToData(this.draftStart),this.pointToData(e)],this.draft.element.removeAttribute("opacity"),this.finishDraft(),this.draftStart=null)}drawMultiPointDraft(e){if(this.clearDraft(),this.polygonPoints.length===0)return;const t=e?[...this.polygonPoints,e]:this.polygonPoints;this.draft=this.createRecord({id:this.createId(),type:this.currentType==="cloudline"?"cloudline":"polygon",workspaceKey:this.currentWorkspaceKey,points:t.map(i=>this.pointToData(i)),style:{...this.style}}),this.draft.element.setAttribute("opacity","0.65"),this.draft.element.style.pointerEvents="none",this.svg.appendChild(this.draft.element),this.updateElement(this.draft)}createRecord(e){const t=this.createElement(e.type);t.classList.add("markup-2d-shape");const i={data:this.cloneData(e),element:t};return this.applyStyle(i),this.bindSelection(i),i}createElement(e){return e==="rect"?this.svgElement("rect"):e==="ellipse"?this.svgElement("ellipse"):e==="text"?this.svgElement("text"):e==="polygon"||e==="cloudline"?this.svgElement("g"):this.svgElement("g")}bindSelection(e){e.element.addEventListener("click",t=>{t.preventDefault(),t.stopPropagation(),this.cancelSelected(),e.selected=!0,e.element.classList.add("selected"),this.engine.events?.trigger?.("markup-click",this.cloneData(e.data))})}cancelSelected(){this.records.forEach(e=>{e.selected=!1,e.element.classList.remove("selected")})}updateElement(e){this.applyStyle(e);const t=e.data.points.map(i=>this.worldToScreen(i));e.data.type==="line"&&this.updateLine(e,t,!1),e.data.type==="arrow"&&this.updateLine(e,t,!0),e.data.type==="rect"&&this.updateRect(e,t),e.data.type==="ellipse"&&this.updateEllipse(e,t),e.data.type==="text"&&this.updateText(e,t[0]),e.data.type==="polygon"&&this.updatePolygon(e,t),e.data.type==="cloudline"&&this.updateCloudLine(e,t)}updateLine(e,t,i){const n=e.element;if(n.innerHTML="",t.length<2)return;const[r,s]=t,o=this.svgElement("line");if(o.setAttribute("x1",`${r.x}`),o.setAttribute("y1",`${r.y}`),o.setAttribute("x2",`${s.x}`),o.setAttribute("y2",`${s.y}`),this.applySvgPaint(o,e.data.style,!1),n.appendChild(o),e===this.draft&&this.drawVertexMarkers(n,t,e.data.style),!i)return;const a=this.createArrowHead(r,s,e.data.style.strokeWidth);this.applySvgPaint(a,e.data.style,!0),a.setAttribute("fill",e.data.style.stroke),n.appendChild(a)}updateRect(e,t){if(t.length<2)return;const[i,n]=t,r=e.element;r.setAttribute("x",`${Math.min(i.x,n.x)}`),r.setAttribute("y",`${Math.min(i.y,n.y)}`),r.setAttribute("width",`${Math.abs(n.x-i.x)}`),r.setAttribute("height",`${Math.abs(n.y-i.y)}`)}updateEllipse(e,t){if(t.length<2)return;const[i,n]=t,r=e.element;r.setAttribute("cx",`${(i.x+n.x)/2}`),r.setAttribute("cy",`${(i.y+n.y)/2}`),r.setAttribute("rx",`${Math.abs(n.x-i.x)/2}`),r.setAttribute("ry",`${Math.abs(n.y-i.y)/2}`)}updateText(e,t){const i=e.element;i.setAttribute("x",`${t.x}`),i.setAttribute("y",`${t.y}`),i.textContent=e.data.text??""}updatePolygon(e,t){const i=e.element;if(i.innerHTML="",t.length===0)return;const n=t.map(s=>`${s.x},${s.y}`).join(" "),r=t.length>=3?this.svgElement("polygon"):this.svgElement("polyline");r.setAttribute("points",n),this.applySvgPaint(r,e.data.style,t.length>=3),i.appendChild(r),e===this.draft&&this.drawVertexMarkers(i,t,e.data.style)}updateCloudLine(e,t){const i=e.element;if(i.innerHTML="",t.length===0)return;const n=this.svgElement("path");n.setAttribute("d",this.buildCloudPath(t,e.data.style.cloudRadius)),this.applySvgPaint(n,e.data.style,!1),i.appendChild(n),e===this.draft&&this.drawVertexMarkers(i,t,e.data.style)}drawVertexMarkers(e,t,i){t.forEach(n=>{const r=this.svgElement("circle");r.setAttribute("cx",`${n.x}`),r.setAttribute("cy",`${n.y}`),r.setAttribute("r",`${Math.max(3,i.strokeWidth+2)}`),r.setAttribute("fill",i.stroke),r.setAttribute("stroke","#ffffff"),r.setAttribute("stroke-width","1"),e.appendChild(r)})}applyStyle(e){e.data.type==="line"||e.data.type==="arrow"||e.data.type==="polygon"||e.data.type==="cloudline"||(this.applySvgPaint(e.element,e.data.style,e.data.type!=="text"&&e.data.type!=="cloudline"),e.data.type==="text"&&(e.element.setAttribute("font-size",`${e.data.style.fontSize}`),e.element.setAttribute("dominant-baseline","middle"),e.element.setAttribute("fill",e.data.style.stroke),e.element.setAttribute("stroke","none")))}applySvgPaint(e,t,i){e.setAttribute("stroke",t.stroke),e.setAttribute("stroke-width",`${t.strokeWidth}`),e.setAttribute("fill",i?t.fill:"none"),e.setAttribute("stroke-linecap","round"),e.setAttribute("stroke-linejoin","round")}createArrowHead(e,t,i){const n=Math.atan2(t.y-e.y,t.x-e.x),r=Math.max(10,i*5),s={x:t.x-r*Math.cos(n-Math.PI/6),y:t.y-r*Math.sin(n-Math.PI/6)},o={x:t.x-r*Math.cos(n+Math.PI/6),y:t.y-r*Math.sin(n+Math.PI/6)},a=this.svgElement("polygon");return a.setAttribute("points",`${t.x},${t.y} ${s.x},${s.y} ${o.x},${o.y}`),a}buildCloudPath(e,t){if(e.length===0)return"";if(e.length===1)return`M ${e[0].x} ${e[0].y}`;const i=Math.max(4,t),n=[`M ${e[0].x} ${e[0].y}`];for(let r=0;r<e.length-1;r+=1){const s=e[r],o=e[r+1],a=o.x-s.x,l=o.y-s.y,c=Math.hypot(a,l);if(c<1e-6)continue;const f=Math.max(1,Math.ceil(c/(i*1.6)));for(let p=0;p<f;p+=1){const d=p/f,y=(p+1)/f,h=(d+y)/2,g={x:s.x+a*h-l/c*i*.7,y:s.y+l*h+a/c*i*.7},v={x:s.x+a*y,y:s.y+l*y};n.push(`Q ${g.x} ${g.y} ${v.x} ${v.y}`)}}return n.join(" ")}isMultiPointType(e){return e==="polygon"||e==="cloudline"}isTwoPointType(e){return e==="line"||e==="arrow"||e==="rect"||e==="ellipse"}removeTrailingDuplicatePoints(e){const t=e.map(i=>i.clone());for(;t.length>=2&&t[t.length-1].distanceTo(t[t.length-2])<1e-6;)t.pop();return t}eventToWorld(e){const t=this.engine.renderer.domElement.getBoundingClientRect(),i=this.engine.cameraModule2d.screenToWorld(e.clientX-t.left,e.clientY-t.top);return i.z=0,i}worldToScreen(e){return this.engine.cameraModule2d.worldToScreen(e.x,e.y)}pointToData(e){return{x:e.x,y:e.y,z:e.z}}svgElement(e){return document.createElementNS("http://www.w3.org/2000/svg",e)}cloneData(e){return{...e,points:e.points.map(t=>({...t})),style:{...e.style}}}hexToTransparent(e){const t=e.replace("#",""),i=parseInt(t.slice(0,2),16),n=parseInt(t.slice(2,4),16),r=parseInt(t.slice(4,6),16);return`rgba(${i}, ${n}, ${r}, 0.08)`}normalizeNumber(e,t,i,n){return Number.isFinite(e)?Math.max(t,Math.min(i,Math.round(e))):n}createId(){return`markup-2d-${Date.now()}-${Math.random().toString(16).slice(2)}`}}class Ci{container;labelContainer;projectCoordinate;pickCoordinate;emitEvent;labels=new Map;clickCallbacks=new Set;pickResolver=null;isPicking=!1;constructor(e){this.container=e.container,this.projectCoordinate=e.projectCoordinate,this.pickCoordinate=e.pickCoordinate,this.emitEvent=e.emitEvent,this.labelContainer=document.createElement("div"),this.labelContainer.className=e.className??"bim-engine-label-container",this.labelContainer.style.cssText=["position:absolute","left:0","top:0","width:100%","height:100%","pointer-events:none","overflow:hidden","z-index:1200"].join(";"),this.container.appendChild(this.labelContainer)}pickPoint(){return this.cancelPick(),this.isPicking=!0,this.container.style.cursor="crosshair",this.addPickBlockers(),this.container.addEventListener("click",this.handlePickClick,!0),new Promise(e=>{this.pickResolver=e})}startPickPoint(e){const t=this.pickPoint();return e&&t.then(e),t}createLabel(e){const t=e.id??this.createId();if(this.labels.has(t))throw new Error(`LabelManager: label "${t}" already exists`);const i=this.createElement(t),n={id:t,coordinate:{...e.coordinate},icon:e.icon,name:e.name,data:e.data,size:e.iconSize??e.size??28,visible:e.visible??!0,element:i};return this.labels.set(t,n),this.labelContainer.appendChild(i),this.renderLabel(n),this.updateLabelPosition(n),this.emitEvent?.("label-created",this.toPayload(n)),t}updateLabel(e,t){const i=this.labels.get(e);return i?(t.coordinate&&(i.coordinate={...t.coordinate}),t.icon!==void 0&&(i.icon=t.icon),t.name!==void 0&&(i.name=t.name),t.data!==void 0&&(i.data=t.data),t.iconSize!==void 0&&(i.size=t.iconSize),t.size!==void 0&&(i.size=t.size),t.visible!==void 0&&(i.visible=t.visible),this.renderLabel(i),this.updateLabelPosition(i),this.emitEvent?.("label-updated",this.toPayload(i)),!0):!1}deleteLabel(e){const t=this.labels.get(e);return t?(t.element.remove(),this.labels.delete(e),this.emitEvent?.("label-deleted",{id:e}),!0):!1}removeLabel(e){return this.deleteLabel(e)}clearLabels(){Array.from(this.labels.keys()).forEach(e=>this.deleteLabel(e))}getLabel(e){return this.labels.get(e)}getLabels(){return Array.from(this.labels.values())}onLabelClick(e){return this.clickCallbacks.add(e),()=>this.offLabelClick(e)}offLabelClick(e){this.clickCallbacks.delete(e)}update(){this.labels.forEach(e=>this.updateLabelPosition(e))}cancelPick(){this.isPicking&&(this.isPicking=!1,this.container.style.cursor="",this.removePickBlockers(),this.container.removeEventListener("click",this.handlePickClick,!0),this.pickResolver?.(null),this.pickResolver=null)}dispose(){this.cancelPick(),this.clearLabels(),this.clickCallbacks.clear(),this.labelContainer.remove()}createElement(e){const t=document.createElement("div");return t.dataset.labelId=e,t.style.cssText=["position:absolute","display:flex","flex-direction:column","align-items:center","gap:5px","transform:translate(-50%, -100%)","pointer-events:auto","cursor:pointer","user-select:none","white-space:nowrap","font:12px/1.2 -apple-system,BlinkMacSystemFont,Segoe UI,Arial,sans-serif"].join(";"),t.addEventListener("click",i=>{i.preventDefault(),i.stopPropagation();const n=this.labels.get(e);if(!n)return;const r={id:e,label:n,coordinate:n.coordinate,originalEvent:i};this.clickCallbacks.forEach(s=>s(r)),this.emitEvent?.("label-click",r)}),t}renderLabel(e){e.element.innerHTML="";const t=document.createElement("img"),i=this.normalizeIconSize(e.size);t.src=e.icon,t.alt=e.name,t.style.cssText=[`width:${i.width}px`,`height:${i.height}px`,"object-fit:contain","display:block","filter:drop-shadow(0 3px 5px rgba(0,0,0,.32))"].join(";");const n=document.createElement("span");n.textContent=e.name,n.style.cssText=["max-width:160px","overflow:hidden","text-overflow:ellipsis","padding:5px 9px","border-radius:6px","background:rgba(15,23,42,.88)","color:#fff","border:1px solid rgba(255,255,255,.16)","box-shadow:0 3px 10px rgba(0,0,0,.24)"].join(";"),e.element.title=e.name,e.element.appendChild(n),e.element.appendChild(t)}updateLabelPosition(e){const t=this.projectCoordinate(e.coordinate);if(!(e.visible&&t!=null&&t.visible!==!1)||!t){e.element.style.display="none";return}e.element.style.display="flex",e.element.style.left=`${t.x}px`,e.element.style.top=`${t.y}px`}handlePickClick=e=>{e.preventDefault(),e.stopImmediatePropagation();const t=this.pickCoordinate(e);this.isPicking=!1,this.container.style.cursor="",this.removePickBlockers(),this.container.removeEventListener("click",this.handlePickClick,!0),this.pickResolver?.(t),this.pickResolver=null,t&&this.emitEvent?.("label-pick",t)};toPayload(e){return{id:e.id,coordinate:e.coordinate,icon:e.icon,name:e.name,data:e.data,size:e.size,visible:e.visible}}normalizeIconSize(e){return typeof e=="number"?{width:e,height:e}:{width:this.normalizeSizeValue(e.width,28),height:this.normalizeSizeValue(e.height,28)}}normalizeSizeValue(e,t){return Number.isFinite(e)&&e>0?e:t}createId(){return`label-${Date.now()}-${Math.random().toString(16).slice(2)}`}addPickBlockers(){this.container.addEventListener("mousedown",this.blockPickInteraction,!0),this.container.addEventListener("mouseup",this.blockPickInteraction,!0),this.container.addEventListener("touchstart",this.blockPickInteraction,!0),this.container.addEventListener("touchmove",this.blockPickInteraction,!0),this.container.addEventListener("touchend",this.blockPickInteraction,!0)}removePickBlockers(){this.container.removeEventListener("mousedown",this.blockPickInteraction,!0),this.container.removeEventListener("mouseup",this.blockPickInteraction,!0),this.container.removeEventListener("touchstart",this.blockPickInteraction,!0),this.container.removeEventListener("touchmove",this.blockPickInteraction,!0),this.container.removeEventListener("touchend",this.blockPickInteraction,!0)}blockPickInteraction=e=>{e.stopImmediatePropagation()}}class Ei{engine;manager;constructor(e){this.engine=e,this.manager=new Ci({container:e.container,className:"bim-engine-label-container bim-engine-label-container-2d",projectCoordinate:t=>this.projectCoordinate(t),pickCoordinate:t=>this.pickCoordinate(t),emitEvent:(t,i)=>this.engine.events?.trigger?.(t,i)})}pickPoint(){return this.manager.pickPoint()}startPickPoint(e){return this.manager.startPickPoint(e)}createLabel(e){return this.manager.createLabel(e)}updateLabel(e,t){return this.manager.updateLabel(e,t)}deleteLabel(e){return this.manager.deleteLabel(e)}removeLabel(e){return this.manager.removeLabel(e)}clearLabels(){this.manager.clearLabels()}getLabel(e){return this.manager.getLabel(e)}getLabels(){return this.manager.getLabels()}onLabelClick(e){return this.manager.onLabelClick(e)}offLabelClick(e){this.manager.offLabelClick(e)}update(){this.manager.update()}dispose(){this.manager.dispose()}projectCoordinate(e){const t=this.engine.cameraModule2d.worldToScreen(e.x??0,e.y??0),i=this.engine.renderer.domElement.clientWidth,n=this.engine.renderer.domElement.clientHeight;return{x:t.x,y:t.y,visible:t.x>=0&&t.x<=i&&t.y>=0&&t.y<=n}}pickCoordinate(e){const t=this.engine.renderer.domElement.getBoundingClientRect(),i=this.engine.cameraModule2d.screenToWorld(e.clientX-t.left,e.clientY-t.top);return{x:i.x,y:i.y,z:0}}}class Si{engine;mainViewPort=null;constructor(e){this.engine=e}saveMainViewPort(){const e=this.engine.cameraModule2d;return e?(this.mainViewPort={activeCamera:"orthographic",orthographicCamera:e.getViewState()},this.mainViewPort):null}setMainViewPort(e){this.mainViewPort=this.normalizeMainViewPort(e),this.goToMainPort()}goToMainPort(){const e=this.mainViewPort;e&&this.engine.cameraModule2d?.applyViewState(e.orthographicCamera)}resetMainViewPort(){this.mainViewPort=null,this.engine.resetView?.(),this.engine.fitToView?.()}normalizeMainViewPort(e){if(!e)return null;const t=e;return t.orthographicCamera?t:{activeCamera:"orthographic",orthographicCamera:e}}}class Ti{constructor(e,t){this.container=e,this.engine=t,this.el=document.createElement("div"),this.el.className="engine-2d-workspace-tabs",this.container.appendChild(this.el),this.unsubscribe=this.engine.events?.on(me.ModelLoaded,()=>this.refresh())??(()=>{}),this.refresh()}el;unsubscribe;loading=!1;refresh(){const e=this.engine.getLayouts?.()??[],t=this.engine.loaderModule2d?.getActiveWorkspace?.()??{type:"model"};this.el.innerHTML="",this.el.appendChild(this.createTab("模型",t.type==="model",()=>this.switchToModelSpace())),e.forEach((i,n)=>{const r=i.name||`布局${n+1}`;this.el.appendChild(this.createTab(r,t.type==="layout"&&t.layoutId===i.id,()=>this.switchToLayout(i.id)))}),this.el.style.display=e.length>0?"flex":"none"}createTab(e,t,i){const n=document.createElement("button");return n.type="button",n.className="engine-2d-workspace-tabs__item",n.classList.toggle("engine-2d-workspace-tabs__item--active",t),n.textContent=e,n.title=e,n.disabled=this.loading||t,n.addEventListener("click",i),n}async switchToModelSpace(){this.loading||await this.runSwitch(()=>this.engine.showModelSpace?.())}async switchToLayout(e){this.loading||await this.runSwitch(()=>this.engine.loadLayout?.(e))}async runSwitch(e){this.loading=!0,this.refresh();try{await e()}finally{this.loading=!1,this.refresh()}}dispose(){this.unsubscribe(),this.el.remove()}}const Ai={version:"3.9.161"}.version;class at{options;container=null;animationId=null;isRendering=!1;fpsFrameCount=0;fpsLastCheck=0;currentFps=0;enablePerformanceMonitoring=!1;stats;modelToolModule2d;engineStatus2d;octreeBox2d;events;handelBehaved2d;interactionModule2d;sceneModule2d;cameraModule2d;renderModule2d;controlModule2d;loaderModule2d;layerManager;searchManager;themeManager;measure;markup;label;viewCube;cadCursorUI;contextMenuUI;loadingUI;workspaceTabsUI;versionEl=null;linkView2d3d;linkElement2d3d;scene=null;camera=null;renderer=null;dwgData=null;version=Ai;constructor(e){if(this.options=e,this.options.backgroundColor=this.options.backgroundColor??1710618,this.options.enablePerformanceMonitoring=this.options.enablePerformanceMonitoring??!1,this.options.showMouseCoordinates=this.options.showMouseCoordinates??!1,this.options.loadingStyle=this.options.loadingStyle??2,this.options.contextMenu=this.options.contextMenu??{items:[{action:"hideElement",label:"隐藏模型"},{action:"showAll",label:"显示全部"},{action:"hideLayer",label:"隐藏图层"},{action:"showAllLayers",label:"显示所有图层"},{action:"toggleBg",label:"切换背景"},{action:"layerManage",label:"图层管理"},{action:"linkElement2d3d",label:"模型联动",dividerBefore:!0}]},this.enablePerformanceMonitoring=e.enablePerformanceMonitoring??!1,this.container=document.getElementById(e.containerId),!this.container)throw new Error(`Container ${e.containerId} not found`);this.initialize(),this.handelBehaved2d=oi(this),this.interactionModule2d=new li(this),this.interactionModule2d.init(),this.interactionModule2d.active()}initialize(){this.events=new yt(!1),this.sceneModule2d=new xt(this,this.options),this.scene=this.sceneModule2d.scene,this.cameraModule2d=new Mt(this,this.container),this.camera=this.cameraModule2d.orthographicCamera,this.renderModule2d=new _t(this,this.container,this.options),this.renderer=this.renderModule2d.renderer,this.controlModule2d=new Et(this),this.loaderModule2d=new ti(this),this.themeManager=new gi(this.container),this.layerManager=new Ze(this),this.searchManager=new mi(this),this.measure=new wi(this),this.markup=new _i(this),this.label=new Ei(this),this.viewCube=new Si(this),this.octreeBox2d=new ii(this),this.modelToolModule2d=new si(this),this.engineStatus2d=new kt(this),this.linkView2d3d=new ni(this),this.linkElement2d3d=new ri(this),this.sceneModule2d.initGrid(),this.cadCursorUI=new hi(this.container,this.renderer.domElement,this.options.cursorStyle??"short-crosshair"),this.cadCursorUI.setBackgroundColor(this.options.backgroundColor??1710618),this.loadingUI=new di(this.container,this.options.loadingStyle),this.events.on(me.ModelLoadStart,()=>this.loadingUI.show("正在加载...",0)),this.events.on(me.ModelLoadProgress,e=>this.loadingUI.update(e.text,e.progress)),this.events.on(me.ModelLoaded,()=>this.loadingUI.hide()),this.events.on(me.ModelLoadError,()=>this.loadingUI.hide()),this.versionEl=document.createElement("div"),this.versionEl.className="engine-2d-version-text",this.updateVersionDisplay(),this.container.appendChild(this.versionEl),this.workspaceTabsUI=new Ti(this.container,this),this.contextMenuUI=new ci(this.container,this.renderer.domElement,e=>{if(e==="search"&&this.searchManager.show(),e==="layerManage"&&this.layerManager.toggle(),e==="hideElement"&&this.modelToolModule2d.hideModel(this.engineStatus2d.highlightModels),e==="showAll"&&this.modelToolModule2d.showAllModels(),e==="hideLayer"&&this.hideHighlightedLayers(),e==="showAllLayers"&&(this.layerManager.setAllLayersVisible(!0),this.layerManager.refresh()),e==="toggleBg"){const t=this.themeManager.getTheme()==="dark"?"light":"dark";this.setTheme(t)}if(e==="linkElement2d3d"){const t=this.linkElement2d3d.toggle();this.contextMenuUI.setMenuItemState("linkElement2d3d",t),!t&&!this.isModelSpaceActive()&&(this.modelToolModule2d.unHighlightModelHover(),this.modelToolModule2d.unhighlightAllModels()),console.log(`[EngineKernel2d] 二三维图元联动: ${t?"已开启":"已关闭"}`)}if(e==="linkView2d3d"){const t=this.linkView2d3d.toggle();this.contextMenuUI.setMenuItemState("linkView2d3d",t),console.log(`[EngineKernel2d] 图模关联: ${t?"已开启":"已关闭"}`)}},this.options.contextMenu?.items),this.contextMenuUI.setMenuItemStates({linkElement2d3d:this.linkElement2d3d.isEnabled(),linkView2d3d:this.linkView2d3d.isEnabled()}),this.initStatsMonitor(),this.startRendering(),console.log(`[EngineKernel2d] 2D Engine initialized (v${this.version})`)}startRendering(){this.isRendering||(this.isRendering=!0,this.fpsLastCheck=performance.now(),this.animate(),console.log("[EngineKernel2d] Rendering started"))}stopRendering(){this.isRendering=!1,this.animationId!==null&&(cancelAnimationFrame(this.animationId),this.animationId=null),console.log("[EngineKernel2d] Rendering stopped")}animate=()=>{this.isRendering&&(this.animationId=requestAnimationFrame(this.animate),this.stats?.begin(),this.controlModule2d.update(),this.camera?.updateMatrixWorld(!0),this.measure?.update(),this.markup?.update(),this.label?.update(),this.scene&&this.camera&&this.renderer&&this.renderer.render(this.scene,this.camera),this.enablePerformanceMonitoring&&this.updatePerformanceStats(),this.stats?.end())};initStatsMonitor(){!(this.options.showStats??this.enablePerformanceMonitoring)||!this.container||(this.stats=new gt,this.stats.showPanel(0),this.stats.dom.className="engine-2d-stats-monitor",this.stats.dom.style.position="absolute",this.stats.dom.style.top="0px",this.stats.dom.style.left="0px",this.stats.dom.style.zIndex="1000",this.container.appendChild(this.stats.dom))}updatePerformanceStats(){this.fpsFrameCount++;const e=performance.now();e-this.fpsLastCheck>=1e3&&(this.currentFps=this.fpsFrameCount,this.fpsFrameCount=0,this.fpsLastCheck=e,this.events.trigger(me.RenderEnd,{fps:this.currentFps}))}async loadModel(e,t){return await this.loaderModule2d.loadModel(e,t),{}}getLayouts(){return this.loaderModule2d?.getLayouts()??[]}getActiveWorkspace(){return this.loaderModule2d?.getActiveWorkspace?.()??{type:"model",name:"模型"}}isModelSpaceActive(){return this.getActiveWorkspace().type==="model"}isElementLink2d3dEnabled(){return this.linkElement2d3d?.isEnabled?.()===!0}async loadLayout(e,t){await this.loaderModule2d.loadLayout(e,t)}async showModelSpace(e){await this.loaderModule2d.showModelSpace(e)}getLayers(){return this.loaderModule2d.getLayers()}getEntitiesByLayer(e){return this.loaderModule2d.getEntitiesByLayer(e)}setLayerVisible(e,t){this.layerManager?.setLayerVisible(e,t)}hideHighlightedLayers(){this.getLayersByModelIds(this.engineStatus2d?.highlightModels??[]).forEach(t=>this.layerManager?.setLayerVisible(t,!1)),this.layerManager?.refresh()}getLayersByModelIds(e){const t=new Set;return e.forEach(i=>{(this.loaderModule2d?.model?.nodeMap?.get(String(i))??this.loaderModule2d?.model?.nodeMap?.get(i))?.forEach(r=>{r?.layer&&t.add(r.layer)})}),Array.from(t)}setTheme(e){this.themeManager.setTheme(e);const t=e==="dark"?1710618:15790320;this.setBackgroundColor(t)}resetView(){this.cameraModule2d&&this.cameraModule2d.resetView()}fitToView(){const e=this.loaderModule2d?.getActiveWorkspaceExtents?.();if(this.getActiveWorkspace().type==="layout"&&e){this.cameraModule2d.fitToExtents(e);return}const t=this.dwgData?.metadata,i=t?.viewExtents??t?.extents;i&&this.cameraModule2d.fitToExtents(i)}setZoom(e){this.cameraModule2d&&this.cameraModule2d.setZoom(e)}getZoom(){return this.cameraModule2d?this.cameraModule2d.getZoom():1}updateVersionDisplay(){this.versionEl&&(this.versionEl.innerHTML=`v${this.version}`)}getPerformanceStats(){const e=this.sceneModule2d.getSceneStats();return{fps:this.currentFps,renderTime:0,entityCount:e.objectCount,visibleEntityCount:e.objectCount}}setBackgroundColor(e){this.options.backgroundColor=e,this.sceneModule2d&&this.sceneModule2d.setBackgroundColor(e),this.cadCursorUI?.setBackgroundColor(e),this.modelToolModule2d?.updateColorsForBackground(e),this.layerManager?.refresh()}clearScene(){this.sceneModule2d&&this.sceneModule2d.clearScene()}resize(){if(this.renderModule2d){const e=this.container?.clientWidth??0,t=this.container?.clientHeight??0;this.renderModule2d.setSize(e,t)}}captureImage(e){if(!this.renderer||!this.sceneModule2d)return console.error("[EngineKernel2d] Renderer or scene module not initialized"),null;const t=this.renderer.domElement,i=e?.format||"png",n=e?.quality||.92,r=`image/${i==="jpeg"?"jpeg":i}`,s=e?.transparent??!1,o=e?.hideGrid??!0,a=e?.hideAxes??!0,l=this.scene?.background??null;let c=!1,f=!1;this.sceneModule2d.adaptiveGrid&&(c=this.sceneModule2d.adaptiveGrid.gridGroup?.visible??!1,o&&this.sceneModule2d.adaptiveGrid.setVisible(!1)),this.sceneModule2d.axesHelper&&(f=this.sceneModule2d.axesHelper.visible??!1,a&&this.sceneModule2d.setAxesVisible(!1)),s&&this.scene&&(this.scene.background=null),this.scene&&this.camera&&this.renderer.render(this.scene,this.camera);const p=t.toDataURL(r,n);this.scene&&(this.scene.background=l),this.sceneModule2d.adaptiveGrid&&o&&this.sceneModule2d.adaptiveGrid.setVisible(c),this.sceneModule2d.axesHelper&&a&&this.sceneModule2d.setAxesVisible(f),this.scene&&this.camera&&this.renderer.render(this.scene,this.camera);const d={dataURL:p};if(e?.download){const y=e.filename||`capture-${Date.now()}.${i}`,h=document.createElement("a");h.href=p,h.download=y,h.style.display="none",document.body.appendChild(h),h.click(),h.remove(),console.log(`[EngineKernel2d] Image captured and downloaded: ${y}`)}else console.log("[EngineKernel2d] Image captured");return d}async captureImageAsync(e){if(!this.renderer||!this.sceneModule2d)return console.error("[EngineKernel2d] Renderer or scene module not initialized"),null;const t=this.renderer.domElement,i=e?.format||"png",n=e?.quality||.92,r=`image/${i==="jpeg"?"jpeg":i}`,s=e?.transparent??!1,o=e?.hideGrid??!0,a=e?.hideAxes??!0,l=this.scene?.background??null;let c=!1,f=!1;this.sceneModule2d.adaptiveGrid&&(c=this.sceneModule2d.adaptiveGrid.gridGroup?.visible??!1,o&&this.sceneModule2d.adaptiveGrid.setVisible(!1)),this.sceneModule2d.axesHelper&&(f=this.sceneModule2d.axesHelper.visible??!1,a&&this.sceneModule2d.setAxesVisible(!1)),s&&this.scene&&(this.scene.background=null),this.scene&&this.camera&&this.renderer.render(this.scene,this.camera);const p=t.toDataURL(r,n),d=await new Promise(h=>{t.toBlob(g=>{g&&h(g)},r,n)}),y=URL.createObjectURL(d);if(this.scene&&(this.scene.background=l),this.sceneModule2d.adaptiveGrid&&o&&this.sceneModule2d.adaptiveGrid.setVisible(c),this.sceneModule2d.axesHelper&&a&&this.sceneModule2d.setAxesVisible(f),this.scene&&this.camera&&this.renderer.render(this.scene,this.camera),e?.download){const h=e.filename||`capture-${Date.now()}.${i}`,g=document.createElement("a");g.href=y,g.download=h,g.style.display="none",document.body.appendChild(g),g.click(),g.remove(),console.log(`[EngineKernel2d] Image captured and downloaded: ${h}`)}else console.log("[EngineKernel2d] Image captured with Blob URL:",y);return{dataURL:p,blobURL:y,blob:d}}dispose(){console.log("[EngineKernel2d] Disposing engine..."),this.stopRendering(),this.cadCursorUI?.dispose(),this.contextMenuUI?.dispose(),this.loadingUI?.dispose(),this.workspaceTabsUI?.dispose(),this.versionEl?.parentElement?.removeChild(this.versionEl),this.searchManager?.dispose(),this.measure?.dispose(),this.markup?.dispose(),this.label?.dispose(),this.themeManager?.dispose(),this.loaderModule2d?.dispose(),this.controlModule2d?.dispose(),this.renderModule2d?.dispose(),this.cameraModule2d?.dispose(),this.sceneModule2d?.dispose(),this.events?.dispose(),this.stats?.dom?.parentElement&&this.stats.dom.parentElement.removeChild(this.stats.dom),this.scene=null,this.camera=null,this.renderer=null,this.dwgData=null,this.stats=void 0,this.versionEl=null,console.log("[EngineKernel2d] Engine disposed")}}function lt(k){return new at(k)}ve.EngineKernel2d=at,ve.createEngine2d=lt,ve.default=lt,Object.defineProperties(ve,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}));
221
+ `,s.addEventListener("click",()=>this.selectResult(n)),s.addEventListener("mouseenter",()=>{this.activeIndex=r,this.highlightItem(this.resultList.querySelectorAll(".engine-2d-search__item"))}),this.resultList.appendChild(s)})}highlight(e,t){const i=this.escapeHtml(e),n=t.trim();if(!n)return i;const r=this.escapeRegExp(this.escapeHtml(n));return i.replace(new RegExp(`(${r})`,"gi"),'<mark class="engine-2d-search__mark">$1</mark>')}highlightItem(e){e.forEach((t,i)=>{t.classList.toggle("engine-2d-search__item--active",i===this.activeIndex)}),this.activeIndex>=0&&e[this.activeIndex]?.scrollIntoView({block:"nearest"})}selectResult(e){this.manager.onResultSelect(e),this.hide()}clearResults(){this.resultList.innerHTML="",this.resultList.style.display="none",this.statusEl.style.display="none";const e=this.wrapper.querySelector(".engine-2d-search__divider");e.style.display="none",this.currentResults=[],this.activeIndex=-1}escapeHtml(e){return String(e??"").replace(/[&<>"']/g,t=>({"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"})[t]??t)}escapeRegExp(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}show(){this.wrapper.classList.add("engine-2d-search--visible"),requestAnimationFrame(()=>this.input.focus())}hide(){this.wrapper.classList.remove("engine-2d-search--visible"),this.clearResults(),this.input.value="",this.clearBtn.style.opacity="0",this.clearBtn.style.pointerEvents="none"}toggle(){this.wrapper.classList.contains("engine-2d-search--visible")?this.hide():this.show()}dispose(){this.input.removeEventListener("input",this.onInput),this.input.removeEventListener("keydown",this.onKeyDown),this.clearBtn.removeEventListener("click",this.onClear),document.removeEventListener("mousedown",this.onDocMouseDown),document.removeEventListener("keydown",this.onEscape),this.wrapper.parentElement?.removeChild(this.wrapper),this.debounceTimer!==null&&clearTimeout(this.debounceTimer)}}class mi{engine;searchUI=null;constructor(e){this.engine=e;const t=document.getElementById(e?.options?.containerId??"")??e?.container??null;t&&(this.searchUI=new pi(t,this))}search(e){const t=this.normalize(e);return t?(this.engine.loaderModule2d?.model?.textItems??[]).map(n=>{const r=this.getMatchScore(n.text,t);return r==null?null:{id:n.id,name:n.text,type:"文字",layer:n.layer,description:this.getPositionDescription(n),score:r,target:n}}).filter(n=>n!==null).sort((n,r)=>(r.score??0)-(n.score??0)||n.name.length-r.name.length).slice(0,100):[]}onResultSelect(e){const t=e.target;t&&(this.engine.modelToolModule2d?.unhighlightAllModels?.(),this.engine.modelToolModule2d?.highlightModel?.([e.id]),this.fitToText(t))}fitToText(e){const t=e.min?.clone(),i=e.max?.clone(),n=e.anchor?.clone();if((!t||!i||t.distanceTo(i)<1e-6)&&n){const o=Math.max(Number(e.info?.height??100),100);this.engine.cameraModule2d?.fitToExtents({min:[n.x-o,n.y-o,0],max:[n.x+o,n.y+o,0]},2,!0,500);return}if(!t||!i)return;const r=new _.Vector3().subVectors(i,t),s=Math.max(r.x,r.y)<1e-6?2:2.5;this.engine.cameraModule2d?.fitToExtents({min:[t.x,t.y,t.z],max:[i.x,i.y,i.z]},s,!0,500)}getPositionDescription(e){const t=e.anchor??e.min;return t?`X:${t.x.toFixed(0)} Y:${t.y.toFixed(0)}`:""}normalize(e){return String(e??"").trim().toLowerCase().replace(/\s+/g,"")}getMatchScore(e,t){const i=this.normalize(e);if(!i)return null;const n=i.indexOf(t);if(n>=0)return 1e3-n-Math.max(0,i.length-t.length)*.01;let r=0,s=0;for(const o of t){const a=i.indexOf(o,r);if(a<0)return null;s+=a-r,r=a+1}return 500-s-Math.max(0,i.length-t.length)*.01}show(){this.searchUI?.show()}hide(){this.searchUI?.hide()}toggle(){this.searchUI?.toggle()}dispose(){this.searchUI?.dispose(),this.searchUI=null}}const st={dark:{"--e2d-bg":"#1e1f22","--e2d-bg2":"#252526","--e2d-bg3":"#222222","--e2d-bg-hover":"rgba(79,195,247,0.08)","--e2d-bg-accent":"#094771","--e2d-icon-bg":"rgba(255,255,255,0.08)","--e2d-icon-bg-hover":"rgba(255,255,255,0.16)","--e2d-border":"rgba(255,255,255,0.12)","--e2d-border2":"#333333","--e2d-text":"#e0e0e0","--e2d-text2":"#cccccc","--e2d-text3":"rgba(255,255,255,0.35)","--e2d-text4":"#666666","--e2d-text-accent":"#ffffff","--e2d-accent":"#4fc3f7","--e2d-shadow":"rgba(0,0,0,0.50)","--e2d-shadow-lg":"rgba(0,0,0,0.65)","--e2d-cursor":"rgba(255,255,255,0.85)","--e2d-scrollbar":"rgba(255,255,255,0.15)","--e2d-float-bg":"rgba(0,0,0,0.65)","--e2d-float-border":"rgba(255,255,255,0.08)","--e2d-swatch-border":"#444444","--e2d-close":"#aaaaaa","--e2d-close-hover":"#ffffff","--e2d-icon":"rgba(255,255,255,0.4)","--e2d-coord-value":"#76c8ff","--e2d-coord-label":"rgba(255,255,255,0.45)"},light:{"--e2d-bg":"#ffffff","--e2d-bg2":"#ffffff","--e2d-bg3":"#eeeeee","--e2d-bg-hover":"rgba(25,118,210,0.06)","--e2d-bg-accent":"#e3f2fd","--e2d-icon-bg":"rgba(0,0,0,0.06)","--e2d-icon-bg-hover":"rgba(0,0,0,0.12)","--e2d-border":"rgba(0,0,0,0.12)","--e2d-border2":"#e0e0e0","--e2d-text":"#1a1a1a","--e2d-text2":"#444444","--e2d-text3":"rgba(0,0,0,0.40)","--e2d-text4":"#aaaaaa","--e2d-text-accent":"#1565c0","--e2d-accent":"#1976d2","--e2d-shadow":"rgba(0,0,0,0.15)","--e2d-shadow-lg":"rgba(0,0,0,0.22)","--e2d-cursor":"rgba(30,30,30,0.70)","--e2d-scrollbar":"rgba(0,0,0,0.18)","--e2d-float-bg":"#ffffff","--e2d-float-border":"rgba(0,0,0,0.10)","--e2d-swatch-border":"#cccccc","--e2d-close":"#777777","--e2d-close-hover":"#1a1a1a","--e2d-icon":"rgba(0,0,0,0.45)","--e2d-coord-value":"#1976d2","--e2d-coord-label":"rgba(0,0,0,0.50)"}};class gi{container;current;constructor(e,t="dark"){this.container=e,this.current=t,this._apply(t)}_apply(e){const t=st[e];for(const[i,n]of Object.entries(t))this.container.style.setProperty(i,n);this.container.setAttribute("data-e2d-theme",e)}setTheme(e){this.current=e,this._apply(e)}getTheme(){return this.current}toggle(){this.setTheme(this.current==="dark"?"light":"dark")}dispose(){for(const e of Object.keys(st[this.current]))this.container.style.removeProperty(e);this.container.removeAttribute("data-e2d-theme")}}const ot={precision:3,unit:"m",areaUnit:"m²",scale:1};class Ue{manager;points=[];constructor(e){this.manager=e}active(){this.points=[],this.manager.setCurrentTool(this)}disActive(){this.points=[],this.manager.clearPreview()}clearAllPoints(){this.points=[],this.manager.clearPreview()}handleClick(e){this.points.push(e.clone())}handleMove(e){}handleDoubleClick(){}handleRightClick(){this.handleDoubleClick()}handleEnter(){this.handleDoubleClick()}handleEsc(){this.clearAllPoints()}}class yi extends Ue{handleClick(e){super.handleClick(e),this.points.length===2&&(this.manager.addMeasurement("distance",this.points),this.clearAllPoints())}handleMove(e){this.points.length===1&&this.manager.drawPreview("distance",[this.points[0],e])}}class vi extends Ue{handleClick(e){super.handleClick(e),this.manager.drawPreview("area",this.points)}handleMove(e){this.points.length>0&&this.manager.drawPreview("area",[...this.points,e])}handleDoubleClick(){const e=this.manager.removeTrailingDuplicatePoint(this.points);e.length>=3&&this.manager.addMeasurement("area",e),this.clearAllPoints()}}class bi extends Ue{handleClick(e){super.handleClick(e),this.points.length===3&&(this.manager.addMeasurement("angle",this.points),this.clearAllPoints())}handleMove(e){this.points.length>=2&&this.manager.drawPreview("angle",[...this.points,e])}}class wi{distanceMeasure;areaMeasure;angleMeasure;annotationData={distanceAnnotation:[],areaAnnotation:[],angleAnnotation:[]};engine;container;annotationContainer;setting={...ot};isActive=!1;currentTool=null;previewRecord=null;mouseDownPoint=null;hasDraggedAfterMouseDown=!1;currentWorkspaceKey="model";constructor(e){this.engine=e,this.container=e.container,this.distanceMeasure=new yi(this),this.areaMeasure=new vi(this),this.angleMeasure=new bi(this),this.annotationContainer=document.createElement("div"),this.annotationContainer.className="annotation-container",this.annotationContainer.style.pointerEvents="none",this.annotationContainer.style.zIndex="20",this.container.appendChild(this.annotationContainer)}active(){if(this.isActive)return;this.isActive=!0,this.engine.interactionModule2d?.disActive?.();const e=this.engine.renderer.domElement;e.addEventListener("mousedown",this.handleMouseDown,!0),e.addEventListener("click",this.handleClick,!0),e.addEventListener("mousemove",this.handleMove,!0),e.addEventListener("dblclick",this.handleDoubleClick,!0),e.addEventListener("contextmenu",this.handleContextMenu,!0),window.addEventListener("keydown",this.handleKeyDown,!0)}disActive(){if(!this.isActive)return;this.quitDraw(),this.isActive=!1;const e=this.engine.renderer.domElement;e.removeEventListener("mousedown",this.handleMouseDown,!0),e.removeEventListener("click",this.handleClick,!0),e.removeEventListener("mousemove",this.handleMove,!0),e.removeEventListener("dblclick",this.handleDoubleClick,!0),e.removeEventListener("contextmenu",this.handleContextMenu,!0),window.removeEventListener("keydown",this.handleKeyDown,!0),this.engine.interactionModule2d?.active?.(),this.clearAll()}quitDraw(){this.currentTool?.disActive(),this.currentTool=null,this.clearPreview()}activate(e){this.active(),this.disActiveMeasureTools(),e==="distance"&&this.distanceMeasure.active(),e==="area"&&this.areaMeasure.active(),e==="angle"&&this.angleMeasure.active()}clearAllPoints(){this.distanceMeasure.clearAllPoints(),this.areaMeasure.clearAllPoints(),this.angleMeasure.clearAllPoints()}clearAll(){Object.values(this.annotationData).forEach(e=>this.removeRecords(e,t=>t.workspaceKey===this.currentWorkspaceKey)),this.clearPreview()}cancelCurrentSelectedAnnotation(){Object.values(this.annotationData).flat().forEach(e=>{e.highlight=!1,this.applyRecordHighlight(e,!1)})}saveSetting(e){this.setting={...this.setting,...e,precision:this.normalizePrecision(e.precision??this.setting.precision),scale:Number.isFinite(e.scale)&&e.scale>0?e.scale:this.setting.scale},this.refreshLabels()}setPrecision(e){this.saveSetting({precision:e})}getSetting(){return{...this.setting}}update(){this.updateRecords(Object.values(this.annotationData).flat().filter(e=>e.workspaceKey===this.currentWorkspaceKey)),this.previewRecord&&this.updateRecordSvg(this.previewRecord)}setWorkspace(e){!e||e===this.currentWorkspaceKey||(this.clearPreview(),this.cancelCurrentSelectedAnnotation(),this.currentWorkspaceKey=e,this.refreshWorkspaceVisibility())}dispose(){this.disActive(),this.clearAll(),this.annotationContainer.remove()}setCurrentTool(e){this.currentTool=e}drawPreview(e,t){this.clearPreview(),!(t.length<2)&&(this.previewRecord=this.createRecord(e,t,!0),this.annotationContainer.appendChild(this.previewRecord.container),this.updateRecordSvg(this.previewRecord))}clearPreview(){this.previewRecord?.container.remove(),this.previewRecord=null}addMeasurement(e,t){const i=this.createRecord(e,t,!1);return this.annotationContainer.appendChild(i.container),this.getRecords(e).push(i),this.updateRecordSvg(i),this.engine.events?.trigger?.("measure-changed",i),i}deleteSelected(){Object.values(this.annotationData).forEach(e=>{for(let t=e.length-1;t>=0;t--)e[t].workspaceKey===this.currentWorkspaceKey&&e[t].highlight&&(e[t].container.remove(),e.splice(t,1))})}removeTrailingDuplicatePoint(e){if(e.length<2)return e.map(r=>r.clone());const t=e.map(r=>r.clone()),i=t[t.length-1],n=t[t.length-2];return i.distanceTo(n)<1e-6&&t.pop(),t}disActiveMeasureTools(){this.distanceMeasure.disActive(),this.areaMeasure.disActive(),this.angleMeasure.disActive()}handleMouseDown=e=>{this.mouseDownPoint=new _.Vector2(e.clientX,e.clientY),this.hasDraggedAfterMouseDown=!1};handleClick=e=>{!this.currentTool||this.hasDraggedAfterMouseDown||(e.preventDefault(),e.stopImmediatePropagation(),this.currentTool.handleClick(this.eventToWorld(e)))};handleMove=e=>{this.currentTool&&(this.mouseDownPoint&&new _.Vector2(e.clientX,e.clientY).distanceTo(this.mouseDownPoint)>3&&(this.hasDraggedAfterMouseDown=!0),this.currentTool.handleMove(this.eventToWorld(e)))};handleDoubleClick=e=>{this.currentTool&&(e.preventDefault(),e.stopImmediatePropagation(),this.currentTool.handleDoubleClick())};handleContextMenu=e=>{this.currentTool&&(e.preventDefault(),e.stopImmediatePropagation(),this.currentTool.handleRightClick())};handleKeyDown=e=>{this.isActive&&(e.key==="Escape"&&(e.preventDefault(),e.stopImmediatePropagation(),this.currentTool?.handleEsc(),this.disActive(),this.engine.events?.trigger?.("quit_measure_draw",!0),window.dispatchEvent(new CustomEvent("D2MeasureQuit"))),(e.key==="Delete"||e.key==="Backspace")&&(e.preventDefault(),e.stopImmediatePropagation(),this.deleteSelected()),e.key==="Enter"&&this.currentTool&&(e.preventDefault(),this.currentTool.handleEnter()))};eventToWorld(e){const t=this.engine.renderer.domElement.getBoundingClientRect(),i=this.engine.cameraModule2d.screenToWorld(e.clientX-t.left,e.clientY-t.top);return i.z=0,i}createRecord(e,t,i){const n=document.createElement("div");n.className=`${e}-annotation`,n.style.position="absolute",n.style.left="0px",n.style.top="0px",n.style.pointerEvents="none";const r=this.createSvg(e);i&&(r.style.opacity="0.65"),n.appendChild(r);const s=this.computeValue(e,t),o={id:this.createId(),type:e,workspaceKey:this.currentWorkspaceKey,points:t.map(a=>a.clone()),container:n,svg:r,value:s,text:this.formatValue(e,s),isSelect:i};return i||this.bindRecordSelection(o),o}createSvg(e){const t=document.createElementNS("http://www.w3.org/2000/svg","svg");if(t.classList.add("measureSvg"),t.style.left="0",t.style.top="0",t.style.pointerEvents="none",e==="area"){const o=this.svgElement("polygon");o.setAttribute("fill","rgba(0, 155, 234, 0.12)"),o.setAttribute("stroke","none"),t.appendChild(o)}const i=e==="angle"?2:1;for(let o=0;o<i;o++){const a=this.svgElement("polyline");a.classList.add("measureLine"),a.setAttribute("stroke-width","2"),a.setAttribute("style","fill: none; opacity: 1;"),t.appendChild(a)}const n=e==="angle"?3:e==="distance"?2:0;for(let o=0;o<n;o++){const a=this.svgElement("circle");a.classList.add("measurePointer"),a.setAttribute("r","5"),t.appendChild(a)}const r=this.svgElement("rect");r.classList.add("measureBack"),r.setAttribute("width","100"),r.setAttribute("height","25"),r.style.pointerEvents="auto",r.style.cursor="pointer",t.appendChild(r);const s=this.svgElement("text");return s.classList.add("measureLabel"),s.setAttribute("text-anchor","middle"),t.appendChild(s),t}bindRecordSelection(e){e.svg.getElementsByTagName("rect")[0].addEventListener("click",i=>{i.preventDefault(),i.stopPropagation(),this.cancelCurrentSelectedAnnotation(),e.highlight=!0,this.applyRecordHighlight(e,!0),this.engine.events?.trigger?.("measure-click",e)})}applyRecordHighlight(e,t){[e.svg,...Array.from(e.svg.getElementsByTagName("polyline")),...Array.from(e.svg.getElementsByTagName("circle")),...Array.from(e.svg.getElementsByTagName("polygon")),...Array.from(e.svg.getElementsByTagName("rect")),...Array.from(e.svg.getElementsByTagName("text"))].forEach(n=>{n.classList.toggle("Hight",t),n.classList.toggle("measure-2d-selected",t)})}svgElement(e){return document.createElementNS("http://www.w3.org/2000/svg",e)}updateRecords(e){e.forEach(t=>this.updateRecordSvg(t))}updateRecordSvg(e){const t=this.container.clientWidth||1,i=this.container.clientHeight||1;e.svg.setAttribute("width",`${t}`),e.svg.setAttribute("height",`${i}`),e.svg.style.width=`${t}px`,e.svg.style.height=`${i}px`;const n=e.points.map(r=>this.worldToScreen(r));e.type==="distance"&&this.updateDistanceSvg(e,n),e.type==="area"&&this.updateAreaSvg(e,n),e.type==="angle"&&this.updateAngleSvg(e,n)}updateDistanceSvg(e,t){const[i,n]=t,r=e.svg.getElementsByTagName("polyline")[0],s=e.svg.getElementsByTagName("circle");r.setAttribute("points",`${i.x},${i.y} ${n.x},${n.y}`),s[0].setAttribute("cx",`${i.x}`),s[0].setAttribute("cy",`${i.y}`),s[1].setAttribute("cx",`${n.x}`),s[1].setAttribute("cy",`${n.y}`),this.updateLabel(e,(i.x+n.x)/2,(i.y+n.y)/2)}updateAreaSvg(e,t){const i=t.map(o=>`${o.x},${o.y}`).join(" "),r=(t.length>=3?[...t,t[0]]:t).map(o=>`${o.x},${o.y}`).join(" ");e.svg.getElementsByTagName("polygon")[0].setAttribute("points",t.length>=3?i:""),e.svg.getElementsByTagName("polyline")[0].setAttribute("points",r);const s=t.reduce((o,a)=>(o.x+=a.x,o.y+=a.y,o),{x:0,y:0});this.updateLabel(e,s.x/t.length,s.y/t.length)}updateAngleSvg(e,t){const[i,n,r]=t,s=e.svg.getElementsByTagName("polyline"),o=e.svg.getElementsByTagName("circle");s[0].setAttribute("points",`${i.x},${i.y} ${n.x},${n.y}`),s[1].setAttribute("points",`${n.x},${n.y} ${r.x},${r.y}`),[i,n,r].forEach((a,l)=>{o[l].setAttribute("cx",`${a.x}`),o[l].setAttribute("cy",`${a.y}`)}),this.updateLabel(e,n.x,n.y-30)}updateLabel(e,t,i){e.value=this.computeValue(e.type,e.points),e.text=this.formatValue(e.type,e.value);const n=e.svg.getElementsByTagName("rect")[0],r=e.svg.getElementsByTagName("text")[0],s=Math.max(100,e.text.length*9+22);n.setAttribute("x",`${t-s/2}`),n.setAttribute("y",`${i-12.5}`),n.setAttribute("width",`${s}`),r.setAttribute("x",`${t}`),r.setAttribute("y",`${i+4}`),r.textContent=e.text}worldToScreen(e){return this.engine.cameraModule2d.worldToScreen(e.x,e.y)}computeValue(e,t){return e==="distance"?t[0].distanceTo(t[1])*this.setting.scale:e==="angle"?this.computeAngle(t[0],t[1],t[2]):this.computeArea(t)*this.setting.scale*this.setting.scale}computeArea(e){if(e.length<3)return 0;let t=0;for(let i=0;i<e.length;i++){const n=e[i],r=e[(i+1)%e.length];t+=n.x*r.y-r.x*n.y}return Math.abs(t)/2}computeAngle(e,t,i){const n=e.clone().sub(t).normalize(),r=i.clone().sub(t).normalize(),s=_.MathUtils.clamp(n.dot(r),-1,1);return _.MathUtils.radToDeg(Math.acos(s))}formatValue(e,t){return e==="angle"?`${t.toFixed(this.setting.precision)}°`:e==="area"?`${t.toFixed(this.setting.precision)} ${this.setting.areaUnit??`${this.setting.unit}²`}`:`${t.toFixed(this.setting.precision)} ${this.setting.unit}`}refreshLabels(){Object.values(this.annotationData).flat().filter(e=>e.workspaceKey===this.currentWorkspaceKey).forEach(e=>{e.value=this.computeValue(e.type,e.points),e.text=this.formatValue(e.type,e.value),this.updateRecordSvg(e)})}refreshWorkspaceVisibility(){Object.values(this.annotationData).flat().forEach(e=>{e.container.style.display=e.workspaceKey===this.currentWorkspaceKey?"":"none"})}removeRecords(e,t){for(let i=e.length-1;i>=0;i-=1)t(e[i])&&(e[i].container.remove(),e.splice(i,1))}getRecords(e){return e==="distance"?this.annotationData.distanceAnnotation:e==="area"?this.annotationData.areaAnnotation:this.annotationData.angleAnnotation}normalizePrecision(e){return Number.isFinite(e)?Math.max(0,Math.min(8,Math.round(e))):ot.precision}createId(){return`measure-2d-${Date.now()}-${Math.random().toString(16).slice(2)}`}}const Ve={stroke:"#ff4d4f",fill:"rgba(255, 77, 79, 0.08)",strokeWidth:2,fontSize:16,cloudRadius:10},xi={none:xe("/assets/icon/选择.svg",typeof document>"u"&&typeof location>"u"?require("url").pathToFileURL(__filename).href:typeof document>"u"?location.href:se&&se.tagName.toUpperCase()==="SCRIPT"&&se.src||new URL("dwg-preview.umd.js",document.baseURI).href),line:xe("/assets/icon/线.svg",typeof document>"u"&&typeof location>"u"?require("url").pathToFileURL(__filename).href:typeof document>"u"?location.href:se&&se.tagName.toUpperCase()==="SCRIPT"&&se.src||new URL("dwg-preview.umd.js",document.baseURI).href),arrow:xe("/assets/icon/箭头.svg",typeof document>"u"&&typeof location>"u"?require("url").pathToFileURL(__filename).href:typeof document>"u"?location.href:se&&se.tagName.toUpperCase()==="SCRIPT"&&se.src||new URL("dwg-preview.umd.js",document.baseURI).href),rect:xe("/assets/icon/矩形.svg",typeof document>"u"&&typeof location>"u"?require("url").pathToFileURL(__filename).href:typeof document>"u"?location.href:se&&se.tagName.toUpperCase()==="SCRIPT"&&se.src||new URL("dwg-preview.umd.js",document.baseURI).href),ellipse:xe("/assets/icon/圆形.svg",typeof document>"u"&&typeof location>"u"?require("url").pathToFileURL(__filename).href:typeof document>"u"?location.href:se&&se.tagName.toUpperCase()==="SCRIPT"&&se.src||new URL("dwg-preview.umd.js",document.baseURI).href),polygon:xe("/assets/icon/面积.svg",typeof document>"u"&&typeof location>"u"?require("url").pathToFileURL(__filename).href:typeof document>"u"?location.href:se&&se.tagName.toUpperCase()==="SCRIPT"&&se.src||new URL("dwg-preview.umd.js",document.baseURI).href),text:xe("/assets/icon/文字.svg",typeof document>"u"&&typeof location>"u"?require("url").pathToFileURL(__filename).href:typeof document>"u"?location.href:se&&se.tagName.toUpperCase()==="SCRIPT"&&se.src||new URL("dwg-preview.umd.js",document.baseURI).href),cloudline:xe("/assets/icon/云线.svg",typeof document>"u"&&typeof location>"u"?require("url").pathToFileURL(__filename).href:typeof document>"u"?location.href:se&&se.tagName.toUpperCase()==="SCRIPT"&&se.src||new URL("dwg-preview.umd.js",document.baseURI).href)},ki="data:image/svg+xml;utf8,"+encodeURIComponent('<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="#1f2937" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M3 6h18"/><path d="M8 6V4h8v2"/><path d="M6 6l1 16h10l1-16"/><path d="M10 11v6"/><path d="M14 11v6"/></svg>'),Mi="data:image/svg+xml;utf8,"+encodeURIComponent('<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="#1f2937" stroke-width="2" stroke-linecap="round"><path d="M6 6l12 12"/><path d="M18 6L6 18"/></svg>');class _i{engine;container;layer;svg;toolbar;records=[];isActive=!1;currentType=null;style={...Ve};draft=null;draftStart=null;polygonPoints=[];currentWorkspaceKey="model";mouseDownPoint=null;hasDraggedAfterMouseDown=!1;buttons={};constructor(e){this.engine=e,this.container=e.container,getComputedStyle(this.container).position==="static"&&(this.container.style.position="relative"),this.layer=document.createElement("div"),this.layer.className="markup-2d-layer",this.svg=document.createElementNS("http://www.w3.org/2000/svg","svg"),this.svg.classList.add("markup-2d-svg"),this.layer.appendChild(this.svg),this.toolbar=this.createToolbar(),this.layer.appendChild(this.toolbar),this.container.appendChild(this.layer)}active(e){if(this.engine.measure?.quitDraw?.(),!this.isActive){this.isActive=!0,this.engine.interactionModule2d?.disActive?.();const t=this.engine.renderer.domElement;t.addEventListener("mousedown",this.handleMouseDown,!0),t.addEventListener("mousemove",this.handleMouseMove,!0),t.addEventListener("mouseup",this.handleMouseUp,!0),t.addEventListener("click",this.handleClick,!0),t.addEventListener("dblclick",this.handleDoubleClick,!0),t.addEventListener("wheel",this.blockDrawingEvent,!0),t.addEventListener("touchstart",this.blockDrawingEvent,!0),t.addEventListener("touchmove",this.blockDrawingEvent,!0),window.addEventListener("keydown",this.handleKeyDown,!0)}this.showToolbar(),e&&this.setDrawType(e)}show(){this.active()}hide(){this.hideToolbar(),this.disActive()}disActive(){if(!this.isActive)return;this.isActive=!1,this.currentType=null,this.clearDraft(),this.polygonPoints=[],this.syncToolbar();const e=this.engine.renderer.domElement;e.removeEventListener("mousedown",this.handleMouseDown,!0),e.removeEventListener("mousemove",this.handleMouseMove,!0),e.removeEventListener("mouseup",this.handleMouseUp,!0),e.removeEventListener("click",this.handleClick,!0),e.removeEventListener("dblclick",this.handleDoubleClick,!0),e.removeEventListener("wheel",this.blockDrawingEvent,!0),e.removeEventListener("touchstart",this.blockDrawingEvent,!0),e.removeEventListener("touchmove",this.blockDrawingEvent,!0),window.removeEventListener("keydown",this.handleKeyDown,!0),this.engine.interactionModule2d?.active?.()}setDrawType(e){this.currentType=e==="none"?null:e,this.clearDraft(),this.polygonPoints=[],this.syncToolbar()}update(){const e=this.container.clientWidth||1,t=this.container.clientHeight||1;this.svg.setAttribute("width",`${e}`),this.svg.setAttribute("height",`${t}`),this.svg.style.width=`${e}px`,this.svg.style.height=`${t}px`,this.records.forEach(i=>{i.element.style.display=i.data.workspaceKey===this.currentWorkspaceKey?"":"none",this.updateElement(i)}),this.draft&&this.updateElement(this.draft)}setWorkspace(e){!e||e===this.currentWorkspaceKey||(this.currentWorkspaceKey=e,this.clearDraft(),this.polygonPoints=[],this.cancelSelected(),this.update())}getData(){return this.records.map(e=>this.cloneData(e.data))}restoreData(e=[]){this.clearAll(!0),e.forEach(t=>this.addMarkup(t)),this.update()}get(){return{cameraViewState:this.engine.cameraModule2d?.getViewState?.()??null,markupData:this.getData()}}restore(e){e&&(e.cameraViewState&&this.engine.cameraModule2d?.applyViewState?.(e.cameraViewState),this.restoreData(e.markupData??[]))}addMarkup(e){const t={id:e.id??this.createId(),type:e.type,workspaceKey:e.workspaceKey??this.currentWorkspaceKey,points:e.points.map(n=>({x:n.x,y:n.y,z:n.z??0})),text:e.text,style:{...this.style,...e.style??{}}},i=this.createRecord(t);return this.records.push(i),this.svg.appendChild(i.element),this.updateElement(i),this.engine.events?.trigger?.("markup-changed",this.cloneData(t)),this.cloneData(t)}clearAll(e=!1){for(let t=this.records.length-1;t>=0;t-=1){const i=this.records[t];!e&&i.data.workspaceKey!==this.currentWorkspaceKey||(i.element.remove(),this.records.splice(t,1))}this.clearDraft()}deleteSelected(){for(let e=this.records.length-1;e>=0;e-=1)this.records[e].selected&&(this.records[e].element.remove(),this.records.splice(e,1));this.engine.events?.trigger?.("markup-changed",this.getData())}dispose(){this.disActive(),this.records.forEach(e=>e.element.remove()),this.records=[],this.layer.remove()}blockDrawingEvent=e=>{this.currentType&&(e instanceof MouseEvent&&this.engine.cadCursorUI?.updateFromMouseEvent?.(e),e.preventDefault(),e.stopImmediatePropagation())};handleMouseDown=e=>{this.currentType&&(this.blockDrawingEvent(e),this.mouseDownPoint=new _.Vector2(e.clientX,e.clientY),this.hasDraggedAfterMouseDown=!1)};handleMouseMove=e=>{if(this.currentType){if(this.blockDrawingEvent(e),this.mouseDownPoint&&e.buttons!==0){const t=new _.Vector2(e.clientX,e.clientY);this.hasDraggedAfterMouseDown=t.distanceTo(this.mouseDownPoint)>3}if(this.isMultiPointType(this.currentType)&&this.polygonPoints.length>0){this.drawMultiPointDraft(this.eventToWorld(e));return}!this.draft||!this.draftStart||(this.draft.data.points=[this.pointToData(this.draftStart),this.pointToData(this.eventToWorld(e))],this.updateElement(this.draft))}};handleMouseUp=e=>{this.currentType&&(this.blockDrawingEvent(e),this.mouseDownPoint=null)};handleClick=e=>{if(this.currentType&&(this.blockDrawingEvent(e),!this.hasDraggedAfterMouseDown)){if(this.currentType==="text"){const t=window.prompt("请输入标记文字","文字")??"";t.trim()&&this.addMarkup({type:"text",points:[this.pointToData(this.eventToWorld(e))],text:t.trim()});return}if(this.isTwoPointType(this.currentType)){const t=this.eventToWorld(e);this.draftStart?this.finishTwoPointDraft(t):this.startTwoPointDraft(t);return}this.isMultiPointType(this.currentType)&&(this.polygonPoints.push(this.eventToWorld(e)),this.drawMultiPointDraft())}};handleDoubleClick=e=>{if(!this.currentType||!this.isMultiPointType(this.currentType))return;this.blockDrawingEvent(e);const t=this.currentType==="cloudline"?2:3,i=this.removeTrailingDuplicatePoints(this.polygonPoints);i.length>=t&&this.addMarkup({type:this.currentType,points:i.map(n=>this.pointToData(n))}),this.polygonPoints=[],this.clearDraft()};handleKeyDown=e=>{if(this.isActive&&(e.key==="Escape"&&(e.preventDefault(),this.clearDraft(),this.polygonPoints=[],this.setDrawType("none")),(e.key==="Delete"||e.key==="Backspace")&&(e.preventDefault(),this.deleteSelected()),e.key==="Enter"&&this.currentType&&this.isMultiPointType(this.currentType))){e.preventDefault();const t=this.currentType==="cloudline"?2:3,i=this.removeTrailingDuplicatePoints(this.polygonPoints);i.length>=t&&this.addMarkup({type:this.currentType,points:i.map(n=>this.pointToData(n))}),this.polygonPoints=[],this.clearDraft()}};createToolbar(){const e=document.createElement("div");e.className="markup-2d-toolbar",[{type:"none",title:"选择"},{type:"line",title:"直线"},{type:"arrow",title:"箭头"},{type:"rect",title:"矩形"},{type:"ellipse",title:"圆形/椭圆"},{type:"polygon",title:"多边形,双击或 Enter 结束"},{type:"cloudline",title:"云线,双击或 Enter 结束"},{type:"text",title:"文字"}].forEach(a=>{const l=this.createIconButton(a.title,xi[a.type]);l.onclick=()=>{this.active(),this.setDrawType(a.type)},a.type!=="none"&&(this.buttons[a.type]=l),e.appendChild(l)}),e.appendChild(this.createDivider());const i=document.createElement("input");i.type="color",i.value=this.style.stroke,i.title="颜色",i.oninput=()=>{this.style.stroke=i.value,this.style.fill=this.hexToTransparent(i.value)},e.appendChild(i);const n=document.createElement("input");n.type="number",n.min="1",n.max="20",n.value=`${this.style.strokeWidth}`,n.title="线宽",n.onchange=()=>{this.style.strokeWidth=this.normalizeNumber(n.valueAsNumber,1,20,Ve.strokeWidth)},e.appendChild(n);const r=document.createElement("input");r.type="number",r.min="10",r.max="72",r.value=`${this.style.fontSize}`,r.title="字号",r.onchange=()=>{this.style.fontSize=this.normalizeNumber(r.valueAsNumber,10,72,Ve.fontSize)},e.appendChild(r),e.appendChild(this.createDivider());const s=this.createIconButton("清空",ki);s.onclick=()=>this.clearAll(),e.appendChild(s);const o=this.createIconButton("关闭",Mi);return o.onclick=()=>{this.hideToolbar(),this.disActive()},e.appendChild(o),e}createDivider(){const e=document.createElement("div");return e.className="markup-2d-divider",e}createIconButton(e,t){const i=document.createElement("button");i.type="button",i.title=e,i.setAttribute("aria-label",e),i.classList.add("markup-2d-icon-button");const n=document.createElement("img");return n.src=t,n.alt=e,n.draggable=!1,i.appendChild(n),i}showToolbar(){this.toolbar.style.display="flex"}hideToolbar(){this.toolbar.style.display="none"}syncToolbar(){Object.entries(this.buttons).forEach(([e,t])=>{t?.classList.toggle("active",e===this.currentType)})}finishDraft(){if(!this.draft)return;const e=this.draft;this.draft=null,e.element.style.pointerEvents="auto",this.records.push(e),this.updateElement(e),this.engine.events?.trigger?.("markup-changed",this.cloneData(e.data))}clearDraft(){this.draft?.element.remove(),this.draft=null,this.draftStart=null}startTwoPointDraft(e){this.draftStart=e.clone(),this.draft=this.createRecord({id:this.createId(),type:this.currentType,workspaceKey:this.currentWorkspaceKey,points:[this.pointToData(e),this.pointToData(e)],style:{...this.style}}),this.draft.element.setAttribute("opacity","0.65"),this.draft.element.style.pointerEvents="none",this.svg.appendChild(this.draft.element),this.updateElement(this.draft)}finishTwoPointDraft(e){!this.draft||!this.draftStart||this.draftStart.distanceTo(e)<1e-6||(this.draft.data.points=[this.pointToData(this.draftStart),this.pointToData(e)],this.draft.element.removeAttribute("opacity"),this.finishDraft(),this.draftStart=null)}drawMultiPointDraft(e){if(this.clearDraft(),this.polygonPoints.length===0)return;const t=e?[...this.polygonPoints,e]:this.polygonPoints;this.draft=this.createRecord({id:this.createId(),type:this.currentType==="cloudline"?"cloudline":"polygon",workspaceKey:this.currentWorkspaceKey,points:t.map(i=>this.pointToData(i)),style:{...this.style}}),this.draft.element.setAttribute("opacity","0.65"),this.draft.element.style.pointerEvents="none",this.svg.appendChild(this.draft.element),this.updateElement(this.draft)}createRecord(e){const t=this.createElement(e.type);t.classList.add("markup-2d-shape");const i={data:this.cloneData(e),element:t};return this.applyStyle(i),this.bindSelection(i),i}createElement(e){return e==="rect"?this.svgElement("rect"):e==="ellipse"?this.svgElement("ellipse"):e==="text"?this.svgElement("text"):e==="polygon"||e==="cloudline"?this.svgElement("g"):this.svgElement("g")}bindSelection(e){e.element.addEventListener("click",t=>{t.preventDefault(),t.stopPropagation(),this.cancelSelected(),e.selected=!0,e.element.classList.add("selected"),this.engine.events?.trigger?.("markup-click",this.cloneData(e.data))})}cancelSelected(){this.records.forEach(e=>{e.selected=!1,e.element.classList.remove("selected")})}updateElement(e){this.applyStyle(e);const t=e.data.points.map(i=>this.worldToScreen(i));e.data.type==="line"&&this.updateLine(e,t,!1),e.data.type==="arrow"&&this.updateLine(e,t,!0),e.data.type==="rect"&&this.updateRect(e,t),e.data.type==="ellipse"&&this.updateEllipse(e,t),e.data.type==="text"&&this.updateText(e,t[0]),e.data.type==="polygon"&&this.updatePolygon(e,t),e.data.type==="cloudline"&&this.updateCloudLine(e,t)}updateLine(e,t,i){const n=e.element;if(n.innerHTML="",t.length<2)return;const[r,s]=t,o=this.svgElement("line");if(o.setAttribute("x1",`${r.x}`),o.setAttribute("y1",`${r.y}`),o.setAttribute("x2",`${s.x}`),o.setAttribute("y2",`${s.y}`),this.applySvgPaint(o,e.data.style,!1),n.appendChild(o),e===this.draft&&this.drawVertexMarkers(n,t,e.data.style),!i)return;const a=this.createArrowHead(r,s,e.data.style.strokeWidth);this.applySvgPaint(a,e.data.style,!0),a.setAttribute("fill",e.data.style.stroke),n.appendChild(a)}updateRect(e,t){if(t.length<2)return;const[i,n]=t,r=e.element;r.setAttribute("x",`${Math.min(i.x,n.x)}`),r.setAttribute("y",`${Math.min(i.y,n.y)}`),r.setAttribute("width",`${Math.abs(n.x-i.x)}`),r.setAttribute("height",`${Math.abs(n.y-i.y)}`)}updateEllipse(e,t){if(t.length<2)return;const[i,n]=t,r=e.element;r.setAttribute("cx",`${(i.x+n.x)/2}`),r.setAttribute("cy",`${(i.y+n.y)/2}`),r.setAttribute("rx",`${Math.abs(n.x-i.x)/2}`),r.setAttribute("ry",`${Math.abs(n.y-i.y)/2}`)}updateText(e,t){const i=e.element;i.setAttribute("x",`${t.x}`),i.setAttribute("y",`${t.y}`),i.textContent=e.data.text??""}updatePolygon(e,t){const i=e.element;if(i.innerHTML="",t.length===0)return;const n=t.map(s=>`${s.x},${s.y}`).join(" "),r=t.length>=3?this.svgElement("polygon"):this.svgElement("polyline");r.setAttribute("points",n),this.applySvgPaint(r,e.data.style,t.length>=3),i.appendChild(r),e===this.draft&&this.drawVertexMarkers(i,t,e.data.style)}updateCloudLine(e,t){const i=e.element;if(i.innerHTML="",t.length===0)return;const n=this.svgElement("path");n.setAttribute("d",this.buildCloudPath(t,e.data.style.cloudRadius)),this.applySvgPaint(n,e.data.style,!1),i.appendChild(n),e===this.draft&&this.drawVertexMarkers(i,t,e.data.style)}drawVertexMarkers(e,t,i){t.forEach(n=>{const r=this.svgElement("circle");r.setAttribute("cx",`${n.x}`),r.setAttribute("cy",`${n.y}`),r.setAttribute("r",`${Math.max(3,i.strokeWidth+2)}`),r.setAttribute("fill",i.stroke),r.setAttribute("stroke","#ffffff"),r.setAttribute("stroke-width","1"),e.appendChild(r)})}applyStyle(e){e.data.type==="line"||e.data.type==="arrow"||e.data.type==="polygon"||e.data.type==="cloudline"||(this.applySvgPaint(e.element,e.data.style,e.data.type!=="text"&&e.data.type!=="cloudline"),e.data.type==="text"&&(e.element.setAttribute("font-size",`${e.data.style.fontSize}`),e.element.setAttribute("dominant-baseline","middle"),e.element.setAttribute("fill",e.data.style.stroke),e.element.setAttribute("stroke","none")))}applySvgPaint(e,t,i){e.setAttribute("stroke",t.stroke),e.setAttribute("stroke-width",`${t.strokeWidth}`),e.setAttribute("fill",i?t.fill:"none"),e.setAttribute("stroke-linecap","round"),e.setAttribute("stroke-linejoin","round")}createArrowHead(e,t,i){const n=Math.atan2(t.y-e.y,t.x-e.x),r=Math.max(10,i*5),s={x:t.x-r*Math.cos(n-Math.PI/6),y:t.y-r*Math.sin(n-Math.PI/6)},o={x:t.x-r*Math.cos(n+Math.PI/6),y:t.y-r*Math.sin(n+Math.PI/6)},a=this.svgElement("polygon");return a.setAttribute("points",`${t.x},${t.y} ${s.x},${s.y} ${o.x},${o.y}`),a}buildCloudPath(e,t){if(e.length===0)return"";if(e.length===1)return`M ${e[0].x} ${e[0].y}`;const i=Math.max(4,t),n=[`M ${e[0].x} ${e[0].y}`];for(let r=0;r<e.length-1;r+=1){const s=e[r],o=e[r+1],a=o.x-s.x,l=o.y-s.y,c=Math.hypot(a,l);if(c<1e-6)continue;const f=Math.max(1,Math.ceil(c/(i*1.6)));for(let p=0;p<f;p+=1){const d=p/f,y=(p+1)/f,h=(d+y)/2,g={x:s.x+a*h-l/c*i*.7,y:s.y+l*h+a/c*i*.7},v={x:s.x+a*y,y:s.y+l*y};n.push(`Q ${g.x} ${g.y} ${v.x} ${v.y}`)}}return n.join(" ")}isMultiPointType(e){return e==="polygon"||e==="cloudline"}isTwoPointType(e){return e==="line"||e==="arrow"||e==="rect"||e==="ellipse"}removeTrailingDuplicatePoints(e){const t=e.map(i=>i.clone());for(;t.length>=2&&t[t.length-1].distanceTo(t[t.length-2])<1e-6;)t.pop();return t}eventToWorld(e){const t=this.engine.renderer.domElement.getBoundingClientRect(),i=this.engine.cameraModule2d.screenToWorld(e.clientX-t.left,e.clientY-t.top);return i.z=0,i}worldToScreen(e){return this.engine.cameraModule2d.worldToScreen(e.x,e.y)}pointToData(e){return{x:e.x,y:e.y,z:e.z}}svgElement(e){return document.createElementNS("http://www.w3.org/2000/svg",e)}cloneData(e){return{...e,points:e.points.map(t=>({...t})),style:{...e.style}}}hexToTransparent(e){const t=e.replace("#",""),i=parseInt(t.slice(0,2),16),n=parseInt(t.slice(2,4),16),r=parseInt(t.slice(4,6),16);return`rgba(${i}, ${n}, ${r}, 0.08)`}normalizeNumber(e,t,i,n){return Number.isFinite(e)?Math.max(t,Math.min(i,Math.round(e))):n}createId(){return`markup-2d-${Date.now()}-${Math.random().toString(16).slice(2)}`}}class Ci{container;labelContainer;projectCoordinate;pickCoordinate;emitEvent;labels=new Map;clickCallbacks=new Set;pickResolver=null;isPicking=!1;constructor(e){this.container=e.container,this.projectCoordinate=e.projectCoordinate,this.pickCoordinate=e.pickCoordinate,this.emitEvent=e.emitEvent,this.labelContainer=document.createElement("div"),this.labelContainer.className=e.className??"bim-engine-label-container",this.labelContainer.style.cssText=["position:absolute","left:0","top:0","width:100%","height:100%","pointer-events:none","overflow:hidden","z-index:1200"].join(";"),this.container.appendChild(this.labelContainer)}pickPoint(){return this.cancelPick(),this.isPicking=!0,this.container.style.cursor="crosshair",this.addPickBlockers(),this.container.addEventListener("click",this.handlePickClick,!0),new Promise(e=>{this.pickResolver=e})}startPickPoint(e){const t=this.pickPoint();return e&&t.then(e),t}createLabel(e){const t=e.id??this.createId();if(this.labels.has(t))throw new Error(`LabelManager: label "${t}" already exists`);const i=this.createElement(t),n={id:t,coordinate:{...e.coordinate},icon:e.icon,name:e.name,data:e.data,size:e.iconSize??e.size??28,visible:e.visible??!0,element:i};return this.labels.set(t,n),this.labelContainer.appendChild(i),this.renderLabel(n),this.updateLabelPosition(n),this.emitEvent?.("label-created",this.toPayload(n)),t}updateLabel(e,t){const i=this.labels.get(e);return i?(t.coordinate&&(i.coordinate={...t.coordinate}),t.icon!==void 0&&(i.icon=t.icon),t.name!==void 0&&(i.name=t.name),t.data!==void 0&&(i.data=t.data),t.iconSize!==void 0&&(i.size=t.iconSize),t.size!==void 0&&(i.size=t.size),t.visible!==void 0&&(i.visible=t.visible),this.renderLabel(i),this.updateLabelPosition(i),this.emitEvent?.("label-updated",this.toPayload(i)),!0):!1}deleteLabel(e){const t=this.labels.get(e);return t?(t.element.remove(),this.labels.delete(e),this.emitEvent?.("label-deleted",{id:e}),!0):!1}removeLabel(e){return this.deleteLabel(e)}clearLabels(){Array.from(this.labels.keys()).forEach(e=>this.deleteLabel(e))}getLabel(e){return this.labels.get(e)}getLabels(){return Array.from(this.labels.values())}onLabelClick(e){return this.clickCallbacks.add(e),()=>this.offLabelClick(e)}offLabelClick(e){this.clickCallbacks.delete(e)}update(){this.labels.forEach(e=>this.updateLabelPosition(e))}cancelPick(){this.isPicking&&(this.isPicking=!1,this.container.style.cursor="",this.removePickBlockers(),this.container.removeEventListener("click",this.handlePickClick,!0),this.pickResolver?.(null),this.pickResolver=null)}dispose(){this.cancelPick(),this.clearLabels(),this.clickCallbacks.clear(),this.labelContainer.remove()}createElement(e){const t=document.createElement("div");return t.dataset.labelId=e,t.style.cssText=["position:absolute","display:flex","flex-direction:column","align-items:center","gap:5px","transform:translate(-50%, -100%)","pointer-events:auto","cursor:pointer","user-select:none","white-space:nowrap","font:12px/1.2 -apple-system,BlinkMacSystemFont,Segoe UI,Arial,sans-serif"].join(";"),t.addEventListener("click",i=>{i.preventDefault(),i.stopPropagation();const n=this.labels.get(e);if(!n)return;const r={id:e,label:n,coordinate:n.coordinate,originalEvent:i};this.clickCallbacks.forEach(s=>s(r)),this.emitEvent?.("label-click",r)}),t}renderLabel(e){e.element.innerHTML="";const t=document.createElement("img"),i=this.normalizeIconSize(e.size);t.src=e.icon,t.alt=e.name,t.style.cssText=[`width:${i.width}px`,`height:${i.height}px`,"object-fit:contain","display:block","filter:drop-shadow(0 3px 5px rgba(0,0,0,.32))"].join(";");const n=document.createElement("span");n.textContent=e.name,n.style.cssText=["max-width:160px","overflow:hidden","text-overflow:ellipsis","padding:5px 9px","border-radius:6px","background:rgba(15,23,42,.88)","color:#fff","border:1px solid rgba(255,255,255,.16)","box-shadow:0 3px 10px rgba(0,0,0,.24)"].join(";"),e.element.title=e.name,e.element.appendChild(n),e.element.appendChild(t)}updateLabelPosition(e){const t=this.projectCoordinate(e.coordinate);if(!(e.visible&&t!=null&&t.visible!==!1)||!t){e.element.style.display="none";return}e.element.style.display="flex",e.element.style.left=`${t.x}px`,e.element.style.top=`${t.y}px`}handlePickClick=e=>{e.preventDefault(),e.stopImmediatePropagation();const t=this.pickCoordinate(e);this.isPicking=!1,this.container.style.cursor="",this.removePickBlockers(),this.container.removeEventListener("click",this.handlePickClick,!0),this.pickResolver?.(t),this.pickResolver=null,t&&this.emitEvent?.("label-pick",t)};toPayload(e){return{id:e.id,coordinate:e.coordinate,icon:e.icon,name:e.name,data:e.data,size:e.size,visible:e.visible}}normalizeIconSize(e){return typeof e=="number"?{width:e,height:e}:{width:this.normalizeSizeValue(e.width,28),height:this.normalizeSizeValue(e.height,28)}}normalizeSizeValue(e,t){return Number.isFinite(e)&&e>0?e:t}createId(){return`label-${Date.now()}-${Math.random().toString(16).slice(2)}`}addPickBlockers(){this.container.addEventListener("mousedown",this.blockPickInteraction,!0),this.container.addEventListener("mouseup",this.blockPickInteraction,!0),this.container.addEventListener("touchstart",this.blockPickInteraction,!0),this.container.addEventListener("touchmove",this.blockPickInteraction,!0),this.container.addEventListener("touchend",this.blockPickInteraction,!0)}removePickBlockers(){this.container.removeEventListener("mousedown",this.blockPickInteraction,!0),this.container.removeEventListener("mouseup",this.blockPickInteraction,!0),this.container.removeEventListener("touchstart",this.blockPickInteraction,!0),this.container.removeEventListener("touchmove",this.blockPickInteraction,!0),this.container.removeEventListener("touchend",this.blockPickInteraction,!0)}blockPickInteraction=e=>{e.stopImmediatePropagation()}}class Ei{engine;manager;constructor(e){this.engine=e,this.manager=new Ci({container:e.container,className:"bim-engine-label-container bim-engine-label-container-2d",projectCoordinate:t=>this.projectCoordinate(t),pickCoordinate:t=>this.pickCoordinate(t),emitEvent:(t,i)=>this.engine.events?.trigger?.(t,i)})}pickPoint(){return this.manager.pickPoint()}startPickPoint(e){return this.manager.startPickPoint(e)}createLabel(e){return this.manager.createLabel(e)}updateLabel(e,t){return this.manager.updateLabel(e,t)}deleteLabel(e){return this.manager.deleteLabel(e)}removeLabel(e){return this.manager.removeLabel(e)}clearLabels(){this.manager.clearLabels()}getLabel(e){return this.manager.getLabel(e)}getLabels(){return this.manager.getLabels()}onLabelClick(e){return this.manager.onLabelClick(e)}offLabelClick(e){this.manager.offLabelClick(e)}update(){this.manager.update()}dispose(){this.manager.dispose()}projectCoordinate(e){const t=this.engine.cameraModule2d.worldToScreen(e.x??0,e.y??0),i=this.engine.renderer.domElement.clientWidth,n=this.engine.renderer.domElement.clientHeight;return{x:t.x,y:t.y,visible:t.x>=0&&t.x<=i&&t.y>=0&&t.y<=n}}pickCoordinate(e){const t=this.engine.renderer.domElement.getBoundingClientRect(),i=this.engine.cameraModule2d.screenToWorld(e.clientX-t.left,e.clientY-t.top);return{x:i.x,y:i.y,z:0}}}class Si{engine;mainViewPort=null;constructor(e){this.engine=e}saveMainViewPort(){const e=this.engine.cameraModule2d;return e?(this.mainViewPort={activeCamera:"orthographic",orthographicCamera:e.getViewState()},this.mainViewPort):null}setMainViewPort(e){this.mainViewPort=this.normalizeMainViewPort(e),this.goToMainPort()}goToMainPort(){const e=this.mainViewPort;e&&this.engine.cameraModule2d?.applyViewState(e.orthographicCamera)}resetMainViewPort(){this.mainViewPort=null,this.engine.resetView?.(),this.engine.fitToView?.()}normalizeMainViewPort(e){if(!e)return null;const t=e;return t.orthographicCamera?t:{activeCamera:"orthographic",orthographicCamera:e}}}class Ti{constructor(e,t){this.container=e,this.engine=t,this.el=document.createElement("div"),this.el.className="engine-2d-workspace-tabs",this.container.appendChild(this.el),this.unsubscribe=this.engine.events?.on(me.ModelLoaded,()=>this.refresh())??(()=>{}),this.refresh()}el;unsubscribe;loading=!1;refresh(){const e=this.engine.getLayouts?.()??[],t=this.engine.loaderModule2d?.getActiveWorkspace?.()??{type:"model"};this.el.innerHTML="",this.el.appendChild(this.createTab("模型",t.type==="model",()=>this.switchToModelSpace())),e.forEach((i,n)=>{const r=i.name||`布局${n+1}`;this.el.appendChild(this.createTab(r,t.type==="layout"&&t.layoutId===i.id,()=>this.switchToLayout(i.id)))}),this.el.style.display=e.length>0?"flex":"none"}createTab(e,t,i){const n=document.createElement("button");return n.type="button",n.className="engine-2d-workspace-tabs__item",n.classList.toggle("engine-2d-workspace-tabs__item--active",t),n.textContent=e,n.title=e,n.disabled=this.loading||t,n.addEventListener("click",i),n}async switchToModelSpace(){this.loading||await this.runSwitch(()=>this.engine.showModelSpace?.())}async switchToLayout(e){this.loading||await this.runSwitch(()=>this.engine.loadLayout?.(e))}async runSwitch(e){this.loading=!0,this.refresh();try{await e()}finally{this.loading=!1,this.refresh()}}dispose(){this.unsubscribe(),this.el.remove()}}const Ai={version:"3.9.18"}.version;class at{options;container=null;animationId=null;isRendering=!1;fpsFrameCount=0;fpsLastCheck=0;currentFps=0;enablePerformanceMonitoring=!1;stats;modelToolModule2d;engineStatus2d;octreeBox2d;events;handelBehaved2d;interactionModule2d;sceneModule2d;cameraModule2d;renderModule2d;controlModule2d;loaderModule2d;layerManager;searchManager;themeManager;measure;markup;label;viewCube;cadCursorUI;contextMenuUI;loadingUI;workspaceTabsUI;versionEl=null;linkView2d3d;linkElement2d3d;scene=null;camera=null;renderer=null;dwgData=null;version=Ai;constructor(e){if(this.options=e,this.options.backgroundColor=this.options.backgroundColor??1710618,this.options.enablePerformanceMonitoring=this.options.enablePerformanceMonitoring??!1,this.options.showMouseCoordinates=this.options.showMouseCoordinates??!1,this.options.loadingStyle=this.options.loadingStyle??2,this.options.contextMenu=this.options.contextMenu??{items:[{action:"hideElement",label:"隐藏模型"},{action:"showAll",label:"显示全部"},{action:"hideLayer",label:"隐藏图层"},{action:"showAllLayers",label:"显示所有图层"},{action:"toggleBg",label:"切换背景"},{action:"layerManage",label:"图层管理"},{action:"linkElement2d3d",label:"模型联动",dividerBefore:!0}]},this.enablePerformanceMonitoring=e.enablePerformanceMonitoring??!1,this.container=document.getElementById(e.containerId),!this.container)throw new Error(`Container ${e.containerId} not found`);this.initialize(),this.handelBehaved2d=oi(this),this.interactionModule2d=new li(this),this.interactionModule2d.init(),this.interactionModule2d.active()}initialize(){this.events=new yt(!1),this.sceneModule2d=new xt(this,this.options),this.scene=this.sceneModule2d.scene,this.cameraModule2d=new Mt(this,this.container),this.camera=this.cameraModule2d.orthographicCamera,this.renderModule2d=new _t(this,this.container,this.options),this.renderer=this.renderModule2d.renderer,this.controlModule2d=new Et(this),this.loaderModule2d=new ti(this),this.themeManager=new gi(this.container),this.layerManager=new Ze(this),this.searchManager=new mi(this),this.measure=new wi(this),this.markup=new _i(this),this.label=new Ei(this),this.viewCube=new Si(this),this.octreeBox2d=new ii(this),this.modelToolModule2d=new si(this),this.engineStatus2d=new kt(this),this.linkView2d3d=new ni(this),this.linkElement2d3d=new ri(this),this.sceneModule2d.initGrid(),this.cadCursorUI=new hi(this.container,this.renderer.domElement,this.options.cursorStyle??"short-crosshair"),this.cadCursorUI.setBackgroundColor(this.options.backgroundColor??1710618),this.loadingUI=new di(this.container,this.options.loadingStyle),this.events.on(me.ModelLoadStart,()=>this.loadingUI.show("正在加载...",0)),this.events.on(me.ModelLoadProgress,e=>this.loadingUI.update(e.text,e.progress)),this.events.on(me.ModelLoaded,()=>this.loadingUI.hide()),this.events.on(me.ModelLoadError,()=>this.loadingUI.hide()),this.versionEl=document.createElement("div"),this.versionEl.className="engine-2d-version-text",this.updateVersionDisplay(),this.container.appendChild(this.versionEl),this.workspaceTabsUI=new Ti(this.container,this),this.contextMenuUI=new ci(this.container,this.renderer.domElement,e=>{if(e==="search"&&this.searchManager.show(),e==="layerManage"&&this.layerManager.toggle(),e==="hideElement"&&this.modelToolModule2d.hideModel(this.engineStatus2d.highlightModels),e==="showAll"&&this.modelToolModule2d.showAllModels(),e==="hideLayer"&&this.hideHighlightedLayers(),e==="showAllLayers"&&(this.layerManager.setAllLayersVisible(!0),this.layerManager.refresh()),e==="toggleBg"){const t=this.themeManager.getTheme()==="dark"?"light":"dark";this.setTheme(t)}if(e==="linkElement2d3d"){const t=this.linkElement2d3d.toggle();this.contextMenuUI.setMenuItemState("linkElement2d3d",t),!t&&!this.isModelSpaceActive()&&(this.modelToolModule2d.unHighlightModelHover(),this.modelToolModule2d.unhighlightAllModels()),console.log(`[EngineKernel2d] 二三维图元联动: ${t?"已开启":"已关闭"}`)}if(e==="linkView2d3d"){const t=this.linkView2d3d.toggle();this.contextMenuUI.setMenuItemState("linkView2d3d",t),console.log(`[EngineKernel2d] 图模关联: ${t?"已开启":"已关闭"}`)}},this.options.contextMenu?.items),this.contextMenuUI.setMenuItemStates({linkElement2d3d:this.linkElement2d3d.isEnabled(),linkView2d3d:this.linkView2d3d.isEnabled()}),this.initStatsMonitor(),this.startRendering(),console.log(`[EngineKernel2d] 2D Engine initialized (v${this.version})`)}startRendering(){this.isRendering||(this.isRendering=!0,this.fpsLastCheck=performance.now(),this.animate(),console.log("[EngineKernel2d] Rendering started"))}stopRendering(){this.isRendering=!1,this.animationId!==null&&(cancelAnimationFrame(this.animationId),this.animationId=null),console.log("[EngineKernel2d] Rendering stopped")}animate=()=>{this.isRendering&&(this.animationId=requestAnimationFrame(this.animate),this.stats?.begin(),this.controlModule2d.update(),this.camera?.updateMatrixWorld(!0),this.measure?.update(),this.markup?.update(),this.label?.update(),this.scene&&this.camera&&this.renderer&&this.renderer.render(this.scene,this.camera),this.enablePerformanceMonitoring&&this.updatePerformanceStats(),this.stats?.end())};initStatsMonitor(){!(this.options.showStats??this.enablePerformanceMonitoring)||!this.container||(this.stats=new gt,this.stats.showPanel(0),this.stats.dom.className="engine-2d-stats-monitor",this.stats.dom.style.position="absolute",this.stats.dom.style.top="0px",this.stats.dom.style.left="0px",this.stats.dom.style.zIndex="1000",this.container.appendChild(this.stats.dom))}updatePerformanceStats(){this.fpsFrameCount++;const e=performance.now();e-this.fpsLastCheck>=1e3&&(this.currentFps=this.fpsFrameCount,this.fpsFrameCount=0,this.fpsLastCheck=e,this.events.trigger(me.RenderEnd,{fps:this.currentFps}))}async loadModel(e,t){return await this.loaderModule2d.loadModel(e,t),{}}getLayouts(){return this.loaderModule2d?.getLayouts()??[]}getActiveWorkspace(){return this.loaderModule2d?.getActiveWorkspace?.()??{type:"model",name:"模型"}}isModelSpaceActive(){return this.getActiveWorkspace().type==="model"}isElementLink2d3dEnabled(){return this.linkElement2d3d?.isEnabled?.()===!0}async loadLayout(e,t){await this.loaderModule2d.loadLayout(e,t)}async showModelSpace(e){await this.loaderModule2d.showModelSpace(e)}getLayers(){return this.loaderModule2d.getLayers()}getEntitiesByLayer(e){return this.loaderModule2d.getEntitiesByLayer(e)}setLayerVisible(e,t){this.layerManager?.setLayerVisible(e,t)}hideHighlightedLayers(){this.getLayersByModelIds(this.engineStatus2d?.highlightModels??[]).forEach(t=>this.layerManager?.setLayerVisible(t,!1)),this.layerManager?.refresh()}getLayersByModelIds(e){const t=new Set;return e.forEach(i=>{(this.loaderModule2d?.model?.nodeMap?.get(String(i))??this.loaderModule2d?.model?.nodeMap?.get(i))?.forEach(r=>{r?.layer&&t.add(r.layer)})}),Array.from(t)}setTheme(e){this.themeManager.setTheme(e);const t=e==="dark"?1710618:15790320;this.setBackgroundColor(t)}resetView(){this.cameraModule2d&&this.cameraModule2d.resetView()}fitToView(){const e=this.loaderModule2d?.getActiveWorkspaceExtents?.();if(this.getActiveWorkspace().type==="layout"&&e){this.cameraModule2d.fitToExtents(e);return}const t=this.dwgData?.metadata,i=t?.viewExtents??t?.extents;i&&this.cameraModule2d.fitToExtents(i)}setZoom(e){this.cameraModule2d&&this.cameraModule2d.setZoom(e)}getZoom(){return this.cameraModule2d?this.cameraModule2d.getZoom():1}updateVersionDisplay(){this.versionEl&&(this.versionEl.innerHTML=`v${this.version}`)}getPerformanceStats(){const e=this.sceneModule2d.getSceneStats();return{fps:this.currentFps,renderTime:0,entityCount:e.objectCount,visibleEntityCount:e.objectCount}}setBackgroundColor(e){this.options.backgroundColor=e,this.sceneModule2d&&this.sceneModule2d.setBackgroundColor(e),this.cadCursorUI?.setBackgroundColor(e),this.modelToolModule2d?.updateColorsForBackground(e),this.layerManager?.refresh()}clearScene(){this.sceneModule2d&&this.sceneModule2d.clearScene()}resize(){if(this.renderModule2d){const e=this.container?.clientWidth??0,t=this.container?.clientHeight??0;this.renderModule2d.setSize(e,t)}}captureImage(e){if(!this.renderer||!this.sceneModule2d)return console.error("[EngineKernel2d] Renderer or scene module not initialized"),null;const t=this.renderer.domElement,i=e?.format||"png",n=e?.quality||.92,r=`image/${i==="jpeg"?"jpeg":i}`,s=e?.transparent??!1,o=e?.hideGrid??!0,a=e?.hideAxes??!0,l=this.scene?.background??null;let c=!1,f=!1;this.sceneModule2d.adaptiveGrid&&(c=this.sceneModule2d.adaptiveGrid.gridGroup?.visible??!1,o&&this.sceneModule2d.adaptiveGrid.setVisible(!1)),this.sceneModule2d.axesHelper&&(f=this.sceneModule2d.axesHelper.visible??!1,a&&this.sceneModule2d.setAxesVisible(!1)),s&&this.scene&&(this.scene.background=null),this.scene&&this.camera&&this.renderer.render(this.scene,this.camera);const p=t.toDataURL(r,n);this.scene&&(this.scene.background=l),this.sceneModule2d.adaptiveGrid&&o&&this.sceneModule2d.adaptiveGrid.setVisible(c),this.sceneModule2d.axesHelper&&a&&this.sceneModule2d.setAxesVisible(f),this.scene&&this.camera&&this.renderer.render(this.scene,this.camera);const d={dataURL:p};if(e?.download){const y=e.filename||`capture-${Date.now()}.${i}`,h=document.createElement("a");h.href=p,h.download=y,h.style.display="none",document.body.appendChild(h),h.click(),h.remove(),console.log(`[EngineKernel2d] Image captured and downloaded: ${y}`)}else console.log("[EngineKernel2d] Image captured");return d}async captureImageAsync(e){if(!this.renderer||!this.sceneModule2d)return console.error("[EngineKernel2d] Renderer or scene module not initialized"),null;const t=this.renderer.domElement,i=e?.format||"png",n=e?.quality||.92,r=`image/${i==="jpeg"?"jpeg":i}`,s=e?.transparent??!1,o=e?.hideGrid??!0,a=e?.hideAxes??!0,l=this.scene?.background??null;let c=!1,f=!1;this.sceneModule2d.adaptiveGrid&&(c=this.sceneModule2d.adaptiveGrid.gridGroup?.visible??!1,o&&this.sceneModule2d.adaptiveGrid.setVisible(!1)),this.sceneModule2d.axesHelper&&(f=this.sceneModule2d.axesHelper.visible??!1,a&&this.sceneModule2d.setAxesVisible(!1)),s&&this.scene&&(this.scene.background=null),this.scene&&this.camera&&this.renderer.render(this.scene,this.camera);const p=t.toDataURL(r,n),d=await new Promise(h=>{t.toBlob(g=>{g&&h(g)},r,n)}),y=URL.createObjectURL(d);if(this.scene&&(this.scene.background=l),this.sceneModule2d.adaptiveGrid&&o&&this.sceneModule2d.adaptiveGrid.setVisible(c),this.sceneModule2d.axesHelper&&a&&this.sceneModule2d.setAxesVisible(f),this.scene&&this.camera&&this.renderer.render(this.scene,this.camera),e?.download){const h=e.filename||`capture-${Date.now()}.${i}`,g=document.createElement("a");g.href=y,g.download=h,g.style.display="none",document.body.appendChild(g),g.click(),g.remove(),console.log(`[EngineKernel2d] Image captured and downloaded: ${h}`)}else console.log("[EngineKernel2d] Image captured with Blob URL:",y);return{dataURL:p,blobURL:y,blob:d}}dispose(){console.log("[EngineKernel2d] Disposing engine..."),this.stopRendering(),this.cadCursorUI?.dispose(),this.contextMenuUI?.dispose(),this.loadingUI?.dispose(),this.workspaceTabsUI?.dispose(),this.versionEl?.parentElement?.removeChild(this.versionEl),this.searchManager?.dispose(),this.measure?.dispose(),this.markup?.dispose(),this.label?.dispose(),this.themeManager?.dispose(),this.loaderModule2d?.dispose(),this.controlModule2d?.dispose(),this.renderModule2d?.dispose(),this.cameraModule2d?.dispose(),this.sceneModule2d?.dispose(),this.events?.dispose(),this.stats?.dom?.parentElement&&this.stats.dom.parentElement.removeChild(this.stats.dom),this.scene=null,this.camera=null,this.renderer=null,this.dwgData=null,this.stats=void 0,this.versionEl=null,console.log("[EngineKernel2d] Engine disposed")}}function lt(k){return new at(k)}ve.EngineKernel2d=at,ve.createEngine2d=lt,ve.default=lt,Object.defineProperties(ve,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}));
@@ -266,7 +266,7 @@ class M {
266
266
  });
267
267
  }
268
268
  }
269
- const w = "3.9.16", v = {
269
+ const w = "3.9.18", v = {
270
270
  version: w
271
271
  }, R = v.version;
272
272
  class I {
@@ -1 +1 @@
1
- (function(a,l){typeof exports=="object"&&typeof module<"u"?l(exports,require("three"),require("@mkkellogg/gaussian-splats-3d")):typeof define=="function"&&define.amd?define(["exports","three","@mkkellogg/gaussian-splats-3d"],l):(a=typeof globalThis<"u"?globalThis:a||self,l(a.Gaussian={},a.THREE,a.GaussianSplats3D))})(this,(function(a,l,m){"use strict";function c(r){const e=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(r){for(const t in r)if(t!=="default"){const i=Object.getOwnPropertyDescriptor(r,t);Object.defineProperty(e,t,i.get?i:{enumerable:!0,get:()=>r[t]})}}return e.default=r,Object.freeze(e)}const d=c(l),h=c(m);var o=(r=>(r.LoadStart="gaussian-load-start",r.LoadProgress="gaussian-load-progress",r.Loaded="gaussian-loaded",r.LoadError="gaussian-load-error",r.SceneRemoved="gaussian-scene-removed",r.FpsUpdated="gaussian-fps-updated",r.ViewChanged="gaussian-view-changed",r))(o||{});class f{listeners=new Map;on(e,t){const i=String(e);this.listeners.has(i)||this.listeners.set(i,[]),this.listeners.get(i).push(t)}off(e,t){const i=String(e),n=this.listeners.get(i);if(!n)return;const s=n.indexOf(t);s!==-1&&n.splice(s,1),n.length===0&&this.listeners.delete(i)}trigger(e,t){const i=this.listeners.get(String(e));!i||i.length===0||[...i].forEach(n=>{try{n(t)}catch(s){console.error(`[EventModuleGaussian] event handler failed: ${e}`,s)}})}clear(){this.listeners.clear()}dispose(){this.clear()}}class g{scene;constructor(e){this.scene=new d.Scene,e&&(this.scene.background=new d.Color(e))}getScene(){return this.scene}setBackgroundColor(e){this.scene.background=e==null?null:new d.Color(e)}dispose(){this.scene.clear(),this.scene.background=null,this.scene.environment=null}}class p{camera;container;cameraUp;initialLookAt;constructor(e,t,i,n){this.container=e,this.cameraUp=t,this.initialLookAt=n,this.camera=this.createCamera(i)}createCamera(e){const t=Math.max(this.container.clientWidth,1),i=Math.max(this.container.clientHeight,1),n=new d.PerspectiveCamera(65,t/i,.1,5e3);return n.position.fromArray(e),n.up.fromArray(this.cameraUp).normalize(),n.lookAt(new d.Vector3().fromArray(this.initialLookAt)),n.updateProjectionMatrix(),n}getCamera(){return this.camera}updateAspectRatio(e,t){this.camera.aspect=Math.max(e,1)/Math.max(t,1),this.camera.updateProjectionMatrix()}reset(e,t){e&&this.camera.position.fromArray(e),this.camera.lookAt(new d.Vector3().fromArray(t??this.initialLookAt)),this.camera.updateMatrixWorld(!0)}dispose(){this.camera=null}}class M{renderer;viewer;container;animationId=null;isRenderingPaused=!0;fpsFrameCount=0;fpsLastTime=performance.now();fpsInfo={fps:0,frameTimeMs:0,minFps:0};onBeforeRenderCallback;onAfterRenderCallback;onFpsUpdatedCallback;constructor(e,t,i,n){this.container=e,this.renderer=this.createRenderer(n.antialias),this.viewer=new h.Viewer({selfDrivenMode:!1,renderer:this.renderer,camera:i,threeScene:t,rootElement:e,useBuiltInControls:!0,cameraUp:n.cameraUp,initialCameraPosition:n.initialCameraPosition,initialCameraLookAt:n.initialCameraLookAt,sharedMemoryForWorkers:n.sharedMemoryForWorkers,gpuAcceleratedSort:n.gpuAcceleratedSort,sphericalHarmonicsDegree:n.sphericalHarmonicsDegree,...n.viewerOptions??{}})}createRenderer(e){const t=new d.WebGLRenderer({antialias:e,alpha:!0,preserveDrawingBuffer:!1});return t.setSize(Math.max(this.container.clientWidth,1),Math.max(this.container.clientHeight,1)),t.setPixelRatio(Math.min(window.devicePixelRatio,2)),this.container.appendChild(t.domElement),t}setOnBeforeRender(e){this.onBeforeRenderCallback=e}setOnAfterRender(e){this.onAfterRenderCallback=e}setOnFpsUpdated(e){this.onFpsUpdatedCallback=e}startRenderLoop(){this.animationId===null&&(this.isRenderingPaused=!1,this.animate())}animate(){if(this.isRenderingPaused){this.animationId=null;return}this.animationId=requestAnimationFrame(()=>this.animate()),this.render()}render(){this.onBeforeRenderCallback?.(),this.viewer.update(this.renderer),this.viewer.render(),this.onAfterRenderCallback?.(),this.updateFps()}updateFps(){this.fpsFrameCount++;const e=performance.now(),t=e-this.fpsLastTime;if(t<1e3)return;const i=Math.round(this.fpsFrameCount*1e3/t);this.fpsInfo={fps:i,frameTimeMs:i>0?1e3/i:0,minFps:this.fpsInfo.minFps===0?i:Math.min(this.fpsInfo.minFps,i)},this.fpsFrameCount=0,this.fpsLastTime=e,this.onFpsUpdatedCallback?.({...this.fpsInfo})}resetFpsStats(){this.fpsInfo={fps:0,frameTimeMs:0,minFps:0},this.fpsFrameCount=0,this.fpsLastTime=performance.now()}pauseRendering(){this.isRenderingPaused=!0,this.animationId!==null&&(cancelAnimationFrame(this.animationId),this.animationId=null)}resumeRendering(){this.isRenderingPaused&&this.startRenderLoop()}isRenderingPausedState(){return this.isRenderingPaused}resize(e,t){this.renderer.setSize(Math.max(e,1),Math.max(t,1)),this.renderer.setPixelRatio(Math.min(window.devicePixelRatio,2))}getViewer(){return this.viewer}getRenderer(){return this.renderer}getDomElement(){return this.renderer.domElement}getFpsInfo(){return{...this.fpsInfo}}async dispose(){this.pauseRendering(),await this.viewer.dispose(),this.container.contains(this.renderer.domElement)&&this.container.removeChild(this.renderer.domElement),this.renderer.dispose(),this.renderer.forceContextLoss()}}const w={identity:[0,0,0,1],"x-90":[-.7071068,0,0,.7071068],x90:[.7071068,0,0,.7071068],x180:[1,0,0,0],"y-90":[0,-.7071068,0,.7071068],y90:[0,.7071068,0,.7071068],"z-90":[0,0,-.7071068,.7071068],z90:[0,0,.7071068,.7071068],z180:[0,0,1,0]};class v{orientationPreset;constructor(e="x180"){this.orientationPreset=e}setOrientationPreset(e){this.orientationPreset=e}getOrientationPreset(){return this.orientationPreset}getOrientationRotation(){return[...w[this.orientationPreset]]}active(){}disActive(){}update(){}dispose(){}}function R(r,e){return`${r}#${e}`}class k{viewer;getDefaultRotation;scenes=new Map;constructor(e,t){this.viewer=e,this.getDefaultRotation=t}async loadModel(e,t={}){const i=this.viewer.getSceneCount(),n={showLoadingUI:!0,progressiveLoad:!1,position:[0,0,0],rotation:this.getDefaultRotation(),scale:[1,1,1],...t};await this.viewer.addSplatScene(e,n);const s={id:n.id??R(e,i),name:n.name??e.split(/[\\/]/).pop()??e,url:e,index:i,options:n};return this.scenes.set(s.id,s),s}async loadModels(e){const t=[];for(const i of e)t.push(await this.loadModel(i.url,i.options));return t}async unloadModel(e,t=!0){const i=this.scenes.get(e);i&&(await this.viewer.removeSplatScene(i.index,t),this.scenes.delete(e),this.reindexScenesAfterRemove(i.index))}getModel(e){return this.scenes.get(e)}getAllModels(){return Array.from(this.scenes.values())}getRawSplatScene(e){const t=typeof e=="number"?e:this.scenes.get(e)?.index;return t==null?void 0:this.viewer.getSplatScene(t)}async clear(e=!1){const t=this.getAllModels().map(i=>i.index);t.length>0&&await this.viewer.removeSplatScenes(t,e),this.scenes.clear()}reindexScenesAfterRemove(e){this.scenes.forEach(t=>{t.index>e&&(t.index-=1)})}}const I={version:"3.9.16"}.version;class u{eventModule;sceneModule;cameraModule;renderModule;controlModule;loaderModule;isInitialized=!1;version=I;constructor(e){this.initialize(e)}initialize(e){const t={containerId:e.containerId,cameraUp:e.cameraUp??[0,1,0],initialCameraPosition:e.initialCameraPosition??[0,0,6],initialCameraLookAt:e.initialCameraLookAt??[0,0,0],backgroundColor:e.backgroundColor,antialias:e.antialias??!1,showLoadingUI:e.showLoadingUI??!0,sharedMemoryForWorkers:e.sharedMemoryForWorkers??!1,gpuAcceleratedSort:e.gpuAcceleratedSort??!1,sphericalHarmonicsDegree:e.sphericalHarmonicsDegree??0,orientationPreset:e.orientationPreset??"x180",viewerOptions:e.viewerOptions},i=document.getElementById(t.containerId);if(!i)throw new Error(`Container with id "${t.containerId}" not found`);this.eventModule=new f,this.sceneModule=new g(t.backgroundColor),this.cameraModule=new p(i,t.cameraUp,t.initialCameraPosition,t.initialCameraLookAt),this.controlModule=new v(t.orientationPreset),this.renderModule=new M(i,this.sceneModule.getScene(),this.cameraModule.getCamera(),t),this.loaderModule=new k(this.renderModule.getViewer(),()=>this.controlModule.getOrientationRotation()),this.renderModule.setOnBeforeRender(()=>{this.controlModule.update()}),this.renderModule.setOnFpsUpdated(n=>{this.eventModule.trigger(o.FpsUpdated,n)}),this.renderModule.startRenderLoop(),this.isInitialized=!0}async loadModel(e,t={}){this.checkInitialized(),this.eventModule.trigger(o.LoadStart,{url:e,name:t.name});try{const i=await this.loaderModule.loadModel(e,{showLoadingUI:!0,...t,onProgress:(n,s,C)=>{this.eventModule.trigger(o.LoadProgress,{url:e,name:t.name,progress:n}),t.onProgress?.(n,s,C)}});return this.eventModule.trigger(o.Loaded,{url:e,name:i.name,progress:100}),i}catch(i){throw this.eventModule.trigger(o.LoadError,{url:e,name:t.name,error:i instanceof Error?i:new Error(String(i))}),i}}async unloadModel(e){this.checkInitialized(),await this.loaderModule.unloadModel(e,!1),this.eventModule.trigger(o.SceneRemoved,{id:e})}setOrientationPreset(e){this.checkInitialized(),this.controlModule.setOrientationPreset(e)}getOrientationPreset(){return this.checkInitialized(),this.controlModule.getOrientationPreset()}resize(e,t){this.checkInitialized();const i=this.renderModule.getDomElement(),n=e??i.parentElement?.clientWidth??i.clientWidth,s=t??i.parentElement?.clientHeight??i.clientHeight;this.renderModule.resize(n,s),this.cameraModule.updateAspectRatio(n,s)}pauseRendering(){this.checkInitialized(),this.renderModule.pauseRendering()}resumeRendering(){this.checkInitialized(),this.renderModule.resumeRendering()}resetFpsStats(){this.checkInitialized(),this.renderModule.resetFpsStats()}getFpsInfo(){return this.checkInitialized(),this.renderModule.getFpsInfo()}on(e,t){this.checkInitialized(),this.eventModule.on(e,t)}off(e,t){this.checkInitialized(),this.eventModule.off(e,t)}getVersion(){return this.version}async dispose(){this.isInitialized&&(await this.loaderModule.clear(!1),await this.renderModule.dispose(),this.controlModule.dispose(),this.cameraModule.dispose(),this.sceneModule.dispose(),this.eventModule.dispose(),this.isInitialized=!1)}checkInitialized(){if(!this.isInitialized)throw new Error("EngineKernelGaussian: Not initialized")}}function S(r){return new u(r)}a.GaussianSplats3D=h,a.EngineKernelGaussian=u,a.EventTypeGaussian=o,a.createEngineGaussian=S,Object.defineProperty(a,Symbol.toStringTag,{value:"Module"})}));
1
+ (function(a,l){typeof exports=="object"&&typeof module<"u"?l(exports,require("three"),require("@mkkellogg/gaussian-splats-3d")):typeof define=="function"&&define.amd?define(["exports","three","@mkkellogg/gaussian-splats-3d"],l):(a=typeof globalThis<"u"?globalThis:a||self,l(a.Gaussian={},a.THREE,a.GaussianSplats3D))})(this,(function(a,l,m){"use strict";function c(r){const e=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(r){for(const t in r)if(t!=="default"){const i=Object.getOwnPropertyDescriptor(r,t);Object.defineProperty(e,t,i.get?i:{enumerable:!0,get:()=>r[t]})}}return e.default=r,Object.freeze(e)}const d=c(l),h=c(m);var o=(r=>(r.LoadStart="gaussian-load-start",r.LoadProgress="gaussian-load-progress",r.Loaded="gaussian-loaded",r.LoadError="gaussian-load-error",r.SceneRemoved="gaussian-scene-removed",r.FpsUpdated="gaussian-fps-updated",r.ViewChanged="gaussian-view-changed",r))(o||{});class f{listeners=new Map;on(e,t){const i=String(e);this.listeners.has(i)||this.listeners.set(i,[]),this.listeners.get(i).push(t)}off(e,t){const i=String(e),n=this.listeners.get(i);if(!n)return;const s=n.indexOf(t);s!==-1&&n.splice(s,1),n.length===0&&this.listeners.delete(i)}trigger(e,t){const i=this.listeners.get(String(e));!i||i.length===0||[...i].forEach(n=>{try{n(t)}catch(s){console.error(`[EventModuleGaussian] event handler failed: ${e}`,s)}})}clear(){this.listeners.clear()}dispose(){this.clear()}}class g{scene;constructor(e){this.scene=new d.Scene,e&&(this.scene.background=new d.Color(e))}getScene(){return this.scene}setBackgroundColor(e){this.scene.background=e==null?null:new d.Color(e)}dispose(){this.scene.clear(),this.scene.background=null,this.scene.environment=null}}class p{camera;container;cameraUp;initialLookAt;constructor(e,t,i,n){this.container=e,this.cameraUp=t,this.initialLookAt=n,this.camera=this.createCamera(i)}createCamera(e){const t=Math.max(this.container.clientWidth,1),i=Math.max(this.container.clientHeight,1),n=new d.PerspectiveCamera(65,t/i,.1,5e3);return n.position.fromArray(e),n.up.fromArray(this.cameraUp).normalize(),n.lookAt(new d.Vector3().fromArray(this.initialLookAt)),n.updateProjectionMatrix(),n}getCamera(){return this.camera}updateAspectRatio(e,t){this.camera.aspect=Math.max(e,1)/Math.max(t,1),this.camera.updateProjectionMatrix()}reset(e,t){e&&this.camera.position.fromArray(e),this.camera.lookAt(new d.Vector3().fromArray(t??this.initialLookAt)),this.camera.updateMatrixWorld(!0)}dispose(){this.camera=null}}class M{renderer;viewer;container;animationId=null;isRenderingPaused=!0;fpsFrameCount=0;fpsLastTime=performance.now();fpsInfo={fps:0,frameTimeMs:0,minFps:0};onBeforeRenderCallback;onAfterRenderCallback;onFpsUpdatedCallback;constructor(e,t,i,n){this.container=e,this.renderer=this.createRenderer(n.antialias),this.viewer=new h.Viewer({selfDrivenMode:!1,renderer:this.renderer,camera:i,threeScene:t,rootElement:e,useBuiltInControls:!0,cameraUp:n.cameraUp,initialCameraPosition:n.initialCameraPosition,initialCameraLookAt:n.initialCameraLookAt,sharedMemoryForWorkers:n.sharedMemoryForWorkers,gpuAcceleratedSort:n.gpuAcceleratedSort,sphericalHarmonicsDegree:n.sphericalHarmonicsDegree,...n.viewerOptions??{}})}createRenderer(e){const t=new d.WebGLRenderer({antialias:e,alpha:!0,preserveDrawingBuffer:!1});return t.setSize(Math.max(this.container.clientWidth,1),Math.max(this.container.clientHeight,1)),t.setPixelRatio(Math.min(window.devicePixelRatio,2)),this.container.appendChild(t.domElement),t}setOnBeforeRender(e){this.onBeforeRenderCallback=e}setOnAfterRender(e){this.onAfterRenderCallback=e}setOnFpsUpdated(e){this.onFpsUpdatedCallback=e}startRenderLoop(){this.animationId===null&&(this.isRenderingPaused=!1,this.animate())}animate(){if(this.isRenderingPaused){this.animationId=null;return}this.animationId=requestAnimationFrame(()=>this.animate()),this.render()}render(){this.onBeforeRenderCallback?.(),this.viewer.update(this.renderer),this.viewer.render(),this.onAfterRenderCallback?.(),this.updateFps()}updateFps(){this.fpsFrameCount++;const e=performance.now(),t=e-this.fpsLastTime;if(t<1e3)return;const i=Math.round(this.fpsFrameCount*1e3/t);this.fpsInfo={fps:i,frameTimeMs:i>0?1e3/i:0,minFps:this.fpsInfo.minFps===0?i:Math.min(this.fpsInfo.minFps,i)},this.fpsFrameCount=0,this.fpsLastTime=e,this.onFpsUpdatedCallback?.({...this.fpsInfo})}resetFpsStats(){this.fpsInfo={fps:0,frameTimeMs:0,minFps:0},this.fpsFrameCount=0,this.fpsLastTime=performance.now()}pauseRendering(){this.isRenderingPaused=!0,this.animationId!==null&&(cancelAnimationFrame(this.animationId),this.animationId=null)}resumeRendering(){this.isRenderingPaused&&this.startRenderLoop()}isRenderingPausedState(){return this.isRenderingPaused}resize(e,t){this.renderer.setSize(Math.max(e,1),Math.max(t,1)),this.renderer.setPixelRatio(Math.min(window.devicePixelRatio,2))}getViewer(){return this.viewer}getRenderer(){return this.renderer}getDomElement(){return this.renderer.domElement}getFpsInfo(){return{...this.fpsInfo}}async dispose(){this.pauseRendering(),await this.viewer.dispose(),this.container.contains(this.renderer.domElement)&&this.container.removeChild(this.renderer.domElement),this.renderer.dispose(),this.renderer.forceContextLoss()}}const w={identity:[0,0,0,1],"x-90":[-.7071068,0,0,.7071068],x90:[.7071068,0,0,.7071068],x180:[1,0,0,0],"y-90":[0,-.7071068,0,.7071068],y90:[0,.7071068,0,.7071068],"z-90":[0,0,-.7071068,.7071068],z90:[0,0,.7071068,.7071068],z180:[0,0,1,0]};class v{orientationPreset;constructor(e="x180"){this.orientationPreset=e}setOrientationPreset(e){this.orientationPreset=e}getOrientationPreset(){return this.orientationPreset}getOrientationRotation(){return[...w[this.orientationPreset]]}active(){}disActive(){}update(){}dispose(){}}function R(r,e){return`${r}#${e}`}class k{viewer;getDefaultRotation;scenes=new Map;constructor(e,t){this.viewer=e,this.getDefaultRotation=t}async loadModel(e,t={}){const i=this.viewer.getSceneCount(),n={showLoadingUI:!0,progressiveLoad:!1,position:[0,0,0],rotation:this.getDefaultRotation(),scale:[1,1,1],...t};await this.viewer.addSplatScene(e,n);const s={id:n.id??R(e,i),name:n.name??e.split(/[\\/]/).pop()??e,url:e,index:i,options:n};return this.scenes.set(s.id,s),s}async loadModels(e){const t=[];for(const i of e)t.push(await this.loadModel(i.url,i.options));return t}async unloadModel(e,t=!0){const i=this.scenes.get(e);i&&(await this.viewer.removeSplatScene(i.index,t),this.scenes.delete(e),this.reindexScenesAfterRemove(i.index))}getModel(e){return this.scenes.get(e)}getAllModels(){return Array.from(this.scenes.values())}getRawSplatScene(e){const t=typeof e=="number"?e:this.scenes.get(e)?.index;return t==null?void 0:this.viewer.getSplatScene(t)}async clear(e=!1){const t=this.getAllModels().map(i=>i.index);t.length>0&&await this.viewer.removeSplatScenes(t,e),this.scenes.clear()}reindexScenesAfterRemove(e){this.scenes.forEach(t=>{t.index>e&&(t.index-=1)})}}const I={version:"3.9.18"}.version;class u{eventModule;sceneModule;cameraModule;renderModule;controlModule;loaderModule;isInitialized=!1;version=I;constructor(e){this.initialize(e)}initialize(e){const t={containerId:e.containerId,cameraUp:e.cameraUp??[0,1,0],initialCameraPosition:e.initialCameraPosition??[0,0,6],initialCameraLookAt:e.initialCameraLookAt??[0,0,0],backgroundColor:e.backgroundColor,antialias:e.antialias??!1,showLoadingUI:e.showLoadingUI??!0,sharedMemoryForWorkers:e.sharedMemoryForWorkers??!1,gpuAcceleratedSort:e.gpuAcceleratedSort??!1,sphericalHarmonicsDegree:e.sphericalHarmonicsDegree??0,orientationPreset:e.orientationPreset??"x180",viewerOptions:e.viewerOptions},i=document.getElementById(t.containerId);if(!i)throw new Error(`Container with id "${t.containerId}" not found`);this.eventModule=new f,this.sceneModule=new g(t.backgroundColor),this.cameraModule=new p(i,t.cameraUp,t.initialCameraPosition,t.initialCameraLookAt),this.controlModule=new v(t.orientationPreset),this.renderModule=new M(i,this.sceneModule.getScene(),this.cameraModule.getCamera(),t),this.loaderModule=new k(this.renderModule.getViewer(),()=>this.controlModule.getOrientationRotation()),this.renderModule.setOnBeforeRender(()=>{this.controlModule.update()}),this.renderModule.setOnFpsUpdated(n=>{this.eventModule.trigger(o.FpsUpdated,n)}),this.renderModule.startRenderLoop(),this.isInitialized=!0}async loadModel(e,t={}){this.checkInitialized(),this.eventModule.trigger(o.LoadStart,{url:e,name:t.name});try{const i=await this.loaderModule.loadModel(e,{showLoadingUI:!0,...t,onProgress:(n,s,C)=>{this.eventModule.trigger(o.LoadProgress,{url:e,name:t.name,progress:n}),t.onProgress?.(n,s,C)}});return this.eventModule.trigger(o.Loaded,{url:e,name:i.name,progress:100}),i}catch(i){throw this.eventModule.trigger(o.LoadError,{url:e,name:t.name,error:i instanceof Error?i:new Error(String(i))}),i}}async unloadModel(e){this.checkInitialized(),await this.loaderModule.unloadModel(e,!1),this.eventModule.trigger(o.SceneRemoved,{id:e})}setOrientationPreset(e){this.checkInitialized(),this.controlModule.setOrientationPreset(e)}getOrientationPreset(){return this.checkInitialized(),this.controlModule.getOrientationPreset()}resize(e,t){this.checkInitialized();const i=this.renderModule.getDomElement(),n=e??i.parentElement?.clientWidth??i.clientWidth,s=t??i.parentElement?.clientHeight??i.clientHeight;this.renderModule.resize(n,s),this.cameraModule.updateAspectRatio(n,s)}pauseRendering(){this.checkInitialized(),this.renderModule.pauseRendering()}resumeRendering(){this.checkInitialized(),this.renderModule.resumeRendering()}resetFpsStats(){this.checkInitialized(),this.renderModule.resetFpsStats()}getFpsInfo(){return this.checkInitialized(),this.renderModule.getFpsInfo()}on(e,t){this.checkInitialized(),this.eventModule.on(e,t)}off(e,t){this.checkInitialized(),this.eventModule.off(e,t)}getVersion(){return this.version}async dispose(){this.isInitialized&&(await this.loaderModule.clear(!1),await this.renderModule.dispose(),this.controlModule.dispose(),this.cameraModule.dispose(),this.sceneModule.dispose(),this.eventModule.dispose(),this.isInitialized=!1)}checkInitialized(){if(!this.isInitialized)throw new Error("EngineKernelGaussian: Not initialized")}}function S(r){return new u(r)}a.GaussianSplats3D=h,a.EngineKernelGaussian=u,a.EventTypeGaussian=o,a.createEngineGaussian=S,Object.defineProperty(a,Symbol.toStringTag,{value:"Module"})}));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "iflow-engine-base",
3
- "version": "3.9.17",
3
+ "version": "3.9.20",
4
4
  "description": "BIM Engine SDK for Vue2, Vue3, React and HTML",
5
5
  "main": "./dist/bim-engine-sdk.umd.js",
6
6
  "module": "./dist/bim-engine-sdk.es.js",