@mlightcad/libredwg-converter 3.1.16 → 3.1.18

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,4 +1,4 @@
1
- import { AcDbFace as E, AcDbArc as M, AcGeVector3d as D, AcDbCircle as L, AcDbEllipse as C, AcDbLine as x, AcGePoint3d as I, AcDbSpline as w, AcDbPoint as v, AcDbTrace as O, AcDbPolyline as k, AcGePoint2d as y, AcDbPoly2dType as A, AcDb2dPolyline as R, AcDbPoly3dType as b, AcDb3dPolyline as m, AcDbHatch as N, AcGePolyline2d as V, AcGeLoop2d as F, AcGeLine2d as B, AcGeCircArc2d as j, AcGeVector2d as z, AcGeEllipseArc2d as W, AcGeSpline3d as T, AcDbTable as H, AcDbText as X, AcDbMText as G, AcDbLeader as U, AcDbAlignedDimension as Y, AcDb3PointAngularDimension as Z, AcDbOrdinateDimension as _, AcDbRadialDimension as K, AcDbDiametricDimension as q, AcDbRasterImage as J, AcDbWipeout as Q, AcDbViewport as $, AcDbRay as ee, AcDbXline as ne, AcDbBlockReference as te, AcDbDatabaseConverter as oe, createWorkerApi as re, AcDbLinetypeTableRecord as se, AcDbTextStyleTableRecord as ie, AcDbDimStyleTableRecord as ce, AcCmColor as ae, AcDbLayerTableRecord as le, AcDbViewportTableRecord as de, AcDbBlockTableRecord as pe, AcDbBatchProcessing as ue, AcDbLayout as fe, AcDbRasterImageDef as he } from "@mlightcad/data-model";
1
+ import { AcDbFace as E, AcDbArc as M, AcGeVector3d as D, AcDbCircle as L, AcDbEllipse as C, AcDbLine as x, AcGePoint3d as I, AcDbSpline as w, AcDbPoint as v, AcDbTrace as O, AcDbPolyline as k, AcGePoint2d as y, AcDbPoly2dType as A, AcDb2dPolyline as R, AcDbPoly3dType as b, AcDb3dPolyline as m, AcDbHatch as V, AcGePolyline2d as N, AcGeLoop2d as F, AcGeLine2d as B, AcGeCircArc2d as j, AcGeVector2d as z, AcGeEllipseArc2d as W, AcGeSpline3d as T, AcDbTable as H, AcDbText as X, AcDbMText as G, AcDbLeader as U, AcDbAlignedDimension as Y, AcDb3PointAngularDimension as Z, AcDbOrdinateDimension as _, AcDbRadialDimension as K, AcDbDiametricDimension as q, AcDbRasterImage as J, AcDbWipeout as Q, AcDbViewport as $, AcDbRay as ee, AcDbXline as ne, AcDbBlockReference as te, AcCmTransparency as oe, AcDbDatabaseConverter as se, createWorkerApi as re, AcDbLinetypeTableRecord as ie, AcDbTextStyleTableRecord as ce, AcDbDimStyleTableRecord as ae, AcCmColor as le, AcDbLayerTableRecord as de, AcDbViewportTableRecord as pe, AcDbBlockTableRecord as ue, AcDbBatchProcessing as fe, AcDbLayout as he, AcDbRasterImageDef as De } from "@mlightcad/data-model";
2
2
  class P {
3
3
  convert(e) {
4
4
  const n = this.createEntity(e);
@@ -33,22 +33,22 @@ class P {
33
33
  );
34
34
  }
35
35
  convertEllipse(e) {
36
- const n = new D(e.majorAxisEndPoint), r = n.length();
36
+ const n = new D(e.majorAxisEndPoint), s = n.length();
37
37
  return new C(
38
38
  e.center,
39
39
  e.extrusionDirection ?? D.Z_AXIS,
40
40
  n,
41
- r,
42
- r * e.axisRatio,
41
+ s,
42
+ s * e.axisRatio,
43
43
  e.startAngle,
44
44
  e.endAngle
45
45
  );
46
46
  }
47
47
  convertLine(e) {
48
- const n = e.startPoint, r = e.endPoint;
48
+ const n = e.startPoint, s = e.endPoint;
49
49
  return new x(
50
50
  new I(n.x, n.y, n.z),
51
- new I(r.x, r.y, r.z)
51
+ new I(s.x, s.y, s.z)
52
52
  );
53
53
  }
54
54
  convertSpline(e) {
@@ -86,29 +86,29 @@ class P {
86
86
  }
87
87
  convertLWPolyline(e) {
88
88
  const n = new k();
89
- return n.closed = !!(e.flag & 512), e.vertices.forEach((r, t) => {
89
+ return n.closed = !!(e.flag & 512), e.vertices.forEach((s, t) => {
90
90
  n.addVertexAt(
91
91
  t,
92
- new y(r.x, r.y),
93
- r.bulge,
94
- r.startWidth,
95
- r.endWidth
92
+ new y(s.x, s.y),
93
+ s.bulge,
94
+ s.startWidth,
95
+ s.endWidth
96
96
  );
97
97
  }), n;
98
98
  }
99
99
  convertPolyline2d(e) {
100
- const n = !!(e.flag & 1), r = [], t = [];
101
- e.vertices.map((s) => {
102
- s.flag & 16 || (r.push({
103
- x: s.x,
104
- y: s.y,
105
- z: s.z
106
- }), t.push(s.bulge ?? 0));
100
+ const n = !!(e.flag & 1), s = [], t = [];
101
+ e.vertices.map((r) => {
102
+ r.flag & 16 || (s.push({
103
+ x: r.x,
104
+ y: r.y,
105
+ z: r.z
106
+ }), t.push(r.bulge ?? 0));
107
107
  });
108
108
  let o = A.SimplePoly;
109
109
  return e.flag & 2 ? o = A.FitCurvePoly : e.flag & 4 && (e.smoothType == 6 ? o = A.CubicSplinePoly : e.smoothType == 5 && (o = A.QuadSplinePoly)), new R(
110
110
  o,
111
- r,
111
+ s,
112
112
  0,
113
113
  n,
114
114
  e.startWidth,
@@ -117,20 +117,20 @@ class P {
117
117
  );
118
118
  }
119
119
  convertPolyline3d(e) {
120
- const n = !!(e.flag & 1), r = [];
120
+ const n = !!(e.flag & 1), s = [];
121
121
  e.vertices.map((o) => {
122
- o.flag & 16 || r.push({
122
+ o.flag & 16 || s.push({
123
123
  x: o.x,
124
124
  y: o.y,
125
125
  z: o.z
126
126
  });
127
127
  });
128
128
  let t = b.SimplePoly;
129
- return e.flag & 4 && (e.smoothType == 6 ? t = b.CubicSplinePoly : e.smoothType == 5 && (t = b.QuadSplinePoly)), new m(t, r, n);
129
+ return e.flag & 4 && (e.smoothType == 6 ? t = b.CubicSplinePoly : e.smoothType == 5 && (t = b.QuadSplinePoly)), new m(t, s, n);
130
130
  }
131
131
  convertHatch(e) {
132
132
  var t;
133
- const n = new N();
133
+ const n = new V();
134
134
  return (t = e.definitionLines) == null || t.forEach((o) => {
135
135
  n.definitionLines.push({
136
136
  angle: o.angle,
@@ -138,9 +138,9 @@ class P {
138
138
  delta: o.offset,
139
139
  dashPattern: o.numberOfDashLengths > 0 ? o.dashLengths : []
140
140
  });
141
- }), n.hatchStyle = e.hatchStyle, n.patternName = e.patternName, n.patternType = e.patternType, n.patternAngle = e.patternAngle == null ? 0 : e.patternAngle, n.patternScale = e.patternScale == null ? 0 : e.patternScale, e.boundaryPaths.forEach((o) => {
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((o) => {
142
142
  if (o.boundaryPathTypeFlag & 2) {
143
- const a = o, i = new V();
143
+ const a = o, i = new N();
144
144
  i.closed = a.isClosed, a.vertices.forEach((l, c) => {
145
145
  i.addVertexAt(c, {
146
146
  x: l.x,
@@ -225,11 +225,11 @@ class P {
225
225
  e.columnCount
226
226
  );
227
227
  return n.attachmentPoint = e.attachmentPoint, n.position.copy(e.startPoint), e.columnWidthArr.forEach(
228
- (r, t) => n.setColumnWidth(t, r)
228
+ (s, t) => n.setColumnWidth(t, s)
229
229
  ), e.rowHeightArr.forEach(
230
- (r, t) => n.setRowHeight(t, r)
231
- ), e.cells.forEach((r, t) => {
232
- n.setCell(t, r);
230
+ (s, t) => n.setRowHeight(t, s)
231
+ ), e.cells.forEach((s, t) => {
232
+ n.setCell(t, s);
233
233
  }), n;
234
234
  }
235
235
  convertText(e) {
@@ -242,56 +242,56 @@ class P {
242
242
  }
243
243
  convertLeader(e) {
244
244
  const n = new U();
245
- return e.vertices.forEach((r) => {
246
- n.appendVertex(r);
245
+ return e.vertices.forEach((s) => {
246
+ n.appendVertex(s);
247
247
  }), n.hasArrowHead = e.isArrowheadEnabled, n.hasHookLine = e.isHooklineExists, n.isSplined = e.isSpline, n.dimensionStyle = e.styleName, n.annoType = e.leaderCreationFlag, n;
248
248
  }
249
249
  convertDimension(e) {
250
250
  if (e.subclassMarker == "AcDbAlignedDimension" || e.subclassMarker == "AcDbRotatedDimension") {
251
- const n = e, r = new Y(
251
+ const n = e, s = new Y(
252
252
  n.subDefinitionPoint1,
253
253
  n.subDefinitionPoint2,
254
254
  n.definitionPoint
255
255
  );
256
- return n.insertionPoint && (r.dimBlockPosition = {
256
+ return n.insertionPoint && (s.dimBlockPosition = {
257
257
  x: n.insertionPoint.x,
258
258
  y: n.insertionPoint.y,
259
259
  z: 0
260
- }), r.rotation = n.rotationAngle, this.processDimensionCommonAttrs(e, r), r;
260
+ }), s.rotation = n.rotationAngle, this.processDimensionCommonAttrs(e, s), s;
261
261
  } else if (e.subclassMarker == "AcDb3PointAngularDimension") {
262
- const n = e, r = new Z(
262
+ const n = e, s = new Z(
263
263
  n.centerPoint,
264
264
  n.subDefinitionPoint1,
265
265
  n.subDefinitionPoint2,
266
266
  n.definitionPoint
267
267
  );
268
- return this.processDimensionCommonAttrs(e, r), r;
268
+ return this.processDimensionCommonAttrs(e, s), s;
269
269
  } else if (e.subclassMarker == "AcDbOrdinateDimension") {
270
- const n = e, r = new _(
270
+ const n = e, s = new _(
271
271
  n.subDefinitionPoint1,
272
272
  n.subDefinitionPoint2
273
273
  );
274
- return this.processDimensionCommonAttrs(e, r), r;
274
+ return this.processDimensionCommonAttrs(e, s), s;
275
275
  } else if (e.subclassMarker == "AcDbRadialDimension") {
276
- const n = e, r = new K(
276
+ const n = e, s = new K(
277
277
  n.definitionPoint,
278
278
  n.centerPoint,
279
279
  n.leaderLength
280
280
  );
281
- return this.processDimensionCommonAttrs(e, r), r;
281
+ return this.processDimensionCommonAttrs(e, s), s;
282
282
  } else if (e.subclassMarker == "AcDbDiametricDimension") {
283
- const n = e, r = new q(
283
+ const n = e, s = new q(
284
284
  n.definitionPoint,
285
285
  n.centerPoint,
286
286
  n.leaderLength
287
287
  );
288
- return this.processDimensionCommonAttrs(e, r), r;
288
+ return this.processDimensionCommonAttrs(e, s), s;
289
289
  }
290
290
  return null;
291
291
  }
292
292
  processImage(e, n) {
293
- n.position.copy(e.position), n.brightness = e.brightness, n.contrast = e.contrast, n.fade = e.fade, n.imageDefId = e.imageDefHandle.toString(), n.isClipped = e.clipping > 0, n.isShownClipped = (e.flags | 4) > 0, n.isImageShown = (e.flags | 3) > 0, n.isImageTransparent = (e.flags | 8) > 0, e.clippingBoundaryPath.forEach((r) => {
294
- n.clipBoundary.push(new y(r));
293
+ n.position.copy(e.position), n.brightness = e.brightness, n.contrast = e.contrast, n.fade = e.fade, n.imageDefId = e.imageDefHandle.toString(), n.isClipped = e.clipping > 0, n.isShownClipped = (e.flags | 4) > 0, n.isImageShown = (e.flags | 3) > 0, n.isImageTransparent = (e.flags | 8) > 0, e.clippingBoundaryPath.forEach((s) => {
294
+ n.clipBoundary.push(new y(s));
295
295
  }), n.clipBoundaryType = e.clippingBoundaryType, n.width = Math.sqrt(
296
296
  e.uPixel.x ** 2 + e.uPixel.y ** 2 + e.uPixel.z ** 2
297
297
  ) * e.imageSize.x, n.height = Math.sqrt(
@@ -326,10 +326,13 @@ class P {
326
326
  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;
327
327
  }
328
328
  processCommonAttrs(e, n) {
329
- n.layer = e.layer || "0", n.objectId = e.handle.toString(), n.ownerId = e.ownerBlockRecordSoftId.toString(), e.lineType != null && (n.lineType = e.lineType), e.lineweight != null && (n.lineWeight = e.lineweight), e.lineTypeScale != null && (n.linetypeScale = e.lineTypeScale), e.color != null && (n.color.color = e.color), e.colorIndex != null && (n.color.colorIndex = e.colorIndex), e.colorName != null && (n.color.colorName = e.colorName), e.isVisible != null && (n.visibility = e.isVisible), e.transparency != null && (n.transparency = e.transparency);
329
+ if (n.layer = e.layer || "0", n.objectId = e.handle.toString(), n.ownerId = e.ownerBlockRecordSoftId.toString(), e.lineType != null && (n.lineType = e.lineType), e.lineweight != null && (n.lineWeight = e.lineweight), e.lineTypeScale != null && (n.linetypeScale = e.lineTypeScale), e.color != null && n.color.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) {
330
+ const s = new oe();
331
+ s.method = e.transparencyType, (s.isByBlock || s.isByBlock) && (s.alpha = e.transparency), n.transparency = s;
332
+ }
330
333
  }
331
334
  }
332
- class ge extends oe {
335
+ class Ae extends se {
333
336
  constructor(e = {}) {
334
337
  super(e), e.useWorker = !0, e.parserWorkerUrl || (e.parserWorkerUrl = "/assets/libredwg-parser-worker.js");
335
338
  }
@@ -339,8 +342,8 @@ class ge extends oe {
339
342
  workerUrl: this.config.parserWorkerUrl,
340
343
  // One concurrent worker needed for parser
341
344
  maxConcurrentWorkers: 1
342
- }), r = await n.execute(e);
343
- return n.destroy(), r.data;
345
+ }), s = await n.execute(e);
346
+ return n.destroy(), s.data;
344
347
  } else
345
348
  throw new Error("dwg converter can run in web worker only!");
346
349
  }
@@ -351,42 +354,42 @@ class ge extends oe {
351
354
  */
352
355
  getFonts(e) {
353
356
  const n = /* @__PURE__ */ new Map();
354
- e.tables.BLOCK_RECORD.entries.forEach((s) => {
355
- n.set(s.name, s);
357
+ e.tables.BLOCK_RECORD.entries.forEach((r) => {
358
+ n.set(r.name, r);
356
359
  });
357
- const r = /* @__PURE__ */ new Map(), t = (s) => {
358
- if (s) {
359
- const a = s.lastIndexOf(".");
360
- return a >= 0 ? s.substring(0, a).toLowerCase() : s.toLowerCase();
360
+ const s = /* @__PURE__ */ new Map(), t = (r) => {
361
+ if (r) {
362
+ const a = r.lastIndexOf(".");
363
+ return a >= 0 ? r.substring(0, a).toLowerCase() : r.toLowerCase();
361
364
  }
362
365
  };
363
- e.tables.STYLE.entries.forEach((s) => {
366
+ e.tables.STYLE.entries.forEach((r) => {
364
367
  const a = [];
365
- let i = t(s.font);
366
- i && a.push(i), i = t(s.bigFont), i && a.push(i), r.set(s.name, a);
368
+ let i = t(r.font);
369
+ i && a.push(i), i = t(r.bigFont), i && a.push(i), s.set(r.name, a);
367
370
  });
368
371
  const o = /* @__PURE__ */ new Set();
369
- return this.getFontsInBlock(e.entities, n, r, o), Array.from(o);
372
+ return this.getFontsInBlock(e.entities, n, s, o), Array.from(o);
370
373
  }
371
374
  /**
372
375
  * Iterate entities in model space to get fonts used by text, mtext and insert entities
373
376
  */
374
- getFontsInBlock(e, n, r, t) {
377
+ getFontsInBlock(e, n, s, t) {
375
378
  const o = /\\f(.*?)\|/g;
376
- e.forEach((s) => {
377
- if (s.type == "MTEXT") {
378
- const a = s;
379
+ e.forEach((r) => {
380
+ if (r.type == "MTEXT") {
381
+ const a = r;
379
382
  [...a.text.matchAll(o)].forEach((l) => {
380
383
  t.add(l[1].toLowerCase());
381
384
  });
382
- const i = r.get(a.styleName);
385
+ const i = s.get(a.styleName);
383
386
  i == null || i.forEach((l) => t.add(l));
384
- } else if (s.type == "TEXT") {
385
- const a = s, i = r.get(a.styleName);
387
+ } else if (r.type == "TEXT") {
388
+ const a = r, i = s.get(a.styleName);
386
389
  i == null || i.forEach((l) => t.add(l));
387
- } else if (s.type == "INSERT") {
388
- const a = s, i = n.get(a.name);
389
- i && this.getFontsInBlock(i.entities, n, r, t);
390
+ } else if (r.type == "INSERT") {
391
+ const a = r, i = n.get(a.name);
392
+ i && this.getFontsInBlock(i.entities, n, s, t);
390
393
  }
391
394
  });
392
395
  }
@@ -398,13 +401,13 @@ class ge extends oe {
398
401
  standardFlag: t.standardFlag,
399
402
  totalPatternLength: t.totalPatternLength,
400
403
  pattern: t.pattern
401
- }, s = new se(o);
402
- this.processCommonTableEntryAttrs(t, s), s.name = t.name, n.tables.linetypeTable.add(s);
404
+ }, r = new ie(o);
405
+ this.processCommonTableEntryAttrs(t, r), r.name = t.name, n.tables.linetypeTable.add(r);
403
406
  });
404
407
  }
405
408
  processTextStyles(e, n) {
406
409
  e.tables.STYLE.entries.forEach((t) => {
407
- const o = new ie(t);
410
+ const o = new ce(t);
408
411
  this.processCommonTableEntryAttrs(t, o), n.tables.textStyleTable.add(o);
409
412
  });
410
413
  }
@@ -484,15 +487,15 @@ class ge extends oe {
484
487
  // TODO: Set correct value
485
488
  dimlwd: t.DIMLWD,
486
489
  dimlwe: t.DIMLWE
487
- }, s = new ce(o);
488
- this.processCommonTableEntryAttrs(t, s), n.tables.dimStyleTable.add(s);
490
+ }, r = new ae(o);
491
+ this.processCommonTableEntryAttrs(t, r), n.tables.dimStyleTable.add(r);
489
492
  });
490
493
  }
491
494
  processLayers(e, n) {
492
495
  e.tables.LAYER.entries.forEach((t) => {
493
- const o = new ae();
496
+ const o = new le();
494
497
  o.colorIndex = t.colorIndex;
495
- const s = new le({
498
+ const r = new de({
496
499
  name: t.name,
497
500
  standardFlags: t.standardFlag,
498
501
  linetype: t.lineType,
@@ -501,27 +504,27 @@ class ge extends oe {
501
504
  color: o,
502
505
  isPlottable: t.plotFlag != 0
503
506
  });
504
- this.processCommonTableEntryAttrs(t, s), n.tables.layerTable.add(s);
507
+ this.processCommonTableEntryAttrs(t, r), n.tables.layerTable.add(r);
505
508
  });
506
509
  }
507
510
  processViewports(e, n) {
508
511
  e.tables.VPORT.entries.forEach((t) => {
509
- const o = new de();
512
+ const o = new pe();
510
513
  this.processCommonTableEntryAttrs(t, o), t.circleSides && (o.circleSides = t.circleSides), o.standardFlag = t.standardFlag, o.center.copy(t.center), o.lowerLeftCorner.copy(t.lowerLeftCorner), o.upperRightCorner.copy(t.upperRightCorner), t.snapBasePoint && o.snapBase.copy(t.snapBasePoint), t.snapRotationAngle && (o.snapAngle = t.snapRotationAngle), t.snapSpacing && o.snapIncrements.copy(t.snapSpacing), t.majorGridLines && (o.gridMajor = t.majorGridLines), t.gridSpacing && o.gridIncrements.copy(t.gridSpacing), t.backgroundObjectId && (o.backgroundObjectId = t.backgroundObjectId), o.gsView.center.copy(t.center), o.gsView.viewDirectionFromTarget.copy(t.viewDirectionFromTarget), o.gsView.viewTarget.copy(t.viewTarget), t.lensLength && (o.gsView.lensLength = t.lensLength), t.frontClippingPlane && (o.gsView.frontClippingPlane = t.frontClippingPlane), t.backClippingPlane && (o.gsView.backClippingPlane = t.backClippingPlane), t.viewHeight && (o.gsView.viewHeight = t.viewHeight), t.viewTwistAngle && (o.gsView.viewTwistAngle = t.viewTwistAngle), t.frozenLayers && (o.gsView.frozenLayers = t.frozenLayers), t.styleSheet && (o.gsView.styleSheet = t.styleSheet), t.renderMode && (o.gsView.renderMode = t.renderMode), t.viewMode && (o.gsView.viewMode = t.viewMode), t.ucsIconSetting && (o.gsView.ucsIconSetting = t.ucsIconSetting), t.ucsOrigin && o.gsView.ucsOrigin.copy(t.ucsOrigin), t.ucsXAxis && o.gsView.ucsXAxis.copy(t.ucsXAxis), t.ucsYAxis && o.gsView.ucsYAxis.copy(t.ucsYAxis), t.orthographicType && (o.gsView.orthographicType = t.orthographicType), t.shadePlotSetting && (o.gsView.shadePlotSetting = t.shadePlotSetting), t.shadePlotObjectId && (o.gsView.shadePlotObjectId = t.shadePlotObjectId), t.visualStyleObjectId && (o.gsView.visualStyleObjectId = t.visualStyleObjectId), t.isDefaultLightingOn && (o.gsView.isDefaultLightingOn = t.isDefaultLightingOn), t.defaultLightingType && (o.gsView.defaultLightingType = t.defaultLightingType), t.brightness && (o.gsView.brightness = t.brightness), t.contrast && (o.gsView.contrast = t.contrast), t.ambientColor && (o.gsView.ambientColor = t.ambientColor), n.tables.viewportTable.add(o);
511
514
  });
512
515
  }
513
516
  processBlockTables(e, n) {
514
517
  e.tables.BLOCK_RECORD.entries.forEach((t) => {
515
518
  let o = n.tables.blockTable.getAt(t.name);
516
- o || (o = new pe(), o.objectId = t.handle.toString(), o.name = t.name, o.ownerId = t.ownerHandle.toString(), o.origin.copy(t.basePoint), o.layoutId = t.layout.toString(), n.tables.blockTable.add(o)), !o.isModelSapce && !o.isPaperSapce && t.entities && t.entities.length > 0 && this.processEntitiesInBlock(t.entities, o);
519
+ o || (o = new ue(), o.objectId = t.handle.toString(), o.name = t.name, o.ownerId = t.ownerHandle.toString(), o.origin.copy(t.basePoint), o.layoutId = t.layout.toString(), n.tables.blockTable.add(o)), !o.isModelSapce && !o.isPaperSapce && t.entities && t.entities.length > 0 && this.processEntitiesInBlock(t.entities, o);
517
520
  });
518
521
  }
519
522
  processBlocks(e, n) {
520
523
  }
521
524
  async processEntitiesInBlock(e, n) {
522
- const r = new P(), t = e.length, o = [];
523
- for (let s = 0; s < t; s++) {
524
- const a = e[s], i = r.convert(a);
525
+ const s = new P(), t = e.length, o = [];
526
+ for (let r = 0; r < t; r++) {
527
+ const a = e[r], i = s.convert(a);
525
528
  i && o.push(i);
526
529
  }
527
530
  n.appendEntity(o);
@@ -531,20 +534,20 @@ class ge extends oe {
531
534
  * as "batch processing" or "cooperative multitasking," where the time-consuming task is broken into
532
535
  * smaller pieces and executed in small intervals to allow the UI to remain responsive.
533
536
  */
534
- async processEntities(e, n, r, t, o) {
535
- const s = new P();
537
+ async processEntities(e, n, s, t, o) {
538
+ const r = new P();
536
539
  let a = e.entities;
537
- const i = a.length, l = new ue(
540
+ const i = a.length, l = new fe(
538
541
  i,
539
542
  100 - t.value,
540
- r
543
+ s
541
544
  );
542
545
  this.config.convertByEntityType && (a = this.groupAndFlattenByType(a));
543
546
  const c = n.tables.blockTable.modelSpace;
544
547
  await l.processChunk(async (u, p) => {
545
548
  const f = [];
546
549
  for (let d = u; d < p; d++) {
547
- const h = a[d], g = s.convert(h);
550
+ const h = a[d], g = r.convert(h);
548
551
  g && f.push(g);
549
552
  }
550
553
  if (c.appendEntity(f), o) {
@@ -554,8 +557,8 @@ class ge extends oe {
554
557
  });
555
558
  }
556
559
  processHeader(e, n) {
557
- const r = e.header;
558
- n.cecolor.colorIndex = r.CECOLOR || 256, n.angBase = r.ANGBASE ?? 0, n.angDir = r.ANGDIR ?? 0, n.aunits = r.AUNITS ?? 0, r.EXTMAX && (n.extmax = r.EXTMAX), r.EXTMIN && (n.extmin = r.EXTMIN), n.insunits = r.INSUNITS ?? 1, n.pdmode = r.PDMODE ?? 0, n.pdsize = r.PDSIZE ?? 0;
560
+ const s = e.header;
561
+ 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, 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;
559
562
  }
560
563
  processCommonTableEntryAttrs(e, n) {
561
564
  n.name = e.name, n.objectId = e.handle.toString(), n.ownerId = e.ownerHandle.toString();
@@ -564,25 +567,25 @@ class ge extends oe {
564
567
  this.processLayouts(e, n), this.processImageDefs(e, n);
565
568
  }
566
569
  processLayouts(e, n) {
567
- const r = n.dictionaries.layouts;
570
+ const s = n.dictionaries.layouts;
568
571
  e.objects.LAYOUT.forEach((o) => {
569
- const s = new fe();
570
- s.layoutName = o.layoutName, s.tabOrder = o.tabOrder;
572
+ const r = new he();
573
+ r.layoutName = o.layoutName, r.tabOrder = o.tabOrder;
571
574
  const a = n.tables.blockTable.newIterator();
572
- s.objectId = o.handle.toString();
575
+ r.objectId = o.handle.toString();
573
576
  for (const i of a)
574
- if (i.layoutId === s.objectId) {
575
- s.blockTableRecordId = i.objectId;
577
+ if (i.layoutId === r.objectId) {
578
+ r.blockTableRecordId = i.objectId;
576
579
  break;
577
580
  }
578
- s.blockTableRecordId || o.layoutName === "Model" && (s.blockTableRecordId = n.tables.blockTable.modelSpace.objectId), s.limits.min.copy(o.minLimit), s.limits.max.copy(o.maxLimit), s.extents.min.copy(o.minExtent), s.extents.max.copy(o.maxExtent), this.processCommonObjectAttrs(o, s), r.setAt(s.layoutName, s);
581
+ r.blockTableRecordId || o.layoutName === "Model" && (r.blockTableRecordId = n.tables.blockTable.modelSpace.objectId), r.limits.min.copy(o.minLimit), r.limits.max.copy(o.maxLimit), r.extents.min.copy(o.minExtent), r.extents.max.copy(o.maxExtent), this.processCommonObjectAttrs(o, r), s.setAt(r.layoutName, r);
579
582
  });
580
583
  }
581
584
  processImageDefs(e, n) {
582
- const r = n.dictionaries.imageDefs;
585
+ const s = n.dictionaries.imageDefs;
583
586
  e.objects.IMAGEDEF.forEach((o) => {
584
- const s = new he();
585
- s.sourceFileName = o.fileName, this.processCommonObjectAttrs(o, s), r.setAt(s.objectId, s);
587
+ const r = new De();
588
+ r.sourceFileName = o.fileName, this.processCommonObjectAttrs(o, r), s.setAt(r.objectId, r);
586
589
  });
587
590
  }
588
591
  processCommonObjectAttrs(e, n) {
@@ -602,12 +605,12 @@ class ge extends oe {
602
605
  * @returns A new array of entities grouped by their `type` property.
603
606
  */
604
607
  groupAndFlattenByType(e) {
605
- const n = {}, r = [];
608
+ const n = {}, s = [];
606
609
  for (const t of e)
607
- n[t.type] || (n[t.type] = [], r.push(t.type)), n[t.type].push(t);
608
- return r.flatMap((t) => n[t]);
610
+ n[t.type] || (n[t.type] = [], s.push(t.type)), n[t.type].push(t);
611
+ return s.flatMap((t) => n[t]);
609
612
  }
610
613
  }
611
614
  export {
612
- ge as AcDbLibreDwgConverter
615
+ Ae as AcDbLibreDwgConverter
613
616
  };
@@ -1 +1 @@
1
- (function(f,s){typeof exports=="object"&&typeof module<"u"?s(exports,require("@mlightcad/data-model")):typeof define=="function"&&define.amd?define(["exports","@mlightcad/data-model"],s):(f=typeof globalThis<"u"?globalThis:f||self,s(f["libredwg-converter"]={},f.dataModel))})(this,function(f,s){"use strict";class b{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=="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 s.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 s.AcDbArc(e.center,e.radius,e.startAngle,e.endAngle,e.extrusionDirection??s.AcGeVector3d.Z_AXIS)}convertCirle(e){return new s.AcDbCircle(e.center,e.radius,e.extrusionDirection??s.AcGeVector3d.Z_AXIS)}convertEllipse(e){const n=new s.AcGeVector3d(e.majorAxisEndPoint),r=n.length();return new s.AcDbEllipse(e.center,e.extrusionDirection??s.AcGeVector3d.Z_AXIS,n,r,r*e.axisRatio,e.startAngle,e.endAngle)}convertLine(e){const n=e.startPoint,r=e.endPoint;return new s.AcDbLine(new s.AcGePoint3d(n.x,n.y,n.z),new s.AcGePoint3d(r.x,r.y,r.z))}convertSpline(e){try{if(e.numberOfControlPoints>0&&e.numberOfKnots>0)return new s.AcDbSpline(e.controlPoints,e.knots,e.weights,e.degree,!!(e.flag&1));if(e.numberOfFitPoints>0)return new s.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 s.AcDbPoint;return n.position=e.position,n}convertSolid(e){const n=new s.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 s.AcDbPolyline;return n.closed=!!(e.flag&512),e.vertices.forEach((r,t)=>{n.addVertexAt(t,new s.AcGePoint2d(r.x,r.y),r.bulge,r.startWidth,r.endWidth)}),n}convertPolyline2d(e){const n=!!(e.flag&1),r=[],t=[];e.vertices.map(i=>{i.flag&16||(r.push({x:i.x,y:i.y,z:i.z}),t.push(i.bulge??0))});let o=s.AcDbPoly2dType.SimplePoly;return e.flag&2?o=s.AcDbPoly2dType.FitCurvePoly:e.flag&4&&(e.smoothType==6?o=s.AcDbPoly2dType.CubicSplinePoly:e.smoothType==5&&(o=s.AcDbPoly2dType.QuadSplinePoly)),new s.AcDb2dPolyline(o,r,0,n,e.startWidth,e.endWidth,t)}convertPolyline3d(e){const n=!!(e.flag&1),r=[];e.vertices.map(o=>{o.flag&16||r.push({x:o.x,y:o.y,z:o.z})});let t=s.AcDbPoly3dType.SimplePoly;return e.flag&4&&(e.smoothType==6?t=s.AcDbPoly3dType.CubicSplinePoly:e.smoothType==5&&(t=s.AcDbPoly3dType.QuadSplinePoly)),new s.AcDb3dPolyline(t,r,n)}convertHatch(e){var t;const n=new s.AcDbHatch;return(t=e.definitionLines)==null||t.forEach(o=>{n.definitionLines.push({angle:o.angle,origin:o.base,delta:o.offset,dashPattern:o.numberOfDashLengths>0?o.dashLengths:[]})}),n.hatchStyle=e.hatchStyle,n.patternName=e.patternName,n.patternType=e.patternType,n.patternAngle=e.patternAngle==null?0:e.patternAngle,n.patternScale=e.patternScale==null?0:e.patternScale,e.boundaryPaths.forEach(o=>{if(o.boundaryPathTypeFlag&2){const a=o,c=new s.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=o,c=new s.AcGeLoop2d;a.edges.forEach(p=>{if(p!=null){if(p.type==1){const l=p;c.add(new s.AcGeLine2d(l.start,l.end))}else if(p.type==2){const l=p;c.add(new s.AcGeCircArc2d(l.center,l.radius,l.startAngle,l.endAngle,!l.isCCW))}else if(p.type==3){const l=p;new s.AcGeVector2d().subVectors(l.end,l.center);const d=Math.sqrt(Math.pow(l.end.x,2)+Math.pow(l.end.y,2)),h=d*l.lengthOfMinorAxis;let u=l.startAngle,g=l.endAngle;const A=Math.atan2(l.end.y,l.end.x);l.isCCW||(u=Math.PI*2-u,g=Math.PI*2-g),c.add(new s.AcGeEllipseArc2d({...l.center,z:0},d,h,u,g,!l.isCCW,A))}else if(p.type==4){const l=p;if(l.numberOfControlPoints>0&&l.numberOfKnots>0){const D=l.controlPoints.map(u=>({x:u.x,y:u.y,z:0}));let d=!0;const h=l.controlPoints.map(u=>(u.weight==null&&(d=!1),u.weight||1));c.add(new s.AcGeSpline3d(D,l.knots,d?h:void 0))}else if(l.numberOfFitData>0){const D=l.fitDatum.map(d=>({x:d.x,y:d.y,z:0}));c.add(new s.AcGeSpline3d(D,"Uniform"))}}}}),n.add(c)}}),n}convertTable(e){const n=new s.AcDbTable(e.name,e.rowCount,e.columnCount);return n.attachmentPoint=e.attachmentPoint,n.position.copy(e.startPoint),e.columnWidthArr.forEach((r,t)=>n.setColumnWidth(t,r)),e.rowHeightArr.forEach((r,t)=>n.setRowHeight(t,r)),e.cells.forEach((r,t)=>{n.setCell(t,r)}),n}convertText(e){const n=new s.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 s.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 s.AcGeVector3d(e.direction)),n.drawingDirection=e.drawingDirection,n}convertLeader(e){const n=new s.AcDbLeader;return e.vertices.forEach(r=>{n.appendVertex(r)}),n.hasArrowHead=e.isArrowheadEnabled,n.hasHookLine=e.isHooklineExists,n.isSplined=e.isSpline,n.dimensionStyle=e.styleName,n.annoType=e.leaderCreationFlag,n}convertDimension(e){if(e.subclassMarker=="AcDbAlignedDimension"||e.subclassMarker=="AcDbRotatedDimension"){const n=e,r=new s.AcDbAlignedDimension(n.subDefinitionPoint1,n.subDefinitionPoint2,n.definitionPoint);return n.insertionPoint&&(r.dimBlockPosition={x:n.insertionPoint.x,y:n.insertionPoint.y,z:0}),r.rotation=n.rotationAngle,this.processDimensionCommonAttrs(e,r),r}else if(e.subclassMarker=="AcDb3PointAngularDimension"){const n=e,r=new s.AcDb3PointAngularDimension(n.centerPoint,n.subDefinitionPoint1,n.subDefinitionPoint2,n.definitionPoint);return this.processDimensionCommonAttrs(e,r),r}else if(e.subclassMarker=="AcDbOrdinateDimension"){const n=e,r=new s.AcDbOrdinateDimension(n.subDefinitionPoint1,n.subDefinitionPoint2);return this.processDimensionCommonAttrs(e,r),r}else if(e.subclassMarker=="AcDbRadialDimension"){const n=e,r=new s.AcDbRadialDimension(n.definitionPoint,n.centerPoint,n.leaderLength);return this.processDimensionCommonAttrs(e,r),r}else if(e.subclassMarker=="AcDbDiametricDimension"){const n=e,r=new s.AcDbDiametricDimension(n.definitionPoint,n.centerPoint,n.leaderLength);return this.processDimensionCommonAttrs(e,r),r}return null}processImage(e,n){n.position.copy(e.position),n.brightness=e.brightness,n.contrast=e.contrast,n.fade=e.fade,n.imageDefId=e.imageDefHandle.toString(),n.isClipped=e.clipping>0,n.isShownClipped=(e.flags|4)>0,n.isImageShown=(e.flags|3)>0,n.isImageTransparent=(e.flags|8)>0,e.clippingBoundaryPath.forEach(r=>{n.clipBoundary.push(new s.AcGePoint2d(r))}),n.clipBoundaryType=e.clippingBoundaryType,n.width=Math.sqrt(e.uPixel.x**2+e.uPixel.y**2+e.uPixel.z**2)*e.imageSize.x,n.height=Math.sqrt(e.vPixel.x**2+e.vPixel.y**2+e.vPixel.z**2)*e.imageSize.y,n.rotation=Math.atan2(e.uPixel.y,e.uPixel.x)}convertImage(e){const n=new s.AcDbRasterImage;return this.processImage(e,n),n}convertWipeout(e){const n=new s.AcDbWipeout;return this.processImage(e,n),n}convertViewport(e){const n=new s.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 s.AcDbRay;return n.basePoint.copy(e.firstPoint),n.unitDir.copy(e.unitDirection),n}convertXline(e){const n=new s.AcDbXline;return n.basePoint.copy(e.firstPoint),n.unitDir.copy(e.unitDirection),n}convertBlockReference(e){const n=new s.AcDbBlockReference(e.name);return e.insertionPoint&&n.position.copy(e.insertionPoint),n.scaleFactors.x=e.xScale,n.scaleFactors.y=e.yScale,n.scaleFactors.z=e.zScale,n.rotation=e.rotation,n.normal.copy(e.extrusionDirection),n}processDimensionCommonAttrs(e,n){n.dimBlockId=e.name,n.textPosition.copy(e.textPoint),n.textRotation=e.textRotation||0,e.textLineSpacingFactor&&(n.textLineSpacingFactor=e.textLineSpacingFactor),e.textLineSpacingStyle&&(n.textLineSpacingStyle=e.textLineSpacingStyle),n.dimensionStyleName=e.styleName,n.dimensionText=e.text||"",n.measurement=e.measurement}processCommonAttrs(e,n){n.layer=e.layer||"0",n.objectId=e.handle.toString(),n.ownerId=e.ownerBlockRecordSoftId.toString(),e.lineType!=null&&(n.lineType=e.lineType),e.lineweight!=null&&(n.lineWeight=e.lineweight),e.lineTypeScale!=null&&(n.linetypeScale=e.lineTypeScale),e.color!=null&&(n.color.color=e.color),e.colorIndex!=null&&(n.color.colorIndex=e.colorIndex),e.colorName!=null&&(n.color.colorName=e.colorName),e.isVisible!=null&&(n.visibility=e.isVisible),e.transparency!=null&&(n.transparency=e.transparency)}}class I extends s.AcDbDatabaseConverter{constructor(e={}){super(e),e.useWorker=!0,e.parserWorkerUrl||(e.parserWorkerUrl="/assets/libredwg-parser-worker.js")}async parse(e){if(this.config.useWorker&&this.config.parserWorkerUrl){const n=s.createWorkerApi({workerUrl:this.config.parserWorkerUrl,maxConcurrentWorkers:1}),r=await n.execute(e);return n.destroy(),r.data}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 r=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),r.set(i.name,a)});const o=new Set;return this.getFontsInBlock(e.entities,n,r,o),Array.from(o)}getFontsInBlock(e,n,r,t){const o=/\\f(.*?)\|/g;e.forEach(i=>{if(i.type=="MTEXT"){const a=i;[...a.text.matchAll(o)].forEach(p=>{t.add(p[1].toLowerCase())});const c=r.get(a.styleName);c==null||c.forEach(p=>t.add(p))}else if(i.type=="TEXT"){const a=i,c=r.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,r,t)}})}processLineTypes(e,n){e.tables.LTYPE.entries.forEach(t=>{const o={name:t.name,description:t.description,standardFlag:t.standardFlag,totalPatternLength:t.totalPatternLength,pattern:t.pattern},i=new s.AcDbLinetypeTableRecord(o);this.processCommonTableEntryAttrs(t,i),i.name=t.name,n.tables.linetypeTable.add(i)})}processTextStyles(e,n){e.tables.STYLE.entries.forEach(t=>{const o=new s.AcDbTextStyleTableRecord(t);this.processCommonTableEntryAttrs(t,o),n.tables.textStyleTable.add(o)})}processDimStyles(e,n){e.tables.DIMSTYLE.entries.forEach(t=>{const o={name:t.name,ownerId:t.ownerHandle.toString(),dimpost:t.DIMPOST||"",dimapost:t.DIMAPOST||"",dimscale:t.DIMSCALE,dimasz:t.DIMASZ,dimexo:t.DIMEXO,dimdli:t.DIMDLI,dimexe:t.DIMEXE,dimrnd:t.DIMRND,dimdle:t.DIMDLE,dimtp:t.DIMTP,dimtm:t.DIMTM,dimtxt:t.DIMTXT,dimcen:t.DIMCEN,dimtsz:t.DIMTSZ,dimaltf:t.DIMALTF,dimlfac:t.DIMLFAC,dimtvp:t.DIMTVP,dimtfac:t.DIMTFAC,dimgap:t.DIMGAP,dimaltrnd:t.DIMALTRND,dimtol:t.DIMTOL==null||t.DIMTOL==0?0:1,dimlim:t.DIMLIM==null||t.DIMLIM==0?0:1,dimtih:t.DIMTIH==null||t.DIMTIH==0?0:1,dimtoh:t.DIMTOH==null||t.DIMTOH==0?0:1,dimse1:t.DIMSE1==null||t.DIMSE1==0?0:1,dimse2:t.DIMSE2==null||t.DIMSE2==0?0:1,dimtad:t.DIMTAD,dimzin:t.DIMZIN,dimazin:t.DIMAZIN,dimalt:t.DIMALT,dimaltd:t.DIMALTD,dimtofl:t.DIMTOFL,dimsah:t.DIMSAH,dimtix:t.DIMTIX,dimsoxd:t.DIMSOXD,dimclrd:t.DIMCLRD,dimclre:t.DIMCLRE,dimclrt:t.DIMCLRT,dimadec:t.DIMADEC||0,dimunit:t.DIMUNIT||2,dimdec:t.DIMDEC,dimtdec:t.DIMTDEC,dimaltu:t.DIMALTU,dimalttd:t.DIMALTTD,dimaunit:t.DIMAUNIT,dimfrac:t.DIMFRAC,dimlunit:t.DIMLUNIT,dimdsep:t.DIMDSEP,dimtmove:t.DIMTMOVE||0,dimjust:t.DIMJUST,dimsd1:t.DIMSD1,dimsd2:t.DIMSD2,dimtolj:t.DIMTOLJ,dimtzin:t.DIMTZIN,dimaltz:t.DIMALTZ,dimalttz:t.DIMALTTZ,dimfit:t.DIMFIT||0,dimupt:t.DIMUPT,dimatfit:t.DIMATFIT,dimtxsty:"Standard",dimldrblk:"",dimblk:t.DIMBLK||"",dimblk1:t.DIMBLK1||"",dimblk2:t.DIMBLK2||"",dimlwd:t.DIMLWD,dimlwe:t.DIMLWE},i=new s.AcDbDimStyleTableRecord(o);this.processCommonTableEntryAttrs(t,i),n.tables.dimStyleTable.add(i)})}processLayers(e,n){e.tables.LAYER.entries.forEach(t=>{const o=new s.AcCmColor;o.colorIndex=t.colorIndex;const i=new s.AcDbLayerTableRecord({name:t.name,standardFlags:t.standardFlag,linetype:t.lineType,lineWeight:t.lineweight,isOff:t.off,color:o,isPlottable:t.plotFlag!=0});this.processCommonTableEntryAttrs(t,i),n.tables.layerTable.add(i)})}processViewports(e,n){e.tables.VPORT.entries.forEach(t=>{const o=new s.AcDbViewportTableRecord;this.processCommonTableEntryAttrs(t,o),t.circleSides&&(o.circleSides=t.circleSides),o.standardFlag=t.standardFlag,o.center.copy(t.center),o.lowerLeftCorner.copy(t.lowerLeftCorner),o.upperRightCorner.copy(t.upperRightCorner),t.snapBasePoint&&o.snapBase.copy(t.snapBasePoint),t.snapRotationAngle&&(o.snapAngle=t.snapRotationAngle),t.snapSpacing&&o.snapIncrements.copy(t.snapSpacing),t.majorGridLines&&(o.gridMajor=t.majorGridLines),t.gridSpacing&&o.gridIncrements.copy(t.gridSpacing),t.backgroundObjectId&&(o.backgroundObjectId=t.backgroundObjectId),o.gsView.center.copy(t.center),o.gsView.viewDirectionFromTarget.copy(t.viewDirectionFromTarget),o.gsView.viewTarget.copy(t.viewTarget),t.lensLength&&(o.gsView.lensLength=t.lensLength),t.frontClippingPlane&&(o.gsView.frontClippingPlane=t.frontClippingPlane),t.backClippingPlane&&(o.gsView.backClippingPlane=t.backClippingPlane),t.viewHeight&&(o.gsView.viewHeight=t.viewHeight),t.viewTwistAngle&&(o.gsView.viewTwistAngle=t.viewTwistAngle),t.frozenLayers&&(o.gsView.frozenLayers=t.frozenLayers),t.styleSheet&&(o.gsView.styleSheet=t.styleSheet),t.renderMode&&(o.gsView.renderMode=t.renderMode),t.viewMode&&(o.gsView.viewMode=t.viewMode),t.ucsIconSetting&&(o.gsView.ucsIconSetting=t.ucsIconSetting),t.ucsOrigin&&o.gsView.ucsOrigin.copy(t.ucsOrigin),t.ucsXAxis&&o.gsView.ucsXAxis.copy(t.ucsXAxis),t.ucsYAxis&&o.gsView.ucsYAxis.copy(t.ucsYAxis),t.orthographicType&&(o.gsView.orthographicType=t.orthographicType),t.shadePlotSetting&&(o.gsView.shadePlotSetting=t.shadePlotSetting),t.shadePlotObjectId&&(o.gsView.shadePlotObjectId=t.shadePlotObjectId),t.visualStyleObjectId&&(o.gsView.visualStyleObjectId=t.visualStyleObjectId),t.isDefaultLightingOn&&(o.gsView.isDefaultLightingOn=t.isDefaultLightingOn),t.defaultLightingType&&(o.gsView.defaultLightingType=t.defaultLightingType),t.brightness&&(o.gsView.brightness=t.brightness),t.contrast&&(o.gsView.contrast=t.contrast),t.ambientColor&&(o.gsView.ambientColor=t.ambientColor),n.tables.viewportTable.add(o)})}processBlockTables(e,n){e.tables.BLOCK_RECORD.entries.forEach(t=>{let o=n.tables.blockTable.getAt(t.name);o||(o=new s.AcDbBlockTableRecord,o.objectId=t.handle.toString(),o.name=t.name,o.ownerId=t.ownerHandle.toString(),o.origin.copy(t.basePoint),o.layoutId=t.layout.toString(),n.tables.blockTable.add(o)),!o.isModelSapce&&!o.isPaperSapce&&t.entities&&t.entities.length>0&&this.processEntitiesInBlock(t.entities,o)})}processBlocks(e,n){}async processEntitiesInBlock(e,n){const r=new b,t=e.length,o=[];for(let i=0;i<t;i++){const a=e[i],c=r.convert(a);c&&o.push(c)}n.appendEntity(o)}async processEntities(e,n,r,t,o){const i=new b;let a=e.entities;const c=a.length,p=new s.AcDbBatchProcessing(c,100-t.value,r);this.config.convertByEntityType&&(a=this.groupAndFlattenByType(a));const l=n.tables.blockTable.modelSpace;await p.processChunk(async(D,d)=>{const h=[];for(let u=D;u<d;u++){const g=a[u],A=i.convert(g);A&&h.push(A)}if(l.appendEntity(h),o){let u=t.value+d/c*(100-t.value);u>100&&(u=100),await o(u,"ENTITY","IN-PROGRESS")}})}processHeader(e,n){const r=e.header;n.cecolor.colorIndex=r.CECOLOR||256,n.angBase=r.ANGBASE??0,n.angDir=r.ANGDIR??0,n.aunits=r.AUNITS??0,r.EXTMAX&&(n.extmax=r.EXTMAX),r.EXTMIN&&(n.extmin=r.EXTMIN),n.insunits=r.INSUNITS??1,n.pdmode=r.PDMODE??0,n.pdsize=r.PDSIZE??0}processCommonTableEntryAttrs(e,n){n.name=e.name,n.objectId=e.handle.toString(),n.ownerId=e.ownerHandle.toString()}processObjects(e,n){this.processLayouts(e,n),this.processImageDefs(e,n)}processLayouts(e,n){const r=n.dictionaries.layouts;e.objects.LAYOUT.forEach(o=>{const i=new s.AcDbLayout;i.layoutName=o.layoutName,i.tabOrder=o.tabOrder;const a=n.tables.blockTable.newIterator();i.objectId=o.handle.toString();for(const c of a)if(c.layoutId===i.objectId){i.blockTableRecordId=c.objectId;break}i.blockTableRecordId||o.layoutName==="Model"&&(i.blockTableRecordId=n.tables.blockTable.modelSpace.objectId),i.limits.min.copy(o.minLimit),i.limits.max.copy(o.maxLimit),i.extents.min.copy(o.minExtent),i.extents.max.copy(o.maxExtent),this.processCommonObjectAttrs(o,i),r.setAt(i.layoutName,i)})}processImageDefs(e,n){const r=n.dictionaries.imageDefs;e.objects.IMAGEDEF.forEach(o=>{const i=new s.AcDbRasterImageDef;i.sourceFileName=o.fileName,this.processCommonObjectAttrs(o,i),r.setAt(i.objectId,i)})}processCommonObjectAttrs(e,n){n.objectId=e.handle.toString(),n.ownerId=e.ownerHandle.toString()}groupAndFlattenByType(e){const n={},r=[];for(const t of e)n[t.type]||(n[t.type]=[],r.push(t.type)),n[t.type].push(t);return r.flatMap(t=>n[t])}}f.AcDbLibreDwgConverter=I,Object.defineProperty(f,Symbol.toStringTag,{value:"Module"})});
1
+ (function(f,s){typeof exports=="object"&&typeof module<"u"?s(exports,require("@mlightcad/data-model")):typeof define=="function"&&define.amd?define(["exports","@mlightcad/data-model"],s):(f=typeof globalThis<"u"?globalThis:f||self,s(f["libredwg-converter"]={},f.dataModel))})(this,function(f,s){"use strict";class b{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=="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 s.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 s.AcDbArc(e.center,e.radius,e.startAngle,e.endAngle,e.extrusionDirection??s.AcGeVector3d.Z_AXIS)}convertCirle(e){return new s.AcDbCircle(e.center,e.radius,e.extrusionDirection??s.AcGeVector3d.Z_AXIS)}convertEllipse(e){const n=new s.AcGeVector3d(e.majorAxisEndPoint),r=n.length();return new s.AcDbEllipse(e.center,e.extrusionDirection??s.AcGeVector3d.Z_AXIS,n,r,r*e.axisRatio,e.startAngle,e.endAngle)}convertLine(e){const n=e.startPoint,r=e.endPoint;return new s.AcDbLine(new s.AcGePoint3d(n.x,n.y,n.z),new s.AcGePoint3d(r.x,r.y,r.z))}convertSpline(e){try{if(e.numberOfControlPoints>0&&e.numberOfKnots>0)return new s.AcDbSpline(e.controlPoints,e.knots,e.weights,e.degree,!!(e.flag&1));if(e.numberOfFitPoints>0)return new s.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 s.AcDbPoint;return n.position=e.position,n}convertSolid(e){const n=new s.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 s.AcDbPolyline;return n.closed=!!(e.flag&512),e.vertices.forEach((r,t)=>{n.addVertexAt(t,new s.AcGePoint2d(r.x,r.y),r.bulge,r.startWidth,r.endWidth)}),n}convertPolyline2d(e){const n=!!(e.flag&1),r=[],t=[];e.vertices.map(i=>{i.flag&16||(r.push({x:i.x,y:i.y,z:i.z}),t.push(i.bulge??0))});let o=s.AcDbPoly2dType.SimplePoly;return e.flag&2?o=s.AcDbPoly2dType.FitCurvePoly:e.flag&4&&(e.smoothType==6?o=s.AcDbPoly2dType.CubicSplinePoly:e.smoothType==5&&(o=s.AcDbPoly2dType.QuadSplinePoly)),new s.AcDb2dPolyline(o,r,0,n,e.startWidth,e.endWidth,t)}convertPolyline3d(e){const n=!!(e.flag&1),r=[];e.vertices.map(o=>{o.flag&16||r.push({x:o.x,y:o.y,z:o.z})});let t=s.AcDbPoly3dType.SimplePoly;return e.flag&4&&(e.smoothType==6?t=s.AcDbPoly3dType.CubicSplinePoly:e.smoothType==5&&(t=s.AcDbPoly3dType.QuadSplinePoly)),new s.AcDb3dPolyline(t,r,n)}convertHatch(e){var t;const n=new s.AcDbHatch;return(t=e.definitionLines)==null||t.forEach(o=>{n.definitionLines.push({angle:o.angle,origin:o.base,delta:o.offset,dashPattern:o.numberOfDashLengths>0?o.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(o=>{if(o.boundaryPathTypeFlag&2){const a=o,c=new s.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=o,c=new s.AcGeLoop2d;a.edges.forEach(p=>{if(p!=null){if(p.type==1){const l=p;c.add(new s.AcGeLine2d(l.start,l.end))}else if(p.type==2){const l=p;c.add(new s.AcGeCircArc2d(l.center,l.radius,l.startAngle,l.endAngle,!l.isCCW))}else if(p.type==3){const l=p;new s.AcGeVector2d().subVectors(l.end,l.center);const d=Math.sqrt(Math.pow(l.end.x,2)+Math.pow(l.end.y,2)),h=d*l.lengthOfMinorAxis;let u=l.startAngle,g=l.endAngle;const A=Math.atan2(l.end.y,l.end.x);l.isCCW||(u=Math.PI*2-u,g=Math.PI*2-g),c.add(new s.AcGeEllipseArc2d({...l.center,z:0},d,h,u,g,!l.isCCW,A))}else if(p.type==4){const l=p;if(l.numberOfControlPoints>0&&l.numberOfKnots>0){const D=l.controlPoints.map(u=>({x:u.x,y:u.y,z:0}));let d=!0;const h=l.controlPoints.map(u=>(u.weight==null&&(d=!1),u.weight||1));c.add(new s.AcGeSpline3d(D,l.knots,d?h:void 0))}else if(l.numberOfFitData>0){const D=l.fitDatum.map(d=>({x:d.x,y:d.y,z:0}));c.add(new s.AcGeSpline3d(D,"Uniform"))}}}}),n.add(c)}}),n}convertTable(e){const n=new s.AcDbTable(e.name,e.rowCount,e.columnCount);return n.attachmentPoint=e.attachmentPoint,n.position.copy(e.startPoint),e.columnWidthArr.forEach((r,t)=>n.setColumnWidth(t,r)),e.rowHeightArr.forEach((r,t)=>n.setRowHeight(t,r)),e.cells.forEach((r,t)=>{n.setCell(t,r)}),n}convertText(e){const n=new s.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 s.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 s.AcGeVector3d(e.direction)),n.drawingDirection=e.drawingDirection,n}convertLeader(e){const n=new s.AcDbLeader;return e.vertices.forEach(r=>{n.appendVertex(r)}),n.hasArrowHead=e.isArrowheadEnabled,n.hasHookLine=e.isHooklineExists,n.isSplined=e.isSpline,n.dimensionStyle=e.styleName,n.annoType=e.leaderCreationFlag,n}convertDimension(e){if(e.subclassMarker=="AcDbAlignedDimension"||e.subclassMarker=="AcDbRotatedDimension"){const n=e,r=new s.AcDbAlignedDimension(n.subDefinitionPoint1,n.subDefinitionPoint2,n.definitionPoint);return n.insertionPoint&&(r.dimBlockPosition={x:n.insertionPoint.x,y:n.insertionPoint.y,z:0}),r.rotation=n.rotationAngle,this.processDimensionCommonAttrs(e,r),r}else if(e.subclassMarker=="AcDb3PointAngularDimension"){const n=e,r=new s.AcDb3PointAngularDimension(n.centerPoint,n.subDefinitionPoint1,n.subDefinitionPoint2,n.definitionPoint);return this.processDimensionCommonAttrs(e,r),r}else if(e.subclassMarker=="AcDbOrdinateDimension"){const n=e,r=new s.AcDbOrdinateDimension(n.subDefinitionPoint1,n.subDefinitionPoint2);return this.processDimensionCommonAttrs(e,r),r}else if(e.subclassMarker=="AcDbRadialDimension"){const n=e,r=new s.AcDbRadialDimension(n.definitionPoint,n.centerPoint,n.leaderLength);return this.processDimensionCommonAttrs(e,r),r}else if(e.subclassMarker=="AcDbDiametricDimension"){const n=e,r=new s.AcDbDiametricDimension(n.definitionPoint,n.centerPoint,n.leaderLength);return this.processDimensionCommonAttrs(e,r),r}return null}processImage(e,n){n.position.copy(e.position),n.brightness=e.brightness,n.contrast=e.contrast,n.fade=e.fade,n.imageDefId=e.imageDefHandle.toString(),n.isClipped=e.clipping>0,n.isShownClipped=(e.flags|4)>0,n.isImageShown=(e.flags|3)>0,n.isImageTransparent=(e.flags|8)>0,e.clippingBoundaryPath.forEach(r=>{n.clipBoundary.push(new s.AcGePoint2d(r))}),n.clipBoundaryType=e.clippingBoundaryType,n.width=Math.sqrt(e.uPixel.x**2+e.uPixel.y**2+e.uPixel.z**2)*e.imageSize.x,n.height=Math.sqrt(e.vPixel.x**2+e.vPixel.y**2+e.vPixel.z**2)*e.imageSize.y,n.rotation=Math.atan2(e.uPixel.y,e.uPixel.x)}convertImage(e){const n=new s.AcDbRasterImage;return this.processImage(e,n),n}convertWipeout(e){const n=new s.AcDbWipeout;return this.processImage(e,n),n}convertViewport(e){const n=new s.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 s.AcDbRay;return n.basePoint.copy(e.firstPoint),n.unitDir.copy(e.unitDirection),n}convertXline(e){const n=new s.AcDbXline;return n.basePoint.copy(e.firstPoint),n.unitDir.copy(e.unitDirection),n}convertBlockReference(e){const n=new s.AcDbBlockReference(e.name);return e.insertionPoint&&n.position.copy(e.insertionPoint),n.scaleFactors.x=e.xScale,n.scaleFactors.y=e.yScale,n.scaleFactors.z=e.zScale,n.rotation=e.rotation,n.normal.copy(e.extrusionDirection),n}processDimensionCommonAttrs(e,n){n.dimBlockId=e.name,n.textPosition.copy(e.textPoint),n.textRotation=e.textRotation||0,e.textLineSpacingFactor&&(n.textLineSpacingFactor=e.textLineSpacingFactor),e.textLineSpacingStyle&&(n.textLineSpacingStyle=e.textLineSpacingStyle),n.dimensionStyleName=e.styleName,n.dimensionText=e.text||"",n.measurement=e.measurement}processCommonAttrs(e,n){if(n.layer=e.layer||"0",n.objectId=e.handle.toString(),n.ownerId=e.ownerBlockRecordSoftId.toString(),e.lineType!=null&&(n.lineType=e.lineType),e.lineweight!=null&&(n.lineWeight=e.lineweight),e.lineTypeScale!=null&&(n.linetypeScale=e.lineTypeScale),e.color!=null&&n.color.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 r=new s.AcCmTransparency;r.method=e.transparencyType,(r.isByBlock||r.isByBlock)&&(r.alpha=e.transparency),n.transparency=r}}}class y extends s.AcDbDatabaseConverter{constructor(e={}){super(e),e.useWorker=!0,e.parserWorkerUrl||(e.parserWorkerUrl="/assets/libredwg-parser-worker.js")}async parse(e){if(this.config.useWorker&&this.config.parserWorkerUrl){const n=s.createWorkerApi({workerUrl:this.config.parserWorkerUrl,maxConcurrentWorkers:1}),r=await n.execute(e);return n.destroy(),r.data}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 r=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),r.set(i.name,a)});const o=new Set;return this.getFontsInBlock(e.entities,n,r,o),Array.from(o)}getFontsInBlock(e,n,r,t){const o=/\\f(.*?)\|/g;e.forEach(i=>{if(i.type=="MTEXT"){const a=i;[...a.text.matchAll(o)].forEach(p=>{t.add(p[1].toLowerCase())});const c=r.get(a.styleName);c==null||c.forEach(p=>t.add(p))}else if(i.type=="TEXT"){const a=i,c=r.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,r,t)}})}processLineTypes(e,n){e.tables.LTYPE.entries.forEach(t=>{const o={name:t.name,description:t.description,standardFlag:t.standardFlag,totalPatternLength:t.totalPatternLength,pattern:t.pattern},i=new s.AcDbLinetypeTableRecord(o);this.processCommonTableEntryAttrs(t,i),i.name=t.name,n.tables.linetypeTable.add(i)})}processTextStyles(e,n){e.tables.STYLE.entries.forEach(t=>{const o=new s.AcDbTextStyleTableRecord(t);this.processCommonTableEntryAttrs(t,o),n.tables.textStyleTable.add(o)})}processDimStyles(e,n){e.tables.DIMSTYLE.entries.forEach(t=>{const o={name:t.name,ownerId:t.ownerHandle.toString(),dimpost:t.DIMPOST||"",dimapost:t.DIMAPOST||"",dimscale:t.DIMSCALE,dimasz:t.DIMASZ,dimexo:t.DIMEXO,dimdli:t.DIMDLI,dimexe:t.DIMEXE,dimrnd:t.DIMRND,dimdle:t.DIMDLE,dimtp:t.DIMTP,dimtm:t.DIMTM,dimtxt:t.DIMTXT,dimcen:t.DIMCEN,dimtsz:t.DIMTSZ,dimaltf:t.DIMALTF,dimlfac:t.DIMLFAC,dimtvp:t.DIMTVP,dimtfac:t.DIMTFAC,dimgap:t.DIMGAP,dimaltrnd:t.DIMALTRND,dimtol:t.DIMTOL==null||t.DIMTOL==0?0:1,dimlim:t.DIMLIM==null||t.DIMLIM==0?0:1,dimtih:t.DIMTIH==null||t.DIMTIH==0?0:1,dimtoh:t.DIMTOH==null||t.DIMTOH==0?0:1,dimse1:t.DIMSE1==null||t.DIMSE1==0?0:1,dimse2:t.DIMSE2==null||t.DIMSE2==0?0:1,dimtad:t.DIMTAD,dimzin:t.DIMZIN,dimazin:t.DIMAZIN,dimalt:t.DIMALT,dimaltd:t.DIMALTD,dimtofl:t.DIMTOFL,dimsah:t.DIMSAH,dimtix:t.DIMTIX,dimsoxd:t.DIMSOXD,dimclrd:t.DIMCLRD,dimclre:t.DIMCLRE,dimclrt:t.DIMCLRT,dimadec:t.DIMADEC||0,dimunit:t.DIMUNIT||2,dimdec:t.DIMDEC,dimtdec:t.DIMTDEC,dimaltu:t.DIMALTU,dimalttd:t.DIMALTTD,dimaunit:t.DIMAUNIT,dimfrac:t.DIMFRAC,dimlunit:t.DIMLUNIT,dimdsep:t.DIMDSEP,dimtmove:t.DIMTMOVE||0,dimjust:t.DIMJUST,dimsd1:t.DIMSD1,dimsd2:t.DIMSD2,dimtolj:t.DIMTOLJ,dimtzin:t.DIMTZIN,dimaltz:t.DIMALTZ,dimalttz:t.DIMALTTZ,dimfit:t.DIMFIT||0,dimupt:t.DIMUPT,dimatfit:t.DIMATFIT,dimtxsty:"Standard",dimldrblk:"",dimblk:t.DIMBLK||"",dimblk1:t.DIMBLK1||"",dimblk2:t.DIMBLK2||"",dimlwd:t.DIMLWD,dimlwe:t.DIMLWE},i=new s.AcDbDimStyleTableRecord(o);this.processCommonTableEntryAttrs(t,i),n.tables.dimStyleTable.add(i)})}processLayers(e,n){e.tables.LAYER.entries.forEach(t=>{const o=new s.AcCmColor;o.colorIndex=t.colorIndex;const i=new s.AcDbLayerTableRecord({name:t.name,standardFlags:t.standardFlag,linetype:t.lineType,lineWeight:t.lineweight,isOff:t.off,color:o,isPlottable:t.plotFlag!=0});this.processCommonTableEntryAttrs(t,i),n.tables.layerTable.add(i)})}processViewports(e,n){e.tables.VPORT.entries.forEach(t=>{const o=new s.AcDbViewportTableRecord;this.processCommonTableEntryAttrs(t,o),t.circleSides&&(o.circleSides=t.circleSides),o.standardFlag=t.standardFlag,o.center.copy(t.center),o.lowerLeftCorner.copy(t.lowerLeftCorner),o.upperRightCorner.copy(t.upperRightCorner),t.snapBasePoint&&o.snapBase.copy(t.snapBasePoint),t.snapRotationAngle&&(o.snapAngle=t.snapRotationAngle),t.snapSpacing&&o.snapIncrements.copy(t.snapSpacing),t.majorGridLines&&(o.gridMajor=t.majorGridLines),t.gridSpacing&&o.gridIncrements.copy(t.gridSpacing),t.backgroundObjectId&&(o.backgroundObjectId=t.backgroundObjectId),o.gsView.center.copy(t.center),o.gsView.viewDirectionFromTarget.copy(t.viewDirectionFromTarget),o.gsView.viewTarget.copy(t.viewTarget),t.lensLength&&(o.gsView.lensLength=t.lensLength),t.frontClippingPlane&&(o.gsView.frontClippingPlane=t.frontClippingPlane),t.backClippingPlane&&(o.gsView.backClippingPlane=t.backClippingPlane),t.viewHeight&&(o.gsView.viewHeight=t.viewHeight),t.viewTwistAngle&&(o.gsView.viewTwistAngle=t.viewTwistAngle),t.frozenLayers&&(o.gsView.frozenLayers=t.frozenLayers),t.styleSheet&&(o.gsView.styleSheet=t.styleSheet),t.renderMode&&(o.gsView.renderMode=t.renderMode),t.viewMode&&(o.gsView.viewMode=t.viewMode),t.ucsIconSetting&&(o.gsView.ucsIconSetting=t.ucsIconSetting),t.ucsOrigin&&o.gsView.ucsOrigin.copy(t.ucsOrigin),t.ucsXAxis&&o.gsView.ucsXAxis.copy(t.ucsXAxis),t.ucsYAxis&&o.gsView.ucsYAxis.copy(t.ucsYAxis),t.orthographicType&&(o.gsView.orthographicType=t.orthographicType),t.shadePlotSetting&&(o.gsView.shadePlotSetting=t.shadePlotSetting),t.shadePlotObjectId&&(o.gsView.shadePlotObjectId=t.shadePlotObjectId),t.visualStyleObjectId&&(o.gsView.visualStyleObjectId=t.visualStyleObjectId),t.isDefaultLightingOn&&(o.gsView.isDefaultLightingOn=t.isDefaultLightingOn),t.defaultLightingType&&(o.gsView.defaultLightingType=t.defaultLightingType),t.brightness&&(o.gsView.brightness=t.brightness),t.contrast&&(o.gsView.contrast=t.contrast),t.ambientColor&&(o.gsView.ambientColor=t.ambientColor),n.tables.viewportTable.add(o)})}processBlockTables(e,n){e.tables.BLOCK_RECORD.entries.forEach(t=>{let o=n.tables.blockTable.getAt(t.name);o||(o=new s.AcDbBlockTableRecord,o.objectId=t.handle.toString(),o.name=t.name,o.ownerId=t.ownerHandle.toString(),o.origin.copy(t.basePoint),o.layoutId=t.layout.toString(),n.tables.blockTable.add(o)),!o.isModelSapce&&!o.isPaperSapce&&t.entities&&t.entities.length>0&&this.processEntitiesInBlock(t.entities,o)})}processBlocks(e,n){}async processEntitiesInBlock(e,n){const r=new b,t=e.length,o=[];for(let i=0;i<t;i++){const a=e[i],c=r.convert(a);c&&o.push(c)}n.appendEntity(o)}async processEntities(e,n,r,t,o){const i=new b;let a=e.entities;const c=a.length,p=new s.AcDbBatchProcessing(c,100-t.value,r);this.config.convertByEntityType&&(a=this.groupAndFlattenByType(a));const l=n.tables.blockTable.modelSpace;await p.processChunk(async(D,d)=>{const h=[];for(let u=D;u<d;u++){const g=a[u],A=i.convert(g);A&&h.push(A)}if(l.appendEntity(h),o){let u=t.value+d/c*(100-t.value);u>100&&(u=100),await o(u,"ENTITY","IN-PROGRESS")}})}processHeader(e,n){const r=e.header;r.CECOLOR&&(r.CECOLOR.index>=0&&r.CECOLOR.index<=256?n.cecolor.colorIndex=r.CECOLOR.index:n.cecolor.setRGBValue(r.CECOLOR.rgb)),n.angBase=r.ANGBASE??0,n.angDir=r.ANGDIR??0,n.aunits=r.AUNITS??0,r.EXTMAX&&(n.extmax=r.EXTMAX),r.EXTMIN&&(n.extmin=r.EXTMIN),n.insunits=r.INSUNITS??1,n.pdmode=r.PDMODE??0,n.pdsize=r.PDSIZE??0}processCommonTableEntryAttrs(e,n){n.name=e.name,n.objectId=e.handle.toString(),n.ownerId=e.ownerHandle.toString()}processObjects(e,n){this.processLayouts(e,n),this.processImageDefs(e,n)}processLayouts(e,n){const r=n.dictionaries.layouts;e.objects.LAYOUT.forEach(o=>{const i=new s.AcDbLayout;i.layoutName=o.layoutName,i.tabOrder=o.tabOrder;const a=n.tables.blockTable.newIterator();i.objectId=o.handle.toString();for(const c of a)if(c.layoutId===i.objectId){i.blockTableRecordId=c.objectId;break}i.blockTableRecordId||o.layoutName==="Model"&&(i.blockTableRecordId=n.tables.blockTable.modelSpace.objectId),i.limits.min.copy(o.minLimit),i.limits.max.copy(o.maxLimit),i.extents.min.copy(o.minExtent),i.extents.max.copy(o.maxExtent),this.processCommonObjectAttrs(o,i),r.setAt(i.layoutName,i)})}processImageDefs(e,n){const r=n.dictionaries.imageDefs;e.objects.IMAGEDEF.forEach(o=>{const i=new s.AcDbRasterImageDef;i.sourceFileName=o.fileName,this.processCommonObjectAttrs(o,i),r.setAt(i.objectId,i)})}processCommonObjectAttrs(e,n){n.objectId=e.handle.toString(),n.ownerId=e.ownerHandle.toString()}groupAndFlattenByType(e){const n={},r=[];for(const t of e)n[t.type]||(n[t.type]=[],r.push(t.type)),n[t.type].push(t);return r.flatMap(t=>n[t])}}f.AcDbLibreDwgConverter=y,Object.defineProperty(f,Symbol.toStringTag,{value:"Module"})});