@mlightcad/libredwg-converter 3.5.26 → 3.5.27

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,19 +1,19 @@
1
- import { AcDbFace as O, AcGeVector3d as D, AcDbArc as m, transformOcsPointToWcs as w, AcDbCircle as k, AcDbEllipse as R, AcDbLine as F, AcGePoint3d as T, AcDbSpline as b, AcDbPoint as V, AcDbTrace as N, AcDbPolyline as B, AcGePoint2d as P, AcDbPolygonMesh as z, AcDbPolyFaceMesh as j, AcDbPoly2dType as A, AcDb2dPolyline as W, AcDbPoly3dType as y, AcDb3dPolyline as H, AcDbHatch as X, AcGePolyline2d as G, AcGeLine2d as U, AcGeCircArc2d as Y, AcGeVector2d as _, AcGeEllipseArc2d as Z, AcGeSpline3d as E, AcGeLoop2d as M, AcDbHatchObjectType as K, AcDbTable as q, AcDbText as J, AcDbMText as Q, AcDbLeader as $, AcDbAlignedDimension as ee, AcDbRotatedDimension as ne, AcDb3PointAngularDimension as oe, AcDbOrdinateDimension as te, AcDbRadialDimension as se, AcDbDiametricDimension as re, AcDbRasterImage as ie, AcDbWipeout as ce, AcDbViewport as ae, AcDbRay as le, AcDbXline as de, AcDbAttributeFlags as I, AcDbAttributeMTextFlag as C, AcDbAttribute as pe, AcDbAttributeDefinition as fe, AcDbBlockReference as ue, AcCmTransparency as ge, AcDbDatabaseConverter as he, createWorkerApi as De, AcDbLinetypeTableRecord as Ae, AcDbTextStyleTableRecord as Ie, DEFAULT_TEXT_STYLE as L, AcDbDimStyleTableRecord as ye, AcCmColor as we, AcDbLayerTableRecord as Te, AcDbViewportTableRecord as be, AcDbBlockTableRecord as Pe, AcDbBatchProcessing as Ee, ByLayer as Me, AcDbLayout as Ce, AcDbRasterImageDef as Le } from "@mlightcad/data-model";
2
- class S {
1
+ import { AcDbFace as m, AcGeVector3d as D, AcDbArc as k, transformOcsPointToWcs as w, AcDbCircle as F, AcDbEllipse as R, AcDbLine as V, AcGePoint3d as T, AcDbSpline as b, AcDbPoint as N, AcDbTrace as B, AcDbPolyline as z, AcGePoint2d as P, AcDbPolygonMesh as j, AcDbPolyFaceMesh as W, AcDbPoly2dType as A, AcDb2dPolyline as H, AcDbPoly3dType as y, AcDb3dPolyline as X, AcDbHatch as G, AcGePolyline2d as U, AcGeLine2d as Y, AcGeCircArc2d as _, AcGeVector2d as Z, AcGeEllipseArc2d as K, AcGeSpline3d as E, AcGeLoop2d as M, AcDbHatchObjectType as q, AcDbTable as J, AcDbText as Q, AcDbMText as $, AcDbLeader as ee, AcDbAlignedDimension as ne, AcDbRotatedDimension as oe, AcDb3PointAngularDimension as te, AcDbOrdinateDimension as se, AcDbRadialDimension as re, AcDbDiametricDimension as ie, AcDbRasterImage as ce, AcDbWipeout as ae, AcDbViewport as le, AcDbRay as de, AcDbXline as pe, AcDbAttributeFlags as I, AcDbAttributeMTextFlag as C, AcDbAttribute as L, AcDbAttributeDefinition as fe, AcDbBlockReference as ue, AcCmTransparency as he, AcDbDatabaseConverter as ge, createWorkerApi as De, AcDbLinetypeTableRecord as Ae, AcDbTextStyleTableRecord as Ie, DEFAULT_TEXT_STYLE as S, AcDbDimStyleTableRecord as ye, AcCmColor as we, AcDbLayerTableRecord as Te, AcDbViewportTableRecord as be, AcDbBlockTableRecord as Pe, AcDbBatchProcessing as Ee, ByLayer as Me, AcDbLayout as Ce, AcDbRasterImageDef as Le } from "@mlightcad/data-model";
2
+ class x {
3
3
  convert(e) {
4
4
  const n = this.createEntity(e);
5
5
  return n && this.processCommonAttrs(e, n), n;
6
6
  }
7
7
  createEntity(e) {
8
- 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;
8
+ return e.type == "3DFACE" ? this.convertFace(e) : e.type == "ARC" ? this.convertArc(e) : e.type == "ATTDEF" ? this.convertAttributeDefinition(e) : e.type == "ATTRIB" ? this.convertAttribute(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;
9
9
  }
10
10
  convertFace(e) {
11
- const n = new O();
11
+ const n = new m();
12
12
  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;
13
13
  }
14
14
  convertArc(e) {
15
15
  const n = e.extrusionDirection ?? D.Z_AXIS;
16
- return new m(
16
+ return new k(
17
17
  w(e.center, n),
18
18
  e.radius,
19
19
  e.startAngle,
@@ -23,7 +23,7 @@ class S {
23
23
  }
24
24
  convertCirle(e) {
25
25
  const n = e.extrusionDirection ?? D.Z_AXIS;
26
- return new k(
26
+ return new F(
27
27
  w(e.center, n),
28
28
  e.radius,
29
29
  n
@@ -43,7 +43,7 @@ class S {
43
43
  }
44
44
  convertLine(e) {
45
45
  const n = e.startPoint, s = e.endPoint;
46
- return new F(
46
+ return new V(
47
47
  new T(n.x, n.y, n.z),
48
48
  new T(s.x, s.y, s.z)
49
49
  );
@@ -70,18 +70,18 @@ class S {
70
70
  return null;
71
71
  }
72
72
  convertPoint(e) {
73
- const n = new V();
73
+ const n = new N();
74
74
  return n.position = e.position, n;
75
75
  }
76
76
  convertSolid(e) {
77
- const n = new N();
77
+ const n = new B();
78
78
  return n.setPointAt(0, { ...e.corner1, z: 0 }), n.setPointAt(1, { ...e.corner2, z: 0 }), n.setPointAt(2, { ...e.corner3, z: 0 }), n.setPointAt(
79
79
  3,
80
80
  e.corner4 ? { ...e.corner4, z: 0 } : { ...e.corner3, z: 0 }
81
81
  ), n.thickness = e.thickness, n;
82
82
  }
83
83
  convertLWPolyline(e) {
84
- const n = new B();
84
+ const n = new z();
85
85
  n.closed = !!(e.flag & 512);
86
86
  const s = e.constantWidth ?? -1;
87
87
  return e.vertices.forEach((o, t) => {
@@ -117,13 +117,13 @@ class S {
117
117
  }), l.push(i.bulge ?? 0);
118
118
  }), s) {
119
119
  const i = e.meshMVertexCount ?? 2, d = e.meshNVertexCount ?? 2;
120
- return new z(i, d, r, n, t);
120
+ return new j(i, d, r, n, t);
121
121
  } else {
122
122
  if (o)
123
- return new j(r, c);
123
+ return new W(r, c);
124
124
  {
125
125
  let i = A.SimplePoly;
126
- return e.flag & 2 ? i = A.FitCurvePoly : e.flag & 4 && (e.smoothType == 6 ? i = A.CubicSplinePoly : e.smoothType == 5 && (i = A.QuadSplinePoly)), new W(
126
+ return e.flag & 2 ? i = A.FitCurvePoly : e.flag & 4 && (e.smoothType == 6 ? i = A.CubicSplinePoly : e.smoothType == 5 && (i = A.QuadSplinePoly)), new H(
127
127
  i,
128
128
  r,
129
129
  0,
@@ -145,11 +145,11 @@ class S {
145
145
  });
146
146
  });
147
147
  let o = y.SimplePoly;
148
- return e.flag & 4 && (e.smoothType == 6 ? o = y.CubicSplinePoly : e.smoothType == 5 && (o = y.QuadSplinePoly)), new H(o, s, n);
148
+ return e.flag & 4 && (e.smoothType == 6 ? o = y.CubicSplinePoly : e.smoothType == 5 && (o = y.QuadSplinePoly)), new X(o, s, n);
149
149
  }
150
150
  convertHatch(e) {
151
151
  var o;
152
- const n = new X();
152
+ const n = new G();
153
153
  if ((o = e.definitionLines) == null || o.forEach((t) => {
154
154
  n.definitionLines.push({
155
155
  angle: t.angle,
@@ -159,7 +159,7 @@ class S {
159
159
  });
160
160
  }), n.isSolidFill = e.solidFill == 1, n.hatchStyle = e.hatchStyle, n.patternName = e.patternName, n.patternType = e.patternType, n.patternAngle = e.patternAngle == null ? 0 : e.patternAngle, n.patternScale = e.patternScale == null ? 0 : e.patternScale, e.boundaryPaths.forEach((t) => {
161
161
  if (t.boundaryPathTypeFlag & 2) {
162
- const l = t, c = new G();
162
+ const l = t, c = new U();
163
163
  c.closed = l.isClosed, l.vertices.forEach((i, d) => {
164
164
  c.addVertexAt(d, {
165
165
  x: i.x,
@@ -173,11 +173,11 @@ class S {
173
173
  if (d != null) {
174
174
  if (d.type == 1) {
175
175
  const a = d;
176
- c.push(new U(a.start, a.end));
176
+ c.push(new Y(a.start, a.end));
177
177
  } else if (d.type == 2) {
178
178
  const a = d;
179
179
  c.push(
180
- new Y(
180
+ new _(
181
181
  a.center,
182
182
  a.radius,
183
183
  a.startAngle,
@@ -187,27 +187,27 @@ class S {
187
187
  );
188
188
  } else if (d.type == 3) {
189
189
  const a = d;
190
- new _().subVectors(a.end, a.center);
190
+ new Z().subVectors(a.end, a.center);
191
191
  const p = Math.sqrt(
192
192
  Math.pow(a.end.x, 2) + Math.pow(a.end.y, 2)
193
193
  ), f = p * a.lengthOfMinorAxis;
194
- let u = a.startAngle, h = a.endAngle;
195
- const v = Math.atan2(a.end.y, a.end.x);
196
- a.isCCW || (u = Math.PI * 2 - u, h = Math.PI * 2 - h), c.push(
197
- new Z(
194
+ let u = a.startAngle, g = a.endAngle;
195
+ const O = Math.atan2(a.end.y, a.end.x);
196
+ a.isCCW || (u = Math.PI * 2 - u, g = Math.PI * 2 - g), c.push(
197
+ new K(
198
198
  { ...a.center, z: 0 },
199
199
  p,
200
200
  f,
201
201
  u,
202
- h,
202
+ g,
203
203
  !a.isCCW,
204
- v
204
+ O
205
205
  )
206
206
  );
207
207
  } else if (d.type == 4) {
208
208
  const a = d;
209
209
  if (a.numberOfControlPoints > 0 && a.numberOfKnots > 0) {
210
- const g = a.controlPoints.map(
210
+ const h = a.controlPoints.map(
211
211
  (u) => ({
212
212
  x: u.x,
213
213
  y: u.y,
@@ -218,18 +218,18 @@ class S {
218
218
  const f = a.controlPoints.map((u) => (u.weight == null && (p = !1), u.weight || 1));
219
219
  c.push(
220
220
  new E(
221
- g,
221
+ h,
222
222
  a.knots,
223
223
  p ? f : void 0
224
224
  )
225
225
  );
226
226
  } else if (a.numberOfFitData > 0) {
227
- const g = a.fitDatum.map((p) => ({
227
+ const h = a.fitDatum.map((p) => ({
228
228
  x: p.x,
229
229
  y: p.y,
230
230
  z: 0
231
231
  }));
232
- c.push(new E(g, "Uniform"));
232
+ c.push(new E(h, "Uniform"));
233
233
  }
234
234
  }
235
235
  }
@@ -239,7 +239,7 @@ class S {
239
239
  }
240
240
  }), e.gradientFlag) {
241
241
  const t = e;
242
- if (n.hatchObjectType = K.GradientObject, n.gradientName = t.gradientName, n.gradientAngle = t.gradientRotation ?? 0, n.gradientShift = t.gradientDefinition ?? 0, n.gradientOneColorMode = t.gradientColorFlag == 1, n.shadeTintValue = t.colorTint ?? 0, t.gradientColors) {
242
+ if (n.hatchObjectType = q.GradientObject, n.gradientName = t.gradientName, n.gradientAngle = t.gradientRotation ?? 0, n.gradientShift = t.gradientDefinition ?? 0, n.gradientOneColorMode = t.gradientColorFlag == 1, n.shadeTintValue = t.colorTint ?? 0, t.gradientColors) {
243
243
  const r = t.gradientColors.length;
244
244
  r > 1 ? (n.gradientStartColor = t.gradientColors[0].rgb, n.gradientEndColor = t.gradientColors[1].rgb) : r > 0 && (n.gradientStartColor = t.gradientColors[0].rgb);
245
245
  }
@@ -247,7 +247,7 @@ class S {
247
247
  return n;
248
248
  }
249
249
  convertTable(e) {
250
- const n = new q(
250
+ const n = new J(
251
251
  e.name,
252
252
  e.rowCount,
253
253
  e.columnCount
@@ -261,22 +261,22 @@ class S {
261
261
  }), n;
262
262
  }
263
263
  convertText(e) {
264
- const n = new J();
264
+ const n = new Q();
265
265
  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;
266
266
  }
267
267
  convertMText(e) {
268
- const n = new Q();
268
+ const n = new $();
269
269
  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;
270
270
  }
271
271
  convertLeader(e) {
272
- const n = new $();
272
+ const n = new ee();
273
273
  return e.vertices.forEach((s) => {
274
274
  n.appendVertex(s);
275
275
  }), n.hasArrowHead = e.isArrowheadEnabled, n.hasHookLine = e.isHooklineExists, n.isSplined = e.isSpline, n.dimensionStyle = e.styleName, n.annoType = e.leaderCreationFlag, n;
276
276
  }
277
277
  convertDimension(e) {
278
278
  if (e.subclassMarker == "AcDbAlignedDimension") {
279
- const n = e, s = new ee(
279
+ const n = e, s = new ne(
280
280
  n.subDefinitionPoint1,
281
281
  n.subDefinitionPoint2,
282
282
  n.definitionPoint
@@ -287,7 +287,7 @@ class S {
287
287
  z: 0
288
288
  }), s.rotation = n.rotationAngle, this.processDimensionCommonAttrs(e, s), s;
289
289
  } else if (e.subclassMarker == "AcDbRotatedDimension") {
290
- const n = e, s = new ne(
290
+ const n = e, s = new oe(
291
291
  n.subDefinitionPoint1,
292
292
  n.subDefinitionPoint2,
293
293
  n.definitionPoint
@@ -298,7 +298,7 @@ class S {
298
298
  z: 0
299
299
  }), s.rotation = n.rotationAngle, this.processDimensionCommonAttrs(e, s), s;
300
300
  } else if (e.subclassMarker == "AcDb3PointAngularDimension") {
301
- const n = e, s = new oe(
301
+ const n = e, s = new te(
302
302
  n.centerPoint,
303
303
  n.subDefinitionPoint1,
304
304
  n.subDefinitionPoint2,
@@ -306,20 +306,20 @@ class S {
306
306
  );
307
307
  return this.processDimensionCommonAttrs(e, s), s;
308
308
  } else if (e.subclassMarker == "AcDbOrdinateDimension") {
309
- const n = e, s = new te(
309
+ const n = e, s = new se(
310
310
  n.subDefinitionPoint1,
311
311
  n.subDefinitionPoint2
312
312
  );
313
313
  return this.processDimensionCommonAttrs(e, s), s;
314
314
  } else if (e.subclassMarker == "AcDbRadialDimension") {
315
- const n = e, s = new se(
315
+ const n = e, s = new re(
316
316
  n.definitionPoint,
317
317
  n.centerPoint,
318
318
  n.leaderLength
319
319
  );
320
320
  return this.processDimensionCommonAttrs(e, s), s;
321
321
  } else if (e.subclassMarker == "AcDbDiametricDimension") {
322
- const n = e, s = new re(
322
+ const n = e, s = new ie(
323
323
  n.definitionPoint,
324
324
  n.centerPoint,
325
325
  n.leaderLength
@@ -338,23 +338,23 @@ class S {
338
338
  ) * e.imageSize.y, n.rotation = Math.atan2(e.uPixel.y, e.uPixel.x);
339
339
  }
340
340
  convertImage(e) {
341
- const n = new ie();
341
+ const n = new ce();
342
342
  return this.processImage(e, n), n;
343
343
  }
344
344
  convertWipeout(e) {
345
- const n = new ce();
345
+ const n = new ae();
346
346
  return this.processImage(e, n), n;
347
347
  }
348
348
  convertViewport(e) {
349
- const n = new ae();
349
+ const n = new le();
350
350
  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;
351
351
  }
352
352
  convertRay(e) {
353
- const n = new le();
353
+ const n = new de();
354
354
  return n.basePoint.copy(e.firstPoint), n.unitDir.copy(e.unitDirection), n;
355
355
  }
356
356
  convertXline(e) {
357
- const n = new de();
357
+ const n = new pe();
358
358
  return n.basePoint.copy(e.firstPoint), n.unitDir.copy(e.unitDirection), n;
359
359
  }
360
360
  convertAttributeCommon(e, n) {
@@ -362,7 +362,7 @@ class S {
362
362
  n.textString = s.text, n.styleName = s.styleName, n.height = s.textHeight, n.position.copy(s.startPoint), n.rotation = s.rotation, n.oblique = s.obliqueAngle ?? 0, n.thickness = s.thickness, n.horizontalMode = s.halign, n.verticalMode = s.valign, n.widthFactor = s.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 & C.MultiLine) !== 0, n.isConstMTextAttribute = (e.mtextFlag & C.ConstMultiLine) !== 0;
363
363
  }
364
364
  convertAttribute(e) {
365
- const n = new pe();
365
+ const n = new L();
366
366
  return this.convertAttributeCommon(e, n), n;
367
367
  }
368
368
  convertAttributeDefinition(e) {
@@ -371,9 +371,9 @@ class S {
371
371
  }
372
372
  convertBlockReference(e) {
373
373
  const n = new ue(e.name);
374
- 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((s) => {
375
- const o = this.convertAttribute(s);
376
- n.appendAttributes(o);
374
+ 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.handle != null && (n.objectId = e.handle), e.attribs && e.attribs.forEach((s) => {
375
+ const o = this.convert(s);
376
+ o instanceof L && n.appendAttributes(o);
377
377
  }), n;
378
378
  }
379
379
  processDimensionCommonAttrs(e, n) {
@@ -381,13 +381,13 @@ class S {
381
381
  }
382
382
  processCommonAttrs(e, n) {
383
383
  if (n.layer = e.layer || "0", n.objectId = e.handle, e.ownerBlockRecordSoftId != null && (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 && (e.color == null || e.colorIndex === 7) && (n.color.colorIndex = e.colorIndex), e.colorName && (n.color.colorName = e.colorName), e.isVisible != null && (n.visibility = e.isVisible), e.transparency != null) {
384
- const s = new ge();
384
+ const s = new he();
385
385
  s.method = e.transparencyType, (s.isByBlock || s.isByBlock) && (s.alpha = e.transparency), n.transparency = s;
386
386
  }
387
387
  }
388
388
  }
389
389
  const Se = "*MODEL_SPACE";
390
- class ve extends he {
390
+ class ve extends ge {
391
391
  constructor(e = {}) {
392
392
  super(e), e.useWorker = !0, e.parserWorkerUrl || (e.parserWorkerUrl = "/assets/libredwg-parser-worker.js");
393
393
  }
@@ -527,7 +527,7 @@ class ve extends he {
527
527
  dimfit: o.DIMFIT || 0,
528
528
  dimupt: o.DIMUPT,
529
529
  dimatfit: o.DIMATFIT,
530
- dimtxsty: L,
530
+ dimtxsty: S,
531
531
  dimldrblk: "",
532
532
  dimblk: o.DIMBLK || "",
533
533
  dimblk1: o.DIMBLK1 || "",
@@ -569,7 +569,7 @@ class ve extends he {
569
569
  processBlocks(e, n) {
570
570
  }
571
571
  async processEntitiesInBlock(e, n) {
572
- const s = new S(), o = e.length, t = [];
572
+ const s = new x(), o = e.length, t = [];
573
573
  for (let r = 0; r < o; r++) {
574
574
  const l = e[r], c = s.convert(l);
575
575
  c && t.push(c);
@@ -577,7 +577,7 @@ class ve extends he {
577
577
  n.appendEntity(t);
578
578
  }
579
579
  async processEntities(e, n, s, o, t) {
580
- const r = new S();
580
+ const r = new x();
581
581
  let l = [];
582
582
  e.tables.BLOCK_RECORD.entries.forEach((a) => {
583
583
  this.isModelSpace(a.name) && (l = a.entities);
@@ -589,21 +589,21 @@ class ve extends he {
589
589
  );
590
590
  this.config.convertByEntityType && (l = this.groupAndFlattenByType(l));
591
591
  const d = n.tables.blockTable.modelSpace;
592
- await i.processChunk(async (a, g) => {
592
+ await i.processChunk(async (a, h) => {
593
593
  const p = [];
594
- for (let f = a; f < g; f++) {
595
- const u = l[f], h = r.convert(u);
596
- h && p.push(h);
594
+ for (let f = a; f < h; f++) {
595
+ const u = l[f], g = r.convert(u);
596
+ g && p.push(g);
597
597
  }
598
598
  if (d.appendEntity(p), t) {
599
- let f = o.value + g / c * (100 - o.value);
599
+ let f = o.value + h / c * (100 - o.value);
600
600
  f > 100 && (f = 100), await t(f, "ENTITY", "IN-PROGRESS");
601
601
  }
602
602
  });
603
603
  }
604
604
  processHeader(e, n) {
605
605
  const s = e.header;
606
- s.CECOLOR && (s.CECOLOR.index >= 0 && s.CECOLOR.index <= 256 ? n.cecolor.colorIndex = s.CECOLOR.index : n.cecolor.setRGBValue(s.CECOLOR.rgb)), n.angBase = s.ANGBASE ?? 0, n.angDir = s.ANGDIR ?? 0, n.aunits = s.AUNITS ?? 0, n.celtype = s.CELTYPE ?? Me, n.celtscale = s.CELTSCALE ?? 1, n.ltscale = s.LTSCALE ?? 1, s.EXTMAX && (n.extmax = s.EXTMAX), s.EXTMIN && (n.extmin = s.EXTMIN), n.insunits = s.INSUNITS ?? 1, n.pdmode = s.PDMODE ?? 0, n.pdsize = s.PDSIZE ?? 0, n.textstyle = s.TEXTSTYLE ?? L;
606
+ s.CECOLOR && (s.CECOLOR.index >= 0 && s.CECOLOR.index <= 256 ? n.cecolor.colorIndex = s.CECOLOR.index : n.cecolor.setRGBValue(s.CECOLOR.rgb)), n.angBase = s.ANGBASE ?? 0, n.angDir = s.ANGDIR ?? 0, n.aunits = s.AUNITS ?? 0, n.celtype = s.CELTYPE ?? Me, n.celtscale = s.CELTSCALE ?? 1, n.ltscale = s.LTSCALE ?? 1, s.EXTMAX && (n.extmax = s.EXTMAX), s.EXTMIN && (n.extmin = s.EXTMIN), n.insunits = s.INSUNITS ?? 1, n.pdmode = s.PDMODE ?? 0, n.pdsize = s.PDSIZE ?? 0, n.textstyle = s.TEXTSTYLE ?? S;
607
607
  }
608
608
  processCommonTableEntryAttrs(e, n) {
609
609
  n.name = e.name, n.objectId = e.handle, e.ownerHandle != null && (n.ownerId = e.ownerHandle);
@@ -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){const n=e.extrusionDirection??r.AcGeVector3d.Z_AXIS;return new r.AcDbArc(r.transformOcsPointToWcs(e.center,n),e.radius,e.startAngle,e.endAngle,n)}convertCirle(e){const n=e.extrusionDirection??r.AcGeVector3d.Z_AXIS;return new r.AcDbCircle(r.transformOcsPointToWcs(e.center,n),e.radius,n)}convertEllipse(e){const n=new r.AcGeVector3d(e.majorAxisEndPoint),s=n.length();return new r.AcDbEllipse(e.center,e.extrusionDirection??r.AcGeVector3d.Z_AXIS,n,s,s*e.axisRatio,e.startAngle,e.endAngle)}convertLine(e){const n=e.startPoint,s=e.endPoint;return new r.AcDbLine(new r.AcGePoint3d(n.x,n.y,n.z),new r.AcGePoint3d(s.x,s.y,s.z))}convertSpline(e){try{if(e.numberOfControlPoints>0&&e.numberOfKnots>0)return new r.AcDbSpline(e.controlPoints,e.knots,e.weights,e.degree,!!(e.flag&1));if(e.numberOfFitPoints>0)return new r.AcDbSpline(e.fitPoints,"Uniform",e.degree,!!(e.flag&1))}catch{}return null}convertPoint(e){const n=new r.AcDbPoint;return n.position=e.position,n}convertSolid(e){const n=new r.AcDbTrace;return n.setPointAt(0,{...e.corner1,z:0}),n.setPointAt(1,{...e.corner2,z:0}),n.setPointAt(2,{...e.corner3,z:0}),n.setPointAt(3,e.corner4?{...e.corner4,z:0}:{...e.corner3,z:0}),n.thickness=e.thickness,n}convertLWPolyline(e){const n=new r.AcDbPolyline;n.closed=!!(e.flag&512);const s=e.constantWidth??-1;return e.vertices.forEach((o,t)=>{n.addVertexAt(t,new r.AcGePoint2d(o.x,o.y),o.bulge,o.startWidth??s,o.endWidth??s)}),n}convertPolyline2d(e){const n=!!(e.flag&1),s=!!(e.flag&16),o=!!(e.flag&64),t=!!(e.flag&32),i=[],p=[],l=[];if(e.vertices.map(c=>{if(!(c.flag&16))if(o&&c.flag&128)if(c.flag&64)i.push({x:c.x,y:c.y,z:c.z}),p.push(c.bulge??0);else{const f=[];c.polyfaceIndex0!=null&&c.polyfaceIndex0!=0&&f.push(Math.abs(c.polyfaceIndex0)-1),c.polyfaceIndex1!=null&&c.polyfaceIndex1!=0&&f.push(Math.abs(c.polyfaceIndex1)-1),c.polyfaceIndex2!=null&&c.polyfaceIndex2!=0&&f.push(Math.abs(c.polyfaceIndex2)-1),c.polyfaceIndex3!=null&&c.polyfaceIndex3!=0&&f.push(Math.abs(c.polyfaceIndex3)-1),f.length>=3&&l.push(f)}else i.push({x:c.x,y:c.y,z:c.z}),p.push(c.bulge??0)}),s){const c=e.meshMVertexCount??2,f=e.meshNVertexCount??2;return new r.AcDbPolygonMesh(c,f,i,n,t)}else{if(o)return new r.AcDbPolyFaceMesh(i,l);{let c=r.AcDbPoly2dType.SimplePoly;return e.flag&2?c=r.AcDbPoly2dType.FitCurvePoly:e.flag&4&&(e.smoothType==6?c=r.AcDbPoly2dType.CubicSplinePoly:e.smoothType==5&&(c=r.AcDbPoly2dType.QuadSplinePoly)),new r.AcDb2dPolyline(c,i,0,n,e.startWidth,e.endWidth,p)}}}convertPolyline3d(e){const n=!!(e.flag&1),s=[];e.vertices.map(t=>{t.flag&16||s.push({x:t.x,y:t.y,z:t.z})});let o=r.AcDbPoly3dType.SimplePoly;return e.flag&4&&(e.smoothType==6?o=r.AcDbPoly3dType.CubicSplinePoly:e.smoothType==5&&(o=r.AcDbPoly3dType.QuadSplinePoly)),new r.AcDb3dPolyline(o,s,n)}convertHatch(e){var o;const n=new r.AcDbHatch;if((o=e.definitionLines)==null||o.forEach(t=>{n.definitionLines.push({angle:t.angle,base:t.base,offset:t.offset,dashLengths:t.numberOfDashLengths>0?t.dashLengths:[]})}),n.isSolidFill=e.solidFill==1,n.hatchStyle=e.hatchStyle,n.patternName=e.patternName,n.patternType=e.patternType,n.patternAngle=e.patternAngle==null?0:e.patternAngle,n.patternScale=e.patternScale==null?0:e.patternScale,e.boundaryPaths.forEach(t=>{if(t.boundaryPathTypeFlag&2){const p=t,l=new r.AcGePolyline2d;l.closed=p.isClosed,p.vertices.forEach((c,f)=>{l.addVertexAt(f,{x:c.x,y:c.y,bulge:c.bulge})}),n.add(l)}else{const p=t,l=[];p.edges.forEach(f=>{if(f!=null){if(f.type==1){const a=f;l.push(new r.AcGeLine2d(a.start,a.end))}else if(f.type==2){const a=f;l.push(new r.AcGeCircArc2d(a.center,a.radius,a.startAngle,a.endAngle,!a.isCCW))}else if(f.type==3){const a=f;new r.AcGeVector2d().subVectors(a.end,a.center);const u=Math.sqrt(Math.pow(a.end.x,2)+Math.pow(a.end.y,2)),g=u*a.lengthOfMinorAxis;let h=a.startAngle,A=a.endAngle;const w=Math.atan2(a.end.y,a.end.x);a.isCCW||(h=Math.PI*2-h,A=Math.PI*2-A),l.push(new r.AcGeEllipseArc2d({...a.center,z:0},u,g,h,A,!a.isCCW,w))}else if(f.type==4){const a=f;if(a.numberOfControlPoints>0&&a.numberOfKnots>0){const D=a.controlPoints.map(h=>({x:h.x,y:h.y,z:0}));let u=!0;const g=a.controlPoints.map(h=>(h.weight==null&&(u=!1),h.weight||1));l.push(new r.AcGeSpline3d(D,a.knots,u?g:void 0))}else if(a.numberOfFitData>0){const D=a.fitDatum.map(u=>({x:u.x,y:u.y,z:0}));l.push(new r.AcGeSpline3d(D,"Uniform"))}}}});const c=r.AcGeLoop2d.buildFromEdges(l);c.length==0&&l.length>0?n.add(new r.AcGeLoop2d(l)):c.forEach(f=>n.add(f))}}),e.gradientFlag){const t=e;if(n.hatchObjectType=r.AcDbHatchObjectType.GradientObject,n.gradientName=t.gradientName,n.gradientAngle=t.gradientRotation??0,n.gradientShift=t.gradientDefinition??0,n.gradientOneColorMode=t.gradientColorFlag==1,n.shadeTintValue=t.colorTint??0,t.gradientColors){const i=t.gradientColors.length;i>1?(n.gradientStartColor=t.gradientColors[0].rgb,n.gradientEndColor=t.gradientColors[1].rgb):i>0&&(n.gradientStartColor=t.gradientColors[0].rgb)}}return 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((s,o)=>n.setColumnWidth(o,s)),e.rowHeightArr.forEach((s,o)=>n.setRowHeight(o,s)),e.cells.forEach((s,o)=>{n.setCell(o,s)}),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(s=>{n.appendVertex(s)}),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"){const n=e,s=new r.AcDbAlignedDimension(n.subDefinitionPoint1,n.subDefinitionPoint2,n.definitionPoint);return n.insertionPoint&&(s.dimBlockPosition={x:n.insertionPoint.x,y:n.insertionPoint.y,z:0}),s.rotation=n.rotationAngle,this.processDimensionCommonAttrs(e,s),s}else if(e.subclassMarker=="AcDbRotatedDimension"){const n=e,s=new r.AcDbRotatedDimension(n.subDefinitionPoint1,n.subDefinitionPoint2,n.definitionPoint);return n.insertionPoint&&(s.dimBlockPosition={x:n.insertionPoint.x,y:n.insertionPoint.y,z:0}),s.rotation=n.rotationAngle,this.processDimensionCommonAttrs(e,s),s}else if(e.subclassMarker=="AcDb3PointAngularDimension"){const n=e,s=new r.AcDb3PointAngularDimension(n.centerPoint,n.subDefinitionPoint1,n.subDefinitionPoint2,n.definitionPoint);return this.processDimensionCommonAttrs(e,s),s}else if(e.subclassMarker=="AcDbOrdinateDimension"){const n=e,s=new r.AcDbOrdinateDimension(n.subDefinitionPoint1,n.subDefinitionPoint2);return this.processDimensionCommonAttrs(e,s),s}else if(e.subclassMarker=="AcDbRadialDimension"){const n=e,s=new r.AcDbRadialDimension(n.definitionPoint,n.centerPoint,n.leaderLength);return this.processDimensionCommonAttrs(e,s),s}else if(e.subclassMarker=="AcDbDiametricDimension"){const n=e,s=new r.AcDbDiametricDimension(n.definitionPoint,n.centerPoint,n.leaderLength);return this.processDimensionCommonAttrs(e,s),s}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(s=>{n.clipBoundary.push(new r.AcGePoint2d(s))}),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 s=e.text;n.textString=s.text,n.styleName=s.styleName,n.height=s.textHeight,n.position.copy(s.startPoint),n.rotation=s.rotation,n.oblique=s.obliqueAngle??0,n.thickness=s.thickness,n.horizontalMode=s.halign,n.verticalMode=s.valign,n.widthFactor=s.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(s=>{const o=this.convertAttribute(s);n.appendAttributes(o)}),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,e.ownerBlockRecordSoftId!=null&&(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&&(e.color==null||e.colorIndex===7)&&(n.color.colorIndex=e.colorIndex),e.colorName&&(n.color.colorName=e.colorName),e.isVisible!=null&&(n.visibility=e.isVisible),e.transparency!=null){const s=new r.AcCmTransparency;s.method=e.transparencyType,(s.isByBlock||s.isByBlock)&&(s.alpha=e.transparency),n.transparency=s}}}const b="*MODEL_SPACE";class I extends r.AcDbDatabaseConverter{constructor(e={}){super(e),e.useWorker=!0,e.parserWorkerUrl||(e.parserWorkerUrl="/assets/libredwg-parser-worker.js")}async parse(e,n){const s=this.config,o=this.getParserWorkerTimeout(e,n);if(s.useWorker&&s.parserWorkerUrl){const t=r.createWorkerApi({workerUrl:s.parserWorkerUrl,timeout:o,maxConcurrentWorkers:1}),i=await t.execute(e);if(t.destroy(),i.success)return i.data;throw new Error(`Failed to parse drawing due to error: '${i.error}'`)}else throw new Error("dwg converter can run in web worker only!")}getFonts(e){const n=new Map;e.tables.BLOCK_RECORD.entries.forEach(i=>{n.set(i.name,i)});const s=new Map,o=i=>{if(i){const p=i.lastIndexOf(".");return p>=0?i.substring(0,p).toLowerCase():i.toLowerCase()}};e.tables.STYLE.entries.forEach(i=>{const p=[];let l=o(i.font);l&&p.push(l),l=o(i.bigFont),l&&p.push(l),s.set(i.name,p)});const t=new Set;return this.getFontsInBlock(e.entities,n,s,t),Array.from(t)}getFontsInBlock(e,n,s,o){const t=/\\f(.*?)\|/g;e.forEach(i=>{if(i.type=="MTEXT"){const p=i;[...p.text.matchAll(t)].forEach(c=>{o.add(c[1].toLowerCase())});const l=s.get(p.styleName);l==null||l.forEach(c=>o.add(c))}else if(i.type=="TEXT"){const p=i,l=s.get(p.styleName);l==null||l.forEach(c=>o.add(c))}else if(i.type=="INSERT"){const p=i,l=n.get(p.name);l&&this.getFontsInBlock(l.entities,n,s,o)}})}processLineTypes(e,n){e.tables.LTYPE.entries.forEach(o=>{const t={name:o.name,description:o.description,standardFlag:o.standardFlag,totalPatternLength:o.totalPatternLength,pattern:o.pattern},i=new r.AcDbLinetypeTableRecord(t);this.processCommonTableEntryAttrs(o,i),i.name=o.name,n.tables.linetypeTable.add(i)})}processTextStyles(e,n){e.tables.STYLE.entries.forEach(o=>{const t=new r.AcDbTextStyleTableRecord(o);this.processCommonTableEntryAttrs(o,t),n.tables.textStyleTable.add(t)})}processDimStyles(e,n){e.tables.DIMSTYLE.entries.forEach(o=>{const t={name:o.name,ownerId:o.ownerHandle,dimpost:o.DIMPOST||"",dimapost:o.DIMAPOST||"",dimscale:o.DIMSCALE,dimasz:o.DIMASZ,dimexo:o.DIMEXO,dimdli:o.DIMDLI,dimexe:o.DIMEXE,dimrnd:o.DIMRND,dimdle:o.DIMDLE,dimtp:o.DIMTP,dimtm:o.DIMTM,dimtxt:o.DIMTXT,dimcen:o.DIMCEN,dimtsz:o.DIMTSZ,dimaltf:o.DIMALTF,dimlfac:o.DIMLFAC,dimtvp:o.DIMTVP,dimtfac:o.DIMTFAC,dimgap:o.DIMGAP,dimaltrnd:o.DIMALTRND,dimtol:o.DIMTOL==null||o.DIMTOL==0?0:1,dimlim:o.DIMLIM==null||o.DIMLIM==0?0:1,dimtih:o.DIMTIH==null||o.DIMTIH==0?0:1,dimtoh:o.DIMTOH==null||o.DIMTOH==0?0:1,dimse1:o.DIMSE1==null||o.DIMSE1==0?0:1,dimse2:o.DIMSE2==null||o.DIMSE2==0?0:1,dimtad:o.DIMTAD,dimzin:o.DIMZIN,dimazin:o.DIMAZIN,dimalt:o.DIMALT,dimaltd:o.DIMALTD,dimtofl:o.DIMTOFL,dimsah:o.DIMSAH,dimtix:o.DIMTIX,dimsoxd:o.DIMSOXD,dimclrd:o.DIMCLRD,dimclre:o.DIMCLRE,dimclrt:o.DIMCLRT,dimadec:o.DIMADEC||0,dimunit:o.DIMUNIT||2,dimdec:o.DIMDEC,dimtdec:o.DIMTDEC,dimaltu:o.DIMALTU,dimalttd:o.DIMALTTD,dimaunit:o.DIMAUNIT,dimfrac:o.DIMFRAC,dimlunit:o.DIMLUNIT,dimdsep:o.DIMDSEP||".",dimtmove:o.DIMTMOVE||0,dimjust:o.DIMJUST,dimsd1:o.DIMSD1,dimsd2:o.DIMSD2,dimtolj:o.DIMTOLJ,dimtzin:o.DIMTZIN,dimaltz:o.DIMALTZ,dimalttz:o.DIMALTTZ,dimfit:o.DIMFIT||0,dimupt:o.DIMUPT,dimatfit:o.DIMATFIT,dimtxsty:r.DEFAULT_TEXT_STYLE,dimldrblk:"",dimblk:o.DIMBLK||"",dimblk1:o.DIMBLK1||"",dimblk2:o.DIMBLK2||"",dimlwd:o.DIMLWD,dimlwe:o.DIMLWE},i=new r.AcDbDimStyleTableRecord(t);this.processCommonTableEntryAttrs(o,i),n.tables.dimStyleTable.add(i)})}processLayers(e,n){e.tables.LAYER.entries.forEach(o=>{const t=new r.AcCmColor;t.colorIndex=o.colorIndex;const i=new r.AcDbLayerTableRecord({name:o.name,standardFlags:o.standardFlag,linetype:o.lineType,lineWeight:o.lineweight,isOff:o.off,color:t,isPlottable:o.plotFlag!=0});this.processCommonTableEntryAttrs(o,i),n.tables.layerTable.add(i)})}processViewports(e,n){e.tables.VPORT.entries.forEach(o=>{const t=new r.AcDbViewportTableRecord;this.processCommonTableEntryAttrs(o,t),o.circleSides&&(t.circleSides=o.circleSides),t.standardFlag=o.standardFlag,t.center.copy(o.center),t.lowerLeftCorner.copy(o.lowerLeftCorner),t.upperRightCorner.copy(o.upperRightCorner),o.snapBasePoint&&t.snapBase.copy(o.snapBasePoint),o.snapRotationAngle&&(t.snapAngle=o.snapRotationAngle),o.snapSpacing&&t.snapIncrements.copy(o.snapSpacing),o.majorGridLines&&(t.gridMajor=o.majorGridLines),o.gridSpacing&&t.gridIncrements.copy(o.gridSpacing),o.backgroundObjectId&&(t.backgroundObjectId=o.backgroundObjectId),t.gsView.center.copy(o.center),t.gsView.viewDirectionFromTarget.copy(o.viewDirectionFromTarget),t.gsView.viewTarget.copy(o.viewTarget),o.lensLength&&(t.gsView.lensLength=o.lensLength),o.frontClippingPlane&&(t.gsView.frontClippingPlane=o.frontClippingPlane),o.backClippingPlane&&(t.gsView.backClippingPlane=o.backClippingPlane),o.viewHeight&&(t.gsView.viewHeight=o.viewHeight),o.viewTwistAngle&&(t.gsView.viewTwistAngle=o.viewTwistAngle),o.frozenLayers&&(t.gsView.frozenLayers=o.frozenLayers),o.styleSheet&&(t.gsView.styleSheet=o.styleSheet),o.renderMode&&(t.gsView.renderMode=o.renderMode),o.viewMode&&(t.gsView.viewMode=o.viewMode),o.ucsIconSetting&&(t.gsView.ucsIconSetting=o.ucsIconSetting),o.ucsOrigin&&t.gsView.ucsOrigin.copy(o.ucsOrigin),o.ucsXAxis&&t.gsView.ucsXAxis.copy(o.ucsXAxis),o.ucsYAxis&&t.gsView.ucsYAxis.copy(o.ucsYAxis),o.orthographicType&&(t.gsView.orthographicType=o.orthographicType),o.shadePlotSetting&&(t.gsView.shadePlotSetting=o.shadePlotSetting),o.shadePlotObjectId&&(t.gsView.shadePlotObjectId=o.shadePlotObjectId),o.visualStyleObjectId&&(t.gsView.visualStyleObjectId=o.visualStyleObjectId),o.isDefaultLightingOn&&(t.gsView.isDefaultLightingOn=o.isDefaultLightingOn),o.defaultLightingType&&(t.gsView.defaultLightingType=o.defaultLightingType),o.brightness&&(t.gsView.brightness=o.brightness),o.contrast&&(t.gsView.contrast=o.contrast),o.ambientColor&&(t.gsView.ambientColor=o.ambientColor),n.tables.viewportTable.add(t)})}processBlockTables(e,n){e.tables.BLOCK_RECORD.entries.forEach(o=>{let t=n.tables.blockTable.getAt(o.name);t||(t=new r.AcDbBlockTableRecord,t.objectId=o.handle,t.name=o.name,t.ownerId=o.ownerHandle,t.origin.copy(o.basePoint),t.layoutId=o.layout,t.blockInsertUnits=o.insertionUnits,t.explodability=o.explodability,t.blockScaling=o.scalability,o.bmpPreview&&(t.bmpPreview=o.bmpPreview),n.tables.blockTable.add(t)),!t.isModelSapce&&o.entities&&o.entities.length>0&&this.processEntitiesInBlock(o.entities,t)})}processBlocks(e,n){}async processEntitiesInBlock(e,n){const s=new y,o=e.length,t=[];for(let i=0;i<o;i++){const p=e[i],l=s.convert(p);l&&t.push(l)}n.appendEntity(t)}async processEntities(e,n,s,o,t){const i=new y;let p=[];e.tables.BLOCK_RECORD.entries.forEach(a=>{this.isModelSpace(a.name)&&(p=a.entities)});const l=p.length,c=new r.AcDbBatchProcessing(l,100-o.value,s);this.config.convertByEntityType&&(p=this.groupAndFlattenByType(p));const f=n.tables.blockTable.modelSpace;await c.processChunk(async(a,D)=>{const u=[];for(let g=a;g<D;g++){const h=p[g],A=i.convert(h);A&&u.push(A)}if(f.appendEntity(u),t){let g=o.value+D/l*(100-o.value);g>100&&(g=100),await t(g,"ENTITY","IN-PROGRESS")}})}processHeader(e,n){const s=e.header;s.CECOLOR&&(s.CECOLOR.index>=0&&s.CECOLOR.index<=256?n.cecolor.colorIndex=s.CECOLOR.index:n.cecolor.setRGBValue(s.CECOLOR.rgb)),n.angBase=s.ANGBASE??0,n.angDir=s.ANGDIR??0,n.aunits=s.AUNITS??0,n.celtype=s.CELTYPE??r.ByLayer,n.celtscale=s.CELTSCALE??1,n.ltscale=s.LTSCALE??1,s.EXTMAX&&(n.extmax=s.EXTMAX),s.EXTMIN&&(n.extmin=s.EXTMIN),n.insunits=s.INSUNITS??1,n.pdmode=s.PDMODE??0,n.pdsize=s.PDSIZE??0,n.textstyle=s.TEXTSTYLE??r.DEFAULT_TEXT_STYLE}processCommonTableEntryAttrs(e,n){n.name=e.name,n.objectId=e.handle,e.ownerHandle!=null&&(n.ownerId=e.ownerHandle)}processObjects(e,n){this.processLayouts(e,n),this.processImageDefs(e,n)}processLayouts(e,n){const s=n.objects.layout;e.objects.LAYOUT.forEach(t=>{const i=new r.AcDbLayout;i.layoutName=t.layoutName,i.tabOrder=t.tabOrder;const p=n.tables.blockTable.newIterator();i.objectId=t.handle;for(const l of p)if(l.layoutId===i.objectId){i.blockTableRecordId=l.objectId;break}i.blockTableRecordId||t.layoutName==="Model"&&(i.blockTableRecordId=n.tables.blockTable.modelSpace.objectId),i.limits.min.copy(t.minLimit),i.limits.max.copy(t.maxLimit),i.extents.min.copy(t.minExtent),i.extents.max.copy(t.maxExtent),t.viewportId&&i.viewportArray.push(t.viewportId),this.processCommonObjectAttrs(t,i),s.setAt(i.layoutName,i)})}processImageDefs(e,n){const s=n.objects.imageDefinition;e.objects.IMAGEDEF.forEach(t=>{const i=new r.AcDbRasterImageDef;i.sourceFileName=t.fileName,this.processCommonObjectAttrs(t,i),s.setAt(i.objectId,i)})}processCommonObjectAttrs(e,n){n.objectId=e.handle,e.ownerHandle!=null&&(n.ownerId=e.ownerHandle)}groupAndFlattenByType(e){const n={},s=[];for(const o of e)n[o.type]||(n[o.type]=[],s.push(o.type)),n[o.type].push(o);return s.flatMap(o=>n[o])}isModelSpace(e){return e&&e.toUpperCase()==b}}d.AcDbLibreDwgConverter=I,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=="ATTRIB"?this.convertAttribute(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){const n=e.extrusionDirection??r.AcGeVector3d.Z_AXIS;return new r.AcDbArc(r.transformOcsPointToWcs(e.center,n),e.radius,e.startAngle,e.endAngle,n)}convertCirle(e){const n=e.extrusionDirection??r.AcGeVector3d.Z_AXIS;return new r.AcDbCircle(r.transformOcsPointToWcs(e.center,n),e.radius,n)}convertEllipse(e){const n=new r.AcGeVector3d(e.majorAxisEndPoint),s=n.length();return new r.AcDbEllipse(e.center,e.extrusionDirection??r.AcGeVector3d.Z_AXIS,n,s,s*e.axisRatio,e.startAngle,e.endAngle)}convertLine(e){const n=e.startPoint,s=e.endPoint;return new r.AcDbLine(new r.AcGePoint3d(n.x,n.y,n.z),new r.AcGePoint3d(s.x,s.y,s.z))}convertSpline(e){try{if(e.numberOfControlPoints>0&&e.numberOfKnots>0)return new r.AcDbSpline(e.controlPoints,e.knots,e.weights,e.degree,!!(e.flag&1));if(e.numberOfFitPoints>0)return new r.AcDbSpline(e.fitPoints,"Uniform",e.degree,!!(e.flag&1))}catch{}return null}convertPoint(e){const n=new r.AcDbPoint;return n.position=e.position,n}convertSolid(e){const n=new r.AcDbTrace;return n.setPointAt(0,{...e.corner1,z:0}),n.setPointAt(1,{...e.corner2,z:0}),n.setPointAt(2,{...e.corner3,z:0}),n.setPointAt(3,e.corner4?{...e.corner4,z:0}:{...e.corner3,z:0}),n.thickness=e.thickness,n}convertLWPolyline(e){const n=new r.AcDbPolyline;n.closed=!!(e.flag&512);const s=e.constantWidth??-1;return e.vertices.forEach((o,t)=>{n.addVertexAt(t,new r.AcGePoint2d(o.x,o.y),o.bulge,o.startWidth??s,o.endWidth??s)}),n}convertPolyline2d(e){const n=!!(e.flag&1),s=!!(e.flag&16),o=!!(e.flag&64),t=!!(e.flag&32),i=[],p=[],l=[];if(e.vertices.map(c=>{if(!(c.flag&16))if(o&&c.flag&128)if(c.flag&64)i.push({x:c.x,y:c.y,z:c.z}),p.push(c.bulge??0);else{const f=[];c.polyfaceIndex0!=null&&c.polyfaceIndex0!=0&&f.push(Math.abs(c.polyfaceIndex0)-1),c.polyfaceIndex1!=null&&c.polyfaceIndex1!=0&&f.push(Math.abs(c.polyfaceIndex1)-1),c.polyfaceIndex2!=null&&c.polyfaceIndex2!=0&&f.push(Math.abs(c.polyfaceIndex2)-1),c.polyfaceIndex3!=null&&c.polyfaceIndex3!=0&&f.push(Math.abs(c.polyfaceIndex3)-1),f.length>=3&&l.push(f)}else i.push({x:c.x,y:c.y,z:c.z}),p.push(c.bulge??0)}),s){const c=e.meshMVertexCount??2,f=e.meshNVertexCount??2;return new r.AcDbPolygonMesh(c,f,i,n,t)}else{if(o)return new r.AcDbPolyFaceMesh(i,l);{let c=r.AcDbPoly2dType.SimplePoly;return e.flag&2?c=r.AcDbPoly2dType.FitCurvePoly:e.flag&4&&(e.smoothType==6?c=r.AcDbPoly2dType.CubicSplinePoly:e.smoothType==5&&(c=r.AcDbPoly2dType.QuadSplinePoly)),new r.AcDb2dPolyline(c,i,0,n,e.startWidth,e.endWidth,p)}}}convertPolyline3d(e){const n=!!(e.flag&1),s=[];e.vertices.map(t=>{t.flag&16||s.push({x:t.x,y:t.y,z:t.z})});let o=r.AcDbPoly3dType.SimplePoly;return e.flag&4&&(e.smoothType==6?o=r.AcDbPoly3dType.CubicSplinePoly:e.smoothType==5&&(o=r.AcDbPoly3dType.QuadSplinePoly)),new r.AcDb3dPolyline(o,s,n)}convertHatch(e){var o;const n=new r.AcDbHatch;if((o=e.definitionLines)==null||o.forEach(t=>{n.definitionLines.push({angle:t.angle,base:t.base,offset:t.offset,dashLengths:t.numberOfDashLengths>0?t.dashLengths:[]})}),n.isSolidFill=e.solidFill==1,n.hatchStyle=e.hatchStyle,n.patternName=e.patternName,n.patternType=e.patternType,n.patternAngle=e.patternAngle==null?0:e.patternAngle,n.patternScale=e.patternScale==null?0:e.patternScale,e.boundaryPaths.forEach(t=>{if(t.boundaryPathTypeFlag&2){const p=t,l=new r.AcGePolyline2d;l.closed=p.isClosed,p.vertices.forEach((c,f)=>{l.addVertexAt(f,{x:c.x,y:c.y,bulge:c.bulge})}),n.add(l)}else{const p=t,l=[];p.edges.forEach(f=>{if(f!=null){if(f.type==1){const a=f;l.push(new r.AcGeLine2d(a.start,a.end))}else if(f.type==2){const a=f;l.push(new r.AcGeCircArc2d(a.center,a.radius,a.startAngle,a.endAngle,!a.isCCW))}else if(f.type==3){const a=f;new r.AcGeVector2d().subVectors(a.end,a.center);const u=Math.sqrt(Math.pow(a.end.x,2)+Math.pow(a.end.y,2)),g=u*a.lengthOfMinorAxis;let h=a.startAngle,A=a.endAngle;const w=Math.atan2(a.end.y,a.end.x);a.isCCW||(h=Math.PI*2-h,A=Math.PI*2-A),l.push(new r.AcGeEllipseArc2d({...a.center,z:0},u,g,h,A,!a.isCCW,w))}else if(f.type==4){const a=f;if(a.numberOfControlPoints>0&&a.numberOfKnots>0){const D=a.controlPoints.map(h=>({x:h.x,y:h.y,z:0}));let u=!0;const g=a.controlPoints.map(h=>(h.weight==null&&(u=!1),h.weight||1));l.push(new r.AcGeSpline3d(D,a.knots,u?g:void 0))}else if(a.numberOfFitData>0){const D=a.fitDatum.map(u=>({x:u.x,y:u.y,z:0}));l.push(new r.AcGeSpline3d(D,"Uniform"))}}}});const c=r.AcGeLoop2d.buildFromEdges(l);c.length==0&&l.length>0?n.add(new r.AcGeLoop2d(l)):c.forEach(f=>n.add(f))}}),e.gradientFlag){const t=e;if(n.hatchObjectType=r.AcDbHatchObjectType.GradientObject,n.gradientName=t.gradientName,n.gradientAngle=t.gradientRotation??0,n.gradientShift=t.gradientDefinition??0,n.gradientOneColorMode=t.gradientColorFlag==1,n.shadeTintValue=t.colorTint??0,t.gradientColors){const i=t.gradientColors.length;i>1?(n.gradientStartColor=t.gradientColors[0].rgb,n.gradientEndColor=t.gradientColors[1].rgb):i>0&&(n.gradientStartColor=t.gradientColors[0].rgb)}}return 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((s,o)=>n.setColumnWidth(o,s)),e.rowHeightArr.forEach((s,o)=>n.setRowHeight(o,s)),e.cells.forEach((s,o)=>{n.setCell(o,s)}),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(s=>{n.appendVertex(s)}),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"){const n=e,s=new r.AcDbAlignedDimension(n.subDefinitionPoint1,n.subDefinitionPoint2,n.definitionPoint);return n.insertionPoint&&(s.dimBlockPosition={x:n.insertionPoint.x,y:n.insertionPoint.y,z:0}),s.rotation=n.rotationAngle,this.processDimensionCommonAttrs(e,s),s}else if(e.subclassMarker=="AcDbRotatedDimension"){const n=e,s=new r.AcDbRotatedDimension(n.subDefinitionPoint1,n.subDefinitionPoint2,n.definitionPoint);return n.insertionPoint&&(s.dimBlockPosition={x:n.insertionPoint.x,y:n.insertionPoint.y,z:0}),s.rotation=n.rotationAngle,this.processDimensionCommonAttrs(e,s),s}else if(e.subclassMarker=="AcDb3PointAngularDimension"){const n=e,s=new r.AcDb3PointAngularDimension(n.centerPoint,n.subDefinitionPoint1,n.subDefinitionPoint2,n.definitionPoint);return this.processDimensionCommonAttrs(e,s),s}else if(e.subclassMarker=="AcDbOrdinateDimension"){const n=e,s=new r.AcDbOrdinateDimension(n.subDefinitionPoint1,n.subDefinitionPoint2);return this.processDimensionCommonAttrs(e,s),s}else if(e.subclassMarker=="AcDbRadialDimension"){const n=e,s=new r.AcDbRadialDimension(n.definitionPoint,n.centerPoint,n.leaderLength);return this.processDimensionCommonAttrs(e,s),s}else if(e.subclassMarker=="AcDbDiametricDimension"){const n=e,s=new r.AcDbDiametricDimension(n.definitionPoint,n.centerPoint,n.leaderLength);return this.processDimensionCommonAttrs(e,s),s}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(s=>{n.clipBoundary.push(new r.AcGePoint2d(s))}),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 s=e.text;n.textString=s.text,n.styleName=s.styleName,n.height=s.textHeight,n.position.copy(s.startPoint),n.rotation=s.rotation,n.oblique=s.obliqueAngle??0,n.thickness=s.thickness,n.horizontalMode=s.halign,n.verticalMode=s.valign,n.widthFactor=s.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.handle!=null&&(n.objectId=e.handle),e.attribs&&e.attribs.forEach(s=>{const o=this.convert(s);o instanceof r.AcDbAttribute&&n.appendAttributes(o)}),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,e.ownerBlockRecordSoftId!=null&&(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&&(e.color==null||e.colorIndex===7)&&(n.color.colorIndex=e.colorIndex),e.colorName&&(n.color.colorName=e.colorName),e.isVisible!=null&&(n.visibility=e.isVisible),e.transparency!=null){const s=new r.AcCmTransparency;s.method=e.transparencyType,(s.isByBlock||s.isByBlock)&&(s.alpha=e.transparency),n.transparency=s}}}const b="*MODEL_SPACE";class I extends r.AcDbDatabaseConverter{constructor(e={}){super(e),e.useWorker=!0,e.parserWorkerUrl||(e.parserWorkerUrl="/assets/libredwg-parser-worker.js")}async parse(e,n){const s=this.config,o=this.getParserWorkerTimeout(e,n);if(s.useWorker&&s.parserWorkerUrl){const t=r.createWorkerApi({workerUrl:s.parserWorkerUrl,timeout:o,maxConcurrentWorkers:1}),i=await t.execute(e);if(t.destroy(),i.success)return i.data;throw new Error(`Failed to parse drawing due to error: '${i.error}'`)}else throw new Error("dwg converter can run in web worker only!")}getFonts(e){const n=new Map;e.tables.BLOCK_RECORD.entries.forEach(i=>{n.set(i.name,i)});const s=new Map,o=i=>{if(i){const p=i.lastIndexOf(".");return p>=0?i.substring(0,p).toLowerCase():i.toLowerCase()}};e.tables.STYLE.entries.forEach(i=>{const p=[];let l=o(i.font);l&&p.push(l),l=o(i.bigFont),l&&p.push(l),s.set(i.name,p)});const t=new Set;return this.getFontsInBlock(e.entities,n,s,t),Array.from(t)}getFontsInBlock(e,n,s,o){const t=/\\f(.*?)\|/g;e.forEach(i=>{if(i.type=="MTEXT"){const p=i;[...p.text.matchAll(t)].forEach(c=>{o.add(c[1].toLowerCase())});const l=s.get(p.styleName);l==null||l.forEach(c=>o.add(c))}else if(i.type=="TEXT"){const p=i,l=s.get(p.styleName);l==null||l.forEach(c=>o.add(c))}else if(i.type=="INSERT"){const p=i,l=n.get(p.name);l&&this.getFontsInBlock(l.entities,n,s,o)}})}processLineTypes(e,n){e.tables.LTYPE.entries.forEach(o=>{const t={name:o.name,description:o.description,standardFlag:o.standardFlag,totalPatternLength:o.totalPatternLength,pattern:o.pattern},i=new r.AcDbLinetypeTableRecord(t);this.processCommonTableEntryAttrs(o,i),i.name=o.name,n.tables.linetypeTable.add(i)})}processTextStyles(e,n){e.tables.STYLE.entries.forEach(o=>{const t=new r.AcDbTextStyleTableRecord(o);this.processCommonTableEntryAttrs(o,t),n.tables.textStyleTable.add(t)})}processDimStyles(e,n){e.tables.DIMSTYLE.entries.forEach(o=>{const t={name:o.name,ownerId:o.ownerHandle,dimpost:o.DIMPOST||"",dimapost:o.DIMAPOST||"",dimscale:o.DIMSCALE,dimasz:o.DIMASZ,dimexo:o.DIMEXO,dimdli:o.DIMDLI,dimexe:o.DIMEXE,dimrnd:o.DIMRND,dimdle:o.DIMDLE,dimtp:o.DIMTP,dimtm:o.DIMTM,dimtxt:o.DIMTXT,dimcen:o.DIMCEN,dimtsz:o.DIMTSZ,dimaltf:o.DIMALTF,dimlfac:o.DIMLFAC,dimtvp:o.DIMTVP,dimtfac:o.DIMTFAC,dimgap:o.DIMGAP,dimaltrnd:o.DIMALTRND,dimtol:o.DIMTOL==null||o.DIMTOL==0?0:1,dimlim:o.DIMLIM==null||o.DIMLIM==0?0:1,dimtih:o.DIMTIH==null||o.DIMTIH==0?0:1,dimtoh:o.DIMTOH==null||o.DIMTOH==0?0:1,dimse1:o.DIMSE1==null||o.DIMSE1==0?0:1,dimse2:o.DIMSE2==null||o.DIMSE2==0?0:1,dimtad:o.DIMTAD,dimzin:o.DIMZIN,dimazin:o.DIMAZIN,dimalt:o.DIMALT,dimaltd:o.DIMALTD,dimtofl:o.DIMTOFL,dimsah:o.DIMSAH,dimtix:o.DIMTIX,dimsoxd:o.DIMSOXD,dimclrd:o.DIMCLRD,dimclre:o.DIMCLRE,dimclrt:o.DIMCLRT,dimadec:o.DIMADEC||0,dimunit:o.DIMUNIT||2,dimdec:o.DIMDEC,dimtdec:o.DIMTDEC,dimaltu:o.DIMALTU,dimalttd:o.DIMALTTD,dimaunit:o.DIMAUNIT,dimfrac:o.DIMFRAC,dimlunit:o.DIMLUNIT,dimdsep:o.DIMDSEP||".",dimtmove:o.DIMTMOVE||0,dimjust:o.DIMJUST,dimsd1:o.DIMSD1,dimsd2:o.DIMSD2,dimtolj:o.DIMTOLJ,dimtzin:o.DIMTZIN,dimaltz:o.DIMALTZ,dimalttz:o.DIMALTTZ,dimfit:o.DIMFIT||0,dimupt:o.DIMUPT,dimatfit:o.DIMATFIT,dimtxsty:r.DEFAULT_TEXT_STYLE,dimldrblk:"",dimblk:o.DIMBLK||"",dimblk1:o.DIMBLK1||"",dimblk2:o.DIMBLK2||"",dimlwd:o.DIMLWD,dimlwe:o.DIMLWE},i=new r.AcDbDimStyleTableRecord(t);this.processCommonTableEntryAttrs(o,i),n.tables.dimStyleTable.add(i)})}processLayers(e,n){e.tables.LAYER.entries.forEach(o=>{const t=new r.AcCmColor;t.colorIndex=o.colorIndex;const i=new r.AcDbLayerTableRecord({name:o.name,standardFlags:o.standardFlag,linetype:o.lineType,lineWeight:o.lineweight,isOff:o.off,color:t,isPlottable:o.plotFlag!=0});this.processCommonTableEntryAttrs(o,i),n.tables.layerTable.add(i)})}processViewports(e,n){e.tables.VPORT.entries.forEach(o=>{const t=new r.AcDbViewportTableRecord;this.processCommonTableEntryAttrs(o,t),o.circleSides&&(t.circleSides=o.circleSides),t.standardFlag=o.standardFlag,t.center.copy(o.center),t.lowerLeftCorner.copy(o.lowerLeftCorner),t.upperRightCorner.copy(o.upperRightCorner),o.snapBasePoint&&t.snapBase.copy(o.snapBasePoint),o.snapRotationAngle&&(t.snapAngle=o.snapRotationAngle),o.snapSpacing&&t.snapIncrements.copy(o.snapSpacing),o.majorGridLines&&(t.gridMajor=o.majorGridLines),o.gridSpacing&&t.gridIncrements.copy(o.gridSpacing),o.backgroundObjectId&&(t.backgroundObjectId=o.backgroundObjectId),t.gsView.center.copy(o.center),t.gsView.viewDirectionFromTarget.copy(o.viewDirectionFromTarget),t.gsView.viewTarget.copy(o.viewTarget),o.lensLength&&(t.gsView.lensLength=o.lensLength),o.frontClippingPlane&&(t.gsView.frontClippingPlane=o.frontClippingPlane),o.backClippingPlane&&(t.gsView.backClippingPlane=o.backClippingPlane),o.viewHeight&&(t.gsView.viewHeight=o.viewHeight),o.viewTwistAngle&&(t.gsView.viewTwistAngle=o.viewTwistAngle),o.frozenLayers&&(t.gsView.frozenLayers=o.frozenLayers),o.styleSheet&&(t.gsView.styleSheet=o.styleSheet),o.renderMode&&(t.gsView.renderMode=o.renderMode),o.viewMode&&(t.gsView.viewMode=o.viewMode),o.ucsIconSetting&&(t.gsView.ucsIconSetting=o.ucsIconSetting),o.ucsOrigin&&t.gsView.ucsOrigin.copy(o.ucsOrigin),o.ucsXAxis&&t.gsView.ucsXAxis.copy(o.ucsXAxis),o.ucsYAxis&&t.gsView.ucsYAxis.copy(o.ucsYAxis),o.orthographicType&&(t.gsView.orthographicType=o.orthographicType),o.shadePlotSetting&&(t.gsView.shadePlotSetting=o.shadePlotSetting),o.shadePlotObjectId&&(t.gsView.shadePlotObjectId=o.shadePlotObjectId),o.visualStyleObjectId&&(t.gsView.visualStyleObjectId=o.visualStyleObjectId),o.isDefaultLightingOn&&(t.gsView.isDefaultLightingOn=o.isDefaultLightingOn),o.defaultLightingType&&(t.gsView.defaultLightingType=o.defaultLightingType),o.brightness&&(t.gsView.brightness=o.brightness),o.contrast&&(t.gsView.contrast=o.contrast),o.ambientColor&&(t.gsView.ambientColor=o.ambientColor),n.tables.viewportTable.add(t)})}processBlockTables(e,n){e.tables.BLOCK_RECORD.entries.forEach(o=>{let t=n.tables.blockTable.getAt(o.name);t||(t=new r.AcDbBlockTableRecord,t.objectId=o.handle,t.name=o.name,t.ownerId=o.ownerHandle,t.origin.copy(o.basePoint),t.layoutId=o.layout,t.blockInsertUnits=o.insertionUnits,t.explodability=o.explodability,t.blockScaling=o.scalability,o.bmpPreview&&(t.bmpPreview=o.bmpPreview),n.tables.blockTable.add(t)),!t.isModelSapce&&o.entities&&o.entities.length>0&&this.processEntitiesInBlock(o.entities,t)})}processBlocks(e,n){}async processEntitiesInBlock(e,n){const s=new y,o=e.length,t=[];for(let i=0;i<o;i++){const p=e[i],l=s.convert(p);l&&t.push(l)}n.appendEntity(t)}async processEntities(e,n,s,o,t){const i=new y;let p=[];e.tables.BLOCK_RECORD.entries.forEach(a=>{this.isModelSpace(a.name)&&(p=a.entities)});const l=p.length,c=new r.AcDbBatchProcessing(l,100-o.value,s);this.config.convertByEntityType&&(p=this.groupAndFlattenByType(p));const f=n.tables.blockTable.modelSpace;await c.processChunk(async(a,D)=>{const u=[];for(let g=a;g<D;g++){const h=p[g],A=i.convert(h);A&&u.push(A)}if(f.appendEntity(u),t){let g=o.value+D/l*(100-o.value);g>100&&(g=100),await t(g,"ENTITY","IN-PROGRESS")}})}processHeader(e,n){const s=e.header;s.CECOLOR&&(s.CECOLOR.index>=0&&s.CECOLOR.index<=256?n.cecolor.colorIndex=s.CECOLOR.index:n.cecolor.setRGBValue(s.CECOLOR.rgb)),n.angBase=s.ANGBASE??0,n.angDir=s.ANGDIR??0,n.aunits=s.AUNITS??0,n.celtype=s.CELTYPE??r.ByLayer,n.celtscale=s.CELTSCALE??1,n.ltscale=s.LTSCALE??1,s.EXTMAX&&(n.extmax=s.EXTMAX),s.EXTMIN&&(n.extmin=s.EXTMIN),n.insunits=s.INSUNITS??1,n.pdmode=s.PDMODE??0,n.pdsize=s.PDSIZE??0,n.textstyle=s.TEXTSTYLE??r.DEFAULT_TEXT_STYLE}processCommonTableEntryAttrs(e,n){n.name=e.name,n.objectId=e.handle,e.ownerHandle!=null&&(n.ownerId=e.ownerHandle)}processObjects(e,n){this.processLayouts(e,n),this.processImageDefs(e,n)}processLayouts(e,n){const s=n.objects.layout;e.objects.LAYOUT.forEach(t=>{const i=new r.AcDbLayout;i.layoutName=t.layoutName,i.tabOrder=t.tabOrder;const p=n.tables.blockTable.newIterator();i.objectId=t.handle;for(const l of p)if(l.layoutId===i.objectId){i.blockTableRecordId=l.objectId;break}i.blockTableRecordId||t.layoutName==="Model"&&(i.blockTableRecordId=n.tables.blockTable.modelSpace.objectId),i.limits.min.copy(t.minLimit),i.limits.max.copy(t.maxLimit),i.extents.min.copy(t.minExtent),i.extents.max.copy(t.maxExtent),t.viewportId&&i.viewportArray.push(t.viewportId),this.processCommonObjectAttrs(t,i),s.setAt(i.layoutName,i)})}processImageDefs(e,n){const s=n.objects.imageDefinition;e.objects.IMAGEDEF.forEach(t=>{const i=new r.AcDbRasterImageDef;i.sourceFileName=t.fileName,this.processCommonObjectAttrs(t,i),s.setAt(i.objectId,i)})}processCommonObjectAttrs(e,n){n.objectId=e.handle,e.ownerHandle!=null&&(n.ownerId=e.ownerHandle)}groupAndFlattenByType(e){const n={},s=[];for(const o of e)n[o.type]||(n[o.type]=[],s.push(o.type)),n[o.type].push(o);return s.flatMap(o=>n[o])}isModelSpace(e){return e&&e.toUpperCase()==b}}d.AcDbLibreDwgConverter=I,Object.defineProperty(d,Symbol.toStringTag,{value:"Module"})});