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
@@ -2,18 +2,332 @@ import {
2
2
  appendText,
3
3
  insertAfter,
4
4
  mdToDoc,
5
- normalizeToLeaf,
6
5
  pathOfId,
7
6
  rewriteNode
8
- } from "./chunk-MFYF2A6U.js";
7
+ } from "./chunk-QO7JEZDB.js";
9
8
  import {
9
+ firstLeafPath,
10
+ lastLeafEnd,
11
+ nodeAt,
12
+ normalizeToLeaf
13
+ } from "./chunk-ZL6WT6OY.js";
14
+ import {
15
+ isAiCompose,
16
+ isElement,
10
17
  isText
11
- } from "./chunk-LA5SBCGQ.js";
18
+ } from "./chunk-WSJUXPAG.js";
19
+
20
+ // src/i18n.ts
21
+ var KEY = "__markloom_locale__";
22
+ var g = globalThis;
23
+ function setLocale(l) {
24
+ g[KEY] = l === "en" ? "en" : "zh";
25
+ }
26
+ function getLocale() {
27
+ return g[KEY] === "en" ? "en" : "zh";
28
+ }
29
+ var MESSAGES = {
30
+ // —— 块类型(斜杠菜单 / 悬停手柄 / 浮动工具条共用) ——
31
+ blkParagraph: ["\u6B63\u6587", "Text"],
32
+ blkH1: ["\u6807\u9898 1", "Heading 1"],
33
+ blkH2: ["\u6807\u9898 2", "Heading 2"],
34
+ blkH3: ["\u6807\u9898 3", "Heading 3"],
35
+ blkBullet: ["\u65E0\u5E8F\u5217\u8868", "Bulleted list"],
36
+ blkOrdered: ["\u6709\u5E8F\u5217\u8868", "Numbered list"],
37
+ blkTask: ["\u4EFB\u52A1\u5217\u8868", "Task list"],
38
+ blkQuote: ["\u5F15\u7528", "Quote"],
39
+ blkCallout: ["\u9AD8\u4EAE\u5757", "Callout"],
40
+ blkCode: ["\u4EE3\u7801\u5757", "Code block"],
41
+ // —— 斜杠菜单 ——
42
+ aiWrite: ["AI \u5199\u4F5C", "Write with AI"],
43
+ insTable: ["\u8868\u683C", "Table"],
44
+ insImage: ["\u56FE\u7247", "Image"],
45
+ insMath: ["\u516C\u5F0F", "Math"],
46
+ insAudio: ["\u97F3\u9891", "Audio"],
47
+ insFile: ["\u6587\u4EF6", "File"],
48
+ insHr: ["\u5206\u5272\u7EBF", "Divider"],
49
+ // —— 通用 ——
50
+ alignLeft: ["\u5DE6\u5BF9\u9F50", "Align left"],
51
+ alignCenterShort: ["\u5C45\u4E2D", "Center"],
52
+ alignRight: ["\u53F3\u5BF9\u9F50", "Align right"],
53
+ cancel: ["\u53D6\u6D88", "Cancel"],
54
+ ok: ["\u786E\u5B9A", "OK"],
55
+ confirm: ["\u786E\u8BA4", "Confirm"],
56
+ save: ["\u4FDD\u5B58", "Save"],
57
+ delete: ["\u5220\u9664", "Delete"],
58
+ send: ["\u53D1\u9001", "Send"],
59
+ apply: ["\u5E94\u7528", "Apply"],
60
+ insert: ["\u63D2\u5165", "Insert"],
61
+ comment: ["\u8BC4\u8BBA", "Comment"],
62
+ me: ["\u6211", "Me"],
63
+ // —— 浮动工具条 ——
64
+ bbHeading1: ["\u4E00\u7EA7\u6807\u9898", "Heading 1"],
65
+ bbHeading2: ["\u4E8C\u7EA7\u6807\u9898", "Heading 2"],
66
+ bbHeading3: ["\u4E09\u7EA7\u6807\u9898", "Heading 3"],
67
+ bbTask: ["\u4EFB\u52A1", "Task"],
68
+ bbBold: ["\u7C97\u4F53", "Bold"],
69
+ bbStrike: ["\u5220\u9664\u7EBF", "Strikethrough"],
70
+ bbItalic: ["\u659C\u4F53", "Italic"],
71
+ bbUnderline: ["\u4E0B\u5212\u7EBF", "Underline"],
72
+ bbHighlight: ["\u9AD8\u4EAE", "Highlight"],
73
+ mdText: ["\u6587\u672C", "text"],
74
+ mdSpace: ["\u7A7A\u683C", "Space"],
75
+ bbTextAndHeading: ["\u6B63\u6587\u4E0E\u6807\u9898", "Text and headings"],
76
+ bbAlignIndent: ["\u5BF9\u9F50\u4E0E\u7F29\u8FDB", "Align and indent"],
77
+ bbAlignCenter: ["\u5C45\u4E2D\u5BF9\u9F50", "Align center"],
78
+ bbIndentMore: ["\u589E\u52A0\u7F29\u8FDB", "Increase indent"],
79
+ bbIndentLess: ["\u51CF\u5C11\u7F29\u8FDB", "Decrease indent"],
80
+ bbLink: ["\u94FE\u63A5", "Link"],
81
+ bbInlineCode: ["\u884C\u5185\u4EE3\u7801", "Inline code"],
82
+ bbClear: ["\u6E05\u9664\u683C\u5F0F", "Clear formatting"],
83
+ bbColorHighlight: ["\u6587\u5B57\u989C\u8272\u4E0E\u9AD8\u4EAE", "Text color and highlight"],
84
+ bbFontColor: ["\u5B57\u4F53\u989C\u8272", "Text color"],
85
+ bbBgColor: ["\u80CC\u666F\u989C\u8272", "Highlight color"],
86
+ bbReset: ["\u6062\u590D\u9ED8\u8BA4", "Reset"],
87
+ bbAiContinue: ["AI \u7EED\u5199", "Continue with AI"],
88
+ bbContinue: ["\u7EED\u5199", "Continue"],
89
+ bbAiRewrite: ["AI \u6539\u5199", "Rewrite with AI"],
90
+ bbRewrite: ["\u6539\u5199", "Rewrite"],
91
+ // —— 颜色名 ——
92
+ colDefault: ["\u9ED8\u8BA4", "Default"],
93
+ colNone: ["\u65E0", "None"],
94
+ colGray: ["\u7070", "Gray"],
95
+ colDarkGray: ["\u6DF1\u7070", "Dark gray"],
96
+ colRed: ["\u7EA2", "Red"],
97
+ colOrange: ["\u6A59", "Orange"],
98
+ colYellow: ["\u9EC4", "Yellow"],
99
+ colGreen: ["\u7EFF", "Green"],
100
+ colBlue: ["\u84DD", "Blue"],
101
+ colPurple: ["\u7D2B", "Purple"],
102
+ colLightGray: ["\u6D45\u7070", "Light gray"],
103
+ colLightRed: ["\u6D45\u7EA2", "Light red"],
104
+ colLightOrange: ["\u6D45\u6A59", "Light orange"],
105
+ colLightYellow: ["\u6D45\u9EC4", "Light yellow"],
106
+ colLightGreen: ["\u6D45\u7EFF", "Light green"],
107
+ colLightBlue: ["\u6D45\u84DD", "Light blue"],
108
+ colLightPurple: ["\u6D45\u7D2B", "Light purple"],
109
+ // —— 悬停手柄 ——
110
+ dhMove: ["\u62D6\u62FD\u79FB\u52A8 \xB7 \u60AC\u505C\u683C\u5F0F", "Drag to move \xB7 hover for options"],
111
+ dhInsert: ["\u63D2\u5165\u5185\u5BB9", "Insert"],
112
+ dhExpand: ["\u5C55\u5F00", "Expand"],
113
+ dhCollapse: ["\u6298\u53E0", "Collapse"],
114
+ // —— 表格 ——
115
+ tcGrip: ["\u9009\u4E2D/\u79FB\u52A8\u8868\u683C", "Select or move table"],
116
+ tcInsertCol: ["\u63D2\u5165\u5217", "Insert column"],
117
+ tcInsertRow: ["\u63D2\u5165\u884C", "Insert row"],
118
+ tcColLeft: ["\u5DE6\u4FA7\u63D2\u5165\u5217", "Insert column left"],
119
+ tcColRight: ["\u53F3\u4FA7\u63D2\u5165\u5217", "Insert column right"],
120
+ tcDelCol: ["\u5220\u9664\u5217", "Delete column"],
121
+ tcHeaderCol: ["\u5207\u6362\u8868\u5934\u5217", "Header column"],
122
+ tcRowAbove: ["\u4E0A\u65B9\u63D2\u5165\u884C", "Insert row above"],
123
+ tcRowBelow: ["\u4E0B\u65B9\u63D2\u5165\u884C", "Insert row below"],
124
+ tcDelRow: ["\u5220\u9664\u884C", "Delete row"],
125
+ tcMerge: ["\u5408\u5E76\u5355\u5143\u683C", "Merge cells"],
126
+ tcSplit: ["\u62C6\u5206\u5355\u5143\u683C", "Split cell"],
127
+ tcBg: ["\u80CC\u666F\u8272", "Cell color"],
128
+ tcClearBg: ["\u6E05\u9664\u80CC\u666F", "Clear color"],
129
+ tcBorder: ["\u8FB9\u6846\u8272", "Border color"],
130
+ tcClearBorder: ["\u6E05\u9664\u8FB9\u6846", "Clear border"],
131
+ tcDelTable: ["\u5220\u9664\u8868\u683C", "Delete table"],
132
+ tcFreezeRow: ["\u51BB\u7ED3\u9996\u884C", "Freeze top row"],
133
+ tcUnfreezeRow: ["\u53D6\u6D88\u51BB\u7ED3\u9996\u884C", "Unfreeze top row"],
134
+ tcFreezeCol: ["\u51BB\u7ED3\u9996\u5217", "Freeze first column"],
135
+ tcUnfreezeCol: ["\u53D6\u6D88\u51BB\u7ED3\u9996\u5217", "Unfreeze first column"],
136
+ tcCellBgAria: ["\u5355\u5143\u683C\u80CC\u666F\u8272", "Cell color"],
137
+ tcCellBorderAria: ["\u5355\u5143\u683C\u8FB9\u6846\u8272", "Cell border color"],
138
+ // —— 图片 ——
139
+ imgPreview: ["\u9884\u89C8", "Preview"],
140
+ imgPreviewAria: ["\u9884\u89C8\u56FE\u7247", "Preview image"],
141
+ imgCaption: ["\u56FE\u6CE8", "Caption"],
142
+ imgCaptionPh: ["\u56FE\u6CE8\u2026", "Add a caption\u2026"],
143
+ // —— 编辑器内的弹层 ——
144
+ mathPh: ["E=mc^2 \u6216 \\frac{a}{b}", "E=mc^2 or \\frac{a}{b}"],
145
+ mathInsertAria: ["\u63D2\u5165\u516C\u5F0F", "Insert math"],
146
+ mathEditAria: ["\u7F16\u8F91\u516C\u5F0F", "Edit math"],
147
+ mathEmpty: ["\u516C\u5F0F\u4E0D\u80FD\u4E3A\u7A7A", "Enter some math first"],
148
+ mathClickEdit: ["\u70B9\u51FB\u7F16\u8F91\u516C\u5F0F", "Click to edit math"],
149
+ embed: ["\u5D4C\u5165", "Embed"],
150
+ embedYt: ["\u5D4C\u5165 YouTube", "Embed YouTube"],
151
+ embedTw: ["\u5D4C\u5165 Twitch", "Embed Twitch"],
152
+ embedNoLink: ["\u8BF7\u8F93\u5165\u94FE\u63A5", "Enter a link"],
153
+ embedBadYt: ["\u65E0\u6CD5\u8BC6\u522B YouTube \u94FE\u63A5", "That isn\u2019t a valid YouTube link"],
154
+ embedBadTw: ["\u65E0\u6CD5\u8BC6\u522B Twitch \u9891\u9053\u94FE\u63A5", "That isn\u2019t a valid Twitch channel link"],
155
+ // —— 提示框 ——
156
+ promptAria: ["\u8F93\u5165", "Input"],
157
+ promptHint: ["\u2318\u21B5 \u786E\u8BA4", "\u2318\u21B5 to confirm"],
158
+ linkPh: ["\u7C98\u8D34\u6216\u8F93\u5165\u94FE\u63A5", "Paste or type a link"],
159
+ linkAria: ["\u6DFB\u52A0\u94FE\u63A5", "Add link"],
160
+ // —— 目录 ——
161
+ tocAria: ["\u76EE\u5F55", "Outline"],
162
+ tocPageAria: ["\u672C\u9875\u76EE\u5F55", "On this page"],
163
+ tocUntitled: ["\u672A\u547D\u540D\u6807\u9898", "Untitled heading"],
164
+ // —— 代码块 ——
165
+ plainText: ["\u7EAF\u6587\u672C", "Plain text"],
166
+ copyCode: ["\u590D\u5236\u4EE3\u7801", "Copy code"],
167
+ // —— 版本 ——
168
+ verTitle: ["\u7248\u672C", "Versions"],
169
+ verEmpty: ["\u5C1A\u65E0\u5FEB\u7167 \xB7 \u2318\u21E7S", "No versions yet \xB7 \u2318\u21E7S"],
170
+ // —— 提及 / 日期 ——
171
+ profStatus: ["\u72B6\u6001", "Status"],
172
+ profEmail: ["\u90AE\u7BB1", "Email"],
173
+ calWeek: ["\u4E00|\u4E8C|\u4E09|\u56DB|\u4E94|\u516D|\u65E5", "Mo|Tu|We|Th|Fr|Sa|Su"],
174
+ calMonth: ["{y}\u5E74{m}\u6708", "{name} {y}"],
175
+ calNow: ["\u73B0\u5728", "Now"],
176
+ // —— 查找替换 ——
177
+ searchFind: ["\u67E5\u627E", "Find"],
178
+ searchReplaceWith: ["\u66FF\u6362\u4E3A", "Replace with"],
179
+ searchPrev: ["\u4E0A\u4E00\u4E2A", "Previous"],
180
+ searchNext: ["\u4E0B\u4E00\u4E2A", "Next"],
181
+ searchReplace: ["\u66FF\u6362", "Replace"],
182
+ searchAll: ["\u5168\u90E8", "Replace all"],
183
+ close: ["\u5173\u95ED", "Close"],
184
+ // —— 协作 ——
185
+ collabUser: ["\u7528\u6237 {id}", "User {id}"],
186
+ collabUserCaret: ["\u7528\u6237{id}", "User {id}"],
187
+ collabMore: ["\u8FD8\u6709 {n} \u4EBA", "{n} more"],
188
+ collabConnecting: ["{name} \xB7 \u8FDE\u63A5\u4E2D\u2026", "{name} \xB7 Connecting\u2026"],
189
+ collabClosed: ["{name} \xB7 \u5DF2\u65AD\u5F00 \xB7 \u91CD\u8FDE\u4E2D", "{name} \xB7 Offline \xB7 Reconnecting\u2026"],
190
+ collabResyncing: ["{name} \xB7 \u540C\u6B65\u4E2D\u2026", "{name} \xB7 Syncing\u2026"],
191
+ collabConflict: ["{name} \xB7 \u540C\u6B65\u51B2\u7A81 \xB7 \u672C\u5730\u4FEE\u6539\u5DF2\u4FDD\u7559", "{name} \xB7 Sync conflict \xB7 Your changes are kept"],
192
+ collabAuthError: ["{name} \xB7 \u9274\u6743\u5931\u8D25", "{name} \xB7 Sign-in failed"],
193
+ // —— 修订 ——
194
+ sgTrack: ["\u8DDF\u8E2A\u4FEE\u8BA2", "Track changes"],
195
+ sgMarkIns: ["\u6807\u63D2\u5165", "Mark as insertion"],
196
+ sgMarkDel: ["\u6807\u5220\u9664", "Mark as deletion"],
197
+ sgCount: ["{n} \u6761", "{n} changes"],
198
+ sgCount1: ["{n} \u6761", "1 change"],
199
+ sgAccept: ["\u63A5\u53D7", "Accept"],
200
+ sgReject: ["\u62D2\u7EDD", "Reject"],
201
+ sgInsTitle: ["\u5EFA\u8BAE\u63D2\u5165", "Suggested insertion"],
202
+ sgDelTitle: ["\u5EFA\u8BAE\u5220\u9664", "Suggested deletion"],
203
+ // —— 评论栏 ——
204
+ cmtTitle: ["\u8BC4\u8BBA ({n})", "Comments ({n})"],
205
+ cmtOnlyOpen: ["\u53EA\u770B\u672A\u89E3\u51B3", "Show unresolved only"],
206
+ cmtShowResolved: ["\u663E\u793A\u5DF2\u89E3\u51B3", "Show resolved"],
207
+ cmtFilterAll: ["\u5168", "All"],
208
+ cmtFilterOpen: ["\u5F00", "Unresolved"],
209
+ cmtCollapse: ["\u6536\u8D77", "Collapse"],
210
+ cmtAddPh: ["\u6DFB\u52A0\u8BC4\u8BBA\u2026", "Add a comment\u2026"],
211
+ cmtNone: ["\u6682\u65E0\u8BC4\u8BBA", "No comments"],
212
+ cmtNoneOpen: ["\u6682\u65E0\u672A\u89E3\u51B3\u8BC4\u8BBA", "No unresolved comments"],
213
+ cmtResolved: ["\u5DF2\u89E3\u51B3", "Resolved"],
214
+ cmtReopen: ["\u91CD\u65B0\u6253\u5F00", "Reopen"],
215
+ cmtResolve: ["\u89E3\u51B3", "Resolve"],
216
+ cmtReplyPh: ["\u56DE\u590D\u2026", "Reply\u2026"],
217
+ cmtReplies: ["{n} \u6761\u56DE\u590D", "{n} more replies"],
218
+ cmtReply1: ["{n} \u6761\u56DE\u590D", "{n} more reply"],
219
+ // —— 文档内 AI 块 ——
220
+ aiGenerating: ["\u751F\u6210\u4E2D", "Generating"],
221
+ aiPending: ["\u5F85\u786E\u8BA4", "Review"],
222
+ aiFailed: ["\u5931\u8D25", "Failed"],
223
+ aiStop: ["\u505C\u6B62", "Stop"],
224
+ aiStopTitle: ["\u505C\u6B62\u751F\u6210", "Stop generating"],
225
+ aiOriginal: ["\u539F\u6587", "Original"],
226
+ aiPhRewrite: ["\u63CF\u8FF0\u600E\u4E48\u6539\u2026\uFF08\u56DE\u8F66\u751F\u6210\uFF09", "Describe the change\u2026 (Enter to generate)"],
227
+ aiPhWrite: ["\u8F93\u5165\u6307\u4EE4\uFF0C\u56DE\u8F66\u751F\u6210\u2026", "Tell AI what to write\u2026 (Enter to generate)"],
228
+ aiGenerate: ["\u751F\u6210", "Generate"],
229
+ aiNewline: ["\u6362\u884C", "new line"],
230
+ aiStart: ["\u5F00\u59CB\u751F\u6210", "Start generating"],
231
+ aiWritten: ["\u6B63\u6587\u5DF2\u5199\u5165 {n} \u5B57\u2026", "{n} characters written\u2026"],
232
+ aiWriting: ["\u6B63\u5728\u5199\u5165\u6B63\u6587\u2026", "Writing\u2026"],
233
+ aiReview: ["{n} \u5B57\u5DF2\u5199\u5165 \xB7 \u786E\u8BA4\u63D0\u4EA4 / \u4E22\u5F03\u64A4\u56DE", "{n} characters written \xB7 Accept or undo"],
234
+ aiReviewNoCount: ["\u4E0B\u65B9\u6DE1\u5316\u6587\u5B57\u5DF2\u5728\u6587\u6863\u4E2D", "The faded text below is already in your note"],
235
+ aiRetry: ["\u91CD\u8BD5", "Retry"],
236
+ aiRetryTitle: ["\u64A4\u56DE\u5E76\u91CD\u65B0\u751F\u6210", "Undo and try again"],
237
+ aiUndo: ["\u64A4\u56DE", "Undo"],
238
+ aiUndoTitle: ["\u6574\u7B14\u64A4\u56DE(undo)", "Undo everything AI wrote"],
239
+ aiAccept: ["\u786E\u8BA4", "Accept"],
240
+ aiAcceptTitle: ["\u63D0\u4EA4\u4E8B\u52A1", "Keep what AI wrote"],
241
+ aiFailHint: ["\u751F\u6210\u5931\u8D25", "Something went wrong"],
242
+ aiRegenTitle: ["\u91CD\u65B0\u751F\u6210", "Try again"],
243
+ aiDiscard: ["\u4E22\u5F03", "Discard"],
244
+ aiErrNoCursor: ["\u8BF7\u5148\u628A\u5149\u6807\u653E\u5728\u4E00\u6BB5\u6587\u5B57\u91CC", "Click in a paragraph first"],
245
+ aiErrNoText: ["\u5F53\u524D\u6BB5\u6CA1\u6709\u53EF\u6539\u5199\u7684\u6587\u5B57", "This paragraph has no text to rewrite"],
246
+ aiErrNoConfig: ["AI \u672A\u914D\u7F6E:\u8BF7\u8BBE\u7F6E ai.provider \u6216 ai.endpoint", "AI isn\u2019t set up: set ai.provider or ai.endpoint"],
247
+ // —— 渲染杂项 ——
248
+ fnBack: ["\u56DE\u5230\u5F15\u7528\u5904", "Back to reference"],
249
+ fnMissing: ["\u6CA1\u6709\u8FD9\u6761\u811A\u6CE8\u7684\u5B9A\u4E49", "This footnote has no text"],
250
+ fnEmpty: ["(\u7A7A\u811A\u6CE8)", "(empty footnote)"],
251
+ taskDone: ["\u5DF2\u5B8C\u6210", "Done"],
252
+ taskTodo: ["\u672A\u5B8C\u6210", "Not done"],
253
+ diagramEdit: ["\u70B9\u51FB\u7F16\u8F91\u6E90\u7801", "Click to edit source"],
254
+ diagramError: ["\u56FE\u753B\u4E0D\u51FA\u6765:{msg}", "Couldn\u2019t draw this diagram: {msg}"],
255
+ frontMatter: ["\u5143\u6570\u636E", "Metadata"]
256
+ };
257
+ function t(key, params) {
258
+ const pair = MESSAGES[key];
259
+ const s = getLocale() === "en" ? pair[1] : pair[0];
260
+ if (!params)
261
+ return s;
262
+ return s.replace(/\{(\w+)\}/g, (m, k) => k in params ? String(params[k]) : m);
263
+ }
12
264
 
13
265
  // src/view/selection.ts
14
266
  function rootEl(root) {
15
267
  return root.querySelector(".markloom-doc") ?? root;
16
268
  }
269
+ function nodeExtent(doc, nodePath = []) {
270
+ const n = nodePath.length === 0 ? doc : nodeAt(doc, nodePath);
271
+ if (!isElement(n) || n.children.length === 0)
272
+ return null;
273
+ return {
274
+ anchor: { path: normalizeToLeaf(doc, [...nodePath, ...firstLeafPath(n), 0]) },
275
+ head: { path: normalizeToLeaf(doc, [...nodePath, ...lastLeafEnd(n)]) }
276
+ };
277
+ }
278
+ function docExtent(doc) {
279
+ return nodeExtent(doc, []);
280
+ }
281
+ var SELECT_UNIT_TYPES = ["code", "quote"];
282
+ function isSelectUnitType(type) {
283
+ return SELECT_UNIT_TYPES.includes(type);
284
+ }
285
+ function isSelectUnit(n) {
286
+ return isElement(n) && isSelectUnitType(n.type);
287
+ }
288
+ function isProgressiveSelectUnit(n) {
289
+ if (isSelectUnit(n))
290
+ return true;
291
+ return isElement(n) && (n.type === "table_cell" || n.type === "table");
292
+ }
293
+ function progressiveUnitPaths(doc, caretPath) {
294
+ const out = [];
295
+ for (let depth = caretPath.length - 2; depth >= 1; depth--) {
296
+ const p = caretPath.slice(0, depth);
297
+ if (isProgressiveSelectUnit(nodeAt(doc, p)))
298
+ out.push(p);
299
+ }
300
+ return out;
301
+ }
302
+ function selectUnitPath(doc, caretPath) {
303
+ return progressiveUnitPaths(doc, caretPath)[0] ?? null;
304
+ }
305
+ function selectionCovers(sel, extent) {
306
+ return pathEq(sel.anchor.path, extent.anchor.path) && pathEq(sel.head.path, extent.head.path) || pathEq(sel.anchor.path, extent.head.path) && pathEq(sel.head.path, extent.anchor.path);
307
+ }
308
+ function pathUnderUnit(path, unitPath) {
309
+ return unitPath.every((s, i) => path[i] === s);
310
+ }
311
+ function selectionInUnit(sel, unitPath) {
312
+ return pathUnderUnit(sel.anchor.path, unitPath) && pathUnderUnit(sel.head.path, unitPath);
313
+ }
314
+ function expandSelectAll(doc, sel) {
315
+ const whole = docExtent(doc);
316
+ if (!sel)
317
+ return whole;
318
+ const chain = progressiveUnitPaths(doc, sel.head.path);
319
+ for (const unit of chain) {
320
+ if (!selectionInUnit(sel, unit))
321
+ continue;
322
+ const extent = nodeExtent(doc, unit);
323
+ if (extent && !selectionCovers(sel, extent))
324
+ return extent;
325
+ }
326
+ return whole;
327
+ }
328
+ function pathEq(a, b) {
329
+ return a.length === b.length && a.every((v, i) => v === b[i]);
330
+ }
17
331
  function pointToDom(root, doc, pos) {
18
332
  const path = pos.path;
19
333
  if (path.length < 2)
@@ -22,7 +336,7 @@ function pointToDom(root, doc, pos) {
22
336
  for (let i = 0; i < path.length - 1; i++) {
23
337
  if (!domNode)
24
338
  return null;
25
- const child = elementChildren(domNode)[path[i]];
339
+ const child = childAt(domNode, path[i]);
26
340
  if (!child)
27
341
  return null;
28
342
  domNode = child;
@@ -39,7 +353,7 @@ function domToPoint(root, doc, container, domOffset) {
39
353
  const structural = node instanceof HTMLElement && node.nodeType !== 3 && !closestLeaf(node);
40
354
  if (structural) {
41
355
  const kids = elementChildren(node);
42
- const at = kids[domOffset];
356
+ const at = childAt(node, domOffset);
43
357
  if (at) {
44
358
  node = deepestText(at) ?? at;
45
359
  charOffset = 0;
@@ -64,7 +378,7 @@ function domToPoint(root, doc, container, domOffset) {
64
378
  if (node instanceof HTMLElement && (node.dataset.blockId !== void 0 || node.dataset.leaf !== void 0)) {
65
379
  const sp = structuralParent(node);
66
380
  if (sp)
67
- segs.unshift(elementChildren(sp).indexOf(node));
381
+ segs.unshift(childIndex(sp, node));
68
382
  }
69
383
  node = parent;
70
384
  }
@@ -78,11 +392,25 @@ function readSelection(root, doc) {
78
392
  return null;
79
393
  const anchor = domToPoint(root, doc, sel.anchorNode, sel.anchorOffset);
80
394
  const head = domToPoint(root, doc, sel.focusNode, sel.focusOffset);
81
- if (!anchor || !head)
82
- return null;
83
- return { anchor, head };
395
+ if (anchor && head)
396
+ return { anchor, head };
397
+ if (rangeCoversSurface(sel, rootEl(root)))
398
+ return docExtent(doc);
399
+ return null;
400
+ }
401
+ function rangeCoversSurface(sel, top) {
402
+ if (!sel.rangeCount)
403
+ return false;
404
+ try {
405
+ const r = sel.getRangeAt(0);
406
+ const tr = top.ownerDocument.createRange();
407
+ tr.selectNodeContents(top);
408
+ return r.compareBoundaryPoints(Range.START_TO_START, tr) <= 0 && r.compareBoundaryPoints(Range.END_TO_END, tr) >= 0;
409
+ } catch {
410
+ return false;
411
+ }
84
412
  }
85
- function writeSelection(root, doc, selection) {
413
+ function writeSelection(root, doc, selection, opts) {
86
414
  const a = pointToDom(root, doc, selection.anchor);
87
415
  const hd = pointToDom(root, doc, selection.head);
88
416
  if (!a || !hd)
@@ -92,12 +420,17 @@ function writeSelection(root, doc, selection) {
92
420
  return;
93
421
  const host = editableHost(a.node, root);
94
422
  if (host && host !== root.ownerDocument.activeElement)
95
- host.focus({ preventScroll: true });
423
+ host.focus({ preventScroll: !opts?.scroll });
96
424
  const range = root.ownerDocument.createRange();
97
425
  range.setStart(a.node, a.offset);
98
426
  range.setEnd(hd.node, hd.offset);
99
427
  sel.removeAllRanges();
100
428
  sel.addRange(range);
429
+ if (opts?.scroll) {
430
+ const n = a.node;
431
+ const el = n.nodeType === 3 ? n.parentElement : n instanceof HTMLElement ? n : null;
432
+ el?.scrollIntoView?.({ block: "nearest", inline: "nearest" });
433
+ }
101
434
  }
102
435
  function editableHost(node, root) {
103
436
  let el = node.nodeType === 3 ? node.parentElement : node;
@@ -112,18 +445,52 @@ var TRANSPARENT = /* @__PURE__ */ new Set(["TBODY", "TR", "THEAD", "TFOOT", "COL
112
445
  function isTransparent(el) {
113
446
  return TRANSPARENT.has(el.tagName) || el.dataset.pass !== void 0;
114
447
  }
115
- function elementChildren(el) {
116
- const out = [];
448
+ var BIG = 256;
449
+ var structureEpoch = 0;
450
+ var childCache = /* @__PURE__ */ new WeakMap();
451
+ function invalidateStructure(keep) {
452
+ const saved = keep ? childCache.get(keep) : void 0;
453
+ structureEpoch++;
454
+ if (keep && saved && keep.children.length === saved.n)
455
+ childCache.set(keep, { ...saved, epoch: structureEpoch });
456
+ }
457
+ function scanChildren(el, out) {
117
458
  for (const c of el.children) {
118
459
  if (!(c instanceof HTMLElement))
119
460
  continue;
120
- if (c.dataset.blockId !== void 0 || c.dataset.leaf !== void 0)
461
+ if (c.hasAttribute("data-block-id") || c.hasAttribute("data-leaf"))
121
462
  out.push(c);
122
463
  else if (isTransparent(c))
123
- out.push(...elementChildren(c));
464
+ scanChildren(c, out);
124
465
  }
466
+ }
467
+ function scanFresh(el) {
468
+ const out = [];
469
+ scanChildren(el, out);
470
+ const n = el.children.length;
471
+ if (n >= BIG)
472
+ childCache.set(el, { epoch: structureEpoch, n, kids: out });
125
473
  return out;
126
474
  }
475
+ function elementChildren(el) {
476
+ const n = el.children.length;
477
+ if (n >= BIG) {
478
+ const hit = childCache.get(el);
479
+ if (hit && hit.epoch === structureEpoch && hit.n === n)
480
+ return hit.kids;
481
+ }
482
+ return scanFresh(el);
483
+ }
484
+ function childAt(el, i) {
485
+ const c = elementChildren(el)[i];
486
+ if (c && !el.contains(c))
487
+ return scanFresh(el)[i];
488
+ return c;
489
+ }
490
+ function childIndex(el, node) {
491
+ const i = elementChildren(el).indexOf(node);
492
+ return i >= 0 ? i : scanFresh(el).indexOf(node);
493
+ }
127
494
  function structuralParent(node) {
128
495
  let p = node.parentElement;
129
496
  while (p && isTransparent(p))
@@ -171,9 +538,9 @@ function zwspFreeLen(s) {
171
538
  }
172
539
  function offsetWithinLeaf(leaf, target, domOffset) {
173
540
  let acc = 0;
174
- for (const t of leafTextNodes(leaf)) {
175
- const s = t.textContent ?? "";
176
- if (t === target)
541
+ for (const t2 of leafTextNodes(leaf)) {
542
+ const s = t2.textContent ?? "";
543
+ if (t2 === target)
177
544
  return acc + zwspFreeLen(s.slice(0, domOffset));
178
545
  acc += zwspFreeLen(s);
179
546
  }
@@ -182,17 +549,17 @@ function offsetWithinLeaf(leaf, target, domOffset) {
182
549
  function locateInLeaf(leaf, charOff) {
183
550
  const texts = leafTextNodes(leaf);
184
551
  if (texts.length === 0) {
185
- const t = deepestText(leaf);
186
- return { node: t ?? leaf, offset: 0 };
552
+ const t2 = deepestText(leaf);
553
+ return { node: t2 ?? leaf, offset: 0 };
187
554
  }
188
555
  let off = Math.max(0, charOff);
189
556
  let prev = null;
190
- for (const t of texts) {
191
- const s = t.textContent ?? "";
557
+ for (const t2 of texts) {
558
+ const s = t2.textContent ?? "";
192
559
  const len = zwspFreeLen(s);
193
560
  if (s === "\n") {
194
561
  if (off === 0)
195
- return prev ?? { node: t, offset: 1 };
562
+ return prev ?? { node: t2, offset: 1 };
196
563
  off -= len;
197
564
  continue;
198
565
  }
@@ -204,9 +571,9 @@ function locateInLeaf(leaf, charOff) {
204
571
  seen++;
205
572
  if (len === 0)
206
573
  dom = s.length;
207
- return { node: t, offset: dom };
574
+ return { node: t2, offset: dom };
208
575
  }
209
- prev = { node: t, offset: s.length };
576
+ prev = { node: t2, offset: s.length };
210
577
  off -= len;
211
578
  }
212
579
  return prev ?? { node: texts[texts.length - 1], offset: texts[texts.length - 1].textContent?.length ?? 0 };
@@ -238,7 +605,7 @@ function emptyLike(block) {
238
605
  return { type: "heading", id: block.id, attrs: { ...block.attrs }, children: [{ text: "" }] };
239
606
  if (block.type === "code")
240
607
  return { type: "code", id: block.id, attrs: { ...block.attrs }, children: [{ text: "" }] };
241
- if (block.type === "quote" || block.type === "callout") {
608
+ if (block.type === "quote") {
242
609
  return {
243
610
  type: block.type,
244
611
  id: block.id,
@@ -252,7 +619,7 @@ function streamTargetId(doc, blockId) {
252
619
  const b = doc.children.find((c) => !isText(c) && c.id === blockId);
253
620
  if (!b)
254
621
  return blockId;
255
- if (b.type === "quote" || b.type === "callout") {
622
+ if (b.type === "quote") {
256
623
  const inner = b.children.find((c) => !isText(c) && c.type === "paragraph");
257
624
  if (inner?.id)
258
625
  return inner.id;
@@ -320,13 +687,13 @@ function precedingPlainText(doc, blockIdx) {
320
687
  const b = doc.children[i];
321
688
  if (isText(b) || !b.id)
322
689
  continue;
323
- if (b.type === "image" || b.type === "table" || b.type === "embed" || b.type === "raw" || b.type === "ai")
690
+ if (b.type === "image" || b.type === "table" || b.type === "embed" || b.type === "raw" || isAiCompose(b))
324
691
  continue;
325
692
  if (b.attrs?.aiDraft)
326
693
  continue;
327
- const t = blockPlainText(doc, b.id);
328
- if (t.trim())
329
- parts.push(t);
694
+ const t2 = blockPlainText(doc, b.id);
695
+ if (t2.trim())
696
+ parts.push(t2);
330
697
  }
331
698
  return parts.join("\n\n");
332
699
  }
@@ -407,7 +774,7 @@ var MarkloomAi = class {
407
774
  return;
408
775
  const bid = focusBlockId(ed);
409
776
  if (!bid) {
410
- this.opts.onError?.("\u8BF7\u5148\u628A\u5149\u6807\u653E\u5728\u4E00\u6BB5\u6587\u5B57\u91CC");
777
+ this.opts.onError?.(t("aiErrNoCursor"));
411
778
  return;
412
779
  }
413
780
  const doc = ed.doc;
@@ -415,33 +782,31 @@ var MarkloomAi = class {
415
782
  if (idx < 0)
416
783
  return;
417
784
  const cur = doc.children[idx];
418
- if (cur.type === "ai")
785
+ if (isAiCompose(cur))
419
786
  return;
420
787
  if (mode === "rewrite") {
421
788
  if (!blockPlainText(doc, bid).trim()) {
422
- this.opts.onError?.("\u5F53\u524D\u6BB5\u6CA1\u6709\u53EF\u6539\u5199\u7684\u6587\u5B57");
789
+ this.opts.onError?.(t("aiErrNoText"));
423
790
  return;
424
791
  }
425
792
  const seed = blockPlainText(doc, bid);
426
793
  const id2 = newAiId();
427
- const promptId2 = newAiId();
428
794
  ed.dispatch(
429
795
  [{
430
796
  kind: "replaceNode",
431
797
  path: [idx],
432
798
  node: {
433
- type: "ai",
799
+ type: "paragraph",
434
800
  id: id2,
435
- attrs: { status: "compose", mode: "rewrite", seed },
436
- children: [{ type: "paragraph", id: promptId2, children: [{ text: "" }] }]
801
+ attrs: { aiCompose: true, status: "compose", mode: "rewrite", seed },
802
+ children: [{ text: "" }]
437
803
  }
438
804
  }],
439
- { anchor: { path: [idx, 0, 0, 0] }, head: { path: [idx, 0, 0, 0] } }
805
+ { anchor: { path: [idx, 0, 0] }, head: { path: [idx, 0, 0] } }
440
806
  );
441
807
  return;
442
808
  }
443
809
  const id = newAiId();
444
- const promptId = newAiId();
445
810
  ed.dispatch(
446
811
  [{
447
812
  kind: "spliceChildren",
@@ -449,13 +814,13 @@ var MarkloomAi = class {
449
814
  at: idx + 1,
450
815
  remove: 0,
451
816
  insert: [{
452
- type: "ai",
817
+ type: "paragraph",
453
818
  id,
454
- attrs: { status: "compose", mode: "continue" },
455
- children: [{ type: "paragraph", id: promptId, children: [{ text: "" }] }]
819
+ attrs: { aiCompose: true, status: "compose", mode: "continue" },
820
+ children: [{ text: "" }]
456
821
  }]
457
822
  }],
458
- { anchor: { path: [idx + 1, 0, 0, 0] }, head: { path: [idx + 1, 0, 0, 0] } }
823
+ { anchor: { path: [idx + 1, 0, 0] }, head: { path: [idx + 1, 0, 0] } }
459
824
  );
460
825
  }
461
826
  openFromSlash(blockIdx, query) {
@@ -464,20 +829,19 @@ var MarkloomAi = class {
464
829
  return;
465
830
  const instruction = aiInstructionFromQuery(query);
466
831
  const id = newAiId();
467
- const promptId = newAiId();
468
832
  const off = instruction.length;
469
833
  ed.dispatch(
470
834
  [{
471
835
  kind: "replaceNode",
472
836
  path: [blockIdx],
473
837
  node: {
474
- type: "ai",
838
+ type: "paragraph",
475
839
  id,
476
- attrs: { status: "compose", mode: "continue" },
477
- children: [{ type: "paragraph", id: promptId, children: [{ text: instruction }] }]
840
+ attrs: { aiCompose: true, status: "compose", mode: "continue" },
841
+ children: [{ text: instruction }]
478
842
  }
479
843
  }],
480
- { anchor: { path: [blockIdx, 0, 0, off] }, head: { path: [blockIdx, 0, 0, off] } }
844
+ { anchor: { path: [blockIdx, 0, off] }, head: { path: [blockIdx, 0, off] } }
481
845
  );
482
846
  }
483
847
  /**
@@ -568,10 +932,10 @@ var MarkloomAi = class {
568
932
  docPreview: ctxBody.slice(0, 4e3),
569
933
  signal: ac.signal
570
934
  },
571
- (t) => {
935
+ (t2) => {
572
936
  if (this.streamingId !== blockId)
573
937
  return;
574
- this.pendingMd += t;
938
+ this.pendingMd += t2;
575
939
  if (!this.raf) {
576
940
  this.raf = requestAnimationFrame(() => {
577
941
  this.raf = 0;
@@ -734,7 +1098,7 @@ var MarkloomAi = class {
734
1098
  if (!path)
735
1099
  return null;
736
1100
  const node = path.reduce((n, i) => n.children[i], ed.doc);
737
- if (!node || isText(node) || node.type !== "ai")
1101
+ if (!node || isText(node) || !isAiCompose(node))
738
1102
  return null;
739
1103
  return { path, node };
740
1104
  }
@@ -920,6 +1284,9 @@ function collectText2(n) {
920
1284
 
921
1285
  // src/ai/stream.ts
922
1286
  function defaultSystem(action) {
1287
+ if (getLocale() === "en") {
1288
+ return action === "rewrite" ? "You are a note-rewriting assistant. Rewrite the given text. Keep the meaning, make it clearer and smoother; no explanations, no heading prefix, no markdown code fences; output the rewritten plain text only (simple line breaks allowed). Reply in the language of the text." : "You are a note-continuation assistant. Continue naturally from the existing context. Same style, no repetition, no explanations, no heading prefix; output the continuation as plain text only (simple line breaks allowed). Reply in the language of the context.";
1289
+ }
923
1290
  if (action === "rewrite") {
924
1291
  return [
925
1292
  "\u4F60\u662F\u7B14\u8BB0\u6539\u5199\u52A9\u624B\u3002\u6839\u636E\u7528\u6237\u7ED9\u51FA\u7684\u539F\u6587,\u8F93\u51FA\u6539\u5199\u540E\u7684\u6B63\u6587\u3002",
@@ -936,6 +1303,21 @@ function defaultSystem(action) {
936
1303
  function userPrompt(action, context, docPreview) {
937
1304
  const ctx = (context || "").slice(0, 8e3);
938
1305
  const prev = (docPreview || "").slice(0, 4e3);
1306
+ if (getLocale() === "en") {
1307
+ if (action === "rewrite")
1308
+ return `Rewrite the following:
1309
+
1310
+ ${ctx}`;
1311
+ return [
1312
+ prev && prev !== ctx ? `Document excerpt:
1313
+ ${prev}
1314
+
1315
+ ` : "",
1316
+ `Continue after this text:
1317
+
1318
+ ${ctx}`
1319
+ ].join("");
1320
+ }
939
1321
  if (action === "rewrite")
940
1322
  return `\u8BF7\u6539\u5199\u4EE5\u4E0B\u5185\u5BB9:
941
1323
 
@@ -1041,7 +1423,7 @@ function createAiStream(cfg) {
1041
1423
  return;
1042
1424
  }
1043
1425
  if (!provider)
1044
- throw new Error("AI \u672A\u914D\u7F6E:\u8BF7\u8BBE\u7F6E ai.provider \u6216 ai.endpoint");
1426
+ throw new Error(t("aiErrNoConfig"));
1045
1427
  const url = completionsUrl(provider.host);
1046
1428
  const res = await fetch(url, {
1047
1429
  method: "POST",
@@ -1068,11 +1450,26 @@ function createAiStream(cfg) {
1068
1450
  }
1069
1451
 
1070
1452
  export {
1453
+ setLocale,
1454
+ getLocale,
1455
+ MESSAGES,
1456
+ t,
1071
1457
  rootEl,
1458
+ nodeExtent,
1459
+ docExtent,
1460
+ SELECT_UNIT_TYPES,
1461
+ isSelectUnitType,
1462
+ isSelectUnit,
1463
+ isProgressiveSelectUnit,
1464
+ progressiveUnitPaths,
1465
+ selectUnitPath,
1466
+ selectionCovers,
1467
+ expandSelectAll,
1072
1468
  pointToDom,
1073
1469
  domToPoint,
1074
1470
  readSelection,
1075
1471
  writeSelection,
1472
+ invalidateStructure,
1076
1473
  elementChildren,
1077
1474
  focusBlockId,
1078
1475
  blockPlainText,