@mlightcad/mtext-parser 1.0.4 → 1.0.6
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.cjs.js +3 -3
- package/dist/parser.cjs.js.map +1 -1
- package/dist/parser.es.js +185 -119
- package/dist/parser.es.js.map +1 -1
- package/dist/parser.umd.js +3 -3
- package/dist/parser.umd.js.map +1 -1
- package/dist/types/parser.d.ts +43 -7
- package/package.json +1 -1
package/dist/parser.es.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
var k = /* @__PURE__ */ ((
|
|
2
|
-
const
|
|
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 = {
|
|
3
3
|
c: "Ø",
|
|
4
4
|
d: "°",
|
|
5
5
|
p: "±"
|
|
6
|
-
},
|
|
6
|
+
}, _ = {
|
|
7
7
|
l: 1,
|
|
8
8
|
r: 2,
|
|
9
9
|
c: 3,
|
|
@@ -11,36 +11,36 @@ const F = {
|
|
|
11
11
|
d: 5
|
|
12
12
|
/* DISTRIBUTED */
|
|
13
13
|
};
|
|
14
|
-
function
|
|
15
|
-
const [e, t,
|
|
16
|
-
return
|
|
14
|
+
function v(s) {
|
|
15
|
+
const [e, t, r] = s;
|
|
16
|
+
return r << 16 | t << 8 | e;
|
|
17
17
|
}
|
|
18
|
-
function
|
|
19
|
-
const e =
|
|
20
|
-
return [e, t,
|
|
18
|
+
function R(s) {
|
|
19
|
+
const e = s & 255, t = s >> 8 & 255, r = s >> 16 & 255;
|
|
20
|
+
return [e, t, r];
|
|
21
21
|
}
|
|
22
|
-
function
|
|
23
|
-
return
|
|
24
|
-
const
|
|
25
|
-
return
|
|
26
|
-
` :
|
|
22
|
+
function S(s) {
|
|
23
|
+
return s.replace(/\^(.)/g, (e, t) => {
|
|
24
|
+
const r = t.charCodeAt(0);
|
|
25
|
+
return r === 32 ? "^" : r === 73 ? " " : r === 74 ? `
|
|
26
|
+
` : r === 77 ? "" : "▯";
|
|
27
27
|
});
|
|
28
28
|
}
|
|
29
|
-
function
|
|
30
|
-
return
|
|
29
|
+
function I(s) {
|
|
30
|
+
return s.replace(/\r\n|\r|\n/g, "\\P");
|
|
31
31
|
}
|
|
32
|
-
function
|
|
33
|
-
return
|
|
32
|
+
function N(s) {
|
|
33
|
+
return s.replace(/\\P/g, "").replace(/\\~/g, "").includes("\\");
|
|
34
34
|
}
|
|
35
|
-
class
|
|
35
|
+
class O {
|
|
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,
|
|
43
|
-
this.ctxStack = [], this.continueStroke = !1, this.scanner = new p(
|
|
42
|
+
constructor(e, t, r = !1) {
|
|
43
|
+
this.ctxStack = [], this.continueStroke = !1, this.scanner = new p(S(e)), this.ctx = t ?? new g(), this.lastCtx = this.ctx.copy(), this.yieldPropertyCommands = r, this.decoder = new TextDecoder("gbk");
|
|
44
44
|
}
|
|
45
45
|
/**
|
|
46
46
|
* Decode multi-byte character from hex code
|
|
@@ -76,28 +76,28 @@ class D {
|
|
|
76
76
|
*/
|
|
77
77
|
parseStacking() {
|
|
78
78
|
const e = new p(this.extractExpression(!0));
|
|
79
|
-
let t = "",
|
|
79
|
+
let t = "", r = "", n = "";
|
|
80
80
|
const i = () => {
|
|
81
|
-
let a = e.peek(),
|
|
82
|
-
return a.charCodeAt(0) < 32 && (a = " "), a === "\\" && (
|
|
81
|
+
let a = e.peek(), o = !1;
|
|
82
|
+
return a.charCodeAt(0) < 32 && (a = " "), a === "\\" && (o = !0, e.consume(1), a = e.peek()), e.consume(1), [a, o];
|
|
83
83
|
}, c = () => {
|
|
84
84
|
let a = "";
|
|
85
85
|
for (; e.hasData; ) {
|
|
86
|
-
const [
|
|
87
|
-
if (!
|
|
88
|
-
return [a,
|
|
89
|
-
a +=
|
|
86
|
+
const [o, h] = i();
|
|
87
|
+
if (!h && "^/#".includes(o))
|
|
88
|
+
return [a, o];
|
|
89
|
+
a += o;
|
|
90
90
|
}
|
|
91
91
|
return [a, ""];
|
|
92
|
-
},
|
|
92
|
+
}, u = () => {
|
|
93
93
|
let a = "";
|
|
94
94
|
for (; e.hasData; ) {
|
|
95
|
-
const [
|
|
96
|
-
|
|
95
|
+
const [o, h] = i();
|
|
96
|
+
h && o === ";" ? a += ";" : a += o;
|
|
97
97
|
}
|
|
98
98
|
return a;
|
|
99
99
|
};
|
|
100
|
-
return [t, n] = c(), n && (
|
|
100
|
+
return [t, n] = c(), n && (r = u()), [2, [t, r, n]];
|
|
101
101
|
}
|
|
102
102
|
/**
|
|
103
103
|
* Parse MText properties
|
|
@@ -157,11 +157,11 @@ class D {
|
|
|
157
157
|
throw new Error(`Unknown command: ${e}`);
|
|
158
158
|
}
|
|
159
159
|
if (t.continueStroke = this.continueStroke, this.ctx = t, this.yieldPropertyCommands) {
|
|
160
|
-
const
|
|
161
|
-
if (Object.keys(
|
|
160
|
+
const r = this.getPropertyChanges(this.lastCtx, t);
|
|
161
|
+
if (Object.keys(r).length > 0)
|
|
162
162
|
return this.lastCtx = this.ctx.copy(), {
|
|
163
163
|
command: e,
|
|
164
|
-
changes:
|
|
164
|
+
changes: r
|
|
165
165
|
};
|
|
166
166
|
}
|
|
167
167
|
}
|
|
@@ -172,12 +172,12 @@ class D {
|
|
|
172
172
|
* @returns Object containing changed properties
|
|
173
173
|
*/
|
|
174
174
|
getPropertyChanges(e, t) {
|
|
175
|
-
const
|
|
176
|
-
if (e.underline !== t.underline && (
|
|
175
|
+
const r = {};
|
|
176
|
+
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)) {
|
|
177
177
|
const n = {};
|
|
178
|
-
e.paragraph.indent !== t.paragraph.indent && (n.indent = t.paragraph.indent), e.paragraph.align !== t.paragraph.align && (n.align = t.paragraph.align), e.paragraph.left !== t.paragraph.left && (n.left = t.paragraph.left), e.paragraph.right !== t.paragraph.right && (n.right = t.paragraph.right), JSON.stringify(e.paragraph.tab_stops) !== JSON.stringify(t.paragraph.tab_stops) && (n.tab_stops = t.paragraph.tab_stops), Object.keys(n).length > 0 && (
|
|
178
|
+
e.paragraph.indent !== t.paragraph.indent && (n.indent = t.paragraph.indent), e.paragraph.align !== t.paragraph.align && (n.align = t.paragraph.align), e.paragraph.left !== t.paragraph.left && (n.left = t.paragraph.left), e.paragraph.right !== t.paragraph.right && (n.right = t.paragraph.right), JSON.stringify(e.paragraph.tab_stops) !== JSON.stringify(t.paragraph.tab_stops) && (n.tab_stops = t.paragraph.tab_stops), Object.keys(n).length > 0 && (r.paragraph = n);
|
|
179
179
|
}
|
|
180
|
-
return
|
|
180
|
+
return r;
|
|
181
181
|
}
|
|
182
182
|
/**
|
|
183
183
|
* Parse alignment property
|
|
@@ -195,7 +195,13 @@ class D {
|
|
|
195
195
|
const t = this.extractFloatExpression(!0);
|
|
196
196
|
if (t)
|
|
197
197
|
try {
|
|
198
|
-
t.endsWith("x") ? e.capHeight =
|
|
198
|
+
t.endsWith("x") ? e.capHeight = {
|
|
199
|
+
value: parseFloat(t.slice(0, -1)),
|
|
200
|
+
isRelative: !0
|
|
201
|
+
} : e.capHeight = {
|
|
202
|
+
value: parseFloat(t),
|
|
203
|
+
isRelative: !1
|
|
204
|
+
};
|
|
199
205
|
} catch {
|
|
200
206
|
this.scanner.consume(-t.length);
|
|
201
207
|
return;
|
|
@@ -210,7 +216,13 @@ class D {
|
|
|
210
216
|
const t = this.extractFloatExpression(!0);
|
|
211
217
|
if (t)
|
|
212
218
|
try {
|
|
213
|
-
t.endsWith("x") ? e.widthFactor =
|
|
219
|
+
t.endsWith("x") ? e.widthFactor = {
|
|
220
|
+
value: parseFloat(t.slice(0, -1)),
|
|
221
|
+
isRelative: !0
|
|
222
|
+
} : e.widthFactor = {
|
|
223
|
+
value: parseFloat(t),
|
|
224
|
+
isRelative: !1
|
|
225
|
+
};
|
|
214
226
|
} catch {
|
|
215
227
|
this.scanner.consume(-t.length);
|
|
216
228
|
return;
|
|
@@ -225,7 +237,13 @@ class D {
|
|
|
225
237
|
const t = this.extractFloatExpression(!0);
|
|
226
238
|
if (t)
|
|
227
239
|
try {
|
|
228
|
-
t.endsWith("x") ? e.charTrackingFactor =
|
|
240
|
+
t.endsWith("x") ? e.charTrackingFactor = {
|
|
241
|
+
value: Math.abs(parseFloat(t.slice(0, -1))),
|
|
242
|
+
isRelative: !0
|
|
243
|
+
} : e.charTrackingFactor = {
|
|
244
|
+
value: Math.abs(parseFloat(t)),
|
|
245
|
+
isRelative: !1
|
|
246
|
+
};
|
|
229
247
|
} catch {
|
|
230
248
|
this.scanner.consume(-t.length);
|
|
231
249
|
return;
|
|
@@ -241,8 +259,8 @@ class D {
|
|
|
241
259
|
const t = this.extractFloatExpression(!0);
|
|
242
260
|
if (t)
|
|
243
261
|
if (t.endsWith("x")) {
|
|
244
|
-
const
|
|
245
|
-
e *= Math.abs(
|
|
262
|
+
const r = parseFloat(t.slice(0, -1));
|
|
263
|
+
e *= Math.abs(r);
|
|
246
264
|
} else
|
|
247
265
|
e = Math.abs(parseFloat(t));
|
|
248
266
|
return e;
|
|
@@ -262,8 +280,8 @@ class D {
|
|
|
262
280
|
parseAciColor(e) {
|
|
263
281
|
const t = this.extractIntExpression();
|
|
264
282
|
if (t) {
|
|
265
|
-
const
|
|
266
|
-
|
|
283
|
+
const r = parseInt(t);
|
|
284
|
+
r < 257 && (e.aci = r, e.rgb = null);
|
|
267
285
|
}
|
|
268
286
|
this.consumeOptionalTerminator();
|
|
269
287
|
}
|
|
@@ -274,7 +292,7 @@ class D {
|
|
|
274
292
|
parseRgbColor(e) {
|
|
275
293
|
const t = this.extractIntExpression();
|
|
276
294
|
if (t) {
|
|
277
|
-
const
|
|
295
|
+
const r = parseInt(t) & 16777215, [n, i, c] = R(r);
|
|
278
296
|
e.rgb = [c, i, n];
|
|
279
297
|
}
|
|
280
298
|
this.consumeOptionalTerminator();
|
|
@@ -285,9 +303,9 @@ class D {
|
|
|
285
303
|
* @returns Extracted expression
|
|
286
304
|
*/
|
|
287
305
|
extractFloatExpression(e = !1) {
|
|
288
|
-
const t = e ? /^[+-]?(?:\d+(?:\.\d*)?|\.\d+)(?:[eE][+-]?\d+)?x?/ : /^[+-]?(?:\d+(?:\.\d*)?|\.\d+)(?:[eE][+-]?\d+)?/,
|
|
289
|
-
if (
|
|
290
|
-
const n =
|
|
306
|
+
const t = e ? /^[+-]?(?:\d+(?:\.\d*)?|\.\d+)(?:[eE][+-]?\d+)?x?/ : /^[+-]?(?:\d+(?:\.\d*)?|\.\d+)(?:[eE][+-]?\d+)?/, r = this.scanner.tail.match(t);
|
|
307
|
+
if (r) {
|
|
308
|
+
const n = r[0];
|
|
291
309
|
return this.scanner.consume(n.length), n;
|
|
292
310
|
}
|
|
293
311
|
return "";
|
|
@@ -325,12 +343,12 @@ class D {
|
|
|
325
343
|
parseFontProperties(e) {
|
|
326
344
|
const t = this.extractExpression().split("|");
|
|
327
345
|
if (t.length > 0 && t[0]) {
|
|
328
|
-
const
|
|
346
|
+
const r = t[0];
|
|
329
347
|
let n = "Regular", i = 400;
|
|
330
348
|
for (const c of t.slice(1))
|
|
331
349
|
c.startsWith("b1") ? i = 700 : c.startsWith("i1") && (n = "Italic");
|
|
332
350
|
e.fontFace = {
|
|
333
|
-
family:
|
|
351
|
+
family: r,
|
|
334
352
|
style: n,
|
|
335
353
|
weight: i
|
|
336
354
|
};
|
|
@@ -343,21 +361,21 @@ class D {
|
|
|
343
361
|
*/
|
|
344
362
|
parseParagraphProperties(e) {
|
|
345
363
|
const t = new p(this.extractExpression());
|
|
346
|
-
let
|
|
364
|
+
let r = e.paragraph.indent, n = e.paragraph.left, i = e.paragraph.right, c = e.paragraph.align, u = [];
|
|
347
365
|
const a = () => {
|
|
348
|
-
const
|
|
349
|
-
if (
|
|
350
|
-
const
|
|
351
|
-
for (t.consume(
|
|
366
|
+
const o = t.tail.match(/^[+-]?\d+(?:\.\d*)?(?:[eE][+-]?\d+)?/);
|
|
367
|
+
if (o) {
|
|
368
|
+
const h = parseFloat(o[0]);
|
|
369
|
+
for (t.consume(o[0].length); t.peek() === ","; )
|
|
352
370
|
t.consume(1);
|
|
353
|
-
return
|
|
371
|
+
return h;
|
|
354
372
|
}
|
|
355
373
|
return 0;
|
|
356
374
|
};
|
|
357
375
|
for (; t.hasData; )
|
|
358
376
|
switch (t.get()) {
|
|
359
377
|
case "i":
|
|
360
|
-
|
|
378
|
+
r = a();
|
|
361
379
|
break;
|
|
362
380
|
case "l":
|
|
363
381
|
n = a();
|
|
@@ -368,31 +386,31 @@ class D {
|
|
|
368
386
|
case "x":
|
|
369
387
|
break;
|
|
370
388
|
case "q": {
|
|
371
|
-
const
|
|
372
|
-
for (c =
|
|
389
|
+
const h = t.get();
|
|
390
|
+
for (c = _[h] || 0; t.peek() === ","; )
|
|
373
391
|
t.consume(1);
|
|
374
392
|
break;
|
|
375
393
|
}
|
|
376
394
|
case "t":
|
|
377
|
-
for (
|
|
378
|
-
const
|
|
379
|
-
if (
|
|
395
|
+
for (u = []; t.hasData; ) {
|
|
396
|
+
const h = t.peek();
|
|
397
|
+
if (h === "r" || h === "c") {
|
|
380
398
|
t.consume(1);
|
|
381
|
-
const
|
|
382
|
-
|
|
399
|
+
const l = a();
|
|
400
|
+
u.push(h + l.toString());
|
|
383
401
|
} else {
|
|
384
|
-
const
|
|
385
|
-
isNaN(
|
|
402
|
+
const l = a();
|
|
403
|
+
isNaN(l) ? t.consume(1) : u.push(l);
|
|
386
404
|
}
|
|
387
405
|
}
|
|
388
406
|
break;
|
|
389
407
|
}
|
|
390
408
|
e.paragraph = {
|
|
391
|
-
indent:
|
|
409
|
+
indent: r,
|
|
392
410
|
left: n,
|
|
393
411
|
right: i,
|
|
394
412
|
align: c,
|
|
395
|
-
tab_stops:
|
|
413
|
+
tab_stops: u
|
|
396
414
|
};
|
|
397
415
|
}
|
|
398
416
|
/**
|
|
@@ -406,13 +424,13 @@ class D {
|
|
|
406
424
|
* @yields MTextToken objects
|
|
407
425
|
*/
|
|
408
426
|
*parse() {
|
|
409
|
-
let
|
|
427
|
+
let r = null;
|
|
410
428
|
const n = () => {
|
|
411
429
|
var c;
|
|
412
430
|
let i = "";
|
|
413
431
|
for (; this.scanner.hasData; ) {
|
|
414
|
-
let
|
|
415
|
-
const
|
|
432
|
+
let u = !1, a = this.scanner.peek();
|
|
433
|
+
const o = this.scanner.currentIndex;
|
|
416
434
|
if (a.charCodeAt(0) < 32) {
|
|
417
435
|
if (this.scanner.consume(1), a === " ")
|
|
418
436
|
return [5, null];
|
|
@@ -423,13 +441,13 @@ class D {
|
|
|
423
441
|
}
|
|
424
442
|
if (a === "\\")
|
|
425
443
|
if ("\\{}".includes(this.scanner.peek(1)))
|
|
426
|
-
|
|
444
|
+
u = !0, this.scanner.consume(1), a = this.scanner.peek();
|
|
427
445
|
else {
|
|
428
446
|
if (i)
|
|
429
447
|
return [1, i];
|
|
430
448
|
this.scanner.consume(1);
|
|
431
|
-
const
|
|
432
|
-
switch (
|
|
449
|
+
const h = this.scanner.get();
|
|
450
|
+
switch (h) {
|
|
433
451
|
case "~":
|
|
434
452
|
return [4, null];
|
|
435
453
|
case "P":
|
|
@@ -444,10 +462,10 @@ class D {
|
|
|
444
462
|
case "M":
|
|
445
463
|
if (this.scanner.peek() === "+") {
|
|
446
464
|
this.scanner.consume(1);
|
|
447
|
-
const
|
|
448
|
-
if (
|
|
465
|
+
const l = (c = this.scanner.tail.match(/^[0-9A-Fa-f]{4}/)) == null ? void 0 : c[0];
|
|
466
|
+
if (l) {
|
|
449
467
|
this.scanner.consume(4);
|
|
450
|
-
const d = this.decodeMultiByteChar(
|
|
468
|
+
const d = this.decodeMultiByteChar(l);
|
|
451
469
|
return i ? [1, i] : [1, d];
|
|
452
470
|
}
|
|
453
471
|
this.scanner.consume(-1);
|
|
@@ -455,26 +473,26 @@ class D {
|
|
|
455
473
|
i += "\\M";
|
|
456
474
|
continue;
|
|
457
475
|
default:
|
|
458
|
-
if (
|
|
476
|
+
if (h)
|
|
459
477
|
try {
|
|
460
|
-
const
|
|
461
|
-
if (this.yieldPropertyCommands &&
|
|
462
|
-
return this.lastCtx = this.ctx.copy(), [9,
|
|
478
|
+
const l = this.parseProperties(h);
|
|
479
|
+
if (this.yieldPropertyCommands && l)
|
|
480
|
+
return this.lastCtx = this.ctx.copy(), [9, l];
|
|
463
481
|
continue;
|
|
464
482
|
} catch {
|
|
465
|
-
const
|
|
466
|
-
|
|
483
|
+
const l = this.scanner.tail.slice(
|
|
484
|
+
o,
|
|
467
485
|
this.scanner.currentIndex
|
|
468
486
|
);
|
|
469
|
-
i +=
|
|
487
|
+
i += l;
|
|
470
488
|
}
|
|
471
489
|
}
|
|
472
490
|
continue;
|
|
473
491
|
}
|
|
474
492
|
if (a === "%" && this.scanner.peek(1) === "%") {
|
|
475
|
-
const
|
|
476
|
-
if (
|
|
477
|
-
this.scanner.consume(3), i +=
|
|
493
|
+
const h = this.scanner.peek(2).toLowerCase(), l = m[h];
|
|
494
|
+
if (l) {
|
|
495
|
+
this.scanner.consume(3), i += l;
|
|
478
496
|
continue;
|
|
479
497
|
} else {
|
|
480
498
|
this.scanner.consume(3);
|
|
@@ -482,8 +500,8 @@ class D {
|
|
|
482
500
|
}
|
|
483
501
|
}
|
|
484
502
|
if (a === " ")
|
|
485
|
-
return i ? (this.scanner.consume(1),
|
|
486
|
-
if (!
|
|
503
|
+
return i ? (this.scanner.consume(1), r = 3, [1, i]) : (this.scanner.consume(1), [3, null]);
|
|
504
|
+
if (!u) {
|
|
487
505
|
if (a === "{") {
|
|
488
506
|
if (i)
|
|
489
507
|
return [1, i];
|
|
@@ -503,7 +521,7 @@ class D {
|
|
|
503
521
|
for (; ; ) {
|
|
504
522
|
const [i, c] = n();
|
|
505
523
|
if (i)
|
|
506
|
-
yield new
|
|
524
|
+
yield new f(i, this.ctx, c), r && (yield new f(r, this.ctx, null), r = null);
|
|
507
525
|
else
|
|
508
526
|
break;
|
|
509
527
|
}
|
|
@@ -568,21 +586,21 @@ class p {
|
|
|
568
586
|
* @returns Index of the character, or -1 if not found
|
|
569
587
|
*/
|
|
570
588
|
find(e, t = !1) {
|
|
571
|
-
let
|
|
572
|
-
for (;
|
|
573
|
-
if (t && this.text[
|
|
574
|
-
if (
|
|
575
|
-
if (this.text[
|
|
576
|
-
return
|
|
577
|
-
|
|
589
|
+
let r = this._index;
|
|
590
|
+
for (; r < this.textLen; ) {
|
|
591
|
+
if (t && this.text[r] === "\\") {
|
|
592
|
+
if (r + 1 < this.textLen) {
|
|
593
|
+
if (this.text[r + 1] === e)
|
|
594
|
+
return r + 1;
|
|
595
|
+
r += 2;
|
|
578
596
|
continue;
|
|
579
597
|
}
|
|
580
|
-
|
|
598
|
+
r++;
|
|
581
599
|
continue;
|
|
582
600
|
}
|
|
583
|
-
if (this.text[
|
|
584
|
-
return
|
|
585
|
-
|
|
601
|
+
if (this.text[r] === e)
|
|
602
|
+
return r;
|
|
603
|
+
r++;
|
|
586
604
|
}
|
|
587
605
|
return -1;
|
|
588
606
|
}
|
|
@@ -609,9 +627,9 @@ class p {
|
|
|
609
627
|
return e;
|
|
610
628
|
}
|
|
611
629
|
}
|
|
612
|
-
class
|
|
630
|
+
class g {
|
|
613
631
|
constructor() {
|
|
614
|
-
this._stroke = 0, this.continueStroke = !1, this._aci = 7, this.rgb = null, this.align = 0, this.fontFace = { family: "", style: "Regular", weight: 400 }, this.
|
|
632
|
+
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 = {
|
|
615
633
|
indent: 0,
|
|
616
634
|
left: 0,
|
|
617
635
|
right: 0,
|
|
@@ -619,6 +637,54 @@ class f {
|
|
|
619
637
|
tab_stops: []
|
|
620
638
|
};
|
|
621
639
|
}
|
|
640
|
+
/**
|
|
641
|
+
* Get the capital letter height
|
|
642
|
+
*/
|
|
643
|
+
get capHeight() {
|
|
644
|
+
return this._capHeight;
|
|
645
|
+
}
|
|
646
|
+
/**
|
|
647
|
+
* Set the capital letter height
|
|
648
|
+
* @param value - Height value
|
|
649
|
+
*/
|
|
650
|
+
set capHeight(e) {
|
|
651
|
+
this._capHeight = {
|
|
652
|
+
value: Math.abs(e.value),
|
|
653
|
+
isRelative: e.isRelative
|
|
654
|
+
};
|
|
655
|
+
}
|
|
656
|
+
/**
|
|
657
|
+
* Get the character width factor
|
|
658
|
+
*/
|
|
659
|
+
get widthFactor() {
|
|
660
|
+
return this._widthFactor;
|
|
661
|
+
}
|
|
662
|
+
/**
|
|
663
|
+
* Set the character width factor
|
|
664
|
+
* @param value - Width factor value
|
|
665
|
+
*/
|
|
666
|
+
set widthFactor(e) {
|
|
667
|
+
this._widthFactor = {
|
|
668
|
+
value: Math.abs(e.value),
|
|
669
|
+
isRelative: e.isRelative
|
|
670
|
+
};
|
|
671
|
+
}
|
|
672
|
+
/**
|
|
673
|
+
* Get the character tracking factor
|
|
674
|
+
*/
|
|
675
|
+
get charTrackingFactor() {
|
|
676
|
+
return this._charTrackingFactor;
|
|
677
|
+
}
|
|
678
|
+
/**
|
|
679
|
+
* Set the character tracking factor
|
|
680
|
+
* @param value - Tracking factor value
|
|
681
|
+
*/
|
|
682
|
+
set charTrackingFactor(e) {
|
|
683
|
+
this._charTrackingFactor = {
|
|
684
|
+
value: Math.abs(e.value),
|
|
685
|
+
isRelative: e.isRelative
|
|
686
|
+
};
|
|
687
|
+
}
|
|
622
688
|
/**
|
|
623
689
|
* Get the ACI color value
|
|
624
690
|
*/
|
|
@@ -694,34 +760,34 @@ class f {
|
|
|
694
760
|
* @returns A new context with the same properties
|
|
695
761
|
*/
|
|
696
762
|
copy() {
|
|
697
|
-
const e = new
|
|
698
|
-
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.
|
|
763
|
+
const e = new g();
|
|
764
|
+
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;
|
|
699
765
|
}
|
|
700
766
|
}
|
|
701
|
-
class
|
|
767
|
+
class f {
|
|
702
768
|
/**
|
|
703
769
|
* Create a new MText token
|
|
704
770
|
* @param type - The token type
|
|
705
771
|
* @param ctx - The text context at this token
|
|
706
772
|
* @param data - Optional token data
|
|
707
773
|
*/
|
|
708
|
-
constructor(e, t,
|
|
709
|
-
this.type = e, this.ctx = t, this.data =
|
|
774
|
+
constructor(e, t, r) {
|
|
775
|
+
this.type = e, this.ctx = t, this.data = r;
|
|
710
776
|
}
|
|
711
777
|
}
|
|
712
778
|
export {
|
|
713
|
-
|
|
779
|
+
g as MTextContext,
|
|
714
780
|
b as MTextLineAlignment,
|
|
715
781
|
E as MTextParagraphAlignment,
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
782
|
+
O as MTextParser,
|
|
783
|
+
F as MTextStroke,
|
|
784
|
+
f as MTextToken,
|
|
719
785
|
p as TextScanner,
|
|
720
786
|
k as TokenType,
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
787
|
+
S as caretDecode,
|
|
788
|
+
I as escapeDxfLineEndings,
|
|
789
|
+
N as hasInlineFormattingCodes,
|
|
790
|
+
R as int2rgb,
|
|
791
|
+
v as rgb2int
|
|
726
792
|
};
|
|
727
793
|
//# sourceMappingURL=parser.es.js.map
|