@mlightcad/mtext-parser 1.1.9 → 1.2.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 m = /* @__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))(_ || {}), 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 || {}), 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 E = {
1
+ var S = /* @__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))(S || {}), F = /* @__PURE__ */ ((s) => (s[s.BOTTOM = 0] = "BOTTOM", s[s.MIDDLE = 1] = "MIDDLE", s[s.TOP = 2] = "TOP", s))(F || {}), 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 || {}), R = /* @__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))(R || {});
2
+ const v = {
3
3
  c: "Ø",
4
4
  d: "°",
5
5
  p: "±"
6
- }, R = {
6
+ }, y = {
7
7
  l: 1,
8
8
  r: 2,
9
9
  c: 3,
@@ -11,28 +11,28 @@ const E = {
11
11
  d: 5
12
12
  /* DISTRIBUTED */
13
13
  };
14
- function y(s) {
14
+ function N(s) {
15
15
  const [t, e, r] = s;
16
16
  return r << 16 | e << 8 | t;
17
17
  }
18
- function O(s) {
18
+ function I(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 N(s) {
22
+ function w(s) {
23
23
  return s.replace(/\r\n|\r|\n/g, "\\P");
24
24
  }
25
- function I(s) {
25
+ function x(s) {
26
26
  return s.replace(/\\P/g, "").replace(/\\~/g, "").includes("\\");
27
27
  }
28
- function w(s, t = !1) {
28
+ function P(s, t = !1) {
29
29
  const e = /* @__PURE__ */ new Set(), r = /\\[fF](.*?)[;|]/g;
30
30
  return [...s.matchAll(r)].forEach((a) => {
31
31
  let l = a[1].toLowerCase();
32
32
  t && (l = l.replace(/\.(ttf|otf|woff|shx)$/, "")), e.add(l);
33
33
  }), e;
34
34
  }
35
- class v {
35
+ class O {
36
36
  /**
37
37
  * Creates a new ContextStack with an initial context.
38
38
  * @param initial The initial MTextContext to use as the base of the stack.
@@ -84,7 +84,7 @@ class v {
84
84
  this.stack[this.stack.length - 1] = t;
85
85
  }
86
86
  }
87
- class x {
87
+ class D {
88
88
  /**
89
89
  * Creates a new MTextParser instance
90
90
  * @param content - The MText content to parse
@@ -92,9 +92,9 @@ class x {
92
92
  * @param options - Parser options
93
93
  */
94
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;
95
+ this.continueStroke = !1, this.inStackContext = !1, this.scanner = new d(t);
96
+ const a = e ?? new m();
97
+ this.ctxStack = new O(a), this.yieldPropertyCommands = r.yieldPropertyCommands ?? !1, this.resetParagraphParameters = r.resetParagraphParameters ?? !1;
98
98
  }
99
99
  /**
100
100
  * Decode multi-byte character from hex code
@@ -132,7 +132,7 @@ class x {
132
132
  * @returns Tuple of [TokenType.STACK, [numerator, denominator, type]]
133
133
  */
134
134
  parseStacking() {
135
- const t = new g(this.extractExpression(!0));
135
+ const t = new d(this.extractExpression(!0));
136
136
  let e = "", r = "", a = "";
137
137
  const l = () => {
138
138
  let c = t.peek(), n = !1;
@@ -149,11 +149,11 @@ class x {
149
149
  }, u = (c) => {
150
150
  let n = "", p = c;
151
151
  for (; t.hasData; ) {
152
- const [o, h] = l();
153
- if (!(p && o === " ")) {
154
- if (p = !1, !h && o === ";")
152
+ const [h, o] = l();
153
+ if (!(p && h === " ")) {
154
+ if (p = !1, !o && h === ";")
155
155
  break;
156
- n += o;
156
+ n += h;
157
157
  }
158
158
  }
159
159
  return n;
@@ -422,7 +422,7 @@ class x {
422
422
  * @param ctx - The context to update
423
423
  */
424
424
  parseParagraphProperties(t) {
425
- const e = new g(this.extractExpression());
425
+ const e = new d(this.extractExpression());
426
426
  let r = t.paragraph.indent, a = t.paragraph.left, l = t.paragraph.right, i = t.paragraph.align, u = [];
427
427
  const c = () => {
428
428
  const n = e.tail.match(/^[+-]?\d+(?:\.\d*)?(?:[eE][+-]?\d+)?/);
@@ -449,7 +449,7 @@ class x {
449
449
  break;
450
450
  case "q": {
451
451
  const p = e.get();
452
- for (i = R[p] || 0; e.peek() === ","; )
452
+ for (i = y[p] || 0; e.peek() === ","; )
453
453
  e.consume(1);
454
454
  break;
455
455
  }
@@ -458,11 +458,11 @@ class x {
458
458
  const p = e.peek();
459
459
  if (p === "r" || p === "c") {
460
460
  e.consume(1);
461
- const o = c();
462
- u.push(p + o.toString());
461
+ const h = c();
462
+ u.push(p + h.toString());
463
463
  } else {
464
- const o = c();
465
- isNaN(o) ? e.consume(1) : u.push(o);
464
+ const h = c();
465
+ isNaN(h) ? e.consume(1) : u.push(h);
466
466
  }
467
467
  }
468
468
  break;
@@ -520,8 +520,8 @@ class x {
520
520
  if (i)
521
521
  return [1, i];
522
522
  this.scanner.consume(1);
523
- const o = this.scanner.get();
524
- switch (o) {
523
+ const h = this.scanner.get();
524
+ switch (h) {
525
525
  case "~":
526
526
  return [4, null];
527
527
  case "P":
@@ -532,44 +532,64 @@ class x {
532
532
  return [8, null];
533
533
  case "S": {
534
534
  this.inStackContext = !0;
535
- const h = this.parseStacking();
536
- return this.inStackContext = !1, h;
535
+ const o = this.parseStacking();
536
+ return this.inStackContext = !1, o;
537
537
  }
538
538
  case "m":
539
539
  case "M":
540
540
  if (this.scanner.peek() === "+") {
541
541
  this.scanner.consume(1);
542
- const h = (u = this.scanner.tail.match(/^[0-9A-Fa-f]{4}/)) == null ? void 0 : u[0];
543
- if (h) {
542
+ const o = (u = this.scanner.tail.match(/^[0-9A-Fa-f]{4}/)) == null ? void 0 : u[0];
543
+ if (o) {
544
544
  this.scanner.consume(4);
545
- const b = this.decodeMultiByteChar(h);
546
- return i ? [1, i] : [1, b];
545
+ const g = this.decodeMultiByteChar(o);
546
+ return i ? [1, i] : [1, g];
547
547
  }
548
548
  this.scanner.consume(-1);
549
549
  }
550
550
  i += "\\M";
551
551
  continue;
552
+ case "U":
553
+ if (this.scanner.peek() === "+") {
554
+ this.scanner.consume(1);
555
+ const o = this.scanner.tail.match(/^[0-9A-Fa-f]{4,8}/);
556
+ if (o) {
557
+ const g = o[0];
558
+ this.scanner.consume(g.length);
559
+ const _ = parseInt(g, 16);
560
+ let f = "";
561
+ try {
562
+ f = String.fromCodePoint(_);
563
+ } catch {
564
+ f = "▯";
565
+ }
566
+ return i ? [1, i] : [1, f];
567
+ }
568
+ this.scanner.consume(-1);
569
+ }
570
+ i += "\\U";
571
+ continue;
552
572
  default:
553
- if (o)
573
+ if (h)
554
574
  try {
555
- const h = this.parseProperties(o);
556
- if (this.yieldPropertyCommands && h)
557
- return [9, h];
575
+ const o = this.parseProperties(h);
576
+ if (this.yieldPropertyCommands && o)
577
+ return [9, o];
558
578
  continue;
559
579
  } catch {
560
- const h = this.scanner.tail.slice(
580
+ const o = this.scanner.tail.slice(
561
581
  p,
562
582
  this.scanner.currentIndex
563
583
  );
564
- i += h;
584
+ i += o;
565
585
  }
566
586
  }
567
587
  continue;
568
588
  }
569
589
  if (n === "%" && this.scanner.peek(1) === "%") {
570
- const o = this.scanner.peek(2).toLowerCase(), h = E[o];
571
- if (h) {
572
- this.scanner.consume(3), i += h;
590
+ const h = this.scanner.peek(2).toLowerCase(), o = v[h];
591
+ if (o) {
592
+ this.scanner.consume(3), i += o;
573
593
  continue;
574
594
  } else {
575
595
  this.scanner.consume(3);
@@ -588,13 +608,13 @@ class x {
588
608
  if (i)
589
609
  return [1, i];
590
610
  if (this.scanner.consume(1), this.yieldPropertyCommands) {
591
- const o = this.ctxStack.current;
611
+ const h = this.ctxStack.current;
592
612
  this.popCtx();
593
- const h = this.getPropertyChanges(o, this.ctxStack.current);
594
- if (Object.keys(h).length > 0)
613
+ const o = this.getPropertyChanges(h, this.ctxStack.current);
614
+ if (Object.keys(o).length > 0)
595
615
  return [
596
616
  9,
597
- { command: void 0, changes: h, depth: this.ctxStack.depth }
617
+ { command: void 0, changes: o, depth: this.ctxStack.depth }
598
618
  ];
599
619
  } else
600
620
  this.popCtx();
@@ -602,17 +622,17 @@ class x {
602
622
  }
603
623
  }
604
624
  if (!this.inStackContext && n === "^") {
605
- const o = this.scanner.peek(1);
606
- if (o) {
607
- const h = o.charCodeAt(0);
608
- if (this.scanner.consume(2), h === 32)
625
+ const h = this.scanner.peek(1);
626
+ if (h) {
627
+ const o = h.charCodeAt(0);
628
+ if (this.scanner.consume(2), o === 32)
609
629
  i += "^";
610
630
  else {
611
- if (h === 73)
631
+ if (o === 73)
612
632
  return i ? [1, i] : [5, null];
613
- if (h === 74)
633
+ if (o === 74)
614
634
  return i ? [1, i] : [6, null];
615
- if (h === 77)
635
+ if (o === 77)
616
636
  continue;
617
637
  i += "▯";
618
638
  }
@@ -626,21 +646,21 @@ class x {
626
646
  for (; ; ) {
627
647
  const [i, u] = l.call(this);
628
648
  if (i) {
629
- if (yield new f(i, this.ctxStack.current.copy(), u), i === 6 && this.resetParagraphParameters) {
649
+ if (yield new k(i, this.ctxStack.current.copy(), u), i === 6 && this.resetParagraphParameters) {
630
650
  const c = this.ctxStack.current, n = a(c);
631
- this.yieldPropertyCommands && Object.keys(n).length > 0 && (yield new f(9, c.copy(), {
651
+ this.yieldPropertyCommands && Object.keys(n).length > 0 && (yield new k(9, c.copy(), {
632
652
  command: void 0,
633
653
  changes: { paragraph: n },
634
654
  depth: this.ctxStack.depth
635
655
  }));
636
656
  }
637
- r && (yield new f(r, this.ctxStack.current.copy(), null), r = null);
657
+ r && (yield new k(r, this.ctxStack.current.copy(), null), r = null);
638
658
  } else
639
659
  break;
640
660
  }
641
661
  }
642
662
  }
643
- class g {
663
+ class d {
644
664
  /**
645
665
  * Create a new text scanner
646
666
  * @param text - The text to scan
@@ -740,7 +760,7 @@ class g {
740
760
  return t;
741
761
  }
742
762
  }
743
- class d {
763
+ class b {
744
764
  // Store as 0xRRGGBB or null
745
765
  /**
746
766
  * Create a new MTextColor instance.
@@ -816,7 +836,7 @@ class d {
816
836
  * @returns A new MTextColor instance with the same color state.
817
837
  */
818
838
  copy() {
819
- const t = new d();
839
+ const t = new b();
820
840
  return t._aci = this._aci, t._rgbValue = this._rgbValue, t;
821
841
  }
822
842
  /**
@@ -835,9 +855,9 @@ class d {
835
855
  return this._aci === t._aci && this._rgbValue === t._rgbValue;
836
856
  }
837
857
  }
838
- class k {
858
+ class m {
839
859
  constructor() {
840
- 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 = {
860
+ 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 = {
841
861
  indent: 0,
842
862
  left: 0,
843
863
  right: 0,
@@ -1007,11 +1027,11 @@ class k {
1007
1027
  * @returns A new context with the same properties
1008
1028
  */
1009
1029
  copy() {
1010
- const t = new k();
1030
+ const t = new m();
1011
1031
  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;
1012
1032
  }
1013
1033
  }
1014
- class f {
1034
+ class k {
1015
1035
  /**
1016
1036
  * Create a new MText token
1017
1037
  * @param type - The token type
@@ -1023,19 +1043,19 @@ class f {
1023
1043
  }
1024
1044
  }
1025
1045
  export {
1026
- d as MTextColor,
1027
- k as MTextContext,
1028
- _ as MTextLineAlignment,
1029
- S as MTextParagraphAlignment,
1030
- x as MTextParser,
1031
- F as MTextStroke,
1032
- f as MTextToken,
1033
- g as TextScanner,
1034
- m as TokenType,
1035
- N as escapeDxfLineEndings,
1036
- w as getFonts,
1037
- I as hasInlineFormattingCodes,
1038
- O as int2rgb,
1039
- y as rgb2int
1046
+ b as MTextColor,
1047
+ m as MTextContext,
1048
+ F as MTextLineAlignment,
1049
+ E as MTextParagraphAlignment,
1050
+ D as MTextParser,
1051
+ R as MTextStroke,
1052
+ k as MTextToken,
1053
+ d as TextScanner,
1054
+ S as TokenType,
1055
+ w as escapeDxfLineEndings,
1056
+ P as getFonts,
1057
+ x as hasInlineFormattingCodes,
1058
+ I as int2rgb,
1059
+ N as rgb2int
1040
1060
  };
1041
1061
  //# sourceMappingURL=parser.es.js.map