@mlightcad/mtext-parser 1.3.1 → 1.3.3
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 +207 -207
- package/dist/parser.cjs.js +2 -2
- package/dist/parser.cjs.js.map +1 -1
- package/dist/parser.es.js +76 -70
- package/dist/parser.es.js.map +1 -1
- package/dist/parser.umd.js +2 -2
- package/dist/parser.umd.js.map +1 -1
- package/package.json +4 -3
package/dist/parser.es.js
CHANGED
|
@@ -2,7 +2,8 @@ var _ = /* @__PURE__ */ ((s) => (s[s.NONE = 0] = "NONE", s[s.WORD = 1] = "WORD",
|
|
|
2
2
|
const R = {
|
|
3
3
|
c: "Ø",
|
|
4
4
|
d: "°",
|
|
5
|
-
p: "±"
|
|
5
|
+
p: "±",
|
|
6
|
+
"%": "%"
|
|
6
7
|
}, v = {
|
|
7
8
|
l: 1,
|
|
8
9
|
r: 2,
|
|
@@ -11,12 +12,12 @@ const R = {
|
|
|
11
12
|
d: 5
|
|
12
13
|
/* DISTRIBUTED */
|
|
13
14
|
};
|
|
14
|
-
function
|
|
15
|
+
function I(s) {
|
|
15
16
|
const [t, e, r] = s;
|
|
16
|
-
return
|
|
17
|
+
return t << 16 | e << 8 | r;
|
|
17
18
|
}
|
|
18
|
-
function
|
|
19
|
-
const t = s & 255, e = s >> 8 & 255, r = s
|
|
19
|
+
function O(s) {
|
|
20
|
+
const t = s >> 16 & 255, e = s >> 8 & 255, r = s & 255;
|
|
20
21
|
return [t, e, r];
|
|
21
22
|
}
|
|
22
23
|
function N(s) {
|
|
@@ -28,8 +29,8 @@ function w(s) {
|
|
|
28
29
|
function D(s, t = !1) {
|
|
29
30
|
const e = /* @__PURE__ */ new Set(), r = /\\[fF](.*?)[;|]/g;
|
|
30
31
|
return [...s.matchAll(r)].forEach((a) => {
|
|
31
|
-
let
|
|
32
|
-
t && (
|
|
32
|
+
let h = a[1].toLowerCase();
|
|
33
|
+
t && (h = h.replace(/\.(ttf|otf|woff|shx)$/, "")), e.add(h);
|
|
33
34
|
}), e;
|
|
34
35
|
}
|
|
35
36
|
class y {
|
|
@@ -92,8 +93,8 @@ class x {
|
|
|
92
93
|
* @param options - Parser options
|
|
93
94
|
*/
|
|
94
95
|
constructor(t, e, r = {}) {
|
|
95
|
-
this.continueStroke = !1, this.inStackContext = !1, this.scanner = new
|
|
96
|
-
const a = e ?? new
|
|
96
|
+
this.continueStroke = !1, this.inStackContext = !1, this.scanner = new d(t);
|
|
97
|
+
const a = e ?? new m();
|
|
97
98
|
this.ctxStack = new y(a), this.yieldPropertyCommands = r.yieldPropertyCommands ?? !1, this.resetParagraphParameters = r.resetParagraphParameters ?? !1, this.mifDecoder = r.mifDecoder ?? this.decodeMultiByteChar.bind(this), this.mifCodeLength = r.mifCodeLength ?? "auto";
|
|
98
99
|
}
|
|
99
100
|
/**
|
|
@@ -136,9 +137,9 @@ class x {
|
|
|
136
137
|
extractMifCode(t) {
|
|
137
138
|
var e, r, a;
|
|
138
139
|
if (t === "auto") {
|
|
139
|
-
const
|
|
140
|
-
if (
|
|
141
|
-
return
|
|
140
|
+
const h = (e = this.scanner.tail.match(/^[0-9A-Fa-f]{5}/)) == null ? void 0 : e[0];
|
|
141
|
+
if (h)
|
|
142
|
+
return h;
|
|
142
143
|
const i = (r = this.scanner.tail.match(/^[0-9A-Fa-f]{4}/)) == null ? void 0 : r[0];
|
|
143
144
|
return i || null;
|
|
144
145
|
} else
|
|
@@ -161,26 +162,26 @@ class x {
|
|
|
161
162
|
* @returns Tuple of [TokenType.STACK, [numerator, denominator, type]]
|
|
162
163
|
*/
|
|
163
164
|
parseStacking() {
|
|
164
|
-
const t = new
|
|
165
|
+
const t = new d(this.extractExpression(!0));
|
|
165
166
|
let e = "", r = "", a = "";
|
|
166
|
-
const
|
|
167
|
+
const h = () => {
|
|
167
168
|
let n = t.peek(), l = !1;
|
|
168
169
|
return n.charCodeAt(0) < 32 && (n = " "), n === "\\" && (l = !0, t.consume(1), n = t.peek()), t.consume(1), [n, l];
|
|
169
170
|
}, i = () => {
|
|
170
171
|
let n = "";
|
|
171
172
|
for (; t.hasData; ) {
|
|
172
|
-
const [l,
|
|
173
|
-
if (!
|
|
173
|
+
const [l, o] = h();
|
|
174
|
+
if (!o && (l === "/" || l === "#" || l === "^"))
|
|
174
175
|
return [n, l];
|
|
175
176
|
n += l;
|
|
176
177
|
}
|
|
177
178
|
return [n, ""];
|
|
178
179
|
}, u = (n) => {
|
|
179
|
-
let l = "",
|
|
180
|
+
let l = "", o = n;
|
|
180
181
|
for (; t.hasData; ) {
|
|
181
|
-
const [c, p] =
|
|
182
|
-
if (!(
|
|
183
|
-
if (
|
|
182
|
+
const [c, p] = h();
|
|
183
|
+
if (!(o && c === " ")) {
|
|
184
|
+
if (o = !1, !p && c === ";")
|
|
184
185
|
break;
|
|
185
186
|
l += c;
|
|
186
187
|
}
|
|
@@ -424,8 +425,8 @@ class x {
|
|
|
424
425
|
const i = this.scanner.tail;
|
|
425
426
|
return this.scanner.consume(i.length), i;
|
|
426
427
|
}
|
|
427
|
-
const a = this.scanner.peek(e - this.scanner.currentIndex - 1) === "\\",
|
|
428
|
-
return this.scanner.consume(
|
|
428
|
+
const a = this.scanner.peek(e - this.scanner.currentIndex - 1) === "\\", h = this.scanner.tail.slice(0, e - this.scanner.currentIndex + (a ? 1 : 0));
|
|
429
|
+
return this.scanner.consume(h.length + 1), h;
|
|
429
430
|
}
|
|
430
431
|
/**
|
|
431
432
|
* Parse font properties
|
|
@@ -435,13 +436,13 @@ class x {
|
|
|
435
436
|
const e = this.extractExpression().split("|");
|
|
436
437
|
if (e.length > 0 && e[0]) {
|
|
437
438
|
const r = e[0];
|
|
438
|
-
let a = "Regular",
|
|
439
|
+
let a = "Regular", h = 400;
|
|
439
440
|
for (const i of e.slice(1))
|
|
440
|
-
i.startsWith("b1") ?
|
|
441
|
+
i.startsWith("b1") ? h = 700 : i === "i" || i.startsWith("i1") ? a = "Italic" : (i === "i0" || i.startsWith("i0")) && (a = "Regular");
|
|
441
442
|
t.fontFace = {
|
|
442
443
|
family: r,
|
|
443
444
|
style: a,
|
|
444
|
-
weight:
|
|
445
|
+
weight: h
|
|
445
446
|
};
|
|
446
447
|
}
|
|
447
448
|
}
|
|
@@ -451,15 +452,15 @@ class x {
|
|
|
451
452
|
* @param ctx - The context to update
|
|
452
453
|
*/
|
|
453
454
|
parseParagraphProperties(t) {
|
|
454
|
-
const e = new
|
|
455
|
-
let r = t.paragraph.indent, a = t.paragraph.left,
|
|
455
|
+
const e = new d(this.extractExpression());
|
|
456
|
+
let r = t.paragraph.indent, a = t.paragraph.left, h = t.paragraph.right, i = t.paragraph.align, u = [];
|
|
456
457
|
const n = () => {
|
|
457
458
|
const l = e.tail.match(/^[+-]?\d+(?:\.\d*)?(?:[eE][+-]?\d+)?/);
|
|
458
459
|
if (l) {
|
|
459
|
-
const
|
|
460
|
+
const o = parseFloat(l[0]);
|
|
460
461
|
for (e.consume(l[0].length); e.peek() === ","; )
|
|
461
462
|
e.consume(1);
|
|
462
|
-
return
|
|
463
|
+
return o;
|
|
463
464
|
}
|
|
464
465
|
return 0;
|
|
465
466
|
};
|
|
@@ -472,23 +473,23 @@ class x {
|
|
|
472
473
|
a = n();
|
|
473
474
|
break;
|
|
474
475
|
case "r":
|
|
475
|
-
|
|
476
|
+
h = n();
|
|
476
477
|
break;
|
|
477
478
|
case "x":
|
|
478
479
|
break;
|
|
479
480
|
case "q": {
|
|
480
|
-
const
|
|
481
|
-
for (i = v[
|
|
481
|
+
const o = e.get();
|
|
482
|
+
for (i = v[o] || 0; e.peek() === ","; )
|
|
482
483
|
e.consume(1);
|
|
483
484
|
break;
|
|
484
485
|
}
|
|
485
486
|
case "t":
|
|
486
487
|
for (u = []; e.hasData; ) {
|
|
487
|
-
const
|
|
488
|
-
if (
|
|
488
|
+
const o = e.peek();
|
|
489
|
+
if (o === "r" || o === "c") {
|
|
489
490
|
e.consume(1);
|
|
490
491
|
const c = n();
|
|
491
|
-
u.push(
|
|
492
|
+
u.push(o + c.toString());
|
|
492
493
|
} else {
|
|
493
494
|
const c = n();
|
|
494
495
|
isNaN(c) ? e.consume(1) : u.push(c);
|
|
@@ -499,7 +500,7 @@ class x {
|
|
|
499
500
|
t.paragraph = {
|
|
500
501
|
indent: r,
|
|
501
502
|
left: a,
|
|
502
|
-
right:
|
|
503
|
+
right: h,
|
|
503
504
|
align: i,
|
|
504
505
|
tabs: u
|
|
505
506
|
};
|
|
@@ -528,7 +529,7 @@ class x {
|
|
|
528
529
|
const n = {};
|
|
529
530
|
return u.indent !== 0 && (n.indent = 0), u.left !== 0 && (n.left = 0), u.right !== 0 && (n.right = 0), u.align !== 0 && (n.align = 0), JSON.stringify(u.tabs) !== JSON.stringify([]) && (n.tabs = []), n;
|
|
530
531
|
}
|
|
531
|
-
const
|
|
532
|
+
const h = () => {
|
|
532
533
|
let i = "";
|
|
533
534
|
for (; this.scanner.hasData; ) {
|
|
534
535
|
let u = !1, n = this.scanner.peek();
|
|
@@ -548,8 +549,8 @@ class x {
|
|
|
548
549
|
if (i)
|
|
549
550
|
return [1, i];
|
|
550
551
|
this.scanner.consume(1);
|
|
551
|
-
const
|
|
552
|
-
switch (
|
|
552
|
+
const o = this.scanner.get();
|
|
553
|
+
switch (o) {
|
|
553
554
|
case "~":
|
|
554
555
|
return [4, null];
|
|
555
556
|
case "P":
|
|
@@ -584,23 +585,23 @@ class x {
|
|
|
584
585
|
if (c) {
|
|
585
586
|
const p = c[0];
|
|
586
587
|
this.scanner.consume(p.length);
|
|
587
|
-
const
|
|
588
|
-
let
|
|
588
|
+
const g = parseInt(p, 16);
|
|
589
|
+
let f = "";
|
|
589
590
|
try {
|
|
590
|
-
|
|
591
|
+
f = String.fromCodePoint(g);
|
|
591
592
|
} catch {
|
|
592
|
-
|
|
593
|
+
f = "▯";
|
|
593
594
|
}
|
|
594
|
-
return i ? [1, i] : [1,
|
|
595
|
+
return i ? [1, i] : [1, f];
|
|
595
596
|
}
|
|
596
597
|
this.scanner.consume(-1);
|
|
597
598
|
}
|
|
598
599
|
i += "\\U";
|
|
599
600
|
continue;
|
|
600
601
|
default:
|
|
601
|
-
if (
|
|
602
|
+
if (o)
|
|
602
603
|
try {
|
|
603
|
-
const c = this.parseProperties(
|
|
604
|
+
const c = this.parseProperties(o);
|
|
604
605
|
if (this.yieldPropertyCommands && c)
|
|
605
606
|
return [9, c];
|
|
606
607
|
continue;
|
|
@@ -615,12 +616,17 @@ class x {
|
|
|
615
616
|
continue;
|
|
616
617
|
}
|
|
617
618
|
if (n === "%" && this.scanner.peek(1) === "%") {
|
|
618
|
-
const
|
|
619
|
+
const o = this.scanner.peek(2).toLowerCase(), c = R[o];
|
|
619
620
|
if (c) {
|
|
620
621
|
this.scanner.consume(3), i += c;
|
|
621
622
|
continue;
|
|
622
623
|
} else {
|
|
623
|
-
this.scanner.
|
|
624
|
+
const p = [o, this.scanner.peek(3), this.scanner.peek(4)];
|
|
625
|
+
if (p.every((g) => g >= "0" && g <= "9")) {
|
|
626
|
+
const g = Number.parseInt(p.join(""), 10);
|
|
627
|
+
this.scanner.consume(5), i += String.fromCharCode(g);
|
|
628
|
+
} else
|
|
629
|
+
this.scanner.consume(3);
|
|
624
630
|
continue;
|
|
625
631
|
}
|
|
626
632
|
}
|
|
@@ -636,9 +642,9 @@ class x {
|
|
|
636
642
|
if (i)
|
|
637
643
|
return [1, i];
|
|
638
644
|
if (this.scanner.consume(1), this.yieldPropertyCommands) {
|
|
639
|
-
const
|
|
645
|
+
const o = this.ctxStack.current;
|
|
640
646
|
this.popCtx();
|
|
641
|
-
const c = this.getPropertyChanges(
|
|
647
|
+
const c = this.getPropertyChanges(o, this.ctxStack.current);
|
|
642
648
|
if (Object.keys(c).length > 0)
|
|
643
649
|
return [
|
|
644
650
|
9,
|
|
@@ -650,9 +656,9 @@ class x {
|
|
|
650
656
|
}
|
|
651
657
|
}
|
|
652
658
|
if (!this.inStackContext && n === "^") {
|
|
653
|
-
const
|
|
654
|
-
if (
|
|
655
|
-
const c =
|
|
659
|
+
const o = this.scanner.peek(1);
|
|
660
|
+
if (o) {
|
|
661
|
+
const c = o.charCodeAt(0);
|
|
656
662
|
if (this.scanner.consume(2), c === 32)
|
|
657
663
|
i += "^";
|
|
658
664
|
else {
|
|
@@ -672,23 +678,23 @@ class x {
|
|
|
672
678
|
return i ? [1, i] : [0, null];
|
|
673
679
|
};
|
|
674
680
|
for (; ; ) {
|
|
675
|
-
const [i, u] =
|
|
681
|
+
const [i, u] = h.call(this);
|
|
676
682
|
if (i) {
|
|
677
|
-
if (yield new
|
|
683
|
+
if (yield new k(i, this.ctxStack.current.copy(), u), i === 6 && this.resetParagraphParameters) {
|
|
678
684
|
const n = this.ctxStack.current, l = a(n);
|
|
679
|
-
this.yieldPropertyCommands && Object.keys(l).length > 0 && (yield new
|
|
685
|
+
this.yieldPropertyCommands && Object.keys(l).length > 0 && (yield new k(9, n.copy(), {
|
|
680
686
|
command: void 0,
|
|
681
687
|
changes: { paragraph: l },
|
|
682
688
|
depth: this.ctxStack.depth
|
|
683
689
|
}));
|
|
684
690
|
}
|
|
685
|
-
r && (yield new
|
|
691
|
+
r && (yield new k(r, this.ctxStack.current.copy(), null), r = null);
|
|
686
692
|
} else
|
|
687
693
|
break;
|
|
688
694
|
}
|
|
689
695
|
}
|
|
690
696
|
}
|
|
691
|
-
class
|
|
697
|
+
class d {
|
|
692
698
|
/**
|
|
693
699
|
* Create a new text scanner
|
|
694
700
|
* @param text - The text to scan
|
|
@@ -788,7 +794,7 @@ class f {
|
|
|
788
794
|
return t;
|
|
789
795
|
}
|
|
790
796
|
}
|
|
791
|
-
class
|
|
797
|
+
class b {
|
|
792
798
|
// Store as 0xRRGGBB or null
|
|
793
799
|
/**
|
|
794
800
|
* Create a new MTextColor instance.
|
|
@@ -864,7 +870,7 @@ class k {
|
|
|
864
870
|
* @returns A new MTextColor instance with the same color state.
|
|
865
871
|
*/
|
|
866
872
|
copy() {
|
|
867
|
-
const t = new
|
|
873
|
+
const t = new b();
|
|
868
874
|
return t._aci = this._aci, t._rgbValue = this._rgbValue, t;
|
|
869
875
|
}
|
|
870
876
|
/**
|
|
@@ -883,9 +889,9 @@ class k {
|
|
|
883
889
|
return this._aci === t._aci && this._rgbValue === t._rgbValue;
|
|
884
890
|
}
|
|
885
891
|
}
|
|
886
|
-
class
|
|
892
|
+
class m {
|
|
887
893
|
constructor() {
|
|
888
|
-
this._stroke = 0, this.continueStroke = !1, this.color = new
|
|
894
|
+
this._stroke = 0, this.continueStroke = !1, this.color = new b(), 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 = {
|
|
889
895
|
indent: 0,
|
|
890
896
|
left: 0,
|
|
891
897
|
right: 0,
|
|
@@ -1055,11 +1061,11 @@ class b {
|
|
|
1055
1061
|
* @returns A new context with the same properties
|
|
1056
1062
|
*/
|
|
1057
1063
|
copy() {
|
|
1058
|
-
const t = new
|
|
1064
|
+
const t = new m();
|
|
1059
1065
|
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;
|
|
1060
1066
|
}
|
|
1061
1067
|
}
|
|
1062
|
-
class
|
|
1068
|
+
class k {
|
|
1063
1069
|
/**
|
|
1064
1070
|
* Create a new MText token
|
|
1065
1071
|
* @param type - The token type
|
|
@@ -1071,19 +1077,19 @@ class d {
|
|
|
1071
1077
|
}
|
|
1072
1078
|
}
|
|
1073
1079
|
export {
|
|
1074
|
-
|
|
1075
|
-
|
|
1080
|
+
b as MTextColor,
|
|
1081
|
+
m as MTextContext,
|
|
1076
1082
|
F as MTextLineAlignment,
|
|
1077
1083
|
S as MTextParagraphAlignment,
|
|
1078
1084
|
x as MTextParser,
|
|
1079
1085
|
E as MTextStroke,
|
|
1080
|
-
|
|
1081
|
-
|
|
1086
|
+
k as MTextToken,
|
|
1087
|
+
d as TextScanner,
|
|
1082
1088
|
_ as TokenType,
|
|
1083
1089
|
N as escapeDxfLineEndings,
|
|
1084
1090
|
D as getFonts,
|
|
1085
1091
|
w as hasInlineFormattingCodes,
|
|
1086
|
-
|
|
1087
|
-
|
|
1092
|
+
O as int2rgb,
|
|
1093
|
+
I as rgb2int
|
|
1088
1094
|
};
|
|
1089
1095
|
//# sourceMappingURL=parser.es.js.map
|