@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,171 +0,0 @@
1
- import { codeBlockSchema } from '@milkdown/kit/preset/commonmark';
2
- import { $remark } from '@milkdown/kit/utils';
3
- import { defaultHandlers } from 'mdast-util-to-markdown';
4
- import { remarkCtx } from '@milkdown/kit/core';
5
- function readFence(value) {
6
- if (typeof value !== 'object' || value == null)
7
- return null;
8
- const fence = value;
9
- return typeof fence.marker === 'string' &&
10
- /^(?:`{3,}|~{3,})$/.test(fence.marker) &&
11
- fence.marker.length <= 30000 &&
12
- typeof fence.info === 'string' &&
13
- !/[\r\n]/.test(fence.info) &&
14
- // A backtick in the info string of a backtick fence is not a fence.
15
- !(fence.marker[0] === '`' && fence.info.includes('`')) &&
16
- typeof fence.close === 'string' &&
17
- (!fence.close ||
18
- new RegExp(`^${fence.marker[0]}{${fence.marker.length},}$`).test(fence.close)) &&
19
- typeof fence.trailing === 'string' &&
20
- /^[ \t]*$/.test(fence.trailing) &&
21
- ['\n', '\r\n'].includes(fence.ending)
22
- ? fence
23
- : null;
24
- }
25
- export const remarkCodeFences = $remark('codeFences', () => () => (tree, file) => {
26
- const source = String(file.value).replace(/^\uFEFF/, '');
27
- const visit = (node) => {
28
- if (node.type === 'code') {
29
- const raw = source.slice(node.position?.start.offset, node.position?.end.offset);
30
- const opening = /^(`{3,}|~{3,})([^\r\n]*)(\r?\n)/.exec(raw);
31
- if (opening) {
32
- const close = /(?:^|\n)[ \t>]*(`{3,}|~{3,})([ \t]*)\r?$/.exec(raw);
33
- const matching = close &&
34
- close[1][0] === opening[1][0] &&
35
- close[1].length >= opening[1].length;
36
- node.data = {
37
- ...node.data,
38
- inkkitFence: {
39
- marker: opening[1],
40
- info: opening[2],
41
- close: matching ? close[1] : '',
42
- trailing: matching ? close[2] : '',
43
- ending: opening[3],
44
- },
45
- };
46
- }
47
- }
48
- if ('children' in node)
49
- node.children.forEach(visit);
50
- };
51
- visit(tree);
52
- });
53
- export const preservingCodeBlocks = codeBlockSchema.extendSchema((base) => (ctx) => {
54
- const schema = base(ctx);
55
- return {
56
- ...schema,
57
- attrs: { ...schema.attrs, authoredFence: { default: null } },
58
- parseDOM: [
59
- {
60
- tag: 'pre',
61
- preserveWhitespace: 'full',
62
- getAttrs: (dom) => {
63
- let authoredFence = null;
64
- try {
65
- authoredFence = readFence(JSON.parse(dom.getAttribute('data-inkkit-fence') ?? 'null'));
66
- // An unclosed fence would take in the content that follows it.
67
- if (!authoredFence?.close)
68
- authoredFence = null;
69
- }
70
- catch {
71
- /* Ordinary code stays usable without provenance. */
72
- }
73
- return { language: dom.dataset.language ?? '', authoredFence };
74
- },
75
- },
76
- ],
77
- toDOM: (node) => [
78
- 'pre',
79
- {
80
- 'data-language': node.attrs.language,
81
- ...(node.attrs.authoredFence
82
- ? { 'data-inkkit-fence': JSON.stringify(node.attrs.authoredFence) }
83
- : {}),
84
- },
85
- ['code', 0],
86
- ],
87
- parseMarkdown: {
88
- match: (node) => node.type === 'code',
89
- runner: (state, node, type) => {
90
- state.openNode(type, {
91
- language: node.lang ?? '',
92
- authoredFence: readFence(node.data?.inkkitFence),
93
- });
94
- if (node.value)
95
- state.addText(String(node.value).replace(/\r\n?/g, '\n'));
96
- state.closeNode();
97
- },
98
- },
99
- toMarkdown: {
100
- match: (node) => node.type.name === 'code_block',
101
- runner: (state, node) => {
102
- state.addNode('code', undefined, node.textContent, {
103
- lang: node.attrs.language,
104
- data: { inkkitFence: node.attrs.authoredFence },
105
- });
106
- },
107
- },
108
- };
109
- });
110
- export const fencedCodeHandler = (node, parent, state, info) => {
111
- const fence = readFence(node.data?.inkkitFence);
112
- if (!fence)
113
- return defaultHandlers.code(node, parent, state, info);
114
- const character = fence.marker[0];
115
- let length = fence.marker.length;
116
- const body = (node.value ?? '').replace(/\r\n?/g, '\n');
117
- for (const line of body.split('\n')) {
118
- const run = new RegExp(`^ {0,3}(${character}+)[ \\t]*$`).exec(line);
119
- if (run)
120
- length = Math.max(length, run[1].length + 1);
121
- }
122
- const close = fence.close
123
- ? character.repeat(Math.max(length, fence.close.length)) + fence.trailing
124
- : '';
125
- return (character.repeat(length) +
126
- fence.info +
127
- fence.ending +
128
- body.replaceAll('\n', fence.ending) +
129
- (close ? (body ? fence.ending : '') + close : ''));
130
- };
131
- export function restoreCodeEndings(ctx, doc, markdown) {
132
- const endings = [];
133
- doc.descendants((node) => {
134
- if (node.type.name === 'code_block')
135
- endings.push(readFence(node.attrs.authoredFence)?.ending ?? '\n');
136
- });
137
- const patches = [];
138
- let index = 0;
139
- const visit = (node) => {
140
- if (node.type === 'code') {
141
- const ending = endings[index++];
142
- const from = node.position?.start.offset, to = node.position?.end.offset;
143
- if (ending === '\r\n' && from != null && to != null)
144
- patches.push({
145
- from,
146
- to,
147
- text: markdown
148
- .slice(from, to)
149
- .replace(/\r\n?/g, '\n')
150
- .replaceAll('\n', ending),
151
- });
152
- }
153
- if ('children' in node)
154
- node.children.forEach(visit);
155
- };
156
- const processor = ctx.get(remarkCtx);
157
- visit(processor.runSync(processor.parse(markdown), { value: markdown }));
158
- for (const patch of patches.reverse())
159
- markdown =
160
- markdown.slice(0, patch.from) + patch.text + markdown.slice(patch.to);
161
- return markdown;
162
- }
163
- export function finalCodeEnding(doc) {
164
- let last = doc.lastChild;
165
- while (last) {
166
- if (last.type.name === 'code_block')
167
- return readFence(last.attrs.authoredFence)?.ending;
168
- last = last.lastChild;
169
- }
170
- return undefined;
171
- }
@@ -1,76 +0,0 @@
1
- import { Fragment, type Node as ProseNode } from '@milkdown/kit/prose/model';
2
- import { type Transaction } from '@milkdown/kit/prose/state';
3
- import type { EditorView } from '@milkdown/kit/prose/view';
4
- import type { Literal } from 'mdast';
5
- export type CommentSyntax = 'html' | 'obsidian';
6
- interface Comment extends Literal {
7
- type: 'inkkitCommentInline' | 'inkkitCommentBlock';
8
- syntax: CommentSyntax;
9
- block?: boolean;
10
- }
11
- declare module 'mdast' {
12
- interface PhrasingContentMap {
13
- inkkitCommentInline: Comment & {
14
- type: 'inkkitCommentInline';
15
- };
16
- }
17
- interface BlockContentMap {
18
- inkkitCommentBlock: Comment & {
19
- type: 'inkkitCommentBlock';
20
- };
21
- }
22
- interface RootContentMap {
23
- inkkitCommentInline: Comment & {
24
- type: 'inkkitCommentInline';
25
- };
26
- inkkitCommentBlock: Comment & {
27
- type: 'inkkitCommentBlock';
28
- };
29
- }
30
- }
31
- declare module 'micromark-util-types' {
32
- interface TokenTypeMap {
33
- inkkitCommentInline: 'inkkitCommentInline';
34
- inkkitCommentBlock: 'inkkitCommentBlock';
35
- inkkitCommentData: 'inkkitCommentData';
36
- }
37
- }
38
- export declare function commentSource(node: ProseNode): string;
39
- export interface CommentSpan {
40
- start: number;
41
- end: number;
42
- syntax: CommentSyntax;
43
- value: string;
44
- block?: boolean;
45
- }
46
- export declare function literalCommentSpans(value: string): CommentSpan[];
47
- export declare const remarkCommentsPlugin: import("@milkdown/kit/utils").$Remark<"remarkComments", unknown>;
48
- export declare const commentInline: import("@milkdown/kit/utils").$Node;
49
- export declare const commentBlock: import("@milkdown/kit/utils").$Node;
50
- export declare const commentVisibility: import("@milkdown/kit/utils").$Prose;
51
- export declare function setCommentVisibility(view: EditorView, visible: boolean): void;
52
- export declare const comments: (import("@milkdown/kit/utils").$Node | import("@milkdown/kit/utils").$Prose)[];
53
- /**
54
- * Whether text inside a comment ends it early for a reader other than InkKit.
55
- * HTML ends a comment at `-->` or `--!>`, and treats a start of `>` or `->` as
56
- * an empty comment. A `%%` comment ends at its next `%%`.
57
- */
58
- export declare function commentTextEndsEarly(syntax: string, text: string): boolean;
59
- /**
60
- * Refuses an edit that gives a comment text which ends it early. A comment
61
- * that already held that text before the edit is left alone, so a note that
62
- * has one still loads and can be edited elsewhere.
63
- */
64
- export declare function assertCommentsEndWhereWritten(before: ProseNode, after: ProseNode): void;
65
- /** Marks a transaction that replaces the document with source given as written. */
66
- export declare const sourceReplacement = "inkkit:sourceReplacement";
67
- /**
68
- * Whether an edit is typed or inserted by a person in the formatted editor. A
69
- * history step restores a document the editor already accepted, and a source
70
- * replacement is the author's own text, so neither is checked.
71
- */
72
- export declare function isWrittenEdit(tr: Transaction): boolean;
73
- export declare function isComment(node: ProseNode): boolean;
74
- export declare function shareableFragment(content: Fragment): Fragment;
75
- export declare function commentSelectionContent(doc: ProseNode, from: number, to: number, content: Fragment): Fragment;
76
- export {};