@mlightcad/libredwg-converter 3.0.6 → 3.0.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,5 @@
1
- import { AcDbArc as S, AcDbCircle as P, AcGeVector3d as h, AcDbEllipse as E, AcDbLine as L, AcGePoint3d as A, AcDbSpline as w, AcDbPoint as C, AcDbTrace as x, AcDbPolyline as I, AcGePoint2d as g, AcDbHatch as v, AcGePolyline2d as O, AcGeLoop2d as k, AcGeLine2d as R, AcGeCircArc2d as N, AcGeVector2d as V, AcGeEllipseArc2d as m, AcGeSpline3d as b, AcDbTable as F, AcDbText as B, AcDbMText as j, AcDbLeader as z, AcDbAlignedDimension as H, AcDb3PointAngularDimension as W, AcDbOrdinateDimension as X, AcDbRadialDimension as G, AcDbDiametricDimension as U, AcDbRasterImage as Y, AcDbViewport as Z, AcDbRay as K, AcDbXline as _, AcDbBlockReference as q, AcDbDatabaseConverter as J, createWorkerApi as Q, AcDbLinetypeTableRecord as $, AcDbTextStyleTableRecord as ee, AcDbDimStyleTableRecord as ne, AcCmColor as te, AcDbLayerTableRecord as oe, AcDbViewportTableRecord as se, AcDbBlockTableRecord as re, AcDbBatchProcessing as ie, AcDbLayout as ce, AcDbRasterImageDef as ae } from "@mlightcad/data-model";
2
- class T {
1
+ import { AcDbArc as M, AcDbCircle as E, AcGeVector3d as g, AcDbEllipse as P, AcDbLine as L, AcGePoint3d as I, AcDbSpline as w, AcDbPoint as C, AcDbTrace as x, AcDbPolyline as b, AcGePoint2d as A, AcDbHatch as v, AcGePolyline2d as O, AcGeLoop2d as k, AcGeLine2d as R, AcGeCircArc2d as N, AcGeVector2d as V, AcGeEllipseArc2d as m, AcGeSpline3d as T, AcDbTable as j, AcDbText as F, AcDbMText as B, AcDbLeader as z, AcDbAlignedDimension as H, AcDb3PointAngularDimension as W, AcDbOrdinateDimension as X, AcDbRadialDimension as G, AcDbDiametricDimension as U, AcDbRasterImage as Y, AcDbViewport as Z, AcDbRay as K, AcDbXline as _, AcDbBlockReference as q, AcDbDatabaseConverter as J, createWorkerApi as Q, AcDbLinetypeTableRecord as $, AcDbTextStyleTableRecord as ee, AcDbDimStyleTableRecord as ne, AcCmColor as te, AcDbLayerTableRecord as oe, AcDbViewportTableRecord as se, AcDbBlockTableRecord as re, AcDbBatchProcessing as ie, AcDbLayout as ce, AcDbRasterImageDef as ae } from "@mlightcad/data-model";
2
+ class y {
3
3
  convert(e) {
4
4
  const n = this.createEntity(e);
5
5
  return n && this.processCommonAttrs(e, n), n;
@@ -13,7 +13,7 @@ class T {
13
13
  return 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 == "XLINE" ? this.convertXline(e) : e.type == "INSERT" ? this.convertBlockReference(e) : null;
14
14
  }
15
15
  convertArc(e) {
16
- return new S(
16
+ return new M(
17
17
  e.center,
18
18
  e.radius,
19
19
  e.startAngle,
@@ -21,13 +21,13 @@ class T {
21
21
  );
22
22
  }
23
23
  convertCirle(e) {
24
- return new P(e.center, e.radius);
24
+ return new E(e.center, e.radius);
25
25
  }
26
26
  convertEllipse(e) {
27
- const n = new h(e.majorAxisEndPoint), s = n.length();
28
- return new E(
27
+ const n = new g(e.majorAxisEndPoint), s = n.length();
28
+ return new P(
29
29
  e.center,
30
- h.Z_AXIS,
30
+ g.Z_AXIS,
31
31
  n,
32
32
  s,
33
33
  s * e.axisRatio,
@@ -38,8 +38,8 @@ class T {
38
38
  convertLine(e) {
39
39
  const n = e.startPoint, s = e.endPoint;
40
40
  return new L(
41
- new A(n.x, n.y, n.z),
42
- new A(s.x, s.y, s.z)
41
+ new I(n.x, n.y, n.z),
42
+ new I(s.x, s.y, s.z)
43
43
  );
44
44
  }
45
45
  convertSpline(e) {
@@ -68,11 +68,11 @@ class T {
68
68
  ), n.thickness = e.thickness, n;
69
69
  }
70
70
  convertLWPolyline(e) {
71
- const n = new I();
71
+ const n = new b();
72
72
  return n.closed = !!(e.flag & 512), e.vertices.forEach((s, t) => {
73
73
  n.addVertexAt(
74
74
  t,
75
- new g(s.x, s.y),
75
+ new A(s.x, s.y),
76
76
  s.bulge,
77
77
  s.startWidth,
78
78
  s.endWidth
@@ -80,11 +80,11 @@ class T {
80
80
  }), n;
81
81
  }
82
82
  convertPolyline(e) {
83
- const n = new I();
83
+ const n = new b();
84
84
  return n.closed = !!(e.flag & 1), e.vertices.forEach((s, t) => {
85
85
  n.addVertexAt(
86
86
  t,
87
- new g(s.x, s.y),
87
+ new A(s.x, s.y),
88
88
  s.bulge,
89
89
  s.startWidth,
90
90
  s.endWidth
@@ -103,84 +103,84 @@ class T {
103
103
  });
104
104
  }), 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((o) => {
105
105
  if (o.boundaryPathTypeFlag & 2) {
106
- const a = o, c = new O();
107
- c.closed = a.isClosed, a.vertices.forEach((l, i) => {
108
- c.addVertexAt(i, {
106
+ const a = o, i = new O();
107
+ i.closed = a.isClosed, a.vertices.forEach((l, c) => {
108
+ i.addVertexAt(c, {
109
109
  x: l.x,
110
110
  y: l.y,
111
111
  bulge: l.bulge
112
112
  });
113
- }), n.add(c);
113
+ }), n.add(i);
114
114
  } else {
115
- const a = o, c = new k();
115
+ const a = o, i = new k();
116
116
  a.edges.forEach((l) => {
117
117
  if (l.type == 1) {
118
- const i = l;
119
- c.add(new R(i.start, i.end));
118
+ const c = l;
119
+ i.add(new R(c.start, c.end));
120
120
  } else if (l.type == 2) {
121
- const i = l;
122
- c.add(
121
+ const c = l;
122
+ i.add(
123
123
  new N(
124
- i.center,
125
- i.radius,
126
- i.startAngle,
127
- i.endAngle,
128
- !i.isCCW
124
+ c.center,
125
+ c.radius,
126
+ c.startAngle,
127
+ c.endAngle,
128
+ !c.isCCW
129
129
  )
130
130
  );
131
131
  } else if (l.type == 3) {
132
- const i = l;
133
- new V().subVectors(i.end, i.center);
134
- const d = Math.sqrt(
135
- Math.pow(i.end.x, 2) + Math.pow(i.end.y, 2)
136
- ), p = d * i.lengthOfMinorAxis;
137
- let D = i.startAngle, u = i.endAngle;
138
- const M = Math.atan2(i.end.y, i.end.x);
139
- i.isCCW || (D = Math.PI * 2 - D, u = Math.PI * 2 - u), c.add(
132
+ const c = l;
133
+ new V().subVectors(c.end, c.center);
134
+ const p = Math.sqrt(
135
+ Math.pow(c.end.x, 2) + Math.pow(c.end.y, 2)
136
+ ), f = p * c.lengthOfMinorAxis;
137
+ let d = c.startAngle, D = c.endAngle;
138
+ const h = Math.atan2(c.end.y, c.end.x);
139
+ c.isCCW || (d = Math.PI * 2 - d, D = Math.PI * 2 - D), i.add(
140
140
  new m(
141
- { ...i.center, z: 0 },
142
- d,
141
+ { ...c.center, z: 0 },
143
142
  p,
143
+ f,
144
+ d,
144
145
  D,
145
- u,
146
- !i.isCCW,
147
- M
146
+ !c.isCCW,
147
+ h
148
148
  )
149
149
  );
150
150
  } else if (l.type == 4) {
151
- const i = l;
152
- if (i.numberOfControlPoints > 0 && i.numberOfKnots > 0) {
153
- const f = i.controlPoints.map(
154
- (D) => ({
155
- x: D.x,
156
- y: D.y,
151
+ const c = l;
152
+ if (c.numberOfControlPoints > 0 && c.numberOfKnots > 0) {
153
+ const u = c.controlPoints.map(
154
+ (d) => ({
155
+ x: d.x,
156
+ y: d.y,
157
157
  z: 0
158
158
  })
159
159
  );
160
- let d = !0;
161
- const p = i.controlPoints.map((D) => (D.weight == null && (d = !1), D.weight || 1));
162
- c.add(
163
- new b(
164
- f,
165
- i.knots,
166
- d ? p : void 0
160
+ let p = !0;
161
+ const f = c.controlPoints.map((d) => (d.weight == null && (p = !1), d.weight || 1));
162
+ i.add(
163
+ new T(
164
+ u,
165
+ c.knots,
166
+ p ? f : void 0
167
167
  )
168
168
  );
169
- } else if (i.numberOfFitData > 0) {
170
- const f = i.fitDatum.map((d) => ({
171
- x: d.x,
172
- y: d.y,
169
+ } else if (c.numberOfFitData > 0) {
170
+ const u = c.fitDatum.map((p) => ({
171
+ x: p.x,
172
+ y: p.y,
173
173
  z: 0
174
174
  }));
175
- c.add(new b(f, "Uniform"));
175
+ i.add(new T(u, "Uniform"));
176
176
  }
177
177
  }
178
- }), n.add(c);
178
+ }), n.add(i);
179
179
  }
180
180
  }), n;
181
181
  }
182
182
  convertTable(e) {
183
- const n = new F(
183
+ const n = new j(
184
184
  e.name,
185
185
  e.rowCount,
186
186
  e.columnCount
@@ -194,12 +194,12 @@ class T {
194
194
  }), n;
195
195
  }
196
196
  convertText(e) {
197
- const n = new B();
197
+ const n = new F();
198
198
  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;
199
199
  }
200
200
  convertMText(e) {
201
- const n = new j();
202
- 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 h(e.direction)), n.drawingDirection = e.drawingDirection, n;
201
+ const n = new B();
202
+ 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 g(e.direction)), n.drawingDirection = e.drawingDirection, n;
203
203
  }
204
204
  convertLeader(e) {
205
205
  const n = new z();
@@ -248,7 +248,7 @@ class T {
248
248
  }
249
249
  processImage(e, n) {
250
250
  n.position.copy(e.position), n.brightness = e.brightness, n.contrast = e.contrast, n.fade = e.fade, n.imageDefId = e.imageDefHandle.toString(), n.isClipped = (e.flags | 4) > 0, n.isImageShown = (e.flags | 3) > 0, n.isImageTransparent = (e.flags | 8) > 0, e.clippingBoundaryPath.forEach((s) => {
251
- n.clipBoundary.push(new g(s));
251
+ n.clipBoundary.push(new A(s));
252
252
  }), n.clipBoundaryType = e.clippingBoundaryType, n.width = Math.sqrt(
253
253
  e.uPixel.x ** 2 + e.uPixel.y ** 2 + e.uPixel.z ** 2
254
254
  ) * e.imageSize.x, n.height = Math.sqrt(
@@ -314,8 +314,8 @@ class de extends J {
314
314
  };
315
315
  e.tables.STYLE.entries.forEach((r) => {
316
316
  const a = [];
317
- let c = t(r.font);
318
- c && a.push(c), c = t(r.bigFont), c && a.push(c), s.set(r.name, a);
317
+ let i = t(r.font);
318
+ i && a.push(i), i = t(r.bigFont), i && a.push(i), s.set(r.name, a);
319
319
  });
320
320
  const o = /* @__PURE__ */ new Set();
321
321
  return this.getFontsInBlock(e.entities, n, s, o), Array.from(o);
@@ -331,14 +331,14 @@ class de extends J {
331
331
  [...a.text.matchAll(o)].forEach((l) => {
332
332
  t.add(l[1].toLowerCase());
333
333
  });
334
- const c = s.get(a.styleName);
335
- c == null || c.forEach((l) => t.add(l));
334
+ const i = s.get(a.styleName);
335
+ i == null || i.forEach((l) => t.add(l));
336
336
  } else if (r.type == "TEXT") {
337
- const a = r, c = s.get(a.styleName);
338
- c == null || c.forEach((l) => t.add(l));
337
+ const a = r, i = s.get(a.styleName);
338
+ i == null || i.forEach((l) => t.add(l));
339
339
  } else if (r.type == "INSERT") {
340
- const a = r, c = n.get(a.name);
341
- c && this.getFontsInBlock(c.entities, n, s, t);
340
+ const a = r, i = n.get(a.name);
341
+ i && this.getFontsInBlock(i.entities, n, s, t);
342
342
  }
343
343
  });
344
344
  }
@@ -465,17 +465,18 @@ class de extends J {
465
465
  processBlockTables(e, n) {
466
466
  e.tables.BLOCK_RECORD.entries.forEach((t) => {
467
467
  let o = n.tables.blockTable.getAt(t.name);
468
- o || (o = new re(), o.objectId = t.handle.toString(), o.name = t.name, n.tables.blockTable.add(o)), !o.isModelSapce && !o.isPaperSapce && t.entities && t.entities.length > 0 && this.processEntitiesInBlock(t.entities, o);
468
+ o || (o = new re(), o.objectId = t.handle.toString(), o.name = t.name, o.ownerId = t.ownerHandle.toString(), o.origin.copy(t.basePoint), o.layoutId = t.layout.toString(), n.tables.blockTable.add(o)), !o.isModelSapce && !o.isPaperSapce && t.entities && t.entities.length > 0 && this.processEntitiesInBlock(t.entities, o);
469
469
  });
470
470
  }
471
471
  processBlocks(e, n) {
472
472
  }
473
473
  async processEntitiesInBlock(e, n) {
474
- const s = new T(), t = e.length;
475
- for (let o = 0; o < t; o++) {
476
- const r = e[o], a = s.convert(r);
477
- a && n.appendEntity(a);
474
+ const s = new y(), t = e.length, o = [];
475
+ for (let r = 0; r < t; r++) {
476
+ const a = e[r], i = s.convert(a);
477
+ i && o.push(i);
478
478
  }
479
+ n.appendEntity(o);
479
480
  }
480
481
  /**
481
482
  * Breaks up the work into smaller chunks that are executed asynchronously. This is often referred to
@@ -483,19 +484,20 @@ class de extends J {
483
484
  * smaller pieces and executed in small intervals to allow the UI to remain responsive.
484
485
  */
485
486
  async processEntities(e, n, s, t, o) {
486
- const r = new T(), a = e.entities, c = a.length, l = new ie(
487
- c,
487
+ const r = new y(), a = e.entities, i = a.length, l = new ie(
488
+ i,
488
489
  100 - t.value,
489
490
  s
490
- ), i = n.tables.blockTable.modelSpace;
491
- await l.processChunk(async (f, d) => {
492
- for (let p = f; p < d; p++) {
493
- const D = a[p], u = r.convert(D);
494
- u && i.appendEntity(u);
491
+ ), c = n.tables.blockTable.modelSpace;
492
+ await l.processChunk(async (u, p) => {
493
+ const f = [];
494
+ for (let d = u; d < p; d++) {
495
+ const D = a[d], h = r.convert(D);
496
+ h && f.push(h);
495
497
  }
496
- if (o) {
497
- let p = t.value + d / c * (100 - t.value);
498
- p > 100 && (p = 100), await o(p, "ENTITY", "IN-PROGRESS");
498
+ if (c.appendEntity(f), o) {
499
+ let d = t.value + p / i * (100 - t.value);
500
+ d > 100 && (d = 100), await o(d, "ENTITY", "IN-PROGRESS");
499
501
  }
500
502
  });
501
503
  }
@@ -513,7 +515,15 @@ class de extends J {
513
515
  const s = n.dictionaries.layouts;
514
516
  e.objects.LAYOUT.forEach((o) => {
515
517
  const r = new ce();
516
- r.layoutName = o.layoutName, r.tabOrder = o.tabOrder, r.blockTableRecordId = o.ownerHandle.toString(), r.limits.min.copy(o.minLimit), r.limits.max.copy(o.maxLimit), r.extents.min.copy(o.minExtent), r.extents.max.copy(o.maxExtent), this.processCommonObjectAttrs(o, r), s.setAt(r.layoutName, r);
518
+ r.layoutName = o.layoutName, r.tabOrder = o.tabOrder;
519
+ const a = n.tables.blockTable.newIterator();
520
+ r.objectId = o.handle.toString();
521
+ for (const i of a)
522
+ if (i.layoutId === r.objectId) {
523
+ r.blockTableRecordId = i.objectId;
524
+ break;
525
+ }
526
+ r.limits.min.copy(o.minLimit), r.limits.max.copy(o.maxLimit), r.extents.min.copy(o.minExtent), r.extents.max.copy(o.maxExtent), this.processCommonObjectAttrs(o, r), s.setAt(r.layoutName, r);
517
527
  });
518
528
  }
519
529
  processImageDefs(e, n) {
@@ -1 +1 @@
1
- (function(D,o){typeof exports=="object"&&typeof module<"u"?o(exports,require("@mlightcad/data-model")):typeof define=="function"&&define.amd?define(["exports","@mlightcad/data-model"],o):(D=typeof globalThis<"u"?globalThis:D||self,o(D["libredwg-converter"]={},D.dataModel))})(this,function(D,o){"use strict";class A{convert(e){const n=this.createEntity(e);return n&&this.processCommonAttrs(e,n),n}createEntity(e){return 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=="XLINE"?this.convertXline(e):e.type=="INSERT"?this.convertBlockReference(e):null}convertArc(e){return new o.AcDbArc(e.center,e.radius,e.startAngle,e.endAngle)}convertCirle(e){return new o.AcDbCircle(e.center,e.radius)}convertEllipse(e){const n=new o.AcGeVector3d(e.majorAxisEndPoint),r=n.length();return new o.AcDbEllipse(e.center,o.AcGeVector3d.Z_AXIS,n,r,r*e.axisRatio,e.startAngle,e.endAngle)}convertLine(e){const n=e.startPoint,r=e.endPoint;return new o.AcDbLine(new o.AcGePoint3d(n.x,n.y,n.z),new o.AcGePoint3d(r.x,r.y,r.z))}convertSpline(e){return e.numberOfControlPoints>0&&e.numberOfKnots>0?new o.AcDbSpline(e.controlPoints,e.knots,e.weights,e.degree,!!(e.flag&1)):e.numberOfFitPoints>0?new o.AcDbSpline(e.fitPoints,"Uniform",e.degree,!!(e.flag&1)):null}convertPoint(e){const n=new o.AcDbPoint;return n.position=e.position,n}convertSolid(e){const n=new o.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 o.AcDbPolyline;return n.closed=!!(e.flag&512),e.vertices.forEach((r,t)=>{n.addVertexAt(t,new o.AcGePoint2d(r.x,r.y),r.bulge,r.startWidth,r.endWidth)}),n}convertPolyline(e){const n=new o.AcDbPolyline;return n.closed=!!(e.flag&1),e.vertices.forEach((r,t)=>{n.addVertexAt(t,new o.AcGePoint2d(r.x,r.y),r.bulge,r.startWidth,r.endWidth)}),n}convertHatch(e){var t;const n=new o.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 l=s,a=new o.AcGePolyline2d;a.closed=l.isClosed,l.vertices.forEach((p,c)=>{a.addVertexAt(c,{x:p.x,y:p.y,bulge:p.bulge})}),n.add(a)}else{const l=s,a=new o.AcGeLoop2d;l.edges.forEach(p=>{if(p.type==1){const c=p;a.add(new o.AcGeLine2d(c.start,c.end))}else if(p.type==2){const c=p;a.add(new o.AcGeCircArc2d(c.center,c.radius,c.startAngle,c.endAngle,!c.isCCW))}else if(p.type==3){const c=p;new o.AcGeVector2d().subVectors(c.end,c.center);const d=Math.sqrt(Math.pow(c.end.x,2)+Math.pow(c.end.y,2)),f=d*c.lengthOfMinorAxis;let u=c.startAngle,g=c.endAngle;const b=Math.atan2(c.end.y,c.end.x);c.isCCW||(u=Math.PI*2-u,g=Math.PI*2-g),a.add(new o.AcGeEllipseArc2d({...c.center,z:0},d,f,u,g,!c.isCCW,b))}else if(p.type==4){const c=p;if(c.numberOfControlPoints>0&&c.numberOfKnots>0){const h=c.controlPoints.map(u=>({x:u.x,y:u.y,z:0}));let d=!0;const f=c.controlPoints.map(u=>(u.weight==null&&(d=!1),u.weight||1));a.add(new o.AcGeSpline3d(h,c.knots,d?f:void 0))}else if(c.numberOfFitData>0){const h=c.fitDatum.map(d=>({x:d.x,y:d.y,z:0}));a.add(new o.AcGeSpline3d(h,"Uniform"))}}}),n.add(a)}}),n}convertTable(e){const n=new o.AcDbTable(e.name,e.rowCount,e.columnCount);return n.attachmentPoint=e.attachmentPoint,n.position.copy(e.startPoint),e.columnWidthArr.forEach((r,t)=>n.setColumnWidth(t,r)),e.rowHeightArr.forEach((r,t)=>n.setRowHeight(t,r)),e.cells.forEach((r,t)=>{n.setCell(t,r)}),n}convertText(e){const n=new o.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 o.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 o.AcGeVector3d(e.direction)),n.drawingDirection=e.drawingDirection,n}convertLeader(e){const n=new o.AcDbLeader;return e.vertices.forEach(r=>{n.appendVertex(r)}),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,r=new o.AcDbAlignedDimension(n.subDefinitionPoint1,n.subDefinitionPoint2,n.definitionPoint);return r.rotation=n.rotationAngle,this.processDimensionCommonAttrs(e,r),r}else if(e.subclassMarker=="AcDb3PointAngularDimension"){const n=e,r=new o.AcDb3PointAngularDimension(n.centerPoint,n.subDefinitionPoint1,n.subDefinitionPoint2,n.definitionPoint);return this.processDimensionCommonAttrs(e,r),r}else if(e.subclassMarker=="AcDbOrdinateDimension"){const n=e,r=new o.AcDbOrdinateDimension(n.subDefinitionPoint1,n.subDefinitionPoint2);return this.processDimensionCommonAttrs(e,r),r}else if(e.subclassMarker=="AcDbRadialDimension"){const n=e,r=new o.AcDbRadialDimension(n.definitionPoint,n.centerPoint,n.leaderLength);return this.processDimensionCommonAttrs(e,r),r}else if(e.subclassMarker=="AcDbDiametricDimension"){const n=e,r=new o.AcDbDiametricDimension(n.definitionPoint,n.centerPoint,n.leaderLength);return this.processDimensionCommonAttrs(e,r),r}return null}processImage(e,n){n.position.copy(e.position),n.brightness=e.brightness,n.contrast=e.contrast,n.fade=e.fade,n.imageDefId=e.imageDefHandle.toString(),n.isClipped=(e.flags|4)>0,n.isImageShown=(e.flags|3)>0,n.isImageTransparent=(e.flags|8)>0,e.clippingBoundaryPath.forEach(r=>{n.clipBoundary.push(new o.AcGePoint2d(r))}),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 o.AcDbRasterImage;return this.processImage(e,n),n}convertViewport(e){const n=new o.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 o.AcDbRay;return n.basePoint.copy(e.firstPoint),n.unitDir.copy(e.unitDirection),n}convertXline(e){const n=new o.AcDbXline;return n.basePoint.copy(e.firstPoint),n.unitDir.copy(e.unitDirection),n}convertBlockReference(e){const n=new o.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),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){n.layer=e.layer,n.objectId=e.handle.toString(),n.ownerId=e.ownerBlockRecordSoftId.toString(),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.color=e.color),e.colorIndex!=null&&(n.color.colorIndex=e.colorIndex),e.colorName!=null&&(n.color.colorName=e.colorName),e.isVisible!=null&&(n.visibility=e.isVisible),e.transparency!=null&&(n.transparency=e.transparency)}}class w extends o.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)return(await o.createWorkerApi({workerUrl:this.config.parserWorkerUrl}).execute(e)).data;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 r=new Map,t=i=>{if(i){const l=i.lastIndexOf(".");return l>=0?i.substring(0,l).toLowerCase():i.toLowerCase()}};e.tables.STYLE.entries.forEach(i=>{const l=[];let a=t(i.font);a&&l.push(a),a=t(i.bigFont),a&&l.push(a),r.set(i.name,l)});const s=new Set;return this.getFontsInBlock(e.entities,n,r,s),Array.from(s)}getFontsInBlock(e,n,r,t){const s=/\\f(.*?)\|/g;e.forEach(i=>{if(i.type=="MTEXT"){const l=i;[...l.text.matchAll(s)].forEach(p=>{t.add(p[1].toLowerCase())});const a=r.get(l.styleName);a==null||a.forEach(p=>t.add(p))}else if(i.type=="TEXT"){const l=i,a=r.get(l.styleName);a==null||a.forEach(p=>t.add(p))}else if(i.type=="INSERT"){const l=i,a=n.get(l.name);a&&this.getFontsInBlock(a.entities,n,r,t)}})}processLineTypes(e,n){e.tables.LTYPE.entries.forEach(t=>{const s={name:t.name,description:t.description,standardFlag:t.standardFlag,totalPatternLength:t.totalPatternLength,pattern:t.pattern},i=new o.AcDbLinetypeTableRecord(s);this.processCommonTableEntryAttrs(t,i),i.name=t.name,n.tables.linetypeTable.add(i)})}processTextStyles(e,n){e.tables.STYLE.entries.forEach(t=>{const s=new o.AcDbTextStyleTableRecord(t);this.processCommonTableEntryAttrs(t,s),n.tables.textStyleTable.add(s)})}processDimStyles(e,n){e.tables.DIMSTYLE.entries.forEach(t=>{const s={name:t.name,ownerId:t.ownerHandle.toString(),dimpost:t.DIMPOST||"",dimapost:t.DIMAPOST||"",dimscale:t.DIMSCALE,dimasz:t.DIMASZ,dimexo:t.DIMEXO,dimdli:t.DIMDLI,dimexe:t.DIMEXE,dimrnd:t.DIMRND,dimdle:t.DIMDLE,dimtp:t.DIMTP,dimtm:t.DIMTM,dimtxt:t.DIMTXT,dimcen:t.DIMCEN,dimtsz:t.DIMTSZ,dimaltf:t.DIMALTF,dimlfac:t.DIMLFAC,dimtvp:t.DIMTVP,dimtfac:t.DIMTFAC,dimgap:t.DIMGAP,dimaltrnd:t.DIMALTRND,dimtol:t.DIMTOL==null||t.DIMTOL==0?0:1,dimlim:t.DIMLIM==null||t.DIMLIM==0?0:1,dimtih:t.DIMTIH==null||t.DIMTIH==0?0:1,dimtoh:t.DIMTOH==null||t.DIMTOH==0?0:1,dimse1:t.DIMSE1==null||t.DIMSE1==0?0:1,dimse2:t.DIMSE2==null||t.DIMSE2==0?0:1,dimtad:t.DIMTAD,dimzin:t.DIMZIN,dimazin:t.DIMAZIN,dimalt:t.DIMALT,dimaltd:t.DIMALTD,dimtofl:t.DIMTOFL,dimsah:t.DIMSAH,dimtix:t.DIMTIX,dimsoxd:t.DIMSOXD,dimclrd:t.DIMCLRD,dimclre:t.DIMCLRE,dimclrt:t.DIMCLRT,dimadec:t.DIMADEC||0,dimunit:t.DIMUNIT||2,dimdec:t.DIMDEC,dimtdec:t.DIMTDEC,dimaltu:t.DIMALTU,dimalttd:t.DIMALTTD,dimaunit:t.DIMAUNIT,dimfrac:t.DIMFRAC,dimlunit:t.DIMLUNIT,dimdsep:t.DIMDSEP,dimtmove:t.DIMTMOVE||0,dimjust:t.DIMJUST,dimsd1:t.DIMSD1,dimsd2:t.DIMSD2,dimtolj:t.DIMTOLJ,dimtzin:t.DIMTZIN,dimaltz:t.DIMALTZ,dimalttz:t.DIMALTTZ,dimfit:t.DIMFIT||0,dimupt:t.DIMUPT,dimatfit:t.DIMATFIT,dimtxsty:"Standard",dimldrblk:"",dimblk:t.DIMBLK||"",dimblk1:t.DIMBLK1||"",dimblk2:t.DIMBLK2||"",dimlwd:t.DIMLWD,dimlwe:t.DIMLWE},i=new o.AcDbDimStyleTableRecord(s);this.processCommonTableEntryAttrs(t,i),n.tables.dimStyleTable.add(i)})}processLayers(e,n){e.tables.LAYER.entries.forEach(t=>{const s=new o.AcCmColor;s.colorIndex=t.colorIndex;const i=new o.AcDbLayerTableRecord({name:t.name,standardFlags:t.standardFlag,linetype:t.lineType,lineWeight:t.lineweight,isOff:t.off,color:s,isPlottable:t.plotFlag!=0});this.processCommonTableEntryAttrs(t,i),n.tables.layerTable.add(i)})}processViewports(e,n){e.tables.VPORT.entries.forEach(t=>{const s=new o.AcDbViewportTableRecord;this.processCommonTableEntryAttrs(t,s),t.circleSides&&(s.circleSides=t.circleSides),s.standardFlag=t.standardFlag,s.center.copy(t.center),s.lowerLeftCorner.copy(t.lowerLeftCorner),s.upperRightCorner.copy(t.upperRightCorner),t.snapBasePoint&&s.snapBase.copy(t.snapBasePoint),t.snapRotationAngle&&(s.snapAngle=t.snapRotationAngle),t.snapSpacing&&s.snapIncrements.copy(t.snapSpacing),t.majorGridLines&&(s.gridMajor=t.majorGridLines),t.gridSpacing&&s.gridIncrements.copy(t.gridSpacing),t.backgroundObjectId&&(s.backgroundObjectId=t.backgroundObjectId),s.gsView.center.copy(t.center),s.gsView.viewDirectionFromTarget.copy(t.viewDirectionFromTarget),s.gsView.viewTarget.copy(t.viewTarget),t.lensLength&&(s.gsView.lensLength=t.lensLength),t.frontClippingPlane&&(s.gsView.frontClippingPlane=t.frontClippingPlane),t.backClippingPlane&&(s.gsView.backClippingPlane=t.backClippingPlane),t.viewHeight&&(s.gsView.viewHeight=t.viewHeight),t.viewTwistAngle&&(s.gsView.viewTwistAngle=t.viewTwistAngle),t.frozenLayers&&(s.gsView.frozenLayers=t.frozenLayers),t.styleSheet&&(s.gsView.styleSheet=t.styleSheet),t.renderMode&&(s.gsView.renderMode=t.renderMode),t.viewMode&&(s.gsView.viewMode=t.viewMode),t.ucsIconSetting&&(s.gsView.ucsIconSetting=t.ucsIconSetting),t.ucsOrigin&&s.gsView.ucsOrigin.copy(t.ucsOrigin),t.ucsXAxis&&s.gsView.ucsXAxis.copy(t.ucsXAxis),t.ucsYAxis&&s.gsView.ucsYAxis.copy(t.ucsYAxis),t.orthographicType&&(s.gsView.orthographicType=t.orthographicType),t.shadePlotSetting&&(s.gsView.shadePlotSetting=t.shadePlotSetting),t.shadePlotObjectId&&(s.gsView.shadePlotObjectId=t.shadePlotObjectId),t.visualStyleObjectId&&(s.gsView.visualStyleObjectId=t.visualStyleObjectId),t.isDefaultLightingOn&&(s.gsView.isDefaultLightingOn=t.isDefaultLightingOn),t.defaultLightingType&&(s.gsView.defaultLightingType=t.defaultLightingType),t.brightness&&(s.gsView.brightness=t.brightness),t.contrast&&(s.gsView.contrast=t.contrast),t.ambientColor&&(s.gsView.ambientColor=t.ambientColor),n.tables.viewportTable.add(s)})}processBlockTables(e,n){e.tables.BLOCK_RECORD.entries.forEach(t=>{let s=n.tables.blockTable.getAt(t.name);s||(s=new o.AcDbBlockTableRecord,s.objectId=t.handle.toString(),s.name=t.name,n.tables.blockTable.add(s)),!s.isModelSapce&&!s.isPaperSapce&&t.entities&&t.entities.length>0&&this.processEntitiesInBlock(t.entities,s)})}processBlocks(e,n){}async processEntitiesInBlock(e,n){const r=new A,t=e.length;for(let s=0;s<t;s++){const i=e[s],l=r.convert(i);l&&n.appendEntity(l)}}async processEntities(e,n,r,t,s){const i=new A,l=e.entities,a=l.length,p=new o.AcDbBatchProcessing(a,100-t.value,r),c=n.tables.blockTable.modelSpace;await p.processChunk(async(h,d)=>{for(let f=h;f<d;f++){const u=l[f],g=i.convert(u);g&&c.appendEntity(g)}if(s){let f=t.value+d/a*(100-t.value);f>100&&(f=100),await s(f,"ENTITY","IN-PROGRESS")}})}processHeader(e,n){const r=e.header;n.cecolor.colorIndex=r.CECOLOR||256,n.angBase=r.ANGBASE??0,n.angDir=r.ANGDIR??0,n.aunits=r.AUNITS??0,n.extmax=r.EXTMAX,n.extmin=r.EXTMIN,n.insunits=r.INSUNITS??1,n.pdmode=r.PDMODE??0,n.pdsize=r.PDSIZE??0}processCommonTableEntryAttrs(e,n){n.name=e.name,n.objectId=e.handle.toString(),n.ownerId=e.ownerHandle.toString()}processObjects(e,n){this.processLayouts(e,n),this.processImageDefs(e,n)}processLayouts(e,n){const r=n.dictionaries.layouts;e.objects.LAYOUT.forEach(s=>{const i=new o.AcDbLayout;i.layoutName=s.layoutName,i.tabOrder=s.tabOrder,i.blockTableRecordId=s.ownerHandle.toString(),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),r.setAt(i.layoutName,i)})}processImageDefs(e,n){const r=n.dictionaries.imageDefs;e.objects.IMAGEDEF.forEach(s=>{const i=new o.AcDbRasterImageDef;i.sourceFileName=s.fileName,this.processCommonObjectAttrs(s,i),r.setAt(i.objectId,i)})}processCommonObjectAttrs(e,n){n.objectId=e.handle.toString(),n.ownerId=e.ownerHandle.toString()}}D.AcDbLibreDwgConverter=w,Object.defineProperty(D,Symbol.toStringTag,{value:"Module"})});
1
+ (function(f,r){typeof exports=="object"&&typeof module<"u"?r(exports,require("@mlightcad/data-model")):typeof define=="function"&&define.amd?define(["exports","@mlightcad/data-model"],r):(f=typeof globalThis<"u"?globalThis:f||self,r(f["libredwg-converter"]={},f.dataModel))})(this,function(f,r){"use strict";class b{convert(e){const n=this.createEntity(e);return n&&this.processCommonAttrs(e,n),n}createEntity(e){return 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=="XLINE"?this.convertXline(e):e.type=="INSERT"?this.convertBlockReference(e):null}convertArc(e){return new r.AcDbArc(e.center,e.radius,e.startAngle,e.endAngle)}convertCirle(e){return new r.AcDbCircle(e.center,e.radius)}convertEllipse(e){const n=new r.AcGeVector3d(e.majorAxisEndPoint),o=n.length();return new r.AcDbEllipse(e.center,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){return e.numberOfControlPoints>0&&e.numberOfKnots>0?new r.AcDbSpline(e.controlPoints,e.knots,e.weights,e.degree,!!(e.flag&1)):e.numberOfFitPoints>0?new r.AcDbSpline(e.fitPoints,"Uniform",e.degree,!!(e.flag&1)):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,t)=>{n.addVertexAt(t,new r.AcGePoint2d(o.x,o.y),o.bulge,o.startWidth,o.endWidth)}),n}convertPolyline(e){const n=new r.AcDbPolyline;return n.closed=!!(e.flag&1),e.vertices.forEach((o,t)=>{n.addVertexAt(t,new r.AcGePoint2d(o.x,o.y),o.bulge,o.startWidth,o.endWidth)}),n}convertHatch(e){var t;const n=new r.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 l=s,c=new r.AcGePolyline2d;c.closed=l.isClosed,l.vertices.forEach((p,a)=>{c.addVertexAt(a,{x:p.x,y:p.y,bulge:p.bulge})}),n.add(c)}else{const l=s,c=new r.AcGeLoop2d;l.edges.forEach(p=>{if(p.type==1){const a=p;c.add(new r.AcGeLine2d(a.start,a.end))}else if(p.type==2){const a=p;c.add(new r.AcGeCircArc2d(a.center,a.radius,a.startAngle,a.endAngle,!a.isCCW))}else if(p.type==3){const a=p;new r.AcGeVector2d().subVectors(a.end,a.center);const u=Math.sqrt(Math.pow(a.end.x,2)+Math.pow(a.end.y,2)),h=u*a.lengthOfMinorAxis;let d=a.startAngle,g=a.endAngle;const A=Math.atan2(a.end.y,a.end.x);a.isCCW||(d=Math.PI*2-d,g=Math.PI*2-g),c.add(new r.AcGeEllipseArc2d({...a.center,z:0},u,h,d,g,!a.isCCW,A))}else if(p.type==4){const a=p;if(a.numberOfControlPoints>0&&a.numberOfKnots>0){const D=a.controlPoints.map(d=>({x:d.x,y:d.y,z:0}));let u=!0;const h=a.controlPoints.map(d=>(d.weight==null&&(u=!1),d.weight||1));c.add(new r.AcGeSpline3d(D,a.knots,u?h:void 0))}else if(a.numberOfFitData>0){const D=a.fitDatum.map(u=>({x:u.x,y:u.y,z:0}));c.add(new r.AcGeSpline3d(D,"Uniform"))}}}),n.add(c)}}),n}convertTable(e){const n=new r.AcDbTable(e.name,e.rowCount,e.columnCount);return n.attachmentPoint=e.attachmentPoint,n.position.copy(e.startPoint),e.columnWidthArr.forEach((o,t)=>n.setColumnWidth(t,o)),e.rowHeightArr.forEach((o,t)=>n.setRowHeight(t,o)),e.cells.forEach((o,t)=>{n.setCell(t,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 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.imageDefId=e.imageDefHandle.toString(),n.isClipped=(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}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}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),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){n.layer=e.layer,n.objectId=e.handle.toString(),n.ownerId=e.ownerBlockRecordSoftId.toString(),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.color=e.color),e.colorIndex!=null&&(n.color.colorIndex=e.colorIndex),e.colorName!=null&&(n.color.colorName=e.colorName),e.isVisible!=null&&(n.visibility=e.isVisible),e.transparency!=null&&(n.transparency=e.transparency)}}class I extends r.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)return(await r.createWorkerApi({workerUrl:this.config.parserWorkerUrl}).execute(e)).data;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,t=i=>{if(i){const l=i.lastIndexOf(".");return l>=0?i.substring(0,l).toLowerCase():i.toLowerCase()}};e.tables.STYLE.entries.forEach(i=>{const l=[];let c=t(i.font);c&&l.push(c),c=t(i.bigFont),c&&l.push(c),o.set(i.name,l)});const s=new Set;return this.getFontsInBlock(e.entities,n,o,s),Array.from(s)}getFontsInBlock(e,n,o,t){const s=/\\f(.*?)\|/g;e.forEach(i=>{if(i.type=="MTEXT"){const l=i;[...l.text.matchAll(s)].forEach(p=>{t.add(p[1].toLowerCase())});const c=o.get(l.styleName);c==null||c.forEach(p=>t.add(p))}else if(i.type=="TEXT"){const l=i,c=o.get(l.styleName);c==null||c.forEach(p=>t.add(p))}else if(i.type=="INSERT"){const l=i,c=n.get(l.name);c&&this.getFontsInBlock(c.entities,n,o,t)}})}processLineTypes(e,n){e.tables.LTYPE.entries.forEach(t=>{const s={name:t.name,description:t.description,standardFlag:t.standardFlag,totalPatternLength:t.totalPatternLength,pattern:t.pattern},i=new r.AcDbLinetypeTableRecord(s);this.processCommonTableEntryAttrs(t,i),i.name=t.name,n.tables.linetypeTable.add(i)})}processTextStyles(e,n){e.tables.STYLE.entries.forEach(t=>{const s=new r.AcDbTextStyleTableRecord(t);this.processCommonTableEntryAttrs(t,s),n.tables.textStyleTable.add(s)})}processDimStyles(e,n){e.tables.DIMSTYLE.entries.forEach(t=>{const s={name:t.name,ownerId:t.ownerHandle.toString(),dimpost:t.DIMPOST||"",dimapost:t.DIMAPOST||"",dimscale:t.DIMSCALE,dimasz:t.DIMASZ,dimexo:t.DIMEXO,dimdli:t.DIMDLI,dimexe:t.DIMEXE,dimrnd:t.DIMRND,dimdle:t.DIMDLE,dimtp:t.DIMTP,dimtm:t.DIMTM,dimtxt:t.DIMTXT,dimcen:t.DIMCEN,dimtsz:t.DIMTSZ,dimaltf:t.DIMALTF,dimlfac:t.DIMLFAC,dimtvp:t.DIMTVP,dimtfac:t.DIMTFAC,dimgap:t.DIMGAP,dimaltrnd:t.DIMALTRND,dimtol:t.DIMTOL==null||t.DIMTOL==0?0:1,dimlim:t.DIMLIM==null||t.DIMLIM==0?0:1,dimtih:t.DIMTIH==null||t.DIMTIH==0?0:1,dimtoh:t.DIMTOH==null||t.DIMTOH==0?0:1,dimse1:t.DIMSE1==null||t.DIMSE1==0?0:1,dimse2:t.DIMSE2==null||t.DIMSE2==0?0:1,dimtad:t.DIMTAD,dimzin:t.DIMZIN,dimazin:t.DIMAZIN,dimalt:t.DIMALT,dimaltd:t.DIMALTD,dimtofl:t.DIMTOFL,dimsah:t.DIMSAH,dimtix:t.DIMTIX,dimsoxd:t.DIMSOXD,dimclrd:t.DIMCLRD,dimclre:t.DIMCLRE,dimclrt:t.DIMCLRT,dimadec:t.DIMADEC||0,dimunit:t.DIMUNIT||2,dimdec:t.DIMDEC,dimtdec:t.DIMTDEC,dimaltu:t.DIMALTU,dimalttd:t.DIMALTTD,dimaunit:t.DIMAUNIT,dimfrac:t.DIMFRAC,dimlunit:t.DIMLUNIT,dimdsep:t.DIMDSEP,dimtmove:t.DIMTMOVE||0,dimjust:t.DIMJUST,dimsd1:t.DIMSD1,dimsd2:t.DIMSD2,dimtolj:t.DIMTOLJ,dimtzin:t.DIMTZIN,dimaltz:t.DIMALTZ,dimalttz:t.DIMALTTZ,dimfit:t.DIMFIT||0,dimupt:t.DIMUPT,dimatfit:t.DIMATFIT,dimtxsty:"Standard",dimldrblk:"",dimblk:t.DIMBLK||"",dimblk1:t.DIMBLK1||"",dimblk2:t.DIMBLK2||"",dimlwd:t.DIMLWD,dimlwe:t.DIMLWE},i=new r.AcDbDimStyleTableRecord(s);this.processCommonTableEntryAttrs(t,i),n.tables.dimStyleTable.add(i)})}processLayers(e,n){e.tables.LAYER.entries.forEach(t=>{const s=new r.AcCmColor;s.colorIndex=t.colorIndex;const i=new r.AcDbLayerTableRecord({name:t.name,standardFlags:t.standardFlag,linetype:t.lineType,lineWeight:t.lineweight,isOff:t.off,color:s,isPlottable:t.plotFlag!=0});this.processCommonTableEntryAttrs(t,i),n.tables.layerTable.add(i)})}processViewports(e,n){e.tables.VPORT.entries.forEach(t=>{const s=new r.AcDbViewportTableRecord;this.processCommonTableEntryAttrs(t,s),t.circleSides&&(s.circleSides=t.circleSides),s.standardFlag=t.standardFlag,s.center.copy(t.center),s.lowerLeftCorner.copy(t.lowerLeftCorner),s.upperRightCorner.copy(t.upperRightCorner),t.snapBasePoint&&s.snapBase.copy(t.snapBasePoint),t.snapRotationAngle&&(s.snapAngle=t.snapRotationAngle),t.snapSpacing&&s.snapIncrements.copy(t.snapSpacing),t.majorGridLines&&(s.gridMajor=t.majorGridLines),t.gridSpacing&&s.gridIncrements.copy(t.gridSpacing),t.backgroundObjectId&&(s.backgroundObjectId=t.backgroundObjectId),s.gsView.center.copy(t.center),s.gsView.viewDirectionFromTarget.copy(t.viewDirectionFromTarget),s.gsView.viewTarget.copy(t.viewTarget),t.lensLength&&(s.gsView.lensLength=t.lensLength),t.frontClippingPlane&&(s.gsView.frontClippingPlane=t.frontClippingPlane),t.backClippingPlane&&(s.gsView.backClippingPlane=t.backClippingPlane),t.viewHeight&&(s.gsView.viewHeight=t.viewHeight),t.viewTwistAngle&&(s.gsView.viewTwistAngle=t.viewTwistAngle),t.frozenLayers&&(s.gsView.frozenLayers=t.frozenLayers),t.styleSheet&&(s.gsView.styleSheet=t.styleSheet),t.renderMode&&(s.gsView.renderMode=t.renderMode),t.viewMode&&(s.gsView.viewMode=t.viewMode),t.ucsIconSetting&&(s.gsView.ucsIconSetting=t.ucsIconSetting),t.ucsOrigin&&s.gsView.ucsOrigin.copy(t.ucsOrigin),t.ucsXAxis&&s.gsView.ucsXAxis.copy(t.ucsXAxis),t.ucsYAxis&&s.gsView.ucsYAxis.copy(t.ucsYAxis),t.orthographicType&&(s.gsView.orthographicType=t.orthographicType),t.shadePlotSetting&&(s.gsView.shadePlotSetting=t.shadePlotSetting),t.shadePlotObjectId&&(s.gsView.shadePlotObjectId=t.shadePlotObjectId),t.visualStyleObjectId&&(s.gsView.visualStyleObjectId=t.visualStyleObjectId),t.isDefaultLightingOn&&(s.gsView.isDefaultLightingOn=t.isDefaultLightingOn),t.defaultLightingType&&(s.gsView.defaultLightingType=t.defaultLightingType),t.brightness&&(s.gsView.brightness=t.brightness),t.contrast&&(s.gsView.contrast=t.contrast),t.ambientColor&&(s.gsView.ambientColor=t.ambientColor),n.tables.viewportTable.add(s)})}processBlockTables(e,n){e.tables.BLOCK_RECORD.entries.forEach(t=>{let s=n.tables.blockTable.getAt(t.name);s||(s=new r.AcDbBlockTableRecord,s.objectId=t.handle.toString(),s.name=t.name,s.ownerId=t.ownerHandle.toString(),s.origin.copy(t.basePoint),s.layoutId=t.layout.toString(),n.tables.blockTable.add(s)),!s.isModelSapce&&!s.isPaperSapce&&t.entities&&t.entities.length>0&&this.processEntitiesInBlock(t.entities,s)})}processBlocks(e,n){}async processEntitiesInBlock(e,n){const o=new b,t=e.length,s=[];for(let i=0;i<t;i++){const l=e[i],c=o.convert(l);c&&s.push(c)}n.appendEntity(s)}async processEntities(e,n,o,t,s){const i=new b,l=e.entities,c=l.length,p=new r.AcDbBatchProcessing(c,100-t.value,o),a=n.tables.blockTable.modelSpace;await p.processChunk(async(D,u)=>{const h=[];for(let d=D;d<u;d++){const g=l[d],A=i.convert(g);A&&h.push(A)}if(a.appendEntity(h),s){let d=t.value+u/c*(100-t.value);d>100&&(d=100),await s(d,"ENTITY","IN-PROGRESS")}})}processHeader(e,n){const o=e.header;n.cecolor.colorIndex=o.CECOLOR||256,n.angBase=o.ANGBASE??0,n.angDir=o.ANGDIR??0,n.aunits=o.AUNITS??0,n.extmax=o.EXTMAX,n.extmin=o.EXTMIN,n.insunits=o.INSUNITS??1,n.pdmode=o.PDMODE??0,n.pdsize=o.PDSIZE??0}processCommonTableEntryAttrs(e,n){n.name=e.name,n.objectId=e.handle.toString(),n.ownerId=e.ownerHandle.toString()}processObjects(e,n){this.processLayouts(e,n),this.processImageDefs(e,n)}processLayouts(e,n){const o=n.dictionaries.layouts;e.objects.LAYOUT.forEach(s=>{const i=new r.AcDbLayout;i.layoutName=s.layoutName,i.tabOrder=s.tabOrder;const l=n.tables.blockTable.newIterator();i.objectId=s.handle.toString();for(const c of l)if(c.layoutId===i.objectId){i.blockTableRecordId=c.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),o.setAt(i.layoutName,i)})}processImageDefs(e,n){const o=n.dictionaries.imageDefs;e.objects.IMAGEDEF.forEach(s=>{const i=new r.AcDbRasterImageDef;i.sourceFileName=s.fileName,this.processCommonObjectAttrs(s,i),o.setAt(i.objectId,i)})}processCommonObjectAttrs(e,n){n.objectId=e.handle.toString(),n.ownerId=e.ownerHandle.toString()}}f.AcDbLibreDwgConverter=I,Object.defineProperty(f,Symbol.toStringTag,{value:"Module"})});