iflow-engine-base 3.10.9 → 3.11.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -41,6 +41,10 @@ declare class Annotation3d {
41
41
  add(config: Annotation3dData): string;
42
42
  /** 批量新增标记。 */
43
43
  addMany(configs: Annotation3dData[]): string[];
44
+ /**
45
+ * 进入模型选点状态,点击模型后返回用于创建标记的世界坐标;取消或不可用时返回 null。
46
+ */
47
+ pickPoint(): Promise<AnnotationPoint3d | null>;
44
48
  /** 更新标记时直接重建几何和窗体,保持内部状态简单且可预测。 */
45
49
  update(id: string, patch: Partial<Annotation3dData>): boolean;
46
50
  /** 删除单个标记。 */
@@ -5375,6 +5379,7 @@ declare class ModelToolModule {
5375
5379
  private appendUniqueIds;
5376
5380
  private restoreSplitModelsOnIdle;
5377
5381
  getSceneModel(index: number): any;
5382
+ getModelCenter(models?: any[]): THREE.Vector3 | null;
5378
5383
  updateMaterial(): void;
5379
5384
  private syncHighlightModelEdges;
5380
5385
  private getUniqueHighlightModels;
@@ -7031,6 +7036,7 @@ declare class ViewCube {
7031
7036
  cameraGoHome(time: number): void;
7032
7037
  zoomToModel(box: any): void;
7033
7038
  zoomToModels(m: any): void;
7039
+ flyToModels(ms?: any[]): void;
7034
7040
  saveMainViewPort(): any;
7035
7041
  setMainViewPort(data: any): void;
7036
7042
  goToMainPort(): void;
@@ -9188,7 +9188,7 @@ class to {
9188
9188
  this.unsubscribe(), this.el.remove();
9189
9189
  }
9190
9190
  }
9191
- const ro = "3.10.9", io = {
9191
+ const ro = "3.11.1", io = {
9192
9192
  version: ro
9193
9193
  }, Mt = io.version;
9194
9194
  function hi() {
@@ -218,7 +218,7 @@
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
- `,a.addEventListener("click",()=>this.selectResult(n)),a.addEventListener("mouseenter",()=>{this.activeIndex=s,this.highlightItem(this.resultList.querySelectorAll(".engine-2d-search__item"))}),this.resultList.appendChild(a)})}highlight(e,t){const r=this.escapeHtml(e),n=t.trim();if(!n)return r;const s=this.escapeRegExp(this.escapeHtml(n));return r.replace(new RegExp(`(${s})`,"gi"),'<mark class="engine-2d-search__mark">$1</mark>')}highlightItem(e){e.forEach((t,r)=>{t.classList.toggle("engine-2d-search__item--active",r===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 Sa{engine;searchUI=null;constructor(e){this.engine=e;const t=document.getElementById(e?.options?.containerId??"")??e?.container??null;t&&(this.searchUI=new wa(t,this))}search(e){const t=this.normalize(e);return t?(this.engine.loaderModule2d?.model?.textItems??[]).map(n=>{const s=this.getMatchScore(n.text,t);return s==null?null:{id:n.id,name:n.text,type:"文字",layer:n.layer,description:this.getPositionDescription(n),score:s,target:n}}).filter(n=>n!==null).sort((n,s)=>(s.score??0)-(n.score??0)||n.name.length-s.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(),r=e.max?.clone(),n=e.anchor?.clone();if((!t||!r||t.distanceTo(r)<1e-6)&&n){const i=Math.max(Number(e.info?.height??100),100);this.engine.cameraModule2d?.fitToExtents({min:[n.x-i,n.y-i,0],max:[n.x+i,n.y+i,0]},2,!0,500);return}if(!t||!r)return;const s=new j.Vector3().subVectors(r,t),a=Math.max(s.x,s.y)<1e-6?2:2.5;this.engine.cameraModule2d?.fitToExtents({min:[t.x,t.y,t.z],max:[r.x,r.y,r.z]},a,!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 r=this.normalize(e);if(!r)return null;const n=r.indexOf(t);if(n>=0)return 1e3-n-Math.max(0,r.length-t.length)*.01;let s=0,a=0;for(const i of t){const l=r.indexOf(i,s);if(l<0)return null;a+=l-s,s=l+1}return 500-a-Math.max(0,r.length-t.length)*.01}show(){this.searchUI?.show()}hide(){this.searchUI?.hide()}toggle(){this.searchUI?.toggle()}dispose(){this.searchUI?.dispose(),this.searchUI=null}}const Gi={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 Ta{container;current;constructor(e,t="dark"){this.container=e,this.current=t,this._apply(t)}_apply(e){const t=Gi[e];for(const[r,n]of Object.entries(t))this.container.style.setProperty(r,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(Gi[this.current]))this.container.style.removeProperty(e);this.container.removeAttribute("data-e2d-theme")}}const Wi={precision:3,unit:"m",areaUnit:"m²",scale:1};class yr{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 Aa extends yr{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 _a extends yr{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 Ia extends yr{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 ka{distanceMeasure;areaMeasure;angleMeasure;annotationData={distanceAnnotation:[],areaAnnotation:[],angleAnnotation:[]};engine;container;annotationContainer;setting={...Wi};isActive=!1;currentTool=null;previewRecord=null;mouseDownPoint=null;hasDraggedAfterMouseDown=!1;currentWorkspaceKey="model";constructor(e){this.engine=e,this.container=e.container,this.distanceMeasure=new Aa(this),this.areaMeasure=new _a(this),this.angleMeasure=new Ia(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 r=this.createRecord(e,t,!1);return this.annotationContainer.appendChild(r.container),this.getRecords(e).push(r),this.updateRecordSvg(r),this.engine.events?.trigger?.("measure-changed",r),r}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(s=>s.clone());const t=e.map(s=>s.clone()),r=t[t.length-1],n=t[t.length-2];return r.distanceTo(n)<1e-6&&t.pop(),t}disActiveMeasureTools(){this.distanceMeasure.disActive(),this.areaMeasure.disActive(),this.angleMeasure.disActive()}handleMouseDown=e=>{this.mouseDownPoint=new j.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 j.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(),r=this.engine.cameraModule2d.screenToWorld(e.clientX-t.left,e.clientY-t.top);return r.z=0,r}createRecord(e,t,r){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 s=this.createSvg(e);r&&(s.style.opacity="0.65"),n.appendChild(s);const a=this.computeValue(e,t),i={id:this.createId(),type:e,workspaceKey:this.currentWorkspaceKey,points:t.map(l=>l.clone()),container:n,svg:s,value:a,text:this.formatValue(e,a),isSelect:r};return r||this.bindRecordSelection(i),i}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 i=this.svgElement("polygon");i.setAttribute("fill","rgba(0, 155, 234, 0.12)"),i.setAttribute("stroke","none"),t.appendChild(i)}const r=e==="angle"?2:1;for(let i=0;i<r;i++){const l=this.svgElement("polyline");l.classList.add("measureLine"),l.setAttribute("stroke-width","2"),l.setAttribute("style","fill: none; opacity: 1;"),t.appendChild(l)}const n=e==="angle"?3:e==="distance"?2:0;for(let i=0;i<n;i++){const l=this.svgElement("circle");l.classList.add("measurePointer"),l.setAttribute("r","5"),t.appendChild(l)}const s=this.svgElement("rect");s.classList.add("measureBack"),s.setAttribute("width","100"),s.setAttribute("height","25"),s.style.pointerEvents="auto",s.style.cursor="pointer",t.appendChild(s);const a=this.svgElement("text");return a.classList.add("measureLabel"),a.setAttribute("text-anchor","middle"),t.appendChild(a),t}bindRecordSelection(e){e.svg.getElementsByTagName("rect")[0].addEventListener("click",r=>{r.preventDefault(),r.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,r=this.container.clientHeight||1;e.svg.setAttribute("width",`${t}`),e.svg.setAttribute("height",`${r}`),e.svg.style.width=`${t}px`,e.svg.style.height=`${r}px`;const n=e.points.map(s=>this.worldToScreen(s));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[r,n]=t,s=e.svg.getElementsByTagName("polyline")[0],a=e.svg.getElementsByTagName("circle");s.setAttribute("points",`${r.x},${r.y} ${n.x},${n.y}`),a[0].setAttribute("cx",`${r.x}`),a[0].setAttribute("cy",`${r.y}`),a[1].setAttribute("cx",`${n.x}`),a[1].setAttribute("cy",`${n.y}`),this.updateLabel(e,(r.x+n.x)/2,(r.y+n.y)/2)}updateAreaSvg(e,t){const r=t.map(i=>`${i.x},${i.y}`).join(" "),s=(t.length>=3?[...t,t[0]]:t).map(i=>`${i.x},${i.y}`).join(" ");e.svg.getElementsByTagName("polygon")[0].setAttribute("points",t.length>=3?r:""),e.svg.getElementsByTagName("polyline")[0].setAttribute("points",s);const a=t.reduce((i,l)=>(i.x+=l.x,i.y+=l.y,i),{x:0,y:0});this.updateLabel(e,a.x/t.length,a.y/t.length)}updateAngleSvg(e,t){const[r,n,s]=t,a=e.svg.getElementsByTagName("polyline"),i=e.svg.getElementsByTagName("circle");a[0].setAttribute("points",`${r.x},${r.y} ${n.x},${n.y}`),a[1].setAttribute("points",`${n.x},${n.y} ${s.x},${s.y}`),[r,n,s].forEach((l,c)=>{i[c].setAttribute("cx",`${l.x}`),i[c].setAttribute("cy",`${l.y}`)}),this.updateLabel(e,n.x,n.y-30)}updateLabel(e,t,r){e.value=this.computeValue(e.type,e.points),e.text=this.formatValue(e.type,e.value);const n=e.svg.getElementsByTagName("rect")[0],s=e.svg.getElementsByTagName("text")[0],a=Math.max(100,e.text.length*9+22);n.setAttribute("x",`${t-a/2}`),n.setAttribute("y",`${r-12.5}`),n.setAttribute("width",`${a}`),s.setAttribute("x",`${t}`),s.setAttribute("y",`${r+4}`),s.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 r=0;r<e.length;r++){const n=e[r],s=e[(r+1)%e.length];t+=n.x*s.y-s.x*n.y}return Math.abs(t)/2}computeAngle(e,t,r){const n=e.clone().sub(t).normalize(),s=r.clone().sub(t).normalize(),a=j.MathUtils.clamp(n.dot(s),-1,1);return j.MathUtils.radToDeg(Math.acos(a))}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 r=e.length-1;r>=0;r-=1)t(e[r])&&(e[r].container.remove(),e.splice(r,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))):Wi.precision}createId(){return`measure-2d-${Date.now()}-${Math.random().toString(16).slice(2)}`}}const vr={stroke:"#ff4d4f",fill:"rgba(255, 77, 79, 0.08)",strokeWidth:2,fontSize:16,cloudRadius:10},Ba={none:mt("/assets/icon/选择.svg",typeof document>"u"&&typeof location>"u"?require("url").pathToFileURL(__filename).href:typeof document>"u"?location.href:Ae&&Ae.tagName.toUpperCase()==="SCRIPT"&&Ae.src||new URL("dwg-preview.umd.js",document.baseURI).href),line:mt("/assets/icon/线.svg",typeof document>"u"&&typeof location>"u"?require("url").pathToFileURL(__filename).href:typeof document>"u"?location.href:Ae&&Ae.tagName.toUpperCase()==="SCRIPT"&&Ae.src||new URL("dwg-preview.umd.js",document.baseURI).href),arrow:mt("/assets/icon/箭头.svg",typeof document>"u"&&typeof location>"u"?require("url").pathToFileURL(__filename).href:typeof document>"u"?location.href:Ae&&Ae.tagName.toUpperCase()==="SCRIPT"&&Ae.src||new URL("dwg-preview.umd.js",document.baseURI).href),rect:mt("/assets/icon/矩形.svg",typeof document>"u"&&typeof location>"u"?require("url").pathToFileURL(__filename).href:typeof document>"u"?location.href:Ae&&Ae.tagName.toUpperCase()==="SCRIPT"&&Ae.src||new URL("dwg-preview.umd.js",document.baseURI).href),ellipse:mt("/assets/icon/圆形.svg",typeof document>"u"&&typeof location>"u"?require("url").pathToFileURL(__filename).href:typeof document>"u"?location.href:Ae&&Ae.tagName.toUpperCase()==="SCRIPT"&&Ae.src||new URL("dwg-preview.umd.js",document.baseURI).href),polygon:mt("/assets/icon/面积.svg",typeof document>"u"&&typeof location>"u"?require("url").pathToFileURL(__filename).href:typeof document>"u"?location.href:Ae&&Ae.tagName.toUpperCase()==="SCRIPT"&&Ae.src||new URL("dwg-preview.umd.js",document.baseURI).href),text:mt("/assets/icon/文字.svg",typeof document>"u"&&typeof location>"u"?require("url").pathToFileURL(__filename).href:typeof document>"u"?location.href:Ae&&Ae.tagName.toUpperCase()==="SCRIPT"&&Ae.src||new URL("dwg-preview.umd.js",document.baseURI).href),cloudline:mt("/assets/icon/云线.svg",typeof document>"u"&&typeof location>"u"?require("url").pathToFileURL(__filename).href:typeof document>"u"?location.href:Ae&&Ae.tagName.toUpperCase()==="SCRIPT"&&Ae.src||new URL("dwg-preview.umd.js",document.baseURI).href)},Ma="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>'),La="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 Ra{engine;container;layer;svg;toolbar;records=[];isActive=!1;currentType=null;style={...vr};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(r=>{r.element.style.display=r.data.workspaceKey===this.currentWorkspaceKey?"":"none",this.updateElement(r)}),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??{}}},r=this.createRecord(t);return this.records.push(r),this.svg.appendChild(r.element),this.updateElement(r),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 r=this.records[t];!e&&r.data.workspaceKey!==this.currentWorkspaceKey||(r.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 j.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 j.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,r=this.removeTrailingDuplicatePoints(this.polygonPoints);r.length>=t&&this.addMarkup({type:this.currentType,points:r.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,r=this.removeTrailingDuplicatePoints(this.polygonPoints);r.length>=t&&this.addMarkup({type:this.currentType,points:r.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(l=>{const c=this.createIconButton(l.title,Ba[l.type]);c.onclick=()=>{this.active(),this.setDrawType(l.type)},l.type!=="none"&&(this.buttons[l.type]=c),e.appendChild(c)}),e.appendChild(this.createDivider());const r=document.createElement("input");r.type="color",r.value=this.style.stroke,r.title="颜色",r.oninput=()=>{this.style.stroke=r.value,this.style.fill=this.hexToTransparent(r.value)},e.appendChild(r);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,vr.strokeWidth)},e.appendChild(n);const s=document.createElement("input");s.type="number",s.min="10",s.max="72",s.value=`${this.style.fontSize}`,s.title="字号",s.onchange=()=>{this.style.fontSize=this.normalizeNumber(s.valueAsNumber,10,72,vr.fontSize)},e.appendChild(s),e.appendChild(this.createDivider());const a=this.createIconButton("清空",Ma);a.onclick=()=>this.clearAll(),e.appendChild(a);const i=this.createIconButton("关闭",La);return i.onclick=()=>{this.hideToolbar(),this.disActive()},e.appendChild(i),e}createDivider(){const e=document.createElement("div");return e.className="markup-2d-divider",e}createIconButton(e,t){const r=document.createElement("button");r.type="button",r.title=e,r.setAttribute("aria-label",e),r.classList.add("markup-2d-icon-button");const n=document.createElement("img");return n.src=t,n.alt=e,n.draggable=!1,r.appendChild(n),r}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(r=>this.pointToData(r)),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 r={data:this.cloneData(e),element:t};return this.applyStyle(r),this.bindSelection(r),r}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(r=>this.worldToScreen(r));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,r){const n=e.element;if(n.innerHTML="",t.length<2)return;const[s,a]=t,i=this.svgElement("line");if(i.setAttribute("x1",`${s.x}`),i.setAttribute("y1",`${s.y}`),i.setAttribute("x2",`${a.x}`),i.setAttribute("y2",`${a.y}`),this.applySvgPaint(i,e.data.style,!1),n.appendChild(i),e===this.draft&&this.drawVertexMarkers(n,t,e.data.style),!r)return;const l=this.createArrowHead(s,a,e.data.style.strokeWidth);this.applySvgPaint(l,e.data.style,!0),l.setAttribute("fill",e.data.style.stroke),n.appendChild(l)}updateRect(e,t){if(t.length<2)return;const[r,n]=t,s=e.element;s.setAttribute("x",`${Math.min(r.x,n.x)}`),s.setAttribute("y",`${Math.min(r.y,n.y)}`),s.setAttribute("width",`${Math.abs(n.x-r.x)}`),s.setAttribute("height",`${Math.abs(n.y-r.y)}`)}updateEllipse(e,t){if(t.length<2)return;const[r,n]=t,s=e.element;s.setAttribute("cx",`${(r.x+n.x)/2}`),s.setAttribute("cy",`${(r.y+n.y)/2}`),s.setAttribute("rx",`${Math.abs(n.x-r.x)/2}`),s.setAttribute("ry",`${Math.abs(n.y-r.y)/2}`)}updateText(e,t){const r=e.element;r.setAttribute("x",`${t.x}`),r.setAttribute("y",`${t.y}`),r.textContent=e.data.text??""}updatePolygon(e,t){const r=e.element;if(r.innerHTML="",t.length===0)return;const n=t.map(a=>`${a.x},${a.y}`).join(" "),s=t.length>=3?this.svgElement("polygon"):this.svgElement("polyline");s.setAttribute("points",n),this.applySvgPaint(s,e.data.style,t.length>=3),r.appendChild(s),e===this.draft&&this.drawVertexMarkers(r,t,e.data.style)}updateCloudLine(e,t){const r=e.element;if(r.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),r.appendChild(n),e===this.draft&&this.drawVertexMarkers(r,t,e.data.style)}drawVertexMarkers(e,t,r){t.forEach(n=>{const s=this.svgElement("circle");s.setAttribute("cx",`${n.x}`),s.setAttribute("cy",`${n.y}`),s.setAttribute("r",`${Math.max(3,r.strokeWidth+2)}`),s.setAttribute("fill",r.stroke),s.setAttribute("stroke","#ffffff"),s.setAttribute("stroke-width","1"),e.appendChild(s)})}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,r){e.setAttribute("stroke",t.stroke),e.setAttribute("stroke-width",`${t.strokeWidth}`),e.setAttribute("fill",r?t.fill:"none"),e.setAttribute("stroke-linecap","round"),e.setAttribute("stroke-linejoin","round")}createArrowHead(e,t,r){const n=Math.atan2(t.y-e.y,t.x-e.x),s=Math.max(10,r*5),a={x:t.x-s*Math.cos(n-Math.PI/6),y:t.y-s*Math.sin(n-Math.PI/6)},i={x:t.x-s*Math.cos(n+Math.PI/6),y:t.y-s*Math.sin(n+Math.PI/6)},l=this.svgElement("polygon");return l.setAttribute("points",`${t.x},${t.y} ${a.x},${a.y} ${i.x},${i.y}`),l}buildCloudPath(e,t){if(e.length===0)return"";if(e.length===1)return`M ${e[0].x} ${e[0].y}`;const r=Math.max(4,t),n=[`M ${e[0].x} ${e[0].y}`];for(let s=0;s<e.length-1;s+=1){const a=e[s],i=e[s+1],l=i.x-a.x,c=i.y-a.y,p=Math.hypot(l,c);if(p<1e-6)continue;const b=Math.max(1,Math.ceil(p/(r*1.6)));for(let x=0;x<b;x+=1){const h=x/b,m=(x+1)/b,d=(h+m)/2,y={x:a.x+l*d-c/p*r*.7,y:a.y+c*d+l/p*r*.7},u={x:a.x+l*m,y:a.y+c*m};n.push(`Q ${y.x} ${y.y} ${u.x} ${u.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(r=>r.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(),r=this.engine.cameraModule2d.screenToWorld(e.clientX-t.left,e.clientY-t.top);return r.z=0,r}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("#",""),r=parseInt(t.slice(0,2),16),n=parseInt(t.slice(2,4),16),s=parseInt(t.slice(4,6),16);return`rgba(${r}, ${n}, ${s}, 0.08)`}normalizeNumber(e,t,r,n){return Number.isFinite(e)?Math.max(t,Math.min(r,Math.round(e))):n}createId(){return`markup-2d-${Date.now()}-${Math.random().toString(16).slice(2)}`}}class Na{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 r=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:r};return this.labels.set(t,n),this.labelContainer.appendChild(r),this.renderLabel(n),this.updateLabelPosition(n),this.emitEvent?.("label-created",this.toPayload(n)),t}updateLabel(e,t){const r=this.labels.get(e);return r?(t.coordinate&&(r.coordinate={...t.coordinate}),t.icon!==void 0&&(r.icon=t.icon),t.name!==void 0&&(r.name=t.name),t.data!==void 0&&(r.data=t.data),t.iconSize!==void 0&&(r.size=t.iconSize),t.size!==void 0&&(r.size=t.size),t.visible!==void 0&&(r.visible=t.visible),this.renderLabel(r),this.updateLabelPosition(r),this.emitEvent?.("label-updated",this.toPayload(r)),!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",r=>{r.preventDefault(),r.stopPropagation();const n=this.labels.get(e);if(!n)return;const s={id:e,label:n,coordinate:n.coordinate,originalEvent:r};this.clickCallbacks.forEach(a=>a(s)),this.emitEvent?.("label-click",s)}),t}renderLabel(e){e.element.innerHTML="";const t=document.createElement("img"),r=this.normalizeIconSize(e.size);t.src=e.icon,t.alt=e.name,t.style.cssText=[`width:${r.width}px`,`height:${r.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 Pa{engine;manager;constructor(e){this.engine=e,this.manager=new Na({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,r)=>this.engine.events?.trigger?.(t,r)})}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),r=this.engine.renderer.domElement.clientWidth,n=this.engine.renderer.domElement.clientHeight;return{x:t.x,y:t.y,visible:t.x>=0&&t.x<=r&&t.y>=0&&t.y<=n}}pickCoordinate(e){const t=this.engine.renderer.domElement.getBoundingClientRect(),r=this.engine.cameraModule2d.screenToWorld(e.clientX-t.left,e.clientY-t.top);return{x:r.x,y:r.y,z:0}}}class Da{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 Ua{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(et.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((r,n)=>{const s=r.name||`布局${n+1}`;this.el.appendChild(this.createTab(s,t.type==="layout"&&t.layoutId===r.id,()=>this.switchToLayout(r.id)))}),this.el.style.display=e.length>0?"flex":"none"}createTab(e,t,r){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",r),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 Mt={version:"3.10.9"}.version;function xr(){const o=globalThis.crypto?.subtle;if(!o)throw new Error("[BimEngine] Web Crypto API is required for secure sdkAuth credentials mode");return o}function Lt(o){return new TextEncoder().encode(o)}function Rt(o){return o.buffer.slice(o.byteOffset,o.byteOffset+o.byteLength)}function ji(o){let e="";return o.forEach(t=>{e+=String.fromCharCode(t)}),btoa(e)}function Va(o){const e=o.getUTCFullYear(),t=String(o.getUTCMonth()+1).padStart(2,"0"),r=String(o.getUTCDate()).padStart(2,"0");return`${e}${t}${r}`}async function Oa(o){const e=await xr().digest("SHA-256",Rt(Lt(o)));return Array.from(new Uint8Array(e)).map(t=>t.toString(16).padStart(2,"0")).join("")}async function Fa(o,e){const t=xr(),r=await t.importKey("raw",Rt(o),{name:"HMAC",hash:"SHA-256"},!1,["sign"]);return t.sign("HMAC",r,Rt(Lt(e)))}function za(o){return Lt([o.appId,o.engineType,o.requestDate,String(o.timestamp),o.nonce].join("|"))}async function Ka(o){const e=xr(),t=new Date,r=t.getTime(),n=Va(t),s=globalThis.crypto.randomUUID(),a=globalThis.crypto.getRandomValues(new Uint8Array(12)),i=await Oa(o.appSecret),l=await Fa(Lt(i),n),c=await e.importKey("raw",l,"AES-GCM",!1,["encrypt"]),p=JSON.stringify({appKey:o.appKey,appSecret:o.appSecret}),b=await e.encrypt({name:"AES-GCM",iv:a,additionalData:Rt(za({appId:o.appId,engineType:o.engineType,requestDate:n,timestamp:r,nonce:s})),tagLength:128},c,Rt(Lt(p)));return{appId:o.appId,engineType:o.engineType,requestDate:n,timestamp:r,nonce:s,iv:ji(a),cipherText:ji(new Uint8Array(b)),sdkVersion:o.sdkVersion,origin:o.origin,product:o.product}}const Cr=new Map;function Yt(o){return o.replace(/\/+$/,"")}function $t(o){if(o)return o;if(typeof window<"u"&&typeof window.location?.origin=="string")return window.location.origin}function Ha(o,e){return JSON.stringify({endpoint:Yt(o.endpoint),token:o.token??"",appId:o.appId??"",appKey:o.appKey??"",appSecret:o.appSecret??"",origin:$t(o.origin)??"",product:o.product??"",engineType:e,sdkVersion:Mt})}async function br(o,e,t){const r=typeof AbortController<"u"?new AbortController:void 0,n=r?setTimeout(()=>r.abort(),t):void 0;try{const s=await fetch(o,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e),signal:r?.signal}),a=await s.json().catch(()=>({}));if(!s.ok){const i=a?.error?.message??a?.message??`SDK authentication failed with status ${s.status}`;throw new Error(i)}return a}finally{n!=null&&clearTimeout(n)}}async function Ga(o,e){const t=await br(`${Yt(o.endpoint)}/oauth/sdk-verify`,{sdkToken:o.token,engineType:e,sdkVersion:Mt,origin:$t(o.origin),product:o.product},o.timeoutMs??8e3);return t.sdkToken=o.token,t}async function Wa(o,e){const t=await Ka({appId:o.appId,appKey:o.appKey,appSecret:o.appSecret,engineType:e,sdkVersion:Mt,origin:$t(o.origin),product:o.product}),r=await br(`${Yt(o.endpoint)}/oauth/sdk-token/secure`,t,o.timeoutMs??8e3),n=await br(`${Yt(o.endpoint)}/oauth/sdk-verify`,{sdkToken:r.sdkToken,engineType:e,sdkVersion:Mt,origin:$t(o.origin),product:o.product},o.timeoutMs??8e3);return n.sdkToken=r.sdkToken,n}async function ja(o,e){const t=o?.sdkAuth;if(!t)return null;if(!t.endpoint)throw new Error("[BimEngine] sdkAuth.endpoint is required");if(!t.token&&!(t.appId&&t.appKey&&t.appSecret))return null;const r=Ha(t,e),n=Cr.get(r);if(n){const a=await n;return o&&(o.__sdkAuthSession=a),a}const s=(t.token?Ga(t,e):Wa(t,e)).then(a=>{if(a.authorized!==!0)throw new Error("[BimEngine] SDK authorization rejected");return o&&(o.__sdkAuthSession=a),a}).catch(a=>{throw Cr.delete(r),a});return Cr.set(r,s),s}function qa(o){return o instanceof Uint8Array||ArrayBuffer.isView(o)&&o.constructor.name==="Uint8Array"&&"BYTES_PER_ELEMENT"in o&&o.BYTES_PER_ELEMENT===1}function qi(o){if(typeof o!="number")throw new TypeError("number expected, got "+typeof o);if(!Number.isSafeInteger(o)||o<0)throw new RangeError("positive integer expected, got "+o)}function tt(o,e,t=""){const r=qa(o),n=o?.length,s=e!==void 0;if(!r||s&&n!==e){const a=t&&`"${t}" `,i=s?` of length ${e}`:"",l=r?`length=${n}`:`type=${typeof o}`,c=a+"expected Uint8Array"+i+", got "+l;throw r?new RangeError(c):new TypeError(c)}return o}function Yi(o,e=!0){if(o.destroyed)throw new Error("Hash instance has been destroyed");if(e&&o.finished)throw new Error("Hash#digest() has already been called")}function Ya(o,e,t=!1){tt(o,void 0,"output");const r=e.outputLen;if(o.length<r)throw new RangeError("digestInto() expects output buffer of length at least "+r);if(t&&!Nt(o))throw new Error("invalid output, must be aligned")}function $a(o){return new Uint8Array(o.buffer,o.byteOffset,o.byteLength)}function wt(o){return new Uint32Array(o.buffer,o.byteOffset,Math.floor(o.byteLength/4))}function Ct(...o){for(let e=0;e<o.length;e++)o[e].fill(0)}function Zt(o){return new DataView(o.buffer,o.byteOffset,o.byteLength)}const Er=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68,$i=o=>o<<24&4278190080|o<<8&16711680|o>>>8&65280|o>>>24&255,Ne=Er?o=>o:o=>$i(o)>>>0,wr=Er?o=>o:o=>{for(let e=0;e<o.length;e++)o[e]=$i(o[e]);return o};function Za(o,e){if(o.length!==e.length)return!1;let t=0;for(let r=0;r<o.length;r++)t|=o[r]^e[r];return t===0}function Xa(o,e,t){const r=e,n=t||(()=>[]),s=(i,l)=>r(l,...n(i)).update(i).digest(),a=r(new Uint8Array(o),...n(new Uint8Array(0)));return s.outputLen=a.outputLen,s.blockLen=a.blockLen,s.create=(i,...l)=>r(i,...l),s}const Qa=(o,e)=>{function t(r,...n){if(tt(r,void 0,"key"),o.nonceLength!==void 0){const p=n[0];tt(p,o.varSizeNonce?void 0:o.nonceLength,"nonce")}const s=o.tagLength;s&&n[1]!==void 0&&tt(n[1],void 0,"AAD");const a=e(r,...n),i=(p,b)=>{if(b!==void 0){if(p!==2)throw new Error("cipher output not supported");tt(b,void 0,"output")}};let l=!1;return{encrypt(p,b){if(l)throw new Error("cannot encrypt() twice with same key + nonce");return l=!0,tt(p),i(a.encrypt.length,b),a.encrypt(p,b)},decrypt(p,b){if(tt(p),s&&p.length<s)throw new Error('"ciphertext" expected length bigger than tagLength='+s);return i(a.decrypt.length,b),a.decrypt(p,b)}}}return Object.assign(t,o),t};function Ja(o,e,t=!0){if(e===void 0)return new Uint8Array(o);if(tt(e,void 0,"output"),e.length!==o)throw new Error('"output" expected Uint8Array of length '+o+", got: "+e.length);if(t&&!Nt(e))throw new Error("invalid output, must be aligned");return e}function eo(o,e,t){qi(o),qi(e);const r=new Uint8Array(16),n=Zt(r);return n.setBigUint64(0,BigInt(e),t),n.setBigUint64(8,BigInt(o),t),r}function Nt(o){return o.byteOffset%4===0}function Pt(o){return Uint8Array.from(tt(o))}const At=16,Zi=new Uint8Array(16),Dt=wt(Zi),to=225,ro=(o,e,t,r)=>{const n=r&1;return{s3:t<<31|r>>>1,s2:e<<31|t>>>1,s1:o<<31|e>>>1,s0:o>>>1^to<<24&-(n&1)}},Xt=o=>(o>>>0&255)<<24|(o>>>8&255)<<16|(o>>>16&255)<<8|o>>>24&255|0,io=o=>o>64*1024?8:o>1024?4:2;class no{blockLen=At;outputLen=At;s0=0;s1=0;s2=0;s3=0;finished=!1;destroyed=!1;t;W;windowSize;constructor(e,t){tt(e,16,"key"),e=Pt(e);const r=Zt(e);let n=r.getUint32(0,!1),s=r.getUint32(4,!1),a=r.getUint32(8,!1),i=r.getUint32(12,!1);const l=[];for(let m=0;m<128;m++)l.push({s0:Xt(n),s1:Xt(s),s2:Xt(a),s3:Xt(i)}),{s0:n,s1:s,s2:a,s3:i}=ro(n,s,a,i);const c=io(t||1024);if(![1,2,4,8].includes(c))throw new Error("ghash: invalid window size, expected 2, 4 or 8");this.W=c;const b=128/c,x=this.windowSize=2**c,h=[];for(let m=0;m<b;m++)for(let d=0;d<x;d++){let y=0,u=0,v=0,E=0;for(let T=0;T<c;T++){if(!(d>>>c-T-1&1))continue;const{s0:w,s1:g,s2:f,s3:k}=l[c*m+T];y^=w,u^=g,v^=f,E^=k}h.push({s0:y,s1:u,s2:v,s3:E})}this.t=h}_updateBlock(e,t,r,n){e^=this.s0,t^=this.s1,r^=this.s2,n^=this.s3;const{W:s,t:a,windowSize:i}=this;let l=0,c=0,p=0,b=0;const x=(1<<s)-1;let h=0;for(const m of[e,t,r,n])for(let d=0;d<4;d++){const y=m>>>8*d&255;for(let u=8/s-1;u>=0;u--){const v=y>>>s*u&x,{s0:E,s1:T,s2:_,s3:w}=a[h*i+v];l^=E,c^=T,p^=_,b^=w,h+=1}}this.s0=l,this.s1=c,this.s2=p,this.s3=b}update(e){Yi(this),tt(e),e=Pt(e);const t=wt(e),r=Math.floor(e.length/At),n=e.length%At;for(let s=0;s<r;s++)this._updateBlock(Ne(t[s*4+0]),Ne(t[s*4+1]),Ne(t[s*4+2]),Ne(t[s*4+3]));return n&&(Zi.set(e.subarray(r*At)),this._updateBlock(Ne(Dt[0]),Ne(Dt[1]),Ne(Dt[2]),Ne(Dt[3])),Ct(Dt)),this}destroy(){this.destroyed=!0;const{t:e}=this;for(const t of e)t.s0=0,t.s1=0,t.s2=0,t.s3=0}digestInto(e){Yi(this),Ya(e,this,!0),this.finished=!0;const{s0:t,s1:r,s2:n,s3:s}=this,a=wt(e);a[0]=t,a[1]=r,a[2]=n,a[3]=s,wr(a)}digest(){const e=new Uint8Array(At);return this.digestInto(e),this.destroy(),e}}const Xi=Xa(16,(o,e)=>new no(o,e),o=>[o.length]),Sr=16,so=4,Qt=new Uint8Array(Sr),ao=283;function oo(o){if(![16,24,32].includes(o.length))throw new Error('"aes key" expected Uint8Array of length 16/24/32, got length='+o.length)}function Tr(o){return o<<1^ao&-(o>>7)}function Qi(o,e){let t=0;for(;e>0;e>>=1)t^=o&-(e&1),o=Tr(o);return t}const lo=(()=>{const o=new Uint8Array(256);for(let t=0,r=1;t<256;t++,r^=Tr(r))o[t]=r;const e=new Uint8Array(256);e[0]=99;for(let t=0;t<255;t++){let r=o[255-t];r|=r<<8,e[o[t]]=(r^r>>4^r>>5^r>>6^r>>7^99)&255}return Ct(o),e})(),co=o=>o<<24|o>>>8,Ar=o=>o<<8|o>>>24;function uo(o,e){if(o.length!==256)throw new Error("Wrong sbox length");const t=new Uint32Array(256).map((c,p)=>e(o[p])),r=t.map(Ar),n=r.map(Ar),s=n.map(Ar),a=new Uint32Array(256*256),i=new Uint32Array(256*256),l=new Uint16Array(256*256);for(let c=0;c<256;c++)for(let p=0;p<256;p++){const b=c*256+p;a[b]=t[c]^r[p],i[b]=n[c]^s[p],l[b]=o[c]<<8|o[p]}return{sbox:o,sbox2:l,T0:t,T1:r,T2:n,T3:s,T01:a,T23:i}}const Ji=uo(lo,o=>Qi(o,3)<<24|o<<16|o<<8|Qi(o,2)),ho=(()=>{const o=new Uint8Array(16);for(let e=0,t=1;e<16;e++,t=Tr(t))o[e]=t;return o})();function fo(o){tt(o);const e=o.length;oo(o);const{sbox2:t}=Ji,r=[];(!Er||!Nt(o))&&r.push(o=Pt(o));const n=wr(wt(o)),s=n.length,a=l=>Ut(t,l,l,l,l),i=new Uint32Array(e+28);i.set(n);for(let l=s;l<i.length;l++){let c=i[l-1];l%s===0?c=a(co(c))^ho[l/s-1]:s>6&&l%s===4&&(c=a(c)),i[l]=i[l-s]^c}return Ct(...r),i}function Jt(o,e,t,r,n,s){return o[t<<8&65280|r>>>8&255]^e[n>>>8&65280|s>>>24&255]}function Ut(o,e,t,r,n){return o[e&255|t&65280]|o[r>>>16&255|n>>>16&65280]<<16}function en(o,e,t,r,n){const{sbox2:s,T01:a,T23:i}=Ji;let l=0;e^=o[l++],t^=o[l++],r^=o[l++],n^=o[l++];const c=o.length/4-2;for(let m=0;m<c;m++){const d=o[l++]^Jt(a,i,e,t,r,n),y=o[l++]^Jt(a,i,t,r,n,e),u=o[l++]^Jt(a,i,r,n,e,t),v=o[l++]^Jt(a,i,n,e,t,r);e=d,t=y,r=u,n=v}const p=o[l++]^Ut(s,e,t,r,n),b=o[l++]^Ut(s,t,r,n,e),x=o[l++]^Ut(s,r,n,e,t),h=o[l++]^Ut(s,n,e,t,r);return{s0:p,s1:b,s2:x,s3:h}}function er(o,e,t,r,n){tt(t,Sr,"nonce"),tt(r),n=Ja(r.length,n);const s=t,a=wt(s),i=Zt(s),l=wt(r),c=wt(n),p=e?0:12,b=r.length;let x=i.getUint32(p,e),{s0:h,s1:m,s2:d,s3:y}=en(o,Ne(a[0]),Ne(a[1]),Ne(a[2]),Ne(a[3]));for(let v=0;v+4<=l.length;v+=4)c[v+0]=l[v+0]^Ne(h),c[v+1]=l[v+1]^Ne(m),c[v+2]=l[v+2]^Ne(d),c[v+3]=l[v+3]^Ne(y),x=x+1>>>0,i.setUint32(p,x,e),{s0:h,s1:m,s2:d,s3:y}=en(o,Ne(a[0]),Ne(a[1]),Ne(a[2]),Ne(a[3]));const u=Sr*Math.floor(l.length/so);if(u<b){const v=new Uint32Array([h,m,d,y]);wr(v);const E=$a(v);for(let T=u,_=0;T<b;T++,_++)n[T]=r[T]^E[_];Ct(v)}return n}function po(o,e,t,r,n){const s=n?n.length:0,a=o.create(t,r.length+s);n&&a.update(n);const i=eo(8*r.length,8*s,e);a.update(r),a.update(i);const l=a.digest();return Ct(i),l}const go=Qa({blockSize:16,nonceLength:12,tagLength:16,varSizeNonce:!0},function(e,t,r){if(t.length<8)throw new Error("aes/gcm: invalid nonce length");const n=16;function s(i,l,c){const p=po(Xi,!1,i,c,r);for(let b=0;b<l.length;b++)p[b]^=l[b];return p}function a(){const i=fo(e),l=Qt.slice(),c=Qt.slice();if(er(i,!1,c,c,l),t.length===12)c.set(t);else{const b=Qt.slice();Zt(b).setBigUint64(8,BigInt(t.length*8),!1);const h=Xi.create(l).update(t).update(b);h.digestInto(c),h.destroy()}const p=er(i,!1,c,Qt);return{xk:i,authKey:l,counter:c,tagMask:p}}return{encrypt(i){const{xk:l,authKey:c,counter:p,tagMask:b}=a(),x=new Uint8Array(i.length+n),h=[l,c,p,b];Nt(i)||h.push(i=Pt(i)),er(l,!1,p,i,x.subarray(0,i.length));const m=s(c,b,x.subarray(0,x.length-n));return h.push(m),x.set(m,i.length),Ct(...h),x},decrypt(i){const{xk:l,authKey:c,counter:p,tagMask:b}=a(),x=[l,c,b,p];Nt(i)||x.push(i=Pt(i));const h=i.subarray(0,-n),m=i.subarray(-n),d=s(c,b,h);if(x.push(d),!Za(d,m))throw Ct(...x),new Error("aes/gcm: invalid ghash tag");const y=er(l,!1,p,h);return Ct(...x),y}}});var _r,tn;function xe(){return tn||(tn=1,_r={options:{usePureJavaScript:!1}}),_r}var Ir={exports:{}},kr,rn;function mo(){if(rn)return kr;rn=1;var o={};kr=o;var e={};o.encode=function(r,n,s){if(typeof n!="string")throw new TypeError('"alphabet" must be a string.');if(s!==void 0&&typeof s!="number")throw new TypeError('"maxline" must be a number.');var a="";if(!(r instanceof Uint8Array))a=t(r,n);else{var i=0,l=n.length,c=n.charAt(0),p=[0];for(i=0;i<r.length;++i){for(var b=0,x=r[i];b<p.length;++b)x+=p[b]<<8,p[b]=x%l,x=x/l|0;for(;x>0;)p.push(x%l),x=x/l|0}for(i=0;r[i]===0&&i<r.length-1;++i)a+=c;for(i=p.length-1;i>=0;--i)a+=n[p[i]]}if(s){var h=new RegExp(".{1,"+s+"}","g");a=a.match(h).join(`\r
221
+ `,a.addEventListener("click",()=>this.selectResult(n)),a.addEventListener("mouseenter",()=>{this.activeIndex=s,this.highlightItem(this.resultList.querySelectorAll(".engine-2d-search__item"))}),this.resultList.appendChild(a)})}highlight(e,t){const r=this.escapeHtml(e),n=t.trim();if(!n)return r;const s=this.escapeRegExp(this.escapeHtml(n));return r.replace(new RegExp(`(${s})`,"gi"),'<mark class="engine-2d-search__mark">$1</mark>')}highlightItem(e){e.forEach((t,r)=>{t.classList.toggle("engine-2d-search__item--active",r===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 Sa{engine;searchUI=null;constructor(e){this.engine=e;const t=document.getElementById(e?.options?.containerId??"")??e?.container??null;t&&(this.searchUI=new wa(t,this))}search(e){const t=this.normalize(e);return t?(this.engine.loaderModule2d?.model?.textItems??[]).map(n=>{const s=this.getMatchScore(n.text,t);return s==null?null:{id:n.id,name:n.text,type:"文字",layer:n.layer,description:this.getPositionDescription(n),score:s,target:n}}).filter(n=>n!==null).sort((n,s)=>(s.score??0)-(n.score??0)||n.name.length-s.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(),r=e.max?.clone(),n=e.anchor?.clone();if((!t||!r||t.distanceTo(r)<1e-6)&&n){const i=Math.max(Number(e.info?.height??100),100);this.engine.cameraModule2d?.fitToExtents({min:[n.x-i,n.y-i,0],max:[n.x+i,n.y+i,0]},2,!0,500);return}if(!t||!r)return;const s=new j.Vector3().subVectors(r,t),a=Math.max(s.x,s.y)<1e-6?2:2.5;this.engine.cameraModule2d?.fitToExtents({min:[t.x,t.y,t.z],max:[r.x,r.y,r.z]},a,!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 r=this.normalize(e);if(!r)return null;const n=r.indexOf(t);if(n>=0)return 1e3-n-Math.max(0,r.length-t.length)*.01;let s=0,a=0;for(const i of t){const l=r.indexOf(i,s);if(l<0)return null;a+=l-s,s=l+1}return 500-a-Math.max(0,r.length-t.length)*.01}show(){this.searchUI?.show()}hide(){this.searchUI?.hide()}toggle(){this.searchUI?.toggle()}dispose(){this.searchUI?.dispose(),this.searchUI=null}}const Gi={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 Ta{container;current;constructor(e,t="dark"){this.container=e,this.current=t,this._apply(t)}_apply(e){const t=Gi[e];for(const[r,n]of Object.entries(t))this.container.style.setProperty(r,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(Gi[this.current]))this.container.style.removeProperty(e);this.container.removeAttribute("data-e2d-theme")}}const Wi={precision:3,unit:"m",areaUnit:"m²",scale:1};class yr{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 Aa extends yr{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 _a extends yr{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 Ia extends yr{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 ka{distanceMeasure;areaMeasure;angleMeasure;annotationData={distanceAnnotation:[],areaAnnotation:[],angleAnnotation:[]};engine;container;annotationContainer;setting={...Wi};isActive=!1;currentTool=null;previewRecord=null;mouseDownPoint=null;hasDraggedAfterMouseDown=!1;currentWorkspaceKey="model";constructor(e){this.engine=e,this.container=e.container,this.distanceMeasure=new Aa(this),this.areaMeasure=new _a(this),this.angleMeasure=new Ia(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 r=this.createRecord(e,t,!1);return this.annotationContainer.appendChild(r.container),this.getRecords(e).push(r),this.updateRecordSvg(r),this.engine.events?.trigger?.("measure-changed",r),r}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(s=>s.clone());const t=e.map(s=>s.clone()),r=t[t.length-1],n=t[t.length-2];return r.distanceTo(n)<1e-6&&t.pop(),t}disActiveMeasureTools(){this.distanceMeasure.disActive(),this.areaMeasure.disActive(),this.angleMeasure.disActive()}handleMouseDown=e=>{this.mouseDownPoint=new j.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 j.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(),r=this.engine.cameraModule2d.screenToWorld(e.clientX-t.left,e.clientY-t.top);return r.z=0,r}createRecord(e,t,r){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 s=this.createSvg(e);r&&(s.style.opacity="0.65"),n.appendChild(s);const a=this.computeValue(e,t),i={id:this.createId(),type:e,workspaceKey:this.currentWorkspaceKey,points:t.map(l=>l.clone()),container:n,svg:s,value:a,text:this.formatValue(e,a),isSelect:r};return r||this.bindRecordSelection(i),i}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 i=this.svgElement("polygon");i.setAttribute("fill","rgba(0, 155, 234, 0.12)"),i.setAttribute("stroke","none"),t.appendChild(i)}const r=e==="angle"?2:1;for(let i=0;i<r;i++){const l=this.svgElement("polyline");l.classList.add("measureLine"),l.setAttribute("stroke-width","2"),l.setAttribute("style","fill: none; opacity: 1;"),t.appendChild(l)}const n=e==="angle"?3:e==="distance"?2:0;for(let i=0;i<n;i++){const l=this.svgElement("circle");l.classList.add("measurePointer"),l.setAttribute("r","5"),t.appendChild(l)}const s=this.svgElement("rect");s.classList.add("measureBack"),s.setAttribute("width","100"),s.setAttribute("height","25"),s.style.pointerEvents="auto",s.style.cursor="pointer",t.appendChild(s);const a=this.svgElement("text");return a.classList.add("measureLabel"),a.setAttribute("text-anchor","middle"),t.appendChild(a),t}bindRecordSelection(e){e.svg.getElementsByTagName("rect")[0].addEventListener("click",r=>{r.preventDefault(),r.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,r=this.container.clientHeight||1;e.svg.setAttribute("width",`${t}`),e.svg.setAttribute("height",`${r}`),e.svg.style.width=`${t}px`,e.svg.style.height=`${r}px`;const n=e.points.map(s=>this.worldToScreen(s));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[r,n]=t,s=e.svg.getElementsByTagName("polyline")[0],a=e.svg.getElementsByTagName("circle");s.setAttribute("points",`${r.x},${r.y} ${n.x},${n.y}`),a[0].setAttribute("cx",`${r.x}`),a[0].setAttribute("cy",`${r.y}`),a[1].setAttribute("cx",`${n.x}`),a[1].setAttribute("cy",`${n.y}`),this.updateLabel(e,(r.x+n.x)/2,(r.y+n.y)/2)}updateAreaSvg(e,t){const r=t.map(i=>`${i.x},${i.y}`).join(" "),s=(t.length>=3?[...t,t[0]]:t).map(i=>`${i.x},${i.y}`).join(" ");e.svg.getElementsByTagName("polygon")[0].setAttribute("points",t.length>=3?r:""),e.svg.getElementsByTagName("polyline")[0].setAttribute("points",s);const a=t.reduce((i,l)=>(i.x+=l.x,i.y+=l.y,i),{x:0,y:0});this.updateLabel(e,a.x/t.length,a.y/t.length)}updateAngleSvg(e,t){const[r,n,s]=t,a=e.svg.getElementsByTagName("polyline"),i=e.svg.getElementsByTagName("circle");a[0].setAttribute("points",`${r.x},${r.y} ${n.x},${n.y}`),a[1].setAttribute("points",`${n.x},${n.y} ${s.x},${s.y}`),[r,n,s].forEach((l,c)=>{i[c].setAttribute("cx",`${l.x}`),i[c].setAttribute("cy",`${l.y}`)}),this.updateLabel(e,n.x,n.y-30)}updateLabel(e,t,r){e.value=this.computeValue(e.type,e.points),e.text=this.formatValue(e.type,e.value);const n=e.svg.getElementsByTagName("rect")[0],s=e.svg.getElementsByTagName("text")[0],a=Math.max(100,e.text.length*9+22);n.setAttribute("x",`${t-a/2}`),n.setAttribute("y",`${r-12.5}`),n.setAttribute("width",`${a}`),s.setAttribute("x",`${t}`),s.setAttribute("y",`${r+4}`),s.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 r=0;r<e.length;r++){const n=e[r],s=e[(r+1)%e.length];t+=n.x*s.y-s.x*n.y}return Math.abs(t)/2}computeAngle(e,t,r){const n=e.clone().sub(t).normalize(),s=r.clone().sub(t).normalize(),a=j.MathUtils.clamp(n.dot(s),-1,1);return j.MathUtils.radToDeg(Math.acos(a))}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 r=e.length-1;r>=0;r-=1)t(e[r])&&(e[r].container.remove(),e.splice(r,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))):Wi.precision}createId(){return`measure-2d-${Date.now()}-${Math.random().toString(16).slice(2)}`}}const vr={stroke:"#ff4d4f",fill:"rgba(255, 77, 79, 0.08)",strokeWidth:2,fontSize:16,cloudRadius:10},Ba={none:mt("/assets/icon/选择.svg",typeof document>"u"&&typeof location>"u"?require("url").pathToFileURL(__filename).href:typeof document>"u"?location.href:Ae&&Ae.tagName.toUpperCase()==="SCRIPT"&&Ae.src||new URL("dwg-preview.umd.js",document.baseURI).href),line:mt("/assets/icon/线.svg",typeof document>"u"&&typeof location>"u"?require("url").pathToFileURL(__filename).href:typeof document>"u"?location.href:Ae&&Ae.tagName.toUpperCase()==="SCRIPT"&&Ae.src||new URL("dwg-preview.umd.js",document.baseURI).href),arrow:mt("/assets/icon/箭头.svg",typeof document>"u"&&typeof location>"u"?require("url").pathToFileURL(__filename).href:typeof document>"u"?location.href:Ae&&Ae.tagName.toUpperCase()==="SCRIPT"&&Ae.src||new URL("dwg-preview.umd.js",document.baseURI).href),rect:mt("/assets/icon/矩形.svg",typeof document>"u"&&typeof location>"u"?require("url").pathToFileURL(__filename).href:typeof document>"u"?location.href:Ae&&Ae.tagName.toUpperCase()==="SCRIPT"&&Ae.src||new URL("dwg-preview.umd.js",document.baseURI).href),ellipse:mt("/assets/icon/圆形.svg",typeof document>"u"&&typeof location>"u"?require("url").pathToFileURL(__filename).href:typeof document>"u"?location.href:Ae&&Ae.tagName.toUpperCase()==="SCRIPT"&&Ae.src||new URL("dwg-preview.umd.js",document.baseURI).href),polygon:mt("/assets/icon/面积.svg",typeof document>"u"&&typeof location>"u"?require("url").pathToFileURL(__filename).href:typeof document>"u"?location.href:Ae&&Ae.tagName.toUpperCase()==="SCRIPT"&&Ae.src||new URL("dwg-preview.umd.js",document.baseURI).href),text:mt("/assets/icon/文字.svg",typeof document>"u"&&typeof location>"u"?require("url").pathToFileURL(__filename).href:typeof document>"u"?location.href:Ae&&Ae.tagName.toUpperCase()==="SCRIPT"&&Ae.src||new URL("dwg-preview.umd.js",document.baseURI).href),cloudline:mt("/assets/icon/云线.svg",typeof document>"u"&&typeof location>"u"?require("url").pathToFileURL(__filename).href:typeof document>"u"?location.href:Ae&&Ae.tagName.toUpperCase()==="SCRIPT"&&Ae.src||new URL("dwg-preview.umd.js",document.baseURI).href)},Ma="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>'),La="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 Ra{engine;container;layer;svg;toolbar;records=[];isActive=!1;currentType=null;style={...vr};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(r=>{r.element.style.display=r.data.workspaceKey===this.currentWorkspaceKey?"":"none",this.updateElement(r)}),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??{}}},r=this.createRecord(t);return this.records.push(r),this.svg.appendChild(r.element),this.updateElement(r),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 r=this.records[t];!e&&r.data.workspaceKey!==this.currentWorkspaceKey||(r.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 j.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 j.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,r=this.removeTrailingDuplicatePoints(this.polygonPoints);r.length>=t&&this.addMarkup({type:this.currentType,points:r.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,r=this.removeTrailingDuplicatePoints(this.polygonPoints);r.length>=t&&this.addMarkup({type:this.currentType,points:r.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(l=>{const c=this.createIconButton(l.title,Ba[l.type]);c.onclick=()=>{this.active(),this.setDrawType(l.type)},l.type!=="none"&&(this.buttons[l.type]=c),e.appendChild(c)}),e.appendChild(this.createDivider());const r=document.createElement("input");r.type="color",r.value=this.style.stroke,r.title="颜色",r.oninput=()=>{this.style.stroke=r.value,this.style.fill=this.hexToTransparent(r.value)},e.appendChild(r);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,vr.strokeWidth)},e.appendChild(n);const s=document.createElement("input");s.type="number",s.min="10",s.max="72",s.value=`${this.style.fontSize}`,s.title="字号",s.onchange=()=>{this.style.fontSize=this.normalizeNumber(s.valueAsNumber,10,72,vr.fontSize)},e.appendChild(s),e.appendChild(this.createDivider());const a=this.createIconButton("清空",Ma);a.onclick=()=>this.clearAll(),e.appendChild(a);const i=this.createIconButton("关闭",La);return i.onclick=()=>{this.hideToolbar(),this.disActive()},e.appendChild(i),e}createDivider(){const e=document.createElement("div");return e.className="markup-2d-divider",e}createIconButton(e,t){const r=document.createElement("button");r.type="button",r.title=e,r.setAttribute("aria-label",e),r.classList.add("markup-2d-icon-button");const n=document.createElement("img");return n.src=t,n.alt=e,n.draggable=!1,r.appendChild(n),r}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(r=>this.pointToData(r)),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 r={data:this.cloneData(e),element:t};return this.applyStyle(r),this.bindSelection(r),r}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(r=>this.worldToScreen(r));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,r){const n=e.element;if(n.innerHTML="",t.length<2)return;const[s,a]=t,i=this.svgElement("line");if(i.setAttribute("x1",`${s.x}`),i.setAttribute("y1",`${s.y}`),i.setAttribute("x2",`${a.x}`),i.setAttribute("y2",`${a.y}`),this.applySvgPaint(i,e.data.style,!1),n.appendChild(i),e===this.draft&&this.drawVertexMarkers(n,t,e.data.style),!r)return;const l=this.createArrowHead(s,a,e.data.style.strokeWidth);this.applySvgPaint(l,e.data.style,!0),l.setAttribute("fill",e.data.style.stroke),n.appendChild(l)}updateRect(e,t){if(t.length<2)return;const[r,n]=t,s=e.element;s.setAttribute("x",`${Math.min(r.x,n.x)}`),s.setAttribute("y",`${Math.min(r.y,n.y)}`),s.setAttribute("width",`${Math.abs(n.x-r.x)}`),s.setAttribute("height",`${Math.abs(n.y-r.y)}`)}updateEllipse(e,t){if(t.length<2)return;const[r,n]=t,s=e.element;s.setAttribute("cx",`${(r.x+n.x)/2}`),s.setAttribute("cy",`${(r.y+n.y)/2}`),s.setAttribute("rx",`${Math.abs(n.x-r.x)/2}`),s.setAttribute("ry",`${Math.abs(n.y-r.y)/2}`)}updateText(e,t){const r=e.element;r.setAttribute("x",`${t.x}`),r.setAttribute("y",`${t.y}`),r.textContent=e.data.text??""}updatePolygon(e,t){const r=e.element;if(r.innerHTML="",t.length===0)return;const n=t.map(a=>`${a.x},${a.y}`).join(" "),s=t.length>=3?this.svgElement("polygon"):this.svgElement("polyline");s.setAttribute("points",n),this.applySvgPaint(s,e.data.style,t.length>=3),r.appendChild(s),e===this.draft&&this.drawVertexMarkers(r,t,e.data.style)}updateCloudLine(e,t){const r=e.element;if(r.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),r.appendChild(n),e===this.draft&&this.drawVertexMarkers(r,t,e.data.style)}drawVertexMarkers(e,t,r){t.forEach(n=>{const s=this.svgElement("circle");s.setAttribute("cx",`${n.x}`),s.setAttribute("cy",`${n.y}`),s.setAttribute("r",`${Math.max(3,r.strokeWidth+2)}`),s.setAttribute("fill",r.stroke),s.setAttribute("stroke","#ffffff"),s.setAttribute("stroke-width","1"),e.appendChild(s)})}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,r){e.setAttribute("stroke",t.stroke),e.setAttribute("stroke-width",`${t.strokeWidth}`),e.setAttribute("fill",r?t.fill:"none"),e.setAttribute("stroke-linecap","round"),e.setAttribute("stroke-linejoin","round")}createArrowHead(e,t,r){const n=Math.atan2(t.y-e.y,t.x-e.x),s=Math.max(10,r*5),a={x:t.x-s*Math.cos(n-Math.PI/6),y:t.y-s*Math.sin(n-Math.PI/6)},i={x:t.x-s*Math.cos(n+Math.PI/6),y:t.y-s*Math.sin(n+Math.PI/6)},l=this.svgElement("polygon");return l.setAttribute("points",`${t.x},${t.y} ${a.x},${a.y} ${i.x},${i.y}`),l}buildCloudPath(e,t){if(e.length===0)return"";if(e.length===1)return`M ${e[0].x} ${e[0].y}`;const r=Math.max(4,t),n=[`M ${e[0].x} ${e[0].y}`];for(let s=0;s<e.length-1;s+=1){const a=e[s],i=e[s+1],l=i.x-a.x,c=i.y-a.y,p=Math.hypot(l,c);if(p<1e-6)continue;const b=Math.max(1,Math.ceil(p/(r*1.6)));for(let x=0;x<b;x+=1){const h=x/b,m=(x+1)/b,d=(h+m)/2,y={x:a.x+l*d-c/p*r*.7,y:a.y+c*d+l/p*r*.7},u={x:a.x+l*m,y:a.y+c*m};n.push(`Q ${y.x} ${y.y} ${u.x} ${u.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(r=>r.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(),r=this.engine.cameraModule2d.screenToWorld(e.clientX-t.left,e.clientY-t.top);return r.z=0,r}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("#",""),r=parseInt(t.slice(0,2),16),n=parseInt(t.slice(2,4),16),s=parseInt(t.slice(4,6),16);return`rgba(${r}, ${n}, ${s}, 0.08)`}normalizeNumber(e,t,r,n){return Number.isFinite(e)?Math.max(t,Math.min(r,Math.round(e))):n}createId(){return`markup-2d-${Date.now()}-${Math.random().toString(16).slice(2)}`}}class Na{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 r=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:r};return this.labels.set(t,n),this.labelContainer.appendChild(r),this.renderLabel(n),this.updateLabelPosition(n),this.emitEvent?.("label-created",this.toPayload(n)),t}updateLabel(e,t){const r=this.labels.get(e);return r?(t.coordinate&&(r.coordinate={...t.coordinate}),t.icon!==void 0&&(r.icon=t.icon),t.name!==void 0&&(r.name=t.name),t.data!==void 0&&(r.data=t.data),t.iconSize!==void 0&&(r.size=t.iconSize),t.size!==void 0&&(r.size=t.size),t.visible!==void 0&&(r.visible=t.visible),this.renderLabel(r),this.updateLabelPosition(r),this.emitEvent?.("label-updated",this.toPayload(r)),!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",r=>{r.preventDefault(),r.stopPropagation();const n=this.labels.get(e);if(!n)return;const s={id:e,label:n,coordinate:n.coordinate,originalEvent:r};this.clickCallbacks.forEach(a=>a(s)),this.emitEvent?.("label-click",s)}),t}renderLabel(e){e.element.innerHTML="";const t=document.createElement("img"),r=this.normalizeIconSize(e.size);t.src=e.icon,t.alt=e.name,t.style.cssText=[`width:${r.width}px`,`height:${r.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 Pa{engine;manager;constructor(e){this.engine=e,this.manager=new Na({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,r)=>this.engine.events?.trigger?.(t,r)})}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),r=this.engine.renderer.domElement.clientWidth,n=this.engine.renderer.domElement.clientHeight;return{x:t.x,y:t.y,visible:t.x>=0&&t.x<=r&&t.y>=0&&t.y<=n}}pickCoordinate(e){const t=this.engine.renderer.domElement.getBoundingClientRect(),r=this.engine.cameraModule2d.screenToWorld(e.clientX-t.left,e.clientY-t.top);return{x:r.x,y:r.y,z:0}}}class Da{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 Ua{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(et.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((r,n)=>{const s=r.name||`布局${n+1}`;this.el.appendChild(this.createTab(s,t.type==="layout"&&t.layoutId===r.id,()=>this.switchToLayout(r.id)))}),this.el.style.display=e.length>0?"flex":"none"}createTab(e,t,r){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",r),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 Mt={version:"3.11.1"}.version;function xr(){const o=globalThis.crypto?.subtle;if(!o)throw new Error("[BimEngine] Web Crypto API is required for secure sdkAuth credentials mode");return o}function Lt(o){return new TextEncoder().encode(o)}function Rt(o){return o.buffer.slice(o.byteOffset,o.byteOffset+o.byteLength)}function ji(o){let e="";return o.forEach(t=>{e+=String.fromCharCode(t)}),btoa(e)}function Va(o){const e=o.getUTCFullYear(),t=String(o.getUTCMonth()+1).padStart(2,"0"),r=String(o.getUTCDate()).padStart(2,"0");return`${e}${t}${r}`}async function Oa(o){const e=await xr().digest("SHA-256",Rt(Lt(o)));return Array.from(new Uint8Array(e)).map(t=>t.toString(16).padStart(2,"0")).join("")}async function Fa(o,e){const t=xr(),r=await t.importKey("raw",Rt(o),{name:"HMAC",hash:"SHA-256"},!1,["sign"]);return t.sign("HMAC",r,Rt(Lt(e)))}function za(o){return Lt([o.appId,o.engineType,o.requestDate,String(o.timestamp),o.nonce].join("|"))}async function Ka(o){const e=xr(),t=new Date,r=t.getTime(),n=Va(t),s=globalThis.crypto.randomUUID(),a=globalThis.crypto.getRandomValues(new Uint8Array(12)),i=await Oa(o.appSecret),l=await Fa(Lt(i),n),c=await e.importKey("raw",l,"AES-GCM",!1,["encrypt"]),p=JSON.stringify({appKey:o.appKey,appSecret:o.appSecret}),b=await e.encrypt({name:"AES-GCM",iv:a,additionalData:Rt(za({appId:o.appId,engineType:o.engineType,requestDate:n,timestamp:r,nonce:s})),tagLength:128},c,Rt(Lt(p)));return{appId:o.appId,engineType:o.engineType,requestDate:n,timestamp:r,nonce:s,iv:ji(a),cipherText:ji(new Uint8Array(b)),sdkVersion:o.sdkVersion,origin:o.origin,product:o.product}}const Cr=new Map;function Yt(o){return o.replace(/\/+$/,"")}function $t(o){if(o)return o;if(typeof window<"u"&&typeof window.location?.origin=="string")return window.location.origin}function Ha(o,e){return JSON.stringify({endpoint:Yt(o.endpoint),token:o.token??"",appId:o.appId??"",appKey:o.appKey??"",appSecret:o.appSecret??"",origin:$t(o.origin)??"",product:o.product??"",engineType:e,sdkVersion:Mt})}async function br(o,e,t){const r=typeof AbortController<"u"?new AbortController:void 0,n=r?setTimeout(()=>r.abort(),t):void 0;try{const s=await fetch(o,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e),signal:r?.signal}),a=await s.json().catch(()=>({}));if(!s.ok){const i=a?.error?.message??a?.message??`SDK authentication failed with status ${s.status}`;throw new Error(i)}return a}finally{n!=null&&clearTimeout(n)}}async function Ga(o,e){const t=await br(`${Yt(o.endpoint)}/oauth/sdk-verify`,{sdkToken:o.token,engineType:e,sdkVersion:Mt,origin:$t(o.origin),product:o.product},o.timeoutMs??8e3);return t.sdkToken=o.token,t}async function Wa(o,e){const t=await Ka({appId:o.appId,appKey:o.appKey,appSecret:o.appSecret,engineType:e,sdkVersion:Mt,origin:$t(o.origin),product:o.product}),r=await br(`${Yt(o.endpoint)}/oauth/sdk-token/secure`,t,o.timeoutMs??8e3),n=await br(`${Yt(o.endpoint)}/oauth/sdk-verify`,{sdkToken:r.sdkToken,engineType:e,sdkVersion:Mt,origin:$t(o.origin),product:o.product},o.timeoutMs??8e3);return n.sdkToken=r.sdkToken,n}async function ja(o,e){const t=o?.sdkAuth;if(!t)return null;if(!t.endpoint)throw new Error("[BimEngine] sdkAuth.endpoint is required");if(!t.token&&!(t.appId&&t.appKey&&t.appSecret))return null;const r=Ha(t,e),n=Cr.get(r);if(n){const a=await n;return o&&(o.__sdkAuthSession=a),a}const s=(t.token?Ga(t,e):Wa(t,e)).then(a=>{if(a.authorized!==!0)throw new Error("[BimEngine] SDK authorization rejected");return o&&(o.__sdkAuthSession=a),a}).catch(a=>{throw Cr.delete(r),a});return Cr.set(r,s),s}function qa(o){return o instanceof Uint8Array||ArrayBuffer.isView(o)&&o.constructor.name==="Uint8Array"&&"BYTES_PER_ELEMENT"in o&&o.BYTES_PER_ELEMENT===1}function qi(o){if(typeof o!="number")throw new TypeError("number expected, got "+typeof o);if(!Number.isSafeInteger(o)||o<0)throw new RangeError("positive integer expected, got "+o)}function tt(o,e,t=""){const r=qa(o),n=o?.length,s=e!==void 0;if(!r||s&&n!==e){const a=t&&`"${t}" `,i=s?` of length ${e}`:"",l=r?`length=${n}`:`type=${typeof o}`,c=a+"expected Uint8Array"+i+", got "+l;throw r?new RangeError(c):new TypeError(c)}return o}function Yi(o,e=!0){if(o.destroyed)throw new Error("Hash instance has been destroyed");if(e&&o.finished)throw new Error("Hash#digest() has already been called")}function Ya(o,e,t=!1){tt(o,void 0,"output");const r=e.outputLen;if(o.length<r)throw new RangeError("digestInto() expects output buffer of length at least "+r);if(t&&!Nt(o))throw new Error("invalid output, must be aligned")}function $a(o){return new Uint8Array(o.buffer,o.byteOffset,o.byteLength)}function wt(o){return new Uint32Array(o.buffer,o.byteOffset,Math.floor(o.byteLength/4))}function Ct(...o){for(let e=0;e<o.length;e++)o[e].fill(0)}function Zt(o){return new DataView(o.buffer,o.byteOffset,o.byteLength)}const Er=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68,$i=o=>o<<24&4278190080|o<<8&16711680|o>>>8&65280|o>>>24&255,Ne=Er?o=>o:o=>$i(o)>>>0,wr=Er?o=>o:o=>{for(let e=0;e<o.length;e++)o[e]=$i(o[e]);return o};function Za(o,e){if(o.length!==e.length)return!1;let t=0;for(let r=0;r<o.length;r++)t|=o[r]^e[r];return t===0}function Xa(o,e,t){const r=e,n=t||(()=>[]),s=(i,l)=>r(l,...n(i)).update(i).digest(),a=r(new Uint8Array(o),...n(new Uint8Array(0)));return s.outputLen=a.outputLen,s.blockLen=a.blockLen,s.create=(i,...l)=>r(i,...l),s}const Qa=(o,e)=>{function t(r,...n){if(tt(r,void 0,"key"),o.nonceLength!==void 0){const p=n[0];tt(p,o.varSizeNonce?void 0:o.nonceLength,"nonce")}const s=o.tagLength;s&&n[1]!==void 0&&tt(n[1],void 0,"AAD");const a=e(r,...n),i=(p,b)=>{if(b!==void 0){if(p!==2)throw new Error("cipher output not supported");tt(b,void 0,"output")}};let l=!1;return{encrypt(p,b){if(l)throw new Error("cannot encrypt() twice with same key + nonce");return l=!0,tt(p),i(a.encrypt.length,b),a.encrypt(p,b)},decrypt(p,b){if(tt(p),s&&p.length<s)throw new Error('"ciphertext" expected length bigger than tagLength='+s);return i(a.decrypt.length,b),a.decrypt(p,b)}}}return Object.assign(t,o),t};function Ja(o,e,t=!0){if(e===void 0)return new Uint8Array(o);if(tt(e,void 0,"output"),e.length!==o)throw new Error('"output" expected Uint8Array of length '+o+", got: "+e.length);if(t&&!Nt(e))throw new Error("invalid output, must be aligned");return e}function eo(o,e,t){qi(o),qi(e);const r=new Uint8Array(16),n=Zt(r);return n.setBigUint64(0,BigInt(e),t),n.setBigUint64(8,BigInt(o),t),r}function Nt(o){return o.byteOffset%4===0}function Pt(o){return Uint8Array.from(tt(o))}const At=16,Zi=new Uint8Array(16),Dt=wt(Zi),to=225,ro=(o,e,t,r)=>{const n=r&1;return{s3:t<<31|r>>>1,s2:e<<31|t>>>1,s1:o<<31|e>>>1,s0:o>>>1^to<<24&-(n&1)}},Xt=o=>(o>>>0&255)<<24|(o>>>8&255)<<16|(o>>>16&255)<<8|o>>>24&255|0,io=o=>o>64*1024?8:o>1024?4:2;class no{blockLen=At;outputLen=At;s0=0;s1=0;s2=0;s3=0;finished=!1;destroyed=!1;t;W;windowSize;constructor(e,t){tt(e,16,"key"),e=Pt(e);const r=Zt(e);let n=r.getUint32(0,!1),s=r.getUint32(4,!1),a=r.getUint32(8,!1),i=r.getUint32(12,!1);const l=[];for(let m=0;m<128;m++)l.push({s0:Xt(n),s1:Xt(s),s2:Xt(a),s3:Xt(i)}),{s0:n,s1:s,s2:a,s3:i}=ro(n,s,a,i);const c=io(t||1024);if(![1,2,4,8].includes(c))throw new Error("ghash: invalid window size, expected 2, 4 or 8");this.W=c;const b=128/c,x=this.windowSize=2**c,h=[];for(let m=0;m<b;m++)for(let d=0;d<x;d++){let y=0,u=0,v=0,E=0;for(let T=0;T<c;T++){if(!(d>>>c-T-1&1))continue;const{s0:w,s1:g,s2:f,s3:k}=l[c*m+T];y^=w,u^=g,v^=f,E^=k}h.push({s0:y,s1:u,s2:v,s3:E})}this.t=h}_updateBlock(e,t,r,n){e^=this.s0,t^=this.s1,r^=this.s2,n^=this.s3;const{W:s,t:a,windowSize:i}=this;let l=0,c=0,p=0,b=0;const x=(1<<s)-1;let h=0;for(const m of[e,t,r,n])for(let d=0;d<4;d++){const y=m>>>8*d&255;for(let u=8/s-1;u>=0;u--){const v=y>>>s*u&x,{s0:E,s1:T,s2:_,s3:w}=a[h*i+v];l^=E,c^=T,p^=_,b^=w,h+=1}}this.s0=l,this.s1=c,this.s2=p,this.s3=b}update(e){Yi(this),tt(e),e=Pt(e);const t=wt(e),r=Math.floor(e.length/At),n=e.length%At;for(let s=0;s<r;s++)this._updateBlock(Ne(t[s*4+0]),Ne(t[s*4+1]),Ne(t[s*4+2]),Ne(t[s*4+3]));return n&&(Zi.set(e.subarray(r*At)),this._updateBlock(Ne(Dt[0]),Ne(Dt[1]),Ne(Dt[2]),Ne(Dt[3])),Ct(Dt)),this}destroy(){this.destroyed=!0;const{t:e}=this;for(const t of e)t.s0=0,t.s1=0,t.s2=0,t.s3=0}digestInto(e){Yi(this),Ya(e,this,!0),this.finished=!0;const{s0:t,s1:r,s2:n,s3:s}=this,a=wt(e);a[0]=t,a[1]=r,a[2]=n,a[3]=s,wr(a)}digest(){const e=new Uint8Array(At);return this.digestInto(e),this.destroy(),e}}const Xi=Xa(16,(o,e)=>new no(o,e),o=>[o.length]),Sr=16,so=4,Qt=new Uint8Array(Sr),ao=283;function oo(o){if(![16,24,32].includes(o.length))throw new Error('"aes key" expected Uint8Array of length 16/24/32, got length='+o.length)}function Tr(o){return o<<1^ao&-(o>>7)}function Qi(o,e){let t=0;for(;e>0;e>>=1)t^=o&-(e&1),o=Tr(o);return t}const lo=(()=>{const o=new Uint8Array(256);for(let t=0,r=1;t<256;t++,r^=Tr(r))o[t]=r;const e=new Uint8Array(256);e[0]=99;for(let t=0;t<255;t++){let r=o[255-t];r|=r<<8,e[o[t]]=(r^r>>4^r>>5^r>>6^r>>7^99)&255}return Ct(o),e})(),co=o=>o<<24|o>>>8,Ar=o=>o<<8|o>>>24;function uo(o,e){if(o.length!==256)throw new Error("Wrong sbox length");const t=new Uint32Array(256).map((c,p)=>e(o[p])),r=t.map(Ar),n=r.map(Ar),s=n.map(Ar),a=new Uint32Array(256*256),i=new Uint32Array(256*256),l=new Uint16Array(256*256);for(let c=0;c<256;c++)for(let p=0;p<256;p++){const b=c*256+p;a[b]=t[c]^r[p],i[b]=n[c]^s[p],l[b]=o[c]<<8|o[p]}return{sbox:o,sbox2:l,T0:t,T1:r,T2:n,T3:s,T01:a,T23:i}}const Ji=uo(lo,o=>Qi(o,3)<<24|o<<16|o<<8|Qi(o,2)),ho=(()=>{const o=new Uint8Array(16);for(let e=0,t=1;e<16;e++,t=Tr(t))o[e]=t;return o})();function fo(o){tt(o);const e=o.length;oo(o);const{sbox2:t}=Ji,r=[];(!Er||!Nt(o))&&r.push(o=Pt(o));const n=wr(wt(o)),s=n.length,a=l=>Ut(t,l,l,l,l),i=new Uint32Array(e+28);i.set(n);for(let l=s;l<i.length;l++){let c=i[l-1];l%s===0?c=a(co(c))^ho[l/s-1]:s>6&&l%s===4&&(c=a(c)),i[l]=i[l-s]^c}return Ct(...r),i}function Jt(o,e,t,r,n,s){return o[t<<8&65280|r>>>8&255]^e[n>>>8&65280|s>>>24&255]}function Ut(o,e,t,r,n){return o[e&255|t&65280]|o[r>>>16&255|n>>>16&65280]<<16}function en(o,e,t,r,n){const{sbox2:s,T01:a,T23:i}=Ji;let l=0;e^=o[l++],t^=o[l++],r^=o[l++],n^=o[l++];const c=o.length/4-2;for(let m=0;m<c;m++){const d=o[l++]^Jt(a,i,e,t,r,n),y=o[l++]^Jt(a,i,t,r,n,e),u=o[l++]^Jt(a,i,r,n,e,t),v=o[l++]^Jt(a,i,n,e,t,r);e=d,t=y,r=u,n=v}const p=o[l++]^Ut(s,e,t,r,n),b=o[l++]^Ut(s,t,r,n,e),x=o[l++]^Ut(s,r,n,e,t),h=o[l++]^Ut(s,n,e,t,r);return{s0:p,s1:b,s2:x,s3:h}}function er(o,e,t,r,n){tt(t,Sr,"nonce"),tt(r),n=Ja(r.length,n);const s=t,a=wt(s),i=Zt(s),l=wt(r),c=wt(n),p=e?0:12,b=r.length;let x=i.getUint32(p,e),{s0:h,s1:m,s2:d,s3:y}=en(o,Ne(a[0]),Ne(a[1]),Ne(a[2]),Ne(a[3]));for(let v=0;v+4<=l.length;v+=4)c[v+0]=l[v+0]^Ne(h),c[v+1]=l[v+1]^Ne(m),c[v+2]=l[v+2]^Ne(d),c[v+3]=l[v+3]^Ne(y),x=x+1>>>0,i.setUint32(p,x,e),{s0:h,s1:m,s2:d,s3:y}=en(o,Ne(a[0]),Ne(a[1]),Ne(a[2]),Ne(a[3]));const u=Sr*Math.floor(l.length/so);if(u<b){const v=new Uint32Array([h,m,d,y]);wr(v);const E=$a(v);for(let T=u,_=0;T<b;T++,_++)n[T]=r[T]^E[_];Ct(v)}return n}function po(o,e,t,r,n){const s=n?n.length:0,a=o.create(t,r.length+s);n&&a.update(n);const i=eo(8*r.length,8*s,e);a.update(r),a.update(i);const l=a.digest();return Ct(i),l}const go=Qa({blockSize:16,nonceLength:12,tagLength:16,varSizeNonce:!0},function(e,t,r){if(t.length<8)throw new Error("aes/gcm: invalid nonce length");const n=16;function s(i,l,c){const p=po(Xi,!1,i,c,r);for(let b=0;b<l.length;b++)p[b]^=l[b];return p}function a(){const i=fo(e),l=Qt.slice(),c=Qt.slice();if(er(i,!1,c,c,l),t.length===12)c.set(t);else{const b=Qt.slice();Zt(b).setBigUint64(8,BigInt(t.length*8),!1);const h=Xi.create(l).update(t).update(b);h.digestInto(c),h.destroy()}const p=er(i,!1,c,Qt);return{xk:i,authKey:l,counter:c,tagMask:p}}return{encrypt(i){const{xk:l,authKey:c,counter:p,tagMask:b}=a(),x=new Uint8Array(i.length+n),h=[l,c,p,b];Nt(i)||h.push(i=Pt(i)),er(l,!1,p,i,x.subarray(0,i.length));const m=s(c,b,x.subarray(0,x.length-n));return h.push(m),x.set(m,i.length),Ct(...h),x},decrypt(i){const{xk:l,authKey:c,counter:p,tagMask:b}=a(),x=[l,c,b,p];Nt(i)||x.push(i=Pt(i));const h=i.subarray(0,-n),m=i.subarray(-n),d=s(c,b,h);if(x.push(d),!Za(d,m))throw Ct(...x),new Error("aes/gcm: invalid ghash tag");const y=er(l,!1,p,h);return Ct(...x),y}}});var _r,tn;function xe(){return tn||(tn=1,_r={options:{usePureJavaScript:!1}}),_r}var Ir={exports:{}},kr,rn;function mo(){if(rn)return kr;rn=1;var o={};kr=o;var e={};o.encode=function(r,n,s){if(typeof n!="string")throw new TypeError('"alphabet" must be a string.');if(s!==void 0&&typeof s!="number")throw new TypeError('"maxline" must be a number.');var a="";if(!(r instanceof Uint8Array))a=t(r,n);else{var i=0,l=n.length,c=n.charAt(0),p=[0];for(i=0;i<r.length;++i){for(var b=0,x=r[i];b<p.length;++b)x+=p[b]<<8,p[b]=x%l,x=x/l|0;for(;x>0;)p.push(x%l),x=x/l|0}for(i=0;r[i]===0&&i<r.length-1;++i)a+=c;for(i=p.length-1;i>=0;--i)a+=n[p[i]]}if(s){var h=new RegExp(".{1,"+s+"}","g");a=a.match(h).join(`\r
222
222
  `)}return a},o.decode=function(r,n){if(typeof r!="string")throw new TypeError('"input" must be a string.');if(typeof n!="string")throw new TypeError('"alphabet" must be a string.');var s=e[n];if(!s){s=e[n]=[];for(var a=0;a<n.length;++a)s[n.charCodeAt(a)]=a}r=r.replace(/\s/g,"");for(var i=n.length,l=n.charAt(0),c=[0],a=0;a<r.length;a++){var p=s[r.charCodeAt(a)];if(p===void 0)return;for(var b=0,x=p;b<c.length;++b)x+=c[b]*i,c[b]=x&255,x>>=8;for(;x>0;)c.push(x&255),x>>=8}for(var h=0;r[h]===l&&h<r.length-1;++h)c.push(0);return typeof Buffer<"u"?Buffer.from(c.reverse()):new Uint8Array(c.reverse())};function t(r,n){var s=0,a=n.length,i=n.charAt(0),l=[0];for(s=0;s<r.length();++s){for(var c=0,p=r.at(s);c<l.length;++c)p+=l[c]<<8,l[c]=p%a,p=p/a|0;for(;p>0;)l.push(p%a),p=p/a|0}var b="";for(s=0;r.at(s)===0&&s<r.length()-1;++s)b+=i;for(s=l.length-1;s>=0;--s)b+=n[l[s]];return b}return kr}var nn;function Ee(){if(nn)return Ir.exports;nn=1;var o=xe(),e=mo(),t=Ir.exports=o.util=o.util||{};(function(){if(typeof process<"u"&&process.nextTick&&!process.browser){t.nextTick=process.nextTick,typeof setImmediate=="function"?t.setImmediate=setImmediate:t.setImmediate=t.nextTick;return}if(typeof setImmediate=="function"){t.setImmediate=function(){return setImmediate.apply(void 0,arguments)},t.nextTick=function(g){return setImmediate(g)};return}if(t.setImmediate=function(g){setTimeout(g,0)},typeof window<"u"&&typeof window.postMessage=="function"){let g=function(f){if(f.source===window&&f.data===u){f.stopPropagation();var k=v.slice();v.length=0,k.forEach(function(L){L()})}};var u="forge.setImmediate",v=[];t.setImmediate=function(f){v.push(f),v.length===1&&window.postMessage(u,"*")},window.addEventListener("message",g,!0)}if(typeof MutationObserver<"u"){var E=Date.now(),T=!0,_=document.createElement("div"),v=[];new MutationObserver(function(){var f=v.slice();v.length=0,f.forEach(function(k){k()})}).observe(_,{attributes:!0});var w=t.setImmediate;t.setImmediate=function(f){Date.now()-E>15?(E=Date.now(),w(f)):(v.push(f),v.length===1&&_.setAttribute("a",T=!T))}}t.nextTick=t.setImmediate})(),t.isNodejs=typeof process<"u"&&process.versions&&process.versions.node,t.globalScope=(function(){return t.isNodejs?kt:typeof self>"u"?window:self})(),t.isArray=Array.isArray||function(u){return Object.prototype.toString.call(u)==="[object Array]"},t.isArrayBuffer=function(u){return typeof ArrayBuffer<"u"&&u instanceof ArrayBuffer},t.isArrayBufferView=function(u){return u&&t.isArrayBuffer(u.buffer)&&u.byteLength!==void 0};function r(u){if(!(u===8||u===16||u===24||u===32))throw new Error("Only 8, 16, 24, or 32 bits supported: "+u)}t.ByteBuffer=n;function n(u){if(this.data="",this.read=0,typeof u=="string")this.data=u;else if(t.isArrayBuffer(u)||t.isArrayBufferView(u))if(typeof Buffer<"u"&&u instanceof Buffer)this.data=u.toString("binary");else{var v=new Uint8Array(u);try{this.data=String.fromCharCode.apply(null,v)}catch{for(var E=0;E<v.length;++E)this.putByte(v[E])}}else(u instanceof n||typeof u=="object"&&typeof u.data=="string"&&typeof u.read=="number")&&(this.data=u.data,this.read=u.read);this._constructedStringLength=0}t.ByteStringBuffer=n;var s=4096;t.ByteStringBuffer.prototype._optimizeConstructedString=function(u){this._constructedStringLength+=u,this._constructedStringLength>s&&(this.data.substr(0,1),this._constructedStringLength=0)},t.ByteStringBuffer.prototype.length=function(){return this.data.length-this.read},t.ByteStringBuffer.prototype.isEmpty=function(){return this.length()<=0},t.ByteStringBuffer.prototype.putByte=function(u){return this.putBytes(String.fromCharCode(u))},t.ByteStringBuffer.prototype.fillWithByte=function(u,v){u=String.fromCharCode(u);for(var E=this.data;v>0;)v&1&&(E+=u),v>>>=1,v>0&&(u+=u);return this.data=E,this._optimizeConstructedString(v),this},t.ByteStringBuffer.prototype.putBytes=function(u){return this.data+=u,this._optimizeConstructedString(u.length),this},t.ByteStringBuffer.prototype.putString=function(u){return this.putBytes(t.encodeUtf8(u))},t.ByteStringBuffer.prototype.putInt16=function(u){return this.putBytes(String.fromCharCode(u>>8&255)+String.fromCharCode(u&255))},t.ByteStringBuffer.prototype.putInt24=function(u){return this.putBytes(String.fromCharCode(u>>16&255)+String.fromCharCode(u>>8&255)+String.fromCharCode(u&255))},t.ByteStringBuffer.prototype.putInt32=function(u){return this.putBytes(String.fromCharCode(u>>24&255)+String.fromCharCode(u>>16&255)+String.fromCharCode(u>>8&255)+String.fromCharCode(u&255))},t.ByteStringBuffer.prototype.putInt16Le=function(u){return this.putBytes(String.fromCharCode(u&255)+String.fromCharCode(u>>8&255))},t.ByteStringBuffer.prototype.putInt24Le=function(u){return this.putBytes(String.fromCharCode(u&255)+String.fromCharCode(u>>8&255)+String.fromCharCode(u>>16&255))},t.ByteStringBuffer.prototype.putInt32Le=function(u){return this.putBytes(String.fromCharCode(u&255)+String.fromCharCode(u>>8&255)+String.fromCharCode(u>>16&255)+String.fromCharCode(u>>24&255))},t.ByteStringBuffer.prototype.putInt=function(u,v){r(v);var E="";do v-=8,E+=String.fromCharCode(u>>v&255);while(v>0);return this.putBytes(E)},t.ByteStringBuffer.prototype.putSignedInt=function(u,v){return u<0&&(u+=2<<v-1),this.putInt(u,v)},t.ByteStringBuffer.prototype.putBuffer=function(u){return this.putBytes(u.getBytes())},t.ByteStringBuffer.prototype.getByte=function(){return this.data.charCodeAt(this.read++)},t.ByteStringBuffer.prototype.getInt16=function(){var u=this.data.charCodeAt(this.read)<<8^this.data.charCodeAt(this.read+1);return this.read+=2,u},t.ByteStringBuffer.prototype.getInt24=function(){var u=this.data.charCodeAt(this.read)<<16^this.data.charCodeAt(this.read+1)<<8^this.data.charCodeAt(this.read+2);return this.read+=3,u},t.ByteStringBuffer.prototype.getInt32=function(){var u=this.data.charCodeAt(this.read)<<24^this.data.charCodeAt(this.read+1)<<16^this.data.charCodeAt(this.read+2)<<8^this.data.charCodeAt(this.read+3);return this.read+=4,u},t.ByteStringBuffer.prototype.getInt16Le=function(){var u=this.data.charCodeAt(this.read)^this.data.charCodeAt(this.read+1)<<8;return this.read+=2,u},t.ByteStringBuffer.prototype.getInt24Le=function(){var u=this.data.charCodeAt(this.read)^this.data.charCodeAt(this.read+1)<<8^this.data.charCodeAt(this.read+2)<<16;return this.read+=3,u},t.ByteStringBuffer.prototype.getInt32Le=function(){var u=this.data.charCodeAt(this.read)^this.data.charCodeAt(this.read+1)<<8^this.data.charCodeAt(this.read+2)<<16^this.data.charCodeAt(this.read+3)<<24;return this.read+=4,u},t.ByteStringBuffer.prototype.getInt=function(u){r(u);var v=0;do v=(v<<8)+this.data.charCodeAt(this.read++),u-=8;while(u>0);return v},t.ByteStringBuffer.prototype.getSignedInt=function(u){var v=this.getInt(u),E=2<<u-2;return v>=E&&(v-=E<<1),v},t.ByteStringBuffer.prototype.getBytes=function(u){var v;return u?(u=Math.min(this.length(),u),v=this.data.slice(this.read,this.read+u),this.read+=u):u===0?v="":(v=this.read===0?this.data:this.data.slice(this.read),this.clear()),v},t.ByteStringBuffer.prototype.bytes=function(u){return typeof u>"u"?this.data.slice(this.read):this.data.slice(this.read,this.read+u)},t.ByteStringBuffer.prototype.at=function(u){return this.data.charCodeAt(this.read+u)},t.ByteStringBuffer.prototype.setAt=function(u,v){return this.data=this.data.substr(0,this.read+u)+String.fromCharCode(v)+this.data.substr(this.read+u+1),this},t.ByteStringBuffer.prototype.last=function(){return this.data.charCodeAt(this.data.length-1)},t.ByteStringBuffer.prototype.copy=function(){var u=t.createBuffer(this.data);return u.read=this.read,u},t.ByteStringBuffer.prototype.compact=function(){return this.read>0&&(this.data=this.data.slice(this.read),this.read=0),this},t.ByteStringBuffer.prototype.clear=function(){return this.data="",this.read=0,this},t.ByteStringBuffer.prototype.truncate=function(u){var v=Math.max(0,this.length()-u);return this.data=this.data.substr(this.read,v),this.read=0,this},t.ByteStringBuffer.prototype.toHex=function(){for(var u="",v=this.read;v<this.data.length;++v){var E=this.data.charCodeAt(v);E<16&&(u+="0"),u+=E.toString(16)}return u},t.ByteStringBuffer.prototype.toString=function(){return t.decodeUtf8(this.bytes())};function a(u,v){v=v||{},this.read=v.readOffset||0,this.growSize=v.growSize||1024;var E=t.isArrayBuffer(u),T=t.isArrayBufferView(u);if(E||T){E?this.data=new DataView(u):this.data=new DataView(u.buffer,u.byteOffset,u.byteLength),this.write="writeOffset"in v?v.writeOffset:this.data.byteLength;return}this.data=new DataView(new ArrayBuffer(0)),this.write=0,u!=null&&this.putBytes(u),"writeOffset"in v&&(this.write=v.writeOffset)}t.DataBuffer=a,t.DataBuffer.prototype.length=function(){return this.write-this.read},t.DataBuffer.prototype.isEmpty=function(){return this.length()<=0},t.DataBuffer.prototype.accommodate=function(u,v){if(this.length()>=u)return this;v=Math.max(v||this.growSize,u);var E=new Uint8Array(this.data.buffer,this.data.byteOffset,this.data.byteLength),T=new Uint8Array(this.length()+v);return T.set(E),this.data=new DataView(T.buffer),this},t.DataBuffer.prototype.putByte=function(u){return this.accommodate(1),this.data.setUint8(this.write++,u),this},t.DataBuffer.prototype.fillWithByte=function(u,v){this.accommodate(v);for(var E=0;E<v;++E)this.data.setUint8(u);return this},t.DataBuffer.prototype.putBytes=function(u,v){if(t.isArrayBufferView(u)){var E=new Uint8Array(u.buffer,u.byteOffset,u.byteLength),T=E.byteLength-E.byteOffset;this.accommodate(T);var _=new Uint8Array(this.data.buffer,this.write);return _.set(E),this.write+=T,this}if(t.isArrayBuffer(u)){var E=new Uint8Array(u);this.accommodate(E.byteLength);var _=new Uint8Array(this.data.buffer);return _.set(E,this.write),this.write+=E.byteLength,this}if(u instanceof t.DataBuffer||typeof u=="object"&&typeof u.read=="number"&&typeof u.write=="number"&&t.isArrayBufferView(u.data)){var E=new Uint8Array(u.data.byteLength,u.read,u.length());this.accommodate(E.byteLength);var _=new Uint8Array(u.data.byteLength,this.write);return _.set(E),this.write+=E.byteLength,this}if(u instanceof t.ByteStringBuffer&&(u=u.data,v="binary"),v=v||"binary",typeof u=="string"){var w;if(v==="hex")return this.accommodate(Math.ceil(u.length/2)),w=new Uint8Array(this.data.buffer,this.write),this.write+=t.binary.hex.decode(u,w,this.write),this;if(v==="base64")return this.accommodate(Math.ceil(u.length/4)*3),w=new Uint8Array(this.data.buffer,this.write),this.write+=t.binary.base64.decode(u,w,this.write),this;if(v==="utf8"&&(u=t.encodeUtf8(u),v="binary"),v==="binary"||v==="raw")return this.accommodate(u.length),w=new Uint8Array(this.data.buffer,this.write),this.write+=t.binary.raw.decode(w),this;if(v==="utf16")return this.accommodate(u.length*2),w=new Uint16Array(this.data.buffer,this.write),this.write+=t.text.utf16.encode(w),this;throw new Error("Invalid encoding: "+v)}throw Error("Invalid parameter: "+u)},t.DataBuffer.prototype.putBuffer=function(u){return this.putBytes(u),u.clear(),this},t.DataBuffer.prototype.putString=function(u){return this.putBytes(u,"utf16")},t.DataBuffer.prototype.putInt16=function(u){return this.accommodate(2),this.data.setInt16(this.write,u),this.write+=2,this},t.DataBuffer.prototype.putInt24=function(u){return this.accommodate(3),this.data.setInt16(this.write,u>>8&65535),this.data.setInt8(this.write,u>>16&255),this.write+=3,this},t.DataBuffer.prototype.putInt32=function(u){return this.accommodate(4),this.data.setInt32(this.write,u),this.write+=4,this},t.DataBuffer.prototype.putInt16Le=function(u){return this.accommodate(2),this.data.setInt16(this.write,u,!0),this.write+=2,this},t.DataBuffer.prototype.putInt24Le=function(u){return this.accommodate(3),this.data.setInt8(this.write,u>>16&255),this.data.setInt16(this.write,u>>8&65535,!0),this.write+=3,this},t.DataBuffer.prototype.putInt32Le=function(u){return this.accommodate(4),this.data.setInt32(this.write,u,!0),this.write+=4,this},t.DataBuffer.prototype.putInt=function(u,v){r(v),this.accommodate(v/8);do v-=8,this.data.setInt8(this.write++,u>>v&255);while(v>0);return this},t.DataBuffer.prototype.putSignedInt=function(u,v){return r(v),this.accommodate(v/8),u<0&&(u+=2<<v-1),this.putInt(u,v)},t.DataBuffer.prototype.getByte=function(){return this.data.getInt8(this.read++)},t.DataBuffer.prototype.getInt16=function(){var u=this.data.getInt16(this.read);return this.read+=2,u},t.DataBuffer.prototype.getInt24=function(){var u=this.data.getInt16(this.read)<<8^this.data.getInt8(this.read+2);return this.read+=3,u},t.DataBuffer.prototype.getInt32=function(){var u=this.data.getInt32(this.read);return this.read+=4,u},t.DataBuffer.prototype.getInt16Le=function(){var u=this.data.getInt16(this.read,!0);return this.read+=2,u},t.DataBuffer.prototype.getInt24Le=function(){var u=this.data.getInt8(this.read)^this.data.getInt16(this.read+1,!0)<<8;return this.read+=3,u},t.DataBuffer.prototype.getInt32Le=function(){var u=this.data.getInt32(this.read,!0);return this.read+=4,u},t.DataBuffer.prototype.getInt=function(u){r(u);var v=0;do v=(v<<8)+this.data.getInt8(this.read++),u-=8;while(u>0);return v},t.DataBuffer.prototype.getSignedInt=function(u){var v=this.getInt(u),E=2<<u-2;return v>=E&&(v-=E<<1),v},t.DataBuffer.prototype.getBytes=function(u){var v;return u?(u=Math.min(this.length(),u),v=this.data.slice(this.read,this.read+u),this.read+=u):u===0?v="":(v=this.read===0?this.data:this.data.slice(this.read),this.clear()),v},t.DataBuffer.prototype.bytes=function(u){return typeof u>"u"?this.data.slice(this.read):this.data.slice(this.read,this.read+u)},t.DataBuffer.prototype.at=function(u){return this.data.getUint8(this.read+u)},t.DataBuffer.prototype.setAt=function(u,v){return this.data.setUint8(u,v),this},t.DataBuffer.prototype.last=function(){return this.data.getUint8(this.write-1)},t.DataBuffer.prototype.copy=function(){return new t.DataBuffer(this)},t.DataBuffer.prototype.compact=function(){if(this.read>0){var u=new Uint8Array(this.data.buffer,this.read),v=new Uint8Array(u.byteLength);v.set(u),this.data=new DataView(v),this.write-=this.read,this.read=0}return this},t.DataBuffer.prototype.clear=function(){return this.data=new DataView(new ArrayBuffer(0)),this.read=this.write=0,this},t.DataBuffer.prototype.truncate=function(u){return this.write=Math.max(0,this.length()-u),this.read=Math.min(this.read,this.write),this},t.DataBuffer.prototype.toHex=function(){for(var u="",v=this.read;v<this.data.byteLength;++v){var E=this.data.getUint8(v);E<16&&(u+="0"),u+=E.toString(16)}return u},t.DataBuffer.prototype.toString=function(u){var v=new Uint8Array(this.data,this.read,this.length());if(u=u||"utf8",u==="binary"||u==="raw")return t.binary.raw.encode(v);if(u==="hex")return t.binary.hex.encode(v);if(u==="base64")return t.binary.base64.encode(v);if(u==="utf8")return t.text.utf8.decode(v);if(u==="utf16")return t.text.utf16.decode(v);throw new Error("Invalid encoding: "+u)},t.createBuffer=function(u,v){return v=v||"raw",u!==void 0&&v==="utf8"&&(u=t.encodeUtf8(u)),new t.ByteBuffer(u)},t.fillString=function(u,v){for(var E="";v>0;)v&1&&(E+=u),v>>>=1,v>0&&(u+=u);return E},t.xorBytes=function(u,v,E){for(var T="",_="",w="",g=0,f=0;E>0;--E,++g)_=u.charCodeAt(g)^v.charCodeAt(g),f>=10&&(T+=w,w="",f=0),w+=String.fromCharCode(_),++f;return T+=w,T},t.hexToBytes=function(u){var v="",E=0;for(u.length&!0&&(E=1,v+=String.fromCharCode(parseInt(u[0],16)));E<u.length;E+=2)v+=String.fromCharCode(parseInt(u.substr(E,2),16));return v},t.bytesToHex=function(u){return t.createBuffer(u).toHex()},t.int32ToBytes=function(u){return String.fromCharCode(u>>24&255)+String.fromCharCode(u>>16&255)+String.fromCharCode(u>>8&255)+String.fromCharCode(u&255)};var i="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",l=[62,-1,-1,-1,63,52,53,54,55,56,57,58,59,60,61,-1,-1,-1,64,-1,-1,-1,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,-1,-1,-1,-1,-1,-1,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51],c="123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";t.encode64=function(u,v){for(var E="",T="",_,w,g,f=0;f<u.length;)_=u.charCodeAt(f++),w=u.charCodeAt(f++),g=u.charCodeAt(f++),E+=i.charAt(_>>2),E+=i.charAt((_&3)<<4|w>>4),isNaN(w)?E+="==":(E+=i.charAt((w&15)<<2|g>>6),E+=isNaN(g)?"=":i.charAt(g&63)),v&&E.length>v&&(T+=E.substr(0,v)+`\r
223
223
  `,E=E.substr(v));return T+=E,T},t.decode64=function(u){u=u.replace(/[^A-Za-z0-9\+\/\=]/g,"");for(var v="",E,T,_,w,g=0;g<u.length;)E=l[u.charCodeAt(g++)-43],T=l[u.charCodeAt(g++)-43],_=l[u.charCodeAt(g++)-43],w=l[u.charCodeAt(g++)-43],v+=String.fromCharCode(E<<2|T>>4),_!==64&&(v+=String.fromCharCode((T&15)<<4|_>>2),w!==64&&(v+=String.fromCharCode((_&3)<<6|w)));return v},t.encodeUtf8=function(u){return unescape(encodeURIComponent(u))},t.decodeUtf8=function(u){return decodeURIComponent(escape(u))},t.binary={raw:{},hex:{},base64:{},base58:{},baseN:{encode:e.encode,decode:e.decode}},t.binary.raw.encode=function(u){return String.fromCharCode.apply(null,u)},t.binary.raw.decode=function(u,v,E){var T=v;T||(T=new Uint8Array(u.length)),E=E||0;for(var _=E,w=0;w<u.length;++w)T[_++]=u.charCodeAt(w);return v?_-E:T},t.binary.hex.encode=t.bytesToHex,t.binary.hex.decode=function(u,v,E){var T=v;T||(T=new Uint8Array(Math.ceil(u.length/2))),E=E||0;var _=0,w=E;for(u.length&1&&(_=1,T[w++]=parseInt(u[0],16));_<u.length;_+=2)T[w++]=parseInt(u.substr(_,2),16);return v?w-E:T},t.binary.base64.encode=function(u,v){for(var E="",T="",_,w,g,f=0;f<u.byteLength;)_=u[f++],w=u[f++],g=u[f++],E+=i.charAt(_>>2),E+=i.charAt((_&3)<<4|w>>4),isNaN(w)?E+="==":(E+=i.charAt((w&15)<<2|g>>6),E+=isNaN(g)?"=":i.charAt(g&63)),v&&E.length>v&&(T+=E.substr(0,v)+`\r
224
224
  `,E=E.substr(v));return T+=E,T},t.binary.base64.decode=function(u,v,E){var T=v;T||(T=new Uint8Array(Math.ceil(u.length/4)*3)),u=u.replace(/[^A-Za-z0-9\+\/\=]/g,""),E=E||0;for(var _,w,g,f,k=0,L=E;k<u.length;)_=l[u.charCodeAt(k++)-43],w=l[u.charCodeAt(k++)-43],g=l[u.charCodeAt(k++)-43],f=l[u.charCodeAt(k++)-43],T[L++]=_<<2|w>>4,g!==64&&(T[L++]=(w&15)<<4|g>>2,f!==64&&(T[L++]=(g&3)<<6|f));return v?L-E:T.subarray(0,L)},t.binary.base58.encode=function(u,v){return t.binary.baseN.encode(u,c,v)},t.binary.base58.decode=function(u,v){return t.binary.baseN.decode(u,c,v)},t.text={utf8:{},utf16:{}},t.text.utf8.encode=function(u,v,E){u=t.encodeUtf8(u);var T=v;T||(T=new Uint8Array(u.length)),E=E||0;for(var _=E,w=0;w<u.length;++w)T[_++]=u.charCodeAt(w);return v?_-E:T},t.text.utf8.decode=function(u){return t.decodeUtf8(String.fromCharCode.apply(null,u))},t.text.utf16.encode=function(u,v,E){var T=v;T||(T=new Uint8Array(u.length*2));var _=new Uint16Array(T.buffer);E=E||0;for(var w=E,g=E,f=0;f<u.length;++f)_[g++]=u.charCodeAt(f),w+=2;return v?w-E:T},t.text.utf16.decode=function(u){return String.fromCharCode.apply(null,new Uint16Array(u.buffer))},t.deflate=function(u,v,E){if(v=t.decode64(u.deflate(t.encode64(v)).rval),E){var T=2,_=v.charCodeAt(1);_&32&&(T=6),v=v.substring(T,v.length-4)}return v},t.inflate=function(u,v,E){var T=u.inflate(t.encode64(v)).rval;return T===null?null:t.decode64(T)};var p=function(u,v,E){if(!u)throw new Error("WebStorage not available.");var T;if(E===null?T=u.removeItem(v):(E=t.encode64(JSON.stringify(E)),T=u.setItem(v,E)),typeof T<"u"&&T.rval!==!0){var _=new Error(T.error.message);throw _.id=T.error.id,_.name=T.error.name,_}},b=function(u,v){if(!u)throw new Error("WebStorage not available.");var E=u.getItem(v);if(u.init)if(E.rval===null){if(E.error){var T=new Error(E.error.message);throw T.id=E.error.id,T.name=E.error.name,T}E=null}else E=E.rval;return E!==null&&(E=JSON.parse(t.decode64(E))),E},x=function(u,v,E,T){var _=b(u,v);_===null&&(_={}),_[E]=T,p(u,v,_)},h=function(u,v,E){var T=b(u,v);return T!==null&&(T=E in T?T[E]:null),T},m=function(u,v,E){var T=b(u,v);if(T!==null&&E in T){delete T[E];var _=!0;for(var w in T){_=!1;break}_&&(T=null),p(u,v,T)}},d=function(u,v){p(u,v,null)},y=function(u,v,E){var T=null;typeof E>"u"&&(E=["web","flash"]);var _,w=!1,g=null;for(var f in E){_=E[f];try{if(_==="flash"||_==="both"){if(v[0]===null)throw new Error("Flash local storage not available.");T=u.apply(this,v),w=_==="flash"}(_==="web"||_==="both")&&(v[0]=localStorage,T=u.apply(this,v),w=!0)}catch(k){g=k}if(w)break}if(!w)throw g;return T};return t.setItem=function(u,v,E,T,_){y(x,arguments,_)},t.getItem=function(u,v,E,T){return y(h,arguments,T)},t.removeItem=function(u,v,E,T){y(m,arguments,T)},t.clearItems=function(u,v,E){y(d,arguments,E)},t.isEmpty=function(u){for(var v in u)if(u.hasOwnProperty(v))return!1;return!0},t.format=function(u){for(var v=/%./g,E,T,_=0,w=[],g=0;E=v.exec(u);){T=u.substring(g,v.lastIndex-2),T.length>0&&w.push(T),g=v.lastIndex;var f=E[0][1];switch(f){case"s":case"o":_<arguments.length?w.push(arguments[_+++1]):w.push("<?>");break;case"%":w.push("%");break;default:w.push("<%"+f+"?>")}}return w.push(u.substring(g)),w.join("")},t.formatNumber=function(u,v,E,T){var _=u,w=isNaN(v=Math.abs(v))?2:v,g=E===void 0?",":E,f=T===void 0?".":T,k=_<0?"-":"",L=parseInt(_=Math.abs(+_||0).toFixed(w),10)+"",H=L.length>3?L.length%3:0;return k+(H?L.substr(0,H)+f:"")+L.substr(H).replace(/(\d{3})(?=\d)/g,"$1"+f)+(w?g+Math.abs(_-L).toFixed(w).slice(2):"")},t.formatSize=function(u){return u>=1073741824?u=t.formatNumber(u/1073741824,2,".","")+" GiB":u>=1048576?u=t.formatNumber(u/1048576,2,".","")+" MiB":u>=1024?u=t.formatNumber(u/1024,0)+" KiB":u=t.formatNumber(u,0)+" bytes",u},t.bytesFromIP=function(u){return u.indexOf(".")!==-1?t.bytesFromIPv4(u):u.indexOf(":")!==-1?t.bytesFromIPv6(u):null},t.bytesFromIPv4=function(u){if(u=u.split("."),u.length!==4)return null;for(var v=t.createBuffer(),E=0;E<u.length;++E){var T=parseInt(u[E],10);if(isNaN(T))return null;v.putByte(T)}return v.getBytes()},t.bytesFromIPv6=function(u){var v=0;u=u.split(":").filter(function(g){return g.length===0&&++v,!0});for(var E=(8-u.length+v)*2,T=t.createBuffer(),_=0;_<8;++_){if(!u[_]||u[_].length===0){T.fillWithByte(0,E),E=0;continue}var w=t.hexToBytes(u[_]);w.length<2&&T.putByte(0),T.putBytes(w)}return T.getBytes()},t.bytesToIP=function(u){return u.length===4?t.bytesToIPv4(u):u.length===16?t.bytesToIPv6(u):null},t.bytesToIPv4=function(u){if(u.length!==4)return null;for(var v=[],E=0;E<u.length;++E)v.push(u.charCodeAt(E));return v.join(".")},t.bytesToIPv6=function(u){if(u.length!==16)return null;for(var v=[],E=[],T=0,_=0;_<u.length;_+=2){for(var w=t.bytesToHex(u[_]+u[_+1]);w[0]==="0"&&w!=="0";)w=w.substr(1);if(w==="0"){var g=E[E.length-1],f=v.length;!g||f!==g.end+1?E.push({start:f,end:f}):(g.end=f,g.end-g.start>E[T].end-E[T].start&&(T=E.length-1))}v.push(w)}if(E.length>0){var k=E[T];k.end-k.start>0&&(v.splice(k.start,k.end-k.start+1,""),k.start===0&&v.unshift(""),k.end===7&&v.push(""))}return v.join(":")},t.estimateCores=function(u,v){if(typeof u=="function"&&(v=u,u={}),u=u||{},"cores"in t&&!u.update)return v(null,t.cores);if(typeof navigator<"u"&&"hardwareConcurrency"in navigator&&navigator.hardwareConcurrency>0)return t.cores=navigator.hardwareConcurrency,v(null,t.cores);if(typeof Worker>"u")return t.cores=1,v(null,t.cores);if(typeof Blob>"u")return t.cores=2,v(null,t.cores);var E=URL.createObjectURL(new Blob(["(",(function(){self.addEventListener("message",function(g){var f=Date.now(),k=f+4;self.postMessage({st:f,et:k})})}).toString(),")()"],{type:"application/javascript"}));T([],5,16);function T(g,f,k){if(f===0){var L=Math.floor(g.reduce(function(H,I){return H+I},0)/g.length);return t.cores=Math.max(1,L),URL.revokeObjectURL(E),v(null,t.cores)}_(k,function(H,I){g.push(w(k,I)),T(g,f-1,k)})}function _(g,f){for(var k=[],L=[],H=0;H<g;++H){var I=new Worker(E);I.addEventListener("message",function(V){if(L.push(V.data),L.length===g){for(var A=0;A<g;++A)k[A].terminate();f(null,L)}}),k.push(I)}for(var H=0;H<g;++H)k[H].postMessage(H)}function w(g,f){for(var k=[],L=0;L<g;++L)for(var H=f[L],I=k[L]=[],V=0;V<g;++V)if(L!==V){var A=f[V];(H.st>A.st&&H.st<A.et||A.st>H.st&&A.st<H.et)&&I.push(V)}return k.reduce(function(G,Y){return Math.max(G,Y.length)},0)}},Ir.exports}var Br,sn;function Mr(){if(sn)return Br;sn=1;var o=xe();Ee(),Br=o.cipher=o.cipher||{},o.cipher.algorithms=o.cipher.algorithms||{},o.cipher.createCipher=function(t,r){var n=t;if(typeof n=="string"&&(n=o.cipher.getAlgorithm(n),n&&(n=n())),!n)throw new Error("Unsupported algorithm: "+t);return new o.cipher.BlockCipher({algorithm:n,key:r,decrypt:!1})},o.cipher.createDecipher=function(t,r){var n=t;if(typeof n=="string"&&(n=o.cipher.getAlgorithm(n),n&&(n=n())),!n)throw new Error("Unsupported algorithm: "+t);return new o.cipher.BlockCipher({algorithm:n,key:r,decrypt:!0})},o.cipher.registerAlgorithm=function(t,r){t=t.toUpperCase(),o.cipher.algorithms[t]=r},o.cipher.getAlgorithm=function(t){return t=t.toUpperCase(),t in o.cipher.algorithms?o.cipher.algorithms[t]:null};var e=o.cipher.BlockCipher=function(t){this.algorithm=t.algorithm,this.mode=this.algorithm.mode,this.blockSize=this.mode.blockSize,this._finish=!1,this._input=null,this.output=null,this._op=t.decrypt?this.mode.decrypt:this.mode.encrypt,this._decrypt=t.decrypt,this.algorithm.initialize(t)};return e.prototype.start=function(t){t=t||{};var r={};for(var n in t)r[n]=t[n];r.decrypt=this._decrypt,this._finish=!1,this._input=o.util.createBuffer(),this.output=t.output||o.util.createBuffer(),this.mode.start(r)},e.prototype.update=function(t){for(t&&this._input.putBuffer(t);!this._op.call(this.mode,this._input,this.output,this._finish)&&!this._finish;);this._input.compact()},e.prototype.finish=function(t){t&&(this.mode.name==="ECB"||this.mode.name==="CBC")&&(this.mode.pad=function(n){return t(this.blockSize,n,!1)},this.mode.unpad=function(n){return t(this.blockSize,n,!0)});var r={};return r.decrypt=this._decrypt,r.overflow=this._input.length()%this.blockSize,!(!this._decrypt&&this.mode.pad&&!this.mode.pad(this._input,r)||(this._finish=!0,this.update(),this._decrypt&&this.mode.unpad&&!this.mode.unpad(this.output,r))||this.mode.afterFinish&&!this.mode.afterFinish(this.output,r))},Br}var Lr={exports:{}},an;function on(){if(an)return Lr.exports;an=1;var o=xe();Ee(),o.cipher=o.cipher||{};var e=Lr.exports=o.cipher.modes=o.cipher.modes||{};e.ecb=function(s){s=s||{},this.name="ECB",this.cipher=s.cipher,this.blockSize=s.blockSize||16,this._ints=this.blockSize/4,this._inBlock=new Array(this._ints),this._outBlock=new Array(this._ints)},e.ecb.prototype.start=function(s){},e.ecb.prototype.encrypt=function(s,a,i){if(s.length()<this.blockSize&&!(i&&s.length()>0))return!0;for(var l=0;l<this._ints;++l)this._inBlock[l]=s.getInt32();this.cipher.encrypt(this._inBlock,this._outBlock);for(var l=0;l<this._ints;++l)a.putInt32(this._outBlock[l])},e.ecb.prototype.decrypt=function(s,a,i){if(s.length()<this.blockSize&&!(i&&s.length()>0))return!0;for(var l=0;l<this._ints;++l)this._inBlock[l]=s.getInt32();this.cipher.decrypt(this._inBlock,this._outBlock);for(var l=0;l<this._ints;++l)a.putInt32(this._outBlock[l])},e.ecb.prototype.pad=function(s,a){var i=s.length()===this.blockSize?this.blockSize:this.blockSize-s.length();return s.fillWithByte(i,i),!0},e.ecb.prototype.unpad=function(s,a){if(a.overflow>0)return!1;var i=s.length(),l=s.at(i-1);return l>this.blockSize<<2?!1:(s.truncate(l),!0)},e.cbc=function(s){s=s||{},this.name="CBC",this.cipher=s.cipher,this.blockSize=s.blockSize||16,this._ints=this.blockSize/4,this._inBlock=new Array(this._ints),this._outBlock=new Array(this._ints)},e.cbc.prototype.start=function(s){if(s.iv===null){if(!this._prev)throw new Error("Invalid IV parameter.");this._iv=this._prev.slice(0)}else if("iv"in s)this._iv=t(s.iv,this.blockSize),this._prev=this._iv.slice(0);else throw new Error("Invalid IV parameter.")},e.cbc.prototype.encrypt=function(s,a,i){if(s.length()<this.blockSize&&!(i&&s.length()>0))return!0;for(var l=0;l<this._ints;++l)this._inBlock[l]=this._prev[l]^s.getInt32();this.cipher.encrypt(this._inBlock,this._outBlock);for(var l=0;l<this._ints;++l)a.putInt32(this._outBlock[l]);this._prev=this._outBlock},e.cbc.prototype.decrypt=function(s,a,i){if(s.length()<this.blockSize&&!(i&&s.length()>0))return!0;for(var l=0;l<this._ints;++l)this._inBlock[l]=s.getInt32();this.cipher.decrypt(this._inBlock,this._outBlock);for(var l=0;l<this._ints;++l)a.putInt32(this._prev[l]^this._outBlock[l]);this._prev=this._inBlock.slice(0)},e.cbc.prototype.pad=function(s,a){var i=s.length()===this.blockSize?this.blockSize:this.blockSize-s.length();return s.fillWithByte(i,i),!0},e.cbc.prototype.unpad=function(s,a){if(a.overflow>0)return!1;var i=s.length(),l=s.at(i-1);return l>this.blockSize<<2?!1:(s.truncate(l),!0)},e.cfb=function(s){s=s||{},this.name="CFB",this.cipher=s.cipher,this.blockSize=s.blockSize||16,this._ints=this.blockSize/4,this._inBlock=null,this._outBlock=new Array(this._ints),this._partialBlock=new Array(this._ints),this._partialOutput=o.util.createBuffer(),this._partialBytes=0},e.cfb.prototype.start=function(s){if(!("iv"in s))throw new Error("Invalid IV parameter.");this._iv=t(s.iv,this.blockSize),this._inBlock=this._iv.slice(0),this._partialBytes=0},e.cfb.prototype.encrypt=function(s,a,i){var l=s.length();if(l===0)return!0;if(this.cipher.encrypt(this._inBlock,this._outBlock),this._partialBytes===0&&l>=this.blockSize){for(var c=0;c<this._ints;++c)this._inBlock[c]=s.getInt32()^this._outBlock[c],a.putInt32(this._inBlock[c]);return}var p=(this.blockSize-l)%this.blockSize;p>0&&(p=this.blockSize-p),this._partialOutput.clear();for(var c=0;c<this._ints;++c)this._partialBlock[c]=s.getInt32()^this._outBlock[c],this._partialOutput.putInt32(this._partialBlock[c]);if(p>0)s.read-=this.blockSize;else for(var c=0;c<this._ints;++c)this._inBlock[c]=this._partialBlock[c];if(this._partialBytes>0&&this._partialOutput.getBytes(this._partialBytes),p>0&&!i)return a.putBytes(this._partialOutput.getBytes(p-this._partialBytes)),this._partialBytes=p,!0;a.putBytes(this._partialOutput.getBytes(l-this._partialBytes)),this._partialBytes=0},e.cfb.prototype.decrypt=function(s,a,i){var l=s.length();if(l===0)return!0;if(this.cipher.encrypt(this._inBlock,this._outBlock),this._partialBytes===0&&l>=this.blockSize){for(var c=0;c<this._ints;++c)this._inBlock[c]=s.getInt32(),a.putInt32(this._inBlock[c]^this._outBlock[c]);return}var p=(this.blockSize-l)%this.blockSize;p>0&&(p=this.blockSize-p),this._partialOutput.clear();for(var c=0;c<this._ints;++c)this._partialBlock[c]=s.getInt32(),this._partialOutput.putInt32(this._partialBlock[c]^this._outBlock[c]);if(p>0)s.read-=this.blockSize;else for(var c=0;c<this._ints;++c)this._inBlock[c]=this._partialBlock[c];if(this._partialBytes>0&&this._partialOutput.getBytes(this._partialBytes),p>0&&!i)return a.putBytes(this._partialOutput.getBytes(p-this._partialBytes)),this._partialBytes=p,!0;a.putBytes(this._partialOutput.getBytes(l-this._partialBytes)),this._partialBytes=0},e.ofb=function(s){s=s||{},this.name="OFB",this.cipher=s.cipher,this.blockSize=s.blockSize||16,this._ints=this.blockSize/4,this._inBlock=null,this._outBlock=new Array(this._ints),this._partialOutput=o.util.createBuffer(),this._partialBytes=0},e.ofb.prototype.start=function(s){if(!("iv"in s))throw new Error("Invalid IV parameter.");this._iv=t(s.iv,this.blockSize),this._inBlock=this._iv.slice(0),this._partialBytes=0},e.ofb.prototype.encrypt=function(s,a,i){var l=s.length();if(s.length()===0)return!0;if(this.cipher.encrypt(this._inBlock,this._outBlock),this._partialBytes===0&&l>=this.blockSize){for(var c=0;c<this._ints;++c)a.putInt32(s.getInt32()^this._outBlock[c]),this._inBlock[c]=this._outBlock[c];return}var p=(this.blockSize-l)%this.blockSize;p>0&&(p=this.blockSize-p),this._partialOutput.clear();for(var c=0;c<this._ints;++c)this._partialOutput.putInt32(s.getInt32()^this._outBlock[c]);if(p>0)s.read-=this.blockSize;else for(var c=0;c<this._ints;++c)this._inBlock[c]=this._outBlock[c];if(this._partialBytes>0&&this._partialOutput.getBytes(this._partialBytes),p>0&&!i)return a.putBytes(this._partialOutput.getBytes(p-this._partialBytes)),this._partialBytes=p,!0;a.putBytes(this._partialOutput.getBytes(l-this._partialBytes)),this._partialBytes=0},e.ofb.prototype.decrypt=e.ofb.prototype.encrypt,e.ctr=function(s){s=s||{},this.name="CTR",this.cipher=s.cipher,this.blockSize=s.blockSize||16,this._ints=this.blockSize/4,this._inBlock=null,this._outBlock=new Array(this._ints),this._partialOutput=o.util.createBuffer(),this._partialBytes=0},e.ctr.prototype.start=function(s){if(!("iv"in s))throw new Error("Invalid IV parameter.");this._iv=t(s.iv,this.blockSize),this._inBlock=this._iv.slice(0),this._partialBytes=0},e.ctr.prototype.encrypt=function(s,a,i){var l=s.length();if(l===0)return!0;if(this.cipher.encrypt(this._inBlock,this._outBlock),this._partialBytes===0&&l>=this.blockSize)for(var c=0;c<this._ints;++c)a.putInt32(s.getInt32()^this._outBlock[c]);else{var p=(this.blockSize-l)%this.blockSize;p>0&&(p=this.blockSize-p),this._partialOutput.clear();for(var c=0;c<this._ints;++c)this._partialOutput.putInt32(s.getInt32()^this._outBlock[c]);if(p>0&&(s.read-=this.blockSize),this._partialBytes>0&&this._partialOutput.getBytes(this._partialBytes),p>0&&!i)return a.putBytes(this._partialOutput.getBytes(p-this._partialBytes)),this._partialBytes=p,!0;a.putBytes(this._partialOutput.getBytes(l-this._partialBytes)),this._partialBytes=0}r(this._inBlock)},e.ctr.prototype.decrypt=e.ctr.prototype.encrypt,e.gcm=function(s){s=s||{},this.name="GCM",this.cipher=s.cipher,this.blockSize=s.blockSize||16,this._ints=this.blockSize/4,this._inBlock=new Array(this._ints),this._outBlock=new Array(this._ints),this._partialOutput=o.util.createBuffer(),this._partialBytes=0,this._R=3774873600},e.gcm.prototype.start=function(s){if(!("iv"in s))throw new Error("Invalid IV parameter.");var a=o.util.createBuffer(s.iv);this._cipherLength=0;var i;if("additionalData"in s?i=o.util.createBuffer(s.additionalData):i=o.util.createBuffer(),"tagLength"in s?this._tagLength=s.tagLength:this._tagLength=128,this._tag=null,s.decrypt&&(this._tag=o.util.createBuffer(s.tag).getBytes(),this._tag.length!==this._tagLength/8))throw new Error("Authentication tag does not match tag length.");this._hashBlock=new Array(this._ints),this.tag=null,this._hashSubkey=new Array(this._ints),this.cipher.encrypt([0,0,0,0],this._hashSubkey),this.componentBits=4,this._m=this.generateHashTable(this._hashSubkey,this.componentBits);var l=a.length();if(l===12)this._j0=[a.getInt32(),a.getInt32(),a.getInt32(),1];else{for(this._j0=[0,0,0,0];a.length()>0;)this._j0=this.ghash(this._hashSubkey,this._j0,[a.getInt32(),a.getInt32(),a.getInt32(),a.getInt32()]);this._j0=this.ghash(this._hashSubkey,this._j0,[0,0].concat(n(l*8)))}this._inBlock=this._j0.slice(0),r(this._inBlock),this._partialBytes=0,i=o.util.createBuffer(i),this._aDataLength=n(i.length()*8);var c=i.length()%this.blockSize;for(c&&i.fillWithByte(0,this.blockSize-c),this._s=[0,0,0,0];i.length()>0;)this._s=this.ghash(this._hashSubkey,this._s,[i.getInt32(),i.getInt32(),i.getInt32(),i.getInt32()])},e.gcm.prototype.encrypt=function(s,a,i){var l=s.length();if(l===0)return!0;if(this.cipher.encrypt(this._inBlock,this._outBlock),this._partialBytes===0&&l>=this.blockSize){for(var c=0;c<this._ints;++c)a.putInt32(this._outBlock[c]^=s.getInt32());this._cipherLength+=this.blockSize}else{var p=(this.blockSize-l)%this.blockSize;p>0&&(p=this.blockSize-p),this._partialOutput.clear();for(var c=0;c<this._ints;++c)this._partialOutput.putInt32(s.getInt32()^this._outBlock[c]);if(p<=0||i){if(i){var b=l%this.blockSize;this._cipherLength+=b,this._partialOutput.truncate(this.blockSize-b)}else this._cipherLength+=this.blockSize;for(var c=0;c<this._ints;++c)this._outBlock[c]=this._partialOutput.getInt32();this._partialOutput.read-=this.blockSize}if(this._partialBytes>0&&this._partialOutput.getBytes(this._partialBytes),p>0&&!i)return s.read-=this.blockSize,a.putBytes(this._partialOutput.getBytes(p-this._partialBytes)),this._partialBytes=p,!0;a.putBytes(this._partialOutput.getBytes(l-this._partialBytes)),this._partialBytes=0}this._s=this.ghash(this._hashSubkey,this._s,this._outBlock),r(this._inBlock)},e.gcm.prototype.decrypt=function(s,a,i){var l=s.length();if(l<this.blockSize&&!(i&&l>0))return!0;this.cipher.encrypt(this._inBlock,this._outBlock),r(this._inBlock),this._hashBlock[0]=s.getInt32(),this._hashBlock[1]=s.getInt32(),this._hashBlock[2]=s.getInt32(),this._hashBlock[3]=s.getInt32(),this._s=this.ghash(this._hashSubkey,this._s,this._hashBlock);for(var c=0;c<this._ints;++c)a.putInt32(this._outBlock[c]^this._hashBlock[c]);l<this.blockSize?this._cipherLength+=l%this.blockSize:this._cipherLength+=this.blockSize},e.gcm.prototype.afterFinish=function(s,a){var i=!0;a.decrypt&&a.overflow&&s.truncate(this.blockSize-a.overflow),this.tag=o.util.createBuffer();var l=this._aDataLength.concat(n(this._cipherLength*8));this._s=this.ghash(this._hashSubkey,this._s,l);var c=[];this.cipher.encrypt(this._j0,c);for(var p=0;p<this._ints;++p)this.tag.putInt32(this._s[p]^c[p]);return this.tag.truncate(this.tag.length()%(this._tagLength/8)),a.decrypt&&this.tag.bytes()!==this._tag&&(i=!1),i},e.gcm.prototype.multiply=function(s,a){for(var i=[0,0,0,0],l=a.slice(0),c=0;c<128;++c){var p=s[c/32|0]&1<<31-c%32;p&&(i[0]^=l[0],i[1]^=l[1],i[2]^=l[2],i[3]^=l[3]),this.pow(l,l)}return i},e.gcm.prototype.pow=function(s,a){for(var i=s[3]&1,l=3;l>0;--l)a[l]=s[l]>>>1|(s[l-1]&1)<<31;a[0]=s[0]>>>1,i&&(a[0]^=this._R)},e.gcm.prototype.tableMultiply=function(s){for(var a=[0,0,0,0],i=0;i<32;++i){var l=i/8|0,c=s[l]>>>(7-i%8)*4&15,p=this._m[i][c];a[0]^=p[0],a[1]^=p[1],a[2]^=p[2],a[3]^=p[3]}return a},e.gcm.prototype.ghash=function(s,a,i){return a[0]^=i[0],a[1]^=i[1],a[2]^=i[2],a[3]^=i[3],this.tableMultiply(a)},e.gcm.prototype.generateHashTable=function(s,a){for(var i=8/a,l=4*i,c=16*i,p=new Array(c),b=0;b<c;++b){var x=[0,0,0,0],h=b/l|0,m=(l-1-b%l)*a;x[h]=1<<a-1<<m,p[b]=this.generateSubHashTable(this.multiply(x,s),a)}return p},e.gcm.prototype.generateSubHashTable=function(s,a){var i=1<<a,l=i>>>1,c=new Array(i);c[l]=s.slice(0);for(var p=l>>>1;p>0;)this.pow(c[2*p],c[p]=[]),p>>=1;for(p=2;p<l;){for(var b=1;b<p;++b){var x=c[p],h=c[b];c[p+b]=[x[0]^h[0],x[1]^h[1],x[2]^h[2],x[3]^h[3]]}p*=2}for(c[0]=[0,0,0,0],p=l+1;p<i;++p){var m=c[p^l];c[p]=[s[0]^m[0],s[1]^m[1],s[2]^m[2],s[3]^m[3]]}return c};function t(s,a){if(typeof s=="string"&&(s=o.util.createBuffer(s)),o.util.isArray(s)&&s.length>4){var i=s;s=o.util.createBuffer();for(var l=0;l<i.length;++l)s.putByte(i[l])}if(s.length()<a)throw new Error("Invalid IV length; got "+s.length()+" bytes and expected "+a+" bytes.");if(!o.util.isArray(s)){for(var c=[],p=a/4,l=0;l<p;++l)c.push(s.getInt32());s=c}return s}function r(s){s[s.length-1]=s[s.length-1]+1&4294967295}function n(s){return[s/4294967296|0,s&4294967295]}return Lr.exports}var Rr,ln;function St(){if(ln)return Rr;ln=1;var o=xe();Mr(),on(),Ee(),Rr=o.aes=o.aes||{},o.aes.startEncrypting=function(h,m,d,y){var u=x({key:h,output:d,decrypt:!1,mode:y});return u.start(m),u},o.aes.createEncryptionCipher=function(h,m){return x({key:h,output:null,decrypt:!1,mode:m})},o.aes.startDecrypting=function(h,m,d,y){var u=x({key:h,output:d,decrypt:!0,mode:y});return u.start(m),u},o.aes.createDecryptionCipher=function(h,m){return x({key:h,output:null,decrypt:!0,mode:m})},o.aes.Algorithm=function(h,m){t||c();var d=this;d.name=h,d.mode=new m({blockSize:16,cipher:{encrypt:function(y,u){return b(d._w,y,u,!1)},decrypt:function(y,u){return b(d._w,y,u,!0)}}}),d._init=!1},o.aes.Algorithm.prototype.initialize=function(h){if(!this._init){var m=h.key,d;if(typeof m=="string"&&(m.length===16||m.length===24||m.length===32))m=o.util.createBuffer(m);else if(o.util.isArray(m)&&(m.length===16||m.length===24||m.length===32)){d=m,m=o.util.createBuffer();for(var y=0;y<d.length;++y)m.putByte(d[y])}if(!o.util.isArray(m)){d=m,m=[];var u=d.length();if(u===16||u===24||u===32){u=u>>>2;for(var y=0;y<u;++y)m.push(d.getInt32())}}if(!o.util.isArray(m)||!(m.length===4||m.length===6||m.length===8))throw new Error("Invalid key parameter.");var v=this.mode.name,E=["CFB","OFB","CTR","GCM"].indexOf(v)!==-1;this._w=p(m,h.decrypt&&!E),this._init=!0}},o.aes._expandKey=function(h,m){return t||c(),p(h,m)},o.aes._updateBlock=b,e("AES-ECB",o.cipher.modes.ecb),e("AES-CBC",o.cipher.modes.cbc),e("AES-CFB",o.cipher.modes.cfb),e("AES-OFB",o.cipher.modes.ofb),e("AES-CTR",o.cipher.modes.ctr),e("AES-GCM",o.cipher.modes.gcm);function e(h,m){var d=function(){return new o.aes.Algorithm(h,m)};o.cipher.registerAlgorithm(h,d)}var t=!1,r=4,n,s,a,i,l;function c(){t=!0,a=[0,1,2,4,8,16,32,64,128,27,54];for(var h=new Array(256),m=0;m<128;++m)h[m]=m<<1,h[m+128]=m+128<<1^283;n=new Array(256),s=new Array(256),i=new Array(4),l=new Array(4);for(var m=0;m<4;++m)i[m]=new Array(256),l[m]=new Array(256);for(var d=0,y=0,u,v,E,T,_,w,g,m=0;m<256;++m){T=y^y<<1^y<<2^y<<3^y<<4,T=T>>8^T&255^99,n[d]=T,s[T]=d,_=h[T],u=h[d],v=h[u],E=h[v],w=_<<24^T<<16^T<<8^(T^_),g=(u^v^E)<<24^(d^E)<<16^(d^v^E)<<8^(d^u^E);for(var f=0;f<4;++f)i[f][d]=w,l[f][T]=g,w=w<<24|w>>>8,g=g<<24|g>>>8;d===0?d=y=1:(d=u^h[h[h[u^E]]],y^=h[h[y]])}}function p(h,m){for(var d=h.slice(0),y,u=1,v=d.length,E=v+6+1,T=r*E,_=v;_<T;++_)y=d[_-1],_%v===0?(y=n[y>>>16&255]<<24^n[y>>>8&255]<<16^n[y&255]<<8^n[y>>>24]^a[u]<<24,u++):v>6&&_%v===4&&(y=n[y>>>24]<<24^n[y>>>16&255]<<16^n[y>>>8&255]<<8^n[y&255]),d[_]=d[_-v]^y;if(m){var w,g=l[0],f=l[1],k=l[2],L=l[3],H=d.slice(0);T=d.length;for(var _=0,I=T-r;_<T;_+=r,I-=r)if(_===0||_===T-r)H[_]=d[I],H[_+1]=d[I+3],H[_+2]=d[I+2],H[_+3]=d[I+1];else for(var V=0;V<r;++V)w=d[I+V],H[_+(3&-V)]=g[n[w>>>24]]^f[n[w>>>16&255]]^k[n[w>>>8&255]]^L[n[w&255]];d=H}return d}function b(h,m,d,y){var u=h.length/4-1,v,E,T,_,w;y?(v=l[0],E=l[1],T=l[2],_=l[3],w=s):(v=i[0],E=i[1],T=i[2],_=i[3],w=n);var g,f,k,L,H,I,V;g=m[0]^h[0],f=m[y?3:1]^h[1],k=m[2]^h[2],L=m[y?1:3]^h[3];for(var A=3,G=1;G<u;++G)H=v[g>>>24]^E[f>>>16&255]^T[k>>>8&255]^_[L&255]^h[++A],I=v[f>>>24]^E[k>>>16&255]^T[L>>>8&255]^_[g&255]^h[++A],V=v[k>>>24]^E[L>>>16&255]^T[g>>>8&255]^_[f&255]^h[++A],L=v[L>>>24]^E[g>>>16&255]^T[f>>>8&255]^_[k&255]^h[++A],g=H,f=I,k=V;d[0]=w[g>>>24]<<24^w[f>>>16&255]<<16^w[k>>>8&255]<<8^w[L&255]^h[++A],d[y?3:1]=w[f>>>24]<<24^w[k>>>16&255]<<16^w[L>>>8&255]<<8^w[g&255]^h[++A],d[2]=w[k>>>24]<<24^w[L>>>16&255]<<16^w[g>>>8&255]<<8^w[f&255]^h[++A],d[y?1:3]=w[L>>>24]<<24^w[g>>>16&255]<<16^w[f>>>8&255]<<8^w[k&255]^h[++A]}function x(h){h=h||{};var m=(h.mode||"CBC").toUpperCase(),d="AES-"+m,y;h.decrypt?y=o.cipher.createDecipher(d,h.key):y=o.cipher.createCipher(d,h.key);var u=y.start;return y.start=function(v,E){var T=null;E instanceof o.util.ByteBuffer&&(T=E,E={}),E=E||{},E.output=T,E.iv=v,u.call(y,E)},y}return Rr}var Nr={exports:{}},Pr={exports:{}},Dr={exports:{}},cn;function Tt(){if(cn)return Dr.exports;cn=1;var o=xe();o.pki=o.pki||{};var e=Dr.exports=o.pki.oids=o.oids=o.oids||{};function t(n,s){e[n]=s,e[s]=n}function r(n,s){e[n]=s}return t("1.2.840.113549.1.1.1","rsaEncryption"),t("1.2.840.113549.1.1.4","md5WithRSAEncryption"),t("1.2.840.113549.1.1.5","sha1WithRSAEncryption"),t("1.2.840.113549.1.1.7","RSAES-OAEP"),t("1.2.840.113549.1.1.8","mgf1"),t("1.2.840.113549.1.1.9","pSpecified"),t("1.2.840.113549.1.1.10","RSASSA-PSS"),t("1.2.840.113549.1.1.11","sha256WithRSAEncryption"),t("1.2.840.113549.1.1.12","sha384WithRSAEncryption"),t("1.2.840.113549.1.1.13","sha512WithRSAEncryption"),t("1.3.101.112","EdDSA25519"),t("1.2.840.10040.4.3","dsa-with-sha1"),t("1.3.14.3.2.7","desCBC"),t("1.3.14.3.2.26","sha1"),t("1.3.14.3.2.29","sha1WithRSASignature"),t("2.16.840.1.101.3.4.2.1","sha256"),t("2.16.840.1.101.3.4.2.2","sha384"),t("2.16.840.1.101.3.4.2.3","sha512"),t("2.16.840.1.101.3.4.2.4","sha224"),t("2.16.840.1.101.3.4.2.5","sha512-224"),t("2.16.840.1.101.3.4.2.6","sha512-256"),t("1.2.840.113549.2.2","md2"),t("1.2.840.113549.2.5","md5"),t("1.2.840.113549.1.7.1","data"),t("1.2.840.113549.1.7.2","signedData"),t("1.2.840.113549.1.7.3","envelopedData"),t("1.2.840.113549.1.7.4","signedAndEnvelopedData"),t("1.2.840.113549.1.7.5","digestedData"),t("1.2.840.113549.1.7.6","encryptedData"),t("1.2.840.113549.1.9.1","emailAddress"),t("1.2.840.113549.1.9.2","unstructuredName"),t("1.2.840.113549.1.9.3","contentType"),t("1.2.840.113549.1.9.4","messageDigest"),t("1.2.840.113549.1.9.5","signingTime"),t("1.2.840.113549.1.9.6","counterSignature"),t("1.2.840.113549.1.9.7","challengePassword"),t("1.2.840.113549.1.9.8","unstructuredAddress"),t("1.2.840.113549.1.9.14","extensionRequest"),t("1.2.840.113549.1.9.20","friendlyName"),t("1.2.840.113549.1.9.21","localKeyId"),t("1.2.840.113549.1.9.22.1","x509Certificate"),t("1.2.840.113549.1.12.10.1.1","keyBag"),t("1.2.840.113549.1.12.10.1.2","pkcs8ShroudedKeyBag"),t("1.2.840.113549.1.12.10.1.3","certBag"),t("1.2.840.113549.1.12.10.1.4","crlBag"),t("1.2.840.113549.1.12.10.1.5","secretBag"),t("1.2.840.113549.1.12.10.1.6","safeContentsBag"),t("1.2.840.113549.1.5.13","pkcs5PBES2"),t("1.2.840.113549.1.5.12","pkcs5PBKDF2"),t("1.2.840.113549.1.12.1.1","pbeWithSHAAnd128BitRC4"),t("1.2.840.113549.1.12.1.2","pbeWithSHAAnd40BitRC4"),t("1.2.840.113549.1.12.1.3","pbeWithSHAAnd3-KeyTripleDES-CBC"),t("1.2.840.113549.1.12.1.4","pbeWithSHAAnd2-KeyTripleDES-CBC"),t("1.2.840.113549.1.12.1.5","pbeWithSHAAnd128BitRC2-CBC"),t("1.2.840.113549.1.12.1.6","pbewithSHAAnd40BitRC2-CBC"),t("1.2.840.113549.2.7","hmacWithSHA1"),t("1.2.840.113549.2.8","hmacWithSHA224"),t("1.2.840.113549.2.9","hmacWithSHA256"),t("1.2.840.113549.2.10","hmacWithSHA384"),t("1.2.840.113549.2.11","hmacWithSHA512"),t("1.2.840.113549.3.7","des-EDE3-CBC"),t("2.16.840.1.101.3.4.1.2","aes128-CBC"),t("2.16.840.1.101.3.4.1.22","aes192-CBC"),t("2.16.840.1.101.3.4.1.42","aes256-CBC"),t("2.5.4.3","commonName"),t("2.5.4.4","surname"),t("2.5.4.5","serialNumber"),t("2.5.4.6","countryName"),t("2.5.4.7","localityName"),t("2.5.4.8","stateOrProvinceName"),t("2.5.4.9","streetAddress"),t("2.5.4.10","organizationName"),t("2.5.4.11","organizationalUnitName"),t("2.5.4.12","title"),t("2.5.4.13","description"),t("2.5.4.15","businessCategory"),t("2.5.4.17","postalCode"),t("2.5.4.42","givenName"),t("2.5.4.65","pseudonym"),t("1.3.6.1.4.1.311.60.2.1.2","jurisdictionOfIncorporationStateOrProvinceName"),t("1.3.6.1.4.1.311.60.2.1.3","jurisdictionOfIncorporationCountryName"),t("2.16.840.1.113730.1.1","nsCertType"),t("2.16.840.1.113730.1.13","nsComment"),r("2.5.29.1","authorityKeyIdentifier"),r("2.5.29.2","keyAttributes"),r("2.5.29.3","certificatePolicies"),r("2.5.29.4","keyUsageRestriction"),r("2.5.29.5","policyMapping"),r("2.5.29.6","subtreesConstraint"),r("2.5.29.7","subjectAltName"),r("2.5.29.8","issuerAltName"),r("2.5.29.9","subjectDirectoryAttributes"),r("2.5.29.10","basicConstraints"),r("2.5.29.11","nameConstraints"),r("2.5.29.12","policyConstraints"),r("2.5.29.13","basicConstraints"),t("2.5.29.14","subjectKeyIdentifier"),t("2.5.29.15","keyUsage"),r("2.5.29.16","privateKeyUsagePeriod"),t("2.5.29.17","subjectAltName"),t("2.5.29.18","issuerAltName"),t("2.5.29.19","basicConstraints"),r("2.5.29.20","cRLNumber"),r("2.5.29.21","cRLReason"),r("2.5.29.22","expirationDate"),r("2.5.29.23","instructionCode"),r("2.5.29.24","invalidityDate"),r("2.5.29.25","cRLDistributionPoints"),r("2.5.29.26","issuingDistributionPoint"),r("2.5.29.27","deltaCRLIndicator"),r("2.5.29.28","issuingDistributionPoint"),r("2.5.29.29","certificateIssuer"),r("2.5.29.30","nameConstraints"),t("2.5.29.31","cRLDistributionPoints"),t("2.5.29.32","certificatePolicies"),r("2.5.29.33","policyMappings"),r("2.5.29.34","policyConstraints"),t("2.5.29.35","authorityKeyIdentifier"),r("2.5.29.36","policyConstraints"),t("2.5.29.37","extKeyUsage"),r("2.5.29.46","freshestCRL"),r("2.5.29.54","inhibitAnyPolicy"),t("1.3.6.1.4.1.11129.2.4.2","timestampList"),t("1.3.6.1.5.5.7.1.1","authorityInfoAccess"),t("1.3.6.1.5.5.7.3.1","serverAuth"),t("1.3.6.1.5.5.7.3.2","clientAuth"),t("1.3.6.1.5.5.7.3.3","codeSigning"),t("1.3.6.1.5.5.7.3.4","emailProtection"),t("1.3.6.1.5.5.7.3.8","timeStamping"),Dr.exports}var un;function gt(){if(un)return Pr.exports;un=1;var o=xe();Ee(),Tt();var e=Pr.exports=o.asn1=o.asn1||{};e.Class={UNIVERSAL:0,APPLICATION:64,CONTEXT_SPECIFIC:128,PRIVATE:192},e.Type={NONE:0,BOOLEAN:1,INTEGER:2,BITSTRING:3,OCTETSTRING:4,NULL:5,OID:6,ODESC:7,EXTERNAL:8,REAL:9,ENUMERATED:10,EMBEDDED:11,UTF8:12,ROID:13,SEQUENCE:16,SET:17,PRINTABLESTRING:19,IA5STRING:22,UTCTIME:23,GENERALIZEDTIME:24,BMPSTRING:30},e.maxDepth=256,e.create=function(a,i,l,c,p){if(o.util.isArray(c)){for(var b=[],x=0;x<c.length;++x)c[x]!==void 0&&b.push(c[x]);c=b}var h={tagClass:a,type:i,constructed:l,composed:l||o.util.isArray(c),value:c};return p&&"bitStringContents"in p&&(h.bitStringContents=p.bitStringContents,h.original=e.copy(h)),h},e.copy=function(a,i){var l;if(o.util.isArray(a)){l=[];for(var c=0;c<a.length;++c)l.push(e.copy(a[c],i));return l}return typeof a=="string"?a:(l={tagClass:a.tagClass,type:a.type,constructed:a.constructed,composed:a.composed,value:e.copy(a.value,i)},i&&!i.excludeBitStringContents&&(l.bitStringContents=a.bitStringContents),l)},e.equals=function(a,i,l){if(o.util.isArray(a)){if(!o.util.isArray(i)||a.length!==i.length)return!1;for(var c=0;c<a.length;++c)if(!e.equals(a[c],i[c]))return!1;return!0}if(typeof a!=typeof i)return!1;if(typeof a=="string")return a===i;var p=a.tagClass===i.tagClass&&a.type===i.type&&a.constructed===i.constructed&&a.composed===i.composed&&e.equals(a.value,i.value);return l&&l.includeBitStringContents&&(p=p&&a.bitStringContents===i.bitStringContents),p},e.getBerValueLength=function(a){var i=a.getByte();if(i!==128){var l,c=i&128;return c?l=a.getInt((i&127)<<3):l=i,l}};function t(a,i,l){if(l>i){var c=new Error("Too few bytes to parse DER.");throw c.available=a.length(),c.remaining=i,c.requested=l,c}}var r=function(a,i){var l=a.getByte();if(i--,l!==128){var c,p=l&128;if(!p)c=l;else{var b=l&127;t(a,i,b),c=a.getInt(b<<3)}if(c<0)throw new Error("Negative length: "+c);return c}};e.fromDer=function(a,i){i===void 0&&(i={strict:!0,parseAllBytes:!0,decodeBitStrings:!0}),typeof i=="boolean"&&(i={strict:i,parseAllBytes:!0,decodeBitStrings:!0}),"strict"in i||(i.strict=!0),"parseAllBytes"in i||(i.parseAllBytes=!0),"decodeBitStrings"in i||(i.decodeBitStrings=!0),"maxDepth"in i||(i.maxDepth=e.maxDepth),typeof a=="string"&&(a=o.util.createBuffer(a));var l=a.length(),c=n(a,a.length(),0,i);if(i.parseAllBytes&&a.length()!==0){var p=new Error("Unparsed DER bytes remain after ASN.1 parsing.");throw p.byteCount=l,p.remaining=a.length(),p}return c};function n(a,i,l,c){if(l>=c.maxDepth)throw new Error("ASN.1 parsing error: Max depth exceeded.");var p;t(a,i,2);var b=a.getByte();i--;var x=b&192,h=b&31;p=a.length();var m=r(a,i);if(i-=p-a.length(),m!==void 0&&m>i){if(c.strict){var d=new Error("Too few bytes to read ASN.1 value.");throw d.available=a.length(),d.remaining=i,d.requested=m,d}m=i}var y,u,v=(b&32)===32;if(v)if(y=[],m===void 0)for(;;){if(t(a,i,2),a.bytes(2)==="\0\0"){a.getBytes(2),i-=2;break}p=a.length(),y.push(n(a,i,l+1,c)),i-=p-a.length()}else for(;m>0;)p=a.length(),y.push(n(a,m,l+1,c)),i-=p-a.length(),m-=p-a.length();if(y===void 0&&x===e.Class.UNIVERSAL&&h===e.Type.BITSTRING&&(u=a.bytes(m)),y===void 0&&c.decodeBitStrings&&x===e.Class.UNIVERSAL&&h===e.Type.BITSTRING&&m>1){var E=a.read,T=i,_=0;if(h===e.Type.BITSTRING&&(t(a,i,1),_=a.getByte(),i--),_===0)try{p=a.length();var w={strict:!0,decodeBitStrings:!0},g=n(a,i,l+1,w),f=p-a.length();i-=f,h==e.Type.BITSTRING&&f++;var k=g.tagClass;f===m&&(k===e.Class.UNIVERSAL||k===e.Class.CONTEXT_SPECIFIC)&&(y=[g])}catch{}y===void 0&&(a.read=E,i=T)}if(y===void 0){if(m===void 0){if(c.strict)throw new Error("Non-constructed ASN.1 object of indefinite length.");m=i}if(h===e.Type.BMPSTRING)for(y="";m>0;m-=2)t(a,i,2),y+=String.fromCharCode(a.getInt16()),i-=2;else y=a.getBytes(m),i-=m}var L=u===void 0?null:{bitStringContents:u};return e.create(x,h,v,y,L)}e.toDer=function(a){var i=o.util.createBuffer(),l=a.tagClass|a.type,c=o.util.createBuffer(),p=!1;if("bitStringContents"in a&&(p=!0,a.original&&(p=e.equals(a,a.original))),p)c.putBytes(a.bitStringContents);else if(a.composed){a.constructed?l|=32:c.putByte(0);for(var b=0;b<a.value.length;++b)a.value[b]!==void 0&&c.putBuffer(e.toDer(a.value[b]))}else if(a.type===e.Type.BMPSTRING)for(var b=0;b<a.value.length;++b)c.putInt16(a.value.charCodeAt(b));else a.type===e.Type.INTEGER&&a.value.length>1&&(a.value.charCodeAt(0)===0&&(a.value.charCodeAt(1)&128)===0||a.value.charCodeAt(0)===255&&(a.value.charCodeAt(1)&128)===128)?c.putBytes(a.value.substr(1)):c.putBytes(a.value);if(i.putByte(l),c.length()<=127)i.putByte(c.length()&127);else{var x=c.length(),h="";do h+=String.fromCharCode(x&255),x=x>>>8;while(x>0);i.putByte(h.length|128);for(var b=h.length-1;b>=0;--b)i.putByte(h.charCodeAt(b))}return i.putBuffer(c),i},e.oidToDer=function(a){var i=a.split("."),l=o.util.createBuffer();l.putByte(40*parseInt(i[0],10)+parseInt(i[1],10));for(var c,p,b,x,h=2;h<i.length;++h){if(c=!0,p=[],b=parseInt(i[h],10),b>4294967295)throw new Error("OID value too large; max is 32-bits.");do x=b&127,b=b>>>7,c||(x|=128),p.push(x),c=!1;while(b>0);for(var m=p.length-1;m>=0;--m)l.putByte(p[m])}return l},e.derToOid=function(a){var i;typeof a=="string"&&(a=o.util.createBuffer(a));var l=a.getByte();i=Math.floor(l/40)+"."+l%40;for(var c=0;a.length()>0;){if(c>70368744177663)throw new Error("OID value too large; max is 53-bits.");l=a.getByte(),c=c*128,l&128?c+=l&127:(i+="."+(c+l),c=0)}return i},e.utcTimeToDate=function(a){var i=new Date,l=parseInt(a.substr(0,2),10);l=l>=50?1900+l:2e3+l;var c=parseInt(a.substr(2,2),10)-1,p=parseInt(a.substr(4,2),10),b=parseInt(a.substr(6,2),10),x=parseInt(a.substr(8,2),10),h=0;if(a.length>11){var m=a.charAt(10),d=10;m!=="+"&&m!=="-"&&(h=parseInt(a.substr(10,2),10),d+=2)}if(i.setUTCFullYear(l,c,p),i.setUTCHours(b,x,h,0),d&&(m=a.charAt(d),m==="+"||m==="-")){var y=parseInt(a.substr(d+1,2),10),u=parseInt(a.substr(d+4,2),10),v=y*60+u;v*=6e4,m==="+"?i.setTime(+i-v):i.setTime(+i+v)}return i},e.generalizedTimeToDate=function(a){var i=new Date,l=parseInt(a.substr(0,4),10),c=parseInt(a.substr(4,2),10)-1,p=parseInt(a.substr(6,2),10),b=parseInt(a.substr(8,2),10),x=parseInt(a.substr(10,2),10),h=parseInt(a.substr(12,2),10),m=0,d=0,y=!1;a.charAt(a.length-1)==="Z"&&(y=!0);var u=a.length-5,v=a.charAt(u);if(v==="+"||v==="-"){var E=parseInt(a.substr(u+1,2),10),T=parseInt(a.substr(u+4,2),10);d=E*60+T,d*=6e4,v==="+"&&(d*=-1),y=!0}return a.charAt(14)==="."&&(m=parseFloat(a.substr(14),10)*1e3),y?(i.setUTCFullYear(l,c,p),i.setUTCHours(b,x,h,m),i.setTime(+i+d)):(i.setFullYear(l,c,p),i.setHours(b,x,h,m)),i},e.dateToUtcTime=function(a){if(typeof a=="string")return a;var i="",l=[];l.push((""+a.getUTCFullYear()).substr(2)),l.push(""+(a.getUTCMonth()+1)),l.push(""+a.getUTCDate()),l.push(""+a.getUTCHours()),l.push(""+a.getUTCMinutes()),l.push(""+a.getUTCSeconds());for(var c=0;c<l.length;++c)l[c].length<2&&(i+="0"),i+=l[c];return i+="Z",i},e.dateToGeneralizedTime=function(a){if(typeof a=="string")return a;var i="",l=[];l.push(""+a.getUTCFullYear()),l.push(""+(a.getUTCMonth()+1)),l.push(""+a.getUTCDate()),l.push(""+a.getUTCHours()),l.push(""+a.getUTCMinutes()),l.push(""+a.getUTCSeconds());for(var c=0;c<l.length;++c)l[c].length<2&&(i+="0"),i+=l[c];return i+="Z",i},e.integerToDer=function(a){var i=o.util.createBuffer();if(a>=-128&&a<128)return i.putSignedInt(a,8);if(a>=-32768&&a<32768)return i.putSignedInt(a,16);if(a>=-8388608&&a<8388608)return i.putSignedInt(a,24);if(a>=-2147483648&&a<2147483648)return i.putSignedInt(a,32);var l=new Error("Integer too large; max is 32-bits.");throw l.integer=a,l},e.derToInteger=function(a){typeof a=="string"&&(a=o.util.createBuffer(a));var i=a.length()*8;if(i>32)throw new Error("Integer too large; max is 32-bits.");return a.getSignedInt(i)},e.validate=function(a,i,l,c){var p=!1;if((a.tagClass===i.tagClass||typeof i.tagClass>"u")&&(a.type===i.type||typeof i.type>"u"))if(a.constructed===i.constructed||typeof i.constructed>"u"){if(p=!0,i.value&&o.util.isArray(i.value))for(var b=0,x=0;p&&x<i.value.length;++x){var h=i.value[x];p=!!h.optional;var m=a.value[b];if(!m){h.optional||(p=!1,c&&c.push("["+i.name+'] Missing required element. Expected tag class "'+h.tagClass+'", type "'+h.type+'"'));continue}var d=typeof h.tagClass<"u"&&typeof h.type<"u";if(d&&(m.tagClass!==h.tagClass||m.type!==h.type))if(h.optional){p=!0;continue}else{p=!1,c&&c.push("["+i.name+"] Tag mismatch. Expected ("+h.tagClass+","+h.type+"), got ("+m.tagClass+","+m.type+")");break}var y=e.validate(m,h,l,c);if(y)++b,p=!0;else if(h.optional)p=!0;else{p=!1;break}}if(p&&l&&(i.capture&&(l[i.capture]=a.value),i.captureAsn1&&(l[i.captureAsn1]=a),i.captureBitStringContents&&"bitStringContents"in a&&(l[i.captureBitStringContents]=a.bitStringContents),i.captureBitStringValue&&"bitStringContents"in a))if(a.bitStringContents.length<2)l[i.captureBitStringValue]="";else{var u=a.bitStringContents.charCodeAt(0);if(u!==0)throw new Error("captureBitStringValue only supported for zero unused bits");l[i.captureBitStringValue]=a.bitStringContents.slice(1)}}else c&&c.push("["+i.name+'] Expected constructed "'+i.constructed+'", got "'+a.constructed+'"');else c&&(a.tagClass!==i.tagClass&&c.push("["+i.name+'] Expected tag class "'+i.tagClass+'", got "'+a.tagClass+'"'),a.type!==i.type&&c.push("["+i.name+'] Expected type "'+i.type+'", got "'+a.type+'"'));return p};var s=/[^\\u0000-\\u00ff]/;return e.prettyPrint=function(a,i,l){var c="";i=i||0,l=l||2,i>0&&(c+=`
@@ -2691,7 +2691,7 @@ class Yn {
2691
2691
  });
2692
2692
  }
2693
2693
  }
2694
- const Zn = "3.10.9", Xn = {
2694
+ const Zn = "3.11.1", Xn = {
2695
2695
  version: Zn
2696
2696
  }, Tt = Xn.version;
2697
2697
  function Wr() {