@mlightcad/mtext-renderer 0.5.1 → 0.6.1

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.
@@ -18242,16 +18242,18 @@ var md = ih((M) => {
18242
18242
  }
18243
18243
  /**
18244
18244
  * Draw the MText object. This method loads required fonts on demand and builds the object graph.
18245
- *
18246
- * @param isLoadFontsOnDemand - The flag indicate whether to load required fonts on demand
18247
18245
  */
18248
- async draw(t = !0) {
18249
- if (t) {
18250
- const r = Array.from(ii.getFonts(this._mtextData.text || "", !0));
18251
- r.length > 0 && await this._fontManager.loadFontsByNames(r);
18252
- }
18253
- const e = this.loadMText(this._mtextData, this._style);
18254
- e && (this.getBoxes(e, this._boxes), this._boxes.forEach((r) => this.box.union(r)), this.add(e));
18246
+ async asyncDraw() {
18247
+ const t = Array.from(ii.getFonts(this._mtextData.text || "", !0));
18248
+ t.length > 0 && await this._fontManager.loadFontsByNames(t), this.syncDraw();
18249
+ }
18250
+ /**
18251
+ * Draw the MText object. This method assumes that fonts needed are loaded. If font needed
18252
+ * not found, the default font will be used.
18253
+ */
18254
+ syncDraw() {
18255
+ const t = this.loadMText(this._mtextData, this._style);
18256
+ t && (this.getBoxes(t, this._boxes), this._boxes.forEach((e) => this.box.union(e)), this.add(t));
18255
18257
  }
18256
18258
  /**
18257
18259
  * Gets the style manager instance associated with this MText object.
@@ -18454,23 +18456,23 @@ var md = ih((M) => {
18454
18456
  switch (t) {
18455
18457
  case "render": {
18456
18458
  if (!r) throw new Error("Missing data for render message");
18457
- const { mtextContent: s, textStyle: i, colorSettings: a, isLoadFontsOnDemand: o } = r, h = new ii(
18459
+ const { mtextContent: s, textStyle: i, colorSettings: a } = r, o = new ii(
18458
18460
  s,
18459
18461
  i,
18460
18462
  pd,
18461
18463
  Ga,
18462
18464
  a
18463
18465
  );
18464
- await h.draw(o), h.updateMatrixWorld(!0);
18465
- const { data: u, transferableObjects: l } = dd(h);
18466
+ await o.asyncDraw(), o.updateMatrixWorld(!0);
18467
+ const { data: h, transferableObjects: u } = dd(o);
18466
18468
  self.postMessage(
18467
18469
  {
18468
18470
  type: "render",
18469
18471
  id: e,
18470
18472
  success: !0,
18471
- data: u
18473
+ data: h
18472
18474
  },
18473
- { transfer: l }
18475
+ { transfer: u }
18474
18476
  );
18475
18477
  break;
18476
18478
  }
@@ -54,10 +54,13 @@ export declare class MText extends THREE.Object3D {
54
54
  get fontManager(): FontManager;
55
55
  /**
56
56
  * Draw the MText object. This method loads required fonts on demand and builds the object graph.
57
- *
58
- * @param isLoadFontsOnDemand - The flag indicate whether to load required fonts on demand
59
57
  */
60
- draw(isLoadFontsOnDemand?: boolean): Promise<void>;
58
+ asyncDraw(): Promise<void>;
59
+ /**
60
+ * Draw the MText object. This method assumes that fonts needed are loaded. If font needed
61
+ * not found, the default font will be used.
62
+ */
63
+ syncDraw(): void;
61
64
  /**
62
65
  * Gets the style manager instance associated with this MText object.
63
66
  * @returns The StyleManager instance
@@ -21,7 +21,7 @@ export interface MTextObject extends THREE.Object3D {
21
21
  */
22
22
  export interface MTextBaseRenderer {
23
23
  /**
24
- * Render the provided MText content into a Three.js object hierarchy.
24
+ * Render the provided MText content into a Three.js object hierarchy asynchronously
25
25
  *
26
26
  * The returned root object contains meshes/lines for glyphs and exposes a
27
27
  * bounding box on `object.box`.
@@ -31,7 +31,19 @@ export interface MTextBaseRenderer {
31
31
  * @param colorSettings Optional color context (ByLayer, ByBlock colors).
32
32
  * @returns A Promise resolving to a populated `MTextObject` ready to add to a scene.
33
33
  */
34
- renderMText(mtextContent: MTextData, textStyle: TextStyle, colorSettings?: ColorSettings): Promise<MTextObject>;
34
+ asyncRenderMText(mtextContent: MTextData, textStyle: TextStyle, colorSettings?: ColorSettings): Promise<MTextObject>;
35
+ /**
36
+ * Render the provided MText content into a Three.js object hierarchy synchronously.
37
+ *
38
+ * The returned root object contains meshes/lines for glyphs and exposes a
39
+ * bounding box on `object.box`.
40
+ *
41
+ * @param mtextContent Structured MText input (text, height, width, position).
42
+ * @param textStyle Text style to apply (font, width factor, oblique, etc.).
43
+ * @param colorSettings Optional color context (ByLayer, ByBlock colors).
44
+ * @returns A Promise resolving to a populated `MTextObject` ready to add to a scene.
45
+ */
46
+ syncRenderMText(mtextContent: MTextData, textStyle: TextStyle, colorSettings?: ColorSettings): MTextObject;
35
47
  /**
36
48
  * Ensure the specified fonts are available to the renderer.
37
49
  *
@@ -10,9 +10,15 @@ export declare class MainThreadRenderer implements MTextBaseRenderer {
10
10
  private isInitialized;
11
11
  constructor();
12
12
  /**
13
- * Render MText directly in the main thread
13
+ * Render MText directly in the main thread asynchronously. It will ensure that default font
14
+ * is loaded. And fonts needed in mtext are loaded on demand.
14
15
  */
15
- renderMText(mtextContent: MTextData, textStyle: TextStyle, colorSettings?: ColorSettings): Promise<MTextObject>;
16
+ asyncRenderMText(mtextContent: MTextData, textStyle: TextStyle, colorSettings?: ColorSettings): Promise<MTextObject>;
17
+ /**
18
+ * Render MText directly in the main thread synchronously. It is user's responsibility to ensure
19
+ * that default font is loaded and fonts needed in mtext are loaded.
20
+ */
21
+ syncRenderMText(mtextContent: MTextData, textStyle: TextStyle, colorSettings?: ColorSettings): MTextObject;
16
22
  /**
17
23
  * Load fonts in the main thread
18
24
  */
@@ -6,11 +6,11 @@ export type RenderMode = 'main' | 'worker';
6
6
  * Unified renderer that can work in both main thread and web worker modes
7
7
  */
8
8
  export declare class UnifiedRenderer {
9
- private workerManager;
9
+ private webWorkerRenderer;
10
10
  private mainThreadRenderer;
11
11
  private adapter;
12
12
  private currentMode;
13
- private workerConfig?;
13
+ private webWorkerConfig?;
14
14
  /**
15
15
  * Constructor
16
16
  *
@@ -29,9 +29,17 @@ export declare class UnifiedRenderer {
29
29
  */
30
30
  getMode(): RenderMode;
31
31
  /**
32
- * Render MText using the current mode
32
+ * Render MText using the current mode asynchronously
33
33
  */
34
- renderMText(mtextContent: MTextData, textStyle: TextStyle, colorSettings?: ColorSettings): Promise<MTextObject>;
34
+ asyncRenderMText(mtextContent: MTextData, textStyle: TextStyle, colorSettings?: ColorSettings): Promise<MTextObject>;
35
+ /**
36
+ * Render MText using the current mode synchronously.
37
+ *
38
+ * Notes:
39
+ * One error will be thrown if calling this function in 'worker' mode because rendering
40
+ * process is always asynchronous in web worker mode.
41
+ */
42
+ syncRenderMText(mtextContent: MTextData, textStyle: TextStyle, colorSettings?: ColorSettings): MTextObject;
35
43
  /**
36
44
  * Load fonts using the current mode
37
45
  */
@@ -14,12 +14,6 @@ export interface WebWorkerRendererConfig {
14
14
  * @default './mtext-renderer-worker.js'
15
15
  */
16
16
  workerUrl?: string;
17
- /**
18
- * The flag indicate whether to load required fonts on demand
19
- *
20
- * @default false
21
- */
22
- isLoadFontsOnDemand?: boolean;
23
17
  /**
24
18
  * Timeout duration in milliseconds for worker requests
25
19
  * @default 120000
@@ -112,7 +106,6 @@ export declare class WebWorkerRenderer implements MTextBaseRenderer {
112
106
  private requestId;
113
107
  private poolSize;
114
108
  private timeOut;
115
- private isLoadFontsOnDemand;
116
109
  private readyPromise;
117
110
  private isInitialized;
118
111
  private styleManager;
@@ -124,9 +117,14 @@ export declare class WebWorkerRenderer implements MTextBaseRenderer {
124
117
  private sendMessage;
125
118
  private ensureTasksFinished;
126
119
  /**
127
- * Render MText in the worker and return serialized data
120
+ * Render MText in the worker and return serialized data asynchronously.
121
+ */
122
+ asyncRenderMText(mtextContent: MTextData, textStyle: TextStyle, colorSettings?: ColorSettings): Promise<MTextObject>;
123
+ /**
124
+ * Render MText synchronously.
125
+ * Notes: It isn't supported yet.
128
126
  */
129
- renderMText(mtextContent: MTextData, textStyle: TextStyle, colorSettings?: ColorSettings): Promise<MTextObject>;
127
+ syncRenderMText(_mtextContent: MTextData, _textStyle: TextStyle, _colorSettings?: ColorSettings): MTextObject;
130
128
  /**
131
129
  * Load fonts in the worker
132
130
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mlightcad/mtext-renderer",
3
- "version": "0.5.1",
3
+ "version": "0.6.1",
4
4
  "description": "AutoCAD MText renderer based on Three.js",
5
5
  "license": "MIT",
6
6
  "author": "MLight Lee <mlight.lee@outlook.com>",