@qingwu-ui/ai-editor 1.1.2 → 1.1.3
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.
package/README.md
CHANGED
|
@@ -105,7 +105,7 @@ export default function Page() {
|
|
|
105
105
|
|
|
106
106
|
- **Tiptap 全套**(`@tiptap/core`、`@tiptap/react` 及各扩展,锁定 `^3.28.0`)——编辑器内核,已由本包统一管理版本,避免你逐个安装、版本错配。
|
|
107
107
|
- **文件预览全套**(`@file-viewer/react` 及 pdf / word / spreadsheet / presentation / archive / text 各渲染器,锁定 `2.2.2`)——附件在线预览能力,且全部按需懒加载,不点开附件不会下载。
|
|
108
|
-
- 其余内部实现库(dompurify、lowlight、xgplayer、cmdk、
|
|
108
|
+
- 其余内部实现库(dompurify、lowlight、xgplayer、cmdk、pele 等)同样自动带入。
|
|
109
109
|
|
|
110
110
|
你只需保证宿主已有的 **peer 依赖**:
|
|
111
111
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"release-notes-dialog.d.ts","sourceRoot":"","sources":["../../src/components/release-notes-dialog.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,OAAO,CAAC;AAEhC,UAAU,KAAK;IACb,IAAI,EAAE,OAAO,CAAC;IACd,OAAO,EAAE,MAAM,IAAI,CAAC;CACrB;
|
|
1
|
+
{"version":3,"file":"release-notes-dialog.d.ts","sourceRoot":"","sources":["../../src/components/release-notes-dialog.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,OAAO,CAAC;AAEhC,UAAU,KAAK;IACb,IAAI,EAAE,OAAO,CAAC;IACd,OAAO,EAAE,MAAM,IAAI,CAAC;CACrB;AAyGD,eAAO,MAAM,kBAAkB,EAAE,EAAE,CAAC,KAAK,CA8CxC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"code-block-view.d.ts","sourceRoot":"","sources":["../../../src/editor/extensions/code-block-view.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"code-block-view.d.ts","sourceRoot":"","sources":["../../../src/editor/extensions/code-block-view.tsx"],"names":[],"mappings":"AAiJA,wBAAgB,aAAa,CAAC,EAC5B,IAAI,EACJ,gBAAgB,EAChB,MAAM,EACN,MAAM,EACN,UAAU,EACV,QAAQ,GACT,EAAE,GAAG,+BA2vBL"}
|
package/dist/index.cjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("./sanitize-D4Bd9RtA.cjs"),t=require("./signed-fetch-ULpEJyn5.cjs"),n=require("./storage-VaeLS7eM.cjs"),r=require("./local-D4481lUa.cjs");let i=require("react"),a=require("react/jsx-runtime"),o=require("ai"),s=require("@tiptap/pm/model"),c=require("@tiptap/react"),l=require("@tiptap/react/menus"),u=require("react-dom"),d=require("@tiptap/core"),f=require("@tiptap/pm/state"),p=require("@tiptap/pm/view"),m=require("@tiptap/extension-image"),h=require("@tiptap/extension-link"),g=require("@tiptap/extension-underline"),_=require("@tiptap/starter-kit");_=e.l(_,1);let v=require("@tiptap/extension-character-count"),y=require("@tiptap/extension-color"),b=require("@tiptap/extension-highlight"),x=require("@tiptap/extension-horizontal-rule"),S=require("@tiptap/extension-placeholder"),C=require("@tiptap/extension-table"),w=require("@tiptap/extension-table-cell"),T=require("@tiptap/extension-table-header"),E=require("@tiptap/extension-table-row"),D=require("@tiptap/extension-task-item"),O=require("@tiptap/extension-task-list"),k=require("@tiptap/extension-text-style"),A=require("tiptap-markdown"),j=require("@tiptap/extension-code-block-lowlight"),M=require("highlight.js/lib/languages/dockerfile");M=e.l(M,1);let N=require("lowlight"),P=require("katex");P=e.l(P,1);let F=require("@tiptap/suggestion");F=e.l(F,1);var ee=null,I=null;function L(){return I||(typeof document>`u`?null:(ee=document.createElement(`canvas`),I=ee.getContext(`2d`),I))}var R=new Map;function te(e,t){let n=R.get(t);n||(n=new Map,R.set(t,n));let r=n.get(e);if(r!==void 0)return r;let i=L();return i?(i.font=t,r=i.measureText(e).width):r=ne(e,t),n.set(e,r),r}function ne(e,t){let n=parseFloat(t)||16,r=0;for(let t of e)re(t.codePointAt(0)??0)?r+=n:t===` `?r+=n*.3:r+=n*.55;return r}function re(e){return e>=19968&&e<=40959||e>=13312&&e<=19903||e>=131072&&e<=173791||e>=63744&&e<=64255||e>=194560&&e<=195103||e>=12288&&e<=12351||e>=65280&&e<=65519||e>=11904&&e<=12031||e>=12736&&e<=12783||e>=44032&&e<=55215}function z(e){return e===12289||e===12290||e===65292||e===65294||e===65306||e===65307||e===65311||e===65281||e===65289||e===65341||e===12301||e===12303||e===12299||e===12305}function B(e,t){let n=[],r=[];if(typeof Intl<`u`&&Intl.Segmenter)try{let t=new Intl.Segmenter(`zh`,{granularity:`grapheme`});for(let n of t.segment(e))r.push(n.segment)}catch{for(let t of e)r.push(t)}else r=[...e];for(let e of r){let r=e.codePointAt(0)??0,i=`latin`;e===`
|
|
2
2
|
`?i=`break`:e===` `||e===` `?i=`space`:re(r)&&(i=z(r)?`punct`:`cjk`),n.push({text:e,width:te(e,t),type:i})}return n}function ie(e,t,n){let r=0,i=Math.min(n,e.length);for(let n=t;n<i;n++)r+=e[n].width;return r}function V(e,t,n,r){return{text:e.slice(t,Math.min(n,e.length)).map(e=>e.text).join(``),width:r}}function ae(e,t,n=`16px system-ui`){let{maxWidth:r,lineHeight:i,maxLines:a,overflowWrap:o=`break-word`}=t,s=B(e,n),c=[],l={lineStart:0,lineWidth:0,lastBreakIdx:-1,lastBreakWidth:0};for(let e=0;e<s.length;e++){let t=s[e];if(t.type===`break`){c.push(V(s,l.lineStart,e,l.lineWidth)),l.lineStart=e+1,l.lineWidth=0,l.lastBreakIdx=-1;continue}let n=l.lineWidth+t.width;if(t.type===`space`){if(n>r&&l.lineWidth>0?(l.lastBreakIdx>=0?(c.push(V(s,l.lineStart,l.lastBreakIdx+1,l.lastBreakWidth)),l.lineStart=l.lastBreakIdx+1,l.lineWidth=ie(s,l.lineStart,e+1)):(c.push(V(s,l.lineStart,e,l.lineWidth)),l.lineStart=e,l.lineWidth=t.width),l.lastBreakIdx=-1):(l.lineWidth=n,l.lastBreakIdx=e,l.lastBreakWidth=l.lineWidth),a&&c.length>=a)break;continue}if(t.type===`cjk`){if(n>r&&l.lineWidth>0?(c.push(V(s,l.lineStart,e,l.lineWidth)),l.lineStart=e,l.lineWidth=t.width,l.lastBreakIdx=-1):(l.lineWidth=n,l.lastBreakIdx=e,l.lastBreakWidth=l.lineWidth),a&&c.length>=a)break;continue}if(t.type===`punct`){if(l.lineWidth===0&&c.length>0?c[c.length-1].text.length>0&&(l.lineWidth=t.width):n>r?(l.lastBreakIdx>=0?(c.push(V(s,l.lineStart,l.lastBreakIdx+1,l.lastBreakWidth)),l.lineStart=l.lastBreakIdx+1,l.lineWidth=ie(s,l.lineStart,e+1)):l.lineWidth=n,l.lastBreakIdx=-1):l.lineWidth=n,a&&c.length>=a)break;continue}if(n>r&&l.lineWidth>0?l.lastBreakIdx>=0?(c.push(V(s,l.lineStart,l.lastBreakIdx+1,l.lastBreakWidth)),l.lineStart=l.lastBreakIdx+1,l.lineWidth=ie(s,l.lineStart,e+1),l.lastBreakIdx=-1):o===`break-word`?(c.push(V(s,l.lineStart,e,l.lineWidth)),l.lineStart=e,l.lineWidth=t.width):l.lineWidth=n:l.lineWidth=n,a&&c.length>=a)break}let u=l.lineStart<s.length;if(u&&(!a||c.length<a)){let e=ie(s,l.lineStart,s.length);c.push(V(s,l.lineStart,s.length,e))}return{lines:c,totalHeight:c.length*i,lineCount:c.length,truncated:u&&a?c.length>=a:!1}}var oe=typeof window<`u`&&window.matchMedia(`(prefers-reduced-motion: reduce)`).matches,H=`13.5px -apple-system, BlinkMacSystemFont, "SF Pro Text", "PingFang SC", "Microsoft YaHei", system-ui, sans-serif`;function U(){if(typeof window>`u`)return 290;let e=window.innerWidth;return e<=480?Math.max(140,e-98):290}var W={info:`<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="10"/><line x1="12" y1="16" x2="12" y2="12"/><line x1="12" y1="8" x2="12.01" y2="8"/></svg>`,success:`<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="10"/><path d="M9 12l2 2 4-4"/></svg>`,warning:`<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M10.29 3.86L1.82 18a2 2 0 0 0 1.71 3h16.94a2 2 0 0 0 1.71-3L13.71 3.86a2 2 0 0 0-3.42 0z"/><line x1="12" y1="9" x2="12" y2="13"/><line x1="12" y1="17" x2="12.01" y2="17"/></svg>`,error:`<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="10"/><line x1="15" y1="9" x2="9" y2="15"/><line x1="9" y1="9" x2="15" y2="15"/></svg>`},se=1;function G(){return`qt${se++}${Date.now().toString(36)}`}function K(e,t,n){let r=document.createElement(e);return t&&(r.className=t),n!=null&&(r.innerHTML=n),r}function ce(e,t){let n=t.split(/\*\*(.+?)\*\*/g);for(let t=0;t<n.length;t++){let r=n[t];if(r)if(t%2==1){let t=K(`em`,`qt-mark`);t.textContent=r,e.appendChild(t)}else e.appendChild(document.createTextNode(r))}}var le={type:`info`,position:`top-center`,duration:4e3,maxVisible:5,persist:!1,persistMaxVisible:3,maxLines:void 0,vibrate:!0},ue=[80,40,80];function de(){if(!(typeof navigator>`u`||!(`vibrate`in navigator)))try{navigator.vibrate(ue)}catch{}}var fe=class{containers=new Map;opts={...le};toasts=new Map;queue=[];_seq=0;constructor(e){e&&Object.assign(this.opts,e)}ensureContainer(e){let t=this.containers.get(e);return t||(t=K(`div`,`qt-container`),t.setAttribute(`data-qt-pos`,e),t.setAttribute(`role`,`status`),t.setAttribute(`aria-live`,`polite`),t.setAttribute(`aria-atomic`,`false`),document.body.appendChild(t),this.containers.set(e,t)),t}show(e,t){let n=t?.type??this.opts.type,r=t?.position??this.opts.position,i=t?.persist??this.opts.persist?0:t?.duration??this.opts.duration,a=t?.dismissible??!0,o=t?.maxLines??this.opts.maxLines,s=t?.description,c=t?.action,l=G(),u={id:l,type:n,dismissible:a,position:r,duration:i,order:++this._seq,element:this.buildElement(l,e,n,a,o,s,c),timer:null};return this.toasts.size>=this.opts.maxVisible?(this.queue.push(u),l):(this.mount(u),l)}info(e,t){return this.show(e,{...t,type:`info`})}success(e,t){return this.show(e,{...t,type:`success`})}warn(e,t){return this.show(e,{...t,type:`warning`})}error(e,t){return this.show(e,{...t,type:`error`})}promise(e,t,n){let r=this.show(t.loading,{...n,type:`info`,duration:0,dismissible:!1});return e.then(e=>{this.dismiss(r);let i=typeof t.success==`function`?t.success(e):t.success;requestAnimationFrame(()=>{this.success(i,{...n,persist:!1})})},e=>{this.dismiss(r);let i=typeof t.error==`function`?t.error(e):t.error;requestAnimationFrame(()=>{this.error(i,{...n,persist:!1})})}),r}dismiss(e){if(e){let t=this.toasts.get(e);t&&this._exit(t)}else this.dismissAll()}dismissAll(){for(let e of this.toasts.values())this._exit(e);this.queue.length=0}configure(e){Object.assign(this.opts,e)}destroy(){for(let e of this.toasts.values())e.timer&&clearTimeout(e.timer);this.toasts.clear(),this.queue.length=0;for(let e of this.containers.values())e.remove();this.containers.clear()}buildElement(e,t,n,r,i,a,o){let s=K(`div`,`qt-toast qt-${n}${i==null?``:` qt-truncate`}${a||o?` qt-rich`:``}`);s.setAttribute(`data-qt-id`,e);let c=K(`span`,`qt-icon`);c.innerHTML=W[n],s.appendChild(c);let l=K(`div`,`qt-body`),u=K(`span`,`qt-msg`),d=ae(t,{maxWidth:U(),lineHeight:1,maxLines:i},H);if(d.lineCount<=1?ce(u,t):d.lines.forEach((e,t)=>{let n=K(`span`,`qt-line`),r=e.text;t===d.lines.length-1&&d.truncated&&!r.endsWith(`…`)&&(r+=`…`),ce(n,r),u.appendChild(n)}),l.appendChild(u),a){let e=K(`div`,`qt-desc`);e.textContent=a,l.appendChild(e)}if(s.appendChild(l),o){let t=K(`button`,`qt-action`);t.type=`button`,t.textContent=o.label,t.addEventListener(`click`,t=>{t.stopPropagation(),this.dismiss(e),o.onClick()}),s.appendChild(t)}if(r){let t=K(`button`,`qt-close`,`<svg width="10" height="10" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round"><path d="M18 6 6 18M6 6l12 12"/></svg>`);t.type=`button`,t.setAttribute(`aria-label`,`关闭通知`),t.addEventListener(`click`,t=>{t.stopPropagation(),this.dismiss(e)}),s.appendChild(t)}return r&&s.addEventListener(`click`,t=>{t.target.closest(`.qt-close, .qt-action`)||this.dismiss(e)}),s}mount(e){e.duration===0&&this.evictPersistIfNeeded(e);let t=this.ensureContainer(e.position);this.toasts.set(e.id,e),t.appendChild(e.element),e.type===`error`&&this.opts.vibrate&&de(),requestAnimationFrame(()=>{requestAnimationFrame(()=>{e.element.classList.add(`qt-enter`)})}),e.duration>0&&(e.timer=setTimeout(()=>this.dismiss(e.id),e.duration))}evictPersistIfNeeded(e){let t=this.opts.persistMaxVisible;if(t<=0)return;let n=[...this.toasts.values()].filter(t=>t.position===e.position&&t.duration===0);for(;n.length>=t;){n.sort((e,t)=>e.order-t.order);let e=n.shift();if(!e)break;this._exit(e)}}_exit(e){e.timer&&=(clearTimeout(e.timer),null),e.element.classList.remove(`qt-enter`),e.element.classList.add(`qt-exit`);let t=()=>{e.element.remove(),this.toasts.delete(e.id),this._dequeue()};if(oe)t();else{let n=!1,r=()=>{n||(n=!0,t())};e.element.addEventListener(`transitionend`,r,{once:!0}),setTimeout(r,400)}}_dequeue(){if(!this.queue.length||this.toasts.size>=this.opts.maxVisible)return;let e=this.queue.shift();this.mount(e)}},pe=null;function q(){return pe||=new fe,pe}var me=Object.assign((e,t)=>q().show(e,t),{info:(e,t)=>q().info(e,t),success:(e,t)=>q().success(e,t),warn:(e,t)=>q().warn(e,t),error:(e,t)=>q().error(e,t),promise:(e,t,n)=>q().promise(e,t,n),dismiss:e=>q().dismiss(e),dismissAll:()=>q().dismissAll(),configure:e=>q().configure(e)}),he=new Set,ge=null;function _e(e){ge=e}function J(e,t=`error`,n){let r={persist:!0,...n};if(he.size>0){for(let n of he)n(e,t,r);return}if(ge){ge(e,t,r);return}t===`success`?me.success(e,r):t===`info`?me.info(e,r):me.error(e,r)}function ve(e){return he.add(e),()=>{he.delete(e)}}var ye=e.c({ImageUploadDialog:()=>be}),be=({open:e,onClose:t,onInsert:r,validate:o})=>{let[s,c]=(0,i.useState)(`upload`),[l,u]=(0,i.useState)(!1),[d,f]=(0,i.useState)(!1),[p,m]=(0,i.useState)(null),[h,g]=(0,i.useState)(null),[_,v]=(0,i.useState)(``),[y,b]=(0,i.useState)(null),x=(0,i.useRef)(null),S=(()=>{try{let e=n.n();return{name:e.name,type:e.type}}catch{return{name:`未配置`,type:`none`}}})(),C=(0,i.useCallback)(()=>{u(!1),m(null),g(null),b(null),v(``),f(!1)},[]),w=(0,i.useCallback)(()=>{C(),t()},[C,t]),T=(0,i.useCallback)(async e=>{let t=e.name.split(`.`).pop()?.toLowerCase();if(!t||![`png`,`jpg`,`jpeg`,`gif`,`webp`,`svg`,`bmp`,`avif`].includes(t)){m(`不支持的图片格式: ${t||`未知`}`);return}let r=o?o(e):e.size>20*1024*1024?`图片大小不能超过 20MB`:null;if(r){m(r),J(r);return}f(!0),m(null);let i=URL.createObjectURL(e);g(i);try{let t=await n.n().upload(e,`editor`);URL.revokeObjectURL(i),b(t),g(t)}catch(e){m(e instanceof Error?e.message:`上传失败`),URL.revokeObjectURL(i),g(null)}finally{f(!1)}},[o]),E=(0,i.useCallback)(e=>{let t=e.target.files?.[0];t&&T(t)},[T]),D=(0,i.useCallback)(e=>{e.preventDefault(),u(!1);let t=e.dataTransfer.files[0];t&&T(t)},[T]),O=(0,i.useCallback)(e=>{let t=e.clipboardData.items;for(let n of Array.from(t))if(n.type.startsWith(`image/`)){e.preventDefault();let t=n.getAsFile();t&&T(t);return}},[T]),k=(0,i.useCallback)(()=>{_.trim()&&(r(_.trim()),w())},[_,r,w]),A=(0,i.useCallback)(()=>{y&&(r(y),w())},[y,r,w]);return e?(0,a.jsxs)(`div`,{className:`fixed inset-0 z-[9999] flex items-center justify-center`,children:[(0,a.jsx)(`div`,{className:`absolute inset-0 bg-black/40 backdrop-blur-sm`,onClick:w}),(0,a.jsxs)(`div`,{className:`relative w-[calc(100vw-2rem)] max-w-[420px] max-h-[90dvh] bg-background rounded-2xl shadow-2xl border border-default-200 overflow-hidden animate-in`,onPaste:s===`upload`?O:void 0,children:[(0,a.jsxs)(`div`,{className:`flex items-center justify-between px-5 py-4 border-b border-default-100`,children:[(0,a.jsx)(`h2`,{className:`text-base font-semibold`,children:`插入图片`}),(0,a.jsx)(`button`,{type:`button`,className:`w-7 h-7 flex items-center justify-center rounded-lg text-default-400 hover:text-default-600 hover:bg-default-100 transition-colors`,onClick:w,children:`✕`})]}),(0,a.jsx)(`div`,{className:`flex border-b border-default-100 px-5`,children:[`upload`,`url`].map(e=>(0,a.jsx)(`button`,{type:`button`,className:`px-4 py-2.5 text-sm font-medium transition-colors border-b-2 -mb-[1px] ${s===e?`border-primary text-primary`:`border-transparent text-default-400 hover:text-default-600`}`,onClick:()=>{c(e),m(null)},children:e===`upload`?`上传图片`:`图片链接`},e))}),(0,a.jsx)(`div`,{className:`p-5`,children:s===`upload`?(0,a.jsxs)(`div`,{className:`space-y-4`,children:[(0,a.jsxs)(`div`,{className:`flex items-center gap-2 px-3 py-2 rounded-lg bg-default-50 text-xs text-default-500`,children:[(0,a.jsx)(`span`,{className:`w-1.5 h-1.5 rounded-full bg-green-500`}),`存储服务:`,S.name]}),!h&&(0,a.jsxs)(`div`,{className:`relative flex flex-col items-center justify-center gap-3 py-10 px-4 rounded-xl border-2 border-dashed transition-all cursor-pointer ${l?`border-primary bg-primary/5 scale-[1.01]`:`border-default-200 hover:border-default-300 hover:bg-default-50`}`,onDragOver:e=>{e.preventDefault(),u(!0)},onDragLeave:()=>u(!1),onDrop:D,onClick:()=>x.current?.click(),children:[(0,a.jsx)(`div`,{className:`w-14 h-14 rounded-full bg-default-100 flex items-center justify-center`,children:(0,a.jsx)(`svg`,{className:`w-7 h-7 text-default-400`,fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,strokeWidth:1.5,children:(0,a.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M3 16.5v2.25A2.25 2.25 0 005.25 21h13.5A2.25 2.25 0 0021 18.75V16.5m-13.5-9L12 3m0 0l4.5 4.5M12 3v13.5`})})}),(0,a.jsxs)(`div`,{className:`text-center`,children:[(0,a.jsx)(`p`,{className:`text-sm font-medium text-default-700`,children:l?`松开放入`:`拖拽图片到此处`}),(0,a.jsx)(`p`,{className:`text-xs text-default-400 mt-1`,children:`或点击选择文件 · 支持粘贴图片`}),(0,a.jsx)(`p`,{className:`text-[10px] text-default-300 mt-1`,children:`PNG / JPG / GIF / WebP / AVIF · 最大 20MB`})]}),(0,a.jsx)(`input`,{ref:x,type:`file`,accept:`image/*`,className:`hidden`,onChange:E})]}),h&&(0,a.jsxs)(`div`,{className:`space-y-3`,children:[(0,a.jsxs)(`div`,{className:`relative rounded-xl overflow-hidden bg-default-100`,children:[(0,a.jsx)(`img`,{src:h,alt:`预览`,className:`w-full max-h-48 object-contain`}),d&&(0,a.jsx)(`div`,{className:`absolute inset-0 bg-black/40 flex items-center justify-center`,children:(0,a.jsxs)(`div`,{className:`flex flex-col items-center gap-2`,children:[(0,a.jsx)(`div`,{className:`w-8 h-8 border-2 border-white border-t-transparent rounded-full animate-spin`}),(0,a.jsx)(`span`,{className:`text-white text-xs`,children:`上传中…`})]})})]}),y&&!d&&(0,a.jsxs)(`div`,{className:`flex items-center gap-2 px-3 py-2 rounded-lg bg-green-50 text-xs text-green-700`,children:[(0,a.jsx)(`svg`,{className:`w-4 h-4 shrink-0`,fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,strokeWidth:2,children:(0,a.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M5 13l4 4L19 7`})}),`上传成功,已存储至 `,S.name]}),(0,a.jsxs)(`div`,{className:`flex gap-2`,children:[(0,a.jsx)(`button`,{type:`button`,className:`flex-1 py-2 rounded-xl bg-primary text-white text-sm font-medium disabled:opacity-40 transition-opacity`,disabled:!y||d,onClick:A,children:`插入图片`}),(0,a.jsx)(`button`,{type:`button`,className:`px-4 py-2 rounded-xl border border-default-200 text-sm hover:bg-default-50 transition-colors`,onClick:C,disabled:d,children:`重新选择`})]})]}),p&&(0,a.jsxs)(`div`,{className:`flex items-start gap-2 px-3 py-2.5 rounded-lg bg-danger-50 text-sm text-danger`,children:[(0,a.jsx)(`svg`,{className:`w-4 h-4 shrink-0 mt-0.5`,fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,strokeWidth:2,children:(0,a.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-2.5L13.732 4c-.77-.833-2.694-.833-3.464 0L3.34 16.5c-.77.833.192 2.5 1.732 2.5z`})}),(0,a.jsx)(`span`,{children:p})]})]}):(0,a.jsxs)(`div`,{className:`space-y-4`,children:[(0,a.jsxs)(`div`,{children:[(0,a.jsx)(`label`,{className:`block text-xs text-default-500 mb-1.5`,children:`图片链接地址`}),(0,a.jsx)(`input`,{type:`url`,className:`w-full px-3 py-2.5 rounded-xl border border-default-200 bg-background text-sm focus:outline-none focus:border-primary transition-colors`,placeholder:`https://example.com/image.png`,value:_,onChange:e=>v(e.target.value),onKeyDown:e=>{e.key===`Enter`&&k()}})]}),_&&(0,a.jsx)(`div`,{className:`rounded-xl overflow-hidden bg-default-100`,children:(0,a.jsx)(`img`,{src:_,alt:`预览`,className:`w-full max-h-40 object-contain`,onError:e=>{e.target.style.display=`none`}})}),(0,a.jsx)(`button`,{type:`button`,className:`w-full py-2.5 rounded-xl bg-primary text-white text-sm font-medium disabled:opacity-40 transition-opacity`,disabled:!_.trim(),onClick:k,children:`插入图片`})]})}),(0,a.jsxs)(`div`,{className:`px-5 py-3 border-t border-default-100 text-[11px] text-default-300 text-center`,children:[`图片将上传至 `,S.name]})]})]}):null};function xe(e,t){return`${e.trim().toLowerCase().replace(/[^\p{L}\p{N}\s-]/gu,``).replace(/\s+/g,`-`).slice(0,40)||`heading`}-${t}`}function Se(e){let t=[],n=[];for(let r of e){let e={...r,children:[]};for(;n.length>0&&n[n.length-1].level>=e.level;)n.pop();n.length>0?n[n.length-1].children.push(e):t.push(e),n.push(e)}return t}function Ce(e){let t=new Set,n=e=>{for(let r of e)r.children.length>0&&(t.add(r.id),n(r.children))};return n(e),t}function we(e,t){let n=[];for(let r of e)n.push(r),r.children.length>0&&!t.has(r.id)&&n.push(...we(r.children,t));return n}function Te(e,t){let n=t.toLowerCase(),r=e=>{let t=[];for(let i of e){let e=i.text.toLowerCase().includes(n),a=r(i.children);(e||a.length>0)&&t.push({...i,children:e?i.children:a})}return t};return r(e)}function Ee(e){let t=e.parentElement;for(;t&&t!==document.documentElement;){let e=getComputedStyle(t).overflowY;if((e===`auto`||e===`scroll`||e===`overlay`)&&t.scrollHeight>t.clientHeight)return t;t=t.parentElement}return null}function De(e){if(e.isDestroyed)return null;try{return e.view.dom}catch{return null}}function Y(e,t){if(!t)return e;let n=e.toLowerCase(),r=t.toLowerCase(),i=[],o=0,s=0;for(;;){let c=n.indexOf(r,o);if(c===-1)break;c>o&&i.push(e.slice(o,c)),i.push((0,a.jsx)(`mark`,{className:`toc-highlight`,children:e.slice(c,c+t.length)},`hl-${s++}`)),o=c+t.length}return o<e.length&&i.push(e.slice(o)),i.length?i:e}var Oe=84,ke=3e3,Ae=({editor:e,className:t=``,onClose:n})=>{let[r,o]=(0,i.useState)([]),[s,c]=(0,i.useState)(``),[l,u]=(0,i.useState)(new Set),[d,f]=(0,i.useState)(``),p=(0,i.useRef)(``),m=(0,i.useRef)([]),h=(0,i.useRef)(null),g=(0,i.useRef)(null),_=(0,i.useRef)(null),v=(0,i.useRef)(0),y=(0,i.useCallback)(()=>{_.current&&=(clearTimeout(_.current.timer),null)},[]),b=(0,i.useCallback)(()=>{let t=De(e);return t?Array.from(t.querySelectorAll(`h1,h2,h3,h4,h5,h6`)).map((e,t)=>(e.id||=xe(e.textContent||``,t),{id:e.id,level:Number(e.tagName.slice(1)),text:e.textContent?.trim()||`(无标题)`,el:e})):[]},[e]),x=(0,i.useCallback)(()=>{let e=m.current;if((!e.length||e.some(e=>!e.el.isConnected))&&(e=b(),m.current=e),!e.length)return;let t=g.current,n=(t?t.getBoundingClientRect().top:0)+Oe,r=t?t.scrollHeight-t.scrollTop-t.clientHeight<2:document.documentElement.scrollHeight-window.scrollY-window.innerHeight<2,i=``;for(let t of e)t.el.isConnected&&t.el.getBoundingClientRect().top<=n&&(i=t.id);if(r){for(let t=e.length-1;t>=0;t--)if(e[t].el.isConnected){i=e[t].id;break}}let a=_.current;if(a){let t=e.find(e=>e.id===a.id);if(!(!t||!t.el.isConnected||r||t.el.getBoundingClientRect().top<=n))return;y()}c(i)},[b,y]),S=(0,i.useCallback)(()=>{v.current||=requestAnimationFrame(()=>{v.current=0,x()})},[x]),C=(0,i.useCallback)(()=>{let e=b(),t=e.map(e=>`${e.level}:${e.text}`).join(`|`);t!==p.current&&(p.current=t,m.current=e,o(e),S())},[b,S]);(0,i.useEffect)(()=>{let t=De(e),n=t?Ee(t):null;g.current=n;let r=n??window;return r.addEventListener(`scroll`,S,{passive:!0}),window.addEventListener(`resize`,S),r.addEventListener(`wheel`,y,{passive:!0}),r.addEventListener(`touchstart`,y,{passive:!0}),()=>{r.removeEventListener(`scroll`,S),window.removeEventListener(`resize`,S),r.removeEventListener(`wheel`,y),r.removeEventListener(`touchstart`,y)}},[e,S,y]),(0,i.useEffect)(()=>{let t=null,n=()=>{let n=[];e.state.doc.descendants(e=>{e.type.name===`heading`&&n.push(`${e.attrs.level}:${e.textContent}`)}),n.join(`|`)!==p.current&&(t&&clearTimeout(t),t=setTimeout(C,300))};e.on(`update`,n);let r=requestAnimationFrame(C);return()=>{e.off(`update`,n),t&&clearTimeout(t),cancelAnimationFrame(r),y(),v.current&&=(cancelAnimationFrame(v.current),0)}},[e,C,y]);let w=(0,i.useCallback)(t=>{let n=De(e);if(!n)return;let r=t.el;if((!r||!n.contains(r))&&(r=n.querySelector(`[id="${CSS.escape(t.id)}"]`)),!r){let e=`h${t.level}`,i=n.querySelectorAll(e);for(let e of i)if(e.textContent?.trim()===t.text){r=e;break}}if(!r)return;y(),_.current={id:t.id,timer:setTimeout(y,ke)},c(t.id);let i=g.current,a=r.getBoundingClientRect().top;if(i){let e=i.getBoundingClientRect().top;i.scrollTo({top:i.scrollTop+a-e-Oe,behavior:`smooth`})}else window.scrollTo({top:window.scrollY+a-Oe,behavior:`smooth`})},[e,y]),T=(0,i.useMemo)(()=>Se(r),[r]),E=(0,i.useMemo)(()=>Ce(T),[T]),D=(0,i.useMemo)(()=>{let e=new Map,t=(n,r)=>{for(let i of n)r&&e.set(i.id,r),t(i.children,i.id)};return t(T,``),e},[T]),O=d.trim().length>0,k=(0,i.useMemo)(()=>O?Te(T,d.trim()):T,[T,O,d]),A=(0,i.useMemo)(()=>we(k,O?new Set:l),[k,l,O]),j=(0,i.useMemo)(()=>new Set(A.map(e=>e.id)),[A]),M=(0,i.useMemo)(()=>{let e=s;for(;e&&!j.has(e);)e=D.get(e)??``;return e},[s,j,D]);(0,i.useEffect)(()=>{let e=h.current;if(!e||!M)return;let t=e.closest(`.toc-scroll`);if(!(t instanceof HTMLElement))return;let n=e.querySelector(`[data-toc-id="${CSS.escape(M)}"]`);if(!n)return;let r=t.getBoundingClientRect(),i=n.getBoundingClientRect();i.top<r.top+8?t.scrollTop-=r.top+8-i.top:i.bottom>r.bottom-8&&(t.scrollTop+=i.bottom-(r.bottom-8))},[M]);let N=(0,i.useCallback)(e=>{u(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},[]),P=(0,i.useCallback)(()=>{u(new Set(E))},[E]),F=(0,i.useCallback)(()=>{u(new Set)},[]);return r.length?(0,a.jsxs)(`nav`,{ref:h,className:`toc-panel ${t}`,"aria-label":`目录`,children:[(0,a.jsxs)(`div`,{className:`toc-title`,children:[n?(0,a.jsx)(`button`,{type:`button`,className:`toc-close-btn`,onClick:n,title:`收起目录`,"aria-label":`收起目录`,children:(0,a.jsxs)(`svg`,{width:`15`,height:`15`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,"aria-hidden":`true`,children:[(0,a.jsx)(`rect`,{x:`3`,y:`3`,width:`18`,height:`18`,rx:`2`}),(0,a.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M9 3v18`}),(0,a.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`m16 15-3-3 3-3`})]})}):(0,a.jsx)(`span`,{className:`toc-title__icon`,"aria-hidden":`true`,children:(0,a.jsx)(`svg`,{width:`14`,height:`14`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,children:(0,a.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M4 6h16M4 12h10M4 18h7`})})}),(0,a.jsx)(`span`,{className:`toc-title__text`,children:`目录`}),(0,a.jsxs)(`div`,{className:`toc-actions`,children:[(0,a.jsx)(`button`,{type:`button`,className:`toc-action-btn`,onClick:P,title:`全部折叠`,"aria-label":`全部折叠`,disabled:O,children:(0,a.jsx)(`svg`,{width:`14`,height:`14`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,"aria-hidden":`true`,children:(0,a.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M5 12h14`})})}),(0,a.jsx)(`button`,{type:`button`,className:`toc-action-btn`,onClick:F,title:`全部展开`,"aria-label":`全部展开`,disabled:O,children:(0,a.jsx)(`svg`,{width:`14`,height:`14`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,"aria-hidden":`true`,children:(0,a.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M12 5v14M5 12h14`})})})]})]}),(0,a.jsxs)(`div`,{className:`toc-search`,children:[(0,a.jsx)(`svg`,{className:`toc-search__icon`,width:`13`,height:`13`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,"aria-hidden":`true`,children:(0,a.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M21 21l-4.35-4.35M17 11a6 6 0 11-12 0 6 6 0 0112 0z`})}),(0,a.jsx)(`input`,{type:`text`,className:`toc-search__input`,placeholder:`搜索标题...`,value:d,onChange:e=>f(e.target.value),"aria-label":`搜索标题`}),d&&(0,a.jsx)(`button`,{type:`button`,className:`toc-search__clear`,onClick:()=>f(``),title:`清除`,"aria-label":`清除搜索`,children:(0,a.jsx)(`svg`,{width:`12`,height:`12`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,"aria-hidden":`true`,children:(0,a.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M6 18L18 6M6 6l12 12`})})})]}),A.length===0?(0,a.jsx)(`div`,{className:`toc-search__empty`,children:O?`未找到"${d.trim()}"相关标题`:`文档暂无标题`}):(0,a.jsx)(`ul`,{className:`toc-list`,children:A.map(e=>{let t=E.has(e.id),n=l.has(e.id);return(0,a.jsxs)(`li`,{"data-toc-id":e.id,className:`toc-item ${M===e.id?`is-active`:``}`,style:{paddingLeft:`${(e.level-1)*12+12}px`},children:[t?(0,a.jsx)(`button`,{type:`button`,className:`toc-toggle ${n?`is-collapsed`:`is-expanded`}`,onClick:t=>{t.stopPropagation(),N(e.id)},title:n?`展开子标题`:`折叠子标题`,"aria-label":n?`展开子标题`:`折叠子标题`,"aria-expanded":!n,children:(0,a.jsx)(`svg`,{width:`10`,height:`10`,viewBox:`0 0 24 24`,fill:`currentColor`,"aria-hidden":`true`,children:(0,a.jsx)(`path`,{d:`M8 5v14l11-7z`})})}):(0,a.jsx)(`span`,{className:`toc-bullet`,"aria-hidden":!0}),(0,a.jsx)(`button`,{type:`button`,className:`toc-link`,onClick:()=>w(e),title:e.text,children:(0,a.jsx)(`span`,{className:`toc-text`,children:O?Y(e.text,d.trim()):e.text})})]},e.id)})})]}):(0,a.jsxs)(`div`,{className:`toc-panel ${t}`,style:{padding:`24px 16px`,textAlign:`center`},children:[(0,a.jsx)(`div`,{className:`toc-empty`,children:`文档暂无标题`}),(0,a.jsx)(`div`,{className:`toc-empty-hint`,children:`使用 # 标记可创建标题`})]})};function je(e,t){return{continue:`你是一个写作助手。请从下文尾部自然流畅地续写内容,保持风格一致。只输出续写的内容,不要加任何前缀说明。`,improve:`你是一个文字润色专家。请优化以下文本的表达,提升文采和流畅度,保持原意不变。只输出润色后的文本。`,shorter:`你是一个精简专家。请将以下文本精简,保留核心信息,删除冗余。只输出精简后的文本。`,longer:`你是一个内容扩写专家。请丰富以下文本的细节和层次,增加深度。只输出扩写后的文本。`,fix:`你是一个校对专家。请修正以下文本中的语法错误、错别字和标点问题。只输出修正后的文本。`,translate:`你是一个翻译专家。请将以下文本翻译为英文。只输出翻译后的文本。`,zap:t||`你是一个全能的 AI 写作助手。请根据用户的指令处理文本。`}[e]}var Me=null;async function Ne(e){let t;try{({createOpenAI:t}=await import(`@ai-sdk/openai`))}catch{throw Error(`缺少可选依赖 @ai-sdk/openai。使用默认 provider 请先安装:npm i @ai-sdk/openai;或调用 setAIProvider() 注册自定义 provider。`)}let n=t({apiKey:e.apiKey,baseURL:e.baseURL}).chat(e.model);return{async*stream(e){let t=await(0,o.streamText)({model:n,system:je(e.mode,e.instruction),prompt:e.context,temperature:.7,maxOutputTokens:2048});for await(let e of t.textStream)yield e},async generate(e){return(await(0,o.generateText)({model:n,system:je(e.mode,e.instruction),prompt:e.context,temperature:.7,maxOutputTokens:2048})).text}}}function Pe(e){Me=e}function X(){if(!Me)throw Error(`未配置 AI 服务。请调用 createAILanguageModelProvider() 创建并通过 setAIProvider() 注册。`);return Me}function Fe(e){let{apiKey:t,baseURL:n,model:r,headers:i}=e;async function*a(e,a){let o=await fetch(`${n}/chat/completions`,{method:`POST`,headers:{"Content-Type":`application/json`,Authorization:`Bearer ${t}`,...i},body:JSON.stringify({model:r,messages:[{role:`system`,content:e},{role:`user`,content:a}],stream:!0,temperature:.7,max_tokens:2048})});if(!o.ok){let e=await o.text();throw Error(`AI API 错误 (${o.status}): ${e}`)}let s=o.body?.getReader();if(!s)throw Error(`无法读取响应流`);let c=new TextDecoder,l=``;for(;;){let{done:e,value:t}=await s.read();if(e)break;l+=c.decode(t,{stream:!0});let n=l.split(`
|
|
3
|
-
`);l=n.pop()||``;for(let e of n){let t=e.trim();if(!t||!t.startsWith(`data: `))continue;let n=t.slice(6);if(n===`[DONE]`)return;try{let e=JSON.parse(n).choices?.[0]?.delta?.content;e&&(yield e)}catch{}}}}return{async*stream(e){yield*a(je(e.mode,e.instruction),e.context)},async generate(e){let t=je(e.mode,e.instruction),n=``;for await(let r of a(t,e.context))n+=r;return n}}}function Ie(e){return Fe({apiKey:e.apiKey,baseURL:e.baseURL||`https://api.deepseek.com/v1`,model:e.model||`deepseek-v4-flash`,headers:e.headers})}function Le(e){return Fe({apiKey:e.apiKey,baseURL:e.baseURL||`https://api.openai.com/v1`,model:e.model||`gpt-5.6-luna`,headers:e.headers})}function Re(e){return Fe({apiKey:e.apiKey,baseURL:e.baseURL||`https://dashscope.aliyuncs.com/compatible-mode/v1`,model:e.model||`qwen3.7-plus`,headers:e.headers})}var ze={keyword:``,caseSensitive:!1,wholeWord:!1,matches:[],currentIndex:-1},Z=new f.PluginKey(`search-highlight`);function Be(e){return e.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`)}function Ve(e,t){let{keyword:n,caseSensitive:r,wholeWord:i}=t;if(!n)return[];let a=r?`g`:`gi`,o=i?`\\b${Be(n)}\\b`:Be(n),s=new RegExp(o,a),c=[];return e.descendants((e,t)=>{if(!e.isText||!e.text)return;s.lastIndex=0;let n;for(;(n=s.exec(e.text))!==null;){let e=t+n.index,r=e+n[0].length;c.push({from:e,to:r}),n[0].length===0&&s.lastIndex++}}),c}function He(e,t){if(t.matches.length===0)return p.DecorationSet.empty;let n=t.matches.map((e,n)=>p.Decoration.inline(e.from,e.to,{class:n===t.currentIndex?`search-highlight search-highlight--active`:`search-highlight`}));return p.DecorationSet.create(e,n)}function Ue(e,t){if(t.currentIndex<0||t.currentIndex>=t.matches.length)return;let n=t.matches[t.currentIndex];n&&requestAnimationFrame(()=>{try{let t=e.dom.querySelector(`.search-highlight--active`);if(t){let e=t.getBoundingClientRect(),n=window.innerHeight-80;(e.top<120||e.bottom>n)&&t.scrollIntoView({behavior:`smooth`,block:`center`});return}let r=e.coordsAtPos(n.from),i=window.innerHeight-80;if(r.top<120||r.top>i){let e=r.top-window.innerHeight/2;window.scrollBy({top:e,behavior:`smooth`})}}catch{}})}var We=d.Extension.create({name:`searchHighlight`,addProseMirrorPlugins(){return[new f.Plugin({key:Z,state:{init:()=>ze,apply(e,t){let n=e.getMeta(Z);if(n)return{...t,...n,matches:n.matches===void 0?t.matches:n.matches,currentIndex:n.currentIndex===void 0?t.currentIndex:n.currentIndex};if(e.docChanged&&t.keyword){let n=Ve(e.doc,t),r=t.currentIndex;return r>=n.length&&(r=n.length-1),r<0&&(r=n.length>0?0:-1),{...t,matches:n,currentIndex:r}}return t}},props:{decorations(e){let t=Z.getState(e);return t?He(e.doc,t):p.DecorationSet.empty}}})]},addCommands(){return{setSearch:(e,t={})=>({state:n,dispatch:r,view:i})=>{let a=Z.getState(n)||ze,o={keyword:e,caseSensitive:t.caseSensitive??a.caseSensitive,wholeWord:t.wholeWord??a.wholeWord,matches:[],currentIndex:-1};return o.matches=Ve(n.doc,o),o.currentIndex=o.matches.length>0?0:-1,r&&(r(n.tr.setMeta(Z,o)),i&&Ue(i,o)),!0},nextMatch:()=>({state:e,dispatch:t,view:n})=>{let r=Z.getState(e)||ze;if(r.matches.length===0)return!1;let i=(r.currentIndex+1)%r.matches.length;return t&&(t(e.tr.setMeta(Z,{currentIndex:i})),n&&Ue(n,{...r,currentIndex:i})),!0},prevMatch:()=>({state:e,dispatch:t,view:n})=>{let r=Z.getState(e)||ze;if(r.matches.length===0)return!1;let i=(r.currentIndex-1+r.matches.length)%r.matches.length;return t&&(t(e.tr.setMeta(Z,{currentIndex:i})),n&&Ue(n,{...r,currentIndex:i})),!0},clearSearch:()=>({state:e,dispatch:t})=>(t&&t(e.tr.setMeta(Z,ze)),!0)}}});function Ge(e){let t=e.state;return Z.getState(t)||ze}var Ke=({editor:e,onClose:t})=>{let[n,r]=(0,i.useState)(``),[o,s]=(0,i.useState)(!1),[c,l]=(0,i.useState)(!1),[u,d]=(0,i.useState)(0),f=(0,i.useRef)(null),p=(0,i.useRef)({keyword:n,caseSensitive:o,wholeWord:c});p.current={keyword:n,caseSensitive:o,wholeWord:c},(0,i.useEffect)(()=>{if(!e)return;let t=0,n=()=>{t&&cancelAnimationFrame(t),t=requestAnimationFrame(()=>{t=0,d(e=>(e+1)%1e6)})};return e.on(`update`,n),()=>{e.off(`update`,n),t&&cancelAnimationFrame(t)}},[e]),(0,i.useEffect)(()=>{let e=setTimeout(()=>f.current?.focus(),30);return()=>clearTimeout(e)},[]),(0,i.useEffect)(()=>{if(!e)return;let t=requestAnimationFrame(()=>{let{keyword:t,caseSensitive:n,wholeWord:r}=p.current;try{e.commands.setSearch(t,{caseSensitive:n,wholeWord:r})}catch(e){console.warn(`[SearchBar] setSearch failed:`,e)}});return()=>cancelAnimationFrame(t)},[e,n,o,c]),(0,i.useEffect)(()=>()=>{try{e?.commands.clearSearch()}catch{}},[]),(0,i.useEffect)(()=>{let e=e=>{e.key===`Escape`&&(e.preventDefault(),e.stopPropagation(),t())};return window.addEventListener(`keydown`,e,!0),()=>window.removeEventListener(`keydown`,e,!0)},[t]);let m=(0,i.useCallback)(()=>{try{e?.commands.nextMatch()}catch{}},[e]),h=(0,i.useCallback)(()=>{try{e?.commands.prevMatch()}catch{}},[e]),g=(0,i.useCallback)(e=>{e.stopPropagation(),e.key===`Enter`&&(e.preventDefault(),e.shiftKey?h():m())},[m,h]),_=(0,i.useMemo)(()=>{if(!e)return null;try{return Ge(e)}catch{return null}},[e,n,o,c,u]),v=n?_&&_.matches.length>0?`${_.currentIndex+1} / ${_.matches.length}`:`无匹配`:``,y=(0,i.useCallback)(e=>{e.stopPropagation()},[]);return(0,a.jsx)(`div`,{className:`search-bar`,role:`search`,"aria-label":`文档内搜索`,onClick:y,onMouseDown:y,children:(0,a.jsxs)(`div`,{className:`search-bar__main`,children:[(0,a.jsx)(`svg`,{className:`search-bar__icon`,width:`14`,height:`14`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,children:(0,a.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M21 21l-6-6m2-5a7 7 0 11-14 0 7 7 0 0114 0z`})}),(0,a.jsx)(`input`,{ref:f,type:`text`,className:`search-bar__input`,placeholder:`查找…`,value:n,onChange:e=>r(e.target.value),onKeyDown:g,onKeyUp:y,onKeyPress:y,onInput:y,spellCheck:!1,autoComplete:`off`,inputMode:`text`}),(0,a.jsx)(`span`,{className:`search-bar__count`,children:v}),(0,a.jsx)(`button`,{type:`button`,className:`search-bar__toggle${o?` search-bar__toggle--active`:``}`,onClick:()=>s(e=>!e),title:`区分大小写 (Aa)`,"aria-pressed":o,children:`Aa`}),(0,a.jsx)(`button`,{type:`button`,className:`search-bar__toggle${c?` search-bar__toggle--active`:``}`,onClick:()=>l(e=>!e),title:`整词匹配 (\\b)`,"aria-pressed":c,children:`\\b`}),(0,a.jsx)(`div`,{className:`search-bar__sep`}),(0,a.jsx)(`button`,{type:`button`,className:`search-bar__btn`,onClick:h,title:`上一个 (Shift+Enter)`,disabled:!_||_.matches.length===0,children:(0,a.jsx)(`svg`,{width:`14`,height:`14`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,children:(0,a.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M5 15l7-7 7 7`})})}),(0,a.jsx)(`button`,{type:`button`,className:`search-bar__btn`,onClick:m,title:`下一个 (Enter)`,disabled:!_||_.matches.length===0,children:(0,a.jsx)(`svg`,{width:`14`,height:`14`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,children:(0,a.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M19 9l-7 7-7-7`})})}),(0,a.jsx)(`button`,{type:`button`,className:`search-bar__btn search-bar__btn--close`,onClick:t,title:`关闭 (Esc)`,children:(0,a.jsx)(`svg`,{width:`14`,height:`14`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,children:(0,a.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M6 18L18 6M6 6l12 12`})})})]})})};function Q({children:e,...t}){return(0,a.jsx)(`svg`,{width:16,height:16,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:2,strokeLinecap:`round`,strokeLinejoin:`round`,"aria-hidden":`true`,...t,children:e})}var qe=e=>(0,a.jsxs)(Q,{...e,children:[(0,a.jsx)(`path`,{d:`M6 4h8a4 4 0 0 1 0 8H6z`}),(0,a.jsx)(`path`,{d:`M6 12h9a4 4 0 0 1 0 8H6z`})]}),Je=e=>(0,a.jsxs)(Q,{...e,children:[(0,a.jsx)(`path`,{d:`M19 4h-9`}),(0,a.jsx)(`path`,{d:`M14 20H5`}),(0,a.jsx)(`path`,{d:`M15 4 9 20`})]}),Ye=e=>(0,a.jsxs)(Q,{...e,children:[(0,a.jsx)(`path`,{d:`M6 4v6a6 6 0 0 0 12 0V4`}),(0,a.jsx)(`path`,{d:`M4 20h16`})]}),Xe=e=>(0,a.jsxs)(Q,{...e,children:[(0,a.jsx)(`path`,{d:`M16 4H9a3 3 0 0 0-2.83 4`}),(0,a.jsx)(`path`,{d:`M14 12a4 4 0 0 1 0 8H6`}),(0,a.jsx)(`path`,{d:`M4 12h16`})]}),Ze=e=>(0,a.jsxs)(Q,{...e,children:[(0,a.jsx)(`path`,{d:`m16 18 6-6-6-6`}),(0,a.jsx)(`path`,{d:`m8 6-6 6 6 6`})]}),Qe=e=>(0,a.jsxs)(Q,{...e,children:[(0,a.jsx)(`path`,{d:`m9 11-6 6v3h9l3-3`}),(0,a.jsx)(`path`,{d:`m22 12-4.6 4.6a2 2 0 0 1-2.8 0l-5.2-5.2a2 2 0 0 1 0-2.8L14 4`})]}),$e=e=>(0,a.jsxs)(Q,{...e,children:[(0,a.jsx)(`path`,{d:`M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71`}),(0,a.jsx)(`path`,{d:`M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71`})]}),et=e=>(0,a.jsxs)(Q,{...e,children:[(0,a.jsx)(`rect`,{x:`3`,y:`3`,width:`18`,height:`18`,rx:`2`,ry:`2`}),(0,a.jsx)(`path`,{d:`M3 9h18M3 15h18M9 3v18M15 3v18`})]}),tt=e=>(0,a.jsxs)(Q,{...e,children:[(0,a.jsx)(`rect`,{x:`8`,y:`8`,width:`14`,height:`14`,rx:`2`,ry:`2`}),(0,a.jsx)(`path`,{d:`M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2`})]}),nt=e=>(0,a.jsxs)(Q,{...e,children:[(0,a.jsx)(`circle`,{cx:`11`,cy:`11`,r:`8`}),(0,a.jsx)(`path`,{d:`m21 21-4.3-4.3`})]}),rt=e=>(0,a.jsxs)(Q,{...e,children:[(0,a.jsx)(`path`,{d:`M12 3l1.6 4.4L18 9l-4.4 1.6L12 15l-1.6-4.4L6 9l4.4-1.6L12 3z`}),(0,a.jsx)(`path`,{d:`M18.5 14l.7 1.9 1.9.7-1.9.7-.7 1.9-.7-1.9-1.9-.7 1.9-.7.7-1.9z`})]}),it=e=>(0,a.jsxs)(Q,{...e,children:[(0,a.jsx)(`circle`,{cx:`5`,cy:`12`,r:`1`}),(0,a.jsx)(`circle`,{cx:`12`,cy:`12`,r:`1`}),(0,a.jsx)(`circle`,{cx:`19`,cy:`12`,r:`1`})]}),at=e=>(0,a.jsxs)(Q,{...e,children:[(0,a.jsx)(`path`,{d:`M18 6 6 18`}),(0,a.jsx)(`path`,{d:`m6 6 12 12`})]});async function ot(e){if(e){if(e.startsWith(`blob:`)){URL.revokeObjectURL(e);return}try{await n.n().remove(e)}catch(e){console.warn(`删除存储资源失败:`,e)}}}var st=3e4,ct=new Set([`image`,`attachmentEmbed`,`audioEmbed`,`videoEmbed`]),lt=new WeakMap;function ut(e){let t=new Set;return e.state.doc.descendants(e=>{if(ct.has(e.type.name)){let n=e.attrs.src;n&&t.add(n)}return!0}),t}function dt(e){let t=lt.get(e);return t||(t={timers:new Map,onTransaction:()=>{},listening:!1},lt.set(e,t)),t}function ft(e,t){let n=[...new Set(t.filter(Boolean))];if(n.length===0)return;let r=dt(e);r.listening||=(r.onTransaction=()=>{if(r.timers.size===0)return;let t=ut(e);for(let[e,n]of r.timers)t.has(e)&&(clearTimeout(n),r.timers.delete(e))},e.on(`transaction`,r.onTransaction),!0);for(let t of n){if(r.timers.has(t))continue;let n=setTimeout(()=>{ut(e).has(t)||ot(t),r.timers.delete(t)},st);r.timers.set(t,n)}}function pt(e){let t=lt.get(e);if(t){if(t.listening&&=(e.off(`transaction`,t.onTransaction),!1),t.timers.size>0){let n=ut(e);for(let[e,r]of t.timers)clearTimeout(r),n.has(e)||ot(e);t.timers.clear()}lt.delete(e)}}var mt=[{mode:`continue`,labelKey:`editor.ai.continue`,descKey:`editor.ai.continueDesc`,icon:`→`},{mode:`improve`,labelKey:`editor.ai.improve`,descKey:`editor.ai.improveDesc`,icon:`✨`},{mode:`shorter`,labelKey:`editor.ai.shorter`,descKey:`editor.ai.shorterDesc`,icon:`↓`},{mode:`longer`,labelKey:`editor.ai.longer`,descKey:`editor.ai.longerDesc`,icon:`↑`},{mode:`fix`,labelKey:`editor.ai.fix`,descKey:`editor.ai.fixDesc`,icon:`✓`},{mode:`translate`,labelKey:`editor.ai.translate`,descKey:`editor.ai.translateDesc`,icon:`🌐`},{mode:`zap`,labelKey:`editor.ai.zap`,descKey:`editor.ai.zapDesc`,icon:`⚡`}],ht=new Set([`image`,`attachmentEmbed`,`audioEmbed`,`videoEmbed`]),gt={image:`editor.ai.nodeImage`,attachmentEmbed:`editor.ai.nodeAttachment`,videoEmbed:`editor.ai.nodeVideo`,audioEmbed:`editor.ai.nodeAudio`};function _t(e,t){return e.storage.qingwuUI?.parseMd?.(e.schema,t)||null}function vt(e,t,n){let r=[];return e.state.doc.nodesBetween(t,n,e=>{if(ht.has(e.type.name)){let t=e.attrs.src;t&&r.push({type:e.type.name,src:t})}return!0}),r}function yt(e){let t=new Set;return e.state.doc.descendants(e=>{if(ht.has(e.type.name)){let n=e.attrs.src;n&&t.add(n)}return!0}),t}function bt(e,t){let n=_t(e,t);if(n&&n.size>0){let t=e.state.tr;t.replaceWith(0,e.state.doc.content.size,n),t.setSelection(f.TextSelection.create(t.doc,t.doc.content.size)),e.view.dispatch(t.scrollIntoView()),e.commands.focus();return}e.commands.setContent(t),e.commands.focus()}function xt(e,t,n,r){let i=_t(e,t);if(e.commands.focus(),!i){let i=e.chain().focus();n===`replace`?i.setTextSelection({from:r.from,to:r.to}).deleteSelection().insertContent(t).run():i.insertContentAt(r.to,t).run();return}let a=e.state.tr;n===`replace`?a.replaceRange(r.from,r.to,new s.Slice(i,0,0)):a.insert(Math.min(r.to,e.state.doc.content.size),i),e.view.dispatch(a.scrollIntoView())}function St({editor:t,onClose:n}){let[r,o]=(0,i.useState)(null),[s,c]=(0,i.useState)(``),[l,u]=(0,i.useState)(``),[d,f]=(0,i.useState)(!1),[p,m]=(0,i.useState)(null),[h,g]=(0,i.useState)(null),_=(0,i.useRef)({from:0,to:0,empty:!0}),v=(0,i.useRef)(null),y=(0,i.useRef)(null),b=(0,i.useRef)(!0),x=(0,i.useCallback)(async e=>{if(o(e),m(null),e!==`zap`){await S(e);return}setTimeout(()=>v.current?.focus(),100)},[t]),S=(0,i.useCallback)(async n=>{let r=t.state.selection;_.current={from:r.from,to:r.to,empty:r.empty},f(!0),u(``),b.current=!0,m(null);try{let e=X(),i=r.empty?t.state.doc.textContent:t.state.doc.textBetween(r.from,r.to),a=[];for await(let t of e.stream({mode:n,context:i,instruction:n===`zap`?s:void 0}))a.push(t),u(a.join(``))}catch(t){m(t instanceof Error?t.message:e.o(`editor.ai.error`))}finally{f(!1)}},[t,s]);(0,i.useEffect)(()=>{let e=y.current;if(!e)return;let t=()=>{let t=e.scrollHeight-e.scrollTop-e.clientHeight<24;b.current=t};return e.addEventListener(`scroll`,t,{passive:!0}),()=>e.removeEventListener(`scroll`,t)},[!!l]),(0,i.useLayoutEffect)(()=>{let e=y.current;!e||!b.current||(e.scrollTop=e.scrollHeight)},[l]);let C=(0,i.useCallback)((e,n,r)=>{let i=new Set(vt(t,r.from,r.to).map(e=>e.src));e===`replaceAll`?bt(t,n):xt(t,n,`replace`,_.current);let a=yt(t);ft(t,[...i].filter(e=>!a.has(e)))},[t]),w=(0,i.useCallback)(e=>{if(e===`below`){xt(t,l,`below`,_.current),n();return}let r=_.current,i=e===`replaceAll`?{from:0,to:t.state.doc.content.size}:{from:r.from,to:r.to},a=vt(t,i.from,i.to);if(a.length>0){g({position:e,willRemove:a});return}C(e,l,i),n()},[t,l,C,n]),T=(0,i.useCallback)(()=>{if(!h)return;let{position:e}=h,r=e===`replaceAll`?{from:0,to:t.state.doc.content.size}:{from:_.current.from,to:_.current.to};C(e,l,r),g(null),n()},[h,t,l,C,n]),E=(0,i.useCallback)(()=>{u(``),o(null),m(null)},[]),D={};for(let e of h?.willRemove??[])D[e.type]=(D[e.type]??0)+1;return(0,a.jsxs)(a.Fragment,{children:[(0,a.jsxs)(`div`,{className:`ai-selector w-full flex-1 min-h-0 flex flex-col`,children:[(0,a.jsxs)(`div`,{className:`flex items-center justify-between pl-3 pr-1.5 py-1.5 border-b border-default-100 shrink-0`,children:[(0,a.jsxs)(`span`,{className:`flex items-center gap-1.5 text-xs font-medium text-default-500`,children:[(0,a.jsx)(rt,{className:`text-primary`}),e.o(`editor.ai.trigger`)]}),(0,a.jsx)(`button`,{type:`button`,onClick:n,"aria-label":e.o(`editor.ai.close`),title:e.o(`editor.ai.close`),className:`flex items-center justify-center w-6 h-6 rounded-md text-default-400 hover:bg-default-100 hover:text-default-700 transition-colors`,children:(0,a.jsx)(at,{})})]}),(0,a.jsx)(`div`,{className:`grid grid-cols-[repeat(auto-fit,minmax(64px,1fr))] gap-1.5 p-2 shrink-0`,children:mt.map(({mode:t,labelKey:n,descKey:i,icon:o})=>(0,a.jsxs)(`button`,{type:`button`,className:`flex flex-col items-center gap-1 px-1 py-2 rounded-xl border transition-colors ${r===t?`border-primary/40 bg-primary/10 text-primary`:`border-default-200 text-default-600 hover:bg-default-100 hover:text-default-900`}`,onClick:()=>x(t),title:e.o(i),children:[(0,a.jsx)(`span`,{className:`text-base leading-none`,children:o}),(0,a.jsx)(`span`,{className:`text-[11px] leading-none truncate`,children:e.o(n)})]},t))}),(0,a.jsxs)(`div`,{className:`px-3 pb-3 flex-1 min-h-0 flex flex-col`,children:[!r&&(0,a.jsx)(`p`,{className:`text-[11px] text-default-400 leading-relaxed`,children:e.o(`editor.ai.triggerDesc`)}),r===`zap`&&!d&&!l&&!p&&(0,a.jsxs)(`div`,{children:[(0,a.jsx)(`input`,{ref:v,className:`w-full px-3 py-2 text-sm border border-default-200 rounded-lg focus:outline-none focus:border-primary bg-background`,placeholder:e.o(`editor.ai.customPlaceholder`),value:s,onChange:e=>c(e.target.value),onKeyDown:e=>{e.key===`Enter`&&s.trim()&&S(`zap`)}}),(0,a.jsxs)(`div`,{className:`flex gap-2 mt-2`,children:[(0,a.jsx)(`button`,{type:`button`,className:`px-3 py-1.5 text-xs bg-primary text-white rounded-lg disabled:opacity-50`,disabled:!s.trim(),onClick:()=>S(`zap`),children:e.o(`editor.ai.confirm`)}),(0,a.jsx)(`button`,{type:`button`,className:`px-3 py-1.5 text-xs border border-default-200 rounded-lg hover:bg-default-100`,onClick:()=>o(null),children:e.o(`editor.ai.back`)})]})]}),(d||l||p)&&(0,a.jsxs)(`div`,{className:`flex-1 min-h-0 flex flex-col`,children:[d&&!l&&(0,a.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-default-500`,children:[(0,a.jsx)(`span`,{className:`animate-spin`,children:`⏳`}),e.o(`editor.ai.thinking`)]}),l&&(0,a.jsxs)(a.Fragment,{children:[(0,a.jsxs)(`div`,{ref:y,className:`flex-1 min-h-0 overflow-y-auto text-sm whitespace-pre-wrap text-default-700 mb-3`,children:[l,d&&(0,a.jsx)(`span`,{className:`animate-pulse`,children:`▊`})]}),!d&&(0,a.jsxs)(`div`,{className:`flex gap-2 shrink-0`,children:[_.current.empty?(0,a.jsx)(`button`,{type:`button`,className:`px-3 py-1.5 text-xs bg-primary text-white rounded-lg`,onClick:()=>w(`replaceAll`),children:e.o(`editor.ai.replaceAll`)}):(0,a.jsx)(`button`,{type:`button`,className:`px-3 py-1.5 text-xs bg-primary text-white rounded-lg`,onClick:()=>w(`replace`),children:e.o(`editor.ai.replace`)}),(0,a.jsx)(`button`,{type:`button`,className:`px-3 py-1.5 text-xs border border-default-200 rounded-lg hover:bg-default-100`,onClick:()=>w(`below`),children:e.o(`editor.ai.insert`)}),(0,a.jsx)(`button`,{type:`button`,className:`px-3 py-1.5 text-xs text-danger`,onClick:E,children:e.o(`editor.ai.discard`)})]})]}),p&&(0,a.jsxs)(`div`,{className:`text-sm text-danger`,children:[(0,a.jsx)(`p`,{children:p}),(0,a.jsx)(`button`,{type:`button`,className:`mt-2 px-3 py-1 text-xs border border-default-200 rounded-lg hover:bg-default-100`,onClick:()=>{m(null),o(null)},children:e.o(`editor.ai.back`)})]})]})]})]}),h&&(0,a.jsxs)(`div`,{className:`qed-root`,style:{zIndex:1e4},onClick:()=>g(null),children:[(0,a.jsx)(`div`,{className:`qed-backdrop`,onClick:()=>g(null)}),(0,a.jsxs)(`div`,{className:`qed-card animate-in`,onClick:e=>e.stopPropagation(),children:[(0,a.jsxs)(`div`,{className:`qed-header`,children:[(0,a.jsx)(`h2`,{className:`qed-title`,children:h.position===`replaceAll`?e.o(`editor.ai.replaceAllTitle`):e.o(`editor.ai.replaceTitle`)}),(0,a.jsx)(`button`,{type:`button`,className:`qed-close`,onClick:()=>g(null),"aria-label":e.o(`editor.ai.close`),children:`✕`})]}),(0,a.jsxs)(`div`,{className:`qed-body`,children:[(0,a.jsx)(`p`,{className:`mb-2`,children:h.position===`replaceAll`?e.o(`editor.ai.replaceAllText`):e.o(`editor.ai.replaceText`)}),Object.keys(D).length>0&&(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(`p`,{className:`text-xs text-default-500`,children:e.o(`editor.ai.removeNodes`)}),(0,a.jsx)(`ul`,{className:`mt-1 space-y-0.5`,children:Object.entries(D).map(([t,n])=>(0,a.jsxs)(`li`,{className:`text-sm text-default-700`,children:[e.o(gt[t]??t),` ×`,n]},t))})]})]}),(0,a.jsxs)(`div`,{className:`qed-footer`,style:{display:`flex`,justifyContent:`flex-end`,gap:8},children:[(0,a.jsx)(`button`,{type:`button`,className:`qed-btn qed-btn--ghost`,onClick:()=>g(null),children:e.o(`editor.ai.cancel`)}),(0,a.jsx)(`button`,{type:`button`,className:`qed-btn qed-btn--primary`,onClick:T,children:e.o(`editor.ai.confirmReplace`)})]})]})]})]})}var Ct=new Set([`attachmentEmbed`,`videoEmbed`,`audioEmbed`,`image`]);function wt(e){let t=0;return e.descendants(e=>{Ct.has(e.type.name)&&(t+=Number(e.attrs?.size)||0)}),t}function Tt(e){if(!Number.isFinite(e)||e<=0)return`0 B`;let t=[`B`,`KB`,`MB`,`GB`,`TB`],n=Math.min(t.length-1,Math.floor(Math.log(e)/Math.log(1024))),r=e/1024**n;return`${n===0||r>=100?`${Math.round(r)}`:`${Math.round(r*10)/10}`} ${t[n]}`}function Et(e){return(e?.storage)?.qingwuUI?.limits}function Dt(e,t,n){let{maxAttachmentSize:r,maxTotalAttachmentSize:i}=n;if(r&&t.size>r)return`单文件大小不能超过 ${Tt(r)}(当前 ${Tt(t.size)})`;if(i){let n=wt(e)+t.size;if(n>i)return`附件总大小不能超过 ${Tt(i)}(当前合计 ${Tt(n)})`}return null}var Ot=!1,kt=null,At=5e3;function jt(){return Ot}function $(e){Ot=e,kt&&=(clearTimeout(kt),null),e&&(kt=setTimeout(()=>{Ot=!1,kt=null},At))}var Mt=null;function Nt(e){Mt=e}function Pt(){return Mt}var Ft=300;function It({open:e,title:t,message:n,confirmText:r=`删除`,cancelText:o=`取消`,onConfirm:s,onCancel:c}){let[l,d]=(0,i.useState)(!1),f=(0,i.useRef)(!1),p=Pt();return(0,i.useEffect)(()=>{if(!e){f.current=!1;return}!p||f.current||(f.current=!0,p({open:e,title:t,message:n,confirmText:r,cancelText:o,onConfirm:s,onCancel:c}))},[e,p,t,n,r,o,s,c]),(0,i.useEffect)(()=>{e||d(!1)},[e]),p||!e?null:(0,u.createPortal)((0,a.jsx)(`div`,{className:`fixed inset-0 z-[10001] flex items-center justify-center bg-black/40 backdrop-blur-sm select-none`,onClick:()=>{l||c()},onMouseDown:e=>e.preventDefault(),children:(0,a.jsxs)(`div`,{className:`bg-white dark:bg-zinc-800 rounded-xl p-6 shadow-xl max-w-sm w-full mx-4 border border-default-200 relative overflow-hidden`,onClick:e=>e.stopPropagation(),children:[l&&(0,a.jsxs)(`div`,{className:`delete-progress`,children:[(0,a.jsx)(`div`,{className:`delete-progress-spinner`}),(0,a.jsx)(`div`,{className:`delete-progress-text`,children:`删除中…`})]}),(0,a.jsx)(`div`,{className:`text-sm font-medium text-default-800 dark:text-zinc-100 mb-2`,children:t}),n&&(0,a.jsx)(`div`,{className:`text-xs text-default-500 dark:text-zinc-400 mb-4 whitespace-pre-line`,children:n}),(0,a.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,a.jsx)(`button`,{type:`button`,className:`px-3 py-1.5 text-xs rounded-lg border border-default-200 hover:bg-default-100 transition-colors`,onClick:c,disabled:l,children:o}),(0,a.jsx)(`button`,{type:`button`,className:`px-3 py-1.5 text-xs rounded-lg bg-red-500 hover:bg-red-600 text-white transition-colors disabled:opacity-60`,onClick:async()=>{if(l)return;d(!0);let e=Date.now();try{await s()}finally{let t=Date.now()-e;t<Ft&&await new Promise(e=>setTimeout(e,Ft-t)),d(!1),c()}},disabled:l,children:r})]})]})}),document.body)}function Lt(e){return/^(\.\.?\/|[a-zA-Z]:\\|file:\/\/)/.test(e)?!0:!(/^[a-z]+:\/\//i.test(e)||e.startsWith(`/`)||e.startsWith(`data:`)||e.startsWith(`blob:`))}function Rt({node:e,deleteNode:n,editor:r}){let[o,s]=(0,i.useState)(!1),[l,u]=(0,i.useState)(!1),[d,f]=(0,i.useState)(!1),p=(0,i.useRef)(!1),[m,h]=(0,i.useState)(!1),g=e.attrs.src||``,_=e.attrs.alt||``,v=e.attrs.width||null,y=e.attrs.height||null,b=(0,i.useRef)(null),x=(0,i.useRef)(null),S=(0,i.useRef)(null),C=(0,i.useRef)(null),w=(0,i.useRef)(null),T=(0,i.useRef)(!1),E=(0,i.useRef)(!1),D=(0,i.useRef)(0),[O,k]=(0,i.useState)(g),A=r?.isEditable??!0,j=(0,i.useCallback)(()=>{l||(D.current=window.scrollY,s(!0))},[l]),M=(0,i.useCallback)(()=>{s(!1),requestAnimationFrame(()=>window.scrollTo(0,D.current))},[]),N=(0,i.useCallback)(()=>{let e=b.current;e&&(D.current=window.scrollY,e.requestFullscreen?e.requestFullscreen():e.webkitRequestFullscreen&&e.webkitRequestFullscreen())},[]),P=(0,i.useCallback)(()=>{let e=x.current;e&&(D.current=window.scrollY,e.requestFullscreen?e.requestFullscreen():e.webkitRequestFullscreen&&e.webkitRequestFullscreen())},[]);(0,i.useEffect)(()=>{u(!1),k(g),T.current=!1,E.current=!1,C.current&&=(URL.revokeObjectURL(C.current),null),w.current&&=(URL.revokeObjectURL(w.current),null)},[g]),(0,i.useEffect)(()=>{if(!g||g.startsWith(`blob:`)||g.startsWith(`data:`)||g.includes(`?X-Amz-`))return;let e=!1;return(async()=>{try{let{signPreviewUrlHeaders:t}=await Promise.resolve().then(()=>require("./signed-fetch-ULpEJyn5.cjs")).then(e=>e.i),n=await t(g);if(!n)return;let r=await fetch(g,{headers:n});if(!r.ok)return;let i=URL.createObjectURL(await r.blob());if(e){URL.revokeObjectURL(i);return}C.current&&URL.revokeObjectURL(C.current),C.current=i,T.current=!0,k(i)}catch{}})(),()=>{e=!0}},[g]),(0,i.useEffect)(()=>()=>{C.current&&URL.revokeObjectURL(C.current),w.current&&URL.revokeObjectURL(w.current)},[]),(0,i.useEffect)(()=>{if(!o)return;let e=e=>{if(e.key===`Escape`){if(document.fullscreenElement||p.current)return;s(!1)}};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[o]),(0,i.useEffect)(()=>{let e=()=>{let e=!!document.fullscreenElement;f(e),e||(p.current=!0,requestAnimationFrame(()=>window.scrollTo(0,D.current)),window.setTimeout(()=>{p.current=!1},300))};return document.addEventListener(`fullscreenchange`,e),()=>document.removeEventListener(`fullscreenchange`,e)},[]);let F=l||Lt(g);return(0,a.jsxs)(c.NodeViewWrapper,{as:`div`,className:`image-node-view group/img`,contentEditable:!1,children:[F?(0,a.jsxs)(`div`,{className:`image-placeholder`,children:[A&&(0,a.jsx)(`button`,{type:`button`,className:`img-ctrl-btn img-ctrl-btn--del image-placeholder-del`,onClick:()=>{jt()||($(!0),h(!0))},title:`删除`,children:(0,a.jsx)(`svg`,{width:`14`,height:`14`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,children:(0,a.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16`})})}),(0,a.jsx)(`svg`,{width:`32`,height:`32`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`1.5`,children:(0,a.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M2.25 15.75l5.159-5.159a2.25 2.25 0 013.182 0l5.159 5.159m-1.5-1.5l1.409-1.409a2.25 2.25 0 013.182 0l2.909 2.909M3.75 21h16.5A2.25 2.25 0 0022.5 18.75V5.25A2.25 2.25 0 0020.25 3H3.75A2.25 2.25 0 001.5 5.25v13.5A2.25 2.25 0 003.75 21z`})}),(0,a.jsx)(`span`,{className:`image-placeholder-text`,children:Lt(g)?`本地图片无法加载`:`图片加载失败`}),(0,a.jsx)(`span`,{className:`image-placeholder-path`,children:_||g})]}):(0,a.jsxs)(`div`,{ref:b,className:`img-wrap`,children:[(0,a.jsx)(`img`,{ref:S,src:O,alt:_,width:v||void 0,height:y||void 0,onClick:j,onError:()=>{T.current||l||(T.current=!0,(async()=>{try{let e=await t.r(g),n=await fetch(g,e?{headers:e}:{});if(n.ok){let e=await n.blob(),t=URL.createObjectURL(e);C.current&&URL.revokeObjectURL(C.current),C.current=t,S.current&&(S.current.src=t);return}}catch{}u(!0)})())},className:`img-main`,draggable:`false`}),(0,a.jsxs)(`div`,{className:`img-controls`,style:d?{opacity:1,pointerEvents:`auto`}:void 0,children:[(0,a.jsx)(`button`,{type:`button`,className:`img-ctrl-btn`,onClick:j,title:`网页全屏`,children:(0,a.jsx)(`svg`,{width:`14`,height:`14`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,children:(0,a.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M8 3H5a2 2 0 00-2 2v3m18 0V5a2 2 0 00-2-2h-3m0 18h3a2 2 0 002-2v-3M3 16v3a2 2 0 002 2h3`})})}),(0,a.jsx)(`button`,{type:`button`,className:`img-ctrl-btn`,onClick:N,title:`全屏`,children:(0,a.jsx)(`svg`,{width:`14`,height:`14`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,children:(0,a.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M15 3h6v6M9 21H3v-6M21 3l-7 7M3 21l7-7`})})}),A&&(0,a.jsx)(`button`,{type:`button`,className:`img-ctrl-btn img-ctrl-btn--del`,onClick:()=>{jt()||($(!0),h(!0))},title:`删除`,children:(0,a.jsx)(`svg`,{width:`14`,height:`14`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,children:(0,a.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16`})})})]})]}),o&&!F&&(0,a.jsxs)(`div`,{className:`image-lightbox`,onClick:M,children:[(0,a.jsxs)(`div`,{className:`image-lightbox-bar`,children:[(0,a.jsx)(`button`,{type:`button`,className:`image-lightbox-bar-btn`,onClick:P,title:`全屏`,children:(0,a.jsx)(`svg`,{width:`18`,height:`18`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,children:(0,a.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M15 3h6v6M9 21H3v-6M21 3l-7 7M3 21l7-7`})})}),(0,a.jsx)(`button`,{type:`button`,className:`image-lightbox-bar-btn`,onClick:M,title:`关闭`,children:(0,a.jsx)(`svg`,{width:`18`,height:`18`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,children:(0,a.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M6 18L18 6M6 6l12 12`})})})]}),(0,a.jsx)(`img`,{ref:x,src:O,alt:_,className:`image-lightbox-img`,onClick:e=>e.stopPropagation(),onError:()=>{if(!E.current){if(E.current=!0,C.current&&x.current){x.current.src=C.current;return}(async()=>{try{let e=await t.r(g),n=await fetch(g,e?{headers:e}:{});if(n.ok){let e=await n.blob(),t=URL.createObjectURL(e);w.current&&URL.revokeObjectURL(w.current),w.current=t,x.current&&(x.current.src=t)}}catch{}})()}}})]}),(0,a.jsx)(It,{open:m,title:`确认删除图片`,message:F?`该图片无法在当前环境加载,仅从编辑器中移除该图片节点,不影响存储文件。`:`此操作将同时删除对象存储中的文件,不可撤销。`,onCancel:()=>{$(!1),h(!1)},onConfirm:async()=>{if(!F)try{await ot(g)}catch{}$(!1),await new Promise(e=>setTimeout(e,300)),n()}})]})}var zt=(0,i.lazy)(()=>import(`@file-viewer/react`)),Bt=new Set,Vt={rendererMode:`replace`,autoRenderers:!0,theme:`light`,styleIsolation:`scoped`,toolbar:{position:`bottom-right`,download:!1,permissions:{download:!1}},pdf:{workerUrl:`/file-viewer/vendor/pdf/pdf.worker.mjs`,cMapUrl:`/file-viewer/vendor/pdf/cmaps/`,wasmUrl:`/file-viewer/vendor/pdf/wasm/`,standardFontDataUrl:`/file-viewer/vendor/pdf/standard_fonts/`,cjkFontFallbackPath:`/file-viewer/vendor/pdf/fonts/`},spreadsheet:{workerUrl:`/file-viewer/vendor/xlsx/sheet.worker.js`},docx:{workerUrl:`/file-viewer/vendor/docx/docx.worker.js`,workerJsZipUrl:`/file-viewer/vendor/docx/jszip.min.js`,backgroundColor:`#ffffff`},archive:{workerUrl:`/file-viewer/vendor/libarchive/worker-bundle.js`,wasmUrl:`/file-viewer/vendor/libarchive/libarchive.wasm`,cache:!0,workerTimeoutMs:3e4}},Ht={pdf:`pdf`,docx:`word`,docm:`word`,dotx:`word`,dotm:`word`,doc:`word`,dot:`word`,rtf:`word`,odt:`word`,xlsx:`spreadsheet`,xlsm:`spreadsheet`,xlsb:`spreadsheet`,xls:`spreadsheet`,xltx:`spreadsheet`,xlt:`spreadsheet`,csv:`spreadsheet`,tsv:`spreadsheet`,ods:`spreadsheet`,numbers:`spreadsheet`,pptx:`presentation`,pptm:`presentation`,potx:`presentation`,potm:`presentation`,ppsx:`presentation`,ppsm:`presentation`,ppt:`presentation`,pot:`presentation`,odp:`presentation`,zip:`archive`,rar:`archive`,"7z":`archive`,tar:`archive`,gz:`archive`,tgz:`archive`,bz2:`archive`,xz:`archive`,zst:`archive`,txt:`text`,md:`text`,log:`text`,html:`text`,htm:`text`,css:`text`,js:`text`,jsx:`text`,ts:`text`,tsx:`text`,py:`text`,sh:`text`,sql:`text`,json:`text`,xml:`text`,yml:`text`,yaml:`text`},Ut={pdf:()=>import(`@file-viewer/renderer-pdf`).then(e=>e.pdfRenderer),word:()=>import(`@file-viewer/renderer-word`).then(e=>e.wordRenderer),spreadsheet:()=>import(`@file-viewer/renderer-spreadsheet`).then(e=>e.spreadsheetRenderer),presentation:()=>import(`@file-viewer/renderer-presentation`).then(e=>e.presentationRenderer),archive:()=>import(`@file-viewer/renderer-archive`).then(e=>e.archiveRenderer),text:()=>import(`@file-viewer/renderer-text`).then(e=>e.textRenderer)};function Wt(e){return e?e<1024?`${e} B`:e<1048576?`${(e/1024).toFixed(1)} KB`:`${(e/1048576).toFixed(1)} MB`:``}function Gt(e){let t=e.split(`.`).pop()?.toLowerCase()||``,n={pdf:{label:`PDF`,color:`#ef4444`},doc:{label:`DOC`,color:`#2563eb`},docx:{label:`DOC`,color:`#2563eb`},dot:{label:`DOT`,color:`#2563eb`},dotx:{label:`DOT`,color:`#2563eb`},xls:{label:`XLS`,color:`#16a34a`},xlsx:{label:`XLS`,color:`#16a34a`},xlt:{label:`XLT`,color:`#16a34a`},xltx:{label:`XLT`,color:`#16a34a`},csv:{label:`CSV`,color:`#16a34a`},ppt:{label:`PPT`,color:`#ea580c`},pptx:{label:`PPT`,color:`#ea580c`},pot:{label:`POT`,color:`#ea580c`},potx:{label:`POT`,color:`#ea580c`},zip:{label:`ZIP`,color:`#ca8a04`},rar:{label:`RAR`,color:`#ca8a04`},"7z":{label:`7Z`,color:`#ca8a04`},tar:{label:`TAR`,color:`#ca8a04`},gz:{label:`GZ`,color:`#ca8a04`},txt:{label:`TXT`,color:`#6b7280`},md:{label:`MD`,color:`#6b7280`},log:{label:`LOG`,color:`#6b7280`},html:{label:`HTM`,color:`#7c3aed`},htm:{label:`HTM`,color:`#7c3aed`},css:{label:`CSS`,color:`#7c3aed`},js:{label:`JS`,color:`#7c3aed`},jsx:{label:`JSX`,color:`#7c3aed`},ts:{label:`TS`,color:`#7c3aed`},tsx:{label:`TSX`,color:`#7c3aed`},json:{label:`JSON`,color:`#7c3aed`},xml:{label:`XML`,color:`#7c3aed`}}[t]||{label:t?t.slice(0,3).toUpperCase():`FILE`,color:`#6b7280`};return(0,a.jsxs)(`svg`,{width:`22`,height:`22`,viewBox:`0 0 24 24`,fill:`none`,xmlns:`http://www.w3.org/2000/svg`,"aria-hidden":`true`,children:[(0,a.jsx)(`path`,{d:`M6 2h7l5 5v15a1 1 0 0 1-1 1H6a1 1 0 0 1-1-1V3a1 1 0 0 1 1-1z`,fill:`#fff`,stroke:n.color,strokeWidth:`1.5`,strokeLinejoin:`round`}),(0,a.jsx)(`path`,{d:`M13 2v5h5`,fill:`none`,stroke:n.color,strokeWidth:`1.5`,strokeLinejoin:`round`}),(0,a.jsx)(`rect`,{x:`5`,y:`14`,width:`14`,height:`6.5`,rx:`1.2`,fill:n.color}),(0,a.jsx)(`text`,{x:`12`,y:`19`,textAnchor:`middle`,fontSize:`5`,fontWeight:`700`,fill:`#fff`,fontFamily:`Arial, sans-serif`,children:n.label})]})}function Kt(e){return e.split(`.`).pop()?.toLowerCase()||``}function qt(e){let t=e.split(`.`).pop()?.toLowerCase()||``;return/^(pdf|docx?|dotx?|xlsx?|xltx?|pptx?|potx?|txt|md|html?|csv|json|xml|yml|yaml|log|zip|rar|7z|tar|gz|odt|ods|odp|rtf|xlsm|xlsb|ppsx|numbers|tgz|bz2|xz|zst|js|ts|tsx|py|sh|sql)$/.test(t)}function Jt(e){return!!e&&!e.startsWith(`file:`)}function Yt(e){return btoa(encodeURIComponent(e)).replace(/\+/g,`-`).replace(/\//g,`_`).replace(/=+$/,``)}async function Xt(e,t){try{let n=Yt(e),r=await fetch(`/api/preview/${n}`,{signal:t,cache:`no-store`});if(!r.ok)return null;if((r.headers.get(`Content-Type`)||``).includes(`text/html`))return console.warn(`[attachment] /api/preview returned HTML (endpoint missing), fallback to direct XHR`),null;let i=await r.arrayBuffer(),a=Number(r.headers.get(`Content-Length`)||0);return i.byteLength>0&&(a===0||i.byteLength===a)?i:(console.warn(`[attachment] /api/preview data incomplete`),null)}catch{return null}}function Zt(e,t,n){return new Promise((r,i)=>{let a=new XMLHttpRequest;if(a.open(`GET`,e,!0),a.responseType=`arraybuffer`,t){let e=[`host`,`connection`,`content-length`,`cookie`,`date`,`expect`,`keep-alive`,`origin`,`referer`,`te`,`trailer`,`transfer-encoding`,`upgrade`,`via`];for(let[n,r]of Object.entries(t))if(!e.includes(n.toLowerCase()))try{a.setRequestHeader(n,r)}catch{}}if(a.onload=()=>{a.status>=200&&a.status<300?r(a.response):i(Error(`HTTP ${a.status} ${a.statusText}`))},a.onerror=()=>i(Error(`XHR network error`)),a.ontimeout=()=>i(Error(`XHR timeout`)),n){if(n.aborted){a.abort(),i(new DOMException(`Aborted`,`AbortError`));return}n.addEventListener(`abort`,()=>{a.abort(),i(new DOMException(`Aborted`,`AbortError`))})}a.send()})}function Qt({node:n,deleteNode:r,selected:o,editor:s}){let l=s?.isEditable??!0,u=n.attrs.src||``,[d,f]=(0,i.useState)(()=>Bt.has(u)),[p,m]=(0,i.useState)(null),[h,g]=(0,i.useState)(null),[_,v]=(0,i.useState)(!1),[y,b]=(0,i.useState)(null),[x,S]=(0,i.useState)(!1),[C,w]=(0,i.useState)(null),T=(0,i.useRef)(null),E=(0,i.useRef)(null),D=(0,i.useRef)(null),O=(0,i.useRef)(0),k=(0,i.useRef)(!1),A=(0,i.useRef)(null),j=(0,i.useRef)(0),[M,N]=(0,i.useState)(!1),P=(0,i.useRef)(null),[F,ee]=(0,i.useState)(0),[I,L]=(0,i.useState)(`none`),[R,te]=(0,i.useState)(void 0),[ne,re]=(0,i.useState)(!1),z=n.attrs.src||``,B=n.attrs.name||z&&z.split(`/`).pop()?.split(`?`)[0]||(z?`attachment`:e.o(`editor.attachment.lost`)),ie=n.attrs.size||0,V=Kt(B),ae=!z;(0,i.useEffect)(()=>{if(!d){te(void 0),re(!1);return}let e=Ht[V];if(!e){te(void 0),re(!1);return}let t=!0;return te(void 0),re(!1),Ut[e]().then(e=>{t&&te(e)}).catch(n=>{console.error(`[attachment] renderer "${e}" load failed:`,n),t&&re(!0)}),()=>{t=!1}},[d,V]);let oe=(0,i.useMemo)(()=>({...Vt,renderers:R?[R]:[],rendererMode:`replace`}),[R]),H=(0,i.useCallback)(e=>{f(t=>{let n=typeof e==`function`?e(t):e;return z&&(n?Bt.add(z):Bt.delete(z)),n})},[z]);(0,i.useEffect)(()=>{f(z?Bt.has(z):!1)},[z]);let U=(0,i.useCallback)(()=>{k.current=!0,H(!0),window.setTimeout(()=>{window.scrollTo(0,O.current),A.current&&(A.current.scrollTop=j.current),k.current&&H(!0),k.current=!1},0)},[H]),W=(0,i.useCallback)(async()=>{I===`web`?(L(`none`),document.body.style.overflow=``,U()):(I===`native`&&document.fullscreenElement&&await document.exitFullscreen(),O.current=window.scrollY,j.current=A.current?.scrollTop??0,document.body.style.overflow=`hidden`,L(`web`))},[I]),se=(0,i.useCallback)(async()=>{let e=E.current;e&&(I===`native`?await document.exitFullscreen():(I===`web`&&(L(`none`),document.body.style.overflow=``),O.current=window.scrollY,j.current=A.current?.scrollTop??0,await e.requestFullscreen(),L(`native`)))},[I,U]),G=(0,i.useCallback)(()=>{I===`none`&&(k.current||H(e=>!e))},[I]);(0,i.useEffect)(()=>{let e=()=>{document.fullscreenElement||(I===`native`&&L(`none`),U())},t=e=>{e.key===`Escape`&&I===`web`&&(L(`none`),document.body.style.overflow=``,U())};return document.addEventListener(`fullscreenchange`,e),window.addEventListener(`keydown`,t),()=>{document.removeEventListener(`fullscreenchange`,e),window.removeEventListener(`keydown`,t)}},[I,U]),(0,i.useEffect)(()=>{let e=e=>{if(e.key!==`Backspace`&&e.key!==`Delete`||!l||!o||jt())return;let t=s?.view?.dom,n=e.target;if(s?.isFocused&&n instanceof Node&&t?.contains(n)){if(e.preventDefault(),e.stopPropagation(),s){let{from:e,to:t}=s.state.selection;P.current={from:e,to:t}}window.getSelection()?.removeAllRanges(),$(!0),N(!0)}};return window.addEventListener(`keydown`,e,!0),()=>window.removeEventListener(`keydown`,e,!0)},[o,s,l]),(0,i.useEffect)(()=>{if(!d||!Jt(z)){m(null),b(null),D.current=null;return}if(D.current===z)return;let e=new AbortController,n=!0;return v(!0),b(null),(async()=>{let r=z.includes(`?X-Amz-`),i=null,a=null;if(!i&&!r&&(i=await Xt(z,e.signal)),!i&&!r)try{let n=await t.n(z);n&&(i=await Xt(n,e.signal)||await Zt(n,void 0,e.signal))}catch(e){console.warn(`[attachment] signPreviewUrl failed:`,e)}if(!i&&!r)try{let n=await t.r(z);if(n){let t={"X-Requested-With":`XMLHttpRequest`};n.forEach((e,n)=>{t[n]=e});try{i=await Zt(z,t,e.signal)}catch(e){console.warn(`[attachment] signed headers XHR failed:`,e),a=e instanceof Error?e:Error(String(e))}}}catch(e){console.warn(`[attachment] signPreviewUrlHeaders failed:`,e)}if(!i)try{i=await Zt(z,r?void 0:{"X-Requested-With":`XMLHttpRequest`},e.signal)}catch(e){console.warn(`[attachment] plain XHR failed:`,e),a=e instanceof Error?e:Error(String(e))}if(!i)throw a||Error(`所有 fetch 方法均失败`);if(!n)return;m(i),D.current=z;let o=URL.createObjectURL(new Blob([i],{type:`application/octet-stream`}));g(o),v(!1)})().catch(e=>{if(n&&!(e instanceof DOMException&&e.name===`AbortError`)){if(D.current===z){v(!1);return}b(e instanceof Error?e.message:`附件读取失败,请检查对象存储 CORS 和公开访问权限`)}}),()=>{n=!1,e.abort()}},[d,z]),(0,i.useEffect)(()=>()=>{h&&URL.revokeObjectURL(h),m(null)},[]),(0,i.useEffect)(()=>()=>{h&&URL.revokeObjectURL(h),g(null),m(null),D.current=null},[z]),(0,i.useEffect)(()=>{if(C!==`success`&&C!==`error`)return;let e=window.setTimeout(()=>w(null),2400);return()=>window.clearTimeout(e)},[C]);let K=(0,i.useCallback)(async()=>{S(!0),w(`loading`);try{if(h){let e=document.createElement(`a`);e.href=h,e.download=B,document.body.appendChild(e),e.click(),document.body.removeChild(e),w(`success`);return}let e=z.includes(`?X-Amz-`),n=null;if(!e)try{let e=await t.n(z);e&&(n=await fetch(e,{headers:{"X-Requested-With":`XMLHttpRequest`}}),n.ok||(n=null))}catch{}if(!n&&!e)try{let e=await t.r(z);e&&(n=await fetch(z,{headers:(()=>{let t=new Headers(e);return t.set(`X-Requested-With`,`XMLHttpRequest`),t})()}),n.ok||(n=null))}catch{}if(n||=await fetch(z,{headers:{"X-Requested-With":`XMLHttpRequest`}}),!n||!n.ok)throw Error(`下载失败`);let r=await n.blob(),i=URL.createObjectURL(r),a=document.createElement(`a`);a.href=i,a.download=B,document.body.appendChild(a),a.click(),document.body.removeChild(a),URL.revokeObjectURL(i),w(`success`)}catch(e){console.error(`[attachment] download failed:`,e),w(`error`)}finally{S(!1)}},[z,B,h]);return(0,a.jsxs)(c.NodeViewWrapper,{ref:T,as:`div`,className:`attachment-embed group/att ${o?`is-selected`:``}`,contentEditable:!1,children:[(0,a.jsxs)(`div`,{className:`att-inner`,style:o?{outline:`2px solid var(--primary, #6366f1)`,outlineOffset:`2px`}:void 0,children:[(0,a.jsxs)(`div`,{className:`att-header`,children:[(0,a.jsxs)(`div`,{className:`att-info`,children:[(0,a.jsx)(`span`,{className:`att-icon`,children:ae?(0,a.jsxs)(`svg`,{width:`22`,height:`22`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`1.6`,strokeLinecap:`round`,strokeLinejoin:`round`,"aria-hidden":`true`,style:{color:`#9ca3af`},children:[(0,a.jsx)(`path`,{d:`M10.29 3.86 1.82 18a2 2 0 0 0 1.71 3h16.94a2 2 0 0 0 1.71-3L13.71 3.86a2 2 0 0 0-3.42 0z`}),(0,a.jsx)(`path`,{d:`M12 9v4`}),(0,a.jsx)(`path`,{d:`M12 17h.01`})]}):Gt(B)}),(0,a.jsxs)(`div`,{className:`att-meta`,children:[(0,a.jsx)(`span`,{className:`att-name`,children:B}),ie>0&&(0,a.jsx)(`span`,{className:`att-size`,children:Wt(ie)})]})]}),(0,a.jsxs)(`div`,{className:`att-tools`,children:[(0,a.jsxs)(`div`,{className:`att-download-status`,role:`status`,"aria-live":`polite`,"aria-atomic":`true`,children:[C===`loading`&&(0,a.jsxs)(`span`,{className:`att-download-status__content is-loading`,children:[(0,a.jsx)(`svg`,{className:`att-download-spinner`,width:`13`,height:`13`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,"aria-hidden":`true`,children:(0,a.jsx)(`path`,{strokeLinecap:`round`,d:`M12 2a10 10 0 1 0 10 10`})}),`正在准备`]}),C===`success`&&(0,a.jsxs)(`span`,{className:`att-download-status__content is-success`,children:[(0,a.jsx)(`svg`,{width:`13`,height:`13`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,"aria-hidden":`true`,children:(0,a.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`m5 12 4 4L19 6`})}),`已下载`]}),C===`error`&&(0,a.jsx)(`span`,{className:`att-download-status__content is-error`,children:`下载失败,请重试`})]}),(0,a.jsxs)(`div`,{className:`att-actions`,children:[z&&qt(B)&&(0,a.jsx)(`button`,{type:`button`,className:`att-btn`,onMouseDown:e=>{e.preventDefault(),e.stopPropagation(),G()},title:e.o(`editor.attachment.preview`),"aria-label":e.o(`editor.attachment.preview`),children:(0,a.jsxs)(`svg`,{width:`14`,height:`14`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,"aria-hidden":`true`,children:[(0,a.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M2.036 12.322a1.012 1.012 0 010-.639C3.423 7.51 7.36 4.5 12 4.5c4.638 0 8.573 3.007 9.963 7.178.07.207.07.431 0 .639C20.577 16.49 16.64 19.5 12 19.5c-4.638 0-8.573-3.007-9.963-7.178z`}),(0,a.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M15 12a3 3 0 11-6 0 3 3 0 016 0z`})]})}),(0,a.jsx)(`button`,{type:`button`,className:`att-btn`,onClick:K,disabled:x||ae,title:x?`正在准备下载`:e.o(`editor.attachment.download`),"aria-label":x?`正在准备下载`:e.o(`editor.attachment.download`),children:(0,a.jsx)(`svg`,{width:`14`,height:`14`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,"aria-hidden":`true`,children:(0,a.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M4 16v1a3 3 0 003 3h10a3 3 0 003-3v-1m-4-4l-4 4m0 0l-4-4m4 4V4`})})}),l&&(0,a.jsx)(`button`,{type:`button`,className:`att-btn att-btn--del`,onClick:()=>{!l||jt()||($(!0),N(!0))},title:e.o(`editor.attachment.delete`),"aria-label":e.o(`editor.attachment.delete`),children:(0,a.jsx)(`svg`,{width:`14`,height:`14`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,"aria-hidden":`true`,children:(0,a.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16`})})})]})]})]}),d&&(0,a.jsxs)(`div`,{ref:E,className:`att-preview-wrap ${I===`web`?`is-web-fs`:``}`,style:{position:`relative`,height:500,overflow:`hidden`,background:`#fff`},children:[(0,a.jsx)(`div`,{ref:A,className:`att-preview-scroll`,style:{height:`100%`,overflow:`auto`},children:_&&!p&&!h?(0,a.jsx)(`div`,{className:`flex items-center justify-center h-full text-default-400 text-sm`,children:e.o(`editor.attachment.loadingPreview`)}):(y||ne)&&!p&&!h?(0,a.jsxs)(`div`,{className:`flex h-full flex-col items-center justify-center gap-2 p-6 text-center text-sm text-default-500`,children:[(0,a.jsx)(`div`,{className:`font-medium text-default-700`,children:`暂时无法预览此附件`}),(0,a.jsx)(`div`,{className:`max-w-md text-xs leading-relaxed`,children:`请稍后重试,或使用附件栏中的下载按钮。`})]}):(0,a.jsx)(i.Suspense,{fallback:(0,a.jsx)(`div`,{className:`flex items-center justify-center h-full text-default-400 text-sm`,style:{background:`#fff`},children:e.o(`editor.attachment.loadingPreview`)}),children:p||h||z?R?(0,a.jsx)(zt,{buffer:p||void 0,url:h||z,name:B,filename:B,type:V,size:ie||p?.byteLength||0,options:oe},`${z}-${F}`):(0,a.jsx)(`div`,{className:`flex h-full items-center justify-center text-sm text-default-400`,children:`正在加载预览引擎...`}):(0,a.jsx)(`div`,{className:`flex h-full items-center justify-center text-sm text-default-400`,children:`正在加载...`})})}),(0,a.jsxs)(`div`,{className:`att-fs-controls__panel`,style:{position:`absolute`,top:8,right:8,zIndex:10,display:`flex`,gap:2,padding:4,background:`rgba(255,255,255,0.92)`,backdropFilter:`blur(8px)`,WebkitBackdropFilter:`blur(8px)`,borderRadius:8,boxShadow:`0 2px 8px rgba(0,0,0,0.12)`,border:`1px solid rgba(0,0,0,0.06)`},children:[(0,a.jsx)(`button`,{type:`button`,onClick:W,title:I===`web`?`退出网页全屏`:`网页全屏`,"aria-label":I===`web`?`退出网页全屏`:`网页全屏`,style:{width:28,height:28,borderRadius:6,border:`none`,background:I===`web`?`#e4e4e7`:`transparent`,cursor:`pointer`,display:`flex`,alignItems:`center`,justifyContent:`center`,color:`#52525b`,transition:`background 0.12s`},onMouseEnter:e=>{I!==`web`&&(e.currentTarget.style.background=`#f4f4f5`)},onMouseLeave:e=>{I!==`web`&&(e.currentTarget.style.background=`transparent`)},children:(0,a.jsx)(`svg`,{width:`14`,height:`14`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,"aria-hidden":`true`,children:(0,a.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M8 3H5a2 2 0 00-2 2v3m18 0V5a2 2 0 00-2-2h-3m0 18h3a2 2 0 002-2v-3M3 16v3a2 2 0 002 2h3`})})}),(0,a.jsx)(`button`,{type:`button`,onClick:se,title:I===`native`?`退出全屏`:`全屏`,"aria-label":I===`native`?`退出全屏`:`全屏`,style:{width:28,height:28,borderRadius:6,border:`none`,background:I===`native`?`#e4e4e7`:`transparent`,cursor:`pointer`,display:`flex`,alignItems:`center`,justifyContent:`center`,color:`#52525b`,transition:`background 0.12s`},onMouseEnter:e=>{I!==`native`&&(e.currentTarget.style.background=`#f4f4f5`)},onMouseLeave:e=>{I!==`native`&&(e.currentTarget.style.background=`transparent`)},children:(0,a.jsx)(`svg`,{width:`14`,height:`14`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,"aria-hidden":`true`,children:(0,a.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M15 3h6v6M9 21H3v-6M21 3l-7 7M3 21l7-7`})})})]})]})]}),(0,a.jsx)(It,{open:M,title:`确认删除附件`,message:ae?`此操作将删除该附件节点,不可撤销。`:`此操作将同时删除对象存储中的文件(${B}),不可撤销。`,onCancel:()=>{$(!1),N(!1)},onConfirm:async()=>{try{if(s){let e=P.current,t=e?.from??s.state.selection.from,n=e?.to??s.state.selection.to,r=[];s.state.doc.nodesBetween(t,n,e=>{e.type.name===`attachmentEmbed`&&e.attrs?.src&&r.push(ot(e.attrs.src))}),await Promise.all(r),$(!1),await new Promise(e=>setTimeout(e,300)),s.chain().focus().setTextSelection({from:t,to:n}).deleteSelection().run()}else await ot(z),$(!1),await new Promise(e=>setTimeout(e,300)),r()}catch{$(!1)}}})]})}var $t=d.Node.create({name:`attachmentEmbed`,group:`block`,atom:!0,inline:!1,addNodeView(){return(0,c.ReactNodeViewRenderer)(Qt)},addAttributes(){return{src:{default:null,parseHTML:e=>e.getAttribute(`data-src`)||e.querySelector(`a`)?.getAttribute(`href`)},name:{default:``,parseHTML:e=>e.getAttribute(`data-name`)||e.querySelector(`a`)?.getAttribute(`download`)||``},size:{default:0,parseHTML:e=>Number(e.getAttribute(`data-size`)||0)},type:{default:``,parseHTML:e=>e.getAttribute(`data-type`)||``}}},parseHTML(){return[{tag:`div[data-attachment-embed]`}]},renderHTML({HTMLAttributes:e}){return[`div`,{"data-attachment-embed":`true`,"data-src":e.src,"data-name":e.name,"data-size":e.size||0,"data-type":e.type||``,class:`attachment-embed`},[`a`,{href:e.src,download:e.name},`📎 ${e.name||`attachment`}`]]}});function en({node:e,deleteNode:n,editor:r}){let o=e.attrs.src||``,s=e.attrs.name||o.split(`/`).pop()?.split(`?`)[0]||`audio`,[l,u]=(0,i.useState)(!1),d=r?.isEditable??!0;(0,i.useEffect)(()=>()=>{o.startsWith(`blob:`)&&URL.revokeObjectURL(o)},[o]);let f=!!o&&(o.startsWith(`blob:`)||o.startsWith(`data:`)),[p,m]=(0,i.useState)(f?o:null),[h,g]=(0,i.useState)(f),_=(0,i.useRef)(null);return(0,i.useEffect)(()=>{if(!o){m(null),g(!1);return}if(o.startsWith(`blob:`)||o.startsWith(`data:`)){m(o),g(!0);return}let e=!1;return g(!1),(async()=>{let n=o;try{let e=await t.r(o);if(e){let t=await fetch(o,{headers:e});if(t.ok){let e=URL.createObjectURL(await t.blob());_.current&&URL.revokeObjectURL(_.current),_.current=e,n=e}}}catch{}e||(m(n),g(!0))})(),()=>{e=!0,_.current&&=(URL.revokeObjectURL(_.current),null)}},[o]),(0,a.jsxs)(c.NodeViewWrapper,{as:`div`,className:`audio-embed group/audio`,style:{margin:`1rem 0`},contentEditable:!1,children:[(0,a.jsxs)(`div`,{className:`audio-embed-inner`,children:[(0,a.jsxs)(`div`,{className:`audio-embed-header`,children:[(0,a.jsxs)(`div`,{className:`audio-embed-title`,children:[(0,a.jsx)(`svg`,{className:`audio-embed-icon`,width:`16`,height:`16`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,children:(0,a.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M9 19V6l12-3v13M9 19c0 1.105-1.343 2-3 2s-3-.895-3-2 1.343-2 3-2 3 .895 3 2zm12-3c0 1.105-1.343 2-3 2s-3-.895-3-2 1.343-2 3-2 3 .895 3 2zM9 10l12-3`})}),(0,a.jsx)(`span`,{className:`audio-embed-filename`,children:s})]}),(0,a.jsx)(`div`,{className:`audio-embed-actions`,children:d&&(0,a.jsx)(`button`,{type:`button`,className:`audio-embed-btn audio-embed-btn--del`,onClick:()=>{jt()||($(!0),u(!0))},title:`删除`,children:(0,a.jsx)(`svg`,{width:`12`,height:`12`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,children:(0,a.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16`})})})})]}),(0,a.jsx)(`div`,{className:`audio-embed-player`,children:o?h&&p?(0,a.jsx)(`audio`,{src:p,controls:!0,style:{width:`100%`},onError:async e=>{let n=e.currentTarget;try{let e=await t.r(o),r=await fetch(o,e?{headers:e}:{});if(r.ok){let e=await r.blob();n.src.startsWith(`blob:`)&&URL.revokeObjectURL(n.src),n.src=URL.createObjectURL(e)}}catch{}}}):(0,a.jsxs)(`div`,{className:`audio-embed-loading`,children:[(0,a.jsx)(`span`,{className:`audio-embed-spinner`}),`音频加载中…`]}):(0,a.jsxs)(`div`,{className:`audio-embed-loading audio-embed-missing`,children:[(0,a.jsx)(`span`,{className:`audio-embed-missing-icon`,"aria-hidden":`true`,children:`!`}),`音频文件缺失`]})})]}),(0,a.jsx)(It,{open:l,title:`确认删除音频`,message:`此操作将同时删除对象存储中的文件(${s}),不可撤销。`,onCancel:()=>{$(!1),u(!1)},onConfirm:async()=>{try{await ot(o)}catch{}$(!1),await new Promise(e=>setTimeout(e,300)),n()}})]})}function tn(e){return/\.(mp3|wav|ogg|flac|aac|m4a|wma|opus)(\?|$)/i.test(e)||/\/.*\.(mp3|wav|ogg|flac)/i.test(e)}var nn=d.Node.create({name:`audioEmbed`,group:`block`,atom:!0,inline:!1,addNodeView(){return(0,c.ReactNodeViewRenderer)(en)},addProseMirrorPlugins(){return[new f.Plugin({props:{handlePaste(e,t){let n=t.clipboardData?.getData(`text/plain`);if(!n)return!1;let r=n.split(/\r?\n/);for(let n of r){let r=n.trim();if(!r||r.includes(` `)||!tn(r))continue;t.preventDefault();let i=e.state.schema.nodes.audioEmbed.create({src:r});return e.dispatch(e.state.tr.replaceSelectionWith(i)),!0}return!1}}})]},addAttributes(){return{src:{default:null},name:{default:``},size:{default:0,parseHTML:e=>Number(e.getAttribute(`data-size`)||0)}}},parseHTML(){return[{tag:`div[data-audio-embed]`,getAttrs:e=>{let t=e,n=t.getAttribute(`src`)||t.getAttribute(`data-src`)||t.querySelector(`audio`)?.getAttribute(`src`)||null;return n?{src:n}:null}},{tag:`audio[src]`}]},renderHTML({HTMLAttributes:e}){return[`div`,{"data-audio-embed":`true`,src:e.src,"data-src":e.src,"data-size":e.size||0,class:`audio-embed`},[`audio`,{src:e.src,controls:`true`,style:`width:100%;`}]]}});function rn(e){return e?/bilibili\.com|BV[a-zA-Z0-9]{10}|av\d+/i.test(e)?`bilibili`:/xiaohongshu\.com|xhslink\.com/i.test(e)?`xiaohongshu`:/\.(mp4|m3u8|webm|ogg|flv|mkv|mov|avi|wmv|ts|m4v|3gp|f4v|rmvb)(\?|$)/i.test(e)||/\/.*\.(mp4|m3u8|mov|webm|flv|mkv)/i.test(e)?`direct`:`unknown`:`unknown`}function an(e){let t=e.match(/BV[a-zA-Z0-9]{10}/);if(t)return t[0];let n=e.match(/av(\d+)/i);return n?n[0]:e}function on({node:e,deleteNode:t,editor:n}){let r=e.attrs.src||``,o=e.attrs.source||`unknown`,s=o===`unknown`?rn(r):o,[l,u]=(0,i.useState)(!1),[d,f]=(0,i.useState)(!1),[p,m]=(0,i.useState)(!1),h=n?.isEditable??!0,g=!h&&r.startsWith(`blob:`),_=(0,a.jsx)(It,{open:l,title:`确认删除视频`,message:`此操作将同时删除对象存储中的文件,不可撤销。`,onCancel:()=>{$(!1),u(!1)},onConfirm:async()=>{try{await ot(r)}catch{}$(!1),await new Promise(e=>setTimeout(e,300)),t()}}),[v,y]=(0,i.useState)(``),b=(0,i.useRef)(null),x=(0,i.useRef)(null),S=(0,i.useRef)(null),C=(0,i.useRef)(null),w=(0,i.useRef)(null),T=(0,i.useRef)(0),E=(0,i.useCallback)(()=>{let e=S.current;e&&(e.style.position=``,e.style.inset=``,e.style.zIndex=``,e.style.borderRadius=``,document.body.style.overflow=``)},[]),D=(0,i.useCallback)(()=>{document.fullscreenElement&&document.exitFullscreen?.(),E()},[E]),O=(0,i.useCallback)(()=>{let e=S.current;e&&(e.style.position===`fixed`?E():(e.style.position=`fixed`,e.style.inset=`0`,e.style.zIndex=`99999`,e.style.borderRadius=`0`,document.body.style.overflow=`hidden`))},[E]),k=(0,i.useCallback)(()=>{T.current=window.scrollY,C.current?.requestFullscreen?.()},[]),A=(0,i.useCallback)(()=>{let e=x.current?.closest(`.video-embed--direct`)||x.current;e&&(T.current=window.scrollY,e.requestFullscreen?.())},[]);if((0,i.useEffect)(()=>{let e=()=>{document.fullscreenElement||requestAnimationFrame(()=>window.scrollTo(0,T.current))};return document.addEventListener(`fullscreenchange`,e),()=>document.removeEventListener(`fullscreenchange`,e)},[]),(0,i.useEffect)(()=>{if(s!==`direct`||!r){y(``);return}let e=!1;return f(!0),(async()=>{try{if(r.includes(`?X-Amz-`)||r.startsWith(`blob:`)||r.startsWith(`data:`)){y(r);return}let{signPreviewUrlHeaders:t}=await Promise.resolve().then(()=>require("./signed-fetch-ULpEJyn5.cjs")).then(e=>e.i),n=await t(r);if(!n){y(r);return}let i=await fetch(r,{headers:n});if(!i.ok){y(r);return}let a=URL.createObjectURL(await i.blob());if(e){URL.revokeObjectURL(a);return}w.current&&URL.revokeObjectURL(w.current),w.current=a,y(a)}catch{e||y(r)}})(),()=>{e=!0,w.current&&=(URL.revokeObjectURL(w.current),null)}},[s,r]),(0,i.useEffect)(()=>{if(s!==`direct`||!v)return;let e=!1;f(!0),m(!1);let t=x.current,n=t=>{let n=t.target;n?.error&&n.error.code===4&&!e&&m(!0)};return t?.addEventListener(`error`,n,!0),(async()=>{if(t)try{let[{default:n}]=await Promise.all([import(`xgplayer`)]);if(e||!x.current)return;b.current?.destroy(),t.replaceChildren(),b.current=new n({el:t,url:v,width:`100%`,height:450,fluid:!0,fitVideoSize:`fixWidth`,autoplay:!1,controls:!0,ignores:[`fullscreen`],playbackRate:[.5,.75,1,1.25,1.5,2],lang:`zh-cn`}),t.__xgplayer=b.current;let r=()=>{e||f(!1)};try{b.current?.once?.(`loadeddata`,r),b.current?.once?.(`canplay`,r)}catch{}window.setTimeout(r,2500)}catch{}})(),()=>{e=!0,t?.removeEventListener(`error`,n,!0),f(!1),b.current?.destroy(),b.current=null,x.current&&(x.current.__xgplayer=null)}},[s,v]),(0,i.useEffect)(()=>{p&&(b.current?.destroy(),b.current=null)},[p]),s===`bilibili`){let e=an(r);return(0,a.jsxs)(c.NodeViewWrapper,{as:`div`,className:`video-embed video-embed--bilibili group/video`,style:{margin:`1rem 0`},contentEditable:!1,children:[(0,a.jsxs)(`div`,{ref:S,style:{borderRadius:12,overflow:`hidden`},children:[(0,a.jsxs)(`div`,{className:`video-fs-controls`,children:[(0,a.jsx)(`button`,{type:`button`,className:`video-fs-btn`,title:`宽屏`,onClick:D,children:(0,a.jsx)(`svg`,{width:`12`,height:`12`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,children:(0,a.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M4 8V4m0 0h4M4 4l5 5m11-1V4m0 0h-4m4 0l-5 5M4 16v4m0 0h4m-4 0l5-5m11 5l-5-5m5 5v-4m0 4h-4`})})}),(0,a.jsx)(`button`,{type:`button`,className:`video-fs-btn`,title:`网页全屏`,onClick:O,children:(0,a.jsx)(`svg`,{width:`12`,height:`12`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,children:(0,a.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M8 3H5a2 2 0 00-2 2v3m18 0V5a2 2 0 00-2-2h-3m0 18h3a2 2 0 002-2v-3M3 16v3a2 2 0 002 2h3`})})}),(0,a.jsx)(`button`,{type:`button`,className:`video-fs-btn`,title:`全屏`,onClick:k,children:(0,a.jsx)(`svg`,{width:`12`,height:`12`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,children:(0,a.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M15 3h6v6M9 21H3v-6M21 3l-7 7M3 21l7-7`})})}),h&&(0,a.jsx)(`button`,{type:`button`,className:`video-fs-btn video-fs-btn--del`,title:`删除`,onClick:()=>{jt()||($(!0),u(!0))},children:(0,a.jsx)(`svg`,{width:`12`,height:`12`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,children:(0,a.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16`})})})]}),(0,a.jsx)(`div`,{style:{position:`relative`,paddingTop:`56.25%`},children:(0,a.jsx)(`iframe`,{ref:C,src:`https://player.bilibili.com/player.html?bvid=${e}&page=1&high_quality=1`,style:{position:`absolute`,top:0,left:0,width:`100%`,height:`100%`,border:`none`},allowFullScreen:!0,scrolling:`no`,sandbox:`allow-scripts allow-same-origin allow-popups allow-popups-to-escape-sandbox`,referrerPolicy:`no-referrer-when-downgrade`})})]}),_]})}return s===`xiaohongshu`?(0,a.jsxs)(c.NodeViewWrapper,{as:`div`,className:`video-embed video-embed--xiaohongshu`,style:{border:`1px solid #e5e7eb`,borderRadius:12,padding:16,display:`flex`,alignItems:`center`,gap:12,maxWidth:480,margin:`1rem 0`},contentEditable:!1,children:[(0,a.jsx)(`div`,{style:{width:40,height:40,background:`#ff2442`,borderRadius:10,display:`flex`,alignItems:`center`,justifyContent:`center`,color:`#fff`,fontWeight:`bold`,fontSize:14,flexShrink:0},children:`红`}),(0,a.jsxs)(`div`,{children:[(0,a.jsx)(`div`,{style:{fontWeight:600,fontSize:14},children:`小红书笔记`}),(0,a.jsx)(`a`,{href:r,target:`_blank`,rel:`noopener noreferrer`,style:{color:`#ff2442`,fontSize:12,textDecoration:`none`},children:`在小红书中打开 →`})]})]}):(0,a.jsxs)(c.NodeViewWrapper,{as:`div`,className:`video-embed video-embed--direct group/video`,style:{margin:`1rem 0`,borderRadius:12,overflow:`hidden`,background:`#000`},contentEditable:!1,onKeyDown:e=>e.stopPropagation(),children:[h&&(0,a.jsxs)(`div`,{className:`video-fs-controls`,children:[(0,a.jsx)(`button`,{type:`button`,className:`video-fs-btn video-fs-btn--del`,title:`删除`,onClick:()=>{jt()||($(!0),u(!0))},children:(0,a.jsx)(`svg`,{width:`12`,height:`12`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,children:(0,a.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16`})})}),(0,a.jsx)(`button`,{type:`button`,className:`video-fs-btn`,title:`全屏`,onClick:A,children:(0,a.jsx)(`svg`,{width:`12`,height:`12`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,children:(0,a.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M15 3h6v6M9 21H3v-6M21 3l-7 7M3 21l7-7`})})})]}),(0,a.jsx)(`div`,{style:{position:`relative`,width:`100%`,background:`#000`},children:g?(0,a.jsxs)(`div`,{style:{minHeight:260,display:`flex`,flexDirection:`column`,alignItems:`center`,justifyContent:`center`,gap:`0.6rem`,padding:`1.25rem`,color:`#fff`},children:[(0,a.jsxs)(`svg`,{width:`34`,height:`34`,viewBox:`0 0 24 24`,children:[(0,a.jsx)(`circle`,{cx:`12`,cy:`12`,r:`9`,fill:`none`,stroke:`rgba(255,255,255,0.2)`,strokeWidth:`3`}),(0,a.jsx)(`path`,{d:`M21 12a9 9 0 0 0-9-9`,fill:`none`,stroke:`#fff`,strokeWidth:`3`,strokeLinecap:`round`,children:(0,a.jsx)(`animateTransform`,{attributeName:`transform`,type:`rotate`,from:`0 12 12`,to:`360 12 12`,dur:`0.8s`,repeatCount:`indefinite`})})]}),(0,a.jsx)(`div`,{style:{fontSize:13,opacity:.75},children:`视频上传中…`})]}):p?(0,a.jsxs)(`div`,{style:{minHeight:260,display:`flex`,flexDirection:`column`,alignItems:`center`,justifyContent:`center`,gap:`0.5rem`,padding:`1.25rem`,textAlign:`center`,color:`#fff`},children:[(0,a.jsxs)(`svg`,{width:`36`,height:`36`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`1.6`,strokeLinecap:`round`,strokeLinejoin:`round`,style:{opacity:.6},children:[(0,a.jsx)(`path`,{d:`M10.29 3.86 1.82 18a2 2 0 0 0 1.71 3h16.94a2 2 0 0 0 1.71-3L13.71 3.86a2 2 0 0 0-3.42 0z`}),(0,a.jsx)(`line`,{x1:`12`,y1:`9`,x2:`12`,y2:`13`}),(0,a.jsx)(`line`,{x1:`12`,y1:`17`,x2:`12.01`,y2:`17`})]}),(0,a.jsx)(`div`,{style:{fontSize:14,fontWeight:500},children:`视频编码不受当前浏览器支持(HEVC/H.265 常见)`}),(0,a.jsx)(`div`,{style:{fontSize:12,opacity:.7,lineHeight:1.5},children:`请安装「HEVC 视频扩展」,或将视频转码为 H.264 后重新上传`})]}):(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(`div`,{ref:x,style:{width:`100%`,minHeight:260}}),d&&(0,a.jsx)(`div`,{className:`xg-loading-overlay`,children:(0,a.jsx)(`span`,{className:`xg-loading-spinner`})})]})}),_]})}function sn(e){return/bilibili\.com|BV[a-zA-Z0-9]{10}|av\d+/i.test(e)?`bilibili`:/xiaohongshu\.com|xhslink\.com/i.test(e)?`xiaohongshu`:/\.(mp4|m3u8|webm|ogg|flv|mkv|mov|avi|wmv|ts|m4v|3gp|f4v|rmvb)(\?|$)/i.test(e)||/\/.*\.(mp4|m3u8|mov|webm|flv|mkv)/i.test(e)?`direct`:`unknown`}function cn(e){let t=e.match(/BV[a-zA-Z0-9]{10}/);if(t)return t[0];let n=e.match(/av(\d+)/i);return n?n[0]:e}function ln(e){let t=e.match(/explore\/([a-zA-Z0-9]+)/);return t?t[1]:e}var un=d.Node.create({name:`videoEmbed`,group:`block`,atom:!0,inline:!1,addNodeView(){return(0,c.ReactNodeViewRenderer)(on)},addProseMirrorPlugins(){return[new f.Plugin({props:{handleKeyDown(e,t){if(t.key!==` `)return!1;let n=e.state.selection;if(n instanceof f.NodeSelection&&n.node.type.name===`videoEmbed`){t.preventDefault();let r=e.nodeDOM(n.from);if(r){let e=r.querySelector(`div`)?.__xgplayer;e&&(e.paused?e.play():e.pause())}return!0}return!1},handlePaste(e,t){let n=t.clipboardData?.getData(`text/plain`);if(!n)return!1;let r=n.split(/\r?\n/);for(let n of r){let r=n.trim();if(!r||r.includes(` `))continue;let i=sn(r);if(i===`unknown`)continue;t.preventDefault();let a=e.state.schema.nodes.videoEmbed.create({src:r,source:i}),o=e.state.tr.replaceSelectionWith(a);return e.dispatch(o),!0}return!1}}})]},addAttributes(){return{src:{default:null},source:{default:`unknown`},name:{default:``},size:{default:0,parseHTML:e=>Number(e.getAttribute(`data-size`)||0)}}},parseHTML(){return[{tag:`div[data-video-embed]`,getAttrs:e=>{let t=e,n=t.getAttribute(`src`)||t.getAttribute(`data-src`)||``;return{src:n,source:sn(n)}}},{tag:`div[data-bilibili]`},{tag:`div[data-xiaohongshu]`}]},renderHTML({HTMLAttributes:e}){let t=e.src||``,n=sn(t);if(n===`bilibili`){let e=cn(t);return[`div`,{"data-video-embed":`bilibili`,src:t,"data-bvid":e,class:`video-embed video-embed--bilibili`,style:`margin: 1rem 0; border-radius: 12px; overflow: hidden;`},[`iframe`,{src:`https://player.bilibili.com/player.html?bvid=${e}&page=1&high_quality=1`,width:`100%`,height:`400`,frameborder:`0`,allowfullscreen:`true`,scrolling:`no`,style:`border: none; display: block;`}]]}if(n===`xiaohongshu`)return ln(t),[`div`,{"data-video-embed":`xiaohongshu`,src:t,class:`video-embed video-embed--xiaohongshu`,style:`border: 1px solid #e5e7eb; border-radius: 12px; padding: 16px; display: flex; align-items: center; gap: 12px; max-width: 480px; margin: 1rem 0;`},[`div`,{style:`width:40px;height:40px;background:#ff2442;border-radius:10px;display:flex;align-items:center;justify-content:center;color:#fff;font-weight:bold;font-size:14px;flex-shrink:0;`},`红`],[`div`,{},[`div`,{style:`font-weight:600;font-size:14px;`},`小红书笔记`],[`a`,{href:t,target:`_blank`,rel:`noopener noreferrer`,style:`color:#ff2442;font-size:12px;text-decoration:none;`},`在小红书中打开 →`]]];let r=`xgplayer-${Math.random().toString(36).slice(2,8)}`;return[`div`,{"data-video-embed":`direct`,src:t,"data-player-id":r,"data-size":e.size||0,class:`video-embed video-embed--direct`,style:`margin: 1rem 0; border-radius: 12px; overflow: hidden; background: #000;`},[`div`,{id:r,style:`width:100%;max-width:720px;`}]]},addCommands(){return{insertVideo:e=>({chain:t})=>{let n=sn(e.src);return t().insertContent({type:this.name,attrs:{...e,source:n}}).focus().run()}}}}),dn=null,fn={bg:`var(--color-background, #ffffff)`,fg:`var(--color-foreground, #11181c)`,accent:`var(--color-qingwu-600, #0891b2)`,transparent:!0,font:`Inter, 'PingFang SC', 'Microsoft YaHei', 'Noto Sans SC', system-ui, sans-serif`,padding:32},pn=.25,mn=4,hn=.25;async function gn(e,t){dn||=await import(`beautiful-mermaid`);let n=dn.renderMermaidSVG;return n(e,t)}var _n=[{value:`javascript`,label:`JavaScript`,deviconClass:`devicon-javascript-plain`,color:`#f0db4f`},{value:`typescript`,label:`TypeScript`,deviconClass:`devicon-typescript-plain`,color:`#3178c6`},{value:`python`,label:`Python`,deviconClass:`devicon-python-plain`,color:`#306998`},{value:`java`,label:`Java`,deviconClass:`devicon-java-plain`,color:`#b07219`},{value:`go`,label:`Go`,deviconClass:`devicon-go-plain`,color:`#00add8`},{value:`rust`,label:`Rust`,deviconClass:`devicon-rust-plain`,color:`#dea584`},{value:`c`,label:`C`,deviconClass:`devicon-c-plain`,color:`#555555`},{value:`cpp`,label:`C++`,deviconClass:`devicon-cplusplus-plain`,color:`#f34b7d`},{value:`csharp`,label:`C#`,deviconClass:`devicon-csharp-plain`,color:`#178600`},{value:`html`,label:`HTML`,deviconClass:`devicon-html5-plain`,color:`#e34c26`},{value:`css`,label:`CSS`,deviconClass:`devicon-css3-plain`,color:`#563d7c`},{value:`json`,label:`JSON`,deviconClass:`devicon-json-plain`,color:`#292929`},{value:`sql`,label:`SQL`,deviconClass:`devicon-mysql-plain`,color:`#00758f`},{value:`bash`,label:`Bash`,deviconClass:`devicon-bash-plain`,color:`#3dbb58`},{value:`sh`,label:`Shell (sh)`,deviconClass:`devicon-bash-plain`,color:`#3dbb58`},{value:`shell`,label:`PowerShell`,deviconClass:`devicon-powershell-plain`,color:`#3dbb58`},{value:`yaml`,label:`YAML`,deviconClass:`devicon-yaml-plain`,color:`#cb171e`},{value:`php`,label:`PHP`,deviconClass:`devicon-php-plain`,color:`#4f5d95`},{value:`ruby`,label:`Ruby`,deviconClass:`devicon-ruby-plain`,color:`#701516`},{value:`swift`,label:`Swift`,deviconClass:`devicon-swift-plain`,color:`#f05138`},{value:`kotlin`,label:`Kotlin`,deviconClass:`devicon-kotlin-plain`,color:`#a97bff`},{value:`dockerfile`,label:`Dockerfile`,deviconClass:`devicon-docker-plain`,color:`#0db7ed`},{value:`vue`,label:`Vue`,deviconClass:`devicon-vuejs-plain`,color:`#42b883`},{value:`react`,label:`React`,deviconClass:`devicon-react-plain`,color:`#61dafb`},{value:`markdown`,label:`Markdown`,deviconClass:`devicon-markdown-plain`,color:`#083fa1`},{value:`mermaid`,label:`Mermaid`,color:`#ff3670`},{value:`txt`,label:`Plain Text`,color:`#6b7280`}],vn={javascript:`js`,typescript:`ts`,python:`py`,java:`java`,go:`go`,rust:`rs`,c:`c`,cpp:`cpp`,csharp:`cs`,html:`html`,css:`css`,json:`json`,sql:`sql`,bash:`sh`,shell:`sh`,yaml:`yml`,php:`php`,ruby:`rb`,swift:`swift`,kotlin:`kt`,dockerfile:``,markdown:`md`,txt:`txt`,vue:`vue`,react:`jsx`},yn={js:`javascript`,ts:`typescript`,py:`python`,rb:`ruby`,rs:`rust`,kt:`kotlin`,cs:`csharp`,"c++":`cpp`,"c#":`csharp`,golang:`go`,yml:`yaml`,ps1:`shell`,jsx:`javascript`,tsx:`typescript`};function bn({node:t,updateAttributes:n,editor:r,getPos:o,deleteNode:s,selected:c}){let l=r?.isEditable??!0,d=!l,[f,p]=(0,i.useState)(!1),[m,h]=(0,i.useState)(!1),[g,_]=(0,i.useState)(!1),[v,y]=(0,i.useState)(!1),[b,x]=(0,i.useState)(220),[S,C]=(0,i.useState)({top:0,left:0,width:210}),[w,T]=(0,i.useState)(``),[E,D]=(0,i.useState)(!1),[O,k]=(0,i.useState)(null),[A,j]=(0,i.useState)(null),[M,N]=(0,i.useState)(!1),[P,F]=(0,i.useState)(!1),[ee,I]=(0,i.useState)(1),[L,R]=(0,i.useState)({x:0,y:0}),[te,ne]=(0,i.useState)(!1),re=(0,i.useRef)(null),z=(0,i.useRef)(null),B=(0,i.useRef)(null),ie=(0,i.useRef)(null),V=(0,i.useRef)(null),ae=(0,i.useRef)(null),oe=(0,i.useRef)(null),H=t.attrs.language||``,U=_n.find(e=>e.value===(yn[H]??H)),W=H===`mermaid`,se=e=>Math.min(mn,Math.max(pn,e)),G=e=>I(t=>Math.round(se(t+e)*100)/100),K=()=>{I(1),R({x:0,y:0})},ce=()=>{K(),F(!0)};(0,i.useEffect)(()=>{O||F(!1)},[O]),(0,i.useEffect)(()=>{if(!P)return;let e=document.body.style.overflow;document.body.style.overflow=`hidden`;let t=e=>{e.key===`Escape`&&F(!1)};return window.addEventListener(`keydown`,t),()=>{document.body.style.overflow=e,window.removeEventListener(`keydown`,t)}},[P]);let le=e=>{e.button===0&&(e.currentTarget.setPointerCapture(e.pointerId),re.current={x:e.clientX,y:e.clientY,panX:L.x,panY:L.y},ne(!0))},ue=e=>{let t=re.current;t&&R({x:t.panX+e.clientX-t.x,y:t.panY+e.clientY-t.y})},de=()=>{re.current=null,ne(!1)},fe=(0,i.useCallback)(()=>{if(!r||typeof o!=`function`)return null;let e=o();return typeof e==`number`?{from:e,to:e+t.nodeSize}:null},[r,o,t.nodeSize]),pe=(0,i.useCallback)(()=>{l&&(jt()||(oe.current=fe(),window.getSelection()?.removeAllRanges(),$(!0),D(!0)))},[fe,l]),q=(0,i.useMemo)(()=>{let e=w.trim().toLowerCase();return e?_n.filter(t=>t.label.toLowerCase().includes(e)||t.value.toLowerCase().includes(e)):_n},[w]);(0,i.useEffect)(()=>{(ae.current?.closest(`.code-block-node-view`))?.classList.toggle(`code-block-node-view--collapsed`,m)},[m]);let me=(0,i.useCallback)(()=>{let e=ie.current;if(!e)return;let t=e.getBoundingClientRect(),n=Math.min(t.left,window.innerWidth-210-8),r=window.innerHeight-t.bottom-12,i=t.top-12,a=_n.length*31+8,o=r-52,s=i-52;o<220&&s>o?(y(!0),x(Math.max(120,Math.min(a,s))),C({top:t.top,left:n,width:210})):(y(!1),x(Math.max(120,Math.min(a,o))),C({top:t.bottom+4,left:n,width:210}))},[]);(0,i.useEffect)(()=>{if(!g)return;T(``),me();let e=setTimeout(()=>V.current?.focus(),50);return window.addEventListener(`resize`,me),window.addEventListener(`scroll`,me,!0),()=>{clearTimeout(e),window.removeEventListener(`resize`,me),window.removeEventListener(`scroll`,me,!0)}},[g,me]),(0,i.useEffect)(()=>{if(!g)return;let e=e=>{let t=e.target;t&&(ie.current?.contains(t)||B.current?.contains(t)||_(!1))};return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[g]),(0,i.useEffect)(()=>{if(!g)return;let e=e=>{e.key===`Escape`&&_(!1)};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[g]),(0,i.useEffect)(()=>{let e=e=>{if(e.key!==`Backspace`&&e.key!==`Delete`||!l||!c||jt())return;let t=r?.view?.dom,n=e.target;if(r?.isFocused&&n instanceof Node&&t?.contains(n)){if(e.preventDefault(),e.stopPropagation(),r){let{from:e,to:t}=r.state.selection;oe.current={from:e,to:t}}window.getSelection()?.removeAllRanges(),$(!0),D(!0)}};return window.addEventListener(`keydown`,e,!0),()=>window.removeEventListener(`keydown`,e,!0)},[c,r,l]);let he=(0,i.useCallback)(e=>{n({language:e||null}),_(!1)},[n]),ge=(0,i.useCallback)(()=>{if(l){if(r&&o){let e=o();r.chain().focus().setNodeSelection(e).run()}_(!1),(r?.storage?.qingwuUI)?.openAI?.()}},[r,o,l]),_e=(0,i.useCallback)(()=>{let e=t.textContent,n=e=>{let t=document.createElement(`textarea`);t.value=e,t.style.position=`fixed`,t.style.opacity=`0`,document.body.appendChild(t),t.select();try{document.execCommand(`copy`)}catch{}document.body.removeChild(t)};navigator.clipboard?.writeText?navigator.clipboard.writeText(e).catch(()=>n(e)):n(e),p(!0),setTimeout(()=>p(!1),1500)},[t.textContent]),J=(0,i.useCallback)(()=>{let e=vn[H]||`txt`,n=e?`code.${e}`:`code.txt`,r=new Blob([t.textContent],{type:`text/plain;charset=utf-8`}),i=URL.createObjectURL(r),a=document.createElement(`a`);a.href=i,a.download=n,document.body.appendChild(a),a.click(),document.body.removeChild(a),URL.revokeObjectURL(i)},[t.textContent,H]),ve=(0,i.useCallback)(async()=>{if(O||M){k(null),j(null),N(!1);return}N(!0),j(null),k(null);try{let n=(t.textContent||``).trim();if(!n){j(`代码块内容为空`);return}let r=e.r(await gn(n,fn));k(r)}catch(e){j(e instanceof Error?e.message:`Mermaid 渲染失败`)}finally{N(!1)}},[t.textContent,O,M]),ye=(0,a.jsxs)(a.Fragment,{children:[U?U.deviconClass?(0,a.jsx)(`i`,{className:`${U.deviconClass} colored cb-lang-icon`,style:{color:U.color}}):(0,a.jsx)(`span`,{className:`cb-lang-icon cb-lang-icon--auto`,children:`Tx`}):(0,a.jsx)(`span`,{className:`cb-lang-icon cb-lang-icon--auto`,children:`?`}),(0,a.jsx)(`span`,{className:`cb-lang-label`,children:U?.label||`自动`})]});return(0,a.jsxs)(`div`,{ref:ae,className:`cb-react-shell group/cb`,style:{display:`contents`},children:[(0,a.jsxs)(`div`,{className:`cb-header${m?` cb-header--collapsed`:``}`,contentEditable:!1,onMouseDown:e=>e.stopPropagation(),children:[(0,a.jsx)(`div`,{className:`cb-lang-wrap`,ref:z,contentEditable:!1,children:d?(0,a.jsx)(`span`,{className:`cb-lang-trigger cb-lang-trigger--static`,children:ye}):(0,a.jsxs)(`button`,{ref:ie,type:`button`,className:`cb-lang-trigger`,onClick:()=>_(!g),children:[ye,(0,a.jsx)(`svg`,{className:`cb-lang-chevron${g?` cb-lang-chevron--open`:``}`,width:`10`,height:`10`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2.5`,children:(0,a.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M6 9l6 6 6-6`})})]})}),m&&(0,a.jsxs)(`button`,{type:`button`,className:`cb-collapsed-bar`,contentEditable:!1,onClick:()=>h(!1),title:`展开代码块`,children:[ye,(0,a.jsx)(`svg`,{className:`cb-lang-chevron`,width:`12`,height:`12`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2.5`,children:(0,a.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M6 9l6 6 6-6`})})]}),l&&g&&(0,u.createPortal)((0,a.jsxs)(`div`,{ref:B,className:`cb-lang-dropdown${v?` cb-lang-dropdown--up`:``}`,style:{position:`fixed`,top:S.top,left:S.left,width:S.width,zIndex:10002},children:[(0,a.jsxs)(`div`,{className:`cb-lang-search-wrap`,children:[(0,a.jsx)(`svg`,{className:`cb-lang-search-icon`,width:`14`,height:`14`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,children:(0,a.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M21 21l-6-6m2-5a7 7 0 11-14 0 7 7 0 0114 0z`})}),(0,a.jsx)(`input`,{ref:V,className:`cb-lang-search`,type:`text`,placeholder:`搜索语言...`,value:w,onChange:e=>T(e.target.value),onKeyDown:e=>e.stopPropagation()})]}),(0,a.jsxs)(`div`,{className:`cb-lang-list`,style:{maxHeight:b},children:[(0,a.jsxs)(`button`,{type:`button`,className:`cb-lang-option${H?``:` cb-lang-option--active`}`,onClick:()=>he(``),children:[(0,a.jsx)(`span`,{className:`cb-lang-icon cb-lang-icon--auto`,children:`?`}),(0,a.jsx)(`span`,{children:`自动检测`})]}),q.map(e=>(0,a.jsxs)(`button`,{type:`button`,className:`cb-lang-option${H===e.value?` cb-lang-option--active`:``}`,onClick:()=>he(e.value),children:[e.deviconClass?(0,a.jsx)(`i`,{className:`${e.deviconClass} colored cb-lang-icon`,style:{color:e.color}}):(0,a.jsx)(`span`,{className:`cb-lang-icon cb-lang-icon--auto`,children:`Tx`}),(0,a.jsx)(`span`,{children:e.label})]},e.value)),q.length===0&&(0,a.jsx)(`div`,{className:`cb-lang-empty`,children:`无匹配语言`})]})]}),document.body),(0,a.jsxs)(`div`,{className:`cb-actions`,children:[(0,a.jsx)(`button`,{type:`button`,className:`cb-btn`,onClick:()=>h(!m),contentEditable:!1,title:m?`展开`:`折叠`,children:(0,a.jsx)(`svg`,{className:`cb-btn-icon`,fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,strokeWidth:`2`,children:m?(0,a.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M6 9l6 6 6-6`}):(0,a.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M6 15l6-6 6 6`})})}),(0,a.jsx)(`button`,{type:`button`,className:`cb-btn`,onClick:_e,contentEditable:!1,title:`复制`,children:f?(0,a.jsx)(`svg`,{className:`cb-btn-icon cb-btn-icon--check`,fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,strokeWidth:`2.5`,children:(0,a.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M5 13l4 4L19 7`})}):(0,a.jsx)(`svg`,{className:`cb-btn-icon`,fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,strokeWidth:`2`,children:(0,a.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M8 16H6a2 2 0 01-2-2V6a2 2 0 012-2h8a2 2 0 012 2v2m-6 12h8a2 2 0 002-2v-8a2 2 0 00-2-2h-8a2 2 0 00-2 2v8a2 2 0 002 2z`})})}),(0,a.jsx)(`button`,{type:`button`,className:`cb-btn`,onClick:J,contentEditable:!1,title:`下载`,children:(0,a.jsx)(`svg`,{className:`cb-btn-icon`,fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,strokeWidth:`2`,children:(0,a.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M4 16v1a3 3 0 003 3h10a3 3 0 003-3v-1m-4-4l-4 4m0 0l-4-4m4 4V4`})})}),l&&(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(`button`,{type:`button`,className:`cb-btn cb-btn--ai`,onClick:ge,contentEditable:!1,title:`写作助手`,children:(0,a.jsx)(`svg`,{className:`cb-btn-icon`,fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,strokeWidth:`2`,children:(0,a.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M13 10V3L4 14h7v7l9-11h-7z`})})}),(0,a.jsx)(`button`,{type:`button`,className:`cb-btn cb-btn--del`,onClick:pe,contentEditable:!1,title:`删除代码块`,children:(0,a.jsx)(`svg`,{className:`cb-btn-icon`,fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,strokeWidth:`2`,children:(0,a.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16`})})})]}),W&&(0,a.jsx)(`button`,{type:`button`,className:`cb-btn cb-btn--diagram`,onClick:ve,contentEditable:!1,title:O||M?`取消渲染`:`渲染图表`,disabled:M,children:(0,a.jsx)(`svg`,{className:`cb-btn-icon`,fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,strokeWidth:`2`,children:(0,a.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M4 5a1 1 0 011-1h4a1 1 0 011 1v5a1 1 0 01-1 1H5a1 1 0 01-1-1V5zM14 5a1 1 0 011-1h4a1 1 0 011 1v2a1 1 0 01-1 1h-4a1 1 0 01-1-1V5zM4 16a1 1 0 011-1h4a1 1 0 011 1v3a1 1 0 01-1 1H5a1 1 0 01-1-1v-3zM14 13a1 1 0 011-1h4a1 1 0 011 1v6a1 1 0 01-1 1h-4a1 1 0 01-1-1v-6z`})})})]})]}),(O||A||M)&&(0,a.jsxs)(`div`,{className:`cb-diagram-output`,contentEditable:!1,children:[M&&(0,a.jsx)(`div`,{className:`cb-diagram-loading`,children:`渲染图表中…`}),A&&(0,a.jsxs)(`div`,{className:`cb-diagram-error`,children:[(0,a.jsx)(`span`,{className:`cb-diagram-error-icon`,children:`!`}),A]}),O&&(0,a.jsxs)(`div`,{className:`cb-diagram-svg`,role:`button`,tabIndex:0,title:`点击放大查看`,onClick:ce,onKeyDown:e=>{(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),ce())},children:[(0,a.jsx)(`div`,{className:`cb-diagram-svg-inner`,dangerouslySetInnerHTML:{__html:O}}),(0,a.jsx)(`span`,{className:`cb-diagram-zoom-hint`,children:`点击放大`})]})]}),P&&O&&(0,u.createPortal)((0,a.jsxs)(`div`,{className:`fixed inset-0 z-[10002] flex flex-col bg-black/75 backdrop-blur-sm select-none`,role:`dialog`,"aria-modal":`true`,"aria-label":`Mermaid 图表预览`,children:[(0,a.jsxs)(`div`,{className:`flex items-center justify-between gap-3 px-4 py-3 text-white`,children:[(0,a.jsx)(`span`,{className:`text-sm font-medium`,children:`Mermaid 图表`}),(0,a.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,a.jsx)(`button`,{type:`button`,className:`flex h-8 min-w-8 items-center justify-center rounded-lg bg-white/10 px-2 text-base text-white transition-colors hover:bg-white/20`,onClick:()=>G(-.25),title:`缩小`,"aria-label":`缩小`,children:`−`}),(0,a.jsxs)(`button`,{type:`button`,className:`flex h-8 min-w-14 items-center justify-center rounded-lg bg-white/10 px-2 text-xs text-white transition-colors hover:bg-white/20`,onClick:K,title:`重置为 100%`,"aria-label":`重置缩放`,children:[Math.round(ee*100),`%`]}),(0,a.jsx)(`button`,{type:`button`,className:`flex h-8 min-w-8 items-center justify-center rounded-lg bg-white/10 px-2 text-base text-white transition-colors hover:bg-white/20`,onClick:()=>G(hn),title:`放大`,"aria-label":`放大`,children:`+`}),(0,a.jsx)(`button`,{type:`button`,className:`flex h-8 min-w-8 items-center justify-center rounded-lg bg-white/10 px-2 text-sm text-white transition-colors hover:bg-white/20`,onClick:K,title:`重置`,"aria-label":`重置`,children:`⟲`}),(0,a.jsx)(`span`,{className:`mx-1 h-5 w-px bg-white/20`}),(0,a.jsx)(`button`,{type:`button`,className:`flex h-8 min-w-8 items-center justify-center rounded-lg bg-white/10 px-2 text-lg text-white transition-colors hover:bg-white/20`,onClick:()=>F(!1),title:`关闭`,"aria-label":`关闭`,children:`×`})]})]}),(0,a.jsx)(`div`,{className:`flex flex-1 touch-none items-center justify-center overflow-hidden`,style:{cursor:te?`grabbing`:ee>1?`grab`:`default`},onWheel:e=>G(e.deltaY>0?-.25:hn),onPointerDown:le,onPointerMove:ue,onPointerUp:de,onPointerCancel:de,onDoubleClick:()=>{I(e=>e===1?2:1),R({x:0,y:0})},children:(0,a.jsx)(`div`,{className:`cb-diagram-zoom-content`,style:{transform:`translate(${L.x}px, ${L.y}px) scale(${ee})`,transition:te?`none`:`transform 120ms ease-out`},dangerouslySetInnerHTML:{__html:O}})})]}),document.body),(0,a.jsx)(It,{open:E,title:`确认删除代码块`,message:`此操作不可撤销。`,onCancel:()=>{$(!1),D(!1)},onConfirm:async()=>{await new Promise(e=>setTimeout(e,300)),$(!1),s()}})]})}var xn=[{value:`javascript`,label:`JavaScript`},{value:`typescript`,label:`TypeScript`},{value:`python`,label:`Python`},{value:`java`,label:`Java`},{value:`go`,label:`Go`},{value:`rust`,label:`Rust`},{value:`c`,label:`C`},{value:`cpp`,label:`C++`},{value:`csharp`,label:`C#`},{value:`html`,label:`HTML/XML`},{value:`css`,label:`CSS`},{value:`json`,label:`JSON`},{value:`sql`,label:`SQL`},{value:`bash`,label:`Bash`},{value:`shell`,label:`Shell`},{value:`yaml`,label:`YAML`},{value:`php`,label:`PHP`},{value:`ruby`,label:`Ruby`},{value:`swift`,label:`Swift`},{value:`kotlin`,label:`Kotlin`},{value:`dockerfile`,label:`Dockerfile`},{value:`vue`,label:`Vue`},{value:`react`,label:`React`},{value:`markdown`,label:`Markdown`},{value:`mermaid`,label:`Mermaid`}],Sn=(0,N.createLowlight)(N.common);Sn.register({dockerfile:M.default}),Sn.registerAlias(`xml`,[`vue`,`html`]),Sn.registerAlias(`javascript`,[`react`,`jsx`]),Sn.registerAlias(`typescript`,[`tsx`]);function Cn(e){return e?e.split(`
|
|
3
|
+
`);l=n.pop()||``;for(let e of n){let t=e.trim();if(!t||!t.startsWith(`data: `))continue;let n=t.slice(6);if(n===`[DONE]`)return;try{let e=JSON.parse(n).choices?.[0]?.delta?.content;e&&(yield e)}catch{}}}}return{async*stream(e){yield*a(je(e.mode,e.instruction),e.context)},async generate(e){let t=je(e.mode,e.instruction),n=``;for await(let r of a(t,e.context))n+=r;return n}}}function Ie(e){return Fe({apiKey:e.apiKey,baseURL:e.baseURL||`https://api.deepseek.com/v1`,model:e.model||`deepseek-v4-flash`,headers:e.headers})}function Le(e){return Fe({apiKey:e.apiKey,baseURL:e.baseURL||`https://api.openai.com/v1`,model:e.model||`gpt-5.6-luna`,headers:e.headers})}function Re(e){return Fe({apiKey:e.apiKey,baseURL:e.baseURL||`https://dashscope.aliyuncs.com/compatible-mode/v1`,model:e.model||`qwen3.7-plus`,headers:e.headers})}var ze={keyword:``,caseSensitive:!1,wholeWord:!1,matches:[],currentIndex:-1},Z=new f.PluginKey(`search-highlight`);function Be(e){return e.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`)}function Ve(e,t){let{keyword:n,caseSensitive:r,wholeWord:i}=t;if(!n)return[];let a=r?`g`:`gi`,o=i?`\\b${Be(n)}\\b`:Be(n),s=new RegExp(o,a),c=[];return e.descendants((e,t)=>{if(!e.isText||!e.text)return;s.lastIndex=0;let n;for(;(n=s.exec(e.text))!==null;){let e=t+n.index,r=e+n[0].length;c.push({from:e,to:r}),n[0].length===0&&s.lastIndex++}}),c}function He(e,t){if(t.matches.length===0)return p.DecorationSet.empty;let n=t.matches.map((e,n)=>p.Decoration.inline(e.from,e.to,{class:n===t.currentIndex?`search-highlight search-highlight--active`:`search-highlight`}));return p.DecorationSet.create(e,n)}function Ue(e,t){if(t.currentIndex<0||t.currentIndex>=t.matches.length)return;let n=t.matches[t.currentIndex];n&&requestAnimationFrame(()=>{try{let t=e.dom.querySelector(`.search-highlight--active`);if(t){let e=t.getBoundingClientRect(),n=window.innerHeight-80;(e.top<120||e.bottom>n)&&t.scrollIntoView({behavior:`smooth`,block:`center`});return}let r=e.coordsAtPos(n.from),i=window.innerHeight-80;if(r.top<120||r.top>i){let e=r.top-window.innerHeight/2;window.scrollBy({top:e,behavior:`smooth`})}}catch{}})}var We=d.Extension.create({name:`searchHighlight`,addProseMirrorPlugins(){return[new f.Plugin({key:Z,state:{init:()=>ze,apply(e,t){let n=e.getMeta(Z);if(n)return{...t,...n,matches:n.matches===void 0?t.matches:n.matches,currentIndex:n.currentIndex===void 0?t.currentIndex:n.currentIndex};if(e.docChanged&&t.keyword){let n=Ve(e.doc,t),r=t.currentIndex;return r>=n.length&&(r=n.length-1),r<0&&(r=n.length>0?0:-1),{...t,matches:n,currentIndex:r}}return t}},props:{decorations(e){let t=Z.getState(e);return t?He(e.doc,t):p.DecorationSet.empty}}})]},addCommands(){return{setSearch:(e,t={})=>({state:n,dispatch:r,view:i})=>{let a=Z.getState(n)||ze,o={keyword:e,caseSensitive:t.caseSensitive??a.caseSensitive,wholeWord:t.wholeWord??a.wholeWord,matches:[],currentIndex:-1};return o.matches=Ve(n.doc,o),o.currentIndex=o.matches.length>0?0:-1,r&&(r(n.tr.setMeta(Z,o)),i&&Ue(i,o)),!0},nextMatch:()=>({state:e,dispatch:t,view:n})=>{let r=Z.getState(e)||ze;if(r.matches.length===0)return!1;let i=(r.currentIndex+1)%r.matches.length;return t&&(t(e.tr.setMeta(Z,{currentIndex:i})),n&&Ue(n,{...r,currentIndex:i})),!0},prevMatch:()=>({state:e,dispatch:t,view:n})=>{let r=Z.getState(e)||ze;if(r.matches.length===0)return!1;let i=(r.currentIndex-1+r.matches.length)%r.matches.length;return t&&(t(e.tr.setMeta(Z,{currentIndex:i})),n&&Ue(n,{...r,currentIndex:i})),!0},clearSearch:()=>({state:e,dispatch:t})=>(t&&t(e.tr.setMeta(Z,ze)),!0)}}});function Ge(e){let t=e.state;return Z.getState(t)||ze}var Ke=({editor:e,onClose:t})=>{let[n,r]=(0,i.useState)(``),[o,s]=(0,i.useState)(!1),[c,l]=(0,i.useState)(!1),[u,d]=(0,i.useState)(0),f=(0,i.useRef)(null),p=(0,i.useRef)({keyword:n,caseSensitive:o,wholeWord:c});p.current={keyword:n,caseSensitive:o,wholeWord:c},(0,i.useEffect)(()=>{if(!e)return;let t=0,n=()=>{t&&cancelAnimationFrame(t),t=requestAnimationFrame(()=>{t=0,d(e=>(e+1)%1e6)})};return e.on(`update`,n),()=>{e.off(`update`,n),t&&cancelAnimationFrame(t)}},[e]),(0,i.useEffect)(()=>{let e=setTimeout(()=>f.current?.focus(),30);return()=>clearTimeout(e)},[]),(0,i.useEffect)(()=>{if(!e)return;let t=requestAnimationFrame(()=>{let{keyword:t,caseSensitive:n,wholeWord:r}=p.current;try{e.commands.setSearch(t,{caseSensitive:n,wholeWord:r})}catch(e){console.warn(`[SearchBar] setSearch failed:`,e)}});return()=>cancelAnimationFrame(t)},[e,n,o,c]),(0,i.useEffect)(()=>()=>{try{e?.commands.clearSearch()}catch{}},[]),(0,i.useEffect)(()=>{let e=e=>{e.key===`Escape`&&(e.preventDefault(),e.stopPropagation(),t())};return window.addEventListener(`keydown`,e,!0),()=>window.removeEventListener(`keydown`,e,!0)},[t]);let m=(0,i.useCallback)(()=>{try{e?.commands.nextMatch()}catch{}},[e]),h=(0,i.useCallback)(()=>{try{e?.commands.prevMatch()}catch{}},[e]),g=(0,i.useCallback)(e=>{e.stopPropagation(),e.key===`Enter`&&(e.preventDefault(),e.shiftKey?h():m())},[m,h]),_=(0,i.useMemo)(()=>{if(!e)return null;try{return Ge(e)}catch{return null}},[e,n,o,c,u]),v=n?_&&_.matches.length>0?`${_.currentIndex+1} / ${_.matches.length}`:`无匹配`:``,y=(0,i.useCallback)(e=>{e.stopPropagation()},[]);return(0,a.jsx)(`div`,{className:`search-bar`,role:`search`,"aria-label":`文档内搜索`,onClick:y,onMouseDown:y,children:(0,a.jsxs)(`div`,{className:`search-bar__main`,children:[(0,a.jsx)(`svg`,{className:`search-bar__icon`,width:`14`,height:`14`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,children:(0,a.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M21 21l-6-6m2-5a7 7 0 11-14 0 7 7 0 0114 0z`})}),(0,a.jsx)(`input`,{ref:f,type:`text`,className:`search-bar__input`,placeholder:`查找…`,value:n,onChange:e=>r(e.target.value),onKeyDown:g,onKeyUp:y,onKeyPress:y,onInput:y,spellCheck:!1,autoComplete:`off`,inputMode:`text`}),(0,a.jsx)(`span`,{className:`search-bar__count`,children:v}),(0,a.jsx)(`button`,{type:`button`,className:`search-bar__toggle${o?` search-bar__toggle--active`:``}`,onClick:()=>s(e=>!e),title:`区分大小写 (Aa)`,"aria-pressed":o,children:`Aa`}),(0,a.jsx)(`button`,{type:`button`,className:`search-bar__toggle${c?` search-bar__toggle--active`:``}`,onClick:()=>l(e=>!e),title:`整词匹配 (\\b)`,"aria-pressed":c,children:`\\b`}),(0,a.jsx)(`div`,{className:`search-bar__sep`}),(0,a.jsx)(`button`,{type:`button`,className:`search-bar__btn`,onClick:h,title:`上一个 (Shift+Enter)`,disabled:!_||_.matches.length===0,children:(0,a.jsx)(`svg`,{width:`14`,height:`14`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,children:(0,a.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M5 15l7-7 7 7`})})}),(0,a.jsx)(`button`,{type:`button`,className:`search-bar__btn`,onClick:m,title:`下一个 (Enter)`,disabled:!_||_.matches.length===0,children:(0,a.jsx)(`svg`,{width:`14`,height:`14`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,children:(0,a.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M19 9l-7 7-7-7`})})}),(0,a.jsx)(`button`,{type:`button`,className:`search-bar__btn search-bar__btn--close`,onClick:t,title:`关闭 (Esc)`,children:(0,a.jsx)(`svg`,{width:`14`,height:`14`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,children:(0,a.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M6 18L18 6M6 6l12 12`})})})]})})};function Q({children:e,...t}){return(0,a.jsx)(`svg`,{width:16,height:16,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:2,strokeLinecap:`round`,strokeLinejoin:`round`,"aria-hidden":`true`,...t,children:e})}var qe=e=>(0,a.jsxs)(Q,{...e,children:[(0,a.jsx)(`path`,{d:`M6 4h8a4 4 0 0 1 0 8H6z`}),(0,a.jsx)(`path`,{d:`M6 12h9a4 4 0 0 1 0 8H6z`})]}),Je=e=>(0,a.jsxs)(Q,{...e,children:[(0,a.jsx)(`path`,{d:`M19 4h-9`}),(0,a.jsx)(`path`,{d:`M14 20H5`}),(0,a.jsx)(`path`,{d:`M15 4 9 20`})]}),Ye=e=>(0,a.jsxs)(Q,{...e,children:[(0,a.jsx)(`path`,{d:`M6 4v6a6 6 0 0 0 12 0V4`}),(0,a.jsx)(`path`,{d:`M4 20h16`})]}),Xe=e=>(0,a.jsxs)(Q,{...e,children:[(0,a.jsx)(`path`,{d:`M16 4H9a3 3 0 0 0-2.83 4`}),(0,a.jsx)(`path`,{d:`M14 12a4 4 0 0 1 0 8H6`}),(0,a.jsx)(`path`,{d:`M4 12h16`})]}),Ze=e=>(0,a.jsxs)(Q,{...e,children:[(0,a.jsx)(`path`,{d:`m16 18 6-6-6-6`}),(0,a.jsx)(`path`,{d:`m8 6-6 6 6 6`})]}),Qe=e=>(0,a.jsxs)(Q,{...e,children:[(0,a.jsx)(`path`,{d:`m9 11-6 6v3h9l3-3`}),(0,a.jsx)(`path`,{d:`m22 12-4.6 4.6a2 2 0 0 1-2.8 0l-5.2-5.2a2 2 0 0 1 0-2.8L14 4`})]}),$e=e=>(0,a.jsxs)(Q,{...e,children:[(0,a.jsx)(`path`,{d:`M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71`}),(0,a.jsx)(`path`,{d:`M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71`})]}),et=e=>(0,a.jsxs)(Q,{...e,children:[(0,a.jsx)(`rect`,{x:`3`,y:`3`,width:`18`,height:`18`,rx:`2`,ry:`2`}),(0,a.jsx)(`path`,{d:`M3 9h18M3 15h18M9 3v18M15 3v18`})]}),tt=e=>(0,a.jsxs)(Q,{...e,children:[(0,a.jsx)(`rect`,{x:`8`,y:`8`,width:`14`,height:`14`,rx:`2`,ry:`2`}),(0,a.jsx)(`path`,{d:`M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2`})]}),nt=e=>(0,a.jsxs)(Q,{...e,children:[(0,a.jsx)(`circle`,{cx:`11`,cy:`11`,r:`8`}),(0,a.jsx)(`path`,{d:`m21 21-4.3-4.3`})]}),rt=e=>(0,a.jsxs)(Q,{...e,children:[(0,a.jsx)(`path`,{d:`M12 3l1.6 4.4L18 9l-4.4 1.6L12 15l-1.6-4.4L6 9l4.4-1.6L12 3z`}),(0,a.jsx)(`path`,{d:`M18.5 14l.7 1.9 1.9.7-1.9.7-.7 1.9-.7-1.9-1.9-.7 1.9-.7.7-1.9z`})]}),it=e=>(0,a.jsxs)(Q,{...e,children:[(0,a.jsx)(`circle`,{cx:`5`,cy:`12`,r:`1`}),(0,a.jsx)(`circle`,{cx:`12`,cy:`12`,r:`1`}),(0,a.jsx)(`circle`,{cx:`19`,cy:`12`,r:`1`})]}),at=e=>(0,a.jsxs)(Q,{...e,children:[(0,a.jsx)(`path`,{d:`M18 6 6 18`}),(0,a.jsx)(`path`,{d:`m6 6 12 12`})]});async function ot(e){if(e){if(e.startsWith(`blob:`)){URL.revokeObjectURL(e);return}try{await n.n().remove(e)}catch(e){console.warn(`删除存储资源失败:`,e)}}}var st=3e4,ct=new Set([`image`,`attachmentEmbed`,`audioEmbed`,`videoEmbed`]),lt=new WeakMap;function ut(e){let t=new Set;return e.state.doc.descendants(e=>{if(ct.has(e.type.name)){let n=e.attrs.src;n&&t.add(n)}return!0}),t}function dt(e){let t=lt.get(e);return t||(t={timers:new Map,onTransaction:()=>{},listening:!1},lt.set(e,t)),t}function ft(e,t){let n=[...new Set(t.filter(Boolean))];if(n.length===0)return;let r=dt(e);r.listening||=(r.onTransaction=()=>{if(r.timers.size===0)return;let t=ut(e);for(let[e,n]of r.timers)t.has(e)&&(clearTimeout(n),r.timers.delete(e))},e.on(`transaction`,r.onTransaction),!0);for(let t of n){if(r.timers.has(t))continue;let n=setTimeout(()=>{ut(e).has(t)||ot(t),r.timers.delete(t)},st);r.timers.set(t,n)}}function pt(e){let t=lt.get(e);if(t){if(t.listening&&=(e.off(`transaction`,t.onTransaction),!1),t.timers.size>0){let n=ut(e);for(let[e,r]of t.timers)clearTimeout(r),n.has(e)||ot(e);t.timers.clear()}lt.delete(e)}}var mt=[{mode:`continue`,labelKey:`editor.ai.continue`,descKey:`editor.ai.continueDesc`,icon:`→`},{mode:`improve`,labelKey:`editor.ai.improve`,descKey:`editor.ai.improveDesc`,icon:`✨`},{mode:`shorter`,labelKey:`editor.ai.shorter`,descKey:`editor.ai.shorterDesc`,icon:`↓`},{mode:`longer`,labelKey:`editor.ai.longer`,descKey:`editor.ai.longerDesc`,icon:`↑`},{mode:`fix`,labelKey:`editor.ai.fix`,descKey:`editor.ai.fixDesc`,icon:`✓`},{mode:`translate`,labelKey:`editor.ai.translate`,descKey:`editor.ai.translateDesc`,icon:`🌐`},{mode:`zap`,labelKey:`editor.ai.zap`,descKey:`editor.ai.zapDesc`,icon:`⚡`}],ht=new Set([`image`,`attachmentEmbed`,`audioEmbed`,`videoEmbed`]),gt={image:`editor.ai.nodeImage`,attachmentEmbed:`editor.ai.nodeAttachment`,videoEmbed:`editor.ai.nodeVideo`,audioEmbed:`editor.ai.nodeAudio`};function _t(e,t){return e.storage.qingwuUI?.parseMd?.(e.schema,t)||null}function vt(e,t,n){let r=[];return e.state.doc.nodesBetween(t,n,e=>{if(ht.has(e.type.name)){let t=e.attrs.src;t&&r.push({type:e.type.name,src:t})}return!0}),r}function yt(e){let t=new Set;return e.state.doc.descendants(e=>{if(ht.has(e.type.name)){let n=e.attrs.src;n&&t.add(n)}return!0}),t}function bt(e,t){let n=_t(e,t);if(n&&n.size>0){let t=e.state.tr;t.replaceWith(0,e.state.doc.content.size,n),t.setSelection(f.TextSelection.create(t.doc,t.doc.content.size)),e.view.dispatch(t.scrollIntoView()),e.commands.focus();return}e.commands.setContent(t),e.commands.focus()}function xt(e,t,n,r){let i=_t(e,t);if(e.commands.focus(),!i){let i=e.chain().focus();n===`replace`?i.setTextSelection({from:r.from,to:r.to}).deleteSelection().insertContent(t).run():i.insertContentAt(r.to,t).run();return}let a=e.state.tr;n===`replace`?a.replaceRange(r.from,r.to,new s.Slice(i,0,0)):a.insert(Math.min(r.to,e.state.doc.content.size),i),e.view.dispatch(a.scrollIntoView())}function St({editor:t,onClose:n}){let[r,o]=(0,i.useState)(null),[s,c]=(0,i.useState)(``),[l,u]=(0,i.useState)(``),[d,f]=(0,i.useState)(!1),[p,m]=(0,i.useState)(null),[h,g]=(0,i.useState)(null),_=(0,i.useRef)({from:0,to:0,empty:!0}),v=(0,i.useRef)(null),y=(0,i.useRef)(null),b=(0,i.useRef)(!0),x=(0,i.useCallback)(async e=>{if(o(e),m(null),e!==`zap`){await S(e);return}setTimeout(()=>v.current?.focus(),100)},[t]),S=(0,i.useCallback)(async n=>{let r=t.state.selection;_.current={from:r.from,to:r.to,empty:r.empty},f(!0),u(``),b.current=!0,m(null);try{let e=X(),i=r.empty?t.state.doc.textContent:t.state.doc.textBetween(r.from,r.to),a=[];for await(let t of e.stream({mode:n,context:i,instruction:n===`zap`?s:void 0}))a.push(t),u(a.join(``))}catch(t){m(t instanceof Error?t.message:e.o(`editor.ai.error`))}finally{f(!1)}},[t,s]);(0,i.useEffect)(()=>{let e=y.current;if(!e)return;let t=()=>{let t=e.scrollHeight-e.scrollTop-e.clientHeight<24;b.current=t};return e.addEventListener(`scroll`,t,{passive:!0}),()=>e.removeEventListener(`scroll`,t)},[!!l]),(0,i.useLayoutEffect)(()=>{let e=y.current;!e||!b.current||(e.scrollTop=e.scrollHeight)},[l]);let C=(0,i.useCallback)((e,n,r)=>{let i=new Set(vt(t,r.from,r.to).map(e=>e.src));e===`replaceAll`?bt(t,n):xt(t,n,`replace`,_.current);let a=yt(t);ft(t,[...i].filter(e=>!a.has(e)))},[t]),w=(0,i.useCallback)(e=>{if(e===`below`){xt(t,l,`below`,_.current),n();return}let r=_.current,i=e===`replaceAll`?{from:0,to:t.state.doc.content.size}:{from:r.from,to:r.to},a=vt(t,i.from,i.to);if(a.length>0){g({position:e,willRemove:a});return}C(e,l,i),n()},[t,l,C,n]),T=(0,i.useCallback)(()=>{if(!h)return;let{position:e}=h,r=e===`replaceAll`?{from:0,to:t.state.doc.content.size}:{from:_.current.from,to:_.current.to};C(e,l,r),g(null),n()},[h,t,l,C,n]),E=(0,i.useCallback)(()=>{u(``),o(null),m(null)},[]),D={};for(let e of h?.willRemove??[])D[e.type]=(D[e.type]??0)+1;return(0,a.jsxs)(a.Fragment,{children:[(0,a.jsxs)(`div`,{className:`ai-selector w-full flex-1 min-h-0 flex flex-col`,children:[(0,a.jsxs)(`div`,{className:`flex items-center justify-between pl-3 pr-1.5 py-1.5 border-b border-default-100 shrink-0`,children:[(0,a.jsxs)(`span`,{className:`flex items-center gap-1.5 text-xs font-medium text-default-500`,children:[(0,a.jsx)(rt,{className:`text-primary`}),e.o(`editor.ai.trigger`)]}),(0,a.jsx)(`button`,{type:`button`,onClick:n,"aria-label":e.o(`editor.ai.close`),title:e.o(`editor.ai.close`),className:`flex items-center justify-center w-6 h-6 rounded-md text-default-400 hover:bg-default-100 hover:text-default-700 transition-colors`,children:(0,a.jsx)(at,{})})]}),(0,a.jsx)(`div`,{className:`grid grid-cols-[repeat(auto-fit,minmax(64px,1fr))] gap-1.5 p-2 shrink-0`,children:mt.map(({mode:t,labelKey:n,descKey:i,icon:o})=>(0,a.jsxs)(`button`,{type:`button`,className:`flex flex-col items-center gap-1 px-1 py-2 rounded-xl border transition-colors ${r===t?`border-primary/40 bg-primary/10 text-primary`:`border-default-200 text-default-600 hover:bg-default-100 hover:text-default-900`}`,onClick:()=>x(t),title:e.o(i),children:[(0,a.jsx)(`span`,{className:`text-base leading-none`,children:o}),(0,a.jsx)(`span`,{className:`text-[11px] leading-none truncate`,children:e.o(n)})]},t))}),(0,a.jsxs)(`div`,{className:`px-3 pb-3 flex-1 min-h-0 flex flex-col`,children:[!r&&(0,a.jsx)(`p`,{className:`text-[11px] text-default-400 leading-relaxed`,children:e.o(`editor.ai.triggerDesc`)}),r===`zap`&&!d&&!l&&!p&&(0,a.jsxs)(`div`,{children:[(0,a.jsx)(`input`,{ref:v,className:`w-full px-3 py-2 text-sm border border-default-200 rounded-lg focus:outline-none focus:border-primary bg-background`,placeholder:e.o(`editor.ai.customPlaceholder`),value:s,onChange:e=>c(e.target.value),onKeyDown:e=>{e.key===`Enter`&&s.trim()&&S(`zap`)}}),(0,a.jsxs)(`div`,{className:`flex gap-2 mt-2`,children:[(0,a.jsx)(`button`,{type:`button`,className:`px-3 py-1.5 text-xs bg-primary text-white rounded-lg disabled:opacity-50`,disabled:!s.trim(),onClick:()=>S(`zap`),children:e.o(`editor.ai.confirm`)}),(0,a.jsx)(`button`,{type:`button`,className:`px-3 py-1.5 text-xs border border-default-200 rounded-lg hover:bg-default-100`,onClick:()=>o(null),children:e.o(`editor.ai.back`)})]})]}),(d||l||p)&&(0,a.jsxs)(`div`,{className:`flex-1 min-h-0 flex flex-col`,children:[d&&!l&&(0,a.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-default-500`,children:[(0,a.jsx)(`span`,{className:`animate-spin`,children:`⏳`}),e.o(`editor.ai.thinking`)]}),l&&(0,a.jsxs)(a.Fragment,{children:[(0,a.jsxs)(`div`,{ref:y,className:`flex-1 min-h-0 overflow-y-auto text-sm whitespace-pre-wrap text-default-700 mb-3`,children:[l,d&&(0,a.jsx)(`span`,{className:`animate-pulse`,children:`▊`})]}),!d&&(0,a.jsxs)(`div`,{className:`flex gap-2 shrink-0`,children:[_.current.empty?(0,a.jsx)(`button`,{type:`button`,className:`px-3 py-1.5 text-xs bg-primary text-white rounded-lg`,onClick:()=>w(`replaceAll`),children:e.o(`editor.ai.replaceAll`)}):(0,a.jsx)(`button`,{type:`button`,className:`px-3 py-1.5 text-xs bg-primary text-white rounded-lg`,onClick:()=>w(`replace`),children:e.o(`editor.ai.replace`)}),(0,a.jsx)(`button`,{type:`button`,className:`px-3 py-1.5 text-xs border border-default-200 rounded-lg hover:bg-default-100`,onClick:()=>w(`below`),children:e.o(`editor.ai.insert`)}),(0,a.jsx)(`button`,{type:`button`,className:`px-3 py-1.5 text-xs text-danger`,onClick:E,children:e.o(`editor.ai.discard`)})]})]}),p&&(0,a.jsxs)(`div`,{className:`text-sm text-danger`,children:[(0,a.jsx)(`p`,{children:p}),(0,a.jsx)(`button`,{type:`button`,className:`mt-2 px-3 py-1 text-xs border border-default-200 rounded-lg hover:bg-default-100`,onClick:()=>{m(null),o(null)},children:e.o(`editor.ai.back`)})]})]})]})]}),h&&(0,a.jsxs)(`div`,{className:`qed-root`,style:{zIndex:1e4},onClick:()=>g(null),children:[(0,a.jsx)(`div`,{className:`qed-backdrop`,onClick:()=>g(null)}),(0,a.jsxs)(`div`,{className:`qed-card animate-in`,onClick:e=>e.stopPropagation(),children:[(0,a.jsxs)(`div`,{className:`qed-header`,children:[(0,a.jsx)(`h2`,{className:`qed-title`,children:h.position===`replaceAll`?e.o(`editor.ai.replaceAllTitle`):e.o(`editor.ai.replaceTitle`)}),(0,a.jsx)(`button`,{type:`button`,className:`qed-close`,onClick:()=>g(null),"aria-label":e.o(`editor.ai.close`),children:`✕`})]}),(0,a.jsxs)(`div`,{className:`qed-body`,children:[(0,a.jsx)(`p`,{className:`mb-2`,children:h.position===`replaceAll`?e.o(`editor.ai.replaceAllText`):e.o(`editor.ai.replaceText`)}),Object.keys(D).length>0&&(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(`p`,{className:`text-xs text-default-500`,children:e.o(`editor.ai.removeNodes`)}),(0,a.jsx)(`ul`,{className:`mt-1 space-y-0.5`,children:Object.entries(D).map(([t,n])=>(0,a.jsxs)(`li`,{className:`text-sm text-default-700`,children:[e.o(gt[t]??t),` ×`,n]},t))})]})]}),(0,a.jsxs)(`div`,{className:`qed-footer`,style:{display:`flex`,justifyContent:`flex-end`,gap:8},children:[(0,a.jsx)(`button`,{type:`button`,className:`qed-btn qed-btn--ghost`,onClick:()=>g(null),children:e.o(`editor.ai.cancel`)}),(0,a.jsx)(`button`,{type:`button`,className:`qed-btn qed-btn--primary`,onClick:T,children:e.o(`editor.ai.confirmReplace`)})]})]})]})]})}var Ct=new Set([`attachmentEmbed`,`videoEmbed`,`audioEmbed`,`image`]);function wt(e){let t=0;return e.descendants(e=>{Ct.has(e.type.name)&&(t+=Number(e.attrs?.size)||0)}),t}function Tt(e){if(!Number.isFinite(e)||e<=0)return`0 B`;let t=[`B`,`KB`,`MB`,`GB`,`TB`],n=Math.min(t.length-1,Math.floor(Math.log(e)/Math.log(1024))),r=e/1024**n;return`${n===0||r>=100?`${Math.round(r)}`:`${Math.round(r*10)/10}`} ${t[n]}`}function Et(e){return(e?.storage)?.qingwuUI?.limits}function Dt(e,t,n){let{maxAttachmentSize:r,maxTotalAttachmentSize:i}=n;if(r&&t.size>r)return`单文件大小不能超过 ${Tt(r)}(当前 ${Tt(t.size)})`;if(i){let n=wt(e)+t.size;if(n>i)return`附件总大小不能超过 ${Tt(i)}(当前合计 ${Tt(n)})`}return null}var Ot=!1,kt=null,At=5e3;function jt(){return Ot}function $(e){Ot=e,kt&&=(clearTimeout(kt),null),e&&(kt=setTimeout(()=>{Ot=!1,kt=null},At))}var Mt=null;function Nt(e){Mt=e}function Pt(){return Mt}var Ft=300;function It({open:e,title:t,message:n,confirmText:r=`删除`,cancelText:o=`取消`,onConfirm:s,onCancel:c}){let[l,d]=(0,i.useState)(!1),f=(0,i.useRef)(!1),p=Pt();return(0,i.useEffect)(()=>{if(!e){f.current=!1;return}!p||f.current||(f.current=!0,p({open:e,title:t,message:n,confirmText:r,cancelText:o,onConfirm:s,onCancel:c}))},[e,p,t,n,r,o,s,c]),(0,i.useEffect)(()=>{e||d(!1)},[e]),p||!e?null:(0,u.createPortal)((0,a.jsx)(`div`,{className:`fixed inset-0 z-[10001] flex items-center justify-center bg-black/40 backdrop-blur-sm select-none`,onClick:()=>{l||c()},onMouseDown:e=>e.preventDefault(),children:(0,a.jsxs)(`div`,{className:`bg-white dark:bg-zinc-800 rounded-xl p-6 shadow-xl max-w-sm w-full mx-4 border border-default-200 relative overflow-hidden`,onClick:e=>e.stopPropagation(),children:[l&&(0,a.jsxs)(`div`,{className:`delete-progress`,children:[(0,a.jsx)(`div`,{className:`delete-progress-spinner`}),(0,a.jsx)(`div`,{className:`delete-progress-text`,children:`删除中…`})]}),(0,a.jsx)(`div`,{className:`text-sm font-medium text-default-800 dark:text-zinc-100 mb-2`,children:t}),n&&(0,a.jsx)(`div`,{className:`text-xs text-default-500 dark:text-zinc-400 mb-4 whitespace-pre-line`,children:n}),(0,a.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,a.jsx)(`button`,{type:`button`,className:`px-3 py-1.5 text-xs rounded-lg border border-default-200 hover:bg-default-100 transition-colors`,onClick:c,disabled:l,children:o}),(0,a.jsx)(`button`,{type:`button`,className:`px-3 py-1.5 text-xs rounded-lg bg-red-500 hover:bg-red-600 text-white transition-colors disabled:opacity-60`,onClick:async()=>{if(l)return;d(!0);let e=Date.now();try{await s()}finally{let t=Date.now()-e;t<Ft&&await new Promise(e=>setTimeout(e,Ft-t)),d(!1),c()}},disabled:l,children:r})]})]})}),document.body)}function Lt(e){return/^(\.\.?\/|[a-zA-Z]:\\|file:\/\/)/.test(e)?!0:!(/^[a-z]+:\/\//i.test(e)||e.startsWith(`/`)||e.startsWith(`data:`)||e.startsWith(`blob:`))}function Rt({node:e,deleteNode:n,editor:r}){let[o,s]=(0,i.useState)(!1),[l,u]=(0,i.useState)(!1),[d,f]=(0,i.useState)(!1),p=(0,i.useRef)(!1),[m,h]=(0,i.useState)(!1),g=e.attrs.src||``,_=e.attrs.alt||``,v=e.attrs.width||null,y=e.attrs.height||null,b=(0,i.useRef)(null),x=(0,i.useRef)(null),S=(0,i.useRef)(null),C=(0,i.useRef)(null),w=(0,i.useRef)(null),T=(0,i.useRef)(!1),E=(0,i.useRef)(!1),D=(0,i.useRef)(0),[O,k]=(0,i.useState)(g),A=r?.isEditable??!0,j=(0,i.useCallback)(()=>{l||(D.current=window.scrollY,s(!0))},[l]),M=(0,i.useCallback)(()=>{s(!1),requestAnimationFrame(()=>window.scrollTo(0,D.current))},[]),N=(0,i.useCallback)(()=>{let e=b.current;e&&(D.current=window.scrollY,e.requestFullscreen?e.requestFullscreen():e.webkitRequestFullscreen&&e.webkitRequestFullscreen())},[]),P=(0,i.useCallback)(()=>{let e=x.current;e&&(D.current=window.scrollY,e.requestFullscreen?e.requestFullscreen():e.webkitRequestFullscreen&&e.webkitRequestFullscreen())},[]);(0,i.useEffect)(()=>{u(!1),k(g),T.current=!1,E.current=!1,C.current&&=(URL.revokeObjectURL(C.current),null),w.current&&=(URL.revokeObjectURL(w.current),null)},[g]),(0,i.useEffect)(()=>{if(!g||g.startsWith(`blob:`)||g.startsWith(`data:`)||g.includes(`?X-Amz-`))return;let e=!1;return(async()=>{try{let{signPreviewUrlHeaders:t}=await Promise.resolve().then(()=>require("./signed-fetch-ULpEJyn5.cjs")).then(e=>e.i),n=await t(g);if(!n)return;let r=await fetch(g,{headers:n});if(!r.ok)return;let i=URL.createObjectURL(await r.blob());if(e){URL.revokeObjectURL(i);return}C.current&&URL.revokeObjectURL(C.current),C.current=i,T.current=!0,k(i)}catch{}})(),()=>{e=!0}},[g]),(0,i.useEffect)(()=>()=>{C.current&&URL.revokeObjectURL(C.current),w.current&&URL.revokeObjectURL(w.current)},[]),(0,i.useEffect)(()=>{if(!o)return;let e=e=>{if(e.key===`Escape`){if(document.fullscreenElement||p.current)return;s(!1)}};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[o]),(0,i.useEffect)(()=>{let e=()=>{let e=!!document.fullscreenElement;f(e),e||(p.current=!0,requestAnimationFrame(()=>window.scrollTo(0,D.current)),window.setTimeout(()=>{p.current=!1},300))};return document.addEventListener(`fullscreenchange`,e),()=>document.removeEventListener(`fullscreenchange`,e)},[]);let F=l||Lt(g);return(0,a.jsxs)(c.NodeViewWrapper,{as:`div`,className:`image-node-view group/img`,contentEditable:!1,children:[F?(0,a.jsxs)(`div`,{className:`image-placeholder`,children:[A&&(0,a.jsx)(`button`,{type:`button`,className:`img-ctrl-btn img-ctrl-btn--del image-placeholder-del`,onClick:()=>{jt()||($(!0),h(!0))},title:`删除`,children:(0,a.jsx)(`svg`,{width:`14`,height:`14`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,children:(0,a.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16`})})}),(0,a.jsx)(`svg`,{width:`32`,height:`32`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`1.5`,children:(0,a.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M2.25 15.75l5.159-5.159a2.25 2.25 0 013.182 0l5.159 5.159m-1.5-1.5l1.409-1.409a2.25 2.25 0 013.182 0l2.909 2.909M3.75 21h16.5A2.25 2.25 0 0022.5 18.75V5.25A2.25 2.25 0 0020.25 3H3.75A2.25 2.25 0 001.5 5.25v13.5A2.25 2.25 0 003.75 21z`})}),(0,a.jsx)(`span`,{className:`image-placeholder-text`,children:Lt(g)?`本地图片无法加载`:`图片加载失败`}),(0,a.jsx)(`span`,{className:`image-placeholder-path`,children:_||g})]}):(0,a.jsxs)(`div`,{ref:b,className:`img-wrap`,children:[(0,a.jsx)(`img`,{ref:S,src:O,alt:_,width:v||void 0,height:y||void 0,onClick:j,onError:()=>{T.current||l||(T.current=!0,(async()=>{try{let e=await t.r(g),n=await fetch(g,e?{headers:e}:{});if(n.ok){let e=await n.blob(),t=URL.createObjectURL(e);C.current&&URL.revokeObjectURL(C.current),C.current=t,S.current&&(S.current.src=t);return}}catch{}u(!0)})())},className:`img-main`,draggable:`false`}),(0,a.jsxs)(`div`,{className:`img-controls`,style:d?{opacity:1,pointerEvents:`auto`}:void 0,children:[(0,a.jsx)(`button`,{type:`button`,className:`img-ctrl-btn`,onClick:j,title:`网页全屏`,children:(0,a.jsx)(`svg`,{width:`14`,height:`14`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,children:(0,a.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M8 3H5a2 2 0 00-2 2v3m18 0V5a2 2 0 00-2-2h-3m0 18h3a2 2 0 002-2v-3M3 16v3a2 2 0 002 2h3`})})}),(0,a.jsx)(`button`,{type:`button`,className:`img-ctrl-btn`,onClick:N,title:`全屏`,children:(0,a.jsx)(`svg`,{width:`14`,height:`14`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,children:(0,a.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M15 3h6v6M9 21H3v-6M21 3l-7 7M3 21l7-7`})})}),A&&(0,a.jsx)(`button`,{type:`button`,className:`img-ctrl-btn img-ctrl-btn--del`,onClick:()=>{jt()||($(!0),h(!0))},title:`删除`,children:(0,a.jsx)(`svg`,{width:`14`,height:`14`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,children:(0,a.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16`})})})]})]}),o&&!F&&(0,a.jsxs)(`div`,{className:`image-lightbox`,onClick:M,children:[(0,a.jsxs)(`div`,{className:`image-lightbox-bar`,children:[(0,a.jsx)(`button`,{type:`button`,className:`image-lightbox-bar-btn`,onClick:P,title:`全屏`,children:(0,a.jsx)(`svg`,{width:`18`,height:`18`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,children:(0,a.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M15 3h6v6M9 21H3v-6M21 3l-7 7M3 21l7-7`})})}),(0,a.jsx)(`button`,{type:`button`,className:`image-lightbox-bar-btn`,onClick:M,title:`关闭`,children:(0,a.jsx)(`svg`,{width:`18`,height:`18`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,children:(0,a.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M6 18L18 6M6 6l12 12`})})})]}),(0,a.jsx)(`img`,{ref:x,src:O,alt:_,className:`image-lightbox-img`,onClick:e=>e.stopPropagation(),onError:()=>{if(!E.current){if(E.current=!0,C.current&&x.current){x.current.src=C.current;return}(async()=>{try{let e=await t.r(g),n=await fetch(g,e?{headers:e}:{});if(n.ok){let e=await n.blob(),t=URL.createObjectURL(e);w.current&&URL.revokeObjectURL(w.current),w.current=t,x.current&&(x.current.src=t)}}catch{}})()}}})]}),(0,a.jsx)(It,{open:m,title:`确认删除图片`,message:F?`该图片无法在当前环境加载,仅从编辑器中移除该图片节点,不影响存储文件。`:`此操作将同时删除对象存储中的文件,不可撤销。`,onCancel:()=>{$(!1),h(!1)},onConfirm:async()=>{if(!F)try{await ot(g)}catch{}$(!1),await new Promise(e=>setTimeout(e,300)),n()}})]})}var zt=(0,i.lazy)(()=>import(`@file-viewer/react`)),Bt=new Set,Vt={rendererMode:`replace`,autoRenderers:!0,theme:`light`,styleIsolation:`scoped`,toolbar:{position:`bottom-right`,download:!1,permissions:{download:!1}},pdf:{workerUrl:`/file-viewer/vendor/pdf/pdf.worker.mjs`,cMapUrl:`/file-viewer/vendor/pdf/cmaps/`,wasmUrl:`/file-viewer/vendor/pdf/wasm/`,standardFontDataUrl:`/file-viewer/vendor/pdf/standard_fonts/`,cjkFontFallbackPath:`/file-viewer/vendor/pdf/fonts/`},spreadsheet:{workerUrl:`/file-viewer/vendor/xlsx/sheet.worker.js`},docx:{workerUrl:`/file-viewer/vendor/docx/docx.worker.js`,workerJsZipUrl:`/file-viewer/vendor/docx/jszip.min.js`,backgroundColor:`#ffffff`},archive:{workerUrl:`/file-viewer/vendor/libarchive/worker-bundle.js`,wasmUrl:`/file-viewer/vendor/libarchive/libarchive.wasm`,cache:!0,workerTimeoutMs:3e4}},Ht={pdf:`pdf`,docx:`word`,docm:`word`,dotx:`word`,dotm:`word`,doc:`word`,dot:`word`,rtf:`word`,odt:`word`,xlsx:`spreadsheet`,xlsm:`spreadsheet`,xlsb:`spreadsheet`,xls:`spreadsheet`,xltx:`spreadsheet`,xlt:`spreadsheet`,csv:`spreadsheet`,tsv:`spreadsheet`,ods:`spreadsheet`,numbers:`spreadsheet`,pptx:`presentation`,pptm:`presentation`,potx:`presentation`,potm:`presentation`,ppsx:`presentation`,ppsm:`presentation`,ppt:`presentation`,pot:`presentation`,odp:`presentation`,zip:`archive`,rar:`archive`,"7z":`archive`,tar:`archive`,gz:`archive`,tgz:`archive`,bz2:`archive`,xz:`archive`,zst:`archive`,txt:`text`,md:`text`,log:`text`,html:`text`,htm:`text`,css:`text`,js:`text`,jsx:`text`,ts:`text`,tsx:`text`,py:`text`,sh:`text`,sql:`text`,json:`text`,xml:`text`,yml:`text`,yaml:`text`},Ut={pdf:()=>import(`@file-viewer/renderer-pdf`).then(e=>e.pdfRenderer),word:()=>import(`@file-viewer/renderer-word`).then(e=>e.wordRenderer),spreadsheet:()=>import(`@file-viewer/renderer-spreadsheet`).then(e=>e.spreadsheetRenderer),presentation:()=>import(`@file-viewer/renderer-presentation`).then(e=>e.presentationRenderer),archive:()=>import(`@file-viewer/renderer-archive`).then(e=>e.archiveRenderer),text:()=>import(`@file-viewer/renderer-text`).then(e=>e.textRenderer)};function Wt(e){return e?e<1024?`${e} B`:e<1048576?`${(e/1024).toFixed(1)} KB`:`${(e/1048576).toFixed(1)} MB`:``}function Gt(e){let t=e.split(`.`).pop()?.toLowerCase()||``,n={pdf:{label:`PDF`,color:`#ef4444`},doc:{label:`DOC`,color:`#2563eb`},docx:{label:`DOC`,color:`#2563eb`},dot:{label:`DOT`,color:`#2563eb`},dotx:{label:`DOT`,color:`#2563eb`},xls:{label:`XLS`,color:`#16a34a`},xlsx:{label:`XLS`,color:`#16a34a`},xlt:{label:`XLT`,color:`#16a34a`},xltx:{label:`XLT`,color:`#16a34a`},csv:{label:`CSV`,color:`#16a34a`},ppt:{label:`PPT`,color:`#ea580c`},pptx:{label:`PPT`,color:`#ea580c`},pot:{label:`POT`,color:`#ea580c`},potx:{label:`POT`,color:`#ea580c`},zip:{label:`ZIP`,color:`#ca8a04`},rar:{label:`RAR`,color:`#ca8a04`},"7z":{label:`7Z`,color:`#ca8a04`},tar:{label:`TAR`,color:`#ca8a04`},gz:{label:`GZ`,color:`#ca8a04`},txt:{label:`TXT`,color:`#6b7280`},md:{label:`MD`,color:`#6b7280`},log:{label:`LOG`,color:`#6b7280`},html:{label:`HTM`,color:`#7c3aed`},htm:{label:`HTM`,color:`#7c3aed`},css:{label:`CSS`,color:`#7c3aed`},js:{label:`JS`,color:`#7c3aed`},jsx:{label:`JSX`,color:`#7c3aed`},ts:{label:`TS`,color:`#7c3aed`},tsx:{label:`TSX`,color:`#7c3aed`},json:{label:`JSON`,color:`#7c3aed`},xml:{label:`XML`,color:`#7c3aed`}}[t]||{label:t?t.slice(0,3).toUpperCase():`FILE`,color:`#6b7280`};return(0,a.jsxs)(`svg`,{width:`22`,height:`22`,viewBox:`0 0 24 24`,fill:`none`,xmlns:`http://www.w3.org/2000/svg`,"aria-hidden":`true`,children:[(0,a.jsx)(`path`,{d:`M6 2h7l5 5v15a1 1 0 0 1-1 1H6a1 1 0 0 1-1-1V3a1 1 0 0 1 1-1z`,fill:`#fff`,stroke:n.color,strokeWidth:`1.5`,strokeLinejoin:`round`}),(0,a.jsx)(`path`,{d:`M13 2v5h5`,fill:`none`,stroke:n.color,strokeWidth:`1.5`,strokeLinejoin:`round`}),(0,a.jsx)(`rect`,{x:`5`,y:`14`,width:`14`,height:`6.5`,rx:`1.2`,fill:n.color}),(0,a.jsx)(`text`,{x:`12`,y:`19`,textAnchor:`middle`,fontSize:`5`,fontWeight:`700`,fill:`#fff`,fontFamily:`Arial, sans-serif`,children:n.label})]})}function Kt(e){return e.split(`.`).pop()?.toLowerCase()||``}function qt(e){let t=e.split(`.`).pop()?.toLowerCase()||``;return/^(pdf|docx?|dotx?|xlsx?|xltx?|pptx?|potx?|txt|md|html?|csv|json|xml|yml|yaml|log|zip|rar|7z|tar|gz|odt|ods|odp|rtf|xlsm|xlsb|ppsx|numbers|tgz|bz2|xz|zst|js|ts|tsx|py|sh|sql)$/.test(t)}function Jt(e){return!!e&&!e.startsWith(`file:`)}function Yt(e){return btoa(encodeURIComponent(e)).replace(/\+/g,`-`).replace(/\//g,`_`).replace(/=+$/,``)}async function Xt(e,t){try{let n=Yt(e),r=await fetch(`/api/preview/${n}`,{signal:t,cache:`no-store`});if(!r.ok)return null;if((r.headers.get(`Content-Type`)||``).includes(`text/html`))return console.warn(`[attachment] /api/preview returned HTML (endpoint missing), fallback to direct XHR`),null;let i=await r.arrayBuffer(),a=Number(r.headers.get(`Content-Length`)||0);return i.byteLength>0&&(a===0||i.byteLength===a)?i:(console.warn(`[attachment] /api/preview data incomplete`),null)}catch{return null}}function Zt(e,t,n){return new Promise((r,i)=>{let a=new XMLHttpRequest;if(a.open(`GET`,e,!0),a.responseType=`arraybuffer`,t){let e=[`host`,`connection`,`content-length`,`cookie`,`date`,`expect`,`keep-alive`,`origin`,`referer`,`te`,`trailer`,`transfer-encoding`,`upgrade`,`via`];for(let[n,r]of Object.entries(t))if(!e.includes(n.toLowerCase()))try{a.setRequestHeader(n,r)}catch{}}if(a.onload=()=>{a.status>=200&&a.status<300?r(a.response):i(Error(`HTTP ${a.status} ${a.statusText}`))},a.onerror=()=>i(Error(`XHR network error`)),a.ontimeout=()=>i(Error(`XHR timeout`)),n){if(n.aborted){a.abort(),i(new DOMException(`Aborted`,`AbortError`));return}n.addEventListener(`abort`,()=>{a.abort(),i(new DOMException(`Aborted`,`AbortError`))})}a.send()})}function Qt({node:n,deleteNode:r,selected:o,editor:s}){let l=s?.isEditable??!0,u=n.attrs.src||``,[d,f]=(0,i.useState)(()=>Bt.has(u)),[p,m]=(0,i.useState)(null),[h,g]=(0,i.useState)(null),[_,v]=(0,i.useState)(!1),[y,b]=(0,i.useState)(null),[x,S]=(0,i.useState)(!1),[C,w]=(0,i.useState)(null),T=(0,i.useRef)(null),E=(0,i.useRef)(null),D=(0,i.useRef)(null),O=(0,i.useRef)(0),k=(0,i.useRef)(!1),A=(0,i.useRef)(null),j=(0,i.useRef)(0),[M,N]=(0,i.useState)(!1),P=(0,i.useRef)(null),[F,ee]=(0,i.useState)(0),[I,L]=(0,i.useState)(`none`),[R,te]=(0,i.useState)(void 0),[ne,re]=(0,i.useState)(!1),z=n.attrs.src||``,B=n.attrs.name||z&&z.split(`/`).pop()?.split(`?`)[0]||(z?`attachment`:e.o(`editor.attachment.lost`)),ie=n.attrs.size||0,V=Kt(B),ae=!z;(0,i.useEffect)(()=>{if(!d){te(void 0),re(!1);return}let e=Ht[V];if(!e){te(void 0),re(!1);return}let t=!0;return te(void 0),re(!1),Ut[e]().then(e=>{t&&te(e)}).catch(n=>{console.error(`[attachment] renderer "${e}" load failed:`,n),t&&re(!0)}),()=>{t=!1}},[d,V]);let oe=(0,i.useMemo)(()=>({...Vt,renderers:R?[R]:[],rendererMode:`replace`}),[R]),H=(0,i.useCallback)(e=>{f(t=>{let n=typeof e==`function`?e(t):e;return z&&(n?Bt.add(z):Bt.delete(z)),n})},[z]);(0,i.useEffect)(()=>{f(z?Bt.has(z):!1)},[z]);let U=(0,i.useCallback)(()=>{k.current=!0,H(!0),window.setTimeout(()=>{window.scrollTo(0,O.current),A.current&&(A.current.scrollTop=j.current),k.current&&H(!0),k.current=!1},0)},[H]),W=(0,i.useCallback)(async()=>{I===`web`?(L(`none`),document.body.style.overflow=``,U()):(I===`native`&&document.fullscreenElement&&await document.exitFullscreen(),O.current=window.scrollY,j.current=A.current?.scrollTop??0,document.body.style.overflow=`hidden`,L(`web`))},[I]),se=(0,i.useCallback)(async()=>{let e=E.current;e&&(I===`native`?await document.exitFullscreen():(I===`web`&&(L(`none`),document.body.style.overflow=``),O.current=window.scrollY,j.current=A.current?.scrollTop??0,await e.requestFullscreen(),L(`native`)))},[I,U]),G=(0,i.useCallback)(()=>{I===`none`&&(k.current||H(e=>!e))},[I]);(0,i.useEffect)(()=>{let e=()=>{document.fullscreenElement||(I===`native`&&L(`none`),U())},t=e=>{e.key===`Escape`&&I===`web`&&(L(`none`),document.body.style.overflow=``,U())};return document.addEventListener(`fullscreenchange`,e),window.addEventListener(`keydown`,t),()=>{document.removeEventListener(`fullscreenchange`,e),window.removeEventListener(`keydown`,t)}},[I,U]),(0,i.useEffect)(()=>{let e=e=>{if(e.key!==`Backspace`&&e.key!==`Delete`||!l||!o||jt())return;let t=s?.view?.dom,n=e.target;if(s?.isFocused&&n instanceof Node&&t?.contains(n)){if(e.preventDefault(),e.stopPropagation(),s){let{from:e,to:t}=s.state.selection;P.current={from:e,to:t}}window.getSelection()?.removeAllRanges(),$(!0),N(!0)}};return window.addEventListener(`keydown`,e,!0),()=>window.removeEventListener(`keydown`,e,!0)},[o,s,l]),(0,i.useEffect)(()=>{if(!d||!Jt(z)){m(null),b(null),D.current=null;return}if(D.current===z)return;let e=new AbortController,n=!0;return v(!0),b(null),(async()=>{let r=z.includes(`?X-Amz-`),i=null,a=null;if(!i&&!r&&(i=await Xt(z,e.signal)),!i&&!r)try{let n=await t.n(z);n&&(i=await Xt(n,e.signal)||await Zt(n,void 0,e.signal))}catch(e){console.warn(`[attachment] signPreviewUrl failed:`,e)}if(!i&&!r)try{let n=await t.r(z);if(n){let t={"X-Requested-With":`XMLHttpRequest`};n.forEach((e,n)=>{t[n]=e});try{i=await Zt(z,t,e.signal)}catch(e){console.warn(`[attachment] signed headers XHR failed:`,e),a=e instanceof Error?e:Error(String(e))}}}catch(e){console.warn(`[attachment] signPreviewUrlHeaders failed:`,e)}if(!i)try{i=await Zt(z,r?void 0:{"X-Requested-With":`XMLHttpRequest`},e.signal)}catch(e){console.warn(`[attachment] plain XHR failed:`,e),a=e instanceof Error?e:Error(String(e))}if(!i)throw a||Error(`所有 fetch 方法均失败`);if(!n)return;m(i),D.current=z;let o=URL.createObjectURL(new Blob([i],{type:`application/octet-stream`}));g(o),v(!1)})().catch(e=>{if(n&&!(e instanceof DOMException&&e.name===`AbortError`)){if(D.current===z){v(!1);return}b(e instanceof Error?e.message:`附件读取失败,请检查对象存储 CORS 和公开访问权限`)}}),()=>{n=!1,e.abort()}},[d,z]),(0,i.useEffect)(()=>()=>{h&&URL.revokeObjectURL(h),m(null)},[]),(0,i.useEffect)(()=>()=>{h&&URL.revokeObjectURL(h),g(null),m(null),D.current=null},[z]),(0,i.useEffect)(()=>{if(C!==`success`&&C!==`error`)return;let e=window.setTimeout(()=>w(null),2400);return()=>window.clearTimeout(e)},[C]);let K=(0,i.useCallback)(async()=>{S(!0),w(`loading`);try{if(h){let e=document.createElement(`a`);e.href=h,e.download=B,document.body.appendChild(e),e.click(),document.body.removeChild(e),w(`success`);return}let e=z.includes(`?X-Amz-`),n=null;if(!e)try{let e=await t.n(z);e&&(n=await fetch(e,{headers:{"X-Requested-With":`XMLHttpRequest`}}),n.ok||(n=null))}catch{}if(!n&&!e)try{let e=await t.r(z);e&&(n=await fetch(z,{headers:(()=>{let t=new Headers(e);return t.set(`X-Requested-With`,`XMLHttpRequest`),t})()}),n.ok||(n=null))}catch{}if(n||=await fetch(z,{headers:{"X-Requested-With":`XMLHttpRequest`}}),!n||!n.ok)throw Error(`下载失败`);let r=await n.blob(),i=URL.createObjectURL(r),a=document.createElement(`a`);a.href=i,a.download=B,document.body.appendChild(a),a.click(),document.body.removeChild(a),URL.revokeObjectURL(i),w(`success`)}catch(e){console.error(`[attachment] download failed:`,e),w(`error`)}finally{S(!1)}},[z,B,h]);return(0,a.jsxs)(c.NodeViewWrapper,{ref:T,as:`div`,className:`attachment-embed group/att ${o?`is-selected`:``}`,contentEditable:!1,children:[(0,a.jsxs)(`div`,{className:`att-inner`,style:o?{outline:`2px solid var(--primary, #6366f1)`,outlineOffset:`2px`}:void 0,children:[(0,a.jsxs)(`div`,{className:`att-header`,children:[(0,a.jsxs)(`div`,{className:`att-info`,children:[(0,a.jsx)(`span`,{className:`att-icon`,children:ae?(0,a.jsxs)(`svg`,{width:`22`,height:`22`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`1.6`,strokeLinecap:`round`,strokeLinejoin:`round`,"aria-hidden":`true`,style:{color:`#9ca3af`},children:[(0,a.jsx)(`path`,{d:`M10.29 3.86 1.82 18a2 2 0 0 0 1.71 3h16.94a2 2 0 0 0 1.71-3L13.71 3.86a2 2 0 0 0-3.42 0z`}),(0,a.jsx)(`path`,{d:`M12 9v4`}),(0,a.jsx)(`path`,{d:`M12 17h.01`})]}):Gt(B)}),(0,a.jsxs)(`div`,{className:`att-meta`,children:[(0,a.jsx)(`span`,{className:`att-name`,children:B}),ie>0&&(0,a.jsx)(`span`,{className:`att-size`,children:Wt(ie)})]})]}),(0,a.jsxs)(`div`,{className:`att-tools`,children:[(0,a.jsxs)(`div`,{className:`att-download-status`,role:`status`,"aria-live":`polite`,"aria-atomic":`true`,children:[C===`loading`&&(0,a.jsxs)(`span`,{className:`att-download-status__content is-loading`,children:[(0,a.jsx)(`svg`,{className:`att-download-spinner`,width:`13`,height:`13`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,"aria-hidden":`true`,children:(0,a.jsx)(`path`,{strokeLinecap:`round`,d:`M12 2a10 10 0 1 0 10 10`})}),`正在准备`]}),C===`success`&&(0,a.jsxs)(`span`,{className:`att-download-status__content is-success`,children:[(0,a.jsx)(`svg`,{width:`13`,height:`13`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,"aria-hidden":`true`,children:(0,a.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`m5 12 4 4L19 6`})}),`已下载`]}),C===`error`&&(0,a.jsx)(`span`,{className:`att-download-status__content is-error`,children:`下载失败,请重试`})]}),(0,a.jsxs)(`div`,{className:`att-actions`,children:[z&&qt(B)&&(0,a.jsx)(`button`,{type:`button`,className:`att-btn`,onMouseDown:e=>{e.preventDefault(),e.stopPropagation(),G()},title:e.o(`editor.attachment.preview`),"aria-label":e.o(`editor.attachment.preview`),children:(0,a.jsxs)(`svg`,{width:`14`,height:`14`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,"aria-hidden":`true`,children:[(0,a.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M2.036 12.322a1.012 1.012 0 010-.639C3.423 7.51 7.36 4.5 12 4.5c4.638 0 8.573 3.007 9.963 7.178.07.207.07.431 0 .639C20.577 16.49 16.64 19.5 12 19.5c-4.638 0-8.573-3.007-9.963-7.178z`}),(0,a.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M15 12a3 3 0 11-6 0 3 3 0 016 0z`})]})}),(0,a.jsx)(`button`,{type:`button`,className:`att-btn`,onClick:K,disabled:x||ae,title:x?`正在准备下载`:e.o(`editor.attachment.download`),"aria-label":x?`正在准备下载`:e.o(`editor.attachment.download`),children:(0,a.jsx)(`svg`,{width:`14`,height:`14`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,"aria-hidden":`true`,children:(0,a.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M4 16v1a3 3 0 003 3h10a3 3 0 003-3v-1m-4-4l-4 4m0 0l-4-4m4 4V4`})})}),l&&(0,a.jsx)(`button`,{type:`button`,className:`att-btn att-btn--del`,onClick:()=>{!l||jt()||($(!0),N(!0))},title:e.o(`editor.attachment.delete`),"aria-label":e.o(`editor.attachment.delete`),children:(0,a.jsx)(`svg`,{width:`14`,height:`14`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,"aria-hidden":`true`,children:(0,a.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16`})})})]})]})]}),d&&(0,a.jsxs)(`div`,{ref:E,className:`att-preview-wrap ${I===`web`?`is-web-fs`:``}`,style:{position:`relative`,height:500,overflow:`hidden`,background:`#fff`},children:[(0,a.jsx)(`div`,{ref:A,className:`att-preview-scroll`,style:{height:`100%`,overflow:`auto`},children:_&&!p&&!h?(0,a.jsx)(`div`,{className:`flex items-center justify-center h-full text-default-400 text-sm`,children:e.o(`editor.attachment.loadingPreview`)}):(y||ne)&&!p&&!h?(0,a.jsxs)(`div`,{className:`flex h-full flex-col items-center justify-center gap-2 p-6 text-center text-sm text-default-500`,children:[(0,a.jsx)(`div`,{className:`font-medium text-default-700`,children:`暂时无法预览此附件`}),(0,a.jsx)(`div`,{className:`max-w-md text-xs leading-relaxed`,children:`请稍后重试,或使用附件栏中的下载按钮。`})]}):(0,a.jsx)(i.Suspense,{fallback:(0,a.jsx)(`div`,{className:`flex items-center justify-center h-full text-default-400 text-sm`,style:{background:`#fff`},children:e.o(`editor.attachment.loadingPreview`)}),children:p||h||z?R?(0,a.jsx)(zt,{buffer:p||void 0,url:h||z,name:B,filename:B,type:V,size:ie||p?.byteLength||0,options:oe},`${z}-${F}`):(0,a.jsx)(`div`,{className:`flex h-full items-center justify-center text-sm text-default-400`,children:`正在加载预览引擎...`}):(0,a.jsx)(`div`,{className:`flex h-full items-center justify-center text-sm text-default-400`,children:`正在加载...`})})}),(0,a.jsxs)(`div`,{className:`att-fs-controls__panel`,style:{position:`absolute`,top:8,right:8,zIndex:10,display:`flex`,gap:2,padding:4,background:`rgba(255,255,255,0.92)`,backdropFilter:`blur(8px)`,WebkitBackdropFilter:`blur(8px)`,borderRadius:8,boxShadow:`0 2px 8px rgba(0,0,0,0.12)`,border:`1px solid rgba(0,0,0,0.06)`},children:[(0,a.jsx)(`button`,{type:`button`,onClick:W,title:I===`web`?`退出网页全屏`:`网页全屏`,"aria-label":I===`web`?`退出网页全屏`:`网页全屏`,style:{width:28,height:28,borderRadius:6,border:`none`,background:I===`web`?`#e4e4e7`:`transparent`,cursor:`pointer`,display:`flex`,alignItems:`center`,justifyContent:`center`,color:`#52525b`,transition:`background 0.12s`},onMouseEnter:e=>{I!==`web`&&(e.currentTarget.style.background=`#f4f4f5`)},onMouseLeave:e=>{I!==`web`&&(e.currentTarget.style.background=`transparent`)},children:(0,a.jsx)(`svg`,{width:`14`,height:`14`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,"aria-hidden":`true`,children:(0,a.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M8 3H5a2 2 0 00-2 2v3m18 0V5a2 2 0 00-2-2h-3m0 18h3a2 2 0 002-2v-3M3 16v3a2 2 0 002 2h3`})})}),(0,a.jsx)(`button`,{type:`button`,onClick:se,title:I===`native`?`退出全屏`:`全屏`,"aria-label":I===`native`?`退出全屏`:`全屏`,style:{width:28,height:28,borderRadius:6,border:`none`,background:I===`native`?`#e4e4e7`:`transparent`,cursor:`pointer`,display:`flex`,alignItems:`center`,justifyContent:`center`,color:`#52525b`,transition:`background 0.12s`},onMouseEnter:e=>{I!==`native`&&(e.currentTarget.style.background=`#f4f4f5`)},onMouseLeave:e=>{I!==`native`&&(e.currentTarget.style.background=`transparent`)},children:(0,a.jsx)(`svg`,{width:`14`,height:`14`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,"aria-hidden":`true`,children:(0,a.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M15 3h6v6M9 21H3v-6M21 3l-7 7M3 21l7-7`})})})]})]})]}),(0,a.jsx)(It,{open:M,title:`确认删除附件`,message:ae?`此操作将删除该附件节点,不可撤销。`:`此操作将同时删除对象存储中的文件(${B}),不可撤销。`,onCancel:()=>{$(!1),N(!1)},onConfirm:async()=>{try{if(s){let e=P.current,t=e?.from??s.state.selection.from,n=e?.to??s.state.selection.to,r=[];s.state.doc.nodesBetween(t,n,e=>{e.type.name===`attachmentEmbed`&&e.attrs?.src&&r.push(ot(e.attrs.src))}),await Promise.all(r),$(!1),await new Promise(e=>setTimeout(e,300)),s.chain().focus().setTextSelection({from:t,to:n}).deleteSelection().run()}else await ot(z),$(!1),await new Promise(e=>setTimeout(e,300)),r()}catch{$(!1)}}})]})}var $t=d.Node.create({name:`attachmentEmbed`,group:`block`,atom:!0,inline:!1,addNodeView(){return(0,c.ReactNodeViewRenderer)(Qt)},addAttributes(){return{src:{default:null,parseHTML:e=>e.getAttribute(`data-src`)||e.querySelector(`a`)?.getAttribute(`href`)},name:{default:``,parseHTML:e=>e.getAttribute(`data-name`)||e.querySelector(`a`)?.getAttribute(`download`)||``},size:{default:0,parseHTML:e=>Number(e.getAttribute(`data-size`)||0)},type:{default:``,parseHTML:e=>e.getAttribute(`data-type`)||``}}},parseHTML(){return[{tag:`div[data-attachment-embed]`}]},renderHTML({HTMLAttributes:e}){return[`div`,{"data-attachment-embed":`true`,"data-src":e.src,"data-name":e.name,"data-size":e.size||0,"data-type":e.type||``,class:`attachment-embed`},[`a`,{href:e.src,download:e.name},`📎 ${e.name||`attachment`}`]]}});function en({node:e,deleteNode:n,editor:r}){let o=e.attrs.src||``,s=e.attrs.name||o.split(`/`).pop()?.split(`?`)[0]||`audio`,[l,u]=(0,i.useState)(!1),d=r?.isEditable??!0;(0,i.useEffect)(()=>()=>{o.startsWith(`blob:`)&&URL.revokeObjectURL(o)},[o]);let f=!!o&&(o.startsWith(`blob:`)||o.startsWith(`data:`)),[p,m]=(0,i.useState)(f?o:null),[h,g]=(0,i.useState)(f),_=(0,i.useRef)(null);return(0,i.useEffect)(()=>{if(!o){m(null),g(!1);return}if(o.startsWith(`blob:`)||o.startsWith(`data:`)){m(o),g(!0);return}let e=!1;return g(!1),(async()=>{let n=o;try{let e=await t.r(o);if(e){let t=await fetch(o,{headers:e});if(t.ok){let e=URL.createObjectURL(await t.blob());_.current&&URL.revokeObjectURL(_.current),_.current=e,n=e}}}catch{}e||(m(n),g(!0))})(),()=>{e=!0,_.current&&=(URL.revokeObjectURL(_.current),null)}},[o]),(0,a.jsxs)(c.NodeViewWrapper,{as:`div`,className:`audio-embed group/audio`,style:{margin:`1rem 0`},contentEditable:!1,children:[(0,a.jsxs)(`div`,{className:`audio-embed-inner`,children:[(0,a.jsxs)(`div`,{className:`audio-embed-header`,children:[(0,a.jsxs)(`div`,{className:`audio-embed-title`,children:[(0,a.jsx)(`svg`,{className:`audio-embed-icon`,width:`16`,height:`16`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,children:(0,a.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M9 19V6l12-3v13M9 19c0 1.105-1.343 2-3 2s-3-.895-3-2 1.343-2 3-2 3 .895 3 2zm12-3c0 1.105-1.343 2-3 2s-3-.895-3-2 1.343-2 3-2 3 .895 3 2zM9 10l12-3`})}),(0,a.jsx)(`span`,{className:`audio-embed-filename`,children:s})]}),(0,a.jsx)(`div`,{className:`audio-embed-actions`,children:d&&(0,a.jsx)(`button`,{type:`button`,className:`audio-embed-btn audio-embed-btn--del`,onClick:()=>{jt()||($(!0),u(!0))},title:`删除`,children:(0,a.jsx)(`svg`,{width:`12`,height:`12`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,children:(0,a.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16`})})})})]}),(0,a.jsx)(`div`,{className:`audio-embed-player`,children:o?h&&p?(0,a.jsx)(`audio`,{src:p,controls:!0,style:{width:`100%`},onError:async e=>{let n=e.currentTarget;try{let e=await t.r(o),r=await fetch(o,e?{headers:e}:{});if(r.ok){let e=await r.blob();n.src.startsWith(`blob:`)&&URL.revokeObjectURL(n.src),n.src=URL.createObjectURL(e)}}catch{}}}):(0,a.jsxs)(`div`,{className:`audio-embed-loading`,children:[(0,a.jsx)(`span`,{className:`audio-embed-spinner`}),`音频加载中…`]}):(0,a.jsxs)(`div`,{className:`audio-embed-loading audio-embed-missing`,children:[(0,a.jsx)(`span`,{className:`audio-embed-missing-icon`,"aria-hidden":`true`,children:`!`}),`音频文件缺失`]})})]}),(0,a.jsx)(It,{open:l,title:`确认删除音频`,message:`此操作将同时删除对象存储中的文件(${s}),不可撤销。`,onCancel:()=>{$(!1),u(!1)},onConfirm:async()=>{try{await ot(o)}catch{}$(!1),await new Promise(e=>setTimeout(e,300)),n()}})]})}function tn(e){return/\.(mp3|wav|ogg|flac|aac|m4a|wma|opus)(\?|$)/i.test(e)||/\/.*\.(mp3|wav|ogg|flac)/i.test(e)}var nn=d.Node.create({name:`audioEmbed`,group:`block`,atom:!0,inline:!1,addNodeView(){return(0,c.ReactNodeViewRenderer)(en)},addProseMirrorPlugins(){return[new f.Plugin({props:{handlePaste(e,t){let n=t.clipboardData?.getData(`text/plain`);if(!n)return!1;let r=n.split(/\r?\n/);for(let n of r){let r=n.trim();if(!r||r.includes(` `)||!tn(r))continue;t.preventDefault();let i=e.state.schema.nodes.audioEmbed.create({src:r});return e.dispatch(e.state.tr.replaceSelectionWith(i)),!0}return!1}}})]},addAttributes(){return{src:{default:null},name:{default:``},size:{default:0,parseHTML:e=>Number(e.getAttribute(`data-size`)||0)}}},parseHTML(){return[{tag:`div[data-audio-embed]`,getAttrs:e=>{let t=e,n=t.getAttribute(`src`)||t.getAttribute(`data-src`)||t.querySelector(`audio`)?.getAttribute(`src`)||null;return n?{src:n}:null}},{tag:`audio[src]`}]},renderHTML({HTMLAttributes:e}){return[`div`,{"data-audio-embed":`true`,src:e.src,"data-src":e.src,"data-size":e.size||0,class:`audio-embed`},[`audio`,{src:e.src,controls:`true`,style:`width:100%;`}]]}});function rn(e){return e?/bilibili\.com|BV[a-zA-Z0-9]{10}|av\d+/i.test(e)?`bilibili`:/xiaohongshu\.com|xhslink\.com/i.test(e)?`xiaohongshu`:/\.(mp4|m3u8|webm|ogg|flv|mkv|mov|avi|wmv|ts|m4v|3gp|f4v|rmvb)(\?|$)/i.test(e)||/\/.*\.(mp4|m3u8|mov|webm|flv|mkv)/i.test(e)?`direct`:`unknown`:`unknown`}function an(e){let t=e.match(/BV[a-zA-Z0-9]{10}/);if(t)return t[0];let n=e.match(/av(\d+)/i);return n?n[0]:e}function on({node:e,deleteNode:t,editor:n}){let r=e.attrs.src||``,o=e.attrs.source||`unknown`,s=o===`unknown`?rn(r):o,[l,u]=(0,i.useState)(!1),[d,f]=(0,i.useState)(!1),[p,m]=(0,i.useState)(!1),h=n?.isEditable??!0,g=!h&&r.startsWith(`blob:`),_=(0,a.jsx)(It,{open:l,title:`确认删除视频`,message:`此操作将同时删除对象存储中的文件,不可撤销。`,onCancel:()=>{$(!1),u(!1)},onConfirm:async()=>{try{await ot(r)}catch{}$(!1),await new Promise(e=>setTimeout(e,300)),t()}}),[v,y]=(0,i.useState)(``),b=(0,i.useRef)(null),x=(0,i.useRef)(null),S=(0,i.useRef)(null),C=(0,i.useRef)(null),w=(0,i.useRef)(null),T=(0,i.useRef)(0),E=(0,i.useCallback)(()=>{let e=S.current;e&&(e.style.position=``,e.style.inset=``,e.style.zIndex=``,e.style.borderRadius=``,document.body.style.overflow=``)},[]),D=(0,i.useCallback)(()=>{document.fullscreenElement&&document.exitFullscreen?.(),E()},[E]),O=(0,i.useCallback)(()=>{let e=S.current;e&&(e.style.position===`fixed`?E():(e.style.position=`fixed`,e.style.inset=`0`,e.style.zIndex=`99999`,e.style.borderRadius=`0`,document.body.style.overflow=`hidden`))},[E]),k=(0,i.useCallback)(()=>{T.current=window.scrollY,C.current?.requestFullscreen?.()},[]),A=(0,i.useCallback)(()=>{let e=x.current?.closest(`.video-embed--direct`)||x.current;e&&(T.current=window.scrollY,e.requestFullscreen?.())},[]);if((0,i.useEffect)(()=>{let e=()=>{document.fullscreenElement||requestAnimationFrame(()=>window.scrollTo(0,T.current))};return document.addEventListener(`fullscreenchange`,e),()=>document.removeEventListener(`fullscreenchange`,e)},[]),(0,i.useEffect)(()=>{if(s!==`direct`||!r){y(``);return}let e=!1;return f(!0),(async()=>{try{if(r.includes(`?X-Amz-`)||r.startsWith(`blob:`)||r.startsWith(`data:`)){y(r);return}let{signPreviewUrlHeaders:t}=await Promise.resolve().then(()=>require("./signed-fetch-ULpEJyn5.cjs")).then(e=>e.i),n=await t(r);if(!n){y(r);return}let i=await fetch(r,{headers:n});if(!i.ok){y(r);return}let a=URL.createObjectURL(await i.blob());if(e){URL.revokeObjectURL(a);return}w.current&&URL.revokeObjectURL(w.current),w.current=a,y(a)}catch{e||y(r)}})(),()=>{e=!0,w.current&&=(URL.revokeObjectURL(w.current),null)}},[s,r]),(0,i.useEffect)(()=>{if(s!==`direct`||!v)return;let e=!1;f(!0),m(!1);let t=x.current,n=t=>{let n=t.target;n?.error&&n.error.code===4&&!e&&m(!0)};return t?.addEventListener(`error`,n,!0),(async()=>{if(t)try{let[{default:n}]=await Promise.all([import(`xgplayer`)]);if(e||!x.current)return;b.current?.destroy(),t.replaceChildren(),b.current=new n({el:t,url:v,width:`100%`,height:450,fluid:!0,fitVideoSize:`fixWidth`,autoplay:!1,controls:!0,ignores:[`fullscreen`],playbackRate:[.5,.75,1,1.25,1.5,2],lang:`zh-cn`}),t.__xgplayer=b.current;let r=()=>{e||f(!1)};try{b.current?.once?.(`loadeddata`,r),b.current?.once?.(`canplay`,r)}catch{}window.setTimeout(r,2500)}catch{}})(),()=>{e=!0,t?.removeEventListener(`error`,n,!0),f(!1),b.current?.destroy(),b.current=null,x.current&&(x.current.__xgplayer=null)}},[s,v]),(0,i.useEffect)(()=>{p&&(b.current?.destroy(),b.current=null)},[p]),s===`bilibili`){let e=an(r);return(0,a.jsxs)(c.NodeViewWrapper,{as:`div`,className:`video-embed video-embed--bilibili group/video`,style:{margin:`1rem 0`},contentEditable:!1,children:[(0,a.jsxs)(`div`,{ref:S,style:{borderRadius:12,overflow:`hidden`},children:[(0,a.jsxs)(`div`,{className:`video-fs-controls`,children:[(0,a.jsx)(`button`,{type:`button`,className:`video-fs-btn`,title:`宽屏`,onClick:D,children:(0,a.jsx)(`svg`,{width:`12`,height:`12`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,children:(0,a.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M4 8V4m0 0h4M4 4l5 5m11-1V4m0 0h-4m4 0l-5 5M4 16v4m0 0h4m-4 0l5-5m11 5l-5-5m5 5v-4m0 4h-4`})})}),(0,a.jsx)(`button`,{type:`button`,className:`video-fs-btn`,title:`网页全屏`,onClick:O,children:(0,a.jsx)(`svg`,{width:`12`,height:`12`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,children:(0,a.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M8 3H5a2 2 0 00-2 2v3m18 0V5a2 2 0 00-2-2h-3m0 18h3a2 2 0 002-2v-3M3 16v3a2 2 0 002 2h3`})})}),(0,a.jsx)(`button`,{type:`button`,className:`video-fs-btn`,title:`全屏`,onClick:k,children:(0,a.jsx)(`svg`,{width:`12`,height:`12`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,children:(0,a.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M15 3h6v6M9 21H3v-6M21 3l-7 7M3 21l7-7`})})}),h&&(0,a.jsx)(`button`,{type:`button`,className:`video-fs-btn video-fs-btn--del`,title:`删除`,onClick:()=>{jt()||($(!0),u(!0))},children:(0,a.jsx)(`svg`,{width:`12`,height:`12`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,children:(0,a.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16`})})})]}),(0,a.jsx)(`div`,{style:{position:`relative`,paddingTop:`56.25%`},children:(0,a.jsx)(`iframe`,{ref:C,src:`https://player.bilibili.com/player.html?bvid=${e}&page=1&high_quality=1`,style:{position:`absolute`,top:0,left:0,width:`100%`,height:`100%`,border:`none`},allowFullScreen:!0,scrolling:`no`,sandbox:`allow-scripts allow-same-origin allow-popups allow-popups-to-escape-sandbox`,referrerPolicy:`no-referrer-when-downgrade`})})]}),_]})}return s===`xiaohongshu`?(0,a.jsxs)(c.NodeViewWrapper,{as:`div`,className:`video-embed video-embed--xiaohongshu`,style:{border:`1px solid #e5e7eb`,borderRadius:12,padding:16,display:`flex`,alignItems:`center`,gap:12,maxWidth:480,margin:`1rem 0`},contentEditable:!1,children:[(0,a.jsx)(`div`,{style:{width:40,height:40,background:`#ff2442`,borderRadius:10,display:`flex`,alignItems:`center`,justifyContent:`center`,color:`#fff`,fontWeight:`bold`,fontSize:14,flexShrink:0},children:`红`}),(0,a.jsxs)(`div`,{children:[(0,a.jsx)(`div`,{style:{fontWeight:600,fontSize:14},children:`小红书笔记`}),(0,a.jsx)(`a`,{href:r,target:`_blank`,rel:`noopener noreferrer`,style:{color:`#ff2442`,fontSize:12,textDecoration:`none`},children:`在小红书中打开 →`})]})]}):(0,a.jsxs)(c.NodeViewWrapper,{as:`div`,className:`video-embed video-embed--direct group/video`,style:{margin:`1rem 0`,borderRadius:12,overflow:`hidden`,background:`#000`},contentEditable:!1,onKeyDown:e=>e.stopPropagation(),children:[h&&(0,a.jsxs)(`div`,{className:`video-fs-controls`,children:[(0,a.jsx)(`button`,{type:`button`,className:`video-fs-btn video-fs-btn--del`,title:`删除`,onClick:()=>{jt()||($(!0),u(!0))},children:(0,a.jsx)(`svg`,{width:`12`,height:`12`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,children:(0,a.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16`})})}),(0,a.jsx)(`button`,{type:`button`,className:`video-fs-btn`,title:`全屏`,onClick:A,children:(0,a.jsx)(`svg`,{width:`12`,height:`12`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,children:(0,a.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M15 3h6v6M9 21H3v-6M21 3l-7 7M3 21l7-7`})})})]}),(0,a.jsx)(`div`,{style:{position:`relative`,width:`100%`,background:`#000`},children:g?(0,a.jsxs)(`div`,{style:{minHeight:260,display:`flex`,flexDirection:`column`,alignItems:`center`,justifyContent:`center`,gap:`0.6rem`,padding:`1.25rem`,color:`#fff`},children:[(0,a.jsxs)(`svg`,{width:`34`,height:`34`,viewBox:`0 0 24 24`,children:[(0,a.jsx)(`circle`,{cx:`12`,cy:`12`,r:`9`,fill:`none`,stroke:`rgba(255,255,255,0.2)`,strokeWidth:`3`}),(0,a.jsx)(`path`,{d:`M21 12a9 9 0 0 0-9-9`,fill:`none`,stroke:`#fff`,strokeWidth:`3`,strokeLinecap:`round`,children:(0,a.jsx)(`animateTransform`,{attributeName:`transform`,type:`rotate`,from:`0 12 12`,to:`360 12 12`,dur:`0.8s`,repeatCount:`indefinite`})})]}),(0,a.jsx)(`div`,{style:{fontSize:13,opacity:.75},children:`视频上传中…`})]}):p?(0,a.jsxs)(`div`,{style:{minHeight:260,display:`flex`,flexDirection:`column`,alignItems:`center`,justifyContent:`center`,gap:`0.5rem`,padding:`1.25rem`,textAlign:`center`,color:`#fff`},children:[(0,a.jsxs)(`svg`,{width:`36`,height:`36`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`1.6`,strokeLinecap:`round`,strokeLinejoin:`round`,style:{opacity:.6},children:[(0,a.jsx)(`path`,{d:`M10.29 3.86 1.82 18a2 2 0 0 0 1.71 3h16.94a2 2 0 0 0 1.71-3L13.71 3.86a2 2 0 0 0-3.42 0z`}),(0,a.jsx)(`line`,{x1:`12`,y1:`9`,x2:`12`,y2:`13`}),(0,a.jsx)(`line`,{x1:`12`,y1:`17`,x2:`12.01`,y2:`17`})]}),(0,a.jsx)(`div`,{style:{fontSize:14,fontWeight:500},children:`视频编码不受当前浏览器支持(HEVC/H.265 常见)`}),(0,a.jsx)(`div`,{style:{fontSize:12,opacity:.7,lineHeight:1.5},children:`请安装「HEVC 视频扩展」,或将视频转码为 H.264 后重新上传`})]}):(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(`div`,{ref:x,style:{width:`100%`,minHeight:260}}),d&&(0,a.jsx)(`div`,{className:`xg-loading-overlay`,children:(0,a.jsx)(`span`,{className:`xg-loading-spinner`})})]})}),_]})}function sn(e){return/bilibili\.com|BV[a-zA-Z0-9]{10}|av\d+/i.test(e)?`bilibili`:/xiaohongshu\.com|xhslink\.com/i.test(e)?`xiaohongshu`:/\.(mp4|m3u8|webm|ogg|flv|mkv|mov|avi|wmv|ts|m4v|3gp|f4v|rmvb)(\?|$)/i.test(e)||/\/.*\.(mp4|m3u8|mov|webm|flv|mkv)/i.test(e)?`direct`:`unknown`}function cn(e){let t=e.match(/BV[a-zA-Z0-9]{10}/);if(t)return t[0];let n=e.match(/av(\d+)/i);return n?n[0]:e}function ln(e){let t=e.match(/explore\/([a-zA-Z0-9]+)/);return t?t[1]:e}var un=d.Node.create({name:`videoEmbed`,group:`block`,atom:!0,inline:!1,addNodeView(){return(0,c.ReactNodeViewRenderer)(on)},addProseMirrorPlugins(){return[new f.Plugin({props:{handleKeyDown(e,t){if(t.key!==` `)return!1;let n=e.state.selection;if(n instanceof f.NodeSelection&&n.node.type.name===`videoEmbed`){t.preventDefault();let r=e.nodeDOM(n.from);if(r){let e=r.querySelector(`div`)?.__xgplayer;e&&(e.paused?e.play():e.pause())}return!0}return!1},handlePaste(e,t){let n=t.clipboardData?.getData(`text/plain`);if(!n)return!1;let r=n.split(/\r?\n/);for(let n of r){let r=n.trim();if(!r||r.includes(` `))continue;let i=sn(r);if(i===`unknown`)continue;t.preventDefault();let a=e.state.schema.nodes.videoEmbed.create({src:r,source:i}),o=e.state.tr.replaceSelectionWith(a);return e.dispatch(o),!0}return!1}}})]},addAttributes(){return{src:{default:null},source:{default:`unknown`},name:{default:``},size:{default:0,parseHTML:e=>Number(e.getAttribute(`data-size`)||0)}}},parseHTML(){return[{tag:`div[data-video-embed]`,getAttrs:e=>{let t=e,n=t.getAttribute(`src`)||t.getAttribute(`data-src`)||``;return{src:n,source:sn(n)}}},{tag:`div[data-bilibili]`},{tag:`div[data-xiaohongshu]`}]},renderHTML({HTMLAttributes:e}){let t=e.src||``,n=sn(t);if(n===`bilibili`){let e=cn(t);return[`div`,{"data-video-embed":`bilibili`,src:t,"data-bvid":e,class:`video-embed video-embed--bilibili`,style:`margin: 1rem 0; border-radius: 12px; overflow: hidden;`},[`iframe`,{src:`https://player.bilibili.com/player.html?bvid=${e}&page=1&high_quality=1`,width:`100%`,height:`400`,frameborder:`0`,allowfullscreen:`true`,scrolling:`no`,style:`border: none; display: block;`}]]}if(n===`xiaohongshu`)return ln(t),[`div`,{"data-video-embed":`xiaohongshu`,src:t,class:`video-embed video-embed--xiaohongshu`,style:`border: 1px solid #e5e7eb; border-radius: 12px; padding: 16px; display: flex; align-items: center; gap: 12px; max-width: 480px; margin: 1rem 0;`},[`div`,{style:`width:40px;height:40px;background:#ff2442;border-radius:10px;display:flex;align-items:center;justify-content:center;color:#fff;font-weight:bold;font-size:14px;flex-shrink:0;`},`红`],[`div`,{},[`div`,{style:`font-weight:600;font-size:14px;`},`小红书笔记`],[`a`,{href:t,target:`_blank`,rel:`noopener noreferrer`,style:`color:#ff2442;font-size:12px;text-decoration:none;`},`在小红书中打开 →`]]];let r=`xgplayer-${Math.random().toString(36).slice(2,8)}`;return[`div`,{"data-video-embed":`direct`,src:t,"data-player-id":r,"data-size":e.size||0,class:`video-embed video-embed--direct`,style:`margin: 1rem 0; border-radius: 12px; overflow: hidden; background: #000;`},[`div`,{id:r,style:`width:100%;max-width:720px;`}]]},addCommands(){return{insertVideo:e=>({chain:t})=>{let n=sn(e.src);return t().insertContent({type:this.name,attrs:{...e,source:n}}).focus().run()}}}}),dn=null,fn={fontFamily:`Inter, 'PingFang SC', 'Microsoft YaHei', 'Noto Sans SC', system-ui, sans-serif`,padding:24},pn=.25,mn=4,hn=.25;async function gn(e){return dn||=await import(`pele`),dn.render(e,fn).svg}var _n=[{value:`javascript`,label:`JavaScript`,deviconClass:`devicon-javascript-plain`,color:`#f0db4f`},{value:`typescript`,label:`TypeScript`,deviconClass:`devicon-typescript-plain`,color:`#3178c6`},{value:`python`,label:`Python`,deviconClass:`devicon-python-plain`,color:`#306998`},{value:`java`,label:`Java`,deviconClass:`devicon-java-plain`,color:`#b07219`},{value:`go`,label:`Go`,deviconClass:`devicon-go-plain`,color:`#00add8`},{value:`rust`,label:`Rust`,deviconClass:`devicon-rust-plain`,color:`#dea584`},{value:`c`,label:`C`,deviconClass:`devicon-c-plain`,color:`#555555`},{value:`cpp`,label:`C++`,deviconClass:`devicon-cplusplus-plain`,color:`#f34b7d`},{value:`csharp`,label:`C#`,deviconClass:`devicon-csharp-plain`,color:`#178600`},{value:`html`,label:`HTML`,deviconClass:`devicon-html5-plain`,color:`#e34c26`},{value:`css`,label:`CSS`,deviconClass:`devicon-css3-plain`,color:`#563d7c`},{value:`json`,label:`JSON`,deviconClass:`devicon-json-plain`,color:`#292929`},{value:`sql`,label:`SQL`,deviconClass:`devicon-mysql-plain`,color:`#00758f`},{value:`bash`,label:`Bash`,deviconClass:`devicon-bash-plain`,color:`#3dbb58`},{value:`sh`,label:`Shell (sh)`,deviconClass:`devicon-bash-plain`,color:`#3dbb58`},{value:`shell`,label:`PowerShell`,deviconClass:`devicon-powershell-plain`,color:`#3dbb58`},{value:`yaml`,label:`YAML`,deviconClass:`devicon-yaml-plain`,color:`#cb171e`},{value:`php`,label:`PHP`,deviconClass:`devicon-php-plain`,color:`#4f5d95`},{value:`ruby`,label:`Ruby`,deviconClass:`devicon-ruby-plain`,color:`#701516`},{value:`swift`,label:`Swift`,deviconClass:`devicon-swift-plain`,color:`#f05138`},{value:`kotlin`,label:`Kotlin`,deviconClass:`devicon-kotlin-plain`,color:`#a97bff`},{value:`dockerfile`,label:`Dockerfile`,deviconClass:`devicon-docker-plain`,color:`#0db7ed`},{value:`vue`,label:`Vue`,deviconClass:`devicon-vuejs-plain`,color:`#42b883`},{value:`react`,label:`React`,deviconClass:`devicon-react-plain`,color:`#61dafb`},{value:`markdown`,label:`Markdown`,deviconClass:`devicon-markdown-plain`,color:`#083fa1`},{value:`mermaid`,label:`Mermaid`,color:`#ff3670`},{value:`txt`,label:`Plain Text`,color:`#6b7280`}],vn={javascript:`js`,typescript:`ts`,python:`py`,java:`java`,go:`go`,rust:`rs`,c:`c`,cpp:`cpp`,csharp:`cs`,html:`html`,css:`css`,json:`json`,sql:`sql`,bash:`sh`,shell:`sh`,yaml:`yml`,php:`php`,ruby:`rb`,swift:`swift`,kotlin:`kt`,dockerfile:``,markdown:`md`,txt:`txt`,vue:`vue`,react:`jsx`},yn={js:`javascript`,ts:`typescript`,py:`python`,rb:`ruby`,rs:`rust`,kt:`kotlin`,cs:`csharp`,"c++":`cpp`,"c#":`csharp`,golang:`go`,yml:`yaml`,ps1:`shell`,jsx:`javascript`,tsx:`typescript`};function bn({node:t,updateAttributes:n,editor:r,getPos:o,deleteNode:s,selected:c}){let l=r?.isEditable??!0,d=!l,[f,p]=(0,i.useState)(!1),[m,h]=(0,i.useState)(!1),[g,_]=(0,i.useState)(!1),[v,y]=(0,i.useState)(!1),[b,x]=(0,i.useState)(220),[S,C]=(0,i.useState)({top:0,left:0,width:210}),[w,T]=(0,i.useState)(``),[E,D]=(0,i.useState)(!1),[O,k]=(0,i.useState)(null),[A,j]=(0,i.useState)(null),[M,N]=(0,i.useState)(!1),[P,F]=(0,i.useState)(!1),[ee,I]=(0,i.useState)(1),[L,R]=(0,i.useState)({x:0,y:0}),[te,ne]=(0,i.useState)(!1),re=(0,i.useRef)(null),z=(0,i.useRef)(null),B=(0,i.useRef)(null),ie=(0,i.useRef)(null),V=(0,i.useRef)(null),ae=(0,i.useRef)(null),oe=(0,i.useRef)(null),H=t.attrs.language||``,U=_n.find(e=>e.value===(yn[H]??H)),W=H===`mermaid`,se=e=>Math.min(mn,Math.max(pn,e)),G=e=>I(t=>Math.round(se(t+e)*100)/100),K=()=>{I(1),R({x:0,y:0})},ce=()=>{K(),F(!0)};(0,i.useEffect)(()=>{O||F(!1)},[O]),(0,i.useEffect)(()=>{if(!P)return;let e=document.body.style.overflow;document.body.style.overflow=`hidden`;let t=e=>{e.key===`Escape`&&F(!1)};return window.addEventListener(`keydown`,t),()=>{document.body.style.overflow=e,window.removeEventListener(`keydown`,t)}},[P]);let le=e=>{e.button===0&&(e.currentTarget.setPointerCapture(e.pointerId),re.current={x:e.clientX,y:e.clientY,panX:L.x,panY:L.y},ne(!0))},ue=e=>{let t=re.current;t&&R({x:t.panX+e.clientX-t.x,y:t.panY+e.clientY-t.y})},de=()=>{re.current=null,ne(!1)},fe=(0,i.useCallback)(()=>{if(!r||typeof o!=`function`)return null;let e=o();return typeof e==`number`?{from:e,to:e+t.nodeSize}:null},[r,o,t.nodeSize]),pe=(0,i.useCallback)(()=>{l&&(jt()||(oe.current=fe(),window.getSelection()?.removeAllRanges(),$(!0),D(!0)))},[fe,l]),q=(0,i.useMemo)(()=>{let e=w.trim().toLowerCase();return e?_n.filter(t=>t.label.toLowerCase().includes(e)||t.value.toLowerCase().includes(e)):_n},[w]);(0,i.useEffect)(()=>{(ae.current?.closest(`.code-block-node-view`))?.classList.toggle(`code-block-node-view--collapsed`,m)},[m]);let me=(0,i.useCallback)(()=>{let e=ie.current;if(!e)return;let t=e.getBoundingClientRect(),n=Math.min(t.left,window.innerWidth-210-8),r=window.innerHeight-t.bottom-12,i=t.top-12,a=_n.length*31+8,o=r-52,s=i-52;o<220&&s>o?(y(!0),x(Math.max(120,Math.min(a,s))),C({top:t.top,left:n,width:210})):(y(!1),x(Math.max(120,Math.min(a,o))),C({top:t.bottom+4,left:n,width:210}))},[]);(0,i.useEffect)(()=>{if(!g)return;T(``),me();let e=setTimeout(()=>V.current?.focus(),50);return window.addEventListener(`resize`,me),window.addEventListener(`scroll`,me,!0),()=>{clearTimeout(e),window.removeEventListener(`resize`,me),window.removeEventListener(`scroll`,me,!0)}},[g,me]),(0,i.useEffect)(()=>{if(!g)return;let e=e=>{let t=e.target;t&&(ie.current?.contains(t)||B.current?.contains(t)||_(!1))};return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[g]),(0,i.useEffect)(()=>{if(!g)return;let e=e=>{e.key===`Escape`&&_(!1)};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[g]),(0,i.useEffect)(()=>{let e=e=>{if(e.key!==`Backspace`&&e.key!==`Delete`||!l||!c||jt())return;let t=r?.view?.dom,n=e.target;if(r?.isFocused&&n instanceof Node&&t?.contains(n)){if(e.preventDefault(),e.stopPropagation(),r){let{from:e,to:t}=r.state.selection;oe.current={from:e,to:t}}window.getSelection()?.removeAllRanges(),$(!0),D(!0)}};return window.addEventListener(`keydown`,e,!0),()=>window.removeEventListener(`keydown`,e,!0)},[c,r,l]);let he=(0,i.useCallback)(e=>{n({language:e||null}),_(!1)},[n]),ge=(0,i.useCallback)(()=>{if(l){if(r&&o){let e=o();r.chain().focus().setNodeSelection(e).run()}_(!1),(r?.storage?.qingwuUI)?.openAI?.()}},[r,o,l]),_e=(0,i.useCallback)(()=>{let e=t.textContent,n=e=>{let t=document.createElement(`textarea`);t.value=e,t.style.position=`fixed`,t.style.opacity=`0`,document.body.appendChild(t),t.select();try{document.execCommand(`copy`)}catch{}document.body.removeChild(t)};navigator.clipboard?.writeText?navigator.clipboard.writeText(e).catch(()=>n(e)):n(e),p(!0),setTimeout(()=>p(!1),1500)},[t.textContent]),J=(0,i.useCallback)(()=>{let e=vn[H]||`txt`,n=e?`code.${e}`:`code.txt`,r=new Blob([t.textContent],{type:`text/plain;charset=utf-8`}),i=URL.createObjectURL(r),a=document.createElement(`a`);a.href=i,a.download=n,document.body.appendChild(a),a.click(),document.body.removeChild(a),URL.revokeObjectURL(i)},[t.textContent,H]),ve=(0,i.useCallback)(async()=>{if(O||M){k(null),j(null),N(!1);return}N(!0),j(null),k(null);try{let n=(t.textContent||``).trim();if(!n){j(`代码块内容为空`);return}let r=e.r(await gn(n));k(r)}catch(e){j(e instanceof Error?e.message:`图表渲染失败`)}finally{N(!1)}},[t.textContent,O,M]),ye=(0,a.jsxs)(a.Fragment,{children:[U?U.deviconClass?(0,a.jsx)(`i`,{className:`${U.deviconClass} colored cb-lang-icon`,style:{color:U.color}}):(0,a.jsx)(`span`,{className:`cb-lang-icon cb-lang-icon--auto`,children:`Tx`}):(0,a.jsx)(`span`,{className:`cb-lang-icon cb-lang-icon--auto`,children:`?`}),(0,a.jsx)(`span`,{className:`cb-lang-label`,children:U?.label||`自动`})]});return(0,a.jsxs)(`div`,{ref:ae,className:`cb-react-shell group/cb`,style:{display:`contents`},children:[(0,a.jsxs)(`div`,{className:`cb-header${m?` cb-header--collapsed`:``}`,contentEditable:!1,onMouseDown:e=>e.stopPropagation(),children:[(0,a.jsx)(`div`,{className:`cb-lang-wrap`,ref:z,contentEditable:!1,children:d?(0,a.jsx)(`span`,{className:`cb-lang-trigger cb-lang-trigger--static`,children:ye}):(0,a.jsxs)(`button`,{ref:ie,type:`button`,className:`cb-lang-trigger`,onClick:()=>_(!g),children:[ye,(0,a.jsx)(`svg`,{className:`cb-lang-chevron${g?` cb-lang-chevron--open`:``}`,width:`10`,height:`10`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2.5`,children:(0,a.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M6 9l6 6 6-6`})})]})}),m&&(0,a.jsxs)(`button`,{type:`button`,className:`cb-collapsed-bar`,contentEditable:!1,onClick:()=>h(!1),title:`展开代码块`,children:[ye,(0,a.jsx)(`svg`,{className:`cb-lang-chevron`,width:`12`,height:`12`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2.5`,children:(0,a.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M6 9l6 6 6-6`})})]}),l&&g&&(0,u.createPortal)((0,a.jsxs)(`div`,{ref:B,className:`cb-lang-dropdown${v?` cb-lang-dropdown--up`:``}`,style:{position:`fixed`,top:S.top,left:S.left,width:S.width,zIndex:10002},children:[(0,a.jsxs)(`div`,{className:`cb-lang-search-wrap`,children:[(0,a.jsx)(`svg`,{className:`cb-lang-search-icon`,width:`14`,height:`14`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,children:(0,a.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M21 21l-6-6m2-5a7 7 0 11-14 0 7 7 0 0114 0z`})}),(0,a.jsx)(`input`,{ref:V,className:`cb-lang-search`,type:`text`,placeholder:`搜索语言...`,value:w,onChange:e=>T(e.target.value),onKeyDown:e=>e.stopPropagation()})]}),(0,a.jsxs)(`div`,{className:`cb-lang-list`,style:{maxHeight:b},children:[(0,a.jsxs)(`button`,{type:`button`,className:`cb-lang-option${H?``:` cb-lang-option--active`}`,onClick:()=>he(``),children:[(0,a.jsx)(`span`,{className:`cb-lang-icon cb-lang-icon--auto`,children:`?`}),(0,a.jsx)(`span`,{children:`自动检测`})]}),q.map(e=>(0,a.jsxs)(`button`,{type:`button`,className:`cb-lang-option${H===e.value?` cb-lang-option--active`:``}`,onClick:()=>he(e.value),children:[e.deviconClass?(0,a.jsx)(`i`,{className:`${e.deviconClass} colored cb-lang-icon`,style:{color:e.color}}):(0,a.jsx)(`span`,{className:`cb-lang-icon cb-lang-icon--auto`,children:`Tx`}),(0,a.jsx)(`span`,{children:e.label})]},e.value)),q.length===0&&(0,a.jsx)(`div`,{className:`cb-lang-empty`,children:`无匹配语言`})]})]}),document.body),(0,a.jsxs)(`div`,{className:`cb-actions`,children:[(0,a.jsx)(`button`,{type:`button`,className:`cb-btn`,onClick:()=>h(!m),contentEditable:!1,title:m?`展开`:`折叠`,children:(0,a.jsx)(`svg`,{className:`cb-btn-icon`,fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,strokeWidth:`2`,children:m?(0,a.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M6 9l6 6 6-6`}):(0,a.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M6 15l6-6 6 6`})})}),(0,a.jsx)(`button`,{type:`button`,className:`cb-btn`,onClick:_e,contentEditable:!1,title:`复制`,children:f?(0,a.jsx)(`svg`,{className:`cb-btn-icon cb-btn-icon--check`,fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,strokeWidth:`2.5`,children:(0,a.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M5 13l4 4L19 7`})}):(0,a.jsx)(`svg`,{className:`cb-btn-icon`,fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,strokeWidth:`2`,children:(0,a.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M8 16H6a2 2 0 01-2-2V6a2 2 0 012-2h8a2 2 0 012 2v2m-6 12h8a2 2 0 002-2v-8a2 2 0 00-2-2h-8a2 2 0 00-2 2v8a2 2 0 002 2z`})})}),(0,a.jsx)(`button`,{type:`button`,className:`cb-btn`,onClick:J,contentEditable:!1,title:`下载`,children:(0,a.jsx)(`svg`,{className:`cb-btn-icon`,fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,strokeWidth:`2`,children:(0,a.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M4 16v1a3 3 0 003 3h10a3 3 0 003-3v-1m-4-4l-4 4m0 0l-4-4m4 4V4`})})}),l&&(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(`button`,{type:`button`,className:`cb-btn cb-btn--ai`,onClick:ge,contentEditable:!1,title:`写作助手`,children:(0,a.jsx)(`svg`,{className:`cb-btn-icon`,fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,strokeWidth:`2`,children:(0,a.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M13 10V3L4 14h7v7l9-11h-7z`})})}),(0,a.jsx)(`button`,{type:`button`,className:`cb-btn cb-btn--del`,onClick:pe,contentEditable:!1,title:`删除代码块`,children:(0,a.jsx)(`svg`,{className:`cb-btn-icon`,fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,strokeWidth:`2`,children:(0,a.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16`})})})]}),W&&(0,a.jsx)(`button`,{type:`button`,className:`cb-btn cb-btn--diagram`,onClick:ve,contentEditable:!1,title:O||M?`取消渲染`:`渲染图表`,disabled:M,children:(0,a.jsx)(`svg`,{className:`cb-btn-icon`,fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,strokeWidth:`2`,children:(0,a.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M4 5a1 1 0 011-1h4a1 1 0 011 1v5a1 1 0 01-1 1H5a1 1 0 01-1-1V5zM14 5a1 1 0 011-1h4a1 1 0 011 1v2a1 1 0 01-1 1h-4a1 1 0 01-1-1V5zM4 16a1 1 0 011-1h4a1 1 0 011 1v3a1 1 0 01-1 1H5a1 1 0 01-1-1v-3zM14 13a1 1 0 011-1h4a1 1 0 011 1v6a1 1 0 01-1 1h-4a1 1 0 01-1-1v-6z`})})})]})]}),(O||A||M)&&(0,a.jsxs)(`div`,{className:`cb-diagram-output`,contentEditable:!1,children:[M&&(0,a.jsx)(`div`,{className:`cb-diagram-loading`,children:`渲染图表中…`}),A&&(0,a.jsxs)(`div`,{className:`cb-diagram-error`,children:[(0,a.jsx)(`span`,{className:`cb-diagram-error-icon`,children:`!`}),A]}),O&&(0,a.jsxs)(`div`,{className:`cb-diagram-svg`,role:`button`,tabIndex:0,title:`点击放大查看`,onClick:ce,onKeyDown:e=>{(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),ce())},children:[(0,a.jsx)(`div`,{className:`cb-diagram-svg-inner`,dangerouslySetInnerHTML:{__html:O}}),(0,a.jsx)(`span`,{className:`cb-diagram-zoom-hint`,children:`点击放大`})]})]}),P&&O&&(0,u.createPortal)((0,a.jsxs)(`div`,{className:`fixed inset-0 z-[10002] flex flex-col bg-black/75 backdrop-blur-sm select-none`,role:`dialog`,"aria-modal":`true`,"aria-label":`Mermaid 图表预览`,children:[(0,a.jsxs)(`div`,{className:`flex items-center justify-between gap-3 px-4 py-3 text-white`,children:[(0,a.jsx)(`span`,{className:`text-sm font-medium`,children:`Mermaid 图表`}),(0,a.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,a.jsx)(`button`,{type:`button`,className:`flex h-8 min-w-8 items-center justify-center rounded-lg bg-white/10 px-2 text-base text-white transition-colors hover:bg-white/20`,onClick:()=>G(-.25),title:`缩小`,"aria-label":`缩小`,children:`−`}),(0,a.jsxs)(`button`,{type:`button`,className:`flex h-8 min-w-14 items-center justify-center rounded-lg bg-white/10 px-2 text-xs text-white transition-colors hover:bg-white/20`,onClick:K,title:`重置为 100%`,"aria-label":`重置缩放`,children:[Math.round(ee*100),`%`]}),(0,a.jsx)(`button`,{type:`button`,className:`flex h-8 min-w-8 items-center justify-center rounded-lg bg-white/10 px-2 text-base text-white transition-colors hover:bg-white/20`,onClick:()=>G(hn),title:`放大`,"aria-label":`放大`,children:`+`}),(0,a.jsx)(`button`,{type:`button`,className:`flex h-8 min-w-8 items-center justify-center rounded-lg bg-white/10 px-2 text-sm text-white transition-colors hover:bg-white/20`,onClick:K,title:`重置`,"aria-label":`重置`,children:`⟲`}),(0,a.jsx)(`span`,{className:`mx-1 h-5 w-px bg-white/20`}),(0,a.jsx)(`button`,{type:`button`,className:`flex h-8 min-w-8 items-center justify-center rounded-lg bg-white/10 px-2 text-lg text-white transition-colors hover:bg-white/20`,onClick:()=>F(!1),title:`关闭`,"aria-label":`关闭`,children:`×`})]})]}),(0,a.jsx)(`div`,{className:`flex flex-1 touch-none items-center justify-center overflow-hidden`,style:{cursor:te?`grabbing`:ee>1?`grab`:`default`},onWheel:e=>G(e.deltaY>0?-.25:hn),onPointerDown:le,onPointerMove:ue,onPointerUp:de,onPointerCancel:de,onDoubleClick:()=>{I(e=>e===1?2:1),R({x:0,y:0})},children:(0,a.jsx)(`div`,{className:`cb-diagram-zoom-content`,style:{transform:`translate(${L.x}px, ${L.y}px) scale(${ee})`,transition:te?`none`:`transform 120ms ease-out`},dangerouslySetInnerHTML:{__html:O}})})]}),document.body),(0,a.jsx)(It,{open:E,title:`确认删除代码块`,message:`此操作不可撤销。`,onCancel:()=>{$(!1),D(!1)},onConfirm:async()=>{await new Promise(e=>setTimeout(e,300)),$(!1),s()}})]})}var xn=[{value:`javascript`,label:`JavaScript`},{value:`typescript`,label:`TypeScript`},{value:`python`,label:`Python`},{value:`java`,label:`Java`},{value:`go`,label:`Go`},{value:`rust`,label:`Rust`},{value:`c`,label:`C`},{value:`cpp`,label:`C++`},{value:`csharp`,label:`C#`},{value:`html`,label:`HTML/XML`},{value:`css`,label:`CSS`},{value:`json`,label:`JSON`},{value:`sql`,label:`SQL`},{value:`bash`,label:`Bash`},{value:`shell`,label:`Shell`},{value:`yaml`,label:`YAML`},{value:`php`,label:`PHP`},{value:`ruby`,label:`Ruby`},{value:`swift`,label:`Swift`},{value:`kotlin`,label:`Kotlin`},{value:`dockerfile`,label:`Dockerfile`},{value:`vue`,label:`Vue`},{value:`react`,label:`React`},{value:`markdown`,label:`Markdown`},{value:`mermaid`,label:`Mermaid`}],Sn=(0,N.createLowlight)(N.common);Sn.register({dockerfile:M.default}),Sn.registerAlias(`xml`,[`vue`,`html`]),Sn.registerAlias(`javascript`,[`react`,`jsx`]),Sn.registerAlias(`typescript`,[`tsx`]);function Cn(e){return e?e.split(`
|
|
4
4
|
`):[``]}function wn(e,t){if(e.childElementCount!==t){e.replaceChildren();for(let n=1;n<=t;n++){let t=document.createElement(`span`);t.className=`cb-line-num`,t.textContent=String(n),e.appendChild(t)}}}function Tn(e,t){e.replaceChildren();for(let n of t){let t=document.createElement(`span`);t.className=`cb-mirror-line`,t.textContent=n.length?n:`\xA0`,e.appendChild(t)}}function En(e,t,n){let r=getComputedStyle(e),i=parseFloat(r.paddingLeft),a=parseFloat(r.paddingRight);t.style.boxSizing=`content-box`,t.style.width=`${Math.max(0,e.clientWidth-i-a)}px`,t.style.padding=r.padding;let o=getComputedStyle(n);(o.paddingTop!==r.paddingTop||o.paddingBottom!==r.paddingBottom)&&(n.style.paddingTop=r.paddingTop,n.style.paddingBottom=r.paddingBottom);let s=e.querySelector(`code`),c=parseFloat(r.lineHeight)||24;if(!s){for(let e=0;e<n.children.length;e++)n.children[e].style.height=`${c}px`;return}let l=s.textContent??``,u=[],d=0;for(let e=0;e<=l.length;e++)(e===l.length||l[e]===`
|
|
5
5
|
`)&&(u.push([d,e]),d=e+1);let f=[],p=[],m=0,h=document.createTreeWalker(s,NodeFilter.SHOW_TEXT),g;for(;g=h.nextNode();)f.push(g),p.push(m),m+=g.textContent?.length??0;let _=e=>{for(let t=0;t<f.length;t++){let n=p[t];if(e<=n+(f[t].textContent?.length??0))return{node:f[t],offset:e-n}}let t=f[f.length-1];return t?{node:t,offset:t.textContent?.length??0}:null},v=e.getBoundingClientRect(),y=parseFloat(r.paddingTop),b=v.top+y,x=v.bottom-parseFloat(r.paddingBottom),S=document.createRange(),C=[];for(let e=0;e<u.length;e++){let[t,n]=u[e],r=NaN,i=_(t),a=_(n);if(i&&a){S.setStart(i.node,i.offset),S.setEnd(a.node,a.offset);let e=S.getClientRects(),t=1/0;for(let n=0;n<e.length;n++)e[n].height>0&&e[n].top<t&&(t=e[n].top);Number.isFinite(t)&&(r=t-b)}C.push(r)}for(let e=0;e<C.length;e++)Number.isFinite(C[e])||(C[e]=e>0?C[e-1]+c:0);let w=x-b,T=0;for(let e=0;e<u.length;e++){let t=n.children[e];if(!t)continue;let r;r=e+1<C.length?C[e+1]-C[e]:w-T,(!Number.isFinite(r)||r<1)&&(r=c),t.style.height=`${r}px`,T+=r}}var Dn=j.CodeBlockLowlight.extend({addNodeView(){return e=>{let{node:t,editor:n,getPos:r}=e,i=t,a=e=>{let t=typeof r==`function`?r():void 0;typeof t==`number`&&n.chain().command(({tr:n})=>(n.setNodeMarkup(t,void 0,{...i.attrs,...e}),!0)).run()},o=()=>{let e=typeof r==`function`?r():void 0;typeof e==`number`&&n.chain().command(({tr:t})=>(t.delete(e,e+i.nodeSize),!0)).run()},s=document.createElement(`div`);s.className=`code-block-node-view group/cb`;let l=document.createElement(`div`);l.contentEditable=`false`,s.appendChild(l);let u=document.createElement(`div`);u.className=`cb-code-area`;let d=document.createElement(`div`);d.className=`cb-code-inner`;let f=document.createElement(`div`);f.className=`cb-line-numbers`,f.contentEditable=`false`,f.setAttribute(`aria-hidden`,`true`);let p=document.createElement(`pre`);p.className=`cb-code-pre`;let m=document.createElement(`code`);p.appendChild(m);let h=document.createElement(`div`);h.className=`cb-code-mirror`,h.contentEditable=`false`,h.setAttribute(`aria-hidden`,`true`),d.appendChild(f),d.appendChild(p),d.appendChild(h),u.appendChild(d),s.appendChild(u);let g=Cn(t.textContent);wn(f,g.length),Tn(h,g);let _=new c.ReactRenderer(bn,{editor:n,props:{node:t,editor:n,getPos:r,updateAttributes:a,deleteNode:o,selected:!1}});l.appendChild(_.element);let v=e=>{let t=Cn(e.textContent);wn(f,t.length),Tn(h,t),requestAnimationFrame(()=>En(p,h,f))};requestAnimationFrame(()=>En(p,h,f));let y=new ResizeObserver(()=>En(p,h,f));return y.observe(p),document.fonts?.ready?.then(()=>En(p,h,f)),{dom:s,contentDOM:m,update(e){return e.type!==t.type||!e.sameMarkup(i)?!1:(i=e,_.updateProps({node:e,editor:n,getPos:r,updateAttributes:a,deleteNode:o,selected:s.classList.contains(`ProseMirror-selectednode`)}),v(e),!0)},selectNode(){s.classList.add(`ProseMirror-selectednode`),_.updateProps({node:i,editor:n,getPos:r,updateAttributes:a,deleteNode:o,selected:!0})},deselectNode(){s.classList.remove(`ProseMirror-selectednode`),_.updateProps({node:i,editor:n,getPos:r,updateAttributes:a,deleteNode:o,selected:!1})},stopEvent(e){let t=e.target;return!!(t&&l.contains(t))},ignoreMutation(e){return!m.contains(e.target)},destroy(){y.disconnect(),_.destroy()}}}},parseHTML(){return(this.parent?.()??[]).map(e=>({...e,getContent:(e,t)=>{let n=e,r=n.querySelector(`:scope > code`),i=Array.from((r??n).querySelectorAll(`:scope > div`));if(i.length>0){let e=i.map(e=>e.textContent??``).join(`
|
|
6
6
|
`);return e?s.Fragment.from(t.text(e)):s.Fragment.empty}let a=n.textContent??``;return a?s.Fragment.from(t.text(a)):s.Fragment.empty}}))}}).configure({lowlight:Sn});function On(e){return new Promise(t=>{let n=document.createElement(`div`);n.className=`fixed inset-0 z-[10001] flex items-center justify-center bg-black/40 backdrop-blur-sm select-none`;let r=document.createElement(`div`);r.className=`bg-white dark:bg-zinc-800 rounded-xl p-6 shadow-xl max-w-sm w-full mx-4 border border-default-200 relative overflow-hidden`;let i=document.createElement(`div`);i.className=`text-sm font-medium text-default-800 dark:text-zinc-100 mb-2`,i.textContent=`导入 Markdown`;let a=document.createElement(`div`);a.className=`text-xs text-default-500 dark:text-zinc-400 mb-4 whitespace-pre-line`,a.textContent=`将 "${e}" 渲染到编辑器,还是作为附件附加?`;let o=document.createElement(`div`);o.className=`flex justify-end gap-2`;let s=e=>{document.removeEventListener(`keydown`,c),n.remove(),t(e)},c=e=>{e.key===`Escape`&&s(null)};n.addEventListener(`mousedown`,e=>{e.target===n&&s(null)});let l=document.createElement(`button`);l.type=`button`,l.className=`px-3 py-1.5 text-xs rounded-lg border border-default-200 hover:bg-default-100 transition-colors`,l.textContent=`取消`,l.addEventListener(`click`,()=>s(null));let u=document.createElement(`button`);u.type=`button`,u.className=`px-3 py-1.5 text-xs rounded-lg border border-default-200 hover:bg-default-100 transition-colors`,u.textContent=`附加`,u.addEventListener(`click`,()=>s(`attach`));let d=document.createElement(`button`);d.type=`button`,d.className=`px-3 py-1.5 text-xs rounded-lg bg-blue-500 hover:bg-blue-600 text-white transition-colors`,d.textContent=`渲染`,d.addEventListener(`click`,()=>s(`render`)),o.append(l,u,d),r.append(i,a,o),n.appendChild(r),document.addEventListener(`keydown`,c),document.body.appendChild(n)})}var kn=/\.(png|jpe?g|gif|webp|bmp|svg|avif|mp4|m4v|webm|ogg|mov|avi|mkv|mp3|wav|flac|m4a|aac|opus|pdf|docx?|xlsx?|pptx?|odt|rtf|txt|md|csv|zip|rar|7z|json)(\?|#|$)/i,An=/^(?:mailto:|tel:|javascript:|about:|data:|blob:)/i;function jn(e){if(!e)return!1;let t=e.trim();return!(!t||/^(?:https?:)?\/\//i.test(t)||An.test(t)||t.startsWith(`#`))}function Mn(e){return kn.test(e)}function Nn(e){let t=e.trim();t=t.replace(/^(?:file|app):\/\/(?:localhost)?/i,``);try{t=decodeURIComponent(t)}catch{}return t=t.replace(/\\/g,`/`),t=t.replace(/^\.\//,``),t=t.replace(/^\/+/,``),t=t.replace(/^[a-zA-Z]:\//,``),t}function Pn(e){let t=Nn(e),n=t.split(`/`).filter(Boolean);return(n[n.length-1]||t).toLowerCase()}function Fn(){return typeof window>`u`||window.isSecureContext===!1?!1:typeof window.showDirectoryPicker==`function`}async function In(){if(!Fn())return null;try{return await window.showDirectoryPicker.call(window,{mode:`read`})??null}catch{return null}}function Ln(){return typeof window>`u`||window.isSecureContext===!1?!1:typeof window.showOpenFilePicker==`function`}async function Rn(){if(!Ln())return null;try{let e=await window.showOpenFilePicker.call(window,{multiple:!0});return await Promise.all(e.map(e=>e.getFile()))}catch{return null}}async function zn(e,t){if(t.length===0)return{file:null};let n=e;for(let e=0;e<t.length-1;e++)try{n=await n.getDirectoryHandle(t[e])}catch{return{file:null}}try{let e=await n.getFileHandle(t[t.length-1]);try{return{file:await e.getFile()}}catch(e){return{file:null,readError:e}}}catch{return{file:null}}}async function Bn(e,t,n=5e3){let r=t.toLowerCase(),i=[e],a=0,o;for(;i.length>0&&a<n;){let e=i.pop();try{for await(let t of e.values()){if(a++,a>n)break;if(t.kind===`file`){if(t.name.toLowerCase()===r)try{return{file:await t.getFile()}}catch(e){o=e}}else t.kind===`directory`&&i.push(t)}}catch{}}return a>=n&&console.warn(`目录遍历预算 ${n} 已耗尽,「${t}」可能藏在不完整的搜索范围内`),{file:null,readError:o}}async function Vn(e,t){let n=Nn(t).split(`/`).filter(Boolean);if(n.length===0)return{file:null};let r;for(let t=0;t<n.length;t++){let i=await zn(e,n.slice(t));if(i.file)return i;i.readError&&(r=i.readError)}let i=await Bn(e,n[n.length-1]);return i.file||i.readError?i:{file:null,readError:r}}var Hn={image:`image`,videoEmbed:`video`,audioEmbed:`audio`,attachmentEmbed:`attachment`};function Un(e,t){let n=new Set,r=[];return e.descendants(e=>{let i=Hn[e.type?.name];if(i){let a=e.attrs?.src,o=`node:${a}`;typeof a==`string`&&jn(a)&&!n.has(o)&&!t?.(a)&&(n.add(o),r.push({src:a,normalized:Nn(a),basename:Pn(a),kind:i,isLink:!1}));return}if(e.isText&&e.marks)for(let i of e.marks){if(i.type.name!==`link`)continue;let e=i.attrs?.href,a=`link:${e}`;typeof e==`string`&&jn(e)&&Mn(e)&&!n.has(a)&&!t?.(e)&&(n.add(a),r.push({src:e,normalized:Nn(e),basename:Pn(e),kind:`attachment`,isLink:!0}))}}),r}function Wn(e,t,n){let r=t?`${e}\n${t}`:e;if(!r)return!1;let i=[];for(let e of r.matchAll(/!?\[[^\]]*\]\(([^)\s]+)(?:\s+"[^"]*")?\)/g))i.push(e[1]);for(let e of r.matchAll(/!?\[\[([^\]|]+)(?:\|[^\]]+)?\]\]/g))i.push(e[1]);for(let e of r.matchAll(/<(?:img|video|audio|source)[^>]*\bsrc=["']([^"']+)["']/gi))i.push(e[1]);for(let e of r.matchAll(/<a[^>]*\bhref=["']([^"']+)["']/gi))i.push(e[1]);return i.some(e=>Mn(e)&&jn(e)&&!n?.(e))}function Gn(e){if(e.type.startsWith(`image/`))return`image`;if(e.type.startsWith(`video/`))return`video`;if(e.type.startsWith(`audio/`))return`audio`;let t=e.name.split(`.`).pop()?.toLowerCase()||``;return/^(png|jpe?g|gif|webp|bmp|svg|avif)$/.test(t)?`image`:/^(mp4|m3u8|webm|ogg|mov|avi|wmv|flv|mkv|ts|m4v|3gp|f4v|rmvb)$/.test(t)?`video`:/^(mp3|wav|flac|aac|m4a|wma|opus)$/.test(t)?`audio`:/^(md|markdown)$/.test(t)?`markdown`:`file`}function Kn(e){let t=e.name.split(`.`).pop()?.toLowerCase()||``;return t===`md`||t===`markdown`}async function qn(e,t,n,r){let i=n??e.state.selection.from,a=r?Et(r):void 0,o=r?.storage?.qingwuUI,s=await new Promise(e=>{o?.chooseMd?o.chooseMd(t.name,e):On(t.name).then(e)});if(s===null)return;if(s===`attach`){let n=a?Dt(e.state.doc,t,a):null;if(n){J(n);return}let r=URL.createObjectURL(t),o=e.state.schema.nodes.attachmentEmbed?.create({src:r,name:t.name,size:t.size,type:t.type});if(o)try{e.dispatch(e.state.tr.insert(i,o))}catch{}return}let c=await t.text();if(o?.parseMd){let t=o.parseMd(e.state.schema,c);if(t){e.dispatch(e.state.tr.insert(i,t));return}}let l=c.split(`
|
package/dist/index.js
CHANGED
|
@@ -4293,17 +4293,11 @@ var Xn = ie.create({
|
|
|
4293
4293
|
} };
|
|
4294
4294
|
}
|
|
4295
4295
|
}), Zn = null, Qn = {
|
|
4296
|
-
|
|
4297
|
-
|
|
4298
|
-
accent: "var(--color-qingwu-600, #0891b2)",
|
|
4299
|
-
transparent: !0,
|
|
4300
|
-
font: "Inter, 'PingFang SC', 'Microsoft YaHei', 'Noto Sans SC', system-ui, sans-serif",
|
|
4301
|
-
padding: 32
|
|
4296
|
+
fontFamily: "Inter, 'PingFang SC', 'Microsoft YaHei', 'Noto Sans SC', system-ui, sans-serif",
|
|
4297
|
+
padding: 24
|
|
4302
4298
|
}, $n = .25, er = 4, tr = .25;
|
|
4303
|
-
async function nr(e
|
|
4304
|
-
Zn ||= await import("
|
|
4305
|
-
let n = Zn.renderMermaidSVG;
|
|
4306
|
-
return n(e, t);
|
|
4299
|
+
async function nr(e) {
|
|
4300
|
+
return Zn ||= await import("pele"), Zn.render(e, Qn).svg;
|
|
4307
4301
|
}
|
|
4308
4302
|
var rr = [
|
|
4309
4303
|
{
|
|
@@ -4666,10 +4660,10 @@ function or({ node: e, updateAttributes: t, editor: n, getPos: r, deleteNode: i,
|
|
|
4666
4660
|
F("代码块内容为空");
|
|
4667
4661
|
return;
|
|
4668
4662
|
}
|
|
4669
|
-
let n = p(await nr(t
|
|
4663
|
+
let n = p(await nr(t));
|
|
4670
4664
|
ee(n);
|
|
4671
4665
|
} catch (e) {
|
|
4672
|
-
F(e instanceof Error ? e.message : "
|
|
4666
|
+
F(e instanceof Error ? e.message : "图表渲染失败");
|
|
4673
4667
|
} finally {
|
|
4674
4668
|
te(!1);
|
|
4675
4669
|
}
|