@mlightcad/mtext-parser 1.1.7 → 1.1.9

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,5 +1,5 @@
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
- const F = {
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 = {
3
3
  c: "Ø",
4
4
  d: "°",
5
5
  p: "±"
@@ -11,11 +11,11 @@ const F = {
11
11
  d: 5
12
12
  /* DISTRIBUTED */
13
13
  };
14
- function O(s) {
14
+ function y(s) {
15
15
  const [t, e, r] = s;
16
16
  return r << 16 | e << 8 | t;
17
17
  }
18
- function y(s) {
18
+ function O(s) {
19
19
  const t = s & 255, e = s >> 8 & 255, r = s >> 16 & 255;
20
20
  return [t, e, r];
21
21
  }
@@ -25,7 +25,7 @@ function N(s) {
25
25
  function I(s) {
26
26
  return s.replace(/\\P/g, "").replace(/\\~/g, "").includes("\\");
27
27
  }
28
- function x(s, t = !1) {
28
+ function w(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();
@@ -84,7 +84,7 @@ class v {
84
84
  this.stack[this.stack.length - 1] = t;
85
85
  }
86
86
  }
87
- class D {
87
+ class x {
88
88
  /**
89
89
  * Creates a new MTextParser instance
90
90
  * @param content - The MText content to parse
@@ -149,11 +149,11 @@ class D {
149
149
  }, u = (c) => {
150
150
  let n = "", p = c;
151
151
  for (; t.hasData; ) {
152
- const [h, o] = l();
153
- if (!(p && h === " ")) {
154
- if (p = !1, !o && h === ";")
152
+ const [o, h] = l();
153
+ if (!(p && o === " ")) {
154
+ if (p = !1, !h && o === ";")
155
155
  break;
156
- n += h;
156
+ n += o;
157
157
  }
158
158
  }
159
159
  return n;
@@ -237,7 +237,7 @@ class D {
237
237
  const r = {};
238
238
  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), 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)) {
239
239
  const a = {};
240
- 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);
240
+ 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.tabs) !== JSON.stringify(e.paragraph.tabs) && (a.tabs = e.paragraph.tabs), Object.keys(a).length > 0 && (r.paragraph = a);
241
241
  }
242
242
  return r;
243
243
  }
@@ -458,11 +458,11 @@ class D {
458
458
  const p = e.peek();
459
459
  if (p === "r" || p === "c") {
460
460
  e.consume(1);
461
- const h = c();
462
- u.push(p + h.toString());
461
+ const o = c();
462
+ u.push(p + o.toString());
463
463
  } else {
464
- const h = c();
465
- isNaN(h) ? e.consume(1) : u.push(h);
464
+ const o = c();
465
+ isNaN(o) ? e.consume(1) : u.push(o);
466
466
  }
467
467
  }
468
468
  break;
@@ -472,7 +472,7 @@ class D {
472
472
  left: a,
473
473
  right: l,
474
474
  align: i,
475
- tab_stops: u
475
+ tabs: u
476
476
  };
477
477
  }
478
478
  /**
@@ -494,10 +494,10 @@ class D {
494
494
  left: 0,
495
495
  right: 0,
496
496
  align: 0,
497
- tab_stops: []
497
+ tabs: []
498
498
  };
499
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;
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.tabs) !== JSON.stringify([]) && (c.tabs = []), c;
501
501
  }
502
502
  const l = () => {
503
503
  var u;
@@ -520,8 +520,8 @@ class D {
520
520
  if (i)
521
521
  return [1, i];
522
522
  this.scanner.consume(1);
523
- const h = this.scanner.get();
524
- switch (h) {
523
+ const o = this.scanner.get();
524
+ switch (o) {
525
525
  case "~":
526
526
  return [4, null];
527
527
  case "P":
@@ -532,17 +532,17 @@ class D {
532
532
  return [8, null];
533
533
  case "S": {
534
534
  this.inStackContext = !0;
535
- const o = this.parseStacking();
536
- return this.inStackContext = !1, o;
535
+ const h = this.parseStacking();
536
+ return this.inStackContext = !1, h;
537
537
  }
538
538
  case "m":
539
539
  case "M":
540
540
  if (this.scanner.peek() === "+") {
541
541
  this.scanner.consume(1);
542
- const o = (u = this.scanner.tail.match(/^[0-9A-Fa-f]{4}/)) == null ? void 0 : u[0];
543
- if (o) {
542
+ const h = (u = this.scanner.tail.match(/^[0-9A-Fa-f]{4}/)) == null ? void 0 : u[0];
543
+ if (h) {
544
544
  this.scanner.consume(4);
545
- const b = this.decodeMultiByteChar(o);
545
+ const b = this.decodeMultiByteChar(h);
546
546
  return i ? [1, i] : [1, b];
547
547
  }
548
548
  this.scanner.consume(-1);
@@ -550,26 +550,26 @@ class D {
550
550
  i += "\\M";
551
551
  continue;
552
552
  default:
553
- if (h)
553
+ if (o)
554
554
  try {
555
- const o = this.parseProperties(h);
556
- if (this.yieldPropertyCommands && o)
557
- return [9, o];
555
+ const h = this.parseProperties(o);
556
+ if (this.yieldPropertyCommands && h)
557
+ return [9, h];
558
558
  continue;
559
559
  } catch {
560
- const o = this.scanner.tail.slice(
560
+ const h = this.scanner.tail.slice(
561
561
  p,
562
562
  this.scanner.currentIndex
563
563
  );
564
- i += o;
564
+ i += h;
565
565
  }
566
566
  }
567
567
  continue;
568
568
  }
569
569
  if (n === "%" && this.scanner.peek(1) === "%") {
570
- const h = this.scanner.peek(2).toLowerCase(), o = F[h];
571
- if (o) {
572
- this.scanner.consume(3), i += o;
570
+ const o = this.scanner.peek(2).toLowerCase(), h = E[o];
571
+ if (h) {
572
+ this.scanner.consume(3), i += h;
573
573
  continue;
574
574
  } else {
575
575
  this.scanner.consume(3);
@@ -588,13 +588,13 @@ class D {
588
588
  if (i)
589
589
  return [1, i];
590
590
  if (this.scanner.consume(1), this.yieldPropertyCommands) {
591
- const h = this.ctxStack.current;
591
+ const o = this.ctxStack.current;
592
592
  this.popCtx();
593
- const o = this.getPropertyChanges(h, this.ctxStack.current);
594
- if (Object.keys(o).length > 0)
593
+ const h = this.getPropertyChanges(o, this.ctxStack.current);
594
+ if (Object.keys(h).length > 0)
595
595
  return [
596
596
  9,
597
- { command: void 0, changes: o, depth: this.ctxStack.depth }
597
+ { command: void 0, changes: h, depth: this.ctxStack.depth }
598
598
  ];
599
599
  } else
600
600
  this.popCtx();
@@ -602,17 +602,17 @@ class D {
602
602
  }
603
603
  }
604
604
  if (!this.inStackContext && n === "^") {
605
- const h = this.scanner.peek(1);
606
- if (h) {
607
- const o = h.charCodeAt(0);
608
- if (this.scanner.consume(2), o === 32)
605
+ const o = this.scanner.peek(1);
606
+ if (o) {
607
+ const h = o.charCodeAt(0);
608
+ if (this.scanner.consume(2), h === 32)
609
609
  i += "^";
610
610
  else {
611
- if (o === 73)
611
+ if (h === 73)
612
612
  return i ? [1, i] : [5, null];
613
- if (o === 74)
613
+ if (h === 74)
614
614
  return i ? [1, i] : [6, null];
615
- if (o === 77)
615
+ if (h === 77)
616
616
  continue;
617
617
  i += "▯";
618
618
  }
@@ -628,15 +628,11 @@ class D {
628
628
  if (i) {
629
629
  if (yield new f(i, this.ctxStack.current.copy(), u), i === 6 && this.resetParagraphParameters) {
630
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
- ));
631
+ this.yieldPropertyCommands && Object.keys(n).length > 0 && (yield new f(9, c.copy(), {
632
+ command: void 0,
633
+ changes: { paragraph: n },
634
+ depth: this.ctxStack.depth
635
+ }));
640
636
  }
641
637
  r && (yield new f(r, this.ctxStack.current.copy(), null), r = null);
642
638
  } else
@@ -846,7 +842,7 @@ class k {
846
842
  left: 0,
847
843
  right: 0,
848
844
  align: 0,
849
- tab_stops: []
845
+ tabs: []
850
846
  };
851
847
  }
852
848
  /**
@@ -923,6 +919,36 @@ class k {
923
919
  set rgb(t) {
924
920
  this.color.rgb = t;
925
921
  }
922
+ /**
923
+ * Gets whether the current text should be rendered in italic style.
924
+ * @returns {boolean} True if the font style is 'Italic', otherwise false.
925
+ */
926
+ get italic() {
927
+ return this.fontFace.style === "Italic";
928
+ }
929
+ /**
930
+ * Sets whether the current text should be rendered in italic style.
931
+ * @param value - If true, sets the font style to 'Italic'; if false, sets it to 'Regular'.
932
+ */
933
+ set italic(t) {
934
+ this.fontFace.style = t ? "Italic" : "Regular";
935
+ }
936
+ /**
937
+ * Gets whether the current text should be rendered in bold style.
938
+ * This is primarily used for mesh fonts and affects font selection.
939
+ * @returns {boolean} True if the font weight is 700 or higher, otherwise false.
940
+ */
941
+ get bold() {
942
+ return (this.fontFace.weight || 400) >= 700;
943
+ }
944
+ /**
945
+ * Sets whether the current text should be rendered in bold style.
946
+ * This is primarily used for mesh fonts and affects font selection.
947
+ * @param value - If true, sets the font weight to 700; if false, sets it to 400.
948
+ */
949
+ set bold(t) {
950
+ this.fontFace.weight = t ? 700 : 400;
951
+ }
926
952
  /**
927
953
  * Get whether text is underlined
928
954
  */
@@ -999,17 +1025,17 @@ class f {
999
1025
  export {
1000
1026
  d as MTextColor,
1001
1027
  k as MTextContext,
1002
- m as MTextLineAlignment,
1028
+ _ as MTextLineAlignment,
1003
1029
  S as MTextParagraphAlignment,
1004
- D as MTextParser,
1005
- E as MTextStroke,
1030
+ x as MTextParser,
1031
+ F as MTextStroke,
1006
1032
  f as MTextToken,
1007
1033
  g as TextScanner,
1008
- _ as TokenType,
1034
+ m as TokenType,
1009
1035
  N as escapeDxfLineEndings,
1010
- x as getFonts,
1036
+ w as getFonts,
1011
1037
  I as hasInlineFormattingCodes,
1012
- y as int2rgb,
1013
- O as rgb2int
1038
+ O as int2rgb,
1039
+ y as rgb2int
1014
1040
  };
1015
1041
  //# sourceMappingURL=parser.es.js.map