@aicayzer/inkkit 0.0.17 → 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 (81) hide show
  1. package/NOTICE +4 -2
  2. package/README.md +12 -6
  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 +4 -0
  7. package/dist/core.js +2 -0
  8. package/dist/editor.d.ts +261 -48
  9. package/dist/index.d.ts +1 -7
  10. package/dist/index.js +5 -2
  11. package/dist/style.css +242 -221
  12. package/dist/types.d.ts +143 -18
  13. package/package.json +26 -15
  14. package/dist/autolink.d.ts +0 -1
  15. package/dist/autolink.js +0 -18
  16. package/dist/callouts.d.ts +0 -26
  17. package/dist/callouts.js +0 -311
  18. package/dist/clipboard.d.ts +0 -11
  19. package/dist/clipboard.js +0 -261
  20. package/dist/code-fences.d.ts +0 -8
  21. package/dist/code-fences.js +0 -166
  22. package/dist/comments.d.ts +0 -55
  23. package/dist/comments.js +0 -494
  24. package/dist/decorations.d.ts +0 -2
  25. package/dist/decorations.js +0 -67
  26. package/dist/dialect.d.ts +0 -9
  27. package/dist/dialect.js +0 -358
  28. package/dist/editor.js +0 -2441
  29. package/dist/files.d.ts +0 -40
  30. package/dist/files.js +0 -133
  31. package/dist/highlight.d.ts +0 -1
  32. package/dist/highlight.js +0 -136
  33. package/dist/image-blocks.d.ts +0 -71
  34. package/dist/image-blocks.js +0 -286
  35. package/dist/images.d.ts +0 -51
  36. package/dist/images.js +0 -398
  37. package/dist/inline-highlight.d.ts +0 -6
  38. package/dist/inline-highlight.js +0 -112
  39. package/dist/labels.d.ts +0 -36
  40. package/dist/labels.js +0 -34
  41. package/dist/linked-syntax.d.ts +0 -48
  42. package/dist/linked-syntax.js +0 -320
  43. package/dist/literals.d.ts +0 -19
  44. package/dist/literals.js +0 -211
  45. package/dist/mermaid.d.ts +0 -8
  46. package/dist/mermaid.js +0 -321
  47. package/dist/outline.d.ts +0 -22
  48. package/dist/outline.js +0 -79
  49. package/dist/paste-html.d.ts +0 -23
  50. package/dist/paste-html.js +0 -441
  51. package/dist/paste.d.ts +0 -26
  52. package/dist/paste.js +0 -482
  53. package/dist/portable-files.d.ts +0 -10
  54. package/dist/portable-files.js +0 -36
  55. package/dist/preserve.d.ts +0 -21
  56. package/dist/preserve.js +0 -757
  57. package/dist/print.d.ts +0 -7
  58. package/dist/print.js +0 -409
  59. package/dist/reference-clipboard.d.ts +0 -8
  60. package/dist/reference-clipboard.js +0 -201
  61. package/dist/references.d.ts +0 -14
  62. package/dist/references.js +0 -368
  63. package/dist/search.d.ts +0 -15
  64. package/dist/search.js +0 -202
  65. package/dist/selection.d.ts +0 -1
  66. package/dist/selection.js +0 -59
  67. package/dist/source.d.ts +0 -16
  68. package/dist/source.js +0 -57
  69. package/dist/spreadsheet.d.ts +0 -3
  70. package/dist/spreadsheet.js +0 -275
  71. package/dist/table-alignment.d.ts +0 -2
  72. package/dist/table-alignment.js +0 -46
  73. package/dist/tables.d.ts +0 -27
  74. package/dist/tables.js +0 -322
  75. package/dist/tasks.d.ts +0 -3
  76. package/dist/tasks.js +0 -51
  77. package/dist/text-ranges.d.ts +0 -29
  78. package/dist/text-ranges.js +0 -256
  79. package/dist/types.js +0 -8
  80. package/dist/wiki-view.d.ts +0 -21
  81. package/dist/wiki-view.js +0 -78
package/dist/dialect.js DELETED
@@ -1,358 +0,0 @@
1
- import { editorViewCtx, serializerCtx } from '@milkdown/kit/core';
2
- import { commonmark, docSchema, hardbreakSchema, imageSchema, paragraphSchema, remarkInlineLinkPlugin, } from '@milkdown/kit/preset/commonmark';
3
- import { extendListItemSchemaForTask, strikethroughAttr, strikethroughInputRule, strikethroughKeymap, strikethroughSchema, toggleStrikethroughCommand, wrapInTaskListInputRule, tableSchema, tableHeaderRowSchema, tableHeaderSchema, tableRowSchema, tableCellSchema, tableEditingPlugin, tableKeymap, goToNextTableCellCommand, goToPrevTableCellCommand, insertTableCommand, addRowBeforeCommand, addRowAfterCommand, addColBeforeCommand, addColAfterCommand, selectRowCommand, selectColCommand, deleteSelectedCellsCommand, setAlignCommand, exitTable, } from '@milkdown/kit/preset/gfm';
4
- import { $node, $remark } from '@milkdown/kit/utils';
5
- import { autolinkInputRule } from './autolink.js';
6
- import { sourceAttribute } from './source.js';
7
- import { linkedSyntax, wikiLinkSchema, namedFileMarkdown, fileReference, } from './linked-syntax.js';
8
- import { normalizeTableAlignment, normalizeTableColumnAlignment, } from './table-alignment.js';
9
- import { preservingCodeBlocks, remarkCodeFences, fencedCodeHandler, } from './code-fences.js';
10
- import { literalBlock, createLiteralPreservation } from './literals.js';
11
- import { imageAttrs, imageBlocks, markdownImageAttrs, readParagraph, } from './image-blocks.js';
12
- import { references, remarkReferencesPlugin } from './references.js';
13
- import { callouts, remarkCalloutsPlugin } from './callouts.js';
14
- import { inlineHighlight } from './inline-highlight.js';
15
- import { comments, remarkCommentsPlugin } from './comments.js';
16
- import { gfmTableFromMarkdown, gfmTableToMarkdown } from 'mdast-util-gfm-table';
17
- import { gfmTable } from 'micromark-extension-gfm-table';
18
- import { defaultHandlers, } from 'mdast-util-to-markdown';
19
- import { gfmAutolinkLiteralFromMarkdown, gfmAutolinkLiteralToMarkdown, } from 'mdast-util-gfm-autolink-literal';
20
- import { gfmStrikethroughFromMarkdown, gfmStrikethroughToMarkdown, } from 'mdast-util-gfm-strikethrough';
21
- import { gfmTaskListItemFromMarkdown, gfmTaskListItemToMarkdown, } from 'mdast-util-gfm-task-list-item';
22
- import { gfmAutolinkLiteral } from 'micromark-extension-gfm-autolink-literal';
23
- import { gfmStrikethrough } from 'micromark-extension-gfm-strikethrough';
24
- import { gfmTaskListItem } from 'micromark-extension-gfm-task-list-item';
25
- const bareURL = /^https?:\/\/[^\s<>]+$/;
26
- // The literal form stops at these, so a URL ending in one would come back shorter than it went out.
27
- const endsInPunctuation = /[.,;:!?]$/;
28
- // What may sit against a bare URL without the reader running the two together.
29
- const beforeURL = /(^|[\s([*_~])$/;
30
- const afterURL = /^([\s.,;:!?)\]}<]|$)/;
31
- function balanced(url) {
32
- let open = 0;
33
- for (const character of url) {
34
- if (character === '(')
35
- open += 1;
36
- else if (character === ')')
37
- open -= 1;
38
- if (open < 0)
39
- return false;
40
- }
41
- return open === 0;
42
- }
43
- function textAt(parent, node, offset) {
44
- const children = parent?.children;
45
- const index = children?.indexOf(node) ?? -1;
46
- return index < 0 ? undefined : children?.[index + offset];
47
- }
48
- /** A link whose text is its own URL is written as the bare URL, the way it was typed. Only where reading
49
- * it back gives the same link again: nothing may run into it at either end. */
50
- function writesBare(node, parent) {
51
- const [child, ...rest] = node.children;
52
- if (node.title ||
53
- rest.length > 0 ||
54
- child?.type !== 'text' ||
55
- child.value !== node.url)
56
- return false;
57
- if (!bareURL.test(node.url) ||
58
- endsInPunctuation.test(node.url) ||
59
- !balanced(node.url))
60
- return false;
61
- const before = textAt(parent, node, -1);
62
- if (before && (before.type !== 'text' || !beforeURL.test(before.value)))
63
- return false;
64
- const after = textAt(parent, node, 1);
65
- if (after && (after.type !== 'text' || !afterURL.test(after.value)))
66
- return false;
67
- return true;
68
- }
69
- const link = (node, parent, state, info) => writesBare(node, parent)
70
- ? node.url
71
- : defaultHandlers.link(node, parent, state, info);
72
- link.peek = (node, parent, state) => writesBare(node, parent)
73
- ? node.url[0]
74
- : defaultHandlers.link.peek(node, parent, state);
75
- function remarkDialect() {
76
- const data = this.data();
77
- const add = (key, value) => {
78
- const list = (data[key] ??= []);
79
- list.push(value);
80
- };
81
- add('micromarkExtensions', gfmStrikethrough());
82
- add('micromarkExtensions', gfmTaskListItem());
83
- add('micromarkExtensions', gfmAutolinkLiteral());
84
- add('micromarkExtensions', gfmTable());
85
- add('fromMarkdownExtensions', gfmStrikethroughFromMarkdown());
86
- add('fromMarkdownExtensions', gfmTaskListItemFromMarkdown());
87
- add('fromMarkdownExtensions', gfmAutolinkLiteralFromMarkdown());
88
- add('fromMarkdownExtensions', gfmTableFromMarkdown());
89
- add('toMarkdownExtensions', gfmStrikethroughToMarkdown());
90
- add('toMarkdownExtensions', gfmTaskListItemToMarkdown());
91
- add('toMarkdownExtensions', gfmAutolinkLiteralToMarkdown());
92
- add('toMarkdownExtensions', gfmTableToMarkdown());
93
- add('toMarkdownExtensions', {
94
- handlers: {
95
- text(node, parent, state, info) {
96
- const value = defaultHandlers.text(node, parent, state, info);
97
- // GFM trims literal whitespace at cell edges on reopening.
98
- return state.stack.includes('tableCell')
99
- ? value.replace(/^[ \t]+|[ \t]+$/g, (spaces) => spaces.replaceAll(' ', '&#x20;').replaceAll('\t', '&#x9;'))
100
- : value;
101
- },
102
- thematicBreak(node, parent, state) {
103
- const value = defaultHandlers.thematicBreak(node, parent, state);
104
- // A document opening with `---` reads back as front matter when
105
- // another `---` line follows.
106
- return parent?.type === 'root' &&
107
- parent.children.length > 1 &&
108
- parent.children[0] === node
109
- ? value.replaceAll('-', '*')
110
- : value;
111
- },
112
- },
113
- });
114
- add('toMarkdownExtensions', { handlers: { link, code: fencedCodeHandler } });
115
- }
116
- export const remarkDialectPlugin = $remark('remarkDialect', () => remarkDialect);
117
- // Reference links retain their authored form instead of expanding to inline links.
118
- const commonmarkWithLiteralReferences = commonmark.filter((plugin) => !remarkInlineLinkPlugin.includes(plugin));
119
- // The preset drops the final empty paragraph, which makes trailing spacers shrink on each reload.
120
- const preserveSpacerParagraphs = paragraphSchema.extendSchema((base) => (ctx) => {
121
- const schema = base(ctx);
122
- return {
123
- ...schema,
124
- parseMarkdown: {
125
- ...schema.parseMarkdown,
126
- runner(state, node, type) {
127
- readParagraph(state, node, type);
128
- },
129
- },
130
- toMarkdown: {
131
- ...schema.toMarkdown,
132
- runner(state, node) {
133
- if (node.lastChild?.type.name === 'hardbreak') {
134
- state.openNode('paragraph');
135
- state.next(node.content.cut(0, node.content.size - node.lastChild.nodeSize));
136
- state.addNode('html', undefined, '<br />');
137
- state.closeNode();
138
- return;
139
- }
140
- if (node.content.size > 0)
141
- return schema.toMarkdown.runner(state, node);
142
- state.openNode('paragraph');
143
- state.addNode('html', undefined, '<br />');
144
- state.closeNode();
145
- },
146
- },
147
- };
148
- });
149
- // Soft Markdown breaks still serialize as a single newline. Display the actual
150
- // line boundary rather than a space, so changing editor mode never joins lines.
151
- const visibleSoftbreaks = hardbreakSchema.extendSchema((base) => (ctx) => {
152
- const schema = base(ctx);
153
- return {
154
- ...schema,
155
- attrs: { ...schema.attrs, isHTML: { default: false } },
156
- parseDOM: [
157
- {
158
- tag: 'br[data-type="softbreak"]',
159
- getAttrs: () => ({ isInline: true }),
160
- },
161
- {
162
- tag: 'br[data-type="hardbreak"]',
163
- getAttrs: () => ({ isInline: false }),
164
- },
165
- { tag: 'br', getAttrs: () => ({ isInline: false, isHTML: true }) },
166
- ],
167
- parseMarkdown: {
168
- ...schema.parseMarkdown,
169
- runner(state, node, type) {
170
- if (node.data
171
- ?.inkkitHTMLBreak)
172
- state.addNode(type, { isInline: false, isHTML: true });
173
- else
174
- schema.parseMarkdown.runner(state, node, type);
175
- },
176
- },
177
- toMarkdown: {
178
- ...schema.toMarkdown,
179
- runner(state, node) {
180
- if (node.attrs.isHTML)
181
- state.addNode('html', undefined, '<br />');
182
- else
183
- schema.toMarkdown.runner(state, node);
184
- },
185
- },
186
- toDOM: (node) => node.attrs.isInline
187
- ? ['br', { 'data-type': 'softbreak' }]
188
- : [
189
- 'br',
190
- { 'data-type': node.attrs.isHTML ? 'htmlbreak' : 'hardbreak' },
191
- ],
192
- };
193
- });
194
- const normalizedImages = imageSchema.extendSchema((base) => (ctx) => {
195
- const schema = base(ctx);
196
- return {
197
- ...schema,
198
- attrs: imageAttrs,
199
- parseDOM: [
200
- {
201
- tag: 'img[src]',
202
- getAttrs(dom) {
203
- return {
204
- src: dom.getAttribute('src') ?? '',
205
- alt: dom.getAttribute('alt') ?? '',
206
- title: dom.getAttribute('title') ?? '',
207
- };
208
- },
209
- },
210
- ],
211
- parseMarkdown: {
212
- ...schema.parseMarkdown,
213
- runner(state, node, type) {
214
- state.addNode(type, markdownImageAttrs(node));
215
- },
216
- },
217
- toMarkdown: {
218
- ...schema.toMarkdown,
219
- runner(state, node) {
220
- const raw = namedFileMarkdown(node, Boolean(node.attrs.inkkitFileInTable));
221
- if (raw == null)
222
- return schema.toMarkdown.runner(state, node);
223
- state.addNode('image', undefined, undefined, {
224
- url: node.attrs.src,
225
- alt: node.attrs.alt,
226
- title: node.attrs.title || null,
227
- inkkitFileRaw: raw,
228
- inkkitFileTarget: node.attrs.inkkitFileTarget,
229
- inkkitFileFragment: node.attrs.inkkitFileFragment,
230
- inkkitFileWidth: fileReference(node).width ?? null,
231
- inkkitFileInTable: node.attrs.inkkitFileInTable,
232
- });
233
- },
234
- },
235
- };
236
- });
237
- export const tables = [
238
- tableSchema.extendSchema((previous) => (ctx) => ({
239
- ...previous(ctx),
240
- content: 'table_header_row table_row*',
241
- })),
242
- tableHeaderRowSchema,
243
- tableHeaderSchema.extendSchema((previous) => (ctx) => {
244
- const schema = previous(ctx);
245
- return {
246
- ...schema,
247
- attrs: { ...schema.attrs, alignment: { default: null } },
248
- parseDOM: schema.parseDOM?.map((rule) => 'tag' in rule
249
- ? {
250
- ...rule,
251
- getAttrs(dom) {
252
- const attrs = rule.getAttrs?.(dom);
253
- if (attrs === false)
254
- return false;
255
- return {
256
- ...attrs,
257
- alignment: normalizeTableAlignment(dom),
258
- };
259
- },
260
- }
261
- : rule),
262
- };
263
- }),
264
- tableRowSchema,
265
- tableCellSchema.extendSchema((previous) => (ctx) => {
266
- const schema = previous(ctx);
267
- return {
268
- ...schema,
269
- attrs: { ...schema.attrs, alignment: { default: null } },
270
- parseDOM: schema.parseDOM?.map((rule) => 'tag' in rule
271
- ? {
272
- ...rule,
273
- getAttrs(dom) {
274
- const attrs = rule.getAttrs?.(dom);
275
- if (attrs === false)
276
- return false;
277
- return {
278
- ...attrs,
279
- alignment: normalizeTableColumnAlignment(dom),
280
- };
281
- },
282
- }
283
- : rule),
284
- };
285
- }),
286
- tableEditingPlugin,
287
- tableKeymap,
288
- goToNextTableCellCommand,
289
- goToPrevTableCellCommand,
290
- insertTableCommand,
291
- addRowBeforeCommand,
292
- addRowAfterCommand,
293
- addColBeforeCommand,
294
- addColAfterCommand,
295
- selectRowCommand,
296
- selectColCommand,
297
- deleteSelectedCellsCommand,
298
- setAlignCommand,
299
- exitTable,
300
- ].flat();
301
- export function createDialect(images, wikiLinks = false, files = false) {
302
- return [
303
- remarkCodeFences,
304
- remarkReferencesPlugin,
305
- remarkCalloutsPlugin,
306
- remarkCommentsPlugin,
307
- wikiLinks || files ? linkedSyntax(wikiLinks, files) : [],
308
- // Protect unsupported inline HTML before the empty-line plugin consumes break nodes.
309
- createLiteralPreservation(images || files),
310
- commonmarkWithLiteralReferences,
311
- $node('doc', () => ({
312
- ...docSchema.schema,
313
- attrs: {
314
- ...docSchema.schema.attrs,
315
- [sourceAttribute]: { default: null },
316
- },
317
- })),
318
- references,
319
- wikiLinks ? wikiLinkSchema : [],
320
- callouts,
321
- comments,
322
- inlineHighlight,
323
- preservingCodeBlocks,
324
- preserveSpacerParagraphs,
325
- visibleSoftbreaks,
326
- normalizedImages,
327
- imageBlocks,
328
- autolinkInputRule,
329
- extendListItemSchemaForTask,
330
- strikethroughAttr,
331
- strikethroughSchema,
332
- strikethroughInputRule,
333
- strikethroughKeymap,
334
- toggleStrikethroughCommand,
335
- wrapInTaskListInputRule,
336
- remarkDialectPlugin,
337
- tables,
338
- literalBlock,
339
- ].flat();
340
- }
341
- export const dialect = createDialect(false);
342
- // One output form, so a document written back unchanged is byte-stable.
343
- export const stringifyOptions = {
344
- bullet: '-',
345
- emphasis: '*',
346
- strong: '*',
347
- fences: true,
348
- listItemIndent: 'one',
349
- rule: '-',
350
- };
351
- // Milkdown preserves authored spacer paragraphs with standalone Markdown HTML breaks.
352
- export function serialize(ctx, doc = ctx.get(editorViewCtx).state.doc) {
353
- if (doc.childCount === 1 &&
354
- doc.firstChild?.type.name === 'paragraph' &&
355
- doc.firstChild.content.size === 0)
356
- return '';
357
- return ctx.get(serializerCtx)(doc);
358
- }