markloom 0.6.0 → 0.7.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 (59) hide show
  1. package/collab.md +25 -13
  2. package/dist/ai/index.cjs +5 -4
  3. package/dist/ai/index.d.cts +5 -5
  4. package/dist/ai/index.d.ts +5 -5
  5. package/dist/ai/index.js +4 -3
  6. package/dist/{chunk-KYZJIOOL.js → chunk-4Q7PAR2T.js} +3671 -904
  7. package/dist/chunk-75EJ4ARB.cjs +642 -0
  8. package/dist/{chunk-U3JZDFL4.cjs → chunk-BMPCVT3B.cjs} +2 -34
  9. package/dist/{chunk-VSBIMMI7.js → chunk-EFYT2223.js} +3 -35
  10. package/dist/chunk-HXABDVLZ.cjs +297 -0
  11. package/dist/{chunk-I5VK4U7J.cjs → chunk-I2LDEVLA.cjs} +434 -80
  12. package/dist/{chunk-YBAT343I.js → chunk-MQLRZQZL.js} +263 -119
  13. package/dist/chunk-OVHASRID.cjs +4279 -0
  14. package/dist/chunk-PCSVBPOR.cjs +40 -0
  15. package/dist/{chunk-TB2OY3D4.js → chunk-PSAXWBNM.js} +413 -59
  16. package/dist/{chunk-QEVME6ZU.cjs → chunk-PZRWTLLB.cjs} +260 -161
  17. package/dist/chunk-QO7JEZDB.js +4279 -0
  18. package/dist/{chunk-EJSFZHGT.js → chunk-WSJUXPAG.js} +18 -2
  19. package/dist/{chunk-ACFYBYZJ.cjs → chunk-Y4IXQFWL.cjs} +4212 -1445
  20. package/dist/{chunk-CGYCJORO.js → chunk-YLVSMDIO.js} +220 -121
  21. package/dist/chunk-ZL6WT6OY.js +297 -0
  22. package/dist/{client-CLYq17SW.d.ts → client-BvvyHjhh.d.ts} +57 -7
  23. package/dist/{client-DAth8pPq.d.cts → client-Ciy7Fa_k.d.cts} +57 -7
  24. package/dist/collab/index.cjs +5 -4
  25. package/dist/collab/index.d.cts +13 -15
  26. package/dist/collab/index.d.ts +13 -15
  27. package/dist/collab/index.js +4 -3
  28. package/dist/{controller-BIOO_XKJ.d.cts → controller-CHznEhAR.d.cts} +186 -27
  29. package/dist/{controller-6AJ36G52.d.ts → controller-DLqI8_jm.d.ts} +186 -27
  30. package/dist/index.cjs +69 -7
  31. package/dist/index.d.cts +127 -8
  32. package/dist/index.d.ts +127 -8
  33. package/dist/index.js +80 -18
  34. package/dist/io/index.cjs +58 -59
  35. package/dist/io/index.d.cts +1 -1
  36. package/dist/io/index.d.ts +1 -1
  37. package/dist/io/index.js +15 -16
  38. package/dist/react/index.cjs +9 -8
  39. package/dist/react/index.d.cts +5 -5
  40. package/dist/react/index.d.ts +5 -5
  41. package/dist/react/index.js +8 -7
  42. package/dist/{rebase-batch-DlerAcFN.d.ts → rebase-batch-CSnv8FKp.d.ts} +1 -1
  43. package/dist/{rebase-batch-PjENQ742.d.cts → rebase-batch-DO1ygkx9.d.cts} +1 -1
  44. package/dist/{types-COUweEav.d.cts → types-BkHlmUFL.d.cts} +5 -1
  45. package/dist/{types-COUweEav.d.ts → types-BkHlmUFL.d.ts} +5 -1
  46. package/dist/{versions-9mG1epfB.d.cts → versions-DNFf8zVz.d.cts} +1 -1
  47. package/dist/{versions-Bubyo4pt.d.ts → versions-DOkOyh2J.d.ts} +1 -1
  48. package/dist/view/index.cjs +215 -17
  49. package/dist/view/index.d.cts +82 -9
  50. package/dist/view/index.d.ts +82 -9
  51. package/dist/view/index.js +212 -14
  52. package/dist/view/theme.css +349 -75
  53. package/dist/{suggest-Bk4zLzuv.d.ts → word-count-BPw9G2Bg.d.ts} +15 -5
  54. package/dist/{suggest-BkGGiPKA.d.cts → word-count-DNLn1h_t.d.cts} +15 -5
  55. package/package.json +11 -6
  56. package/dist/chunk-EADZKEU4.cjs +0 -498
  57. package/dist/chunk-SNFF6X45.js +0 -2347
  58. package/dist/chunk-TWD5T4YC.cjs +0 -2347
  59. package/dist/chunk-ZKQSQSSM.cjs +0 -24
package/dist/index.d.cts CHANGED
@@ -1,9 +1,9 @@
1
- import { S as Step } from './versions-9mG1epfB.cjs';
2
- export { D as DeleteText, a as DocVersion, I as InsertText, R as ReplaceNode, b as SpliceChildren, c as apply, d as applyAll, g as getVersion, i as invert, e as invertAll, m as moveBlock, p as pushVersion, r as removeVersion, s as snapshotDoc } from './versions-9mG1epfB.cjs';
3
- import { E as ElementNode, P as Path, N as Node, a as Position } from './types-COUweEav.cjs';
4
- export { D as Doc, M as Mark, S as Selection, T as TextNode, i as isElement, b as isInlineAtom, c as isText } from './types-COUweEav.cjs';
5
- export { C as CommentAuthor, a as CommentMessage, b as CommentRenderState, c as CommentThread, d as Commit, H as History, S as SearchOpts, e as SuggestAuthor, f as SuggestHit, g as SuggestKind, T as TextMatch, h as acceptSuggestion, i as amend, j as applyForeign, k as applyReplaceAll, l as commentIdsInDoc, m as commit, n as dropSuggestText, o as findText, p as init, q as isSuggestMark, r as listSuggestions, s as markSuggestRange, t as rangeForDelete, u as rangeIsSuggestInsert, v as redo, w as rejectSuggestion, x as replaceAll, y as replaceMatch, z as stripCommentMarks, A as stripSuggestMarks, B as suggestIdsInDoc, D as suggestMark, E as undo } from './suggest-BkGGiPKA.cjs';
6
- export { B as Bias, m as makeBias, d as rebase, r as rebaseBatchOver, a as rebaseOne, b as rebaseStepsThrough, t as transformRemoteAgainstPending } from './rebase-batch-PjENQ742.cjs';
1
+ import { S as Step } from './versions-DNFf8zVz.cjs';
2
+ export { D as DeleteText, a as DocVersion, I as InsertText, R as ReplaceNode, b as SpliceChildren, c as apply, d as applyAll, g as getVersion, i as invert, e as invertAll, m as moveBlock, p as pushVersion, r as removeVersion, s as snapshotDoc } from './versions-DNFf8zVz.cjs';
3
+ import { E as ElementNode, P as Path, N as Node, a as Position, T as TextNode, M as Mark } from './types-BkHlmUFL.cjs';
4
+ export { D as Doc, S as Selection, f as footnoteKey, i as isAiCompose, b as isCallout, c as isElement, d as isFootnoteDef, e as isInlineAtom, g as isText } from './types-BkHlmUFL.cjs';
5
+ export { C as CommentAuthor, a as CommentMessage, b as CommentRenderState, c as CommentThread, d as Commit, H as History, S as SearchOpts, e as SuggestAuthor, f as SuggestHit, g as SuggestKind, T as TextMatch, W as WordCount, h as acceptSuggestion, i as amend, j as applyForeign, k as applyReplaceAll, l as commentIdsInDoc, m as commit, n as dropSuggestText, o as findText, p as init, q as isSuggestMark, r as listSuggestions, s as markSuggestRange, t as rangeForDelete, u as rangeIsSuggestInsert, v as redo, w as rejectSuggestion, x as replaceAll, y as replaceMatch, z as stripCommentMarks, A as stripSuggestMarks, B as suggestIdsInDoc, D as suggestMark, E as undo, F as wordCount } from './word-count-DNLn1h_t.cjs';
6
+ export { B as Bias, m as makeBias, d as rebase, r as rebaseBatchOver, a as rebaseOne, b as rebaseStepsThrough, t as transformRemoteAgainstPending } from './rebase-batch-DO1ygkx9.cjs';
7
7
 
8
8
  interface TableShape {
9
9
  rows: number;
@@ -30,12 +30,14 @@ declare function caretCell(tablePath: Path, table: ElementNode, caret: Path): {
30
30
  r: number;
31
31
  c: number;
32
32
  } | null;
33
+ declare const DEFAULT_COL_WIDTH = 120;
33
34
  declare function makeTable(id: string, rows: number, cols: number): ElementNode;
34
35
  declare function cellText(table: ElementNode, r: number, c: number): string;
35
36
  declare function nextCell(table: ElementNode, r: number, c: number, dir: 1 | -1): {
36
37
  r: number;
37
38
  c: number;
38
39
  };
40
+ declare function isLastCell(table: ElementNode, r: number, c: number): boolean;
39
41
  declare function arrowCell(table: ElementNode, r: number, c: number, dir: 'up' | 'down' | 'left' | 'right'): {
40
42
  r: number;
41
43
  c: number;
@@ -47,7 +49,9 @@ declare function deleteCol(table: ElementNode, tablePath: Path, c: number, doc?:
47
49
  declare function hasSpan(table: ElementNode): boolean;
48
50
  declare function moveRow(table: ElementNode, tablePath: Path, from: number, to: number): Step;
49
51
  declare function moveCol(table: ElementNode, tablePath: Path, from: number, to: number): Step;
52
+ declare function cellRectTable(table: ElementNode, r1: number, c1: number, r2: number, c2: number): ElementNode;
50
53
  declare function tableColWidths(table: ElementNode): number[] | null;
54
+ declare function resolvedColWidths(table: ElementNode): number[];
51
55
  declare function setColWidths(table: ElementNode, tablePath: Path, widths: number[]): Step;
52
56
  declare function setAlign(table: ElementNode, tablePath: Path, col: number, value: 'left' | 'center' | 'right' | null): Step;
53
57
  declare function mergeCells(table: ElementNode, tablePath: Path, r1: number, c1: number, r2: number, c2: number): Step;
@@ -66,9 +70,14 @@ declare function setFreeze(table: ElementNode, tablePath: Path, freeze: {
66
70
  rows?: number;
67
71
  cols?: number;
68
72
  }): Step;
73
+ declare function setHeaderCol(table: ElementNode, tablePath: Path, on: boolean): Step;
69
74
  declare function deleteTableBlock(tablePath: Path, doc?: ElementNode): Step;
70
75
  declare function tableAt(doc: ElementNode, tablePath: Path): ElementNode | null;
71
76
  declare function checkTable(table: ElementNode): string[];
77
+ /** 名保留兼容;定义 = cellBlockTypes() */
78
+ declare const CELL_BLOCK_TYPES: readonly string[];
79
+ type CellBlockType = string;
80
+ declare function isCellBlockType(type: string): boolean;
72
81
  declare const tableSchema: {
73
82
  marks: string[];
74
83
  nodes: {
@@ -83,10 +92,68 @@ declare const tableSchema: {
83
92
  content: string[];
84
93
  inline: boolean;
85
94
  };
95
+ list: {
96
+ content: string[];
97
+ };
98
+ list_item: {
99
+ content: string[];
100
+ };
101
+ quote: {
102
+ content: string[];
103
+ };
104
+ callout: {
105
+ content: string[];
106
+ };
107
+ code: {
108
+ content: string[];
109
+ inline: boolean;
110
+ marks: never[];
111
+ };
112
+ image: {
113
+ content: never[];
114
+ atom: boolean;
115
+ };
116
+ embed: {
117
+ content: never[];
118
+ atom: boolean;
119
+ };
120
+ raw: {
121
+ content: string[];
122
+ inline: boolean;
123
+ marks: never[];
124
+ };
86
125
  };
87
126
  };
88
127
 
89
- declare function mdToDoc(md: string): ElementNode;
128
+ /**
129
+ * 公式怎么写进 Markdown。
130
+ * - `'html'`(默认):`<span data-math data-latex=…>$x$</span>`,`$x$` 不当公式读(README 里的 `$HOME/$USER` 还是字)。
131
+ * - `'dollar'`:读写 `$x$`、`$$x$$`(pandoc 的规则,见 md-math.ts),Typora、Obsidian、GitHub 都读得懂。
132
+ * 旧的 span 照读;没改过的块逐字节不变,改过的块里的公式写成 `$`;写不成 `$` 的(公式里有空行、开头是空格)仍写 span。
133
+ * 这是这个页面的文件格式,不是某一个编辑器的:在打开任何文档之前设一次。
134
+ */
135
+ declare function setMathSyntax(syntax: 'html' | 'dollar'): void;
136
+ interface MdToDocAsyncOptions {
137
+ chunkBytes?: number;
138
+ /** 每一片最多占主线程这么久(毫秒,默认 6)。片与片之间把线程还给浏览器,输入、滚动、绘制不被 3 秒的解析冻住。 */
139
+ budgetMs?: number;
140
+ /** 解出至少这么多个块后,调用一次 onHead,给一份「文档开头」的预览树(默认 200 块,约一屏多)。 */
141
+ headBlocks?: number;
142
+ /**
143
+ * 开头预览。**只能看,不能编辑、不能存盘**:它只是整篇的前缀,结尾处的 callout 若还没等到 `</div>` 会按普通块降级,
144
+ * 且它没有后面的块——拿它当文档存回去就丢了全文。真正的文档是 promise 的结果。
145
+ * 预览的块 id 与最终文档里同位置的块相同(都是 b0、b1…),所以换成完整文档时块能原地对上。
146
+ */
147
+ onHead?: (head: ElementNode) => void;
148
+ signal?: AbortSignal;
149
+ }
150
+ /**
151
+ * mdToDoc 的非阻塞版:同一份解析代码(生成器),每解完一块看一眼用掉了多少时间,超了预算就把主线程还出去再继续。
152
+ * 结果与 mdToDoc(md) 逐字节相同(同一个生成器,只是中间多了让出)。总耗时比同步版略长(让出的间隙),但没有一次超过预算的阻塞。
153
+ * 块的粒度见 md-chunk.ts:单块一般 1–3 ms,个别切不开的大表/大代码块更长,那一块里没法再让。
154
+ */
155
+ declare function mdToDocAsync(md: string, opts?: MdToDocAsyncOptions): Promise<ElementNode>;
156
+ declare function mdToDoc(md: string, chunkBytes?: number): ElementNode;
90
157
  declare function htmlToBlocks(html: string): ElementNode[] | null;
91
158
  declare function isRichHtmlBlocks(blocks: ElementNode[]): boolean;
92
159
  declare function isPlainTransportHtml(blocks: ElementNode[]): boolean;
@@ -106,6 +173,12 @@ interface Resolved {
106
173
  }
107
174
  declare function resolve(doc: ElementNode, path: Path): Resolved;
108
175
  declare function firstLeafPath(block: ElementNode): Path;
176
+ /**
177
+ * 元素内 child 缝 at → 最近可落文本叶。
178
+ * 空 atom(image/embed/hard_break/math)从缝上跳过,吸到后侧文本首;
179
+ * mention 不跳,归前叶尾。再无文本才扫另一侧。
180
+ */
181
+ declare function gapToTextPath(parent: ElementNode, at: number, prefix?: Path): Path;
109
182
  declare function normalizeToLeaf(doc: ElementNode, path: Path): Path;
110
183
  declare function lastLeafEnd(block: ElementNode): Path;
111
184
  declare function nodeAt(doc: ElementNode, path: Path): Node;
@@ -177,6 +250,24 @@ declare function resolveTxAfter<S extends {
177
250
  }>(before: S | null | undefined, after: S | null | undefined, steps: readonly Step[], gaps?: readonly Step[]): S | undefined;
178
251
  declare function normalizePosition(doc: ElementNode, pos: Position): Position;
179
252
 
253
+ /**
254
+ * Content spaces — composable finite block sets (runtime + domain share).
255
+ *
256
+ * bodyBlocks = doc.content
257
+ * cellBlocks = bodyBlocks − { heading, table, ai }
258
+ *
259
+ * Definition is set algebra, not a second hand-written list.
260
+ */
261
+
262
+ /** Types in body but not admitted as table-cell children. */
263
+ declare const CELL_EXCLUDED_FROM_BODY: readonly ["heading", "table"];
264
+ /** Top-level block types under doc (paste/transform palette). */
265
+ declare function bodyBlockTypes(schema?: Schema): readonly string[];
266
+ /** Table-cell admit set = body − CELL_EXCLUDED_FROM_BODY. */
267
+ declare function cellBlockTypes(schema?: Schema): readonly string[];
268
+ declare function isBodyBlockType(type: string, schema?: Schema): boolean;
269
+ declare function isCellBlockTypeInSpace(type: string, schema?: Schema): boolean;
270
+
180
271
  interface DocStats {
181
272
  chars: number;
182
273
  words: number;
@@ -184,6 +275,15 @@ interface DocStats {
184
275
  }
185
276
  declare function docStats(doc: ElementNode): DocStats;
186
277
 
278
+ declare const FRONT_MATTER = "frontmatter";
279
+ declare function isFrontMatter(n: Node | null | undefined): boolean;
280
+ /**
281
+ * md 开头是 front matter 时,返回闭合栅栏文字的结束偏移(不含其后的空白和换行);不是则 -1。
282
+ * 判据:首行只有 `---`(行尾空白不算);往下第一条只有 `---` / `...` 的行闭合;两条栅栏之间至少有一行非空白
283
+ * (`---\n---` 是两条分隔线,不是空的 front matter)。CRLF 照常认。
284
+ */
285
+ declare function frontMatterEnd(md: string): number;
286
+
187
287
  interface TocEntry {
188
288
  level: number;
189
289
  text: string;
@@ -192,4 +292,23 @@ interface TocEntry {
192
292
  }
193
293
  declare function outline(doc: ElementNode): TocEntry[];
194
294
 
195
- export { type DocStats, ElementNode, type Grid, type IdIndex, Node, type NodeChange, type NodeSpec, Path, Position, type Resolved, type Schema, Step, type TableShape, type TocEntry, type Violation, appendText, arrowCell, basicSchema, buildGrid, buildIdIndex, calloutToHtml, caretCell, cellCaret, cellText, checkSchema, checkTable, clearCells, colspanOf, deleteCol, deleteRow, deleteTableBlock, diffById, docStats, docToMd, embedHtml, firstLeafPath, firstViolation, hasSpan, htmlToBlocks, insertAfter, insertCol, insertRow, invariants, isPlainTransportHtml, isRichHtmlBlocks, lastLeafEnd, makeTable, mapPosition, mapSelection, mapSelectionThrough, mdStructureBeatsTransport, mdToDoc, mergeCells, moveCol, moveRow, nextCell, nodeAt, normalizePosition, normalizeToLeaf, outline, pathOfId, preferMarkdownPaste, replaceAt, resolve, resolveTxAfter, rewriteNode, rowspanOf, setAlign, setCellStyle, setColWidths, setFreeze, spliceAt, splitCell, tableAt, tableColWidths, tableHasExtras, tableSchema, tableShape, tableToHtml, validate, validateAll };
295
+ declare function markIdsInDoc(doc: ElementNode, name: string): Set<string>;
296
+ declare function mapLeafBlocks(doc: ElementNode, fn: (node: ElementNode, path: Path) => ElementNode | null): Step[];
297
+ declare function stripMarks(doc: ElementNode, pred: (m: Mark) => boolean): Step[];
298
+ declare function dropMarkedLeaves(doc: ElementNode, pred: (leaf: TextNode) => boolean): Step[];
299
+
300
+ interface FootnoteIndex {
301
+ /** 引用首次出现的顺序(规范化键);编号 = 下标 + 1。 */
302
+ order: string[];
303
+ /** 键 → 定义块(同一键多个定义时取第一个,同 CommonMark 引用定义)。 */
304
+ defs: Map<string, ElementNode>;
305
+ /** 键 → 引用次数。 */
306
+ refs: Map<string, number>;
307
+ }
308
+ declare function footnoteIndex(doc: ElementNode): FootnoteIndex;
309
+ /** 一个块的纯文本(块间换行),悬停卡显示用。 */
310
+ declare function footnoteText(def: ElementNode): string;
311
+ /** 文档里有没有任何脚注(引用或定义):没有就不必为编号付任何代价。 */
312
+ declare function hasFootnotes(doc: ElementNode): boolean;
313
+
314
+ export { CELL_BLOCK_TYPES, CELL_EXCLUDED_FROM_BODY, type CellBlockType, DEFAULT_COL_WIDTH, type DocStats, ElementNode, FRONT_MATTER, type FootnoteIndex, type Grid, type IdIndex, Mark, type MdToDocAsyncOptions, Node, type NodeChange, type NodeSpec, Path, Position, type Resolved, type Schema, Step, type TableShape, TextNode, type TocEntry, type Violation, appendText, arrowCell, basicSchema, bodyBlockTypes, buildGrid, buildIdIndex, calloutToHtml, caretCell, cellBlockTypes, cellCaret, cellRectTable, cellText, checkSchema, checkTable, clearCells, colspanOf, deleteCol, deleteRow, deleteTableBlock, diffById, docStats, docToMd, dropMarkedLeaves, embedHtml, firstLeafPath, firstViolation, footnoteIndex, footnoteText, frontMatterEnd, gapToTextPath, hasFootnotes, hasSpan, htmlToBlocks, insertAfter, insertCol, insertRow, invariants, isBodyBlockType, isCellBlockType, isCellBlockTypeInSpace, isFrontMatter, isLastCell, isPlainTransportHtml, isRichHtmlBlocks, lastLeafEnd, makeTable, mapLeafBlocks, mapPosition, mapSelection, mapSelectionThrough, markIdsInDoc, mdStructureBeatsTransport, mdToDoc, mdToDocAsync, mergeCells, moveCol, moveRow, nextCell, nodeAt, normalizePosition, normalizeToLeaf, outline, pathOfId, preferMarkdownPaste, replaceAt, resolve, resolveTxAfter, resolvedColWidths, rewriteNode, rowspanOf, setAlign, setCellStyle, setColWidths, setFreeze, setHeaderCol, setMathSyntax, spliceAt, splitCell, stripMarks, tableAt, tableColWidths, tableHasExtras, tableSchema, tableShape, tableToHtml, validate, validateAll };
package/dist/index.d.ts CHANGED
@@ -1,9 +1,9 @@
1
- import { S as Step } from './versions-Bubyo4pt.js';
2
- export { D as DeleteText, a as DocVersion, I as InsertText, R as ReplaceNode, b as SpliceChildren, c as apply, d as applyAll, g as getVersion, i as invert, e as invertAll, m as moveBlock, p as pushVersion, r as removeVersion, s as snapshotDoc } from './versions-Bubyo4pt.js';
3
- import { E as ElementNode, P as Path, N as Node, a as Position } from './types-COUweEav.js';
4
- export { D as Doc, M as Mark, S as Selection, T as TextNode, i as isElement, b as isInlineAtom, c as isText } from './types-COUweEav.js';
5
- export { C as CommentAuthor, a as CommentMessage, b as CommentRenderState, c as CommentThread, d as Commit, H as History, S as SearchOpts, e as SuggestAuthor, f as SuggestHit, g as SuggestKind, T as TextMatch, h as acceptSuggestion, i as amend, j as applyForeign, k as applyReplaceAll, l as commentIdsInDoc, m as commit, n as dropSuggestText, o as findText, p as init, q as isSuggestMark, r as listSuggestions, s as markSuggestRange, t as rangeForDelete, u as rangeIsSuggestInsert, v as redo, w as rejectSuggestion, x as replaceAll, y as replaceMatch, z as stripCommentMarks, A as stripSuggestMarks, B as suggestIdsInDoc, D as suggestMark, E as undo } from './suggest-Bk4zLzuv.js';
6
- export { B as Bias, m as makeBias, d as rebase, r as rebaseBatchOver, a as rebaseOne, b as rebaseStepsThrough, t as transformRemoteAgainstPending } from './rebase-batch-DlerAcFN.js';
1
+ import { S as Step } from './versions-DOkOyh2J.js';
2
+ export { D as DeleteText, a as DocVersion, I as InsertText, R as ReplaceNode, b as SpliceChildren, c as apply, d as applyAll, g as getVersion, i as invert, e as invertAll, m as moveBlock, p as pushVersion, r as removeVersion, s as snapshotDoc } from './versions-DOkOyh2J.js';
3
+ import { E as ElementNode, P as Path, N as Node, a as Position, T as TextNode, M as Mark } from './types-BkHlmUFL.js';
4
+ export { D as Doc, S as Selection, f as footnoteKey, i as isAiCompose, b as isCallout, c as isElement, d as isFootnoteDef, e as isInlineAtom, g as isText } from './types-BkHlmUFL.js';
5
+ export { C as CommentAuthor, a as CommentMessage, b as CommentRenderState, c as CommentThread, d as Commit, H as History, S as SearchOpts, e as SuggestAuthor, f as SuggestHit, g as SuggestKind, T as TextMatch, W as WordCount, h as acceptSuggestion, i as amend, j as applyForeign, k as applyReplaceAll, l as commentIdsInDoc, m as commit, n as dropSuggestText, o as findText, p as init, q as isSuggestMark, r as listSuggestions, s as markSuggestRange, t as rangeForDelete, u as rangeIsSuggestInsert, v as redo, w as rejectSuggestion, x as replaceAll, y as replaceMatch, z as stripCommentMarks, A as stripSuggestMarks, B as suggestIdsInDoc, D as suggestMark, E as undo, F as wordCount } from './word-count-BPw9G2Bg.js';
6
+ export { B as Bias, m as makeBias, d as rebase, r as rebaseBatchOver, a as rebaseOne, b as rebaseStepsThrough, t as transformRemoteAgainstPending } from './rebase-batch-CSnv8FKp.js';
7
7
 
8
8
  interface TableShape {
9
9
  rows: number;
@@ -30,12 +30,14 @@ declare function caretCell(tablePath: Path, table: ElementNode, caret: Path): {
30
30
  r: number;
31
31
  c: number;
32
32
  } | null;
33
+ declare const DEFAULT_COL_WIDTH = 120;
33
34
  declare function makeTable(id: string, rows: number, cols: number): ElementNode;
34
35
  declare function cellText(table: ElementNode, r: number, c: number): string;
35
36
  declare function nextCell(table: ElementNode, r: number, c: number, dir: 1 | -1): {
36
37
  r: number;
37
38
  c: number;
38
39
  };
40
+ declare function isLastCell(table: ElementNode, r: number, c: number): boolean;
39
41
  declare function arrowCell(table: ElementNode, r: number, c: number, dir: 'up' | 'down' | 'left' | 'right'): {
40
42
  r: number;
41
43
  c: number;
@@ -47,7 +49,9 @@ declare function deleteCol(table: ElementNode, tablePath: Path, c: number, doc?:
47
49
  declare function hasSpan(table: ElementNode): boolean;
48
50
  declare function moveRow(table: ElementNode, tablePath: Path, from: number, to: number): Step;
49
51
  declare function moveCol(table: ElementNode, tablePath: Path, from: number, to: number): Step;
52
+ declare function cellRectTable(table: ElementNode, r1: number, c1: number, r2: number, c2: number): ElementNode;
50
53
  declare function tableColWidths(table: ElementNode): number[] | null;
54
+ declare function resolvedColWidths(table: ElementNode): number[];
51
55
  declare function setColWidths(table: ElementNode, tablePath: Path, widths: number[]): Step;
52
56
  declare function setAlign(table: ElementNode, tablePath: Path, col: number, value: 'left' | 'center' | 'right' | null): Step;
53
57
  declare function mergeCells(table: ElementNode, tablePath: Path, r1: number, c1: number, r2: number, c2: number): Step;
@@ -66,9 +70,14 @@ declare function setFreeze(table: ElementNode, tablePath: Path, freeze: {
66
70
  rows?: number;
67
71
  cols?: number;
68
72
  }): Step;
73
+ declare function setHeaderCol(table: ElementNode, tablePath: Path, on: boolean): Step;
69
74
  declare function deleteTableBlock(tablePath: Path, doc?: ElementNode): Step;
70
75
  declare function tableAt(doc: ElementNode, tablePath: Path): ElementNode | null;
71
76
  declare function checkTable(table: ElementNode): string[];
77
+ /** 名保留兼容;定义 = cellBlockTypes() */
78
+ declare const CELL_BLOCK_TYPES: readonly string[];
79
+ type CellBlockType = string;
80
+ declare function isCellBlockType(type: string): boolean;
72
81
  declare const tableSchema: {
73
82
  marks: string[];
74
83
  nodes: {
@@ -83,10 +92,68 @@ declare const tableSchema: {
83
92
  content: string[];
84
93
  inline: boolean;
85
94
  };
95
+ list: {
96
+ content: string[];
97
+ };
98
+ list_item: {
99
+ content: string[];
100
+ };
101
+ quote: {
102
+ content: string[];
103
+ };
104
+ callout: {
105
+ content: string[];
106
+ };
107
+ code: {
108
+ content: string[];
109
+ inline: boolean;
110
+ marks: never[];
111
+ };
112
+ image: {
113
+ content: never[];
114
+ atom: boolean;
115
+ };
116
+ embed: {
117
+ content: never[];
118
+ atom: boolean;
119
+ };
120
+ raw: {
121
+ content: string[];
122
+ inline: boolean;
123
+ marks: never[];
124
+ };
86
125
  };
87
126
  };
88
127
 
89
- declare function mdToDoc(md: string): ElementNode;
128
+ /**
129
+ * 公式怎么写进 Markdown。
130
+ * - `'html'`(默认):`<span data-math data-latex=…>$x$</span>`,`$x$` 不当公式读(README 里的 `$HOME/$USER` 还是字)。
131
+ * - `'dollar'`:读写 `$x$`、`$$x$$`(pandoc 的规则,见 md-math.ts),Typora、Obsidian、GitHub 都读得懂。
132
+ * 旧的 span 照读;没改过的块逐字节不变,改过的块里的公式写成 `$`;写不成 `$` 的(公式里有空行、开头是空格)仍写 span。
133
+ * 这是这个页面的文件格式,不是某一个编辑器的:在打开任何文档之前设一次。
134
+ */
135
+ declare function setMathSyntax(syntax: 'html' | 'dollar'): void;
136
+ interface MdToDocAsyncOptions {
137
+ chunkBytes?: number;
138
+ /** 每一片最多占主线程这么久(毫秒,默认 6)。片与片之间把线程还给浏览器,输入、滚动、绘制不被 3 秒的解析冻住。 */
139
+ budgetMs?: number;
140
+ /** 解出至少这么多个块后,调用一次 onHead,给一份「文档开头」的预览树(默认 200 块,约一屏多)。 */
141
+ headBlocks?: number;
142
+ /**
143
+ * 开头预览。**只能看,不能编辑、不能存盘**:它只是整篇的前缀,结尾处的 callout 若还没等到 `</div>` 会按普通块降级,
144
+ * 且它没有后面的块——拿它当文档存回去就丢了全文。真正的文档是 promise 的结果。
145
+ * 预览的块 id 与最终文档里同位置的块相同(都是 b0、b1…),所以换成完整文档时块能原地对上。
146
+ */
147
+ onHead?: (head: ElementNode) => void;
148
+ signal?: AbortSignal;
149
+ }
150
+ /**
151
+ * mdToDoc 的非阻塞版:同一份解析代码(生成器),每解完一块看一眼用掉了多少时间,超了预算就把主线程还出去再继续。
152
+ * 结果与 mdToDoc(md) 逐字节相同(同一个生成器,只是中间多了让出)。总耗时比同步版略长(让出的间隙),但没有一次超过预算的阻塞。
153
+ * 块的粒度见 md-chunk.ts:单块一般 1–3 ms,个别切不开的大表/大代码块更长,那一块里没法再让。
154
+ */
155
+ declare function mdToDocAsync(md: string, opts?: MdToDocAsyncOptions): Promise<ElementNode>;
156
+ declare function mdToDoc(md: string, chunkBytes?: number): ElementNode;
90
157
  declare function htmlToBlocks(html: string): ElementNode[] | null;
91
158
  declare function isRichHtmlBlocks(blocks: ElementNode[]): boolean;
92
159
  declare function isPlainTransportHtml(blocks: ElementNode[]): boolean;
@@ -106,6 +173,12 @@ interface Resolved {
106
173
  }
107
174
  declare function resolve(doc: ElementNode, path: Path): Resolved;
108
175
  declare function firstLeafPath(block: ElementNode): Path;
176
+ /**
177
+ * 元素内 child 缝 at → 最近可落文本叶。
178
+ * 空 atom(image/embed/hard_break/math)从缝上跳过,吸到后侧文本首;
179
+ * mention 不跳,归前叶尾。再无文本才扫另一侧。
180
+ */
181
+ declare function gapToTextPath(parent: ElementNode, at: number, prefix?: Path): Path;
109
182
  declare function normalizeToLeaf(doc: ElementNode, path: Path): Path;
110
183
  declare function lastLeafEnd(block: ElementNode): Path;
111
184
  declare function nodeAt(doc: ElementNode, path: Path): Node;
@@ -177,6 +250,24 @@ declare function resolveTxAfter<S extends {
177
250
  }>(before: S | null | undefined, after: S | null | undefined, steps: readonly Step[], gaps?: readonly Step[]): S | undefined;
178
251
  declare function normalizePosition(doc: ElementNode, pos: Position): Position;
179
252
 
253
+ /**
254
+ * Content spaces — composable finite block sets (runtime + domain share).
255
+ *
256
+ * bodyBlocks = doc.content
257
+ * cellBlocks = bodyBlocks − { heading, table, ai }
258
+ *
259
+ * Definition is set algebra, not a second hand-written list.
260
+ */
261
+
262
+ /** Types in body but not admitted as table-cell children. */
263
+ declare const CELL_EXCLUDED_FROM_BODY: readonly ["heading", "table"];
264
+ /** Top-level block types under doc (paste/transform palette). */
265
+ declare function bodyBlockTypes(schema?: Schema): readonly string[];
266
+ /** Table-cell admit set = body − CELL_EXCLUDED_FROM_BODY. */
267
+ declare function cellBlockTypes(schema?: Schema): readonly string[];
268
+ declare function isBodyBlockType(type: string, schema?: Schema): boolean;
269
+ declare function isCellBlockTypeInSpace(type: string, schema?: Schema): boolean;
270
+
180
271
  interface DocStats {
181
272
  chars: number;
182
273
  words: number;
@@ -184,6 +275,15 @@ interface DocStats {
184
275
  }
185
276
  declare function docStats(doc: ElementNode): DocStats;
186
277
 
278
+ declare const FRONT_MATTER = "frontmatter";
279
+ declare function isFrontMatter(n: Node | null | undefined): boolean;
280
+ /**
281
+ * md 开头是 front matter 时,返回闭合栅栏文字的结束偏移(不含其后的空白和换行);不是则 -1。
282
+ * 判据:首行只有 `---`(行尾空白不算);往下第一条只有 `---` / `...` 的行闭合;两条栅栏之间至少有一行非空白
283
+ * (`---\n---` 是两条分隔线,不是空的 front matter)。CRLF 照常认。
284
+ */
285
+ declare function frontMatterEnd(md: string): number;
286
+
187
287
  interface TocEntry {
188
288
  level: number;
189
289
  text: string;
@@ -192,4 +292,23 @@ interface TocEntry {
192
292
  }
193
293
  declare function outline(doc: ElementNode): TocEntry[];
194
294
 
195
- export { type DocStats, ElementNode, type Grid, type IdIndex, Node, type NodeChange, type NodeSpec, Path, Position, type Resolved, type Schema, Step, type TableShape, type TocEntry, type Violation, appendText, arrowCell, basicSchema, buildGrid, buildIdIndex, calloutToHtml, caretCell, cellCaret, cellText, checkSchema, checkTable, clearCells, colspanOf, deleteCol, deleteRow, deleteTableBlock, diffById, docStats, docToMd, embedHtml, firstLeafPath, firstViolation, hasSpan, htmlToBlocks, insertAfter, insertCol, insertRow, invariants, isPlainTransportHtml, isRichHtmlBlocks, lastLeafEnd, makeTable, mapPosition, mapSelection, mapSelectionThrough, mdStructureBeatsTransport, mdToDoc, mergeCells, moveCol, moveRow, nextCell, nodeAt, normalizePosition, normalizeToLeaf, outline, pathOfId, preferMarkdownPaste, replaceAt, resolve, resolveTxAfter, rewriteNode, rowspanOf, setAlign, setCellStyle, setColWidths, setFreeze, spliceAt, splitCell, tableAt, tableColWidths, tableHasExtras, tableSchema, tableShape, tableToHtml, validate, validateAll };
295
+ declare function markIdsInDoc(doc: ElementNode, name: string): Set<string>;
296
+ declare function mapLeafBlocks(doc: ElementNode, fn: (node: ElementNode, path: Path) => ElementNode | null): Step[];
297
+ declare function stripMarks(doc: ElementNode, pred: (m: Mark) => boolean): Step[];
298
+ declare function dropMarkedLeaves(doc: ElementNode, pred: (leaf: TextNode) => boolean): Step[];
299
+
300
+ interface FootnoteIndex {
301
+ /** 引用首次出现的顺序(规范化键);编号 = 下标 + 1。 */
302
+ order: string[];
303
+ /** 键 → 定义块(同一键多个定义时取第一个,同 CommonMark 引用定义)。 */
304
+ defs: Map<string, ElementNode>;
305
+ /** 键 → 引用次数。 */
306
+ refs: Map<string, number>;
307
+ }
308
+ declare function footnoteIndex(doc: ElementNode): FootnoteIndex;
309
+ /** 一个块的纯文本(块间换行),悬停卡显示用。 */
310
+ declare function footnoteText(def: ElementNode): string;
311
+ /** 文档里有没有任何脚注(引用或定义):没有就不必为编号付任何代价。 */
312
+ declare function hasFootnotes(doc: ElementNode): boolean;
313
+
314
+ export { CELL_BLOCK_TYPES, CELL_EXCLUDED_FROM_BODY, type CellBlockType, DEFAULT_COL_WIDTH, type DocStats, ElementNode, FRONT_MATTER, type FootnoteIndex, type Grid, type IdIndex, Mark, type MdToDocAsyncOptions, Node, type NodeChange, type NodeSpec, Path, Position, type Resolved, type Schema, Step, type TableShape, TextNode, type TocEntry, type Violation, appendText, arrowCell, basicSchema, bodyBlockTypes, buildGrid, buildIdIndex, calloutToHtml, caretCell, cellBlockTypes, cellCaret, cellRectTable, cellText, checkSchema, checkTable, clearCells, colspanOf, deleteCol, deleteRow, deleteTableBlock, diffById, docStats, docToMd, dropMarkedLeaves, embedHtml, firstLeafPath, firstViolation, footnoteIndex, footnoteText, frontMatterEnd, gapToTextPath, hasFootnotes, hasSpan, htmlToBlocks, insertAfter, insertCol, insertRow, invariants, isBodyBlockType, isCellBlockType, isCellBlockTypeInSpace, isFrontMatter, isLastCell, isPlainTransportHtml, isRichHtmlBlocks, lastLeafEnd, makeTable, mapLeafBlocks, mapPosition, mapSelection, mapSelectionThrough, markIdsInDoc, mdStructureBeatsTransport, mdToDoc, mdToDocAsync, mergeCells, moveCol, moveRow, nextCell, nodeAt, normalizePosition, normalizeToLeaf, outline, pathOfId, preferMarkdownPaste, replaceAt, resolve, resolveTxAfter, resolvedColWidths, rewriteNode, rowspanOf, setAlign, setCellStyle, setColWidths, setFreeze, setHeaderCol, setMathSyntax, spliceAt, splitCell, stripMarks, tableAt, tableColWidths, tableHasExtras, tableSchema, tableShape, tableToHtml, validate, validateAll };
package/dist/index.js CHANGED
@@ -5,14 +5,20 @@ import {
5
5
  applyReplaceAll,
6
6
  commentIdsInDoc,
7
7
  commit,
8
+ dropMarkedLeaves,
8
9
  dropSuggestText,
9
10
  findText,
10
11
  firstViolation,
12
+ footnoteIndex,
13
+ footnoteText,
11
14
  getVersion,
15
+ hasFootnotes,
12
16
  init,
13
17
  invariants,
14
18
  isSuggestMark,
15
19
  listSuggestions,
20
+ mapLeafBlocks,
21
+ markIdsInDoc,
16
22
  markSuggestRange,
17
23
  outline,
18
24
  pushVersion,
@@ -25,22 +31,29 @@ import {
25
31
  replaceMatch,
26
32
  snapshotDoc,
27
33
  stripCommentMarks,
34
+ stripMarks,
28
35
  stripSuggestMarks,
29
36
  suggestIdsInDoc,
30
37
  suggestMark,
31
- undo
32
- } from "./chunk-CGYCJORO.js";
38
+ undo,
39
+ wordCount
40
+ } from "./chunk-YLVSMDIO.js";
33
41
  import {
42
+ CELL_BLOCK_TYPES,
43
+ CELL_EXCLUDED_FROM_BODY,
44
+ DEFAULT_COL_WIDTH,
45
+ FRONT_MATTER,
34
46
  appendText,
35
- apply,
36
- applyAll,
37
47
  arrowCell,
38
48
  basicSchema,
49
+ bodyBlockTypes,
39
50
  buildGrid,
40
51
  buildIdIndex,
41
52
  calloutToHtml,
42
53
  caretCell,
54
+ cellBlockTypes,
43
55
  cellCaret,
56
+ cellRectTable,
44
57
  cellText,
45
58
  checkSchema,
46
59
  checkTable,
@@ -52,38 +65,38 @@ import {
52
65
  diffById,
53
66
  docToMd,
54
67
  embedHtml,
55
- firstLeafPath,
68
+ frontMatterEnd,
56
69
  hasSpan,
57
70
  htmlToBlocks,
58
71
  insertAfter,
59
72
  insertCol,
60
73
  insertRow,
61
- invert,
62
- invertAll,
74
+ isBodyBlockType,
75
+ isCellBlockType,
76
+ isCellBlockTypeInSpace,
77
+ isFrontMatter,
78
+ isLastCell,
63
79
  isPlainTransportHtml,
64
80
  isRichHtmlBlocks,
65
- lastLeafEnd,
66
81
  makeTable,
67
82
  mdStructureBeatsTransport,
68
83
  mdToDoc,
84
+ mdToDocAsync,
69
85
  mergeCells,
70
- moveBlock,
71
86
  moveCol,
72
87
  moveRow,
73
88
  nextCell,
74
- nodeAt,
75
- normalizeToLeaf,
76
89
  pathOfId,
77
90
  preferMarkdownPaste,
78
- replaceAt,
79
- resolve,
91
+ resolvedColWidths,
80
92
  rewriteNode,
81
93
  rowspanOf,
82
94
  setAlign,
83
95
  setCellStyle,
84
96
  setColWidths,
85
97
  setFreeze,
86
- spliceAt,
98
+ setHeaderCol,
99
+ setMathSyntax,
87
100
  splitCell,
88
101
  tableAt,
89
102
  tableColWidths,
@@ -93,7 +106,7 @@ import {
93
106
  tableToHtml,
94
107
  validate,
95
108
  validateAll
96
- } from "./chunk-SNFF6X45.js";
109
+ } from "./chunk-QO7JEZDB.js";
97
110
  import {
98
111
  makeBias,
99
112
  mapPosition,
@@ -106,12 +119,31 @@ import {
106
119
  rebaseStepsThrough,
107
120
  resolveTxAfter,
108
121
  transformRemoteAgainstPending
109
- } from "./chunk-VSBIMMI7.js";
122
+ } from "./chunk-EFYT2223.js";
110
123
  import {
124
+ apply,
125
+ applyAll,
126
+ firstLeafPath,
127
+ gapToTextPath,
128
+ invert,
129
+ invertAll,
130
+ lastLeafEnd,
131
+ moveBlock,
132
+ nodeAt,
133
+ normalizeToLeaf,
134
+ replaceAt,
135
+ resolve,
136
+ spliceAt
137
+ } from "./chunk-ZL6WT6OY.js";
138
+ import {
139
+ footnoteKey,
140
+ isAiCompose,
141
+ isCallout,
111
142
  isElement,
143
+ isFootnoteDef,
112
144
  isInlineAtom,
113
145
  isText
114
- } from "./chunk-EJSFZHGT.js";
146
+ } from "./chunk-WSJUXPAG.js";
115
147
 
116
148
  // src/tree/stats.ts
117
149
  function rawText(node) {
@@ -142,6 +174,10 @@ function docStats(doc) {
142
174
  return { chars: [...rawText(doc)].length, words: countWords(spacedText(doc)), blocks: doc.children.length };
143
175
  }
144
176
  export {
177
+ CELL_BLOCK_TYPES,
178
+ CELL_EXCLUDED_FROM_BODY,
179
+ DEFAULT_COL_WIDTH,
180
+ FRONT_MATTER,
145
181
  acceptSuggestion,
146
182
  amend,
147
183
  appendText,
@@ -151,11 +187,14 @@ export {
151
187
  applyReplaceAll,
152
188
  arrowCell,
153
189
  basicSchema,
190
+ bodyBlockTypes,
154
191
  buildGrid,
155
192
  buildIdIndex,
156
193
  calloutToHtml,
157
194
  caretCell,
195
+ cellBlockTypes,
158
196
  cellCaret,
197
+ cellRectTable,
159
198
  cellText,
160
199
  checkSchema,
161
200
  checkTable,
@@ -169,12 +208,19 @@ export {
169
208
  diffById,
170
209
  docStats,
171
210
  docToMd,
211
+ dropMarkedLeaves,
172
212
  dropSuggestText,
173
213
  embedHtml,
174
214
  findText,
175
215
  firstLeafPath,
176
216
  firstViolation,
217
+ footnoteIndex,
218
+ footnoteKey,
219
+ footnoteText,
220
+ frontMatterEnd,
221
+ gapToTextPath,
177
222
  getVersion,
223
+ hasFootnotes,
178
224
  hasSpan,
179
225
  htmlToBlocks,
180
226
  init,
@@ -184,8 +230,16 @@ export {
184
230
  invariants,
185
231
  invert,
186
232
  invertAll,
233
+ isAiCompose,
234
+ isBodyBlockType,
235
+ isCallout,
236
+ isCellBlockType,
237
+ isCellBlockTypeInSpace,
187
238
  isElement,
239
+ isFootnoteDef,
240
+ isFrontMatter,
188
241
  isInlineAtom,
242
+ isLastCell,
189
243
  isPlainTransportHtml,
190
244
  isRichHtmlBlocks,
191
245
  isSuggestMark,
@@ -194,12 +248,15 @@ export {
194
248
  listSuggestions,
195
249
  makeBias,
196
250
  makeTable,
251
+ mapLeafBlocks,
197
252
  mapPosition,
198
253
  mapSelection,
199
254
  mapSelectionThrough,
255
+ markIdsInDoc,
200
256
  markSuggestRange,
201
257
  mdStructureBeatsTransport,
202
258
  mdToDoc,
259
+ mdToDocAsync,
203
260
  mergeCells,
204
261
  moveBlock,
205
262
  moveCol,
@@ -226,16 +283,20 @@ export {
226
283
  replaceMatch,
227
284
  resolve,
228
285
  resolveTxAfter,
286
+ resolvedColWidths,
229
287
  rewriteNode,
230
288
  rowspanOf,
231
289
  setAlign,
232
290
  setCellStyle,
233
291
  setColWidths,
234
292
  setFreeze,
293
+ setHeaderCol,
294
+ setMathSyntax,
235
295
  snapshotDoc,
236
296
  spliceAt,
237
297
  splitCell,
238
298
  stripCommentMarks,
299
+ stripMarks,
239
300
  stripSuggestMarks,
240
301
  suggestIdsInDoc,
241
302
  suggestMark,
@@ -248,5 +309,6 @@ export {
248
309
  transformRemoteAgainstPending,
249
310
  undo,
250
311
  validate,
251
- validateAll
312
+ validateAll,
313
+ wordCount
252
314
  };