@mlightcad/mtext-input-box 0.1.0 → 0.1.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.
- package/README.md +149 -149
- package/dist/ui/toolbar.js +121 -121
- package/dist/viewer/viewer.js +36 -2
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -1,149 +1,149 @@
|
|
|
1
|
-
# @mlightcad/mtext-input-box - Three.js Rich Text Editor
|
|
2
|
-
|
|
3
|
-
Three.js-based MTEXT editor component with built-in IME bridge, cursor/selection rendering, and floating toolbar.
|
|
4
|
-
|
|
5
|
-
## Purpose
|
|
6
|
-
|
|
7
|
-
- MTEXT-style editing in Three.js.
|
|
8
|
-
- Keyboard/mouse/IME editing, selection, formatting, undo/redo.
|
|
9
|
-
- Built-in toolbar (theme/font list/container/offset configurable).
|
|
10
|
-
- Integrates `@mlightcad/mtext-renderer` and `@mlightcad/text-box-cursor`.
|
|
11
|
-
|
|
12
|
-
## Install
|
|
13
|
-
|
|
14
|
-
```bash
|
|
15
|
-
pnpm add @mlightcad/mtext-input-box three @mlightcad/mtext-parser @mlightcad/mtext-renderer
|
|
16
|
-
```
|
|
17
|
-
|
|
18
|
-
`@mlightcad/mtext-parser` and `@mlightcad/mtext-renderer` are peer dependencies of `@mlightcad/mtext-input-box`, so your app should install them directly.
|
|
19
|
-
|
|
20
|
-
## Basic Usage
|
|
21
|
-
|
|
22
|
-
```ts
|
|
23
|
-
import * as THREE from 'three';
|
|
24
|
-
import { MTextInputBox } from '@mlightcad/mtext-input-box';
|
|
25
|
-
|
|
26
|
-
const scene = new THREE.Scene();
|
|
27
|
-
const camera = new THREE.OrthographicCamera(0, 1000, 600, 0, -1000, 1000);
|
|
28
|
-
const canvas = document.querySelector<HTMLCanvasElement>('#stage')!;
|
|
29
|
-
|
|
30
|
-
const editor = new MTextInputBox({
|
|
31
|
-
scene,
|
|
32
|
-
camera,
|
|
33
|
-
width: 800,
|
|
34
|
-
position: new THREE.Vector3(80, 520, 0),
|
|
35
|
-
initialText: 'Hello\\PWorld',
|
|
36
|
-
imeTarget: canvas,
|
|
37
|
-
defaultFormat: {
|
|
38
|
-
fontFamily: 'monospace',
|
|
39
|
-
fontSize: 24,
|
|
40
|
-
bold: false,
|
|
41
|
-
italic: false,
|
|
42
|
-
underline: false,
|
|
43
|
-
overline: false,
|
|
44
|
-
strike: false,
|
|
45
|
-
aci: null,
|
|
46
|
-
rgb: 0xffffff
|
|
47
|
-
},
|
|
48
|
-
toolbar: {
|
|
49
|
-
enabled: true,
|
|
50
|
-
theme: 'dark',
|
|
51
|
-
offsetY: 12
|
|
52
|
-
}
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
function animate() {
|
|
56
|
-
requestAnimationFrame(animate);
|
|
57
|
-
editor.update();
|
|
58
|
-
}
|
|
59
|
-
animate();
|
|
60
|
-
```
|
|
61
|
-
|
|
62
|
-
Notes:
|
|
63
|
-
|
|
64
|
-
- `imeTarget` is required for text input/IME and built-in mouse interactions.
|
|
65
|
-
- For multi-editor scenes, each editor instance can share the same canvas `imeTarget`.
|
|
66
|
-
|
|
67
|
-
## Toolbar
|
|
68
|
-
|
|
69
|
-
The built-in toolbar is a DOM overlay mounted above the active editor and updated automatically when camera/viewport changes.
|
|
70
|
-
|
|
71
|
-
`toolbar` options:
|
|
72
|
-
|
|
73
|
-
- `enabled?: boolean` (default `true`)
|
|
74
|
-
- `theme?: 'light' | 'dark'` (default `dark`)
|
|
75
|
-
- `fontFamilies?: string[]` (default `['Arial', 'Helvetica', 'Verdana', 'Tahoma', 'Trebuchet MS', 'Times New Roman', 'Georgia', 'Courier New', 'system-ui', 'sans-serif', 'serif', 'monospace']`)
|
|
76
|
-
- `container?: HTMLElement` (default `document.body`)
|
|
77
|
-
- `offsetY?: number` (default `10`)
|
|
78
|
-
|
|
79
|
-
Public toolbar-related methods:
|
|
80
|
-
|
|
81
|
-
- `setToolbarTheme('light' | 'dark')`
|
|
82
|
-
- `getToolbarTheme()`
|
|
83
|
-
|
|
84
|
-
## Editor Visibility And Activation
|
|
85
|
-
|
|
86
|
-
- Click inside editor bounds: activate editor and start editing.
|
|
87
|
-
- Click outside active editor bounds: editor closes (`closeEditor()` behavior).
|
|
88
|
-
- Double-click rendered text of a closed editor: re-open (`showEditor()` behavior).
|
|
89
|
-
- Programmatic control:
|
|
90
|
-
- `closeEditor(): void`
|
|
91
|
-
- `showEditor(): boolean`
|
|
92
|
-
|
|
93
|
-
## Important Options
|
|
94
|
-
|
|
95
|
-
- `defaultFormat`: base insert format and renderer fallback style source.
|
|
96
|
-
- `imeTarget`: element used by built-in IME bridge and built-in pointer interactions.
|
|
97
|
-
- `enableWordWrap?: boolean`: enable/disable editor-side wrapping behavior.
|
|
98
|
-
- `showBoundingBox?: boolean`: show editor boundary rectangle.
|
|
99
|
-
- `boundingBoxStyle?: { color?, opacity?, padding?, zOffset? }`: boundary style overrides.
|
|
100
|
-
- `workerUrl?: string | URL`: worker URL for renderer initialization.
|
|
101
|
-
- `cursorStyle` / `selectionStyle`: forwarded to cursor renderer.
|
|
102
|
-
- `toolbar`: built-in toolbar options (`enabled`, `theme`, `fontFamilies`, `container`, `offsetY`).
|
|
103
|
-
|
|
104
|
-
## Input And Interaction
|
|
105
|
-
|
|
106
|
-
Built-in handling:
|
|
107
|
-
|
|
108
|
-
- Keyboard editing (including macOS/Windows shortcut variants)
|
|
109
|
-
- IME composition (via hidden textarea bridge)
|
|
110
|
-
- Mouse selection and word-select:
|
|
111
|
-
- `mousedown`: place cursor / shift-select
|
|
112
|
-
- `mousemove` during drag: update selection
|
|
113
|
-
- `mouseup`: stop drag
|
|
114
|
-
- `dblclick`: select word
|
|
115
|
-
|
|
116
|
-
Advanced control:
|
|
117
|
-
|
|
118
|
-
- `attachIme(target)` / `detachIme()`
|
|
119
|
-
- `attachPointerInteractions(target)` / `detachPointerInteractions()`
|
|
120
|
-
|
|
121
|
-
## Events
|
|
122
|
-
|
|
123
|
-
- `change`
|
|
124
|
-
- `selectionChange`
|
|
125
|
-
- `cursorMove`
|
|
126
|
-
- `show`
|
|
127
|
-
- `close`
|
|
128
|
-
|
|
129
|
-
## Undo / Redo
|
|
130
|
-
|
|
131
|
-
- API:
|
|
132
|
-
- `undo(): boolean`
|
|
133
|
-
- `redo(): boolean`
|
|
134
|
-
- Keyboard:
|
|
135
|
-
- `Ctrl/Cmd + Z`: undo
|
|
136
|
-
- `Ctrl/Cmd + Y`: redo
|
|
137
|
-
- `Ctrl/Cmd + Shift + Z`: redo
|
|
138
|
-
|
|
139
|
-
## Lifecycle
|
|
140
|
-
|
|
141
|
-
- Call `editor.update()` inside your render loop.
|
|
142
|
-
- Call `editor.dispose()` when unmounting to release renderer, cursor, IME, toolbar, and pointer listeners.
|
|
143
|
-
|
|
144
|
-
## Development
|
|
145
|
-
|
|
146
|
-
```bash
|
|
147
|
-
pnpm --filter @mlightcad/mtext-input-box lint
|
|
148
|
-
pnpm --filter @mlightcad/mtext-input-box build
|
|
149
|
-
```
|
|
1
|
+
# @mlightcad/mtext-input-box - Three.js Rich Text Editor
|
|
2
|
+
|
|
3
|
+
Three.js-based MTEXT editor component with built-in IME bridge, cursor/selection rendering, and floating toolbar.
|
|
4
|
+
|
|
5
|
+
## Purpose
|
|
6
|
+
|
|
7
|
+
- MTEXT-style editing in Three.js.
|
|
8
|
+
- Keyboard/mouse/IME editing, selection, formatting, undo/redo.
|
|
9
|
+
- Built-in toolbar (theme/font list/container/offset configurable).
|
|
10
|
+
- Integrates `@mlightcad/mtext-renderer` and `@mlightcad/text-box-cursor`.
|
|
11
|
+
|
|
12
|
+
## Install
|
|
13
|
+
|
|
14
|
+
```bash
|
|
15
|
+
pnpm add @mlightcad/mtext-input-box three @mlightcad/mtext-parser @mlightcad/mtext-renderer
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
`@mlightcad/mtext-parser` and `@mlightcad/mtext-renderer` are peer dependencies of `@mlightcad/mtext-input-box`, so your app should install them directly.
|
|
19
|
+
|
|
20
|
+
## Basic Usage
|
|
21
|
+
|
|
22
|
+
```ts
|
|
23
|
+
import * as THREE from 'three';
|
|
24
|
+
import { MTextInputBox } from '@mlightcad/mtext-input-box';
|
|
25
|
+
|
|
26
|
+
const scene = new THREE.Scene();
|
|
27
|
+
const camera = new THREE.OrthographicCamera(0, 1000, 600, 0, -1000, 1000);
|
|
28
|
+
const canvas = document.querySelector<HTMLCanvasElement>('#stage')!;
|
|
29
|
+
|
|
30
|
+
const editor = new MTextInputBox({
|
|
31
|
+
scene,
|
|
32
|
+
camera,
|
|
33
|
+
width: 800,
|
|
34
|
+
position: new THREE.Vector3(80, 520, 0),
|
|
35
|
+
initialText: 'Hello\\PWorld',
|
|
36
|
+
imeTarget: canvas,
|
|
37
|
+
defaultFormat: {
|
|
38
|
+
fontFamily: 'monospace',
|
|
39
|
+
fontSize: 24,
|
|
40
|
+
bold: false,
|
|
41
|
+
italic: false,
|
|
42
|
+
underline: false,
|
|
43
|
+
overline: false,
|
|
44
|
+
strike: false,
|
|
45
|
+
aci: null,
|
|
46
|
+
rgb: 0xffffff
|
|
47
|
+
},
|
|
48
|
+
toolbar: {
|
|
49
|
+
enabled: true,
|
|
50
|
+
theme: 'dark',
|
|
51
|
+
offsetY: 12
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
function animate() {
|
|
56
|
+
requestAnimationFrame(animate);
|
|
57
|
+
editor.update();
|
|
58
|
+
}
|
|
59
|
+
animate();
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
Notes:
|
|
63
|
+
|
|
64
|
+
- `imeTarget` is required for text input/IME and built-in mouse interactions.
|
|
65
|
+
- For multi-editor scenes, each editor instance can share the same canvas `imeTarget`.
|
|
66
|
+
|
|
67
|
+
## Toolbar
|
|
68
|
+
|
|
69
|
+
The built-in toolbar is a DOM overlay mounted above the active editor and updated automatically when camera/viewport changes.
|
|
70
|
+
|
|
71
|
+
`toolbar` options:
|
|
72
|
+
|
|
73
|
+
- `enabled?: boolean` (default `true`)
|
|
74
|
+
- `theme?: 'light' | 'dark'` (default `dark`)
|
|
75
|
+
- `fontFamilies?: string[]` (default `['Arial', 'Helvetica', 'Verdana', 'Tahoma', 'Trebuchet MS', 'Times New Roman', 'Georgia', 'Courier New', 'system-ui', 'sans-serif', 'serif', 'monospace']`)
|
|
76
|
+
- `container?: HTMLElement` (default `document.body`)
|
|
77
|
+
- `offsetY?: number` (default `10`)
|
|
78
|
+
|
|
79
|
+
Public toolbar-related methods:
|
|
80
|
+
|
|
81
|
+
- `setToolbarTheme('light' | 'dark')`
|
|
82
|
+
- `getToolbarTheme()`
|
|
83
|
+
|
|
84
|
+
## Editor Visibility And Activation
|
|
85
|
+
|
|
86
|
+
- Click inside editor bounds: activate editor and start editing.
|
|
87
|
+
- Click outside active editor bounds: editor closes (`closeEditor()` behavior).
|
|
88
|
+
- Double-click rendered text of a closed editor: re-open (`showEditor()` behavior).
|
|
89
|
+
- Programmatic control:
|
|
90
|
+
- `closeEditor(): void`
|
|
91
|
+
- `showEditor(): boolean`
|
|
92
|
+
|
|
93
|
+
## Important Options
|
|
94
|
+
|
|
95
|
+
- `defaultFormat`: base insert format and renderer fallback style source.
|
|
96
|
+
- `imeTarget`: element used by built-in IME bridge and built-in pointer interactions.
|
|
97
|
+
- `enableWordWrap?: boolean`: enable/disable editor-side wrapping behavior.
|
|
98
|
+
- `showBoundingBox?: boolean`: show editor boundary rectangle.
|
|
99
|
+
- `boundingBoxStyle?: { color?, opacity?, padding?, zOffset? }`: boundary style overrides.
|
|
100
|
+
- `workerUrl?: string | URL`: worker URL for renderer initialization.
|
|
101
|
+
- `cursorStyle` / `selectionStyle`: forwarded to cursor renderer.
|
|
102
|
+
- `toolbar`: built-in toolbar options (`enabled`, `theme`, `fontFamilies`, `container`, `offsetY`).
|
|
103
|
+
|
|
104
|
+
## Input And Interaction
|
|
105
|
+
|
|
106
|
+
Built-in handling:
|
|
107
|
+
|
|
108
|
+
- Keyboard editing (including macOS/Windows shortcut variants)
|
|
109
|
+
- IME composition (via hidden textarea bridge)
|
|
110
|
+
- Mouse selection and word-select:
|
|
111
|
+
- `mousedown`: place cursor / shift-select
|
|
112
|
+
- `mousemove` during drag: update selection
|
|
113
|
+
- `mouseup`: stop drag
|
|
114
|
+
- `dblclick`: select word
|
|
115
|
+
|
|
116
|
+
Advanced control:
|
|
117
|
+
|
|
118
|
+
- `attachIme(target)` / `detachIme()`
|
|
119
|
+
- `attachPointerInteractions(target)` / `detachPointerInteractions()`
|
|
120
|
+
|
|
121
|
+
## Events
|
|
122
|
+
|
|
123
|
+
- `change`
|
|
124
|
+
- `selectionChange`
|
|
125
|
+
- `cursorMove`
|
|
126
|
+
- `show`
|
|
127
|
+
- `close`
|
|
128
|
+
|
|
129
|
+
## Undo / Redo
|
|
130
|
+
|
|
131
|
+
- API:
|
|
132
|
+
- `undo(): boolean`
|
|
133
|
+
- `redo(): boolean`
|
|
134
|
+
- Keyboard:
|
|
135
|
+
- `Ctrl/Cmd + Z`: undo
|
|
136
|
+
- `Ctrl/Cmd + Y`: redo
|
|
137
|
+
- `Ctrl/Cmd + Shift + Z`: redo
|
|
138
|
+
|
|
139
|
+
## Lifecycle
|
|
140
|
+
|
|
141
|
+
- Call `editor.update()` inside your render loop.
|
|
142
|
+
- Call `editor.dispose()` when unmounting to release renderer, cursor, IME, toolbar, and pointer listeners.
|
|
143
|
+
|
|
144
|
+
## Development
|
|
145
|
+
|
|
146
|
+
```bash
|
|
147
|
+
pnpm --filter @mlightcad/mtext-input-box lint
|
|
148
|
+
pnpm --filter @mlightcad/mtext-input-box build
|
|
149
|
+
```
|
package/dist/ui/toolbar.js
CHANGED
|
@@ -19,119 +19,119 @@ function ensureToolbarStyles() {
|
|
|
19
19
|
return;
|
|
20
20
|
const style = document.createElement('style');
|
|
21
21
|
style.id = STYLE_ID;
|
|
22
|
-
style.textContent = `
|
|
23
|
-
.
|
|
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
|
-
.
|
|
41
|
-
background: linear-gradient(180deg, #2a2d33 0%, #1d2025 100%);
|
|
42
|
-
border-color: #444b58;
|
|
43
|
-
color: #e8ecf4;
|
|
44
|
-
}
|
|
45
|
-
.
|
|
46
|
-
background: linear-gradient(180deg, #ffffff 0%, #f2f4f8 100%);
|
|
47
|
-
border-color: #cfd5df;
|
|
48
|
-
color: #1e2430;
|
|
49
|
-
}
|
|
50
|
-
.
|
|
51
|
-
display: inline-flex;
|
|
52
|
-
align-items: center;
|
|
53
|
-
gap: 4px;
|
|
54
|
-
}
|
|
55
|
-
.
|
|
56
|
-
width: 1px;
|
|
57
|
-
height: 24px;
|
|
58
|
-
opacity: 0.35;
|
|
59
|
-
}
|
|
60
|
-
.
|
|
61
|
-
background: #576177;
|
|
62
|
-
}
|
|
63
|
-
.
|
|
64
|
-
background: #b8c0ce;
|
|
65
|
-
}
|
|
66
|
-
.
|
|
67
|
-
.
|
|
68
|
-
.
|
|
69
|
-
.
|
|
70
|
-
border: 1px solid;
|
|
71
|
-
border-radius: 6px;
|
|
72
|
-
height: 34px;
|
|
73
|
-
}
|
|
74
|
-
.
|
|
75
|
-
.
|
|
76
|
-
.
|
|
77
|
-
.
|
|
78
|
-
background: #12161d;
|
|
79
|
-
border-color: #454d5f;
|
|
80
|
-
color: #f2f5fb;
|
|
81
|
-
}
|
|
82
|
-
.
|
|
83
|
-
.
|
|
84
|
-
.
|
|
85
|
-
.
|
|
86
|
-
background: #ffffff;
|
|
87
|
-
border-color: #c7cdd8;
|
|
88
|
-
color: #1f2632;
|
|
89
|
-
}
|
|
90
|
-
.
|
|
91
|
-
min-width: 140px;
|
|
92
|
-
padding: 0 8px;
|
|
93
|
-
}
|
|
94
|
-
.
|
|
95
|
-
width: 64px;
|
|
96
|
-
padding: 0 8px;
|
|
97
|
-
}
|
|
98
|
-
.
|
|
99
|
-
width: 40px;
|
|
100
|
-
padding: 2px;
|
|
101
|
-
}
|
|
102
|
-
.
|
|
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
|
-
.
|
|
111
|
-
width: 24px;
|
|
112
|
-
height: 24px;
|
|
113
|
-
fill: currentColor;
|
|
114
|
-
}
|
|
115
|
-
.
|
|
116
|
-
border-color: #2f9dff;
|
|
117
|
-
color: #2f9dff;
|
|
118
|
-
}
|
|
119
|
-
.
|
|
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
|
-
.
|
|
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
|
-
.
|
|
130
|
-
background: #1f2530;
|
|
131
|
-
}
|
|
132
|
-
.
|
|
133
|
-
background: #edf3ff;
|
|
134
|
-
}
|
|
22
|
+
style.textContent = `
|
|
23
|
+
.ml-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
|
+
.ml-mtext-toolbar[data-theme='dark'] {
|
|
41
|
+
background: linear-gradient(180deg, #2a2d33 0%, #1d2025 100%);
|
|
42
|
+
border-color: #444b58;
|
|
43
|
+
color: #e8ecf4;
|
|
44
|
+
}
|
|
45
|
+
.ml-mtext-toolbar[data-theme='light'] {
|
|
46
|
+
background: linear-gradient(180deg, #ffffff 0%, #f2f4f8 100%);
|
|
47
|
+
border-color: #cfd5df;
|
|
48
|
+
color: #1e2430;
|
|
49
|
+
}
|
|
50
|
+
.ml-mtext-toolbar__group {
|
|
51
|
+
display: inline-flex;
|
|
52
|
+
align-items: center;
|
|
53
|
+
gap: 4px;
|
|
54
|
+
}
|
|
55
|
+
.ml-mtext-toolbar__separator {
|
|
56
|
+
width: 1px;
|
|
57
|
+
height: 24px;
|
|
58
|
+
opacity: 0.35;
|
|
59
|
+
}
|
|
60
|
+
.ml-mtext-toolbar[data-theme='dark'] .ml-mtext-toolbar__separator {
|
|
61
|
+
background: #576177;
|
|
62
|
+
}
|
|
63
|
+
.ml-mtext-toolbar[data-theme='light'] .ml-mtext-toolbar__separator {
|
|
64
|
+
background: #b8c0ce;
|
|
65
|
+
}
|
|
66
|
+
.ml-mtext-toolbar__select,
|
|
67
|
+
.ml-mtext-toolbar__input,
|
|
68
|
+
.ml-mtext-toolbar__color,
|
|
69
|
+
.ml-mtext-toolbar__btn {
|
|
70
|
+
border: 1px solid;
|
|
71
|
+
border-radius: 6px;
|
|
72
|
+
height: 34px;
|
|
73
|
+
}
|
|
74
|
+
.ml-mtext-toolbar[data-theme='dark'] .ml-mtext-toolbar__select,
|
|
75
|
+
.ml-mtext-toolbar[data-theme='dark'] .ml-mtext-toolbar__input,
|
|
76
|
+
.ml-mtext-toolbar[data-theme='dark'] .ml-mtext-toolbar__color,
|
|
77
|
+
.ml-mtext-toolbar[data-theme='dark'] .ml-mtext-toolbar__btn {
|
|
78
|
+
background: #12161d;
|
|
79
|
+
border-color: #454d5f;
|
|
80
|
+
color: #f2f5fb;
|
|
81
|
+
}
|
|
82
|
+
.ml-mtext-toolbar[data-theme='light'] .ml-mtext-toolbar__select,
|
|
83
|
+
.ml-mtext-toolbar[data-theme='light'] .ml-mtext-toolbar__input,
|
|
84
|
+
.ml-mtext-toolbar[data-theme='light'] .ml-mtext-toolbar__color,
|
|
85
|
+
.ml-mtext-toolbar[data-theme='light'] .ml-mtext-toolbar__btn {
|
|
86
|
+
background: #ffffff;
|
|
87
|
+
border-color: #c7cdd8;
|
|
88
|
+
color: #1f2632;
|
|
89
|
+
}
|
|
90
|
+
.ml-mtext-toolbar__select {
|
|
91
|
+
min-width: 140px;
|
|
92
|
+
padding: 0 8px;
|
|
93
|
+
}
|
|
94
|
+
.ml-mtext-toolbar__input {
|
|
95
|
+
width: 64px;
|
|
96
|
+
padding: 0 8px;
|
|
97
|
+
}
|
|
98
|
+
.ml-mtext-toolbar__color {
|
|
99
|
+
width: 40px;
|
|
100
|
+
padding: 2px;
|
|
101
|
+
}
|
|
102
|
+
.ml-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
|
+
.ml-mtext-toolbar__btn svg {
|
|
111
|
+
width: 24px;
|
|
112
|
+
height: 24px;
|
|
113
|
+
fill: currentColor;
|
|
114
|
+
}
|
|
115
|
+
.ml-mtext-toolbar__btn.is-active {
|
|
116
|
+
border-color: #2f9dff;
|
|
117
|
+
color: #2f9dff;
|
|
118
|
+
}
|
|
119
|
+
.ml-mtext-toolbar[data-theme='dark'] .ml-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
|
+
.ml-mtext-toolbar[data-theme='light'] .ml-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
|
+
.ml-mtext-toolbar[data-theme='dark'] .ml-mtext-toolbar__btn:hover {
|
|
130
|
+
background: #1f2530;
|
|
131
|
+
}
|
|
132
|
+
.ml-mtext-toolbar[data-theme='light'] .ml-mtext-toolbar__btn:hover {
|
|
133
|
+
background: #edf3ff;
|
|
134
|
+
}
|
|
135
135
|
`;
|
|
136
136
|
document.head.appendChild(style);
|
|
137
137
|
}
|
|
@@ -150,7 +150,7 @@ function hexToColorNumber(hex) {
|
|
|
150
150
|
function createIconButton(title, icon) {
|
|
151
151
|
const btn = document.createElement('button');
|
|
152
152
|
btn.type = 'button';
|
|
153
|
-
btn.className = '
|
|
153
|
+
btn.className = 'ml-mtext-toolbar__btn';
|
|
154
154
|
btn.title = title;
|
|
155
155
|
btn.setAttribute('aria-label', title);
|
|
156
156
|
btn.setAttribute('aria-pressed', 'false');
|
|
@@ -188,11 +188,11 @@ export class MTextToolbar {
|
|
|
188
188
|
this.onToggleSubscript = options.onToggleSubscript ?? (() => false);
|
|
189
189
|
this.theme = options.theme;
|
|
190
190
|
this.root = document.createElement('div');
|
|
191
|
-
this.root.className = '
|
|
191
|
+
this.root.className = 'ml-mtext-toolbar';
|
|
192
192
|
const typographyGroup = document.createElement('div');
|
|
193
|
-
typographyGroup.className = '
|
|
193
|
+
typographyGroup.className = 'ml-mtext-toolbar__group';
|
|
194
194
|
const fontFamily = document.createElement('select');
|
|
195
|
-
fontFamily.className = '
|
|
195
|
+
fontFamily.className = 'ml-mtext-toolbar__select';
|
|
196
196
|
for (const family of resolveFontFamilies(options.fontFamilies)) {
|
|
197
197
|
const option = document.createElement('option');
|
|
198
198
|
option.value = family;
|
|
@@ -200,19 +200,19 @@ export class MTextToolbar {
|
|
|
200
200
|
fontFamily.appendChild(option);
|
|
201
201
|
}
|
|
202
202
|
const fontSize = document.createElement('input');
|
|
203
|
-
fontSize.className = '
|
|
203
|
+
fontSize.className = 'ml-mtext-toolbar__input';
|
|
204
204
|
fontSize.type = 'number';
|
|
205
205
|
fontSize.min = '1';
|
|
206
206
|
fontSize.max = '1024';
|
|
207
207
|
fontSize.step = '1';
|
|
208
208
|
const fontColor = document.createElement('input');
|
|
209
|
-
fontColor.className = '
|
|
209
|
+
fontColor.className = 'ml-mtext-toolbar__color';
|
|
210
210
|
fontColor.type = 'color';
|
|
211
211
|
typographyGroup.append(fontFamily, fontSize, fontColor);
|
|
212
212
|
const separator1 = document.createElement('div');
|
|
213
|
-
separator1.className = '
|
|
213
|
+
separator1.className = 'ml-mtext-toolbar__separator';
|
|
214
214
|
const styleGroup = document.createElement('div');
|
|
215
|
-
styleGroup.className = '
|
|
215
|
+
styleGroup.className = 'ml-mtext-toolbar__group';
|
|
216
216
|
const boldBtn = createIconButton('Bold', 'bold');
|
|
217
217
|
const italicBtn = createIconButton('Italic', 'italic');
|
|
218
218
|
const underlineBtn = createIconButton('Underline', 'underline');
|
package/dist/viewer/viewer.js
CHANGED
|
@@ -533,6 +533,10 @@ export class MTextInputBox {
|
|
|
533
533
|
if (event.isComposing || event.key === 'Process') {
|
|
534
534
|
return false;
|
|
535
535
|
}
|
|
536
|
+
if (event.key === 'Escape') {
|
|
537
|
+
this.closeEditor();
|
|
538
|
+
return true;
|
|
539
|
+
}
|
|
536
540
|
const isMac = this.isMacPlatform();
|
|
537
541
|
const primaryModifier = isMac ? event.metaKey : event.ctrlKey;
|
|
538
542
|
const wordNavModifier = isMac ? event.altKey : event.ctrlKey;
|
|
@@ -1445,9 +1449,39 @@ export class MTextInputBox {
|
|
|
1445
1449
|
const index = this.cursorLogic.getCurrentIndex();
|
|
1446
1450
|
const line = this.cursorLogic.getCurrentLineInfo();
|
|
1447
1451
|
if (boxes.length === 0) {
|
|
1452
|
+
// Empty-content bootstrap path.
|
|
1453
|
+
//
|
|
1454
|
+
// Why this exists:
|
|
1455
|
+
// - For a brand new/empty MTEXT, there are no glyph boxes yet.
|
|
1456
|
+
// - In that state, TextBoxCursor falls back to its container line info.
|
|
1457
|
+
// - Depending on renderer output, that fallback Y can represent the whole
|
|
1458
|
+
// container center instead of the first editable line center, so the
|
|
1459
|
+
// caret appears visually lower than the top line area.
|
|
1460
|
+
//
|
|
1461
|
+
// Goal:
|
|
1462
|
+
// - Anchor caret to the first editable line, not to the entire empty box.
|
|
1463
|
+
// - Keep X from cursor logic (fallbackPosition.x), only correct Y/height.
|
|
1464
|
+
const firstLine = this.latestCursorLayoutData.lineLayouts?.[0];
|
|
1465
|
+
if (firstLine && Number.isFinite(firstLine.y) && Number.isFinite(firstLine.height)) {
|
|
1466
|
+
const lineHeight = Math.max(1, firstLine.height);
|
|
1467
|
+
return {
|
|
1468
|
+
// Best source: renderer-provided line layout already represents
|
|
1469
|
+
// the actual first-line center in editor local coordinates.
|
|
1470
|
+
position: { x: fallbackPosition.x, y: firstLine.y },
|
|
1471
|
+
height: Math.max(1, lineHeight * 0.8)
|
|
1472
|
+
};
|
|
1473
|
+
}
|
|
1474
|
+
const inferredLineHeight = Math.max(1, this.getFallbackLineAdvance());
|
|
1448
1475
|
return {
|
|
1449
|
-
position:
|
|
1450
|
-
|
|
1476
|
+
position: {
|
|
1477
|
+
x: fallbackPosition.x,
|
|
1478
|
+
// When explicit line layout is unavailable, infer first-line center
|
|
1479
|
+
// from top-left container coordinates:
|
|
1480
|
+
// lineCenterY = containerTopY + lineHeight / 2
|
|
1481
|
+
// This keeps caret aligned with the top row for empty MTEXT.
|
|
1482
|
+
y: this.layoutContainer.y + inferredLineHeight / 2
|
|
1483
|
+
},
|
|
1484
|
+
height: Math.max(1, inferredLineHeight * 0.8)
|
|
1451
1485
|
};
|
|
1452
1486
|
}
|
|
1453
1487
|
// At a line-start gap (including wrapped/paragraph boundaries), rely on
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mlightcad/mtext-input-box",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
"dist"
|
|
15
15
|
],
|
|
16
16
|
"dependencies": {
|
|
17
|
-
"@mlightcad/text-box-cursor": "0.1.
|
|
17
|
+
"@mlightcad/text-box-cursor": "0.1.1"
|
|
18
18
|
},
|
|
19
19
|
"peerDependencies": {
|
|
20
20
|
"@mlightcad/mtext-parser": "^1.3.2",
|