@mlightcad/mtext-parser 1.1.5 → 1.1.7
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/README.md +10 -1
- package/dist/parser.cjs.js +2 -2
- package/dist/parser.cjs.js.map +1 -1
- package/dist/parser.es.js +218 -139
- package/dist/parser.es.js.map +1 -1
- package/dist/parser.umd.js +2 -2
- package/dist/parser.umd.js.map +1 -1
- package/dist/types/parser.d.ts +44 -5
- package/package.json +1 -1
package/dist/parser.es.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
var
|
|
1
|
+
var _ = /* @__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))(_ || {}), m = /* @__PURE__ */ ((s) => (s[s.BOTTOM = 0] = "BOTTOM", s[s.MIDDLE = 1] = "MIDDLE", s[s.TOP = 2] = "TOP", s))(m || {}), S = /* @__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))(S || {}), 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
2
|
const F = {
|
|
3
3
|
c: "Ø",
|
|
4
4
|
d: "°",
|
|
5
5
|
p: "±"
|
|
6
|
-
},
|
|
6
|
+
}, R = {
|
|
7
7
|
l: 1,
|
|
8
8
|
r: 2,
|
|
9
9
|
c: 3,
|
|
@@ -11,36 +11,90 @@ const F = {
|
|
|
11
11
|
d: 5
|
|
12
12
|
/* DISTRIBUTED */
|
|
13
13
|
};
|
|
14
|
-
function
|
|
14
|
+
function O(s) {
|
|
15
15
|
const [t, e, r] = s;
|
|
16
16
|
return r << 16 | e << 8 | t;
|
|
17
17
|
}
|
|
18
|
-
function
|
|
18
|
+
function y(s) {
|
|
19
19
|
const t = s & 255, e = s >> 8 & 255, r = s >> 16 & 255;
|
|
20
20
|
return [t, e, r];
|
|
21
21
|
}
|
|
22
|
-
function
|
|
22
|
+
function N(s) {
|
|
23
23
|
return s.replace(/\r\n|\r|\n/g, "\\P");
|
|
24
24
|
}
|
|
25
25
|
function I(s) {
|
|
26
26
|
return s.replace(/\\P/g, "").replace(/\\~/g, "").includes("\\");
|
|
27
27
|
}
|
|
28
|
-
function
|
|
28
|
+
function x(s, t = !1) {
|
|
29
29
|
const e = /* @__PURE__ */ new Set(), r = /\\[fF](.*?)[;|]/g;
|
|
30
30
|
return [...s.matchAll(r)].forEach((a) => {
|
|
31
|
-
let
|
|
32
|
-
t && (
|
|
31
|
+
let l = a[1].toLowerCase();
|
|
32
|
+
t && (l = l.replace(/\.(ttf|otf|woff|shx)$/, "")), e.add(l);
|
|
33
33
|
}), e;
|
|
34
34
|
}
|
|
35
|
-
class
|
|
35
|
+
class v {
|
|
36
|
+
/**
|
|
37
|
+
* Creates a new ContextStack with an initial context.
|
|
38
|
+
* @param initial The initial MTextContext to use as the base of the stack.
|
|
39
|
+
*/
|
|
40
|
+
constructor(t) {
|
|
41
|
+
this.stack = [], this.stack.push(t);
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Pushes a copy of the given context onto the stack.
|
|
45
|
+
* @param ctx The MTextContext to push (copied).
|
|
46
|
+
*/
|
|
47
|
+
push(t) {
|
|
48
|
+
this.stack.push(t);
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Pops the top context from the stack and merges its paragraph properties into the new top context.
|
|
52
|
+
* If only one context remains, nothing is popped.
|
|
53
|
+
* @returns The popped MTextContext, or undefined if the stack has only one context.
|
|
54
|
+
*/
|
|
55
|
+
pop() {
|
|
56
|
+
if (this.stack.length <= 1) return;
|
|
57
|
+
const t = this.stack.pop(), e = this.stack[this.stack.length - 1];
|
|
58
|
+
return JSON.stringify(e.paragraph) !== JSON.stringify(t.paragraph) && (e.paragraph = { ...t.paragraph }), t;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Returns the current (top) context on the stack.
|
|
62
|
+
*/
|
|
63
|
+
get current() {
|
|
64
|
+
return this.stack[this.stack.length - 1];
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Returns the current stack depth (number of nested blocks), not counting the root context.
|
|
68
|
+
*/
|
|
69
|
+
get depth() {
|
|
70
|
+
return this.stack.length - 1;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Returns the root (bottom) context, which represents the global formatting state.
|
|
74
|
+
* Used for paragraph property application.
|
|
75
|
+
*/
|
|
76
|
+
get root() {
|
|
77
|
+
return this.stack[0];
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Replaces the current (top) context with the given context.
|
|
81
|
+
* @param ctx The new context to set as the current context.
|
|
82
|
+
*/
|
|
83
|
+
setCurrent(t) {
|
|
84
|
+
this.stack[this.stack.length - 1] = t;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
class D {
|
|
36
88
|
/**
|
|
37
89
|
* Creates a new MTextParser instance
|
|
38
90
|
* @param content - The MText content to parse
|
|
39
91
|
* @param ctx - Optional initial MText context
|
|
40
|
-
* @param
|
|
92
|
+
* @param options - Parser options
|
|
41
93
|
*/
|
|
42
|
-
constructor(t, e, r =
|
|
43
|
-
this.
|
|
94
|
+
constructor(t, e, r = {}) {
|
|
95
|
+
this.continueStroke = !1, this.inStackContext = !1, this.scanner = new g(t);
|
|
96
|
+
const a = e ?? new k();
|
|
97
|
+
this.ctxStack = new v(a), this.yieldPropertyCommands = r.yieldPropertyCommands ?? !1, this.resetParagraphParameters = r.resetParagraphParameters ?? !1;
|
|
44
98
|
}
|
|
45
99
|
/**
|
|
46
100
|
* Decode multi-byte character from hex code
|
|
@@ -55,8 +109,8 @@ class x {
|
|
|
55
109
|
]), a = new TextDecoder("gbk").decode(e);
|
|
56
110
|
if (a !== "▯")
|
|
57
111
|
return a;
|
|
58
|
-
const
|
|
59
|
-
return
|
|
112
|
+
const i = new TextDecoder("big5").decode(e);
|
|
113
|
+
return i !== "▯" ? i : "▯";
|
|
60
114
|
} catch {
|
|
61
115
|
return "▯";
|
|
62
116
|
}
|
|
@@ -65,13 +119,13 @@ class x {
|
|
|
65
119
|
* Push current context onto the stack
|
|
66
120
|
*/
|
|
67
121
|
pushCtx() {
|
|
68
|
-
this.ctxStack.push(this.
|
|
122
|
+
this.ctxStack.push(this.ctxStack.current);
|
|
69
123
|
}
|
|
70
124
|
/**
|
|
71
125
|
* Pop context from the stack
|
|
72
126
|
*/
|
|
73
127
|
popCtx() {
|
|
74
|
-
this.ctxStack.
|
|
128
|
+
this.ctxStack.pop();
|
|
75
129
|
}
|
|
76
130
|
/**
|
|
77
131
|
* Parse stacking expression (numerator/denominator)
|
|
@@ -80,31 +134,31 @@ class x {
|
|
|
80
134
|
parseStacking() {
|
|
81
135
|
const t = new g(this.extractExpression(!0));
|
|
82
136
|
let e = "", r = "", a = "";
|
|
83
|
-
const
|
|
84
|
-
let
|
|
85
|
-
return
|
|
86
|
-
},
|
|
87
|
-
let
|
|
137
|
+
const l = () => {
|
|
138
|
+
let c = t.peek(), n = !1;
|
|
139
|
+
return c.charCodeAt(0) < 32 && (c = " "), c === "\\" && (n = !0, t.consume(1), c = t.peek()), t.consume(1), [c, n];
|
|
140
|
+
}, i = () => {
|
|
141
|
+
let c = "";
|
|
88
142
|
for (; t.hasData; ) {
|
|
89
|
-
const [
|
|
90
|
-
if (!
|
|
91
|
-
return [
|
|
92
|
-
|
|
143
|
+
const [n, p] = l();
|
|
144
|
+
if (!p && (n === "/" || n === "#" || n === "^"))
|
|
145
|
+
return [c, n];
|
|
146
|
+
c += n;
|
|
93
147
|
}
|
|
94
|
-
return [
|
|
95
|
-
}, u = (
|
|
96
|
-
let
|
|
148
|
+
return [c, ""];
|
|
149
|
+
}, u = (c) => {
|
|
150
|
+
let n = "", p = c;
|
|
97
151
|
for (; t.hasData; ) {
|
|
98
|
-
const [
|
|
99
|
-
if (!(
|
|
100
|
-
if (
|
|
152
|
+
const [h, o] = l();
|
|
153
|
+
if (!(p && h === " ")) {
|
|
154
|
+
if (p = !1, !o && h === ";")
|
|
101
155
|
break;
|
|
102
|
-
|
|
156
|
+
n += h;
|
|
103
157
|
}
|
|
104
158
|
}
|
|
105
|
-
return
|
|
159
|
+
return n;
|
|
106
160
|
};
|
|
107
|
-
return [e, a] =
|
|
161
|
+
return [e, a] = i(), a && (r = u(a === "^")), e === "" && r.includes("I/") ? [2, [" ", " ", "/"]] : a === "^" ? [2, [e, r, "^"]] : [2, [e, r, a]];
|
|
108
162
|
}
|
|
109
163
|
/**
|
|
110
164
|
* Parse MText properties
|
|
@@ -112,64 +166,64 @@ class x {
|
|
|
112
166
|
* @returns Property changes if yieldPropertyCommands is true and changes occurred
|
|
113
167
|
*/
|
|
114
168
|
parseProperties(t) {
|
|
115
|
-
const e = this.
|
|
169
|
+
const e = this.ctxStack.current.copy(), r = this.ctxStack.current.copy();
|
|
116
170
|
switch (t) {
|
|
117
171
|
case "L":
|
|
118
|
-
|
|
172
|
+
r.underline = !0, this.continueStroke = !0;
|
|
119
173
|
break;
|
|
120
174
|
case "l":
|
|
121
|
-
|
|
175
|
+
r.underline = !1, r.hasAnyStroke || (this.continueStroke = !1);
|
|
122
176
|
break;
|
|
123
177
|
case "O":
|
|
124
|
-
|
|
178
|
+
r.overline = !0, this.continueStroke = !0;
|
|
125
179
|
break;
|
|
126
180
|
case "o":
|
|
127
|
-
|
|
181
|
+
r.overline = !1, r.hasAnyStroke || (this.continueStroke = !1);
|
|
128
182
|
break;
|
|
129
183
|
case "K":
|
|
130
|
-
|
|
184
|
+
r.strikeThrough = !0, this.continueStroke = !0;
|
|
131
185
|
break;
|
|
132
186
|
case "k":
|
|
133
|
-
|
|
187
|
+
r.strikeThrough = !1, r.hasAnyStroke || (this.continueStroke = !1);
|
|
134
188
|
break;
|
|
135
189
|
case "A":
|
|
136
|
-
this.parseAlign(
|
|
190
|
+
this.parseAlign(r);
|
|
137
191
|
break;
|
|
138
192
|
case "C":
|
|
139
|
-
this.parseAciColor(
|
|
193
|
+
this.parseAciColor(r);
|
|
140
194
|
break;
|
|
141
195
|
case "c":
|
|
142
|
-
this.parseRgbColor(
|
|
196
|
+
this.parseRgbColor(r);
|
|
143
197
|
break;
|
|
144
198
|
case "H":
|
|
145
|
-
this.parseHeight(
|
|
199
|
+
this.parseHeight(r);
|
|
146
200
|
break;
|
|
147
201
|
case "W":
|
|
148
|
-
this.parseWidth(
|
|
202
|
+
this.parseWidth(r);
|
|
149
203
|
break;
|
|
150
204
|
case "Q":
|
|
151
|
-
this.parseOblique(
|
|
205
|
+
this.parseOblique(r);
|
|
152
206
|
break;
|
|
153
207
|
case "T":
|
|
154
|
-
this.parseCharTracking(
|
|
208
|
+
this.parseCharTracking(r);
|
|
155
209
|
break;
|
|
156
210
|
case "p":
|
|
157
|
-
this.parseParagraphProperties(
|
|
211
|
+
this.parseParagraphProperties(r);
|
|
158
212
|
break;
|
|
159
213
|
case "f":
|
|
160
214
|
case "F":
|
|
161
|
-
this.parseFontProperties(
|
|
215
|
+
this.parseFontProperties(r);
|
|
162
216
|
break;
|
|
163
217
|
default:
|
|
164
218
|
throw new Error(`Unknown command: ${t}`);
|
|
165
219
|
}
|
|
166
|
-
if (this.continueStroke =
|
|
167
|
-
const
|
|
168
|
-
if (Object.keys(
|
|
169
|
-
return
|
|
220
|
+
if (this.continueStroke = r.hasAnyStroke, r.continueStroke = this.continueStroke, this.ctxStack.setCurrent(r), this.yieldPropertyCommands) {
|
|
221
|
+
const a = this.getPropertyChanges(e, r);
|
|
222
|
+
if (Object.keys(a).length > 0)
|
|
223
|
+
return {
|
|
170
224
|
command: t,
|
|
171
|
-
changes:
|
|
172
|
-
depth: this.ctxStack.
|
|
225
|
+
changes: a,
|
|
226
|
+
depth: this.ctxStack.depth
|
|
173
227
|
};
|
|
174
228
|
}
|
|
175
229
|
}
|
|
@@ -338,11 +392,11 @@ class x {
|
|
|
338
392
|
extractExpression(t = !1) {
|
|
339
393
|
const e = this.scanner.find(";", t);
|
|
340
394
|
if (e < 0) {
|
|
341
|
-
const
|
|
342
|
-
return this.scanner.consume(
|
|
395
|
+
const i = this.scanner.tail;
|
|
396
|
+
return this.scanner.consume(i.length), i;
|
|
343
397
|
}
|
|
344
|
-
const a = this.scanner.peek(e - this.scanner.currentIndex - 1) === "\\",
|
|
345
|
-
return this.scanner.consume(
|
|
398
|
+
const a = this.scanner.peek(e - this.scanner.currentIndex - 1) === "\\", l = this.scanner.tail.slice(0, e - this.scanner.currentIndex + (a ? 1 : 0));
|
|
399
|
+
return this.scanner.consume(l.length + 1), l;
|
|
346
400
|
}
|
|
347
401
|
/**
|
|
348
402
|
* Parse font properties
|
|
@@ -352,13 +406,13 @@ class x {
|
|
|
352
406
|
const e = this.extractExpression().split("|");
|
|
353
407
|
if (e.length > 0 && e[0]) {
|
|
354
408
|
const r = e[0];
|
|
355
|
-
let a = "Regular",
|
|
356
|
-
for (const
|
|
357
|
-
|
|
409
|
+
let a = "Regular", l = 400;
|
|
410
|
+
for (const i of e.slice(1))
|
|
411
|
+
i.startsWith("b1") ? l = 700 : i === "i" || i.startsWith("i1") ? a = "Italic" : (i === "i0" || i.startsWith("i0")) && (a = "Regular");
|
|
358
412
|
t.fontFace = {
|
|
359
413
|
family: r,
|
|
360
414
|
style: a,
|
|
361
|
-
weight:
|
|
415
|
+
weight: l
|
|
362
416
|
};
|
|
363
417
|
}
|
|
364
418
|
}
|
|
@@ -369,46 +423,46 @@ class x {
|
|
|
369
423
|
*/
|
|
370
424
|
parseParagraphProperties(t) {
|
|
371
425
|
const e = new g(this.extractExpression());
|
|
372
|
-
let r = t.paragraph.indent, a = t.paragraph.left,
|
|
373
|
-
const
|
|
374
|
-
const
|
|
375
|
-
if (
|
|
376
|
-
const
|
|
377
|
-
for (e.consume(
|
|
426
|
+
let r = t.paragraph.indent, a = t.paragraph.left, l = t.paragraph.right, i = t.paragraph.align, u = [];
|
|
427
|
+
const c = () => {
|
|
428
|
+
const n = e.tail.match(/^[+-]?\d+(?:\.\d*)?(?:[eE][+-]?\d+)?/);
|
|
429
|
+
if (n) {
|
|
430
|
+
const p = parseFloat(n[0]);
|
|
431
|
+
for (e.consume(n[0].length); e.peek() === ","; )
|
|
378
432
|
e.consume(1);
|
|
379
|
-
return
|
|
433
|
+
return p;
|
|
380
434
|
}
|
|
381
435
|
return 0;
|
|
382
436
|
};
|
|
383
437
|
for (; e.hasData; )
|
|
384
438
|
switch (e.get()) {
|
|
385
439
|
case "i":
|
|
386
|
-
r =
|
|
440
|
+
r = c();
|
|
387
441
|
break;
|
|
388
442
|
case "l":
|
|
389
|
-
a =
|
|
443
|
+
a = c();
|
|
390
444
|
break;
|
|
391
445
|
case "r":
|
|
392
|
-
|
|
446
|
+
l = c();
|
|
393
447
|
break;
|
|
394
448
|
case "x":
|
|
395
449
|
break;
|
|
396
450
|
case "q": {
|
|
397
|
-
const
|
|
398
|
-
for (
|
|
451
|
+
const p = e.get();
|
|
452
|
+
for (i = R[p] || 0; e.peek() === ","; )
|
|
399
453
|
e.consume(1);
|
|
400
454
|
break;
|
|
401
455
|
}
|
|
402
456
|
case "t":
|
|
403
457
|
for (u = []; e.hasData; ) {
|
|
404
|
-
const
|
|
405
|
-
if (
|
|
458
|
+
const p = e.peek();
|
|
459
|
+
if (p === "r" || p === "c") {
|
|
406
460
|
e.consume(1);
|
|
407
|
-
const
|
|
408
|
-
u.push(
|
|
461
|
+
const h = c();
|
|
462
|
+
u.push(p + h.toString());
|
|
409
463
|
} else {
|
|
410
|
-
const
|
|
411
|
-
isNaN(
|
|
464
|
+
const h = c();
|
|
465
|
+
isNaN(h) ? e.consume(1) : u.push(h);
|
|
412
466
|
}
|
|
413
467
|
}
|
|
414
468
|
break;
|
|
@@ -416,8 +470,8 @@ class x {
|
|
|
416
470
|
t.paragraph = {
|
|
417
471
|
indent: r,
|
|
418
472
|
left: a,
|
|
419
|
-
right:
|
|
420
|
-
align:
|
|
473
|
+
right: l,
|
|
474
|
+
align: i,
|
|
421
475
|
tab_stops: u
|
|
422
476
|
};
|
|
423
477
|
}
|
|
@@ -433,12 +487,24 @@ class x {
|
|
|
433
487
|
*/
|
|
434
488
|
*parse() {
|
|
435
489
|
let r = null;
|
|
436
|
-
|
|
437
|
-
|
|
490
|
+
function a(i) {
|
|
491
|
+
const u = { ...i.paragraph };
|
|
492
|
+
i.paragraph = {
|
|
493
|
+
indent: 0,
|
|
494
|
+
left: 0,
|
|
495
|
+
right: 0,
|
|
496
|
+
align: 0,
|
|
497
|
+
tab_stops: []
|
|
498
|
+
};
|
|
499
|
+
const c = {};
|
|
500
|
+
return u.indent !== 0 && (c.indent = 0), u.left !== 0 && (c.left = 0), u.right !== 0 && (c.right = 0), u.align !== 0 && (c.align = 0), JSON.stringify(u.tab_stops) !== JSON.stringify([]) && (c.tab_stops = []), c;
|
|
501
|
+
}
|
|
502
|
+
const l = () => {
|
|
503
|
+
var u;
|
|
438
504
|
let i = "";
|
|
439
505
|
for (; this.scanner.hasData; ) {
|
|
440
|
-
let
|
|
441
|
-
const
|
|
506
|
+
let c = !1, n = this.scanner.peek();
|
|
507
|
+
const p = this.scanner.currentIndex;
|
|
442
508
|
if (n.charCodeAt(0) < 32) {
|
|
443
509
|
if (this.scanner.consume(1), n === " ")
|
|
444
510
|
return [5, null];
|
|
@@ -449,13 +515,13 @@ class x {
|
|
|
449
515
|
}
|
|
450
516
|
if (n === "\\")
|
|
451
517
|
if ("\\{}".includes(this.scanner.peek(1)))
|
|
452
|
-
|
|
518
|
+
c = !0, this.scanner.consume(1), n = this.scanner.peek();
|
|
453
519
|
else {
|
|
454
520
|
if (i)
|
|
455
521
|
return [1, i];
|
|
456
522
|
this.scanner.consume(1);
|
|
457
|
-
const
|
|
458
|
-
switch (
|
|
523
|
+
const h = this.scanner.get();
|
|
524
|
+
switch (h) {
|
|
459
525
|
case "~":
|
|
460
526
|
return [4, null];
|
|
461
527
|
case "P":
|
|
@@ -466,44 +532,44 @@ class x {
|
|
|
466
532
|
return [8, null];
|
|
467
533
|
case "S": {
|
|
468
534
|
this.inStackContext = !0;
|
|
469
|
-
const
|
|
470
|
-
return this.inStackContext = !1,
|
|
535
|
+
const o = this.parseStacking();
|
|
536
|
+
return this.inStackContext = !1, o;
|
|
471
537
|
}
|
|
472
538
|
case "m":
|
|
473
539
|
case "M":
|
|
474
540
|
if (this.scanner.peek() === "+") {
|
|
475
541
|
this.scanner.consume(1);
|
|
476
|
-
const
|
|
477
|
-
if (
|
|
542
|
+
const o = (u = this.scanner.tail.match(/^[0-9A-Fa-f]{4}/)) == null ? void 0 : u[0];
|
|
543
|
+
if (o) {
|
|
478
544
|
this.scanner.consume(4);
|
|
479
|
-
const
|
|
480
|
-
return i ? [1, i] : [1,
|
|
545
|
+
const b = this.decodeMultiByteChar(o);
|
|
546
|
+
return i ? [1, i] : [1, b];
|
|
481
547
|
}
|
|
482
548
|
this.scanner.consume(-1);
|
|
483
549
|
}
|
|
484
550
|
i += "\\M";
|
|
485
551
|
continue;
|
|
486
552
|
default:
|
|
487
|
-
if (
|
|
553
|
+
if (h)
|
|
488
554
|
try {
|
|
489
|
-
const
|
|
490
|
-
if (this.yieldPropertyCommands &&
|
|
491
|
-
return
|
|
555
|
+
const o = this.parseProperties(h);
|
|
556
|
+
if (this.yieldPropertyCommands && o)
|
|
557
|
+
return [9, o];
|
|
492
558
|
continue;
|
|
493
559
|
} catch {
|
|
494
|
-
const
|
|
495
|
-
|
|
560
|
+
const o = this.scanner.tail.slice(
|
|
561
|
+
p,
|
|
496
562
|
this.scanner.currentIndex
|
|
497
563
|
);
|
|
498
|
-
i +=
|
|
564
|
+
i += o;
|
|
499
565
|
}
|
|
500
566
|
}
|
|
501
567
|
continue;
|
|
502
568
|
}
|
|
503
569
|
if (n === "%" && this.scanner.peek(1) === "%") {
|
|
504
|
-
const
|
|
505
|
-
if (
|
|
506
|
-
this.scanner.consume(3), i +=
|
|
570
|
+
const h = this.scanner.peek(2).toLowerCase(), o = F[h];
|
|
571
|
+
if (o) {
|
|
572
|
+
this.scanner.consume(3), i += o;
|
|
507
573
|
continue;
|
|
508
574
|
} else {
|
|
509
575
|
this.scanner.consume(3);
|
|
@@ -512,7 +578,7 @@ class x {
|
|
|
512
578
|
}
|
|
513
579
|
if (n === " ")
|
|
514
580
|
return i ? (this.scanner.consume(1), r = 3, [1, i]) : (this.scanner.consume(1), [3, null]);
|
|
515
|
-
if (!
|
|
581
|
+
if (!c) {
|
|
516
582
|
if (n === "{") {
|
|
517
583
|
if (i)
|
|
518
584
|
return [1, i];
|
|
@@ -522,12 +588,13 @@ class x {
|
|
|
522
588
|
if (i)
|
|
523
589
|
return [1, i];
|
|
524
590
|
if (this.scanner.consume(1), this.yieldPropertyCommands) {
|
|
591
|
+
const h = this.ctxStack.current;
|
|
525
592
|
this.popCtx();
|
|
526
|
-
const o = this.getPropertyChanges(
|
|
593
|
+
const o = this.getPropertyChanges(h, this.ctxStack.current);
|
|
527
594
|
if (Object.keys(o).length > 0)
|
|
528
|
-
return
|
|
595
|
+
return [
|
|
529
596
|
9,
|
|
530
|
-
{ command: void 0, changes: o, depth: this.ctxStack.
|
|
597
|
+
{ command: void 0, changes: o, depth: this.ctxStack.depth }
|
|
531
598
|
];
|
|
532
599
|
} else
|
|
533
600
|
this.popCtx();
|
|
@@ -535,17 +602,17 @@ class x {
|
|
|
535
602
|
}
|
|
536
603
|
}
|
|
537
604
|
if (!this.inStackContext && n === "^") {
|
|
538
|
-
const
|
|
539
|
-
if (
|
|
540
|
-
const
|
|
541
|
-
if (this.scanner.consume(2),
|
|
605
|
+
const h = this.scanner.peek(1);
|
|
606
|
+
if (h) {
|
|
607
|
+
const o = h.charCodeAt(0);
|
|
608
|
+
if (this.scanner.consume(2), o === 32)
|
|
542
609
|
i += "^";
|
|
543
610
|
else {
|
|
544
|
-
if (
|
|
611
|
+
if (o === 73)
|
|
545
612
|
return i ? [1, i] : [5, null];
|
|
546
|
-
if (
|
|
613
|
+
if (o === 74)
|
|
547
614
|
return i ? [1, i] : [6, null];
|
|
548
|
-
if (
|
|
615
|
+
if (o === 77)
|
|
549
616
|
continue;
|
|
550
617
|
i += "▯";
|
|
551
618
|
}
|
|
@@ -557,10 +624,22 @@ class x {
|
|
|
557
624
|
return i ? [1, i] : [0, null];
|
|
558
625
|
};
|
|
559
626
|
for (; ; ) {
|
|
560
|
-
const [i,
|
|
561
|
-
if (i)
|
|
562
|
-
yield new
|
|
563
|
-
|
|
627
|
+
const [i, u] = l.call(this);
|
|
628
|
+
if (i) {
|
|
629
|
+
if (yield new f(i, this.ctxStack.current.copy(), u), i === 6 && this.resetParagraphParameters) {
|
|
630
|
+
const c = this.ctxStack.current, n = a(c);
|
|
631
|
+
this.yieldPropertyCommands && Object.keys(n).length > 0 && (yield new f(
|
|
632
|
+
9,
|
|
633
|
+
c.copy(),
|
|
634
|
+
{
|
|
635
|
+
command: void 0,
|
|
636
|
+
changes: { paragraph: n },
|
|
637
|
+
depth: this.ctxStack.depth
|
|
638
|
+
}
|
|
639
|
+
));
|
|
640
|
+
}
|
|
641
|
+
r && (yield new f(r, this.ctxStack.current.copy(), null), r = null);
|
|
642
|
+
} else
|
|
564
643
|
break;
|
|
565
644
|
}
|
|
566
645
|
}
|
|
@@ -665,7 +744,7 @@ class g {
|
|
|
665
744
|
return t;
|
|
666
745
|
}
|
|
667
746
|
}
|
|
668
|
-
class
|
|
747
|
+
class d {
|
|
669
748
|
// Store as 0xRRGGBB or null
|
|
670
749
|
/**
|
|
671
750
|
* Create a new MTextColor instance.
|
|
@@ -741,7 +820,7 @@ class f {
|
|
|
741
820
|
* @returns A new MTextColor instance with the same color state.
|
|
742
821
|
*/
|
|
743
822
|
copy() {
|
|
744
|
-
const t = new
|
|
823
|
+
const t = new d();
|
|
745
824
|
return t._aci = this._aci, t._rgbValue = this._rgbValue, t;
|
|
746
825
|
}
|
|
747
826
|
/**
|
|
@@ -760,9 +839,9 @@ class f {
|
|
|
760
839
|
return this._aci === t._aci && this._rgbValue === t._rgbValue;
|
|
761
840
|
}
|
|
762
841
|
}
|
|
763
|
-
class
|
|
842
|
+
class k {
|
|
764
843
|
constructor() {
|
|
765
|
-
this._stroke = 0, this.continueStroke = !1, this.color = new
|
|
844
|
+
this._stroke = 0, this.continueStroke = !1, this.color = new d(), 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 = {
|
|
766
845
|
indent: 0,
|
|
767
846
|
left: 0,
|
|
768
847
|
right: 0,
|
|
@@ -902,11 +981,11 @@ class d {
|
|
|
902
981
|
* @returns A new context with the same properties
|
|
903
982
|
*/
|
|
904
983
|
copy() {
|
|
905
|
-
const t = new
|
|
984
|
+
const t = new k();
|
|
906
985
|
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;
|
|
907
986
|
}
|
|
908
987
|
}
|
|
909
|
-
class
|
|
988
|
+
class f {
|
|
910
989
|
/**
|
|
911
990
|
* Create a new MText token
|
|
912
991
|
* @param type - The token type
|
|
@@ -918,19 +997,19 @@ class b {
|
|
|
918
997
|
}
|
|
919
998
|
}
|
|
920
999
|
export {
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
1000
|
+
d as MTextColor,
|
|
1001
|
+
k as MTextContext,
|
|
1002
|
+
m as MTextLineAlignment,
|
|
1003
|
+
S as MTextParagraphAlignment,
|
|
1004
|
+
D as MTextParser,
|
|
926
1005
|
E as MTextStroke,
|
|
927
|
-
|
|
1006
|
+
f as MTextToken,
|
|
928
1007
|
g as TextScanner,
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
1008
|
+
_ as TokenType,
|
|
1009
|
+
N as escapeDxfLineEndings,
|
|
1010
|
+
x as getFonts,
|
|
932
1011
|
I as hasInlineFormattingCodes,
|
|
933
|
-
|
|
934
|
-
|
|
1012
|
+
y as int2rgb,
|
|
1013
|
+
O as rgb2int
|
|
935
1014
|
};
|
|
936
1015
|
//# sourceMappingURL=parser.es.js.map
|