@mlightcad/libredwg-converter 3.5.20 → 3.5.21

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/LICENSE CHANGED
@@ -1,21 +1,21 @@
1
- MIT License
2
-
3
- Copyright (c) 2025 mlight-lee
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
1
+ MIT License
2
+
3
+ Copyright (c) 2025 mlight-lee
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,53 +1,53 @@
1
- # @mlightcad/libredwg-converter
2
-
3
- The `libredwg-converter` package provides a DWG file converter for the RealDWG-Web ecosystem, enabling reading and conversion of DWG files into the AutoCAD-like drawing database structure. It is based on the [LibreDWG](https://www.gnu.org/software/libredwg/) library compiled to WebAssembly.
4
-
5
- ## Overview
6
-
7
- This package implements a DWG file converter compatible with the RealDWG-Web data model. It allows you to register DWG file support in your application and convert DWG files into the in-memory drawing database.
8
-
9
- ## Key Features
10
-
11
- - **DWG File Support**: Read and convert DWG files to the drawing database
12
- - **Integration**: Designed to work with the RealDWG-Web data model and converter manager
13
- - **WebAssembly Powered**: Uses LibreDWG compiled to WASM for fast, browser-compatible parsing
14
-
15
- ## Installation
16
-
17
- ```bash
18
- npm install @mlightcad/libredwg-converter
19
- ```
20
-
21
- > **Peer dependencies:**
22
- > - `@mlightcad/data-model`
23
- > - `@mlightcad/libredwg-web`
24
-
25
- ## Usage Example
26
-
27
- ```typescript
28
- import { AcDbDatabaseConverterManager, AcDbFileType } from '@mlightcad/data-model';
29
- import { AcDbLibreDwgConverter } from '@mlightcad/libredwg-converter';
30
-
31
- // WASM module loading (async)
32
- import('@mlightcad/libredwg-web/wasm/libredwg-web').then(libredwgModule => {
33
- const dwgConverter = new AcDbLibreDwgConverter(libredwgModule);
34
- AcDbDatabaseConverterManager.instance.register(AcDbFileType.DWG, dwgConverter);
35
- });
36
- ```
37
-
38
- ## API
39
-
40
- - **AcDbLibreDwgConverter**: Main converter class for DWG files (extends `AcDbDatabaseConverter`)
41
-
42
- ## Dependencies
43
-
44
- - **@mlightcad/data-model**: Drawing database and entity definitions
45
- - **@mlightcad/libredwg-web**: WASM wrapper for LibreDWG
46
-
47
- ## API Documentation
48
-
49
- For detailed API documentation, visit the [RealDWG-Web documentation](https://mlight-lee.github.io/realdwg-web/).
50
-
51
- ## Contributing
52
-
1
+ # @mlightcad/libredwg-converter
2
+
3
+ The `libredwg-converter` package provides a DWG file converter for the RealDWG-Web ecosystem, enabling reading and conversion of DWG files into the AutoCAD-like drawing database structure. It is based on the [LibreDWG](https://www.gnu.org/software/libredwg/) library compiled to WebAssembly.
4
+
5
+ ## Overview
6
+
7
+ This package implements a DWG file converter compatible with the RealDWG-Web data model. It allows you to register DWG file support in your application and convert DWG files into the in-memory drawing database.
8
+
9
+ ## Key Features
10
+
11
+ - **DWG File Support**: Read and convert DWG files to the drawing database
12
+ - **Integration**: Designed to work with the RealDWG-Web data model and converter manager
13
+ - **WebAssembly Powered**: Uses LibreDWG compiled to WASM for fast, browser-compatible parsing
14
+
15
+ ## Installation
16
+
17
+ ```bash
18
+ npm install @mlightcad/libredwg-converter
19
+ ```
20
+
21
+ > **Peer dependencies:**
22
+ > - `@mlightcad/data-model`
23
+ > - `@mlightcad/libredwg-web`
24
+
25
+ ## Usage Example
26
+
27
+ ```typescript
28
+ import { AcDbDatabaseConverterManager, AcDbFileType } from '@mlightcad/data-model';
29
+ import { AcDbLibreDwgConverter } from '@mlightcad/libredwg-converter';
30
+
31
+ // WASM module loading (async)
32
+ import('@mlightcad/libredwg-web/wasm/libredwg-web').then(libredwgModule => {
33
+ const dwgConverter = new AcDbLibreDwgConverter(libredwgModule);
34
+ AcDbDatabaseConverterManager.instance.register(AcDbFileType.DWG, dwgConverter);
35
+ });
36
+ ```
37
+
38
+ ## API
39
+
40
+ - **AcDbLibreDwgConverter**: Main converter class for DWG files (extends `AcDbDatabaseConverter`)
41
+
42
+ ## Dependencies
43
+
44
+ - **@mlightcad/data-model**: Drawing database and entity definitions
45
+ - **@mlightcad/libredwg-web**: WASM wrapper for LibreDWG
46
+
47
+ ## API Documentation
48
+
49
+ For detailed API documentation, visit the [RealDWG-Web documentation](https://mlight-lee.github.io/realdwg-web/).
50
+
51
+ ## Contributing
52
+
53
53
  This package is part of the RealDWG-Web monorepo. Please refer to the main project README for contribution guidelines.
@@ -1,5 +1,5 @@
1
- import { AcDbFace as v, AcDbArc as O, AcGeVector3d as D, AcDbCircle as m, AcDbEllipse as k, AcDbLine as F, AcGePoint3d as w, AcDbSpline as T, AcDbPoint as R, AcDbTrace as V, AcDbPolyline as N, AcGePoint2d as b, AcDbPolygonMesh as B, AcDbPolyFaceMesh as z, AcDbPoly2dType as A, AcDb2dPolyline as j, AcDbPoly3dType as y, AcDb3dPolyline as W, AcDbHatch as H, AcGePolyline2d as X, AcGeLine2d as U, AcGeCircArc2d as G, AcGeVector2d as Y, AcGeEllipseArc2d as _, AcGeSpline3d as P, AcGeLoop2d as E, AcDbTable as Z, AcDbText as K, AcDbMText as q, AcDbLeader as J, AcDbAlignedDimension as Q, AcDb3PointAngularDimension as $, AcDbOrdinateDimension as ee, AcDbRadialDimension as ne, AcDbDiametricDimension as oe, AcDbRasterImage as te, AcDbWipeout as se, AcDbViewport as re, AcDbRay as ie, AcDbXline as ce, AcDbAttributeFlags as I, AcDbAttributeMTextFlag as M, AcDbAttribute as le, AcDbAttributeDefinition as ae, AcDbBlockReference as de, AcCmTransparency as pe, AcDbDatabaseConverter as ue, createWorkerApi as fe, AcDbLinetypeTableRecord as he, AcDbTextStyleTableRecord as ge, DEFAULT_TEXT_STYLE as L, AcDbDimStyleTableRecord as De, AcCmColor as Ae, AcDbLayerTableRecord as Ie, AcDbViewportTableRecord as ye, AcDbBlockTableRecord as we, AcDbBatchProcessing as Te, AcDbLayout as be, AcDbRasterImageDef as Pe } from "@mlightcad/data-model";
2
- class S {
1
+ import { AcDbFace as v, AcDbArc as O, AcGeVector3d as D, AcDbCircle as m, AcDbEllipse as k, AcDbLine as F, AcGePoint3d as w, AcDbSpline as T, AcDbPoint as R, AcDbTrace as V, AcDbPolyline as N, AcGePoint2d as b, AcDbPolygonMesh as B, AcDbPolyFaceMesh as z, AcDbPoly2dType as A, AcDb2dPolyline as j, AcDbPoly3dType as y, AcDb3dPolyline as W, AcDbHatch as H, AcGePolyline2d as X, AcGeLine2d as U, AcGeCircArc2d as G, AcGeVector2d as Y, AcGeEllipseArc2d as _, AcGeSpline3d as P, AcGeLoop2d as E, AcDbTable as Z, AcDbText as K, AcDbMText as q, AcDbLeader as J, AcDbAlignedDimension as Q, AcDb3PointAngularDimension as $, AcDbOrdinateDimension as ee, AcDbRadialDimension as ne, AcDbDiametricDimension as oe, AcDbRasterImage as te, AcDbWipeout as se, AcDbViewport as re, AcDbRay as ie, AcDbXline as ce, AcDbAttributeFlags as I, AcDbAttributeMTextFlag as M, AcDbAttribute as le, AcDbAttributeDefinition as ae, AcDbBlockReference as de, AcCmTransparency as pe, AcDbDatabaseConverter as ue, createWorkerApi as fe, AcDbLinetypeTableRecord as he, AcDbTextStyleTableRecord as ge, DEFAULT_TEXT_STYLE as L, AcDbDimStyleTableRecord as De, AcCmColor as Ae, AcDbLayerTableRecord as Ie, AcDbViewportTableRecord as ye, AcDbBlockTableRecord as we, AcDbBatchProcessing as Te, ByLayer as be, AcDbLayout as Pe, AcDbRasterImageDef as Ee } from "@mlightcad/data-model";
2
+ class C {
3
3
  convert(e) {
4
4
  const n = this.createEntity(e);
5
5
  return n && this.processCommonAttrs(e, n), n;
@@ -364,8 +364,8 @@ class S {
364
364
  }
365
365
  }
366
366
  }
367
- const Ee = "*MODEL_SPACE";
368
- class Le extends ue {
367
+ const Me = "*MODEL_SPACE";
368
+ class Ce extends ue {
369
369
  constructor(e = {}) {
370
370
  super(e), e.useWorker = !0, e.parserWorkerUrl || (e.parserWorkerUrl = "/assets/libredwg-parser-worker.js");
371
371
  }
@@ -547,7 +547,7 @@ class Le extends ue {
547
547
  processBlocks(e, n) {
548
548
  }
549
549
  async processEntitiesInBlock(e, n) {
550
- const t = new S(), o = e.length, s = [];
550
+ const t = new C(), o = e.length, s = [];
551
551
  for (let r = 0; r < o; r++) {
552
552
  const a = e[r], c = t.convert(a);
553
553
  c && s.push(c);
@@ -555,7 +555,7 @@ class Le extends ue {
555
555
  n.appendEntity(s);
556
556
  }
557
557
  async processEntities(e, n, t, o, s) {
558
- const r = new S();
558
+ const r = new C();
559
559
  let a = [];
560
560
  e.tables.BLOCK_RECORD.entries.forEach((l) => {
561
561
  this.isModelSpace(l.name) && (a = l.entities);
@@ -581,7 +581,7 @@ class Le extends ue {
581
581
  }
582
582
  processHeader(e, n) {
583
583
  const t = e.header;
584
- t.CECOLOR && (t.CECOLOR.index >= 0 && t.CECOLOR.index <= 256 ? n.cecolor.colorIndex = t.CECOLOR.index : n.cecolor.setRGBValue(t.CECOLOR.rgb)), n.angBase = t.ANGBASE ?? 0, n.angDir = t.ANGDIR ?? 0, n.aunits = t.AUNITS ?? 0, n.celtscale = t.CELTSCALE ?? 1, n.ltscale = t.LTSCALE ?? 1, t.EXTMAX && (n.extmax = t.EXTMAX), t.EXTMIN && (n.extmin = t.EXTMIN), n.insunits = t.INSUNITS ?? 1, n.pdmode = t.PDMODE ?? 0, n.pdsize = t.PDSIZE ?? 0, n.textstyle = t.TEXTSTYLE ?? L;
584
+ t.CECOLOR && (t.CECOLOR.index >= 0 && t.CECOLOR.index <= 256 ? n.cecolor.colorIndex = t.CECOLOR.index : n.cecolor.setRGBValue(t.CECOLOR.rgb)), n.angBase = t.ANGBASE ?? 0, n.angDir = t.ANGDIR ?? 0, n.aunits = t.AUNITS ?? 0, n.celtype = t.CELTYPE ?? be, n.celtscale = t.CELTSCALE ?? 1, n.ltscale = t.LTSCALE ?? 1, t.EXTMAX && (n.extmax = t.EXTMAX), t.EXTMIN && (n.extmin = t.EXTMIN), n.insunits = t.INSUNITS ?? 1, n.pdmode = t.PDMODE ?? 0, n.pdsize = t.PDSIZE ?? 0, n.textstyle = t.TEXTSTYLE ?? L;
585
585
  }
586
586
  processCommonTableEntryAttrs(e, n) {
587
587
  n.name = e.name, n.objectId = e.handle, n.ownerId = e.ownerHandle;
@@ -592,7 +592,7 @@ class Le extends ue {
592
592
  processLayouts(e, n) {
593
593
  const t = n.objects.layout;
594
594
  e.objects.LAYOUT.forEach((s) => {
595
- const r = new be();
595
+ const r = new Pe();
596
596
  r.layoutName = s.layoutName, r.tabOrder = s.tabOrder;
597
597
  const a = n.tables.blockTable.newIterator();
598
598
  r.objectId = s.handle;
@@ -607,7 +607,7 @@ class Le extends ue {
607
607
  processImageDefs(e, n) {
608
608
  const t = n.objects.imageDefinition;
609
609
  e.objects.IMAGEDEF.forEach((s) => {
610
- const r = new Pe();
610
+ const r = new Ee();
611
611
  r.sourceFileName = s.fileName, this.processCommonObjectAttrs(s, r), t.setAt(r.objectId, r);
612
612
  });
613
613
  }
@@ -621,9 +621,9 @@ class Le extends ue {
621
621
  return t.flatMap((o) => n[o]);
622
622
  }
623
623
  isModelSpace(e) {
624
- return e && e.toUpperCase() == Ee;
624
+ return e && e.toUpperCase() == Me;
625
625
  }
626
626
  }
627
627
  export {
628
- Le as AcDbLibreDwgConverter
628
+ Ce as AcDbLibreDwgConverter
629
629
  };
@@ -1 +1 @@
1
- (function(D,r){typeof exports=="object"&&typeof module<"u"?r(exports,require("@mlightcad/data-model")):typeof define=="function"&&define.amd?define(["exports","@mlightcad/data-model"],r):(D=typeof globalThis<"u"?globalThis:D||self,r(D["libredwg-converter"]={},D.dataModel))})(this,function(D,r){"use strict";class y{convert(e){const n=this.createEntity(e);return n&&this.processCommonAttrs(e,n),n}createEntity(e){return e.type=="3DFACE"?this.convertFace(e):e.type=="ARC"?this.convertArc(e):e.type=="ATTDEF"?this.convertAttributeDefinition(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=="POLYLINE2D"?this.convertPolyline2d(e):e.type=="POLYLINE3D"?this.convertPolyline3d(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 n=new r.AcDbFace;return e.corner1&&n.setVertexAt(0,e.corner1),e.corner2&&n.setVertexAt(1,e.corner2),e.corner3&&n.setVertexAt(2,e.corner3),e.corner4&&n.setVertexAt(3,e.corner4),n.setEdgeInvisibilities(e.flag),n}convertArc(e){return new r.AcDbArc(e.center,e.radius,e.startAngle,e.endAngle,e.extrusionDirection??r.AcGeVector3d.Z_AXIS)}convertCirle(e){return new r.AcDbCircle(e.center,e.radius,e.extrusionDirection??r.AcGeVector3d.Z_AXIS)}convertEllipse(e){const n=new r.AcGeVector3d(e.majorAxisEndPoint),o=n.length();return new r.AcDbEllipse(e.center,e.extrusionDirection??r.AcGeVector3d.Z_AXIS,n,o,o*e.axisRatio,e.startAngle,e.endAngle)}convertLine(e){const n=e.startPoint,o=e.endPoint;return new r.AcDbLine(new r.AcGePoint3d(n.x,n.y,n.z),new r.AcGePoint3d(o.x,o.y,o.z))}convertSpline(e){try{if(e.numberOfControlPoints>0&&e.numberOfKnots>0)return new r.AcDbSpline(e.controlPoints,e.knots,e.weights,e.degree,!!(e.flag&1));if(e.numberOfFitPoints>0)return new r.AcDbSpline(e.fitPoints,"Uniform",e.degree,!!(e.flag&1))}catch{}return null}convertPoint(e){const n=new r.AcDbPoint;return n.position=e.position,n}convertSolid(e){const n=new r.AcDbTrace;return n.setPointAt(0,{...e.corner1,z:0}),n.setPointAt(1,{...e.corner2,z:0}),n.setPointAt(2,{...e.corner3,z:0}),n.setPointAt(3,e.corner4?{...e.corner4,z:0}:{...e.corner3,z:0}),n.thickness=e.thickness,n}convertLWPolyline(e){const n=new r.AcDbPolyline;return n.closed=!!(e.flag&512),e.vertices.forEach((o,s)=>{n.addVertexAt(s,new r.AcGePoint2d(o.x,o.y),o.bulge,o.startWidth,o.endWidth)}),n}convertPolyline2d(e){const n=!!(e.flag&1),o=!!(e.flag&16),s=!!(e.flag&64),t=!!(e.flag&32),i=[],p=[],l=[];if(e.vertices.map(c=>{if(!(c.flag&16))if(s&&c.flag&128)if(c.flag&64)i.push({x:c.x,y:c.y,z:c.z}),p.push(c.bulge??0);else{const u=[];c.polyfaceIndex0!=null&&c.polyfaceIndex0!=0&&u.push(Math.abs(c.polyfaceIndex0)-1),c.polyfaceIndex1!=null&&c.polyfaceIndex1!=0&&u.push(Math.abs(c.polyfaceIndex1)-1),c.polyfaceIndex2!=null&&c.polyfaceIndex2!=0&&u.push(Math.abs(c.polyfaceIndex2)-1),c.polyfaceIndex3!=null&&c.polyfaceIndex3!=0&&u.push(Math.abs(c.polyfaceIndex3)-1),u.length>=3&&l.push(u)}else i.push({x:c.x,y:c.y,z:c.z}),p.push(c.bulge??0)}),o){const c=e.meshMVertexCount??2,u=e.meshNVertexCount??2;return new r.AcDbPolygonMesh(c,u,i,n,t)}else{if(s)return new r.AcDbPolyFaceMesh(i,l);{let c=r.AcDbPoly2dType.SimplePoly;return e.flag&2?c=r.AcDbPoly2dType.FitCurvePoly:e.flag&4&&(e.smoothType==6?c=r.AcDbPoly2dType.CubicSplinePoly:e.smoothType==5&&(c=r.AcDbPoly2dType.QuadSplinePoly)),new r.AcDb2dPolyline(c,i,0,n,e.startWidth,e.endWidth,p)}}}convertPolyline3d(e){const n=!!(e.flag&1),o=[];e.vertices.map(t=>{t.flag&16||o.push({x:t.x,y:t.y,z:t.z})});let s=r.AcDbPoly3dType.SimplePoly;return e.flag&4&&(e.smoothType==6?s=r.AcDbPoly3dType.CubicSplinePoly:e.smoothType==5&&(s=r.AcDbPoly3dType.QuadSplinePoly)),new r.AcDb3dPolyline(s,o,n)}convertHatch(e){var s;const n=new r.AcDbHatch;return(s=e.definitionLines)==null||s.forEach(t=>{n.definitionLines.push({angle:t.angle,base:t.base,offset:t.offset,dashLengths:t.numberOfDashLengths>0?t.dashLengths:[]})}),n.isSolidFill=e.solidFill==1,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(t=>{if(t.boundaryPathTypeFlag&2){const p=t,l=new r.AcGePolyline2d;l.closed=p.isClosed,p.vertices.forEach((c,u)=>{l.addVertexAt(u,{x:c.x,y:c.y,bulge:c.bulge})}),n.add(l)}else{const p=t,l=[];p.edges.forEach(u=>{if(u!=null){if(u.type==1){const a=u;l.push(new r.AcGeLine2d(a.start,a.end))}else if(u.type==2){const a=u;l.push(new r.AcGeCircArc2d(a.center,a.radius,a.startAngle,a.endAngle,!a.isCCW))}else if(u.type==3){const a=u;new r.AcGeVector2d().subVectors(a.end,a.center);const f=Math.sqrt(Math.pow(a.end.x,2)+Math.pow(a.end.y,2)),h=f*a.lengthOfMinorAxis;let g=a.startAngle,A=a.endAngle;const w=Math.atan2(a.end.y,a.end.x);a.isCCW||(g=Math.PI*2-g,A=Math.PI*2-A),l.push(new r.AcGeEllipseArc2d({...a.center,z:0},f,h,g,A,!a.isCCW,w))}else if(u.type==4){const a=u;if(a.numberOfControlPoints>0&&a.numberOfKnots>0){const d=a.controlPoints.map(g=>({x:g.x,y:g.y,z:0}));let f=!0;const h=a.controlPoints.map(g=>(g.weight==null&&(f=!1),g.weight||1));l.push(new r.AcGeSpline3d(d,a.knots,f?h:void 0))}else if(a.numberOfFitData>0){const d=a.fitDatum.map(f=>({x:f.x,y:f.y,z:0}));l.push(new r.AcGeSpline3d(d,"Uniform"))}}}});const c=r.AcGeLoop2d.buildFromEdges(l);c.length==0&&l.length>0?n.add(new r.AcGeLoop2d(l)):c.forEach(u=>n.add(u))}}),n}convertTable(e){const n=new r.AcDbTable(e.name,e.rowCount,e.columnCount);return n.tableStyleId=e.tableStyleId,n.owningBlockRecordId=e.blockRecordHandle,e.directionVector&&(n.horizontalDirection=new r.AcGeVector3d(e.directionVector)),n.attachmentPoint=e.attachmentPoint,n.position.copy(e.startPoint),n.tableValueFlag=e.tableValue,n.tableOverrideFlag=e.overrideFlag,n.borderColorOverrideFlag=e.borderColorOverrideFlag,n.borderLineweightOverrideFlag=e.borderLineWeightOverrideFlag,n.borderVisibilityOverrideFlag=e.borderVisibilityOverrideFlag,e.columnWidthArr.forEach((o,s)=>n.setColumnWidth(s,o)),e.rowHeightArr.forEach((o,s)=>n.setRowHeight(s,o)),e.cells.forEach((o,s)=>{n.setCell(s,o)}),n}convertText(e){const n=new r.AcDbText;return n.textString=e.text,n.styleName=e.styleName,n.height=e.textHeight,n.position.copy(e.startPoint),n.rotation=e.rotation,n.oblique=e.obliqueAngle??0,n.thickness=e.thickness,n.horizontalMode=e.halign,n.verticalMode=e.valign,n.widthFactor=e.xScale??1,n}convertMText(e){const n=new r.AcDbMText;return n.contents=e.text,e.styleName!=null&&(n.styleName=e.styleName),n.height=e.textHeight,n.width=e.rectWidth,n.rotation=e.rotation||0,n.location=e.insertionPoint,n.attachmentPoint=e.attachmentPoint,e.direction&&(n.direction=new r.AcGeVector3d(e.direction)),n.drawingDirection=e.drawingDirection,n}convertLeader(e){const n=new r.AcDbLeader;return e.vertices.forEach(o=>{n.appendVertex(o)}),n.hasArrowHead=e.isArrowheadEnabled,n.hasHookLine=e.isHooklineExists,n.isSplined=e.isSpline,n.dimensionStyle=e.styleName,n.annoType=e.leaderCreationFlag,n}convertDimension(e){if(e.subclassMarker=="AcDbAlignedDimension"||e.subclassMarker=="AcDbRotatedDimension"){const n=e,o=new r.AcDbAlignedDimension(n.subDefinitionPoint1,n.subDefinitionPoint2,n.definitionPoint);return n.insertionPoint&&(o.dimBlockPosition={x:n.insertionPoint.x,y:n.insertionPoint.y,z:0}),o.rotation=n.rotationAngle,this.processDimensionCommonAttrs(e,o),o}else if(e.subclassMarker=="AcDb3PointAngularDimension"){const n=e,o=new r.AcDb3PointAngularDimension(n.centerPoint,n.subDefinitionPoint1,n.subDefinitionPoint2,n.definitionPoint);return this.processDimensionCommonAttrs(e,o),o}else if(e.subclassMarker=="AcDbOrdinateDimension"){const n=e,o=new r.AcDbOrdinateDimension(n.subDefinitionPoint1,n.subDefinitionPoint2);return this.processDimensionCommonAttrs(e,o),o}else if(e.subclassMarker=="AcDbRadialDimension"){const n=e,o=new r.AcDbRadialDimension(n.definitionPoint,n.centerPoint,n.leaderLength);return this.processDimensionCommonAttrs(e,o),o}else if(e.subclassMarker=="AcDbDiametricDimension"){const n=e,o=new r.AcDbDiametricDimension(n.definitionPoint,n.centerPoint,n.leaderLength);return this.processDimensionCommonAttrs(e,o),o}return null}processImage(e,n){n.position.copy(e.position),n.brightness=e.brightness,n.contrast=e.contrast,n.fade=e.fade,n.imageSize.copy(e.imageSize),n.imageDefId=e.imageDefHandle,n.isClipped=e.clipping>0,n.isShownClipped=(e.flags|4)>0,n.isImageShown=(e.flags|3)>0,n.isImageTransparent=(e.flags|8)>0,e.clippingBoundaryPath.forEach(o=>{n.clipBoundary.push(new r.AcGePoint2d(o))}),n.clipBoundaryType=e.clippingBoundaryType,n.width=Math.sqrt(e.uPixel.x**2+e.uPixel.y**2+e.uPixel.z**2)*e.imageSize.x,n.height=Math.sqrt(e.vPixel.x**2+e.vPixel.y**2+e.vPixel.z**2)*e.imageSize.y,n.rotation=Math.atan2(e.uPixel.y,e.uPixel.x)}convertImage(e){const n=new r.AcDbRasterImage;return this.processImage(e,n),n}convertWipeout(e){const n=new r.AcDbWipeout;return this.processImage(e,n),n}convertViewport(e){const n=new r.AcDbViewport;return n.number=e.viewportId,n.centerPoint.copy(e.viewportCenter),n.height=e.height,n.width=e.width,n.viewCenter.copy(e.displayCenter),n.viewHeight=e.viewHeight,n}convertRay(e){const n=new r.AcDbRay;return n.basePoint.copy(e.firstPoint),n.unitDir.copy(e.unitDirection),n}convertXline(e){const n=new r.AcDbXline;return n.basePoint.copy(e.firstPoint),n.unitDir.copy(e.unitDirection),n}convertAttributeCommon(e,n){const o=e.text;n.textString=o.text,n.styleName=o.styleName,n.height=o.textHeight,n.position.copy(o.startPoint),n.rotation=o.rotation,n.oblique=o.obliqueAngle??0,n.thickness=o.thickness,n.horizontalMode=o.halign,n.verticalMode=o.valign,n.widthFactor=o.xScale??1,n.tag=e.tag,n.fieldLength=e.fieldLength,n.isInvisible=(e.flags&r.AcDbAttributeFlags.Invisible)!==0,n.isConst=(e.flags&r.AcDbAttributeFlags.Const)!==0,n.isVerifiable=(e.flags&r.AcDbAttributeFlags.Verifiable)!==0,n.isPreset=(e.flags&r.AcDbAttributeFlags.Preset)!==0,n.lockPositionInBlock=e.lockPositionFlag,n.isReallyLocked=e.isReallyLocked,n.isMTextAttribute=(e.mtextFlag&r.AcDbAttributeMTextFlag.MultiLine)!==0,n.isConstMTextAttribute=(e.mtextFlag&r.AcDbAttributeMTextFlag.ConstMultiLine)!==0}convertAttribute(e){const n=new r.AcDbAttribute;return this.convertAttributeCommon(e,n),n}convertAttributeDefinition(e){const n=new r.AcDbAttributeDefinition;return this.convertAttributeCommon(e,n),n.prompt=e.prompt,n}convertBlockReference(e){const n=new r.AcDbBlockReference(e.name);return e.insertionPoint&&n.position.copy(e.insertionPoint),n.scaleFactors.x=e.xScale,n.scaleFactors.y=e.yScale,n.scaleFactors.z=e.zScale,n.rotation=e.rotation,n.normal.copy(e.extrusionDirection),e.attribs&&e.attribs.forEach(o=>{const s=this.convertAttribute(o);n.appendAttributes(s)}),n}processDimensionCommonAttrs(e,n){n.dimBlockId=e.name,n.textPosition.copy(e.textPoint),n.textRotation=e.textRotation||0,e.textLineSpacingFactor&&(n.textLineSpacingFactor=e.textLineSpacingFactor),e.textLineSpacingStyle&&(n.textLineSpacingStyle=e.textLineSpacingStyle),n.dimensionStyleName=e.styleName,n.dimensionText=e.text||"",n.measurement=e.measurement}processCommonAttrs(e,n){if(n.layer=e.layer||"0",n.objectId=e.handle,n.ownerId=e.ownerBlockRecordSoftId,e.lineType!=null&&(n.lineType=e.lineType),e.lineweight!=null&&(n.lineWeight=e.lineweight),e.lineTypeScale!=null&&(n.linetypeScale=e.lineTypeScale),e.color!=null&&n.color.setRGBValue(e.color),e.colorIndex!=null&&(n.color.colorIndex=e.colorIndex),e.colorName&&(n.color.colorName=e.colorName),e.isVisible!=null&&(n.visibility=e.isVisible),e.transparency!=null){const o=new r.AcCmTransparency;o.method=e.transparencyType,(o.isByBlock||o.isByBlock)&&(o.alpha=e.transparency),n.transparency=o}}}const I="*MODEL_SPACE";class b extends r.AcDbDatabaseConverter{constructor(e={}){super(e),e.useWorker=!0,e.parserWorkerUrl||(e.parserWorkerUrl="/assets/libredwg-parser-worker.js")}async parse(e,n){const o=this.config,s=this.getParserWorkerTimeout(e,n);if(o.useWorker&&o.parserWorkerUrl){const t=r.createWorkerApi({workerUrl:o.parserWorkerUrl,timeout:s,maxConcurrentWorkers:1}),i=await t.execute(e);if(t.destroy(),i.success)return i.data;throw new Error(`Failed to parse drawing due to error: '${i.error}'`)}else throw new Error("dwg converter can run in web worker only!")}getFonts(e){const n=new Map;e.tables.BLOCK_RECORD.entries.forEach(i=>{n.set(i.name,i)});const o=new Map,s=i=>{if(i){const p=i.lastIndexOf(".");return p>=0?i.substring(0,p).toLowerCase():i.toLowerCase()}};e.tables.STYLE.entries.forEach(i=>{const p=[];let l=s(i.font);l&&p.push(l),l=s(i.bigFont),l&&p.push(l),o.set(i.name,p)});const t=new Set;return this.getFontsInBlock(e.entities,n,o,t),Array.from(t)}getFontsInBlock(e,n,o,s){const t=/\\f(.*?)\|/g;e.forEach(i=>{if(i.type=="MTEXT"){const p=i;[...p.text.matchAll(t)].forEach(c=>{s.add(c[1].toLowerCase())});const l=o.get(p.styleName);l==null||l.forEach(c=>s.add(c))}else if(i.type=="TEXT"){const p=i,l=o.get(p.styleName);l==null||l.forEach(c=>s.add(c))}else if(i.type=="INSERT"){const p=i,l=n.get(p.name);l&&this.getFontsInBlock(l.entities,n,o,s)}})}processLineTypes(e,n){e.tables.LTYPE.entries.forEach(s=>{const t={name:s.name,description:s.description,standardFlag:s.standardFlag,totalPatternLength:s.totalPatternLength,pattern:s.pattern},i=new r.AcDbLinetypeTableRecord(t);this.processCommonTableEntryAttrs(s,i),i.name=s.name,n.tables.linetypeTable.add(i)})}processTextStyles(e,n){e.tables.STYLE.entries.forEach(s=>{const t=new r.AcDbTextStyleTableRecord(s);this.processCommonTableEntryAttrs(s,t),n.tables.textStyleTable.add(t)})}processDimStyles(e,n){e.tables.DIMSTYLE.entries.forEach(s=>{const t={name:s.name,ownerId:s.ownerHandle,dimpost:s.DIMPOST||"",dimapost:s.DIMAPOST||"",dimscale:s.DIMSCALE,dimasz:s.DIMASZ,dimexo:s.DIMEXO,dimdli:s.DIMDLI,dimexe:s.DIMEXE,dimrnd:s.DIMRND,dimdle:s.DIMDLE,dimtp:s.DIMTP,dimtm:s.DIMTM,dimtxt:s.DIMTXT,dimcen:s.DIMCEN,dimtsz:s.DIMTSZ,dimaltf:s.DIMALTF,dimlfac:s.DIMLFAC,dimtvp:s.DIMTVP,dimtfac:s.DIMTFAC,dimgap:s.DIMGAP,dimaltrnd:s.DIMALTRND,dimtol:s.DIMTOL==null||s.DIMTOL==0?0:1,dimlim:s.DIMLIM==null||s.DIMLIM==0?0:1,dimtih:s.DIMTIH==null||s.DIMTIH==0?0:1,dimtoh:s.DIMTOH==null||s.DIMTOH==0?0:1,dimse1:s.DIMSE1==null||s.DIMSE1==0?0:1,dimse2:s.DIMSE2==null||s.DIMSE2==0?0:1,dimtad:s.DIMTAD,dimzin:s.DIMZIN,dimazin:s.DIMAZIN,dimalt:s.DIMALT,dimaltd:s.DIMALTD,dimtofl:s.DIMTOFL,dimsah:s.DIMSAH,dimtix:s.DIMTIX,dimsoxd:s.DIMSOXD,dimclrd:s.DIMCLRD,dimclre:s.DIMCLRE,dimclrt:s.DIMCLRT,dimadec:s.DIMADEC||0,dimunit:s.DIMUNIT||2,dimdec:s.DIMDEC,dimtdec:s.DIMTDEC,dimaltu:s.DIMALTU,dimalttd:s.DIMALTTD,dimaunit:s.DIMAUNIT,dimfrac:s.DIMFRAC,dimlunit:s.DIMLUNIT,dimdsep:s.DIMDSEP||".",dimtmove:s.DIMTMOVE||0,dimjust:s.DIMJUST,dimsd1:s.DIMSD1,dimsd2:s.DIMSD2,dimtolj:s.DIMTOLJ,dimtzin:s.DIMTZIN,dimaltz:s.DIMALTZ,dimalttz:s.DIMALTTZ,dimfit:s.DIMFIT||0,dimupt:s.DIMUPT,dimatfit:s.DIMATFIT,dimtxsty:r.DEFAULT_TEXT_STYLE,dimldrblk:"",dimblk:s.DIMBLK||"",dimblk1:s.DIMBLK1||"",dimblk2:s.DIMBLK2||"",dimlwd:s.DIMLWD,dimlwe:s.DIMLWE},i=new r.AcDbDimStyleTableRecord(t);this.processCommonTableEntryAttrs(s,i),n.tables.dimStyleTable.add(i)})}processLayers(e,n){e.tables.LAYER.entries.forEach(s=>{const t=new r.AcCmColor;t.colorIndex=s.colorIndex;const i=new r.AcDbLayerTableRecord({name:s.name,standardFlags:s.standardFlag,linetype:s.lineType,lineWeight:s.lineweight,isOff:s.off,color:t,isPlottable:s.plotFlag!=0});this.processCommonTableEntryAttrs(s,i),n.tables.layerTable.add(i)})}processViewports(e,n){e.tables.VPORT.entries.forEach(s=>{const t=new r.AcDbViewportTableRecord;this.processCommonTableEntryAttrs(s,t),s.circleSides&&(t.circleSides=s.circleSides),t.standardFlag=s.standardFlag,t.center.copy(s.center),t.lowerLeftCorner.copy(s.lowerLeftCorner),t.upperRightCorner.copy(s.upperRightCorner),s.snapBasePoint&&t.snapBase.copy(s.snapBasePoint),s.snapRotationAngle&&(t.snapAngle=s.snapRotationAngle),s.snapSpacing&&t.snapIncrements.copy(s.snapSpacing),s.majorGridLines&&(t.gridMajor=s.majorGridLines),s.gridSpacing&&t.gridIncrements.copy(s.gridSpacing),s.backgroundObjectId&&(t.backgroundObjectId=s.backgroundObjectId),t.gsView.center.copy(s.center),t.gsView.viewDirectionFromTarget.copy(s.viewDirectionFromTarget),t.gsView.viewTarget.copy(s.viewTarget),s.lensLength&&(t.gsView.lensLength=s.lensLength),s.frontClippingPlane&&(t.gsView.frontClippingPlane=s.frontClippingPlane),s.backClippingPlane&&(t.gsView.backClippingPlane=s.backClippingPlane),s.viewHeight&&(t.gsView.viewHeight=s.viewHeight),s.viewTwistAngle&&(t.gsView.viewTwistAngle=s.viewTwistAngle),s.frozenLayers&&(t.gsView.frozenLayers=s.frozenLayers),s.styleSheet&&(t.gsView.styleSheet=s.styleSheet),s.renderMode&&(t.gsView.renderMode=s.renderMode),s.viewMode&&(t.gsView.viewMode=s.viewMode),s.ucsIconSetting&&(t.gsView.ucsIconSetting=s.ucsIconSetting),s.ucsOrigin&&t.gsView.ucsOrigin.copy(s.ucsOrigin),s.ucsXAxis&&t.gsView.ucsXAxis.copy(s.ucsXAxis),s.ucsYAxis&&t.gsView.ucsYAxis.copy(s.ucsYAxis),s.orthographicType&&(t.gsView.orthographicType=s.orthographicType),s.shadePlotSetting&&(t.gsView.shadePlotSetting=s.shadePlotSetting),s.shadePlotObjectId&&(t.gsView.shadePlotObjectId=s.shadePlotObjectId),s.visualStyleObjectId&&(t.gsView.visualStyleObjectId=s.visualStyleObjectId),s.isDefaultLightingOn&&(t.gsView.isDefaultLightingOn=s.isDefaultLightingOn),s.defaultLightingType&&(t.gsView.defaultLightingType=s.defaultLightingType),s.brightness&&(t.gsView.brightness=s.brightness),s.contrast&&(t.gsView.contrast=s.contrast),s.ambientColor&&(t.gsView.ambientColor=s.ambientColor),n.tables.viewportTable.add(t)})}processBlockTables(e,n){e.tables.BLOCK_RECORD.entries.forEach(s=>{let t=n.tables.blockTable.getAt(s.name);t||(t=new r.AcDbBlockTableRecord,t.objectId=s.handle,t.name=s.name,t.ownerId=s.ownerHandle,t.origin.copy(s.basePoint),t.layoutId=s.layout,t.blockInsertUnits=s.insertionUnits,t.explodability=s.explodability,t.blockScaling=s.scalability,s.bmpPreview&&(t.bmpPreview=s.bmpPreview),n.tables.blockTable.add(t)),!t.isModelSapce&&s.entities&&s.entities.length>0&&this.processEntitiesInBlock(s.entities,t)})}processBlocks(e,n){}async processEntitiesInBlock(e,n){const o=new y,s=e.length,t=[];for(let i=0;i<s;i++){const p=e[i],l=o.convert(p);l&&t.push(l)}n.appendEntity(t)}async processEntities(e,n,o,s,t){const i=new y;let p=[];e.tables.BLOCK_RECORD.entries.forEach(a=>{this.isModelSpace(a.name)&&(p=a.entities)});const l=p.length,c=new r.AcDbBatchProcessing(l,100-s.value,o);this.config.convertByEntityType&&(p=this.groupAndFlattenByType(p));const u=n.tables.blockTable.modelSpace;await c.processChunk(async(a,d)=>{const f=[];for(let h=a;h<d;h++){const g=p[h],A=i.convert(g);A&&f.push(A)}if(u.appendEntity(f),t){let h=s.value+d/l*(100-s.value);h>100&&(h=100),await t(h,"ENTITY","IN-PROGRESS")}})}processHeader(e,n){const o=e.header;o.CECOLOR&&(o.CECOLOR.index>=0&&o.CECOLOR.index<=256?n.cecolor.colorIndex=o.CECOLOR.index:n.cecolor.setRGBValue(o.CECOLOR.rgb)),n.angBase=o.ANGBASE??0,n.angDir=o.ANGDIR??0,n.aunits=o.AUNITS??0,n.celtscale=o.CELTSCALE??1,n.ltscale=o.LTSCALE??1,o.EXTMAX&&(n.extmax=o.EXTMAX),o.EXTMIN&&(n.extmin=o.EXTMIN),n.insunits=o.INSUNITS??1,n.pdmode=o.PDMODE??0,n.pdsize=o.PDSIZE??0,n.textstyle=o.TEXTSTYLE??r.DEFAULT_TEXT_STYLE}processCommonTableEntryAttrs(e,n){n.name=e.name,n.objectId=e.handle,n.ownerId=e.ownerHandle}processObjects(e,n){this.processLayouts(e,n),this.processImageDefs(e,n)}processLayouts(e,n){const o=n.objects.layout;e.objects.LAYOUT.forEach(t=>{const i=new r.AcDbLayout;i.layoutName=t.layoutName,i.tabOrder=t.tabOrder;const p=n.tables.blockTable.newIterator();i.objectId=t.handle;for(const l of p)if(l.layoutId===i.objectId){i.blockTableRecordId=l.objectId;break}i.blockTableRecordId||t.layoutName==="Model"&&(i.blockTableRecordId=n.tables.blockTable.modelSpace.objectId),i.limits.min.copy(t.minLimit),i.limits.max.copy(t.maxLimit),i.extents.min.copy(t.minExtent),i.extents.max.copy(t.maxExtent),t.viewportId&&i.viewportArray.push(t.viewportId),this.processCommonObjectAttrs(t,i),o.setAt(i.layoutName,i)})}processImageDefs(e,n){const o=n.objects.imageDefinition;e.objects.IMAGEDEF.forEach(t=>{const i=new r.AcDbRasterImageDef;i.sourceFileName=t.fileName,this.processCommonObjectAttrs(t,i),o.setAt(i.objectId,i)})}processCommonObjectAttrs(e,n){n.objectId=e.handle,n.ownerId=e.ownerHandle}groupAndFlattenByType(e){const n={},o=[];for(const s of e)n[s.type]||(n[s.type]=[],o.push(s.type)),n[s.type].push(s);return o.flatMap(s=>n[s])}isModelSpace(e){return e&&e.toUpperCase()==I}}D.AcDbLibreDwgConverter=b,Object.defineProperty(D,Symbol.toStringTag,{value:"Module"})});
1
+ (function(D,r){typeof exports=="object"&&typeof module<"u"?r(exports,require("@mlightcad/data-model")):typeof define=="function"&&define.amd?define(["exports","@mlightcad/data-model"],r):(D=typeof globalThis<"u"?globalThis:D||self,r(D["libredwg-converter"]={},D.dataModel))})(this,function(D,r){"use strict";class y{convert(e){const n=this.createEntity(e);return n&&this.processCommonAttrs(e,n),n}createEntity(e){return e.type=="3DFACE"?this.convertFace(e):e.type=="ARC"?this.convertArc(e):e.type=="ATTDEF"?this.convertAttributeDefinition(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=="POLYLINE2D"?this.convertPolyline2d(e):e.type=="POLYLINE3D"?this.convertPolyline3d(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 n=new r.AcDbFace;return e.corner1&&n.setVertexAt(0,e.corner1),e.corner2&&n.setVertexAt(1,e.corner2),e.corner3&&n.setVertexAt(2,e.corner3),e.corner4&&n.setVertexAt(3,e.corner4),n.setEdgeInvisibilities(e.flag),n}convertArc(e){return new r.AcDbArc(e.center,e.radius,e.startAngle,e.endAngle,e.extrusionDirection??r.AcGeVector3d.Z_AXIS)}convertCirle(e){return new r.AcDbCircle(e.center,e.radius,e.extrusionDirection??r.AcGeVector3d.Z_AXIS)}convertEllipse(e){const n=new r.AcGeVector3d(e.majorAxisEndPoint),o=n.length();return new r.AcDbEllipse(e.center,e.extrusionDirection??r.AcGeVector3d.Z_AXIS,n,o,o*e.axisRatio,e.startAngle,e.endAngle)}convertLine(e){const n=e.startPoint,o=e.endPoint;return new r.AcDbLine(new r.AcGePoint3d(n.x,n.y,n.z),new r.AcGePoint3d(o.x,o.y,o.z))}convertSpline(e){try{if(e.numberOfControlPoints>0&&e.numberOfKnots>0)return new r.AcDbSpline(e.controlPoints,e.knots,e.weights,e.degree,!!(e.flag&1));if(e.numberOfFitPoints>0)return new r.AcDbSpline(e.fitPoints,"Uniform",e.degree,!!(e.flag&1))}catch{}return null}convertPoint(e){const n=new r.AcDbPoint;return n.position=e.position,n}convertSolid(e){const n=new r.AcDbTrace;return n.setPointAt(0,{...e.corner1,z:0}),n.setPointAt(1,{...e.corner2,z:0}),n.setPointAt(2,{...e.corner3,z:0}),n.setPointAt(3,e.corner4?{...e.corner4,z:0}:{...e.corner3,z:0}),n.thickness=e.thickness,n}convertLWPolyline(e){const n=new r.AcDbPolyline;return n.closed=!!(e.flag&512),e.vertices.forEach((o,s)=>{n.addVertexAt(s,new r.AcGePoint2d(o.x,o.y),o.bulge,o.startWidth,o.endWidth)}),n}convertPolyline2d(e){const n=!!(e.flag&1),o=!!(e.flag&16),s=!!(e.flag&64),t=!!(e.flag&32),i=[],p=[],l=[];if(e.vertices.map(c=>{if(!(c.flag&16))if(s&&c.flag&128)if(c.flag&64)i.push({x:c.x,y:c.y,z:c.z}),p.push(c.bulge??0);else{const u=[];c.polyfaceIndex0!=null&&c.polyfaceIndex0!=0&&u.push(Math.abs(c.polyfaceIndex0)-1),c.polyfaceIndex1!=null&&c.polyfaceIndex1!=0&&u.push(Math.abs(c.polyfaceIndex1)-1),c.polyfaceIndex2!=null&&c.polyfaceIndex2!=0&&u.push(Math.abs(c.polyfaceIndex2)-1),c.polyfaceIndex3!=null&&c.polyfaceIndex3!=0&&u.push(Math.abs(c.polyfaceIndex3)-1),u.length>=3&&l.push(u)}else i.push({x:c.x,y:c.y,z:c.z}),p.push(c.bulge??0)}),o){const c=e.meshMVertexCount??2,u=e.meshNVertexCount??2;return new r.AcDbPolygonMesh(c,u,i,n,t)}else{if(s)return new r.AcDbPolyFaceMesh(i,l);{let c=r.AcDbPoly2dType.SimplePoly;return e.flag&2?c=r.AcDbPoly2dType.FitCurvePoly:e.flag&4&&(e.smoothType==6?c=r.AcDbPoly2dType.CubicSplinePoly:e.smoothType==5&&(c=r.AcDbPoly2dType.QuadSplinePoly)),new r.AcDb2dPolyline(c,i,0,n,e.startWidth,e.endWidth,p)}}}convertPolyline3d(e){const n=!!(e.flag&1),o=[];e.vertices.map(t=>{t.flag&16||o.push({x:t.x,y:t.y,z:t.z})});let s=r.AcDbPoly3dType.SimplePoly;return e.flag&4&&(e.smoothType==6?s=r.AcDbPoly3dType.CubicSplinePoly:e.smoothType==5&&(s=r.AcDbPoly3dType.QuadSplinePoly)),new r.AcDb3dPolyline(s,o,n)}convertHatch(e){var s;const n=new r.AcDbHatch;return(s=e.definitionLines)==null||s.forEach(t=>{n.definitionLines.push({angle:t.angle,base:t.base,offset:t.offset,dashLengths:t.numberOfDashLengths>0?t.dashLengths:[]})}),n.isSolidFill=e.solidFill==1,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(t=>{if(t.boundaryPathTypeFlag&2){const p=t,l=new r.AcGePolyline2d;l.closed=p.isClosed,p.vertices.forEach((c,u)=>{l.addVertexAt(u,{x:c.x,y:c.y,bulge:c.bulge})}),n.add(l)}else{const p=t,l=[];p.edges.forEach(u=>{if(u!=null){if(u.type==1){const a=u;l.push(new r.AcGeLine2d(a.start,a.end))}else if(u.type==2){const a=u;l.push(new r.AcGeCircArc2d(a.center,a.radius,a.startAngle,a.endAngle,!a.isCCW))}else if(u.type==3){const a=u;new r.AcGeVector2d().subVectors(a.end,a.center);const f=Math.sqrt(Math.pow(a.end.x,2)+Math.pow(a.end.y,2)),h=f*a.lengthOfMinorAxis;let g=a.startAngle,A=a.endAngle;const w=Math.atan2(a.end.y,a.end.x);a.isCCW||(g=Math.PI*2-g,A=Math.PI*2-A),l.push(new r.AcGeEllipseArc2d({...a.center,z:0},f,h,g,A,!a.isCCW,w))}else if(u.type==4){const a=u;if(a.numberOfControlPoints>0&&a.numberOfKnots>0){const d=a.controlPoints.map(g=>({x:g.x,y:g.y,z:0}));let f=!0;const h=a.controlPoints.map(g=>(g.weight==null&&(f=!1),g.weight||1));l.push(new r.AcGeSpline3d(d,a.knots,f?h:void 0))}else if(a.numberOfFitData>0){const d=a.fitDatum.map(f=>({x:f.x,y:f.y,z:0}));l.push(new r.AcGeSpline3d(d,"Uniform"))}}}});const c=r.AcGeLoop2d.buildFromEdges(l);c.length==0&&l.length>0?n.add(new r.AcGeLoop2d(l)):c.forEach(u=>n.add(u))}}),n}convertTable(e){const n=new r.AcDbTable(e.name,e.rowCount,e.columnCount);return n.tableStyleId=e.tableStyleId,n.owningBlockRecordId=e.blockRecordHandle,e.directionVector&&(n.horizontalDirection=new r.AcGeVector3d(e.directionVector)),n.attachmentPoint=e.attachmentPoint,n.position.copy(e.startPoint),n.tableValueFlag=e.tableValue,n.tableOverrideFlag=e.overrideFlag,n.borderColorOverrideFlag=e.borderColorOverrideFlag,n.borderLineweightOverrideFlag=e.borderLineWeightOverrideFlag,n.borderVisibilityOverrideFlag=e.borderVisibilityOverrideFlag,e.columnWidthArr.forEach((o,s)=>n.setColumnWidth(s,o)),e.rowHeightArr.forEach((o,s)=>n.setRowHeight(s,o)),e.cells.forEach((o,s)=>{n.setCell(s,o)}),n}convertText(e){const n=new r.AcDbText;return n.textString=e.text,n.styleName=e.styleName,n.height=e.textHeight,n.position.copy(e.startPoint),n.rotation=e.rotation,n.oblique=e.obliqueAngle??0,n.thickness=e.thickness,n.horizontalMode=e.halign,n.verticalMode=e.valign,n.widthFactor=e.xScale??1,n}convertMText(e){const n=new r.AcDbMText;return n.contents=e.text,e.styleName!=null&&(n.styleName=e.styleName),n.height=e.textHeight,n.width=e.rectWidth,n.rotation=e.rotation||0,n.location=e.insertionPoint,n.attachmentPoint=e.attachmentPoint,e.direction&&(n.direction=new r.AcGeVector3d(e.direction)),n.drawingDirection=e.drawingDirection,n}convertLeader(e){const n=new r.AcDbLeader;return e.vertices.forEach(o=>{n.appendVertex(o)}),n.hasArrowHead=e.isArrowheadEnabled,n.hasHookLine=e.isHooklineExists,n.isSplined=e.isSpline,n.dimensionStyle=e.styleName,n.annoType=e.leaderCreationFlag,n}convertDimension(e){if(e.subclassMarker=="AcDbAlignedDimension"||e.subclassMarker=="AcDbRotatedDimension"){const n=e,o=new r.AcDbAlignedDimension(n.subDefinitionPoint1,n.subDefinitionPoint2,n.definitionPoint);return n.insertionPoint&&(o.dimBlockPosition={x:n.insertionPoint.x,y:n.insertionPoint.y,z:0}),o.rotation=n.rotationAngle,this.processDimensionCommonAttrs(e,o),o}else if(e.subclassMarker=="AcDb3PointAngularDimension"){const n=e,o=new r.AcDb3PointAngularDimension(n.centerPoint,n.subDefinitionPoint1,n.subDefinitionPoint2,n.definitionPoint);return this.processDimensionCommonAttrs(e,o),o}else if(e.subclassMarker=="AcDbOrdinateDimension"){const n=e,o=new r.AcDbOrdinateDimension(n.subDefinitionPoint1,n.subDefinitionPoint2);return this.processDimensionCommonAttrs(e,o),o}else if(e.subclassMarker=="AcDbRadialDimension"){const n=e,o=new r.AcDbRadialDimension(n.definitionPoint,n.centerPoint,n.leaderLength);return this.processDimensionCommonAttrs(e,o),o}else if(e.subclassMarker=="AcDbDiametricDimension"){const n=e,o=new r.AcDbDiametricDimension(n.definitionPoint,n.centerPoint,n.leaderLength);return this.processDimensionCommonAttrs(e,o),o}return null}processImage(e,n){n.position.copy(e.position),n.brightness=e.brightness,n.contrast=e.contrast,n.fade=e.fade,n.imageSize.copy(e.imageSize),n.imageDefId=e.imageDefHandle,n.isClipped=e.clipping>0,n.isShownClipped=(e.flags|4)>0,n.isImageShown=(e.flags|3)>0,n.isImageTransparent=(e.flags|8)>0,e.clippingBoundaryPath.forEach(o=>{n.clipBoundary.push(new r.AcGePoint2d(o))}),n.clipBoundaryType=e.clippingBoundaryType,n.width=Math.sqrt(e.uPixel.x**2+e.uPixel.y**2+e.uPixel.z**2)*e.imageSize.x,n.height=Math.sqrt(e.vPixel.x**2+e.vPixel.y**2+e.vPixel.z**2)*e.imageSize.y,n.rotation=Math.atan2(e.uPixel.y,e.uPixel.x)}convertImage(e){const n=new r.AcDbRasterImage;return this.processImage(e,n),n}convertWipeout(e){const n=new r.AcDbWipeout;return this.processImage(e,n),n}convertViewport(e){const n=new r.AcDbViewport;return n.number=e.viewportId,n.centerPoint.copy(e.viewportCenter),n.height=e.height,n.width=e.width,n.viewCenter.copy(e.displayCenter),n.viewHeight=e.viewHeight,n}convertRay(e){const n=new r.AcDbRay;return n.basePoint.copy(e.firstPoint),n.unitDir.copy(e.unitDirection),n}convertXline(e){const n=new r.AcDbXline;return n.basePoint.copy(e.firstPoint),n.unitDir.copy(e.unitDirection),n}convertAttributeCommon(e,n){const o=e.text;n.textString=o.text,n.styleName=o.styleName,n.height=o.textHeight,n.position.copy(o.startPoint),n.rotation=o.rotation,n.oblique=o.obliqueAngle??0,n.thickness=o.thickness,n.horizontalMode=o.halign,n.verticalMode=o.valign,n.widthFactor=o.xScale??1,n.tag=e.tag,n.fieldLength=e.fieldLength,n.isInvisible=(e.flags&r.AcDbAttributeFlags.Invisible)!==0,n.isConst=(e.flags&r.AcDbAttributeFlags.Const)!==0,n.isVerifiable=(e.flags&r.AcDbAttributeFlags.Verifiable)!==0,n.isPreset=(e.flags&r.AcDbAttributeFlags.Preset)!==0,n.lockPositionInBlock=e.lockPositionFlag,n.isReallyLocked=e.isReallyLocked,n.isMTextAttribute=(e.mtextFlag&r.AcDbAttributeMTextFlag.MultiLine)!==0,n.isConstMTextAttribute=(e.mtextFlag&r.AcDbAttributeMTextFlag.ConstMultiLine)!==0}convertAttribute(e){const n=new r.AcDbAttribute;return this.convertAttributeCommon(e,n),n}convertAttributeDefinition(e){const n=new r.AcDbAttributeDefinition;return this.convertAttributeCommon(e,n),n.prompt=e.prompt,n}convertBlockReference(e){const n=new r.AcDbBlockReference(e.name);return e.insertionPoint&&n.position.copy(e.insertionPoint),n.scaleFactors.x=e.xScale,n.scaleFactors.y=e.yScale,n.scaleFactors.z=e.zScale,n.rotation=e.rotation,n.normal.copy(e.extrusionDirection),e.attribs&&e.attribs.forEach(o=>{const s=this.convertAttribute(o);n.appendAttributes(s)}),n}processDimensionCommonAttrs(e,n){n.dimBlockId=e.name,n.textPosition.copy(e.textPoint),n.textRotation=e.textRotation||0,e.textLineSpacingFactor&&(n.textLineSpacingFactor=e.textLineSpacingFactor),e.textLineSpacingStyle&&(n.textLineSpacingStyle=e.textLineSpacingStyle),n.dimensionStyleName=e.styleName,n.dimensionText=e.text||"",n.measurement=e.measurement}processCommonAttrs(e,n){if(n.layer=e.layer||"0",n.objectId=e.handle,n.ownerId=e.ownerBlockRecordSoftId,e.lineType!=null&&(n.lineType=e.lineType),e.lineweight!=null&&(n.lineWeight=e.lineweight),e.lineTypeScale!=null&&(n.linetypeScale=e.lineTypeScale),e.color!=null&&n.color.setRGBValue(e.color),e.colorIndex!=null&&(n.color.colorIndex=e.colorIndex),e.colorName&&(n.color.colorName=e.colorName),e.isVisible!=null&&(n.visibility=e.isVisible),e.transparency!=null){const o=new r.AcCmTransparency;o.method=e.transparencyType,(o.isByBlock||o.isByBlock)&&(o.alpha=e.transparency),n.transparency=o}}}const I="*MODEL_SPACE";class b extends r.AcDbDatabaseConverter{constructor(e={}){super(e),e.useWorker=!0,e.parserWorkerUrl||(e.parserWorkerUrl="/assets/libredwg-parser-worker.js")}async parse(e,n){const o=this.config,s=this.getParserWorkerTimeout(e,n);if(o.useWorker&&o.parserWorkerUrl){const t=r.createWorkerApi({workerUrl:o.parserWorkerUrl,timeout:s,maxConcurrentWorkers:1}),i=await t.execute(e);if(t.destroy(),i.success)return i.data;throw new Error(`Failed to parse drawing due to error: '${i.error}'`)}else throw new Error("dwg converter can run in web worker only!")}getFonts(e){const n=new Map;e.tables.BLOCK_RECORD.entries.forEach(i=>{n.set(i.name,i)});const o=new Map,s=i=>{if(i){const p=i.lastIndexOf(".");return p>=0?i.substring(0,p).toLowerCase():i.toLowerCase()}};e.tables.STYLE.entries.forEach(i=>{const p=[];let l=s(i.font);l&&p.push(l),l=s(i.bigFont),l&&p.push(l),o.set(i.name,p)});const t=new Set;return this.getFontsInBlock(e.entities,n,o,t),Array.from(t)}getFontsInBlock(e,n,o,s){const t=/\\f(.*?)\|/g;e.forEach(i=>{if(i.type=="MTEXT"){const p=i;[...p.text.matchAll(t)].forEach(c=>{s.add(c[1].toLowerCase())});const l=o.get(p.styleName);l==null||l.forEach(c=>s.add(c))}else if(i.type=="TEXT"){const p=i,l=o.get(p.styleName);l==null||l.forEach(c=>s.add(c))}else if(i.type=="INSERT"){const p=i,l=n.get(p.name);l&&this.getFontsInBlock(l.entities,n,o,s)}})}processLineTypes(e,n){e.tables.LTYPE.entries.forEach(s=>{const t={name:s.name,description:s.description,standardFlag:s.standardFlag,totalPatternLength:s.totalPatternLength,pattern:s.pattern},i=new r.AcDbLinetypeTableRecord(t);this.processCommonTableEntryAttrs(s,i),i.name=s.name,n.tables.linetypeTable.add(i)})}processTextStyles(e,n){e.tables.STYLE.entries.forEach(s=>{const t=new r.AcDbTextStyleTableRecord(s);this.processCommonTableEntryAttrs(s,t),n.tables.textStyleTable.add(t)})}processDimStyles(e,n){e.tables.DIMSTYLE.entries.forEach(s=>{const t={name:s.name,ownerId:s.ownerHandle,dimpost:s.DIMPOST||"",dimapost:s.DIMAPOST||"",dimscale:s.DIMSCALE,dimasz:s.DIMASZ,dimexo:s.DIMEXO,dimdli:s.DIMDLI,dimexe:s.DIMEXE,dimrnd:s.DIMRND,dimdle:s.DIMDLE,dimtp:s.DIMTP,dimtm:s.DIMTM,dimtxt:s.DIMTXT,dimcen:s.DIMCEN,dimtsz:s.DIMTSZ,dimaltf:s.DIMALTF,dimlfac:s.DIMLFAC,dimtvp:s.DIMTVP,dimtfac:s.DIMTFAC,dimgap:s.DIMGAP,dimaltrnd:s.DIMALTRND,dimtol:s.DIMTOL==null||s.DIMTOL==0?0:1,dimlim:s.DIMLIM==null||s.DIMLIM==0?0:1,dimtih:s.DIMTIH==null||s.DIMTIH==0?0:1,dimtoh:s.DIMTOH==null||s.DIMTOH==0?0:1,dimse1:s.DIMSE1==null||s.DIMSE1==0?0:1,dimse2:s.DIMSE2==null||s.DIMSE2==0?0:1,dimtad:s.DIMTAD,dimzin:s.DIMZIN,dimazin:s.DIMAZIN,dimalt:s.DIMALT,dimaltd:s.DIMALTD,dimtofl:s.DIMTOFL,dimsah:s.DIMSAH,dimtix:s.DIMTIX,dimsoxd:s.DIMSOXD,dimclrd:s.DIMCLRD,dimclre:s.DIMCLRE,dimclrt:s.DIMCLRT,dimadec:s.DIMADEC||0,dimunit:s.DIMUNIT||2,dimdec:s.DIMDEC,dimtdec:s.DIMTDEC,dimaltu:s.DIMALTU,dimalttd:s.DIMALTTD,dimaunit:s.DIMAUNIT,dimfrac:s.DIMFRAC,dimlunit:s.DIMLUNIT,dimdsep:s.DIMDSEP||".",dimtmove:s.DIMTMOVE||0,dimjust:s.DIMJUST,dimsd1:s.DIMSD1,dimsd2:s.DIMSD2,dimtolj:s.DIMTOLJ,dimtzin:s.DIMTZIN,dimaltz:s.DIMALTZ,dimalttz:s.DIMALTTZ,dimfit:s.DIMFIT||0,dimupt:s.DIMUPT,dimatfit:s.DIMATFIT,dimtxsty:r.DEFAULT_TEXT_STYLE,dimldrblk:"",dimblk:s.DIMBLK||"",dimblk1:s.DIMBLK1||"",dimblk2:s.DIMBLK2||"",dimlwd:s.DIMLWD,dimlwe:s.DIMLWE},i=new r.AcDbDimStyleTableRecord(t);this.processCommonTableEntryAttrs(s,i),n.tables.dimStyleTable.add(i)})}processLayers(e,n){e.tables.LAYER.entries.forEach(s=>{const t=new r.AcCmColor;t.colorIndex=s.colorIndex;const i=new r.AcDbLayerTableRecord({name:s.name,standardFlags:s.standardFlag,linetype:s.lineType,lineWeight:s.lineweight,isOff:s.off,color:t,isPlottable:s.plotFlag!=0});this.processCommonTableEntryAttrs(s,i),n.tables.layerTable.add(i)})}processViewports(e,n){e.tables.VPORT.entries.forEach(s=>{const t=new r.AcDbViewportTableRecord;this.processCommonTableEntryAttrs(s,t),s.circleSides&&(t.circleSides=s.circleSides),t.standardFlag=s.standardFlag,t.center.copy(s.center),t.lowerLeftCorner.copy(s.lowerLeftCorner),t.upperRightCorner.copy(s.upperRightCorner),s.snapBasePoint&&t.snapBase.copy(s.snapBasePoint),s.snapRotationAngle&&(t.snapAngle=s.snapRotationAngle),s.snapSpacing&&t.snapIncrements.copy(s.snapSpacing),s.majorGridLines&&(t.gridMajor=s.majorGridLines),s.gridSpacing&&t.gridIncrements.copy(s.gridSpacing),s.backgroundObjectId&&(t.backgroundObjectId=s.backgroundObjectId),t.gsView.center.copy(s.center),t.gsView.viewDirectionFromTarget.copy(s.viewDirectionFromTarget),t.gsView.viewTarget.copy(s.viewTarget),s.lensLength&&(t.gsView.lensLength=s.lensLength),s.frontClippingPlane&&(t.gsView.frontClippingPlane=s.frontClippingPlane),s.backClippingPlane&&(t.gsView.backClippingPlane=s.backClippingPlane),s.viewHeight&&(t.gsView.viewHeight=s.viewHeight),s.viewTwistAngle&&(t.gsView.viewTwistAngle=s.viewTwistAngle),s.frozenLayers&&(t.gsView.frozenLayers=s.frozenLayers),s.styleSheet&&(t.gsView.styleSheet=s.styleSheet),s.renderMode&&(t.gsView.renderMode=s.renderMode),s.viewMode&&(t.gsView.viewMode=s.viewMode),s.ucsIconSetting&&(t.gsView.ucsIconSetting=s.ucsIconSetting),s.ucsOrigin&&t.gsView.ucsOrigin.copy(s.ucsOrigin),s.ucsXAxis&&t.gsView.ucsXAxis.copy(s.ucsXAxis),s.ucsYAxis&&t.gsView.ucsYAxis.copy(s.ucsYAxis),s.orthographicType&&(t.gsView.orthographicType=s.orthographicType),s.shadePlotSetting&&(t.gsView.shadePlotSetting=s.shadePlotSetting),s.shadePlotObjectId&&(t.gsView.shadePlotObjectId=s.shadePlotObjectId),s.visualStyleObjectId&&(t.gsView.visualStyleObjectId=s.visualStyleObjectId),s.isDefaultLightingOn&&(t.gsView.isDefaultLightingOn=s.isDefaultLightingOn),s.defaultLightingType&&(t.gsView.defaultLightingType=s.defaultLightingType),s.brightness&&(t.gsView.brightness=s.brightness),s.contrast&&(t.gsView.contrast=s.contrast),s.ambientColor&&(t.gsView.ambientColor=s.ambientColor),n.tables.viewportTable.add(t)})}processBlockTables(e,n){e.tables.BLOCK_RECORD.entries.forEach(s=>{let t=n.tables.blockTable.getAt(s.name);t||(t=new r.AcDbBlockTableRecord,t.objectId=s.handle,t.name=s.name,t.ownerId=s.ownerHandle,t.origin.copy(s.basePoint),t.layoutId=s.layout,t.blockInsertUnits=s.insertionUnits,t.explodability=s.explodability,t.blockScaling=s.scalability,s.bmpPreview&&(t.bmpPreview=s.bmpPreview),n.tables.blockTable.add(t)),!t.isModelSapce&&s.entities&&s.entities.length>0&&this.processEntitiesInBlock(s.entities,t)})}processBlocks(e,n){}async processEntitiesInBlock(e,n){const o=new y,s=e.length,t=[];for(let i=0;i<s;i++){const p=e[i],l=o.convert(p);l&&t.push(l)}n.appendEntity(t)}async processEntities(e,n,o,s,t){const i=new y;let p=[];e.tables.BLOCK_RECORD.entries.forEach(a=>{this.isModelSpace(a.name)&&(p=a.entities)});const l=p.length,c=new r.AcDbBatchProcessing(l,100-s.value,o);this.config.convertByEntityType&&(p=this.groupAndFlattenByType(p));const u=n.tables.blockTable.modelSpace;await c.processChunk(async(a,d)=>{const f=[];for(let h=a;h<d;h++){const g=p[h],A=i.convert(g);A&&f.push(A)}if(u.appendEntity(f),t){let h=s.value+d/l*(100-s.value);h>100&&(h=100),await t(h,"ENTITY","IN-PROGRESS")}})}processHeader(e,n){const o=e.header;o.CECOLOR&&(o.CECOLOR.index>=0&&o.CECOLOR.index<=256?n.cecolor.colorIndex=o.CECOLOR.index:n.cecolor.setRGBValue(o.CECOLOR.rgb)),n.angBase=o.ANGBASE??0,n.angDir=o.ANGDIR??0,n.aunits=o.AUNITS??0,n.celtype=o.CELTYPE??r.ByLayer,n.celtscale=o.CELTSCALE??1,n.ltscale=o.LTSCALE??1,o.EXTMAX&&(n.extmax=o.EXTMAX),o.EXTMIN&&(n.extmin=o.EXTMIN),n.insunits=o.INSUNITS??1,n.pdmode=o.PDMODE??0,n.pdsize=o.PDSIZE??0,n.textstyle=o.TEXTSTYLE??r.DEFAULT_TEXT_STYLE}processCommonTableEntryAttrs(e,n){n.name=e.name,n.objectId=e.handle,n.ownerId=e.ownerHandle}processObjects(e,n){this.processLayouts(e,n),this.processImageDefs(e,n)}processLayouts(e,n){const o=n.objects.layout;e.objects.LAYOUT.forEach(t=>{const i=new r.AcDbLayout;i.layoutName=t.layoutName,i.tabOrder=t.tabOrder;const p=n.tables.blockTable.newIterator();i.objectId=t.handle;for(const l of p)if(l.layoutId===i.objectId){i.blockTableRecordId=l.objectId;break}i.blockTableRecordId||t.layoutName==="Model"&&(i.blockTableRecordId=n.tables.blockTable.modelSpace.objectId),i.limits.min.copy(t.minLimit),i.limits.max.copy(t.maxLimit),i.extents.min.copy(t.minExtent),i.extents.max.copy(t.maxExtent),t.viewportId&&i.viewportArray.push(t.viewportId),this.processCommonObjectAttrs(t,i),o.setAt(i.layoutName,i)})}processImageDefs(e,n){const o=n.objects.imageDefinition;e.objects.IMAGEDEF.forEach(t=>{const i=new r.AcDbRasterImageDef;i.sourceFileName=t.fileName,this.processCommonObjectAttrs(t,i),o.setAt(i.objectId,i)})}processCommonObjectAttrs(e,n){n.objectId=e.handle,n.ownerId=e.ownerHandle}groupAndFlattenByType(e){const n={},o=[];for(const s of e)n[s.type]||(n[s.type]=[],o.push(s.type)),n[s.type].push(s);return o.flatMap(s=>n[s])}isModelSpace(e){return e&&e.toUpperCase()==I}}D.AcDbLibreDwgConverter=b,Object.defineProperty(D,Symbol.toStringTag,{value:"Module"})});