@mlightcad/mtext-renderer 0.3.2 → 0.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/dist/index.js CHANGED
@@ -10761,7 +10761,7 @@ class Me {
10761
10761
  this.fontMap.clear();
10762
10762
  }
10763
10763
  }
10764
- class bl {
10764
+ class Sl {
10765
10765
  /**
10766
10766
  * Creates a new instance of DefaultFontLoader
10767
10767
  */
@@ -10824,7 +10824,14 @@ const hl = {
10824
10824
  d: 5
10825
10825
  /* DISTRIBUTED */
10826
10826
  };
10827
- class pl {
10827
+ function pl(t, e = !1) {
10828
+ const r = /* @__PURE__ */ new Set(), n = /\\[fF](.*?)[;|]/g;
10829
+ return [...t.matchAll(n)].forEach((a) => {
10830
+ let s = a[1].toLowerCase();
10831
+ e && (s = s.replace(/\.(ttf|otf|woff|shx)$/, "")), r.add(s);
10832
+ }), r;
10833
+ }
10834
+ class dl {
10828
10835
  /**
10829
10836
  * Creates a new MTextParser instance
10830
10837
  * @param content - The MText content to parse
@@ -11802,16 +11809,25 @@ function pn(t) {
11802
11809
  }
11803
11810
  return a !== void 0 && (u.gpuType = a), u;
11804
11811
  }
11805
- const dl = /* @__PURE__ */ new R.Vector3(), vl = 1.666666;
11812
+ const vl = /* @__PURE__ */ new R.Vector3(), gl = 1.666666;
11806
11813
  class hr {
11814
+ /**
11815
+ * Creates a new Context instance with optional initial values.
11816
+ * @param init - Partial object containing initial values for context properties
11817
+ */
11807
11818
  constructor(e) {
11808
11819
  this.font = "", this.fontScaleFactor = 1, this.fontSize = 1, this.fontSizeScaleFactor = 1, this.color = 16777215, this.underline = !1, this.overline = !1, this.strikeThrough = !1, this.obliqueAngle = 0, this.italic = !1, this.bold = !1, this.widthFactor = 1, this.wordSpace = 1, this.blankWidth = 0, this.horizontalAlignment = se.LEFT, Object.assign(this, e);
11809
11820
  }
11821
+ /**
11822
+ * Creates a deep copy of the current context.
11823
+ * This is useful for saving state before applying formatting changes.
11824
+ * @returns A new Context instance with identical property values
11825
+ */
11810
11826
  clone() {
11811
11827
  return new hr({ ...this });
11812
11828
  }
11813
11829
  }
11814
- class gl {
11830
+ class yl {
11815
11831
  /**
11816
11832
  * Construct one instance of this class and initialize some properties with default values.
11817
11833
  * @param style Input text style
@@ -11928,7 +11944,7 @@ class gl {
11928
11944
  * The height of current line of texts
11929
11945
  */
11930
11946
  get currentLineHeight() {
11931
- return this.defaultLineSpaceFactor * this.currentFontSize * vl + this.currentMaxFontSize;
11947
+ return this.defaultLineSpaceFactor * this.currentFontSize * gl + this.currentMaxFontSize;
11932
11948
  }
11933
11949
  /**
11934
11950
  * The maximum font size in current line. Characters in one line may have different font and font
@@ -11939,7 +11955,10 @@ class gl {
11939
11955
  return this._maxFontSize;
11940
11956
  }
11941
11957
  /**
11942
- * The current space setting between two characters
11958
+ * The current space setting between two characters. The meaning of this value is as follows.
11959
+ * - 1: no extra spacing (default tracking)
11960
+ * - 1.2: increases spacing by 20% of the text height
11961
+ * - 0.8: decreases spacing by 20% of the text height
11943
11962
  */
11944
11963
  get currentWordSpace() {
11945
11964
  return this._currentContext.wordSpace;
@@ -12009,7 +12028,7 @@ class gl {
12009
12028
  e.changes.capHeight && (e.changes.capHeight.isRelative ? this.changeFontSizeScaleFactor(e.changes.capHeight.value) : this.changeFontHeight(e.changes.capHeight.value));
12010
12029
  break;
12011
12030
  case "T":
12012
- e.changes.charTrackingFactor && (this._currentContext.wordSpace = e.changes.charTrackingFactor.value);
12031
+ e.changes.charTrackingFactor && (e.changes.charTrackingFactor.isRelative ? this._currentContext.wordSpace = e.changes.charTrackingFactor.value + 1 : this._currentContext.wordSpace = e.changes.charTrackingFactor.value);
12013
12032
  break;
12014
12033
  case "q":
12015
12034
  e.changes.paragraph && e.changes.paragraph.align && (this._currentContext.horizontalAlignment = e.changes.paragraph.align);
@@ -12053,7 +12072,7 @@ class gl {
12053
12072
  this.processBlank();
12054
12073
  else if (s.type === De.PROPERTIES_CHANGED) {
12055
12074
  const i = s.data;
12056
- i.command === void 0 ? this._contextStack.length > 0 && (this._currentContext = this._contextStack.pop()) : (this._contextStack.push(this._currentContext.clone()), this.processFormat(i)), this.processGeometries(r, n, a);
12075
+ i.command === void 0 ? this._contextStack.length > 0 && (this._currentContext = this._contextStack.pop()) : (this._contextStack.length === 0 && this._contextStack.push(this._currentContext.clone()), this.processFormat(i)), this.processGeometries(r, n, a);
12057
12076
  } else s.type === De.STACK && (this.processStack(s.data, r, n), this.processGeometries(r, n, a));
12058
12077
  return (r.length > 0 || n.length > 0) && this.processGeometries(r, n, a), a;
12059
12078
  }
@@ -12221,7 +12240,7 @@ class gl {
12221
12240
  if (e.forEach((n, a) => {
12222
12241
  n.boundingBox || n.computeBoundingBox(), a === 0 ? r = n.boundingBox : r.union(n.boundingBox);
12223
12242
  }), r) {
12224
- const n = r.getSize(dl);
12243
+ const n = r.getSize(vl);
12225
12244
  switch (this.currentHorizontalAlignment) {
12226
12245
  case se.LEFT:
12227
12246
  break;
@@ -12283,7 +12302,25 @@ class gl {
12283
12302
  }
12284
12303
  }
12285
12304
  const Mt = /* @__PURE__ */ new R.Vector3(), we = /* @__PURE__ */ new R.Vector3(), Bt = /* @__PURE__ */ new R.Vector3(), Pt = /* @__PURE__ */ new R.Quaternion(), It = /* @__PURE__ */ new R.Matrix4(), dn = /* @__PURE__ */ new R.Matrix4(), vn = /* @__PURE__ */ new R.Vector3(1, 0, 0);
12286
- class Sl extends R.Object3D {
12305
+ class kl extends R.Object3D {
12306
+ /**
12307
+ * Extracts all unique font names used in an MText string.
12308
+ * This function searches for font commands in the format \f{fontname}| or \f{fontname}; and returns a set of unique font names.
12309
+ * Font names are converted to lowercase to ensure case-insensitive uniqueness.
12310
+ *
12311
+ * @param mtext - The MText string to analyze for font names
12312
+ * @param removeExtension - Whether to remove font file extensions (e.g., .ttf, .shx) from font names. Defaults to false.
12313
+ * @returns A Set containing all unique font names found in the MText string, converted to lowercase
12314
+ * @example
12315
+ * ```ts
12316
+ * const mtext = "\\fArial.ttf|Hello\\fTimes New Roman.otf|World";
12317
+ * const fonts = getFonts(mtext, true);
12318
+ * // Returns: Set(2) { "arial", "times new roman" }
12319
+ * ```
12320
+ */
12321
+ static getFonts(e, r = !1) {
12322
+ return pl(e, r);
12323
+ }
12287
12324
  /**
12288
12325
  * Creates a new instance of MText.
12289
12326
  * @param text - The MText data containing text content and properties
@@ -12410,7 +12447,7 @@ class Sl extends R.Object3D {
12410
12447
  removeFontExtension: !0
12411
12448
  }, c = new mt();
12412
12449
  c.fontFace.family = r.font, c.capHeight = { value: e.height || 1, isRelative: !0 }, c.widthFactor = { value: e.widthFactor ?? 1, isRelative: !0 }, c.align = s, c.paragraph.align = a;
12413
- const h = new pl(e.text, c, !0).parse(), p = new gl(
12450
+ const h = new dl(e.text, c, !0).parse(), p = new yl(
12414
12451
  r,
12415
12452
  this.styleManager,
12416
12453
  this.fontManager,
@@ -12480,7 +12517,7 @@ class Sl extends R.Object3D {
12480
12517
  this.getBoxes(n[a], r);
12481
12518
  }
12482
12519
  }
12483
- class kl {
12520
+ class Tl {
12484
12521
  constructor() {
12485
12522
  this.lineBasicMaterials = {}, this.meshBasicMaterials = {}, this.unsupportedTextStyles = {};
12486
12523
  }
@@ -12498,12 +12535,12 @@ class kl {
12498
12535
  export {
12499
12536
  gn as BaseFont,
12500
12537
  yn as BaseTextShape,
12501
- bl as DefaultFontLoader,
12538
+ Sl as DefaultFontLoader,
12502
12539
  pr as EventManager,
12503
12540
  Se as FontFactory,
12504
12541
  Me as FontManager,
12505
- Sl as MText,
12542
+ kl as MText,
12506
12543
  cl as MTextAttachmentPoint,
12507
12544
  je as MTextFlowDirection,
12508
- kl as StyleManager
12545
+ Tl as StyleManager
12509
12546
  };