@qingwu-ui/ai-editor 0.9.0-beta.2 → 0.9.0-beta.20
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 +17 -5
- package/dist/clipper.d.ts +2 -7
- package/dist/components/ai-settings-dialog.d.ts.map +1 -1
- package/dist/components/export-dialog.d.ts.map +1 -1
- package/dist/components/image-upload-dialog.d.ts.map +1 -1
- package/dist/components/md-import-dialog.d.ts.map +1 -1
- package/dist/components/search-bar.d.ts +3 -10
- package/dist/components/search-bar.d.ts.map +1 -1
- package/dist/components/storage-settings-dialog.d.ts.map +1 -1
- package/dist/components/toast.d.ts.map +1 -1
- package/dist/components/toc.d.ts +13 -6
- package/dist/components/toc.d.ts.map +1 -1
- package/dist/components/video-embed-dialog.d.ts.map +1 -1
- package/dist/editor/ai/components/ai-selector.d.ts.map +1 -1
- package/dist/editor/ai/index.d.ts +4 -9
- package/dist/editor/ai/index.d.ts.map +1 -1
- package/dist/editor/ai/pending-removal.d.ts +3 -13
- package/dist/editor/ai/pending-removal.d.ts.map +1 -1
- package/dist/editor/ai/providers/deepseek.d.ts +2 -5
- package/dist/editor/ai/providers/deepseek.d.ts.map +1 -1
- package/dist/editor/ai/providers/openai-compat.d.ts +2 -9
- package/dist/editor/ai/providers/openai-compat.d.ts.map +1 -1
- package/dist/editor/ai/providers/openai.d.ts +1 -5
- package/dist/editor/ai/providers/openai.d.ts.map +1 -1
- package/dist/editor/ai/providers/qwen.d.ts +2 -7
- package/dist/editor/ai/providers/qwen.d.ts.map +1 -1
- package/dist/editor/ai-editor.d.ts +7 -18
- package/dist/editor/ai-editor.d.ts.map +1 -1
- package/dist/editor/attachment-limits.d.ts +5 -16
- package/dist/editor/attachment-limits.d.ts.map +1 -1
- package/dist/editor/clipper/receiver-browser.d.ts +1 -13
- package/dist/editor/clipper/receiver-browser.d.ts.map +1 -1
- package/dist/editor/clipper/receiver-node.d.ts +3 -37
- package/dist/editor/clipper/receiver-node.d.ts.map +1 -1
- package/dist/editor/clipper/receiver.d.ts +1 -7
- package/dist/editor/clipper/receiver.d.ts.map +1 -1
- package/dist/editor/clipper/types.d.ts +1 -7
- package/dist/editor/clipper/types.d.ts.map +1 -1
- package/dist/editor/embeds/attachment-view.d.ts.map +1 -1
- package/dist/editor/embeds/attachment.d.ts.map +1 -1
- package/dist/editor/embeds/audio-view.d.ts.map +1 -1
- package/dist/editor/embeds/audio.d.ts.map +1 -1
- package/dist/editor/embeds/video-view.d.ts.map +1 -1
- package/dist/editor/embeds/video.d.ts.map +1 -1
- package/dist/editor/extensions/bubble-menu.d.ts +1 -5
- package/dist/editor/extensions/bubble-menu.d.ts.map +1 -1
- package/dist/editor/extensions/code-block-view.d.ts.map +1 -1
- package/dist/editor/extensions/code-block.d.ts.map +1 -1
- package/dist/editor/extensions/image-upload.d.ts +2 -6
- package/dist/editor/extensions/image-upload.d.ts.map +1 -1
- package/dist/editor/extensions/image-view.d.ts.map +1 -1
- package/dist/editor/extensions/ime-commit-space-guard.d.ts +3 -0
- package/dist/editor/extensions/ime-commit-space-guard.d.ts.map +1 -0
- package/dist/editor/extensions/index.d.ts.map +1 -1
- package/dist/editor/extensions/obsidian-markdown.d.ts.map +1 -1
- package/dist/editor/extensions/qingwu-ui.d.ts +2 -12
- package/dist/editor/extensions/qingwu-ui.d.ts.map +1 -1
- package/dist/editor/extensions/relative-media.d.ts +4 -16
- package/dist/editor/extensions/relative-media.d.ts.map +1 -1
- package/dist/editor/extensions/search-highlight.d.ts +2 -14
- package/dist/editor/extensions/search-highlight.d.ts.map +1 -1
- package/dist/editor/extensions/slash-command.d.ts +2 -12
- package/dist/editor/extensions/slash-command.d.ts.map +1 -1
- package/dist/editor/i18n/en-US.d.ts.map +1 -1
- package/dist/editor/index.d.ts.map +1 -1
- package/dist/editor/storage/index.d.ts +6 -8
- package/dist/editor/storage/index.d.ts.map +1 -1
- package/dist/editor/storage/providers/cos.d.ts +2 -5
- package/dist/editor/storage/providers/cos.d.ts.map +1 -1
- package/dist/editor/storage/providers/oss.d.ts +1 -2
- package/dist/editor/storage/providers/oss.d.ts.map +1 -1
- package/dist/editor/storage/providers/s3.d.ts +1 -5
- package/dist/editor/storage/providers/s3.d.ts.map +1 -1
- package/dist/editor/storage/signed-fetch.d.ts +5 -15
- package/dist/editor/storage/signed-fetch.d.ts.map +1 -1
- package/dist/editor/utils/delete-confirm-dialog.d.ts +3 -5
- package/dist/editor/utils/delete-confirm-dialog.d.ts.map +1 -1
- package/dist/editor/utils/delete-confirm.d.ts +2 -5
- package/dist/editor/utils/delete-confirm.d.ts.map +1 -1
- package/dist/editor/utils/import-choice-dialog.d.ts +1 -7
- package/dist/editor/utils/import-choice-dialog.d.ts.map +1 -1
- package/dist/editor/utils/local-media.d.ts +22 -60
- package/dist/editor/utils/local-media.d.ts.map +1 -1
- package/dist/editor/utils/render-probe.d.ts +1 -4
- package/dist/editor/utils/render-probe.d.ts.map +1 -1
- package/dist/editor/utils/resolve-local-media.d.ts +14 -27
- package/dist/editor/utils/resolve-local-media.d.ts.map +1 -1
- package/dist/editor/utils/sanitize.d.ts +6 -15
- package/dist/editor/utils/sanitize.d.ts.map +1 -1
- package/dist/{export-dialog-JUHUKqo-.cjs → export-dialog-BSEeEEHv.cjs} +1 -1
- package/dist/{export-dialog-DLCACwRK.js → export-dialog-CL7ie13Z.js} +1 -1
- package/dist/index.cjs +11 -9
- package/dist/index.js +2319 -1855
- package/dist/{sanitize-BLVk_EcE.cjs → sanitize-CrbFQE46.cjs} +1 -1
- package/dist/{sanitize-OUn05c7P.js → sanitize-z8gMk0lV.js} +2 -1
- package/dist/{signed-fetch-D8Rk6R5t.cjs → signed-fetch-DiWXujJ1.cjs} +1 -1
- package/dist/{storage-B6LsdlnG.js → storage-DUcmM2Ex.js} +6 -2
- package/dist/storage-VaeLS7eM.cjs +2 -0
- package/dist/{storage-settings-dialog-BA8QlSw7.js → storage-settings-dialog-DZqqDAiO.js} +1 -1
- package/dist/{storage-settings-dialog-Dojhp-Uo.cjs → storage-settings-dialog-ZtMUoApJ.cjs} +1 -1
- package/dist/styles.css +1 -1
- package/package.json +2 -2
- package/dist/storage-raz9BRoZ.cjs +0 -2
package/dist/index.cjs
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("./sanitize-
|
|
2
|
-
`?i=`break`:e===` `||e===` `?i=`space`:ie(r)&&(i=ae(r)?`punct`:`cjk`),n.push({text:e,width:ne(e,t),type:i})}return n}function R(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 z(e,t,n,r){return{text:e.slice(t,Math.min(n,e.length)).map(e=>e.text).join(``),width:r}}function B(e,t,n=`16px system-ui`){let{maxWidth:r,lineHeight:i,maxLines:a,overflowWrap:o=`break-word`}=t,s=L(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(z(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(z(s,l.lineStart,l.lastBreakIdx+1,l.lastBreakWidth)),l.lineStart=l.lastBreakIdx+1,l.lineWidth=R(s,l.lineStart,e+1)):(c.push(z(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(z(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(z(s,l.lineStart,l.lastBreakIdx+1,l.lastBreakWidth)),l.lineStart=l.lastBreakIdx+1,l.lineWidth=R(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(z(s,l.lineStart,l.lastBreakIdx+1,l.lastBreakWidth)),l.lineStart=l.lastBreakIdx+1,l.lineWidth=R(s,l.lineStart,e+1),l.lastBreakIdx=-1):o===`break-word`?(c.push(z(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=R(s,l.lineStart,s.length);c.push(z(s,l.lineStart,s.length,e))}return{lines:c,totalHeight:c.length*i,lineCount:c.length,truncated:u&&a?c.length>=a:!1}}var V=typeof window<`u`&&window.matchMedia(`(prefers-reduced-motion: reduce)`).matches,oe=`13.5px -apple-system, BlinkMacSystemFont, "SF Pro Text", "PingFang SC", "Microsoft YaHei", system-ui, sans-serif`;function H(){if(typeof window>`u`)return 290;let e=window.innerWidth;return e<=480?Math.max(140,e-98):290}var U={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>`},W=1;function se(){return`qt${W++}${Date.now().toString(36)}`}function G(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=G(`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=G(`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=se(),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=G(`div`,`qt-toast qt-${n}${i==null?``:` qt-truncate`}${a||o?` qt-rich`:``}`);s.setAttribute(`data-qt-id`,e);let c=G(`span`,`qt-icon`);c.innerHTML=U[n],s.appendChild(c);let l=G(`div`,`qt-body`),u=G(`span`,`qt-msg`),d=B(t,{maxWidth:H(),lineHeight:1,maxLines:i},oe);if(d.lineCount<=1?ce(u,t):d.lines.forEach((e,t)=>{let n=G(`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=G(`div`,`qt-desc`);e.textContent=a,l.appendChild(e)}if(s.appendChild(l),o){let t=G(`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=G(`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(V)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 K(){return pe||=new fe,pe}var me=Object.assign((e,t)=>K().show(e,t),{info:(e,t)=>K().info(e,t),success:(e,t)=>K().success(e,t),warn:(e,t)=>K().warn(e,t),error:(e,t)=>K().error(e,t),promise:(e,t,n)=>K().promise(e,t,n),dismiss:e=>K().dismiss(e),dismissAll:()=>K().dismissAll(),configure:e=>K().configure(e)}),q=new Set,he=null;function ge(e){he=e}function J(e,t=`error`,n){let r={persist:!0,...n};if(q.size>0){for(let n of q)n(e,t,r);return}if(he){he(e,t,r);return}t===`success`?me.success(e,r):t===`info`?me.info(e,r):me.error(e,r)}function _e(e){return q.add(e),()=>{q.delete(e)}}var ve=e.c({ImageUploadDialog:()=>ye}),ye=({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]),ee=(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]),O=(0,i.useCallback)(()=>{_.trim()&&(r(_.trim()),w())},[_,r,w]),k=(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-32px)] max-w-[420px] max-h-[90vh] bg-background rounded-2xl shadow-2xl border border-default-200 overflow-hidden animate-in`,onPaste:s===`upload`?ee: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:k,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`&&O()}})]}),_&&(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:O,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 be(e,t){return`${e.trim().toLowerCase().replace(/[^\p{L}\p{N}\s-]/gu,``).replace(/\s+/g,`-`).slice(0,40)||`heading`}-${t}`}function xe(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 Se(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 Y(e,t){let n=[];for(let r of e)n.push(r),r.children.length>0&&!t.has(r.id)&&n.push(...Y(r.children,t));return n}function Ce(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 we(e){let t=e.parentElement;for(;t&&t!==document.documentElement;){let e=getComputedStyle(t).overflowY;if(e===`auto`||e===`scroll`||e===`overlay`)return t;t=t.parentElement}return null}function Te(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 Ee=({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)(null),m=(0,i.useRef)(new Map),h=(0,i.useRef)(``),g=(0,i.useCallback)(()=>{let t=e.view.dom,n=Array.from(t.querySelectorAll(`h1,h2,h3,h4,h5,h6`)),r=n.map((e,t)=>(e.id||=be(e.textContent||``,t),{id:e.id,level:Number(e.tagName.slice(1)),text:e.textContent?.trim()||`(无标题)`,el:e})),i=r.map(e=>`${e.level}:${e.text}`).join(`|`);if(i===h.current||(h.current=i,o(r),p.current?.disconnect(),m.current.clear(),!n.length))return;let a=new IntersectionObserver(e=>{for(let t of e){let e=t.target.id;t.isIntersecting?m.current.set(e,t.boundingClientRect.top):m.current.delete(e)}let t=``,n=1/0;m.current.forEach((e,r)=>{e<n&&e>=0&&(n=e,t=r)}),t&&c(t)},{root:we(e.view.dom),rootMargin:`0px 0px -72% 0px`,threshold:[0,1]});n.forEach(e=>a.observe(e)),p.current=a},[e]);(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(`|`)!==h.current&&(t&&clearTimeout(t),t=setTimeout(g,300))};e.on(`update`,n);let r=requestAnimationFrame(g);return()=>{e.off(`update`,n),t&&clearTimeout(t),cancelAnimationFrame(r),p.current?.disconnect()}},[e,g]);let _=(0,i.useCallback)(t=>{let n=t.el;if((!n||!e.view.dom.contains(n))&&(n=e.view.dom.querySelector(`[id="${CSS.escape(t.id)}"]`)),!n){let r=`h${t.level}`,i=e.view.dom.querySelectorAll(r);for(let e of i)if(e.textContent?.trim()===t.text){n=e;break}}n&&(n.scrollIntoView({behavior:`smooth`,block:`start`}),c(t.id))},[e]),v=(0,i.useMemo)(()=>xe(r),[r]),y=(0,i.useMemo)(()=>Se(v),[v]),b=d.trim().length>0,x=(0,i.useMemo)(()=>b?Ce(v,d.trim()):v,[v,b,d]),S=(0,i.useMemo)(()=>Y(x,b?new Set:l),[x,l,b]),C=(0,i.useCallback)(e=>{u(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},[]),w=(0,i.useCallback)(()=>{u(new Set(y))},[y]),T=(0,i.useCallback)(()=>{u(new Set)},[]);return r.length?(0,a.jsxs)(`nav`,{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:w,title:`全部折叠`,"aria-label":`全部折叠`,disabled:b,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:T,title:`全部展开`,"aria-label":`全部展开`,disabled:b,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`})})})]}),S.length===0?(0,a.jsx)(`div`,{className:`toc-search__empty`,children:b?`未找到"${d.trim()}"相关标题`:`文档暂无标题`}):(0,a.jsx)(`ul`,{className:`toc-list`,children:S.map(e=>{let t=y.has(e.id),n=l.has(e.id);return(0,a.jsxs)(`li`,{className:`toc-item ${s===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(),C(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:()=>_(e),title:e.text,children:(0,a.jsx)(`span`,{className:`toc-text`,children:b?Te(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 De(e,t){return{continue:`你是一个写作助手。请从下文尾部自然流畅地续写内容,保持风格一致。只输出续写的内容,不要加任何前缀说明。`,improve:`你是一个文字润色专家。请优化以下文本的表达,提升文采和流畅度,保持原意不变。只输出润色后的文本。`,shorter:`你是一个精简专家。请将以下文本精简,保留核心信息,删除冗余。只输出精简后的文本。`,longer:`你是一个内容扩写专家。请丰富以下文本的细节和层次,增加深度。只输出扩写后的文本。`,fix:`你是一个校对专家。请修正以下文本中的语法错误、错别字和标点问题。只输出修正后的文本。`,translate:`你是一个翻译专家。请将以下文本翻译为英文。只输出翻译后的文本。`,zap:t||`你是一个全能的 AI 写作助手。请根据用户的指令处理文本。`}[e]}var Oe=null;async function X(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:De(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:De(e.mode,e.instruction),prompt:e.context,temperature:.7,maxOutputTokens:2048})).text}}}function ke(e){Oe=e}function Ae(){if(!Oe)throw Error(`未配置 AI 服务。请调用 createAILanguageModelProvider() 创建并通过 setAIProvider() 注册。`);return Oe}function je(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(De(e.mode,e.instruction),e.context)},async generate(e){let t=De(e.mode,e.instruction),n=``;for await(let r of a(t,e.context))n+=r;return n}}}function Me(e){return je({apiKey:e.apiKey,baseURL:e.baseURL||`https://api.deepseek.com/v1`,model:e.model||`deepseek-v4-flash`,headers:e.headers})}function Ne(e){return je({apiKey:e.apiKey,baseURL:e.baseURL||`https://api.openai.com/v1`,model:e.model||`gpt-5.6-luna`,headers:e.headers})}function Pe(e){return je({apiKey:e.apiKey,baseURL:e.baseURL||`https://dashscope.aliyuncs.com/compatible-mode/v1`,model:e.model||`qwen3.7-plus`,headers:e.headers})}var Fe={keyword:``,caseSensitive:!1,wholeWord:!1,matches:[],currentIndex:-1},Z=new f.PluginKey(`search-highlight`);function Ie(e){return e.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`)}function Le(e,t){let{keyword:n,caseSensitive:r,wholeWord:i}=t;if(!n)return[];let a=r?`g`:`gi`,o=i?`\\b${Ie(n)}\\b`:Ie(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 Re(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 ze(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 Be=d.Extension.create({name:`searchHighlight`,addProseMirrorPlugins(){return[new f.Plugin({key:Z,state:{init:()=>Fe,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=Le(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?Re(e.doc,t):p.DecorationSet.empty}}})]},addCommands(){return{setSearch:(e,t={})=>({state:n,dispatch:r,view:i})=>{let a=Z.getState(n)||Fe,o={keyword:e,caseSensitive:t.caseSensitive??a.caseSensitive,wholeWord:t.wholeWord??a.wholeWord,matches:[],currentIndex:-1};return o.matches=Le(n.doc,o),o.currentIndex=o.matches.length>0?0:-1,r&&(r(n.tr.setMeta(Z,o)),i&&ze(i,o)),!0},nextMatch:()=>({state:e,dispatch:t,view:n})=>{let r=Z.getState(e)||Fe;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&&ze(n,{...r,currentIndex:i})),!0},prevMatch:()=>({state:e,dispatch:t,view:n})=>{let r=Z.getState(e)||Fe;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&&ze(n,{...r,currentIndex:i})),!0},clearSearch:()=>({state:e,dispatch:t})=>(t&&t(e.tr.setMeta(Z,Fe)),!0)}}});function Ve(e){let t=e.state;return Z.getState(t)||Fe}var He=({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 Ve(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 Ue=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`})]}),We=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`})]}),Ge=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`})]}),Ke=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`})]}),qe=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`})]}),Je=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`})]}),Ye=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`})]}),Xe=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`})]}),Ze=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`})]}),Qe=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`})]}),$e=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`})]}),et=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`})]}),tt=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 nt(e){if(e){if(e.startsWith(`blob:`)){URL.revokeObjectURL(e);return}try{await n.n().remove(e)}catch(e){console.warn(`删除存储资源失败:`,e)}}}var rt=3e4,it=new Set([`image`,`attachmentEmbed`,`audioEmbed`,`videoEmbed`]),at=new WeakMap;function ot(e){let t=new Set;return e.state.doc.descendants(e=>{if(it.has(e.type.name)){let n=e.attrs.src;n&&t.add(n)}return!0}),t}function st(e){let t=at.get(e);return t||(t={timers:new Map,onTransaction:()=>{},listening:!1},at.set(e,t)),t}function ct(e,t){let n=[...new Set(t.filter(Boolean))];if(n.length===0)return;let r=st(e);r.listening||=(r.onTransaction=()=>{if(r.timers.size===0)return;let t=ot(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(()=>{ot(e).has(t)||nt(t),r.timers.delete(t)},rt);r.timers.set(t,n)}}function lt(e){let t=at.get(e);if(t){if(t.listening&&=(e.off(`transaction`,t.onTransaction),!1),t.timers.size>0){let n=ot(e);for(let[e,r]of t.timers)clearTimeout(r),n.has(e)||nt(e);t.timers.clear()}at.delete(e)}}var ut=[{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:`⚡`}],dt=new Set([`image`,`attachmentEmbed`,`audioEmbed`,`videoEmbed`]),ft={image:`editor.ai.nodeImage`,attachmentEmbed:`editor.ai.nodeAttachment`,videoEmbed:`editor.ai.nodeVideo`,audioEmbed:`editor.ai.nodeAudio`};function pt(e,t){return e.storage.qingwuUI?.parseMd?.(e.schema,t)||null}function mt(e,t,n){let r=[];return e.state.doc.nodesBetween(t,n,e=>{if(dt.has(e.type.name)){let t=e.attrs.src;t&&r.push({type:e.type.name,src:t})}return!0}),r}function ht(e){let t=new Set;return e.state.doc.descendants(e=>{if(dt.has(e.type.name)){let n=e.attrs.src;n&&t.add(n)}return!0}),t}function gt(e,t){let n=pt(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 _t(e,t,n,r){let i=pt(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 vt({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.useCallback)(async e=>{if(o(e),m(null),e!==`zap`){await b(e);return}setTimeout(()=>v.current?.focus(),100)},[t]),b=(0,i.useCallback)(async n=>{let r=t.state.selection;_.current={from:r.from,to:r.to,empty:r.empty},f(!0),u(``),m(null);try{let e=Ae(),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]),x=(0,i.useCallback)((e,n,r)=>{let i=new Set(mt(t,r.from,r.to).map(e=>e.src));e===`replaceAll`?gt(t,n):_t(t,n,`replace`,_.current);let a=ht(t);ct(t,[...i].filter(e=>!a.has(e)))},[t]),S=(0,i.useCallback)(e=>{if(e===`below`){_t(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=mt(t,i.from,i.to);if(a.length>0){g({position:e,willRemove:a});return}x(e,l,i),n()},[t,l,x,n]),C=(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};x(e,l,r),g(null),n()},[h,t,l,x,n]),w=(0,i.useCallback)(()=>{u(``),o(null),m(null)},[]),T={};for(let e of h?.willRemove??[])T[e.type]=(T[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)($e,{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)(tt,{})})]}),(0,a.jsx)(`div`,{className:`grid grid-cols-[repeat(auto-fit,minmax(64px,1fr))] gap-1.5 p-2 shrink-0`,children:ut.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:()=>y(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()&&b(`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:()=>b(`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`,{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:()=>S(`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:()=>S(`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:()=>S(`below`),children:e.o(`editor.ai.insert`)}),(0,a.jsx)(`button`,{type:`button`,className:`px-3 py-1.5 text-xs text-danger`,onClick:w,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(T).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(T).map(([t,n])=>(0,a.jsxs)(`li`,{className:`text-sm text-default-700`,children:[e.o(ft[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:C,children:e.o(`editor.ai.confirmReplace`)})]})]})]})]})}var yt=new Set([`attachmentEmbed`,`videoEmbed`,`audioEmbed`,`image`]);function bt(e){let t=0;return e.descendants(e=>{yt.has(e.type.name)&&(t+=Number(e.attrs?.size)||0)}),t}function xt(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 St(e){return(e?.storage)?.qingwuUI?.limits}function Ct(e,t,n){let{maxAttachmentSize:r,maxTotalAttachmentSize:i}=n;if(r&&t.size>r)return`单文件大小不能超过 ${xt(r)}(当前 ${xt(t.size)})`;if(i){let n=bt(e)+t.size;if(n>i)return`附件总大小不能超过 ${xt(i)}(当前合计 ${xt(n)})`}return null}var wt=!1,Tt=null,Et=5e3;function Dt(){return wt}function $(e){wt=e,Tt&&=(clearTimeout(Tt),null),e&&(Tt=setTimeout(()=>{wt=!1,Tt=null},Et))}var Ot=null;function kt(e){Ot=e}function At(){return Ot}var jt=300;function Mt({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=At();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<jt&&await new Promise(e=>setTimeout(e,jt-t)),d(!1),c()}},disabled:l,children:r})]})]})}),document.body)}function Nt(e){return/^(\.\.?\/|[a-zA-Z]:\\|file:\/\/)/.test(e)?!0:!(/^[a-z]+:\/\//i.test(e)||e.startsWith(`/`)||e.startsWith(`data:`)||e.startsWith(`blob:`))}function Pt({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),[ee,O]=(0,i.useState)(g),k=r?.isEditable??!0,A=(0,i.useCallback)(()=>{l||(D.current=window.scrollY,s(!0))},[l]),j=(0,i.useCallback)(()=>{s(!1),requestAnimationFrame(()=>window.scrollTo(0,D.current))},[]),M=(0,i.useCallback)(()=>{let e=b.current;e&&(D.current=window.scrollY,e.requestFullscreen?e.requestFullscreen():e.webkitRequestFullscreen&&e.webkitRequestFullscreen())},[]),N=(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),O(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-D8Rk6R5t.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,O(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 P=l||Nt(g);return(0,a.jsxs)(c.NodeViewWrapper,{as:`div`,className:`image-node-view group/img`,contentEditable:!1,children:[P?(0,a.jsxs)(`div`,{className:`image-placeholder`,children:[k&&(0,a.jsx)(`button`,{type:`button`,className:`img-ctrl-btn img-ctrl-btn--del image-placeholder-del`,onClick:()=>{Dt()||($(!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:Nt(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:ee,alt:_,width:v||void 0,height:y||void 0,onClick:A,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:A,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:M,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`})})}),k&&(0,a.jsx)(`button`,{type:`button`,className:`img-ctrl-btn img-ctrl-btn--del`,onClick:()=>{Dt()||($(!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&&!P&&(0,a.jsxs)(`div`,{className:`image-lightbox`,onClick:j,children:[(0,a.jsxs)(`div`,{className:`image-lightbox-bar`,children:[(0,a.jsx)(`button`,{type:`button`,className:`image-lightbox-bar-btn`,onClick:N,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:j,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:ee,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)(Mt,{open:m,title:`确认删除图片`,message:P?`该图片无法在当前环境加载,仅从编辑器中移除该图片节点,不影响存储文件。`:`此操作将同时删除对象存储中的文件,不可撤销。`,onCancel:()=>{$(!1),h(!1)},onConfirm:async()=>{if(!P)try{await nt(g)}catch{}$(!1),await new Promise(e=>setTimeout(e,300)),n()}})]})}var Ft=(0,i.lazy)(()=>import(`@file-viewer/react`)),It=new Set,Lt={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}},Rt={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`},zt={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 Bt(e){return e?e<1024?`${e} B`:e<1048576?`${(e/1024).toFixed(1)} KB`:`${(e/1048576).toFixed(1)} MB`:``}function Vt(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 Ht(e){return e.split(`.`).pop()?.toLowerCase()||``}function Ut(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 Wt(e){return!!e&&!e.startsWith(`file:`)}function Gt(e){return btoa(encodeURIComponent(e)).replace(/\+/g,`-`).replace(/\//g,`_`).replace(/=+$/,``)}async function Kt(e,t){try{let n=Gt(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 qt(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 Jt({node:n,deleteNode:r,selected:o,editor:s}){let l=s?.isEditable??!0,u=n.attrs.src||``,[d,f]=(0,i.useState)(()=>It.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),ee=(0,i.useRef)(0),O=(0,i.useRef)(!1),k=(0,i.useRef)(null),A=(0,i.useRef)(0),[j,M]=(0,i.useState)(!1),N=(0,i.useRef)(null),[P,te]=(0,i.useState)(0),[F,I]=(0,i.useState)(`none`),[ne,re]=(0,i.useState)(void 0),[ie,ae]=(0,i.useState)(!1),L=n.attrs.src||``,R=n.attrs.name||L&&L.split(`/`).pop()?.split(`?`)[0]||(L?`attachment`:e.o(`editor.attachment.lost`)),z=n.attrs.size||0,B=Ht(R),V=!L;(0,i.useEffect)(()=>{if(!d){re(void 0),ae(!1);return}let e=Rt[B];if(!e){re(void 0),ae(!1);return}let t=!0;return re(void 0),ae(!1),zt[e]().then(e=>{t&&re(e)}).catch(n=>{console.error(`[attachment] renderer "${e}" load failed:`,n),t&&ae(!0)}),()=>{t=!1}},[d,B]);let oe=(0,i.useMemo)(()=>({...Lt,renderers:ne?[ne]:[],rendererMode:`replace`}),[ne]),H=(0,i.useCallback)(e=>{f(t=>{let n=typeof e==`function`?e(t):e;return L&&(n?It.add(L):It.delete(L)),n})},[L]);(0,i.useEffect)(()=>{f(L?It.has(L):!1)},[L]);let U=(0,i.useCallback)(()=>{O.current=!0,H(!0),window.setTimeout(()=>{window.scrollTo(0,ee.current),k.current&&(k.current.scrollTop=A.current),O.current&&H(!0),O.current=!1},0)},[H]),W=(0,i.useCallback)(async()=>{F===`web`?(I(`none`),document.body.style.overflow=``,U()):(F===`native`&&document.fullscreenElement&&await document.exitFullscreen(),ee.current=window.scrollY,A.current=k.current?.scrollTop??0,document.body.style.overflow=`hidden`,I(`web`))},[F]),se=(0,i.useCallback)(async()=>{let e=E.current;e&&(F===`native`?await document.exitFullscreen():(F===`web`&&(I(`none`),document.body.style.overflow=``),ee.current=window.scrollY,A.current=k.current?.scrollTop??0,await e.requestFullscreen(),I(`native`)))},[F,U]),G=(0,i.useCallback)(()=>{F===`none`&&(O.current||H(e=>!e))},[F]);(0,i.useEffect)(()=>{let e=()=>{document.fullscreenElement||(F===`native`&&I(`none`),U())},t=e=>{e.key===`Escape`&&F===`web`&&(I(`none`),document.body.style.overflow=``,U())};return document.addEventListener(`fullscreenchange`,e),window.addEventListener(`keydown`,t),()=>{document.removeEventListener(`fullscreenchange`,e),window.removeEventListener(`keydown`,t)}},[F,U]),(0,i.useEffect)(()=>{let e=e=>{if(!(e.key!==`Backspace`&&e.key!==`Delete`)&&l&&o&&!Dt()){if(e.preventDefault(),e.stopPropagation(),s){let{from:e,to:t}=s.state.selection;N.current={from:e,to:t}}window.getSelection()?.removeAllRanges(),$(!0),M(!0)}};return window.addEventListener(`keydown`,e,!0),()=>window.removeEventListener(`keydown`,e,!0)},[o,s,l]),(0,i.useEffect)(()=>{if(!d||!Wt(L)){m(null),b(null),D.current=null;return}if(D.current===L)return;let e=new AbortController,n=!0;return v(!0),b(null),(async()=>{let r=L.includes(`?X-Amz-`),i=null,a=null;if(!i&&!r&&(i=await Kt(L,e.signal)),!i&&!r)try{let n=await t.n(L);n&&(i=await Kt(n,e.signal)||await qt(n,void 0,e.signal))}catch(e){console.warn(`[attachment] signPreviewUrl failed:`,e)}if(!i&&!r)try{let n=await t.r(L);if(n){let t={"X-Requested-With":`XMLHttpRequest`};n.forEach((e,n)=>{t[n]=e});try{i=await qt(L,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 qt(L,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=L;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===L){v(!1);return}b(e instanceof Error?e.message:`附件读取失败,请检查对象存储 CORS 和公开访问权限`)}}),()=>{n=!1,e.abort()}},[d,L]),(0,i.useEffect)(()=>()=>{h&&URL.revokeObjectURL(h),m(null)},[]),(0,i.useEffect)(()=>()=>{h&&URL.revokeObjectURL(h),g(null),m(null),D.current=null},[L]),(0,i.useEffect)(()=>{if(C!==`success`&&C!==`error`)return;let e=window.setTimeout(()=>w(null),2400);return()=>window.clearTimeout(e)},[C]);let ce=(0,i.useCallback)(async()=>{S(!0),w(`loading`);try{if(h){let e=document.createElement(`a`);e.href=h,e.download=R,document.body.appendChild(e),e.click(),document.body.removeChild(e),w(`success`);return}let e=L.includes(`?X-Amz-`),n=null;if(!e)try{let e=await t.n(L);e&&(n=await fetch(e,{headers:{"X-Requested-With":`XMLHttpRequest`}}),n.ok||(n=null))}catch{}if(!n&&!e)try{let e=await t.r(L);e&&(n=await fetch(L,{headers:(()=>{let t=new Headers(e);return t.set(`X-Requested-With`,`XMLHttpRequest`),t})()}),n.ok||(n=null))}catch{}if(n||=await fetch(L,{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=R,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)}},[L,R,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:V?(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`})]}):Vt(R)}),(0,a.jsxs)(`div`,{className:`att-meta`,children:[(0,a.jsx)(`span`,{className:`att-name`,children:R}),z>0&&(0,a.jsx)(`span`,{className:`att-size`,children:Bt(z)})]})]}),(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:[L&&Ut(R)&&(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:ce,disabled:x||V,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||Dt()||($(!0),M(!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 ${F===`web`?`is-web-fs`:``}`,style:{position:`relative`,height:500,overflow:`hidden`,background:`#fff`},children:[(0,a.jsx)(`div`,{ref:k,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||ie)&&!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||L?ne?(0,a.jsx)(Ft,{buffer:p||void 0,url:h||L,name:R,filename:R,type:B,size:z||p?.byteLength||0,options:oe},`${L}-${P}`):(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:F===`web`?`退出网页全屏`:`网页全屏`,"aria-label":F===`web`?`退出网页全屏`:`网页全屏`,style:{width:28,height:28,borderRadius:6,border:`none`,background:F===`web`?`#e4e4e7`:`transparent`,cursor:`pointer`,display:`flex`,alignItems:`center`,justifyContent:`center`,color:`#52525b`,transition:`background 0.12s`},onMouseEnter:e=>{F!==`web`&&(e.currentTarget.style.background=`#f4f4f5`)},onMouseLeave:e=>{F!==`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:F===`native`?`退出全屏`:`全屏`,"aria-label":F===`native`?`退出全屏`:`全屏`,style:{width:28,height:28,borderRadius:6,border:`none`,background:F===`native`?`#e4e4e7`:`transparent`,cursor:`pointer`,display:`flex`,alignItems:`center`,justifyContent:`center`,color:`#52525b`,transition:`background 0.12s`},onMouseEnter:e=>{F!==`native`&&(e.currentTarget.style.background=`#f4f4f5`)},onMouseLeave:e=>{F!==`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)(Mt,{open:j,title:`确认删除附件`,message:V?`此操作将删除该附件节点,不可撤销。`:`此操作将同时删除对象存储中的文件(${R}),不可撤销。`,onCancel:()=>{$(!1),M(!1)},onConfirm:async()=>{try{if(s){let e=N.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(nt(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 nt(L),$(!1),await new Promise(e=>setTimeout(e,300)),r()}catch{$(!1)}}})]})}var Yt=d.Node.create({name:`attachmentEmbed`,group:`block`,atom:!0,inline:!1,addNodeView(){return(0,c.ReactNodeViewRenderer)(Jt)},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 Xt({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:()=>{Dt()||($(!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)(Mt,{open:l,title:`确认删除音频`,message:`此操作将同时删除对象存储中的文件(${s}),不可撤销。`,onCancel:()=>{$(!1),u(!1)},onConfirm:async()=>{try{await nt(o)}catch{}$(!1),await new Promise(e=>setTimeout(e,300)),n()}})]})}function Zt(e){return/\.(mp3|wav|ogg|flac|aac|m4a|wma|opus)(\?|$)/i.test(e)||/\/.*\.(mp3|wav|ogg|flac)/i.test(e)}var Qt=d.Node.create({name:`audioEmbed`,group:`block`,atom:!0,inline:!1,addNodeView(){return(0,c.ReactNodeViewRenderer)(Xt)},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(` `)||!Zt(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 $t(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 en(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 tn({node:e,deleteNode:t,editor:n}){let r=e.attrs.src||``,o=e.attrs.source||`unknown`,s=o===`unknown`?$t(r):o,[l,u]=(0,i.useState)(!1),[d,f]=(0,i.useState)(!1),p=n?.isEditable??!0,m=(0,a.jsx)(Mt,{open:l,title:`确认删除视频`,message:`此操作将同时删除对象存储中的文件,不可撤销。`,onCancel:()=>{$(!1),u(!1)},onConfirm:async()=>{try{await nt(r)}catch{}$(!1),await new Promise(e=>setTimeout(e,300)),t()}}),[h,g]=(0,i.useState)(``),_=(0,i.useRef)(null),v=(0,i.useRef)(null),y=(0,i.useRef)(null),b=(0,i.useRef)(null),x=(0,i.useRef)(null),S=(0,i.useRef)(0),C=(0,i.useCallback)(()=>{let e=y.current;e&&(e.style.position=``,e.style.inset=``,e.style.zIndex=``,e.style.borderRadius=``,document.body.style.overflow=``)},[]),w=(0,i.useCallback)(()=>{document.fullscreenElement&&document.exitFullscreen?.(),C()},[C]),T=(0,i.useCallback)(()=>{let e=y.current;e&&(e.style.position===`fixed`?C():(e.style.position=`fixed`,e.style.inset=`0`,e.style.zIndex=`99999`,e.style.borderRadius=`0`,document.body.style.overflow=`hidden`))},[C]),E=(0,i.useCallback)(()=>{S.current=window.scrollY,b.current?.requestFullscreen?.()},[]),D=(0,i.useCallback)(()=>{let e=v.current?.closest(`.video-embed--direct`)||v.current;e&&(S.current=window.scrollY,e.requestFullscreen?.())},[]);if((0,i.useEffect)(()=>{let e=()=>{document.fullscreenElement||requestAnimationFrame(()=>window.scrollTo(0,S.current))};return document.addEventListener(`fullscreenchange`,e),()=>document.removeEventListener(`fullscreenchange`,e)},[]),(0,i.useEffect)(()=>{if(s!==`direct`||!r){g(``);return}let e=!1;return f(!0),(async()=>{try{if(r.includes(`?X-Amz-`)||r.startsWith(`blob:`)||r.startsWith(`data:`)){g(r);return}let{signPreviewUrlHeaders:t}=await Promise.resolve().then(()=>require("./signed-fetch-D8Rk6R5t.cjs")).then(e=>e.i),n=await t(r);if(!n){g(r);return}let i=await fetch(r,{headers:n});if(!i.ok){g(r);return}let a=URL.createObjectURL(await i.blob());if(e){URL.revokeObjectURL(a);return}x.current&&URL.revokeObjectURL(x.current),x.current=a,g(a)}catch{e||g(r)}})(),()=>{e=!0,x.current&&=(URL.revokeObjectURL(x.current),null)}},[s,r]),(0,i.useEffect)(()=>{if(s!==`direct`||!h)return;let e=!1;return f(!0),(async()=>{let t=v.current;if(t)try{let[{default:n}]=await Promise.all([import(`xgplayer`)]);if(e||!v.current)return;_.current?.destroy(),t.replaceChildren(),_.current=new n({el:t,url:h,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=_.current;let r=()=>{e||f(!1)};try{_.current?.once?.(`loadeddata`,r),_.current?.once?.(`canplay`,r)}catch{}window.setTimeout(r,2500)}catch{}})(),()=>{e=!0,f(!1),_.current?.destroy(),_.current=null,v.current&&(v.current.__xgplayer=null)}},[s,h]),s===`bilibili`){let e=en(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:y,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:w,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:T,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:E,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`})})}),p&&(0,a.jsx)(`button`,{type:`button`,className:`video-fs-btn video-fs-btn--del`,title:`删除`,onClick:()=>{Dt()||($(!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:b,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`})})]}),m]})}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:[p&&(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:()=>{Dt()||($(!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: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:`M15 3h6v6M9 21H3v-6M21 3l-7 7M3 21l7-7`})})})]}),(0,a.jsxs)(`div`,{style:{position:`relative`,width:`100%`,background:`#000`},children:[(0,a.jsx)(`div`,{ref:v,style:{width:`100%`,minHeight:260}}),d&&(0,a.jsx)(`div`,{className:`xg-loading-overlay`,children:(0,a.jsx)(`span`,{className:`xg-loading-spinner`})})]}),m]})}function nn(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 rn(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 an(e){let t=e.match(/explore\/([a-zA-Z0-9]+)/);return t?t[1]:e}var on=d.Node.create({name:`videoEmbed`,group:`block`,atom:!0,inline:!1,addNodeView(){return(0,c.ReactNodeViewRenderer)(tn)},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=nn(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:nn(n)}}},{tag:`div[data-bilibili]`},{tag:`div[data-xiaohongshu]`}]},renderHTML({HTMLAttributes:e}){let t=e.src||``,n=nn(t);if(n===`bilibili`){let e=rn(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 an(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=nn(e.src);return t().insertContent({type:this.name,attrs:{...e,source:n}}).focus().run()}}}}),sn=null;async function cn(e){sn||=await import(`beautiful-mermaid`);let t=sn.renderMermaidSVG;return t(e)}var ln=[{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`}],un={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`},dn={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 fn(e){return e instanceof Element&&!!e.closest(`.cb-code-area`)}function pn({node:t,updateAttributes:n,editor:r,getPos:o,deleteNode:s,selected:l}){let u=r?.isEditable??!0,d=!u,[f,p]=(0,i.useState)(!1),[m,h]=(0,i.useState)(!1),[g,_]=(0,i.useState)(!1),[v,y]=(0,i.useState)(``),[b,x]=(0,i.useState)(!1),[S,C]=(0,i.useState)(null),[w,T]=(0,i.useState)(null),[E,D]=(0,i.useState)(!1),[ee,O]=(0,i.useState)([]),k=(0,i.useRef)(null),A=(0,i.useRef)(null),j=(0,i.useRef)(null),M=(0,i.useRef)(null),N=(0,i.useRef)(null),P=t.attrs.language||``,te=ln.find(e=>e.value===(dn[P]??P)),F=P===`mermaid`,I=(0,i.useCallback)(e=>{fn(e.target)||e.stopPropagation()},[]),ne=(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]),re=(0,i.useCallback)(()=>{u&&(Dt()||(N.current=ne(),window.getSelection()?.removeAllRanges(),$(!0),x(!0)))},[ne,u]),ie=(0,i.useMemo)(()=>t.textContent?t.textContent.split(`
|
|
4
|
-
`):[``],[t.textContent]),ae=ie.length,L=(0,i.useMemo)(()=>Array.from({length:ae},(e,t)=>t+1),[ae]),R=(0,i.useMemo)(()=>{let e=v.trim().toLowerCase();return e?ln.filter(t=>t.label.toLowerCase().includes(e)||t.value.toLowerCase().includes(e)):ln},[v]);(0,i.useEffect)(()=>{g&&(y(``),setTimeout(()=>A.current?.focus(),50))},[g]),(0,i.useEffect)(()=>{if(!g)return;let e=e=>{k.current&&!k.current.contains(e.target)&&_(!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`)&&u&&l&&!Dt()){if(e.preventDefault(),e.stopPropagation(),r){let{from:e,to:t}=r.state.selection;N.current={from:e,to:t}}window.getSelection()?.removeAllRanges(),$(!0),x(!0)}};return window.addEventListener(`keydown`,e,!0),()=>window.removeEventListener(`keydown`,e,!0)},[l,r,u]);let z=(0,i.useCallback)(e=>{O(t=>t.length===e.length&&t.every((t,n)=>t===e[n])?t:e)},[]),B=(0,i.useCallback)(()=>{let e=j.current,t=M.current;if(!e||!t)return;t.style.width=`${e.clientWidth}px`;let n=t.children,r=Array(n.length);for(let e=0;e<n.length;e++)r[e]=n[e].offsetHeight;z(r)},[z]);(0,i.useLayoutEffect)(()=>{B()},[B,ie]),(0,i.useEffect)(()=>{let e=j.current;if(!e)return;let t=new ResizeObserver(()=>B());return t.observe(e),window.addEventListener(`resize`,B),document.fonts?.ready?.then(()=>B()),()=>{t.disconnect(),window.removeEventListener(`resize`,B)}},[B]);let V=(0,i.useCallback)(e=>{n({language:e||null}),_(!1)},[n]),oe=(0,i.useCallback)(()=>{if(u){if(r&&o){let e=o();r.chain().focus().setNodeSelection(e).run()}_(!1),(r?.storage?.qingwuUI)?.openAI?.()}},[r,o,u]),H=(0,i.useCallback)(()=>{navigator.clipboard.writeText(t.textContent),p(!0),setTimeout(()=>p(!1),1500)},[t.textContent]),U=(0,i.useCallback)(()=>{let e=un[P]||`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,P]),W=(0,i.useCallback)(async()=>{if(S||E){C(null),T(null),D(!1);return}D(!0),T(null),C(null);try{let n=(t.textContent||``).trim();if(!n){T(`代码块内容为空`);return}let r=e.r(await cn(n));C(r)}catch(e){T(e instanceof Error?e.message:`Mermaid 渲染失败`)}finally{D(!1)}},[t.textContent,S,E]),se=(0,a.jsxs)(a.Fragment,{children:[te?te.deviconClass?(0,a.jsx)(`i`,{className:`${te.deviconClass} colored cb-lang-icon`,style:{color:te.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:te?.label||`自动`})]});return(0,a.jsxs)(c.NodeViewWrapper,{as:`div`,className:`code-block-node-view group/cb`,onMouseDown:I,onTouchStart:I,children:[(0,a.jsxs)(`div`,{className:`cb-header`,contentEditable:!1,children:[(0,a.jsxs)(`div`,{className:`cb-lang-wrap`,ref:k,contentEditable:!1,children:[d?(0,a.jsx)(`span`,{className:`cb-lang-trigger cb-lang-trigger--static`,children:se}):(0,a.jsxs)(`button`,{type:`button`,className:`cb-lang-trigger`,onClick:()=>_(!g),children:[se,(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`})})]}),u&&g&&(0,a.jsxs)(`div`,{className:`cb-lang-dropdown`,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:A,className:`cb-lang-search`,type:`text`,placeholder:`搜索语言...`,value:v,onChange:e=>y(e.target.value),onKeyDown:e=>e.stopPropagation()})]}),(0,a.jsxs)(`div`,{className:`cb-lang-list`,children:[(0,a.jsxs)(`button`,{type:`button`,className:`cb-lang-option${P?``:` cb-lang-option--active`}`,onClick:()=>V(``),children:[(0,a.jsx)(`span`,{className:`cb-lang-icon cb-lang-icon--auto`,children:`?`}),(0,a.jsx)(`span`,{children:`自动检测`})]}),R.map(e=>(0,a.jsxs)(`button`,{type:`button`,className:`cb-lang-option${P===e.value?` cb-lang-option--active`:``}`,onClick:()=>V(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)),R.length===0&&(0,a.jsx)(`div`,{className:`cb-lang-empty`,children:`无匹配语言`})]})]})]}),(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:H,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:U,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`})})}),u&&(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(`button`,{type:`button`,className:`cb-btn cb-btn--ai`,onClick:oe,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:re,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`})})})]}),F&&(0,a.jsx)(`button`,{type:`button`,className:`cb-btn cb-btn--diagram`,onClick:W,contentEditable:!1,title:S||E?`取消渲染`:`渲染图表`,disabled:E,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`})})})]})]}),(0,a.jsxs)(`div`,{className:`cb-code-area${m?` cb-code-area--collapsed`:``}`,children:[(0,a.jsx)(`div`,{className:`cb-line-numbers`,contentEditable:!1,"aria-hidden":`true`,children:L.map((e,t)=>(0,a.jsx)(`span`,{className:`cb-line-num`,style:ee[t]?{height:ee[t]}:void 0,children:e},e))}),(0,a.jsx)(`pre`,{className:`cb-code-pre`,ref:j,children:(0,a.jsx)(c.NodeViewContent,{as:`code`})}),(0,a.jsx)(`div`,{ref:M,className:`cb-code-mirror`,contentEditable:!1,"aria-hidden":`true`,children:ie.map((e,t)=>(0,a.jsx)(`span`,{className:`cb-mirror-line`,children:e.length?e:`\xA0`},t))})]}),(S||w||E)&&(0,a.jsxs)(`div`,{className:`cb-diagram-output`,contentEditable:!1,children:[E&&(0,a.jsx)(`div`,{className:`cb-diagram-loading`,children:`渲染图表中…`}),w&&(0,a.jsxs)(`div`,{className:`cb-diagram-error`,children:[(0,a.jsx)(`span`,{className:`cb-diagram-error-icon`,children:`!`}),w]}),S&&(0,a.jsx)(`div`,{className:`cb-diagram-svg`,dangerouslySetInnerHTML:{__html:S}})]}),(0,a.jsx)(Mt,{open:b,title:`确认删除代码块`,message:`此操作不可撤销。`,onCancel:()=>{$(!1),x(!1)},onConfirm:async()=>{if(await new Promise(e=>setTimeout(e,300)),$(!1),r){let e=N.current??ne();e?r.chain().focus().setTextSelection(e).deleteSelection().run():s()}else s()}})]})}var mn=[{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`}],hn=(0,M.createLowlight)(M.common);hn.register({dockerfile:j.default}),hn.registerAlias(`xml`,[`vue`,`html`]),hn.registerAlias(`javascript`,[`react`,`jsx`]),hn.registerAlias(`typescript`,[`tsx`]);var gn=A.CodeBlockLowlight.extend({addNodeView(){return(0,c.ReactNodeViewRenderer)(pn)}}).configure({lowlight:hn});function _n(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 vn=/\.(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,yn=/^(?:mailto:|tel:|javascript:|about:|data:|blob:)/i;function bn(e){if(!e)return!1;let t=e.trim();return!(!t||/^(?:https?:)?\/\//i.test(t)||yn.test(t)||t.startsWith(`#`))}function xn(e){return vn.test(e)}function Sn(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 Cn(e){let t=Sn(e),n=t.split(`/`).filter(Boolean);return(n[n.length-1]||t).toLowerCase()}function wn(){return typeof window>`u`||window.isSecureContext===!1?!1:typeof window.showDirectoryPicker==`function`}async function Tn(){if(!wn())return null;try{return await window.showDirectoryPicker.call(window,{mode:`read`})??null}catch{return null}}function En(){return typeof window>`u`||window.isSecureContext===!1?!1:typeof window.showOpenFilePicker==`function`}async function Dn(){if(!En())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 On(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 kn(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 An(e,t){let n=Sn(t).split(`/`).filter(Boolean);if(n.length===0)return{file:null};let r;for(let t=0;t<n.length;t++){let i=await On(e,n.slice(t));if(i.file)return i;i.readError&&(r=i.readError)}let i=await kn(e,n[n.length-1]);return i.file||i.readError?i:{file:null,readError:r}}var jn={image:`image`,videoEmbed:`video`,audioEmbed:`audio`,attachmentEmbed:`attachment`};function Mn(e){let t=new Set,n=[];return e.descendants(e=>{let r=jn[e.type?.name];if(r){let i=e.attrs?.src,a=`node:${i}`;typeof i==`string`&&bn(i)&&!t.has(a)&&(t.add(a),n.push({src:i,normalized:Sn(i),basename:Cn(i),kind:r,isLink:!1}));return}if(e.isText&&e.marks)for(let r of e.marks){if(r.type.name!==`link`)continue;let e=r.attrs?.href,i=`link:${e}`;typeof e==`string`&&bn(e)&&xn(e)&&!t.has(i)&&(t.add(i),n.push({src:e,normalized:Sn(e),basename:Cn(e),kind:`attachment`,isLink:!0}))}}),n}function Nn(e,t){let n=t?`${e}\n${t}`:e;if(!n)return!1;let r=[];for(let e of n.matchAll(/!?\[[^\]]*\]\(([^)\s]+)(?:\s+"[^"]*")?\)/g))r.push(e[1]);for(let e of n.matchAll(/!?\[\[([^\]|]+)(?:\|[^\]]+)?\]\]/g))r.push(e[1]);for(let e of n.matchAll(/<(?:img|video|audio|source)[^>]*\bsrc=["']([^"']+)["']/gi))r.push(e[1]);for(let e of n.matchAll(/<a[^>]*\bhref=["']([^"']+)["']/gi))r.push(e[1]);return r.some(e=>xn(e)&&bn(e))}function Pn(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 Fn(e){let t=e.name.split(`.`).pop()?.toLowerCase()||``;return t===`md`||t===`markdown`}async function In(e,t,n,r){let i=n??e.state.selection.from,a=r?St(r):void 0,o=r?.storage?.qingwuUI,s=await new Promise(e=>{o?.chooseMd?o.chooseMd(t.name,e):_n(t.name).then(e)});if(s===null)return;if(s===`attach`){let n=a?Ct(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(`
|
|
5
|
-
`)
|
|
6
|
-
也可以选择稍后把文件直接拖进编辑器。`;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(`cancel`)};n.addEventListener(`mousedown`,e=>{e.target===n&&s(`cancel`)});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 text-default-700 dark:text-zinc-300 dark:border-zinc-600 dark:hover:bg-zinc-700`,l.textContent=`稍后处理`,l.addEventListener(`click`,()=>s(`cancel`));let u=document.createElement(`button`);u.type=`button`,u.className=`px-3 py-1.5 text-xs rounded-lg bg-blue-500 hover:bg-blue-600 text-white`,u.textContent=`选择文件夹…`,u.addEventListener(`click`,()=>s(`pick`)),o.append(l,u),r.append(i,a,o),n.appendChild(r),document.addEventListener(`keydown`,c),document.body.appendChild(n)})}function cr(e){let t=document.createElement(`div`);t.className=`fixed inset-0 z-[10001] flex items-center justify-center bg-black/40 backdrop-blur-sm select-none`;let n=document.createElement(`div`);n.className=`bg-white dark:bg-zinc-800 rounded-xl p-6 shadow-xl max-w-md w-full mx-4 border border-default-200 dark:border-zinc-700`;let r=document.createElement(`div`);r.className=`text-sm font-medium text-default-800 dark:text-zinc-100 mb-2`,r.textContent=`粘贴内容中包含本地文件`;let i=document.createElement(`div`);i.className=`text-xs text-default-500 dark:text-zinc-400 mb-4 whitespace-pre-line leading-relaxed`,i.textContent=`检测到 ${e} 个本地图片/附件使用相对路径,粘贴时文件本体没有跟过来。\n当前浏览器不支持读取本地文件夹(需要 Chrome / Edge)。请把对应的图片或文件直接拖进编辑器,会自动完成上传。`;let a=document.createElement(`div`);a.className=`flex justify-end`;let o=()=>{document.removeEventListener(`keydown`,s),t.remove()},s=e=>{e.key===`Escape`&&o()};t.addEventListener(`mousedown`,e=>{e.target===t&&o()});let c=document.createElement(`button`);c.type=`button`,c.className=`px-3 py-1.5 text-xs rounded-lg bg-blue-500 hover:bg-blue-600 text-white`,c.textContent=`知道了`,c.addEventListener(`click`,o),a.append(c),n.append(r,i,a),t.appendChild(n),document.addEventListener(`keydown`,s),document.body.appendChild(t)}function lr(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-md w-full mx-4 border border-default-200 dark:border-zinc-700 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=`选择文件直接上传`;let a=document.createElement(`div`);a.className=`text-xs text-default-500 dark:text-zinc-400 mb-4 whitespace-pre-line leading-relaxed`,a.textContent=`还有 ${e.length} 个本地文件无法从所选文件夹读取:${e.join(`、`)}。\n点击「选择文件…」后在系统对话框里选中这些文件(可多选),将直接上传到存储。若它们位于云同步目录(OneDrive / 绿联云等),选中后会自动取回本地内容。`;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(`cancel`)};n.addEventListener(`mousedown`,e=>{e.target===n&&s(`cancel`)});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 text-default-700 dark:text-zinc-300 dark:border-zinc-600 dark:hover:bg-zinc-700`,l.textContent=`稍后处理`,l.addEventListener(`click`,()=>s(`cancel`));let u=document.createElement(`button`);u.type=`button`,u.className=`px-3 py-1.5 text-xs rounded-lg bg-blue-500 hover:bg-blue-600 text-white`,u.textContent=`选择文件…`,u.addEventListener(`click`,()=>s(`pick`)),o.append(l,u),r.append(i,a,o),n.appendChild(r),document.addEventListener(`keydown`,c),document.body.appendChild(n)})}async function ur(e,t,n){let r=Zn(),i=tr(n),a=await Dn();if(!a){for(let e of i)r.missing.push(e[0]);return r}let o=new Map(a.map(e=>[e.name.toLowerCase(),e]));for(let n of i){let i=n[0],a=o.get(i.basename);if(!a){r.missing.push(i);continue}o.delete(i.basename);let s=await nr(e,t,n,a);r[s]++}return r}var dr=d.Extension.create({name:`relativeMedia`,addStorage(){return{clipboardFiles:new Map,pausedUntilPaste:!1}},addProseMirrorPlugins(){let e=this.editor,t=this.storage,n=!1,r=null,i=async(n,i)=>{let a=e.view,o=Zn(),{matched:s,unmatched:c}=rr(n,t.clipboardFiles);for(let{refs:t,file:n}of s){let r=await nr(a,e,t,n);o[r]++}if(c.length>0){let t=tr(c).length;if(wn()){let n=i??null;if(n||(await sr(t)===`pick`?(n=await Tn(),n||J(`没有选择文件夹。本地文件暂以占位显示,稍后可直接把文件拖进编辑器上传`,`info`)):J(`已选择稍后处理。本地文件暂以占位显示,可直接把文件拖进编辑器上传`,`info`)),n){r=n,Qn(o,await ir(a,e,c,n));let t=[...o.missing,...o.readFailed];if(t.length>0&&En()&&await lr(t.map(e=>e.basename))===`pick`){let n=await ur(a,e,t);Qn(o,n),o.missing=n.missing,o.readFailed=[]}}}else cr(t)}or(o)},a=()=>{if(!e||e.isDestroyed||t.pausedUntilPaste)return;let a=Mn(e.state.doc);if(a.length===0||n)return;n=!0;let o=new Set(a.map(e=>e.src));i(a).then(()=>{if(e.isDestroyed)return;let t=Mn(e.state.doc).filter(e=>!o.has(e.src));if(t.length!==0)return i(t,r)}).finally(()=>{n=!1,!(!e||e.isDestroyed)&&(t.pausedUntilPaste=Mn(e.state.doc).length>0)})};return[new f.Plugin({key:new f.PluginKey(`relativeMedia`),props:{handlePaste(e,n){let r=n.clipboardData?.files;return t.clipboardFiles=new Map(Array.from(r??[]).map(e=>[e.name.toLowerCase(),e])),t.pausedUntilPaste=!1,!1}},appendTransaction(e){return e.some(e=>e.docChanged)&&queueMicrotask(a),null}})]}}),fr=new f.PluginKey(`slashCommand`);function pr(e){return d.Extension.create({name:`slashCommand`,addProseMirrorPlugins(){let t={char:`/`,pluginKey:fr,findSuggestionMatch:e=>{let{$position:t}=e;for(let e=t.depth;e>=0;e--)if(t.node(e).type.name===`codeBlock`)return null;return t.marks().some(e=>e.type.name===`code`)?null:(0,N.findSuggestionMatch)(e)},allow:({editor:e,state:t})=>{if(!e.isEditable)return!1;let{$from:n}=t.selection;for(let e=n.depth;e>=0;e--)if(n.node(e).type.name===`codeBlock`)return!1;return!n.marks().some(e=>e.type.name===`code`)},command:({editor:e,range:t,props:n})=>{e.chain().focus().deleteRange(t).run(),n.command({editor:e})},items:({query:t})=>{let n=e();if(!t)return n;let r=t.toLowerCase();return n.filter(e=>e.title.toLowerCase().includes(r)||(e.description?.toLowerCase().includes(r)??!1))},render:()=>{let e=null,t=null,n=0,r=[];function i(e,i){if(!t)return;r=e,t.textContent=``;let a=document.createElement(`div`);a.style.cssText=`padding:6px 8px;border-bottom:1px solid #f4f4f5;`;let o=document.createElement(`input`);o.type=`text`,o.placeholder=`搜索命令…`,o.style.cssText=`width:100%;padding:6px 8px;border:1px solid #e4e4e7;border-radius:8px;font-size:13px;outline:none;background:#fafafa;`,a.appendChild(o),t.appendChild(a);let s=document.createElement(`div`);if(s.className=`slash-item-list`,s.style.cssText=`max-height:300px;overflow-y:auto;`,e.length===0){let e=document.createElement(`div`);e.style.cssText=`padding:12px;text-align:center;color:#a1a1aa;font-size:13px;`,e.textContent=`未找到匹配`,s.appendChild(e)}else e.forEach((e,t)=>{let r=document.createElement(`button`);r.type=`button`,r.className=`slash-item${t===n?` slash-item--selected`:``}`,r.dataset.index=String(t),r.style.cssText=`display:flex;align-items:center;gap:12px;width:100%;padding:8px 12px;border:none;background:${t===n?`#f4f4f5`:`transparent`};cursor:pointer;text-align:left;border-radius:8px;font-size:14px;transition:background 0.1s;`;let a=document.createElement(`span`);a.style.cssText=`font-size:16px;width:24px;text-align:center;flex-shrink:0;`,a.textContent=e.icon||``,r.appendChild(a);let o=document.createElement(`div`);o.style.cssText=`min-width:0;`;let c=document.createElement(`div`);if(c.style.cssText=`font-weight:500;color:#18181b;`,c.textContent=e.title,o.appendChild(c),e.description){let t=document.createElement(`div`);t.style.cssText=`font-size:12px;color:#a1a1aa;margin-top:1px;`,t.textContent=e.description,o.appendChild(t)}r.appendChild(o),r.addEventListener(`click`,()=>{i(e)}),s.appendChild(r)});t.appendChild(s),o.addEventListener(`input`,()=>{let e=o.value.toLowerCase();s.querySelectorAll(`.slash-item`).forEach(t=>{let n=(t.textContent||``).toLowerCase();t.style.display=n.includes(e)?``:`none`})})}let a=null,o=null;function s(){if(!e||!a)return;let t=a();t&&(e.style.top=`${t.bottom+4}px`,e.style.left=`${t.left}px`)}return{onStart:c=>{n=0,a=c.clientRect||null,e||(e=document.createElement(`div`),e.style.position=`fixed`,e.style.zIndex=`9999`,document.body.appendChild(e)),t||(t=document.createElement(`div`),t.className=`slash-command-popup`,t.style.cssText=`background:#fff;border:1px solid #e4e4e7;border-radius:12px;box-shadow:0 4px 24px rgba(0,0,0,0.12);min-width:260px;max-width:340px;`,e.appendChild(t)),s(),r=c.items,i(c.items,c.command),e.style.display=`block`,o=()=>s(),window.addEventListener(`scroll`,o,!0)},onUpdate:e=>{n=0,a=e.clientRect||null,r=e.items,i(e.items,e.command),s()},onKeyDown:e=>e.event.key===`ArrowDown`?(e.event.preventDefault(),n=Math.min(n+1,r.length-1),i(r,e.command),!0):e.event.key===`ArrowUp`?(e.event.preventDefault(),n=Math.max(n-1,0),i(r,e.command),!0):e.event.key===`Enter`?(e.event.preventDefault(),r[n]&&e.command(r[n]),!0):e.event.key===`Escape`,onExit:()=>{e&&(e.style.display=`none`),n=0,r=[],a=null,o&&=(window.removeEventListener(`scroll`,o,!0),null)}}}};return[(0,N.default)({editor:this.editor,...t}),new f.Plugin({key:new f.PluginKey(`slashCodeBlockGuard`),appendTransaction:(e,t,n)=>{let{$from:r}=n.selection,i=!1;for(let e=r.depth;e>=0;e--)if(r.node(e).type.name===`codeBlock`){i=!0;break}if(!i&&!r.marks().some(e=>e.type.name===`code`))return null;let a=fr.getState(n);return a&&a.active?n.tr.setMeta(fr,{exit:!0}):null}})]}})}function mr(e,t){return[{title:e(`editor.slash.heading1`),description:e(`editor.slash.heading1Desc`),icon:`H1`,command:({editor:e})=>e.chain().focus().toggleHeading({level:1}).run()},{title:e(`editor.slash.heading2`),description:e(`editor.slash.heading2Desc`),icon:`H2`,command:({editor:e})=>e.chain().focus().toggleHeading({level:2}).run()},{title:e(`editor.slash.heading3`),description:e(`editor.slash.heading3Desc`),icon:`H3`,command:({editor:e})=>e.chain().focus().toggleHeading({level:3}).run()},{title:e(`editor.slash.heading4`),description:e(`editor.slash.heading4Desc`),icon:`H4`,command:({editor:e})=>e.chain().focus().toggleHeading({level:4}).run()},{title:e(`editor.slash.heading5`),description:e(`editor.slash.heading5Desc`),icon:`H5`,command:({editor:e})=>e.chain().focus().toggleHeading({level:5}).run()},{title:e(`editor.slash.heading6`),description:e(`editor.slash.heading6Desc`),icon:`H6`,command:({editor:e})=>e.chain().focus().toggleHeading({level:6}).run()},{title:e(`editor.slash.bulletList`),description:e(`editor.slash.bulletListDesc`),icon:`•`,command:({editor:e})=>e.chain().focus().toggleBulletList().run()},{title:e(`editor.slash.numberedList`),description:e(`editor.slash.numberedListDesc`),icon:`1.`,command:({editor:e})=>e.chain().focus().toggleOrderedList().run()},{title:e(`editor.slash.taskList`),description:e(`editor.slash.taskListDesc`),icon:`☑`,command:({editor:e})=>e.chain().focus().toggleTaskList().run()},{title:e(`editor.slash.blockquote`),description:e(`editor.slash.blockquoteDesc`),icon:`❝`,command:({editor:e})=>e.chain().focus().toggleBlockquote().run()},{title:e(`editor.slash.codeBlock`),description:e(`editor.slash.codeBlockDesc`),icon:`</>`,command:({editor:e})=>e.chain().focus().toggleCodeBlock().run()},{title:e(`editor.slash.horizontalRule`),description:e(`editor.slash.horizontalRuleDesc`),icon:`—`,command:({editor:e})=>e.chain().focus().setHorizontalRule().run()},{title:e(`editor.slash.image`),description:e(`editor.slash.imageDesc`),icon:`🖼`,command:({editor:e})=>{e.storage.qingwuUI?.openImageDialog?.()}},{title:e(`editor.slash.video`),description:e(`editor.slash.videoDesc`),icon:`🎬`,command:({editor:e})=>{e.storage.qingwuUI?.openVideoDialog?.()}},{title:e(`editor.slash.audio`),description:e(`editor.slash.audioDesc`),icon:`🎵`,command:({editor:e})=>{let n=document.createElement(`input`);n.type=`file`,n.accept=`audio/*`,n.onchange=async()=>{let r=n.files?.[0];if(!r)return;let i=St(e)??t,a=i?Ct(e.state.doc,r,i):null;if(a){J(a);return}let o=URL.createObjectURL(r),s=e.schema.nodes.audioEmbed?.create({src:o,name:r.name,size:r.size});s&&(e.chain().focus().insertContent(s).run(),await Rn(e.view,r,o))},n.click()}},{title:e(`editor.slash.attachment`),description:e(`editor.slash.attachmentDesc`),icon:`📎`,command:({editor:e})=>{let n=document.createElement(`input`);n.type=`file`,n.accept=`*/*`,n.multiple=!0,n.onchange=async()=>{let r=n.files;if(!(!r||r.length===0))for(let n of Array.from(r)){let r=St(e)??t,i=r?Ct(e.state.doc,n,r):null;if(i){J(i);continue}let a=URL.createObjectURL(n),o=e.schema.nodes.attachmentEmbed;if(o){try{e.chain().focus().insertContent(o.create({src:a,name:n.name,size:n.size,type:n.type})).run()}catch{continue}await Rn(e.view,n,a)}}},n.click()}}]}var hr=m.Image.extend({addNodeView(){return(0,c.ReactNodeViewRenderer)(Pt)},addAttributes(){return{...this.parent?.(),width:{default:null,parseHTML:e=>e.getAttribute(`width`)||null,renderHTML:e=>e.width?{width:e.width}:{}},height:{default:null,parseHTML:e=>e.getAttribute(`height`)||null,renderHTML:e=>e.height?{height:e.height}:{}},size:{default:0,parseHTML:e=>Number(e.getAttribute(`data-size`)||0),renderHTML:e=>e.size?{"data-size":e.size}:{}}}}});function gr(t={}){return[_.default.configure({codeBlock:!1,horizontalRule:!1,underline:!1,link:!1}),g.Underline,h.Link.configure({openOnClick:!0,HTMLAttributes:{rel:`noopener noreferrer`,target:`_blank`}}),hr.configure({inline:!1,allowBase64:!0}),ee.TaskList,D.TaskItem.configure({nested:!0}),b.Highlight.configure({multicolor:!0}),O.TextStyle,y.Color,v.CharacterCount.configure(t.maxLength?{limit:t.maxLength}:{}),x.HorizontalRule,gn,C.Table.configure({resizable:!0}),E.TableRow,w.TableCell,T.TableHeader,k.Markdown.configure({html:!0,transformPastedText:!0,transformCopiedText:!1}),S.Placeholder.configure({placeholder:t.placeholder||`输入 '/' 打开菜单…`}),pr(()=>mr(t=>e.o(t),{maxAttachmentSize:t.maxAttachmentSize,maxTotalAttachmentSize:t.maxTotalAttachmentSize})),Bn.configure({maxAttachmentSize:t.maxAttachmentSize,maxTotalAttachmentSize:t.maxTotalAttachmentSize}),dr,qn,Be,Jn,on,Qt,Yt]}var _r=`https://www.bing.com/search?q={query}`;function vr(e){_r=e}function yr(){return _r}function br(e){return[{key:`bold`,label:e(`editor.bubble.bold`),icon:(0,a.jsx)(Ue,{}),isActive:e=>e.isActive(`bold`),command:e=>e.isEditable&&e.chain().focus().toggleBold().run()},{key:`italic`,label:e(`editor.bubble.italic`),icon:(0,a.jsx)(We,{}),isActive:e=>e.isActive(`italic`),command:e=>e.isEditable&&e.chain().focus().toggleItalic().run()},{key:`underline`,label:e(`editor.bubble.underline`),icon:(0,a.jsx)(Ge,{}),isActive:e=>e.isActive(`underline`),command:e=>e.isEditable&&e.chain().focus().toggleUnderline().run()},{key:`strikethrough`,label:e(`editor.bubble.strikethrough`),icon:(0,a.jsx)(Ke,{}),isActive:e=>e.isActive(`strike`),command:e=>e.isEditable&&e.chain().focus().toggleStrike().run()},{key:`code`,label:e(`editor.bubble.emphasis`),icon:(0,a.jsx)(qe,{}),isActive:e=>e.isActive(`code`),command:e=>e.isEditable&&e.chain().focus().toggleCode().run()},{key:`highlight`,label:e(`editor.bubble.highlight`),icon:(0,a.jsx)(Je,{}),more:!0,isActive:e=>e.isActive(`highlight`),command:()=>{}},{key:`link`,label:e(`editor.bubble.link`),icon:(0,a.jsx)(Ye,{}),more:!0,isActive:e=>e.isActive(`link`),command:()=>{}},{key:`copy`,label:e(`editor.bubble.copy`),icon:(0,a.jsx)(Ze,{}),more:!0,isActive:()=>!1,command:e=>{let{from:t,to:n}=e.state.selection,r=e.state.doc.textBetween(t,n,`
|
|
7
|
-
`).trim()
|
|
8
|
-
`)}function wr(e){let t=e=>/[",\n]/.test(e)?`"${e.replace(/"/g,`""`)}"`:e;return e.map(e=>e.map(t).join(`,`)).join(`
|
|
9
|
-
`)}function Tr(e){let t=e.trim();if(!t)return null;let n=t.split(/\r?\n/);if(n.length>=2&&n.every(e=>e.includes(`|`))){let e=n.filter(e=>!/^\s*\|?[\s:|-]+\|?\s*$/.test(e)).map(e=>e.replace(/^\s*\|/,``).replace(/\|\s*$/,``).split(`|`).map(e=>e.trim()));if(e.length>0&&e[0].length>1)return e}if(n.length>=1){let e=n[0].includes(` `)?` `:`,`,t=n.map(t=>t.split(e).map(e=>e.trim()));if(t.length>0&&t[0].length>1)return t}return null}function Er({editor:e}){let[t,n]=(0,i.useState)(null),[r,o]=(0,i.useState)(!1),[s,c]=(0,i.useState)(!1),l=(0,i.useRef)(null),u=(0,i.useRef)(null),d=e.isEditable,f=(0,i.useCallback)(()=>{u.current!=null&&cancelAnimationFrame(u.current),u.current=requestAnimationFrame(()=>{u.current=null;let n=l.current;if(n==null||t==null)return;let r=e.view.nodeDOM(t);if(!(r instanceof HTMLElement))return;let i=r.getBoundingClientRect(),a=i.top>40?i.top-34:Math.min(i.bottom+4,window.innerHeight-40);n.style.top=`${a}px`,n.style.left=`${Math.max(8,Math.min(i.left,window.innerWidth-160))}px`})},[e,t]),p=(0,i.useCallback)(()=>{if(!e.isEditable||!e.isActive(`table`)){n(null);return}let t=xr(e);if(!t){n(null);return}n(e=>e===t.pos?e:t.pos)},[e]);(0,i.useEffect)(()=>(p(),e.on(`selectionUpdate`,p),e.on(`focus`,p),window.addEventListener(`scroll`,f,!0),window.addEventListener(`resize`,f),()=>{e.off(`selectionUpdate`,p),e.off(`focus`,p),window.removeEventListener(`scroll`,f,!0),window.removeEventListener(`resize`,f),u.current!=null&&cancelAnimationFrame(u.current)}),[e,p,f]),(0,i.useEffect)(()=>{f()},[t,f]);let m=t=>{let{schema:n}=e.state;if(!n.nodes.table||!n.nodes.tableRow||!n.nodes.tableCell||!n.nodes.tableHeader)return null;let r=Math.max(...t.map(e=>e.length)),i=t.map((e,t)=>{let i=[];for(let a=0;a<r;a++){let r=e[a]??``,o=t===0?n.nodes.tableHeader:n.nodes.tableCell,s=r?n.text(r):null;i.push(o.create(null,s?[s]:[]))}return n.nodes.tableRow.create(null,i)});return n.nodes.table.create(null,i)},h=()=>{let t=xr(e);if(!t)return;let n=Cr(Sr(t.node));navigator.clipboard?.writeText(n),o(!0),setTimeout(()=>o(!1),1500)},g=()=>{let t=xr(e);if(!t)return;let n=wr(Sr(t.node)),r=new Blob([`\ufeff${n}`],{type:`text/csv;charset=utf-8`}),i=URL.createObjectURL(r),a=document.createElement(`a`);a.href=i,a.download=`table.csv`,document.body.appendChild(a),a.click(),document.body.removeChild(a),URL.revokeObjectURL(i)},_=async()=>{if(d)try{let t=await navigator.clipboard?.readText();if(!t)return;let n=Tr(t);if(!n||n.length===0)return;let r=m(n);if(!r)return;let i=xr(e),a=e.chain().focus();if(i){let t=Math.min(i.pos+i.node.nodeSize,e.state.doc.content.size);a.setTextSelection(t)}a.insertContent(r).run()}catch{}},v=()=>{d&&t!=null&&(e.chain().focus().setNodeSelection(t).run(),e.storage.qingwuUI?.openAI?.())},y=()=>{d&&e.chain().focus().deleteTable().run()};return!d||t==null?null:(0,a.jsxs)(`div`,{ref:l,style:{position:`fixed`,top:0,left:0,zIndex:1e5},className:`tbl-toolbar`,contentEditable:!1,children:[(0,a.jsx)(`button`,{type:`button`,className:`tbl-btn`,onClick:h,title:`复制`,children:r?(0,a.jsx)(`svg`,{className:`tbl-btn-icon tbl-btn-icon--check`,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 13l4 4L19 7`})}):(0,a.jsx)(`svg`,{className:`tbl-btn-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:`M8 5H6a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2v-2M8 5a2 2 0 002 2h2a2 2 0 002-2M8 5a2 2 0 012-2h2a2 2 0 012 2m0 0h2a2 2 0 012 2v3`})})}),(0,a.jsx)(`button`,{type:`button`,className:`tbl-btn`,onClick:g,title:`下载`,children:(0,a.jsx)(`svg`,{className:`tbl-btn-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:`M4 16v1a3 3 0 003 3h10a3 3 0 003-3v-1m-4-4l-4 4m0 0l-4-4m4 4V4`})})}),(0,a.jsx)(`button`,{type:`button`,className:`tbl-btn`,onClick:_,title:`粘贴`,children:(0,a.jsx)(`svg`,{className:`tbl-btn-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:`M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2`})})}),(0,a.jsx)(`button`,{type:`button`,className:`tbl-btn tbl-btn--ai`,onClick:v,title:`AI 助手`,children:(0,a.jsx)(`svg`,{className:`tbl-btn-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:`M13 10V3L4 14h7v7l9-11h-7z`})})}),(0,a.jsx)(`button`,{type:`button`,className:`tbl-btn tbl-btn--del`,onClick:()=>{!d||Dt()||($(!0),c(!0))},title:`删除`,children:(0,a.jsx)(`svg`,{className:`tbl-btn-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:`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)(Mt,{open:s,title:`确认删除表格`,message:`此操作不可撤销。`,onCancel:()=>{$(!1),c(!1)},onConfirm:async()=>{await new Promise(e=>setTimeout(e,300)),$(!1),y()}})]})}var Dr=[{color:`#fef08a`,name:`黄`},{color:`#bbf7d0`,name:`绿`},{color:`#bfdbfe`,name:`蓝`},{color:`#fbcfe8`,name:`粉`},{color:`#fed7aa`,name:`橙`},{color:`#ddd6fe`,name:`紫`}],Or=288,kr=320;function Ar(e,t,n={}){let r=window.innerWidth,i=window.innerHeight,a=Math.min(n.panelWidth||Or,r-32),o=Math.max(t||kr,160);if(r<640)return{style:{position:`fixed`,top:Math.max(8,Math.min(e.top+10,i-420)),left:8,right:8,width:`auto`,zIndex:9999,maxHeight:`calc(100dvh - 32px)`,overflow:`hidden`,display:`flex`,flexDirection:`column`},placement:`below`,arrowLeft:50};let s=e.left+e.width/2,c=typeof n.editorLeft==`number`?n.editorLeft:s-a/2;c=Math.max(16,Math.min(c,r-a-16));let l=i-e.top-16,u=e.top-16,d=l<o+12&&u>=o+12?`above`:`below`,f=d===`below`?e.top+10:e.top-o-10;f=Math.max(16,Math.min(f,i-o-16));let p=Math.max(14,Math.min((s-c)/a*100,86));return{style:{position:`fixed`,top:f,left:c,width:a,zIndex:9999,maxHeight:`calc(100dvh - 32px)`,overflow:`hidden`,display:`flex`,flexDirection:`column`},placement:d,arrowLeft:p}}function jr(e){return/(^|\n)```|(^|\n)#{1,6}\s|(^|\n)>\s?|(^|\n)\s*([-*_])(?:\s*\4){2,}\s*(?=\n|$)|(^|\n)\s*[-*+]\s+|(^|\n)\s*\d+[.)]\s+|(^|\n)\s*<img\s+|(^|\n)\s*\|.+\|/i.test(e)}function Mr(e,t){try{let n=e.storage?.markdown?.parser;if(!n)return null;let r=n.parse(t),i=document.createElement(`div`);return i.innerHTML=r,s.DOMParser.fromSchema(e.schema).parse(i).content}catch{return null}}var Nr=(0,i.lazy)(()=>Promise.resolve().then(()=>ve).then(e=>({default:e.ImageUploadDialog}))),Pr=(0,i.lazy)(()=>Promise.resolve().then(()=>require("./storage-settings-dialog-Dojhp-Uo.cjs")).then(e=>({default:e.StorageSettingsDialog}))),Fr=(0,i.lazy)(()=>Promise.resolve().then(()=>require("./export-dialog-JUHUKqo-.cjs")).then(e=>({default:e.ExportDialog}))),Ir=(0,i.lazy)(()=>Promise.resolve().then(()=>require("./video-embed-dialog-BbVHq51W.cjs")).then(e=>({default:e.VideoEmbedDialog}))),Lr=(0,i.lazy)(()=>Promise.resolve().then(()=>require("./md-import-dialog-CnstzrIK.cjs")).then(e=>({default:e.MdImportDialog}))),Rr=()=>(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`}),(0,a.jsx)(`div`,{className:`relative bg-background rounded-2xl border border-default-200 p-8 flex items-center justify-center`,children:(0,a.jsx)(`div`,{className:`w-6 h-6 border-2 border-primary border-t-transparent rounded-full animate-spin`})})]}),zr=({initialContent:t=``,onChange:n,placeholder:r,mode:o,readonly:d=!1,maxLength:f,maxAttachmentSize:p,maxTotalAttachmentSize:m,className:h=``,borderless:g=!1,style:_,showToolbar:v=!0,showToc:y=!0,showSearch:b=!0,onEditorReady:x,immediatelyRender:S,onToast:C})=>{let w=o===`view`||d,T=(0,i.useMemo)(()=>jr(t)?t:e.n(t),[t]),[E,D]=(0,i.useState)(!1),[ee,O]=(0,i.useState)({}),[k,A]=(0,i.useState)(`below`),[j,M]=(0,i.useState)(50),N=(0,i.useRef)(null),[P,te]=(0,i.useState)(!1),[F,I]=(0,i.useState)(!1),[ne,re]=(0,i.useState)(!1),[ie,ae]=(0,i.useState)(!1),[L,R]=(0,i.useState)(`none`),[z,B]=(0,i.useState)({}),[V,oe]=(0,i.useState)(``),[H,U]=(0,i.useState)(null),[W,se]=(0,i.useState)(y),[G,ce]=(0,i.useState)(!1);(0,i.useEffect)(()=>{se(y)},[y]);let[le,ue]=(0,i.useState)(!1),[de,fe]=(0,i.useState)(()=>typeof window<`u`&&typeof window.matchMedia==`function`?window.matchMedia(`(min-width: 80rem)`).matches:!0),[pe,K]=(0,i.useState)(()=>typeof window<`u`&&typeof window.matchMedia==`function`?window.matchMedia(`(min-width: 64rem)`).matches:!0),me=(0,i.useRef)(null),q=(0,i.useRef)(null),he=(0,i.useRef)(null),ge=(0,i.useRef)(0),ve=(0,i.useRef)(null),ye=(0,i.useRef)(null),be=(0,i.useRef)(null),[xe,Se]=(0,i.useState)(!1),[Y,Ce]=(0,i.useState)(!1),[we,Te]=(0,i.useState)(!1),De=(0,i.useCallback)(()=>{let e=q.current,t=he.current;e&&(Y?(document.body.style.overflow=``,Object.assign(e.style,{position:``,top:``,left:``,width:``,height:``,zIndex:``,background:``,borderRadius:``,overflow:``,display:``,flexDirection:``}),t&&Object.assign(t.style,{flex:``,overflow:``,minHeight:``}),Ce(!1),requestAnimationFrame(()=>{window.scrollTo(0,ge.current)})):(document.fullscreenElement&&document.exitFullscreen(),ge.current=window.scrollY,Object.assign(e.style,{position:`fixed`,top:`0`,left:`0`,width:`100vw`,height:`100vh`,zIndex:`99999`,background:`var(--background, #fff)`,borderRadius:`0`,overflow:`hidden`,display:`flex`,flexDirection:`column`}),t&&Object.assign(t.style,{flex:`1`,overflow:`auto`,minHeight:`0`}),document.body.style.overflow=`hidden`,Ce(!0)))},[Y]),Oe=(0,i.useCallback)(()=>{let e=q.current;e&&(document.fullscreenElement?document.exitFullscreen():(Y&&De(),ge.current=window.scrollY,e.requestFullscreen()))},[Y,De]);(0,i.useEffect)(()=>{let e=e=>{e.key===`Escape`&&Y&&De()},t=()=>{document.fullscreenElement?Te(!0):(Te(!1),requestAnimationFrame(()=>{window.scrollTo(0,ge.current)}))};return window.addEventListener(`keydown`,e),document.addEventListener(`fullscreenchange`,t),()=>{window.removeEventListener(`keydown`,e),document.removeEventListener(`fullscreenchange`,t)}},[Y,De]),(0,i.useEffect)(()=>{if(!b)return;let e=e=>{if((e.ctrlKey||e.metaKey)&&(e.key===`f`||e.key===`F`)){if(!q.current)return;e.preventDefault(),e.stopPropagation(),ue(!0)}};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[b]),(0,i.useEffect)(()=>{if(typeof window>`u`||typeof window.matchMedia!=`function`)return;let e=window.matchMedia(`(min-width: 80rem)`),t=e=>fe(e.matches);return fe(e.matches),e.addEventListener(`change`,t),()=>e.removeEventListener(`change`,t)},[]),(0,i.useEffect)(()=>{if(typeof window>`u`||typeof window.matchMedia!=`function`)return;let e=window.matchMedia(`(min-width: 64rem)`),t=e=>K(e.matches);return K(e.matches),e.addEventListener(`change`,t),()=>e.removeEventListener(`change`,t)},[]);let X=(0,c.useEditor)({extensions:gr({placeholder:r||e.o(`editor.placeholder`),maxLength:f,maxAttachmentSize:p,maxTotalAttachmentSize:m}),content:T,editable:!w,immediatelyRender:S,onUpdate:({editor:e})=>{n&&(me.current&&clearTimeout(me.current),me.current=setTimeout(()=>{n?.(e.getHTML(),e.getJSON())},300))},onCreate:()=>{},editorProps:{attributes:{class:`prose prose-neutral dark:prose-invert max-w-none focus:outline-none min-h-[200px] px-4 sm:px-8 py-4`},handlePaste(e,t){let n=t.clipboardData;if(!n)return!1;let r=n.getData(`text/plain`);if(!r||!r.includes(`[[`))return!1;t.preventDefault();let i=ye.current?.storage?.relativeMedia;i&&(i.clipboardFiles=new Map(Array.from(n.files??[]).map(e=>[e.name.toLowerCase(),e])),i.pausedUntilPaste=!1);let a=ye.current?Mr(ye.current,r):null;if(a){let t=new s.Slice(a,0,0);e.dispatch(e.state.tr.replaceSelection(t).scrollIntoView())}else e.dispatch(e.state.tr.insertText(r).scrollIntoView());return!0}}});(0,i.useEffect)(()=>{ye.current=X,window.__editor=X},[X]),(0,i.useEffect)(()=>{if(X)return()=>lt(X)},[X]),(0,i.useEffect)(()=>{!X||!x||x(X)},[X,x]),(0,i.useEffect)(()=>{if(!X)return;let e=()=>{X.state.selection.empty&&(R(`none`),Se(!1))};return X.on(`selectionUpdate`,e),()=>{X.off(`selectionUpdate`,e)}},[X]),(0,i.useEffect)(()=>{X&&X.setOptions({extensions:gr({placeholder:r||e.o(`editor.placeholder`),maxLength:f,maxAttachmentSize:p,maxTotalAttachmentSize:m})})},[r,f,p,m]);let ke=(0,i.useRef)(t);(0,i.useEffect)(()=>{if(!X||t===ke.current)return;ke.current=t;let n=jr(t)?t:e.n(t);X.commands.setContent(n,{emitUpdate:!1})},[X,t]),(0,i.useEffect)(()=>{X&&X.setEditable(!w,!1)},[X,w]),(0,i.useEffect)(()=>{if(C)return _e(C)},[C]),(0,i.useEffect)(()=>{if(!X)return;let e=bt(X.state.doc);e>m&&J(`文档内附件总大小 ${xt(e)} 已超过限制 ${xt(m)}`,`info`)},[X,m]),(0,i.useEffect)(()=>{if(!X)return;let e=X.storage.qingwuUI;e&&(e.limits={maxAttachmentSize:p,maxTotalAttachmentSize:m})},[X,p,m]);let Ae=(0,i.useCallback)(e=>{let t=be.current?.getBoundingClientRect();R(e),Se(!1),B({position:`fixed`,top:t?t.bottom+8:void 0,left:t?Math.max(8,Math.min(t.left,window.innerWidth-240)):8,zIndex:9999})},[]),je=br(t=>e.o(t)),Me=je.filter(e=>!e.more),Ne=je.filter(e=>e.more),Pe=Me.filter(e=>e.key!==`ai`),Fe=Me.find(e=>e.key===`ai`),Z=(0,i.useCallback)(e=>{if(X)if(Se(!1),e.key===`link`)if(X.isActive(`link`))X.chain().focus().unsetLink().run();else{let e=X.getAttributes(`link`).href||``;oe(e),Ae(`link`)}else e.key===`highlight`?L===`highlight`?R(`none`):Ae(`highlight`):e.command(X)},[X,L,Ae]),Ie=(0,i.useCallback)(e=>X?e.key===`highlight`?L===`highlight`:e.key===`link`?X.isActive(`link`):e.isActive(X):!1,[X,L]),[Le,Re]=(0,i.useState)(0);(0,i.useEffect)(()=>{if(!X)return;let e=()=>Re(e=>(e+1)%1e6);return X.on(`update`,e),()=>{X.off(`update`,e)}},[X]);let[ze,Be]=(0,i.useState)(!1);(0,i.useEffect)(()=>{if(!X)return;let e=()=>{let e=!1;X.state.doc.descendants(t=>{t.type.name===`heading`&&(e=!0)}),Be(e)};return e(),X.on(`update`,e),()=>{X.off(`update`,e)}},[X]);let Ve=(0,i.useMemo)(()=>X?.storage?.characterCount?.characters?.()??0,[X,Le]),Q=f?Ve>f:!1;(0,i.useEffect)(()=>()=>{me.current&&clearTimeout(me.current)},[]),(0,i.useEffect)(()=>()=>{H&&H.resolve(null)},[]);let Ue=(0,i.useCallback)(e=>{if(!X?.isEditable)return;let t=window.getSelection(),n;if(e){let t=e.getBoundingClientRect();n={top:t.bottom,left:t.left,width:t.width}}else if(t&&t.rangeCount>0&&!t.isCollapsed){let e=t.getRangeAt(0).getBoundingClientRect();n={top:e.bottom,left:e.left,width:e.width}}else{let e=X.view.coordsAtPos(X.state.selection.from);n={top:e.bottom,left:e.left,width:0}}ve.current=n;let r=q.current?.getBoundingClientRect(),i=Ar(n,void 0,{panelWidth:r?.width,editorLeft:r?.left});D(!0),O(i.style),A(i.placement),M(i.arrowLeft)},[X]);(0,i.useEffect)(()=>{if(!X)return;let e=X.storage.qingwuUI;if(e)return e.openImageDialog=()=>te(!0),e.openVideoDialog=()=>I(!0),e.chooseMd=(e,t)=>{U({filename:e,resolve:t})},e.openAI=Ue,e.parseMd=(e,t)=>X?Mr(X,t):null,()=>{delete e.openImageDialog,delete e.openVideoDialog,delete e.openAI,delete e.parseMd,delete e.chooseMd}},[X,Ue]),(0,i.useLayoutEffect)(()=>{if(!E||!X)return;let e=ve.current;if(!e)return;let t=N.current,n=q.current?.getBoundingClientRect(),r=Ar(e,t?.offsetHeight||void 0,{panelWidth:n?.width,editorLeft:n?.left});A(r.placement),M(r.arrowLeft),O(r.style)},[E,X]),(0,i.useEffect)(()=>{if(!E||!X)return;let e=()=>{let e=ve.current;if(!e)return;let t=N.current,n=q.current?.getBoundingClientRect(),r=Ar(e,t?.offsetHeight||void 0,{panelWidth:n?.width,editorLeft:n?.left});A(r.placement),M(r.arrowLeft),O(r.style)};return window.addEventListener(`resize`,e),()=>window.removeEventListener(`resize`,e)},[E,X]),(0,i.useEffect)(()=>{E||(ve.current=null)},[E]);let We=(0,i.useCallback)(e=>{X?.chain().focus().setImage({src:e}).run()},[X]),Ge=(0,i.useCallback)(e=>{(X?.commands).insertVideo?.({src:e})},[X]),Ke=W&&de&&!Y&&!we,qe=!Ke&&!G&&(W||ze&&!(!w&&pe)),Je=(0,i.useRef)(!1);return(0,i.useEffect)(()=>{Je.current||(Je.current=!0,W&&!Ke&&ce(!0))},[W,Ke]),X?(0,a.jsxs)(`div`,{className:`qingwu-editor-row`,children:[(0,a.jsxs)(`div`,{ref:q,className:`qingwu-editor relative flex-1 min-w-0 bg-background ${w?`qingwu-editor--readonly`:``} ${g?``:`rounded-xl border border-default-200`} ${h}`,style:_,children:[v&&(0,a.jsxs)(`div`,{className:`qed-toolbar`,children:[(0,a.jsxs)(`div`,{className:`qed-toolbar__group`,children:[(0,a.jsx)(`button`,{type:`button`,className:`qed-tb-btn qed-tb-btn--desktop-only${W?` is-active`:``}`,onClick:()=>{W?(se(!1),ce(!1)):(se(!0),Ke||ce(!0))},title:W?`隐藏目录`:`显示目录`,"aria-label":W?`隐藏目录`:`显示目录`,"aria-pressed":W,children:(0,a.jsx)(`svg`,{fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,strokeWidth:2,"aria-hidden":`true`,children:(0,a.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M4 6h16M4 12h10M4 18h7`})})}),b&&(0,a.jsx)(`button`,{type:`button`,className:`qed-tb-btn${le?` is-active`:``}`,onClick:()=>ue(!le),title:`查找 (Ctrl+F)`,"aria-label":`查找`,"aria-pressed":le,children:(0,a.jsx)(`svg`,{fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,strokeWidth:2,"aria-hidden":`true`,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`})})}),!w&&(0,a.jsx)(`button`,{type:`button`,className:`qed-tb-btn qed-tb-btn--ai${E?` is-active`:``}`,onClick:e=>E?D(!1):Ue(e.currentTarget),title:e.o(`editor.toolbar.aiTitle`),"aria-label":e.o(`editor.toolbar.ai`),"aria-pressed":E,children:(0,a.jsxs)(`svg`,{fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,strokeWidth:2,"aria-hidden":`true`,children:[(0,a.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,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`,{strokeLinecap:`round`,strokeLinejoin:`round`,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`})]})})]}),(0,a.jsxs)(`div`,{className:`qed-toolbar__group`,children:[(0,a.jsxs)(`button`,{type:`button`,className:`qed-tb-btn qed-tb-btn--solid`,onClick:()=>ae(!0),title:e.o(`editor.toolbar.exportTitle`),children:[(0,a.jsx)(`svg`,{fill:`none`,viewBox:`0 0 24 24`,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`})}),(0,a.jsx)(`span`,{className:`qed-tb-btn__label`,children:e.o(`editor.toolbar.export`)})]}),(0,a.jsx)(`button`,{type:`button`,className:`qed-tb-btn${Y?` is-active`:``}`,onClick:De,title:Y?`退出网页全屏`:`网页全屏`,"aria-label":Y?`退出网页全屏`:`网页全屏`,"aria-pressed":Y,children:(0,a.jsx)(`svg`,{fill:`none`,viewBox:`0 0 24 24`,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`,className:`qed-tb-btn${we?` is-active`:``}`,onClick:Oe,title:we?`退出全屏`:`全屏`,"aria-label":we?`退出全屏`:`全屏`,"aria-pressed":we,children:(0,a.jsx)(`svg`,{fill:`none`,viewBox:`0 0 24 24`,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`})})})]})]}),X&&!w&&X.isEditable&&(0,a.jsx)(l.BubbleMenu,{editor:X,shouldShow:({editor:e,state:t})=>!(e.isActive(`image`)||e.isActive(`videoEmbed`)||e.isActive(`codeBlock`)||e.isActive(`audioEmbed`)||e.isActive(`attachmentEmbed`)||t.selection.empty),options:{placement:`bottom`,offset:8,flip:!0},className:`bubble-menu-pop bg-background border border-default-200 rounded-xl p-1 shadow-lg`,children:(0,a.jsxs)(`div`,{ref:be,className:`bubble-menu-items relative flex items-center gap-0.5`,onPointerDown:e=>{e.target.closest(`button`)&&e.preventDefault()},children:[Pe.map(e=>(0,a.jsx)(`button`,{type:`button`,className:`flex items-center justify-center w-7 h-7 rounded-lg transition-colors ${e.isActive(X)?`bg-primary/10 text-primary`:`text-default-600 hover:bg-default-100`}`,onClick:t=>{t.preventDefault(),Z(e)},title:e.label,"aria-label":e.label,children:e.icon},e.key)),(0,a.jsx)(`span`,{className:`w-px h-4 bg-default-200 mx-0.5 shrink-0`,"aria-hidden":`true`}),(0,a.jsx)(`button`,{type:`button`,className:`flex items-center justify-center w-7 h-7 rounded-lg transition-colors ${E?`bg-primary/15 text-primary`:`text-primary hover:bg-primary/10`}`,onClick:e=>{e.preventDefault(),Se(!1),Fe?.command(X)},title:Fe?.label,"aria-label":Fe?.label,children:(0,a.jsx)($e,{})}),(0,a.jsx)(`span`,{className:`w-px h-4 bg-default-200 mx-0.5 shrink-0`,"aria-hidden":`true`}),(0,a.jsx)(`button`,{type:`button`,"aria-expanded":xe,className:`flex items-center justify-center w-7 h-7 rounded-lg transition-colors ${xe?`bg-default-100 text-default-900`:`text-default-600 hover:bg-default-100`}`,onClick:e=>{e.preventDefault(),Se(e=>!e)},title:e.o(`editor.bubble.more`),"aria-label":e.o(`editor.bubble.more`),children:(0,a.jsx)(et,{})}),xe&&(0,a.jsx)(`div`,{role:`menu`,className:`bubble-more-menu absolute right-0 top-full z-[9999] mt-1 w-max max-h-[70vh] overflow-y-auto flex-col gap-1 rounded-xl border border-default-200 bg-background p-1.5 shadow-xl`,onPointerDown:e=>{e.target.closest(`button`)&&e.preventDefault()},children:Ne.map(e=>(0,a.jsxs)(`button`,{type:`button`,role:`menuitem`,className:`flex items-center gap-2 w-full whitespace-nowrap px-3 py-1.5 text-xs rounded-md transition-colors ${Ie(e)?`bg-primary/10 text-primary`:`text-default-600 hover:bg-default-100`}`,onClick:t=>{t.preventDefault(),Z(e)},title:e.label,children:[(0,a.jsx)(`span`,{className:`w-4 h-4 flex items-center justify-center shrink-0`,children:e.icon}),(0,a.jsx)(`span`,{className:`tracking-wide`,children:e.label})]},e.key))})]})}),X&&L!==`none`&&(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(`div`,{className:`fixed inset-0 z-[9998]`,onClick:()=>R(`none`)}),(0,a.jsx)(`div`,{style:z,className:`bg-background border border-default-200 rounded-xl shadow-xl`,onClick:e=>e.stopPropagation(),children:L===`highlight`?(0,a.jsxs)(`div`,{className:`flex items-center gap-1 p-1.5 flex-wrap`,children:[Dr.map(e=>(0,a.jsx)(`button`,{type:`button`,className:`w-5 h-5 rounded-full border border-default-200 hover:scale-110 transition-transform`,style:{background:e.color},title:e.name,onClick:()=>{X.chain().focus().setHighlight({color:e.color}).run(),R(`none`)}},e.color)),(0,a.jsxs)(`button`,{type:`button`,className:`w-5 h-5 rounded-full border border-default-200 text-default-500 hover:bg-default-100 flex items-center justify-center text-[10px]`,title:`清除高亮`,onClick:()=>{X.chain().focus().unsetHighlight().run(),R(`none`)},children:[`✕`,` `]})]}):(0,a.jsxs)(`div`,{className:`flex items-center gap-1.5 p-1.5`,children:[(0,a.jsx)(`input`,{type:`url`,autoFocus:!0,className:`flex-1 px-2 py-1 text-xs rounded-md border border-default-200 bg-background focus:outline-none focus:border-primary`,placeholder:`https://...`,value:V,onChange:e=>oe(e.target.value),onKeyDown:e=>{e.key===`Enter`?(V.trim()&&X.chain().focus().setLink({href:V.trim()}).run(),R(`none`)):e.key===`Escape`&&R(`none`)}}),(0,a.jsx)(`button`,{type:`button`,className:`px-2 py-1 text-xs rounded-md bg-primary text-white hover:opacity-90`,onClick:()=>{V.trim()&&X.chain().focus().setLink({href:V.trim()}).run(),R(`none`)},children:`确定`})]})})]}),!w&&E&&(0,u.createPortal)((0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(`div`,{className:`fixed inset-0 z-[9998]`,onClick:()=>D(!1)}),(0,a.jsxs)(`div`,{ref:N,"data-lenis-prevent":!0,style:ee,className:`ai-panel relative flex flex-col bg-background border border-default-200 rounded-xl shadow-xl${k===`above`?` ai-panel--above`:``}`,onClick:e=>e.stopPropagation(),children:[(0,a.jsx)(`span`,{className:`ai-panel__arrow`,style:{left:`${j}%`},"aria-hidden":`true`}),(0,a.jsx)(vt,{editor:X,onClose:()=>D(!1)})]})]}),document.body),P&&(0,a.jsx)(i.Suspense,{fallback:(0,a.jsx)(Rr,{}),children:(0,a.jsx)(Nr,{open:P,onClose:()=>te(!1),onInsert:We,validate:e=>X?Ct(X.state.doc,e,{maxAttachmentSize:p,maxTotalAttachmentSize:m}):null})}),F&&(0,a.jsx)(i.Suspense,{fallback:(0,a.jsx)(Rr,{}),children:(0,a.jsx)(Ir,{open:F,onClose:()=>I(!1),onInsert:Ge})}),ne&&(0,a.jsx)(i.Suspense,{fallback:(0,a.jsx)(Rr,{}),children:(0,a.jsx)(Pr,{open:ne,onClose:()=>re(!1)})}),ie&&(0,a.jsx)(i.Suspense,{fallback:(0,a.jsx)(Rr,{}),children:(0,a.jsx)(Fr,{open:ie,onClose:()=>ae(!1),editor:X})}),H&&(0,a.jsx)(i.Suspense,{fallback:(0,a.jsx)(Rr,{}),children:(0,a.jsx)(Lr,{open:!!H,filename:H.filename,onRender:()=>{H.resolve(`render`),U(null)},onAttach:()=>{H.resolve(`attach`),U(null)},onClose:()=>{H.resolve(null),U(null)}})}),(0,a.jsx)(`div`,{ref:he,className:`flex editor-body`,children:(0,a.jsxs)(`div`,{className:`relative min-w-0 flex-1`,children:[(0,a.jsx)(c.EditorContent,{editor:X}),!w&&(0,a.jsx)(Er,{editor:X}),(0,a.jsx)(`div`,{className:`${Y||we?`fixed`:`absolute`} bottom-2 right-4 z-10 pointer-events-none select-none`,children:(0,a.jsxs)(`span`,{className:`text-xs ${Q?`bg-danger/10 text-danger font-medium px-2 py-0.5 rounded`:f&&Ve>f*.9?`bg-warning/10 text-warning px-2 py-0.5 rounded`:`text-default-300`}`,children:[Ve,f?` / ${f}`:``,` 字`]})})]})}),b&&le&&(0,a.jsx)(He,{editor:X,onClose:()=>ue(!1)}),qe&&(0,a.jsx)(`button`,{type:`button`,className:`qingwu-toc-fab`,onClick:()=>ce(!0),title:`目录`,"aria-label":`打开目录`,children:(0,a.jsx)(`svg`,{fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,strokeWidth:2,"aria-hidden":`true`,children:(0,a.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M4 6h16M4 12h10M4 18h7`})})}),G&&(0,a.jsxs)(`div`,{className:`qingwu-toc-drawer toc-scroll`,children:[(0,a.jsxs)(`div`,{className:`qed-drawer-head`,children:[(0,a.jsx)(`span`,{className:`qed-drawer-head__title`,children:`目录`}),(0,a.jsx)(`button`,{type:`button`,className:`qed-drawer-head__close`,onClick:()=>ce(!1),"aria-label":`关闭目录`,children:(0,a.jsx)(`svg`,{fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,strokeWidth:2,"aria-hidden":`true`,children:(0,a.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M6 18L18 6M6 6l12 12`})})})]}),(0,a.jsx)(Ee,{editor:X,className:`!p-3`,onClose:()=>{ce(!1),se(!1)}})]})]}),Ke&&(0,a.jsx)(`aside`,{className:`qingwu-toc-desktop toc-scroll`,children:(0,a.jsx)(Ee,{editor:X,onClose:()=>se(!1)})})]}):(0,a.jsx)(`div`,{className:`flex items-center justify-center h-32 text-default-400`,children:e.o(`editor.loading`)})};function Br(e){let t=async t=>{let n=t.data;if(!n||typeof n!=`object`||n.kind!==`qingwu-clip`)return;let r=t.origin;if(r&&r!==`null`&&r!==window.location.origin)return;let i=n.clip;if(i?.markdown)try{await e.onClip(i,t)}catch(e){console.warn(`[qingwu-clipper] 处理剪藏失败:`,e)}};return window.addEventListener(`message`,t),{close:()=>window.removeEventListener(`message`,t)}}function Vr(e){return r.n({endpoint:`https://cos.${e.region}.myqcloud.com`,bucket:e.bucket,region:e.region,accessKeyId:e.secretId,secretAccessKey:e.secretKey,customDomain:e.customDomain,uploadPrefix:e.uploadPrefix,nameTemplate:e.nameTemplate})}function Hr(e){return r.n({endpoint:`https://${e.bucket}.${e.region}.aliyuncs.com`,bucket:e.bucket,region:e.region,accessKeyId:e.accessKeyId,secretAccessKey:e.accessKeySecret,customDomain:e.customDomain,uploadPrefix:e.uploadPrefix,nameTemplate:e.nameTemplate})}exports.CODE_LANGUAGES=mn,exports.CodeBlock=gn,exports.ImageUpload=Bn,exports.ImageUploadDialog=ye,exports.QingWuAIEditor=zr,exports.RelativeMedia=dr,exports.SearchHighlight=Be,exports.TocPanel=Ee,exports.VideoEmbed=on,exports.buildSystemPrompt=De,exports.createAILanguageModelProvider=X,exports.createCOSStorage=Vr,exports.createDeepSeekProvider=Me,exports.createLocalStorage=r.t,exports.createOSSStorage=Hr,exports.createOpenAICompatProvider=je,exports.createOpenAIProvider=Ne,exports.createQwenProvider=Pe,exports.createS3Storage=r.n,exports.createSlashCommandExtension=pr,exports.escapeHtml=e.t,exports.formatBytes=xt,exports.getAIProvider=Ae,exports.getBubbleMenuActions=br,exports.getDefaultSlashCommands=mr,exports.getDocAttachmentTotal=bt,exports.getEditorExtensions=gr,exports.getLocale=e.i,exports.getSearchEngine=yr,exports.getSearchState=Ve,exports.getStorageInfo=n.t,exports.getStorageProvider=n.n,exports.loadStorageConfig=n.r,exports.registerS3PreviewConfig=t.t,exports.sanitizeHtml=e.n,exports.sanitizeSvg=e.r,exports.setAIProvider=ke,exports.setConfirmProvider=kt,exports.setLocale=e.a,exports.setSearchEngine=vr,exports.setStorageProvider=n.i,exports.setToastProvider=ge,exports.signPreviewUrlHeaders=t.r,exports.startBrowserClipperReceiver=Br,exports.subscribeToast=_e,exports.t=e.o,exports.tf=e.s,exports.toast=J,exports.validateAttachmentFile=Ct;
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("./sanitize-CrbFQE46.cjs"),t=require("./signed-fetch-DiWXujJ1.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("@tiptap/suggestion");P=e.l(P,1);var F=null,ee=null;function I(){return ee||(typeof document>`u`?null:(F=document.createElement(`canvas`),ee=F.getContext(`2d`),ee))}var L=new Map;function te(e,t){let n=L.get(t);n||(n=new Map,L.set(t,n));let r=n.get(e);if(r!==void 0)return r;let i=I();return i?(i.font=t,r=i.measureText(e).width):r=R(e,t),n.set(e,r),r}function R(e,t){let n=parseFloat(t)||16,r=0;for(let t of e)ne(t.codePointAt(0)??0)?r+=n:t===` `?r+=n*.3:r+=n*.55;return r}function ne(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 re(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 z(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
|
+
`?i=`break`:e===` `||e===` `?i=`space`:ne(r)&&(i=re(r)?`punct`:`cjk`),n.push({text:e,width:te(e,t),type:i})}return n}function B(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 H(e,t,n=`16px system-ui`){let{maxWidth:r,lineHeight:i,maxLines:a,overflowWrap:o=`break-word`}=t,s=z(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=B(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=B(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=B(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=B(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 ie=typeof window<`u`&&window.matchMedia(`(prefers-reduced-motion: reduce)`).matches,ae=`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 oe={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>`},W=1;function se(){return`qt${W++}${Date.now().toString(36)}`}function G(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=G(`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=G(`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=se(),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=G(`div`,`qt-toast qt-${n}${i==null?``:` qt-truncate`}${a||o?` qt-rich`:``}`);s.setAttribute(`data-qt-id`,e);let c=G(`span`,`qt-icon`);c.innerHTML=oe[n],s.appendChild(c);let l=G(`div`,`qt-body`),u=G(`span`,`qt-msg`),d=H(t,{maxWidth:U(),lineHeight:1,maxLines:i},ae);if(d.lineCount<=1?ce(u,t):d.lines.forEach((e,t)=>{let n=G(`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=G(`div`,`qt-desc`);e.textContent=a,l.appendChild(e)}if(s.appendChild(l),o){let t=G(`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=G(`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(ie)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 K(){return pe||=new fe,pe}var me=Object.assign((e,t)=>K().show(e,t),{info:(e,t)=>K().info(e,t),success:(e,t)=>K().success(e,t),warn:(e,t)=>K().warn(e,t),error:(e,t)=>K().error(e,t),promise:(e,t,n)=>K().promise(e,t,n),dismiss:e=>K().dismiss(e),dismissAll:()=>K().dismissAll(),configure:e=>K().configure(e)}),q=new Set,he=null;function ge(e){he=e}function J(e,t=`error`,n){let r={persist:!0,...n};if(q.size>0){for(let n of q)n(e,t,r);return}if(he){he(e,t,r);return}t===`success`?me.success(e,r):t===`info`?me.info(e,r):me.error(e,r)}function _e(e){return q.add(e),()=>{q.delete(e)}}var ve=e.c({ImageUploadDialog:()=>ye}),ye=({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-32px)] max-w-[420px] max-h-[90vh] 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 be(e,t){return`${e.trim().toLowerCase().replace(/[^\p{L}\p{N}\s-]/gu,``).replace(/\s+/g,`-`).slice(0,40)||`heading`}-${t}`}function xe(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 Se(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 Ce(e,t){let n=[];for(let r of e)n.push(r),r.children.length>0&&!t.has(r.id)&&n.push(...Ce(r.children,t));return n}function Y(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 we(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 Te(e){if(e.isDestroyed)return null;try{return e.view.dom}catch{return null}}function Ee(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 De=84,Oe=3e3,ke=({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=Te(e);return t?Array.from(t.querySelectorAll(`h1,h2,h3,h4,h5,h6`)).map((e,t)=>(e.id||=be(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)+De,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=Te(e),n=t?we(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=Te(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,Oe)},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-De,behavior:`smooth`})}else window.scrollTo({top:window.scrollY+a-De,behavior:`smooth`})},[e,y]),T=(0,i.useMemo)(()=>xe(r),[r]),E=(0,i.useMemo)(()=>Se(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?Y(T,d.trim()):T,[T,O,d]),A=(0,i.useMemo)(()=>Ce(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?Ee(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 Ae(e,t){return{continue:`你是一个写作助手。请从下文尾部自然流畅地续写内容,保持风格一致。只输出续写的内容,不要加任何前缀说明。`,improve:`你是一个文字润色专家。请优化以下文本的表达,提升文采和流畅度,保持原意不变。只输出润色后的文本。`,shorter:`你是一个精简专家。请将以下文本精简,保留核心信息,删除冗余。只输出精简后的文本。`,longer:`你是一个内容扩写专家。请丰富以下文本的细节和层次,增加深度。只输出扩写后的文本。`,fix:`你是一个校对专家。请修正以下文本中的语法错误、错别字和标点问题。只输出修正后的文本。`,translate:`你是一个翻译专家。请将以下文本翻译为英文。只输出翻译后的文本。`,zap:t||`你是一个全能的 AI 写作助手。请根据用户的指令处理文本。`}[e]}var je=null;async function Me(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:Ae(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:Ae(e.mode,e.instruction),prompt:e.context,temperature:.7,maxOutputTokens:2048})).text}}}function X(e){je=e}function Ne(){if(!je)throw Error(`未配置 AI 服务。请调用 createAILanguageModelProvider() 创建并通过 setAIProvider() 注册。`);return je}function Pe(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(Ae(e.mode,e.instruction),e.context)},async generate(e){let t=Ae(e.mode,e.instruction),n=``;for await(let r of a(t,e.context))n+=r;return n}}}function Fe(e){return Pe({apiKey:e.apiKey,baseURL:e.baseURL||`https://api.deepseek.com/v1`,model:e.model||`deepseek-v4-flash`,headers:e.headers})}function Ie(e){return Pe({apiKey:e.apiKey,baseURL:e.baseURL||`https://api.openai.com/v1`,model:e.model||`gpt-5.6-luna`,headers:e.headers})}function Le(e){return Pe({apiKey:e.apiKey,baseURL:e.baseURL||`https://dashscope.aliyuncs.com/compatible-mode/v1`,model:e.model||`qwen3.7-plus`,headers:e.headers})}var Re={keyword:``,caseSensitive:!1,wholeWord:!1,matches:[],currentIndex:-1},Z=new f.PluginKey(`search-highlight`);function ze(e){return e.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`)}function Be(e,t){let{keyword:n,caseSensitive:r,wholeWord:i}=t;if(!n)return[];let a=r?`g`:`gi`,o=i?`\\b${ze(n)}\\b`:ze(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 Ve(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 He(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 Ue=d.Extension.create({name:`searchHighlight`,addProseMirrorPlugins(){return[new f.Plugin({key:Z,state:{init:()=>Re,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=Be(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?Ve(e.doc,t):p.DecorationSet.empty}}})]},addCommands(){return{setSearch:(e,t={})=>({state:n,dispatch:r,view:i})=>{let a=Z.getState(n)||Re,o={keyword:e,caseSensitive:t.caseSensitive??a.caseSensitive,wholeWord:t.wholeWord??a.wholeWord,matches:[],currentIndex:-1};return o.matches=Be(n.doc,o),o.currentIndex=o.matches.length>0?0:-1,r&&(r(n.tr.setMeta(Z,o)),i&&He(i,o)),!0},nextMatch:()=>({state:e,dispatch:t,view:n})=>{let r=Z.getState(e)||Re;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&&He(n,{...r,currentIndex:i})),!0},prevMatch:()=>({state:e,dispatch:t,view:n})=>{let r=Z.getState(e)||Re;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&&He(n,{...r,currentIndex:i})),!0},clearSearch:()=>({state:e,dispatch:t})=>(t&&t(e.tr.setMeta(Z,Re)),!0)}}});function We(e){let t=e.state;return Z.getState(t)||Re}var Ge=({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 We(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 Ke=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`})]}),qe=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`})]}),Je=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`})]}),Ye=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`})]}),Xe=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`})]}),Ze=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`})]}),Qe=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`})]}),$e=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`})]}),et=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`})]}),tt=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`})]}),nt=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`})]}),rt=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`})]}),it=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 at(e){if(e){if(e.startsWith(`blob:`)){URL.revokeObjectURL(e);return}try{await n.n().remove(e)}catch(e){console.warn(`删除存储资源失败:`,e)}}}var ot=3e4,st=new Set([`image`,`attachmentEmbed`,`audioEmbed`,`videoEmbed`]),ct=new WeakMap;function lt(e){let t=new Set;return e.state.doc.descendants(e=>{if(st.has(e.type.name)){let n=e.attrs.src;n&&t.add(n)}return!0}),t}function ut(e){let t=ct.get(e);return t||(t={timers:new Map,onTransaction:()=>{},listening:!1},ct.set(e,t)),t}function dt(e,t){let n=[...new Set(t.filter(Boolean))];if(n.length===0)return;let r=ut(e);r.listening||=(r.onTransaction=()=>{if(r.timers.size===0)return;let t=lt(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(()=>{lt(e).has(t)||at(t),r.timers.delete(t)},ot);r.timers.set(t,n)}}function ft(e){let t=ct.get(e);if(t){if(t.listening&&=(e.off(`transaction`,t.onTransaction),!1),t.timers.size>0){let n=lt(e);for(let[e,r]of t.timers)clearTimeout(r),n.has(e)||at(e);t.timers.clear()}ct.delete(e)}}var pt=[{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:`⚡`}],mt=new Set([`image`,`attachmentEmbed`,`audioEmbed`,`videoEmbed`]),ht={image:`editor.ai.nodeImage`,attachmentEmbed:`editor.ai.nodeAttachment`,videoEmbed:`editor.ai.nodeVideo`,audioEmbed:`editor.ai.nodeAudio`};function gt(e,t){return e.storage.qingwuUI?.parseMd?.(e.schema,t)||null}function _t(e,t,n){let r=[];return e.state.doc.nodesBetween(t,n,e=>{if(mt.has(e.type.name)){let t=e.attrs.src;t&&r.push({type:e.type.name,src:t})}return!0}),r}function vt(e){let t=new Set;return e.state.doc.descendants(e=>{if(mt.has(e.type.name)){let n=e.attrs.src;n&&t.add(n)}return!0}),t}function yt(e,t){let n=gt(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 bt(e,t,n,r){let i=gt(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 xt({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=Ne(),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(_t(t,r.from,r.to).map(e=>e.src));e===`replaceAll`?yt(t,n):bt(t,n,`replace`,_.current);let a=vt(t);dt(t,[...i].filter(e=>!a.has(e)))},[t]),w=(0,i.useCallback)(e=>{if(e===`below`){bt(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=_t(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)(nt,{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)(it,{})})]}),(0,a.jsx)(`div`,{className:`grid grid-cols-[repeat(auto-fit,minmax(64px,1fr))] gap-1.5 p-2 shrink-0`,children:pt.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(ht[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 St=new Set([`attachmentEmbed`,`videoEmbed`,`audioEmbed`,`image`]);function Ct(e){let t=0;return e.descendants(e=>{St.has(e.type.name)&&(t+=Number(e.attrs?.size)||0)}),t}function wt(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 Tt(e){return(e?.storage)?.qingwuUI?.limits}function Et(e,t,n){let{maxAttachmentSize:r,maxTotalAttachmentSize:i}=n;if(r&&t.size>r)return`单文件大小不能超过 ${wt(r)}(当前 ${wt(t.size)})`;if(i){let n=Ct(e)+t.size;if(n>i)return`附件总大小不能超过 ${wt(i)}(当前合计 ${wt(n)})`}return null}var Dt=!1,Ot=null,kt=5e3;function At(){return Dt}function $(e){Dt=e,Ot&&=(clearTimeout(Ot),null),e&&(Ot=setTimeout(()=>{Dt=!1,Ot=null},kt))}var jt=null;function Mt(e){jt=e}function Nt(){return jt}var Pt=300;function Ft({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=Nt();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<Pt&&await new Promise(e=>setTimeout(e,Pt-t)),d(!1),c()}},disabled:l,children:r})]})]})}),document.body)}function It(e){return/^(\.\.?\/|[a-zA-Z]:\\|file:\/\/)/.test(e)?!0:!(/^[a-z]+:\/\//i.test(e)||e.startsWith(`/`)||e.startsWith(`data:`)||e.startsWith(`blob:`))}function Lt({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-DiWXujJ1.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||It(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:()=>{At()||($(!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:It(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:()=>{At()||($(!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)(Ft,{open:m,title:`确认删除图片`,message:F?`该图片无法在当前环境加载,仅从编辑器中移除该图片节点,不影响存储文件。`:`此操作将同时删除对象存储中的文件,不可撤销。`,onCancel:()=>{$(!1),h(!1)},onConfirm:async()=>{if(!F)try{await at(g)}catch{}$(!1),await new Promise(e=>setTimeout(e,300)),n()}})]})}var Rt=(0,i.lazy)(()=>import(`@file-viewer/react`)),zt=new Set,Bt={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}},Vt={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`},Ht={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 Ut(e){return e?e<1024?`${e} B`:e<1048576?`${(e/1024).toFixed(1)} KB`:`${(e/1048576).toFixed(1)} MB`:``}function Wt(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 Gt(e){return e.split(`.`).pop()?.toLowerCase()||``}function Kt(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 qt(e){return!!e&&!e.startsWith(`file:`)}function Jt(e){return btoa(encodeURIComponent(e)).replace(/\+/g,`-`).replace(/\//g,`_`).replace(/=+$/,``)}async function Yt(e,t){try{let n=Jt(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 Xt(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 Zt({node:n,deleteNode:r,selected:o,editor:s}){let l=s?.isEditable??!0,u=n.attrs.src||``,[d,f]=(0,i.useState)(()=>zt.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`),[te,R]=(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`)),V=n.attrs.size||0,H=Gt(B),ie=!z;(0,i.useEffect)(()=>{if(!d){R(void 0),re(!1);return}let e=Vt[H];if(!e){R(void 0),re(!1);return}let t=!0;return R(void 0),re(!1),Ht[e]().then(e=>{t&&R(e)}).catch(n=>{console.error(`[attachment] renderer "${e}" load failed:`,n),t&&re(!0)}),()=>{t=!1}},[d,H]);let ae=(0,i.useMemo)(()=>({...Bt,renderers:te?[te]:[],rendererMode:`replace`}),[te]),U=(0,i.useCallback)(e=>{f(t=>{let n=typeof e==`function`?e(t):e;return z&&(n?zt.add(z):zt.delete(z)),n})},[z]);(0,i.useEffect)(()=>{f(z?zt.has(z):!1)},[z]);let oe=(0,i.useCallback)(()=>{k.current=!0,U(!0),window.setTimeout(()=>{window.scrollTo(0,O.current),A.current&&(A.current.scrollTop=j.current),k.current&&U(!0),k.current=!1},0)},[U]),W=(0,i.useCallback)(async()=>{I===`web`?(L(`none`),document.body.style.overflow=``,oe()):(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,oe]),G=(0,i.useCallback)(()=>{I===`none`&&(k.current||U(e=>!e))},[I]);(0,i.useEffect)(()=>{let e=()=>{document.fullscreenElement||(I===`native`&&L(`none`),oe())},t=e=>{e.key===`Escape`&&I===`web`&&(L(`none`),document.body.style.overflow=``,oe())};return document.addEventListener(`fullscreenchange`,e),window.addEventListener(`keydown`,t),()=>{document.removeEventListener(`fullscreenchange`,e),window.removeEventListener(`keydown`,t)}},[I,oe]),(0,i.useEffect)(()=>{let e=e=>{if(!(e.key!==`Backspace`&&e.key!==`Delete`)&&l&&o&&!At()){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||!qt(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 Yt(z,e.signal)),!i&&!r)try{let n=await t.n(z);n&&(i=await Yt(n,e.signal)||await Xt(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 Xt(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 Xt(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 ce=(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:ie?(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`})]}):Wt(B)}),(0,a.jsxs)(`div`,{className:`att-meta`,children:[(0,a.jsx)(`span`,{className:`att-name`,children:B}),V>0&&(0,a.jsx)(`span`,{className:`att-size`,children:Ut(V)})]})]}),(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&&Kt(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:ce,disabled:x||ie,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||At()||($(!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?te?(0,a.jsx)(Rt,{buffer:p||void 0,url:h||z,name:B,filename:B,type:H,size:V||p?.byteLength||0,options:ae},`${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)(Ft,{open:M,title:`确认删除附件`,message:ie?`此操作将删除该附件节点,不可撤销。`:`此操作将同时删除对象存储中的文件(${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(at(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 at(z),$(!1),await new Promise(e=>setTimeout(e,300)),r()}catch{$(!1)}}})]})}var Qt=d.Node.create({name:`attachmentEmbed`,group:`block`,atom:!0,inline:!1,addNodeView(){return(0,c.ReactNodeViewRenderer)(Zt)},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 $t({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:()=>{At()||($(!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)(Ft,{open:l,title:`确认删除音频`,message:`此操作将同时删除对象存储中的文件(${s}),不可撤销。`,onCancel:()=>{$(!1),u(!1)},onConfirm:async()=>{try{await at(o)}catch{}$(!1),await new Promise(e=>setTimeout(e,300)),n()}})]})}function en(e){return/\.(mp3|wav|ogg|flac|aac|m4a|wma|opus)(\?|$)/i.test(e)||/\/.*\.(mp3|wav|ogg|flac)/i.test(e)}var tn=d.Node.create({name:`audioEmbed`,group:`block`,atom:!0,inline:!1,addNodeView(){return(0,c.ReactNodeViewRenderer)($t)},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(` `)||!en(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 nn(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 rn(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 an({node:e,deleteNode:t,editor:n}){let r=e.attrs.src||``,o=e.attrs.source||`unknown`,s=o===`unknown`?nn(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)(Ft,{open:l,title:`确认删除视频`,message:`此操作将同时删除对象存储中的文件,不可撤销。`,onCancel:()=>{$(!1),u(!1)},onConfirm:async()=>{try{await at(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-DiWXujJ1.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=rn(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:()=>{At()||($(!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:()=>{At()||($(!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 on(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 sn(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 cn(e){let t=e.match(/explore\/([a-zA-Z0-9]+)/);return t?t[1]:e}var ln=d.Node.create({name:`videoEmbed`,group:`block`,atom:!0,inline:!1,addNodeView(){return(0,c.ReactNodeViewRenderer)(an)},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=on(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:on(n)}}},{tag:`div[data-bilibili]`},{tag:`div[data-xiaohongshu]`}]},renderHTML({HTMLAttributes:e}){let t=e.src||``,n=on(t);if(n===`bilibili`){let e=sn(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 cn(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=on(e.src);return t().insertContent({type:this.name,attrs:{...e,source:n}}).focus().run()}}}}),un=null;async function dn(e){un||=await import(`beautiful-mermaid`);let t=un.renderMermaidSVG;return t(e)}var fn=[{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`}],pn={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`},mn={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 hn({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=(0,i.useRef)(null),F=(0,i.useRef)(null),ee=(0,i.useRef)(null),I=(0,i.useRef)(null),L=(0,i.useRef)(null),te=(0,i.useRef)(null),R=t.attrs.language||``,ne=fn.find(e=>e.value===(mn[R]??R)),re=R===`mermaid`,z=(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]),B=(0,i.useCallback)(()=>{l&&(At()||(te.current=z(),window.getSelection()?.removeAllRanges(),$(!0),D(!0)))},[z,l]),V=(0,i.useMemo)(()=>{let e=w.trim().toLowerCase();return e?fn.filter(t=>t.label.toLowerCase().includes(e)||t.value.toLowerCase().includes(e)):fn},[w]);(0,i.useEffect)(()=>{(L.current?.parentElement?.querySelector(`.cb-code-area`))?.classList.toggle(`cb-code-area--collapsed`,m)},[m]);let H=(0,i.useCallback)(()=>{let e=ee.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=fn.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(``),H();let e=setTimeout(()=>I.current?.focus(),50);return window.addEventListener(`resize`,H),window.addEventListener(`scroll`,H,!0),()=>{clearTimeout(e),window.removeEventListener(`resize`,H),window.removeEventListener(`scroll`,H,!0)}},[g,H]),(0,i.useEffect)(()=>{if(!g)return;let e=e=>{let t=e.target;t&&(ee.current?.contains(t)||F.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&&!At()){if(e.preventDefault(),e.stopPropagation(),r){let{from:e,to:t}=r.state.selection;te.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 ie=(0,i.useCallback)(e=>{n({language:e||null}),_(!1)},[n]),ae=(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]),U=(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]),oe=(0,i.useCallback)(()=>{let e=pn[R]||`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,R]),W=(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 dn(n));k(r)}catch(e){j(e instanceof Error?e.message:`Mermaid 渲染失败`)}finally{N(!1)}},[t.textContent,O,M]),se=(0,a.jsxs)(a.Fragment,{children:[ne?ne.deviconClass?(0,a.jsx)(`i`,{className:`${ne.deviconClass} colored cb-lang-icon`,style:{color:ne.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:ne?.label||`自动`})]});return(0,a.jsxs)(`div`,{ref:L,className:`cb-react-shell group/cb`,style:{display:`contents`},children:[(0,a.jsxs)(`div`,{className:`cb-header`,contentEditable:!1,onMouseDown:e=>e.stopPropagation(),children:[(0,a.jsx)(`div`,{className:`cb-lang-wrap`,ref:P,contentEditable:!1,children:d?(0,a.jsx)(`span`,{className:`cb-lang-trigger cb-lang-trigger--static`,children:se}):(0,a.jsxs)(`button`,{ref:ee,type:`button`,className:`cb-lang-trigger`,onClick:()=>_(!g),children:[se,(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`})})]})}),l&&g&&(0,u.createPortal)((0,a.jsxs)(`div`,{ref:F,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:I,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${R?``:` cb-lang-option--active`}`,onClick:()=>ie(``),children:[(0,a.jsx)(`span`,{className:`cb-lang-icon cb-lang-icon--auto`,children:`?`}),(0,a.jsx)(`span`,{children:`自动检测`})]}),V.map(e=>(0,a.jsxs)(`button`,{type:`button`,className:`cb-lang-option${R===e.value?` cb-lang-option--active`:``}`,onClick:()=>ie(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)),V.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:U,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:oe,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:ae,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:B,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`})})})]}),re&&(0,a.jsx)(`button`,{type:`button`,className:`cb-btn cb-btn--diagram`,onClick:W,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.jsx)(`div`,{className:`cb-diagram-svg`,dangerouslySetInnerHTML:{__html:O}})]}),(0,a.jsx)(Ft,{open:E,title:`确认删除代码块`,message:`此操作不可撤销。`,onCancel:()=>{$(!1),D(!1)},onConfirm:async()=>{await new Promise(e=>setTimeout(e,300)),$(!1),s()}})]})}var gn=[{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`}],_n=(0,N.createLowlight)(N.common);_n.register({dockerfile:M.default}),_n.registerAlias(`xml`,[`vue`,`html`]),_n.registerAlias(`javascript`,[`react`,`jsx`]),_n.registerAlias(`typescript`,[`tsx`]);function vn(e){return e?e.split(`
|
|
4
|
+
`):[``]}function yn(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 bn(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 xn(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
|
+
`)&&(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 Sn=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-line-numbers`,d.contentEditable=`false`,d.setAttribute(`aria-hidden`,`true`);let f=document.createElement(`pre`);f.className=`cb-code-pre`;let p=document.createElement(`code`);f.appendChild(p);let m=document.createElement(`div`);m.className=`cb-code-mirror`,m.contentEditable=`false`,m.setAttribute(`aria-hidden`,`true`),u.appendChild(d),u.appendChild(f),u.appendChild(m),s.appendChild(u);let h=vn(t.textContent);yn(d,h.length),bn(m,h);let g=new c.ReactRenderer(hn,{editor:n,props:{node:t,editor:n,getPos:r,updateAttributes:a,deleteNode:o,selected:!1}});l.appendChild(g.element);let _=e=>{let t=vn(e.textContent);yn(d,t.length),bn(m,t),requestAnimationFrame(()=>xn(f,m,d))};requestAnimationFrame(()=>xn(f,m,d));let v=new ResizeObserver(()=>xn(f,m,d));return v.observe(f),document.fonts?.ready?.then(()=>xn(f,m,d)),{dom:s,contentDOM:p,update(e){return e.type!==t.type||!e.sameMarkup(i)?!1:(i=e,g.updateProps({node:e,editor:n,getPos:r,updateAttributes:a,deleteNode:o,selected:s.classList.contains(`ProseMirror-selectednode`)}),_(e),!0)},selectNode(){s.classList.add(`ProseMirror-selectednode`),g.updateProps({node:i,editor:n,getPos:r,updateAttributes:a,deleteNode:o,selected:!0})},deselectNode(){s.classList.remove(`ProseMirror-selectednode`),g.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!p.contains(e.target)},destroy(){v.disconnect(),g.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
|
+
`);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:_n});function Cn(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 wn=/\.(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,Tn=/^(?:mailto:|tel:|javascript:|about:|data:|blob:)/i;function En(e){if(!e)return!1;let t=e.trim();return!(!t||/^(?:https?:)?\/\//i.test(t)||Tn.test(t)||t.startsWith(`#`))}function Dn(e){return wn.test(e)}function On(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 kn(e){let t=On(e),n=t.split(`/`).filter(Boolean);return(n[n.length-1]||t).toLowerCase()}function An(){return typeof window>`u`||window.isSecureContext===!1?!1:typeof window.showDirectoryPicker==`function`}async function jn(){if(!An())return null;try{return await window.showDirectoryPicker.call(window,{mode:`read`})??null}catch{return null}}function Mn(){return typeof window>`u`||window.isSecureContext===!1?!1:typeof window.showOpenFilePicker==`function`}async function Nn(){if(!Mn())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 Pn(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 Fn(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 In(e,t){let n=On(t).split(`/`).filter(Boolean);if(n.length===0)return{file:null};let r;for(let t=0;t<n.length;t++){let i=await Pn(e,n.slice(t));if(i.file)return i;i.readError&&(r=i.readError)}let i=await Fn(e,n[n.length-1]);return i.file||i.readError?i:{file:null,readError:r}}var Ln={image:`image`,videoEmbed:`video`,audioEmbed:`audio`,attachmentEmbed:`attachment`};function Rn(e,t){let n=new Set,r=[];return e.descendants(e=>{let i=Ln[e.type?.name];if(i){let a=e.attrs?.src,o=`node:${a}`;typeof a==`string`&&En(a)&&!n.has(o)&&!t?.(a)&&(n.add(o),r.push({src:a,normalized:On(a),basename:kn(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`&&En(e)&&Dn(e)&&!n.has(a)&&!t?.(e)&&(n.add(a),r.push({src:e,normalized:On(e),basename:kn(e),kind:`attachment`,isLink:!0}))}}),r}function zn(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=>Dn(e)&&En(e)&&!n?.(e))}function Bn(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 Vn(e){let t=e.name.split(`.`).pop()?.toLowerCase()||``;return t===`md`||t===`markdown`}async function Hn(e,t,n,r){let i=n??e.state.selection.from,a=r?Tt(r):void 0,o=r?.storage?.qingwuUI,s=await new Promise(e=>{o?.chooseMd?o.chooseMd(t.name,e):Cn(t.name).then(e)});if(s===null)return;if(s===`attach`){let n=a?Et(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(`
|
|
7
|
+
`),u=[];for(let t of l)t.trim()?u.push(e.state.schema.nodes.paragraph.create(null,e.state.schema.text(t))):u.push(e.state.schema.nodes.paragraph.create());if(u.length>0){let{Fragment:t}=await import(`@tiptap/pm/model`);e.dispatch(e.state.tr.insert(i,t.from(u)))}}function Un(e,t,n){switch(Bn(t)){case`image`:return e.nodes.image?.create({src:n,alt:t.name});case`video`:return e.nodes.videoEmbed?.create({src:n,source:`direct`,name:t.name});case`audio`:return e.nodes.audioEmbed?.create({src:n,name:t.name});default:{if(e.nodes.attachmentEmbed)return e.nodes.attachmentEmbed.create({src:n,name:t.name,size:t.size,type:t.type});let r=e.marks.link?.create({href:n});return r?e.text(`📎 ${t.name}`,[r]):null}}}async function Wn(e,t,r){let i;try{i=n.n()}catch{return null}try{let n=await i.upload(t,`editor`);URL.revokeObjectURL(r);let a=!1;return e.state.doc.descendants((t,i)=>t.attrs?.src===r?(e.dispatch(e.state.tr.setNodeMarkup(i,void 0,{...t.attrs,src:n})),a=!0,!1):!0),a?n:null}catch(e){return console.error(`${t.type} upload failed:`,e),URL.revokeObjectURL(r),null}}async function Gn(e,t,n,r){let i=r?Tt(r):void 0,a=i?Et(e.state.doc,t,i):null;if(a){J(a);return}let o=URL.createObjectURL(t),s=Un(e.state.schema,t,o);if(!s)return;let c=n??e.state.selection.from;try{e.dispatch(e.state.tr.insert(c,s))}catch{return}await Wn(e,t,o)}var Kn=d.Extension.create({name:`imageUpload`,addOptions(){return{maxAttachmentSize:0,maxTotalAttachmentSize:0}},addProseMirrorPlugins(){let e=this.editor;return[new f.Plugin({key:new f.PluginKey(`imageUpload`),props:{handleDrop(t,n){let r=n.dataTransfer?.files;if(!r||r.length===0)return!1;n.preventDefault();let i=t.posAtCoords({left:n.clientX,top:n.clientY});for(let n of Array.from(r))Vn(n)?Hn(t,n,i?.pos,e):Gn(t,n,i?.pos,e);return!0},handlePaste(t,r){let i=r.clipboardData?.items;if(!i)return!1;let a=r.clipboardData?.getData(`text/plain`)||``;if((r.clipboardData?.files?.length??0)>0&&zn(a,void 0,n.i()))return!1;for(let n of Array.from(i)){if(n.type.startsWith(`image/`)||n.type.startsWith(`video/`)||n.type.startsWith(`audio/`)){r.preventDefault();let i=n.getAsFile();return i&&Bn(i)!==`file`&&Gn(t,i,void 0,e),!0}if(n.kind===`file`){let i=n.getAsFile();if(i&&Vn(i))return r.preventDefault(),Hn(t,i,void 0,e),!0}}return!1}}})]}}),qn=100,Jn=d.Extension.create({name:`imeCommitSpaceGuard`,addProseMirrorPlugins(){let e=0;return[new f.Plugin({key:new f.PluginKey(`imeCommitSpaceGuard`),props:{handleDOMEvents:{compositionend(){return e=performance.now(),!1},input(t,n){return n.isComposing&&(e=performance.now()),!1},beforeinput(t,n){let r=n;return r.inputType!==`insertText`||r.data!==` `||r.isComposing||performance.now()-e>qn?!1:(r.preventDefault(),!0)}}}})]}}),Yn=/\.(png|jpe?g|gif|webp|bmp|svg|avif)(\?|#|$)/i,Xn=/\.(mp4|m3u8|webm|ogg|flv|mkv|mov|avi|wmv|ts|m4v|3gp|f4v|rmvb)(\?|#|$)/i,Zn=/\.(mp3|wav|ogg|flac|aac|m4a|wma|opus)(\?|#|$)/i;function Qn(e){return e.replace(/&/g,`&`).replace(/"/g,`"`).replace(/</g,`<`).replace(/>/g,`>`)}function $n(e){let t=e.trim().replace(/\\/g,`/`);return t.split(`/`).pop()||t}function er(e,t){let n=e.src.slice(e.pos),r=/^!\[\[([^\]|]+)(?:\|([^\]]+))?\]\]/.exec(n),i=!0;if(r||(r=/^\[\[([^\]|]+)(?:\|([^\]]+))?\]\]/.exec(n),i=!1),!r)return!1;let a=r[1].trim(),o=r[2]?.trim();if(!t){let t=o||$n(a);if(i){let n=``;if(Yn.test(a)||/^data:image\//i.test(a))n=`<img src="${Qn(a)}" alt="${Qn(t)}">`;else if(Xn.test(a)||/^data:video\//i.test(a))n=`<div data-video-embed src="${Qn(a)}"></div>`;else if(Zn.test(a)||/^data:audio\//i.test(a))n=`<audio src="${Qn(a)}"></audio>`;else{let n=e.push(`link_open`,`a`,1);n.attrs=[[`href`,a]];let i=e.push(`text`,``,0);return i.content=t,e.push(`link_close`,`a`,-1),e.pos+=r[0].length,!0}let i=e.push(`html_inline`,``,0);i.content=n}else{let n=e.push(`link_open`,`a`,1);n.attrs=[[`href`,a]];let r=e.push(`text`,``,0);r.content=t,e.push(`link_close`,`a`,-1)}}return e.pos+=r[0].length,!0}var tr=d.Extension.create({name:`obsidianMarkdown`,addStorage(){return{markdown:{parse:{setup(e){e.__obsidianReg||(e.__obsidianReg=!0,e.inline.ruler.before(`link`,`obsidian_embed`,er))}}}}}}),nr=d.Extension.create({name:`qingwuUI`,addStorage(){return{}}});function rr(e,t){return new Promise(n=>{if(typeof Image!=`function`)return n(!0);let r=new Image,i=!1,a=setTimeout(()=>o(!1),t),o=e=>{i||(i=!0,clearTimeout(a),r.onload=null,r.onerror=null,n(e))};r.onload=()=>o(!0),r.onerror=()=>o(!1),r.src=e})}async function ir(e,n=8e3){if(await rr(e,n))return!0;try{let r=await t.r(e);if(!r)return!1;let i=await fetch(e,{headers:r});if(!i.ok)return!1;let a=URL.createObjectURL(await i.blob()),o=await rr(a,n);return URL.revokeObjectURL(a),o}catch{return!1}}function ar(){return{uploaded:0,sessionOnly:0,limitRejected:0,renderFailed:0,missing:[],readFailed:[]}}function or(e,t){e.uploaded+=t.uploaded,e.sessionOnly+=t.sessionOnly,e.limitRejected+=t.limitRejected,e.renderFailed+=t.renderFailed,e.missing.push(...t.missing),e.readFailed.push(...t.readFailed)}function sr(e,t,n,r){let{state:i}=e,a=[];if(i.doc.descendants((e,n)=>{e.attrs?.src===t&&a.push(n)}),a.length===0)return!1;let o=i.tr;for(let e of a){let t=i.doc.nodeAt(e);t&&o.setNodeMarkup(e,void 0,{...t.attrs,src:n,size:r})}return e.dispatch(o),!0}function cr(e,t,n){let{state:r}=e,i=r.schema.marks.link;if(!i)return!1;let a=[];if(r.doc.descendants((e,n)=>{if(e.isText)for(let r of e.marks)r.type===i&&r.attrs.href===t&&a.push({from:n,to:n+e.nodeSize,mark:r})}),a.length===0)return!1;let o=r.tr;for(let{from:e,to:t,mark:r}of a)o=o.removeMark(e,t,i),o=o.addMark(e,t,i.create({...r.attrs,href:n}));return e.dispatch(o),!0}function lr(e){let t=new Map;for(let n of e){let e=t.get(n.normalized);e?e.push(n):t.set(n.normalized,[n])}return Array.from(t.values())}async function ur(e,t,r,i){if(r.length===0)return`sessionOnly`;let a=r[0],o=Tt(t);if(o){let t=Et(e.state.doc,i,o);if(t)return J(`${a.basename}:${t}`,`error`),`limitRejected`}let s=r.filter(e=>!e.isLink),c=r.filter(e=>e.isLink);if(s.length===0)try{let t=await n.n().upload(i,`editor`),r=!1;for(let n of c)cr(e,n.src,t)&&(r=!0);return r?`uploaded`:`sessionOnly`}catch(e){return console.error(`本地附件 ${a.basename} 上传失败:`,e),J(`「${a.basename}」上传失败`,`error`),`sessionOnly`}let l=URL.createObjectURL(i),u=!1;for(let t of s)sr(e,t.src,l,i.size)&&(u=!0);let d;try{d=await n.n().upload(i,`editor`)}catch(e){return console.error(`本地文件 ${a.basename} 上传失败:`,e),J(`「${a.basename}」上传失败`,`error`),URL.revokeObjectURL(l),`sessionOnly`}URL.revokeObjectURL(l),u&&sr(e,l,d,i.size);for(let t of c)cr(e,t.src,d);return!u&&c.length===0?`sessionOnly`:u&&r.some(e=>e.kind===`image`)?await ir(d)?`uploaded`:`renderFailed`:`uploaded`}function dr(e,t){let n=[],r=[];for(let i of lr(e)){let e=i[0],a=t.get(e.basename);a?(n.push({refs:i,file:a}),t.delete(e.basename)):r.push(...i)}return{matched:n,unmatched:r}}async function fr(e,t,n,r){let i=ar();for(let a of lr(n)){let n=a[0],{file:o,readError:s}=await In(r,n.src);if(!o){s?(console.warn(`本地文件「${n.basename}」在所选文件夹中找到但读取失败:`,s),i.readFailed.push(n)):(console.warn(`本地文件「${n.basename}」未在所选文件夹「${r.name}」中找到`),i.missing.push(n));continue}let c=await ur(e,t,a,o);i[c]++}return i}function pr(e){let t=e.map(e=>e.basename);return t.length<=3?t.join(`、`):`${t.slice(0,3).join(`、`)} 等 ${t.length} 个文件`}function mr(e){let t=[];if(e.uploaded>0&&t.push(`${e.uploaded} 个已上传至存储`),e.sessionOnly>0&&t.push(`${e.sessionOnly} 个仅本次会话可见(未配置存储或上传失败)`),e.limitRejected>0&&t.push(`${e.limitRejected} 个超出大小限制`),e.renderFailed>0&&t.push(`${e.renderFailed} 个上传成功但页面渲染失败(存储 URL 无法在浏览器访问/解码)`),e.readFailed.length>0&&t.push(`${e.readFailed.length} 个找到但读取失败:${pr(e.readFailed)}(若在 OneDrive / WPS 云盘等同步目录,请右键文件选择「始终保留在此设备」后重试)`),e.missing.length>0&&t.push(`${e.missing.length} 个未能获取:${pr(e.missing)}(可把文件直接拖进编辑器上传)`),t.length===0)return;let n=e.uploaded>0&&e.renderFailed===0&&e.missing.length===0&&e.readFailed.length===0;J(`本地文件解析完成:${t.join(`;`)}`,n?`success`:`info`)}function hr(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-md w-full mx-4 border border-default-200 dark:border-zinc-700 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=`粘贴内容中包含本地文件`;let a=document.createElement(`div`);a.className=`text-xs text-default-500 dark:text-zinc-400 mb-4 whitespace-pre-line leading-relaxed`,a.textContent=`检测到 ${e} 个本地图片/附件使用相对路径,粘贴时文件本体没有跟过来。\n浏览器不能直接读取你的磁盘。请选择一个包含这些文件的文件夹(推荐 Obsidian 库根目录,它会连同子目录一起查找),编辑器读取后会上传到你的存储。
|
|
8
|
+
也可以选择稍后把文件直接拖进编辑器。`;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(`cancel`)};n.addEventListener(`mousedown`,e=>{e.target===n&&s(`cancel`)});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 text-default-700 dark:text-zinc-300 dark:border-zinc-600 dark:hover:bg-zinc-700`,l.textContent=`稍后处理`,l.addEventListener(`click`,()=>s(`cancel`));let u=document.createElement(`button`);u.type=`button`,u.className=`px-3 py-1.5 text-xs rounded-lg bg-blue-500 hover:bg-blue-600 text-white`,u.textContent=`选择文件夹…`,u.addEventListener(`click`,()=>s(`pick`)),o.append(l,u),r.append(i,a,o),n.appendChild(r),document.addEventListener(`keydown`,c),document.body.appendChild(n)})}function gr(e){let t=document.createElement(`div`);t.className=`fixed inset-0 z-[10001] flex items-center justify-center bg-black/40 backdrop-blur-sm select-none`;let n=document.createElement(`div`);n.className=`bg-white dark:bg-zinc-800 rounded-xl p-6 shadow-xl max-w-md w-full mx-4 border border-default-200 dark:border-zinc-700`;let r=document.createElement(`div`);r.className=`text-sm font-medium text-default-800 dark:text-zinc-100 mb-2`,r.textContent=`粘贴内容中包含本地文件`;let i=document.createElement(`div`);i.className=`text-xs text-default-500 dark:text-zinc-400 mb-4 whitespace-pre-line leading-relaxed`,i.textContent=`检测到 ${e} 个本地图片/附件使用相对路径,粘贴时文件本体没有跟过来。\n当前浏览器不支持读取本地文件夹(需要 Chrome / Edge)。请把对应的图片或文件直接拖进编辑器,会自动完成上传。`;let a=document.createElement(`div`);a.className=`flex justify-end`;let o=()=>{document.removeEventListener(`keydown`,s),t.remove()},s=e=>{e.key===`Escape`&&o()};t.addEventListener(`mousedown`,e=>{e.target===t&&o()});let c=document.createElement(`button`);c.type=`button`,c.className=`px-3 py-1.5 text-xs rounded-lg bg-blue-500 hover:bg-blue-600 text-white`,c.textContent=`知道了`,c.addEventListener(`click`,o),a.append(c),n.append(r,i,a),t.appendChild(n),document.addEventListener(`keydown`,s),document.body.appendChild(t)}function _r(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-md w-full mx-4 border border-default-200 dark:border-zinc-700 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=`选择文件直接上传`;let a=document.createElement(`div`);a.className=`text-xs text-default-500 dark:text-zinc-400 mb-4 whitespace-pre-line leading-relaxed`,a.textContent=`还有 ${e.length} 个本地文件无法从所选文件夹读取:${e.join(`、`)}。\n点击「选择文件…」后在系统对话框里选中这些文件(可多选),将直接上传到存储。若它们位于云同步目录(OneDrive / 绿联云等),选中后会自动取回本地内容。`;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(`cancel`)};n.addEventListener(`mousedown`,e=>{e.target===n&&s(`cancel`)});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 text-default-700 dark:text-zinc-300 dark:border-zinc-600 dark:hover:bg-zinc-700`,l.textContent=`稍后处理`,l.addEventListener(`click`,()=>s(`cancel`));let u=document.createElement(`button`);u.type=`button`,u.className=`px-3 py-1.5 text-xs rounded-lg bg-blue-500 hover:bg-blue-600 text-white`,u.textContent=`选择文件…`,u.addEventListener(`click`,()=>s(`pick`)),o.append(l,u),r.append(i,a,o),n.appendChild(r),document.addEventListener(`keydown`,c),document.body.appendChild(n)})}async function vr(e,t,n){let r=ar(),i=lr(n),a=await Nn();if(!a){for(let e of i)r.missing.push(e[0]);return r}let o=new Map(a.map(e=>[e.name.toLowerCase(),e]));for(let n of i){let i=n[0],a=o.get(i.basename);if(!a){r.missing.push(i);continue}o.delete(i.basename);let s=await ur(e,t,n,a);r[s]++}return r}var yr=d.Extension.create({name:`relativeMedia`,addStorage(){return{clipboardFiles:new Map,pausedUntilPaste:!1}},addProseMirrorPlugins(){let e=this.editor,t=this.storage,r=!1,i=null,a=async(n,r)=>{let a=e.view,o=ar(),{matched:s,unmatched:c}=dr(n,t.clipboardFiles);for(let{refs:t,file:n}of s){let r=await ur(a,e,t,n);o[r]++}if(c.length>0){let t=lr(c).length;if(An()){let n=r??null;if(n||(await hr(t)===`pick`?(n=await jn(),n||J(`没有选择文件夹。本地文件暂以占位显示,稍后可直接把文件拖进编辑器上传`,`info`)):J(`已选择稍后处理。本地文件暂以占位显示,可直接把文件拖进编辑器上传`,`info`)),n){i=n,or(o,await fr(a,e,c,n));let t=[...o.missing,...o.readFailed];if(t.length>0&&Mn()&&await _r(t.map(e=>e.basename))===`pick`){let n=await vr(a,e,t);or(o,n),o.missing=n.missing,o.readFailed=[]}}}else gr(t)}mr(o)},o=()=>{if(!e||e.isDestroyed||t.pausedUntilPaste)return;let o=n.i(),s=Rn(e.state.doc,o);if(s.length===0||r)return;r=!0;let c=new Set(s.map(e=>e.src));a(s).then(()=>{if(e.isDestroyed)return;let t=Rn(e.state.doc,o).filter(e=>!c.has(e.src));if(t.length!==0)return a(t,i)}).finally(()=>{r=!1,!(!e||e.isDestroyed)&&(t.pausedUntilPaste=Rn(e.state.doc,o).length>0)})};return[new f.Plugin({key:new f.PluginKey(`relativeMedia`),props:{handlePaste(e,n){let r=n.clipboardData?.files;return t.clipboardFiles=new Map(Array.from(r??[]).map(e=>[e.name.toLowerCase(),e])),t.pausedUntilPaste=!1,!1}},appendTransaction(e){return e.some(e=>e.docChanged)&&queueMicrotask(o),null}})]}}),br=new f.PluginKey(`slashCommand`);function xr(e){return d.Extension.create({name:`slashCommand`,addProseMirrorPlugins(){let t={char:`/`,pluginKey:br,findSuggestionMatch:e=>{let{$position:t}=e;for(let e=t.depth;e>=0;e--)if(t.node(e).type.name===`codeBlock`)return null;return t.marks().some(e=>e.type.name===`code`)?null:(0,P.findSuggestionMatch)(e)},allow:({editor:e,state:t})=>{if(!e.isEditable)return!1;let{$from:n}=t.selection;for(let e=n.depth;e>=0;e--)if(n.node(e).type.name===`codeBlock`)return!1;return!n.marks().some(e=>e.type.name===`code`)},command:({editor:e,range:t,props:n})=>{e.chain().focus().deleteRange(t).run(),n.command({editor:e})},items:({query:t})=>{let n=e();if(!t)return n;let r=t.toLowerCase();return n.filter(e=>e.title.toLowerCase().includes(r)||(e.description?.toLowerCase().includes(r)??!1))},render:()=>{let e=null,t=null,n=0,r=[],i=null,a=null,o=null;function s(e,o){if(!t)return;r=e,i=o,t.textContent=``;let s=document.createElement(`div`);s.style.cssText=`padding:6px 8px;border-bottom:1px solid #f4f4f5;`;let c=document.createElement(`input`);c.type=`text`,c.placeholder=`搜索命令…`,c.style.cssText=`width:100%;padding:6px 8px;border:1px solid #e4e4e7;border-radius:8px;font-size:13px;outline:none;background:#fafafa;`,s.appendChild(c),t.appendChild(s);let l=document.createElement(`div`);if(l.className=`slash-item-list`,l.style.cssText=`max-height:300px;overflow-y:auto;`,e.length===0){let e=document.createElement(`div`);e.style.cssText=`padding:12px;text-align:center;color:#a1a1aa;font-size:13px;`,e.textContent=`未找到匹配`,l.appendChild(e)}else e.forEach((e,t)=>{let r=document.createElement(`button`);r.type=`button`,r.className=`slash-item${t===n?` slash-item--selected`:``}`,r.dataset.index=String(t),r.style.cssText=`display:flex;align-items:center;gap:12px;width:100%;padding:8px 12px;border:none;background:${t===n?`#f4f4f5`:`transparent`};cursor:pointer;text-align:left;border-radius:8px;font-size:14px;transition:background 0.1s;`;let i=document.createElement(`span`);i.style.cssText=`font-size:16px;width:24px;text-align:center;flex-shrink:0;`,i.textContent=e.icon||``,r.appendChild(i);let a=document.createElement(`div`);a.style.cssText=`min-width:0;`;let s=document.createElement(`div`);if(s.style.cssText=`font-weight:500;color:#18181b;`,s.textContent=e.title,a.appendChild(s),e.description){let t=document.createElement(`div`);t.style.cssText=`font-size:12px;color:#a1a1aa;margin-top:1px;`,t.textContent=e.description,a.appendChild(t)}r.appendChild(a),r.addEventListener(`click`,()=>{o(e)}),l.appendChild(r)});t.appendChild(l);let u=l.querySelector(`.slash-item--selected`);if(u){let e=l.getBoundingClientRect(),t=u.getBoundingClientRect();t.top<e.top?l.scrollTop-=e.top-t.top:t.bottom>e.bottom&&(l.scrollTop+=t.bottom-e.bottom)}let d=()=>Array.from(l.querySelectorAll(`.slash-item`)).filter(e=>e.style.display!==`none`&&!e.disabled),f=e=>{l.querySelectorAll(`.slash-item`).forEach(t=>{t.classList.toggle(`slash-item--selected`,t===e),t.style.background=t===e?`#f4f4f5`:`transparent`});let t=l.getBoundingClientRect(),n=e.getBoundingClientRect();n.top<t.top?l.scrollTop-=t.top-n.top:n.bottom>t.bottom&&(l.scrollTop+=n.bottom-t.bottom)};c.addEventListener(`input`,()=>{let e=c.value.toLowerCase();l.querySelectorAll(`.slash-item`).forEach(t=>{let n=(t.textContent||``).toLowerCase();t.style.display=n.includes(e)?``:`none`});let t=d()[0];t&&(n=Number(t.dataset.index??0),f(t))}),c.addEventListener(`keydown`,e=>{let t=d();if(e.key===`Enter`){e.preventDefault(),(t.find(e=>e.classList.contains(`slash-item--selected`))??t[0])?.click();return}if(e.key===`ArrowDown`||e.key===`ArrowUp`){if(e.preventDefault(),t.length===0)return;let r=t.findIndex(e=>e.classList.contains(`slash-item--selected`)),i=t[e.key===`ArrowDown`?(r+1)%t.length:(r-1+t.length)%t.length];n=Number(i.dataset.index??0),f(i);return}if(e.key===`Escape`){e.preventDefault();let t=a?.view;t&&(0,P.exitSuggestion)(t,br)}})}let c=null,l=null;function u(){if(!e||!c)return;let t=c();t&&(e.style.top=`${t.bottom+4}px`,e.style.left=`${t.left}px`)}return{onStart:i=>{if(n=0,c=i.clientRect||null,a={view:i.editor.view},e||(e=document.createElement(`div`),e.style.position=`fixed`,e.style.zIndex=`9999`,document.body.appendChild(e)),t||(t=document.createElement(`div`),t.className=`slash-command-popup`,t.style.cssText=`background:#fff;border:1px solid #e4e4e7;border-radius:12px;box-shadow:0 4px 24px rgba(0,0,0,0.12);min-width:260px;max-width:340px;`,t.setAttribute(`data-lenis-prevent`,``),e.appendChild(t)),u(),r=i.items,s(i.items,i.command),e.style.display=`block`,l=()=>u(),window.addEventListener(`scroll`,l,!0),!o){let t=!1;o=n=>{if(!e||e.style.display===`none`||n.target instanceof Node&&e.contains(n.target)||t)return;let r=a?.view;r&&(t=!0,window.setTimeout(()=>{t=!1,e?.style.display!==`none`&&(0,P.exitSuggestion)(r,br)},0))},document.addEventListener(`mousedown`,o,!0),document.addEventListener(`touchstart`,o,!0)}},onUpdate:e=>{n=0,c=e.clientRect||null,a={view:e.editor.view},r=e.items,s(e.items,e.command),u()},onKeyDown:e=>{if(e.event.key===`ArrowDown`)return e.event.preventDefault(),n=Math.min(n+1,r.length-1),i&&s(r,i),!0;if(e.event.key===`ArrowUp`)return e.event.preventDefault(),n=Math.max(n-1,0),i&&s(r,i),!0;if(e.event.key===`Enter`){e.event.preventDefault();let t=r[n];return t&&typeof t.command==`function`&&i&&i(t),!0}return e.event.key===`Escape`},onExit:()=>{e&&(e.style.display=`none`),n=0,r=[],i=null,c=null,a=null,l&&=(window.removeEventListener(`scroll`,l,!0),null),o&&=(document.removeEventListener(`mousedown`,o,!0),document.removeEventListener(`touchstart`,o,!0),null)}}}};return[(0,P.default)({editor:this.editor,...t}),new f.Plugin({key:new f.PluginKey(`slashCodeBlockGuard`),appendTransaction:(e,t,n)=>{let{$from:r}=n.selection,i=!1;for(let e=r.depth;e>=0;e--)if(r.node(e).type.name===`codeBlock`){i=!0;break}if(!i&&!r.marks().some(e=>e.type.name===`code`))return null;let a=br.getState(n);return a&&a.active?n.tr.setMeta(br,{exit:!0}):null}})]}})}function Sr(e,t){return[{title:e(`editor.slash.heading1`),description:e(`editor.slash.heading1Desc`),icon:`H1`,command:({editor:e})=>e.chain().focus().toggleHeading({level:1}).run()},{title:e(`editor.slash.heading2`),description:e(`editor.slash.heading2Desc`),icon:`H2`,command:({editor:e})=>e.chain().focus().toggleHeading({level:2}).run()},{title:e(`editor.slash.heading3`),description:e(`editor.slash.heading3Desc`),icon:`H3`,command:({editor:e})=>e.chain().focus().toggleHeading({level:3}).run()},{title:e(`editor.slash.heading4`),description:e(`editor.slash.heading4Desc`),icon:`H4`,command:({editor:e})=>e.chain().focus().toggleHeading({level:4}).run()},{title:e(`editor.slash.heading5`),description:e(`editor.slash.heading5Desc`),icon:`H5`,command:({editor:e})=>e.chain().focus().toggleHeading({level:5}).run()},{title:e(`editor.slash.heading6`),description:e(`editor.slash.heading6Desc`),icon:`H6`,command:({editor:e})=>e.chain().focus().toggleHeading({level:6}).run()},{title:e(`editor.slash.bulletList`),description:e(`editor.slash.bulletListDesc`),icon:`•`,command:({editor:e})=>e.chain().focus().toggleBulletList().run()},{title:e(`editor.slash.numberedList`),description:e(`editor.slash.numberedListDesc`),icon:`1.`,command:({editor:e})=>e.chain().focus().toggleOrderedList().run()},{title:e(`editor.slash.taskList`),description:e(`editor.slash.taskListDesc`),icon:`☑`,command:({editor:e})=>e.chain().focus().toggleTaskList().run()},{title:e(`editor.slash.blockquote`),description:e(`editor.slash.blockquoteDesc`),icon:`❝`,command:({editor:e})=>e.chain().focus().toggleBlockquote().run()},{title:e(`editor.slash.codeBlock`),description:e(`editor.slash.codeBlockDesc`),icon:`</>`,command:({editor:e})=>e.chain().focus().toggleCodeBlock().run()},{title:e(`editor.slash.horizontalRule`),description:e(`editor.slash.horizontalRuleDesc`),icon:`—`,command:({editor:e})=>e.chain().focus().setHorizontalRule().run()},{title:e(`editor.slash.image`),description:e(`editor.slash.imageDesc`),icon:`🖼`,command:({editor:e})=>{e.storage.qingwuUI?.openImageDialog?.()}},{title:e(`editor.slash.video`),description:e(`editor.slash.videoDesc`),icon:`🎬`,command:({editor:e})=>{e.storage.qingwuUI?.openVideoDialog?.()}},{title:e(`editor.slash.audio`),description:e(`editor.slash.audioDesc`),icon:`🎵`,command:({editor:e})=>{let n=document.createElement(`input`);n.type=`file`,n.accept=`audio/*`,n.onchange=async()=>{let r=n.files?.[0];if(!r)return;let i=Tt(e)??t,a=i?Et(e.state.doc,r,i):null;if(a){J(a);return}let o=URL.createObjectURL(r),s=e.schema.nodes.audioEmbed?.create({src:o,name:r.name,size:r.size});s&&(e.chain().focus().insertContent(s).run(),await Wn(e.view,r,o))},n.click()}},{title:e(`editor.slash.attachment`),description:e(`editor.slash.attachmentDesc`),icon:`📎`,command:({editor:e})=>{let n=document.createElement(`input`);n.type=`file`,n.accept=`*/*`,n.multiple=!0,n.onchange=async()=>{let r=n.files;if(!(!r||r.length===0))for(let n of Array.from(r)){let r=Tt(e)??t,i=r?Et(e.state.doc,n,r):null;if(i){J(i);continue}let a=URL.createObjectURL(n),o=e.schema.nodes.attachmentEmbed;if(o){try{e.chain().focus().insertContent(o.create({src:a,name:n.name,size:n.size,type:n.type})).run()}catch{continue}await Wn(e.view,n,a)}}},n.click()}}]}var Cr=m.Image.extend({addNodeView(){return(0,c.ReactNodeViewRenderer)(Lt)},addAttributes(){return{...this.parent?.(),width:{default:null,parseHTML:e=>e.getAttribute(`width`)||null,renderHTML:e=>e.width?{width:e.width}:{}},height:{default:null,parseHTML:e=>e.getAttribute(`height`)||null,renderHTML:e=>e.height?{height:e.height}:{}},size:{default:0,parseHTML:e=>Number(e.getAttribute(`data-size`)||0),renderHTML:e=>e.size?{"data-size":e.size}:{}}}}});function wr(t={}){return[_.default.configure({codeBlock:!1,horizontalRule:!1,underline:!1,link:!1}),g.Underline,h.Link.configure({openOnClick:!0,HTMLAttributes:{rel:`noopener noreferrer`,target:`_blank`}}),Cr.configure({inline:!1,allowBase64:!0}),O.TaskList,D.TaskItem.configure({nested:!0}),b.Highlight.configure({multicolor:!0}),k.TextStyle,y.Color,v.CharacterCount.configure(t.maxLength?{limit:t.maxLength}:{}),x.HorizontalRule,Sn,C.Table.configure({resizable:!0}),E.TableRow,w.TableCell,T.TableHeader,A.Markdown.configure({html:!0,transformPastedText:!0,transformCopiedText:!1}),S.Placeholder.configure({placeholder:t.placeholder||`输入 '/' 打开菜单…`}),xr(()=>Sr(t=>e.o(t),{maxAttachmentSize:t.maxAttachmentSize,maxTotalAttachmentSize:t.maxTotalAttachmentSize})),Kn.configure({maxAttachmentSize:t.maxAttachmentSize,maxTotalAttachmentSize:t.maxTotalAttachmentSize}),yr,tr,Ue,Jn,nr,ln,tn,Qt]}var Tr=`https://www.bing.com/search?q={query}`;function Er(e){Tr=e}function Dr(){return Tr}function Or(e){return[{key:`bold`,label:e(`editor.bubble.bold`),icon:(0,a.jsx)(Ke,{}),isActive:e=>e.isActive(`bold`),command:e=>e.isEditable&&e.chain().focus().toggleBold().run()},{key:`italic`,label:e(`editor.bubble.italic`),icon:(0,a.jsx)(qe,{}),isActive:e=>e.isActive(`italic`),command:e=>e.isEditable&&e.chain().focus().toggleItalic().run()},{key:`underline`,label:e(`editor.bubble.underline`),icon:(0,a.jsx)(Je,{}),isActive:e=>e.isActive(`underline`),command:e=>e.isEditable&&e.chain().focus().toggleUnderline().run()},{key:`strikethrough`,label:e(`editor.bubble.strikethrough`),icon:(0,a.jsx)(Ye,{}),isActive:e=>e.isActive(`strike`),command:e=>e.isEditable&&e.chain().focus().toggleStrike().run()},{key:`code`,label:e(`editor.bubble.emphasis`),icon:(0,a.jsx)(Xe,{}),isActive:e=>e.isActive(`code`),command:e=>e.isEditable&&e.chain().focus().toggleCode().run()},{key:`highlight`,label:e(`editor.bubble.highlight`),icon:(0,a.jsx)(Ze,{}),more:!0,isActive:e=>e.isActive(`highlight`),command:()=>{}},{key:`link`,label:e(`editor.bubble.link`),icon:(0,a.jsx)(Qe,{}),more:!0,isActive:e=>e.isActive(`link`),command:()=>{}},{key:`copy`,label:e(`editor.bubble.copy`),icon:(0,a.jsx)(et,{}),more:!0,isActive:()=>!1,command:e=>{let{from:t,to:n}=e.state.selection,r=e.state.doc.textBetween(t,n,`
|
|
9
|
+
`).trim();r&&navigator.clipboard?.writeText(r).catch(()=>{})}},{key:`search`,label:e(`editor.bubble.search`),icon:(0,a.jsx)(tt,{}),more:!0,isActive:()=>!1,command:e=>{if(e.isActive(`table`))return;let{from:t,to:n}=e.state.selection,r=e.state.doc.textBetween(t,n,` `).trim();if(!r)return;let i=Tr.replace(`{query}`,encodeURIComponent(r));window.open(i,`_blank`,`noopener,noreferrer`)}},{key:`table`,label:e(`editor.bubble.table`),icon:(0,a.jsx)($e,{}),more:!0,isActive:e=>e.isActive(`table`),command:e=>{if(!e.isEditable||e.isActive(`table`))return;let{from:t,to:n,$to:r}=e.state.selection,i=e.chain().focus();t!==n&&i.setTextSelection(r.end(r.depth)),i.insertTable({rows:3,cols:3,withHeaderRow:!0}).scrollIntoView().run()}},{key:`ai`,label:e(`editor.ai.trigger`),icon:(0,a.jsx)(nt,{}),isActive:()=>!1,command:e=>{e.isEditable&&e.storage.qingwuUI?.openAI?.()}}]}d.Extension.create({name:`bubbleMenu`});function kr(e){let{$from:t}=e.state.selection;for(let e=t.depth;e>0;e--){let n=t.node(e);if(n.type.name===`table`)return{node:n,pos:t.before(e)}}return null}function Ar(e){let t=[];return e.forEach(e=>{let n=[];e.forEach(e=>{n.push(e.textContent.replace(/\n/g,` `).trim())}),t.push(n)}),t}function jr(e){if(e.length===0)return``;let t=Math.max(...e.map(e=>e.length),1),n=e=>e.concat(Array(Math.max(0,t-e.length)).fill(``)).slice(0,t),r=n(e[0]),i=e.slice(1).map(n),a=e=>`| ${e.join(` | `)} |`;return[a(r),a(Array(t).fill(`---`)),...i.map(a)].join(`
|
|
10
|
+
`)}function Mr(e){let t=e=>/[",\n]/.test(e)?`"${e.replace(/"/g,`""`)}"`:e;return e.map(e=>e.map(t).join(`,`)).join(`
|
|
11
|
+
`)}function Nr(e){let t=e.trim();if(!t)return null;let n=t.split(/\r?\n/);if(n.length>=2&&n.every(e=>e.includes(`|`))){let e=n.filter(e=>!/^\s*\|?[\s:|-]+\|?\s*$/.test(e)).map(e=>e.replace(/^\s*\|/,``).replace(/\|\s*$/,``).split(`|`).map(e=>e.trim()));if(e.length>0&&e[0].length>1)return e}if(n.length>=1){let e=n[0].includes(` `)?` `:`,`,t=n.map(t=>t.split(e).map(e=>e.trim()));if(t.length>0&&t[0].length>1)return t}return null}function Pr({editor:e}){let[t,n]=(0,i.useState)(null),[r,o]=(0,i.useState)(!1),[s,c]=(0,i.useState)(!1),l=(0,i.useRef)(null),u=(0,i.useRef)(null),d=e.isEditable,f=(0,i.useCallback)(()=>{u.current!=null&&cancelAnimationFrame(u.current),u.current=requestAnimationFrame(()=>{u.current=null;let n=l.current;if(n==null||t==null)return;let r=e.view.nodeDOM(t);if(!(r instanceof HTMLElement))return;let i=r.getBoundingClientRect(),a=i.top>40?i.top-34:Math.min(i.bottom+4,window.innerHeight-40);n.style.top=`${a}px`,n.style.left=`${Math.max(8,Math.min(i.left,window.innerWidth-160))}px`})},[e,t]),p=(0,i.useCallback)(()=>{if(!e.isEditable||!e.isActive(`table`)){n(null);return}let t=kr(e);if(!t){n(null);return}n(e=>e===t.pos?e:t.pos)},[e]);(0,i.useEffect)(()=>(p(),e.on(`selectionUpdate`,p),e.on(`focus`,p),window.addEventListener(`scroll`,f,!0),window.addEventListener(`resize`,f),()=>{e.off(`selectionUpdate`,p),e.off(`focus`,p),window.removeEventListener(`scroll`,f,!0),window.removeEventListener(`resize`,f),u.current!=null&&cancelAnimationFrame(u.current)}),[e,p,f]),(0,i.useEffect)(()=>{f()},[t,f]);let m=t=>{let{schema:n}=e.state;if(!n.nodes.table||!n.nodes.tableRow||!n.nodes.tableCell||!n.nodes.tableHeader)return null;let r=Math.max(...t.map(e=>e.length)),i=t.map((e,t)=>{let i=[];for(let a=0;a<r;a++){let r=e[a]??``,o=t===0?n.nodes.tableHeader:n.nodes.tableCell,s=r?n.text(r):null;i.push(o.create(null,s?[s]:[]))}return n.nodes.tableRow.create(null,i)});return n.nodes.table.create(null,i)},h=()=>{let t=kr(e);if(!t)return;let n=jr(Ar(t.node));navigator.clipboard?.writeText(n),o(!0),setTimeout(()=>o(!1),1500)},g=()=>{let t=kr(e);if(!t)return;let n=Mr(Ar(t.node)),r=new Blob([`\ufeff${n}`],{type:`text/csv;charset=utf-8`}),i=URL.createObjectURL(r),a=document.createElement(`a`);a.href=i,a.download=`table.csv`,document.body.appendChild(a),a.click(),document.body.removeChild(a),URL.revokeObjectURL(i)},_=async()=>{if(d)try{let t=await navigator.clipboard?.readText();if(!t)return;let n=Nr(t);if(!n||n.length===0)return;let r=m(n);if(!r)return;let i=kr(e),a=e.chain().focus();if(i){let t=Math.min(i.pos+i.node.nodeSize,e.state.doc.content.size);a.setTextSelection(t)}a.insertContent(r).run()}catch{}},v=()=>{d&&t!=null&&(e.chain().focus().setNodeSelection(t).run(),e.storage.qingwuUI?.openAI?.())},y=()=>{d&&e.chain().focus().deleteTable().run()};return!d||t==null?null:(0,a.jsxs)(`div`,{ref:l,style:{position:`fixed`,top:0,left:0,zIndex:1e5},className:`tbl-toolbar`,contentEditable:!1,children:[(0,a.jsx)(`button`,{type:`button`,className:`tbl-btn`,onClick:h,title:`复制`,children:r?(0,a.jsx)(`svg`,{className:`tbl-btn-icon tbl-btn-icon--check`,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 13l4 4L19 7`})}):(0,a.jsx)(`svg`,{className:`tbl-btn-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:`M8 5H6a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2v-2M8 5a2 2 0 002 2h2a2 2 0 002-2M8 5a2 2 0 012-2h2a2 2 0 012 2m0 0h2a2 2 0 012 2v3`})})}),(0,a.jsx)(`button`,{type:`button`,className:`tbl-btn`,onClick:g,title:`下载`,children:(0,a.jsx)(`svg`,{className:`tbl-btn-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:`M4 16v1a3 3 0 003 3h10a3 3 0 003-3v-1m-4-4l-4 4m0 0l-4-4m4 4V4`})})}),(0,a.jsx)(`button`,{type:`button`,className:`tbl-btn`,onClick:_,title:`粘贴`,children:(0,a.jsx)(`svg`,{className:`tbl-btn-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:`M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2`})})}),(0,a.jsx)(`button`,{type:`button`,className:`tbl-btn tbl-btn--ai`,onClick:v,title:`AI 助手`,children:(0,a.jsx)(`svg`,{className:`tbl-btn-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:`M13 10V3L4 14h7v7l9-11h-7z`})})}),(0,a.jsx)(`button`,{type:`button`,className:`tbl-btn tbl-btn--del`,onClick:()=>{!d||At()||($(!0),c(!0))},title:`删除`,children:(0,a.jsx)(`svg`,{className:`tbl-btn-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:`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)(Ft,{open:s,title:`确认删除表格`,message:`此操作不可撤销。`,onCancel:()=>{$(!1),c(!1)},onConfirm:async()=>{await new Promise(e=>setTimeout(e,300)),$(!1),y()}})]})}var Fr=[{color:`#fef08a`,name:`黄`},{color:`#bbf7d0`,name:`绿`},{color:`#bfdbfe`,name:`蓝`},{color:`#fbcfe8`,name:`粉`},{color:`#fed7aa`,name:`橙`},{color:`#ddd6fe`,name:`紫`}],Ir=288,Lr=480,Rr=320;function zr(e,t,n={}){let r=window.innerWidth,i=window.innerHeight,a=Math.min(n.panelWidth||Ir,Lr,r-32),o=Math.max(t||Rr,160);if(r<640){let t=Math.max(8,Math.min(e.top+10,i-420));return{style:{position:`fixed`,top:t,left:8,right:8,width:`auto`,zIndex:9999,maxHeight:`calc(100dvh - ${t}px - 16px)`,overflow:`hidden`,display:`flex`,flexDirection:`column`},placement:`below`,arrowLeft:50}}let s=e.left+e.width/2,c=typeof n.editorLeft==`number`?n.editorLeft:s-a/2;c=Math.max(16,Math.min(c,r-a-16));let l=i-e.top-16,u=e.top-16,d=l<o+12&&u>=o+12?`above`:`below`,f=d===`below`?e.top+10:e.top-o-10;f=Math.max(16,Math.min(f,i-o-16));let p=Math.max(14,Math.min((s-c)/a*100,86)),m=d===`above`?`${Math.max(e.top-10-f,160)}px`:`calc(100dvh - ${f}px - 16px)`;return{style:{position:`fixed`,top:f,left:c,width:a,zIndex:9999,maxHeight:m,overflow:`hidden`,display:`flex`,flexDirection:`column`},placement:d,arrowLeft:p}}function Br(e){return/(^|\n)```|(^|\n)#{1,6}\s|(^|\n)>\s?|(^|\n)\s*([-*_])(?:\s*\4){2,}\s*(?=\n|$)|(^|\n)\s*[-*+]\s+|(^|\n)\s*\d+[.)]\s+|(^|\n)\s*<img\s+|(^|\n)\s*\|.+\|/i.test(e)}function Vr(e,t){try{let n=e.storage?.markdown?.parser;if(!n)return null;let r=n.parse(t),i=document.createElement(`div`);return i.innerHTML=r,s.DOMParser.fromSchema(e.schema).parse(i).content}catch{return null}}var Hr=(0,i.lazy)(()=>Promise.resolve().then(()=>ve).then(e=>({default:e.ImageUploadDialog}))),Ur=(0,i.lazy)(()=>Promise.resolve().then(()=>require("./storage-settings-dialog-ZtMUoApJ.cjs")).then(e=>({default:e.StorageSettingsDialog}))),Wr=(0,i.lazy)(()=>Promise.resolve().then(()=>require("./export-dialog-BSEeEEHv.cjs")).then(e=>({default:e.ExportDialog}))),Gr=(0,i.lazy)(()=>Promise.resolve().then(()=>require("./video-embed-dialog-BbVHq51W.cjs")).then(e=>({default:e.VideoEmbedDialog}))),Kr=(0,i.lazy)(()=>Promise.resolve().then(()=>require("./md-import-dialog-CnstzrIK.cjs")).then(e=>({default:e.MdImportDialog}))),qr=()=>(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`}),(0,a.jsx)(`div`,{className:`relative bg-background rounded-2xl border border-default-200 p-8 flex items-center justify-center`,children:(0,a.jsx)(`div`,{className:`w-6 h-6 border-2 border-primary border-t-transparent rounded-full animate-spin`})})]}),Jr=({initialContent:t=``,onChange:n,placeholder:r,mode:o,readonly:d=!1,maxLength:f,maxAttachmentSize:p,maxTotalAttachmentSize:m,className:h=``,borderless:g=!1,style:_,showToolbar:v=!0,showToc:y=!0,showSearch:b=!0,onEditorReady:x,immediatelyRender:S,onToast:C})=>{let w=o===`view`||d,T=(0,i.useMemo)(()=>typeof t==`object`&&t||Br(t)?t:e.n(t),[t]),[E,D]=(0,i.useState)(!1),[O,k]=(0,i.useState)({}),[A,j]=(0,i.useState)(`below`),[M,N]=(0,i.useState)(50),P=(0,i.useRef)(null),[F,ee]=(0,i.useState)(!1),[I,L]=(0,i.useState)(!1),[te,R]=(0,i.useState)(!1),[ne,re]=(0,i.useState)(!1),[z,B]=(0,i.useState)(`none`),[V,H]=(0,i.useState)({}),[ie,ae]=(0,i.useState)(``),[U,oe]=(0,i.useState)(null),[W,se]=(0,i.useState)(y),[G,ce]=(0,i.useState)(!1);(0,i.useEffect)(()=>{se(y)},[y]);let[le,ue]=(0,i.useState)(!1),[de,fe]=(0,i.useState)(()=>typeof window<`u`&&typeof window.matchMedia==`function`?window.matchMedia(`(min-width: 80rem)`).matches:!0),[pe,K]=(0,i.useState)(()=>typeof window<`u`&&typeof window.matchMedia==`function`?window.matchMedia(`(min-width: 64rem)`).matches:!0),me=(0,i.useRef)(null),q=(0,i.useRef)(null),he=(0,i.useRef)(null),ge=(0,i.useRef)(0),ve=(0,i.useRef)(null),ye=(0,i.useRef)(null),be=(0,i.useRef)(null),xe=(0,i.useRef)(null),[Se,Ce]=(0,i.useState)(!1),[Y,Ee]=(0,i.useState)(!1),[De,Oe]=(0,i.useState)(!1),Ae=(0,i.useRef)(null),je=(0,i.useCallback)(()=>{let e=q.current,t=he.current;e&&(Y?(document.body.style.overflow=``,Object.assign(e.style,{position:``,top:``,left:``,width:``,height:``,zIndex:``,background:``,borderRadius:``,overflow:``,display:``,flexDirection:``}),t&&Object.assign(t.style,{flex:``,overflow:``,minHeight:``}),Ee(!1),requestAnimationFrame(()=>{window.scrollTo(0,ge.current)})):(document.fullscreenElement&&document.exitFullscreen(),ge.current=window.scrollY,Object.assign(e.style,{position:`fixed`,top:`0`,left:`0`,width:`100vw`,height:`100vh`,zIndex:`99999`,background:`var(--background, #fff)`,borderRadius:`0`,overflow:`hidden`,display:`flex`,flexDirection:`column`}),t&&Object.assign(t.style,{flex:`1`,overflow:`auto`,minHeight:`0`}),document.body.style.overflow=`hidden`,Ee(!0)))},[Y]),Me=(0,i.useCallback)(()=>{let e=q.current;e&&(document.fullscreenElement?document.exitFullscreen():(Y&&je(),ge.current=window.scrollY,e.requestFullscreen()))},[Y,je]);(0,i.useEffect)(()=>{let e=e=>{e.key===`Escape`&&Y&&je()},t=()=>{document.fullscreenElement?Oe(!0):(Oe(!1),requestAnimationFrame(()=>{window.scrollTo(0,ge.current)}))};return window.addEventListener(`keydown`,e),document.addEventListener(`fullscreenchange`,t),()=>{window.removeEventListener(`keydown`,e),document.removeEventListener(`fullscreenchange`,t)}},[Y,je]),(0,i.useEffect)(()=>{if(!b)return;let e=e=>{if((e.ctrlKey||e.metaKey)&&(e.key===`f`||e.key===`F`)){if(!q.current)return;e.preventDefault(),e.stopPropagation(),ue(!0)}};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[b]),(0,i.useEffect)(()=>{if(typeof window>`u`||typeof window.matchMedia!=`function`)return;let e=window.matchMedia(`(min-width: 80rem)`),t=e=>fe(e.matches);return fe(e.matches),e.addEventListener(`change`,t),()=>e.removeEventListener(`change`,t)},[]),(0,i.useEffect)(()=>{if(typeof window>`u`||typeof window.matchMedia!=`function`)return;let e=window.matchMedia(`(min-width: 64rem)`),t=e=>K(e.matches);return K(e.matches),e.addEventListener(`change`,t),()=>e.removeEventListener(`change`,t)},[]);let X=(0,c.useEditor)({extensions:wr({placeholder:r||e.o(`editor.placeholder`),maxLength:f,maxAttachmentSize:p,maxTotalAttachmentSize:m}),content:T,editable:!w,immediatelyRender:S,onUpdate:({editor:e})=>{n&&(me.current&&clearTimeout(me.current),me.current=setTimeout(()=>{n?.(e.getHTML(),e.getJSON())},300))},onCreate:()=>{},editorProps:{attributes:{class:`prose prose-neutral dark:prose-invert max-w-none focus:outline-none min-h-[200px] px-4 sm:px-8 py-4`,...w?{}:{style:`padding-left: 2.75rem`}},handlePaste(e,t){let n=t.clipboardData;if(!n)return!1;let r=n.getData(`text/plain`);if(!r||!r.includes(`[[`))return!1;t.preventDefault();let i=ye.current?.storage?.relativeMedia;i&&(i.clipboardFiles=new Map(Array.from(n.files??[]).map(e=>[e.name.toLowerCase(),e])),i.pausedUntilPaste=!1);let a=ye.current?Vr(ye.current,r):null;if(a){let t=new s.Slice(a,0,0);e.dispatch(e.state.tr.replaceSelection(t).scrollIntoView())}else e.dispatch(e.state.tr.insertText(r).scrollIntoView());return!0}}});(0,i.useEffect)(()=>{ye.current=X,window.__editor=X},[X]),(0,i.useEffect)(()=>{if(X)return()=>ft(X)},[X]),(0,i.useEffect)(()=>{!X||!x||x(X)},[X,x]),(0,i.useEffect)(()=>{if(!X)return;let e=()=>{X.state.selection.empty&&(B(`none`),Ce(!1))};return X.on(`selectionUpdate`,e),()=>{X.off(`selectionUpdate`,e)}},[X]),(0,i.useEffect)(()=>{X&&X.setOptions({extensions:wr({placeholder:r||e.o(`editor.placeholder`),maxLength:f,maxAttachmentSize:p,maxTotalAttachmentSize:m})})},[r,f,p,m]);let Ne=(0,i.useRef)(t);(0,i.useEffect)(()=>{if(!X||t===Ne.current)return;Ne.current=t;let n=typeof t==`object`&&t||Br(t)?t:e.n(t);X.commands.setContent(n,{emitUpdate:!1})},[X,t]),(0,i.useEffect)(()=>{X&&X.setEditable(!w,!1)},[X,w]),(0,i.useEffect)(()=>{if(C)return _e(C)},[C]),(0,i.useEffect)(()=>{if(!X)return;let e=Ct(X.state.doc);e>m&&J(`文档内附件总大小 ${wt(e)} 已超过限制 ${wt(m)}`,`info`)},[X,m]),(0,i.useEffect)(()=>{if(!X)return;let e=X.storage.qingwuUI;e&&(e.limits={maxAttachmentSize:p,maxTotalAttachmentSize:m})},[X,p,m]);let Pe=(0,i.useCallback)(e=>{let t=xe.current?.getBoundingClientRect();B(e),Ce(!1),H({position:`fixed`,top:t?t.bottom+8:void 0,left:t?Math.max(8,Math.min(t.left,window.innerWidth-240)):8,zIndex:9999})},[]),Fe=Or(t=>e.o(t)),Ie=Fe.filter(e=>!e.more),Le=Fe.filter(e=>e.more),Re=Ie.filter(e=>e.key!==`ai`),Z=Ie.find(e=>e.key===`ai`),ze=(0,i.useCallback)(e=>{if(X)if(Ce(!1),e.key===`link`)if(X.isActive(`link`))X.chain().focus().unsetLink().run();else{let e=X.getAttributes(`link`).href||``;ae(e),Pe(`link`)}else e.key===`highlight`?z===`highlight`?B(`none`):Pe(`highlight`):e.command(X)},[X,z,Pe]),Be=(0,i.useCallback)(e=>X?e.key===`highlight`?z===`highlight`:e.key===`link`?X.isActive(`link`):e.isActive(X):!1,[X,z]),[Ve,He]=(0,i.useState)(0);(0,i.useEffect)(()=>{if(!X)return;let e=()=>He(e=>(e+1)%1e6);return X.on(`update`,e),()=>{X.off(`update`,e)}},[X]);let[Ue,We]=(0,i.useState)(!1);(0,i.useEffect)(()=>{if(!X)return;let e=()=>{let e=!1;X.state.doc.descendants(t=>{t.type.name===`heading`&&(e=!0)}),We(e)};return e(),X.on(`update`,e),()=>{X.off(`update`,e)}},[X]);let Q=(0,i.useMemo)(()=>X?.storage?.characterCount?.characters?.()??0,[X,Ve]),Ke=f?Q>f:!1;(0,i.useEffect)(()=>()=>{me.current&&clearTimeout(me.current)},[]),(0,i.useEffect)(()=>()=>{U&&U.resolve(null)},[]);let qe=(0,i.useCallback)(e=>{if(!X?.isEditable)return;let t=window.getSelection(),n;if(e){let t=e.getBoundingClientRect();n={top:t.bottom,left:t.left,width:t.width}}else if(t&&t.rangeCount>0&&!t.isCollapsed){let e=t.getRangeAt(0).getBoundingClientRect();n={top:e.bottom,left:e.left,width:e.width}}else{let e=X.view.coordsAtPos(X.state.selection.from);n={top:e.bottom,left:e.left,width:0}}ve.current=n;let r=q.current?.getBoundingClientRect(),i=zr(n,void 0,{panelWidth:r?.width,editorLeft:r?.left});D(!0),k(i.style),j(i.placement),N(i.arrowLeft)},[X]);(0,i.useEffect)(()=>{if(!X)return;let e=X.storage.qingwuUI;if(e)return e.openImageDialog=()=>ee(!0),e.openVideoDialog=()=>L(!0),e.chooseMd=(e,t)=>{oe({filename:e,resolve:t})},e.openAI=qe,e.parseMd=(e,t)=>X?Vr(X,t):null,()=>{delete e.openImageDialog,delete e.openVideoDialog,delete e.openAI,delete e.parseMd,delete e.chooseMd}},[X,qe]),(0,i.useLayoutEffect)(()=>{if(!E||!X)return;let e=ve.current;if(!e)return;let t=P.current,n=q.current?.getBoundingClientRect(),r=zr(e,t?.offsetHeight||void 0,{panelWidth:n?.width,editorLeft:n?.left});j(r.placement),N(r.arrowLeft),k(r.style)},[E,X]),(0,i.useEffect)(()=>{if(!E||!X)return;let e=()=>{let e=ve.current;if(!e)return;let t=P.current,n=q.current?.getBoundingClientRect(),r=zr(e,t?.offsetHeight||void 0,{panelWidth:n?.width,editorLeft:n?.left});j(r.placement),N(r.arrowLeft),k(r.style)};return window.addEventListener(`resize`,e),()=>window.removeEventListener(`resize`,e)},[E,X]),(0,i.useEffect)(()=>{E||(ve.current=null)},[E]);let Je=(0,i.useCallback)(e=>{X?.chain().focus().setImage({src:e}).run()},[X]),Ye=(0,i.useCallback)(e=>{(X?.commands).insertVideo?.({src:e})},[X]),Xe=W&&de&&!Y&&!De,Ze=!Xe&&!G&&(W||Ue&&!(!w&&pe)),Qe=(0,i.useRef)(!1);return(0,i.useEffect)(()=>{Qe.current||(Qe.current=!0,W&&!Xe&&ce(!0))},[W,Xe]),(0,i.useEffect)(()=>{if(!G)return;let e=e=>{let t=e.target;Ae.current?.contains(t)||ce(!1)},t=e=>{e.key===`Escape`&&ce(!1)};return document.addEventListener(`mousedown`,e),document.addEventListener(`touchstart`,e,{passive:!0}),document.addEventListener(`keydown`,t),()=>{document.removeEventListener(`mousedown`,e),document.removeEventListener(`touchstart`,e),document.removeEventListener(`keydown`,t)}},[G]),(0,i.useEffect)(()=>{if(!X||!Xe)return;let e=be.current;if(!(e instanceof HTMLElement))return;let t=t=>{let n=t.deltaY;if(n===0)return;let r=e.scrollTop<=0,i=!(e.scrollTop+e.clientHeight>=e.scrollHeight-1);if(n>0&&i||n<0&&!r){e.scrollTop+=n,t.preventDefault(),t.stopPropagation();return}let a=Te(X),o=a?we(a):null;if(o){o.scrollTop+=n,t.preventDefault(),t.stopPropagation();return}};return e.addEventListener(`wheel`,t,{passive:!1}),()=>e.removeEventListener(`wheel`,t)},[X,Xe]),X?(0,a.jsxs)(`div`,{className:`qingwu-editor-row`,children:[(0,a.jsxs)(`div`,{ref:q,className:`qingwu-editor relative flex-1 min-w-0 bg-background ${w?`qingwu-editor--readonly`:``} ${g?``:`rounded-xl border border-default-200`} ${h}`,style:_,children:[v&&(0,a.jsxs)(`div`,{className:`qed-toolbar`,children:[(0,a.jsxs)(`div`,{className:`qed-toolbar__group`,children:[(0,a.jsx)(`button`,{type:`button`,className:`qed-tb-btn qed-tb-btn--desktop-only${W?` is-active`:``}`,onClick:()=>{W?(se(!1),ce(!1)):(se(!0),de&&!Y&&!De||ce(!0))},title:W?`隐藏目录`:`显示目录`,"aria-label":W?`隐藏目录`:`显示目录`,"aria-pressed":W,children:(0,a.jsx)(`svg`,{fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,strokeWidth:2,"aria-hidden":`true`,children:(0,a.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M4 6h16M4 12h10M4 18h7`})})}),b&&(0,a.jsx)(`button`,{type:`button`,className:`qed-tb-btn${le?` is-active`:``}`,onClick:()=>ue(!le),title:`查找 (Ctrl+F)`,"aria-label":`查找`,"aria-pressed":le,children:(0,a.jsx)(`svg`,{fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,strokeWidth:2,"aria-hidden":`true`,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`})})}),!w&&(0,a.jsx)(`button`,{type:`button`,className:`qed-tb-btn qed-tb-btn--ai${E?` is-active`:``}`,onClick:e=>E?D(!1):qe(e.currentTarget),title:e.o(`editor.toolbar.aiTitle`),"aria-label":e.o(`editor.toolbar.ai`),"aria-pressed":E,children:(0,a.jsxs)(`svg`,{fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,strokeWidth:2,"aria-hidden":`true`,children:[(0,a.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,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`,{strokeLinecap:`round`,strokeLinejoin:`round`,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`})]})})]}),(0,a.jsxs)(`div`,{className:`qed-toolbar__group`,children:[(0,a.jsxs)(`button`,{type:`button`,className:`qed-tb-btn qed-tb-btn--solid`,onClick:()=>re(!0),title:e.o(`editor.toolbar.exportTitle`),children:[(0,a.jsx)(`svg`,{fill:`none`,viewBox:`0 0 24 24`,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`})}),(0,a.jsx)(`span`,{className:`qed-tb-btn__label`,children:e.o(`editor.toolbar.export`)})]}),(0,a.jsx)(`button`,{type:`button`,className:`qed-tb-btn${Y?` is-active`:``}`,onClick:je,title:Y?`退出网页全屏`:`网页全屏`,"aria-label":Y?`退出网页全屏`:`网页全屏`,"aria-pressed":Y,children:(0,a.jsx)(`svg`,{fill:`none`,viewBox:`0 0 24 24`,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`,className:`qed-tb-btn${De?` is-active`:``}`,onClick:Me,title:De?`退出全屏`:`全屏`,"aria-label":De?`退出全屏`:`全屏`,"aria-pressed":De,children:(0,a.jsx)(`svg`,{fill:`none`,viewBox:`0 0 24 24`,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`})})})]})]}),X&&!w&&X.isEditable&&(0,a.jsx)(l.BubbleMenu,{editor:X,shouldShow:({editor:e,state:t})=>!(e.isActive(`image`)||e.isActive(`videoEmbed`)||e.isActive(`codeBlock`)||e.isActive(`audioEmbed`)||e.isActive(`attachmentEmbed`)||t.selection.empty),options:{placement:`bottom`,offset:8,flip:!0},className:`bubble-menu-pop bg-background border border-default-200 rounded-xl p-1 shadow-lg`,children:(0,a.jsxs)(`div`,{ref:xe,className:`bubble-menu-items relative flex items-center gap-0.5`,onPointerDown:e=>{e.target.closest(`button`)&&e.preventDefault()},children:[Re.map(e=>(0,a.jsx)(`button`,{type:`button`,className:`flex items-center justify-center w-7 h-7 rounded-lg transition-colors ${e.isActive(X)?`bg-primary/10 text-primary`:`text-default-600 hover:bg-default-100`}`,onClick:t=>{t.preventDefault(),ze(e)},title:e.label,"aria-label":e.label,children:e.icon},e.key)),(0,a.jsx)(`span`,{className:`w-px h-4 bg-default-200 mx-0.5 shrink-0`,"aria-hidden":`true`}),(0,a.jsx)(`button`,{type:`button`,className:`flex items-center justify-center w-7 h-7 rounded-lg transition-colors ${E?`bg-primary/15 text-primary`:`text-primary hover:bg-primary/10`}`,onClick:e=>{e.preventDefault(),Ce(!1),Z?.command(X)},title:Z?.label,"aria-label":Z?.label,children:(0,a.jsx)(nt,{})}),(0,a.jsx)(`span`,{className:`w-px h-4 bg-default-200 mx-0.5 shrink-0`,"aria-hidden":`true`}),(0,a.jsx)(`button`,{type:`button`,"aria-expanded":Se,className:`flex items-center justify-center w-7 h-7 rounded-lg transition-colors ${Se?`bg-default-100 text-default-900`:`text-default-600 hover:bg-default-100`}`,onClick:e=>{e.preventDefault(),Ce(e=>!e)},title:e.o(`editor.bubble.more`),"aria-label":e.o(`editor.bubble.more`),children:(0,a.jsx)(rt,{})}),Se&&(0,a.jsx)(`div`,{role:`menu`,className:`bubble-more-menu absolute right-0 top-full z-[9999] mt-1 w-max max-h-[70vh] overflow-y-auto flex-col gap-1 rounded-xl border border-default-200 bg-background p-1.5 shadow-xl`,onPointerDown:e=>{e.target.closest(`button`)&&e.preventDefault()},children:Le.map(e=>(0,a.jsxs)(`button`,{type:`button`,role:`menuitem`,className:`flex items-center gap-2 w-full whitespace-nowrap px-3 py-1.5 text-xs rounded-md transition-colors ${Be(e)?`bg-primary/10 text-primary`:`text-default-600 hover:bg-default-100`}`,onClick:t=>{t.preventDefault(),ze(e)},title:e.label,children:[(0,a.jsx)(`span`,{className:`w-4 h-4 flex items-center justify-center shrink-0`,children:e.icon}),(0,a.jsx)(`span`,{className:`tracking-wide`,children:e.label})]},e.key))})]})}),X&&z!==`none`&&(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(`div`,{className:`fixed inset-0 z-[9998]`,onClick:()=>B(`none`)}),(0,a.jsx)(`div`,{style:V,className:`bg-background border border-default-200 rounded-xl shadow-xl`,onClick:e=>e.stopPropagation(),children:z===`highlight`?(0,a.jsxs)(`div`,{className:`flex items-center gap-1 p-1.5 flex-wrap`,children:[Fr.map(e=>(0,a.jsx)(`button`,{type:`button`,className:`w-5 h-5 rounded-full border border-default-200 hover:scale-110 transition-transform`,style:{background:e.color},title:e.name,onClick:()=>{X.chain().focus().setHighlight({color:e.color}).run(),B(`none`)}},e.color)),(0,a.jsxs)(`button`,{type:`button`,className:`w-5 h-5 rounded-full border border-default-200 text-default-500 hover:bg-default-100 flex items-center justify-center text-[10px]`,title:`清除高亮`,onClick:()=>{X.chain().focus().unsetHighlight().run(),B(`none`)},children:[`✕`,` `]})]}):(0,a.jsxs)(`div`,{className:`flex items-center gap-1.5 p-1.5`,children:[(0,a.jsx)(`input`,{type:`url`,className:`flex-1 px-2 py-1 text-xs rounded-md border border-default-200 bg-background focus:outline-none focus:border-primary`,placeholder:`https://...`,value:ie,onChange:e=>ae(e.target.value),onKeyDown:e=>{e.key===`Enter`?(ie.trim()&&X.chain().focus().setLink({href:ie.trim()}).run(),B(`none`)):e.key===`Escape`&&B(`none`)}}),(0,a.jsx)(`button`,{type:`button`,className:`px-2 py-1 text-xs rounded-md bg-primary text-white hover:opacity-90`,onClick:()=>{ie.trim()&&X.chain().focus().setLink({href:ie.trim()}).run(),B(`none`)},children:`确定`})]})})]}),!w&&E&&(0,u.createPortal)((0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(`div`,{className:`fixed inset-0 z-[9998]`,onClick:()=>D(!1)}),(0,a.jsxs)(`div`,{ref:P,"data-lenis-prevent":!0,style:O,className:`ai-panel relative flex flex-col bg-background border border-default-200 rounded-xl shadow-xl${A===`above`?` ai-panel--above`:``}`,onClick:e=>e.stopPropagation(),children:[(0,a.jsx)(`span`,{className:`ai-panel__arrow`,style:{left:`${M}%`},"aria-hidden":`true`}),(0,a.jsx)(xt,{editor:X,onClose:()=>D(!1)})]})]}),document.body),F&&(0,a.jsx)(i.Suspense,{fallback:(0,a.jsx)(qr,{}),children:(0,a.jsx)(Hr,{open:F,onClose:()=>ee(!1),onInsert:Je,validate:e=>X?Et(X.state.doc,e,{maxAttachmentSize:p,maxTotalAttachmentSize:m}):null})}),I&&(0,a.jsx)(i.Suspense,{fallback:(0,a.jsx)(qr,{}),children:(0,a.jsx)(Gr,{open:I,onClose:()=>L(!1),onInsert:Ye})}),te&&(0,a.jsx)(i.Suspense,{fallback:(0,a.jsx)(qr,{}),children:(0,a.jsx)(Ur,{open:te,onClose:()=>R(!1)})}),ne&&(0,a.jsx)(i.Suspense,{fallback:(0,a.jsx)(qr,{}),children:(0,a.jsx)(Wr,{open:ne,onClose:()=>re(!1),editor:X})}),U&&(0,a.jsx)(i.Suspense,{fallback:(0,a.jsx)(qr,{}),children:(0,a.jsx)(Kr,{open:!!U,filename:U.filename,onRender:()=>{U.resolve(`render`),oe(null)},onAttach:()=>{U.resolve(`attach`),oe(null)},onClose:()=>{U.resolve(null),oe(null)}})}),(0,a.jsx)(`div`,{ref:he,className:`flex editor-body`,children:(0,a.jsxs)(`div`,{className:`relative min-w-0 flex-1`,children:[(0,a.jsx)(c.EditorContent,{editor:X}),!w&&(0,a.jsx)(Pr,{editor:X}),(0,a.jsx)(`div`,{className:`${Y||De?`fixed`:`absolute`} bottom-2 right-4 z-10 pointer-events-none select-none`,children:(0,a.jsxs)(`span`,{className:`text-xs ${Ke?`bg-danger/10 text-danger font-medium px-2 py-0.5 rounded`:f&&Q>f*.9?`bg-warning/10 text-warning px-2 py-0.5 rounded`:`text-default-300`}`,children:[Q,f?` / ${f}`:``,` 字`]})})]})}),b&&le&&(0,a.jsx)(Ge,{editor:X,onClose:()=>ue(!1)}),Ze&&(0,a.jsx)(`button`,{type:`button`,className:`qingwu-toc-fab`,onClick:()=>ce(!0),title:`目录`,"aria-label":`打开目录`,children:(0,a.jsx)(`svg`,{fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,strokeWidth:2,"aria-hidden":`true`,children:(0,a.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M4 6h16M4 12h10M4 18h7`})})}),G&&(0,u.createPortal)((0,a.jsxs)(`div`,{ref:Ae,className:`qingwu-toc-drawer toc-scroll`,"data-lenis-prevent":!0,children:[(0,a.jsxs)(`div`,{className:`qed-drawer-head`,children:[(0,a.jsx)(`span`,{className:`qed-drawer-head__title`,children:`目录`}),(0,a.jsx)(`button`,{type:`button`,className:`qed-drawer-head__close`,onClick:()=>ce(!1),"aria-label":`关闭目录`,children:(0,a.jsx)(`svg`,{fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,strokeWidth:2,"aria-hidden":`true`,children:(0,a.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M6 18L18 6M6 6l12 12`})})})]}),(0,a.jsx)(ke,{editor:X,className:`!p-3`,onClose:()=>{ce(!1),se(!1)}})]}),document.body)]}),Xe&&(0,u.createPortal)((0,a.jsx)(`aside`,{ref:be,className:`qingwu-toc-desktop toc-scroll`,children:(0,a.jsx)(ke,{editor:X,onClose:()=>se(!1)})}),document.body)]}):(0,a.jsx)(`div`,{className:`flex items-center justify-center h-32 text-default-400`,children:e.o(`editor.loading`)})};function Yr(e){let t=async t=>{let n=t.data;if(!n||typeof n!=`object`||n.kind!==`qingwu-clip`)return;let r=t.origin;if(r&&r!==`null`&&r!==window.location.origin)return;let i=n.clip;if(i?.markdown)try{await e.onClip(i,t)}catch(e){console.warn(`[qingwu-clipper] 处理剪藏失败:`,e)}};return window.addEventListener(`message`,t),{close:()=>window.removeEventListener(`message`,t)}}function Xr(e){return r.n({endpoint:`https://cos.${e.region}.myqcloud.com`,bucket:e.bucket,region:e.region,accessKeyId:e.secretId,secretAccessKey:e.secretKey,customDomain:e.customDomain,uploadPrefix:e.uploadPrefix,nameTemplate:e.nameTemplate})}function Zr(e){return r.n({endpoint:`https://${e.bucket}.${e.region}.aliyuncs.com`,bucket:e.bucket,region:e.region,accessKeyId:e.accessKeyId,secretAccessKey:e.accessKeySecret,customDomain:e.customDomain,uploadPrefix:e.uploadPrefix,nameTemplate:e.nameTemplate})}exports.CODE_LANGUAGES=gn,exports.CodeBlock=Sn,exports.ImageUpload=Kn,exports.ImageUploadDialog=ye,exports.QingWuAIEditor=Jr,exports.RelativeMedia=yr,exports.SearchHighlight=Ue,exports.TocPanel=ke,exports.VideoEmbed=ln,exports.buildSystemPrompt=Ae,exports.createAILanguageModelProvider=Me,exports.createCOSStorage=Xr,exports.createDeepSeekProvider=Fe,exports.createLocalStorage=r.t,exports.createOSSStorage=Zr,exports.createOpenAICompatProvider=Pe,exports.createOpenAIProvider=Ie,exports.createQwenProvider=Le,exports.createS3Storage=r.n,exports.createSlashCommandExtension=xr,exports.escapeHtml=e.t,exports.formatBytes=wt,exports.getAIProvider=Ne,exports.getBubbleMenuActions=Or,exports.getDefaultSlashCommands=Sr,exports.getDocAttachmentTotal=Ct,exports.getEditorExtensions=wr,exports.getLocale=e.i,exports.getSearchEngine=Dr,exports.getSearchState=We,exports.getStorageInfo=n.t,exports.getStorageProvider=n.n,exports.loadStorageConfig=n.r,exports.registerS3PreviewConfig=t.t,exports.sanitizeHtml=e.n,exports.sanitizeSvg=e.r,exports.setAIProvider=X,exports.setConfirmProvider=Mt,exports.setLocale=e.a,exports.setSearchEngine=Er,exports.setStorageProvider=n.a,exports.setToastProvider=ge,exports.signPreviewUrlHeaders=t.r,exports.startBrowserClipperReceiver=Yr,exports.subscribeToast=_e,exports.t=e.o,exports.tf=e.s,exports.toast=J,exports.validateAttachmentFile=Et;
|