@twip/web 0.1.0-alpha.1 → 0.1.0-pre.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +35 -0
- package/dist/THIRD-PARTY-NOTICES.md +1013 -225
- package/dist/commands.d.ts +637 -0
- package/dist/commands.js +188 -0
- package/dist/editor.d.ts +218 -0
- package/dist/editor.js +460 -0
- package/dist/errors.d.ts +21 -0
- package/dist/errors.js +26 -0
- package/dist/events.d.ts +126 -0
- package/dist/events.js +1 -0
- package/dist/fonts/google.d.ts +3 -0
- package/dist/fonts/google.js +39 -0
- package/dist/fonts/library.d.ts +65 -0
- package/dist/fonts/library.js +130 -0
- package/dist/host/a11y.d.ts +3 -0
- package/dist/host/a11y.js +62 -0
- package/dist/host/chrome.d.ts +28 -0
- package/dist/host/chrome.js +144 -0
- package/dist/host/clipboard.d.ts +16 -0
- package/dist/host/clipboard.js +128 -0
- package/dist/host/dom.d.ts +45 -0
- package/dist/host/dom.js +122 -0
- package/dist/host/frames.d.ts +14 -0
- package/dist/host/frames.js +87 -0
- package/dist/host/gpu.d.ts +58 -0
- package/dist/host/gpu.js +79 -0
- package/dist/host/ime.d.ts +3 -0
- package/dist/host/ime.js +11 -0
- package/dist/host/input.d.ts +12 -0
- package/dist/host/input.js +86 -0
- package/dist/host/keys.d.ts +16 -0
- package/dist/host/keys.js +27 -0
- package/dist/host/mount.d.ts +11 -0
- package/dist/host/mount.js +72 -0
- package/dist/host/pointer.d.ts +4 -0
- package/dist/host/pointer.js +171 -0
- package/dist/host/scroll.d.ts +14 -0
- package/dist/host/scroll.js +95 -0
- package/dist/index.d.ts +27 -98
- package/dist/index.js +10 -0
- package/dist/review.d.ts +156 -0
- package/dist/review.js +38 -0
- package/dist/services/accessibility.d.ts +52 -0
- package/dist/services/accessibility.js +71 -0
- package/dist/services/dialogs.d.ts +181 -0
- package/dist/services/dialogs.js +18 -0
- package/dist/services/elements.d.ts +146 -0
- package/dist/services/elements.js +18 -0
- package/dist/services/find.d.ts +50 -0
- package/dist/services/find.js +12 -0
- package/dist/services/menus.d.ts +82 -0
- package/dist/services/menus.js +8 -0
- package/dist/services/navigation.d.ts +58 -0
- package/dist/services/navigation.js +12 -0
- package/dist/services/ruler.d.ts +95 -0
- package/dist/services/ruler.js +16 -0
- package/dist/services/spelling.d.ts +34 -0
- package/dist/services/spelling.js +14 -0
- package/dist/services/view.d.ts +70 -0
- package/dist/services/view.js +19 -0
- package/dist/state.d.ts +483 -0
- package/dist/state.js +1 -0
- package/dist/transport/direct.d.ts +31 -0
- package/dist/transport/direct.js +405 -0
- package/dist/transport/module.d.ts +51 -0
- package/dist/transport/module.js +17 -0
- package/dist/transport/protocol.d.ts +265 -0
- package/dist/transport/protocol.js +132 -0
- package/dist/transport/worker.d.ts +54 -0
- package/dist/transport/worker.js +203 -0
- package/dist/twip-wasm.js +1 -1
- package/dist/twip_wasm.wasm +0 -0
- package/dist/types.d.ts +134 -0
- package/dist/types.js +16 -0
- package/dist/worker/entry.d.ts +1 -0
- package/dist/worker/entry.js +53 -0
- package/dist/worker.d.ts +1 -0
- package/dist/worker.js +2 -0
- package/package.json +17 -7
- package/dist/AccessibleNode.d.ts +0 -51
- package/dist/AccessibleNode.mjs +0 -177
- package/dist/Alignment.d.ts +0 -38
- package/dist/Alignment.mjs +0 -90
- package/dist/BorderEdges.d.ts +0 -50
- package/dist/BorderEdges.mjs +0 -114
- package/dist/BorderStyle.d.ts +0 -27
- package/dist/BorderStyle.mjs +0 -81
- package/dist/Bytes.d.ts +0 -19
- package/dist/Bytes.mjs +0 -76
- package/dist/CaretPosition.d.ts +0 -34
- package/dist/CaretPosition.mjs +0 -148
- package/dist/CellAlignment.d.ts +0 -25
- package/dist/CellAlignment.mjs +0 -75
- package/dist/CellShift.d.ts +0 -30
- package/dist/CellShift.mjs +0 -78
- package/dist/Clipboard.d.ts +0 -22
- package/dist/Clipboard.mjs +0 -90
- package/dist/ColumnSide.d.ts +0 -24
- package/dist/ColumnSide.mjs +0 -72
- package/dist/ControlKind.d.ts +0 -28
- package/dist/ControlKind.mjs +0 -84
- package/dist/ControlLock.d.ts +0 -42
- package/dist/ControlLock.mjs +0 -96
- package/dist/DocumentStatus.d.ts +0 -34
- package/dist/DocumentStatus.mjs +0 -148
- package/dist/Editor.d.ts +0 -773
- package/dist/Editor.mjs +0 -2269
- package/dist/EditorMode.d.ts +0 -34
- package/dist/EditorMode.mjs +0 -84
- package/dist/Element.d.ts +0 -57
- package/dist/Element.mjs +0 -201
- package/dist/ElementKind.d.ts +0 -28
- package/dist/ElementKind.mjs +0 -78
- package/dist/ElementList.d.ts +0 -20
- package/dist/ElementList.mjs +0 -71
- package/dist/ElementText.d.ts +0 -34
- package/dist/ElementText.mjs +0 -84
- package/dist/Event.d.ts +0 -45
- package/dist/Event.mjs +0 -159
- package/dist/EventKind.d.ts +0 -39
- package/dist/EventKind.mjs +0 -93
- package/dist/EventList.d.ts +0 -20
- package/dist/EventList.mjs +0 -71
- package/dist/Fonts.d.ts +0 -29
- package/dist/Fonts.mjs +0 -107
- package/dist/Highlight.d.ts +0 -41
- package/dist/Highlight.mjs +0 -117
- package/dist/MarginPreset.d.ts +0 -38
- package/dist/MarginPreset.mjs +0 -90
- package/dist/MarkSeverity.d.ts +0 -25
- package/dist/MarkSeverity.mjs +0 -75
- package/dist/Modifiers.d.ts +0 -34
- package/dist/Modifiers.mjs +0 -148
- package/dist/OpenError.d.ts +0 -30
- package/dist/OpenError.mjs +0 -78
- package/dist/Orientation.d.ts +0 -30
- package/dist/Orientation.mjs +0 -78
- package/dist/PageNumber.d.ts +0 -34
- package/dist/PageNumber.mjs +0 -84
- package/dist/PaperSize.d.ts +0 -50
- package/dist/PaperSize.mjs +0 -108
- package/dist/ParagraphBorders.d.ts +0 -34
- package/dist/ParagraphBorders.mjs +0 -84
- package/dist/PictureWrap.d.ts +0 -34
- package/dist/PictureWrap.mjs +0 -90
- package/dist/PointerKind.d.ts +0 -23
- package/dist/PointerKind.mjs +0 -75
- package/dist/Rect.d.ts +0 -34
- package/dist/Rect.mjs +0 -148
- package/dist/Request.d.ts +0 -55
- package/dist/Request.mjs +0 -207
- package/dist/RequestKind.d.ts +0 -45
- package/dist/RequestKind.mjs +0 -105
- package/dist/RequestList.d.ts +0 -20
- package/dist/RequestList.mjs +0 -71
- package/dist/RowHeightRule.d.ts +0 -34
- package/dist/RowHeightRule.mjs +0 -84
- package/dist/RowSide.d.ts +0 -24
- package/dist/RowSide.mjs +0 -72
- package/dist/SaveError.d.ts +0 -24
- package/dist/SaveError.mjs +0 -72
- package/dist/SelectionInfo.d.ts +0 -39
- package/dist/SelectionInfo.mjs +0 -166
- package/dist/SelectionKind.d.ts +0 -37
- package/dist/SelectionKind.mjs +0 -93
- package/dist/TableAlignment.d.ts +0 -25
- package/dist/TableAlignment.mjs +0 -75
- package/dist/TableSelection.d.ts +0 -38
- package/dist/TableSelection.mjs +0 -90
- package/dist/TableWidthUnit.d.ts +0 -31
- package/dist/TableWidthUnit.mjs +0 -81
- package/dist/TextUnit.d.ts +0 -25
- package/dist/TextUnit.mjs +0 -75
- package/dist/diplomat-runtime.d.ts +0 -15
- package/dist/diplomat-runtime.mjs +0 -786
- package/dist/diplomat-wasm.mjs +0 -18
- package/dist/gpu.d.ts +0 -15
- package/dist/gpu.mjs +0 -42
- package/dist/index.mjs +0 -101
package/dist/commands.js
ADDED
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
/** How each command's argument travels: checked against {@link Encoding} by the compiler. */
|
|
2
|
+
const encodings = {
|
|
3
|
+
insertText: 'value',
|
|
4
|
+
insertParagraph: 'none',
|
|
5
|
+
insertLineBreak: 'none',
|
|
6
|
+
insertPageBreak: 'none',
|
|
7
|
+
insertColumnBreak: 'none',
|
|
8
|
+
insertSectionBreak: 'value',
|
|
9
|
+
insertTab: 'none',
|
|
10
|
+
insertSymbol: 'spread',
|
|
11
|
+
delete: 'spread',
|
|
12
|
+
cut: 'none',
|
|
13
|
+
copy: 'none',
|
|
14
|
+
paste: 'spread',
|
|
15
|
+
pasteText: 'value',
|
|
16
|
+
undo: 'none',
|
|
17
|
+
redo: 'none',
|
|
18
|
+
repeat: 'none',
|
|
19
|
+
selectAll: 'none',
|
|
20
|
+
select: 'value',
|
|
21
|
+
moveSelection: 'spread',
|
|
22
|
+
moveToCell: 'value',
|
|
23
|
+
setSelectionMode: 'value',
|
|
24
|
+
goBack: 'none',
|
|
25
|
+
escape: 'none',
|
|
26
|
+
selectNextObject: 'value',
|
|
27
|
+
goToPage: 'value',
|
|
28
|
+
setBold: 'value',
|
|
29
|
+
setItalic: 'value',
|
|
30
|
+
setUnderline: 'value',
|
|
31
|
+
setStrikethrough: 'value',
|
|
32
|
+
setDoubleStrikethrough: 'value',
|
|
33
|
+
setSubscript: 'value',
|
|
34
|
+
setSuperscript: 'value',
|
|
35
|
+
setSmallCaps: 'value',
|
|
36
|
+
setAllCaps: 'value',
|
|
37
|
+
setHidden: 'value',
|
|
38
|
+
setFont: 'value',
|
|
39
|
+
setFontSize: 'value',
|
|
40
|
+
growFont: 'none',
|
|
41
|
+
shrinkFont: 'none',
|
|
42
|
+
setFontColor: 'value',
|
|
43
|
+
setHighlight: 'value',
|
|
44
|
+
setCharacterSpacing: 'value',
|
|
45
|
+
setCharacterPosition: 'value',
|
|
46
|
+
clearFormatting: 'none',
|
|
47
|
+
changeCase: 'value',
|
|
48
|
+
copyFormatting: 'none',
|
|
49
|
+
pasteFormatting: 'none',
|
|
50
|
+
setAlignment: 'value',
|
|
51
|
+
setLineSpacing: 'spread',
|
|
52
|
+
setParagraphSpacing: 'spread',
|
|
53
|
+
setIndents: 'spread',
|
|
54
|
+
increaseIndent: 'none',
|
|
55
|
+
decreaseIndent: 'none',
|
|
56
|
+
setParagraphStyle: 'value',
|
|
57
|
+
setList: 'value',
|
|
58
|
+
setListLevel: 'value',
|
|
59
|
+
setParagraphFlow: 'spread',
|
|
60
|
+
setParagraphBorders: 'value',
|
|
61
|
+
setParagraphShading: 'value',
|
|
62
|
+
addTabStop: 'spread',
|
|
63
|
+
moveTabStop: 'spread',
|
|
64
|
+
deleteTabStop: 'value',
|
|
65
|
+
clearTabStops: 'none',
|
|
66
|
+
setDefaultTabStop: 'value',
|
|
67
|
+
setMargins: 'spread',
|
|
68
|
+
setOrientation: 'value',
|
|
69
|
+
setPaperSize: 'spread',
|
|
70
|
+
setColumns: 'spread',
|
|
71
|
+
setHeaderFooterDistance: 'spread',
|
|
72
|
+
setDifferentFirstPage: 'value',
|
|
73
|
+
setDifferentOddEvenPages: 'value',
|
|
74
|
+
moveColumnBoundary: 'spread',
|
|
75
|
+
editHeader: 'none',
|
|
76
|
+
editFooter: 'none',
|
|
77
|
+
closeHeaderFooter: 'none',
|
|
78
|
+
insertPageNumber: 'spread',
|
|
79
|
+
insertTable: 'spread',
|
|
80
|
+
insertPicture: 'spread',
|
|
81
|
+
insertTextBox: 'none',
|
|
82
|
+
insertFootnote: 'none',
|
|
83
|
+
insertEndnote: 'none',
|
|
84
|
+
insertHyperlink: 'spread',
|
|
85
|
+
editHyperlink: 'spread',
|
|
86
|
+
removeHyperlink: 'none',
|
|
87
|
+
insertField: 'spread',
|
|
88
|
+
insertRows: 'spread',
|
|
89
|
+
insertColumns: 'spread',
|
|
90
|
+
deleteRows: 'none',
|
|
91
|
+
deleteColumns: 'none',
|
|
92
|
+
deleteTable: 'none',
|
|
93
|
+
deleteCells: 'value',
|
|
94
|
+
mergeCells: 'none',
|
|
95
|
+
splitCells: 'spread',
|
|
96
|
+
splitTable: 'none',
|
|
97
|
+
distributeRows: 'none',
|
|
98
|
+
distributeColumns: 'none',
|
|
99
|
+
moveRows: 'value',
|
|
100
|
+
autoFitColumns: 'value',
|
|
101
|
+
setCellAlignment: 'value',
|
|
102
|
+
setCellShading: 'value',
|
|
103
|
+
setCellBorders: 'spread',
|
|
104
|
+
setCellMargins: 'spread',
|
|
105
|
+
setHeaderRow: 'value',
|
|
106
|
+
setRowHeight: 'value',
|
|
107
|
+
setRowCanBreak: 'value',
|
|
108
|
+
setColumnWidth: 'value',
|
|
109
|
+
moveTableColumnBoundary: 'spread',
|
|
110
|
+
moveTableRowBoundary: 'spread',
|
|
111
|
+
setTableWidth: 'spread',
|
|
112
|
+
setTableAlignment: 'value',
|
|
113
|
+
setTableIndent: 'value',
|
|
114
|
+
setTableStyle: 'value',
|
|
115
|
+
setTableStyleOptions: 'spread',
|
|
116
|
+
setObjectSize: 'spread',
|
|
117
|
+
resetObjectSize: 'none',
|
|
118
|
+
setObjectWrap: 'value',
|
|
119
|
+
setAnchorLocked: 'value',
|
|
120
|
+
setAltText: 'spread',
|
|
121
|
+
deleteObject: 'none',
|
|
122
|
+
setField: 'spread',
|
|
123
|
+
setFieldResults: 'spread',
|
|
124
|
+
updateFields: 'spread',
|
|
125
|
+
setFieldsLocked: 'spread',
|
|
126
|
+
unlinkFields: 'spread',
|
|
127
|
+
showFieldCodes: 'spread',
|
|
128
|
+
setFieldLabels: 'spread',
|
|
129
|
+
insertControl: 'spread',
|
|
130
|
+
setControl: 'spread',
|
|
131
|
+
removeControl: 'spread',
|
|
132
|
+
fillControl: 'spread',
|
|
133
|
+
setCheckbox: 'spread',
|
|
134
|
+
wrapInRepeatingSection: 'spread',
|
|
135
|
+
removeElement: 'value',
|
|
136
|
+
replaceInElements: 'spread',
|
|
137
|
+
markElements: 'spread',
|
|
138
|
+
setPlaceholderLooks: 'spread',
|
|
139
|
+
fillPlaceholder: 'spread',
|
|
140
|
+
writeDataPart: 'spread',
|
|
141
|
+
removeDataPart: 'spread',
|
|
142
|
+
setTrackChanges: 'value',
|
|
143
|
+
setMarkupView: 'value',
|
|
144
|
+
acceptRevision: 'value',
|
|
145
|
+
rejectRevision: 'value',
|
|
146
|
+
acceptRevisionsInSelection: 'none',
|
|
147
|
+
rejectRevisionsInSelection: 'none',
|
|
148
|
+
acceptAllRevisions: 'spread',
|
|
149
|
+
rejectAllRevisions: 'spread',
|
|
150
|
+
selectRevision: 'value',
|
|
151
|
+
addComment: 'value',
|
|
152
|
+
replyToComment: 'spread',
|
|
153
|
+
editComment: 'spread',
|
|
154
|
+
deleteComment: 'value',
|
|
155
|
+
resolveComment: 'spread',
|
|
156
|
+
setActiveComment: 'value',
|
|
157
|
+
selectComment: 'value',
|
|
158
|
+
setAuthorColor: 'spread',
|
|
159
|
+
setZoom: 'value',
|
|
160
|
+
setViewOptions: 'spread',
|
|
161
|
+
setMode: 'value',
|
|
162
|
+
};
|
|
163
|
+
/** Builds a command's op from its method arguments. */
|
|
164
|
+
export function toOp(id, arg) {
|
|
165
|
+
const how = encodings[id];
|
|
166
|
+
if (how === 'none' || arg === undefined)
|
|
167
|
+
return { type: id };
|
|
168
|
+
if (how === 'value')
|
|
169
|
+
return { type: id, value: arg };
|
|
170
|
+
return { type: id, ...arg };
|
|
171
|
+
}
|
|
172
|
+
/** The inverse of {@link toOp}: the command id and its method argument. */
|
|
173
|
+
export function fromOp(op) {
|
|
174
|
+
const { type, ...fields } = op;
|
|
175
|
+
const how = encodings[type];
|
|
176
|
+
if (how === 'none')
|
|
177
|
+
return [type, undefined];
|
|
178
|
+
if (how === 'value')
|
|
179
|
+
return [type, fields.value];
|
|
180
|
+
return [type, fields];
|
|
181
|
+
}
|
|
182
|
+
/** Builds the `commands` object: every method turns its arguments into an op and runs it. */
|
|
183
|
+
export function createCommands(run) {
|
|
184
|
+
const commands = {};
|
|
185
|
+
for (const id of Object.keys(encodings))
|
|
186
|
+
commands[id] = (arg) => run(toOp(id, arg));
|
|
187
|
+
return Object.freeze(commands);
|
|
188
|
+
}
|
package/dist/editor.d.ts
ADDED
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
import { type CommandInfo, type Commands, type Op } from './commands.js';
|
|
2
|
+
import type { TwipEvents } from './events.js';
|
|
3
|
+
import { FontLibrary } from './fonts/library.js';
|
|
4
|
+
import { type MountedReview, type Review } from './review.js';
|
|
5
|
+
import { type Accessibility, type Shortcuts } from './services/accessibility.js';
|
|
6
|
+
import { type Dialogs } from './services/dialogs.js';
|
|
7
|
+
import { type DataParts, type Elements, type MountedElements } from './services/elements.js';
|
|
8
|
+
import { type Find } from './services/find.js';
|
|
9
|
+
import { type Menus } from './services/menus.js';
|
|
10
|
+
import { type Navigation, type Styles } from './services/navigation.js';
|
|
11
|
+
import { type Ruler, type RulerModelSource, type RulerUnit } from './services/ruler.js';
|
|
12
|
+
import { type Dictionary, type Spelling } from './services/spelling.js';
|
|
13
|
+
import { type Gestures, type View } from './services/view.js';
|
|
14
|
+
import type { EditorState } from './state.js';
|
|
15
|
+
import { type FrameInfo, Method, type Input, type Message, type Transport } from './transport/protocol.js';
|
|
16
|
+
import type { Author, Color, OverlayColors, Warning, WordCount } from './types.js';
|
|
17
|
+
/** Options for a new session. */
|
|
18
|
+
export interface SessionOptions {
|
|
19
|
+
/** Start read only. Default false. */
|
|
20
|
+
readOnly?: boolean;
|
|
21
|
+
/** Start in editing (the default) or design mode. */
|
|
22
|
+
mode?: 'editing' | 'design';
|
|
23
|
+
/** Who makes changes. */
|
|
24
|
+
author?: Author;
|
|
25
|
+
/** The fonts to draw with: share one per page, {@link FontLibrary.default} (the default). */
|
|
26
|
+
fonts?: FontLibrary;
|
|
27
|
+
/** The default language, BCP 47. Default `'en-US'`. */
|
|
28
|
+
language?: string;
|
|
29
|
+
/** Spelling dictionaries. */
|
|
30
|
+
dictionaries?: Dictionary[];
|
|
31
|
+
/** Turns tracking on after open, unless the document locks it. */
|
|
32
|
+
trackChanges?: boolean;
|
|
33
|
+
}
|
|
34
|
+
/** Options for {@link Editor.mount}. */
|
|
35
|
+
export interface MountOptions extends SessionOptions {
|
|
36
|
+
/** The document to open; blank when absent. */
|
|
37
|
+
document?: Uint8Array;
|
|
38
|
+
/** Where the engine runs. Default `'auto'`: a worker where supported. */
|
|
39
|
+
execution?: 'auto' | 'main' | 'worker';
|
|
40
|
+
/** The built-in rulers. Default off. */
|
|
41
|
+
rulers?: boolean | {
|
|
42
|
+
horizontal?: boolean;
|
|
43
|
+
vertical?: boolean;
|
|
44
|
+
};
|
|
45
|
+
/** The ruler unit. Default from `language`: inches for en-US, centimeters otherwise. */
|
|
46
|
+
rulerUnit?: RulerUnit;
|
|
47
|
+
/** Room beside the pages for balloons, CSS px. Default 0. */
|
|
48
|
+
markupPaneWidth?: number;
|
|
49
|
+
/** The zoom. Default 100. */
|
|
50
|
+
zoom?: number | 'pageWidth' | 'wholePage';
|
|
51
|
+
/** The background around the pages. Default `'#E6E6E6'`; the paper stays white. */
|
|
52
|
+
background?: Color;
|
|
53
|
+
/**
|
|
54
|
+
* The caret's blink: ms per phase, 0 for a steady caret. Default 530, or steady while the platform asks for reduced
|
|
55
|
+
* motion (`prefers-reduced-motion`), which the editor then follows.
|
|
56
|
+
*/
|
|
57
|
+
caretBlink?: number;
|
|
58
|
+
/** Stop blinking after this many ms without input, the caret left visible. Default: never. */
|
|
59
|
+
caretBlinkStopAfter?: number;
|
|
60
|
+
/**
|
|
61
|
+
* The colours of what the editor draws over the document. Default: the engine's, or the system's colours while the
|
|
62
|
+
* platform is in forced-colours (high contrast) mode, which the editor then follows.
|
|
63
|
+
*/
|
|
64
|
+
overlayColors?: Partial<OverlayColors>;
|
|
65
|
+
/**
|
|
66
|
+
* The memory the editor keeps pages' drawing in, bytes: their recordings (default 32 MB). Past it, what was drawn
|
|
67
|
+
* longest ago goes first.
|
|
68
|
+
*/
|
|
69
|
+
paintBudget?: {
|
|
70
|
+
recordings?: number;
|
|
71
|
+
};
|
|
72
|
+
/**
|
|
73
|
+
* The editor draws each attached balloon's leader line (from `balloonsLaidOut`'s placements) in the overlay colours'
|
|
74
|
+
* `leaders` colour, so the application draws only the cards. Default false: the application draws them.
|
|
75
|
+
*/
|
|
76
|
+
drawLeaders?: boolean;
|
|
77
|
+
/** Aborts the mount; everything it created is released. */
|
|
78
|
+
signal?: AbortSignal;
|
|
79
|
+
}
|
|
80
|
+
/** An exported document. */
|
|
81
|
+
export interface ExportResult {
|
|
82
|
+
/** The file. */
|
|
83
|
+
bytes: Uint8Array;
|
|
84
|
+
/** The revision it captures; later edits don't change these bytes. */
|
|
85
|
+
revision: number;
|
|
86
|
+
/** Fidelity warnings. */
|
|
87
|
+
warnings: Warning[];
|
|
88
|
+
}
|
|
89
|
+
/** A request in the engine's JSON shape: bytes travel as base64. */
|
|
90
|
+
export declare function toWire(value: unknown): unknown;
|
|
91
|
+
/** One editor's session over a transport: the state cache, the listeners and the calls. Internal. */
|
|
92
|
+
export declare class Session {
|
|
93
|
+
#private;
|
|
94
|
+
readonly transport: Transport;
|
|
95
|
+
readonly id: number;
|
|
96
|
+
state: EditorState;
|
|
97
|
+
readonly catalog: readonly CommandInfo[];
|
|
98
|
+
destroyed: boolean;
|
|
99
|
+
/** Mounted hosts listen for frame and host requests here. */
|
|
100
|
+
readonly hostListeners: Set<(message: Message) => void>;
|
|
101
|
+
/** A mounted host's view of an engine event before it is emitted: its viewport points become client points. */
|
|
102
|
+
adjust: ((type: keyof TwipEvents, event: unknown) => unknown) | undefined;
|
|
103
|
+
/** Run once on destroy, last added first. */
|
|
104
|
+
readonly disposers: (() => void)[];
|
|
105
|
+
private constructor();
|
|
106
|
+
/** Creates a session on the page's engine: on this thread, or in the page's engine worker. */
|
|
107
|
+
static start(options?: SessionOptions, execution?: 'main' | 'worker'): Promise<Session>;
|
|
108
|
+
/** Rejects `destroyed` once destroyed, or with the fault after one, else runs `call`. */
|
|
109
|
+
guard<T>(call: () => Promise<T>): Promise<T>;
|
|
110
|
+
/** A structured call, with the request in the engine's JSON shape. */
|
|
111
|
+
call<T = void>(method: Method, request?: unknown): Promise<T>;
|
|
112
|
+
/** A call that commits: resolves with its value once the state cache holds the revision it committed. */
|
|
113
|
+
commit<T = void>(method: Method, request?: unknown): Promise<T>;
|
|
114
|
+
run(op: Op): Promise<unknown>;
|
|
115
|
+
input(input: Input): Promise<number>;
|
|
116
|
+
frame(width: number, height: number): Promise<FrameInfo | null>;
|
|
117
|
+
subscribe(listener: (state: EditorState) => void): () => void;
|
|
118
|
+
on<K extends keyof TwipEvents>(type: K, listener: (event: TwipEvents[K]) => void): () => void;
|
|
119
|
+
/** Whether anything listens to `type`. */
|
|
120
|
+
listening(type: keyof TwipEvents): boolean;
|
|
121
|
+
emit<K extends keyof TwipEvents>(type: K, event: TwipEvents[K]): void;
|
|
122
|
+
destroy(): Promise<void>;
|
|
123
|
+
}
|
|
124
|
+
/** The session behind an editor. Internal: for the SDK's own hosts and tests. */
|
|
125
|
+
export declare function sessionOf(editor: HeadlessEditor): Session;
|
|
126
|
+
/** A session with no DOM: Node, workers, tests and servers. */
|
|
127
|
+
export declare class HeadlessEditor {
|
|
128
|
+
#private;
|
|
129
|
+
/** Every edit, one method per command. */
|
|
130
|
+
readonly commands: Commands;
|
|
131
|
+
/** Every command's id, label, group, shortcuts and undo grouping. */
|
|
132
|
+
readonly catalog: readonly CommandInfo[];
|
|
133
|
+
/** The context menu. */
|
|
134
|
+
readonly menus: Menus;
|
|
135
|
+
/** The dialogs. */
|
|
136
|
+
readonly dialogs: Dialogs;
|
|
137
|
+
/** Find and replace. */
|
|
138
|
+
readonly find: Find;
|
|
139
|
+
/** Spell checking. */
|
|
140
|
+
readonly spelling: Spelling;
|
|
141
|
+
/** The document's headings. */
|
|
142
|
+
readonly navigation: Navigation;
|
|
143
|
+
/** The document's styles. */
|
|
144
|
+
readonly styles: Styles;
|
|
145
|
+
/** Tracked changes and comments. */
|
|
146
|
+
readonly review: Review;
|
|
147
|
+
/** The merge designer's elements. */
|
|
148
|
+
readonly elements: Elements;
|
|
149
|
+
/** The custom XML data parts. */
|
|
150
|
+
readonly data: DataParts;
|
|
151
|
+
/** The ruler model. */
|
|
152
|
+
readonly ruler: RulerModelSource;
|
|
153
|
+
/** The accessibility tree. */
|
|
154
|
+
readonly accessibility: Accessibility;
|
|
155
|
+
/** Keyboard shortcuts. */
|
|
156
|
+
readonly shortcuts: Shortcuts;
|
|
157
|
+
/** Editors are made by {@link HeadlessEditor.create} and {@link Editor.mount}. */
|
|
158
|
+
protected constructor();
|
|
159
|
+
/** Creates a session with a blank document. */
|
|
160
|
+
static create(options?: SessionOptions): Promise<HeadlessEditor>;
|
|
161
|
+
/** Replaces the document, only after it was read successfully. Resolves with the read's warnings. */
|
|
162
|
+
open(bytes: Uint8Array, options?: {
|
|
163
|
+
signal?: AbortSignal;
|
|
164
|
+
}): Promise<{
|
|
165
|
+
warnings: Warning[];
|
|
166
|
+
}>;
|
|
167
|
+
/** Replaces the document with a blank one. */
|
|
168
|
+
newDocument(): Promise<void>;
|
|
169
|
+
/** Exports the document as DOCX or PDF, with the revision it captures. */
|
|
170
|
+
export(options: {
|
|
171
|
+
format: 'docx' | 'pdf';
|
|
172
|
+
signal?: AbortSignal;
|
|
173
|
+
}): Promise<ExportResult>;
|
|
174
|
+
/** Runs several commands atomically: one transaction and one undo step, or nothing when one fails. */
|
|
175
|
+
batch(ops: readonly Op[], options?: {
|
|
176
|
+
label?: string;
|
|
177
|
+
}): Promise<void>;
|
|
178
|
+
/** The latest state snapshot: synchronous and immutable. */
|
|
179
|
+
getState(): EditorState;
|
|
180
|
+
/** Calls `listener` with the current state now, then after every change. Returns the unsubscribe function. */
|
|
181
|
+
subscribe(listener: (state: EditorState) => void): () => void;
|
|
182
|
+
/** Listens to an event. Returns the unsubscribe function. */
|
|
183
|
+
on<K extends keyof TwipEvents>(type: K, listener: (event: TwipEvents[K]) => void): () => void;
|
|
184
|
+
/** Makes the editor read only, or editable again, without reopening. */
|
|
185
|
+
setReadOnly(value: boolean): Promise<void>;
|
|
186
|
+
/** Switches between editing and design mode. */
|
|
187
|
+
setMode(mode: 'editing' | 'design'): Promise<void>;
|
|
188
|
+
/** Sets who makes the next changes. */
|
|
189
|
+
setAuthor(author: Author): Promise<void>;
|
|
190
|
+
/** Counts words, characters, paragraphs, lines and pages. */
|
|
191
|
+
wordCount(): Promise<WordCount>;
|
|
192
|
+
/** Releases the editor. Idempotent; later calls reject `destroyed`. */
|
|
193
|
+
destroy(): Promise<void>;
|
|
194
|
+
}
|
|
195
|
+
/** An editor mounted in a page: it owns input, rendering, scrolling and its DOM inside the container. */
|
|
196
|
+
export declare class Editor extends HeadlessEditor {
|
|
197
|
+
#private;
|
|
198
|
+
/** The element the editor was mounted in. */
|
|
199
|
+
readonly container: HTMLElement;
|
|
200
|
+
/** Where the engine runs. */
|
|
201
|
+
readonly executionMode: 'main' | 'worker';
|
|
202
|
+
/** The rulers: the model, the built-in rulers and the viewport mapping. */
|
|
203
|
+
readonly ruler: Ruler;
|
|
204
|
+
/** Review, with the markup pane and balloons. */
|
|
205
|
+
readonly review: MountedReview;
|
|
206
|
+
/** Elements, with drop targets and hit testing. */
|
|
207
|
+
readonly elements: MountedElements;
|
|
208
|
+
/** The view. */
|
|
209
|
+
readonly view: View;
|
|
210
|
+
/** The pointer gestures. */
|
|
211
|
+
readonly gestures: Gestures;
|
|
212
|
+
/** Editors are made by {@link Editor.mount}. */
|
|
213
|
+
protected constructor();
|
|
214
|
+
/** Mounts an editor in `container`, which must be empty of other editors. Resolves when it accepts commands. */
|
|
215
|
+
static mount(container: HTMLElement, options?: MountOptions): Promise<Editor>;
|
|
216
|
+
/** Focuses the editor, keeping the selection. Mounting never takes focus by itself. */
|
|
217
|
+
focus(): void;
|
|
218
|
+
}
|