markloom 0.5.1 → 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 (73) hide show
  1. package/PACKAGES.md +26 -0
  2. package/README.md +20 -2
  3. package/collab.md +60 -13
  4. package/dist/ai/index.cjs +5 -4
  5. package/dist/ai/index.d.cts +5 -4
  6. package/dist/ai/index.d.ts +5 -4
  7. package/dist/ai/index.js +4 -3
  8. package/dist/ai/theme.css +66 -102
  9. package/dist/{chunk-ZMTLSFLO.js → chunk-4Q7PAR2T.js} +5746 -1341
  10. package/dist/chunk-75EJ4ARB.cjs +642 -0
  11. package/dist/{chunk-JS527FDV.cjs → chunk-BMPCVT3B.cjs} +47 -39
  12. package/dist/{chunk-RLTHVQNQ.js → chunk-EFYT2223.js} +47 -39
  13. package/dist/chunk-HXABDVLZ.cjs +297 -0
  14. package/dist/{chunk-YIFOGP2D.cjs → chunk-I2LDEVLA.cjs} +499 -102
  15. package/dist/chunk-MQLRZQZL.js +642 -0
  16. package/dist/chunk-OVHASRID.cjs +4279 -0
  17. package/dist/chunk-PCSVBPOR.cjs +40 -0
  18. package/dist/{chunk-FCH7LZFI.js → chunk-PSAXWBNM.js} +450 -53
  19. package/dist/chunk-PZRWTLLB.cjs +858 -0
  20. package/dist/chunk-QO7JEZDB.js +4279 -0
  21. package/dist/chunk-WSJUXPAG.js +40 -0
  22. package/dist/{chunk-VXM7Q6P5.cjs → chunk-Y4IXQFWL.cjs} +6026 -1621
  23. package/dist/chunk-YLVSMDIO.js +858 -0
  24. package/dist/chunk-ZL6WT6OY.js +297 -0
  25. package/dist/client-BvvyHjhh.d.ts +250 -0
  26. package/dist/client-Ciy7Fa_k.d.cts +250 -0
  27. package/dist/collab/index.cjs +17 -4
  28. package/dist/collab/index.d.cts +18 -7
  29. package/dist/collab/index.d.ts +18 -7
  30. package/dist/collab/index.js +19 -6
  31. package/dist/{controller-DQITsFhy.d.cts → controller-CHznEhAR.d.cts} +277 -26
  32. package/dist/{controller-BNuuUM3E.d.ts → controller-DLqI8_jm.d.ts} +277 -26
  33. package/dist/index.cjs +119 -7
  34. package/dist/index.d.cts +138 -6
  35. package/dist/index.d.ts +138 -6
  36. package/dist/index.js +130 -18
  37. package/dist/io/index.cjs +1412 -0
  38. package/dist/io/index.d.cts +33 -0
  39. package/dist/io/index.d.ts +33 -0
  40. package/dist/io/index.js +1412 -0
  41. package/dist/react/index.cjs +9 -8
  42. package/dist/react/index.d.cts +5 -4
  43. package/dist/react/index.d.ts +5 -4
  44. package/dist/react/index.js +8 -7
  45. package/dist/{rebase-batch-8rL_aXEE.d.ts → rebase-batch-CSnv8FKp.d.ts} +11 -9
  46. package/dist/{rebase-batch-bYnBJpRO.d.cts → rebase-batch-DO1ygkx9.d.cts} +11 -9
  47. package/dist/types-BkHlmUFL.d.cts +34 -0
  48. package/dist/types-BkHlmUFL.d.ts +34 -0
  49. package/dist/versions-DNFf8zVz.d.cts +51 -0
  50. package/dist/versions-DOkOyh2J.d.ts +51 -0
  51. package/dist/view/index.cjs +259 -17
  52. package/dist/view/index.d.cts +277 -12
  53. package/dist/view/index.d.ts +277 -12
  54. package/dist/view/index.js +256 -14
  55. package/dist/view/theme.css +2093 -1577
  56. package/dist/word-count-BPw9G2Bg.d.ts +130 -0
  57. package/dist/word-count-DNLn1h_t.d.cts +130 -0
  58. package/io.md +38 -0
  59. package/package.json +25 -4
  60. package/dist/chunk-4JSJAHTB.js +0 -255
  61. package/dist/chunk-4TMHVNL6.cjs +0 -2297
  62. package/dist/chunk-ALZ3A5CS.cjs +0 -255
  63. package/dist/chunk-GQ2HHRGI.cjs +0 -16
  64. package/dist/chunk-LA5SBCGQ.js +0 -16
  65. package/dist/chunk-LEYAQNJA.js +0 -220
  66. package/dist/chunk-MFYF2A6U.js +0 -2297
  67. package/dist/chunk-YXQDCW4Y.cjs +0 -220
  68. package/dist/client-6KiH4kGK.d.ts +0 -144
  69. package/dist/client-ZRZj2nkq.d.cts +0 -144
  70. package/dist/comments-DlExS6f-.d.cts +0 -43
  71. package/dist/comments-PhnR7Gkn.d.ts +0 -43
  72. package/dist/step-BrvHIK7O.d.cts +0 -65
  73. package/dist/step-BrvHIK7O.d.ts +0 -65
@@ -0,0 +1,130 @@
1
+ import { E as ElementNode, S as Selection, P as Path, M as Mark } from './types-BkHlmUFL.js';
2
+ import { S as Step } from './versions-DOkOyh2J.js';
3
+
4
+ interface Commit {
5
+ steps: Step[];
6
+ inverse: Step[];
7
+ before?: Selection;
8
+ after?: Selection;
9
+ }
10
+ interface History {
11
+ doc: ElementNode;
12
+ past: Commit[];
13
+ future: Commit[];
14
+ validate?: (doc: ElementNode) => string | null;
15
+ }
16
+ declare function init(doc: ElementNode, validate?: (doc: ElementNode) => string | null): History;
17
+ declare function commit(h: History, steps: Step[], before?: Selection | null, after?: Selection | null): History;
18
+ /**
19
+ * 远端/他人 op:写入 doc,不入 past/future;并把本端 undo/redo 栈穿过这批 steps(OT)。
20
+ * thisSite / foreignSite 给 makeBias;无 site 时用 0/1 固定偏序。
21
+ */
22
+ declare function applyForeign(h: History, steps: Step[], thisSite?: number, foreignSite?: number): History;
23
+ declare function amend(h: History, more: Step[], after?: Selection | null, before?: Selection | null): History;
24
+ declare function undo(h: History): History;
25
+ declare function redo(h: History): History;
26
+
27
+ interface CommentAuthor {
28
+ id: string;
29
+ name: string;
30
+ avatar?: string;
31
+ }
32
+ interface CommentMessage {
33
+ id: string;
34
+ author: CommentAuthor;
35
+ body: string;
36
+ createdAt: number;
37
+ }
38
+ interface CommentThread {
39
+ id: string;
40
+ resolved: boolean;
41
+ quote?: string;
42
+ messages: CommentMessage[];
43
+ }
44
+ interface CommentRenderState {
45
+ resolved: Set<string>;
46
+ activeId: string | null;
47
+ }
48
+ declare function commentIdsInDoc(doc: ElementNode): Set<string>;
49
+ declare function stripCommentMarks(doc: ElementNode, id: string): Step[];
50
+
51
+ interface TextMatch {
52
+ path: Path;
53
+ offset: number;
54
+ length: number;
55
+ }
56
+ interface SearchOpts {
57
+ caseSensitive?: boolean;
58
+ /** 跳过 type∈ 的块子树(默认跳 code——代码块内替换易误伤) */
59
+ skipTypes?: string[];
60
+ }
61
+ declare function findText(doc: ElementNode, query: string, opts?: SearchOpts): TextMatch[];
62
+ /** 单处替换 → 删 + 可选插 */
63
+ declare function replaceMatch(match: TextMatch, replacement: string): Step[];
64
+ /**
65
+ * 全部替换:按叶整段改写(一次 replaceNode / 叶),count = 命中次数。
66
+ * 步之间互不依赖 offset,任意序 apply 皆可。
67
+ */
68
+ declare function replaceAll(doc: ElementNode, query: string, replacement: string, opts?: SearchOpts): {
69
+ steps: Step[];
70
+ count: number;
71
+ };
72
+ declare function applyReplaceAll(doc: ElementNode, query: string, replacement: string, opts?: SearchOpts): ElementNode;
73
+
74
+ type SuggestKind = 'insert' | 'delete';
75
+ type SuggestAuthor = {
76
+ id: string;
77
+ name: string;
78
+ };
79
+ type SuggestHit = {
80
+ id: string;
81
+ kind: SuggestKind;
82
+ quote: string;
83
+ authorId?: string;
84
+ authorName?: string;
85
+ };
86
+ declare function suggestMark(id: string, kind: SuggestKind, author?: SuggestAuthor): Mark;
87
+ declare function isSuggestMark(m: Mark, id?: string): boolean;
88
+ declare function suggestIdsInDoc(doc: ElementNode): Set<string>;
89
+ /** 文档序枚举建议(同一 id 合并 quote)。 */
90
+ declare function listSuggestions(doc: ElementNode): SuggestHit[];
91
+ declare function stripSuggestMarks(doc: ElementNode, id: string): Step[];
92
+ declare function dropSuggestText(doc: ElementNode, id: string): Step[];
93
+ /**
94
+ * 接受建议:
95
+ * · insert → 剥 mark,正文留下
96
+ * · delete → 删掉标删文本
97
+ */
98
+ declare function acceptSuggestion(doc: ElementNode, id: string): Step[];
99
+ /**
100
+ * 拒绝建议:
101
+ * · insert → 删掉建议插入
102
+ * · delete → 剥 mark,原文留下
103
+ */
104
+ declare function rejectSuggestion(doc: ElementNode, id: string): Step[];
105
+ /**
106
+ * 删除意图对应的选区:非塌缩原样;塌缩则扩 1 字符(同叶内)。
107
+ * 叶边界/非文本 → null(调用方退回真实 delete,避免挡并块)。
108
+ */
109
+ declare function rangeForDelete(doc: ElementNode, sel: Selection, dir: 'backward' | 'forward'): Selection | null;
110
+ /** 选区文本是否全部已是 suggest insert(跟踪删时改为真删,撤自己的插入)。 */
111
+ declare function rangeIsSuggestInsert(doc: ElementNode, sel: Selection): boolean;
112
+ /**
113
+ * 在选区上强制套 suggest mark(insert 或 delete)。
114
+ * 塌缩选区 → 空 steps。
115
+ */
116
+ declare function markSuggestRange(doc: ElementNode, sel: Selection, kind: SuggestKind, id: string, author?: SuggestAuthor): Step[];
117
+
118
+ interface WordCount {
119
+ /** 词数:CJK 一字一词,其余按词。 */
120
+ words: number;
121
+ /** 字符数,含空格,不含换行(码点计,emoji 算 1)。 */
122
+ chars: number;
123
+ /** 字符数,不含任何空白。 */
124
+ charsNoSpace: number;
125
+ /** 段落数:有字的 paragraph / heading 块(嵌在列表、引用里的也算)。 */
126
+ paragraphs: number;
127
+ }
128
+ declare function wordCount(doc: ElementNode): WordCount;
129
+
130
+ export { stripSuggestMarks as A, suggestIdsInDoc as B, type CommentAuthor as C, suggestMark as D, undo as E, wordCount as F, type History as H, type SearchOpts as S, type TextMatch as T, type WordCount as W, type CommentMessage as a, type CommentRenderState as b, type CommentThread as c, type Commit as d, type SuggestAuthor as e, type SuggestHit as f, type SuggestKind as g, acceptSuggestion as h, amend as i, applyForeign as j, applyReplaceAll as k, commentIdsInDoc as l, commit as m, dropSuggestText as n, findText as o, init as p, isSuggestMark as q, listSuggestions as r, markSuggestRange as s, rangeForDelete as t, rangeIsSuggestInsert as u, redo as v, rejectSuggestion as w, replaceAll as x, replaceMatch as y, stripCommentMarks as z };
@@ -0,0 +1,130 @@
1
+ import { E as ElementNode, S as Selection, P as Path, M as Mark } from './types-BkHlmUFL.cjs';
2
+ import { S as Step } from './versions-DNFf8zVz.cjs';
3
+
4
+ interface Commit {
5
+ steps: Step[];
6
+ inverse: Step[];
7
+ before?: Selection;
8
+ after?: Selection;
9
+ }
10
+ interface History {
11
+ doc: ElementNode;
12
+ past: Commit[];
13
+ future: Commit[];
14
+ validate?: (doc: ElementNode) => string | null;
15
+ }
16
+ declare function init(doc: ElementNode, validate?: (doc: ElementNode) => string | null): History;
17
+ declare function commit(h: History, steps: Step[], before?: Selection | null, after?: Selection | null): History;
18
+ /**
19
+ * 远端/他人 op:写入 doc,不入 past/future;并把本端 undo/redo 栈穿过这批 steps(OT)。
20
+ * thisSite / foreignSite 给 makeBias;无 site 时用 0/1 固定偏序。
21
+ */
22
+ declare function applyForeign(h: History, steps: Step[], thisSite?: number, foreignSite?: number): History;
23
+ declare function amend(h: History, more: Step[], after?: Selection | null, before?: Selection | null): History;
24
+ declare function undo(h: History): History;
25
+ declare function redo(h: History): History;
26
+
27
+ interface CommentAuthor {
28
+ id: string;
29
+ name: string;
30
+ avatar?: string;
31
+ }
32
+ interface CommentMessage {
33
+ id: string;
34
+ author: CommentAuthor;
35
+ body: string;
36
+ createdAt: number;
37
+ }
38
+ interface CommentThread {
39
+ id: string;
40
+ resolved: boolean;
41
+ quote?: string;
42
+ messages: CommentMessage[];
43
+ }
44
+ interface CommentRenderState {
45
+ resolved: Set<string>;
46
+ activeId: string | null;
47
+ }
48
+ declare function commentIdsInDoc(doc: ElementNode): Set<string>;
49
+ declare function stripCommentMarks(doc: ElementNode, id: string): Step[];
50
+
51
+ interface TextMatch {
52
+ path: Path;
53
+ offset: number;
54
+ length: number;
55
+ }
56
+ interface SearchOpts {
57
+ caseSensitive?: boolean;
58
+ /** 跳过 type∈ 的块子树(默认跳 code——代码块内替换易误伤) */
59
+ skipTypes?: string[];
60
+ }
61
+ declare function findText(doc: ElementNode, query: string, opts?: SearchOpts): TextMatch[];
62
+ /** 单处替换 → 删 + 可选插 */
63
+ declare function replaceMatch(match: TextMatch, replacement: string): Step[];
64
+ /**
65
+ * 全部替换:按叶整段改写(一次 replaceNode / 叶),count = 命中次数。
66
+ * 步之间互不依赖 offset,任意序 apply 皆可。
67
+ */
68
+ declare function replaceAll(doc: ElementNode, query: string, replacement: string, opts?: SearchOpts): {
69
+ steps: Step[];
70
+ count: number;
71
+ };
72
+ declare function applyReplaceAll(doc: ElementNode, query: string, replacement: string, opts?: SearchOpts): ElementNode;
73
+
74
+ type SuggestKind = 'insert' | 'delete';
75
+ type SuggestAuthor = {
76
+ id: string;
77
+ name: string;
78
+ };
79
+ type SuggestHit = {
80
+ id: string;
81
+ kind: SuggestKind;
82
+ quote: string;
83
+ authorId?: string;
84
+ authorName?: string;
85
+ };
86
+ declare function suggestMark(id: string, kind: SuggestKind, author?: SuggestAuthor): Mark;
87
+ declare function isSuggestMark(m: Mark, id?: string): boolean;
88
+ declare function suggestIdsInDoc(doc: ElementNode): Set<string>;
89
+ /** 文档序枚举建议(同一 id 合并 quote)。 */
90
+ declare function listSuggestions(doc: ElementNode): SuggestHit[];
91
+ declare function stripSuggestMarks(doc: ElementNode, id: string): Step[];
92
+ declare function dropSuggestText(doc: ElementNode, id: string): Step[];
93
+ /**
94
+ * 接受建议:
95
+ * · insert → 剥 mark,正文留下
96
+ * · delete → 删掉标删文本
97
+ */
98
+ declare function acceptSuggestion(doc: ElementNode, id: string): Step[];
99
+ /**
100
+ * 拒绝建议:
101
+ * · insert → 删掉建议插入
102
+ * · delete → 剥 mark,原文留下
103
+ */
104
+ declare function rejectSuggestion(doc: ElementNode, id: string): Step[];
105
+ /**
106
+ * 删除意图对应的选区:非塌缩原样;塌缩则扩 1 字符(同叶内)。
107
+ * 叶边界/非文本 → null(调用方退回真实 delete,避免挡并块)。
108
+ */
109
+ declare function rangeForDelete(doc: ElementNode, sel: Selection, dir: 'backward' | 'forward'): Selection | null;
110
+ /** 选区文本是否全部已是 suggest insert(跟踪删时改为真删,撤自己的插入)。 */
111
+ declare function rangeIsSuggestInsert(doc: ElementNode, sel: Selection): boolean;
112
+ /**
113
+ * 在选区上强制套 suggest mark(insert 或 delete)。
114
+ * 塌缩选区 → 空 steps。
115
+ */
116
+ declare function markSuggestRange(doc: ElementNode, sel: Selection, kind: SuggestKind, id: string, author?: SuggestAuthor): Step[];
117
+
118
+ interface WordCount {
119
+ /** 词数:CJK 一字一词,其余按词。 */
120
+ words: number;
121
+ /** 字符数,含空格,不含换行(码点计,emoji 算 1)。 */
122
+ chars: number;
123
+ /** 字符数,不含任何空白。 */
124
+ charsNoSpace: number;
125
+ /** 段落数:有字的 paragraph / heading 块(嵌在列表、引用里的也算)。 */
126
+ paragraphs: number;
127
+ }
128
+ declare function wordCount(doc: ElementNode): WordCount;
129
+
130
+ export { stripSuggestMarks as A, suggestIdsInDoc as B, type CommentAuthor as C, suggestMark as D, undo as E, wordCount as F, type History as H, type SearchOpts as S, type TextMatch as T, type WordCount as W, type CommentMessage as a, type CommentRenderState as b, type CommentThread as c, type Commit as d, type SuggestAuthor as e, type SuggestHit as f, type SuggestKind as g, acceptSuggestion as h, amend as i, applyForeign as j, applyReplaceAll as k, commentIdsInDoc as l, commit as m, dropSuggestText as n, findText as o, init as p, isSuggestMark as q, listSuggestions as r, markSuggestRange as s, rangeForDelete as t, rangeIsSuggestInsert as u, redo as v, rejectSuggestion as w, replaceAll as x, replaceMatch as y, stripCommentMarks as z };
package/io.md ADDED
@@ -0,0 +1,38 @@
1
+ # DOCX I/O (`markloom/io`)
2
+
3
+ O(1): import the entrypoint. Not in the default editor bundle.
4
+
5
+ ```bash
6
+ npm i markloom
7
+ ```
8
+
9
+ ```ts
10
+ import { docToDocx, docToDocxBlob, docToDocxAsync, docxToDoc } from 'markloom/io'
11
+
12
+ // Export (sync: embeds data: images only)
13
+ const bytes = docToDocx(doc)
14
+ const blob = docToDocxBlob(doc) // browser download
15
+
16
+ // Export with remote images
17
+ const bytes2 = await docToDocxAsync(doc)
18
+ // or: await docToDocxAsync(doc, { resolveImage: async url => … })
19
+
20
+ // Import (store + deflate ZIP; Word-exported packages OK)
21
+ const doc2 = docxToDoc(await file.arrayBuffer())
22
+ ```
23
+
24
+ ## Coverage
25
+
26
+ | In/out | Supported |
27
+ |--------|-----------|
28
+ | Paragraphs, headings H1–H6 | yes |
29
+ | Bold / italic / strike / underline / code / highlight | yes |
30
+ | Lists, tables, code blocks | yes (list numbering simplified) |
31
+ | Images | export: `data:` sync, http(s) via async; import → `data:` image nodes |
32
+ | Callout / embed / mention | text fallbacks |
33
+
34
+ ## Notes
35
+
36
+ - Export ZIP uses **store** (uncompressed) for predictability; Word/Pages open it fine.
37
+ - Import inflates **deflate** entries via `fflate` (no Bun-only path).
38
+ - Node import uses `@xmldom/xmldom` when `DOMParser` is missing; browsers use native DOMParser.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "markloom",
3
- "version": "0.5.1",
4
- "description": "The loom for Markdown — rich text with MD isomorphism, reversible Steps, controlled editor, optional AI write + realtime collab",
3
+ "version": "0.7.0",
4
+ "description": "The loom for Markdown — rich text with MD isomorphism, reversible Steps, AI write, collab, search/versions/suggest, DOCX I/O",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",
7
7
  "module": "./dist/index.js",
@@ -32,6 +32,11 @@
32
32
  "import": "./dist/collab/index.js",
33
33
  "require": "./dist/collab/index.cjs"
34
34
  },
35
+ "./io": {
36
+ "types": "./dist/io/index.d.ts",
37
+ "import": "./dist/io/index.js",
38
+ "require": "./dist/io/index.cjs"
39
+ },
35
40
  "./view/theme.css": "./dist/view/theme.css",
36
41
  "./ai/theme.css": "./dist/ai/theme.css"
37
42
  },
@@ -42,7 +47,9 @@
42
47
  "dist",
43
48
  "README.md",
44
49
  "ai.md",
45
- "collab.md"
50
+ "collab.md",
51
+ "io.md",
52
+ "PACKAGES.md"
46
53
  ],
47
54
  "scripts": {
48
55
  "typecheck": "tsc --noEmit",
@@ -50,7 +57,13 @@
50
57
  "dev": "vite --config lab/vite.config.ts",
51
58
  "lab": "vite --config lab/vite.config.ts",
52
59
  "test": "vitest run",
53
- "test:watch": "vitest"
60
+ "test:watch": "vitest",
61
+ "site:dev": "bunx --bun serve site -l 4178",
62
+ "deploy:site": "wrangler pages deploy site --project-name=markloom-www --branch=main --commit-dirty=true",
63
+ "test:domain": "vitest run __tests__/domain/",
64
+ "test:domain:audit": "vitest run __tests__/domain/spaces-audit.meta.test.ts __tests__/domain/axis-sync.meta.test.ts __tests__/domain/registry.meta.test.ts __tests__/domain/catalog.meta.test.ts __tests__/domain/shell-surfaces.meta.test.ts __tests__/domain/classic-coverage.meta.test.ts",
65
+ "test:shell": "vitest run __tests__/editor-behavior-contracts.test.ts __tests__/compound-contracts.test.ts __tests__/editor-delete.test.ts __tests__/editor-cut.test.ts __tests__/tiptap-list-parity.test.ts __tests__/editor-shift-enter.test.ts __tests__/editor-undo-selection.test.ts __tests__/undo-coalesce.test.ts __tests__/block-start-backspace.test.ts __tests__/table-tab-append.test.ts __tests__/code-exit-down.test.ts __tests__/typography-edge.test.ts __tests__/editor-word-line-delete.test.ts __tests__/editor-stray-node.test.ts __tests__/open-async.test.ts __tests__/editor-preact-surface.test.ts __tests__/atom-neighbor-select.test.ts __tests__/gap.test.ts __tests__/hard-break.test.ts __tests__/tasklist.test.ts __tests__/align.test.ts __tests__/typora-keys.test.ts __tests__/keymap.test.ts __tests__/ime-composition-contracts.test.ts __tests__/slash-menu.test.ts __tests__/mention-menu.test.ts __tests__/mention-popovers.test.ts __tests__/bubble-menu.test.ts __tests__/drag-handle.test.ts __tests__/floating-menu.test.ts __tests__/prompt-dialog.test.ts __tests__/toc-panel.test.ts __tests__/ai-write.test.ts __tests__/ai-ui.test.ts __tests__/ai-bubble.test.ts __tests__/ai-discard.test.ts __tests__/ai-discard-draft-orphan.test.ts __tests__/table-controls.test.ts __tests__/image-controls.test.ts __tests__/code-controls.test.ts __tests__/editor-table-delete.test.ts __tests__/editor-image-delete.test.ts __tests__/editor-code-select-all.test.ts __tests__/editor-cell-autolist.test.ts __tests__/editor-paste-image.test.ts __tests__/image-caption-align.test.ts __tests__/math-embed.test.ts __tests__/view.test.ts __tests__/selection.test.ts __tests__/render-parity.test.ts __tests__/heading-fold.test.ts __tests__/invisible-characters.test.ts __tests__/readonly.test.ts __tests__/placeholder.test.ts __tests__/i18n.test.ts __tests__/html-paste.test.ts __tests__/extension.test.ts __tests__/react.test.tsx __tests__/collab-state.test.ts",
66
+ "test:model": "bun run test:domain:audit && bun run test:shell"
54
67
  },
55
68
  "devDependencies": {
56
69
  "@types/mdast": "^4.0.4",
@@ -58,10 +71,14 @@
58
71
  "@types/react-dom": "^19.2.3",
59
72
  "@vitejs/plugin-react": "4",
60
73
  "aihand": "0.1.17",
74
+ "autoprefixer": "^10.5.4",
61
75
  "github-slugger": "^2.0.0",
76
+ "jsdom": "^26.1.0",
77
+ "postcss": "^8.5.24",
62
78
  "react": "^19.2.7",
63
79
  "react-dom": "^19.2.7",
64
80
  "shiki": "^4.3.1",
81
+ "tailwindcss": "3.4.17",
65
82
  "tsup": "^8.4.0",
66
83
  "typescript": "~5.7.2",
67
84
  "vite": "^6",
@@ -86,10 +103,14 @@
86
103
  },
87
104
  "dependencies": {
88
105
  "@floating-ui/dom": "^1.8.0",
106
+ "@xmldom/xmldom": "^0.9.10",
107
+ "fflate": "^0.8.3",
89
108
  "mdast-util-from-markdown": "^2",
90
109
  "mdast-util-gfm": "^3",
91
110
  "mdast-util-to-markdown": "^2",
111
+ "micromark-extension-cjk-friendly": "^2.0.2",
92
112
  "micromark-extension-gfm": "^3",
113
+ "photoswipe": "^5.4.4",
93
114
  "preact": "^10.29.2",
94
115
  "preact-render-to-string": "^6.7.0"
95
116
  }
@@ -1,255 +0,0 @@
1
- import {
2
- transformRemoteAgainstPending
3
- } from "./chunk-RLTHVQNQ.js";
4
-
5
- // src/collab/colors.ts
6
- var COLLAB_COLORS = [
7
- "#3370ff",
8
- "#f54a45",
9
- "#ff8800",
10
- "#00b578",
11
- "#7b61ff",
12
- "#e13edb",
13
- "#14c0ff",
14
- "#8f959e",
15
- "#d83931",
16
- "#2ea121"
17
- ];
18
- function collabColor(siteId, explicit) {
19
- if (explicit)
20
- return explicit;
21
- const i = Math.abs((siteId || 1) - 1) % COLLAB_COLORS.length;
22
- return COLLAB_COLORS[i];
23
- }
24
- function collabInitial(name, siteId) {
25
- const n = (name || "").trim();
26
- if (n) {
27
- const ch = n[0];
28
- return /[a-z]/i.test(ch) ? ch.toUpperCase() : ch;
29
- }
30
- return String(siteId ?? "?");
31
- }
32
-
33
- // src/collab/client.ts
34
- function toWsUrl(url, room) {
35
- let u = url.replace(/\/+$/, "");
36
- if (u.startsWith("https://"))
37
- u = `wss://${u.slice(8)}`;
38
- else if (u.startsWith("http://"))
39
- u = `ws://${u.slice(7)}`;
40
- return `${u}/room/${encodeURIComponent(room)}`;
41
- }
42
- function retryDelay(attempt) {
43
- const base = Math.min(1e3 * 2 ** Math.min(attempt, 5), 3e4);
44
- const jitter = base * 0.5 * Math.random();
45
- return base * 0.75 + jitter;
46
- }
47
- var CollabClient = class {
48
- cfg;
49
- handlers;
50
- ws = null;
51
- closed = false;
52
- retry = 0;
53
- reconnectTimer = null;
54
- siteId = 0;
55
- version = 0;
56
- clientSeq = 0;
57
- pending = [];
58
- peers = /* @__PURE__ */ new Map();
59
- joined = false;
60
- constructor(cfg, handlers) {
61
- this.cfg = cfg;
62
- this.handlers = handlers;
63
- this.connect();
64
- }
65
- get peersList() {
66
- return [...this.peers.values()];
67
- }
68
- connect() {
69
- if (this.closed)
70
- return;
71
- this.handlers.onStatus?.("connecting");
72
- const url = toWsUrl(this.cfg.url, this.cfg.room);
73
- let ws;
74
- try {
75
- ws = new WebSocket(url);
76
- } catch (e) {
77
- this.handlers.onError?.(e instanceof Error ? e.message : String(e));
78
- this.scheduleReconnect();
79
- return;
80
- }
81
- this.ws = ws;
82
- ws.onopen = () => {
83
- this.retry = 0;
84
- this.handlers.onStatus?.("open");
85
- this.send({
86
- type: "join",
87
- room: this.cfg.room,
88
- name: this.cfg.name,
89
- color: this.cfg.color,
90
- seed: this.cfg.seed
91
- });
92
- };
93
- ws.onclose = () => {
94
- this.joined = false;
95
- this.handlers.onStatus?.("closed");
96
- if (!this.closed)
97
- this.scheduleReconnect();
98
- };
99
- ws.onerror = () => {
100
- try {
101
- ws.close();
102
- } catch {
103
- }
104
- };
105
- ws.onmessage = (ev) => {
106
- try {
107
- const msg = JSON.parse(String(ev.data));
108
- this.onServer(msg);
109
- } catch {
110
- }
111
- };
112
- }
113
- scheduleReconnect() {
114
- if (this.reconnectTimer || this.closed)
115
- return;
116
- const delay = retryDelay(this.retry++);
117
- this.reconnectTimer = setTimeout(() => {
118
- this.reconnectTimer = null;
119
- this.connect();
120
- }, delay);
121
- }
122
- send(msg) {
123
- if (this.ws?.readyState === WebSocket.OPEN)
124
- this.ws.send(JSON.stringify(msg));
125
- }
126
- onServer(msg) {
127
- switch (msg.type) {
128
- case "welcome": {
129
- this.siteId = msg.siteId;
130
- this.version = msg.version;
131
- this.pending = [];
132
- this.joined = true;
133
- if (!this.cfg.color)
134
- this.cfg.color = collabColor(msg.siteId);
135
- this.peers.clear();
136
- for (const p of msg.peers) {
137
- this.peers.set(p.siteId, {
138
- ...p,
139
- color: collabColor(p.siteId, p.color)
140
- });
141
- }
142
- this.handlers.onWelcome?.({
143
- siteId: msg.siteId,
144
- version: msg.version,
145
- name: this.cfg.name,
146
- color: this.cfg.color
147
- });
148
- this.handlers.onDoc(msg.doc, msg.version);
149
- this.handlers.onPeers?.(this.peersList);
150
- break;
151
- }
152
- case "resync": {
153
- this.version = msg.version;
154
- this.pending = [];
155
- this.handlers.onDoc(msg.doc, msg.version);
156
- break;
157
- }
158
- case "op": {
159
- if (!this.joined)
160
- return;
161
- if (msg.siteId === this.siteId) {
162
- if (msg.clientSeq != null)
163
- this.pending = this.pending.filter((p) => p.clientSeq > msg.clientSeq);
164
- this.version = msg.version;
165
- return;
166
- }
167
- const pendingAs = this.pending.map((p) => ({ siteId: this.siteId, steps: p.steps }));
168
- const { remote, pending: nextP } = transformRemoteAgainstPending(
169
- msg.steps,
170
- msg.siteId,
171
- pendingAs,
172
- this.siteId
173
- );
174
- this.pending = this.pending.map((p, i) => ({
175
- ...p,
176
- steps: nextP[i]?.steps ?? p.steps
177
- }));
178
- this.version = msg.version;
179
- if (remote.length)
180
- this.handlers.onRemote(remote);
181
- break;
182
- }
183
- case "presence": {
184
- const cur = this.peers.get(msg.siteId) ?? { siteId: msg.siteId };
185
- this.peers.set(msg.siteId, {
186
- ...cur,
187
- name: msg.name ?? cur.name,
188
- color: collabColor(msg.siteId, msg.color ?? cur.color),
189
- sel: msg.sel === void 0 ? cur.sel : msg.sel
190
- });
191
- this.handlers.onPeers?.(this.peersList);
192
- break;
193
- }
194
- case "peer-join": {
195
- this.peers.set(msg.siteId, {
196
- siteId: msg.siteId,
197
- name: msg.name,
198
- color: collabColor(msg.siteId, msg.color)
199
- });
200
- this.handlers.onPeers?.(this.peersList);
201
- break;
202
- }
203
- case "peer-leave": {
204
- this.peers.delete(msg.siteId);
205
- this.handlers.onPeers?.(this.peersList);
206
- break;
207
- }
208
- case "error":
209
- this.handlers.onError?.(msg.message);
210
- break;
211
- case "pong":
212
- break;
213
- }
214
- }
215
- /** 本地已 apply 的 steps 推上服务器 */
216
- push(steps) {
217
- if (!steps.length || !this.joined || this.siteId <= 0)
218
- return;
219
- const clientSeq = ++this.clientSeq;
220
- const baseVersion = this.version;
221
- this.pending.push({ clientSeq, baseVersion, steps });
222
- this.send({ type: "op", baseVersion, clientSeq, steps });
223
- }
224
- presence(sel) {
225
- if (!this.joined)
226
- return;
227
- this.send({
228
- type: "presence",
229
- name: this.cfg.name,
230
- color: this.cfg.color ?? collabColor(this.siteId),
231
- sel
232
- });
233
- }
234
- close() {
235
- this.closed = true;
236
- if (this.reconnectTimer)
237
- clearTimeout(this.reconnectTimer);
238
- try {
239
- this.ws?.close();
240
- } catch {
241
- }
242
- this.ws = null;
243
- }
244
- };
245
- function connectCollab(cfg, handlers) {
246
- return new CollabClient(cfg, handlers);
247
- }
248
-
249
- export {
250
- COLLAB_COLORS,
251
- collabColor,
252
- collabInitial,
253
- CollabClient,
254
- connectCollab
255
- };