@aicayzer/inkkit 0.0.18 → 0.1.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/NOTICE +4 -2
- package/README.md +11 -7
- package/dist/THIRD-PARTY-NOTICES.txt +2742 -0
- package/dist/chunks/core-vtCr4MBS.js +56503 -0
- package/dist/chunks/highlight-Daj2fv_u.js +14122 -0
- package/dist/core.d.ts +2 -5
- package/dist/core.js +2 -2
- package/dist/editor.d.ts +229 -47
- package/dist/index.js +5 -3
- package/dist/style.css +231 -202
- package/dist/types.d.ts +143 -18
- package/package.json +16 -13
- package/dist/autolink.d.ts +0 -1
- package/dist/autolink.js +0 -18
- package/dist/callouts.d.ts +0 -25
- package/dist/callouts.js +0 -288
- package/dist/clipboard.d.ts +0 -11
- package/dist/clipboard.js +0 -261
- package/dist/code-fences.d.ts +0 -8
- package/dist/code-fences.js +0 -171
- package/dist/comments.d.ts +0 -76
- package/dist/comments.js +0 -545
- package/dist/cursor.d.ts +0 -2
- package/dist/cursor.js +0 -40
- package/dist/decorations.d.ts +0 -2
- package/dist/decorations.js +0 -67
- package/dist/dialect.d.ts +0 -9
- package/dist/dialect.js +0 -446
- package/dist/drop-placement.d.ts +0 -19
- package/dist/drop-placement.js +0 -47
- package/dist/editor.js +0 -2673
- package/dist/files.d.ts +0 -40
- package/dist/files.js +0 -133
- package/dist/highlight.d.ts +0 -1
- package/dist/highlight.js +0 -136
- package/dist/html-import.d.ts +0 -13
- package/dist/html-import.js +0 -477
- package/dist/image-blocks.d.ts +0 -86
- package/dist/image-blocks.js +0 -329
- package/dist/images.d.ts +0 -51
- package/dist/images.js +0 -398
- package/dist/inline-highlight.d.ts +0 -6
- package/dist/inline-highlight.js +0 -112
- package/dist/labels.d.ts +0 -36
- package/dist/labels.js +0 -34
- package/dist/link-safety.d.ts +0 -17
- package/dist/link-safety.js +0 -29
- package/dist/linked-syntax.d.ts +0 -48
- package/dist/linked-syntax.js +0 -320
- package/dist/literals.d.ts +0 -20
- package/dist/literals.js +0 -216
- package/dist/mermaid.d.ts +0 -28
- package/dist/mermaid.js +0 -404
- package/dist/outline.d.ts +0 -22
- package/dist/outline.js +0 -79
- package/dist/paste-html.d.ts +0 -31
- package/dist/paste-html.js +0 -462
- package/dist/paste.d.ts +0 -33
- package/dist/paste.js +0 -591
- package/dist/portable-files.d.ts +0 -10
- package/dist/portable-files.js +0 -36
- package/dist/preserve.d.ts +0 -38
- package/dist/preserve.js +0 -1396
- package/dist/print.d.ts +0 -7
- package/dist/print.js +0 -406
- package/dist/reference-clipboard.d.ts +0 -8
- package/dist/reference-clipboard.js +0 -201
- package/dist/references.d.ts +0 -16
- package/dist/references.js +0 -418
- package/dist/scroll.d.ts +0 -15
- package/dist/scroll.js +0 -27
- package/dist/search.d.ts +0 -15
- package/dist/search.js +0 -202
- package/dist/selection.d.ts +0 -1
- package/dist/selection.js +0 -59
- package/dist/source.d.ts +0 -16
- package/dist/source.js +0 -57
- package/dist/spreadsheet.d.ts +0 -8
- package/dist/spreadsheet.js +0 -289
- package/dist/table-alignment.d.ts +0 -2
- package/dist/table-alignment.js +0 -46
- package/dist/tables.d.ts +0 -27
- package/dist/tables.js +0 -344
- package/dist/tasks.d.ts +0 -3
- package/dist/tasks.js +0 -51
- package/dist/text-ranges.d.ts +0 -29
- package/dist/text-ranges.js +0 -256
- package/dist/types.js +0 -8
- package/dist/wiki-view.d.ts +0 -21
- package/dist/wiki-view.js +0 -78
package/dist/files.d.ts
DELETED
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import type { DocumentContext, FileAdapter, FileContext, FilePresentation, FileReference } from './types.js';
|
|
2
|
-
import type { EditorLabels } from './labels.js';
|
|
3
|
-
export interface FileViewRuntime {
|
|
4
|
-
adapter: FileAdapter;
|
|
5
|
-
capture(): {
|
|
6
|
-
context: DocumentContext;
|
|
7
|
-
isCurrent(): boolean;
|
|
8
|
-
};
|
|
9
|
-
active(): boolean;
|
|
10
|
-
labels: Readonly<EditorLabels>;
|
|
11
|
-
error?(error: Error): void;
|
|
12
|
-
}
|
|
13
|
-
export declare function withFileSignal<T>(operation: Promise<T>, signal: AbortSignal): Promise<T>;
|
|
14
|
-
export declare function resolveFile(adapter: FileAdapter, reference: FileReference, context: FileContext): Promise<FilePresentation>;
|
|
15
|
-
export type FileResolutionState = {
|
|
16
|
-
status: 'idle';
|
|
17
|
-
} | {
|
|
18
|
-
status: 'loading';
|
|
19
|
-
} | {
|
|
20
|
-
status: 'resolved';
|
|
21
|
-
presentation: FilePresentation;
|
|
22
|
-
} | {
|
|
23
|
-
status: 'failed';
|
|
24
|
-
error: Error;
|
|
25
|
-
};
|
|
26
|
-
export declare class FileResolution {
|
|
27
|
-
private readonly runtime;
|
|
28
|
-
private readonly changed;
|
|
29
|
-
state: FileResolutionState;
|
|
30
|
-
private reference?;
|
|
31
|
-
private key;
|
|
32
|
-
private request?;
|
|
33
|
-
private dead;
|
|
34
|
-
constructor(runtime: FileViewRuntime, changed: () => void);
|
|
35
|
-
update(reference: FileReference): void;
|
|
36
|
-
retry(): void;
|
|
37
|
-
private current;
|
|
38
|
-
cancel(): void;
|
|
39
|
-
destroy(): void;
|
|
40
|
-
}
|
package/dist/files.js
DELETED
|
@@ -1,133 +0,0 @@
|
|
|
1
|
-
function abort(signal) {
|
|
2
|
-
if (signal.aborted)
|
|
3
|
-
throw new DOMException('File resolution cancelled', 'AbortError');
|
|
4
|
-
}
|
|
5
|
-
export function withFileSignal(operation, signal) {
|
|
6
|
-
return new Promise((resolve, reject) => {
|
|
7
|
-
const cleanup = () => signal.removeEventListener('abort', cancelled);
|
|
8
|
-
const cancelled = () => {
|
|
9
|
-
cleanup();
|
|
10
|
-
reject(new DOMException('File operation cancelled', 'AbortError'));
|
|
11
|
-
};
|
|
12
|
-
if (signal.aborted)
|
|
13
|
-
cancelled();
|
|
14
|
-
else
|
|
15
|
-
signal.addEventListener('abort', cancelled, { once: true });
|
|
16
|
-
operation.then((result) => {
|
|
17
|
-
cleanup();
|
|
18
|
-
if (signal.aborted)
|
|
19
|
-
cancelled();
|
|
20
|
-
else
|
|
21
|
-
resolve(result);
|
|
22
|
-
}, (error) => {
|
|
23
|
-
cleanup();
|
|
24
|
-
reject(error);
|
|
25
|
-
});
|
|
26
|
-
});
|
|
27
|
-
}
|
|
28
|
-
export async function resolveFile(adapter, reference, context) {
|
|
29
|
-
abort(context.signal);
|
|
30
|
-
const presentation = await withFileSignal(adapter.resolve(Object.freeze({ ...reference }), context), context.signal);
|
|
31
|
-
abort(context.signal);
|
|
32
|
-
if (!presentation ||
|
|
33
|
-
typeof presentation !== 'object' ||
|
|
34
|
-
!['image', 'audio', 'video', 'pdf', 'file', 'missing', 'error'].includes(presentation.kind))
|
|
35
|
-
throw new TypeError('File adapter returned an unsupported presentation');
|
|
36
|
-
if (presentation.label !== undefined &&
|
|
37
|
-
typeof presentation.label !== 'string')
|
|
38
|
-
throw new TypeError('File presentation label must be text');
|
|
39
|
-
if (presentation.kind === 'error' && typeof presentation.message !== 'string')
|
|
40
|
-
throw new TypeError('File presentation error must include a message');
|
|
41
|
-
if ('url' in presentation) {
|
|
42
|
-
if (typeof presentation.url !== 'string' || !presentation.url.trim())
|
|
43
|
-
throw new TypeError('File presentation needs a resource URL');
|
|
44
|
-
const url = new URL(presentation.url, document.baseURI);
|
|
45
|
-
if (['javascript:', 'vbscript:'].includes(url.protocol))
|
|
46
|
-
throw new TypeError('Executable file presentation URLs are not supported');
|
|
47
|
-
const prefix = presentation.kind === 'pdf' ? 'application/pdf' : `${presentation.kind}/`;
|
|
48
|
-
const mime = presentation.mimeType?.toLowerCase().split(';')[0]?.trim();
|
|
49
|
-
if (mime &&
|
|
50
|
-
(presentation.kind === 'pdf' ? mime !== prefix : !mime.startsWith(prefix)))
|
|
51
|
-
throw new TypeError('File presentation MIME type does not match its kind');
|
|
52
|
-
const dataMime = url.pathname.toLowerCase().split(/[;,]/)[0] ?? '';
|
|
53
|
-
if (url.protocol === 'data:' &&
|
|
54
|
-
(presentation.kind === 'pdf'
|
|
55
|
-
? dataMime !== prefix
|
|
56
|
-
: !dataMime.startsWith(prefix)))
|
|
57
|
-
throw new TypeError('File presentation data URL does not match its kind');
|
|
58
|
-
}
|
|
59
|
-
else if (['image', 'audio', 'video', 'pdf'].includes(presentation.kind)) {
|
|
60
|
-
throw new TypeError('File presentation needs a resource URL');
|
|
61
|
-
}
|
|
62
|
-
return Object.freeze({ ...presentation });
|
|
63
|
-
}
|
|
64
|
-
export class FileResolution {
|
|
65
|
-
runtime;
|
|
66
|
-
changed;
|
|
67
|
-
state = { status: 'idle' };
|
|
68
|
-
reference;
|
|
69
|
-
key = '';
|
|
70
|
-
request;
|
|
71
|
-
dead = false;
|
|
72
|
-
constructor(runtime, changed) {
|
|
73
|
-
this.runtime = runtime;
|
|
74
|
-
this.changed = changed;
|
|
75
|
-
}
|
|
76
|
-
update(reference) {
|
|
77
|
-
const key = JSON.stringify([
|
|
78
|
-
reference.reference,
|
|
79
|
-
reference.kind,
|
|
80
|
-
reference.fragment,
|
|
81
|
-
]);
|
|
82
|
-
this.reference = Object.freeze({ ...reference });
|
|
83
|
-
if (this.key === key && this.request?.isCurrent())
|
|
84
|
-
return;
|
|
85
|
-
this.key = key;
|
|
86
|
-
this.retry();
|
|
87
|
-
}
|
|
88
|
-
retry() {
|
|
89
|
-
this.cancel();
|
|
90
|
-
if (this.dead || !this.reference || !this.runtime.active())
|
|
91
|
-
return;
|
|
92
|
-
const captured = this.runtime.capture();
|
|
93
|
-
const request = {
|
|
94
|
-
controller: new AbortController(),
|
|
95
|
-
isCurrent: captured.isCurrent,
|
|
96
|
-
};
|
|
97
|
-
this.request = request;
|
|
98
|
-
this.state = { status: 'loading' };
|
|
99
|
-
this.changed();
|
|
100
|
-
void resolveFile(this.runtime.adapter, this.reference, {
|
|
101
|
-
...captured.context,
|
|
102
|
-
signal: request.controller.signal,
|
|
103
|
-
}).then((presentation) => {
|
|
104
|
-
if (!this.current(request))
|
|
105
|
-
return;
|
|
106
|
-
this.state = { status: 'resolved', presentation };
|
|
107
|
-
this.changed();
|
|
108
|
-
}, (failure) => {
|
|
109
|
-
if (!this.current(request))
|
|
110
|
-
return;
|
|
111
|
-
const error = failure instanceof Error ? failure : new Error(String(failure));
|
|
112
|
-
this.state = { status: 'failed', error };
|
|
113
|
-
this.changed();
|
|
114
|
-
this.runtime.error?.(error);
|
|
115
|
-
});
|
|
116
|
-
}
|
|
117
|
-
current(request) {
|
|
118
|
-
return (!this.dead &&
|
|
119
|
-
this.request === request &&
|
|
120
|
-
!request.controller.signal.aborted &&
|
|
121
|
-
this.runtime.active() &&
|
|
122
|
-
request.isCurrent());
|
|
123
|
-
}
|
|
124
|
-
cancel() {
|
|
125
|
-
this.request?.controller.abort();
|
|
126
|
-
this.request = undefined;
|
|
127
|
-
this.state = { status: 'idle' };
|
|
128
|
-
}
|
|
129
|
-
destroy() {
|
|
130
|
-
this.dead = true;
|
|
131
|
-
this.cancel();
|
|
132
|
-
}
|
|
133
|
-
}
|
package/dist/highlight.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const highlightPlugin: import("@milkdown/kit/utils").$Prose;
|
package/dist/highlight.js
DELETED
|
@@ -1,136 +0,0 @@
|
|
|
1
|
-
import { common, createLowlight } from 'lowlight';
|
|
2
|
-
import { Plugin, PluginKey } from '@milkdown/kit/prose/state';
|
|
3
|
-
import { Decoration, DecorationSet } from '@milkdown/kit/prose/view';
|
|
4
|
-
import { $prose } from '@milkdown/kit/utils';
|
|
5
|
-
const lowlight = createLowlight(common);
|
|
6
|
-
// Colors are decorations over the plain text, so the markdown is untouched;
|
|
7
|
-
// a block without a known language stays plain.
|
|
8
|
-
function blockDecorations(node, pos) {
|
|
9
|
-
const language = String(node.attrs.language ?? '').toLowerCase();
|
|
10
|
-
const found = [];
|
|
11
|
-
if (!language || !lowlight.registered(language))
|
|
12
|
-
return found;
|
|
13
|
-
let offset = pos + 1;
|
|
14
|
-
const walk = (children, classes) => {
|
|
15
|
-
for (const child of children) {
|
|
16
|
-
if (child.type === 'text') {
|
|
17
|
-
const end = offset + child.value.length;
|
|
18
|
-
if (classes.length > 0)
|
|
19
|
-
found.push(Decoration.inline(offset, end, { class: classes.join(' ') }));
|
|
20
|
-
offset = end;
|
|
21
|
-
}
|
|
22
|
-
else if (child.type === 'element') {
|
|
23
|
-
const own = child.properties?.className ?? [];
|
|
24
|
-
walk(child.children, [...classes, ...own]);
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
};
|
|
28
|
-
walk(lowlight.highlight(language, node.textContent).children, []);
|
|
29
|
-
return found;
|
|
30
|
-
}
|
|
31
|
-
function decorations(doc) {
|
|
32
|
-
const found = [];
|
|
33
|
-
doc.descendants((node, pos) => {
|
|
34
|
-
if (!node.isTextblock)
|
|
35
|
-
return true;
|
|
36
|
-
if (node.type.name === 'code_block')
|
|
37
|
-
for (const decoration of blockDecorations(node, pos))
|
|
38
|
-
found.push(decoration);
|
|
39
|
-
return false;
|
|
40
|
-
});
|
|
41
|
-
return DecorationSet.create(doc, found);
|
|
42
|
-
}
|
|
43
|
-
// Every range of the new document an update may have touched: each step's own
|
|
44
|
-
// range, plus the whole span where the two documents differ, which also covers
|
|
45
|
-
// steps that change a node without changing its size.
|
|
46
|
-
function touched(tr) {
|
|
47
|
-
const ranges = [];
|
|
48
|
-
tr.mapping.maps.forEach((map, index) => {
|
|
49
|
-
const rest = tr.mapping.slice(index + 1);
|
|
50
|
-
map.forEach((_, __, from, to) => ranges.push([rest.map(from, -1), rest.map(to, 1)]));
|
|
51
|
-
});
|
|
52
|
-
const start = tr.before.content.findDiffStart(tr.doc.content);
|
|
53
|
-
if (start != null) {
|
|
54
|
-
const end = tr.before.content.findDiffEnd(tr.doc.content);
|
|
55
|
-
// The scans overlap when inserted or deleted text repeats its neighbours.
|
|
56
|
-
if (end)
|
|
57
|
-
ranges.push([start, end.b + Math.max(0, start - Math.min(end.a, end.b))]);
|
|
58
|
-
}
|
|
59
|
-
return ranges;
|
|
60
|
-
}
|
|
61
|
-
// Mapping carries colors of unchanged blocks to their new positions without
|
|
62
|
-
// reading them, but leaves stale colors inside any block that was edited. Those
|
|
63
|
-
// blocks are highlighted again; no other block is. Stale colors are dropped by
|
|
64
|
-
// rebuilding the set: DecorationSet.remove compares every removed decoration
|
|
65
|
-
// with every other in its block, which is quadratic in a large block.
|
|
66
|
-
function update(mapped, tr) {
|
|
67
|
-
const stale = [];
|
|
68
|
-
const fresh = [];
|
|
69
|
-
const seen = new Set();
|
|
70
|
-
for (const [from, to] of touched(tr)) {
|
|
71
|
-
let start = from;
|
|
72
|
-
let end = to;
|
|
73
|
-
const blocks = [];
|
|
74
|
-
tr.doc.nodesBetween(from, to, (node, pos) => {
|
|
75
|
-
if (!node.isTextblock)
|
|
76
|
-
return true;
|
|
77
|
-
start = Math.min(start, pos);
|
|
78
|
-
end = Math.max(end, pos + node.nodeSize);
|
|
79
|
-
if (node.type.name === 'code_block' && !seen.has(pos)) {
|
|
80
|
-
seen.add(pos);
|
|
81
|
-
blocks.push([node, pos]);
|
|
82
|
-
}
|
|
83
|
-
return false;
|
|
84
|
-
});
|
|
85
|
-
stale.push([start, end]);
|
|
86
|
-
for (const [node, pos] of blocks)
|
|
87
|
-
for (const decoration of blockDecorations(node, pos))
|
|
88
|
-
fresh.push(decoration);
|
|
89
|
-
}
|
|
90
|
-
const found = [];
|
|
91
|
-
for (const [start, end] of stale)
|
|
92
|
-
for (const decoration of mapped.find(start, end))
|
|
93
|
-
found.push(decoration);
|
|
94
|
-
if (found.length === 0)
|
|
95
|
-
return mapped.add(tr.doc, fresh);
|
|
96
|
-
// remove is quadratic in the decorations it removes, so only a large block takes the rebuild below.
|
|
97
|
-
if (found.length <= 256)
|
|
98
|
-
return mapped.remove(found).add(tr.doc, fresh);
|
|
99
|
-
stale.sort((a, b) => a[0] - b[0]);
|
|
100
|
-
const merged = [];
|
|
101
|
-
for (const range of stale) {
|
|
102
|
-
const last = merged.at(-1);
|
|
103
|
-
if (last && range[0] <= last[1])
|
|
104
|
-
last[1] = Math.max(last[1], range[1]);
|
|
105
|
-
else
|
|
106
|
-
merged.push([range[0], range[1]]);
|
|
107
|
-
}
|
|
108
|
-
const kept = mapped.find().filter((decoration) => {
|
|
109
|
-
let low = 0;
|
|
110
|
-
let high = merged.length;
|
|
111
|
-
while (low < high) {
|
|
112
|
-
const middle = (low + high) >> 1;
|
|
113
|
-
if (merged[middle][0] < decoration.to)
|
|
114
|
-
low = middle + 1;
|
|
115
|
-
else
|
|
116
|
-
high = middle;
|
|
117
|
-
}
|
|
118
|
-
const range = merged[low - 1];
|
|
119
|
-
return !range || range[1] <= decoration.from;
|
|
120
|
-
});
|
|
121
|
-
return DecorationSet.create(tr.doc, kept.concat(fresh));
|
|
122
|
-
}
|
|
123
|
-
export const highlightPlugin = $prose(() => new Plugin({
|
|
124
|
-
key: new PluginKey('highlight'),
|
|
125
|
-
state: {
|
|
126
|
-
init: (_, state) => decorations(state.doc),
|
|
127
|
-
apply: (tr, previous) => tr.docChanged
|
|
128
|
-
? update(previous.map(tr.mapping, tr.doc), tr)
|
|
129
|
-
: previous,
|
|
130
|
-
},
|
|
131
|
-
props: {
|
|
132
|
-
decorations(state) {
|
|
133
|
-
return this.getState(state);
|
|
134
|
-
},
|
|
135
|
-
},
|
|
136
|
-
}));
|
package/dist/html-import.d.ts
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import type { Ctx } from '@milkdown/kit/ctx';
|
|
2
|
-
import { Fragment, Slice, type Node, type Schema } from '@milkdown/kit/prose/model';
|
|
3
|
-
/**
|
|
4
|
-
* The slice's nodes as blocks a document holds, wrapped as insertion would
|
|
5
|
-
* wrap them: inline nodes in a paragraph and list items in a list.
|
|
6
|
-
*/
|
|
7
|
-
export declare function topLevel(schema: Schema, content: Fragment): Node[];
|
|
8
|
-
/**
|
|
9
|
-
* Returns the slice with every part whose Markdown would read back as
|
|
10
|
-
* different structure replaced by a form that reads back the same, keeping as
|
|
11
|
-
* much of its text and formatting as possible.
|
|
12
|
-
*/
|
|
13
|
-
export declare function importableSlice(ctx: Ctx, slice: Slice): Slice;
|