@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/source.js DELETED
@@ -1,57 +0,0 @@
1
- import { literalCommentSpans } from './comments.js';
2
- export const sourceAttribute = 'inkkitSource';
3
- export function cleanSourceDoc(doc) {
4
- return doc.attrs[sourceAttribute] == null
5
- ? doc
6
- : doc.type.create({ ...doc.attrs, [sourceAttribute]: null }, doc.content);
7
- }
8
- export function rawOffset(source, normalized) {
9
- let position = 0, count = 0;
10
- while (position < source.length && count < normalized) {
11
- if (source[position] === '\r' && source[position + 1] === '\n')
12
- position++;
13
- position++;
14
- count++;
15
- }
16
- return position;
17
- }
18
- export function normalizedOffset(source, raw) {
19
- return source.slice(0, raw).replace(/\r\n?/g, '\n').length;
20
- }
21
- export function editedPlainSource(previous, value) {
22
- const normalized = previous.replace(/\r\n?/g, '\n');
23
- if (normalized === value)
24
- return previous;
25
- let prefix = 0, suffix = 0;
26
- while (prefix < normalized.length &&
27
- prefix < value.length &&
28
- normalized[prefix] === value[prefix])
29
- prefix++;
30
- while (suffix < normalized.length - prefix &&
31
- suffix < value.length - prefix &&
32
- normalized[normalized.length - suffix - 1] ===
33
- value[value.length - suffix - 1])
34
- suffix++;
35
- const ending = /\r\n|\r|\n/.exec(previous)?.[0] ?? '\n';
36
- return (previous.slice(0, rawOffset(previous, prefix)) +
37
- value
38
- .slice(prefix, value.length - suffix)
39
- .replace(/\r\n?/g, '\n')
40
- .replaceAll('\n', ending) +
41
- previous.slice(rawOffset(previous, normalized.length - suffix)));
42
- }
43
- export function sourceSelection(source, start, end) {
44
- const from = rawOffset(source, start), to = rawOffset(source, end);
45
- let shareable = '', cursor = from;
46
- const bom = source.startsWith('\uFEFF') ? 1 : 0;
47
- for (const parsed of literalCommentSpans(source.slice(bom))) {
48
- const span = { start: parsed.start + bom, end: parsed.end + bom };
49
- if (span.end <= from || span.start >= to)
50
- continue;
51
- if (span.start > cursor)
52
- shareable += source.slice(cursor, Math.min(span.start, to));
53
- cursor = Math.max(cursor, Math.min(span.end, to));
54
- }
55
- shareable += source.slice(cursor, to);
56
- return { markdown: source.slice(from, to), shareable };
57
- }
@@ -1,3 +0,0 @@
1
- import type { Ctx } from '@milkdown/kit/ctx';
2
- import { type ClipboardInput } from './types.js';
3
- export declare function pasteSpreadsheet(ctx: Ctx, input: ClipboardInput): boolean;
@@ -1,275 +0,0 @@
1
- import { editorViewCtx } from '@milkdown/kit/core';
2
- import { DOMParser as ProseParser, Fragment, } from '@milkdown/kit/prose/model';
3
- import { isInTable, selectedRect } from '@milkdown/kit/prose/tables';
4
- import { InkKitError } from './types.js';
5
- import { literalCommentSpans } from './comments.js';
6
- import { normalizeTableAlignment } from './table-alignment.js';
7
- import { dispatchTableOperation, editableTable, selectTableRectangle, } from './tables.js';
8
- export function pasteSpreadsheet(ctx, input) {
9
- const view = ctx.get(editorViewCtx);
10
- if (input.plainText || input.markdown != null)
11
- return false;
12
- const inTable = isInTable(view.state);
13
- if (input.html &&
14
- /data-inkkit-(?:markdown|reference|footnote|comment)/i.test(input.html)) {
15
- if (inTable && /<table[\s>]/i.test(input.html))
16
- reject();
17
- return false;
18
- }
19
- if (input.images?.length || (input.html && /<img[\s>]/i.test(input.html))) {
20
- if (!input.html || !/<table[\s>]/i.test(input.html))
21
- return false;
22
- const template = document.createElement('template');
23
- template.innerHTML = input.html;
24
- for (const image of template.content.querySelectorAll('img'))
25
- image.replaceWith(document.createTextNode(image.getAttribute('alt') ?? 'Image'));
26
- try {
27
- htmlGrid(view.state.schema, template.innerHTML);
28
- return false;
29
- }
30
- catch {
31
- if (!inTable && !standaloneTable(input.html))
32
- return false;
33
- }
34
- }
35
- let grid;
36
- try {
37
- grid = input.html?.match(/<table[\s>]/i)
38
- ? htmlGrid(view.state.schema, input.html)
39
- : input.text.includes('\t')
40
- ? textGrid(view.state.schema, input.text)
41
- : undefined;
42
- }
43
- catch (error) {
44
- if (inTable || !input.html)
45
- throw error;
46
- if (!standaloneTable(input.html))
47
- return false;
48
- const schema = view.state.schema;
49
- const children = [];
50
- let cursor = 0;
51
- for (const span of literalCommentSpans(input.html)) {
52
- if (span.start > cursor)
53
- children.push(schema.text(input.html.slice(cursor, span.start)));
54
- children.push(schema.nodes.comment_inline.create({ syntax: span.syntax, block: Boolean(span.block) }, span.value ? schema.text(span.value) : null));
55
- cursor = span.end;
56
- }
57
- if (cursor < input.html.length)
58
- children.push(schema.text(input.html.slice(cursor)));
59
- const literal = schema.nodes.literal_markdown.create(null, children);
60
- const selection = view.state.selection;
61
- const tr = selection.$from.parent.type.name === 'paragraph' &&
62
- selection.empty &&
63
- selection.$from.parent.content.size === 0
64
- ? view.state.tr.replaceWith(selection.$from.before(), selection.$from.after(), literal)
65
- : view.state.tr.replaceSelectionWith(literal);
66
- dispatchTableOperation(view, tr);
67
- return true;
68
- }
69
- if (!grid)
70
- return false;
71
- if (!inTable) {
72
- const schema = view.state.schema;
73
- const rows = grid.cells.map((row, index) => schema.nodes[index ? 'table_row' : 'table_header_row'].create(null, row.map((content, column) => schema.nodes[index ? 'table_cell' : 'table_header'].create({ alignment: grid.alignment?.[column] ?? 'left' }, schema.nodes.paragraph.create(null, content)))));
74
- const table = schema.nodes.table.create(null, rows);
75
- const selection = view.state.selection;
76
- const tr = selection.$from.parent.type.name === 'paragraph' &&
77
- selection.empty &&
78
- selection.$from.parent.content.size === 0
79
- ? view.state.tr.replaceWith(selection.$from.before(), selection.$from.after(), table)
80
- : view.state.tr.replaceSelectionWith(table);
81
- let tableStart = -1;
82
- tr.doc.descendants((node, pos) => {
83
- if (node === table)
84
- tableStart = pos + 1;
85
- });
86
- if (tableStart < 0)
87
- reject();
88
- selectTableRectangle(tr, tableStart, table, 0, 0, grid.cells.length, grid.width);
89
- dispatchTableOperation(view, tr);
90
- return true;
91
- }
92
- const rect = selectedRect(view.state);
93
- if (!editableTable(rect.table))
94
- reject();
95
- const width = Math.max(rect.map.width, rect.left + grid.width);
96
- const height = Math.max(rect.map.height, rect.top + grid.cells.length);
97
- if (width > 100 || height > 100)
98
- reject();
99
- const schema = view.state.schema;
100
- const alignment = Array.from({ length: width }, (_, column) => column < rect.map.width
101
- ? rect.table.firstChild.child(column).attrs.alignment
102
- : 'left');
103
- const rows = [];
104
- for (let row = 0; row < height; row++) {
105
- const cells = [];
106
- for (let column = 0; column < width; column++) {
107
- const existing = row < rect.map.height && column < rect.map.width
108
- ? rect.table.child(row).child(column)
109
- : undefined;
110
- const incoming = grid.cells[row - rect.top]?.[column - rect.left];
111
- const cleared = row >= rect.top &&
112
- row < rect.bottom &&
113
- column >= rect.left &&
114
- column < rect.right;
115
- if (existing && !incoming && !cleared)
116
- cells.push(existing);
117
- else {
118
- const type = schema.nodes[row ? 'table_cell' : 'table_header'];
119
- cells.push(type.create({ ...(existing?.attrs ?? {}), alignment: alignment[column] }, schema.nodes.paragraph.create(null, incoming)));
120
- }
121
- }
122
- rows.push(schema.nodes[row ? 'table_row' : 'table_header_row'].create(rect.table.maybeChild(row)?.attrs, cells));
123
- }
124
- const table = rect.table.copy(Fragment.fromArray(rows));
125
- const tr = view.state.tr.replaceWith(rect.tableStart - 1, rect.tableStart - 1 + rect.table.nodeSize, table);
126
- selectTableRectangle(tr, rect.tableStart, table, rect.top, rect.left, rect.top + grid.cells.length, rect.left + grid.width);
127
- dispatchTableOperation(view, tr);
128
- return true;
129
- }
130
- function standaloneTable(html) {
131
- const template = document.createElement('template');
132
- template.innerHTML = html;
133
- for (const metadata of template.content.querySelectorAll('meta[charset]'))
134
- metadata.remove();
135
- const elements = [...template.content.childNodes].filter((node) => node.nodeType !== 3 || node.textContent?.trim());
136
- return elements.length === 1 && elements[0] instanceof HTMLTableElement;
137
- }
138
- function reject() {
139
- throw new InkKitError('preservation', 'This spreadsheet cannot be represented safely in a Markdown table. Paste as plain text outside the table to retain its source.');
140
- }
141
- function textGrid(schema, input) {
142
- const text = input.replace(/\r\n?/g, '\n').replace(/\n$/, '');
143
- const rows = [[]];
144
- let value = '', quoted = false, closed = false, start = true;
145
- for (let index = 0; index <= text.length; index++) {
146
- const character = text[index];
147
- if (quoted) {
148
- if (character == null)
149
- reject();
150
- if (character === '"') {
151
- if (text[index + 1] === '"') {
152
- value += '"';
153
- index++;
154
- }
155
- else {
156
- quoted = false;
157
- closed = true;
158
- }
159
- }
160
- else
161
- value += character;
162
- continue;
163
- }
164
- if (character === '"' && start) {
165
- quoted = true;
166
- start = false;
167
- }
168
- else if (character === '\t' || character === '\n' || character == null) {
169
- rows.at(-1).push(value);
170
- value = '';
171
- start = true;
172
- closed = false;
173
- if (character === '\n')
174
- rows.push([]);
175
- }
176
- else {
177
- if (closed)
178
- reject();
179
- value += character;
180
- start = false;
181
- }
182
- }
183
- const width = Math.max(...rows.map((row) => row.length));
184
- if (width > 100 || rows.length > 100)
185
- reject();
186
- if (rows.some((row) => row.some((value) => /[\n\t]/.test(value))))
187
- reject();
188
- return {
189
- width,
190
- cells: rows.map((row) => Array.from({ length: width }, (_, column) => {
191
- const value = row[column] ?? '';
192
- return value ? Fragment.from(schema.text(value)) : Fragment.empty;
193
- })),
194
- };
195
- }
196
- function htmlGrid(schema, html) {
197
- const template = document.createElement('template');
198
- template.innerHTML = html;
199
- const fragment = template.content;
200
- for (const metadata of fragment.querySelectorAll('meta[charset]'))
201
- metadata.remove();
202
- const table = fragment.querySelector('table');
203
- if (!table || fragment.querySelectorAll('table').length !== 1)
204
- reject();
205
- const wrapper = table.parentElement;
206
- if (wrapper && wrapper.tagName !== 'BODY')
207
- reject();
208
- for (const sibling of fragment.childNodes)
209
- if (sibling !== table &&
210
- (sibling.textContent?.trim() || sibling.nodeType !== 3))
211
- reject();
212
- const rows = [...table.querySelectorAll('tr')];
213
- if (document.createTreeWalker(table, NodeFilter.SHOW_COMMENT).nextNode())
214
- reject();
215
- for (const element of table.children) {
216
- if (!['TR', 'THEAD', 'TBODY', 'TFOOT'].includes(element.tagName))
217
- reject();
218
- if (element.tagName !== 'TR')
219
- for (const row of element.children)
220
- if (row.tagName !== 'TR')
221
- reject();
222
- }
223
- const width = rows[0]?.children.length ?? 0;
224
- if (!width || width > 100 || !rows.length || rows.length > 100)
225
- reject();
226
- const parser = ProseParser.fromSchema(schema);
227
- const inline = new Set([
228
- 'STRONG',
229
- 'B',
230
- 'EM',
231
- 'I',
232
- 'S',
233
- 'DEL',
234
- 'STRIKE',
235
- 'CODE',
236
- 'A',
237
- 'MARK',
238
- 'SPAN',
239
- ]);
240
- const cells = rows.map((row) => {
241
- if (row.children.length !== width)
242
- reject();
243
- return [...row.children].map((cell) => {
244
- if (!['TH', 'TD'].includes(cell.tagName))
245
- reject();
246
- if ((cell.hasAttribute('rowspan') &&
247
- cell.getAttribute('rowspan') !== '1') ||
248
- (cell.hasAttribute('colspan') && cell.getAttribute('colspan') !== '1'))
249
- reject();
250
- for (const element of cell.querySelectorAll('*'))
251
- if (!inline.has(element.tagName) &&
252
- !(element.tagName === 'P' &&
253
- element.parentElement === cell &&
254
- cell.children.length === 1))
255
- reject();
256
- const walker = document.createTreeWalker(cell, NodeFilter.SHOW_COMMENT);
257
- if (walker.nextNode())
258
- reject();
259
- if (/[\n\r\t]/.test(cell.textContent ?? ''))
260
- reject();
261
- for (const link of cell.querySelectorAll('a'))
262
- if (!link.hasAttribute('href'))
263
- reject();
264
- const parsed = parser.parse(cell, { preserveWhitespace: true });
265
- if (parsed.childCount === 0)
266
- return Fragment.empty;
267
- if (parsed.childCount !== 1 ||
268
- parsed.firstChild.type.name !== 'paragraph')
269
- reject();
270
- return parsed.firstChild.content;
271
- });
272
- });
273
- const alignment = [...rows[0].children].map((cell) => normalizeTableAlignment(cell) ?? 'left');
274
- return { width, cells, alignment };
275
- }
@@ -1,2 +0,0 @@
1
- export declare function normalizeTableAlignment(element: HTMLElement): 'left' | 'center' | 'right' | null;
2
- export declare function normalizeTableColumnAlignment(element: HTMLElement): 'left' | 'center' | 'right' | null;
@@ -1,46 +0,0 @@
1
- export function normalizeTableAlignment(element) {
2
- const alignment = (element.style.textAlign ||
3
- element.getAttribute('align') ||
4
- '')
5
- .trim()
6
- .toLowerCase();
7
- if (alignment === 'left' || alignment === 'center' || alignment === 'right')
8
- return alignment;
9
- if (alignment !== 'start' && alignment !== 'end')
10
- return null;
11
- let direction = 'ltr';
12
- for (let current = element; current; current = current.parentElement) {
13
- const value = (current.style.direction || current.getAttribute('dir') || '')
14
- .trim()
15
- .toLowerCase();
16
- if (value === 'ltr' || value === 'rtl') {
17
- direction = value;
18
- break;
19
- }
20
- if (value === 'auto') {
21
- const first = [...(current.textContent ?? '')].find((character) => /[\u061c\u200e\u200f]|\p{Letter}/u.test(character));
22
- if (first) {
23
- direction =
24
- /[\u0590-\u08ff\u200f\ufb1d-\ufdff\ufe70-\ufeff\u{10800}-\u{10fff}\u{1e800}-\u{1edff}\u{1e900}-\u{1e95f}]/u.test(first)
25
- ? 'rtl'
26
- : 'ltr';
27
- break;
28
- }
29
- }
30
- }
31
- return alignment === 'start'
32
- ? direction === 'rtl'
33
- ? 'right'
34
- : 'left'
35
- : direction === 'rtl'
36
- ? 'left'
37
- : 'right';
38
- }
39
- export function normalizeTableColumnAlignment(element) {
40
- if (!(element instanceof HTMLTableCellElement))
41
- return normalizeTableAlignment(element);
42
- const table = element.closest('table');
43
- const header = table?.rows[0]?.cells[element.cellIndex];
44
- // GFM represents alignment once per column, independently of cell direction.
45
- return normalizeTableAlignment(header ?? element);
46
- }
package/dist/tables.d.ts DELETED
@@ -1,27 +0,0 @@
1
- import type { Ctx } from '@milkdown/kit/ctx';
2
- import { type Node as ProseNode } from '@milkdown/kit/prose/model';
3
- import type { EditorView } from '@milkdown/kit/prose/view';
4
- import type { EditorState, Transaction } from '@milkdown/kit/prose/state';
5
- export type TableCommand = 'insert' | 'addRowBefore' | 'addRowAfter' | 'addColumnBefore' | 'addColumnAfter' | 'deleteRow' | 'deleteColumn' | 'deleteTable' | 'alignLeft' | 'alignCenter' | 'alignRight' | 'moveRowUp' | 'moveRowDown' | 'moveColumnLeft' | 'moveColumnRight' | 'sortRows' | 'exit';
6
- export declare const tableCommands: readonly TableCommand[];
7
- export declare function tableContext(state: EditorState): {
8
- row: number;
9
- column: number;
10
- rows: number;
11
- columns: number;
12
- } | undefined;
13
- /** Checks the same default operations without dispatching a transaction. */
14
- export declare function tableAvailability(ctx: Ctx): Record<TableCommand, boolean>;
15
- export interface TableOptions {
16
- rows?: number;
17
- columns?: number;
18
- column?: number;
19
- order?: 'ascending' | 'descending';
20
- comparison?: 'text' | 'number';
21
- }
22
- export declare const tablePlugins: (((ctx: Ctx) => () => void) | import("@milkdown/kit/ctx").MilkdownPlugin)[];
23
- export declare function tableCommand(ctx: Ctx, command: TableCommand, options?: TableOptions): boolean;
24
- export declare function dispatchTableOperation(view: EditorView, tr: Transaction): void;
25
- export declare function configureTableMovement(ctx: Ctx, canEdit: () => boolean): void;
26
- export declare function editableTable(table: ProseNode): boolean;
27
- export declare function selectTableRectangle(tr: Transaction, tableStart: number, table: ProseNode, top: number, left: number, bottom: number, right: number): void;