@hypen-space/web 0.4.980 → 0.5.3
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 +20 -13
- package/dist/canvas/accessibility.d.ts +118 -11
- package/dist/canvas/accessibility.js +470 -108
- package/dist/canvas/accessibility.js.map +1 -1
- package/dist/canvas/dispatch.d.ts +24 -0
- package/dist/canvas/dispatch.js +62 -0
- package/dist/canvas/dispatch.js.map +1 -0
- package/dist/canvas/editing.d.ts +178 -0
- package/dist/canvas/editing.js +590 -0
- package/dist/canvas/editing.js.map +1 -0
- package/dist/canvas/events.d.ts +28 -23
- package/dist/canvas/events.js +90 -103
- package/dist/canvas/events.js.map +1 -1
- package/dist/canvas/focus.d.ts +78 -0
- package/dist/canvas/focus.js +182 -0
- package/dist/canvas/focus.js.map +1 -0
- package/dist/canvas/index.d.ts +3 -2
- package/dist/canvas/index.js +3 -2
- package/dist/canvas/index.js.map +1 -1
- package/dist/canvas/layout.js +68 -98
- package/dist/canvas/layout.js.map +1 -1
- package/dist/canvas/paint.d.ts +16 -3
- package/dist/canvas/paint.js +449 -110
- package/dist/canvas/paint.js.map +1 -1
- package/dist/canvas/renderer.d.ts +28 -4
- package/dist/canvas/renderer.js +201 -81
- package/dist/canvas/renderer.js.map +1 -1
- package/dist/canvas/selection.js +31 -177
- package/dist/canvas/selection.js.map +1 -1
- package/dist/canvas/text-geometry.d.ts +72 -0
- package/dist/canvas/text-geometry.js +244 -0
- package/dist/canvas/text-geometry.js.map +1 -0
- package/dist/canvas/text.js +44 -18
- package/dist/canvas/text.js.map +1 -1
- package/dist/canvas/types.d.ts +10 -1
- package/dist/canvas/utils.d.ts +0 -23
- package/dist/canvas/utils.js +3 -67
- package/dist/canvas/utils.js.map +1 -1
- package/dist/canvas/variants.d.ts +52 -0
- package/dist/canvas/variants.js +156 -0
- package/dist/canvas/variants.js.map +1 -0
- package/dist/dom/a11y-styles.d.ts +20 -0
- package/dist/dom/a11y-styles.js +61 -0
- package/dist/dom/a11y-styles.js.map +1 -0
- package/dist/dom/applicators/aria.d.ts +19 -0
- package/dist/dom/applicators/aria.js +36 -0
- package/dist/dom/applicators/aria.js.map +1 -0
- package/dist/dom/applicators/events.d.ts +7 -0
- package/dist/dom/applicators/events.js +36 -8
- package/dist/dom/applicators/events.js.map +1 -1
- package/dist/dom/applicators/font.d.ts +11 -6
- package/dist/dom/applicators/font.js +16 -27
- package/dist/dom/applicators/font.js.map +1 -1
- package/dist/dom/applicators/index.js +51 -45
- package/dist/dom/applicators/index.js.map +1 -1
- package/dist/dom/canvas/index.js +2 -2
- package/dist/dom/canvas/index.js.map +1 -1
- package/dist/dom/components/app.js +2 -2
- package/dist/dom/components/app.js.map +1 -1
- package/dist/dom/components/audio.js +2 -2
- package/dist/dom/components/audio.js.map +1 -1
- package/dist/dom/components/avatar.js +3 -4
- package/dist/dom/components/avatar.js.map +1 -1
- package/dist/dom/components/badge.js +3 -4
- package/dist/dom/components/badge.js.map +1 -1
- package/dist/dom/components/button.js +2 -2
- package/dist/dom/components/button.js.map +1 -1
- package/dist/dom/components/card.js +2 -2
- package/dist/dom/components/card.js.map +1 -1
- package/dist/dom/components/center.js +2 -2
- package/dist/dom/components/center.js.map +1 -1
- package/dist/dom/components/checkbox.js +4 -5
- package/dist/dom/components/checkbox.js.map +1 -1
- package/dist/dom/components/column.js +2 -2
- package/dist/dom/components/column.js.map +1 -1
- package/dist/dom/components/container.js +2 -2
- package/dist/dom/components/container.js.map +1 -1
- package/dist/dom/components/divider.js +2 -2
- package/dist/dom/components/divider.js.map +1 -1
- package/dist/dom/components/grid.js +10 -10
- package/dist/dom/components/grid.js.map +1 -1
- package/dist/dom/components/heading.js +4 -6
- package/dist/dom/components/heading.js.map +1 -1
- package/dist/dom/components/hypenapp.d.ts +25 -1
- package/dist/dom/components/hypenapp.js +215 -247
- package/dist/dom/components/hypenapp.js.map +1 -1
- package/dist/dom/components/icon.js +4 -5
- package/dist/dom/components/icon.js.map +1 -1
- package/dist/dom/components/image.js +2 -2
- package/dist/dom/components/image.js.map +1 -1
- package/dist/dom/components/index.d.ts +2 -2
- package/dist/dom/components/index.js +9 -2
- package/dist/dom/components/index.js.map +1 -1
- package/dist/dom/components/input.js +2 -2
- package/dist/dom/components/input.js.map +1 -1
- package/dist/dom/components/link.js +2 -2
- package/dist/dom/components/link.js.map +1 -1
- package/dist/dom/components/list.js +2 -2
- package/dist/dom/components/list.js.map +1 -1
- package/dist/dom/components/paragraph.js +3 -4
- package/dist/dom/components/paragraph.js.map +1 -1
- package/dist/dom/components/progressbar.js +3 -3
- package/dist/dom/components/progressbar.js.map +1 -1
- package/dist/dom/components/route.js +2 -2
- package/dist/dom/components/route.js.map +1 -1
- package/dist/dom/components/router.js +2 -2
- package/dist/dom/components/router.js.map +1 -1
- package/dist/dom/components/row.js +10 -10
- package/dist/dom/components/row.js.map +1 -1
- package/dist/dom/components/select.js +3 -4
- package/dist/dom/components/select.js.map +1 -1
- package/dist/dom/components/slider.js +2 -2
- package/dist/dom/components/slider.js.map +1 -1
- package/dist/dom/components/spacer.js +2 -2
- package/dist/dom/components/spacer.js.map +1 -1
- package/dist/dom/components/spinner.js +27 -13
- package/dist/dom/components/spinner.js.map +1 -1
- package/dist/dom/components/stack.js +10 -10
- package/dist/dom/components/stack.js.map +1 -1
- package/dist/dom/components/switch.js +5 -6
- package/dist/dom/components/switch.js.map +1 -1
- package/dist/dom/components/tabs.d.ts +27 -0
- package/dist/dom/components/tabs.js +69 -0
- package/dist/dom/components/tabs.js.map +1 -0
- package/dist/dom/components/text.js +4 -7
- package/dist/dom/components/text.js.map +1 -1
- package/dist/dom/components/textarea.js +2 -2
- package/dist/dom/components/textarea.js.map +1 -1
- package/dist/dom/components/video.js +2 -2
- package/dist/dom/components/video.js.map +1 -1
- package/dist/dom/components/visuallyhidden.d.ts +9 -0
- package/dist/dom/components/visuallyhidden.js +26 -0
- package/dist/dom/components/visuallyhidden.js.map +1 -0
- package/dist/dom/debug.js +6 -8
- package/dist/dom/debug.js.map +1 -1
- package/dist/dom/index.d.ts +0 -1
- package/dist/dom/index.js +0 -1
- package/dist/dom/index.js.map +1 -1
- package/dist/dom/operability.d.ts +100 -0
- package/dist/dom/operability.js +298 -0
- package/dist/dom/operability.js.map +1 -0
- package/dist/dom/renderer.d.ts +98 -5
- package/dist/dom/renderer.js +400 -66
- package/dist/dom/renderer.js.map +1 -1
- package/dist/dom/route-focus.d.ts +42 -0
- package/dist/dom/route-focus.js +88 -0
- package/dist/dom/route-focus.js.map +1 -0
- package/dist/dom/semantics.d.ts +35 -0
- package/dist/dom/semantics.js +184 -0
- package/dist/dom/semantics.js.map +1 -0
- package/dist/variants.d.ts +90 -0
- package/dist/variants.js +206 -0
- package/dist/variants.js.map +1 -0
- package/package.json +2 -2
- package/src/canvas/QUICKSTART.md +16 -11
- package/src/canvas/README.md +63 -34
- package/src/canvas/accessibility.ts +507 -115
- package/src/canvas/dispatch.ts +78 -0
- package/src/canvas/editing.ts +697 -0
- package/src/canvas/events.ts +104 -115
- package/src/canvas/focus.ts +216 -0
- package/src/canvas/index.ts +8 -9
- package/src/canvas/layout.ts +68 -103
- package/src/canvas/paint.ts +509 -109
- package/src/canvas/renderer.ts +239 -99
- package/src/canvas/selection.ts +52 -210
- package/src/canvas/text-geometry.ts +311 -0
- package/src/canvas/text.ts +45 -18
- package/src/canvas/types.ts +28 -1
- package/src/canvas/utils.ts +3 -69
- package/src/canvas/variants.ts +172 -0
- package/src/dom/README.md +8 -7
- package/src/dom/a11y-styles.ts +65 -0
- package/src/dom/applicators/aria.ts +41 -0
- package/src/dom/applicators/events.ts +39 -7
- package/src/dom/applicators/font.ts +16 -29
- package/src/dom/applicators/index.ts +61 -46
- package/src/dom/canvas/index.ts +2 -2
- package/src/dom/components/app.ts +2 -2
- package/src/dom/components/audio.ts +2 -2
- package/src/dom/components/avatar.ts +3 -4
- package/src/dom/components/badge.ts +3 -4
- package/src/dom/components/button.ts +2 -2
- package/src/dom/components/card.ts +2 -2
- package/src/dom/components/center.ts +2 -2
- package/src/dom/components/checkbox.ts +4 -5
- package/src/dom/components/column.ts +2 -2
- package/src/dom/components/container.ts +2 -2
- package/src/dom/components/divider.ts +2 -2
- package/src/dom/components/grid.ts +10 -10
- package/src/dom/components/heading.ts +4 -6
- package/src/dom/components/hypenapp.ts +246 -274
- package/src/dom/components/icon.ts +4 -5
- package/src/dom/components/image.ts +2 -2
- package/src/dom/components/index.ts +10 -3
- package/src/dom/components/input.ts +2 -2
- package/src/dom/components/link.ts +2 -2
- package/src/dom/components/list.ts +2 -2
- package/src/dom/components/paragraph.ts +3 -4
- package/src/dom/components/progressbar.ts +3 -3
- package/src/dom/components/route.ts +2 -2
- package/src/dom/components/router.ts +2 -2
- package/src/dom/components/row.ts +10 -10
- package/src/dom/components/select.ts +3 -4
- package/src/dom/components/slider.ts +2 -2
- package/src/dom/components/spacer.ts +2 -2
- package/src/dom/components/spinner.ts +34 -16
- package/src/dom/components/stack.ts +10 -10
- package/src/dom/components/switch.ts +5 -6
- package/src/dom/components/tabs.ts +76 -0
- package/src/dom/components/text.ts +4 -7
- package/src/dom/components/textarea.ts +2 -2
- package/src/dom/components/video.ts +2 -2
- package/src/dom/components/visuallyhidden.ts +30 -0
- package/src/dom/debug.ts +6 -8
- package/src/dom/index.ts +0 -8
- package/src/dom/operability.ts +312 -0
- package/src/dom/renderer.ts +457 -66
- package/src/dom/route-focus.ts +98 -0
- package/src/dom/semantics.ts +199 -0
- package/src/variants.ts +249 -0
- package/dist/canvas/input.d.ts +0 -76
- package/dist/canvas/input.js +0 -207
- package/dist/canvas/input.js.map +0 -1
- package/dist/client.d.ts +0 -36
- package/dist/client.js +0 -47
- package/dist/client.js.map +0 -1
- package/src/canvas/input.ts +0 -251
- package/src/client.ts +0 -88
|
@@ -0,0 +1,697 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Native Canvas Text Editing
|
|
3
|
+
*
|
|
4
|
+
* Text, caret, and selection are painted on the canvas; the browser does
|
|
5
|
+
* the actual editing (typing, caret movement, word-jumps, select-all,
|
|
6
|
+
* clipboard, undo, IME composition) in a single hidden **proxy textarea**
|
|
7
|
+
* positioned at the caret — the Monaco/xterm.js approach. This controller
|
|
8
|
+
* reads `value`/`selectionStart`/`selectionEnd` from the proxy after each
|
|
9
|
+
* event and the canvas paints the result. No visible DOM overlay.
|
|
10
|
+
*
|
|
11
|
+
* Why a proxy and not the accessibility-mirror input itself: the proxy is
|
|
12
|
+
* per-session and positioned at the caret, which (a) puts the IME candidate
|
|
13
|
+
* window next to the painted text regardless of where the mirror element
|
|
14
|
+
* sits, and (b) gives screen readers a FRESH focus target per field so
|
|
15
|
+
* every field is announced (AT stays silent when focus "returns" to an
|
|
16
|
+
* element it already announced). Focus and accessibility live on the
|
|
17
|
+
* mirror; the keystroke stream lives on the proxy.
|
|
18
|
+
*
|
|
19
|
+
* Positioning the proxy at the caret makes the IME candidate window
|
|
20
|
+
* appear next to the painted text.
|
|
21
|
+
*
|
|
22
|
+
* Data flow for one keystroke:
|
|
23
|
+
* focusin on mirror input → beginEditing → proxy seeded + focused
|
|
24
|
+
* key → proxy (native edit) → "input" event
|
|
25
|
+
* → EditState {value, selStart, selEnd} read from the proxy
|
|
26
|
+
* → node.props.value = value (local echo so the next paint is current)
|
|
27
|
+
* → engine.dispatchAction("__hypen_bind", {path, value}) (two-way bind)
|
|
28
|
+
* → scheduleRedraw + caret blink reset
|
|
29
|
+
* engine echoes SetProp("value") → onEngineValueEcho → same value → no-op
|
|
30
|
+
* (a *different* echo, e.g. engine-side formatting, rewrites the proxy
|
|
31
|
+
* and clamps the selection).
|
|
32
|
+
*/
|
|
33
|
+
|
|
34
|
+
import type { Point, Rectangle, VirtualNode } from "./types.js";
|
|
35
|
+
import type { DispatchEngine } from "./dispatch.js";
|
|
36
|
+
import { getScrollAwareBounds } from "./scroll.js";
|
|
37
|
+
import { cssLengthToPx } from "./utils.js";
|
|
38
|
+
import {
|
|
39
|
+
nodeTextGeometry,
|
|
40
|
+
offsetToCaretRect,
|
|
41
|
+
pointToOffset,
|
|
42
|
+
type TextGeometry,
|
|
43
|
+
} from "./text-geometry.js";
|
|
44
|
+
|
|
45
|
+
type EditableElement = HTMLInputElement | HTMLTextAreaElement;
|
|
46
|
+
|
|
47
|
+
/** Margin kept between the caret and the content edge when auto-scrolling. */
|
|
48
|
+
const CARET_SCROLL_MARGIN = 4;
|
|
49
|
+
|
|
50
|
+
export interface EditState {
|
|
51
|
+
node: VirtualNode;
|
|
52
|
+
/** The hidden proxy textarea receiving keystrokes and IME composition. */
|
|
53
|
+
element: EditableElement;
|
|
54
|
+
/** The node's accessibility-mirror element (Tab transit target). */
|
|
55
|
+
mirrorElement: HTMLElement;
|
|
56
|
+
value: string;
|
|
57
|
+
selStart: number;
|
|
58
|
+
selEnd: number;
|
|
59
|
+
/** IME composition range (underlined in paint), null when not composing. */
|
|
60
|
+
compStart: number | null;
|
|
61
|
+
compEnd: number | null;
|
|
62
|
+
composing: boolean;
|
|
63
|
+
/** Horizontal pan for single-line inputs whose text overflows. */
|
|
64
|
+
scrollX: number;
|
|
65
|
+
/** Caret blink phase. */
|
|
66
|
+
caretVisible: boolean;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export interface TextEditHooks {
|
|
70
|
+
scheduleRedraw(): void;
|
|
71
|
+
/** Mark the edited node's region dirty (dirty-rect mode). */
|
|
72
|
+
markDirty(node: VirtualNode): void;
|
|
73
|
+
/**
|
|
74
|
+
* Focus left the proxy for somewhere outside the canvas — the renderer
|
|
75
|
+
* clears the focus manager so `node.focused` follows.
|
|
76
|
+
*/
|
|
77
|
+
onEditBlur(): void;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export function isEditableNode(node: VirtualNode | null): boolean {
|
|
81
|
+
if (!node) return false;
|
|
82
|
+
const t = node.type.toLowerCase();
|
|
83
|
+
return t === "input" || t === "textarea";
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/** Whether an element lives inside the accessibility mirror. */
|
|
87
|
+
function isInMirror(el: HTMLElement | null): boolean {
|
|
88
|
+
let current: any = el;
|
|
89
|
+
while (current) {
|
|
90
|
+
if (current.getAttribute?.("data-hypen-id")) return true;
|
|
91
|
+
current = current.parentNode;
|
|
92
|
+
}
|
|
93
|
+
return false;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
export class TextEditController {
|
|
97
|
+
private canvas: HTMLCanvasElement;
|
|
98
|
+
private engine: DispatchEngine;
|
|
99
|
+
private hooks: TextEditHooks;
|
|
100
|
+
private state: EditState | null = null;
|
|
101
|
+
private bindPath: string | null = null;
|
|
102
|
+
private proxy: HTMLTextAreaElement | null = null;
|
|
103
|
+
|
|
104
|
+
/** Blink period; tests may set 0 to disable the timer. */
|
|
105
|
+
blinkIntervalMs = 530;
|
|
106
|
+
private blinkTimer: ReturnType<typeof setInterval> | null = null;
|
|
107
|
+
|
|
108
|
+
// Drag-selection tracking (canvas mousemove while button held on the node)
|
|
109
|
+
private dragAnchor: number | null = null;
|
|
110
|
+
|
|
111
|
+
private boundInput = () => this.onInput();
|
|
112
|
+
private boundSelect = () => this.onSelectionMaybeChanged();
|
|
113
|
+
private boundKeyUp = () => this.onSelectionMaybeChanged();
|
|
114
|
+
private boundKeyDown = (e: Event) => this.onKeyDown(e as KeyboardEvent);
|
|
115
|
+
private boundCompStart = () => this.onCompositionStart();
|
|
116
|
+
private boundCompUpdate = (e: Event) => this.onCompositionUpdate(e as CompositionEvent);
|
|
117
|
+
private boundCompEnd = () => this.onCompositionEnd();
|
|
118
|
+
private boundSelectionChange = () => this.onDocumentSelectionChange();
|
|
119
|
+
private boundBlur = (e: Event) => this.onProxyBlur(e as FocusEvent);
|
|
120
|
+
private boundDragMove = (e: Event) => this.onDragMove(e as MouseEvent);
|
|
121
|
+
private boundDragEnd = () => this.onDragEnd();
|
|
122
|
+
|
|
123
|
+
constructor(canvas: HTMLCanvasElement, engine: DispatchEngine, hooks: TextEditHooks) {
|
|
124
|
+
this.canvas = canvas;
|
|
125
|
+
this.engine = engine;
|
|
126
|
+
this.hooks = hooks;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
// -------------------------------------------------------------------------
|
|
130
|
+
// Session lifecycle
|
|
131
|
+
// -------------------------------------------------------------------------
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* The hidden keystroke/IME target. A FRESH element per edit session:
|
|
135
|
+
* screen readers key announcements off focus moving to a *new* node — a
|
|
136
|
+
* reused proxy reads as "focus returned to the element I already
|
|
137
|
+
* announced" and stays silent, so tabbing between fields would speak the
|
|
138
|
+
* first field's label and then nothing. Kept OUT of the tab order
|
|
139
|
+
* (tabindex=-1) — Tab reaches inputs through their mirror elements;
|
|
140
|
+
* `beginEditing` hands focus here from there.
|
|
141
|
+
*/
|
|
142
|
+
private createProxy(node: VirtualNode): HTMLTextAreaElement | null {
|
|
143
|
+
if (typeof document === "undefined") return null;
|
|
144
|
+
|
|
145
|
+
const proxy = document.createElement("textarea") as HTMLTextAreaElement;
|
|
146
|
+
proxy.setAttribute("tabindex", "-1");
|
|
147
|
+
proxy.setAttribute("autocorrect", "off");
|
|
148
|
+
proxy.setAttribute("autocapitalize", "off");
|
|
149
|
+
proxy.setAttribute("spellcheck", "false");
|
|
150
|
+
proxy.setAttribute("data-hypen-ime-proxy", "");
|
|
151
|
+
Object.assign(proxy.style, {
|
|
152
|
+
position: "absolute",
|
|
153
|
+
width: "1px",
|
|
154
|
+
height: "16px",
|
|
155
|
+
padding: "0",
|
|
156
|
+
border: "0",
|
|
157
|
+
outline: "none",
|
|
158
|
+
margin: "0",
|
|
159
|
+
opacity: "0",
|
|
160
|
+
background: "transparent",
|
|
161
|
+
color: "transparent",
|
|
162
|
+
resize: "none",
|
|
163
|
+
overflow: "hidden",
|
|
164
|
+
zIndex: "1000",
|
|
165
|
+
// Never intercept pointer events meant for the canvas underneath.
|
|
166
|
+
pointerEvents: "none",
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
// Announce like the field it stands in for: label, hint, multiline-ness.
|
|
170
|
+
const isSingleLine = node.type.toLowerCase() === "input";
|
|
171
|
+
proxy.setAttribute("aria-multiline", isSingleLine ? "false" : "true");
|
|
172
|
+
const label =
|
|
173
|
+
node.semantics?.name || node.props.placeholder || node.props["aria-label"];
|
|
174
|
+
if (label) proxy.setAttribute("aria-label", String(label));
|
|
175
|
+
if (node.props.placeholder != null) {
|
|
176
|
+
proxy.placeholder = String(node.props.placeholder);
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
// IME metrics and iOS zoom guard: candidate windows size off the
|
|
180
|
+
// focused element's font; iOS Safari zooms inputs under 16px.
|
|
181
|
+
const fontSize = Math.max(16, cssLengthToPx(node.props.fontSize) ?? 16);
|
|
182
|
+
proxy.style.font = `${fontSize}px ${node.props.fontFamily || "system-ui, sans-serif"}`;
|
|
183
|
+
|
|
184
|
+
const host =
|
|
185
|
+
(this.canvas as any).parentElement ||
|
|
186
|
+
(typeof document !== "undefined" ? document.body : null);
|
|
187
|
+
host?.appendChild?.(proxy);
|
|
188
|
+
|
|
189
|
+
return proxy;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
/**
|
|
193
|
+
* Start editing a node. `mirrorElement` is the node's fallback-content
|
|
194
|
+
* element (focus/AT anchor); keystrokes flow through the hidden proxy.
|
|
195
|
+
* Idempotent for the same node.
|
|
196
|
+
*/
|
|
197
|
+
beginEditing(node: VirtualNode, mirrorElement: HTMLElement): void {
|
|
198
|
+
if (this.state?.node === node) return;
|
|
199
|
+
this.endEditing();
|
|
200
|
+
|
|
201
|
+
const element = this.createProxy(node);
|
|
202
|
+
if (!element) return;
|
|
203
|
+
this.proxy = element;
|
|
204
|
+
|
|
205
|
+
this.bindPath = typeof node.props.bind === "string" ? node.props.bind : null;
|
|
206
|
+
|
|
207
|
+
// Seed the proxy from the node; caret at the end (the pointer path
|
|
208
|
+
// refines it via placeCaretFromPoint right after).
|
|
209
|
+
const value = String(node.props.value ?? "");
|
|
210
|
+
element.value = value;
|
|
211
|
+
element.setSelectionRange?.(value.length, value.length);
|
|
212
|
+
|
|
213
|
+
this.state = {
|
|
214
|
+
node,
|
|
215
|
+
element,
|
|
216
|
+
mirrorElement,
|
|
217
|
+
value,
|
|
218
|
+
selStart: element.selectionStart ?? value.length,
|
|
219
|
+
selEnd: element.selectionEnd ?? value.length,
|
|
220
|
+
compStart: null,
|
|
221
|
+
compEnd: null,
|
|
222
|
+
composing: false,
|
|
223
|
+
scrollX: 0,
|
|
224
|
+
caretVisible: true,
|
|
225
|
+
};
|
|
226
|
+
|
|
227
|
+
element.addEventListener("input", this.boundInput);
|
|
228
|
+
element.addEventListener("select", this.boundSelect);
|
|
229
|
+
element.addEventListener("keyup", this.boundKeyUp);
|
|
230
|
+
element.addEventListener("keydown", this.boundKeyDown);
|
|
231
|
+
element.addEventListener("compositionstart", this.boundCompStart);
|
|
232
|
+
element.addEventListener("compositionupdate", this.boundCompUpdate);
|
|
233
|
+
element.addEventListener("compositionend", this.boundCompEnd);
|
|
234
|
+
element.addEventListener("blur", this.boundBlur);
|
|
235
|
+
// Belt-and-braces caret tracking: `select`/`keyup` miss some caret-only
|
|
236
|
+
// movements in some engines; document selectionchange covers them.
|
|
237
|
+
if (typeof document !== "undefined") {
|
|
238
|
+
(document as any).addEventListener?.("selectionchange", this.boundSelectionChange);
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
this.ensureCaretVisible();
|
|
242
|
+
this.syncProxyPosition();
|
|
243
|
+
(element as any).focus?.({ preventScroll: true });
|
|
244
|
+
|
|
245
|
+
this.startBlink();
|
|
246
|
+
this.hooks.markDirty(node);
|
|
247
|
+
this.hooks.scheduleRedraw();
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
/** Stop editing (focus left the node, Enter/Escape, teardown). */
|
|
251
|
+
endEditing(): void {
|
|
252
|
+
const state = this.state;
|
|
253
|
+
if (!state) return;
|
|
254
|
+
|
|
255
|
+
const { element, node } = state;
|
|
256
|
+
element.removeEventListener("input", this.boundInput);
|
|
257
|
+
element.removeEventListener("select", this.boundSelect);
|
|
258
|
+
element.removeEventListener("keyup", this.boundKeyUp);
|
|
259
|
+
element.removeEventListener("keydown", this.boundKeyDown);
|
|
260
|
+
element.removeEventListener("compositionstart", this.boundCompStart);
|
|
261
|
+
element.removeEventListener("compositionupdate", this.boundCompUpdate);
|
|
262
|
+
element.removeEventListener("compositionend", this.boundCompEnd);
|
|
263
|
+
element.removeEventListener("blur", this.boundBlur);
|
|
264
|
+
if (typeof document !== "undefined") {
|
|
265
|
+
(document as any).removeEventListener?.("selectionchange", this.boundSelectionChange);
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
// A composition cut short by blur/navigation still owes the engine its
|
|
269
|
+
// final value.
|
|
270
|
+
if (state.composing) {
|
|
271
|
+
this.dispatchBind(state.value);
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
this.stopBlink();
|
|
275
|
+
this.onDragEnd();
|
|
276
|
+
this.state = null;
|
|
277
|
+
this.bindPath = null;
|
|
278
|
+
|
|
279
|
+
// If the session ends while the proxy still holds focus (detach,
|
|
280
|
+
// remove, clear), release it. Listener is already removed, so this
|
|
281
|
+
// can't re-enter.
|
|
282
|
+
if (typeof document !== "undefined" && document.activeElement === element) {
|
|
283
|
+
(element as any).blur?.();
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
// The proxy is per-session (fresh element per field so AT announces
|
|
287
|
+
// each one) — remove it from the DOM entirely.
|
|
288
|
+
(element as any).remove?.();
|
|
289
|
+
this.proxy = null;
|
|
290
|
+
|
|
291
|
+
this.hooks.markDirty(node);
|
|
292
|
+
this.hooks.scheduleRedraw();
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
/**
|
|
296
|
+
* Focus left the proxy. Movement back into the mirror (Tab transit, or a
|
|
297
|
+
* click that focuses another node) is handled by the FocusManager's own
|
|
298
|
+
* focusin — only a true departure ends the session here.
|
|
299
|
+
*/
|
|
300
|
+
private onProxyBlur(e: FocusEvent): void {
|
|
301
|
+
if (!this.state) return;
|
|
302
|
+
const next = e.relatedTarget as HTMLElement | null;
|
|
303
|
+
if (next && this.state.mirrorElement.parentNode && isInMirror(next)) return;
|
|
304
|
+
this.endEditing();
|
|
305
|
+
this.hooks.onEditBlur();
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
/** True while `element` is this controller's proxy (focus bookkeeping). */
|
|
309
|
+
isProxyElement(element: unknown): boolean {
|
|
310
|
+
return this.proxy !== null && element === this.proxy;
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
/** The hidden proxy textarea (test/diagnostic access). */
|
|
314
|
+
getProxyElement(): HTMLTextAreaElement | null {
|
|
315
|
+
return this.proxy;
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
isActive(): boolean {
|
|
319
|
+
return this.state !== null;
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
/** Editing state for a node, or null — read by paintInput each frame. */
|
|
323
|
+
getStateFor(node: VirtualNode): EditState | null {
|
|
324
|
+
return this.state?.node === node ? this.state : null;
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
/**
|
|
328
|
+
* End the session if the edited node is `node` or a descendant of it —
|
|
329
|
+
* called by the renderer before remove/detach unlinks a subtree (in a
|
|
330
|
+
* real browser removing a focused element blurs it, but the renderer
|
|
331
|
+
* can't rely on that in every host environment).
|
|
332
|
+
*/
|
|
333
|
+
endIfWithin(node: VirtualNode): void {
|
|
334
|
+
let current: VirtualNode | null = this.state?.node ?? null;
|
|
335
|
+
while (current) {
|
|
336
|
+
if (current === node) {
|
|
337
|
+
this.endEditing();
|
|
338
|
+
return;
|
|
339
|
+
}
|
|
340
|
+
current = current.parent;
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
destroy(): void {
|
|
345
|
+
this.endEditing();
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
// -------------------------------------------------------------------------
|
|
349
|
+
// Element events → state → engine
|
|
350
|
+
// -------------------------------------------------------------------------
|
|
351
|
+
|
|
352
|
+
private syncFromElement(): boolean {
|
|
353
|
+
const state = this.state;
|
|
354
|
+
if (!state) return false;
|
|
355
|
+
const { element } = state;
|
|
356
|
+
|
|
357
|
+
const value = String(element.value ?? "");
|
|
358
|
+
const selStart = element.selectionStart ?? value.length;
|
|
359
|
+
const selEnd = element.selectionEnd ?? value.length;
|
|
360
|
+
|
|
361
|
+
const changed =
|
|
362
|
+
value !== state.value || selStart !== state.selStart || selEnd !== state.selEnd;
|
|
363
|
+
state.value = value;
|
|
364
|
+
state.selStart = selStart;
|
|
365
|
+
state.selEnd = selEnd;
|
|
366
|
+
return changed;
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
private onInput(): void {
|
|
370
|
+
const state = this.state;
|
|
371
|
+
if (!state) return;
|
|
372
|
+
|
|
373
|
+
this.syncFromElement();
|
|
374
|
+
|
|
375
|
+
// Local echo: the next paint shows the typed text before the engine
|
|
376
|
+
// round-trips it via SetProp.
|
|
377
|
+
state.node.props.value = state.value;
|
|
378
|
+
|
|
379
|
+
// Two-way binding — suppressed during IME composition (intermediate
|
|
380
|
+
// composition strings aren't values); compositionend flushes the final.
|
|
381
|
+
if (!state.composing) {
|
|
382
|
+
this.dispatchBind(state.value);
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
this.afterEditActivity();
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
private onSelectionMaybeChanged(): void {
|
|
389
|
+
if (!this.state) return;
|
|
390
|
+
if (this.syncFromElement()) {
|
|
391
|
+
this.afterEditActivity();
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
private onDocumentSelectionChange(): void {
|
|
396
|
+
const state = this.state;
|
|
397
|
+
if (!state) return;
|
|
398
|
+
if (typeof document === "undefined" || document.activeElement !== state.element) return;
|
|
399
|
+
this.onSelectionMaybeChanged();
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
private onKeyDown(e: KeyboardEvent): void {
|
|
403
|
+
const state = this.state;
|
|
404
|
+
if (!state) return;
|
|
405
|
+
|
|
406
|
+
const isSingleLine = state.node.type.toLowerCase() === "input";
|
|
407
|
+
|
|
408
|
+
// Enter submits single-line inputs (blur commits), Escape cancels focus.
|
|
409
|
+
// The proxy's blur handler ends the session, matching the old overlay.
|
|
410
|
+
if ((e.key === "Enter" && isSingleLine && !state.composing) || e.key === "Escape") {
|
|
411
|
+
e.preventDefault();
|
|
412
|
+
state.element.blur?.();
|
|
413
|
+
return;
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
// Tab transit: hand focus back to the node's mirror element WITHOUT
|
|
417
|
+
// preventDefault — the browser's default sequential navigation then
|
|
418
|
+
// proceeds from the mirror, landing on the next/previous mirror element
|
|
419
|
+
// (or out of the canvas) in natural order. If the destination is
|
|
420
|
+
// another Input, its focusin starts the next edit session.
|
|
421
|
+
if (e.key === "Tab" && !state.composing) {
|
|
422
|
+
(state.mirrorElement as any).focus?.({ preventScroll: true });
|
|
423
|
+
}
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
private onCompositionStart(): void {
|
|
427
|
+
const state = this.state;
|
|
428
|
+
if (!state) return;
|
|
429
|
+
state.composing = true;
|
|
430
|
+
state.compStart = state.selStart;
|
|
431
|
+
state.compEnd = state.selStart;
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
private onCompositionUpdate(e: CompositionEvent): void {
|
|
435
|
+
const state = this.state;
|
|
436
|
+
if (!state || state.compStart === null) return;
|
|
437
|
+
state.compEnd = state.compStart + (e.data?.length ?? 0);
|
|
438
|
+
this.afterEditActivity();
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
private onCompositionEnd(): void {
|
|
442
|
+
const state = this.state;
|
|
443
|
+
if (!state) return;
|
|
444
|
+
state.composing = false;
|
|
445
|
+
state.compStart = null;
|
|
446
|
+
state.compEnd = null;
|
|
447
|
+
// Browsers disagree on input-vs-compositionend ordering; syncing and
|
|
448
|
+
// dispatching here covers both (the same-value no-op makes double
|
|
449
|
+
// dispatch harmless).
|
|
450
|
+
this.syncFromElement();
|
|
451
|
+
state.node.props.value = state.value;
|
|
452
|
+
this.dispatchBind(state.value);
|
|
453
|
+
this.afterEditActivity();
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
private dispatchBind(value: string): void {
|
|
457
|
+
if (!this.bindPath) return;
|
|
458
|
+
this.engine.dispatchAction("__hypen_bind", { path: this.bindPath, value });
|
|
459
|
+
}
|
|
460
|
+
|
|
461
|
+
/** Common tail for anything that edited or moved the caret. */
|
|
462
|
+
private afterEditActivity(): void {
|
|
463
|
+
const state = this.state;
|
|
464
|
+
if (!state) return;
|
|
465
|
+
this.ensureCaretVisible();
|
|
466
|
+
this.syncProxyPosition();
|
|
467
|
+
state.caretVisible = true;
|
|
468
|
+
this.restartBlink();
|
|
469
|
+
this.hooks.markDirty(state.node);
|
|
470
|
+
this.hooks.scheduleRedraw();
|
|
471
|
+
}
|
|
472
|
+
|
|
473
|
+
// -------------------------------------------------------------------------
|
|
474
|
+
// Engine echo
|
|
475
|
+
// -------------------------------------------------------------------------
|
|
476
|
+
|
|
477
|
+
/**
|
|
478
|
+
* The engine confirmed/rewrote the value via SetProp. Our own echo
|
|
479
|
+
* round-tripping (same value) must NOT touch the element — writing
|
|
480
|
+
* `element.value` collapses the caret. A genuinely different value
|
|
481
|
+
* (engine-side formatting) rewrites the element and clamps the selection.
|
|
482
|
+
*/
|
|
483
|
+
onEngineValueEcho(node: VirtualNode): void {
|
|
484
|
+
const state = this.state;
|
|
485
|
+
if (!state || state.node !== node) return;
|
|
486
|
+
|
|
487
|
+
const value = String(node.props.value ?? "");
|
|
488
|
+
if (value === state.value) return;
|
|
489
|
+
|
|
490
|
+
const { element } = state;
|
|
491
|
+
element.value = value;
|
|
492
|
+
const sel = Math.min(state.selEnd, value.length);
|
|
493
|
+
element.setSelectionRange?.(sel, sel);
|
|
494
|
+
this.syncFromElement();
|
|
495
|
+
this.afterEditActivity();
|
|
496
|
+
}
|
|
497
|
+
|
|
498
|
+
// -------------------------------------------------------------------------
|
|
499
|
+
// Pointer path — caret placement and drag selection on the canvas
|
|
500
|
+
// -------------------------------------------------------------------------
|
|
501
|
+
|
|
502
|
+
/**
|
|
503
|
+
* Map a canvas mousedown on the edited node to a caret position, and arm
|
|
504
|
+
* drag-selection until mouseup.
|
|
505
|
+
*/
|
|
506
|
+
placeCaretFromPoint(node: VirtualNode, point: Point): void {
|
|
507
|
+
const state = this.state;
|
|
508
|
+
if (!state || state.node !== node) return;
|
|
509
|
+
|
|
510
|
+
const offset = this.offsetFromPoint(point);
|
|
511
|
+
if (offset === null) return;
|
|
512
|
+
|
|
513
|
+
state.element.setSelectionRange?.(offset, offset);
|
|
514
|
+
this.dragAnchor = offset;
|
|
515
|
+
this.canvas.addEventListener("mousemove", this.boundDragMove);
|
|
516
|
+
(typeof window !== "undefined" ? window : this.canvas).addEventListener(
|
|
517
|
+
"mouseup",
|
|
518
|
+
this.boundDragEnd as EventListener,
|
|
519
|
+
);
|
|
520
|
+
|
|
521
|
+
this.syncFromElement();
|
|
522
|
+
this.afterEditActivity();
|
|
523
|
+
}
|
|
524
|
+
|
|
525
|
+
private onDragMove(e: MouseEvent): void {
|
|
526
|
+
const state = this.state;
|
|
527
|
+
if (!state || this.dragAnchor === null) return;
|
|
528
|
+
|
|
529
|
+
const rect = this.canvas.getBoundingClientRect();
|
|
530
|
+
const offset = this.offsetFromPoint({
|
|
531
|
+
x: e.clientX - rect.left,
|
|
532
|
+
y: e.clientY - rect.top,
|
|
533
|
+
});
|
|
534
|
+
if (offset === null) return;
|
|
535
|
+
|
|
536
|
+
state.element.setSelectionRange?.(
|
|
537
|
+
Math.min(this.dragAnchor, offset),
|
|
538
|
+
Math.max(this.dragAnchor, offset),
|
|
539
|
+
offset < this.dragAnchor ? "backward" : "forward",
|
|
540
|
+
);
|
|
541
|
+
if (this.syncFromElement()) {
|
|
542
|
+
this.afterEditActivity();
|
|
543
|
+
}
|
|
544
|
+
}
|
|
545
|
+
|
|
546
|
+
private onDragEnd(): void {
|
|
547
|
+
if (this.dragAnchor === null) return;
|
|
548
|
+
this.dragAnchor = null;
|
|
549
|
+
this.canvas.removeEventListener("mousemove", this.boundDragMove);
|
|
550
|
+
(typeof window !== "undefined" ? window : this.canvas).removeEventListener(
|
|
551
|
+
"mouseup",
|
|
552
|
+
this.boundDragEnd as EventListener,
|
|
553
|
+
);
|
|
554
|
+
}
|
|
555
|
+
|
|
556
|
+
/** Canvas-space point → character offset in the edited node's value. */
|
|
557
|
+
private offsetFromPoint(point: Point): number | null {
|
|
558
|
+
const state = this.state;
|
|
559
|
+
if (!state) return null;
|
|
560
|
+
|
|
561
|
+
const ctx = this.canvas.getContext("2d");
|
|
562
|
+
const bounds = getScrollAwareBounds(state.node);
|
|
563
|
+
const layout = state.node.layout;
|
|
564
|
+
if (!ctx || !bounds || !layout) return null;
|
|
565
|
+
|
|
566
|
+
const g = this.geometry(
|
|
567
|
+
bounds.x + layout.contentX - state.scrollX,
|
|
568
|
+
bounds.y + layout.contentY,
|
|
569
|
+
);
|
|
570
|
+
return pointToOffset(ctx, g, point);
|
|
571
|
+
}
|
|
572
|
+
|
|
573
|
+
// -------------------------------------------------------------------------
|
|
574
|
+
// Geometry (shared with paintInput via getStateFor + text-geometry)
|
|
575
|
+
// -------------------------------------------------------------------------
|
|
576
|
+
|
|
577
|
+
/**
|
|
578
|
+
* TextGeometry for the edited value at a given content origin. Single-line
|
|
579
|
+
* inputs don't wrap and are middle-aligned; textareas wrap at content
|
|
580
|
+
* width and are top-aligned — both matching how paintInput draws them.
|
|
581
|
+
*/
|
|
582
|
+
geometry(contentX: number, contentY: number): TextGeometry {
|
|
583
|
+
const state = this.state!;
|
|
584
|
+
const isSingleLine = state.node.type.toLowerCase() === "input";
|
|
585
|
+
const g = nodeTextGeometry(state.node, state.value, contentX, contentY, {
|
|
586
|
+
verticalAlign: isSingleLine ? "middle" : "top",
|
|
587
|
+
wrap: !isSingleLine,
|
|
588
|
+
});
|
|
589
|
+
// Inputs always paint left-aligned (paintInput parity).
|
|
590
|
+
g.textAlign = "left";
|
|
591
|
+
return g;
|
|
592
|
+
}
|
|
593
|
+
|
|
594
|
+
/**
|
|
595
|
+
* Position the proxy at the caret in page coordinates so the IME
|
|
596
|
+
* candidate window opens next to the painted text. Called on every edit
|
|
597
|
+
* activity and by the renderer after each frame (layout/scroll changes).
|
|
598
|
+
*/
|
|
599
|
+
syncProxyPosition(): void {
|
|
600
|
+
const state = this.state;
|
|
601
|
+
if (!state) return;
|
|
602
|
+
const el = state.element;
|
|
603
|
+
if (!el.style) return;
|
|
604
|
+
|
|
605
|
+
const canvasBounds = (this.canvas as any).getBoundingClientRect?.();
|
|
606
|
+
if (!canvasBounds) return;
|
|
607
|
+
|
|
608
|
+
const ctx = this.canvas.getContext("2d");
|
|
609
|
+
const bounds = getScrollAwareBounds(state.node);
|
|
610
|
+
const layout = state.node.layout;
|
|
611
|
+
|
|
612
|
+
let x = canvasBounds.left;
|
|
613
|
+
let y = canvasBounds.top;
|
|
614
|
+
let h = 16;
|
|
615
|
+
if (ctx && bounds && layout) {
|
|
616
|
+
const g = this.geometry(
|
|
617
|
+
bounds.x + layout.contentX - state.scrollX,
|
|
618
|
+
bounds.y + layout.contentY,
|
|
619
|
+
);
|
|
620
|
+
const caret = offsetToCaretRect(ctx, g, state.selEnd);
|
|
621
|
+
x += caret.x;
|
|
622
|
+
y += caret.y;
|
|
623
|
+
h = caret.height;
|
|
624
|
+
}
|
|
625
|
+
|
|
626
|
+
// Same page-coordinate math the old overlay used: canvas rect is
|
|
627
|
+
// viewport-relative, absolute positioning is document-relative.
|
|
628
|
+
const sx = typeof window !== "undefined" ? window.scrollX : 0;
|
|
629
|
+
const sy = typeof window !== "undefined" ? window.scrollY : 0;
|
|
630
|
+
Object.assign(el.style, {
|
|
631
|
+
left: `${x + sx}px`,
|
|
632
|
+
top: `${y + sy}px`,
|
|
633
|
+
height: `${h}px`,
|
|
634
|
+
});
|
|
635
|
+
}
|
|
636
|
+
|
|
637
|
+
/**
|
|
638
|
+
* Keep the caret inside the visible content box of single-line inputs by
|
|
639
|
+
* panning `scrollX` (textareas wrap instead).
|
|
640
|
+
*/
|
|
641
|
+
private ensureCaretVisible(): void {
|
|
642
|
+
const state = this.state;
|
|
643
|
+
if (!state) return;
|
|
644
|
+
if (state.node.type.toLowerCase() !== "input") return;
|
|
645
|
+
|
|
646
|
+
const ctx = this.canvas.getContext("2d");
|
|
647
|
+
const layout = state.node.layout;
|
|
648
|
+
if (!ctx || !layout) return;
|
|
649
|
+
|
|
650
|
+
// Content-space geometry (origin 0) — caretX is the caret's distance
|
|
651
|
+
// from the content-box left edge before scrolling.
|
|
652
|
+
const g = this.geometry(0, 0);
|
|
653
|
+
const caretX = offsetToCaretRect(ctx, g, state.selEnd).x;
|
|
654
|
+
const visible = layout.contentWidth;
|
|
655
|
+
|
|
656
|
+
if (caretX - state.scrollX > visible - CARET_SCROLL_MARGIN) {
|
|
657
|
+
state.scrollX = caretX - visible + CARET_SCROLL_MARGIN;
|
|
658
|
+
} else if (caretX - state.scrollX < CARET_SCROLL_MARGIN) {
|
|
659
|
+
state.scrollX = Math.max(0, caretX - CARET_SCROLL_MARGIN);
|
|
660
|
+
}
|
|
661
|
+
if (state.scrollX < 0) state.scrollX = 0;
|
|
662
|
+
}
|
|
663
|
+
|
|
664
|
+
// -------------------------------------------------------------------------
|
|
665
|
+
// Caret blink
|
|
666
|
+
// -------------------------------------------------------------------------
|
|
667
|
+
|
|
668
|
+
private startBlink(): void {
|
|
669
|
+
if (this.blinkIntervalMs <= 0) return;
|
|
670
|
+
this.blinkTimer = setInterval(() => {
|
|
671
|
+
const state = this.state;
|
|
672
|
+
if (!state) return;
|
|
673
|
+
state.caretVisible = !state.caretVisible;
|
|
674
|
+
this.hooks.markDirty(state.node);
|
|
675
|
+
this.hooks.scheduleRedraw();
|
|
676
|
+
}, this.blinkIntervalMs);
|
|
677
|
+
}
|
|
678
|
+
|
|
679
|
+
private stopBlink(): void {
|
|
680
|
+
if (this.blinkTimer !== null) {
|
|
681
|
+
clearInterval(this.blinkTimer);
|
|
682
|
+
this.blinkTimer = null;
|
|
683
|
+
}
|
|
684
|
+
}
|
|
685
|
+
|
|
686
|
+
private restartBlink(): void {
|
|
687
|
+
this.stopBlink();
|
|
688
|
+
this.startBlink();
|
|
689
|
+
}
|
|
690
|
+
|
|
691
|
+
/** Test hook: advance one blink phase without timers. */
|
|
692
|
+
tickBlink(): void {
|
|
693
|
+
const state = this.state;
|
|
694
|
+
if (!state) return;
|
|
695
|
+
state.caretVisible = !state.caretVisible;
|
|
696
|
+
}
|
|
697
|
+
}
|