reactive-md 0.4.1 → 0.5.0

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