@mlightcad/mtext-parser 1.0.11 → 1.1.0

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.
package/dist/parser.es.js CHANGED
@@ -1,9 +1,9 @@
1
- var k = /* @__PURE__ */ ((s) => (s[s.NONE = 0] = "NONE", s[s.WORD = 1] = "WORD", s[s.STACK = 2] = "STACK", s[s.SPACE = 3] = "SPACE", s[s.NBSP = 4] = "NBSP", s[s.TABULATOR = 5] = "TABULATOR", s[s.NEW_PARAGRAPH = 6] = "NEW_PARAGRAPH", s[s.NEW_COLUMN = 7] = "NEW_COLUMN", s[s.WRAP_AT_DIMLINE = 8] = "WRAP_AT_DIMLINE", s[s.PROPERTIES_CHANGED = 9] = "PROPERTIES_CHANGED", s))(k || {}), b = /* @__PURE__ */ ((s) => (s[s.BOTTOM = 0] = "BOTTOM", s[s.MIDDLE = 1] = "MIDDLE", s[s.TOP = 2] = "TOP", s))(b || {}), E = /* @__PURE__ */ ((s) => (s[s.DEFAULT = 0] = "DEFAULT", s[s.LEFT = 1] = "LEFT", s[s.RIGHT = 2] = "RIGHT", s[s.CENTER = 3] = "CENTER", s[s.JUSTIFIED = 4] = "JUSTIFIED", s[s.DISTRIBUTED = 5] = "DISTRIBUTED", s))(E || {}), F = /* @__PURE__ */ ((s) => (s[s.NONE = 0] = "NONE", s[s.UNDERLINE = 1] = "UNDERLINE", s[s.OVERLINE = 2] = "OVERLINE", s[s.STRIKE_THROUGH = 4] = "STRIKE_THROUGH", s))(F || {});
2
- const m = {
1
+ var k = /* @__PURE__ */ ((s) => (s[s.NONE = 0] = "NONE", s[s.WORD = 1] = "WORD", s[s.STACK = 2] = "STACK", s[s.SPACE = 3] = "SPACE", s[s.NBSP = 4] = "NBSP", s[s.TABULATOR = 5] = "TABULATOR", s[s.NEW_PARAGRAPH = 6] = "NEW_PARAGRAPH", s[s.NEW_COLUMN = 7] = "NEW_COLUMN", s[s.WRAP_AT_DIMLINE = 8] = "WRAP_AT_DIMLINE", s[s.PROPERTIES_CHANGED = 9] = "PROPERTIES_CHANGED", s))(k || {}), _ = /* @__PURE__ */ ((s) => (s[s.BOTTOM = 0] = "BOTTOM", s[s.MIDDLE = 1] = "MIDDLE", s[s.TOP = 2] = "TOP", s))(_ || {}), m = /* @__PURE__ */ ((s) => (s[s.DEFAULT = 0] = "DEFAULT", s[s.LEFT = 1] = "LEFT", s[s.RIGHT = 2] = "RIGHT", s[s.CENTER = 3] = "CENTER", s[s.JUSTIFIED = 4] = "JUSTIFIED", s[s.DISTRIBUTED = 5] = "DISTRIBUTED", s))(m || {}), E = /* @__PURE__ */ ((s) => (s[s.NONE = 0] = "NONE", s[s.UNDERLINE = 1] = "UNDERLINE", s[s.OVERLINE = 2] = "OVERLINE", s[s.STRIKE_THROUGH = 4] = "STRIKE_THROUGH", s))(E || {});
2
+ const F = {
3
3
  c: "Ø",
4
4
  d: "°",
5
5
  p: "±"
6
- }, _ = {
6
+ }, S = {
7
7
  l: 1,
8
8
  r: 2,
9
9
  c: 3,
@@ -12,49 +12,50 @@ const m = {
12
12
  /* DISTRIBUTED */
13
13
  };
14
14
  function R(s) {
15
- const [e, t, r] = s;
16
- return r << 16 | t << 8 | e;
17
- }
18
- function S(s) {
19
- const e = s & 255, t = s >> 8 & 255, r = s >> 16 & 255;
20
- return [e, t, r];
15
+ const [t, e, r] = s;
16
+ return r << 16 | e << 8 | t;
21
17
  }
22
18
  function v(s) {
23
- return s.replace(/\r\n|\r|\n/g, "\\P");
19
+ const t = s & 255, e = s >> 8 & 255, r = s >> 16 & 255;
20
+ return [t, e, r];
24
21
  }
25
22
  function I(s) {
26
- return s.replace(/\\P/g, "").replace(/\\~/g, "").includes("\\");
23
+ return s.replace(/\r\n|\r|\n/g, "\\P");
27
24
  }
28
25
  function N(s) {
29
- const e = /* @__PURE__ */ new Set(), t = /\\[fF](.*?)[;|]/g;
30
- return [...s.matchAll(t)].forEach((r) => {
31
- e.add(r[1].toLowerCase());
26
+ return s.replace(/\\P/g, "").replace(/\\~/g, "").includes("\\");
27
+ }
28
+ function O(s, t = !1) {
29
+ const e = /* @__PURE__ */ new Set(), r = /\\[fF](.*?)[;|]/g;
30
+ return [...s.matchAll(r)].forEach((a) => {
31
+ let i = a[1].toLowerCase();
32
+ t && (i = i.replace(/\.(ttf|otf|woff|shx)$/, "")), e.add(i);
32
33
  }), e;
33
34
  }
34
- class O {
35
+ class D {
35
36
  /**
36
37
  * Creates a new MTextParser instance
37
38
  * @param content - The MText content to parse
38
39
  * @param ctx - Optional initial MText context
39
40
  * @param yieldPropertyCommands - Whether to yield property change commands
40
41
  */
41
- constructor(e, t, r = !1) {
42
- this.ctxStack = [], this.continueStroke = !1, this.inStackContext = !1, this.scanner = new f(e), this.ctx = t ?? new g(), this.lastCtx = this.ctx.copy(), this.yieldPropertyCommands = r;
42
+ constructor(t, e, r = !1) {
43
+ this.ctxStack = [], this.continueStroke = !1, this.inStackContext = !1, this.scanner = new g(t), this.ctx = e ?? new d(), this.lastCtx = this.ctx.copy(), this.yieldPropertyCommands = r;
43
44
  }
44
45
  /**
45
46
  * Decode multi-byte character from hex code
46
47
  * @param hex - Hex code string (e.g. "C4E3")
47
48
  * @returns Decoded character or empty square if invalid
48
49
  */
49
- decodeMultiByteChar(e) {
50
+ decodeMultiByteChar(t) {
50
51
  try {
51
- const t = new Uint8Array([
52
- parseInt(e.substr(0, 2), 16),
53
- parseInt(e.substr(2, 2), 16)
54
- ]), a = new TextDecoder("gbk").decode(t);
52
+ const e = new Uint8Array([
53
+ parseInt(t.substr(0, 2), 16),
54
+ parseInt(t.substr(2, 2), 16)
55
+ ]), a = new TextDecoder("gbk").decode(e);
55
56
  if (a !== "▯")
56
57
  return a;
57
- const h = new TextDecoder("big5").decode(t);
58
+ const h = new TextDecoder("big5").decode(e);
58
59
  return h !== "▯" ? h : "▯";
59
60
  } catch {
60
61
  return "▯";
@@ -77,14 +78,14 @@ class O {
77
78
  * @returns Tuple of [TokenType.STACK, [numerator, denominator, type]]
78
79
  */
79
80
  parseStacking() {
80
- const e = new f(this.extractExpression(!0));
81
- let t = "", r = "", a = "";
81
+ const t = new g(this.extractExpression(!0));
82
+ let e = "", r = "", a = "";
82
83
  const i = () => {
83
- let n = e.peek(), l = !1;
84
- return n.charCodeAt(0) < 32 && (n = " "), n === "\\" && (l = !0, e.consume(1), n = e.peek()), e.consume(1), [n, l];
84
+ let n = t.peek(), l = !1;
85
+ return n.charCodeAt(0) < 32 && (n = " "), n === "\\" && (l = !0, t.consume(1), n = t.peek()), t.consume(1), [n, l];
85
86
  }, h = () => {
86
87
  let n = "";
87
- for (; e.hasData; ) {
88
+ for (; t.hasData; ) {
88
89
  const [l, o] = i();
89
90
  if (!o && (l === "/" || l === "#" || l === "^"))
90
91
  return [n, l];
@@ -93,7 +94,7 @@ class O {
93
94
  return [n, ""];
94
95
  }, u = (n) => {
95
96
  let l = "", o = n;
96
- for (; e.hasData; ) {
97
+ for (; t.hasData; ) {
97
98
  const [c, p] = i();
98
99
  if (!(o && c === " ")) {
99
100
  if (o = !1, !p && c === ";")
@@ -103,70 +104,70 @@ class O {
103
104
  }
104
105
  return l;
105
106
  };
106
- return [t, a] = h(), a && (r = u(a === "^")), t === "" && r.includes("I/") ? [2, [" ", " ", "/"]] : a === "^" ? [2, [t, r, "^"]] : [2, [t, r, a]];
107
+ return [e, a] = h(), a && (r = u(a === "^")), e === "" && r.includes("I/") ? [2, [" ", " ", "/"]] : a === "^" ? [2, [e, r, "^"]] : [2, [e, r, a]];
107
108
  }
108
109
  /**
109
110
  * Parse MText properties
110
111
  * @param cmd - The property command to parse
111
112
  * @returns Property changes if yieldPropertyCommands is true and changes occurred
112
113
  */
113
- parseProperties(e) {
114
- const t = this.ctx.copy();
115
- switch (e) {
114
+ parseProperties(t) {
115
+ const e = this.ctx.copy();
116
+ switch (t) {
116
117
  case "L":
117
- t.underline = !0, this.continueStroke = !0;
118
+ e.underline = !0, this.continueStroke = !0;
118
119
  break;
119
120
  case "l":
120
- t.underline = !1, t.hasAnyStroke || (this.continueStroke = !1);
121
+ e.underline = !1, e.hasAnyStroke || (this.continueStroke = !1);
121
122
  break;
122
123
  case "O":
123
- t.overline = !0, this.continueStroke = !0;
124
+ e.overline = !0, this.continueStroke = !0;
124
125
  break;
125
126
  case "o":
126
- t.overline = !1, t.hasAnyStroke || (this.continueStroke = !1);
127
+ e.overline = !1, e.hasAnyStroke || (this.continueStroke = !1);
127
128
  break;
128
129
  case "K":
129
- t.strikeThrough = !0, this.continueStroke = !0;
130
+ e.strikeThrough = !0, this.continueStroke = !0;
130
131
  break;
131
132
  case "k":
132
- t.strikeThrough = !1, t.hasAnyStroke || (this.continueStroke = !1);
133
+ e.strikeThrough = !1, e.hasAnyStroke || (this.continueStroke = !1);
133
134
  break;
134
135
  case "A":
135
- this.parseAlign(t);
136
+ this.parseAlign(e);
136
137
  break;
137
138
  case "C":
138
- this.parseAciColor(t);
139
+ this.parseAciColor(e);
139
140
  break;
140
141
  case "c":
141
- this.parseRgbColor(t);
142
+ this.parseRgbColor(e);
142
143
  break;
143
144
  case "H":
144
- this.parseHeight(t);
145
+ this.parseHeight(e);
145
146
  break;
146
147
  case "W":
147
- this.parseWidth(t);
148
+ this.parseWidth(e);
148
149
  break;
149
150
  case "Q":
150
- this.parseOblique(t);
151
+ this.parseOblique(e);
151
152
  break;
152
153
  case "T":
153
- this.parseCharTracking(t);
154
+ this.parseCharTracking(e);
154
155
  break;
155
156
  case "p":
156
- this.parseParagraphProperties(t);
157
+ this.parseParagraphProperties(e);
157
158
  break;
158
159
  case "f":
159
160
  case "F":
160
- this.parseFontProperties(t);
161
+ this.parseFontProperties(e);
161
162
  break;
162
163
  default:
163
- throw new Error(`Unknown command: ${e}`);
164
+ throw new Error(`Unknown command: ${t}`);
164
165
  }
165
- if (this.continueStroke = t.hasAnyStroke, t.continueStroke = this.continueStroke, this.ctx = t, this.yieldPropertyCommands) {
166
- const r = this.getPropertyChanges(this.lastCtx, t);
166
+ if (this.continueStroke = e.hasAnyStroke, e.continueStroke = this.continueStroke, this.ctx = e, this.yieldPropertyCommands) {
167
+ const r = this.getPropertyChanges(this.lastCtx, e);
167
168
  if (Object.keys(r).length > 0)
168
169
  return this.lastCtx = this.ctx.copy(), {
169
- command: e,
170
+ command: t,
170
171
  changes: r
171
172
  };
172
173
  }
@@ -177,11 +178,11 @@ class O {
177
178
  * @param newCtx - The new context
178
179
  * @returns Object containing changed properties
179
180
  */
180
- getPropertyChanges(e, t) {
181
+ getPropertyChanges(t, e) {
181
182
  const r = {};
182
- if (e.underline !== t.underline && (r.underline = t.underline), e.overline !== t.overline && (r.overline = t.overline), e.strikeThrough !== t.strikeThrough && (r.strikeThrough = t.strikeThrough), e.aci !== t.aci && (r.aci = t.aci, r.rgb = t.rgb), e.rgb !== t.rgb && (r.rgb = t.rgb), e.align !== t.align && (r.align = t.align), JSON.stringify(e.fontFace) !== JSON.stringify(t.fontFace) && (r.fontFace = t.fontFace), (e.capHeight.value !== t.capHeight.value || e.capHeight.isRelative !== t.capHeight.isRelative) && (r.capHeight = t.capHeight), (e.widthFactor.value !== t.widthFactor.value || e.widthFactor.isRelative !== t.widthFactor.isRelative) && (r.widthFactor = t.widthFactor), (e.charTrackingFactor.value !== t.charTrackingFactor.value || e.charTrackingFactor.isRelative !== t.charTrackingFactor.isRelative) && (r.charTrackingFactor = t.charTrackingFactor), e.oblique !== t.oblique && (r.oblique = t.oblique), JSON.stringify(e.paragraph) !== JSON.stringify(t.paragraph)) {
183
+ if (t.underline !== e.underline && (r.underline = e.underline), t.overline !== e.overline && (r.overline = e.overline), t.strikeThrough !== e.strikeThrough && (r.strikeThrough = e.strikeThrough), t.color.aci !== e.color.aci && (r.aci = e.color.aci, r.rgb = e.color.rgb), t.color.rgbValue !== e.color.rgbValue && (r.rgb = e.color.rgb), t.align !== e.align && (r.align = e.align), JSON.stringify(t.fontFace) !== JSON.stringify(e.fontFace) && (r.fontFace = e.fontFace), (t.capHeight.value !== e.capHeight.value || t.capHeight.isRelative !== e.capHeight.isRelative) && (r.capHeight = e.capHeight), (t.widthFactor.value !== e.widthFactor.value || t.widthFactor.isRelative !== e.widthFactor.isRelative) && (r.widthFactor = e.widthFactor), (t.charTrackingFactor.value !== e.charTrackingFactor.value || t.charTrackingFactor.isRelative !== e.charTrackingFactor.isRelative) && (r.charTrackingFactor = e.charTrackingFactor), t.oblique !== e.oblique && (r.oblique = e.oblique), JSON.stringify(t.paragraph) !== JSON.stringify(e.paragraph)) {
183
184
  const a = {};
184
- e.paragraph.indent !== t.paragraph.indent && (a.indent = t.paragraph.indent), e.paragraph.align !== t.paragraph.align && (a.align = t.paragraph.align), e.paragraph.left !== t.paragraph.left && (a.left = t.paragraph.left), e.paragraph.right !== t.paragraph.right && (a.right = t.paragraph.right), JSON.stringify(e.paragraph.tab_stops) !== JSON.stringify(t.paragraph.tab_stops) && (a.tab_stops = t.paragraph.tab_stops), Object.keys(a).length > 0 && (r.paragraph = a);
185
+ t.paragraph.indent !== e.paragraph.indent && (a.indent = e.paragraph.indent), t.paragraph.align !== e.paragraph.align && (a.align = e.paragraph.align), t.paragraph.left !== e.paragraph.left && (a.left = e.paragraph.left), t.paragraph.right !== e.paragraph.right && (a.right = e.paragraph.right), JSON.stringify(t.paragraph.tab_stops) !== JSON.stringify(e.paragraph.tab_stops) && (a.tab_stops = e.paragraph.tab_stops), Object.keys(a).length > 0 && (r.paragraph = a);
185
186
  }
186
187
  return r;
187
188
  }
@@ -189,27 +190,27 @@ class O {
189
190
  * Parse alignment property
190
191
  * @param ctx - The context to update
191
192
  */
192
- parseAlign(e) {
193
- const t = this.scanner.get();
194
- "012".includes(t) ? e.align = parseInt(t) : e.align = 0, this.consumeOptionalTerminator();
193
+ parseAlign(t) {
194
+ const e = this.scanner.get();
195
+ "012".includes(e) ? t.align = parseInt(e) : t.align = 0, this.consumeOptionalTerminator();
195
196
  }
196
197
  /**
197
198
  * Parse height property
198
199
  * @param ctx - The context to update
199
200
  */
200
- parseHeight(e) {
201
- const t = this.extractFloatExpression(!0);
202
- if (t)
201
+ parseHeight(t) {
202
+ const e = this.extractFloatExpression(!0);
203
+ if (e)
203
204
  try {
204
- t.endsWith("x") ? e.capHeight = {
205
- value: parseFloat(t.slice(0, -1)),
205
+ e.endsWith("x") ? t.capHeight = {
206
+ value: parseFloat(e.slice(0, -1)),
206
207
  isRelative: !0
207
- } : e.capHeight = {
208
- value: parseFloat(t),
208
+ } : t.capHeight = {
209
+ value: parseFloat(e),
209
210
  isRelative: !1
210
211
  };
211
212
  } catch {
212
- this.scanner.consume(-t.length);
213
+ this.scanner.consume(-e.length);
213
214
  return;
214
215
  }
215
216
  this.consumeOptionalTerminator();
@@ -218,19 +219,19 @@ class O {
218
219
  * Parse width property
219
220
  * @param ctx - The context to update
220
221
  */
221
- parseWidth(e) {
222
- const t = this.extractFloatExpression(!0);
223
- if (t)
222
+ parseWidth(t) {
223
+ const e = this.extractFloatExpression(!0);
224
+ if (e)
224
225
  try {
225
- t.endsWith("x") ? e.widthFactor = {
226
- value: parseFloat(t.slice(0, -1)),
226
+ e.endsWith("x") ? t.widthFactor = {
227
+ value: parseFloat(e.slice(0, -1)),
227
228
  isRelative: !0
228
- } : e.widthFactor = {
229
- value: parseFloat(t),
229
+ } : t.widthFactor = {
230
+ value: parseFloat(e),
230
231
  isRelative: !1
231
232
  };
232
233
  } catch {
233
- this.scanner.consume(-t.length);
234
+ this.scanner.consume(-e.length);
234
235
  return;
235
236
  }
236
237
  this.consumeOptionalTerminator();
@@ -239,19 +240,19 @@ class O {
239
240
  * Parse character tracking property
240
241
  * @param ctx - The context to update
241
242
  */
242
- parseCharTracking(e) {
243
- const t = this.extractFloatExpression(!0);
244
- if (t)
243
+ parseCharTracking(t) {
244
+ const e = this.extractFloatExpression(!0);
245
+ if (e)
245
246
  try {
246
- t.endsWith("x") ? e.charTrackingFactor = {
247
- value: Math.abs(parseFloat(t.slice(0, -1))),
247
+ e.endsWith("x") ? t.charTrackingFactor = {
248
+ value: Math.abs(parseFloat(e.slice(0, -1))),
248
249
  isRelative: !0
249
- } : e.charTrackingFactor = {
250
- value: Math.abs(parseFloat(t)),
250
+ } : t.charTrackingFactor = {
251
+ value: Math.abs(parseFloat(e)),
251
252
  isRelative: !1
252
253
  };
253
254
  } catch {
254
- this.scanner.consume(-t.length);
255
+ this.scanner.consume(-e.length);
255
256
  return;
256
257
  }
257
258
  this.consumeOptionalTerminator();
@@ -261,33 +262,33 @@ class O {
261
262
  * @param value - Current value to apply factor to
262
263
  * @returns New value
263
264
  */
264
- parseFloatValueOrFactor(e) {
265
- const t = this.extractFloatExpression(!0);
266
- if (t)
267
- if (t.endsWith("x")) {
268
- const r = parseFloat(t.slice(0, -1));
269
- e *= r;
265
+ parseFloatValueOrFactor(t) {
266
+ const e = this.extractFloatExpression(!0);
267
+ if (e)
268
+ if (e.endsWith("x")) {
269
+ const r = parseFloat(e.slice(0, -1));
270
+ t *= r;
270
271
  } else
271
- e = parseFloat(t);
272
- return e;
272
+ t = parseFloat(e);
273
+ return t;
273
274
  }
274
275
  /**
275
276
  * Parse oblique angle property
276
277
  * @param ctx - The context to update
277
278
  */
278
- parseOblique(e) {
279
- const t = this.extractFloatExpression(!1);
280
- t && (e.oblique = parseFloat(t)), this.consumeOptionalTerminator();
279
+ parseOblique(t) {
280
+ const e = this.extractFloatExpression(!1);
281
+ e && (t.oblique = parseFloat(e)), this.consumeOptionalTerminator();
281
282
  }
282
283
  /**
283
284
  * Parse ACI color property
284
285
  * @param ctx - The context to update
285
286
  */
286
- parseAciColor(e) {
287
- const t = this.extractIntExpression();
288
- if (t) {
289
- const r = parseInt(t);
290
- r < 257 && (e.aci = r, e.rgb = null);
287
+ parseAciColor(t) {
288
+ const e = this.extractIntExpression();
289
+ if (e) {
290
+ const r = parseInt(e);
291
+ r < 257 && (t.color.aci = r);
291
292
  }
292
293
  this.consumeOptionalTerminator();
293
294
  }
@@ -295,11 +296,11 @@ class O {
295
296
  * Parse RGB color property
296
297
  * @param ctx - The context to update
297
298
  */
298
- parseRgbColor(e) {
299
- const t = this.extractIntExpression();
300
- if (t) {
301
- const r = parseInt(t) & 16777215, [a, i, h] = S(r);
302
- e.rgb = [h, i, a];
299
+ parseRgbColor(t) {
300
+ const e = this.extractIntExpression();
301
+ if (e) {
302
+ const r = parseInt(e) & 16777215;
303
+ t.color.rgbValue = r;
303
304
  }
304
305
  this.consumeOptionalTerminator();
305
306
  }
@@ -308,8 +309,8 @@ class O {
308
309
  * @param relative - Whether to allow relative values (ending in 'x')
309
310
  * @returns Extracted expression
310
311
  */
311
- extractFloatExpression(e = !1) {
312
- const t = e ? /^[+-]?(?:\d+(?:\.\d*)?|\.\d+)(?:[eE][+-]?\d+)?x?/ : /^[+-]?(?:\d+(?:\.\d*)?|\.\d+)(?:[eE][+-]?\d+)?/, r = this.scanner.tail.match(t);
312
+ extractFloatExpression(t = !1) {
313
+ const e = t ? /^[+-]?(?:\d+(?:\.\d*)?|\.\d+)(?:[eE][+-]?\d+)?x?/ : /^[+-]?(?:\d+(?:\.\d*)?|\.\d+)(?:[eE][+-]?\d+)?/, r = this.scanner.tail.match(e);
313
314
  if (r) {
314
315
  const a = r[0];
315
316
  return this.scanner.consume(a.length), a;
@@ -321,10 +322,10 @@ class O {
321
322
  * @returns Extracted expression
322
323
  */
323
324
  extractIntExpression() {
324
- const e = this.scanner.tail.match(/^\d+/);
325
- if (e) {
326
- const t = e[0];
327
- return this.scanner.consume(t.length), t;
325
+ const t = this.scanner.tail.match(/^\d+/);
326
+ if (t) {
327
+ const e = t[0];
328
+ return this.scanner.consume(e.length), e;
328
329
  }
329
330
  return "";
330
331
  }
@@ -333,27 +334,27 @@ class O {
333
334
  * @param escape - Whether to handle escaped semicolons
334
335
  * @returns Extracted expression
335
336
  */
336
- extractExpression(e = !1) {
337
- const t = this.scanner.find(";", e);
338
- if (t < 0) {
337
+ extractExpression(t = !1) {
338
+ const e = this.scanner.find(";", t);
339
+ if (e < 0) {
339
340
  const h = this.scanner.tail;
340
341
  return this.scanner.consume(h.length), h;
341
342
  }
342
- const a = this.scanner.peek(t - this.scanner.currentIndex - 1) === "\\", i = this.scanner.tail.slice(0, t - this.scanner.currentIndex + (a ? 1 : 0));
343
+ const a = this.scanner.peek(e - this.scanner.currentIndex - 1) === "\\", i = this.scanner.tail.slice(0, e - this.scanner.currentIndex + (a ? 1 : 0));
343
344
  return this.scanner.consume(i.length + 1), i;
344
345
  }
345
346
  /**
346
347
  * Parse font properties
347
348
  * @param ctx - The context to update
348
349
  */
349
- parseFontProperties(e) {
350
- const t = this.extractExpression().split("|");
351
- if (t.length > 0 && t[0]) {
352
- const r = t[0];
350
+ parseFontProperties(t) {
351
+ const e = this.extractExpression().split("|");
352
+ if (e.length > 0 && e[0]) {
353
+ const r = e[0];
353
354
  let a = "Regular", i = 400;
354
- for (const h of t.slice(1))
355
+ for (const h of e.slice(1))
355
356
  h.startsWith("b1") ? i = 700 : h.startsWith("i1") && (a = "Italic");
356
- e.fontFace = {
357
+ t.fontFace = {
357
358
  family: r,
358
359
  style: a,
359
360
  weight: i
@@ -365,21 +366,21 @@ class O {
365
366
  * Handles properties like indentation, alignment, and tab stops
366
367
  * @param ctx - The context to update
367
368
  */
368
- parseParagraphProperties(e) {
369
- const t = new f(this.extractExpression());
370
- let r = e.paragraph.indent, a = e.paragraph.left, i = e.paragraph.right, h = e.paragraph.align, u = [];
369
+ parseParagraphProperties(t) {
370
+ const e = new g(this.extractExpression());
371
+ let r = t.paragraph.indent, a = t.paragraph.left, i = t.paragraph.right, h = t.paragraph.align, u = [];
371
372
  const n = () => {
372
- const l = t.tail.match(/^[+-]?\d+(?:\.\d*)?(?:[eE][+-]?\d+)?/);
373
+ const l = e.tail.match(/^[+-]?\d+(?:\.\d*)?(?:[eE][+-]?\d+)?/);
373
374
  if (l) {
374
375
  const o = parseFloat(l[0]);
375
- for (t.consume(l[0].length); t.peek() === ","; )
376
- t.consume(1);
376
+ for (e.consume(l[0].length); e.peek() === ","; )
377
+ e.consume(1);
377
378
  return o;
378
379
  }
379
380
  return 0;
380
381
  };
381
- for (; t.hasData; )
382
- switch (t.get()) {
382
+ for (; e.hasData; )
383
+ switch (e.get()) {
383
384
  case "i":
384
385
  r = n();
385
386
  break;
@@ -392,26 +393,26 @@ class O {
392
393
  case "x":
393
394
  break;
394
395
  case "q": {
395
- const o = t.get();
396
- for (h = _[o] || 0; t.peek() === ","; )
397
- t.consume(1);
396
+ const o = e.get();
397
+ for (h = S[o] || 0; e.peek() === ","; )
398
+ e.consume(1);
398
399
  break;
399
400
  }
400
401
  case "t":
401
- for (u = []; t.hasData; ) {
402
- const o = t.peek();
402
+ for (u = []; e.hasData; ) {
403
+ const o = e.peek();
403
404
  if (o === "r" || o === "c") {
404
- t.consume(1);
405
+ e.consume(1);
405
406
  const c = n();
406
407
  u.push(o + c.toString());
407
408
  } else {
408
409
  const c = n();
409
- isNaN(c) ? t.consume(1) : u.push(c);
410
+ isNaN(c) ? e.consume(1) : u.push(c);
410
411
  }
411
412
  }
412
413
  break;
413
414
  }
414
- e.paragraph = {
415
+ t.paragraph = {
415
416
  indent: r,
416
417
  left: a,
417
418
  right: i,
@@ -499,7 +500,7 @@ class O {
499
500
  continue;
500
501
  }
501
502
  if (n === "%" && this.scanner.peek(1) === "%") {
502
- const o = this.scanner.peek(2).toLowerCase(), c = m[o];
503
+ const o = this.scanner.peek(2).toLowerCase(), c = F[o];
503
504
  if (c) {
504
505
  this.scanner.consume(3), i += c;
505
506
  continue;
@@ -548,19 +549,19 @@ class O {
548
549
  for (; ; ) {
549
550
  const [i, h] = a();
550
551
  if (i)
551
- yield new d(i, this.ctx, h), r && (yield new d(r, this.ctx, null), r = null);
552
+ yield new b(i, this.ctx, h), r && (yield new b(r, this.ctx, null), r = null);
552
553
  else
553
554
  break;
554
555
  }
555
556
  }
556
557
  }
557
- class f {
558
+ class g {
558
559
  /**
559
560
  * Create a new text scanner
560
561
  * @param text - The text to scan
561
562
  */
562
- constructor(e) {
563
- this.text = e, this.textLen = e.length, this._index = 0;
563
+ constructor(t) {
564
+ this.text = t, this.textLen = t.length, this._index = 0;
564
565
  }
565
566
  /**
566
567
  * Get the current index in the text
@@ -587,24 +588,24 @@ class f {
587
588
  get() {
588
589
  if (this.isEmpty)
589
590
  return "";
590
- const e = this.text[this._index];
591
- return this._index++, e;
591
+ const t = this.text[this._index];
592
+ return this._index++, t;
592
593
  }
593
594
  /**
594
595
  * Advance the index by the specified count
595
596
  * @param count - Number of characters to advance
596
597
  */
597
- consume(e = 1) {
598
- this._index = Math.max(0, Math.min(this._index + e, this.textLen));
598
+ consume(t = 1) {
599
+ this._index = Math.max(0, Math.min(this._index + t, this.textLen));
599
600
  }
600
601
  /**
601
602
  * Look at a character without advancing the index
602
603
  * @param offset - Offset from current position
603
604
  * @returns The character at the offset position, or empty string if out of bounds
604
605
  */
605
- peek(e = 0) {
606
- const t = this._index + e;
607
- return t >= this.textLen || t < 0 ? "" : this.text[t];
606
+ peek(t = 0) {
607
+ const e = this._index + t;
608
+ return e >= this.textLen || e < 0 ? "" : this.text[e];
608
609
  }
609
610
  /**
610
611
  * Find the next occurrence of a character
@@ -612,12 +613,12 @@ class f {
612
613
  * @param escape - Whether to handle escaped characters
613
614
  * @returns Index of the character, or -1 if not found
614
615
  */
615
- find(e, t = !1) {
616
+ find(t, e = !1) {
616
617
  let r = this._index;
617
618
  for (; r < this.textLen; ) {
618
- if (t && this.text[r] === "\\") {
619
+ if (e && this.text[r] === "\\") {
619
620
  if (r + 1 < this.textLen) {
620
- if (this.text[r + 1] === e)
621
+ if (this.text[r + 1] === t)
621
622
  return r + 1;
622
623
  r += 2;
623
624
  continue;
@@ -625,7 +626,7 @@ class f {
625
626
  r++;
626
627
  continue;
627
628
  }
628
- if (this.text[r] === e)
629
+ if (this.text[r] === t)
629
630
  return r;
630
631
  r++;
631
632
  }
@@ -648,15 +649,110 @@ class f {
648
649
  * @returns Number of spaces consumed
649
650
  */
650
651
  consumeSpaces() {
651
- let e = 0;
652
+ let t = 0;
652
653
  for (; this.isNextSpace(); )
653
- this.consume(), e++;
654
- return e;
654
+ this.consume(), t++;
655
+ return t;
655
656
  }
656
657
  }
657
- class g {
658
+ class f {
659
+ // Store as 0xRRGGBB or null
660
+ /**
661
+ * Create a new MTextColor instance.
662
+ * @param color The initial color: number for ACI, [r,g,b] for RGB, or null/undefined for default (ACI=256).
663
+ */
664
+ constructor(t) {
665
+ this._aci = 256, this._rgbValue = null, Array.isArray(t) ? this.rgb = t : typeof t == "number" ? this.aci = t : this.aci = 256;
666
+ }
667
+ /**
668
+ * Get the current ACI color value.
669
+ * @returns The ACI color (0-256), or null if using RGB.
670
+ */
671
+ get aci() {
672
+ return this._aci;
673
+ }
674
+ /**
675
+ * Set the ACI color value. Setting this disables any RGB color.
676
+ * @param value The ACI color (0-256), or null to unset.
677
+ * @throws Error if value is out of range.
678
+ */
679
+ set aci(t) {
680
+ if (t === null)
681
+ this._aci = null;
682
+ else if (t >= 0 && t <= 256)
683
+ this._aci = t, this._rgbValue = null;
684
+ else
685
+ throw new Error("ACI not in range [0, 256]");
686
+ }
687
+ /**
688
+ * Get the current RGB color as a tuple [r, g, b], or null if not set.
689
+ * @returns The RGB color tuple, or null if using ACI.
690
+ */
691
+ get rgb() {
692
+ if (this._rgbValue === null) return null;
693
+ const t = this._rgbValue >> 16 & 255, e = this._rgbValue >> 8 & 255, r = this._rgbValue & 255;
694
+ return [t, e, r];
695
+ }
696
+ /**
697
+ * Set the RGB color. Setting this disables ACI color.
698
+ * @param value The RGB color tuple [r, g, b], or null to use ACI.
699
+ */
700
+ set rgb(t) {
701
+ if (t) {
702
+ const [e, r, a] = t;
703
+ this._rgbValue = (e & 255) << 16 | (r & 255) << 8 | a & 255, this._aci = null;
704
+ } else
705
+ this._rgbValue = null;
706
+ }
707
+ /**
708
+ * Returns true if the color is set by RGB, false if by ACI.
709
+ */
710
+ get isRgb() {
711
+ return this._rgbValue !== null;
712
+ }
713
+ /**
714
+ * Returns true if the color is set by ACI, false if by RGB.
715
+ */
716
+ get isAci() {
717
+ return this._rgbValue === null && this._aci !== null;
718
+ }
719
+ /**
720
+ * Get or set the internal RGB value as a number (0xRRGGBB), or null if not set.
721
+ * Setting this will switch to RGB mode and set ACI to null.
722
+ */
723
+ get rgbValue() {
724
+ return this._rgbValue;
725
+ }
726
+ set rgbValue(t) {
727
+ t === null ? this._rgbValue = null : (this._rgbValue = t & 16777215, this._aci = null);
728
+ }
729
+ /**
730
+ * Returns a deep copy of this color.
731
+ * @returns A new MTextColor instance with the same color state.
732
+ */
733
+ copy() {
734
+ const t = new f();
735
+ return t._aci = this._aci, t._rgbValue = this._rgbValue, t;
736
+ }
737
+ /**
738
+ * Returns a plain object for serialization.
739
+ * @returns An object with aci, rgb (tuple), and rgbValue (number or null).
740
+ */
741
+ toObject() {
742
+ return { aci: this._aci, rgb: this.rgb, rgbValue: this._rgbValue };
743
+ }
744
+ /**
745
+ * Equality check for color.
746
+ * @param other The other MTextColor to compare.
747
+ * @returns True if both ACI and RGB values are equal.
748
+ */
749
+ equals(t) {
750
+ return this._aci === t._aci && this._rgbValue === t._rgbValue;
751
+ }
752
+ }
753
+ class d {
658
754
  constructor() {
659
- this._stroke = 0, this.continueStroke = !1, this._aci = 7, this.rgb = null, this.align = 0, this.fontFace = { family: "", style: "Regular", weight: 400 }, this._capHeight = { value: 1, isRelative: !1 }, this._widthFactor = { value: 1, isRelative: !1 }, this._charTrackingFactor = { value: 1, isRelative: !1 }, this.oblique = 0, this.paragraph = {
755
+ this._stroke = 0, this.continueStroke = !1, this.color = new f(), this.align = 0, this.fontFace = { family: "", style: "Regular", weight: 400 }, this._capHeight = { value: 1, isRelative: !1 }, this._widthFactor = { value: 1, isRelative: !1 }, this._charTrackingFactor = { value: 1, isRelative: !1 }, this.oblique = 0, this.paragraph = {
660
756
  indent: 0,
661
757
  left: 0,
662
758
  right: 0,
@@ -674,10 +770,10 @@ class g {
674
770
  * Set the capital letter height
675
771
  * @param value - Height value
676
772
  */
677
- set capHeight(e) {
773
+ set capHeight(t) {
678
774
  this._capHeight = {
679
- value: Math.abs(e.value),
680
- isRelative: e.isRelative
775
+ value: Math.abs(t.value),
776
+ isRelative: t.isRelative
681
777
  };
682
778
  }
683
779
  /**
@@ -690,10 +786,10 @@ class g {
690
786
  * Set the character width factor
691
787
  * @param value - Width factor value
692
788
  */
693
- set widthFactor(e) {
789
+ set widthFactor(t) {
694
790
  this._widthFactor = {
695
- value: Math.abs(e.value),
696
- isRelative: e.isRelative
791
+ value: Math.abs(t.value),
792
+ isRelative: t.isRelative
697
793
  };
698
794
  }
699
795
  /**
@@ -706,28 +802,37 @@ class g {
706
802
  * Set the character tracking factor
707
803
  * @param value - Tracking factor value
708
804
  */
709
- set charTrackingFactor(e) {
805
+ set charTrackingFactor(t) {
710
806
  this._charTrackingFactor = {
711
- value: Math.abs(e.value),
712
- isRelative: e.isRelative
807
+ value: Math.abs(t.value),
808
+ isRelative: t.isRelative
713
809
  };
714
810
  }
715
811
  /**
716
812
  * Get the ACI color value
717
813
  */
718
814
  get aci() {
719
- return this._aci;
815
+ return this.color.aci;
720
816
  }
721
817
  /**
722
818
  * Set the ACI color value
723
819
  * @param value - ACI color value (0-256)
724
820
  * @throws Error if value is out of range
725
821
  */
726
- set aci(e) {
727
- if (e >= 0 && e <= 256)
728
- this._aci = e, this.rgb = null;
729
- else
730
- throw new Error("ACI not in range [0, 256]");
822
+ set aci(t) {
823
+ this.color.aci = t;
824
+ }
825
+ /**
826
+ * Get the RGB color value
827
+ */
828
+ get rgb() {
829
+ return this.color.rgb;
830
+ }
831
+ /**
832
+ * Set the RGB color value
833
+ */
834
+ set rgb(t) {
835
+ this.color.rgb = t;
731
836
  }
732
837
  /**
733
838
  * Get whether text is underlined
@@ -739,8 +844,8 @@ class g {
739
844
  * Set whether text is underlined
740
845
  * @param value - Whether to underline
741
846
  */
742
- set underline(e) {
743
- this._setStrokeState(1, e);
847
+ set underline(t) {
848
+ this._setStrokeState(1, t);
744
849
  }
745
850
  /**
746
851
  * Get whether text has strike-through
@@ -752,8 +857,8 @@ class g {
752
857
  * Set whether text has strike-through
753
858
  * @param value - Whether to strike through
754
859
  */
755
- set strikeThrough(e) {
756
- this._setStrokeState(4, e);
860
+ set strikeThrough(t) {
861
+ this._setStrokeState(4, t);
757
862
  }
758
863
  /**
759
864
  * Get whether text has overline
@@ -765,8 +870,8 @@ class g {
765
870
  * Set whether text has overline
766
871
  * @param value - Whether to overline
767
872
  */
768
- set overline(e) {
769
- this._setStrokeState(2, e);
873
+ set overline(t) {
874
+ this._setStrokeState(2, t);
770
875
  }
771
876
  /**
772
877
  * Check if any stroke formatting is active
@@ -779,42 +884,43 @@ class g {
779
884
  * @param stroke - The stroke type to set
780
885
  * @param state - Whether to enable or disable the stroke
781
886
  */
782
- _setStrokeState(e, t = !0) {
783
- t ? this._stroke |= e : this._stroke &= ~e;
887
+ _setStrokeState(t, e = !0) {
888
+ e ? this._stroke |= t : this._stroke &= ~t;
784
889
  }
785
890
  /**
786
891
  * Create a copy of this context
787
892
  * @returns A new context with the same properties
788
893
  */
789
894
  copy() {
790
- const e = new g();
791
- return e._stroke = this._stroke, e.continueStroke = this.continueStroke, e._aci = this._aci, e.rgb = this.rgb, e.align = this.align, e.fontFace = { ...this.fontFace }, e._capHeight = { ...this._capHeight }, e._widthFactor = { ...this._widthFactor }, e._charTrackingFactor = { ...this._charTrackingFactor }, e.oblique = this.oblique, e.paragraph = { ...this.paragraph }, e;
895
+ const t = new d();
896
+ return t._stroke = this._stroke, t.continueStroke = this.continueStroke, t.color = this.color.copy(), t.align = this.align, t.fontFace = { ...this.fontFace }, t._capHeight = { ...this._capHeight }, t._widthFactor = { ...this._widthFactor }, t._charTrackingFactor = { ...this._charTrackingFactor }, t.oblique = this.oblique, t.paragraph = { ...this.paragraph }, t;
792
897
  }
793
898
  }
794
- class d {
899
+ class b {
795
900
  /**
796
901
  * Create a new MText token
797
902
  * @param type - The token type
798
903
  * @param ctx - The text context at this token
799
904
  * @param data - Optional token data
800
905
  */
801
- constructor(e, t, r) {
802
- this.type = e, this.ctx = t, this.data = r;
906
+ constructor(t, e, r) {
907
+ this.type = t, this.ctx = e, this.data = r;
803
908
  }
804
909
  }
805
910
  export {
806
- g as MTextContext,
807
- b as MTextLineAlignment,
808
- E as MTextParagraphAlignment,
809
- O as MTextParser,
810
- F as MTextStroke,
811
- d as MTextToken,
812
- f as TextScanner,
911
+ f as MTextColor,
912
+ d as MTextContext,
913
+ _ as MTextLineAlignment,
914
+ m as MTextParagraphAlignment,
915
+ D as MTextParser,
916
+ E as MTextStroke,
917
+ b as MTextToken,
918
+ g as TextScanner,
813
919
  k as TokenType,
814
- v as escapeDxfLineEndings,
815
- N as getFonts,
816
- I as hasInlineFormattingCodes,
817
- S as int2rgb,
920
+ I as escapeDxfLineEndings,
921
+ O as getFonts,
922
+ N as hasInlineFormattingCodes,
923
+ v as int2rgb,
818
924
  R as rgb2int
819
925
  };
820
926
  //# sourceMappingURL=parser.es.js.map