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