wendang-react 0.6.3 → 0.6.5

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 (120) hide show
  1. package/NOTICE.md +1 -1
  2. package/README.md +133 -1
  3. package/dist/bindings/yjs.js +1 -5
  4. package/dist/chunks/AnchoredPanel-C7jMoPze.js +1 -0
  5. package/dist/chunks/DocumentExportMenu-CUMsgq3w.js +2 -0
  6. package/dist/chunks/Dropdown-D98tXfe0.js +3 -0
  7. package/dist/chunks/MindMapCanvas-C46Q5JBU.js +163 -0
  8. package/dist/chunks/MindMapViewer-C9zxZIW8.js +13 -0
  9. package/dist/chunks/SpreadsheetViewer-CoQ4VIgj.js +23 -0
  10. package/dist/chunks/code-highlight-BmaqTe1m.js +1 -30
  11. package/dist/chunks/code-highlight-engine-BFDzDPzy.js +1 -40
  12. package/dist/chunks/comment-hint-BhUxKjKK.js +14 -0
  13. package/dist/chunks/composition-state-Bl-U1R_2.js +1 -40
  14. package/dist/chunks/extensions-BefQ1tDm.js +14 -0
  15. package/dist/chunks/fuzzy-match-DYQR-4w2.js +1 -89
  16. package/dist/chunks/hooks-C53Dp0pr.js +1 -35
  17. package/dist/chunks/i18n-B0kCsIjc.js +2 -0
  18. package/dist/chunks/index-COeA2QcQ.js +15 -0
  19. package/dist/chunks/katex-WjrodtTU.js +1 -71
  20. package/dist/chunks/locale-DWpIJ_9X.js +1 -0
  21. package/dist/chunks/mind-map-controller-Ce76mETT.js +1 -0
  22. package/dist/chunks/mind-map-delete-CVsxdXfs.js +1 -31
  23. package/dist/chunks/mind-map-input-CEWRz_t6.js +1 -43
  24. package/dist/chunks/mind-topic-text-BHXkxexr.js +30 -0
  25. package/dist/chunks/popover-placement-D3xVYdkt.js +1 -47
  26. package/dist/chunks/worksheet-engine-c84sdD4N.js +1 -0
  27. package/dist/chunks/worksheet-preview-DsDVWxIM.js +1 -129
  28. package/dist/document/viewer.js +30 -289
  29. package/dist/document.js +120 -3811
  30. package/dist/export/json.js +1 -5
  31. package/dist/export/markdown.js +1 -2
  32. package/dist/export/mindmap.js +1 -2
  33. package/dist/export/pdf.js +1 -6
  34. package/dist/export/word.js +1 -2
  35. package/dist/export.js +1 -2
  36. package/dist/i18n.js +1 -0
  37. package/dist/index.js +1 -8
  38. package/dist/locales/en-US.js +1 -0
  39. package/dist/locales/es-ES.js +1 -0
  40. package/dist/locales/ja-JP.js +1 -0
  41. package/dist/locales/ko-KR.js +1 -0
  42. package/dist/locales/zh-CN.js +1 -0
  43. package/dist/locales/zh-TW.js +1 -0
  44. package/dist/mindmap/viewer.js +1 -6
  45. package/dist/mindmap.js +3 -123
  46. package/dist/shared.js +1 -52
  47. package/dist/spreadsheet/viewer.js +1 -5
  48. package/dist/spreadsheet/xlsx.js +1 -299
  49. package/dist/spreadsheet.js +2 -120
  50. package/dist/styles/callout.css +1 -34
  51. package/dist/styles/code-block.css +1 -58
  52. package/dist/styles/content-style.css +1 -619
  53. package/dist/styles/content-tokens.css +1 -29
  54. package/dist/styles/editor-interaction.css +1 -621
  55. package/dist/styles/file-video.css +1 -12
  56. package/dist/styles/image-preview.css +1 -103
  57. package/dist/styles/mind-map-block.css +1 -14
  58. package/dist/styles/mind-map-canvas.css +1 -80
  59. package/dist/styles/mind-map-comments.css +1 -93
  60. package/dist/styles/mind-map-details.css +1 -7
  61. package/dist/styles/mind-map-preview.css +1 -7
  62. package/dist/styles/mind-map-topic.css +1 -112
  63. package/dist/styles/page-picker.css +1 -47
  64. package/dist/styles/renderer.css +1 -45
  65. package/dist/styles/spreadsheet-editor.css +1 -3
  66. package/dist/styles/tokens.css +1 -142
  67. package/dist/styles/video-dialog.css +1 -41
  68. package/dist/styles/video-embed.css +1 -35
  69. package/dist/styles.css +1 -2655
  70. package/dist/types/editor/BlockAffordance.d.ts +5 -2
  71. package/dist/types/editor/CalloutView.d.ts +2 -1
  72. package/dist/types/editor/ImagePreview.d.ts +1 -1
  73. package/dist/types/editor/PagePicker.d.ts +1 -1
  74. package/dist/types/editor/extensions.d.ts +4 -1
  75. package/dist/types/engine/editor/block-commands.d.ts +1 -1
  76. package/dist/types/engine/editor/block-menu-hover.d.ts +16 -0
  77. package/dist/types/engine/editor/extensions/locale.d.ts +3 -0
  78. package/dist/types/engine/editor/nodes/image-nodeview.d.ts +1 -1
  79. package/dist/types/engine/editor/video-block-controls.d.ts +13 -0
  80. package/dist/types/engine/host.d.ts +60 -2
  81. package/dist/types/engine/renderer/attachments.d.ts +3 -3
  82. package/dist/types/engine/shared/video-feedback.d.ts +1 -1
  83. package/dist/types/engine/worksheets/worksheet-engine.d.ts +1 -0
  84. package/dist/types/engine/worksheets/worksheet-xlsx.d.ts +6 -1
  85. package/dist/types/host-types.d.ts +2 -60
  86. package/dist/types/host.d.ts +8 -1
  87. package/dist/types/i18n.d.ts +3 -0
  88. package/dist/types/index.d.ts +2 -0
  89. package/dist/types/locales/en-US.d.ts +1 -0
  90. package/dist/types/locales/es-ES.d.ts +1 -0
  91. package/dist/types/locales/ja-JP.d.ts +1 -0
  92. package/dist/types/locales/ko-KR.d.ts +1 -0
  93. package/dist/types/locales/zh-CN.d.ts +1 -0
  94. package/dist/types/locales/zh-TW.d.ts +1 -0
  95. package/dist/types/renderer/media.d.ts +2 -1
  96. package/dist/types/spreadsheet/xlsx.d.ts +1 -1
  97. package/dist/types/wui/Dropdown.d.ts +2 -1
  98. package/dist/types/wui/index.d.ts +2 -1
  99. package/integrity.json +3140 -0
  100. package/package.json +15 -5
  101. package/verify-integrity.mjs +138 -0
  102. package/dist/chunks/AnchoredPanel-Cv4RURwF.js +0 -68
  103. package/dist/chunks/DocumentExportMenu-BrGipZ59.js +0 -75
  104. package/dist/chunks/MindMapCanvas-tkFBBs4g.js +0 -2090
  105. package/dist/chunks/MindMapViewer-DJrryb2Y.js +0 -180
  106. package/dist/chunks/SpreadsheetViewer-DxCxIUx_.js +0 -163
  107. package/dist/chunks/comment-hint-B9qcrqvn.js +0 -296
  108. package/dist/chunks/extensions-ByORRoRa.js +0 -4210
  109. package/dist/chunks/host-C-V688Rq.js +0 -197
  110. package/dist/chunks/index-DdfMnva8.js +0 -726
  111. package/dist/chunks/mind-map-controller-B6SxK3GZ.js +0 -479
  112. package/dist/chunks/mind-topic-text-DSyb95vL.js +0 -446
  113. package/dist/chunks/nodes-iKqTGr_N.js +0 -291
  114. package/dist/chunks/worksheet-engine-TJ54m0KC.js +0 -125
  115. package/third-party-notices/wendang-export@0.6.0-NOTICE.md.txt +0 -51
  116. package/third-party-notices/wendang-export@0.6.1-LICENSE.txt +0 -21
  117. package/third-party-notices/wendang-export@0.6.2-LICENSE.txt +0 -21
  118. package/third-party-notices/wendang-export@0.6.2-NOTICE.md.txt +0 -70
  119. /package/third-party-notices/{wendang-export@0.6.0-LICENSE.txt → wendang-export@0.6.4-LICENSE.txt} +0 -0
  120. /package/third-party-notices/{wendang-export@0.6.1-NOTICE.md.txt → wendang-export@0.6.4-NOTICE.md.txt} +0 -0
@@ -1,30 +1 @@
1
- "use client";
2
- let highlight = null;
3
- let loading = null;
4
- const cache = /* @__PURE__ */ new Map();
5
- const MAX_HIGHLIGHT_LENGTH = 32e3;
6
- function ensureCodeHighlight() {
7
- if (highlight) return Promise.resolve(true);
8
- return loading ?? (loading = import("./code-highlight-engine-BFDzDPzy.js").then((engine) => {
9
- highlight = engine.highlightCode;
10
- return true;
11
- }).catch(() => {
12
- loading = null;
13
- return false;
14
- }));
15
- }
16
- function codeTokens(text, language) {
17
- if (!highlight || !text || text.length > MAX_HIGHLIGHT_LENGTH) return [];
18
- const key = `${language ?? ""}\0${text}`;
19
- const found = cache.get(key);
20
- if (found) return found;
21
- const tokens = highlight(text, language ?? "");
22
- if (cache.size >= 64) cache.delete(cache.keys().next().value);
23
- cache.set(key, tokens);
24
- return tokens;
25
- }
26
- export {
27
- MAX_HIGHLIGHT_LENGTH as M,
28
- codeTokens as c,
29
- ensureCodeHighlight as e
30
- };
1
+ "use client";let e=null,n=null;const t=/* @__PURE__ */new Map,i=32e3;function ensureCodeHighlight(){return e?Promise.resolve(!0):n??(n=import("./code-highlight-engine-BFDzDPzy.js").then(n=>(e=n.highlightCode,!0)).catch(()=>(n=null,!1)))}function codeTokens(n,i){if(!e||!n||n.length>32e3)return[];const o=`${i??""}\0${n}`,s=t.get(o);if(s)return s;const l=e(n,i??"");return t.size>=64&&t.delete(t.keys().next().value),t.set(o,l),l}export{i as M,codeTokens as c,ensureCodeHighlight as e};
@@ -1,40 +1 @@
1
- "use client";
2
- import { createLowlight, common } from "lowlight";
3
- const lowlight = createLowlight(common);
4
- const aliases = {
5
- jsx: "javascript",
6
- tsx: "typescript",
7
- html: "xml",
8
- sh: "bash",
9
- shell: "bash",
10
- ini: "ini"
11
- };
12
- const autoLanguages = ["javascript", "typescript", "json", "python", "bash", "sql", "css", "xml", "yaml", "java", "go", "rust", "cpp"];
13
- function highlightCode(text, language) {
14
- const normalized = language.toLowerCase().replace(/^language-/, "");
15
- if (["text", "txt", "plaintext", "plain"].includes(normalized)) return [];
16
- const name = aliases[normalized] ?? normalized;
17
- if (name && !lowlight.registered(name)) return [];
18
- try {
19
- const tree = name ? lowlight.highlight(name, text) : lowlight.highlightAuto(text, { subset: autoLanguages });
20
- const tokens = [];
21
- let offset = 0;
22
- const walk = (node, classes) => {
23
- if (node.type === "text") {
24
- const to = offset + node.value.length;
25
- if (to > offset && classes.length) tokens.push({ from: offset, to, classes: classes.join(" ") });
26
- offset = to;
27
- } else if ("children" in node) {
28
- const own = node.type === "element" && Array.isArray(node.properties.className) ? node.properties.className.filter((value) => typeof value === "string" && /^[\w-]+$/.test(value)) : [];
29
- for (const child of node.children) walk(child, [...classes, ...own]);
30
- }
31
- };
32
- walk(tree, []);
33
- return offset === text.length ? tokens : [];
34
- } catch {
35
- return [];
36
- }
37
- }
38
- export {
39
- highlightCode
40
- };
1
+ "use client";import{createLowlight as t,common as e}from"lowlight";const s=t(e),i={jsx:"javascript",tsx:"typescript",html:"xml",sh:"bash",shell:"bash",ini:"ini"},r=["javascript","typescript","json","python","bash","sql","css","xml","yaml","java","go","rust","cpp"];function highlightCode(t,e){const l=e.toLowerCase().replace(/^language-/,"");if(["text","txt","plaintext","plain"].includes(l))return[];const n=i[l]??l;if(n&&!s.registered(n))return[];try{const e=n?s.highlight(n,t):s.highlightAuto(t,{subset:r}),i=[];let l=0;const walk=(t,e)=>{if("text"===t.type){const s=l+t.value.length;s>l&&e.length&&i.push({from:l,to:s,classes:e.join(" ")}),l=s}else if("children"in t){const s="element"===t.type&&Array.isArray(t.properties.className)?t.properties.className.filter(t=>"string"==typeof t&&/^[\w-]+$/.test(t)):[];for(const i of t.children)walk(i,[...e,...s])}};return walk(e,[]),l===t.length?i:[]}catch{return[]}}export{highlightCode};
@@ -0,0 +1,14 @@
1
+ "use client";import{jsxs as e,jsx as t}from"react/jsx-runtime";import{c as n,b as o}from"./i18n-B0kCsIjc.js";import{useState as r,useRef as a,useEffect as i}from"react";import{codeLanguageLabel as l,CODE_LANGUAGES as d,isKnownCodeLanguage as c}from"wendang/shared";import{a as s,W as u,b as p}from"./index-COeA2QcQ.js";import{A as m}from"./AnchoredPanel-C7jMoPze.js";import{CODE_THEMES as h,codeLineCount as f}from"wendang/internal/code-block";function CodeToolbar({text:v,language:w,editable:g,canCopy:y,display:b,onLanguage:x,onDisplay:C}){const k=n().text,N=o(),[T,E]=r(""),[D,L]=r(!1),[z,H]=r(!1),[A,F]=r(!1),j=a(null),M=a(void 0),P=a(null),K=a(null),O=a(void 0),B=a(!0),$=a(!1),I=a({display:b,onDisplay:C,canCopy:y,text:v});function showFoldTip(){clearTimeout(M.current),M.current=setTimeout(()=>F(!0),200)}function hideFoldTip(){clearTimeout(M.current),F(!1)}function update(e){C({...b,...e})}function settings(e){var t;if("numbers"===e)update({lineNumbers:!b.lineNumbers});else if("height"===e)update({limited:!b.limited});else if(h.some(t=>t.value===e)){try{null==(t=N.preferences)||t.set("code-theme",e)}catch{}update({theme:e})}H(!1)}I.current={display:b,onDisplay:C,canCopy:y,text:v},i(()=>(B.current=!0,()=>{B.current=!1,clearTimeout(O.current),clearTimeout(M.current)}),[]),i(()=>{var e;try{const t=null==(e=N.preferences)?void 0:e.get("code-theme");h.some(e=>e.value===t)&&t!==I.current.display.theme&&I.current.onDisplay({...I.current.display,theme:t})}catch{}},[N.preferences]),i(()=>{if(!A)return;const close=()=>F(!1);return window.addEventListener("scroll",close,!0),()=>window.removeEventListener("scroll",close,!0)},[A]);const W="plaintext"===w?k("纯文本"):l(w)||k("自动识别"),X=[{value:"",label:k("自动识别")},{value:"plaintext",label:k("纯文本")},...d.filter(e=>e.value),...!w||"plaintext"===w||c(w)?[]:[{value:w,label:w}]];function menuKeydown(e){var t,n;if(!z||e.defaultPrevented||e.nativeEvent.isComposing||229===e.keyCode)return;if("Escape"===e.key)return e.preventDefault(),H(!1),void(null==(t=P.current)||t.focus());if(!["ArrowDown","ArrowUp","Home","End"].includes(e.key))return;const o=Array.from((null==(n=K.current)?void 0:n.querySelectorAll('[role="menuitem"],[role="menuitemradio"]'))??[]);if(!o.length)return;e.preventDefault();const r=o.indexOf(document.activeElement);o["Home"===e.key?0:"End"===e.key?o.length-1:(r+("ArrowUp"===e.key?-1:1)+o.length)%o.length].focus()}/* @__PURE__ */
2
+ return e("div",{className:"code-toolbar",contentEditable:!1,"aria-label":k("代码块工具栏"),onKeyDown:e=>{menuKeydown(e),"Escape"===e.key&&hideFoldTip(),e.stopPropagation()},onPointerDown:e=>e.stopPropagation(),children:[
3
+ /* @__PURE__ */t(s,{ref:j,variant:"text",size:"mini",className:"code-fold-button","aria-label":b.collapsed?k("展开代码块"):k("折叠代码块"),"aria-expanded":!b.collapsed,onMouseEnter:showFoldTip,onMouseLeave:hideFoldTip,onFocus:showFoldTip,onBlur:hideFoldTip,onClick:()=>update({collapsed:!b.collapsed}),children:/* @__PURE__ */t("svg",{width:"14",height:"14",viewBox:"0 0 16 16",fill:"none","aria-hidden":"true",style:{transform:b.collapsed?"rotate(-90deg)":void 0},children:/* @__PURE__ */t("path",{d:"m4 6 4 4 4-4",stroke:"currentColor",strokeWidth:"1.6",strokeLinecap:"round",strokeLinejoin:"round"})})}),A&&/* @__PURE__ */t(m,{anchor:j.current,onClose:hideFoldTip,role:"tooltip",align:"center",prefer:"above",gap:8,className:"code-tooltip-popup",children:/* @__PURE__ */t("div",{className:"w-tooltip",children:b.collapsed?k("展开代码"):k("折叠代码")})}),
4
+ /* @__PURE__ */e("span",{className:"code-toolbar-summary",children:[b.collapsed?"已折叠 · ":"",f(v)," ",k("行")]}),
5
+ /* @__PURE__ */e("div",{className:"code-toolbar-actions",children:[g?/* @__PURE__ */t(u,{className:"code-language-select",ariaLabel:k("代码语言"),value:w,options:X,size:"small",searchable:!0,onChange:x}):/* @__PURE__ */t("span",{className:"code-language-label",children:W}),
6
+ /* @__PURE__ */t("span",{className:"code-toolbar-divider","aria-hidden":"true"}),
7
+ /* @__PURE__ */e(s,{variant:"text",size:"mini",className:"code-copy-button","aria-label":k("复制代码"),disabled:!y,loading:D,title:k(y?"复制完整代码":"当前空间未开放导出"),onClick:()=>{!async function copy(){if(I.current.canCopy&&!$.current){$.current=!0,L(!0);try{await navigator.clipboard.writeText(I.current.text),B.current&&E(k("已复制"))}catch{B.current&&E(k("复制失败,请重试"))}finally{$.current=!1,B.current&&L(!1)}B.current&&(clearTimeout(O.current),O.current=setTimeout(()=>{B.current&&E("")},1800))}}()},children:[
8
+ /* @__PURE__ */t(p,{name:"copy",size:14}),
9
+ /* @__PURE__ */t("span",{children:T||k("复制代码")})]}),T&&/* @__PURE__ */t("span",{className:"code-copy-announcement",role:"status",children:T}),
10
+ /* @__PURE__ */t(s,{ref:P,variant:"text",size:"mini",className:"code-settings-button","aria-label":k("代码块显示设置"),"aria-expanded":z,onClick:()=>H(!z),children:/* @__PURE__ */t("span",{"aria-hidden":"true",children:"···"})}),z&&/* @__PURE__ */t(m,{anchor:P.current,onClose:()=>H(!1),role:"menu",label:k("代码块显示设置"),align:"end",gap:6,className:"code-settings-popup",onKeyDown:menuKeydown,children:/* @__PURE__ */e("div",{ref:K,className:"w-dropdown",children:[
11
+ /* @__PURE__ */e("div",{className:"w-dropdown-group",role:"group","aria-label":k("配色主题"),children:[
12
+ /* @__PURE__ */t("div",{className:"w-dropdown-group__title",children:k("配色主题")}),h.map(n=>/* @__PURE__ */e("div",{className:"w-dropdown-option",role:"menuitemradio",tabIndex:-1,"aria-checked":b.theme===n.value,onClick:()=>settings(n.value),onKeyDown:e=>{"Enter"!==e.key&&" "!==e.key||(e.preventDefault(),settings(n.value))},children:[
13
+ /* @__PURE__ */t("span",{className:"code-theme-swatch","data-code-swatch":n.value,"aria-hidden":"true"}),n.label,b.theme===n.value&&/* @__PURE__ */t("span",{className:"code-option-check","aria-hidden":"true",children:"✓"})]},n.value))]}),
14
+ /* @__PURE__ */t("div",{className:"w-dropdown-group",role:"group",children:[{value:"numbers",label:b.lineNumbers?k("隐藏行号"):k("显示行号")},{value:"height",label:b.limited?k("取消高度限制"):k("限制代码高度")}].map(e=>/* @__PURE__ */t("div",{className:"w-dropdown-option",role:"menuitem",tabIndex:-1,onClick:()=>settings(e.value),onKeyDown:t=>{"Enter"!==t.key&&" "!==t.key||(t.preventDefault(),settings(e.value))},children:k(e.label)},e.value))})]})})]})]})}let v=null,w=null;function tokenOf(e,t,n){return getComputedStyle(e).getPropertyValue(t).trim()||n}function showCommentHint(e,t){if("undefined"==typeof document)return;if(!(e instanceof HTMLElement))return;hideCommentHint();const n=document.createElement("div");n.className="doc-comment-hint",n.setAttribute("role","tooltip"),n.textContent=t,n.style.cssText=["position:fixed","z-index:1300","pointer-events:none","transform:translateX(-50%)","padding:5px 9px",`border:1px solid ${tokenOf(e,"--color-border","#dce2eb")}`,`background:${tokenOf(e,"--color-surface","#ffffff")}`,`color:${tokenOf(e,"--color-text","#1f2937")}`,"font-size:12px","line-height:1.5","white-space:nowrap","box-shadow:0 6px 20px #1018282e","border-radius:0"].join(";"),document.body.appendChild(n);const o=e.getBoundingClientRect(),r=n.getBoundingClientRect(),a=function commentHintPosition(e,t,n){const o=e.left+e.width/2,r=Math.max(0,t.width/2),a=r+8,i=Math.max(a,n.width-r-8),l=Math.min(Math.max(o,a),i);return e.top>=40?{left:l,top:e.top-8,placement:"top"}:{left:l,top:e.top+e.height+8,placement:"bottom"}}({left:o.left,top:o.top,width:o.width,height:o.height},{width:r.width,height:r.height},{width:window.innerWidth});n.style.left=`${a.left}px`,n.style.top=`${a.top}px`,"bottom"===a.placement?n.style.transform="translateX(-50%)":n.style.transform="translateX(-50%) translateY(-100%)",v=n,w=()=>hideCommentHint(),window.addEventListener("scroll",w,!0),window.addEventListener("resize",w)}function hideCommentHint(){v&&(v.remove(),v=null,w&&(window.removeEventListener("scroll",w,!0),window.removeEventListener("resize",w),w=null))}export{CodeToolbar as C,hideCommentHint as h,showCommentHint as s};
@@ -1,40 +1 @@
1
- "use client";
2
- const SETTLE_DELAY_MS = 0;
3
- let composing = false;
4
- let settleTimer = null;
5
- function isComposingNow() {
6
- return composing;
7
- }
8
- function beginComposition() {
9
- composing = true;
10
- if (settleTimer !== null) {
11
- clearTimeout(settleTimer);
12
- settleTimer = null;
13
- }
14
- }
15
- function endComposition() {
16
- if (settleTimer !== null) clearTimeout(settleTimer);
17
- settleTimer = setTimeout(() => {
18
- composing = false;
19
- settleTimer = null;
20
- }, SETTLE_DELAY_MS);
21
- }
22
- function resetCompositionState() {
23
- composing = false;
24
- if (settleTimer !== null) {
25
- clearTimeout(settleTimer);
26
- settleTimer = null;
27
- }
28
- }
29
- function shouldIgnoreForIme(event) {
30
- return composing || event.isComposing === true || event.keyCode === 229;
31
- }
32
- const IME_SETTLE_DELAY_MS = SETTLE_DELAY_MS;
33
- export {
34
- IME_SETTLE_DELAY_MS as I,
35
- beginComposition as b,
36
- endComposition as e,
37
- isComposingNow as i,
38
- resetCompositionState as r,
39
- shouldIgnoreForIme as s
40
- };
1
+ "use client";let o=!1,n=null;function isComposingNow(){return o}function beginComposition(){o=!0,null!==n&&(clearTimeout(n),n=null)}function endComposition(){null!==n&&clearTimeout(n),n=setTimeout(()=>{o=!1,n=null},0)}function resetCompositionState(){o=!1,null!==n&&(clearTimeout(n),n=null)}function shouldIgnoreForIme(n){return o||!0===n.isComposing||229===n.keyCode}const e=0;export{e as I,beginComposition as b,endComposition as e,isComposingNow as i,resetCompositionState as r,shouldIgnoreForIme as s};
@@ -0,0 +1,14 @@
1
+ "use client";var t=Object.defineProperty,__publicField=(e,n,o)=>((e,n,o)=>n in e?t(e,n,{enumerable:!0,configurable:!0,writable:!0,value:o}):e[n]=o)(e,"symbol"!=typeof n?n+"":n,o);import e from"@tiptap/starter-kit";import n from"@tiptap/extension-link";import o from"@tiptap/extension-placeholder";import{Table as a}from"@tiptap/extension-table";import r from"@tiptap/extension-table-row";import l from"@tiptap/extension-task-list";import i from"@tiptap/extension-task-item";import s from"@tiptap/extension-collaboration";import{a as c,b as d,c as u,d as m,T as p,H as f,l as h,V as g,M as v,C as b}from"./locale-DWpIJ_9X.js";import{readI18n as y}from"wendang/i18n";import{u as w,d as k,e as M,f as x,g as E,c as C}from"./i18n-B0kCsIjc.js";import{Fragment as A,Slice as L}from"@tiptap/pm/model";import{w as S,e as N,r as T}from"./katex-WjrodtTU.js";import{IMAGE_GALLERY_DEFAULT_HEIGHT as P,normalizeGalleryHeight as B,normalizeImageAspectRatio as R,IMAGE_GALLERY_MAX_IMAGES as I,imageAspectRatioFromSize as H}from"wendang/internal/image-gallery";import{jsx as D,jsxs as z}from"react/jsx-runtime";import{useState as O,useRef as $}from"react";import{createRoot as F}from"react-dom/client";import{calloutDOMAttributes as W,effectiveCallout as U,CALLOUT_COLORS as Y,CALLOUT_FILLS as X,CALLOUT_TONES as j,calloutSwatchStyle as q,CALLOUT_ICONS as G}from"wendang/shared";import{closeHistory as J}from"@tiptap/pm/history";import{yUndoPluginKey as V,yCursorPlugin as _}from"@tiptap/y-tiptap";import{validCalloutAttrs as K}from"wendang/internal/callout";import{A as Q}from"./AnchoredPanel-C7jMoPze.js";import{a as Z,b as tt}from"./index-COeA2QcQ.js";import{W as et}from"./Dropdown-D98tXfe0.js";import{C as nt,s as ot,h as at}from"./comment-hint-BhUxKjKK.js";import rt from"@tiptap/extension-code-block";import{codeBlockDisplay as lt,codeLineNumbers as it,codeBlockClass as st}from"wendang/internal/code-block";import{Node as ct,mergeAttributes as dt,Extension as ut}from"@tiptap/core";import{Plugin as mt,PluginKey as pt,Selection as ft,TextSelection as ht,SelectionRange as gt}from"@tiptap/pm/state";import{r as vt,e as bt,b as yt,s as wt}from"./composition-state-Bl-U1R_2.js";import{Decoration as kt,DecorationSet as Mt}from"@tiptap/pm/view";import{e as xt,c as Et}from"./code-highlight-BmaqTe1m.js";import{resolveInlineComments as Ct}from"wendang/internal/inline-comments";import{readableTextColor as At}from"wendang/internal/presence";import{CellSelection as Lt,TableMap as St,addRow as Nt,addColumn as Tt,selectedRect as Pt}from"@tiptap/pm/tables";import{cellBackground as Bt,CELL_BACKGROUNDS as Rt}from"wendang/internal/table-cell-format";import{TABLE_CELL_MIN_WIDTH as It}from"wendang/internal/table-layout";import Ht from"@tiptap/extension-table-cell";import Dt from"@tiptap/extension-table-header";import{paletteColor as zt}from"wendang/internal/document-colors";import Ot from"@tiptap/extension-image";const $t=ct.create({name:"columns",group:"block",content:"column+",defining:!0,parseHTML:()=>[{tag:"div[data-columns]"}],renderHTML:({HTMLAttributes:t})=>["div",dt(t,{"data-columns":"true","data-block-chrome":"",class:"doc-columns"}),0]}),Ft=ct.create({name:"column",content:"block+",defining:!0,parseHTML:()=>[{tag:"div[data-column]"}],renderHTML:({HTMLAttributes:t})=>["div",dt(t,{"data-column":"true",class:"doc-column"}),0]});function buildColumnsJson(t){const e=Math.min(Math.max(Math.round(t),1),5);return{type:"columns",content:Array.from({length:e},()=>({type:"column",content:[{type:"paragraph"}]}))}}const Wt=ct.create({name:"fileAttachment",group:"block",atom:!0,selectable:!0,draggable:!1,addAttributes:()=>({attachmentId:{default:null},filename:{default:""},mimeType:{default:""},size:{default:0}}),parseHTML:()=>[{tag:"div[data-file-attachment]"}],renderHTML({HTMLAttributes:t,node:e}){const n=e.attrs.filename||"附件";return["div",dt(t,{"data-file-attachment":"true","data-attachment-id":e.attrs.attachmentId??"","data-block-chrome":"",class:"doc-file-attachment"}),`[附件]${n}`]},renderText:({node:t})=>t.attrs.filename||"附件"}),Ut=Ot.extend({addAttributes(){var t;return{...null==(t=this.parent)?void 0:t.call(this),attachmentId:{default:null,parseHTML:t=>t.getAttribute("data-attachment-id"),renderHTML:t=>t.attachmentId?{"data-attachment-id":t.attachmentId}:{}},width:{default:null,parseHTML:t=>{const e=t.getAttribute("data-width")??t.getAttribute("width"),n=Number(e);return Number.isFinite(n)&&n>0?Math.round(n):null},renderHTML:t=>{const e=Number(t.width);return Number.isFinite(e)&&e>0?{"data-width":String(Math.round(e)),width:String(Math.round(e))}:{}}},align:{default:null,parseHTML:t=>{const e=t.getAttribute("data-align");return"left"===e||"center"===e||"right"===e?e:null},renderHTML:t=>{const e=t.align;return"left"===e||"center"===e||"right"===e?{"data-align":e}:{}}},aspectRatio:{default:null,parseHTML:t=>{const e=Number(t.getAttribute("data-aspect-ratio"));return Number.isFinite(e)&&e>0?e:null},renderHTML:t=>{const e=Number(t.aspectRatio);return Number.isFinite(e)&&e>0?{"data-aspect-ratio":String(e)}:{}}},galleryScale:{default:null,parseHTML:t=>{const e=Number(t.getAttribute("data-gallery-scale"));return Number.isFinite(e)&&e>0?e:null},renderHTML:t=>{const e=Number(t.galleryScale);return Number.isFinite(e)&&e>0&&1!==e?{"data-gallery-scale":String(e)}:{}}},caption:{default:null,parseHTML:t=>t.getAttribute("data-caption")||null,renderHTML:t=>t.caption?{"data-caption":String(t.caption)}:{}}}},parseHTML(){var t;return[{tag:"img[data-attachment-id]"},...(null==(t=this.parent)?void 0:t.call(this))??[]]}}),Yt=ct.create({name:"imageGallery",group:"block",content:"image{2,10}",defining:!0,addAttributes:()=>({height:{default:P,parseHTML:t=>B(t.getAttribute("data-gallery-height")),renderHTML:t=>{const e=B(t.height);return{"data-gallery-height":String(e),style:`--image-gallery-height:${e}px`}}}}),parseHTML:()=>[{tag:"div[data-image-gallery]"}],renderHTML:({HTMLAttributes:t})=>["div",dt(t,{"data-image-gallery":"true",class:"ywiki-image-gallery"}),0]}),Xt=ct.create({name:"mathInline",group:"inline",inline:!0,atom:!0,selectable:!0,addAttributes:()=>({latex:{default:"",parseHTML:t=>t.getAttribute("data-latex")??"",renderHTML:t=>({"data-latex":t.latex})}}),parseHTML:()=>[{tag:"span[data-math-inline]"}],renderHTML:({HTMLAttributes:t,node:e})=>["span",dt(t,{"data-math-inline":"true",class:"doc-math-inline"}),`$${e.attrs.latex}$`],renderText:({node:t})=>`$${t.attrs.latex}$`}),jt=ct.create({name:"mathBlock",group:"block",atom:!0,selectable:!0,addAttributes:()=>({latex:{default:"",parseHTML:t=>t.getAttribute("data-latex")??"",renderHTML:t=>({"data-latex":t.latex})}}),parseHTML:()=>[{tag:"div[data-math-block]"}],renderHTML:({HTMLAttributes:t,node:e})=>["div",dt(t,{"data-math-block":"true","data-block-chrome":"",class:"doc-math-block"}),`$$${e.attrs.latex}$$`],renderText:({node:t})=>`$$\n${t.attrs.latex}\n$$`}),qt=ct.create({name:"pageLink",group:"inline",inline:!0,atom:!0,selectable:!0,addAttributes:()=>({pageId:{default:null},label:{default:""}}),parseHTML:()=>[{tag:"span[data-page-link]",getAttrs:t=>{const e=t;return{pageId:e.getAttribute("data-page-id")??null,label:e.textContent??""}}}],renderHTML:({HTMLAttributes:t,node:e})=>["span",dt(t,{"data-page-link":"true","data-page-id":e.attrs.pageId,class:"doc-page-link"}),e.attrs.label||"页面"],renderText:({node:t})=>t.attrs.label||"页面"}),Gt=ct.create({name:"mention",group:"inline",inline:!0,atom:!0,selectable:!0,addAttributes:()=>({userId:{default:null},label:{default:""}}),parseHTML:()=>[{tag:"span[data-mention]",getAttrs:t=>{var e;const n=t;return{userId:n.getAttribute("data-user-id")??null,label:(null==(e=n.textContent)?void 0:e.replace(/^@/,""))??""}}}],renderHTML:({HTMLAttributes:t,node:e})=>["span",dt(t,{"data-mention":"true","data-user-id":e.attrs.userId,class:"doc-mention"}),`@${e.attrs.label||"用户"}`],renderText:({node:t})=>`@${t.attrs.label||"用户"}`}),Jt=["left","center","right"],isCellAlign=t=>"string"==typeof t&&Jt.includes(t),Vt={default:null,parseHTML:t=>{var e;const n=null==(e=t.style)?void 0:e.textAlign;if(isCellAlign(n))return n;const o=t.getAttribute("data-align");return isCellAlign(o)?o:null},renderHTML:t=>isCellAlign(t.align)?{"data-align":t.align,style:`text-align: ${t.align}`}:{}},_t={default:null,parseHTML:t=>zt(t.getAttribute("data-cell-background")??t.style.backgroundColor,Rt),renderHTML:t=>{const e=Bt(t.backgroundColor);return e?{"data-cell-background":e,style:`background-color: ${e}; color: #202124`}:{}}},Kt=Ht.extend({addAttributes(){var t;return{...null==(t=this.parent)?void 0:t.call(this),align:Vt,backgroundColor:_t}}}),Qt=Dt.extend({addAttributes(){var t;return{...null==(t=this.parent)?void 0:t.call(this),align:Vt,backgroundColor:_t}}}),Zt=/* @__PURE__ */new WeakMap,te=/* @__PURE__ */new WeakMap,createImageNodeView=(t=w,e,n)=>({node:o,getPos:a,editor:r})=>{var l,i,s,c,d,u,m;y(r).text;let p=te.get(r);p||(p=crypto.randomUUID(),te.set(r,p));const f=`ywiki-image-drop-line-${p}`,imageDragLayer=()=>(null==n?void 0:n())??r.view.dom.closest(".editor-shell")??document.body,clearImageDropTargets=()=>{var t;for(const t of r.view.dom.querySelectorAll(".is-image-drop-target"))t.classList.remove("is-image-drop-target");null==(t=document.getElementById(f))||t.remove()},h={get value(){return Zt.get(r)??null},set value(t){t?Zt.set(r,t):Zt.delete(r)}},g=document.createElement("div");g.className="ywiki-image-frame";const v=document.createElement("div");v.className="ywiki-image-inner",g.appendChild(v);const b=document.createElement("img");b.className="ywiki-image",b.setAttribute("draggable","false");let w=String((null==(l=o.attrs)?void 0:l.attachmentId)??"");const inImageGallery=()=>{const t="function"==typeof a?a():null;if(null==t||r.isDestroyed||t>=r.state.doc.content.size)return!1;try{return"imageGallery"===r.state.doc.resolve(t).parent.type.name}catch{return!1}};let M=String((null==(i=o.attrs)?void 0:i.alt)??""),x=o;const aspectCloseEnough=(t,e)=>!(!Number.isFinite(t)||!Number.isFinite(e)||e<=0)&&Math.abs(t-e)/e<=.02,backfillAspectRatio=()=>{var t,e;const n=H(b.naturalWidth,b.naturalHeight);if(null===n)return;const o=R(null==(t=x.attrs)?void 0:t.aspectRatio);if(null!==o&&aspectCloseEnough(o,n))return;const l="function"==typeof a?a():null;if(null==l||r.isDestroyed||!r.isEditable)return;const i=r.state.doc.nodeAt(l);if(!i||"image"!==i.type.name)return;const s=R(null==(e=i.attrs)?void 0:e.aspectRatio);null!==s&&aspectCloseEnough(s,n)||r.view.dispatch(r.state.tr.setNodeMarkup(l,void 0,{...i.attrs,aspectRatio:n}))},markLoaded=()=>{b.removeAttribute("data-image-loading"),M&&(b.alt=M,b.title=M),backfillAspectRatio()};b.setAttribute("data-image-loading","true");const applyWidth=t=>{if(inImageGallery())return b.style.removeProperty("width"),void g.removeAttribute("data-sized");const e=Number(t);Number.isFinite(e)&&e>0?(b.style.width=`${Math.round(e)}px`,g.setAttribute("data-sized","true")):(b.style.removeProperty("width"),g.removeAttribute("data-sized"))};applyWidth(null==(s=o.attrs)?void 0:s.width);const applyAspectRatio=t=>{const e=R(t);null===e?(g.style.removeProperty("--ywiki-image-ratio"),g.removeAttribute("data-aspect-ratio")):(g.style.setProperty("--ywiki-image-ratio",String(e)),g.setAttribute("data-aspect-ratio",String(e)))},applyGalleryScale=t=>{const e=Number(t);Number.isFinite(e)&&e>0&&1!==e?(g.style.setProperty("--ywiki-image-weight",String(e)),g.setAttribute("data-gallery-scale",String(e))):(g.style.removeProperty("--ywiki-image-weight"),g.removeAttribute("data-gallery-scale"))};applyAspectRatio(null==(c=o.attrs)?void 0:c.aspectRatio),applyGalleryScale(null==(d=o.attrs)?void 0:d.galleryScale);const E=document.createElement("div");E.className="ywiki-image-caption",E.setAttribute("contenteditable","false");let C=!1;const applyCaption=t=>{const e="string"==typeof t?t:"";C||(E.textContent=e,E.hidden=0===e.length,g.classList.toggle("has-caption",e.length>0),e&&(E.title=e))};function commitCaption(t){var e;C=!1,E.removeAttribute("contenteditable"),E.classList.remove("is-editing");const n="function"==typeof a?a():null;if(null==n||r.isDestroyed)return;const o=r.state.doc.nodeAt(n);if(!o||"image"!==o.type.name)return;const l=t.trim().slice(0,500);((null==(e=o.attrs)?void 0:e.caption)??"")!==(l||null)?r.view.dispatch(r.state.tr.setNodeMarkup(n,void 0,{...o.attrs,caption:l||null})):applyCaption(l)}function startCaptionEdit(){var t;if(!r.isEditable)return;C=!0,E.hidden=!1,g.classList.add("has-caption"),E.textContent=String((null==(t=o.attrs)?void 0:t.caption)??""),E.setAttribute("contenteditable","true"),E.classList.add("is-editing"),E.focus();const e=document.createRange();e.selectNodeContents(E),e.collapse(!1);const n=window.getSelection();null==n||n.removeAllRanges(),null==n||n.addRange(e)}applyCaption(null==(u=o.attrs)?void 0:u.caption),E.addEventListener("dblclick",t=>{t.preventDefault(),t.stopPropagation(),startCaptionEdit()}),E.addEventListener("keydown",t=>{C&&(t.stopPropagation(),"Escape"===t.key?(t.preventDefault(),commitCaption("")):"Enter"===t.key&&(t.preventDefault(),commitCaption(E.textContent??"")))}),E.addEventListener("blur",()=>{C&&commitCaption(E.textContent??"")}),g.addEventListener("ywiki-caption-edit",startCaptionEdit);const applyAlign=t=>{"left"===t||"center"===t||"right"===t?g.setAttribute("data-align",t):g.removeAttribute("data-align")};applyAlign(null==(m=o.attrs)?void 0:m.align);let L,N=null;const load=n=>{if(null==L||L(),null==N||N(),N=null,!n)return b.removeAttribute("src"),b.removeAttribute("data-image-loading"),void b.setAttribute("data-image-missing","true");b.removeAttribute("data-image-missing"),b.removeAttribute("data-image-error"),b.getAttribute("src")?markLoaded():b.setAttribute("data-image-loading","true"),N=S(b,()=>(n=>{null==L||L(),L=k(n,t=>{w===n&&(b.src=t,b.complete&&b.naturalWidth>0?markLoaded():b.addEventListener("load",()=>markLoaded(),{once:!0}))},t,()=>{w===n&&(b.removeAttribute("data-image-loading"),M&&(b.alt=M,b.title=M),b.setAttribute("data-image-error","true"))},e)})(n))};load(w);const T={nw:"nwse-resize",ne:"nesw-resize",sw:"nesw-resize",se:"nwse-resize"},B=[];for(const t of["nw","ne","sw","se"]){const e=document.createElement("div");e.className=`ywiki-image-handle handle-${t}`,e.setAttribute("aria-hidden","true"),e.setAttribute("contenteditable","false"),e.addEventListener("mousedown",e=>startResize(e,t)),v.appendChild(e),B.push(e)}const syncGalleryMode=()=>{const t=inImageGallery();g.classList.toggle("is-in-gallery",t),g.setAttribute("draggable",t?"false":"true");for(const e of B)e.hidden=t};syncGalleryMode(),requestAnimationFrame(()=>syncGalleryMode());const setSelected=t=>{g.classList.toggle("is-selected",t)};let D=null,z=null;const galleryContainerOf=t=>{if(r.isDestroyed)return null;try{const e=r.state.doc.resolve(t),n=e.parent;return"imageGallery"!==n.type.name||0===e.depth?null:{node:n,pos:e.before()}}catch{return null}},onGalleryMove=t=>{const e=D;if(!e)return;e.lastX=t.clientX,e.lastY=t.clientY;const n=g.closest(".ywiki-image-gallery");if(!(n instanceof HTMLElement))return;const o=n.getBoundingClientRect(),a=Array.from(n.children).filter(t=>t instanceof HTMLElement&&t!==z);if(e.outside=t.clientX<o.left-24||t.clientX>o.right+24||t.clientY<o.top-24||t.clientY>o.bottom+24,e.outside)return void(z&&(z.style.opacity="0"));const r=a.filter(t=>t!==g);let l=r.length;for(let e=0;e<r.length;e+=1){const n=r[e].getBoundingClientRect();if(t.clientX<n.left+n.width/2){l=e;break}}e.dropIndex=e.index<=l?l+1:l;const i=r[Math.min(l,r.length-1)];let s=o.left;if(i){const t=i.getBoundingClientRect();s=l>=r.length?t.right:t.left}!function showIndicator(t,e,n){if(!z){z=document.createElement("div"),z.className="ywiki-gallery-drop-line",z.setAttribute("aria-hidden","true");const t=getComputedStyle(g).getPropertyValue("--color-accent").trim()||getComputedStyle(document.documentElement).getPropertyValue("--color-accent").trim()||"#2f6feb";z.style.background=t,z.style.width="3px",z.style.borderRadius="999px",z.style.border="1px solid rgba(255, 255, 255, 0.9)",z.style.boxShadow="0 0 0 1px rgba(0, 0, 0, 0.06), 0 2px 10px rgba(0, 0, 0, 0.18)",imageDragLayer().appendChild(z)}z.style.left=Math.round(t)-1+"px",z.style.top=`${Math.round(e)}px`,z.style.height=`${Math.round(n)}px`,z.style.opacity="1"}(s,o.top,o.height)},onGalleryUp=()=>{const t=D;if(function clearGalleryDrag(){D=null,z&&(z.remove(),z=null),document.removeEventListener("mousemove",onGalleryMove,!0),document.removeEventListener("mouseup",onGalleryUp,!0),g.classList.remove("is-gallery-dragging"),document.documentElement.style.cursor=""}(),!t||!r.isEditable)return;const e="function"==typeof a?a():null;if(null==e)return;const n=galleryContainerOf(e);if(!n)return;const o=r.state.doc.nodeAt(e);if(!o||"image"!==o.type.name)return;if(!t.outside&&t.dropIndex===t.index)return;const l=r.state.tr,i=n.node,s=r.schema.nodes.image,c=r.schema.nodes.imageGallery;if(!s||!c)return;const d=[];if(i.forEach(t=>{d.push(t)}),d.length!==t.childPositions.length)return;const u=n.pos,m=u+i.nodeSize;if(t.outside){const e=function imageHitTest(t,e){if(r.isDestroyed)return null;const n=g.style.pointerEvents;g.style.pointerEvents="none";const o=document.elementFromPoint(t,e);if(g.style.pointerEvents=n,!(o instanceof Element))return null;const a=o.closest(".ywiki-image-frame");if(!(a instanceof HTMLElement)||a===g)return null;const l=g.closest(".ywiki-image-gallery"),i=a.closest(".ywiki-image-gallery");if(i instanceof HTMLElement){if(i===l)return null;let t=null;return r.state.doc.descendants((e,n)=>{if(!t&&"imageGallery"===e.type.name)try{r.view.nodeDOM(n)===i&&(t={kind:"gallery",pos:n,node:e})}catch{}}),t}if(!a.querySelector("img"))return null;let s=null;try{const t=r.view.posAtDOM(a,0),e=[t,t-1,t+1].filter(t=>t>=0&&t<=r.state.doc.content.size);for(const t of e){const e=r.state.doc.nodeAt(t);if("image"===(null==e?void 0:e.type.name)){s=t;break}}}catch(t){s=null}if(null===s)return null;const c=r.state.doc.nodeAt(s);return c?{kind:"image",pos:s,node:c}:null}(t.lastX,t.lastY);if(e&&e.pos!==u)if("image"===e.kind){const n=function mergeIntoStandalone(t,e,n,o,a){const{state:l}=r,i=l.schema.nodes.imageGallery;if(!i)return!1;if(a.pos===t)return!1;const s=[];e.forEach((t,e,n)=>{n!==o&&s.push(t)});const c=s.length>=2?[i.create(e.attrs,A.fromArray(s))]:1===s.length?[s[0]]:[],d=i.create({height:P},A.fromArray([a.node,n])),u=topLevelIndexOf(t),m=topLevelIndexOf(a.pos);return!(u<0||m<0)&&replaceTopLevelBlocks(u,c,m,[d])}(u,i,o,t.index,e);if(n)return}else if(function moveImageIntoGalleryAt(t,e,n,o,a,l){const{state:i}=r,s=i.schema.nodes.imageGallery;if(!s)return!1;if(a.pos===t)return!1;if(a.node.content.childCount>=I)return!1;const c=[];a.node.forEach(t=>{c.push(t)});const d=r.view.nodeDOM(a.pos),u=d instanceof HTMLElement?[...d.querySelectorAll(".ywiki-image-frame")]:[];let m=c.length-1;for(let t=0;t<u.length&&t<c.length;t+=1){const e=u[t].getBoundingClientRect();if(l.x<e.left+e.width/2){m=t;break}m=t+1}const p=Math.max(0,Math.min(m,c.length));c.splice(p,0,n);const f=[];e.forEach((t,e,n)=>{n!==o&&f.push(t)});const h=f.length>=2?[s.create(e.attrs,A.fromArray(f))]:1===f.length?[f[0]]:[],g=topLevelIndexOf(t),v=topLevelIndexOf(a.pos);return!(g<0||v<0)&&replaceTopLevelBlocks(g,h,v,[s.create(a.node.attrs,A.fromArray(c))])}(u,i,o,t.index,e,{x:t.lastX,y:t.lastY}))return;d.splice(t.index,1);const n=d.length>=2?[c.create(i.attrs,A.fromArray(d)),o]:1===d.length?[d[0],o]:[o];return l.replaceWith(u,m,A.fromArray(n)),r.view.dispatch(l),void r.commands.focus()}const p=t.index,f=t.dropIndex>p?t.dropIndex-1:t.dropIndex;if(f===p)return;const[h]=d.splice(p,1);d.splice(f,0,h),l.replaceWith(u,m,c.create(i.attrs,A.fromArray(d))),r.view.dispatch(l),r.commands.focus()};g.addEventListener("mousedown",t=>{if(!inImageGallery())return;const e=g.closest(".ywiki-image-gallery");e instanceof HTMLElement&&(e.classList.contains("is-block-selected")||e.classList.contains("is-block-image-selected"))||function startGalleryDrag(t){if(0!==t.button||!r.isEditable||t.altKey)return;const e="function"==typeof a?a():null;if(null==e)return;const n=galleryContainerOf(e);if(!n)return;const o=[];n.node.forEach((t,e)=>{o.push(n.pos+1+e)});const l=o.indexOf(e);if(l<0)return;const i=t.clientX,s=t.clientY;let c=!1;const arm=e=>{if(c)return;const a=e.clientX-i,r=e.clientY-s;Math.hypot(a,r)<32||(c=!0,document.removeEventListener("mousemove",arm,!0),g.classList.add("is-gallery-dragging"),document.documentElement.style.cursor="grabbing",D={galleryPos:n.pos,galleryEnd:n.pos+n.node.nodeSize,childPositions:o,index:l,dropIndex:l,outside:!1,element:g,lastX:t.clientX,lastY:t.clientY},document.addEventListener("mousemove",onGalleryMove,!0),document.addEventListener("mouseup",onGalleryUp,!0))},blockNativeDrag=t=>{t.preventDefault()};g.addEventListener("dragstart",blockNativeDrag,!0);const stopBlockingDrag=()=>{g.removeEventListener("dragstart",blockNativeDrag,!0),document.removeEventListener("mouseup",stopBlockingDrag,!0)};document.addEventListener("mouseup",stopBlockingDrag,!0),document.addEventListener("mousemove",arm,!0);const cancelArm=()=>{document.removeEventListener("mousemove",arm,!0),document.removeEventListener("mouseup",cancelArm,!0)};document.addEventListener("mouseup",cancelArm,!0)}(t)});const ownPos=()=>{const t="function"==typeof a?a():null;return"number"==typeof t?t:null},visibleRect=()=>{const t=v.getBoundingClientRect();return t.width>1&&t.height>1?t:g.getBoundingClientRect()},dropAfter=t=>{const e=visibleRect();return t.clientX>=e.left+e.width/2},hideMergeHint=()=>{var t;g.classList.remove("is-image-drop-target"),null==(t=document.getElementById(f))||t.remove()};function topLevelIndexOf(t){let e=0,n=0,o=-1;return r.state.doc.forEach(a=>{o<0&&e===t&&(o=n),e+=a.nodeSize,n+=1}),o}function replaceTopLevelBlocks(t,e,n,o){const{state:a}=r,l=[];if(a.doc.forEach(t=>{l.push(t)}),t<0||t>=l.length)return!1;if(n<0||n>=l.length)return!1;if(t===n)return!1;const i=[];for(let a=0;a<l.length;a+=1)a===t?i.push(...e):a===n?i.push(...o):i.push(l[a]);const s=a.tr;try{const a=[];t<=n?(a.push({index:n,nodes:o}),a.push({index:t,nodes:e})):(a.push({index:t,nodes:e}),a.push({index:n,nodes:o}));let i=[],c=0;for(const t of l)i.push(c),c+=t.nodeSize;for(const t of a){const e=s.mapping.map(i[t.index],1),n=s.mapping.map(i[t.index]+l[t.index].nodeSize,-1);s.replaceWith(e,Math.max(e,n),A.fromArray(t.nodes))}r.view.dispatch(s)}catch{return!1}return r.commands.focus(),!0}function startResize(t,e){const n="nw"===e||"sw"===e?-1:1;if(0!==t.button||!r.isEditable)return;if(t.preventDefault(),t.stopPropagation(),inImageGallery())return void function resizeInGallery(t,e){var n;const o="function"==typeof a?a():null;if(null==o)return;const l=r.state.doc.nodeAt(o);if(!l||"image"!==l.type.name)return;const i=t.clientX,s=g.getBoundingClientRect().width,c=Number(null==(n=l.attrs)?void 0:n.galleryScale)||1,d=document.documentElement.style.cursor;g.classList.add("is-resizing"),document.documentElement.style.cursor=T.nw,document.body.style.userSelect="none";let u=c;const onMove=t=>{const n=(t.clientX-i)*e,o=Math.max(24,s+n);var a;a=c*(o/Math.max(1,s)),u=Math.max(.25,Math.min(4,a)),g.style.setProperty("--ywiki-image-weight",String(u))},onUp=()=>{if(window.removeEventListener("mousemove",onMove),window.removeEventListener("mouseup",onUp),window.removeEventListener("blur",onUp),g.classList.remove("is-resizing"),document.documentElement.style.cursor=d,document.body.style.userSelect="",r.isDestroyed)return;const t=r.state.doc.nodeAt(o);if(!t||"image"!==t.type.name)return;const e=Math.round(1e3*u)/1e3;Math.abs(e-c)<.001?g.style.removeProperty("--ywiki-image-weight"):r.view.dispatch(r.state.tr.setNodeMarkup(o,void 0,{...t.attrs,galleryScale:1===e?null:e}))};window.addEventListener("mousemove",onMove),window.addEventListener("mouseup",onUp),window.addEventListener("blur",onUp)}(t,n);g.classList.add("is-resizing");const o=T[e],l=document.documentElement.style.cursor;document.documentElement.style.cursor=o;const i=t.clientX,s=b.getBoundingClientRect().width,c=r.view.dom.clientWidth||Number.POSITIVE_INFINITY,onMove=t=>{const e=(t.clientX-i)*n,o=Math.max(40,Math.min(c,Math.round(s+e)));b.style.width=`${o}px`,g.setAttribute("data-sized","true")},onUp=()=>{window.removeEventListener("mousemove",onMove),window.removeEventListener("mouseup",onUp),window.removeEventListener("blur",onUp),g.classList.remove("is-resizing"),document.documentElement.style.cursor=l;const t=Math.round(b.getBoundingClientRect().width),e="function"==typeof a?a():null;if(null==e||r.isDestroyed)return;const n=r.state.doc.nodeAt(e);n&&"image"===n.type.name&&Number(n.attrs.width)!==t&&r.view.dispatch(r.state.tr.setNodeMarkup(e,void 0,{...n.attrs,width:t}))};window.addEventListener("mousemove",onMove),window.addEventListener("mouseup",onUp),window.addEventListener("blur",onUp)}return g.addEventListener("dragstart",t=>{var e,n;if(inImageGallery())return;const o=ownPos();if(null===o||!r.isEditable)return;const a=r.state.doc.nodeAt(o);if(a&&"image"===a.type.name){h.value={pos:o,node:a},null==(e=t.dataTransfer)||e.setData("text/plain",""),t.dataTransfer&&(t.dataTransfer.effectAllowed="move");try{null==(n=t.dataTransfer)||n.setDragImage(b,b.width/2,Math.min(b.height/2,40))}catch{}}}),g.addEventListener("dragend",()=>{h.value=null,hideMergeHint(),clearImageDropTargets(),queueMicrotask(clearImageDropTargets)}),g.addEventListener("dragover",t=>{if(!h.value)return;const e=ownPos();null!==e&&h.value.pos!==e&&(t.preventDefault(),t.stopPropagation(),t.dataTransfer&&(t.dataTransfer.dropEffect="move"),(t=>{const e=visibleRect();g.classList.add("is-image-drop-target");let n=document.getElementById(f);if(!n){n=document.createElement("div"),n.id=f,n.className="ywiki-image-drop-line",n.setAttribute("aria-hidden","true");const t=getComputedStyle(g).getPropertyValue("--color-accent").trim()||getComputedStyle(document.documentElement).getPropertyValue("--color-accent").trim()||"#2f6feb";n.style.background=t,n.style.width="3px",n.style.borderRadius="999px",n.style.border="1px solid rgba(255, 255, 255, 0.9)",n.style.boxShadow="0 0 0 1px rgba(0, 0, 0, 0.06), 0 2px 10px rgba(0, 0, 0, 0.18)",imageDragLayer().appendChild(n)}const o=dropAfter(t);n.style.top=`${Math.round(e.top)}px`,n.style.height=`${Math.round(e.height)}px`,n.style.left=`${Math.round(o?e.right+4:e.left-4)}px`,n.style.opacity="1"})(t))}),g.addEventListener("dragleave",t=>{if(!h.value)return;const e=t.relatedTarget;e instanceof Node&&g.contains(e)||hideMergeHint()}),g.addEventListener("drop",t=>{var e;const n=h.value;if(!n)return;const o=ownPos();if(null===o)return;if(hideMergeHint(),clearImageDropTargets(),h.value=null,queueMicrotask(clearImageDropTargets),n.pos===o)return;t.preventDefault(),t.stopPropagation();const a=galleryContainerOf(o);if(a){const o=[];a.node.forEach(t=>{o.push(t)}),dropAfter(t)&&o.length;const l=[...(null==(e=g.parentElement)?void 0:e.children)??[]].filter(t=>t instanceof HTMLElement&&t.classList.contains("ywiki-image-frame"));let i=l.length;for(let e=0;e<l.length;e+=1){const n=l[e].getBoundingClientRect();if(t.clientX<n.left+n.width/2){i=e;break}}return void function insertIntoGallery(t,e,n,o){const{state:a}=r,l=a.doc.nodeAt(t);if(!l||"image"!==l.type.name)return!1;const i=a.schema.nodes.imageGallery;if(!i)return!1;if(n.content.content.slice().length>=I)return!1;const s=t<e?l.nodeSize:0,c=[];n.forEach(t=>{c.push(t)}),c.splice(o,0,l);const d=a.tr;d.delete(t,t+l.nodeSize);const u=e-s;d.replaceWith(u,u+n.nodeSize,i.create(n.attrs,A.fromArray(c))),r.view.dispatch(d),r.commands.focus()}(n.pos,a.pos,a.node,i)}!function mergeTwoImages(t,e,n){const{state:o}=r,a=o.doc.nodeAt(t),l=o.doc.nodeAt(e);if(!a||!l||"image"!==a.type.name||"image"!==l.type.name)return!1;const i=o.schema.nodes.imageGallery;if(!i)return!1;const s=n?[l,a]:[a,l],c=Math.min(t,e),d=Math.max(t,e),u=c===t?a:l,m=d===t?a:l,p=o.doc.slice(c+u.nodeSize,d).content,f=i.create({height:P},A.fromArray(s)),h=o.tr.replaceWith(c,d+m.nodeSize,A.fromArray([f]).append(p));r.view.dispatch(h),r.commands.focus()}(n.pos,o,dropAfter(t))}),v.appendChild(b),g.appendChild(E),{dom:g,update:t=>{var e,n,o,a,r,l,i,s;if("image"!==t.type.name)return!1;const c=String((null==(e=t.attrs)?void 0:e.alt)??"");c!==M&&(M=c,b.getAttribute("data-image-loading")||(b.alt=M,b.title=M));const d=null==(n=t.attrs)?void 0:n.aspectRatio,u=String(d??"")!==String((null==(o=x.attrs)?void 0:o.aspectRatio)??"");x=t,applyAspectRatio(d),u&&queueMicrotask(backfillAspectRatio),applyGalleryScale(null==(a=t.attrs)?void 0:a.galleryScale),applyCaption(null==(r=t.attrs)?void 0:r.caption),syncGalleryMode(),applyWidth(null==(l=t.attrs)?void 0:l.width),applyAlign(null==(i=t.attrs)?void 0:i.align);const m=String((null==(s=t.attrs)?void 0:s.attachmentId)??"");return m!==w&&(w=m,load(m)),!0},selectNode:()=>{setSelected(!0),syncGalleryMode()},deselectNode:()=>{setSelected(!1),syncGalleryMode()},destroy:()=>{setSelected(!1),w="",hideMergeHint(),clearImageDropTargets(),null==L||L(),null==N||N(),N=null}}};function dispatch(t,e){var n;const o=null==(n=V.getState(t.state))?void 0:n.undoManager;null==o||o.stopCapturing(),t.view.dispatch(J(e)),null==o||o.stopCapturing()}function unwrapCallout(t,e){if(!t.isEditable||t.isDestroyed)return!1;const n=t.state.doc.nodeAt(e);if("callout"!==(null==n?void 0:n.type.name))return!1;const o=t.state.doc.resolve(e);return!!o.parent.canReplace(o.index(),o.index()+1,n.content)&&(dispatch(t,t.state.tr.replaceWith(e,e+n.nodeSize,n.content)),!0)}const ee={info:"💡 提示",success:"✅ 成功",warning:"⚠️ 注意",danger:"❗ 警告"},ne={gray:"灰",red:"红",orange:"橙",yellow:"黄",green:"绿",blue:"蓝",purple:"紫"};function swatchName(t,e,n){if(null===t)return n.t("common.default");if("none"===t)return n.t("common.none");const o=n.text(ne[t.replace("-strong","")]??t);return"backgroundColor"!==e?o:n.t("color.tone",{tone:n.text(t.endsWith("-strong")?"浓":"浅"),color:o})}function CalloutControls({attrs:t,editable:e,portal:n,onPatch:o,onUnwrap:a}){const r=C(),l=r.text,[i,s]=O("none"),[c,d]=O(!1),u=$(null),m=$(null),p=$(null),f=$(null),h=U(t),g="color"===i?m.current:"icon"===i?f.current:null,v=[{key:"textColor",label:l("字体颜色"),values:[null,...Y]},{key:"borderColor",label:l("边框颜色"),values:["none",...Y]},{key:"backgroundColor",label:l("填充颜色"),values:[null,"none",...X]}],selected=(e,n)=>("borderColor"===e?h.borderColor:t[e]??null)===n;/* @__PURE__ */
2
+ return z("div",{className:"callout-controls",contentEditable:!1,onPointerDown:t=>t.stopPropagation(),onKeyDown:t=>t.stopPropagation(),children:[h.icon&&/* @__PURE__ */D(Z,{ref:u,variant:"text",className:"callout-icon callout-icon-button","aria-label":l("更换高亮块图标"),"aria-expanded":"icon"===i,disabled:!e,onClick:t=>{f.current=t.currentTarget,s("icon"===i?"none":"icon")},children:h.icon}),e&&/* @__PURE__ */z("div",{className:"callout-toolbar"+("none"!==i||c?" is-open":""),"aria-label":l("高亮块操作"),children:[
3
+ /* @__PURE__ */D(Z,{ref:m,variant:"text",size:"small",className:"callout-toolbar-button callout-palette-button","aria-label":l("高亮块颜色设置"),"aria-expanded":"color"===i,onClick:()=>s("color"===i?"none":"color"),children:/* @__PURE__ */D(tt,{name:"palette",size:22})}),
4
+ /* @__PURE__ */D(Z,{ref:p,variant:"text",size:"small",className:"callout-toolbar-button","aria-label":l("高亮块图标设置"),"aria-expanded":"icon"===i,onClick:t=>{f.current=t.currentTarget,s("icon"===i?"none":"icon")},children:l("图标")}),
5
+ /* @__PURE__ */D(et,{label:l("预设"),buttonProps:{variant:"text",size:"small",className:"callout-toolbar-button","aria-label":l("高亮块预设")},groups:[{items:j.map(t=>({value:t,label:l(ee[t])}))}],onOpenChange:t=>{d(t),t&&s("none")},onSelect:t=>o({tone:t,icon:null,textColor:null,borderColor:null,backgroundColor:null})}),
6
+ /* @__PURE__ */D("span",{className:"callout-toolbar-divider","aria-hidden":"true"}),
7
+ /* @__PURE__ */D(Z,{variant:"text",size:"small",className:"callout-toolbar-button",onClick:a,children:l("取消高亮块")})]}),"color"===i&&/* @__PURE__ */D(Q,{anchor:g,portal:n,label:l("高亮块颜色"),onClose:()=>s("none"),align:"start",prefer:"below",gap:6,children:/* @__PURE__ */z("div",{className:"callout-color-panel",role:"group","aria-label":l("高亮块颜色"),children:[v.map(t=>/* @__PURE__ */z("section",{children:[
8
+ /* @__PURE__ */D("div",{className:"callout-color-label",children:t.label}),
9
+ /* @__PURE__ */D("div",{className:"callout-color-grid",role:"group","aria-label":t.label,children:t.values.map(e=>/* @__PURE__ */D("button",{type:"button",className:`callout-color-choice${selected(t.key,e)?" is-selected":""}${"none"===e?" is-none":""}`,style:q(t.key,e),"aria-label":`${t.label}:${swatchName(e,t.key,r)}`,"aria-pressed":selected(t.key,e),onClick:()=>o({[t.key]:e}),children:"none"===e?/* @__PURE__ */D("span",{className:"color-transparency-grid","aria-hidden":"true"}):"textColor"===t.key?/* @__PURE__ */D("span",{className:"callout-font-sample",children:"A"}):null===e?/* @__PURE__ */D("span",{"aria-hidden":"true",children:"↺"}):null},e??"default"))})]},t.key)),
10
+ /* @__PURE__ */D(Z,{variant:"outline",block:!0,onClick:()=>o({textColor:null,borderColor:null,backgroundColor:null}),children:l("恢复默认颜色")})]})}),"icon"===i&&/* @__PURE__ */D(Q,{anchor:g,portal:n,label:l("高亮块图标"),onClose:()=>s("none"),align:"center",prefer:"below",gap:6,children:/* @__PURE__ */z("div",{className:"callout-icon-picker",role:"group","aria-label":l("高亮块图标"),children:[
11
+ /* @__PURE__ */D("div",{className:"callout-icon-grid",children:G.map(t=>/* @__PURE__ */D("button",{type:"button",className:"callout-icon-choice","aria-label":l("高亮块图标:{0}",{0:t}),"aria-pressed":h.icon===t,onClick:()=>{o({icon:t}),s("none")},children:t},t))}),
12
+ /* @__PURE__ */z("div",{className:"callout-icon-footer",children:[
13
+ /* @__PURE__ */D(Z,{size:"small",variant:"text",onClick:()=>{o({icon:""}),s("none")},children:l("隐藏图标")}),
14
+ /* @__PURE__ */D(Z,{size:"small",variant:"text",onClick:()=>{o({icon:null}),s("none")},children:l("默认图标")})]})]})})]})}const oe=rt.extend({addOptions(){var t;return{...null==(t=this.parent)?void 0:t.call(this),canCopy:void 0}},addAttributes(){var t;return{...null==(t=this.parent)?void 0:t.call(this),language:{default:null,parseHTML:t=>function parseLanguage(t){var e;const n=t.getAttribute("data-language");if(n)return n;const o=/(?:^|\s)language-([\w+#-]+)/.exec((null==(e=t.querySelector("code"))?void 0:e.className)||t.className);return o?o[1]:null}(t),renderHTML:t=>t.language?{"data-language":t.language}:{}}}},addNodeView(){return t=this.options.canCopy,e=this.options.contentContext,({node:n,editor:o,getPos:a,extension:r})=>{const l=document.createElement("div"),i=document.createElement("div");l.dataset.blockChrome="";const s=document.createElement("div"),c=document.createElement("div"),d=document.createElement("pre"),u=document.createElement("code");i.className="code-toolbar-host",i.contentEditable="false",s.className="code-scroll",s.setAttribute("aria-label","代码内容"),c.className="code-line-numbers",c.contentEditable="false",c.setAttribute("aria-hidden","true"),d.className="doc-code",d.append(u),s.append(c,d),l.append(i,s);let m=lt(),p=n,f=n.textContent,h=F(i);const paintClass=()=>{const t=["code-block-wrap",...st(m)];for(const e of["code-theme-auto","code-theme-paper","code-theme-soft","code-theme-night","is-collapsed","without-line-numbers","is-unlimited"])l.classList.toggle(e,t.includes(e));l.classList.add("code-block-wrap","ywiki-code-panel"),s.hidden=m.collapsed,c.hidden=!m.lineNumbers},chooseLanguage=t=>{if(!o.isEditable||o.isDestroyed)return;const e=a();if("number"!=typeof e)return;const r=o.state.doc.nodeAt(e);(null==r?void 0:r.type)===n.type&&o.view.dispatch(o.state.tr.setNodeMarkup(e,void 0,{...r.attrs,language:t||null}))},paintToolbar=()=>{const n=null==e?void 0:e(),a=/* @__PURE__ */D(nt,{text:p.textContent,language:String(p.attrs.language??""),editable:o.isEditable,canCopy:(null==t?void 0:t())??!1,display:m,onLanguage:chooseLanguage,onDisplay:t=>{m=t,paintClass(),paintToolbar()}});null==h||h.render(n?/* @__PURE__ */D(E,{value:n,children:a}):a)};c.textContent=it(f),paintClass(),paintToolbar();const syncMode=()=>paintToolbar();o.on("transaction",syncMode),o.on("update",syncMode);const revealSelection=()=>{if(!m.collapsed||!o.isFocused)return;const t=a();if("number"!=typeof t)return;const{from:e,to:n}=o.state.selection;e>t&&n<t+p.nodeSize&&(m={...m,collapsed:!1},paintClass(),paintToolbar())};return o.on("selectionUpdate",revealSelection),{dom:l,contentDOM:u,update:t=>"codeBlock"===t.type.name&&(p=t,t.textContent!==f&&(f=t.textContent,c.textContent=it(f)),paintToolbar(),!0),stopEvent:t=>i.contains(t.target)||c.contains(t.target),ignoreMutation:t=>"selection"!==t.type&&!u.contains(t.target),destroy(){o.off("selectionUpdate",revealSelection),o.off("transaction",syncMode),o.off("update",syncMode);const t=h;h=null,queueMicrotask(()=>null==t?void 0:t.unmount())}}};var t,e}}),ae=new pt("ywiki-ime"),re=ut.create({name:"ywikiImeGuard",addProseMirrorPlugins:()=>[new mt({key:ae,props:{handleDOMEvents:{compositionstart:()=>(yt(),!1),compositionend:()=>(bt(),!1)}}})],onDestroy(){vt()}}),mathNodeView=({node:t,editor:e,getPos:n})=>{var o;const a=y(e),r=a.text,l="mathBlock"===t.type.name,i=document.createElement(l?"div":"span");i.className=l?"doc-math-block math-node":"doc-math-inline math-node",i.setAttribute("data-math-node",l?"block":"inline"),l&&i.setAttribute("data-block-chrome","");const s=document.createElement("span");s.className="math-render",i.appendChild(s);let c=String((null==(o=t.attrs)?void 0:o.latex)??""),d=null,u=!1,m=!1,p=0;function paint(){const t=++p;s.replaceChildren(),i.classList.remove("doc-math-error","doc-math-pending"),i.removeAttribute("title"),c?(s.textContent=l?`$$${c}$$`:`$${c}$`,i.classList.add("doc-math-pending"),T(c,l).then(e=>{if(!m&&t===p)if(i.classList.remove("doc-math-pending"),e.html&&!e.error)!function setRenderedHtml(t,e){const n=document.createElement("template");n.innerHTML=e,t.replaceChildren(n.content)}(s,e.html);else{i.classList.add("doc-math-error"),i.title=e.error||r("公式渲染失败"),s.textContent=l?`$$${c}$$`:`$${c}$`;const t=document.createElement("span");t.className="doc-math-error-hint",t.textContent=r("(公式渲染失败)"),s.appendChild(t)}})):s.textContent=r("空公式")}function closeEdit(){if(u)return;u=!0;const t=d;d=null,null==t||t.remove(),i.classList.remove("is-editing"),s.style.display="",u=!1}function commit(){var o;if(u)return;if(!d||m||!e.isEditable)return void closeEdit();const a=d.value,r="function"==typeof n?n():void 0;closeEdit(),a!==c&&(c=a,"number"==typeof r&&(null==(o=e.state.doc.nodeAt(r))?void 0:o.type)===t.type?(e.view.dispatch(e.view.state.tr.setNodeMarkup(r,void 0,{...t.attrs,latex:a})),paint()):paint())}i.addEventListener("click",t=>{e.isEditable&&(t.preventDefault(),function beginEdit(){e.isEditable&&!d&&(d=document.createElement("input"),d.type="text",d.className="math-latex-input",d.value=c,d.spellcheck=!1,d.setAttribute("aria-label",r("编辑公式")),d.addEventListener("keydown",t=>{t.stopPropagation(),wt(t)||("Enter"===t.key?(t.preventDefault(),commit()):"Escape"===t.key&&(t.preventDefault(),closeEdit()))}),d.addEventListener("blur",()=>commit()),d.addEventListener("mousedown",t=>t.stopPropagation()),s.style.display="none",i.classList.add("is-editing"),i.appendChild(d),N(),setTimeout(()=>null==d?void 0:d.focus(),0))}())}),paint(),N();const f=a.subscribe(()=>{null==d||d.setAttribute("aria-label",r("编辑公式")),paint()});return{dom:i,update:e=>{var n;if(e.type.name!==t.type.name)return!1;t=e;const o=String((null==(n=e.attrs)?void 0:n.latex)??"");return o!==c&&(c=o,paint()),!0},stopEvent:t=>{var e;const n=t.target;return!!(null==(e=null==n?void 0:n.classList)?void 0:e.contains("math-latex-input"))},ignoreMutation:()=>!0,destroy:()=>{f(),m=!0,p+=1,closeEdit()}}},le=["left","center","right","justify"],ie=ut.create({name:"blockFormat",addOptions:()=>({types:["paragraph","heading"]}),addGlobalAttributes(){return[{types:this.options.types??["paragraph","heading"],attributes:{textAlign:{default:null,parseHTML:t=>{const e=t.getAttribute("data-text-align")??t.style.textAlign;return le.includes(e)?e:null},renderHTML:t=>{const e=t.textAlign;return e&&le.includes(e)?{"data-text-align":e,style:`text-align: ${e}`}:{}}},indent:{default:0,parseHTML:t=>{const e=t.getAttribute("data-indent"),n=Number(e);return Number.isFinite(n)&&n>0?Math.min(Math.floor(n),6):0},renderHTML:t=>{const e=Number(t.indent??0);return!Number.isFinite(e)||e<=0?{}:{"data-indent":String(Math.min(Math.floor(e),6)),style:`margin-left: ${24*Math.min(Math.floor(e),6)}px`}}}}}]},addCommands(){return{setTextAlign:t=>({tr:e,state:n,dispatch:o})=>{const a=this.options.types??["paragraph","heading"],{from:r,to:l}=n.selection;let i=!1;return n.doc.nodesBetween(r,l,(n,r)=>{a.includes(n.type.name)&&(o&&e.setNodeMarkup(r,void 0,{...n.attrs,textAlign:t}),i=!0)}),!!i&&(null==o||o(e),!0)},setIndent:t=>({tr:e,state:n,dispatch:o})=>{const a=this.options.types??["paragraph","heading"],r=Math.max(0,Math.min(Math.floor(t),6)),{from:l,to:i}=n.selection;let s=!1;return n.doc.nodesBetween(l,i,(t,n)=>{a.includes(t.type.name)&&Number(t.attrs.indent??0)!==r&&(o&&e.setNodeMarkup(n,void 0,{...t.attrs,indent:r}),s=!0)}),!!s&&(null==o||o(e),!0)},indentBlock:()=>({tr:t,state:e,dispatch:n})=>{const o=this.options.types??["paragraph","heading"],{from:a,to:r}=e.selection;let l=!1;return e.doc.nodesBetween(a,r,(e,a)=>{if(!o.includes(e.type.name))return;const r=Number(e.attrs.indent??0);r>=6||(n&&t.setNodeMarkup(a,void 0,{...e.attrs,indent:r+1}),l=!0)}),!!l&&(null==n||n(t),!0)},outdentBlock:()=>({tr:t,state:e,dispatch:n})=>{const o=this.options.types??["paragraph","heading"],{from:a,to:r}=e.selection;let l=!1;return e.doc.nodesBetween(a,r,(e,a)=>{if(!o.includes(e.type.name))return;const r=Number(e.attrs.indent??0);r<=0||(n&&t.setNodeMarkup(a,void 0,{...e.attrs,indent:r-1}),l=!0)}),!!l&&(null==n||n(t),!0)}}}}),se=new pt("ywikiBlockSelection");function blockSelectionBand(t){const e=t.dom;if(!e||"function"!=typeof e.getBoundingClientRect)return{left:0,right:0};const n=e.getBoundingClientRect(),o=blockSelectionBandRect(t);return{left:Math.min((null==o?void 0:o.left)??n.left,n.left-48),right:Math.max((null==o?void 0:o.right)??n.right,n.right+48)}}function blockSelectionBandRect(t){var e,n;const o=t.dom;if(!o||"function"!=typeof o.getBoundingClientRect)return null;const a=null==(e=o.closest)?void 0:e.call(o,"[data-block-select-band]"),r=(a instanceof HTMLElement?a:null)??(null==(n=o.closest)?void 0:n.call(o,".editor-shell"))??null;return(null==r?void 0:r.getBoundingClientRect())??null}function autoScrollDelta(t,e,n,o=60,a=16){if(!Number.isFinite(t)||n<=e)return 0;if(t<e+o){const n=Math.min(o,e+o-t);return-Math.ceil(n/o*a)}if(t>n-o){const e=Math.min(o,t-(n-o));return Math.ceil(e/o*a)}return 0}class BlockRangeSelection extends ft{constructor(t,e,n){super(t,e,(null==n?void 0:n.length)?function expandParts(t,e){const n=[];for(const o of e)if("block"!==o.kind)for(const e of o.images)n.push(new gt(t.resolve(e.from),t.resolve(e.to)));else n.push(new gt(t.resolve(o.from),t.resolve(o.to)));return n}(t.doc,n):void 0),__publicField(this,"parts"),__publicField(this,"visible",!1),this.parts=n}content(){const t=this.parts;if(!(null==t?void 0:t.length))return this.$from.doc.slice(this.from,this.to);const e=this.$from.doc,n=[];for(const o of t){if("block"===o.kind){const t=e.nodeAt(o.from);t&&n.push(t);continue}const t=e.nodeAt(o.from);if(!t)continue;const a=[];t.forEach((t,e)=>{const n=o.from+1+e;o.images.some(t=>n>=t.from&&n<t.to)&&a.push(t)}),a.length>=2?n.push(t.type.create(t.attrs,A.fromArray(a))):1===a.length&&n.push(a[0])}return new L(A.fromArray(n),0,0)}replace(t,e=L.empty){var n;if(!(null==(n=this.parts)?void 0:n.length)||e.size>0)return void super.replace(t,e);const o=[...this.parts].sort((t,e)=>e.from-t.from);let a=null;for(const e of o){if("block"===e.kind){t.delete(e.from,e.to),a=e.from;continue}const n=t.doc.nodeAt(e.from);if(!n)continue;const o=[];n.forEach((t,n)=>{const a=e.from+1+n;e.images.some(t=>a>=t.from&&a<t.to)||o.push(t)}),o.length>=2?t.replaceWith(e.from,e.to,n.type.create(n.attrs,A.fromArray(o))):1===o.length?t.replaceWith(e.from,e.to,o[0]):t.delete(e.from,e.to),a=e.from}if(null!==a){const e=Math.max(0,Math.min(a,t.doc.content.size));t.setSelection(ft.near(t.doc.resolve(e),1))}}eq(t){return"ywikiBlockRange"===t.toJSON().type&&t.from===this.from&&t.to===this.to&&JSON.stringify(t.parts??null)===JSON.stringify(this.parts??null)}map(t,e){return ft.near(t.resolve(e.map(this.from,1)))}toJSON(){return{type:"ywikiBlockRange",from:this.from,to:this.to,parts:this.parts}}static fromJSON(t,e){return new BlockRangeSelection(t.resolve(e.from),t.resolve(e.to),e.parts)}getBookmark(){return ft.near(this.$from).getBookmark()}}try{ft.jsonID("ywikiBlockRange",BlockRangeSelection)}catch(t){if(!(t instanceof RangeError)||"Duplicate use of selection JSON ID ywikiBlockRange"!==t.message)throw t}function blockAtY(t,e){const n=[];if(t.state.doc.forEach((e,o)=>{const a=t.nodeDOM(o);if(!(a instanceof HTMLElement))return;const r=a.getBoundingClientRect();n.push({pos:o,node:e,top:r.top,bottom:r.bottom})}),0===n.length)return null;for(const t of n)if(e>=t.top&&e<=t.bottom)return{pos:t.pos,node:t.node};let o=n[0],a=Number.POSITIVE_INFINITY;for(const t of n){const n=e<t.top?t.top-e:e-t.bottom;n<a&&(a=n,o=t)}return a>48?null:{pos:o.pos,node:o.node}}function coveredBlocks(t,e,n){const o=Math.min(e,n),a=Math.max(e,n),r=[];return t.forEach((t,e)=>{const n=e+t.nodeSize;n>o&&e<=a&&r.push({from:e,to:n})}),r}function rectsIntersect(t,e){return t.right>e.left&&t.left<e.right&&t.bottom>e.top&&t.top<e.bottom}function marqueeImageRanges(t,e,n,o){const a=[];let r=0;for(let l=0;l<e.length;l+=1){const i=t+1+r;r+=e[l];const s=n[l];s&&rectsIntersect(o,s)&&a.push({from:i,to:i+e[l]})}return a}function measureBlocksPadding(t,e){if(0===e.length)return[];if("function"!=typeof t.nodeDOM)return[];const n=[];for(const o of e){const e=t.nodeDOM(o.from);if(!(e instanceof HTMLElement))return[];const a=e.getBoundingClientRect();n.push({top:a.top,bottom:a.bottom})}return function selectionPadding(t){if(0===t.length)return[];let e=Number.POSITIVE_INFINITY;for(let n=1;n<t.length;n+=1){const o=t[n].top-t[n-1].bottom;o>0&&(e=Math.min(e,o))}const n=Number.isFinite(e)?Math.max(0,(e-6)/2):5,o=Math.max(0,Math.min(5,n));return t.map(()=>({top:o,bottom:o}))}(n)}function setBlockRangeSelection(t,e,n,o){const{doc:a}=t.state,r=o?function selectionPartsForRange(t,e,n,o,a){const r=[];for(const l of coveredBlocks(e,n,o)){const n=e.nodeAt(l.from);if("imageGallery"===(null==n?void 0:n.type.name)){const e="function"==typeof t.nodeDOM?t.nodeDOM(l.from):null;if(e instanceof HTMLElement){const o=e.getBoundingClientRect();if(rectsIntersect(a,{left:o.left,top:o.top,right:o.right,bottom:o.bottom})){const e=[];n.forEach(t=>e.push(t.nodeSize));const o=[];let i=0;n.forEach(e=>{const n=l.from+1+i;i+=e.nodeSize;const a="function"==typeof t.nodeDOM?t.nodeDOM(n):null;if(!(a instanceof HTMLElement))return void o.push(null);const r=a.getBoundingClientRect();o.push({left:r.left,top:r.top,right:r.right,bottom:r.bottom})});const s=marqueeImageRanges(l.from,e,o,a);if(0===s.length)continue;s.length===e.length?r.push({kind:"block",...l}):r.push({kind:"images",...l,images:s});continue}}}r.push({kind:"block",...l})}return r}(t,a,e,n,o):coveredBlocks(a,e,n).map(t=>({kind:"block",...t}));if(0===r.length)return function clearBlockRangeSelection(t){const e=t.state.tr.setMeta(se,{blocks:[]});t.dispatch(e)}(t),!1;const l=r[0],i=r[r.length-1],s=new BlockRangeSelection(a.resolve(l.from),a.resolve(i.to),r),c=t.state.tr.setSelection(s),d=measureBlocksPadding(t,r.filter(t=>"block"===t.kind));let u=0;return c.setMeta(se,{blocks:r.map(t=>{if("images"===t.kind)return{from:t.from,to:t.to,images:t.images};const e=d[u];return u+=1,{from:t.from,to:t.to,padding:e}})}),t.dispatch(c),!0}function setImageRangeSelection(t,e,n){const{doc:o}=t.state,a=o.nodeAt(e);if(!a||"imageGallery"!==a.type.name||0===n.length)return!1;const r=n.length===a.childCount?[{kind:"block",from:e,to:e+a.nodeSize}]:[{kind:"images",from:e,to:e+a.nodeSize,images:n}],l=r[0],i=r[r.length-1],s=new BlockRangeSelection(o.resolve(l.from),o.resolve(i.to),r),c=t.state.tr.setSelection(s),d=measureBlocksPadding(t,r.filter(t=>"block"===t.kind));return c.setMeta(se,{blocks:r.map(t=>"images"===t.kind?{from:t.from,to:t.to,images:t.images}:{from:t.from,to:t.to,padding:d[0]})}),t.dispatch(c),!0}function getSelectedBlocks(t){var e;return(null==(e=se.getState(t.state))?void 0:e.blocks)??[]}function hasPartialImageSelection(t){var e;const n=t.state.selection;return n instanceof BlockRangeSelection&&!!(null==(e=n.parts)?void 0:e.some(t=>"images"===t.kind))}function replacePartialWithText(t,e){if(!hasPartialImageSelection(t))return!1;const n=t.state.selection,o=t.state.tr;n.replace(o);const a=t.state.schema,r=o.selection.from;if(o.selection.$from.parent.inlineContent)e&&o.insertText(e,r),o.setSelection(ht.create(o.doc,r+e.length));else{if(!a.nodes.paragraph)return!1;o.insert(r,a.nodes.paragraph.create(null,e?a.text(e):void 0)),o.setSelection(ht.create(o.doc,r+1+e.length))}return o.setMeta(se,{blocks:[]}),t.dispatch(o.scrollIntoView()),!0}const ce=ut.create({name:"ywikiBlockSelection",priority:1e3,addKeyboardShortcuts(){const remove=()=>{var t;const e=this.editor.view,n=e.state.selection;if(!(n instanceof BlockRangeSelection&&(null==(t=n.parts)?void 0:t.length)))return!1;const o=e.state.tr;return n.replace(o),!!o.docChanged&&(o.setMeta(se,{blocks:[]}),e.dispatch(o.scrollIntoView()),!0)};return{Backspace:remove,Delete:remove,"Mod-Backspace":remove,"Mod-Delete":remove,"Shift-Backspace":remove,"Ctrl-h":remove,"Ctrl-d":remove,"Alt-Backspace":remove,"Alt-Delete":remove,"Ctrl-Alt-Backspace":remove,"Alt-d":remove}},addProseMirrorPlugins:()=>[new mt({key:se,state:{init:()=>({blocks:[]}),apply:(t,e)=>t.getMeta(se)||(t.selectionSet||t.docChanged?{blocks:[]}:e)},props:{handleTextInput:(t,e,n,o)=>replacePartialWithText(t,o),handleDOMEvents:{beforeinput(t,e){const n=e;return"insertText"===n.inputType&&null!==n.data&&!!hasPartialImageSelection(t)&&(n.preventDefault(),replacePartialWithText(t,n.data),!0)},compositionstart:t=>!!hasPartialImageSelection(t)&&(replacePartialWithText(t,""),!1)},decorations(t){var e;const n=se.getState(t);if(!n||0===n.blocks.length)return null;const o=[];for(const t of n.blocks)if(null==(e=t.images)?void 0:e.length){o.push(kt.node(t.from,t.to,{class:"is-block-image-selected"}));for(const e of t.images)o.push(kt.node(e.from,e.to,{class:"is-block-selected-image"}))}else o.push(kt.node(t.from,t.to,{class:"is-block-selected",style:t.padding?`--block-select-pad-top:${t.padding.top}px;--block-select-pad-bottom:${t.padding.bottom}px`:""}));return Mt.create(t.doc,o)}},view:t=>{let e=null;const applyBlockSelection=n=>{null!==e&&setBlockRangeSelection(t,e,n,marqueeRect(s,c))};let n=!1,o=0,a=0;const r=t.dom.closest(".editor-shell")??t.dom.parentElement;let l=null;const updateMarquee=(e,n)=>{if(!r)return;l||(l=document.createElement("div"),l.className="block-marquee",r.appendChild(l));const i=r.getBoundingClientRect(),s=blockSelectionBand(t),c=blockSelectionBandRect(t)??i,d=function clampMarqueeBand(t,e,n,o,a=Number.POSITIVE_INFINITY){const r=Math.max(t,n),l=Math.min(e,o,a);return l>r?{left:r,right:l}:{left:n,right:Math.max(n,Math.min(o,a))}}(s.left,s.right,c.left,c.right,"undefined"!=typeof document?document.documentElement.clientWidth:void 0),clampX=t=>Math.max(d.left,Math.min(t,d.right)),clampY=t=>Math.max(i.top,Math.min(t,i.bottom)),u=function marqueeBox(t,e,n,o,a,r){return{left:Math.min(t,n)-a,top:Math.min(e,o)-r,width:Math.abs(n-t),height:Math.abs(o-e)}}(clampX(o),clampY(a),clampX(e),clampY(n),i.left,i.top);l.style.left=`${u.left}px`,l.style.top=`${u.top}px`,l.style.width=`${u.width}px`,l.style.height=`${u.height}px`},clearMarquee=()=>{null==l||l.remove(),l=null},marqueeRect=(t,e)=>({left:Math.min(o,t),top:Math.min(a,e),right:Math.max(o,t),bottom:Math.max(a,e)});let i=0,s=0,c=0,d=null,u=0;const stopAutoScroll=()=>{i&&cancelAnimationFrame(i),i=0,d=null,u=0},tickAutoScroll=(o=performance.now())=>{if(i=0,null===e||!n)return;const a=d;if(!a)return;const r=u?Math.min(o-u,50):16.7;u=o;const l=a.getBoundingClientRect(),m=autoScrollDelta(c,l.top,l.bottom);if(0===m)return void(u=0);const p=Math.round(m*r/16.7),f=a.scrollTop;if(a.scrollTop=f+(0===p?Math.sign(m):p),a.scrollTop===f)return;const h=blockAtY(t,c);h&&applyBlockSelection(h.pos),updateMarquee(s,c),i=requestAnimationFrame(tickAutoScroll)},onMouseMove=r=>{if(null===e)return;if(!n&&!function isBlockSelectGesture(t,e){return Math.max(Math.abs(t),Math.abs(e))>=8}(r.clientX-o,r.clientY-a))return;s=r.clientX,c=r.clientY,n||(n=!0,applyBlockSelection(e)),d??(d=function scrollParentOf(t){let e=(null==t?void 0:t.parentElement)??null;for(;e;){const t="function"==typeof getComputedStyle?getComputedStyle(e):null;if(/(auto|scroll)/.test((null==t?void 0:t.overflowY)??""))return e;e=e.parentElement}return null}(t.dom)),updateMarquee(r.clientX,r.clientY);const l=blockAtY(t,r.clientY);if(l&&applyBlockSelection(l.pos),d){const t=d.getBoundingClientRect();0!==autoScrollDelta(r.clientY,t.top,t.bottom)&&(i||(i=requestAnimationFrame(tickAutoScroll)))}r.preventDefault()},finish=o=>{const a="mouseup"===(null==o?void 0:o.type)&&!n&&null!==e,r=e;if(e=null,n=!1,stopAutoScroll(),clearMarquee(),window.removeEventListener("mousemove",onMouseMove),window.removeEventListener("mouseup",finish,!0),window.removeEventListener("blur",finish),window.removeEventListener("pointercancel",finish),window.removeEventListener("keydown",onKeydown,!0),a&&null!==r){const e=function gutterClickCaretPos(t,e){if(!Number.isInteger(e)||e<0||e>=t.content.size)return null;const n=t.nodeAt(e);return n?n.isTextblock?Math.min(e+1,t.content.size):e:null}(t.state.doc,r);if(null!==e){const n=t.state.tr.setSelection(ht.near(t.state.doc.resolve(e),1));n.setMeta(se,{blocks:[]}),t.dispatch(n),t.focus()}}},onKeydown=e=>{"Escape"!==e.key||e.isComposing||(e.preventDefault(),finish(),t.isDestroyed||t.dispatch(t.state.tr.setSelection(ft.near(t.state.doc.resolve(t.state.selection.from)))))},onMouseDown=l=>{var i,s;if(0!==l.button||!t.editable||t.composing)return;const c=l.target,d=t.dom.closest(".edit-workspace")??r;if(!c||!d||!d.contains(c)&&!c.contains(d))return;if(null==(i=null==c?void 0:c.closest)?void 0:i.call(c,'button, input, textarea, select, a, img, video, audio, [contenteditable="false"], .math-node, .code-lang-menu, .block-grip, .block-plus, .block-chip, .insert-picker, .tbl-handle, .sel-toolbar, .tbl-menu, .tbl-ctx, .block-anchor, .slash-anchor'))return;if(null==(s=null==c?void 0:c.closest)?void 0:s.call(c,"table"))return;if(c.closest(".is-block-selected")&&t.dom.contains(c))return;const u=function gutterAreaHit(t,e){const n=t.dom.getBoundingClientRect();return e.clientY<n.top||e.clientY>n.bottom?null:function bandSide(t,e,n,o){return t>=e&&t<=n?null:t<e?t>=o.left?"left":null:t<=o.right?"right":null}(e.clientX,n.left,n.right,blockSelectionBand(t))?blockAtY(t,e.clientY):null}(t,l);u&&(l.preventDefault(),l.stopPropagation(),t.focus(),e=u.pos,o=l.clientX,a=l.clientY,n=!1,window.addEventListener("mousemove",onMouseMove),window.addEventListener("mouseup",finish,!0),window.addEventListener("blur",finish),window.addEventListener("pointercancel",finish),window.addEventListener("keydown",onKeydown,!0))};document.addEventListener("mousedown",onMouseDown,!0);const onGlobalKeydown=e=>{if("Escape"!==e.key||e.isComposing)return;if(!getSelectedBlocks(t).length)return;e.preventDefault(),e.stopPropagation();const{state:n}=t,o=n.tr.setSelection(ft.near(n.doc.resolve(n.selection.from)));o.setMeta(se,{blocks:[]}),t.dispatch(o),t.focus()};window.addEventListener("keydown",onGlobalKeydown,!0);const syncNativeHighlight=t=>{const e=se.getState(t.state);t.dom.classList.toggle("is-block-selecting",function shouldSuppressNativeHighlight(t){return((null==t?void 0:t.length)??0)>0}(null==e?void 0:e.blocks))};return syncNativeHighlight(t),{update:(t,n)=>{null===e||t.state.doc.eq(n.doc)||finish(),syncNativeHighlight(t)},destroy:()=>{document.removeEventListener("mousedown",onMouseDown,!0),window.removeEventListener("keydown",onGlobalKeydown,!0),stopAutoScroll(),clearMarquee(),t.dom.classList.remove("is-block-selecting"),finish()}}}})]}),de=new pt("ywikiBlockMenuHighlight"),ue=ut.create({name:"ywikiBlockMenuHighlight",addProseMirrorPlugins:()=>[new mt({key:de,state:{init:()=>null,apply(t,e){const n=t.getMeta(de);if(void 0!==n)return n;if(null===e||!t.docChanged)return e;const o=t.mapping.mapResult(e);return o.deleted?null:o.pos}},props:{decorations(t){const e=de.getState(t);if(null==e)return null;const n=t.doc.nodeAt(e);return n?Mt.create(t.doc,[kt.node(e,e+n.nodeSize,{class:"is-block-menu-target"})]):null}}})]});function highlightMenuBlock(t,e){t.isDestroyed||de.getState(t.state)===e||t.dispatch(t.state.tr.setMeta(de,e))}const me=new pt("ywikiCodeHighlight");function decorate(t){const e=[];return t.descendants((t,n)=>{if("codeBlock"===t.type.name){for(const o of Et(t.textContent,t.attrs.language))e.push(kt.inline(n+1+o.from,n+1+o.to,{class:o.classes}));return!1}}),Mt.create(t,e)}const pe=ut.create({name:"ywikiCodeHighlight",addProseMirrorPlugins:()=>[new mt({key:me,state:{init:(t,e)=>decorate(e.doc),apply:(t,e)=>t.docChanged||t.getMeta(me)?decorate(t.doc):e},props:{decorations:t=>me.getState(t)},view(t){let e=!1,n=!1;const load=()=>{if(n)return;let o=!1;t.state.doc.descendants(t=>{"codeBlock"===t.type.name&&(o=!0)}),o&&(n=!0,xt().then(n=>{n&&!e&&t.dispatch(t.state.tr.setMeta(me,!0).setMeta("addToHistory",!1))}))};return load(),{update:load,destroy:()=>{e=!0}}}})]}),fe={a:["href","title"],img:["src","alt","title","width","height","data-width","data-align","data-attachment-id"],td:["colspan","rowspan","colwidth","data-align","data-cell-background"],th:["colspan","rowspan","colwidth","data-align","data-cell-background"],code:["class"],pre:["class","data-language"],ol:["start","data-type"],ul:["data-type"],li:["data-type","data-checked"],div:["data-video-embed","data-provider","data-video-id","data-page","data-start-seconds","data-auto-load","data-topic-meta","data-branch-style","data-mind-map","data-map-id","data-root-id","data-format-version","data-layout","data-theme","data-height","data-mind-topic","data-topic-id","data-parent-id","data-order","data-file-attachment","data-attachment-id","attachmentid","filename","mimetype","size","data-math-block","data-latex","data-columns","data-column","data-callout","data-tone","data-callout-content","data-callout-icon","data-callout-textcolor","data-callout-bordercolor","data-callout-backgroundcolor"],span:["data-mind-description","data-mind-note","data-mind-relation","data-id","data-source","data-target","data-kind","data-label","data-page-link","data-page-id","pageid","label","data-mention","data-user-id","userid","data-math-inline","data-latex","data-text-color","data-color"],mark:["data-highlight","data-color"],p:["data-indent","data-text-align"],h1:["data-indent","data-text-align"],h2:["data-indent","data-text-align"],h3:["data-indent","data-text-align"],h4:["data-indent","data-text-align"],h5:["data-indent","data-text-align"],h6:["data-indent","data-text-align"]},he=/* @__PURE__ */new Set(["style","script","meta","link","iframe","object","embed","form","input","button"]);function sanitizeElement(t){for(const e of Array.from(t.children)){if(e.hasAttribute("data-callout-decoration")){e.remove();continue}if(he.has(e.tagName.toLowerCase())){e.remove();continue}e.removeAttribute("style");const t=/(?:^|\s)(language-[\w+#-]+)/.exec(e.className);e.removeAttribute("class"),["code","pre"].includes(e.tagName.toLowerCase())&&t&&e.setAttribute("class",t[1]),e.removeAttribute("id");for(const t of Array.from(e.attributes)){const n=t.name.toLowerCase();if(n.startsWith("on")){e.removeAttribute(t.name);continue}const o=fe[e.tagName.toLowerCase()];o&&o.includes(n)||e.removeAttribute(t.name)}if("a"===e.tagName.toLowerCase()){const t=(e.getAttribute("href")??"").trim().toLowerCase();(t.startsWith("javascript:")||t.startsWith("data:")||t.startsWith("vbscript:"))&&e.removeAttribute("href")}sanitizeElement(e)}}const ge=ut.create({name:"ywikiPasteSanitizer",addProseMirrorPlugins:()=>[new mt({props:{transformPastedHTML(t){const e=document.createElement("div");return e.innerHTML=t,sanitizeElement(e),e.innerHTML}}})]});function pastedImageFiles(t){var e;const n=null==(e=t.clipboardData)?void 0:e.items;if(!n)return[];const o=[];for(const t of Array.from(n))if("file"===t.kind&&t.type.startsWith("image/")){const e=t.getAsFile();e&&o.push(e)}return o}function pastedRemoteImageUrls(t){var e;const n=(null==(e=t.clipboardData)?void 0:e.getData("text/html"))??"";if(!n)return[];const o=document.createElement("div");o.innerHTML=n;const a=/* @__PURE__ */new Set;for(const t of Array.from(o.querySelectorAll("img"))){const e=(t.getAttribute("src")??"").trim();/^https?:\/\//i.test(e)&&a.add(e)}return[...a]}const ve=new pt("ywikiInlineComments"),be=ut.create({name:"ywikiInlineCommentHighlight",addProseMirrorPlugins(){const t=this.options;return[new mt({key:ve,state:{init:()=>({comments:t.getComments()}),apply:(t,e)=>t.getMeta(ve)??e},props:{decorations(e){var n;const o=ve.getState(e);return o&&0!==o.comments.length?function buildDecorations(t,e,n){const{marks:o}=Ct(t.toJSON(),e);if(0===o.length)return Mt.empty;const a=function textNodePositions(t){const e=[];return t.descendants((t,n)=>{var o;t.isText&&((null==(o=t.text)?void 0:o.length)??0)>0&&e.push(n)}),e}(t),r=[];for(const t of o){const e=a[t.textIndex];if(void 0===e)continue;const o=e+t.from,l=e+t.to;if(l<=o){r.push(kt.widget(o,()=>{const e=document.createElement("span");return e.className="doc-inline-comment is-editor is-shifted",e.setAttribute("data-comment-id",t.commentId),e.setAttribute("data-comment-hint","此处有讨论(原文已改动)"),e}));continue}const i=["doc-inline-comment","is-editor"];t.hasReplies&&i.push("has-replies"),n===t.commentId&&i.push("is-active"),r.push(kt.inline(o,l,{class:i.join(" "),"data-comment-id":t.commentId,"data-comment-hint":"点击查看该处讨论"}))}return Mt.create(t,r)}(e.doc,o.comments,(null==(n=t.getActiveId)?void 0:n.call(t))??null):null},handleClick(e,n,o){var a;const r=o.target,l=null==r?void 0:r.closest("[data-comment-id]"),i=null==l?void 0:l.getAttribute("data-comment-id");return!!i&&(at(),null==(a=t.onMarkClick)||a.call(t,i),!0)},handleDOMEvents:{mouseover(t,e){const n=e.target,o=null==n?void 0:n.closest("[data-comment-hint]");if(!(o instanceof HTMLElement))return!1;const a=o.getAttribute("data-comment-hint");return a&&ot(o,a),!1},mouseout(t,e){const n=e,o=n.target,a=null==o?void 0:o.closest("[data-comment-hint]");if(!a)return!1;const r=n.relatedTarget;return r&&a.contains(r)||at(),!1}}}})]}});function refreshInlineComments(t,e){const n=t.state.tr.setMeta(ve,{comments:e});t.view.dispatch(n)}new pt("ywiki-collab-cursor");const ye=ut.create({name:"collabCursor",addOptions:()=>({awareness:null}),addProseMirrorPlugins(){return this.options.awareness?[_(this.options.awareness,{cursorBuilder:t=>function buildCursor(t){const e=t.color||"#2f6feb",n=t.name||"匿名",o=document.createElement("span");o.classList.add("ProseMirror-yjs-cursor"),o.style.setProperty("--yjs-cursor-color",e);const a=document.createElement("span");a.classList.add("ywiki-collab-caret"),a.style.backgroundColor=e;const r=document.createElement("span");return r.classList.add("ywiki-collab-caret-label"),r.style.backgroundColor=e,r.style.color=At(e),r.textContent=n,o.appendChild(a),o.appendChild(r),o}(t)})]:[]}}),we=new pt("ywiki-slash");function dismissSlash(t){const{$from:e}=t.state.selection,n=e.parent.textBetween(0,e.parentOffset).lastIndexOf("/");t.dispatch(t.state.tr.setMeta(we,{dismissedFrom:n>=0?e.start()+n:null}))}const ke=ut.create({name:"ywikiSlashCommand",addOptions:()=>({onOpen:()=>{},onUpdate:()=>{},onClose:()=>{}}),addProseMirrorPlugins(){const t=this.options;return[new mt({key:we,state:{init:()=>({dismissedFrom:null}),apply:(t,e)=>{const n=t.getMeta(we);if(n)return n;if(null===e.dismissedFrom)return e;const o=t.mapping.mapResult(e.dismissedFrom,1);return{dismissedFrom:o.deleted?null:o.pos}}},view:()=>{let e=null;return{update:(n,o)=>{var a;if(wt({isComposing:!1}))return;if(n.state.doc.eq(o.doc)&&n.state.selection.eq(o.selection)&&we.getState(n.state)===we.getState(o))return;const{$from:r,empty:l}=n.state.selection;if(!n.editable||n.composing||!l||r.parent.type.spec.code)return void(null!==e&&(e=null,t.onClose()));const i=r.parent.textBetween(0,r.parentOffset,void 0,""),s=i.lastIndexOf("/");if(s>=0&&(0===s||/\s/.test(i[s-1]))){const o=r.start()+s,l=i.slice(s+1);if((null==(a=we.getState(n.state))?void 0:a.dismissedFrom)===o)return null!==e&&t.onClose(),void(e=null);if(/\s/.test(l))return void(null!==e&&(e=null,t.onClose()));e!==o?(e=o,t.onOpen({from:o,query:l})):t.onUpdate(l)}else null!==e&&(e=null,t.onClose())},destroy:()=>{null!==e&&(e=null,t.onClose())}}},props:{handleKeyDown:(t,e)=>(wt(e),!1)}})]}}),Me=new pt("ywiki-block-handle"),xe=ut.create({name:"ywikiBlockHandle",addOptions:()=>({onHover:()=>{}}),addProseMirrorPlugins(){const t=this.options;return[new mt({key:Me,view:e=>{let n=null,o=Number.NaN;const a=e.dom.closest(".editor-shell")??e.dom.parentElement,report=e=>{e?(e.pos!==n||Math.abs(e.top-o)>.5)&&(n=e.pos,o=e.top,t.onHover(e)):null!==n&&(n=null,o=Number.NaN,t.onHover(null))},onMove=t=>{if(!e.editable)return void report(null);if(!a)return;const n=e.dom.getBoundingClientRect(),o=t.clientX>=n.left&&t.clientX<=n.right,r=t.clientX<n.left&&t.clientX>=n.left-64,l=t.clientY>=n.top-8&&t.clientY<=n.bottom+8;if(!o&&!r||!l)return void report(null);let i=null;try{i=function resolveTopLevelBlock(t,e,n){const o=t.dom;let a=null,r=null,l=null,i=e.target instanceof HTMLElement?e.target:null;for(;i&&i.parentElement&&i.parentElement!==o;)i=i.parentElement;if(i&&i.parentElement===o)try{const e=t.posAtDOM(i,0),n=t.state.doc.resolve(e),o=n.depth>0?n.before(1):e,s=t.state.doc.nodeAt(o);s&&(a=o,r=s,l=i)}catch{}if(null===a||!r){const n=t.posAtCoords({left:e.clientX,top:e.clientY});if(!n)return null;const o=n.pos;if("number"!=typeof o||o<0)return null;const l=Math.min(o,t.state.doc.content.size);if(t.state.doc.forEach((t,e)=>{null===a&&l>=e&&l<e+t.nodeSize&&(a=e,r=t)}),null===a&&t.state.doc.childCount>0){const e=t.state.doc.lastChild;a=t.state.doc.content.size-e.nodeSize,r=e}if(null===a||!r)return null}const s=n.getBoundingClientRect();let c=e.clientY,d=o.getBoundingClientRect().left-s.left;try{const e=l??t.nodeDOM(a);if(e instanceof HTMLElement){const t=e.getBoundingClientRect();let n=t.top,o=t.height;try{const t=document.createRange();t.selectNodeContents(e);const a=Array.from(t.getClientRects()).filter(t=>t.height>.5);a.length>0&&(n=a[0].top,o=a[0].height)}catch{}c=n+o/2-13-s.top}}catch{c=e.clientY-s.top}return{pos:a,type:r.type.name,top:c,contentLeft:d,isEmpty:(u=r.type.name,m=r.content.size,0===m&&("paragraph"===u||"heading"===u))};var u,m}(e,t,a)}catch{i=null}r&&!i||report(i)},onLeave=()=>{report(null)};return document.addEventListener("mousemove",onMove),document.addEventListener("mouseleave",onLeave),{destroy:()=>{document.removeEventListener("mousemove",onMove),document.removeEventListener("mouseleave",onLeave)}}}})]}});function insertUploadedBlock(t,e,n){const o=t.doc.resolve(e);if(n.isBlock&&o.depth>0&&"paragraph"===o.parent.type.name&&0===o.parent.content.size){const e=o.before(),a=o.after();return t.replaceWith(e,a,n),{replacedEmpty:!0,nextPos:e+n.nodeSize}}return t.insert(e,n),{replacedEmpty:!1,nextPos:t.mapping.map(e,1)}}const Ee=new pt("ywikiUploadPlaceholder");function anchorAt(t,e){const n=Math.max(0,Math.min(e,t.content.size));let o=-1,a=0;if(t.forEach((t,e,r)=>{o>=0||n>=e&&n<e+t.nodeSize&&(o=r,a=e)}),o<0&&t.childCount>0&&(o=t.childCount-1,a=t.content.size-t.child(t.childCount-1).nodeSize),o<0)return{pos:n,blockIndex:0,offset:0,blockText:"",blockCount:t.childCount,blockJSON:"",relative:0};const r=t.child(o);return{pos:n,blockIndex:o,offset:Math.max(0,n-(a+1)),blockText:r.textContent,blockCount:t.childCount,blockJSON:JSON.stringify(r.toJSON()),relative:n-a}}function resolveAnchor(t,e){if(0===t.childCount)return null;const n=[];if(t.forEach((t,o,a)=>{JSON.stringify(t.toJSON())===e.blockJSON&&n.push(a)}),1!==n.length)return null;const o=function blockStartAt(t,e){let n=0;for(let o=0;o<e&&o<t.childCount;o+=1)n+=t.child(o).nodeSize;return n}(t,n[0]),a=t.child(n[0]);return o+Math.max(0,Math.min(e.relative,a.nodeSize))}const Ce=/* @__PURE__ */new Set;function releasePreview(t){t&&Ce.delete(t)&&"function"==typeof URL.revokeObjectURL&&URL.revokeObjectURL(t)}const Ae=ut.create({name:"ywikiUploadPlaceholder",addOptions:()=>({onLost:()=>{},onCancel:()=>{}}),addProseMirrorPlugins(){const t=this.options,e=this.editor;return[new mt({key:Ee,state:{init:()=>({items:[]}),apply:(e,n)=>{var o;const a=e.getMeta(Ee);if(null==a?void 0:a.clear){for(const t of n.items)releasePreview(t.previewUrl);return{items:[]}}const r=/* @__PURE__ */new Set([...(null==a?void 0:a.remove)?[a.remove]:[],...(null==a?void 0:a.removeMany)??[]]),l=0===r.size?n.items:n.items.filter(t=>!r.has(t.id));if(r.size>0)for(const t of n.items)r.has(t.id)&&releasePreview(t.previewUrl);const i=(null==a?void 0:a.reanchor)?l.filter(t=>t.anchor.pos===a.reanchor.from).map(t=>({...t,anchor:anchorAt(e.doc,a.reanchor.to)})):[],s=l.filter(t=>!(null==a?void 0:a.reanchor)||t.anchor.pos!==a.reanchor.from),c=e.docChanged?function advancePlaceholders(t,e,n,o=!1){const a=[],r=[];for(const l of e){const e=n.mapResult(l.anchor.pos,1);if(!e.deleted){a.push({...l,anchor:anchorAt(t,e.pos)});continue}const i=o?resolveAnchor(t,l.anchor):null;null!==i?a.push({...l,anchor:anchorAt(t,i)}):r.push(l.id)}return{items:a,lost:r}}(e.doc,s,e.mapping,!!e.getMeta("y-sync$")):{items:s,lost:[]};c.items.push(...i);for(const e of c.lost){const a=n.items.find(t=>t.id===e);releasePreview(null==a?void 0:a.previewUrl),null==(o=t.onLost)||o.call(t,e)}return a&&a.add?{items:[...c.items,a.add]}:{items:c.items}}},view:()=>({destroy:()=>function releaseAllPreviews(){for(const t of[...Ce])releasePreview(t)}()}),props:{decorations(n){const o=Ee.getState(n);return o&&0!==o.items.length?Mt.create(n.doc,o.items.map(n=>{const o=y(e),a=kt.widget(n.anchor.pos,()=>function placeholderDom(t,e,n){const o=document.createElement("span");o.className="ywiki-upload-placeholder",o.setAttribute("data-upload-id",t.id);const a=document.createElement("span");a.className="ywiki-upload-spinner",a.setAttribute("aria-hidden","true");const r=document.createElement("span");r.className="ywiki-upload-label",r.textContent=n.t("image"===t.kind?"upload.image":"upload.file",{0:t.label});const l=document.createElement("button");if(l.type="button",l.className="ywiki-upload-cancel",l.title=n.t("upload.cancel"),l.setAttribute("aria-label",n.t("upload.cancel")),l.textContent="×",l.addEventListener("mousedown",t=>{t.preventDefault(),t.stopPropagation()}),l.addEventListener("click",n=>{var o;n.preventDefault(),n.stopPropagation(),null==(o=e.onCancel)||o.call(e,t.id)}),t.previewUrl){o.classList.add("has-preview");const e=document.createElement("img");return e.className="ywiki-upload-preview",e.setAttribute("alt",""),e.setAttribute("aria-hidden","true"),e.setAttribute("draggable","false"),e.src=t.previewUrl,o.title=t.label,o.append(e,a,l),o}return o.append(a,r,l),o}(n,t,o),{key:`${n.id}:${o.version}`,side:1});return a})):null}}})]}});function addUploadPlaceholder(t,e){const n=anchorAt(t.state.doc,e.pos),o=function createPreview(t,e){if(t&&"image"===e&&"function"==typeof URL.createObjectURL)try{const e=URL.createObjectURL(t);return Ce.add(e),e}catch{return}}(e.file,e.kind);t.dispatch(t.state.tr.setMeta(Ee,{add:{id:e.id,label:e.label,kind:e.kind,anchor:n,...o?{previewUrl:o}:{}}}))}function removeUploadPlaceholder(t,e){const n=Ee.getState(t.state);(null==n?void 0:n.items.some(t=>t.id===e))&&t.dispatch(t.state.tr.setMeta(Ee,{remove:e}))}function replacePlaceholderWithNode(t,e,n){const o=currentPlaceholderPos(t,e);if(null===o||!t.editable||t.isDestroyed)return!1;const a=t.state.schema.nodes[n.type];if(!a)return!1;const r=a.create(n.attrs??null),l=t.state.tr;let i;try{const t=insertUploadedBlock(l,o,r);t.replacedEmpty&&(i={from:o,to:t.nextPos})}catch{return l.setMeta(Ee,{remove:e}),t.dispatch(l),!1}return l.setMeta(Ee,{remove:e,reanchor:i}),t.dispatch(l),!0}function currentPlaceholderPos(t,e){const n=Ee.getState(t.state),o=null==n?void 0:n.items.find(t=>t.id===e);return o?o.anchor.pos:null}function selectTableCell(t,e){var n,o;if(e<0||e>=t.state.doc.content.size||!["cell","header_cell"].includes((null==(n=t.state.doc.nodeAt(e))?void 0:n.type.spec.tableRole)??""))return;const a=t.state.selection;let r=!1;null==(o=a.forEachCell)||o.call(a,(t,n)=>{n===e&&(r=!0)}),r||t.dispatch(t.state.tr.setSelection(ft.near(t.state.doc.resolve(e+1))))}function cellPositionAtDOM(t,e){try{const n=t.state.doc.resolve(t.posAtDOM(e,0));for(let t=n.depth;t>0;t-=1)if(["cell","header_cell"].includes(n.node(t).type.spec.tableRole??""))return n.before(t)}catch{}return null}function selectTableAxis(t,e,n,o){if(!t.editable)return!1;try{const a=t.state.doc.resolve(e),r=a.node(-1);if("table"!==r.type.spec.tableRole)return!1;const l=a.start(-1),i=St.get(r),s=i.findCell(e-l);if(void 0!==o){const t="row"===n?i.height:i.width;if(!Number.isInteger(o)||o<0||o>=t)return!1;"row"===n&&(s.top=o,s.bottom=o+1),"column"===n&&(s.left=o,s.right=o+1)}const c="row"===n?s.top*i.width:"column"===n?s.left:0,d="row"===n?(s.bottom-1)*i.width+i.width-1:"column"===n?(i.height-1)*i.width+s.right-1:i.map.length-1,u=Lt.create(t.state.doc,l+i.map[c],l+i.map[d]);return t.dispatch(t.state.tr.setSelection(u)),t.focus(),!0}catch{return!1}}function tablePositionAtCell(t,e){try{const n=t.state.doc.resolve(e);return"table"===n.node(-1).type.spec.tableRole?n.before(-1):null}catch{return null}}function currentTableCellPosition(t){const e=t.state.selection;if(e instanceof Lt)return e.$anchorCell.pos;for(let t=e.$from.depth;t>0;t-=1)if(["cell","header_cell"].includes(e.$from.node(t).type.spec.tableRole??""))return e.$from.before(t);return null}function insertTableBoundary(t,e,n,o){if(!t.isEditable)return!1;const a=tablePositionAtCell(t.view,e);if(null===a)return!1;const r=t.state.doc.nodeAt(a),l=St.get(r),i="row"===n?l.height:l.width;if(!Number.isInteger(o)||o<0||o>i)return!1;const s={map:l,table:r,tableStart:a+1,left:0,top:0,right:l.width,bottom:l.height},c=t.state.tr.setSelection(ft.near(t.state.doc.resolve(e+1)));return"row"===n?Nt(c,s,o):Tt(c,s,o),t.view.dispatch(c),t.view.focus(),!0}function tableSelectionMarkActive(t,e){const n=t.state.schema.marks[e],o=t.state.selection;if(!(n&&o instanceof Lt))return!1;let a=!1,r=!0;return o.forEachCell(t=>t.descendants(t=>{t.isText&&(a=!0,n.isInSet(t.marks)||(r=!1))})),a&&r}function setTableSelectionMark(t,e,n){const o=t.state.schema.marks[e],a=t.state.selection;if(!(t.isEditable&&o&&a instanceof Lt))return!1;const r=t.state.tr;return a.forEachCell((t,e)=>{const a=e+1,l=e+t.nodeSize-1;null===n?r.removeMark(a,l,o):r.addMark(a,l,o.create(n))}),!!r.docChanged&&(t.view.dispatch(r),!0)}function findTable(t){const{$from:e}=t.state.selection;for(let t=e.depth;t>0;t-=1){const n=e.node(t);if("table"===n.type.spec.tableRole)return{node:n,pos:e.before(t)}}return null}function tableHeaderActive(t,e){const n=findTable(t);if(!n)return!1;const o=St.get(n.node),a=o.cellsInRect({left:0,top:0,right:"row"===e?o.width:1,bottom:"column"===e?o.height:1});return a.length>0&&a.every(t=>{var e;return"header_cell"===(null==(e=n.node.nodeAt(t))?void 0:e.type.spec.tableRole)})}function distributeTableColumns(t,e){const n=findTable(t);if(!t.isEditable||!n||!Number.isFinite(e)||e<=0)return!1;const o=St.get(n.node),a=Math.max(It,Math.min(2e3,Math.floor(e/o.width))),r=t.state.tr;for(const e of new Set(o.map)){const o=n.pos+1+e,l=t.state.doc.nodeAt(o);r.setNodeMarkup(o,void 0,{...l.attrs,colwidth:Array(Number(l.attrs.colspan)).fill(a)})}return t.view.dispatch(r),!0}function setTableHeaderBackground(t,e){const n=findTable(t),o=Object.values(t.state.schema.nodes).find(t=>"header_cell"===t.spec.tableRole);if(!t.isEditable||!n||!o||null!==e&&!Rt.some(t=>t.value===e))return!1;const a=St.get(n.node),r=t.state.tr;for(const l of new Set(a.map.slice(0,a.width))){const a=n.pos+1+l,i=t.state.doc.nodeAt(a);r.setNodeMarkup(a,o,{...i.attrs,backgroundColor:e})}return t.view.dispatch(r),!0}function currentCellRect(t){try{const e=Pt(t.state);return{row:e.top,col:e.left}}catch{return null}}function setColumnWidth(t,e,n){const o=findTable(t);if(!o)return!1;const a=St.get(o.node);if(e<0||e>=a.width)return!1;const{state:r,view:l}=t;if(!t.isEditable||!Number.isFinite(n)||n<40||n>2e3)return!1;const i=r.tr,s=/* @__PURE__ */new Set;let c=0;for(let t=0;t<a.height;t+=1){const l=a.map[t*a.width+e];if(s.has(l))continue;s.add(l);const d=o.pos+1+l,u=r.doc.nodeAt(d);if(!u)continue;const m=[...u.attrs.colwidth??Array(Number(u.attrs.colspan??1)).fill(0)];m[e-a.findCell(l).left]=n,i.setNodeMarkup(d,void 0,{...u.attrs,colwidth:m}),c+=1}return c>0&&l.dispatch(i),c>0}function autoFitColumn(t,e){var n;const o=findTable(t);if(!o)return!1;const a=St.get(o.node);if(e<0||e>=a.width)return!1;const{state:r,view:l}=t;if(!t.isEditable)return!1;const i=r.tr,s=/* @__PURE__ */new Set;let c=0;for(let t=0;t<a.height;t+=1){const l=a.map[t*a.width+e];if(s.has(l))continue;s.add(l);const d=o.pos+1+l,u=r.doc.nodeAt(d);if(!u)continue;if(null==(null==(n=u.attrs)?void 0:n.colwidth))continue;const m=[...u.attrs.colwidth];m[e-a.findCell(l).left]=0,i.setNodeMarkup(d,void 0,{...u.attrs,colwidth:m.some(t=>t>0)?m:null}),c+=1}return c>0&&l.dispatch(i),c>0}function readTableGeometry(t,e,n){var o,a;try{const r=t.state.doc.resolve(e),l=r.node(-1);if("table"!==l.type.spec.tableRole)return null;const i=r.start(-1),s=St.get(l),c=t.nodeDOM(e);if(!(c instanceof HTMLElement))return null;const d=c.closest("table"),u=t.dom.closest(".editor-shell");if(!d||!u)return null;const m=u.getBoundingClientRect(),p=d.getBoundingClientRect(),f=(d.closest(".tableWrapper")??d).getBoundingClientRect(),h=Math.max(p.left,f.left),g=Math.min(p.right,f.right);if(g<=h)return null;const v=Array.from(d.rows).map((t,e)=>{const n=t.getBoundingClientRect();return{index:e,cellPos:i+s.map[e*s.width],start:n.top-m.top,size:n.height}}),b=Array.from(d.querySelectorAll(":scope > colgroup > col")).map((t,e)=>{const n=t.getBoundingClientRect();return{index:e,cellPos:i+s.map[e],start:n.left-m.left,size:n.width}});if(v.length!==s.height||b.length!==s.width)return null;const y=s.findCell(e-i),w=n?(null==(o=v.find(t=>n.y>=t.start+m.top&&n.y<t.start+m.top+t.size))?void 0:o.index)??y.top:y.top,k=n?(null==(a=b.find(t=>n.x>=t.start+m.left&&n.x<t.start+m.left+t.size))?void 0:a.index)??y.left:y.left;return{cellPos:e,rowIndex:w,colIndex:k,rowTop:v[w].start,rowHeight:v[w].size,colLeft:b[k].start,colWidth:b[k].size,tableWidth:g-h,tableHeight:p.height,tableTop:p.top-m.top,tableLeft:h-m.left,contentLeft:t.dom.getBoundingClientRect().left-m.left,rows:v,columns:b}}catch{return null}}function clippedTableSelection(t,e){if(!t.length)return null;const n=Math.max(e.left,Math.min(...t.map(t=>t.left))),o=Math.min(e.right,Math.max(...t.map(t=>t.right))),a=Math.min(...t.map(t=>t.top)),r=Math.max(...t.map(t=>t.bottom));return o>n&&r>a?{left:n,right:o,top:a,bottom:r}:null}const Le=new pt("ywiki-table-interaction"),Se=ut.create({name:"ywikiTableInteraction",addOptions:()=>({onHover:()=>{}}),addProseMirrorPlugins(){const t=this.options;return[new mt({key:Le,view:e=>{const n=e.dom.closest(".editor-shell")??e.dom;let o,a=null,r="",l=0;const clear=()=>{a=null,o=void 0,r&&t.onHover(null),r=""},schedule=()=>{l||(l=requestAnimationFrame(()=>{l=0,(()=>{if(!(null==a?void 0:a.isConnected)||!e.editable)return void clear();const n=cellPositionAtDOM(e,a),l=null===n?null:readTableGeometry(e,n,o);if(!l)return void clear();const i=JSON.stringify(l);i!==r&&(r=i,t.onHover(l))})()}))},move=t=>{var n;const r=t,l=r.target instanceof Element?r.target:null;if(null==l?void 0:l.closest(".tbl-ui-host"))return;const i=null==l?void 0:l.closest("td,th");if(i&&e.dom.contains(i))return a=i,o={x:r.clientX,y:r.clientY},void schedule();const s=null==(n=null==a?void 0:a.closest("table"))?void 0:n.getBoundingClientRect();s&&r.clientX>=s.left-64&&r.clientX<=s.right+24&&r.clientY>=s.top-32&&r.clientY<=s.bottom+24||clear()};n.addEventListener("mousemove",move),n.addEventListener("mouseleave",clear),window.addEventListener("scroll",schedule,!0),window.addEventListener("resize",schedule);const i=new ResizeObserver(schedule);return i.observe(e.dom),{update:schedule,destroy:()=>{cancelAnimationFrame(l),i.disconnect(),n.removeEventListener("mousemove",move),n.removeEventListener("mouseleave",clear),window.removeEventListener("scroll",schedule,!0),window.removeEventListener("resize",schedule)}}}})]}}),Ne="default";function coreExtensions(t={}){const C=[...t.i18n?[h(t.i18n)]:[],e.configure({heading:{levels:[1,2,3,4,5,6]},undoRedo:!t.collabDoc&&{},link:!1,codeBlock:!1,trailingNode:!1,dropcursor:!1}),oe.configure({canCopy:()=>{var e;return(null==(e=t.canCopyCode)?void 0:e.call(t))??!1},contentContext:t.contentContext}),pe,n.configure({openOnClick:!1,protocols:["http","https","mailto"],HTMLAttributes:{rel:"noopener noreferrer nofollow"}}),Ut.configure({inline:!1,allowBase64:!1}).extend({addNodeView:()=>createImageNodeView(t.attachmentFetcher,t.attachmentScope,t.attachmentPortal)}),Wt.extend({addNodeView:()=>((t=w,e)=>({node:n,editor:o})=>{var a,r,l;const i=y(o),s=i.text,c=document.createElement("div");c.className="doc-file-attachment",c.setAttribute("data-file-attachment","true"),c.setAttribute("data-block-chrome",""),c.setAttribute("contenteditable","false");let d,u=String((null==(a=n.attrs)?void 0:a.attachmentId)??""),m=String((null==(r=n.attrs)?void 0:r.mimeType)??""),p=String((null==(l=n.attrs)?void 0:l.filename)??s("附件")),f=null;const h=document.createElement("div");h.className="doc-file-head";const g=document.createElement("span");g.className="doc-file-icon";const v=document.createElement("span");v.className="doc-file-name";const b=document.createElement("span");b.className="doc-file-size";const w=document.createElement("button");w.type="button",w.className="doc-file-action",w.textContent=s("下载"),w.addEventListener("click",async e=>{if(e.preventDefault(),e.stopPropagation(),!u||w.disabled)return;const n=u;w.disabled=!0;try{await M(n,p,t),n===u&&(w.textContent=s("下载"))}catch{n===u&&(w.textContent=s("下载失败,重试"))}finally{n===u&&(w.disabled=!1)}}),h.append(g,v,b,w),c.append(h);let E=null;function render(){var o;c.setAttribute("data-attachment-id",u),g.textContent=m.startsWith("video/")?"▶":m.startsWith("image/")?"🖼":"📎",v.textContent=p,v.title=p;const a=Number((null==(o=n.attrs)?void 0:o.size)??0);if(b.textContent=a>0?x(a):"",w.disabled=!u,w.textContent=s("下载"),null==E||E.remove(),E=null,null==d||d(),null==f||f(),f=null,!u)return;if(m.startsWith("video/")){const t=document.createElement("video");t.className="doc-file-video",t.controls=!0,t.preload="metadata",E=t,c.append(t)}else{if(!m.startsWith("image/"))return;{const t=document.createElement("img");t.className="doc-file-image",t.alt=p,E=t,c.append(t)}}const r=u;f=S(c,()=>{null==d||d(),d=k(r,t=>{r===u&&E&&E.setAttribute("src",t)},t,void 0,e)})}render();const C=i.subscribe(()=>{w.textContent=s("下载")});return{dom:c,update:t=>{var e,o,a,r;if("fileAttachment"!==t.type.name)return!1;n=t;const l=Number((null==(e=t.attrs)?void 0:e.size)??0);b.textContent=l>0?x(l):"";const i=String((null==(o=t.attrs)?void 0:o.attachmentId)??""),c=String((null==(a=t.attrs)?void 0:a.mimeType)??""),d=String((null==(r=t.attrs)?void 0:r.filename)??s("附件"));return i===u&&c===m&&d===p||(u=i,m=c,p=d,render()),!0},destroy:()=>{C(),u="",E=null,null==d||d(),null==f||f(),f=null},stopEvent:t=>{var e,n;return!!(null==(n=null==(e=t.target)?void 0:e.closest)?void 0:n.call(e,"video, audio, button"))}}})(t.attachmentFetcher,t.attachmentScope)}),Yt,a.configure({resizable:!0,cellMinWidth:120,allowTableNodeSelection:!0}),r,Kt,Qt,l,i.configure({nested:!0}),$t,Ft,qt,Gt,Xt.extend({addNodeView:()=>mathNodeView}),jt.extend({addNodeView:()=>mathNodeView}),g.configure({renderer:t.videoRenderer}),v.configure({renderer:t.mindMapRenderer}),b.configure({renderer:(A=t.contentContext,({node:t,editor:e,getPos:n})=>{const o=document.createElement("div"),a=document.createElement("div");a.className="callout-controls-host",a.contentEditable="false";const r=document.createElement("div");r.className="doc-callout-content",r.dataset.calloutContent="true",o.append(a,r);const l=function createPortalResolver(t,e){let n=null;return{resolve:()=>{var o;const a=null==e?void 0:e().portal;if(null==a?void 0:a.isConnected)return a;if(!t.isConnected)return null;if(null==n?void 0:n.isConnected)return n;const r=document.createElement("div");r.className="wendang-portal wendang",r.dataset.wendangPortal="";const l=null==(o=t.closest("[data-wendang-theme]"))?void 0:o.getAttribute("data-wendang-theme");return l&&(r.dataset.wendangTheme=l),document.body.append(r),n=r,r},destroy(){null==n||n.remove(),n=null}}}(o,A);let i=t,s=F(a),c=e.isEditable;const position=()=>{var t;const o=n();return"number"==typeof o&&"callout"===(null==(t=e.state.doc.nodeAt(o))?void 0:t.type.name)?o:null},paint=()=>{const t=W(i.attrs);o.classList.add("doc-callout");for(const t of Object.keys(o.dataset))(t.startsWith("callout")||"tone"===t||"iconHidden"===t)&&delete o.dataset[t];for(const[e,n]of Object.entries(t))o.setAttribute(e,n);const n=/* @__PURE__ */D(CalloutControls,{attrs:i.attrs,editable:e.isEditable,portal:l.resolve,onPatch:t=>{const n=position();null!==n&&function patchCallout(t,e,n){if(!t.isEditable||t.isDestroyed)return!1;const o=t.state.doc.nodeAt(e);"callout"!==(null==o?void 0:o.type.name)||!K({...o.attrs,...n})||dispatch(t,t.state.tr.setNodeMarkup(e,void 0,{...o.attrs,...n}))}(e,n,t)},onUnwrap:()=>{const t=position();null!==t&&unwrapCallout(e,t)}}),a=null==A?void 0:A();null==s||s.render(a?/* @__PURE__ */D(E,{value:a,children:n}):n)};paint();const syncEditable=({transaction:t})=>{(e.isEditable!==c||t.getMeta("content-context"))&&(c=e.isEditable,paint())};return e.on("transaction",syncEditable),{dom:o,contentDOM:r,update:t=>"callout"===t.type.name&&(i=t,paint(),!0),stopEvent:t=>a.contains(t.target),ignoreMutation:t=>"selection"!==t.type&&!r.contains(t.target),destroy(){l.destroy(),e.off("transaction",syncEditable);const t=s;s=null,queueMicrotask(()=>null==t?void 0:t.unmount())}}})}),c,d,u,m,p,f,ie,ce,ue,re,ge];var A;return t.placeholder&&C.push(o.configure({placeholder:t.placeholder})),t.inlineComments&&C.push(be.configure(t.inlineComments)),t.slash&&C.push(ke.configure(t.slash)),t.blockHandle&&C.push(xe.configure(t.blockHandle)),t.tableInteraction&&C.push(Se.configure(t.tableInteraction)),t.uploadPlaceholder&&C.push(Ae.configure(t.uploadPlaceholder)),t.collabDoc&&C.push(s.configure({document:t.collabDoc,field:t.collabField??Ne})),t.collabDoc&&t.collabAwareness&&C.push(ye.configure({awareness:t.collabAwareness})),C}export{coreExtensions as A,BlockRangeSelection as B,Ne as C,refreshInlineComments as D,addUploadPlaceholder as E,currentPlaceholderPos as F,insertUploadedBlock as G,removeUploadPlaceholder as H,replacePlaceholderWithNode as I,le as T,tablePositionAtCell as a,buildColumnsJson as b,currentTableCellPosition as c,dismissSlash as d,Jt as e,cellPositionAtDOM as f,selectTableCell as g,highlightMenuBlock as h,insertTableBoundary as i,clippedTableSelection as j,tableSelectionMarkActive as k,setTableSelectionMark as l,setTableHeaderBackground as m,currentCellRect as n,setColumnWidth as o,autoFitColumn as p,distributeTableColumns as q,readTableGeometry as r,selectTableAxis as s,tableHeaderActive as t,unwrapCallout as u,getSelectedBlocks as v,setBlockRangeSelection as w,setImageRangeSelection as x,pastedImageFiles as y,pastedRemoteImageUrls as z};
@@ -1,89 +1 @@
1
- "use client";
2
- import pinyin from "tiny-pinyin";
3
- const cache = /* @__PURE__ */ new Map();
4
- const CACHE_LIMIT = 2e3;
5
- function pinyinIndex(title) {
6
- const key = title;
7
- const hit = cache.get(key);
8
- if (hit) return hit;
9
- let full;
10
- let initials;
11
- if (pinyin.isSupported()) {
12
- const withSep = pinyin.convertToPinyin(title, "-", true).toLowerCase().replace(/\s+/g, "");
13
- full = withSep.replace(/-/g, "");
14
- initials = withSep.split("-").filter((seg) => seg.length > 0).map((seg) => seg[0]).join("");
15
- } else {
16
- full = title.toLowerCase();
17
- initials = full;
18
- }
19
- const value = { full, initials };
20
- if (cache.size >= CACHE_LIMIT) cache.clear();
21
- cache.set(key, value);
22
- return value;
23
- }
24
- function clearPinyinCache() {
25
- cache.clear();
26
- }
27
- const SCORE = {
28
- exact: 1e3,
29
- startsWith: 900,
30
- /** 出现在词边界(空格、连字符等分隔)之后 */
31
- boundary: 850,
32
- includes: 800,
33
- pinyinStartsWith: 700,
34
- pinyinIncludes: 650,
35
- initialsExact: 680,
36
- initialsStartsWith: 660,
37
- initialsIncludes: 620
38
- };
39
- function normalize(q) {
40
- return q.trim().toLowerCase();
41
- }
42
- function isLatinQuery(q) {
43
- return /^[a-z0-9]+$/.test(q);
44
- }
45
- function matchTitle(input, rawQuery) {
46
- const query = normalize(rawQuery);
47
- if (query.length === 0) return { score: 0, kind: "title" };
48
- const title = input.title.toLowerCase();
49
- if (title === query) return { score: SCORE.exact, kind: "title" };
50
- if (title.startsWith(query)) return { score: SCORE.startsWith, kind: "title" };
51
- const idx = title.indexOf(query);
52
- if (idx > 0) {
53
- const prev = title[idx - 1];
54
- const atBoundary = /[\s\-_/.,;::,。、()()]/.test(prev);
55
- return {
56
- score: atBoundary ? SCORE.boundary : SCORE.includes,
57
- kind: "title"
58
- };
59
- }
60
- if (!isLatinQuery(query)) return null;
61
- const { full, initials } = pinyinIndex(input.title);
62
- if (initials === query) return { score: SCORE.initialsExact, kind: "initials" };
63
- if (initials.startsWith(query)) {
64
- return { score: SCORE.initialsStartsWith, kind: "initials" };
65
- }
66
- if (full.startsWith(query)) {
67
- return { score: SCORE.pinyinStartsWith, kind: "pinyin" };
68
- }
69
- if (full.includes(query)) return { score: SCORE.pinyinIncludes, kind: "pinyin" };
70
- if (initials.includes(query)) {
71
- return { score: SCORE.initialsIncludes, kind: "initials" };
72
- }
73
- return null;
74
- }
75
- function rankPages(pages, rawQuery) {
76
- const out = [];
77
- pages.forEach((page, order) => {
78
- const match = matchTitle(page, rawQuery);
79
- if (match) out.push({ page, match, order });
80
- });
81
- out.sort((a, b) => b.match.score - a.match.score || a.order - b.order);
82
- return out.map(({ page, match }) => ({ page, match }));
83
- }
84
- export {
85
- clearPinyinCache as c,
86
- matchTitle as m,
87
- pinyinIndex as p,
88
- rankPages as r
89
- };
1
+ "use client";import t from"tiny-pinyin";const n=/* @__PURE__ */new Map;function pinyinIndex(e){const i=e,r=n.get(i);if(r)return r;let s,c;if(t.isSupported()){const n=t.convertToPinyin(e,"-",!0).toLowerCase().replace(/\s+/g,"");s=n.replace(/-/g,""),c=n.split("-").filter(t=>t.length>0).map(t=>t[0]).join("")}else s=e.toLowerCase(),c=s;const o={full:s,initials:c};return n.size>=2e3&&n.clear(),n.set(i,o),o}function clearPinyinCache(){n.clear()}function matchTitle(t,n){const e=function normalize(t){return t.trim().toLowerCase()}(n);if(0===e.length)return{score:0,kind:"title"};const i=t.title.toLowerCase();if(i===e)return{score:1e3,kind:"title"};if(i.startsWith(e))return{score:900,kind:"title"};const r=i.indexOf(e);if(r>0){const t=i[r-1];return{score:/[\s\-_/.,;::,。、()()]/.test(t)?850:800,kind:"title"}}if(!function isLatinQuery(t){return/^[a-z0-9]+$/.test(t)}(e))return null;const{full:s,initials:c}=pinyinIndex(t.title);return c===e?{score:680,kind:"initials"}:c.startsWith(e)?{score:660,kind:"initials"}:s.startsWith(e)?{score:700,kind:"pinyin"}:s.includes(e)?{score:650,kind:"pinyin"}:c.includes(e)?{score:620,kind:"initials"}:null}function rankPages(t,n){const e=[];return t.forEach((t,i)=>{const r=matchTitle(t,n);r&&e.push({page:t,match:r,order:i})}),e.sort((t,n)=>n.match.score-t.match.score||t.order-n.order),e.map(({page:t,match:n})=>({page:t,match:n}))}export{clearPinyinCache as c,matchTitle as m,pinyinIndex as p,rankPages as r};
@@ -1,35 +1 @@
1
- "use client";
2
- import { useRef, useEffect, useCallback } from "react";
3
- function useLatest(value) {
4
- const ref = useRef(value);
5
- ref.current = value;
6
- return ref;
7
- }
8
- function useReady() {
9
- const state = useRef({ ready: false, disposed: false, waiters: [] });
10
- useEffect(() => {
11
- state.current.disposed = false;
12
- return () => {
13
- state.current.disposed = true;
14
- state.current.ready = false;
15
- for (const resolve of state.current.waiters.splice(0)) resolve();
16
- };
17
- }, []);
18
- const markReady = useCallback(() => {
19
- state.current.ready = true;
20
- for (const resolve of state.current.waiters.splice(0)) resolve();
21
- }, []);
22
- return {
23
- markReady,
24
- isReady: () => state.current.ready,
25
- whenReady: () => state.current.ready || state.current.disposed ? Promise.resolve() : new Promise((resolve) => state.current.waiters.push(resolve))
26
- };
27
- }
28
- function asError(error) {
29
- return error instanceof Error ? error : new Error(String(error));
30
- }
31
- export {
32
- useReady as a,
33
- asError as b,
34
- useLatest as u
35
- };
1
+ "use client";import{useRef as r,useEffect as e,useCallback as s}from"react";function useLatest(e){const s=r(e);return s.current=e,s}function useReady(){const t=r({ready:!1,disposed:!1,waiters:[]});return e(()=>(t.current.disposed=!1,()=>{t.current.disposed=!0,t.current.ready=!1;for(const r of t.current.waiters.splice(0))r()}),[]),{markReady:s(()=>{t.current.ready=!0;for(const r of t.current.waiters.splice(0))r()},[]),isReady:()=>t.current.ready,whenReady:()=>t.current.ready||t.current.disposed?Promise.resolve():new Promise(r=>t.current.waiters.push(r))}}function asError(r){return r instanceof Error?r:new Error(String(r))}export{useReady as a,asError as b,useLatest as u};
@@ -0,0 +1,2 @@
1
+ "use client";import{useState as e,useEffect as t,useRef as n,useContext as r,createContext as c,useSyncExternalStore as o}from"react";import{jsx as a}from"react/jsx-runtime";import{createI18n as s}from"wendang/i18n";const unavailableAttachment=async()=>{throw new Error("未配置附件读取服务")},l=unavailableAttachment,i=/* @__PURE__ */new Map;function primeAttachment(e,t,n,r){if(!e||!t||void 0===n&&!r)return;const c=cacheKey(e,n,r);for(i.delete(c),i.set(c,t);i.size>16;){const e=i.keys().next();if(e.done)break;i.delete(e.value)}}const u=/* @__PURE__ */new Map,d=/* @__PURE__ */new Map,h=50331648;let f=0,m=0;const g=/* @__PURE__ */new WeakMap;let v=0;function cacheOwner(e,t=unavailableAttachment){if(void 0!==e)return["scope",e];let n=g.get(t);return void 0===n&&(n=++v,g.set(t,n)),["fetcher",n]}function cacheKey(e,t,n){return JSON.stringify([...cacheOwner(t,n),e])}function trimCache(){if(f<=h)return;const e=[...u.entries()].filter(([,e])=>0===e.refs).sort((e,t)=>e[1].touched-t[1].touched);for(const[t,n]of e){if(f<=h)break;u.delete(t),f-=n.blob.size,URL.revokeObjectURL(n.url)}}function acquireEntry(e,t){let n=u.get(e);return n||(n={blob:t,url:URL.createObjectURL(t),refs:0,touched:++m},u.set(e,n),f+=t.size),n.touched=++m,n}function attachmentObjectUrl(e,t,n=unavailableAttachment,r,c){const o=cacheKey(e,c,n);let a,s=!1;const dispose=()=>{s||(s=!0,a&&function releaseEntry(e,t){0!==t.refs&&(t.refs-=1,0===t.refs&&(t.touched=++m,u.get(e)===t&&trimCache()))}(o,a))},l=u.get(o);if(l)return l.refs+=1,a=l,l.touched=++m,t(l.url),dispose;const h=function takePrimedAttachment(e,t,n){if(void 0===t&&!n)return null;const r=cacheKey(e,t,n),c=i.get(r);return c?(i.delete(r),c):null}(e,c,n);if(h){const e=acquireEntry(o,h);return e.refs+=1,a=e,t(e.url),trimCache(),dispose}let f=d.get(o);if(!f){f={promise:Promise.resolve().then(()=>n(e)),cancelled:!1},d.set(o,f);const t=f;t.promise.finally(()=>{d.get(o)===t&&d.delete(o)}).catch(()=>{})}const g=f;return g.promise.then(e=>{if(s||g.cancelled)return;const n=acquireEntry(o,e);n.refs+=1,a=n,t(n.url),trimCache()}).catch(()=>{s||g.cancelled||null==r||r()}),dispose}async function downloadAttachment(e,t,n=l){const r=await n(e),c=URL.createObjectURL(r),o=document.createElement("a");o.href=c,o.download=t||"attachment",document.body.appendChild(o),o.click(),o.remove(),setTimeout(()=>URL.revokeObjectURL(c),1e4)}function formatBytes(e){if(!Number.isFinite(e)||e<=0)return"";const t=["B","KB","MB","GB"];let n=e,r=0;for(;n>=1024&&r<t.length-1;)n/=1024,r+=1;return`${n>=10||0===r?Math.round(n):n.toFixed(1)} ${t[r]}`}const p=c({host:{},theme:"light",accent:"#2f6feb",portal:null,i18n:s()});function useContentContext(){return r(p)}function useContentHost(){return useContentContext().host}function ContentContextBridge({value:e,children:t}){/* @__PURE__ */
2
+ return a(p.Provider,{value:e,children:t})}function ContentProvider({host:r={},theme:c="light",accent:o="#2f6feb",unstyled:l=!1,children:h,className:m="",locale:g,messages:v,video:y}){const[w]=e(()=>`wendang:${crypto.randomUUID()}`),C=r.scope??w,b={...r,scope:C},[U]=e(()=>s(g,v));t(()=>{U.update(g,v)},[U,g,v]);const[O,N]=e(null),k=n(C),x=n({theme:c,accent:o,unstyled:l});return x.current={theme:c,accent:o,unstyled:l},t(()=>{const e=document.createElement("div"),{theme:t,accent:n,unstyled:r}=x.current;return e.className=("wendang-portal "+(r?"":"wendang")).trim(),e.dataset.wendangPortal="",e.dataset.wendangTheme=t,e.style.setProperty("--wendang-accent",n),e.style.colorScheme=t,e.lang=(null==g?void 0:g.locale)??"zh-CN",document.body.append(e),N(e),()=>{e.remove()}},[]),t(()=>{k.current!==C&&(function clearAttachmentCache(e,t){const n=void 0!==e||t?cacheOwner(e,t):void 0,matches=e=>{if(!n)return!0;const[t,r]=JSON.parse(e);return t===n[0]&&r===n[1]};for(const[e,t]of u)matches(e)&&(URL.revokeObjectURL(t.url),u.delete(e),f-=t.blob.size);for(const[e,t]of d)matches(e)&&(t.cancelled=!0,d.delete(e));for(const e of i.keys())matches(e)&&i.delete(e)}(k.current),k.current=C)},[C]),t(()=>{O&&(O.className=("wendang-portal "+(l?"":"wendang")).trim(),O.dataset.wendangTheme=c,O.style.setProperty("--wendang-accent",o),O.style.colorScheme=c,O.lang=(null==g?void 0:g.locale)??"zh-CN")},[O,c,o,l,g]),/* @__PURE__ */a(p.Provider,{value:{host:b,theme:c,accent:o,portal:O,i18n:U,video:y},children:/* @__PURE__ */a("div",{className:`wendang-root ${m}`,"data-wendang-theme":c,lang:(null==g?void 0:g.locale)??"zh-CN",style:{"--wendang-accent":o,colorScheme:c},children:/* @__PURE__ */a("div",{className:l?void 0:"wendang","data-wendang-theme":c,children:h},C)})})}function useI18n(){const e=useContentContext().i18n;return o(e.subscribe,()=>e.version,()=>e.version),e}export{ContentProvider as C,useContentContext as a,useContentHost as b,useI18n as c,attachmentObjectUrl as d,downloadAttachment as e,formatBytes as f,ContentContextBridge as g,primeAttachment as p,unavailableAttachment as u};