@smartdoca/markdown 0.4.3 → 0.4.4

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.
@@ -0,0 +1,2008 @@
1
+ import { jsx as c, jsxs as I, Fragment as le } from "react/jsx-runtime";
2
+ import { memo as We, useId as nr, useState as V, useEffect as K, useRef as A, useCallback as Ee, useMemo as J, useLayoutEffect as Pt, forwardRef as Xe, createElement as gt, useImperativeHandle as or } from "react";
3
+ import ar from "@uiw/react-codemirror";
4
+ import { createPortal as Ct } from "react-dom";
5
+ import { markdown as ir } from "@codemirror/lang-markdown";
6
+ import { syntaxHighlighting as sr, defaultHighlightStyle as lr } from "@codemirror/language";
7
+ import { ViewPlugin as cr, EditorView as ce, Decoration as pe, WidgetType as dr, keymap as ur } from "@codemirror/view";
8
+ import { StateEffect as Ae, StateField as mr, EditorState as pt, Prec as ht } from "@codemirror/state";
9
+ import { yCollab as fr, ySyncAnnotation as gr } from "y-codemirror.next";
10
+ import * as U from "yjs";
11
+ import { ZoomOut as pr, ZoomIn as hr, RotateCcw as vr, X as wr, ChevronLeft as br, ChevronRight as yr, Undo2 as xr, Redo2 as kr, ImagePlus as Mr, Workflow as Er, Sigma as Pr, PanelLeft as Cr, Columns2 as Fr, PanelRight as Sr, Check as Tr, TriangleAlert as Ar, CloudOff as Dr, LoaderCircle as Ir } from "lucide-react";
12
+ import Rr from "react-markdown";
13
+ import Lr from "remark-gfm";
14
+ import Nr from "remark-math";
15
+ import Or from "rehype-katex";
16
+ import Ur from "rehype-raw";
17
+ import _r, { defaultSchema as He } from "rehype-sanitize";
18
+ import Z from "highlight.js/lib/core";
19
+ import zr from "highlight.js/lib/languages/bash";
20
+ import Br from "highlight.js/lib/languages/c";
21
+ import Hr from "highlight.js/lib/languages/cpp";
22
+ import Kr from "highlight.js/lib/languages/csharp";
23
+ import $r from "highlight.js/lib/languages/css";
24
+ import Vr from "highlight.js/lib/languages/dockerfile";
25
+ import jr from "highlight.js/lib/languages/go";
26
+ import qr from "highlight.js/lib/languages/graphql";
27
+ import Wr from "highlight.js/lib/languages/java";
28
+ import Xr from "highlight.js/lib/languages/javascript";
29
+ import Yr from "highlight.js/lib/languages/json";
30
+ import Gr from "highlight.js/lib/languages/kotlin";
31
+ import Jr from "highlight.js/lib/languages/markdown";
32
+ import Zr from "highlight.js/lib/languages/php";
33
+ import Qr from "highlight.js/lib/languages/python";
34
+ import en from "highlight.js/lib/languages/ruby";
35
+ import tn from "highlight.js/lib/languages/rust";
36
+ import rn from "highlight.js/lib/languages/sql";
37
+ import nn from "highlight.js/lib/languages/swift";
38
+ import on from "highlight.js/lib/languages/typescript";
39
+ import an from "highlight.js/lib/languages/xml";
40
+ import sn from "highlight.js/lib/languages/yaml";
41
+ import { postprocess as ln, parse as cn, preprocess as dn } from "micromark";
42
+ import { gfm as un } from "micromark-extension-gfm";
43
+ import { decodeString as mn } from "micromark-util-decode-string";
44
+ import { IndexeddbPersistence as fn } from "y-indexeddb";
45
+ import { WebsocketProvider as gn } from "y-websocket";
46
+ import { Awareness as Ft } from "y-protocols/awareness";
47
+ function St(t) {
48
+ return t == null || t === "" || t === "zh" ? "zh" : "en";
49
+ }
50
+ function pn(t) {
51
+ return St(t) === "zh" ? "zh-CN" : "en";
52
+ }
53
+ const Tt = {
54
+ "toolbar.label": "Markdown formatting toolbar",
55
+ "toolbar.undo": "Undo",
56
+ "toolbar.redo": "Redo",
57
+ "toolbar.insertCode": "Insert code block",
58
+ "toolbar.codeLanguage": "Code language",
59
+ "toolbar.textColor": "Text color",
60
+ "toolbar.uploadImage": "Upload image",
61
+ "toolbar.insertDiagram": "Insert diagram",
62
+ "toolbar.insertFormula": "Insert math formula",
63
+ "toolbar.viewEdit": "Edit only",
64
+ "toolbar.viewSplit": "Split view",
65
+ "toolbar.viewPreview": "Preview only",
66
+ "format.heading1": "Heading 1",
67
+ "format.heading2": "Heading 2",
68
+ "format.heading3": "Heading 3",
69
+ "format.heading4": "Heading 4",
70
+ "format.heading5": "Heading 5",
71
+ "format.bold": "Bold",
72
+ "format.italic": "Italic",
73
+ "format.strike": "Strikethrough",
74
+ "format.inlineCode": "Inline code",
75
+ "format.quote": "Quote",
76
+ "format.bulletList": "Bulleted list",
77
+ "format.orderedList": "Numbered list",
78
+ "format.task": "Task list",
79
+ "format.link": "Link",
80
+ "format.boldPlaceholder": "bold text",
81
+ "format.italicPlaceholder": "italic text",
82
+ "format.strikePlaceholder": "strikethrough text",
83
+ "format.codePlaceholder": "code",
84
+ "format.linkPlaceholder": "link text",
85
+ "format.colorPlaceholder": "colored text",
86
+ "insert.diagram": `
87
+ \`\`\`mermaid
88
+ flowchart TD
89
+ A[Start] --> B{Decision}
90
+ B -->|Yes| C[Done]
91
+ B -->|No| D[Revise]
92
+ \`\`\`
93
+ `,
94
+ "insert.codePlaceholder": "Type code here",
95
+ "diagram.syntaxError": "The diagram syntax is invalid. Check the Mermaid code.",
96
+ "image.open": "Preview {name}",
97
+ "image.image": "Image",
98
+ "image.diagram": "Diagram",
99
+ "image.preview": "Image preview",
100
+ "image.counter": "{current} / {total}",
101
+ "image.zoomOut": "Zoom out",
102
+ "image.zoomIn": "Zoom in",
103
+ "image.reset": "Reset zoom and position",
104
+ "image.close": "Close image preview",
105
+ "image.previous": "Previous image",
106
+ "image.next": "Next image",
107
+ "image.unavailable": "This image is unavailable",
108
+ "image.hint": "Drag to move · Scroll to zoom · Arrow keys or swipe to switch",
109
+ "selection.toolbar": "Selection actions",
110
+ "notice.imageRequired": "Choose an image file",
111
+ "notice.readOnly": "This document is read-only",
112
+ "notice.uploadFailed": "Image upload failed",
113
+ "notice.downloadFailed": "Download failed",
114
+ "notice.uploading": "Processing image…",
115
+ "editor.pane": "Markdown editor",
116
+ "editor.characters.one": "{count} character",
117
+ "editor.characters.other": "{count} characters",
118
+ "editor.transportRequired": "roomId and websocketUrl are required, or pass a host-managed collaboration session",
119
+ "preview.pane": "Document preview",
120
+ "preview.label": "Preview",
121
+ "preview.updating": "Updating preview…",
122
+ "preview.syncScroll": "Scroll sync",
123
+ "preview.live": "Live render",
124
+ "document.title": "Collaborative document",
125
+ "status.ready": "Collaboration ready",
126
+ "status.error": "Collaboration error",
127
+ "status.offline": "Offline",
128
+ "status.offlineEditing": "Offline editing",
129
+ "status.syncing": "Syncing document",
130
+ "status.loading": "Loading document",
131
+ "header.room": "Room · {roomId}",
132
+ "presence.online.one": "{count} person online",
133
+ "presence.online.other": "{count} people online",
134
+ "presence.cursor": "{name}'s cursor",
135
+ "presence.anonymous": "Anonymous",
136
+ "loading.document": "Loading collaborative document…",
137
+ "footer.formats": "CommonMark · GFM · Mermaid",
138
+ "footer.readOnly": "Read-only",
139
+ "footer.dropImages": "Drop or paste images",
140
+ "collaboration.schemaMismatch": "This document format is not supported",
141
+ "collaboration.initializationFailed": "Failed to load local collaboration data",
142
+ "pdf.aborted": "PDF conversion was cancelled",
143
+ "pdf.fileTooLarge": "PDF exceeds the {maxBytes}-byte limit",
144
+ "pdf.readFailed": "Could not read the PDF file",
145
+ "pdf.passwordRequired": "This PDF requires a password. Password-protected PDFs are not supported in this phase",
146
+ "pdf.errorDetail": "{message} ({detail})",
147
+ "pdf.timeout": "PDF conversion exceeded the {timeoutMs} ms limit",
148
+ "pdf.pageLimit": "PDF exceeds the {maxPages}-page limit",
149
+ "pdf.unsafeLink": "Skipped an unsafe or unverifiable PDF link",
150
+ "pdf.multiColumn": "Possible multi-column layout detected. Text order is reconstructed approximately from PDF coordinates",
151
+ "pdf.imagePixelLimit": "An image in the PDF exceeds the {maxImagePixels}-pixel limit",
152
+ "pdf.pngFailed": "Could not convert a PDF image to PNG",
153
+ "pdf.imageSkipped": "Could not extract an embedded PDF image. It was skipped",
154
+ "pdf.canvasUnavailable": "No Canvas is available in this environment, so embedded PDF images could not be extracted",
155
+ "pdf.imageParseFailed": "Failed to parse an embedded PDF image. Text import continued",
156
+ "pdf.noTextPage": "This page has no extractable text. Scanned PDFs are not OCR'd in this phase",
157
+ "pdf.imageAlt": "PDF image",
158
+ "pdf.complexTableImport": "PDF tables are reconstructed approximately from text coordinates. Complex merged cells may be lossy",
159
+ "pdf.noText": "The PDF has no extractable text. Scanned PDFs are not OCR'd in this phase",
160
+ "pdf.invalid": "The PDF is damaged or uses an unsupported format",
161
+ "pdf.unsafeLinkText": "Downgraded an unsafe link to plain text",
162
+ "pdf.mathDegraded": "Math was downgraded to readable plain text",
163
+ "pdf.complexTableExport": "Tables are drawn at a fixed width. Merged cells and overly wide columns may be lossy",
164
+ "pdf.fontFallback": "No font covering every character was provided. Unsupported characters were replaced with question marks. Provide a Chinese TTF/OTF font in PdfExportOptions.fontBytes",
165
+ "pdf.fontFallbackCjk": "No Chinese font was provided. Characters the standard fonts cannot encode are replaced with question marks. Provide a Chinese TTF/OTF font in PdfExportOptions.fontBytes",
166
+ "pdf.imageUnresolved": "No resolveResource callback was provided for a Markdown image. Alternate text was exported instead",
167
+ "pdf.imageFailed": "Failed to resolve a Markdown image. Alternate text was exported instead",
168
+ "pdf.inlineImageUnresolved": "No resolveResource callback was provided for an inline Markdown image. Alternate text was exported instead",
169
+ "pdf.inlineImageUnsupported": "The inline Markdown image format is unsupported. Alternate text was exported instead",
170
+ "pdf.inlineImageFailed": "Failed to resolve an inline Markdown image. Alternate text was exported instead",
171
+ "pdf.pageGeometry": "PDF page size and margins must be positive numbers",
172
+ "validation.positiveInteger": "{name} must be a positive safe integer",
173
+ "validation.nonNegativeInteger": "{name} must be a non-negative safe integer",
174
+ "validation.markdownString": "markdown must be a string",
175
+ "validation.loneSurrogate": "Markdown contains an isolated UTF-16 surrogate and cannot be exported to UTF-8 without data loss",
176
+ "markdown.resourcePreserved": "Only the Markdown source is exchanged. Image, attachment, and internal-link IDs, paths, and addresses are kept as-is. Resources were not read and authorization was not checked. Platform-internal resources are not guaranteed to work outside the platform.",
177
+ "markdown.unsupportedExtension": "Only .md and .markdown files are supported",
178
+ "markdown.fileTooLarge": "File exceeds the {maxBytes}-byte limit",
179
+ "markdown.readFailed": "Could not read the Markdown file",
180
+ "markdown.invalidUtf8": "The file is not valid UTF-8. Convert the encoding first. No damaged characters were replaced",
181
+ "markdown.binary": "The file contains a NUL character and may be binary or unsupported UTF-16/UTF-32",
182
+ "markdown.bomRemoved": "Removed the UTF-8 BOM at the start of the file. U+FEFF in the body was kept",
183
+ "markdown.mixedLineEndings": "The file mixes line-ending styles. They were kept as-is and not normalized",
184
+ "upload.failed": "Upload failed ({status})",
185
+ "upload.missingUrl": "The upload endpoint did not return an image URL",
186
+ "upload.readFailed": "Could not read the image"
187
+ }, At = {
188
+ "toolbar.label": "Markdown 格式工具栏",
189
+ "toolbar.undo": "撤销",
190
+ "toolbar.redo": "重做",
191
+ "toolbar.insertCode": "插入代码块",
192
+ "toolbar.codeLanguage": "代码语言",
193
+ "toolbar.textColor": "文字颜色",
194
+ "toolbar.uploadImage": "上传图片",
195
+ "toolbar.insertDiagram": "插入流程图",
196
+ "toolbar.insertFormula": "插入数学公式",
197
+ "toolbar.viewEdit": "仅编辑",
198
+ "toolbar.viewSplit": "分栏",
199
+ "toolbar.viewPreview": "仅预览",
200
+ "format.heading1": "一级标题",
201
+ "format.heading2": "二级标题",
202
+ "format.heading3": "三级标题",
203
+ "format.heading4": "四级标题",
204
+ "format.heading5": "五级标题",
205
+ "format.bold": "加粗",
206
+ "format.italic": "斜体",
207
+ "format.strike": "删除线",
208
+ "format.inlineCode": "行内代码",
209
+ "format.quote": "引用",
210
+ "format.bulletList": "无序列表",
211
+ "format.orderedList": "有序列表",
212
+ "format.task": "待办事项",
213
+ "format.link": "链接",
214
+ "format.boldPlaceholder": "加粗文字",
215
+ "format.italicPlaceholder": "斜体文字",
216
+ "format.strikePlaceholder": "删除文字",
217
+ "format.codePlaceholder": "代码",
218
+ "format.linkPlaceholder": "链接文字",
219
+ "format.colorPlaceholder": "彩色文字",
220
+ "insert.diagram": `
221
+ \`\`\`mermaid
222
+ flowchart TD
223
+ A[开始] --> B{判断}
224
+ B -->|是| C[完成]
225
+ B -->|否| D[调整]
226
+ \`\`\`
227
+ `,
228
+ "insert.codePlaceholder": "在这里输入代码",
229
+ "diagram.syntaxError": "流程图语法有误,请检查 Mermaid 代码。",
230
+ "image.open": "预览{name}",
231
+ "image.image": "图片",
232
+ "image.diagram": "流程图",
233
+ "image.preview": "图片预览",
234
+ "image.counter": "{current} / {total}",
235
+ "image.zoomOut": "缩小",
236
+ "image.zoomIn": "放大",
237
+ "image.reset": "重置缩放和位置",
238
+ "image.close": "关闭图片预览",
239
+ "image.previous": "上一张图片",
240
+ "image.next": "下一张图片",
241
+ "image.unavailable": "此图片暂时无法显示",
242
+ "image.hint": "拖动平移 · 滚轮缩放 · 方向键或滑动切换",
243
+ "selection.toolbar": "选中文字操作",
244
+ "notice.imageRequired": "请选择图片文件",
245
+ "notice.readOnly": "当前文档为只读模式",
246
+ "notice.uploadFailed": "图片上传失败",
247
+ "notice.downloadFailed": "下载失败",
248
+ "notice.uploading": "正在处理图片…",
249
+ "editor.pane": "Markdown 编辑器",
250
+ "editor.characters.one": "{count} 字符",
251
+ "editor.characters.other": "{count} 字符",
252
+ "editor.transportRequired": "roomId 和 websocketUrl 必填,或传入宿主管理的 collaboration 会话",
253
+ "preview.pane": "文档预览",
254
+ "preview.label": "预览",
255
+ "preview.updating": "预览更新中…",
256
+ "preview.syncScroll": "同步滚动",
257
+ "preview.live": "实时渲染",
258
+ "document.title": "协作文档",
259
+ "status.ready": "协同就绪",
260
+ "status.error": "协同错误",
261
+ "status.offline": "离线",
262
+ "status.offlineEditing": "离线编辑",
263
+ "status.syncing": "同步文档中",
264
+ "status.loading": "加载文档中",
265
+ "header.room": "房间 · {roomId}",
266
+ "presence.online.one": "{count} 人在线",
267
+ "presence.online.other": "{count} 人在线",
268
+ "presence.cursor": "{name} 的光标",
269
+ "presence.anonymous": "匿名",
270
+ "loading.document": "正在获取协作文档…",
271
+ "footer.formats": "支持 CommonMark · GFM · Mermaid",
272
+ "footer.readOnly": "只读模式",
273
+ "footer.dropImages": "图片可直接拖入或粘贴",
274
+ "collaboration.schemaMismatch": "文档格式不受支持",
275
+ "collaboration.initializationFailed": "本地协同数据加载失败",
276
+ "pdf.aborted": "PDF 转换已取消",
277
+ "pdf.fileTooLarge": "PDF 文件超过 {maxBytes} 字节限制",
278
+ "pdf.readFailed": "无法读取 PDF 文件",
279
+ "pdf.passwordRequired": "PDF 需要密码,第一阶段不支持密码 PDF",
280
+ "pdf.errorDetail": "{message}({detail})",
281
+ "pdf.timeout": "PDF 转换超过 {timeoutMs} 毫秒限制",
282
+ "pdf.pageLimit": "PDF 页数超过 {maxPages} 页限制",
283
+ "pdf.unsafeLink": "已跳过不安全或无法验证的 PDF 链接",
284
+ "pdf.multiColumn": "检测到可能的多栏布局,文本顺序按 PDF 坐标近似重建",
285
+ "pdf.imagePixelLimit": "PDF 内图片超过 {maxImagePixels} 像素限制",
286
+ "pdf.pngFailed": "无法将 PDF 图片转换为 PNG",
287
+ "pdf.imageSkipped": "PDF 内嵌图片无法提取,已跳过",
288
+ "pdf.canvasUnavailable": "当前运行环境没有可用的 Canvas,无法提取 PDF 内嵌图片",
289
+ "pdf.imageParseFailed": "PDF 内嵌图片解析失败,已继续导入文本",
290
+ "pdf.noTextPage": "此页没有可提取文本;扫描 PDF 第一阶段不执行 OCR",
291
+ "pdf.imageAlt": "PDF 图片",
292
+ "pdf.complexTableImport": "PDF 表格按坐标文本近似还原,复杂合并单元格可能有损",
293
+ "pdf.noText": "PDF 没有可提取文本;扫描 PDF 第一阶段不执行 OCR",
294
+ "pdf.invalid": "PDF 文件损坏或格式不受支持",
295
+ "pdf.unsafeLinkText": "已将不安全链接降级为纯文本",
296
+ "pdf.mathDegraded": "数学公式已按可读纯文本降级",
297
+ "pdf.complexTableExport": "表格按固定宽度绘制;合并单元格和超宽列可能有损",
298
+ "pdf.fontFallback": "未提供可覆盖全部字符的字体;不兼容字符已替换为问号。建议在 PdfExportOptions.fontBytes 中提供中文 TTF/OTF 字体",
299
+ "pdf.fontFallbackCjk": "未提供中文字体;导出会将标准字体无法编码的字符降级为问号。请在 PdfExportOptions.fontBytes 中提供中文 TTF/OTF 字体",
300
+ "pdf.imageUnresolved": "Markdown 图片未提供 resolveResource,已用替代文本导出",
301
+ "pdf.imageFailed": "Markdown 图片资源解析失败,已用替代文本导出",
302
+ "pdf.inlineImageUnresolved": "Markdown 行内图片未提供 resolveResource,已用替代文本导出",
303
+ "pdf.inlineImageUnsupported": "Markdown 行内图片格式不受支持,已用替代文本导出",
304
+ "pdf.inlineImageFailed": "Markdown 行内图片资源解析失败,已用替代文本导出",
305
+ "pdf.pageGeometry": "PDF 页面尺寸和页边距必须为正数",
306
+ "validation.positiveInteger": "{name} 必须为正安全整数",
307
+ "validation.nonNegativeInteger": "{name} 必须为非负安全整数",
308
+ "validation.markdownString": "markdown 必须为字符串",
309
+ "validation.loneSurrogate": "Markdown 包含孤立 UTF-16 代理字符,无法无损导出为 UTF-8",
310
+ "markdown.resourcePreserved": "仅交换 Markdown 原文;图片、附件和内部链接的 ID/path/地址原样保留,未读取资源或验证授权,平台内部资源离开平台不保证可访问。",
311
+ "markdown.unsupportedExtension": "只支持 .md 和 .markdown 文件",
312
+ "markdown.fileTooLarge": "文件超过 {maxBytes} 字节限制",
313
+ "markdown.readFailed": "无法读取 Markdown 文件",
314
+ "markdown.invalidUtf8": "文件不是有效 UTF-8;请先转换编码,未替换任何损坏字符",
315
+ "markdown.binary": "文件包含 NUL 字符,可能是二进制或不受支持的 UTF-16/UTF-32 编码",
316
+ "markdown.bomRemoved": "已移除文件开头的 UTF-8 BOM;正文内的 U+FEFF 保留",
317
+ "markdown.mixedLineEndings": "文件混用了换行格式;原样保留,未统一换行",
318
+ "upload.failed": "上传失败({status})",
319
+ "upload.missingUrl": "上传接口未返回图片地址",
320
+ "upload.readFailed": "读取图片失败"
321
+ };
322
+ function hn(t, e) {
323
+ const r = Object.keys(t).filter((o) => !Object.prototype.hasOwnProperty.call(e, o)), n = Object.keys(e).filter((o) => !Object.prototype.hasOwnProperty.call(t, o));
324
+ if (r.length || n.length)
325
+ throw new Error(`Message catalog mismatch. Missing zh: ${r.join(", ")}. Extra zh: ${n.join(", ")}`);
326
+ }
327
+ hn(Tt, At);
328
+ const vt = { en: Tt, zh: At };
329
+ function D(t, e, r, n) {
330
+ const o = St(t), s = r && typeof r.count == "number" ? r.count : void 0, d = s === void 0 ? [e] : [`${e}.${s === 1 ? "one" : "other"}`, e], u = [n, vt[o], vt.en];
331
+ let a;
332
+ for (const i of u)
333
+ if (i) {
334
+ for (const f of d)
335
+ if (Object.prototype.hasOwnProperty.call(i, f)) {
336
+ a = i[f];
337
+ break;
338
+ }
339
+ if (a !== void 0) break;
340
+ }
341
+ return a === void 0 && (a = d[0]), r ? a.replace(/\{([A-Za-z0-9_]+)\}/g, (i, f) => {
342
+ const l = r[f];
343
+ return l == null ? i : String(l);
344
+ }) : a;
345
+ }
346
+ function Zo(t, e) {
347
+ return (r, n) => D(t, r, n, e);
348
+ }
349
+ function vn(t, e, r) {
350
+ return t.code === "INITIALIZATION_FAILED" ? D(e, "collaboration.initializationFailed", void 0, r) : t.code === "SCHEMA_MISMATCH" && !(t.cause instanceof Error) ? D(e, "collaboration.schemaMismatch", void 0, r) : t.message;
351
+ }
352
+ let wt = !1;
353
+ const wn = We(function({ code: e, locale: r, messages: n }) {
354
+ const o = nr().replace(/:/g, ""), [s, d] = V(null), u = s?.code === e ? s.svg : "", a = s?.code === e && s.failed;
355
+ return K(() => {
356
+ let i = !0;
357
+ const f = `mermaid-${o}-${Date.now()}`;
358
+ return import("mermaid").then(({ default: l }) => (wt || (l.initialize({ startOnLoad: !1, theme: "neutral", securityLevel: "strict", fontFamily: "Inter, system-ui, sans-serif" }), wt = !0), l.render(f, e))).then(({ svg: l }) => {
359
+ i && d({ code: e, svg: l, failed: !1 });
360
+ }).catch(() => {
361
+ i && d({ code: e, svg: "", failed: !0 });
362
+ }), () => {
363
+ i = !1;
364
+ };
365
+ }, [e, o]), a ? /* @__PURE__ */ c("div", { className: "diagram-error", children: D(r, "diagram.syntaxError", void 0, n) }) : /* @__PURE__ */ c("div", { className: "mermaid-diagram", dangerouslySetInnerHTML: { __html: u } });
366
+ }), bn = { bash: zr, c: Br, cpp: Hr, csharp: Kr, css: $r, dockerfile: Vr, go: jr, graphql: qr, java: Wr, javascript: Xr, json: Yr, kotlin: Gr, markdown: Jr, php: Zr, python: Qr, ruby: en, rust: tn, sql: rn, swift: nn, typescript: on, xml: an, yaml: sn };
367
+ Object.entries(bn).forEach(([t, e]) => {
368
+ Z.getLanguage(t) || Z.registerLanguage(t, e);
369
+ });
370
+ Z.registerAliases(["js", "jsx"], { languageName: "javascript" });
371
+ Z.registerAliases(["ts", "tsx"], { languageName: "typescript" });
372
+ Z.registerAliases(["sh", "shell"], { languageName: "bash" });
373
+ Z.registerAliases(["html", "svg", "vue"], { languageName: "xml" });
374
+ Z.registerAliases(["yml"], { languageName: "yaml" });
375
+ Z.registerAliases(["cs", "dotnet"], { languageName: "csharp" });
376
+ Z.registerAliases(["md"], { languageName: "markdown" });
377
+ function Ye(t, e, r) {
378
+ if (!e) return;
379
+ const n = t.at(-1);
380
+ n && n.scope === r ? n.text += e : t.push({ text: e, scope: r });
381
+ }
382
+ function Dt(t, e, r) {
383
+ if (typeof t == "string") {
384
+ Ye(e, t, r);
385
+ return;
386
+ }
387
+ const n = t.scope || r;
388
+ for (const o of t.children || []) Dt(o, e, n);
389
+ }
390
+ function yn(t) {
391
+ const e = [[]];
392
+ for (const r of t) {
393
+ const n = r.text.split(`
394
+ `);
395
+ for (let o = 0; o < n.length; o++)
396
+ Ye(e.at(-1), n[o], r.scope), o < n.length - 1 && e.push([]);
397
+ }
398
+ return e;
399
+ }
400
+ function xn(t) {
401
+ const e = { "&": "&amp;", "<": "&lt;", ">": "&gt;", '"': "&quot;", "'": "&#039;" };
402
+ return t.replace(/[&<>"']/g, (r) => e[r]);
403
+ }
404
+ function kn(t, e) {
405
+ const r = (e || "").toLowerCase(), n = Z.getLanguage(r) ? r : "plaintext";
406
+ if (n === "plaintext") return { language: n, html: xn(t), lines: t.split(`
407
+ `).map((u) => u ? [{ text: u }] : []) };
408
+ const o = Z.highlight(t, { language: n }), s = o._emitter.rootNode, d = [];
409
+ return s ? Dt(s, d) : Ye(d, t), { language: n, html: o.value, lines: yn(d) };
410
+ }
411
+ function Mn({ code: t, language: e }) {
412
+ const r = t.replace(/\n$/, ""), n = kn(r, e);
413
+ return /* @__PURE__ */ c("pre", { className: "highlighted-code", children: /* @__PURE__ */ c("code", { className: `hljs language-${n.language}`, dangerouslySetInnerHTML: { __html: n.html } }) });
414
+ }
415
+ function En(t) {
416
+ const e = [];
417
+ let r = 0;
418
+ for (const [i, f] of ln(cn({ extensions: [un()] }).document().write(dn()(t, "utf8", !0)))) {
419
+ if (f.type === "codeText" && (r += i === "enter" ? 1 : -1), i !== "enter") continue;
420
+ const l = f.start.offset, b = f.end.offset, p = t.slice(l, b);
421
+ if (["data", "codeTextData", "autolinkProtocol", "autolinkEmail"].includes(f.type))
422
+ for (let h = 0; h < p.length; h++) e.push({ from: l + h, to: l + h + 1, value: p[h] === "\0" ? "�" : p[h] });
423
+ else if (f.type === "characterEscape" || f.type === "characterReference")
424
+ for (const h of mn(p).split("")) e.push({ from: l, to: b, value: h });
425
+ else if (f.type === "lineEnding")
426
+ if (r) e.push({ from: l, to: b, value: " " });
427
+ else for (let h = 0; h < p.length; h++) e.push({ from: l + h, to: l + h + 1, value: p[h] });
428
+ }
429
+ e.sort((i, f) => i.from - f.from);
430
+ const n = { source: t, runs: /* @__PURE__ */ new Map() }, o = /* @__PURE__ */ new Map(), s = (i) => `${i.position?.start?.offset}:${i.position?.end?.offset}`, d = (i) => {
431
+ let f = 0, l = e.length;
432
+ for (; f < l; ) {
433
+ const b = f + l >>> 1;
434
+ e[b].from < i ? f = b + 1 : l = b;
435
+ }
436
+ return f;
437
+ };
438
+ return { mapping: n, beforeRaw: () => (i) => {
439
+ n.runs.clear(), o.clear();
440
+ const f = (l, b = !1) => {
441
+ b ||= l.tagName === "pre" || l.tagName === "code" && !!l.properties?.className, !(!l.children || b) && (l.children = l.children.map((p) => {
442
+ if (p.type !== "text")
443
+ return f(p, b), p;
444
+ const h = p.position?.start?.offset, k = p.position?.end?.offset;
445
+ if (h === void 0 || k === void 0 || !p.value) return p;
446
+ const C = [];
447
+ for (let v = d(h); v < e.length && e[v].to <= k; v++) C.push(e[v]);
448
+ if (C.map((v) => v.value).join("") !== p.value) return p;
449
+ const y = String(n.runs.size);
450
+ return n.runs.set(y, { value: p.value, characters: C.map(({ from: v, to: M }) => ({ from: v, to: M })) }), o.set(s(p), y), { type: "element", tagName: "span", properties: {}, position: p.position, children: [p] };
451
+ }));
452
+ };
453
+ f(i);
454
+ }, afterSanitize: () => (i) => {
455
+ const f = (l) => {
456
+ l.type === "element" && l.position?.start?.line && (l.properties = {
457
+ ...l.properties,
458
+ dataExmdSourceLine: l.position.start.line,
459
+ dataExmdSourceEndLine: l.position.end?.line ?? l.position.start.line
460
+ });
461
+ const b = l.tagName === "span" ? o.get(s(l)) : void 0;
462
+ b !== void 0 && l.children?.length === 1 && l.children[0].type === "text" && l.children[0].value === n.runs.get(b)?.value && (l.properties = { ...l.properties, dataExmdText: b }), l.children?.forEach(f);
463
+ };
464
+ f(i);
465
+ } };
466
+ }
467
+ function It(t, e) {
468
+ const r = [], n = t.ownerDocument.createTreeWalker(
469
+ t,
470
+ 4
471
+ /* SHOW_TEXT */
472
+ );
473
+ for (let o = n.nextNode(); o; o = n.nextNode()) {
474
+ const s = o.parentElement?.closest("[data-exmd-text]"), d = s && e.runs.get(s.dataset.exmdText);
475
+ d && o.nodeValue === d.value && t.contains(s) && r.push({ node: o, run: d });
476
+ }
477
+ return r;
478
+ }
479
+ function bt(t, e) {
480
+ const r = t.ownerDocument.getSelection();
481
+ if (!r || r.isCollapsed || r.rangeCount !== 1) return null;
482
+ const n = r.getRangeAt(0);
483
+ if (!t.contains(n.startContainer) || !t.contains(n.endContainer)) return null;
484
+ const o = new Map(It(t, e).map((a) => [a.node, a.run]));
485
+ let s, d;
486
+ const u = t.ownerDocument.createTreeWalker(t, 4);
487
+ for (let a = u.nextNode(); a; a = u.nextNode()) {
488
+ if (!n.intersectsNode(a)) continue;
489
+ const i = a === n.startContainer ? n.startOffset : 0, f = a === n.endContainer ? n.endOffset : a.nodeValue.length;
490
+ if (i >= f) continue;
491
+ const l = o.get(a);
492
+ if (!l) {
493
+ if (a.nodeValue.slice(i, f).trim()) return null;
494
+ continue;
495
+ }
496
+ if (!l.characters[i] || !l.characters[f - 1]) return null;
497
+ s ??= l.characters[i].from, d = l.characters[f - 1].to;
498
+ }
499
+ for (const a of t.querySelectorAll("img,svg,.katex,pre")) if (n.intersectsNode(a)) return null;
500
+ return s !== void 0 && d !== void 0 && s < d ? { from: s, to: d, range: n.cloneRange() } : null;
501
+ }
502
+ function Pn(t, e, r, n) {
503
+ const o = [];
504
+ for (const { node: s, run: d } of It(t, e)) {
505
+ let u = -1, a = -1;
506
+ if (d.characters.forEach((f, l) => {
507
+ f.to > r && f.from < n && (u < 0 && (u = l), a = l + 1);
508
+ }), u < 0) continue;
509
+ const i = t.ownerDocument.createRange();
510
+ i.setStart(s, u), i.setEnd(s, a), o.push(i);
511
+ }
512
+ return o;
513
+ }
514
+ function yt(t) {
515
+ const e = /* @__PURE__ */ new Map(), r = [], n = [];
516
+ for (const o of t.querySelectorAll("[data-exmd-preview-kind]")) {
517
+ const s = o.dataset.exmdPreviewKind;
518
+ if (s !== "image" && s !== "mermaid") continue;
519
+ const d = o.dataset.exmdPreviewKey || "", u = `${s}:${d.length}:${d}`, a = e.get(u) || 0;
520
+ e.set(u, a + 1);
521
+ const i = {
522
+ id: `${u}:${a}`,
523
+ kind: s,
524
+ alt: o.getAttribute("alt") || o.dataset.exmdPreviewAlt || ""
525
+ }, f = o.getAttribute("title");
526
+ f && (i.title = f);
527
+ const l = o.dataset.exmdPreviewFrom, b = o.dataset.exmdPreviewTo;
528
+ if (l !== void 0 && b !== void 0 && (i.source = { from: Number(l), to: Number(b) }), s === "image") {
529
+ const p = o;
530
+ i.path = d, i.src = p.getAttribute("src") || void 0, p.naturalWidth && (i.width = p.naturalWidth), p.naturalHeight && (i.height = p.naturalHeight);
531
+ } else {
532
+ const p = o.querySelector("svg");
533
+ if (!p) continue;
534
+ const h = t.ownerDocument.defaultView?.XMLSerializer;
535
+ if (!h) continue;
536
+ i.src = `data:image/svg+xml;charset=utf-8,${encodeURIComponent(new h().serializeToString(p))}`, p.viewBox.baseVal.width && (i.width = p.viewBox.baseVal.width), p.viewBox.baseVal.height && (i.height = p.viewBox.baseVal.height);
537
+ }
538
+ r.push(o), n.push(i);
539
+ }
540
+ return { elements: r, images: n };
541
+ }
542
+ const Me = () => ({ scale: 1, x: 0, y: 0 });
543
+ function Cn({ images: t, index: e, onClose: r, locale: n, messages: o }) {
544
+ const [s, d] = V(e), [u, a] = V(Me), [i, f] = V(!1), [l, b] = V(!1), p = A(null), h = A(null), k = A(null), C = A(u), y = A({ onClose: r, active: s, images: t });
545
+ C.current = u, y.current = { onClose: r, active: s, images: t };
546
+ const v = t[s], M = (E, S) => D(n, E, S, o), _ = (E) => {
547
+ d((S) => Math.max(0, Math.min(t.length - 1, S + E)));
548
+ }, R = (E) => a((S) => ({ ...S, scale: Math.max(0.2, Math.min(8, S.scale * E)) }));
549
+ K(() => {
550
+ d(e);
551
+ }, [e]), K(() => {
552
+ k.current = null, f(!1), a(Me()), b(!1);
553
+ }, [s, v?.src]), K(() => {
554
+ const E = document.activeElement instanceof HTMLElement ? document.activeElement : null, S = document.body.style.overflow;
555
+ document.body.style.overflow = "hidden", p.current?.focus();
556
+ const w = (g) => {
557
+ if (g.key === "Escape")
558
+ g.preventDefault(), g.stopPropagation(), y.current.onClose();
559
+ else if (g.key === "ArrowLeft" || g.key === "ArrowRight") {
560
+ g.preventDefault(), g.stopPropagation();
561
+ const P = g.key === "ArrowLeft" ? -1 : 1;
562
+ d((j) => Math.max(0, Math.min(y.current.images.length - 1, j + P)));
563
+ } else if (g.key === "Tab") {
564
+ const P = Array.from(p.current?.querySelectorAll("button:not(:disabled)") || []), j = P[0], $ = P.at(-1);
565
+ if (!j || !$) {
566
+ g.preventDefault();
567
+ return;
568
+ }
569
+ const z = document.activeElement;
570
+ g.shiftKey && (z === j || z === p.current) ? (g.preventDefault(), $.focus()) : !g.shiftKey && (z === $ || z === p.current) && (g.preventDefault(), j.focus());
571
+ }
572
+ }, F = (g) => {
573
+ g.target instanceof Node && !p.current?.contains(g.target) && p.current?.focus();
574
+ };
575
+ return document.addEventListener("keydown", w, !0), document.addEventListener("focusin", F), () => {
576
+ document.removeEventListener("keydown", w, !0), document.removeEventListener("focusin", F), document.body.style.overflow = S, E?.isConnected && E.focus({ preventScroll: !0 });
577
+ };
578
+ }, []), K(() => {
579
+ const E = h.current;
580
+ if (!E) return;
581
+ const S = (w) => {
582
+ w.preventDefault(), a((F) => ({ ...F, scale: Math.max(0.2, Math.min(8, F.scale * Math.exp(-w.deltaY * 2e-3))) }));
583
+ };
584
+ return E.addEventListener("wheel", S, { passive: !1 }), () => E.removeEventListener("wheel", S);
585
+ }, []);
586
+ const O = (E) => {
587
+ if (k.current) {
588
+ k.current.singlePointer = !1;
589
+ return;
590
+ }
591
+ E.button === 0 && (E.preventDefault(), k.current = {
592
+ pointerId: E.pointerId,
593
+ type: E.pointerType,
594
+ startX: E.clientX,
595
+ startY: E.clientY,
596
+ view: C.current,
597
+ moved: !1,
598
+ backdrop: E.target === E.currentTarget,
599
+ singlePointer: !0
600
+ }, E.currentTarget.setPointerCapture(E.pointerId), f(!0));
601
+ }, re = (E) => {
602
+ const S = k.current;
603
+ if (!S || S.pointerId !== E.pointerId) return;
604
+ const w = E.clientX - S.startX, F = E.clientY - S.startY;
605
+ Math.hypot(w, F) > 4 && (S.moved = !0), a({ ...S.view, x: S.view.x + w, y: S.view.y + F });
606
+ }, N = (E, S = !1) => {
607
+ const w = k.current;
608
+ if (!w || w.pointerId !== E.pointerId || (k.current = null, f(!1), E.currentTarget.hasPointerCapture(E.pointerId) && E.currentTarget.releasePointerCapture(E.pointerId), S)) return;
609
+ const F = E.clientX - w.startX, g = E.clientY - w.startY;
610
+ w.type === "touch" && w.singlePointer && w.view.scale === 1 && Math.abs(F) >= 60 && Math.abs(F) > Math.abs(g) * 1.5 ? (a(Me()), _(F < 0 ? 1 : -1)) : !w.moved && Math.hypot(F, g) <= 4 && w.backdrop && r();
611
+ };
612
+ return v ? Ct(/* @__PURE__ */ I(
613
+ "div",
614
+ {
615
+ ref: p,
616
+ className: "exmd-image-lightbox",
617
+ role: "dialog",
618
+ "aria-modal": "true",
619
+ "aria-label": M("image.preview"),
620
+ tabIndex: -1,
621
+ children: [
622
+ /* @__PURE__ */ I("div", { className: "exmd-image-lightbox-toolbar", children: [
623
+ /* @__PURE__ */ c("span", { className: "exmd-image-lightbox-title", children: v.title || v.alt || M(v.kind === "mermaid" ? "image.diagram" : "image.image") }),
624
+ /* @__PURE__ */ c("span", { className: "exmd-image-lightbox-counter", "aria-live": "polite", children: M("image.counter", { current: s + 1, total: t.length }) }),
625
+ /* @__PURE__ */ c("button", { type: "button", "aria-label": M("image.zoomOut"), title: M("image.zoomOut"), onClick: () => R(1 / 1.25), disabled: u.scale <= 0.2, children: /* @__PURE__ */ c(pr, {}) }),
626
+ /* @__PURE__ */ I("span", { className: "exmd-image-lightbox-scale", children: [
627
+ Math.round(u.scale * 100),
628
+ "%"
629
+ ] }),
630
+ /* @__PURE__ */ c("button", { type: "button", "aria-label": M("image.zoomIn"), title: M("image.zoomIn"), onClick: () => R(1.25), disabled: u.scale >= 8, children: /* @__PURE__ */ c(hr, {}) }),
631
+ /* @__PURE__ */ c("button", { type: "button", "aria-label": M("image.reset"), title: M("image.reset"), onClick: () => a(Me()), children: /* @__PURE__ */ c(vr, {}) }),
632
+ /* @__PURE__ */ c("button", { type: "button", className: "exmd-image-lightbox-close", "aria-label": M("image.close"), title: M("image.close"), onClick: r, children: /* @__PURE__ */ c(wr, {}) })
633
+ ] }),
634
+ /* @__PURE__ */ c(
635
+ "div",
636
+ {
637
+ ref: h,
638
+ className: `exmd-image-lightbox-stage${i ? " is-dragging" : ""}`,
639
+ onPointerDown: O,
640
+ onPointerMove: re,
641
+ onPointerUp: (E) => N(E),
642
+ onPointerCancel: (E) => N(E, !0),
643
+ onLostPointerCapture: () => {
644
+ k.current = null, f(!1);
645
+ },
646
+ children: v.src && !l ? /* @__PURE__ */ c(
647
+ "img",
648
+ {
649
+ className: "exmd-image-lightbox-image",
650
+ src: v.src,
651
+ alt: v.alt,
652
+ draggable: !1,
653
+ style: { transform: `translate(${u.x}px, ${u.y}px) scale(${u.scale})` },
654
+ onError: () => b(!0)
655
+ }
656
+ ) : /* @__PURE__ */ c("p", { className: "exmd-image-lightbox-unavailable", role: "status", children: M("image.unavailable") })
657
+ }
658
+ ),
659
+ t.length > 1 && /* @__PURE__ */ I(le, { children: [
660
+ /* @__PURE__ */ c(
661
+ "button",
662
+ {
663
+ type: "button",
664
+ className: "exmd-image-lightbox-previous",
665
+ "aria-label": M("image.previous"),
666
+ title: M("image.previous"),
667
+ onClick: () => _(-1),
668
+ disabled: s === 0,
669
+ children: /* @__PURE__ */ c(br, {})
670
+ }
671
+ ),
672
+ /* @__PURE__ */ c(
673
+ "button",
674
+ {
675
+ type: "button",
676
+ className: "exmd-image-lightbox-next",
677
+ "aria-label": M("image.next"),
678
+ title: M("image.next"),
679
+ onClick: () => _(1),
680
+ disabled: s === t.length - 1,
681
+ children: /* @__PURE__ */ c(yr, {})
682
+ }
683
+ )
684
+ ] }),
685
+ /* @__PURE__ */ c("p", { className: "exmd-image-lightbox-hint", children: M("image.hint") })
686
+ ]
687
+ }
688
+ ), document.body) : null;
689
+ }
690
+ const Fn = {
691
+ ...He,
692
+ attributes: { ...He.attributes, span: [...He.attributes?.span || [], "dataColor"] }
693
+ }, Sn = {
694
+ a: ({ children: t, ...e }) => /* @__PURE__ */ c("a", { ...e, target: "_blank", rel: "noreferrer", children: t }),
695
+ span: ({ node: t, children: e, ...r }) => {
696
+ const n = t?.properties?.dataColor, o = typeof n == "string" && /^#[0-9a-fA-F]{6}$/.test(n) ? n : void 0;
697
+ return /* @__PURE__ */ c("span", { ...r, style: o ? { ...r.style, color: o } : r.style, children: e });
698
+ },
699
+ pre: ({ children: t, node: e }) => /* @__PURE__ */ c("div", { "data-exmd-source-line": e?.position?.start.line, "data-exmd-source-end-line": e?.position?.end.line, children: t })
700
+ }, Tn = We(function({ value: e, resolveImageUrl: r, onImagePreview: n, interaction: o, locale: s, messages: d }) {
701
+ const u = A(null), [a, i] = V(null);
702
+ K(() => i(null), [e, r, n]);
703
+ const f = a !== null;
704
+ K(() => {
705
+ const h = u.current;
706
+ if (!f || !h) return;
707
+ const k = () => {
708
+ const y = new Map(yt(h).images.map((v) => [v.id, v]));
709
+ i((v) => {
710
+ if (!v) return null;
711
+ const M = v.images.map((_) => y.get(_.id) || _);
712
+ return { images: M, index: v.index, image: M[v.index] };
713
+ });
714
+ }, C = new MutationObserver(k);
715
+ return C.observe(h, { attributes: !0, subtree: !0, attributeFilter: ["src"] }), h.addEventListener("load", k, !0), () => {
716
+ C.disconnect(), h.removeEventListener("load", k, !0);
717
+ };
718
+ }, [f]);
719
+ const l = Ee((h) => {
720
+ const k = u.current;
721
+ if (!k || !h || !h.closest) return !1;
722
+ const C = h.closest("[data-exmd-preview-kind]");
723
+ if (!C || !k.contains(C)) return !1;
724
+ const { elements: y, images: v } = yt(k), M = y.indexOf(C);
725
+ if (M < 0) return !1;
726
+ const _ = { image: v[M], images: v, index: M };
727
+ return n ? n(_) : i(_), !0;
728
+ }, [n]), b = J(() => o ? En(e) : null, [e, o]);
729
+ Pt(() => {
730
+ if (u.current && b && o) return o.attach(u.current, b.mapping);
731
+ }, [b, o]);
732
+ const p = J(() => ({
733
+ ...Sn,
734
+ code: ({ className: h, children: k, ...C }) => {
735
+ const y = /language-([\w-]+)/.exec(h || ""), v = String(k);
736
+ return y?.[1] === "mermaid" ? /* @__PURE__ */ c(
737
+ "div",
738
+ {
739
+ "data-exmd-preview-kind": "mermaid",
740
+ "data-exmd-preview-key": v,
741
+ "data-exmd-preview-from": C.node?.position?.start.offset,
742
+ "data-exmd-preview-to": C.node?.position?.end.offset,
743
+ "data-exmd-preview-alt": D(s, "image.diagram", void 0, d),
744
+ role: "button",
745
+ tabIndex: 0,
746
+ "aria-label": D(s, "image.open", { name: D(s, "image.diagram", void 0, d) }, d),
747
+ children: /* @__PURE__ */ c(wn, { code: v.replace(/\n$/, ""), locale: s, messages: d })
748
+ }
749
+ ) : y ? /* @__PURE__ */ c(Mn, { code: v, language: y[1] }) : /* @__PURE__ */ c("code", { className: h, ...C, children: k });
750
+ },
751
+ img: ({ node: h, alt: k, src: C, ...y }) => /* @__PURE__ */ c(
752
+ An,
753
+ {
754
+ ...y,
755
+ alt: k || "",
756
+ path: C || "",
757
+ resolveUrl: r,
758
+ "data-exmd-preview-kind": "image",
759
+ "data-exmd-preview-key": C || "",
760
+ "data-exmd-preview-from": h?.position?.start.offset,
761
+ "data-exmd-preview-to": h?.position?.end.offset,
762
+ role: "button",
763
+ tabIndex: 0,
764
+ "aria-label": D(s, "image.open", { name: k || D(s, "image.image", void 0, d) }, d)
765
+ }
766
+ )
767
+ }), [r, s, d]);
768
+ return /* @__PURE__ */ I(le, { children: [
769
+ /* @__PURE__ */ c("article", { ref: u, className: "markdown-body", onClick: (h) => {
770
+ l(h.target) && (h.preventDefault(), h.stopPropagation());
771
+ }, onKeyDown: (h) => {
772
+ (h.key === "Enter" || h.key === " ") && l(h.target) && (h.preventDefault(), h.stopPropagation());
773
+ }, children: /* @__PURE__ */ c(Rr, { remarkPlugins: [Lr, Nr], rehypePlugins: [
774
+ ...b ? [b.beforeRaw] : [],
775
+ // No raw HTML can exist without '<'. Keep sanitization on both paths.
776
+ ...e.includes("<") ? [Ur] : [],
777
+ [_r, Fn],
778
+ ...b ? [b.afterSanitize] : [],
779
+ Or
780
+ ], components: p, children: e }) }),
781
+ a && /* @__PURE__ */ c(Cn, { images: a.images, index: a.index, onClose: () => i(null), locale: s, messages: d })
782
+ ] });
783
+ });
784
+ function An({ path: t, resolveUrl: e, alt: r, ...n }) {
785
+ const [o, s] = V(null), d = e ? o?.path === t && o.resolveUrl === e ? o.src : "" : t;
786
+ return K(() => {
787
+ let u = !0;
788
+ if (e)
789
+ return Promise.resolve().then(() => e(t)).then((a) => {
790
+ u && s({ path: t, resolveUrl: e, src: a });
791
+ }).catch(() => {
792
+ u && s({ path: t, resolveUrl: e, src: "" });
793
+ }), () => {
794
+ u = !1;
795
+ };
796
+ }, [t, e]), /* @__PURE__ */ c("img", { ...n, src: d || void 0, alt: r || "", loading: "lazy" });
797
+ }
798
+ const Dn = [
799
+ { id: "heading1", label: "H1", titleKey: "format.heading1", prefix: "# ", block: !0 },
800
+ { id: "heading2", label: "H2", titleKey: "format.heading2", prefix: "## ", block: !0 },
801
+ { id: "heading3", label: "H3", titleKey: "format.heading3", prefix: "### ", block: !0 },
802
+ { id: "heading4", label: "H4", titleKey: "format.heading4", prefix: "#### ", block: !0 },
803
+ { id: "heading5", label: "H5", titleKey: "format.heading5", prefix: "##### ", block: !0 },
804
+ { id: "bold", label: "B", titleKey: "format.bold", prefix: "**", suffix: "**", placeholderKey: "format.boldPlaceholder" },
805
+ { id: "italic", label: "I", titleKey: "format.italic", prefix: "*", suffix: "*", placeholderKey: "format.italicPlaceholder" },
806
+ { id: "strike", label: "S", titleKey: "format.strike", prefix: "~~", suffix: "~~", placeholderKey: "format.strikePlaceholder" },
807
+ { id: "code", label: "</>", titleKey: "format.inlineCode", prefix: "`", suffix: "`", placeholderKey: "format.codePlaceholder" },
808
+ { id: "quote", label: "“", titleKey: "format.quote", prefix: "> ", block: !0 },
809
+ { id: "bullet", label: "•", titleKey: "format.bulletList", prefix: "- ", block: !0 },
810
+ { id: "ordered", label: "1.", titleKey: "format.orderedList", prefix: "1. ", block: !0 },
811
+ { id: "task", label: "☑", titleKey: "format.task", prefix: "- [ ] ", block: !0 },
812
+ { id: "link", label: "↗", titleKey: "format.link", prefix: "[", suffix: "](https://)", placeholderKey: "format.linkPlaceholder" }
813
+ ];
814
+ function In(t, e) {
815
+ const r = t.state.selection.main, n = t.state.sliceDoc(r.from, r.to);
816
+ if (e.block) {
817
+ const o = t.state.doc.lineAt(r.from), s = e.prefix;
818
+ t.dispatch({ changes: { from: o.from, insert: s }, selection: { anchor: r.from + s.length, head: r.to + s.length } });
819
+ } else {
820
+ const o = n || e.placeholder || "", s = `${e.prefix}${o}${e.suffix || ""}`, d = r.from + e.prefix.length;
821
+ t.dispatch({ changes: { from: r.from, to: r.to, insert: s }, selection: { anchor: d, head: d + o.length } });
822
+ }
823
+ t.focus();
824
+ }
825
+ function he(t, e) {
826
+ const r = t.state.selection.main;
827
+ t.dispatch({ changes: { from: r.from, to: r.to, insert: e }, selection: { anchor: r.from + e.length } }), t.focus();
828
+ }
829
+ function Rn(t, e, r) {
830
+ return { label: t.label, title: e, prefix: t.prefix, suffix: t.suffix, placeholder: r, block: t.block };
831
+ }
832
+ function Ln(t) {
833
+ const e = t.readOnly, r = (n) => D(t.locale, n, void 0, t.messages);
834
+ return /* @__PURE__ */ I("div", { className: "toolbar", role: "toolbar", "aria-label": r("toolbar.label"), children: [
835
+ /* @__PURE__ */ I("div", { className: "tool-group history-tools", children: [
836
+ /* @__PURE__ */ c("button", { disabled: e, onClick: t.onUndo, title: r("toolbar.undo"), children: /* @__PURE__ */ c(xr, {}) }),
837
+ /* @__PURE__ */ c("button", { disabled: e, onClick: t.onRedo, title: r("toolbar.redo"), children: /* @__PURE__ */ c(kr, {}) })
838
+ ] }),
839
+ /* @__PURE__ */ c("div", { className: "tool-divider" }),
840
+ /* @__PURE__ */ c("div", { className: "tool-group format-tools", children: Dn.map((n) => {
841
+ const o = r(n.titleKey);
842
+ return /* @__PURE__ */ c("button", { disabled: e, onClick: () => t.onAction(Rn(n, o, n.placeholderKey ? r(n.placeholderKey) : void 0)), title: o, className: n.label === "I" ? "italic" : "", children: n.label }, n.id);
843
+ }) }),
844
+ /* @__PURE__ */ c("div", { className: "tool-divider" }),
845
+ /* @__PURE__ */ I("div", { className: "tool-group rich-tools", children: [
846
+ /* @__PURE__ */ I("select", { disabled: e, defaultValue: "", "aria-label": r("toolbar.insertCode"), title: r("toolbar.insertCode"), onChange: (n) => {
847
+ n.target.value && t.onCodeBlock(n.target.value), n.target.value = "";
848
+ }, children: [
849
+ /* @__PURE__ */ c("option", { value: "", disabled: !0, children: r("toolbar.codeLanguage") }),
850
+ /* @__PURE__ */ c("option", { value: "typescript", children: "TypeScript" }),
851
+ /* @__PURE__ */ c("option", { value: "javascript", children: "JavaScript" }),
852
+ /* @__PURE__ */ c("option", { value: "tsx", children: "TSX" }),
853
+ /* @__PURE__ */ c("option", { value: "python", children: "Python" }),
854
+ /* @__PURE__ */ c("option", { value: "java", children: "Java" }),
855
+ /* @__PURE__ */ c("option", { value: "go", children: "Go" }),
856
+ /* @__PURE__ */ c("option", { value: "rust", children: "Rust" }),
857
+ /* @__PURE__ */ c("option", { value: "cpp", children: "C++" }),
858
+ /* @__PURE__ */ c("option", { value: "csharp", children: "C#" }),
859
+ /* @__PURE__ */ c("option", { value: "php", children: "PHP" }),
860
+ /* @__PURE__ */ c("option", { value: "ruby", children: "Ruby" }),
861
+ /* @__PURE__ */ c("option", { value: "swift", children: "Swift" }),
862
+ /* @__PURE__ */ c("option", { value: "kotlin", children: "Kotlin" }),
863
+ /* @__PURE__ */ c("option", { value: "bash", children: "Shell" }),
864
+ /* @__PURE__ */ c("option", { value: "sql", children: "SQL" }),
865
+ /* @__PURE__ */ c("option", { value: "json", children: "JSON" }),
866
+ /* @__PURE__ */ c("option", { value: "yaml", children: "YAML" }),
867
+ /* @__PURE__ */ c("option", { value: "html", children: "HTML" }),
868
+ /* @__PURE__ */ c("option", { value: "css", children: "CSS" }),
869
+ /* @__PURE__ */ c("option", { value: "graphql", children: "GraphQL" }),
870
+ /* @__PURE__ */ c("option", { value: "dockerfile", children: "Dockerfile" }),
871
+ /* @__PURE__ */ c("option", { value: "markdown", children: "Markdown" })
872
+ ] }),
873
+ /* @__PURE__ */ I("label", { className: "color-tool", title: r("toolbar.textColor"), children: [
874
+ /* @__PURE__ */ c("span", { children: "A" }),
875
+ /* @__PURE__ */ c("input", { disabled: e, type: "color", defaultValue: "#d14f4f", "aria-label": r("toolbar.textColor"), onChange: (n) => t.onColor(n.target.value) })
876
+ ] })
877
+ ] }),
878
+ /* @__PURE__ */ c("div", { className: "tool-divider" }),
879
+ /* @__PURE__ */ I("div", { className: "tool-group", children: [
880
+ /* @__PURE__ */ c("button", { disabled: e, onClick: t.onImage, title: r("toolbar.uploadImage"), children: /* @__PURE__ */ c(Mr, {}) }),
881
+ /* @__PURE__ */ c("button", { disabled: e, onClick: t.onDiagram, title: r("toolbar.insertDiagram"), children: /* @__PURE__ */ c(Er, {}) }),
882
+ /* @__PURE__ */ c("button", { disabled: e, onClick: t.onFormula, title: r("toolbar.insertFormula"), children: /* @__PURE__ */ c(Pr, {}) })
883
+ ] }),
884
+ /* @__PURE__ */ c("div", { className: "toolbar-spacer" }),
885
+ t.hostActions,
886
+ /* @__PURE__ */ I("div", { className: "tool-group view-switcher", children: [
887
+ /* @__PURE__ */ c("button", { className: t.mode === "edit" ? "active" : "", onClick: () => t.onModeChange("edit"), title: r("toolbar.viewEdit"), children: /* @__PURE__ */ c(Cr, {}) }),
888
+ /* @__PURE__ */ c("button", { className: t.mode === "split" ? "active" : "", onClick: () => t.onModeChange("split"), title: r("toolbar.viewSplit"), children: /* @__PURE__ */ c(Fr, {}) }),
889
+ /* @__PURE__ */ c("button", { className: t.mode === "preview" ? "active" : "", onClick: () => t.onModeChange("preview"), title: r("toolbar.viewPreview"), children: /* @__PURE__ */ c(Sr, {}) })
890
+ ] })
891
+ ] });
892
+ }
893
+ function xt({ actions: t, context: e, capture: r }) {
894
+ return /* @__PURE__ */ c("div", { className: "exmd-host-actions", children: t.map((n) => /* @__PURE__ */ c(
895
+ "button",
896
+ {
897
+ type: "button",
898
+ title: n.title,
899
+ "aria-label": n.title,
900
+ disabled: n.disabled || n.requiresSelection !== !1 && !e.anchor,
901
+ onPointerDown: (o) => o.preventDefault(),
902
+ onMouseDown: (o) => o.preventDefault(),
903
+ onClick: () => {
904
+ const o = r();
905
+ !n.disabled && (n.requiresSelection === !1 || o.anchor) && n.onClick(o);
906
+ },
907
+ children: n.icon || n.title
908
+ },
909
+ n.id
910
+ )) });
911
+ }
912
+ function Pe(t) {
913
+ return { bytes: U.encodeRelativePosition(t) };
914
+ }
915
+ function kt(t) {
916
+ return U.decodeRelativePosition(new Uint8Array(t.bytes));
917
+ }
918
+ function Ce(t, e) {
919
+ if (!Number.isInteger(e) || e < 0 || e > t.length) throw new RangeError("Invalid Markdown text position");
920
+ }
921
+ function Nn(t, e, r) {
922
+ return Ce(t, e), Ce(t, r), {
923
+ kind: "text",
924
+ anchor: Pe(U.createRelativePositionFromTypeIndex(t, e)),
925
+ focus: Pe(U.createRelativePositionFromTypeIndex(t, r))
926
+ };
927
+ }
928
+ function Qo(t, e, r) {
929
+ const n = Ge(t, e, r);
930
+ return n ? { from: Math.min(n.anchor, n.focus), to: Math.max(n.anchor, n.focus) } : null;
931
+ }
932
+ function Ge(t, e, r) {
933
+ try {
934
+ if (r.kind !== "text") return null;
935
+ const n = U.createAbsolutePositionFromRelativePosition(kt(r.anchor), t, !1), o = U.createAbsolutePositionFromRelativePosition(kt(r.focus), t, !1);
936
+ return !n || !o || n.type !== e || o.type !== e ? null : { anchor: n.index, focus: o.index };
937
+ } catch {
938
+ return null;
939
+ }
940
+ }
941
+ function Rt(t, e, r) {
942
+ if (Ce(t, e), Ce(t, r), e >= r) throw new RangeError("A comment anchor requires a nonempty forward range");
943
+ return {
944
+ kind: "markdown-text-range",
945
+ start: Pe(U.createRelativePositionFromTypeIndex(t, e, 0)),
946
+ end: Pe(U.createRelativePositionFromTypeIndex(t, r, -1)),
947
+ content: On(t, e, r)
948
+ };
949
+ }
950
+ function ve(t, e, r) {
951
+ if (!r || r.kind !== "markdown-text-range" || !Array.isArray(r.content) || !r.content.length || r.content && (!Array.isArray(r.content) || r.content.some((o) => !o || !Number.isSafeInteger(o.client) || o.client < 0 || !Number.isSafeInteger(o.clock) || o.clock < 0 || !Number.isSafeInteger(o.length) || o.length <= 0))) return null;
952
+ if (r.content?.length) {
953
+ const o = U.createDeleteSetFromStructStore(t.store);
954
+ if (r.content.every((d) => {
955
+ let u = d.clock;
956
+ for (const a of o.clients.get(d.client) || []) {
957
+ if (a.clock > u) break;
958
+ if (a.clock + a.len > u && (u = a.clock + a.len), u >= d.clock + d.length) return !0;
959
+ }
960
+ return !1;
961
+ })) return null;
962
+ }
963
+ const n = Ge(t, e, { kind: "text", anchor: r.start, focus: r.end });
964
+ return n && n.anchor < n.focus ? { from: n.anchor, to: n.focus } : null;
965
+ }
966
+ function On(t, e, r) {
967
+ const n = t.doc;
968
+ if (!n) throw new Error("The text must belong to a Y.Doc");
969
+ const o = [];
970
+ for (const s of n.store.clients.values())
971
+ for (const d of s) {
972
+ if (!(d instanceof U.Item) || d.parent !== t || d.deleted || !d.countable) continue;
973
+ const u = U.createAbsolutePositionFromRelativePosition(
974
+ U.createRelativePositionFromJSON({ item: d.id, assoc: 0 }),
975
+ n,
976
+ !1
977
+ );
978
+ if (!u) continue;
979
+ const a = Math.max(e, u.index), i = Math.min(r, u.index + d.length);
980
+ a < i && o.push({ client: d.id.client, clock: d.id.clock + a - u.index, length: i - a });
981
+ }
982
+ return o;
983
+ }
984
+ function Un(t, e) {
985
+ let r, n, o = [], s = null, d = null, u = !1, a = () => {
986
+ };
987
+ const i = () => !!(r && n && n.source === t.toString()), f = () => {
988
+ if (!i()) return null;
989
+ const p = bt(r, n);
990
+ return p ? Rt(t, p.from, p.to) : null;
991
+ }, l = (p) => {
992
+ const h = t.doc && ve(t.doc, t, p);
993
+ return i() && h ? Pn(r, n, h.from, h.to) : [];
994
+ };
995
+ return {
996
+ capture: f,
997
+ selectionRect: () => i() && bt(r, n)?.range.getBoundingClientRect() || null,
998
+ clearSelection: () => {
999
+ d = null, u = !1;
1000
+ },
1001
+ setComments: (p) => {
1002
+ o = [...new Map(p.map((h) => [h.id, h])).values()], a();
1003
+ },
1004
+ setActive: (p) => {
1005
+ s = p, a();
1006
+ },
1007
+ reveal: (p) => {
1008
+ const h = l(p);
1009
+ return h.length ? (e.activate(), h[0].startContainer.parentElement?.scrollIntoView({ block: "center", inline: "nearest" }), a(), !0) : !1;
1010
+ },
1011
+ attach: (p, h) => {
1012
+ r = p, n = h;
1013
+ const k = r.ownerDocument, C = k.defaultView, y = k.createElement("div");
1014
+ y.className = "exmd-preview-annotations", y.setAttribute("aria-hidden", "true"), Object.assign(y.style, { position: "fixed", inset: "0", pointerEvents: "none", zIndex: "4" }), k.body.append(y);
1015
+ let v = 0, M = [];
1016
+ const _ = () => {
1017
+ if (v = 0, y.replaceChildren(), M = [], !o.length || !i() || !p.getClientRects().length) return;
1018
+ let w = { left: 0, top: 0, right: C.innerWidth, bottom: C.innerHeight };
1019
+ for (let F = p; F; F = F.parentElement) {
1020
+ const g = C.getComputedStyle(F);
1021
+ if (/(auto|scroll|hidden|clip)/.test(g.overflow + g.overflowX + g.overflowY)) {
1022
+ const P = F.getBoundingClientRect();
1023
+ w = {
1024
+ left: Math.max(w.left, P.left),
1025
+ right: Math.min(w.right, P.right),
1026
+ top: Math.max(w.top, P.top),
1027
+ bottom: Math.min(w.bottom, P.bottom)
1028
+ };
1029
+ }
1030
+ if (F.classList.contains("preview-pane")) {
1031
+ const P = F.querySelector(".pane-label")?.getBoundingClientRect();
1032
+ P && (w.top = Math.max(w.top, P.bottom));
1033
+ }
1034
+ }
1035
+ for (const F of o)
1036
+ if (!(F.resolved || F.deleted))
1037
+ for (const g of l(F.anchor)) for (const P of g.getClientRects()) {
1038
+ const j = Math.max(P.left, w.left), $ = Math.min(P.right, w.right), z = Math.max(P.top, w.top), Q = Math.min(P.bottom, w.bottom);
1039
+ if ($ <= j || Q <= z) continue;
1040
+ const W = k.createElement("span");
1041
+ W.dataset.commentId = F.id, W.className = "exmd-preview-comment" + (F.id === s ? " exmd-preview-comment-active" : ""), Object.assign(W.style, {
1042
+ position: "absolute",
1043
+ left: j + "px",
1044
+ top: z + "px",
1045
+ width: $ - j + "px",
1046
+ height: Q - z + "px",
1047
+ boxSizing: "border-box",
1048
+ borderBottom: "2px solid #d8a12c",
1049
+ background: F.id === s ? "#ffd86666" : "transparent"
1050
+ }), y.append(W), M.push({ id: F.id, left: j, right: $, top: z, bottom: Q });
1051
+ }
1052
+ };
1053
+ a = () => {
1054
+ v || (v = C.requestAnimationFrame(_));
1055
+ };
1056
+ const R = () => {
1057
+ const w = k.getSelection(), F = w?.anchorNode && p.contains(w.anchorNode);
1058
+ !F && !e.isActive() || i() && (F && e.activate(), e.isActive() && (d = f(), e.selectionChanged()));
1059
+ }, O = () => {
1060
+ e.activate(), d = null, u = !1;
1061
+ }, re = (w) => {
1062
+ if (!i() || !k.getSelection()?.isCollapsed) return;
1063
+ const F = [...new Set(M.filter((P) => w.clientX >= P.left && w.clientX <= P.right && w.clientY >= P.top && w.clientY <= P.bottom).map((P) => P.id))];
1064
+ if (!F.length) return;
1065
+ w.preventDefault();
1066
+ const g = F[(F.indexOf(s || "") + 1) % F.length];
1067
+ e.click(g);
1068
+ }, N = () => {
1069
+ u = e.isActive() && !!d, a();
1070
+ };
1071
+ p.addEventListener("pointerdown", O), p.addEventListener("click", re), k.addEventListener("selectionchange", R), k.addEventListener("scroll", a, !0), C.addEventListener("resize", a), C.visualViewport?.addEventListener("resize", a), C.visualViewport?.addEventListener("scroll", a);
1072
+ const E = new ResizeObserver(a);
1073
+ E.observe(p);
1074
+ const S = new MutationObserver(a);
1075
+ for (let w = p; w; w = w.parentElement)
1076
+ S.observe(w, { attributes: !0, attributeFilter: ["style", "class"] });
1077
+ if (k.fonts?.addEventListener("loadingdone", a), t.observe(N), u && d && e.isActive()) {
1078
+ const w = l(d);
1079
+ if (w.length) {
1080
+ const F = k.createRange(), g = w[w.length - 1];
1081
+ F.setStart(w[0].startContainer, w[0].startOffset), F.setEnd(g.endContainer, g.endOffset);
1082
+ const P = k.getSelection();
1083
+ P?.removeAllRanges(), P?.addRange(F);
1084
+ } else
1085
+ d = null, k.getSelection()?.removeAllRanges();
1086
+ }
1087
+ return u = !1, a(), () => {
1088
+ p.removeEventListener("pointerdown", O), p.removeEventListener("click", re), k.removeEventListener("selectionchange", R), k.removeEventListener("scroll", a, !0), C.removeEventListener("resize", a), C.visualViewport?.removeEventListener("resize", a), C.visualViewport?.removeEventListener("scroll", a), E.disconnect(), S.disconnect(), k.fonts?.removeEventListener("loadingdone", a), t.unobserve(N), C.cancelAnimationFrame(v), y.remove(), r = void 0, n = void 0, a = () => {
1089
+ };
1090
+ };
1091
+ }
1092
+ };
1093
+ }
1094
+ function _n(t, e, r) {
1095
+ if (r.button !== 0 || r.shiftKey || r.ctrlKey || r.metaKey || r.altKey) return !1;
1096
+ const n = r.target;
1097
+ if (n !== e && n !== t.dom.parentElement && n !== t.dom && n !== t.scrollDOM && n !== t.contentDOM) return !1;
1098
+ const o = e.getBoundingClientRect(), s = o.width / e.offsetWidth, d = o.height / e.offsetHeight;
1099
+ if (r.clientX < o.left + e.clientLeft * s || r.clientX >= o.left + (e.clientLeft + e.clientWidth) * s || r.clientY >= o.top + (e.clientTop + e.clientHeight) * d) return !1;
1100
+ const u = t.state.doc.length, a = t.coordsAtPos(u);
1101
+ return !a || r.clientY < a.bottom ? !1 : (t.dispatch({ selection: { anchor: u }, scrollIntoView: !0 }), t.focus(), !0);
1102
+ }
1103
+ function Mt(t) {
1104
+ if (t.length >= 1e4) return 150;
1105
+ let e = 1;
1106
+ for (let r = 0; r < t.length; r++) if (t[r] === `
1107
+ ` && ++e >= 500) return 150;
1108
+ return 0;
1109
+ }
1110
+ function zn(t, e, r) {
1111
+ const n = r === void 0 ? Mt(t) : Number.isFinite(r) ? Math.min(2e3, Math.max(0, r)) : Mt(t), [o, s] = V(t), d = A(e);
1112
+ return Pt(() => {
1113
+ const u = e && !d.current;
1114
+ if (d.current = e, !e) return;
1115
+ if (u || n === 0) {
1116
+ s(t);
1117
+ return;
1118
+ }
1119
+ const a = window.setTimeout(() => s(t), n);
1120
+ return () => window.clearTimeout(a);
1121
+ }, [t, e, n]), n === 0 ? t : o;
1122
+ }
1123
+ function Bn(t, e) {
1124
+ if (!t.length) return e;
1125
+ if (e <= t[0].source) return t[0].target;
1126
+ for (let r = 1; r < t.length; r++) {
1127
+ const n = t[r - 1], o = t[r];
1128
+ if (e <= o.source) return n.target + (o.target - n.target) * (e - n.source) / Math.max(1, o.source - n.source);
1129
+ }
1130
+ return t[t.length - 1].target;
1131
+ }
1132
+ function Hn(t, e, r) {
1133
+ let n = 0, o = null, s = null, d = "", u = [];
1134
+ const a = () => {
1135
+ const l = t();
1136
+ if (!l) return [];
1137
+ const b = [e.scrollHeight, r.scrollHeight, e.clientWidth, r.clientWidth, l.state.doc.length].join(":");
1138
+ if (d === b && u.length) return u;
1139
+ d = b;
1140
+ const p = l.documentTop - e.getBoundingClientRect().top + e.scrollTop, h = r.getBoundingClientRect().top - r.scrollTop, k = [{ source: 0, target: 0 }], C = /* @__PURE__ */ new Set();
1141
+ for (const y of r.querySelectorAll(".markdown-body > [data-exmd-source-line]")) {
1142
+ const v = Math.max(1, Math.min(l.state.doc.lines, Number(y.dataset.exmdSourceLine)));
1143
+ if (!Number.isFinite(v) || C.has(v)) continue;
1144
+ C.add(v), k.push({ source: p + l.lineBlockAt(l.state.doc.line(v).from).top, target: y.getBoundingClientRect().top - h });
1145
+ const M = Number(y.dataset.exmdSourceEndLine) + 1;
1146
+ M > v && M <= l.state.doc.lines && !C.has(M) && (k.push({ source: p + l.lineBlockAt(l.state.doc.line(M).from).top, target: y.getBoundingClientRect().bottom - h }), C.add(M));
1147
+ }
1148
+ k.push({ source: e.scrollHeight, target: r.scrollHeight }), u = k.sort((y, v) => y.source - v.source).filter((y, v, M) => !v || y.source > M[v - 1].source);
1149
+ for (let y = 1; y < u.length; y++) u[y].target = Math.max(u[y - 1].target, u[y].target);
1150
+ return u;
1151
+ }, i = () => {
1152
+ n = 0;
1153
+ const l = o;
1154
+ if (o = null, !l) return;
1155
+ const b = l === e ? r : e, p = Math.max(0, l.scrollHeight - l.clientHeight), h = Math.max(0, b.scrollHeight - b.clientHeight), k = a(), C = l === e ? k : k.map((v) => ({ source: v.target, target: v.source })).filter((v, M, _) => !M || v.source > _[M - 1].source), y = l.scrollTop <= 1 ? 0 : l.scrollTop >= p - 1 ? h : Math.max(0, Math.min(h, Bn(C, l.scrollTop + l.clientHeight / 2) - b.clientHeight / 2));
1156
+ s = { node: b, top: y }, b.scrollTop = y;
1157
+ }, f = (l) => {
1158
+ const b = l.currentTarget;
1159
+ if (s?.node === b && Math.abs(b.scrollTop - s.top) < 1) {
1160
+ s = null;
1161
+ return;
1162
+ }
1163
+ o = b, n || (n = requestAnimationFrame(i));
1164
+ };
1165
+ return e.addEventListener("scroll", f, { passive: !0 }), r.addEventListener("scroll", f, { passive: !0 }), () => {
1166
+ cancelAnimationFrame(n), e.removeEventListener("scroll", f), r.removeEventListener("scroll", f);
1167
+ };
1168
+ }
1169
+ const Kn = 1, Je = "markdown-ytext", Ze = 1, $n = "markdown", Lt = "exmd:meta", Fe = {
1170
+ bootstrap: /* @__PURE__ */ Symbol("exmd.bootstrap"),
1171
+ remote: /* @__PURE__ */ Symbol("exmd.remote")
1172
+ };
1173
+ function Qe(t) {
1174
+ return t.getText($n);
1175
+ }
1176
+ function Nt(t) {
1177
+ const e = t.getMap(Lt);
1178
+ return {
1179
+ codec: e.get("codec"),
1180
+ schemaVersion: e.get("schemaVersion")
1181
+ };
1182
+ }
1183
+ function Vn(t, e) {
1184
+ const r = Qe(t), n = t.getMap(Lt);
1185
+ t.transact(() => {
1186
+ r.length === 0 && e && r.insert(0, e), n.has("codec") || n.set("codec", Je), n.has("schemaVersion") || n.set("schemaVersion", Ze);
1187
+ }, Fe.bootstrap);
1188
+ }
1189
+ function $e(t) {
1190
+ const e = Nt(t);
1191
+ if (e.codec !== Je) throw new Error(`Unsupported codec: ${e.codec}`);
1192
+ if (e.schemaVersion !== Ze) throw new Error(`Unsupported schema version: ${e.schemaVersion}`);
1193
+ }
1194
+ function ea(t) {
1195
+ return U.encodeStateAsUpdate(t);
1196
+ }
1197
+ const Ve = ["#7357d8", "#d9547a", "#16866f", "#d57828", "#3676c8", "#8a5b3d"], ta = `# 一起写点什么
1198
+
1199
+ 这是一个支持 **实时协作** 的 Markdown 文档。试试从另一个窗口打开相同链接。
1200
+
1201
+ ## 快速开始
1202
+
1203
+ - 使用上方工具栏插入常用格式
1204
+ - 拖入或粘贴图片
1205
+ - 用 Mermaid 描述流程图
1206
+
1207
+ \`\`\`mermaid
1208
+ flowchart LR
1209
+ A[想法] --> B{一起讨论}
1210
+ B --> C[写成文档]
1211
+ B --> D[继续迭代]
1212
+ \`\`\`
1213
+ `;
1214
+ function jn() {
1215
+ const t = localStorage.getItem("collab-markdown:user");
1216
+ if (t)
1217
+ try {
1218
+ return JSON.parse(t);
1219
+ } catch {
1220
+ }
1221
+ const e = {
1222
+ name: `访客 ${Math.floor(100 + Math.random() * 900)}`,
1223
+ color: Ve[Math.floor(Math.random() * Ve.length)]
1224
+ };
1225
+ return localStorage.setItem("collab-markdown:user", JSON.stringify(e)), e;
1226
+ }
1227
+ function qn(t) {
1228
+ const { roomId: e, websocketUrl: r, initialValue: n = "", user: o, persistence: s = !0, persistenceKey: d, readOnly: u = !1, enabled: a = !0, locale: i, messages: f } = t, l = A(i), b = A(f);
1229
+ l.current = i, b.current = f;
1230
+ const p = A(() => {
1231
+ }), h = o?.name, k = o?.color, C = o?.colorLight, y = J(() => {
1232
+ const S = new U.Doc(), w = Qe(S), F = new Ft(S), g = new U.UndoManager(w);
1233
+ return { doc: S, text: w, awareness: F, undoManager: g };
1234
+ }, [e]), [v, M] = V("loading"), [_, R] = V(!1), [O, re] = V([]), [N, E] = V();
1235
+ return K(() => {
1236
+ if (!a) return () => {
1237
+ p.current = () => {
1238
+ }, y.undoManager.destroy(), y.doc.destroy();
1239
+ };
1240
+ const { doc: S, awareness: w, text: F } = y, g = new gn(r, e, S, { awareness: w }), P = s ? new fn(d || `collab-markdown:${e}`, S) : void 0;
1241
+ u ? w.setLocalState(null) : w.setLocalStateField("user", h && k ? { name: h, color: k, colorLight: C } : jn());
1242
+ let j = !P, $ = !1, z = !1;
1243
+ const Q = () => {
1244
+ if (!(z || !j || !$))
1245
+ try {
1246
+ $e(S), Vn(S, n), z = !0, R(!0), M("ready");
1247
+ } catch (B) {
1248
+ E({ code: "SCHEMA_MISMATCH", message: B instanceof Error ? B.message : "文档格式不受支持", retryable: !1, cause: B }), M("error");
1249
+ }
1250
+ };
1251
+ P && P.whenSynced.then(() => {
1252
+ j = !0, (F.length > 0 || Nt(S).codec) && (z = !0, R(!0)), Q();
1253
+ }).catch((B) => {
1254
+ E({ code: "INITIALIZATION_FAILED", message: "本地协同数据加载失败", retryable: !0, cause: B }), M("error");
1255
+ });
1256
+ const W = (B) => {
1257
+ if (B)
1258
+ if ($ = !0, z)
1259
+ try {
1260
+ $e(S), M("ready");
1261
+ } catch (X) {
1262
+ E({ code: "SCHEMA_MISMATCH", message: X instanceof Error ? X.message : "文档格式不受支持", retryable: !1, cause: X }), M("error");
1263
+ }
1264
+ else Q();
1265
+ }, H = ({ status: B }) => M((X) => B === "connected" ? X === "ready" ? "ready" : "syncing" : X === "error" ? X : "disconnected"), ne = () => {
1266
+ const B = [];
1267
+ g.awareness.getStates().forEach((X, oe) => {
1268
+ const ae = X.user;
1269
+ ae && B.push({ clientId: oe, name: ae.name || D(l.current, "presence.anonymous", void 0, b.current), color: ae.color || Ve[0] });
1270
+ }), re(B);
1271
+ };
1272
+ return p.current = ne, g.on("status", H), g.on("sync", W), g.awareness.on("change", ne), M(g.wsconnected ? "syncing" : "loading"), ne(), () => {
1273
+ p.current = () => {
1274
+ }, g.off("status", H), g.off("sync", W), g.awareness.off("change", ne), g.destroy(), P?.destroy(), y.undoManager.destroy(), y.doc.destroy();
1275
+ };
1276
+ }, [a, n, s, d, u, y, e, k, C, h, r]), K(() => {
1277
+ p.current();
1278
+ }, [i, f]), {
1279
+ doc: y.doc,
1280
+ text: y.text,
1281
+ awareness: y.awareness,
1282
+ undoManager: y.undoManager,
1283
+ state: v,
1284
+ ready: _,
1285
+ saveState: "unavailable",
1286
+ collaborators: O,
1287
+ error: N
1288
+ };
1289
+ }
1290
+ async function ra(t, e) {
1291
+ if (e) {
1292
+ const r = typeof e == "string" ? { endpoint: e } : e, n = new FormData();
1293
+ n.append(r.fieldName || "file", t);
1294
+ const o = await fetch(r.endpoint, {
1295
+ method: "POST",
1296
+ body: n,
1297
+ headers: r.headers,
1298
+ signal: r.signal,
1299
+ credentials: r.credentials
1300
+ });
1301
+ if (!o.ok) throw new Error(D(r.locale, "upload.failed", { status: o.status }, r.messages));
1302
+ const s = await o.json(), d = r.resolveUrl ? await r.resolveUrl(s) : s?.url;
1303
+ if (!d) throw new Error(D(r.locale, "upload.missingUrl", void 0, r.messages));
1304
+ return d;
1305
+ }
1306
+ return Ot(t);
1307
+ }
1308
+ function Ot(t, e = {}) {
1309
+ return new Promise((r, n) => {
1310
+ const o = new FileReader();
1311
+ o.onload = () => r(String(o.result)), o.onerror = () => n(new Error(D(e.locale, "upload.readFailed", void 0, e.messages))), o.readAsDataURL(t);
1312
+ });
1313
+ }
1314
+ function Ut(t, e = {}) {
1315
+ for (let r = 0; r < t.length; r++) {
1316
+ const n = t.charCodeAt(r);
1317
+ if (n >= 55296 && n <= 56319) {
1318
+ const o = t.charCodeAt(++r);
1319
+ if (!(o >= 56320 && o <= 57343)) throw new TypeError(D(e.locale, "validation.loneSurrogate", void 0, e.messages));
1320
+ } else if (n >= 56320 && n <= 57343) throw new TypeError(D(e.locale, "validation.loneSurrogate", void 0, e.messages));
1321
+ }
1322
+ return new File(
1323
+ [t],
1324
+ Wn(e.fileName || "document.md"),
1325
+ { type: e.mimeType || "text/markdown;charset=utf-8" }
1326
+ );
1327
+ }
1328
+ function na(t, e = {}) {
1329
+ const r = Ut(t, e), n = URL.createObjectURL(r), o = document.createElement("a");
1330
+ o.href = n, o.download = r.name, o.click(), URL.revokeObjectURL(n);
1331
+ }
1332
+ function Wn(t) {
1333
+ const e = t.replace(/[\u0000-\u001f\u007f\\/:*?"<>|]/g, "-").trim().replace(/\.markdown$/i, ".md") || "document.md";
1334
+ return /\.md$/i.test(e) ? e : `${e}.md`;
1335
+ }
1336
+ const Se = Ae.define(), je = Ae.define(), Te = Ae.define(), qe = Ae.define(), Ke = mr.define({
1337
+ create: () => ({ remote: [], comments: [], active: null }),
1338
+ update: (t, e) => {
1339
+ for (const r of e.effects)
1340
+ r.is(Se) && (t = { ...t, remote: r.value }), r.is(je) && (t = {
1341
+ ...t,
1342
+ comments: r.value,
1343
+ active: r.value.some((n) => n.id === t.active && !n.resolved && !n.deleted) ? t.active : null
1344
+ }), r.is(Te) && (t = { ...t, active: r.value });
1345
+ return t;
1346
+ }
1347
+ });
1348
+ class Xn extends dr {
1349
+ constructor(e, r, n, o) {
1350
+ super(), this.sessionId = e, this.name = r, this.color = n, this.label = o;
1351
+ }
1352
+ sessionId;
1353
+ name;
1354
+ color;
1355
+ label;
1356
+ eq(e) {
1357
+ return this.sessionId === e.sessionId && this.name === e.name && this.color === e.color && this.label === e.label;
1358
+ }
1359
+ toDOM() {
1360
+ const e = document.createElement("span");
1361
+ e.className = "exmd-remote-caret", e.dataset.sessionId = this.sessionId, e.style.setProperty("--exmd-selection-color", this.color), e.setAttribute("aria-label", this.label);
1362
+ const r = e.appendChild(document.createElement("span"));
1363
+ return r.className = "exmd-remote-label", r.textContent = this.name, e;
1364
+ }
1365
+ ignoreEvent() {
1366
+ return !0;
1367
+ }
1368
+ }
1369
+ function Yn(t, e) {
1370
+ const r = (n) => {
1371
+ const o = t.doc;
1372
+ if (!o) return pe.none;
1373
+ const s = n.state.field(Ke), d = [];
1374
+ if (e.showRemote()) {
1375
+ const u = new Map(s.remote.map((a) => [a.sessionId, a]));
1376
+ for (const a of u.values()) {
1377
+ if (!a.selection) continue;
1378
+ const i = Ge(o, t, a.selection);
1379
+ if (!i) continue;
1380
+ const f = /^#[0-9a-f]{6}$/i.test(a.color) ? a.color : "#7357d8", l = Math.min(i.anchor, i.focus), b = Math.max(i.anchor, i.focus);
1381
+ b > l && d.push(pe.mark({
1382
+ class: "exmd-remote-selection",
1383
+ attributes: {
1384
+ "data-session-id": a.sessionId,
1385
+ style: "--exmd-selection-color:" + f
1386
+ }
1387
+ }).range(l, b)), d.push(pe.widget({ widget: new Xn(a.sessionId, a.name, f, e.cursorLabel?.(a.name) || `${a.name} 的光标`), side: 1 }).range(i.focus));
1388
+ }
1389
+ }
1390
+ for (const u of s.comments) {
1391
+ if (u.resolved || u.deleted) continue;
1392
+ const a = ve(o, t, u.anchor);
1393
+ a && d.push(pe.mark({
1394
+ class: "exmd-comment-anchor" + (u.id === s.active ? " exmd-comment-active" : ""),
1395
+ attributes: { "data-comment-id": u.id }
1396
+ }).range(a.from, a.to));
1397
+ }
1398
+ return pe.set(d, !0);
1399
+ };
1400
+ return [
1401
+ Ke,
1402
+ cr.fromClass(class {
1403
+ decorations;
1404
+ composing = !1;
1405
+ frame = 0;
1406
+ constructor(n) {
1407
+ this.decorations = r(n);
1408
+ }
1409
+ update(n) {
1410
+ if (this.composing || n.view.composing) {
1411
+ this.decorations = this.decorations.map(n.changes);
1412
+ return;
1413
+ }
1414
+ (n.docChanged || n.viewportChanged || n.transactions.some((o) => o.effects.length)) && (this.decorations = r(n.view));
1415
+ }
1416
+ destroy() {
1417
+ cancelAnimationFrame(this.frame);
1418
+ }
1419
+ }, {
1420
+ decorations: (n) => n.decorations,
1421
+ eventHandlers: {
1422
+ compositionstart() {
1423
+ cancelAnimationFrame(this.frame), this.composing = !0;
1424
+ },
1425
+ compositionend(n, o) {
1426
+ cancelAnimationFrame(this.frame), this.frame = requestAnimationFrame(() => {
1427
+ this.composing = !1, o.dispatch({ effects: qe.of() });
1428
+ });
1429
+ }
1430
+ }
1431
+ }),
1432
+ ce.domEventHandlers({
1433
+ click: (n, o) => {
1434
+ const s = n.target instanceof Element ? n.target.closest("[data-comment-id]") : null;
1435
+ let d = s?.getAttribute("data-comment-id");
1436
+ if (d && o.dom.contains(s)) {
1437
+ const u = o.state.field(Ke), a = o.posAtCoords({ x: n.clientX, y: n.clientY }), i = a === null ? [d] : [...new Set(u.comments.filter((f) => {
1438
+ const l = !f.deleted && !f.resolved && t.doc && ve(t.doc, t, f.anchor);
1439
+ return l && a >= l.from && a < l.to;
1440
+ }).map((f) => f.id))];
1441
+ i.length && (d = i[(i.indexOf(u.active || "") + 1) % i.length]), o.dispatch({ effects: Te.of(d) }), e.onAnchorClick(d);
1442
+ }
1443
+ return !1;
1444
+ }
1445
+ })
1446
+ ];
1447
+ }
1448
+ const oa = Xe(function(e, r) {
1449
+ if (e.collaboration) return /* @__PURE__ */ gt(_t, { ...e, ref: r, key: e.collaboration.doc.guid });
1450
+ if (!e.roomId || !e.websocketUrl) throw new Error(D(e.locale, "editor.transportRequired", void 0, e.messages));
1451
+ return /* @__PURE__ */ gt(Gn, { ...e, ref: r, key: e.roomId + ":" + e.websocketUrl });
1452
+ }), Gn = Xe(function(e, r) {
1453
+ const n = qn({
1454
+ roomId: e.roomId,
1455
+ websocketUrl: e.websocketUrl,
1456
+ initialValue: e.initialValue,
1457
+ user: e.user,
1458
+ persistence: e.persistence,
1459
+ persistenceKey: e.persistenceKey,
1460
+ readOnly: e.mode === "readonly",
1461
+ locale: e.locale,
1462
+ messages: e.messages
1463
+ });
1464
+ return /* @__PURE__ */ c(_t, { ...e, collaboration: n, standalone: !0, ref: r });
1465
+ }), Jn = {
1466
+ lineNumbers: !0,
1467
+ foldGutter: !0,
1468
+ highlightActiveLine: !0,
1469
+ highlightActiveLineGutter: !0,
1470
+ history: !1,
1471
+ historyKeymap: !1
1472
+ }, Zn = We(ar), _t = Xe(function({
1473
+ roomId: e,
1474
+ collaboration: r,
1475
+ uploadImage: n,
1476
+ defaultViewMode: o = "split",
1477
+ title: s,
1478
+ className: d = "",
1479
+ height: u = "100vh",
1480
+ syncScroll: a = !0,
1481
+ previewDebounceMs: i,
1482
+ mode: f = "edit",
1483
+ resources: l,
1484
+ onImagePreview: b,
1485
+ onUploadProgress: p,
1486
+ onChange: h,
1487
+ onConnectionChange: k,
1488
+ components: C = {},
1489
+ standalone: y = !1,
1490
+ selectionActions: v = [],
1491
+ selectionToolbar: M = !0,
1492
+ toolbarActions: _ = [],
1493
+ locale: R,
1494
+ messages: O
1495
+ }, re) {
1496
+ const N = (m, x) => D(R, m, x, O), E = n ?? ((m) => Ot(m, { locale: R, messages: O })), S = s ?? N("document.title"), w = A(R), F = A(O);
1497
+ w.current = R, F.current = O;
1498
+ const g = r, P = f === "readonly" || !g.ready || g.state === "error", j = e || "document", $ = A(null), z = A(null), Q = A(null), W = A(null), [H, ne] = V(o), [B, X] = V(() => g.text.toString()), oe = zn(B, H !== "edit", i), [ae, De] = V(!1), [Ie, we] = V(""), et = A(0), be = A(void 0), de = A(void 0), ye = A(/* @__PURE__ */ new Set()), xe = A(void 0), tt = A(/* @__PURE__ */ new Set()), Y = A(o === "preview" ? "preview" : "source"), rt = A([]), Re = A(null), [, Bt] = V(0), ue = Ee(() => Bt((m) => m + 1), []), nt = A(ue), Le = A(() => {
1499
+ }), T = A({ readOnly: P, session: g, mode: H, standalone: y, onChange: h, mounted: !0 });
1500
+ T.current = { ...T.current, readOnly: P, session: g, mode: H, standalone: y, onChange: h };
1501
+ const G = J(() => Un(g.text, {
1502
+ activate: () => {
1503
+ Y.current = "preview";
1504
+ },
1505
+ isActive: () => Y.current === "preview" && T.current.mode !== "edit",
1506
+ selectionChanged: () => nt.current(),
1507
+ click: (m) => Le.current(m)
1508
+ }), [g.text]), ot = () => {
1509
+ if (T.current.mode === "preview" || T.current.mode !== "edit" && Y.current === "preview") return G.capture();
1510
+ const m = $.current?.view, x = m?.state.selection.main;
1511
+ return !x || x.empty || m?.state.doc.toString() !== g.text.toString() ? null : Rt(g.text, x.from, x.to);
1512
+ }, Ne = (m) => {
1513
+ Re.current = m, G.setActive(m), $.current?.view?.dispatch({ effects: Te.of(m) });
1514
+ };
1515
+ Le.current = (m) => {
1516
+ Ne(m), tt.current.forEach((x) => x(m));
1517
+ }, K(() => k?.(g.state), [k, g.state]), K(() => {
1518
+ P && g.awareness.setLocalStateField("cursor", null);
1519
+ }, [P, g.awareness]);
1520
+ const at = J(() => ce.updateListener.of((m) => {
1521
+ (m.focusChanged && m.view.hasFocus || m.selectionSet && !m.docChanged) && (Y.current = "source", G.clearSelection(), nt.current()), !(!m.selectionSet && !m.focusChanged) && (window.clearTimeout(xe.current), xe.current = window.setTimeout(() => {
1522
+ const x = T.current, L = x.mounted && !x.readOnly && x.mode !== "preview" && x.session.state === "ready" && m.view.hasFocus ? Nn(x.session.text, m.view.state.selection.main.anchor, m.view.state.selection.main.head) : null;
1523
+ ye.current.forEach((ee) => ee(L));
1524
+ }, 120));
1525
+ }), [G]);
1526
+ K(() => {
1527
+ if (!a || H !== "split") return;
1528
+ const m = z.current, x = Q.current;
1529
+ if (!(!m || !x) && oe === B)
1530
+ return Hn(() => $.current?.view, m, x);
1531
+ }, [H, a, oe, B]), K(() => {
1532
+ const m = () => {
1533
+ et.current += 1;
1534
+ const x = g.text.toString();
1535
+ X(x), T.current.onChange?.(x);
1536
+ };
1537
+ return X(g.text.toString()), g.text.observe(m), () => g.text.unobserve(m);
1538
+ }, [g.text]);
1539
+ const it = J(() => fr(
1540
+ g.text,
1541
+ y ? g.awareness : null,
1542
+ { undoManager: g.undoManager }
1543
+ ), [g.text, g.awareness, g.undoManager, y]), st = J(() => Yn(g.text, {
1544
+ showRemote: () => !T.current.readOnly && T.current.mode !== "preview" && T.current.session.state === "ready",
1545
+ onAnchorClick: (m) => Le.current(m),
1546
+ cursorLabel: (m) => D(w.current, "presence.cursor", { name: m }, F.current)
1547
+ }), [g.text]), lt = J(() => pt.transactionFilter.of((m) => m.docChanged && T.current.readOnly && !m.annotation(gr) ? [] : m), []), ct = J(() => ht.highest(ur.of([
1548
+ { key: "Mod-z", run: () => (T.current.readOnly || T.current.session.undoManager.undo(), !0) },
1549
+ { key: "Mod-Shift-z", run: () => (T.current.readOnly || T.current.session.undoManager.redo(), !0) },
1550
+ { key: "Mod-y", run: () => (T.current.readOnly || T.current.session.undoManager.redo(), !0) }
1551
+ ])), []), dt = J(() => ht.highest(ce.domEventHandlers({
1552
+ beforeinput: (m) => m.inputType !== "historyUndo" && m.inputType !== "historyRedo" ? !1 : (m.preventDefault(), T.current.readOnly || (m.inputType === "historyUndo" ? T.current.session.undoManager.undo() : T.current.session.undoManager.redo()), !0)
1553
+ })), []), Ht = J(
1554
+ () => [
1555
+ pt.lineSeparator.of(`
1556
+ `),
1557
+ ir(),
1558
+ sr(lr),
1559
+ ce.lineWrapping,
1560
+ dt,
1561
+ it,
1562
+ st,
1563
+ lt,
1564
+ ct,
1565
+ at
1566
+ ],
1567
+ [st, it, lt, dt, at, ct]
1568
+ ), q = () => $.current?.view, Kt = N("presence.cursor", { name: " " });
1569
+ K(() => {
1570
+ q()?.dispatch({ effects: qe.of() });
1571
+ }, [Kt]), K(() => {
1572
+ H === "preview" && (Y.current = "preview"), H === "edit" && (Y.current = "source", G.clearSelection()), P && (de.current?.abort(), De(!1)), (P || H === "preview" || g.state !== "ready") && (window.clearTimeout(xe.current), q()?.dispatch({ effects: Se.of([]) }), ye.current.forEach((m) => m(null))), q()?.dispatch({ effects: qe.of() }), H !== "preview" && q()?.requestMeasure();
1573
+ }, [P, H, g.state]), K(() => {
1574
+ const m = Q.current || z.current;
1575
+ if (!m || !v.length && !_.length) return;
1576
+ const x = m.ownerDocument, L = x.defaultView;
1577
+ let ee = 0;
1578
+ const te = () => {
1579
+ ee || (ee = L.requestAnimationFrame(() => {
1580
+ ee = 0, ue();
1581
+ }));
1582
+ };
1583
+ return x.addEventListener("scroll", te, !0), x.addEventListener("selectionchange", te), L.addEventListener("resize", te), L.visualViewport?.addEventListener("resize", te), () => {
1584
+ x.removeEventListener("scroll", te, !0), x.removeEventListener("selectionchange", te), L.removeEventListener("resize", te), L.visualViewport?.removeEventListener("resize", te), L.cancelAnimationFrame(ee);
1585
+ };
1586
+ }, [v.length, _.length, ue]);
1587
+ const $t = (m) => {
1588
+ const x = q();
1589
+ x && !P && In(x, m);
1590
+ }, Vt = () => {
1591
+ const m = q();
1592
+ m && he(m, N("insert.diagram"));
1593
+ }, jt = () => {
1594
+ const m = q();
1595
+ m && he(m, `
1596
+ $$
1597
+ E = mc^2
1598
+ $$
1599
+ `);
1600
+ }, qt = (m) => {
1601
+ const x = q();
1602
+ x && he(x, `
1603
+ \`\`\`${m}
1604
+ ${N("insert.codePlaceholder")}
1605
+ \`\`\`
1606
+ `);
1607
+ }, Wt = (m) => {
1608
+ const x = q();
1609
+ if (!x) return;
1610
+ const L = x.state.selection.main, ee = x.state.sliceDoc(L.from, L.to) || N("format.colorPlaceholder");
1611
+ he(x, `<span data-color="${m}">${ee}</span>`);
1612
+ }, Oe = Ee(async (m) => {
1613
+ if (!m || !m.type.startsWith("image/")) {
1614
+ we(D(R, "notice.imageRequired", void 0, O));
1615
+ return;
1616
+ }
1617
+ if (T.current.readOnly) {
1618
+ we(D(R, "notice.readOnly", void 0, O));
1619
+ return;
1620
+ }
1621
+ const x = q();
1622
+ if (!x) return;
1623
+ const L = x.state.selection.main, ee = U.createRelativePositionFromTypeIndex(g.text, L.from), te = U.createRelativePositionFromTypeIndex(g.text, L.to);
1624
+ de.current?.abort();
1625
+ const fe = new AbortController();
1626
+ de.current = fe, De(!0), we("");
1627
+ try {
1628
+ const se = l?.uploadImage ? await l.uploadImage(m, { signal: fe.signal, onProgress: (rr) => p?.(rr) }) : await E(m);
1629
+ if (fe.signal.aborted || T.current.readOnly || !T.current.mounted) return;
1630
+ const tr = typeof se == "string" ? se : se.path, ke = g.text.doc, ge = ke && U.createAbsolutePositionFromRelativePosition(ee, ke), Be = ke && U.createAbsolutePositionFromRelativePosition(te, ke);
1631
+ if (!ge || !Be || ge.type !== g.text || Be.type !== g.text) return;
1632
+ const ft = `![${m.name.replace(/\.[^.]+$/, "")}](${tr})`;
1633
+ x.dispatch({
1634
+ changes: { from: ge.index, to: Math.max(ge.index, Be.index), insert: ft },
1635
+ selection: { anchor: ge.index + ft.length }
1636
+ });
1637
+ } catch (se) {
1638
+ !fe.signal.aborted && T.current.mounted && we(se instanceof Error ? se.message : D(R, "notice.uploadFailed", void 0, O));
1639
+ } finally {
1640
+ T.current.mounted && de.current === fe && (De(!1), W.current && (W.current.value = ""));
1641
+ }
1642
+ }, [P, R, O, p, l, g.text, E]);
1643
+ K(() => (T.current.mounted = !0, () => {
1644
+ T.current.mounted = !1, de.current?.abort(), window.clearTimeout(xe.current), ye.current.forEach((m) => m(null));
1645
+ }), []), or(re, () => ro(
1646
+ q,
1647
+ g,
1648
+ () => T.current.readOnly || !T.current.mounted,
1649
+ et,
1650
+ ye.current,
1651
+ tt.current,
1652
+ () => {
1653
+ Y.current = "source", T.current.mode === "preview" && ne("split");
1654
+ },
1655
+ {
1656
+ capture: ot,
1657
+ render: (m) => {
1658
+ rt.current = m, G.setComments(m), q()?.dispatch({ effects: je.of(m) }), m.some((x) => x.id === Re.current && !x.resolved && !x.deleted) || Ne(null);
1659
+ },
1660
+ activate: Ne,
1661
+ reveal: (m) => {
1662
+ if (T.current.mode === "preview" || Y.current === "preview" && T.current.mode !== "edit") return G.reveal(m);
1663
+ const x = q(), L = ve(g.doc, g.text, m);
1664
+ return !x || !L ? !1 : (x.dispatch({ selection: { anchor: L.from, head: L.to }, effects: ce.scrollIntoView(L.from, { y: "center" }) }), !0);
1665
+ }
1666
+ }
1667
+ ), [g.text, g.undoManager, G]);
1668
+ const Xt = C.Header || Qn, Yt = C.Toolbar || Ln, Gt = C.Preview || Tn, Jt = C.Loading || eo, Zt = C.Footer || to, Ue = () => ({
1669
+ view: T.current.mode === "preview" ? "preview" : T.current.mode === "edit" ? "source" : Y.current,
1670
+ anchor: ot()
1671
+ }), ie = Ue(), _e = q();
1672
+ let me = ie.view === "preview" ? G.selectionRect() : null;
1673
+ if (ie.anchor && ie.view === "source" && _e) {
1674
+ const m = _e.coordsAtPos(_e.state.selection.main.from);
1675
+ m && (me = new DOMRect(m.left, m.top, 0, m.bottom - m.top));
1676
+ }
1677
+ const ut = M && v.length > 0 && !!(ie.anchor && me), mt = [..._, ...ut ? [] : v], Qt = mt.length ? /* @__PURE__ */ c(xt, { actions: mt, context: ie, capture: Ue }) : void 0, ze = z.current?.ownerDocument, er = Ee((m) => {
1678
+ m.dispatch({ effects: [je.of(rt.current), Te.of(Re.current)] }), ue();
1679
+ }, [ue]);
1680
+ return g.ready && be.current === void 0 && (be.current = g.text.toString()), /* @__PURE__ */ I("div", { className: `exmd-editor app-shell ${d}`, style: { height: u }, lang: pn(R), children: [
1681
+ /* @__PURE__ */ c(Xt, { title: S, roomId: j, session: g, locale: R, messages: O }),
1682
+ /* @__PURE__ */ c(Yt, { hostActions: Qt, readOnly: P, mode: H, onModeChange: ne, onAction: $t, onUndo: () => {
1683
+ T.current.readOnly || g.undoManager.undo();
1684
+ }, onRedo: () => {
1685
+ T.current.readOnly || g.undoManager.redo();
1686
+ }, onImage: () => {
1687
+ T.current.readOnly || W.current?.click();
1688
+ }, onDiagram: Vt, onFormula: jt, onCodeBlock: qt, onColor: Wt, locale: R, messages: O }),
1689
+ ut && ze && me && Ct(/* @__PURE__ */ c(
1690
+ "div",
1691
+ {
1692
+ className: "exmd-selection-toolbar",
1693
+ role: "toolbar",
1694
+ "aria-label": N("selection.toolbar"),
1695
+ style: {
1696
+ position: "fixed",
1697
+ left: Math.max(8, Math.min(me.left, ze.documentElement.clientWidth - 180)),
1698
+ top: Math.max(8, me.top - 42),
1699
+ zIndex: 1e3
1700
+ },
1701
+ children: /* @__PURE__ */ c(xt, { actions: v, context: ie, capture: Ue })
1702
+ }
1703
+ ), ze.body),
1704
+ /* @__PURE__ */ c("input", { ref: W, hidden: !0, type: "file", accept: "image/*", onChange: (m) => {
1705
+ Oe(m.target.files?.[0]);
1706
+ } }),
1707
+ (ae || Ie) && /* @__PURE__ */ c("div", { className: Ie ? "notice error" : "notice", children: ae ? N("notice.uploading") : Ie }),
1708
+ /* @__PURE__ */ I("main", { className: `workspace mode-${H}`, onDragOver: (m) => {
1709
+ P || m.preventDefault();
1710
+ }, onDrop: (m) => {
1711
+ if (P) return;
1712
+ const x = [...m.dataTransfer.files].find((L) => L.type.startsWith("image/"));
1713
+ x && (m.preventDefault(), Oe(x));
1714
+ }, onPaste: (m) => {
1715
+ if (P) return;
1716
+ const x = [...m.clipboardData.files].find((L) => L.type.startsWith("image/"));
1717
+ x && (m.preventDefault(), Oe(x));
1718
+ }, children: [
1719
+ /* @__PURE__ */ I("section", { ref: z, className: "editor-pane", hidden: H === "preview", onPointerDown: () => {
1720
+ Y.current = "source", G.clearSelection();
1721
+ }, onMouseDownCapture: (m) => {
1722
+ const x = $.current?.view;
1723
+ x && _n(x, m.currentTarget, m.nativeEvent) && (m.preventDefault(), m.stopPropagation());
1724
+ }, "aria-label": N("editor.pane"), children: [
1725
+ /* @__PURE__ */ I("div", { className: "pane-label", children: [
1726
+ /* @__PURE__ */ c("span", { children: "MARKDOWN" }),
1727
+ /* @__PURE__ */ c("span", { children: N("editor.characters", { count: B.length }) })
1728
+ ] }),
1729
+ be.current !== void 0 ? /* @__PURE__ */ c(Zn, { ref: $, onCreateEditor: er, value: be.current, extensions: Ht, editable: !P, readOnly: P, basicSetup: Jn }) : /* @__PURE__ */ c(Jt, { state: g.state, errorMessage: g.error ? vn(g.error, R, O) : void 0, locale: R, messages: O })
1730
+ ] }),
1731
+ H !== "edit" && /* @__PURE__ */ I("section", { ref: Q, className: "preview-pane", "aria-busy": oe !== B, onPointerDown: () => {
1732
+ Y.current = "preview";
1733
+ }, "aria-label": N("preview.pane"), children: [
1734
+ /* @__PURE__ */ I("div", { className: "pane-label", children: [
1735
+ /* @__PURE__ */ c("span", { children: N("preview.label") }),
1736
+ /* @__PURE__ */ c("span", { children: N(oe !== B ? "preview.updating" : a && H === "split" ? "preview.syncScroll" : "preview.live") })
1737
+ ] }),
1738
+ /* @__PURE__ */ c(Gt, { value: oe, resolveImageUrl: l?.resolveUrl, onImagePreview: b, interaction: G, locale: R, messages: O })
1739
+ ] })
1740
+ ] }),
1741
+ /* @__PURE__ */ c(Zt, { readOnly: P, locale: R, messages: O })
1742
+ ] });
1743
+ });
1744
+ function Qn({ title: t, roomId: e, session: r, locale: n, messages: o }) {
1745
+ const s = (a, i) => D(n, a, i, o), d = r.state === "ready" ? /* @__PURE__ */ I(le, { children: [
1746
+ /* @__PURE__ */ c(Tr, {}),
1747
+ " ",
1748
+ s("status.ready")
1749
+ ] }) : r.state === "error" ? /* @__PURE__ */ I(le, { children: [
1750
+ /* @__PURE__ */ c(Ar, {}),
1751
+ " ",
1752
+ s("status.error")
1753
+ ] }) : r.state === "disconnected" ? /* @__PURE__ */ I(le, { children: [
1754
+ /* @__PURE__ */ c(Dr, {}),
1755
+ " ",
1756
+ r.ready ? s("status.offlineEditing") : s("status.offline")
1757
+ ] }) : /* @__PURE__ */ I(le, { children: [
1758
+ /* @__PURE__ */ c(Ir, { className: "spin" }),
1759
+ " ",
1760
+ r.state === "syncing" ? s("status.syncing") : s("status.loading")
1761
+ ] }), u = s("presence.online", { count: r.collaborators.length });
1762
+ return /* @__PURE__ */ I("header", { className: "topbar", children: [
1763
+ /* @__PURE__ */ I("div", { className: "brand", children: [
1764
+ /* @__PURE__ */ c("span", { className: "brand-mark", children: "墨" }),
1765
+ /* @__PURE__ */ I("div", { children: [
1766
+ /* @__PURE__ */ c("strong", { children: t }),
1767
+ /* @__PURE__ */ c("small", { children: s("header.room", { roomId: e }) })
1768
+ ] })
1769
+ ] }),
1770
+ /* @__PURE__ */ c("div", { className: `sync-state ${r.state}`, children: d }),
1771
+ /* @__PURE__ */ I("div", { className: "presence", "aria-label": u, children: [
1772
+ /* @__PURE__ */ c("div", { className: "avatars", children: r.collaborators.slice(0, 4).map((a) => /* @__PURE__ */ c("span", { title: a.name, style: { background: a.color }, children: a.name.slice(0, 1) }, a.clientId)) }),
1773
+ /* @__PURE__ */ c("span", { children: u })
1774
+ ] })
1775
+ ] });
1776
+ }
1777
+ function eo({ errorMessage: t, locale: e, messages: r }) {
1778
+ return /* @__PURE__ */ c("div", { className: "collaboration-loading", children: t || D(e, "loading.document", void 0, r) });
1779
+ }
1780
+ function to({ readOnly: t, locale: e, messages: r }) {
1781
+ const n = (o) => D(e, o, void 0, r);
1782
+ return /* @__PURE__ */ I("footer", { children: [
1783
+ /* @__PURE__ */ c("span", { children: n("footer.formats") }),
1784
+ /* @__PURE__ */ c("span", { children: n(t ? "footer.readOnly" : "footer.dropImages") })
1785
+ ] });
1786
+ }
1787
+ function ro(t, e, r, n, o, s, d, u) {
1788
+ const a = (i, f = {}) => no(e.text.toString(), i, f, n.current);
1789
+ return {
1790
+ focus: () => t()?.focus(),
1791
+ getMarkdown: () => e.text.toString(),
1792
+ replaceMarkdown: (i, f = {}) => {
1793
+ const l = t();
1794
+ if (!l || r()) return !1;
1795
+ const b = e.text.toString();
1796
+ return f.expectedMarkdown !== void 0 && f.expectedMarkdown !== b || l.state.doc.toString() !== b ? !1 : (i === b || (e.undoManager.stopCapturing(), l.dispatch({ changes: { from: 0, to: l.state.doc.length, insert: i }, selection: { anchor: 0 } }), e.undoManager.stopCapturing()), !0);
1797
+ },
1798
+ getEditorView: t,
1799
+ insertText: (i) => {
1800
+ const f = t();
1801
+ return !f || r() ? !1 : (he(f, i), !0);
1802
+ },
1803
+ find: a,
1804
+ reveal: (i) => {
1805
+ const f = t();
1806
+ return !f || i.revision !== n.current || i.from < 0 || i.to > f.state.doc.length ? !1 : (d(), f.dispatch({ selection: { anchor: i.from, head: i.to }, effects: ce.scrollIntoView(i.from, { y: "center" }) }), f.focus(), !0);
1807
+ },
1808
+ replace: (i, f) => {
1809
+ const l = t();
1810
+ return !l || r() || i.revision !== n.current || l.state.sliceDoc(i.from, i.to) !== i.text ? !1 : (e.undoManager.stopCapturing(), l.dispatch({ changes: { from: i.from, to: i.to, insert: f } }), e.undoManager.stopCapturing(), !0);
1811
+ },
1812
+ replaceAll: (i, f, l = {}) => {
1813
+ const b = t();
1814
+ if (!b || r()) return 0;
1815
+ const p = a(i, l);
1816
+ return p.length ? (e.undoManager.stopCapturing(), b.dispatch({ changes: p.map((h) => ({ from: h.from, to: h.to, insert: f })) }), e.undoManager.stopCapturing(), p.length) : 0;
1817
+ },
1818
+ undo: () => r() || !e.undoManager.canUndo() ? !1 : (e.undoManager.undo(), !0),
1819
+ redo: () => r() || !e.undoManager.canRedo() ? !1 : (e.undoManager.redo(), !0),
1820
+ queryFormatState: () => {
1821
+ const f = t()?.state.selection.main;
1822
+ return {
1823
+ selection: { from: f?.from || 0, to: f?.to || 0 },
1824
+ canUndo: !r() && e.undoManager.canUndo(),
1825
+ canRedo: !r() && e.undoManager.canRedo()
1826
+ };
1827
+ },
1828
+ onSelectionChange: (i) => (o.add(i), () => o.delete(i)),
1829
+ renderRemoteSelections: (i) => {
1830
+ const f = t();
1831
+ !f || r() || f.dispatch({ effects: Se.of(i) });
1832
+ },
1833
+ clearRemoteSelections: () => {
1834
+ t()?.dispatch({ effects: Se.of([]) });
1835
+ },
1836
+ renderAnchors: u.render,
1837
+ setActiveAnchor: u.activate,
1838
+ clearAnchors: () => {
1839
+ u.render([]), u.activate(null);
1840
+ },
1841
+ onAnchorClick: (i) => (s.add(i), () => s.delete(i)),
1842
+ captureAnchor: u.capture,
1843
+ resolveAnchor: (i) => ve(e.doc, e.text, i),
1844
+ revealAnchor: u.reveal
1845
+ };
1846
+ }
1847
+ function no(t, e, r, n) {
1848
+ if (!e) return [];
1849
+ const o = r.caseSensitive ? t : t.toLocaleLowerCase(), s = r.caseSensitive ? e : e.toLocaleLowerCase(), d = [];
1850
+ let u = 0;
1851
+ for (; u <= o.length - s.length; ) {
1852
+ const a = o.indexOf(s, u);
1853
+ if (a < 0) break;
1854
+ const i = a + e.length;
1855
+ d.push({ id: `${n}:${a}:${i}`, from: a, to: i, text: t.slice(a, i), revision: n }), u = Math.max(i, a + 1);
1856
+ }
1857
+ return d;
1858
+ }
1859
+ const Et = "text/markdown;charset=utf-8", oo = 512 * 1024;
1860
+ function zt(t, e) {
1861
+ return { code: "RESOURCE_REFERENCES_PRESERVED", message: D(t, "markdown.resourcePreserved", void 0, e) };
1862
+ }
1863
+ function ao(t) {
1864
+ const e = /* @__PURE__ */ new Set();
1865
+ for (const r of t.matchAll(/\r\n|\r|\n/g)) e.add(r[0] === `\r
1866
+ ` ? "crlf" : r[0] === "\r" ? "cr" : "lf");
1867
+ return e.size > 1 ? "mixed" : e.values().next().value || "none";
1868
+ }
1869
+ async function aa(t, e = {}) {
1870
+ const r = e.maxBytes ?? oo, n = (f, l) => D(e.locale, f, l, e.messages);
1871
+ if (!Number.isSafeInteger(r) || r < 0) throw new RangeError(n("validation.nonNegativeInteger", { name: "maxBytes" }));
1872
+ const o = (f, l) => ({ ok: !1, error: { code: f, message: l }, warnings: [] });
1873
+ if (!/\.(md|markdown)$/i.test(t.name)) return o("UNSUPPORTED_EXTENSION", n("markdown.unsupportedExtension"));
1874
+ if (t.size > r) return o("FILE_TOO_LARGE", n("markdown.fileTooLarge", { maxBytes: r }));
1875
+ let s;
1876
+ try {
1877
+ s = new Uint8Array(await t.arrayBuffer());
1878
+ } catch {
1879
+ return o("READ_FAILED", n("markdown.readFailed"));
1880
+ }
1881
+ if (s.byteLength > r) return o("FILE_TOO_LARGE", n("markdown.fileTooLarge", { maxBytes: r }));
1882
+ let d;
1883
+ const u = s[0] === 239 && s[1] === 187 && s[2] === 191;
1884
+ try {
1885
+ d = new TextDecoder("utf-8", { fatal: !0, ignoreBOM: !0 }).decode(u ? s.subarray(3) : s);
1886
+ } catch {
1887
+ return o("INVALID_UTF8", n("markdown.invalidUtf8"));
1888
+ }
1889
+ if (d.includes("\0")) return o("BINARY_CONTENT", n("markdown.binary"));
1890
+ const a = ao(d), i = [zt(e.locale, e.messages)];
1891
+ return u && i.unshift({ code: "UTF8_BOM_REMOVED", message: n("markdown.bomRemoved") }), a === "mixed" && i.push({ code: "MIXED_LINE_ENDINGS", message: n("markdown.mixedLineEndings") }), { ok: !0, markdown: d, fileName: t.name, byteLength: s.byteLength, encoding: "utf-8", hadBom: u, lineEndings: a, warnings: i };
1892
+ }
1893
+ function ia(t, e = {}) {
1894
+ const r = Ut(t, { fileName: e.fileName, mimeType: Et, locale: e.locale, messages: e.messages });
1895
+ return { blob: r, fileName: r.name, mimeType: Et, warnings: [zt(e.locale, e.messages)] };
1896
+ }
1897
+ const sa = "application/pdf", la = 25 * 1024 * 1024, ca = 100, da = 4e7, ua = 3e4;
1898
+ class ma extends Error {
1899
+ code;
1900
+ cause;
1901
+ constructor(e, r, n) {
1902
+ super(r), this.name = "PdfFileError", this.code = e, this.cause = n;
1903
+ }
1904
+ }
1905
+ async function fa(t, e = {}) {
1906
+ return (await import("./pdf-file-impl-BvS6-o8W.js")).importPdfFile(t, e);
1907
+ }
1908
+ async function ga(t, e = {}) {
1909
+ return (await import("./pdf-file-impl-BvS6-o8W.js")).exportPdfFile(t, e);
1910
+ }
1911
+ function pa(t) {
1912
+ $e(t.doc);
1913
+ const e = Qe(t.doc), r = !t.awareness, n = !t.undoManager, o = t.awareness || new Ft(t.doc), s = t.undoManager || new U.UndoManager(e);
1914
+ return {
1915
+ doc: t.doc,
1916
+ text: e,
1917
+ awareness: o,
1918
+ undoManager: s,
1919
+ state: t.state,
1920
+ saveState: t.saveState,
1921
+ ready: t.ready,
1922
+ collaborators: t.collaborators || [],
1923
+ error: t.error,
1924
+ epochId: t.epochId,
1925
+ dispose: () => {
1926
+ n && s.destroy(), r && o.destroy();
1927
+ }
1928
+ };
1929
+ }
1930
+ function ha(t, e) {
1931
+ return { ...t, ...e };
1932
+ }
1933
+ function va(t, e) {
1934
+ const r = (n, o, s, d) => {
1935
+ const u = Array.from(d.changedParentTypes.keys()).some((a) => Object.is(a, t.text));
1936
+ !d.local || o === Fe.bootstrap || o === Fe.remote || !u || e({ update: n, origin: o, transaction: d });
1937
+ };
1938
+ return t.doc.on("update", r), () => t.doc.off("update", r);
1939
+ }
1940
+ function wa(t, e) {
1941
+ U.applyUpdate(t, e, Fe.remote);
1942
+ }
1943
+ const ba = Object.freeze({
1944
+ protocolVersion: Kn,
1945
+ codec: Je,
1946
+ schemaVersion: Ze,
1947
+ textRoot: "markdown",
1948
+ find: { literal: !0, caseSensitive: !0, regex: !1 },
1949
+ permanentTextAnchors: !0,
1950
+ remoteCarets: !0,
1951
+ commentDecorations: !0,
1952
+ previewTextAnchors: !0,
1953
+ previewCommentDecorations: !0,
1954
+ hostSelectionActions: !0,
1955
+ anchorKind: "markdown-text-range",
1956
+ anchorBoundary: "exclude-both"
1957
+ });
1958
+ export {
1959
+ pn as A,
1960
+ ea as B,
1961
+ Kn as C,
1962
+ la as D,
1963
+ ia as E,
1964
+ ga as F,
1965
+ Qe as G,
1966
+ Ot as H,
1967
+ aa as I,
1968
+ fa as J,
1969
+ Vn as K,
1970
+ va as L,
1971
+ Je as M,
1972
+ Nt as N,
1973
+ St as O,
1974
+ ma as P,
1975
+ ve as Q,
1976
+ Qo as R,
1977
+ D as S,
1978
+ Fe as T,
1979
+ ha as U,
1980
+ ra as V,
1981
+ qn as W,
1982
+ sa as a,
1983
+ Zo as b,
1984
+ ua as c,
1985
+ ca as d,
1986
+ da as e,
1987
+ Mn as f,
1988
+ oa as g,
1989
+ kn as h,
1990
+ ta as i,
1991
+ oo as j,
1992
+ to as k,
1993
+ Qn as l,
1994
+ eo as m,
1995
+ Et as n,
1996
+ ba as o,
1997
+ Ze as p,
1998
+ Tn as q,
1999
+ wn as r,
2000
+ Ln as s,
2001
+ wa as t,
2002
+ $e as u,
2003
+ pa as v,
2004
+ Ut as w,
2005
+ Rt as x,
2006
+ Nn as y,
2007
+ na as z
2008
+ };