@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,369 @@
|
|
|
1
|
+
import { toolbarIcons } from './icons';
|
|
2
|
+
const STYLE_ID = 'mlightcad-mtext-toolbar-style';
|
|
3
|
+
const DEFAULT_FONT_FAMILIES = [
|
|
4
|
+
'Arial',
|
|
5
|
+
'Helvetica',
|
|
6
|
+
'Verdana',
|
|
7
|
+
'Tahoma',
|
|
8
|
+
'Trebuchet MS',
|
|
9
|
+
'Times New Roman',
|
|
10
|
+
'Georgia',
|
|
11
|
+
'Courier New',
|
|
12
|
+
'system-ui',
|
|
13
|
+
'sans-serif',
|
|
14
|
+
'serif',
|
|
15
|
+
'monospace'
|
|
16
|
+
];
|
|
17
|
+
function ensureToolbarStyles() {
|
|
18
|
+
if (document.getElementById(STYLE_ID))
|
|
19
|
+
return;
|
|
20
|
+
const style = document.createElement('style');
|
|
21
|
+
style.id = STYLE_ID;
|
|
22
|
+
style.textContent = `
|
|
23
|
+
.mlc-mtext-toolbar {
|
|
24
|
+
position: fixed;
|
|
25
|
+
left: 0;
|
|
26
|
+
top: 0;
|
|
27
|
+
z-index: 2147483000;
|
|
28
|
+
display: inline-flex;
|
|
29
|
+
align-items: center;
|
|
30
|
+
gap: 10px;
|
|
31
|
+
border-radius: 8px;
|
|
32
|
+
border: 1px solid;
|
|
33
|
+
padding: 8px;
|
|
34
|
+
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Helvetica, Arial, sans-serif;
|
|
35
|
+
font-size: 12px;
|
|
36
|
+
line-height: 1;
|
|
37
|
+
box-shadow: 0 8px 24px rgba(0, 0, 0, 0.24);
|
|
38
|
+
user-select: none;
|
|
39
|
+
}
|
|
40
|
+
.mlc-mtext-toolbar[data-theme='dark'] {
|
|
41
|
+
background: linear-gradient(180deg, #2a2d33 0%, #1d2025 100%);
|
|
42
|
+
border-color: #444b58;
|
|
43
|
+
color: #e8ecf4;
|
|
44
|
+
}
|
|
45
|
+
.mlc-mtext-toolbar[data-theme='light'] {
|
|
46
|
+
background: linear-gradient(180deg, #ffffff 0%, #f2f4f8 100%);
|
|
47
|
+
border-color: #cfd5df;
|
|
48
|
+
color: #1e2430;
|
|
49
|
+
}
|
|
50
|
+
.mlc-mtext-toolbar__group {
|
|
51
|
+
display: inline-flex;
|
|
52
|
+
align-items: center;
|
|
53
|
+
gap: 4px;
|
|
54
|
+
}
|
|
55
|
+
.mlc-mtext-toolbar__separator {
|
|
56
|
+
width: 1px;
|
|
57
|
+
height: 24px;
|
|
58
|
+
opacity: 0.35;
|
|
59
|
+
}
|
|
60
|
+
.mlc-mtext-toolbar[data-theme='dark'] .mlc-mtext-toolbar__separator {
|
|
61
|
+
background: #576177;
|
|
62
|
+
}
|
|
63
|
+
.mlc-mtext-toolbar[data-theme='light'] .mlc-mtext-toolbar__separator {
|
|
64
|
+
background: #b8c0ce;
|
|
65
|
+
}
|
|
66
|
+
.mlc-mtext-toolbar__select,
|
|
67
|
+
.mlc-mtext-toolbar__input,
|
|
68
|
+
.mlc-mtext-toolbar__color,
|
|
69
|
+
.mlc-mtext-toolbar__btn {
|
|
70
|
+
border: 1px solid;
|
|
71
|
+
border-radius: 6px;
|
|
72
|
+
height: 34px;
|
|
73
|
+
}
|
|
74
|
+
.mlc-mtext-toolbar[data-theme='dark'] .mlc-mtext-toolbar__select,
|
|
75
|
+
.mlc-mtext-toolbar[data-theme='dark'] .mlc-mtext-toolbar__input,
|
|
76
|
+
.mlc-mtext-toolbar[data-theme='dark'] .mlc-mtext-toolbar__color,
|
|
77
|
+
.mlc-mtext-toolbar[data-theme='dark'] .mlc-mtext-toolbar__btn {
|
|
78
|
+
background: #12161d;
|
|
79
|
+
border-color: #454d5f;
|
|
80
|
+
color: #f2f5fb;
|
|
81
|
+
}
|
|
82
|
+
.mlc-mtext-toolbar[data-theme='light'] .mlc-mtext-toolbar__select,
|
|
83
|
+
.mlc-mtext-toolbar[data-theme='light'] .mlc-mtext-toolbar__input,
|
|
84
|
+
.mlc-mtext-toolbar[data-theme='light'] .mlc-mtext-toolbar__color,
|
|
85
|
+
.mlc-mtext-toolbar[data-theme='light'] .mlc-mtext-toolbar__btn {
|
|
86
|
+
background: #ffffff;
|
|
87
|
+
border-color: #c7cdd8;
|
|
88
|
+
color: #1f2632;
|
|
89
|
+
}
|
|
90
|
+
.mlc-mtext-toolbar__select {
|
|
91
|
+
min-width: 140px;
|
|
92
|
+
padding: 0 8px;
|
|
93
|
+
}
|
|
94
|
+
.mlc-mtext-toolbar__input {
|
|
95
|
+
width: 64px;
|
|
96
|
+
padding: 0 8px;
|
|
97
|
+
}
|
|
98
|
+
.mlc-mtext-toolbar__color {
|
|
99
|
+
width: 40px;
|
|
100
|
+
padding: 2px;
|
|
101
|
+
}
|
|
102
|
+
.mlc-mtext-toolbar__btn {
|
|
103
|
+
width: 34px;
|
|
104
|
+
display: inline-flex;
|
|
105
|
+
align-items: center;
|
|
106
|
+
justify-content: center;
|
|
107
|
+
cursor: pointer;
|
|
108
|
+
transition: border-color 0.14s ease, background 0.14s ease, color 0.14s ease;
|
|
109
|
+
}
|
|
110
|
+
.mlc-mtext-toolbar__btn svg {
|
|
111
|
+
width: 24px;
|
|
112
|
+
height: 24px;
|
|
113
|
+
fill: currentColor;
|
|
114
|
+
}
|
|
115
|
+
.mlc-mtext-toolbar__btn.is-active {
|
|
116
|
+
border-color: #2f9dff;
|
|
117
|
+
color: #2f9dff;
|
|
118
|
+
}
|
|
119
|
+
.mlc-mtext-toolbar[data-theme='dark'] .mlc-mtext-toolbar__btn.is-active {
|
|
120
|
+
background: linear-gradient(180deg, #123252 0%, #0c243d 100%);
|
|
121
|
+
color: #8fcbff;
|
|
122
|
+
box-shadow: inset 0 0 0 1px rgba(143, 203, 255, 0.18);
|
|
123
|
+
}
|
|
124
|
+
.mlc-mtext-toolbar[data-theme='light'] .mlc-mtext-toolbar__btn.is-active {
|
|
125
|
+
background: linear-gradient(180deg, #dcebff 0%, #cfe3ff 100%);
|
|
126
|
+
color: #1d67ad;
|
|
127
|
+
box-shadow: inset 0 0 0 1px rgba(29, 103, 173, 0.16);
|
|
128
|
+
}
|
|
129
|
+
.mlc-mtext-toolbar[data-theme='dark'] .mlc-mtext-toolbar__btn:hover {
|
|
130
|
+
background: #1f2530;
|
|
131
|
+
}
|
|
132
|
+
.mlc-mtext-toolbar[data-theme='light'] .mlc-mtext-toolbar__btn:hover {
|
|
133
|
+
background: #edf3ff;
|
|
134
|
+
}
|
|
135
|
+
`;
|
|
136
|
+
document.head.appendChild(style);
|
|
137
|
+
}
|
|
138
|
+
function normalizeColorNumber(color) {
|
|
139
|
+
return Math.max(0, Math.min(0xffffff, Math.round(color)));
|
|
140
|
+
}
|
|
141
|
+
function colorNumberToHex(color) {
|
|
142
|
+
const resolved = color === null ? 0xffffff : normalizeColorNumber(color);
|
|
143
|
+
return `#${resolved.toString(16).padStart(6, '0')}`;
|
|
144
|
+
}
|
|
145
|
+
function hexToColorNumber(hex) {
|
|
146
|
+
if (!/^#[0-9a-fA-F]{6}$/.test(hex))
|
|
147
|
+
return 0xffffff;
|
|
148
|
+
return Number.parseInt(hex.slice(1), 16);
|
|
149
|
+
}
|
|
150
|
+
function createIconButton(title, icon) {
|
|
151
|
+
const btn = document.createElement('button');
|
|
152
|
+
btn.type = 'button';
|
|
153
|
+
btn.className = 'mlc-mtext-toolbar__btn';
|
|
154
|
+
btn.title = title;
|
|
155
|
+
btn.setAttribute('aria-label', title);
|
|
156
|
+
btn.setAttribute('aria-pressed', 'false');
|
|
157
|
+
btn.innerHTML = toolbarIcons[icon];
|
|
158
|
+
return btn;
|
|
159
|
+
}
|
|
160
|
+
function resolveFontFamilies(fontFamilies) {
|
|
161
|
+
const source = fontFamilies && fontFamilies.length > 0 ? fontFamilies : DEFAULT_FONT_FAMILIES;
|
|
162
|
+
const unique = [];
|
|
163
|
+
const seen = new Set();
|
|
164
|
+
for (const raw of source) {
|
|
165
|
+
const name = raw.trim();
|
|
166
|
+
if (!name || seen.has(name))
|
|
167
|
+
continue;
|
|
168
|
+
seen.add(name);
|
|
169
|
+
unique.push(name);
|
|
170
|
+
}
|
|
171
|
+
return unique.length > 0 ? unique : [...DEFAULT_FONT_FAMILIES];
|
|
172
|
+
}
|
|
173
|
+
export class MTextToolbar {
|
|
174
|
+
anchorElement;
|
|
175
|
+
root;
|
|
176
|
+
controls;
|
|
177
|
+
onFormatChange;
|
|
178
|
+
onToggleStack;
|
|
179
|
+
onToggleSuperscript;
|
|
180
|
+
onToggleSubscript;
|
|
181
|
+
theme;
|
|
182
|
+
constructor(options) {
|
|
183
|
+
ensureToolbarStyles();
|
|
184
|
+
this.anchorElement = options.anchorElement;
|
|
185
|
+
this.onFormatChange = options.onFormatChange;
|
|
186
|
+
this.onToggleStack = options.onToggleStack ?? (() => { });
|
|
187
|
+
this.onToggleSuperscript = options.onToggleSuperscript ?? (() => false);
|
|
188
|
+
this.onToggleSubscript = options.onToggleSubscript ?? (() => false);
|
|
189
|
+
this.theme = options.theme;
|
|
190
|
+
this.root = document.createElement('div');
|
|
191
|
+
this.root.className = 'mlc-mtext-toolbar';
|
|
192
|
+
const typographyGroup = document.createElement('div');
|
|
193
|
+
typographyGroup.className = 'mlc-mtext-toolbar__group';
|
|
194
|
+
const fontFamily = document.createElement('select');
|
|
195
|
+
fontFamily.className = 'mlc-mtext-toolbar__select';
|
|
196
|
+
for (const family of resolveFontFamilies(options.fontFamilies)) {
|
|
197
|
+
const option = document.createElement('option');
|
|
198
|
+
option.value = family;
|
|
199
|
+
option.textContent = family;
|
|
200
|
+
fontFamily.appendChild(option);
|
|
201
|
+
}
|
|
202
|
+
const fontSize = document.createElement('input');
|
|
203
|
+
fontSize.className = 'mlc-mtext-toolbar__input';
|
|
204
|
+
fontSize.type = 'number';
|
|
205
|
+
fontSize.min = '1';
|
|
206
|
+
fontSize.max = '1024';
|
|
207
|
+
fontSize.step = '1';
|
|
208
|
+
const fontColor = document.createElement('input');
|
|
209
|
+
fontColor.className = 'mlc-mtext-toolbar__color';
|
|
210
|
+
fontColor.type = 'color';
|
|
211
|
+
typographyGroup.append(fontFamily, fontSize, fontColor);
|
|
212
|
+
const separator1 = document.createElement('div');
|
|
213
|
+
separator1.className = 'mlc-mtext-toolbar__separator';
|
|
214
|
+
const styleGroup = document.createElement('div');
|
|
215
|
+
styleGroup.className = 'mlc-mtext-toolbar__group';
|
|
216
|
+
const boldBtn = createIconButton('Bold', 'bold');
|
|
217
|
+
const italicBtn = createIconButton('Italic', 'italic');
|
|
218
|
+
const underlineBtn = createIconButton('Underline', 'underline');
|
|
219
|
+
const overlineBtn = createIconButton('Overline', 'overline');
|
|
220
|
+
const strikeBtn = createIconButton('Strike Through', 'strike');
|
|
221
|
+
const superscriptBtn = createIconButton('Superscript', 'superscript');
|
|
222
|
+
const subscriptBtn = createIconButton('Subscript', 'subscript');
|
|
223
|
+
const stackBtn = createIconButton('Stack', 'stack');
|
|
224
|
+
styleGroup.append(boldBtn, italicBtn, underlineBtn, overlineBtn, strikeBtn, superscriptBtn, subscriptBtn, stackBtn);
|
|
225
|
+
this.root.append(typographyGroup, separator1, styleGroup);
|
|
226
|
+
this.controls = {
|
|
227
|
+
fontFamily,
|
|
228
|
+
fontSize,
|
|
229
|
+
fontColor,
|
|
230
|
+
boldBtn,
|
|
231
|
+
italicBtn,
|
|
232
|
+
underlineBtn,
|
|
233
|
+
overlineBtn,
|
|
234
|
+
strikeBtn,
|
|
235
|
+
superscriptBtn,
|
|
236
|
+
subscriptBtn,
|
|
237
|
+
stackBtn
|
|
238
|
+
};
|
|
239
|
+
this.setTheme(this.theme);
|
|
240
|
+
this.bindEvents();
|
|
241
|
+
(options.container ?? document.body).appendChild(this.root);
|
|
242
|
+
}
|
|
243
|
+
setTheme(theme) {
|
|
244
|
+
this.theme = theme;
|
|
245
|
+
this.root.dataset.theme = theme;
|
|
246
|
+
}
|
|
247
|
+
getTheme() {
|
|
248
|
+
return this.theme;
|
|
249
|
+
}
|
|
250
|
+
setVisible(visible) {
|
|
251
|
+
this.root.style.display = visible ? 'inline-flex' : 'none';
|
|
252
|
+
}
|
|
253
|
+
setSession(options) {
|
|
254
|
+
this.anchorElement = options.anchorElement;
|
|
255
|
+
this.onFormatChange = options.onFormatChange;
|
|
256
|
+
this.onToggleStack = options.onToggleStack;
|
|
257
|
+
this.onToggleSuperscript = options.onToggleSuperscript ?? (() => false);
|
|
258
|
+
this.onToggleSubscript = options.onToggleSubscript ?? (() => false);
|
|
259
|
+
}
|
|
260
|
+
setAnchor(clientX, clientY) {
|
|
261
|
+
const width = this.root.offsetWidth || 0;
|
|
262
|
+
const height = this.root.offsetHeight || 0;
|
|
263
|
+
const minX = 8;
|
|
264
|
+
const minY = 8;
|
|
265
|
+
const maxX = Math.max(minX, window.innerWidth - width - 8);
|
|
266
|
+
const maxY = Math.max(minY, window.innerHeight - height - 8);
|
|
267
|
+
const x = Math.max(minX, Math.min(maxX, Math.round(clientX)));
|
|
268
|
+
const y = Math.max(minY, Math.min(maxY, Math.round(clientY - height)));
|
|
269
|
+
this.root.style.left = `${x}px`;
|
|
270
|
+
this.root.style.top = `${y}px`;
|
|
271
|
+
}
|
|
272
|
+
setFormat(format) {
|
|
273
|
+
this.ensureSelectValue(format.fontFamily);
|
|
274
|
+
this.controls.fontSize.value = String(Math.max(1, Math.round(format.fontSize)));
|
|
275
|
+
const color = format.rgb !== null ? format.rgb : 0xffffff;
|
|
276
|
+
this.controls.fontColor.value = colorNumberToHex(color);
|
|
277
|
+
this.setToggleState(this.controls.boldBtn, format.bold);
|
|
278
|
+
this.setToggleState(this.controls.italicBtn, format.italic);
|
|
279
|
+
this.setToggleState(this.controls.underlineBtn, format.underline);
|
|
280
|
+
this.setToggleState(this.controls.overlineBtn, format.overline);
|
|
281
|
+
this.setToggleState(this.controls.strikeBtn, format.strike);
|
|
282
|
+
this.setToggleState(this.controls.superscriptBtn, format.script === 'superscript');
|
|
283
|
+
this.setToggleState(this.controls.subscriptBtn, format.script === 'subscript');
|
|
284
|
+
}
|
|
285
|
+
dispose() {
|
|
286
|
+
this.root.remove();
|
|
287
|
+
}
|
|
288
|
+
setStackActive(active) {
|
|
289
|
+
this.setToggleState(this.controls.stackBtn, active);
|
|
290
|
+
}
|
|
291
|
+
setToggleState(button, active) {
|
|
292
|
+
button.classList.toggle('is-active', active);
|
|
293
|
+
button.setAttribute('aria-pressed', active ? 'true' : 'false');
|
|
294
|
+
}
|
|
295
|
+
ensureSelectValue(fontFamily) {
|
|
296
|
+
const existing = Array.from(this.controls.fontFamily.options).some((item) => item.value === fontFamily);
|
|
297
|
+
if (!existing) {
|
|
298
|
+
const option = document.createElement('option');
|
|
299
|
+
option.value = fontFamily;
|
|
300
|
+
option.textContent = fontFamily;
|
|
301
|
+
this.controls.fontFamily.appendChild(option);
|
|
302
|
+
}
|
|
303
|
+
this.controls.fontFamily.value = fontFamily;
|
|
304
|
+
}
|
|
305
|
+
bindEvents() {
|
|
306
|
+
const applyFontSize = () => {
|
|
307
|
+
const value = Math.max(1, Number(this.controls.fontSize.value) || 1);
|
|
308
|
+
this.controls.fontSize.value = String(Math.round(value));
|
|
309
|
+
this.onFormatChange({ fontSize: value });
|
|
310
|
+
};
|
|
311
|
+
this.controls.fontFamily.addEventListener('change', () => {
|
|
312
|
+
this.onFormatChange({ fontFamily: this.controls.fontFamily.value });
|
|
313
|
+
});
|
|
314
|
+
this.controls.fontSize.addEventListener('input', applyFontSize);
|
|
315
|
+
this.controls.fontSize.addEventListener('change', applyFontSize);
|
|
316
|
+
this.controls.fontSize.addEventListener('blur', applyFontSize);
|
|
317
|
+
this.controls.fontSize.addEventListener('keydown', (event) => {
|
|
318
|
+
if (event.key === 'Enter') {
|
|
319
|
+
applyFontSize();
|
|
320
|
+
this.anchorElement.focus({ preventScroll: true });
|
|
321
|
+
}
|
|
322
|
+
});
|
|
323
|
+
this.controls.fontColor.addEventListener('input', () => {
|
|
324
|
+
this.onFormatChange({
|
|
325
|
+
aci: null,
|
|
326
|
+
rgb: hexToColorNumber(this.controls.fontColor.value)
|
|
327
|
+
});
|
|
328
|
+
});
|
|
329
|
+
this.controls.boldBtn.addEventListener('click', () => {
|
|
330
|
+
this.onFormatChange({ bold: !this.controls.boldBtn.classList.contains('is-active') });
|
|
331
|
+
});
|
|
332
|
+
this.controls.italicBtn.addEventListener('click', () => {
|
|
333
|
+
this.onFormatChange({ italic: !this.controls.italicBtn.classList.contains('is-active') });
|
|
334
|
+
});
|
|
335
|
+
this.controls.underlineBtn.addEventListener('click', () => {
|
|
336
|
+
this.onFormatChange({ underline: !this.controls.underlineBtn.classList.contains('is-active') });
|
|
337
|
+
});
|
|
338
|
+
this.controls.overlineBtn.addEventListener('click', () => {
|
|
339
|
+
this.onFormatChange({ overline: !this.controls.overlineBtn.classList.contains('is-active') });
|
|
340
|
+
});
|
|
341
|
+
this.controls.strikeBtn.addEventListener('click', () => {
|
|
342
|
+
this.onFormatChange({ strike: !this.controls.strikeBtn.classList.contains('is-active') });
|
|
343
|
+
});
|
|
344
|
+
this.controls.superscriptBtn.addEventListener('click', () => {
|
|
345
|
+
if (this.onToggleSuperscript())
|
|
346
|
+
return;
|
|
347
|
+
const active = this.controls.superscriptBtn.classList.contains('is-active');
|
|
348
|
+
this.onFormatChange({ script: active ? 'normal' : 'superscript' });
|
|
349
|
+
});
|
|
350
|
+
this.controls.subscriptBtn.addEventListener('click', () => {
|
|
351
|
+
if (this.onToggleSubscript())
|
|
352
|
+
return;
|
|
353
|
+
const active = this.controls.subscriptBtn.classList.contains('is-active');
|
|
354
|
+
this.onFormatChange({ script: active ? 'normal' : 'subscript' });
|
|
355
|
+
});
|
|
356
|
+
this.controls.stackBtn.addEventListener('click', () => {
|
|
357
|
+
this.onToggleStack();
|
|
358
|
+
});
|
|
359
|
+
this.root.addEventListener('mousedown', (event) => {
|
|
360
|
+
const target = event.target;
|
|
361
|
+
if (!target)
|
|
362
|
+
return;
|
|
363
|
+
if (target.tagName === 'INPUT' || target.tagName === 'SELECT' || target.tagName === 'OPTION')
|
|
364
|
+
return;
|
|
365
|
+
event.preventDefault();
|
|
366
|
+
this.anchorElement.focus({ preventScroll: true });
|
|
367
|
+
});
|
|
368
|
+
}
|
|
369
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/** Returns default character format. */
|
|
2
|
+
export function defaultCharFormat() {
|
|
3
|
+
return {
|
|
4
|
+
fontFamily: 'monospace',
|
|
5
|
+
fontSize: 24,
|
|
6
|
+
bold: false,
|
|
7
|
+
italic: false,
|
|
8
|
+
underline: false,
|
|
9
|
+
overline: false,
|
|
10
|
+
strike: false,
|
|
11
|
+
script: 'normal',
|
|
12
|
+
aci: null,
|
|
13
|
+
rgb: 0xffffff
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
/** Compares two formats. */
|
|
17
|
+
export function sameFormat(a, b) {
|
|
18
|
+
return (a.fontFamily === b.fontFamily &&
|
|
19
|
+
a.fontSize === b.fontSize &&
|
|
20
|
+
a.bold === b.bold &&
|
|
21
|
+
a.italic === b.italic &&
|
|
22
|
+
a.underline === b.underline &&
|
|
23
|
+
a.overline === b.overline &&
|
|
24
|
+
a.strike === b.strike &&
|
|
25
|
+
a.script === b.script &&
|
|
26
|
+
a.aci === b.aci &&
|
|
27
|
+
a.rgb === b.rgb);
|
|
28
|
+
}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
export { MTextInputBox, MTextEditor, defaultCharFormat, sameFormat } from './viewer';
|
|
2
|
+
export type { CharFormat, CharScript, EditorState, LayoutCharBox, RendererContainerBox, RendererLineInfo, MTextRendererOutput, CursorLayoutData, MTextBoundingBoxStyle, MTextInputBoxOptions, MTextToolbarOptions, MTextToolbarTheme, CursorDirection, SelectionDirection, MTextInputBoxEvent, MTextEditorEvent, MTextEditorOptions } from './types';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { MTextInputBox, MTextEditor, defaultCharFormat, sameFormat } from './viewer';
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
import type { Box, CursorStyle, SelectionStyle } from '@mlightcad/text-box-cursor';
|
|
2
|
+
import type * as THREE from 'three';
|
|
3
|
+
/** Vertical script style for a character run. */
|
|
4
|
+
export type CharScript = 'normal' | 'superscript' | 'subscript';
|
|
5
|
+
/** Character-level formatting attributes used by rich text editing operations. */
|
|
6
|
+
export interface CharFormat {
|
|
7
|
+
/** Font family name (for example `Arial` or `sans-serif`). */
|
|
8
|
+
fontFamily: string;
|
|
9
|
+
/** Font size in world units. */
|
|
10
|
+
fontSize: number;
|
|
11
|
+
/** Whether bold style is enabled. */
|
|
12
|
+
bold: boolean;
|
|
13
|
+
/** Whether italic style is enabled. */
|
|
14
|
+
italic: boolean;
|
|
15
|
+
/** Whether underline decoration is enabled. */
|
|
16
|
+
underline: boolean;
|
|
17
|
+
/** Whether overline decoration is enabled. */
|
|
18
|
+
overline: boolean;
|
|
19
|
+
/** Vertical script style (normal/superscript/subscript). */
|
|
20
|
+
script: CharScript;
|
|
21
|
+
/** Whether strike-through decoration is enabled. */
|
|
22
|
+
strike: boolean;
|
|
23
|
+
/** AutoCAD ACI indexed color. When present (1..255), it takes precedence over `rgb`. */
|
|
24
|
+
aci: number | null;
|
|
25
|
+
/** Explicit RGB color packed as `0xRRGGBB`. */
|
|
26
|
+
rgb: number | null;
|
|
27
|
+
}
|
|
28
|
+
/** Internal editor state snapshot used for updates and history-like operations. */
|
|
29
|
+
export interface EditorState {
|
|
30
|
+
/** Full MTEXT source string. */
|
|
31
|
+
mtextString: string;
|
|
32
|
+
/** Current cursor index in the logical character sequence. */
|
|
33
|
+
cursorIndex: number;
|
|
34
|
+
/** Selection start index (inclusive). */
|
|
35
|
+
selectionStart: number;
|
|
36
|
+
/** Selection end index (exclusive). */
|
|
37
|
+
selectionEnd: number;
|
|
38
|
+
/** Active format applied to newly inserted text. */
|
|
39
|
+
currentFormat: CharFormat;
|
|
40
|
+
}
|
|
41
|
+
/** Per-character layout box resolved from rendered MTEXT output. */
|
|
42
|
+
export interface LayoutCharBox {
|
|
43
|
+
/** Character center X coordinate. */
|
|
44
|
+
x: number;
|
|
45
|
+
/** Character center Y coordinate. */
|
|
46
|
+
y: number;
|
|
47
|
+
/** Character box width. */
|
|
48
|
+
width: number;
|
|
49
|
+
/** Character box height. */
|
|
50
|
+
height: number;
|
|
51
|
+
/** Character value represented by this box. */
|
|
52
|
+
char: string;
|
|
53
|
+
/** Effective format used when laying out this character. */
|
|
54
|
+
format: CharFormat;
|
|
55
|
+
}
|
|
56
|
+
/** Container bounds for the editable text region. */
|
|
57
|
+
export interface RendererContainerBox {
|
|
58
|
+
/** Container center X coordinate. */
|
|
59
|
+
x: number;
|
|
60
|
+
/** Container center Y coordinate. */
|
|
61
|
+
y: number;
|
|
62
|
+
/** Container width. */
|
|
63
|
+
width: number;
|
|
64
|
+
/** Container height. */
|
|
65
|
+
height: number;
|
|
66
|
+
}
|
|
67
|
+
/** Line-level layout metadata returned by the renderer. */
|
|
68
|
+
export interface RendererLineInfo {
|
|
69
|
+
/** First character index in this line. */
|
|
70
|
+
startIndex: number;
|
|
71
|
+
/** Last character index in this line. */
|
|
72
|
+
endIndex: number;
|
|
73
|
+
/** Line center Y coordinate. */
|
|
74
|
+
y: number;
|
|
75
|
+
/** Computed line height. */
|
|
76
|
+
height: number;
|
|
77
|
+
}
|
|
78
|
+
/** Renderer output consumed by cursor logic and scene visualization. */
|
|
79
|
+
export interface MTextRendererOutput {
|
|
80
|
+
/** Per-character layout boxes in document order. */
|
|
81
|
+
boxes: LayoutCharBox[];
|
|
82
|
+
/** Overall container bounds for hit-testing and selection visualization. */
|
|
83
|
+
containerBox: RendererContainerBox;
|
|
84
|
+
/** Optional line metadata used for vertical cursor navigation. */
|
|
85
|
+
lines?: RendererLineInfo[];
|
|
86
|
+
}
|
|
87
|
+
/** Snapshot of the latest geometry payload passed to `TextBoxCursor.updateData`. */
|
|
88
|
+
export interface CursorLayoutData {
|
|
89
|
+
/** Container bounds passed to TextBoxCursor for caret/selection positioning. */
|
|
90
|
+
containerBox: Box;
|
|
91
|
+
/** Per-character layout boxes in logical text order. */
|
|
92
|
+
charBoxes: Array<Box>;
|
|
93
|
+
/** Optional explicit line break boundary indices. */
|
|
94
|
+
lineBreakIndices?: number[];
|
|
95
|
+
/** Optional per-line layout metadata. */
|
|
96
|
+
lineLayouts?: Array<{
|
|
97
|
+
y: number;
|
|
98
|
+
height: number;
|
|
99
|
+
}>;
|
|
100
|
+
}
|
|
101
|
+
/** Visual style options for the editor bounding box overlay. */
|
|
102
|
+
export interface MTextBoundingBoxStyle {
|
|
103
|
+
/** Stroke/fill color accepted by three.js materials. */
|
|
104
|
+
color?: string | number;
|
|
105
|
+
/** Bounding box opacity in range `[0, 1]`. */
|
|
106
|
+
opacity?: number;
|
|
107
|
+
/** Extra padding added around rendered text bounds. */
|
|
108
|
+
padding?: number;
|
|
109
|
+
/** Z-axis offset used to avoid depth conflicts. */
|
|
110
|
+
zOffset?: number;
|
|
111
|
+
}
|
|
112
|
+
/** Construction options for `MTextInputBox`. */
|
|
113
|
+
export type MTextToolbarTheme = 'light' | 'dark';
|
|
114
|
+
/** Toolbar options for built-in editor toolbar UI. */
|
|
115
|
+
export interface MTextToolbarOptions {
|
|
116
|
+
/** Enables the built-in toolbar. Defaults to true. */
|
|
117
|
+
enabled?: boolean;
|
|
118
|
+
/** Toolbar color theme. Defaults to dark. */
|
|
119
|
+
theme?: MTextToolbarTheme;
|
|
120
|
+
/** Available font family options shown in toolbar dropdown. */
|
|
121
|
+
fontFamilies?: string[];
|
|
122
|
+
/** Custom DOM container to mount toolbar. Defaults to document.body. */
|
|
123
|
+
container?: HTMLElement;
|
|
124
|
+
/** Vertical offset in pixels above editor top edge. Defaults to 10. */
|
|
125
|
+
offsetY?: number;
|
|
126
|
+
}
|
|
127
|
+
export interface MTextInputBoxOptions {
|
|
128
|
+
/** Target three.js scene that owns editor meshes. */
|
|
129
|
+
scene: THREE.Scene;
|
|
130
|
+
/** Camera used for coordinate conversion and interaction. */
|
|
131
|
+
camera: THREE.Camera;
|
|
132
|
+
/** Optional initial MTEXT source string. */
|
|
133
|
+
initialText?: string;
|
|
134
|
+
/** Preferred editor width. */
|
|
135
|
+
width: number;
|
|
136
|
+
/** Optional world-space origin of the editor container. */
|
|
137
|
+
position?: THREE.Vector3;
|
|
138
|
+
/**
|
|
139
|
+
* Single default style source for the component.
|
|
140
|
+
*
|
|
141
|
+
* It is used for:
|
|
142
|
+
* - insertion format of newly typed characters
|
|
143
|
+
* - derived fallback text style passed to `@mlightcad/mtext-renderer`
|
|
144
|
+
*/
|
|
145
|
+
defaultFormat?: Partial<CharFormat>;
|
|
146
|
+
/** Partial cursor style overrides forwarded to cursor renderer. */
|
|
147
|
+
cursorStyle?: Partial<CursorStyle>;
|
|
148
|
+
/** Partial selection style overrides forwarded to cursor renderer. */
|
|
149
|
+
selectionStyle?: Partial<SelectionStyle>;
|
|
150
|
+
/** Enables/disables word wrapping behavior. */
|
|
151
|
+
enableWordWrap?: boolean;
|
|
152
|
+
/** Optional worker URL used by renderer implementations that support workers. */
|
|
153
|
+
workerUrl?: string | URL;
|
|
154
|
+
/** Element used for built-in IME bridge attachment. */
|
|
155
|
+
imeTarget: HTMLElement;
|
|
156
|
+
/** Whether to render a visible editor bounding box overlay. */
|
|
157
|
+
showBoundingBox?: boolean;
|
|
158
|
+
/** Optional style overrides for the bounding box overlay. */
|
|
159
|
+
boundingBoxStyle?: MTextBoundingBoxStyle;
|
|
160
|
+
/** Built-in toolbar configuration (DOM overlay). */
|
|
161
|
+
toolbar?: MTextToolbarOptions;
|
|
162
|
+
}
|
|
163
|
+
/** Directional cursor movement commands. */
|
|
164
|
+
export type CursorDirection = 'left' | 'right' | 'up' | 'down' | 'lineStart' | 'lineEnd' | 'wordPrev' | 'wordNext';
|
|
165
|
+
/** Directional selection extension commands. */
|
|
166
|
+
export type SelectionDirection = 'left' | 'right' | 'up' | 'down' | 'lineStart' | 'lineEnd';
|
|
167
|
+
/** Events emitted by `MTextInputBox`. */
|
|
168
|
+
export type MTextInputBoxEvent = 'change' | 'selectionChange' | 'cursorMove' | 'show' | 'close';
|
|
169
|
+
/** Backward-compatible alias for `MTextInputBoxEvent`. */
|
|
170
|
+
export type MTextEditorEvent = MTextInputBoxEvent;
|
|
171
|
+
/** Backward-compatible alias for `MTextInputBoxOptions`. */
|
|
172
|
+
export type MTextEditorOptions = MTextInputBoxOptions;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|