@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
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import type { Session } from '../editor.js';
|
|
2
|
+
import type { Points } from '../types.js';
|
|
3
|
+
/** The ruler model, on every editor. */
|
|
4
|
+
export interface RulerModelSource {
|
|
5
|
+
/** The ruler model for the selection, in points: the same value as `getState().ruler`. */
|
|
6
|
+
model(): RulerModel;
|
|
7
|
+
}
|
|
8
|
+
/** The rulers of a mounted editor: the built-in rulers, and the model mapped to the viewport. */
|
|
9
|
+
export interface Ruler extends RulerModelSource {
|
|
10
|
+
/** Shows or hides the built-in rulers. */
|
|
11
|
+
setVisible(rulers: {
|
|
12
|
+
horizontal?: boolean;
|
|
13
|
+
vertical?: boolean;
|
|
14
|
+
}): Promise<void>;
|
|
15
|
+
/** The unit the rulers show. */
|
|
16
|
+
setUnit(unit: RulerUnit): Promise<void>;
|
|
17
|
+
/** What a click on the ruler adds; the corner box cycles it. */
|
|
18
|
+
setTabSelector(kind: TabSelector): Promise<void>;
|
|
19
|
+
/** The model with its mapping to the viewport, for an application drawing its own ruler. */
|
|
20
|
+
view(): RulerView;
|
|
21
|
+
}
|
|
22
|
+
/** A ruler unit. */
|
|
23
|
+
export type RulerUnit = 'inches' | 'centimeters' | 'millimeters' | 'points' | 'picas';
|
|
24
|
+
/** What a click on the ruler adds. */
|
|
25
|
+
export type TabSelector = TabAlignment | 'firstLineIndent' | 'hangingIndent';
|
|
26
|
+
/** A tab stop's alignment. */
|
|
27
|
+
export type TabAlignment = 'left' | 'center' | 'right' | 'decimal' | 'bar';
|
|
28
|
+
/** A tab stop's leader. */
|
|
29
|
+
export type TabLeader = 'none' | 'dots' | 'dashes' | 'underline' | 'heavy' | 'middleDot';
|
|
30
|
+
/** The ruler model for the selection, in points. */
|
|
31
|
+
export interface RulerModel {
|
|
32
|
+
/** The selected paragraphs differ: the first one's values are shown. */
|
|
33
|
+
mixed: boolean;
|
|
34
|
+
/** The horizontal ruler. */
|
|
35
|
+
horizontal: {
|
|
36
|
+
pageWidth: Points;
|
|
37
|
+
/** The margins, or the cell or text column around the caret. */
|
|
38
|
+
text: {
|
|
39
|
+
start: Points;
|
|
40
|
+
end: Points;
|
|
41
|
+
};
|
|
42
|
+
/** `firstLine` is relative to `left`; negative is hanging. */
|
|
43
|
+
indents: {
|
|
44
|
+
left: Points;
|
|
45
|
+
right: Points;
|
|
46
|
+
firstLine: Points;
|
|
47
|
+
};
|
|
48
|
+
tabs: {
|
|
49
|
+
position: Points;
|
|
50
|
+
alignment: TabAlignment;
|
|
51
|
+
leader: TabLeader;
|
|
52
|
+
inherited: boolean;
|
|
53
|
+
}[];
|
|
54
|
+
defaultTabStop: Points;
|
|
55
|
+
/** The section's text columns. */
|
|
56
|
+
columns: {
|
|
57
|
+
start: Points;
|
|
58
|
+
end: Points;
|
|
59
|
+
}[];
|
|
60
|
+
/** The cell boundaries of the caret's row. */
|
|
61
|
+
tableColumns: Points[];
|
|
62
|
+
};
|
|
63
|
+
/** The vertical ruler. */
|
|
64
|
+
vertical: {
|
|
65
|
+
pageHeight: Points;
|
|
66
|
+
/** The top and bottom margins. */
|
|
67
|
+
text: {
|
|
68
|
+
start: Points;
|
|
69
|
+
end: Points;
|
|
70
|
+
};
|
|
71
|
+
/** The row boundaries of the caret's table on this page. */
|
|
72
|
+
tableRows: Points[];
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
/** The ruler model mapped to the viewport. */
|
|
76
|
+
export interface RulerView {
|
|
77
|
+
/** The model. */
|
|
78
|
+
model: RulerModel;
|
|
79
|
+
/** The page the rulers follow (the caret's). */
|
|
80
|
+
page: number;
|
|
81
|
+
/** The client x of the page's left edge, and CSS px per point. */
|
|
82
|
+
horizontal: {
|
|
83
|
+
origin: number;
|
|
84
|
+
scale: number;
|
|
85
|
+
};
|
|
86
|
+
/** The client y of the page's top edge, and CSS px per point. */
|
|
87
|
+
vertical: {
|
|
88
|
+
origin: number;
|
|
89
|
+
scale: number;
|
|
90
|
+
};
|
|
91
|
+
/** The unit shown. */
|
|
92
|
+
unit: RulerUnit;
|
|
93
|
+
}
|
|
94
|
+
/** The mounted rulers over a session; `view` starts as `initial` and follows `rulerChanged`. */
|
|
95
|
+
export declare function createRuler(s: Session, initial: RulerView): Ruler;
|
|
@@ -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
|
+
}
|