@mlightcad/cad-simple-viewer 1.1.10 → 1.1.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +78 -68
- package/dist/index.umd.cjs +1 -1
- package/lib/app/AcApFontLoader.js +1 -1
- package/lib/app/AcApFontLoader.js.map +1 -1
- package/package.json +5 -5
package/dist/index.js
CHANGED
|
@@ -20927,7 +20927,7 @@ class Cp {
|
|
|
20927
20927
|
*/
|
|
20928
20928
|
async getAvaiableFonts() {
|
|
20929
20929
|
if (this._avaiableFonts.length == 0) {
|
|
20930
|
-
const e = "https://
|
|
20930
|
+
const e = "https://mlightcad.gitlab.io/cad-data/fonts/", t = e + "fonts.json";
|
|
20931
20931
|
try {
|
|
20932
20932
|
const n = await fetch(t);
|
|
20933
20933
|
this._avaiableFonts = await n.json();
|
|
@@ -21345,18 +21345,26 @@ class zs {
|
|
|
21345
21345
|
);
|
|
21346
21346
|
}
|
|
21347
21347
|
convertSpline(e) {
|
|
21348
|
-
|
|
21349
|
-
e.
|
|
21350
|
-
|
|
21351
|
-
|
|
21352
|
-
|
|
21353
|
-
|
|
21354
|
-
|
|
21355
|
-
|
|
21356
|
-
|
|
21357
|
-
e.
|
|
21358
|
-
|
|
21359
|
-
|
|
21348
|
+
try {
|
|
21349
|
+
if (e.numberOfControlPoints > 0 && e.numberOfKnots > 0)
|
|
21350
|
+
return new Cr(
|
|
21351
|
+
e.controlPoints,
|
|
21352
|
+
e.knots,
|
|
21353
|
+
e.weights,
|
|
21354
|
+
e.degree,
|
|
21355
|
+
!!(e.flag & 1)
|
|
21356
|
+
);
|
|
21357
|
+
if (e.numberOfFitPoints > 0)
|
|
21358
|
+
return new Cr(
|
|
21359
|
+
e.fitPoints,
|
|
21360
|
+
"Uniform",
|
|
21361
|
+
e.degree,
|
|
21362
|
+
!!(e.flag & 1)
|
|
21363
|
+
);
|
|
21364
|
+
} catch (t) {
|
|
21365
|
+
console.log(`Failed to convert spline with error: ${t}`);
|
|
21366
|
+
}
|
|
21367
|
+
return null;
|
|
21360
21368
|
}
|
|
21361
21369
|
convertPoint(e) {
|
|
21362
21370
|
const t = new Co();
|
|
@@ -21416,65 +21424,67 @@ class zs {
|
|
|
21416
21424
|
} else {
|
|
21417
21425
|
const i = s, o = new Mo();
|
|
21418
21426
|
i.edges.forEach((a) => {
|
|
21419
|
-
if (a
|
|
21420
|
-
|
|
21421
|
-
|
|
21422
|
-
|
|
21423
|
-
|
|
21424
|
-
|
|
21425
|
-
new Ao(
|
|
21426
|
-
c.center,
|
|
21427
|
-
c.radius,
|
|
21428
|
-
c.startAngle,
|
|
21429
|
-
c.endAngle,
|
|
21430
|
-
!c.isCCW
|
|
21431
|
-
)
|
|
21432
|
-
);
|
|
21433
|
-
} else if (a.type == 3) {
|
|
21434
|
-
const c = a;
|
|
21435
|
-
new Vn().subVectors(c.end, c.center);
|
|
21436
|
-
const l = Math.sqrt(
|
|
21437
|
-
Math.pow(c.end.x, 2) + Math.pow(c.end.y, 2)
|
|
21438
|
-
), h = l * c.lengthOfMinorAxis;
|
|
21439
|
-
let d = c.startAngle, u = c.endAngle;
|
|
21440
|
-
const p = Math.atan2(c.end.y, c.end.x);
|
|
21441
|
-
c.isCCW || (d = Math.PI * 2 - d, u = Math.PI * 2 - u), o.add(
|
|
21442
|
-
new Lo(
|
|
21443
|
-
{ ...c.center, z: 0 },
|
|
21444
|
-
l,
|
|
21445
|
-
h,
|
|
21446
|
-
d,
|
|
21447
|
-
u,
|
|
21448
|
-
!c.isCCW,
|
|
21449
|
-
p
|
|
21450
|
-
)
|
|
21451
|
-
);
|
|
21452
|
-
} else if (a.type == 4) {
|
|
21453
|
-
const c = a;
|
|
21454
|
-
if (c.numberOfControlPoints > 0 && c.numberOfKnots > 0) {
|
|
21455
|
-
const l = c.controlPoints.map(
|
|
21456
|
-
(u) => ({
|
|
21457
|
-
x: u.x,
|
|
21458
|
-
y: u.y,
|
|
21459
|
-
z: 0
|
|
21460
|
-
})
|
|
21461
|
-
);
|
|
21462
|
-
let h = !0;
|
|
21463
|
-
const d = c.controlPoints.map((u) => (u.weight == null && (h = !1), u.weight || 1));
|
|
21427
|
+
if (a != null) {
|
|
21428
|
+
if (a.type == 1) {
|
|
21429
|
+
const c = a;
|
|
21430
|
+
o.add(new Bo(c.start, c.end));
|
|
21431
|
+
} else if (a.type == 2) {
|
|
21432
|
+
const c = a;
|
|
21464
21433
|
o.add(
|
|
21465
|
-
new
|
|
21434
|
+
new Ao(
|
|
21435
|
+
c.center,
|
|
21436
|
+
c.radius,
|
|
21437
|
+
c.startAngle,
|
|
21438
|
+
c.endAngle,
|
|
21439
|
+
!c.isCCW
|
|
21440
|
+
)
|
|
21441
|
+
);
|
|
21442
|
+
} else if (a.type == 3) {
|
|
21443
|
+
const c = a;
|
|
21444
|
+
new Vn().subVectors(c.end, c.center);
|
|
21445
|
+
const l = Math.sqrt(
|
|
21446
|
+
Math.pow(c.end.x, 2) + Math.pow(c.end.y, 2)
|
|
21447
|
+
), h = l * c.lengthOfMinorAxis;
|
|
21448
|
+
let d = c.startAngle, u = c.endAngle;
|
|
21449
|
+
const p = Math.atan2(c.end.y, c.end.x);
|
|
21450
|
+
c.isCCW || (d = Math.PI * 2 - d, u = Math.PI * 2 - u), o.add(
|
|
21451
|
+
new Lo(
|
|
21452
|
+
{ ...c.center, z: 0 },
|
|
21466
21453
|
l,
|
|
21467
|
-
|
|
21468
|
-
|
|
21454
|
+
h,
|
|
21455
|
+
d,
|
|
21456
|
+
u,
|
|
21457
|
+
!c.isCCW,
|
|
21458
|
+
p
|
|
21469
21459
|
)
|
|
21470
21460
|
);
|
|
21471
|
-
} else if (
|
|
21472
|
-
const
|
|
21473
|
-
|
|
21474
|
-
|
|
21475
|
-
|
|
21476
|
-
|
|
21477
|
-
|
|
21461
|
+
} else if (a.type == 4) {
|
|
21462
|
+
const c = a;
|
|
21463
|
+
if (c.numberOfControlPoints > 0 && c.numberOfKnots > 0) {
|
|
21464
|
+
const l = c.controlPoints.map(
|
|
21465
|
+
(u) => ({
|
|
21466
|
+
x: u.x,
|
|
21467
|
+
y: u.y,
|
|
21468
|
+
z: 0
|
|
21469
|
+
})
|
|
21470
|
+
);
|
|
21471
|
+
let h = !0;
|
|
21472
|
+
const d = c.controlPoints.map((u) => (u.weight == null && (h = !1), u.weight || 1));
|
|
21473
|
+
o.add(
|
|
21474
|
+
new kr(
|
|
21475
|
+
l,
|
|
21476
|
+
c.knots,
|
|
21477
|
+
h ? d : void 0
|
|
21478
|
+
)
|
|
21479
|
+
);
|
|
21480
|
+
} else if (c.numberOfFitData > 0) {
|
|
21481
|
+
const l = c.fitDatum.map((h) => ({
|
|
21482
|
+
x: h.x,
|
|
21483
|
+
y: h.y,
|
|
21484
|
+
z: 0
|
|
21485
|
+
}));
|
|
21486
|
+
o.add(new kr(l, "Uniform"));
|
|
21487
|
+
}
|
|
21478
21488
|
}
|
|
21479
21489
|
}
|
|
21480
21490
|
}), n.add(o);
|
package/dist/index.umd.cjs
CHANGED
|
@@ -281,4 +281,4 @@
|
|
|
281
281
|
}
|
|
282
282
|
}
|
|
283
283
|
#include <colorspace_fragment>
|
|
284
|
-
}`;return new g.ShaderMaterial({uniforms:c,vertexShader:h,fragmentShader:l,clipping:!0})}}const hn=class Ft{constructor(){this.pointMaterials={},this.lineShaderMaterials={},this.lineBasicMaterials={},this.hatchShaderMaterials=[],this.meshBasicMaterials={},this.unsupportedTextStyles={}}getPointsMaterial(e,t=2){const n=`${e}_${t}`;return this.pointMaterials[n]||(this.pointMaterials[n]=new g.PointsMaterial({size:t,color:e})),this.pointMaterials[n]}getMeshBasicMaterial(e){return this.meshBasicMaterials[e]||(this.meshBasicMaterials[e]=new g.MeshBasicMaterial({color:e})),this.meshBasicMaterials[e]}getLineBasicMaterial(e){return this.lineBasicMaterials[e]||(this.lineBasicMaterials[e]=new g.LineBasicMaterial({color:e})),this.lineBasicMaterials[e]}getLineShaderMaterial(e,t){if(e.pattern&&e.pattern.length!==0){const n=`${e.name}_${e.color}_${t}`;return this.lineShaderMaterials[n]||(this.lineShaderMaterials[n]=qu.createLineShaderMaterial(e.pattern,e.color,t,Ft.ViewportScaleUniform,Ft.CameraZoomUniform)),this.lineShaderMaterials[n]}else return this.getLineBasicMaterial(e.color)}getHatchShaderMaterial(e,t){if(!e.patternLines||e.patternLines.length<1)return this.getMeshBasicMaterial(e.color);let n=!1;if(e.patternLines.forEach(u=>{u.dashPattern||(n=!0,console.log("Invalid dash pattern: ",e))}),n)return;const s=this.findMatchedHatchShaderMaterial(e);if(s)return s;const i=.005,o=.05;let a=2;e.patternLines.forEach(u=>{a=Math.max(u.dashPattern.length,a)});let c=0;const h=[],l=new g.Vector2;for(const u of e.patternLines){const p=new g.Vector2(u.origin.x,u.origin.y).sub(t).rotateAround(l,-g.MathUtils.degToRad(e.patternAngle)),f=new g.Vector2(u.delta.x,u.delta.y).rotateAround(l,-g.MathUtils.degToRad(u.angle));if(f.y===0){console.warn("delta.y is equal to zero!");return}const m=u.dashPattern.length;let y=!0,b=0;for(let I=0;I<m;++I){const E=u.dashPattern[I];E>0&&(y=!1),b+=Math.abs(E)}const S=y?o:i,w=[],C=[];let T=0;C[0]=T;for(let I=0;I<m;++I)w[I]=u.dashPattern[I],w[I]===0&&(w[I]=S*b),T+=Math.abs(w[I]),C[I+1]=T;for(let I=m;I<a;++I)w[I]=0;for(let I=C.length;I<a+1;++I)C[I]=T;const D={origin:p,delta:f,angle:u.angle-e.patternAngle,pattern:w,patternSum:C,patternLength:T};if(c+=4,c+=a,c+=a+1,c>Ft.MaxFragmentUniforms){console.warn("There will be warning in fragment shader when number of uniforms exceeds 1024, so extra hatch line patterns are ignored here!");break}h.push(D)}const d=Xu(h,e.patternAngle,Ft.CameraZoomUniform,new g.Color(e.color));return d.defines={MAX_PATTERN_SEGMENT_COUNT:a},this.hatchShaderMaterials.push({patternLines:e.patternLines,patternAngle:e.patternAngle,color:e.color,material:d}),d}findMatchedHatchShaderMaterial(e){const t=e.patternLines;if(!t||t.length<1)return;const n=(c,h)=>Math.abs(c-h)<1e-5,s=(c,h)=>{if(c.length!==h.length)return!1;for(let l=0;l<c.length;++l)if(!n(c[l],h[l]))return!1;return!0},i=(c,h)=>n(c.angle,h.angle)&&n(c.delta.x,h.delta.x)&&n(c.delta.y,h.delta.y)&&n(c.origin.x,h.origin.x)&&n(c.origin.y,h.origin.y)&&s(c.dashPattern,h.dashPattern),o=(c,h)=>{if(c.length!==h.length)return!1;for(let l=0;l<c.length;++l)if(!i(c[l],h[l]))return!1;return!0},a=this.hatchShaderMaterials.find(c=>c.color===e.color&&c.patternAngle===e.patternAngle&&o(c.patternLines,t));return a==null?void 0:a.material}};hn.CameraZoomUniform={value:1},hn.ViewportScaleUniform={value:1},hn.MaxFragmentUniforms=1024;let $u=hn;class Yu{constructor(e){this.events={fontNotFound:new _.AcCmEventManager},this._renderer=e,this._styleManager=new $u,ee.instance.events.fontNotFound.addEventListener(t=>{this.events.fontNotFound.dispatch(t)})}get autoClear(){return this._renderer.autoClear}set autoClear(e){this._renderer.autoClear=e}get domElement(){return this._renderer.domElement}setSize(e,t){this._renderer.setSize(e,t)}getViewport(e){return this._renderer.getViewport(e)}setViewport(e,t,n,s){this._renderer.setViewport(e,t,n,s)}clear(){this._renderer.clear()}clearDepth(){this._renderer.clearDepth()}render(e,t){this._renderer.render(e,t.internalCamera)}setClearColor(e,t){this._renderer.setClearColor(e,t)}getClearColor(){const e=new g.Color;return this._renderer.getClearColor(e),e.getHex()}setClearAlpha(e){this._renderer.setClearAlpha(e)}getClearAlpha(){return this._renderer.getClearAlpha()}get internalRenderer(){return this._renderer}async loadFonts(e){return await ee.instance.loadFontsByUrls(e)}setFontMapping(e){ee.instance.setFontMapping(e)}get missedFonts(){return ee.instance.missedFonts}clearMissedFonts(){ee.instance.missedFonts={}}createObject(){return new Yi(this._styleManager)}createEntity(){return new ne(this._styleManager)}group(e){return new sn(e,this._styleManager)}point(e,t){return new Wu(e,t,this._styleManager)}circularArc(e,t){return this.linePoints(e.getPoints(100),t)}ellipticalArc(e,t){return this.linePoints(e.getPoints(100),t)}lines(e,t){return this.linePoints(e,t)}lineSegments(e,t,n,s){return new zu(e,t,n,s,this._styleManager)}area(e,t){return new ju(e,t,this._styleManager)}mtext(e,t,n){return new Vu(e,t,this._styleManager,n)}image(e,t){return new Gu(e,t,this._styleManager)}linePoints(e,t=void 0){return new Nu(e,t,this._styleManager)}}class Zu{constructor(e){this._camera=e}get position(){return this._camera.position}get left(){return this._camera.left}set left(e){this._camera.left=e}get right(){return this._camera.right}set right(e){this._camera.right=e}get top(){return this._camera.top}set top(e){this._camera.top=e}get bottom(){return this._camera.bottom}set bottom(e){this._camera.bottom=e}get zoom(){return this._camera.zoom}set zoom(e){this._camera.zoom=e}get internalCamera(){return this._camera}lookAt(e){this._camera.lookAt(e)}setRotationFromEuler(e){this._camera.setRotationFromEuler(e)}updateProjectionMatrix(){this._camera.updateProjectionMatrix()}cwcs2Wcs(e,t,n){const s=new g.Vector3(e.x,e.y,0);s.x=e.x/t*2-1,s.y=-(e.y/n)*2+1;const i=s.unproject(this._camera);return new _.AcGePoint2d(i.x,i.y)}wcs2Cwcs(e,t,n){const s=new g.Vector3(e.x,e.y,0).project(this._camera);return new _.AcGePoint2d((s.x+1)/2*t,(-s.y+1)/2*n)}wcs2Ndc(e,t,n){const s=this.wcs2Cwcs(e,t,n);return this.cwcs2Ndc(s,t,n)}cwcs2Ndc(e,t,n){return new _.AcGePoint2d(e.x/t*2-1,-(e.y/n)*2+1)}}class Qi{constructor(e,t,n){this._frustum=400,this.events={viewChanged:new _.AcCmEventManager},this._renderer=e,this._width=t,this._height=n;const s=this.createCamera();this._camera=new Zu(s),this._cameraControls=this.createCameraControls(),this._cameraControls.addEventListener("change",()=>{this.events.viewChanged.dispatch({view:this})}),this._raycaster=new g.Raycaster}get width(){return this._width}set width(e){this._width=e}get height(){return this._height}set height(e){this._height=e}get enabled(){return this._cameraControls.enabled}set enabled(e){this._cameraControls.enabled=e}get center(){return this._camera.cwcs2Wcs({x:this._width/2,y:this._height/2},this._width,this._height)}set center(e){this._camera.position.set(e.x,e.y,this._camera.position.z),this._camera.updateProjectionMatrix()}cwcs2Wcs(e){return this._camera.cwcs2Wcs(e,this._width,this._height)}wcs2Cwcs(e){return this._camera.wcs2Cwcs(e,this._width,this._height)}pointToBox(e,t){const n=this.wcs2Cwcs(e),s=this.cwcs2Wcs({x:n.x+t,y:n.y+t}),i=this.cwcs2Wcs({x:n.x-t,y:n.y-t});return new _.AcGeBox2d().setFromPoints([s,i])}resetRaycaster(e,t){const n=this._camera.wcs2Ndc(e,this._width,this._height);return this._raycaster.setFromCamera(new g.Vector2(n.x,n.y),this._camera.internalCamera),this._raycaster.params.Line.threshold=t,this._raycaster.params.Points.threshold=t,this._raycaster}zoomTo(e,t=1.1){const n=new _.AcGeVector2d;e.getSize(n);const s=new _.AcGeVector2d;e.getCenter(s);const i=new g.Vector3(s.x,s.y,0);this._camera.position.set(s.x,s.y,this._camera.position.z),this._camera.lookAt(i),this._camera.setRotationFromEuler(new g.Euler(0,0,0));const o=n.x*t,a=n.y*t,c=this._width/o,h=this._height/a;this._camera.zoom=Math.min(c,h),this._cameraControls.target=i,this.updateCameraFrustum()}updateCameraFrustum(e,t){const n=(e??this._width)/(t??this._height);this._camera.left=-n*this._frustum,this._camera.right=n*this._frustum,this._camera.top=this._frustum,this._camera.bottom=-this._frustum,this._camera.updateProjectionMatrix(),this._cameraControls.update()}createCamera(){const e=new g.OrthographicCamera(-this._width/2,this._width/2,this._height/2,-this._height/2,.1,1e3);return e.position.set(0,0,500),e.up.set(0,1,0),e.updateProjectionMatrix(),e}createCameraControls(){const e=new co.OrbitControls(this._camera.internalCamera,this._renderer.domElement);return e.enableDamping=!1,e.autoRotate=!1,e.enableRotate=!1,e.zoomSpeed=5,e.mouseButtons={MIDDLE:g.MOUSE.PAN},e.update(),e}}class ln extends Qi{static calculateViewportWindowBox(e,t){const n=t.box,s=new _.AcGeBox2d;return s.expandByPoint(e.wcs2Cwcs(n.min)),s.expandByPoint(e.wcs2Cwcs(n.max)),s}constructor(e,t,n){const s=ln.calculateViewportWindowBox(e,t).size;super(n,s.width,s.height),this._parentView=e,this._viewport=t.clone(),this._frustum*=t.height/e.height,this.zoomTo(this._viewport.viewBox),this.enabled=!1}get viewport(){return this._viewport}update(){this.zoomTo(this._viewport.viewBox)}render(e){const t=ln.calculateViewportWindowBox(this._parentView,this._viewport);if(!t.isEmpty()){const n=this._parentView.height-t.min.y-t.size.height;this._renderer.setViewport(t.min.x,n,t.size.width,t.size.height),this._renderer.internalRenderer.setScissor(t.min.x,n,t.size.width,t.size.height),this._renderer.internalRenderer.setScissorTest(!0),this._renderer.render(e,this._camera),this._renderer.internalRenderer.setScissorTest(!1)}}}const Qu={threeBo2dToGeBox2d:r=>new _.AcGeBox2d(r.min,r.max),geBox2dToThreeBox2d:r=>new g.Box2(r.min,r.max),threeBox3dToGeBox3d:r=>new _.AcGeBox3d(r.min,r.max),geBox3dToThreeBox3d:r=>new g.Box3(r.min,r.max),goBox3dToGeBox2d:r=>new _.AcGeBox2d(r.min,r.max),threeBox3dToGeBox2d:r=>new _.AcGeBox2d(r.min,r.max),geBox2dToThreeBox3d:r=>{const e=new g.Box3;return e.min.set(r.min.x,r.min.y,0),e.max.set(r.max.x,r.max.y,0),e}};var un=(r=>(r[r.LEFT_BOTTOM=0]="LEFT_BOTTOM",r[r.LEFT_TOP=1]="LEFT_TOP",r[r.RIGHT_TOP=2]="RIGHT_TOP",r[r.RIGHT_BOTTOM=4]="RIGHT_BOTTOM",r))(un||{});class Ju extends g.Object3D{constructor(e,t,n=150,s=2){super(),this.camera=e,this.renderer=t,this.gizmoCamera=new g.OrthographicCamera(-2,2,2,-2,0,4),this.gizmoCamera.position.set(0,0,2),this.gizmoDim=n,this.gizmoPos=s,this.initialize()}initialize(){}update(){this.updateOrientation();const e=this.renderer.autoClear;this.renderer.autoClear=!1,this.renderer.clearDepth();const t=new g.Vector4;this.renderer.getViewport(t);const n=this.calculateViewportPos();this.renderer.setViewport(n.x,n.y,this.gizmoDim,this.gizmoDim),this.renderer.render(this,this.gizmoCamera),this.renderer.setViewport(t.x,t.y,t.z,t.w),this.renderer.autoClear=e}dispose(){}updateOrientation(){this.quaternion.copy(this.camera.quaternion).invert(),this.updateMatrixWorld()}calculatePosInViewport(e,t,n){const s=(e-n.min.x)/this.gizmoDim*2-1,i=-((t-n.min.y)/this.gizmoDim)*2+1;return{x:s,y:i}}calculateViewportPos(){const e=this.renderer.domElement,t=e.offsetWidth,n=e.offsetHeight,s=this.gizmoPos,i=this.gizmoDim;let o=t-i,a=n-i;switch(s){case 0:o=0,a=0;break;case 1:o=0;break;case 4:a=0;break}return{x:o,y:a}}calculateViewportBbox(){const e=this.renderer.domElement,t=e.offsetWidth,n=e.offsetHeight,s=this.gizmoPos,i=this.gizmoDim,o=new g.Box2(new g.Vector2(t-i,0),new g.Vector2(t,i));switch(s){case 0:o.set(new g.Vector2(0,n-i),new g.Vector2(i,n));break;case 1:o.set(new g.Vector2(0,0),new g.Vector2(i,i));break;case 4:o.set(new g.Vector2(t-i,n-i),new g.Vector2(t,n));break}return o}}function Ku(r,e){const t=e.font||"Helvetica",n=e.fontSize||30,s=e.width||200,i=e.height||200,o=e.bgColor?e.bgColor.join(", "):"255, 255, 255, 1.0",a=e.color?e.color.join(", "):"0, 0, 0, 1.0",c=document.createElement("canvas");c.width=s,c.height=i;const h=c.getContext("2d");if(h){h.font=`bold ${n}px ${t}`,h.fillStyle=`rgba(${o})`,h.fillRect(0,0,s,i);const u=h.measureText(r).width;h.fillStyle=`rgba(${a})`,h.fillText(r,s/2-u/2,i/2+n/2-2)}const l=new g.Texture(c);return l.minFilter=g.LinearFilter,l.needsUpdate=!0,l}function gr(r){const e=Ku(r,{fontSize:100,font:"Arial Narrow, sans-serif",color:[255,255,255,1],bgColor:[0,0,0,0]}),t=new g.SpriteMaterial({map:e,transparent:!0});return new g.Sprite(t)}un.RIGHT_TOP;const ed={pos:un.LEFT_BOTTOM,size:100,hasZAxis:!0};class td extends Ju{constructor(e,t,n){const s={...ed,...n};super(e,t,s.size,n.pos),this.hasZAxis=s.hasZAxis;const i=[0,0,0,2,0,0,0,0,0,0,2,0],o=[1,0,0,1,.6,0,0,1,0,.6,1,0];this.hasZAxis&&(i.push(0,0,0,0,0,2),o.push(0,0,1,0,.6,1));const a=new g.BufferGeometry;a.setAttribute("position",new g.Float32BufferAttribute(i,3)),a.setAttribute("color",new g.Float32BufferAttribute(o,3));const c=new g.LineBasicMaterial({vertexColors:!0,toneMapped:!1});this.axes=new g.LineSegments(a,c),this.axes.position.set(-1,-1,-1),this.add(this.axes),this.xText=gr("X"),this.xText.position.set(1.5,-1,-1),this.add(this.xText),this.yText=gr("Y"),this.yText.position.set(-1,1.5,-1),this.add(this.yText),this.hasZAxis&&(this.zText=gr("Z"),this.zText.position.set(-1,-1,1.5),this.add(this.zText))}setLineColors(e,t){const n=new g.Color,s=this.axes.geometry.attributes.color.array;return n.set(e),n.toArray(s,0),n.toArray(s,3),n.set(t),n.toArray(s,6),n.toArray(s,9),this.axes.geometry.attributes.color.needsUpdate=!0,this}setTextColor(e){this.xText.material.color=e,this.yText.material.color=e}dispose(){var e,t;this.axes.geometry.dispose(),this.axes.material.dispose(),this.xText.geometry.dispose(),this.xText.material.dispose(),this.yText.geometry.dispose(),this.yText.material.dispose(),this.hasZAxis&&((e=this.zText)==null||e.geometry.dispose(),(t=this.zText)==null||t.material.dispose())}}class nd extends Qi{constructor(e,t,n,s){super(e,n,s),this._layoutBtrId=t,this._mode=Ie.SELECTION,this._axesGizmo=this.createAxesGizmo(),this._viewportViews=new Map}get layoutBtrId(){return this._layoutBtrId}get mode(){return this._mode}set mode(e){e==Ie.SELECTION?this._cameraControls.mouseButtons={MIDDLE:g.MOUSE.PAN}:e==Ie.PAN&&(this._cameraControls.mouseButtons={LEFT:g.MOUSE.PAN}),this._cameraControls.update(),this._mode=e}get viewportCount(){return this._viewportViews.size}addViewport(e){this._viewportViews.set(e.viewport.id,e)}removeViewport(e){this._viewportViews.delete(e)}resize(e,t){this._height=t,this._width=e,this.updateCameraFrustum(),this._viewportViews.forEach(n=>{n.update()})}render(e){var n;this._renderer.clear(),this._renderer.render(e.internalScene,this._camera);const t=e.modelSpaceLayout;t&&this.drawViewports(t.internalObject),(n=this._axesGizmo)==null||n.update()}createAxesGizmo(){return new td(this._camera.internalCamera,this._renderer.internalRenderer,{hasZAxis:!1,pos:un.LEFT_BOTTOM})}drawViewports(e){if(this._viewportViews.size>0){const t=this._renderer.autoClear;this._renderer.autoClear=!1;const n=new g.Vector4;this._renderer.getViewport(n),this._renderer.clearDepth();const s=e.visible;e.visible=!0,this._viewportViews.forEach(i=>{i.render(e)}),e.visible=s,this._renderer.setViewport(n.x,n.y,n.z,n.w),this._renderer.autoClear=t}}}class rd{constructor(){this._activeLayoutBtrId="",this._layoutViews=new Map}get activeLayoutBtrId(){return this._activeLayoutBtrId}set activeLayoutBtrId(e){this._activeLayoutBtrId=e,this._layoutViews.forEach(t=>{t.enabled=t.layoutBtrId==e})}get activeLayoutView(){return this._layoutViews.get(this._activeLayoutBtrId)}has(e){return this._layoutViews.has(e)}getAt(e){return this._layoutViews.get(e)}resize(e,t){this._layoutViews.forEach(n=>{n.resize(e,t)})}add(e){this._layoutViews.set(e.layoutBtrId,e)}render(e){var t;(t=this.activeLayoutView)==null||t.render(e)}}function Ji(r,e,t=0,n=r.length-1,s=sd){for(;n>t;){if(n-t>600){const c=n-t+1,h=e-t+1,l=Math.log(c),d=.5*Math.exp(2*l/3),u=.5*Math.sqrt(l*d*(c-d)/c)*(h-c/2<0?-1:1),p=Math.max(t,Math.floor(e-h*d/c+u)),f=Math.min(n,Math.floor(e+(c-h)*d/c+u));Ji(r,e,p,f,s)}const i=r[e];let o=t,a=n;for(Ot(r,t,e),s(r[n],i)>0&&Ot(r,t,n);o<a;){for(Ot(r,o,a),o++,a--;s(r[o],i)<0;)o++;for(;s(r[a],i)>0;)a--}s(r[t],i)===0?Ot(r,t,a):(a++,Ot(r,a,n)),a<=e&&(t=a+1),e<=a&&(n=a-1)}}function Ot(r,e,t){const n=r[e];r[e]=r[t],r[t]=n}function sd(r,e){return r<e?-1:r>e?1:0}class id{constructor(e=9){this._maxEntries=Math.max(4,e),this._minEntries=Math.max(2,Math.ceil(this._maxEntries*.4)),this.clear()}all(){return this._all(this.data,[])}search(e){let t=this.data;const n=[];if(!pn(e,t))return n;const s=this.toBBox,i=[];for(;t;){for(let o=0;o<t.children.length;o++){const a=t.children[o],c=t.leaf?s(a):a;pn(e,c)&&(t.leaf?n.push(a):yr(e,c)?this._all(a,n):i.push(a))}t=i.pop()}return n}collides(e){let t=this.data;if(!pn(e,t))return!1;const n=[];for(;t;){for(let s=0;s<t.children.length;s++){const i=t.children[s],o=t.leaf?this.toBBox(i):i;if(pn(e,o)){if(t.leaf||yr(e,o))return!0;n.push(i)}}t=n.pop()}return!1}load(e){if(!(e&&e.length))return this;if(e.length<this._minEntries){for(let n=0;n<e.length;n++)this.insert(e[n]);return this}let t=this._build(e.slice(),0,e.length-1,0);if(!this.data.children.length)this.data=t;else if(this.data.height===t.height)this._splitRoot(this.data,t);else{if(this.data.height<t.height){const n=this.data;this.data=t,t=n}this._insert(t,this.data.height-t.height-1,!0)}return this}insert(e){return e&&this._insert(e,this.data.height-1),this}clear(){return this.data=ut([]),this}remove(e,t){if(!e)return this;let n=this.data;const s=this.toBBox(e),i=[],o=[];let a,c,h;for(;n||i.length;){if(n||(n=i.pop(),c=i[i.length-1],a=o.pop(),h=!0),n.leaf){const l=od(e,n.children,t);if(l!==-1)return n.children.splice(l,1),i.push(n),this._condense(i),this}!h&&!n.leaf&&yr(n,s)?(i.push(n),o.push(a),a=0,c=n,n=n.children[0]):c?(a++,n=c.children[a],h=!1):n=null}return this}toBBox(e){return e}compareMinX(e,t){return e.minX-t.minX}compareMinY(e,t){return e.minY-t.minY}toJSON(){return this.data}fromJSON(e){return this.data=e,this}_all(e,t){const n=[];for(;e;)e.leaf?t.push(...e.children):n.push(...e.children),e=n.pop();return t}_build(e,t,n,s){const i=n-t+1;let o=this._maxEntries,a;if(i<=o)return a=ut(e.slice(t,n+1)),lt(a,this.toBBox),a;s||(s=Math.ceil(Math.log(i)/Math.log(o)),o=Math.ceil(i/Math.pow(o,s-1))),a=ut([]),a.leaf=!1,a.height=s;const c=Math.ceil(i/o),h=c*Math.ceil(Math.sqrt(o));Ki(e,t,n,h,this.compareMinX);for(let l=t;l<=n;l+=h){const d=Math.min(l+h-1,n);Ki(e,l,d,c,this.compareMinY);for(let u=l;u<=d;u+=c){const p=Math.min(u+c-1,d);a.children.push(this._build(e,u,p,s-1))}}return lt(a,this.toBBox),a}_chooseSubtree(e,t,n,s){for(;s.push(t),!(t.leaf||s.length-1===n);){let i=1/0,o=1/0,a;for(let c=0;c<t.children.length;c++){const h=t.children[c],l=mr(h),d=hd(e,h)-l;d<o?(o=d,i=l<i?l:i,a=h):d===o&&l<i&&(i=l,a=h)}t=a||t.children[0]}return t}_insert(e,t,n){const s=n?e:this.toBBox(e),i=[],o=this._chooseSubtree(s,this.data,t,i);for(o.children.push(e),Rt(o,s);t>=0&&i[t].children.length>this._maxEntries;)this._split(i,t),t--;this._adjustParentBBoxes(s,i,t)}_split(e,t){const n=e[t],s=n.children.length,i=this._minEntries;this._chooseSplitAxis(n,i,s);const o=this._chooseSplitIndex(n,i,s),a=ut(n.children.splice(o,n.children.length-o));a.height=n.height,a.leaf=n.leaf,lt(n,this.toBBox),lt(a,this.toBBox),t?e[t-1].children.push(a):this._splitRoot(n,a)}_splitRoot(e,t){this.data=ut([e,t]),this.data.height=e.height+1,this.data.leaf=!1,lt(this.data,this.toBBox)}_chooseSplitIndex(e,t,n){let s,i=1/0,o=1/0;for(let a=t;a<=n-t;a++){const c=Dt(e,0,a,this.toBBox),h=Dt(e,a,n,this.toBBox),l=ld(c,h),d=mr(c)+mr(h);l<i?(i=l,s=a,o=d<o?d:o):l===i&&d<o&&(o=d,s=a)}return s||n-t}_chooseSplitAxis(e,t,n){const s=e.leaf?this.compareMinX:ad,i=e.leaf?this.compareMinY:cd,o=this._allDistMargin(e,t,n,s),a=this._allDistMargin(e,t,n,i);o<a&&e.children.sort(s)}_allDistMargin(e,t,n,s){e.children.sort(s);const i=this.toBBox,o=Dt(e,0,t,i),a=Dt(e,n-t,n,i);let c=dn(o)+dn(a);for(let h=t;h<n-t;h++){const l=e.children[h];Rt(o,e.leaf?i(l):l),c+=dn(o)}for(let h=n-t-1;h>=t;h--){const l=e.children[h];Rt(a,e.leaf?i(l):l),c+=dn(a)}return c}_adjustParentBBoxes(e,t,n){for(let s=n;s>=0;s--)Rt(t[s],e)}_condense(e){for(let t=e.length-1,n;t>=0;t--)e[t].children.length===0?t>0?(n=e[t-1].children,n.splice(n.indexOf(e[t]),1)):this.clear():lt(e[t],this.toBBox)}}function od(r,e,t){if(!t)return e.indexOf(r);for(let n=0;n<e.length;n++)if(t(r,e[n]))return n;return-1}function lt(r,e){Dt(r,0,r.children.length,e,r)}function Dt(r,e,t,n,s){s||(s=ut(null)),s.minX=1/0,s.minY=1/0,s.maxX=-1/0,s.maxY=-1/0;for(let i=e;i<t;i++){const o=r.children[i];Rt(s,r.leaf?n(o):o)}return s}function Rt(r,e){return r.minX=Math.min(r.minX,e.minX),r.minY=Math.min(r.minY,e.minY),r.maxX=Math.max(r.maxX,e.maxX),r.maxY=Math.max(r.maxY,e.maxY),r}function ad(r,e){return r.minX-e.minX}function cd(r,e){return r.minY-e.minY}function mr(r){return(r.maxX-r.minX)*(r.maxY-r.minY)}function dn(r){return r.maxX-r.minX+(r.maxY-r.minY)}function hd(r,e){return(Math.max(e.maxX,r.maxX)-Math.min(e.minX,r.minX))*(Math.max(e.maxY,r.maxY)-Math.min(e.minY,r.minY))}function ld(r,e){const t=Math.max(r.minX,e.minX),n=Math.max(r.minY,e.minY),s=Math.min(r.maxX,e.maxX),i=Math.min(r.maxY,e.maxY);return Math.max(0,s-t)*Math.max(0,i-n)}function yr(r,e){return r.minX<=e.minX&&r.minY<=e.minY&&e.maxX<=r.maxX&&e.maxY<=r.maxY}function pn(r,e){return e.minX<=r.maxX&&e.minY<=r.maxY&&e.maxX>=r.minX&&e.maxY>=r.minY}function ut(r){return{children:r,height:1,leaf:!0,minX:1/0,minY:1/0,maxX:-1/0,maxY:-1/0}}function Ki(r,e,t,n,s){const i=[e,t];for(;i.length;){if(t=i.pop(),e=i.pop(),t-e<=n)continue;const o=e+Math.ceil((t-e)/n/2)*n;Ji(r,o,e,t,s),i.push(e,o,o,t)}}class ud{constructor(e){this._group=new Pu,this._name=e}get name(){return this._name}set name(e){this._name=e}get visible(){return this._group.visible}set visible(e){this._group.visible=e}get internalObject(){return this._group}get stats(){const e=this._group.stats;return{name:this._name,...e}}get entityCount(){return this._group.entityCount}rerenderPoints(e){this._group.rerenderPoints(e)}hasEntity(e){return this._group.hasEntity(e)}addEntity(e){this._group.addEntity(e)}isIntersectWith(e,t){return this._group.isIntersectWith(e,t)}remove(e){throw new Error("Not implemented yet!")}update(e){return this._group.add(e),!0}hover(e){e.forEach(t=>{this._group.hover(t)})}unhover(e){e.forEach(t=>{this._group.unhover(t)})}select(e){e.forEach(t=>{this._group.select(t)})}unselect(e){e.forEach(t=>{this._group.unselect(t)})}}class dd{constructor(){this._group=new g.Group,this._indexTree=new id,this._box=new g.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(e){this._group.visible=e}get entityCount(){let e=0;return this._layers.forEach(t=>e+=t.entityCount),e}get stats(){const e=[];let t=0,n=0,s=0,i=0,o=0;return this._layers.forEach(a=>{const c=a.stats;e.push(c),s+=c.line.indexed.geometrySize+c.line.nonIndexed.geometrySize,i+=c.mesh.indexed.geometrySize+c.mesh.nonIndexed.geometrySize,o+=c.point.indexed.geometrySize+c.point.nonIndexed.geometrySize,t+=c.summary.totalGeometrySize,n+=c.summary.totalMappingSize}),{layers:e,summary:{entityCount:this.entityCount,totalSize:{line:s,mesh:i,point:o,geometry:t,mapping:n}}}}clear(){return this._layers.forEach(e=>{this._group.remove(e.internalObject)}),this._layers.clear(),this._box.makeEmpty(),this._indexTree.clear(),this}rerenderPoints(e){this._layers.forEach(t=>{t.rerenderPoints(e)})}isIntersectWith(e,t){const n=this.getLayerByObjectId(e);return n&&n.isIntersectWith(e,t)}addEntity(e,t=!0){if(!e.objectId)throw new Error("Object id is required to add one entity!");if(!e.layerName)throw new Error("Layer name is required to add one entity!");const n=this._layers.get(e.layerName);if(!n)throw new Error(`layer '${e.layerName}' doesn't exist!`);n.addEntity(e);const s=e.box;return t&&this._box.union(s),this._indexTree.insert({minX:s.min.x,minY:s.min.y,maxX:s.max.x,maxY:s.max.y,id:e.objectId}),this}remove(e){for(const[t,n]of this._layers)if(n.remove(e))return!0;return!1}updateEntity(e){for(const[t,n]of this._layers)if(n.update(e))return!0;return!1}addLayer(e){const t=e.name;let n=this._layers.get(t);return n===void 0&&(n=new ud(t),n.visible=!(e.isFrozen||e.isOff),this._layers.set(t,n),this._group.add(n.internalObject)),e}updateLayer(e){const t=this._layers.get(e.name);return t&&(t.visible=!(e.isFrozen||e.isOff)),t}hover(e){e.forEach(t=>{const n=this.getLayerByObjectId(t);n&&n.hover([t])})}unhover(e){e.forEach(t=>{const n=this.getLayerByObjectId(t);n&&n.unhover([t])})}select(e){e.forEach(t=>{const n=this.getLayerByObjectId(t);n&&n.select([t])})}unselect(e){e.forEach(t=>{const n=this.getLayerByObjectId(t);n&&n.unselect([t])})}setSnapObject(e){this._snapPointsObject&&this._group.remove(this._snapPointsObject),this._snapPointsObject=e,this._group.add(e)}search(e){return this._indexTree.search({minX:e.min.x,minY:e.min.y,maxX:e.max.x,maxY:e.max.y})}getLayerByObjectId(e){for(const[t,n]of this._layers)if(n.hasEntity(e))return n}}class pd{constructor(){this._scene=new g.Scene,this._layers=new Map,this._layouts=new Map,this._activeLayoutBtrId="",this._modelSpaceBtrId=""}get layers(){return this._layers}get layouts(){return this._layouts}get box(){var e;return(e=this.activeLayout)==null?void 0:e.box}get internalScene(){return this._scene}get modelSpaceBtrId(){return this._modelSpaceBtrId}set modelSpaceBtrId(e){if(this._modelSpaceBtrId=e,!this._layouts.has(e))throw new Error(`[AcTrScene] No layout assiciated with the specified block table record id '${e}'!`)}get activeLayoutBtrId(){return this._activeLayoutBtrId}set activeLayoutBtrId(e){this._activeLayoutBtrId=e,this._layouts.forEach((t,n)=>{t.visible=e==n})}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 e=[];return this._layouts.forEach(t=>e.push(t.stats)),{layouts:e}}addEmptyLayout(e){const t=new dd;return this._layouts.set(e,t),this._scene.add(t.internalObject),t.visible=e==this._activeLayoutBtrId,this._layers.forEach(n=>{t.addLayer(n)}),t}clear(){return this._layouts.forEach(e=>{this._scene.remove(e.internalObject),e.clear()}),this._layouts.clear(),this._layers.clear(),this._scene.clear(),this}hover(e){return this.activeLayout?(this.activeLayout.hover(e),!0):!1}unhover(e){return this.activeLayout?(this.activeLayout.unhover(e),!0):!1}select(e){return this.activeLayout?(this.activeLayout.select(e),!0):!1}unselect(e){return this.activeLayout?(this.activeLayout.unselect(e),!0):!1}search(e){const t=this.activeLayout;return t?t==null?void 0:t.search(e):[]}addLayer(e){this._layers.set(e.name,e),this._layouts.forEach(t=>{t.addLayer(e)})}updateLayer(e){this._layers.set(e.name,e),this._layouts.forEach(t=>{t.updateLayer(e)})}addEntity(e,t=!0){const n=e.ownerId;if(n){let s=this._layouts.get(n);s||(s=this.addEmptyLayout(n)),s.addEntity(e,t)}else console.warn("[AcTrSecene] The owner id of one entity cannot be empty!");return this}remove(e){for(const[t,n]of this._layouts)if(n.remove(e))return!0;return!1}update(e){for(const[t,n]of this._layouts)if(n.updateEntity(e))return!0;return!1}setSnapObject(e){return this._layouts.forEach(t=>{t.setSnapObject(e)}),this}}const vr={background:0};class eo extends Er{constructor(e=vr){const t={...vr,...e},n=new g.WebGLRenderer({antialias:!0,alpha:!0,canvas:e.canvas});t.canvas==null&&(t.canvas=n.domElement),super(t.canvas),e.calculateSizeCallback&&this.setCalculateSizeCallback(e.calculateSizeCallback),n.setPixelRatio(Math.min(window.devicePixelRatio,2)),n.setSize(this.width,this.height),this._renderer=new Yu(n);const s=dt.instance.fontMapping;this._renderer.setFontMapping(s),this._renderer.events.fontNotFound.addEventListener(i=>{Ce.emit("font-not-found",{fontName:i.fontName,count:i.count??0})}),this._scene=this.createScene(),this._renderer.setClearColor(t.background||0),this._stats=this.createStats(dt.instance.isShowStats),dt.instance.events.modified.addEventListener(i=>{i.key=="isShowStats"&&this.toggleStatsVisibility(this._stats,i.value)}),this.canvas.addEventListener("click",()=>{this.mode==Ie.SELECTION&&this.select()}),document.addEventListener("keydown",i=>{i.code==="Escape"&&this.selectionSet.clear()}),_.acdbHostApplicationServices().layoutManager.events.layoutSwitched.addEventListener(i=>{this.activeLayoutBtrId=i.layout.blockTableRecordId}),this._missedImages=new Map,this._layoutViewManager=new rd,this.initialize(),this.onWindowResize(),this.animate(),this._isDirty=!0,this._numOfEntitiesToProcess=0}initialize(){this.setCursor(qe.Crosshair)}get mode(){const e=this.activeLayoutView;return e?e.mode:Ie.SELECTION}set mode(e){this.activeLayoutView.mode=e,this.editor.getPoint()}get renderer(){return this._renderer}get isDirty(){return this._isDirty}set isDirty(e){this._isDirty=e}get missedData(){return{fonts:this._renderer.missedFonts,images:this._missedImages}}get center(){return this.activeLayoutView.center}set center(e){this.activeLayoutView.center=e}get backgroundColor(){return this._renderer.getClearColor()}set backgroundColor(e){this._renderer.setClearColor(e),this._isDirty=!0}get modelSpaceBtrId(){return this._scene.modelSpaceBtrId}set modelSpaceBtrId(e){this._scene.modelSpaceBtrId=e}get activeLayoutBtrId(){return this._scene.activeLayoutBtrId}set activeLayoutBtrId(e){this._layoutViewManager.activeLayoutBtrId=e,this._scene.activeLayoutBtrId=e,this._isDirty=!0}get activeLayoutView(){return this._layoutViewManager.activeLayoutView}get stats(){return this._scene.stats}animate(){var e;requestAnimationFrame(this.animate.bind(this)),this._isDirty&&(this._layoutViewManager.render(this._scene),(e=this._stats)==null||e.update(),this._isDirty=!1)}cwcs2Wcs(e){const t=this.activeLayoutView;return t?t.cwcs2Wcs(e):new _.AcGePoint2d(e)}wcs2Cwcs(e){const t=this.activeLayoutView;return t?t.wcs2Cwcs(e):new _.AcGePoint2d(e)}zoomTo(e,t=1.1){this.activeLayoutView.zoomTo(e,t),this._isDirty=!0}rerenderPoints(e){const t=this._scene.activeLayout;t&&(t.rerenderPoints(e),this._isDirty=!0)}zoomToFit(e=0){new _r(()=>this._numOfEntitiesToProcess<=0,()=>{if(this._scene.box){const n=Qu.threeBox3dToGeBox2d(this._scene.box);this.zoomTo(n),this._isDirty=!0}},300,e).start()}pick(e){e==null&&(e=this.curPos);const t=[],n=this._scene.activeLayout;if(n){const s=this.activeLayoutView,i=s.pointToBox(e,this.selectionBoxSize),o=this._scene.search(i),a=Math.max(i.size.width/2,i.size.height/2),c=s.resetRaycaster(e,a);o.forEach(h=>{const l=h.id;n.isIntersectWith(l,c)&&t.push(l)})}return t}search(e){return this._scene.search(e)}select(e){const t=[];this.pick(e).forEach(s=>t.push(s)),t.length>0&&this.selectionSet.add(t)}selectByBox(e){const t=[];this._scene.search(e).forEach(s=>t.push(s.id)),this.selectionSet.add(t)}addLayer(e){this._scene.addLayer({name:e.name,isFrozen:e.isFrozen,isOff:e.isOff}),this._isDirty=!0}updateLayer(e){this._scene.updateLayer({name:e.name,isFrozen:e.isFrozen,isOff:e.isOff}),this._isDirty=!0}addEntity(e){const t=Array.isArray(e)?e:[e];this._numOfEntitiesToProcess+=t.length,setTimeout(async()=>{await this.batchConvert(t)})}removeEntity(e){this._scene.remove(e)}updateEntity(e){let t=[];Array.isArray(e)?t=e:t.push(e);for(let n=0;n<t.length;++n){const s=t[n],i=s.draw(this._renderer);i&&(i.objectId=s.objectId,i.ownerId=s.ownerId,i.layerName=s.layer,i.visible=s.visibility,this._scene.update(i))}this._isDirty=!0,setTimeout(()=>{this._isDirty=!0},100)}addLayout(e){this._scene.addEmptyLayout(e.blockTableRecordId),this.createLayoutViewIfNeeded(e.blockTableRecordId),this._isDirty=!0}clear(){this._scene.clear(),this._isDirty=!0,this._missedImages.clear(),this._renderer.clearMissedFonts()}highlight(e){this._isDirty=this._scene.select(e)}unhighlight(e){this._isDirty=this._scene.unselect(e)}onHover(e){this._isDirty=this._scene.hover([e])}onUnhover(e){this._isDirty=this._scene.unhover([e])}createScene(){const e=new pd;return e.layouts.forEach(t=>{t.setSnapObject(this.renderer.createObject())}),e}createStats(e){const t=new ho;document.body.appendChild(t.dom);const n=t.dom;return n.style.position="fixed",n.style.inset="unset",n.style.bottom="30px",n.style.right="0px",this.toggleStatsVisibility(t,e),t}onWindowResize(){super.onWindowResize(),this._renderer.setSize(this.width,this.height),this._layoutViewManager.resize(this.width,this.height),this._isDirty=!0}createLayoutViewIfNeeded(e){let t=this._layoutViewManager.getAt(e);return t==null&&(t=new nd(this._renderer,e,this.width,this.height),t.events.viewChanged.addEventListener(()=>{this._isDirty=!0}),this._layoutViewManager.add(t)),t}toggleStatsVisibility(e,t){t?e.dom.style.display="block":e.dom.style.display="none"}async batchConvert(e){for(let t=0;t<e.length;++t){const n=e[t],s=n.draw(this._renderer,!0);if(s){if(s.objectId=n.objectId,s.ownerId=n.ownerId,s.layerName=n.layer,s.visible=n.visibility,s instanceof sn&&!s.isOnTheSameLayer)this.handleGroup(s),this.decreaseNumOfEntitiesToProcess();else{const i=!(n instanceof _.AcDbRay||n instanceof _.AcDbXline);await s.draw().then(()=>{this._scene.addEntity(s,i),s.dispose(),this._isDirty=!0}).finally(()=>{this.decreaseNumOfEntitiesToProcess()})}if(n instanceof _.AcDbViewport){if(n.number>1){const i=this._layoutViewManager.getAt(n.ownerId);if(i){const o=new ln(i,n.toGiViewport(),this._renderer);i.addViewport(o)}}}else if(n instanceof _.AcDbRasterImage){const i=n.imageFileName;i&&this._missedImages.set(n.objectId,i)}}else this.decreaseNumOfEntitiesToProcess()}}handleGroup(e){const t=e.children,n=new Map;t.forEach(c=>{var l;const h=c.userData.layerName;n.has(h)||n.set(h,[]),(l=n.get(h))==null||l.push(c)});const s=e.styleManager,i=e.objectId,o=e.layerName,a=e.box;n.forEach((c,h)=>{const l=new ne(s);l.applyMatrix4(e.matrix),l.objectId=i,l.ownerId=e.ownerId,l.layerName=h==="0"?o:h,l.box=a,l.add(...c),this._scene.addEntity(l,!0),l.dispose()}),this._isDirty=!0}decreaseNumOfEntitiesToProcess(){this._numOfEntitiesToProcess--,this._numOfEntitiesToProcess<0&&(this._numOfEntitiesToProcess=0,console.warn("Something wrong! The number of entities to process should not be less than 0."))}}class fd{constructor(e){this._cadRenderer=e,this._avaiableFonts=[]}get avaiableFonts(){return this._avaiableFonts}async getAvaiableFonts(){if(this._avaiableFonts.length==0){const e="https://cdn.jsdelivr.net/gh/mlight-lee/cad-data/fonts/",t=e+"fonts.json";try{const n=await fetch(t);this._avaiableFonts=await n.json()}catch{Ce.emit("failed-to-get-avaiable-fonts",{url:t})}this._avaiableFonts.forEach(n=>{n.url=e+n.file})}return this._avaiableFonts}async load(e){await this.getAvaiableFonts();const t=[];e.forEach(s=>{const i=s.toLowerCase(),o=gn.find(this._avaiableFonts,a=>gn.findIndex(a.name,c=>c.toLowerCase()==i)>=0);o&&t.push(o.url)}),(await this._cadRenderer.loadFonts(t)).forEach(s=>{s.status||Ce.emit("font-not-loaded",{fontName:s.fontName,url:s.url})})}}class le{constructor(e){this.events={documentCreated:new _.AcCmEventManager,documentActivated:new _.AcCmEventManager};const t=new Ar;t.database.events.openProgress.addEventListener(i=>{Ce.emit("open-file-progress",{database:t.database,percentage:i.percentage,stage:i.stage,subStage:i.subStage,subStageStatus:i.subStageStatus,data:i.data})});const n=()=>({width:window.innerWidth,height:window.innerHeight-30}),s=new eo({canvas:e,calculateSizeCallback:n});this._context=new Sr(s,t),this._fontLoader=new fd(s.renderer),_.acdbHostApplicationServices().workingDatabase=t.database,this.registerCommands()}static createInstance(e){return le._instance==null&&(le._instance=new le(e)),this._instance}static get instance(){return le._instance||(le._instance=new le),le._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(e){await this._fontLoader.load(e)}async loadDefaultFonts(e){e==null?await this._fontLoader.load(["simkai"]):await this._fontLoader.load(e)}async openUrl(e,t){this.onBeforeOpenDocument(),t=this.setOptions(t);const n=await this.context.doc.openUri(e,t);return this.onAfterOpenDocument(n),n}async openDocument(e,t,n){this.onBeforeOpenDocument(),n=this.setOptions(n);const s=await this.context.doc.openDocument(e,t,n);return this.onAfterOpenDocument(s),s}registerCommands(){const e=ce.instance;e.addCommand(ce.SYSTEMT_COMMAND_GROUP_NAME,"pan","pan",new Ur),e.addCommand(ce.SYSTEMT_COMMAND_GROUP_NAME,"select","select",new Or),e.addCommand(ce.SYSTEMT_COMMAND_GROUP_NAME,"zoom","zoom",new Dr),e.addCommand(ce.SYSTEMT_COMMAND_GROUP_NAME,"zoomw","zoomw",new Fr),e.addCommand(ce.SYSTEMT_COMMAND_GROUP_NAME,"csvg","csvg",new Br),e.addCommand(ce.SYSTEMT_COMMAND_GROUP_NAME,"qnew","qnew",new Mr),e.addCommand(ce.SYSTEMT_COMMAND_GROUP_NAME,"open","open",new Lr)}sendStringToExecute(e){const n=ce.instance.lookupGlobalCmd(e);n==null||n.execute(this.context)}setActiveLayout(){const e=this.curView;e.activeLayoutBtrId=this.curDocument.database.currentSpaceId,e.modelSpaceBtrId=this.curDocument.database.currentSpaceId}onBeforeOpenDocument(){this.curView.clear()}onAfterOpenDocument(e){if(e){const t=this.context.doc;this.events.documentActivated.dispatch({doc:t}),this.setActiveLayout();const n=t.database;n.extents.isEmpty()?this.curView.zoomToFit():this.curView.zoomTo(new _.AcGeBox2d(n.extmin,n.extmax))}}setOptions(e){return e==null?e={fontLoader:this._fontLoader}:e.fontLoader==null&&(e.fontLoader=this._fontLoader),e}}class to{convert(e){const t=this.createEntity(e);return t&&this.processCommonAttrs(e,t),t}createEntity(e){return e.type=="3DFACE"?this.convertFace(e):e.type=="ARC"?this.convertArc(e):e.type=="CIRCLE"?this.convertCirle(e):e.type=="DIMENSION"?this.convertDimension(e):e.type=="ELLIPSE"?this.convertEllipse(e):e.type=="HATCH"?this.convertHatch(e):e.type=="IMAGE"?this.convertImage(e):e.type=="LEADER"?this.convertLeader(e):e.type=="LINE"?this.convertLine(e):e.type=="LWPOLYLINE"?this.convertLWPolyline(e):e.type=="MTEXT"?this.convertMText(e):e.type=="POINT"?this.convertPoint(e):e.type=="POLYLINE"?this.convertPolyline(e):e.type=="RAY"?this.convertRay(e):e.type=="SPLINE"?this.convertSpline(e):e.type=="ACAD_TABLE"?this.convertTable(e):e.type=="TEXT"?this.convertText(e):e.type=="SOLID"?this.convertSolid(e):e.type=="VIEWPORT"?this.convertViewport(e):e.type=="WIPEOUT"?this.convertWipeout(e):e.type=="XLINE"?this.convertXline(e):e.type=="INSERT"?this.convertBlockReference(e):null}convertFace(e){const t=new _.AcDbFace;return e.corner1&&t.setVertexAt(0,e.corner1),e.corner2&&t.setVertexAt(1,e.corner2),e.corner3&&t.setVertexAt(2,e.corner3),e.corner4&&t.setVertexAt(3,e.corner4),t.setEdgeInvisibilities(e.flag),t}convertArc(e){return new _.AcDbArc(e.center,e.radius,e.startAngle,e.endAngle)}convertCirle(e){return new _.AcDbCircle(e.center,e.radius)}convertEllipse(e){const t=new _.AcGeVector3d(e.majorAxisEndPoint),n=t.length();return new _.AcDbEllipse(e.center,e.extrusionDirection??_.AcGeVector3d.Z_AXIS,t,n,n*e.axisRatio,e.startAngle,e.endAngle)}convertLine(e){const t=e.startPoint,n=e.endPoint;return new _.AcDbLine(new _.AcGePoint3d(t.x,t.y,t.z),new _.AcGePoint3d(n.x,n.y,n.z))}convertSpline(e){return e.numberOfControlPoints>0&&e.numberOfKnots>0?new _.AcDbSpline(e.controlPoints,e.knots,e.weights,e.degree,!!(e.flag&1)):e.numberOfFitPoints>0?new _.AcDbSpline(e.fitPoints,"Uniform",e.degree,!!(e.flag&1)):null}convertPoint(e){const t=new _.AcDbPoint;return t.position=e.position,t}convertSolid(e){const t=new _.AcDbTrace;return t.setPointAt(0,{...e.corner1,z:0}),t.setPointAt(1,{...e.corner2,z:0}),t.setPointAt(2,{...e.corner3,z:0}),t.setPointAt(3,e.corner4?{...e.corner4,z:0}:{...e.corner3,z:0}),t.thickness=e.thickness,t}convertLWPolyline(e){const t=new _.AcDbPolyline;return t.closed=!!(e.flag&512),e.vertices.forEach((n,s)=>{t.addVertexAt(s,new _.AcGePoint2d(n.x,n.y),n.bulge,n.startWidth,n.endWidth)}),t}convertPolyline(e){const t=new _.AcDbPolyline;return t.closed=!!(e.flag&1),e.vertices.forEach((n,s)=>{t.addVertexAt(s,new _.AcGePoint2d(n.x,n.y),n.bulge,n.startWidth,n.endWidth)}),t}convertHatch(e){var t;const n=new _.AcDbHatch;return(t=e.definitionLines)==null||t.forEach(s=>{n.definitionLines.push({angle:s.angle,origin:s.base,delta:s.offset,dashPattern:s.numberOfDashLengths>0?s.dashLengths:[]})}),n.hatchStyle=e.hatchStyle,n.patternName=e.patternName,n.patternType=e.patternType,n.patternAngle=e.patternAngle==null?0:e.patternAngle,n.patternScale=e.patternScale==null?0:e.patternScale,e.boundaryPaths.forEach(s=>{if(s.boundaryPathTypeFlag&2){const i=s,o=new _.AcGePolyline2d;o.closed=i.isClosed,i.vertices.forEach((a,c)=>{o.addVertexAt(c,{x:a.x,y:a.y,bulge:a.bulge})}),n.add(o)}else{const i=s,o=new _.AcGeLoop2d;i.edges.forEach(a=>{if(a.type==1){const c=a;o.add(new _.AcGeLine2d(c.start,c.end))}else if(a.type==2){const c=a;o.add(new _.AcGeCircArc2d(c.center,c.radius,c.startAngle,c.endAngle,!c.isCCW))}else if(a.type==3){const c=a;new _.AcGeVector2d().subVectors(c.end,c.center);const h=Math.sqrt(Math.pow(c.end.x,2)+Math.pow(c.end.y,2)),l=h*c.lengthOfMinorAxis;let d=c.startAngle,u=c.endAngle;const p=Math.atan2(c.end.y,c.end.x);c.isCCW||(d=Math.PI*2-d,u=Math.PI*2-u),o.add(new _.AcGeEllipseArc2d({...c.center,z:0},h,l,d,u,!c.isCCW,p))}else if(a.type==4){const c=a;if(c.numberOfControlPoints>0&&c.numberOfKnots>0){const h=c.controlPoints.map(u=>({x:u.x,y:u.y,z:0}));let l=!0;const d=c.controlPoints.map(u=>(u.weight==null&&(l=!1),u.weight||1));o.add(new _.AcGeSpline3d(h,c.knots,l?d:void 0))}else if(c.numberOfFitData>0){const h=c.fitDatum.map(l=>({x:l.x,y:l.y,z:0}));o.add(new _.AcGeSpline3d(h,"Uniform"))}}}),n.add(o)}}),n}convertTable(e){const t=new _.AcDbTable(e.name,e.rowCount,e.columnCount);return t.attachmentPoint=e.attachmentPoint,t.position.copy(e.startPoint),e.columnWidthArr.forEach((n,s)=>t.setColumnWidth(s,n)),e.rowHeightArr.forEach((n,s)=>t.setRowHeight(s,n)),e.cells.forEach((n,s)=>{t.setCell(s,n)}),t}convertText(e){const t=new _.AcDbText;return t.textString=e.text,t.styleName=e.styleName,t.height=e.textHeight,t.position.copy(e.startPoint),t.rotation=e.rotation,t.oblique=e.obliqueAngle??0,t.thickness=e.thickness,t.horizontalMode=e.halign,t.verticalMode=e.valign,t.widthFactor=e.xScale??1,t}convertMText(e){const t=new _.AcDbMText;return t.contents=e.text,e.styleName!=null&&(t.styleName=e.styleName),t.height=e.textHeight,t.width=e.rectWidth,t.rotation=e.rotation||0,t.location=e.insertionPoint,t.attachmentPoint=e.attachmentPoint,e.direction&&(t.direction=new _.AcGeVector3d(e.direction)),t.drawingDirection=e.drawingDirection,t}convertLeader(e){const t=new _.AcDbLeader;return e.vertices.forEach(n=>{t.appendVertex(n)}),t.hasArrowHead=e.isArrowheadEnabled,t.hasHookLine=e.isHooklineExists,t.isSplined=e.isSpline,t.dimensionStyle=e.styleName,t.annoType=e.leaderCreationFlag,t}convertDimension(e){if(e.subclassMarker=="AcDbAlignedDimension"||e.subclassMarker=="AcDbRotatedDimension"){const t=e,n=new _.AcDbAlignedDimension(t.subDefinitionPoint1,t.subDefinitionPoint2,t.definitionPoint);return n.rotation=t.rotationAngle,this.processDimensionCommonAttrs(e,n),n}else if(e.subclassMarker=="AcDb3PointAngularDimension"){const t=e,n=new _.AcDb3PointAngularDimension(t.centerPoint,t.subDefinitionPoint1,t.subDefinitionPoint2,t.definitionPoint);return this.processDimensionCommonAttrs(e,n),n}else if(e.subclassMarker=="AcDbOrdinateDimension"){const t=e,n=new _.AcDbOrdinateDimension(t.subDefinitionPoint1,t.subDefinitionPoint2);return this.processDimensionCommonAttrs(e,n),n}else if(e.subclassMarker=="AcDbRadialDimension"){const t=e,n=new _.AcDbRadialDimension(t.definitionPoint,t.centerPoint,t.leaderLength);return this.processDimensionCommonAttrs(e,n),n}else if(e.subclassMarker=="AcDbDiametricDimension"){const t=e,n=new _.AcDbDiametricDimension(t.definitionPoint,t.centerPoint,t.leaderLength);return this.processDimensionCommonAttrs(e,n),n}return null}processImage(e,t){t.position.copy(e.position),t.brightness=e.brightness,t.contrast=e.contrast,t.fade=e.fade,t.imageDefId=e.imageDefHandle.toString(),t.isClipped=e.clipping>0,t.isShownClipped=(e.flags|4)>0,t.isImageShown=(e.flags|3)>0,t.isImageTransparent=(e.flags|8)>0,e.clippingBoundaryPath.forEach(n=>{t.clipBoundary.push(new _.AcGePoint2d(n))}),t.clipBoundaryType=e.clippingBoundaryType,t.width=Math.sqrt(e.uPixel.x**2+e.uPixel.y**2+e.uPixel.z**2)*e.imageSize.x,t.height=Math.sqrt(e.vPixel.x**2+e.vPixel.y**2+e.vPixel.z**2)*e.imageSize.y,t.rotation=Math.atan2(e.uPixel.y,e.uPixel.x)}convertImage(e){const t=new _.AcDbRasterImage;return this.processImage(e,t),t}convertWipeout(e){const t=new _.AcDbWipeout;return this.processImage(e,t),t}convertViewport(e){const t=new _.AcDbViewport;return t.number=e.viewportId,t.centerPoint.copy(e.viewportCenter),t.height=e.height,t.width=e.width,t.viewCenter.copy(e.displayCenter),t.viewHeight=e.viewHeight,t}convertRay(e){const t=new _.AcDbRay;return t.basePoint.copy(e.firstPoint),t.unitDir.copy(e.unitDirection),t}convertXline(e){const t=new _.AcDbXline;return t.basePoint.copy(e.firstPoint),t.unitDir.copy(e.unitDirection),t}convertBlockReference(e){const t=new _.AcDbBlockReference(e.name);return e.insertionPoint&&t.position.copy(e.insertionPoint),t.scaleFactors.x=e.xScale,t.scaleFactors.y=e.yScale,t.scaleFactors.z=e.zScale,t.rotation=e.rotation,t.normal.copy(e.extrusionDirection),t}processDimensionCommonAttrs(e,t){t.dimBlockId=e.name,t.textPosition.copy(e.textPoint),t.textRotation=e.textRotation||0,e.textLineSpacingFactor&&(t.textLineSpacingFactor=e.textLineSpacingFactor),e.textLineSpacingStyle&&(t.textLineSpacingStyle=e.textLineSpacingStyle),t.dimensionStyleName=e.styleName,t.dimensionText=e.text||"",t.measurement=e.measurement}processCommonAttrs(e,t){t.layer=e.layer||"0",t.objectId=e.handle.toString(),t.ownerId=e.ownerBlockRecordSoftId.toString(),e.lineType!=null&&(t.lineType=e.lineType),e.lineweight!=null&&(t.lineWeight=e.lineweight),e.lineTypeScale!=null&&(t.linetypeScale=e.lineTypeScale),e.color!=null&&(t.color.color=e.color),e.colorIndex!=null&&(t.color.colorIndex=e.colorIndex),e.colorName!=null&&(t.color.colorName=e.colorName),e.isVisible!=null&&(t.visibility=e.isVisible),e.transparency!=null&&(t.transparency=e.transparency)}}class gd extends _.AcDbDatabaseConverter{constructor(e={}){super(e),e.useWorker=!0,e.parserWorkerUrl||(e.parserWorkerUrl="/assets/libredwg-parser-worker.js")}async parse(e){if(this.config.useWorker&&this.config.parserWorkerUrl){const t=_.createWorkerApi({workerUrl:this.config.parserWorkerUrl,maxConcurrentWorkers:1}),n=await t.execute(e);return t.destroy(),n.data}else throw new Error("dwg converter can run in web worker only!")}getFonts(e){const t=new Map;e.tables.BLOCK_RECORD.entries.forEach(o=>{t.set(o.name,o)});const n=new Map,s=o=>{if(o){const a=o.lastIndexOf(".");return a>=0?o.substring(0,a).toLowerCase():o.toLowerCase()}};e.tables.STYLE.entries.forEach(o=>{const a=[];let c=s(o.font);c&&a.push(c),c=s(o.bigFont),c&&a.push(c),n.set(o.name,a)});const i=new Set;return this.getFontsInBlock(e.entities,t,n,i),Array.from(i)}getFontsInBlock(e,t,n,s){const i=/\\f(.*?)\|/g;e.forEach(o=>{if(o.type=="MTEXT"){const a=o;[...a.text.matchAll(i)].forEach(h=>{s.add(h[1].toLowerCase())});const c=n.get(a.styleName);c==null||c.forEach(h=>s.add(h))}else if(o.type=="TEXT"){const a=o,c=n.get(a.styleName);c==null||c.forEach(h=>s.add(h))}else if(o.type=="INSERT"){const a=o,c=t.get(a.name);c&&this.getFontsInBlock(c.entities,t,n,s)}})}processLineTypes(e,t){e.tables.LTYPE.entries.forEach(n=>{const s={name:n.name,description:n.description,standardFlag:n.standardFlag,totalPatternLength:n.totalPatternLength,pattern:n.pattern},i=new _.AcDbLinetypeTableRecord(s);this.processCommonTableEntryAttrs(n,i),i.name=n.name,t.tables.linetypeTable.add(i)})}processTextStyles(e,t){e.tables.STYLE.entries.forEach(n=>{const s=new _.AcDbTextStyleTableRecord(n);this.processCommonTableEntryAttrs(n,s),t.tables.textStyleTable.add(s)})}processDimStyles(e,t){e.tables.DIMSTYLE.entries.forEach(n=>{const s={name:n.name,ownerId:n.ownerHandle.toString(),dimpost:n.DIMPOST||"",dimapost:n.DIMAPOST||"",dimscale:n.DIMSCALE,dimasz:n.DIMASZ,dimexo:n.DIMEXO,dimdli:n.DIMDLI,dimexe:n.DIMEXE,dimrnd:n.DIMRND,dimdle:n.DIMDLE,dimtp:n.DIMTP,dimtm:n.DIMTM,dimtxt:n.DIMTXT,dimcen:n.DIMCEN,dimtsz:n.DIMTSZ,dimaltf:n.DIMALTF,dimlfac:n.DIMLFAC,dimtvp:n.DIMTVP,dimtfac:n.DIMTFAC,dimgap:n.DIMGAP,dimaltrnd:n.DIMALTRND,dimtol:n.DIMTOL==null||n.DIMTOL==0?0:1,dimlim:n.DIMLIM==null||n.DIMLIM==0?0:1,dimtih:n.DIMTIH==null||n.DIMTIH==0?0:1,dimtoh:n.DIMTOH==null||n.DIMTOH==0?0:1,dimse1:n.DIMSE1==null||n.DIMSE1==0?0:1,dimse2:n.DIMSE2==null||n.DIMSE2==0?0:1,dimtad:n.DIMTAD,dimzin:n.DIMZIN,dimazin:n.DIMAZIN,dimalt:n.DIMALT,dimaltd:n.DIMALTD,dimtofl:n.DIMTOFL,dimsah:n.DIMSAH,dimtix:n.DIMTIX,dimsoxd:n.DIMSOXD,dimclrd:n.DIMCLRD,dimclre:n.DIMCLRE,dimclrt:n.DIMCLRT,dimadec:n.DIMADEC||0,dimunit:n.DIMUNIT||2,dimdec:n.DIMDEC,dimtdec:n.DIMTDEC,dimaltu:n.DIMALTU,dimalttd:n.DIMALTTD,dimaunit:n.DIMAUNIT,dimfrac:n.DIMFRAC,dimlunit:n.DIMLUNIT,dimdsep:n.DIMDSEP,dimtmove:n.DIMTMOVE||0,dimjust:n.DIMJUST,dimsd1:n.DIMSD1,dimsd2:n.DIMSD2,dimtolj:n.DIMTOLJ,dimtzin:n.DIMTZIN,dimaltz:n.DIMALTZ,dimalttz:n.DIMALTTZ,dimfit:n.DIMFIT||0,dimupt:n.DIMUPT,dimatfit:n.DIMATFIT,dimtxsty:"Standard",dimldrblk:"",dimblk:n.DIMBLK||"",dimblk1:n.DIMBLK1||"",dimblk2:n.DIMBLK2||"",dimlwd:n.DIMLWD,dimlwe:n.DIMLWE},i=new _.AcDbDimStyleTableRecord(s);this.processCommonTableEntryAttrs(n,i),t.tables.dimStyleTable.add(i)})}processLayers(e,t){e.tables.LAYER.entries.forEach(n=>{const s=new _.AcCmColor;s.colorIndex=n.colorIndex;const i=new _.AcDbLayerTableRecord({name:n.name,standardFlags:n.standardFlag,linetype:n.lineType,lineWeight:n.lineweight,isOff:n.off,color:s,isPlottable:n.plotFlag!=0});this.processCommonTableEntryAttrs(n,i),t.tables.layerTable.add(i)})}processViewports(e,t){e.tables.VPORT.entries.forEach(n=>{const s=new _.AcDbViewportTableRecord;this.processCommonTableEntryAttrs(n,s),n.circleSides&&(s.circleSides=n.circleSides),s.standardFlag=n.standardFlag,s.center.copy(n.center),s.lowerLeftCorner.copy(n.lowerLeftCorner),s.upperRightCorner.copy(n.upperRightCorner),n.snapBasePoint&&s.snapBase.copy(n.snapBasePoint),n.snapRotationAngle&&(s.snapAngle=n.snapRotationAngle),n.snapSpacing&&s.snapIncrements.copy(n.snapSpacing),n.majorGridLines&&(s.gridMajor=n.majorGridLines),n.gridSpacing&&s.gridIncrements.copy(n.gridSpacing),n.backgroundObjectId&&(s.backgroundObjectId=n.backgroundObjectId),s.gsView.center.copy(n.center),s.gsView.viewDirectionFromTarget.copy(n.viewDirectionFromTarget),s.gsView.viewTarget.copy(n.viewTarget),n.lensLength&&(s.gsView.lensLength=n.lensLength),n.frontClippingPlane&&(s.gsView.frontClippingPlane=n.frontClippingPlane),n.backClippingPlane&&(s.gsView.backClippingPlane=n.backClippingPlane),n.viewHeight&&(s.gsView.viewHeight=n.viewHeight),n.viewTwistAngle&&(s.gsView.viewTwistAngle=n.viewTwistAngle),n.frozenLayers&&(s.gsView.frozenLayers=n.frozenLayers),n.styleSheet&&(s.gsView.styleSheet=n.styleSheet),n.renderMode&&(s.gsView.renderMode=n.renderMode),n.viewMode&&(s.gsView.viewMode=n.viewMode),n.ucsIconSetting&&(s.gsView.ucsIconSetting=n.ucsIconSetting),n.ucsOrigin&&s.gsView.ucsOrigin.copy(n.ucsOrigin),n.ucsXAxis&&s.gsView.ucsXAxis.copy(n.ucsXAxis),n.ucsYAxis&&s.gsView.ucsYAxis.copy(n.ucsYAxis),n.orthographicType&&(s.gsView.orthographicType=n.orthographicType),n.shadePlotSetting&&(s.gsView.shadePlotSetting=n.shadePlotSetting),n.shadePlotObjectId&&(s.gsView.shadePlotObjectId=n.shadePlotObjectId),n.visualStyleObjectId&&(s.gsView.visualStyleObjectId=n.visualStyleObjectId),n.isDefaultLightingOn&&(s.gsView.isDefaultLightingOn=n.isDefaultLightingOn),n.defaultLightingType&&(s.gsView.defaultLightingType=n.defaultLightingType),n.brightness&&(s.gsView.brightness=n.brightness),n.contrast&&(s.gsView.contrast=n.contrast),n.ambientColor&&(s.gsView.ambientColor=n.ambientColor),t.tables.viewportTable.add(s)})}processBlockTables(e,t){e.tables.BLOCK_RECORD.entries.forEach(n=>{let s=t.tables.blockTable.getAt(n.name);s||(s=new _.AcDbBlockTableRecord,s.objectId=n.handle.toString(),s.name=n.name,s.ownerId=n.ownerHandle.toString(),s.origin.copy(n.basePoint),s.layoutId=n.layout.toString(),t.tables.blockTable.add(s)),!s.isModelSapce&&!s.isPaperSapce&&n.entities&&n.entities.length>0&&this.processEntitiesInBlock(n.entities,s)})}processBlocks(e,t){}async processEntitiesInBlock(e,t){const n=new to,s=e.length,i=[];for(let o=0;o<s;o++){const a=e[o],c=n.convert(a);c&&i.push(c)}t.appendEntity(i)}async processEntities(e,t,n,s,i){const o=new to;let a=e.entities;const c=a.length,h=new _.AcDbBatchProcessing(c,100-s.value,n);this.config.convertByEntityType&&(a=this.groupAndFlattenByType(a));const l=t.tables.blockTable.modelSpace;await h.processChunk(async(d,u)=>{const p=[];for(let f=d;f<u;f++){const m=a[f],y=o.convert(m);y&&p.push(y)}if(l.appendEntity(p),i){let f=s.value+u/c*(100-s.value);f>100&&(f=100),await i(f,"ENTITY","IN-PROGRESS")}})}processHeader(e,t){const n=e.header;t.cecolor.colorIndex=n.CECOLOR||256,t.angBase=n.ANGBASE??0,t.angDir=n.ANGDIR??0,t.aunits=n.AUNITS??0,n.EXTMAX&&(t.extmax=n.EXTMAX),n.EXTMIN&&(t.extmin=n.EXTMIN),t.insunits=n.INSUNITS??1,t.pdmode=n.PDMODE??0,t.pdsize=n.PDSIZE??0}processCommonTableEntryAttrs(e,t){t.name=e.name,t.objectId=e.handle.toString(),t.ownerId=e.ownerHandle.toString()}processObjects(e,t){this.processLayouts(e,t),this.processImageDefs(e,t)}processLayouts(e,t){const n=t.dictionaries.layouts;e.objects.LAYOUT.forEach(s=>{const i=new _.AcDbLayout;i.layoutName=s.layoutName,i.tabOrder=s.tabOrder;const o=t.tables.blockTable.newIterator();i.objectId=s.handle.toString();for(const a of o)if(a.layoutId===i.objectId){i.blockTableRecordId=a.objectId;break}i.limits.min.copy(s.minLimit),i.limits.max.copy(s.maxLimit),i.extents.min.copy(s.minExtent),i.extents.max.copy(s.maxExtent),this.processCommonObjectAttrs(s,i),n.setAt(i.layoutName,i)})}processImageDefs(e,t){const n=t.dictionaries.imageDefs;e.objects.IMAGEDEF.forEach(s=>{const i=new _.AcDbRasterImageDef;i.sourceFileName=s.fileName,this.processCommonObjectAttrs(s,i),n.setAt(i.objectId,i)})}processCommonObjectAttrs(e,t){t.objectId=e.handle.toString(),t.ownerId=e.ownerHandle.toString()}groupAndFlattenByType(e){const t={},n=[];for(const s of e)t[s.type]||(t[s.type]=[],n.push(s.type)),t[s.type].push(s);return n.flatMap(s=>t[s])}}function no(){try{const r=new _.AcDbDxfConverter({convertByEntityType:!1,useWorker:!0,parserWorkerUrl:"./assets/dxf-parser-worker.js"});_.AcDbDatabaseConverterManager.instance.register(_.AcDbFileType.DXF,r)}catch(r){console.error("Failed to register dxf converter: ",r)}try{const r=new gd({convertByEntityType:!1,useWorker:!0,parserWorkerUrl:"./assets/libredwg-parser-worker.js"});_.AcDbDatabaseConverterManager.instance.register(_.AcDbFileType.DWG,r)}catch(r){console.error("Failed to register dwg converter: ",r)}}function md(){no(),typeof window<"u"&&!!window.location&&(window.location.hostname==="localhost"||window.location.hostname==="127.0.0.1")?on.getInstance().initialize("/assets/mtext-renderer-worker.js"):on.getInstance().initialize("./mtext-renderer-worker.js")}const yd={isDebug:!1,isShowCommandLine:!0,isShowCoordinate:!0,isShowToolbar:!0,isShowStats:!1,fontMapping:{}},ro="settings";class dt{constructor(){this.events={modified:new _.AcCmEventManager}}static get instance(){return this._instance||(this._instance=new dt),this._instance}set(e,t){const n=this.settings;n[e]=t,localStorage.setItem(ro,JSON.stringify(n)),this.events.modified.dispatch({key:e,value:t})}get(e){return this.settings[e]}toggle(e){const t=this.get(e);this.set(e,!t)}get isDebug(){return this.get("isDebug")}set isDebug(e){this.set("isDebug",e)}get isShowCommandLine(){return this.get("isShowCommandLine")}set isShowCommandLine(e){this.set("isShowCommandLine",e)}get isShowCoordinate(){return this.get("isShowCoordinate")}set isShowCoordinate(e){this.set("isShowCoordinate",e)}get isShowToolbar(){return this.get("isShowToolbar")}set isShowToolbar(e){this.set("isShowToolbar",e)}get isShowStats(){return this.get("isShowStats")}set isShowStats(e){this.set("isShowStats",e)}get fontMapping(){return this.get("fontMapping")}set fontMapping(e){this.set("fontMapping",e)}setFontMapping(e,t){const n=this.get("fontMapping");n[e]=t,this.set("fontMapping",n)}get settings(){const e=localStorage.getItem(ro),t=e==null?{}:JSON.parse(e);return gn.defaults(t,yd)}}v.AcApContext=Sr,v.AcApConvertToSvgCmd=Br,v.AcApDocManager=le,v.AcApDocument=Ar,v.AcApOpenCmd=Lr,v.AcApPanCmd=Ur,v.AcApQNewCmd=Mr,v.AcApSelectCmd=Or,v.AcApSettingManager=dt,v.AcApZoomCmd=Dr,v.AcApZoomToBoxCmd=Fr,v.AcApZoomToBoxJig=Rr,v.AcEdBaseView=Er,v.AcEdCommand=Be,v.AcEdCommandStack=ce,v.AcEdConditionWaiter=_r,v.AcEdCorsorType=qe,v.AcEdCursorManager=Tr,v.AcEdJig=Cr,v.AcEdSelectionSet=kr,v.AcEdViewMode=Ie,v.AcEditor=Ir,v.AcTrView2d=eo,v.DEFAULT_VIEW_2D_OPTIONS=vr,v.acedAlert=fo,v.eventBus=Ce,v.registerConverters=no,v.registerWorkers=md,Object.defineProperty(v,Symbol.toStringTag,{value:"Module"})});
|
|
284
|
+
}`;return new g.ShaderMaterial({uniforms:c,vertexShader:h,fragmentShader:l,clipping:!0})}}const hn=class Ft{constructor(){this.pointMaterials={},this.lineShaderMaterials={},this.lineBasicMaterials={},this.hatchShaderMaterials=[],this.meshBasicMaterials={},this.unsupportedTextStyles={}}getPointsMaterial(e,t=2){const n=`${e}_${t}`;return this.pointMaterials[n]||(this.pointMaterials[n]=new g.PointsMaterial({size:t,color:e})),this.pointMaterials[n]}getMeshBasicMaterial(e){return this.meshBasicMaterials[e]||(this.meshBasicMaterials[e]=new g.MeshBasicMaterial({color:e})),this.meshBasicMaterials[e]}getLineBasicMaterial(e){return this.lineBasicMaterials[e]||(this.lineBasicMaterials[e]=new g.LineBasicMaterial({color:e})),this.lineBasicMaterials[e]}getLineShaderMaterial(e,t){if(e.pattern&&e.pattern.length!==0){const n=`${e.name}_${e.color}_${t}`;return this.lineShaderMaterials[n]||(this.lineShaderMaterials[n]=qu.createLineShaderMaterial(e.pattern,e.color,t,Ft.ViewportScaleUniform,Ft.CameraZoomUniform)),this.lineShaderMaterials[n]}else return this.getLineBasicMaterial(e.color)}getHatchShaderMaterial(e,t){if(!e.patternLines||e.patternLines.length<1)return this.getMeshBasicMaterial(e.color);let n=!1;if(e.patternLines.forEach(u=>{u.dashPattern||(n=!0,console.log("Invalid dash pattern: ",e))}),n)return;const s=this.findMatchedHatchShaderMaterial(e);if(s)return s;const i=.005,o=.05;let a=2;e.patternLines.forEach(u=>{a=Math.max(u.dashPattern.length,a)});let c=0;const h=[],l=new g.Vector2;for(const u of e.patternLines){const p=new g.Vector2(u.origin.x,u.origin.y).sub(t).rotateAround(l,-g.MathUtils.degToRad(e.patternAngle)),f=new g.Vector2(u.delta.x,u.delta.y).rotateAround(l,-g.MathUtils.degToRad(u.angle));if(f.y===0){console.warn("delta.y is equal to zero!");return}const m=u.dashPattern.length;let y=!0,b=0;for(let I=0;I<m;++I){const E=u.dashPattern[I];E>0&&(y=!1),b+=Math.abs(E)}const S=y?o:i,w=[],C=[];let T=0;C[0]=T;for(let I=0;I<m;++I)w[I]=u.dashPattern[I],w[I]===0&&(w[I]=S*b),T+=Math.abs(w[I]),C[I+1]=T;for(let I=m;I<a;++I)w[I]=0;for(let I=C.length;I<a+1;++I)C[I]=T;const D={origin:p,delta:f,angle:u.angle-e.patternAngle,pattern:w,patternSum:C,patternLength:T};if(c+=4,c+=a,c+=a+1,c>Ft.MaxFragmentUniforms){console.warn("There will be warning in fragment shader when number of uniforms exceeds 1024, so extra hatch line patterns are ignored here!");break}h.push(D)}const d=Xu(h,e.patternAngle,Ft.CameraZoomUniform,new g.Color(e.color));return d.defines={MAX_PATTERN_SEGMENT_COUNT:a},this.hatchShaderMaterials.push({patternLines:e.patternLines,patternAngle:e.patternAngle,color:e.color,material:d}),d}findMatchedHatchShaderMaterial(e){const t=e.patternLines;if(!t||t.length<1)return;const n=(c,h)=>Math.abs(c-h)<1e-5,s=(c,h)=>{if(c.length!==h.length)return!1;for(let l=0;l<c.length;++l)if(!n(c[l],h[l]))return!1;return!0},i=(c,h)=>n(c.angle,h.angle)&&n(c.delta.x,h.delta.x)&&n(c.delta.y,h.delta.y)&&n(c.origin.x,h.origin.x)&&n(c.origin.y,h.origin.y)&&s(c.dashPattern,h.dashPattern),o=(c,h)=>{if(c.length!==h.length)return!1;for(let l=0;l<c.length;++l)if(!i(c[l],h[l]))return!1;return!0},a=this.hatchShaderMaterials.find(c=>c.color===e.color&&c.patternAngle===e.patternAngle&&o(c.patternLines,t));return a==null?void 0:a.material}};hn.CameraZoomUniform={value:1},hn.ViewportScaleUniform={value:1},hn.MaxFragmentUniforms=1024;let $u=hn;class Yu{constructor(e){this.events={fontNotFound:new _.AcCmEventManager},this._renderer=e,this._styleManager=new $u,ee.instance.events.fontNotFound.addEventListener(t=>{this.events.fontNotFound.dispatch(t)})}get autoClear(){return this._renderer.autoClear}set autoClear(e){this._renderer.autoClear=e}get domElement(){return this._renderer.domElement}setSize(e,t){this._renderer.setSize(e,t)}getViewport(e){return this._renderer.getViewport(e)}setViewport(e,t,n,s){this._renderer.setViewport(e,t,n,s)}clear(){this._renderer.clear()}clearDepth(){this._renderer.clearDepth()}render(e,t){this._renderer.render(e,t.internalCamera)}setClearColor(e,t){this._renderer.setClearColor(e,t)}getClearColor(){const e=new g.Color;return this._renderer.getClearColor(e),e.getHex()}setClearAlpha(e){this._renderer.setClearAlpha(e)}getClearAlpha(){return this._renderer.getClearAlpha()}get internalRenderer(){return this._renderer}async loadFonts(e){return await ee.instance.loadFontsByUrls(e)}setFontMapping(e){ee.instance.setFontMapping(e)}get missedFonts(){return ee.instance.missedFonts}clearMissedFonts(){ee.instance.missedFonts={}}createObject(){return new Yi(this._styleManager)}createEntity(){return new ne(this._styleManager)}group(e){return new sn(e,this._styleManager)}point(e,t){return new Wu(e,t,this._styleManager)}circularArc(e,t){return this.linePoints(e.getPoints(100),t)}ellipticalArc(e,t){return this.linePoints(e.getPoints(100),t)}lines(e,t){return this.linePoints(e,t)}lineSegments(e,t,n,s){return new zu(e,t,n,s,this._styleManager)}area(e,t){return new ju(e,t,this._styleManager)}mtext(e,t,n){return new Vu(e,t,this._styleManager,n)}image(e,t){return new Gu(e,t,this._styleManager)}linePoints(e,t=void 0){return new Nu(e,t,this._styleManager)}}class Zu{constructor(e){this._camera=e}get position(){return this._camera.position}get left(){return this._camera.left}set left(e){this._camera.left=e}get right(){return this._camera.right}set right(e){this._camera.right=e}get top(){return this._camera.top}set top(e){this._camera.top=e}get bottom(){return this._camera.bottom}set bottom(e){this._camera.bottom=e}get zoom(){return this._camera.zoom}set zoom(e){this._camera.zoom=e}get internalCamera(){return this._camera}lookAt(e){this._camera.lookAt(e)}setRotationFromEuler(e){this._camera.setRotationFromEuler(e)}updateProjectionMatrix(){this._camera.updateProjectionMatrix()}cwcs2Wcs(e,t,n){const s=new g.Vector3(e.x,e.y,0);s.x=e.x/t*2-1,s.y=-(e.y/n)*2+1;const i=s.unproject(this._camera);return new _.AcGePoint2d(i.x,i.y)}wcs2Cwcs(e,t,n){const s=new g.Vector3(e.x,e.y,0).project(this._camera);return new _.AcGePoint2d((s.x+1)/2*t,(-s.y+1)/2*n)}wcs2Ndc(e,t,n){const s=this.wcs2Cwcs(e,t,n);return this.cwcs2Ndc(s,t,n)}cwcs2Ndc(e,t,n){return new _.AcGePoint2d(e.x/t*2-1,-(e.y/n)*2+1)}}class Qi{constructor(e,t,n){this._frustum=400,this.events={viewChanged:new _.AcCmEventManager},this._renderer=e,this._width=t,this._height=n;const s=this.createCamera();this._camera=new Zu(s),this._cameraControls=this.createCameraControls(),this._cameraControls.addEventListener("change",()=>{this.events.viewChanged.dispatch({view:this})}),this._raycaster=new g.Raycaster}get width(){return this._width}set width(e){this._width=e}get height(){return this._height}set height(e){this._height=e}get enabled(){return this._cameraControls.enabled}set enabled(e){this._cameraControls.enabled=e}get center(){return this._camera.cwcs2Wcs({x:this._width/2,y:this._height/2},this._width,this._height)}set center(e){this._camera.position.set(e.x,e.y,this._camera.position.z),this._camera.updateProjectionMatrix()}cwcs2Wcs(e){return this._camera.cwcs2Wcs(e,this._width,this._height)}wcs2Cwcs(e){return this._camera.wcs2Cwcs(e,this._width,this._height)}pointToBox(e,t){const n=this.wcs2Cwcs(e),s=this.cwcs2Wcs({x:n.x+t,y:n.y+t}),i=this.cwcs2Wcs({x:n.x-t,y:n.y-t});return new _.AcGeBox2d().setFromPoints([s,i])}resetRaycaster(e,t){const n=this._camera.wcs2Ndc(e,this._width,this._height);return this._raycaster.setFromCamera(new g.Vector2(n.x,n.y),this._camera.internalCamera),this._raycaster.params.Line.threshold=t,this._raycaster.params.Points.threshold=t,this._raycaster}zoomTo(e,t=1.1){const n=new _.AcGeVector2d;e.getSize(n);const s=new _.AcGeVector2d;e.getCenter(s);const i=new g.Vector3(s.x,s.y,0);this._camera.position.set(s.x,s.y,this._camera.position.z),this._camera.lookAt(i),this._camera.setRotationFromEuler(new g.Euler(0,0,0));const o=n.x*t,a=n.y*t,c=this._width/o,h=this._height/a;this._camera.zoom=Math.min(c,h),this._cameraControls.target=i,this.updateCameraFrustum()}updateCameraFrustum(e,t){const n=(e??this._width)/(t??this._height);this._camera.left=-n*this._frustum,this._camera.right=n*this._frustum,this._camera.top=this._frustum,this._camera.bottom=-this._frustum,this._camera.updateProjectionMatrix(),this._cameraControls.update()}createCamera(){const e=new g.OrthographicCamera(-this._width/2,this._width/2,this._height/2,-this._height/2,.1,1e3);return e.position.set(0,0,500),e.up.set(0,1,0),e.updateProjectionMatrix(),e}createCameraControls(){const e=new co.OrbitControls(this._camera.internalCamera,this._renderer.domElement);return e.enableDamping=!1,e.autoRotate=!1,e.enableRotate=!1,e.zoomSpeed=5,e.mouseButtons={MIDDLE:g.MOUSE.PAN},e.update(),e}}class ln extends Qi{static calculateViewportWindowBox(e,t){const n=t.box,s=new _.AcGeBox2d;return s.expandByPoint(e.wcs2Cwcs(n.min)),s.expandByPoint(e.wcs2Cwcs(n.max)),s}constructor(e,t,n){const s=ln.calculateViewportWindowBox(e,t).size;super(n,s.width,s.height),this._parentView=e,this._viewport=t.clone(),this._frustum*=t.height/e.height,this.zoomTo(this._viewport.viewBox),this.enabled=!1}get viewport(){return this._viewport}update(){this.zoomTo(this._viewport.viewBox)}render(e){const t=ln.calculateViewportWindowBox(this._parentView,this._viewport);if(!t.isEmpty()){const n=this._parentView.height-t.min.y-t.size.height;this._renderer.setViewport(t.min.x,n,t.size.width,t.size.height),this._renderer.internalRenderer.setScissor(t.min.x,n,t.size.width,t.size.height),this._renderer.internalRenderer.setScissorTest(!0),this._renderer.render(e,this._camera),this._renderer.internalRenderer.setScissorTest(!1)}}}const Qu={threeBo2dToGeBox2d:r=>new _.AcGeBox2d(r.min,r.max),geBox2dToThreeBox2d:r=>new g.Box2(r.min,r.max),threeBox3dToGeBox3d:r=>new _.AcGeBox3d(r.min,r.max),geBox3dToThreeBox3d:r=>new g.Box3(r.min,r.max),goBox3dToGeBox2d:r=>new _.AcGeBox2d(r.min,r.max),threeBox3dToGeBox2d:r=>new _.AcGeBox2d(r.min,r.max),geBox2dToThreeBox3d:r=>{const e=new g.Box3;return e.min.set(r.min.x,r.min.y,0),e.max.set(r.max.x,r.max.y,0),e}};var un=(r=>(r[r.LEFT_BOTTOM=0]="LEFT_BOTTOM",r[r.LEFT_TOP=1]="LEFT_TOP",r[r.RIGHT_TOP=2]="RIGHT_TOP",r[r.RIGHT_BOTTOM=4]="RIGHT_BOTTOM",r))(un||{});class Ju extends g.Object3D{constructor(e,t,n=150,s=2){super(),this.camera=e,this.renderer=t,this.gizmoCamera=new g.OrthographicCamera(-2,2,2,-2,0,4),this.gizmoCamera.position.set(0,0,2),this.gizmoDim=n,this.gizmoPos=s,this.initialize()}initialize(){}update(){this.updateOrientation();const e=this.renderer.autoClear;this.renderer.autoClear=!1,this.renderer.clearDepth();const t=new g.Vector4;this.renderer.getViewport(t);const n=this.calculateViewportPos();this.renderer.setViewport(n.x,n.y,this.gizmoDim,this.gizmoDim),this.renderer.render(this,this.gizmoCamera),this.renderer.setViewport(t.x,t.y,t.z,t.w),this.renderer.autoClear=e}dispose(){}updateOrientation(){this.quaternion.copy(this.camera.quaternion).invert(),this.updateMatrixWorld()}calculatePosInViewport(e,t,n){const s=(e-n.min.x)/this.gizmoDim*2-1,i=-((t-n.min.y)/this.gizmoDim)*2+1;return{x:s,y:i}}calculateViewportPos(){const e=this.renderer.domElement,t=e.offsetWidth,n=e.offsetHeight,s=this.gizmoPos,i=this.gizmoDim;let o=t-i,a=n-i;switch(s){case 0:o=0,a=0;break;case 1:o=0;break;case 4:a=0;break}return{x:o,y:a}}calculateViewportBbox(){const e=this.renderer.domElement,t=e.offsetWidth,n=e.offsetHeight,s=this.gizmoPos,i=this.gizmoDim,o=new g.Box2(new g.Vector2(t-i,0),new g.Vector2(t,i));switch(s){case 0:o.set(new g.Vector2(0,n-i),new g.Vector2(i,n));break;case 1:o.set(new g.Vector2(0,0),new g.Vector2(i,i));break;case 4:o.set(new g.Vector2(t-i,n-i),new g.Vector2(t,n));break}return o}}function Ku(r,e){const t=e.font||"Helvetica",n=e.fontSize||30,s=e.width||200,i=e.height||200,o=e.bgColor?e.bgColor.join(", "):"255, 255, 255, 1.0",a=e.color?e.color.join(", "):"0, 0, 0, 1.0",c=document.createElement("canvas");c.width=s,c.height=i;const h=c.getContext("2d");if(h){h.font=`bold ${n}px ${t}`,h.fillStyle=`rgba(${o})`,h.fillRect(0,0,s,i);const u=h.measureText(r).width;h.fillStyle=`rgba(${a})`,h.fillText(r,s/2-u/2,i/2+n/2-2)}const l=new g.Texture(c);return l.minFilter=g.LinearFilter,l.needsUpdate=!0,l}function gr(r){const e=Ku(r,{fontSize:100,font:"Arial Narrow, sans-serif",color:[255,255,255,1],bgColor:[0,0,0,0]}),t=new g.SpriteMaterial({map:e,transparent:!0});return new g.Sprite(t)}un.RIGHT_TOP;const ed={pos:un.LEFT_BOTTOM,size:100,hasZAxis:!0};class td extends Ju{constructor(e,t,n){const s={...ed,...n};super(e,t,s.size,n.pos),this.hasZAxis=s.hasZAxis;const i=[0,0,0,2,0,0,0,0,0,0,2,0],o=[1,0,0,1,.6,0,0,1,0,.6,1,0];this.hasZAxis&&(i.push(0,0,0,0,0,2),o.push(0,0,1,0,.6,1));const a=new g.BufferGeometry;a.setAttribute("position",new g.Float32BufferAttribute(i,3)),a.setAttribute("color",new g.Float32BufferAttribute(o,3));const c=new g.LineBasicMaterial({vertexColors:!0,toneMapped:!1});this.axes=new g.LineSegments(a,c),this.axes.position.set(-1,-1,-1),this.add(this.axes),this.xText=gr("X"),this.xText.position.set(1.5,-1,-1),this.add(this.xText),this.yText=gr("Y"),this.yText.position.set(-1,1.5,-1),this.add(this.yText),this.hasZAxis&&(this.zText=gr("Z"),this.zText.position.set(-1,-1,1.5),this.add(this.zText))}setLineColors(e,t){const n=new g.Color,s=this.axes.geometry.attributes.color.array;return n.set(e),n.toArray(s,0),n.toArray(s,3),n.set(t),n.toArray(s,6),n.toArray(s,9),this.axes.geometry.attributes.color.needsUpdate=!0,this}setTextColor(e){this.xText.material.color=e,this.yText.material.color=e}dispose(){var e,t;this.axes.geometry.dispose(),this.axes.material.dispose(),this.xText.geometry.dispose(),this.xText.material.dispose(),this.yText.geometry.dispose(),this.yText.material.dispose(),this.hasZAxis&&((e=this.zText)==null||e.geometry.dispose(),(t=this.zText)==null||t.material.dispose())}}class nd extends Qi{constructor(e,t,n,s){super(e,n,s),this._layoutBtrId=t,this._mode=Ie.SELECTION,this._axesGizmo=this.createAxesGizmo(),this._viewportViews=new Map}get layoutBtrId(){return this._layoutBtrId}get mode(){return this._mode}set mode(e){e==Ie.SELECTION?this._cameraControls.mouseButtons={MIDDLE:g.MOUSE.PAN}:e==Ie.PAN&&(this._cameraControls.mouseButtons={LEFT:g.MOUSE.PAN}),this._cameraControls.update(),this._mode=e}get viewportCount(){return this._viewportViews.size}addViewport(e){this._viewportViews.set(e.viewport.id,e)}removeViewport(e){this._viewportViews.delete(e)}resize(e,t){this._height=t,this._width=e,this.updateCameraFrustum(),this._viewportViews.forEach(n=>{n.update()})}render(e){var n;this._renderer.clear(),this._renderer.render(e.internalScene,this._camera);const t=e.modelSpaceLayout;t&&this.drawViewports(t.internalObject),(n=this._axesGizmo)==null||n.update()}createAxesGizmo(){return new td(this._camera.internalCamera,this._renderer.internalRenderer,{hasZAxis:!1,pos:un.LEFT_BOTTOM})}drawViewports(e){if(this._viewportViews.size>0){const t=this._renderer.autoClear;this._renderer.autoClear=!1;const n=new g.Vector4;this._renderer.getViewport(n),this._renderer.clearDepth();const s=e.visible;e.visible=!0,this._viewportViews.forEach(i=>{i.render(e)}),e.visible=s,this._renderer.setViewport(n.x,n.y,n.z,n.w),this._renderer.autoClear=t}}}class rd{constructor(){this._activeLayoutBtrId="",this._layoutViews=new Map}get activeLayoutBtrId(){return this._activeLayoutBtrId}set activeLayoutBtrId(e){this._activeLayoutBtrId=e,this._layoutViews.forEach(t=>{t.enabled=t.layoutBtrId==e})}get activeLayoutView(){return this._layoutViews.get(this._activeLayoutBtrId)}has(e){return this._layoutViews.has(e)}getAt(e){return this._layoutViews.get(e)}resize(e,t){this._layoutViews.forEach(n=>{n.resize(e,t)})}add(e){this._layoutViews.set(e.layoutBtrId,e)}render(e){var t;(t=this.activeLayoutView)==null||t.render(e)}}function Ji(r,e,t=0,n=r.length-1,s=sd){for(;n>t;){if(n-t>600){const c=n-t+1,h=e-t+1,l=Math.log(c),d=.5*Math.exp(2*l/3),u=.5*Math.sqrt(l*d*(c-d)/c)*(h-c/2<0?-1:1),p=Math.max(t,Math.floor(e-h*d/c+u)),f=Math.min(n,Math.floor(e+(c-h)*d/c+u));Ji(r,e,p,f,s)}const i=r[e];let o=t,a=n;for(Ot(r,t,e),s(r[n],i)>0&&Ot(r,t,n);o<a;){for(Ot(r,o,a),o++,a--;s(r[o],i)<0;)o++;for(;s(r[a],i)>0;)a--}s(r[t],i)===0?Ot(r,t,a):(a++,Ot(r,a,n)),a<=e&&(t=a+1),e<=a&&(n=a-1)}}function Ot(r,e,t){const n=r[e];r[e]=r[t],r[t]=n}function sd(r,e){return r<e?-1:r>e?1:0}class id{constructor(e=9){this._maxEntries=Math.max(4,e),this._minEntries=Math.max(2,Math.ceil(this._maxEntries*.4)),this.clear()}all(){return this._all(this.data,[])}search(e){let t=this.data;const n=[];if(!pn(e,t))return n;const s=this.toBBox,i=[];for(;t;){for(let o=0;o<t.children.length;o++){const a=t.children[o],c=t.leaf?s(a):a;pn(e,c)&&(t.leaf?n.push(a):yr(e,c)?this._all(a,n):i.push(a))}t=i.pop()}return n}collides(e){let t=this.data;if(!pn(e,t))return!1;const n=[];for(;t;){for(let s=0;s<t.children.length;s++){const i=t.children[s],o=t.leaf?this.toBBox(i):i;if(pn(e,o)){if(t.leaf||yr(e,o))return!0;n.push(i)}}t=n.pop()}return!1}load(e){if(!(e&&e.length))return this;if(e.length<this._minEntries){for(let n=0;n<e.length;n++)this.insert(e[n]);return this}let t=this._build(e.slice(),0,e.length-1,0);if(!this.data.children.length)this.data=t;else if(this.data.height===t.height)this._splitRoot(this.data,t);else{if(this.data.height<t.height){const n=this.data;this.data=t,t=n}this._insert(t,this.data.height-t.height-1,!0)}return this}insert(e){return e&&this._insert(e,this.data.height-1),this}clear(){return this.data=ut([]),this}remove(e,t){if(!e)return this;let n=this.data;const s=this.toBBox(e),i=[],o=[];let a,c,h;for(;n||i.length;){if(n||(n=i.pop(),c=i[i.length-1],a=o.pop(),h=!0),n.leaf){const l=od(e,n.children,t);if(l!==-1)return n.children.splice(l,1),i.push(n),this._condense(i),this}!h&&!n.leaf&&yr(n,s)?(i.push(n),o.push(a),a=0,c=n,n=n.children[0]):c?(a++,n=c.children[a],h=!1):n=null}return this}toBBox(e){return e}compareMinX(e,t){return e.minX-t.minX}compareMinY(e,t){return e.minY-t.minY}toJSON(){return this.data}fromJSON(e){return this.data=e,this}_all(e,t){const n=[];for(;e;)e.leaf?t.push(...e.children):n.push(...e.children),e=n.pop();return t}_build(e,t,n,s){const i=n-t+1;let o=this._maxEntries,a;if(i<=o)return a=ut(e.slice(t,n+1)),lt(a,this.toBBox),a;s||(s=Math.ceil(Math.log(i)/Math.log(o)),o=Math.ceil(i/Math.pow(o,s-1))),a=ut([]),a.leaf=!1,a.height=s;const c=Math.ceil(i/o),h=c*Math.ceil(Math.sqrt(o));Ki(e,t,n,h,this.compareMinX);for(let l=t;l<=n;l+=h){const d=Math.min(l+h-1,n);Ki(e,l,d,c,this.compareMinY);for(let u=l;u<=d;u+=c){const p=Math.min(u+c-1,d);a.children.push(this._build(e,u,p,s-1))}}return lt(a,this.toBBox),a}_chooseSubtree(e,t,n,s){for(;s.push(t),!(t.leaf||s.length-1===n);){let i=1/0,o=1/0,a;for(let c=0;c<t.children.length;c++){const h=t.children[c],l=mr(h),d=hd(e,h)-l;d<o?(o=d,i=l<i?l:i,a=h):d===o&&l<i&&(i=l,a=h)}t=a||t.children[0]}return t}_insert(e,t,n){const s=n?e:this.toBBox(e),i=[],o=this._chooseSubtree(s,this.data,t,i);for(o.children.push(e),Rt(o,s);t>=0&&i[t].children.length>this._maxEntries;)this._split(i,t),t--;this._adjustParentBBoxes(s,i,t)}_split(e,t){const n=e[t],s=n.children.length,i=this._minEntries;this._chooseSplitAxis(n,i,s);const o=this._chooseSplitIndex(n,i,s),a=ut(n.children.splice(o,n.children.length-o));a.height=n.height,a.leaf=n.leaf,lt(n,this.toBBox),lt(a,this.toBBox),t?e[t-1].children.push(a):this._splitRoot(n,a)}_splitRoot(e,t){this.data=ut([e,t]),this.data.height=e.height+1,this.data.leaf=!1,lt(this.data,this.toBBox)}_chooseSplitIndex(e,t,n){let s,i=1/0,o=1/0;for(let a=t;a<=n-t;a++){const c=Dt(e,0,a,this.toBBox),h=Dt(e,a,n,this.toBBox),l=ld(c,h),d=mr(c)+mr(h);l<i?(i=l,s=a,o=d<o?d:o):l===i&&d<o&&(o=d,s=a)}return s||n-t}_chooseSplitAxis(e,t,n){const s=e.leaf?this.compareMinX:ad,i=e.leaf?this.compareMinY:cd,o=this._allDistMargin(e,t,n,s),a=this._allDistMargin(e,t,n,i);o<a&&e.children.sort(s)}_allDistMargin(e,t,n,s){e.children.sort(s);const i=this.toBBox,o=Dt(e,0,t,i),a=Dt(e,n-t,n,i);let c=dn(o)+dn(a);for(let h=t;h<n-t;h++){const l=e.children[h];Rt(o,e.leaf?i(l):l),c+=dn(o)}for(let h=n-t-1;h>=t;h--){const l=e.children[h];Rt(a,e.leaf?i(l):l),c+=dn(a)}return c}_adjustParentBBoxes(e,t,n){for(let s=n;s>=0;s--)Rt(t[s],e)}_condense(e){for(let t=e.length-1,n;t>=0;t--)e[t].children.length===0?t>0?(n=e[t-1].children,n.splice(n.indexOf(e[t]),1)):this.clear():lt(e[t],this.toBBox)}}function od(r,e,t){if(!t)return e.indexOf(r);for(let n=0;n<e.length;n++)if(t(r,e[n]))return n;return-1}function lt(r,e){Dt(r,0,r.children.length,e,r)}function Dt(r,e,t,n,s){s||(s=ut(null)),s.minX=1/0,s.minY=1/0,s.maxX=-1/0,s.maxY=-1/0;for(let i=e;i<t;i++){const o=r.children[i];Rt(s,r.leaf?n(o):o)}return s}function Rt(r,e){return r.minX=Math.min(r.minX,e.minX),r.minY=Math.min(r.minY,e.minY),r.maxX=Math.max(r.maxX,e.maxX),r.maxY=Math.max(r.maxY,e.maxY),r}function ad(r,e){return r.minX-e.minX}function cd(r,e){return r.minY-e.minY}function mr(r){return(r.maxX-r.minX)*(r.maxY-r.minY)}function dn(r){return r.maxX-r.minX+(r.maxY-r.minY)}function hd(r,e){return(Math.max(e.maxX,r.maxX)-Math.min(e.minX,r.minX))*(Math.max(e.maxY,r.maxY)-Math.min(e.minY,r.minY))}function ld(r,e){const t=Math.max(r.minX,e.minX),n=Math.max(r.minY,e.minY),s=Math.min(r.maxX,e.maxX),i=Math.min(r.maxY,e.maxY);return Math.max(0,s-t)*Math.max(0,i-n)}function yr(r,e){return r.minX<=e.minX&&r.minY<=e.minY&&e.maxX<=r.maxX&&e.maxY<=r.maxY}function pn(r,e){return e.minX<=r.maxX&&e.minY<=r.maxY&&e.maxX>=r.minX&&e.maxY>=r.minY}function ut(r){return{children:r,height:1,leaf:!0,minX:1/0,minY:1/0,maxX:-1/0,maxY:-1/0}}function Ki(r,e,t,n,s){const i=[e,t];for(;i.length;){if(t=i.pop(),e=i.pop(),t-e<=n)continue;const o=e+Math.ceil((t-e)/n/2)*n;Ji(r,o,e,t,s),i.push(e,o,o,t)}}class ud{constructor(e){this._group=new Pu,this._name=e}get name(){return this._name}set name(e){this._name=e}get visible(){return this._group.visible}set visible(e){this._group.visible=e}get internalObject(){return this._group}get stats(){const e=this._group.stats;return{name:this._name,...e}}get entityCount(){return this._group.entityCount}rerenderPoints(e){this._group.rerenderPoints(e)}hasEntity(e){return this._group.hasEntity(e)}addEntity(e){this._group.addEntity(e)}isIntersectWith(e,t){return this._group.isIntersectWith(e,t)}remove(e){throw new Error("Not implemented yet!")}update(e){return this._group.add(e),!0}hover(e){e.forEach(t=>{this._group.hover(t)})}unhover(e){e.forEach(t=>{this._group.unhover(t)})}select(e){e.forEach(t=>{this._group.select(t)})}unselect(e){e.forEach(t=>{this._group.unselect(t)})}}class dd{constructor(){this._group=new g.Group,this._indexTree=new id,this._box=new g.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(e){this._group.visible=e}get entityCount(){let e=0;return this._layers.forEach(t=>e+=t.entityCount),e}get stats(){const e=[];let t=0,n=0,s=0,i=0,o=0;return this._layers.forEach(a=>{const c=a.stats;e.push(c),s+=c.line.indexed.geometrySize+c.line.nonIndexed.geometrySize,i+=c.mesh.indexed.geometrySize+c.mesh.nonIndexed.geometrySize,o+=c.point.indexed.geometrySize+c.point.nonIndexed.geometrySize,t+=c.summary.totalGeometrySize,n+=c.summary.totalMappingSize}),{layers:e,summary:{entityCount:this.entityCount,totalSize:{line:s,mesh:i,point:o,geometry:t,mapping:n}}}}clear(){return this._layers.forEach(e=>{this._group.remove(e.internalObject)}),this._layers.clear(),this._box.makeEmpty(),this._indexTree.clear(),this}rerenderPoints(e){this._layers.forEach(t=>{t.rerenderPoints(e)})}isIntersectWith(e,t){const n=this.getLayerByObjectId(e);return n&&n.isIntersectWith(e,t)}addEntity(e,t=!0){if(!e.objectId)throw new Error("Object id is required to add one entity!");if(!e.layerName)throw new Error("Layer name is required to add one entity!");const n=this._layers.get(e.layerName);if(!n)throw new Error(`layer '${e.layerName}' doesn't exist!`);n.addEntity(e);const s=e.box;return t&&this._box.union(s),this._indexTree.insert({minX:s.min.x,minY:s.min.y,maxX:s.max.x,maxY:s.max.y,id:e.objectId}),this}remove(e){for(const[t,n]of this._layers)if(n.remove(e))return!0;return!1}updateEntity(e){for(const[t,n]of this._layers)if(n.update(e))return!0;return!1}addLayer(e){const t=e.name;let n=this._layers.get(t);return n===void 0&&(n=new ud(t),n.visible=!(e.isFrozen||e.isOff),this._layers.set(t,n),this._group.add(n.internalObject)),e}updateLayer(e){const t=this._layers.get(e.name);return t&&(t.visible=!(e.isFrozen||e.isOff)),t}hover(e){e.forEach(t=>{const n=this.getLayerByObjectId(t);n&&n.hover([t])})}unhover(e){e.forEach(t=>{const n=this.getLayerByObjectId(t);n&&n.unhover([t])})}select(e){e.forEach(t=>{const n=this.getLayerByObjectId(t);n&&n.select([t])})}unselect(e){e.forEach(t=>{const n=this.getLayerByObjectId(t);n&&n.unselect([t])})}setSnapObject(e){this._snapPointsObject&&this._group.remove(this._snapPointsObject),this._snapPointsObject=e,this._group.add(e)}search(e){return this._indexTree.search({minX:e.min.x,minY:e.min.y,maxX:e.max.x,maxY:e.max.y})}getLayerByObjectId(e){for(const[t,n]of this._layers)if(n.hasEntity(e))return n}}class pd{constructor(){this._scene=new g.Scene,this._layers=new Map,this._layouts=new Map,this._activeLayoutBtrId="",this._modelSpaceBtrId=""}get layers(){return this._layers}get layouts(){return this._layouts}get box(){var e;return(e=this.activeLayout)==null?void 0:e.box}get internalScene(){return this._scene}get modelSpaceBtrId(){return this._modelSpaceBtrId}set modelSpaceBtrId(e){if(this._modelSpaceBtrId=e,!this._layouts.has(e))throw new Error(`[AcTrScene] No layout assiciated with the specified block table record id '${e}'!`)}get activeLayoutBtrId(){return this._activeLayoutBtrId}set activeLayoutBtrId(e){this._activeLayoutBtrId=e,this._layouts.forEach((t,n)=>{t.visible=e==n})}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 e=[];return this._layouts.forEach(t=>e.push(t.stats)),{layouts:e}}addEmptyLayout(e){const t=new dd;return this._layouts.set(e,t),this._scene.add(t.internalObject),t.visible=e==this._activeLayoutBtrId,this._layers.forEach(n=>{t.addLayer(n)}),t}clear(){return this._layouts.forEach(e=>{this._scene.remove(e.internalObject),e.clear()}),this._layouts.clear(),this._layers.clear(),this._scene.clear(),this}hover(e){return this.activeLayout?(this.activeLayout.hover(e),!0):!1}unhover(e){return this.activeLayout?(this.activeLayout.unhover(e),!0):!1}select(e){return this.activeLayout?(this.activeLayout.select(e),!0):!1}unselect(e){return this.activeLayout?(this.activeLayout.unselect(e),!0):!1}search(e){const t=this.activeLayout;return t?t==null?void 0:t.search(e):[]}addLayer(e){this._layers.set(e.name,e),this._layouts.forEach(t=>{t.addLayer(e)})}updateLayer(e){this._layers.set(e.name,e),this._layouts.forEach(t=>{t.updateLayer(e)})}addEntity(e,t=!0){const n=e.ownerId;if(n){let s=this._layouts.get(n);s||(s=this.addEmptyLayout(n)),s.addEntity(e,t)}else console.warn("[AcTrSecene] The owner id of one entity cannot be empty!");return this}remove(e){for(const[t,n]of this._layouts)if(n.remove(e))return!0;return!1}update(e){for(const[t,n]of this._layouts)if(n.updateEntity(e))return!0;return!1}setSnapObject(e){return this._layouts.forEach(t=>{t.setSnapObject(e)}),this}}const vr={background:0};class eo extends Er{constructor(e=vr){const t={...vr,...e},n=new g.WebGLRenderer({antialias:!0,alpha:!0,canvas:e.canvas});t.canvas==null&&(t.canvas=n.domElement),super(t.canvas),e.calculateSizeCallback&&this.setCalculateSizeCallback(e.calculateSizeCallback),n.setPixelRatio(Math.min(window.devicePixelRatio,2)),n.setSize(this.width,this.height),this._renderer=new Yu(n);const s=dt.instance.fontMapping;this._renderer.setFontMapping(s),this._renderer.events.fontNotFound.addEventListener(i=>{Ce.emit("font-not-found",{fontName:i.fontName,count:i.count??0})}),this._scene=this.createScene(),this._renderer.setClearColor(t.background||0),this._stats=this.createStats(dt.instance.isShowStats),dt.instance.events.modified.addEventListener(i=>{i.key=="isShowStats"&&this.toggleStatsVisibility(this._stats,i.value)}),this.canvas.addEventListener("click",()=>{this.mode==Ie.SELECTION&&this.select()}),document.addEventListener("keydown",i=>{i.code==="Escape"&&this.selectionSet.clear()}),_.acdbHostApplicationServices().layoutManager.events.layoutSwitched.addEventListener(i=>{this.activeLayoutBtrId=i.layout.blockTableRecordId}),this._missedImages=new Map,this._layoutViewManager=new rd,this.initialize(),this.onWindowResize(),this.animate(),this._isDirty=!0,this._numOfEntitiesToProcess=0}initialize(){this.setCursor(qe.Crosshair)}get mode(){const e=this.activeLayoutView;return e?e.mode:Ie.SELECTION}set mode(e){this.activeLayoutView.mode=e,this.editor.getPoint()}get renderer(){return this._renderer}get isDirty(){return this._isDirty}set isDirty(e){this._isDirty=e}get missedData(){return{fonts:this._renderer.missedFonts,images:this._missedImages}}get center(){return this.activeLayoutView.center}set center(e){this.activeLayoutView.center=e}get backgroundColor(){return this._renderer.getClearColor()}set backgroundColor(e){this._renderer.setClearColor(e),this._isDirty=!0}get modelSpaceBtrId(){return this._scene.modelSpaceBtrId}set modelSpaceBtrId(e){this._scene.modelSpaceBtrId=e}get activeLayoutBtrId(){return this._scene.activeLayoutBtrId}set activeLayoutBtrId(e){this._layoutViewManager.activeLayoutBtrId=e,this._scene.activeLayoutBtrId=e,this._isDirty=!0}get activeLayoutView(){return this._layoutViewManager.activeLayoutView}get stats(){return this._scene.stats}animate(){var e;requestAnimationFrame(this.animate.bind(this)),this._isDirty&&(this._layoutViewManager.render(this._scene),(e=this._stats)==null||e.update(),this._isDirty=!1)}cwcs2Wcs(e){const t=this.activeLayoutView;return t?t.cwcs2Wcs(e):new _.AcGePoint2d(e)}wcs2Cwcs(e){const t=this.activeLayoutView;return t?t.wcs2Cwcs(e):new _.AcGePoint2d(e)}zoomTo(e,t=1.1){this.activeLayoutView.zoomTo(e,t),this._isDirty=!0}rerenderPoints(e){const t=this._scene.activeLayout;t&&(t.rerenderPoints(e),this._isDirty=!0)}zoomToFit(e=0){new _r(()=>this._numOfEntitiesToProcess<=0,()=>{if(this._scene.box){const n=Qu.threeBox3dToGeBox2d(this._scene.box);this.zoomTo(n),this._isDirty=!0}},300,e).start()}pick(e){e==null&&(e=this.curPos);const t=[],n=this._scene.activeLayout;if(n){const s=this.activeLayoutView,i=s.pointToBox(e,this.selectionBoxSize),o=this._scene.search(i),a=Math.max(i.size.width/2,i.size.height/2),c=s.resetRaycaster(e,a);o.forEach(h=>{const l=h.id;n.isIntersectWith(l,c)&&t.push(l)})}return t}search(e){return this._scene.search(e)}select(e){const t=[];this.pick(e).forEach(s=>t.push(s)),t.length>0&&this.selectionSet.add(t)}selectByBox(e){const t=[];this._scene.search(e).forEach(s=>t.push(s.id)),this.selectionSet.add(t)}addLayer(e){this._scene.addLayer({name:e.name,isFrozen:e.isFrozen,isOff:e.isOff}),this._isDirty=!0}updateLayer(e){this._scene.updateLayer({name:e.name,isFrozen:e.isFrozen,isOff:e.isOff}),this._isDirty=!0}addEntity(e){const t=Array.isArray(e)?e:[e];this._numOfEntitiesToProcess+=t.length,setTimeout(async()=>{await this.batchConvert(t)})}removeEntity(e){this._scene.remove(e)}updateEntity(e){let t=[];Array.isArray(e)?t=e:t.push(e);for(let n=0;n<t.length;++n){const s=t[n],i=s.draw(this._renderer);i&&(i.objectId=s.objectId,i.ownerId=s.ownerId,i.layerName=s.layer,i.visible=s.visibility,this._scene.update(i))}this._isDirty=!0,setTimeout(()=>{this._isDirty=!0},100)}addLayout(e){this._scene.addEmptyLayout(e.blockTableRecordId),this.createLayoutViewIfNeeded(e.blockTableRecordId),this._isDirty=!0}clear(){this._scene.clear(),this._isDirty=!0,this._missedImages.clear(),this._renderer.clearMissedFonts()}highlight(e){this._isDirty=this._scene.select(e)}unhighlight(e){this._isDirty=this._scene.unselect(e)}onHover(e){this._isDirty=this._scene.hover([e])}onUnhover(e){this._isDirty=this._scene.unhover([e])}createScene(){const e=new pd;return e.layouts.forEach(t=>{t.setSnapObject(this.renderer.createObject())}),e}createStats(e){const t=new ho;document.body.appendChild(t.dom);const n=t.dom;return n.style.position="fixed",n.style.inset="unset",n.style.bottom="30px",n.style.right="0px",this.toggleStatsVisibility(t,e),t}onWindowResize(){super.onWindowResize(),this._renderer.setSize(this.width,this.height),this._layoutViewManager.resize(this.width,this.height),this._isDirty=!0}createLayoutViewIfNeeded(e){let t=this._layoutViewManager.getAt(e);return t==null&&(t=new nd(this._renderer,e,this.width,this.height),t.events.viewChanged.addEventListener(()=>{this._isDirty=!0}),this._layoutViewManager.add(t)),t}toggleStatsVisibility(e,t){t?e.dom.style.display="block":e.dom.style.display="none"}async batchConvert(e){for(let t=0;t<e.length;++t){const n=e[t],s=n.draw(this._renderer,!0);if(s){if(s.objectId=n.objectId,s.ownerId=n.ownerId,s.layerName=n.layer,s.visible=n.visibility,s instanceof sn&&!s.isOnTheSameLayer)this.handleGroup(s),this.decreaseNumOfEntitiesToProcess();else{const i=!(n instanceof _.AcDbRay||n instanceof _.AcDbXline);await s.draw().then(()=>{this._scene.addEntity(s,i),s.dispose(),this._isDirty=!0}).finally(()=>{this.decreaseNumOfEntitiesToProcess()})}if(n instanceof _.AcDbViewport){if(n.number>1){const i=this._layoutViewManager.getAt(n.ownerId);if(i){const o=new ln(i,n.toGiViewport(),this._renderer);i.addViewport(o)}}}else if(n instanceof _.AcDbRasterImage){const i=n.imageFileName;i&&this._missedImages.set(n.objectId,i)}}else this.decreaseNumOfEntitiesToProcess()}}handleGroup(e){const t=e.children,n=new Map;t.forEach(c=>{var l;const h=c.userData.layerName;n.has(h)||n.set(h,[]),(l=n.get(h))==null||l.push(c)});const s=e.styleManager,i=e.objectId,o=e.layerName,a=e.box;n.forEach((c,h)=>{const l=new ne(s);l.applyMatrix4(e.matrix),l.objectId=i,l.ownerId=e.ownerId,l.layerName=h==="0"?o:h,l.box=a,l.add(...c),this._scene.addEntity(l,!0),l.dispose()}),this._isDirty=!0}decreaseNumOfEntitiesToProcess(){this._numOfEntitiesToProcess--,this._numOfEntitiesToProcess<0&&(this._numOfEntitiesToProcess=0,console.warn("Something wrong! The number of entities to process should not be less than 0."))}}class fd{constructor(e){this._cadRenderer=e,this._avaiableFonts=[]}get avaiableFonts(){return this._avaiableFonts}async getAvaiableFonts(){if(this._avaiableFonts.length==0){const e="https://mlightcad.gitlab.io/cad-data/fonts/",t=e+"fonts.json";try{const n=await fetch(t);this._avaiableFonts=await n.json()}catch{Ce.emit("failed-to-get-avaiable-fonts",{url:t})}this._avaiableFonts.forEach(n=>{n.url=e+n.file})}return this._avaiableFonts}async load(e){await this.getAvaiableFonts();const t=[];e.forEach(s=>{const i=s.toLowerCase(),o=gn.find(this._avaiableFonts,a=>gn.findIndex(a.name,c=>c.toLowerCase()==i)>=0);o&&t.push(o.url)}),(await this._cadRenderer.loadFonts(t)).forEach(s=>{s.status||Ce.emit("font-not-loaded",{fontName:s.fontName,url:s.url})})}}class le{constructor(e){this.events={documentCreated:new _.AcCmEventManager,documentActivated:new _.AcCmEventManager};const t=new Ar;t.database.events.openProgress.addEventListener(i=>{Ce.emit("open-file-progress",{database:t.database,percentage:i.percentage,stage:i.stage,subStage:i.subStage,subStageStatus:i.subStageStatus,data:i.data})});const n=()=>({width:window.innerWidth,height:window.innerHeight-30}),s=new eo({canvas:e,calculateSizeCallback:n});this._context=new Sr(s,t),this._fontLoader=new fd(s.renderer),_.acdbHostApplicationServices().workingDatabase=t.database,this.registerCommands()}static createInstance(e){return le._instance==null&&(le._instance=new le(e)),this._instance}static get instance(){return le._instance||(le._instance=new le),le._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(e){await this._fontLoader.load(e)}async loadDefaultFonts(e){e==null?await this._fontLoader.load(["simkai"]):await this._fontLoader.load(e)}async openUrl(e,t){this.onBeforeOpenDocument(),t=this.setOptions(t);const n=await this.context.doc.openUri(e,t);return this.onAfterOpenDocument(n),n}async openDocument(e,t,n){this.onBeforeOpenDocument(),n=this.setOptions(n);const s=await this.context.doc.openDocument(e,t,n);return this.onAfterOpenDocument(s),s}registerCommands(){const e=ce.instance;e.addCommand(ce.SYSTEMT_COMMAND_GROUP_NAME,"pan","pan",new Ur),e.addCommand(ce.SYSTEMT_COMMAND_GROUP_NAME,"select","select",new Or),e.addCommand(ce.SYSTEMT_COMMAND_GROUP_NAME,"zoom","zoom",new Dr),e.addCommand(ce.SYSTEMT_COMMAND_GROUP_NAME,"zoomw","zoomw",new Fr),e.addCommand(ce.SYSTEMT_COMMAND_GROUP_NAME,"csvg","csvg",new Br),e.addCommand(ce.SYSTEMT_COMMAND_GROUP_NAME,"qnew","qnew",new Mr),e.addCommand(ce.SYSTEMT_COMMAND_GROUP_NAME,"open","open",new Lr)}sendStringToExecute(e){const n=ce.instance.lookupGlobalCmd(e);n==null||n.execute(this.context)}setActiveLayout(){const e=this.curView;e.activeLayoutBtrId=this.curDocument.database.currentSpaceId,e.modelSpaceBtrId=this.curDocument.database.currentSpaceId}onBeforeOpenDocument(){this.curView.clear()}onAfterOpenDocument(e){if(e){const t=this.context.doc;this.events.documentActivated.dispatch({doc:t}),this.setActiveLayout();const n=t.database;n.extents.isEmpty()?this.curView.zoomToFit():this.curView.zoomTo(new _.AcGeBox2d(n.extmin,n.extmax))}}setOptions(e){return e==null?e={fontLoader:this._fontLoader}:e.fontLoader==null&&(e.fontLoader=this._fontLoader),e}}class to{convert(e){const t=this.createEntity(e);return t&&this.processCommonAttrs(e,t),t}createEntity(e){return e.type=="3DFACE"?this.convertFace(e):e.type=="ARC"?this.convertArc(e):e.type=="CIRCLE"?this.convertCirle(e):e.type=="DIMENSION"?this.convertDimension(e):e.type=="ELLIPSE"?this.convertEllipse(e):e.type=="HATCH"?this.convertHatch(e):e.type=="IMAGE"?this.convertImage(e):e.type=="LEADER"?this.convertLeader(e):e.type=="LINE"?this.convertLine(e):e.type=="LWPOLYLINE"?this.convertLWPolyline(e):e.type=="MTEXT"?this.convertMText(e):e.type=="POINT"?this.convertPoint(e):e.type=="POLYLINE"?this.convertPolyline(e):e.type=="RAY"?this.convertRay(e):e.type=="SPLINE"?this.convertSpline(e):e.type=="ACAD_TABLE"?this.convertTable(e):e.type=="TEXT"?this.convertText(e):e.type=="SOLID"?this.convertSolid(e):e.type=="VIEWPORT"?this.convertViewport(e):e.type=="WIPEOUT"?this.convertWipeout(e):e.type=="XLINE"?this.convertXline(e):e.type=="INSERT"?this.convertBlockReference(e):null}convertFace(e){const t=new _.AcDbFace;return e.corner1&&t.setVertexAt(0,e.corner1),e.corner2&&t.setVertexAt(1,e.corner2),e.corner3&&t.setVertexAt(2,e.corner3),e.corner4&&t.setVertexAt(3,e.corner4),t.setEdgeInvisibilities(e.flag),t}convertArc(e){return new _.AcDbArc(e.center,e.radius,e.startAngle,e.endAngle)}convertCirle(e){return new _.AcDbCircle(e.center,e.radius)}convertEllipse(e){const t=new _.AcGeVector3d(e.majorAxisEndPoint),n=t.length();return new _.AcDbEllipse(e.center,e.extrusionDirection??_.AcGeVector3d.Z_AXIS,t,n,n*e.axisRatio,e.startAngle,e.endAngle)}convertLine(e){const t=e.startPoint,n=e.endPoint;return new _.AcDbLine(new _.AcGePoint3d(t.x,t.y,t.z),new _.AcGePoint3d(n.x,n.y,n.z))}convertSpline(e){try{if(e.numberOfControlPoints>0&&e.numberOfKnots>0)return new _.AcDbSpline(e.controlPoints,e.knots,e.weights,e.degree,!!(e.flag&1));if(e.numberOfFitPoints>0)return new _.AcDbSpline(e.fitPoints,"Uniform",e.degree,!!(e.flag&1))}catch(t){console.log(`Failed to convert spline with error: ${t}`)}return null}convertPoint(e){const t=new _.AcDbPoint;return t.position=e.position,t}convertSolid(e){const t=new _.AcDbTrace;return t.setPointAt(0,{...e.corner1,z:0}),t.setPointAt(1,{...e.corner2,z:0}),t.setPointAt(2,{...e.corner3,z:0}),t.setPointAt(3,e.corner4?{...e.corner4,z:0}:{...e.corner3,z:0}),t.thickness=e.thickness,t}convertLWPolyline(e){const t=new _.AcDbPolyline;return t.closed=!!(e.flag&512),e.vertices.forEach((n,s)=>{t.addVertexAt(s,new _.AcGePoint2d(n.x,n.y),n.bulge,n.startWidth,n.endWidth)}),t}convertPolyline(e){const t=new _.AcDbPolyline;return t.closed=!!(e.flag&1),e.vertices.forEach((n,s)=>{t.addVertexAt(s,new _.AcGePoint2d(n.x,n.y),n.bulge,n.startWidth,n.endWidth)}),t}convertHatch(e){var t;const n=new _.AcDbHatch;return(t=e.definitionLines)==null||t.forEach(s=>{n.definitionLines.push({angle:s.angle,origin:s.base,delta:s.offset,dashPattern:s.numberOfDashLengths>0?s.dashLengths:[]})}),n.hatchStyle=e.hatchStyle,n.patternName=e.patternName,n.patternType=e.patternType,n.patternAngle=e.patternAngle==null?0:e.patternAngle,n.patternScale=e.patternScale==null?0:e.patternScale,e.boundaryPaths.forEach(s=>{if(s.boundaryPathTypeFlag&2){const i=s,o=new _.AcGePolyline2d;o.closed=i.isClosed,i.vertices.forEach((a,c)=>{o.addVertexAt(c,{x:a.x,y:a.y,bulge:a.bulge})}),n.add(o)}else{const i=s,o=new _.AcGeLoop2d;i.edges.forEach(a=>{if(a!=null){if(a.type==1){const c=a;o.add(new _.AcGeLine2d(c.start,c.end))}else if(a.type==2){const c=a;o.add(new _.AcGeCircArc2d(c.center,c.radius,c.startAngle,c.endAngle,!c.isCCW))}else if(a.type==3){const c=a;new _.AcGeVector2d().subVectors(c.end,c.center);const h=Math.sqrt(Math.pow(c.end.x,2)+Math.pow(c.end.y,2)),l=h*c.lengthOfMinorAxis;let d=c.startAngle,u=c.endAngle;const p=Math.atan2(c.end.y,c.end.x);c.isCCW||(d=Math.PI*2-d,u=Math.PI*2-u),o.add(new _.AcGeEllipseArc2d({...c.center,z:0},h,l,d,u,!c.isCCW,p))}else if(a.type==4){const c=a;if(c.numberOfControlPoints>0&&c.numberOfKnots>0){const h=c.controlPoints.map(u=>({x:u.x,y:u.y,z:0}));let l=!0;const d=c.controlPoints.map(u=>(u.weight==null&&(l=!1),u.weight||1));o.add(new _.AcGeSpline3d(h,c.knots,l?d:void 0))}else if(c.numberOfFitData>0){const h=c.fitDatum.map(l=>({x:l.x,y:l.y,z:0}));o.add(new _.AcGeSpline3d(h,"Uniform"))}}}}),n.add(o)}}),n}convertTable(e){const t=new _.AcDbTable(e.name,e.rowCount,e.columnCount);return t.attachmentPoint=e.attachmentPoint,t.position.copy(e.startPoint),e.columnWidthArr.forEach((n,s)=>t.setColumnWidth(s,n)),e.rowHeightArr.forEach((n,s)=>t.setRowHeight(s,n)),e.cells.forEach((n,s)=>{t.setCell(s,n)}),t}convertText(e){const t=new _.AcDbText;return t.textString=e.text,t.styleName=e.styleName,t.height=e.textHeight,t.position.copy(e.startPoint),t.rotation=e.rotation,t.oblique=e.obliqueAngle??0,t.thickness=e.thickness,t.horizontalMode=e.halign,t.verticalMode=e.valign,t.widthFactor=e.xScale??1,t}convertMText(e){const t=new _.AcDbMText;return t.contents=e.text,e.styleName!=null&&(t.styleName=e.styleName),t.height=e.textHeight,t.width=e.rectWidth,t.rotation=e.rotation||0,t.location=e.insertionPoint,t.attachmentPoint=e.attachmentPoint,e.direction&&(t.direction=new _.AcGeVector3d(e.direction)),t.drawingDirection=e.drawingDirection,t}convertLeader(e){const t=new _.AcDbLeader;return e.vertices.forEach(n=>{t.appendVertex(n)}),t.hasArrowHead=e.isArrowheadEnabled,t.hasHookLine=e.isHooklineExists,t.isSplined=e.isSpline,t.dimensionStyle=e.styleName,t.annoType=e.leaderCreationFlag,t}convertDimension(e){if(e.subclassMarker=="AcDbAlignedDimension"||e.subclassMarker=="AcDbRotatedDimension"){const t=e,n=new _.AcDbAlignedDimension(t.subDefinitionPoint1,t.subDefinitionPoint2,t.definitionPoint);return n.rotation=t.rotationAngle,this.processDimensionCommonAttrs(e,n),n}else if(e.subclassMarker=="AcDb3PointAngularDimension"){const t=e,n=new _.AcDb3PointAngularDimension(t.centerPoint,t.subDefinitionPoint1,t.subDefinitionPoint2,t.definitionPoint);return this.processDimensionCommonAttrs(e,n),n}else if(e.subclassMarker=="AcDbOrdinateDimension"){const t=e,n=new _.AcDbOrdinateDimension(t.subDefinitionPoint1,t.subDefinitionPoint2);return this.processDimensionCommonAttrs(e,n),n}else if(e.subclassMarker=="AcDbRadialDimension"){const t=e,n=new _.AcDbRadialDimension(t.definitionPoint,t.centerPoint,t.leaderLength);return this.processDimensionCommonAttrs(e,n),n}else if(e.subclassMarker=="AcDbDiametricDimension"){const t=e,n=new _.AcDbDiametricDimension(t.definitionPoint,t.centerPoint,t.leaderLength);return this.processDimensionCommonAttrs(e,n),n}return null}processImage(e,t){t.position.copy(e.position),t.brightness=e.brightness,t.contrast=e.contrast,t.fade=e.fade,t.imageDefId=e.imageDefHandle.toString(),t.isClipped=e.clipping>0,t.isShownClipped=(e.flags|4)>0,t.isImageShown=(e.flags|3)>0,t.isImageTransparent=(e.flags|8)>0,e.clippingBoundaryPath.forEach(n=>{t.clipBoundary.push(new _.AcGePoint2d(n))}),t.clipBoundaryType=e.clippingBoundaryType,t.width=Math.sqrt(e.uPixel.x**2+e.uPixel.y**2+e.uPixel.z**2)*e.imageSize.x,t.height=Math.sqrt(e.vPixel.x**2+e.vPixel.y**2+e.vPixel.z**2)*e.imageSize.y,t.rotation=Math.atan2(e.uPixel.y,e.uPixel.x)}convertImage(e){const t=new _.AcDbRasterImage;return this.processImage(e,t),t}convertWipeout(e){const t=new _.AcDbWipeout;return this.processImage(e,t),t}convertViewport(e){const t=new _.AcDbViewport;return t.number=e.viewportId,t.centerPoint.copy(e.viewportCenter),t.height=e.height,t.width=e.width,t.viewCenter.copy(e.displayCenter),t.viewHeight=e.viewHeight,t}convertRay(e){const t=new _.AcDbRay;return t.basePoint.copy(e.firstPoint),t.unitDir.copy(e.unitDirection),t}convertXline(e){const t=new _.AcDbXline;return t.basePoint.copy(e.firstPoint),t.unitDir.copy(e.unitDirection),t}convertBlockReference(e){const t=new _.AcDbBlockReference(e.name);return e.insertionPoint&&t.position.copy(e.insertionPoint),t.scaleFactors.x=e.xScale,t.scaleFactors.y=e.yScale,t.scaleFactors.z=e.zScale,t.rotation=e.rotation,t.normal.copy(e.extrusionDirection),t}processDimensionCommonAttrs(e,t){t.dimBlockId=e.name,t.textPosition.copy(e.textPoint),t.textRotation=e.textRotation||0,e.textLineSpacingFactor&&(t.textLineSpacingFactor=e.textLineSpacingFactor),e.textLineSpacingStyle&&(t.textLineSpacingStyle=e.textLineSpacingStyle),t.dimensionStyleName=e.styleName,t.dimensionText=e.text||"",t.measurement=e.measurement}processCommonAttrs(e,t){t.layer=e.layer||"0",t.objectId=e.handle.toString(),t.ownerId=e.ownerBlockRecordSoftId.toString(),e.lineType!=null&&(t.lineType=e.lineType),e.lineweight!=null&&(t.lineWeight=e.lineweight),e.lineTypeScale!=null&&(t.linetypeScale=e.lineTypeScale),e.color!=null&&(t.color.color=e.color),e.colorIndex!=null&&(t.color.colorIndex=e.colorIndex),e.colorName!=null&&(t.color.colorName=e.colorName),e.isVisible!=null&&(t.visibility=e.isVisible),e.transparency!=null&&(t.transparency=e.transparency)}}class gd extends _.AcDbDatabaseConverter{constructor(e={}){super(e),e.useWorker=!0,e.parserWorkerUrl||(e.parserWorkerUrl="/assets/libredwg-parser-worker.js")}async parse(e){if(this.config.useWorker&&this.config.parserWorkerUrl){const t=_.createWorkerApi({workerUrl:this.config.parserWorkerUrl,maxConcurrentWorkers:1}),n=await t.execute(e);return t.destroy(),n.data}else throw new Error("dwg converter can run in web worker only!")}getFonts(e){const t=new Map;e.tables.BLOCK_RECORD.entries.forEach(o=>{t.set(o.name,o)});const n=new Map,s=o=>{if(o){const a=o.lastIndexOf(".");return a>=0?o.substring(0,a).toLowerCase():o.toLowerCase()}};e.tables.STYLE.entries.forEach(o=>{const a=[];let c=s(o.font);c&&a.push(c),c=s(o.bigFont),c&&a.push(c),n.set(o.name,a)});const i=new Set;return this.getFontsInBlock(e.entities,t,n,i),Array.from(i)}getFontsInBlock(e,t,n,s){const i=/\\f(.*?)\|/g;e.forEach(o=>{if(o.type=="MTEXT"){const a=o;[...a.text.matchAll(i)].forEach(h=>{s.add(h[1].toLowerCase())});const c=n.get(a.styleName);c==null||c.forEach(h=>s.add(h))}else if(o.type=="TEXT"){const a=o,c=n.get(a.styleName);c==null||c.forEach(h=>s.add(h))}else if(o.type=="INSERT"){const a=o,c=t.get(a.name);c&&this.getFontsInBlock(c.entities,t,n,s)}})}processLineTypes(e,t){e.tables.LTYPE.entries.forEach(n=>{const s={name:n.name,description:n.description,standardFlag:n.standardFlag,totalPatternLength:n.totalPatternLength,pattern:n.pattern},i=new _.AcDbLinetypeTableRecord(s);this.processCommonTableEntryAttrs(n,i),i.name=n.name,t.tables.linetypeTable.add(i)})}processTextStyles(e,t){e.tables.STYLE.entries.forEach(n=>{const s=new _.AcDbTextStyleTableRecord(n);this.processCommonTableEntryAttrs(n,s),t.tables.textStyleTable.add(s)})}processDimStyles(e,t){e.tables.DIMSTYLE.entries.forEach(n=>{const s={name:n.name,ownerId:n.ownerHandle.toString(),dimpost:n.DIMPOST||"",dimapost:n.DIMAPOST||"",dimscale:n.DIMSCALE,dimasz:n.DIMASZ,dimexo:n.DIMEXO,dimdli:n.DIMDLI,dimexe:n.DIMEXE,dimrnd:n.DIMRND,dimdle:n.DIMDLE,dimtp:n.DIMTP,dimtm:n.DIMTM,dimtxt:n.DIMTXT,dimcen:n.DIMCEN,dimtsz:n.DIMTSZ,dimaltf:n.DIMALTF,dimlfac:n.DIMLFAC,dimtvp:n.DIMTVP,dimtfac:n.DIMTFAC,dimgap:n.DIMGAP,dimaltrnd:n.DIMALTRND,dimtol:n.DIMTOL==null||n.DIMTOL==0?0:1,dimlim:n.DIMLIM==null||n.DIMLIM==0?0:1,dimtih:n.DIMTIH==null||n.DIMTIH==0?0:1,dimtoh:n.DIMTOH==null||n.DIMTOH==0?0:1,dimse1:n.DIMSE1==null||n.DIMSE1==0?0:1,dimse2:n.DIMSE2==null||n.DIMSE2==0?0:1,dimtad:n.DIMTAD,dimzin:n.DIMZIN,dimazin:n.DIMAZIN,dimalt:n.DIMALT,dimaltd:n.DIMALTD,dimtofl:n.DIMTOFL,dimsah:n.DIMSAH,dimtix:n.DIMTIX,dimsoxd:n.DIMSOXD,dimclrd:n.DIMCLRD,dimclre:n.DIMCLRE,dimclrt:n.DIMCLRT,dimadec:n.DIMADEC||0,dimunit:n.DIMUNIT||2,dimdec:n.DIMDEC,dimtdec:n.DIMTDEC,dimaltu:n.DIMALTU,dimalttd:n.DIMALTTD,dimaunit:n.DIMAUNIT,dimfrac:n.DIMFRAC,dimlunit:n.DIMLUNIT,dimdsep:n.DIMDSEP,dimtmove:n.DIMTMOVE||0,dimjust:n.DIMJUST,dimsd1:n.DIMSD1,dimsd2:n.DIMSD2,dimtolj:n.DIMTOLJ,dimtzin:n.DIMTZIN,dimaltz:n.DIMALTZ,dimalttz:n.DIMALTTZ,dimfit:n.DIMFIT||0,dimupt:n.DIMUPT,dimatfit:n.DIMATFIT,dimtxsty:"Standard",dimldrblk:"",dimblk:n.DIMBLK||"",dimblk1:n.DIMBLK1||"",dimblk2:n.DIMBLK2||"",dimlwd:n.DIMLWD,dimlwe:n.DIMLWE},i=new _.AcDbDimStyleTableRecord(s);this.processCommonTableEntryAttrs(n,i),t.tables.dimStyleTable.add(i)})}processLayers(e,t){e.tables.LAYER.entries.forEach(n=>{const s=new _.AcCmColor;s.colorIndex=n.colorIndex;const i=new _.AcDbLayerTableRecord({name:n.name,standardFlags:n.standardFlag,linetype:n.lineType,lineWeight:n.lineweight,isOff:n.off,color:s,isPlottable:n.plotFlag!=0});this.processCommonTableEntryAttrs(n,i),t.tables.layerTable.add(i)})}processViewports(e,t){e.tables.VPORT.entries.forEach(n=>{const s=new _.AcDbViewportTableRecord;this.processCommonTableEntryAttrs(n,s),n.circleSides&&(s.circleSides=n.circleSides),s.standardFlag=n.standardFlag,s.center.copy(n.center),s.lowerLeftCorner.copy(n.lowerLeftCorner),s.upperRightCorner.copy(n.upperRightCorner),n.snapBasePoint&&s.snapBase.copy(n.snapBasePoint),n.snapRotationAngle&&(s.snapAngle=n.snapRotationAngle),n.snapSpacing&&s.snapIncrements.copy(n.snapSpacing),n.majorGridLines&&(s.gridMajor=n.majorGridLines),n.gridSpacing&&s.gridIncrements.copy(n.gridSpacing),n.backgroundObjectId&&(s.backgroundObjectId=n.backgroundObjectId),s.gsView.center.copy(n.center),s.gsView.viewDirectionFromTarget.copy(n.viewDirectionFromTarget),s.gsView.viewTarget.copy(n.viewTarget),n.lensLength&&(s.gsView.lensLength=n.lensLength),n.frontClippingPlane&&(s.gsView.frontClippingPlane=n.frontClippingPlane),n.backClippingPlane&&(s.gsView.backClippingPlane=n.backClippingPlane),n.viewHeight&&(s.gsView.viewHeight=n.viewHeight),n.viewTwistAngle&&(s.gsView.viewTwistAngle=n.viewTwistAngle),n.frozenLayers&&(s.gsView.frozenLayers=n.frozenLayers),n.styleSheet&&(s.gsView.styleSheet=n.styleSheet),n.renderMode&&(s.gsView.renderMode=n.renderMode),n.viewMode&&(s.gsView.viewMode=n.viewMode),n.ucsIconSetting&&(s.gsView.ucsIconSetting=n.ucsIconSetting),n.ucsOrigin&&s.gsView.ucsOrigin.copy(n.ucsOrigin),n.ucsXAxis&&s.gsView.ucsXAxis.copy(n.ucsXAxis),n.ucsYAxis&&s.gsView.ucsYAxis.copy(n.ucsYAxis),n.orthographicType&&(s.gsView.orthographicType=n.orthographicType),n.shadePlotSetting&&(s.gsView.shadePlotSetting=n.shadePlotSetting),n.shadePlotObjectId&&(s.gsView.shadePlotObjectId=n.shadePlotObjectId),n.visualStyleObjectId&&(s.gsView.visualStyleObjectId=n.visualStyleObjectId),n.isDefaultLightingOn&&(s.gsView.isDefaultLightingOn=n.isDefaultLightingOn),n.defaultLightingType&&(s.gsView.defaultLightingType=n.defaultLightingType),n.brightness&&(s.gsView.brightness=n.brightness),n.contrast&&(s.gsView.contrast=n.contrast),n.ambientColor&&(s.gsView.ambientColor=n.ambientColor),t.tables.viewportTable.add(s)})}processBlockTables(e,t){e.tables.BLOCK_RECORD.entries.forEach(n=>{let s=t.tables.blockTable.getAt(n.name);s||(s=new _.AcDbBlockTableRecord,s.objectId=n.handle.toString(),s.name=n.name,s.ownerId=n.ownerHandle.toString(),s.origin.copy(n.basePoint),s.layoutId=n.layout.toString(),t.tables.blockTable.add(s)),!s.isModelSapce&&!s.isPaperSapce&&n.entities&&n.entities.length>0&&this.processEntitiesInBlock(n.entities,s)})}processBlocks(e,t){}async processEntitiesInBlock(e,t){const n=new to,s=e.length,i=[];for(let o=0;o<s;o++){const a=e[o],c=n.convert(a);c&&i.push(c)}t.appendEntity(i)}async processEntities(e,t,n,s,i){const o=new to;let a=e.entities;const c=a.length,h=new _.AcDbBatchProcessing(c,100-s.value,n);this.config.convertByEntityType&&(a=this.groupAndFlattenByType(a));const l=t.tables.blockTable.modelSpace;await h.processChunk(async(d,u)=>{const p=[];for(let f=d;f<u;f++){const m=a[f],y=o.convert(m);y&&p.push(y)}if(l.appendEntity(p),i){let f=s.value+u/c*(100-s.value);f>100&&(f=100),await i(f,"ENTITY","IN-PROGRESS")}})}processHeader(e,t){const n=e.header;t.cecolor.colorIndex=n.CECOLOR||256,t.angBase=n.ANGBASE??0,t.angDir=n.ANGDIR??0,t.aunits=n.AUNITS??0,n.EXTMAX&&(t.extmax=n.EXTMAX),n.EXTMIN&&(t.extmin=n.EXTMIN),t.insunits=n.INSUNITS??1,t.pdmode=n.PDMODE??0,t.pdsize=n.PDSIZE??0}processCommonTableEntryAttrs(e,t){t.name=e.name,t.objectId=e.handle.toString(),t.ownerId=e.ownerHandle.toString()}processObjects(e,t){this.processLayouts(e,t),this.processImageDefs(e,t)}processLayouts(e,t){const n=t.dictionaries.layouts;e.objects.LAYOUT.forEach(s=>{const i=new _.AcDbLayout;i.layoutName=s.layoutName,i.tabOrder=s.tabOrder;const o=t.tables.blockTable.newIterator();i.objectId=s.handle.toString();for(const a of o)if(a.layoutId===i.objectId){i.blockTableRecordId=a.objectId;break}i.limits.min.copy(s.minLimit),i.limits.max.copy(s.maxLimit),i.extents.min.copy(s.minExtent),i.extents.max.copy(s.maxExtent),this.processCommonObjectAttrs(s,i),n.setAt(i.layoutName,i)})}processImageDefs(e,t){const n=t.dictionaries.imageDefs;e.objects.IMAGEDEF.forEach(s=>{const i=new _.AcDbRasterImageDef;i.sourceFileName=s.fileName,this.processCommonObjectAttrs(s,i),n.setAt(i.objectId,i)})}processCommonObjectAttrs(e,t){t.objectId=e.handle.toString(),t.ownerId=e.ownerHandle.toString()}groupAndFlattenByType(e){const t={},n=[];for(const s of e)t[s.type]||(t[s.type]=[],n.push(s.type)),t[s.type].push(s);return n.flatMap(s=>t[s])}}function no(){try{const r=new _.AcDbDxfConverter({convertByEntityType:!1,useWorker:!0,parserWorkerUrl:"./assets/dxf-parser-worker.js"});_.AcDbDatabaseConverterManager.instance.register(_.AcDbFileType.DXF,r)}catch(r){console.error("Failed to register dxf converter: ",r)}try{const r=new gd({convertByEntityType:!1,useWorker:!0,parserWorkerUrl:"./assets/libredwg-parser-worker.js"});_.AcDbDatabaseConverterManager.instance.register(_.AcDbFileType.DWG,r)}catch(r){console.error("Failed to register dwg converter: ",r)}}function md(){no(),typeof window<"u"&&!!window.location&&(window.location.hostname==="localhost"||window.location.hostname==="127.0.0.1")?on.getInstance().initialize("/assets/mtext-renderer-worker.js"):on.getInstance().initialize("./mtext-renderer-worker.js")}const yd={isDebug:!1,isShowCommandLine:!0,isShowCoordinate:!0,isShowToolbar:!0,isShowStats:!1,fontMapping:{}},ro="settings";class dt{constructor(){this.events={modified:new _.AcCmEventManager}}static get instance(){return this._instance||(this._instance=new dt),this._instance}set(e,t){const n=this.settings;n[e]=t,localStorage.setItem(ro,JSON.stringify(n)),this.events.modified.dispatch({key:e,value:t})}get(e){return this.settings[e]}toggle(e){const t=this.get(e);this.set(e,!t)}get isDebug(){return this.get("isDebug")}set isDebug(e){this.set("isDebug",e)}get isShowCommandLine(){return this.get("isShowCommandLine")}set isShowCommandLine(e){this.set("isShowCommandLine",e)}get isShowCoordinate(){return this.get("isShowCoordinate")}set isShowCoordinate(e){this.set("isShowCoordinate",e)}get isShowToolbar(){return this.get("isShowToolbar")}set isShowToolbar(e){this.set("isShowToolbar",e)}get isShowStats(){return this.get("isShowStats")}set isShowStats(e){this.set("isShowStats",e)}get fontMapping(){return this.get("fontMapping")}set fontMapping(e){this.set("fontMapping",e)}setFontMapping(e,t){const n=this.get("fontMapping");n[e]=t,this.set("fontMapping",n)}get settings(){const e=localStorage.getItem(ro),t=e==null?{}:JSON.parse(e);return gn.defaults(t,yd)}}v.AcApContext=Sr,v.AcApConvertToSvgCmd=Br,v.AcApDocManager=le,v.AcApDocument=Ar,v.AcApOpenCmd=Lr,v.AcApPanCmd=Ur,v.AcApQNewCmd=Mr,v.AcApSelectCmd=Or,v.AcApSettingManager=dt,v.AcApZoomCmd=Dr,v.AcApZoomToBoxCmd=Fr,v.AcApZoomToBoxJig=Rr,v.AcEdBaseView=Er,v.AcEdCommand=Be,v.AcEdCommandStack=ce,v.AcEdConditionWaiter=_r,v.AcEdCorsorType=qe,v.AcEdCursorManager=Tr,v.AcEdJig=Cr,v.AcEdSelectionSet=kr,v.AcEdViewMode=Ie,v.AcEditor=Ir,v.AcTrView2d=eo,v.DEFAULT_VIEW_2D_OPTIONS=vr,v.acedAlert=fo,v.eventBus=Ce,v.registerConverters=no,v.registerWorkers=md,Object.defineProperty(v,Symbol.toStringTag,{value:"Module"})});
|
|
@@ -91,7 +91,7 @@ var AcApFontLoader = /** @class */ (function () {
|
|
|
91
91
|
switch (_b.label) {
|
|
92
92
|
case 0:
|
|
93
93
|
if (!(this._avaiableFonts.length == 0)) return [3 /*break*/, 6];
|
|
94
|
-
baseUrl_1 = 'https://
|
|
94
|
+
baseUrl_1 = 'https://mlightcad.gitlab.io/cad-data/fonts/';
|
|
95
95
|
fontMetaDataUrl = baseUrl_1 + 'fonts.json';
|
|
96
96
|
_b.label = 1;
|
|
97
97
|
case 1:
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AcApFontLoader.js","sourceRoot":"","sources":["../../src/app/AcApFontLoader.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEA,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,WAAW,CAAA;AAE3C,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAA;AAEpC;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH;IAME;;;;OAIG;IACH,wBAAY,QAAsB;QAChC,IAAI,CAAC,YAAY,GAAG,QAAQ,CAAA;QAC5B,IAAI,CAAC,cAAc,GAAG,EAAE,CAAA;IAC1B,CAAC;IAKD,sBAAI,yCAAa;QAHjB;;WAEG;aACH;YACE,OAAO,IAAI,CAAC,cAAc,CAAA;QAC5B,CAAC;;;OAAA;IAED;;OAEG;IACG,yCAAgB,GAAtB;;;;;;6BACM,CAAA,IAAI,CAAC,cAAc,CAAC,MAAM,IAAI,CAAC,CAAA,EAA/B,wBAA+B;wBAC3B,YAAU,
|
|
1
|
+
{"version":3,"file":"AcApFontLoader.js","sourceRoot":"","sources":["../../src/app/AcApFontLoader.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEA,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,WAAW,CAAA;AAE3C,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAA;AAEpC;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH;IAME;;;;OAIG;IACH,wBAAY,QAAsB;QAChC,IAAI,CAAC,YAAY,GAAG,QAAQ,CAAA;QAC5B,IAAI,CAAC,cAAc,GAAG,EAAE,CAAA;IAC1B,CAAC;IAKD,sBAAI,yCAAa;QAHjB;;WAEG;aACH;YACE,OAAO,IAAI,CAAC,cAAc,CAAA;QAC5B,CAAC;;;OAAA;IAED;;OAEG;IACG,yCAAgB,GAAtB;;;;;;6BACM,CAAA,IAAI,CAAC,cAAc,CAAC,MAAM,IAAI,CAAC,CAAA,EAA/B,wBAA+B;wBAC3B,YAAU,6CAA6C,CAAA;wBACvD,eAAe,GAAG,SAAO,GAAG,YAAY,CAAA;;;;wBAE3B,qBAAM,KAAK,CAAC,eAAe,CAAC,EAAA;;wBAAvC,QAAQ,GAAG,SAA4B;wBAC7C,KAAA,IAAI,CAAA;wBAAmB,qBAAM,QAAQ,CAAC,IAAI,EAAE,EAAA;;wBAA5C,GAAK,cAAc,GAAG,CAAC,SAAqB,CAAmB,CAAA;;;;wBAE/D,QAAQ,CAAC,IAAI,CAAC,8BAA8B,EAAE;4BAC5C,GAAG,EAAE,eAAe;yBACrB,CAAC,CAAA;;;wBAGJ,IAAI,CAAC,cAAc,CAAC,OAAO,CAAC,UAAA,IAAI;4BAC9B,IAAI,CAAC,GAAG,GAAG,SAAO,GAAG,IAAI,CAAC,IAAI,CAAA;wBAChC,CAAC,CAAC,CAAA;;4BAEJ,sBAAO,IAAI,CAAC,cAAc,EAAA;;;;KAC3B;IAED;;OAEG;IACG,6BAAI,GAAV,UAAW,SAAmB;;;;;;4BAC5B,qBAAM,IAAI,CAAC,gBAAgB,EAAE,EAAA;;wBAA7B,SAA6B,CAAA;wBAEvB,IAAI,GAAa,EAAE,CAAA;wBACzB,SAAS,CAAC,OAAO,CAAC,UAAA,IAAI;4BACpB,IAAM,iBAAiB,GAAG,IAAI,CAAC,WAAW,EAAE,CAAA;4BAC5C,IAAM,MAAM,GAAG,IAAI,CAAC,KAAI,CAAC,cAAc,EAAE,UAAC,IAAkB;gCAC1D,OAAO,CACL,SAAS,CAAC,IAAI,CAAC,IAAI,EAAE,UAAA,IAAI;oCACvB,OAAO,IAAI,CAAC,WAAW,EAAE,IAAI,iBAAiB,CAAA;gCAChD,CAAC,CAAC,IAAI,CAAC,CACR,CAAA;4BACH,CAAC,CAAC,CAAA;4BACF,IAAI,MAAM;gCAAE,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,CAAA;wBACnC,CAAC,CAAC,CAAA;wBACiB,qBAAM,IAAI,CAAC,YAAY,CAAC,SAAS,CAAC,IAAI,CAAC,EAAA;;wBAApD,UAAU,GAAG,SAAuC;wBAC1D,UAAU,CAAC,OAAO,CAAC,UAAA,IAAI;4BACrB,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC;gCACjB,QAAQ,CAAC,IAAI,CAAC,iBAAiB,EAAE;oCAC/B,QAAQ,EAAE,IAAI,CAAC,QAAQ;oCACvB,GAAG,EAAE,IAAI,CAAC,GAAG;iCACd,CAAC,CAAA;4BACJ,CAAC;wBACH,CAAC,CAAC,CAAA;;;;;KACH;IACH,qBAAC;AAAD,CAAC,AA1ED,IA0EC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mlightcad/cad-simple-viewer",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.11",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"repository": {
|
|
@@ -38,16 +38,16 @@
|
|
|
38
38
|
"@types/lodash-es": "^4.17.12",
|
|
39
39
|
"@types/rbush": "^3.0.4",
|
|
40
40
|
"@types/three": "^0.172.0",
|
|
41
|
-
"@mlightcad/svg-renderer": "0.0.
|
|
42
|
-
"@mlightcad/three-renderer": "1.1.
|
|
41
|
+
"@mlightcad/svg-renderer": "0.0.22",
|
|
42
|
+
"@mlightcad/three-renderer": "1.1.10"
|
|
43
43
|
},
|
|
44
44
|
"dependencies": {
|
|
45
|
-
"@mlightcad/libredwg-converter": "3.0.
|
|
45
|
+
"@mlightcad/libredwg-converter": "3.0.24",
|
|
46
46
|
"mitt": "^3.0.1",
|
|
47
47
|
"rbush": "^4.0.1"
|
|
48
48
|
},
|
|
49
49
|
"peerDependencies": {
|
|
50
|
-
"@mlightcad/data-model": "1.2.
|
|
50
|
+
"@mlightcad/data-model": "1.2.24",
|
|
51
51
|
"three": "^0.172.0",
|
|
52
52
|
"lodash-es": "4.17.21"
|
|
53
53
|
},
|