@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.
Files changed (90) hide show
  1. package/NOTICE +4 -2
  2. package/README.md +11 -7
  3. package/dist/THIRD-PARTY-NOTICES.txt +2742 -0
  4. package/dist/chunks/core-vtCr4MBS.js +56503 -0
  5. package/dist/chunks/highlight-Daj2fv_u.js +14122 -0
  6. package/dist/core.d.ts +2 -5
  7. package/dist/core.js +2 -2
  8. package/dist/editor.d.ts +229 -47
  9. package/dist/index.js +5 -3
  10. package/dist/style.css +231 -202
  11. package/dist/types.d.ts +143 -18
  12. package/package.json +16 -13
  13. package/dist/autolink.d.ts +0 -1
  14. package/dist/autolink.js +0 -18
  15. package/dist/callouts.d.ts +0 -25
  16. package/dist/callouts.js +0 -288
  17. package/dist/clipboard.d.ts +0 -11
  18. package/dist/clipboard.js +0 -261
  19. package/dist/code-fences.d.ts +0 -8
  20. package/dist/code-fences.js +0 -171
  21. package/dist/comments.d.ts +0 -76
  22. package/dist/comments.js +0 -545
  23. package/dist/cursor.d.ts +0 -2
  24. package/dist/cursor.js +0 -40
  25. package/dist/decorations.d.ts +0 -2
  26. package/dist/decorations.js +0 -67
  27. package/dist/dialect.d.ts +0 -9
  28. package/dist/dialect.js +0 -446
  29. package/dist/drop-placement.d.ts +0 -19
  30. package/dist/drop-placement.js +0 -47
  31. package/dist/editor.js +0 -2673
  32. package/dist/files.d.ts +0 -40
  33. package/dist/files.js +0 -133
  34. package/dist/highlight.d.ts +0 -1
  35. package/dist/highlight.js +0 -136
  36. package/dist/html-import.d.ts +0 -13
  37. package/dist/html-import.js +0 -477
  38. package/dist/image-blocks.d.ts +0 -86
  39. package/dist/image-blocks.js +0 -329
  40. package/dist/images.d.ts +0 -51
  41. package/dist/images.js +0 -398
  42. package/dist/inline-highlight.d.ts +0 -6
  43. package/dist/inline-highlight.js +0 -112
  44. package/dist/labels.d.ts +0 -36
  45. package/dist/labels.js +0 -34
  46. package/dist/link-safety.d.ts +0 -17
  47. package/dist/link-safety.js +0 -29
  48. package/dist/linked-syntax.d.ts +0 -48
  49. package/dist/linked-syntax.js +0 -320
  50. package/dist/literals.d.ts +0 -20
  51. package/dist/literals.js +0 -216
  52. package/dist/mermaid.d.ts +0 -28
  53. package/dist/mermaid.js +0 -404
  54. package/dist/outline.d.ts +0 -22
  55. package/dist/outline.js +0 -79
  56. package/dist/paste-html.d.ts +0 -31
  57. package/dist/paste-html.js +0 -462
  58. package/dist/paste.d.ts +0 -33
  59. package/dist/paste.js +0 -591
  60. package/dist/portable-files.d.ts +0 -10
  61. package/dist/portable-files.js +0 -36
  62. package/dist/preserve.d.ts +0 -38
  63. package/dist/preserve.js +0 -1396
  64. package/dist/print.d.ts +0 -7
  65. package/dist/print.js +0 -406
  66. package/dist/reference-clipboard.d.ts +0 -8
  67. package/dist/reference-clipboard.js +0 -201
  68. package/dist/references.d.ts +0 -16
  69. package/dist/references.js +0 -418
  70. package/dist/scroll.d.ts +0 -15
  71. package/dist/scroll.js +0 -27
  72. package/dist/search.d.ts +0 -15
  73. package/dist/search.js +0 -202
  74. package/dist/selection.d.ts +0 -1
  75. package/dist/selection.js +0 -59
  76. package/dist/source.d.ts +0 -16
  77. package/dist/source.js +0 -57
  78. package/dist/spreadsheet.d.ts +0 -8
  79. package/dist/spreadsheet.js +0 -289
  80. package/dist/table-alignment.d.ts +0 -2
  81. package/dist/table-alignment.js +0 -46
  82. package/dist/tables.d.ts +0 -27
  83. package/dist/tables.js +0 -344
  84. package/dist/tasks.d.ts +0 -3
  85. package/dist/tasks.js +0 -51
  86. package/dist/text-ranges.d.ts +0 -29
  87. package/dist/text-ranges.js +0 -256
  88. package/dist/types.js +0 -8
  89. package/dist/wiki-view.d.ts +0 -21
  90. package/dist/wiki-view.js +0 -78
@@ -1,462 +0,0 @@
1
- // Elements the HTML paste path hands to ProseMirror's parser. Anything else
2
- // is kept as literal source, so a tag must be listed here or rewritten by
3
- // `normalizeClipboardHTML` to avoid becoming a raw-HTML block.
4
- const rich = new Set([
5
- 'P',
6
- 'H1',
7
- 'H2',
8
- 'H3',
9
- 'H4',
10
- 'H5',
11
- 'H6',
12
- 'STRONG',
13
- 'MARK',
14
- 'B',
15
- 'EM',
16
- 'I',
17
- 'S',
18
- 'DEL',
19
- 'STRIKE',
20
- 'CODE',
21
- 'PRE',
22
- 'BLOCKQUOTE',
23
- 'A',
24
- 'BR',
25
- 'HR',
26
- 'UL',
27
- 'OL',
28
- 'LI',
29
- 'TABLE',
30
- 'THEAD',
31
- 'TBODY',
32
- 'TFOOT',
33
- 'TR',
34
- 'TH',
35
- 'TD',
36
- 'IMG',
37
- 'SPAN',
38
- 'SUP',
39
- 'DIV',
40
- 'FONT',
41
- 'SECTION',
42
- 'ARTICLE',
43
- 'MAIN',
44
- 'HEADER',
45
- 'FOOTER',
46
- ]);
47
- // Document furniture and form inputs hold no content of their own. A
48
- // template never keeps `head`, so it is not listed.
49
- const dropped = new Set(['STYLE', 'META', 'LINK', 'TITLE', 'SOURCE', 'INPUT']);
50
- // The dialect has no underline, subscript or similar marks, so these keep
51
- // their children and lose only the wrapper.
52
- const unwrapped = new Set([
53
- 'U',
54
- 'SUB',
55
- 'SMALL',
56
- 'TIME',
57
- 'ABBR',
58
- 'CITE',
59
- 'DFN',
60
- 'VAR',
61
- 'INS',
62
- 'BDI',
63
- 'BDO',
64
- 'LABEL',
65
- ]);
66
- const blockWrappers = new Set(['FIGURE', 'FIGCAPTION', 'DL', 'DD']);
67
- const handled = new Set([
68
- ...dropped,
69
- ...unwrapped,
70
- ...blockWrappers,
71
- 'DT',
72
- 'PICTURE',
73
- ]);
74
- export function isRichElement(element) {
75
- return rich.has(element.tagName);
76
- }
77
- /** Whether normalisation enters the element, so its content may be rewritten. */
78
- export function isRewrittenElement(element) {
79
- return rich.has(element.tagName) || handled.has(element.tagName);
80
- }
81
- // `white-space` and its longhand `white-space-collapse` keep source spaces with
82
- // these keywords. `pre-line` and `preserve-breaks` collapse spaces, so they are
83
- // collapsed here too.
84
- const keepingWhitespace = new Set([
85
- 'pre',
86
- 'pre-wrap',
87
- 'break-spaces',
88
- 'preserve',
89
- 'preserve-spaces',
90
- ]);
91
- /**
92
- * Whether the element's own inline style makes a browser keep the whitespace
93
- * of its content, as copied editor code does with `white-space: pre`. The
94
- * declarations are parsed, so case, spacing, comments, quoted text and
95
- * `!important` do not matter. Style sheets are not consulted.
96
- */
97
- export function keepsWhitespace(element) {
98
- const style = element.getAttribute('style');
99
- if (!style)
100
- return false;
101
- const winning = new Map();
102
- for (const declaration of declarations(style)) {
103
- const colon = declaration.indexOf(':');
104
- if (colon < 0)
105
- continue;
106
- const name = declaration.slice(0, colon).trim().toLowerCase();
107
- if (name !== 'white-space' && name !== 'white-space-collapse')
108
- continue;
109
- let value = declaration.slice(colon + 1).trim();
110
- const important = /!\s*important$/i.test(value);
111
- if (important)
112
- value = value.replace(/!\s*important$/i, '');
113
- const earlier = winning.get(name);
114
- if (!earlier?.important || important)
115
- winning.set(name, { value: value.trim().toLowerCase(), important });
116
- }
117
- return [...winning.values()].some(({ value }) => value.split(/\s+/).some((keyword) => keepingWhitespace.has(keyword)));
118
- }
119
- // Splits a style attribute at the semicolons that end declarations, ignoring
120
- // those inside comments, quoted strings and parentheses such as `url(...)`.
121
- function declarations(style) {
122
- const result = [];
123
- let current = '';
124
- let quote = '';
125
- let depth = 0;
126
- for (let index = 0; index < style.length; index++) {
127
- const character = style[index];
128
- if (quote) {
129
- current += character;
130
- if (character === '\\' && index + 1 < style.length)
131
- current += style[++index];
132
- else if (character === quote)
133
- quote = '';
134
- }
135
- else if (character === '/' && style[index + 1] === '*') {
136
- const end = style.indexOf('*/', index + 2);
137
- index = end < 0 ? style.length : end + 1;
138
- }
139
- else if (character === '"' || character === "'") {
140
- quote = character;
141
- current += character;
142
- }
143
- else if (character === '(') {
144
- depth++;
145
- current += character;
146
- }
147
- else if (character === ')') {
148
- depth = Math.max(0, depth - 1);
149
- current += character;
150
- }
151
- else if (character === ';' && depth === 0) {
152
- result.push(current);
153
- current = '';
154
- }
155
- else
156
- current += character;
157
- }
158
- result.push(current);
159
- return result;
160
- }
161
- /**
162
- * WebKit writes a space beside an inline element to the clipboard as a
163
- * non-breaking space in a `span.Apple-converted-space`, to protect it from
164
- * the destination's whitespace collapse. Only such a span is converted back:
165
- * a non-breaking space anywhere else was authored.
166
- */
167
- export function restoreConvertedSpaces(root) {
168
- for (const span of root.querySelectorAll('span.Apple-converted-space'))
169
- restoreConvertedSpace(span);
170
- }
171
- function restoreConvertedSpace(span) {
172
- for (const node of span.childNodes)
173
- if (node.nodeType === Node.TEXT_NODE)
174
- node.data = node.data.replace(/\u00a0/g, ' ');
175
- }
176
- /**
177
- * Rewrites common web-page elements to ones the importer already understands.
178
- * Elements that will stay literal source are not entered, so their content is
179
- * preserved exactly.
180
- */
181
- export function normalizeClipboardHTML(root) {
182
- for (const node of [...root.childNodes]) {
183
- if (node.nodeType === Node.COMMENT_NODE) {
184
- // Windows and some native apps leave the CF_HTML fragment markers in.
185
- if (/^\s*(?:Start|End)Fragment\s*$/.test(node.data))
186
- node.parentNode?.removeChild(node);
187
- continue;
188
- }
189
- if (node.nodeType !== Node.ELEMENT_NODE)
190
- continue;
191
- const element = node;
192
- const tag = element.tagName;
193
- if (!rich.has(tag) && !handled.has(tag))
194
- continue;
195
- if (dropped.has(tag)) {
196
- const parent = element.parentElement;
197
- element.remove();
198
- if (parent)
199
- removeEmptyParagraph(parent);
200
- }
201
- else if (tag === 'PICTURE') {
202
- const image = element.querySelector('img');
203
- if (image)
204
- element.replaceWith(image);
205
- else
206
- element.remove();
207
- }
208
- else if (unwrapped.has(tag)) {
209
- normalizeClipboardHTML(element);
210
- element.replaceWith(...element.childNodes);
211
- }
212
- else if (tag === 'DT') {
213
- normalizeClipboardHTML(element);
214
- // Markdown has no definition lists. A bold term over its definition
215
- // keeps which text names the other.
216
- const term = element.ownerDocument.createElement('div');
217
- boldInto(term, [...element.childNodes]);
218
- element.replaceWith(term);
219
- }
220
- else if (blockWrappers.has(tag)) {
221
- normalizeClipboardHTML(element);
222
- const block = element.ownerDocument.createElement('div');
223
- block.append(...element.childNodes);
224
- element.replaceWith(block);
225
- }
226
- else {
227
- if (tag === 'LI')
228
- markTask(element);
229
- else if (tag === 'SPAN' &&
230
- element.classList.contains('Apple-converted-space'))
231
- restoreConvertedSpace(element);
232
- normalizeClipboardHTML(element);
233
- }
234
- }
235
- }
236
- // A paragraph whose only content was a dropped element would otherwise import
237
- // as a blank paragraph.
238
- function removeEmptyParagraph(from) {
239
- let node = from;
240
- while (node &&
241
- ['SPAN', 'FONT', 'STRONG', 'B', 'EM', 'I'].includes(node.tagName))
242
- node = node.parentElement;
243
- if (node?.tagName === 'P' &&
244
- !node.textContent?.trim() &&
245
- !node.querySelector('img,br,hr'))
246
- node.remove();
247
- }
248
- const termBlocks = new Set(['P', 'DIV', 'H1', 'H2', 'H3', 'H4', 'H5', 'H6']);
249
- const blocks = new Set([
250
- ...termBlocks,
251
- 'BLOCKQUOTE',
252
- 'PRE',
253
- 'UL',
254
- 'OL',
255
- 'LI',
256
- 'TABLE',
257
- 'THEAD',
258
- 'TBODY',
259
- 'TFOOT',
260
- 'TR',
261
- 'TH',
262
- 'TD',
263
- 'SECTION',
264
- 'ARTICLE',
265
- 'MAIN',
266
- 'HEADER',
267
- 'FOOTER',
268
- 'HR',
269
- ]);
270
- export function isBlockElement(element) {
271
- return blocks.has(element.tagName);
272
- }
273
- // Bolds the inline content of a term. Paragraphs, headings and divisions
274
- // inside it each become one bold paragraph; other blocks are kept as they are.
275
- function boldInto(target, nodes) {
276
- const document = target.ownerDocument;
277
- let run;
278
- const paragraph = (content) => {
279
- if (!content.some((node) => node.textContent?.trim() || isImage(node)))
280
- return undefined;
281
- const block = document.createElement('p');
282
- const strong = document.createElement('strong');
283
- strong.append(...content);
284
- block.append(strong);
285
- target.append(block);
286
- return strong;
287
- };
288
- for (const node of nodes) {
289
- const element = node.nodeType === Node.ELEMENT_NODE ? node : null;
290
- if (element && blocks.has(element.tagName)) {
291
- run = undefined;
292
- if (element.tagName === 'P' || /^H[1-6]$/.test(element.tagName))
293
- paragraph([...element.childNodes]);
294
- else if (element.tagName === 'DIV')
295
- boldInto(target, [...element.childNodes]);
296
- else
297
- target.append(element);
298
- }
299
- else if (run)
300
- run.append(node);
301
- else if (node.textContent?.trim() || isImage(node)) {
302
- run = paragraph([node]);
303
- }
304
- }
305
- }
306
- function isImage(node) {
307
- return (node.nodeType === Node.ELEMENT_NODE &&
308
- (node.tagName === 'IMG' ||
309
- !!node.querySelector('img')));
310
- }
311
- // GitHub, Notion and similar pages render a task as a checkbox leading its
312
- // list item, optionally inside a paragraph or label.
313
- function leadingCheckbox(item) {
314
- let node = item;
315
- for (;;) {
316
- const first = [...node.childNodes].find((child) => child.nodeType !== Node.COMMENT_NODE &&
317
- !(child.nodeType === Node.TEXT_NODE && !child.textContent?.trim()));
318
- if (first?.nodeType !== Node.ELEMENT_NODE)
319
- return undefined;
320
- const element = first;
321
- if (element.tagName === 'INPUT')
322
- return element.getAttribute('type')?.toLowerCase() === 'checkbox'
323
- ? element
324
- : undefined;
325
- if (!['P', 'LABEL', 'DIV', 'SPAN'].includes(element.tagName))
326
- return undefined;
327
- node = element;
328
- }
329
- }
330
- function markTask(item) {
331
- const checkbox = leadingCheckbox(item);
332
- if (!checkbox)
333
- return;
334
- item.setAttribute('data-item-type', 'task');
335
- item.setAttribute('data-checked', String(checkbox.hasAttribute('checked')));
336
- checkbox.remove();
337
- }
338
- const inline = new Set([
339
- 'STRONG',
340
- 'MARK',
341
- 'B',
342
- 'EM',
343
- 'I',
344
- 'S',
345
- 'DEL',
346
- 'STRIKE',
347
- 'A',
348
- 'SPAN',
349
- 'SUP',
350
- 'FONT',
351
- ]);
352
- const space = /[ \t\r\n\f]+/g;
353
- /**
354
- * Collapses source whitespace the way a browser renders it: runs become one
355
- * space, and none remains at the edges of a block or beside a line break.
356
- * `pre`, `code`, elements that stay literal source and elements whose style
357
- * keeps whitespace are not entered.
358
- */
359
- export function collapseClipboardWhitespace(root) {
360
- hoistEdgeSpace(root);
361
- let trailing;
362
- let start = true;
363
- const trim = () => {
364
- if (!trailing)
365
- return;
366
- trailing.data = trailing.data.slice(0, -1);
367
- if (!trailing.data)
368
- trailing.remove();
369
- trailing = undefined;
370
- };
371
- const visit = (node) => {
372
- if (node.nodeType === Node.TEXT_NODE) {
373
- const text = node;
374
- let data = text.data.replace(space, ' ');
375
- if ((start || trailing) && data.startsWith(' '))
376
- data = data.slice(1);
377
- if (!data)
378
- return text.remove();
379
- text.data = data;
380
- start = false;
381
- trailing = data.endsWith(' ') ? text : undefined;
382
- return;
383
- }
384
- if (node.nodeType !== Node.ELEMENT_NODE)
385
- return;
386
- const element = node;
387
- const tag = element.tagName;
388
- if (keepsWhitespace(element)) {
389
- // Treated like `code` inside a line and like `pre` as a block.
390
- if (inline.has(tag) || tag === 'CODE' || tag === 'IMG') {
391
- trailing = undefined;
392
- start = false;
393
- }
394
- else {
395
- trim();
396
- start = true;
397
- }
398
- }
399
- else if (inline.has(tag)) {
400
- for (const child of [...element.childNodes])
401
- visit(child);
402
- }
403
- else if (tag === 'BR') {
404
- trim();
405
- start = true;
406
- }
407
- else if (tag === 'CODE' || tag === 'IMG') {
408
- trailing = undefined;
409
- start = false;
410
- }
411
- else {
412
- trim();
413
- start = true;
414
- if (blocks.has(tag) && tag !== 'PRE' && tag !== 'HR')
415
- for (const child of [...element.childNodes])
416
- visit(child);
417
- trim();
418
- start = true;
419
- }
420
- };
421
- for (const child of [...root.childNodes])
422
- visit(child);
423
- trim();
424
- }
425
- // Whitespace inside emphasis, links and similar wrappers cannot be written in
426
- // Markdown, so it moves outside them.
427
- function hoistEdgeSpace(node) {
428
- for (const child of [...node.childNodes]) {
429
- if (child.nodeType !== Node.ELEMENT_NODE)
430
- continue;
431
- const element = child;
432
- if (keepsWhitespace(element))
433
- continue;
434
- if (inline.has(element.tagName)) {
435
- hoistEdgeSpace(element);
436
- const lead = edgeText(element, 'start');
437
- const leading = lead?.data.match(/^[ \t\r\n\f]+/)?.[0];
438
- if (lead && leading) {
439
- lead.data = lead.data.slice(leading.length);
440
- element.before(leading);
441
- }
442
- const tail = edgeText(element, 'end');
443
- const trailing = tail?.data.match(/[ \t\r\n\f]+$/)?.[0];
444
- if (tail && trailing) {
445
- tail.data = tail.data.slice(0, -trailing.length);
446
- element.after(trailing);
447
- }
448
- }
449
- else if (blocks.has(element.tagName) && element.tagName !== 'PRE')
450
- hoistEdgeSpace(element);
451
- }
452
- }
453
- function edgeText(element, side) {
454
- let node = side === 'start' ? element.firstChild : element.lastChild;
455
- while (node && node.nodeType === Node.ELEMENT_NODE) {
456
- if (!inline.has(node.tagName) ||
457
- keepsWhitespace(node))
458
- return undefined;
459
- node = side === 'start' ? node.firstChild : node.lastChild;
460
- }
461
- return node?.nodeType === Node.TEXT_NODE ? node : undefined;
462
- }
package/dist/paste.d.ts DELETED
@@ -1,33 +0,0 @@
1
- import type { Ctx } from '@milkdown/kit/ctx';
2
- import { type ClipboardInput, type DocumentContext, type ImageAdapter } from './types.js';
3
- export interface PasteControllerOptions {
4
- ctx: () => Ctx;
5
- context: () => DocumentContext;
6
- adapter?: ImageAdapter;
7
- onError?: (error: unknown) => void;
8
- onPendingChanged?: () => void;
9
- editable?: () => boolean;
10
- literalText?: () => boolean;
11
- }
12
- export declare class PasteController {
13
- private readonly options;
14
- private active?;
15
- private readonly key;
16
- private dead;
17
- private claimed;
18
- get pending(): boolean;
19
- readonly plugin: import("@milkdown/kit/utils").$Prose;
20
- constructor(options: PasteControllerOptions);
21
- paste(input: ClipboardInput): Promise<void>;
22
- private anchor;
23
- cancelPending(): void;
24
- destroy(): void;
25
- private assertContext;
26
- /**
27
- * Inserts dropped content as whole blocks, so none joins the block beside
28
- * it, and puts the caret after them.
29
- */
30
- private insertBlocks;
31
- /** Imports the input at the selection, or in place of `target`. */
32
- private run;
33
- }