@mlightcad/data-model 1.7.28 → 1.7.30

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.
Files changed (76) hide show
  1. package/dist/data-model.cjs +7 -4
  2. package/dist/data-model.js +15760 -8896
  3. package/dist/dxf-parser-worker.js +325 -304
  4. package/lib/converter/AcDbDxfConverter.d.ts +1 -0
  5. package/lib/converter/AcDbDxfConverter.d.ts.map +1 -1
  6. package/lib/converter/AcDbDxfConverter.js +20 -1
  7. package/lib/converter/AcDbDxfConverter.js.map +1 -1
  8. package/lib/converter/AcDbEntitiyConverter.d.ts.map +1 -1
  9. package/lib/converter/AcDbEntitiyConverter.js +18 -42
  10. package/lib/converter/AcDbEntitiyConverter.js.map +1 -1
  11. package/lib/converter/AcDbObjectConverter.d.ts.map +1 -1
  12. package/lib/converter/AcDbObjectConverter.js +30 -11
  13. package/lib/converter/AcDbObjectConverter.js.map +1 -1
  14. package/lib/database/AcDbBlockTableRecord.d.ts.map +1 -1
  15. package/lib/database/AcDbBlockTableRecord.js +1 -0
  16. package/lib/database/AcDbBlockTableRecord.js.map +1 -1
  17. package/lib/database/AcDbDatabase.d.ts +38 -0
  18. package/lib/database/AcDbDatabase.d.ts.map +1 -1
  19. package/lib/database/AcDbDatabase.js +193 -27
  20. package/lib/database/AcDbDatabase.js.map +1 -1
  21. package/lib/database/AcDbSysVarManager.d.ts.map +1 -1
  22. package/lib/database/AcDbSysVarManager.js +28 -1
  23. package/lib/database/AcDbSysVarManager.js.map +1 -1
  24. package/lib/database/AcDbSystemVariables.d.ts +7 -1
  25. package/lib/database/AcDbSystemVariables.d.ts.map +1 -1
  26. package/lib/database/AcDbSystemVariables.js +6 -0
  27. package/lib/database/AcDbSystemVariables.js.map +1 -1
  28. package/lib/entity/AcDbMLeader.d.ts +200 -7
  29. package/lib/entity/AcDbMLeader.d.ts.map +1 -1
  30. package/lib/entity/AcDbMLeader.js +456 -25
  31. package/lib/entity/AcDbMLeader.js.map +1 -1
  32. package/lib/entity/AcDbMLine.d.ts +548 -0
  33. package/lib/entity/AcDbMLine.d.ts.map +1 -1
  34. package/lib/entity/AcDbMLine.js +986 -24
  35. package/lib/entity/AcDbMLine.js.map +1 -1
  36. package/lib/misc/AcDbConstants.d.ts +14 -0
  37. package/lib/misc/AcDbConstants.d.ts.map +1 -1
  38. package/lib/misc/AcDbConstants.js +14 -0
  39. package/lib/misc/AcDbConstants.js.map +1 -1
  40. package/lib/misc/AcDbMLeaderStyleColorCodec.d.ts +59 -0
  41. package/lib/misc/AcDbMLeaderStyleColorCodec.d.ts.map +1 -0
  42. package/lib/misc/AcDbMLeaderStyleColorCodec.js +101 -0
  43. package/lib/misc/AcDbMLeaderStyleColorCodec.js.map +1 -0
  44. package/lib/misc/index.d.ts +2 -0
  45. package/lib/misc/index.d.ts.map +1 -1
  46. package/lib/misc/index.js +2 -0
  47. package/lib/misc/index.js.map +1 -1
  48. package/lib/misc/pat/AcDbPatDefinition.d.ts +148 -0
  49. package/lib/misc/pat/AcDbPatDefinition.d.ts.map +1 -0
  50. package/lib/misc/pat/AcDbPatDefinition.js +2 -0
  51. package/lib/misc/pat/AcDbPatDefinition.js.map +1 -0
  52. package/lib/misc/pat/AcDbPatParser.d.ts +93 -0
  53. package/lib/misc/pat/AcDbPatParser.d.ts.map +1 -0
  54. package/lib/misc/pat/AcDbPatParser.js +245 -0
  55. package/lib/misc/pat/AcDbPatParser.js.map +1 -0
  56. package/lib/misc/pat/AcDbPatPredefined.d.ts +10 -0
  57. package/lib/misc/pat/AcDbPatPredefined.d.ts.map +1 -0
  58. package/lib/misc/pat/AcDbPatPredefined.js +5960 -0
  59. package/lib/misc/pat/AcDbPatPredefined.js.map +1 -0
  60. package/lib/misc/pat/AcDbPatSvgRenderer.d.ts +91 -0
  61. package/lib/misc/pat/AcDbPatSvgRenderer.d.ts.map +1 -0
  62. package/lib/misc/pat/AcDbPatSvgRenderer.js +287 -0
  63. package/lib/misc/pat/AcDbPatSvgRenderer.js.map +1 -0
  64. package/lib/misc/pat/index.d.ts +5 -0
  65. package/lib/misc/pat/index.d.ts.map +1 -0
  66. package/lib/misc/pat/index.js +5 -0
  67. package/lib/misc/pat/index.js.map +1 -0
  68. package/lib/object/AcDbMLeaderStyle.d.ts +9 -8
  69. package/lib/object/AcDbMLeaderStyle.d.ts.map +1 -1
  70. package/lib/object/AcDbMLeaderStyle.js +11 -9
  71. package/lib/object/AcDbMLeaderStyle.js.map +1 -1
  72. package/lib/object/AcDbMlineStyle.d.ts +5 -4
  73. package/lib/object/AcDbMlineStyle.d.ts.map +1 -1
  74. package/lib/object/AcDbMlineStyle.js +12 -18
  75. package/lib/object/AcDbMlineStyle.js.map +1 -1
  76. package/package.json +5 -5
@@ -13,6 +13,17 @@ var __extends = (this && this.__extends) || (function () {
13
13
  d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
14
14
  };
15
15
  })();
16
+ var __assign = (this && this.__assign) || function () {
17
+ __assign = Object.assign || function(t) {
18
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
19
+ s = arguments[i];
20
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
21
+ t[p] = s[p];
22
+ }
23
+ return t;
24
+ };
25
+ return __assign.apply(this, arguments);
26
+ };
16
27
  var __read = (this && this.__read) || function (o, n) {
17
28
  var m = typeof Symbol === "function" && o[Symbol.iterator];
18
29
  if (!m) return o;
@@ -49,16 +60,25 @@ var __values = (this && this.__values) || function(o) {
49
60
  };
50
61
  throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
51
62
  };
52
- import { AcCmColor } from '@mlightcad/common';
53
- import { AcGeBox3d, AcGePoint3d, AcGeVector3d } from '@mlightcad/geometry-engine';
63
+ import { AcGeArea2d, AcGeBox3d, AcGeCircArc3d, AcGePoint3d, AcGePolyline2d, AcGeVector3d } from '@mlightcad/geometry-engine';
64
+ import { ByBlock, ByLayer, DEFAULT_LINE_TYPE, DEFAULT_MLINE_STYLE } from '../misc';
54
65
  import { AcDbEntity } from './AcDbEntity';
55
66
  /**
56
67
  * Defines MLINE justification relative to the style element offsets.
57
68
  */
58
69
  export var AcDbMLineJustification;
59
70
  (function (AcDbMLineJustification) {
71
+ /**
72
+ * Places all style elements below or on the reference path.
73
+ */
60
74
  AcDbMLineJustification[AcDbMLineJustification["Top"] = 0] = "Top";
75
+ /**
76
+ * Centers style elements around the reference path.
77
+ */
61
78
  AcDbMLineJustification[AcDbMLineJustification["Zero"] = 1] = "Zero";
79
+ /**
80
+ * Places all style elements above or on the reference path.
81
+ */
62
82
  AcDbMLineJustification[AcDbMLineJustification["Bottom"] = 2] = "Bottom";
63
83
  })(AcDbMLineJustification || (AcDbMLineJustification = {}));
64
84
  /**
@@ -66,19 +86,72 @@ export var AcDbMLineJustification;
66
86
  */
67
87
  export var AcDbMLineFlags;
68
88
  (function (AcDbMLineFlags) {
89
+ /**
90
+ * Indicates the MLINE currently contains at least one segment vertex.
91
+ */
69
92
  AcDbMLineFlags[AcDbMLineFlags["HasVertex"] = 1] = "HasVertex";
93
+ /**
94
+ * Indicates the MLINE should be treated as a closed loop.
95
+ */
70
96
  AcDbMLineFlags[AcDbMLineFlags["Closed"] = 2] = "Closed";
97
+ /**
98
+ * Suppresses cap geometry at the start of the MLINE.
99
+ */
71
100
  AcDbMLineFlags[AcDbMLineFlags["SuppressStartCaps"] = 4] = "SuppressStartCaps";
101
+ /**
102
+ * Suppresses cap geometry at the end of the MLINE.
103
+ */
72
104
  AcDbMLineFlags[AcDbMLineFlags["SuppressEndCaps"] = 8] = "SuppressEndCaps";
73
105
  })(AcDbMLineFlags || (AcDbMLineFlags = {}));
106
+ /**
107
+ * Bit flags used by MLINESTYLE objects.
108
+ */
109
+ var AcDbMLineStyleFlags;
110
+ (function (AcDbMLineStyleFlags) {
111
+ /**
112
+ * Enables fill rendering between the outer and inner style elements.
113
+ */
114
+ AcDbMLineStyleFlags[AcDbMLineStyleFlags["FillOn"] = 1] = "FillOn";
115
+ /**
116
+ * Enables drawing miter connector lines at polyline joints.
117
+ */
118
+ AcDbMLineStyleFlags[AcDbMLineStyleFlags["DisplayMiters"] = 2] = "DisplayMiters";
119
+ /**
120
+ * Enables square-line start cap.
121
+ */
122
+ AcDbMLineStyleFlags[AcDbMLineStyleFlags["StartSquareCap"] = 16] = "StartSquareCap";
123
+ /**
124
+ * Enables inner-arc start cap pairs.
125
+ */
126
+ AcDbMLineStyleFlags[AcDbMLineStyleFlags["StartInnerArcs"] = 32] = "StartInnerArcs";
127
+ /**
128
+ * Enables outer-arc start cap.
129
+ */
130
+ AcDbMLineStyleFlags[AcDbMLineStyleFlags["StartRoundCap"] = 64] = "StartRoundCap";
131
+ /**
132
+ * Enables square-line end cap.
133
+ */
134
+ AcDbMLineStyleFlags[AcDbMLineStyleFlags["EndSquareCap"] = 256] = "EndSquareCap";
135
+ /**
136
+ * Enables inner-arc end cap pairs.
137
+ */
138
+ AcDbMLineStyleFlags[AcDbMLineStyleFlags["EndInnerArcs"] = 512] = "EndInnerArcs";
139
+ /**
140
+ * Enables outer-arc end cap.
141
+ */
142
+ AcDbMLineStyleFlags[AcDbMLineStyleFlags["EndRoundCap"] = 1024] = "EndRoundCap";
143
+ })(AcDbMLineStyleFlags || (AcDbMLineStyleFlags = {}));
74
144
  /**
75
145
  * Represents the AutoCAD MLINE entity.
76
146
  */
77
147
  var AcDbMLine = /** @class */ (function (_super) {
78
148
  __extends(AcDbMLine, _super);
149
+ /**
150
+ * Creates a new MLINE entity initialized with AutoCAD-compatible defaults.
151
+ */
79
152
  function AcDbMLine() {
80
153
  var _this = _super.call(this) || this;
81
- _this._styleName = 'STANDARD';
154
+ _this._styleName = '';
82
155
  _this._styleObjectHandle = '';
83
156
  _this._scale = 1;
84
157
  _this._justification = AcDbMLineJustification.Zero;
@@ -90,6 +163,9 @@ var AcDbMLine = /** @class */ (function (_super) {
90
163
  return _this;
91
164
  }
92
165
  Object.defineProperty(AcDbMLine.prototype, "dxfTypeName", {
166
+ /**
167
+ * DXF entity type token written to or read from drawing files.
168
+ */
93
169
  get: function () {
94
170
  return 'MLINE';
95
171
  },
@@ -97,9 +173,19 @@ var AcDbMLine = /** @class */ (function (_super) {
97
173
  configurable: true
98
174
  });
99
175
  Object.defineProperty(AcDbMLine.prototype, "styleName", {
176
+ /**
177
+ * Gets the style name used to resolve the MLINE style object.
178
+ *
179
+ * @returns Current style name.
180
+ */
100
181
  get: function () {
101
- return this._styleName;
182
+ return this._styleName || this.getDefaultStyleName();
102
183
  },
184
+ /**
185
+ * Sets the style name used to resolve the MLINE style object.
186
+ *
187
+ * @param value New style name.
188
+ */
103
189
  set: function (value) {
104
190
  this._styleName = value;
105
191
  },
@@ -107,9 +193,19 @@ var AcDbMLine = /** @class */ (function (_super) {
107
193
  configurable: true
108
194
  });
109
195
  Object.defineProperty(AcDbMLine.prototype, "styleObjectHandle", {
196
+ /**
197
+ * Gets the handle of the referenced MLINESTYLE object.
198
+ *
199
+ * @returns Style object handle.
200
+ */
110
201
  get: function () {
111
202
  return this._styleObjectHandle;
112
203
  },
204
+ /**
205
+ * Sets the handle of the referenced MLINESTYLE object.
206
+ *
207
+ * @param value Style object handle.
208
+ */
113
209
  set: function (value) {
114
210
  this._styleObjectHandle = value;
115
211
  },
@@ -117,9 +213,19 @@ var AcDbMLine = /** @class */ (function (_super) {
117
213
  configurable: true
118
214
  });
119
215
  Object.defineProperty(AcDbMLine.prototype, "scale", {
216
+ /**
217
+ * Gets the global scale factor applied to style offsets.
218
+ *
219
+ * @returns MLINE scale.
220
+ */
120
221
  get: function () {
121
222
  return this._scale;
122
223
  },
224
+ /**
225
+ * Sets the global scale factor applied to style offsets.
226
+ *
227
+ * @param value MLINE scale.
228
+ */
123
229
  set: function (value) {
124
230
  this._scale = value;
125
231
  },
@@ -127,9 +233,19 @@ var AcDbMLine = /** @class */ (function (_super) {
127
233
  configurable: true
128
234
  });
129
235
  Object.defineProperty(AcDbMLine.prototype, "justification", {
236
+ /**
237
+ * Gets the current justification mode.
238
+ *
239
+ * @returns Justification enum value.
240
+ */
130
241
  get: function () {
131
242
  return this._justification;
132
243
  },
244
+ /**
245
+ * Sets the current justification mode.
246
+ *
247
+ * @param value Justification enum value.
248
+ */
133
249
  set: function (value) {
134
250
  this._justification = value;
135
251
  },
@@ -137,9 +253,19 @@ var AcDbMLine = /** @class */ (function (_super) {
137
253
  configurable: true
138
254
  });
139
255
  Object.defineProperty(AcDbMLine.prototype, "flags", {
256
+ /**
257
+ * Gets the raw MLINE bit flags.
258
+ *
259
+ * @returns Bitwise combination of {@link AcDbMLineFlags}.
260
+ */
140
261
  get: function () {
141
262
  return this._flags;
142
263
  },
264
+ /**
265
+ * Sets the raw MLINE bit flags.
266
+ *
267
+ * @param value Bitwise combination of {@link AcDbMLineFlags}.
268
+ */
143
269
  set: function (value) {
144
270
  this._flags = value;
145
271
  },
@@ -147,9 +273,20 @@ var AcDbMLine = /** @class */ (function (_super) {
147
273
  configurable: true
148
274
  });
149
275
  Object.defineProperty(AcDbMLine.prototype, "styleCount", {
276
+ /**
277
+ * Gets the number of style elements expected by the entity.
278
+ *
279
+ * @returns Style element count.
280
+ */
150
281
  get: function () {
151
282
  return this._styleCount;
152
283
  },
284
+ /**
285
+ * Sets the style element count.
286
+ * Negative values are clamped to `0`.
287
+ *
288
+ * @param value Requested style element count.
289
+ */
153
290
  set: function (value) {
154
291
  this._styleCount = Math.max(0, value);
155
292
  },
@@ -157,9 +294,19 @@ var AcDbMLine = /** @class */ (function (_super) {
157
294
  configurable: true
158
295
  });
159
296
  Object.defineProperty(AcDbMLine.prototype, "startPosition", {
297
+ /**
298
+ * Gets the MLINE start point in world coordinates.
299
+ *
300
+ * @returns Start point instance.
301
+ */
160
302
  get: function () {
161
303
  return this._startPosition;
162
304
  },
305
+ /**
306
+ * Sets the MLINE start point in world coordinates.
307
+ *
308
+ * @param value New start point.
309
+ */
163
310
  set: function (value) {
164
311
  this._startPosition.copy(value);
165
312
  },
@@ -167,9 +314,19 @@ var AcDbMLine = /** @class */ (function (_super) {
167
314
  configurable: true
168
315
  });
169
316
  Object.defineProperty(AcDbMLine.prototype, "normal", {
317
+ /**
318
+ * Gets the MLINE plane normal.
319
+ *
320
+ * @returns Normal vector instance.
321
+ */
170
322
  get: function () {
171
323
  return this._normal;
172
324
  },
325
+ /**
326
+ * Sets the MLINE plane normal.
327
+ *
328
+ * @param value New normal vector.
329
+ */
173
330
  set: function (value) {
174
331
  this._normal.copy(value);
175
332
  },
@@ -177,10 +334,22 @@ var AcDbMLine = /** @class */ (function (_super) {
177
334
  configurable: true
178
335
  });
179
336
  Object.defineProperty(AcDbMLine.prototype, "segments", {
337
+ /**
338
+ * Gets a deep-cloned snapshot of all segments.
339
+ * Mutating the returned array or objects will not affect internal state.
340
+ *
341
+ * @returns Cloned segment collection.
342
+ */
180
343
  get: function () {
181
344
  var _this = this;
182
345
  return this._segments.map(function (segment) { return _this.cloneSegment(segment); });
183
346
  },
347
+ /**
348
+ * Replaces all segments using normalized internal copies.
349
+ * Also updates the internal `HasVertex` flag.
350
+ *
351
+ * @param value Segment list to normalize and store.
352
+ */
184
353
  set: function (value) {
185
354
  var _this = this;
186
355
  this._segments = value.map(function (segment) { return _this.createSegment(segment); });
@@ -190,6 +359,11 @@ var AcDbMLine = /** @class */ (function (_super) {
190
359
  configurable: true
191
360
  });
192
361
  Object.defineProperty(AcDbMLine.prototype, "vertexCount", {
362
+ /**
363
+ * Gets the number of stored segment vertices.
364
+ *
365
+ * @returns Vertex count.
366
+ */
193
367
  get: function () {
194
368
  return this._segments.length;
195
369
  },
@@ -197,9 +371,19 @@ var AcDbMLine = /** @class */ (function (_super) {
197
371
  configurable: true
198
372
  });
199
373
  Object.defineProperty(AcDbMLine.prototype, "closed", {
374
+ /**
375
+ * Indicates whether the MLINE is closed.
376
+ *
377
+ * @returns `true` when the `Closed` flag is set.
378
+ */
200
379
  get: function () {
201
380
  return (this._flags & AcDbMLineFlags.Closed) !== 0;
202
381
  },
382
+ /**
383
+ * Enables or disables closed-loop behavior.
384
+ *
385
+ * @param value `true` to close the path, otherwise `false`.
386
+ */
203
387
  set: function (value) {
204
388
  this.setFlag(AcDbMLineFlags.Closed, value);
205
389
  },
@@ -207,9 +391,19 @@ var AcDbMLine = /** @class */ (function (_super) {
207
391
  configurable: true
208
392
  });
209
393
  Object.defineProperty(AcDbMLine.prototype, "suppressStartCaps", {
394
+ /**
395
+ * Indicates whether start caps are suppressed during rendering.
396
+ *
397
+ * @returns `true` when the `SuppressStartCaps` flag is set.
398
+ */
210
399
  get: function () {
211
400
  return (this._flags & AcDbMLineFlags.SuppressStartCaps) !== 0;
212
401
  },
402
+ /**
403
+ * Enables or disables start cap suppression.
404
+ *
405
+ * @param value `true` to suppress start caps.
406
+ */
213
407
  set: function (value) {
214
408
  this.setFlag(AcDbMLineFlags.SuppressStartCaps, value);
215
409
  },
@@ -217,24 +411,48 @@ var AcDbMLine = /** @class */ (function (_super) {
217
411
  configurable: true
218
412
  });
219
413
  Object.defineProperty(AcDbMLine.prototype, "suppressEndCaps", {
414
+ /**
415
+ * Indicates whether end caps are suppressed during rendering.
416
+ *
417
+ * @returns `true` when the `SuppressEndCaps` flag is set.
418
+ */
220
419
  get: function () {
221
420
  return (this._flags & AcDbMLineFlags.SuppressEndCaps) !== 0;
222
421
  },
422
+ /**
423
+ * Enables or disables end cap suppression.
424
+ *
425
+ * @param value `true` to suppress end caps.
426
+ */
223
427
  set: function (value) {
224
428
  this.setFlag(AcDbMLineFlags.SuppressEndCaps, value);
225
429
  },
226
430
  enumerable: false,
227
431
  configurable: true
228
432
  });
433
+ /**
434
+ * Appends one segment to the MLINE.
435
+ * The segment is normalized into internal geometry instances.
436
+ *
437
+ * @param segment Segment payload to append.
438
+ */
229
439
  AcDbMLine.prototype.appendSegment = function (segment) {
230
440
  this._segments.push(this.createSegment(segment));
231
441
  this.updateHasVertexFlag();
232
442
  };
443
+ /**
444
+ * Removes all segments and clears the `HasVertex` flag.
445
+ */
233
446
  AcDbMLine.prototype.clearSegments = function () {
234
447
  this._segments = [];
235
448
  this.updateHasVertexFlag();
236
449
  };
237
450
  Object.defineProperty(AcDbMLine.prototype, "geometricExtents", {
451
+ /**
452
+ * Computes a bounding box from renderable MLINE geometry.
453
+ *
454
+ * @returns Axis-aligned 3D extents box.
455
+ */
238
456
  get: function () {
239
457
  var points = this.collectGeometryPoints();
240
458
  var box = new AcGeBox3d();
@@ -243,6 +461,14 @@ var AcDbMLine = /** @class */ (function (_super) {
243
461
  enumerable: false,
244
462
  configurable: true
245
463
  });
464
+ /**
465
+ * Applies a transformation matrix to the full MLINE geometry.
466
+ * Points are transformed directly, while vectors are transformed without
467
+ * introducing translation components.
468
+ *
469
+ * @param matrix Matrix to apply.
470
+ * @returns The same entity instance for chaining.
471
+ */
246
472
  AcDbMLine.prototype.transformBy = function (matrix) {
247
473
  var _this = this;
248
474
  this._startPosition.applyMatrix4(matrix);
@@ -255,6 +481,11 @@ var AcDbMLine = /** @class */ (function (_super) {
255
481
  return this;
256
482
  };
257
483
  Object.defineProperty(AcDbMLine.prototype, "properties", {
484
+ /**
485
+ * Exposes editable property metadata for UI/property panels.
486
+ *
487
+ * @returns Entity property definition grouped by category.
488
+ */
258
489
  get: function () {
259
490
  var _this = this;
260
491
  return {
@@ -324,6 +555,13 @@ var AcDbMLine = /** @class */ (function (_super) {
324
555
  enumerable: false,
325
556
  configurable: true
326
557
  });
558
+ /**
559
+ * Renders this MLINE into one or more graphic interface entities.
560
+ * It draws optional fill first and then style element lines.
561
+ *
562
+ * @param renderer Active graphics renderer.
563
+ * @returns A single entity, an entity group, or `undefined` when nothing is drawable.
564
+ */
327
565
  AcDbMLine.prototype.subWorldDraw = function (renderer) {
328
566
  if (this._segments.length === 0)
329
567
  return undefined;
@@ -333,6 +571,24 @@ var AcDbMLine = /** @class */ (function (_super) {
333
571
  var traits = renderer.subEntityTraits;
334
572
  var originalColor = traits.color;
335
573
  var originalRgbColor = traits.rgbColor;
574
+ var originalLineType = traits.lineType;
575
+ var originalFillType = traits.fillType;
576
+ var originalDrawOrder = traits.drawOrder;
577
+ var fillArea = this.createFillArea(mlineStyle, elementCount);
578
+ if (fillArea) {
579
+ traits.color = originalColor;
580
+ traits.rgbColor = originalRgbColor;
581
+ this.applyFillTraits(mlineStyle, traits);
582
+ traits.fillType = {
583
+ solidFill: true,
584
+ patternAngle: 0,
585
+ definitionLines: []
586
+ };
587
+ traits.drawOrder = -1;
588
+ entities.push(renderer.area(fillArea));
589
+ traits.fillType = originalFillType;
590
+ traits.drawOrder = originalDrawOrder;
591
+ }
336
592
  if (elementCount <= 0) {
337
593
  var reference = this.getReferencePath();
338
594
  if (reference.length >= 2)
@@ -342,23 +598,34 @@ var AcDbMLine = /** @class */ (function (_super) {
342
598
  for (var elementIndex = 0; elementIndex < elementCount; elementIndex++) {
343
599
  traits.color = originalColor;
344
600
  traits.rgbColor = originalRgbColor;
601
+ traits.lineType = originalLineType;
345
602
  this.applyStyleElementTraits(mlineStyle, elementIndex, traits);
346
603
  var points = this.getElementPath(elementIndex, mlineStyle);
347
604
  if (points.length >= 2) {
348
605
  entities.push(renderer.lines(points));
349
606
  }
350
607
  }
608
+ this.appendStyleDrivenJointAndCapEntities(renderer, entities, mlineStyle, elementCount, originalColor, originalRgbColor, originalLineType);
351
609
  }
352
610
  traits.color = originalColor;
353
611
  traits.rgbColor = originalRgbColor;
612
+ traits.lineType = originalLineType;
613
+ traits.fillType = originalFillType;
614
+ traits.drawOrder = originalDrawOrder;
354
615
  if (entities.length === 0)
355
616
  return undefined;
356
617
  return entities.length === 1 ? entities[0] : renderer.group(entities);
357
618
  };
619
+ /**
620
+ * Serializes MLINE-specific fields to the DXF filer.
621
+ *
622
+ * @param filer DXF writer context.
623
+ * @returns The current entity instance.
624
+ */
358
625
  AcDbMLine.prototype.dxfOutFields = function (filer) {
359
626
  _super.prototype.dxfOutFields.call(this, filer);
360
627
  filer.writeSubclassMarker('AcDbMline');
361
- filer.writeString(2, this._styleName);
628
+ filer.writeString(2, this.styleName);
362
629
  filer.writeHandle(340, this._styleObjectHandle);
363
630
  filer.writeDouble(40, this._scale);
364
631
  filer.writeInt16(70, this._justification);
@@ -384,6 +651,12 @@ var AcDbMLine = /** @class */ (function (_super) {
384
651
  });
385
652
  return this;
386
653
  };
654
+ /**
655
+ * Sets or clears a single MLINE bit flag.
656
+ *
657
+ * @param flag Flag bit to update.
658
+ * @param enabled Whether the flag should be set.
659
+ */
387
660
  AcDbMLine.prototype.setFlag = function (flag, enabled) {
388
661
  if (enabled) {
389
662
  this._flags |= flag;
@@ -392,9 +665,18 @@ var AcDbMLine = /** @class */ (function (_super) {
392
665
  this._flags &= ~flag;
393
666
  }
394
667
  };
668
+ /**
669
+ * Synchronizes the `HasVertex` flag with current segment count.
670
+ */
395
671
  AcDbMLine.prototype.updateHasVertexFlag = function () {
396
672
  this.setFlag(AcDbMLineFlags.HasVertex, this._segments.length > 0);
397
673
  };
674
+ /**
675
+ * Normalizes segment-like input into internal segment storage.
676
+ *
677
+ * @param segment Segment-like payload.
678
+ * @returns Normalized segment.
679
+ */
398
680
  AcDbMLine.prototype.createSegment = function (segment) {
399
681
  var _this = this;
400
682
  var _a, _b;
@@ -405,6 +687,12 @@ var AcDbMLine = /** @class */ (function (_super) {
405
687
  elements: (_b = (_a = segment.elements) === null || _a === void 0 ? void 0 : _a.map(function (element) { return _this.createElement(element); })) !== null && _b !== void 0 ? _b : []
406
688
  };
407
689
  };
690
+ /**
691
+ * Normalizes element-like input and infers count fields when missing.
692
+ *
693
+ * @param element Element-like payload.
694
+ * @returns Normalized element.
695
+ */
408
696
  AcDbMLine.prototype.createElement = function (element) {
409
697
  var _a, _b;
410
698
  var parameters = element.parameters ? __spreadArray([], __read(element.parameters), false) : [];
@@ -417,6 +705,12 @@ var AcDbMLine = /** @class */ (function (_super) {
417
705
  fillParameters: fillParameters
418
706
  };
419
707
  };
708
+ /**
709
+ * Produces a deep clone of one normalized segment.
710
+ *
711
+ * @param segment Source segment.
712
+ * @returns Deep-cloned segment.
713
+ */
420
714
  AcDbMLine.prototype.cloneSegment = function (segment) {
421
715
  return {
422
716
  position: segment.position.clone(),
@@ -430,6 +724,11 @@ var AcDbMLine = /** @class */ (function (_super) {
430
724
  }); })
431
725
  };
432
726
  };
727
+ /**
728
+ * Collects points that represent all drawable geometry for extents calculation.
729
+ *
730
+ * @returns Geometry point list in world coordinates.
731
+ */
433
732
  AcDbMLine.prototype.collectGeometryPoints = function () {
434
733
  var points = [this._startPosition];
435
734
  if (this._segments.length === 0)
@@ -445,37 +744,365 @@ var AcDbMLine = /** @class */ (function (_super) {
445
744
  }
446
745
  return points;
447
746
  };
747
+ /**
748
+ * Calculates how many element paths should be rendered.
749
+ * Uses the max of entity style count, style definition count, and segment data.
750
+ *
751
+ * @param mlineStyle Resolved style object, if available.
752
+ * @returns Renderable element count.
753
+ */
448
754
  AcDbMLine.prototype.getRenderableElementCount = function (mlineStyle) {
449
755
  var _a;
450
756
  var styleElementCount = (_a = mlineStyle === null || mlineStyle === void 0 ? void 0 : mlineStyle.elementCount) !== null && _a !== void 0 ? _a : 0;
451
757
  return Math.max.apply(Math, __spreadArray(__spreadArray([this._styleCount,
452
758
  styleElementCount], __read(this._segments.map(function (segment) { return segment.elements.length; })), false), [0], false));
453
759
  };
760
+ /**
761
+ * Builds the un-offset reference polyline path from start point and segments.
762
+ *
763
+ * @returns Reference path points, optionally closed when needed.
764
+ */
454
765
  AcDbMLine.prototype.getReferencePath = function () {
455
- return __spreadArray([
766
+ var points = __spreadArray([
456
767
  this._startPosition.clone()
457
768
  ], __read(this._segments.map(function (segment) { return segment.position.clone(); })), false);
769
+ return this.closePathIfNeeded(points);
458
770
  };
771
+ /**
772
+ * Computes one style element path by offsetting every segment along its miter direction.
773
+ *
774
+ * @param elementIndex Style element index to evaluate.
775
+ * @param mlineStyle Resolved style object, if available.
776
+ * @returns Offset path points, optionally closed when needed.
777
+ */
459
778
  AcDbMLine.prototype.getElementPath = function (elementIndex, mlineStyle) {
460
779
  var _this = this;
461
780
  var points = [];
462
781
  var first = this._segments[0];
463
- var startOffset = this.getElementMiterOffset(first, elementIndex, mlineStyle);
464
- points.push(this.offsetPoint(this._startPosition, first.miterDirection, startOffset));
782
+ points.push(this.getElementBoundaryPoint('start', first, elementIndex, mlineStyle));
465
783
  this._segments.forEach(function (segment) {
466
- var offset = _this.getElementMiterOffset(segment, elementIndex, mlineStyle);
467
- points.push(_this.offsetPoint(segment.position, segment.miterDirection, offset));
784
+ points.push(_this.offsetPoint(segment.position, segment.miterDirection, _this.getElementMiterOffset(segment, elementIndex, mlineStyle)));
468
785
  });
469
- return points;
786
+ points[points.length - 1] = this.getElementBoundaryPoint('end', this._segments[this._segments.length - 1], elementIndex, mlineStyle);
787
+ return this.closePathIfNeeded(points);
470
788
  };
789
+ /**
790
+ * Resolves the offset distance for an element at a specific segment.
791
+ * Prefers segment element parameters and falls back to style offsets.
792
+ *
793
+ * @param segment Segment to evaluate.
794
+ * @param elementIndex Style element index.
795
+ * @param mlineStyle Resolved style object, if available.
796
+ * @returns Miter offset distance.
797
+ */
471
798
  AcDbMLine.prototype.getElementMiterOffset = function (segment, elementIndex, mlineStyle) {
472
- var _a, _b;
799
+ var _a;
473
800
  var element = segment.elements[elementIndex];
474
801
  if ((_a = element === null || element === void 0 ? void 0 : element.parameters) === null || _a === void 0 ? void 0 : _a.length)
475
802
  return element.parameters[0];
803
+ return this.getStyleElementOffset(elementIndex, mlineStyle);
804
+ };
805
+ /**
806
+ * Resolves one element boundary point at the start/end of open MLINE paths.
807
+ *
808
+ * @param side `start` or `end`.
809
+ * @param segment Segment data used to resolve miter offset.
810
+ * @param elementIndex Style element index.
811
+ * @param mlineStyle Resolved style object, if available.
812
+ * @returns Boundary point after cap-angle cut adjustment.
813
+ */
814
+ AcDbMLine.prototype.getElementBoundaryPoint = function (side, segment, elementIndex, mlineStyle) {
815
+ var offset = this.getElementMiterOffset(segment, elementIndex, mlineStyle);
816
+ var basePoint = side === 'start' ? this._startPosition : segment.position;
817
+ var point = this.offsetPoint(basePoint, segment.miterDirection, offset);
818
+ if (!this.shouldApplyCapCutAtSide(side, mlineStyle)) {
819
+ return point;
820
+ }
821
+ var capAngle = side === 'start' ? mlineStyle === null || mlineStyle === void 0 ? void 0 : mlineStyle.startAngle : mlineStyle === null || mlineStyle === void 0 ? void 0 : mlineStyle.endAngle;
822
+ var cutDistance = this.computeCapCutDistance(offset, capAngle, side);
823
+ if (cutDistance === 0)
824
+ return point;
825
+ var direction = side === 'start'
826
+ ? this.getStartSegmentDirection()
827
+ : this.getEndSegmentDirection();
828
+ if (direction.lengthSq() === 0)
829
+ return point;
830
+ return point.add(direction.multiplyScalar(cutDistance));
831
+ };
832
+ /**
833
+ * Indicates whether cap-angle cut should be applied at the given side.
834
+ *
835
+ * @param side `start` or `end`.
836
+ * @param mlineStyle Resolved style object, if available.
837
+ * @returns `true` when side has cap components and is not suppressed.
838
+ */
839
+ AcDbMLine.prototype.shouldApplyCapCutAtSide = function (side, mlineStyle) {
840
+ if (!mlineStyle || this.closed)
841
+ return false;
842
+ if (side === 'start') {
843
+ if (this.suppressStartCaps)
844
+ return false;
845
+ return ((mlineStyle.flags &
846
+ (AcDbMLineStyleFlags.StartSquareCap |
847
+ AcDbMLineStyleFlags.StartInnerArcs |
848
+ AcDbMLineStyleFlags.StartRoundCap)) !==
849
+ 0);
850
+ }
851
+ if (this.suppressEndCaps)
852
+ return false;
853
+ return ((mlineStyle.flags &
854
+ (AcDbMLineStyleFlags.EndSquareCap |
855
+ AcDbMLineStyleFlags.EndInnerArcs |
856
+ AcDbMLineStyleFlags.EndRoundCap)) !==
857
+ 0);
858
+ };
859
+ /**
860
+ * Computes longitudinal cut distance based on cap angle and style-element offset.
861
+ *
862
+ * @param offset Element offset along miter direction.
863
+ * @param angleDegrees Cap angle in degree units.
864
+ * @param side `start` or `end`.
865
+ * @returns Signed distance to move along segment direction.
866
+ */
867
+ AcDbMLine.prototype.computeCapCutDistance = function (offset, angleDegrees, side) {
868
+ var angle = this.normalizeCapAngle(angleDegrees);
869
+ var tan = Math.tan(angle);
870
+ if (Math.abs(tan) < 1e-6)
871
+ return 0;
872
+ var distance = offset / tan;
873
+ return side === 'start' ? distance : distance;
874
+ };
875
+ /**
876
+ * Normalizes cap angle from DXF degree units to radians.
877
+ *
878
+ * @param angleDegrees Cap angle in degree units.
879
+ * @returns Safe radian value in `(0, PI)` with 90-degree fallback.
880
+ */
881
+ AcDbMLine.prototype.normalizeCapAngle = function (angleDegrees) {
882
+ if (angleDegrees == null || !Number.isFinite(angleDegrees)) {
883
+ return Math.PI / 2;
884
+ }
885
+ var degrees = angleDegrees % 180;
886
+ if (degrees < 0)
887
+ degrees += 180;
888
+ if (degrees < 1 || degrees > 179) {
889
+ degrees = 90;
890
+ }
891
+ return (degrees * Math.PI) / 180;
892
+ };
893
+ /**
894
+ * Resolves forward direction at MLINE start.
895
+ *
896
+ * @returns Unit vector along the first segment.
897
+ */
898
+ AcDbMLine.prototype.getStartSegmentDirection = function () {
899
+ var first = this._segments[0];
900
+ var direction = new AcGeVector3d();
901
+ if (first) {
902
+ // Prefer actual geometry direction. The serialized first segment direction can be noisy
903
+ // in some files and may not match the true start-edge direction.
904
+ direction.subVectors(first.position, this._startPosition);
905
+ if (direction.lengthSq() === 0) {
906
+ direction.copy(first.direction);
907
+ }
908
+ }
909
+ if (direction.lengthSq() > 0)
910
+ direction.normalize();
911
+ return direction;
912
+ };
913
+ /**
914
+ * Resolves forward direction at MLINE end.
915
+ *
916
+ * @returns Unit vector along the last visible segment.
917
+ */
918
+ AcDbMLine.prototype.getEndSegmentDirection = function () {
919
+ var last = this._segments[this._segments.length - 1];
920
+ if (!last)
921
+ return new AcGeVector3d();
922
+ var direction = new AcGeVector3d();
923
+ var previousPoint = this._segments.length > 1
924
+ ? this._segments[this._segments.length - 2].position
925
+ : this._startPosition;
926
+ // Prefer actual geometry direction. Some DXF producers write a final segment direction
927
+ // that does not represent the visible last edge, which flips end caps.
928
+ direction.subVectors(last.position, previousPoint);
929
+ if (direction.lengthSq() === 0) {
930
+ direction.copy(last.direction);
931
+ }
932
+ if (direction.lengthSq() > 0)
933
+ direction.normalize();
934
+ return direction;
935
+ };
936
+ /**
937
+ * Creates a fill area between outermost and innermost element paths when style fill is enabled.
938
+ *
939
+ * @param mlineStyle Resolved style object.
940
+ * @param elementCount Total renderable element count.
941
+ * @returns Fill area polygon(s), or `undefined` when fill cannot be formed.
942
+ */
943
+ AcDbMLine.prototype.createFillArea = function (mlineStyle, elementCount) {
944
+ if (!mlineStyle ||
945
+ (mlineStyle.flags & AcDbMLineStyleFlags.FillOn) === 0 ||
946
+ elementCount < 2) {
947
+ return undefined;
948
+ }
949
+ var boundary = this.getFillBoundaryElementIndices(elementCount, mlineStyle);
950
+ if (!boundary)
951
+ return undefined;
952
+ var outerPath = this.getElementPath(boundary.outerIndex, mlineStyle);
953
+ var innerPath = this.getElementPath(boundary.innerIndex, mlineStyle);
954
+ var outerPoints = this.stripClosingPoint(outerPath);
955
+ var innerPoints = this.stripClosingPoint(innerPath);
956
+ if (outerPoints.length < 2 || innerPoints.length < 2) {
957
+ return undefined;
958
+ }
959
+ var area = new AcGeArea2d();
960
+ if (this.closed) {
961
+ if (outerPoints.length < 3 || innerPoints.length < 3)
962
+ return undefined;
963
+ area.add(new AcGePolyline2d(outerPoints.map(function (point) { return ({ x: point.x, y: point.y }); }), true));
964
+ area.add(new AcGePolyline2d(innerPoints.map(function (point) { return ({ x: point.x, y: point.y }); }), true));
965
+ }
966
+ else {
967
+ var ringPoints = __spreadArray(__spreadArray([], __read(outerPoints), false), __read(innerPoints.slice().reverse()), false).map(function (point) { return ({ x: point.x, y: point.y }); });
968
+ if (ringPoints.length < 3)
969
+ return undefined;
970
+ area.add(new AcGePolyline2d(ringPoints, true));
971
+ }
972
+ return area;
973
+ };
974
+ /**
975
+ * Finds the element indices that define fill boundaries by minimum and maximum reference offsets.
976
+ *
977
+ * @param elementCount Total renderable element count.
978
+ * @param mlineStyle Resolved style object, if available.
979
+ * @returns Outer/inner boundary indices, or `undefined` when not resolvable.
980
+ */
981
+ AcDbMLine.prototype.getFillBoundaryElementIndices = function (elementCount, mlineStyle) {
982
+ var minOffset = Number.POSITIVE_INFINITY;
983
+ var maxOffset = Number.NEGATIVE_INFINITY;
984
+ var minIndex = -1;
985
+ var maxIndex = -1;
986
+ for (var i = 0; i < elementCount; i++) {
987
+ var offset = this.getElementReferenceOffset(i, mlineStyle);
988
+ if (offset < minOffset) {
989
+ minOffset = offset;
990
+ minIndex = i;
991
+ }
992
+ if (offset > maxOffset) {
993
+ maxOffset = offset;
994
+ maxIndex = i;
995
+ }
996
+ }
997
+ if (minIndex < 0 || maxIndex < 0 || minIndex === maxIndex) {
998
+ return undefined;
999
+ }
1000
+ return {
1001
+ outerIndex: maxIndex,
1002
+ innerIndex: minIndex
1003
+ };
1004
+ };
1005
+ /**
1006
+ * Resolves an element's reference offset from first-segment data or style defaults.
1007
+ *
1008
+ * @param elementIndex Style element index.
1009
+ * @param mlineStyle Resolved style object, if available.
1010
+ * @returns Reference offset used for boundary comparison.
1011
+ */
1012
+ AcDbMLine.prototype.getElementReferenceOffset = function (elementIndex, mlineStyle) {
1013
+ var _a;
1014
+ var firstSegment = this._segments[0];
1015
+ if (firstSegment) {
1016
+ var element = firstSegment.elements[elementIndex];
1017
+ if ((_a = element === null || element === void 0 ? void 0 : element.parameters) === null || _a === void 0 ? void 0 : _a.length) {
1018
+ return element.parameters[0];
1019
+ }
1020
+ }
1021
+ return this.getStyleElementOffset(elementIndex, mlineStyle);
1022
+ };
1023
+ /**
1024
+ * Resolves style-defined element offset to world offset under current
1025
+ * justification and entity scale.
1026
+ *
1027
+ * @param elementIndex Style element index.
1028
+ * @param mlineStyle Resolved style object, if available.
1029
+ * @returns Final offset distance used for miter displacement.
1030
+ */
1031
+ AcDbMLine.prototype.getStyleElementOffset = function (elementIndex, mlineStyle) {
476
1032
  var styleElement = mlineStyle === null || mlineStyle === void 0 ? void 0 : mlineStyle.elements[elementIndex];
477
- return (_b = styleElement === null || styleElement === void 0 ? void 0 : styleElement.offset) !== null && _b !== void 0 ? _b : 0;
1033
+ if (!styleElement)
1034
+ return 0;
1035
+ var shift = this.getStyleJustificationShift(mlineStyle);
1036
+ return (styleElement.offset + shift) * this._scale;
1037
+ };
1038
+ /**
1039
+ * Calculates justification shift in style-offset space.
1040
+ *
1041
+ * - `Zero`: shift = 0
1042
+ * - `Top`: highest style offset is moved to 0
1043
+ * - `Bottom`: lowest style offset is moved to 0
1044
+ *
1045
+ * @param mlineStyle Resolved style object, if available.
1046
+ * @returns Offset shift before scaling.
1047
+ */
1048
+ AcDbMLine.prototype.getStyleJustificationShift = function (mlineStyle) {
1049
+ var e_1, _a;
1050
+ var _b;
1051
+ var elements = (_b = mlineStyle === null || mlineStyle === void 0 ? void 0 : mlineStyle.elements) !== null && _b !== void 0 ? _b : [];
1052
+ if (elements.length <= 0)
1053
+ return 0;
1054
+ var minOffset = Number.POSITIVE_INFINITY;
1055
+ var maxOffset = Number.NEGATIVE_INFINITY;
1056
+ try {
1057
+ for (var elements_1 = __values(elements), elements_1_1 = elements_1.next(); !elements_1_1.done; elements_1_1 = elements_1.next()) {
1058
+ var element = elements_1_1.value;
1059
+ var offset = element.offset;
1060
+ if (offset < minOffset)
1061
+ minOffset = offset;
1062
+ if (offset > maxOffset)
1063
+ maxOffset = offset;
1064
+ }
1065
+ }
1066
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
1067
+ finally {
1068
+ try {
1069
+ if (elements_1_1 && !elements_1_1.done && (_a = elements_1.return)) _a.call(elements_1);
1070
+ }
1071
+ finally { if (e_1) throw e_1.error; }
1072
+ }
1073
+ if (this._justification === AcDbMLineJustification.Top) {
1074
+ return -maxOffset;
1075
+ }
1076
+ if (this._justification === AcDbMLineJustification.Bottom) {
1077
+ return -minOffset;
1078
+ }
1079
+ return 0;
1080
+ };
1081
+ /**
1082
+ * Removes a duplicated closing vertex when the first and last points are numerically equal.
1083
+ *
1084
+ * @param points Candidate closed path.
1085
+ * @returns Path without duplicated terminal point.
1086
+ */
1087
+ AcDbMLine.prototype.stripClosingPoint = function (points) {
1088
+ if (points.length < 2)
1089
+ return points;
1090
+ var first = points[0];
1091
+ var last = points[points.length - 1];
1092
+ var epsilon = 1e-9;
1093
+ var isClosed = Math.abs(first.x - last.x) <= epsilon &&
1094
+ Math.abs(first.y - last.y) <= epsilon &&
1095
+ Math.abs(first.z - last.z) <= epsilon;
1096
+ return isClosed ? points.slice(0, -1) : points;
478
1097
  };
1098
+ /**
1099
+ * Offsets a point along a miter direction by a scalar distance.
1100
+ *
1101
+ * @param point Base point.
1102
+ * @param miterDirection Offset direction.
1103
+ * @param distance Offset distance.
1104
+ * @returns Offset point clone.
1105
+ */
479
1106
  AcDbMLine.prototype.offsetPoint = function (point, miterDirection, distance) {
480
1107
  if (distance === 0 || miterDirection.lengthSq() === 0) {
481
1108
  return point.clone();
@@ -486,6 +1113,245 @@ var AcDbMLine = /** @class */ (function (_super) {
486
1113
  .multiplyScalar(distance);
487
1114
  return point.clone().add(direction);
488
1115
  };
1116
+ /**
1117
+ * Appends the first point to the end of a path when closed mode requires an explicit closure.
1118
+ *
1119
+ * @param points Path points to inspect.
1120
+ * @returns Original or explicitly closed path array.
1121
+ */
1122
+ AcDbMLine.prototype.closePathIfNeeded = function (points) {
1123
+ if (!this.closed || points.length < 2)
1124
+ return points;
1125
+ var first = points[0];
1126
+ var last = points[points.length - 1];
1127
+ var epsilon = 1e-9;
1128
+ var isClosed = Math.abs(first.x - last.x) <= epsilon &&
1129
+ Math.abs(first.y - last.y) <= epsilon &&
1130
+ Math.abs(first.z - last.z) <= epsilon;
1131
+ if (!isClosed)
1132
+ points.push(first.clone());
1133
+ return points;
1134
+ };
1135
+ /**
1136
+ * Appends style-driven joint/cap entities after element path rendering.
1137
+ *
1138
+ * @param renderer Active graphics renderer.
1139
+ * @param entities Output entity list to append into.
1140
+ * @param mlineStyle Resolved style object, if available.
1141
+ * @param elementCount Renderable style element count.
1142
+ * @param originalColor Original trait color.
1143
+ * @param originalRgbColor Original trait RGB.
1144
+ * @param originalLineType Original trait linetype.
1145
+ */
1146
+ AcDbMLine.prototype.appendStyleDrivenJointAndCapEntities = function (renderer, entities, mlineStyle, elementCount, originalColor, originalRgbColor, originalLineType) {
1147
+ if (!mlineStyle || elementCount < 2)
1148
+ return;
1149
+ entities.push.apply(entities, __spreadArray([], __read(this.drawMiterJointEntities(renderer, mlineStyle, elementCount, originalColor, originalRgbColor, originalLineType)), false));
1150
+ entities.push.apply(entities, __spreadArray([], __read(this.drawCapEntities(renderer, mlineStyle, elementCount, originalColor, originalRgbColor, originalLineType)), false));
1151
+ };
1152
+ /**
1153
+ * Draws miter connector lines at interior joints when style enables it.
1154
+ *
1155
+ * @param renderer Active graphics renderer.
1156
+ * @param mlineStyle Resolved style object.
1157
+ * @param elementCount Renderable style element count.
1158
+ * @param originalColor Original trait color.
1159
+ * @param originalRgbColor Original trait RGB.
1160
+ * @param originalLineType Original trait linetype.
1161
+ * @returns Drawn joint entities.
1162
+ */
1163
+ AcDbMLine.prototype.drawMiterJointEntities = function (renderer, mlineStyle, elementCount, originalColor, originalRgbColor, originalLineType) {
1164
+ var _this = this;
1165
+ if (this.closed ||
1166
+ this._segments.length < 2 ||
1167
+ (mlineStyle.flags & AcDbMLineStyleFlags.DisplayMiters) === 0) {
1168
+ return [];
1169
+ }
1170
+ var entities = [];
1171
+ var traits = renderer.subEntityTraits;
1172
+ var _loop_1 = function (segmentIndex) {
1173
+ var segment = this_1._segments[segmentIndex];
1174
+ var points = Array.from({ length: elementCount }, function (_, elementIndex) {
1175
+ var offset = _this.getElementMiterOffset(segment, elementIndex, mlineStyle);
1176
+ return {
1177
+ elementIndex: elementIndex,
1178
+ offset: offset,
1179
+ point: _this.offsetPoint(segment.position, segment.miterDirection, offset)
1180
+ };
1181
+ }).sort(function (a, b) { return b.offset - a.offset; });
1182
+ for (var i = 0; i < points.length - 1; i++) {
1183
+ this_1.applyElementDrawTraits(traits, originalColor, originalRgbColor, originalLineType, mlineStyle, points[i].elementIndex);
1184
+ entities.push(renderer.lines([points[i].point, points[i + 1].point]));
1185
+ }
1186
+ };
1187
+ var this_1 = this;
1188
+ for (var segmentIndex = 0; segmentIndex < this._segments.length - 1; segmentIndex++) {
1189
+ _loop_1(segmentIndex);
1190
+ }
1191
+ return entities;
1192
+ };
1193
+ /**
1194
+ * Draws start/end cap entities according to MLINESTYLE cap flags.
1195
+ *
1196
+ * @param renderer Active graphics renderer.
1197
+ * @param mlineStyle Resolved style object.
1198
+ * @param elementCount Renderable style element count.
1199
+ * @param originalColor Original trait color.
1200
+ * @param originalRgbColor Original trait RGB.
1201
+ * @param originalLineType Original trait linetype.
1202
+ * @returns Drawn cap entities.
1203
+ */
1204
+ AcDbMLine.prototype.drawCapEntities = function (renderer, mlineStyle, elementCount, originalColor, originalRgbColor, originalLineType) {
1205
+ if (this.closed || this._segments.length <= 0)
1206
+ return [];
1207
+ var entities = [];
1208
+ entities.push.apply(entities, __spreadArray([], __read(this.drawCapEntitiesForSide(renderer, 'start', mlineStyle, elementCount, originalColor, originalRgbColor, originalLineType)), false));
1209
+ entities.push.apply(entities, __spreadArray([], __read(this.drawCapEntitiesForSide(renderer, 'end', mlineStyle, elementCount, originalColor, originalRgbColor, originalLineType)), false));
1210
+ return entities;
1211
+ };
1212
+ /**
1213
+ * Draws one-side cap entities (line/outer-arc/inner-arcs).
1214
+ *
1215
+ * @param renderer Active graphics renderer.
1216
+ * @param side `start` or `end`.
1217
+ * @param mlineStyle Resolved style object.
1218
+ * @param elementCount Renderable style element count.
1219
+ * @param originalColor Original trait color.
1220
+ * @param originalRgbColor Original trait RGB.
1221
+ * @param originalLineType Original trait linetype.
1222
+ * @returns Drawn one-side cap entities.
1223
+ */
1224
+ AcDbMLine.prototype.drawCapEntitiesForSide = function (renderer, side, mlineStyle, elementCount, originalColor, originalRgbColor, originalLineType) {
1225
+ if (side === 'start' && this.suppressStartCaps)
1226
+ return [];
1227
+ if (side === 'end' && this.suppressEndCaps)
1228
+ return [];
1229
+ var flags = mlineStyle.flags;
1230
+ var isStart = side === 'start';
1231
+ var hasSquare = isStart
1232
+ ? (flags & AcDbMLineStyleFlags.StartSquareCap) !== 0
1233
+ : (flags & AcDbMLineStyleFlags.EndSquareCap) !== 0;
1234
+ var hasOuterArc = isStart
1235
+ ? (flags & AcDbMLineStyleFlags.StartRoundCap) !== 0
1236
+ : (flags & AcDbMLineStyleFlags.EndRoundCap) !== 0;
1237
+ var hasInnerArcs = isStart
1238
+ ? (flags & AcDbMLineStyleFlags.StartInnerArcs) !== 0
1239
+ : (flags & AcDbMLineStyleFlags.EndInnerArcs) !== 0;
1240
+ if (!hasSquare && !hasOuterArc && !hasInnerArcs)
1241
+ return [];
1242
+ var points = this.getCapElementPoints(side, elementCount, mlineStyle);
1243
+ if (points.length < 2)
1244
+ return [];
1245
+ var entities = [];
1246
+ var traits = renderer.subEntityTraits;
1247
+ if (hasSquare) {
1248
+ for (var i = 0; i < points.length - 1; i++) {
1249
+ this.applyElementDrawTraits(traits, originalColor, originalRgbColor, originalLineType, mlineStyle, points[i].elementIndex);
1250
+ entities.push(renderer.lines([points[i].point, points[i + 1].point]));
1251
+ }
1252
+ }
1253
+ var capDirection = isStart
1254
+ ? this.getStartSegmentDirection().multiplyScalar(-1)
1255
+ : this.getEndSegmentDirection().clone();
1256
+ if (hasOuterArc) {
1257
+ var outer = this.drawCapArcBetweenElements(renderer, side, points[0], points[points.length - 1], capDirection, traits, originalColor, originalRgbColor, originalLineType, mlineStyle);
1258
+ if (outer)
1259
+ entities.push(outer);
1260
+ }
1261
+ if (hasInnerArcs) {
1262
+ for (var i = 1; i < Math.floor(points.length / 2); i++) {
1263
+ var left = points[i];
1264
+ var right = points[points.length - 1 - i];
1265
+ if (!left || !right || left === right)
1266
+ continue;
1267
+ var inner = this.drawCapArcBetweenElements(renderer, side, left, right, capDirection, traits, originalColor, originalRgbColor, originalLineType, mlineStyle);
1268
+ if (inner)
1269
+ entities.push(inner);
1270
+ }
1271
+ }
1272
+ return entities;
1273
+ };
1274
+ /**
1275
+ * Creates sorted element boundary points for one cap side.
1276
+ *
1277
+ * @param side `start` or `end`.
1278
+ * @param elementCount Renderable style element count.
1279
+ * @param mlineStyle Resolved style object.
1280
+ * @returns Cap points sorted by descending element offset.
1281
+ */
1282
+ AcDbMLine.prototype.getCapElementPoints = function (side, elementCount, mlineStyle) {
1283
+ var _this = this;
1284
+ var segment = side === 'start'
1285
+ ? this._segments[0]
1286
+ : this._segments[this._segments.length - 1];
1287
+ if (!segment)
1288
+ return [];
1289
+ return Array.from({ length: elementCount }, function (_, elementIndex) { return ({
1290
+ elementIndex: elementIndex,
1291
+ offset: _this.getElementMiterOffset(segment, elementIndex, mlineStyle),
1292
+ point: _this.getElementBoundaryPoint(side, segment, elementIndex, mlineStyle)
1293
+ }); }).sort(function (a, b) { return b.offset - a.offset; });
1294
+ };
1295
+ /**
1296
+ * Draws one cap arc between two cap element points.
1297
+ *
1298
+ * @param renderer Active graphics renderer.
1299
+ * @param startPointPair Start element point.
1300
+ * @param endPointPair End element point.
1301
+ * @param capDirection Outward cap direction.
1302
+ * @param traits Mutable renderer traits.
1303
+ * @param originalColor Original trait color.
1304
+ * @param originalRgbColor Original trait RGB.
1305
+ * @param originalLineType Original trait linetype.
1306
+ * @param mlineStyle Resolved style object.
1307
+ * @returns Arc entity, or `undefined` when arc cannot be constructed.
1308
+ */
1309
+ AcDbMLine.prototype.drawCapArcBetweenElements = function (renderer, side, startPointPair, endPointPair, capDirection, traits, originalColor, originalRgbColor, originalLineType, mlineStyle) {
1310
+ // For 180-degree cap arcs, start/end point order determines whether
1311
+ // the renderer takes the left or right semicircle. End caps need reverse order.
1312
+ var arcStartPoint = side === 'end' ? endPointPair.point : startPointPair.point;
1313
+ var arcEndPoint = side === 'end' ? startPointPair.point : endPointPair.point;
1314
+ var chord = arcStartPoint.distanceTo(arcEndPoint);
1315
+ if (chord <= 1e-9 || capDirection.lengthSq() === 0)
1316
+ return undefined;
1317
+ var midpoint = arcStartPoint
1318
+ .clone()
1319
+ .add(new AcGeVector3d()
1320
+ .subVectors(arcEndPoint, arcStartPoint)
1321
+ .multiplyScalar(0.5));
1322
+ var pointOnArc = midpoint.add(capDirection
1323
+ .clone()
1324
+ .normalize()
1325
+ .multiplyScalar(chord / 2));
1326
+ var arc = AcGeCircArc3d.createByThreePoints(arcStartPoint, arcEndPoint, pointOnArc);
1327
+ if (!arc)
1328
+ return undefined;
1329
+ this.applyElementDrawTraits(traits, originalColor, originalRgbColor, originalLineType, mlineStyle, side === 'end' ? endPointPair.elementIndex : startPointPair.elementIndex);
1330
+ return renderer.circularArc(arc);
1331
+ };
1332
+ /**
1333
+ * Applies per-element traits while restoring baseline traits first.
1334
+ *
1335
+ * @param traits Mutable renderer traits.
1336
+ * @param originalColor Original trait color.
1337
+ * @param originalRgbColor Original trait RGB.
1338
+ * @param originalLineType Original trait linetype.
1339
+ * @param mlineStyle Resolved style object.
1340
+ * @param elementIndex Style element index.
1341
+ */
1342
+ AcDbMLine.prototype.applyElementDrawTraits = function (traits, originalColor, originalRgbColor, originalLineType, mlineStyle, elementIndex) {
1343
+ traits.color = originalColor;
1344
+ traits.rgbColor = originalRgbColor;
1345
+ traits.lineType = originalLineType;
1346
+ this.applyStyleElementTraits(mlineStyle, elementIndex, traits);
1347
+ };
1348
+ /**
1349
+ * Transforms a vector by matrix rotation/scale only.
1350
+ * Translation is canceled by transforming an origin-endpoint pair.
1351
+ *
1352
+ * @param vector Vector to transform in place.
1353
+ * @param matrix Transformation matrix.
1354
+ */
489
1355
  AcDbMLine.prototype.transformVector = function (vector, matrix) {
490
1356
  var origin = new AcGePoint3d();
491
1357
  var endpoint = new AcGePoint3d(vector.x, vector.y, vector.z);
@@ -493,8 +1359,14 @@ var AcDbMLine = /** @class */ (function (_super) {
493
1359
  endpoint.applyMatrix4(matrix);
494
1360
  vector.set(endpoint.x - origin.x, endpoint.y - origin.y, endpoint.z - origin.z);
495
1361
  };
1362
+ /**
1363
+ * Resolves the effective MLINE style from database dictionary.
1364
+ * Lookup order: handle, exact name, then case-insensitive name match.
1365
+ *
1366
+ * @returns Matching style object, or `undefined` when no style is found.
1367
+ */
496
1368
  AcDbMLine.prototype.getMLineStyle = function () {
497
- var e_1, _a;
1369
+ var e_2, _a;
498
1370
  var _b;
499
1371
  var dictionary = this.database.objects.mlineStyle;
500
1372
  var byHandle = this.styleObjectHandle
@@ -512,35 +1384,125 @@ var AcDbMLine = /** @class */ (function (_super) {
512
1384
  try {
513
1385
  for (var _c = __values(dictionary.entries()), _d = _c.next(); !_d.done; _d = _c.next()) {
514
1386
  var _e = __read(_d.value, 2), name_1 = _e[0], style = _e[1];
515
- if (name_1.toUpperCase() === normalizedStyleName) {
1387
+ var styleName = (style.styleName || name_1).toUpperCase();
1388
+ if (name_1.toUpperCase() === normalizedStyleName ||
1389
+ styleName === normalizedStyleName) {
516
1390
  return style;
517
1391
  }
518
1392
  }
519
1393
  }
520
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
1394
+ catch (e_2_1) { e_2 = { error: e_2_1 }; }
521
1395
  finally {
522
1396
  try {
523
1397
  if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
524
1398
  }
525
- finally { if (e_1) throw e_1.error; }
1399
+ finally { if (e_2) throw e_2.error; }
526
1400
  }
527
1401
  }
528
1402
  return undefined;
529
1403
  };
1404
+ /**
1405
+ * Applies style-element color and linetype traits to renderer traits.
1406
+ * BYBLOCK and BYLAYER colors are ignored.
1407
+ *
1408
+ * @param mlineStyle Resolved style object.
1409
+ * @param elementIndex Style element index.
1410
+ * @param traits Mutable renderer trait set.
1411
+ */
530
1412
  AcDbMLine.prototype.applyStyleElementTraits = function (mlineStyle, elementIndex, traits) {
1413
+ var _a;
531
1414
  var styleElement = mlineStyle === null || mlineStyle === void 0 ? void 0 : mlineStyle.elements[elementIndex];
532
1415
  if (!styleElement)
533
1416
  return;
534
- var colorIndex = styleElement.color;
535
- if (colorIndex === 0 || colorIndex === 256)
1417
+ var lineType = this.resolveStyleElementLineType(styleElement.lineType);
1418
+ if (lineType) {
1419
+ traits.lineType = lineType;
1420
+ }
1421
+ if (styleElement.color.isByBlock || styleElement.color.isByLayer)
1422
+ return;
1423
+ traits.color = styleElement.color.clone();
1424
+ traits.rgbColor = (_a = styleElement.color.RGB) !== null && _a !== void 0 ? _a : this.rgbColor;
1425
+ };
1426
+ /**
1427
+ * Applies fill color traits from style definition to the renderer traits object.
1428
+ * BYBLOCK and BYLAYER colors are ignored.
1429
+ *
1430
+ * @param mlineStyle Resolved style object.
1431
+ * @param traits Mutable renderer trait set.
1432
+ */
1433
+ AcDbMLine.prototype.applyFillTraits = function (mlineStyle, traits) {
1434
+ var _a;
1435
+ var fillColor = mlineStyle === null || mlineStyle === void 0 ? void 0 : mlineStyle.fillColor;
1436
+ if (!fillColor || fillColor.isByBlock || fillColor.isByLayer)
536
1437
  return;
537
- var color = new AcCmColor();
538
- color.colorIndex = colorIndex;
539
- traits.color = color;
540
- if (color.RGB != null) {
541
- traits.rgbColor = color.RGB;
1438
+ traits.color = fillColor.clone();
1439
+ traits.rgbColor = (_a = fillColor.RGB) !== null && _a !== void 0 ? _a : this.rgbColor;
1440
+ };
1441
+ /**
1442
+ * Resolves a style-element linetype token to concrete renderer linetype traits.
1443
+ *
1444
+ * @param rawLineType Style element linetype token.
1445
+ * @returns Resolved linetype traits, or `undefined` when no override is needed.
1446
+ */
1447
+ AcDbMLine.prototype.resolveStyleElementLineType = function (rawLineType) {
1448
+ var _a;
1449
+ var lineTypeName = rawLineType === null || rawLineType === void 0 ? void 0 : rawLineType.trim();
1450
+ if (!lineTypeName)
1451
+ return undefined;
1452
+ var normalized = lineTypeName.toUpperCase();
1453
+ var byLayer = ByLayer.toUpperCase();
1454
+ var byBlock = ByBlock.toUpperCase();
1455
+ var type = 'UserSpecified';
1456
+ var resolvedName = lineTypeName;
1457
+ if (normalized === byLayer) {
1458
+ type = 'ByLayer';
1459
+ var layerLineType = (_a = this.database.tables.layerTable.getAt(this.layer)) === null || _a === void 0 ? void 0 : _a.linetype;
1460
+ resolvedName =
1461
+ layerLineType &&
1462
+ layerLineType.toUpperCase() !== byLayer &&
1463
+ layerLineType.toUpperCase() !== byBlock
1464
+ ? layerLineType
1465
+ : DEFAULT_LINE_TYPE;
1466
+ }
1467
+ else if (normalized === byBlock) {
1468
+ type = 'ByBlock';
1469
+ resolvedName = DEFAULT_LINE_TYPE;
1470
+ }
1471
+ var lineTypeRecord = this.database.tables.linetypeTable.getAt(resolvedName);
1472
+ if (lineTypeRecord) {
1473
+ return __assign({ type: type }, lineTypeRecord.linetype);
1474
+ }
1475
+ return {
1476
+ type: type,
1477
+ name: resolvedName,
1478
+ standardFlag: 0,
1479
+ description: '',
1480
+ totalPatternLength: 0
1481
+ };
1482
+ };
1483
+ /**
1484
+ * @inheritdoc
1485
+ */
1486
+ AcDbMLine.prototype.resolveEffectiveProperties = function () {
1487
+ _super.prototype.resolveEffectiveProperties.call(this);
1488
+ if (!this._styleName) {
1489
+ this._styleName = this.getDefaultStyleName();
1490
+ }
1491
+ };
1492
+ /**
1493
+ * Resolves the default style name for newly created MLINE entities.
1494
+ */
1495
+ AcDbMLine.prototype.getDefaultStyleName = function () {
1496
+ try {
1497
+ return this.database.cmlstyle || DEFAULT_MLINE_STYLE;
1498
+ }
1499
+ catch (_a) {
1500
+ return DEFAULT_MLINE_STYLE;
542
1501
  }
543
1502
  };
1503
+ /**
1504
+ * Runtime type name used by the entity factory and RTTI helpers.
1505
+ */
544
1506
  AcDbMLine.typeName = 'MLine';
545
1507
  return AcDbMLine;
546
1508
  }(AcDbEntity));