@mlightcad/mtext-input-box 0.1.0
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/README.md +149 -0
- package/dist/controller/adapter.d.ts +13 -0
- package/dist/controller/adapter.js +119 -0
- package/dist/controller/index.d.ts +2 -0
- package/dist/controller/index.js +1 -0
- package/dist/controller/types.d.ts +46 -0
- package/dist/controller/types.js +1 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +4 -0
- package/dist/model/ast.d.ts +13 -0
- package/dist/model/ast.js +214 -0
- package/dist/model/document.d.ts +31 -0
- package/dist/model/document.js +146 -0
- package/dist/model/index.d.ts +4 -0
- package/dist/model/index.js +3 -0
- package/dist/model/style.d.ts +6 -0
- package/dist/model/style.js +186 -0
- package/dist/model/types.d.ts +57 -0
- package/dist/model/types.js +1 -0
- package/dist/ui/icons.d.ts +11 -0
- package/dist/ui/icons.js +10 -0
- package/dist/ui/index.d.ts +2 -0
- package/dist/ui/index.js +2 -0
- package/dist/ui/toolbar.d.ts +34 -0
- package/dist/ui/toolbar.js +369 -0
- package/dist/viewer/format.d.ts +5 -0
- package/dist/viewer/format.js +28 -0
- package/dist/viewer/index.d.ts +2 -0
- package/dist/viewer/index.js +1 -0
- package/dist/viewer/types.d.ts +172 -0
- package/dist/viewer/types.js +1 -0
- package/dist/viewer/viewer.d.ts +251 -0
- package/dist/viewer/viewer.js +2153 -0
- package/package.json +40 -0
|
@@ -0,0 +1,251 @@
|
|
|
1
|
+
import { type DebugVisibility } from '@mlightcad/text-box-cursor';
|
|
2
|
+
import { type TextStyle } from '@mlightcad/mtext-renderer';
|
|
3
|
+
import { defaultCharFormat, sameFormat } from './format';
|
|
4
|
+
import type { CharFormat, CursorLayoutData, CursorDirection, EditorState, MTextInputBoxEvent, MTextInputBoxOptions, MTextToolbarTheme, SelectionDirection } from './types';
|
|
5
|
+
type Handler = () => void;
|
|
6
|
+
/**
|
|
7
|
+
* Three.js based MText editor component with core text editing interaction.
|
|
8
|
+
*/
|
|
9
|
+
export declare class MTextInputBox {
|
|
10
|
+
private static activeEditor;
|
|
11
|
+
private static sharedToolbar;
|
|
12
|
+
private static sharedToolbarContainer;
|
|
13
|
+
private static sharedToolbarFontFamiliesKey;
|
|
14
|
+
private static readonly instances;
|
|
15
|
+
private readonly scene;
|
|
16
|
+
private readonly camera;
|
|
17
|
+
private readonly mtextRenderer;
|
|
18
|
+
private readonly cursorRenderer;
|
|
19
|
+
private static readonly FALLBACK_LINE_ADVANCE_RATIO;
|
|
20
|
+
private width;
|
|
21
|
+
private position;
|
|
22
|
+
private enableWordWrap;
|
|
23
|
+
private mtextString;
|
|
24
|
+
private cursorIndex;
|
|
25
|
+
private selectionStart;
|
|
26
|
+
private selectionEnd;
|
|
27
|
+
private readonly baseFormat;
|
|
28
|
+
private currentFormat;
|
|
29
|
+
private readonly defaultTextStyle;
|
|
30
|
+
private cursorLogic;
|
|
31
|
+
private layoutContainer;
|
|
32
|
+
private isDragging;
|
|
33
|
+
private pendingCursorLineHint;
|
|
34
|
+
private latestCursorLayoutData;
|
|
35
|
+
private renderedObject;
|
|
36
|
+
private boundingBoxObject;
|
|
37
|
+
private boundingBoxPadding;
|
|
38
|
+
private boundingBoxZOffset;
|
|
39
|
+
private rendererReady;
|
|
40
|
+
private toolbarTheme;
|
|
41
|
+
private toolbarOffsetY;
|
|
42
|
+
private debugMode;
|
|
43
|
+
private debugVisibility;
|
|
44
|
+
private readonly maxHistorySize;
|
|
45
|
+
private undoStack;
|
|
46
|
+
private redoStack;
|
|
47
|
+
private document;
|
|
48
|
+
private uiAdapter;
|
|
49
|
+
private imeInput;
|
|
50
|
+
private imeTarget;
|
|
51
|
+
private lastImeTarget;
|
|
52
|
+
private reopenTarget;
|
|
53
|
+
private pointerTarget;
|
|
54
|
+
private imeComposing;
|
|
55
|
+
private imeFocusTimer;
|
|
56
|
+
private closed;
|
|
57
|
+
private toolbarEnabled;
|
|
58
|
+
private toolbarContainer;
|
|
59
|
+
private toolbarFontFamilies;
|
|
60
|
+
private readonly onImeKeyDown;
|
|
61
|
+
private readonly onWindowKeyDown;
|
|
62
|
+
private readonly onImeBeforeInput;
|
|
63
|
+
private readonly onImeCompositionStart;
|
|
64
|
+
private readonly onImeCompositionEnd;
|
|
65
|
+
private readonly onImeTargetMouseDown;
|
|
66
|
+
private readonly onPointerMouseDown;
|
|
67
|
+
private readonly onPointerMouseMove;
|
|
68
|
+
private readonly onPointerMouseUp;
|
|
69
|
+
private readonly onPointerDoubleClick;
|
|
70
|
+
private readonly onReopenDoubleClick;
|
|
71
|
+
private readonly handlers;
|
|
72
|
+
constructor(options: MTextInputBoxOptions);
|
|
73
|
+
/** Sets full text and rebuilds model/layout state. */
|
|
74
|
+
setText(text: string): void;
|
|
75
|
+
/** Returns current MTEXT source string. */
|
|
76
|
+
getText(): string;
|
|
77
|
+
/** Returns plain text resolved from document AST. */
|
|
78
|
+
getPlainText(): string;
|
|
79
|
+
/** Inserts text at cursor; replaces selection when present. */
|
|
80
|
+
insertText(text: string): void;
|
|
81
|
+
/** Backspace behavior: remove selection or previous character. */
|
|
82
|
+
deleteBackward(): void;
|
|
83
|
+
/** Delete behavior: remove selection or next character. */
|
|
84
|
+
deleteForward(): void;
|
|
85
|
+
/** Restores previous text-editing state. Returns true when successful. */
|
|
86
|
+
undo(): boolean;
|
|
87
|
+
/** Restores next text-editing state from redo history. Returns true when successful. */
|
|
88
|
+
redo(): boolean;
|
|
89
|
+
/** Moves cursor and clears selection. */
|
|
90
|
+
moveCursor(direction: CursorDirection): void;
|
|
91
|
+
/** Extends selection toward direction. */
|
|
92
|
+
extendSelection(direction: SelectionDirection): void;
|
|
93
|
+
/** Selects all text. */
|
|
94
|
+
selectAll(): void;
|
|
95
|
+
/** Clears current selection. */
|
|
96
|
+
clearSelection(): void;
|
|
97
|
+
/** Enables/disables debug overlay rendering. */
|
|
98
|
+
setDebugMode(enabled: boolean): void;
|
|
99
|
+
/** Returns current debug mode flag. */
|
|
100
|
+
isDebugMode(): boolean;
|
|
101
|
+
/** Partially overrides visibility of debug sub-layers. */
|
|
102
|
+
setDebugVisibility(visibility: Partial<DebugVisibility>): void;
|
|
103
|
+
/** Returns current debug sub-layer visibility flags. */
|
|
104
|
+
getDebugVisibility(): DebugVisibility;
|
|
105
|
+
/** Sets built-in toolbar theme. */
|
|
106
|
+
setToolbarTheme(theme: MTextToolbarTheme): void;
|
|
107
|
+
/** Returns built-in toolbar theme. */
|
|
108
|
+
getToolbarTheme(): MTextToolbarTheme;
|
|
109
|
+
/** Attaches IME/input bridge to a target element (typically the render canvas). */
|
|
110
|
+
attachIme(target: HTMLElement): void;
|
|
111
|
+
/** Detaches and destroys IME/input bridge. */
|
|
112
|
+
detachIme(): void;
|
|
113
|
+
/** Returns cursor index. */
|
|
114
|
+
getCursorIndex(): number;
|
|
115
|
+
/** Returns normalized selection range. */
|
|
116
|
+
getSelectionRange(): {
|
|
117
|
+
start: number;
|
|
118
|
+
end: number;
|
|
119
|
+
isCollapsed: boolean;
|
|
120
|
+
};
|
|
121
|
+
/** Returns the latest geometry payload forwarded to `TextBoxCursor.updateData`. */
|
|
122
|
+
getCursorLayoutData(): CursorLayoutData;
|
|
123
|
+
/** Sets current insertion format. */
|
|
124
|
+
setCurrentFormat(format: Partial<CharFormat>): void;
|
|
125
|
+
/** Returns current insertion format. */
|
|
126
|
+
getCurrentFormat(): CharFormat;
|
|
127
|
+
/** Returns renderer default text style derived from `defaultFormat`. */
|
|
128
|
+
getDefaultTextStyle(): TextStyle;
|
|
129
|
+
/** Keyboard event handler. Returns true when consumed. */
|
|
130
|
+
handleKeyDown(event: KeyboardEvent): boolean;
|
|
131
|
+
/** Inserts committed text from IME/beforeinput events. Returns true when consumed. */
|
|
132
|
+
handleTextInput(text: string): boolean;
|
|
133
|
+
/** Handles pointer down in editor local coordinates. */
|
|
134
|
+
handleMouseDown(x: number, y: number, shiftKey: boolean): void;
|
|
135
|
+
/** Handles pointer move during drag selection. */
|
|
136
|
+
handleMouseMove(x: number, y: number): void;
|
|
137
|
+
/** Handles pointer release. */
|
|
138
|
+
handleMouseUp(): void;
|
|
139
|
+
/** Handles double click to select current word. */
|
|
140
|
+
handleDoubleClick(x: number, y: number): void;
|
|
141
|
+
/** Per-frame update. Call in animation loop. */
|
|
142
|
+
update(): void;
|
|
143
|
+
/** Releases all allocated resources. */
|
|
144
|
+
dispose(): void;
|
|
145
|
+
/** Closes editing interactions and destroys toolbar while keeping rendered text object. */
|
|
146
|
+
closeEditor(): void;
|
|
147
|
+
/** Re-opens a closed editor and restores IME/pointer interactions and toolbar. */
|
|
148
|
+
showEditor(): boolean;
|
|
149
|
+
/** Binds built-in mouse interactions using the editor target element. */
|
|
150
|
+
attachPointerInteractions(target: HTMLElement): void;
|
|
151
|
+
/** Unbinds built-in mouse interactions. */
|
|
152
|
+
detachPointerInteractions(): void;
|
|
153
|
+
/** Registers event handler. */
|
|
154
|
+
on(event: MTextInputBoxEvent, handler: Handler): void;
|
|
155
|
+
/** Removes event handler. */
|
|
156
|
+
off(event: string, handler: Handler): void;
|
|
157
|
+
/** Returns cursor world position for IME/caret anchoring. */
|
|
158
|
+
getCursorWorldPosition(): {
|
|
159
|
+
x: number;
|
|
160
|
+
y: number;
|
|
161
|
+
z: number;
|
|
162
|
+
};
|
|
163
|
+
/** Returns current internal state snapshot. */
|
|
164
|
+
getState(): EditorState;
|
|
165
|
+
private isActiveEditor;
|
|
166
|
+
private activateEditor;
|
|
167
|
+
private deactivateEditor;
|
|
168
|
+
private attachImeBridge;
|
|
169
|
+
private getActiveToolbar;
|
|
170
|
+
private createToolbarSessionOptions;
|
|
171
|
+
private ensureSharedToolbar;
|
|
172
|
+
private mountToolbar;
|
|
173
|
+
private updateToolbarPosition;
|
|
174
|
+
private getEditorScreenBounds;
|
|
175
|
+
private pointerEventToEditorLocal;
|
|
176
|
+
private pointerEventToEditorLocalByTarget;
|
|
177
|
+
private shouldReopenFromDoubleClick;
|
|
178
|
+
private hitTestRenderedObject;
|
|
179
|
+
private bindReopenDoubleClick;
|
|
180
|
+
private unbindReopenDoubleClick;
|
|
181
|
+
private isPointInContainer;
|
|
182
|
+
private initializeRenderer;
|
|
183
|
+
private relayout;
|
|
184
|
+
private updateCursorData;
|
|
185
|
+
private extractBoxesFromRenderedObject;
|
|
186
|
+
private normalizeRenderedTopAlignment;
|
|
187
|
+
private toLocalBox;
|
|
188
|
+
private createFallbackCharBoxes;
|
|
189
|
+
private createBoundingBox;
|
|
190
|
+
private updateBoundingBoxGeometry;
|
|
191
|
+
private disposeBoundingBox;
|
|
192
|
+
private replaceRenderedObject;
|
|
193
|
+
private forceVisibleMaterialState;
|
|
194
|
+
private disposeRenderedObject;
|
|
195
|
+
private isExplicitAci;
|
|
196
|
+
private normalizeColorNumber;
|
|
197
|
+
private resolveAciColor;
|
|
198
|
+
private resolveBaseColor;
|
|
199
|
+
private resolveFormatColorNumber;
|
|
200
|
+
private createDefaultTextStyle;
|
|
201
|
+
private createMTextData;
|
|
202
|
+
private getFallbackLineAdvance;
|
|
203
|
+
private createTextStyle;
|
|
204
|
+
private focusImeInput;
|
|
205
|
+
private refocusImeInputSoon;
|
|
206
|
+
private updateImeAnchorPosition;
|
|
207
|
+
private syncStateFromCursor;
|
|
208
|
+
private consumeMove;
|
|
209
|
+
private consumeExtend;
|
|
210
|
+
private isMacPlatform;
|
|
211
|
+
private emit;
|
|
212
|
+
private findPrevWordStart;
|
|
213
|
+
private findNextWordStart;
|
|
214
|
+
private getChars;
|
|
215
|
+
private charCount;
|
|
216
|
+
private getActiveCursorRenderState;
|
|
217
|
+
private getNodeLogicalSpan;
|
|
218
|
+
private toLogicalIndexFromDocumentIndex;
|
|
219
|
+
private toDocumentIndexFromLogicalIndex;
|
|
220
|
+
private resolveCandidateByVisualLineHint;
|
|
221
|
+
private syncUiStateFromDocument;
|
|
222
|
+
private syncDocumentFromUiState;
|
|
223
|
+
private refreshCurrentFormatFromDocument;
|
|
224
|
+
private toggleStackSelection;
|
|
225
|
+
private toggleScriptSelection;
|
|
226
|
+
private commitHistoryEdit;
|
|
227
|
+
private createHistorySnapshot;
|
|
228
|
+
private restoreHistorySnapshot;
|
|
229
|
+
private isSameAsCurrent;
|
|
230
|
+
private buildMTextFromAst;
|
|
231
|
+
private clearHistory;
|
|
232
|
+
private cloneAst;
|
|
233
|
+
private stackNodeToPlainText;
|
|
234
|
+
private scriptStackToPlainText;
|
|
235
|
+
private parseStackParts;
|
|
236
|
+
private updateToolbarStackState;
|
|
237
|
+
private isScriptOnlyStack;
|
|
238
|
+
private inferCurrentFormatFromDocument;
|
|
239
|
+
private getNodeByLogicalCharIndex;
|
|
240
|
+
private getNodesByLogicalRange;
|
|
241
|
+
private toCharFormat;
|
|
242
|
+
private toScriptFromStyle;
|
|
243
|
+
private createDefaultParseContext;
|
|
244
|
+
private createNormalizedDocument;
|
|
245
|
+
private mergeCharFormat;
|
|
246
|
+
private cloneDocumentStyle;
|
|
247
|
+
private toDocumentStyle;
|
|
248
|
+
private colorNumberToRgbArray;
|
|
249
|
+
private rgbArrayToColorNumber;
|
|
250
|
+
}
|
|
251
|
+
export { MTextInputBox as MTextEditor, defaultCharFormat, sameFormat };
|