@mlightcad/mtext-renderer 0.10.0 → 0.10.2

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.
Files changed (42) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +523 -523
  3. package/dist/index.js +25481 -0
  4. package/dist/index.umd.cjs +14 -0
  5. package/dist/mtext-renderer-worker.js +30383 -0
  6. package/lib/cache/fontCacheManager.d.ts +71 -0
  7. package/lib/cache/index.d.ts +1 -0
  8. package/lib/cache/schema.d.ts +27 -0
  9. package/lib/common/eventManager.d.ts +26 -0
  10. package/lib/common/index.d.ts +2 -0
  11. package/lib/common/utils.d.ts +11 -0
  12. package/lib/font/baseFont.d.ts +81 -0
  13. package/lib/font/baseTextShape.d.ts +17 -0
  14. package/lib/font/charGeometryCache.d.ts +43 -0
  15. package/lib/font/defaultFontLoader.d.ts +50 -0
  16. package/lib/font/font.d.ts +25 -0
  17. package/lib/font/fontFactory.d.ts +31 -0
  18. package/lib/font/fontLoader.d.ts +58 -0
  19. package/lib/font/fontManager.d.ts +192 -0
  20. package/lib/font/index.d.ts +7 -0
  21. package/lib/font/meshFont.d.ts +138 -0
  22. package/lib/font/meshFontParser.d.ts +10 -0
  23. package/lib/font/meshTextShape.d.ts +33 -0
  24. package/lib/font/normalComputationToggle.d.ts +57 -0
  25. package/lib/font/shxFont.d.ts +62 -0
  26. package/lib/font/shxTextShape.d.ts +29 -0
  27. package/lib/font/threeFont.d.ts +50 -0
  28. package/lib/index.d.ts +5 -0
  29. package/lib/renderer/charBoxUtils.d.ts +4 -0
  30. package/lib/renderer/defaultStyleManager.d.ts +18 -0
  31. package/lib/renderer/index.d.ts +3 -0
  32. package/lib/renderer/mtext.d.ts +134 -0
  33. package/lib/renderer/mtextProcessor.d.ts +249 -0
  34. package/lib/renderer/styleManager.d.ts +20 -0
  35. package/lib/renderer/types.d.ts +199 -0
  36. package/lib/worker/baseRenderer.d.ts +92 -0
  37. package/lib/worker/index.d.ts +5 -0
  38. package/lib/worker/mainThreadRenderer.d.ts +49 -0
  39. package/lib/worker/mtextWorker.d.ts +1 -0
  40. package/lib/worker/unifiedRenderer.d.ts +69 -0
  41. package/lib/worker/webWorkerRenderer.d.ts +190 -0
  42. package/package.json +2 -2
@@ -0,0 +1,249 @@
1
+ import { ChangedProperties, MTextParagraphAlignment, MTextToken } from '@mlightcad/mtext-parser';
2
+ import { FontManager } from '../font';
3
+ import { StyleManager } from './styleManager';
4
+ import { LineLayout, MTextFlowDirection, TextStyle } from './types';
5
+ import * as THREE from 'three';
6
+ export interface MTextFormatOptions {
7
+ /**
8
+ * Font size.
9
+ */
10
+ fontSize: number;
11
+ /**
12
+ * Scale factor of character width.
13
+ */
14
+ widthFactor: number;
15
+ /**
16
+ * The line space factor.
17
+ */
18
+ lineSpaceFactor: number;
19
+ /**
20
+ * The horizontal alignment.
21
+ */
22
+ horizontalAlignment: MTextParagraphAlignment;
23
+ /**
24
+ * The maximum width of one line of text string.
25
+ */
26
+ maxWidth: number;
27
+ /**
28
+ * The direction that the text string follows from its start to its finish.
29
+ */
30
+ flowDirection: MTextFlowDirection;
31
+ /**
32
+ * The color of the current block which is used when the text color is by block.
33
+ */
34
+ byBlockColor: number;
35
+ /**
36
+ * The color of the current layer which is used when the text color is by layer.
37
+ */
38
+ byLayerColor: number;
39
+ /**
40
+ * Whether to remove font name extension.
41
+ */
42
+ removeFontExtension: boolean;
43
+ /**
44
+ * Whether to collect per-character bounding boxes for picking.
45
+ */
46
+ collectCharBoxes?: boolean;
47
+ }
48
+ /**
49
+ * This class represents lines of texts.
50
+ */
51
+ export declare class MTextProcessor {
52
+ private _style;
53
+ private _styleManager;
54
+ private _fontManager;
55
+ private _options;
56
+ private _totalHeight;
57
+ private _hOffset;
58
+ private _vOffset;
59
+ private _lineCount;
60
+ private _currentLineObjects;
61
+ private _contextStack;
62
+ private _currentContext;
63
+ private _maxFontSize;
64
+ /**
65
+ * The current horizontal alignment for the paragraph.
66
+ *
67
+ * In AutoCAD MText, paragraph-level formatting commands (such as \pqr, \pql, \pqc)
68
+ * persist for the entire paragraph and are not scoped to inline formatting groups ({} blocks).
69
+ * Only character-level formatting (font, bold, italic, color, etc.) is scoped to {} and managed via Context.
70
+ * Therefore, paragraph alignment is maintained at the MTextProcessor level and not in Context,
71
+ * so it persists until explicitly changed by another paragraph alignment command.
72
+ */
73
+ private _currentHorizontalAlignment;
74
+ private _lastCharBoxTarget;
75
+ private _lineHasRenderableChar;
76
+ private _pendingEmptyLineFontSizeAdjust?;
77
+ private _lineLayouts;
78
+ private _lineBreakIndices;
79
+ private _processedCharCount;
80
+ private _currentIndent;
81
+ private _currentLeftMargin;
82
+ private _currentRightMargin;
83
+ /**
84
+ * Construct one instance of this class and initialize some properties with default values.
85
+ * @param style Input text style
86
+ * @param styleManager Input text style manager instance
87
+ * @param fontManager Input font manager instance
88
+ * @param options Input formating options
89
+ */
90
+ constructor(style: TextStyle, styleManager: StyleManager, fontManager: FontManager, options: MTextFormatOptions);
91
+ get fontManager(): FontManager;
92
+ get styleManager(): StyleManager;
93
+ get textStyle(): TextStyle;
94
+ /**
95
+ * Total height of all lines of text
96
+ */
97
+ get totalHeight(): number;
98
+ /**
99
+ * The maximum width of one text line
100
+ */
101
+ get maxWidth(): number;
102
+ /**
103
+ * The direction that the text string follows from its start to its finish.
104
+ */
105
+ get flowDirection(): MTextFlowDirection;
106
+ /**
107
+ * The default horizontal alignment of one text line
108
+ */
109
+ get defaultHorizontalAlignment(): MTextParagraphAlignment;
110
+ /**
111
+ * The default scale factor of character width
112
+ */
113
+ get defaultWidthFactor(): number;
114
+ /**
115
+ * The default font size of texts
116
+ */
117
+ get defaultFontSize(): number;
118
+ /**
119
+ * The default line space factor
120
+ */
121
+ get defaultLineSpaceFactor(): number;
122
+ /**
123
+ * Font name of current character
124
+ */
125
+ get currentFont(): string;
126
+ /**
127
+ * The current horizontal alignment of one text line
128
+ */
129
+ get currentHorizontalAlignment(): MTextParagraphAlignment;
130
+ /**
131
+ * Font size of current character
132
+ */
133
+ get currentFontSize(): number;
134
+ /**
135
+ * The height of current line of texts
136
+ */
137
+ get currentLineHeight(): number;
138
+ /**
139
+ * The maximum font size in current line. Characters in one line may have different font and font
140
+ * size. So we need to store the maximum font size in current line in order to calculate the height
141
+ * of current line.
142
+ */
143
+ get currentMaxFontSize(): number;
144
+ /**
145
+ * The current space setting between two characters. The meaning of this value is as follows.
146
+ * - 1: no extra spacing (default tracking)
147
+ * - 1.2: increases spacing by 20% of the text height
148
+ * - 0.8: decreases spacing by 20% of the text height
149
+ */
150
+ get currentWordSpace(): number;
151
+ /**
152
+ * The current scale factor of character width
153
+ */
154
+ get currentWidthFactor(): number;
155
+ /**
156
+ * All of THREE.js objects in current line. It contains objects in all of sections of this line.
157
+ */
158
+ get currentLineObjects(): THREE.Object3D<THREE.Object3DEventMap>[];
159
+ get lineLayouts(): LineLayout[];
160
+ /**
161
+ * The horizental offset of current character in this line
162
+ */
163
+ get hOffset(): number;
164
+ set hOffset(value: number);
165
+ /**
166
+ * The vertical offset of current character in this line
167
+ */
168
+ get vOffset(): number;
169
+ set vOffset(value: number);
170
+ get currentIndent(): number;
171
+ get currentLeftMargin(): number;
172
+ get currentRightMargin(): number;
173
+ get maxLineWidth(): number;
174
+ /**
175
+ * Process text format information
176
+ * @param item Input mtext inline codes
177
+ */
178
+ processFormat(item: ChangedProperties): void;
179
+ /**
180
+ * Reset paragraph properties to their default values from options.
181
+ */
182
+ private resetParagraphProperties;
183
+ /**
184
+ * Start a new paragraph by processing current geometries, resetting paragraph properties,
185
+ * and starting a new line with indent applied.
186
+ * @param geometries Current text geometries to process
187
+ * @param lineGeometries Current line geometries to process
188
+ * @param group The group to add processed geometries to
189
+ */
190
+ private startNewParagraph;
191
+ /**
192
+ * Render the specified texts
193
+ * @param item Input texts to render
194
+ */
195
+ processText(tokens: Generator<MTextToken>): THREE.Group<THREE.Object3DEventMap>;
196
+ private processGeometries;
197
+ private processWord;
198
+ private processStack;
199
+ private recordStackDivider;
200
+ /**
201
+ * Convert a legacy top-anchored vOffset (used by stack/sub/sup logic) into
202
+ * the current baseline-anchored coordinate system.
203
+ */
204
+ private convertTopAlignedVOffset;
205
+ private processBlank;
206
+ private recordVisualLineBreak;
207
+ private recordCurrentLineLayout;
208
+ private processChar;
209
+ private processLastLine;
210
+ private initLineParams;
211
+ private changeFont;
212
+ /**
213
+ * Calcuate font size, line space, line height and other parameters.
214
+ */
215
+ private calcuateLineParams;
216
+ /**
217
+ * Get text shape of the specified character
218
+ * @param char Input one character
219
+ * @returns Return the text shape of the specified character
220
+ */
221
+ private getCharShape;
222
+ private advanceToNextLine;
223
+ private countFinalCharBoxes;
224
+ private applyPendingEmptyLineYAdjust;
225
+ private resolveCharBoxTarget;
226
+ /**
227
+ * Apply translation on the specified buffer geometries according to text alignment setting
228
+ */
229
+ private processAlignment;
230
+ /**
231
+ * In AutoCAD, the width of a regular space character (ASCII 32, the space key on the keyboard) in MText
232
+ * depends on the current font and text height, and is not a fixed value.
233
+ * Specifically:
234
+ * - Space width ≈ Text height × space width ratio defined by the font
235
+ * - For common TrueType fonts (like Arial), the space width is typically about 1/4 to 1/3 of the text height.
236
+ * For example, if the text height is 10 (units), the space width would be approximately 2.5 to 3.3 units.
237
+ * - For SHX fonts (AutoCAD's built-in vector fonts, such as txt.shx), the space width is often half the text height.
238
+ * So if the text height is 10, the space width is typically 5 units.
239
+ */
240
+ private calculateBlankWidthForFont;
241
+ /**
242
+ * Convert the text shape geometries to three.js object
243
+ * @param geometries Input text shape geometries
244
+ * @returns Return three.js object created from the specified text shape geometries
245
+ */
246
+ private toThreeObject;
247
+ private changeFontSizeScaleFactor;
248
+ private changeFontHeight;
249
+ }
@@ -0,0 +1,20 @@
1
+ import { StyleTraits } from './types';
2
+ import * as THREE from 'three';
3
+ /**
4
+ * Class to manage materials used by texts
5
+ */
6
+ export interface StyleManager {
7
+ unsupportedTextStyles: Record<string, number>;
8
+ /**
9
+ * Gets one reusable material for mesh type font. If not found in cache, just create one.
10
+ * @param traits - Traits to define one mesh basic material
11
+ * @returns - One reusable material for mesh type font.
12
+ */
13
+ getMeshBasicMaterial(traits: StyleTraits): THREE.Material;
14
+ /**
15
+ * Gets one reusable material for line type font. If not found in cache, just create one.
16
+ * @param traits - Traits to define one line basic material
17
+ * @returns - One reusable material for line type font.
18
+ */
19
+ getLineBasicMaterial(traits: StyleTraits): THREE.Material;
20
+ }
@@ -0,0 +1,199 @@
1
+ import * as THREE from 'three';
2
+ /**
3
+ * A 3D point in drawing coordinates.
4
+ */
5
+ export interface Point3d {
6
+ /** X coordinate */
7
+ x: number;
8
+ /** Y coordinate */
9
+ y: number;
10
+ /** Z coordinate */
11
+ z: number;
12
+ }
13
+ /**
14
+ * A 2D point in drawing coordinates.
15
+ */
16
+ export interface Point2d {
17
+ /** X coordinate */
18
+ x: number;
19
+ /** Y coordinate */
20
+ y: number;
21
+ }
22
+ /**
23
+ * Defines the global text flow direction for MText layout.
24
+ */
25
+ export declare enum MTextFlowDirection {
26
+ /** Text flows from left to right. */
27
+ LEFT_TO_RIGHT = 1,
28
+ /** Text flows from right to left. */
29
+ RIGHT_TO_LEFT = 2,
30
+ /** Text flows from top to bottom. */
31
+ TOP_TO_BOTTOM = 3,
32
+ /** Text flows from bottom to top. */
33
+ BOTTOM_TO_TOP = 4,
34
+ /** Use the direction defined by the active text style. */
35
+ BY_STYLE = 5
36
+ }
37
+ /**
38
+ * Anchor position used to align rendered MText relative to its insertion point.
39
+ */
40
+ export declare enum MTextAttachmentPoint {
41
+ /** Top-left corner. */
42
+ TopLeft = 1,
43
+ /** Top-center point. */
44
+ TopCenter = 2,
45
+ /** Top-right corner. */
46
+ TopRight = 3,
47
+ /** Middle-left point. */
48
+ MiddleLeft = 4,
49
+ /** Center point. */
50
+ MiddleCenter = 5,
51
+ /** Middle-right point. */
52
+ MiddleRight = 6,
53
+ /** Bottom-left corner. */
54
+ BottomLeft = 7,
55
+ /** Bottom-center point. */
56
+ BottomCenter = 8,
57
+ /** Bottom-right corner. */
58
+ BottomRight = 9
59
+ }
60
+ /**
61
+ * Logical text token with optional pick box information.
62
+ *
63
+ * Semantics by {@link CharBoxType}:
64
+ * - `CHAR`: `char` is the rendered character, `box` is defined, `children` is empty.
65
+ * - `STACK`: `char` is `''`, `box` is the union box of stack components, `children` contains stack parts.
66
+ */
67
+ export interface CharBox {
68
+ /** Token type. */
69
+ type: CharBoxType;
70
+ /** Token bounding box in local MText coordinates. */
71
+ box: THREE.Box3;
72
+ /** Token character payload (`''` for `STACK`). */
73
+ char: string;
74
+ /** Nested token components (currently used by `STACK`). */
75
+ children: CharBox[];
76
+ }
77
+ /**
78
+ * Per-line layout geometry used by text cursor and line hit-testing.
79
+ */
80
+ export interface LineLayout {
81
+ /** Line center Y used for cursor placement and hit-testing. */
82
+ y: number;
83
+ /** Line height used for cursor size and vertical hit area. */
84
+ height: number;
85
+ /**
86
+ * Visual line-break index in `MTextLayout.chars` for this line.
87
+ * Index `i` means a break between char `i - 1` and char `i`.
88
+ *
89
+ * This is line-boundary data (rendered rows), not paragraph structure.
90
+ * Duplicated indices are meaningful and represent empty lines.
91
+ *
92
+ * This field is `undefined` for the last rendered line.
93
+ */
94
+ breakIndex?: number;
95
+ }
96
+ /**
97
+ * Aggregated layout output for rendered MText.
98
+ */
99
+ export interface MTextLayout {
100
+ /** Per-line layout entries. */
101
+ lines: LineLayout[];
102
+ /** Logical text token boxes for picking/debug. */
103
+ chars: CharBox[];
104
+ }
105
+ /**
106
+ * Type of logical token emitted in {@link CharBox} output.
107
+ */
108
+ export declare enum CharBoxType {
109
+ /** Regular rendered character token. */
110
+ CHAR = "CHAR",
111
+ /** Stack token (for fraction-style stacked expressions). */
112
+ STACK = "STACK"
113
+ }
114
+ /**
115
+ * Sentinel character used internally to represent a stack divider line.
116
+ */
117
+ export declare const STACK_DIVIDER_CHAR = "\uE000";
118
+ export interface StyleTraits {
119
+ /**
120
+ * Optional layer name. Material is identified by layer and color. So it means different
121
+ * materials are created for the same color and differnt layer.
122
+ */
123
+ layer?: string;
124
+ /**
125
+ * The color of material
126
+ */
127
+ color: number;
128
+ /**
129
+ * One flag to indicate whether the color is by layer. If it is true, it means that the
130
+ * material become invalid once layer color changed.
131
+ */
132
+ isByLayer?: boolean;
133
+ }
134
+ /**
135
+ * Represents the data structure for multiline text (MText) entities.
136
+ * Contains all necessary properties to define the appearance and positioning of text.
137
+ */
138
+ export interface MTextData {
139
+ /** The actual text content to be displayed */
140
+ text: string;
141
+ /** The height of the text characters in drawing units */
142
+ height: number;
143
+ /** The width of the text box in drawing units. Text will wrap if it exceeds this width */
144
+ width: number;
145
+ /** The 3D insertion point coordinates where the text will be placed */
146
+ position: Point3d;
147
+ /** The rotation angle of the text in radians. Default is 0 (horizontal) */
148
+ rotation?: number;
149
+ /** The normal vector that defines the plane in which the text lies. Used for 3D orientation */
150
+ directionVector?: Point3d;
151
+ /** Specifies which point of the text boundary is aligned with the insertion point */
152
+ attachmentPoint?: MTextAttachmentPoint;
153
+ /** Determines the primary direction in which text flows */
154
+ drawingDirection?: MTextFlowDirection;
155
+ /** Factor that controls the spacing between text lines. Default is 1.0 */
156
+ lineSpaceFactor?: number;
157
+ /** The width scaling factor applied to each character. Default is 1.0 */
158
+ widthFactor?: number;
159
+ /** Whether to collect per-character bounding boxes for picking. Default is true */
160
+ collectCharBoxes?: boolean;
161
+ }
162
+ /**
163
+ * Represents a text style configuration that defines the visual appearance and formatting of text.
164
+ * This interface contains properties that control various aspects of text rendering including font,
165
+ * dimensions, and display characteristics.
166
+ */
167
+ export interface TextStyle extends StyleTraits {
168
+ /** The unique name identifier for this text style */
169
+ name: string;
170
+ /** Flag indicating standard text style settings. Controls various text generation behaviors */
171
+ standardFlag: number;
172
+ /** The fixed height of the text in drawing units. Used when text height should remain constant */
173
+ fixedTextHeight: number;
174
+ /** The horizontal scaling factor applied to text characters. Default is 1.0 for normal width */
175
+ widthFactor: number;
176
+ /** The angle in radians for italic text. 0.0 represents vertical text, positive values slant to the right */
177
+ obliqueAngle: number;
178
+ /** Bit-coded flag controlling text generation options (e.g., mirroring, upside-down) */
179
+ textGenerationFlag: number;
180
+ /** The most recently used text height for this style */
181
+ lastHeight: number;
182
+ /** The primary font name or file to be used for text rendering */
183
+ font: string;
184
+ /** The font name or file to be used for wide characters (typically used for CJK characters) */
185
+ bigFont: string;
186
+ /** Optional extended font settings or alternative font specification */
187
+ extendedFont?: string;
188
+ }
189
+ /**
190
+ * Defines the default color settings for special color modes in text rendering.
191
+ * These settings are used to resolve color values when text uses layer-dependent
192
+ * or block-dependent coloring.
193
+ */
194
+ export interface ColorSettings {
195
+ /** The color value to use when text is set to "by layer" color mode */
196
+ byLayerColor: number;
197
+ /** The color value to use when text is set to "by block" color mode */
198
+ byBlockColor: number;
199
+ }
@@ -0,0 +1,92 @@
1
+ import { StyleManager } from '../renderer/styleManager';
2
+ import { ColorSettings, MTextData, MTextLayout, TextStyle } from '../renderer/types';
3
+ import * as THREE from 'three';
4
+ /**
5
+ * Represents a rendered MText object that extends THREE.Object3D with additional MText-specific properties.
6
+ * This interface defines the contract for objects returned by MText renderers.
7
+ */
8
+ export interface MTextObject extends THREE.Object3D {
9
+ /**
10
+ * The bounding box of the MText object in local coordinates.
11
+ * This box represents the bounds of the text content without considering transformations.
12
+ * To get the world-space bounding box, apply the object's world matrix to this box.
13
+ */
14
+ box: THREE.Box3;
15
+ /**
16
+ * Create text layout details (lines and logical char boxes) on demand.
17
+ * The result may be internally cached and reused by subsequent calls.
18
+ */
19
+ createLayoutData(): MTextLayout;
20
+ }
21
+ /**
22
+ * Defines the common rendering contract for producing Three.js objects from MText content.
23
+ *
24
+ * Implementations may render on the main thread or delegate work to a Web Worker,
25
+ * but they must expose the same high-level API so callers can switch strategies
26
+ * without changing usage.
27
+ */
28
+ export interface MTextBaseRenderer {
29
+ /**
30
+ * Used to manage materials used by texts
31
+ */
32
+ get styleManager(): StyleManager;
33
+ set styleManager(value: StyleManager);
34
+ /**
35
+ * Render the provided MText content into a Three.js object hierarchy asynchronously
36
+ *
37
+ * The returned root object contains meshes/lines for glyphs and exposes a
38
+ * bounding box on `object.box`.
39
+ *
40
+ * @param mtextContent Structured MText input (text, height, width, position).
41
+ * @param textStyle Text style to apply (font, width factor, oblique, etc.).
42
+ * @param colorSettings Optional color context (ByLayer, ByBlock colors).
43
+ * @returns A Promise resolving to a populated `MTextObject` ready to add to a scene.
44
+ */
45
+ asyncRenderMText(mtextContent: MTextData, textStyle: TextStyle, colorSettings?: ColorSettings): Promise<MTextObject>;
46
+ /**
47
+ * Render the provided MText content into a Three.js object hierarchy synchronously.
48
+ *
49
+ * The returned root object contains meshes/lines for glyphs and exposes a
50
+ * bounding box on `object.box`.
51
+ *
52
+ * @param mtextContent Structured MText input (text, height, width, position).
53
+ * @param textStyle Text style to apply (font, width factor, oblique, etc.).
54
+ * @param colorSettings Optional color context (ByLayer, ByBlock colors).
55
+ * @returns A Promise resolving to a populated `MTextObject` ready to add to a scene.
56
+ */
57
+ syncRenderMText(mtextContent: MTextData, textStyle: TextStyle, colorSettings?: ColorSettings): MTextObject;
58
+ /**
59
+ * Ensure the specified fonts are available to the renderer.
60
+ *
61
+ * Implementations should load and cache missing fonts; repeated calls should be cheap.
62
+ *
63
+ * @param fonts Font names to load (without extension for built-ins).
64
+ * @returns A Promise with the list of fonts that were processed.
65
+ */
66
+ loadFonts(fonts: string[]): Promise<{
67
+ loaded: string[];
68
+ }>;
69
+ /**
70
+ * Retrieve the list of fonts that can be used by the renderer.
71
+ *
72
+ * The shape of each font entry is implementation-defined but should include a displayable name.
73
+ *
74
+ * @returns A Promise with available font metadata.
75
+ */
76
+ getAvailableFonts(): Promise<{
77
+ fonts: Array<{
78
+ name: string[];
79
+ }>;
80
+ }>;
81
+ /**
82
+ * Set URL to load fonts
83
+ * @param value - URL to load fonts
84
+ */
85
+ setFontUrl(value: string): Promise<void>;
86
+ /**
87
+ * Release any resources owned by the renderer (e.g., terminate Web Workers).
88
+ *
89
+ * Safe to call multiple times.
90
+ */
91
+ destroy(): void;
92
+ }
@@ -0,0 +1,5 @@
1
+ export * from './webWorkerRenderer';
2
+ export * from './mainThreadRenderer';
3
+ export * from './unifiedRenderer';
4
+ export * from './unifiedRenderer';
5
+ export * from './baseRenderer';
@@ -0,0 +1,49 @@
1
+ import { StyleManager } from '../renderer/styleManager';
2
+ import { ColorSettings, MTextData, TextStyle } from '../renderer/types';
3
+ import { MTextBaseRenderer, MTextObject } from './baseRenderer';
4
+ /**
5
+ * Main thread renderer for MText objects
6
+ * This provides the same interface as the worker but runs in the main thread
7
+ */
8
+ export declare class MainThreadRenderer implements MTextBaseRenderer {
9
+ private fontManager;
10
+ private defaultStyleManager;
11
+ private isInitialized;
12
+ constructor();
13
+ /**
14
+ * Used to manage materials used by texts
15
+ */
16
+ get styleManager(): StyleManager;
17
+ set styleManager(value: StyleManager);
18
+ /**
19
+ * Set URL to load fonts
20
+ * @param value - URL to load fonts
21
+ */
22
+ setFontUrl(value: string): Promise<void>;
23
+ /**
24
+ * Render MText directly in the main thread asynchronously. It will ensure that default font
25
+ * is loaded. And fonts needed in mtext are loaded on demand.
26
+ */
27
+ asyncRenderMText(mtextContent: MTextData, textStyle: TextStyle, colorSettings?: ColorSettings): Promise<MTextObject>;
28
+ /**
29
+ * Render MText directly in the main thread synchronously. It is user's responsibility to ensure
30
+ * that default font is loaded and fonts needed in mtext are loaded.
31
+ */
32
+ syncRenderMText(mtextContent: MTextData, textStyle: TextStyle, colorSettings?: ColorSettings): MTextObject;
33
+ /**
34
+ * Load fonts in the main thread
35
+ */
36
+ loadFonts(fonts: string[]): Promise<{
37
+ loaded: string[];
38
+ }>;
39
+ /**
40
+ * Get available fonts from the main thread
41
+ */
42
+ getAvailableFonts(): Promise<{
43
+ fonts: Array<{
44
+ name: string[];
45
+ }>;
46
+ }>;
47
+ destroy(): void;
48
+ private ensureInitialized;
49
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,69 @@
1
+ import { StyleManager } from '../renderer';
2
+ import { ColorSettings, MTextData, TextStyle } from '../renderer/types';
3
+ import { MTextObject } from './baseRenderer';
4
+ import { WebWorkerRendererConfig } from './webWorkerRenderer';
5
+ export type RenderMode = 'main' | 'worker';
6
+ /**
7
+ * Unified renderer that can work in both main thread and web worker modes
8
+ */
9
+ export declare class UnifiedRenderer {
10
+ private webWorkerRenderer;
11
+ private mainThreadRenderer;
12
+ private renderer;
13
+ private defaultMode;
14
+ /**
15
+ * Constructor
16
+ *
17
+ * @param defaultMode - Default rendering mode. Default is 'main' which means rendering in main thread.
18
+ * @param workerConfig - Configuration options for WebWorkerRenderer which is used
19
+ * when render mode is 'worker'.
20
+ */
21
+ constructor(defaultMode?: RenderMode, workerConfig?: WebWorkerRendererConfig);
22
+ /**
23
+ * Sets one new style manager to override the default style manager
24
+ * @param value - New style manager
25
+ */
26
+ setStyleManager(value: StyleManager): void;
27
+ /**
28
+ * Sets the default rendering mmode
29
+ * @param mode The default rendering mode
30
+ */
31
+ setDefaultMode(mode: RenderMode): void;
32
+ /**
33
+ * Set URL to load fonts
34
+ * @param value - URL to load fonts
35
+ */
36
+ setFontUrl(value: string): Promise<void>;
37
+ /**
38
+ * Get the default rendering mode
39
+ */
40
+ getDefaultMode(): RenderMode;
41
+ /**
42
+ * Render MText using the current mode asynchronously.
43
+ * @param mode - Rendering mode used. If undefined, the default rendering mode is used.
44
+ */
45
+ asyncRenderMText(mtextContent: MTextData, textStyle: TextStyle, colorSettings?: ColorSettings, mode?: RenderMode): Promise<MTextObject>;
46
+ /**
47
+ * Render MText using the current mode synchronously. Main thread render is always used
48
+ * for this function because web worker renderer doesn't support rendering synchronously.
49
+ */
50
+ syncRenderMText(mtextContent: MTextData, textStyle: TextStyle, colorSettings?: ColorSettings): MTextObject;
51
+ /**
52
+ * Load fonts using the current mode
53
+ */
54
+ loadFonts(fonts: string[]): Promise<{
55
+ loaded: string[];
56
+ }>;
57
+ /**
58
+ * Get available fonts using the current mode
59
+ */
60
+ getAvailableFonts(): Promise<{
61
+ fonts: Array<{
62
+ name: string[];
63
+ }>;
64
+ }>;
65
+ /**
66
+ * Clean up resources
67
+ */
68
+ destroy(): void;
69
+ }