@mlightcad/libredwg-converter 3.5.35 → 3.5.37

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,833 +0,0 @@
1
- import { AcDbFace as j, AcGeVector3d as A, AcDbArc as z, transformOcsPointToWcs as x, AcDbCircle as U, AcDbEllipse as X, AcDbLine as _, AcGePoint3d as S, AcDbSpline as M, AcDbPoint as G, AcDbTrace as Y, AcDbPolyline as Z, AcGePoint2d as m, AcDbPolygonMesh as K, AcDbPolyFaceMesh as q, AcDbPoly2dType as b, AcDb2dPolyline as J, AcDbPoly3dType as I, AcDb3dPolyline as Q, AcDbHatch as $, AcGePolyline2d as ee, AcGeLine2d as te, AcGeCircArc2d as ne, AcGeVector2d as oe, AcGeEllipseArc2d as re, AcGeSpline3d as v, AcGeLoop2d as O, AcDbHatchObjectType as ie, AcDbTable as se, AcDbText as ce, AcDbMText as ae, AcDbLeader as le, AcDbMLine as de, AcDbMLeader as fe, AcDbMLeaderLineType as pe, AcDbMLeaderContentType as T, AcDbAlignedDimension as ue, AcDbRotatedDimension as ge, AcDb3PointAngularDimension as he, AcDbOrdinateDimension as De, AcDbRadialDimension as ye, AcDbDiametricDimension as Ae, AcDbRasterImage as be, AcDbWipeout as Pe, AcDbViewport as Ie, AcDbRay as Te, AcDbXline as Le, AcDbAttributeFlags as P, AcDbAttributeMTextFlag as k, AcDbAttribute as N, AcDbAttributeDefinition as we, AcDbBlockReference as Ce, AcCmColor as B, AcCmTransparency as Ee, AcDbDatabaseConverter as xe, createWorkerApi as Se, AcDbLinetypeTableRecord as Me, AcDbTextStyleTableRecord as me, DEFAULT_TEXT_STYLE as R, AcDbDimStyleTableRecord as ve, AcDbLayerTableRecord as Oe, AcDbViewportTableRecord as ke, VPORT_FALLBACK_CENTER_2D as V, VPORT_FALLBACK_LLC as Ne, VPORT_FALLBACK_URC as Re, VPORT_FALLBACK_VIEW_DIR as Ve, VPORT_FALLBACK_VIEW_TARGET as Fe, AcDbBlockTableRecord as Be, AcDbBatchProcessing as He, ByLayer as We, AcDbLayout as je, AcDbRasterImageDef as ze } from "@mlightcad/data-model";
2
- class F {
3
- convert(e) {
4
- const t = this.createEntity(e);
5
- return t && this.processCommonAttrs(e, t), t;
6
- }
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 == "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 == "MLINE" ? this.convertMLine(e) : e.type == "MTEXT" ? this.convertMText(e) : e.type == "MULTILEADER" || e.type == "MLEADER" ? this.convertMLeader(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
- }
10
- convertFace(e) {
11
- const t = new j();
12
- return e.corner1 && t.setVertexAt(0, e.corner1), e.corner2 && t.setVertexAt(1, e.corner2), e.corner3 && t.setVertexAt(2, e.corner3), e.corner4 && t.setVertexAt(3, e.corner4), t.setEdgeInvisibilities(e.flag), t;
13
- }
14
- convertArc(e) {
15
- const t = e.extrusionDirection ?? A.Z_AXIS;
16
- return new z(
17
- x(e.center, t),
18
- e.radius,
19
- e.startAngle,
20
- e.endAngle,
21
- t
22
- );
23
- }
24
- convertCirle(e) {
25
- const t = e.extrusionDirection ?? A.Z_AXIS;
26
- return new U(
27
- x(e.center, t),
28
- e.radius,
29
- t
30
- );
31
- }
32
- convertEllipse(e) {
33
- const t = new A(e.majorAxisEndPoint), o = t.length();
34
- return new X(
35
- e.center,
36
- e.extrusionDirection ?? A.Z_AXIS,
37
- t,
38
- o,
39
- o * e.axisRatio,
40
- e.startAngle,
41
- e.endAngle
42
- );
43
- }
44
- convertLine(e) {
45
- const t = e.startPoint, o = e.endPoint;
46
- return new _(
47
- new S(t.x, t.y, t.z),
48
- new S(o.x, o.y, o.z)
49
- );
50
- }
51
- convertSpline(e) {
52
- try {
53
- if (e.numberOfControlPoints > 0 && e.numberOfKnots > 0)
54
- return new M(
55
- e.controlPoints,
56
- e.knots,
57
- e.weights,
58
- e.degree,
59
- !!(e.flag & 1)
60
- );
61
- if (e.numberOfFitPoints > 0)
62
- return new M(
63
- e.fitPoints,
64
- "Uniform",
65
- e.degree,
66
- !!(e.flag & 1)
67
- );
68
- } catch {
69
- }
70
- return null;
71
- }
72
- convertPoint(e) {
73
- const t = new G();
74
- return t.position = e.position, t;
75
- }
76
- convertSolid(e) {
77
- const t = new Y();
78
- return t.setPointAt(0, { ...e.corner1, z: 0 }), t.setPointAt(1, { ...e.corner2, z: 0 }), t.setPointAt(2, { ...e.corner3, z: 0 }), t.setPointAt(
79
- 3,
80
- e.corner4 ? { ...e.corner4, z: 0 } : { ...e.corner3, z: 0 }
81
- ), t.thickness = e.thickness, t;
82
- }
83
- convertLWPolyline(e) {
84
- const t = new Z();
85
- t.closed = !!(e.flag & 512);
86
- const o = e.constantWidth ?? -1;
87
- return e.vertices.forEach((n, r) => {
88
- t.addVertexAt(
89
- r,
90
- new m(n.x, n.y),
91
- n.bulge,
92
- n.startWidth ?? o,
93
- n.endWidth ?? o
94
- );
95
- }), t;
96
- }
97
- convertPolyline2d(e) {
98
- const t = !!(e.flag & 1), o = !!(e.flag & 16), n = !!(e.flag & 64), r = !!(e.flag & 32), i = [], a = [], s = [];
99
- if (e.vertices.map((c) => {
100
- if (!(c.flag & 16))
101
- if (n && c.flag & 128)
102
- if (c.flag & 64)
103
- i.push({
104
- x: c.x,
105
- y: c.y,
106
- z: c.z
107
- }), a.push(c.bulge ?? 0);
108
- else {
109
- const d = [];
110
- c.polyfaceIndex0 != null && c.polyfaceIndex0 != 0 && d.push(Math.abs(c.polyfaceIndex0) - 1), c.polyfaceIndex1 != null && c.polyfaceIndex1 != 0 && d.push(Math.abs(c.polyfaceIndex1) - 1), c.polyfaceIndex2 != null && c.polyfaceIndex2 != 0 && d.push(Math.abs(c.polyfaceIndex2) - 1), c.polyfaceIndex3 != null && c.polyfaceIndex3 != 0 && d.push(Math.abs(c.polyfaceIndex3) - 1), d.length >= 3 && s.push(d);
111
- }
112
- else
113
- i.push({
114
- x: c.x,
115
- y: c.y,
116
- z: c.z
117
- }), a.push(c.bulge ?? 0);
118
- }), o) {
119
- const c = e.meshMVertexCount ?? 2, d = e.meshNVertexCount ?? 2;
120
- return new K(c, d, i, t, r);
121
- } else {
122
- if (n)
123
- return new q(i, s);
124
- {
125
- let c = b.SimplePoly;
126
- return e.flag & 2 ? c = b.FitCurvePoly : e.flag & 4 && (e.smoothType == 6 ? c = b.CubicSplinePoly : e.smoothType == 5 && (c = b.QuadSplinePoly)), new J(
127
- c,
128
- i,
129
- 0,
130
- t,
131
- e.startWidth,
132
- e.endWidth,
133
- a
134
- );
135
- }
136
- }
137
- }
138
- convertPolyline3d(e) {
139
- const t = !!(e.flag & 1), o = [];
140
- e.vertices.map((r) => {
141
- r.flag & 16 || o.push({
142
- x: r.x,
143
- y: r.y,
144
- z: r.z
145
- });
146
- });
147
- let n = I.SimplePoly;
148
- return e.flag & 4 && (e.smoothType == 6 ? n = I.CubicSplinePoly : e.smoothType == 5 && (n = I.QuadSplinePoly)), new Q(n, o, t);
149
- }
150
- convertHatch(e) {
151
- var n;
152
- const t = new $();
153
- if ((n = e.definitionLines) == null || n.forEach((r) => {
154
- t.definitionLines.push({
155
- angle: r.angle,
156
- base: r.base,
157
- offset: r.offset,
158
- dashLengths: r.numberOfDashLengths > 0 ? r.dashLengths : []
159
- });
160
- }), t.isSolidFill = e.solidFill == 1, t.hatchStyle = e.hatchStyle, t.patternName = e.patternName, t.patternType = e.patternType, t.patternAngle = e.patternAngle == null ? 0 : e.patternAngle, t.patternScale = e.patternScale == null ? 0 : e.patternScale, e.boundaryPaths.forEach((r) => {
161
- if (r.boundaryPathTypeFlag & 2) {
162
- const a = r, s = new ee();
163
- s.closed = a.isClosed, a.vertices.forEach((c, d) => {
164
- s.addVertexAt(d, {
165
- x: c.x,
166
- y: c.y,
167
- bulge: c.bulge
168
- });
169
- }), t.add(s);
170
- } else {
171
- const a = r, s = [];
172
- a.edges.forEach((d) => {
173
- if (d != null) {
174
- if (d.type == 1) {
175
- const l = d;
176
- s.push(new te(l.start, l.end));
177
- } else if (d.type == 2) {
178
- const l = d;
179
- s.push(
180
- new ne(
181
- l.center,
182
- l.radius,
183
- l.startAngle,
184
- l.endAngle,
185
- !l.isCCW
186
- )
187
- );
188
- } else if (d.type == 3) {
189
- const l = d;
190
- new oe().subVectors(l.end, l.center);
191
- const p = Math.sqrt(
192
- Math.pow(l.end.x, 2) + Math.pow(l.end.y, 2)
193
- ), u = p * l.lengthOfMinorAxis;
194
- let g = l.startAngle, y = l.endAngle;
195
- const h = Math.atan2(l.end.y, l.end.x);
196
- l.isCCW || (g = Math.PI * 2 - g, y = Math.PI * 2 - y), s.push(
197
- new re(
198
- { ...l.center, z: 0 },
199
- p,
200
- u,
201
- g,
202
- y,
203
- !l.isCCW,
204
- h
205
- )
206
- );
207
- } else if (d.type == 4) {
208
- const l = d;
209
- if (l.numberOfControlPoints > 0 && l.numberOfKnots > 0) {
210
- const f = l.controlPoints.map(
211
- (g) => ({
212
- x: g.x,
213
- y: g.y,
214
- z: 0
215
- })
216
- );
217
- let p = !0;
218
- const u = l.controlPoints.map((g) => (g.weight == null && (p = !1), g.weight || 1));
219
- s.push(
220
- new v(
221
- f,
222
- l.knots,
223
- p ? u : void 0
224
- )
225
- );
226
- } else if (l.numberOfFitData > 0) {
227
- const f = l.fitDatum.map((p) => ({
228
- x: p.x,
229
- y: p.y,
230
- z: 0
231
- }));
232
- s.push(new v(f, "Uniform"));
233
- }
234
- }
235
- }
236
- });
237
- const c = O.buildFromEdges(s);
238
- c.length == 0 && s.length > 0 ? t.add(new O(s)) : c.forEach((d) => t.add(d));
239
- }
240
- }), e.gradientFlag) {
241
- const r = e;
242
- if (t.hatchObjectType = ie.GradientObject, t.gradientName = r.gradientName, t.gradientAngle = r.gradientRotation ?? 0, t.gradientShift = r.gradientDefinition ?? 0, t.gradientOneColorMode = r.gradientColorFlag == 1, t.shadeTintValue = r.colorTint ?? 0, r.gradientColors) {
243
- const i = r.gradientColors.length;
244
- i > 1 ? (t.gradientStartColor = r.gradientColors[0].rgb, t.gradientEndColor = r.gradientColors[1].rgb) : i > 0 && (t.gradientStartColor = r.gradientColors[0].rgb);
245
- }
246
- }
247
- return t;
248
- }
249
- convertTable(e) {
250
- const t = new se(
251
- e.name,
252
- e.rowCount,
253
- e.columnCount
254
- );
255
- return t.tableStyleId = e.tableStyleId, t.owningBlockRecordId = e.blockRecordHandle, e.directionVector && (t.horizontalDirection = new A(e.directionVector)), t.attachmentPoint = e.attachmentPoint, t.position.copy(e.startPoint), t.tableValueFlag = e.tableValue, t.tableOverrideFlag = e.overrideFlag, t.borderColorOverrideFlag = e.borderColorOverrideFlag, t.borderLineweightOverrideFlag = e.borderLineWeightOverrideFlag, t.borderVisibilityOverrideFlag = e.borderVisibilityOverrideFlag, e.columnWidthArr.forEach(
256
- (o, n) => t.setColumnWidth(n, o)
257
- ), e.rowHeightArr.forEach(
258
- (o, n) => t.setRowHeight(n, o)
259
- ), e.cells.forEach((o, n) => {
260
- t.setCell(n, o);
261
- }), t;
262
- }
263
- convertText(e) {
264
- const t = new ce();
265
- t.textString = e.text, t.styleName = e.styleName, t.height = e.textHeight, t.position.copy(e.startPoint);
266
- const o = !e.endPoint || e.endPoint.x === 0 && e.endPoint.y === 0 && (e.endPoint.z ?? 0) === 0;
267
- return e.endPoint && !o ? t.alignmentPoint.copy(e.endPoint) : t.alignmentPoint.copy(e.startPoint), t.rotation = e.rotation, t.oblique = e.obliqueAngle ?? 0, t.thickness = e.thickness, t.horizontalMode = e.halign, t.verticalMode = e.valign, t.widthFactor = e.xScale ?? 1, t;
268
- }
269
- convertMText(e) {
270
- const t = new ae();
271
- return t.contents = e.text, e.styleName != null && (t.styleName = e.styleName), t.height = e.textHeight, t.width = e.rectWidth, t.rotation = e.rotation || 0, t.location = e.insertionPoint, t.attachmentPoint = e.attachmentPoint, e.direction && (t.direction = new A(e.direction)), t.drawingDirection = e.drawingDirection, t;
272
- }
273
- convertLeader(e) {
274
- const t = new le();
275
- return e.vertices.forEach((o) => {
276
- t.appendVertex(o);
277
- }), t.hasArrowHead = e.isArrowheadEnabled, t.hasHookLine = e.isHooklineExists, t.isSplined = e.isSpline, t.dimensionStyle = e.styleName, t.annoType = e.leaderCreationFlag, t;
278
- }
279
- convertMLine(e) {
280
- const t = new de();
281
- return t.styleName = e.mlineStyle || "STANDARD", t.scale = e.scale, t.flags = e.flags, t.justification = e.justification, t.startPosition = e.startPoint, t.normal = e.extrusionDirection ?? A.Z_AXIS, t.styleCount = e.numberOfLines ?? 0, t.segments = (e.vertices ?? []).map((o) => ({
282
- position: o.vertex,
283
- direction: o.vertexDirection,
284
- miterDirection: o.miterDirection,
285
- elements: (o.lines ?? []).map((n) => ({
286
- parameterCount: n.numberOfSegmentParams,
287
- parameters: n.segmentParams ?? [],
288
- fillCount: n.numberOfAreaFillParams,
289
- fillParameters: n.areaFillParams ?? []
290
- }))
291
- })), t;
292
- }
293
- convertMLeader(e) {
294
- var p, u, g, y;
295
- const t = new fe(), o = e;
296
- t.leaderLineType = this.readNumber(o, [
297
- "multileaderType",
298
- "leaderLineType",
299
- "leaderType"
300
- ]) ?? pe.StraightLeader;
301
- const n = this.readNumber(o, ["contentType"]) ?? (e.textContent ? T.MTextContent : e.blockContent ? T.BlockContent : T.NoneContent);
302
- t.contentType = n, t.doglegEnabled = this.readBoolean(o, ["doglegEnabled", "enableDogleg"]) ?? !1, t.doglegLength = this.readNumber(o, ["doglegLength"]) ?? 0, e.landingPoint && (t.landingPoint = e.landingPoint), e.doglegVector && (t.doglegVector = e.doglegVector);
303
- const r = this.readString(o, [
304
- "mleaderStyleId",
305
- "mLeaderStyleId",
306
- "mleaderStyleHandle",
307
- "styleHandle",
308
- "styleName"
309
- ]);
310
- r && (t.mleaderStyleId = r);
311
- const i = this.readPoint(o, ["normal", "extrusionDirection"]);
312
- i && (t.normal = i);
313
- const a = e.textContent, s = this.readString(a ?? {}, ["styleName", "textStyleName"]) ?? this.readString(o, ["textStyleName", "textStyle", "styleName"]);
314
- s && (t.textStyleName = s), t.textHeight = this.readNumber(a ?? {}, ["textHeight", "height"]) ?? this.readNumber(o, [
315
- "textHeight",
316
- "mtextHeight",
317
- "textContentHeight"
318
- ]) ?? t.textHeight, t.textWidth = this.readNumber(a ?? {}, ["textWidth", "width"]) ?? this.readNumber(o, ["textWidth", "mtextWidth", "textContentWidth"]) ?? t.textWidth;
319
- const c = this.readNumber(a ?? {}, ["textRotation", "rotation"]) ?? this.readNumber(o, [
320
- "textRotation",
321
- "mtextRotation",
322
- "textContentRotation"
323
- ]);
324
- c != null && (t.textRotation = c);
325
- const d = this.readPoint(o, [
326
- "textDirection",
327
- "mtextDirection",
328
- "textDirectionVector"
329
- ]);
330
- d && (t.textDirection = d);
331
- const l = this.readNumber(o, [
332
- "textAttachmentPoint",
333
- "attachmentPoint"
334
- ]);
335
- l != null && (t.textAttachmentPoint = l);
336
- const f = this.readNumber(o, [
337
- "textDrawingDirection",
338
- "drawingDirection"
339
- ]);
340
- if (f != null && (t.textDrawingDirection = f), ((p = e.textContent) == null ? void 0 : p.text) != null && e.textContent.anchorPoint)
341
- t.mtextContent = {
342
- text: e.textContent.text,
343
- anchorPoint: e.textContent.anchorPoint
344
- };
345
- else {
346
- const h = this.readString(o, ["text", "contents", "mtext"]), D = this.readPoint(o, [
347
- "textLocation",
348
- "textPosition",
349
- "textAnchorPoint"
350
- ]);
351
- h != null && D && (t.mtextContent = { text: h, anchorPoint: D });
352
- }
353
- if ((u = e.blockContent) != null && u.blockHandle && e.blockContent.position)
354
- t.blockContent = {
355
- blockHandle: e.blockContent.blockHandle,
356
- position: e.blockContent.position
357
- };
358
- else {
359
- const h = this.readString(o, [
360
- "blockHandle",
361
- "blockContentHandle",
362
- "blockId"
363
- ]), D = this.readPoint(o, [
364
- "blockPosition",
365
- "blockContentPosition"
366
- ]);
367
- h && D && (t.blockContent = {
368
- blockHandle: h,
369
- position: D
370
- });
371
- }
372
- return (g = e.leaders) == null || g.forEach((h) => {
373
- var L;
374
- const D = t.addLeader({
375
- landingPoint: h.landingPoint ?? e.landingPoint,
376
- doglegVector: h.doglegVector ?? e.doglegVector,
377
- doglegLength: h.doglegLength ?? e.doglegLength
378
- });
379
- (L = h.leaderLines) == null || L.forEach((w) => {
380
- var C;
381
- const W = t.addLeaderLine(
382
- D,
383
- w.vertices ?? []
384
- );
385
- (C = w.breaks) == null || C.forEach((E) => {
386
- t.addBreak(D, W, E.start, E.end);
387
- });
388
- });
389
- }), t.numberOfLeaders === 0 && ((y = this.readLeaderLineArray(o)) == null || y.forEach((h) => {
390
- const D = t.addLeader({
391
- landingPoint: e.landingPoint,
392
- doglegVector: e.doglegVector,
393
- doglegLength: e.doglegLength
394
- });
395
- t.addLeaderLine(D, h);
396
- })), t;
397
- }
398
- convertDimension(e) {
399
- if (e.subclassMarker == "AcDbAlignedDimension") {
400
- const t = e, o = new ue(
401
- t.subDefinitionPoint1,
402
- t.subDefinitionPoint2,
403
- t.definitionPoint
404
- );
405
- return t.insertionPoint && (o.dimBlockPosition = {
406
- x: t.insertionPoint.x,
407
- y: t.insertionPoint.y,
408
- z: 0
409
- }), o.rotation = t.rotationAngle, this.processDimensionCommonAttrs(e, o), o;
410
- } else if (e.subclassMarker == "AcDbRotatedDimension") {
411
- const t = e, o = new ge(
412
- t.subDefinitionPoint1,
413
- t.subDefinitionPoint2,
414
- t.definitionPoint
415
- );
416
- return t.insertionPoint && (o.dimBlockPosition = {
417
- x: t.insertionPoint.x,
418
- y: t.insertionPoint.y,
419
- z: 0
420
- }), o.rotation = t.rotationAngle, this.processDimensionCommonAttrs(e, o), o;
421
- } else if (e.subclassMarker == "AcDb3PointAngularDimension") {
422
- const t = e, o = new he(
423
- t.centerPoint,
424
- t.subDefinitionPoint1,
425
- t.subDefinitionPoint2,
426
- t.definitionPoint
427
- );
428
- return this.processDimensionCommonAttrs(e, o), o;
429
- } else if (e.subclassMarker == "AcDbOrdinateDimension") {
430
- const t = e, o = new De(
431
- t.subDefinitionPoint1,
432
- t.subDefinitionPoint2
433
- );
434
- return this.processDimensionCommonAttrs(e, o), o;
435
- } else if (e.subclassMarker == "AcDbRadialDimension") {
436
- const t = e, o = new ye(
437
- t.definitionPoint,
438
- t.centerPoint,
439
- t.leaderLength
440
- );
441
- return this.processDimensionCommonAttrs(e, o), o;
442
- } else if (e.subclassMarker == "AcDbDiametricDimension") {
443
- const t = e, o = new Ae(
444
- t.definitionPoint,
445
- t.centerPoint,
446
- t.leaderLength
447
- );
448
- return this.processDimensionCommonAttrs(e, o), o;
449
- }
450
- return null;
451
- }
452
- processImage(e, t) {
453
- t.position.copy(e.position), t.brightness = e.brightness, t.contrast = e.contrast, t.fade = e.fade, t.imageSize.copy(e.imageSize), t.imageDefId = e.imageDefHandle, t.isClipped = e.clipping > 0, t.isShownClipped = (e.flags | 4) > 0, t.isImageShown = (e.flags | 3) > 0, t.isImageTransparent = (e.flags | 8) > 0, e.clippingBoundaryPath.forEach((o) => {
454
- t.clipBoundary.push(new m(o));
455
- }), t.clipBoundaryType = e.clippingBoundaryType, t.width = Math.sqrt(
456
- e.uPixel.x ** 2 + e.uPixel.y ** 2 + e.uPixel.z ** 2
457
- ) * e.imageSize.x, t.height = Math.sqrt(
458
- e.vPixel.x ** 2 + e.vPixel.y ** 2 + e.vPixel.z ** 2
459
- ) * e.imageSize.y, t.rotation = Math.atan2(e.uPixel.y, e.uPixel.x);
460
- }
461
- convertImage(e) {
462
- const t = new be();
463
- return this.processImage(e, t), t;
464
- }
465
- convertWipeout(e) {
466
- const t = new Pe();
467
- return this.processImage(e, t), t;
468
- }
469
- convertViewport(e) {
470
- const t = new Ie();
471
- return t.number = e.viewportId, t.centerPoint.copy(e.viewportCenter), t.height = e.height, t.width = e.width, t.viewCenter.copy(e.displayCenter), t.viewHeight = e.viewHeight, t;
472
- }
473
- convertRay(e) {
474
- const t = new Te();
475
- return t.basePoint.copy(e.firstPoint), t.unitDir.copy(e.unitDirection), t;
476
- }
477
- convertXline(e) {
478
- const t = new Le();
479
- return t.basePoint.copy(e.firstPoint), t.unitDir.copy(e.unitDirection), t;
480
- }
481
- convertAttributeCommon(e, t) {
482
- const o = e.text;
483
- t.textString = o.text, t.styleName = o.styleName, t.height = o.textHeight, t.position.copy(o.startPoint);
484
- const n = e.alignmentPoint ?? o.endPoint, r = !n || n.x === 0 && n.y === 0 && (n.z ?? 0) === 0;
485
- n && !r ? t.alignmentPoint.copy(n) : t.alignmentPoint.copy(o.startPoint), t.rotation = o.rotation, t.oblique = o.obliqueAngle ?? 0, t.thickness = o.thickness, t.horizontalMode = o.halign, t.verticalMode = o.valign, t.widthFactor = o.xScale ?? 1, t.tag = e.tag, t.fieldLength = e.fieldLength, t.isInvisible = (e.flags & P.Invisible) !== 0, t.isConst = (e.flags & P.Const) !== 0, t.isVerifiable = (e.flags & P.Verifiable) !== 0, t.isPreset = (e.flags & P.Preset) !== 0, t.lockPositionInBlock = e.lockPositionFlag, t.isReallyLocked = e.isReallyLocked, t.isMTextAttribute = (e.mtextFlag & k.MultiLine) !== 0, t.isConstMTextAttribute = (e.mtextFlag & k.ConstMultiLine) !== 0;
486
- }
487
- convertAttribute(e) {
488
- const t = new N();
489
- return this.convertAttributeCommon(e, t), t;
490
- }
491
- convertAttributeDefinition(e) {
492
- const t = new we();
493
- return this.convertAttributeCommon(e, t), t.prompt = e.prompt, t;
494
- }
495
- convertBlockReference(e) {
496
- const t = new Ce(e.name);
497
- return e.insertionPoint && t.position.copy(e.insertionPoint), t.scaleFactors.x = e.xScale, t.scaleFactors.y = e.yScale, t.scaleFactors.z = e.zScale, t.rotation = e.rotation, t.normal.copy(e.extrusionDirection), e.handle != null && (t.objectId = e.handle), e.attribs && e.attribs.forEach((o) => {
498
- const n = this.convert(o);
499
- n instanceof N && t.appendAttributes(n);
500
- }), t;
501
- }
502
- processDimensionCommonAttrs(e, t) {
503
- t.dimBlockId = e.name, t.textPosition.copy(e.textPoint), t.textRotation = e.textRotation || 0, e.textLineSpacingFactor && (t.textLineSpacingFactor = e.textLineSpacingFactor), e.textLineSpacingStyle && (t.textLineSpacingStyle = e.textLineSpacingStyle), t.dimensionStyleName = e.styleName, t.dimensionText = e.text || "", t.measurement = e.measurement;
504
- }
505
- processCommonAttrs(e, t) {
506
- if (t.layer = e.layer || "0", t.objectId = e.handle, e.ownerBlockRecordSoftId != null && (t.ownerId = e.ownerBlockRecordSoftId), e.lineType != null && (t.lineType = e.lineType), e.lineweight != null && (t.lineWeight = e.lineweight), e.lineTypeScale != null && (t.linetypeScale = e.lineTypeScale), e.color != null || e.colorIndex != null || e.colorName) {
507
- const o = new B();
508
- e.color != null && o.setRGBValue(e.color), e.colorIndex != null && (e.color == null || e.colorIndex === 7) && (o.colorIndex = e.colorIndex), e.colorName && (o.colorName = e.colorName), t.color = o;
509
- }
510
- if (e.isVisible != null && (t.visibility = e.isVisible), e.transparency != null) {
511
- const o = new Ee();
512
- o.method = e.transparencyType, (o.isByBlock || o.isByBlock) && (o.alpha = e.transparency), t.transparency = o;
513
- }
514
- }
515
- readNumber(e, t) {
516
- for (const o of t) {
517
- const n = e[o];
518
- if (typeof n == "number" && Number.isFinite(n)) return n;
519
- }
520
- }
521
- readString(e, t) {
522
- for (const o of t) {
523
- const n = e[o];
524
- if (typeof n == "string") return n;
525
- }
526
- }
527
- readBoolean(e, t) {
528
- for (const o of t) {
529
- const n = e[o];
530
- if (typeof n == "boolean") return n;
531
- if (typeof n == "number") return n !== 0;
532
- }
533
- }
534
- readPoint(e, t) {
535
- for (const o of t) {
536
- const n = e[o];
537
- if (this.isPointLike(n)) return n;
538
- if (Array.isArray(n) && typeof n[0] == "number" && typeof n[1] == "number")
539
- return { x: n[0], y: n[1], z: n[2] ?? 0 };
540
- }
541
- }
542
- readLeaderLineArray(e) {
543
- const t = e.leaderLines;
544
- if (Array.isArray(t))
545
- return t.map((n) => {
546
- if (!n || typeof n != "object") return;
547
- const r = n.vertices;
548
- return Array.isArray(r) ? r.filter((i) => this.isPointLike(i)) : void 0;
549
- }).filter((n) => !!n && n.length > 0);
550
- const o = e.vertices;
551
- if (Array.isArray(o)) {
552
- const n = o.filter((r) => this.isPointLike(r));
553
- return n.length > 0 ? [n] : void 0;
554
- }
555
- }
556
- isPointLike(e) {
557
- return !!e && typeof e == "object" && typeof e.x == "number" && typeof e.y == "number";
558
- }
559
- }
560
- const Ue = "*MODEL_SPACE";
561
- class _e extends xe {
562
- constructor(e = {}) {
563
- super(e), e.useWorker = !0, e.parserWorkerUrl || (e.parserWorkerUrl = "/assets/libredwg-parser-worker.js");
564
- }
565
- async parse(e, t) {
566
- const o = this.config, n = this.getParserWorkerTimeout(e, t);
567
- if (o.useWorker && o.parserWorkerUrl) {
568
- const r = Se({
569
- workerUrl: o.parserWorkerUrl,
570
- timeout: n,
571
- maxConcurrentWorkers: 1
572
- }), i = await r.execute(e);
573
- if (r.destroy(), i.success)
574
- return i.data;
575
- throw new Error(
576
- `Failed to parse drawing due to error: '${i.error}'`
577
- );
578
- } else
579
- throw new Error("dwg converter can run in web worker only!");
580
- }
581
- getFonts(e) {
582
- const t = /* @__PURE__ */ new Map();
583
- e.tables.BLOCK_RECORD.entries.forEach((i) => {
584
- t.set(i.name, i);
585
- });
586
- const o = /* @__PURE__ */ new Map(), n = (i) => {
587
- if (i) {
588
- const a = i.lastIndexOf(".");
589
- return a >= 0 ? i.substring(0, a).toLowerCase() : i.toLowerCase();
590
- }
591
- };
592
- e.tables.STYLE.entries.forEach((i) => {
593
- const a = [];
594
- let s = n(i.font);
595
- s && a.push(s), s = n(i.bigFont), s && a.push(s), o.set(i.name, a);
596
- });
597
- const r = /* @__PURE__ */ new Set();
598
- return this.getFontsInBlock(e.entities, t, o, r), Array.from(r);
599
- }
600
- getFontsInBlock(e, t, o, n) {
601
- const r = /\\f(.*?)\|/g;
602
- e.forEach((i) => {
603
- if (i.type == "MTEXT") {
604
- const a = i;
605
- [...a.text.matchAll(r)].forEach((c) => {
606
- n.add(c[1].toLowerCase());
607
- });
608
- const s = o.get(a.styleName);
609
- s == null || s.forEach((c) => n.add(c));
610
- } else if (i.type == "TEXT") {
611
- const a = i, s = o.get(a.styleName);
612
- s == null || s.forEach((c) => n.add(c));
613
- } else if (i.type == "MULTILEADER" || i.type == "MLEADER") {
614
- const a = i, s = a.textContent;
615
- [...(typeof (s == null ? void 0 : s.text) == "string" ? s.text : "").matchAll(r)].forEach((f) => {
616
- n.add(f[1].toLowerCase());
617
- });
618
- const d = typeof (s == null ? void 0 : s.styleName) == "string" ? s.styleName : typeof a.textStyleName == "string" ? a.textStyleName : typeof a.styleName == "string" ? a.styleName : void 0, l = d ? o.get(d) : void 0;
619
- l == null || l.forEach((f) => n.add(f));
620
- } else if (i.type == "INSERT") {
621
- const a = i, s = t.get(a.name);
622
- s && this.getFontsInBlock(s.entities, t, o, n);
623
- }
624
- });
625
- }
626
- processLineTypes(e, t) {
627
- e.tables.LTYPE.entries.forEach((n) => {
628
- const r = {
629
- name: n.name,
630
- description: n.description,
631
- standardFlag: n.standardFlag,
632
- totalPatternLength: n.totalPatternLength,
633
- pattern: n.pattern
634
- }, i = new Me(r);
635
- this.processCommonTableEntryAttrs(n, i), i.name = n.name, t.tables.linetypeTable.add(i);
636
- });
637
- }
638
- processTextStyles(e, t) {
639
- e.tables.STYLE.entries.forEach((n) => {
640
- const r = new me(n);
641
- this.processCommonTableEntryAttrs(n, r), t.tables.textStyleTable.add(r);
642
- });
643
- }
644
- processDimStyles(e, t) {
645
- e.tables.DIMSTYLE.entries.forEach((n) => {
646
- const r = {
647
- name: n.name,
648
- ownerId: n.ownerHandle,
649
- dimpost: n.DIMPOST || "",
650
- dimapost: n.DIMAPOST || "",
651
- dimscale: n.DIMSCALE,
652
- dimasz: n.DIMASZ,
653
- dimexo: n.DIMEXO,
654
- dimdli: n.DIMDLI,
655
- dimexe: n.DIMEXE,
656
- dimrnd: n.DIMRND,
657
- dimdle: n.DIMDLE,
658
- dimtp: n.DIMTP,
659
- dimtm: n.DIMTM,
660
- dimtxt: n.DIMTXT,
661
- dimcen: n.DIMCEN,
662
- dimtsz: n.DIMTSZ,
663
- dimaltf: n.DIMALTF,
664
- dimlfac: n.DIMLFAC,
665
- dimtvp: n.DIMTVP,
666
- dimtfac: n.DIMTFAC,
667
- dimgap: n.DIMGAP,
668
- dimaltrnd: n.DIMALTRND,
669
- dimtol: n.DIMTOL == null || n.DIMTOL == 0 ? 0 : 1,
670
- dimlim: n.DIMLIM == null || n.DIMLIM == 0 ? 0 : 1,
671
- dimtih: n.DIMTIH == null || n.DIMTIH == 0 ? 0 : 1,
672
- dimtoh: n.DIMTOH == null || n.DIMTOH == 0 ? 0 : 1,
673
- dimse1: n.DIMSE1 == null || n.DIMSE1 == 0 ? 0 : 1,
674
- dimse2: n.DIMSE2 == null || n.DIMSE2 == 0 ? 0 : 1,
675
- dimtad: n.DIMTAD,
676
- dimzin: n.DIMZIN,
677
- dimazin: n.DIMAZIN,
678
- dimalt: n.DIMALT,
679
- dimaltd: n.DIMALTD,
680
- dimtofl: n.DIMTOFL,
681
- dimsah: n.DIMSAH,
682
- dimtix: n.DIMTIX,
683
- dimsoxd: n.DIMSOXD,
684
- dimclrd: n.DIMCLRD,
685
- dimclre: n.DIMCLRE,
686
- dimclrt: n.DIMCLRT,
687
- dimadec: n.DIMADEC || 0,
688
- dimunit: n.DIMUNIT || 2,
689
- dimdec: n.DIMDEC,
690
- dimtdec: n.DIMTDEC,
691
- dimaltu: n.DIMALTU,
692
- dimalttd: n.DIMALTTD,
693
- dimaunit: n.DIMAUNIT,
694
- dimfrac: n.DIMFRAC,
695
- dimlunit: n.DIMLUNIT,
696
- dimdsep: n.DIMDSEP || ".",
697
- dimtmove: n.DIMTMOVE || 0,
698
- dimjust: n.DIMJUST,
699
- dimsd1: n.DIMSD1,
700
- dimsd2: n.DIMSD2,
701
- dimtolj: n.DIMTOLJ,
702
- dimtzin: n.DIMTZIN,
703
- dimaltz: n.DIMALTZ,
704
- dimalttz: n.DIMALTTZ,
705
- dimfit: n.DIMFIT || 0,
706
- dimupt: n.DIMUPT,
707
- dimatfit: n.DIMATFIT,
708
- dimtxsty: R,
709
- dimldrblk: "",
710
- dimblk: n.DIMBLK || "",
711
- dimblk1: n.DIMBLK1 || "",
712
- dimblk2: n.DIMBLK2 || "",
713
- dimlwd: n.DIMLWD,
714
- dimlwe: n.DIMLWE
715
- }, i = new ve(r);
716
- this.processCommonTableEntryAttrs(n, i), t.tables.dimStyleTable.add(i);
717
- });
718
- }
719
- processLayers(e, t) {
720
- e.tables.LAYER.entries.forEach((n) => {
721
- const r = new B();
722
- r.colorIndex = n.colorIndex;
723
- const i = new Oe({
724
- name: n.name,
725
- standardFlags: n.standardFlag,
726
- linetype: n.lineType,
727
- lineWeight: n.lineweight,
728
- isOff: n.off,
729
- color: r,
730
- isPlottable: n.plotFlag != 0
731
- });
732
- this.processCommonTableEntryAttrs(n, i), t.tables.layerTable.add(i);
733
- });
734
- }
735
- processViewports(e, t) {
736
- e.tables.VPORT.entries.forEach((n) => {
737
- const r = new ke();
738
- this.processCommonTableEntryAttrs(n, r), n.circleSides && (r.circleSides = n.circleSides), r.standardFlag = n.standardFlag, r.center.copy(n.center ?? V), r.lowerLeftCorner.copy(n.lowerLeftCorner ?? Ne), r.upperRightCorner.copy(n.upperRightCorner ?? Re), n.snapBasePoint && r.snapBase.copy(n.snapBasePoint), n.snapRotationAngle && (r.snapAngle = n.snapRotationAngle), n.snapSpacing && r.snapIncrements.copy(n.snapSpacing), n.majorGridLines && (r.gridMajor = n.majorGridLines), n.gridSpacing && r.gridIncrements.copy(n.gridSpacing), n.backgroundObjectId && (r.backgroundObjectId = n.backgroundObjectId), r.gsView.center.copy(n.center ?? V), r.gsView.viewDirectionFromTarget.copy(
739
- n.viewDirectionFromTarget ?? Ve
740
- ), r.gsView.viewTarget.copy(
741
- n.viewTarget ?? Fe
742
- ), n.lensLength && (r.gsView.lensLength = n.lensLength), n.frontClippingPlane && (r.gsView.frontClippingPlane = n.frontClippingPlane), n.backClippingPlane && (r.gsView.backClippingPlane = n.backClippingPlane), n.viewHeight && (r.gsView.viewHeight = n.viewHeight), n.viewTwistAngle && (r.gsView.viewTwistAngle = n.viewTwistAngle), n.frozenLayers && (r.gsView.frozenLayers = n.frozenLayers), n.styleSheet && (r.gsView.styleSheet = n.styleSheet), n.renderMode && (r.gsView.renderMode = n.renderMode), n.viewMode && (r.gsView.viewMode = n.viewMode), n.ucsIconSetting && (r.gsView.ucsIconSetting = n.ucsIconSetting), n.ucsOrigin && r.gsView.ucsOrigin.copy(n.ucsOrigin), n.ucsXAxis && r.gsView.ucsXAxis.copy(n.ucsXAxis), n.ucsYAxis && r.gsView.ucsYAxis.copy(n.ucsYAxis), n.orthographicType && (r.gsView.orthographicType = n.orthographicType), n.shadePlotSetting && (r.gsView.shadePlotSetting = n.shadePlotSetting), n.shadePlotObjectId && (r.gsView.shadePlotObjectId = n.shadePlotObjectId), n.visualStyleObjectId && (r.gsView.visualStyleObjectId = n.visualStyleObjectId), n.isDefaultLightingOn && (r.gsView.isDefaultLightingOn = n.isDefaultLightingOn), n.defaultLightingType && (r.gsView.defaultLightingType = n.defaultLightingType), n.brightness && (r.gsView.brightness = n.brightness), n.contrast && (r.gsView.contrast = n.contrast), n.ambientColor && (r.gsView.ambientColor = n.ambientColor), t.tables.viewportTable.add(r);
743
- });
744
- }
745
- processBlockTables(e, t) {
746
- e.tables.BLOCK_RECORD.entries.forEach((n) => {
747
- let r = t.tables.blockTable.getAt(n.name);
748
- r || (r = new Be(), r.objectId = n.handle, r.name = n.name, r.ownerId = n.ownerHandle, r.origin.copy(n.basePoint), r.layoutId = n.layout, r.blockInsertUnits = n.insertionUnits, r.explodability = n.explodability, r.blockScaling = n.scalability, n.bmpPreview && (r.bmpPreview = n.bmpPreview), t.tables.blockTable.add(r)), !r.isModelSapce && n.entities && n.entities.length > 0 && this.processEntitiesInBlock(n.entities, r);
749
- });
750
- }
751
- processBlocks(e, t) {
752
- }
753
- async processEntitiesInBlock(e, t) {
754
- const o = new F(), n = e.length, r = [];
755
- for (let i = 0; i < n; i++) {
756
- const a = e[i], s = o.convert(a);
757
- s && r.push(s);
758
- }
759
- t.appendEntity(r);
760
- }
761
- async processEntities(e, t, o, n, r) {
762
- const i = new F();
763
- let a = [];
764
- e.tables.BLOCK_RECORD.entries.forEach((l) => {
765
- this.isModelSpace(l.name) && (a = l.entities);
766
- });
767
- const s = a.length, c = new He(
768
- s,
769
- 100 - n.value,
770
- o
771
- );
772
- this.config.convertByEntityType && (a = this.groupAndFlattenByType(a));
773
- const d = t.tables.blockTable.modelSpace;
774
- await c.processChunk(async (l, f) => {
775
- const p = [];
776
- for (let u = l; u < f; u++) {
777
- const g = a[u], y = i.convert(g);
778
- y && p.push(y);
779
- }
780
- if (d.appendEntity(p), r) {
781
- let u = n.value + f / s * (100 - n.value);
782
- u > 100 && (u = 100), await r(u, "ENTITY", "IN-PROGRESS");
783
- }
784
- });
785
- }
786
- processHeader(e, t) {
787
- const o = e.header;
788
- o.CECOLOR && (o.CECOLOR.index >= 0 && o.CECOLOR.index <= 256 ? t.cecolor.colorIndex = o.CECOLOR.index : t.cecolor.setRGBValue(o.CECOLOR.rgb)), t.angbase = o.ANGBASE ?? 0, t.angdir = o.ANGDIR ?? 0, t.aunits = o.AUNITS ?? 0, o.AUPREC != null && (t.auprec = o.AUPREC), o.LUNITS != null && (t.lunits = o.LUNITS), o.LUPREC != null && (t.luprec = o.LUPREC), t.celtype = o.CELTYPE ?? We, t.celtscale = o.CELTSCALE ?? 1, t.ltscale = o.LTSCALE ?? 1, o.EXTMAX && (t.extmax = o.EXTMAX), o.EXTMIN && (t.extmin = o.EXTMIN), t.insunits = o.INSUNITS ?? 1, t.pdmode = o.PDMODE ?? 0, t.pdsize = o.PDSIZE ?? 0, t.textstyle = o.TEXTSTYLE ?? R;
789
- }
790
- processCommonTableEntryAttrs(e, t) {
791
- t.name = e.name, t.objectId = e.handle, e.ownerHandle != null && (t.ownerId = e.ownerHandle);
792
- }
793
- processObjects(e, t) {
794
- this.processLayouts(e, t), this.processImageDefs(e, t);
795
- }
796
- processLayouts(e, t) {
797
- const o = t.objects.layout;
798
- e.objects.LAYOUT.forEach((r) => {
799
- const i = new je();
800
- i.layoutName = r.layoutName, i.tabOrder = r.tabOrder;
801
- const a = t.tables.blockTable.newIterator();
802
- i.objectId = r.handle;
803
- for (const s of a)
804
- if (s.layoutId === i.objectId) {
805
- i.blockTableRecordId = s.objectId;
806
- break;
807
- }
808
- i.blockTableRecordId || r.layoutName === "Model" && (i.blockTableRecordId = t.tables.blockTable.modelSpace.objectId), i.limits.min.copy(r.minLimit), i.limits.max.copy(r.maxLimit), i.extents.min.copy(r.minExtent), i.extents.max.copy(r.maxExtent), r.viewportId && i.viewportArray.push(r.viewportId), this.processCommonObjectAttrs(r, i), o.setAt(i.layoutName, i);
809
- });
810
- }
811
- processImageDefs(e, t) {
812
- const o = t.objects.imageDefinition;
813
- e.objects.IMAGEDEF.forEach((r) => {
814
- const i = new ze();
815
- i.sourceFileName = r.fileName, this.processCommonObjectAttrs(r, i), o.setAt(i.objectId, i);
816
- });
817
- }
818
- processCommonObjectAttrs(e, t) {
819
- t.objectId = e.handle, e.ownerHandle != null && (t.ownerId = e.ownerHandle);
820
- }
821
- groupAndFlattenByType(e) {
822
- const t = {}, o = [];
823
- for (const n of e)
824
- t[n.type] || (t[n.type] = [], o.push(n.type)), t[n.type].push(n);
825
- return o.flatMap((n) => t[n]);
826
- }
827
- isModelSpace(e) {
828
- return e && e.toUpperCase() == Ue;
829
- }
830
- }
831
- export {
832
- _e as AcDbLibreDwgConverter
833
- };