@mlightcad/cad-simple-viewer 1.0.0 → 1.0.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/README.md +296 -2
- package/dist/index.js +1347 -122
- package/dist/index.umd.cjs +2 -2
- package/lib/app/AcApContext.d.ts +45 -3
- package/lib/app/AcApContext.d.ts.map +1 -1
- package/lib/app/AcApContext.js +43 -3
- package/lib/app/AcApContext.js.map +1 -1
- package/lib/app/AcApDocCreator.d.ts +68 -2
- package/lib/app/AcApDocCreator.d.ts.map +1 -1
- package/lib/app/AcApDocCreator.js +67 -2
- package/lib/app/AcApDocCreator.js.map +1 -1
- package/lib/app/AcApDocManager.d.ts +227 -12
- package/lib/app/AcApDocManager.d.ts.map +1 -1
- package/lib/app/AcApDocManager.js +228 -17
- package/lib/app/AcApDocManager.js.map +1 -1
- package/lib/app/AcApDocument.d.ts +77 -3
- package/lib/app/AcApDocument.d.ts.map +1 -1
- package/lib/app/AcApDocument.js +75 -3
- package/lib/app/AcApDocument.js.map +1 -1
- package/lib/app/AcApFontLoader.d.ts +32 -0
- package/lib/app/AcApFontLoader.d.ts.map +1 -1
- package/lib/app/AcApFontLoader.js +30 -0
- package/lib/app/AcApFontLoader.js.map +1 -1
- package/lib/app/AcApSettingManager.d.ts +191 -3
- package/lib/app/AcApSettingManager.d.ts.map +1 -1
- package/lib/app/AcApSettingManager.js +161 -0
- package/lib/app/AcApSettingManager.js.map +1 -1
- package/lib/command/AcApConvertToSvgCmd.d.ts +26 -0
- package/lib/command/AcApConvertToSvgCmd.d.ts.map +1 -1
- package/lib/command/AcApConvertToSvgCmd.js +26 -0
- package/lib/command/AcApConvertToSvgCmd.js.map +1 -1
- package/lib/command/AcApOpenCmd.d.ts +31 -0
- package/lib/command/AcApOpenCmd.d.ts.map +1 -1
- package/lib/command/AcApOpenCmd.js +31 -0
- package/lib/command/AcApOpenCmd.js.map +1 -1
- package/lib/command/AcApPanCmd.d.ts +25 -0
- package/lib/command/AcApPanCmd.d.ts.map +1 -1
- package/lib/command/AcApPanCmd.js +25 -0
- package/lib/command/AcApPanCmd.js.map +1 -1
- package/lib/command/AcApQNewCmd.d.ts +26 -0
- package/lib/command/AcApQNewCmd.d.ts.map +1 -1
- package/lib/command/AcApQNewCmd.js +26 -0
- package/lib/command/AcApQNewCmd.js.map +1 -1
- package/lib/command/AcApSelectCmd.d.ts +26 -0
- package/lib/command/AcApSelectCmd.d.ts.map +1 -1
- package/lib/command/AcApSelectCmd.js +26 -0
- package/lib/command/AcApSelectCmd.js.map +1 -1
- package/lib/command/AcApSvgConvertor.d.ts +48 -0
- package/lib/command/AcApSvgConvertor.d.ts.map +1 -1
- package/lib/command/AcApSvgConvertor.js +48 -0
- package/lib/command/AcApSvgConvertor.js.map +1 -1
- package/lib/command/AcApZoomCmd.d.ts +29 -0
- package/lib/command/AcApZoomCmd.d.ts.map +1 -1
- package/lib/command/AcApZoomCmd.js +29 -0
- package/lib/command/AcApZoomCmd.js.map +1 -1
- package/lib/command/AcApZoomToBoxCmd.d.ts +57 -0
- package/lib/command/AcApZoomToBoxCmd.d.ts.map +1 -1
- package/lib/command/AcApZoomToBoxCmd.js +57 -0
- package/lib/command/AcApZoomToBoxCmd.js.map +1 -1
- package/lib/editor/command/AcEdCommand.d.ts +118 -9
- package/lib/editor/command/AcEdCommand.d.ts.map +1 -1
- package/lib/editor/command/AcEdCommand.js +113 -9
- package/lib/editor/command/AcEdCommand.js.map +1 -1
- package/lib/editor/command/AcEdCommandStack.d.ts +59 -5
- package/lib/editor/command/AcEdCommandStack.d.ts.map +1 -1
- package/lib/editor/command/AcEdCommandStack.js +48 -5
- package/lib/editor/command/AcEdCommandStack.js.map +1 -1
- package/lib/editor/global/eventBus.d.ts +69 -1
- package/lib/editor/global/eventBus.d.ts.map +1 -1
- package/lib/editor/global/eventBus.js +37 -0
- package/lib/editor/global/eventBus.js.map +1 -1
- package/lib/editor/input/AcEdBaseInput.d.ts +65 -1
- package/lib/editor/input/AcEdBaseInput.d.ts.map +1 -1
- package/lib/editor/input/AcEdBaseInput.js +62 -1
- package/lib/editor/input/AcEdBaseInput.js.map +1 -1
- package/lib/editor/input/AcEdBoxSelector.d.ts +81 -0
- package/lib/editor/input/AcEdBoxSelector.d.ts.map +1 -1
- package/lib/editor/input/AcEdBoxSelector.js +80 -0
- package/lib/editor/input/AcEdBoxSelector.js.map +1 -1
- package/lib/editor/input/AcEdCursorManager.d.ts +95 -8
- package/lib/editor/input/AcEdCursorManager.d.ts.map +1 -1
- package/lib/editor/input/AcEdCursorManager.js +95 -11
- package/lib/editor/input/AcEdCursorManager.js.map +1 -1
- package/lib/editor/input/AcEdInputPoint.d.ts +38 -1
- package/lib/editor/input/AcEdInputPoint.d.ts.map +1 -1
- package/lib/editor/input/AcEdInputPoint.js +38 -1
- package/lib/editor/input/AcEdInputPoint.js.map +1 -1
- package/lib/editor/input/AcEdJig.d.ts +166 -0
- package/lib/editor/input/AcEdJig.d.ts.map +1 -1
- package/lib/editor/input/AcEdJig.js +164 -0
- package/lib/editor/input/AcEdJig.js.map +1 -1
- package/lib/editor/input/AcEdJigLoop.d.ts +49 -0
- package/lib/editor/input/AcEdJigLoop.d.ts.map +1 -1
- package/lib/editor/input/AcEdJigLoop.js +48 -0
- package/lib/editor/input/AcEdJigLoop.js.map +1 -1
- package/lib/editor/input/AcEdSelectionSet.d.ts +122 -2
- package/lib/editor/input/AcEdSelectionSet.d.ts.map +1 -1
- package/lib/editor/input/AcEdSelectionSet.js +117 -1
- package/lib/editor/input/AcEdSelectionSet.js.map +1 -1
- package/lib/editor/input/AcEditor.d.ts +90 -6
- package/lib/editor/input/AcEditor.d.ts.map +1 -1
- package/lib/editor/input/AcEditor.js +86 -6
- package/lib/editor/input/AcEditor.js.map +1 -1
- package/lib/editor/view/AcEdBaseView.d.ts +163 -16
- package/lib/editor/view/AcEdBaseView.d.ts.map +1 -1
- package/lib/editor/view/AcEdBaseView.js +94 -5
- package/lib/editor/view/AcEdBaseView.js.map +1 -1
- package/lib/util/AcTrGeometryUtil.d.ts +65 -0
- package/lib/util/AcTrGeometryUtil.d.ts.map +1 -1
- package/lib/util/AcTrGeometryUtil.js +65 -0
- package/lib/util/AcTrGeometryUtil.js.map +1 -1
- package/lib/view/AcTrLayer.d.ts +40 -5
- package/lib/view/AcTrLayer.d.ts.map +1 -1
- package/lib/view/AcTrLayer.js +34 -5
- package/lib/view/AcTrLayer.js.map +1 -1
- package/lib/view/AcTrLayout.d.ts +122 -23
- package/lib/view/AcTrLayout.d.ts.map +1 -1
- package/lib/view/AcTrLayout.js +103 -23
- package/lib/view/AcTrLayout.js.map +1 -1
- package/lib/view/AcTrLayoutView.d.ts +74 -16
- package/lib/view/AcTrLayoutView.d.ts.map +1 -1
- package/lib/view/AcTrLayoutView.js +65 -16
- package/lib/view/AcTrLayoutView.js.map +1 -1
- package/lib/view/AcTrLayoutViewManager.d.ts +58 -12
- package/lib/view/AcTrLayoutViewManager.d.ts.map +1 -1
- package/lib/view/AcTrLayoutViewManager.js +56 -12
- package/lib/view/AcTrLayoutViewManager.js.map +1 -1
- package/lib/view/AcTrScene.d.ts +48 -4
- package/lib/view/AcTrScene.d.ts.map +1 -1
- package/lib/view/AcTrScene.js +44 -4
- package/lib/view/AcTrScene.js.map +1 -1
- package/lib/view/AcTrView2d.d.ts +71 -0
- package/lib/view/AcTrView2d.d.ts.map +1 -1
- package/lib/view/AcTrView2d.js +65 -0
- package/lib/view/AcTrView2d.js.map +1 -1
- package/package.json +8 -4
package/dist/index.umd.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
(function(u,c){typeof exports=="object"&&typeof module<"u"?c(exports,require("@mlightcad/data-model"),require("@mlightcad/svg-renderer"),require("lodash-es"),require("@mlightcad/three-renderer"),require("three"),require("three/examples/jsm/libs/stats.module"),require("@mlightcad/three-viewcube")):typeof define=="function"&&define.amd?define(["exports","@mlightcad/data-model","@mlightcad/svg-renderer","lodash-es","@mlightcad/three-renderer","three","three/examples/jsm/libs/stats.module","@mlightcad/three-viewcube"],c):(u=typeof globalThis<"u"?globalThis:u||self,c(u["cad-simple-viewer"]={},u.dataModel,u.svgRenderer,u.lodashEs,u.threeRenderer,u.THREE,u.Stats,u.threeViewcube))})(this,function(u,c,rt,O,
|
|
1
|
+
(function(u,c){typeof exports=="object"&&typeof module<"u"?c(exports,require("@mlightcad/data-model"),require("@mlightcad/svg-renderer"),require("lodash-es"),require("@mlightcad/three-renderer"),require("three"),require("three/examples/jsm/libs/stats.module"),require("@mlightcad/three-viewcube")):typeof define=="function"&&define.amd?define(["exports","@mlightcad/data-model","@mlightcad/svg-renderer","lodash-es","@mlightcad/three-renderer","three","three/examples/jsm/libs/stats.module","@mlightcad/three-viewcube"],c):(u=typeof globalThis<"u"?globalThis:u||self,c(u["cad-simple-viewer"]={},u.dataModel,u.svgRenderer,u.lodashEs,u.threeRenderer,u.THREE,u.Stats,u.threeViewcube))})(this,function(u,c,rt,O,D,at,ct,V){"use strict";function ht(s){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(s){for(const e in s)if(e!=="default"){const i=Object.getOwnPropertyDescriptor(s,e);Object.defineProperty(t,e,i.get?i:{enumerable:!0,get:()=>s[e]})}}return t.default=s,Object.freeze(t)}const f=ht(at);class z{constructor(t,e){this._view=t,this._doc=e,e.database.events.entityAppended.addEventListener(i=>{this.view.addEntity(i.entity)}),e.database.events.entityModified.addEventListener(i=>{this.view.updateEntity(i.entity)}),e.database.events.layerModified.addEventListener(i=>{this._view.setLayerVisibility(i.layer.name,!i.layer.isOff)}),e.database.events.headerSysVarChanged.addEventListener(i=>{i.name=="pdmode"&&this._view.rerenderPoints(i.database.pdmode)}),t.selectionSet.events.selectionAdded.addEventListener(i=>{t.highlight(i.ids)}),t.selectionSet.events.selectionRemoved.addEventListener(i=>{t.unhighlight(i.ids)})}get view(){return this._view}get doc(){return this._doc}}class g{constructor(){this.events={commandWillStart:new c.AcCmEventManager,commandEnded:new c.AcCmEventManager},this._globalName="",this._localName=""}get globalName(){return this._globalName}set globalName(t){this._globalName=t}get localName(){return this._localName}set localName(t){this._localName=t}tirgger(t){this.events.commandWillStart.dispatch({command:this}),this.execute(t),this.events.commandEnded.dispatch({command:this})}execute(t){}}class ut{constructor(t){this._index=0,this._commands=[],t.forEach(e=>{const i=e.groupName;e.commandsByGlobalName.forEach(n=>{this._commands.push({command:n,commandGroup:i})})})}[Symbol.iterator](){return this}get command(){return this._index<this._commands.length?this._commands[this._index].command:null}get commandGroup(){return this._index<this._commands.length?this._commands[this._index].commandGroup:null}next(){for(;this._index<this._commands.length;){const t=this._commands[this._index];return this._index+=1,{value:t,done:!1}}return{value:null,done:!0}}}const v=class v{constructor(){this._commandsByGroup=[],this._systemCommandGroup={groupName:v.SYSTEMT_COMMAND_GROUP_NAME,commandsByGlobalName:new Map,commandsByLocalName:new Map},this._defaultCommandGroup={groupName:v.DEFAUT_COMMAND_GROUP_NAME,commandsByGlobalName:new Map,commandsByLocalName:new Map},this._commandsByGroup.push(this._systemCommandGroup),this._commandsByGroup.push(this._defaultCommandGroup)}static get instance(){return v._instance||(v._instance=new v),v._instance}addCommand(t,e,i,n){if(!e)throw new Error("[AcEdCommandStack] The global name of the command is required!");i||(i=e);let o=this._defaultCommandGroup;if(t){const r=this._commandsByGroup.find(a=>a.groupName==t);r?o=r:o={groupName:t,commandsByGlobalName:new Map,commandsByLocalName:new Map}}if(o.commandsByGlobalName.has(e))throw new Error(`[AcEdCommandStack] The command with global name '${e}' already exists!`);if(o.commandsByLocalName.has(i))throw new Error(`[AcEdCommandStack] The command with local name '${i}' already exists!`);o.commandsByGlobalName.set(e,n),o.commandsByLocalName.set(i,n),n.globalName=e,n.localName=i}iterator(){return new ut(this._commandsByGroup)}lookupGlobalCmd(t){let e;for(const i of this._commandsByGroup)if(e=i.commandsByGlobalName.get(t),e)break;return e}lookupLocalCmd(t){let e;for(const i of this._commandsByGroup)if(e=i.commandsByLocalName.get(t),e)break;return e}removeCmd(t,e){for(const i of this._commandsByGroup)if(i.groupName==t)return i.commandsByGlobalName.delete(e);return!1}removeGroup(t){let e=-1;return this._commandsByGroup.some((i,n)=>(e=n,i.groupName==t)),e>=0?(this._commandsByGroup.splice(e,1),!0):!1}};v.SYSTEMT_COMMAND_GROUP_NAME="ACAD",v.DEFAUT_COMMAND_GROUP_NAME="USER";let _=v;function lt(s){return{all:s=s||new Map,on:function(t,e){var i=s.get(t);i?i.push(e):s.set(t,[e])},off:function(t,e){var i=s.get(t);i&&(e?i.splice(i.indexOf(e)>>>0,1):s.set(t,[]))},emit:function(t,e){var i=s.get(t);i&&i.slice().map(function(n){n(e)}),(i=s.get("*"))&&i.slice().map(function(n){n(t,e)})}}}const y=lt();function dt(s){y.emit("message",{message:s,type:"warning"})}var b=(s=>(s[s.NoSpecialCursor=-1]="NoSpecialCursor",s[s.Crosshair=0]="Crosshair",s[s.RectCursor=1]="RectCursor",s[s.RubberBand=2]="RubberBand",s[s.NotRotated=3]="NotRotated",s[s.TargetBox=4]="TargetBox",s[s.RotatedCrosshair=5]="RotatedCrosshair",s[s.CrosshairNoRotate=6]="CrosshairNoRotate",s[s.Invisible=7]="Invisible",s[s.EntitySelect=8]="EntitySelect",s[s.Parallelogram=9]="Parallelogram",s[s.EntitySelectNoPersp=10]="EntitySelectNoPersp",s[s.PkfirstOrGrips=11]="PkfirstOrGrips",s[s.CrosshairDashed=12]="CrosshairDashed",s[s.Grab=13]="Grab",s))(b||{});class Y{constructor(){this._cursorMap=new Map,this._cursorMap.set(0,this.createRectCrossIcon(10,10))}setCursor(t,e){if(t<=-1)e.style.cursor="default";else if(t==13)e.style.cursor="grab";else{const i=this._cursorMap.get(t);i&&(e.style.cursor=i)}}encodeSvgToCursor(t,e,i){return`url('data:image/svg+xml;base64,${btoa(t)}') ${e} ${i}, auto`}createRectCrossIcon(t,e,i="white"){const n=t/2,o=t+2*e,r=`
|
|
2
2
|
<svg xmlns="http://www.w3.org/2000/svg" width="${o}" height="${o}" viewBox="0 0 ${o} ${o}">
|
|
3
3
|
<rect x="${e}" y="${e}" width="${t}" height="${t}" fill="none" stroke="${i}" />
|
|
4
4
|
<line x1="${n+e}" y1="0" x2="${n+e}" y2="${e}" stroke="${i}" />
|
|
@@ -6,4 +6,4 @@
|
|
|
6
6
|
<line x1="${n+e}" y1="${t+e}" x2="${n+e}" y2="${t+2*e}" stroke="${i}" />
|
|
7
7
|
<line x1="0" y1="${n+e}" x2="${e}" y2="${n+e}" stroke="${i}" />
|
|
8
8
|
</svg>
|
|
9
|
-
`;return this.encodeSvg(r,n+e,n+e)}}class P{constructor(t){this.active=!1,this.isResolvedOrRejected=!1,this.onKeyDown=e=>{e.code==="Escape"&&this.reject("Canceled by user!")},this.view=t}get isActive(){return this.active}activate(){this.isActive&&console.warn("Something wrong here!"),this.active=!0,this.view.canvas.addEventListener("keydown",this.onKeyDown)}deactivate(){this.active=!1,this.view.canvas.removeEventListener("keydown",this.onKeyDown)}resolve(t){this.deactivate(),this._resolve&&!this.isResolvedOrRejected&&(this._resolve(t),this.isResolvedOrRejected=!0)}reject(t){this.deactivate(),this._reject&&!this.isResolvedOrRejected&&(this._reject(t),this.isResolvedOrRejected=!0)}async start(){return this.isResolvedOrRejected=!1,new Promise((t,e)=>{this._resolve=t,this._reject=e,this.activate()})}}class mt extends P{constructor(t){super(t),this.events={update:new c.AcCmEventManager},this.onMouseMove=e=>{this.curPos.set(e.clientX,e.clientY),this.events.update.dispatch()},this.curPos=new c.AcGePoint2d}activate(){super.activate(),this.view.canvas.addEventListener("mousemove",this.onMouseMove)}deactivate(){super.deactivate(),this.view.canvas.removeEventListener("mousemove",this.onMouseMove)}}class X{constructor(t){this.onUpdate=()=>{this.update()},this._view=t,this._jigLoop=new mt(t),this._jigLoop.events.update.addEventListener(this.onUpdate)}get view(){return this._view}resolve(t){this._jigLoop.events.update.removeEventListener(this.onUpdate),this._jigLoop.resolve(t)}reject(t){this._jigLoop.events.update.removeEventListener(this.onUpdate),this._jigLoop.reject(t)}async drag(){const t=this._jigLoop.start(),e=this.sampler();await Promise.allSettled([t,e])}async sampler(){}update(){}}const _t=16777215,wt="1px";class ft extends P{constructor(t){super(t),this.mouseDown=!1,this.mouseMove=!1,this.mouseDownPositionX=-1,this.mouseDownPositionY=-1,this.mousedown=e=>{if(e.button===0){this.mouseDown=!0;const i=new c.AcGePoint2d(e.x,e.y);this.mouseDownPositionX=i.x,this.mouseDownPositionY=i.y}},this.mousemove=e=>{if(!this.mouseDown)return;const i=new c.AcGePoint2d(e.x,e.y);if(this.mouseDownPositionX>=0&&this.mouseDownPositionY>=0&&(Math.abs(i.x-this.mouseDownPositionX)>=5||Math.abs(i.y-this.mouseDownPositionY)>=5)){this.mouseMove=!0;const o=new c.AcGePoint2d(Math.min(this.mouseDownPositionX,i.x),Math.min(this.mouseDownPositionY,i.y)),r=new c.AcGePoint2d(Math.max(this.mouseDownPositionX,i.x),Math.max(this.mouseDownPositionY,i.y));this.drawRect(o,r)}},this.mouseup=e=>{if(this.mouseDown&&this.mouseMove){const i=new c.AcGePoint2d(e.x,e.y),n=new c.AcGePoint2d(Math.min(this.mouseDownPositionX,i.x),Math.min(this.mouseDownPositionY,i.y)),o=new c.AcGePoint2d(Math.max(this.mouseDownPositionX,i.x),Math.max(this.mouseDownPositionY,i.y)),r=new c.AcGeBox2d(n,o);this.resolve(this.toWcs(r))}this.mouseDown=!1,this.mouseMove=!1,this.mouseDownPositionX=-1,this.mouseDownPositionY=-1},this.container=t.canvas,this.color=_t}activate(){super.activate(),this.active=!0,this.container.addEventListener("pointerdown",this.mousedown),this.container.addEventListener("pointermove",this.mousemove),this.container.addEventListener("pointerup",this.mouseup)}deactivate(){super.deactivate(),this.container.removeEventListener("pointerdown",this.mousedown),this.container.removeEventListener("pointermove",this.mousemove),this.container.removeEventListener("pointerup",this.mouseup),this.setRectDomVisible(!1)}reject(t){var e;super.reject(t),(e=this.boxDom)==null||e.remove(),this.boxDom=void 0}drawRect(t,e){if(!this.boxDom){const o=new c.AcCmColor;o.color=this.color,this.boxDom=document.createElement("div"),this.boxDom.style.cssText=`position: absolute;border: ${wt} solid ${o.cssColor};`,document.body.appendChild(this.boxDom)}this.setRectDomVisible(!0),t.x<=0&&(t.x=0),t.y<=0&&(t.y=0),e.x>=this.container.clientWidth-2&&(e.x=this.container.clientWidth-2),e.y>=this.container.clientHeight-2&&(e.y=this.container.clientHeight-2),this.boxDom.style.left=`${t.x}px`,this.boxDom.style.top=`${t.y}px`;const i=Math.abs(e.x-t.x),n=Math.abs(e.y-t.y);this.boxDom.style.width=`${i}px`,this.boxDom.style.height=`${n}px`}setRectDomVisible(t){this.boxDom&&(this.boxDom.style.display=t?"inline-block":"none")}toWcs(t){const e=new c.AcGeBox2d,i=new c.AcGePoint2d(t.min.x,t.min.y),n=new c.AcGePoint2d(t.max.x,t.max.y);return e.expandByPoint(this.view.cwcs2Wcs(i)),e.expandByPoint(this.view.cwcs2Wcs(n)),e}}class vt extends P{constructor(t){super(t),this.onClick=e=>{this.resolve(this.view.cwcs2Wcs({x:e.clientX,y:e.clientY}))}}activate(){super.activate(),this.view.canvas.addEventListener("click",this.onClick)}deactivate(){super.deactivate(),this.view.canvas.removeEventListener("click",this.onClick)}}class F{constructor(t){this._view=t,this._cursorManager=new Y}get currentCursor(){return this._currentCursor}restoreCursor(){this._previousCursor!=null&&this.setCursor(this._previousCursor)}setCursor(t){this._cursorManager.setCursor(t,this._view.canvas),this._previousCursor=this._currentCursor,this._currentCursor=t}async getPoint(){return await new vt(this._view).start()}async getSelection(){return await new ft(this._view).start()}}class U{constructor(t=[]){this.events={selectionAdded:new c.AcCmEventManager,selectionRemoved:new c.AcCmEventManager},this._ids=new Set(t)}get ids(){return Array.from(this._ids)}get count(){return this._ids.size}add(t){Array.isArray(t)?(t.forEach(e=>this._ids.add(e)),this.events.selectionAdded.dispatch({ids:t})):(this._ids.add(t),this.events.selectionAdded.dispatch({ids:[t]}))}delete(t){Array.isArray(t)?(t.forEach(e=>this._ids.delete(e)),this.events.selectionRemoved.dispatch({ids:t})):(this._ids.delete(t),this.events.selectionRemoved.dispatch({ids:[t]}))}has(t){return this._ids.has(t)}clear(){if(this._ids.size>0){const t=Array.from(this._ids);this._ids.clear(),this.events.selectionRemoved.dispatch({ids:t})}}}var p=(s=>(s[s.SELECTION=0]="SELECTION",s[s.PAN=1]="PAN",s))(p||{});class k{constructor(t){this.events={mouseMove:new c.AcCmEventManager,viewResize:new c.AcCmEventManager,hover:new c.AcCmEventManager,unhover:new c.AcCmEventManager},this._canvas=t;const e=t.getBoundingClientRect();this._bbox=new c.AcGeBox3d,this._width=e.width,this._height=e.height,this._curPos=new c.AcGePoint2d,this._curScreenPos=new c.AcGePoint2d,this._selectionSet=new U,this._editor=new F(this),this._canvas.addEventListener("mousemove",i=>this.onMouseMove(i)),this._canvas.addEventListener("mousedown",i=>{i.button===1&&this._editor.setCursor(b.Grab)}),this._canvas.addEventListener("mouseup",i=>{i.button===1&&this._editor.restoreCursor()}),window.addEventListener("resize",this.onWindowResize.bind(this)),this._selectionBoxSize=4,this._hoverTimer=null,this._pauseTimer=null,this._hoveredObjectId=null}get editor(){return this._editor}get selectionBoxSize(){return this._selectionBoxSize}set selectionBoxSize(t){this._selectionBoxSize=t}setCursor(t){this._editor.setCursor(t)}setCalculateSizeCallback(t){this._calculateSizeCallback=t}get width(){return this._width}set width(t){this._width=t}get height(){return this._height}set height(t){this._height=t}get bbox(){return this._bbox}get canvas(){return this._canvas}get aspect(){return this._width/this._height}get curPos(){return this._curPos}get curScreenPos(){return this._curScreenPos}get selectionSet(){return this._selectionSet}onWindowResize(){if(this._calculateSizeCallback){const{width:t,height:e}=this._calculateSizeCallback();this._width=t,this._height=e}else this._width=this._canvas.clientWidth,this._height=this._canvas.clientHeight;this.events.viewResize.dispatch({width:this._width,height:this._height})}onMouseMove(t){this._curScreenPos=new c.AcGePoint2d(t.clientX,t.clientY);const e=this.cwcs2Wcs(this._curScreenPos);this._curPos.copy(e),this.events.mouseMove.dispatch({x:e.x,y:e.y}),this.mode==0&&this.startHoverTimer(e.x,e.y)}setHoveredObjectId(t){this._hoveredObjectId&&(this.events.unhover.dispatch({id:this._hoveredObjectId,x:this.curScreenPos.x,y:this.curScreenPos.y}),this.onUnhover(this._hoveredObjectId)),this._hoveredObjectId=t,t&&(this.startPauseTimer(t),this.onHover(t))}hoverAt(t,e){const i=this.pick({x:t,y:e});i.length>0?this.setHoveredObjectId(i[0]):(this.setHoveredObjectId(null),this.clearPauseTimer())}clearHoverTimer(){this._hoverTimer&&clearTimeout(this._hoverTimer)}clearPauseTimer(){this._pauseTimer&&clearTimeout(this._pauseTimer)}startHoverTimer(t,e){this.clearHoverTimer(),this._hoverTimer=setTimeout(()=>{this.hoverAt(t,e)},50)}startPauseTimer(t){this._pauseTimer=setTimeout(()=>{this.events.hover.dispatch({id:t,x:this.curScreenPos.x,y:this.curScreenPos.y})},500)}}class ${constructor(){this._fileName="",this._docTitle="",this._isReadOnly=!0,this._database=new c.AcDbDatabase,this.docTitle="Untitled"}async openUri(t,e){this._uri=t,this._isReadOnly=e&&e.readOnly||!1,this._fileName=this.getFileNameFromUri(t);let i=!0;try{await this._database.openUri(t,e),this.docTitle=this._fileName}catch{i=!1,y.emit("failed-to-open-file",{fileName:t})}return i}async openDocument(t,e,i){var o;let n=!0;this._fileName=t;try{const r=(o=t.split(".").pop())==null?void 0:o.toLocaleLowerCase();await this._database.read(e,i,r=="dwg"?c.AcDbFileType.DWG:c.AcDbFileType.DXF),this.docTitle=this._fileName}catch(r){n=!1,y.emit("failed-to-open-file",{fileName:t}),console.error(r)}return n}get uri(){return this._uri}get database(){return this._database}get docTitle(){return this._docTitle}set docTitle(t){this._docTitle=t,typeof document<"u"&&(document.title=t)}get isReadOnly(){return this._isReadOnly}getFileNameFromUri(t){try{const i=new URL(t).pathname.split("/");return i[i.length-1]||""}catch(e){return console.error("Invalid URI:",e),""}}}class yt{convert(){const t=w.instance.curDocument.database.tables.blockTable.modelSpace.newIterator(),e=new rt.AcSvgRenderer;for(const i of t)i.draw(e);this.createFileAndDownloadIt(e.export())}createFileAndDownloadIt(t){const e=new Blob([t],{type:"image/svg+xml;charset=utf-8"}),i=URL.createObjectURL(e),n=document.createElement("a");n.href=i,n.download="example.svg",document.body.appendChild(n),n.click()}}class W extends g{execute(t){new yt().convert()}}class H extends g{execute(t){y.emit("open-file",{})}}class q extends g{execute(t){w.instance.openUrl("https://cdn.jsdelivr.net/gh/mlight-lee/cad-data/templates/"+"acadiso.dxf")}}class J extends g{execute(t){t.view.mode=p.SELECTION,t.view.setCursor(b.Crosshair)}}class Z extends g{execute(t){t.view.zoomToFit()}}class K extends X{constructor(t){super(t)}async sampler(){await w.instance.editor.getSelection().then(t=>this.view.zoomTo(t,1))}}class Q extends g{async execute(t){await new K(t.view).drag()}}class tt extends g{execute(t){t.view.mode=p.PAN,t.view.setCursor(b.Grab)}}const pt={threeBo2dToGeBox2d:s=>new c.AcGeBox2d(s.min,s.max),goBox2dToThreeBox2d:s=>new f.Box2(s.min,s.max),threeBox3dToGeBox3d:s=>new c.AcGeBox3d(s.min,s.max),goBox3dToThreeBox3d:s=>new f.Box3(s.min,s.max),threeBox3dToGeBox2d:s=>new c.AcGeBox2d(s.min,s.max),goBox2dToThreeBox3d:s=>{const t=new f.Box3;return t.min.set(s.min.x,s.min.y,0),t.max.set(s.max.x,s.max.y,0),t}};class gt extends T.AcTrBaseView{constructor(t,e,i,n){super(t,i,n),this._layoutBtrId=e,this._mode=p.SELECTION,this._axesGizmo=this.createAxesGizmo(),this._viewportViews=new Map}get layoutBtrId(){return this._layoutBtrId}get mode(){return this._mode}set mode(t){t==p.SELECTION?this._cameraControls.mouseButtons={MIDDLE:f.MOUSE.PAN}:t==p.PAN&&(this._cameraControls.mouseButtons={LEFT:f.MOUSE.PAN}),this._cameraControls.update(),this._mode=t}get viewportCount(){return this._viewportViews.size}addViewport(t){this._viewportViews.set(t.viewport.id,t)}removeViewport(t){this._viewportViews.delete(t)}resize(t,e){this._height=e,this._width=t,this.updateCameraFrustum(),this._viewportViews.forEach(i=>{i.update()})}render(t){var i;this._renderer.clear(),this._renderer.render(t.internalScene,this._camera);const e=t.modelSpaceLayout;e&&this.drawViewports(e.internalObject),(i=this._axesGizmo)==null||i.update()}createAxesGizmo(){return new V.AxesGizmo(this._camera.internalCamera,this._renderer.internalRenderer,{hasZAxis:!1,pos:V.ObjectPosition.LEFT_BOTTOM})}drawViewports(t){if(this._viewportViews.size>0){const e=this._renderer.autoClear;this._renderer.autoClear=!1;const i=new f.Vector4;this._renderer.getViewport(i),this._renderer.clearDepth();const n=t.visible;t.visible=!0,this._viewportViews.forEach(o=>{o.render(t)}),t.visible=n,this._renderer.setViewport(i.x,i.y,i.z,i.w),this._renderer.autoClear=e}}}class xt{constructor(){this._activeLayoutBtrId="",this._layoutViews=new Map}get activeLayoutBtrId(){return this._activeLayoutBtrId}set activeLayoutBtrId(t){this._activeLayoutBtrId=t,this._layoutViews.forEach(e=>{e.enabled=e.layoutBtrId==t})}get activeLayoutView(){return this._layoutViews.get(this._activeLayoutBtrId)}has(t){return this._layoutViews.has(t)}getAt(t){return this._layoutViews.get(t)}resize(t,e){this._layoutViews.forEach(i=>{i.resize(t,e)})}add(t){this._layoutViews.set(t.layoutBtrId,t)}render(t){var e;(e=this.activeLayoutView)==null||e.render(t)}}function et(s,t,e=0,i=s.length-1,n=bt){for(;i>e;){if(i-e>600){const h=i-e+1,d=t-e+1,l=Math.log(h),m=.5*Math.exp(2*l/3),x=.5*Math.sqrt(l*m*(h-m)/h)*(d-h/2<0?-1:1),j=Math.max(e,Math.floor(t-d*m/h+x)),Pt=Math.min(i,Math.floor(t+(h-d)*m/h+x));et(s,t,j,Pt,n)}const o=s[t];let r=e,a=i;for(L(s,e,t),n(s[i],o)>0&&L(s,e,i);r<a;){for(L(s,r,a),r++,a--;n(s[r],o)<0;)r++;for(;n(s[a],o)>0;)a--}n(s[e],o)===0?L(s,e,a):(a++,L(s,a,i)),a<=t&&(e=a+1),t<=a&&(i=a-1)}}function L(s,t,e){const i=s[t];s[t]=s[e],s[e]=i}function bt(s,t){return s<t?-1:s>t?1:0}class St{constructor(t=9){this._maxEntries=Math.max(4,t),this._minEntries=Math.max(2,Math.ceil(this._maxEntries*.4)),this.clear()}all(){return this._all(this.data,[])}search(t){let e=this.data;const i=[];if(!M(t,e))return i;const n=this.toBBox,o=[];for(;e;){for(let r=0;r<e.children.length;r++){const a=e.children[r],h=e.leaf?n(a):a;M(t,h)&&(e.leaf?i.push(a):G(t,h)?this._all(a,i):o.push(a))}e=o.pop()}return i}collides(t){let e=this.data;if(!M(t,e))return!1;const i=[];for(;e;){for(let n=0;n<e.children.length;n++){const o=e.children[n],r=e.leaf?this.toBBox(o):o;if(M(t,r)){if(e.leaf||G(t,r))return!0;i.push(o)}}e=i.pop()}return!1}load(t){if(!(t&&t.length))return this;if(t.length<this._minEntries){for(let i=0;i<t.length;i++)this.insert(t[i]);return this}let e=this._build(t.slice(),0,t.length-1,0);if(!this.data.children.length)this.data=e;else if(this.data.height===e.height)this._splitRoot(this.data,e);else{if(this.data.height<e.height){const i=this.data;this.data=e,e=i}this._insert(e,this.data.height-e.height-1,!0)}return this}insert(t){return t&&this._insert(t,this.data.height-1),this}clear(){return this.data=B([]),this}remove(t,e){if(!t)return this;let i=this.data;const n=this.toBBox(t),o=[],r=[];let a,h,d;for(;i||o.length;){if(i||(i=o.pop(),h=o[o.length-1],a=r.pop(),d=!0),i.leaf){const l=Bt(t,i.children,e);if(l!==-1)return i.children.splice(l,1),o.push(i),this._condense(o),this}!d&&!i.leaf&&G(i,n)?(o.push(i),r.push(a),a=0,h=i,i=i.children[0]):h?(a++,i=h.children[a],d=!1):i=null}return this}toBBox(t){return t}compareMinX(t,e){return t.minX-e.minX}compareMinY(t,e){return t.minY-e.minY}toJSON(){return this.data}fromJSON(t){return this.data=t,this}_all(t,e){const i=[];for(;t;)t.leaf?e.push(...t.children):i.push(...t.children),t=i.pop();return e}_build(t,e,i,n){const o=i-e+1;let r=this._maxEntries,a;if(o<=r)return a=B(t.slice(e,i+1)),S(a,this.toBBox),a;n||(n=Math.ceil(Math.log(o)/Math.log(r)),r=Math.ceil(o/Math.pow(r,n-1))),a=B([]),a.leaf=!1,a.height=n;const h=Math.ceil(o/r),d=h*Math.ceil(Math.sqrt(r));it(t,e,i,d,this.compareMinX);for(let l=e;l<=i;l+=d){const m=Math.min(l+d-1,i);it(t,l,m,h,this.compareMinY);for(let x=l;x<=m;x+=h){const j=Math.min(x+h-1,m);a.children.push(this._build(t,x,j,n-1))}}return S(a,this.toBBox),a}_chooseSubtree(t,e,i,n){for(;n.push(e),!(e.leaf||n.length-1===i);){let o=1/0,r=1/0,a;for(let h=0;h<e.children.length;h++){const d=e.children[h],l=N(d),m=Lt(t,d)-l;m<r?(r=m,o=l<o?l:o,a=d):m===r&&l<o&&(o=l,a=d)}e=a||e.children[0]}return e}_insert(t,e,i){const n=i?t:this.toBBox(t),o=[],r=this._chooseSubtree(n,this.data,e,o);for(r.children.push(t),D(r,n);e>=0&&o[e].children.length>this._maxEntries;)this._split(o,e),e--;this._adjustParentBBoxes(n,o,e)}_split(t,e){const i=t[e],n=i.children.length,o=this._minEntries;this._chooseSplitAxis(i,o,n);const r=this._chooseSplitIndex(i,o,n),a=B(i.children.splice(r,i.children.length-r));a.height=i.height,a.leaf=i.leaf,S(i,this.toBBox),S(a,this.toBBox),e?t[e-1].children.push(a):this._splitRoot(i,a)}_splitRoot(t,e){this.data=B([t,e]),this.data.height=t.height+1,this.data.leaf=!1,S(this.data,this.toBBox)}_chooseSplitIndex(t,e,i){let n,o=1/0,r=1/0;for(let a=e;a<=i-e;a++){const h=C(t,0,a,this.toBBox),d=C(t,a,i,this.toBBox),l=Ct(h,d),m=N(h)+N(d);l<o?(o=l,n=a,r=m<r?m:r):l===o&&m<r&&(r=m,n=a)}return n||i-e}_chooseSplitAxis(t,e,i){const n=t.leaf?this.compareMinX:At,o=t.leaf?this.compareMinY:Et,r=this._allDistMargin(t,e,i,n),a=this._allDistMargin(t,e,i,o);r<a&&t.children.sort(n)}_allDistMargin(t,e,i,n){t.children.sort(n);const o=this.toBBox,r=C(t,0,e,o),a=C(t,i-e,i,o);let h=I(r)+I(a);for(let d=e;d<i-e;d++){const l=t.children[d];D(r,t.leaf?o(l):l),h+=I(r)}for(let d=i-e-1;d>=e;d--){const l=t.children[d];D(a,t.leaf?o(l):l),h+=I(a)}return h}_adjustParentBBoxes(t,e,i){for(let n=i;n>=0;n--)D(e[n],t)}_condense(t){for(let e=t.length-1,i;e>=0;e--)t[e].children.length===0?e>0?(i=t[e-1].children,i.splice(i.indexOf(t[e]),1)):this.clear():S(t[e],this.toBBox)}}function Bt(s,t,e){if(!e)return t.indexOf(s);for(let i=0;i<t.length;i++)if(e(s,t[i]))return i;return-1}function S(s,t){C(s,0,s.children.length,t,s)}function C(s,t,e,i,n){n||(n=B(null)),n.minX=1/0,n.minY=1/0,n.maxX=-1/0,n.maxY=-1/0;for(let o=t;o<e;o++){const r=s.children[o];D(n,s.leaf?i(r):r)}return n}function D(s,t){return s.minX=Math.min(s.minX,t.minX),s.minY=Math.min(s.minY,t.minY),s.maxX=Math.max(s.maxX,t.maxX),s.maxY=Math.max(s.maxY,t.maxY),s}function At(s,t){return s.minX-t.minX}function Et(s,t){return s.minY-t.minY}function N(s){return(s.maxX-s.minX)*(s.maxY-s.minY)}function I(s){return s.maxX-s.minX+(s.maxY-s.minY)}function Lt(s,t){return(Math.max(t.maxX,s.maxX)-Math.min(t.minX,s.minX))*(Math.max(t.maxY,s.maxY)-Math.min(t.minY,s.minY))}function Ct(s,t){const e=Math.max(s.minX,t.minX),i=Math.max(s.minY,t.minY),n=Math.min(s.maxX,t.maxX),o=Math.min(s.maxY,t.maxY);return Math.max(0,n-e)*Math.max(0,o-i)}function G(s,t){return s.minX<=t.minX&&s.minY<=t.minY&&t.maxX<=s.maxX&&t.maxY<=s.maxY}function M(s,t){return t.minX<=s.maxX&&t.minY<=s.maxY&&t.maxX>=s.minX&&t.maxY>=s.minY}function B(s){return{children:s,height:1,leaf:!0,minX:1/0,minY:1/0,maxX:-1/0,maxY:-1/0}}function it(s,t,e,i,n){const o=[t,e];for(;o.length;){if(e=o.pop(),t=o.pop(),e-t<=i)continue;const r=t+Math.ceil((e-t)/i/2)*i;et(s,r,t,e,n),o.push(t,r,r,e)}}class Dt{constructor(t){this._group=new T.AcTrBatchedGroup,this._name=t}get name(){return this._name}set name(t){this._name=t}get visible(){return this._group.visible}set visible(t){this._group.visible=t}get internalObject(){return this._group}get stats(){const t=this._group.stats;return{name:this._name,...t}}get entityCount(){return this._group.entityCount}rerenderPoints(t){this._group.rerenderPoints(t)}hasEntity(t){return this._group.hasEntity(t)}addEntity(t){this._group.addEntity(t)}isIntersectWith(t,e){return this._group.isIntersectWith(t,e)}remove(t){throw new Error("Not implemented yet!")}update(t){return this._group.add(t),!0}hover(t){t.forEach(e=>{this._group.hover(e)})}unhover(t){t.forEach(e=>{this._group.unhover(e)})}select(t){t.forEach(e=>{this._group.select(e)})}unselect(t){t.forEach(e=>{this._group.unselect(e)})}}class Tt{constructor(){this._group=new f.Group,this._indexTree=new St,this._box=new f.Box3,this._layers=new Map}get internalObject(){return this._group}get layers(){return this._layers}get box(){return this._box}get visible(){return this._group.visible}set visible(t){this._group.visible=t}get entityCount(){let t=0;return this._layers.forEach(e=>t+=e.entityCount),t}get stats(){const t=[];let e=0,i=0,n=0,o=0,r=0;return this._layers.forEach(a=>{const h=a.stats;t.push(h),n+=h.line.indexed.geometrySize+h.line.nonIndexed.geometrySize,o+=h.mesh.indexed.geometrySize+h.mesh.nonIndexed.geometrySize,r+=h.point.indexed.geometrySize+h.point.nonIndexed.geometrySize,e+=h.summary.totalGeometrySize,i+=h.summary.totalMappingSize}),{layers:t,summary:{entityCount:this.entityCount,totalSize:{line:n,mesh:o,point:r,geometry:e,mapping:i}}}}clear(){return this._layers.forEach(t=>{this._group.remove(t.internalObject)}),this._layers.clear(),this._box.makeEmpty(),this._indexTree.clear(),this}rerenderPoints(t){this._layers.forEach(e=>{e.rerenderPoints(t)})}isIntersectWith(t,e){const i=this.getLayerByObjectId(t);return i&&i.isIntersectWith(t,e)}addEntity(t,e=!0){if(!t.objectId)throw new Error("[AcTrEntity] Object id is required to add one entity!");if(!t.layerName)throw new Error("[AcTrEntity] Layer name is required to add one entity!");const i=this.getLayer(t.layerName,!0);if(i){i.addEntity(t);const n=t.box;e&&this._box.union(n),this._indexTree.insert({minX:n.min.x,minY:n.min.y,maxX:n.max.x,maxY:n.max.y,id:t.objectId})}return this}remove(t){for(const[e,i]of this._layers)if(i.remove(t))return!0;return!1}update(t){for(const[e,i]of this._layers)if(i.update(t))return!0;return!1}hover(t){t.forEach(e=>{const i=this.getLayerByObjectId(e);i&&i.hover([e])})}unhover(t){t.forEach(e=>{const i=this.getLayerByObjectId(e);i&&i.unhover([e])})}select(t){t.forEach(e=>{const i=this.getLayerByObjectId(e);i&&i.select([e])})}unselect(t){t.forEach(e=>{const i=this.getLayerByObjectId(e);i&&i.unselect([e])})}setSnapObject(t){this._snapPointsObject&&this._group.remove(this._snapPointsObject),this._snapPointsObject=t,this._group.add(t)}search(t){return this._indexTree.search({minX:t.min.x,minY:t.min.y,maxX:t.max.x,maxY:t.max.y})}getLayerByObjectId(t){for(const[e,i]of this._layers)if(i.hasEntity(t))return i}getLayer(t,e=!0){let i=this._layers.get(t);return i===void 0&&e&&(i=new Dt(t),this._layers.set(t,i),this._group.add(i.internalObject)),i}}class It{constructor(){this._scene=new f.Scene,this._layouts=new Map,this._activeLayoutBtrId="",this._modelSpaceBtrId=""}get layouts(){return this._layouts}get box(){var t;return(t=this.activeLayout)==null?void 0:t.box}get internalScene(){return this._scene}get modelSpaceBtrId(){return this._modelSpaceBtrId}set modelSpaceBtrId(t){if(this._modelSpaceBtrId=t,!this._layouts.has(t))throw new Error(`[AcTrScene] No layout assiciated with the specified block table record id '${t}'!`)}get activeLayoutBtrId(){return this._activeLayoutBtrId}set activeLayoutBtrId(t){this._activeLayoutBtrId=t,this._layouts.forEach((e,i)=>{e.visible=t==i})}get activeLayout(){if(this._activeLayoutBtrId&&this._layouts.has(this._activeLayoutBtrId))return this._layouts.get(this._activeLayoutBtrId)}get modelSpaceLayout(){if(this._modelSpaceBtrId&&this._layouts.has(this._modelSpaceBtrId))return this._layouts.get(this._modelSpaceBtrId)}get stats(){const t=[];return this._layouts.forEach(e=>t.push(e.stats)),{layouts:t}}addEmptyLayout(t){const e=new Tt;return this._layouts.set(t,e),this._scene.add(e.internalObject),e.visible=t==this._activeLayoutBtrId,e}clear(){return this._layouts.forEach(t=>{this._scene.remove(t.internalObject),t.clear()}),this._layouts.clear(),this._scene.clear(),this}setLayerVisibility(t,e){var n;let i=!1;return(n=this.activeLayout)==null||n.layers.forEach(o=>{o.name===t&&(o.visible=e,i=!0)}),i}hover(t){return this.activeLayout?(this.activeLayout.hover(t),!0):!1}unhover(t){return this.activeLayout?(this.activeLayout.unhover(t),!0):!1}select(t){return this.activeLayout?(this.activeLayout.select(t),!0):!1}unselect(t){return this.activeLayout?(this.activeLayout.unselect(t),!0):!1}search(t){const e=this.activeLayout;return e?e==null?void 0:e.search(t):[]}addEntity(t,e=!0){const i=t.ownerId;if(i){let n=this._layouts.get(i);n||(n=this.addEmptyLayout(i)),n.addEntity(t,e)}else console.warn("[AcTrSecene] The owner id of one entity cannot be empty!");return this}remove(t){for(const[e,i]of this._layouts)if(i.remove(t))return!0;return!1}update(t){for(const[e,i]of this._layouts)if(i.update(t))return!0;return!1}setSnapObject(t){return this._layouts.forEach(e=>{e.setSnapObject(t)}),this}}const R={background:0};class st extends k{constructor(t=R){const e={...R,...t},i=new f.WebGLRenderer({antialias:!0,alpha:!0,canvas:t.canvas});e.canvas==null&&(e.canvas=i.domElement),super(e.canvas),t.calculateSizeCallback&&this.setCalculateSizeCallback(t.calculateSizeCallback),i.setPixelRatio(Math.min(window.devicePixelRatio,2)),i.setSize(this.width,this.height),i.setClearColor(e.background||0),this._renderer=new T.AcTrRenderer(i);const n=E.instance.fontMapping;this._renderer.setFontMapping(n),this._renderer.events.fontNotFound.addEventListener(o=>{y.emit("font-not-found",{fontName:o.fontName,count:o.count??0})}),this._scene=this.createScene(),this._stats=this.createStats(E.instance.isShowStats),E.instance.events.modified.addEventListener(o=>{o.key=="isShowStats"&&this.toggleStatsVisibility(this._stats,o.value)}),this.canvas.addEventListener("click",()=>{this.mode==p.SELECTION&&this.select()}),document.addEventListener("keydown",o=>{o.code==="Escape"&&this.selectionSet.clear()}),c.acdbHostApplicationServices().layoutManager.events.layoutSwitched.addEventListener(o=>{this.activeLayoutBtrId=o.newLayout.blockTableRecordId}),this._missedImages=new Map,this._layoutViewManager=new xt,this.initialize(),this.onWindowResize(),this.animate(),this._isDirty=!0}initialize(){this.setCursor(b.Crosshair)}get mode(){const t=this.activeLayoutView;return t?t.mode:p.SELECTION}set mode(t){this.activeLayoutView.mode=t,this.editor.getPoint()}get renderer(){return this._renderer}get isDirty(){return this._isDirty}set isDirty(t){this._isDirty=t}get missedData(){return{fonts:this._renderer.missedFonts,images:this._missedImages}}get center(){return this.activeLayoutView.center}set center(t){this.activeLayoutView.center=t}get modelSpaceBtrId(){return this._scene.modelSpaceBtrId}set modelSpaceBtrId(t){this._scene.modelSpaceBtrId=t}get activeLayoutBtrId(){return this._scene.activeLayoutBtrId}set activeLayoutBtrId(t){this._layoutViewManager.activeLayoutBtrId=t,this._scene.activeLayoutBtrId=t,this._isDirty=!0}get activeLayoutView(){return this._layoutViewManager.activeLayoutView}get stats(){return this._scene.stats}animate(){var t;requestAnimationFrame(this.animate.bind(this)),this._isDirty&&(this._layoutViewManager.render(this._scene),(t=this._stats)==null||t.update(),this._isDirty=!1)}cwcs2Wcs(t){const e=this.activeLayoutView;return e?e.cwcs2Wcs(t):new c.AcGePoint2d(t)}wcs2Cwcs(t){const e=this.activeLayoutView;return e?e.wcs2Cwcs(t):new c.AcGePoint2d(t)}zoomTo(t,e=1.1){this.activeLayoutView.zoomTo(t,e),this._isDirty=!0}rerenderPoints(t){const e=this._scene.activeLayout;e&&(e.rerenderPoints(t),this._isDirty=!0)}zoomToFit(){if(this._scene.box){const t=pt.threeBox3dToGeBox2d(this._scene.box);this.zoomTo(t),this._isDirty=!0}}pick(t){t==null&&(t=this.curPos);const e=[],i=this._scene.activeLayout;if(i){const n=this.activeLayoutView,o=n.pointToBox(t,this.selectionBoxSize),r=this._scene.search(o),a=Math.max(o.size.width/2,o.size.height/2),h=n.resetRaycaster(t,a);r.forEach(d=>{const l=d.id;i.isIntersectWith(l,h)&&e.push(l)})}return e}search(t){return this._scene.search(t)}select(t){const e=[];this.pick(t).forEach(n=>e.push(n)),e.length>0&&this.selectionSet.add(e)}selectByBox(t){const e=[];this._scene.search(t).forEach(n=>e.push(n.id)),this.selectionSet.add(e)}addEntity(t){const e=this.createLayoutViewIfNeeded(t.ownerId);let i=t.draw(this._renderer);if(i){i.objectId=t.objectId,i.ownerId=t.ownerId,i.layerName=t.layer,i.visible=t.visibility;const n=!(t instanceof c.AcDbRay||t instanceof c.AcDbXline);this._scene.addEntity(i,n),this._isDirty=!0,i.dispose(),i=null}if(t instanceof c.AcDbViewport){if(t.number>1){const n=new T.AcTrViewportView(e,t.toGiViewport(),this._renderer);e.addViewport(n)}}else if(t instanceof c.AcDbRasterImage){const n=t.imageFileName;n&&this._missedImages.set(t.objectId,n)}}removeEntity(t){this._scene.remove(t)}updateEntity(t){const e=t.draw(this._renderer);return e&&(e.objectId=t.objectId,e.ownerId=t.ownerId,e.layerName=t.layer,e.visible=t.visibility,this._scene.update(e),this._isDirty=!0,setTimeout(()=>{this._isDirty=!0},100)),e}clear(){this._scene.clear(),this._isDirty=!0,this._missedImages.clear(),this._renderer.clearMissedFonts()}highlight(t){this._isDirty=this._scene.select(t)}unhighlight(t){this._isDirty=this._scene.unselect(t)}setLayerVisibility(t,e){this._isDirty=this._scene.setLayerVisibility(t,e)}onHover(t){this._isDirty=this._scene.hover([t])}onUnhover(t){this._isDirty=this._scene.unhover([t])}createScene(){const t=new It;return t.layouts.forEach(e=>{e.setSnapObject(this.renderer.createObject())}),t}createStats(t){const e=new ct;document.body.appendChild(e.dom);const i=e.dom;return i.style.position="fixed",i.style.inset="unset",i.style.bottom="30px",i.style.right="0px",this.toggleStatsVisibility(e,t),e}onWindowResize(){super.onWindowResize(),this._renderer.setSize(this.width,this.height),this._layoutViewManager.resize(this.width,this.height),this._isDirty=!0}createLayoutViewIfNeeded(t){let e=this._layoutViewManager.getAt(t);return e==null&&(e=new gt(this._renderer,t,this.width,this.height),e.events.viewChanged.addEventListener(()=>{this._isDirty=!0}),this._layoutViewManager.add(e)),e}toggleStatsVisibility(t,e){e?t.dom.style.display="block":t.dom.style.display="none"}}const nt="simsun";class A{static get instance(){return A._instance||(A._instance=new A),A._instance}createExampleDoc1(t){for(let n=0;n<2;++n)for(let o=0;o<2;++o){const r=new c.AcDbHatch,a=new c.AcGePolyline2d;a.addVertexAt(0,{x:o*100,y:n*100,bulge:1}),a.addVertexAt(1,{x:o*100+100,y:n*100,bulge:1}),a.closed=!0,r.add(a),t.tables.blockTable.modelSpace.appendEntity(r)}}createExampleDoc2(t){const e=t.tables.blockTable.modelSpace;e.appendEntity(this.createArc()),this.createLines().forEach(n=>{t.tables.blockTable.modelSpace.appendEntity(new c.AcDbLine(n.startPoint,n.endPoint))}),e.appendEntity(this.createHatch()),t.tables.textStyleTable.add(this.createTextStyle()),e.appendEntity(this.createMText())}createTextStyle(){const t={bigFont:"",color:16777215,extendedFont:nt,fixedTextHeight:0,font:nt,lastHeight:.2,name:"Standard",obliqueAngle:0,standardFlag:0,textGenerationFlag:0,widthFactor:.667};return new c.AcDbTextStyleTableRecord(t)}createMText(){const t=new c.AcDbMText;return t.attachmentPoint=c.AcGiMTextAttachmentPoint.MiddleLeft,t.color=new c.AcCmColor().setColorName("red"),t.layer="0",t.location=new c.AcGePoint3d(9850,86773,0),t.contents="{\\W0.667;\\T1.1;智慧8081}",t.height=200,t.width=1e3,t.styleName="Standard",t}createHatch(){const t=this.createLines(),e=new c.AcDbHatch,i=new c.AcGeLoop2d;return i.add(new c.AcGeCircArc2d({x:20241.23355899991,y:174118.6312674369},89258.30757455899,c.AcGeMathUtil.degToRad(262.2471115358437),c.AcGeMathUtil.degToRad(264.444541053754),!1)),t.forEach(n=>{i.add(new c.AcGeLine2d(n.startPoint,n.endPoint))}),e.add(i),e}createArc(){return new c.AcDbArc({x:20241.23355899991,y:174118.6312674369,z:0},89258.30757455899,c.AcGeMathUtil.degToRad(262.2471115358437),c.AcGeMathUtil.degToRad(264.444541053754))}createLines(){const t=[];return t.push(new c.AcGeLine3d({x:11600.20888122753,y:85279.57362051727,z:0},{x:11600.20890652924,y:86546.03982284805,z:0})),t.push(new c.AcGeLine3d({x:11600.20890652924,y:86546.03982284805,z:0},{x:10850.20885583921,y:86546.03980174381,z:0})),t.push(new c.AcGeLine3d({x:10850.2088602169,y:86546.03967292747,z:0},{x:9050.208860216895,y:86546.039672927,z:0})),t.push(new c.AcGeLine3d({x:9050.208855839213,y:86546.0397510943,z:0},{x:8200.209067034302,y:86546.039727177,z:0})),t.push(new c.AcGeLine3d({x:8200.209067034302,y:86546.039727177,z:0},{x:8200.209067033837,y:85676.22514764359,z:0})),t}}class Mt{constructor(t){this._cadRenderer=t,this._avaiableFonts=[]}get avaiableFonts(){return this._avaiableFonts}async getAvaiableFonts(){if(this._avaiableFonts.length==0){const t="https://cdn.jsdelivr.net/gh/mlight-lee/cad-data/fonts/",e=t+"fonts.json";try{const i=await fetch(e);this._avaiableFonts=await i.json()}catch{y.emit("failed-to-get-avaiable-fonts",{url:e})}this._avaiableFonts.forEach(i=>{i.url=t+i.file})}return this._avaiableFonts}async load(t){await this.getAvaiableFonts();const e=[];t.forEach(n=>{const o=n.toLowerCase(),r=O.find(this._avaiableFonts,a=>O.findIndex(a.name,h=>h.toLowerCase()==o)>=0);r&&e.push(r.url)}),(await this._cadRenderer.loadFonts(e)).forEach(n=>{n.status||y.emit("font-not-loaded",{fontName:n.fontName,url:n.url})})}}class w{constructor(t){this.events={documentCreated:new c.AcCmEventManager,documentActivated:new c.AcCmEventManager};const e=new $;e.database.events.openProgress.addEventListener(o=>{y.emit("open-file-progress",{percentage:o.percentage,stage:o.stage,stageStatus:o.stageStatus})});const i=()=>({width:window.innerWidth,height:window.innerHeight-30}),n=new st({canvas:t,calculateSizeCallback:i});this._context=new z(n,e),this._fontLoader=new Mt(n.renderer),c.acdbHostApplicationServices().workingDatabase=e.database,this.registerCommands(),this.createExampleDoc()}static createInstance(t){return w._instance==null&&(w._instance=new w(t)),this._instance}static get instance(){return w._instance||(w._instance=new w),w._instance}get context(){return this._context}get curDocument(){return this._context.doc}get mdiActiveDocument(){return this._context.doc}get curView(){return this._context.view}get editor(){return this._context.view.editor}get avaiableFonts(){return this._fontLoader.avaiableFonts}async loadFonts(t){await this._fontLoader.load(t)}async loadDefaultFonts(){const t=["simkai"];await this._fontLoader.load(t)}createExampleDoc(){setTimeout(async()=>{await this.loadDefaultFonts(),A.instance.createExampleDoc2(this.curDocument.database),this.setLayoutInfo(),this.curView.zoomToFit()})}async openUrl(t,e){this.onBeforeOpenDocument(),e=this.setOptions(e);const i=await this.context.doc.openUri(t,e);this.onAfterOpenDocument(i)}async openDocument(t,e,i){this.onBeforeOpenDocument(),i=this.setOptions(i);const n=await this.context.doc.openDocument(t,e,i);this.onAfterOpenDocument(n)}registerCommands(){const t=_.instance;t.addCommand(_.SYSTEMT_COMMAND_GROUP_NAME,"pan","pan",new tt),t.addCommand(_.SYSTEMT_COMMAND_GROUP_NAME,"select","select",new J),t.addCommand(_.SYSTEMT_COMMAND_GROUP_NAME,"zoom","zoom",new Z),t.addCommand(_.SYSTEMT_COMMAND_GROUP_NAME,"zoomw","zoomw",new Q),t.addCommand(_.SYSTEMT_COMMAND_GROUP_NAME,"csvg","csvg",new W),t.addCommand(_.SYSTEMT_COMMAND_GROUP_NAME,"qnew","qnew",new q),t.addCommand(_.SYSTEMT_COMMAND_GROUP_NAME,"open","open",new H)}sendStringToExecute(t){const i=_.instance.lookupGlobalCmd(t);i==null||i.execute(this.context)}onBeforeOpenDocument(){this.curView.clear()}onAfterOpenDocument(t){t&&(this.events.documentActivated.dispatch({doc:this.context.doc}),this.setLayoutInfo(),this.curView.zoomToFit())}setOptions(t){return t==null?t={fontLoader:this._fontLoader}:t.fontLoader==null&&(t.fontLoader=this._fontLoader),t}setLayoutInfo(){const t=this.curView;t.activeLayoutBtrId=this.curDocument.database.currentSpaceId,t.modelSpaceBtrId=this.curDocument.database.currentSpaceId}}const Ot={isDebug:!1,isShowCommandLine:!0,isShowCoordinate:!0,isShowToolbar:!0,isShowStats:!1,fontMapping:{}},ot="settings";class E{constructor(){this.events={modified:new c.AcCmEventManager}}static get instance(){return this._instance||(this._instance=new E),this._instance}set(t,e){const i=this.settings;i[t]=e,localStorage.setItem(ot,JSON.stringify(i)),this.events.modified.dispatch({key:t,value:e})}get(t){return this.settings[t]}toggle(t){const e=this.get(t);this.set(t,!e)}get isDebug(){return this.get("isDebug")}set isDebug(t){this.set("isDebug",t)}get isShowCommandLine(){return this.get("isShowCommandLine")}set isShowCommandLine(t){this.set("isShowCommandLine",t)}get isShowCoordinate(){return this.get("isShowCoordinate")}set isShowCoordinate(t){this.set("isShowCoordinate",t)}get isShowToolbar(){return this.get("isShowToolbar")}set isShowToolbar(t){this.set("isShowToolbar",t)}get isShowStats(){return this.get("isShowStats")}set isShowStats(t){this.set("isShowStats",t)}get fontMapping(){return this.get("fontMapping")}set fontMapping(t){this.set("fontMapping",t)}setFontMapping(t,e){const i=this.get("fontMapping");i[t]=e,this.set("fontMapping",i)}get settings(){const t=localStorage.getItem(ot),e=t==null?{}:JSON.parse(t);return O.defaults(e,Ot)}}u.AcApContext=z,u.AcApConvertToSvgCmd=W,u.AcApDocManager=w,u.AcApDocument=$,u.AcApOpenCmd=H,u.AcApPanCmd=tt,u.AcApQNewCmd=q,u.AcApSelectCmd=J,u.AcApSettingManager=E,u.AcApZoomCmd=Z,u.AcApZoomToBoxCmd=Q,u.AcApZoomToBoxJig=K,u.AcEdBaseView=k,u.AcEdCommand=g,u.AcEdCommandStack=_,u.AcEdCorsorType=b,u.AcEdCursorManager=Y,u.AcEdJig=X,u.AcEdSelectionSet=U,u.AcEdViewMode=p,u.AcEditor=F,u.AcTrView2d=st,u.DEFAULT_VIEW_2D_OPTIONS=R,u.acedAlert=dt,u.eventBus=y,Object.defineProperty(u,Symbol.toStringTag,{value:"Module"})});
|
|
9
|
+
`;return this.encodeSvgToCursor(r,n+e,n+e)}}class P{constructor(t){this.active=!1,this.isResolvedOrRejected=!1,this.onKeyDown=e=>{e.code==="Escape"&&this.reject("Canceled by user!")},this.view=t}get isActive(){return this.active}activate(){this.isActive&&console.warn("Something wrong here!"),this.active=!0,this.view.canvas.addEventListener("keydown",this.onKeyDown)}deactivate(){this.active=!1,this.view.canvas.removeEventListener("keydown",this.onKeyDown)}resolve(t){this.deactivate(),this._resolve&&!this.isResolvedOrRejected&&(this._resolve(t),this.isResolvedOrRejected=!0)}reject(t){this.deactivate(),this._reject&&!this.isResolvedOrRejected&&(this._reject(t),this.isResolvedOrRejected=!0)}async start(){return this.isResolvedOrRejected=!1,new Promise((t,e)=>{this._resolve=t,this._reject=e,this.activate()})}}class mt extends P{constructor(t){super(t),this.events={update:new c.AcCmEventManager},this.onMouseMove=e=>{this.curPos.set(e.clientX,e.clientY),this.events.update.dispatch()},this.curPos=new c.AcGePoint2d}activate(){super.activate(),this.view.canvas.addEventListener("mousemove",this.onMouseMove)}deactivate(){super.deactivate(),this.view.canvas.removeEventListener("mousemove",this.onMouseMove)}}class X{constructor(t){this.onUpdate=()=>{this.update()},this._view=t,this._jigLoop=new mt(t),this._jigLoop.events.update.addEventListener(this.onUpdate)}get view(){return this._view}resolve(t){this._jigLoop.events.update.removeEventListener(this.onUpdate),this._jigLoop.resolve(t)}reject(t){this._jigLoop.events.update.removeEventListener(this.onUpdate),this._jigLoop.reject(t)}async drag(){const t=this._jigLoop.start(),e=this.sampler();await Promise.allSettled([t,e])}async sampler(){}update(){}}const _t=16777215,wt="1px";class ft extends P{constructor(t){super(t),this.mouseDown=!1,this.mouseMove=!1,this.mouseDownPositionX=-1,this.mouseDownPositionY=-1,this.mousedown=e=>{if(e.button===0){this.mouseDown=!0;const i=new c.AcGePoint2d(e.x,e.y);this.mouseDownPositionX=i.x,this.mouseDownPositionY=i.y}},this.mousemove=e=>{if(!this.mouseDown)return;const i=new c.AcGePoint2d(e.x,e.y);if(this.mouseDownPositionX>=0&&this.mouseDownPositionY>=0&&(Math.abs(i.x-this.mouseDownPositionX)>=5||Math.abs(i.y-this.mouseDownPositionY)>=5)){this.mouseMove=!0;const o=new c.AcGePoint2d(Math.min(this.mouseDownPositionX,i.x),Math.min(this.mouseDownPositionY,i.y)),r=new c.AcGePoint2d(Math.max(this.mouseDownPositionX,i.x),Math.max(this.mouseDownPositionY,i.y));this.drawRect(o,r)}},this.mouseup=e=>{if(this.mouseDown&&this.mouseMove){const i=new c.AcGePoint2d(e.x,e.y),n=new c.AcGePoint2d(Math.min(this.mouseDownPositionX,i.x),Math.min(this.mouseDownPositionY,i.y)),o=new c.AcGePoint2d(Math.max(this.mouseDownPositionX,i.x),Math.max(this.mouseDownPositionY,i.y)),r=new c.AcGeBox2d(n,o);this.resolve(this.toWcs(r))}this.mouseDown=!1,this.mouseMove=!1,this.mouseDownPositionX=-1,this.mouseDownPositionY=-1},this.container=t.canvas,this.color=_t}activate(){super.activate(),this.active=!0,this.container.addEventListener("pointerdown",this.mousedown),this.container.addEventListener("pointermove",this.mousemove),this.container.addEventListener("pointerup",this.mouseup)}deactivate(){super.deactivate(),this.container.removeEventListener("pointerdown",this.mousedown),this.container.removeEventListener("pointermove",this.mousemove),this.container.removeEventListener("pointerup",this.mouseup),this.setRectDomVisible(!1)}reject(t){var e;super.reject(t),(e=this.boxDom)==null||e.remove(),this.boxDom=void 0}drawRect(t,e){if(!this.boxDom){const o=new c.AcCmColor;o.color=this.color,this.boxDom=document.createElement("div"),this.boxDom.style.cssText=`position: absolute;border: ${wt} solid ${o.cssColor};`,document.body.appendChild(this.boxDom)}this.setRectDomVisible(!0),t.x<=0&&(t.x=0),t.y<=0&&(t.y=0),e.x>=this.container.clientWidth-2&&(e.x=this.container.clientWidth-2),e.y>=this.container.clientHeight-2&&(e.y=this.container.clientHeight-2),this.boxDom.style.left=`${t.x}px`,this.boxDom.style.top=`${t.y}px`;const i=Math.abs(e.x-t.x),n=Math.abs(e.y-t.y);this.boxDom.style.width=`${i}px`,this.boxDom.style.height=`${n}px`}setRectDomVisible(t){this.boxDom&&(this.boxDom.style.display=t?"inline-block":"none")}toWcs(t){const e=new c.AcGeBox2d,i=new c.AcGePoint2d(t.min.x,t.min.y),n=new c.AcGePoint2d(t.max.x,t.max.y);return e.expandByPoint(this.view.cwcs2Wcs(i)),e.expandByPoint(this.view.cwcs2Wcs(n)),e}}class vt extends P{constructor(t){super(t),this.onClick=e=>{this.resolve(this.view.cwcs2Wcs({x:e.clientX,y:e.clientY}))}}activate(){super.activate(),this.view.canvas.addEventListener("click",this.onClick)}deactivate(){super.deactivate(),this.view.canvas.removeEventListener("click",this.onClick)}}class F{constructor(t){this._view=t,this._cursorManager=new Y}get currentCursor(){return this._currentCursor}restoreCursor(){this._previousCursor!=null&&this.setCursor(this._previousCursor)}setCursor(t){this._cursorManager.setCursor(t,this._view.canvas),this._previousCursor=this._currentCursor,this._currentCursor=t}async getPoint(){return await new vt(this._view).start()}async getSelection(){return await new ft(this._view).start()}}class U{constructor(t=[]){this.events={selectionAdded:new c.AcCmEventManager,selectionRemoved:new c.AcCmEventManager},this._ids=new Set(t)}get ids(){return Array.from(this._ids)}get count(){return this._ids.size}add(t){Array.isArray(t)?(t.forEach(e=>this._ids.add(e)),this.events.selectionAdded.dispatch({ids:t})):(this._ids.add(t),this.events.selectionAdded.dispatch({ids:[t]}))}delete(t){Array.isArray(t)?(t.forEach(e=>this._ids.delete(e)),this.events.selectionRemoved.dispatch({ids:t})):(this._ids.delete(t),this.events.selectionRemoved.dispatch({ids:[t]}))}has(t){return this._ids.has(t)}clear(){if(this._ids.size>0){const t=Array.from(this._ids);this._ids.clear(),this.events.selectionRemoved.dispatch({ids:t})}}}var p=(s=>(s[s.SELECTION=0]="SELECTION",s[s.PAN=1]="PAN",s))(p||{});class k{constructor(t){this.events={mouseMove:new c.AcCmEventManager,viewResize:new c.AcCmEventManager,hover:new c.AcCmEventManager,unhover:new c.AcCmEventManager},this._canvas=t;const e=t.getBoundingClientRect();this._bbox=new c.AcGeBox3d,this._width=e.width,this._height=e.height,this._curPos=new c.AcGePoint2d,this._curScreenPos=new c.AcGePoint2d,this._selectionSet=new U,this._editor=new F(this),this._canvas.addEventListener("mousemove",i=>this.onMouseMove(i)),this._canvas.addEventListener("mousedown",i=>{i.button===1&&this._editor.setCursor(b.Grab)}),this._canvas.addEventListener("mouseup",i=>{i.button===1&&this._editor.restoreCursor()}),window.addEventListener("resize",this.onWindowResize.bind(this)),this._selectionBoxSize=4,this._hoverTimer=null,this._pauseTimer=null,this._hoveredObjectId=null}get editor(){return this._editor}get selectionBoxSize(){return this._selectionBoxSize}set selectionBoxSize(t){this._selectionBoxSize=t}setCursor(t){this._editor.setCursor(t)}setCalculateSizeCallback(t){this._calculateSizeCallback=t}get width(){return this._width}set width(t){this._width=t}get height(){return this._height}set height(t){this._height=t}get bbox(){return this._bbox}get canvas(){return this._canvas}get aspect(){return this._width/this._height}get curPos(){return this._curPos}get curScreenPos(){return this._curScreenPos}get selectionSet(){return this._selectionSet}onWindowResize(){if(this._calculateSizeCallback){const{width:t,height:e}=this._calculateSizeCallback();this._width=t,this._height=e}else this._width=this._canvas.clientWidth,this._height=this._canvas.clientHeight;this.events.viewResize.dispatch({width:this._width,height:this._height})}onMouseMove(t){this._curScreenPos=new c.AcGePoint2d(t.clientX,t.clientY);const e=this.cwcs2Wcs(this._curScreenPos);this._curPos.copy(e),this.events.mouseMove.dispatch({x:e.x,y:e.y}),this.mode==0&&this.startHoverTimer(e.x,e.y)}setHoveredObjectId(t){this._hoveredObjectId&&(this.events.unhover.dispatch({id:this._hoveredObjectId,x:this.curScreenPos.x,y:this.curScreenPos.y}),this.onUnhover(this._hoveredObjectId)),this._hoveredObjectId=t,t&&(this.startPauseTimer(t),this.onHover(t))}hoverAt(t,e){const i=this.pick({x:t,y:e});i.length>0?this.setHoveredObjectId(i[0]):(this.setHoveredObjectId(null),this.clearPauseTimer())}clearHoverTimer(){this._hoverTimer&&clearTimeout(this._hoverTimer)}clearPauseTimer(){this._pauseTimer&&clearTimeout(this._pauseTimer)}startHoverTimer(t,e){this.clearHoverTimer(),this._hoverTimer=setTimeout(()=>{this.hoverAt(t,e)},50)}startPauseTimer(t){this._pauseTimer=setTimeout(()=>{this.events.hover.dispatch({id:t,x:this.curScreenPos.x,y:this.curScreenPos.y})},500)}}class ${constructor(){this._fileName="",this._docTitle="",this._isReadOnly=!0,this._database=new c.AcDbDatabase,this.docTitle="Untitled"}async openUri(t,e){this._uri=t,this._isReadOnly=e&&e.readOnly||!1,this._fileName=this.getFileNameFromUri(t);let i=!0;try{await this._database.openUri(t,e),this.docTitle=this._fileName}catch{i=!1,y.emit("failed-to-open-file",{fileName:t})}return i}async openDocument(t,e,i){var o;let n=!0;this._fileName=t;try{const r=(o=t.split(".").pop())==null?void 0:o.toLocaleLowerCase();await this._database.read(e,i,r=="dwg"?c.AcDbFileType.DWG:c.AcDbFileType.DXF),this.docTitle=this._fileName}catch(r){n=!1,y.emit("failed-to-open-file",{fileName:t}),console.error(r)}return n}get uri(){return this._uri}get database(){return this._database}get docTitle(){return this._docTitle}set docTitle(t){this._docTitle=t,typeof document<"u"&&(document.title=t)}get isReadOnly(){return this._isReadOnly}getFileNameFromUri(t){try{const i=new URL(t).pathname.split("/");return i[i.length-1]||""}catch(e){return console.error("Invalid URI:",e),""}}}class yt{convert(){const t=w.instance.curDocument.database.tables.blockTable.modelSpace.newIterator(),e=new rt.AcSvgRenderer;for(const i of t)i.draw(e);this.createFileAndDownloadIt(e.export())}createFileAndDownloadIt(t){const e=new Blob([t],{type:"image/svg+xml;charset=utf-8"}),i=URL.createObjectURL(e),n=document.createElement("a");n.href=i,n.download="example.svg",document.body.appendChild(n),n.click()}}class W extends g{execute(t){new yt().convert()}}class H extends g{execute(t){y.emit("open-file",{})}}class q extends g{execute(t){w.instance.openUrl("https://cdn.jsdelivr.net/gh/mlight-lee/cad-data/templates/"+"acadiso.dxf")}}class J extends g{execute(t){t.view.mode=p.SELECTION,t.view.setCursor(b.Crosshair)}}class Z extends g{execute(t){t.view.zoomToFit()}}class K extends X{constructor(t){super(t)}async sampler(){await w.instance.editor.getSelection().then(t=>this.view.zoomTo(t,1))}}class Q extends g{async execute(t){await new K(t.view).drag()}}class tt extends g{execute(t){t.view.mode=p.PAN,t.view.setCursor(b.Grab)}}const pt={threeBo2dToGeBox2d:s=>new c.AcGeBox2d(s.min,s.max),goBox2dToThreeBox2d:s=>new f.Box2(s.min,s.max),threeBox3dToGeBox3d:s=>new c.AcGeBox3d(s.min,s.max),goBox3dToThreeBox3d:s=>new f.Box3(s.min,s.max),threeBox3dToGeBox2d:s=>new c.AcGeBox2d(s.min,s.max),goBox2dToThreeBox3d:s=>{const t=new f.Box3;return t.min.set(s.min.x,s.min.y,0),t.max.set(s.max.x,s.max.y,0),t}};class gt extends D.AcTrBaseView{constructor(t,e,i,n){super(t,i,n),this._layoutBtrId=e,this._mode=p.SELECTION,this._axesGizmo=this.createAxesGizmo(),this._viewportViews=new Map}get layoutBtrId(){return this._layoutBtrId}get mode(){return this._mode}set mode(t){t==p.SELECTION?this._cameraControls.mouseButtons={MIDDLE:f.MOUSE.PAN}:t==p.PAN&&(this._cameraControls.mouseButtons={LEFT:f.MOUSE.PAN}),this._cameraControls.update(),this._mode=t}get viewportCount(){return this._viewportViews.size}addViewport(t){this._viewportViews.set(t.viewport.id,t)}removeViewport(t){this._viewportViews.delete(t)}resize(t,e){this._height=e,this._width=t,this.updateCameraFrustum(),this._viewportViews.forEach(i=>{i.update()})}render(t){var i;this._renderer.clear(),this._renderer.render(t.internalScene,this._camera);const e=t.modelSpaceLayout;e&&this.drawViewports(e.internalObject),(i=this._axesGizmo)==null||i.update()}createAxesGizmo(){return new V.AxesGizmo(this._camera.internalCamera,this._renderer.internalRenderer,{hasZAxis:!1,pos:V.ObjectPosition.LEFT_BOTTOM})}drawViewports(t){if(this._viewportViews.size>0){const e=this._renderer.autoClear;this._renderer.autoClear=!1;const i=new f.Vector4;this._renderer.getViewport(i),this._renderer.clearDepth();const n=t.visible;t.visible=!0,this._viewportViews.forEach(o=>{o.render(t)}),t.visible=n,this._renderer.setViewport(i.x,i.y,i.z,i.w),this._renderer.autoClear=e}}}class xt{constructor(){this._activeLayoutBtrId="",this._layoutViews=new Map}get activeLayoutBtrId(){return this._activeLayoutBtrId}set activeLayoutBtrId(t){this._activeLayoutBtrId=t,this._layoutViews.forEach(e=>{e.enabled=e.layoutBtrId==t})}get activeLayoutView(){return this._layoutViews.get(this._activeLayoutBtrId)}has(t){return this._layoutViews.has(t)}getAt(t){return this._layoutViews.get(t)}resize(t,e){this._layoutViews.forEach(i=>{i.resize(t,e)})}add(t){this._layoutViews.set(t.layoutBtrId,t)}render(t){var e;(e=this.activeLayoutView)==null||e.render(t)}}function et(s,t,e=0,i=s.length-1,n=bt){for(;i>e;){if(i-e>600){const h=i-e+1,d=t-e+1,l=Math.log(h),m=.5*Math.exp(2*l/3),x=.5*Math.sqrt(l*m*(h-m)/h)*(d-h/2<0?-1:1),j=Math.max(e,Math.floor(t-d*m/h+x)),Pt=Math.min(i,Math.floor(t+(h-d)*m/h+x));et(s,t,j,Pt,n)}const o=s[t];let r=e,a=i;for(L(s,e,t),n(s[i],o)>0&&L(s,e,i);r<a;){for(L(s,r,a),r++,a--;n(s[r],o)<0;)r++;for(;n(s[a],o)>0;)a--}n(s[e],o)===0?L(s,e,a):(a++,L(s,a,i)),a<=t&&(e=a+1),t<=a&&(i=a-1)}}function L(s,t,e){const i=s[t];s[t]=s[e],s[e]=i}function bt(s,t){return s<t?-1:s>t?1:0}class St{constructor(t=9){this._maxEntries=Math.max(4,t),this._minEntries=Math.max(2,Math.ceil(this._maxEntries*.4)),this.clear()}all(){return this._all(this.data,[])}search(t){let e=this.data;const i=[];if(!M(t,e))return i;const n=this.toBBox,o=[];for(;e;){for(let r=0;r<e.children.length;r++){const a=e.children[r],h=e.leaf?n(a):a;M(t,h)&&(e.leaf?i.push(a):G(t,h)?this._all(a,i):o.push(a))}e=o.pop()}return i}collides(t){let e=this.data;if(!M(t,e))return!1;const i=[];for(;e;){for(let n=0;n<e.children.length;n++){const o=e.children[n],r=e.leaf?this.toBBox(o):o;if(M(t,r)){if(e.leaf||G(t,r))return!0;i.push(o)}}e=i.pop()}return!1}load(t){if(!(t&&t.length))return this;if(t.length<this._minEntries){for(let i=0;i<t.length;i++)this.insert(t[i]);return this}let e=this._build(t.slice(),0,t.length-1,0);if(!this.data.children.length)this.data=e;else if(this.data.height===e.height)this._splitRoot(this.data,e);else{if(this.data.height<e.height){const i=this.data;this.data=e,e=i}this._insert(e,this.data.height-e.height-1,!0)}return this}insert(t){return t&&this._insert(t,this.data.height-1),this}clear(){return this.data=B([]),this}remove(t,e){if(!t)return this;let i=this.data;const n=this.toBBox(t),o=[],r=[];let a,h,d;for(;i||o.length;){if(i||(i=o.pop(),h=o[o.length-1],a=r.pop(),d=!0),i.leaf){const l=Bt(t,i.children,e);if(l!==-1)return i.children.splice(l,1),o.push(i),this._condense(o),this}!d&&!i.leaf&&G(i,n)?(o.push(i),r.push(a),a=0,h=i,i=i.children[0]):h?(a++,i=h.children[a],d=!1):i=null}return this}toBBox(t){return t}compareMinX(t,e){return t.minX-e.minX}compareMinY(t,e){return t.minY-e.minY}toJSON(){return this.data}fromJSON(t){return this.data=t,this}_all(t,e){const i=[];for(;t;)t.leaf?e.push(...t.children):i.push(...t.children),t=i.pop();return e}_build(t,e,i,n){const o=i-e+1;let r=this._maxEntries,a;if(o<=r)return a=B(t.slice(e,i+1)),S(a,this.toBBox),a;n||(n=Math.ceil(Math.log(o)/Math.log(r)),r=Math.ceil(o/Math.pow(r,n-1))),a=B([]),a.leaf=!1,a.height=n;const h=Math.ceil(o/r),d=h*Math.ceil(Math.sqrt(r));it(t,e,i,d,this.compareMinX);for(let l=e;l<=i;l+=d){const m=Math.min(l+d-1,i);it(t,l,m,h,this.compareMinY);for(let x=l;x<=m;x+=h){const j=Math.min(x+h-1,m);a.children.push(this._build(t,x,j,n-1))}}return S(a,this.toBBox),a}_chooseSubtree(t,e,i,n){for(;n.push(e),!(e.leaf||n.length-1===i);){let o=1/0,r=1/0,a;for(let h=0;h<e.children.length;h++){const d=e.children[h],l=N(d),m=Lt(t,d)-l;m<r?(r=m,o=l<o?l:o,a=d):m===r&&l<o&&(o=l,a=d)}e=a||e.children[0]}return e}_insert(t,e,i){const n=i?t:this.toBBox(t),o=[],r=this._chooseSubtree(n,this.data,e,o);for(r.children.push(t),T(r,n);e>=0&&o[e].children.length>this._maxEntries;)this._split(o,e),e--;this._adjustParentBBoxes(n,o,e)}_split(t,e){const i=t[e],n=i.children.length,o=this._minEntries;this._chooseSplitAxis(i,o,n);const r=this._chooseSplitIndex(i,o,n),a=B(i.children.splice(r,i.children.length-r));a.height=i.height,a.leaf=i.leaf,S(i,this.toBBox),S(a,this.toBBox),e?t[e-1].children.push(a):this._splitRoot(i,a)}_splitRoot(t,e){this.data=B([t,e]),this.data.height=t.height+1,this.data.leaf=!1,S(this.data,this.toBBox)}_chooseSplitIndex(t,e,i){let n,o=1/0,r=1/0;for(let a=e;a<=i-e;a++){const h=C(t,0,a,this.toBBox),d=C(t,a,i,this.toBBox),l=Ct(h,d),m=N(h)+N(d);l<o?(o=l,n=a,r=m<r?m:r):l===o&&m<r&&(r=m,n=a)}return n||i-e}_chooseSplitAxis(t,e,i){const n=t.leaf?this.compareMinX:At,o=t.leaf?this.compareMinY:Et,r=this._allDistMargin(t,e,i,n),a=this._allDistMargin(t,e,i,o);r<a&&t.children.sort(n)}_allDistMargin(t,e,i,n){t.children.sort(n);const o=this.toBBox,r=C(t,0,e,o),a=C(t,i-e,i,o);let h=I(r)+I(a);for(let d=e;d<i-e;d++){const l=t.children[d];T(r,t.leaf?o(l):l),h+=I(r)}for(let d=i-e-1;d>=e;d--){const l=t.children[d];T(a,t.leaf?o(l):l),h+=I(a)}return h}_adjustParentBBoxes(t,e,i){for(let n=i;n>=0;n--)T(e[n],t)}_condense(t){for(let e=t.length-1,i;e>=0;e--)t[e].children.length===0?e>0?(i=t[e-1].children,i.splice(i.indexOf(t[e]),1)):this.clear():S(t[e],this.toBBox)}}function Bt(s,t,e){if(!e)return t.indexOf(s);for(let i=0;i<t.length;i++)if(e(s,t[i]))return i;return-1}function S(s,t){C(s,0,s.children.length,t,s)}function C(s,t,e,i,n){n||(n=B(null)),n.minX=1/0,n.minY=1/0,n.maxX=-1/0,n.maxY=-1/0;for(let o=t;o<e;o++){const r=s.children[o];T(n,s.leaf?i(r):r)}return n}function T(s,t){return s.minX=Math.min(s.minX,t.minX),s.minY=Math.min(s.minY,t.minY),s.maxX=Math.max(s.maxX,t.maxX),s.maxY=Math.max(s.maxY,t.maxY),s}function At(s,t){return s.minX-t.minX}function Et(s,t){return s.minY-t.minY}function N(s){return(s.maxX-s.minX)*(s.maxY-s.minY)}function I(s){return s.maxX-s.minX+(s.maxY-s.minY)}function Lt(s,t){return(Math.max(t.maxX,s.maxX)-Math.min(t.minX,s.minX))*(Math.max(t.maxY,s.maxY)-Math.min(t.minY,s.minY))}function Ct(s,t){const e=Math.max(s.minX,t.minX),i=Math.max(s.minY,t.minY),n=Math.min(s.maxX,t.maxX),o=Math.min(s.maxY,t.maxY);return Math.max(0,n-e)*Math.max(0,o-i)}function G(s,t){return s.minX<=t.minX&&s.minY<=t.minY&&t.maxX<=s.maxX&&t.maxY<=s.maxY}function M(s,t){return t.minX<=s.maxX&&t.minY<=s.maxY&&t.maxX>=s.minX&&t.maxY>=s.minY}function B(s){return{children:s,height:1,leaf:!0,minX:1/0,minY:1/0,maxX:-1/0,maxY:-1/0}}function it(s,t,e,i,n){const o=[t,e];for(;o.length;){if(e=o.pop(),t=o.pop(),e-t<=i)continue;const r=t+Math.ceil((e-t)/i/2)*i;et(s,r,t,e,n),o.push(t,r,r,e)}}class Tt{constructor(t){this._group=new D.AcTrBatchedGroup,this._name=t}get name(){return this._name}set name(t){this._name=t}get visible(){return this._group.visible}set visible(t){this._group.visible=t}get internalObject(){return this._group}get stats(){const t=this._group.stats;return{name:this._name,...t}}get entityCount(){return this._group.entityCount}rerenderPoints(t){this._group.rerenderPoints(t)}hasEntity(t){return this._group.hasEntity(t)}addEntity(t){this._group.addEntity(t)}isIntersectWith(t,e){return this._group.isIntersectWith(t,e)}remove(t){throw new Error("Not implemented yet!")}update(t){return this._group.add(t),!0}hover(t){t.forEach(e=>{this._group.hover(e)})}unhover(t){t.forEach(e=>{this._group.unhover(e)})}select(t){t.forEach(e=>{this._group.select(e)})}unselect(t){t.forEach(e=>{this._group.unselect(e)})}}class Dt{constructor(){this._group=new f.Group,this._indexTree=new St,this._box=new f.Box3,this._layers=new Map}get internalObject(){return this._group}get layers(){return this._layers}get box(){return this._box}get visible(){return this._group.visible}set visible(t){this._group.visible=t}get entityCount(){let t=0;return this._layers.forEach(e=>t+=e.entityCount),t}get stats(){const t=[];let e=0,i=0,n=0,o=0,r=0;return this._layers.forEach(a=>{const h=a.stats;t.push(h),n+=h.line.indexed.geometrySize+h.line.nonIndexed.geometrySize,o+=h.mesh.indexed.geometrySize+h.mesh.nonIndexed.geometrySize,r+=h.point.indexed.geometrySize+h.point.nonIndexed.geometrySize,e+=h.summary.totalGeometrySize,i+=h.summary.totalMappingSize}),{layers:t,summary:{entityCount:this.entityCount,totalSize:{line:n,mesh:o,point:r,geometry:e,mapping:i}}}}clear(){return this._layers.forEach(t=>{this._group.remove(t.internalObject)}),this._layers.clear(),this._box.makeEmpty(),this._indexTree.clear(),this}rerenderPoints(t){this._layers.forEach(e=>{e.rerenderPoints(t)})}isIntersectWith(t,e){const i=this.getLayerByObjectId(t);return i&&i.isIntersectWith(t,e)}addEntity(t,e=!0){if(!t.objectId)throw new Error("[AcTrEntity] Object id is required to add one entity!");if(!t.layerName)throw new Error("[AcTrEntity] Layer name is required to add one entity!");const i=this.getLayer(t.layerName,!0);if(i){i.addEntity(t);const n=t.box;e&&this._box.union(n),this._indexTree.insert({minX:n.min.x,minY:n.min.y,maxX:n.max.x,maxY:n.max.y,id:t.objectId})}return this}remove(t){for(const[e,i]of this._layers)if(i.remove(t))return!0;return!1}update(t){for(const[e,i]of this._layers)if(i.update(t))return!0;return!1}hover(t){t.forEach(e=>{const i=this.getLayerByObjectId(e);i&&i.hover([e])})}unhover(t){t.forEach(e=>{const i=this.getLayerByObjectId(e);i&&i.unhover([e])})}select(t){t.forEach(e=>{const i=this.getLayerByObjectId(e);i&&i.select([e])})}unselect(t){t.forEach(e=>{const i=this.getLayerByObjectId(e);i&&i.unselect([e])})}setSnapObject(t){this._snapPointsObject&&this._group.remove(this._snapPointsObject),this._snapPointsObject=t,this._group.add(t)}search(t){return this._indexTree.search({minX:t.min.x,minY:t.min.y,maxX:t.max.x,maxY:t.max.y})}getLayerByObjectId(t){for(const[e,i]of this._layers)if(i.hasEntity(t))return i}getLayer(t,e=!0){let i=this._layers.get(t);return i===void 0&&e&&(i=new Tt(t),this._layers.set(t,i),this._group.add(i.internalObject)),i}}class It{constructor(){this._scene=new f.Scene,this._layouts=new Map,this._activeLayoutBtrId="",this._modelSpaceBtrId=""}get layouts(){return this._layouts}get box(){var t;return(t=this.activeLayout)==null?void 0:t.box}get internalScene(){return this._scene}get modelSpaceBtrId(){return this._modelSpaceBtrId}set modelSpaceBtrId(t){if(this._modelSpaceBtrId=t,!this._layouts.has(t))throw new Error(`[AcTrScene] No layout assiciated with the specified block table record id '${t}'!`)}get activeLayoutBtrId(){return this._activeLayoutBtrId}set activeLayoutBtrId(t){this._activeLayoutBtrId=t,this._layouts.forEach((e,i)=>{e.visible=t==i})}get activeLayout(){if(this._activeLayoutBtrId&&this._layouts.has(this._activeLayoutBtrId))return this._layouts.get(this._activeLayoutBtrId)}get modelSpaceLayout(){if(this._modelSpaceBtrId&&this._layouts.has(this._modelSpaceBtrId))return this._layouts.get(this._modelSpaceBtrId)}get stats(){const t=[];return this._layouts.forEach(e=>t.push(e.stats)),{layouts:t}}addEmptyLayout(t){const e=new Dt;return this._layouts.set(t,e),this._scene.add(e.internalObject),e.visible=t==this._activeLayoutBtrId,e}clear(){return this._layouts.forEach(t=>{this._scene.remove(t.internalObject),t.clear()}),this._layouts.clear(),this._scene.clear(),this}setLayerVisibility(t,e){var n;let i=!1;return(n=this.activeLayout)==null||n.layers.forEach(o=>{o.name===t&&(o.visible=e,i=!0)}),i}hover(t){return this.activeLayout?(this.activeLayout.hover(t),!0):!1}unhover(t){return this.activeLayout?(this.activeLayout.unhover(t),!0):!1}select(t){return this.activeLayout?(this.activeLayout.select(t),!0):!1}unselect(t){return this.activeLayout?(this.activeLayout.unselect(t),!0):!1}search(t){const e=this.activeLayout;return e?e==null?void 0:e.search(t):[]}addEntity(t,e=!0){const i=t.ownerId;if(i){let n=this._layouts.get(i);n||(n=this.addEmptyLayout(i)),n.addEntity(t,e)}else console.warn("[AcTrSecene] The owner id of one entity cannot be empty!");return this}remove(t){for(const[e,i]of this._layouts)if(i.remove(t))return!0;return!1}update(t){for(const[e,i]of this._layouts)if(i.update(t))return!0;return!1}setSnapObject(t){return this._layouts.forEach(e=>{e.setSnapObject(t)}),this}}const R={background:0};class st extends k{constructor(t=R){const e={...R,...t},i=new f.WebGLRenderer({antialias:!0,alpha:!0,canvas:t.canvas});e.canvas==null&&(e.canvas=i.domElement),super(e.canvas),t.calculateSizeCallback&&this.setCalculateSizeCallback(t.calculateSizeCallback),i.setPixelRatio(Math.min(window.devicePixelRatio,2)),i.setSize(this.width,this.height),i.setClearColor(e.background||0),this._renderer=new D.AcTrRenderer(i);const n=E.instance.fontMapping;this._renderer.setFontMapping(n),this._renderer.events.fontNotFound.addEventListener(o=>{y.emit("font-not-found",{fontName:o.fontName,count:o.count??0})}),this._scene=this.createScene(),this._stats=this.createStats(E.instance.isShowStats),E.instance.events.modified.addEventListener(o=>{o.key=="isShowStats"&&this.toggleStatsVisibility(this._stats,o.value)}),this.canvas.addEventListener("click",()=>{this.mode==p.SELECTION&&this.select()}),document.addEventListener("keydown",o=>{o.code==="Escape"&&this.selectionSet.clear()}),c.acdbHostApplicationServices().layoutManager.events.layoutSwitched.addEventListener(o=>{this.activeLayoutBtrId=o.newLayout.blockTableRecordId}),this._missedImages=new Map,this._layoutViewManager=new xt,this.initialize(),this.onWindowResize(),this.animate(),this._isDirty=!0}initialize(){this.setCursor(b.Crosshair)}get mode(){const t=this.activeLayoutView;return t?t.mode:p.SELECTION}set mode(t){this.activeLayoutView.mode=t,this.editor.getPoint()}get renderer(){return this._renderer}get isDirty(){return this._isDirty}set isDirty(t){this._isDirty=t}get missedData(){return{fonts:this._renderer.missedFonts,images:this._missedImages}}get center(){return this.activeLayoutView.center}set center(t){this.activeLayoutView.center=t}get modelSpaceBtrId(){return this._scene.modelSpaceBtrId}set modelSpaceBtrId(t){this._scene.modelSpaceBtrId=t}get activeLayoutBtrId(){return this._scene.activeLayoutBtrId}set activeLayoutBtrId(t){this._layoutViewManager.activeLayoutBtrId=t,this._scene.activeLayoutBtrId=t,this._isDirty=!0}get activeLayoutView(){return this._layoutViewManager.activeLayoutView}get stats(){return this._scene.stats}animate(){var t;requestAnimationFrame(this.animate.bind(this)),this._isDirty&&(this._layoutViewManager.render(this._scene),(t=this._stats)==null||t.update(),this._isDirty=!1)}cwcs2Wcs(t){const e=this.activeLayoutView;return e?e.cwcs2Wcs(t):new c.AcGePoint2d(t)}wcs2Cwcs(t){const e=this.activeLayoutView;return e?e.wcs2Cwcs(t):new c.AcGePoint2d(t)}zoomTo(t,e=1.1){this.activeLayoutView.zoomTo(t,e),this._isDirty=!0}rerenderPoints(t){const e=this._scene.activeLayout;e&&(e.rerenderPoints(t),this._isDirty=!0)}zoomToFit(){if(this._scene.box){const t=pt.threeBox3dToGeBox2d(this._scene.box);this.zoomTo(t),this._isDirty=!0}}pick(t){t==null&&(t=this.curPos);const e=[],i=this._scene.activeLayout;if(i){const n=this.activeLayoutView,o=n.pointToBox(t,this.selectionBoxSize),r=this._scene.search(o),a=Math.max(o.size.width/2,o.size.height/2),h=n.resetRaycaster(t,a);r.forEach(d=>{const l=d.id;i.isIntersectWith(l,h)&&e.push(l)})}return e}search(t){return this._scene.search(t)}select(t){const e=[];this.pick(t).forEach(n=>e.push(n)),e.length>0&&this.selectionSet.add(e)}selectByBox(t){const e=[];this._scene.search(t).forEach(n=>e.push(n.id)),this.selectionSet.add(e)}addEntity(t){const e=this.createLayoutViewIfNeeded(t.ownerId);let i=t.draw(this._renderer);if(i){i.objectId=t.objectId,i.ownerId=t.ownerId,i.layerName=t.layer,i.visible=t.visibility;const n=!(t instanceof c.AcDbRay||t instanceof c.AcDbXline);this._scene.addEntity(i,n),this._isDirty=!0,i.dispose(),i=null}if(t instanceof c.AcDbViewport){if(t.number>1){const n=new D.AcTrViewportView(e,t.toGiViewport(),this._renderer);e.addViewport(n)}}else if(t instanceof c.AcDbRasterImage){const n=t.imageFileName;n&&this._missedImages.set(t.objectId,n)}}removeEntity(t){this._scene.remove(t)}updateEntity(t){const e=t.draw(this._renderer);return e&&(e.objectId=t.objectId,e.ownerId=t.ownerId,e.layerName=t.layer,e.visible=t.visibility,this._scene.update(e),this._isDirty=!0,setTimeout(()=>{this._isDirty=!0},100)),e}clear(){this._scene.clear(),this._isDirty=!0,this._missedImages.clear(),this._renderer.clearMissedFonts()}highlight(t){this._isDirty=this._scene.select(t)}unhighlight(t){this._isDirty=this._scene.unselect(t)}setLayerVisibility(t,e){this._isDirty=this._scene.setLayerVisibility(t,e)}onHover(t){this._isDirty=this._scene.hover([t])}onUnhover(t){this._isDirty=this._scene.unhover([t])}createScene(){const t=new It;return t.layouts.forEach(e=>{e.setSnapObject(this.renderer.createObject())}),t}createStats(t){const e=new ct;document.body.appendChild(e.dom);const i=e.dom;return i.style.position="fixed",i.style.inset="unset",i.style.bottom="30px",i.style.right="0px",this.toggleStatsVisibility(e,t),e}onWindowResize(){super.onWindowResize(),this._renderer.setSize(this.width,this.height),this._layoutViewManager.resize(this.width,this.height),this._isDirty=!0}createLayoutViewIfNeeded(t){let e=this._layoutViewManager.getAt(t);return e==null&&(e=new gt(this._renderer,t,this.width,this.height),e.events.viewChanged.addEventListener(()=>{this._isDirty=!0}),this._layoutViewManager.add(e)),e}toggleStatsVisibility(t,e){e?t.dom.style.display="block":t.dom.style.display="none"}}const nt="simsun";class A{static get instance(){return A._instance||(A._instance=new A),A._instance}createExampleDoc1(t){for(let n=0;n<2;++n)for(let o=0;o<2;++o){const r=new c.AcDbHatch,a=new c.AcGePolyline2d;a.addVertexAt(0,{x:o*100,y:n*100,bulge:1}),a.addVertexAt(1,{x:o*100+100,y:n*100,bulge:1}),a.closed=!0,r.add(a),t.tables.blockTable.modelSpace.appendEntity(r)}}createExampleDoc2(t){const e=t.tables.blockTable.modelSpace;e.appendEntity(this.createArc()),this.createLines().forEach(n=>{t.tables.blockTable.modelSpace.appendEntity(new c.AcDbLine(n.startPoint,n.endPoint))}),e.appendEntity(this.createHatch()),t.tables.textStyleTable.add(this.createTextStyle()),e.appendEntity(this.createMText())}createTextStyle(){const t={bigFont:"",color:16777215,extendedFont:nt,fixedTextHeight:0,font:nt,lastHeight:.2,name:"Standard",obliqueAngle:0,standardFlag:0,textGenerationFlag:0,widthFactor:.667};return new c.AcDbTextStyleTableRecord(t)}createMText(){const t=new c.AcDbMText;return t.attachmentPoint=c.AcGiMTextAttachmentPoint.MiddleLeft,t.color=new c.AcCmColor().setColorName("red"),t.layer="0",t.location=new c.AcGePoint3d(9850,86773,0),t.contents="{\\W0.667;\\T1.1;智慧8081}",t.height=200,t.width=1e3,t.styleName="Standard",t}createHatch(){const t=this.createLines(),e=new c.AcDbHatch,i=new c.AcGeLoop2d;return i.add(new c.AcGeCircArc2d({x:20241.23355899991,y:174118.6312674369},89258.30757455899,c.AcGeMathUtil.degToRad(262.2471115358437),c.AcGeMathUtil.degToRad(264.444541053754),!1)),t.forEach(n=>{i.add(new c.AcGeLine2d(n.startPoint,n.endPoint))}),e.add(i),e}createArc(){return new c.AcDbArc({x:20241.23355899991,y:174118.6312674369,z:0},89258.30757455899,c.AcGeMathUtil.degToRad(262.2471115358437),c.AcGeMathUtil.degToRad(264.444541053754))}createLines(){const t=[];return t.push(new c.AcGeLine3d({x:11600.20888122753,y:85279.57362051727,z:0},{x:11600.20890652924,y:86546.03982284805,z:0})),t.push(new c.AcGeLine3d({x:11600.20890652924,y:86546.03982284805,z:0},{x:10850.20885583921,y:86546.03980174381,z:0})),t.push(new c.AcGeLine3d({x:10850.2088602169,y:86546.03967292747,z:0},{x:9050.208860216895,y:86546.039672927,z:0})),t.push(new c.AcGeLine3d({x:9050.208855839213,y:86546.0397510943,z:0},{x:8200.209067034302,y:86546.039727177,z:0})),t.push(new c.AcGeLine3d({x:8200.209067034302,y:86546.039727177,z:0},{x:8200.209067033837,y:85676.22514764359,z:0})),t}}class Mt{constructor(t){this._cadRenderer=t,this._avaiableFonts=[]}get avaiableFonts(){return this._avaiableFonts}async getAvaiableFonts(){if(this._avaiableFonts.length==0){const t="https://cdn.jsdelivr.net/gh/mlight-lee/cad-data/fonts/",e=t+"fonts.json";try{const i=await fetch(e);this._avaiableFonts=await i.json()}catch{y.emit("failed-to-get-avaiable-fonts",{url:e})}this._avaiableFonts.forEach(i=>{i.url=t+i.file})}return this._avaiableFonts}async load(t){await this.getAvaiableFonts();const e=[];t.forEach(n=>{const o=n.toLowerCase(),r=O.find(this._avaiableFonts,a=>O.findIndex(a.name,h=>h.toLowerCase()==o)>=0);r&&e.push(r.url)}),(await this._cadRenderer.loadFonts(e)).forEach(n=>{n.status||y.emit("font-not-loaded",{fontName:n.fontName,url:n.url})})}}class w{constructor(t){this.events={documentCreated:new c.AcCmEventManager,documentActivated:new c.AcCmEventManager};const e=new $;e.database.events.openProgress.addEventListener(o=>{y.emit("open-file-progress",{percentage:o.percentage,stage:o.stage,stageStatus:o.stageStatus})});const i=()=>({width:window.innerWidth,height:window.innerHeight-30}),n=new st({canvas:t,calculateSizeCallback:i});this._context=new z(n,e),this._fontLoader=new Mt(n.renderer),c.acdbHostApplicationServices().workingDatabase=e.database,this.registerCommands()}static createInstance(t){return w._instance==null&&(w._instance=new w(t)),this._instance}static get instance(){return w._instance||(w._instance=new w),w._instance}get context(){return this._context}get curDocument(){return this._context.doc}get mdiActiveDocument(){return this._context.doc}get curView(){return this._context.view}get editor(){return this._context.view.editor}get avaiableFonts(){return this._fontLoader.avaiableFonts}async loadFonts(t){await this._fontLoader.load(t)}async loadDefaultFonts(t){t==null?await this._fontLoader.load(["simkai"]):await this._fontLoader.load(t)}createExampleDoc(){setTimeout(async()=>{await this.loadDefaultFonts(),A.instance.createExampleDoc2(this.curDocument.database),this.setLayoutInfo(),this.curView.zoomToFit()})}async openUrl(t,e){this.onBeforeOpenDocument(),e=this.setOptions(e);const i=await this.context.doc.openUri(t,e);return this.onAfterOpenDocument(i),i}async openDocument(t,e,i){this.onBeforeOpenDocument(),i=this.setOptions(i);const n=await this.context.doc.openDocument(t,e,i);return this.onAfterOpenDocument(n),n}registerCommands(){const t=_.instance;t.addCommand(_.SYSTEMT_COMMAND_GROUP_NAME,"pan","pan",new tt),t.addCommand(_.SYSTEMT_COMMAND_GROUP_NAME,"select","select",new J),t.addCommand(_.SYSTEMT_COMMAND_GROUP_NAME,"zoom","zoom",new Z),t.addCommand(_.SYSTEMT_COMMAND_GROUP_NAME,"zoomw","zoomw",new Q),t.addCommand(_.SYSTEMT_COMMAND_GROUP_NAME,"csvg","csvg",new W),t.addCommand(_.SYSTEMT_COMMAND_GROUP_NAME,"qnew","qnew",new q),t.addCommand(_.SYSTEMT_COMMAND_GROUP_NAME,"open","open",new H)}sendStringToExecute(t){const i=_.instance.lookupGlobalCmd(t);i==null||i.execute(this.context)}onBeforeOpenDocument(){this.curView.clear()}onAfterOpenDocument(t){t&&(this.events.documentActivated.dispatch({doc:this.context.doc}),this.setLayoutInfo(),this.curView.zoomToFit())}setOptions(t){return t==null?t={fontLoader:this._fontLoader}:t.fontLoader==null&&(t.fontLoader=this._fontLoader),t}setLayoutInfo(){const t=this.curView;t.activeLayoutBtrId=this.curDocument.database.currentSpaceId,t.modelSpaceBtrId=this.curDocument.database.currentSpaceId}}const Ot={isDebug:!1,isShowCommandLine:!0,isShowCoordinate:!0,isShowToolbar:!0,isShowStats:!1,fontMapping:{}},ot="settings";class E{constructor(){this.events={modified:new c.AcCmEventManager}}static get instance(){return this._instance||(this._instance=new E),this._instance}set(t,e){const i=this.settings;i[t]=e,localStorage.setItem(ot,JSON.stringify(i)),this.events.modified.dispatch({key:t,value:e})}get(t){return this.settings[t]}toggle(t){const e=this.get(t);this.set(t,!e)}get isDebug(){return this.get("isDebug")}set isDebug(t){this.set("isDebug",t)}get isShowCommandLine(){return this.get("isShowCommandLine")}set isShowCommandLine(t){this.set("isShowCommandLine",t)}get isShowCoordinate(){return this.get("isShowCoordinate")}set isShowCoordinate(t){this.set("isShowCoordinate",t)}get isShowToolbar(){return this.get("isShowToolbar")}set isShowToolbar(t){this.set("isShowToolbar",t)}get isShowStats(){return this.get("isShowStats")}set isShowStats(t){this.set("isShowStats",t)}get fontMapping(){return this.get("fontMapping")}set fontMapping(t){this.set("fontMapping",t)}setFontMapping(t,e){const i=this.get("fontMapping");i[t]=e,this.set("fontMapping",i)}get settings(){const t=localStorage.getItem(ot),e=t==null?{}:JSON.parse(t);return O.defaults(e,Ot)}}u.AcApContext=z,u.AcApConvertToSvgCmd=W,u.AcApDocManager=w,u.AcApDocument=$,u.AcApOpenCmd=H,u.AcApPanCmd=tt,u.AcApQNewCmd=q,u.AcApSelectCmd=J,u.AcApSettingManager=E,u.AcApZoomCmd=Z,u.AcApZoomToBoxCmd=Q,u.AcApZoomToBoxJig=K,u.AcEdBaseView=k,u.AcEdCommand=g,u.AcEdCommandStack=_,u.AcEdCorsorType=b,u.AcEdCursorManager=Y,u.AcEdJig=X,u.AcEdSelectionSet=U,u.AcEdViewMode=p,u.AcEditor=F,u.AcTrView2d=st,u.DEFAULT_VIEW_2D_OPTIONS=R,u.acedAlert=dt,u.eventBus=y,Object.defineProperty(u,Symbol.toStringTag,{value:"Module"})});
|
package/lib/app/AcApContext.d.ts
CHANGED
|
@@ -1,15 +1,57 @@
|
|
|
1
1
|
import { AcEdBaseView } from '../editor/view/AcEdBaseView';
|
|
2
2
|
import { AcApDocument } from './AcApDocument';
|
|
3
|
+
/**
|
|
4
|
+
* Application context that binds a CAD document with its associated view.
|
|
5
|
+
*
|
|
6
|
+
* This class establishes the connection between a CAD document (containing the drawing database)
|
|
7
|
+
* and its visual representation (the view). It handles event forwarding between the document
|
|
8
|
+
* and view to keep them synchronized.
|
|
9
|
+
*
|
|
10
|
+
* The context manages:
|
|
11
|
+
* - Entity lifecycle events (add, modify, remove)
|
|
12
|
+
* - Layer visibility changes
|
|
13
|
+
* - System variable changes (like point display mode)
|
|
14
|
+
* - Entity selection and highlighting
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```typescript
|
|
18
|
+
* const document = new AcApDocument();
|
|
19
|
+
* const view = new AcTrView2d();
|
|
20
|
+
* const context = new AcApContext(view, document);
|
|
21
|
+
*
|
|
22
|
+
* // The context will automatically sync changes between document and view
|
|
23
|
+
* // For example, when entities are added to the document, they appear in the view
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
3
26
|
export declare class AcApContext {
|
|
27
|
+
/** The view component that renders the CAD drawing */
|
|
4
28
|
private _view;
|
|
29
|
+
/** The document containing the CAD database */
|
|
5
30
|
private _doc;
|
|
6
31
|
/**
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
32
|
+
* Creates a new application context that binds a document with its view.
|
|
33
|
+
*
|
|
34
|
+
* The constructor sets up event listeners to synchronize the document and view:
|
|
35
|
+
* - Entity additions/modifications are reflected in the view
|
|
36
|
+
* - Layer visibility changes update the view
|
|
37
|
+
* - System variable changes (like point display mode) update rendering
|
|
38
|
+
* - Entity selections show/hide grip points
|
|
39
|
+
*
|
|
40
|
+
* @param view - The view used to display the drawing
|
|
41
|
+
* @param doc - The document containing the drawing database
|
|
10
42
|
*/
|
|
11
43
|
constructor(view: AcEdBaseView, doc: AcApDocument);
|
|
44
|
+
/**
|
|
45
|
+
* Gets the view component that renders the CAD drawing.
|
|
46
|
+
*
|
|
47
|
+
* @returns The associated view instance
|
|
48
|
+
*/
|
|
12
49
|
get view(): AcEdBaseView;
|
|
50
|
+
/**
|
|
51
|
+
* Gets the document containing the CAD database.
|
|
52
|
+
*
|
|
53
|
+
* @returns The associated document instance
|
|
54
|
+
*/
|
|
13
55
|
get doc(): AcApDocument;
|
|
14
56
|
}
|
|
15
57
|
//# sourceMappingURL=AcApContext.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AcApContext.d.ts","sourceRoot":"","sources":["../../src/app/AcApContext.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAA;AAE1D,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAA;AAE7C,qBAAa,WAAW;IACtB,OAAO,CAAC,KAAK,CAAc;IAC3B,OAAO,CAAC,IAAI,CAAc;IAE1B
|
|
1
|
+
{"version":3,"file":"AcApContext.d.ts","sourceRoot":"","sources":["../../src/app/AcApContext.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAA;AAE1D,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAA;AAE7C;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,qBAAa,WAAW;IACtB,sDAAsD;IACtD,OAAO,CAAC,KAAK,CAAc;IAC3B,+CAA+C;IAC/C,OAAO,CAAC,IAAI,CAAc;IAE1B;;;;;;;;;;;OAWG;gBACS,IAAI,EAAE,YAAY,EAAE,GAAG,EAAE,YAAY;IAqCjD;;;;OAIG;IACH,IAAI,IAAI,iBAEP;IAED;;;;OAIG;IACH,IAAI,GAAG,IAAI,YAAY,CAEtB;CACF"}
|
package/lib/app/AcApContext.js
CHANGED
|
@@ -1,8 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Application context that binds a CAD document with its associated view.
|
|
3
|
+
*
|
|
4
|
+
* This class establishes the connection between a CAD document (containing the drawing database)
|
|
5
|
+
* and its visual representation (the view). It handles event forwarding between the document
|
|
6
|
+
* and view to keep them synchronized.
|
|
7
|
+
*
|
|
8
|
+
* The context manages:
|
|
9
|
+
* - Entity lifecycle events (add, modify, remove)
|
|
10
|
+
* - Layer visibility changes
|
|
11
|
+
* - System variable changes (like point display mode)
|
|
12
|
+
* - Entity selection and highlighting
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```typescript
|
|
16
|
+
* const document = new AcApDocument();
|
|
17
|
+
* const view = new AcTrView2d();
|
|
18
|
+
* const context = new AcApContext(view, document);
|
|
19
|
+
*
|
|
20
|
+
* // The context will automatically sync changes between document and view
|
|
21
|
+
* // For example, when entities are added to the document, they appear in the view
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
1
24
|
var AcApContext = /** @class */ (function () {
|
|
2
25
|
/**
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
26
|
+
* Creates a new application context that binds a document with its view.
|
|
27
|
+
*
|
|
28
|
+
* The constructor sets up event listeners to synchronize the document and view:
|
|
29
|
+
* - Entity additions/modifications are reflected in the view
|
|
30
|
+
* - Layer visibility changes update the view
|
|
31
|
+
* - System variable changes (like point display mode) update rendering
|
|
32
|
+
* - Entity selections show/hide grip points
|
|
33
|
+
*
|
|
34
|
+
* @param view - The view used to display the drawing
|
|
35
|
+
* @param doc - The document containing the drawing database
|
|
6
36
|
*/
|
|
7
37
|
function AcApContext(view, doc) {
|
|
8
38
|
var _this = this;
|
|
@@ -37,6 +67,11 @@ var AcApContext = /** @class */ (function () {
|
|
|
37
67
|
});
|
|
38
68
|
}
|
|
39
69
|
Object.defineProperty(AcApContext.prototype, "view", {
|
|
70
|
+
/**
|
|
71
|
+
* Gets the view component that renders the CAD drawing.
|
|
72
|
+
*
|
|
73
|
+
* @returns The associated view instance
|
|
74
|
+
*/
|
|
40
75
|
get: function () {
|
|
41
76
|
return this._view;
|
|
42
77
|
},
|
|
@@ -44,6 +79,11 @@ var AcApContext = /** @class */ (function () {
|
|
|
44
79
|
configurable: true
|
|
45
80
|
});
|
|
46
81
|
Object.defineProperty(AcApContext.prototype, "doc", {
|
|
82
|
+
/**
|
|
83
|
+
* Gets the document containing the CAD database.
|
|
84
|
+
*
|
|
85
|
+
* @returns The associated document instance
|
|
86
|
+
*/
|
|
47
87
|
get: function () {
|
|
48
88
|
return this._doc;
|
|
49
89
|
},
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AcApContext.js","sourceRoot":"","sources":["../../src/app/AcApContext.ts"],"names":[],"mappings":"AAIA;
|
|
1
|
+
{"version":3,"file":"AcApContext.js","sourceRoot":"","sources":["../../src/app/AcApContext.ts"],"names":[],"mappings":"AAIA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH;IAME;;;;;;;;;;;OAWG;IACH,qBAAY,IAAkB,EAAE,GAAiB;QAAjD,iBAmCC;QAlCC,IAAI,CAAC,KAAK,GAAG,IAAI,CAAA;QACjB,IAAI,CAAC,IAAI,GAAG,GAAG,CAAA;QAEf,sBAAsB;QACtB,GAAG,CAAC,QAAQ,CAAC,MAAM,CAAC,cAAc,CAAC,gBAAgB,CAAC,UAAA,IAAI;YACtD,KAAI,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,MAAM,CAAC,CAAA;QAClC,CAAC,CAAC,CAAA;QAEF,gBAAgB;QAChB,GAAG,CAAC,QAAQ,CAAC,MAAM,CAAC,cAAc,CAAC,gBAAgB,CAAC,UAAA,IAAI;YACtD,KAAI,CAAC,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,MAAM,CAAC,CAAA;QACrC,CAAC,CAAC,CAAA;QAEF,uBAAuB;QACvB,GAAG,CAAC,QAAQ,CAAC,MAAM,CAAC,aAAa,CAAC,gBAAgB,CAAC,UAAA,IAAI;YACrD,KAAI,CAAC,KAAK,CAAC,kBAAkB,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAA;QACnE,CAAC,CAAC,CAAA;QAEF,yBAAyB;QACzB,GAAG,CAAC,QAAQ,CAAC,MAAM,CAAC,mBAAmB,CAAC,gBAAgB,CAAC,UAAA,IAAI;YAC3D,IAAI,IAAI,CAAC,IAAI,IAAI,QAAQ,EAAE,CAAC;gBAC1B,CAAC;gBAAC,KAAI,CAAC,KAAoB,CAAC,cAAc,CAAC,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAA;YAClE,CAAC;QACH,CAAC,CAAC,CAAA;QAEF,oDAAoD;QACpD,IAAI,CAAC,YAAY,CAAC,MAAM,CAAC,cAAc,CAAC,gBAAgB,CAAC,UAAA,IAAI;YAC3D,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;QAC1B,CAAC,CAAC,CAAA;QAEF,sDAAsD;QACtD,IAAI,CAAC,YAAY,CAAC,MAAM,CAAC,gBAAgB,CAAC,gBAAgB,CAAC,UAAA,IAAI;YAC7D,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;QAC5B,CAAC,CAAC,CAAA;IACJ,CAAC;IAOD,sBAAI,6BAAI;QALR;;;;WAIG;aACH;YACE,OAAO,IAAI,CAAC,KAAK,CAAA;QACnB,CAAC;;;OAAA;IAOD,sBAAI,4BAAG;QALP;;;;WAIG;aACH;YACE,OAAO,IAAI,CAAC,IAAI,CAAA;QAClB,CAAC;;;OAAA;IACH,kBAAC;AAAD,CAAC,AAxED,IAwEC"}
|
|
@@ -1,12 +1,78 @@
|
|
|
1
1
|
import { AcDbDatabase } from '@mlightcad/data-model';
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
4
|
-
*
|
|
3
|
+
* Factory class for creating example CAD documents with predefined content.
|
|
4
|
+
*
|
|
5
|
+
* This utility class provides methods to generate sample CAD drawings for
|
|
6
|
+
* testing, demonstration, or initial document templates. It creates various
|
|
7
|
+
* types of CAD entities including:
|
|
8
|
+
* - Geometric shapes (arcs, lines, hatches)
|
|
9
|
+
* - Text elements (MText with formatting)
|
|
10
|
+
* - Text styles and formatting
|
|
11
|
+
*
|
|
12
|
+
* The class follows a singleton pattern to ensure consistent example
|
|
13
|
+
* data generation across the application.
|
|
14
|
+
*
|
|
15
|
+
* @internal This class is for internal use by the framework
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```typescript
|
|
19
|
+
* const creator = AcApDocCreator.instance;
|
|
20
|
+
* const database = new AcDbDatabase();
|
|
21
|
+
*
|
|
22
|
+
* // Create example document with various entities
|
|
23
|
+
* creator.createExampleDoc2(database);
|
|
24
|
+
*
|
|
25
|
+
* // The database now contains sample lines, arcs, hatches, and text
|
|
26
|
+
* ```
|
|
5
27
|
*/
|
|
6
28
|
export declare class AcApDocCreator {
|
|
29
|
+
/** Singleton instance */
|
|
7
30
|
private static _instance?;
|
|
31
|
+
/**
|
|
32
|
+
* Gets the singleton instance of the document creator.
|
|
33
|
+
*
|
|
34
|
+
* @returns The singleton AcApDocCreator instance
|
|
35
|
+
*/
|
|
8
36
|
static get instance(): AcApDocCreator;
|
|
37
|
+
/**
|
|
38
|
+
* Creates a simple example document with circular hatches.
|
|
39
|
+
*
|
|
40
|
+
* This method generates a 2x2 grid of circular hatched areas,
|
|
41
|
+
* useful for testing hatch rendering and basic geometry display.
|
|
42
|
+
*
|
|
43
|
+
* @param db - The database to add the example entities to
|
|
44
|
+
*
|
|
45
|
+
* @example
|
|
46
|
+
* ```typescript
|
|
47
|
+
* const creator = AcApDocCreator.instance;
|
|
48
|
+
* const database = new AcDbDatabase();
|
|
49
|
+
* creator.createExampleDoc1(database);
|
|
50
|
+
* // Database now contains 4 circular hatches in a grid
|
|
51
|
+
* ```
|
|
52
|
+
*/
|
|
9
53
|
createExampleDoc1(db: AcDbDatabase): void;
|
|
54
|
+
/**
|
|
55
|
+
* Creates a comprehensive example document with various CAD entities.
|
|
56
|
+
*
|
|
57
|
+
* This method generates a more complex document containing:
|
|
58
|
+
* - Arcs and lines forming geometric shapes
|
|
59
|
+
* - Complex hatches with boundary loops
|
|
60
|
+
* - Formatted text (MText) with Chinese characters
|
|
61
|
+
* - Custom text styles
|
|
62
|
+
*
|
|
63
|
+
* This example is useful for testing complex rendering scenarios,
|
|
64
|
+
* text handling, and international character support.
|
|
65
|
+
*
|
|
66
|
+
* @param db - The database to add the example entities to
|
|
67
|
+
*
|
|
68
|
+
* @example
|
|
69
|
+
* ```typescript
|
|
70
|
+
* const creator = AcApDocCreator.instance;
|
|
71
|
+
* const database = new AcDbDatabase();
|
|
72
|
+
* creator.createExampleDoc2(database);
|
|
73
|
+
* // Database now contains arcs, lines, hatches, and formatted text
|
|
74
|
+
* ```
|
|
75
|
+
*/
|
|
10
76
|
createExampleDoc2(db: AcDbDatabase): void;
|
|
11
77
|
private createTextStyle;
|
|
12
78
|
private createMText;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AcApDocCreator.d.ts","sourceRoot":"","sources":["../../src/app/AcApDocCreator.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,YAAY,EAcb,MAAM,uBAAuB,CAAA;AAI9B
|
|
1
|
+
{"version":3,"file":"AcApDocCreator.d.ts","sourceRoot":"","sources":["../../src/app/AcApDocCreator.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,YAAY,EAcb,MAAM,uBAAuB,CAAA;AAI9B;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,qBAAa,cAAc;IACzB,yBAAyB;IACzB,OAAO,CAAC,MAAM,CAAC,SAAS,CAAC,CAAgB;IAEzC;;;;OAIG;IACH,MAAM,KAAK,QAAQ,mBAKlB;IAED;;;;;;;;;;;;;;;OAeG;IACH,iBAAiB,CAAC,EAAE,EAAE,YAAY;IAgBlC;;;;;;;;;;;;;;;;;;;;;OAqBG;IACH,iBAAiB,CAAC,EAAE,EAAE,YAAY;IAelC,OAAO,CAAC,eAAe;IAiBvB,OAAO,CAAC,WAAW;IAanB,OAAO,CAAC,WAAW;IAoBnB,OAAO,CAAC,SAAS;IASjB,OAAO,CAAC,WAAW;CA0EpB"}
|
|
@@ -1,13 +1,40 @@
|
|
|
1
1
|
import { AcCmColor, AcDbArc, AcDbHatch, AcDbLine, AcDbMText, AcDbTextStyleTableRecord, AcGeCircArc2d, AcGeLine2d, AcGeLine3d, AcGeLoop2d, AcGeMathUtil, AcGePoint3d, AcGePolyline2d, AcGiMTextAttachmentPoint } from '@mlightcad/data-model';
|
|
2
2
|
var DEFAULT_FONT = 'simsun';
|
|
3
3
|
/**
|
|
4
|
-
*
|
|
5
|
-
*
|
|
4
|
+
* Factory class for creating example CAD documents with predefined content.
|
|
5
|
+
*
|
|
6
|
+
* This utility class provides methods to generate sample CAD drawings for
|
|
7
|
+
* testing, demonstration, or initial document templates. It creates various
|
|
8
|
+
* types of CAD entities including:
|
|
9
|
+
* - Geometric shapes (arcs, lines, hatches)
|
|
10
|
+
* - Text elements (MText with formatting)
|
|
11
|
+
* - Text styles and formatting
|
|
12
|
+
*
|
|
13
|
+
* The class follows a singleton pattern to ensure consistent example
|
|
14
|
+
* data generation across the application.
|
|
15
|
+
*
|
|
16
|
+
* @internal This class is for internal use by the framework
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```typescript
|
|
20
|
+
* const creator = AcApDocCreator.instance;
|
|
21
|
+
* const database = new AcDbDatabase();
|
|
22
|
+
*
|
|
23
|
+
* // Create example document with various entities
|
|
24
|
+
* creator.createExampleDoc2(database);
|
|
25
|
+
*
|
|
26
|
+
* // The database now contains sample lines, arcs, hatches, and text
|
|
27
|
+
* ```
|
|
6
28
|
*/
|
|
7
29
|
var AcApDocCreator = /** @class */ (function () {
|
|
8
30
|
function AcApDocCreator() {
|
|
9
31
|
}
|
|
10
32
|
Object.defineProperty(AcApDocCreator, "instance", {
|
|
33
|
+
/**
|
|
34
|
+
* Gets the singleton instance of the document creator.
|
|
35
|
+
*
|
|
36
|
+
* @returns The singleton AcApDocCreator instance
|
|
37
|
+
*/
|
|
11
38
|
get: function () {
|
|
12
39
|
if (!AcApDocCreator._instance) {
|
|
13
40
|
AcApDocCreator._instance = new AcApDocCreator();
|
|
@@ -17,6 +44,22 @@ var AcApDocCreator = /** @class */ (function () {
|
|
|
17
44
|
enumerable: false,
|
|
18
45
|
configurable: true
|
|
19
46
|
});
|
|
47
|
+
/**
|
|
48
|
+
* Creates a simple example document with circular hatches.
|
|
49
|
+
*
|
|
50
|
+
* This method generates a 2x2 grid of circular hatched areas,
|
|
51
|
+
* useful for testing hatch rendering and basic geometry display.
|
|
52
|
+
*
|
|
53
|
+
* @param db - The database to add the example entities to
|
|
54
|
+
*
|
|
55
|
+
* @example
|
|
56
|
+
* ```typescript
|
|
57
|
+
* const creator = AcApDocCreator.instance;
|
|
58
|
+
* const database = new AcDbDatabase();
|
|
59
|
+
* creator.createExampleDoc1(database);
|
|
60
|
+
* // Database now contains 4 circular hatches in a grid
|
|
61
|
+
* ```
|
|
62
|
+
*/
|
|
20
63
|
AcApDocCreator.prototype.createExampleDoc1 = function (db) {
|
|
21
64
|
var rowCount = 2;
|
|
22
65
|
var colCount = 2;
|
|
@@ -32,6 +75,28 @@ var AcApDocCreator = /** @class */ (function () {
|
|
|
32
75
|
}
|
|
33
76
|
}
|
|
34
77
|
};
|
|
78
|
+
/**
|
|
79
|
+
* Creates a comprehensive example document with various CAD entities.
|
|
80
|
+
*
|
|
81
|
+
* This method generates a more complex document containing:
|
|
82
|
+
* - Arcs and lines forming geometric shapes
|
|
83
|
+
* - Complex hatches with boundary loops
|
|
84
|
+
* - Formatted text (MText) with Chinese characters
|
|
85
|
+
* - Custom text styles
|
|
86
|
+
*
|
|
87
|
+
* This example is useful for testing complex rendering scenarios,
|
|
88
|
+
* text handling, and international character support.
|
|
89
|
+
*
|
|
90
|
+
* @param db - The database to add the example entities to
|
|
91
|
+
*
|
|
92
|
+
* @example
|
|
93
|
+
* ```typescript
|
|
94
|
+
* const creator = AcApDocCreator.instance;
|
|
95
|
+
* const database = new AcDbDatabase();
|
|
96
|
+
* creator.createExampleDoc2(database);
|
|
97
|
+
* // Database now contains arcs, lines, hatches, and formatted text
|
|
98
|
+
* ```
|
|
99
|
+
*/
|
|
35
100
|
AcApDocCreator.prototype.createExampleDoc2 = function (db) {
|
|
36
101
|
var modelSpace = db.tables.blockTable.modelSpace;
|
|
37
102
|
modelSpace.appendEntity(this.createArc());
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AcApDocCreator.js","sourceRoot":"","sources":["../../src/app/AcApDocCreator.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,SAAS,EACT,OAAO,EAEP,SAAS,EACT,QAAQ,EACR,SAAS,EACT,wBAAwB,EACxB,aAAa,EACb,UAAU,EACV,UAAU,EACV,UAAU,EACV,YAAY,EACZ,WAAW,EACX,cAAc,EACd,wBAAwB,EAEzB,MAAM,uBAAuB,CAAA;AAE9B,IAAM,YAAY,GAAG,QAAQ,CAAA;AAE7B
|
|
1
|
+
{"version":3,"file":"AcApDocCreator.js","sourceRoot":"","sources":["../../src/app/AcApDocCreator.ts"],"names":[],"mappings":"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"}
|