@mlightcad/mtext-renderer 0.9.4 → 0.10.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.
@@ -1,6 +1,6 @@
1
1
  import { FontManager } from '../font';
2
2
  import { StyleManager } from './styleManager';
3
- import { CharBox, ColorSettings, MTextData, TextStyle } from './types';
3
+ import { ColorSettings, MTextData, MTextLayout, TextStyle } from './types';
4
4
  import * as THREE from 'three';
5
5
  /**
6
6
  * Represents an AutoCAD MText object in Three.js.
@@ -20,8 +20,8 @@ export declare class MText extends THREE.Object3D {
20
20
  private _colorSettings;
21
21
  /** The bounding box of the entire MText object */
22
22
  private _box;
23
- /** Array of per-character bounding boxes with debug chars */
24
- private _charBoxes;
23
+ /** Lazily built layout data (line geometry + char boxes). */
24
+ private _layoutData;
25
25
  /** Raw mtext data to draw on demand */
26
26
  private _mtextData;
27
27
  /**
@@ -85,21 +85,8 @@ export declare class MText extends THREE.Object3D {
85
85
  */
86
86
  get box(): THREE.Box3;
87
87
  set box(box: THREE.Box3);
88
- /**
89
- * Gets logical text token boxes for picking/debug.
90
- *
91
- * Token semantics:
92
- * - `CHAR`: `char` is the rendered character, `box` is defined, `children` is empty.
93
- * - `NEW_PARAGRAPH`: `char` is `\n`. The `box` represents a zero-width vertical
94
- * line whose height equals the current line height. `children` is empty.
95
- * - `STACK`: `char` is empty string (`''`), `box` is the union of stack component boxes,
96
- * and `children` contains the stack sub-components.
97
- *
98
- * Notes:
99
- * - Superscript/subscript stacks (`^`) are emitted as regular `CHAR` entries.
100
- * - Fraction stacks (`/`, `#`) are emitted as one `STACK` entry.
101
- */
102
- get charBoxes(): CharBox[];
88
+ /** Creates text layout data for cursor/picking/debug usage on demand. */
89
+ createLayoutData(): MTextLayout;
103
90
  /**
104
91
  * Calculates intersections between a ray and this MText object.
105
92
  * Overrides the base THREE.Object3D raycast method to use the text's bounding boxes.
@@ -135,7 +122,8 @@ export declare class MText extends THREE.Object3D {
135
122
  * @param object - The Three.js object to process
136
123
  * @param boxes - Array to store the calculated bounding boxes
137
124
  */
138
- private getBoxes;
125
+ private getLayout;
126
+ private updateBoxFromObject;
139
127
  /**
140
128
  * Remove the specified object from its parent and release geometry and material resource used
141
129
  * by the object.
@@ -1,7 +1,7 @@
1
1
  import { ChangedProperties, MTextParagraphAlignment, MTextToken } from '@mlightcad/mtext-parser';
2
2
  import { FontManager } from '../font';
3
3
  import { StyleManager } from './styleManager';
4
- import { MTextFlowDirection, TextStyle } from './types';
4
+ import { LineLayout, MTextFlowDirection, TextStyle } from './types';
5
5
  import * as THREE from 'three';
6
6
  export interface MTextFormatOptions {
7
7
  /**
@@ -74,6 +74,9 @@ export declare class MTextProcessor {
74
74
  private _lastCharBoxTarget;
75
75
  private _lineHasRenderableChar;
76
76
  private _pendingEmptyLineFontSizeAdjust?;
77
+ private _lineLayouts;
78
+ private _lineBreakIndices;
79
+ private _processedCharCount;
77
80
  private _currentIndent;
78
81
  private _currentLeftMargin;
79
82
  private _currentRightMargin;
@@ -153,6 +156,7 @@ export declare class MTextProcessor {
153
156
  * All of THREE.js objects in current line. It contains objects in all of sections of this line.
154
157
  */
155
158
  get currentLineObjects(): THREE.Object3D<THREE.Object3DEventMap>[];
159
+ get lineLayouts(): LineLayout[];
156
160
  /**
157
161
  * The horizental offset of current character in this line
158
162
  */
@@ -199,7 +203,8 @@ export declare class MTextProcessor {
199
203
  */
200
204
  private convertTopAlignedVOffset;
201
205
  private processBlank;
202
- private recordLineBreak;
206
+ private recordVisualLineBreak;
207
+ private recordCurrentLineLayout;
203
208
  private processChar;
204
209
  private processLastLine;
205
210
  private initLineParams;
@@ -214,8 +219,8 @@ export declare class MTextProcessor {
214
219
  * @returns Return the text shape of the specified character
215
220
  */
216
221
  private getCharShape;
217
- private startNewLine;
218
222
  private advanceToNextLine;
223
+ private countFinalCharBoxes;
219
224
  private applyPendingEmptyLineYAdjust;
220
225
  private resolveCharBoxTarget;
221
226
  /**
@@ -62,8 +62,6 @@ export declare enum MTextAttachmentPoint {
62
62
  *
63
63
  * Semantics by {@link CharBoxType}:
64
64
  * - `CHAR`: `char` is the rendered character, `box` is defined, `children` is empty.
65
- * - `NEW_PARAGRAPH`: `char` is `\n`. The `box` represents a zero-width vertical
66
- * line whose height equals the current line height. `children` is empty.
67
65
  * - `STACK`: `char` is `''`, `box` is the union box of stack components, `children` contains stack parts.
68
66
  */
69
67
  export interface CharBox {
@@ -71,19 +69,45 @@ export interface CharBox {
71
69
  type: CharBoxType;
72
70
  /** Token bounding box in local MText coordinates. */
73
71
  box: THREE.Box3;
74
- /** Token character payload (`''` for `STACK`, `\n` for `NEW_PARAGRAPH`). */
72
+ /** Token character payload (`''` for `STACK`). */
75
73
  char: string;
76
74
  /** Nested token components (currently used by `STACK`). */
77
75
  children: CharBox[];
78
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
+ }
79
105
  /**
80
106
  * Type of logical token emitted in {@link CharBox} output.
81
107
  */
82
108
  export declare enum CharBoxType {
83
109
  /** Regular rendered character token. */
84
110
  CHAR = "CHAR",
85
- /** Explicit paragraph break token. */
86
- NEW_PARAGRAPH = "NEW_PARAGRAPH",
87
111
  /** Stack token (for fraction-style stacked expressions). */
88
112
  STACK = "STACK"
89
113
  }
@@ -1,5 +1,5 @@
1
1
  import { StyleManager } from '../renderer/styleManager';
2
- import { CharBox, ColorSettings, MTextData, TextStyle } from '../renderer/types';
2
+ import { ColorSettings, MTextData, MTextLayout, TextStyle } from '../renderer/types';
3
3
  import * as THREE from 'three';
4
4
  /**
5
5
  * Represents a rendered MText object that extends THREE.Object3D with additional MText-specific properties.
@@ -13,9 +13,10 @@ export interface MTextObject extends THREE.Object3D {
13
13
  */
14
14
  box: THREE.Box3;
15
15
  /**
16
- * The list of bounding boxes for each glyph in the MText object.
16
+ * Create text layout details (lines and logical char boxes) on demand.
17
+ * The result may be internally cached and reused by subsequent calls.
17
18
  */
18
- charBoxes: CharBox[];
19
+ createLayoutData(): MTextLayout;
19
20
  }
20
21
  /**
21
22
  * Defines the common rendering contract for producing Three.js objects from MText content.
@@ -1,5 +1,5 @@
1
1
  import { StyleManager } from '../renderer/styleManager';
2
- import { ColorSettings, MTextData, TextStyle } from '../renderer/types';
2
+ import { CharBox, ColorSettings, MTextData, TextStyle } from '../renderer/types';
3
3
  import { MTextBaseRenderer, MTextObject } from './baseRenderer';
4
4
  /**
5
5
  * Configuration options for WebWorkerRenderer
@@ -53,6 +53,23 @@ interface SerializedMText {
53
53
  };
54
54
  children: SerializedChild[];
55
55
  }
56
+ interface SerializedCharBox {
57
+ type: string;
58
+ char: string;
59
+ box: {
60
+ min: {
61
+ x: number;
62
+ y: number;
63
+ z: number;
64
+ };
65
+ max: {
66
+ x: number;
67
+ y: number;
68
+ z: number;
69
+ };
70
+ };
71
+ children: SerializedCharBox[];
72
+ }
56
73
  interface SerializedChild {
57
74
  type: 'mesh' | 'line';
58
75
  position: {
@@ -96,6 +113,13 @@ interface SerializedChild {
96
113
  side?: number;
97
114
  linewidth?: number;
98
115
  };
116
+ charBoxType?: CharBox['type'];
117
+ lineLayouts?: Array<{
118
+ y: number;
119
+ height: number;
120
+ breakIndex?: number;
121
+ }>;
122
+ charBoxes?: SerializedCharBox[];
99
123
  }
100
124
  /**
101
125
  * Manages communication with the MText web worker
@@ -155,6 +179,8 @@ export declare class WebWorkerRenderer implements MTextBaseRenderer {
155
179
  * Reconstruct MText object from JSON serialized data
156
180
  */
157
181
  reconstructMText(serializedData: SerializedMText, textStyle: TextStyle): MTextObject;
182
+ private deserializeCharBoxes;
183
+ private collectLayout;
158
184
  /**
159
185
  * Terminate the worker
160
186
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mlightcad/mtext-renderer",
3
- "version": "0.9.4",
3
+ "version": "0.10.1",
4
4
  "description": "AutoCAD MText renderer based on Three.js",
5
5
  "license": "MIT",
6
6
  "author": "MLight Lee <mlight.lee@outlook.com>",