@twip/web 0.0.0-canary-f16fa12

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 (82) hide show
  1. package/LICENSE +202 -0
  2. package/README.md +35 -0
  3. package/dist/THIRD-PARTY-NOTICES.md +5457 -0
  4. package/dist/commands.d.ts +637 -0
  5. package/dist/commands.js +188 -0
  6. package/dist/editor.d.ts +218 -0
  7. package/dist/editor.js +460 -0
  8. package/dist/errors.d.ts +21 -0
  9. package/dist/errors.js +26 -0
  10. package/dist/events.d.ts +126 -0
  11. package/dist/events.js +1 -0
  12. package/dist/fonts/google.d.ts +3 -0
  13. package/dist/fonts/google.js +39 -0
  14. package/dist/fonts/library.d.ts +65 -0
  15. package/dist/fonts/library.js +130 -0
  16. package/dist/host/a11y.d.ts +3 -0
  17. package/dist/host/a11y.js +62 -0
  18. package/dist/host/chrome.d.ts +28 -0
  19. package/dist/host/chrome.js +144 -0
  20. package/dist/host/clipboard.d.ts +16 -0
  21. package/dist/host/clipboard.js +128 -0
  22. package/dist/host/cursors.d.ts +15 -0
  23. package/dist/host/cursors.js +5 -0
  24. package/dist/host/dom.d.ts +45 -0
  25. package/dist/host/dom.js +122 -0
  26. package/dist/host/frames.d.ts +14 -0
  27. package/dist/host/frames.js +87 -0
  28. package/dist/host/gpu.d.ts +58 -0
  29. package/dist/host/gpu.js +79 -0
  30. package/dist/host/ime.d.ts +3 -0
  31. package/dist/host/ime.js +11 -0
  32. package/dist/host/input.d.ts +12 -0
  33. package/dist/host/input.js +86 -0
  34. package/dist/host/keys.d.ts +16 -0
  35. package/dist/host/keys.js +27 -0
  36. package/dist/host/mount.d.ts +11 -0
  37. package/dist/host/mount.js +72 -0
  38. package/dist/host/pointer.d.ts +4 -0
  39. package/dist/host/pointer.js +196 -0
  40. package/dist/host/scroll.d.ts +14 -0
  41. package/dist/host/scroll.js +95 -0
  42. package/dist/index.d.ts +27 -0
  43. package/dist/index.js +10 -0
  44. package/dist/review.d.ts +156 -0
  45. package/dist/review.js +38 -0
  46. package/dist/services/accessibility.d.ts +52 -0
  47. package/dist/services/accessibility.js +71 -0
  48. package/dist/services/dialogs.d.ts +181 -0
  49. package/dist/services/dialogs.js +18 -0
  50. package/dist/services/elements.d.ts +146 -0
  51. package/dist/services/elements.js +18 -0
  52. package/dist/services/find.d.ts +50 -0
  53. package/dist/services/find.js +12 -0
  54. package/dist/services/menus.d.ts +82 -0
  55. package/dist/services/menus.js +8 -0
  56. package/dist/services/navigation.d.ts +58 -0
  57. package/dist/services/navigation.js +12 -0
  58. package/dist/services/ruler.d.ts +95 -0
  59. package/dist/services/ruler.js +16 -0
  60. package/dist/services/spelling.d.ts +34 -0
  61. package/dist/services/spelling.js +14 -0
  62. package/dist/services/view.d.ts +70 -0
  63. package/dist/services/view.js +19 -0
  64. package/dist/state.d.ts +483 -0
  65. package/dist/state.js +1 -0
  66. package/dist/transport/direct.d.ts +31 -0
  67. package/dist/transport/direct.js +405 -0
  68. package/dist/transport/module.d.ts +51 -0
  69. package/dist/transport/module.js +17 -0
  70. package/dist/transport/protocol.d.ts +265 -0
  71. package/dist/transport/protocol.js +132 -0
  72. package/dist/transport/worker.d.ts +54 -0
  73. package/dist/transport/worker.js +203 -0
  74. package/dist/twip-wasm.js +2 -0
  75. package/dist/twip_wasm.wasm +0 -0
  76. package/dist/types.d.ts +134 -0
  77. package/dist/types.js +16 -0
  78. package/dist/worker/entry.d.ts +1 -0
  79. package/dist/worker/entry.js +53 -0
  80. package/dist/worker.d.ts +1 -0
  81. package/dist/worker.js +2 -0
  82. package/package.json +30 -0
@@ -0,0 +1,16 @@
1
+ import { Method } from '../transport/protocol.js';
2
+ /** The mounted rulers over a session; `view` starts as `initial` and follows `rulerChanged`. */
3
+ export function createRuler(s, initial) {
4
+ let view = initial;
5
+ s.on('rulerChanged', (v) => (view = v));
6
+ return {
7
+ model: () => s.state.ruler,
8
+ setVisible: ({ horizontal, vertical }) => {
9
+ const now = s.state.view.rulers;
10
+ return s.call(Method.HostSetRulers, { horizontal: horizontal ?? now.horizontal, vertical: vertical ?? now.vertical });
11
+ },
12
+ setUnit: (unit) => s.call(Method.HostSetRulerUnit, unit),
13
+ setTabSelector: (kind) => s.call(Method.HostSetTabSelector, kind),
14
+ view: () => view,
15
+ };
16
+ }
@@ -0,0 +1,34 @@
1
+ import type { Session } from '../editor.js';
2
+ /** Hunspell dictionaries for one language. */
3
+ export interface Dictionary {
4
+ /** The BCP 47 language tag. */
5
+ language: string;
6
+ /** The `.aff` file. */
7
+ aff: Uint8Array;
8
+ /** The `.dic` file. */
9
+ dic: Uint8Array;
10
+ }
11
+ /** Spell checking. */
12
+ export interface Spelling {
13
+ /** Adds a language's dictionaries. */
14
+ addDictionary(dictionary: Dictionary): Promise<void>;
15
+ /** Turns checking on or off. */
16
+ setEnabled(on: boolean): Promise<void>;
17
+ /** The default language for text with no language. */
18
+ setLanguage(language: string): Promise<void>;
19
+ /** Ignores a word for this session. */
20
+ ignore(word: string): Promise<void>;
21
+ /** Adds a word to the user's dictionary: emits `wordAdded`, for the application to persist. */
22
+ add(word: string): Promise<void>;
23
+ /** Loads the user's words for a language; kept until that language's dictionary arrives. */
24
+ loadUserWords(language: string, words: string[]): Promise<void>;
25
+ /** Suggestions for a word. */
26
+ suggestions(word: string, language?: string): Promise<string[]>;
27
+ /** Selects the next misspelling (F7), or resolves `null` when there is none. */
28
+ next(): Promise<{
29
+ word: string;
30
+ suggestions: string[];
31
+ } | null>;
32
+ }
33
+ /** Spell checking over a session. */
34
+ export declare function createSpelling(s: Session): Spelling;
@@ -0,0 +1,14 @@
1
+ import { Method } from '../transport/protocol.js';
2
+ /** Spell checking over a session. */
3
+ export function createSpelling(s) {
4
+ return {
5
+ addDictionary: (dictionary) => s.call(Method.SpellingAddDictionary, dictionary),
6
+ setEnabled: (on) => s.call(Method.SpellingSetEnabled, on),
7
+ setLanguage: (language) => s.call(Method.SpellingSetLanguage, language),
8
+ ignore: (word) => s.call(Method.SpellingIgnore, word),
9
+ add: (word) => s.call(Method.SpellingAdd, word),
10
+ loadUserWords: (language, words) => s.call(Method.SpellingLoadUserWords, { language, words }),
11
+ suggestions: (word, language) => s.call(Method.SpellingSuggestions, { word, language }),
12
+ next: () => s.call(Method.SpellingNext),
13
+ };
14
+ }
@@ -0,0 +1,70 @@
1
+ import type { Op } from '../commands.js';
2
+ import type { Session } from '../editor.js';
3
+ import type { ClientPoint, ClientRect, Color, FrameStats, OverlayColors } from '../types.js';
4
+ import type { MenuTarget } from './menus.js';
5
+ /** The view of a mounted editor. Zoom and the other view settings are the view commands. */
6
+ export interface View {
7
+ /** Scrolls the selection into view. */
8
+ revealSelection(): Promise<void>;
9
+ /**
10
+ * The background around the pages (dark mode). The paper stays white. The page shadow, the markup pane and the
11
+ * rulers' colours follow it: a dark background gives dark rulers.
12
+ */
13
+ setBackground(color: Color): Promise<void>;
14
+ /** The pages on screen, for a page navigator or a thumbnails strip. */
15
+ visiblePages(): {
16
+ page: number;
17
+ rect: ClientRect;
18
+ }[];
19
+ /** What the frames have cost so far: for benchmarks and tests. */
20
+ frameStats(): Promise<FrameStats>;
21
+ /**
22
+ * How the caret blinks: `ms` per phase (0 for a steady caret), and stop blinking, the caret left visible, after
23
+ * `stopAfterMs` without input. The editor stops following the platform's reduced-motion setting.
24
+ */
25
+ setCaretBlink(ms: number, stopAfterMs?: number): Promise<void>;
26
+ /**
27
+ * The colours of what the editor draws over the document; the ones not given keep theirs. The editor stops following
28
+ * the platform's forced-colours mode.
29
+ */
30
+ setOverlayColors(colors: Partial<OverlayColors>): Promise<void>;
31
+ }
32
+ /** What the engine's pointer gestures do, on a mounted editor. */
33
+ export interface Gestures {
34
+ /** Every gesture's binding. */
35
+ bindings(): GestureBinding[];
36
+ /** Rebinds a gesture. */
37
+ set(gesture: GestureId, action: GestureAction): Promise<void>;
38
+ /** Back to the default (all of them when no id is given). */
39
+ reset(gesture?: GestureId): Promise<void>;
40
+ }
41
+ /** A pointer gesture the engine recognises. */
42
+ export type GestureId = 'headerAreaDoubleClick' | 'footerAreaDoubleClick' | 'bodyDoubleClickInHeaderFooter' | 'textDoubleClick' | 'textTripleClick' | 'textCtrlClick' | 'linkActivate' | 'marginClick' | 'marginDoubleClick' | 'tableBorderDoubleClick' | 'tableBorderDrag' | 'objectDrag' | 'textDrag' | 'elementDoubleClick' | 'placeholderClick' | 'rulerClick' | 'rulerDrag' | 'rulerDragOff' | 'rulerDoubleClick' | 'contextClick';
43
+ /** What a gesture does: its default, an event, nothing, or an op. */
44
+ export type GestureAction = 'default' | 'emit' | 'none' | {
45
+ op: Op;
46
+ };
47
+ /** A gesture's binding. */
48
+ export interface GestureBinding {
49
+ /** The gesture. */
50
+ gesture: GestureId;
51
+ /** What it does. */
52
+ action: GestureAction;
53
+ /** For example `'Double-click the header area'`. */
54
+ label: string;
55
+ }
56
+ /** The `gesture` event: a gesture bound to `'emit'` happened. */
57
+ export interface GestureEvent {
58
+ /** The gesture. */
59
+ gesture: GestureId;
60
+ /** Where. */
61
+ at: ClientPoint;
62
+ /** The page. */
63
+ page: number;
64
+ /** What is under the point. */
65
+ target: MenuTarget | {
66
+ kind: 'headerArea' | 'footerArea' | 'margin' | 'ruler' | 'tableBorder';
67
+ };
68
+ }
69
+ /** The gestures over a session; `bindings` starts as `initial` and is read again after each change. */
70
+ export declare function createGestures(s: Session, initial: GestureBinding[]): Gestures;
@@ -0,0 +1,19 @@
1
+ import { Method } from '../transport/protocol.js';
2
+ /** The gestures over a session; `bindings` starts as `initial` and is read again after each change. */
3
+ export function createGestures(s, initial) {
4
+ let bindings = initial;
5
+ const refresh = async () => {
6
+ bindings = await s.call(Method.GesturesBindings);
7
+ };
8
+ return {
9
+ bindings: () => bindings,
10
+ set: async (gesture, action) => {
11
+ await s.call(Method.GesturesSet, { gesture, action });
12
+ await refresh();
13
+ },
14
+ reset: async (gesture) => {
15
+ await s.call(Method.GesturesReset, gesture ?? null);
16
+ await refresh();
17
+ },
18
+ };
19
+ }
@@ -0,0 +1,483 @@
1
+ import type { CommandId } from './commands.js';
2
+ import type { DialogKind } from './services/dialogs.js';
3
+ import type { ControlKind } from './services/elements.js';
4
+ import type { RulerModel, RulerUnit, TabSelector } from './services/ruler.js';
5
+ import type { Color, CommentId, ElementId, Points, RevisionId, StyleId } from './types.js';
6
+ /** An on/off value over the selection: `'mixed'` where it differs, `null` where it doesn't apply. */
7
+ export type Tri = boolean | 'mixed' | null;
8
+ /** A value over the selection: `'mixed'` where it differs, `null` where it doesn't apply. */
9
+ export type Mixed<T> = T | 'mixed' | null;
10
+ /** The editor's UI snapshot: small, immutable, and cached on the calling side. */
11
+ export interface EditorState {
12
+ /** Rises by one per committed transaction. */
13
+ revision: number;
14
+ /** Rises by one per observable change, selection included. */
15
+ sequence: number;
16
+ /** Whether a document is opening, ready, or still being laid out. */
17
+ load: 'opening' | 'ready' | 'layingOut';
18
+ /** Editing or the merge designer's design mode. */
19
+ mode: 'editing' | 'design';
20
+ /** Whether edits are refused. */
21
+ readOnly: boolean;
22
+ /** Changed since the last open or DOCX export; undoing back clears it. */
23
+ modified: boolean;
24
+ /** What is selected. */
25
+ selection: SelectionSummary;
26
+ /** The selection's character formatting. */
27
+ formatting: CharacterFormatting;
28
+ /** The selection's paragraph formatting. */
29
+ paragraph: ParagraphFormatting;
30
+ /** The selection's section. */
31
+ page: PageFormatting;
32
+ /** Each command's availability and value, keyed by command id. */
33
+ commands: {
34
+ readonly [K in CommandId]: CommandState<K>;
35
+ };
36
+ /** Each dialog's availability: whether `dialogs.open` opens it now. */
37
+ dialogs: {
38
+ readonly [K in DialogKind]: boolean;
39
+ };
40
+ /** Undo and redo. */
41
+ history: {
42
+ canUndo: boolean;
43
+ canRedo: boolean;
44
+ undoLabel: string | null;
45
+ redoLabel: string | null;
46
+ };
47
+ /**
48
+ * The pages laid out so far and the caret's page. Background layout adds pages until `complete`; each change is a
49
+ * new state with the same revision.
50
+ */
51
+ pages: {
52
+ count: number;
53
+ current: number;
54
+ complete: boolean;
55
+ };
56
+ /** View settings. */
57
+ view: ViewState;
58
+ /** Track changes and comments. */
59
+ review: ReviewState;
60
+ /** Spell checking. */
61
+ spelling: {
62
+ enabled: boolean;
63
+ language: string;
64
+ misspellings: number;
65
+ };
66
+ /** Fonts being fetched and fonts that could not be found. */
67
+ fonts: {
68
+ pending: string[];
69
+ unresolved: string[];
70
+ };
71
+ /** The ruler model for the selection, in points, with no viewport mapping. */
72
+ ruler: RulerModel;
73
+ /** Whether formatting is held for `pasteFormatting`. */
74
+ formatPainter: boolean;
75
+ }
76
+ /** The value each command reports in state, for the commands that report one. */
77
+ export interface CommandValues {
78
+ /** The undo label. */
79
+ undo: string | null;
80
+ /** The redo label. */
81
+ redo: string | null;
82
+ /** The selection mode. */
83
+ setSelectionMode: SelectionSummary['mode'];
84
+ /** Bold. */
85
+ setBold: Tri;
86
+ /** Italic. */
87
+ setItalic: Tri;
88
+ /** The underline style. */
89
+ setUnderline: Mixed<UnderlineStyle>;
90
+ /** Strikethrough. */
91
+ setStrikethrough: Tri;
92
+ /** Double strikethrough. */
93
+ setDoubleStrikethrough: Tri;
94
+ /** Subscript. */
95
+ setSubscript: Tri;
96
+ /** Superscript. */
97
+ setSuperscript: Tri;
98
+ /** Small caps. */
99
+ setSmallCaps: Tri;
100
+ /** All caps. */
101
+ setAllCaps: Tri;
102
+ /** Hidden text. */
103
+ setHidden: Tri;
104
+ /** The document's font family. */
105
+ setFont: Mixed<string>;
106
+ /** The font size. */
107
+ setFontSize: Mixed<Points>;
108
+ /** The font colour. */
109
+ setFontColor: Mixed<Color | 'auto'>;
110
+ /** The highlight. */
111
+ setHighlight: Mixed<HighlightColor | 'none'>;
112
+ /** The character spacing. */
113
+ setCharacterSpacing: Mixed<Points>;
114
+ /** The raised or lowered position. */
115
+ setCharacterPosition: Mixed<Points>;
116
+ /** Whether formatting is held. */
117
+ copyFormatting: boolean;
118
+ /** Whether formatting is held. */
119
+ pasteFormatting: boolean;
120
+ /** The alignment. */
121
+ setAlignment: ParagraphFormatting['alignment'];
122
+ /** The line spacing. */
123
+ setLineSpacing: Mixed<LineSpacing>;
124
+ /** The space before and after. */
125
+ setParagraphSpacing: {
126
+ before: Mixed<Points | 'auto'>;
127
+ after: Mixed<Points | 'auto'>;
128
+ };
129
+ /** The indents. */
130
+ setIndents: ParagraphFormatting['indents'];
131
+ /** The paragraph style. */
132
+ setParagraphStyle: Mixed<StyleId>;
133
+ /** The list kind. */
134
+ setList: ParagraphFormatting['list'];
135
+ /** The list level. */
136
+ setListLevel: Mixed<number>;
137
+ /** The pagination flags. */
138
+ setParagraphFlow: ParagraphFormatting['flow'];
139
+ /** The paragraph borders. */
140
+ setParagraphBorders: ParagraphFormatting['borders'];
141
+ /** The paragraph shading. */
142
+ setParagraphShading: Mixed<Color | 'none'>;
143
+ /** The margins. */
144
+ setMargins: PageFormatting['margins'];
145
+ /** The orientation. */
146
+ setOrientation: PageFormatting['orientation'];
147
+ /** The paper size. */
148
+ setPaperSize: PageFormatting['size'];
149
+ /** The text columns. */
150
+ setColumns: PageFormatting['columns'];
151
+ /** The header and footer distances. */
152
+ setHeaderFooterDistance: {
153
+ header: Points;
154
+ footer: Points;
155
+ };
156
+ /** A different first page. */
157
+ setDifferentFirstPage: boolean;
158
+ /** Different odd and even pages. */
159
+ setDifferentOddEvenPages: boolean;
160
+ /** Whether changes are tracked. */
161
+ setTrackChanges: boolean;
162
+ /** The markup view. */
163
+ setMarkupView: MarkupView;
164
+ /** The active comment. */
165
+ setActiveComment: CommentId | null;
166
+ /** The zoom, in percent. */
167
+ setZoom: number;
168
+ /** The view options. */
169
+ setViewOptions: {
170
+ formattingMarks: boolean;
171
+ gridlines: boolean;
172
+ textBoundaries: boolean;
173
+ };
174
+ /** The mode. */
175
+ setMode: EditorState['mode'];
176
+ }
177
+ /** A command's entry in {@link EditorState.commands}. */
178
+ export interface CommandState<K extends CommandId = CommandId> {
179
+ /** Whether running it now would succeed. */
180
+ enabled: boolean;
181
+ /** For on/off commands: whether it is on. */
182
+ checked?: boolean;
183
+ /** The command's state value, where it has one. */
184
+ value?: K extends keyof CommandValues ? CommandValues[K] : never;
185
+ }
186
+ /** What is selected. No document position is public. */
187
+ export interface SelectionSummary {
188
+ /** A caret, text, table cells, an object, or an element. */
189
+ kind: 'caret' | 'text' | 'cells' | 'object' | 'element';
190
+ /** The story the selection is in. */
191
+ story: 'body' | 'header' | 'footer' | 'footnote' | 'endnote' | 'textBox';
192
+ /** The page of the caret. */
193
+ page: number;
194
+ /** The selection mode. */
195
+ mode: 'normal' | 'extend' | 'block';
196
+ /** Nothing is selected (a caret). */
197
+ empty: boolean;
198
+ /**
199
+ * The selection as plain text, paragraphs separated by `\n` (`''` for a caret), or `null` when it is longer than
200
+ * 10,000 characters.
201
+ */
202
+ text: string | null;
203
+ /** The table around the selection, if any. */
204
+ table: TableSelection | null;
205
+ /** The selected object, if any. */
206
+ object: ObjectSelection | null;
207
+ /** Innermost first: the element the selection is in or covers, then its parents. */
208
+ context: ElementContext[];
209
+ /** The link at the selection, if any. */
210
+ link: {
211
+ address: string;
212
+ text: string;
213
+ } | null;
214
+ /** The comment thread at the caret. */
215
+ comment: CommentId | null;
216
+ /** The revision at the caret. */
217
+ revision: RevisionId | null;
218
+ /** Set while a header or footer is being edited. */
219
+ headerFooter: {
220
+ kind: 'header' | 'footer';
221
+ type: 'default' | 'first' | 'even';
222
+ section: number;
223
+ page: number;
224
+ /** For example `'First Page Header -Section 2-'`. */
225
+ label: string;
226
+ } | null;
227
+ }
228
+ /** The table around the selection. */
229
+ export interface TableSelection {
230
+ /** The row count. */
231
+ rows: number;
232
+ /** The column count. */
233
+ columns: number;
234
+ /** The current cell's row, 0-based. */
235
+ row: number;
236
+ /** The current cell's column, 0-based. */
237
+ column: number;
238
+ /** Whether the selected cells can merge. */
239
+ canMerge: boolean;
240
+ /** Repeat as header row. */
241
+ headerRow: Tri;
242
+ /** Rows can break across pages. */
243
+ rowCanBreak: Tri;
244
+ /** The vertical cell alignment. */
245
+ cellAlignment: Mixed<'top' | 'center' | 'bottom'>;
246
+ /** The cell shading. */
247
+ cellShading: Mixed<Color | 'none'>;
248
+ /** The row height. */
249
+ rowHeight: Mixed<RowHeight>;
250
+ /** The column width. */
251
+ columnWidth: Mixed<Points>;
252
+ /** The table style. */
253
+ style: StyleId | null;
254
+ /** The table style options. */
255
+ styleOptions: TableStyleOptions;
256
+ /** The table width. */
257
+ width: TableWidth;
258
+ /** The table alignment. */
259
+ alignment: 'left' | 'center' | 'right';
260
+ /** The table indent. */
261
+ indent: Points;
262
+ }
263
+ /** A row height. */
264
+ export type RowHeight = {
265
+ height: Points;
266
+ rule: 'atLeast' | 'exact';
267
+ } | 'auto';
268
+ /** Which parts of a table style apply. */
269
+ export interface TableStyleOptions {
270
+ /** The header row. */
271
+ headerRow: boolean;
272
+ /** The total row. */
273
+ totalRow: boolean;
274
+ /** The first column. */
275
+ firstColumn: boolean;
276
+ /** The last column. */
277
+ lastColumn: boolean;
278
+ /** Banded rows. */
279
+ bandedRows: boolean;
280
+ /** Banded columns. */
281
+ bandedColumns: boolean;
282
+ }
283
+ /** A table width. */
284
+ export type TableWidth = {
285
+ kind: 'auto';
286
+ } | {
287
+ kind: 'points';
288
+ value: Points;
289
+ } | {
290
+ kind: 'percent';
291
+ value: number;
292
+ };
293
+ /** The selected picture or text box. */
294
+ export interface ObjectSelection {
295
+ /** A picture or a text box. */
296
+ kind: 'picture' | 'textBox';
297
+ /** How text wraps around it. */
298
+ wrap: ObjectWrap;
299
+ /** The width. */
300
+ width: Points;
301
+ /** The height. */
302
+ height: Points;
303
+ /** The alternative text. */
304
+ altText: string;
305
+ /** Marked decorative. */
306
+ decorative: boolean;
307
+ /** Whether a floating object's anchor is locked; `null` when inline. */
308
+ anchorLocked: boolean | null;
309
+ }
310
+ /** How text wraps around an object. */
311
+ export type ObjectWrap = 'inline' | 'square' | 'tight' | 'through' | 'topAndBottom' | 'behindText' | 'inFrontOfText';
312
+ /** An element the selection is in or covers. */
313
+ export interface ElementContext {
314
+ /** The element. */
315
+ id: ElementId;
316
+ /** Its kind. */
317
+ kind: 'field' | ControlKind | 'repeatingItem';
318
+ /** The selection covers exactly this element. */
319
+ exact: boolean;
320
+ /** A field's code. */
321
+ code?: string;
322
+ /** A control's tag. */
323
+ tag?: string;
324
+ /** A control's title. */
325
+ title?: string;
326
+ }
327
+ /** The selection's character formatting. */
328
+ export interface CharacterFormatting {
329
+ /** The document's family, never the substituted one. */
330
+ font: Mixed<string>;
331
+ /** The size. */
332
+ size: Mixed<Points>;
333
+ /** Bold. */
334
+ bold: Tri;
335
+ /** Italic. */
336
+ italic: Tri;
337
+ /** The underline style. */
338
+ underline: Mixed<UnderlineStyle>;
339
+ /** Strikethrough. */
340
+ strikethrough: Tri;
341
+ /** Double strikethrough. */
342
+ doubleStrikethrough: Tri;
343
+ /** Subscript. */
344
+ subscript: Tri;
345
+ /** Superscript. */
346
+ superscript: Tri;
347
+ /** Small caps. */
348
+ smallCaps: Tri;
349
+ /** All caps. */
350
+ allCaps: Tri;
351
+ /** Hidden. */
352
+ hidden: Tri;
353
+ /** The colour. */
354
+ color: Mixed<Color | 'auto'>;
355
+ /** The highlight. */
356
+ highlight: Mixed<HighlightColor | 'none'>;
357
+ /** The character spacing. */
358
+ characterSpacing: Mixed<Points>;
359
+ /** The raised (positive) or lowered position. */
360
+ position: Mixed<Points>;
361
+ }
362
+ /** The selection's paragraph formatting. */
363
+ export interface ParagraphFormatting {
364
+ /** The paragraph style. */
365
+ style: Mixed<StyleId>;
366
+ /** The alignment. */
367
+ alignment: Mixed<'left' | 'center' | 'right' | 'justify'>;
368
+ /** The line spacing. */
369
+ lineSpacing: Mixed<LineSpacing>;
370
+ /** The space before. */
371
+ spaceBefore: Mixed<Points | 'auto'>;
372
+ /** The space after. */
373
+ spaceAfter: Mixed<Points | 'auto'>;
374
+ /** The indents. */
375
+ indents: {
376
+ left: Mixed<Points>;
377
+ right: Mixed<Points>;
378
+ firstLine: Mixed<Points>;
379
+ hanging: Mixed<Points>;
380
+ };
381
+ /** The list kind. */
382
+ list: Mixed<'bullet' | 'numbered' | 'none'>;
383
+ /** The list level. */
384
+ listLevel: Mixed<number>;
385
+ /** The pagination flags. */
386
+ flow: {
387
+ keepWithNext: Tri;
388
+ keepLinesTogether: Tri;
389
+ pageBreakBefore: Tri;
390
+ widowControl: Tri;
391
+ };
392
+ /** The borders. */
393
+ borders: Mixed<'box' | 'bottom' | 'none' | 'other'>;
394
+ /** The shading. */
395
+ shading: Mixed<Color | 'none'>;
396
+ }
397
+ /** The selection's section. */
398
+ export interface PageFormatting {
399
+ /** The paper size. */
400
+ size: {
401
+ width: Points;
402
+ height: Points;
403
+ };
404
+ /** The orientation. */
405
+ orientation: 'portrait' | 'landscape';
406
+ /** The margins. */
407
+ margins: {
408
+ top: Points;
409
+ bottom: Points;
410
+ left: Points;
411
+ right: Points;
412
+ gutter: Points;
413
+ };
414
+ /** The text columns. */
415
+ columns: {
416
+ count: number;
417
+ spacing: Points;
418
+ separator: boolean;
419
+ };
420
+ /** The header distance from the page edge. */
421
+ headerDistance: Points;
422
+ /** The footer distance from the page edge. */
423
+ footerDistance: Points;
424
+ /** A different first page. */
425
+ differentFirstPage: boolean;
426
+ /** Different odd and even pages. */
427
+ differentOddEven: boolean;
428
+ }
429
+ /** View settings. */
430
+ export interface ViewState {
431
+ /** Percent, after any fit. */
432
+ zoom: number;
433
+ /** Formatting marks are shown. */
434
+ formattingMarks: boolean;
435
+ /** Table gridlines are shown. */
436
+ gridlines: boolean;
437
+ /** Text boundaries are shown. */
438
+ textBoundaries: boolean;
439
+ /** Field codes are shown. */
440
+ fieldCodes: boolean;
441
+ /** Which built-in rulers are shown. */
442
+ rulers: {
443
+ horizontal: boolean;
444
+ vertical: boolean;
445
+ };
446
+ /** The ruler unit. */
447
+ rulerUnit: RulerUnit;
448
+ /** What a click on the ruler adds. */
449
+ tabSelector: TabSelector;
450
+ /** The room beside the pages for balloons, CSS px. */
451
+ markupPaneWidth: number;
452
+ /** The editor background around the pages. */
453
+ background: Color;
454
+ }
455
+ /** Track changes and comments. */
456
+ export interface ReviewState {
457
+ /** Changes are tracked. */
458
+ tracking: boolean;
459
+ /** Document protection keeps tracking on. */
460
+ trackingLocked: boolean;
461
+ /** The markup view. */
462
+ markupView: MarkupView;
463
+ /** The revision count. */
464
+ revisions: number;
465
+ /** The comment count. */
466
+ comments: number;
467
+ /** The active comment thread. */
468
+ activeComment: CommentId | null;
469
+ }
470
+ /** How tracked changes are shown. */
471
+ export type MarkupView = 'all' | 'simple' | 'noMarkup' | 'original';
472
+ /** A line spacing. */
473
+ export type LineSpacing = {
474
+ rule: 'multiple';
475
+ lines: number;
476
+ } | {
477
+ rule: 'exact' | 'atLeast';
478
+ size: Points;
479
+ };
480
+ /** An underline style. */
481
+ export type UnderlineStyle = 'none' | 'single' | 'words' | 'double' | 'thick' | 'dotted' | 'dash' | 'dotDash' | 'wave';
482
+ /** A highlight colour. */
483
+ export type HighlightColor = 'yellow' | 'brightGreen' | 'turquoise' | 'pink' | 'blue' | 'red' | 'darkBlue' | 'teal' | 'green' | 'violet' | 'darkRed' | 'darkYellow' | 'gray50' | 'gray25' | 'black';
package/dist/state.js ADDED
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,31 @@
1
+ import type { FaceInfo } from '../fonts/library.js';
2
+ import type { Warning } from '../types.js';
3
+ import { type Backend, type FrameInfo, type Input, type Message, Method, type Transport } from './protocol.js';
4
+ /** The page's one direct transport, loading the engine module on first use. */
5
+ export declare function directTransport(): Promise<DirectTransport>;
6
+ /** The {@link Transport} that calls the engine module on this thread. */
7
+ export declare class DirectTransport implements Transport {
8
+ #private;
9
+ private constructor();
10
+ /** Loads the module and creates the page's engine. */
11
+ static load(): Promise<DirectTransport>;
12
+ createSession(options: object): Promise<number>;
13
+ closeSession(session: number): Promise<void>;
14
+ call(session: number, method: Method, request?: unknown): Promise<unknown>;
15
+ open(session: number, bytes: Uint8Array, signal?: AbortSignal): Promise<Warning[]>;
16
+ openPrepare(session: number, bytes: Uint8Array): Promise<number>;
17
+ openCommit(session: number, token: number): Promise<Warning[]>;
18
+ openDiscard(session: number, token: number): Promise<void>;
19
+ export(session: number, options: {
20
+ format: 'docx' | 'pdf';
21
+ }, signal?: AbortSignal): Promise<{
22
+ bytes: Uint8Array<ArrayBufferLike>;
23
+ revision: number;
24
+ warnings: Warning[];
25
+ }>;
26
+ addFont(bytes: Uint8Array): Promise<FaceInfo[]>;
27
+ input(session: number, input: Input): Promise<number>;
28
+ attachCanvas(session: number, canvas: HTMLCanvasElement): Promise<Backend>;
29
+ frame(session: number, width: number, height: number): Promise<FrameInfo | null>;
30
+ listen(session: number, listener: (message: Message) => void): () => void;
31
+ }