grayling 0.0.0-stage → 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.
Files changed (55) hide show
  1. package/LICENSE +661 -0
  2. package/README.md +268 -2
  3. package/dist/index.d.ts +290 -0
  4. package/dist/index.js +50 -0
  5. package/dist/node/archive.d.ts +4 -0
  6. package/dist/node/archive.js +115 -0
  7. package/dist/node/client.d.ts +188 -0
  8. package/dist/node/client.js +669 -0
  9. package/dist/node/connection.d.ts +56 -0
  10. package/dist/node/connection.js +240 -0
  11. package/dist/node/errors.d.ts +14 -0
  12. package/dist/node/errors.js +13 -0
  13. package/dist/node/handler.d.ts +56 -0
  14. package/dist/node/handler.js +208 -0
  15. package/dist/node/index.d.ts +15 -0
  16. package/dist/node/index.js +14 -0
  17. package/dist/node/paths.d.ts +51 -0
  18. package/dist/node/paths.js +115 -0
  19. package/dist/node/program.d.ts +74 -0
  20. package/dist/node/program.js +385 -0
  21. package/dist/node/state.d.ts +7 -0
  22. package/dist/node/state.js +12 -0
  23. package/dist/node/suggest.d.ts +13 -0
  24. package/dist/node/suggest.js +87 -0
  25. package/dist/node/types.d.ts +142 -0
  26. package/dist/node/types.js +13 -0
  27. package/dist/node/version.d.ts +10 -0
  28. package/dist/node/version.js +50 -0
  29. package/dist/node/wire.d.ts +32 -0
  30. package/dist/node/wire.js +44 -0
  31. package/dist/react/index.d.ts +121 -0
  32. package/dist/react/index.js +205 -0
  33. package/dist/web/announce.d.ts +51 -0
  34. package/dist/web/announce.js +141 -0
  35. package/dist/web/attach.d.ts +77 -0
  36. package/dist/web/attach.js +89 -0
  37. package/dist/web/box.d.ts +57 -0
  38. package/dist/web/box.js +150 -0
  39. package/dist/web/dom.d.ts +80 -0
  40. package/dist/web/dom.js +265 -0
  41. package/dist/web/index.d.ts +8 -0
  42. package/dist/web/index.js +8 -0
  43. package/dist/web/logic.d.ts +308 -0
  44. package/dist/web/logic.js +467 -0
  45. package/dist/web/overlay.d.ts +56 -0
  46. package/dist/web/overlay.js +211 -0
  47. package/dist/web/style.css +193 -0
  48. package/dist/web/suggester.d.ts +189 -0
  49. package/dist/web/suggester.js +696 -0
  50. package/dist/web/ui.d.ts +65 -0
  51. package/dist/web/ui.js +32 -0
  52. package/dist/web/usage.d.ts +39 -0
  53. package/dist/web/usage.js +84 -0
  54. package/package.json +89 -4
  55. package/program.json +35 -0
@@ -0,0 +1,211 @@
1
+ // What a plain text box shows without a framework: a mirror of the box laid over it (the grey rest of the word and the next
2
+ // word, and the marks on words typed wrong, drawn with the box's own font so that they sit exactly where the text would), and
3
+ // the chips, fixed in the page's body (the right word for one typed wrong, and a word suggested inside a text). React gets
4
+ // the same from react/index.tsx; both follow the same rules (logic.ts: chipsOf, moveSpot, diffLetters).
5
+ import { CLOSE_ICON, DEFAULT_CLASSES, DEFAULT_LABELS } from './ui.js';
6
+ import { LAYER_STYLE, MIRROR_STYLE, followBox, followChip, isTouch, placeChip, placeMirror, segments, typedLetters } from './dom.js';
7
+ import { chipsOf, diffLetters, moveSpot } from './logic.js';
8
+ function el(doc, tag, cls = '', attrs) {
9
+ const e = doc.createElement(tag);
10
+ if (cls)
11
+ e.className = cls;
12
+ for (const [k, v] of Object.entries(attrs ?? {}))
13
+ e.setAttribute(k, v);
14
+ return e;
15
+ }
16
+ const style = (e, s) => Object.assign(e.style, s);
17
+ export class Overlay {
18
+ ta;
19
+ o;
20
+ classes;
21
+ labels;
22
+ doc;
23
+ grey = null;
24
+ marks = null;
25
+ markEl = null;
26
+ caretEl = null;
27
+ chip = null;
28
+ constructor(ta, o) {
29
+ this.ta = ta;
30
+ this.o = o;
31
+ this.classes = { ...DEFAULT_CLASSES, ...o.classes };
32
+ this.labels = { ...DEFAULT_LABELS, ...o.labels };
33
+ this.doc = ta.ownerDocument;
34
+ }
35
+ /** A mirror laid over the box, right after it, and kept there. */
36
+ mirror(cls, attrs, extra = {}) {
37
+ const box = el(this.doc, 'div', cls, { 'aria-hidden': 'true', translate: 'no', ...attrs });
38
+ style(box, { ...MIRROR_STYLE, ...extra });
39
+ this.ta.after(box);
40
+ const place = () => placeMirror(box, this.ta);
41
+ const stop = followBox(place, this.ta);
42
+ return { box, place, stop };
43
+ }
44
+ drop(m) {
45
+ m?.stop();
46
+ m?.box.remove();
47
+ }
48
+ /** The textarea's text, wrapped as it wraps it: its text up to the caret unseen, then the grey words. */
49
+ drawGrey(before, g) {
50
+ const m = (this.grey ??= this.mirror(this.classes.mirror, undefined));
51
+ const hidden = el(this.doc, 'span');
52
+ hidden.style.visibility = 'hidden';
53
+ hidden.textContent = before;
54
+ const tip = el(this.doc, 'span', '', this.o.attributes?.grey);
55
+ const word = el(this.doc, 'span', this.classes.grey);
56
+ word.textContent = g.word;
57
+ tip.append(word);
58
+ if (g.next) {
59
+ const next = el(this.doc, 'span', this.classes.greyNext);
60
+ next.textContent = g.next;
61
+ tip.append(next);
62
+ }
63
+ m.box.replaceChildren(hidden, tip);
64
+ m.place();
65
+ }
66
+ /** Exactly the box's text, its letters unseen, with each word typed wrong marked (so that nothing shifts), and an empty span at the caret where a chip points at. */
67
+ drawMarks(text, marks, fixAt, caret) {
68
+ const m = (this.marks ??= this.mirror(`${this.classes.marks}`, this.o.attributes?.marks, { color: 'transparent' }));
69
+ this.markEl = null;
70
+ this.caretEl = null;
71
+ const parts = [];
72
+ for (const s of segments(text, marks, fixAt, caret)) {
73
+ if ('caret' in s) {
74
+ this.caretEl = el(this.doc, 'span');
75
+ parts.push(this.caretEl);
76
+ }
77
+ else if (s.marked) {
78
+ const e = el(this.doc, 'span', this.classes.mark);
79
+ e.textContent = s.text;
80
+ if (s.first)
81
+ this.markEl = e;
82
+ parts.push(e);
83
+ }
84
+ else
85
+ parts.push(s.text);
86
+ }
87
+ // A textarea has an empty last line after a line break, which a block of text has only when something stands on it.
88
+ if (text.endsWith('\n'))
89
+ parts.push('​');
90
+ m.box.replaceChildren(...parts);
91
+ m.place();
92
+ }
93
+ kbd(label, dim) {
94
+ const k = this.o.kbd ? this.o.kbd(label) : Object.assign(el(this.doc, 'kbd', this.classes.kbd), { textContent: label });
95
+ if (!dim)
96
+ return k;
97
+ const w = el(this.doc, 'span', this.classes.chipDim);
98
+ w.append(k);
99
+ return w;
100
+ }
101
+ part(label, onClick) {
102
+ const b = el(this.doc, 'button', this.classes.chipPart, { type: 'button', tabindex: '-1', 'aria-label': label });
103
+ b.addEventListener('click', onClick);
104
+ return b;
105
+ }
106
+ fixContent(fix) {
107
+ const d = diffLetters(fix.typed, fix.word);
108
+ const box = el(this.doc, 'div', this.classes.chipBox);
109
+ const bar = el(this.doc, 'span', this.classes.chipBar, { 'aria-hidden': 'true' });
110
+ const accept = this.part(this.labels.replace(fix.word), this.o.onAccept);
111
+ const words = el(this.doc, 'span', '', { translate: 'no' });
112
+ const strong = el(this.doc, 'span', this.classes.chipStrong);
113
+ strong.textContent = d.mid;
114
+ words.append(d.pre, strong, d.post);
115
+ accept.append(words);
116
+ if (!isTouch())
117
+ accept.append(this.kbd(this.labels.tab(), !fix.tab));
118
+ const close = el(this.doc, 'button', this.classes.chipClose, { type: 'button', tabindex: '-1', 'aria-label': this.labels.keep() });
119
+ close.innerHTML = CLOSE_ICON;
120
+ close.addEventListener('click', this.o.onKeep);
121
+ box.append(bar, accept, close);
122
+ return box;
123
+ }
124
+ midContent(typed, word) {
125
+ const box = el(this.doc, 'div', this.classes.chipBox);
126
+ const take = this.part(this.labels.complete(typed + word), this.o.onTake);
127
+ const words = el(this.doc, 'span', '', { translate: 'no' });
128
+ const t = el(this.doc, 'span', this.classes.chipTyped);
129
+ t.textContent = typed;
130
+ const r = el(this.doc, 'span', this.classes.chipRest);
131
+ r.textContent = word;
132
+ words.append(t, r);
133
+ take.append(words);
134
+ if (!isTouch())
135
+ take.append(this.kbd(this.labels.tab(), false));
136
+ box.append(take);
137
+ return box;
138
+ }
139
+ /** A chip's fixed layer: one kind at a time (a new kind replaces the one before). */
140
+ showChip(kind, content, anchor) {
141
+ if (this.chip && this.chip.kind !== kind)
142
+ this.dropChip();
143
+ let c = this.chip;
144
+ if (!c) {
145
+ // Hidden from screen readers: the box's own text is what is read, and `announce` says what is suggested (announce.ts).
146
+ const layer = el(this.doc, 'div', this.classes.layer, { 'data-grayling-chip': '', 'aria-hidden': 'true', ...this.o.attributes?.chip });
147
+ style(layer, LAYER_STYLE);
148
+ // Never takes the focus: a press on it must leave the caret where it is in the box.
149
+ const keep = (e) => e.preventDefault();
150
+ layer.addEventListener('pointerdown', keep);
151
+ layer.addEventListener('mousedown', keep);
152
+ const inner = el(this.doc, 'div', this.classes.chip);
153
+ layer.append(inner);
154
+ this.doc.body.append(layer);
155
+ const place = () => this.chip && placeChip(this.chip.layer, this.chip.anchor(), this.ta);
156
+ const f = followChip(layer, () => this.ta, place);
157
+ c = this.chip = { kind, layer, inner, anchor, place, stop: f.stop };
158
+ }
159
+ c.anchor = anchor;
160
+ c.inner.replaceChildren(content);
161
+ c.place();
162
+ }
163
+ dropChip() {
164
+ this.chip?.stop();
165
+ this.chip?.layer.remove();
166
+ this.chip = null;
167
+ }
168
+ static rectOf(n) {
169
+ return n?.isConnected ? (n.getClientRects()[0] ?? n.getBoundingClientRect()) : null;
170
+ }
171
+ /** Draw what the suggester told, with the box's text as it is now. `known` is the text the places in `shown` are in. */
172
+ update(shown, known) {
173
+ if (!shown)
174
+ return this.clear();
175
+ const { v, before } = shown;
176
+ const { fix, mid } = chipsOf(v);
177
+ const text = this.ta.value;
178
+ // A letter typed since the box was last read moves the words after it: drawn with them, not a letter off until it is read again.
179
+ const marks = v.marks.flatMap((m) => moveSpot(m, known, text) ?? []);
180
+ if (v.grey && !v.mid)
181
+ this.drawGrey(before, v.grey);
182
+ else
183
+ (this.drop(this.grey), (this.grey = null));
184
+ if (marks.length > 0 || mid)
185
+ this.drawMarks(text, marks, fix ? (moveSpot(fix, known, text)?.start ?? null) : null, mid ? before.length : null);
186
+ else
187
+ (this.drop(this.marks), (this.marks = null), (this.markEl = this.caretEl = null));
188
+ if (fix)
189
+ this.showChip('fix', this.fixContent(fix), () => Overlay.rectOf(this.markEl));
190
+ else if (mid)
191
+ this.showChip('mid', this.midContent(typedLetters(before), mid.word), () => Overlay.rectOf(this.caretEl));
192
+ else
193
+ this.dropChip();
194
+ }
195
+ /** Nothing shows. */
196
+ clear() {
197
+ this.drop(this.grey);
198
+ this.drop(this.marks);
199
+ this.grey = this.marks = this.markEl = this.caretEl = null;
200
+ this.dropChip();
201
+ }
202
+ /** Put the layers where they belong again (the box moved or changed). */
203
+ place() {
204
+ this.grey?.place();
205
+ this.marks?.place();
206
+ this.chip?.place();
207
+ }
208
+ destroy() {
209
+ this.clear();
210
+ }
211
+ }
@@ -0,0 +1,193 @@
1
+ /*
2
+ * The default look of grayling's text-box code (`grayling/web` and `grayling/react`): the grey words after the caret, the
3
+ * marks on words typed wrong, and the chips. Every colour is a custom property, so change them on :root (or give the
4
+ * elements your own class names with the `classes` option). The class `grayling-box`, which a text box carries while
5
+ * suggestions are on in it, has no look: it only tells other programs "leave this box alone".
6
+ *
7
+ * Light by default; dark with prefers-color-scheme. To force one, set data-grayling-theme="dark" (or "light") on <html>.
8
+ */
9
+ :root {
10
+ --grayling-grey: #8b9099;
11
+ --grayling-grey-next: color-mix(in srgb, var(--grayling-grey) 55%, transparent);
12
+ --grayling-warn: #d97706;
13
+ --grayling-chip-bg: #ffffff;
14
+ --grayling-chip-line: #d3d6dc;
15
+ --grayling-chip-fg: #4b5260;
16
+ --grayling-chip-fg-strong: #14161a;
17
+ --grayling-chip-muted: #7a808c;
18
+ --grayling-chip-hover: #f0f1f4;
19
+ --grayling-chip-shadow: 0 1px 4px rgb(0 0 0 / 0.18);
20
+ --grayling-chip-radius: 8px;
21
+ --grayling-chip-font-size: 13px;
22
+ --grayling-kbd-bg: #f3f4f6;
23
+ --grayling-kbd-line: #d3d6dc;
24
+ }
25
+
26
+ @media (prefers-color-scheme: dark) {
27
+ :root {
28
+ --grayling-grey: #7a808b;
29
+ --grayling-warn: #f5a524;
30
+ --grayling-chip-bg: #24272c;
31
+ --grayling-chip-line: #3b3f46;
32
+ --grayling-chip-fg: #c4c8cf;
33
+ --grayling-chip-fg-strong: #f3f4f6;
34
+ --grayling-chip-muted: #8e939d;
35
+ --grayling-chip-hover: #2e3238;
36
+ --grayling-chip-shadow: 0 1px 6px rgb(0 0 0 / 0.5);
37
+ --grayling-kbd-bg: #1b1d21;
38
+ --grayling-kbd-line: #444850;
39
+ }
40
+ }
41
+
42
+ :root[data-grayling-theme='dark'] {
43
+ --grayling-grey: #7a808b;
44
+ --grayling-warn: #f5a524;
45
+ --grayling-chip-bg: #24272c;
46
+ --grayling-chip-line: #3b3f46;
47
+ --grayling-chip-fg: #c4c8cf;
48
+ --grayling-chip-fg-strong: #f3f4f6;
49
+ --grayling-chip-muted: #8e939d;
50
+ --grayling-chip-hover: #2e3238;
51
+ --grayling-chip-shadow: 0 1px 6px rgb(0 0 0 / 0.5);
52
+ --grayling-kbd-bg: #1b1d21;
53
+ --grayling-kbd-line: #444850;
54
+ }
55
+
56
+ :root[data-grayling-theme='light'] {
57
+ --grayling-grey: #8b9099;
58
+ --grayling-warn: #d97706;
59
+ --grayling-chip-bg: #ffffff;
60
+ --grayling-chip-line: #d3d6dc;
61
+ --grayling-chip-fg: #4b5260;
62
+ --grayling-chip-fg-strong: #14161a;
63
+ --grayling-chip-muted: #7a808c;
64
+ --grayling-chip-hover: #f0f1f4;
65
+ --grayling-chip-shadow: 0 1px 4px rgb(0 0 0 / 0.18);
66
+ --grayling-kbd-bg: #f3f4f6;
67
+ --grayling-kbd-line: #d3d6dc;
68
+ }
69
+
70
+ /* The grey words: the rest of the word being typed, and the next word, dimmer. */
71
+ .grayling-grey {
72
+ color: var(--grayling-grey);
73
+ }
74
+ .grayling-grey-next {
75
+ color: var(--grayling-grey-next);
76
+ }
77
+
78
+ /* A word typed wrong: a faint tint, and a dotted line under it. */
79
+ .grayling-mark {
80
+ background: color-mix(in srgb, var(--grayling-warn) 16%, transparent);
81
+ text-decoration-line: underline;
82
+ text-decoration-style: dotted;
83
+ text-decoration-color: var(--grayling-warn);
84
+ text-decoration-thickness: 2px;
85
+ text-underline-offset: 2px;
86
+ border-radius: 3px;
87
+ }
88
+
89
+ /* The chip: a short fade and rise (not with reduced motion). */
90
+ .grayling-chip {
91
+ font-size: var(--grayling-chip-font-size);
92
+ line-height: 1;
93
+ color: var(--grayling-chip-fg);
94
+ }
95
+ @keyframes grayling-chip-in {
96
+ from {
97
+ opacity: 0;
98
+ transform: translateY(3px);
99
+ }
100
+ to {
101
+ opacity: 1;
102
+ transform: none;
103
+ }
104
+ }
105
+ @media (prefers-reduced-motion: no-preference) {
106
+ .grayling-chip {
107
+ animation: grayling-chip-in 120ms ease-out both;
108
+ }
109
+ }
110
+
111
+ .grayling-chip-box {
112
+ display: flex;
113
+ align-items: stretch;
114
+ overflow: hidden;
115
+ border: 1px solid var(--grayling-chip-line);
116
+ border-radius: var(--grayling-chip-radius);
117
+ background: var(--grayling-chip-bg);
118
+ box-shadow: var(--grayling-chip-shadow);
119
+ }
120
+ .grayling-chip-bar {
121
+ flex: none;
122
+ width: 3px;
123
+ background: var(--grayling-warn);
124
+ }
125
+ .grayling-chip-part {
126
+ display: flex;
127
+ align-items: center;
128
+ gap: 8px;
129
+ min-height: 28px;
130
+ padding: 0 10px;
131
+ margin: 0;
132
+ border: 0;
133
+ background: none;
134
+ color: inherit;
135
+ font: inherit;
136
+ line-height: 1;
137
+ cursor: pointer;
138
+ }
139
+ .grayling-chip-part:hover,
140
+ .grayling-chip-close:hover {
141
+ background: var(--grayling-chip-hover);
142
+ }
143
+ .grayling-chip-strong {
144
+ font-weight: 600;
145
+ color: var(--grayling-chip-fg-strong);
146
+ }
147
+ .grayling-chip-typed {
148
+ color: var(--grayling-chip-fg-strong);
149
+ }
150
+ .grayling-chip-rest {
151
+ color: var(--grayling-grey);
152
+ }
153
+ .grayling-chip-dim {
154
+ display: inline-flex;
155
+ opacity: 0.4;
156
+ }
157
+ .grayling-chip-close {
158
+ display: flex;
159
+ align-items: center;
160
+ justify-content: center;
161
+ min-width: 24px;
162
+ padding: 0 6px 0 4px;
163
+ margin: 0;
164
+ border: 0;
165
+ background: none;
166
+ color: var(--grayling-chip-muted);
167
+ cursor: pointer;
168
+ }
169
+ .grayling-chip-close:hover {
170
+ color: var(--grayling-chip-fg-strong);
171
+ }
172
+ .grayling-kbd {
173
+ display: inline-flex;
174
+ align-items: center;
175
+ height: 18px;
176
+ padding: 0 5px;
177
+ border: 1px solid var(--grayling-kbd-line);
178
+ border-radius: 4px;
179
+ background: var(--grayling-kbd-bg);
180
+ color: var(--grayling-chip-muted);
181
+ font: 600 10px/1 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
182
+ }
183
+
184
+ /* A phone or a tablet: bigger buttons, and the chip is the button (the key is not shown). */
185
+ @media (hover: none) {
186
+ .grayling-chip-part {
187
+ min-height: 40px;
188
+ padding: 0 12px;
189
+ }
190
+ .grayling-chip-close {
191
+ min-width: 40px;
192
+ }
193
+ }
@@ -0,0 +1,189 @@
1
+ import type { SuggestCounts, SuggestPlan, SuggestRequest, SuggestResponse } from '../index.js';
2
+ import { type Field, type Gate, type Grey, type Mark, type Place, type View } from './logic.js';
3
+ /** What the box is to the suggester. */
4
+ export interface Adapter {
5
+ place: Place;
6
+ /** The box as it is now, or null when it has no caret (not focused, gone). */
7
+ read(): Field | null;
8
+ /** Put text at the caret, the way typing it would (so that undo works). */
9
+ insert(text: string): void;
10
+ /**
11
+ * Put `word` in place of the stretch from `start` to `end` of the text (before + after the caret), as one change that can be
12
+ * undone, and keep the caret where it was in relation to the text after it. false when it could not be done.
13
+ */
14
+ replace(start: number, end: number, word: string): boolean | void;
15
+ /** What goes with the text before the caret: the reply being answered, the document before the paragraph, the session. */
16
+ context(): {
17
+ reply?: string;
18
+ prev?: string;
19
+ doc?: string;
20
+ session?: string;
21
+ };
22
+ }
23
+ export declare const DEBOUNCE_MS = 30;
24
+ /** The caret must rest this long in a word, which it came to by a caret move, before the word is checked. */
25
+ export declare const REST_MS = 500;
26
+ /** A request out this long is given up on at the next keystroke (a connection that hangs must not hold the box). */
27
+ export declare const MAX_FLIGHT_MS = 3000;
28
+ /** What the suggester needs from outside: the request, the switches, and this client's id (one per browser tab). */
29
+ export interface Outside {
30
+ send: (req: SuggestRequest, signal: AbortSignal) => Promise<SuggestResponse | null>;
31
+ gate: () => Gate;
32
+ client: string;
33
+ /** Told what suggestions did, as counts only (batch them, for example with `UsageBatch`). */
34
+ count?: (c: Partial<SuggestCounts>) => void;
35
+ /** Told whether a guess, shown or not, was right: how sure it was and which plan made it, never the word. */
36
+ judge?: (plan: SuggestPlan, conf: number, right: boolean) => void;
37
+ /** Told which word the person kept as typed (Esc on its fix): the engine never offers it as a typo again. */
38
+ keep?: (word: string) => void;
39
+ /** How long the caret rests before its word is checked (ms; REST_MS). */
40
+ rest?: number;
41
+ }
42
+ export declare class Suggester {
43
+ private ad;
44
+ private on;
45
+ private out;
46
+ grey: Grey | null;
47
+ /** The grey word showing is a suggestion inside a text. */
48
+ mid: boolean;
49
+ /** What was last told (the view). */
50
+ view: View;
51
+ /** The text its places are in: the box's when it was last read. */
52
+ text: string;
53
+ /** The words typed wrong that were found, in every box this one controls (an editor: every paragraph). */
54
+ marks: Mark[];
55
+ /** Esc hid what shows: nothing shows until the next word begins. */
56
+ private hidden;
57
+ private last;
58
+ private timer;
59
+ /** An ask for the word at the caret is waiting for its pause to end. */
60
+ private waiting;
61
+ /** The pause before a fix of its own is asked for (punctuation typed, or the caret at rest). */
62
+ private fixTimer;
63
+ /** That pause is for a word just ended. */
64
+ private endedDue;
65
+ /** The box as it was when the word at the caret was last asked for (its answer may hold a fix: no other is needed there). */
66
+ private allAt;
67
+ /** A fix of its own is wanted but a request is out: it is asked for when that answers. */
68
+ private fixWait;
69
+ /** The request under way: what the box was when it was sent. */
70
+ private flight;
71
+ /** The box as it was when it lost the focus. */
72
+ private away;
73
+ private inserting;
74
+ /** The grey word showing is a suggestion that has been counted as shown and has no outcome yet. */
75
+ private live;
76
+ /** The person typed letters of what shows: an answer with nothing to show leaves it. */
77
+ private confirmed;
78
+ /** The guesses waiting for the word to be finished, and the one of them whose letters show. */
79
+ private guesses;
80
+ private shownGuess;
81
+ /** The caret's place: whether a word is put in before another, and whether something was typed there. */
82
+ private place;
83
+ /** The marks the caret has left (moved away from, or gone on by more than 6 words): their chip shows again only when the caret is in them. */
84
+ private passed;
85
+ /** The words kept as typed in this box (lower case): never marked again. */
86
+ private kept;
87
+ /** Where a word still being typed was kept: however it goes on there, it is not marked again. */
88
+ private keptAt;
89
+ /** The fixes counted as shown (typed, word and what stood before it). */
90
+ private shownFixes;
91
+ /** The words the caret rested at (the 16 characters before and the word) that were asked about. */
92
+ private asked;
93
+ private seq;
94
+ private told;
95
+ constructor(ad: Adapter, on: (v: View) => void, out: Outside);
96
+ /** Which marks stand in the box as it is (`f`), with where. */
97
+ private placed;
98
+ /** The mark whose chip shows now, if any. */
99
+ private current;
100
+ /** A fix's chip shows for the word the caret is in or right after: Tab is its, and no word is suggested inside a text there. */
101
+ private fixHere;
102
+ /** What the box shows now, told to whoever draws it when any of it changed. */
103
+ private publish;
104
+ /** Count what suggestions did; a suggestion inside a text counts in the keys of its own. */
105
+ private count;
106
+ private show;
107
+ /** A new suggestion is showing (inside a text, or at its end): counted as shown, and waiting for what the person does with it. */
108
+ private began;
109
+ /** The suggestion showing has an outcome (taken, typed through, or something else typed): its guess is judged so. */
110
+ private verdict;
111
+ /** Keep the guess an answer about `asked` holds, to be judged (one per place in the word: a later one replaces it). */
112
+ private note;
113
+ /** The letters showing are the rest of `g`'s word (`typed` of it typed already): their outcome judges it. */
114
+ private link;
115
+ /** Judge the guesses whose word the person has finished by now. */
116
+ private judgeGuesses;
117
+ /** No verdict for the guesses waiting (a deletion, a caret move, a paste, the box gone). */
118
+ private forget;
119
+ /** The request under way is no longer wanted: its answer is not waited for, and the engine stops working on it. */
120
+ private cancel;
121
+ /** A request that had no answer: the word the caret rested at may be asked about again. */
122
+ private unasked;
123
+ /** Every mark goes (the switch was turned off). */
124
+ private dropMarks;
125
+ /** Stop what is under way and show nothing (a blur, a switch turned off, the box gone). The marks stay: they show again when the box has the focus. */
126
+ reset(): void;
127
+ /** The box may have changed: keep what shows if the person typed exactly its letters, else ask again. */
128
+ sync(): void;
129
+ /**
130
+ * After a change of the box: the marks that no longer stand in it are gone (a box that was emptied has none), and the ones the
131
+ * caret has left (moved away from, or gone on from by more than 6 words or a line) are passed: their chip shows again only when
132
+ * the caret is in them.
133
+ */
134
+ private marksMoved;
135
+ /** Whether words typed wrong are looked for here now. */
136
+ private fixOn;
137
+ /**
138
+ * Ask for a fix of its own after punctuation was typed right after a word (at the usual pause; a space too, where the word
139
+ * at the caret is not asked for, whose answer would hold the fix), or once the caret has rested (REST_MS) in or at the end of a
140
+ * word that it came to by a caret move.
141
+ */
142
+ private fixSchedule;
143
+ private fixFire;
144
+ /** A request has answered: a fix of its own that waited for it goes now, unless the word at the caret is asked for (its answer has the fix too). */
145
+ private afterFlight;
146
+ /** Where a word may be suggested now: at the end of a text, inside it, or nowhere. */
147
+ private spot;
148
+ /**
149
+ * Ask for a suggestion at the caret, after a pause of 30 ms. `keep`: what shows stays until the answer. While a
150
+ * request is under way none is sent: its answer asks about the box as it is then.
151
+ */
152
+ private ask;
153
+ /** Send a request for the box as it is: the word at the caret (and a fix), or a fix alone (`key`: of the word the caret rests at). */
154
+ private fly;
155
+ /**
156
+ * An answer about the box as it was (`asked`): shown if the box is still so; what is left of it if the person has
157
+ * since typed letters of its grey word; else dropped. A box that has moved on is asked about again. A fix in it is taken
158
+ * when the word still stands where it was found.
159
+ */
160
+ private answered;
161
+ /** An answer for the box as it is now. */
162
+ private apply;
163
+ /**
164
+ * The fix an answer holds becomes a mark when, in the text as it was asked about, the word stands where it says and it still
165
+ * stands in the box now; an answer for the same place with no fix takes away the open mark there (a closed one stays). No answer
166
+ * at all (the models are loading, the request was dropped) changes nothing.
167
+ */
168
+ private takeFix;
169
+ private removeMark;
170
+ /** The right word goes in the place of the word at the caret (Tab, or a tap on its chip), and the box is read again. */
171
+ accept(): undefined;
172
+ /** The word is kept as it stands (Esc, or the chip's ×): its mark goes, and it is never marked again in this box, nor by the engine. */
173
+ keep(): void;
174
+ /** A key press, before the box's own handling: true when it was taken (Tab, → at the end, Esc). */
175
+ key(e: {
176
+ key: string;
177
+ shiftKey: boolean;
178
+ ctrlKey: boolean;
179
+ metaKey: boolean;
180
+ altKey: boolean;
181
+ isComposing?: boolean;
182
+ preventDefault(): void;
183
+ stopPropagation(): void;
184
+ }): boolean;
185
+ /** What Tab does with the grey word (also a tap on the chip of one inside a text): takes the word, and the next one becomes the one shown. */
186
+ tab(): void;
187
+ /** Put what was taken in the box, and show what follows it. */
188
+ private take;
189
+ }