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,87 @@
1
+ import { snake } from './wire.js';
2
+ const num = (v) => (typeof v === 'number' && Number.isFinite(v) ? v : 0);
3
+ /** The `suggest` request as it goes over the wire. `tab`: a newer request of the same tab drops the one before it. */
4
+ export function suggestToWire(req, tab) {
5
+ const w = { surface: req.surface, text: req.text };
6
+ for (const k of ['reply', 'prev', 'doc', 'session', 'after'])
7
+ if (req[k] !== undefined)
8
+ w[k] = req[k];
9
+ if (req.apart)
10
+ w.apart = true;
11
+ if (req.want)
12
+ w.want = req.want;
13
+ w.fix = req.fix ?? true;
14
+ w.precision = req.precision ?? 0.2;
15
+ for (const k of ['next', 'cache', 'switch', 'typedWords', 'contextWords'])
16
+ if (req[k] !== undefined)
17
+ w[snake(k)] = req[k];
18
+ const t = tab ?? req.client;
19
+ if (t)
20
+ w.tab = t;
21
+ return w;
22
+ }
23
+ /** A word typed wrong, when it is whole: the host's words are checked again, as a page must not be sent half a fix. */
24
+ function fixOf(f) {
25
+ if (!f || typeof f !== 'object')
26
+ return undefined;
27
+ const { back, typed, word, conf, open } = f;
28
+ const text = (v) => typeof v === 'string' && v.length > 0 && [...v].length <= 64;
29
+ if (typeof back !== 'number' || !Number.isInteger(back) || back < 0)
30
+ return undefined;
31
+ if (!text(typed) || !text(word) || typed === word)
32
+ return undefined;
33
+ if (typeof conf !== 'number' || !Number.isFinite(conf) || conf < 0 || conf > 1)
34
+ return undefined;
35
+ return { back, typed, word, conf, ...(open === true ? { open: true } : {}) };
36
+ }
37
+ /** The host's answer (`{"none": why}` or an `Answer`) as the response a text box takes. */
38
+ export function outcomeFromWire(a, req) {
39
+ if (typeof a.none === 'string')
40
+ return { response: null, why: a.none };
41
+ const next = req.next !== false && typeof a.next === 'string' ? a.next : '';
42
+ const out = {
43
+ word: typeof a.word === 'string' ? a.word : '',
44
+ next,
45
+ conf: num(a.conf),
46
+ confNext: next ? num(a.conf_next) : 0,
47
+ show: !!a.show,
48
+ showNext: !!a.show && !!a.show_next && !!next,
49
+ };
50
+ if (a.plan === 'mix' || a.plan === 'llm' || a.plan === 'slm')
51
+ out.plan = a.plan;
52
+ if (typeof a.lang === 'string' && a.lang)
53
+ out.lang = a.lang;
54
+ if (a.model === 'base' || a.model === 'personal')
55
+ out.model = a.model;
56
+ const fix = fixOf(a.fix);
57
+ if (fix)
58
+ out.fix = fix;
59
+ const ms = a.ms && typeof a.ms === 'object' ? num(a.ms.total) : 0;
60
+ if (ms)
61
+ out.ms = ms;
62
+ return { response: out };
63
+ }
64
+ /**
65
+ * What an app's own settings make of a request, as Hydor's service does: false when nothing is to be suggested (suggestions are
66
+ * off, or off where the request comes from, or the word inside a text / the fix alone is off), else the options of the request.
67
+ */
68
+ export function optionsFor(s, req) {
69
+ if (!s.enabled)
70
+ return false;
71
+ const w = s.where;
72
+ if (!(req.surface === 'chat' ? w.chat : req.surface === 'doc' ? w.docs : w.other || w.notes))
73
+ return false;
74
+ if (req.want === 'fix' ? !s.fixTypos : req.after !== undefined && !s.midText)
75
+ return false;
76
+ // Inside a text (with the word to fit before what follows): no next word, no session cache.
77
+ const inside = req.after !== undefined && req.want !== 'fix';
78
+ return {
79
+ fix: s.fixTypos,
80
+ precision: s.precision,
81
+ next: s.nextWord && !inside,
82
+ cache: s.sessionCache && req.surface === 'chat' && !!req.session && !inside,
83
+ switch: s.switchByLanguage,
84
+ typedWords: s.typedWords,
85
+ contextWords: s.contextWords,
86
+ };
87
+ }
@@ -0,0 +1,142 @@
1
+ import type { SuggestCounts, SuggestJudged, SuggestRequest, SuggestSettings, SuggestStatus, SuggestThresholds, SuggestUsage } from '../index.js';
2
+ /**
3
+ * The settings the engine host keeps for everybody (`<data>/settings.json`). They are the fields of `SuggestSettings` that
4
+ * belong to the engine; the rest of `SuggestSettings` (`enabled`, `where`, `precision`, `nextWord`, `midText`, `fixTypos`,
5
+ * `typedWords`, `contextWords`, `switchByLanguage`, `sessionCache`, `sources`) is the app's own and is sent with each request
6
+ * (`GraylingRequestOptions`) or never leaves the app.
7
+ */
8
+ export type GraylingSettings = Pick<SuggestSettings, 'llm' | 'quant' | 'threads' | 'personalise' | 'schedule' | 'userWeight' | 'trainThreads' | 'trainGpu'>;
9
+ /** The names of `GraylingSettings`, to pick them out of a patch of the app's whole settings. */
10
+ export declare const GRAYLING_SETTING_KEYS: readonly ["llm", "quant", "threads", "personalise", "schedule", "userWeight", "trainThreads", "trainGpu"];
11
+ /** What the host's settings were before anything was changed. */
12
+ export declare const GRAYLING_SETTING_DEFAULTS: GraylingSettings;
13
+ /** `SuggestStatus` as the host says it (the same shape), and the engine's version. `usage` and `thresholds` are this client's. */
14
+ export type GraylingStatus = SuggestStatus & {
15
+ engine: string;
16
+ };
17
+ /** The settings and the status, as the `state` answer and the `state` event give them. */
18
+ export interface GraylingState {
19
+ settings: GraylingSettings;
20
+ status: GraylingStatus;
21
+ }
22
+ /** A program that shows suggestions of its own (claimed, so that the desktop app leaves it alone). */
23
+ export interface ClaimedApp {
24
+ /** macOS: `com.hydor.app` */
25
+ bundle?: string;
26
+ /** Windows and Linux: `Hydor` */
27
+ exe?: string;
28
+ /** Linux: `hydor` */
29
+ wmClass?: string;
30
+ }
31
+ /** What a request may say besides the text: the app's own settings for this one request. */
32
+ export interface GraylingRequestOptions {
33
+ /** Look for a word typed wrong too (default true). */
34
+ fix?: boolean;
35
+ /** How sure a suggestion must be to show: 0.2 (more of them) … 0.6 (surer ones) (default 0.2). */
36
+ precision?: number;
37
+ /** The next word too (default: the host's). */
38
+ next?: boolean;
39
+ /** Use the chat session's earlier text for the cache (see `session`). */
40
+ cache?: boolean;
41
+ /** Choose per language between the language model alone and the mix. */
42
+ switch?: boolean;
43
+ /** Words of the typed text read before the caret. */
44
+ typedWords?: number;
45
+ /** Words of the reply or the document read. */
46
+ contextWords?: number;
47
+ }
48
+ /** A request to suggest: the `SuggestRequest` a text box sends, and the app's options for it. */
49
+ export type GraylingSuggestRequest = SuggestRequest & GraylingRequestOptions;
50
+ /** Why there was no suggestion (`unavailable`: no connection to the host, `aborted`: the caller gave up). */
51
+ export type NoneWhy = 'starting' | 'dropped' | 'memory' | 'failed' | 'off' | 'elsewhere' | 'unavailable' | 'aborted' | 'timeout' | (string & {});
52
+ /** What `suggestRaw` gives: the response, or null and why. */
53
+ export interface SuggestOutcome<R> {
54
+ response: R | null;
55
+ why?: NoneWhy;
56
+ }
57
+ /** Counts of a report, and what the host made of them. */
58
+ export interface UsageAnswer {
59
+ usage: SuggestUsage;
60
+ thresholds: SuggestThresholds;
61
+ }
62
+ export interface HostClient {
63
+ client: string;
64
+ instance: string;
65
+ version: string;
66
+ since: number;
67
+ }
68
+ /** `info`: the host's process, folders and clients. */
69
+ export interface HostInfo {
70
+ pid: number;
71
+ engine: string;
72
+ data: string;
73
+ cache: string;
74
+ clients: HostClient[];
75
+ workerMb?: number;
76
+ llamaPid?: number;
77
+ log: string;
78
+ }
79
+ /** What the host said in hello. */
80
+ export interface HostHello {
81
+ protocol: number;
82
+ engine: string;
83
+ pid: number;
84
+ }
85
+ /** What an earlier Hydor kept for itself (`adopt`): usage, judged guesses, kept words and settings as it kept them, and folders. */
86
+ export interface AdoptWhat {
87
+ usage?: unknown;
88
+ judged?: unknown;
89
+ kept?: unknown;
90
+ settings?: unknown;
91
+ personal?: string;
92
+ llama?: string;
93
+ venv?: string;
94
+ venvGpu?: string;
95
+ models?: string[];
96
+ }
97
+ export type LearnAction = 'now' | 'pause' | 'stop' | 'forget';
98
+ /** A line of the texts a provider hands over for learning (written as JSON lines). */
99
+ export interface TextLine {
100
+ kind: 'user' | 'agent' | 'doc';
101
+ text: string;
102
+ /** Milliseconds since 1970. */
103
+ ts: number;
104
+ session?: string;
105
+ reply?: string;
106
+ }
107
+ /** How many texts there are of each kind, and how many of the person's own are newer than `freshSince`. */
108
+ export interface TextCounts {
109
+ user: number;
110
+ agent: number;
111
+ doc: number;
112
+ fresh: number;
113
+ }
114
+ /** What a learning run asks a provider for. */
115
+ export interface TextsJob {
116
+ /** An empty private file that exists: the texts go in it as JSON lines (`TextLine`), later than `since`, not later than `until`. */
117
+ file: string;
118
+ since: number;
119
+ until: number;
120
+ freshSince: number;
121
+ /** Aborted after ten minutes, the most a provider has. */
122
+ signal: AbortSignal;
123
+ }
124
+ /**
125
+ * Hands over the texts for learning. Either write `file` yourself and return the counts, or return the lines (an array, an
126
+ * iterable or an async iterable of `TextLine`) and the client writes them and counts them. Throwing tells the host it failed.
127
+ */
128
+ export type TextsProvider = (job: TextsJob) => TextCounts | Iterable<TextLine> | AsyncIterable<TextLine> | Promise<TextCounts | Iterable<TextLine> | AsyncIterable<TextLine>>;
129
+ /** The events of a `Grayling`. */
130
+ export interface GraylingEvents {
131
+ /** The host's state changed (at most every 150 ms); also sent after a reconnect. */
132
+ state: GraylingState;
133
+ /** The programs claimed by every connected client changed. */
134
+ claims: ClaimedApp[];
135
+ /** Connected (the first time, and after each reconnect). */
136
+ connect: HostHello;
137
+ /** The connection ended; it connects again by itself unless the client was closed. */
138
+ disconnect: {
139
+ reason: string;
140
+ };
141
+ }
142
+ export type { SuggestCounts, SuggestJudged };
@@ -0,0 +1,13 @@
1
+ /** The names of `GraylingSettings`, to pick them out of a patch of the app's whole settings. */
2
+ export const GRAYLING_SETTING_KEYS = ['llm', 'quant', 'threads', 'personalise', 'schedule', 'userWeight', 'trainThreads', 'trainGpu'];
3
+ /** What the host's settings were before anything was changed. */
4
+ export const GRAYLING_SETTING_DEFAULTS = {
5
+ llm: 'auto',
6
+ quant: 'q8',
7
+ threads: 0,
8
+ personalise: true,
9
+ schedule: 'nightly',
10
+ userWeight: 4,
11
+ trainThreads: 0,
12
+ trainGpu: true,
13
+ };
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Compares two versions such as `0.124.0` and `0.2.0-rc1` (the same rule as `version_cmp` in
3
+ * crates/grayling-protocol/src/messages.rs): the numbers in order (a missing one is 0), and with all equal a version with a
4
+ * suffix (`-rc1`) is older than the plain one. Returns -1, 0 or 1.
5
+ */
6
+ export declare function versionCmp(a: string, b: string): -1 | 0 | 1;
7
+ /** The folder of this package (the one with the package.json named `grayling`), wherever this file is compiled to. */
8
+ export declare function packageRoot(): string;
9
+ /** This package's version: the version of the `grayling` program it goes with. */
10
+ export declare function packageVersion(): string;
@@ -0,0 +1,50 @@
1
+ import { readFileSync } from 'node:fs';
2
+ import { dirname, join } from 'node:path';
3
+ import { fileURLToPath } from 'node:url';
4
+ /**
5
+ * Compares two versions such as `0.124.0` and `0.2.0-rc1` (the same rule as `version_cmp` in
6
+ * crates/grayling-protocol/src/messages.rs): the numbers in order (a missing one is 0), and with all equal a version with a
7
+ * suffix (`-rc1`) is older than the plain one. Returns -1, 0 or 1.
8
+ */
9
+ export function versionCmp(a, b) {
10
+ const split = (v) => {
11
+ v = v.trim().replace(/^v+/, '');
12
+ const i = v.search(/[-+]/);
13
+ const core = i < 0 ? v : v.slice(0, i);
14
+ const suffix = i >= 0 && v[i] === '-';
15
+ return [core.split('.').map((p) => (/^\d+$/.test(p) ? Number(p) : 0)), suffix];
16
+ };
17
+ const [x, xs] = split(a);
18
+ const [y, ys] = split(b);
19
+ for (let i = 0; i < Math.max(x.length, y.length); i++) {
20
+ const p = x[i] ?? 0;
21
+ const q = y[i] ?? 0;
22
+ if (p !== q)
23
+ return p < q ? -1 : 1;
24
+ }
25
+ // All numbers equal: with a suffix is older.
26
+ return xs === ys ? 0 : xs ? -1 : 1;
27
+ }
28
+ let root;
29
+ /** The folder of this package (the one with the package.json named `grayling`), wherever this file is compiled to. */
30
+ export function packageRoot() {
31
+ if (root)
32
+ return root;
33
+ let dir = dirname(fileURLToPath(import.meta.url));
34
+ for (let i = 0; i < 6; i++) {
35
+ try {
36
+ const j = JSON.parse(readFileSync(join(dir, 'package.json'), 'utf8'));
37
+ if (j.name === 'grayling')
38
+ return (root = dir);
39
+ }
40
+ catch {
41
+ // not here: look further up
42
+ }
43
+ dir = dirname(dir);
44
+ }
45
+ throw new Error('grayling: cannot find its own package.json');
46
+ }
47
+ /** This package's version: the version of the `grayling` program it goes with. */
48
+ export function packageVersion() {
49
+ return JSON.parse(readFileSync(join(packageRoot(), 'package.json'), 'utf8')).version;
50
+ }
@@ -0,0 +1,32 @@
1
+ /**
2
+ * The one place that maps names between this side (camelCase) and the wire (snake_case, docs/protocol.md), both ways. Keys that
3
+ * are data, not field names (a language code such as `eng_Latn`, a plan name), are not renamed: `OPAQUE` lists, for each kind of
4
+ * message, the paths whose children are left as they are.
5
+ */
6
+ import type { ClaimedApp, GraylingSettings, GraylingState, HostHello, HostInfo } from './types.js';
7
+ export declare const snake: (k: string) => string;
8
+ export declare const camel: (k: string) => string;
9
+ /** Paths (from the root of a message) whose children are data: their keys are kept. */
10
+ export declare const OPAQUE: {
11
+ readonly state: readonly ['status.model.languages'];
12
+ readonly usage: readonly ['judged'];
13
+ readonly none: string[];
14
+ };
15
+ export type Json = null | boolean | number | string | Json[] | {
16
+ [k: string]: Json;
17
+ };
18
+ export type Wire = Record<string, unknown>;
19
+ /** `value` with every object key renamed by `rename`, except the children of the `opaque` paths. */
20
+ export declare function mapKeys(value: unknown, rename: (k: string) => string, opaque?: readonly string[], path?: string): unknown;
21
+ /** From the wire (snake_case) to this side. */
22
+ export declare const fromWire: <T>(value: unknown, opaque?: readonly string[]) => T;
23
+ /** From this side to the wire. */
24
+ export declare const toWire: (value: unknown, opaque?: readonly string[]) => Wire;
25
+ /** The `state` answer and the `state` event's body. */
26
+ export declare function stateFromWire(v: Wire): GraylingState;
27
+ export declare const helloFromWire: (v: Wire) => HostHello;
28
+ export declare const infoFromWire: (v: Wire) => HostInfo;
29
+ export declare const appsToWire: (apps: readonly ClaimedApp[]) => Wire[];
30
+ export declare const appsFromWire: (v: unknown) => ClaimedApp[];
31
+ /** A patch of settings, to the wire. */
32
+ export declare const settingsToWire: (patch: Partial<GraylingSettings>) => Wire;
@@ -0,0 +1,44 @@
1
+ export const snake = (k) => k.replace(/[A-Z]/g, (c) => `_${c.toLowerCase()}`);
2
+ export const camel = (k) => k.replace(/_([a-z0-9])/g, (_, c) => c.toUpperCase());
3
+ /** Paths (from the root of a message) whose children are data: their keys are kept. */
4
+ export const OPAQUE = {
5
+ state: ['status.model.languages'],
6
+ usage: ['judged'],
7
+ none: [],
8
+ };
9
+ const isObject = (v) => !!v && typeof v === 'object' && !Array.isArray(v);
10
+ /** `value` with every object key renamed by `rename`, except the children of the `opaque` paths. */
11
+ export function mapKeys(value, rename, opaque = [], path = '') {
12
+ if (Array.isArray(value))
13
+ return value.map((v) => mapKeys(v, rename, opaque, path));
14
+ if (!isObject(value))
15
+ return value;
16
+ const keep = opaque.includes(path);
17
+ const out = {};
18
+ for (const [k, v] of Object.entries(value)) {
19
+ out[keep ? k : rename(k)] = mapKeys(v, rename, opaque, keep ? `${path}.*` : path ? `${path}.${k}` : k);
20
+ }
21
+ return out;
22
+ }
23
+ /** From the wire (snake_case) to this side. */
24
+ export const fromWire = (value, opaque = []) => mapKeys(value, camel, opaque);
25
+ /** From this side to the wire. */
26
+ export const toWire = (value, opaque = []) => mapKeys(value, snake, opaque);
27
+ /** The `state` answer and the `state` event's body. */
28
+ export function stateFromWire(v) {
29
+ const { settings, status } = v;
30
+ return fromWire({ settings, status }, OPAQUE.state);
31
+ }
32
+ export const helloFromWire = (v) => ({
33
+ protocol: Number(v.protocol),
34
+ engine: String(v.engine ?? ''),
35
+ pid: Number(v.pid),
36
+ });
37
+ export const infoFromWire = (v) => {
38
+ const { id: _id, ...rest } = v;
39
+ return fromWire(rest);
40
+ };
41
+ export const appsToWire = (apps) => apps.map((a) => toWire(a));
42
+ export const appsFromWire = (v) => (Array.isArray(v) ? v.map((a) => fromWire(a)) : []);
43
+ /** A patch of settings, to the wire. */
44
+ export const settingsToWire = (patch) => toWire(patch);
@@ -0,0 +1,121 @@
1
+ import { type KeyboardEvent as ReactKeyboard, type ReactNode, type RefObject } from 'react';
2
+ import type { SuggestCounts, SuggestPlan, SuggestRequest, SuggestResponse } from '../index.js';
3
+ import { type TextBox } from '../web/dom.js';
4
+ import { type FixView, type Gate, type Grey, type Place, type Spot, type View } from '../web/logic.js';
5
+ import { Suggester, type Adapter } from '../web/suggester.js';
6
+ import { type Attributes, type Classes, type Labels } from '../web/ui.js';
7
+ export { newClientId, typedLetters } from '../web/dom.js';
8
+ export { ANNOUNCE_MS, Announcer, spokenOf, type AnnouncerOptions, type Spoken } from '../web/announce.js';
9
+ export { BOX_CLASS, DEFAULT_CLASSES, DEFAULT_LABELS, type Attributes, type Classes, type Labels } from '../web/ui.js';
10
+ export { insertInto, replaceIn } from '../web/dom.js';
11
+ type Context = ReturnType<Adapter['context']>;
12
+ /** How the pieces look and read: every part is optional (the defaults are the package's own class names and English words). */
13
+ export interface Look {
14
+ classes?: Partial<Classes>;
15
+ labels?: Partial<Labels>;
16
+ /** Draws the key beside a word on a chip (default: a <kbd> with the label; give your own key component here). */
17
+ kbd?: (label: string) => ReactNode;
18
+ /** Extra attributes for some elements (an app's own hooks). */
19
+ attributes?: Attributes;
20
+ /** Icons drawn with the app's own icon set instead of the package's (the × that keeps a word as typed). */
21
+ icons?: {
22
+ close?: ReactNode;
23
+ };
24
+ }
25
+ /**
26
+ * The textarea's text, wrapped as the textarea wraps it: its text up to the caret unseen, then the grey words. Laid
27
+ * over the textarea, it lets the pointer through and is hidden from screen readers and from translation.
28
+ */
29
+ export declare function GreyMirror({ ta, before, grey, ...l }: {
30
+ ta: TextBox | null;
31
+ before: string;
32
+ grey: Grey;
33
+ } & Look): import("react").JSX.Element;
34
+ /**
35
+ * Exactly the textarea's text, its letters unseen, with each word typed wrong marked (so that nothing shifts), and an empty
36
+ * span at the caret where a chip points at. `markRef` is given the first mark's span of `fixAt` (a chip points at its first
37
+ * line), `caretRef` the span at `caret` when there is one.
38
+ */
39
+ export declare function MarksMirror({ ta, text, marks, fixAt, caret, markRef, caretRef, ...l }: {
40
+ ta: TextBox | null;
41
+ text: string;
42
+ marks: Spot[];
43
+ fixAt: number | null;
44
+ caret: number | null;
45
+ markRef: RefObject<HTMLElement | null>;
46
+ caretRef: RefObject<HTMLElement | null>;
47
+ } & Look): import("react").JSX.Element;
48
+ interface LayerProps extends Look {
49
+ /** Where it points at, on the screen now (null: nowhere, so nothing shows). */
50
+ anchor: () => DOMRect | null;
51
+ /** The box the place is in: the chip is hidden while the place is scrolled out of it. */
52
+ within: () => Element | null;
53
+ children: ReactNode;
54
+ }
55
+ /** The fixed layer, in the page's body: placed above its anchor, or below it, and inside the screen. It never takes the focus. */
56
+ export declare function Layer({ anchor, within, children, ...l }: LayerProps): import("react").ReactPortal;
57
+ /** The right word for one typed wrong: its changed letters strong, then Tab (dim when the grey word's Tab is the box's), then × to keep the word as typed. */
58
+ export declare function FixChip({ fix, anchor, within, onAccept, onKeep, ...l }: {
59
+ fix: FixView;
60
+ anchor: () => DOMRect | null;
61
+ within: () => Element | null;
62
+ onAccept: () => void;
63
+ onKeep: () => void;
64
+ } & Look): import("react").JSX.Element;
65
+ /** A word suggested inside a text: the letters already typed in the text colour, the rest in grey, and Tab; a tap takes it. */
66
+ export declare function MidChip({ typed, word, anchor, within, onTake, ...l }: {
67
+ typed: string;
68
+ word: string;
69
+ anchor: () => DOMRect | null;
70
+ within: () => Element | null;
71
+ onTake: () => void;
72
+ } & Look): import("react").JSX.Element;
73
+ /** What `createSuggest` needs from the app. */
74
+ export interface CreateSuggestOptions extends Look {
75
+ /** Asks the engine (a POST to your server, a message to it…): the answer, or null when there is nothing to show. */
76
+ send: (req: SuggestRequest, signal: AbortSignal) => Promise<SuggestResponse | null>;
77
+ /** The switches, read each time they matter (see `Gate`). */
78
+ gate: () => Gate;
79
+ /** Called when the switches change (a settings store's subscribe): the boxes look again. Return what stops it. */
80
+ subscribe?: (cb: () => void) => () => void;
81
+ /** Called when a box gets the focus (to start the engine, say). */
82
+ warm?: () => void;
83
+ /** Told what suggestions did, as counts only (see `UsageBatch`). */
84
+ count?: (c: Partial<SuggestCounts>) => void;
85
+ /** Told whether a guess, shown or not, was right: how sure it was and which plan made it, never the word. */
86
+ judge?: (plan: SuggestPlan, conf: number, right: boolean) => void;
87
+ /** Told which word the person kept as typed (Esc on its fix). */
88
+ keep?: (word: string) => void;
89
+ /** This page's client id: a new request cancels the client's one before (see `newClientId`). */
90
+ client: string;
91
+ /**
92
+ * Tell a screen reader about a suggestion that has stood for 1.2 s, in a polite live region that cannot be seen (default true; the words are
93
+ * `labels.suggestion` and `labels.correction`). `useTextareaSuggest` does it for its box; a `makeSuggester` box can use `Announcer`.
94
+ */
95
+ announce?: boolean;
96
+ /** How long the caret rests before its word is checked (ms). */
97
+ rest?: number;
98
+ }
99
+ export interface TextareaSuggest {
100
+ /** Offer a key press first: Tab, → at the end, Esc; true when it was taken (the box's own handling is then skipped). */
101
+ onKeyDown: (e: ReactKeyboard<HTMLTextAreaElement>) => boolean;
102
+ /** Draw it after the textarea, in the box it is in (the textarea's parent must be positioned: relative, say). */
103
+ overlay: ReactNode;
104
+ /** A word is suggested now (for a hint). */
105
+ shown: boolean;
106
+ }
107
+ export interface TextareaSuggestOptions {
108
+ place: Place;
109
+ /** The textarea's text (the hook asks again when it changes). */
110
+ value: string;
111
+ /** What goes with the text (read when a request goes out, so it may be a function of the latest state). */
112
+ context?: () => Context;
113
+ /** Suggestions are off in this box. */
114
+ off?: boolean;
115
+ }
116
+ export declare function createSuggest(o: CreateSuggestOptions): {
117
+ FixChip: (p: Parameters<typeof FixChip>[0]) => import("react").JSX.Element;
118
+ MidChip: (p: Parameters<typeof MidChip>[0]) => import("react").JSX.Element;
119
+ useTextareaSuggest: (ref: RefObject<HTMLTextAreaElement | null>, opt: TextareaSuggestOptions) => TextareaSuggest;
120
+ makeSuggester: (adapter: Adapter, on: (v: View) => void) => Suggester;
121
+ };