reactive-md 0.4.1 → 0.5.1

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 (98) hide show
  1. package/CHANGELOG-ch.md +144 -113
  2. package/CHANGELOG.md +144 -113
  3. package/LICENSE +21 -21
  4. package/README-ch.md +154 -123
  5. package/README-en.md +179 -147
  6. package/README.md +179 -147
  7. package/SECURITY-ch.md +4 -3
  8. package/SECURITY.md +4 -3
  9. package/THIRD_PARTY_NOTICES.md +138 -1
  10. package/bin/reactive-md.mjs +1 -1
  11. package/dist-library/reactive-md-editor.css +2 -0
  12. package/dist-library/reactive-md-editor.js +3834 -0
  13. package/dist-library/reactive-md-react.js +9324 -1670
  14. package/dist-library/reactive-md.css +1 -1
  15. package/dist-library/reactive-md.js +426 -305
  16. package/dist-library/{runtime-D3QTVYaz.js → runtime-CXBdLQ3A.js} +8950 -2895
  17. package/dist-library/types/editor/ReactiveMarkdownEditor.d.ts +7 -0
  18. package/dist-library/types/editor/editor-commands.d.ts +50 -0
  19. package/dist-library/types/editor/editor-i18n.d.ts +109 -0
  20. package/dist-library/types/editor/editor-toolbar.d.ts +24 -0
  21. package/dist-library/types/editor/editor-view-bar.d.ts +11 -0
  22. package/dist-library/types/editor/extended-native-components.d.ts +58 -0
  23. package/dist-library/types/editor/index.d.ts +9 -0
  24. package/dist-library/types/editor/locale.d.ts +13 -0
  25. package/dist-library/types/editor/native-components.d.ts +47 -0
  26. package/dist-library/types/editor/source-authoring.d.ts +57 -0
  27. package/dist-library/types/editor/types.d.ts +51 -0
  28. package/dist-library/types/editor/use-gutter-metrics.d.ts +5 -0
  29. package/dist-library/types/editor/use-source-history.d.ts +16 -0
  30. package/dist-library/types/local/LocalDocumentView.d.ts +10 -3
  31. package/dist-library/types/local/code-block.d.ts +26 -0
  32. package/dist-library/types/local/diagnostics.d.ts +25 -0
  33. package/dist-library/types/local/footnotes.d.ts +51 -0
  34. package/dist-library/types/local/heading-anchors.d.ts +2 -0
  35. package/dist-library/types/local/html.d.ts +16 -0
  36. package/dist-library/types/local/image-view.d.ts +23 -0
  37. package/dist-library/types/local/index.d.ts +1 -1
  38. package/dist-library/types/local/options.d.ts +29 -0
  39. package/dist-library/types/local/types.d.ts +42 -1
  40. package/dist-library/types/local/worker.d.ts +18 -6
  41. package/dist-library/types/shareable.d.ts +9 -1
  42. package/dist-standalone/reactive-md-standalone.css +1 -1
  43. package/dist-standalone/reactive-md-standalone.js +49 -38
  44. package/docs/compatibility-ch.md +12 -8
  45. package/docs/compatibility-en.md +12 -8
  46. package/docs/component-protocol-ch.md +2 -2
  47. package/docs/component-protocol-en.md +2 -2
  48. package/docs/editor-ch.md +235 -0
  49. package/docs/editor-en.md +235 -0
  50. package/docs/html-compatibility-ch.md +98 -0
  51. package/docs/html-compatibility-en.md +98 -0
  52. package/docs/local-guide-ch.md +11 -5
  53. package/docs/local-guide-en.md +11 -5
  54. package/docs/local-integration-ch.md +4 -1
  55. package/docs/local-integration-en.md +4 -1
  56. package/docs/local-interaction-syntax-ch.md +9 -2
  57. package/docs/local-interaction-syntax-en.md +7 -2
  58. package/docs/release-0.4.1-ch.md +23 -23
  59. package/docs/release-0.4.1-en.md +23 -23
  60. package/docs/release-0.5.0-ch.md +41 -0
  61. package/docs/release-0.5.0-en.md +41 -0
  62. package/docs/release-0.5.1-ch.md +39 -0
  63. package/docs/release-0.5.1-en.md +39 -0
  64. package/docs/releasing-ch.md +108 -101
  65. package/docs/releasing-en.md +108 -101
  66. package/docs/shareable-export-ch.md +6 -2
  67. package/docs/shareable-export-en.md +6 -2
  68. package/examples/integration/core/package.json +7 -7
  69. package/examples/integration/react/index.html +12 -12
  70. package/examples/integration/react/main.jsx +21 -21
  71. package/examples/integration/react/package.json +9 -9
  72. package/examples/integration/react-editor.tsx +74 -0
  73. package/examples/local/README.md +2 -0
  74. package/examples/local/catalog.reactive.md +20 -20
  75. package/examples/local/checklist.reactive.md +32 -32
  76. package/examples/local/comparison.reactive.md +47 -47
  77. package/examples/local/components.reactive.md +44 -44
  78. package/examples/local/counter.reactive.md +7 -7
  79. package/examples/local/diagnostics.reactive.md +54 -54
  80. package/examples/local/diagram.reactive.md +44 -44
  81. package/examples/local/gallery.reactive.md +61 -61
  82. package/examples/local/html-compat.reactive.md +24 -0
  83. package/examples/local/parameters.reactive.md +36 -36
  84. package/examples/local/planning.reactive.md +24 -24
  85. package/examples/local/pricing.reactive.md +20 -20
  86. package/examples/local/zh/catalog.reactive.md +20 -20
  87. package/examples/local/zh/charts.reactive.md +73 -73
  88. package/examples/local/zh/checklist.reactive.md +32 -32
  89. package/examples/local/zh/comparison.reactive.md +47 -47
  90. package/examples/local/zh/components.reactive.md +44 -44
  91. package/examples/local/zh/counter.reactive.md +7 -7
  92. package/examples/local/zh/diagnostics.reactive.md +54 -54
  93. package/examples/local/zh/diagram.reactive.md +44 -44
  94. package/examples/local/zh/gallery.reactive.md +61 -61
  95. package/examples/local/zh/parameters.reactive.md +36 -36
  96. package/examples/local/zh/planning.reactive.md +24 -24
  97. package/examples/local/zh/pricing.reactive.md +20 -20
  98. package/package.json +135 -91
@@ -0,0 +1,3834 @@
1
+ import { createContext as e, forwardRef as t, memo as n, useCallback as r, useContext as i, useEffect as a, useId as o, useImperativeHandle as s, useLayoutEffect as c, useMemo as l, useRef as u, useState as d } from "react";
2
+ import { Fragment as f, jsx as p, jsxs as m } from "react/jsx-runtime";
3
+ import { analyzeLocalSource as ee, completeLocalSource as te, formatLocalSource as h, renameLocalBinding as g } from "reactive-md";
4
+ // src/editor/extended-native-components.ts
5
+ var _ = [
6
+ {
7
+ id: "jump",
8
+ label: "Jump and anchor",
9
+ description: "Link to a named position in this document.",
10
+ group: "action",
11
+ keywords: [
12
+ "jump",
13
+ "anchor",
14
+ "navigation"
15
+ ],
16
+ template: "<jump to=\"{{bind:destination}}\" appearance=\"button\" color=\"#2563eb\">View results</jump>\n\n<anchor id=\"{{bind:destination}}\">\n\n{{selection:Results appear here.}}"
17
+ },
18
+ {
19
+ id: "anchor",
20
+ label: "Anchor",
21
+ description: "Name a destination for document links.",
22
+ group: "layout",
23
+ keywords: [
24
+ "anchor",
25
+ "target",
26
+ "destination"
27
+ ],
28
+ template: "<anchor id=\"{{bind:destination}}\">"
29
+ },
30
+ {
31
+ id: "text",
32
+ label: "Colored text",
33
+ description: "Give selected words a foreground color.",
34
+ group: "hint",
35
+ keywords: [
36
+ "text",
37
+ "color",
38
+ "foreground"
39
+ ],
40
+ inline: !0,
41
+ template: "<text color=\"#a2273a\">{{selection:Important reminder}}</text>"
42
+ },
43
+ {
44
+ id: "section",
45
+ label: "Colored section",
46
+ description: "Apply a shared text color to several paragraphs.",
47
+ group: "layout",
48
+ keywords: [
49
+ "section",
50
+ "color",
51
+ "paragraph"
52
+ ],
53
+ template: "<section color=\"#45536f\">\n\n{{selection:Your paragraphs go here.}}\n\n</section>"
54
+ },
55
+ {
56
+ id: "multi-select",
57
+ label: "Multiple selection",
58
+ description: "Choose up to two items and read their values.",
59
+ group: "input",
60
+ keywords: [
61
+ "multiple",
62
+ "select",
63
+ "subjects",
64
+ "checkbox"
65
+ ],
66
+ template: "<multi-select bind=\"{{bind:subjects}}\" label=\"Subjects\" max-selected=\"2\">\n<option value=\"math\">Math</option>\n<option value=\"physics\">Physics</option>\n<option value=\"chemistry\">Chemistry</option>\n</multi-select>"
67
+ },
68
+ {
69
+ id: "range-slider",
70
+ label: "Interval slider",
71
+ description: "Choose the lower and upper bounds of an interval.",
72
+ group: "input",
73
+ keywords: [
74
+ "range",
75
+ "interval",
76
+ "slider",
77
+ "bounds"
78
+ ],
79
+ template: "<range-slider label=\"Interval\" bind-start=\"{{bind:low}}\" bind-end=\"{{bind:high}}\" initial-start=\"20\" initial-end=\"80\" min=\"0\" max=\"100\" step=\"1\">"
80
+ },
81
+ {
82
+ id: "coordinate",
83
+ label: "Coordinate point",
84
+ description: "Drag a point or change its two coordinates.",
85
+ group: "input",
86
+ keywords: [
87
+ "coordinate",
88
+ "point",
89
+ "drag",
90
+ "geometry"
91
+ ],
92
+ template: "<coordinate label=\"Point\" bind-x=\"{{bind:px}}\" bind-y=\"{{bind:py}}\" initial-x=\"1\" initial-y=\"2\" x-min=\"-5\" x-max=\"5\" y-min=\"-5\" y-max=\"5\">"
93
+ },
94
+ {
95
+ id: "quiz",
96
+ label: "Practice question",
97
+ description: "Check an answer and read a short explanation.",
98
+ group: "action",
99
+ keywords: [
100
+ "quiz",
101
+ "practice",
102
+ "answer",
103
+ "learn"
104
+ ],
105
+ template: "<quiz type=\"choice\" label=\"What is 2 + 3?\" answer=\"b\" explanation=\"The sum is 5.\">\n<option value=\"a\">4</option>\n<option value=\"b\">5</option>\n</quiz>"
106
+ },
107
+ {
108
+ id: "steps",
109
+ label: "Guided steps",
110
+ description: "Read instructions one step at a time.",
111
+ group: "layout",
112
+ keywords: [
113
+ "steps",
114
+ "guide",
115
+ "previous",
116
+ "next"
117
+ ],
118
+ template: "<steps label=\"Learning path\" bind=\"{{bind:lesson}}\">\n<step label=\"Observe\">\nChange a parameter.\n</step>\n<step label=\"Practice\">\nCheck an answer.\n</step>\n</steps>"
119
+ }
120
+ ], ne = {
121
+ jump: {
122
+ label: "跳转与锚点",
123
+ description: "跳到当前文档中的指定位置。",
124
+ keywords: [
125
+ "跳转",
126
+ "锚点",
127
+ "导航"
128
+ ],
129
+ template: "<jump to=\"{{bind:destination}}\" appearance=\"button\" color=\"#2563eb\">查看结果</jump>\n\n<anchor id=\"{{bind:destination}}\">\n\n{{selection:结果显示在这里。}}"
130
+ },
131
+ anchor: {
132
+ label: "锚点",
133
+ description: "为文档内的跳转指定目标位置。",
134
+ keywords: [
135
+ "锚点",
136
+ "目标",
137
+ "位置"
138
+ ],
139
+ template: "<anchor id=\"{{bind:destination}}\">"
140
+ },
141
+ text: {
142
+ label: "文字颜色",
143
+ description: "为选中的局部文字指定颜色。",
144
+ keywords: [
145
+ "文字",
146
+ "颜色",
147
+ "前景"
148
+ ],
149
+ template: "<text color=\"#a2273a\">{{selection:重要提醒}}</text>"
150
+ },
151
+ section: {
152
+ label: "正文颜色",
153
+ description: "为一段或多段正文指定统一颜色。",
154
+ keywords: [
155
+ "正文",
156
+ "段落",
157
+ "颜色"
158
+ ],
159
+ template: "<section color=\"#45536f\">\n\n{{selection:在这里填写正文。}}\n\n</section>"
160
+ },
161
+ "multi-select": {
162
+ label: "多选",
163
+ description: "最多选择两个选项,公开选项值数组。",
164
+ keywords: [
165
+ "多选",
166
+ "选项",
167
+ "主题"
168
+ ],
169
+ template: "<multi-select bind=\"{{bind:subjects}}\" label=\"主题\" max-selected=\"2\">\n<option value=\"math\">数学</option>\n<option value=\"physics\">物理</option>\n<option value=\"chemistry\">化学</option>\n</multi-select>"
170
+ },
171
+ "range-slider": {
172
+ label: "区间滑块",
173
+ description: "同时选择区间的起点和终点。",
174
+ keywords: [
175
+ "区间",
176
+ "滑块",
177
+ "上下限"
178
+ ],
179
+ template: "<range-slider label=\"观察区间\" bind-start=\"{{bind:low}}\" bind-end=\"{{bind:high}}\" initial-start=\"20\" initial-end=\"80\" min=\"0\" max=\"100\" step=\"1\">"
180
+ },
181
+ coordinate: {
182
+ label: "二维坐标",
183
+ description: "拖动坐标点,或直接修改两个坐标。",
184
+ keywords: [
185
+ "坐标",
186
+ "拖动",
187
+ "几何"
188
+ ],
189
+ template: "<coordinate label=\"坐标点\" bind-x=\"{{bind:px}}\" bind-y=\"{{bind:py}}\" initial-x=\"1\" initial-y=\"2\" x-min=\"-5\" x-max=\"5\" y-min=\"-5\" y-max=\"5\">"
190
+ },
191
+ quiz: {
192
+ label: "练习题",
193
+ description: "检查答案并阅读简短解析。",
194
+ keywords: [
195
+ "练习",
196
+ "题目",
197
+ "答案"
198
+ ],
199
+ template: "<quiz type=\"choice\" label=\"2 + 3 等于多少?\" answer=\"b\" explanation=\"相加得到 5。\">\n<option value=\"a\">4</option>\n<option value=\"b\">5</option>\n</quiz>"
200
+ },
201
+ steps: {
202
+ label: "分步阅读",
203
+ description: "按顺序阅读说明,内置上一步和下一步。",
204
+ keywords: [
205
+ "步骤",
206
+ "引导",
207
+ "下一步"
208
+ ],
209
+ template: "<steps label=\"学习路线\" bind=\"{{bind:lesson}}\">\n<step label=\"观察\">\n调整参数。\n</step>\n<step label=\"练习\">\n检查答案。\n</step>\n</steps>"
210
+ }
211
+ }, re = {
212
+ en: {
213
+ sourceLabel: "Reactive MD source",
214
+ region: "Source editor",
215
+ previewRegion: "Document preview",
216
+ viewLabel: "Editor view",
217
+ count: (e) => `${e} ${e === "1" ? "character" : "characters"}`,
218
+ keyboardHint: "Press Esc, then Tab to reach the toolbar",
219
+ edit: "Edit",
220
+ split: "Split",
221
+ preview: "Preview"
222
+ },
223
+ zh: {
224
+ sourceLabel: "Reactive MD 源码",
225
+ region: "源码编辑器",
226
+ previewRegion: "文档预览",
227
+ viewLabel: "编辑器视图",
228
+ count: (e) => `${e} 字`,
229
+ keyboardHint: "按 Esc 再 Tab 可到工具条",
230
+ edit: "编辑",
231
+ split: "并排",
232
+ preview: "预览"
233
+ }
234
+ }, ie = {
235
+ en: {
236
+ boldPlaceholder: "bold text",
237
+ italicPlaceholder: "italic text",
238
+ strikePlaceholder: "strikethrough text",
239
+ inlineCodePlaceholder: "code",
240
+ linkText: "link text",
241
+ imageAlt: "example image",
242
+ codeBlockPlaceholder: "Write code here",
243
+ tableHeaders: [
244
+ "Column 1",
245
+ "Column 2",
246
+ "Column 3"
247
+ ],
248
+ tableRows: [[
249
+ "Example 1",
250
+ "Example 2",
251
+ "Example 3"
252
+ ], [
253
+ "Example 4",
254
+ "Example 5",
255
+ "Example 6"
256
+ ]]
257
+ },
258
+ zh: {
259
+ boldPlaceholder: "粗体文字",
260
+ italicPlaceholder: "斜体文字",
261
+ strikePlaceholder: "删除线文字",
262
+ inlineCodePlaceholder: "代码",
263
+ linkText: "链接文字",
264
+ imageAlt: "示意图",
265
+ codeBlockPlaceholder: "在这里写代码",
266
+ tableHeaders: [
267
+ "列 1",
268
+ "列 2",
269
+ "列 3"
270
+ ],
271
+ tableRows: [[
272
+ "示例 1",
273
+ "示例 2",
274
+ "示例 3"
275
+ ], [
276
+ "示例 4",
277
+ "示例 5",
278
+ "示例 6"
279
+ ]]
280
+ }
281
+ }, ae = {
282
+ en: {
283
+ toolbarLabel: "Document editing toolbar",
284
+ headingLabels: [
285
+ "Body",
286
+ "Heading 1",
287
+ "Heading 2",
288
+ "Heading 3",
289
+ "Heading 4",
290
+ "Heading 5",
291
+ "Heading 6"
292
+ ],
293
+ headingLevelLabel: (e) => `Heading level: ${e}`,
294
+ headingMenuLabel: "Heading level",
295
+ bold: "Bold",
296
+ italic: "Italic",
297
+ listLabel: "List",
298
+ listLabelWithType: (e) => `List: ${e}`,
299
+ listMenuLabel: "List",
300
+ listLabels: {
301
+ bullet: "Bullet list",
302
+ ordered: "Numbered list",
303
+ task: "Task list"
304
+ },
305
+ decreaseIndent: "Decrease indent",
306
+ increaseIndent: "Increase indent",
307
+ insertLink: "Insert link",
308
+ insert: "Insert",
309
+ insertMenuLabel: "Insert content",
310
+ insertItems: {
311
+ image: "Image",
312
+ table: "Table",
313
+ divider: "Divider",
314
+ codeBlock: "Code block",
315
+ inlineCode: "Inline code",
316
+ strikethrough: "Strikethrough",
317
+ quote: "Quote"
318
+ },
319
+ emoji: "Emoji",
320
+ insertEmojiMenuLabel: "Insert emoji",
321
+ insertEmojiLabel: (e) => `Insert emoji ${e}`,
322
+ componentsTriggerLabel: "Insert native component",
323
+ componentsLabel: "Components",
324
+ componentsCompactLabel: "Add",
325
+ nativeMenuLabel: "Insert native component",
326
+ nativeTitle: "Insert component",
327
+ closeNativeLabel: "Close component panel",
328
+ searchPlaceholder: "Search components, descriptions or keywords",
329
+ searchLabel: "Search native components",
330
+ nativeListLabel: "Native component list",
331
+ noMatchingComponents: "No matching components",
332
+ inlineBadge: "Inline",
333
+ historyLabel: "History and export",
334
+ undo: "Undo",
335
+ redo: "Redo",
336
+ download: "Download document",
337
+ more: "More",
338
+ moreMenuLabel: "More actions",
339
+ linkMenuItem: "Link"
340
+ },
341
+ zh: {
342
+ toolbarLabel: "文档编辑工具栏",
343
+ headingLabels: [
344
+ "正文",
345
+ "标题 1",
346
+ "标题 2",
347
+ "标题 3",
348
+ "标题 4",
349
+ "标题 5",
350
+ "标题 6"
351
+ ],
352
+ headingLevelLabel: (e) => `标题级别:${e}`,
353
+ headingMenuLabel: "标题级别",
354
+ bold: "加粗",
355
+ italic: "斜体",
356
+ listLabel: "列表",
357
+ listLabelWithType: (e) => `列表:${e}`,
358
+ listMenuLabel: "列表",
359
+ listLabels: {
360
+ bullet: "无序列表",
361
+ ordered: "有序列表",
362
+ task: "任务列表"
363
+ },
364
+ decreaseIndent: "减少缩进",
365
+ increaseIndent: "增加缩进",
366
+ insertLink: "插入链接",
367
+ insert: "插入",
368
+ insertMenuLabel: "插入内容",
369
+ insertItems: {
370
+ image: "图片",
371
+ table: "表格",
372
+ divider: "分隔线",
373
+ codeBlock: "代码块",
374
+ inlineCode: "行内代码",
375
+ strikethrough: "删除线",
376
+ quote: "引用"
377
+ },
378
+ emoji: "表情",
379
+ insertEmojiMenuLabel: "插入表情",
380
+ insertEmojiLabel: (e) => `插入表情 ${e}`,
381
+ componentsTriggerLabel: "插入原生组件",
382
+ componentsLabel: "插入组件",
383
+ componentsCompactLabel: "添加",
384
+ nativeMenuLabel: "插入原生组件",
385
+ nativeTitle: "插入组件",
386
+ closeNativeLabel: "关闭组件面板",
387
+ searchPlaceholder: "搜索组件、说明或关键词",
388
+ searchLabel: "搜索原生组件",
389
+ nativeListLabel: "原生组件列表",
390
+ noMatchingComponents: "没有匹配的组件",
391
+ inlineBadge: "行内",
392
+ historyLabel: "历史与导出",
393
+ undo: "撤销",
394
+ redo: "重做",
395
+ download: "下载文档",
396
+ more: "更多",
397
+ moreMenuLabel: "更多操作",
398
+ linkMenuItem: "链接"
399
+ }
400
+ }, v = {
401
+ en: {
402
+ groups: {
403
+ input: "Input controls",
404
+ action: "Interactive tools",
405
+ layout: "Content layout",
406
+ data: "Data visualization",
407
+ hint: "Feedback"
408
+ },
409
+ components: {}
410
+ },
411
+ zh: {
412
+ groups: {
413
+ input: "输入控件",
414
+ action: "交互工具",
415
+ layout: "内容组织",
416
+ data: "数据可视化",
417
+ hint: "提示反馈"
418
+ },
419
+ components: {
420
+ ...ne,
421
+ slider: {
422
+ label: "滑块",
423
+ description: "拖动滑块在指定范围内选择一个数值。",
424
+ keywords: [
425
+ "滑块",
426
+ "范围",
427
+ "数值",
428
+ "拖动",
429
+ "滑动"
430
+ ],
431
+ template: "<slider bind=\"{{bind:amount}}\" label=\"数量\" initial=\"10\" min=\"0\" max=\"100\" step=\"1\">"
432
+ },
433
+ number: {
434
+ label: "数字输入",
435
+ description: "输入精确数字,可限制范围和步长。",
436
+ keywords: [
437
+ "数字",
438
+ "数值",
439
+ "输入",
440
+ "步长",
441
+ "数量"
442
+ ],
443
+ template: "<number bind=\"{{bind:quantity}}\" label=\"数量\" initial=\"1\" min=\"0\" max=\"100\" step=\"1\">"
444
+ },
445
+ input: {
446
+ label: "单行文本",
447
+ description: "输入姓名、标题等单行文本。",
448
+ keywords: [
449
+ "文本",
450
+ "单行",
451
+ "输入框",
452
+ "名称",
453
+ "输入"
454
+ ],
455
+ template: "<input bind=\"{{bind:name}}\" label=\"名称\" placeholder=\"请输入名称\">"
456
+ },
457
+ textarea: {
458
+ label: "多行文本",
459
+ description: "输入说明、备注等多行文字。",
460
+ keywords: [
461
+ "文本域",
462
+ "多行",
463
+ "说明",
464
+ "备注",
465
+ "详细"
466
+ ],
467
+ template: "<textarea bind=\"{{bind:message}}\" label=\"详细说明\" placeholder=\"请输入详细说明\" rows=\"4\">"
468
+ },
469
+ toggle: {
470
+ label: "开关",
471
+ description: "在开启与关闭之间切换一个布尔选项。",
472
+ keywords: [
473
+ "开关",
474
+ "布尔",
475
+ "启用",
476
+ "切换",
477
+ "选项"
478
+ ],
479
+ template: "<toggle bind=\"{{bind:enabled}}\" label=\"启用选项\">"
480
+ },
481
+ checkbox: {
482
+ label: "复选框",
483
+ description: "勾选或取消一个布尔选项。",
484
+ keywords: [
485
+ "复选",
486
+ "勾选",
487
+ "布尔",
488
+ "确认",
489
+ "选项"
490
+ ],
491
+ template: "<checkbox bind=\"{{bind:confirmed}}\" label=\"确认选项\">"
492
+ },
493
+ date: {
494
+ label: "日期选择",
495
+ description: "选择一个日期,未选择时为空字符串。",
496
+ keywords: [
497
+ "日期",
498
+ "日历",
499
+ "时间",
500
+ "选择"
501
+ ],
502
+ template: "<date bind=\"{{bind:date}}\" label=\"选择日期\">"
503
+ },
504
+ choices: {
505
+ label: "选项卡片",
506
+ description: "从多个选项卡中选择一项。",
507
+ keywords: [
508
+ "选项",
509
+ "选择",
510
+ "卡片",
511
+ "单选",
512
+ "方案"
513
+ ],
514
+ template: "<choices bind=\"{{bind:plan}}\" label=\"选择方案\">\n<option value=\"basic\">基础版</option>\n<option value=\"pro\">专业版</option>\n</choices>"
515
+ },
516
+ counter: {
517
+ label: "计数器",
518
+ description: "通过加减按钮调整整数,并可一键重置。",
519
+ keywords: [
520
+ "计数",
521
+ "加减",
522
+ "整数",
523
+ "调整",
524
+ "重置"
525
+ ],
526
+ template: "<counter bind=\"{{bind:count}}\" label=\"计数\" initial=\"0\" min=\"0\" max=\"99\">"
527
+ },
528
+ timer: {
529
+ label: "倒计时",
530
+ description: "启动、暂停和重置一段专注计时。",
531
+ keywords: [
532
+ "计时",
533
+ "倒计时",
534
+ "专注",
535
+ "秒",
536
+ "暂停"
537
+ ],
538
+ template: "<timer bind=\"{{bind:remaining}}\" label=\"专注计时\" duration=\"60\">"
539
+ },
540
+ checklist: {
541
+ label: "任务清单",
542
+ description: "用可勾选的任务列表记录完成情况。",
543
+ keywords: [
544
+ "清单",
545
+ "任务",
546
+ "勾选",
547
+ "待办",
548
+ "完成"
549
+ ],
550
+ template: "<checklist bind=\"{{bind:done}}\" label=\"完成清单\">\n- [ ] 第一项任务\n- [ ] 第二项任务\n- [ ] 第三项任务\n</checklist>"
551
+ },
552
+ progress: {
553
+ label: "进度条",
554
+ description: "展示 0 到 100 之间的完成进度。",
555
+ keywords: [
556
+ "进度",
557
+ "完成度",
558
+ "进度条",
559
+ "百分比"
560
+ ],
561
+ template: "<progress label=\"完成进度\" value=\"{{ 40 }}\">"
562
+ },
563
+ panel: {
564
+ label: "参数面板",
565
+ description: "把一组控件包进面板,并附带恢复默认按钮。",
566
+ keywords: [
567
+ "面板",
568
+ "参数",
569
+ "重置",
570
+ "表单",
571
+ "控件"
572
+ ],
573
+ template: "<panel title=\"参数面板\">\n{{selection:示例内容}}\n</panel>"
574
+ },
575
+ card: {
576
+ label: "内容卡片",
577
+ description: "用卡片组织一段独立内容。",
578
+ keywords: [
579
+ "卡片",
580
+ "容器",
581
+ "内容",
582
+ "区块"
583
+ ],
584
+ template: "<card title=\"内容卡片\">\n{{selection:示例内容}}\n</card>"
585
+ },
586
+ if: {
587
+ label: "条件区域",
588
+ description: "只有条件为真时才显示其中内容。",
589
+ keywords: [
590
+ "条件",
591
+ "判断",
592
+ "显示",
593
+ "当"
594
+ ],
595
+ template: "<if when=\"{{ {{select:true}} }}\">\n{{selection:示例内容}}\n</if>"
596
+ },
597
+ tabs: {
598
+ label: "标签页",
599
+ description: "把内容分到多个可切换的标签页中。",
600
+ keywords: [
601
+ "标签页",
602
+ "切换",
603
+ "分组",
604
+ "选项卡"
605
+ ],
606
+ template: "<tabs label=\"内容标签页\">\n<tab label=\"标签一\">\n{{selection:示例内容}}\n</tab>\n\n<tab label=\"标签二\">\n第二个标签页的内容。\n</tab>\n</tabs>"
607
+ },
608
+ accordion: {
609
+ label: "折叠面板",
610
+ description: "把说明放进可展开和收起的条目。",
611
+ keywords: [
612
+ "折叠",
613
+ "展开",
614
+ "问答",
615
+ "手风琴",
616
+ "条目"
617
+ ],
618
+ template: "<accordion label=\"常见问题\">\n<disclosure label=\"问题一\">\n{{selection:示例内容}}\n</disclosure>\n\n<disclosure label=\"问题二\">\n第二个条目的说明。\n</disclosure>\n</accordion>"
619
+ },
620
+ chart: {
621
+ label: "柱状图",
622
+ description: "把 Markdown 表格转换成柱状图。",
623
+ keywords: [
624
+ "图表",
625
+ "柱状图",
626
+ "表格",
627
+ "数据",
628
+ "对比"
629
+ ],
630
+ template: "<chart kind=\"bar\" title=\"分类对比\" y-label=\"数值\">\n| 项目 | 数值 |\n| --- | ---: |\n| 项目甲 | 20 |\n| 项目乙 | 35 |\n</chart>"
631
+ },
632
+ table: {
633
+ label: "增强表格",
634
+ description: "带搜索、排序和分页的 Markdown 表格。",
635
+ keywords: [
636
+ "表格",
637
+ "搜索",
638
+ "排序",
639
+ "分页",
640
+ "数据"
641
+ ],
642
+ template: "<table label=\"数据表格\" page-size=\"5\">\n| 名称 | 分类 | 数值 |\n| --- | --- | ---: |\n| 项目甲 | 分类一 | 20 |\n| 项目乙 | 分类二 | 35 |\n</table>"
643
+ },
644
+ timeline: {
645
+ label: "时间轴",
646
+ description: "用表格展示任务的开始时间与时长。",
647
+ keywords: [
648
+ "时间轴",
649
+ "计划",
650
+ "时长",
651
+ "日程",
652
+ "任务"
653
+ ],
654
+ template: "<timeline title=\"任务时间轴\">\n| 事项 | 开始 | 时长 | 说明 |\n| --- | ---: | ---: | --- |\n| 准备 | 0 | 10 | 列出所需材料 |\n| 执行 | 10 | 20 | 完成主要内容 |\n| 检查 | 30 | 5 | 复核结果 |\n</timeline>"
655
+ },
656
+ diagram: {
657
+ label: "交互图解",
658
+ description: "用节点和连线展示流程,可点击查看说明。",
659
+ keywords: [
660
+ "图解",
661
+ "流程",
662
+ "节点",
663
+ "连线",
664
+ "关系图"
665
+ ],
666
+ template: "<diagram label=\"流程示意\">\n<node id=\"start\" label=\"开始\">\n流程起点。\n</node>\n\n<node id=\"process\" label=\"处理\">\n执行主要步骤。\n</node>\n\n<node id=\"end\" label=\"结束\">\n查看结果。\n</node>\n\n<edge from=\"start\" to=\"process\" label=\"进入\">\n<edge from=\"process\" to=\"end\" label=\"完成\">\n</diagram>"
667
+ },
668
+ plot: {
669
+ label: "函数曲线",
670
+ description: "用 LaTeX 公式绘制一条函数曲线。",
671
+ keywords: [
672
+ "曲线",
673
+ "函数",
674
+ "公式",
675
+ "数学",
676
+ "绘图"
677
+ ],
678
+ template: "<plot min=\"-5\" max=\"5\" label=\"函数曲线\">\n$$ y = x^2 $$\n</plot>"
679
+ },
680
+ alert: {
681
+ label: "提示框",
682
+ description: "用不同语气突出普通、成功或警告信息。",
683
+ keywords: [
684
+ "提示",
685
+ "警告",
686
+ "通知",
687
+ "信息",
688
+ "消息"
689
+ ],
690
+ template: "<alert tone=\"info\" title=\"提示\">\n{{selection:示例内容}}\n</alert>"
691
+ },
692
+ badge: {
693
+ label: "徽标",
694
+ description: "在句子里显示一个简短状态标记。",
695
+ keywords: [
696
+ "徽标",
697
+ "标签",
698
+ "状态",
699
+ "行内",
700
+ "标记"
701
+ ],
702
+ template: "<badge tone=\"success\">标签</badge>"
703
+ },
704
+ tooltip: {
705
+ label: "行内提示",
706
+ description: "为句中的词语附加悬停或聚焦说明。",
707
+ keywords: [
708
+ "提示",
709
+ "悬停",
710
+ "说明",
711
+ "行内",
712
+ "气泡"
713
+ ],
714
+ template: "<tooltip text=\"这里显示补充说明。\">悬停查看</tooltip>"
715
+ }
716
+ }
717
+ }
718
+ }, y = e("en");
719
+ function b({ locale: e, children: t }) {
720
+ return /* @__PURE__ */ p(y.Provider, {
721
+ value: e,
722
+ children: t
723
+ });
724
+ }
725
+ function oe() {
726
+ return i(y);
727
+ }
728
+ // src/editor/editor-commands.ts
729
+ function x(e, t) {
730
+ return typeof e != "number" || Number.isNaN(e) ? 0 : Math.min(Math.max(Math.trunc(e), 0), t);
731
+ }
732
+ function S(e, t) {
733
+ let n = x(t.start, e.length), r = x(t.end, e.length);
734
+ return n <= r ? {
735
+ start: n,
736
+ end: r
737
+ } : {
738
+ start: r,
739
+ end: n
740
+ };
741
+ }
742
+ function C(e) {
743
+ return ie[e] ?? ie.en;
744
+ }
745
+ function w(e, t) {
746
+ return t <= 0 ? 0 : e.lastIndexOf("\n", t - 1) + 1;
747
+ }
748
+ function T(e, t) {
749
+ let n = w(e, t.start), r = t.end > t.start && e[t.end - 1] === "\n" ? t.end - 1 : t.end, i = e.indexOf("\n", r), a = i === -1 ? e.length : i, o = [], s = n;
750
+ for (;;) {
751
+ let t = e.indexOf("\n", s), n = t === -1 || t > a ? a : t;
752
+ if (o.push({
753
+ start: s,
754
+ end: n,
755
+ text: e.slice(s, n)
756
+ }), n >= a) break;
757
+ s = n + 1;
758
+ }
759
+ return o;
760
+ }
761
+ function E(e, t, n) {
762
+ if (n.length === 0) return {
763
+ value: e,
764
+ selection: t
765
+ };
766
+ let r = [...n].sort((e, t) => e.start - t.start), i = 0, a = r.map((e) => {
767
+ let t = e.start + i, n = i;
768
+ return i += e.text.length - (e.end - e.start), {
769
+ edit: e,
770
+ newStart: t,
771
+ deltaBefore: n
772
+ };
773
+ }), o = "", s = 0;
774
+ for (let t of a) o += e.slice(s, t.edit.start), o += t.edit.text, s = t.edit.end;
775
+ o += e.slice(s);
776
+ let c = (e) => {
777
+ for (let t of a) {
778
+ let { edit: n, newStart: r, deltaBefore: i } = t;
779
+ if (e < n.start) return e + i;
780
+ if (e <= n.end) {
781
+ let t = e - n.start, i = t <= n.oldPrefixLength ? n.newPrefixLength : t + (n.newPrefixLength - n.oldPrefixLength);
782
+ return r + Math.min(Math.max(i, 0), n.text.length);
783
+ }
784
+ }
785
+ return e + i;
786
+ };
787
+ return {
788
+ value: o,
789
+ selection: {
790
+ start: c(t.start),
791
+ end: c(t.end)
792
+ }
793
+ };
794
+ }
795
+ function D(e, t, n, r) {
796
+ return t === e.text ? null : {
797
+ start: e.start,
798
+ end: e.end,
799
+ text: t,
800
+ oldPrefixLength: n,
801
+ newPrefixLength: r
802
+ };
803
+ }
804
+ function O(e, t, n, r) {
805
+ return n === "*" ? r ? e[t.start - 1] !== "*" && e[t.end] !== "*" : e[t.start - n.length - 1] !== "*" && e[t.end + n.length] !== "*" : !0;
806
+ }
807
+ function k(e, t, n, r) {
808
+ let i = S(e, t), a = n.length, { start: o, end: s } = i, c = e.slice(o, s);
809
+ if (o !== s) {
810
+ if (c.length >= a * 2 && c.startsWith(n) && c.endsWith(n) && (n !== "*" || !c.startsWith("**") && !c.endsWith("**")) && O(e, i, n, !0)) {
811
+ let t = c.slice(a, c.length - a);
812
+ return {
813
+ value: e.slice(0, o) + t + e.slice(s),
814
+ selection: {
815
+ start: o,
816
+ end: o + t.length
817
+ }
818
+ };
819
+ }
820
+ let t = o - a, r = s + a;
821
+ return t >= 0 && r <= e.length && e.slice(t, o) === n && e.slice(s, r) === n && O(e, i, n, !1) ? {
822
+ value: e.slice(0, t) + c + e.slice(r),
823
+ selection: {
824
+ start: t,
825
+ end: t + c.length
826
+ }
827
+ } : {
828
+ value: e.slice(0, o) + n + c + n + e.slice(s),
829
+ selection: {
830
+ start: o + a,
831
+ end: s + a
832
+ }
833
+ };
834
+ }
835
+ let l = n + r + n;
836
+ return {
837
+ value: e.slice(0, o) + l + e.slice(s),
838
+ selection: {
839
+ start: o + a,
840
+ end: o + a + r.length
841
+ }
842
+ };
843
+ }
844
+ function A(e, t, n = "en") {
845
+ return k(e, t, "**", C(n).boldPlaceholder);
846
+ }
847
+ function se(e, t, n = "en") {
848
+ return k(e, t, "*", C(n).italicPlaceholder);
849
+ }
850
+ function j(e, t, n = "en") {
851
+ return k(e, t, "~~", C(n).strikePlaceholder);
852
+ }
853
+ function M(e) {
854
+ let t = 0;
855
+ for (let n of e.match(/`+/g) ?? []) t = Math.max(t, n.length);
856
+ return t;
857
+ }
858
+ function N(e, t, n) {
859
+ let r = 0;
860
+ for (; e[t] === "`";) r += 1, t += n;
861
+ return r;
862
+ }
863
+ function ce(e, t) {
864
+ let { start: n, end: r } = t, i = e.slice(n, r), a = N(e, n - 1, -1), o = N(e, r, 1), s = a > 0 && a === o ? {
865
+ run: a,
866
+ padding: 0
867
+ } : null, c = N(e, n - 2, -1), l = N(e, r + 1, 1), u = e[n - 1] === " " && e[r] === " " && c > 0 && c === l ? {
868
+ run: c,
869
+ padding: 1
870
+ } : null, d = s ?? u;
871
+ return !d || M(i) >= d.run ? null : d;
872
+ }
873
+ function le(e, t, n = "en") {
874
+ let r = S(e, t), { start: i, end: a } = r, o = e.slice(i, a);
875
+ if (i === a) {
876
+ let t = C(n).inlineCodePlaceholder, r = `\`${t}\``;
877
+ return {
878
+ value: e.slice(0, i) + r + e.slice(a),
879
+ selection: {
880
+ start: i + 1,
881
+ end: i + 1 + t.length
882
+ }
883
+ };
884
+ }
885
+ let s = N(o, 0, 1), c = N(o, o.length - 1, -1);
886
+ if (s > 0 && s === c && o.length >= s * 2 && M(o.slice(s, o.length - s)) < s) {
887
+ let t = o.slice(s, o.length - s);
888
+ return t.startsWith(" ") && t.endsWith(" ") && t.trim().length > 0 && (t = t.slice(1, -1)), {
889
+ value: e.slice(0, i) + t + e.slice(a),
890
+ selection: {
891
+ start: i,
892
+ end: i + t.length
893
+ }
894
+ };
895
+ }
896
+ let l = ce(e, r);
897
+ if (l) {
898
+ let t = l.run + l.padding;
899
+ return {
900
+ value: e.slice(0, i - t) + o + e.slice(a + t),
901
+ selection: {
902
+ start: i - t,
903
+ end: i - t + o.length
904
+ }
905
+ };
906
+ }
907
+ let u = "`".repeat(M(o) + 1), d = /^[` ]|[` ]$/.test(o) ? " " : "", f = u + d;
908
+ return {
909
+ value: e.slice(0, i) + f + o + d + u + e.slice(a),
910
+ selection: {
911
+ start: i + f.length,
912
+ end: i + f.length + o.length
913
+ }
914
+ };
915
+ }
916
+ var P = /^(#{1,6})[ \t]+/;
917
+ function F(e, t, n) {
918
+ let r = S(e, t), i = [];
919
+ for (let t of T(e, r)) {
920
+ let e = P.exec(t.text), r = e ? e[0].length : 0;
921
+ if (n === 0 && !e) continue;
922
+ let a = t.text.slice(r), o = n === 0 ? "" : `${"#".repeat(n)} `, s = D(t, o + a, r, o.length);
923
+ s && i.push(s);
924
+ }
925
+ return E(e, r, i);
926
+ }
927
+ var I = /^([ \t]*)([-*+] )/, L = /^([ \t]*)(\d+[.)] )/, R = /^([ \t]*)([-*+] \[[ xX]\] )/, z = /^([ \t]*)(> ?)/;
928
+ function B(e, t) {
929
+ let n = t.exec(e);
930
+ if (!n) return null;
931
+ let r = n[1] ?? "", i = n[2] ?? "";
932
+ return {
933
+ indent: r,
934
+ prefix: i,
935
+ prefixLength: r.length + i.length
936
+ };
937
+ }
938
+ function V(e) {
939
+ let t = /^[ \t]*/.exec(e);
940
+ return t ? t[0] : "";
941
+ }
942
+ function H(e, t, n, r) {
943
+ let i = S(e, t), a = T(e, i), o = a.map((e) => n(e.text)), s = 0, c = !0;
944
+ for (let e = 0; e < a.length; e += 1) {
945
+ let t = a[e];
946
+ (o[e] || t.text.trim().length > 0) && (s += 1, o[e] || (c = !1));
947
+ }
948
+ let l = s > 0 && c, u = [];
949
+ for (let e = 0; e < a.length; e += 1) {
950
+ let t = a[e], n = o[e] ?? null;
951
+ if (l) {
952
+ if (!n) continue;
953
+ let e = D(t, n.indent + t.text.slice(n.prefixLength), n.prefixLength, n.indent.length);
954
+ e && u.push(e);
955
+ continue;
956
+ }
957
+ let i = n ? n.indent : V(t.text), s = t.text.slice(n ? n.prefixLength : i.length), c = r(i, e + 1), d = D(t, i + c + s, n ? n.prefixLength : i.length, i.length + c.length);
958
+ d && u.push(d);
959
+ }
960
+ return E(e, i, u);
961
+ }
962
+ function U(e, t) {
963
+ return H(e, t, (e) => B(e, I), () => "- ");
964
+ }
965
+ function W(e, t) {
966
+ return H(e, t, (e) => B(e, L), (e, t) => `${t}. `);
967
+ }
968
+ function ue(e, t) {
969
+ return H(e, t, (e) => B(e, R), () => "- [ ] ");
970
+ }
971
+ function G(e, t) {
972
+ return H(e, t, (e) => B(e, z), () => "> ");
973
+ }
974
+ function de(e, t) {
975
+ let n = S(e, t);
976
+ return E(e, n, T(e, n).map((e) => ({
977
+ start: e.start,
978
+ end: e.end,
979
+ text: ` ${e.text}`,
980
+ oldPrefixLength: 0,
981
+ newPrefixLength: 2
982
+ })));
983
+ }
984
+ function fe(e) {
985
+ if (e.startsWith(" ")) return {
986
+ text: e.slice(1),
987
+ removed: 1
988
+ };
989
+ let t = 0;
990
+ for (; t < 2 && e[t] === " ";) t += 1;
991
+ return {
992
+ text: e.slice(t),
993
+ removed: t
994
+ };
995
+ }
996
+ function K(e, t) {
997
+ let n = S(e, t), r = [];
998
+ for (let t of T(e, n)) {
999
+ let e = fe(t.text);
1000
+ if (e.removed === 0) continue;
1001
+ let n = D(t, e.text, e.removed, 0);
1002
+ n && r.push(n);
1003
+ }
1004
+ return E(e, n, r);
1005
+ }
1006
+ function pe(e, t, n = "en") {
1007
+ let { start: r, end: i } = S(e, t), a = e.slice(r, i), o = "https://example.com";
1008
+ if (a.length > 0) {
1009
+ let t = `[${a}](${o})`, n = r + 1 + a.length + 2;
1010
+ return {
1011
+ value: e.slice(0, r) + t + e.slice(i),
1012
+ selection: {
1013
+ start: n,
1014
+ end: n + 19
1015
+ }
1016
+ };
1017
+ }
1018
+ let s = C(n).linkText, c = `[${s}](${o})`;
1019
+ return {
1020
+ value: e.slice(0, r) + c + e.slice(i),
1021
+ selection: {
1022
+ start: r + 1,
1023
+ end: r + 1 + s.length
1024
+ }
1025
+ };
1026
+ }
1027
+ function me(e, t, n = "en") {
1028
+ let { start: r, end: i } = S(e, t), a = e.slice(r, i), o = "images/example.png";
1029
+ if (a.length > 0) {
1030
+ let t = `![${a}](${o})`, n = r + 2 + a.length + 2;
1031
+ return {
1032
+ value: e.slice(0, r) + t + e.slice(i),
1033
+ selection: {
1034
+ start: n,
1035
+ end: n + 18
1036
+ }
1037
+ };
1038
+ }
1039
+ let s = C(n).imageAlt, c = `![${s}](${o})`;
1040
+ return {
1041
+ value: e.slice(0, r) + c + e.slice(i),
1042
+ selection: {
1043
+ start: r + 2,
1044
+ end: r + 2 + s.length
1045
+ }
1046
+ };
1047
+ }
1048
+ function he(e, t, n = "en") {
1049
+ let r = S(e, t), i = e.slice(r.start, r.end), a = i.length > 0 ? i : C(n).codeBlockPlaceholder, o = "`".repeat(Math.max(3, M(a) + 1)), s = `${o}text\n`;
1050
+ return ve(e, r, `${s}${a}\n${o}`, {
1051
+ start: s.length,
1052
+ end: s.length + a.length
1053
+ });
1054
+ }
1055
+ function ge(e) {
1056
+ return [
1057
+ `| ${e.tableHeaders.join(" | ")} |`,
1058
+ `| ${e.tableHeaders.map(() => "---").join(" | ")} |`,
1059
+ ...e.tableRows.map((e) => `| ${e.join(" | ")} |`)
1060
+ ].join("\n");
1061
+ }
1062
+ function _e(e, t) {
1063
+ let n = w(e, t.start), r = e.slice(n, t.start), i = e.indexOf("\n", t.end), a = i === -1 ? e.length : i, o = e.slice(t.end, a), s = "";
1064
+ if (/\S/.test(r)) s = "\n\n";
1065
+ else if (n > 0) {
1066
+ let t = w(e, n - 1);
1067
+ /\S/.test(e.slice(t, n - 1)) && (s = "\n");
1068
+ }
1069
+ return {
1070
+ prefix: s,
1071
+ suffix: /\S/.test(o) ? "\n\n" : ""
1072
+ };
1073
+ }
1074
+ function ve(e, t, n, r) {
1075
+ let { prefix: i, suffix: a } = _e(e, t), o = t.start + i.length;
1076
+ return {
1077
+ value: e.slice(0, t.start) + i + n + a + e.slice(t.end),
1078
+ selection: {
1079
+ start: o + r.start,
1080
+ end: o + r.end
1081
+ }
1082
+ };
1083
+ }
1084
+ function ye(e, t, n = "en") {
1085
+ let r = S(e, t), i = C(n), a = ge(i), o = i.tableRows[0][0], s = a.indexOf(o);
1086
+ return ve(e, r, a, {
1087
+ start: s,
1088
+ end: s + o.length
1089
+ });
1090
+ }
1091
+ function q(e, t) {
1092
+ return ve(e, S(e, t), "---", {
1093
+ start: 3,
1094
+ end: 3
1095
+ });
1096
+ }
1097
+ function be(e, t, n) {
1098
+ let r = S(e, t), i = r.start + n.length;
1099
+ return {
1100
+ value: e.slice(0, r.start) + n + e.slice(r.end),
1101
+ selection: {
1102
+ start: i,
1103
+ end: i
1104
+ }
1105
+ };
1106
+ }
1107
+ var xe = /\{\{(selection(?::[^{}]*)?|caret|select:[^{}]*)\}\}/g;
1108
+ function J(e, t) {
1109
+ let n = "", r = 0, i = null, a = null, o = null;
1110
+ xe.lastIndex = 0;
1111
+ for (let s = xe.exec(e); s; s = xe.exec(e)) {
1112
+ let c = s.index;
1113
+ n += e.slice(r, c), r = c + s[0].length;
1114
+ let l = s[1] ?? "";
1115
+ if (l === "selection") n += t;
1116
+ else if (l.startsWith("selection:")) {
1117
+ let e = l.slice(10);
1118
+ if (t.length > 0) n += t;
1119
+ else {
1120
+ let t = n.length;
1121
+ n += e, a ||= {
1122
+ start: t,
1123
+ end: n.length
1124
+ };
1125
+ }
1126
+ } else if (l === "caret") o === null && (o = n.length);
1127
+ else if (l.startsWith("select:")) {
1128
+ let e = l.slice(7), t = n.length;
1129
+ n += e, i ||= {
1130
+ start: t,
1131
+ end: n.length
1132
+ };
1133
+ } else n += s[0];
1134
+ }
1135
+ return n += e.slice(r), {
1136
+ text: n,
1137
+ select: i,
1138
+ fallback: a,
1139
+ caret: o
1140
+ };
1141
+ }
1142
+ function Se(e, t, n, r = {}) {
1143
+ let i = S(e, t), a = J(n, e.slice(i.start, i.end)), o = r.block === !0 && a.text.length > 0 ? _e(e, i) : {
1144
+ prefix: "",
1145
+ suffix: ""
1146
+ }, s = i.start + o.prefix.length, c;
1147
+ return c = a.select ? {
1148
+ start: s + a.select.start,
1149
+ end: s + a.select.end
1150
+ } : a.fallback ? {
1151
+ start: s + a.fallback.start,
1152
+ end: s + a.fallback.end
1153
+ } : a.caret === null ? {
1154
+ start: s + a.text.length,
1155
+ end: s + a.text.length
1156
+ } : {
1157
+ start: s + a.caret,
1158
+ end: s + a.caret
1159
+ }, {
1160
+ value: e.slice(0, i.start) + o.prefix + a.text + o.suffix + e.slice(i.end),
1161
+ selection: c
1162
+ };
1163
+ }
1164
+ function Ce(e, t) {
1165
+ let n = [], r = 0;
1166
+ for (; r < e.length;) {
1167
+ if (e[r] !== t) {
1168
+ r += 1;
1169
+ continue;
1170
+ }
1171
+ let i = r;
1172
+ for (; e[r] === t;) r += 1;
1173
+ n.push({
1174
+ start: i,
1175
+ end: r,
1176
+ length: r - i
1177
+ });
1178
+ }
1179
+ return n;
1180
+ }
1181
+ function we(e, t) {
1182
+ if (t === "inlineCode") return Ce(e, "`");
1183
+ let n = Ce(e, t === "strike" ? "~" : "*");
1184
+ return t === "italic" ? n.filter((e) => e.length % 2 == 1) : n.filter((e) => e.length >= 2);
1185
+ }
1186
+ function Te(e, t, n) {
1187
+ return e >= t ? !1 : n.some((r) => r.start === e && n.some((e) => e.end === t && e.length === r.length && e.start >= r.end));
1188
+ }
1189
+ function Ee(e, t, n) {
1190
+ return e >= t ? !1 : n.some((r) => r.end === e && n.some((e) => e.start === t && e.length === r.length && e.start >= r.end));
1191
+ }
1192
+ function De(e, t) {
1193
+ let n = 0;
1194
+ for (; n < t.length;) {
1195
+ let r = t[n], i = n + 1;
1196
+ for (; i < t.length && t[i].length !== r.length;) i += 1;
1197
+ let a = t[i];
1198
+ if (!a) n += 1;
1199
+ else {
1200
+ if (e >= r.end && e <= a.start) return !0;
1201
+ n = i + 1;
1202
+ }
1203
+ }
1204
+ return !1;
1205
+ }
1206
+ function Y(e, t, n, r) {
1207
+ if (t.start !== t.end) {
1208
+ let n = we(e, r);
1209
+ return Te(t.start, t.end, n) || Ee(t.start, t.end, n);
1210
+ }
1211
+ return De(Math.min(Math.max(t.start - n.start, 0), n.text.length), we(n.text, r).filter((e) => e.start >= Oe(n.text)));
1212
+ }
1213
+ function Oe(e) {
1214
+ let t = 0;
1215
+ for (;;) {
1216
+ let n = e.slice(t), r = B(n, R) ?? B(n, I) ?? B(n, L) ?? B(n, z);
1217
+ if (!r) return t;
1218
+ t += r.prefixLength;
1219
+ }
1220
+ }
1221
+ function ke(e) {
1222
+ return B(e, R) ? "task" : B(e, I) ? "bullet" : B(e, L) ? "ordered" : null;
1223
+ }
1224
+ function Ae(e, t) {
1225
+ let n = S(e, t), r = T(e, {
1226
+ start: n.start,
1227
+ end: n.start
1228
+ })[0], i = r.text, a = P.exec(i);
1229
+ return {
1230
+ headingLevel: a ? a[1].length : 0,
1231
+ bold: Y(e, n, r, "bold"),
1232
+ italic: Y(e, n, r, "italic"),
1233
+ strike: Y(e, n, r, "strike"),
1234
+ inlineCode: Y(e, n, r, "inlineCode"),
1235
+ list: ke(i),
1236
+ quote: B(i, z) !== null
1237
+ };
1238
+ }
1239
+ // src/editor/native-components.ts
1240
+ var je = [
1241
+ {
1242
+ id: "input",
1243
+ label: "Input controls"
1244
+ },
1245
+ {
1246
+ id: "action",
1247
+ label: "Interactive tools"
1248
+ },
1249
+ {
1250
+ id: "layout",
1251
+ label: "Content layout"
1252
+ },
1253
+ {
1254
+ id: "data",
1255
+ label: "Data visualization"
1256
+ },
1257
+ {
1258
+ id: "hint",
1259
+ label: "Feedback"
1260
+ }
1261
+ ], Me = [
1262
+ ..._,
1263
+ {
1264
+ id: "slider",
1265
+ label: "Slider",
1266
+ description: "Drag the slider to choose a number within a range.",
1267
+ group: "input",
1268
+ keywords: [
1269
+ "slider",
1270
+ "range",
1271
+ "number",
1272
+ "drag",
1273
+ "value"
1274
+ ],
1275
+ template: "<slider bind=\"{{bind:amount}}\" label=\"Amount\" initial=\"10\" min=\"0\" max=\"100\" step=\"1\">"
1276
+ },
1277
+ {
1278
+ id: "number",
1279
+ label: "Number input",
1280
+ description: "Enter an exact number with an optional range and step.",
1281
+ group: "input",
1282
+ keywords: [
1283
+ "number",
1284
+ "numeric",
1285
+ "input",
1286
+ "step",
1287
+ "quantity"
1288
+ ],
1289
+ template: "<number bind=\"{{bind:quantity}}\" label=\"Quantity\" initial=\"1\" min=\"0\" max=\"100\" step=\"1\">"
1290
+ },
1291
+ {
1292
+ id: "input",
1293
+ label: "Single-line text",
1294
+ description: "Enter a name, title or other single-line text.",
1295
+ group: "input",
1296
+ keywords: [
1297
+ "input",
1298
+ "text",
1299
+ "single-line",
1300
+ "field",
1301
+ "name"
1302
+ ],
1303
+ template: "<input bind=\"{{bind:name}}\" label=\"Name\" placeholder=\"Enter a name\">"
1304
+ },
1305
+ {
1306
+ id: "textarea",
1307
+ label: "Multi-line text",
1308
+ description: "Enter notes, descriptions or other multi-line text.",
1309
+ group: "input",
1310
+ keywords: [
1311
+ "textarea",
1312
+ "text area",
1313
+ "multi-line",
1314
+ "notes",
1315
+ "description"
1316
+ ],
1317
+ template: "<textarea bind=\"{{bind:message}}\" label=\"Details\" placeholder=\"Enter details\" rows=\"4\">"
1318
+ },
1319
+ {
1320
+ id: "toggle",
1321
+ label: "Toggle",
1322
+ description: "Switch a boolean option on or off.",
1323
+ group: "input",
1324
+ keywords: [
1325
+ "toggle",
1326
+ "switch",
1327
+ "boolean",
1328
+ "enable",
1329
+ "on"
1330
+ ],
1331
+ template: "<toggle bind=\"{{bind:enabled}}\" label=\"Enable option\">"
1332
+ },
1333
+ {
1334
+ id: "checkbox",
1335
+ label: "Checkbox",
1336
+ description: "Check or uncheck a boolean option.",
1337
+ group: "input",
1338
+ keywords: [
1339
+ "checkbox",
1340
+ "check",
1341
+ "boolean",
1342
+ "confirm",
1343
+ "option"
1344
+ ],
1345
+ template: "<checkbox bind=\"{{bind:confirmed}}\" label=\"Confirm option\">"
1346
+ },
1347
+ {
1348
+ id: "date",
1349
+ label: "Date picker",
1350
+ description: "Pick a date; the value stays empty until one is chosen.",
1351
+ group: "input",
1352
+ keywords: [
1353
+ "date",
1354
+ "calendar",
1355
+ "picker",
1356
+ "day"
1357
+ ],
1358
+ template: "<date bind=\"{{bind:date}}\" label=\"Pick a date\">"
1359
+ },
1360
+ {
1361
+ id: "choices",
1362
+ label: "Choice cards",
1363
+ description: "Pick one option from a set of cards.",
1364
+ group: "input",
1365
+ keywords: [
1366
+ "choices",
1367
+ "options",
1368
+ "cards",
1369
+ "select",
1370
+ "radio"
1371
+ ],
1372
+ template: "<choices bind=\"{{bind:plan}}\" label=\"Choose a plan\">\n<option value=\"basic\">Basic</option>\n<option value=\"pro\">Pro</option>\n</choices>"
1373
+ },
1374
+ {
1375
+ id: "counter",
1376
+ label: "Counter",
1377
+ description: "Adjust an integer with plus and minus buttons, then reset it in one click.",
1378
+ group: "action",
1379
+ keywords: [
1380
+ "counter",
1381
+ "count",
1382
+ "plus",
1383
+ "minus",
1384
+ "integer"
1385
+ ],
1386
+ template: "<counter bind=\"{{bind:count}}\" label=\"Count\" initial=\"0\" min=\"0\" max=\"99\">"
1387
+ },
1388
+ {
1389
+ id: "timer",
1390
+ label: "Countdown timer",
1391
+ description: "Start, pause and reset a focus timer.",
1392
+ group: "action",
1393
+ keywords: [
1394
+ "timer",
1395
+ "countdown",
1396
+ "focus",
1397
+ "seconds",
1398
+ "pause"
1399
+ ],
1400
+ template: "<timer bind=\"{{bind:remaining}}\" label=\"Focus timer\" duration=\"60\">"
1401
+ },
1402
+ {
1403
+ id: "checklist",
1404
+ label: "Checklist",
1405
+ description: "Track completion with a checkable task list.",
1406
+ group: "action",
1407
+ keywords: [
1408
+ "checklist",
1409
+ "tasks",
1410
+ "todo",
1411
+ "check",
1412
+ "done"
1413
+ ],
1414
+ template: "<checklist bind=\"{{bind:done}}\" label=\"Task checklist\">\n- [ ] First task\n- [ ] Second task\n- [ ] Third task\n</checklist>"
1415
+ },
1416
+ {
1417
+ id: "progress",
1418
+ label: "Progress bar",
1419
+ description: "Show completion from 0 to 100.",
1420
+ group: "action",
1421
+ keywords: [
1422
+ "progress",
1423
+ "completion",
1424
+ "bar",
1425
+ "percent"
1426
+ ],
1427
+ template: "<progress label=\"Progress\" value=\"{{ 40 }}\">"
1428
+ },
1429
+ {
1430
+ id: "panel",
1431
+ label: "Parameter panel",
1432
+ description: "Group controls in a panel with a restore-defaults button.",
1433
+ group: "layout",
1434
+ keywords: [
1435
+ "panel",
1436
+ "parameters",
1437
+ "reset",
1438
+ "form",
1439
+ "group"
1440
+ ],
1441
+ template: "<panel title=\"Parameters\">\n{{selection:Sample content}}\n</panel>"
1442
+ },
1443
+ {
1444
+ id: "card",
1445
+ label: "Content card",
1446
+ description: "Organize a self-contained piece of content in a card.",
1447
+ group: "layout",
1448
+ keywords: [
1449
+ "card",
1450
+ "container",
1451
+ "content",
1452
+ "section"
1453
+ ],
1454
+ template: "<card title=\"Content card\">\n{{selection:Sample content}}\n</card>"
1455
+ },
1456
+ {
1457
+ id: "if",
1458
+ label: "Conditional section",
1459
+ description: "Show the contents only when a condition is true.",
1460
+ group: "layout",
1461
+ keywords: [
1462
+ "if",
1463
+ "condition",
1464
+ "when",
1465
+ "show",
1466
+ "visible"
1467
+ ],
1468
+ template: "<if when=\"{{ {{select:true}} }}\">\n{{selection:Sample content}}\n</if>"
1469
+ },
1470
+ {
1471
+ id: "tabs",
1472
+ label: "Tabs",
1473
+ description: "Split content across switchable tabs.",
1474
+ group: "layout",
1475
+ keywords: [
1476
+ "tabs",
1477
+ "switch",
1478
+ "sections",
1479
+ "groups"
1480
+ ],
1481
+ template: "<tabs label=\"Content tabs\">\n<tab label=\"Tab one\">\n{{selection:Sample content}}\n</tab>\n\n<tab label=\"Tab two\">\nContent for the second tab.\n</tab>\n</tabs>"
1482
+ },
1483
+ {
1484
+ id: "accordion",
1485
+ label: "Accordion",
1486
+ description: "Put notes into items that expand and collapse.",
1487
+ group: "layout",
1488
+ keywords: [
1489
+ "accordion",
1490
+ "collapse",
1491
+ "expand",
1492
+ "faq",
1493
+ "disclosure"
1494
+ ],
1495
+ template: "<accordion label=\"FAQ\">\n<disclosure label=\"Question one\">\n{{selection:Sample content}}\n</disclosure>\n\n<disclosure label=\"Question two\">\nDetails for the second item.\n</disclosure>\n</accordion>"
1496
+ },
1497
+ {
1498
+ id: "chart",
1499
+ label: "Bar chart",
1500
+ description: "Turn a Markdown table into a bar chart.",
1501
+ group: "data",
1502
+ keywords: [
1503
+ "chart",
1504
+ "bar",
1505
+ "graph",
1506
+ "table",
1507
+ "data"
1508
+ ],
1509
+ template: "<chart kind=\"bar\" title=\"Category comparison\" y-label=\"Value\">\n| Item | Value |\n| --- | ---: |\n| Item A | 20 |\n| Item B | 35 |\n</chart>"
1510
+ },
1511
+ {
1512
+ id: "table",
1513
+ label: "Enhanced table",
1514
+ description: "A Markdown table with search, sorting and paging.",
1515
+ group: "data",
1516
+ keywords: [
1517
+ "table",
1518
+ "search",
1519
+ "sort",
1520
+ "paging",
1521
+ "data"
1522
+ ],
1523
+ template: "<table label=\"Data table\" page-size=\"5\">\n| Name | Category | Value |\n| --- | --- | ---: |\n| Item A | Category one | 20 |\n| Item B | Category two | 35 |\n</table>"
1524
+ },
1525
+ {
1526
+ id: "timeline",
1527
+ label: "Timeline",
1528
+ description: "Show task start times and durations in a table.",
1529
+ group: "data",
1530
+ keywords: [
1531
+ "timeline",
1532
+ "schedule",
1533
+ "plan",
1534
+ "duration",
1535
+ "gantt"
1536
+ ],
1537
+ template: "<timeline title=\"Task timeline\">\n| Task | Start | Duration | Notes |\n| --- | ---: | ---: | --- |\n| Prepare | 0 | 10 | List the materials |\n| Execute | 10 | 20 | Complete the main work |\n| Review | 30 | 5 | Check the results |\n</timeline>"
1538
+ },
1539
+ {
1540
+ id: "diagram",
1541
+ label: "Interactive diagram",
1542
+ description: "Show a flow with nodes and edges; click a node to read its notes.",
1543
+ group: "data",
1544
+ keywords: [
1545
+ "diagram",
1546
+ "flow",
1547
+ "node",
1548
+ "edge",
1549
+ "graph"
1550
+ ],
1551
+ template: "<diagram label=\"Flow overview\">\n<node id=\"start\" label=\"Start\">\nWhere the flow begins.\n</node>\n\n<node id=\"process\" label=\"Process\">\nPerform the main step.\n</node>\n\n<node id=\"end\" label=\"End\">\nReview the result.\n</node>\n\n<edge from=\"start\" to=\"process\" label=\"Proceed\">\n<edge from=\"process\" to=\"end\" label=\"Complete\">\n</diagram>"
1552
+ },
1553
+ {
1554
+ id: "plot",
1555
+ label: "Function plot",
1556
+ description: "Plot a function curve from a LaTeX formula.",
1557
+ group: "data",
1558
+ keywords: [
1559
+ "plot",
1560
+ "curve",
1561
+ "function",
1562
+ "formula",
1563
+ "latex",
1564
+ "math"
1565
+ ],
1566
+ template: "<plot min=\"-5\" max=\"5\" label=\"Function plot\">\n$$ y = x^2 $$\n</plot>"
1567
+ },
1568
+ {
1569
+ id: "alert",
1570
+ label: "Alert",
1571
+ description: "Highlight info, success or warning messages with different tones.",
1572
+ group: "hint",
1573
+ keywords: [
1574
+ "alert",
1575
+ "notice",
1576
+ "warning",
1577
+ "info",
1578
+ "message"
1579
+ ],
1580
+ template: "<alert tone=\"info\" title=\"Notice\">\n{{selection:Sample content}}\n</alert>"
1581
+ },
1582
+ {
1583
+ id: "badge",
1584
+ label: "Badge",
1585
+ description: "Show a short status marker inside a sentence.",
1586
+ group: "hint",
1587
+ keywords: [
1588
+ "badge",
1589
+ "label",
1590
+ "status",
1591
+ "inline",
1592
+ "tag"
1593
+ ],
1594
+ inline: !0,
1595
+ template: "<badge tone=\"success\">Badge</badge>"
1596
+ },
1597
+ {
1598
+ id: "tooltip",
1599
+ label: "Tooltip",
1600
+ description: "Attach a hover or focus note to a word in a sentence.",
1601
+ group: "hint",
1602
+ keywords: [
1603
+ "tooltip",
1604
+ "hint",
1605
+ "hover",
1606
+ "focus",
1607
+ "inline"
1608
+ ],
1609
+ inline: !0,
1610
+ template: "<tooltip text=\"Extra details appear here.\">Hover to view</tooltip>"
1611
+ }
1612
+ ], Ne = /\{\{bind:([^{}]+)\}\}/g, Pe = /[A-Za-z_][A-Za-z0-9_]*/g;
1613
+ function Fe(e, t) {
1614
+ let n = [...e];
1615
+ for (let e of t) {
1616
+ let t = e.toLowerCase();
1617
+ n.some((e) => e.toLowerCase() === t) || n.push(e);
1618
+ }
1619
+ return n;
1620
+ }
1621
+ var Ie = je.map((e) => ({
1622
+ ...e,
1623
+ label: v.zh.groups[e.id]
1624
+ })), Le = Me.map((e) => ({
1625
+ ...e,
1626
+ keywords: Fe(e.keywords, v.zh.components[e.id]?.keywords ?? [])
1627
+ })), Re = Me.map((e) => {
1628
+ let t = v.zh.components[e.id];
1629
+ return t ? {
1630
+ ...e,
1631
+ label: t.label,
1632
+ description: t.description,
1633
+ keywords: Fe(e.keywords, t.keywords),
1634
+ template: t.template
1635
+ } : e;
1636
+ });
1637
+ function ze(e = "en") {
1638
+ return e === "zh" ? {
1639
+ groups: Ie,
1640
+ components: Re
1641
+ } : {
1642
+ groups: je,
1643
+ components: Le
1644
+ };
1645
+ }
1646
+ function Be(e) {
1647
+ return new Set(e.match(Pe) ?? []);
1648
+ }
1649
+ function Ve(e) {
1650
+ let t = e.trim().replace(/[^A-Za-z0-9_]/g, "_");
1651
+ return t ? /^[0-9]/.test(t) ? `_${t}` : t : "value";
1652
+ }
1653
+ function He(e, t) {
1654
+ if (!t.has(e)) return e;
1655
+ let n = 2;
1656
+ for (; t.has(`${e}${n}`);) n += 1;
1657
+ return `${e}${n}`;
1658
+ }
1659
+ function Ue(e, t, n) {
1660
+ let r = Be(t), i = /* @__PURE__ */ new Map();
1661
+ return e.template.replace(Ne, (e, t) => {
1662
+ let n = t.trim(), a = i.get(n);
1663
+ if (a) return a;
1664
+ let o = He(Ve(n), r);
1665
+ return r.add(o), i.set(n, o), o;
1666
+ });
1667
+ }
1668
+ // src/editor/editor-toolbar.tsx
1669
+ var We = /* @__PURE__ */ "😀.😄.😁.😊.🙂.😉.😍.🤔.😎.😅.😂.🥳.👍.👎.👏.🙏.💡.✅.❌.⚠️.🔥.⭐.🎉.❤️.💬.📌.🚀.📈.📉.🧩.⚙️.🔍.📎.🗂️.🕒.✨".split("."), Ge = [
1670
+ {
1671
+ level: 0,
1672
+ sample: "¶"
1673
+ },
1674
+ {
1675
+ level: 1,
1676
+ sample: "H1"
1677
+ },
1678
+ {
1679
+ level: 2,
1680
+ sample: "H2"
1681
+ },
1682
+ {
1683
+ level: 3,
1684
+ sample: "H3"
1685
+ },
1686
+ {
1687
+ level: 4,
1688
+ sample: "H4"
1689
+ },
1690
+ {
1691
+ level: 5,
1692
+ sample: "H5"
1693
+ },
1694
+ {
1695
+ level: 6,
1696
+ sample: "H6"
1697
+ }
1698
+ ], Ke = [
1699
+ {
1700
+ type: "bullet",
1701
+ icon: "bulletList",
1702
+ command: U
1703
+ },
1704
+ {
1705
+ type: "ordered",
1706
+ icon: "orderedList",
1707
+ command: W
1708
+ },
1709
+ {
1710
+ type: "task",
1711
+ icon: "taskList",
1712
+ command: ue
1713
+ }
1714
+ ], qe = [{
1715
+ labelKey: "decreaseIndent",
1716
+ icon: "outdent",
1717
+ command: K
1718
+ }, {
1719
+ labelKey: "increaseIndent",
1720
+ icon: "indent",
1721
+ command: de
1722
+ }], Je = [
1723
+ {
1724
+ labelKey: "image",
1725
+ icon: "image",
1726
+ command: me
1727
+ },
1728
+ {
1729
+ labelKey: "table",
1730
+ icon: "table",
1731
+ command: ye
1732
+ },
1733
+ {
1734
+ labelKey: "divider",
1735
+ icon: "divider",
1736
+ command: q
1737
+ },
1738
+ {
1739
+ labelKey: "codeBlock",
1740
+ icon: "codeBlock",
1741
+ command: he
1742
+ },
1743
+ {
1744
+ labelKey: "inlineCode",
1745
+ icon: "inlineCode",
1746
+ command: le
1747
+ },
1748
+ {
1749
+ labelKey: "strikethrough",
1750
+ icon: "strike",
1751
+ command: j
1752
+ },
1753
+ {
1754
+ labelKey: "quote",
1755
+ icon: "quote",
1756
+ command: G
1757
+ }
1758
+ ], Ye = {
1759
+ heading: 200,
1760
+ list: 208,
1761
+ insert: 216,
1762
+ more: 188
1763
+ }, Xe = {
1764
+ headingLevel: 0,
1765
+ bold: !1,
1766
+ italic: !1,
1767
+ strike: !1,
1768
+ inlineCode: !1,
1769
+ list: null,
1770
+ quote: !1
1771
+ }, Ze = {
1772
+ smile: /* @__PURE__ */ m(f, { children: [
1773
+ /* @__PURE__ */ p("circle", {
1774
+ cx: "12",
1775
+ cy: "12",
1776
+ r: "8.4"
1777
+ }),
1778
+ /* @__PURE__ */ p("path", { d: "M8.6 14.1c.9 1.4 2 2.1 3.4 2.1s2.5-.7 3.4-2.1" }),
1779
+ /* @__PURE__ */ p("path", { d: "M9.2 9.7h.01M14.8 9.7h.01" })
1780
+ ] }),
1781
+ link: /* @__PURE__ */ m(f, { children: [/* @__PURE__ */ p("path", { d: "M10.1 13.9a3.8 3.8 0 0 0 5.4 0l2.4-2.4a3.8 3.8 0 0 0-5.4-5.4l-1.2 1.2" }), /* @__PURE__ */ p("path", { d: "M13.9 10.1a3.8 3.8 0 0 0-5.4 0l-2.4 2.4a3.8 3.8 0 0 0 5.4 5.4l1.2-1.2" })] }),
1782
+ bulletList: /* @__PURE__ */ m(f, { children: [/* @__PURE__ */ p("path", { d: "M9.5 6.5H20M9.5 12H20M9.5 17.5H20" }), /* @__PURE__ */ p("path", { d: "M4.5 6.5h.01M4.5 12h.01M4.5 17.5h.01" })] }),
1783
+ orderedList: /* @__PURE__ */ m(f, { children: [
1784
+ /* @__PURE__ */ p("path", { d: "M10.5 6.5H20M10.5 12H20M10.5 17.5H20" }),
1785
+ /* @__PURE__ */ p("text", {
1786
+ x: "2.9",
1787
+ y: "8.6",
1788
+ fill: "currentColor",
1789
+ stroke: "none",
1790
+ fontSize: "6.8",
1791
+ fontWeight: "650",
1792
+ fontFamily: "ui-sans-serif, system-ui, sans-serif",
1793
+ children: "1"
1794
+ }),
1795
+ /* @__PURE__ */ p("text", {
1796
+ x: "2.9",
1797
+ y: "14.1",
1798
+ fill: "currentColor",
1799
+ stroke: "none",
1800
+ fontSize: "6.8",
1801
+ fontWeight: "650",
1802
+ fontFamily: "ui-sans-serif, system-ui, sans-serif",
1803
+ children: "2"
1804
+ }),
1805
+ /* @__PURE__ */ p("text", {
1806
+ x: "2.9",
1807
+ y: "19.6",
1808
+ fill: "currentColor",
1809
+ stroke: "none",
1810
+ fontSize: "6.8",
1811
+ fontWeight: "650",
1812
+ fontFamily: "ui-sans-serif, system-ui, sans-serif",
1813
+ children: "3"
1814
+ })
1815
+ ] }),
1816
+ taskList: /* @__PURE__ */ m(f, { children: [
1817
+ /* @__PURE__ */ p("rect", {
1818
+ x: "3",
1819
+ y: "4",
1820
+ width: "5.6",
1821
+ height: "5.6",
1822
+ rx: "1.2"
1823
+ }),
1824
+ /* @__PURE__ */ p("path", { d: "M4.5 6.8l1 1 1.6-1.9" }),
1825
+ /* @__PURE__ */ p("path", { d: "M12 6.8h8.4" }),
1826
+ /* @__PURE__ */ p("path", {
1827
+ d: "M3.4 13.9h5M3.4 17.4h5",
1828
+ opacity: ".55"
1829
+ }),
1830
+ /* @__PURE__ */ p("path", {
1831
+ d: "M12 13.9h8.4M12 17.4h8.4",
1832
+ opacity: ".55"
1833
+ })
1834
+ ] }),
1835
+ outdent: /* @__PURE__ */ m(f, { children: [/* @__PURE__ */ p("path", { d: "M10 6.5H20M10 12H20M10 17.5H20" }), /* @__PURE__ */ p("path", { d: "M7.2 9l-3.4 3 3.4 3M4.2 12h7" })] }),
1836
+ indent: /* @__PURE__ */ m(f, { children: [/* @__PURE__ */ p("path", { d: "M10 6.5H20M10 12H20M10 17.5H20" }), /* @__PURE__ */ p("path", { d: "M3.8 9l3.4 3-3.4 3M3.2 12h7" })] }),
1837
+ quote: /* @__PURE__ */ m(f, { children: [/* @__PURE__ */ p("path", { d: "M10 8.2c-2.4.7-3.8 2.4-3.8 5.2V17H10v-4.2H7.5c0-1.5.7-2.6 2.5-3.2z" }), /* @__PURE__ */ p("path", { d: "M18.5 8.2c-2.4.7-3.8 2.4-3.8 5.2V17h3.8v-4.2h-2.5c0-1.5.7-2.6 2.5-3.2z" })] }),
1838
+ divider: /* @__PURE__ */ m(f, { children: [/* @__PURE__ */ p("path", { d: "M4 12h16" }), /* @__PURE__ */ p("path", {
1839
+ d: "M7 7.5h10M7 16.5h10",
1840
+ opacity: ".55"
1841
+ })] }),
1842
+ codeBlock: /* @__PURE__ */ m(f, { children: [/* @__PURE__ */ p("rect", {
1843
+ x: "3",
1844
+ y: "4.5",
1845
+ width: "18",
1846
+ height: "15",
1847
+ rx: "2.4"
1848
+ }), /* @__PURE__ */ p("path", { d: "M9.8 9.3l-2.7 2.7 2.7 2.7M14.2 9.3l2.7 2.7-2.7 2.7" })] }),
1849
+ inlineCode: /* @__PURE__ */ m(f, { children: [/* @__PURE__ */ p("path", { d: "M8.8 8.5L5 12l3.8 3.5M15.2 8.5L19 12l-3.8 3.5" }), /* @__PURE__ */ p("path", {
1850
+ d: "M13.6 6.5l-3.2 11",
1851
+ opacity: ".45"
1852
+ })] }),
1853
+ strike: /* @__PURE__ */ m(f, { children: [/* @__PURE__ */ p("path", { d: "M4 12h16" }), /* @__PURE__ */ p("path", { d: "M16.7 7.4c-.7-1.2-2-1.9-3.7-1.9-2.3 0-3.9 1.1-3.9 2.8 0 1.5 1.1 2.3 3.7 3 2.8.8 4.2 1.7 4.2 3.5 0 2-1.7 3.2-4.3 3.2-2.1 0-3.6-.8-4.3-2.2" })] }),
1854
+ image: /* @__PURE__ */ m(f, { children: [
1855
+ /* @__PURE__ */ p("rect", {
1856
+ x: "3",
1857
+ y: "4.5",
1858
+ width: "18",
1859
+ height: "15",
1860
+ rx: "2.4"
1861
+ }),
1862
+ /* @__PURE__ */ p("circle", {
1863
+ cx: "8.4",
1864
+ cy: "9.4",
1865
+ r: "1.35"
1866
+ }),
1867
+ /* @__PURE__ */ p("path", { d: "M4.6 17.4l4.9-4.9 3.5 3.5 2.7-2.7 3.7 3.7" })
1868
+ ] }),
1869
+ table: /* @__PURE__ */ m(f, { children: [/* @__PURE__ */ p("rect", {
1870
+ x: "3",
1871
+ y: "4.5",
1872
+ width: "18",
1873
+ height: "15",
1874
+ rx: "2.4"
1875
+ }), /* @__PURE__ */ p("path", { d: "M3.4 9.7h17.2M9.7 9.2v10.2M14.9 9.2v10.2M9.2 14.5h11.4" })] }),
1876
+ undo: /* @__PURE__ */ m(f, { children: [/* @__PURE__ */ p("path", { d: "M5 12h9.2a4.3 4.3 0 0 1 0 8.6h-1.8" }), /* @__PURE__ */ p("path", { d: "M8.8 8.2L5 12l3.8 3.8" })] }),
1877
+ redo: /* @__PURE__ */ m(f, { children: [/* @__PURE__ */ p("path", { d: "M19 12h-9.2a4.3 4.3 0 0 0 0 8.6h1.8" }), /* @__PURE__ */ p("path", { d: "M15.2 8.2L19 12l-3.8 3.8" })] }),
1878
+ download: /* @__PURE__ */ m(f, { children: [/* @__PURE__ */ p("path", { d: "M12 4v10.5M8 10.8l4 3.7 4-3.7" }), /* @__PURE__ */ p("path", { d: "M4.5 17.5v2h15v-2" })] }),
1879
+ chevron: /* @__PURE__ */ p("path", { d: "M7.5 9.7l4.5 4.5 4.5-4.5" }),
1880
+ sparkle: /* @__PURE__ */ m(f, { children: [/* @__PURE__ */ p("path", { d: "M11.2 4.2l1.5 4.3 4.3 1.5-4.3 1.5-1.5 4.3-1.5-4.3-4.3-1.5 4.3-1.5z" }), /* @__PURE__ */ p("path", { d: "M18.3 15.4v3.4M16.6 17.1h3.4" })] }),
1881
+ search: /* @__PURE__ */ m(f, { children: [/* @__PURE__ */ p("circle", {
1882
+ cx: "10.6",
1883
+ cy: "10.6",
1884
+ r: "5.6"
1885
+ }), /* @__PURE__ */ p("path", { d: "M14.8 14.8L20 20" })] }),
1886
+ plus: /* @__PURE__ */ p("path", { d: "M12 5.2v13.6M5.2 12h13.6" }),
1887
+ more: /* @__PURE__ */ m(f, { children: [
1888
+ /* @__PURE__ */ p("circle", {
1889
+ cx: "5.5",
1890
+ cy: "12",
1891
+ r: "1.1",
1892
+ fill: "currentColor",
1893
+ stroke: "none"
1894
+ }),
1895
+ /* @__PURE__ */ p("circle", {
1896
+ cx: "12",
1897
+ cy: "12",
1898
+ r: "1.1",
1899
+ fill: "currentColor",
1900
+ stroke: "none"
1901
+ }),
1902
+ /* @__PURE__ */ p("circle", {
1903
+ cx: "18.5",
1904
+ cy: "12",
1905
+ r: "1.1",
1906
+ fill: "currentColor",
1907
+ stroke: "none"
1908
+ })
1909
+ ] }),
1910
+ close: /* @__PURE__ */ p("path", { d: "M6.5 6.5l11 11M17.5 6.5l-11 11" })
1911
+ };
1912
+ function X({ name: e, className: t }) {
1913
+ return /* @__PURE__ */ p("svg", {
1914
+ className: t ? `editor-toolbar-icon ${t}` : "editor-toolbar-icon",
1915
+ viewBox: "0 0 24 24",
1916
+ width: "18",
1917
+ height: "18",
1918
+ fill: "none",
1919
+ stroke: "currentColor",
1920
+ strokeWidth: "1.7",
1921
+ strokeLinecap: "round",
1922
+ strokeLinejoin: "round",
1923
+ "aria-hidden": "true",
1924
+ focusable: "false",
1925
+ children: Ze[e]
1926
+ });
1927
+ }
1928
+ function Z(e) {
1929
+ e.preventDefault();
1930
+ }
1931
+ function Q({ toolbarId: e, label: t, tabStop: n, onFocus: r, onClick: i, children: a, className: o, disabled: s, expanded: c, popup: l, controls: u, pressed: d, active: f, onKeyDown: m }) {
1932
+ return /* @__PURE__ */ p("button", {
1933
+ type: "button",
1934
+ "data-toolbar-item": "true",
1935
+ "data-toolbar-id": e,
1936
+ "data-tooltip": t,
1937
+ className: `editor-toolbar-button${o ? ` ${o}` : ""}` + (f ? " is-active" : ""),
1938
+ "aria-label": t,
1939
+ "aria-pressed": d,
1940
+ "aria-expanded": c,
1941
+ "aria-haspopup": l,
1942
+ "aria-controls": u,
1943
+ disabled: s,
1944
+ tabIndex: n ? 0 : -1,
1945
+ onFocus: r,
1946
+ onMouseDown: l ? void 0 : Z,
1947
+ onClick: i,
1948
+ onKeyDown: m,
1949
+ children: a
1950
+ });
1951
+ }
1952
+ function Qe(e) {
1953
+ let t = e.current, n = t?.value ?? "", r = Math.max(0, Math.min(t?.selectionStart ?? 0, n.length)), i = Math.max(r, Math.min(t?.selectionEnd ?? 0, n.length));
1954
+ return {
1955
+ value: n,
1956
+ selection: {
1957
+ start: r,
1958
+ end: i
1959
+ },
1960
+ selectedText: n.slice(r, i)
1961
+ };
1962
+ }
1963
+ function $e(e, t) {
1964
+ return !t || e.label.toLowerCase().includes(t) || e.description.toLowerCase().includes(t) || e.keywords.some((e) => e.toLowerCase().includes(t));
1965
+ }
1966
+ function et(e, t) {
1967
+ return e.headingLevel === t.headingLevel && e.bold === t.bold && e.italic === t.italic && e.strike === t.strike && e.inlineCode === t.inlineCode && e.list === t.list && e.quote === t.quote;
1968
+ }
1969
+ function tt(e) {
1970
+ return e ? Array.from(e.querySelectorAll("[data-toolbar-item]")).filter((e) => !e.disabled && e.getClientRects().length > 0) : [];
1971
+ }
1972
+ function nt(e) {
1973
+ return e ? Array.from(e.querySelectorAll("[role=\"menuitem\"], [role=\"menuitemradio\"]")).filter((e) => !e.disabled && e.getClientRects().length > 0) : [];
1974
+ }
1975
+ function rt(e, t) {
1976
+ let n = nt(t);
1977
+ if (n.length === 0) return;
1978
+ let r = document.activeElement, i = r ? n.indexOf(r) : -1, a = i;
1979
+ switch (e.key) {
1980
+ case "ArrowDown":
1981
+ a = i < 0 ? 0 : (i + 1) % n.length;
1982
+ break;
1983
+ case "ArrowUp":
1984
+ a = i < 0 ? n.length - 1 : (i - 1 + n.length) % n.length;
1985
+ break;
1986
+ case "Home":
1987
+ a = 0;
1988
+ break;
1989
+ case "End":
1990
+ a = n.length - 1;
1991
+ break;
1992
+ default: return;
1993
+ }
1994
+ e.preventDefault(), n[a]?.focus();
1995
+ }
1996
+ function it(e, t) {
1997
+ if (!t) return;
1998
+ let n = Array.from(t.querySelectorAll(".editor-toolbar-emoji"));
1999
+ if (n.length === 0) return;
2000
+ let r = document.activeElement, i = r ? n.indexOf(r) : -1;
2001
+ if (i < 0) return;
2002
+ let a = i;
2003
+ switch (e.key) {
2004
+ case "ArrowRight":
2005
+ a = Math.min(i + 1, n.length - 1);
2006
+ break;
2007
+ case "ArrowLeft":
2008
+ a = Math.max(i - 1, 0);
2009
+ break;
2010
+ case "ArrowDown":
2011
+ a = Math.min(i + 8, n.length - 1);
2012
+ break;
2013
+ case "ArrowUp":
2014
+ a = Math.max(i - 8, 0);
2015
+ break;
2016
+ case "Home":
2017
+ a = 0;
2018
+ break;
2019
+ case "End":
2020
+ a = n.length - 1;
2021
+ break;
2022
+ default: return;
2023
+ }
2024
+ e.preventDefault(), n[a]?.focus();
2025
+ }
2026
+ function at({ editorRef: e, onEdit: t, onUndo: n, onRedo: i, canUndo: s, canRedo: f, onExport: ee, showExport: te = !1, disabled: h = !1 }) {
2027
+ let g = u(null), _ = u(null), ne = u(null), re = u(null), ie = u(null), v = u(null), [y, b] = d(null), [x, S] = d("heading"), [C, w] = d(""), [T, E] = d(Xe), [D, O] = d(null), k = o(), j = `${k}-emoji-menu`, M = `${k}-heading-menu`, N = `${k}-list-menu`, ce = `${k}-insert-menu`, le = `${k}-more-menu`, P = `${k}-native-menu`, I = oe(), L = ae[I], R = l(() => ze(I), [I]), z = Ge.map((e) => ({
2028
+ ...e,
2029
+ label: L.headingLabels[e.level]
2030
+ })), B = Ke.map((e) => ({
2031
+ ...e,
2032
+ label: L.listLabels[e.type]
2033
+ })), V = qe.map((e) => ({
2034
+ ...e,
2035
+ label: L[e.labelKey]
2036
+ })), H = Je.map((e) => ({
2037
+ ...e,
2038
+ label: L.insertItems[e.labelKey]
2039
+ })), U = l(() => {
2040
+ let e = C.trim().toLowerCase();
2041
+ return R.groups.map((t) => ({
2042
+ group: t,
2043
+ components: R.components.filter((n) => n.group === t.id && $e(n, e))
2044
+ })).filter((e) => e.components.length > 0);
2045
+ }, [R, C]), W = r(() => {
2046
+ let t = e.current;
2047
+ if (!t) {
2048
+ E(Xe);
2049
+ return;
2050
+ }
2051
+ let n = Ae(t.value, {
2052
+ start: t.selectionStart,
2053
+ end: t.selectionEnd
2054
+ });
2055
+ E((e) => et(e, n) ? e : n);
2056
+ }, [e]), ue = r(() => {
2057
+ v.current !== null && window.cancelAnimationFrame(v.current), v.current = window.requestAnimationFrame(() => {
2058
+ v.current = null, W();
2059
+ });
2060
+ }, [W]);
2061
+ a(() => {
2062
+ let t = e.current;
2063
+ if (!t) return;
2064
+ let n = () => W(), r = [
2065
+ "select",
2066
+ "keyup",
2067
+ "click",
2068
+ "input",
2069
+ "focus"
2070
+ ];
2071
+ for (let e of r) t.addEventListener(e, n);
2072
+ let i = () => {
2073
+ document.activeElement === t && W();
2074
+ };
2075
+ return document.addEventListener("selectionchange", i), W(), () => {
2076
+ for (let e of r) t.removeEventListener(e, n);
2077
+ document.removeEventListener("selectionchange", i);
2078
+ };
2079
+ }, [e, W]), a(() => () => {
2080
+ v.current !== null && window.cancelAnimationFrame(v.current);
2081
+ }, []);
2082
+ let G = r((e) => {
2083
+ let t = e === "emoji" ? "insert" : e === "native" ? "components" : e;
2084
+ return g.current?.querySelector(`[data-toolbar-id="${t}"]`) ?? null;
2085
+ }, []);
2086
+ c(() => {
2087
+ if (!y || y === "native" || y === "emoji") {
2088
+ O(null);
2089
+ return;
2090
+ }
2091
+ let e = window.matchMedia("(max-width: 640px)"), t = () => {
2092
+ if (!e.matches) {
2093
+ O(null);
2094
+ return;
2095
+ }
2096
+ let t = G(y);
2097
+ if (!t) return;
2098
+ let n = t.getBoundingClientRect(), r = Ye[y] ?? 216, i = n.top - 6 - 8, a = window.innerHeight - n.bottom - 6 - 8, o = {};
2099
+ i >= a ? (o.bottom = window.innerHeight - n.top + 6, o.top = "auto", o.maxHeight = Math.max(80, i)) : (o.top = n.bottom + 6, o.bottom = "auto", o.maxHeight = Math.max(80, a)), y === "heading" || y === "list" ? (o.left = Math.min(Math.max(8, n.left), window.innerWidth - 8 - r), o.right = "auto") : (o.right = Math.min(Math.max(8, window.innerWidth - n.right), window.innerWidth - 8 - r), o.left = "auto"), O(o);
2100
+ };
2101
+ return t(), e.addEventListener("change", t), window.addEventListener("resize", t), window.addEventListener("scroll", t, !0), () => {
2102
+ e.removeEventListener("change", t), window.removeEventListener("resize", t), window.removeEventListener("scroll", t, !0);
2103
+ };
2104
+ }, [y, G]), a(() => {
2105
+ if (!y) return;
2106
+ let e = (e) => {
2107
+ g.current && !g.current.contains(e.target) && b(null);
2108
+ }, t = (e) => {
2109
+ if (e.key !== "Escape") return;
2110
+ e.preventDefault(), e.stopPropagation();
2111
+ let t = y;
2112
+ b(null), G(t)?.focus();
2113
+ };
2114
+ return document.addEventListener("pointerdown", e, !0), document.addEventListener("keydown", t, !0), () => {
2115
+ document.removeEventListener("pointerdown", e, !0), document.removeEventListener("keydown", t, !0);
2116
+ };
2117
+ }, [y, G]), a(() => {
2118
+ if (!y) return;
2119
+ let e = ie.current;
2120
+ ie.current = null;
2121
+ let t = window.requestAnimationFrame(() => {
2122
+ let t = _.current;
2123
+ if (e) {
2124
+ let n = nt(t);
2125
+ (e === "first" ? n[0] : n[n.length - 1])?.focus();
2126
+ } else y === "native" ? ne.current?.focus() : y === "emoji" && nt(t)[0]?.focus();
2127
+ });
2128
+ return () => window.cancelAnimationFrame(t);
2129
+ }, [y]);
2130
+ let de = r(() => {
2131
+ let e = tt(g.current);
2132
+ e.length !== 0 && S((t) => e.some((e) => e.dataset.toolbarId === t) ? t : e[0]?.dataset.toolbarId ?? "heading");
2133
+ }, []);
2134
+ a(() => (de(), window.addEventListener("resize", de), () => window.removeEventListener("resize", de)), [de]), a(() => {
2135
+ de();
2136
+ }, [
2137
+ y,
2138
+ s,
2139
+ f,
2140
+ de
2141
+ ]);
2142
+ let fe = r((e) => {
2143
+ h || (b(null), t(e), ue());
2144
+ }, [
2145
+ h,
2146
+ t,
2147
+ ue
2148
+ ]), K = (t) => {
2149
+ if (h) return;
2150
+ let { value: n, selection: r } = Qe(e);
2151
+ fe(t(n, r, I));
2152
+ }, me = (t) => {
2153
+ if (h) return;
2154
+ let { value: n, selection: r } = Qe(e);
2155
+ fe(F(n, r, t));
2156
+ }, he = (t) => {
2157
+ if (h) return;
2158
+ let { value: n, selection: r } = Qe(e);
2159
+ fe(be(n, r, t));
2160
+ }, ge = (t) => {
2161
+ if (h) return;
2162
+ let { value: n, selection: r, selectedText: i } = Qe(e), a = Ue(t, n, i);
2163
+ fe(Se(n, r, a, { block: !t.inline }));
2164
+ }, _e = () => {
2165
+ h || (b(null), n(), ue());
2166
+ }, ve = () => {
2167
+ h || (b(null), i(), ue());
2168
+ }, ye = () => {
2169
+ b(null), te && ee?.();
2170
+ }, q = (e) => {
2171
+ b((t) => t === e ? null : e), e === "native" && w("");
2172
+ }, xe = (e, t, n) => {
2173
+ if (t.preventDefault(), e === "native" && w(""), y === e) {
2174
+ let e = nt(_.current);
2175
+ (n === "first" ? e[0] : e[e.length - 1])?.focus();
2176
+ } else ie.current = n, b(e);
2177
+ }, J = (e, t) => {
2178
+ (t.key === "ArrowDown" || t.key === "ArrowUp") && xe(e, t, t.key === "ArrowDown" ? "first" : "last");
2179
+ }, Ce = (e) => {
2180
+ if (e.altKey || e.ctrlKey || e.metaKey || ![
2181
+ "ArrowLeft",
2182
+ "ArrowRight",
2183
+ "Home",
2184
+ "End"
2185
+ ].includes(e.key)) return;
2186
+ let t = e.target;
2187
+ if (!(t instanceof HTMLElement)) return;
2188
+ let n = t.closest("[data-toolbar-item]");
2189
+ if (!n || n !== t) return;
2190
+ let r = tt(g.current), i = r.indexOf(n);
2191
+ if (i < 0) return;
2192
+ let a = i;
2193
+ switch (e.key) {
2194
+ case "ArrowLeft":
2195
+ a = (i - 1 + r.length) % r.length;
2196
+ break;
2197
+ case "ArrowRight":
2198
+ a = (i + 1) % r.length;
2199
+ break;
2200
+ case "Home":
2201
+ a = 0;
2202
+ break;
2203
+ case "End":
2204
+ a = r.length - 1;
2205
+ break;
2206
+ default: return;
2207
+ }
2208
+ e.preventDefault(), y && b(null), r[a]?.focus();
2209
+ }, we = () => {
2210
+ b(null), G("native")?.focus();
2211
+ }, Te = z.find((e) => e.level === T.headingLevel)?.label ?? L.headingLabels[0], Ee = T.headingLevel === 0 ? "¶" : `H${T.headingLevel}`, De = L.headingLevelLabel(Te), Y = T.list ? L.listLabels[T.list] : null, Oe = Y ? L.listLabelWithType(Y) : L.listLabel, ke = T.list === "ordered" ? "orderedList" : T.list === "task" ? "taskList" : "bulletList";
2212
+ return /* @__PURE__ */ m("div", {
2213
+ className: `editor-toolbar${y ? " is-menu-open" : ""}`,
2214
+ role: "toolbar",
2215
+ "aria-label": L.toolbarLabel,
2216
+ "aria-orientation": "horizontal",
2217
+ "aria-disabled": h || void 0,
2218
+ ref: g,
2219
+ onKeyDown: Ce,
2220
+ children: [
2221
+ /* @__PURE__ */ m("div", {
2222
+ className: "editor-toolbar-slot",
2223
+ children: [/* @__PURE__ */ m(Q, {
2224
+ toolbarId: "heading",
2225
+ label: De,
2226
+ className: "editor-toolbar-heading-trigger",
2227
+ active: T.headingLevel > 0,
2228
+ tabStop: x === "heading",
2229
+ onFocus: () => S("heading"),
2230
+ disabled: h,
2231
+ popup: "menu",
2232
+ expanded: y === "heading",
2233
+ controls: M,
2234
+ onClick: () => q("heading"),
2235
+ onKeyDown: (e) => J("heading", e),
2236
+ children: [
2237
+ /* @__PURE__ */ p("span", {
2238
+ className: "editor-toolbar-heading-label editor-toolbar-heading-label-full",
2239
+ children: Te
2240
+ }),
2241
+ /* @__PURE__ */ p("span", {
2242
+ className: "editor-toolbar-heading-label editor-toolbar-heading-label-compact",
2243
+ "aria-hidden": "true",
2244
+ children: Ee
2245
+ }),
2246
+ /* @__PURE__ */ p(X, {
2247
+ name: "chevron",
2248
+ className: "editor-toolbar-chevron"
2249
+ })
2250
+ ]
2251
+ }), y === "heading" ? /* @__PURE__ */ p("div", {
2252
+ id: M,
2253
+ ref: _,
2254
+ className: "editor-toolbar-popover editor-toolbar-heading-menu",
2255
+ role: "menu",
2256
+ "aria-label": L.headingMenuLabel,
2257
+ style: D ?? void 0,
2258
+ onKeyDown: (e) => rt(e, _.current),
2259
+ children: z.map((e) => /* @__PURE__ */ m("button", {
2260
+ type: "button",
2261
+ role: "menuitemradio",
2262
+ "aria-checked": T.headingLevel === e.level,
2263
+ tabIndex: -1,
2264
+ className: "editor-toolbar-menu-item editor-toolbar-heading-item",
2265
+ onMouseDown: Z,
2266
+ onClick: () => me(e.level),
2267
+ children: [/* @__PURE__ */ p("span", {
2268
+ className: `editor-toolbar-heading-sample is-level-${e.level}`,
2269
+ "aria-hidden": "true",
2270
+ children: e.sample
2271
+ }), /* @__PURE__ */ p("span", { children: e.label })]
2272
+ }, e.level))
2273
+ }) : null]
2274
+ }),
2275
+ /* @__PURE__ */ p(Q, {
2276
+ toolbarId: "bold",
2277
+ label: L.bold,
2278
+ tabStop: x === "bold",
2279
+ onFocus: () => S("bold"),
2280
+ disabled: h,
2281
+ onClick: () => K(A),
2282
+ pressed: T.bold,
2283
+ active: T.bold,
2284
+ children: /* @__PURE__ */ p("span", {
2285
+ className: "editor-toolbar-glyph is-bold",
2286
+ "aria-hidden": "true",
2287
+ children: "B"
2288
+ })
2289
+ }),
2290
+ /* @__PURE__ */ p(Q, {
2291
+ toolbarId: "italic",
2292
+ label: L.italic,
2293
+ tabStop: x === "italic",
2294
+ onFocus: () => S("italic"),
2295
+ disabled: h,
2296
+ onClick: () => K(se),
2297
+ pressed: T.italic,
2298
+ active: T.italic,
2299
+ children: /* @__PURE__ */ p("span", {
2300
+ className: "editor-toolbar-glyph is-italic",
2301
+ "aria-hidden": "true",
2302
+ children: "I"
2303
+ })
2304
+ }),
2305
+ /* @__PURE__ */ m("div", {
2306
+ className: "editor-toolbar-slot",
2307
+ children: [/* @__PURE__ */ m(Q, {
2308
+ toolbarId: "list",
2309
+ label: Oe,
2310
+ className: "editor-toolbar-list-trigger",
2311
+ tabStop: x === "list",
2312
+ onFocus: () => S("list"),
2313
+ disabled: h,
2314
+ popup: "menu",
2315
+ expanded: y === "list",
2316
+ controls: N,
2317
+ active: T.list !== null,
2318
+ onClick: () => q("list"),
2319
+ onKeyDown: (e) => J("list", e),
2320
+ children: [/* @__PURE__ */ p(X, { name: ke }), /* @__PURE__ */ p(X, {
2321
+ name: "chevron",
2322
+ className: "editor-toolbar-chevron"
2323
+ })]
2324
+ }), y === "list" ? /* @__PURE__ */ m("div", {
2325
+ id: N,
2326
+ ref: _,
2327
+ className: "editor-toolbar-popover editor-toolbar-list-menu",
2328
+ role: "menu",
2329
+ "aria-label": L.listMenuLabel,
2330
+ style: D ?? void 0,
2331
+ onKeyDown: (e) => rt(e, _.current),
2332
+ children: [
2333
+ B.map((e) => /* @__PURE__ */ m("button", {
2334
+ type: "button",
2335
+ role: "menuitemradio",
2336
+ "aria-checked": T.list === e.type,
2337
+ tabIndex: -1,
2338
+ className: "editor-toolbar-menu-item editor-toolbar-list-item",
2339
+ onMouseDown: Z,
2340
+ onClick: () => K(e.command),
2341
+ children: [/* @__PURE__ */ p(X, {
2342
+ name: e.icon,
2343
+ className: "editor-toolbar-menu-icon"
2344
+ }), /* @__PURE__ */ p("span", { children: e.label })]
2345
+ }, e.type)),
2346
+ /* @__PURE__ */ p("div", {
2347
+ className: "editor-toolbar-menu-divider",
2348
+ role: "separator"
2349
+ }),
2350
+ V.map((e) => /* @__PURE__ */ m("button", {
2351
+ type: "button",
2352
+ role: "menuitem",
2353
+ tabIndex: -1,
2354
+ className: "editor-toolbar-menu-item editor-toolbar-list-item",
2355
+ onMouseDown: Z,
2356
+ onClick: () => K(e.command),
2357
+ children: [/* @__PURE__ */ p(X, {
2358
+ name: e.icon,
2359
+ className: "editor-toolbar-menu-icon"
2360
+ }), /* @__PURE__ */ p("span", { children: e.label })]
2361
+ }, e.labelKey))
2362
+ ]
2363
+ }) : null]
2364
+ }),
2365
+ /* @__PURE__ */ p(Q, {
2366
+ toolbarId: "link",
2367
+ label: L.insertLink,
2368
+ className: "editor-toolbar-desktop-only",
2369
+ tabStop: x === "link",
2370
+ onFocus: () => S("link"),
2371
+ disabled: h,
2372
+ onClick: () => K(pe),
2373
+ children: /* @__PURE__ */ p(X, { name: "link" })
2374
+ }),
2375
+ /* @__PURE__ */ m("div", {
2376
+ className: "editor-toolbar-slot",
2377
+ children: [
2378
+ /* @__PURE__ */ m(Q, {
2379
+ toolbarId: "insert",
2380
+ label: L.insert,
2381
+ className: "editor-toolbar-insert-trigger",
2382
+ tabStop: x === "insert",
2383
+ onFocus: () => S("insert"),
2384
+ disabled: h,
2385
+ popup: "menu",
2386
+ expanded: y === "insert" || y === "emoji",
2387
+ controls: y === "emoji" ? j : ce,
2388
+ onClick: () => q("insert"),
2389
+ onKeyDown: (e) => J("insert", e),
2390
+ children: [
2391
+ /* @__PURE__ */ p(X, { name: "plus" }),
2392
+ /* @__PURE__ */ p("span", {
2393
+ className: "editor-toolbar-insert-label",
2394
+ children: L.insert
2395
+ }),
2396
+ /* @__PURE__ */ p(X, {
2397
+ name: "chevron",
2398
+ className: "editor-toolbar-chevron"
2399
+ })
2400
+ ]
2401
+ }),
2402
+ y === "insert" ? /* @__PURE__ */ m("div", {
2403
+ id: ce,
2404
+ ref: _,
2405
+ className: "editor-toolbar-popover editor-toolbar-insert-menu",
2406
+ role: "menu",
2407
+ "aria-label": L.insertMenuLabel,
2408
+ style: D ?? void 0,
2409
+ onKeyDown: (e) => rt(e, _.current),
2410
+ children: [H.map((e) => /* @__PURE__ */ m("button", {
2411
+ type: "button",
2412
+ role: "menuitem",
2413
+ tabIndex: -1,
2414
+ className: "editor-toolbar-menu-item editor-toolbar-insert-item",
2415
+ onMouseDown: Z,
2416
+ onClick: () => K(e.command),
2417
+ children: [/* @__PURE__ */ p(X, {
2418
+ name: e.icon,
2419
+ className: "editor-toolbar-menu-icon"
2420
+ }), /* @__PURE__ */ p("span", { children: e.label })]
2421
+ }, e.labelKey)), /* @__PURE__ */ m("button", {
2422
+ type: "button",
2423
+ role: "menuitem",
2424
+ tabIndex: -1,
2425
+ className: "editor-toolbar-menu-item editor-toolbar-insert-item",
2426
+ onMouseDown: Z,
2427
+ onClick: () => b("emoji"),
2428
+ children: [/* @__PURE__ */ p(X, {
2429
+ name: "smile",
2430
+ className: "editor-toolbar-menu-icon"
2431
+ }), /* @__PURE__ */ p("span", { children: L.emoji })]
2432
+ })]
2433
+ }) : null,
2434
+ y === "emoji" ? /* @__PURE__ */ p("div", {
2435
+ id: j,
2436
+ ref: _,
2437
+ className: "editor-toolbar-popover editor-toolbar-emoji-menu",
2438
+ role: "menu",
2439
+ "aria-label": L.insertEmojiMenuLabel,
2440
+ onKeyDown: (e) => it(e, re.current),
2441
+ children: /* @__PURE__ */ p("div", {
2442
+ className: "editor-toolbar-emoji-grid",
2443
+ ref: re,
2444
+ children: We.map((e) => /* @__PURE__ */ p("button", {
2445
+ type: "button",
2446
+ role: "menuitem",
2447
+ tabIndex: -1,
2448
+ className: "editor-toolbar-emoji",
2449
+ "aria-label": L.insertEmojiLabel(e),
2450
+ onMouseDown: Z,
2451
+ onClick: () => he(e),
2452
+ children: e
2453
+ }, e))
2454
+ })
2455
+ }) : null
2456
+ ]
2457
+ }),
2458
+ /* @__PURE__ */ m("div", {
2459
+ className: "editor-toolbar-slot editor-toolbar-slot-native",
2460
+ children: [/* @__PURE__ */ m(Q, {
2461
+ toolbarId: "components",
2462
+ label: L.componentsTriggerLabel,
2463
+ className: "editor-toolbar-components-trigger",
2464
+ tabStop: x === "components",
2465
+ onFocus: () => S("components"),
2466
+ disabled: h,
2467
+ popup: "dialog",
2468
+ expanded: y === "native",
2469
+ controls: P,
2470
+ onClick: () => q("native"),
2471
+ onKeyDown: (e) => J("native", e),
2472
+ children: [
2473
+ /* @__PURE__ */ p(X, { name: "sparkle" }),
2474
+ /* @__PURE__ */ p("span", {
2475
+ className: "editor-toolbar-components-label editor-toolbar-components-label-full",
2476
+ children: L.componentsLabel
2477
+ }),
2478
+ /* @__PURE__ */ p("span", {
2479
+ className: "editor-toolbar-components-label editor-toolbar-components-label-compact",
2480
+ children: L.componentsCompactLabel
2481
+ })
2482
+ ]
2483
+ }), y === "native" ? /* @__PURE__ */ m("div", {
2484
+ id: P,
2485
+ ref: _,
2486
+ className: "editor-toolbar-popover editor-toolbar-native-menu",
2487
+ role: "dialog",
2488
+ "aria-label": L.nativeMenuLabel,
2489
+ onKeyDown: (e) => rt(e, _.current),
2490
+ children: [
2491
+ /* @__PURE__ */ m("div", {
2492
+ className: "editor-toolbar-native-head",
2493
+ children: [/* @__PURE__ */ p("span", {
2494
+ className: "editor-toolbar-native-title",
2495
+ children: L.nativeTitle
2496
+ }), /* @__PURE__ */ p("button", {
2497
+ type: "button",
2498
+ className: "editor-toolbar-close",
2499
+ "aria-label": L.closeNativeLabel,
2500
+ onMouseDown: Z,
2501
+ onClick: we,
2502
+ children: /* @__PURE__ */ p(X, { name: "close" })
2503
+ })]
2504
+ }),
2505
+ /* @__PURE__ */ m("div", {
2506
+ className: "editor-toolbar-search",
2507
+ children: [/* @__PURE__ */ p(X, {
2508
+ name: "search",
2509
+ className: "editor-toolbar-search-icon"
2510
+ }), /* @__PURE__ */ p("input", {
2511
+ ref: ne,
2512
+ type: "search",
2513
+ className: "editor-toolbar-search-input",
2514
+ value: C,
2515
+ placeholder: L.searchPlaceholder,
2516
+ "aria-label": L.searchLabel,
2517
+ autoComplete: "off",
2518
+ spellCheck: !1,
2519
+ onChange: (e) => w(e.target.value)
2520
+ })]
2521
+ }),
2522
+ /* @__PURE__ */ p("div", {
2523
+ className: "editor-toolbar-native-scroll",
2524
+ role: "menu",
2525
+ "aria-label": L.nativeListLabel,
2526
+ children: U.length === 0 ? /* @__PURE__ */ p("p", {
2527
+ className: "editor-toolbar-menu-empty",
2528
+ children: L.noMatchingComponents
2529
+ }) : U.map(({ group: e, components: t }) => /* @__PURE__ */ m("div", {
2530
+ className: "editor-toolbar-native-group",
2531
+ role: "group",
2532
+ "aria-label": e.label,
2533
+ children: [/* @__PURE__ */ p("div", {
2534
+ className: "editor-toolbar-native-group-title",
2535
+ "aria-hidden": "true",
2536
+ children: e.label
2537
+ }), t.map((e) => /* @__PURE__ */ m("button", {
2538
+ type: "button",
2539
+ role: "menuitem",
2540
+ tabIndex: -1,
2541
+ className: "editor-toolbar-native-item",
2542
+ onMouseDown: Z,
2543
+ onClick: () => ge(e),
2544
+ children: [/* @__PURE__ */ m("span", {
2545
+ className: "editor-toolbar-native-copy",
2546
+ children: [/* @__PURE__ */ m("span", {
2547
+ className: "editor-toolbar-native-label",
2548
+ children: [e.label, e.inline ? /* @__PURE__ */ p("span", {
2549
+ className: "editor-toolbar-native-badge",
2550
+ children: L.inlineBadge
2551
+ }) : null]
2552
+ }), /* @__PURE__ */ p("span", {
2553
+ className: "editor-toolbar-native-description",
2554
+ children: e.description
2555
+ })]
2556
+ }), /* @__PURE__ */ p(X, {
2557
+ name: "plus",
2558
+ className: "editor-toolbar-native-add"
2559
+ })]
2560
+ }, e.id))]
2561
+ }, e.id))
2562
+ })
2563
+ ]
2564
+ }) : null]
2565
+ }),
2566
+ /* @__PURE__ */ m("div", {
2567
+ className: "editor-toolbar-history",
2568
+ role: "group",
2569
+ "aria-label": L.historyLabel,
2570
+ children: [
2571
+ /* @__PURE__ */ p(Q, {
2572
+ toolbarId: "undo",
2573
+ label: L.undo,
2574
+ className: "editor-toolbar-desktop-only",
2575
+ tabStop: x === "undo",
2576
+ onFocus: () => S("undo"),
2577
+ disabled: h || !s,
2578
+ onClick: _e,
2579
+ children: /* @__PURE__ */ p(X, { name: "undo" })
2580
+ }),
2581
+ /* @__PURE__ */ p(Q, {
2582
+ toolbarId: "redo",
2583
+ label: L.redo,
2584
+ className: "editor-toolbar-desktop-only",
2585
+ tabStop: x === "redo",
2586
+ onFocus: () => S("redo"),
2587
+ disabled: h || !f,
2588
+ onClick: ve,
2589
+ children: /* @__PURE__ */ p(X, { name: "redo" })
2590
+ }),
2591
+ te ? /* @__PURE__ */ p(Q, {
2592
+ toolbarId: "download",
2593
+ label: L.download,
2594
+ className: "editor-toolbar-desktop-only",
2595
+ tabStop: x === "download",
2596
+ onFocus: () => S("download"),
2597
+ disabled: h,
2598
+ onClick: ye,
2599
+ children: /* @__PURE__ */ p(X, { name: "download" })
2600
+ }) : null,
2601
+ /* @__PURE__ */ m("div", {
2602
+ className: "editor-toolbar-slot editor-toolbar-mobile-only",
2603
+ children: [/* @__PURE__ */ p(Q, {
2604
+ toolbarId: "more",
2605
+ label: L.more,
2606
+ className: "editor-toolbar-more-trigger",
2607
+ tabStop: x === "more",
2608
+ onFocus: () => S("more"),
2609
+ disabled: h,
2610
+ popup: "menu",
2611
+ expanded: y === "more",
2612
+ controls: le,
2613
+ onClick: () => q("more"),
2614
+ onKeyDown: (e) => J("more", e),
2615
+ children: /* @__PURE__ */ p(X, { name: "more" })
2616
+ }), y === "more" ? /* @__PURE__ */ m("div", {
2617
+ id: le,
2618
+ ref: _,
2619
+ className: "editor-toolbar-popover editor-toolbar-more-menu",
2620
+ role: "menu",
2621
+ "aria-label": L.moreMenuLabel,
2622
+ style: D ?? void 0,
2623
+ onKeyDown: (e) => rt(e, _.current),
2624
+ children: [
2625
+ /* @__PURE__ */ m("button", {
2626
+ type: "button",
2627
+ role: "menuitem",
2628
+ tabIndex: -1,
2629
+ className: "editor-toolbar-menu-item editor-toolbar-more-item editor-toolbar-more-link",
2630
+ onMouseDown: Z,
2631
+ onClick: () => K(pe),
2632
+ children: [/* @__PURE__ */ p(X, {
2633
+ name: "link",
2634
+ className: "editor-toolbar-menu-icon"
2635
+ }), /* @__PURE__ */ p("span", { children: L.linkMenuItem })]
2636
+ }),
2637
+ /* @__PURE__ */ m("button", {
2638
+ type: "button",
2639
+ role: "menuitem",
2640
+ tabIndex: -1,
2641
+ className: "editor-toolbar-menu-item editor-toolbar-more-item",
2642
+ disabled: !s,
2643
+ onMouseDown: Z,
2644
+ onClick: _e,
2645
+ children: [/* @__PURE__ */ p(X, {
2646
+ name: "undo",
2647
+ className: "editor-toolbar-menu-icon"
2648
+ }), /* @__PURE__ */ p("span", { children: L.undo })]
2649
+ }),
2650
+ /* @__PURE__ */ m("button", {
2651
+ type: "button",
2652
+ role: "menuitem",
2653
+ tabIndex: -1,
2654
+ className: "editor-toolbar-menu-item editor-toolbar-more-item",
2655
+ disabled: !f,
2656
+ onMouseDown: Z,
2657
+ onClick: ve,
2658
+ children: [/* @__PURE__ */ p(X, {
2659
+ name: "redo",
2660
+ className: "editor-toolbar-menu-icon"
2661
+ }), /* @__PURE__ */ p("span", { children: L.redo })]
2662
+ }),
2663
+ te ? /* @__PURE__ */ m("button", {
2664
+ type: "button",
2665
+ role: "menuitem",
2666
+ tabIndex: -1,
2667
+ className: "editor-toolbar-menu-item editor-toolbar-more-item",
2668
+ onMouseDown: Z,
2669
+ onClick: ye,
2670
+ children: [/* @__PURE__ */ p(X, {
2671
+ name: "download",
2672
+ className: "editor-toolbar-menu-icon"
2673
+ }), /* @__PURE__ */ p("span", { children: L.download })]
2674
+ }) : null
2675
+ ]
2676
+ }) : null]
2677
+ })
2678
+ ]
2679
+ })
2680
+ ]
2681
+ });
2682
+ }
2683
+ // src/editor/editor-view-bar.tsx
2684
+ function ot({ source: e, mode: t, onModeChange: n, sourceId: r, previewId: i, hasPreview: a, allowSplit: o, toolbar: s }) {
2685
+ let c = oe(), u = re[c], d = l(() => Array.from(e).length, [e]);
2686
+ return /* @__PURE__ */ m("div", {
2687
+ className: "editor-status-bar",
2688
+ role: "group",
2689
+ "aria-label": u.viewLabel,
2690
+ children: [
2691
+ /* @__PURE__ */ p("span", {
2692
+ className: "editor-status-count",
2693
+ children: u.count(d.toLocaleString(c))
2694
+ }),
2695
+ /* @__PURE__ */ p("span", {
2696
+ className: "editor-status-hint",
2697
+ children: t !== "preview" && s ? u.keyboardHint : ""
2698
+ }),
2699
+ a ? /* @__PURE__ */ p("div", {
2700
+ className: "editor-view-modes",
2701
+ children: [
2702
+ "edit",
2703
+ "split",
2704
+ "preview"
2705
+ ].filter((e) => e !== "split" || o).map((e) => /* @__PURE__ */ m("button", {
2706
+ type: "button",
2707
+ "data-editor-view-option": e,
2708
+ "aria-pressed": t === e,
2709
+ "aria-controls": e === "edit" ? r : e === "preview" ? i : `${r} ${i}`,
2710
+ onClick: () => n(e),
2711
+ children: [/* @__PURE__ */ p("svg", {
2712
+ viewBox: "0 0 24 24",
2713
+ width: "18",
2714
+ height: "18",
2715
+ fill: "none",
2716
+ stroke: "currentColor",
2717
+ strokeWidth: "1.7",
2718
+ strokeLinecap: "round",
2719
+ strokeLinejoin: "round",
2720
+ "aria-hidden": "true",
2721
+ children: e === "edit" ? /* @__PURE__ */ m(f, { children: [/* @__PURE__ */ p("path", { d: "m16 3 5 5-12 12-6 1 1-6Z" }), /* @__PURE__ */ p("path", { d: "m13 6 5 5" })] }) : e === "split" ? /* @__PURE__ */ m(f, { children: [/* @__PURE__ */ p("rect", {
2722
+ x: "3",
2723
+ y: "4",
2724
+ width: "18",
2725
+ height: "16",
2726
+ rx: "2"
2727
+ }), /* @__PURE__ */ p("path", { d: "M12 4v16" })] }) : /* @__PURE__ */ m(f, { children: [/* @__PURE__ */ p("path", { d: "M2 12s3.5-7 10-7 10 7 10 7-3.5 7-10 7S2 12 2 12Z" }), /* @__PURE__ */ p("circle", {
2728
+ cx: "12",
2729
+ cy: "12",
2730
+ r: "3"
2731
+ })] })
2732
+ }), /* @__PURE__ */ p("span", { children: u[e] })]
2733
+ }, e))
2734
+ }) : null
2735
+ ]
2736
+ });
2737
+ }
2738
+ // src/editor/source-authoring.tsx
2739
+ var st = {
2740
+ tokens: [],
2741
+ bindings: [],
2742
+ diagnostics: []
2743
+ }, ct = {
2744
+ tag: "tag",
2745
+ attribute: "attribute",
2746
+ string: "string",
2747
+ expression: "expression",
2748
+ binding: "binding",
2749
+ markdown: "markdown",
2750
+ math: "math",
2751
+ code: "code",
2752
+ comment: "comment"
2753
+ };
2754
+ function lt(e) {
2755
+ let t = e.toLowerCase();
2756
+ return ct[t] || (t.includes("tag") ? "tag" : t.includes("attr") ? "attribute" : t.includes("string") || t.includes("quote") ? "string" : t.includes("expr") || t.includes("interp") ? "expression" : t.includes("bind") ? "binding" : t.includes("math") || t.includes("latex") ? "math" : t.includes("code") || t.includes("fence") ? "code" : t.includes("comment") ? "comment" : t.includes("markdown") || t.includes("heading") || t.includes("emphasis") || t.includes("link") ? "markdown" : "plain");
2757
+ }
2758
+ function ut(e, t, n) {
2759
+ return Math.min(Math.max(e, t), n);
2760
+ }
2761
+ function dt(e, t) {
2762
+ let n = [], r = 0, i = [...t].sort((e, t) => e.range.start - t.range.start);
2763
+ for (let t of i) {
2764
+ let i = ut(Math.max(t.range.start, r), 0, e.length), a = ut(t.range.end, i, e.length);
2765
+ r = a, a > i && n.push({
2766
+ kind: t.kind,
2767
+ range: {
2768
+ start: i,
2769
+ end: a
2770
+ }
2771
+ });
2772
+ }
2773
+ return n;
2774
+ }
2775
+ function ft(e, t = !0) {
2776
+ return l(() => {
2777
+ if (!t) return st;
2778
+ try {
2779
+ let t = ee(e);
2780
+ return {
2781
+ tokens: dt(e, t.tokens),
2782
+ bindings: t.bindings,
2783
+ diagnostics: t.diagnostics
2784
+ };
2785
+ } catch {
2786
+ return st;
2787
+ }
2788
+ }, [e, t]);
2789
+ }
2790
+ function pt(e, t) {
2791
+ let n = [], r = 0;
2792
+ return t.forEach((t, i) => {
2793
+ t.range.start > r && n.push(e.slice(r, t.range.start)), n.push(/* @__PURE__ */ p("span", {
2794
+ className: `author-token author-token-${lt(t.kind)}`,
2795
+ "data-token-kind": t.kind,
2796
+ children: e.slice(t.range.start, t.range.end)
2797
+ }, `${i}-${t.range.start}`)), r = t.range.end;
2798
+ }), r < e.length && n.push(e.slice(r)), n;
2799
+ }
2800
+ var mt = n(function({ source: e, tokens: t, width: n, editorRef: r }) {
2801
+ let i = u(null);
2802
+ return a(() => {
2803
+ let e = r.current, t = i.current;
2804
+ if (!e || !t) return;
2805
+ let n = 0, a = 0, o = NaN, s = NaN, c = () => {
2806
+ let n = e.scrollTop, r = e.scrollLeft;
2807
+ (n !== o || r !== s) && (o = n, s = r, t.style.transform = `translate3d(${-r}px, ${-n}px, 0)`);
2808
+ }, l = () => {
2809
+ n = 0, c(), a !== 0 && (n = window.requestAnimationFrame(l));
2810
+ }, u = () => {
2811
+ c(), a !== 0 && window.clearTimeout(a), a = window.setTimeout(() => {
2812
+ a = 0, n !== 0 && (window.cancelAnimationFrame(n), n = 0);
2813
+ }, 1e3), n === 0 && (n = window.requestAnimationFrame(l));
2814
+ };
2815
+ c();
2816
+ let d = [
2817
+ "scroll",
2818
+ "wheel",
2819
+ "touchstart",
2820
+ "touchmove"
2821
+ ];
2822
+ for (let t of d) e.addEventListener(t, u, { passive: !0 });
2823
+ return () => {
2824
+ for (let t of d) e.removeEventListener(t, u);
2825
+ a !== 0 && window.clearTimeout(a), n !== 0 && window.cancelAnimationFrame(n);
2826
+ };
2827
+ }, [r]), /* @__PURE__ */ p("div", {
2828
+ className: "author-highlight",
2829
+ "aria-hidden": "true",
2830
+ style: n > 0 ? { width: `${n}px` } : void 0,
2831
+ children: /* @__PURE__ */ p("div", {
2832
+ className: "author-highlight-content",
2833
+ ref: i,
2834
+ children: pt(e, t)
2835
+ })
2836
+ });
2837
+ }), ht = {
2838
+ en: {
2839
+ region: "Source authoring tools",
2840
+ title: "Authoring",
2841
+ format: "Format",
2842
+ formatTitle: "Normalise spacing inside recognised Reactive MD tags",
2843
+ suggestions: "Suggest",
2844
+ suggestionsTitle: "Show tag, attribute and binding suggestions (Ctrl+Space)",
2845
+ completionLabel: "Source suggestions",
2846
+ completionEmpty: "No suggestions at this position.",
2847
+ completionCount: (e) => `${e} suggestion${e === 1 ? "" : "s"}`,
2848
+ kinds: {
2849
+ tag: "Tag",
2850
+ attribute: "Attribute",
2851
+ binding: "Binding",
2852
+ value: "Value"
2853
+ },
2854
+ bindingsLabel: "Bindings",
2855
+ noBindings: "No bindings in this source.",
2856
+ caretLabel: "At caret",
2857
+ noBindingAtCaret: "Caret is not on a binding.",
2858
+ declarationCount: (e) => `${e} declaration${e === 1 ? "" : "s"}`,
2859
+ referenceCount: (e) => `${e} reference${e === 1 ? "" : "s"}`,
2860
+ declaration: "Declaration",
2861
+ reference: "Reference",
2862
+ locateTitle: "Locate in editor",
2863
+ renameLabel: "Rename selected binding",
2864
+ renamePlaceholder: "New name",
2865
+ renameAction: "Rename",
2866
+ renameTitle: "Rename this binding everywhere it is declared or read",
2867
+ renameHint: "Updates declarations, expressions and plot parameters. Literal text and display formulas keep their source.",
2868
+ renameEmpty: "Enter a new name.",
2869
+ renameSame: "The new name is the current name.",
2870
+ renameDone: (e, t) => `Renamed ${e} to ${t}.`,
2871
+ renameFailed: (e) => `Rename failed: ${e}`,
2872
+ formatApplied: "Formatted as one undo step.",
2873
+ formatUnchanged: "The source is already formatted.",
2874
+ formatFailed: (e) => `Formatting failed: ${e}`,
2875
+ typeLabel: "Type",
2876
+ unknownType: "Unknown",
2877
+ typeNames: {
2878
+ string: "Text",
2879
+ number: "Number",
2880
+ boolean: "Boolean",
2881
+ array: "List",
2882
+ "number-array": "Number list",
2883
+ null: "Null"
2884
+ },
2885
+ position: (e, t) => `Line ${e}:${t}`
2886
+ },
2887
+ zh: {
2888
+ region: "源码作者工具",
2889
+ title: "作者工具",
2890
+ format: "格式化",
2891
+ formatTitle: "整理已识别 Reactive MD 标签内的空白",
2892
+ suggestions: "补全",
2893
+ suggestionsTitle: "显示标签、属性与绑定建议(Ctrl+Space)",
2894
+ completionLabel: "源码补全建议",
2895
+ completionEmpty: "当前位置没有补全建议。",
2896
+ completionCount: (e) => `${e} 条建议`,
2897
+ kinds: {
2898
+ tag: "标签",
2899
+ attribute: "属性",
2900
+ binding: "绑定",
2901
+ value: "值"
2902
+ },
2903
+ bindingsLabel: "绑定",
2904
+ noBindings: "源码中没有绑定。",
2905
+ caretLabel: "光标位置",
2906
+ noBindingAtCaret: "光标不在绑定上。",
2907
+ declarationCount: (e) => `${e} 处声明`,
2908
+ referenceCount: (e) => `${e} 处引用`,
2909
+ declaration: "声明",
2910
+ reference: "引用",
2911
+ locateTitle: "在编辑器中定位",
2912
+ renameLabel: "重命名选中绑定",
2913
+ renamePlaceholder: "新名称",
2914
+ renameAction: "重命名",
2915
+ renameTitle: "重命名所有声明与引用位置",
2916
+ renameHint: "修改绑定声明、表达式引用与绘图参数,保留普通文字和展示公式。",
2917
+ renameEmpty: "请输入新名称。",
2918
+ renameSame: "新名称与当前名称相同。",
2919
+ renameDone: (e, t) => `已将 ${e} 重命名为 ${t}。`,
2920
+ renameFailed: (e) => `重命名失败:${e}`,
2921
+ formatApplied: "已格式化,可一步撤销。",
2922
+ formatUnchanged: "源码无需格式化。",
2923
+ formatFailed: (e) => `格式化失败:${e}`,
2924
+ typeLabel: "类型",
2925
+ unknownType: "未知",
2926
+ typeNames: {
2927
+ string: "文本",
2928
+ number: "数字",
2929
+ boolean: "布尔值",
2930
+ array: "列表",
2931
+ "number-array": "数字列表",
2932
+ null: "空值"
2933
+ },
2934
+ position: (e, t) => `第 ${e} 行 ${t} 列`
2935
+ }
2936
+ };
2937
+ function gt(e, t) {
2938
+ return t >= e.start && t <= e.end;
2939
+ }
2940
+ function _t(e) {
2941
+ return e.end - e.start;
2942
+ }
2943
+ function vt(e, t) {
2944
+ let n = null, r = Infinity, i = (e, i, a) => {
2945
+ if (!gt(i, t)) return;
2946
+ let o = _t(i);
2947
+ o >= r || (n = {
2948
+ binding: e,
2949
+ role: a
2950
+ }, r = o);
2951
+ };
2952
+ for (let t of e) {
2953
+ for (let e of t.declarations) i(t, e, "declaration");
2954
+ for (let e of t.references) i(t, e, "reference");
2955
+ }
2956
+ return n;
2957
+ }
2958
+ function yt(e) {
2959
+ let t = e.current;
2960
+ if (!t) return {
2961
+ start: 0,
2962
+ end: 0
2963
+ };
2964
+ let n = t.value.length, r = ut(t.selectionStart, 0, n);
2965
+ return {
2966
+ start: r,
2967
+ end: ut(t.selectionEnd, r, n)
2968
+ };
2969
+ }
2970
+ function bt(e, t) {
2971
+ let n = Math.min(e.length, t.length), r = 0;
2972
+ for (; r < n && e[r] === t[r];) r += 1;
2973
+ return r;
2974
+ }
2975
+ function xt(e, t, n) {
2976
+ let r = Math.min(e.length, t.length) - n, i = 0;
2977
+ for (; i < r && e[e.length - 1 - i] === t[t.length - 1 - i];) i += 1;
2978
+ return i;
2979
+ }
2980
+ function St(e, t, n) {
2981
+ let r = ut(n, 0, e.length), i = bt(e, t);
2982
+ if (r <= i) return r;
2983
+ let a = xt(e, t, i), o = e.length - a;
2984
+ if (r >= o) return t.length - a + (r - o);
2985
+ let s = o - i, c = t.length - a - i;
2986
+ if (s <= 0) return t.length - a;
2987
+ let l = (r - i) / s;
2988
+ return Math.round(i + l * c);
2989
+ }
2990
+ function Ct(e, t) {
2991
+ let n = 0;
2992
+ for (let r of [...t].sort((e, t) => e.range.start - t.range.start)) {
2993
+ if (e < r.range.start) break;
2994
+ if (e > r.range.end) n += r.text.length - _t(r.range);
2995
+ else return r.range.start + n + Math.min(e - r.range.start, r.text.length);
2996
+ }
2997
+ return e + n;
2998
+ }
2999
+ function wt(e) {
3000
+ e.preventDefault();
3001
+ }
3002
+ function Tt(e) {
3003
+ return e.isComposing === !0 || e.keyCode === 229;
3004
+ }
3005
+ function Et(e, t) {
3006
+ let n = ut(t, 0, e.length), r = e.lastIndexOf("\n", n - 1) + 1;
3007
+ return {
3008
+ line: e.slice(0, n).split("\n").length,
3009
+ column: n - r + 1
3010
+ };
3011
+ }
3012
+ function Dt({ source: e, analysis: t, bindingDocument: n, editorRef: i, onEdit: s, onLocate: c, disabled: f = !1 }) {
3013
+ let ee = oe(), _ = ht[ee], ne = o(), re = o(), ie = u(null), ae = u(null), [v, y] = d(0), [b, x] = d(null), [S, C] = d(""), [w, T] = d(null), [E, D] = d(null), [O, k] = d(!1), [A, se] = d([]), [j, M] = d(0), N = u(O), ce = u(A), le = u(j);
3014
+ N.current = O, ce.current = A, le.current = j, a(() => {
3015
+ let e = i.current;
3016
+ if (!e) return;
3017
+ let t = () => y(e.selectionStart);
3018
+ t();
3019
+ let n = [
3020
+ "select",
3021
+ "keyup",
3022
+ "click",
3023
+ "input",
3024
+ "focus"
3025
+ ];
3026
+ for (let r of n) e.addEventListener(r, t);
3027
+ return () => {
3028
+ for (let r of n) e.removeEventListener(r, t);
3029
+ };
3030
+ }, [i]), a(() => {
3031
+ k(!1);
3032
+ }, [e]), a(() => {
3033
+ D(null), T(null);
3034
+ }, [ee]);
3035
+ let P = l(() => vt(t.bindings, v), [t.bindings, v]);
3036
+ a(() => {
3037
+ P && x(P.binding.name);
3038
+ }, [P]);
3039
+ let F = l(() => (b ? t.bindings.find((e) => e.name === b) : void 0) ?? t.bindings[0] ?? null, [t.bindings, b]);
3040
+ a(() => {
3041
+ C(""), T(null);
3042
+ }, [F?.name]);
3043
+ let I = F && n ? n.bindings[F.name]?.type ?? n.computations?.[F.name]?.type : void 0, L = P && n ? n.bindings[P.binding.name]?.type ?? n.computations?.[P.binding.name]?.type : void 0, R = L ? _.typeNames[L] ?? L : _.unknownType, z = I ? _.typeNames[I] ?? I : _.unknownType, B = r(() => {
3044
+ if (f) return;
3045
+ let t = i.current, n = ut(t?.selectionStart ?? 0, 0, e.length), r = [];
3046
+ try {
3047
+ r = te(e, n) ?? [];
3048
+ } catch {
3049
+ r = [];
3050
+ }
3051
+ se(r), M(0), k(!0), D(null);
3052
+ }, [
3053
+ f,
3054
+ i,
3055
+ e
3056
+ ]), V = r((t) => {
3057
+ if (f) return;
3058
+ let n = ut(t.range.start, 0, e.length), r = ut(t.range.end, n, e.length), i = e.slice(0, n) + t.insertText + e.slice(r), a = n + t.insertText.length;
3059
+ k(!1), s({
3060
+ value: i,
3061
+ selection: {
3062
+ start: a,
3063
+ end: a
3064
+ }
3065
+ });
3066
+ }, [
3067
+ f,
3068
+ s,
3069
+ e
3070
+ ]);
3071
+ a(() => {
3072
+ let e = i.current;
3073
+ if (!e) return;
3074
+ let t = (e) => {
3075
+ if (Tt(e)) return;
3076
+ if (f) {
3077
+ N.current && k(!1);
3078
+ return;
3079
+ }
3080
+ let t = e.key;
3081
+ if ((e.ctrlKey || e.metaKey) && !e.altKey && (t === " " || t === "Spacebar")) e.preventDefault(), e.stopPropagation(), B();
3082
+ else if (N.current) {
3083
+ if (t === "ArrowDown" || t === "ArrowUp") {
3084
+ e.preventDefault(), e.stopPropagation();
3085
+ let n = ce.current.length;
3086
+ M((e) => n === 0 ? 0 : (e + (t === "ArrowDown" ? 1 : -1) + n) % n);
3087
+ } else if (t === "Enter") {
3088
+ e.preventDefault(), e.stopPropagation();
3089
+ let t = ce.current[le.current];
3090
+ t ? V(t) : k(!1);
3091
+ } else t === "Escape" && (e.preventDefault(), e.stopPropagation(), k(!1));
3092
+ }
3093
+ };
3094
+ return e.addEventListener("keydown", t, !0), () => e.removeEventListener("keydown", t, !0);
3095
+ }, [
3096
+ V,
3097
+ f,
3098
+ i,
3099
+ B
3100
+ ]), a(() => {
3101
+ if (!O) return;
3102
+ let e = (e) => {
3103
+ ie.current?.contains(e.target) || k(!1);
3104
+ }, t = (e) => {
3105
+ e.key === "Escape" && !Tt(e) && k(!1);
3106
+ };
3107
+ return document.addEventListener("pointerdown", e, !0), document.addEventListener("keydown", t, !0), () => {
3108
+ document.removeEventListener("pointerdown", e, !0), document.removeEventListener("keydown", t, !0);
3109
+ };
3110
+ }, [O]), a(() => {
3111
+ O && ae.current?.querySelector(`[data-completion-index="${j}"]`)?.scrollIntoView({ block: "nearest" });
3112
+ }, [j, O]);
3113
+ let H = () => {
3114
+ if (f) return;
3115
+ let t;
3116
+ try {
3117
+ t = h(e);
3118
+ } catch (e) {
3119
+ D(_.formatFailed(e instanceof Error ? e.message : String(e)));
3120
+ return;
3121
+ }
3122
+ if (t === e) {
3123
+ D(_.formatUnchanged);
3124
+ return;
3125
+ }
3126
+ let n = yt(i);
3127
+ s({
3128
+ value: t,
3129
+ selection: {
3130
+ start: St(e, t, n.start),
3131
+ end: St(e, t, n.end)
3132
+ }
3133
+ }), D(_.formatApplied);
3134
+ }, U = () => {
3135
+ if (f || !F) return;
3136
+ let t = S.trim();
3137
+ if (!t) T(_.renameEmpty);
3138
+ else if (t === F.name) T(_.renameSame);
3139
+ else try {
3140
+ let n = g(e, F.name, t), r = yt(i);
3141
+ s({
3142
+ value: n.source,
3143
+ selection: {
3144
+ start: Ct(r.start, n.edits),
3145
+ end: Ct(r.end, n.edits)
3146
+ }
3147
+ }), x(t), C(""), T(null), D(_.renameDone(F.name, t));
3148
+ } catch (e) {
3149
+ T(_.renameFailed(e instanceof Error ? e.message : String(e)));
3150
+ }
3151
+ }, W = A[j], ue = F ? [...F.declarations.map((e, t) => ({
3152
+ range: e,
3153
+ role: "declaration",
3154
+ index: t
3155
+ })), ...F.references.map((e, t) => ({
3156
+ range: e,
3157
+ role: "reference",
3158
+ index: t
3159
+ }))] : [];
3160
+ return /* @__PURE__ */ m("section", {
3161
+ className: "source-authoring",
3162
+ "aria-label": _.region,
3163
+ ref: ie,
3164
+ children: [
3165
+ /* @__PURE__ */ m("div", {
3166
+ className: "authoring-bar",
3167
+ children: [/* @__PURE__ */ p("span", {
3168
+ className: "authoring-title",
3169
+ children: _.title
3170
+ }), /* @__PURE__ */ m("div", {
3171
+ className: "authoring-actions",
3172
+ children: [/* @__PURE__ */ p("button", {
3173
+ type: "button",
3174
+ className: "authoring-button",
3175
+ "data-authoring-action": "format",
3176
+ title: _.formatTitle,
3177
+ disabled: f,
3178
+ onMouseDown: wt,
3179
+ onClick: H,
3180
+ children: _.format
3181
+ }), /* @__PURE__ */ p("button", {
3182
+ type: "button",
3183
+ className: "authoring-button",
3184
+ "data-authoring-action": "suggest",
3185
+ title: _.suggestionsTitle,
3186
+ "aria-expanded": O,
3187
+ "aria-controls": re,
3188
+ disabled: f,
3189
+ onMouseDown: wt,
3190
+ onClick: B,
3191
+ children: _.suggestions
3192
+ })]
3193
+ })]
3194
+ }),
3195
+ O ? /* @__PURE__ */ m("div", {
3196
+ className: "authoring-completion",
3197
+ "aria-label": _.completionLabel,
3198
+ children: [
3199
+ /* @__PURE__ */ m("div", {
3200
+ className: "authoring-completion-head",
3201
+ children: [/* @__PURE__ */ p("span", { children: _.completionLabel }), /* @__PURE__ */ p("span", {
3202
+ className: "authoring-completion-count",
3203
+ children: _.completionCount(A.length)
3204
+ })]
3205
+ }),
3206
+ /* @__PURE__ */ p("div", {
3207
+ id: re,
3208
+ className: "authoring-completion-list",
3209
+ role: "listbox",
3210
+ "aria-label": _.completionLabel,
3211
+ ref: ae,
3212
+ children: A.length === 0 ? /* @__PURE__ */ p("p", {
3213
+ className: "authoring-empty",
3214
+ children: _.completionEmpty
3215
+ }) : A.map((e, t) => /* @__PURE__ */ m("button", {
3216
+ type: "button",
3217
+ role: "option",
3218
+ "data-completion-index": t,
3219
+ "aria-selected": t === j,
3220
+ className: `authoring-completion-item${t === j ? " is-active" : ""}`,
3221
+ onMouseDown: wt,
3222
+ onMouseEnter: () => M(t),
3223
+ onClick: () => V(e),
3224
+ children: [
3225
+ /* @__PURE__ */ p("span", {
3226
+ className: `authoring-kind is-${e.kind}`,
3227
+ children: _.kinds[e.kind] ?? e.kind
3228
+ }),
3229
+ /* @__PURE__ */ p("span", {
3230
+ className: "authoring-completion-label",
3231
+ children: e.label
3232
+ }),
3233
+ e.detail ? /* @__PURE__ */ p("span", {
3234
+ className: "authoring-completion-detail",
3235
+ children: e.detail
3236
+ }) : null
3237
+ ]
3238
+ }, `${e.kind}-${e.range.start}-${e.range.end}-${t}`))
3239
+ }),
3240
+ /* @__PURE__ */ p("p", {
3241
+ className: "reactive-md-editor-sr-only",
3242
+ "aria-live": "polite",
3243
+ children: W ? `${_.kinds[W.kind] ?? W.kind} ${W.label}` : ""
3244
+ })
3245
+ ]
3246
+ }) : null,
3247
+ /* @__PURE__ */ m("div", {
3248
+ className: "authoring-body",
3249
+ children: [
3250
+ /* @__PURE__ */ m("p", {
3251
+ className: "authoring-caret",
3252
+ "data-binding-caret": P?.binding.name ?? "",
3253
+ children: [/* @__PURE__ */ p("span", {
3254
+ className: "authoring-label",
3255
+ children: _.caretLabel
3256
+ }), P ? /* @__PURE__ */ m("span", {
3257
+ className: "authoring-caret-value",
3258
+ children: [
3259
+ /* @__PURE__ */ p("strong", { children: P.binding.name }),
3260
+ /* @__PURE__ */ m("span", {
3261
+ className: "authoring-type",
3262
+ children: [
3263
+ _.typeLabel,
3264
+ ": ",
3265
+ R
3266
+ ]
3267
+ }),
3268
+ /* @__PURE__ */ p("span", { children: _.declarationCount(P.binding.declarations.length) }),
3269
+ /* @__PURE__ */ p("span", { children: _.referenceCount(P.binding.references.length) })
3270
+ ]
3271
+ }) : /* @__PURE__ */ p("span", {
3272
+ className: "authoring-muted",
3273
+ children: _.noBindingAtCaret
3274
+ })]
3275
+ }),
3276
+ /* @__PURE__ */ m("div", {
3277
+ className: "authoring-row",
3278
+ children: [/* @__PURE__ */ p("span", {
3279
+ className: "authoring-label",
3280
+ children: _.bindingsLabel
3281
+ }), /* @__PURE__ */ p("div", {
3282
+ className: "authoring-binding-list",
3283
+ children: t.bindings.length === 0 ? /* @__PURE__ */ p("span", {
3284
+ className: "authoring-muted",
3285
+ children: _.noBindings
3286
+ }) : t.bindings.map((e) => /* @__PURE__ */ m("button", {
3287
+ type: "button",
3288
+ "data-binding-name": e.name,
3289
+ className: "authoring-binding-chip",
3290
+ "aria-pressed": e.name === F?.name,
3291
+ title: `${_.declarationCount(e.declarations.length)} · ${_.referenceCount(e.references.length)}`,
3292
+ onClick: () => {
3293
+ x(e.name), D(null);
3294
+ },
3295
+ children: [/* @__PURE__ */ p("span", { children: e.name }), /* @__PURE__ */ m("span", {
3296
+ className: "authoring-binding-count",
3297
+ children: [
3298
+ e.declarations.length,
3299
+ "/",
3300
+ e.references.length
3301
+ ]
3302
+ })]
3303
+ }, e.name))
3304
+ })]
3305
+ }),
3306
+ F ? /* @__PURE__ */ m("div", {
3307
+ className: "authoring-row",
3308
+ children: [/* @__PURE__ */ m("span", {
3309
+ className: "authoring-label",
3310
+ children: [
3311
+ F.name,
3312
+ " · ",
3313
+ _.typeLabel,
3314
+ ": ",
3315
+ z
3316
+ ]
3317
+ }), /* @__PURE__ */ p("div", {
3318
+ className: "authoring-locations",
3319
+ children: ue.map(({ range: t, role: n, index: r }) => {
3320
+ let i = Et(e, t.start);
3321
+ return /* @__PURE__ */ m("button", {
3322
+ type: "button",
3323
+ className: `authoring-location is-${n}`,
3324
+ "data-binding-location": n,
3325
+ "data-start": t.start,
3326
+ "data-end": t.end,
3327
+ title: _.locateTitle,
3328
+ onClick: () => {
3329
+ x(F.name), c(t);
3330
+ },
3331
+ children: [/* @__PURE__ */ m("span", { children: [
3332
+ n === "declaration" ? _.declaration : _.reference,
3333
+ " ",
3334
+ r + 1
3335
+ ] }), /* @__PURE__ */ p("span", {
3336
+ className: "authoring-location-position",
3337
+ children: _.position(i.line, i.column)
3338
+ })]
3339
+ }, `${n}-${t.start}-${t.end}`);
3340
+ })
3341
+ })]
3342
+ }) : null,
3343
+ /* @__PURE__ */ m("div", {
3344
+ className: "authoring-rename",
3345
+ children: [
3346
+ /* @__PURE__ */ p("label", {
3347
+ className: "authoring-label",
3348
+ htmlFor: ne,
3349
+ children: _.renameLabel
3350
+ }),
3351
+ /* @__PURE__ */ m("div", {
3352
+ className: "authoring-rename-row",
3353
+ children: [/* @__PURE__ */ p("input", {
3354
+ id: ne,
3355
+ type: "text",
3356
+ className: "authoring-rename-input",
3357
+ "data-authoring-action": "rename-input",
3358
+ value: S,
3359
+ placeholder: _.renamePlaceholder,
3360
+ autoComplete: "off",
3361
+ spellCheck: !1,
3362
+ disabled: f || !F,
3363
+ onChange: (e) => {
3364
+ C(e.target.value), T(null);
3365
+ },
3366
+ onKeyDown: (e) => {
3367
+ e.key === "Enter" && Tt(e.nativeEvent) && e.preventDefault();
3368
+ }
3369
+ }), /* @__PURE__ */ p("button", {
3370
+ type: "button",
3371
+ className: "authoring-button authoring-primary",
3372
+ "data-authoring-action": "rename",
3373
+ disabled: f || !F,
3374
+ onMouseDown: wt,
3375
+ onClick: U,
3376
+ title: _.renameTitle,
3377
+ children: _.renameAction
3378
+ })]
3379
+ }),
3380
+ w ? /* @__PURE__ */ p("p", {
3381
+ className: "authoring-error",
3382
+ role: "alert",
3383
+ children: w
3384
+ }) : null,
3385
+ /* @__PURE__ */ p("p", {
3386
+ className: "authoring-hint",
3387
+ children: _.renameHint
3388
+ })
3389
+ ]
3390
+ }),
3391
+ E ? /* @__PURE__ */ p("p", {
3392
+ className: "authoring-status",
3393
+ "data-authoring-status": "true",
3394
+ role: "status",
3395
+ children: E
3396
+ }) : null
3397
+ ]
3398
+ })
3399
+ ]
3400
+ });
3401
+ }
3402
+ // src/editor/use-gutter-metrics.ts
3403
+ function Ot(e, t) {
3404
+ return e.length === t.length && e.every((e, n) => Math.abs(e - t[n]) < .01);
3405
+ }
3406
+ function kt(e, t, n) {
3407
+ let [r, i] = d(0), [o, s] = d([]), [l, u] = d(0);
3408
+ return c(() => {
3409
+ let e = n.current;
3410
+ if (!e) return;
3411
+ let t = () => i(e.clientWidth);
3412
+ t();
3413
+ let r = new ResizeObserver(t);
3414
+ return r.observe(e), () => r.disconnect();
3415
+ }, [n]), a(() => {
3416
+ let e = !1;
3417
+ return document.fonts?.ready.then(() => {
3418
+ e || u((e) => e + 1);
3419
+ }).catch(() => {}), () => {
3420
+ e = !0;
3421
+ };
3422
+ }, []), c(() => {
3423
+ let n = t.current;
3424
+ if (!n || r === 0) return;
3425
+ let i = Array.from(n.children);
3426
+ if (i.length !== e.length) return;
3427
+ let a = Number.parseFloat(window.getComputedStyle(n).lineHeight) || 22, o = i.map((e) => e.getBoundingClientRect().height || a);
3428
+ s((e) => Ot(e, o) ? e : o);
3429
+ }, [
3430
+ e,
3431
+ r,
3432
+ l,
3433
+ t
3434
+ ]), {
3435
+ width: r,
3436
+ heights: o
3437
+ };
3438
+ }
3439
+ // src/editor/use-source-history.ts
3440
+ var At = 700, jt = 120, Mt = {
3441
+ start: 0,
3442
+ end: 0
3443
+ };
3444
+ function Nt(e, t = Mt, n = Date.now) {
3445
+ let r = [{
3446
+ value: e,
3447
+ selection: t
3448
+ }], i = 0, a = 0, o = !1;
3449
+ return {
3450
+ get canUndo() {
3451
+ return i > 0;
3452
+ },
3453
+ get canRedo() {
3454
+ return i < r.length - 1;
3455
+ },
3456
+ record: (e, t, s = "merge") => {
3457
+ let c = r[i];
3458
+ if (e === c.value && t.start === c.selection.start && t.end === c.selection.end) return;
3459
+ let l = n();
3460
+ s === "merge" && o && i > 0 && i === r.length - 1 && l - a < At ? r[i] = {
3461
+ value: e,
3462
+ selection: t
3463
+ } : (r = r.slice(0, i + 1), r.push({
3464
+ value: e,
3465
+ selection: t
3466
+ }), r.length > jt && r.shift(), i = r.length - 1), a = l, o = s === "merge";
3467
+ },
3468
+ undo: () => i <= 0 ? null : (--i, a = 0, o = !1, r[i]),
3469
+ redo: () => i >= r.length - 1 ? null : (i += 1, a = 0, o = !1, r[i]),
3470
+ reset: (e, t = Mt) => {
3471
+ r = [{
3472
+ value: e,
3473
+ selection: t
3474
+ }], i = 0, a = 0, o = !1;
3475
+ }
3476
+ };
3477
+ }
3478
+ function Pt(e, t = Mt) {
3479
+ let n = u(null);
3480
+ n.current ||= Nt(e, t);
3481
+ let [, i] = d(0), a = r(() => i((e) => e + 1), []), o = r((e, t, r) => {
3482
+ n.current.record(e, t, r), a();
3483
+ }, [a]), s = r(() => {
3484
+ let e = n.current.undo();
3485
+ return a(), e;
3486
+ }, [a]), c = r(() => {
3487
+ let e = n.current.redo();
3488
+ return a(), e;
3489
+ }, [a]), l = r((e, t) => {
3490
+ n.current.reset(e, t), a();
3491
+ }, [a]);
3492
+ return {
3493
+ canUndo: n.current.canUndo,
3494
+ canRedo: n.current.canRedo,
3495
+ record: o,
3496
+ undo: s,
3497
+ redo: c,
3498
+ reset: l
3499
+ };
3500
+ }
3501
+ // src/editor/ReactiveMarkdownEditor.tsx
3502
+ function $(e, t) {
3503
+ return Number.isFinite(e) ? Math.min(Math.max(Math.trunc(e), 0), t) : 0;
3504
+ }
3505
+ function Ft(e) {
3506
+ return typeof e == "number" ? `${e}px` : e;
3507
+ }
3508
+ function It(e, t) {
3509
+ let n = $(t.start, e.length), r = $(t.end, e.length);
3510
+ return n <= r ? {
3511
+ start: n,
3512
+ end: r
3513
+ } : {
3514
+ start: r,
3515
+ end: n
3516
+ };
3517
+ }
3518
+ function Lt(e, t) {
3519
+ e && (e.current = t);
3520
+ }
3521
+ var Rt = t(function({ value: e, onChange: t, locale: n = "en", theme: i = "auto", preview: a, viewMode: f, defaultViewMode: ee = "edit", onViewModeChange: te, id: h, className: g, style: _, height: ne = 560, minHeight: ie = 280, placeholder: ae, ariaLabel: v, readOnly: y = !1, disabled: oe = !1, documentKey: x, diagnostics: S, document: C = null, toolbar: w = !0, authoring: T = !0, onExport: E, textareaRef: D }, O) {
3522
+ let k = o(), A = h ?? `reactive-md-editor-${k.replace(/:/g, "")}`, se = re[n], j = u(null), [M, N] = d(!1);
3523
+ c(() => {
3524
+ let e = j.current;
3525
+ if (!e) return;
3526
+ let t = () => N(e.clientWidth <= 600);
3527
+ if (t(), typeof ResizeObserver > "u") return window.addEventListener("resize", t), () => window.removeEventListener("resize", t);
3528
+ let n = new ResizeObserver(t);
3529
+ return n.observe(e), () => n.disconnect();
3530
+ }, []);
3531
+ let [ce, le] = d(ee), P = a != null, F = P ? f ?? ce : "edit", I = M && F === "split" ? "edit" : F, L = (e) => {
3532
+ f === void 0 && le(e), te?.(e);
3533
+ }, R = u(null), z = u(null), B = u(null), V = u({
3534
+ start: 0,
3535
+ end: 0
3536
+ }), H = u(null), U = u(e), W = u(x), ue = u(!1), G = u(!1), fe = u(e);
3537
+ fe.current = e;
3538
+ let K = y || oe, pe = u(K);
3539
+ pe.current = K;
3540
+ let [me, he] = d(!1), [ge, _e] = d(1), { canUndo: ve, canRedo: ye, record: q, undo: be, redo: xe, reset: J } = Pt(e), Se = r(() => {
3541
+ V.current = {
3542
+ start: 0,
3543
+ end: 0
3544
+ };
3545
+ let e = R.current;
3546
+ e && (e.setSelectionRange(0, 0), e.scrollTop = 0, e.scrollLeft = 0), z.current && (z.current.scrollTop = 0), _e(1);
3547
+ }, []);
3548
+ c(() => {
3549
+ e !== U.current && (U.current = e, H.current = null, J(e), Se());
3550
+ }, [
3551
+ e,
3552
+ J,
3553
+ Se
3554
+ ]), c(() => {
3555
+ W.current !== x && (W.current = x, U.current = e, H.current = null, J(e), Se());
3556
+ }, [
3557
+ x,
3558
+ e,
3559
+ J,
3560
+ Se
3561
+ ]);
3562
+ let Ce = ft(e, T), we = l(() => e.split("\n"), [e]), Te = kt(we, B, R), Ee = l(() => {
3563
+ let e = /* @__PURE__ */ new Set();
3564
+ for (let t of S ?? []) Number.isInteger(t.line) && t.line > 0 && e.add(t.line);
3565
+ return e;
3566
+ }, [S]), De = r((e) => {
3567
+ let t = e.value.length, n = $(e.selectionStart, t), r = $(e.selectionEnd, t);
3568
+ V.current = {
3569
+ start: n,
3570
+ end: r
3571
+ }, _e(e.value.slice(0, n).split("\n").length);
3572
+ }, []), Y = r((e, n) => {
3573
+ let r = e !== fe.current;
3574
+ fe.current = e, U.current = e, n && r && (H.current = n), t(e);
3575
+ }, [t]), Oe = r((e) => {
3576
+ pe.current || (q(e.value, e.selection, "separate"), Y(e.value, e.selection));
3577
+ }, [Y, q]), ke = r(() => {
3578
+ if (pe.current) return;
3579
+ let e = be();
3580
+ e && Y(e.value, e.selection);
3581
+ }, [Y, be]), Ae = r(() => {
3582
+ if (pe.current) return;
3583
+ let e = xe();
3584
+ e && Y(e.value, e.selection);
3585
+ }, [Y, xe]);
3586
+ c(() => {
3587
+ let t = H.current;
3588
+ if (!t) return;
3589
+ if (e !== U.current) {
3590
+ H.current = null;
3591
+ return;
3592
+ }
3593
+ H.current = null;
3594
+ let n = R.current;
3595
+ if (!n) return;
3596
+ let r = It(n.value, t);
3597
+ n.setSelectionRange(r.start, r.end), n.focus({ preventScroll: !0 }), V.current = r, _e(n.value.slice(0, r.start).split("\n").length);
3598
+ }, [e]);
3599
+ let je = r((e) => {
3600
+ let t = R.current;
3601
+ if (t && (t.focus({ preventScroll: !0 }), e)) {
3602
+ let n = It(t.value, e);
3603
+ t.setSelectionRange(n.start, n.end), V.current = n, _e(t.value.slice(0, n.start).split("\n").length);
3604
+ }
3605
+ }, []), Me = r((e) => {
3606
+ let t = R.current;
3607
+ if (!t) return;
3608
+ let n = It(t.value, e);
3609
+ je(n);
3610
+ let r = t.value.slice(0, n.start).split("\n").length, i = z.current, a = i?.children[r - 1];
3611
+ if (i && a) {
3612
+ let e = a.getBoundingClientRect().top - i.getBoundingClientRect().top + i.scrollTop;
3613
+ t.scrollTop = Math.max(0, e - t.clientHeight / 3);
3614
+ } else {
3615
+ let e = window.getComputedStyle(t), n = Number.parseFloat(e.lineHeight) || 22;
3616
+ t.scrollTop = Math.max(0, (r - 1) * n - t.clientHeight / 3);
3617
+ }
3618
+ i && (i.scrollTop = t.scrollTop);
3619
+ }, [je]);
3620
+ s(O, () => ({
3621
+ focus(e) {
3622
+ je(e);
3623
+ },
3624
+ selectRange(e) {
3625
+ je(e);
3626
+ },
3627
+ getSelection() {
3628
+ let e = R.current;
3629
+ if (!e) return V.current;
3630
+ let t = e.value.length;
3631
+ return {
3632
+ start: $(e.selectionStart, t),
3633
+ end: $(e.selectionEnd, t)
3634
+ };
3635
+ },
3636
+ getTextarea() {
3637
+ return R.current;
3638
+ },
3639
+ undo: ke,
3640
+ redo: Ae
3641
+ }), [
3642
+ je,
3643
+ ke,
3644
+ Ae
3645
+ ]);
3646
+ let Ne = r((e) => {
3647
+ R.current = e, Lt(D, e);
3648
+ }, [D]), Pe = (e) => {
3649
+ if (pe.current) return;
3650
+ let t = e.currentTarget, n = {
3651
+ start: $(t.selectionStart, t.value.length),
3652
+ end: $(t.selectionEnd, t.value.length)
3653
+ };
3654
+ q(t.value, n, "merge"), Y(t.value);
3655
+ }, Fe = (e) => {
3656
+ if (ue.current || e.nativeEvent.isComposing) return;
3657
+ if (e.key === "Escape") {
3658
+ G.current = w;
3659
+ return;
3660
+ }
3661
+ let t = G.current && e.key === "Tab" && !e.shiftKey;
3662
+ if (G.current = !1, t) {
3663
+ let t = R.current?.closest(".reactive-md-editor")?.querySelector(".editor-toolbar [tabindex=\"0\"]:not(:disabled)");
3664
+ if (t) {
3665
+ e.preventDefault(), t.focus({ preventScroll: !0 });
3666
+ return;
3667
+ }
3668
+ }
3669
+ if (pe.current) return;
3670
+ let n = e.metaKey || e.ctrlKey, r = e.key.toLowerCase();
3671
+ if (n && !e.altKey && r === "z") {
3672
+ e.preventDefault(), e.shiftKey ? Ae() : ke();
3673
+ return;
3674
+ }
3675
+ if (n && !e.altKey && r === "y") {
3676
+ e.preventDefault(), Ae();
3677
+ return;
3678
+ }
3679
+ if (e.key !== "Tab" || e.shiftKey) return;
3680
+ e.preventDefault();
3681
+ let i = e.currentTarget, a = $(i.selectionStart, i.value.length), o = $(i.selectionEnd, i.value.length);
3682
+ if (a !== o) {
3683
+ Oe(de(i.value, {
3684
+ start: a,
3685
+ end: o
3686
+ }));
3687
+ return;
3688
+ }
3689
+ let s = `${i.value.slice(0, a)} ${i.value.slice(o)}`, c = {
3690
+ start: a + 2,
3691
+ end: a + 2
3692
+ };
3693
+ q(s, c, "separate"), Y(s, c);
3694
+ }, Ie = () => {
3695
+ G.current = !1, ue.current = !0, he(!0);
3696
+ }, Le = (e) => {
3697
+ ue.current = !1, he(!1), De(e.currentTarget);
3698
+ }, Re = (e) => {
3699
+ z.current && (z.current.scrollTop = e.currentTarget.scrollTop);
3700
+ }, ze = w, Be = `reactive-md-editor${g ? ` ${g}` : ""}`;
3701
+ return /* @__PURE__ */ p(b, {
3702
+ locale: n,
3703
+ children: /* @__PURE__ */ m("div", {
3704
+ className: Be,
3705
+ "data-editor-theme": i,
3706
+ lang: n === "zh" ? "zh-CN" : "en",
3707
+ style: _,
3708
+ role: "group",
3709
+ "aria-label": se.region,
3710
+ "aria-disabled": K || void 0,
3711
+ inert: oe || void 0,
3712
+ children: [/* @__PURE__ */ m("div", {
3713
+ className: "editor-frame",
3714
+ ref: j,
3715
+ "data-editor-view": I,
3716
+ style: {
3717
+ height: Ft(ne),
3718
+ minHeight: Ft(ie)
3719
+ },
3720
+ children: [
3721
+ ze ? /* @__PURE__ */ p(at, {
3722
+ editorRef: R,
3723
+ onEdit: Oe,
3724
+ onUndo: ke,
3725
+ onRedo: Ae,
3726
+ canUndo: ve,
3727
+ canRedo: ye,
3728
+ onExport: E,
3729
+ showExport: typeof E == "function",
3730
+ disabled: K
3731
+ }) : null,
3732
+ /* @__PURE__ */ p("label", {
3733
+ className: "reactive-md-editor-sr-only",
3734
+ htmlFor: A,
3735
+ children: se.sourceLabel
3736
+ }),
3737
+ /* @__PURE__ */ m("div", {
3738
+ className: "editor-workspace",
3739
+ "data-view": I,
3740
+ children: [/* @__PURE__ */ m("div", {
3741
+ id: `${A}-source`,
3742
+ hidden: I === "preview",
3743
+ className: `editor-shell${me ? " is-composing" : ""}`,
3744
+ children: [
3745
+ /* @__PURE__ */ p("div", {
3746
+ className: "editor-gutter",
3747
+ ref: z,
3748
+ "aria-hidden": "true",
3749
+ children: we.map((e, t) => {
3750
+ let n = t + 1;
3751
+ return /* @__PURE__ */ p("span", {
3752
+ className: `gutter-line ${ge === n ? "is-active" : ""} ${Ee.has(n) ? "is-diagnostic" : ""}`,
3753
+ style: Te.heights[t] ? { height: `${Te.heights[t]}px` } : void 0,
3754
+ children: n
3755
+ }, n);
3756
+ })
3757
+ }),
3758
+ /* @__PURE__ */ m("div", {
3759
+ className: "editor-input-wrap",
3760
+ children: [/* @__PURE__ */ p(mt, {
3761
+ source: e,
3762
+ tokens: Ce.tokens,
3763
+ width: Te.width,
3764
+ editorRef: R
3765
+ }), /* @__PURE__ */ p("textarea", {
3766
+ id: A,
3767
+ ref: Ne,
3768
+ className: "editor-input",
3769
+ value: e,
3770
+ wrap: "soft",
3771
+ spellCheck: !1,
3772
+ autoCapitalize: "off",
3773
+ autoCorrect: "off",
3774
+ placeholder: ae,
3775
+ "aria-label": v,
3776
+ readOnly: y,
3777
+ disabled: oe,
3778
+ onScroll: Re,
3779
+ onChange: Pe,
3780
+ onKeyDown: Fe,
3781
+ onBlur: () => {
3782
+ G.current = !1;
3783
+ },
3784
+ onCompositionStart: Ie,
3785
+ onCompositionEnd: Le,
3786
+ onSelect: (e) => De(e.currentTarget),
3787
+ onKeyUp: (e) => De(e.currentTarget),
3788
+ onClick: (e) => De(e.currentTarget)
3789
+ })]
3790
+ }),
3791
+ /* @__PURE__ */ p("div", {
3792
+ className: "editor-mirror",
3793
+ ref: B,
3794
+ "aria-hidden": "true",
3795
+ style: Te.width ? { width: Te.width } : void 0,
3796
+ children: we.map((e, t) => /* @__PURE__ */ p("div", { children: e.replace(/\r$/, "") || "​" }, t))
3797
+ })
3798
+ ]
3799
+ }), P ? /* @__PURE__ */ p("div", {
3800
+ id: `${A}-preview`,
3801
+ className: "editor-preview",
3802
+ role: "region",
3803
+ "aria-label": se.previewRegion,
3804
+ hidden: I === "edit",
3805
+ children: a
3806
+ }) : null]
3807
+ }),
3808
+ /* @__PURE__ */ p(ot, {
3809
+ source: e,
3810
+ mode: I,
3811
+ onModeChange: L,
3812
+ sourceId: `${A}-source`,
3813
+ previewId: `${A}-preview`,
3814
+ hasPreview: P,
3815
+ allowSplit: !M,
3816
+ toolbar: w && !K
3817
+ })
3818
+ ]
3819
+ }), T ? /* @__PURE__ */ p("div", {
3820
+ hidden: I === "preview",
3821
+ children: /* @__PURE__ */ p(Dt, {
3822
+ source: e,
3823
+ analysis: Ce,
3824
+ bindingDocument: C,
3825
+ editorRef: R,
3826
+ onEdit: Oe,
3827
+ onLocate: Me,
3828
+ disabled: K
3829
+ })
3830
+ }) : null]
3831
+ })
3832
+ });
3833
+ });
3834
+ export { Rt as ReactiveMarkdownEditor };