@smartdoca/markdown 0.4.2

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