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,308 @@
1
+ import { type SuggestCounts, type SuggestJudged, type SuggestPlan, type SuggestRequest, type SuggestResponse, type SuggestSettings, type SuggestState, type SuggestSurface } from '../index.js';
2
+ /** Where a text box is, as an app names the places to turn suggestions on or off in: message boxes, documents, notes, other boxes. */
3
+ export type Place = 'chat' | 'docs' | 'notes' | 'other';
4
+ /** What the engine is asked for in each place. */
5
+ export declare const surfaceOf: (p: Place) => SuggestSurface;
6
+ /** How much of each text goes to the engine (its last characters). */
7
+ export declare const MAX_CHARS = 2000;
8
+ export declare const tail: (s: string | undefined, n?: number) => string | undefined;
9
+ /** What the state of a text box is, as far as asking goes: the text before the caret and after it. */
10
+ export interface Field {
11
+ before: string;
12
+ after: string;
13
+ /** Some text is selected (there is no caret to suggest at). */
14
+ selected?: boolean;
15
+ /** The selected text, when neither `before` nor `after` holds it (a textarea). */
16
+ picked?: string;
17
+ /** An input method (Japanese, Chinese, an accent key…) is composing. */
18
+ composing?: boolean;
19
+ /** Which box it is, where one editor holds many (a paragraph, say): another box is never "typing more". */
20
+ id?: string;
21
+ }
22
+ /** The whole text of a box: what is before the caret, selected, and after it. */
23
+ export declare const textOf: (f: Field) => string;
24
+ /** The switches that decide whether to ask in a place. */
25
+ export interface Gate {
26
+ enabled: boolean;
27
+ state: SuggestState['status']['state'] | undefined;
28
+ where: SuggestSettings['where'];
29
+ /** This browser's own switch (an app's "show here" setting). */
30
+ browser: boolean;
31
+ /** Suggest inside a text too (more text after the caret on its line). */
32
+ midText: boolean;
33
+ /** Mark a word typed wrong and show the right one. */
34
+ fixTypos: boolean;
35
+ }
36
+ /** Whether suggestions show in `place` at all: on, set up (or loading), the place on in the settings, and this browser's switch on. */
37
+ export declare function allowed(g: Gate, place: Place): boolean;
38
+ /**
39
+ * Whether the caret is where a suggestion makes sense: collapsed, not mid-composition, nothing more on its line
40
+ * (the grey text would sit on top of it), and right after a letter (the end of a word) or after whitespace (a new
41
+ * word). After punctuation or nothing at all there is no word to suggest, nor in an @file, a /command or an address.
42
+ */
43
+ export declare function atWordEnd(f: Field): boolean;
44
+ /**
45
+ * Where a suggestion goes at the caret: `end` (grey text after it: nothing more on the line), `mid` (a chip over the caret: more
46
+ * text follows on the line), or null. Inside a text only after typing there (`typed`), and never before a letter of the same
47
+ * word, unless the caret was put right before that word to put a new one in (`seam`).
48
+ */
49
+ export declare function spotOf(f: Field, o: {
50
+ typed: boolean;
51
+ seam: boolean;
52
+ }): 'end' | 'mid' | null;
53
+ /**
54
+ * What the caret's place is, inside a text: the text before and after it when it came there, whether a new word is being put in
55
+ * before the word that follows (`seam`: whitespace or nothing before the caret, a letter after it), and whether something was
56
+ * typed there (or Tab took a suggestion) since.
57
+ */
58
+ export interface PlaceState {
59
+ before: string;
60
+ after: string;
61
+ id?: string;
62
+ seam: boolean;
63
+ typed: boolean;
64
+ }
65
+ /** Whether a new word is about to be put in before the word that follows the caret. */
66
+ export declare const seamOf: (f: Field) => boolean;
67
+ /**
68
+ * The caret's place after a change from `prev` to `cur`: the same while the text after the caret and the id stay, and the text
69
+ * before still begins as it did when the caret came there; typing there (`grown`: 1 to TYPED_MAX characters) or Tab (`tab`)
70
+ * makes it typed. Any other change (a caret move, Backspace, another box) starts over.
71
+ */
72
+ export declare function placeOf(p: PlaceState | null, prev: Field | null, cur: Field, o: {
73
+ grown: boolean;
74
+ tab?: boolean;
75
+ }): PlaceState;
76
+ /** What goes to the engine for a text box in `place` (chat: with the reply it answers and the earlier message). */
77
+ export declare function requestOf(place: Place, f: Field, ctx: {
78
+ reply?: string;
79
+ prev?: string;
80
+ doc?: string;
81
+ session?: string;
82
+ }, client: string): SuggestRequest;
83
+ /** The most characters after the caret that go to the engine. */
84
+ export declare const AFTER_MAX = 300;
85
+ /** What goes to the engine for a suggestion inside a text: the same, with the text after the caret (and `apart` when a new word is put in before the next one). */
86
+ export declare function midRequestOf(place: Place, f: Field, ctx: {
87
+ reply?: string;
88
+ prev?: string;
89
+ doc?: string;
90
+ session?: string;
91
+ }, client: string, seam: boolean): SuggestRequest;
92
+ /** What goes to the engine to check a word alone: the text before the caret, and what follows when a word goes on after it or more text stands on the line. */
93
+ export declare function fixRequestOf(place: Place, f: Field, ctx: {
94
+ reply?: string;
95
+ prev?: string;
96
+ doc?: string;
97
+ session?: string;
98
+ }, client: string): SuggestRequest;
99
+ /** What shows after the caret: the rest of the word being typed (or a whole next word), and the word after it, dimmer. */
100
+ export interface Grey {
101
+ word: string;
102
+ next: string;
103
+ }
104
+ /** What an answer shows: nothing when it says not to (or has nothing), `word` when `show`, `next` also when `showNext`. */
105
+ export declare function greyOf(r: SuggestResponse | null | undefined): Grey | null;
106
+ /**
107
+ * What shows right after whitespace that was typed: never more whitespace (a second space). The grey text loses the
108
+ * whitespace it begins with, and when the word itself is empty the next word becomes the word.
109
+ */
110
+ export declare function afterSpace(g: Grey | null, before: string): Grey | null;
111
+ /** Whether two things to show read the same (an answer that only repeats what is on screen changes nothing). */
112
+ export declare const sameGrey: (a: Grey | null, b: Grey | null) => boolean;
113
+ /**
114
+ * What typing `typed` leaves of what shows: the letters it shows are used up, with no new request. undefined when
115
+ * the letters differ (a new request, then); null when all of it has been typed. Once the rest of the word is typed
116
+ * the next word shows as it is; once its first letters are typed it is the word being typed, in the word's grey.
117
+ */
118
+ export declare function consume(g: Grey, typed: string): Grey | null | undefined;
119
+ /** What Tab takes: the word, and the next word becomes the one shown (the word's grey); with no word left, the next word. */
120
+ export declare function takeWord(g: Grey): {
121
+ insert: string;
122
+ grey: Grey | null;
123
+ };
124
+ /** What → at the end of the text takes: the word and the next one. */
125
+ export declare const takeAll: (g: Grey) => string;
126
+ /**
127
+ * What was typed between two states of a box, when the text after the caret did not change and the text before it
128
+ * only grew: that growth ('' when nothing changed). null when it is anything else (Backspace, a paste over a
129
+ * selection, a caret move, a different text).
130
+ */
131
+ export declare function typedBetween(prev: Field | null, cur: Field): string | null;
132
+ /** Whether the caret is just after whitespace: a new word begins here (Esc's hiding lasts until it does). */
133
+ export declare const startsWord: (f: Field) => boolean;
134
+ /** No counts. */
135
+ export declare const noCounts: () => SuggestCounts;
136
+ /** The counts of a suggestion shown inside a text, in the keys of its own (the characters typed are the box's, not the suggestion's). */
137
+ export declare function toMid(c: Partial<SuggestCounts>): Partial<SuggestCounts>;
138
+ /** `a` and `b` added up. */
139
+ export declare function addCounts(a: SuggestCounts, b: Partial<SuggestCounts>): SuggestCounts;
140
+ /** Whether any count is more than 0. */
141
+ export declare const hasCounts: (c: SuggestCounts) => boolean;
142
+ /**
143
+ * `c` cut into pieces the engine accepts: no count above `cap` in any one (the rest goes in the next piece). Nothing
144
+ * for no counts.
145
+ */
146
+ export declare function splitCounts(c: SuggestCounts, cap?: number): SuggestCounts[];
147
+ /** The characters of a text, as a person counts them (an emoji or a letter with its accents is one). */
148
+ export declare const charCount: (s: string) => number;
149
+ /** The most characters one change of a box may add and still be counted as typing (more is a paste or dictation). */
150
+ export declare const TYPED_MAX = 4;
151
+ /** What a change that grew the text before the caret by `typed` ('' or null: not a growth) adds to the characters typed: 1 to 4, else 0. */
152
+ export declare function typedChars(typed: string | null): number;
153
+ /** The keystrokes one Tab or → saved: the characters it inserted, minus the key pressed (never below 0). */
154
+ export declare const savedBy: (inserted: string) => number;
155
+ /** What Tab or → did to the counts: the words taken (→ takes the word and the next: two), and the keystrokes saved by what it inserted. */
156
+ export declare function takenCounts(g: Grey, insert: string, all: boolean): SuggestCounts;
157
+ /** What typing `typed` did to the suggestion showing: nothing, its words typed through, or something else typed. */
158
+ export interface Typed {
159
+ /** The words of what showed that the typing completed (0 to 2: the word, and the next one). */
160
+ through: number;
161
+ /** The next word became the grey word because of it: a new suggestion (so `shown` goes up). */
162
+ fresh: boolean;
163
+ /** Something other than what showed was typed. */
164
+ wrong: boolean;
165
+ }
166
+ /**
167
+ * The verdict on typing `typed` (a growth of the text before the caret) while `g` showed: the letters it shows used up
168
+ * are right once a whole word is typed (its last letter, or the space after it, typed in the same change); a letter
169
+ * that differs is wrong. The unit is the word, or the next word when the word is empty (it is all that shows).
170
+ */
171
+ export declare function judgeTyped(g: Grey, typed: string): Typed;
172
+ /** Whether `cur` is `prev` with some characters just before the caret deleted (Backspace, or Ctrl+Backspace), nothing else changed. */
173
+ export declare function backspaced(prev: Field | null, cur: Field): boolean;
174
+ /** A guess at the word being typed: what the box was when it was asked, the letters guessed after the caret, and how sure. */
175
+ export interface Guess {
176
+ base: Field;
177
+ word: string;
178
+ plan: SuggestPlan;
179
+ conf: number;
180
+ }
181
+ /**
182
+ * The guess an answer about `base` holds, shown or not: the letters of the word (without the space already typed) and
183
+ * how sure. null when it has no word, no plan or no confidence (there is nothing to judge).
184
+ */
185
+ export declare function guessOf(base: Field, r: SuggestResponse | null | undefined): Guess | null;
186
+ /**
187
+ * Whether the guess `word` was right, from what was typed since it was asked (`typed`): true once the word is typed
188
+ * and something that ends it (a space, punctuation) follows; false once the person finished another word; undefined
189
+ * while they are still typing it.
190
+ */
191
+ export declare function verdictOf(word: string, typed: string): boolean | undefined;
192
+ /** The bin a confidence falls in (0..1 cut in SUGGEST_BINS equal parts). */
193
+ export declare const binOf: (conf: number) => number;
194
+ /** One judged guess added to the counts (a bin never past what one request may send). */
195
+ export declare function addVerdict(j: SuggestJudged, plan: SuggestPlan, conf: number, right: boolean): void;
196
+ /** `add` put into `into` (a batch that could not be sent, joining the next). */
197
+ export declare function mergeJudged(into: SuggestJudged, add: SuggestJudged): void;
198
+ export declare const hasJudged: (j: SuggestJudged) => boolean;
199
+ /** The numbers a settings page can show for a set of counts: keystrokes saved and their share of the typing, suggestions right of those judged (at the end of a text and inside it together). */
200
+ export declare function summarise(c: SuggestCounts): {
201
+ saved: number;
202
+ savedShare: number;
203
+ right: number;
204
+ judged: number;
205
+ rightShare: number;
206
+ taken: number;
207
+ };
208
+ /** A word typed wrong that was found, and the right one. */
209
+ export interface Mark {
210
+ typed: string;
211
+ word: string;
212
+ conf: number;
213
+ /** The word was still being typed when it was found: it may have gone on since by a few letters. */
214
+ open: boolean;
215
+ /** The up to 16 characters before the word where it was found: a mark is kept by its words, not by its place. */
216
+ left: string;
217
+ /** A counter: later marks are newer. */
218
+ at: number;
219
+ /** Which box of an editor it was found in (a paragraph, say). */
220
+ id?: string;
221
+ }
222
+ /** A stretch of the text (before + after the caret): offsets of its characters. */
223
+ export interface Spot {
224
+ start: number;
225
+ end: number;
226
+ }
227
+ /** The chip over a mark: the stretch it stands on, the word as typed, the right word, and whether Tab puts it in. */
228
+ export interface FixView {
229
+ start: number;
230
+ end: number;
231
+ typed: string;
232
+ word: string;
233
+ tab: boolean;
234
+ }
235
+ /** What a text box shows, told to its adapter whenever any of it changes. */
236
+ export interface View {
237
+ grey: Grey | null;
238
+ /** The grey word is a suggestion inside a text: a chip over the caret, not grey text after it. */
239
+ mid: boolean;
240
+ marks: Spot[];
241
+ fix: FixView | null;
242
+ }
243
+ /** The most marks a box keeps (the oldest go). */
244
+ export declare const MARKS_MAX = 20;
245
+ /** The characters kept before a mark's word. */
246
+ export declare const LEFT_MAX = 16;
247
+ /** The letters an open mark's word may have gone on by. */
248
+ export declare const OPEN_MORE = 3;
249
+ /** The most words typed after a mark for its chip to still show. */
250
+ export declare const CHIP_WORDS = 6;
251
+ /** The `left` a mark found at `start` keeps. */
252
+ export declare const leftOf: (text: string, start: number) => string;
253
+ /**
254
+ * Where a mark stands in a text: the first place where its word stands as a whole word (no letter on either side), with
255
+ * the text before it ending as `left`; an open mark's word may go on by up to 3 letters. null when it stands nowhere
256
+ * now (the word was changed, or what was before it).
257
+ */
258
+ export declare function findMark(text: string, m: Pick<Mark, 'typed' | 'open' | 'left'>): Spot | null;
259
+ /** A mark and where it stands. */
260
+ export interface Placed {
261
+ mark: Mark;
262
+ spot: Spot;
263
+ }
264
+ /**
265
+ * Where a stretch of `from` stands in `to`, the same text a change later: before the change as it was, after it moved along, and
266
+ * nowhere (null) when the change touches it. What is drawn keeps to its words until the marks are looked for again.
267
+ */
268
+ export declare function moveSpot(s: Spot, from: string, to: string): Spot | null;
269
+ /** The marks that stand in a text, with their places (the others are gone). */
270
+ export declare const placeMarks: (text: string, marks: readonly Mark[]) => Placed[];
271
+ /** Whether the caret has left a mark behind: a line break, or more than 6 words, stand between its end and the caret. */
272
+ export declare function leftBehind(text: string, spot: Spot, caret: number): boolean;
273
+ /**
274
+ * The mark whose chip shows: the one the caret is in or at the end of (the newest if several), else the newest one before the
275
+ * caret with at most 6 words after it and no line break between (`passed`: marks the caret has left, which show again only when
276
+ * the caret is in them).
277
+ */
278
+ export declare function currentMark(list: readonly Placed[], text: string, caret: number, passed?: ReadonlySet<Mark>): Placed | null;
279
+ /** Whether the caret is in a word or right after it: only characters that are no letters stand between the word's end and the caret. */
280
+ export declare const caretAtWord: (text: string, spot: Spot, caret: number) => boolean;
281
+ /** Whether Tab is the chip's: the caret is in its word or right after it, or no grey word shows. */
282
+ export declare const fixOwnsTab: (text: string, spot: Spot, caret: number, greyShows: boolean) => boolean;
283
+ /**
284
+ * The chips a box shows: one at a time, the one Tab is for, so that Tab never does what cannot be seen. A fix whose Tab is the
285
+ * grey word's keeps its chip beside grey text at the end of a text, but gives way to a word suggested inside it.
286
+ */
287
+ export declare function chipsOf(v: View): {
288
+ fix: FixView | null;
289
+ mid: Grey | null;
290
+ };
291
+ /** The word a caret is in or at the ends of (a letter right before it or right after it): where it stands, or null. */
292
+ export declare function wordAround(text: string, caret: number): Spot | null;
293
+ /** Whether a character that is no letter and no whitespace (punctuation, a closing bracket, a quote) was just typed right after a word. */
294
+ export declare function punctAfterWord(before: string): boolean;
295
+ /** Whether a word has just ended before the caret: at most three characters that are no letters and no spaces stand after it. */
296
+ export declare const wordEnded: (before: string) => boolean;
297
+ /** Whether a word and one space after it are what stands right before the caret. */
298
+ export declare const spaceAfterWord: (before: string) => boolean;
299
+ /** A box as if the caret were one character into the word it stands at the beginning of (so that this word is the one at the caret, not the one before it). */
300
+ export declare function intoWord(f: Field): Field;
301
+ /** The words a caret rests at, remembered as the 16 characters before it and the word: the same word at the same place is asked about once. */
302
+ export declare const askedKey: (text: string, w: Spot) => string;
303
+ /** The right word with the letters that differ from the typed word marked: outside the longest common prefix and suffix. */
304
+ export declare function diffLetters(typed: string, word: string): {
305
+ pre: string;
306
+ mid: string;
307
+ post: string;
308
+ };