@withmarfa/inkkit 0.0.0-stage → 0.8.0-alpha.0
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/LICENSE +21 -0
- package/NOTICE +41 -0
- package/README.md +47 -2
- package/dist/THIRD-PARTY-NOTICES-FULL.txt +3377 -0
- package/dist/THIRD-PARTY-NOTICES.txt +3377 -0
- package/dist/chunks/core-CntI6pRW.js +71644 -0
- package/dist/chunks/highlight-B__AKLId.js +14068 -0
- package/dist/core.d.ts +7 -0
- package/dist/core.js +2 -0
- package/dist/diagnostics.d.ts +109 -0
- package/dist/editor.d.ts +550 -0
- package/dist/formats/convert.d.ts +17 -0
- package/dist/formats/index.d.ts +8 -0
- package/dist/formats/markdown.d.ts +4 -0
- package/dist/formats/rich-text-import.d.ts +11 -0
- package/dist/formats/rich-text-model.d.ts +56 -0
- package/dist/formats/rich-text-prose.d.ts +23 -0
- package/dist/formats/rich-text.d.ts +5 -0
- package/dist/formats/text.d.ts +4 -0
- package/dist/formats/types.d.ts +120 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +32793 -0
- package/dist/link-address.d.ts +11 -0
- package/dist/style.css +2195 -0
- package/dist/themes/calm.css +36 -0
- package/dist/themes/essential.css +36 -0
- package/dist/themes/standard.css +39 -0
- package/dist/types.d.ts +560 -0
- package/package.json +101 -4
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
:where([data-inkkit-theme='calm']) {
|
|
2
|
+
--inkkit-font-family:
|
|
3
|
+
-apple-system, BlinkMacSystemFont, system-ui, sans-serif;
|
|
4
|
+
--inkkit-font-size: 15px;
|
|
5
|
+
--inkkit-paragraph-spacing: calc(var(--inkkit-font-size) * 0.667);
|
|
6
|
+
--inkkit-reading-width: 100%;
|
|
7
|
+
--inkkit-background-color: light-dark(#ffffff, #1d2430);
|
|
8
|
+
--inkkit-text-color: light-dark(#252c36, #e6eaf0);
|
|
9
|
+
--inkkit-muted-color: light-dark(#656f7c, #a4adbb);
|
|
10
|
+
--inkkit-accent-color: light-dark(#3064af, #9abbf5);
|
|
11
|
+
--inkkit-rule-color: light-dark(#dce2e9, #434d5e);
|
|
12
|
+
--inkkit-checkbox-border-color: var(--inkkit-muted-color);
|
|
13
|
+
--inkkit-code-background: light-dark(#f3f5f8, #272e3a);
|
|
14
|
+
--inkkit-table-radius: 10px;
|
|
15
|
+
--inkkit-code-radius: 10px;
|
|
16
|
+
--inkkit-quote-rule-width: 3px;
|
|
17
|
+
--inkkit-quote-rule-radius: 2px;
|
|
18
|
+
--inkkit-quote-rule-color: light-dark(#a6a6a6, #777777);
|
|
19
|
+
--inkkit-code-comment: light-dark(#6e6e6e, #99999a);
|
|
20
|
+
--inkkit-code-keyword: light-dark(#a626a4, #c77bde);
|
|
21
|
+
--inkkit-code-string: light-dark(#3b763a, #98c379);
|
|
22
|
+
--inkkit-code-number: light-dark(#8d6001, #d19a66);
|
|
23
|
+
--inkkit-code-title: light-dark(#8d6101, #e5c07b);
|
|
24
|
+
--inkkit-code-attr: light-dark(#c82c1e, #e37981);
|
|
25
|
+
--inkkit-diagram-background: light-dark(#ffffff, #1d2430);
|
|
26
|
+
--inkkit-diagram-text-color: light-dark(#252c36, #e6eaf0);
|
|
27
|
+
--inkkit-diagram-color-strength: 35%;
|
|
28
|
+
--inkkit-diagram-series-1: light-dark(#4d87d5, #9abbf5);
|
|
29
|
+
--inkkit-diagram-series-2: light-dark(#69ad91, #a1d6bd);
|
|
30
|
+
--inkkit-diagram-series-3: light-dark(#9b80ce, #c4aff0);
|
|
31
|
+
--inkkit-diagram-series-4: light-dark(#d6a660, #edce9b);
|
|
32
|
+
--inkkit-diagram-series-5: light-dark(#ce819a, #eeb4c8);
|
|
33
|
+
--inkkit-diagram-series-6: light-dark(#65b4b1, #9edbd7);
|
|
34
|
+
--inkkit-diagram-series-7: light-dark(#cab85d, #e9dd99);
|
|
35
|
+
--inkkit-diagram-series-8: light-dark(#7ca9c5, #b1d6ed);
|
|
36
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
:where([data-inkkit-theme='essential']) {
|
|
2
|
+
--inkkit-font-family:
|
|
3
|
+
-apple-system, BlinkMacSystemFont, system-ui, sans-serif;
|
|
4
|
+
--inkkit-font-size: 15px;
|
|
5
|
+
--inkkit-paragraph-spacing: calc(var(--inkkit-font-size) * 0.667);
|
|
6
|
+
--inkkit-reading-width: 100%;
|
|
7
|
+
--inkkit-background-color: light-dark(#ffffff, #1c1c1c);
|
|
8
|
+
--inkkit-text-color: light-dark(#262626, #e8e8e8);
|
|
9
|
+
--inkkit-muted-color: light-dark(#707070, #a6a6a6);
|
|
10
|
+
--inkkit-accent-color: light-dark(#555555, #c4c4c4);
|
|
11
|
+
--inkkit-rule-color: light-dark(#dddddd, #444444);
|
|
12
|
+
--inkkit-checkbox-border-color: var(--inkkit-muted-color);
|
|
13
|
+
--inkkit-code-background: light-dark(#f7f7f7, #2a2a2a);
|
|
14
|
+
--inkkit-table-radius: 10px;
|
|
15
|
+
--inkkit-code-radius: 10px;
|
|
16
|
+
--inkkit-quote-rule-width: 3px;
|
|
17
|
+
--inkkit-quote-rule-radius: 2px;
|
|
18
|
+
--inkkit-quote-rule-color: light-dark(#a6a6a6, #777777);
|
|
19
|
+
--inkkit-code-comment: light-dark(#707070, #929292);
|
|
20
|
+
--inkkit-code-keyword: light-dark(#333333, #eeeeee);
|
|
21
|
+
--inkkit-code-string: light-dark(#686868, #bbbbbb);
|
|
22
|
+
--inkkit-code-number: light-dark(#555555, #c8c8c8);
|
|
23
|
+
--inkkit-code-title: light-dark(#444444, #dddddd);
|
|
24
|
+
--inkkit-code-attr: light-dark(#707070, #aaaaaa);
|
|
25
|
+
--inkkit-diagram-background: light-dark(#ffffff, #1c1c1c);
|
|
26
|
+
--inkkit-diagram-text-color: light-dark(#262626, #e8e8e8);
|
|
27
|
+
--inkkit-diagram-color-strength: 75%;
|
|
28
|
+
--inkkit-diagram-series-1: light-dark(#3d3d3d, #eeeeee);
|
|
29
|
+
--inkkit-diagram-series-2: light-dark(#5a5a5a, #d6d6d6);
|
|
30
|
+
--inkkit-diagram-series-3: light-dark(#747474, #bebebe);
|
|
31
|
+
--inkkit-diagram-series-4: light-dark(#8b8b8b, #a6a6a6);
|
|
32
|
+
--inkkit-diagram-series-5: light-dark(#a0a0a0, #8e8e8e);
|
|
33
|
+
--inkkit-diagram-series-6: light-dark(#b4b4b4, #767676);
|
|
34
|
+
--inkkit-diagram-series-7: light-dark(#c6c6c6, #5e5e5e);
|
|
35
|
+
--inkkit-diagram-series-8: light-dark(#d7d7d7, #464646);
|
|
36
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
:where([data-inkkit-theme='standard']) {
|
|
2
|
+
--inkkit-font-family:
|
|
3
|
+
-apple-system, BlinkMacSystemFont, system-ui, sans-serif;
|
|
4
|
+
--inkkit-font-size: 15px;
|
|
5
|
+
--inkkit-paragraph-spacing: calc(var(--inkkit-font-size) * 0.667);
|
|
6
|
+
--inkkit-reading-width: 100%;
|
|
7
|
+
--inkkit-background-color: light-dark(#ffffff, #1c1c1e);
|
|
8
|
+
--inkkit-text-color: CanvasText;
|
|
9
|
+
--inkkit-muted-color: light-dark(#6e6e6e, #99999a);
|
|
10
|
+
--inkkit-accent-color: light-dark(#0069d1, #409cff);
|
|
11
|
+
--inkkit-rule-color: color-mix(in srgb, CanvasText 14%, transparent);
|
|
12
|
+
--inkkit-checkbox-border-color: var(--inkkit-muted-color);
|
|
13
|
+
--inkkit-code-background: light-dark(
|
|
14
|
+
#f3f5f8,
|
|
15
|
+
color-mix(in srgb, CanvasText 8%, transparent)
|
|
16
|
+
);
|
|
17
|
+
--inkkit-table-radius: 10px;
|
|
18
|
+
--inkkit-code-radius: 10px;
|
|
19
|
+
--inkkit-quote-rule-width: 3px;
|
|
20
|
+
--inkkit-quote-rule-radius: 2px;
|
|
21
|
+
--inkkit-quote-rule-color: light-dark(#a6a6a6, #777777);
|
|
22
|
+
--inkkit-code-comment: light-dark(#6e6e6e, #99999a);
|
|
23
|
+
--inkkit-code-keyword: light-dark(#a626a4, #c77bde);
|
|
24
|
+
--inkkit-code-string: light-dark(#3b763a, #98c379);
|
|
25
|
+
--inkkit-code-number: light-dark(#8d6001, #d19a66);
|
|
26
|
+
--inkkit-code-title: light-dark(#8d6101, #e5c07b);
|
|
27
|
+
--inkkit-code-attr: light-dark(#c82c1e, #e37981);
|
|
28
|
+
--inkkit-diagram-background: light-dark(#ffffff, #1c1c1e);
|
|
29
|
+
--inkkit-diagram-text-color: light-dark(#1c1c1e, #f2f2f7);
|
|
30
|
+
--inkkit-diagram-color-strength: 35%;
|
|
31
|
+
--inkkit-diagram-series-1: light-dark(#0088ff, #0091ff);
|
|
32
|
+
--inkkit-diagram-series-2: light-dark(#34c759, #30d158);
|
|
33
|
+
--inkkit-diagram-series-3: light-dark(#6155f5, #6d7cff);
|
|
34
|
+
--inkkit-diagram-series-4: light-dark(#ff8d28, #ff9230);
|
|
35
|
+
--inkkit-diagram-series-5: light-dark(#ff383c, #ff4245);
|
|
36
|
+
--inkkit-diagram-series-6: light-dark(#00c8b3, #00dac3);
|
|
37
|
+
--inkkit-diagram-series-7: light-dark(#ffcc00, #ffd600);
|
|
38
|
+
--inkkit-diagram-series-8: light-dark(#00c0e8, #3cd3fe);
|
|
39
|
+
}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,560 @@
|
|
|
1
|
+
/** `md` is Markdown; `txt` is literal text, shown and saved as typed; `rtf` is rich text, which the
|
|
2
|
+
* host converts to and from a `RichTextDocument`. */
|
|
3
|
+
export type DocumentFormat = 'md' | 'txt' | 'rtf';
|
|
4
|
+
/** The formats whose document is text: Markdown and TXT. An editor mounted without `rtf` in its
|
|
5
|
+
* `formats` has only these. */
|
|
6
|
+
export type TextDocumentFormat = 'md' | 'txt';
|
|
7
|
+
/** What saving promises for a format. `exact` saves the file exactly. `structure` keeps the
|
|
8
|
+
* structure and marks and replaces fonts, colors and sizes with Inkkit's style. `lossy` is a
|
|
9
|
+
* conversion that drops something and says what. */
|
|
10
|
+
export type FormatPromise = 'exact' | 'structure' | 'lossy';
|
|
11
|
+
/** A format the host offered at mount, with what saving it promises. */
|
|
12
|
+
export interface OfferedFormat {
|
|
13
|
+
format: DocumentFormat;
|
|
14
|
+
promise: FormatPromise;
|
|
15
|
+
}
|
|
16
|
+
/** What every adapter call receives, to tell which document, load and call it belongs to. The
|
|
17
|
+
* operation ID is opaque and differs for each call from one editor. */
|
|
18
|
+
export interface DocumentContext {
|
|
19
|
+
documentId: string;
|
|
20
|
+
generation: number;
|
|
21
|
+
operationId: string;
|
|
22
|
+
}
|
|
23
|
+
/** A document to load. `generation` must be greater than the loaded one. Markdown and TXT carry
|
|
24
|
+
* their `text`; RTF carries the `document` the host read from the file. `F` is the formats the
|
|
25
|
+
* editor was mounted with; without `rtf` among them, every input is text. */
|
|
26
|
+
export type DocumentInput<F extends DocumentFormat = TextDocumentFormat> = F extends 'rtf' ? RichTextDocumentInput : TextDocumentInput;
|
|
27
|
+
/** A Markdown or TXT document to load. */
|
|
28
|
+
export interface TextDocumentInput {
|
|
29
|
+
documentId: string;
|
|
30
|
+
generation: number;
|
|
31
|
+
format: TextDocumentFormat;
|
|
32
|
+
text: string;
|
|
33
|
+
}
|
|
34
|
+
/** An RTF document to load, as the host's converter read it. */
|
|
35
|
+
export interface RichTextDocumentInput {
|
|
36
|
+
documentId: string;
|
|
37
|
+
generation: number;
|
|
38
|
+
format: 'rtf';
|
|
39
|
+
document: RichTextDocument;
|
|
40
|
+
}
|
|
41
|
+
/** A rich text document: the JSON form of an RTF file that the host converts. Version 1 is the
|
|
42
|
+
* only version. */
|
|
43
|
+
export interface RichTextDocument {
|
|
44
|
+
version: 1;
|
|
45
|
+
blocks: RichTextBlock[];
|
|
46
|
+
}
|
|
47
|
+
/** A paragraph, a list or a table. A list item holds a paragraph and then only lists. */
|
|
48
|
+
export type RichTextBlock = {
|
|
49
|
+
type: 'paragraph';
|
|
50
|
+
/** Absent for left alignment. */
|
|
51
|
+
align?: 'center' | 'right' | 'justify';
|
|
52
|
+
content: RichTextInline[];
|
|
53
|
+
} | {
|
|
54
|
+
type: 'list';
|
|
55
|
+
ordered: boolean;
|
|
56
|
+
/** An ordered list's first number, 1 or more. Absent for 1. */
|
|
57
|
+
start?: number;
|
|
58
|
+
items: RichTextListItem[];
|
|
59
|
+
} | {
|
|
60
|
+
type: 'table';
|
|
61
|
+
/** Every row has the same number of cells. */
|
|
62
|
+
rows: RichTextTableCell[][];
|
|
63
|
+
};
|
|
64
|
+
export interface RichTextListItem {
|
|
65
|
+
blocks: RichTextBlock[];
|
|
66
|
+
}
|
|
67
|
+
export interface RichTextTableCell {
|
|
68
|
+
content: RichTextInline[];
|
|
69
|
+
}
|
|
70
|
+
/** A run of text, never empty and without line or paragraph separators, or a line break. */
|
|
71
|
+
export type RichTextInline = {
|
|
72
|
+
type: 'text';
|
|
73
|
+
text: string;
|
|
74
|
+
marks?: RichTextMark[];
|
|
75
|
+
} | {
|
|
76
|
+
type: 'break';
|
|
77
|
+
};
|
|
78
|
+
/** An inline mark. A run holds each type at most once, and never both superscript and
|
|
79
|
+
* subscript. */
|
|
80
|
+
export type RichTextMark = {
|
|
81
|
+
type: 'bold' | 'italic' | 'underline' | 'strikethrough' | 'superscript' | 'subscript' | 'code';
|
|
82
|
+
} | {
|
|
83
|
+
type: 'link';
|
|
84
|
+
href: string;
|
|
85
|
+
};
|
|
86
|
+
/** Something a conversion between formats could not keep. `count` is how many places lost it. */
|
|
87
|
+
export interface FormatLoss {
|
|
88
|
+
code: FormatLossCode;
|
|
89
|
+
count: number;
|
|
90
|
+
}
|
|
91
|
+
/** The closed list of what a conversion can lose. The API reference describes each one. */
|
|
92
|
+
export declare const formatLossCodes: readonly ['heading', 'code-block', 'diagram', 'quote', 'callout', 'task', 'rule', 'footnote', 'comment', 'highlight', 'image', 'file', 'wiki-link', 'literal', 'link', 'table-alignment', 'list-start', 'list-item-blocks', 'list-depth', 'link-underline', 'invalid-character', 'alignment', 'mark-spaces', 'empty-line'];
|
|
93
|
+
export type FormatLossCode = (typeof formatLossCodes)[number];
|
|
94
|
+
/** A document converted to another format, for the host to load as a new generation. */
|
|
95
|
+
export type ConvertedDocument = {
|
|
96
|
+
format: 'md' | 'txt';
|
|
97
|
+
text: string;
|
|
98
|
+
lost: readonly FormatLoss[];
|
|
99
|
+
} | {
|
|
100
|
+
format: 'rtf';
|
|
101
|
+
document: RichTextDocument;
|
|
102
|
+
lost: readonly FormatLoss[];
|
|
103
|
+
};
|
|
104
|
+
/** Which document an output describes: the load, named by its generation, and the revision of
|
|
105
|
+
* its content within that load. */
|
|
106
|
+
export interface DocumentVersion {
|
|
107
|
+
documentId: string;
|
|
108
|
+
generation: number;
|
|
109
|
+
revision: number;
|
|
110
|
+
}
|
|
111
|
+
/** The complete current document. `dirty` is true when it differs from the last load. `F` is the
|
|
112
|
+
* formats the editor was mounted with; without `rtf` among them, every snapshot is text. */
|
|
113
|
+
export type DocumentSnapshot<F extends DocumentFormat = TextDocumentFormat> = F extends 'rtf' ? RichTextDocumentSnapshot : TextDocumentSnapshot;
|
|
114
|
+
/** The complete current text of a Markdown or TXT document. */
|
|
115
|
+
export interface TextDocumentSnapshot extends TextDocumentInput, DocumentVersion {
|
|
116
|
+
dirty: boolean;
|
|
117
|
+
}
|
|
118
|
+
/** The complete current RTF document, in canonical form, for the host to write as RTF. */
|
|
119
|
+
export interface RichTextDocumentSnapshot extends RichTextDocumentInput, DocumentVersion {
|
|
120
|
+
dirty: boolean;
|
|
121
|
+
}
|
|
122
|
+
/** The closed list of failure codes. The API reference describes each one. */
|
|
123
|
+
export declare const editorErrorCodes: readonly ['not-ready', 'destroyed', 'stale-document', 'composition', 'operation-pending', 'read-only', 'invalid-argument', 'invalid-range', 'hidden-text', 'preservation', 'image-unavailable', 'image-unsupported', 'diagram-unavailable', 'file-unavailable', 'clipboard-unavailable', 'slash-command-failed', 'internal'];
|
|
124
|
+
export type EditorErrorCode = (typeof editorErrorCodes)[number];
|
|
125
|
+
/** Every failure InkKit reports. Hosts branch on `code`; `message` is for logs. When the failure
|
|
126
|
+
* started elsewhere, such as in an adapter, the host clipboard or the renderer, `cause` holds the
|
|
127
|
+
* original error. */
|
|
128
|
+
export declare class InkKitError extends Error {
|
|
129
|
+
readonly code: EditorErrorCode;
|
|
130
|
+
constructor(code: EditorErrorCode, message: string, options?: {
|
|
131
|
+
cause?: unknown;
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
/** Image bytes that the editor captured from a paste or drop, for the adapter to store. */
|
|
135
|
+
export interface CapturedImage {
|
|
136
|
+
bytes: Uint8Array;
|
|
137
|
+
mimeType: string;
|
|
138
|
+
filename?: string;
|
|
139
|
+
/** The `src` of the HTML image the bytes belong to, when there is one. */
|
|
140
|
+
source?: string;
|
|
141
|
+
}
|
|
142
|
+
/** Image bytes that leave the editor in clipboard and print output. */
|
|
143
|
+
export interface PortableImage {
|
|
144
|
+
bytes: Uint8Array;
|
|
145
|
+
mimeType: string;
|
|
146
|
+
filename?: string;
|
|
147
|
+
}
|
|
148
|
+
/** The document and cancellation signal for one image import. */
|
|
149
|
+
export interface ImageImportContext extends DocumentContext {
|
|
150
|
+
signal: AbortSignal;
|
|
151
|
+
}
|
|
152
|
+
/** Stores, shows and exports the images a host owns. References stay opaque to the editor. */
|
|
153
|
+
export interface ImageAdapter {
|
|
154
|
+
/** The display URL for `reference`, or `undefined` when the image is unavailable. */
|
|
155
|
+
presentation(reference: string): {
|
|
156
|
+
url: string;
|
|
157
|
+
} | undefined;
|
|
158
|
+
/** Stores the bytes and returns the reference to write into the Markdown. */
|
|
159
|
+
importImage(input: CapturedImage, context: ImageImportContext): Promise<{
|
|
160
|
+
reference: string;
|
|
161
|
+
}>;
|
|
162
|
+
/** The stored bytes and type of `reference`, for portable clipboard and print output. */
|
|
163
|
+
exportImage(reference: string, context: DocumentContext): Promise<PortableImage>;
|
|
164
|
+
/** Called for a context-menu request on an image. Inkkit selects the image first. */
|
|
165
|
+
contextMenu?(reference: string, point: ClientPoint, context: DocumentContext): void;
|
|
166
|
+
}
|
|
167
|
+
/** A wiki link as authored. */
|
|
168
|
+
export interface WikiLinkReference {
|
|
169
|
+
/** The link's Markdown as the document holds it, such as `[[Plan|Plan]]`. */
|
|
170
|
+
raw: string;
|
|
171
|
+
/** The note name, with escapes removed. Empty for a link such as `[[#Heading]]`. */
|
|
172
|
+
target: string;
|
|
173
|
+
fragment?: string;
|
|
174
|
+
/** The text shown: the alias, or the target and fragment. */
|
|
175
|
+
label: string;
|
|
176
|
+
}
|
|
177
|
+
/** How a resolved wiki link is drawn, beyond its text. */
|
|
178
|
+
export interface WikiLinkPresentation {
|
|
179
|
+
/** An image drawn as a mask before the link text, such as a data URL of an SVG. It stays with the
|
|
180
|
+
* first character of the link and is decoration only. A `missing` link ignores it. */
|
|
181
|
+
icon?: string;
|
|
182
|
+
/** The icon's CSS color: a color value or a `var()` reference. Without it, or with an undefined
|
|
183
|
+
* variable, the icon takes the link text's color. */
|
|
184
|
+
iconColor?: string;
|
|
185
|
+
/** A CSS color for a host's look to fill the link with, such as the tint of its kind of item. It
|
|
186
|
+
* is a color value or a `var()` reference, and a link without one fills with the host's plain
|
|
187
|
+
* background. A `missing` link ignores it. */
|
|
188
|
+
tint?: string;
|
|
189
|
+
}
|
|
190
|
+
/** Resolves and opens wiki links. The host owns lookup, permissions and navigation. */
|
|
191
|
+
export interface WikiLinkAdapter {
|
|
192
|
+
/** Matches note names for a typed `[[` query. Late answers are ignored. */
|
|
193
|
+
suggest?(query: string, context: FileContext): Promise<readonly string[]>;
|
|
194
|
+
/** Whether the target is missing, and how to draw it if it is not, for presentation only. */
|
|
195
|
+
resolve?(reference: WikiLinkReference, context: DocumentContext): ({
|
|
196
|
+
missing?: boolean;
|
|
197
|
+
} & WikiLinkPresentation) | undefined;
|
|
198
|
+
/** Called by Mod-click, and by Enter or Space on the focused link. */
|
|
199
|
+
open(reference: WikiLinkReference, context: DocumentContext): void;
|
|
200
|
+
}
|
|
201
|
+
/** A link a person asked a menu for, as `events.linkMenu` receives it. Inkkit selects the link
|
|
202
|
+
* first, so `format('link', { destination })` changes a web link's address and `format('link')`
|
|
203
|
+
* removes it, and `range` names the same text. */
|
|
204
|
+
export type LinkMenuTarget = {
|
|
205
|
+
/** The link's text. */
|
|
206
|
+
text: string;
|
|
207
|
+
/** The readable text the link covers, in the snapshot that is current when the event fires. It
|
|
208
|
+
* goes stale when the document changes. */
|
|
209
|
+
range: TextRange;
|
|
210
|
+
} & ({
|
|
211
|
+
kind: 'web';
|
|
212
|
+
/** The destination as the document holds it. For a reference link, the address its definition
|
|
213
|
+
* gives. It can be empty, or use a scheme that Inkkit does not open. */
|
|
214
|
+
href: string;
|
|
215
|
+
/** Whether Mod-click would open it: not empty, relative, or on a scheme Inkkit opens. Only an
|
|
216
|
+
* openable address goes to `events.openLink`. */
|
|
217
|
+
openable: boolean;
|
|
218
|
+
} | {
|
|
219
|
+
kind: 'wiki';
|
|
220
|
+
/** The link as authored, as `WikiLinkAdapter.open` receives it. */
|
|
221
|
+
reference: WikiLinkReference;
|
|
222
|
+
});
|
|
223
|
+
/** A file the document refers to, as authored. */
|
|
224
|
+
export interface FileReference {
|
|
225
|
+
/** The whole reference, including any fragment. */
|
|
226
|
+
reference: string;
|
|
227
|
+
/** `path` for ``, `wiki` for `![[name]]`. */
|
|
228
|
+
kind: 'path' | 'wiki';
|
|
229
|
+
/** The embed's Markdown as the document holds it, such as ``. */
|
|
230
|
+
raw: string;
|
|
231
|
+
/** The reference without its fragment. Use it to find the file. */
|
|
232
|
+
target: string;
|
|
233
|
+
/** Everything after the separating `#`, such as `t=10` or `page=3`. */
|
|
234
|
+
fragment?: string;
|
|
235
|
+
label?: string;
|
|
236
|
+
/** The authored width in pixels. */
|
|
237
|
+
width?: number;
|
|
238
|
+
}
|
|
239
|
+
/** The context of a file call. Abandon the work when `signal` aborts. */
|
|
240
|
+
export interface FileContext extends DocumentContext {
|
|
241
|
+
signal: AbortSignal;
|
|
242
|
+
}
|
|
243
|
+
/** How the host shows a file. `url` must be private to the host and usable offline. */
|
|
244
|
+
export type FilePresentation = {
|
|
245
|
+
kind: 'image' | 'audio' | 'video' | 'pdf';
|
|
246
|
+
url: string;
|
|
247
|
+
label?: string;
|
|
248
|
+
mimeType?: string;
|
|
249
|
+
} | {
|
|
250
|
+
kind: 'file';
|
|
251
|
+
label?: string;
|
|
252
|
+
/** `'fill'` stretches the card to the full width of the column. */
|
|
253
|
+
layout?: 'fill';
|
|
254
|
+
/** `'card'` makes the whole card the one control that calls `FileAdapter.open`. */
|
|
255
|
+
activation?: 'card';
|
|
256
|
+
/** `'placeholder'` draws one quiet line of text in place of a card, for a file that is not
|
|
257
|
+
* shown yet. `layout` and `activation` have no effect on it. */
|
|
258
|
+
appearance?: 'placeholder';
|
|
259
|
+
/** The small picture drawn before a placeholder's label. Only a placeholder uses it. */
|
|
260
|
+
symbol?: 'image' | 'file';
|
|
261
|
+
/** The text of the placeholder's button, which calls `FileAdapter.open` for this
|
|
262
|
+
* reference alone. Without it, or without `FileAdapter.open`, the line has no button. */
|
|
263
|
+
action?: string;
|
|
264
|
+
/** Actions the host adds to the card, drawn as icon buttons in its corner before Open. A
|
|
265
|
+
* placeholder, and a card with `activation: 'card'`, whose whole card is the Open control,
|
|
266
|
+
* take none: a presentation that gives them is refused. */
|
|
267
|
+
actions?: readonly FileCardAction[];
|
|
268
|
+
} | {
|
|
269
|
+
kind: 'missing';
|
|
270
|
+
label?: string;
|
|
271
|
+
} | {
|
|
272
|
+
kind: 'error';
|
|
273
|
+
label?: string;
|
|
274
|
+
message: string;
|
|
275
|
+
};
|
|
276
|
+
/** An action a host adds to a file card, such as a quick look. InkKit draws it as an icon button in
|
|
277
|
+
* the card's corner with no text, shown while the pointer is over the card or focus is inside it,
|
|
278
|
+
* and always on a device with no hover. It works in a read-only editor, as Open does. */
|
|
279
|
+
export interface FileCardAction {
|
|
280
|
+
/** The button's accessible name and hover help, used as given. Include the file's name when
|
|
281
|
+
* several cards could be confused. */
|
|
282
|
+
label: string;
|
|
283
|
+
/** An image drawn as a mask in the button's color, such as a data URL of an SVG. A URL that
|
|
284
|
+
* loads from the network or runs script is refused. */
|
|
285
|
+
icon: string;
|
|
286
|
+
/** Called by a click, or by Enter or Space on the focused button. */
|
|
287
|
+
run(reference: FileReference, context: DocumentContext): void;
|
|
288
|
+
}
|
|
289
|
+
/** Resolves, exports and opens files. The host owns storage, permissions and native actions. */
|
|
290
|
+
export interface FileAdapter {
|
|
291
|
+
/** Decides what kind of file `reference` is and how to show it. InkKit never guesses from the
|
|
292
|
+
* extension. */
|
|
293
|
+
resolve(reference: FileReference, context: FileContext): Promise<FilePresentation>;
|
|
294
|
+
/** Portable bytes of an image for copy and print. Named images need it. */
|
|
295
|
+
exportImage?(reference: FileReference, context: FileContext): Promise<PortableImage>;
|
|
296
|
+
/** Adds an Open icon button to file cards, and is what a placeholder's `action` button calls
|
|
297
|
+
* when `placeholderAction` isn't set. */
|
|
298
|
+
open?(reference: FileReference, context: DocumentContext): void;
|
|
299
|
+
/** What a placeholder's `action` button calls, in place of `open`. Setting it adds no other
|
|
300
|
+
* button. */
|
|
301
|
+
placeholderAction?(reference: FileReference, context: DocumentContext): void;
|
|
302
|
+
/** Who receives a dropped image file while the editor has no `images` adapter: the host
|
|
303
|
+
* (`'host'`, the default), or nobody, refused with `image-unsupported` as a pasted image is
|
|
304
|
+
* (`'refuse'`). Read at mount. */
|
|
305
|
+
imageDrops?: 'host' | 'refuse';
|
|
306
|
+
/** Called for a context-menu request on a file card. */
|
|
307
|
+
contextMenu?(reference: FileReference, point: ClientPoint, context: DocumentContext): void;
|
|
308
|
+
}
|
|
309
|
+
/** A position in CSS pixels in the web view's client area, as in DOM pointer events. */
|
|
310
|
+
export interface ClientPoint {
|
|
311
|
+
clientX: number;
|
|
312
|
+
clientY: number;
|
|
313
|
+
}
|
|
314
|
+
/** What the host read from the native clipboard. */
|
|
315
|
+
export interface ClipboardInput {
|
|
316
|
+
text: string;
|
|
317
|
+
/** Explicit Markdown source. It takes precedence over `text` and `html`. */
|
|
318
|
+
markdown?: string;
|
|
319
|
+
html?: string;
|
|
320
|
+
/** Bytes for the images that `html` refers to. */
|
|
321
|
+
images?: CapturedImage[];
|
|
322
|
+
}
|
|
323
|
+
/** An image in clipboard output. */
|
|
324
|
+
export interface ClipboardImage {
|
|
325
|
+
/** The authored reference. Empty for the picture of a diagram. */
|
|
326
|
+
reference: string;
|
|
327
|
+
alt: string;
|
|
328
|
+
image?: PortableImage;
|
|
329
|
+
/** Why `image` is missing. */
|
|
330
|
+
error?: string;
|
|
331
|
+
}
|
|
332
|
+
/** What `clipboardSnapshot` copies: the whole document or the current selection. */
|
|
333
|
+
export type ClipboardScope = 'document' | 'selection';
|
|
334
|
+
/** Clipboard content, with the document version it was copied from. */
|
|
335
|
+
export interface ClipboardOutput extends DocumentVersion {
|
|
336
|
+
text: string;
|
|
337
|
+
html: string;
|
|
338
|
+
markdown: string;
|
|
339
|
+
images: ClipboardImage[];
|
|
340
|
+
diagrams: ClipboardDiagram[];
|
|
341
|
+
}
|
|
342
|
+
/** A complete Mermaid diagram in clipboard output. */
|
|
343
|
+
export interface ClipboardDiagram {
|
|
344
|
+
source: string;
|
|
345
|
+
/** A PNG of the rendered diagram. */
|
|
346
|
+
image?: PortableImage;
|
|
347
|
+
/** Why `image` is missing. The source is still in the output. */
|
|
348
|
+
error?: string;
|
|
349
|
+
}
|
|
350
|
+
/** Output that degraded, such as a diagram printed as code or a file printed as a description. */
|
|
351
|
+
export interface PrintableWarning {
|
|
352
|
+
code: 'diagram-unavailable' | 'attachment-fallback' | 'attachment-unavailable';
|
|
353
|
+
message: string;
|
|
354
|
+
}
|
|
355
|
+
/** The whole document, ready to print. The host owns the Print or PDF command. */
|
|
356
|
+
export interface PrintableDocument extends DocumentVersion {
|
|
357
|
+
format: DocumentFormat;
|
|
358
|
+
/** A standalone HTML document with the print CSS embedded and `data:` images only. */
|
|
359
|
+
html: string;
|
|
360
|
+
/** The print CSS on its own. */
|
|
361
|
+
styles: string;
|
|
362
|
+
/** The images, in the order they appear in `html`. */
|
|
363
|
+
assets: readonly PortableImage[];
|
|
364
|
+
warnings: readonly PrintableWarning[];
|
|
365
|
+
}
|
|
366
|
+
/** A range of readable text. Offsets are zero-based UTF-16 code units in the `text` of the
|
|
367
|
+
* snapshot that `snapshotId` names, with `to` exclusive. */
|
|
368
|
+
export interface TextRange {
|
|
369
|
+
snapshotId: string;
|
|
370
|
+
from: number;
|
|
371
|
+
to: number;
|
|
372
|
+
}
|
|
373
|
+
/** The editor's readable text and selection. Ranges from it go stale when the document changes. */
|
|
374
|
+
export interface ReadableTextSnapshot extends DocumentVersion {
|
|
375
|
+
snapshotId: string;
|
|
376
|
+
format: DocumentFormat;
|
|
377
|
+
mode: 'source' | 'formatted';
|
|
378
|
+
text: string;
|
|
379
|
+
selection: TextRange;
|
|
380
|
+
}
|
|
381
|
+
/** What a find session shows: how many matches the query has and which one the selection is on. */
|
|
382
|
+
export interface FindState extends DocumentVersion {
|
|
383
|
+
/** The query, or an empty string when there is none. */
|
|
384
|
+
query: string;
|
|
385
|
+
/** The position, from 1, of the match that the selection covers exactly, or 0 when the selection
|
|
386
|
+
* is not on a match. */
|
|
387
|
+
current: number;
|
|
388
|
+
/** The number of matches. */
|
|
389
|
+
total: number;
|
|
390
|
+
}
|
|
391
|
+
/**
|
|
392
|
+
* A find bar's state and commands: the query, the match count, the match the selection is on, and
|
|
393
|
+
* navigation that wraps. Open one with `InkKitEditor.findSession`.
|
|
394
|
+
*/
|
|
395
|
+
export interface FindSession {
|
|
396
|
+
/** The current state. It does not call the change handler. */
|
|
397
|
+
state(expectedGeneration?: number): FindState;
|
|
398
|
+
/** Sets the query, highlights its matches and selects one. A new query selects the first match
|
|
399
|
+
* at or after the selection, or the last one before it with `direction: 'previous'`. With the
|
|
400
|
+
* same query, the selection moves to the next or previous match and wraps at the ends; without
|
|
401
|
+
* a direction, a selection on a match stays there. Returns whether there is a match. */
|
|
402
|
+
find(query: string, options?: {
|
|
403
|
+
direction?: 'next' | 'previous';
|
|
404
|
+
}, expectedGeneration?: number): boolean;
|
|
405
|
+
/** Moves to the next match, wrapping at the end. Returns whether there is a match. */
|
|
406
|
+
next(expectedGeneration?: number): boolean;
|
|
407
|
+
/** Moves to the previous match, wrapping at the start. Returns whether there is a match. */
|
|
408
|
+
previous(expectedGeneration?: number): boolean;
|
|
409
|
+
/** Replaces the selected match, or the next one, and selects the match after it. Returns whether
|
|
410
|
+
* the text changed. A match that already reads as the replacement is skipped without a change. */
|
|
411
|
+
replace(query: string, replacement: string, expectedGeneration?: number): boolean;
|
|
412
|
+
/** Replaces every match and returns how many were replaced. */
|
|
413
|
+
replaceAll(query: string, replacement: string, expectedGeneration?: number): number;
|
|
414
|
+
/** Clears the query and the highlights. */
|
|
415
|
+
clear(expectedGeneration?: number): void;
|
|
416
|
+
/** Stops the session: it clears the highlights and its handler is not called again. */
|
|
417
|
+
close(): void;
|
|
418
|
+
}
|
|
419
|
+
/** A rectangle in CSS pixels in the web view's client coordinate space. */
|
|
420
|
+
export interface TextRect {
|
|
421
|
+
left: number;
|
|
422
|
+
top: number;
|
|
423
|
+
right: number;
|
|
424
|
+
bottom: number;
|
|
425
|
+
width: number;
|
|
426
|
+
height: number;
|
|
427
|
+
}
|
|
428
|
+
/** How far host chrome covers each edge of the visible area, in non-negative CSS pixels. */
|
|
429
|
+
export interface ViewportInsets {
|
|
430
|
+
top: number;
|
|
431
|
+
right: number;
|
|
432
|
+
bottom: number;
|
|
433
|
+
left: number;
|
|
434
|
+
}
|
|
435
|
+
export interface ViewportOptions {
|
|
436
|
+
/** The element that scrolls. It must be the root or an ancestor of it. Defaults to the root. */
|
|
437
|
+
scrollContainer?: HTMLElement;
|
|
438
|
+
insets?: Partial<ViewportInsets>;
|
|
439
|
+
}
|
|
440
|
+
export interface ViewportSnapshot {
|
|
441
|
+
/** The visible area, less the insets. */
|
|
442
|
+
rect: TextRect;
|
|
443
|
+
insets: ViewportInsets;
|
|
444
|
+
/** The combined scroll offsets of the container and, in source and TXT modes, the textarea. */
|
|
445
|
+
scrollTop: number;
|
|
446
|
+
scrollLeft: number;
|
|
447
|
+
}
|
|
448
|
+
/** Built-in editor text. Hosts can override individual labels at mount time. */
|
|
449
|
+
export interface EditorLabels {
|
|
450
|
+
suggestions: string;
|
|
451
|
+
suggestionsEmpty: string;
|
|
452
|
+
suggestionsLoading: string;
|
|
453
|
+
slashHeading1: string;
|
|
454
|
+
slashHeading2: string;
|
|
455
|
+
slashHeading3: string;
|
|
456
|
+
slashBulletList: string;
|
|
457
|
+
slashOrderedList: string;
|
|
458
|
+
slashTaskList: string;
|
|
459
|
+
taskCheckbox: string;
|
|
460
|
+
slashQuote: string;
|
|
461
|
+
slashCodeBlock: string;
|
|
462
|
+
slashTable: string;
|
|
463
|
+
slashCallout: string;
|
|
464
|
+
slashDivider: string;
|
|
465
|
+
slashDiagram: string;
|
|
466
|
+
slashNote: string;
|
|
467
|
+
slashTip: string;
|
|
468
|
+
slashImportant: string;
|
|
469
|
+
slashWarning: string;
|
|
470
|
+
slashCaution: string;
|
|
471
|
+
formattedEditor: string;
|
|
472
|
+
/** Accessible name of the formatted surface while an RTF document is loaded. */
|
|
473
|
+
richTextEditor: string;
|
|
474
|
+
plainTextEditor: string;
|
|
475
|
+
sourceEditor: string;
|
|
476
|
+
placeholder: string;
|
|
477
|
+
copyCode: string;
|
|
478
|
+
codeLanguage: string;
|
|
479
|
+
codeLanguageSearch: string;
|
|
480
|
+
codeWrap: string;
|
|
481
|
+
codeAuto: string;
|
|
482
|
+
codePlainText: string;
|
|
483
|
+
expandCallout: string;
|
|
484
|
+
collapseCallout: string;
|
|
485
|
+
/** The fold button of an expanded heading, followed by the heading's text in its accessible name. */
|
|
486
|
+
foldHeading: string;
|
|
487
|
+
/** The fold button of a folded heading, followed by the heading's text in its accessible name. */
|
|
488
|
+
unfoldHeading: string;
|
|
489
|
+
diagramRendering: string;
|
|
490
|
+
/** Prefix shown before the renderer's diagnostic message. */
|
|
491
|
+
diagramUnavailable: string;
|
|
492
|
+
/** Prefix followed by the authored footnote label. */
|
|
493
|
+
footnote: string;
|
|
494
|
+
tableAddRow: string;
|
|
495
|
+
tableAddColumn: string;
|
|
496
|
+
tableDeleteRow: string;
|
|
497
|
+
tableDeleteColumn: string;
|
|
498
|
+
tableAlignLeft: string;
|
|
499
|
+
tableAlignCenter: string;
|
|
500
|
+
tableAlignRight: string;
|
|
501
|
+
tableMoveColumn: string;
|
|
502
|
+
tableMoveRow: string;
|
|
503
|
+
fileLoading: string;
|
|
504
|
+
fileMissing: string;
|
|
505
|
+
fileError: string;
|
|
506
|
+
fileRetry: string;
|
|
507
|
+
fileOpen: string;
|
|
508
|
+
filePreviewUnavailable: string;
|
|
509
|
+
filePDFPreview: string;
|
|
510
|
+
imageResize: string;
|
|
511
|
+
wikiMissing: string;
|
|
512
|
+
/** The hint under a link that Mod-click opens, shown after the pointer rests on it in an editor
|
|
513
|
+
* that can be edited. An empty text draws no hint. */
|
|
514
|
+
linkOpenHint: string;
|
|
515
|
+
/** Name of an author comment, which stays out of the readable text. */
|
|
516
|
+
comment: string;
|
|
517
|
+
/** Name of a block of Markdown InkKit keeps as authored and does not render. */
|
|
518
|
+
preservedMarkdown: string;
|
|
519
|
+
/** Accessible name of the list of front matter properties. */
|
|
520
|
+
frontMatter: string;
|
|
521
|
+
/** Button that shows front matter's YAML to edit. */
|
|
522
|
+
editFrontMatter: string;
|
|
523
|
+
}
|
|
524
|
+
/** An outline entry. Pass it back to `navigateHeading`; it goes stale when the document changes. */
|
|
525
|
+
export interface Heading extends Readonly<DocumentVersion> {
|
|
526
|
+
/** Opaque. It belongs to the loaded document and editing mode. */
|
|
527
|
+
readonly id: string;
|
|
528
|
+
/** 1 to 6. */
|
|
529
|
+
readonly level: number;
|
|
530
|
+
readonly text: string;
|
|
531
|
+
}
|
|
532
|
+
/** A command for `table`. `insert` makes a table; the others work on the table at the selection. */
|
|
533
|
+
export type TableCommand = 'insert' | 'addRowBefore' | 'addRowAfter' | 'addColumnBefore' | 'addColumnAfter' | 'deleteRow' | 'deleteColumn' | 'deleteTable' | 'alignLeft' | 'alignCenter' | 'alignRight' | 'moveRowUp' | 'moveRowDown' | 'moveColumnLeft' | 'moveColumnRight' | 'sortRows' | 'exit';
|
|
534
|
+
/** Where `moveBlock` moves the blocks at the selection. */
|
|
535
|
+
export type BlockMoveDirection = 'up' | 'down';
|
|
536
|
+
/** Each option belongs to one command; any other combination is refused. */
|
|
537
|
+
export interface TableOptions {
|
|
538
|
+
/** `insert`: 1 to 100, counting the header row. Defaults to 3. */
|
|
539
|
+
rows?: number;
|
|
540
|
+
/** `insert`: 1 to 100. Defaults to 2. */
|
|
541
|
+
columns?: number;
|
|
542
|
+
/** `sortRows`: zero-based. Defaults to the column of the selection. */
|
|
543
|
+
column?: number;
|
|
544
|
+
/** `sortRows`. Defaults to `ascending`. */
|
|
545
|
+
order?: 'ascending' | 'descending';
|
|
546
|
+
/** `sortRows`. Defaults to `text`. */
|
|
547
|
+
comparison?: 'text' | 'number';
|
|
548
|
+
}
|
|
549
|
+
export type SlashCommandName = 'heading1' | 'heading2' | 'heading3' | 'bulletList' | 'orderedList' | 'taskList' | 'quote' | 'codeBlock' | 'table' | 'callout' | 'divider' | 'diagram';
|
|
550
|
+
export interface SlashCommand {
|
|
551
|
+
name: string;
|
|
552
|
+
keywords?: readonly string[];
|
|
553
|
+
/** Returns Markdown to insert in place of the trigger. Undefined cancels the action. */
|
|
554
|
+
action(context: DocumentContext): string | undefined | Promise<string | undefined>;
|
|
555
|
+
}
|
|
556
|
+
export interface SlashMenuOptions {
|
|
557
|
+
enabled?: boolean;
|
|
558
|
+
commands?: readonly SlashCommandName[];
|
|
559
|
+
customCommands?: readonly SlashCommand[];
|
|
560
|
+
}
|