@qingwu-ui/ai-editor 1.1.6 → 1.1.7
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/dist/clipper.cjs +1 -1
- package/dist/clipper.js +48 -30
- package/dist/components/export-dialog.d.ts.map +1 -1
- package/dist/components/release-notes-dialog.d.ts.map +1 -1
- package/dist/editor/ai-editor.d.ts.map +1 -1
- package/dist/editor/clipper/receiver-browser.d.ts.map +1 -1
- package/dist/editor/clipper/receiver-node.d.ts.map +1 -1
- package/dist/editor/clipper/types.d.ts +3 -1
- package/dist/editor/clipper/types.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/image-upload.d.ts.map +1 -1
- package/dist/editor/extensions/index.d.ts.map +1 -1
- package/dist/editor/extensions/list-quote-highlight.d.ts +4 -0
- package/dist/editor/extensions/list-quote-highlight.d.ts.map +1 -0
- package/dist/editor/extensions/qingwu-ui.d.ts.map +1 -1
- package/dist/editor/extensions/slash-command.d.ts.map +1 -1
- package/dist/editor/i18n/en-US.d.ts +7 -3
- package/dist/editor/i18n/en-US.d.ts.map +1 -1
- package/dist/editor/i18n/zh-CN.d.ts +7 -3
- package/dist/editor/i18n/zh-CN.d.ts.map +1 -1
- package/dist/editor/storage/providers/s3.d.ts +6 -0
- package/dist/editor/storage/providers/s3.d.ts.map +1 -1
- package/dist/editor/storage/signed-fetch.d.ts +1 -1
- package/dist/editor/storage/signed-fetch.d.ts.map +1 -1
- package/dist/editor/utils/document-export.d.ts +12 -0
- package/dist/editor/utils/document-export.d.ts.map +1 -0
- package/dist/editor/utils/insert-media.d.ts +7 -0
- package/dist/editor/utils/insert-media.d.ts.map +1 -0
- package/dist/editor/utils/sanitize.d.ts +1 -5
- package/dist/editor/utils/sanitize.d.ts.map +1 -1
- package/dist/export-dialog-Bnbjhxoc.js +3349 -0
- package/dist/export-dialog-Co3pPwTl.cjs +16 -0
- package/dist/index.cjs +15 -15
- package/dist/index.js +1163 -1223
- package/dist/local-A1ZU5Y6C.js +15 -0
- package/dist/local-a2ROEKrE.cjs +1 -0
- package/dist/{md-import-dialog-DbC-NCH_.js → md-import-dialog-WLWQ4INh.js} +1 -2
- package/dist/sanitize-BebkUITX.cjs +1 -0
- package/dist/{sanitize-Cm8YOT1D.js → sanitize-ths-sP-x.js} +40 -26
- package/dist/signed-fetch-BuPD4Q0V.cjs +7 -0
- package/dist/signed-fetch-iBM0Zozv.js +191 -0
- package/dist/{storage-DUcmM2Ex.js → storage-D68X3FCl.js} +1 -2
- package/dist/storage-settings-dialog-BPlrjhQc.cjs +1 -0
- package/dist/{storage-settings-dialog-DnWNQWjN.js → storage-settings-dialog-DfJuUAkg.js} +27 -26
- package/dist/styles.css +1 -1
- package/dist/video-embed-dialog-DwcFWipC.cjs +1 -0
- package/dist/{video-embed-dialog-B0_pc5xe.js → video-embed-dialog-eCCrqLDP.js} +3 -8
- package/package.json +28 -27
- package/dist/export-dialog-BwVrBASi.js +0 -162
- package/dist/export-dialog-wG4oZtsB.cjs +0 -13
- package/dist/local-B20eAPCo.js +0 -93
- package/dist/local-D4481lUa.cjs +0 -3
- package/dist/sanitize-DfFeo1bZ.cjs +0 -1
- package/dist/signed-fetch-BO5NjYGN.cjs +0 -5
- package/dist/signed-fetch-CPPWCUUS.js +0 -102
- package/dist/storage-settings-dialog-LY_-VFA4.cjs +0 -1
- package/dist/video-embed-dialog-f5HKKPzg.cjs +0 -1
package/dist/index.cjs
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("./sanitize-
|
|
2
|
-
`?i=`break`:e===` `||e===` `?i=`space`:ie(r)&&(i=R(r)?`punct`:`cjk`),n.push({text:e,width:ne(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 ae(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 oe=typeof window<`u`&&window.matchMedia(`(prefers-reduced-motion: reduce)`).matches,H=`13.5px -apple-system, BlinkMacSystemFont, "SF Pro Text", "PingFang SC", "Microsoft YaHei", system-ui, sans-serif`;function U(){if(typeof window>`u`)return 290;let e=window.innerWidth;return e<=480?Math.max(140,e-98):290}var W={info:`<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="10"/><line x1="12" y1="16" x2="12" y2="12"/><line x1="12" y1="8" x2="12.01" y2="8"/></svg>`,success:`<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="10"/><path d="M9 12l2 2 4-4"/></svg>`,warning:`<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M10.29 3.86L1.82 18a2 2 0 0 0 1.71 3h16.94a2 2 0 0 0 1.71-3L13.71 3.86a2 2 0 0 0-3.42 0z"/><line x1="12" y1="9" x2="12" y2="13"/><line x1="12" y1="17" x2="12.01" y2="17"/></svg>`,error:`<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="10"/><line x1="15" y1="9" x2="9" y2="15"/><line x1="9" y1="9" x2="15" y2="15"/></svg>`},se=1;function G(){return`qt${se++}${Date.now().toString(36)}`}function K(e,t,n){let r=document.createElement(e);return t&&(r.className=t),n!=null&&(r.innerHTML=n),r}function ce(e,t){let n=t.split(/\*\*(.+?)\*\*/g);for(let t=0;t<n.length;t++){let r=n[t];if(r)if(t%2==1){let t=K(`em`,`qt-mark`);t.textContent=r,e.appendChild(t)}else e.appendChild(document.createTextNode(r))}}var le={type:`info`,position:`top-center`,duration:4e3,maxVisible:5,persist:!1,persistMaxVisible:3,maxLines:void 0,vibrate:!0},ue=[80,40,80];function de(){if(!(typeof navigator>`u`||!(`vibrate`in navigator)))try{navigator.vibrate(ue)}catch{}}var fe=class{containers=new Map;opts={...le};toasts=new Map;queue=[];_seq=0;constructor(e){e&&Object.assign(this.opts,e)}ensureContainer(e){let t=this.containers.get(e);return t||(t=K(`div`,`qt-container`),t.setAttribute(`data-qt-pos`,e),t.setAttribute(`role`,`status`),t.setAttribute(`aria-live`,`polite`),t.setAttribute(`aria-atomic`,`false`),document.body.appendChild(t),this.containers.set(e,t)),t}show(e,t){let n=t?.type??this.opts.type,r=t?.position??this.opts.position,i=t?.persist??this.opts.persist?0:t?.duration??this.opts.duration,a=t?.dismissible??!0,o=t?.maxLines??this.opts.maxLines,s=t?.description,c=t?.action,l=G(),u={id:l,type:n,dismissible:a,position:r,duration:i,order:++this._seq,element:this.buildElement(l,e,n,a,o,s,c),timer:null};return this.toasts.size>=this.opts.maxVisible?(this.queue.push(u),l):(this.mount(u),l)}info(e,t){return this.show(e,{...t,type:`info`})}success(e,t){return this.show(e,{...t,type:`success`})}warn(e,t){return this.show(e,{...t,type:`warning`})}error(e,t){return this.show(e,{...t,type:`error`})}promise(e,t,n){let r=this.show(t.loading,{...n,type:`info`,duration:0,dismissible:!1});return e.then(e=>{this.dismiss(r);let i=typeof t.success==`function`?t.success(e):t.success;requestAnimationFrame(()=>{this.success(i,{...n,persist:!1})})},e=>{this.dismiss(r);let i=typeof t.error==`function`?t.error(e):t.error;requestAnimationFrame(()=>{this.error(i,{...n,persist:!1})})}),r}dismiss(e){if(e){let t=this.toasts.get(e);t&&this._exit(t)}else this.dismissAll()}dismissAll(){for(let e of this.toasts.values())this._exit(e);this.queue.length=0}configure(e){Object.assign(this.opts,e)}destroy(){for(let e of this.toasts.values())e.timer&&clearTimeout(e.timer);this.toasts.clear(),this.queue.length=0;for(let e of this.containers.values())e.remove();this.containers.clear()}buildElement(e,t,n,r,i,a,o){let s=K(`div`,`qt-toast qt-${n}${i==null?``:` qt-truncate`}${a||o?` qt-rich`:``}`);s.setAttribute(`data-qt-id`,e);let c=K(`span`,`qt-icon`);c.innerHTML=W[n],s.appendChild(c);let l=K(`div`,`qt-body`),u=K(`span`,`qt-msg`),d=ae(t,{maxWidth:U(),lineHeight:1,maxLines:i},H);if(d.lineCount<=1?ce(u,t):d.lines.forEach((e,t)=>{let n=K(`span`,`qt-line`),r=e.text;t===d.lines.length-1&&d.truncated&&!r.endsWith(`…`)&&(r+=`…`),ce(n,r),u.appendChild(n)}),l.appendChild(u),a){let e=K(`div`,`qt-desc`);e.textContent=a,l.appendChild(e)}if(s.appendChild(l),o){let t=K(`button`,`qt-action`);t.type=`button`,t.textContent=o.label,t.addEventListener(`click`,t=>{t.stopPropagation(),this.dismiss(e),o.onClick()}),s.appendChild(t)}if(r){let t=K(`button`,`qt-close`,`<svg width="10" height="10" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round"><path d="M18 6 6 18M6 6l12 12"/></svg>`);t.type=`button`,t.setAttribute(`aria-label`,`关闭通知`),t.addEventListener(`click`,t=>{t.stopPropagation(),this.dismiss(e)}),s.appendChild(t)}return r&&s.addEventListener(`click`,t=>{t.target.closest(`.qt-close, .qt-action`)||this.dismiss(e)}),s}mount(e){e.duration===0&&this.evictPersistIfNeeded(e);let t=this.ensureContainer(e.position);this.toasts.set(e.id,e),t.appendChild(e.element),e.type===`error`&&this.opts.vibrate&&de(),requestAnimationFrame(()=>{requestAnimationFrame(()=>{e.element.classList.add(`qt-enter`)})}),e.duration>0&&(e.timer=setTimeout(()=>this.dismiss(e.id),e.duration))}evictPersistIfNeeded(e){let t=this.opts.persistMaxVisible;if(t<=0)return;let n=[...this.toasts.values()].filter(t=>t.position===e.position&&t.duration===0);for(;n.length>=t;){n.sort((e,t)=>e.order-t.order);let e=n.shift();if(!e)break;this._exit(e)}}_exit(e){e.timer&&=(clearTimeout(e.timer),null),e.element.classList.remove(`qt-enter`),e.element.classList.add(`qt-exit`);let t=()=>{e.element.remove(),this.toasts.delete(e.id),this._dequeue()};if(oe)t();else{let n=!1,r=()=>{n||(n=!0,t())};e.element.addEventListener(`transitionend`,r,{once:!0}),setTimeout(r,400)}}_dequeue(){if(!this.queue.length||this.toasts.size>=this.opts.maxVisible)return;let e=this.queue.shift();this.mount(e)}},pe=null;function q(){return pe||=new fe,pe}var me=Object.assign((e,t)=>q().show(e,t),{info:(e,t)=>q().info(e,t),success:(e,t)=>q().success(e,t),warn:(e,t)=>q().warn(e,t),error:(e,t)=>q().error(e,t),promise:(e,t,n)=>q().promise(e,t,n),dismiss:e=>q().dismiss(e),dismissAll:()=>q().dismissAll(),configure:e=>q().configure(e)}),he=new Set,ge=null;function _e(e){ge=e}function J(e,t=`error`,n){let r={persist:!0,...n};if(he.size>0){for(let n of he)n(e,t,r);return}if(ge){ge(e,t,r);return}t===`success`?me.success(e,r):t===`info`?me.info(e,r):me.error(e,r)}function ve(e){return he.add(e),()=>{he.delete(e)}}var ye=e.c({ImageUploadDialog:()=>be}),be=({open:e,onClose:t,onInsert:r,validate:o})=>{let[s,c]=(0,i.useState)(`upload`),[l,u]=(0,i.useState)(!1),[d,f]=(0,i.useState)(!1),[p,m]=(0,i.useState)(null),[h,g]=(0,i.useState)(null),[_,v]=(0,i.useState)(``),[y,b]=(0,i.useState)(null),x=(0,i.useRef)(null),S=(()=>{try{let e=n.n();return{name:e.name,type:e.type}}catch{return{name:`未配置`,type:`none`}}})(),C=(0,i.useCallback)(()=>{u(!1),m(null),g(null),b(null),v(``),f(!1)},[]),w=(0,i.useCallback)(()=>{C(),t()},[C,t]),T=(0,i.useCallback)(async e=>{let t=e.name.split(`.`).pop()?.toLowerCase();if(!t||![`png`,`jpg`,`jpeg`,`gif`,`webp`,`svg`,`bmp`,`avif`].includes(t)){m(`不支持的图片格式: ${t||`未知`}`);return}let r=o?o(e):e.size>20*1024*1024?`图片大小不能超过 20MB`:null;if(r){m(r),J(r);return}f(!0),m(null);let i=URL.createObjectURL(e);g(i);try{let t=await n.n().upload(e,`editor`);URL.revokeObjectURL(i),b(t),g(t)}catch(e){m(e instanceof Error?e.message:`上传失败`),URL.revokeObjectURL(i),g(null)}finally{f(!1)}},[o]),E=(0,i.useCallback)(e=>{let t=e.target.files?.[0];t&&T(t)},[T]),D=(0,i.useCallback)(e=>{e.preventDefault(),u(!1);let t=e.dataTransfer.files[0];t&&T(t)},[T]),O=(0,i.useCallback)(e=>{let t=e.clipboardData.items;for(let n of Array.from(t))if(n.type.startsWith(`image/`)){e.preventDefault();let t=n.getAsFile();t&&T(t);return}},[T]),k=(0,i.useCallback)(()=>{_.trim()&&(r(_.trim()),w())},[_,r,w]),A=(0,i.useCallback)(()=>{y&&(r(y),w())},[y,r,w]);return e?(0,a.jsxs)(`div`,{className:`fixed inset-0 z-[9999] flex items-center justify-center`,children:[(0,a.jsx)(`div`,{className:`absolute inset-0 bg-black/40 backdrop-blur-sm`,onClick:w}),(0,a.jsxs)(`div`,{className:`relative w-[calc(100vw-2rem)] max-w-[420px] max-h-[90dvh] bg-background rounded-2xl shadow-2xl border border-default-200 overflow-hidden animate-in`,onPaste:s===`upload`?O:void 0,children:[(0,a.jsxs)(`div`,{className:`flex items-center justify-between px-5 py-4 border-b border-default-100`,children:[(0,a.jsx)(`h2`,{className:`text-base font-semibold`,children:`插入图片`}),(0,a.jsx)(`button`,{type:`button`,className:`w-7 h-7 flex items-center justify-center rounded-lg text-default-400 hover:text-default-600 hover:bg-default-100 transition-colors`,onClick:w,children:`✕`})]}),(0,a.jsx)(`div`,{className:`flex border-b border-default-100 px-5`,children:[`upload`,`url`].map(e=>(0,a.jsx)(`button`,{type:`button`,className:`px-4 py-2.5 text-sm font-medium transition-colors border-b-2 -mb-[1px] ${s===e?`border-primary text-primary`:`border-transparent text-default-400 hover:text-default-600`}`,onClick:()=>{c(e),m(null)},children:e===`upload`?`上传图片`:`图片链接`},e))}),(0,a.jsx)(`div`,{className:`p-5`,children:s===`upload`?(0,a.jsxs)(`div`,{className:`space-y-4`,children:[(0,a.jsxs)(`div`,{className:`flex items-center gap-2 px-3 py-2 rounded-lg bg-default-50 text-xs text-default-500`,children:[(0,a.jsx)(`span`,{className:`w-1.5 h-1.5 rounded-full bg-green-500`}),`存储服务:`,S.name]}),!h&&(0,a.jsxs)(`div`,{className:`relative flex flex-col items-center justify-center gap-3 py-10 px-4 rounded-xl border-2 border-dashed transition-all cursor-pointer ${l?`border-primary bg-primary/5 scale-[1.01]`:`border-default-200 hover:border-default-300 hover:bg-default-50`}`,onDragOver:e=>{e.preventDefault(),u(!0)},onDragLeave:()=>u(!1),onDrop:D,onClick:()=>x.current?.click(),children:[(0,a.jsx)(`div`,{className:`w-14 h-14 rounded-full bg-default-100 flex items-center justify-center`,children:(0,a.jsx)(`svg`,{className:`w-7 h-7 text-default-400`,fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,strokeWidth:1.5,children:(0,a.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M3 16.5v2.25A2.25 2.25 0 005.25 21h13.5A2.25 2.25 0 0021 18.75V16.5m-13.5-9L12 3m0 0l4.5 4.5M12 3v13.5`})})}),(0,a.jsxs)(`div`,{className:`text-center`,children:[(0,a.jsx)(`p`,{className:`text-sm font-medium text-default-700`,children:l?`松开放入`:`拖拽图片到此处`}),(0,a.jsx)(`p`,{className:`text-xs text-default-400 mt-1`,children:`或点击选择文件 · 支持粘贴图片`}),(0,a.jsx)(`p`,{className:`text-[10px] text-default-300 mt-1`,children:`PNG / JPG / GIF / WebP / AVIF · 最大 20MB`})]}),(0,a.jsx)(`input`,{ref:x,type:`file`,accept:`image/*`,className:`hidden`,onChange:E})]}),h&&(0,a.jsxs)(`div`,{className:`space-y-3`,children:[(0,a.jsxs)(`div`,{className:`relative rounded-xl overflow-hidden bg-default-100`,children:[(0,a.jsx)(`img`,{src:h,alt:`预览`,className:`w-full max-h-48 object-contain`}),d&&(0,a.jsx)(`div`,{className:`absolute inset-0 bg-black/40 flex items-center justify-center`,children:(0,a.jsxs)(`div`,{className:`flex flex-col items-center gap-2`,children:[(0,a.jsx)(`div`,{className:`w-8 h-8 border-2 border-white border-t-transparent rounded-full animate-spin`}),(0,a.jsx)(`span`,{className:`text-white text-xs`,children:`上传中…`})]})})]}),y&&!d&&(0,a.jsxs)(`div`,{className:`flex items-center gap-2 px-3 py-2 rounded-lg bg-green-50 text-xs text-green-700`,children:[(0,a.jsx)(`svg`,{className:`w-4 h-4 shrink-0`,fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,strokeWidth:2,children:(0,a.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M5 13l4 4L19 7`})}),`上传成功,已存储至 `,S.name]}),(0,a.jsxs)(`div`,{className:`flex gap-2`,children:[(0,a.jsx)(`button`,{type:`button`,className:`flex-1 py-2 rounded-xl bg-primary text-white text-sm font-medium disabled:opacity-40 transition-opacity`,disabled:!y||d,onClick:A,children:`插入图片`}),(0,a.jsx)(`button`,{type:`button`,className:`px-4 py-2 rounded-xl border border-default-200 text-sm hover:bg-default-50 transition-colors`,onClick:C,disabled:d,children:`重新选择`})]})]}),p&&(0,a.jsxs)(`div`,{className:`flex items-start gap-2 px-3 py-2.5 rounded-lg bg-danger-50 text-sm text-danger`,children:[(0,a.jsx)(`svg`,{className:`w-4 h-4 shrink-0 mt-0.5`,fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,strokeWidth:2,children:(0,a.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-2.5L13.732 4c-.77-.833-2.694-.833-3.464 0L3.34 16.5c-.77.833.192 2.5 1.732 2.5z`})}),(0,a.jsx)(`span`,{children:p})]})]}):(0,a.jsxs)(`div`,{className:`space-y-4`,children:[(0,a.jsxs)(`div`,{children:[(0,a.jsx)(`label`,{className:`block text-xs text-default-500 mb-1.5`,children:`图片链接地址`}),(0,a.jsx)(`input`,{type:`url`,className:`w-full px-3 py-2.5 rounded-xl border border-default-200 bg-background text-sm focus:outline-none focus:border-primary transition-colors`,placeholder:`https://example.com/image.png`,value:_,onChange:e=>v(e.target.value),onKeyDown:e=>{e.key===`Enter`&&k()}})]}),_&&(0,a.jsx)(`div`,{className:`rounded-xl overflow-hidden bg-default-100`,children:(0,a.jsx)(`img`,{src:_,alt:`预览`,className:`w-full max-h-40 object-contain`,onError:e=>{e.target.style.display=`none`}})}),(0,a.jsx)(`button`,{type:`button`,className:`w-full py-2.5 rounded-xl bg-primary text-white text-sm font-medium disabled:opacity-40 transition-opacity`,disabled:!_.trim(),onClick:k,children:`插入图片`})]})}),(0,a.jsxs)(`div`,{className:`px-5 py-3 border-t border-default-100 text-[11px] text-default-300 text-center`,children:[`图片将上传至 `,S.name]})]})]}):null};function xe(e,t){return`${e.trim().toLowerCase().replace(/[^\p{L}\p{N}\s-]/gu,``).replace(/\s+/g,`-`).slice(0,40)||`heading`}-${t}`}function Se(e){let t=[],n=[];for(let r of e){let e={...r,children:[]};for(;n.length>0&&n[n.length-1].level>=e.level;)n.pop();n.length>0?n[n.length-1].children.push(e):t.push(e),n.push(e)}return t}function Ce(e){let t=new Set,n=e=>{for(let r of e)r.children.length>0&&(t.add(r.id),n(r.children))};return n(e),t}function we(e,t){let n=[];for(let r of e)n.push(r),r.children.length>0&&!t.has(r.id)&&n.push(...we(r.children,t));return n}function Te(e,t){let n=t.toLowerCase(),r=e=>{let t=[];for(let i of e){let e=i.text.toLowerCase().includes(n),a=r(i.children);(e||a.length>0)&&t.push({...i,children:e?i.children:a})}return t};return r(e)}function Ee(e){let t=e.parentElement;for(;t&&t!==document.documentElement;){let e=getComputedStyle(t).overflowY;if((e===`auto`||e===`scroll`||e===`overlay`)&&t.scrollHeight>t.clientHeight)return t;t=t.parentElement}return null}function De(e){if(e.isDestroyed)return null;try{return e.view.dom}catch{return null}}function Oe(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 ke=84,Y=3e3,Ae=({editor:e,className:t=``,onClose:n})=>{let[r,o]=(0,i.useState)([]),[s,c]=(0,i.useState)(``),[l,u]=(0,i.useState)(new Set),[d,f]=(0,i.useState)(``),p=(0,i.useRef)(``),m=(0,i.useRef)([]),h=(0,i.useRef)(null),g=(0,i.useRef)(null),_=(0,i.useRef)(null),v=(0,i.useRef)(0),y=(0,i.useCallback)(()=>{_.current&&=(clearTimeout(_.current.timer),null)},[]),b=(0,i.useCallback)(()=>{let t=De(e);return t?Array.from(t.querySelectorAll(`h1,h2,h3,h4,h5,h6`)).map((e,t)=>(e.id||=xe(e.textContent||``,t),{id:e.id,level:Number(e.tagName.slice(1)),text:e.textContent?.trim()||`(无标题)`,el:e})):[]},[e]),x=(0,i.useCallback)(()=>{let e=m.current;if((!e.length||e.some(e=>!e.el.isConnected))&&(e=b(),m.current=e),!e.length)return;let t=g.current,n=(t?t.getBoundingClientRect().top:0)+ke,r=t?t.scrollHeight-t.scrollTop-t.clientHeight<2:document.documentElement.scrollHeight-window.scrollY-window.innerHeight<2,i=``;for(let t of e)t.el.isConnected&&t.el.getBoundingClientRect().top<=n&&(i=t.id);if(r){for(let t=e.length-1;t>=0;t--)if(e[t].el.isConnected){i=e[t].id;break}}let a=_.current;if(a){let t=e.find(e=>e.id===a.id);if(!(!t||!t.el.isConnected||r||t.el.getBoundingClientRect().top<=n))return;y()}c(i)},[b,y]),S=(0,i.useCallback)(()=>{v.current||=requestAnimationFrame(()=>{v.current=0,x()})},[x]),C=(0,i.useCallback)(()=>{let e=b(),t=e.map(e=>`${e.level}:${e.text}`).join(`|`);t!==p.current&&(p.current=t,m.current=e,o(e),S())},[b,S]);(0,i.useEffect)(()=>{let t=De(e),n=t?Ee(t):null;g.current=n;let r=n??window;return r.addEventListener(`scroll`,S,{passive:!0}),window.addEventListener(`resize`,S),r.addEventListener(`wheel`,y,{passive:!0}),r.addEventListener(`touchstart`,y,{passive:!0}),()=>{r.removeEventListener(`scroll`,S),window.removeEventListener(`resize`,S),r.removeEventListener(`wheel`,y),r.removeEventListener(`touchstart`,y)}},[e,S,y]),(0,i.useEffect)(()=>{let t=null,n=()=>{let n=[];e.state.doc.descendants(e=>{e.type.name===`heading`&&n.push(`${e.attrs.level}:${e.textContent}`)}),n.join(`|`)!==p.current&&(t&&clearTimeout(t),t=setTimeout(C,300))};e.on(`update`,n);let r=requestAnimationFrame(C);return()=>{e.off(`update`,n),t&&clearTimeout(t),cancelAnimationFrame(r),y(),v.current&&=(cancelAnimationFrame(v.current),0)}},[e,C,y]);let w=(0,i.useCallback)(t=>{let n=De(e);if(!n)return;let r=t.el;if((!r||!n.contains(r))&&(r=n.querySelector(`[id="${CSS.escape(t.id)}"]`)),!r){let e=`h${t.level}`,i=n.querySelectorAll(e);for(let e of i)if(e.textContent?.trim()===t.text){r=e;break}}if(!r)return;y(),_.current={id:t.id,timer:setTimeout(y,Y)},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-ke,behavior:`smooth`})}else window.scrollTo({top:window.scrollY+a-ke,behavior:`smooth`})},[e,y]),T=(0,i.useMemo)(()=>Se(r),[r]),E=(0,i.useMemo)(()=>Ce(T),[T]),D=(0,i.useMemo)(()=>{let e=new Map,t=(n,r)=>{for(let i of n)r&&e.set(i.id,r),t(i.children,i.id)};return t(T,``),e},[T]),O=d.trim().length>0,k=(0,i.useMemo)(()=>O?Te(T,d.trim()):T,[T,O,d]),A=(0,i.useMemo)(()=>we(k,O?new Set:l),[k,l,O]),j=(0,i.useMemo)(()=>new Set(A.map(e=>e.id)),[A]),M=(0,i.useMemo)(()=>{let e=s;for(;e&&!j.has(e);)e=D.get(e)??``;return e},[s,j,D]);(0,i.useEffect)(()=>{let e=h.current;if(!e||!M)return;let t=e.closest(`.toc-scroll`);if(!(t instanceof HTMLElement))return;let n=e.querySelector(`[data-toc-id="${CSS.escape(M)}"]`);if(!n)return;let r=t.getBoundingClientRect(),i=n.getBoundingClientRect();i.top<r.top+8?t.scrollTop-=r.top+8-i.top:i.bottom>r.bottom-8&&(t.scrollTop+=i.bottom-(r.bottom-8))},[M]);let N=(0,i.useCallback)(e=>{u(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},[]),P=(0,i.useCallback)(()=>{u(new Set(E))},[E]),F=(0,i.useCallback)(()=>{u(new Set)},[]);return r.length?(0,a.jsxs)(`nav`,{ref:h,className:`toc-panel ${t}`,"aria-label":`目录`,children:[(0,a.jsxs)(`div`,{className:`toc-title`,children:[n?(0,a.jsx)(`button`,{type:`button`,className:`toc-close-btn`,onClick:n,title:`收起目录`,"aria-label":`收起目录`,children:(0,a.jsxs)(`svg`,{width:`15`,height:`15`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,"aria-hidden":`true`,children:[(0,a.jsx)(`rect`,{x:`3`,y:`3`,width:`18`,height:`18`,rx:`2`}),(0,a.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M9 3v18`}),(0,a.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`m16 15-3-3 3-3`})]})}):(0,a.jsx)(`span`,{className:`toc-title__icon`,"aria-hidden":`true`,children:(0,a.jsx)(`svg`,{width:`14`,height:`14`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,children:(0,a.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M4 6h16M4 12h10M4 18h7`})})}),(0,a.jsx)(`span`,{className:`toc-title__text`,children:`目录`}),(0,a.jsxs)(`div`,{className:`toc-actions`,children:[(0,a.jsx)(`button`,{type:`button`,className:`toc-action-btn`,onClick:P,title:`全部折叠`,"aria-label":`全部折叠`,disabled:O,children:(0,a.jsx)(`svg`,{width:`14`,height:`14`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,"aria-hidden":`true`,children:(0,a.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M5 12h14`})})}),(0,a.jsx)(`button`,{type:`button`,className:`toc-action-btn`,onClick:F,title:`全部展开`,"aria-label":`全部展开`,disabled:O,children:(0,a.jsx)(`svg`,{width:`14`,height:`14`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,"aria-hidden":`true`,children:(0,a.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M12 5v14M5 12h14`})})})]})]}),(0,a.jsxs)(`div`,{className:`toc-search`,children:[(0,a.jsx)(`svg`,{className:`toc-search__icon`,width:`13`,height:`13`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,"aria-hidden":`true`,children:(0,a.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M21 21l-4.35-4.35M17 11a6 6 0 11-12 0 6 6 0 0112 0z`})}),(0,a.jsx)(`input`,{type:`text`,className:`toc-search__input`,placeholder:`搜索标题...`,value:d,onChange:e=>f(e.target.value),"aria-label":`搜索标题`}),d&&(0,a.jsx)(`button`,{type:`button`,className:`toc-search__clear`,onClick:()=>f(``),title:`清除`,"aria-label":`清除搜索`,children:(0,a.jsx)(`svg`,{width:`12`,height:`12`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,"aria-hidden":`true`,children:(0,a.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M6 18L18 6M6 6l12 12`})})})]}),A.length===0?(0,a.jsx)(`div`,{className:`toc-search__empty`,children:O?`未找到"${d.trim()}"相关标题`:`文档暂无标题`}):(0,a.jsx)(`ul`,{className:`toc-list`,children:A.map(e=>{let t=E.has(e.id),n=l.has(e.id);return(0,a.jsxs)(`li`,{"data-toc-id":e.id,className:`toc-item ${M===e.id?`is-active`:``}`,style:{paddingLeft:`${(e.level-1)*12+12}px`},children:[t?(0,a.jsx)(`button`,{type:`button`,className:`toc-toggle ${n?`is-collapsed`:`is-expanded`}`,onClick:t=>{t.stopPropagation(),N(e.id)},title:n?`展开子标题`:`折叠子标题`,"aria-label":n?`展开子标题`:`折叠子标题`,"aria-expanded":!n,children:(0,a.jsx)(`svg`,{width:`10`,height:`10`,viewBox:`0 0 24 24`,fill:`currentColor`,"aria-hidden":`true`,children:(0,a.jsx)(`path`,{d:`M8 5v14l11-7z`})})}):(0,a.jsx)(`span`,{className:`toc-bullet`,"aria-hidden":!0}),(0,a.jsx)(`button`,{type:`button`,className:`toc-link`,onClick:()=>w(e),title:e.text,children:(0,a.jsx)(`span`,{className:`toc-text`,children:O?Oe(e.text,d.trim()):e.text})})]},e.id)})})]}):(0,a.jsxs)(`div`,{className:`toc-panel ${t}`,style:{padding:`24px 16px`,textAlign:`center`},children:[(0,a.jsx)(`div`,{className:`toc-empty`,children:`文档暂无标题`}),(0,a.jsx)(`div`,{className:`toc-empty-hint`,children:`使用 # 标记可创建标题`})]})};function je(e,t){return{continue:`你是一个写作助手。请从下文尾部自然流畅地续写内容,保持风格一致。只输出续写的内容,不要加任何前缀说明。`,improve:`你是一个文字润色专家。请优化以下文本的表达,提升文采和流畅度,保持原意不变。只输出润色后的文本。`,shorter:`你是一个精简专家。请将以下文本精简,保留核心信息,删除冗余。只输出精简后的文本。`,longer:`你是一个内容扩写专家。请丰富以下文本的细节和层次,增加深度。只输出扩写后的文本。`,fix:`你是一个校对专家。请修正以下文本中的语法错误、错别字和标点问题。只输出修正后的文本。`,translate:`你是一个翻译专家。请将以下文本翻译为英文。只输出翻译后的文本。`,zap:t||`你是一个全能的 AI 写作助手。请根据用户的指令处理文本。`}[e]}var Me=null;async function Ne(e){let t;try{({createOpenAI:t}=await import(`@ai-sdk/openai`))}catch{throw Error(`缺少可选依赖 @ai-sdk/openai。使用默认 provider 请先安装:npm i @ai-sdk/openai;或调用 setAIProvider() 注册自定义 provider。`)}let n=t({apiKey:e.apiKey,baseURL:e.baseURL}).chat(e.model);return{async*stream(e){let t=await(0,o.streamText)({model:n,system:je(e.mode,e.instruction),prompt:e.context,temperature:.7,maxOutputTokens:2048});for await(let e of t.textStream)yield e},async generate(e){return(await(0,o.generateText)({model:n,system:je(e.mode,e.instruction),prompt:e.context,temperature:.7,maxOutputTokens:2048})).text}}}function Pe(e){Me=e}function Fe(){if(!Me)throw Error(`未配置 AI 服务。请调用 createAILanguageModelProvider() 创建并通过 setAIProvider() 注册。`);return Me}function Ie(e){let{apiKey:t,baseURL:n,model:r,headers:i}=e;async function*a(e,a){let o=await fetch(`${n}/chat/completions`,{method:`POST`,headers:{"Content-Type":`application/json`,Authorization:`Bearer ${t}`,...i},body:JSON.stringify({model:r,messages:[{role:`system`,content:e},{role:`user`,content:a}],stream:!0,temperature:.7,max_tokens:2048})});if(!o.ok){let e=await o.text();throw Error(`AI API 错误 (${o.status}): ${e}`)}let s=o.body?.getReader();if(!s)throw Error(`无法读取响应流`);let c=new TextDecoder,l=``;for(;;){let{done:e,value:t}=await s.read();if(e)break;l+=c.decode(t,{stream:!0});let n=l.split(`
|
|
3
|
-
`);l=n.pop()||``;for(let e of n){let t=e.trim();if(!t||!t.startsWith(`data: `))continue;let n=t.slice(6);if(n===`[DONE]`)return;try{let e=JSON.parse(n).choices?.[0]?.delta?.content;e&&(yield e)}catch{}}}}return{async*stream(e){yield*a(je(e.mode,e.instruction),e.context)},async generate(e){let t=je(e.mode,e.instruction),n=``;for await(let r of a(t,e.context))n+=r;return n}}}function X(e){return Ie({apiKey:e.apiKey,baseURL:e.baseURL||`https://api.deepseek.com/v1`,model:e.model||`deepseek-v4-flash`,headers:e.headers})}function Le(e){return Ie({apiKey:e.apiKey,baseURL:e.baseURL||`https://api.openai.com/v1`,model:e.model||`gpt-5.6-luna`,headers:e.headers})}function Re(e){return Ie({apiKey:e.apiKey,baseURL:e.baseURL||`https://dashscope.aliyuncs.com/compatible-mode/v1`,model:e.model||`qwen3.7-plus`,headers:e.headers})}var ze={keyword:``,caseSensitive:!1,wholeWord:!1,matches:[],currentIndex:-1},Z=new f.PluginKey(`search-highlight`);function Be(e){return e.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`)}function Ve(e,t){let{keyword:n,caseSensitive:r,wholeWord:i}=t;if(!n)return[];let a=r?`g`:`gi`,o=i?`\\b${Be(n)}\\b`:Be(n),s=new RegExp(o,a),c=[];return e.descendants((e,t)=>{if(!e.isText||!e.text)return;s.lastIndex=0;let n;for(;(n=s.exec(e.text))!==null;){let e=t+n.index,r=e+n[0].length;c.push({from:e,to:r}),n[0].length===0&&s.lastIndex++}}),c}function He(e,t){if(t.matches.length===0)return p.DecorationSet.empty;let n=t.matches.map((e,n)=>p.Decoration.inline(e.from,e.to,{class:n===t.currentIndex?`search-highlight search-highlight--active`:`search-highlight`}));return p.DecorationSet.create(e,n)}function Ue(e,t){if(t.currentIndex<0||t.currentIndex>=t.matches.length)return;let n=t.matches[t.currentIndex];n&&requestAnimationFrame(()=>{try{let t=e.dom.querySelector(`.search-highlight--active`);if(t){let e=t.getBoundingClientRect(),n=window.innerHeight-80;(e.top<120||e.bottom>n)&&t.scrollIntoView({behavior:`smooth`,block:`center`});return}let r=e.coordsAtPos(n.from),i=window.innerHeight-80;if(r.top<120||r.top>i){let e=r.top-window.innerHeight/2;window.scrollBy({top:e,behavior:`smooth`})}}catch{}})}var We=d.Extension.create({name:`searchHighlight`,addProseMirrorPlugins(){return[new f.Plugin({key:Z,state:{init:()=>ze,apply(e,t){let n=e.getMeta(Z);if(n)return{...t,...n,matches:n.matches===void 0?t.matches:n.matches,currentIndex:n.currentIndex===void 0?t.currentIndex:n.currentIndex};if(e.docChanged&&t.keyword){let n=Ve(e.doc,t),r=t.currentIndex;return r>=n.length&&(r=n.length-1),r<0&&(r=n.length>0?0:-1),{...t,matches:n,currentIndex:r}}return t}},props:{decorations(e){let t=Z.getState(e);return t?He(e.doc,t):p.DecorationSet.empty}}})]},addCommands(){return{setSearch:(e,t={})=>({state:n,dispatch:r,view:i})=>{let a=Z.getState(n)||ze,o={keyword:e,caseSensitive:t.caseSensitive??a.caseSensitive,wholeWord:t.wholeWord??a.wholeWord,matches:[],currentIndex:-1};return o.matches=Ve(n.doc,o),o.currentIndex=o.matches.length>0?0:-1,r&&(r(n.tr.setMeta(Z,o)),i&&Ue(i,o)),!0},nextMatch:()=>({state:e,dispatch:t,view:n})=>{let r=Z.getState(e)||ze;if(r.matches.length===0)return!1;let i=(r.currentIndex+1)%r.matches.length;return t&&(t(e.tr.setMeta(Z,{currentIndex:i})),n&&Ue(n,{...r,currentIndex:i})),!0},prevMatch:()=>({state:e,dispatch:t,view:n})=>{let r=Z.getState(e)||ze;if(r.matches.length===0)return!1;let i=(r.currentIndex-1+r.matches.length)%r.matches.length;return t&&(t(e.tr.setMeta(Z,{currentIndex:i})),n&&Ue(n,{...r,currentIndex:i})),!0},clearSearch:()=>({state:e,dispatch:t})=>(t&&t(e.tr.setMeta(Z,ze)),!0)}}});function Ge(e){let t=e.state;return Z.getState(t)||ze}var Ke=({editor:e,onClose:t})=>{let[n,r]=(0,i.useState)(``),[o,s]=(0,i.useState)(!1),[c,l]=(0,i.useState)(!1),[u,d]=(0,i.useState)(0),f=(0,i.useRef)(null),p=(0,i.useRef)({keyword:n,caseSensitive:o,wholeWord:c});p.current={keyword:n,caseSensitive:o,wholeWord:c},(0,i.useEffect)(()=>{if(!e)return;let t=0,n=()=>{t&&cancelAnimationFrame(t),t=requestAnimationFrame(()=>{t=0,d(e=>(e+1)%1e6)})};return e.on(`update`,n),()=>{e.off(`update`,n),t&&cancelAnimationFrame(t)}},[e]),(0,i.useEffect)(()=>{let e=setTimeout(()=>f.current?.focus(),30);return()=>clearTimeout(e)},[]),(0,i.useEffect)(()=>{if(!e)return;let t=requestAnimationFrame(()=>{let{keyword:t,caseSensitive:n,wholeWord:r}=p.current;try{e.commands.setSearch(t,{caseSensitive:n,wholeWord:r})}catch(e){console.warn(`[SearchBar] setSearch failed:`,e)}});return()=>cancelAnimationFrame(t)},[e,n,o,c]),(0,i.useEffect)(()=>()=>{try{e?.commands.clearSearch()}catch{}},[]),(0,i.useEffect)(()=>{let e=e=>{e.key===`Escape`&&(e.preventDefault(),e.stopPropagation(),t())};return window.addEventListener(`keydown`,e,!0),()=>window.removeEventListener(`keydown`,e,!0)},[t]);let m=(0,i.useCallback)(()=>{try{e?.commands.nextMatch()}catch{}},[e]),h=(0,i.useCallback)(()=>{try{e?.commands.prevMatch()}catch{}},[e]),g=(0,i.useCallback)(e=>{e.stopPropagation(),e.key===`Enter`&&(e.preventDefault(),e.shiftKey?h():m())},[m,h]),_=(0,i.useMemo)(()=>{if(!e)return null;try{return Ge(e)}catch{return null}},[e,n,o,c,u]),v=n?_&&_.matches.length>0?`${_.currentIndex+1} / ${_.matches.length}`:`无匹配`:``,y=(0,i.useCallback)(e=>{e.stopPropagation()},[]);return(0,a.jsx)(`div`,{className:`search-bar`,role:`search`,"aria-label":`文档内搜索`,onClick:y,onMouseDown:y,children:(0,a.jsxs)(`div`,{className:`search-bar__main`,children:[(0,a.jsx)(`svg`,{className:`search-bar__icon`,width:`14`,height:`14`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,children:(0,a.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M21 21l-6-6m2-5a7 7 0 11-14 0 7 7 0 0114 0z`})}),(0,a.jsx)(`input`,{ref:f,type:`text`,className:`search-bar__input`,placeholder:`查找…`,value:n,onChange:e=>r(e.target.value),onKeyDown:g,onKeyUp:y,onKeyPress:y,onInput:y,spellCheck:!1,autoComplete:`off`,inputMode:`text`}),(0,a.jsx)(`span`,{className:`search-bar__count`,children:v}),(0,a.jsx)(`button`,{type:`button`,className:`search-bar__toggle${o?` search-bar__toggle--active`:``}`,onClick:()=>s(e=>!e),title:`区分大小写 (Aa)`,"aria-pressed":o,children:`Aa`}),(0,a.jsx)(`button`,{type:`button`,className:`search-bar__toggle${c?` search-bar__toggle--active`:``}`,onClick:()=>l(e=>!e),title:`整词匹配 (\\b)`,"aria-pressed":c,children:`\\b`}),(0,a.jsx)(`div`,{className:`search-bar__sep`}),(0,a.jsx)(`button`,{type:`button`,className:`search-bar__btn`,onClick:h,title:`上一个 (Shift+Enter)`,disabled:!_||_.matches.length===0,children:(0,a.jsx)(`svg`,{width:`14`,height:`14`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,children:(0,a.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M5 15l7-7 7 7`})})}),(0,a.jsx)(`button`,{type:`button`,className:`search-bar__btn`,onClick:m,title:`下一个 (Enter)`,disabled:!_||_.matches.length===0,children:(0,a.jsx)(`svg`,{width:`14`,height:`14`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,children:(0,a.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M19 9l-7 7-7-7`})})}),(0,a.jsx)(`button`,{type:`button`,className:`search-bar__btn search-bar__btn--close`,onClick:t,title:`关闭 (Esc)`,children:(0,a.jsx)(`svg`,{width:`14`,height:`14`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,children:(0,a.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M6 18L18 6M6 6l12 12`})})})]})})};function Q({children:e,...t}){return(0,a.jsx)(`svg`,{width:16,height:16,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:2,strokeLinecap:`round`,strokeLinejoin:`round`,"aria-hidden":`true`,...t,children:e})}var qe=e=>(0,a.jsxs)(Q,{...e,children:[(0,a.jsx)(`path`,{d:`M6 4h8a4 4 0 0 1 0 8H6z`}),(0,a.jsx)(`path`,{d:`M6 12h9a4 4 0 0 1 0 8H6z`})]}),Je=e=>(0,a.jsxs)(Q,{...e,children:[(0,a.jsx)(`path`,{d:`M19 4h-9`}),(0,a.jsx)(`path`,{d:`M14 20H5`}),(0,a.jsx)(`path`,{d:`M15 4 9 20`})]}),Ye=e=>(0,a.jsxs)(Q,{...e,children:[(0,a.jsx)(`path`,{d:`M6 4v6a6 6 0 0 0 12 0V4`}),(0,a.jsx)(`path`,{d:`M4 20h16`})]}),Xe=e=>(0,a.jsxs)(Q,{...e,children:[(0,a.jsx)(`path`,{d:`M16 4H9a3 3 0 0 0-2.83 4`}),(0,a.jsx)(`path`,{d:`M14 12a4 4 0 0 1 0 8H6`}),(0,a.jsx)(`path`,{d:`M4 12h16`})]}),Ze=e=>(0,a.jsxs)(Q,{...e,children:[(0,a.jsx)(`path`,{d:`m16 18 6-6-6-6`}),(0,a.jsx)(`path`,{d:`m8 6-6 6 6 6`})]}),Qe=e=>(0,a.jsxs)(Q,{...e,children:[(0,a.jsx)(`path`,{d:`m9 11-6 6v3h9l3-3`}),(0,a.jsx)(`path`,{d:`m22 12-4.6 4.6a2 2 0 0 1-2.8 0l-5.2-5.2a2 2 0 0 1 0-2.8L14 4`})]}),$e=e=>(0,a.jsxs)(Q,{...e,children:[(0,a.jsx)(`path`,{d:`M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71`}),(0,a.jsx)(`path`,{d:`M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71`})]}),et=e=>(0,a.jsxs)(Q,{...e,children:[(0,a.jsx)(`rect`,{x:`3`,y:`3`,width:`18`,height:`18`,rx:`2`,ry:`2`}),(0,a.jsx)(`path`,{d:`M3 9h18M3 15h18M9 3v18M15 3v18`})]}),tt=e=>(0,a.jsxs)(Q,{...e,children:[(0,a.jsx)(`rect`,{x:`8`,y:`8`,width:`14`,height:`14`,rx:`2`,ry:`2`}),(0,a.jsx)(`path`,{d:`M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2`})]}),nt=e=>(0,a.jsxs)(Q,{...e,children:[(0,a.jsx)(`circle`,{cx:`11`,cy:`11`,r:`8`}),(0,a.jsx)(`path`,{d:`m21 21-4.3-4.3`})]}),rt=e=>(0,a.jsxs)(Q,{...e,children:[(0,a.jsx)(`path`,{d:`M12 3l1.6 4.4L18 9l-4.4 1.6L12 15l-1.6-4.4L6 9l4.4-1.6L12 3z`}),(0,a.jsx)(`path`,{d:`M18.5 14l.7 1.9 1.9.7-1.9.7-.7 1.9-.7-1.9-1.9-.7 1.9-.7.7-1.9z`})]}),it=e=>(0,a.jsx)(Q,{...e,children:(0,a.jsx)(`path`,{d:`M18 5H6l6 7-6 7h12`})}),at=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`})]}),ot=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 st(e){if(e){if(e.startsWith(`blob:`)){URL.revokeObjectURL(e);return}try{await n.n().remove(e)}catch(e){console.warn(`删除存储资源失败:`,e)}}}var ct=3e4,lt=new Set([`image`,`attachmentEmbed`,`audioEmbed`,`videoEmbed`]),ut=new WeakMap;function dt(e){let t=new Set;return e.state.doc.descendants(e=>{if(lt.has(e.type.name)){let n=e.attrs.src;n&&t.add(n)}return!0}),t}function ft(e){let t=ut.get(e);return t||(t={timers:new Map,onTransaction:()=>{},listening:!1},ut.set(e,t)),t}function pt(e,t){let n=[...new Set(t.filter(Boolean))];if(n.length===0)return;let r=ft(e);r.listening||=(r.onTransaction=()=>{if(r.timers.size===0)return;let t=dt(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(()=>{dt(e).has(t)||st(t),r.timers.delete(t)},ct);r.timers.set(t,n)}}function mt(e){let t=ut.get(e);if(t){if(t.listening&&=(e.off(`transaction`,t.onTransaction),!1),t.timers.size>0){let n=dt(e);for(let[e,r]of t.timers)clearTimeout(r),n.has(e)||st(e);t.timers.clear()}ut.delete(e)}}var ht=[{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:`⚡`}],gt=new Set([`image`,`attachmentEmbed`,`audioEmbed`,`videoEmbed`]),_t={image:`editor.ai.nodeImage`,attachmentEmbed:`editor.ai.nodeAttachment`,videoEmbed:`editor.ai.nodeVideo`,audioEmbed:`editor.ai.nodeAudio`};function vt(e,t){return e.storage.qingwuUI?.parseMd?.(e.schema,t)||null}function yt(e,t,n){let r=[];return e.state.doc.nodesBetween(t,n,e=>{if(gt.has(e.type.name)){let t=e.attrs.src;t&&r.push({type:e.type.name,src:t})}return!0}),r}function bt(e){let t=new Set;return e.state.doc.descendants(e=>{if(gt.has(e.type.name)){let n=e.attrs.src;n&&t.add(n)}return!0}),t}function xt(e,t){let n=vt(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 St(e,t,n,r){let i=vt(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 Ct({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=Fe(),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(yt(t,r.from,r.to).map(e=>e.src));e===`replaceAll`?xt(t,n):St(t,n,`replace`,_.current);let a=bt(t);pt(t,[...i].filter(e=>!a.has(e)))},[t]),w=(0,i.useCallback)(e=>{if(e===`below`){St(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=yt(t,i.from,i.to);if(a.length>0){g({position:e,willRemove:a});return}C(e,l,i),n()},[t,l,C,n]),T=(0,i.useCallback)(()=>{if(!h)return;let{position:e}=h,r=e===`replaceAll`?{from:0,to:t.state.doc.content.size}:{from:_.current.from,to:_.current.to};C(e,l,r),g(null),n()},[h,t,l,C,n]),E=(0,i.useCallback)(()=>{u(``),o(null),m(null)},[]),D={};for(let e of h?.willRemove??[])D[e.type]=(D[e.type]??0)+1;return(0,a.jsxs)(a.Fragment,{children:[(0,a.jsxs)(`div`,{className:`ai-selector w-full flex-1 min-h-0 flex flex-col`,children:[(0,a.jsxs)(`div`,{className:`flex items-center justify-between pl-3 pr-1.5 py-1.5 border-b border-default-100 shrink-0`,children:[(0,a.jsxs)(`span`,{className:`flex items-center gap-1.5 text-xs font-medium text-default-500`,children:[(0,a.jsx)(rt,{className:`text-primary`}),e.o(`editor.ai.trigger`)]}),(0,a.jsx)(`button`,{type:`button`,onClick:n,"aria-label":e.o(`editor.ai.close`),title:e.o(`editor.ai.close`),className:`flex items-center justify-center w-6 h-6 rounded-md text-default-400 hover:bg-default-100 hover:text-default-700 transition-colors`,children:(0,a.jsx)(ot,{})})]}),(0,a.jsx)(`div`,{className:`grid grid-cols-[repeat(auto-fit,minmax(64px,1fr))] gap-1.5 p-2 shrink-0`,children:ht.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(_t[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 wt=new Set([`attachmentEmbed`,`videoEmbed`,`audioEmbed`,`image`]);function Tt(e){let t=0;return e.descendants(e=>{wt.has(e.type.name)&&(t+=Number(e.attrs?.size)||0)}),t}function Et(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 Dt(e){return(e?.storage)?.qingwuUI?.limits}function Ot(e,t,n){let{maxAttachmentSize:r,maxTotalAttachmentSize:i}=n;if(r&&t.size>r)return`单文件大小不能超过 ${Et(r)}(当前 ${Et(t.size)})`;if(i){let n=Tt(e)+t.size;if(n>i)return`附件总大小不能超过 ${Et(i)}(当前合计 ${Et(n)})`}return null}var kt=!1,At=null,jt=5e3;function Mt(){return kt}function $(e){kt=e,At&&=(clearTimeout(At),null),e&&(At=setTimeout(()=>{kt=!1,At=null},jt))}var Nt=null;function Pt(e){Nt=e}function Ft(){return Nt}var It=300;function Lt({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=Ft();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<It&&await new Promise(e=>setTimeout(e,It-t)),d(!1),c()}},disabled:l,children:r})]})]})}),document.body)}function Rt(e){return/^(\.\.?\/|[a-zA-Z]:\\|file:\/\/)/.test(e)?!0:!(/^[a-z]+:\/\//i.test(e)||e.startsWith(`/`)||e.startsWith(`data:`)||e.startsWith(`blob:`))}function zt({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-BO5NjYGN.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||Rt(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:()=>{Mt()||($(!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:Rt(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:()=>{Mt()||($(!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)(Lt,{open:m,title:`确认删除图片`,message:F?`该图片无法在当前环境加载,仅从编辑器中移除该图片节点,不影响存储文件。`:`此操作将同时删除对象存储中的文件,不可撤销。`,onCancel:()=>{$(!1),h(!1)},onConfirm:async()=>{if(!F)try{await st(g)}catch{}$(!1),await new Promise(e=>setTimeout(e,300)),n()}})]})}var Bt=(0,i.lazy)(()=>import(`@file-viewer/react`)),Vt=new Set,Ht={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}},Ut={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`},Wt={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 Gt(e){return e?e<1024?`${e} B`:e<1048576?`${(e/1024).toFixed(1)} KB`:`${(e/1048576).toFixed(1)} MB`:``}function Kt(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 qt(e){return e.split(`.`).pop()?.toLowerCase()||``}function Jt(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 Yt(e){return!!e&&!e.startsWith(`file:`)}function Xt(e){return btoa(encodeURIComponent(e)).replace(/\+/g,`-`).replace(/\//g,`_`).replace(/=+$/,``)}async function Zt(e,t){try{let n=Xt(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 $t({node:n,deleteNode:r,selected:o,editor:s}){let l=s?.isEditable??!0,u=n.attrs.src||``,[d,f]=(0,i.useState)(()=>Vt.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,ne]=(0,i.useState)(void 0),[re,ie]=(0,i.useState)(!1),R=n.attrs.src||``,z=n.attrs.name||R&&R.split(`/`).pop()?.split(`?`)[0]||(R?`attachment`:e.o(`editor.attachment.lost`)),B=n.attrs.size||0,V=qt(z),ae=!R;(0,i.useEffect)(()=>{if(!d){ne(void 0),ie(!1);return}let e=Ut[V];if(!e){ne(void 0),ie(!1);return}let t=!0;return ne(void 0),ie(!1),Wt[e]().then(e=>{t&&ne(e)}).catch(n=>{console.error(`[attachment] renderer "${e}" load failed:`,n),t&&ie(!0)}),()=>{t=!1}},[d,V]);let oe=(0,i.useMemo)(()=>({...Ht,renderers:te?[te]:[],rendererMode:`replace`}),[te]),H=(0,i.useCallback)(e=>{f(t=>{let n=typeof e==`function`?e(t):e;return R&&(n?Vt.add(R):Vt.delete(R)),n})},[R]);(0,i.useEffect)(()=>{f(R?Vt.has(R):!1)},[R]);let U=(0,i.useCallback)(()=>{k.current=!0,H(!0),window.setTimeout(()=>{window.scrollTo(0,O.current),A.current&&(A.current.scrollTop=j.current),k.current&&H(!0),k.current=!1},0)},[H]),W=(0,i.useCallback)(async()=>{I===`web`?(L(`none`),document.body.style.overflow=``,U()):(I===`native`&&document.fullscreenElement&&await document.exitFullscreen(),O.current=window.scrollY,j.current=A.current?.scrollTop??0,document.body.style.overflow=`hidden`,L(`web`))},[I]),se=(0,i.useCallback)(async()=>{let e=E.current;e&&(I===`native`?await document.exitFullscreen():(I===`web`&&(L(`none`),document.body.style.overflow=``),O.current=window.scrollY,j.current=A.current?.scrollTop??0,await e.requestFullscreen(),L(`native`)))},[I,U]),G=(0,i.useCallback)(()=>{I===`none`&&(k.current||H(e=>!e))},[I]);(0,i.useEffect)(()=>{let e=()=>{document.fullscreenElement||(I===`native`&&L(`none`),U())},t=e=>{e.key===`Escape`&&I===`web`&&(L(`none`),document.body.style.overflow=``,U())};return document.addEventListener(`fullscreenchange`,e),window.addEventListener(`keydown`,t),()=>{document.removeEventListener(`fullscreenchange`,e),window.removeEventListener(`keydown`,t)}},[I,U]),(0,i.useEffect)(()=>{let e=e=>{if(e.key!==`Backspace`&&e.key!==`Delete`||!l||!o||Mt())return;let t=s?.view?.dom,n=e.target;if(s?.isFocused&&n instanceof Node&&t?.contains(n)){if(e.preventDefault(),e.stopPropagation(),s){let{from:e,to:t}=s.state.selection;P.current={from:e,to:t}}window.getSelection()?.removeAllRanges(),$(!0),N(!0)}};return window.addEventListener(`keydown`,e,!0),()=>window.removeEventListener(`keydown`,e,!0)},[o,s,l]),(0,i.useEffect)(()=>{if(!d||!Yt(R)){m(null),b(null),D.current=null;return}if(D.current===R)return;let e=new AbortController,n=!0;return v(!0),b(null),(async()=>{let r=R.includes(`?X-Amz-`),i=null,a=null;if(!i&&!r&&(i=await Zt(R,e.signal)),!i&&!r)try{let n=await t.n(R);n&&(i=await Zt(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(R);if(n){let t={"X-Requested-With":`XMLHttpRequest`};n.forEach((e,n)=>{t[n]=e});try{i=await Qt(R,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(R,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=R;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===R){v(!1);return}b(e instanceof Error?e.message:`附件读取失败,请检查对象存储 CORS 和公开访问权限`)}}),()=>{n=!1,e.abort()}},[d,R]),(0,i.useEffect)(()=>()=>{h&&URL.revokeObjectURL(h),m(null)},[]),(0,i.useEffect)(()=>()=>{h&&URL.revokeObjectURL(h),g(null),m(null),D.current=null},[R]),(0,i.useEffect)(()=>{if(C!==`success`&&C!==`error`)return;let e=window.setTimeout(()=>w(null),2400);return()=>window.clearTimeout(e)},[C]);let K=(0,i.useCallback)(async()=>{S(!0),w(`loading`);try{if(h){let e=document.createElement(`a`);e.href=h,e.download=z,document.body.appendChild(e),e.click(),document.body.removeChild(e),w(`success`);return}let e=R.includes(`?X-Amz-`),n=null;if(!e)try{let e=await t.n(R);e&&(n=await fetch(e,{headers:{"X-Requested-With":`XMLHttpRequest`}}),n.ok||(n=null))}catch{}if(!n&&!e)try{let e=await t.r(R);e&&(n=await fetch(R,{headers:(()=>{let t=new Headers(e);return t.set(`X-Requested-With`,`XMLHttpRequest`),t})()}),n.ok||(n=null))}catch{}if(n||=await fetch(R,{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=z,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)}},[R,z,h]);return(0,a.jsxs)(c.NodeViewWrapper,{ref:T,as:`div`,className:`attachment-embed group/att ${o?`is-selected`:``}`,contentEditable:!1,children:[(0,a.jsxs)(`div`,{className:`att-inner`,style:o?{outline:`2px solid var(--primary, #6366f1)`,outlineOffset:`2px`}:void 0,children:[(0,a.jsxs)(`div`,{className:`att-header`,children:[(0,a.jsxs)(`div`,{className:`att-info`,children:[(0,a.jsx)(`span`,{className:`att-icon`,children:ae?(0,a.jsxs)(`svg`,{width:`22`,height:`22`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`1.6`,strokeLinecap:`round`,strokeLinejoin:`round`,"aria-hidden":`true`,style:{color:`#9ca3af`},children:[(0,a.jsx)(`path`,{d:`M10.29 3.86 1.82 18a2 2 0 0 0 1.71 3h16.94a2 2 0 0 0 1.71-3L13.71 3.86a2 2 0 0 0-3.42 0z`}),(0,a.jsx)(`path`,{d:`M12 9v4`}),(0,a.jsx)(`path`,{d:`M12 17h.01`})]}):Kt(z)}),(0,a.jsxs)(`div`,{className:`att-meta`,children:[(0,a.jsx)(`span`,{className:`att-name`,children:z}),B>0&&(0,a.jsx)(`span`,{className:`att-size`,children:Gt(B)})]})]}),(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:[R&&Jt(z)&&(0,a.jsx)(`button`,{type:`button`,className:`att-btn`,onMouseDown:e=>{e.preventDefault(),e.stopPropagation(),G()},title:e.o(`editor.attachment.preview`),"aria-label":e.o(`editor.attachment.preview`),children:(0,a.jsxs)(`svg`,{width:`14`,height:`14`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,"aria-hidden":`true`,children:[(0,a.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M2.036 12.322a1.012 1.012 0 010-.639C3.423 7.51 7.36 4.5 12 4.5c4.638 0 8.573 3.007 9.963 7.178.07.207.07.431 0 .639C20.577 16.49 16.64 19.5 12 19.5c-4.638 0-8.573-3.007-9.963-7.178z`}),(0,a.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M15 12a3 3 0 11-6 0 3 3 0 016 0z`})]})}),(0,a.jsx)(`button`,{type:`button`,className:`att-btn`,onClick:K,disabled:x||ae,title:x?`正在准备下载`:e.o(`editor.attachment.download`),"aria-label":x?`正在准备下载`:e.o(`editor.attachment.download`),children:(0,a.jsx)(`svg`,{width:`14`,height:`14`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,"aria-hidden":`true`,children:(0,a.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M4 16v1a3 3 0 003 3h10a3 3 0 003-3v-1m-4-4l-4 4m0 0l-4-4m4 4V4`})})}),l&&(0,a.jsx)(`button`,{type:`button`,className:`att-btn att-btn--del`,onClick:()=>{!l||Mt()||($(!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||re)&&!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||R?te?(0,a.jsx)(Bt,{buffer:p||void 0,url:h||R,name:z,filename:z,type:V,size:B||p?.byteLength||0,options:oe},`${R}-${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)(Lt,{open:M,title:`确认删除附件`,message:ae?`此操作将删除该附件节点,不可撤销。`:`此操作将同时删除对象存储中的文件(${z}),不可撤销。`,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(st(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 st(R),$(!1),await new Promise(e=>setTimeout(e,300)),r()}catch{$(!1)}}})]})}var en=d.Node.create({name:`attachmentEmbed`,group:`block`,atom:!0,inline:!1,addNodeView(){return(0,c.ReactNodeViewRenderer)($t)},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 tn({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:()=>{Mt()||($(!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)(Lt,{open:l,title:`确认删除音频`,message:`此操作将同时删除对象存储中的文件(${s}),不可撤销。`,onCancel:()=>{$(!1),u(!1)},onConfirm:async()=>{try{await st(o)}catch{}$(!1),await new Promise(e=>setTimeout(e,300)),n()}})]})}function nn(e){return/\.(mp3|wav|ogg|flac|aac|m4a|wma|opus)(\?|$)/i.test(e)||/\/.*\.(mp3|wav|ogg|flac)/i.test(e)}var rn=d.Node.create({name:`audioEmbed`,group:`block`,atom:!0,inline:!1,addNodeView(){return(0,c.ReactNodeViewRenderer)(tn)},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(` `)||!nn(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 an(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 on(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 sn({node:e,deleteNode:t,editor:n}){let r=e.attrs.src||``,o=e.attrs.source||`unknown`,s=o===`unknown`?an(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)(Lt,{open:l,title:`确认删除视频`,message:`此操作将同时删除对象存储中的文件,不可撤销。`,onCancel:()=>{$(!1),u(!1)},onConfirm:async()=>{try{await st(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-BO5NjYGN.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=on(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:()=>{Mt()||($(!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:()=>{Mt()||($(!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 cn(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 ln(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 un(e){let t=e.match(/explore\/([a-zA-Z0-9]+)/);return t?t[1]:e}var dn=d.Node.create({name:`videoEmbed`,group:`block`,atom:!0,inline:!1,addNodeView(){return(0,c.ReactNodeViewRenderer)(sn)},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=cn(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:cn(n)}}},{tag:`div[data-bilibili]`},{tag:`div[data-xiaohongshu]`}]},renderHTML({HTMLAttributes:e}){let t=e.src||``,n=cn(t);if(n===`bilibili`){let e=ln(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 un(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=cn(e.src);return t().insertContent({type:this.name,attrs:{...e,source:n}}).focus().run()}}}}),fn=null,pn={fontFamily:`Inter, 'PingFang SC', 'Microsoft YaHei', 'Noto Sans SC', system-ui, sans-serif`,padding:24},mn=.25,hn=4,gn=.25;async function _n(e){return fn||=await import(`pele`),fn.render(e,pn).svg}var vn=[{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`}],yn={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`},bn={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 xn({node:t,updateAttributes:n,editor:r,getPos:o,deleteNode:s,selected:c}){let l=r?.isEditable??!0,d=!l,[f,p]=(0,i.useState)(!1),[m,h]=(0,i.useState)(!1),[g,_]=(0,i.useState)(!1),[v,y]=(0,i.useState)(!1),[b,x]=(0,i.useState)(220),[S,C]=(0,i.useState)({top:0,left:0,width:210}),[w,T]=(0,i.useState)(``),[E,D]=(0,i.useState)(!1),[O,k]=(0,i.useState)(null),[A,j]=(0,i.useState)(null),[M,N]=(0,i.useState)(!1),[P,F]=(0,i.useState)(!1),[ee,I]=(0,i.useState)(1),[L,te]=(0,i.useState)({x:0,y:0}),[ne,re]=(0,i.useState)(!1),ie=(0,i.useRef)(null),R=(0,i.useRef)(null),z=(0,i.useRef)(null),B=(0,i.useRef)(null),V=(0,i.useRef)(null),ae=(0,i.useRef)(null),oe=(0,i.useRef)(null),H=t.attrs.language||``,U=vn.find(e=>e.value===(bn[H]??H)),W=H===`mermaid`,se=e=>Math.min(hn,Math.max(mn,e)),G=e=>I(t=>Math.round(se(t+e)*100)/100),K=()=>{I(1),te({x:0,y:0})},ce=()=>{K(),F(!0)};(0,i.useEffect)(()=>{O||F(!1)},[O]),(0,i.useEffect)(()=>{if(!P)return;let e=document.body.style.overflow;document.body.style.overflow=`hidden`;let t=e=>{e.key===`Escape`&&F(!1)};return window.addEventListener(`keydown`,t),()=>{document.body.style.overflow=e,window.removeEventListener(`keydown`,t)}},[P]);let le=e=>{e.button===0&&(e.currentTarget.setPointerCapture(e.pointerId),ie.current={x:e.clientX,y:e.clientY,panX:L.x,panY:L.y},re(!0))},ue=e=>{let t=ie.current;t&&te({x:t.panX+e.clientX-t.x,y:t.panY+e.clientY-t.y})},de=()=>{ie.current=null,re(!1)},fe=(0,i.useCallback)(()=>{if(!r||typeof o!=`function`)return null;let e=o();return typeof e==`number`?{from:e,to:e+t.nodeSize}:null},[r,o,t.nodeSize]),pe=(0,i.useCallback)(()=>{l&&(Mt()||(oe.current=fe(),window.getSelection()?.removeAllRanges(),$(!0),D(!0)))},[fe,l]),q=(0,i.useMemo)(()=>{let e=w.trim().toLowerCase();return e?vn.filter(t=>t.label.toLowerCase().includes(e)||t.value.toLowerCase().includes(e)):vn},[w]);(0,i.useEffect)(()=>{(ae.current?.closest(`.code-block-node-view`))?.classList.toggle(`code-block-node-view--collapsed`,m)},[m]);let me=(0,i.useCallback)(()=>{let e=B.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=vn.length*31+8,o=r-52,s=i-52;o<220&&s>o?(y(!0),x(Math.max(120,Math.min(a,s))),C({top:t.top,left:n,width:210})):(y(!1),x(Math.max(120,Math.min(a,o))),C({top:t.bottom+4,left:n,width:210}))},[]);(0,i.useEffect)(()=>{if(!g)return;T(``),me();let e=setTimeout(()=>V.current?.focus(),50);return window.addEventListener(`resize`,me),window.addEventListener(`scroll`,me,!0),()=>{clearTimeout(e),window.removeEventListener(`resize`,me),window.removeEventListener(`scroll`,me,!0)}},[g,me]),(0,i.useEffect)(()=>{if(!g)return;let e=e=>{let t=e.target;t&&(B.current?.contains(t)||z.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||Mt())return;let t=r?.view?.dom,n=e.target;if(r?.isFocused&&n instanceof Node&&t?.contains(n)){if(e.preventDefault(),e.stopPropagation(),r){let{from:e,to:t}=r.state.selection;oe.current={from:e,to:t}}window.getSelection()?.removeAllRanges(),$(!0),D(!0)}};return window.addEventListener(`keydown`,e,!0),()=>window.removeEventListener(`keydown`,e,!0)},[c,r,l]);let he=(0,i.useCallback)(e=>{n({language:e||null}),_(!1)},[n]),ge=(0,i.useCallback)(()=>{if(l){if(r&&o){let e=o();r.chain().focus().setNodeSelection(e).run()}_(!1),(r?.storage?.qingwuUI)?.openAI?.()}},[r,o,l]),_e=(0,i.useCallback)(()=>{let e=t.textContent,n=e=>{let t=document.createElement(`textarea`);t.value=e,t.style.position=`fixed`,t.style.opacity=`0`,document.body.appendChild(t),t.select();try{document.execCommand(`copy`)}catch{}document.body.removeChild(t)};navigator.clipboard?.writeText?navigator.clipboard.writeText(e).catch(()=>n(e)):n(e),p(!0),setTimeout(()=>p(!1),1500)},[t.textContent]),J=(0,i.useCallback)(()=>{let e=yn[H]||`txt`,n=e?`code.${e}`:`code.txt`,r=new Blob([t.textContent],{type:`text/plain;charset=utf-8`}),i=URL.createObjectURL(r),a=document.createElement(`a`);a.href=i,a.download=n,document.body.appendChild(a),a.click(),document.body.removeChild(a),URL.revokeObjectURL(i)},[t.textContent,H]),ve=(0,i.useCallback)(async()=>{if(O||M){k(null),j(null),N(!1);return}N(!0),j(null),k(null);try{let n=(t.textContent||``).trim();if(!n){j(`代码块内容为空`);return}let r=e.r(await _n(n));k(r)}catch(e){j(e instanceof Error?e.message:`图表渲染失败`)}finally{N(!1)}},[t.textContent,O,M]),ye=(0,a.jsxs)(a.Fragment,{children:[U?U.deviconClass?(0,a.jsx)(`i`,{className:`${U.deviconClass} colored cb-lang-icon`,style:{color:U.color}}):(0,a.jsx)(`span`,{className:`cb-lang-icon cb-lang-icon--auto`,children:`Tx`}):(0,a.jsx)(`span`,{className:`cb-lang-icon cb-lang-icon--auto`,children:`?`}),(0,a.jsx)(`span`,{className:`cb-lang-label`,children:U?.label||`自动`})]});return(0,a.jsxs)(`div`,{ref:ae,className:`cb-react-shell group/cb`,style:{display:`contents`},children:[(0,a.jsxs)(`div`,{className:`cb-header${m?` cb-header--collapsed`:``}`,contentEditable:!1,onMouseDown:e=>e.stopPropagation(),children:[(0,a.jsx)(`div`,{className:`cb-lang-wrap`,ref:R,contentEditable:!1,children:d?(0,a.jsx)(`span`,{className:`cb-lang-trigger cb-lang-trigger--static`,children:ye}):(0,a.jsxs)(`button`,{ref:B,type:`button`,className:`cb-lang-trigger`,onClick:()=>_(!g),children:[ye,(0,a.jsx)(`svg`,{className:`cb-lang-chevron${g?` cb-lang-chevron--open`:``}`,width:`10`,height:`10`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2.5`,children:(0,a.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M6 9l6 6 6-6`})})]})}),m&&(0,a.jsxs)(`button`,{type:`button`,className:`cb-collapsed-bar`,contentEditable:!1,onClick:()=>h(!1),title:`展开代码块`,children:[ye,(0,a.jsx)(`svg`,{className:`cb-lang-chevron`,width:`12`,height:`12`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2.5`,children:(0,a.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M6 9l6 6 6-6`})})]}),l&&g&&(0,u.createPortal)((0,a.jsxs)(`div`,{ref:z,className:`cb-lang-dropdown${v?` cb-lang-dropdown--up`:``}`,style:{position:`fixed`,top:S.top,left:S.left,width:S.width,zIndex:10002},children:[(0,a.jsxs)(`div`,{className:`cb-lang-search-wrap`,children:[(0,a.jsx)(`svg`,{className:`cb-lang-search-icon`,width:`14`,height:`14`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,children:(0,a.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M21 21l-6-6m2-5a7 7 0 11-14 0 7 7 0 0114 0z`})}),(0,a.jsx)(`input`,{ref:V,className:`cb-lang-search`,type:`text`,placeholder:`搜索语言...`,value:w,onChange:e=>T(e.target.value),onKeyDown:e=>e.stopPropagation()})]}),(0,a.jsxs)(`div`,{className:`cb-lang-list`,style:{maxHeight:b},children:[(0,a.jsxs)(`button`,{type:`button`,className:`cb-lang-option${H?``:` cb-lang-option--active`}`,onClick:()=>he(``),children:[(0,a.jsx)(`span`,{className:`cb-lang-icon cb-lang-icon--auto`,children:`?`}),(0,a.jsx)(`span`,{children:`自动检测`})]}),q.map(e=>(0,a.jsxs)(`button`,{type:`button`,className:`cb-lang-option${H===e.value?` cb-lang-option--active`:``}`,onClick:()=>he(e.value),children:[e.deviconClass?(0,a.jsx)(`i`,{className:`${e.deviconClass} colored cb-lang-icon`,style:{color:e.color}}):(0,a.jsx)(`span`,{className:`cb-lang-icon cb-lang-icon--auto`,children:`Tx`}),(0,a.jsx)(`span`,{children:e.label})]},e.value)),q.length===0&&(0,a.jsx)(`div`,{className:`cb-lang-empty`,children:`无匹配语言`})]})]}),document.body),(0,a.jsxs)(`div`,{className:`cb-actions`,children:[(0,a.jsx)(`button`,{type:`button`,className:`cb-btn`,onClick:()=>h(!m),contentEditable:!1,title:m?`展开`:`折叠`,children:(0,a.jsx)(`svg`,{className:`cb-btn-icon`,fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,strokeWidth:`2`,children:m?(0,a.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M6 9l6 6 6-6`}):(0,a.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M6 15l6-6 6 6`})})}),(0,a.jsx)(`button`,{type:`button`,className:`cb-btn`,onClick:_e,contentEditable:!1,title:`复制`,children:f?(0,a.jsx)(`svg`,{className:`cb-btn-icon cb-btn-icon--check`,fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,strokeWidth:`2.5`,children:(0,a.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M5 13l4 4L19 7`})}):(0,a.jsx)(`svg`,{className:`cb-btn-icon`,fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,strokeWidth:`2`,children:(0,a.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M8 16H6a2 2 0 01-2-2V6a2 2 0 012-2h8a2 2 0 012 2v2m-6 12h8a2 2 0 002-2v-8a2 2 0 00-2-2h-8a2 2 0 00-2 2v8a2 2 0 002 2z`})})}),(0,a.jsx)(`button`,{type:`button`,className:`cb-btn`,onClick:J,contentEditable:!1,title:`下载`,children:(0,a.jsx)(`svg`,{className:`cb-btn-icon`,fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,strokeWidth:`2`,children:(0,a.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M4 16v1a3 3 0 003 3h10a3 3 0 003-3v-1m-4-4l-4 4m0 0l-4-4m4 4V4`})})}),l&&(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(`button`,{type:`button`,className:`cb-btn cb-btn--ai`,onClick:ge,contentEditable:!1,title:`写作助手`,children:(0,a.jsx)(`svg`,{className:`cb-btn-icon`,fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,strokeWidth:`2`,children:(0,a.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M13 10V3L4 14h7v7l9-11h-7z`})})}),(0,a.jsx)(`button`,{type:`button`,className:`cb-btn cb-btn--del`,onClick:pe,contentEditable:!1,title:`删除代码块`,children:(0,a.jsx)(`svg`,{className:`cb-btn-icon`,fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,strokeWidth:`2`,children:(0,a.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16`})})})]}),W&&(0,a.jsx)(`button`,{type:`button`,className:`cb-btn cb-btn--diagram`,onClick:ve,contentEditable:!1,title:O||M?`取消渲染`:`渲染图表`,disabled:M,children:(0,a.jsx)(`svg`,{className:`cb-btn-icon`,fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,strokeWidth:`2`,children:(0,a.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M4 5a1 1 0 011-1h4a1 1 0 011 1v5a1 1 0 01-1 1H5a1 1 0 01-1-1V5zM14 5a1 1 0 011-1h4a1 1 0 011 1v2a1 1 0 01-1 1h-4a1 1 0 01-1-1V5zM4 16a1 1 0 011-1h4a1 1 0 011 1v3a1 1 0 01-1 1H5a1 1 0 01-1-1v-3zM14 13a1 1 0 011-1h4a1 1 0 011 1v6a1 1 0 01-1 1h-4a1 1 0 01-1-1v-6z`})})})]})]}),(O||A||M)&&(0,a.jsxs)(`div`,{className:`cb-diagram-output`,contentEditable:!1,children:[M&&(0,a.jsx)(`div`,{className:`cb-diagram-loading`,children:`渲染图表中…`}),A&&(0,a.jsxs)(`div`,{className:`cb-diagram-error`,children:[(0,a.jsx)(`span`,{className:`cb-diagram-error-icon`,children:`!`}),A]}),O&&(0,a.jsxs)(`div`,{className:`cb-diagram-svg`,role:`button`,tabIndex:0,title:`点击放大查看`,onClick:ce,onKeyDown:e=>{(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),ce())},children:[(0,a.jsx)(`div`,{className:`cb-diagram-svg-inner`,dangerouslySetInnerHTML:{__html:O}}),(0,a.jsx)(`span`,{className:`cb-diagram-zoom-hint`,children:`点击放大`})]})]}),P&&O&&(0,u.createPortal)((0,a.jsxs)(`div`,{className:`fixed inset-0 z-[10002] flex flex-col bg-black/75 backdrop-blur-sm select-none`,role:`dialog`,"aria-modal":`true`,"aria-label":`Mermaid 图表预览`,children:[(0,a.jsxs)(`div`,{className:`flex items-center justify-between gap-3 px-4 py-3 text-white`,children:[(0,a.jsx)(`span`,{className:`text-sm font-medium`,children:`Mermaid 图表`}),(0,a.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,a.jsx)(`button`,{type:`button`,className:`flex h-8 min-w-8 items-center justify-center rounded-lg bg-white/10 px-2 text-base text-white transition-colors hover:bg-white/20`,onClick:()=>G(-.25),title:`缩小`,"aria-label":`缩小`,children:`−`}),(0,a.jsxs)(`button`,{type:`button`,className:`flex h-8 min-w-14 items-center justify-center rounded-lg bg-white/10 px-2 text-xs text-white transition-colors hover:bg-white/20`,onClick:K,title:`重置为 100%`,"aria-label":`重置缩放`,children:[Math.round(ee*100),`%`]}),(0,a.jsx)(`button`,{type:`button`,className:`flex h-8 min-w-8 items-center justify-center rounded-lg bg-white/10 px-2 text-base text-white transition-colors hover:bg-white/20`,onClick:()=>G(gn),title:`放大`,"aria-label":`放大`,children:`+`}),(0,a.jsx)(`button`,{type:`button`,className:`flex h-8 min-w-8 items-center justify-center rounded-lg bg-white/10 px-2 text-sm text-white transition-colors hover:bg-white/20`,onClick:K,title:`重置`,"aria-label":`重置`,children:`⟲`}),(0,a.jsx)(`span`,{className:`mx-1 h-5 w-px bg-white/20`}),(0,a.jsx)(`button`,{type:`button`,className:`flex h-8 min-w-8 items-center justify-center rounded-lg bg-white/10 px-2 text-lg text-white transition-colors hover:bg-white/20`,onClick:()=>F(!1),title:`关闭`,"aria-label":`关闭`,children:`×`})]})]}),(0,a.jsx)(`div`,{className:`flex flex-1 touch-none items-center justify-center overflow-hidden`,style:{cursor:ne?`grabbing`:ee>1?`grab`:`default`},onWheel:e=>G(e.deltaY>0?-.25:gn),onPointerDown:le,onPointerMove:ue,onPointerUp:de,onPointerCancel:de,onDoubleClick:()=>{I(e=>e===1?2:1),te({x:0,y:0})},children:(0,a.jsx)(`div`,{className:`cb-diagram-zoom-content`,style:{transform:`translate(${L.x}px, ${L.y}px) scale(${ee})`,transition:ne?`none`:`transform 120ms ease-out`},dangerouslySetInnerHTML:{__html:O}})})]}),document.body),(0,a.jsx)(Lt,{open:E,title:`确认删除代码块`,message:`此操作不可撤销。`,onCancel:()=>{$(!1),D(!1)},onConfirm:async()=>{await new Promise(e=>setTimeout(e,300)),$(!1),s()}})]})}var Sn=[{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`}],Cn=(0,N.createLowlight)(N.common);Cn.register({dockerfile:M.default}),Cn.registerAlias(`xml`,[`vue`,`html`]),Cn.registerAlias(`javascript`,[`react`,`jsx`]),Cn.registerAlias(`typescript`,[`tsx`]);function wn(e){return e?e.split(`
|
|
4
|
-
`):[``]}function
|
|
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
|
|
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:
|
|
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
|
|
8
|
-
`)}),s=null
|
|
9
|
-
`)}}if(r)return!0;let l=e.push(`html_block`,``,0);return l.content=`<div data-type="block-math" data-latex="${
|
|
10
|
-
`))t.write(e),t.ensureNewLine();t.write(`$$`),t.closeBlock(n)},parse:{setup(e){
|
|
11
|
-
也可以选择稍后把文件直接拖进编辑器。`;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 Rr(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 zr(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 Br(e,t,n){let r=Dr(),i=jr(n),a=await zn();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 Mr(e,t,n,a);r[s]++}return r}var Vr=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=Dr(),{matched:s,unmatched:c}=Nr(n,t.clipboardFiles);for(let{refs:t,file:n}of s){let r=await Mr(a,e,t,n);o[r]++}if(c.length>0){let t=jr(c).length;if(In()){let n=r??null;if(n||(await Lr(t)===`pick`?(n=await Ln(),n||J(`没有选择文件夹。本地文件暂以占位显示,稍后可直接把文件拖进编辑器上传`,`info`)):J(`已选择稍后处理。本地文件暂以占位显示,可直接把文件拖进编辑器上传`,`info`)),n){i=n,Or(o,await Pr(a,e,c,n));let t=[...o.missing,...o.readFailed];if(t.length>0&&Rn()&&await zr(t.map(e=>e.basename))===`pick`){let n=await Br(a,e,t);Or(o,n),o.missing=n.missing,o.readFailed=[]}}}else Rr(t)}Ir(o)},o=()=>{if(!e||e.isDestroyed||t.pausedUntilPaste)return;let o=n.i(),s=Wn(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=Wn(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=Wn(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}})]}}),Hr=new f.PluginKey(`slashCommand`);function Ur(e){return d.Extension.create({name:`slashCommand`,addProseMirrorPlugins(){let t={char:`/`,pluginKey:Hr,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,F.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,F.exitSuggestion)(t,Hr)}})}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,F.exitSuggestion)(r,Hr)},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,F.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=Hr.getState(n);return a&&a.active?n.tr.setMeta(Hr,{exit:!0}):null}})]}})}function Wr(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.mathInline`),description:e(`editor.slash.mathInlineDesc`),icon:`∑`,command:({editor:e})=>e.chain().focus().insertContent({type:`mathInline`,attrs:{latex:``}}).run()},{title:e(`editor.slash.mathBlock`),description:e(`editor.slash.mathBlockDesc`),icon:`∫`,command:({editor:e})=>e.chain().focus().insertContent({type:`mathBlock`,attrs:{latex:``}}).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=Dt(e)??t,a=i?Ot(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 Xn(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=Dt(e)??t,i=r?Ot(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 Xn(e.view,n,a)}}},n.click()}}]}var Gr=m.Image.extend({addNodeView(){return(0,c.ReactNodeViewRenderer)(zt)},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 Kr(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`}}),Gr.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,tr,hr,gr,On,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||`输入 '/' 打开菜单…`}),Ur(()=>Wr(t=>e.o(t),{maxAttachmentSize:t.maxAttachmentSize,maxTotalAttachmentSize:t.maxTotalAttachmentSize})),Qn.configure({maxAttachmentSize:t.maxAttachmentSize,maxTotalAttachmentSize:t.maxTotalAttachmentSize}),Vr,Cr,We,er,wr,dn,rn,en]}function qr(e){let t=e.trim(),n=/^\$([^$]+?)\$$/.exec(t);if(n)return n[1].trim();let r=/^\$\$([\s\S]+?)\$\$$/.exec(t);return r?r[1].trim():t}function Jr(e){let t=e.trim();return t?/^\${1,2}[\s\S]*\${1,2}$/.test(t)?!0:/[0-9=]/.test(t)&&/[+\-*/^=(){}_\\]/.test(t):!1}var Yr=`https://www.bing.com/search?q={query}`;function Xr(e){Yr=e}function Zr(){return Yr}function Qr(e){return[{key:`bold`,label:e(`editor.bubble.bold`),icon:(0,a.jsx)(qe,{}),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)(Je,{}),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)(Ye,{}),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)(Xe,{}),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)(Ze,{}),isActive:e=>e.isActive(`code`),command:e=>e.isEditable&&e.chain().focus().toggleCode().run()},{key:`mathInline`,label:e(`editor.bubble.mathInline`),icon:(0,a.jsx)(it,{}),isActive:e=>e.isActive(`mathInline`),command:e=>{if(!e.isEditable)return;let{from:t,to:n}=e.state.selection;if(t===n)return;let r=qr(e.state.doc.textBetween(t,n,`
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("./sanitize-BebkUITX.cjs"),t=require("./signed-fetch-BuPD4Q0V.cjs"),n=require("./storage-VaeLS7eM.cjs"),r=require("./local-a2ROEKrE.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.u(_,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.u(M,1);let N=require("lowlight"),P=require("katex");P=e.u(P,1);let F=require("@tiptap/suggestion");F=e.u(F,1);var ee=null,I=null;function L(){return I||(typeof document>`u`?null:(ee=document.createElement(`canvas`),I=ee.getContext(`2d`),I))}var te=new Map;function ne(e,t){let n=te.get(t);n||(n=new Map,te.set(t,n));let r=n.get(e);if(r!==void 0)return r;let i=L();return i?(i.font=t,r=i.measureText(e).width):r=re(e,t),n.set(e,r),r}function re(e,t){let n=parseFloat(t)||16,r=0;for(let t of e)ie(t.codePointAt(0)??0)?r+=n:r+=t===` `?n*.3:n*.55;return r}function ie(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 R(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`:ie(r)&&(i=R(r)?`punct`:`cjk`),n.push({text:e,width:ne(e,t),type:i})}return n}function ae(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 B(e,t,n,r){return{text:e.slice(t,Math.min(n,e.length)).map(e=>e.text).join(``),width:r}}function oe(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(B(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(B(s,l.lineStart,l.lastBreakIdx+1,l.lastBreakWidth)),l.lineStart=l.lastBreakIdx+1,l.lineWidth=ae(s,l.lineStart,e+1)):(c.push(B(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}else if(t.type===`cjk`){if(n>r&&l.lineWidth>0?(c.push(B(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}else 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(B(s,l.lineStart,l.lastBreakIdx+1,l.lastBreakWidth)),l.lineStart=l.lastBreakIdx+1,l.lineWidth=ae(s,l.lineStart,e+1)):l.lineWidth=n,l.lastBreakIdx=-1):l.lineWidth=n,a&&c.length>=a)break}else if(n>r&&l.lineWidth>0?l.lastBreakIdx>=0?(c.push(B(s,l.lineStart,l.lastBreakIdx+1,l.lastBreakWidth)),l.lineStart=l.lastBreakIdx+1,l.lineWidth=ae(s,l.lineStart,e+1),l.lastBreakIdx=-1):o===`break-word`?(c.push(B(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=ae(s,l.lineStart,s.length);c.push(B(s,l.lineStart,s.length,e))}return{lines:c,totalHeight:c.length*i,lineCount:c.length,truncated:u&&a?c.length>=a:!1}}var se=typeof window<`u`&&window.matchMedia(`(prefers-reduced-motion: reduce)`).matches,V=`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 ce={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>`},le=1;function U(){return`qt${le++}${Date.now().toString(36)}`}function W(e,t,n){let r=document.createElement(e);return t&&(r.className=t),n!=null&&(r.innerHTML=n),r}function ue(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=W(`em`,`qt-mark`);t.textContent=r,e.appendChild(t)}else e.appendChild(document.createTextNode(r))}}}var de={type:`info`,position:`top-center`,duration:4e3,maxVisible:5,persist:!1,persistMaxVisible:3,maxLines:void 0,vibrate:!0},fe=[80,40,80];function pe(){if(typeof navigator<`u`&&`vibrate`in navigator)try{navigator.vibrate(fe)}catch{}}var me=class{containers=new Map;opts={...de};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=W(`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=U(),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=W(`div`,`qt-toast qt-${n}${i==null?``:` qt-truncate`}${a||o?` qt-rich`:``}`);s.setAttribute(`data-qt-id`,e);let c=W(`span`,`qt-icon`);c.innerHTML=ce[n],s.appendChild(c);let l=W(`div`,`qt-body`),u=W(`span`,`qt-msg`),d=oe(t,{maxWidth:H(),lineHeight:1,maxLines:i},V);if(d.lineCount<=1?ue(u,t):d.lines.forEach((e,t)=>{let n=W(`span`,`qt-line`),r=e.text;t===d.lines.length-1&&d.truncated&&!r.endsWith(`…`)&&(r+=`…`),ue(n,r),u.appendChild(n)}),l.appendChild(u),a){let e=W(`div`,`qt-desc`);e.textContent=a,l.appendChild(e)}if(s.appendChild(l),o){let t=W(`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=W(`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&&pe(),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(se)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)}},he=null;function G(){return he||=new me,he}var ge=Object.assign((e,t)=>G().show(e,t),{info:(e,t)=>G().info(e,t),success:(e,t)=>G().success(e,t),warn:(e,t)=>G().warn(e,t),error:(e,t)=>G().error(e,t),promise:(e,t,n)=>G().promise(e,t,n),dismiss:e=>G().dismiss(e),dismissAll:()=>G().dismissAll(),configure:e=>G().configure(e)}),_e=new Set,ve=null;function ye(e){ve=e}function K(e,t=`error`,n){let r={persist:!0,...n};if(_e.size>0)for(let n of _e)n(e,t,r);else ve?ve(e,t,r):t===`success`?ge.success(e,r):t===`info`?ge.info(e,r):ge.error(e,r)}function be(e){return _e.add(e),()=>{_e.delete(e)}}var xe=e.l({ImageUploadDialog:()=>Se}),Se=({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>20971520?`图片大小不能超过 20MB`:null;if(r){m(r),K(r);return}f(!0),m(null);let i=URL.createObjectURL(e);g(i);try{let t=await n.n().upload(e,`editor`);URL.revokeObjectURL(i),b(t),g(t)}catch(e){m(e instanceof Error?e.message:`上传失败`),URL.revokeObjectURL(i),g(null)}finally{f(!1)}},[o]),E=(0,i.useCallback)(e=>{let t=e.target.files?.[0];t&&T(t)},[T]),D=(0,i.useCallback)(e=>{e.preventDefault(),u(!1);let t=e.dataTransfer.files[0];t&&T(t)},[T]),O=(0,i.useCallback)(e=>{let t=e.clipboardData.items;for(let n of Array.from(t))if(n.type.startsWith(`image/`)){e.preventDefault();let t=n.getAsFile();t&&T(t);return}},[T]),k=(0,i.useCallback)(()=>{_.trim()&&(r(_.trim()),w())},[_,r,w]),A=(0,i.useCallback)(()=>{y&&(r(y),w())},[y,r,w]);return e?(0,a.jsxs)(`div`,{className:`fixed inset-0 z-[9999] flex items-center justify-center`,children:[(0,a.jsx)(`div`,{className:`absolute inset-0 bg-black/40 backdrop-blur-sm`,onClick:w}),(0,a.jsxs)(`div`,{className:`relative w-[calc(100vw-2rem)] max-w-[420px] max-h-[90dvh] bg-background rounded-2xl shadow-2xl border border-default-200 overflow-hidden animate-in`,onPaste:s===`upload`?O:void 0,children:[(0,a.jsxs)(`div`,{className:`flex items-center justify-between px-5 py-4 border-b border-default-100`,children:[(0,a.jsx)(`h2`,{className:`text-base font-semibold`,children:`插入图片`}),(0,a.jsx)(`button`,{type:`button`,className:`w-7 h-7 flex items-center justify-center rounded-lg text-default-400 hover:text-default-600 hover:bg-default-100 transition-colors`,onClick:w,children:`✕`})]}),(0,a.jsx)(`div`,{className:`flex border-b border-default-100 px-5`,children:[`upload`,`url`].map(e=>(0,a.jsx)(`button`,{type:`button`,className:`px-4 py-2.5 text-sm font-medium transition-colors border-b-2 -mb-[1px] ${s===e?`border-primary text-primary`:`border-transparent text-default-400 hover:text-default-600`}`,onClick:()=>{c(e),m(null)},children:e===`upload`?`上传图片`:`图片链接`},e))}),(0,a.jsx)(`div`,{className:`p-5`,children:s===`upload`?(0,a.jsxs)(`div`,{className:`space-y-4`,children:[(0,a.jsxs)(`div`,{className:`flex items-center gap-2 px-3 py-2 rounded-lg bg-default-50 text-xs text-default-500`,children:[(0,a.jsx)(`span`,{className:`w-1.5 h-1.5 rounded-full bg-green-500`}),`存储服务:`,S.name]}),!h&&(0,a.jsxs)(`div`,{className:`relative flex flex-col items-center justify-center gap-3 py-10 px-4 rounded-xl border-2 border-dashed transition-all cursor-pointer ${l?`border-primary bg-primary/5 scale-[1.01]`:`border-default-200 hover:border-default-300 hover:bg-default-50`}`,onDragOver:e=>{e.preventDefault(),u(!0)},onDragLeave:()=>u(!1),onDrop:D,onClick:()=>x.current?.click(),children:[(0,a.jsx)(`div`,{className:`w-14 h-14 rounded-full bg-default-100 flex items-center justify-center`,children:(0,a.jsx)(`svg`,{className:`w-7 h-7 text-default-400`,fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,strokeWidth:1.5,children:(0,a.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M3 16.5v2.25A2.25 2.25 0 005.25 21h13.5A2.25 2.25 0 0021 18.75V16.5m-13.5-9L12 3m0 0l4.5 4.5M12 3v13.5`})})}),(0,a.jsxs)(`div`,{className:`text-center`,children:[(0,a.jsx)(`p`,{className:`text-sm font-medium text-default-700`,children:l?`松开放入`:`拖拽图片到此处`}),(0,a.jsx)(`p`,{className:`text-xs text-default-400 mt-1`,children:`或点击选择文件 · 支持粘贴图片`}),(0,a.jsx)(`p`,{className:`text-[10px] text-default-300 mt-1`,children:`PNG / JPG / GIF / WebP / AVIF · 最大 20MB`})]}),(0,a.jsx)(`input`,{ref:x,type:`file`,accept:`image/*`,className:`hidden`,onChange:E})]}),h&&(0,a.jsxs)(`div`,{className:`space-y-3`,children:[(0,a.jsxs)(`div`,{className:`relative rounded-xl overflow-hidden bg-default-100`,children:[(0,a.jsx)(`img`,{src:h,alt:`预览`,className:`w-full max-h-48 object-contain`}),d&&(0,a.jsx)(`div`,{className:`absolute inset-0 bg-black/40 flex items-center justify-center`,children:(0,a.jsxs)(`div`,{className:`flex flex-col items-center gap-2`,children:[(0,a.jsx)(`div`,{className:`w-8 h-8 border-2 border-white border-t-transparent rounded-full animate-spin`}),(0,a.jsx)(`span`,{className:`text-white text-xs`,children:`上传中…`})]})})]}),y&&!d&&(0,a.jsxs)(`div`,{className:`flex items-center gap-2 px-3 py-2 rounded-lg bg-green-50 text-xs text-green-700`,children:[(0,a.jsx)(`svg`,{className:`w-4 h-4 shrink-0`,fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,strokeWidth:2,children:(0,a.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M5 13l4 4L19 7`})}),`上传成功,已存储至 `,S.name]}),(0,a.jsxs)(`div`,{className:`flex gap-2`,children:[(0,a.jsx)(`button`,{type:`button`,className:`flex-1 py-2 rounded-xl bg-primary text-white text-sm font-medium disabled:opacity-40 transition-opacity`,disabled:!y||d,onClick:A,children:`插入图片`}),(0,a.jsx)(`button`,{type:`button`,className:`px-4 py-2 rounded-xl border border-default-200 text-sm hover:bg-default-50 transition-colors`,onClick:C,disabled:d,children:`重新选择`})]})]}),p&&(0,a.jsxs)(`div`,{className:`flex items-start gap-2 px-3 py-2.5 rounded-lg bg-danger-50 text-sm text-danger`,children:[(0,a.jsx)(`svg`,{className:`w-4 h-4 shrink-0 mt-0.5`,fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,strokeWidth:2,children:(0,a.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-2.5L13.732 4c-.77-.833-2.694-.833-3.464 0L3.34 16.5c-.77.833.192 2.5 1.732 2.5z`})}),(0,a.jsx)(`span`,{children:p})]})]}):(0,a.jsxs)(`div`,{className:`space-y-4`,children:[(0,a.jsxs)(`div`,{children:[(0,a.jsx)(`label`,{className:`block text-xs text-default-500 mb-1.5`,children:`图片链接地址`}),(0,a.jsx)(`input`,{type:`url`,className:`w-full px-3 py-2.5 rounded-xl border border-default-200 bg-background text-sm focus:outline-none focus:border-primary transition-colors`,placeholder:`https://example.com/image.png`,value:_,onChange:e=>v(e.target.value),onKeyDown:e=>{e.key===`Enter`&&k()}})]}),_&&(0,a.jsx)(`div`,{className:`rounded-xl overflow-hidden bg-default-100`,children:(0,a.jsx)(`img`,{src:_,alt:`预览`,className:`w-full max-h-40 object-contain`,onError:e=>{e.target.style.display=`none`}})}),(0,a.jsx)(`button`,{type:`button`,className:`w-full py-2.5 rounded-xl bg-primary text-white text-sm font-medium disabled:opacity-40 transition-opacity`,disabled:!_.trim(),onClick:k,children:`插入图片`})]})}),(0,a.jsxs)(`div`,{className:`px-5 py-3 border-t border-default-100 text-[11px] text-default-300 text-center`,children:[`图片将上传至 `,S.name]})]})]}):null};function Ce(e,t){return`${e.trim().toLowerCase().replace(/[^\p{L}\p{N}\s-]/gu,``).replace(/\s+/g,`-`).slice(0,40)||`heading`}-${t}`}function we(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 Te(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 Ee(e,t){let n=[];for(let r of e)n.push(r),r.children.length>0&&!t.has(r.id)&&n.push(...Ee(r.children,t));return n}function De(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 Oe(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 ke(e){if(e.isDestroyed)return null;try{return e.view.dom}catch{return null}}function Ae(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 je=84,Me=3e3,Ne=({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=ke(e);return t?Array.from(t.querySelectorAll(`h1,h2,h3,h4,h5,h6`)).map((e,t)=>(e.id||=Ce(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)+je,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=ke(e),n=t?Oe(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=ke(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,Me)},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-je,behavior:`smooth`})}else window.scrollTo({top:window.scrollY+a-je,behavior:`smooth`})},[e,y]),T=(0,i.useMemo)(()=>we(r),[r]),E=(0,i.useMemo)(()=>Te(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?De(T,d.trim()):T,[T,O,d]),A=(0,i.useMemo)(()=>Ee(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?Ae(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 q(e,t){return{continue:`你是一个写作助手。请从下文尾部自然流畅地续写内容,保持风格一致。只输出续写的内容,不要加任何前缀说明。`,improve:`你是一个文字润色专家。请优化以下文本的表达,提升文采和流畅度,保持原意不变。只输出润色后的文本。`,shorter:`你是一个精简专家。请将以下文本精简,保留核心信息,删除冗余。只输出精简后的文本。`,longer:`你是一个内容扩写专家。请丰富以下文本的细节和层次,增加深度。只输出扩写后的文本。`,fix:`你是一个校对专家。请修正以下文本中的语法错误、错别字和标点问题。只输出修正后的文本。`,translate:`你是一个翻译专家。请将以下文本翻译为英文。只输出翻译后的文本。`,zap:t||`你是一个全能的 AI 写作助手。请根据用户的指令处理文本。`}[e]}var Pe=null;async function Fe(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:q(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:q(e.mode,e.instruction),prompt:e.context,temperature:.7,maxOutputTokens:2048})).text}}}function Ie(e){Pe=e}function Le(){if(!Pe)throw Error(`未配置 AI 服务。请调用 createAILanguageModelProvider() 创建并通过 setAIProvider() 注册。`);return Pe}function Re(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(q(e.mode,e.instruction),e.context)},async generate(e){let t=q(e.mode,e.instruction),n=``;for await(let r of a(t,e.context))n+=r;return n}}}function ze(e){return Re({apiKey:e.apiKey,baseURL:e.baseURL||`https://api.deepseek.com/v1`,model:e.model||`deepseek-v4-flash`,headers:e.headers})}function J(e){return Re({apiKey:e.apiKey,baseURL:e.baseURL||`https://api.openai.com/v1`,model:e.model||`gpt-5.6-luna`,headers:e.headers})}function Be(e){return Re({apiKey:e.apiKey,baseURL:e.baseURL||`https://dashscope.aliyuncs.com/compatible-mode/v1`,model:e.model||`qwen3.7-plus`,headers:e.headers})}var Y={keyword:``,caseSensitive:!1,wholeWord:!1,matches:[],currentIndex:-1},X=new f.PluginKey(`search-highlight`);function Z(e){return e.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`)}function Ve(e,t){let{keyword:n,caseSensitive:r,wholeWord:i}=t;if(!n)return[];let a=r?`g`:`gi`,o=i?`\\b${Z(n)}\\b`:Z(n),s=new RegExp(o,a),c=[];return e.descendants((e,t)=>{if(!e.isText||!e.text)return;s.lastIndex=0;let n;for(;(n=s.exec(e.text))!==null;){let e=t+n.index,r=e+n[0].length;c.push({from:e,to:r}),n[0].length===0&&s.lastIndex++}}),c}function He(e,t){if(t.matches.length===0)return p.DecorationSet.empty;let n=t.matches.map((e,n)=>p.Decoration.inline(e.from,e.to,{class:n===t.currentIndex?`search-highlight search-highlight--active`:`search-highlight`}));return p.DecorationSet.create(e,n)}function Ue(e,t){if(t.currentIndex<0||t.currentIndex>=t.matches.length)return;let n=t.matches[t.currentIndex];n&&requestAnimationFrame(()=>{try{let t=e.dom.querySelector(`.search-highlight--active`);if(t){let e=t.getBoundingClientRect(),n=window.innerHeight-80;(e.top<120||e.bottom>n)&&t.scrollIntoView({behavior:`smooth`,block:`center`});return}let r=e.coordsAtPos(n.from),i=window.innerHeight-80;if(r.top<120||r.top>i){let e=r.top-window.innerHeight/2;window.scrollBy({top:e,behavior:`smooth`})}}catch{}})}var We=d.Extension.create({name:`searchHighlight`,addProseMirrorPlugins(){return[new f.Plugin({key:X,state:{init:()=>Y,apply(e,t){let n=e.getMeta(X);if(n)return{...t,...n,matches:n.matches===void 0?t.matches:n.matches,currentIndex:n.currentIndex===void 0?t.currentIndex:n.currentIndex};if(e.docChanged&&t.keyword){let n=Ve(e.doc,t),r=t.currentIndex;return r>=n.length&&(r=n.length-1),r<0&&(r=n.length>0?0:-1),{...t,matches:n,currentIndex:r}}return t}},props:{decorations(e){let t=X.getState(e);return t?He(e.doc,t):p.DecorationSet.empty}}})]},addCommands(){return{setSearch:(e,t={})=>({state:n,dispatch:r,view:i})=>{let a=X.getState(n)||Y,o={keyword:e,caseSensitive:t.caseSensitive??a.caseSensitive,wholeWord:t.wholeWord??a.wholeWord,matches:[],currentIndex:-1};return o.matches=Ve(n.doc,o),o.currentIndex=o.matches.length>0?0:-1,r&&(r(n.tr.setMeta(X,o)),i&&Ue(i,o)),!0},nextMatch:()=>({state:e,dispatch:t,view:n})=>{let r=X.getState(e)||Y;if(r.matches.length===0)return!1;let i=(r.currentIndex+1)%r.matches.length;return t&&(t(e.tr.setMeta(X,{currentIndex:i})),n&&Ue(n,{...r,currentIndex:i})),!0},prevMatch:()=>({state:e,dispatch:t,view:n})=>{let r=X.getState(e)||Y;if(r.matches.length===0)return!1;let i=(r.currentIndex-1+r.matches.length)%r.matches.length;return t&&(t(e.tr.setMeta(X,{currentIndex:i})),n&&Ue(n,{...r,currentIndex:i})),!0},clearSearch:()=>({state:e,dispatch:t})=>(t&&t(e.tr.setMeta(X,Y)),!0)}}});function Ge(e){let t=e.state;return X.getState(t)||Y}var Ke=({editor:e,onClose:t})=>{let[n,r]=(0,i.useState)(``),[o,s]=(0,i.useState)(!1),[c,l]=(0,i.useState)(!1),[u,d]=(0,i.useState)(0),f=(0,i.useRef)(null),p=(0,i.useRef)({keyword:n,caseSensitive:o,wholeWord:c});p.current={keyword:n,caseSensitive:o,wholeWord:c},(0,i.useEffect)(()=>{if(!e)return;let t=0,n=()=>{t&&cancelAnimationFrame(t),t=requestAnimationFrame(()=>{t=0,d(e=>(e+1)%1e6)})};return e.on(`update`,n),()=>{e.off(`update`,n),t&&cancelAnimationFrame(t)}},[e]),(0,i.useEffect)(()=>{let e=setTimeout(()=>f.current?.focus(),30);return()=>clearTimeout(e)},[]),(0,i.useEffect)(()=>{if(!e)return;let t=requestAnimationFrame(()=>{let{keyword:t,caseSensitive:n,wholeWord:r}=p.current;try{e.commands.setSearch(t,{caseSensitive:n,wholeWord:r})}catch(e){console.warn(`[SearchBar] setSearch failed:`,e)}});return()=>cancelAnimationFrame(t)},[e,n,o,c]),(0,i.useEffect)(()=>()=>{try{e?.commands.clearSearch()}catch{}},[]),(0,i.useEffect)(()=>{let e=e=>{e.key===`Escape`&&(e.preventDefault(),e.stopPropagation(),t())};return window.addEventListener(`keydown`,e,!0),()=>window.removeEventListener(`keydown`,e,!0)},[t]);let m=(0,i.useCallback)(()=>{try{e?.commands.nextMatch()}catch{}},[e]),h=(0,i.useCallback)(()=>{try{e?.commands.prevMatch()}catch{}},[e]),g=(0,i.useCallback)(e=>{e.stopPropagation(),e.key===`Enter`&&(e.preventDefault(),e.shiftKey?h():m())},[m,h]),_=(0,i.useMemo)(()=>{if(!e)return null;try{return Ge(e)}catch{return null}},[e,n,o,c,u]),v=n?_&&_.matches.length>0?`${_.currentIndex+1} / ${_.matches.length}`:`无匹配`:``,y=(0,i.useCallback)(e=>{e.stopPropagation()},[]);return(0,a.jsx)(`div`,{className:`search-bar`,role:`search`,"aria-label":`文档内搜索`,onClick:y,onMouseDown:y,children:(0,a.jsxs)(`div`,{className:`search-bar__main`,children:[(0,a.jsx)(`svg`,{className:`search-bar__icon`,width:`14`,height:`14`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,children:(0,a.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M21 21l-6-6m2-5a7 7 0 11-14 0 7 7 0 0114 0z`})}),(0,a.jsx)(`input`,{ref:f,type:`text`,className:`search-bar__input`,placeholder:`查找…`,value:n,onChange:e=>r(e.target.value),onKeyDown:g,onKeyUp:y,onKeyPress:y,onInput:y,spellCheck:!1,autoComplete:`off`,inputMode:`text`}),(0,a.jsx)(`span`,{className:`search-bar__count`,children:v}),(0,a.jsx)(`button`,{type:`button`,className:`search-bar__toggle${o?` search-bar__toggle--active`:``}`,onClick:()=>s(e=>!e),title:`区分大小写 (Aa)`,"aria-pressed":o,children:`Aa`}),(0,a.jsx)(`button`,{type:`button`,className:`search-bar__toggle${c?` search-bar__toggle--active`:``}`,onClick:()=>l(e=>!e),title:`整词匹配 (\\b)`,"aria-pressed":c,children:`\\b`}),(0,a.jsx)(`div`,{className:`search-bar__sep`}),(0,a.jsx)(`button`,{type:`button`,className:`search-bar__btn`,onClick:h,title:`上一个 (Shift+Enter)`,disabled:!_||_.matches.length===0,children:(0,a.jsx)(`svg`,{width:`14`,height:`14`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,children:(0,a.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M5 15l7-7 7 7`})})}),(0,a.jsx)(`button`,{type:`button`,className:`search-bar__btn`,onClick:m,title:`下一个 (Enter)`,disabled:!_||_.matches.length===0,children:(0,a.jsx)(`svg`,{width:`14`,height:`14`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,children:(0,a.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M19 9l-7 7-7-7`})})}),(0,a.jsx)(`button`,{type:`button`,className:`search-bar__btn search-bar__btn--close`,onClick:t,title:`关闭 (Esc)`,children:(0,a.jsx)(`svg`,{width:`14`,height:`14`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,children:(0,a.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M6 18L18 6M6 6l12 12`})})})]})})};function Q({children:e,...t}){return(0,a.jsx)(`svg`,{width:16,height:16,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:2,strokeLinecap:`round`,strokeLinejoin:`round`,"aria-hidden":`true`,...t,children:e})}var qe=e=>(0,a.jsxs)(Q,{...e,children:[(0,a.jsx)(`path`,{d:`M6 4h8a4 4 0 0 1 0 8H6z`}),(0,a.jsx)(`path`,{d:`M6 12h9a4 4 0 0 1 0 8H6z`})]}),Je=e=>(0,a.jsxs)(Q,{...e,children:[(0,a.jsx)(`path`,{d:`M19 4h-9`}),(0,a.jsx)(`path`,{d:`M14 20H5`}),(0,a.jsx)(`path`,{d:`M15 4 9 20`})]}),Ye=e=>(0,a.jsxs)(Q,{...e,children:[(0,a.jsx)(`path`,{d:`M6 4v6a6 6 0 0 0 12 0V4`}),(0,a.jsx)(`path`,{d:`M4 20h16`})]}),Xe=e=>(0,a.jsxs)(Q,{...e,children:[(0,a.jsx)(`path`,{d:`M16 4H9a3 3 0 0 0-2.83 4`}),(0,a.jsx)(`path`,{d:`M14 12a4 4 0 0 1 0 8H6`}),(0,a.jsx)(`path`,{d:`M4 12h16`})]}),Ze=e=>(0,a.jsxs)(Q,{...e,children:[(0,a.jsx)(`path`,{d:`m16 18 6-6-6-6`}),(0,a.jsx)(`path`,{d:`m8 6-6 6 6 6`})]}),Qe=e=>(0,a.jsxs)(Q,{...e,children:[(0,a.jsx)(`path`,{d:`m9 11-6 6v3h9l3-3`}),(0,a.jsx)(`path`,{d:`m22 12-4.6 4.6a2 2 0 0 1-2.8 0l-5.2-5.2a2 2 0 0 1 0-2.8L14 4`})]}),$e=e=>(0,a.jsxs)(Q,{...e,children:[(0,a.jsx)(`path`,{d:`M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71`}),(0,a.jsx)(`path`,{d:`M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71`})]}),et=e=>(0,a.jsxs)(Q,{...e,children:[(0,a.jsx)(`rect`,{x:`3`,y:`3`,width:`18`,height:`18`,rx:`2`,ry:`2`}),(0,a.jsx)(`path`,{d:`M3 9h18M3 15h18M9 3v18M15 3v18`})]}),tt=e=>(0,a.jsxs)(Q,{...e,children:[(0,a.jsx)(`rect`,{x:`8`,y:`8`,width:`14`,height:`14`,rx:`2`,ry:`2`}),(0,a.jsx)(`path`,{d:`M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2`})]}),nt=e=>(0,a.jsxs)(Q,{...e,children:[(0,a.jsx)(`circle`,{cx:`11`,cy:`11`,r:`8`}),(0,a.jsx)(`path`,{d:`m21 21-4.3-4.3`})]}),rt=e=>(0,a.jsxs)(Q,{...e,children:[(0,a.jsx)(`path`,{d:`M12 3l1.6 4.4L18 9l-4.4 1.6L12 15l-1.6-4.4L6 9l4.4-1.6L12 3z`}),(0,a.jsx)(`path`,{d:`M18.5 14l.7 1.9 1.9.7-1.9.7-.7 1.9-.7-1.9-1.9-.7 1.9-.7.7-1.9z`})]}),it=e=>(0,a.jsx)(Q,{...e,children:(0,a.jsx)(`path`,{d:`M18 5H6l6 7-6 7h12`})}),at=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`})]}),ot=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 st(e){if(e){if(e.startsWith(`blob:`))URL.revokeObjectURL(e);else try{await n.n().remove(e)}catch(e){console.warn(`删除存储资源失败:`,e)}}}var ct=3e4,lt=new Set([`image`,`attachmentEmbed`,`audioEmbed`,`videoEmbed`]),ut=new WeakMap;function dt(e){let t=new Set;return e.state.doc.descendants(e=>{if(lt.has(e.type.name)){let n=e.attrs.src;n&&t.add(n)}return!0}),t}function ft(e){let t=ut.get(e);return t||(t={timers:new Map,onTransaction:()=>{},listening:!1},ut.set(e,t)),t}function pt(e,t){let n=[...new Set(t.filter(Boolean))];if(n.length===0)return;let r=ft(e);r.listening||=(r.onTransaction=()=>{if(r.timers.size===0)return;let t=dt(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(()=>{dt(e).has(t)||st(t),r.timers.delete(t)},ct);r.timers.set(t,n)}}function mt(e){let t=ut.get(e);if(t){if(t.listening&&=(e.off(`transaction`,t.onTransaction),!1),t.timers.size>0){let n=dt(e);for(let[e,r]of t.timers)clearTimeout(r),n.has(e)||st(e);t.timers.clear()}ut.delete(e)}}var ht=[{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:`⚡`}],gt=new Set([`image`,`attachmentEmbed`,`audioEmbed`,`videoEmbed`]),_t={image:`editor.ai.nodeImage`,attachmentEmbed:`editor.ai.nodeAttachment`,videoEmbed:`editor.ai.nodeVideo`,audioEmbed:`editor.ai.nodeAudio`};function vt(e,t){return e.storage.qingwuUI?.parseMd?.(e.schema,t)||null}function yt(e,t,n){let r=[];return e.state.doc.nodesBetween(t,n,e=>{if(gt.has(e.type.name)){let t=e.attrs.src;t&&r.push({type:e.type.name,src:t})}return!0}),r}function bt(e){let t=new Set;return e.state.doc.descendants(e=>{if(gt.has(e.type.name)){let n=e.attrs.src;n&&t.add(n)}return!0}),t}function xt(e,t){let n=vt(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()}else e.commands.setContent(t),e.commands.focus()}function St(e,t,n,r){let i=vt(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 Ct({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=>{o(e),m(null),e===`zap`?setTimeout(()=>v.current?.focus(),100):await S(e)},[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=Le(),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(yt(t,r.from,r.to).map(e=>e.src));e===`replaceAll`?xt(t,n):St(t,n,`replace`,_.current);let a=bt(t);pt(t,[...i].filter(e=>!a.has(e)))},[t]),w=(0,i.useCallback)(e=>{if(e===`below`){St(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=yt(t,i.from,i.to);a.length>0?g({position:e,willRemove:a}):(C(e,l,i),n())},[t,l,C,n]),T=(0,i.useCallback)(()=>{if(!h)return;let{position:e}=h,r=e===`replaceAll`?{from:0,to:t.state.doc.content.size}:{from:_.current.from,to:_.current.to};C(e,l,r),g(null),n()},[h,t,l,C,n]),E=(0,i.useCallback)(()=>{u(``),o(null),m(null)},[]),D={};for(let e of h?.willRemove??[])D[e.type]=(D[e.type]??0)+1;return(0,a.jsxs)(a.Fragment,{children:[(0,a.jsxs)(`div`,{className:`ai-selector w-full flex-1 min-h-0 flex flex-col`,children:[(0,a.jsxs)(`div`,{className:`flex items-center justify-between pl-3 pr-1.5 py-1.5 border-b border-default-100 shrink-0`,children:[(0,a.jsxs)(`span`,{className:`flex items-center gap-1.5 text-xs font-medium text-default-500`,children:[(0,a.jsx)(rt,{className:`text-primary`}),e.o(`editor.ai.trigger`)]}),(0,a.jsx)(`button`,{type:`button`,onClick:n,"aria-label":e.o(`editor.ai.close`),title:e.o(`editor.ai.close`),className:`flex items-center justify-center w-6 h-6 rounded-md text-default-400 hover:bg-default-100 hover:text-default-700 transition-colors`,children:(0,a.jsx)(ot,{})})]}),(0,a.jsx)(`div`,{className:`grid grid-cols-[repeat(auto-fit,minmax(64px,1fr))] gap-1.5 p-2 shrink-0`,children:ht.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(_t[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 wt=new Set([`attachmentEmbed`,`videoEmbed`,`audioEmbed`,`image`]);function Tt(e){let t=0;return e.descendants(e=>{wt.has(e.type.name)&&(t+=Number(e.attrs?.size)||0)}),t}function Et(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 Dt(e){return(e?.storage)?.qingwuUI?.limits}function Ot(e,t,n){let{maxAttachmentSize:r,maxTotalAttachmentSize:i}=n;if(r&&t.size>r)return`单文件大小不能超过 ${Et(r)}(当前 ${Et(t.size)})`;if(i){let n=Tt(e)+t.size;if(n>i)return`附件总大小不能超过 ${Et(i)}(当前合计 ${Et(n)})`}return null}var kt=!1,At=null,jt=5e3;function Mt(){return kt}function $(e){kt=e,At&&=(clearTimeout(At),null),e&&(At=setTimeout(()=>{kt=!1,At=null},jt))}var Nt=null;function Pt(e){Nt=e}function Ft(){return Nt}var It=300;function Lt({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=Ft();return(0,i.useEffect)(()=>{e?p&&!f.current&&(f.current=!0,p({open:e,title:t,message:n,confirmText:r,cancelText:o,onConfirm:s,onCancel:c})):f.current=!1},[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<It&&await new Promise(e=>setTimeout(e,It-t)),d(!1),c()}},disabled:l,children:r})]})]})}),document.body)}function Rt(e){return/^(\.\.?\/|[a-zA-Z]:\\|file:\/\/)/.test(e)?!0:!(/^[a-z]+:\/\//i.test(e)||e.startsWith(`/`)||e.startsWith(`data:`)||e.startsWith(`blob:`))}function zt({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-BuPD4Q0V.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||Rt(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:()=>{Mt()||($(!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:Rt(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:()=>{Mt()||($(!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:()=>{E.current||(E.current=!0,C.current&&x.current?x.current.src=C.current:(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)(Lt,{open:m,title:`确认删除图片`,message:F?`该图片无法在当前环境加载,仅从编辑器中移除该图片节点,不影响存储文件。`:`此操作将同时删除对象存储中的文件,不可撤销。`,onCancel:()=>{$(!1),h(!1)},onConfirm:async()=>{if(!F)try{await st(g)}catch{}$(!1),await new Promise(e=>setTimeout(e,300)),n()}})]})}var Bt=(0,i.lazy)(()=>import(`@file-viewer/react`)),Vt=new Set,Ht={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}},Ut={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`},Wt={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 Gt(e){return e?e<1024?`${e} B`:e<1048576?`${(e/1024).toFixed(1)} KB`:`${(e/1048576).toFixed(1)} MB`:``}function Kt(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 qt(e){return e.split(`.`).pop()?.toLowerCase()||``}function Jt(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 Yt(e){return!!e&&!e.startsWith(`file:`)}function Xt(e){return btoa(encodeURIComponent(e)).replace(/\+/g,`-`).replace(/\//g,`_`).replace(/=+$/,``)}async function Zt(e,t){try{let n=Xt(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 $t({node:n,deleteNode:r,selected:o,editor:s}){let l=s?.isEditable??!0,u=n.attrs.src||``,[d,f]=(0,i.useState)(()=>Vt.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,ne]=(0,i.useState)(void 0),[re,ie]=(0,i.useState)(!1),R=n.attrs.src||``,z=n.attrs.name||R&&R.split(`/`).pop()?.split(`?`)[0]||(R?`attachment`:e.o(`editor.attachment.lost`)),ae=n.attrs.size||0,B=qt(z),oe=!R;(0,i.useEffect)(()=>{if(!d){ne(void 0),ie(!1);return}let e=Ut[B];if(!e){ne(void 0),ie(!1);return}let t=!0;return ne(void 0),ie(!1),Wt[e]().then(e=>{t&&ne(e)}).catch(n=>{console.error(`[attachment] renderer "${e}" load failed:`,n),t&&ie(!0)}),()=>{t=!1}},[d,B]);let se=(0,i.useMemo)(()=>({...Ht,renderers:te?[te]:[],rendererMode:`replace`}),[te]),V=(0,i.useCallback)(e=>{f(t=>{let n=typeof e==`function`?e(t):e;return R&&(n?Vt.add(R):Vt.delete(R)),n})},[R]);(0,i.useEffect)(()=>{f(R?Vt.has(R):!1)},[R]);let H=(0,i.useCallback)(()=>{k.current=!0,V(!0),window.setTimeout(()=>{window.scrollTo(0,O.current),A.current&&(A.current.scrollTop=j.current),k.current&&V(!0),k.current=!1},0)},[V]),ce=(0,i.useCallback)(async()=>{I===`web`?(L(`none`),document.body.style.overflow=``,H()):(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]),le=(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,H]),U=(0,i.useCallback)(()=>{I===`none`&&(k.current||V(e=>!e))},[I]);(0,i.useEffect)(()=>{let e=()=>{document.fullscreenElement||(I===`native`&&L(`none`),H())},t=e=>{e.key===`Escape`&&I===`web`&&(L(`none`),document.body.style.overflow=``,H())};return document.addEventListener(`fullscreenchange`,e),window.addEventListener(`keydown`,t),()=>{document.removeEventListener(`fullscreenchange`,e),window.removeEventListener(`keydown`,t)}},[I,H]),(0,i.useEffect)(()=>{let e=e=>{if(e.key!==`Backspace`&&e.key!==`Delete`||!l||!o||Mt())return;let t=s?.view?.dom,n=e.target;if(s?.isFocused&&n instanceof Node&&t?.contains(n)){if(e.preventDefault(),e.stopPropagation(),s){let{from:e,to:t}=s.state.selection;P.current={from:e,to:t}}window.getSelection()?.removeAllRanges(),$(!0),N(!0)}};return window.addEventListener(`keydown`,e,!0),()=>window.removeEventListener(`keydown`,e,!0)},[o,s,l]),(0,i.useEffect)(()=>{if(!d||!Yt(R)){m(null),b(null),D.current=null;return}if(D.current===R)return;let e=new AbortController,n=!0;return v(!0),b(null),(async()=>{let r=R.includes(`?X-Amz-`),i=null,a=null;if(!i&&!r&&(i=await Zt(R,e.signal)),!i&&!r)try{let n=await t.n(R);n&&(i=await Zt(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(R);if(n){let t={"X-Requested-With":`XMLHttpRequest`};n.forEach((e,n)=>{t[n]=e});try{i=await Qt(R,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(R,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=R;let o=URL.createObjectURL(new Blob([i],{type:`application/octet-stream`}));g(o),v(!1)})().catch(e=>{n&&(e instanceof DOMException&&e.name===`AbortError`||(D.current===R?v(!1):b(e instanceof Error?e.message:`附件读取失败,请检查对象存储 CORS 和公开访问权限`)))}),()=>{n=!1,e.abort()}},[d,R]),(0,i.useEffect)(()=>()=>{h&&URL.revokeObjectURL(h),m(null)},[]),(0,i.useEffect)(()=>()=>{h&&URL.revokeObjectURL(h),g(null),m(null),D.current=null},[R]),(0,i.useEffect)(()=>{if(C!==`success`&&C!==`error`)return;let e=window.setTimeout(()=>w(null),2400);return()=>window.clearTimeout(e)},[C]);let W=(0,i.useCallback)(async()=>{S(!0),w(`loading`);try{if(h){let e=document.createElement(`a`);e.href=h,e.download=z,document.body.appendChild(e),e.click(),document.body.removeChild(e),w(`success`);return}let e=R.includes(`?X-Amz-`),n=null;if(!e)try{let e=await t.n(R);e&&(n=await fetch(e,{headers:{"X-Requested-With":`XMLHttpRequest`}}),n.ok||(n=null))}catch{}if(!n&&!e)try{let e=await t.r(R);e&&(n=await fetch(R,{headers:(()=>{let t=new Headers(e);return t.set(`X-Requested-With`,`XMLHttpRequest`),t})()}),n.ok||(n=null))}catch{}if(n||=await fetch(R,{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=z,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)}},[R,z,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:oe?(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`})]}):Kt(z)}),(0,a.jsxs)(`div`,{className:`att-meta`,children:[(0,a.jsx)(`span`,{className:`att-name`,children:z}),ae>0&&(0,a.jsx)(`span`,{className:`att-size`,children:Gt(ae)})]})]}),(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:[R&&Jt(z)&&(0,a.jsx)(`button`,{type:`button`,className:`att-btn`,onMouseDown:e=>{e.preventDefault(),e.stopPropagation(),U()},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:W,disabled:x||oe,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&&!Mt()&&($(!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||re)&&!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||R?te?(0,a.jsx)(Bt,{buffer:p||void 0,url:h||R,name:z,filename:z,type:B,size:ae||p?.byteLength||0,options:se},`${R}-${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:ce,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:le,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)(Lt,{open:M,title:`确认删除附件`,message:oe?`此操作将删除该附件节点,不可撤销。`:`此操作将同时删除对象存储中的文件(${z}),不可撤销。`,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(st(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 st(R),$(!1),await new Promise(e=>setTimeout(e,300)),r()}catch{$(!1)}}})]})}var en=d.Node.create({name:`attachmentEmbed`,group:`block`,atom:!0,inline:!1,addNodeView(){return(0,c.ReactNodeViewRenderer)($t)},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 tn(e,t,n){n===void 0?e.replaceSelectionWith(t):e.insert(n,t);let r=0;if(e.doc.descendants((e,n)=>{e===t&&(r=n+e.nodeSize)}),!r)return!1;let i=e.doc.nodeAt(r);return(i?.type.name!==`paragraph`||i.content.size!==0)&&e.insert(r,e.doc.type.schema.nodes.paragraph.create()),e.setSelection(f.TextSelection.create(e.doc,r+1)),!0}function nn(e,t,n){let r=e.state.tr;return tn(r,t,n)?(e.dispatch(r.scrollIntoView()),e.focus(),!0):!1}function rn({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`,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:()=>{Mt()||($(!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)(Lt,{open:l,title:`确认删除音频`,message:`此操作将同时删除对象存储中的文件(${s}),不可撤销。`,onCancel:()=>{$(!1),u(!1)},onConfirm:async()=>{try{await st(o)}catch{}$(!1),await new Promise(e=>setTimeout(e,300)),n()}})]})}function an(e){return/\.(mp3|wav|ogg|flac|aac|m4a|wma|opus)(\?|$)/i.test(e)||/\/.*\.(mp3|wav|ogg|flac)/i.test(e)}var on=d.Node.create({name:`audioEmbed`,group:`block`,atom:!0,inline:!1,addNodeView(){return(0,c.ReactNodeViewRenderer)(rn)},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(` `)&&an(r))return t.preventDefault(),nn(e,e.state.schema.nodes.audioEmbed.create({src:r})),!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 sn(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 cn(e){let t=e.match(/BV[a-zA-Z0-9]{10}/);if(t)return t[0];let n=e.match(/av(\d+)/i);return n?n[0]:e}function ln({node:e,deleteNode:t,editor:n}){let r=e.attrs.src||``,o=e.attrs.source||`unknown`,s=o===`unknown`?sn(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)(Lt,{open:l,title:`确认删除视频`,message:`此操作将同时删除对象存储中的文件,不可撤销。`,onCancel:()=>{$(!1),u(!1)},onConfirm:async()=>{try{await st(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-BuPD4Q0V.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=cn(r);return(0,a.jsxs)(c.NodeViewWrapper,{as:`div`,className:`video-embed video-embed--bilibili group/video`,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:()=>{Mt()||($(!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},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:{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:()=>{Mt()||($(!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 un(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 dn(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 fn(e){let t=e.match(/explore\/([a-zA-Z0-9]+)/);return t?t[1]:e}var pn=d.Node.create({name:`videoEmbed`,group:`block`,atom:!0,inline:!1,addNodeView(){return(0,c.ReactNodeViewRenderer)(ln)},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=un(r);if(i!==`unknown`)return t.preventDefault(),nn(e,e.state.schema.nodes.videoEmbed.create({src:r,source:i})),!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:un(n)}}},{tag:`div[data-bilibili]`},{tag:`div[data-xiaohongshu]`}]},renderHTML({HTMLAttributes:e}){let t=e.src||``,n=un(t);if(n===`bilibili`){let e=dn(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 fn(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=un(e.src);return t().command(({tr:t})=>tn(t,this.type.create({...e,source:n}))).focus().scrollIntoView().run()}}}}),mn=null,hn={fontFamily:`Inter, 'PingFang SC', 'Microsoft YaHei', 'Noto Sans SC', system-ui, sans-serif`,padding:24},gn=.25,_n=4,vn=.25;async function yn(e){return mn||=await import(`pele`),mn.render(e,hn).svg}var bn=[{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`}],xn={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`},Sn={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 Cn({node:t,updateAttributes:n,editor:r,getPos:o,deleteNode:s,selected:c}){let l=r?.isEditable??!0,d=!l,[f,p]=(0,i.useState)(!1),[m,h]=(0,i.useState)(!1),[g,_]=(0,i.useState)(!1),[v,y]=(0,i.useState)(!1),[b,x]=(0,i.useState)(220),[S,C]=(0,i.useState)({top:0,left:0,width:210}),[w,T]=(0,i.useState)(``),[E,D]=(0,i.useState)(!1),[O,k]=(0,i.useState)(null),[A,j]=(0,i.useState)(null),[M,N]=(0,i.useState)(!1),[P,F]=(0,i.useState)(!1),[ee,I]=(0,i.useState)(1),[L,te]=(0,i.useState)({x:0,y:0}),[ne,re]=(0,i.useState)(!1),ie=(0,i.useRef)(null),R=(0,i.useRef)(null),z=(0,i.useRef)(null),ae=(0,i.useRef)(null),B=(0,i.useRef)(null),oe=(0,i.useRef)(null),se=(0,i.useRef)(null),V=t.attrs.language||``,H=bn.find(e=>e.value===(Sn[V]??V)),ce=V===`mermaid`,le=e=>Math.min(_n,Math.max(gn,e)),U=e=>I(t=>Math.round(le(t+e)*100)/100),W=()=>{I(1),te({x:0,y:0})},ue=()=>{W(),F(!0)};(0,i.useEffect)(()=>{O||F(!1)},[O]),(0,i.useEffect)(()=>{if(!P)return;let e=document.body.style.overflow;document.body.style.overflow=`hidden`;let t=e=>{e.key===`Escape`&&F(!1)};return window.addEventListener(`keydown`,t),()=>{document.body.style.overflow=e,window.removeEventListener(`keydown`,t)}},[P]);let de=e=>{e.button===0&&(e.currentTarget.setPointerCapture(e.pointerId),ie.current={x:e.clientX,y:e.clientY,panX:L.x,panY:L.y},re(!0))},fe=e=>{let t=ie.current;t&&te({x:t.panX+e.clientX-t.x,y:t.panY+e.clientY-t.y})},pe=()=>{ie.current=null,re(!1)},me=(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]),he=(0,i.useCallback)(()=>{l&&(Mt()||(se.current=me(),window.getSelection()?.removeAllRanges(),$(!0),D(!0)))},[me,l]),G=(0,i.useMemo)(()=>{let e=w.trim().toLowerCase();return e?bn.filter(t=>t.label.toLowerCase().includes(e)||t.value.toLowerCase().includes(e)):bn},[w]);(0,i.useEffect)(()=>{(oe.current?.closest(`.code-block-node-view`))?.classList.toggle(`code-block-node-view--collapsed`,m)},[m]);let ge=(0,i.useCallback)(()=>{let e=ae.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=bn.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(``),ge();let e=setTimeout(()=>B.current?.focus(),50);return window.addEventListener(`resize`,ge),window.addEventListener(`scroll`,ge,!0),()=>{clearTimeout(e),window.removeEventListener(`resize`,ge),window.removeEventListener(`scroll`,ge,!0)}},[g,ge]),(0,i.useEffect)(()=>{if(!g)return;let e=e=>{let t=e.target;t&&(ae.current?.contains(t)||z.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||Mt())return;let t=r?.view?.dom,n=e.target;if(r?.isFocused&&n instanceof Node&&t?.contains(n)){if(e.preventDefault(),e.stopPropagation(),r){let{from:e,to:t}=r.state.selection;se.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 _e=(0,i.useCallback)(e=>{n({language:e||null}),_(!1)},[n]),ve=(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]),ye=(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]),K=(0,i.useCallback)(()=>{let e=xn[V]||`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,V]),be=(0,i.useCallback)(async()=>{if(O||M)k(null),j(null),N(!1);else{N(!0),j(null),k(null);try{let n=(t.textContent||``).trim();if(!n){j(`代码块内容为空`);return}let r=await yn(n),i=e.r(r);k(i)}catch(e){j(e instanceof Error?e.message:`图表渲染失败`)}finally{N(!1)}}},[t.textContent,O,M]),xe=(0,a.jsxs)(a.Fragment,{children:[H?H.deviconClass?(0,a.jsx)(`i`,{className:`${H.deviconClass} colored cb-lang-icon`,style:{color:H.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:H?.label||`自动`})]});return(0,a.jsxs)(`div`,{ref:oe,className:`cb-react-shell group/cb`,style:{display:`contents`},children:[(0,a.jsxs)(`div`,{className:`cb-header${m?` cb-header--collapsed`:``}`,contentEditable:!1,onMouseDown:e=>e.stopPropagation(),children:[(0,a.jsx)(`div`,{className:`cb-lang-wrap`,ref:R,contentEditable:!1,children:d?(0,a.jsx)(`span`,{className:`cb-lang-trigger cb-lang-trigger--static`,children:xe}):(0,a.jsxs)(`button`,{ref:ae,type:`button`,className:`cb-lang-trigger`,onClick:()=>_(!g),children:[xe,(0,a.jsx)(`svg`,{className:`cb-lang-chevron${g?` cb-lang-chevron--open`:``}`,width:`10`,height:`10`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2.5`,children:(0,a.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M6 9l6 6 6-6`})})]})}),m&&(0,a.jsxs)(`button`,{type:`button`,className:`cb-collapsed-bar`,contentEditable:!1,onClick:()=>h(!1),title:`展开代码块`,children:[xe,(0,a.jsx)(`svg`,{className:`cb-lang-chevron`,width:`12`,height:`12`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2.5`,children:(0,a.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M6 9l6 6 6-6`})})]}),l&&g&&(0,u.createPortal)((0,a.jsxs)(`div`,{ref:z,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:B,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${V?``:` cb-lang-option--active`}`,onClick:()=>_e(``),children:[(0,a.jsx)(`span`,{className:`cb-lang-icon cb-lang-icon--auto`,children:`?`}),(0,a.jsx)(`span`,{children:`自动检测`})]}),G.map(e=>(0,a.jsxs)(`button`,{type:`button`,className:`cb-lang-option${V===e.value?` cb-lang-option--active`:``}`,onClick:()=>_e(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)),G.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:ye,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:K,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:ve,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:he,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`})})})]}),ce&&(0,a.jsx)(`button`,{type:`button`,className:`cb-btn cb-btn--diagram`,onClick:be,contentEditable:!1,title:O||M?`取消渲染`:`渲染图表`,disabled:M,children:(0,a.jsx)(`svg`,{className:`cb-btn-icon`,fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,strokeWidth:`2`,children:(0,a.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M4 5a1 1 0 011-1h4a1 1 0 011 1v5a1 1 0 01-1 1H5a1 1 0 01-1-1V5zM14 5a1 1 0 011-1h4a1 1 0 011 1v2a1 1 0 01-1 1h-4a1 1 0 01-1-1V5zM4 16a1 1 0 011-1h4a1 1 0 011 1v3a1 1 0 01-1 1H5a1 1 0 01-1-1v-3zM14 13a1 1 0 011-1h4a1 1 0 011 1v6a1 1 0 01-1 1h-4a1 1 0 01-1-1v-6z`})})})]})]}),(O||A||M)&&(0,a.jsxs)(`div`,{className:`cb-diagram-output`,contentEditable:!1,children:[M&&(0,a.jsx)(`div`,{className:`cb-diagram-loading`,children:`渲染图表中…`}),A&&(0,a.jsxs)(`div`,{className:`cb-diagram-error`,children:[(0,a.jsx)(`span`,{className:`cb-diagram-error-icon`,children:`!`}),A]}),O&&(0,a.jsxs)(`div`,{className:`cb-diagram-svg`,role:`button`,tabIndex:0,title:`点击放大查看`,onClick:ue,onKeyDown:e=>{(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),ue())},children:[(0,a.jsx)(`div`,{className:`cb-diagram-svg-inner`,dangerouslySetInnerHTML:{__html:O}}),(0,a.jsx)(`span`,{className:`cb-diagram-zoom-hint`,children:`点击放大`})]})]}),P&&O&&(0,u.createPortal)((0,a.jsxs)(`div`,{className:`fixed inset-0 z-[10002] flex flex-col bg-black/75 backdrop-blur-sm select-none`,role:`dialog`,"aria-modal":`true`,"aria-label":`Mermaid 图表预览`,children:[(0,a.jsxs)(`div`,{className:`flex items-center justify-between gap-3 px-4 py-3 text-white`,children:[(0,a.jsx)(`span`,{className:`text-sm font-medium`,children:`Mermaid 图表`}),(0,a.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,a.jsx)(`button`,{type:`button`,className:`flex h-8 min-w-8 items-center justify-center rounded-lg bg-white/10 px-2 text-base text-white transition-colors hover:bg-white/20`,onClick:()=>U(-.25),title:`缩小`,"aria-label":`缩小`,children:`−`}),(0,a.jsxs)(`button`,{type:`button`,className:`flex h-8 min-w-14 items-center justify-center rounded-lg bg-white/10 px-2 text-xs text-white transition-colors hover:bg-white/20`,onClick:W,title:`重置为 100%`,"aria-label":`重置缩放`,children:[Math.round(ee*100),`%`]}),(0,a.jsx)(`button`,{type:`button`,className:`flex h-8 min-w-8 items-center justify-center rounded-lg bg-white/10 px-2 text-base text-white transition-colors hover:bg-white/20`,onClick:()=>U(vn),title:`放大`,"aria-label":`放大`,children:`+`}),(0,a.jsx)(`button`,{type:`button`,className:`flex h-8 min-w-8 items-center justify-center rounded-lg bg-white/10 px-2 text-sm text-white transition-colors hover:bg-white/20`,onClick:W,title:`重置`,"aria-label":`重置`,children:`⟲`}),(0,a.jsx)(`span`,{className:`mx-1 h-5 w-px bg-white/20`}),(0,a.jsx)(`button`,{type:`button`,className:`flex h-8 min-w-8 items-center justify-center rounded-lg bg-white/10 px-2 text-lg text-white transition-colors hover:bg-white/20`,onClick:()=>F(!1),title:`关闭`,"aria-label":`关闭`,children:`×`})]})]}),(0,a.jsx)(`div`,{className:`flex flex-1 touch-none items-center justify-center overflow-hidden`,style:{cursor:ne?`grabbing`:ee>1?`grab`:`default`},onWheel:e=>U(e.deltaY>0?-.25:vn),onPointerDown:de,onPointerMove:fe,onPointerUp:pe,onPointerCancel:pe,onDoubleClick:()=>{I(e=>e===1?2:1),te({x:0,y:0})},children:(0,a.jsx)(`div`,{className:`cb-diagram-zoom-content`,style:{transform:`translate(${L.x}px, ${L.y}px) scale(${ee})`,transition:ne?`none`:`transform 120ms ease-out`},dangerouslySetInnerHTML:{__html:O}})})]}),document.body),(0,a.jsx)(Lt,{open:E,title:`确认删除代码块`,message:`此操作不可撤销。`,onCancel:()=>{$(!1),D(!1)},onConfirm:async()=>{await new Promise(e=>setTimeout(e,300)),$(!1),s()}})]})}var wn=[{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`}],Tn=(0,N.createLowlight)(N.common);Tn.register({dockerfile:M.default}),Tn.registerAlias(`xml`,[`vue`,`html`]),Tn.registerAlias(`javascript`,[`react`,`jsx`]),Tn.registerAlias(`typescript`,[`tsx`]);function En(e){return e?e.split(`
|
|
4
|
+
`):[``]}function Dn(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 On(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 kn(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 An=j.CodeBlockLowlight.extend({addNodeView(){return e=>{let{node:t,editor:n,getPos:r}=e,i=t,a=e=>{let t=typeof r==`function`?r():void 0;typeof t==`number`&&n.chain().command(({tr:n})=>(n.setNodeMarkup(t,void 0,{...i.attrs,...e}),!0)).run()},o=()=>{let e=typeof r==`function`?r():void 0;typeof e==`number`&&n.chain().command(({tr:t})=>(t.delete(e,e+i.nodeSize),!0)).run()},s=document.createElement(`div`);s.className=`code-block-node-view group/cb`;let l=document.createElement(`div`);l.contentEditable=`false`,s.appendChild(l);let u=document.createElement(`div`);u.className=`cb-code-area`;let d=document.createElement(`div`);d.className=`cb-code-inner`;let f=document.createElement(`div`);f.className=`cb-line-numbers`,f.contentEditable=`false`,f.setAttribute(`aria-hidden`,`true`);let p=document.createElement(`pre`);p.className=`cb-code-pre`;let m=document.createElement(`code`);p.appendChild(m);let h=document.createElement(`div`);h.className=`cb-code-mirror`,h.contentEditable=`false`,h.setAttribute(`aria-hidden`,`true`),d.appendChild(f),d.appendChild(p),d.appendChild(h),u.appendChild(d),s.appendChild(u);let g=En(t.textContent);Dn(f,g.length),On(h,g);let _=new c.ReactRenderer(Cn,{editor:n,props:{node:t,editor:n,getPos:r,updateAttributes:a,deleteNode:o,selected:!1}});l.appendChild(_.element);let v=e=>{let t=En(e.textContent);Dn(f,t.length),On(h,t),requestAnimationFrame(()=>kn(p,h,f))};requestAnimationFrame(()=>kn(p,h,f));let y=new ResizeObserver(()=>kn(p,h,f));return y.observe(p),document.fonts?.ready?.then(()=>kn(p,h,f)),{dom:s,contentDOM:m,update(e){return e.type!==t.type||!e.sameMarkup(i)?!1:(i=e,_.updateProps({node:e,editor:n,getPos:r,updateAttributes:a,deleteNode:o,selected:s.classList.contains(`ProseMirror-selectednode`)}),v(e),!0)},selectNode(){s.classList.add(`ProseMirror-selectednode`),_.updateProps({node:i,editor:n,getPos:r,updateAttributes:a,deleteNode:o,selected:!0})},deselectNode(){s.classList.remove(`ProseMirror-selectednode`),_.updateProps({node:i,editor:n,getPos:r,updateAttributes:a,deleteNode:o,selected:!1})},stopEvent(e){let t=e.target;return!!(t&&l.contains(t))},ignoreMutation(e){return!m.contains(e.target)},destroy(){y.disconnect(),_.destroy()}}}},parseHTML(){return(this.parent?.()??[]).map(e=>({...e,getContent:(e,t)=>{let n=e,r=n.querySelector(`:scope > code`),i=Array.from((r??n).querySelectorAll(`:scope > div`));if(i.length>0){let e=i.map(e=>e.textContent??``).join(`
|
|
6
|
+
`);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:Tn});function jn(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 Mn=/\.(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,Nn=/^(?:mailto:|tel:|javascript:|about:|data:|blob:)/i;function Pn(e){if(!e)return!1;let t=e.trim();return!(!t||/^(?:https?:)?\/\//i.test(t)||Nn.test(t)||t.startsWith(`#`))}function Fn(e){return Mn.test(e)}function In(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 Ln(e){let t=In(e),n=t.split(`/`).filter(Boolean);return(n[n.length-1]||t).toLowerCase()}function Rn(){return typeof window>`u`||window.isSecureContext===!1?!1:typeof window.showDirectoryPicker==`function`}async function zn(){if(!Rn())return null;try{return await window.showDirectoryPicker.call(window,{mode:`read`})??null}catch{return null}}function Bn(){return typeof window>`u`||window.isSecureContext===!1?!1:typeof window.showOpenFilePicker==`function`}async function Vn(){if(!Bn())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 Hn(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 Un(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 Wn(e,t){let n=In(t).split(`/`).filter(Boolean);if(n.length===0)return{file:null};let r;for(let t=0;t<n.length;t++){let i=await Hn(e,n.slice(t));if(i.file)return i;i.readError&&(r=i.readError)}let i=await Un(e,n[n.length-1]);return i.file||i.readError?i:{file:null,readError:r}}var Gn={image:`image`,videoEmbed:`video`,audioEmbed:`audio`,attachmentEmbed:`attachment`};function Kn(e,t){let n=new Set,r=[];return e.descendants(e=>{let i=Gn[e.type?.name];if(i){let a=e.attrs?.src,o=`node:${a}`;typeof a==`string`&&Pn(a)&&!n.has(o)&&!t?.(a)&&(n.add(o),r.push({src:a,normalized:In(a),basename:Ln(a),kind:i,isLink:!1}))}else 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`&&Pn(e)&&Fn(e)&&!n.has(a)&&!t?.(e)&&(n.add(a),r.push({src:e,normalized:In(e),basename:Ln(e),kind:`attachment`,isLink:!0}))}}),r}function qn(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=>Fn(e)&&Pn(e)&&!n?.(e))}function Jn(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 Yn(e){let t=e.name.split(`.`).pop()?.toLowerCase()||``;return t===`md`||t===`markdown`}async function Xn(e,t,n,r){let i=n??e.state.selection.from,a=r?Dt(r):void 0,o=r?.storage?.qingwuUI,s=await new Promise(e=>{o?.chooseMd?o.chooseMd(t.name,e):jn(t.name).then(e)});if(s===null)return;if(s===`attach`){let r=a?Ot(e.state.doc,t,a):null;if(r){K(r);return}let i=URL.createObjectURL(t),o=e.state.schema.nodes.attachmentEmbed?.create({src:i,name:t.name,size:t.size,type:t.type});if(o)try{nn(e,o,n)}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 Zn(e,t,n){switch(Jn(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 Qn(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)),a?n:null}catch(e){return console.error(`${t.type} upload failed:`,e),URL.revokeObjectURL(r),null}}async function $n(e,t,n,r){let i=r?Dt(r):void 0,a=i?Ot(e.state.doc,t,i):null;if(a){K(a);return}let o=URL.createObjectURL(t),s=Zn(e.state.schema,t,o);if(s){try{nn(e,s,n)}catch{return}await Qn(e,t,o)}}var er=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})?.pos;for(let n of Array.from(r))Yn(n)?Xn(t,n,i,e):$n(t,n,i,e),i=void 0;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&&qn(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&&Jn(i)!==`file`&&$n(t,i,void 0,e),!0}if(n.kind===`file`){let i=n.getAsFile();if(i&&Yn(i))return r.preventDefault(),Xn(t,i,void 0,e),!0}}return!1}}})]}}),tr=100,nr=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>tr?!1:(r.preventDefault(),!0)}}}})]}}),rr=d.Extension.create({name:`inlineCodeEnd`,addInputRules(){let e=this.editor.schema.marks.code;return e?[(0,d.markInputRule)({find:/`([^`]+)`$/,type:e})]:[]}}),ir=d.Extension.create({name:`listQuoteHighlight`,addProseMirrorPlugins(){return[new f.Plugin({props:{decorations:e=>{let{$head:t,empty:n}=e.selection;if(!this.editor.isFocused||!n||![`paragraph`,`heading`].includes(t.parent.type.name))return p.DecorationSet.empty;let r=[],i=!1;for(let e=t.depth-1;e>0;e--){let n=t.node(e).type.name;if(n===`listItem`&&!i&&(i=!0,r.push(p.Decoration.node(t.before(),t.after(),{class:`qw-active-row`}),p.Decoration.node(t.before(e),t.after(e),{class:`qw-active-list-item`}))),n===`blockquote`){r.push(p.Decoration.node(t.before(e),t.after(e),{class:`qw-active-quote`}));break}}return p.DecorationSet.create(e.doc,r)}}})]}});function ar(e){return e.replace(/&/g,`&`).replace(/"/g,`"`).replace(/</g,`<`).replace(/>/g,`>`).replace(/\n/g,` `)}function or(e){return e.replace(/&/g,`&`).replace(/</g,`<`).replace(/>/g,`>`).replace(/"/g,`"`)}function sr(e,t){let n=e??``;if(!n.trim())return``;try{return P.default.renderToString(n,{displayMode:t,throwOnError:!1,strict:`ignore`,trust:!1,output:`htmlAndMathml`})}catch{return`<span class="math-fallback">${or(n)}</span>`}}function cr({node:t,updateAttributes:n,deleteNode:r,editor:o,getPos:s,selected:l}){let d=t.type.name===`mathBlock`,p=String(t.attrs.latex??``),m=o?.isEditable??!0,[h,g]=(0,i.useState)(!1),[_,v]=(0,i.useState)(p),y=(0,i.useRef)(null),b=(0,i.useRef)(!1),x=(0,i.useRef)(()=>{}),S=(0,i.useRef)(()=>{}),C=(0,i.useMemo)(()=>sr(p,d),[p,d]),w=(0,i.useMemo)(()=>sr(_,d),[_,d]),T=()=>{let e=_.trim();e?(n({latex:e}),g(!1)):(g(!1),m&&r?.())},E=()=>{g(!1),!p&&m&&r?.()};x.current=T,S.current=E,(0,i.useEffect)(()=>{m&&!b.current&&(b.current=!0,p||g(!0))},[m,p]),(0,i.useEffect)(()=>{if(!h)return;v(p);let e=window.setTimeout(()=>{y.current?.focus(),y.current?.select()},30),t=e=>{e.key===`Escape`?(e.preventDefault(),S.current()):(e.metaKey||e.ctrlKey)&&e.key===`Enter`&&(e.preventDefault(),x.current())};return window.addEventListener(`keydown`,t,!0),()=>{window.clearTimeout(e),window.removeEventListener(`keydown`,t,!0)}},[h,p]);let D=()=>{m&&g(!0)},O=e=>{if(!o||typeof s!=`function`)return;let n=s();if(n===void 0)return;let r=e.currentTarget.getBoundingClientRect(),i=e.clientX-r.left<r.width/2?`before`:`after`,a=i===`before`?n:n+t.nodeSize,{state:c,view:l}=o,u=f.TextSelection.near(c.doc.resolve(a),i===`before`?-1:1);l.dispatch(c.tr.setSelection(u)),l.focus()};return(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(c.NodeViewWrapper,{as:d?`div`:`span`,className:`math-node ${d?`math-node--block`:`math-node--inline`}${l?` is-selected`:``}`,contentEditable:!1,title:m&&!d?e.o(`editor.math.inlineClickHint`):void 0,onMouseDown:e=>{m&&d&&e.preventDefault()},onClick:e=>{m&&(e.preventDefault(),e.stopPropagation(),d||e.detail>=2?D():O(e))},children:p?(0,a.jsx)(`span`,{className:`math-render`,dangerouslySetInnerHTML:{__html:C}}):(0,a.jsx)(`span`,{className:`math-placeholder`,children:e.o(`editor.math.empty`)})}),h&&(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:E,onMouseDown:e=>e.preventDefault(),children:(0,a.jsxs)(`div`,{className:`w-full max-w-lg mx-4 rounded-xl border border-default-200 dark:border-zinc-700 bg-white dark:bg-zinc-800 p-5 shadow-xl`,onClick:e=>e.stopPropagation(),children:[(0,a.jsx)(`div`,{className:`mb-3 text-sm font-medium text-default-800 dark:text-zinc-100`,children:e.o(d?`editor.math.blockTitle`:`editor.math.inlineTitle`)}),(0,a.jsx)(`textarea`,{ref:y,value:_,onChange:e=>v(e.target.value),rows:d?5:2,spellCheck:!1,placeholder:e.o(`editor.math.placeholder`),className:`w-full resize-y rounded-lg border border-default-200 dark:border-zinc-700 bg-default-50 dark:bg-zinc-900 px-3 py-2 font-mono text-sm text-default-800 dark:text-zinc-100 outline-none focus:ring-2 focus:ring-qingwu-500/40`}),(0,a.jsx)(`div`,{className:`math-dialog-preview`,children:_.trim()?(0,a.jsx)(`div`,{dangerouslySetInnerHTML:{__html:w}}):(0,a.jsx)(`span`,{className:`math-placeholder`,children:e.o(`editor.math.emptyPreview`)})}),(0,a.jsxs)(`div`,{className:`mt-4 flex items-center justify-between gap-3`,children:[(0,a.jsx)(`span`,{className:`text-[11px] text-default-400 dark:text-zinc-500`,children:e.o(`editor.math.hint`)}),(0,a.jsxs)(`div`,{className:`flex shrink-0 gap-2`,children:[(0,a.jsx)(`button`,{type:`button`,className:`px-3 py-1.5 text-xs rounded-lg border border-default-200 dark:border-zinc-600 hover:bg-default-100 dark:hover:bg-zinc-700 transition-colors`,onClick:E,children:e.o(`editor.math.cancel`)}),(0,a.jsx)(`button`,{type:`button`,className:`px-3 py-1.5 text-xs rounded-lg bg-qingwu-600 hover:bg-qingwu-700 text-white transition-colors`,onClick:T,children:e.o(`editor.math.save`)})]})]})]})}),document.body)]})}var lr=/(?:^|[^\\$])\$([^\s$](?:[^$\n]*[^\s$])?)\$$/,ur=/^\$\$([\s\S]+?)\$\$$/;function dr(e){return new f.Plugin({appendTransaction(t,n,r){if(!e.isEditable||e.view.composing||!t.some(e=>e.docChanged))return null;let i=r.schema.nodes.paragraph,a=r.schema.nodes.mathBlock;if(!i||!a)return null;let o=[],s=null;if(r.doc.forEach((e,t)=>{if(e.type!==i){s=null;return}let n=e.textContent.trim(),r=s;r?n===`$$`?(o.push({from:r.from,to:t+e.nodeSize,latex:r.lines.join(`
|
|
8
|
+
`)}),s=null):r.lines.push(e.textContent):n===`$$`&&(s={from:t,lines:[]})}),!o.length)return null;let c=r.tr;for(let e of o.reverse()){let t=a.create({latex:e.latex});c.replaceWith(e.from,e.to,t);let n=e.from+t.nodeSize,r=c.doc.resolve(n);r.nodeAfter&&r.nodeAfter.isTextblock||c.insert(n,i.create()),c.setSelection(f.TextSelection.near(c.doc.resolve(n),1))}return c}})}function fr(e){return new d.InputRule({find:lr,handler:({state:t,range:n,match:r})=>{let i=r[1],a=r[0].indexOf(`$`);if(a<0)return;let o=n.from+a,s=n.to;o>=s||t.tr.replaceWith(o,s,e.create({latex:i}))}})}function pr(e){return new d.InputRule({find:ur,handler:({state:t,range:n,match:r})=>{let i=r[1].trim();if(!i)return;let a=t.doc.resolve(n.from),o=a.depth,s=a.before(o),c=a.after(o),l=e.create({latex:i}),u=t.tr.replaceWith(s,c,l),d=s+l.nodeSize,p=u.doc.resolve(d);p.nodeAfter&&p.nodeAfter.isTextblock||u.insert(d,t.schema.nodes.paragraph.create()),u.setSelection(f.TextSelection.near(u.doc.resolve(d),1))}})}function mr(e,t){let n=e.src,r=e.pos;if(n.charCodeAt(r)!==36||n.charCodeAt(r+1)===36)return!1;let i=r+1;for(;i<n.length;){let e=n.charCodeAt(i);if(e===10)return!1;if(e===36&&n.charCodeAt(i-1)!==92)break;i+=1}if(i>=n.length)return!1;let a=n.slice(r+1,i);if(!a||/^\s|\s$/.test(a))return!1;if(!t){let t=e.push(`html_inline`,``,0);t.content=`<span data-type="inline-math" data-latex="${ar(a)}"></span>`}return e.pos=i+1,!0}function hr(e,t,n,r){let i=e.bMarks[t]+e.tShift[t],a=e.eMarks[t];if(i+1>=a||e.src.charCodeAt(i)!==36||e.src.charCodeAt(i+1)!==36)return!1;let o=e.src.slice(i,a).trim(),s=``,c=t+1;if(o.length>4&&o.endsWith(`$$`))s=o.slice(2,-2);else{let t=[],r=o.slice(2),i=r.endsWith(`$$`);if(i)s=r.slice(0,-2);else{for(r&&t.push(r);c<n;c+=1){let n=e.bMarks[c]+e.tShift[c],r=e.eMarks[c],a=e.src.slice(n,r),o=a.trimEnd();if(o.endsWith(`$$`)){t.push(o.slice(0,-2)),i=!0,c+=1;break}t.push(a)}if(!i)return!1;s=t.join(`
|
|
9
|
+
`)}}if(r)return!0;let l=e.push(`html_block`,``,0);return l.content=`<div data-type="block-math" data-latex="${ar(s.trim())}"></div>\n`,e.line=c,!0}function gr(e){e.__qingwuMathReg||(e.__qingwuMathReg=!0,e.inline.ruler.before(`backticks`,`qingwu_math_inline`,mr),e.block.ruler.before(`fence`,`qingwu_math_block`,hr,{alt:[`paragraph`]}))}function _r(e){return{markdown:{serialize(t,n){let r=String(n.attrs.latex??``);if(!e)t.write(`$${r}$`);else{t.ensureNewLine(),t.write(`$$`),t.ensureNewLine();for(let e of r.split(`
|
|
10
|
+
`))t.write(e),t.ensureNewLine();t.write(`$$`),t.closeBlock(n)}},parse:{setup(e){gr(e)}}}}}var vr=d.Node.create({name:`mathInline`,group:`inline`,inline:!0,atom:!0,selectable:!0,addAttributes(){return{latex:{default:``,parseHTML:e=>e.getAttribute(`data-latex`)??e.textContent??``}}},parseHTML(){return[{tag:`span[data-type="inline-math"]`},{tag:`span.math-node--inline`}]},renderHTML({node:e}){let t=String(e.attrs.latex??``),n={"data-type":`inline-math`,"data-latex":t,class:`math-node math-node--inline`};if(typeof document>`u`)return[`span`,n,t];let r=document.createElement(`span`);for(let[e,t]of Object.entries(n))r.setAttribute(e,t);return r.innerHTML=sr(t,!1),r},addNodeView(){return(0,c.ReactNodeViewRenderer)(cr)},addInputRules(){return[fr(this.type)]},addStorage(){return _r(!1)}}),yr=d.Node.create({name:`mathBlock`,group:`block`,atom:!0,selectable:!0,addAttributes(){return{latex:{default:``,parseHTML:e=>e.getAttribute(`data-latex`)??e.textContent??``}}},parseHTML(){return[{tag:`div[data-type="block-math"]`},{tag:`div.math-node--block`}]},renderHTML({node:e}){let t=String(e.attrs.latex??``),n={"data-type":`block-math`,"data-latex":t,class:`math-node math-node--block`};if(typeof document>`u`)return[`div`,n,t];let r=document.createElement(`div`);for(let[e,t]of Object.entries(n))r.setAttribute(e,t);return r.innerHTML=sr(t,!0),r},addNodeView(){return(0,c.ReactNodeViewRenderer)(cr)},addInputRules(){return[pr(this.type)]},addProseMirrorPlugins(){return[dr(this.editor)]},addStorage(){return _r(!0)}}),br=/\.(png|jpe?g|gif|webp|bmp|svg|avif)(\?|#|$)/i,xr=/\.(mp4|m3u8|webm|ogg|flv|mkv|mov|avi|wmv|ts|m4v|3gp|f4v|rmvb)(\?|#|$)/i,Sr=/\.(mp3|wav|ogg|flac|aac|m4a|wma|opus)(\?|#|$)/i;function Cr(e){return e.replace(/&/g,`&`).replace(/"/g,`"`).replace(/</g,`<`).replace(/>/g,`>`)}function wr(e){let t=e.trim().replace(/\\/g,`/`);return t.split(`/`).pop()||t}function Tr(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||wr(a);if(i){let n=``;if(br.test(a)||/^data:image\//i.test(a))n=`<img src="${Cr(a)}" alt="${Cr(t)}">`;else if(xr.test(a)||/^data:video\//i.test(a))n=`<div data-video-embed src="${Cr(a)}"></div>`;else if(Sr.test(a)||/^data:audio\//i.test(a))n=`<audio src="${Cr(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 Er=d.Extension.create({name:`obsidianMarkdown`,addStorage(){return{markdown:{parse:{setup(e){e.__obsidianReg||(e.__obsidianReg=!0,e.inline.ruler.before(`link`,`obsidian_embed`,Tr))}}}}}}),Dr=d.Extension.create({name:`qingwuUI`,priority:1e3,addKeyboardShortcuts(){return{"Ctrl-Enter":()=>this.editor.isEditable&&this.editor.isActive(`heading`)&&this.editor.commands.setParagraph()}},addStorage(){return{}}});function Or(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 kr(e,n=8e3){if(await Or(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 Or(a,n);return URL.revokeObjectURL(a),o}catch{return!1}}function Ar(){return{uploaded:0,sessionOnly:0,limitRejected:0,renderFailed:0,missing:[],readFailed:[]}}function jr(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 Mr(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 Nr(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 Pr(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 Fr(e,t,r,i){if(r.length===0)return`sessionOnly`;let a=r[0],o=Dt(t);if(o){let t=Ot(e.state.doc,i,o);if(t)return K(`${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)Nr(e,n.src,t)&&(r=!0);return r?`uploaded`:`sessionOnly`}catch(e){return console.error(`本地附件 ${a.basename} 上传失败:`,e),K(`「${a.basename}」上传失败`,`error`),`sessionOnly`}let l=URL.createObjectURL(i),u=!1;for(let t of s)Mr(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),K(`「${a.basename}」上传失败`,`error`),URL.revokeObjectURL(l),`sessionOnly`}URL.revokeObjectURL(l),u&&Mr(e,l,d,i.size);for(let t of c)Nr(e,t.src,d);return!u&&c.length===0?`sessionOnly`:u&&r.some(e=>e.kind===`image`)?await kr(d)?`uploaded`:`renderFailed`:`uploaded`}function Ir(e,t){let n=[],r=[];for(let i of Pr(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 Lr(e,t,n,r){let i=Ar();for(let a of Pr(n)){let n=a[0],{file:o,readError:s}=await Wn(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 Fr(e,t,a,o);i[c]++}return i}function Rr(e){let t=e.map(e=>e.basename);return t.length<=3?t.join(`、`):`${t.slice(0,3).join(`、`)} 等 ${t.length} 个文件`}function zr(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} 个找到但读取失败:${Rr(e.readFailed)}(若在 OneDrive / WPS 云盘等同步目录,请右键文件选择「始终保留在此设备」后重试)`),e.missing.length>0&&t.push(`${e.missing.length} 个未能获取:${Rr(e.missing)}(可把文件直接拖进编辑器上传)`),t.length===0)return;let n=e.uploaded>0&&e.renderFailed===0&&e.missing.length===0&&e.readFailed.length===0;K(`本地文件解析完成:${t.join(`;`)}`,n?`success`:`info`)}function Br(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 库根目录,它会连同子目录一起查找),编辑器读取后会上传到你的存储。
|
|
11
|
+
也可以选择稍后把文件直接拖进编辑器。`;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 Vr(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 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.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=Ar(),i=Pr(n),a=await Vn();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 Fr(e,t,n,a);r[s]++}return r}var Wr=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}=Ir(n,t.clipboardFiles);for(let{refs:t,file:n}of s){let r=await Fr(a,e,t,n);o[r]++}if(c.length>0){let t=Pr(c).length;if(Rn()){let n=r??null;if(n||(await Br(t)===`pick`?(n=await zn(),n||K(`没有选择文件夹。本地文件暂以占位显示,稍后可直接把文件拖进编辑器上传`,`info`)):K(`已选择稍后处理。本地文件暂以占位显示,可直接把文件拖进编辑器上传`,`info`)),n){i=n,jr(o,await Lr(a,e,c,n));let t=[...o.missing,...o.readFailed];if(t.length>0&&Bn()&&await Hr(t.map(e=>e.basename))===`pick`){let n=await Ur(a,e,t);jr(o,n),o.missing=n.missing,o.readFailed=[]}}}else Vr(t)}zr(o)},o=()=>{if(!e||e.isDestroyed||t.pausedUntilPaste)return;let o=n.i(),s=Kn(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=Kn(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=Kn(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}})]}}),Gr=new f.PluginKey(`slashCommand`);function Kr(e){return d.Extension.create({name:`slashCommand`,addProseMirrorPlugins(){let t={char:`/`,pluginKey:Gr,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,F.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();else 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)}else if(e.key===`Escape`){e.preventDefault();let t=a?.view;t&&(0,F.exitSuggestion)(t,Gr)}})}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,F.exitSuggestion)(r,Gr)},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,F.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=Gr.getState(n);return a&&a.active?n.tr.setMeta(Gr,{exit:!0}):null}})]}})}function qr(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.mathInline`),description:e(`editor.slash.mathInlineDesc`),icon:`∑`,command:({editor:e})=>e.chain().focus().insertContent({type:`mathInline`,attrs:{latex:``}}).run()},{title:e(`editor.slash.mathBlock`),description:e(`editor.slash.mathBlockDesc`),icon:`∫`,command:({editor:e})=>e.chain().focus().insertContent({type:`mathBlock`,attrs:{latex:``}}).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=Dt(e)??t,a=i?Ot(e.state.doc,r,i):null;if(a){K(a);return}let o=URL.createObjectURL(r),s=e.schema.nodes.audioEmbed?.create({src:o,name:r.name,size:r.size});s&&(nn(e.view,s),await Qn(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=Dt(e)??t,i=r?Ot(e.state.doc,n,r):null;if(i){K(i);continue}let a=URL.createObjectURL(n),o=e.schema.nodes.attachmentEmbed;if(o){try{nn(e.view,o.create({src:a,name:n.name,size:n.size,type:n.type}))}catch{continue}await Qn(e.view,n,a)}}},n.click()}}]}var Jr=m.Image.extend({addNodeView(){return(0,c.ReactNodeViewRenderer)(zt)},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 Yr(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`}}),Jr.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,rr,vr,yr,An,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||`输入 '/' 打开菜单…`}),Kr(()=>qr(t=>e.o(t),{maxAttachmentSize:t.maxAttachmentSize,maxTotalAttachmentSize:t.maxTotalAttachmentSize})),er.configure({maxAttachmentSize:t.maxAttachmentSize,maxTotalAttachmentSize:t.maxTotalAttachmentSize}),Wr,Er,We,ir,nr,Dr,pn,on,en]}function Xr(e){let t=e.trim(),n=/^\$([^$]+?)\$$/.exec(t);if(n)return n[1].trim();let r=/^\$\$([\s\S]+?)\$\$$/.exec(t);return r?r[1].trim():t}function Zr(e){let t=e.trim();return t?/^\${1,2}[\s\S]*\${1,2}$/.test(t)?!0:/[0-9=]/.test(t)&&/[+\-*/^=(){}_\\]/.test(t):!1}var Qr=`https://www.bing.com/search?q={query}`;function $r(e){Qr=e}function ei(){return Qr}function ti(e){return[{key:`bold`,label:e(`editor.bubble.bold`),icon:(0,a.jsx)(qe,{}),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)(Je,{}),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)(Ye,{}),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)(Xe,{}),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)(Ze,{}),isActive:e=>e.isActive(`code`),command:e=>e.isEditable&&e.chain().focus().toggleCode().run()},{key:`mathInline`,label:e(`editor.bubble.mathInline`),icon:(0,a.jsx)(it,{}),isActive:e=>e.isActive(`mathInline`),command:e=>{if(!e.isEditable)return;let{from:t,to:n}=e.state.selection;if(t===n)return;let r=Xr(e.state.doc.textBetween(t,n,`
|
|
12
12
|
`));r&&e.chain().focus().insertContentAt({from:t,to:n},{type:`mathInline`,attrs:{latex:r}}).run()}},{key:`highlight`,label:e(`editor.bubble.highlight`),icon:(0,a.jsx)(Qe,{}),more:!0,isActive:e=>e.isActive(`highlight`),command:()=>{}},{key:`link`,label:e(`editor.bubble.link`),icon:(0,a.jsx)($e,{}),more:!0,isActive:e=>e.isActive(`link`),command:()=>{}},{key:`copy`,label:e(`editor.bubble.copy`),icon:(0,a.jsx)(tt,{}),more:!0,isActive:()=>!1,command:e=>{let{from:t,to:n}=e.state.selection,r=e.state.doc.textBetween(t,n,`
|
|
13
|
-
`).trim();r&&navigator.clipboard?.writeText(r).catch(()=>{})}},{key:`search`,label:e(`editor.bubble.search`),icon:(0,a.jsx)(nt,{}),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=
|
|
14
|
-
`)}function
|
|
15
|
-
`)}function ri(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 ii({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=$r(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=$r(e);if(!t)return;let n=ti(ei(t.node));navigator.clipboard?.writeText(n),o(!0),setTimeout(()=>o(!1),1500)},g=()=>{let t=$r(e);if(!t)return;let n=ni(ei(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=ri(t);if(!n||n.length===0)return;let r=m(n);if(!r)return;let i=$r(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||Mt()||($(!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)(Lt,{open:s,title:`确认删除表格`,message:`此操作不可撤销。`,onCancel:()=>{$(!1),c(!1)},onConfirm:async()=>{await new Promise(e=>setTimeout(e,300)),$(!1),y()}})]})}var ai=[{color:`#fef08a`,name:`黄`},{color:`#bbf7d0`,name:`绿`},{color:`#bfdbfe`,name:`蓝`},{color:`#fbcfe8`,name:`粉`},{color:`#fed7aa`,name:`橙`},{color:`#ddd6fe`,name:`紫`}],oi=288,si=480,ci=320;function li(e,t,n={}){let r=window.innerWidth,i=window.innerHeight,a=Math.min(n.panelWidth||oi,si,r-32),o=Math.max(t||ci,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 ui(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*\|.+\||(^|\n)\s*\$\$[\s\S]*?\$\$|(^|[^\\$])\$[^\s$\n](?:[^$\n]*[^\s$\n])?\$/i.test(e)}function di(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 fi=(0,i.lazy)(()=>Promise.resolve().then(()=>ye).then(e=>({default:e.ImageUploadDialog}))),pi=(0,i.lazy)(()=>Promise.resolve().then(()=>require("./storage-settings-dialog-LY_-VFA4.cjs")).then(e=>({default:e.StorageSettingsDialog}))),mi=(0,i.lazy)(()=>Promise.resolve().then(()=>require("./export-dialog-wG4oZtsB.cjs")).then(e=>({default:e.ExportDialog}))),hi=(0,i.lazy)(()=>Promise.resolve().then(()=>require("./video-embed-dialog-f5HKKPzg.cjs")).then(e=>({default:e.VideoEmbedDialog}))),gi=(0,i.lazy)(()=>Promise.resolve().then(()=>require("./md-import-dialog-CVvu-Adt.cjs")).then(e=>({default:e.MdImportDialog}))),_i=()=>(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`})})]}),vi=({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||ui(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,ne]=(0,i.useState)(!1),[re,ie]=(0,i.useState)(!1),[R,z]=(0,i.useState)(`none`),[B,V]=(0,i.useState)({}),ae=(0,i.useRef)(null),oe=(0,i.useRef)(null),[H,U]=(0,i.useState)(``),[W,se]=(0,i.useState)(null),[G,K]=(0,i.useState)(y),[ce,le]=(0,i.useState)(!1);(0,i.useEffect)(()=>{K(y)},[y]);let[ue,de]=(0,i.useState)(!1),[fe,pe]=(0,i.useState)(()=>typeof window<`u`&&typeof window.matchMedia==`function`?window.matchMedia(`(min-width: 80rem)`).matches:!0),[q,me]=(0,i.useState)(()=>typeof window<`u`&&typeof window.matchMedia==`function`?window.matchMedia(`(min-width: 64rem)`).matches:!0),he=(0,i.useRef)(null),ge=(0,i.useRef)(null),_e=(0,i.useRef)(null),ye=(0,i.useRef)(0),be=(0,i.useRef)(null),xe=(0,i.useRef)(null),Se=(0,i.useRef)(null),Ce=(0,i.useRef)(null),[we,Te]=(0,i.useState)(!1),[Oe,ke]=(0,i.useState)(!1),[Y,je]=(0,i.useState)(!1),[Me,Ne]=(0,i.useState)(!1),Pe=(0,i.useRef)(null),Fe=(0,i.useCallback)(()=>{let e=ge.current,t=_e.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:``}),je(!1),requestAnimationFrame(()=>{window.scrollTo(0,ye.current)})):(document.fullscreenElement&&document.exitFullscreen(),ye.current=window.scrollY,Object.assign(e.style,{position:`fixed`,top:`0`,left:`0`,width:`100%`,zIndex:`99999`,background:`var(--background, #fff)`,borderRadius:`0`,overflow:`hidden`,display:`flex`,flexDirection:`column`}),e.style.height=`100vh`,e.style.height=`100dvh`,t&&Object.assign(t.style,{flex:`1`,overflow:`auto`,minHeight:`0`}),document.body.style.overflow=`hidden`,je(!0)))},[Y]),Ie=(0,i.useCallback)(()=>{let e=ge.current;e&&(document.fullscreenElement?document.exitFullscreen():(Y&&Fe(),ye.current=window.scrollY,e.requestFullscreen()))},[Y,Fe]);(0,i.useEffect)(()=>{let e=e=>{e.key===`Escape`&&Y&&Fe()},t=()=>{document.fullscreenElement?Ne(!0):(Ne(!1),requestAnimationFrame(()=>{window.scrollTo(0,ye.current)}))};return window.addEventListener(`keydown`,e),document.addEventListener(`fullscreenchange`,t),()=>{window.removeEventListener(`keydown`,e),document.removeEventListener(`fullscreenchange`,t)}},[Y,Fe]),(0,i.useEffect)(()=>{if(!b)return;let e=e=>{if((e.ctrlKey||e.metaKey)&&(e.key===`f`||e.key===`F`)){if(!ge.current)return;e.preventDefault(),e.stopPropagation(),de(!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=>pe(e.matches);return pe(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=>me(e.matches);return me(e.matches),e.addEventListener(`change`,t),()=>e.removeEventListener(`change`,t)},[]);let X=(0,c.useEditor)({extensions:Kr({placeholder:r||e.o(`editor.placeholder`),maxLength:f,maxAttachmentSize:p,maxTotalAttachmentSize:m}),content:T,editable:!w,immediatelyRender:S,onUpdate:({editor:e})=>{n&&(he.current&&clearTimeout(he.current),he.current=setTimeout(()=>{n?.(e.getHTML(),e.getJSON())},300))},onCreate:()=>{},onSelectionUpdate:({editor:e})=>{let{from:t,to:n}=e.state.selection,r=t===n?``:e.state.doc.textBetween(t,n,`
|
|
16
|
-
`);ke(Jr(r))},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=xe.current?.storage?.relativeMedia;i&&(i.clipboardFiles=new Map(Array.from(n.files??[]).map(e=>[e.name.toLowerCase(),e])),i.pausedUntilPaste=!1);let a=xe.current?di(xe.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)(()=>{xe.current=X,window.__editor=X},[X]),(0,i.useEffect)(()=>{if(X)return()=>mt(X)},[X]),(0,i.useEffect)(()=>{!X||!x||x(X)},[X,x]),(0,i.useEffect)(()=>{if(!X)return;let e=()=>{X.state.selection.empty&&(z(`none`),Te(!1))};return X.on(`selectionUpdate`,e),()=>{X.off(`selectionUpdate`,e)}},[X]),(0,i.useEffect)(()=>{X&&X.setOptions({extensions:Kr({placeholder:r||e.o(`editor.placeholder`),maxLength:f,maxAttachmentSize:p,maxTotalAttachmentSize:m})})},[r,f,p,m]);let Le=(0,i.useRef)(t);(0,i.useEffect)(()=>{if(!X||t===Le.current)return;Le.current=t;let n=typeof t==`object`&&t||ui(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 ve(C)},[C]),(0,i.useEffect)(()=>{if(!X)return;let e=Tt(X.state.doc);e>m&&J(`文档内附件总大小 ${Et(e)} 已超过限制 ${Et(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 Re=(0,i.useCallback)((e,t)=>{let n=e?Math.max(8,Math.min(e.left,window.innerWidth-240-8)):8,r;return r=e?t&&e.bottom+8+t>window.innerHeight?Math.max(8,e.top-t-8):e.bottom+8:8,{position:`fixed`,top:r,left:n,zIndex:9999}},[]),ze=(0,i.useCallback)(e=>{let t=Ce.current?.getBoundingClientRect()??null;oe.current=t,z(e),Te(!1),V(Re(t,void 0))},[Re]);(0,i.useLayoutEffect)(()=>{if(R===`none`)return;let e=ae.current;V(Re(oe.current,e?.offsetHeight||void 0))},[R,Re]),(0,i.useEffect)(()=>{if(R===`none`)return;let e=()=>z(`none`),t=()=>{let e=ae.current;V(Re(oe.current,e?.offsetHeight||void 0))};return window.addEventListener(`scroll`,e,!0),window.addEventListener(`resize`,t),()=>{window.removeEventListener(`scroll`,e,!0),window.removeEventListener(`resize`,t)}},[R,Re]),(0,i.useEffect)(()=>{R===`none`&&(oe.current=null)},[R]);let Z=Qr(t=>e.o(t)),Be=Z.filter(e=>!e.more),Ve=Z.filter(e=>e.more),He=Be.filter(e=>e.key!==`ai`&&(e.key!==`mathInline`||Oe)),Ue=Be.find(e=>e.key===`ai`),We=(0,i.useCallback)(e=>{if(X)if(Te(!1),e.key===`link`)if(X.isActive(`link`))X.chain().focus().unsetLink().run();else{let e=X.getAttributes(`link`).href||``;U(e),ze(`link`)}else e.key===`highlight`?R===`highlight`?z(`none`):ze(`highlight`):e.command(X)},[X,R,ze]),Ge=(0,i.useCallback)(e=>X?e.key===`highlight`?R===`highlight`:e.key===`link`?X.isActive(`link`):e.isActive(X):!1,[X,R]),[Q,qe]=(0,i.useState)(0);(0,i.useEffect)(()=>{if(!X)return;let e=()=>qe(e=>(e+1)%1e6);return X.on(`update`,e),()=>{X.off(`update`,e)}},[X]);let[Je,Ye]=(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)}),Ye(e)};return e(),X.on(`update`,e),()=>{X.off(`update`,e)}},[X]);let Xe=(0,i.useMemo)(()=>X?.storage?.characterCount?.characters?.()??0,[X,Q]),Ze=f?Xe>f:!1;(0,i.useEffect)(()=>()=>{he.current&&clearTimeout(he.current)},[]),(0,i.useEffect)(()=>()=>{W&&W.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}}be.current=n;let r=ge.current?.getBoundingClientRect(),i=li(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)=>{se({filename:e,resolve:t})},e.openAI=Qe,e.parseMd=(e,t)=>X?di(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=be.current;if(!e)return;let t=P.current,n=ge.current?.getBoundingClientRect(),r=li(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=be.current;if(!e)return;let t=P.current,n=ge.current?.getBoundingClientRect(),r=li(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||(be.current=null)},[E]);let $e=(0,i.useCallback)(e=>{X?.chain().focus().setImage({src:e}).run()},[X]),et=(0,i.useCallback)(e=>{(X?.commands).insertVideo?.({src:e})},[X]),tt=G&&fe&&!Y&&!Me,nt=!tt&&!ce&&(G||Je&&!(!w&&q)),it=(0,i.useRef)(!1);return(0,i.useEffect)(()=>{it.current||(it.current=!0,G&&!tt&&le(!0))},[G,tt]),(0,i.useEffect)(()=>{if(!ce)return;let e=e=>{let t=e.target;Pe.current?.contains(t)||le(!1)},t=e=>{e.key===`Escape`&&le(!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)}},[ce]),(0,i.useEffect)(()=>{if(!X||!tt)return;let e=Se.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=De(X),o=a?Ee(a):null;if(o){o.scrollTop+=n,t.preventDefault(),t.stopPropagation();return}};return e.addEventListener(`wheel`,t,{passive:!1}),()=>e.removeEventListener(`wheel`,t)},[X,tt]),X?(0,a.jsxs)(`div`,{className:`qingwu-editor-row`,children:[(0,a.jsxs)(`div`,{ref:ge,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${G?` is-active`:``}`,onClick:()=>{G?(K(!1),le(!1)):(K(!0),fe&&!Y&&!Me||le(!0))},title:G?`隐藏目录`:`显示目录`,"aria-label":G?`隐藏目录`:`显示目录`,"aria-pressed":G,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${ue?` is-active`:``}`,onClick:()=>de(!ue),title:`查找 (Ctrl+F)`,"aria-label":`查找`,"aria-pressed":ue,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:()=>ie(!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:Fe,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${Me?` is-active`:``}`,onClick:Ie,title:Me?`退出全屏`:`全屏`,"aria-label":Me?`退出全屏`:`全屏`,"aria-pressed":Me,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:Ce,className:`bubble-menu-items relative flex items-center gap-0.5`,onPointerDown:e=>{e.target.closest(`button`)&&e.preventDefault()},children:[He.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(),We(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(),Te(!1),Ue?.command(X)},title:Ue?.label,"aria-label":Ue?.label,children:(0,a.jsx)(rt,{})}),(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":we,className:`flex items-center justify-center w-7 h-7 rounded-lg transition-colors ${we?`bg-default-100 text-default-900`:`text-default-600 hover:bg-default-100`}`,onClick:e=>{e.preventDefault(),Te(e=>!e)},title:e.o(`editor.bubble.more`),"aria-label":e.o(`editor.bubble.more`),children:(0,a.jsx)(at,{})}),we&&(0,a.jsx)(`div`,{role:`menu`,className:`bubble-more-menu absolute right-0 top-full z-[9999] mt-1 w-max max-h-[70dvh] 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:Ve.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 ${Ge(e)?`bg-primary/10 text-primary`:`text-default-600 hover:bg-default-100`}`,onClick:t=>{t.preventDefault(),We(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&&R!==`none`&&(0,u.createPortal)((0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(`div`,{className:`fixed inset-0 z-[9998]`,onClick:()=>z(`none`)}),(0,a.jsx)(`div`,{ref:ae,style:B,className:`bg-background border border-default-200 rounded-xl shadow-xl`,onClick:e=>e.stopPropagation(),children:R===`highlight`?(0,a.jsxs)(`div`,{className:`flex items-center gap-1 p-1.5 flex-wrap`,children:[ai.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(),z(`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(),z(`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:H,onChange:e=>U(e.target.value),onKeyDown:e=>{e.key===`Enter`?(H.trim()&&X.chain().focus().setLink({href:H.trim()}).run(),z(`none`)):e.key===`Escape`&&z(`none`)}}),(0,a.jsx)(`button`,{type:`button`,className:`px-2 py-1 text-xs rounded-md bg-primary text-white hover:opacity-90`,onClick:()=>{H.trim()&&X.chain().focus().setLink({href:H.trim()}).run(),z(`none`)},children:`确定`})]})})]}),document.body),!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)(Ct,{editor:X,onClose:()=>D(!1)})]})]}),document.body),F&&(0,a.jsx)(i.Suspense,{fallback:(0,a.jsx)(_i,{}),children:(0,a.jsx)(fi,{open:F,onClose:()=>ee(!1),onInsert:$e,validate:e=>X?Ot(X.state.doc,e,{maxAttachmentSize:p,maxTotalAttachmentSize:m}):null})}),I&&(0,a.jsx)(i.Suspense,{fallback:(0,a.jsx)(_i,{}),children:(0,a.jsx)(hi,{open:I,onClose:()=>L(!1),onInsert:et})}),te&&(0,a.jsx)(i.Suspense,{fallback:(0,a.jsx)(_i,{}),children:(0,a.jsx)(pi,{open:te,onClose:()=>ne(!1)})}),re&&(0,a.jsx)(i.Suspense,{fallback:(0,a.jsx)(_i,{}),children:(0,a.jsx)(mi,{open:re,onClose:()=>ie(!1),editor:X})}),W&&(0,a.jsx)(i.Suspense,{fallback:(0,a.jsx)(_i,{}),children:(0,a.jsx)(gi,{open:!!W,filename:W.filename,onRender:()=>{W.resolve(`render`),se(null)},onAttach:()=>{W.resolve(`attach`),se(null)},onClose:()=>{W.resolve(null),se(null)}})}),(0,a.jsx)(`div`,{ref:_e,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)(ii,{editor:X}),(0,a.jsx)(`div`,{className:`${Y||Me?`fixed`:`absolute`} bottom-2 right-4 z-10 pointer-events-none select-none`,children:(0,a.jsxs)(`span`,{className:`text-xs ${Ze?`bg-danger/10 text-danger font-medium px-2 py-0.5 rounded`:f&&Xe>f*.9?`bg-warning/10 text-warning px-2 py-0.5 rounded`:`text-default-300`}`,children:[Xe,f?` / ${f}`:``,` 字`]})})]})}),b&&ue&&(0,a.jsx)(Ke,{editor:X,onClose:()=>de(!1)}),nt&&(0,a.jsx)(`button`,{type:`button`,className:`qingwu-toc-fab`,onClick:()=>le(!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`})})}),ce&&(0,u.createPortal)((0,a.jsxs)(`div`,{ref:Pe,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:()=>le(!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)(Ae,{editor:X,className:`!p-3`,onClose:()=>{le(!1),K(!1)}})]}),document.body)]}),tt&&(0,u.createPortal)((0,a.jsx)(`aside`,{ref:Se,className:`qingwu-toc-desktop toc-scroll`,children:(0,a.jsx)(Ae,{editor:X,onClose:()=>K(!1)})}),document.body)]}):(0,a.jsx)(`div`,{className:`flex items-center justify-center h-32 text-default-400`,children:e.o(`editor.loading`)})};function yi(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 bi(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 xi(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=Sn,exports.CodeBlock=On,exports.ImageUpload=Qn,exports.ImageUploadDialog=be,exports.MathBlock=gr,exports.MathInline=hr,exports.QingWuAIEditor=vi,exports.RelativeMedia=Vr,exports.SearchHighlight=We,exports.TocPanel=Ae,exports.VideoEmbed=dn,exports.buildSystemPrompt=je,exports.createAILanguageModelProvider=Ne,exports.createCOSStorage=bi,exports.createDeepSeekProvider=X,exports.createLocalStorage=r.t,exports.createOSSStorage=xi,exports.createOpenAICompatProvider=Ie,exports.createOpenAIProvider=Le,exports.createQwenProvider=Re,exports.createS3Storage=r.n,exports.createSlashCommandExtension=Ur,exports.escapeHtml=e.t,exports.formatBytes=Et,exports.getAIProvider=Fe,exports.getBubbleMenuActions=Qr,exports.getDefaultSlashCommands=Wr,exports.getDocAttachmentTotal=Tt,exports.getEditorExtensions=Kr,exports.getLocale=e.i,exports.getSearchEngine=Zr,exports.getSearchState=Ge,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=Pe,exports.setConfirmProvider=Pt,exports.setLocale=e.a,exports.setSearchEngine=Xr,exports.setStorageProvider=n.a,exports.setToastProvider=_e,exports.signPreviewUrlHeaders=t.r,exports.startBrowserClipperReceiver=yi,exports.subscribeToast=ve,exports.t=e.o,exports.tf=e.s,exports.toast=J,exports.validateAttachmentFile=Ot;
|
|
13
|
+
`).trim();r&&navigator.clipboard?.writeText(r).catch(()=>{})}},{key:`search`,label:e(`editor.bubble.search`),icon:(0,a.jsx)(nt,{}),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=Qr.replace(`{query}`,encodeURIComponent(r));window.open(i,`_blank`,`noopener,noreferrer`)}},{key:`table`,label:e(`editor.bubble.table`),icon:(0,a.jsx)(et,{}),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)(rt,{}),isActive:()=>!1,command:e=>{e.isEditable&&e.storage.qingwuUI?.openAI?.()}}]}d.Extension.create({name:`bubbleMenu`});function ni(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 ri(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 ii(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(`
|
|
14
|
+
`)}function ai(e){let t=e=>/[",\n]/.test(e)?`"${e.replace(/"/g,`""`)}"`:e;return e.map(e=>e.map(t).join(`,`)).join(`
|
|
15
|
+
`)}function oi(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 si({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=ni(e);n(t?e=>e===t.pos?e:t.pos:null)},[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=ni(e);if(!t)return;let n=ii(ri(t.node));navigator.clipboard?.writeText(n),o(!0),setTimeout(()=>o(!1),1500)},g=()=>{let t=ni(e);if(!t)return;let n=ai(ri(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=oi(t);if(!n||n.length===0)return;let r=m(n);if(!r)return;let i=ni(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&&!Mt()&&($(!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)(Lt,{open:s,title:`确认删除表格`,message:`此操作不可撤销。`,onCancel:()=>{$(!1),c(!1)},onConfirm:async()=>{await new Promise(e=>setTimeout(e,300)),$(!1),y()}})]})}var ci=[{color:`#fef08a`,name:`黄`},{color:`#bbf7d0`,name:`绿`},{color:`#bfdbfe`,name:`蓝`},{color:`#fbcfe8`,name:`粉`},{color:`#fed7aa`,name:`橙`},{color:`#ddd6fe`,name:`紫`}],li=288,ui=480,di=320;function fi(e,t,n={}){let r=window.innerWidth,i=window.innerHeight,a=Math.min(n.panelWidth||li,ui,r-32),o=Math.max(t||di,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 pi(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*\|.+\||(^|\n)\s*\$\$[\s\S]*?\$\$|(^|[^\\$])\$[^\s$\n](?:[^$\n]*[^\s$\n])?\$/i.test(e)}function mi(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 hi=(0,i.lazy)(()=>Promise.resolve().then(()=>xe).then(e=>({default:e.ImageUploadDialog}))),gi=(0,i.lazy)(()=>Promise.resolve().then(()=>require("./storage-settings-dialog-BPlrjhQc.cjs")).then(e=>({default:e.StorageSettingsDialog}))),_i=(0,i.lazy)(()=>Promise.resolve().then(()=>require("./export-dialog-Co3pPwTl.cjs")).then(e=>({default:e.ExportDialog}))),vi=(0,i.lazy)(()=>Promise.resolve().then(()=>require("./video-embed-dialog-DwcFWipC.cjs")).then(e=>({default:e.VideoEmbedDialog}))),yi=(0,i.lazy)(()=>Promise.resolve().then(()=>require("./md-import-dialog-CVvu-Adt.cjs")).then(e=>({default:e.MdImportDialog}))),bi=()=>(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`})})]}),xi=({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||pi(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,ne]=(0,i.useState)(!1),[re,ie]=(0,i.useState)(!1),[R,z]=(0,i.useState)(`none`),[ae,B]=(0,i.useState)({}),oe=(0,i.useRef)(null),se=(0,i.useRef)(null),[V,H]=(0,i.useState)(``),[ce,le]=(0,i.useState)(null),[U,W]=(0,i.useState)(y),[ue,de]=(0,i.useState)(!1);(0,i.useEffect)(()=>{W(y)},[y]);let[fe,pe]=(0,i.useState)(!1),[me,he]=(0,i.useState)(()=>typeof window<`u`&&typeof window.matchMedia==`function`?window.matchMedia(`(min-width: 80rem)`).matches:!0),[G,ge]=(0,i.useState)(()=>typeof window<`u`&&typeof window.matchMedia==`function`?window.matchMedia(`(min-width: 64rem)`).matches:!0),_e=(0,i.useRef)(null),ve=(0,i.useRef)(null),ye=(0,i.useRef)(null),xe=(0,i.useRef)(0),Se=(0,i.useRef)(null),Ce=(0,i.useRef)(null),we=(0,i.useRef)(null),Te=(0,i.useRef)(null),Ee=(0,i.useRef)(null),[De,Ae]=(0,i.useState)(!1),[je,Me]=(0,i.useState)(!1),[q,Pe]=(0,i.useState)(!1),[Fe,Ie]=(0,i.useState)(!1),Le=(0,i.useRef)(null),Re=(0,i.useCallback)(()=>{let e=ve.current,t=ye.current;e&&(q?(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:``}),Pe(!1),requestAnimationFrame(()=>{window.scrollTo(0,xe.current)})):(document.fullscreenElement&&document.exitFullscreen(),xe.current=window.scrollY,Object.assign(e.style,{position:`fixed`,top:`0`,left:`0`,width:`100%`,zIndex:`99999`,background:`var(--background, #fff)`,borderRadius:`0`,overflow:`hidden`,display:`flex`,flexDirection:`column`}),e.style.height=`100vh`,e.style.height=`100dvh`,t&&Object.assign(t.style,{flex:`1`,overflow:`auto`,minHeight:`0`}),document.body.style.overflow=`hidden`,Pe(!0)))},[q]),ze=(0,i.useCallback)(()=>{let e=ve.current;e&&(document.fullscreenElement?document.exitFullscreen():(q&&Re(),xe.current=window.scrollY,e.requestFullscreen()))},[q,Re]);(0,i.useEffect)(()=>{let e=e=>{e.key===`Escape`&&q&&Re()},t=()=>{document.fullscreenElement?Ie(!0):(Ie(!1),requestAnimationFrame(()=>{window.scrollTo(0,xe.current)}))};return window.addEventListener(`keydown`,e),document.addEventListener(`fullscreenchange`,t),()=>{window.removeEventListener(`keydown`,e),document.removeEventListener(`fullscreenchange`,t)}},[q,Re]),(0,i.useEffect)(()=>{if(!b)return;let e=e=>{if((e.ctrlKey||e.metaKey)&&(e.key===`f`||e.key===`F`)){if(!ve.current)return;e.preventDefault(),e.stopPropagation(),pe(!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=>he(e.matches);return he(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=>ge(e.matches);return ge(e.matches),e.addEventListener(`change`,t),()=>e.removeEventListener(`change`,t)},[]);let J=(0,c.useEditor)({extensions:Yr({placeholder:r||e.o(`editor.placeholder`),maxLength:f,maxAttachmentSize:p,maxTotalAttachmentSize:m}),content:T,editable:!w,immediatelyRender:S,onUpdate:({editor:e})=>{n&&(_e.current&&clearTimeout(_e.current),_e.current=setTimeout(()=>{n?.(e.getHTML(),e.getJSON())},300))},onCreate:()=>{},onSelectionUpdate:({editor:e})=>{let{from:t,to:n}=e.state.selection,r=t===n?``:e.state.doc.textBetween(t,n,`
|
|
16
|
+
`);Me(Zr(r))},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=Ce.current?.storage?.relativeMedia;i&&(i.clipboardFiles=new Map(Array.from(n.files??[]).map(e=>[e.name.toLowerCase(),e])),i.pausedUntilPaste=!1);let a=Ce.current?mi(Ce.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)(()=>{Ce.current=J,window.__editor=J},[J]),(0,i.useEffect)(()=>{if(J)return()=>mt(J)},[J]),(0,i.useEffect)(()=>{J&&x&&x(J)},[J,x]),(0,i.useEffect)(()=>{if(!J)return;let e=()=>{J.state.selection.empty&&(z(`none`),Ae(!1))};return J.on(`selectionUpdate`,e),()=>{J.off(`selectionUpdate`,e)}},[J]),(0,i.useEffect)(()=>{J&&J.setOptions({extensions:Yr({placeholder:r||e.o(`editor.placeholder`),maxLength:f,maxAttachmentSize:p,maxTotalAttachmentSize:m})})},[r,f,p,m]);let Be=(0,i.useRef)(t);(0,i.useEffect)(()=>{if(!J||t===Be.current)return;Be.current=t;let n=typeof t==`object`&&t||pi(t)?t:e.n(t);J.commands.setContent(n,{emitUpdate:!1})},[J,t]),(0,i.useEffect)(()=>{J&&J.setEditable(!w,!1)},[J,w]),(0,i.useEffect)(()=>{if(C)return be(C)},[C]),(0,i.useEffect)(()=>{if(!J)return;let e=Tt(J.state.doc);e>m&&K(`文档内附件总大小 ${Et(e)} 已超过限制 ${Et(m)}`,`info`)},[J,m]),(0,i.useEffect)(()=>{if(!J)return;let e=J.storage.qingwuUI;e&&(e.limits={maxAttachmentSize:p,maxTotalAttachmentSize:m})},[J,p,m]);let Y=(0,i.useCallback)((e,t)=>{let n=window.visualViewport,r=n?.offsetLeft??0,i=n?.offsetTop??0,a=n?.width??window.innerWidth,o=n?.height??window.innerHeight,s=Math.min(252,a-16),c=e?Math.max(r+8,Math.min(e.left,r+a-s-8)):r+8,l;return l=e?t&&e.bottom+8+t>i+o-8?e.top-t-8:e.bottom+8:i+8,l=Math.max(i+8,Math.min(l,i+o-(t??0)-8)),{position:`fixed`,top:l,left:c,width:s,maxHeight:o-16,overflowY:`auto`,zIndex:9999}},[]),X=(0,i.useCallback)(e=>{let t=Te.current?.getBoundingClientRect()??null;se.current=t,z(e),Ae(!1),B(Y(t,void 0))},[Y]);(0,i.useLayoutEffect)(()=>{if(R===`none`)return;let e=oe.current;B(Y(se.current,e?.offsetHeight||void 0))},[R,Y]);let Z=(0,i.useCallback)(()=>{let e=Ee.current,t=Te.current;if(!e||!t)return;let n=t.getBoundingClientRect(),r=window.visualViewport,i=r?.offsetTop??0,a=r?.height??window.innerHeight,o=i+a-n.bottom-16,s=n.top-i-16,c=o<e.scrollHeight+2&&s>o;e.dataset.placement=c?`above`:`below`,e.style.maxHeight=`${Math.max(40,Math.min(a-16,c?s:o))}px`},[]);(0,i.useLayoutEffect)(()=>{if(!De)return;Z();let e=window.visualViewport;return window.addEventListener(`resize`,Z),window.addEventListener(`scroll`,Z,!0),e?.addEventListener(`resize`,Z),e?.addEventListener(`scroll`,Z),()=>{window.removeEventListener(`resize`,Z),window.removeEventListener(`scroll`,Z,!0),e?.removeEventListener(`resize`,Z),e?.removeEventListener(`scroll`,Z)}},[De,Z]),(0,i.useEffect)(()=>{if(R===`none`)return;let e=()=>z(`none`),t=()=>{let e=oe.current;B(Y(Te.current?.getBoundingClientRect()??se.current,e?.offsetHeight||void 0))},n=window.visualViewport;return window.addEventListener(`scroll`,e,!0),window.addEventListener(`resize`,t),n?.addEventListener(`resize`,t),n?.addEventListener(`scroll`,t),()=>{window.removeEventListener(`scroll`,e,!0),window.removeEventListener(`resize`,t),n?.removeEventListener(`resize`,t),n?.removeEventListener(`scroll`,t)}},[R,Y]),(0,i.useEffect)(()=>{R===`none`&&(se.current=null)},[R]);let Ve=ti(t=>e.o(t)),He=Ve.filter(e=>!e.more),Ue=Ve.filter(e=>e.more),We=He.filter(e=>e.key!==`ai`&&(e.key!==`mathInline`||je)),Ge=He.find(e=>e.key===`ai`),Q=(0,i.useCallback)(e=>{if(J){if(Ae(!1),e.key===`link`){if(J.isActive(`link`))J.chain().focus().unsetLink().run();else{let e=J.getAttributes(`link`).href||``;H(e),X(`link`)}}else e.key===`highlight`?R===`highlight`?z(`none`):X(`highlight`):e.command(J)}},[J,R,X]),qe=(0,i.useCallback)(e=>J?e.key===`highlight`?R===`highlight`:e.key===`link`?J.isActive(`link`):e.isActive(J):!1,[J,R]),[Je,Ye]=(0,i.useState)(0);(0,i.useEffect)(()=>{if(!J)return;let e=()=>Ye(e=>(e+1)%1e6);return J.on(`update`,e),()=>{J.off(`update`,e)}},[J]);let[Xe,Ze]=(0,i.useState)(!1);(0,i.useEffect)(()=>{if(!J)return;let e=()=>{let e=!1;J.state.doc.descendants(t=>{t.type.name===`heading`&&(e=!0)}),Ze(e)};return e(),J.on(`update`,e),()=>{J.off(`update`,e)}},[J]);let Qe=(0,i.useMemo)(()=>J?.storage?.characterCount?.characters?.()??0,[J,Je]),$e=f?Qe>f:!1;(0,i.useEffect)(()=>()=>{_e.current&&clearTimeout(_e.current)},[]),(0,i.useEffect)(()=>()=>{ce&&ce.resolve(null)},[]);let et=(0,i.useCallback)(e=>{if(!J?.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=J.view.coordsAtPos(J.state.selection.from);n={top:e.bottom,left:e.left,width:0}}Se.current=n;let r=ve.current?.getBoundingClientRect(),i=fi(n,void 0,{panelWidth:r?.width,editorLeft:r?.left});D(!0),k(i.style),j(i.placement),N(i.arrowLeft)},[J]);(0,i.useEffect)(()=>{if(!J)return;let e=J.storage.qingwuUI;if(e)return e.openImageDialog=()=>ee(!0),e.openVideoDialog=()=>L(!0),e.chooseMd=(e,t)=>{le({filename:e,resolve:t})},e.openAI=et,e.parseMd=(e,t)=>J?mi(J,t):null,()=>{delete e.openImageDialog,delete e.openVideoDialog,delete e.openAI,delete e.parseMd,delete e.chooseMd}},[J,et]),(0,i.useLayoutEffect)(()=>{if(!E||!J)return;let e=Se.current;if(!e)return;let t=P.current,n=ve.current?.getBoundingClientRect(),r=fi(e,t?.offsetHeight||void 0,{panelWidth:n?.width,editorLeft:n?.left});j(r.placement),N(r.arrowLeft),k(r.style)},[E,J]),(0,i.useEffect)(()=>{if(!E||!J)return;let e=()=>{let e=Se.current;if(!e)return;let t=P.current,n=ve.current?.getBoundingClientRect(),r=fi(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,J]),(0,i.useEffect)(()=>{E||(Se.current=null)},[E]);let tt=(0,i.useCallback)(e=>{J&&nn(J.view,J.schema.nodes.image.create({src:e}))},[J]),nt=(0,i.useCallback)(e=>{(J?.commands).insertVideo?.({src:e})},[J]),it=U&&me&&!q&&!Fe,ot=!it&&!ue&&(U||Xe&&!(!w&&G)),st=(0,i.useRef)(!1);return(0,i.useEffect)(()=>{st.current||(st.current=!0,U&&!it&&de(!0))},[U,it]),(0,i.useEffect)(()=>{if(!ue)return;let e=e=>{let t=e.target;Le.current?.contains(t)||de(!1)},t=e=>{e.key===`Escape`&&de(!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)}},[ue]),(0,i.useEffect)(()=>{if(!J||!it)return;let e=we.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=ke(J),o=a?Oe(a):null;o&&(o.scrollTop+=n,t.preventDefault(),t.stopPropagation())};return e.addEventListener(`wheel`,t,{passive:!1}),()=>e.removeEventListener(`wheel`,t)},[J,it]),J?(0,a.jsxs)(`div`,{className:`qingwu-editor-row`,children:[(0,a.jsxs)(`div`,{ref:ve,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${U?` is-active`:``}`,onClick:()=>{U?(W(!1),de(!1)):(W(!0),(!me||q||Fe)&&de(!0))},title:U?`隐藏目录`:`显示目录`,"aria-label":U?`隐藏目录`:`显示目录`,"aria-pressed":U,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${fe?` is-active`:``}`,onClick:()=>pe(!fe),title:`查找 (Ctrl+F)`,"aria-label":`查找`,"aria-pressed":fe,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):et(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:()=>ie(!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${q?` is-active`:``}`,onClick:Re,title:q?`退出网页全屏`:`网页全屏`,"aria-label":q?`退出网页全屏`:`网页全屏`,"aria-pressed":q,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${Fe?` is-active`:``}`,onClick:ze,title:Fe?`退出全屏`:`全屏`,"aria-label":Fe?`退出全屏`:`全屏`,"aria-pressed":Fe,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`})})})]})]}),J&&!w&&J.isEditable&&(0,a.jsx)(l.BubbleMenu,{editor:J,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:{padding:8},shift:{padding:8},size:{padding:8,apply:({availableWidth:e,elements:t})=>{t.floating.style.maxWidth=`${e}px`}},onUpdate:Z},className:`qw-bubble bubble-menu-pop`,children:(0,a.jsxs)(`div`,{ref:Te,className:`bubble-menu-items`,onPointerDown:e=>{e.target.closest(`button`)&&e.preventDefault()},children:[We.map(e=>(0,a.jsx)(`button`,{type:`button`,className:`qw-bubble-button`,"data-active":e.isActive(J),"aria-pressed":e.isActive(J),onClick:t=>{t.preventDefault(),Q(e)},title:e.label,"aria-label":e.label,children:e.icon},e.key)),(0,a.jsx)(`span`,{className:`qw-bubble-divider`,"aria-hidden":`true`}),(0,a.jsx)(`button`,{type:`button`,className:`qw-bubble-button qw-bubble-button--ai`,"data-active":E,onClick:e=>{e.preventDefault(),Ae(!1),Ge?.command(J)},title:Ge?.label,"aria-label":Ge?.label,children:(0,a.jsx)(rt,{})}),(0,a.jsx)(`span`,{className:`qw-bubble-divider`,"aria-hidden":`true`}),(0,a.jsx)(`button`,{type:`button`,"aria-expanded":De,"aria-haspopup":`menu`,className:`qw-bubble-button`,"data-active":De,onClick:e=>{e.preventDefault(),Ae(e=>!e)},title:e.o(`editor.bubble.more`),"aria-label":e.o(`editor.bubble.more`),children:(0,a.jsx)(at,{})}),De&&(0,a.jsx)(`div`,{ref:Ee,role:`menu`,className:`bubble-more-menu`,onPointerDown:e=>{e.target.closest(`button`)&&e.preventDefault()},children:Ue.map(e=>(0,a.jsxs)(`button`,{type:`button`,role:`menuitem`,className:`qw-bubble-menu-item`,"data-active":qe(e),onClick:t=>{t.preventDefault(),Q(e)},title:e.label,children:[(0,a.jsx)(`span`,{className:`qw-bubble-menu-icon`,children:e.icon}),(0,a.jsx)(`span`,{children:e.label})]},e.key))})]})}),J&&R!==`none`&&(0,u.createPortal)((0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(`div`,{className:`fixed inset-0 z-[9998]`,onClick:()=>z(`none`)}),(0,a.jsx)(`div`,{ref:oe,style:ae,className:`qw-bubble-panel`,onClick:e=>e.stopPropagation(),children:R===`highlight`?(0,a.jsxs)(`div`,{className:`qw-bubble-colors`,children:[ci.map(e=>(0,a.jsx)(`button`,{type:`button`,className:`qw-bubble-swatch`,style:{background:e.color},title:e.name,"aria-label":e.name,onClick:()=>{J.chain().focus().setHighlight({color:e.color}).run(),z(`none`)}},e.color)),(0,a.jsxs)(`button`,{type:`button`,className:`qw-bubble-swatch qw-bubble-clear`,title:`清除高亮`,"aria-label":`清除高亮`,onClick:()=>{J.chain().focus().unsetHighlight().run(),z(`none`)},children:[`✕`,` `]})]}):(0,a.jsxs)(`div`,{className:`qw-bubble-link`,children:[(0,a.jsx)(`input`,{type:`url`,className:`qw-bubble-link-input`,placeholder:`https://...`,"aria-label":`链接地址`,value:V,onChange:e=>H(e.target.value),onKeyDown:e=>{e.key===`Enter`?(V.trim()&&J.chain().focus().setLink({href:V.trim()}).run(),z(`none`)):e.key===`Escape`&&z(`none`)}}),(0,a.jsx)(`button`,{type:`button`,className:`qw-bubble-link-apply`,onClick:()=>{V.trim()&&J.chain().focus().setLink({href:V.trim()}).run(),z(`none`)},children:`确定`})]})})]}),document.body),!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)(Ct,{editor:J,onClose:()=>D(!1)})]})]}),document.body),F&&(0,a.jsx)(i.Suspense,{fallback:(0,a.jsx)(bi,{}),children:(0,a.jsx)(hi,{open:F,onClose:()=>ee(!1),onInsert:tt,validate:e=>J?Ot(J.state.doc,e,{maxAttachmentSize:p,maxTotalAttachmentSize:m}):null})}),I&&(0,a.jsx)(i.Suspense,{fallback:(0,a.jsx)(bi,{}),children:(0,a.jsx)(vi,{open:I,onClose:()=>L(!1),onInsert:nt})}),te&&(0,a.jsx)(i.Suspense,{fallback:(0,a.jsx)(bi,{}),children:(0,a.jsx)(gi,{open:te,onClose:()=>ne(!1)})}),re&&(0,a.jsx)(i.Suspense,{fallback:(0,a.jsx)(bi,{}),children:(0,a.jsx)(_i,{open:re,onClose:()=>ie(!1),editor:J})}),ce&&(0,a.jsx)(i.Suspense,{fallback:(0,a.jsx)(bi,{}),children:(0,a.jsx)(yi,{open:!!ce,filename:ce.filename,onRender:()=>{ce.resolve(`render`),le(null)},onAttach:()=>{ce.resolve(`attach`),le(null)},onClose:()=>{ce.resolve(null),le(null)}})}),(0,a.jsx)(`div`,{ref:ye,className:`flex editor-body`,children:(0,a.jsxs)(`div`,{className:`relative min-w-0 flex-1`,children:[(0,a.jsx)(c.EditorContent,{editor:J}),!w&&(0,a.jsx)(si,{editor:J}),(0,a.jsx)(`div`,{className:`${q||Fe?`fixed`:`absolute`} bottom-2 right-4 z-10 pointer-events-none select-none`,children:(0,a.jsxs)(`span`,{className:`text-xs ${$e?`bg-danger/10 text-danger font-medium px-2 py-0.5 rounded`:f&&Qe>f*.9?`bg-warning/10 text-warning px-2 py-0.5 rounded`:`text-default-300`}`,children:[Qe,f?` / ${f}`:``,` 字`]})})]})}),b&&fe&&(0,a.jsx)(Ke,{editor:J,onClose:()=>pe(!1)}),ot&&(0,a.jsx)(`button`,{type:`button`,className:`qingwu-toc-fab`,onClick:()=>de(!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`})})}),ue&&(0,u.createPortal)((0,a.jsxs)(`div`,{ref:Le,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:()=>de(!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)(Ne,{editor:J,className:`!p-3`,onClose:()=>{de(!1),W(!1)}})]}),document.body)]}),it&&(0,u.createPortal)((0,a.jsx)(`aside`,{ref:we,className:`qingwu-toc-desktop toc-scroll`,children:(0,a.jsx)(Ne,{editor:J,onClose:()=>W(!1)})}),document.body)]}):(0,a.jsx)(`div`,{className:`flex items-center justify-center h-32 text-default-400`,children:e.o(`editor.loading`)})};function Si(e){let t=async t=>{let n=t.data;if(!n||typeof n!=`object`||n.kind!==`qingwu-clip`||t.origin!==window.location.origin||t.origin===`null`||t.source!==window)return;let r=n.clip;if(typeof r?.markdown==`string`&&r.markdown.trim())try{await e.onClip(r,t)}catch(e){console.warn(`[qingwu-clipper] 处理剪藏失败:`,e)}};return window.addEventListener(`message`,t),{close:()=>window.removeEventListener(`message`,t)}}function Ci(e){return t.a({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 wi(e){return t.a({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=wn,exports.CodeBlock=An,exports.ImageUpload=er,exports.ImageUploadDialog=Se,exports.MathBlock=yr,exports.MathInline=vr,exports.QingWuAIEditor=xi,exports.RelativeMedia=Wr,exports.SearchHighlight=We,exports.TocPanel=Ne,exports.VideoEmbed=pn,exports.buildSystemPrompt=q,exports.createAILanguageModelProvider=Fe,exports.createCOSStorage=Ci,exports.createDeepSeekProvider=ze,exports.createLocalStorage=r.t,exports.createOSSStorage=wi,exports.createOpenAICompatProvider=Re,exports.createOpenAIProvider=J,exports.createQwenProvider=Be,exports.createS3Storage=t.a,exports.createSlashCommandExtension=Kr,exports.escapeHtml=e.t,exports.formatBytes=Et,exports.getAIProvider=Le,exports.getBubbleMenuActions=ti,exports.getDefaultSlashCommands=qr,exports.getDocAttachmentTotal=Tt,exports.getEditorExtensions=Yr,exports.getLocale=e.i,exports.getSearchEngine=ei,exports.getSearchState=Ge,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=Ie,exports.setConfirmProvider=Pt,exports.setLocale=e.a,exports.setSearchEngine=$r,exports.setStorageProvider=n.a,exports.setToastProvider=ye,exports.signPreviewUrlHeaders=t.r,exports.startBrowserClipperReceiver=Si,exports.subscribeToast=be,exports.t=e.o,exports.tf=e.s,exports.toast=K,exports.validateAttachmentFile=Ot;
|