@mlightcad/libredwg-converter 3.5.9 → 3.5.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,5 @@
1
- import { AcDbFace as C, AcDbArc as v, AcGeVector3d as h, AcDbCircle as x, AcDbEllipse as O, AcDbLine as m, AcGePoint3d as y, AcDbSpline as T, AcDbPoint as k, AcDbTrace as R, AcDbPolyline as F, AcGePoint2d as b, AcDbPoly2dType as A, AcDb2dPolyline as V, AcDbPoly3dType as w, AcDb3dPolyline as N, AcDbHatch as B, AcGePolyline2d as z, AcGeLoop2d as j, AcGeLine2d as W, AcGeCircArc2d as H, AcGeVector2d as X, AcGeEllipseArc2d as U, AcGeSpline3d as P, AcDbTable as G, AcDbText as Y, AcDbMText as _, AcDbLeader as Z, AcDbAlignedDimension as K, AcDb3PointAngularDimension as q, AcDbOrdinateDimension as J, AcDbRadialDimension as Q, AcDbDiametricDimension as $, AcDbRasterImage as ee, AcDbWipeout as ne, AcDbViewport as te, AcDbRay as oe, AcDbXline as se, AcDbAttributeFlags as I, AcDbAttributeMTextFlag as E, AcDbAttribute as re, AcDbAttributeDefinition as ie, AcDbBlockReference as ce, AcCmTransparency as le, AcDbDatabaseConverter as ae, createWorkerApi as de, AcDbLinetypeTableRecord as pe, AcDbTextStyleTableRecord as ue, DEFAULT_TEXT_STYLE as L, AcDbDimStyleTableRecord as fe, AcCmColor as he, AcDbLayerTableRecord as ge, AcDbViewportTableRecord as De, AcDbBlockTableRecord as Ae, AcDbBatchProcessing as Ie, AcDbLayout as we, AcDbRasterImageDef as ye } from "@mlightcad/data-model";
2
- class M {
1
+ import { AcDbFace as x, AcDbArc as O, AcGeVector3d as D, AcDbCircle as m, AcDbEllipse as k, AcDbLine as F, AcGePoint3d as y, AcDbSpline as T, AcDbPoint as R, AcDbTrace as V, AcDbPolyline as N, AcGePoint2d as b, AcDbPoly2dType as A, AcDb2dPolyline as B, AcDbPoly3dType as w, AcDb3dPolyline as z, AcDbHatch as j, AcGePolyline2d as W, AcGeLine2d as H, AcGeCircArc2d as X, AcGeVector2d as U, AcGeEllipseArc2d as G, AcGeSpline3d as E, AcGeLoop2d as P, AcDbTable as Y, AcDbText as _, AcDbMText as Z, AcDbLeader as K, AcDbAlignedDimension as q, AcDb3PointAngularDimension as J, AcDbOrdinateDimension as Q, AcDbRadialDimension as $, AcDbDiametricDimension as ee, AcDbRasterImage as ne, AcDbWipeout as te, AcDbViewport as oe, AcDbRay as se, AcDbXline as re, AcDbAttributeFlags as I, AcDbAttributeMTextFlag as L, AcDbAttribute as ie, AcDbAttributeDefinition as ce, AcDbBlockReference as le, AcCmTransparency as ae, AcDbDatabaseConverter as de, createWorkerApi as pe, AcDbLinetypeTableRecord as ue, AcDbTextStyleTableRecord as fe, DEFAULT_TEXT_STYLE as M, AcDbDimStyleTableRecord as he, AcCmColor as ge, AcDbLayerTableRecord as De, AcDbViewportTableRecord as Ae, AcDbBlockTableRecord as Ie, AcDbBatchProcessing as we, AcDbLayout as ye, AcDbRasterImageDef as Te } from "@mlightcad/data-model";
2
+ class S {
3
3
  convert(e) {
4
4
  const n = this.createEntity(e);
5
5
  return n && this.processCommonAttrs(e, n), n;
@@ -13,30 +13,30 @@ class M {
13
13
  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;
14
14
  }
15
15
  convertFace(e) {
16
- const n = new C();
16
+ const n = new x();
17
17
  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;
18
18
  }
19
19
  convertArc(e) {
20
- return new v(
20
+ return new O(
21
21
  e.center,
22
22
  e.radius,
23
23
  e.startAngle,
24
24
  e.endAngle,
25
- e.extrusionDirection ?? h.Z_AXIS
25
+ e.extrusionDirection ?? D.Z_AXIS
26
26
  );
27
27
  }
28
28
  convertCirle(e) {
29
- return new x(
29
+ return new m(
30
30
  e.center,
31
31
  e.radius,
32
- e.extrusionDirection ?? h.Z_AXIS
32
+ e.extrusionDirection ?? D.Z_AXIS
33
33
  );
34
34
  }
35
35
  convertEllipse(e) {
36
- const n = new h(e.majorAxisEndPoint), o = n.length();
37
- return new O(
36
+ const n = new D(e.majorAxisEndPoint), o = n.length();
37
+ return new k(
38
38
  e.center,
39
- e.extrusionDirection ?? h.Z_AXIS,
39
+ e.extrusionDirection ?? D.Z_AXIS,
40
40
  n,
41
41
  o,
42
42
  o * e.axisRatio,
@@ -46,7 +46,7 @@ class M {
46
46
  }
47
47
  convertLine(e) {
48
48
  const n = e.startPoint, o = e.endPoint;
49
- return new m(
49
+ return new F(
50
50
  new y(n.x, n.y, n.z),
51
51
  new y(o.x, o.y, o.z)
52
52
  );
@@ -74,18 +74,18 @@ class M {
74
74
  return null;
75
75
  }
76
76
  convertPoint(e) {
77
- const n = new k();
77
+ const n = new R();
78
78
  return n.position = e.position, n;
79
79
  }
80
80
  convertSolid(e) {
81
- const n = new R();
81
+ const n = new V();
82
82
  return n.setPointAt(0, { ...e.corner1, z: 0 }), n.setPointAt(1, { ...e.corner2, z: 0 }), n.setPointAt(2, { ...e.corner3, z: 0 }), n.setPointAt(
83
83
  3,
84
84
  e.corner4 ? { ...e.corner4, z: 0 } : { ...e.corner3, z: 0 }
85
85
  ), n.thickness = e.thickness, n;
86
86
  }
87
87
  convertLWPolyline(e) {
88
- const n = new F();
88
+ const n = new N();
89
89
  return n.closed = !!(e.flag & 512), e.vertices.forEach((o, t) => {
90
90
  n.addVertexAt(
91
91
  t,
@@ -106,7 +106,7 @@ class M {
106
106
  }), t.push(r.bulge ?? 0));
107
107
  });
108
108
  let s = A.SimplePoly;
109
- return e.flag & 2 ? s = A.FitCurvePoly : e.flag & 4 && (e.smoothType == 6 ? s = A.CubicSplinePoly : e.smoothType == 5 && (s = A.QuadSplinePoly)), new V(
109
+ return e.flag & 2 ? s = A.FitCurvePoly : e.flag & 4 && (e.smoothType == 6 ? s = A.CubicSplinePoly : e.smoothType == 5 && (s = A.QuadSplinePoly)), new B(
110
110
  s,
111
111
  o,
112
112
  0,
@@ -126,11 +126,11 @@ class M {
126
126
  });
127
127
  });
128
128
  let t = w.SimplePoly;
129
- return e.flag & 4 && (e.smoothType == 6 ? t = w.CubicSplinePoly : e.smoothType == 5 && (t = w.QuadSplinePoly)), new N(t, o, n);
129
+ return e.flag & 4 && (e.smoothType == 6 ? t = w.CubicSplinePoly : e.smoothType == 5 && (t = w.QuadSplinePoly)), new z(t, o, n);
130
130
  }
131
131
  convertHatch(e) {
132
132
  var t;
133
- const n = new B();
133
+ const n = new j();
134
134
  return (t = e.definitionLines) == null || t.forEach((s) => {
135
135
  n.definitionLines.push({
136
136
  angle: s.angle,
@@ -140,25 +140,25 @@ class M {
140
140
  });
141
141
  }), 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((s) => {
142
142
  if (s.boundaryPathTypeFlag & 2) {
143
- const l = s, i = new z();
144
- i.closed = l.isClosed, l.vertices.forEach((a, c) => {
145
- i.addVertexAt(c, {
146
- x: a.x,
147
- y: a.y,
148
- bulge: a.bulge
143
+ const l = s, i = new W();
144
+ i.closed = l.isClosed, l.vertices.forEach((d, a) => {
145
+ i.addVertexAt(a, {
146
+ x: d.x,
147
+ y: d.y,
148
+ bulge: d.bulge
149
149
  });
150
150
  }), n.add(i);
151
151
  } else {
152
- const l = s, i = new j();
152
+ const l = s, i = [];
153
153
  l.edges.forEach((a) => {
154
154
  if (a != null) {
155
155
  if (a.type == 1) {
156
156
  const c = a;
157
- i.add(new W(c.start, c.end));
157
+ i.push(new H(c.start, c.end));
158
158
  } else if (a.type == 2) {
159
159
  const c = a;
160
- i.add(
161
- new H(
160
+ i.push(
161
+ new X(
162
162
  c.center,
163
163
  c.radius,
164
164
  c.startAngle,
@@ -168,63 +168,65 @@ class M {
168
168
  );
169
169
  } else if (a.type == 3) {
170
170
  const c = a;
171
- new X().subVectors(c.end, c.center);
171
+ new U().subVectors(c.end, c.center);
172
172
  const p = Math.sqrt(
173
173
  Math.pow(c.end.x, 2) + Math.pow(c.end.y, 2)
174
- ), f = p * c.lengthOfMinorAxis;
175
- let d = c.startAngle, g = c.endAngle;
176
- const D = Math.atan2(c.end.y, c.end.x);
177
- c.isCCW || (d = Math.PI * 2 - d, g = Math.PI * 2 - g), i.add(
178
- new U(
174
+ ), u = p * c.lengthOfMinorAxis;
175
+ let f = c.startAngle, g = c.endAngle;
176
+ const v = Math.atan2(c.end.y, c.end.x);
177
+ c.isCCW || (f = Math.PI * 2 - f, g = Math.PI * 2 - g), i.push(
178
+ new G(
179
179
  { ...c.center, z: 0 },
180
180
  p,
181
+ u,
181
182
  f,
182
- d,
183
183
  g,
184
184
  !c.isCCW,
185
- D
185
+ v
186
186
  )
187
187
  );
188
188
  } else if (a.type == 4) {
189
189
  const c = a;
190
190
  if (c.numberOfControlPoints > 0 && c.numberOfKnots > 0) {
191
- const u = c.controlPoints.map(
192
- (d) => ({
193
- x: d.x,
194
- y: d.y,
191
+ const h = c.controlPoints.map(
192
+ (f) => ({
193
+ x: f.x,
194
+ y: f.y,
195
195
  z: 0
196
196
  })
197
197
  );
198
198
  let p = !0;
199
- const f = c.controlPoints.map((d) => (d.weight == null && (p = !1), d.weight || 1));
200
- i.add(
201
- new P(
202
- u,
199
+ const u = c.controlPoints.map((f) => (f.weight == null && (p = !1), f.weight || 1));
200
+ i.push(
201
+ new E(
202
+ h,
203
203
  c.knots,
204
- p ? f : void 0
204
+ p ? u : void 0
205
205
  )
206
206
  );
207
207
  } else if (c.numberOfFitData > 0) {
208
- const u = c.fitDatum.map((p) => ({
208
+ const h = c.fitDatum.map((p) => ({
209
209
  x: p.x,
210
210
  y: p.y,
211
211
  z: 0
212
212
  }));
213
- i.add(new P(u, "Uniform"));
213
+ i.push(new E(h, "Uniform"));
214
214
  }
215
215
  }
216
216
  }
217
- }), n.add(i);
217
+ });
218
+ const d = P.buildFromEdges(i);
219
+ d.length == 0 && i.length > 0 ? n.add(new P(i)) : d.forEach((a) => n.add(a));
218
220
  }
219
221
  }), n;
220
222
  }
221
223
  convertTable(e) {
222
- const n = new G(
224
+ const n = new Y(
223
225
  e.name,
224
226
  e.rowCount,
225
227
  e.columnCount
226
228
  );
227
- return n.tableStyleId = e.tableStyleId, n.owningBlockRecordId = e.blockRecordHandle, e.directionVector && (n.horizontalDirection = new h(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(
229
+ return n.tableStyleId = e.tableStyleId, n.owningBlockRecordId = e.blockRecordHandle, e.directionVector && (n.horizontalDirection = new D(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(
228
230
  (o, t) => n.setColumnWidth(t, o)
229
231
  ), e.rowHeightArr.forEach(
230
232
  (o, t) => n.setRowHeight(t, o)
@@ -233,22 +235,22 @@ class M {
233
235
  }), n;
234
236
  }
235
237
  convertText(e) {
236
- const n = new Y();
238
+ const n = new _();
237
239
  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;
238
240
  }
239
241
  convertMText(e) {
240
- const n = new _();
241
- 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;
242
+ const n = new Z();
243
+ 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 D(e.direction)), n.drawingDirection = e.drawingDirection, n;
242
244
  }
243
245
  convertLeader(e) {
244
- const n = new Z();
246
+ const n = new K();
245
247
  return e.vertices.forEach((o) => {
246
248
  n.appendVertex(o);
247
249
  }), n.hasArrowHead = e.isArrowheadEnabled, n.hasHookLine = e.isHooklineExists, n.isSplined = e.isSpline, n.dimensionStyle = e.styleName, n.annoType = e.leaderCreationFlag, n;
248
250
  }
249
251
  convertDimension(e) {
250
252
  if (e.subclassMarker == "AcDbAlignedDimension" || e.subclassMarker == "AcDbRotatedDimension") {
251
- const n = e, o = new K(
253
+ const n = e, o = new q(
252
254
  n.subDefinitionPoint1,
253
255
  n.subDefinitionPoint2,
254
256
  n.definitionPoint
@@ -259,7 +261,7 @@ class M {
259
261
  z: 0
260
262
  }), o.rotation = n.rotationAngle, this.processDimensionCommonAttrs(e, o), o;
261
263
  } else if (e.subclassMarker == "AcDb3PointAngularDimension") {
262
- const n = e, o = new q(
264
+ const n = e, o = new J(
263
265
  n.centerPoint,
264
266
  n.subDefinitionPoint1,
265
267
  n.subDefinitionPoint2,
@@ -267,20 +269,20 @@ class M {
267
269
  );
268
270
  return this.processDimensionCommonAttrs(e, o), o;
269
271
  } else if (e.subclassMarker == "AcDbOrdinateDimension") {
270
- const n = e, o = new J(
272
+ const n = e, o = new Q(
271
273
  n.subDefinitionPoint1,
272
274
  n.subDefinitionPoint2
273
275
  );
274
276
  return this.processDimensionCommonAttrs(e, o), o;
275
277
  } else if (e.subclassMarker == "AcDbRadialDimension") {
276
- const n = e, o = new Q(
278
+ const n = e, o = new $(
277
279
  n.definitionPoint,
278
280
  n.centerPoint,
279
281
  n.leaderLength
280
282
  );
281
283
  return this.processDimensionCommonAttrs(e, o), o;
282
284
  } else if (e.subclassMarker == "AcDbDiametricDimension") {
283
- const n = e, o = new $(
285
+ const n = e, o = new ee(
284
286
  n.definitionPoint,
285
287
  n.centerPoint,
286
288
  n.leaderLength
@@ -299,39 +301,39 @@ class M {
299
301
  ) * e.imageSize.y, n.rotation = Math.atan2(e.uPixel.y, e.uPixel.x);
300
302
  }
301
303
  convertImage(e) {
302
- const n = new ee();
304
+ const n = new ne();
303
305
  return this.processImage(e, n), n;
304
306
  }
305
307
  convertWipeout(e) {
306
- const n = new ne();
308
+ const n = new te();
307
309
  return this.processImage(e, n), n;
308
310
  }
309
311
  convertViewport(e) {
310
- const n = new te();
312
+ const n = new oe();
311
313
  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;
312
314
  }
313
315
  convertRay(e) {
314
- const n = new oe();
316
+ const n = new se();
315
317
  return n.basePoint.copy(e.firstPoint), n.unitDir.copy(e.unitDirection), n;
316
318
  }
317
319
  convertXline(e) {
318
- const n = new se();
320
+ const n = new re();
319
321
  return n.basePoint.copy(e.firstPoint), n.unitDir.copy(e.unitDirection), n;
320
322
  }
321
323
  convertAttributeCommon(e, n) {
322
324
  const o = e.text;
323
- 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 & I.Invisible) !== 0, n.isConst = (e.flags & I.Const) !== 0, n.isVerifiable = (e.flags & I.Verifiable) !== 0, n.isPreset = (e.flags & I.Preset) !== 0, n.lockPositionInBlock = e.lockPositionFlag, n.isReallyLocked = e.isReallyLocked, n.isMTextAttribute = (e.mtextFlag & E.MultiLine) !== 0, n.isConstMTextAttribute = (e.mtextFlag & E.ConstMultiLine) !== 0;
325
+ 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 & I.Invisible) !== 0, n.isConst = (e.flags & I.Const) !== 0, n.isVerifiable = (e.flags & I.Verifiable) !== 0, n.isPreset = (e.flags & I.Preset) !== 0, n.lockPositionInBlock = e.lockPositionFlag, n.isReallyLocked = e.isReallyLocked, n.isMTextAttribute = (e.mtextFlag & L.MultiLine) !== 0, n.isConstMTextAttribute = (e.mtextFlag & L.ConstMultiLine) !== 0;
324
326
  }
325
327
  convertAttribute(e) {
326
- const n = new re();
328
+ const n = new ie();
327
329
  return this.convertAttributeCommon(e, n), n;
328
330
  }
329
331
  convertAttributeDefinition(e) {
330
- const n = new ie();
332
+ const n = new ce();
331
333
  return this.convertAttributeCommon(e, n), n.prompt = e.prompt, n;
332
334
  }
333
335
  convertBlockReference(e) {
334
- const n = new ce(e.name);
336
+ const n = new le(e.name);
335
337
  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) => {
336
338
  const t = this.convertAttribute(o);
337
339
  n.appendAttributes(t);
@@ -342,20 +344,20 @@ class M {
342
344
  }
343
345
  processCommonAttrs(e, n) {
344
346
  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) {
345
- const o = new le();
347
+ const o = new ae();
346
348
  o.method = e.transparencyType, (o.isByBlock || o.isByBlock) && (o.alpha = e.transparency), n.transparency = o;
347
349
  }
348
350
  }
349
351
  }
350
- const Te = "*MODEL_SPACE";
351
- class Pe extends ae {
352
+ const be = "*MODEL_SPACE";
353
+ class Pe extends de {
352
354
  constructor(e = {}) {
353
355
  super(e), e.useWorker = !0, e.parserWorkerUrl || (e.parserWorkerUrl = "/assets/libredwg-parser-worker.js");
354
356
  }
355
357
  async parse(e, n) {
356
358
  const o = this.config, t = this.getParserWorkerTimeout(e, n);
357
359
  if (o.useWorker && o.parserWorkerUrl) {
358
- const s = de({
360
+ const s = pe({
359
361
  workerUrl: o.parserWorkerUrl,
360
362
  timeout: t,
361
363
  // One concurrent worker needed for parser
@@ -401,14 +403,14 @@ class Pe extends ae {
401
403
  e.forEach((r) => {
402
404
  if (r.type == "MTEXT") {
403
405
  const l = r;
404
- [...l.text.matchAll(s)].forEach((a) => {
405
- t.add(a[1].toLowerCase());
406
+ [...l.text.matchAll(s)].forEach((d) => {
407
+ t.add(d[1].toLowerCase());
406
408
  });
407
409
  const i = o.get(l.styleName);
408
- i == null || i.forEach((a) => t.add(a));
410
+ i == null || i.forEach((d) => t.add(d));
409
411
  } else if (r.type == "TEXT") {
410
412
  const l = r, i = o.get(l.styleName);
411
- i == null || i.forEach((a) => t.add(a));
413
+ i == null || i.forEach((d) => t.add(d));
412
414
  } else if (r.type == "INSERT") {
413
415
  const l = r, i = n.get(l.name);
414
416
  i && this.getFontsInBlock(i.entities, n, o, t);
@@ -423,13 +425,13 @@ class Pe extends ae {
423
425
  standardFlag: t.standardFlag,
424
426
  totalPatternLength: t.totalPatternLength,
425
427
  pattern: t.pattern
426
- }, r = new pe(s);
428
+ }, r = new ue(s);
427
429
  this.processCommonTableEntryAttrs(t, r), r.name = t.name, n.tables.linetypeTable.add(r);
428
430
  });
429
431
  }
430
432
  processTextStyles(e, n) {
431
433
  e.tables.STYLE.entries.forEach((t) => {
432
- const s = new ue(t);
434
+ const s = new fe(t);
433
435
  this.processCommonTableEntryAttrs(t, s), n.tables.textStyleTable.add(s);
434
436
  });
435
437
  }
@@ -497,7 +499,7 @@ class Pe extends ae {
497
499
  dimfit: t.DIMFIT || 0,
498
500
  dimupt: t.DIMUPT,
499
501
  dimatfit: t.DIMATFIT,
500
- dimtxsty: L,
502
+ dimtxsty: M,
501
503
  // TODO: Set correct value
502
504
  dimldrblk: "",
503
505
  // TODO: Set correct value
@@ -509,15 +511,15 @@ class Pe extends ae {
509
511
  // TODO: Set correct value
510
512
  dimlwd: t.DIMLWD,
511
513
  dimlwe: t.DIMLWE
512
- }, r = new fe(s);
514
+ }, r = new he(s);
513
515
  this.processCommonTableEntryAttrs(t, r), n.tables.dimStyleTable.add(r);
514
516
  });
515
517
  }
516
518
  processLayers(e, n) {
517
519
  e.tables.LAYER.entries.forEach((t) => {
518
- const s = new he();
520
+ const s = new ge();
519
521
  s.colorIndex = t.colorIndex;
520
- const r = new ge({
522
+ const r = new De({
521
523
  name: t.name,
522
524
  standardFlags: t.standardFlag,
523
525
  linetype: t.lineType,
@@ -531,20 +533,20 @@ class Pe extends ae {
531
533
  }
532
534
  processViewports(e, n) {
533
535
  e.tables.VPORT.entries.forEach((t) => {
534
- const s = new De();
536
+ const s = new Ae();
535
537
  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);
536
538
  });
537
539
  }
538
540
  processBlockTables(e, n) {
539
541
  e.tables.BLOCK_RECORD.entries.forEach((t) => {
540
542
  let s = n.tables.blockTable.getAt(t.name);
541
- s || (s = new Ae(), s.objectId = t.handle, s.name = t.name, s.ownerId = t.ownerHandle, s.origin.copy(t.basePoint), s.layoutId = t.layout, s.blockInsertUnits = t.insertionUnits, s.explodability = t.explodability, s.blockScaling = t.scalability, t.bmpPreview && (s.bmpPreview = t.bmpPreview), n.tables.blockTable.add(s)), !s.isModelSapce && t.entities && t.entities.length > 0 && this.processEntitiesInBlock(t.entities, s);
543
+ s || (s = new Ie(), s.objectId = t.handle, s.name = t.name, s.ownerId = t.ownerHandle, s.origin.copy(t.basePoint), s.layoutId = t.layout, s.blockInsertUnits = t.insertionUnits, s.explodability = t.explodability, s.blockScaling = t.scalability, t.bmpPreview && (s.bmpPreview = t.bmpPreview), n.tables.blockTable.add(s)), !s.isModelSapce && t.entities && t.entities.length > 0 && this.processEntitiesInBlock(t.entities, s);
542
544
  });
543
545
  }
544
546
  processBlocks(e, n) {
545
547
  }
546
548
  async processEntitiesInBlock(e, n) {
547
- const o = new M(), t = e.length, s = [];
549
+ const o = new S(), t = e.length, s = [];
548
550
  for (let r = 0; r < t; r++) {
549
551
  const l = e[r], i = o.convert(l);
550
552
  i && s.push(i);
@@ -557,33 +559,33 @@ class Pe extends ae {
557
559
  * smaller pieces and executed in small intervals to allow the UI to remain responsive.
558
560
  */
559
561
  async processEntities(e, n, o, t, s) {
560
- const r = new M();
562
+ const r = new S();
561
563
  let l = [];
562
- e.tables.BLOCK_RECORD.entries.forEach((u) => {
563
- this.isModelSpace(u.name) && (l = u.entities);
564
+ e.tables.BLOCK_RECORD.entries.forEach((c) => {
565
+ this.isModelSpace(c.name) && (l = c.entities);
564
566
  });
565
- const i = l.length, a = new Ie(
567
+ const i = l.length, d = new we(
566
568
  i,
567
569
  100 - t.value,
568
570
  o
569
571
  );
570
572
  this.config.convertByEntityType && (l = this.groupAndFlattenByType(l));
571
- const c = n.tables.blockTable.modelSpace;
572
- await a.processChunk(async (u, p) => {
573
- const f = [];
574
- for (let d = u; d < p; d++) {
575
- const g = l[d], D = r.convert(g);
576
- D && f.push(D);
573
+ const a = n.tables.blockTable.modelSpace;
574
+ await d.processChunk(async (c, h) => {
575
+ const p = [];
576
+ for (let u = c; u < h; u++) {
577
+ const f = l[u], g = r.convert(f);
578
+ g && p.push(g);
577
579
  }
578
- if (c.appendEntity(f), s) {
579
- let d = t.value + p / i * (100 - t.value);
580
- d > 100 && (d = 100), await s(d, "ENTITY", "IN-PROGRESS");
580
+ if (a.appendEntity(p), s) {
581
+ let u = t.value + h / i * (100 - t.value);
582
+ u > 100 && (u = 100), await s(u, "ENTITY", "IN-PROGRESS");
581
583
  }
582
584
  });
583
585
  }
584
586
  processHeader(e, n) {
585
587
  const o = e.header;
586
- 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 ?? L;
588
+ 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 ?? M;
587
589
  }
588
590
  processCommonTableEntryAttrs(e, n) {
589
591
  n.name = e.name, n.objectId = e.handle, n.ownerId = e.ownerHandle;
@@ -594,7 +596,7 @@ class Pe extends ae {
594
596
  processLayouts(e, n) {
595
597
  const o = n.objects.layout;
596
598
  e.objects.LAYOUT.forEach((s) => {
597
- const r = new we();
599
+ const r = new ye();
598
600
  r.layoutName = s.layoutName, r.tabOrder = s.tabOrder;
599
601
  const l = n.tables.blockTable.newIterator();
600
602
  r.objectId = s.handle;
@@ -609,7 +611,7 @@ class Pe extends ae {
609
611
  processImageDefs(e, n) {
610
612
  const o = n.objects.imageDefinition;
611
613
  e.objects.IMAGEDEF.forEach((s) => {
612
- const r = new ye();
614
+ const r = new Te();
613
615
  r.sourceFileName = s.fileName, this.processCommonObjectAttrs(s, r), o.setAt(r.objectId, r);
614
616
  });
615
617
  }
@@ -636,7 +638,7 @@ class Pe extends ae {
636
638
  return o.flatMap((t) => n[t]);
637
639
  }
638
640
  isModelSpace(e) {
639
- return e && e.toUpperCase() == Te;
641
+ return e && e.toUpperCase() == be;
640
642
  }
641
643
  }
642
644
  export {
@@ -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(n){console.log(`Failed to convert spline with error: ${n}`)}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,t)=>{n.addVertexAt(t,new r.AcGePoint2d(o.x,o.y),o.bulge,o.startWidth,o.endWidth)}),n}convertPolyline2d(e){const n=!!(e.flag&1),o=[],t=[];e.vertices.map(i=>{i.flag&16||(o.push({x:i.x,y:i.y,z:i.z}),t.push(i.bulge??0))});let s=r.AcDbPoly2dType.SimplePoly;return e.flag&2?s=r.AcDbPoly2dType.FitCurvePoly:e.flag&4&&(e.smoothType==6?s=r.AcDbPoly2dType.CubicSplinePoly:e.smoothType==5&&(s=r.AcDbPoly2dType.QuadSplinePoly)),new r.AcDb2dPolyline(s,o,0,n,e.startWidth,e.endWidth,t)}convertPolyline3d(e){const n=!!(e.flag&1),o=[];e.vertices.map(s=>{s.flag&16||o.push({x:s.x,y:s.y,z:s.z})});let t=r.AcDbPoly3dType.SimplePoly;return e.flag&4&&(e.smoothType==6?t=r.AcDbPoly3dType.CubicSplinePoly:e.smoothType==5&&(t=r.AcDbPoly3dType.QuadSplinePoly)),new r.AcDb3dPolyline(t,o,n)}convertHatch(e){var t;const n=new r.AcDbHatch;return(t=e.definitionLines)==null||t.forEach(s=>{n.definitionLines.push({angle:s.angle,base:s.base,offset:s.offset,dashLengths:s.numberOfDashLengths>0?s.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(s=>{if(s.boundaryPathTypeFlag&2){const a=s,c=new r.AcGePolyline2d;c.closed=a.isClosed,a.vertices.forEach((p,l)=>{c.addVertexAt(l,{x:p.x,y:p.y,bulge:p.bulge})}),n.add(c)}else{const a=s,c=new r.AcGeLoop2d;a.edges.forEach(p=>{if(p!=null){if(p.type==1){const l=p;c.add(new r.AcGeLine2d(l.start,l.end))}else if(p.type==2){const l=p;c.add(new r.AcGeCircArc2d(l.center,l.radius,l.startAngle,l.endAngle,!l.isCCW))}else if(p.type==3){const l=p;new r.AcGeVector2d().subVectors(l.end,l.center);const f=Math.sqrt(Math.pow(l.end.x,2)+Math.pow(l.end.y,2)),g=f*l.lengthOfMinorAxis;let u=l.startAngle,d=l.endAngle;const A=Math.atan2(l.end.y,l.end.x);l.isCCW||(u=Math.PI*2-u,d=Math.PI*2-d),c.add(new r.AcGeEllipseArc2d({...l.center,z:0},f,g,u,d,!l.isCCW,A))}else if(p.type==4){const l=p;if(l.numberOfControlPoints>0&&l.numberOfKnots>0){const h=l.controlPoints.map(u=>({x:u.x,y:u.y,z:0}));let f=!0;const g=l.controlPoints.map(u=>(u.weight==null&&(f=!1),u.weight||1));c.add(new r.AcGeSpline3d(h,l.knots,f?g:void 0))}else if(l.numberOfFitData>0){const h=l.fitDatum.map(f=>({x:f.x,y:f.y,z:0}));c.add(new r.AcGeSpline3d(h,"Uniform"))}}}}),n.add(c)}}),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,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 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 t=this.convertAttribute(o);n.appendAttributes(t)}),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 T="*MODEL_SPACE";class w 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,t=this.getParserWorkerTimeout(e,n);if(o.useWorker&&o.parserWorkerUrl){const s=r.createWorkerApi({workerUrl:o.parserWorkerUrl,timeout:t,maxConcurrentWorkers:1}),i=await s.execute(e);if(s.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,t=i=>{if(i){const a=i.lastIndexOf(".");return a>=0?i.substring(0,a).toLowerCase():i.toLowerCase()}};e.tables.STYLE.entries.forEach(i=>{const a=[];let c=t(i.font);c&&a.push(c),c=t(i.bigFont),c&&a.push(c),o.set(i.name,a)});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 a=i;[...a.text.matchAll(s)].forEach(p=>{t.add(p[1].toLowerCase())});const c=o.get(a.styleName);c==null||c.forEach(p=>t.add(p))}else if(i.type=="TEXT"){const a=i,c=o.get(a.styleName);c==null||c.forEach(p=>t.add(p))}else if(i.type=="INSERT"){const a=i,c=n.get(a.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,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:r.DEFAULT_TEXT_STYLE,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,s.name=t.name,s.ownerId=t.ownerHandle,s.origin.copy(t.basePoint),s.layoutId=t.layout,s.blockInsertUnits=t.insertionUnits,s.explodability=t.explodability,s.blockScaling=t.scalability,t.bmpPreview&&(s.bmpPreview=t.bmpPreview),n.tables.blockTable.add(s)),!s.isModelSapce&&t.entities&&t.entities.length>0&&this.processEntitiesInBlock(t.entities,s)})}processBlocks(e,n){}async processEntitiesInBlock(e,n){const o=new y,t=e.length,s=[];for(let i=0;i<t;i++){const a=e[i],c=o.convert(a);c&&s.push(c)}n.appendEntity(s)}async processEntities(e,n,o,t,s){const i=new y;let a=[];e.tables.BLOCK_RECORD.entries.forEach(h=>{this.isModelSpace(h.name)&&(a=h.entities)});const c=a.length,p=new r.AcDbBatchProcessing(c,100-t.value,o);this.config.convertByEntityType&&(a=this.groupAndFlattenByType(a));const l=n.tables.blockTable.modelSpace;await p.processChunk(async(h,f)=>{const g=[];for(let u=h;u<f;u++){const d=a[u],A=i.convert(d);A&&g.push(A)}if(l.appendEntity(g),s){let u=t.value+f/c*(100-t.value);u>100&&(u=100),await s(u,"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(s=>{const i=new r.AcDbLayout;i.layoutName=s.layoutName,i.tabOrder=s.tabOrder;const a=n.tables.blockTable.newIterator();i.objectId=s.handle;for(const c of a)if(c.layoutId===i.objectId){i.blockTableRecordId=c.objectId;break}i.blockTableRecordId||s.layoutName==="Model"&&(i.blockTableRecordId=n.tables.blockTable.modelSpace.objectId),i.limits.min.copy(s.minLimit),i.limits.max.copy(s.maxLimit),i.extents.min.copy(s.minExtent),i.extents.max.copy(s.maxExtent),s.viewportId&&i.viewportArray.push(s.viewportId),this.processCommonObjectAttrs(s,i),o.setAt(i.layoutName,i)})}processImageDefs(e,n){const o=n.objects.imageDefinition;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,n.ownerId=e.ownerHandle}groupAndFlattenByType(e){const n={},o=[];for(const t of e)n[t.type]||(n[t.type]=[],o.push(t.type)),n[t.type].push(t);return o.flatMap(t=>n[t])}isModelSpace(e){return e&&e.toUpperCase()==T}}D.AcDbLibreDwgConverter=w,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(n){console.log(`Failed to convert spline with error: ${n}`)}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,t)=>{n.addVertexAt(t,new r.AcGePoint2d(o.x,o.y),o.bulge,o.startWidth,o.endWidth)}),n}convertPolyline2d(e){const n=!!(e.flag&1),o=[],t=[];e.vertices.map(i=>{i.flag&16||(o.push({x:i.x,y:i.y,z:i.z}),t.push(i.bulge??0))});let s=r.AcDbPoly2dType.SimplePoly;return e.flag&2?s=r.AcDbPoly2dType.FitCurvePoly:e.flag&4&&(e.smoothType==6?s=r.AcDbPoly2dType.CubicSplinePoly:e.smoothType==5&&(s=r.AcDbPoly2dType.QuadSplinePoly)),new r.AcDb2dPolyline(s,o,0,n,e.startWidth,e.endWidth,t)}convertPolyline3d(e){const n=!!(e.flag&1),o=[];e.vertices.map(s=>{s.flag&16||o.push({x:s.x,y:s.y,z:s.z})});let t=r.AcDbPoly3dType.SimplePoly;return e.flag&4&&(e.smoothType==6?t=r.AcDbPoly3dType.CubicSplinePoly:e.smoothType==5&&(t=r.AcDbPoly3dType.QuadSplinePoly)),new r.AcDb3dPolyline(t,o,n)}convertHatch(e){var t;const n=new r.AcDbHatch;return(t=e.definitionLines)==null||t.forEach(s=>{n.definitionLines.push({angle:s.angle,base:s.base,offset:s.offset,dashLengths:s.numberOfDashLengths>0?s.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(s=>{if(s.boundaryPathTypeFlag&2){const a=s,c=new r.AcGePolyline2d;c.closed=a.isClosed,a.vertices.forEach((u,p)=>{c.addVertexAt(p,{x:u.x,y:u.y,bulge:u.bulge})}),n.add(c)}else{const a=s,c=[];a.edges.forEach(p=>{if(p!=null){if(p.type==1){const l=p;c.push(new r.AcGeLine2d(l.start,l.end))}else if(p.type==2){const l=p;c.push(new r.AcGeCircArc2d(l.center,l.radius,l.startAngle,l.endAngle,!l.isCCW))}else if(p.type==3){const l=p;new r.AcGeVector2d().subVectors(l.end,l.center);const f=Math.sqrt(Math.pow(l.end.x,2)+Math.pow(l.end.y,2)),h=f*l.lengthOfMinorAxis;let g=l.startAngle,A=l.endAngle;const I=Math.atan2(l.end.y,l.end.x);l.isCCW||(g=Math.PI*2-g,A=Math.PI*2-A),c.push(new r.AcGeEllipseArc2d({...l.center,z:0},f,h,g,A,!l.isCCW,I))}else if(p.type==4){const l=p;if(l.numberOfControlPoints>0&&l.numberOfKnots>0){const d=l.controlPoints.map(g=>({x:g.x,y:g.y,z:0}));let f=!0;const h=l.controlPoints.map(g=>(g.weight==null&&(f=!1),g.weight||1));c.push(new r.AcGeSpline3d(d,l.knots,f?h:void 0))}else if(l.numberOfFitData>0){const d=l.fitDatum.map(f=>({x:f.x,y:f.y,z:0}));c.push(new r.AcGeSpline3d(d,"Uniform"))}}}});const u=r.AcGeLoop2d.buildFromEdges(c);u.length==0&&c.length>0?n.add(new r.AcGeLoop2d(c)):u.forEach(p=>n.add(p))}}),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,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 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 t=this.convertAttribute(o);n.appendAttributes(t)}),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 T="*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,t=this.getParserWorkerTimeout(e,n);if(o.useWorker&&o.parserWorkerUrl){const s=r.createWorkerApi({workerUrl:o.parserWorkerUrl,timeout:t,maxConcurrentWorkers:1}),i=await s.execute(e);if(s.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,t=i=>{if(i){const a=i.lastIndexOf(".");return a>=0?i.substring(0,a).toLowerCase():i.toLowerCase()}};e.tables.STYLE.entries.forEach(i=>{const a=[];let c=t(i.font);c&&a.push(c),c=t(i.bigFont),c&&a.push(c),o.set(i.name,a)});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 a=i;[...a.text.matchAll(s)].forEach(u=>{t.add(u[1].toLowerCase())});const c=o.get(a.styleName);c==null||c.forEach(u=>t.add(u))}else if(i.type=="TEXT"){const a=i,c=o.get(a.styleName);c==null||c.forEach(u=>t.add(u))}else if(i.type=="INSERT"){const a=i,c=n.get(a.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,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:r.DEFAULT_TEXT_STYLE,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,s.name=t.name,s.ownerId=t.ownerHandle,s.origin.copy(t.basePoint),s.layoutId=t.layout,s.blockInsertUnits=t.insertionUnits,s.explodability=t.explodability,s.blockScaling=t.scalability,t.bmpPreview&&(s.bmpPreview=t.bmpPreview),n.tables.blockTable.add(s)),!s.isModelSapce&&t.entities&&t.entities.length>0&&this.processEntitiesInBlock(t.entities,s)})}processBlocks(e,n){}async processEntitiesInBlock(e,n){const o=new y,t=e.length,s=[];for(let i=0;i<t;i++){const a=e[i],c=o.convert(a);c&&s.push(c)}n.appendEntity(s)}async processEntities(e,n,o,t,s){const i=new y;let a=[];e.tables.BLOCK_RECORD.entries.forEach(l=>{this.isModelSpace(l.name)&&(a=l.entities)});const c=a.length,u=new r.AcDbBatchProcessing(c,100-t.value,o);this.config.convertByEntityType&&(a=this.groupAndFlattenByType(a));const p=n.tables.blockTable.modelSpace;await u.processChunk(async(l,d)=>{const f=[];for(let h=l;h<d;h++){const g=a[h],A=i.convert(g);A&&f.push(A)}if(p.appendEntity(f),s){let h=t.value+d/c*(100-t.value);h>100&&(h=100),await s(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(s=>{const i=new r.AcDbLayout;i.layoutName=s.layoutName,i.tabOrder=s.tabOrder;const a=n.tables.blockTable.newIterator();i.objectId=s.handle;for(const c of a)if(c.layoutId===i.objectId){i.blockTableRecordId=c.objectId;break}i.blockTableRecordId||s.layoutName==="Model"&&(i.blockTableRecordId=n.tables.blockTable.modelSpace.objectId),i.limits.min.copy(s.minLimit),i.limits.max.copy(s.maxLimit),i.extents.min.copy(s.minExtent),i.extents.max.copy(s.maxExtent),s.viewportId&&i.viewportArray.push(s.viewportId),this.processCommonObjectAttrs(s,i),o.setAt(i.layoutName,i)})}processImageDefs(e,n){const o=n.objects.imageDefinition;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,n.ownerId=e.ownerHandle}groupAndFlattenByType(e){const n={},o=[];for(const t of e)n[t.type]||(n[t.type]=[],o.push(t.type)),n[t.type].push(t);return o.flatMap(t=>n[t])}isModelSpace(e){return e&&e.toUpperCase()==T}}D.AcDbLibreDwgConverter=b,Object.defineProperty(D,Symbol.toStringTag,{value:"Module"})});