@qingwu-ui/ai-editor 0.9.0-beta.10 → 0.9.0-beta.11

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.
@@ -1 +1 @@
1
- {"version":3,"file":"sanitize.d.ts","sourceRoot":"","sources":["../../../src/editor/utils/sanitize.ts"],"names":[],"mappings":"AAsBA,gBAAgB;AAChB,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAS/C;AA6BD;;;;;;;;;;GAUG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CASjD;AAED;;;;;;;GAOG;AACH,wBAAgB,WAAW,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAa/C"}
1
+ {"version":3,"file":"sanitize.d.ts","sourceRoot":"","sources":["../../../src/editor/utils/sanitize.ts"],"names":[],"mappings":"AAsBA,gBAAgB;AAChB,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAS/C;AA6BD;;;;;;;;;;GAUG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAajD;AAED;;;;;;;GAOG;AACH,wBAAgB,WAAW,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAa/C"}
@@ -1,4 +1,4 @@
1
- const e=require("./sanitize-BLVk_EcE.cjs");let t=require("react"),n=require("react/jsx-runtime");var r=({open:r,onClose:i,editor:a})=>{let[o,s]=(0,t.useState)(!1),c=(0,t.useCallback)(e=>{if(!a)return``;switch(e){case`html`:return a.getHTML();case`json`:return JSON.stringify(a.getJSON(),null,2);case`text`:return a.state.doc.textContent;case`md`:{let e=a.storage?.markdown;return e?.getMarkdown?e.getMarkdown():a.getHTML()}default:return``}},[a]),l=(0,t.useCallback)(e=>{if(!a)return;let t=c(e),n={html:`text/html`,json:`application/json`,md:`text/markdown`,text:`text/plain`},r={html:`html`,json:`json`,md:`md`,text:`txt`},o=new Blob([t],{type:n[e]||`text/plain`}),s=URL.createObjectURL(o),l=document.createElement(`a`);l.href=s,l.download=`qingwu-doc.${r[e]||`txt`}`,l.click(),URL.revokeObjectURL(s),i()},[a,c,i]),u=(0,t.useCallback)(async e=>{let t=c(e);await navigator.clipboard.writeText(t),s(!0),setTimeout(()=>s(!1),1500)},[c]),d=(0,t.useCallback)(()=>{if(!a)return;let t=e.n(a.getHTML()).replace(/<iframe\b[^>]*>[\s\S]*?<\/iframe>/gi,``).replace(/<iframe\b[^>]*\/?>/gi,``).replace(/<object\b[^>]*>[\s\S]*?<\/object>/gi,``).replace(/<embed\b[^>]*\/?>/gi,``),n=window.open(``,`_blank`);if(!n)return;n.document.write(`
1
+ const e=require("./sanitize-CrbFQE46.cjs");let t=require("react"),n=require("react/jsx-runtime");var r=({open:r,onClose:i,editor:a})=>{let[o,s]=(0,t.useState)(!1),c=(0,t.useCallback)(e=>{if(!a)return``;switch(e){case`html`:return a.getHTML();case`json`:return JSON.stringify(a.getJSON(),null,2);case`text`:return a.state.doc.textContent;case`md`:{let e=a.storage?.markdown;return e?.getMarkdown?e.getMarkdown():a.getHTML()}default:return``}},[a]),l=(0,t.useCallback)(e=>{if(!a)return;let t=c(e),n={html:`text/html`,json:`application/json`,md:`text/markdown`,text:`text/plain`},r={html:`html`,json:`json`,md:`md`,text:`txt`},o=new Blob([t],{type:n[e]||`text/plain`}),s=URL.createObjectURL(o),l=document.createElement(`a`);l.href=s,l.download=`qingwu-doc.${r[e]||`txt`}`,l.click(),URL.revokeObjectURL(s),i()},[a,c,i]),u=(0,t.useCallback)(async e=>{let t=c(e);await navigator.clipboard.writeText(t),s(!0),setTimeout(()=>s(!1),1500)},[c]),d=(0,t.useCallback)(()=>{if(!a)return;let t=e.n(a.getHTML()).replace(/<iframe\b[^>]*>[\s\S]*?<\/iframe>/gi,``).replace(/<iframe\b[^>]*\/?>/gi,``).replace(/<object\b[^>]*>[\s\S]*?<\/object>/gi,``).replace(/<embed\b[^>]*\/?>/gi,``),n=window.open(``,`_blank`);if(!n)return;n.document.write(`
2
2
  <!DOCTYPE html>
3
3
  <html>
4
4
  <head><meta charset="utf-8"><title>青梧文档</title>
@@ -1,4 +1,4 @@
1
- import { n as e, o as t } from "./sanitize-OUn05c7P.js";
1
+ import { n as e, o as t } from "./sanitize-z8gMk0lV.js";
2
2
  import { useCallback as n, useState as r } from "react";
3
3
  import { Fragment as i, jsx as a, jsxs as o } from "react/jsx-runtime";
4
4
  //#region src/components/export-dialog.tsx
package/dist/index.cjs CHANGED
@@ -1,9 +1,9 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("./sanitize-BLVk_EcE.cjs"),t=require("./signed-fetch-D8Rk6R5t.cjs"),n=require("./storage-VaeLS7eM.cjs"),r=require("./local-D4481lUa.cjs");let i=require("react"),a=require("react/jsx-runtime"),o=require("ai"),s=require("@tiptap/pm/model"),c=require("@tiptap/react"),l=require("@tiptap/react/menus"),u=require("react-dom"),d=require("@tiptap/core"),f=require("@tiptap/pm/state"),p=require("@tiptap/pm/view"),m=require("@tiptap/extension-image"),h=require("@tiptap/extension-link"),g=require("@tiptap/extension-underline"),_=require("@tiptap/starter-kit");_=e.l(_,1);let v=require("@tiptap/extension-character-count"),y=require("@tiptap/extension-color"),b=require("@tiptap/extension-highlight"),x=require("@tiptap/extension-horizontal-rule"),S=require("@tiptap/extension-placeholder"),C=require("@tiptap/extension-table"),w=require("@tiptap/extension-table-cell"),T=require("@tiptap/extension-table-header"),E=require("@tiptap/extension-table-row"),D=require("@tiptap/extension-task-item"),O=require("@tiptap/extension-task-list"),k=require("@tiptap/extension-text-style"),A=require("tiptap-markdown"),j=require("@tiptap/extension-code-block-lowlight"),ee=require("highlight.js/lib/languages/dockerfile");ee=e.l(ee,1);let M=require("lowlight"),N=require("@tiptap/suggestion");N=e.l(N,1);var P=null,te=null;function F(){return te||(typeof document>`u`?null:(P=document.createElement(`canvas`),te=P.getContext(`2d`),te))}var I=new Map;function ne(e,t){let n=I.get(t);n||(n=new Map,I.set(t,n));let r=n.get(e);if(r!==void 0)return r;let i=F();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:t===` `?r+=n*.3:r+=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 ae(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 L(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===`
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("./sanitize-CrbFQE46.cjs"),t=require("./signed-fetch-DiWXujJ1.cjs"),n=require("./storage-VaeLS7eM.cjs"),r=require("./local-D4481lUa.cjs");let i=require("react"),a=require("react/jsx-runtime"),o=require("ai"),s=require("@tiptap/pm/model"),c=require("@tiptap/react"),l=require("@tiptap/react/menus"),u=require("react-dom"),d=require("@tiptap/core"),f=require("@tiptap/pm/state"),p=require("@tiptap/pm/view"),m=require("@tiptap/extension-image"),h=require("@tiptap/extension-link"),g=require("@tiptap/extension-underline"),_=require("@tiptap/starter-kit");_=e.l(_,1);let v=require("@tiptap/extension-character-count"),y=require("@tiptap/extension-color"),b=require("@tiptap/extension-highlight"),x=require("@tiptap/extension-horizontal-rule"),S=require("@tiptap/extension-placeholder"),C=require("@tiptap/extension-table"),w=require("@tiptap/extension-table-cell"),T=require("@tiptap/extension-table-header"),E=require("@tiptap/extension-table-row"),D=require("@tiptap/extension-task-item"),O=require("@tiptap/extension-task-list"),k=require("@tiptap/extension-text-style"),A=require("tiptap-markdown"),j=require("@tiptap/extension-code-block-lowlight"),ee=require("highlight.js/lib/languages/dockerfile");ee=e.l(ee,1);let M=require("lowlight"),N=require("@tiptap/suggestion");N=e.l(N,1);var P=null,te=null;function F(){return te||(typeof document>`u`?null:(P=document.createElement(`canvas`),te=P.getContext(`2d`),te))}var I=new Map;function ne(e,t){let n=I.get(t);n||(n=new Map,I.set(t,n));let r=n.get(e);if(r!==void 0)return r;let i=F();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:t===` `?r+=n*.3:r+=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 ae(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 L(e,t){let n=[],r=[];if(typeof Intl<`u`&&Intl.Segmenter)try{let t=new Intl.Segmenter(`zh`,{granularity:`grapheme`});for(let n of t.segment(e))r.push(n.segment)}catch{for(let t of e)r.push(t)}else r=[...e];for(let e of r){let r=e.codePointAt(0)??0,i=`latin`;e===`
2
2
  `?i=`break`:e===` `||e===` `?i=`space`:ie(r)&&(i=ae(r)?`punct`:`cjk`),n.push({text:e,width:ne(e,t),type:i})}return n}function R(e,t,n){let r=0,i=Math.min(n,e.length);for(let n=t;n<i;n++)r+=e[n].width;return r}function z(e,t,n,r){return{text:e.slice(t,Math.min(n,e.length)).map(e=>e.text).join(``),width:r}}function B(e,t,n=`16px system-ui`){let{maxWidth:r,lineHeight:i,maxLines:a,overflowWrap:o=`break-word`}=t,s=L(e,n),c=[],l={lineStart:0,lineWidth:0,lastBreakIdx:-1,lastBreakWidth:0};for(let e=0;e<s.length;e++){let t=s[e];if(t.type===`break`){c.push(z(s,l.lineStart,e,l.lineWidth)),l.lineStart=e+1,l.lineWidth=0,l.lastBreakIdx=-1;continue}let n=l.lineWidth+t.width;if(t.type===`space`){if(n>r&&l.lineWidth>0?(l.lastBreakIdx>=0?(c.push(z(s,l.lineStart,l.lastBreakIdx+1,l.lastBreakWidth)),l.lineStart=l.lastBreakIdx+1,l.lineWidth=R(s,l.lineStart,e+1)):(c.push(z(s,l.lineStart,e,l.lineWidth)),l.lineStart=e,l.lineWidth=t.width),l.lastBreakIdx=-1):(l.lineWidth=n,l.lastBreakIdx=e,l.lastBreakWidth=l.lineWidth),a&&c.length>=a)break;continue}if(t.type===`cjk`){if(n>r&&l.lineWidth>0?(c.push(z(s,l.lineStart,e,l.lineWidth)),l.lineStart=e,l.lineWidth=t.width,l.lastBreakIdx=-1):(l.lineWidth=n,l.lastBreakIdx=e,l.lastBreakWidth=l.lineWidth),a&&c.length>=a)break;continue}if(t.type===`punct`){if(l.lineWidth===0&&c.length>0?c[c.length-1].text.length>0&&(l.lineWidth=t.width):n>r?(l.lastBreakIdx>=0?(c.push(z(s,l.lineStart,l.lastBreakIdx+1,l.lastBreakWidth)),l.lineStart=l.lastBreakIdx+1,l.lineWidth=R(s,l.lineStart,e+1)):l.lineWidth=n,l.lastBreakIdx=-1):l.lineWidth=n,a&&c.length>=a)break;continue}if(n>r&&l.lineWidth>0?l.lastBreakIdx>=0?(c.push(z(s,l.lineStart,l.lastBreakIdx+1,l.lastBreakWidth)),l.lineStart=l.lastBreakIdx+1,l.lineWidth=R(s,l.lineStart,e+1),l.lastBreakIdx=-1):o===`break-word`?(c.push(z(s,l.lineStart,e,l.lineWidth)),l.lineStart=e,l.lineWidth=t.width):l.lineWidth=n:l.lineWidth=n,a&&c.length>=a)break}let u=l.lineStart<s.length;if(u&&(!a||c.length<a)){let e=R(s,l.lineStart,s.length);c.push(z(s,l.lineStart,s.length,e))}return{lines:c,totalHeight:c.length*i,lineCount:c.length,truncated:u&&a?c.length>=a:!1}}var V=typeof window<`u`&&window.matchMedia(`(prefers-reduced-motion: reduce)`).matches,oe=`13.5px -apple-system, BlinkMacSystemFont, "SF Pro Text", "PingFang SC", "Microsoft YaHei", system-ui, sans-serif`;function H(){if(typeof window>`u`)return 290;let e=window.innerWidth;return e<=480?Math.max(140,e-98):290}var U={info:`<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="10"/><line x1="12" y1="16" x2="12" y2="12"/><line x1="12" y1="8" x2="12.01" y2="8"/></svg>`,success:`<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="10"/><path d="M9 12l2 2 4-4"/></svg>`,warning:`<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M10.29 3.86L1.82 18a2 2 0 0 0 1.71 3h16.94a2 2 0 0 0 1.71-3L13.71 3.86a2 2 0 0 0-3.42 0z"/><line x1="12" y1="9" x2="12" y2="13"/><line x1="12" y1="17" x2="12.01" y2="17"/></svg>`,error:`<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="10"/><line x1="15" y1="9" x2="9" y2="15"/><line x1="9" y1="9" x2="15" y2="15"/></svg>`},W=1;function se(){return`qt${W++}${Date.now().toString(36)}`}function G(e,t,n){let r=document.createElement(e);return t&&(r.className=t),n!=null&&(r.innerHTML=n),r}function ce(e,t){let n=t.split(/\*\*(.+?)\*\*/g);for(let t=0;t<n.length;t++){let r=n[t];if(r)if(t%2==1){let t=G(`em`,`qt-mark`);t.textContent=r,e.appendChild(t)}else e.appendChild(document.createTextNode(r))}}var le={type:`info`,position:`top-center`,duration:4e3,maxVisible:5,persist:!1,persistMaxVisible:3,maxLines:void 0,vibrate:!0},ue=[80,40,80];function de(){if(!(typeof navigator>`u`||!(`vibrate`in navigator)))try{navigator.vibrate(ue)}catch{}}var fe=class{containers=new Map;opts={...le};toasts=new Map;queue=[];_seq=0;constructor(e){e&&Object.assign(this.opts,e)}ensureContainer(e){let t=this.containers.get(e);return t||(t=G(`div`,`qt-container`),t.setAttribute(`data-qt-pos`,e),t.setAttribute(`role`,`status`),t.setAttribute(`aria-live`,`polite`),t.setAttribute(`aria-atomic`,`false`),document.body.appendChild(t),this.containers.set(e,t)),t}show(e,t){let n=t?.type??this.opts.type,r=t?.position??this.opts.position,i=t?.persist??this.opts.persist?0:t?.duration??this.opts.duration,a=t?.dismissible??!0,o=t?.maxLines??this.opts.maxLines,s=t?.description,c=t?.action,l=se(),u={id:l,type:n,dismissible:a,position:r,duration:i,order:++this._seq,element:this.buildElement(l,e,n,a,o,s,c),timer:null};return this.toasts.size>=this.opts.maxVisible?(this.queue.push(u),l):(this.mount(u),l)}info(e,t){return this.show(e,{...t,type:`info`})}success(e,t){return this.show(e,{...t,type:`success`})}warn(e,t){return this.show(e,{...t,type:`warning`})}error(e,t){return this.show(e,{...t,type:`error`})}promise(e,t,n){let r=this.show(t.loading,{...n,type:`info`,duration:0,dismissible:!1});return e.then(e=>{this.dismiss(r);let i=typeof t.success==`function`?t.success(e):t.success;requestAnimationFrame(()=>{this.success(i,{...n,persist:!1})})},e=>{this.dismiss(r);let i=typeof t.error==`function`?t.error(e):t.error;requestAnimationFrame(()=>{this.error(i,{...n,persist:!1})})}),r}dismiss(e){if(e){let t=this.toasts.get(e);t&&this._exit(t)}else this.dismissAll()}dismissAll(){for(let e of this.toasts.values())this._exit(e);this.queue.length=0}configure(e){Object.assign(this.opts,e)}destroy(){for(let e of this.toasts.values())e.timer&&clearTimeout(e.timer);this.toasts.clear(),this.queue.length=0;for(let e of this.containers.values())e.remove();this.containers.clear()}buildElement(e,t,n,r,i,a,o){let s=G(`div`,`qt-toast qt-${n}${i==null?``:` qt-truncate`}${a||o?` qt-rich`:``}`);s.setAttribute(`data-qt-id`,e);let c=G(`span`,`qt-icon`);c.innerHTML=U[n],s.appendChild(c);let l=G(`div`,`qt-body`),u=G(`span`,`qt-msg`),d=B(t,{maxWidth:H(),lineHeight:1,maxLines:i},oe);if(d.lineCount<=1?ce(u,t):d.lines.forEach((e,t)=>{let n=G(`span`,`qt-line`),r=e.text;t===d.lines.length-1&&d.truncated&&!r.endsWith(`…`)&&(r+=`…`),ce(n,r),u.appendChild(n)}),l.appendChild(u),a){let e=G(`div`,`qt-desc`);e.textContent=a,l.appendChild(e)}if(s.appendChild(l),o){let t=G(`button`,`qt-action`);t.type=`button`,t.textContent=o.label,t.addEventListener(`click`,t=>{t.stopPropagation(),this.dismiss(e),o.onClick()}),s.appendChild(t)}if(r){let t=G(`button`,`qt-close`,`<svg width="10" height="10" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round"><path d="M18 6 6 18M6 6l12 12"/></svg>`);t.type=`button`,t.setAttribute(`aria-label`,`关闭通知`),t.addEventListener(`click`,t=>{t.stopPropagation(),this.dismiss(e)}),s.appendChild(t)}return r&&s.addEventListener(`click`,t=>{t.target.closest(`.qt-close, .qt-action`)||this.dismiss(e)}),s}mount(e){e.duration===0&&this.evictPersistIfNeeded(e);let t=this.ensureContainer(e.position);this.toasts.set(e.id,e),t.appendChild(e.element),e.type===`error`&&this.opts.vibrate&&de(),requestAnimationFrame(()=>{requestAnimationFrame(()=>{e.element.classList.add(`qt-enter`)})}),e.duration>0&&(e.timer=setTimeout(()=>this.dismiss(e.id),e.duration))}evictPersistIfNeeded(e){let t=this.opts.persistMaxVisible;if(t<=0)return;let n=[...this.toasts.values()].filter(t=>t.position===e.position&&t.duration===0);for(;n.length>=t;){n.sort((e,t)=>e.order-t.order);let e=n.shift();if(!e)break;this._exit(e)}}_exit(e){e.timer&&=(clearTimeout(e.timer),null),e.element.classList.remove(`qt-enter`),e.element.classList.add(`qt-exit`);let t=()=>{e.element.remove(),this.toasts.delete(e.id),this._dequeue()};if(V)t();else{let n=!1,r=()=>{n||(n=!0,t())};e.element.addEventListener(`transitionend`,r,{once:!0}),setTimeout(r,400)}}_dequeue(){if(!this.queue.length||this.toasts.size>=this.opts.maxVisible)return;let e=this.queue.shift();this.mount(e)}},pe=null;function K(){return pe||=new fe,pe}var me=Object.assign((e,t)=>K().show(e,t),{info:(e,t)=>K().info(e,t),success:(e,t)=>K().success(e,t),warn:(e,t)=>K().warn(e,t),error:(e,t)=>K().error(e,t),promise:(e,t,n)=>K().promise(e,t,n),dismiss:e=>K().dismiss(e),dismissAll:()=>K().dismissAll(),configure:e=>K().configure(e)}),q=new Set,he=null;function ge(e){he=e}function J(e,t=`error`,n){let r={persist:!0,...n};if(q.size>0){for(let n of q)n(e,t,r);return}if(he){he(e,t,r);return}t===`success`?me.success(e,r):t===`info`?me.info(e,r):me.error(e,r)}function _e(e){return q.add(e),()=>{q.delete(e)}}var ve=e.c({ImageUploadDialog:()=>ye}),ye=({open:e,onClose:t,onInsert:r,validate:o})=>{let[s,c]=(0,i.useState)(`upload`),[l,u]=(0,i.useState)(!1),[d,f]=(0,i.useState)(!1),[p,m]=(0,i.useState)(null),[h,g]=(0,i.useState)(null),[_,v]=(0,i.useState)(``),[y,b]=(0,i.useState)(null),x=(0,i.useRef)(null),S=(()=>{try{let e=n.n();return{name:e.name,type:e.type}}catch{return{name:`未配置`,type:`none`}}})(),C=(0,i.useCallback)(()=>{u(!1),m(null),g(null),b(null),v(``),f(!1)},[]),w=(0,i.useCallback)(()=>{C(),t()},[C,t]),T=(0,i.useCallback)(async e=>{let t=e.name.split(`.`).pop()?.toLowerCase();if(!t||![`png`,`jpg`,`jpeg`,`gif`,`webp`,`svg`,`bmp`,`avif`].includes(t)){m(`不支持的图片格式: ${t||`未知`}`);return}let r=o?o(e):e.size>20*1024*1024?`图片大小不能超过 20MB`:null;if(r){m(r),J(r);return}f(!0),m(null);let i=URL.createObjectURL(e);g(i);try{let t=await n.n().upload(e,`editor`);URL.revokeObjectURL(i),b(t),g(t)}catch(e){m(e instanceof Error?e.message:`上传失败`),URL.revokeObjectURL(i),g(null)}finally{f(!1)}},[o]),E=(0,i.useCallback)(e=>{let t=e.target.files?.[0];t&&T(t)},[T]),D=(0,i.useCallback)(e=>{e.preventDefault(),u(!1);let t=e.dataTransfer.files[0];t&&T(t)},[T]),O=(0,i.useCallback)(e=>{let t=e.clipboardData.items;for(let n of Array.from(t))if(n.type.startsWith(`image/`)){e.preventDefault();let t=n.getAsFile();t&&T(t);return}},[T]),k=(0,i.useCallback)(()=>{_.trim()&&(r(_.trim()),w())},[_,r,w]),A=(0,i.useCallback)(()=>{y&&(r(y),w())},[y,r,w]);return e?(0,a.jsxs)(`div`,{className:`fixed inset-0 z-[9999] flex items-center justify-center`,children:[(0,a.jsx)(`div`,{className:`absolute inset-0 bg-black/40 backdrop-blur-sm`,onClick:w}),(0,a.jsxs)(`div`,{className:`relative w-[calc(100vw-32px)] max-w-[420px] max-h-[90vh] bg-background rounded-2xl shadow-2xl border border-default-200 overflow-hidden animate-in`,onPaste:s===`upload`?O:void 0,children:[(0,a.jsxs)(`div`,{className:`flex items-center justify-between px-5 py-4 border-b border-default-100`,children:[(0,a.jsx)(`h2`,{className:`text-base font-semibold`,children:`插入图片`}),(0,a.jsx)(`button`,{type:`button`,className:`w-7 h-7 flex items-center justify-center rounded-lg text-default-400 hover:text-default-600 hover:bg-default-100 transition-colors`,onClick:w,children:`✕`})]}),(0,a.jsx)(`div`,{className:`flex border-b border-default-100 px-5`,children:[`upload`,`url`].map(e=>(0,a.jsx)(`button`,{type:`button`,className:`px-4 py-2.5 text-sm font-medium transition-colors border-b-2 -mb-[1px] ${s===e?`border-primary text-primary`:`border-transparent text-default-400 hover:text-default-600`}`,onClick:()=>{c(e),m(null)},children:e===`upload`?`上传图片`:`图片链接`},e))}),(0,a.jsx)(`div`,{className:`p-5`,children:s===`upload`?(0,a.jsxs)(`div`,{className:`space-y-4`,children:[(0,a.jsxs)(`div`,{className:`flex items-center gap-2 px-3 py-2 rounded-lg bg-default-50 text-xs text-default-500`,children:[(0,a.jsx)(`span`,{className:`w-1.5 h-1.5 rounded-full bg-green-500`}),`存储服务:`,S.name]}),!h&&(0,a.jsxs)(`div`,{className:`relative flex flex-col items-center justify-center gap-3 py-10 px-4 rounded-xl border-2 border-dashed transition-all cursor-pointer ${l?`border-primary bg-primary/5 scale-[1.01]`:`border-default-200 hover:border-default-300 hover:bg-default-50`}`,onDragOver:e=>{e.preventDefault(),u(!0)},onDragLeave:()=>u(!1),onDrop:D,onClick:()=>x.current?.click(),children:[(0,a.jsx)(`div`,{className:`w-14 h-14 rounded-full bg-default-100 flex items-center justify-center`,children:(0,a.jsx)(`svg`,{className:`w-7 h-7 text-default-400`,fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,strokeWidth:1.5,children:(0,a.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M3 16.5v2.25A2.25 2.25 0 005.25 21h13.5A2.25 2.25 0 0021 18.75V16.5m-13.5-9L12 3m0 0l4.5 4.5M12 3v13.5`})})}),(0,a.jsxs)(`div`,{className:`text-center`,children:[(0,a.jsx)(`p`,{className:`text-sm font-medium text-default-700`,children:l?`松开放入`:`拖拽图片到此处`}),(0,a.jsx)(`p`,{className:`text-xs text-default-400 mt-1`,children:`或点击选择文件 · 支持粘贴图片`}),(0,a.jsx)(`p`,{className:`text-[10px] text-default-300 mt-1`,children:`PNG / JPG / GIF / WebP / AVIF · 最大 20MB`})]}),(0,a.jsx)(`input`,{ref:x,type:`file`,accept:`image/*`,className:`hidden`,onChange:E})]}),h&&(0,a.jsxs)(`div`,{className:`space-y-3`,children:[(0,a.jsxs)(`div`,{className:`relative rounded-xl overflow-hidden bg-default-100`,children:[(0,a.jsx)(`img`,{src:h,alt:`预览`,className:`w-full max-h-48 object-contain`}),d&&(0,a.jsx)(`div`,{className:`absolute inset-0 bg-black/40 flex items-center justify-center`,children:(0,a.jsxs)(`div`,{className:`flex flex-col items-center gap-2`,children:[(0,a.jsx)(`div`,{className:`w-8 h-8 border-2 border-white border-t-transparent rounded-full animate-spin`}),(0,a.jsx)(`span`,{className:`text-white text-xs`,children:`上传中…`})]})})]}),y&&!d&&(0,a.jsxs)(`div`,{className:`flex items-center gap-2 px-3 py-2 rounded-lg bg-green-50 text-xs text-green-700`,children:[(0,a.jsx)(`svg`,{className:`w-4 h-4 shrink-0`,fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,strokeWidth:2,children:(0,a.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M5 13l4 4L19 7`})}),`上传成功,已存储至 `,S.name]}),(0,a.jsxs)(`div`,{className:`flex gap-2`,children:[(0,a.jsx)(`button`,{type:`button`,className:`flex-1 py-2 rounded-xl bg-primary text-white text-sm font-medium disabled:opacity-40 transition-opacity`,disabled:!y||d,onClick:A,children:`插入图片`}),(0,a.jsx)(`button`,{type:`button`,className:`px-4 py-2 rounded-xl border border-default-200 text-sm hover:bg-default-50 transition-colors`,onClick:C,disabled:d,children:`重新选择`})]})]}),p&&(0,a.jsxs)(`div`,{className:`flex items-start gap-2 px-3 py-2.5 rounded-lg bg-danger-50 text-sm text-danger`,children:[(0,a.jsx)(`svg`,{className:`w-4 h-4 shrink-0 mt-0.5`,fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,strokeWidth:2,children:(0,a.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-2.5L13.732 4c-.77-.833-2.694-.833-3.464 0L3.34 16.5c-.77.833.192 2.5 1.732 2.5z`})}),(0,a.jsx)(`span`,{children:p})]})]}):(0,a.jsxs)(`div`,{className:`space-y-4`,children:[(0,a.jsxs)(`div`,{children:[(0,a.jsx)(`label`,{className:`block text-xs text-default-500 mb-1.5`,children:`图片链接地址`}),(0,a.jsx)(`input`,{type:`url`,className:`w-full px-3 py-2.5 rounded-xl border border-default-200 bg-background text-sm focus:outline-none focus:border-primary transition-colors`,placeholder:`https://example.com/image.png`,value:_,onChange:e=>v(e.target.value),onKeyDown:e=>{e.key===`Enter`&&k()}})]}),_&&(0,a.jsx)(`div`,{className:`rounded-xl overflow-hidden bg-default-100`,children:(0,a.jsx)(`img`,{src:_,alt:`预览`,className:`w-full max-h-40 object-contain`,onError:e=>{e.target.style.display=`none`}})}),(0,a.jsx)(`button`,{type:`button`,className:`w-full py-2.5 rounded-xl bg-primary text-white text-sm font-medium disabled:opacity-40 transition-opacity`,disabled:!_.trim(),onClick:k,children:`插入图片`})]})}),(0,a.jsxs)(`div`,{className:`px-5 py-3 border-t border-default-100 text-[11px] text-default-300 text-center`,children:[`图片将上传至 `,S.name]})]})]}):null};function be(e,t){return`${e.trim().toLowerCase().replace(/[^\p{L}\p{N}\s-]/gu,``).replace(/\s+/g,`-`).slice(0,40)||`heading`}-${t}`}function xe(e){let t=[],n=[];for(let r of e){let e={...r,children:[]};for(;n.length>0&&n[n.length-1].level>=e.level;)n.pop();n.length>0?n[n.length-1].children.push(e):t.push(e),n.push(e)}return t}function Se(e){let t=new Set,n=e=>{for(let r of e)r.children.length>0&&(t.add(r.id),n(r.children))};return n(e),t}function Y(e,t){let n=[];for(let r of e)n.push(r),r.children.length>0&&!t.has(r.id)&&n.push(...Y(r.children,t));return n}function Ce(e,t){let n=t.toLowerCase(),r=e=>{let t=[];for(let i of e){let e=i.text.toLowerCase().includes(n),a=r(i.children);(e||a.length>0)&&t.push({...i,children:e?i.children:a})}return t};return r(e)}function we(e){let t=e.parentElement;for(;t&&t!==document.documentElement;){let e=getComputedStyle(t).overflowY;if(e===`auto`||e===`scroll`||e===`overlay`)return t;t=t.parentElement}return null}function Te(e,t){if(!t)return e;let n=e.toLowerCase(),r=t.toLowerCase(),i=[],o=0,s=0;for(;;){let c=n.indexOf(r,o);if(c===-1)break;c>o&&i.push(e.slice(o,c)),i.push((0,a.jsx)(`mark`,{className:`toc-highlight`,children:e.slice(c,c+t.length)},`hl-${s++}`)),o=c+t.length}return o<e.length&&i.push(e.slice(o)),i.length?i:e}var Ee=({editor:e,className:t=``,onClose:n})=>{let[r,o]=(0,i.useState)([]),[s,c]=(0,i.useState)(``),[l,u]=(0,i.useState)(new Set),[d,f]=(0,i.useState)(``),p=(0,i.useRef)(null),m=(0,i.useRef)(new Map),h=(0,i.useRef)(``),g=(0,i.useCallback)(()=>{let t=e.view.dom,n=Array.from(t.querySelectorAll(`h1,h2,h3,h4,h5,h6`)),r=n.map((e,t)=>(e.id||=be(e.textContent||``,t),{id:e.id,level:Number(e.tagName.slice(1)),text:e.textContent?.trim()||`(无标题)`,el:e})),i=r.map(e=>`${e.level}:${e.text}`).join(`|`);if(i===h.current||(h.current=i,o(r),p.current?.disconnect(),m.current.clear(),!n.length))return;let a=new IntersectionObserver(e=>{for(let t of e){let e=t.target.id;t.isIntersecting?m.current.set(e,t.boundingClientRect.top):m.current.delete(e)}let t=``,n=1/0;m.current.forEach((e,r)=>{e<n&&e>=0&&(n=e,t=r)}),t&&c(t)},{root:we(e.view.dom),rootMargin:`0px 0px -72% 0px`,threshold:[0,1]});n.forEach(e=>a.observe(e)),p.current=a},[e]);(0,i.useEffect)(()=>{let t=null,n=()=>{let n=[];e.state.doc.descendants(e=>{e.type.name===`heading`&&n.push(`${e.attrs.level}:${e.textContent}`)}),n.join(`|`)!==h.current&&(t&&clearTimeout(t),t=setTimeout(g,300))};e.on(`update`,n);let r=requestAnimationFrame(g);return()=>{e.off(`update`,n),t&&clearTimeout(t),cancelAnimationFrame(r),p.current?.disconnect()}},[e,g]);let _=(0,i.useCallback)(t=>{let n=t.el;if((!n||!e.view.dom.contains(n))&&(n=e.view.dom.querySelector(`[id="${CSS.escape(t.id)}"]`)),!n){let r=`h${t.level}`,i=e.view.dom.querySelectorAll(r);for(let e of i)if(e.textContent?.trim()===t.text){n=e;break}}n&&(n.scrollIntoView({behavior:`smooth`,block:`start`}),c(t.id))},[e]),v=(0,i.useMemo)(()=>xe(r),[r]),y=(0,i.useMemo)(()=>Se(v),[v]),b=d.trim().length>0,x=(0,i.useMemo)(()=>b?Ce(v,d.trim()):v,[v,b,d]),S=(0,i.useMemo)(()=>Y(x,b?new Set:l),[x,l,b]),C=(0,i.useCallback)(e=>{u(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},[]),w=(0,i.useCallback)(()=>{u(new Set(y))},[y]),T=(0,i.useCallback)(()=>{u(new Set)},[]);return r.length?(0,a.jsxs)(`nav`,{className:`toc-panel ${t}`,"aria-label":`目录`,children:[(0,a.jsxs)(`div`,{className:`toc-title`,children:[n?(0,a.jsx)(`button`,{type:`button`,className:`toc-close-btn`,onClick:n,title:`收起目录`,"aria-label":`收起目录`,children:(0,a.jsxs)(`svg`,{width:`15`,height:`15`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,"aria-hidden":`true`,children:[(0,a.jsx)(`rect`,{x:`3`,y:`3`,width:`18`,height:`18`,rx:`2`}),(0,a.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M9 3v18`}),(0,a.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`m16 15-3-3 3-3`})]})}):(0,a.jsx)(`span`,{className:`toc-title__icon`,"aria-hidden":`true`,children:(0,a.jsx)(`svg`,{width:`14`,height:`14`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,children:(0,a.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M4 6h16M4 12h10M4 18h7`})})}),(0,a.jsx)(`span`,{className:`toc-title__text`,children:`目录`}),(0,a.jsxs)(`div`,{className:`toc-actions`,children:[(0,a.jsx)(`button`,{type:`button`,className:`toc-action-btn`,onClick:w,title:`全部折叠`,"aria-label":`全部折叠`,disabled:b,children:(0,a.jsx)(`svg`,{width:`14`,height:`14`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,"aria-hidden":`true`,children:(0,a.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M5 12h14`})})}),(0,a.jsx)(`button`,{type:`button`,className:`toc-action-btn`,onClick:T,title:`全部展开`,"aria-label":`全部展开`,disabled:b,children:(0,a.jsx)(`svg`,{width:`14`,height:`14`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,"aria-hidden":`true`,children:(0,a.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M12 5v14M5 12h14`})})})]})]}),(0,a.jsxs)(`div`,{className:`toc-search`,children:[(0,a.jsx)(`svg`,{className:`toc-search__icon`,width:`13`,height:`13`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,"aria-hidden":`true`,children:(0,a.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M21 21l-4.35-4.35M17 11a6 6 0 11-12 0 6 6 0 0112 0z`})}),(0,a.jsx)(`input`,{type:`text`,className:`toc-search__input`,placeholder:`搜索标题...`,value:d,onChange:e=>f(e.target.value),"aria-label":`搜索标题`}),d&&(0,a.jsx)(`button`,{type:`button`,className:`toc-search__clear`,onClick:()=>f(``),title:`清除`,"aria-label":`清除搜索`,children:(0,a.jsx)(`svg`,{width:`12`,height:`12`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,"aria-hidden":`true`,children:(0,a.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M6 18L18 6M6 6l12 12`})})})]}),S.length===0?(0,a.jsx)(`div`,{className:`toc-search__empty`,children:b?`未找到"${d.trim()}"相关标题`:`文档暂无标题`}):(0,a.jsx)(`ul`,{className:`toc-list`,children:S.map(e=>{let t=y.has(e.id),n=l.has(e.id);return(0,a.jsxs)(`li`,{className:`toc-item ${s===e.id?`is-active`:``}`,style:{paddingLeft:`${(e.level-1)*12+12}px`},children:[t?(0,a.jsx)(`button`,{type:`button`,className:`toc-toggle ${n?`is-collapsed`:`is-expanded`}`,onClick:t=>{t.stopPropagation(),C(e.id)},title:n?`展开子标题`:`折叠子标题`,"aria-label":n?`展开子标题`:`折叠子标题`,"aria-expanded":!n,children:(0,a.jsx)(`svg`,{width:`10`,height:`10`,viewBox:`0 0 24 24`,fill:`currentColor`,"aria-hidden":`true`,children:(0,a.jsx)(`path`,{d:`M8 5v14l11-7z`})})}):(0,a.jsx)(`span`,{className:`toc-bullet`,"aria-hidden":!0}),(0,a.jsx)(`button`,{type:`button`,className:`toc-link`,onClick:()=>_(e),title:e.text,children:(0,a.jsx)(`span`,{className:`toc-text`,children:b?Te(e.text,d.trim()):e.text})})]},e.id)})})]}):(0,a.jsxs)(`div`,{className:`toc-panel ${t}`,style:{padding:`24px 16px`,textAlign:`center`},children:[(0,a.jsx)(`div`,{className:`toc-empty`,children:`文档暂无标题`}),(0,a.jsx)(`div`,{className:`toc-empty-hint`,children:`使用 # 标记可创建标题`})]})};function De(e,t){return{continue:`你是一个写作助手。请从下文尾部自然流畅地续写内容,保持风格一致。只输出续写的内容,不要加任何前缀说明。`,improve:`你是一个文字润色专家。请优化以下文本的表达,提升文采和流畅度,保持原意不变。只输出润色后的文本。`,shorter:`你是一个精简专家。请将以下文本精简,保留核心信息,删除冗余。只输出精简后的文本。`,longer:`你是一个内容扩写专家。请丰富以下文本的细节和层次,增加深度。只输出扩写后的文本。`,fix:`你是一个校对专家。请修正以下文本中的语法错误、错别字和标点问题。只输出修正后的文本。`,translate:`你是一个翻译专家。请将以下文本翻译为英文。只输出翻译后的文本。`,zap:t||`你是一个全能的 AI 写作助手。请根据用户的指令处理文本。`}[e]}var Oe=null;async function X(e){let t;try{({createOpenAI:t}=await import(`@ai-sdk/openai`))}catch{throw Error(`缺少可选依赖 @ai-sdk/openai。使用默认 provider 请先安装:npm i @ai-sdk/openai;或调用 setAIProvider() 注册自定义 provider。`)}let n=t({apiKey:e.apiKey,baseURL:e.baseURL}).chat(e.model);return{async*stream(e){let t=await(0,o.streamText)({model:n,system:De(e.mode,e.instruction),prompt:e.context,temperature:.7,maxOutputTokens:2048});for await(let e of t.textStream)yield e},async generate(e){return(await(0,o.generateText)({model:n,system:De(e.mode,e.instruction),prompt:e.context,temperature:.7,maxOutputTokens:2048})).text}}}function ke(e){Oe=e}function Ae(){if(!Oe)throw Error(`未配置 AI 服务。请调用 createAILanguageModelProvider() 创建并通过 setAIProvider() 注册。`);return Oe}function je(e){let{apiKey:t,baseURL:n,model:r,headers:i}=e;async function*a(e,a){let o=await fetch(`${n}/chat/completions`,{method:`POST`,headers:{"Content-Type":`application/json`,Authorization:`Bearer ${t}`,...i},body:JSON.stringify({model:r,messages:[{role:`system`,content:e},{role:`user`,content:a}],stream:!0,temperature:.7,max_tokens:2048})});if(!o.ok){let e=await o.text();throw Error(`AI API 错误 (${o.status}): ${e}`)}let s=o.body?.getReader();if(!s)throw Error(`无法读取响应流`);let c=new TextDecoder,l=``;for(;;){let{done:e,value:t}=await s.read();if(e)break;l+=c.decode(t,{stream:!0});let n=l.split(`
3
- `);l=n.pop()||``;for(let e of n){let t=e.trim();if(!t||!t.startsWith(`data: `))continue;let n=t.slice(6);if(n===`[DONE]`)return;try{let e=JSON.parse(n).choices?.[0]?.delta?.content;e&&(yield e)}catch{}}}}return{async*stream(e){yield*a(De(e.mode,e.instruction),e.context)},async generate(e){let t=De(e.mode,e.instruction),n=``;for await(let r of a(t,e.context))n+=r;return n}}}function Me(e){return je({apiKey:e.apiKey,baseURL:e.baseURL||`https://api.deepseek.com/v1`,model:e.model||`deepseek-v4-flash`,headers:e.headers})}function Ne(e){return je({apiKey:e.apiKey,baseURL:e.baseURL||`https://api.openai.com/v1`,model:e.model||`gpt-5.6-luna`,headers:e.headers})}function Pe(e){return je({apiKey:e.apiKey,baseURL:e.baseURL||`https://dashscope.aliyuncs.com/compatible-mode/v1`,model:e.model||`qwen3.7-plus`,headers:e.headers})}var Fe={keyword:``,caseSensitive:!1,wholeWord:!1,matches:[],currentIndex:-1},Z=new f.PluginKey(`search-highlight`);function Ie(e){return e.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`)}function Le(e,t){let{keyword:n,caseSensitive:r,wholeWord:i}=t;if(!n)return[];let a=r?`g`:`gi`,o=i?`\\b${Ie(n)}\\b`:Ie(n),s=new RegExp(o,a),c=[];return e.descendants((e,t)=>{if(!e.isText||!e.text)return;s.lastIndex=0;let n;for(;(n=s.exec(e.text))!==null;){let e=t+n.index,r=e+n[0].length;c.push({from:e,to:r}),n[0].length===0&&s.lastIndex++}}),c}function Re(e,t){if(t.matches.length===0)return p.DecorationSet.empty;let n=t.matches.map((e,n)=>p.Decoration.inline(e.from,e.to,{class:n===t.currentIndex?`search-highlight search-highlight--active`:`search-highlight`}));return p.DecorationSet.create(e,n)}function ze(e,t){if(t.currentIndex<0||t.currentIndex>=t.matches.length)return;let n=t.matches[t.currentIndex];n&&requestAnimationFrame(()=>{try{let t=e.dom.querySelector(`.search-highlight--active`);if(t){let e=t.getBoundingClientRect(),n=window.innerHeight-80;(e.top<120||e.bottom>n)&&t.scrollIntoView({behavior:`smooth`,block:`center`});return}let r=e.coordsAtPos(n.from),i=window.innerHeight-80;if(r.top<120||r.top>i){let e=r.top-window.innerHeight/2;window.scrollBy({top:e,behavior:`smooth`})}}catch{}})}var Be=d.Extension.create({name:`searchHighlight`,addProseMirrorPlugins(){return[new f.Plugin({key:Z,state:{init:()=>Fe,apply(e,t){let n=e.getMeta(Z);if(n)return{...t,...n,matches:n.matches===void 0?t.matches:n.matches,currentIndex:n.currentIndex===void 0?t.currentIndex:n.currentIndex};if(e.docChanged&&t.keyword){let n=Le(e.doc,t),r=t.currentIndex;return r>=n.length&&(r=n.length-1),r<0&&(r=n.length>0?0:-1),{...t,matches:n,currentIndex:r}}return t}},props:{decorations(e){let t=Z.getState(e);return t?Re(e.doc,t):p.DecorationSet.empty}}})]},addCommands(){return{setSearch:(e,t={})=>({state:n,dispatch:r,view:i})=>{let a=Z.getState(n)||Fe,o={keyword:e,caseSensitive:t.caseSensitive??a.caseSensitive,wholeWord:t.wholeWord??a.wholeWord,matches:[],currentIndex:-1};return o.matches=Le(n.doc,o),o.currentIndex=o.matches.length>0?0:-1,r&&(r(n.tr.setMeta(Z,o)),i&&ze(i,o)),!0},nextMatch:()=>({state:e,dispatch:t,view:n})=>{let r=Z.getState(e)||Fe;if(r.matches.length===0)return!1;let i=(r.currentIndex+1)%r.matches.length;return t&&(t(e.tr.setMeta(Z,{currentIndex:i})),n&&ze(n,{...r,currentIndex:i})),!0},prevMatch:()=>({state:e,dispatch:t,view:n})=>{let r=Z.getState(e)||Fe;if(r.matches.length===0)return!1;let i=(r.currentIndex-1+r.matches.length)%r.matches.length;return t&&(t(e.tr.setMeta(Z,{currentIndex:i})),n&&ze(n,{...r,currentIndex:i})),!0},clearSearch:()=>({state:e,dispatch:t})=>(t&&t(e.tr.setMeta(Z,Fe)),!0)}}});function Ve(e){let t=e.state;return Z.getState(t)||Fe}var He=({editor:e,onClose:t})=>{let[n,r]=(0,i.useState)(``),[o,s]=(0,i.useState)(!1),[c,l]=(0,i.useState)(!1),[u,d]=(0,i.useState)(0),f=(0,i.useRef)(null),p=(0,i.useRef)({keyword:n,caseSensitive:o,wholeWord:c});p.current={keyword:n,caseSensitive:o,wholeWord:c},(0,i.useEffect)(()=>{if(!e)return;let t=0,n=()=>{t&&cancelAnimationFrame(t),t=requestAnimationFrame(()=>{t=0,d(e=>(e+1)%1e6)})};return e.on(`update`,n),()=>{e.off(`update`,n),t&&cancelAnimationFrame(t)}},[e]),(0,i.useEffect)(()=>{let e=setTimeout(()=>f.current?.focus(),30);return()=>clearTimeout(e)},[]),(0,i.useEffect)(()=>{if(!e)return;let t=requestAnimationFrame(()=>{let{keyword:t,caseSensitive:n,wholeWord:r}=p.current;try{e.commands.setSearch(t,{caseSensitive:n,wholeWord:r})}catch(e){console.warn(`[SearchBar] setSearch failed:`,e)}});return()=>cancelAnimationFrame(t)},[e,n,o,c]),(0,i.useEffect)(()=>()=>{try{e?.commands.clearSearch()}catch{}},[]),(0,i.useEffect)(()=>{let e=e=>{e.key===`Escape`&&(e.preventDefault(),e.stopPropagation(),t())};return window.addEventListener(`keydown`,e,!0),()=>window.removeEventListener(`keydown`,e,!0)},[t]);let m=(0,i.useCallback)(()=>{try{e?.commands.nextMatch()}catch{}},[e]),h=(0,i.useCallback)(()=>{try{e?.commands.prevMatch()}catch{}},[e]),g=(0,i.useCallback)(e=>{e.stopPropagation(),e.key===`Enter`&&(e.preventDefault(),e.shiftKey?h():m())},[m,h]),_=(0,i.useMemo)(()=>{if(!e)return null;try{return Ve(e)}catch{return null}},[e,n,o,c,u]),v=n?_&&_.matches.length>0?`${_.currentIndex+1} / ${_.matches.length}`:`无匹配`:``,y=(0,i.useCallback)(e=>{e.stopPropagation()},[]);return(0,a.jsx)(`div`,{className:`search-bar`,role:`search`,"aria-label":`文档内搜索`,onClick:y,onMouseDown:y,children:(0,a.jsxs)(`div`,{className:`search-bar__main`,children:[(0,a.jsx)(`svg`,{className:`search-bar__icon`,width:`14`,height:`14`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,children:(0,a.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M21 21l-6-6m2-5a7 7 0 11-14 0 7 7 0 0114 0z`})}),(0,a.jsx)(`input`,{ref:f,type:`text`,className:`search-bar__input`,placeholder:`查找…`,value:n,onChange:e=>r(e.target.value),onKeyDown:g,onKeyUp:y,onKeyPress:y,onInput:y,spellCheck:!1,autoComplete:`off`,inputMode:`text`}),(0,a.jsx)(`span`,{className:`search-bar__count`,children:v}),(0,a.jsx)(`button`,{type:`button`,className:`search-bar__toggle${o?` search-bar__toggle--active`:``}`,onClick:()=>s(e=>!e),title:`区分大小写 (Aa)`,"aria-pressed":o,children:`Aa`}),(0,a.jsx)(`button`,{type:`button`,className:`search-bar__toggle${c?` search-bar__toggle--active`:``}`,onClick:()=>l(e=>!e),title:`整词匹配 (\\b)`,"aria-pressed":c,children:`\\b`}),(0,a.jsx)(`div`,{className:`search-bar__sep`}),(0,a.jsx)(`button`,{type:`button`,className:`search-bar__btn`,onClick:h,title:`上一个 (Shift+Enter)`,disabled:!_||_.matches.length===0,children:(0,a.jsx)(`svg`,{width:`14`,height:`14`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,children:(0,a.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M5 15l7-7 7 7`})})}),(0,a.jsx)(`button`,{type:`button`,className:`search-bar__btn`,onClick:m,title:`下一个 (Enter)`,disabled:!_||_.matches.length===0,children:(0,a.jsx)(`svg`,{width:`14`,height:`14`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,children:(0,a.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M19 9l-7 7-7-7`})})}),(0,a.jsx)(`button`,{type:`button`,className:`search-bar__btn search-bar__btn--close`,onClick:t,title:`关闭 (Esc)`,children:(0,a.jsx)(`svg`,{width:`14`,height:`14`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,children:(0,a.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M6 18L18 6M6 6l12 12`})})})]})})};function Q({children:e,...t}){return(0,a.jsx)(`svg`,{width:16,height:16,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:2,strokeLinecap:`round`,strokeLinejoin:`round`,"aria-hidden":`true`,...t,children:e})}var Ue=e=>(0,a.jsxs)(Q,{...e,children:[(0,a.jsx)(`path`,{d:`M6 4h8a4 4 0 0 1 0 8H6z`}),(0,a.jsx)(`path`,{d:`M6 12h9a4 4 0 0 1 0 8H6z`})]}),We=e=>(0,a.jsxs)(Q,{...e,children:[(0,a.jsx)(`path`,{d:`M19 4h-9`}),(0,a.jsx)(`path`,{d:`M14 20H5`}),(0,a.jsx)(`path`,{d:`M15 4 9 20`})]}),Ge=e=>(0,a.jsxs)(Q,{...e,children:[(0,a.jsx)(`path`,{d:`M6 4v6a6 6 0 0 0 12 0V4`}),(0,a.jsx)(`path`,{d:`M4 20h16`})]}),Ke=e=>(0,a.jsxs)(Q,{...e,children:[(0,a.jsx)(`path`,{d:`M16 4H9a3 3 0 0 0-2.83 4`}),(0,a.jsx)(`path`,{d:`M14 12a4 4 0 0 1 0 8H6`}),(0,a.jsx)(`path`,{d:`M4 12h16`})]}),qe=e=>(0,a.jsxs)(Q,{...e,children:[(0,a.jsx)(`path`,{d:`m16 18 6-6-6-6`}),(0,a.jsx)(`path`,{d:`m8 6-6 6 6 6`})]}),Je=e=>(0,a.jsxs)(Q,{...e,children:[(0,a.jsx)(`path`,{d:`m9 11-6 6v3h9l3-3`}),(0,a.jsx)(`path`,{d:`m22 12-4.6 4.6a2 2 0 0 1-2.8 0l-5.2-5.2a2 2 0 0 1 0-2.8L14 4`})]}),Ye=e=>(0,a.jsxs)(Q,{...e,children:[(0,a.jsx)(`path`,{d:`M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71`}),(0,a.jsx)(`path`,{d:`M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71`})]}),Xe=e=>(0,a.jsxs)(Q,{...e,children:[(0,a.jsx)(`rect`,{x:`3`,y:`3`,width:`18`,height:`18`,rx:`2`,ry:`2`}),(0,a.jsx)(`path`,{d:`M3 9h18M3 15h18M9 3v18M15 3v18`})]}),Ze=e=>(0,a.jsxs)(Q,{...e,children:[(0,a.jsx)(`rect`,{x:`8`,y:`8`,width:`14`,height:`14`,rx:`2`,ry:`2`}),(0,a.jsx)(`path`,{d:`M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2`})]}),Qe=e=>(0,a.jsxs)(Q,{...e,children:[(0,a.jsx)(`circle`,{cx:`11`,cy:`11`,r:`8`}),(0,a.jsx)(`path`,{d:`m21 21-4.3-4.3`})]}),$e=e=>(0,a.jsxs)(Q,{...e,children:[(0,a.jsx)(`path`,{d:`M12 3l1.6 4.4L18 9l-4.4 1.6L12 15l-1.6-4.4L6 9l4.4-1.6L12 3z`}),(0,a.jsx)(`path`,{d:`M18.5 14l.7 1.9 1.9.7-1.9.7-.7 1.9-.7-1.9-1.9-.7 1.9-.7.7-1.9z`})]}),et=e=>(0,a.jsxs)(Q,{...e,children:[(0,a.jsx)(`circle`,{cx:`5`,cy:`12`,r:`1`}),(0,a.jsx)(`circle`,{cx:`12`,cy:`12`,r:`1`}),(0,a.jsx)(`circle`,{cx:`19`,cy:`12`,r:`1`})]}),tt=e=>(0,a.jsxs)(Q,{...e,children:[(0,a.jsx)(`path`,{d:`M18 6 6 18`}),(0,a.jsx)(`path`,{d:`m6 6 12 12`})]});async function nt(e){if(e){if(e.startsWith(`blob:`)){URL.revokeObjectURL(e);return}try{await n.n().remove(e)}catch(e){console.warn(`删除存储资源失败:`,e)}}}var rt=3e4,it=new Set([`image`,`attachmentEmbed`,`audioEmbed`,`videoEmbed`]),at=new WeakMap;function ot(e){let t=new Set;return e.state.doc.descendants(e=>{if(it.has(e.type.name)){let n=e.attrs.src;n&&t.add(n)}return!0}),t}function st(e){let t=at.get(e);return t||(t={timers:new Map,onTransaction:()=>{},listening:!1},at.set(e,t)),t}function ct(e,t){let n=[...new Set(t.filter(Boolean))];if(n.length===0)return;let r=st(e);r.listening||=(r.onTransaction=()=>{if(r.timers.size===0)return;let t=ot(e);for(let[e,n]of r.timers)t.has(e)&&(clearTimeout(n),r.timers.delete(e))},e.on(`transaction`,r.onTransaction),!0);for(let t of n){if(r.timers.has(t))continue;let n=setTimeout(()=>{ot(e).has(t)||nt(t),r.timers.delete(t)},rt);r.timers.set(t,n)}}function lt(e){let t=at.get(e);if(t){if(t.listening&&=(e.off(`transaction`,t.onTransaction),!1),t.timers.size>0){let n=ot(e);for(let[e,r]of t.timers)clearTimeout(r),n.has(e)||nt(e);t.timers.clear()}at.delete(e)}}var ut=[{mode:`continue`,labelKey:`editor.ai.continue`,descKey:`editor.ai.continueDesc`,icon:`→`},{mode:`improve`,labelKey:`editor.ai.improve`,descKey:`editor.ai.improveDesc`,icon:`✨`},{mode:`shorter`,labelKey:`editor.ai.shorter`,descKey:`editor.ai.shorterDesc`,icon:`↓`},{mode:`longer`,labelKey:`editor.ai.longer`,descKey:`editor.ai.longerDesc`,icon:`↑`},{mode:`fix`,labelKey:`editor.ai.fix`,descKey:`editor.ai.fixDesc`,icon:`✓`},{mode:`translate`,labelKey:`editor.ai.translate`,descKey:`editor.ai.translateDesc`,icon:`🌐`},{mode:`zap`,labelKey:`editor.ai.zap`,descKey:`editor.ai.zapDesc`,icon:`⚡`}],dt=new Set([`image`,`attachmentEmbed`,`audioEmbed`,`videoEmbed`]),ft={image:`editor.ai.nodeImage`,attachmentEmbed:`editor.ai.nodeAttachment`,videoEmbed:`editor.ai.nodeVideo`,audioEmbed:`editor.ai.nodeAudio`};function pt(e,t){return e.storage.qingwuUI?.parseMd?.(e.schema,t)||null}function mt(e,t,n){let r=[];return e.state.doc.nodesBetween(t,n,e=>{if(dt.has(e.type.name)){let t=e.attrs.src;t&&r.push({type:e.type.name,src:t})}return!0}),r}function ht(e){let t=new Set;return e.state.doc.descendants(e=>{if(dt.has(e.type.name)){let n=e.attrs.src;n&&t.add(n)}return!0}),t}function gt(e,t){let n=pt(e,t);if(n&&n.size>0){let t=e.state.tr;t.replaceWith(0,e.state.doc.content.size,n),t.setSelection(f.TextSelection.create(t.doc,t.doc.content.size)),e.view.dispatch(t.scrollIntoView()),e.commands.focus();return}e.commands.setContent(t),e.commands.focus()}function _t(e,t,n,r){let i=pt(e,t);if(e.commands.focus(),!i){let i=e.chain().focus();n===`replace`?i.setTextSelection({from:r.from,to:r.to}).deleteSelection().insertContent(t).run():i.insertContentAt(r.to,t).run();return}let a=e.state.tr;n===`replace`?a.replaceRange(r.from,r.to,new s.Slice(i,0,0)):a.insert(Math.min(r.to,e.state.doc.content.size),i),e.view.dispatch(a.scrollIntoView())}function vt({editor:t,onClose:n}){let[r,o]=(0,i.useState)(null),[s,c]=(0,i.useState)(``),[l,u]=(0,i.useState)(``),[d,f]=(0,i.useState)(!1),[p,m]=(0,i.useState)(null),[h,g]=(0,i.useState)(null),_=(0,i.useRef)({from:0,to:0,empty:!0}),v=(0,i.useRef)(null),y=(0,i.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=Ae(),i=r.empty?t.state.doc.textContent:t.state.doc.textBetween(r.from,r.to),a=[];for await(let t of e.stream({mode:n,context:i,instruction:n===`zap`?s:void 0}))a.push(t),u(a.join(``))}catch(t){m(t instanceof Error?t.message:e.o(`editor.ai.error`))}finally{f(!1)}},[t,s]);(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(mt(t,r.from,r.to).map(e=>e.src));e===`replaceAll`?gt(t,n):_t(t,n,`replace`,_.current);let a=ht(t);ct(t,[...i].filter(e=>!a.has(e)))},[t]),w=(0,i.useCallback)(e=>{if(e===`below`){_t(t,l,`below`,_.current),n();return}let r=_.current,i=e===`replaceAll`?{from:0,to:t.state.doc.content.size}:{from:r.from,to:r.to},a=mt(t,i.from,i.to);if(a.length>0){g({position:e,willRemove:a});return}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)($e,{className:`text-primary`}),e.o(`editor.ai.trigger`)]}),(0,a.jsx)(`button`,{type:`button`,onClick:n,"aria-label":e.o(`editor.ai.close`),title:e.o(`editor.ai.close`),className:`flex items-center justify-center w-6 h-6 rounded-md text-default-400 hover:bg-default-100 hover:text-default-700 transition-colors`,children:(0,a.jsx)(tt,{})})]}),(0,a.jsx)(`div`,{className:`grid grid-cols-[repeat(auto-fit,minmax(64px,1fr))] gap-1.5 p-2 shrink-0`,children:ut.map(({mode:t,labelKey:n,descKey:i,icon:o})=>(0,a.jsxs)(`button`,{type:`button`,className:`flex flex-col items-center gap-1 px-1 py-2 rounded-xl border transition-colors ${r===t?`border-primary/40 bg-primary/10 text-primary`:`border-default-200 text-default-600 hover:bg-default-100 hover:text-default-900`}`,onClick:()=>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(ft[t]??t),` ×`,n]},t))})]})]}),(0,a.jsxs)(`div`,{className:`qed-footer`,style:{display:`flex`,justifyContent:`flex-end`,gap:8},children:[(0,a.jsx)(`button`,{type:`button`,className:`qed-btn qed-btn--ghost`,onClick:()=>g(null),children:e.o(`editor.ai.cancel`)}),(0,a.jsx)(`button`,{type:`button`,className:`qed-btn qed-btn--primary`,onClick:T,children:e.o(`editor.ai.confirmReplace`)})]})]})]})]})}var yt=new Set([`attachmentEmbed`,`videoEmbed`,`audioEmbed`,`image`]);function bt(e){let t=0;return e.descendants(e=>{yt.has(e.type.name)&&(t+=Number(e.attrs?.size)||0)}),t}function xt(e){if(!Number.isFinite(e)||e<=0)return`0 B`;let t=[`B`,`KB`,`MB`,`GB`,`TB`],n=Math.min(t.length-1,Math.floor(Math.log(e)/Math.log(1024))),r=e/1024**n;return`${n===0||r>=100?`${Math.round(r)}`:`${Math.round(r*10)/10}`} ${t[n]}`}function St(e){return(e?.storage)?.qingwuUI?.limits}function Ct(e,t,n){let{maxAttachmentSize:r,maxTotalAttachmentSize:i}=n;if(r&&t.size>r)return`单文件大小不能超过 ${xt(r)}(当前 ${xt(t.size)})`;if(i){let n=bt(e)+t.size;if(n>i)return`附件总大小不能超过 ${xt(i)}(当前合计 ${xt(n)})`}return null}var wt=!1,Tt=null,Et=5e3;function Dt(){return wt}function $(e){wt=e,Tt&&=(clearTimeout(Tt),null),e&&(Tt=setTimeout(()=>{wt=!1,Tt=null},Et))}var Ot=null;function kt(e){Ot=e}function At(){return Ot}var jt=300;function Mt({open:e,title:t,message:n,confirmText:r=`删除`,cancelText:o=`取消`,onConfirm:s,onCancel:c}){let[l,d]=(0,i.useState)(!1),f=(0,i.useRef)(!1),p=At();return(0,i.useEffect)(()=>{if(!e){f.current=!1;return}!p||f.current||(f.current=!0,p({open:e,title:t,message:n,confirmText:r,cancelText:o,onConfirm:s,onCancel:c}))},[e,p,t,n,r,o,s,c]),(0,i.useEffect)(()=>{e||d(!1)},[e]),p||!e?null:(0,u.createPortal)((0,a.jsx)(`div`,{className:`fixed inset-0 z-[10001] flex items-center justify-center bg-black/40 backdrop-blur-sm select-none`,onClick:()=>{l||c()},onMouseDown:e=>e.preventDefault(),children:(0,a.jsxs)(`div`,{className:`bg-white dark:bg-zinc-800 rounded-xl p-6 shadow-xl max-w-sm w-full mx-4 border border-default-200 relative overflow-hidden`,onClick:e=>e.stopPropagation(),children:[l&&(0,a.jsxs)(`div`,{className:`delete-progress`,children:[(0,a.jsx)(`div`,{className:`delete-progress-spinner`}),(0,a.jsx)(`div`,{className:`delete-progress-text`,children:`删除中…`})]}),(0,a.jsx)(`div`,{className:`text-sm font-medium text-default-800 dark:text-zinc-100 mb-2`,children:t}),n&&(0,a.jsx)(`div`,{className:`text-xs text-default-500 dark:text-zinc-400 mb-4 whitespace-pre-line`,children:n}),(0,a.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,a.jsx)(`button`,{type:`button`,className:`px-3 py-1.5 text-xs rounded-lg border border-default-200 hover:bg-default-100 transition-colors`,onClick:c,disabled:l,children:o}),(0,a.jsx)(`button`,{type:`button`,className:`px-3 py-1.5 text-xs rounded-lg bg-red-500 hover:bg-red-600 text-white transition-colors disabled:opacity-60`,onClick:async()=>{if(l)return;d(!0);let e=Date.now();try{await s()}finally{let t=Date.now()-e;t<jt&&await new Promise(e=>setTimeout(e,jt-t)),d(!1),c()}},disabled:l,children:r})]})]})}),document.body)}function Nt(e){return/^(\.\.?\/|[a-zA-Z]:\\|file:\/\/)/.test(e)?!0:!(/^[a-z]+:\/\//i.test(e)||e.startsWith(`/`)||e.startsWith(`data:`)||e.startsWith(`blob:`))}function Pt({node:e,deleteNode:n,editor:r}){let[o,s]=(0,i.useState)(!1),[l,u]=(0,i.useState)(!1),[d,f]=(0,i.useState)(!1),p=(0,i.useRef)(!1),[m,h]=(0,i.useState)(!1),g=e.attrs.src||``,_=e.attrs.alt||``,v=e.attrs.width||null,y=e.attrs.height||null,b=(0,i.useRef)(null),x=(0,i.useRef)(null),S=(0,i.useRef)(null),C=(0,i.useRef)(null),w=(0,i.useRef)(null),T=(0,i.useRef)(!1),E=(0,i.useRef)(!1),D=(0,i.useRef)(0),[O,k]=(0,i.useState)(g),A=r?.isEditable??!0,j=(0,i.useCallback)(()=>{l||(D.current=window.scrollY,s(!0))},[l]),ee=(0,i.useCallback)(()=>{s(!1),requestAnimationFrame(()=>window.scrollTo(0,D.current))},[]),M=(0,i.useCallback)(()=>{let e=b.current;e&&(D.current=window.scrollY,e.requestFullscreen?e.requestFullscreen():e.webkitRequestFullscreen&&e.webkitRequestFullscreen())},[]),N=(0,i.useCallback)(()=>{let e=x.current;e&&(D.current=window.scrollY,e.requestFullscreen?e.requestFullscreen():e.webkitRequestFullscreen&&e.webkitRequestFullscreen())},[]);(0,i.useEffect)(()=>{u(!1),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-D8Rk6R5t.cjs")).then(e=>e.i),n=await t(g);if(!n)return;let r=await fetch(g,{headers:n});if(!r.ok)return;let i=URL.createObjectURL(await r.blob());if(e){URL.revokeObjectURL(i);return}C.current&&URL.revokeObjectURL(C.current),C.current=i,T.current=!0,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 P=l||Nt(g);return(0,a.jsxs)(c.NodeViewWrapper,{as:`div`,className:`image-node-view group/img`,contentEditable:!1,children:[P?(0,a.jsxs)(`div`,{className:`image-placeholder`,children:[A&&(0,a.jsx)(`button`,{type:`button`,className:`img-ctrl-btn img-ctrl-btn--del image-placeholder-del`,onClick:()=>{Dt()||($(!0),h(!0))},title:`删除`,children:(0,a.jsx)(`svg`,{width:`14`,height:`14`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,children:(0,a.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16`})})}),(0,a.jsx)(`svg`,{width:`32`,height:`32`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`1.5`,children:(0,a.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M2.25 15.75l5.159-5.159a2.25 2.25 0 013.182 0l5.159 5.159m-1.5-1.5l1.409-1.409a2.25 2.25 0 013.182 0l2.909 2.909M3.75 21h16.5A2.25 2.25 0 0022.5 18.75V5.25A2.25 2.25 0 0020.25 3H3.75A2.25 2.25 0 001.5 5.25v13.5A2.25 2.25 0 003.75 21z`})}),(0,a.jsx)(`span`,{className:`image-placeholder-text`,children:Nt(g)?`本地图片无法加载`:`图片加载失败`}),(0,a.jsx)(`span`,{className:`image-placeholder-path`,children:_||g})]}):(0,a.jsxs)(`div`,{ref:b,className:`img-wrap`,children:[(0,a.jsx)(`img`,{ref:S,src: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:M,title:`全屏`,children:(0,a.jsx)(`svg`,{width:`14`,height:`14`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,children:(0,a.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M15 3h6v6M9 21H3v-6M21 3l-7 7M3 21l7-7`})})}),A&&(0,a.jsx)(`button`,{type:`button`,className:`img-ctrl-btn img-ctrl-btn--del`,onClick:()=>{Dt()||($(!0),h(!0))},title:`删除`,children:(0,a.jsx)(`svg`,{width:`14`,height:`14`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,children:(0,a.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16`})})})]})]}),o&&!P&&(0,a.jsxs)(`div`,{className:`image-lightbox`,onClick:ee,children:[(0,a.jsxs)(`div`,{className:`image-lightbox-bar`,children:[(0,a.jsx)(`button`,{type:`button`,className:`image-lightbox-bar-btn`,onClick:N,title:`全屏`,children:(0,a.jsx)(`svg`,{width:`18`,height:`18`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,children:(0,a.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M15 3h6v6M9 21H3v-6M21 3l-7 7M3 21l7-7`})})}),(0,a.jsx)(`button`,{type:`button`,className:`image-lightbox-bar-btn`,onClick:ee,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)(Mt,{open:m,title:`确认删除图片`,message:P?`该图片无法在当前环境加载,仅从编辑器中移除该图片节点,不影响存储文件。`:`此操作将同时删除对象存储中的文件,不可撤销。`,onCancel:()=>{$(!1),h(!1)},onConfirm:async()=>{if(!P)try{await nt(g)}catch{}$(!1),await new Promise(e=>setTimeout(e,300)),n()}})]})}var Ft=(0,i.lazy)(()=>import(`@file-viewer/react`)),It=new Set,Lt={rendererMode:`replace`,autoRenderers:!0,theme:`light`,styleIsolation:`scoped`,toolbar:{position:`bottom-right`,download:!1,permissions:{download:!1}},pdf:{workerUrl:`/file-viewer/vendor/pdf/pdf.worker.mjs`,cMapUrl:`/file-viewer/vendor/pdf/cmaps/`,wasmUrl:`/file-viewer/vendor/pdf/wasm/`,standardFontDataUrl:`/file-viewer/vendor/pdf/standard_fonts/`,cjkFontFallbackPath:`/file-viewer/vendor/pdf/fonts/`},spreadsheet:{workerUrl:`/file-viewer/vendor/xlsx/sheet.worker.js`},docx:{workerUrl:`/file-viewer/vendor/docx/docx.worker.js`,workerJsZipUrl:`/file-viewer/vendor/docx/jszip.min.js`,backgroundColor:`#ffffff`},archive:{workerUrl:`/file-viewer/vendor/libarchive/worker-bundle.js`,wasmUrl:`/file-viewer/vendor/libarchive/libarchive.wasm`,cache:!0,workerTimeoutMs:3e4}},Rt={pdf:`pdf`,docx:`word`,docm:`word`,dotx:`word`,dotm:`word`,doc:`word`,dot:`word`,rtf:`word`,odt:`word`,xlsx:`spreadsheet`,xlsm:`spreadsheet`,xlsb:`spreadsheet`,xls:`spreadsheet`,xltx:`spreadsheet`,xlt:`spreadsheet`,csv:`spreadsheet`,tsv:`spreadsheet`,ods:`spreadsheet`,numbers:`spreadsheet`,pptx:`presentation`,pptm:`presentation`,potx:`presentation`,potm:`presentation`,ppsx:`presentation`,ppsm:`presentation`,ppt:`presentation`,pot:`presentation`,odp:`presentation`,zip:`archive`,rar:`archive`,"7z":`archive`,tar:`archive`,gz:`archive`,tgz:`archive`,bz2:`archive`,xz:`archive`,zst:`archive`,txt:`text`,md:`text`,log:`text`,html:`text`,htm:`text`,css:`text`,js:`text`,jsx:`text`,ts:`text`,tsx:`text`,py:`text`,sh:`text`,sql:`text`,json:`text`,xml:`text`,yml:`text`,yaml:`text`},zt={pdf:()=>import(`@file-viewer/renderer-pdf`).then(e=>e.pdfRenderer),word:()=>import(`@file-viewer/renderer-word`).then(e=>e.wordRenderer),spreadsheet:()=>import(`@file-viewer/renderer-spreadsheet`).then(e=>e.spreadsheetRenderer),presentation:()=>import(`@file-viewer/renderer-presentation`).then(e=>e.presentationRenderer),archive:()=>import(`@file-viewer/renderer-archive`).then(e=>e.archiveRenderer),text:()=>import(`@file-viewer/renderer-text`).then(e=>e.textRenderer)};function Bt(e){return e?e<1024?`${e} B`:e<1048576?`${(e/1024).toFixed(1)} KB`:`${(e/1048576).toFixed(1)} MB`:``}function Vt(e){let t=e.split(`.`).pop()?.toLowerCase()||``,n={pdf:{label:`PDF`,color:`#ef4444`},doc:{label:`DOC`,color:`#2563eb`},docx:{label:`DOC`,color:`#2563eb`},dot:{label:`DOT`,color:`#2563eb`},dotx:{label:`DOT`,color:`#2563eb`},xls:{label:`XLS`,color:`#16a34a`},xlsx:{label:`XLS`,color:`#16a34a`},xlt:{label:`XLT`,color:`#16a34a`},xltx:{label:`XLT`,color:`#16a34a`},csv:{label:`CSV`,color:`#16a34a`},ppt:{label:`PPT`,color:`#ea580c`},pptx:{label:`PPT`,color:`#ea580c`},pot:{label:`POT`,color:`#ea580c`},potx:{label:`POT`,color:`#ea580c`},zip:{label:`ZIP`,color:`#ca8a04`},rar:{label:`RAR`,color:`#ca8a04`},"7z":{label:`7Z`,color:`#ca8a04`},tar:{label:`TAR`,color:`#ca8a04`},gz:{label:`GZ`,color:`#ca8a04`},txt:{label:`TXT`,color:`#6b7280`},md:{label:`MD`,color:`#6b7280`},log:{label:`LOG`,color:`#6b7280`},html:{label:`HTM`,color:`#7c3aed`},htm:{label:`HTM`,color:`#7c3aed`},css:{label:`CSS`,color:`#7c3aed`},js:{label:`JS`,color:`#7c3aed`},jsx:{label:`JSX`,color:`#7c3aed`},ts:{label:`TS`,color:`#7c3aed`},tsx:{label:`TSX`,color:`#7c3aed`},json:{label:`JSON`,color:`#7c3aed`},xml:{label:`XML`,color:`#7c3aed`}}[t]||{label:t?t.slice(0,3).toUpperCase():`FILE`,color:`#6b7280`};return(0,a.jsxs)(`svg`,{width:`22`,height:`22`,viewBox:`0 0 24 24`,fill:`none`,xmlns:`http://www.w3.org/2000/svg`,"aria-hidden":`true`,children:[(0,a.jsx)(`path`,{d:`M6 2h7l5 5v15a1 1 0 0 1-1 1H6a1 1 0 0 1-1-1V3a1 1 0 0 1 1-1z`,fill:`#fff`,stroke:n.color,strokeWidth:`1.5`,strokeLinejoin:`round`}),(0,a.jsx)(`path`,{d:`M13 2v5h5`,fill:`none`,stroke:n.color,strokeWidth:`1.5`,strokeLinejoin:`round`}),(0,a.jsx)(`rect`,{x:`5`,y:`14`,width:`14`,height:`6.5`,rx:`1.2`,fill:n.color}),(0,a.jsx)(`text`,{x:`12`,y:`19`,textAnchor:`middle`,fontSize:`5`,fontWeight:`700`,fill:`#fff`,fontFamily:`Arial, sans-serif`,children:n.label})]})}function Ht(e){return e.split(`.`).pop()?.toLowerCase()||``}function Ut(e){let t=e.split(`.`).pop()?.toLowerCase()||``;return/^(pdf|docx?|dotx?|xlsx?|xltx?|pptx?|potx?|txt|md|html?|csv|json|xml|yml|yaml|log|zip|rar|7z|tar|gz|odt|ods|odp|rtf|xlsm|xlsb|ppsx|numbers|tgz|bz2|xz|zst|js|ts|tsx|py|sh|sql)$/.test(t)}function Wt(e){return!!e&&!e.startsWith(`file:`)}function Gt(e){return btoa(encodeURIComponent(e)).replace(/\+/g,`-`).replace(/\//g,`_`).replace(/=+$/,``)}async function Kt(e,t){try{let n=Gt(e),r=await fetch(`/api/preview/${n}`,{signal:t,cache:`no-store`});if(!r.ok)return null;if((r.headers.get(`Content-Type`)||``).includes(`text/html`))return console.warn(`[attachment] /api/preview returned HTML (endpoint missing), fallback to direct XHR`),null;let i=await r.arrayBuffer(),a=Number(r.headers.get(`Content-Length`)||0);return i.byteLength>0&&(a===0||i.byteLength===a)?i:(console.warn(`[attachment] /api/preview data incomplete`),null)}catch{return null}}function qt(e,t,n){return new Promise((r,i)=>{let a=new XMLHttpRequest;if(a.open(`GET`,e,!0),a.responseType=`arraybuffer`,t){let e=[`host`,`connection`,`content-length`,`cookie`,`date`,`expect`,`keep-alive`,`origin`,`referer`,`te`,`trailer`,`transfer-encoding`,`upgrade`,`via`];for(let[n,r]of Object.entries(t))if(!e.includes(n.toLowerCase()))try{a.setRequestHeader(n,r)}catch{}}if(a.onload=()=>{a.status>=200&&a.status<300?r(a.response):i(Error(`HTTP ${a.status} ${a.statusText}`))},a.onerror=()=>i(Error(`XHR network error`)),a.ontimeout=()=>i(Error(`XHR timeout`)),n){if(n.aborted){a.abort(),i(new DOMException(`Aborted`,`AbortError`));return}n.addEventListener(`abort`,()=>{a.abort(),i(new DOMException(`Aborted`,`AbortError`))})}a.send()})}function Jt({node:n,deleteNode:r,selected:o,editor:s}){let l=s?.isEditable??!0,u=n.attrs.src||``,[d,f]=(0,i.useState)(()=>It.has(u)),[p,m]=(0,i.useState)(null),[h,g]=(0,i.useState)(null),[_,v]=(0,i.useState)(!1),[y,b]=(0,i.useState)(null),[x,S]=(0,i.useState)(!1),[C,w]=(0,i.useState)(null),T=(0,i.useRef)(null),E=(0,i.useRef)(null),D=(0,i.useRef)(null),O=(0,i.useRef)(0),k=(0,i.useRef)(!1),A=(0,i.useRef)(null),j=(0,i.useRef)(0),[ee,M]=(0,i.useState)(!1),N=(0,i.useRef)(null),[P,te]=(0,i.useState)(0),[F,I]=(0,i.useState)(`none`),[ne,re]=(0,i.useState)(void 0),[ie,ae]=(0,i.useState)(!1),L=n.attrs.src||``,R=n.attrs.name||L&&L.split(`/`).pop()?.split(`?`)[0]||(L?`attachment`:e.o(`editor.attachment.lost`)),z=n.attrs.size||0,B=Ht(R),V=!L;(0,i.useEffect)(()=>{if(!d){re(void 0),ae(!1);return}let e=Rt[B];if(!e){re(void 0),ae(!1);return}let t=!0;return re(void 0),ae(!1),zt[e]().then(e=>{t&&re(e)}).catch(n=>{console.error(`[attachment] renderer "${e}" load failed:`,n),t&&ae(!0)}),()=>{t=!1}},[d,B]);let oe=(0,i.useMemo)(()=>({...Lt,renderers:ne?[ne]:[],rendererMode:`replace`}),[ne]),H=(0,i.useCallback)(e=>{f(t=>{let n=typeof e==`function`?e(t):e;return L&&(n?It.add(L):It.delete(L)),n})},[L]);(0,i.useEffect)(()=>{f(L?It.has(L):!1)},[L]);let U=(0,i.useCallback)(()=>{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()=>{F===`web`?(I(`none`),document.body.style.overflow=``,U()):(F===`native`&&document.fullscreenElement&&await document.exitFullscreen(),O.current=window.scrollY,j.current=A.current?.scrollTop??0,document.body.style.overflow=`hidden`,I(`web`))},[F]),se=(0,i.useCallback)(async()=>{let e=E.current;e&&(F===`native`?await document.exitFullscreen():(F===`web`&&(I(`none`),document.body.style.overflow=``),O.current=window.scrollY,j.current=A.current?.scrollTop??0,await e.requestFullscreen(),I(`native`)))},[F,U]),G=(0,i.useCallback)(()=>{F===`none`&&(k.current||H(e=>!e))},[F]);(0,i.useEffect)(()=>{let e=()=>{document.fullscreenElement||(F===`native`&&I(`none`),U())},t=e=>{e.key===`Escape`&&F===`web`&&(I(`none`),document.body.style.overflow=``,U())};return document.addEventListener(`fullscreenchange`,e),window.addEventListener(`keydown`,t),()=>{document.removeEventListener(`fullscreenchange`,e),window.removeEventListener(`keydown`,t)}},[F,U]),(0,i.useEffect)(()=>{let e=e=>{if(!(e.key!==`Backspace`&&e.key!==`Delete`)&&l&&o&&!Dt()){if(e.preventDefault(),e.stopPropagation(),s){let{from:e,to:t}=s.state.selection;N.current={from:e,to:t}}window.getSelection()?.removeAllRanges(),$(!0),M(!0)}};return window.addEventListener(`keydown`,e,!0),()=>window.removeEventListener(`keydown`,e,!0)},[o,s,l]),(0,i.useEffect)(()=>{if(!d||!Wt(L)){m(null),b(null),D.current=null;return}if(D.current===L)return;let e=new AbortController,n=!0;return v(!0),b(null),(async()=>{let r=L.includes(`?X-Amz-`),i=null,a=null;if(!i&&!r&&(i=await Kt(L,e.signal)),!i&&!r)try{let n=await t.n(L);n&&(i=await Kt(n,e.signal)||await qt(n,void 0,e.signal))}catch(e){console.warn(`[attachment] signPreviewUrl failed:`,e)}if(!i&&!r)try{let n=await t.r(L);if(n){let t={"X-Requested-With":`XMLHttpRequest`};n.forEach((e,n)=>{t[n]=e});try{i=await qt(L,t,e.signal)}catch(e){console.warn(`[attachment] signed headers XHR failed:`,e),a=e instanceof Error?e:Error(String(e))}}}catch(e){console.warn(`[attachment] signPreviewUrlHeaders failed:`,e)}if(!i)try{i=await qt(L,r?void 0:{"X-Requested-With":`XMLHttpRequest`},e.signal)}catch(e){console.warn(`[attachment] plain XHR failed:`,e),a=e instanceof Error?e:Error(String(e))}if(!i)throw a||Error(`所有 fetch 方法均失败`);if(!n)return;m(i),D.current=L;let o=URL.createObjectURL(new Blob([i],{type:`application/octet-stream`}));g(o),v(!1)})().catch(e=>{if(n&&!(e instanceof DOMException&&e.name===`AbortError`)){if(D.current===L){v(!1);return}b(e instanceof Error?e.message:`附件读取失败,请检查对象存储 CORS 和公开访问权限`)}}),()=>{n=!1,e.abort()}},[d,L]),(0,i.useEffect)(()=>()=>{h&&URL.revokeObjectURL(h),m(null)},[]),(0,i.useEffect)(()=>()=>{h&&URL.revokeObjectURL(h),g(null),m(null),D.current=null},[L]),(0,i.useEffect)(()=>{if(C!==`success`&&C!==`error`)return;let e=window.setTimeout(()=>w(null),2400);return()=>window.clearTimeout(e)},[C]);let ce=(0,i.useCallback)(async()=>{S(!0),w(`loading`);try{if(h){let e=document.createElement(`a`);e.href=h,e.download=R,document.body.appendChild(e),e.click(),document.body.removeChild(e),w(`success`);return}let e=L.includes(`?X-Amz-`),n=null;if(!e)try{let e=await t.n(L);e&&(n=await fetch(e,{headers:{"X-Requested-With":`XMLHttpRequest`}}),n.ok||(n=null))}catch{}if(!n&&!e)try{let e=await t.r(L);e&&(n=await fetch(L,{headers:(()=>{let t=new Headers(e);return t.set(`X-Requested-With`,`XMLHttpRequest`),t})()}),n.ok||(n=null))}catch{}if(n||=await fetch(L,{headers:{"X-Requested-With":`XMLHttpRequest`}}),!n||!n.ok)throw Error(`下载失败`);let r=await n.blob(),i=URL.createObjectURL(r),a=document.createElement(`a`);a.href=i,a.download=R,document.body.appendChild(a),a.click(),document.body.removeChild(a),URL.revokeObjectURL(i),w(`success`)}catch(e){console.error(`[attachment] download failed:`,e),w(`error`)}finally{S(!1)}},[L,R,h]);return(0,a.jsxs)(c.NodeViewWrapper,{ref:T,as:`div`,className:`attachment-embed group/att ${o?`is-selected`:``}`,contentEditable:!1,children:[(0,a.jsxs)(`div`,{className:`att-inner`,style:o?{outline:`2px solid var(--primary, #6366f1)`,outlineOffset:`2px`}:void 0,children:[(0,a.jsxs)(`div`,{className:`att-header`,children:[(0,a.jsxs)(`div`,{className:`att-info`,children:[(0,a.jsx)(`span`,{className:`att-icon`,children:V?(0,a.jsxs)(`svg`,{width:`22`,height:`22`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`1.6`,strokeLinecap:`round`,strokeLinejoin:`round`,"aria-hidden":`true`,style:{color:`#9ca3af`},children:[(0,a.jsx)(`path`,{d:`M10.29 3.86 1.82 18a2 2 0 0 0 1.71 3h16.94a2 2 0 0 0 1.71-3L13.71 3.86a2 2 0 0 0-3.42 0z`}),(0,a.jsx)(`path`,{d:`M12 9v4`}),(0,a.jsx)(`path`,{d:`M12 17h.01`})]}):Vt(R)}),(0,a.jsxs)(`div`,{className:`att-meta`,children:[(0,a.jsx)(`span`,{className:`att-name`,children:R}),z>0&&(0,a.jsx)(`span`,{className:`att-size`,children:Bt(z)})]})]}),(0,a.jsxs)(`div`,{className:`att-tools`,children:[(0,a.jsxs)(`div`,{className:`att-download-status`,role:`status`,"aria-live":`polite`,"aria-atomic":`true`,children:[C===`loading`&&(0,a.jsxs)(`span`,{className:`att-download-status__content is-loading`,children:[(0,a.jsx)(`svg`,{className:`att-download-spinner`,width:`13`,height:`13`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,"aria-hidden":`true`,children:(0,a.jsx)(`path`,{strokeLinecap:`round`,d:`M12 2a10 10 0 1 0 10 10`})}),`正在准备`]}),C===`success`&&(0,a.jsxs)(`span`,{className:`att-download-status__content is-success`,children:[(0,a.jsx)(`svg`,{width:`13`,height:`13`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,"aria-hidden":`true`,children:(0,a.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`m5 12 4 4L19 6`})}),`已下载`]}),C===`error`&&(0,a.jsx)(`span`,{className:`att-download-status__content is-error`,children:`下载失败,请重试`})]}),(0,a.jsxs)(`div`,{className:`att-actions`,children:[L&&Ut(R)&&(0,a.jsx)(`button`,{type:`button`,className:`att-btn`,onMouseDown:e=>{e.preventDefault(),e.stopPropagation(),G()},title:e.o(`editor.attachment.preview`),"aria-label":e.o(`editor.attachment.preview`),children:(0,a.jsxs)(`svg`,{width:`14`,height:`14`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,"aria-hidden":`true`,children:[(0,a.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M2.036 12.322a1.012 1.012 0 010-.639C3.423 7.51 7.36 4.5 12 4.5c4.638 0 8.573 3.007 9.963 7.178.07.207.07.431 0 .639C20.577 16.49 16.64 19.5 12 19.5c-4.638 0-8.573-3.007-9.963-7.178z`}),(0,a.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M15 12a3 3 0 11-6 0 3 3 0 016 0z`})]})}),(0,a.jsx)(`button`,{type:`button`,className:`att-btn`,onClick:ce,disabled:x||V,title:x?`正在准备下载`:e.o(`editor.attachment.download`),"aria-label":x?`正在准备下载`:e.o(`editor.attachment.download`),children:(0,a.jsx)(`svg`,{width:`14`,height:`14`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,"aria-hidden":`true`,children:(0,a.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M4 16v1a3 3 0 003 3h10a3 3 0 003-3v-1m-4-4l-4 4m0 0l-4-4m4 4V4`})})}),l&&(0,a.jsx)(`button`,{type:`button`,className:`att-btn att-btn--del`,onClick:()=>{!l||Dt()||($(!0),M(!0))},title:e.o(`editor.attachment.delete`),"aria-label":e.o(`editor.attachment.delete`),children:(0,a.jsx)(`svg`,{width:`14`,height:`14`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,"aria-hidden":`true`,children:(0,a.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16`})})})]})]})]}),d&&(0,a.jsxs)(`div`,{ref:E,className:`att-preview-wrap ${F===`web`?`is-web-fs`:``}`,style:{position:`relative`,height:500,overflow:`hidden`,background:`#fff`},children:[(0,a.jsx)(`div`,{ref: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||ie)&&!p&&!h?(0,a.jsxs)(`div`,{className:`flex h-full flex-col items-center justify-center gap-2 p-6 text-center text-sm text-default-500`,children:[(0,a.jsx)(`div`,{className:`font-medium text-default-700`,children:`暂时无法预览此附件`}),(0,a.jsx)(`div`,{className:`max-w-md text-xs leading-relaxed`,children:`请稍后重试,或使用附件栏中的下载按钮。`})]}):(0,a.jsx)(i.Suspense,{fallback:(0,a.jsx)(`div`,{className:`flex items-center justify-center h-full text-default-400 text-sm`,style:{background:`#fff`},children:e.o(`editor.attachment.loadingPreview`)}),children:p||h||L?ne?(0,a.jsx)(Ft,{buffer:p||void 0,url:h||L,name:R,filename:R,type:B,size:z||p?.byteLength||0,options:oe},`${L}-${P}`):(0,a.jsx)(`div`,{className:`flex h-full items-center justify-center text-sm text-default-400`,children:`正在加载预览引擎...`}):(0,a.jsx)(`div`,{className:`flex h-full items-center justify-center text-sm text-default-400`,children:`正在加载...`})})}),(0,a.jsxs)(`div`,{className:`att-fs-controls__panel`,style:{position:`absolute`,top:8,right:8,zIndex:10,display:`flex`,gap:2,padding:4,background:`rgba(255,255,255,0.92)`,backdropFilter:`blur(8px)`,WebkitBackdropFilter:`blur(8px)`,borderRadius:8,boxShadow:`0 2px 8px rgba(0,0,0,0.12)`,border:`1px solid rgba(0,0,0,0.06)`},children:[(0,a.jsx)(`button`,{type:`button`,onClick:W,title:F===`web`?`退出网页全屏`:`网页全屏`,"aria-label":F===`web`?`退出网页全屏`:`网页全屏`,style:{width:28,height:28,borderRadius:6,border:`none`,background:F===`web`?`#e4e4e7`:`transparent`,cursor:`pointer`,display:`flex`,alignItems:`center`,justifyContent:`center`,color:`#52525b`,transition:`background 0.12s`},onMouseEnter:e=>{F!==`web`&&(e.currentTarget.style.background=`#f4f4f5`)},onMouseLeave:e=>{F!==`web`&&(e.currentTarget.style.background=`transparent`)},children:(0,a.jsx)(`svg`,{width:`14`,height:`14`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,"aria-hidden":`true`,children:(0,a.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M8 3H5a2 2 0 00-2 2v3m18 0V5a2 2 0 00-2-2h-3m0 18h3a2 2 0 002-2v-3M3 16v3a2 2 0 002 2h3`})})}),(0,a.jsx)(`button`,{type:`button`,onClick:se,title:F===`native`?`退出全屏`:`全屏`,"aria-label":F===`native`?`退出全屏`:`全屏`,style:{width:28,height:28,borderRadius:6,border:`none`,background:F===`native`?`#e4e4e7`:`transparent`,cursor:`pointer`,display:`flex`,alignItems:`center`,justifyContent:`center`,color:`#52525b`,transition:`background 0.12s`},onMouseEnter:e=>{F!==`native`&&(e.currentTarget.style.background=`#f4f4f5`)},onMouseLeave:e=>{F!==`native`&&(e.currentTarget.style.background=`transparent`)},children:(0,a.jsx)(`svg`,{width:`14`,height:`14`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,"aria-hidden":`true`,children:(0,a.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M15 3h6v6M9 21H3v-6M21 3l-7 7M3 21l7-7`})})})]})]})]}),(0,a.jsx)(Mt,{open:ee,title:`确认删除附件`,message:V?`此操作将删除该附件节点,不可撤销。`:`此操作将同时删除对象存储中的文件(${R}),不可撤销。`,onCancel:()=>{$(!1),M(!1)},onConfirm:async()=>{try{if(s){let e=N.current,t=e?.from??s.state.selection.from,n=e?.to??s.state.selection.to,r=[];s.state.doc.nodesBetween(t,n,e=>{e.type.name===`attachmentEmbed`&&e.attrs?.src&&r.push(nt(e.attrs.src))}),await Promise.all(r),$(!1),await new Promise(e=>setTimeout(e,300)),s.chain().focus().setTextSelection({from:t,to:n}).deleteSelection().run()}else await nt(L),$(!1),await new Promise(e=>setTimeout(e,300)),r()}catch{$(!1)}}})]})}var Yt=d.Node.create({name:`attachmentEmbed`,group:`block`,atom:!0,inline:!1,addNodeView(){return(0,c.ReactNodeViewRenderer)(Jt)},addAttributes(){return{src:{default:null,parseHTML:e=>e.getAttribute(`data-src`)||e.querySelector(`a`)?.getAttribute(`href`)},name:{default:``,parseHTML:e=>e.getAttribute(`data-name`)||e.querySelector(`a`)?.getAttribute(`download`)||``},size:{default:0,parseHTML:e=>Number(e.getAttribute(`data-size`)||0)},type:{default:``,parseHTML:e=>e.getAttribute(`data-type`)||``}}},parseHTML(){return[{tag:`div[data-attachment-embed]`}]},renderHTML({HTMLAttributes:e}){return[`div`,{"data-attachment-embed":`true`,"data-src":e.src,"data-name":e.name,"data-size":e.size||0,"data-type":e.type||``,class:`attachment-embed`},[`a`,{href:e.src,download:e.name},`📎 ${e.name||`attachment`}`]]}});function Xt({node:e,deleteNode:n,editor:r}){let o=e.attrs.src||``,s=e.attrs.name||o.split(`/`).pop()?.split(`?`)[0]||`audio`,[l,u]=(0,i.useState)(!1),d=r?.isEditable??!0;(0,i.useEffect)(()=>()=>{o.startsWith(`blob:`)&&URL.revokeObjectURL(o)},[o]);let f=!!o&&(o.startsWith(`blob:`)||o.startsWith(`data:`)),[p,m]=(0,i.useState)(f?o:null),[h,g]=(0,i.useState)(f),_=(0,i.useRef)(null);return(0,i.useEffect)(()=>{if(!o){m(null),g(!1);return}if(o.startsWith(`blob:`)||o.startsWith(`data:`)){m(o),g(!0);return}let e=!1;return g(!1),(async()=>{let n=o;try{let e=await t.r(o);if(e){let t=await fetch(o,{headers:e});if(t.ok){let e=URL.createObjectURL(await t.blob());_.current&&URL.revokeObjectURL(_.current),_.current=e,n=e}}}catch{}e||(m(n),g(!0))})(),()=>{e=!0,_.current&&=(URL.revokeObjectURL(_.current),null)}},[o]),(0,a.jsxs)(c.NodeViewWrapper,{as:`div`,className:`audio-embed group/audio`,style:{margin:`1rem 0`},contentEditable:!1,children:[(0,a.jsxs)(`div`,{className:`audio-embed-inner`,children:[(0,a.jsxs)(`div`,{className:`audio-embed-header`,children:[(0,a.jsxs)(`div`,{className:`audio-embed-title`,children:[(0,a.jsx)(`svg`,{className:`audio-embed-icon`,width:`16`,height:`16`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,children:(0,a.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M9 19V6l12-3v13M9 19c0 1.105-1.343 2-3 2s-3-.895-3-2 1.343-2 3-2 3 .895 3 2zm12-3c0 1.105-1.343 2-3 2s-3-.895-3-2 1.343-2 3-2 3 .895 3 2zM9 10l12-3`})}),(0,a.jsx)(`span`,{className:`audio-embed-filename`,children:s})]}),(0,a.jsx)(`div`,{className:`audio-embed-actions`,children:d&&(0,a.jsx)(`button`,{type:`button`,className:`audio-embed-btn audio-embed-btn--del`,onClick:()=>{Dt()||($(!0),u(!0))},title:`删除`,children:(0,a.jsx)(`svg`,{width:`12`,height:`12`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,children:(0,a.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16`})})})})]}),(0,a.jsx)(`div`,{className:`audio-embed-player`,children:o?h&&p?(0,a.jsx)(`audio`,{src:p,controls:!0,style:{width:`100%`},onError:async e=>{let n=e.currentTarget;try{let e=await t.r(o),r=await fetch(o,e?{headers:e}:{});if(r.ok){let e=await r.blob();n.src.startsWith(`blob:`)&&URL.revokeObjectURL(n.src),n.src=URL.createObjectURL(e)}}catch{}}}):(0,a.jsxs)(`div`,{className:`audio-embed-loading`,children:[(0,a.jsx)(`span`,{className:`audio-embed-spinner`}),`音频加载中…`]}):(0,a.jsxs)(`div`,{className:`audio-embed-loading audio-embed-missing`,children:[(0,a.jsx)(`span`,{className:`audio-embed-missing-icon`,"aria-hidden":`true`,children:`!`}),`音频文件缺失`]})})]}),(0,a.jsx)(Mt,{open:l,title:`确认删除音频`,message:`此操作将同时删除对象存储中的文件(${s}),不可撤销。`,onCancel:()=>{$(!1),u(!1)},onConfirm:async()=>{try{await nt(o)}catch{}$(!1),await new Promise(e=>setTimeout(e,300)),n()}})]})}function Zt(e){return/\.(mp3|wav|ogg|flac|aac|m4a|wma|opus)(\?|$)/i.test(e)||/\/.*\.(mp3|wav|ogg|flac)/i.test(e)}var Qt=d.Node.create({name:`audioEmbed`,group:`block`,atom:!0,inline:!1,addNodeView(){return(0,c.ReactNodeViewRenderer)(Xt)},addProseMirrorPlugins(){return[new f.Plugin({props:{handlePaste(e,t){let n=t.clipboardData?.getData(`text/plain`);if(!n)return!1;let r=n.split(/\r?\n/);for(let n of r){let r=n.trim();if(!r||r.includes(` `)||!Zt(r))continue;t.preventDefault();let i=e.state.schema.nodes.audioEmbed.create({src:r});return e.dispatch(e.state.tr.replaceSelectionWith(i)),!0}return!1}}})]},addAttributes(){return{src:{default:null},name:{default:``},size:{default:0,parseHTML:e=>Number(e.getAttribute(`data-size`)||0)}}},parseHTML(){return[{tag:`div[data-audio-embed]`,getAttrs:e=>{let t=e,n=t.getAttribute(`src`)||t.getAttribute(`data-src`)||t.querySelector(`audio`)?.getAttribute(`src`)||null;return n?{src:n}:null}},{tag:`audio[src]`}]},renderHTML({HTMLAttributes:e}){return[`div`,{"data-audio-embed":`true`,src:e.src,"data-src":e.src,"data-size":e.size||0,class:`audio-embed`},[`audio`,{src:e.src,controls:`true`,style:`width:100%;`}]]}});function $t(e){return e?/bilibili\.com|BV[a-zA-Z0-9]{10}|av\d+/i.test(e)?`bilibili`:/xiaohongshu\.com|xhslink\.com/i.test(e)?`xiaohongshu`:/\.(mp4|m3u8|webm|ogg|flv|mkv|mov|avi|wmv|ts|m4v|3gp|f4v|rmvb)(\?|$)/i.test(e)||/\/.*\.(mp4|m3u8|mov|webm|flv|mkv)/i.test(e)?`direct`:`unknown`:`unknown`}function en(e){let t=e.match(/BV[a-zA-Z0-9]{10}/);if(t)return t[0];let n=e.match(/av(\d+)/i);return n?n[0]:e}function tn({node:e,deleteNode:t,editor:n}){let r=e.attrs.src||``,o=e.attrs.source||`unknown`,s=o===`unknown`?$t(r):o,[l,u]=(0,i.useState)(!1),[d,f]=(0,i.useState)(!1),[p,m]=(0,i.useState)(!1),h=n?.isEditable??!0,g=!h&&r.startsWith(`blob:`),_=(0,a.jsx)(Mt,{open:l,title:`确认删除视频`,message:`此操作将同时删除对象存储中的文件,不可撤销。`,onCancel:()=>{$(!1),u(!1)},onConfirm:async()=>{try{await nt(r)}catch{}$(!1),await new Promise(e=>setTimeout(e,300)),t()}}),[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-D8Rk6R5t.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=en(r);return(0,a.jsxs)(c.NodeViewWrapper,{as:`div`,className:`video-embed video-embed--bilibili group/video`,style:{margin:`1rem 0`},contentEditable:!1,children:[(0,a.jsxs)(`div`,{ref: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:()=>{Dt()||($(!0),u(!0))},children:(0,a.jsx)(`svg`,{width:`12`,height:`12`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,children:(0,a.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16`})})})]}),(0,a.jsx)(`div`,{style:{position:`relative`,paddingTop:`56.25%`},children:(0,a.jsx)(`iframe`,{ref: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:()=>{Dt()||($(!0),u(!0))},children:(0,a.jsx)(`svg`,{width:`12`,height:`12`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,children:(0,a.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16`})})}),(0,a.jsx)(`button`,{type:`button`,className:`video-fs-btn`,title:`全屏`,onClick: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 nn(e){return/bilibili\.com|BV[a-zA-Z0-9]{10}|av\d+/i.test(e)?`bilibili`:/xiaohongshu\.com|xhslink\.com/i.test(e)?`xiaohongshu`:/\.(mp4|m3u8|webm|ogg|flv|mkv|mov|avi|wmv|ts|m4v|3gp|f4v|rmvb)(\?|$)/i.test(e)||/\/.*\.(mp4|m3u8|mov|webm|flv|mkv)/i.test(e)?`direct`:`unknown`}function rn(e){let t=e.match(/BV[a-zA-Z0-9]{10}/);if(t)return t[0];let n=e.match(/av(\d+)/i);return n?n[0]:e}function an(e){let t=e.match(/explore\/([a-zA-Z0-9]+)/);return t?t[1]:e}var on=d.Node.create({name:`videoEmbed`,group:`block`,atom:!0,inline:!1,addNodeView(){return(0,c.ReactNodeViewRenderer)(tn)},addProseMirrorPlugins(){return[new f.Plugin({props:{handleKeyDown(e,t){if(t.key!==` `)return!1;let n=e.state.selection;if(n instanceof f.NodeSelection&&n.node.type.name===`videoEmbed`){t.preventDefault();let r=e.nodeDOM(n.from);if(r){let e=r.querySelector(`div`)?.__xgplayer;e&&(e.paused?e.play():e.pause())}return!0}return!1},handlePaste(e,t){let n=t.clipboardData?.getData(`text/plain`);if(!n)return!1;let r=n.split(/\r?\n/);for(let n of r){let r=n.trim();if(!r||r.includes(` `))continue;let i=nn(r);if(i===`unknown`)continue;t.preventDefault();let a=e.state.schema.nodes.videoEmbed.create({src:r,source:i}),o=e.state.tr.replaceSelectionWith(a);return e.dispatch(o),!0}return!1}}})]},addAttributes(){return{src:{default:null},source:{default:`unknown`},name:{default:``},size:{default:0,parseHTML:e=>Number(e.getAttribute(`data-size`)||0)}}},parseHTML(){return[{tag:`div[data-video-embed]`,getAttrs:e=>{let t=e,n=t.getAttribute(`src`)||t.getAttribute(`data-src`)||``;return{src:n,source:nn(n)}}},{tag:`div[data-bilibili]`},{tag:`div[data-xiaohongshu]`}]},renderHTML({HTMLAttributes:e}){let t=e.src||``,n=nn(t);if(n===`bilibili`){let e=rn(t);return[`div`,{"data-video-embed":`bilibili`,src:t,"data-bvid":e,class:`video-embed video-embed--bilibili`,style:`margin: 1rem 0; border-radius: 12px; overflow: hidden;`},[`iframe`,{src:`https://player.bilibili.com/player.html?bvid=${e}&page=1&high_quality=1`,width:`100%`,height:`400`,frameborder:`0`,allowfullscreen:`true`,scrolling:`no`,style:`border: none; display: block;`}]]}if(n===`xiaohongshu`)return an(t),[`div`,{"data-video-embed":`xiaohongshu`,src:t,class:`video-embed video-embed--xiaohongshu`,style:`border: 1px solid #e5e7eb; border-radius: 12px; padding: 16px; display: flex; align-items: center; gap: 12px; max-width: 480px; margin: 1rem 0;`},[`div`,{style:`width:40px;height:40px;background:#ff2442;border-radius:10px;display:flex;align-items:center;justify-content:center;color:#fff;font-weight:bold;font-size:14px;flex-shrink:0;`},`红`],[`div`,{},[`div`,{style:`font-weight:600;font-size:14px;`},`小红书笔记`],[`a`,{href:t,target:`_blank`,rel:`noopener noreferrer`,style:`color:#ff2442;font-size:12px;text-decoration:none;`},`在小红书中打开 →`]]];let r=`xgplayer-${Math.random().toString(36).slice(2,8)}`;return[`div`,{"data-video-embed":`direct`,src:t,"data-player-id":r,"data-size":e.size||0,class:`video-embed video-embed--direct`,style:`margin: 1rem 0; border-radius: 12px; overflow: hidden; background: #000;`},[`div`,{id:r,style:`width:100%;max-width:720px;`}]]},addCommands(){return{insertVideo:e=>({chain:t})=>{let n=nn(e.src);return t().insertContent({type:this.name,attrs:{...e,source:n}}).focus().run()}}}}),sn=null;async function cn(e){sn||=await import(`beautiful-mermaid`);let t=sn.renderMermaidSVG;return t(e)}var ln=[{value:`javascript`,label:`JavaScript`,deviconClass:`devicon-javascript-plain`,color:`#f0db4f`},{value:`typescript`,label:`TypeScript`,deviconClass:`devicon-typescript-plain`,color:`#3178c6`},{value:`python`,label:`Python`,deviconClass:`devicon-python-plain`,color:`#306998`},{value:`java`,label:`Java`,deviconClass:`devicon-java-plain`,color:`#b07219`},{value:`go`,label:`Go`,deviconClass:`devicon-go-plain`,color:`#00add8`},{value:`rust`,label:`Rust`,deviconClass:`devicon-rust-plain`,color:`#dea584`},{value:`c`,label:`C`,deviconClass:`devicon-c-plain`,color:`#555555`},{value:`cpp`,label:`C++`,deviconClass:`devicon-cplusplus-plain`,color:`#f34b7d`},{value:`csharp`,label:`C#`,deviconClass:`devicon-csharp-plain`,color:`#178600`},{value:`html`,label:`HTML`,deviconClass:`devicon-html5-plain`,color:`#e34c26`},{value:`css`,label:`CSS`,deviconClass:`devicon-css3-plain`,color:`#563d7c`},{value:`json`,label:`JSON`,deviconClass:`devicon-json-plain`,color:`#292929`},{value:`sql`,label:`SQL`,deviconClass:`devicon-mysql-plain`,color:`#00758f`},{value:`bash`,label:`Bash`,deviconClass:`devicon-bash-plain`,color:`#3dbb58`},{value:`sh`,label:`Shell (sh)`,deviconClass:`devicon-bash-plain`,color:`#3dbb58`},{value:`shell`,label:`PowerShell`,deviconClass:`devicon-powershell-plain`,color:`#3dbb58`},{value:`yaml`,label:`YAML`,deviconClass:`devicon-yaml-plain`,color:`#cb171e`},{value:`php`,label:`PHP`,deviconClass:`devicon-php-plain`,color:`#4f5d95`},{value:`ruby`,label:`Ruby`,deviconClass:`devicon-ruby-plain`,color:`#701516`},{value:`swift`,label:`Swift`,deviconClass:`devicon-swift-plain`,color:`#f05138`},{value:`kotlin`,label:`Kotlin`,deviconClass:`devicon-kotlin-plain`,color:`#a97bff`},{value:`dockerfile`,label:`Dockerfile`,deviconClass:`devicon-docker-plain`,color:`#0db7ed`},{value:`vue`,label:`Vue`,deviconClass:`devicon-vuejs-plain`,color:`#42b883`},{value:`react`,label:`React`,deviconClass:`devicon-react-plain`,color:`#61dafb`},{value:`markdown`,label:`Markdown`,deviconClass:`devicon-markdown-plain`,color:`#083fa1`},{value:`mermaid`,label:`Mermaid`,color:`#ff3670`},{value:`txt`,label:`Plain Text`,color:`#6b7280`}],un={javascript:`js`,typescript:`ts`,python:`py`,java:`java`,go:`go`,rust:`rs`,c:`c`,cpp:`cpp`,csharp:`cs`,html:`html`,css:`css`,json:`json`,sql:`sql`,bash:`sh`,shell:`sh`,yaml:`yml`,php:`php`,ruby:`rb`,swift:`swift`,kotlin:`kt`,dockerfile:``,markdown:`md`,txt:`txt`,vue:`vue`,react:`jsx`},dn={js:`javascript`,ts:`typescript`,py:`python`,rb:`ruby`,rs:`rust`,kt:`kotlin`,cs:`csharp`,"c++":`cpp`,"c#":`csharp`,golang:`go`,yml:`yaml`,ps1:`shell`,jsx:`javascript`,tsx:`typescript`};function fn(e){return e instanceof Element&&!!e.closest(`.cb-code-area`)}function pn({node:t,updateAttributes:n,editor:r,getPos:o,deleteNode:s,selected:l}){let u=r?.isEditable??!0,d=!u,[f,p]=(0,i.useState)(!1),[m,h]=(0,i.useState)(!1),[g,_]=(0,i.useState)(!1),[v,y]=(0,i.useState)(``),[b,x]=(0,i.useState)(!1),[S,C]=(0,i.useState)(null),[w,T]=(0,i.useState)(null),[E,D]=(0,i.useState)(!1),[O,k]=(0,i.useState)([]),A=(0,i.useRef)(null),j=(0,i.useRef)(null),ee=(0,i.useRef)(null),M=(0,i.useRef)(null),N=(0,i.useRef)(null),P=t.attrs.language||``,te=ln.find(e=>e.value===(dn[P]??P)),F=P===`mermaid`,I=(0,i.useCallback)(e=>{fn(e.target)||e.stopPropagation()},[]),ne=(0,i.useCallback)(()=>{if(!r||typeof o!=`function`)return null;let e=o();return typeof e==`number`?{from:e,to:e+t.nodeSize}:null},[r,o,t.nodeSize]),re=(0,i.useCallback)(()=>{u&&(Dt()||(N.current=ne(),window.getSelection()?.removeAllRanges(),$(!0),x(!0)))},[ne,u]),ie=(0,i.useMemo)(()=>t.textContent?t.textContent.split(`
3
+ `);l=n.pop()||``;for(let e of n){let t=e.trim();if(!t||!t.startsWith(`data: `))continue;let n=t.slice(6);if(n===`[DONE]`)return;try{let e=JSON.parse(n).choices?.[0]?.delta?.content;e&&(yield e)}catch{}}}}return{async*stream(e){yield*a(De(e.mode,e.instruction),e.context)},async generate(e){let t=De(e.mode,e.instruction),n=``;for await(let r of a(t,e.context))n+=r;return n}}}function Me(e){return je({apiKey:e.apiKey,baseURL:e.baseURL||`https://api.deepseek.com/v1`,model:e.model||`deepseek-v4-flash`,headers:e.headers})}function Ne(e){return je({apiKey:e.apiKey,baseURL:e.baseURL||`https://api.openai.com/v1`,model:e.model||`gpt-5.6-luna`,headers:e.headers})}function Pe(e){return je({apiKey:e.apiKey,baseURL:e.baseURL||`https://dashscope.aliyuncs.com/compatible-mode/v1`,model:e.model||`qwen3.7-plus`,headers:e.headers})}var Fe={keyword:``,caseSensitive:!1,wholeWord:!1,matches:[],currentIndex:-1},Z=new f.PluginKey(`search-highlight`);function Ie(e){return e.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`)}function Le(e,t){let{keyword:n,caseSensitive:r,wholeWord:i}=t;if(!n)return[];let a=r?`g`:`gi`,o=i?`\\b${Ie(n)}\\b`:Ie(n),s=new RegExp(o,a),c=[];return e.descendants((e,t)=>{if(!e.isText||!e.text)return;s.lastIndex=0;let n;for(;(n=s.exec(e.text))!==null;){let e=t+n.index,r=e+n[0].length;c.push({from:e,to:r}),n[0].length===0&&s.lastIndex++}}),c}function Re(e,t){if(t.matches.length===0)return p.DecorationSet.empty;let n=t.matches.map((e,n)=>p.Decoration.inline(e.from,e.to,{class:n===t.currentIndex?`search-highlight search-highlight--active`:`search-highlight`}));return p.DecorationSet.create(e,n)}function ze(e,t){if(t.currentIndex<0||t.currentIndex>=t.matches.length)return;let n=t.matches[t.currentIndex];n&&requestAnimationFrame(()=>{try{let t=e.dom.querySelector(`.search-highlight--active`);if(t){let e=t.getBoundingClientRect(),n=window.innerHeight-80;(e.top<120||e.bottom>n)&&t.scrollIntoView({behavior:`smooth`,block:`center`});return}let r=e.coordsAtPos(n.from),i=window.innerHeight-80;if(r.top<120||r.top>i){let e=r.top-window.innerHeight/2;window.scrollBy({top:e,behavior:`smooth`})}}catch{}})}var Be=d.Extension.create({name:`searchHighlight`,addProseMirrorPlugins(){return[new f.Plugin({key:Z,state:{init:()=>Fe,apply(e,t){let n=e.getMeta(Z);if(n)return{...t,...n,matches:n.matches===void 0?t.matches:n.matches,currentIndex:n.currentIndex===void 0?t.currentIndex:n.currentIndex};if(e.docChanged&&t.keyword){let n=Le(e.doc,t),r=t.currentIndex;return r>=n.length&&(r=n.length-1),r<0&&(r=n.length>0?0:-1),{...t,matches:n,currentIndex:r}}return t}},props:{decorations(e){let t=Z.getState(e);return t?Re(e.doc,t):p.DecorationSet.empty}}})]},addCommands(){return{setSearch:(e,t={})=>({state:n,dispatch:r,view:i})=>{let a=Z.getState(n)||Fe,o={keyword:e,caseSensitive:t.caseSensitive??a.caseSensitive,wholeWord:t.wholeWord??a.wholeWord,matches:[],currentIndex:-1};return o.matches=Le(n.doc,o),o.currentIndex=o.matches.length>0?0:-1,r&&(r(n.tr.setMeta(Z,o)),i&&ze(i,o)),!0},nextMatch:()=>({state:e,dispatch:t,view:n})=>{let r=Z.getState(e)||Fe;if(r.matches.length===0)return!1;let i=(r.currentIndex+1)%r.matches.length;return t&&(t(e.tr.setMeta(Z,{currentIndex:i})),n&&ze(n,{...r,currentIndex:i})),!0},prevMatch:()=>({state:e,dispatch:t,view:n})=>{let r=Z.getState(e)||Fe;if(r.matches.length===0)return!1;let i=(r.currentIndex-1+r.matches.length)%r.matches.length;return t&&(t(e.tr.setMeta(Z,{currentIndex:i})),n&&ze(n,{...r,currentIndex:i})),!0},clearSearch:()=>({state:e,dispatch:t})=>(t&&t(e.tr.setMeta(Z,Fe)),!0)}}});function Ve(e){let t=e.state;return Z.getState(t)||Fe}var He=({editor:e,onClose:t})=>{let[n,r]=(0,i.useState)(``),[o,s]=(0,i.useState)(!1),[c,l]=(0,i.useState)(!1),[u,d]=(0,i.useState)(0),f=(0,i.useRef)(null),p=(0,i.useRef)({keyword:n,caseSensitive:o,wholeWord:c});p.current={keyword:n,caseSensitive:o,wholeWord:c},(0,i.useEffect)(()=>{if(!e)return;let t=0,n=()=>{t&&cancelAnimationFrame(t),t=requestAnimationFrame(()=>{t=0,d(e=>(e+1)%1e6)})};return e.on(`update`,n),()=>{e.off(`update`,n),t&&cancelAnimationFrame(t)}},[e]),(0,i.useEffect)(()=>{let e=setTimeout(()=>f.current?.focus(),30);return()=>clearTimeout(e)},[]),(0,i.useEffect)(()=>{if(!e)return;let t=requestAnimationFrame(()=>{let{keyword:t,caseSensitive:n,wholeWord:r}=p.current;try{e.commands.setSearch(t,{caseSensitive:n,wholeWord:r})}catch(e){console.warn(`[SearchBar] setSearch failed:`,e)}});return()=>cancelAnimationFrame(t)},[e,n,o,c]),(0,i.useEffect)(()=>()=>{try{e?.commands.clearSearch()}catch{}},[]),(0,i.useEffect)(()=>{let e=e=>{e.key===`Escape`&&(e.preventDefault(),e.stopPropagation(),t())};return window.addEventListener(`keydown`,e,!0),()=>window.removeEventListener(`keydown`,e,!0)},[t]);let m=(0,i.useCallback)(()=>{try{e?.commands.nextMatch()}catch{}},[e]),h=(0,i.useCallback)(()=>{try{e?.commands.prevMatch()}catch{}},[e]),g=(0,i.useCallback)(e=>{e.stopPropagation(),e.key===`Enter`&&(e.preventDefault(),e.shiftKey?h():m())},[m,h]),_=(0,i.useMemo)(()=>{if(!e)return null;try{return Ve(e)}catch{return null}},[e,n,o,c,u]),v=n?_&&_.matches.length>0?`${_.currentIndex+1} / ${_.matches.length}`:`无匹配`:``,y=(0,i.useCallback)(e=>{e.stopPropagation()},[]);return(0,a.jsx)(`div`,{className:`search-bar`,role:`search`,"aria-label":`文档内搜索`,onClick:y,onMouseDown:y,children:(0,a.jsxs)(`div`,{className:`search-bar__main`,children:[(0,a.jsx)(`svg`,{className:`search-bar__icon`,width:`14`,height:`14`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,children:(0,a.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M21 21l-6-6m2-5a7 7 0 11-14 0 7 7 0 0114 0z`})}),(0,a.jsx)(`input`,{ref:f,type:`text`,className:`search-bar__input`,placeholder:`查找…`,value:n,onChange:e=>r(e.target.value),onKeyDown:g,onKeyUp:y,onKeyPress:y,onInput:y,spellCheck:!1,autoComplete:`off`,inputMode:`text`}),(0,a.jsx)(`span`,{className:`search-bar__count`,children:v}),(0,a.jsx)(`button`,{type:`button`,className:`search-bar__toggle${o?` search-bar__toggle--active`:``}`,onClick:()=>s(e=>!e),title:`区分大小写 (Aa)`,"aria-pressed":o,children:`Aa`}),(0,a.jsx)(`button`,{type:`button`,className:`search-bar__toggle${c?` search-bar__toggle--active`:``}`,onClick:()=>l(e=>!e),title:`整词匹配 (\\b)`,"aria-pressed":c,children:`\\b`}),(0,a.jsx)(`div`,{className:`search-bar__sep`}),(0,a.jsx)(`button`,{type:`button`,className:`search-bar__btn`,onClick:h,title:`上一个 (Shift+Enter)`,disabled:!_||_.matches.length===0,children:(0,a.jsx)(`svg`,{width:`14`,height:`14`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,children:(0,a.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M5 15l7-7 7 7`})})}),(0,a.jsx)(`button`,{type:`button`,className:`search-bar__btn`,onClick:m,title:`下一个 (Enter)`,disabled:!_||_.matches.length===0,children:(0,a.jsx)(`svg`,{width:`14`,height:`14`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,children:(0,a.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M19 9l-7 7-7-7`})})}),(0,a.jsx)(`button`,{type:`button`,className:`search-bar__btn search-bar__btn--close`,onClick:t,title:`关闭 (Esc)`,children:(0,a.jsx)(`svg`,{width:`14`,height:`14`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,children:(0,a.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M6 18L18 6M6 6l12 12`})})})]})})};function Q({children:e,...t}){return(0,a.jsx)(`svg`,{width:16,height:16,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:2,strokeLinecap:`round`,strokeLinejoin:`round`,"aria-hidden":`true`,...t,children:e})}var Ue=e=>(0,a.jsxs)(Q,{...e,children:[(0,a.jsx)(`path`,{d:`M6 4h8a4 4 0 0 1 0 8H6z`}),(0,a.jsx)(`path`,{d:`M6 12h9a4 4 0 0 1 0 8H6z`})]}),We=e=>(0,a.jsxs)(Q,{...e,children:[(0,a.jsx)(`path`,{d:`M19 4h-9`}),(0,a.jsx)(`path`,{d:`M14 20H5`}),(0,a.jsx)(`path`,{d:`M15 4 9 20`})]}),Ge=e=>(0,a.jsxs)(Q,{...e,children:[(0,a.jsx)(`path`,{d:`M6 4v6a6 6 0 0 0 12 0V4`}),(0,a.jsx)(`path`,{d:`M4 20h16`})]}),Ke=e=>(0,a.jsxs)(Q,{...e,children:[(0,a.jsx)(`path`,{d:`M16 4H9a3 3 0 0 0-2.83 4`}),(0,a.jsx)(`path`,{d:`M14 12a4 4 0 0 1 0 8H6`}),(0,a.jsx)(`path`,{d:`M4 12h16`})]}),qe=e=>(0,a.jsxs)(Q,{...e,children:[(0,a.jsx)(`path`,{d:`m16 18 6-6-6-6`}),(0,a.jsx)(`path`,{d:`m8 6-6 6 6 6`})]}),Je=e=>(0,a.jsxs)(Q,{...e,children:[(0,a.jsx)(`path`,{d:`m9 11-6 6v3h9l3-3`}),(0,a.jsx)(`path`,{d:`m22 12-4.6 4.6a2 2 0 0 1-2.8 0l-5.2-5.2a2 2 0 0 1 0-2.8L14 4`})]}),Ye=e=>(0,a.jsxs)(Q,{...e,children:[(0,a.jsx)(`path`,{d:`M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71`}),(0,a.jsx)(`path`,{d:`M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71`})]}),Xe=e=>(0,a.jsxs)(Q,{...e,children:[(0,a.jsx)(`rect`,{x:`3`,y:`3`,width:`18`,height:`18`,rx:`2`,ry:`2`}),(0,a.jsx)(`path`,{d:`M3 9h18M3 15h18M9 3v18M15 3v18`})]}),Ze=e=>(0,a.jsxs)(Q,{...e,children:[(0,a.jsx)(`rect`,{x:`8`,y:`8`,width:`14`,height:`14`,rx:`2`,ry:`2`}),(0,a.jsx)(`path`,{d:`M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2`})]}),Qe=e=>(0,a.jsxs)(Q,{...e,children:[(0,a.jsx)(`circle`,{cx:`11`,cy:`11`,r:`8`}),(0,a.jsx)(`path`,{d:`m21 21-4.3-4.3`})]}),$e=e=>(0,a.jsxs)(Q,{...e,children:[(0,a.jsx)(`path`,{d:`M12 3l1.6 4.4L18 9l-4.4 1.6L12 15l-1.6-4.4L6 9l4.4-1.6L12 3z`}),(0,a.jsx)(`path`,{d:`M18.5 14l.7 1.9 1.9.7-1.9.7-.7 1.9-.7-1.9-1.9-.7 1.9-.7.7-1.9z`})]}),et=e=>(0,a.jsxs)(Q,{...e,children:[(0,a.jsx)(`circle`,{cx:`5`,cy:`12`,r:`1`}),(0,a.jsx)(`circle`,{cx:`12`,cy:`12`,r:`1`}),(0,a.jsx)(`circle`,{cx:`19`,cy:`12`,r:`1`})]}),tt=e=>(0,a.jsxs)(Q,{...e,children:[(0,a.jsx)(`path`,{d:`M18 6 6 18`}),(0,a.jsx)(`path`,{d:`m6 6 12 12`})]});async function nt(e){if(e){if(e.startsWith(`blob:`)){URL.revokeObjectURL(e);return}try{await n.n().remove(e)}catch(e){console.warn(`删除存储资源失败:`,e)}}}var rt=3e4,it=new Set([`image`,`attachmentEmbed`,`audioEmbed`,`videoEmbed`]),at=new WeakMap;function ot(e){let t=new Set;return e.state.doc.descendants(e=>{if(it.has(e.type.name)){let n=e.attrs.src;n&&t.add(n)}return!0}),t}function st(e){let t=at.get(e);return t||(t={timers:new Map,onTransaction:()=>{},listening:!1},at.set(e,t)),t}function ct(e,t){let n=[...new Set(t.filter(Boolean))];if(n.length===0)return;let r=st(e);r.listening||=(r.onTransaction=()=>{if(r.timers.size===0)return;let t=ot(e);for(let[e,n]of r.timers)t.has(e)&&(clearTimeout(n),r.timers.delete(e))},e.on(`transaction`,r.onTransaction),!0);for(let t of n){if(r.timers.has(t))continue;let n=setTimeout(()=>{ot(e).has(t)||nt(t),r.timers.delete(t)},rt);r.timers.set(t,n)}}function lt(e){let t=at.get(e);if(t){if(t.listening&&=(e.off(`transaction`,t.onTransaction),!1),t.timers.size>0){let n=ot(e);for(let[e,r]of t.timers)clearTimeout(r),n.has(e)||nt(e);t.timers.clear()}at.delete(e)}}var ut=[{mode:`continue`,labelKey:`editor.ai.continue`,descKey:`editor.ai.continueDesc`,icon:`→`},{mode:`improve`,labelKey:`editor.ai.improve`,descKey:`editor.ai.improveDesc`,icon:`✨`},{mode:`shorter`,labelKey:`editor.ai.shorter`,descKey:`editor.ai.shorterDesc`,icon:`↓`},{mode:`longer`,labelKey:`editor.ai.longer`,descKey:`editor.ai.longerDesc`,icon:`↑`},{mode:`fix`,labelKey:`editor.ai.fix`,descKey:`editor.ai.fixDesc`,icon:`✓`},{mode:`translate`,labelKey:`editor.ai.translate`,descKey:`editor.ai.translateDesc`,icon:`🌐`},{mode:`zap`,labelKey:`editor.ai.zap`,descKey:`editor.ai.zapDesc`,icon:`⚡`}],dt=new Set([`image`,`attachmentEmbed`,`audioEmbed`,`videoEmbed`]),ft={image:`editor.ai.nodeImage`,attachmentEmbed:`editor.ai.nodeAttachment`,videoEmbed:`editor.ai.nodeVideo`,audioEmbed:`editor.ai.nodeAudio`};function pt(e,t){return e.storage.qingwuUI?.parseMd?.(e.schema,t)||null}function mt(e,t,n){let r=[];return e.state.doc.nodesBetween(t,n,e=>{if(dt.has(e.type.name)){let t=e.attrs.src;t&&r.push({type:e.type.name,src:t})}return!0}),r}function ht(e){let t=new Set;return e.state.doc.descendants(e=>{if(dt.has(e.type.name)){let n=e.attrs.src;n&&t.add(n)}return!0}),t}function gt(e,t){let n=pt(e,t);if(n&&n.size>0){let t=e.state.tr;t.replaceWith(0,e.state.doc.content.size,n),t.setSelection(f.TextSelection.create(t.doc,t.doc.content.size)),e.view.dispatch(t.scrollIntoView()),e.commands.focus();return}e.commands.setContent(t),e.commands.focus()}function _t(e,t,n,r){let i=pt(e,t);if(e.commands.focus(),!i){let i=e.chain().focus();n===`replace`?i.setTextSelection({from:r.from,to:r.to}).deleteSelection().insertContent(t).run():i.insertContentAt(r.to,t).run();return}let a=e.state.tr;n===`replace`?a.replaceRange(r.from,r.to,new s.Slice(i,0,0)):a.insert(Math.min(r.to,e.state.doc.content.size),i),e.view.dispatch(a.scrollIntoView())}function vt({editor:t,onClose:n}){let[r,o]=(0,i.useState)(null),[s,c]=(0,i.useState)(``),[l,u]=(0,i.useState)(``),[d,f]=(0,i.useState)(!1),[p,m]=(0,i.useState)(null),[h,g]=(0,i.useState)(null),_=(0,i.useRef)({from:0,to:0,empty:!0}),v=(0,i.useRef)(null),y=(0,i.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=Ae(),i=r.empty?t.state.doc.textContent:t.state.doc.textBetween(r.from,r.to),a=[];for await(let t of e.stream({mode:n,context:i,instruction:n===`zap`?s:void 0}))a.push(t),u(a.join(``))}catch(t){m(t instanceof Error?t.message:e.o(`editor.ai.error`))}finally{f(!1)}},[t,s]);(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(mt(t,r.from,r.to).map(e=>e.src));e===`replaceAll`?gt(t,n):_t(t,n,`replace`,_.current);let a=ht(t);ct(t,[...i].filter(e=>!a.has(e)))},[t]),w=(0,i.useCallback)(e=>{if(e===`below`){_t(t,l,`below`,_.current),n();return}let r=_.current,i=e===`replaceAll`?{from:0,to:t.state.doc.content.size}:{from:r.from,to:r.to},a=mt(t,i.from,i.to);if(a.length>0){g({position:e,willRemove:a});return}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)($e,{className:`text-primary`}),e.o(`editor.ai.trigger`)]}),(0,a.jsx)(`button`,{type:`button`,onClick:n,"aria-label":e.o(`editor.ai.close`),title:e.o(`editor.ai.close`),className:`flex items-center justify-center w-6 h-6 rounded-md text-default-400 hover:bg-default-100 hover:text-default-700 transition-colors`,children:(0,a.jsx)(tt,{})})]}),(0,a.jsx)(`div`,{className:`grid grid-cols-[repeat(auto-fit,minmax(64px,1fr))] gap-1.5 p-2 shrink-0`,children:ut.map(({mode:t,labelKey:n,descKey:i,icon:o})=>(0,a.jsxs)(`button`,{type:`button`,className:`flex flex-col items-center gap-1 px-1 py-2 rounded-xl border transition-colors ${r===t?`border-primary/40 bg-primary/10 text-primary`:`border-default-200 text-default-600 hover:bg-default-100 hover:text-default-900`}`,onClick:()=>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(ft[t]??t),` ×`,n]},t))})]})]}),(0,a.jsxs)(`div`,{className:`qed-footer`,style:{display:`flex`,justifyContent:`flex-end`,gap:8},children:[(0,a.jsx)(`button`,{type:`button`,className:`qed-btn qed-btn--ghost`,onClick:()=>g(null),children:e.o(`editor.ai.cancel`)}),(0,a.jsx)(`button`,{type:`button`,className:`qed-btn qed-btn--primary`,onClick:T,children:e.o(`editor.ai.confirmReplace`)})]})]})]})]})}var yt=new Set([`attachmentEmbed`,`videoEmbed`,`audioEmbed`,`image`]);function bt(e){let t=0;return e.descendants(e=>{yt.has(e.type.name)&&(t+=Number(e.attrs?.size)||0)}),t}function xt(e){if(!Number.isFinite(e)||e<=0)return`0 B`;let t=[`B`,`KB`,`MB`,`GB`,`TB`],n=Math.min(t.length-1,Math.floor(Math.log(e)/Math.log(1024))),r=e/1024**n;return`${n===0||r>=100?`${Math.round(r)}`:`${Math.round(r*10)/10}`} ${t[n]}`}function St(e){return(e?.storage)?.qingwuUI?.limits}function Ct(e,t,n){let{maxAttachmentSize:r,maxTotalAttachmentSize:i}=n;if(r&&t.size>r)return`单文件大小不能超过 ${xt(r)}(当前 ${xt(t.size)})`;if(i){let n=bt(e)+t.size;if(n>i)return`附件总大小不能超过 ${xt(i)}(当前合计 ${xt(n)})`}return null}var wt=!1,Tt=null,Et=5e3;function Dt(){return wt}function $(e){wt=e,Tt&&=(clearTimeout(Tt),null),e&&(Tt=setTimeout(()=>{wt=!1,Tt=null},Et))}var Ot=null;function kt(e){Ot=e}function At(){return Ot}var jt=300;function Mt({open:e,title:t,message:n,confirmText:r=`删除`,cancelText:o=`取消`,onConfirm:s,onCancel:c}){let[l,d]=(0,i.useState)(!1),f=(0,i.useRef)(!1),p=At();return(0,i.useEffect)(()=>{if(!e){f.current=!1;return}!p||f.current||(f.current=!0,p({open:e,title:t,message:n,confirmText:r,cancelText:o,onConfirm:s,onCancel:c}))},[e,p,t,n,r,o,s,c]),(0,i.useEffect)(()=>{e||d(!1)},[e]),p||!e?null:(0,u.createPortal)((0,a.jsx)(`div`,{className:`fixed inset-0 z-[10001] flex items-center justify-center bg-black/40 backdrop-blur-sm select-none`,onClick:()=>{l||c()},onMouseDown:e=>e.preventDefault(),children:(0,a.jsxs)(`div`,{className:`bg-white dark:bg-zinc-800 rounded-xl p-6 shadow-xl max-w-sm w-full mx-4 border border-default-200 relative overflow-hidden`,onClick:e=>e.stopPropagation(),children:[l&&(0,a.jsxs)(`div`,{className:`delete-progress`,children:[(0,a.jsx)(`div`,{className:`delete-progress-spinner`}),(0,a.jsx)(`div`,{className:`delete-progress-text`,children:`删除中…`})]}),(0,a.jsx)(`div`,{className:`text-sm font-medium text-default-800 dark:text-zinc-100 mb-2`,children:t}),n&&(0,a.jsx)(`div`,{className:`text-xs text-default-500 dark:text-zinc-400 mb-4 whitespace-pre-line`,children:n}),(0,a.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,a.jsx)(`button`,{type:`button`,className:`px-3 py-1.5 text-xs rounded-lg border border-default-200 hover:bg-default-100 transition-colors`,onClick:c,disabled:l,children:o}),(0,a.jsx)(`button`,{type:`button`,className:`px-3 py-1.5 text-xs rounded-lg bg-red-500 hover:bg-red-600 text-white transition-colors disabled:opacity-60`,onClick:async()=>{if(l)return;d(!0);let e=Date.now();try{await s()}finally{let t=Date.now()-e;t<jt&&await new Promise(e=>setTimeout(e,jt-t)),d(!1),c()}},disabled:l,children:r})]})]})}),document.body)}function Nt(e){return/^(\.\.?\/|[a-zA-Z]:\\|file:\/\/)/.test(e)?!0:!(/^[a-z]+:\/\//i.test(e)||e.startsWith(`/`)||e.startsWith(`data:`)||e.startsWith(`blob:`))}function Pt({node:e,deleteNode:n,editor:r}){let[o,s]=(0,i.useState)(!1),[l,u]=(0,i.useState)(!1),[d,f]=(0,i.useState)(!1),p=(0,i.useRef)(!1),[m,h]=(0,i.useState)(!1),g=e.attrs.src||``,_=e.attrs.alt||``,v=e.attrs.width||null,y=e.attrs.height||null,b=(0,i.useRef)(null),x=(0,i.useRef)(null),S=(0,i.useRef)(null),C=(0,i.useRef)(null),w=(0,i.useRef)(null),T=(0,i.useRef)(!1),E=(0,i.useRef)(!1),D=(0,i.useRef)(0),[O,k]=(0,i.useState)(g),A=r?.isEditable??!0,j=(0,i.useCallback)(()=>{l||(D.current=window.scrollY,s(!0))},[l]),ee=(0,i.useCallback)(()=>{s(!1),requestAnimationFrame(()=>window.scrollTo(0,D.current))},[]),M=(0,i.useCallback)(()=>{let e=b.current;e&&(D.current=window.scrollY,e.requestFullscreen?e.requestFullscreen():e.webkitRequestFullscreen&&e.webkitRequestFullscreen())},[]),N=(0,i.useCallback)(()=>{let e=x.current;e&&(D.current=window.scrollY,e.requestFullscreen?e.requestFullscreen():e.webkitRequestFullscreen&&e.webkitRequestFullscreen())},[]);(0,i.useEffect)(()=>{u(!1),k(g),T.current=!1,E.current=!1,C.current&&=(URL.revokeObjectURL(C.current),null),w.current&&=(URL.revokeObjectURL(w.current),null)},[g]),(0,i.useEffect)(()=>{if(!g||g.startsWith(`blob:`)||g.startsWith(`data:`)||g.includes(`?X-Amz-`))return;let e=!1;return(async()=>{try{let{signPreviewUrlHeaders:t}=await Promise.resolve().then(()=>require("./signed-fetch-DiWXujJ1.cjs")).then(e=>e.i),n=await t(g);if(!n)return;let r=await fetch(g,{headers:n});if(!r.ok)return;let i=URL.createObjectURL(await r.blob());if(e){URL.revokeObjectURL(i);return}C.current&&URL.revokeObjectURL(C.current),C.current=i,T.current=!0,k(i)}catch{}})(),()=>{e=!0}},[g]),(0,i.useEffect)(()=>()=>{C.current&&URL.revokeObjectURL(C.current),w.current&&URL.revokeObjectURL(w.current)},[]),(0,i.useEffect)(()=>{if(!o)return;let e=e=>{if(e.key===`Escape`){if(document.fullscreenElement||p.current)return;s(!1)}};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[o]),(0,i.useEffect)(()=>{let e=()=>{let e=!!document.fullscreenElement;f(e),e||(p.current=!0,requestAnimationFrame(()=>window.scrollTo(0,D.current)),window.setTimeout(()=>{p.current=!1},300))};return document.addEventListener(`fullscreenchange`,e),()=>document.removeEventListener(`fullscreenchange`,e)},[]);let P=l||Nt(g);return(0,a.jsxs)(c.NodeViewWrapper,{as:`div`,className:`image-node-view group/img`,contentEditable:!1,children:[P?(0,a.jsxs)(`div`,{className:`image-placeholder`,children:[A&&(0,a.jsx)(`button`,{type:`button`,className:`img-ctrl-btn img-ctrl-btn--del image-placeholder-del`,onClick:()=>{Dt()||($(!0),h(!0))},title:`删除`,children:(0,a.jsx)(`svg`,{width:`14`,height:`14`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,children:(0,a.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16`})})}),(0,a.jsx)(`svg`,{width:`32`,height:`32`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`1.5`,children:(0,a.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M2.25 15.75l5.159-5.159a2.25 2.25 0 013.182 0l5.159 5.159m-1.5-1.5l1.409-1.409a2.25 2.25 0 013.182 0l2.909 2.909M3.75 21h16.5A2.25 2.25 0 0022.5 18.75V5.25A2.25 2.25 0 0020.25 3H3.75A2.25 2.25 0 001.5 5.25v13.5A2.25 2.25 0 003.75 21z`})}),(0,a.jsx)(`span`,{className:`image-placeholder-text`,children:Nt(g)?`本地图片无法加载`:`图片加载失败`}),(0,a.jsx)(`span`,{className:`image-placeholder-path`,children:_||g})]}):(0,a.jsxs)(`div`,{ref:b,className:`img-wrap`,children:[(0,a.jsx)(`img`,{ref:S,src: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:M,title:`全屏`,children:(0,a.jsx)(`svg`,{width:`14`,height:`14`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,children:(0,a.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M15 3h6v6M9 21H3v-6M21 3l-7 7M3 21l7-7`})})}),A&&(0,a.jsx)(`button`,{type:`button`,className:`img-ctrl-btn img-ctrl-btn--del`,onClick:()=>{Dt()||($(!0),h(!0))},title:`删除`,children:(0,a.jsx)(`svg`,{width:`14`,height:`14`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,children:(0,a.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16`})})})]})]}),o&&!P&&(0,a.jsxs)(`div`,{className:`image-lightbox`,onClick:ee,children:[(0,a.jsxs)(`div`,{className:`image-lightbox-bar`,children:[(0,a.jsx)(`button`,{type:`button`,className:`image-lightbox-bar-btn`,onClick:N,title:`全屏`,children:(0,a.jsx)(`svg`,{width:`18`,height:`18`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,children:(0,a.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M15 3h6v6M9 21H3v-6M21 3l-7 7M3 21l7-7`})})}),(0,a.jsx)(`button`,{type:`button`,className:`image-lightbox-bar-btn`,onClick:ee,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)(Mt,{open:m,title:`确认删除图片`,message:P?`该图片无法在当前环境加载,仅从编辑器中移除该图片节点,不影响存储文件。`:`此操作将同时删除对象存储中的文件,不可撤销。`,onCancel:()=>{$(!1),h(!1)},onConfirm:async()=>{if(!P)try{await nt(g)}catch{}$(!1),await new Promise(e=>setTimeout(e,300)),n()}})]})}var Ft=(0,i.lazy)(()=>import(`@file-viewer/react`)),It=new Set,Lt={rendererMode:`replace`,autoRenderers:!0,theme:`light`,styleIsolation:`scoped`,toolbar:{position:`bottom-right`,download:!1,permissions:{download:!1}},pdf:{workerUrl:`/file-viewer/vendor/pdf/pdf.worker.mjs`,cMapUrl:`/file-viewer/vendor/pdf/cmaps/`,wasmUrl:`/file-viewer/vendor/pdf/wasm/`,standardFontDataUrl:`/file-viewer/vendor/pdf/standard_fonts/`,cjkFontFallbackPath:`/file-viewer/vendor/pdf/fonts/`},spreadsheet:{workerUrl:`/file-viewer/vendor/xlsx/sheet.worker.js`},docx:{workerUrl:`/file-viewer/vendor/docx/docx.worker.js`,workerJsZipUrl:`/file-viewer/vendor/docx/jszip.min.js`,backgroundColor:`#ffffff`},archive:{workerUrl:`/file-viewer/vendor/libarchive/worker-bundle.js`,wasmUrl:`/file-viewer/vendor/libarchive/libarchive.wasm`,cache:!0,workerTimeoutMs:3e4}},Rt={pdf:`pdf`,docx:`word`,docm:`word`,dotx:`word`,dotm:`word`,doc:`word`,dot:`word`,rtf:`word`,odt:`word`,xlsx:`spreadsheet`,xlsm:`spreadsheet`,xlsb:`spreadsheet`,xls:`spreadsheet`,xltx:`spreadsheet`,xlt:`spreadsheet`,csv:`spreadsheet`,tsv:`spreadsheet`,ods:`spreadsheet`,numbers:`spreadsheet`,pptx:`presentation`,pptm:`presentation`,potx:`presentation`,potm:`presentation`,ppsx:`presentation`,ppsm:`presentation`,ppt:`presentation`,pot:`presentation`,odp:`presentation`,zip:`archive`,rar:`archive`,"7z":`archive`,tar:`archive`,gz:`archive`,tgz:`archive`,bz2:`archive`,xz:`archive`,zst:`archive`,txt:`text`,md:`text`,log:`text`,html:`text`,htm:`text`,css:`text`,js:`text`,jsx:`text`,ts:`text`,tsx:`text`,py:`text`,sh:`text`,sql:`text`,json:`text`,xml:`text`,yml:`text`,yaml:`text`},zt={pdf:()=>import(`@file-viewer/renderer-pdf`).then(e=>e.pdfRenderer),word:()=>import(`@file-viewer/renderer-word`).then(e=>e.wordRenderer),spreadsheet:()=>import(`@file-viewer/renderer-spreadsheet`).then(e=>e.spreadsheetRenderer),presentation:()=>import(`@file-viewer/renderer-presentation`).then(e=>e.presentationRenderer),archive:()=>import(`@file-viewer/renderer-archive`).then(e=>e.archiveRenderer),text:()=>import(`@file-viewer/renderer-text`).then(e=>e.textRenderer)};function Bt(e){return e?e<1024?`${e} B`:e<1048576?`${(e/1024).toFixed(1)} KB`:`${(e/1048576).toFixed(1)} MB`:``}function Vt(e){let t=e.split(`.`).pop()?.toLowerCase()||``,n={pdf:{label:`PDF`,color:`#ef4444`},doc:{label:`DOC`,color:`#2563eb`},docx:{label:`DOC`,color:`#2563eb`},dot:{label:`DOT`,color:`#2563eb`},dotx:{label:`DOT`,color:`#2563eb`},xls:{label:`XLS`,color:`#16a34a`},xlsx:{label:`XLS`,color:`#16a34a`},xlt:{label:`XLT`,color:`#16a34a`},xltx:{label:`XLT`,color:`#16a34a`},csv:{label:`CSV`,color:`#16a34a`},ppt:{label:`PPT`,color:`#ea580c`},pptx:{label:`PPT`,color:`#ea580c`},pot:{label:`POT`,color:`#ea580c`},potx:{label:`POT`,color:`#ea580c`},zip:{label:`ZIP`,color:`#ca8a04`},rar:{label:`RAR`,color:`#ca8a04`},"7z":{label:`7Z`,color:`#ca8a04`},tar:{label:`TAR`,color:`#ca8a04`},gz:{label:`GZ`,color:`#ca8a04`},txt:{label:`TXT`,color:`#6b7280`},md:{label:`MD`,color:`#6b7280`},log:{label:`LOG`,color:`#6b7280`},html:{label:`HTM`,color:`#7c3aed`},htm:{label:`HTM`,color:`#7c3aed`},css:{label:`CSS`,color:`#7c3aed`},js:{label:`JS`,color:`#7c3aed`},jsx:{label:`JSX`,color:`#7c3aed`},ts:{label:`TS`,color:`#7c3aed`},tsx:{label:`TSX`,color:`#7c3aed`},json:{label:`JSON`,color:`#7c3aed`},xml:{label:`XML`,color:`#7c3aed`}}[t]||{label:t?t.slice(0,3).toUpperCase():`FILE`,color:`#6b7280`};return(0,a.jsxs)(`svg`,{width:`22`,height:`22`,viewBox:`0 0 24 24`,fill:`none`,xmlns:`http://www.w3.org/2000/svg`,"aria-hidden":`true`,children:[(0,a.jsx)(`path`,{d:`M6 2h7l5 5v15a1 1 0 0 1-1 1H6a1 1 0 0 1-1-1V3a1 1 0 0 1 1-1z`,fill:`#fff`,stroke:n.color,strokeWidth:`1.5`,strokeLinejoin:`round`}),(0,a.jsx)(`path`,{d:`M13 2v5h5`,fill:`none`,stroke:n.color,strokeWidth:`1.5`,strokeLinejoin:`round`}),(0,a.jsx)(`rect`,{x:`5`,y:`14`,width:`14`,height:`6.5`,rx:`1.2`,fill:n.color}),(0,a.jsx)(`text`,{x:`12`,y:`19`,textAnchor:`middle`,fontSize:`5`,fontWeight:`700`,fill:`#fff`,fontFamily:`Arial, sans-serif`,children:n.label})]})}function Ht(e){return e.split(`.`).pop()?.toLowerCase()||``}function Ut(e){let t=e.split(`.`).pop()?.toLowerCase()||``;return/^(pdf|docx?|dotx?|xlsx?|xltx?|pptx?|potx?|txt|md|html?|csv|json|xml|yml|yaml|log|zip|rar|7z|tar|gz|odt|ods|odp|rtf|xlsm|xlsb|ppsx|numbers|tgz|bz2|xz|zst|js|ts|tsx|py|sh|sql)$/.test(t)}function Wt(e){return!!e&&!e.startsWith(`file:`)}function Gt(e){return btoa(encodeURIComponent(e)).replace(/\+/g,`-`).replace(/\//g,`_`).replace(/=+$/,``)}async function Kt(e,t){try{let n=Gt(e),r=await fetch(`/api/preview/${n}`,{signal:t,cache:`no-store`});if(!r.ok)return null;if((r.headers.get(`Content-Type`)||``).includes(`text/html`))return console.warn(`[attachment] /api/preview returned HTML (endpoint missing), fallback to direct XHR`),null;let i=await r.arrayBuffer(),a=Number(r.headers.get(`Content-Length`)||0);return i.byteLength>0&&(a===0||i.byteLength===a)?i:(console.warn(`[attachment] /api/preview data incomplete`),null)}catch{return null}}function qt(e,t,n){return new Promise((r,i)=>{let a=new XMLHttpRequest;if(a.open(`GET`,e,!0),a.responseType=`arraybuffer`,t){let e=[`host`,`connection`,`content-length`,`cookie`,`date`,`expect`,`keep-alive`,`origin`,`referer`,`te`,`trailer`,`transfer-encoding`,`upgrade`,`via`];for(let[n,r]of Object.entries(t))if(!e.includes(n.toLowerCase()))try{a.setRequestHeader(n,r)}catch{}}if(a.onload=()=>{a.status>=200&&a.status<300?r(a.response):i(Error(`HTTP ${a.status} ${a.statusText}`))},a.onerror=()=>i(Error(`XHR network error`)),a.ontimeout=()=>i(Error(`XHR timeout`)),n){if(n.aborted){a.abort(),i(new DOMException(`Aborted`,`AbortError`));return}n.addEventListener(`abort`,()=>{a.abort(),i(new DOMException(`Aborted`,`AbortError`))})}a.send()})}function Jt({node:n,deleteNode:r,selected:o,editor:s}){let l=s?.isEditable??!0,u=n.attrs.src||``,[d,f]=(0,i.useState)(()=>It.has(u)),[p,m]=(0,i.useState)(null),[h,g]=(0,i.useState)(null),[_,v]=(0,i.useState)(!1),[y,b]=(0,i.useState)(null),[x,S]=(0,i.useState)(!1),[C,w]=(0,i.useState)(null),T=(0,i.useRef)(null),E=(0,i.useRef)(null),D=(0,i.useRef)(null),O=(0,i.useRef)(0),k=(0,i.useRef)(!1),A=(0,i.useRef)(null),j=(0,i.useRef)(0),[ee,M]=(0,i.useState)(!1),N=(0,i.useRef)(null),[P,te]=(0,i.useState)(0),[F,I]=(0,i.useState)(`none`),[ne,re]=(0,i.useState)(void 0),[ie,ae]=(0,i.useState)(!1),L=n.attrs.src||``,R=n.attrs.name||L&&L.split(`/`).pop()?.split(`?`)[0]||(L?`attachment`:e.o(`editor.attachment.lost`)),z=n.attrs.size||0,B=Ht(R),V=!L;(0,i.useEffect)(()=>{if(!d){re(void 0),ae(!1);return}let e=Rt[B];if(!e){re(void 0),ae(!1);return}let t=!0;return re(void 0),ae(!1),zt[e]().then(e=>{t&&re(e)}).catch(n=>{console.error(`[attachment] renderer "${e}" load failed:`,n),t&&ae(!0)}),()=>{t=!1}},[d,B]);let oe=(0,i.useMemo)(()=>({...Lt,renderers:ne?[ne]:[],rendererMode:`replace`}),[ne]),H=(0,i.useCallback)(e=>{f(t=>{let n=typeof e==`function`?e(t):e;return L&&(n?It.add(L):It.delete(L)),n})},[L]);(0,i.useEffect)(()=>{f(L?It.has(L):!1)},[L]);let U=(0,i.useCallback)(()=>{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()=>{F===`web`?(I(`none`),document.body.style.overflow=``,U()):(F===`native`&&document.fullscreenElement&&await document.exitFullscreen(),O.current=window.scrollY,j.current=A.current?.scrollTop??0,document.body.style.overflow=`hidden`,I(`web`))},[F]),se=(0,i.useCallback)(async()=>{let e=E.current;e&&(F===`native`?await document.exitFullscreen():(F===`web`&&(I(`none`),document.body.style.overflow=``),O.current=window.scrollY,j.current=A.current?.scrollTop??0,await e.requestFullscreen(),I(`native`)))},[F,U]),G=(0,i.useCallback)(()=>{F===`none`&&(k.current||H(e=>!e))},[F]);(0,i.useEffect)(()=>{let e=()=>{document.fullscreenElement||(F===`native`&&I(`none`),U())},t=e=>{e.key===`Escape`&&F===`web`&&(I(`none`),document.body.style.overflow=``,U())};return document.addEventListener(`fullscreenchange`,e),window.addEventListener(`keydown`,t),()=>{document.removeEventListener(`fullscreenchange`,e),window.removeEventListener(`keydown`,t)}},[F,U]),(0,i.useEffect)(()=>{let e=e=>{if(!(e.key!==`Backspace`&&e.key!==`Delete`)&&l&&o&&!Dt()){if(e.preventDefault(),e.stopPropagation(),s){let{from:e,to:t}=s.state.selection;N.current={from:e,to:t}}window.getSelection()?.removeAllRanges(),$(!0),M(!0)}};return window.addEventListener(`keydown`,e,!0),()=>window.removeEventListener(`keydown`,e,!0)},[o,s,l]),(0,i.useEffect)(()=>{if(!d||!Wt(L)){m(null),b(null),D.current=null;return}if(D.current===L)return;let e=new AbortController,n=!0;return v(!0),b(null),(async()=>{let r=L.includes(`?X-Amz-`),i=null,a=null;if(!i&&!r&&(i=await Kt(L,e.signal)),!i&&!r)try{let n=await t.n(L);n&&(i=await Kt(n,e.signal)||await qt(n,void 0,e.signal))}catch(e){console.warn(`[attachment] signPreviewUrl failed:`,e)}if(!i&&!r)try{let n=await t.r(L);if(n){let t={"X-Requested-With":`XMLHttpRequest`};n.forEach((e,n)=>{t[n]=e});try{i=await qt(L,t,e.signal)}catch(e){console.warn(`[attachment] signed headers XHR failed:`,e),a=e instanceof Error?e:Error(String(e))}}}catch(e){console.warn(`[attachment] signPreviewUrlHeaders failed:`,e)}if(!i)try{i=await qt(L,r?void 0:{"X-Requested-With":`XMLHttpRequest`},e.signal)}catch(e){console.warn(`[attachment] plain XHR failed:`,e),a=e instanceof Error?e:Error(String(e))}if(!i)throw a||Error(`所有 fetch 方法均失败`);if(!n)return;m(i),D.current=L;let o=URL.createObjectURL(new Blob([i],{type:`application/octet-stream`}));g(o),v(!1)})().catch(e=>{if(n&&!(e instanceof DOMException&&e.name===`AbortError`)){if(D.current===L){v(!1);return}b(e instanceof Error?e.message:`附件读取失败,请检查对象存储 CORS 和公开访问权限`)}}),()=>{n=!1,e.abort()}},[d,L]),(0,i.useEffect)(()=>()=>{h&&URL.revokeObjectURL(h),m(null)},[]),(0,i.useEffect)(()=>()=>{h&&URL.revokeObjectURL(h),g(null),m(null),D.current=null},[L]),(0,i.useEffect)(()=>{if(C!==`success`&&C!==`error`)return;let e=window.setTimeout(()=>w(null),2400);return()=>window.clearTimeout(e)},[C]);let ce=(0,i.useCallback)(async()=>{S(!0),w(`loading`);try{if(h){let e=document.createElement(`a`);e.href=h,e.download=R,document.body.appendChild(e),e.click(),document.body.removeChild(e),w(`success`);return}let e=L.includes(`?X-Amz-`),n=null;if(!e)try{let e=await t.n(L);e&&(n=await fetch(e,{headers:{"X-Requested-With":`XMLHttpRequest`}}),n.ok||(n=null))}catch{}if(!n&&!e)try{let e=await t.r(L);e&&(n=await fetch(L,{headers:(()=>{let t=new Headers(e);return t.set(`X-Requested-With`,`XMLHttpRequest`),t})()}),n.ok||(n=null))}catch{}if(n||=await fetch(L,{headers:{"X-Requested-With":`XMLHttpRequest`}}),!n||!n.ok)throw Error(`下载失败`);let r=await n.blob(),i=URL.createObjectURL(r),a=document.createElement(`a`);a.href=i,a.download=R,document.body.appendChild(a),a.click(),document.body.removeChild(a),URL.revokeObjectURL(i),w(`success`)}catch(e){console.error(`[attachment] download failed:`,e),w(`error`)}finally{S(!1)}},[L,R,h]);return(0,a.jsxs)(c.NodeViewWrapper,{ref:T,as:`div`,className:`attachment-embed group/att ${o?`is-selected`:``}`,contentEditable:!1,children:[(0,a.jsxs)(`div`,{className:`att-inner`,style:o?{outline:`2px solid var(--primary, #6366f1)`,outlineOffset:`2px`}:void 0,children:[(0,a.jsxs)(`div`,{className:`att-header`,children:[(0,a.jsxs)(`div`,{className:`att-info`,children:[(0,a.jsx)(`span`,{className:`att-icon`,children:V?(0,a.jsxs)(`svg`,{width:`22`,height:`22`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`1.6`,strokeLinecap:`round`,strokeLinejoin:`round`,"aria-hidden":`true`,style:{color:`#9ca3af`},children:[(0,a.jsx)(`path`,{d:`M10.29 3.86 1.82 18a2 2 0 0 0 1.71 3h16.94a2 2 0 0 0 1.71-3L13.71 3.86a2 2 0 0 0-3.42 0z`}),(0,a.jsx)(`path`,{d:`M12 9v4`}),(0,a.jsx)(`path`,{d:`M12 17h.01`})]}):Vt(R)}),(0,a.jsxs)(`div`,{className:`att-meta`,children:[(0,a.jsx)(`span`,{className:`att-name`,children:R}),z>0&&(0,a.jsx)(`span`,{className:`att-size`,children:Bt(z)})]})]}),(0,a.jsxs)(`div`,{className:`att-tools`,children:[(0,a.jsxs)(`div`,{className:`att-download-status`,role:`status`,"aria-live":`polite`,"aria-atomic":`true`,children:[C===`loading`&&(0,a.jsxs)(`span`,{className:`att-download-status__content is-loading`,children:[(0,a.jsx)(`svg`,{className:`att-download-spinner`,width:`13`,height:`13`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,"aria-hidden":`true`,children:(0,a.jsx)(`path`,{strokeLinecap:`round`,d:`M12 2a10 10 0 1 0 10 10`})}),`正在准备`]}),C===`success`&&(0,a.jsxs)(`span`,{className:`att-download-status__content is-success`,children:[(0,a.jsx)(`svg`,{width:`13`,height:`13`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,"aria-hidden":`true`,children:(0,a.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`m5 12 4 4L19 6`})}),`已下载`]}),C===`error`&&(0,a.jsx)(`span`,{className:`att-download-status__content is-error`,children:`下载失败,请重试`})]}),(0,a.jsxs)(`div`,{className:`att-actions`,children:[L&&Ut(R)&&(0,a.jsx)(`button`,{type:`button`,className:`att-btn`,onMouseDown:e=>{e.preventDefault(),e.stopPropagation(),G()},title:e.o(`editor.attachment.preview`),"aria-label":e.o(`editor.attachment.preview`),children:(0,a.jsxs)(`svg`,{width:`14`,height:`14`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,"aria-hidden":`true`,children:[(0,a.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M2.036 12.322a1.012 1.012 0 010-.639C3.423 7.51 7.36 4.5 12 4.5c4.638 0 8.573 3.007 9.963 7.178.07.207.07.431 0 .639C20.577 16.49 16.64 19.5 12 19.5c-4.638 0-8.573-3.007-9.963-7.178z`}),(0,a.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M15 12a3 3 0 11-6 0 3 3 0 016 0z`})]})}),(0,a.jsx)(`button`,{type:`button`,className:`att-btn`,onClick:ce,disabled:x||V,title:x?`正在准备下载`:e.o(`editor.attachment.download`),"aria-label":x?`正在准备下载`:e.o(`editor.attachment.download`),children:(0,a.jsx)(`svg`,{width:`14`,height:`14`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,"aria-hidden":`true`,children:(0,a.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M4 16v1a3 3 0 003 3h10a3 3 0 003-3v-1m-4-4l-4 4m0 0l-4-4m4 4V4`})})}),l&&(0,a.jsx)(`button`,{type:`button`,className:`att-btn att-btn--del`,onClick:()=>{!l||Dt()||($(!0),M(!0))},title:e.o(`editor.attachment.delete`),"aria-label":e.o(`editor.attachment.delete`),children:(0,a.jsx)(`svg`,{width:`14`,height:`14`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,"aria-hidden":`true`,children:(0,a.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16`})})})]})]})]}),d&&(0,a.jsxs)(`div`,{ref:E,className:`att-preview-wrap ${F===`web`?`is-web-fs`:``}`,style:{position:`relative`,height:500,overflow:`hidden`,background:`#fff`},children:[(0,a.jsx)(`div`,{ref: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||ie)&&!p&&!h?(0,a.jsxs)(`div`,{className:`flex h-full flex-col items-center justify-center gap-2 p-6 text-center text-sm text-default-500`,children:[(0,a.jsx)(`div`,{className:`font-medium text-default-700`,children:`暂时无法预览此附件`}),(0,a.jsx)(`div`,{className:`max-w-md text-xs leading-relaxed`,children:`请稍后重试,或使用附件栏中的下载按钮。`})]}):(0,a.jsx)(i.Suspense,{fallback:(0,a.jsx)(`div`,{className:`flex items-center justify-center h-full text-default-400 text-sm`,style:{background:`#fff`},children:e.o(`editor.attachment.loadingPreview`)}),children:p||h||L?ne?(0,a.jsx)(Ft,{buffer:p||void 0,url:h||L,name:R,filename:R,type:B,size:z||p?.byteLength||0,options:oe},`${L}-${P}`):(0,a.jsx)(`div`,{className:`flex h-full items-center justify-center text-sm text-default-400`,children:`正在加载预览引擎...`}):(0,a.jsx)(`div`,{className:`flex h-full items-center justify-center text-sm text-default-400`,children:`正在加载...`})})}),(0,a.jsxs)(`div`,{className:`att-fs-controls__panel`,style:{position:`absolute`,top:8,right:8,zIndex:10,display:`flex`,gap:2,padding:4,background:`rgba(255,255,255,0.92)`,backdropFilter:`blur(8px)`,WebkitBackdropFilter:`blur(8px)`,borderRadius:8,boxShadow:`0 2px 8px rgba(0,0,0,0.12)`,border:`1px solid rgba(0,0,0,0.06)`},children:[(0,a.jsx)(`button`,{type:`button`,onClick:W,title:F===`web`?`退出网页全屏`:`网页全屏`,"aria-label":F===`web`?`退出网页全屏`:`网页全屏`,style:{width:28,height:28,borderRadius:6,border:`none`,background:F===`web`?`#e4e4e7`:`transparent`,cursor:`pointer`,display:`flex`,alignItems:`center`,justifyContent:`center`,color:`#52525b`,transition:`background 0.12s`},onMouseEnter:e=>{F!==`web`&&(e.currentTarget.style.background=`#f4f4f5`)},onMouseLeave:e=>{F!==`web`&&(e.currentTarget.style.background=`transparent`)},children:(0,a.jsx)(`svg`,{width:`14`,height:`14`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,"aria-hidden":`true`,children:(0,a.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M8 3H5a2 2 0 00-2 2v3m18 0V5a2 2 0 00-2-2h-3m0 18h3a2 2 0 002-2v-3M3 16v3a2 2 0 002 2h3`})})}),(0,a.jsx)(`button`,{type:`button`,onClick:se,title:F===`native`?`退出全屏`:`全屏`,"aria-label":F===`native`?`退出全屏`:`全屏`,style:{width:28,height:28,borderRadius:6,border:`none`,background:F===`native`?`#e4e4e7`:`transparent`,cursor:`pointer`,display:`flex`,alignItems:`center`,justifyContent:`center`,color:`#52525b`,transition:`background 0.12s`},onMouseEnter:e=>{F!==`native`&&(e.currentTarget.style.background=`#f4f4f5`)},onMouseLeave:e=>{F!==`native`&&(e.currentTarget.style.background=`transparent`)},children:(0,a.jsx)(`svg`,{width:`14`,height:`14`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,"aria-hidden":`true`,children:(0,a.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M15 3h6v6M9 21H3v-6M21 3l-7 7M3 21l7-7`})})})]})]})]}),(0,a.jsx)(Mt,{open:ee,title:`确认删除附件`,message:V?`此操作将删除该附件节点,不可撤销。`:`此操作将同时删除对象存储中的文件(${R}),不可撤销。`,onCancel:()=>{$(!1),M(!1)},onConfirm:async()=>{try{if(s){let e=N.current,t=e?.from??s.state.selection.from,n=e?.to??s.state.selection.to,r=[];s.state.doc.nodesBetween(t,n,e=>{e.type.name===`attachmentEmbed`&&e.attrs?.src&&r.push(nt(e.attrs.src))}),await Promise.all(r),$(!1),await new Promise(e=>setTimeout(e,300)),s.chain().focus().setTextSelection({from:t,to:n}).deleteSelection().run()}else await nt(L),$(!1),await new Promise(e=>setTimeout(e,300)),r()}catch{$(!1)}}})]})}var Yt=d.Node.create({name:`attachmentEmbed`,group:`block`,atom:!0,inline:!1,addNodeView(){return(0,c.ReactNodeViewRenderer)(Jt)},addAttributes(){return{src:{default:null,parseHTML:e=>e.getAttribute(`data-src`)||e.querySelector(`a`)?.getAttribute(`href`)},name:{default:``,parseHTML:e=>e.getAttribute(`data-name`)||e.querySelector(`a`)?.getAttribute(`download`)||``},size:{default:0,parseHTML:e=>Number(e.getAttribute(`data-size`)||0)},type:{default:``,parseHTML:e=>e.getAttribute(`data-type`)||``}}},parseHTML(){return[{tag:`div[data-attachment-embed]`}]},renderHTML({HTMLAttributes:e}){return[`div`,{"data-attachment-embed":`true`,"data-src":e.src,"data-name":e.name,"data-size":e.size||0,"data-type":e.type||``,class:`attachment-embed`},[`a`,{href:e.src,download:e.name},`📎 ${e.name||`attachment`}`]]}});function Xt({node:e,deleteNode:n,editor:r}){let o=e.attrs.src||``,s=e.attrs.name||o.split(`/`).pop()?.split(`?`)[0]||`audio`,[l,u]=(0,i.useState)(!1),d=r?.isEditable??!0;(0,i.useEffect)(()=>()=>{o.startsWith(`blob:`)&&URL.revokeObjectURL(o)},[o]);let f=!!o&&(o.startsWith(`blob:`)||o.startsWith(`data:`)),[p,m]=(0,i.useState)(f?o:null),[h,g]=(0,i.useState)(f),_=(0,i.useRef)(null);return(0,i.useEffect)(()=>{if(!o){m(null),g(!1);return}if(o.startsWith(`blob:`)||o.startsWith(`data:`)){m(o),g(!0);return}let e=!1;return g(!1),(async()=>{let n=o;try{let e=await t.r(o);if(e){let t=await fetch(o,{headers:e});if(t.ok){let e=URL.createObjectURL(await t.blob());_.current&&URL.revokeObjectURL(_.current),_.current=e,n=e}}}catch{}e||(m(n),g(!0))})(),()=>{e=!0,_.current&&=(URL.revokeObjectURL(_.current),null)}},[o]),(0,a.jsxs)(c.NodeViewWrapper,{as:`div`,className:`audio-embed group/audio`,style:{margin:`1rem 0`},contentEditable:!1,children:[(0,a.jsxs)(`div`,{className:`audio-embed-inner`,children:[(0,a.jsxs)(`div`,{className:`audio-embed-header`,children:[(0,a.jsxs)(`div`,{className:`audio-embed-title`,children:[(0,a.jsx)(`svg`,{className:`audio-embed-icon`,width:`16`,height:`16`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,children:(0,a.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M9 19V6l12-3v13M9 19c0 1.105-1.343 2-3 2s-3-.895-3-2 1.343-2 3-2 3 .895 3 2zm12-3c0 1.105-1.343 2-3 2s-3-.895-3-2 1.343-2 3-2 3 .895 3 2zM9 10l12-3`})}),(0,a.jsx)(`span`,{className:`audio-embed-filename`,children:s})]}),(0,a.jsx)(`div`,{className:`audio-embed-actions`,children:d&&(0,a.jsx)(`button`,{type:`button`,className:`audio-embed-btn audio-embed-btn--del`,onClick:()=>{Dt()||($(!0),u(!0))},title:`删除`,children:(0,a.jsx)(`svg`,{width:`12`,height:`12`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,children:(0,a.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16`})})})})]}),(0,a.jsx)(`div`,{className:`audio-embed-player`,children:o?h&&p?(0,a.jsx)(`audio`,{src:p,controls:!0,style:{width:`100%`},onError:async e=>{let n=e.currentTarget;try{let e=await t.r(o),r=await fetch(o,e?{headers:e}:{});if(r.ok){let e=await r.blob();n.src.startsWith(`blob:`)&&URL.revokeObjectURL(n.src),n.src=URL.createObjectURL(e)}}catch{}}}):(0,a.jsxs)(`div`,{className:`audio-embed-loading`,children:[(0,a.jsx)(`span`,{className:`audio-embed-spinner`}),`音频加载中…`]}):(0,a.jsxs)(`div`,{className:`audio-embed-loading audio-embed-missing`,children:[(0,a.jsx)(`span`,{className:`audio-embed-missing-icon`,"aria-hidden":`true`,children:`!`}),`音频文件缺失`]})})]}),(0,a.jsx)(Mt,{open:l,title:`确认删除音频`,message:`此操作将同时删除对象存储中的文件(${s}),不可撤销。`,onCancel:()=>{$(!1),u(!1)},onConfirm:async()=>{try{await nt(o)}catch{}$(!1),await new Promise(e=>setTimeout(e,300)),n()}})]})}function Zt(e){return/\.(mp3|wav|ogg|flac|aac|m4a|wma|opus)(\?|$)/i.test(e)||/\/.*\.(mp3|wav|ogg|flac)/i.test(e)}var Qt=d.Node.create({name:`audioEmbed`,group:`block`,atom:!0,inline:!1,addNodeView(){return(0,c.ReactNodeViewRenderer)(Xt)},addProseMirrorPlugins(){return[new f.Plugin({props:{handlePaste(e,t){let n=t.clipboardData?.getData(`text/plain`);if(!n)return!1;let r=n.split(/\r?\n/);for(let n of r){let r=n.trim();if(!r||r.includes(` `)||!Zt(r))continue;t.preventDefault();let i=e.state.schema.nodes.audioEmbed.create({src:r});return e.dispatch(e.state.tr.replaceSelectionWith(i)),!0}return!1}}})]},addAttributes(){return{src:{default:null},name:{default:``},size:{default:0,parseHTML:e=>Number(e.getAttribute(`data-size`)||0)}}},parseHTML(){return[{tag:`div[data-audio-embed]`,getAttrs:e=>{let t=e,n=t.getAttribute(`src`)||t.getAttribute(`data-src`)||t.querySelector(`audio`)?.getAttribute(`src`)||null;return n?{src:n}:null}},{tag:`audio[src]`}]},renderHTML({HTMLAttributes:e}){return[`div`,{"data-audio-embed":`true`,src:e.src,"data-src":e.src,"data-size":e.size||0,class:`audio-embed`},[`audio`,{src:e.src,controls:`true`,style:`width:100%;`}]]}});function $t(e){return e?/bilibili\.com|BV[a-zA-Z0-9]{10}|av\d+/i.test(e)?`bilibili`:/xiaohongshu\.com|xhslink\.com/i.test(e)?`xiaohongshu`:/\.(mp4|m3u8|webm|ogg|flv|mkv|mov|avi|wmv|ts|m4v|3gp|f4v|rmvb)(\?|$)/i.test(e)||/\/.*\.(mp4|m3u8|mov|webm|flv|mkv)/i.test(e)?`direct`:`unknown`:`unknown`}function en(e){let t=e.match(/BV[a-zA-Z0-9]{10}/);if(t)return t[0];let n=e.match(/av(\d+)/i);return n?n[0]:e}function tn({node:e,deleteNode:t,editor:n}){let r=e.attrs.src||``,o=e.attrs.source||`unknown`,s=o===`unknown`?$t(r):o,[l,u]=(0,i.useState)(!1),[d,f]=(0,i.useState)(!1),[p,m]=(0,i.useState)(!1),h=n?.isEditable??!0,g=!h&&r.startsWith(`blob:`),_=(0,a.jsx)(Mt,{open:l,title:`确认删除视频`,message:`此操作将同时删除对象存储中的文件,不可撤销。`,onCancel:()=>{$(!1),u(!1)},onConfirm:async()=>{try{await nt(r)}catch{}$(!1),await new Promise(e=>setTimeout(e,300)),t()}}),[v,y]=(0,i.useState)(``),b=(0,i.useRef)(null),x=(0,i.useRef)(null),S=(0,i.useRef)(null),C=(0,i.useRef)(null),w=(0,i.useRef)(null),T=(0,i.useRef)(0),E=(0,i.useCallback)(()=>{let e=S.current;e&&(e.style.position=``,e.style.inset=``,e.style.zIndex=``,e.style.borderRadius=``,document.body.style.overflow=``)},[]),D=(0,i.useCallback)(()=>{document.fullscreenElement&&document.exitFullscreen?.(),E()},[E]),O=(0,i.useCallback)(()=>{let e=S.current;e&&(e.style.position===`fixed`?E():(e.style.position=`fixed`,e.style.inset=`0`,e.style.zIndex=`99999`,e.style.borderRadius=`0`,document.body.style.overflow=`hidden`))},[E]),k=(0,i.useCallback)(()=>{T.current=window.scrollY,C.current?.requestFullscreen?.()},[]),A=(0,i.useCallback)(()=>{let e=x.current?.closest(`.video-embed--direct`)||x.current;e&&(T.current=window.scrollY,e.requestFullscreen?.())},[]);if((0,i.useEffect)(()=>{let e=()=>{document.fullscreenElement||requestAnimationFrame(()=>window.scrollTo(0,T.current))};return document.addEventListener(`fullscreenchange`,e),()=>document.removeEventListener(`fullscreenchange`,e)},[]),(0,i.useEffect)(()=>{if(s!==`direct`||!r){y(``);return}let e=!1;return f(!0),(async()=>{try{if(r.includes(`?X-Amz-`)||r.startsWith(`blob:`)||r.startsWith(`data:`)){y(r);return}let{signPreviewUrlHeaders:t}=await Promise.resolve().then(()=>require("./signed-fetch-DiWXujJ1.cjs")).then(e=>e.i),n=await t(r);if(!n){y(r);return}let i=await fetch(r,{headers:n});if(!i.ok){y(r);return}let a=URL.createObjectURL(await i.blob());if(e){URL.revokeObjectURL(a);return}w.current&&URL.revokeObjectURL(w.current),w.current=a,y(a)}catch{e||y(r)}})(),()=>{e=!0,w.current&&=(URL.revokeObjectURL(w.current),null)}},[s,r]),(0,i.useEffect)(()=>{if(s!==`direct`||!v)return;let e=!1;f(!0),m(!1);let t=x.current,n=t=>{let n=t.target;n?.error&&n.error.code===4&&!e&&m(!0)};return t?.addEventListener(`error`,n,!0),(async()=>{if(t)try{let[{default:n}]=await Promise.all([import(`xgplayer`)]);if(e||!x.current)return;b.current?.destroy(),t.replaceChildren(),b.current=new n({el:t,url:v,width:`100%`,height:450,fluid:!0,fitVideoSize:`fixWidth`,autoplay:!1,controls:!0,ignores:[`fullscreen`],playbackRate:[.5,.75,1,1.25,1.5,2],lang:`zh-cn`}),t.__xgplayer=b.current;let r=()=>{e||f(!1)};try{b.current?.once?.(`loadeddata`,r),b.current?.once?.(`canplay`,r)}catch{}window.setTimeout(r,2500)}catch{}})(),()=>{e=!0,t?.removeEventListener(`error`,n,!0),f(!1),b.current?.destroy(),b.current=null,x.current&&(x.current.__xgplayer=null)}},[s,v]),(0,i.useEffect)(()=>{p&&(b.current?.destroy(),b.current=null)},[p]),s===`bilibili`){let e=en(r);return(0,a.jsxs)(c.NodeViewWrapper,{as:`div`,className:`video-embed video-embed--bilibili group/video`,style:{margin:`1rem 0`},contentEditable:!1,children:[(0,a.jsxs)(`div`,{ref: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:()=>{Dt()||($(!0),u(!0))},children:(0,a.jsx)(`svg`,{width:`12`,height:`12`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,children:(0,a.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16`})})})]}),(0,a.jsx)(`div`,{style:{position:`relative`,paddingTop:`56.25%`},children:(0,a.jsx)(`iframe`,{ref: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:()=>{Dt()||($(!0),u(!0))},children:(0,a.jsx)(`svg`,{width:`12`,height:`12`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,children:(0,a.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16`})})}),(0,a.jsx)(`button`,{type:`button`,className:`video-fs-btn`,title:`全屏`,onClick: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 nn(e){return/bilibili\.com|BV[a-zA-Z0-9]{10}|av\d+/i.test(e)?`bilibili`:/xiaohongshu\.com|xhslink\.com/i.test(e)?`xiaohongshu`:/\.(mp4|m3u8|webm|ogg|flv|mkv|mov|avi|wmv|ts|m4v|3gp|f4v|rmvb)(\?|$)/i.test(e)||/\/.*\.(mp4|m3u8|mov|webm|flv|mkv)/i.test(e)?`direct`:`unknown`}function rn(e){let t=e.match(/BV[a-zA-Z0-9]{10}/);if(t)return t[0];let n=e.match(/av(\d+)/i);return n?n[0]:e}function an(e){let t=e.match(/explore\/([a-zA-Z0-9]+)/);return t?t[1]:e}var on=d.Node.create({name:`videoEmbed`,group:`block`,atom:!0,inline:!1,addNodeView(){return(0,c.ReactNodeViewRenderer)(tn)},addProseMirrorPlugins(){return[new f.Plugin({props:{handleKeyDown(e,t){if(t.key!==` `)return!1;let n=e.state.selection;if(n instanceof f.NodeSelection&&n.node.type.name===`videoEmbed`){t.preventDefault();let r=e.nodeDOM(n.from);if(r){let e=r.querySelector(`div`)?.__xgplayer;e&&(e.paused?e.play():e.pause())}return!0}return!1},handlePaste(e,t){let n=t.clipboardData?.getData(`text/plain`);if(!n)return!1;let r=n.split(/\r?\n/);for(let n of r){let r=n.trim();if(!r||r.includes(` `))continue;let i=nn(r);if(i===`unknown`)continue;t.preventDefault();let a=e.state.schema.nodes.videoEmbed.create({src:r,source:i}),o=e.state.tr.replaceSelectionWith(a);return e.dispatch(o),!0}return!1}}})]},addAttributes(){return{src:{default:null},source:{default:`unknown`},name:{default:``},size:{default:0,parseHTML:e=>Number(e.getAttribute(`data-size`)||0)}}},parseHTML(){return[{tag:`div[data-video-embed]`,getAttrs:e=>{let t=e,n=t.getAttribute(`src`)||t.getAttribute(`data-src`)||``;return{src:n,source:nn(n)}}},{tag:`div[data-bilibili]`},{tag:`div[data-xiaohongshu]`}]},renderHTML({HTMLAttributes:e}){let t=e.src||``,n=nn(t);if(n===`bilibili`){let e=rn(t);return[`div`,{"data-video-embed":`bilibili`,src:t,"data-bvid":e,class:`video-embed video-embed--bilibili`,style:`margin: 1rem 0; border-radius: 12px; overflow: hidden;`},[`iframe`,{src:`https://player.bilibili.com/player.html?bvid=${e}&page=1&high_quality=1`,width:`100%`,height:`400`,frameborder:`0`,allowfullscreen:`true`,scrolling:`no`,style:`border: none; display: block;`}]]}if(n===`xiaohongshu`)return an(t),[`div`,{"data-video-embed":`xiaohongshu`,src:t,class:`video-embed video-embed--xiaohongshu`,style:`border: 1px solid #e5e7eb; border-radius: 12px; padding: 16px; display: flex; align-items: center; gap: 12px; max-width: 480px; margin: 1rem 0;`},[`div`,{style:`width:40px;height:40px;background:#ff2442;border-radius:10px;display:flex;align-items:center;justify-content:center;color:#fff;font-weight:bold;font-size:14px;flex-shrink:0;`},`红`],[`div`,{},[`div`,{style:`font-weight:600;font-size:14px;`},`小红书笔记`],[`a`,{href:t,target:`_blank`,rel:`noopener noreferrer`,style:`color:#ff2442;font-size:12px;text-decoration:none;`},`在小红书中打开 →`]]];let r=`xgplayer-${Math.random().toString(36).slice(2,8)}`;return[`div`,{"data-video-embed":`direct`,src:t,"data-player-id":r,"data-size":e.size||0,class:`video-embed video-embed--direct`,style:`margin: 1rem 0; border-radius: 12px; overflow: hidden; background: #000;`},[`div`,{id:r,style:`width:100%;max-width:720px;`}]]},addCommands(){return{insertVideo:e=>({chain:t})=>{let n=nn(e.src);return t().insertContent({type:this.name,attrs:{...e,source:n}}).focus().run()}}}}),sn=null;async function cn(e){sn||=await import(`beautiful-mermaid`);let t=sn.renderMermaidSVG;return t(e)}var ln=[{value:`javascript`,label:`JavaScript`,deviconClass:`devicon-javascript-plain`,color:`#f0db4f`},{value:`typescript`,label:`TypeScript`,deviconClass:`devicon-typescript-plain`,color:`#3178c6`},{value:`python`,label:`Python`,deviconClass:`devicon-python-plain`,color:`#306998`},{value:`java`,label:`Java`,deviconClass:`devicon-java-plain`,color:`#b07219`},{value:`go`,label:`Go`,deviconClass:`devicon-go-plain`,color:`#00add8`},{value:`rust`,label:`Rust`,deviconClass:`devicon-rust-plain`,color:`#dea584`},{value:`c`,label:`C`,deviconClass:`devicon-c-plain`,color:`#555555`},{value:`cpp`,label:`C++`,deviconClass:`devicon-cplusplus-plain`,color:`#f34b7d`},{value:`csharp`,label:`C#`,deviconClass:`devicon-csharp-plain`,color:`#178600`},{value:`html`,label:`HTML`,deviconClass:`devicon-html5-plain`,color:`#e34c26`},{value:`css`,label:`CSS`,deviconClass:`devicon-css3-plain`,color:`#563d7c`},{value:`json`,label:`JSON`,deviconClass:`devicon-json-plain`,color:`#292929`},{value:`sql`,label:`SQL`,deviconClass:`devicon-mysql-plain`,color:`#00758f`},{value:`bash`,label:`Bash`,deviconClass:`devicon-bash-plain`,color:`#3dbb58`},{value:`sh`,label:`Shell (sh)`,deviconClass:`devicon-bash-plain`,color:`#3dbb58`},{value:`shell`,label:`PowerShell`,deviconClass:`devicon-powershell-plain`,color:`#3dbb58`},{value:`yaml`,label:`YAML`,deviconClass:`devicon-yaml-plain`,color:`#cb171e`},{value:`php`,label:`PHP`,deviconClass:`devicon-php-plain`,color:`#4f5d95`},{value:`ruby`,label:`Ruby`,deviconClass:`devicon-ruby-plain`,color:`#701516`},{value:`swift`,label:`Swift`,deviconClass:`devicon-swift-plain`,color:`#f05138`},{value:`kotlin`,label:`Kotlin`,deviconClass:`devicon-kotlin-plain`,color:`#a97bff`},{value:`dockerfile`,label:`Dockerfile`,deviconClass:`devicon-docker-plain`,color:`#0db7ed`},{value:`vue`,label:`Vue`,deviconClass:`devicon-vuejs-plain`,color:`#42b883`},{value:`react`,label:`React`,deviconClass:`devicon-react-plain`,color:`#61dafb`},{value:`markdown`,label:`Markdown`,deviconClass:`devicon-markdown-plain`,color:`#083fa1`},{value:`mermaid`,label:`Mermaid`,color:`#ff3670`},{value:`txt`,label:`Plain Text`,color:`#6b7280`}],un={javascript:`js`,typescript:`ts`,python:`py`,java:`java`,go:`go`,rust:`rs`,c:`c`,cpp:`cpp`,csharp:`cs`,html:`html`,css:`css`,json:`json`,sql:`sql`,bash:`sh`,shell:`sh`,yaml:`yml`,php:`php`,ruby:`rb`,swift:`swift`,kotlin:`kt`,dockerfile:``,markdown:`md`,txt:`txt`,vue:`vue`,react:`jsx`},dn={js:`javascript`,ts:`typescript`,py:`python`,rb:`ruby`,rs:`rust`,kt:`kotlin`,cs:`csharp`,"c++":`cpp`,"c#":`csharp`,golang:`go`,yml:`yaml`,ps1:`shell`,jsx:`javascript`,tsx:`typescript`};function fn(e){return e instanceof Element&&!!e.closest(`.cb-code-area`)}function pn({node:t,updateAttributes:n,editor:r,getPos:o,deleteNode:s,selected:l}){let u=r?.isEditable??!0,d=!u,[f,p]=(0,i.useState)(!1),[m,h]=(0,i.useState)(!1),[g,_]=(0,i.useState)(!1),[v,y]=(0,i.useState)(``),[b,x]=(0,i.useState)(!1),[S,C]=(0,i.useState)(null),[w,T]=(0,i.useState)(null),[E,D]=(0,i.useState)(!1),[O,k]=(0,i.useState)([]),A=(0,i.useRef)(null),j=(0,i.useRef)(null),ee=(0,i.useRef)(null),M=(0,i.useRef)(null),N=(0,i.useRef)(null),P=t.attrs.language||``,te=ln.find(e=>e.value===(dn[P]??P)),F=P===`mermaid`,I=(0,i.useCallback)(e=>{fn(e.target)||e.stopPropagation()},[]),ne=(0,i.useCallback)(()=>{if(!r||typeof o!=`function`)return null;let e=o();return typeof e==`number`?{from:e,to:e+t.nodeSize}:null},[r,o,t.nodeSize]),re=(0,i.useCallback)(()=>{u&&(Dt()||(N.current=ne(),window.getSelection()?.removeAllRanges(),$(!0),x(!0)))},[ne,u]),ie=(0,i.useMemo)(()=>t.textContent?t.textContent.split(`
4
4
  `):[``],[t.textContent]),ae=ie.length,L=(0,i.useMemo)(()=>Array.from({length:ae},(e,t)=>t+1),[ae]),R=(0,i.useMemo)(()=>{let e=v.trim().toLowerCase();return e?ln.filter(t=>t.label.toLowerCase().includes(e)||t.value.toLowerCase().includes(e)):ln},[v]);(0,i.useEffect)(()=>{g&&(y(``),setTimeout(()=>j.current?.focus(),50))},[g]),(0,i.useEffect)(()=>{if(!g)return;let e=e=>{A.current&&!A.current.contains(e.target)&&_(!1)};return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[g]),(0,i.useEffect)(()=>{if(!g)return;let e=e=>{e.key===`Escape`&&_(!1)};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[g]),(0,i.useEffect)(()=>{let e=e=>{if(!(e.key!==`Backspace`&&e.key!==`Delete`)&&u&&l&&!Dt()){if(e.preventDefault(),e.stopPropagation(),r){let{from:e,to:t}=r.state.selection;N.current={from:e,to:t}}window.getSelection()?.removeAllRanges(),$(!0),x(!0)}};return window.addEventListener(`keydown`,e,!0),()=>window.removeEventListener(`keydown`,e,!0)},[l,r,u]);let z=(0,i.useCallback)(e=>{k(t=>t.length===e.length&&t.every((t,n)=>t===e[n])?t:e)},[]),B=(0,i.useCallback)(()=>{let e=ee.current,t=M.current;if(!e||!t)return;t.style.width=`${e.clientWidth}px`;let n=t.children,r=Array(n.length);for(let e=0;e<n.length;e++)r[e]=n[e].offsetHeight;z(r)},[z]);(0,i.useLayoutEffect)(()=>{B()},[B,ie]),(0,i.useEffect)(()=>{let e=ee.current;if(!e)return;let t=new ResizeObserver(()=>B());return t.observe(e),window.addEventListener(`resize`,B),document.fonts?.ready?.then(()=>B()),()=>{t.disconnect(),window.removeEventListener(`resize`,B)}},[B]);let V=(0,i.useCallback)(e=>{n({language:e||null}),_(!1)},[n]),oe=(0,i.useCallback)(()=>{if(u){if(r&&o){let e=o();r.chain().focus().setNodeSelection(e).run()}_(!1),(r?.storage?.qingwuUI)?.openAI?.()}},[r,o,u]),H=(0,i.useCallback)(()=>{navigator.clipboard.writeText(t.textContent),p(!0),setTimeout(()=>p(!1),1500)},[t.textContent]),U=(0,i.useCallback)(()=>{let e=un[P]||`txt`,n=e?`code.${e}`:`code.txt`,r=new Blob([t.textContent],{type:`text/plain;charset=utf-8`}),i=URL.createObjectURL(r),a=document.createElement(`a`);a.href=i,a.download=n,document.body.appendChild(a),a.click(),document.body.removeChild(a),URL.revokeObjectURL(i)},[t.textContent,P]),W=(0,i.useCallback)(async()=>{if(S||E){C(null),T(null),D(!1);return}D(!0),T(null),C(null);try{let n=(t.textContent||``).trim();if(!n){T(`代码块内容为空`);return}let r=e.r(await cn(n));C(r)}catch(e){T(e instanceof Error?e.message:`Mermaid 渲染失败`)}finally{D(!1)}},[t.textContent,S,E]),se=(0,a.jsxs)(a.Fragment,{children:[te?te.deviconClass?(0,a.jsx)(`i`,{className:`${te.deviconClass} colored cb-lang-icon`,style:{color:te.color}}):(0,a.jsx)(`span`,{className:`cb-lang-icon cb-lang-icon--auto`,children:`Tx`}):(0,a.jsx)(`span`,{className:`cb-lang-icon cb-lang-icon--auto`,children:`?`}),(0,a.jsx)(`span`,{className:`cb-lang-label`,children:te?.label||`自动`})]});return(0,a.jsxs)(c.NodeViewWrapper,{as:`div`,className:`code-block-node-view group/cb`,onMouseDown:I,onTouchStart:I,children:[(0,a.jsxs)(`div`,{className:`cb-header`,contentEditable:!1,children:[(0,a.jsxs)(`div`,{className:`cb-lang-wrap`,ref:A,contentEditable:!1,children:[d?(0,a.jsx)(`span`,{className:`cb-lang-trigger cb-lang-trigger--static`,children:se}):(0,a.jsxs)(`button`,{type:`button`,className:`cb-lang-trigger`,onClick:()=>_(!g),children:[se,(0,a.jsx)(`svg`,{className:`cb-lang-chevron${g?` cb-lang-chevron--open`:``}`,width:`10`,height:`10`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2.5`,children:(0,a.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M6 9l6 6 6-6`})})]}),u&&g&&(0,a.jsxs)(`div`,{className:`cb-lang-dropdown`,children:[(0,a.jsxs)(`div`,{className:`cb-lang-search-wrap`,children:[(0,a.jsx)(`svg`,{className:`cb-lang-search-icon`,width:`14`,height:`14`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,children:(0,a.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M21 21l-6-6m2-5a7 7 0 11-14 0 7 7 0 0114 0z`})}),(0,a.jsx)(`input`,{ref:j,className:`cb-lang-search`,type:`text`,placeholder:`搜索语言...`,value:v,onChange:e=>y(e.target.value),onKeyDown:e=>e.stopPropagation()})]}),(0,a.jsxs)(`div`,{className:`cb-lang-list`,children:[(0,a.jsxs)(`button`,{type:`button`,className:`cb-lang-option${P?``:` cb-lang-option--active`}`,onClick:()=>V(``),children:[(0,a.jsx)(`span`,{className:`cb-lang-icon cb-lang-icon--auto`,children:`?`}),(0,a.jsx)(`span`,{children:`自动检测`})]}),R.map(e=>(0,a.jsxs)(`button`,{type:`button`,className:`cb-lang-option${P===e.value?` cb-lang-option--active`:``}`,onClick:()=>V(e.value),children:[e.deviconClass?(0,a.jsx)(`i`,{className:`${e.deviconClass} colored cb-lang-icon`,style:{color:e.color}}):(0,a.jsx)(`span`,{className:`cb-lang-icon cb-lang-icon--auto`,children:`Tx`}),(0,a.jsx)(`span`,{children:e.label})]},e.value)),R.length===0&&(0,a.jsx)(`div`,{className:`cb-lang-empty`,children:`无匹配语言`})]})]})]}),(0,a.jsxs)(`div`,{className:`cb-actions`,children:[(0,a.jsx)(`button`,{type:`button`,className:`cb-btn`,onClick:()=>h(!m),contentEditable:!1,title:m?`展开`:`折叠`,children:(0,a.jsx)(`svg`,{className:`cb-btn-icon`,fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,strokeWidth:`2`,children:m?(0,a.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M6 9l6 6 6-6`}):(0,a.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M6 15l6-6 6 6`})})}),(0,a.jsx)(`button`,{type:`button`,className:`cb-btn`,onClick:H,contentEditable:!1,title:`复制`,children:f?(0,a.jsx)(`svg`,{className:`cb-btn-icon cb-btn-icon--check`,fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,strokeWidth:`2.5`,children:(0,a.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M5 13l4 4L19 7`})}):(0,a.jsx)(`svg`,{className:`cb-btn-icon`,fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,strokeWidth:`2`,children:(0,a.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M8 16H6a2 2 0 01-2-2V6a2 2 0 012-2h8a2 2 0 012 2v2m-6 12h8a2 2 0 002-2v-8a2 2 0 00-2-2h-8a2 2 0 00-2 2v8a2 2 0 002 2z`})})}),(0,a.jsx)(`button`,{type:`button`,className:`cb-btn`,onClick:U,contentEditable:!1,title:`下载`,children:(0,a.jsx)(`svg`,{className:`cb-btn-icon`,fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,strokeWidth:`2`,children:(0,a.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M4 16v1a3 3 0 003 3h10a3 3 0 003-3v-1m-4-4l-4 4m0 0l-4-4m4 4V4`})})}),u&&(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(`button`,{type:`button`,className:`cb-btn cb-btn--ai`,onClick:oe,contentEditable:!1,title:`写作助手`,children:(0,a.jsx)(`svg`,{className:`cb-btn-icon`,fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,strokeWidth:`2`,children:(0,a.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M13 10V3L4 14h7v7l9-11h-7z`})})}),(0,a.jsx)(`button`,{type:`button`,className:`cb-btn cb-btn--del`,onClick:re,contentEditable:!1,title:`删除代码块`,children:(0,a.jsx)(`svg`,{className:`cb-btn-icon`,fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,strokeWidth:`2`,children:(0,a.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16`})})})]}),F&&(0,a.jsx)(`button`,{type:`button`,className:`cb-btn cb-btn--diagram`,onClick:W,contentEditable:!1,title:S||E?`取消渲染`:`渲染图表`,disabled:E,children:(0,a.jsx)(`svg`,{className:`cb-btn-icon`,fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,strokeWidth:`2`,children:(0,a.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M4 5a1 1 0 011-1h4a1 1 0 011 1v5a1 1 0 01-1 1H5a1 1 0 01-1-1V5zM14 5a1 1 0 011-1h4a1 1 0 011 1v2a1 1 0 01-1 1h-4a1 1 0 01-1-1V5zM4 16a1 1 0 011-1h4a1 1 0 011 1v3a1 1 0 01-1 1H5a1 1 0 01-1-1v-3zM14 13a1 1 0 011-1h4a1 1 0 011 1v6a1 1 0 01-1 1h-4a1 1 0 01-1-1v-6z`})})})]})]}),(0,a.jsxs)(`div`,{className:`cb-code-area${m?` cb-code-area--collapsed`:``}`,children:[(0,a.jsx)(`div`,{className:`cb-line-numbers`,contentEditable:!1,"aria-hidden":`true`,children:L.map((e,t)=>(0,a.jsx)(`span`,{className:`cb-line-num`,style:O[t]?{height:O[t]}:void 0,children:e},e))}),(0,a.jsx)(`pre`,{className:`cb-code-pre`,ref:ee,children:(0,a.jsx)(c.NodeViewContent,{as:`code`})}),(0,a.jsx)(`div`,{ref:M,className:`cb-code-mirror`,contentEditable:!1,"aria-hidden":`true`,children:ie.map((e,t)=>(0,a.jsx)(`span`,{className:`cb-mirror-line`,children:e.length?e:`\xA0`},t))})]}),(S||w||E)&&(0,a.jsxs)(`div`,{className:`cb-diagram-output`,contentEditable:!1,children:[E&&(0,a.jsx)(`div`,{className:`cb-diagram-loading`,children:`渲染图表中…`}),w&&(0,a.jsxs)(`div`,{className:`cb-diagram-error`,children:[(0,a.jsx)(`span`,{className:`cb-diagram-error-icon`,children:`!`}),w]}),S&&(0,a.jsx)(`div`,{className:`cb-diagram-svg`,dangerouslySetInnerHTML:{__html:S}})]}),(0,a.jsx)(Mt,{open:b,title:`确认删除代码块`,message:`此操作不可撤销。`,onCancel:()=>{$(!1),x(!1)},onConfirm:async()=>{if(await new Promise(e=>setTimeout(e,300)),$(!1),r){let e=N.current??ne();e?r.chain().focus().setTextSelection(e).deleteSelection().run():s()}else s()}})]})}var mn=[{value:`javascript`,label:`JavaScript`},{value:`typescript`,label:`TypeScript`},{value:`python`,label:`Python`},{value:`java`,label:`Java`},{value:`go`,label:`Go`},{value:`rust`,label:`Rust`},{value:`c`,label:`C`},{value:`cpp`,label:`C++`},{value:`csharp`,label:`C#`},{value:`html`,label:`HTML/XML`},{value:`css`,label:`CSS`},{value:`json`,label:`JSON`},{value:`sql`,label:`SQL`},{value:`bash`,label:`Bash`},{value:`shell`,label:`Shell`},{value:`yaml`,label:`YAML`},{value:`php`,label:`PHP`},{value:`ruby`,label:`Ruby`},{value:`swift`,label:`Swift`},{value:`kotlin`,label:`Kotlin`},{value:`dockerfile`,label:`Dockerfile`},{value:`vue`,label:`Vue`},{value:`react`,label:`React`},{value:`markdown`,label:`Markdown`},{value:`mermaid`,label:`Mermaid`}],hn=(0,M.createLowlight)(M.common);hn.register({dockerfile:ee.default}),hn.registerAlias(`xml`,[`vue`,`html`]),hn.registerAlias(`javascript`,[`react`,`jsx`]),hn.registerAlias(`typescript`,[`tsx`]);var gn=j.CodeBlockLowlight.extend({addNodeView(){return(0,c.ReactNodeViewRenderer)(pn)}}).configure({lowlight:hn});function _n(e){return new Promise(t=>{let n=document.createElement(`div`);n.className=`fixed inset-0 z-[10001] flex items-center justify-center bg-black/40 backdrop-blur-sm select-none`;let r=document.createElement(`div`);r.className=`bg-white dark:bg-zinc-800 rounded-xl p-6 shadow-xl max-w-sm w-full mx-4 border border-default-200 relative overflow-hidden`;let i=document.createElement(`div`);i.className=`text-sm font-medium text-default-800 dark:text-zinc-100 mb-2`,i.textContent=`导入 Markdown`;let a=document.createElement(`div`);a.className=`text-xs text-default-500 dark:text-zinc-400 mb-4 whitespace-pre-line`,a.textContent=`将 "${e}" 渲染到编辑器,还是作为附件附加?`;let o=document.createElement(`div`);o.className=`flex justify-end gap-2`;let s=e=>{document.removeEventListener(`keydown`,c),n.remove(),t(e)},c=e=>{e.key===`Escape`&&s(null)};n.addEventListener(`mousedown`,e=>{e.target===n&&s(null)});let l=document.createElement(`button`);l.type=`button`,l.className=`px-3 py-1.5 text-xs rounded-lg border border-default-200 hover:bg-default-100 transition-colors`,l.textContent=`取消`,l.addEventListener(`click`,()=>s(null));let u=document.createElement(`button`);u.type=`button`,u.className=`px-3 py-1.5 text-xs rounded-lg border border-default-200 hover:bg-default-100 transition-colors`,u.textContent=`附加`,u.addEventListener(`click`,()=>s(`attach`));let d=document.createElement(`button`);d.type=`button`,d.className=`px-3 py-1.5 text-xs rounded-lg bg-blue-500 hover:bg-blue-600 text-white transition-colors`,d.textContent=`渲染`,d.addEventListener(`click`,()=>s(`render`)),o.append(l,u,d),r.append(i,a,o),n.appendChild(r),document.addEventListener(`keydown`,c),document.body.appendChild(n)})}var vn=/\.(png|jpe?g|gif|webp|bmp|svg|avif|mp4|m4v|webm|ogg|mov|avi|mkv|mp3|wav|flac|m4a|aac|opus|pdf|docx?|xlsx?|pptx?|odt|rtf|txt|md|csv|zip|rar|7z|json)(\?|#|$)/i,yn=/^(?:mailto:|tel:|javascript:|about:|data:|blob:)/i;function bn(e){if(!e)return!1;let t=e.trim();return!(!t||/^(?:https?:)?\/\//i.test(t)||yn.test(t)||t.startsWith(`#`))}function xn(e){return vn.test(e)}function Sn(e){let t=e.trim();t=t.replace(/^(?:file|app):\/\/(?:localhost)?/i,``);try{t=decodeURIComponent(t)}catch{}return t=t.replace(/\\/g,`/`),t=t.replace(/^\.\//,``),t=t.replace(/^\/+/,``),t=t.replace(/^[a-zA-Z]:\//,``),t}function Cn(e){let t=Sn(e),n=t.split(`/`).filter(Boolean);return(n[n.length-1]||t).toLowerCase()}function wn(){return typeof window>`u`||window.isSecureContext===!1?!1:typeof window.showDirectoryPicker==`function`}async function Tn(){if(!wn())return null;try{return await window.showDirectoryPicker.call(window,{mode:`read`})??null}catch{return null}}function En(){return typeof window>`u`||window.isSecureContext===!1?!1:typeof window.showOpenFilePicker==`function`}async function Dn(){if(!En())return null;try{let e=await window.showOpenFilePicker.call(window,{multiple:!0});return await Promise.all(e.map(e=>e.getFile()))}catch{return null}}async function On(e,t){if(t.length===0)return{file:null};let n=e;for(let e=0;e<t.length-1;e++)try{n=await n.getDirectoryHandle(t[e])}catch{return{file:null}}try{let e=await n.getFileHandle(t[t.length-1]);try{return{file:await e.getFile()}}catch(e){return{file:null,readError:e}}}catch{return{file:null}}}async function kn(e,t,n=5e3){let r=t.toLowerCase(),i=[e],a=0,o;for(;i.length>0&&a<n;){let e=i.pop();try{for await(let t of e.values()){if(a++,a>n)break;if(t.kind===`file`){if(t.name.toLowerCase()===r)try{return{file:await t.getFile()}}catch(e){o=e}}else t.kind===`directory`&&i.push(t)}}catch{}}return a>=n&&console.warn(`目录遍历预算 ${n} 已耗尽,「${t}」可能藏在不完整的搜索范围内`),{file:null,readError:o}}async function An(e,t){let n=Sn(t).split(`/`).filter(Boolean);if(n.length===0)return{file:null};let r;for(let t=0;t<n.length;t++){let i=await On(e,n.slice(t));if(i.file)return i;i.readError&&(r=i.readError)}let i=await kn(e,n[n.length-1]);return i.file||i.readError?i:{file:null,readError:r}}var jn={image:`image`,videoEmbed:`video`,audioEmbed:`audio`,attachmentEmbed:`attachment`};function Mn(e,t){let n=new Set,r=[];return e.descendants(e=>{let i=jn[e.type?.name];if(i){let a=e.attrs?.src,o=`node:${a}`;typeof a==`string`&&bn(a)&&!n.has(o)&&!t?.(a)&&(n.add(o),r.push({src:a,normalized:Sn(a),basename:Cn(a),kind:i,isLink:!1}));return}if(e.isText&&e.marks)for(let i of e.marks){if(i.type.name!==`link`)continue;let e=i.attrs?.href,a=`link:${e}`;typeof e==`string`&&bn(e)&&xn(e)&&!n.has(a)&&!t?.(e)&&(n.add(a),r.push({src:e,normalized:Sn(e),basename:Cn(e),kind:`attachment`,isLink:!0}))}}),r}function Nn(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=>xn(e)&&bn(e)&&!n?.(e))}function Pn(e){if(e.type.startsWith(`image/`))return`image`;if(e.type.startsWith(`video/`))return`video`;if(e.type.startsWith(`audio/`))return`audio`;let t=e.name.split(`.`).pop()?.toLowerCase()||``;return/^(png|jpe?g|gif|webp|bmp|svg|avif)$/.test(t)?`image`:/^(mp4|m3u8|webm|ogg|mov|avi|wmv|flv|mkv|ts|m4v|3gp|f4v|rmvb)$/.test(t)?`video`:/^(mp3|wav|flac|aac|m4a|wma|opus)$/.test(t)?`audio`:/^(md|markdown)$/.test(t)?`markdown`:`file`}function Fn(e){let t=e.name.split(`.`).pop()?.toLowerCase()||``;return t===`md`||t===`markdown`}async function In(e,t,n,r){let i=n??e.state.selection.from,a=r?St(r):void 0,o=r?.storage?.qingwuUI,s=await new Promise(e=>{o?.chooseMd?o.chooseMd(t.name,e):_n(t.name).then(e)});if(s===null)return;if(s===`attach`){let n=a?Ct(e.state.doc,t,a):null;if(n){J(n);return}let r=URL.createObjectURL(t),o=e.state.schema.nodes.attachmentEmbed?.create({src:r,name:t.name,size:t.size,type:t.type});if(o)try{e.dispatch(e.state.tr.insert(i,o))}catch{}return}let c=await t.text();if(o?.parseMd){let t=o.parseMd(e.state.schema,c);if(t){e.dispatch(e.state.tr.insert(i,t));return}}let l=c.split(`
5
5
  `),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 Ln(e,t,n){switch(Pn(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 Rn(e,t,r){let i;try{i=n.n()}catch{return null}try{let n=await i.upload(t,`editor`);URL.revokeObjectURL(r);let a=!1;return e.state.doc.descendants((t,i)=>t.attrs?.src===r?(e.dispatch(e.state.tr.setNodeMarkup(i,void 0,{...t.attrs,src:n})),a=!0,!1):!0),a?n:null}catch(e){return console.error(`${t.type} upload failed:`,e),URL.revokeObjectURL(r),null}}async function zn(e,t,n,r){let i=r?St(r):void 0,a=i?Ct(e.state.doc,t,i):null;if(a){J(a);return}let o=URL.createObjectURL(t),s=Ln(e.state.schema,t,o);if(!s)return;let c=n??e.state.selection.from;try{e.dispatch(e.state.tr.insert(c,s))}catch{return}await Rn(e,t,o)}var Bn=d.Extension.create({name:`imageUpload`,addOptions(){return{maxAttachmentSize:0,maxTotalAttachmentSize:0}},addProseMirrorPlugins(){let e=this.editor;return[new f.Plugin({key:new f.PluginKey(`imageUpload`),props:{handleDrop(t,n){let r=n.dataTransfer?.files;if(!r||r.length===0)return!1;n.preventDefault();let i=t.posAtCoords({left:n.clientX,top:n.clientY});for(let n of Array.from(r))Fn(n)?In(t,n,i?.pos,e):zn(t,n,i?.pos,e);return!0},handlePaste(t,r){let i=r.clipboardData?.items;if(!i)return!1;let a=r.clipboardData?.getData(`text/plain`)||``;if((r.clipboardData?.files?.length??0)>0&&Nn(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&&Pn(i)!==`file`&&zn(t,i,void 0,e),!0}if(n.kind===`file`){let i=n.getAsFile();if(i&&Fn(i))return r.preventDefault(),In(t,i,void 0,e),!0}}return!1}}})]}}),Vn=/\.(png|jpe?g|gif|webp|bmp|svg|avif)(\?|#|$)/i,Hn=/\.(mp4|m3u8|webm|ogg|flv|mkv|mov|avi|wmv|ts|m4v|3gp|f4v|rmvb)(\?|#|$)/i,Un=/\.(mp3|wav|ogg|flac|aac|m4a|wma|opus)(\?|#|$)/i;function Wn(e){return e.replace(/&/g,`&amp;`).replace(/"/g,`&quot;`).replace(/</g,`&lt;`).replace(/>/g,`&gt;`)}function Gn(e){let t=e.trim().replace(/\\/g,`/`);return t.split(`/`).pop()||t}function Kn(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||Gn(a);if(i){let n=``;if(Vn.test(a)||/^data:image\//i.test(a))n=`<img src="${Wn(a)}" alt="${Wn(t)}">`;else if(Hn.test(a)||/^data:video\//i.test(a))n=`<div data-video-embed src="${Wn(a)}"></div>`;else if(Un.test(a)||/^data:audio\//i.test(a))n=`<audio src="${Wn(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 qn=d.Extension.create({name:`obsidianMarkdown`,addStorage(){return{markdown:{parse:{setup(e){e.__obsidianReg||(e.__obsidianReg=!0,e.inline.ruler.before(`link`,`obsidian_embed`,Kn))}}}}}}),Jn=d.Extension.create({name:`qingwuUI`,addStorage(){return{}}});function Yn(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 Xn(e,n=8e3){if(await Yn(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 Yn(a,n);return URL.revokeObjectURL(a),o}catch{return!1}}function Zn(){return{uploaded:0,sessionOnly:0,limitRejected:0,renderFailed:0,missing:[],readFailed:[]}}function Qn(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 $n(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 er(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 tr(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 nr(e,t,r,i){if(r.length===0)return`sessionOnly`;let a=r[0],o=St(t);if(o){let t=Ct(e.state.doc,i,o);if(t)return J(`${a.basename}:${t}`,`error`),`limitRejected`}let s=r.filter(e=>!e.isLink),c=r.filter(e=>e.isLink);if(s.length===0)try{let t=await n.n().upload(i,`editor`),r=!1;for(let n of c)er(e,n.src,t)&&(r=!0);return r?`uploaded`:`sessionOnly`}catch(e){return console.error(`本地附件 ${a.basename} 上传失败:`,e),J(`「${a.basename}」上传失败`,`error`),`sessionOnly`}let l=URL.createObjectURL(i),u=!1;for(let t of s)$n(e,t.src,l,i.size)&&(u=!0);let d;try{d=await n.n().upload(i,`editor`)}catch(e){return console.error(`本地文件 ${a.basename} 上传失败:`,e),J(`「${a.basename}」上传失败`,`error`),URL.revokeObjectURL(l),`sessionOnly`}URL.revokeObjectURL(l),u&&$n(e,l,d,i.size);for(let t of c)er(e,t.src,d);return!u&&c.length===0?`sessionOnly`:u&&r.some(e=>e.kind===`image`)?await Xn(d)?`uploaded`:`renderFailed`:`uploaded`}function rr(e,t){let n=[],r=[];for(let i of tr(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 ir(e,t,n,r){let i=Zn();for(let a of tr(n)){let n=a[0],{file:o,readError:s}=await An(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 nr(e,t,a,o);i[c]++}return i}function ar(e){let t=e.map(e=>e.basename);return t.length<=3?t.join(`、`):`${t.slice(0,3).join(`、`)} 等 ${t.length} 个文件`}function or(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} 个找到但读取失败:${ar(e.readFailed)}(若在 OneDrive / WPS 云盘等同步目录,请右键文件选择「始终保留在此设备」后重试)`),e.missing.length>0&&t.push(`${e.missing.length} 个未能获取:${ar(e.missing)}(可把文件直接拖进编辑器上传)`),t.length===0)return;let n=e.uploaded>0&&e.renderFailed===0&&e.missing.length===0&&e.readFailed.length===0;J(`本地文件解析完成:${t.join(`;`)}`,n?`success`:`info`)}function sr(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 库根目录,它会连同子目录一起查找),编辑器读取后会上传到你的存储。
6
6
  也可以选择稍后把文件直接拖进编辑器。`;let o=document.createElement(`div`);o.className=`flex justify-end gap-2`;let s=e=>{document.removeEventListener(`keydown`,c),n.remove(),t(e)},c=e=>{e.key===`Escape`&&s(`cancel`)};n.addEventListener(`mousedown`,e=>{e.target===n&&s(`cancel`)});let l=document.createElement(`button`);l.type=`button`,l.className=`px-3 py-1.5 text-xs rounded-lg border border-default-200 hover:bg-default-100 text-default-700 dark:text-zinc-300 dark:border-zinc-600 dark:hover:bg-zinc-700`,l.textContent=`稍后处理`,l.addEventListener(`click`,()=>s(`cancel`));let u=document.createElement(`button`);u.type=`button`,u.className=`px-3 py-1.5 text-xs rounded-lg bg-blue-500 hover:bg-blue-600 text-white`,u.textContent=`选择文件夹…`,u.addEventListener(`click`,()=>s(`pick`)),o.append(l,u),r.append(i,a,o),n.appendChild(r),document.addEventListener(`keydown`,c),document.body.appendChild(n)})}function cr(e){let t=document.createElement(`div`);t.className=`fixed inset-0 z-[10001] flex items-center justify-center bg-black/40 backdrop-blur-sm select-none`;let n=document.createElement(`div`);n.className=`bg-white dark:bg-zinc-800 rounded-xl p-6 shadow-xl max-w-md w-full mx-4 border border-default-200 dark:border-zinc-700`;let r=document.createElement(`div`);r.className=`text-sm font-medium text-default-800 dark:text-zinc-100 mb-2`,r.textContent=`粘贴内容中包含本地文件`;let i=document.createElement(`div`);i.className=`text-xs text-default-500 dark:text-zinc-400 mb-4 whitespace-pre-line leading-relaxed`,i.textContent=`检测到 ${e} 个本地图片/附件使用相对路径,粘贴时文件本体没有跟过来。\n当前浏览器不支持读取本地文件夹(需要 Chrome / Edge)。请把对应的图片或文件直接拖进编辑器,会自动完成上传。`;let a=document.createElement(`div`);a.className=`flex justify-end`;let o=()=>{document.removeEventListener(`keydown`,s),t.remove()},s=e=>{e.key===`Escape`&&o()};t.addEventListener(`mousedown`,e=>{e.target===t&&o()});let c=document.createElement(`button`);c.type=`button`,c.className=`px-3 py-1.5 text-xs rounded-lg bg-blue-500 hover:bg-blue-600 text-white`,c.textContent=`知道了`,c.addEventListener(`click`,o),a.append(c),n.append(r,i,a),t.appendChild(n),document.addEventListener(`keydown`,s),document.body.appendChild(t)}function lr(e){return new Promise(t=>{let n=document.createElement(`div`);n.className=`fixed inset-0 z-[10001] flex items-center justify-center bg-black/40 backdrop-blur-sm select-none`;let r=document.createElement(`div`);r.className=`bg-white dark:bg-zinc-800 rounded-xl p-6 shadow-xl max-w-md w-full mx-4 border border-default-200 dark:border-zinc-700 relative overflow-hidden`;let i=document.createElement(`div`);i.className=`text-sm font-medium text-default-800 dark:text-zinc-100 mb-2`,i.textContent=`选择文件直接上传`;let a=document.createElement(`div`);a.className=`text-xs text-default-500 dark:text-zinc-400 mb-4 whitespace-pre-line leading-relaxed`,a.textContent=`还有 ${e.length} 个本地文件无法从所选文件夹读取:${e.join(`、`)}。\n点击「选择文件…」后在系统对话框里选中这些文件(可多选),将直接上传到存储。若它们位于云同步目录(OneDrive / 绿联云等),选中后会自动取回本地内容。`;let o=document.createElement(`div`);o.className=`flex justify-end gap-2`;let s=e=>{document.removeEventListener(`keydown`,c),n.remove(),t(e)},c=e=>{e.key===`Escape`&&s(`cancel`)};n.addEventListener(`mousedown`,e=>{e.target===n&&s(`cancel`)});let l=document.createElement(`button`);l.type=`button`,l.className=`px-3 py-1.5 text-xs rounded-lg border border-default-200 hover:bg-default-100 text-default-700 dark:text-zinc-300 dark:border-zinc-600 dark:hover:bg-zinc-700`,l.textContent=`稍后处理`,l.addEventListener(`click`,()=>s(`cancel`));let u=document.createElement(`button`);u.type=`button`,u.className=`px-3 py-1.5 text-xs rounded-lg bg-blue-500 hover:bg-blue-600 text-white`,u.textContent=`选择文件…`,u.addEventListener(`click`,()=>s(`pick`)),o.append(l,u),r.append(i,a,o),n.appendChild(r),document.addEventListener(`keydown`,c),document.body.appendChild(n)})}async function ur(e,t,n){let r=Zn(),i=tr(n),a=await Dn();if(!a){for(let e of i)r.missing.push(e[0]);return r}let o=new Map(a.map(e=>[e.name.toLowerCase(),e]));for(let n of i){let i=n[0],a=o.get(i.basename);if(!a){r.missing.push(i);continue}o.delete(i.basename);let s=await nr(e,t,n,a);r[s]++}return r}var dr=d.Extension.create({name:`relativeMedia`,addStorage(){return{clipboardFiles:new Map,pausedUntilPaste:!1}},addProseMirrorPlugins(){let e=this.editor,t=this.storage,r=!1,i=null,a=async(n,r)=>{let a=e.view,o=Zn(),{matched:s,unmatched:c}=rr(n,t.clipboardFiles);for(let{refs:t,file:n}of s){let r=await nr(a,e,t,n);o[r]++}if(c.length>0){let t=tr(c).length;if(wn()){let n=r??null;if(n||(await sr(t)===`pick`?(n=await Tn(),n||J(`没有选择文件夹。本地文件暂以占位显示,稍后可直接把文件拖进编辑器上传`,`info`)):J(`已选择稍后处理。本地文件暂以占位显示,可直接把文件拖进编辑器上传`,`info`)),n){i=n,Qn(o,await ir(a,e,c,n));let t=[...o.missing,...o.readFailed];if(t.length>0&&En()&&await lr(t.map(e=>e.basename))===`pick`){let n=await ur(a,e,t);Qn(o,n),o.missing=n.missing,o.readFailed=[]}}}else cr(t)}or(o)},o=()=>{if(!e||e.isDestroyed||t.pausedUntilPaste)return;let o=n.i(),s=Mn(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=Mn(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=Mn(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}})]}}),fr=new f.PluginKey(`slashCommand`);function pr(e){return d.Extension.create({name:`slashCommand`,addProseMirrorPlugins(){let t={char:`/`,pluginKey:fr,findSuggestionMatch:e=>{let{$position:t}=e;for(let e=t.depth;e>=0;e--)if(t.node(e).type.name===`codeBlock`)return null;return t.marks().some(e=>e.type.name===`code`)?null:(0,N.findSuggestionMatch)(e)},allow:({editor:e,state:t})=>{if(!e.isEditable)return!1;let{$from:n}=t.selection;for(let e=n.depth;e>=0;e--)if(n.node(e).type.name===`codeBlock`)return!1;return!n.marks().some(e=>e.type.name===`code`)},command:({editor:e,range:t,props:n})=>{e.chain().focus().deleteRange(t).run(),n.command({editor:e})},items:({query:t})=>{let n=e();if(!t)return n;let r=t.toLowerCase();return n.filter(e=>e.title.toLowerCase().includes(r)||(e.description?.toLowerCase().includes(r)??!1))},render:()=>{let e=null,t=null,n=0,r=[];function i(e,i){if(!t)return;r=e,t.textContent=``;let a=document.createElement(`div`);a.style.cssText=`padding:6px 8px;border-bottom:1px solid #f4f4f5;`;let o=document.createElement(`input`);o.type=`text`,o.placeholder=`搜索命令…`,o.style.cssText=`width:100%;padding:6px 8px;border:1px solid #e4e4e7;border-radius:8px;font-size:13px;outline:none;background:#fafafa;`,a.appendChild(o),t.appendChild(a);let s=document.createElement(`div`);if(s.className=`slash-item-list`,s.style.cssText=`max-height:300px;overflow-y:auto;`,e.length===0){let e=document.createElement(`div`);e.style.cssText=`padding:12px;text-align:center;color:#a1a1aa;font-size:13px;`,e.textContent=`未找到匹配`,s.appendChild(e)}else e.forEach((e,t)=>{let r=document.createElement(`button`);r.type=`button`,r.className=`slash-item${t===n?` slash-item--selected`:``}`,r.dataset.index=String(t),r.style.cssText=`display:flex;align-items:center;gap:12px;width:100%;padding:8px 12px;border:none;background:${t===n?`#f4f4f5`:`transparent`};cursor:pointer;text-align:left;border-radius:8px;font-size:14px;transition:background 0.1s;`;let a=document.createElement(`span`);a.style.cssText=`font-size:16px;width:24px;text-align:center;flex-shrink:0;`,a.textContent=e.icon||``,r.appendChild(a);let o=document.createElement(`div`);o.style.cssText=`min-width:0;`;let c=document.createElement(`div`);if(c.style.cssText=`font-weight:500;color:#18181b;`,c.textContent=e.title,o.appendChild(c),e.description){let t=document.createElement(`div`);t.style.cssText=`font-size:12px;color:#a1a1aa;margin-top:1px;`,t.textContent=e.description,o.appendChild(t)}r.appendChild(o),r.addEventListener(`click`,()=>{i(e)}),s.appendChild(r)});t.appendChild(s);let c=s.querySelector(`.slash-item--selected`);if(c){let e=s.getBoundingClientRect(),t=c.getBoundingClientRect();t.top<e.top?s.scrollTop-=e.top-t.top:t.bottom>e.bottom&&(s.scrollTop+=t.bottom-e.bottom)}o.addEventListener(`input`,()=>{let e=o.value.toLowerCase();s.querySelectorAll(`.slash-item`).forEach(t=>{let n=(t.textContent||``).toLowerCase();t.style.display=n.includes(e)?``:`none`})})}let a=null,o=null;function s(){if(!e||!a)return;let t=a();t&&(e.style.top=`${t.bottom+4}px`,e.style.left=`${t.left}px`)}return{onStart:c=>{n=0,a=c.clientRect||null,e||(e=document.createElement(`div`),e.style.position=`fixed`,e.style.zIndex=`9999`,document.body.appendChild(e)),t||(t=document.createElement(`div`),t.className=`slash-command-popup`,t.style.cssText=`background:#fff;border:1px solid #e4e4e7;border-radius:12px;box-shadow:0 4px 24px rgba(0,0,0,0.12);min-width:260px;max-width:340px;`,t.setAttribute(`data-lenis-prevent`,``),e.appendChild(t)),s(),r=c.items,i(c.items,c.command),e.style.display=`block`,o=()=>s(),window.addEventListener(`scroll`,o,!0)},onUpdate:e=>{n=0,a=e.clientRect||null,r=e.items,i(e.items,e.command),s()},onKeyDown:e=>e.event.key===`ArrowDown`?(e.event.preventDefault(),n=Math.min(n+1,r.length-1),i(r,e.command),!0):e.event.key===`ArrowUp`?(e.event.preventDefault(),n=Math.max(n-1,0),i(r,e.command),!0):e.event.key===`Enter`?(e.event.preventDefault(),r[n]&&e.command(r[n]),!0):e.event.key===`Escape`,onExit:()=>{e&&(e.style.display=`none`),n=0,r=[],a=null,o&&=(window.removeEventListener(`scroll`,o,!0),null)}}}};return[(0,N.default)({editor:this.editor,...t}),new f.Plugin({key:new f.PluginKey(`slashCodeBlockGuard`),appendTransaction:(e,t,n)=>{let{$from:r}=n.selection,i=!1;for(let e=r.depth;e>=0;e--)if(r.node(e).type.name===`codeBlock`){i=!0;break}if(!i&&!r.marks().some(e=>e.type.name===`code`))return null;let a=fr.getState(n);return a&&a.active?n.tr.setMeta(fr,{exit:!0}):null}})]}})}function mr(e,t){return[{title:e(`editor.slash.heading1`),description:e(`editor.slash.heading1Desc`),icon:`H1`,command:({editor:e})=>e.chain().focus().toggleHeading({level:1}).run()},{title:e(`editor.slash.heading2`),description:e(`editor.slash.heading2Desc`),icon:`H2`,command:({editor:e})=>e.chain().focus().toggleHeading({level:2}).run()},{title:e(`editor.slash.heading3`),description:e(`editor.slash.heading3Desc`),icon:`H3`,command:({editor:e})=>e.chain().focus().toggleHeading({level:3}).run()},{title:e(`editor.slash.heading4`),description:e(`editor.slash.heading4Desc`),icon:`H4`,command:({editor:e})=>e.chain().focus().toggleHeading({level:4}).run()},{title:e(`editor.slash.heading5`),description:e(`editor.slash.heading5Desc`),icon:`H5`,command:({editor:e})=>e.chain().focus().toggleHeading({level:5}).run()},{title:e(`editor.slash.heading6`),description:e(`editor.slash.heading6Desc`),icon:`H6`,command:({editor:e})=>e.chain().focus().toggleHeading({level:6}).run()},{title:e(`editor.slash.bulletList`),description:e(`editor.slash.bulletListDesc`),icon:`•`,command:({editor:e})=>e.chain().focus().toggleBulletList().run()},{title:e(`editor.slash.numberedList`),description:e(`editor.slash.numberedListDesc`),icon:`1.`,command:({editor:e})=>e.chain().focus().toggleOrderedList().run()},{title:e(`editor.slash.taskList`),description:e(`editor.slash.taskListDesc`),icon:`☑`,command:({editor:e})=>e.chain().focus().toggleTaskList().run()},{title:e(`editor.slash.blockquote`),description:e(`editor.slash.blockquoteDesc`),icon:`❝`,command:({editor:e})=>e.chain().focus().toggleBlockquote().run()},{title:e(`editor.slash.codeBlock`),description:e(`editor.slash.codeBlockDesc`),icon:`</>`,command:({editor:e})=>e.chain().focus().toggleCodeBlock().run()},{title:e(`editor.slash.horizontalRule`),description:e(`editor.slash.horizontalRuleDesc`),icon:`—`,command:({editor:e})=>e.chain().focus().setHorizontalRule().run()},{title:e(`editor.slash.image`),description:e(`editor.slash.imageDesc`),icon:`🖼`,command:({editor:e})=>{e.storage.qingwuUI?.openImageDialog?.()}},{title:e(`editor.slash.video`),description:e(`editor.slash.videoDesc`),icon:`🎬`,command:({editor:e})=>{e.storage.qingwuUI?.openVideoDialog?.()}},{title:e(`editor.slash.audio`),description:e(`editor.slash.audioDesc`),icon:`🎵`,command:({editor:e})=>{let n=document.createElement(`input`);n.type=`file`,n.accept=`audio/*`,n.onchange=async()=>{let r=n.files?.[0];if(!r)return;let i=St(e)??t,a=i?Ct(e.state.doc,r,i):null;if(a){J(a);return}let o=URL.createObjectURL(r),s=e.schema.nodes.audioEmbed?.create({src:o,name:r.name,size:r.size});s&&(e.chain().focus().insertContent(s).run(),await Rn(e.view,r,o))},n.click()}},{title:e(`editor.slash.attachment`),description:e(`editor.slash.attachmentDesc`),icon:`📎`,command:({editor:e})=>{let n=document.createElement(`input`);n.type=`file`,n.accept=`*/*`,n.multiple=!0,n.onchange=async()=>{let r=n.files;if(!(!r||r.length===0))for(let n of Array.from(r)){let r=St(e)??t,i=r?Ct(e.state.doc,n,r):null;if(i){J(i);continue}let a=URL.createObjectURL(n),o=e.schema.nodes.attachmentEmbed;if(o){try{e.chain().focus().insertContent(o.create({src:a,name:n.name,size:n.size,type:n.type})).run()}catch{continue}await Rn(e.view,n,a)}}},n.click()}}]}var hr=m.Image.extend({addNodeView(){return(0,c.ReactNodeViewRenderer)(Pt)},addAttributes(){return{...this.parent?.(),width:{default:null,parseHTML:e=>e.getAttribute(`width`)||null,renderHTML:e=>e.width?{width:e.width}:{}},height:{default:null,parseHTML:e=>e.getAttribute(`height`)||null,renderHTML:e=>e.height?{height:e.height}:{}},size:{default:0,parseHTML:e=>Number(e.getAttribute(`data-size`)||0),renderHTML:e=>e.size?{"data-size":e.size}:{}}}}});function gr(t={}){return[_.default.configure({codeBlock:!1,horizontalRule:!1,underline:!1,link:!1}),g.Underline,h.Link.configure({openOnClick:!0,HTMLAttributes:{rel:`noopener noreferrer`,target:`_blank`}}),hr.configure({inline:!1,allowBase64:!0}),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,gn,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||`输入 '/' 打开菜单…`}),pr(()=>mr(t=>e.o(t),{maxAttachmentSize:t.maxAttachmentSize,maxTotalAttachmentSize:t.maxTotalAttachmentSize})),Bn.configure({maxAttachmentSize:t.maxAttachmentSize,maxTotalAttachmentSize:t.maxTotalAttachmentSize}),dr,qn,Be,Jn,on,Qt,Yt]}var _r=`https://www.bing.com/search?q={query}`;function vr(e){_r=e}function yr(){return _r}function br(e){return[{key:`bold`,label:e(`editor.bubble.bold`),icon:(0,a.jsx)(Ue,{}),isActive:e=>e.isActive(`bold`),command:e=>e.isEditable&&e.chain().focus().toggleBold().run()},{key:`italic`,label:e(`editor.bubble.italic`),icon:(0,a.jsx)(We,{}),isActive:e=>e.isActive(`italic`),command:e=>e.isEditable&&e.chain().focus().toggleItalic().run()},{key:`underline`,label:e(`editor.bubble.underline`),icon:(0,a.jsx)(Ge,{}),isActive:e=>e.isActive(`underline`),command:e=>e.isEditable&&e.chain().focus().toggleUnderline().run()},{key:`strikethrough`,label:e(`editor.bubble.strikethrough`),icon:(0,a.jsx)(Ke,{}),isActive:e=>e.isActive(`strike`),command:e=>e.isEditable&&e.chain().focus().toggleStrike().run()},{key:`code`,label:e(`editor.bubble.emphasis`),icon:(0,a.jsx)(qe,{}),isActive:e=>e.isActive(`code`),command:e=>e.isEditable&&e.chain().focus().toggleCode().run()},{key:`highlight`,label:e(`editor.bubble.highlight`),icon:(0,a.jsx)(Je,{}),more:!0,isActive:e=>e.isActive(`highlight`),command:()=>{}},{key:`link`,label:e(`editor.bubble.link`),icon:(0,a.jsx)(Ye,{}),more:!0,isActive:e=>e.isActive(`link`),command:()=>{}},{key:`copy`,label:e(`editor.bubble.copy`),icon:(0,a.jsx)(Ze,{}),more:!0,isActive:()=>!1,command:e=>{let{from:t,to:n}=e.state.selection,r=e.state.doc.textBetween(t,n,`
7
7
  `).trim();r&&navigator.clipboard?.writeText(r).catch(()=>{})}},{key:`search`,label:e(`editor.bubble.search`),icon:(0,a.jsx)(Qe,{}),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=_r.replace(`{query}`,encodeURIComponent(r));window.open(i,`_blank`,`noopener,noreferrer`)}},{key:`table`,label:e(`editor.bubble.table`),icon:(0,a.jsx)(Xe,{}),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)($e,{}),isActive:()=>!1,command:e=>{e.isEditable&&e.storage.qingwuUI?.openAI?.()}}]}d.Extension.create({name:`bubbleMenu`});function xr(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 Sr(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 Cr(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(`
8
8
  `)}function wr(e){let t=e=>/[",\n]/.test(e)?`"${e.replace(/"/g,`""`)}"`:e;return e.map(e=>e.map(t).join(`,`)).join(`
9
- `)}function Tr(e){let t=e.trim();if(!t)return null;let n=t.split(/\r?\n/);if(n.length>=2&&n.every(e=>e.includes(`|`))){let e=n.filter(e=>!/^\s*\|?[\s:|-]+\|?\s*$/.test(e)).map(e=>e.replace(/^\s*\|/,``).replace(/\|\s*$/,``).split(`|`).map(e=>e.trim()));if(e.length>0&&e[0].length>1)return e}if(n.length>=1){let e=n[0].includes(` `)?` `:`,`,t=n.map(t=>t.split(e).map(e=>e.trim()));if(t.length>0&&t[0].length>1)return t}return null}function Er({editor:e}){let[t,n]=(0,i.useState)(null),[r,o]=(0,i.useState)(!1),[s,c]=(0,i.useState)(!1),l=(0,i.useRef)(null),u=(0,i.useRef)(null),d=e.isEditable,f=(0,i.useCallback)(()=>{u.current!=null&&cancelAnimationFrame(u.current),u.current=requestAnimationFrame(()=>{u.current=null;let n=l.current;if(n==null||t==null)return;let r=e.view.nodeDOM(t);if(!(r instanceof HTMLElement))return;let i=r.getBoundingClientRect(),a=i.top>40?i.top-34:Math.min(i.bottom+4,window.innerHeight-40);n.style.top=`${a}px`,n.style.left=`${Math.max(8,Math.min(i.left,window.innerWidth-160))}px`})},[e,t]),p=(0,i.useCallback)(()=>{if(!e.isEditable||!e.isActive(`table`)){n(null);return}let t=xr(e);if(!t){n(null);return}n(e=>e===t.pos?e:t.pos)},[e]);(0,i.useEffect)(()=>(p(),e.on(`selectionUpdate`,p),e.on(`focus`,p),window.addEventListener(`scroll`,f,!0),window.addEventListener(`resize`,f),()=>{e.off(`selectionUpdate`,p),e.off(`focus`,p),window.removeEventListener(`scroll`,f,!0),window.removeEventListener(`resize`,f),u.current!=null&&cancelAnimationFrame(u.current)}),[e,p,f]),(0,i.useEffect)(()=>{f()},[t,f]);let m=t=>{let{schema:n}=e.state;if(!n.nodes.table||!n.nodes.tableRow||!n.nodes.tableCell||!n.nodes.tableHeader)return null;let r=Math.max(...t.map(e=>e.length)),i=t.map((e,t)=>{let i=[];for(let a=0;a<r;a++){let r=e[a]??``,o=t===0?n.nodes.tableHeader:n.nodes.tableCell,s=r?n.text(r):null;i.push(o.create(null,s?[s]:[]))}return n.nodes.tableRow.create(null,i)});return n.nodes.table.create(null,i)},h=()=>{let t=xr(e);if(!t)return;let n=Cr(Sr(t.node));navigator.clipboard?.writeText(n),o(!0),setTimeout(()=>o(!1),1500)},g=()=>{let t=xr(e);if(!t)return;let n=wr(Sr(t.node)),r=new Blob([`\ufeff${n}`],{type:`text/csv;charset=utf-8`}),i=URL.createObjectURL(r),a=document.createElement(`a`);a.href=i,a.download=`table.csv`,document.body.appendChild(a),a.click(),document.body.removeChild(a),URL.revokeObjectURL(i)},_=async()=>{if(d)try{let t=await navigator.clipboard?.readText();if(!t)return;let n=Tr(t);if(!n||n.length===0)return;let r=m(n);if(!r)return;let i=xr(e),a=e.chain().focus();if(i){let t=Math.min(i.pos+i.node.nodeSize,e.state.doc.content.size);a.setTextSelection(t)}a.insertContent(r).run()}catch{}},v=()=>{d&&t!=null&&(e.chain().focus().setNodeSelection(t).run(),e.storage.qingwuUI?.openAI?.())},y=()=>{d&&e.chain().focus().deleteTable().run()};return!d||t==null?null:(0,a.jsxs)(`div`,{ref:l,style:{position:`fixed`,top:0,left:0,zIndex:1e5},className:`tbl-toolbar`,contentEditable:!1,children:[(0,a.jsx)(`button`,{type:`button`,className:`tbl-btn`,onClick:h,title:`复制`,children:r?(0,a.jsx)(`svg`,{className:`tbl-btn-icon tbl-btn-icon--check`,width:`14`,height:`14`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,children:(0,a.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M5 13l4 4L19 7`})}):(0,a.jsx)(`svg`,{className:`tbl-btn-icon`,width:`14`,height:`14`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,children:(0,a.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M8 5H6a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2v-2M8 5a2 2 0 002 2h2a2 2 0 002-2M8 5a2 2 0 012-2h2a2 2 0 012 2m0 0h2a2 2 0 012 2v3`})})}),(0,a.jsx)(`button`,{type:`button`,className:`tbl-btn`,onClick:g,title:`下载`,children:(0,a.jsx)(`svg`,{className:`tbl-btn-icon`,width:`14`,height:`14`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,children:(0,a.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M4 16v1a3 3 0 003 3h10a3 3 0 003-3v-1m-4-4l-4 4m0 0l-4-4m4 4V4`})})}),(0,a.jsx)(`button`,{type:`button`,className:`tbl-btn`,onClick:_,title:`粘贴`,children:(0,a.jsx)(`svg`,{className:`tbl-btn-icon`,width:`14`,height:`14`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,children:(0,a.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2`})})}),(0,a.jsx)(`button`,{type:`button`,className:`tbl-btn tbl-btn--ai`,onClick:v,title:`AI 助手`,children:(0,a.jsx)(`svg`,{className:`tbl-btn-icon`,width:`14`,height:`14`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,children:(0,a.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M13 10V3L4 14h7v7l9-11h-7z`})})}),(0,a.jsx)(`button`,{type:`button`,className:`tbl-btn tbl-btn--del`,onClick:()=>{!d||Dt()||($(!0),c(!0))},title:`删除`,children:(0,a.jsx)(`svg`,{className:`tbl-btn-icon`,width:`14`,height:`14`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,children:(0,a.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16`})})}),(0,a.jsx)(Mt,{open:s,title:`确认删除表格`,message:`此操作不可撤销。`,onCancel:()=>{$(!1),c(!1)},onConfirm:async()=>{await new Promise(e=>setTimeout(e,300)),$(!1),y()}})]})}var Dr=[{color:`#fef08a`,name:`黄`},{color:`#bbf7d0`,name:`绿`},{color:`#bfdbfe`,name:`蓝`},{color:`#fbcfe8`,name:`粉`},{color:`#fed7aa`,name:`橙`},{color:`#ddd6fe`,name:`紫`}],Or=288,kr=480,Ar=320;function jr(e,t,n={}){let r=window.innerWidth,i=window.innerHeight,a=Math.min(n.panelWidth||Or,kr,r-32),o=Math.max(t||Ar,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 Mr(e){return/(^|\n)```|(^|\n)#{1,6}\s|(^|\n)>\s?|(^|\n)\s*([-*_])(?:\s*\4){2,}\s*(?=\n|$)|(^|\n)\s*[-*+]\s+|(^|\n)\s*\d+[.)]\s+|(^|\n)\s*<img\s+|(^|\n)\s*\|.+\|/i.test(e)}function Nr(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 Pr=(0,i.lazy)(()=>Promise.resolve().then(()=>ve).then(e=>({default:e.ImageUploadDialog}))),Fr=(0,i.lazy)(()=>Promise.resolve().then(()=>require("./storage-settings-dialog-1_Pqjd2x.cjs")).then(e=>({default:e.StorageSettingsDialog}))),Ir=(0,i.lazy)(()=>Promise.resolve().then(()=>require("./export-dialog-JUHUKqo-.cjs")).then(e=>({default:e.ExportDialog}))),Lr=(0,i.lazy)(()=>Promise.resolve().then(()=>require("./video-embed-dialog-BbVHq51W.cjs")).then(e=>({default:e.VideoEmbedDialog}))),Rr=(0,i.lazy)(()=>Promise.resolve().then(()=>require("./md-import-dialog-CnstzrIK.cjs")).then(e=>({default:e.MdImportDialog}))),zr=()=>(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`})})]}),Br=({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)(()=>Mr(t)?t:e.n(t),[t]),[E,D]=(0,i.useState)(!1),[O,k]=(0,i.useState)({}),[A,j]=(0,i.useState)(`below`),[ee,M]=(0,i.useState)(50),N=(0,i.useRef)(null),[P,te]=(0,i.useState)(!1),[F,I]=(0,i.useState)(!1),[ne,re]=(0,i.useState)(!1),[ie,ae]=(0,i.useState)(!1),[L,R]=(0,i.useState)(`none`),[z,B]=(0,i.useState)({}),[V,oe]=(0,i.useState)(``),[H,U]=(0,i.useState)(null),[W,se]=(0,i.useState)(y),[G,ce]=(0,i.useState)(!1);(0,i.useEffect)(()=>{se(y)},[y]);let[le,ue]=(0,i.useState)(!1),[de,fe]=(0,i.useState)(()=>typeof window<`u`&&typeof window.matchMedia==`function`?window.matchMedia(`(min-width: 80rem)`).matches:!0),[pe,K]=(0,i.useState)(()=>typeof window<`u`&&typeof window.matchMedia==`function`?window.matchMedia(`(min-width: 64rem)`).matches:!0),me=(0,i.useRef)(null),q=(0,i.useRef)(null),he=(0,i.useRef)(null),ge=(0,i.useRef)(0),ve=(0,i.useRef)(null),ye=(0,i.useRef)(null),be=(0,i.useRef)(null),[xe,Se]=(0,i.useState)(!1),[Y,Ce]=(0,i.useState)(!1),[we,Te]=(0,i.useState)(!1),De=(0,i.useCallback)(()=>{let e=q.current,t=he.current;e&&(Y?(document.body.style.overflow=``,Object.assign(e.style,{position:``,top:``,left:``,width:``,height:``,zIndex:``,background:``,borderRadius:``,overflow:``,display:``,flexDirection:``}),t&&Object.assign(t.style,{flex:``,overflow:``,minHeight:``}),Ce(!1),requestAnimationFrame(()=>{window.scrollTo(0,ge.current)})):(document.fullscreenElement&&document.exitFullscreen(),ge.current=window.scrollY,Object.assign(e.style,{position:`fixed`,top:`0`,left:`0`,width:`100vw`,height:`100vh`,zIndex:`99999`,background:`var(--background, #fff)`,borderRadius:`0`,overflow:`hidden`,display:`flex`,flexDirection:`column`}),t&&Object.assign(t.style,{flex:`1`,overflow:`auto`,minHeight:`0`}),document.body.style.overflow=`hidden`,Ce(!0)))},[Y]),Oe=(0,i.useCallback)(()=>{let e=q.current;e&&(document.fullscreenElement?document.exitFullscreen():(Y&&De(),ge.current=window.scrollY,e.requestFullscreen()))},[Y,De]);(0,i.useEffect)(()=>{let e=e=>{e.key===`Escape`&&Y&&De()},t=()=>{document.fullscreenElement?Te(!0):(Te(!1),requestAnimationFrame(()=>{window.scrollTo(0,ge.current)}))};return window.addEventListener(`keydown`,e),document.addEventListener(`fullscreenchange`,t),()=>{window.removeEventListener(`keydown`,e),document.removeEventListener(`fullscreenchange`,t)}},[Y,De]),(0,i.useEffect)(()=>{if(!b)return;let e=e=>{if((e.ctrlKey||e.metaKey)&&(e.key===`f`||e.key===`F`)){if(!q.current)return;e.preventDefault(),e.stopPropagation(),ue(!0)}};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[b]),(0,i.useEffect)(()=>{if(typeof window>`u`||typeof window.matchMedia!=`function`)return;let e=window.matchMedia(`(min-width: 80rem)`),t=e=>fe(e.matches);return fe(e.matches),e.addEventListener(`change`,t),()=>e.removeEventListener(`change`,t)},[]),(0,i.useEffect)(()=>{if(typeof window>`u`||typeof window.matchMedia!=`function`)return;let e=window.matchMedia(`(min-width: 64rem)`),t=e=>K(e.matches);return K(e.matches),e.addEventListener(`change`,t),()=>e.removeEventListener(`change`,t)},[]);let X=(0,c.useEditor)({extensions:gr({placeholder:r||e.o(`editor.placeholder`),maxLength:f,maxAttachmentSize:p,maxTotalAttachmentSize:m}),content:T,editable:!w,immediatelyRender:S,onUpdate:({editor:e})=>{n&&(me.current&&clearTimeout(me.current),me.current=setTimeout(()=>{n?.(e.getHTML(),e.getJSON())},300))},onCreate:()=>{},editorProps:{attributes:{class:`prose prose-neutral dark:prose-invert max-w-none focus:outline-none min-h-[200px] px-4 sm:px-8 py-4`},handlePaste(e,t){let n=t.clipboardData;if(!n)return!1;let r=n.getData(`text/plain`);if(!r||!r.includes(`[[`))return!1;t.preventDefault();let i=ye.current?.storage?.relativeMedia;i&&(i.clipboardFiles=new Map(Array.from(n.files??[]).map(e=>[e.name.toLowerCase(),e])),i.pausedUntilPaste=!1);let a=ye.current?Nr(ye.current,r):null;if(a){let t=new s.Slice(a,0,0);e.dispatch(e.state.tr.replaceSelection(t).scrollIntoView())}else e.dispatch(e.state.tr.insertText(r).scrollIntoView());return!0}}});(0,i.useEffect)(()=>{ye.current=X,window.__editor=X},[X]),(0,i.useEffect)(()=>{if(X)return()=>lt(X)},[X]),(0,i.useEffect)(()=>{!X||!x||x(X)},[X,x]),(0,i.useEffect)(()=>{if(!X)return;let e=()=>{X.state.selection.empty&&(R(`none`),Se(!1))};return X.on(`selectionUpdate`,e),()=>{X.off(`selectionUpdate`,e)}},[X]),(0,i.useEffect)(()=>{X&&X.setOptions({extensions:gr({placeholder:r||e.o(`editor.placeholder`),maxLength:f,maxAttachmentSize:p,maxTotalAttachmentSize:m})})},[r,f,p,m]);let ke=(0,i.useRef)(t);(0,i.useEffect)(()=>{if(!X||t===ke.current)return;ke.current=t;let n=Mr(t)?t:e.n(t);X.commands.setContent(n,{emitUpdate:!1})},[X,t]),(0,i.useEffect)(()=>{X&&X.setEditable(!w,!1)},[X,w]),(0,i.useEffect)(()=>{if(C)return _e(C)},[C]),(0,i.useEffect)(()=>{if(!X)return;let e=bt(X.state.doc);e>m&&J(`文档内附件总大小 ${xt(e)} 已超过限制 ${xt(m)}`,`info`)},[X,m]),(0,i.useEffect)(()=>{if(!X)return;let e=X.storage.qingwuUI;e&&(e.limits={maxAttachmentSize:p,maxTotalAttachmentSize:m})},[X,p,m]);let Ae=(0,i.useCallback)(e=>{let t=be.current?.getBoundingClientRect();R(e),Se(!1),B({position:`fixed`,top:t?t.bottom+8:void 0,left:t?Math.max(8,Math.min(t.left,window.innerWidth-240)):8,zIndex:9999})},[]),je=br(t=>e.o(t)),Me=je.filter(e=>!e.more),Ne=je.filter(e=>e.more),Pe=Me.filter(e=>e.key!==`ai`),Fe=Me.find(e=>e.key===`ai`),Z=(0,i.useCallback)(e=>{if(X)if(Se(!1),e.key===`link`)if(X.isActive(`link`))X.chain().focus().unsetLink().run();else{let e=X.getAttributes(`link`).href||``;oe(e),Ae(`link`)}else e.key===`highlight`?L===`highlight`?R(`none`):Ae(`highlight`):e.command(X)},[X,L,Ae]),Ie=(0,i.useCallback)(e=>X?e.key===`highlight`?L===`highlight`:e.key===`link`?X.isActive(`link`):e.isActive(X):!1,[X,L]),[Le,Re]=(0,i.useState)(0);(0,i.useEffect)(()=>{if(!X)return;let e=()=>Re(e=>(e+1)%1e6);return X.on(`update`,e),()=>{X.off(`update`,e)}},[X]);let[ze,Be]=(0,i.useState)(!1);(0,i.useEffect)(()=>{if(!X)return;let e=()=>{let e=!1;X.state.doc.descendants(t=>{t.type.name===`heading`&&(e=!0)}),Be(e)};return e(),X.on(`update`,e),()=>{X.off(`update`,e)}},[X]);let Ve=(0,i.useMemo)(()=>X?.storage?.characterCount?.characters?.()??0,[X,Le]),Q=f?Ve>f:!1;(0,i.useEffect)(()=>()=>{me.current&&clearTimeout(me.current)},[]),(0,i.useEffect)(()=>()=>{H&&H.resolve(null)},[]);let Ue=(0,i.useCallback)(e=>{if(!X?.isEditable)return;let t=window.getSelection(),n;if(e){let t=e.getBoundingClientRect();n={top:t.bottom,left:t.left,width:t.width}}else if(t&&t.rangeCount>0&&!t.isCollapsed){let e=t.getRangeAt(0).getBoundingClientRect();n={top:e.bottom,left:e.left,width:e.width}}else{let e=X.view.coordsAtPos(X.state.selection.from);n={top:e.bottom,left:e.left,width:0}}ve.current=n;let r=q.current?.getBoundingClientRect(),i=jr(n,void 0,{panelWidth:r?.width,editorLeft:r?.left});D(!0),k(i.style),j(i.placement),M(i.arrowLeft)},[X]);(0,i.useEffect)(()=>{if(!X)return;let e=X.storage.qingwuUI;if(e)return e.openImageDialog=()=>te(!0),e.openVideoDialog=()=>I(!0),e.chooseMd=(e,t)=>{U({filename:e,resolve:t})},e.openAI=Ue,e.parseMd=(e,t)=>X?Nr(X,t):null,()=>{delete e.openImageDialog,delete e.openVideoDialog,delete e.openAI,delete e.parseMd,delete e.chooseMd}},[X,Ue]),(0,i.useLayoutEffect)(()=>{if(!E||!X)return;let e=ve.current;if(!e)return;let t=N.current,n=q.current?.getBoundingClientRect(),r=jr(e,t?.offsetHeight||void 0,{panelWidth:n?.width,editorLeft:n?.left});j(r.placement),M(r.arrowLeft),k(r.style)},[E,X]),(0,i.useEffect)(()=>{if(!E||!X)return;let e=()=>{let e=ve.current;if(!e)return;let t=N.current,n=q.current?.getBoundingClientRect(),r=jr(e,t?.offsetHeight||void 0,{panelWidth:n?.width,editorLeft:n?.left});j(r.placement),M(r.arrowLeft),k(r.style)};return window.addEventListener(`resize`,e),()=>window.removeEventListener(`resize`,e)},[E,X]),(0,i.useEffect)(()=>{E||(ve.current=null)},[E]);let We=(0,i.useCallback)(e=>{X?.chain().focus().setImage({src:e}).run()},[X]),Ge=(0,i.useCallback)(e=>{(X?.commands).insertVideo?.({src:e})},[X]),Ke=W&&de&&!Y&&!we,qe=!Ke&&!G&&(W||ze&&!(!w&&pe)),Je=(0,i.useRef)(!1);return(0,i.useEffect)(()=>{Je.current||(Je.current=!0,W&&!Ke&&ce(!0))},[W,Ke]),X?(0,a.jsxs)(`div`,{className:`qingwu-editor-row`,children:[(0,a.jsxs)(`div`,{ref:q,className:`qingwu-editor relative flex-1 min-w-0 bg-background ${w?`qingwu-editor--readonly`:``} ${g?``:`rounded-xl border border-default-200`} ${h}`,style:_,children:[v&&(0,a.jsxs)(`div`,{className:`qed-toolbar`,children:[(0,a.jsxs)(`div`,{className:`qed-toolbar__group`,children:[(0,a.jsx)(`button`,{type:`button`,className:`qed-tb-btn qed-tb-btn--desktop-only${W?` is-active`:``}`,onClick:()=>{W?(se(!1),ce(!1)):(se(!0),de&&!Y&&!we||ce(!0))},title:W?`隐藏目录`:`显示目录`,"aria-label":W?`隐藏目录`:`显示目录`,"aria-pressed":W,children:(0,a.jsx)(`svg`,{fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,strokeWidth:2,"aria-hidden":`true`,children:(0,a.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M4 6h16M4 12h10M4 18h7`})})}),b&&(0,a.jsx)(`button`,{type:`button`,className:`qed-tb-btn${le?` is-active`:``}`,onClick:()=>ue(!le),title:`查找 (Ctrl+F)`,"aria-label":`查找`,"aria-pressed":le,children:(0,a.jsx)(`svg`,{fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,strokeWidth:2,"aria-hidden":`true`,children:(0,a.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M21 21l-6-6m2-5a7 7 0 11-14 0 7 7 0 0114 0z`})})}),!w&&(0,a.jsx)(`button`,{type:`button`,className:`qed-tb-btn qed-tb-btn--ai${E?` is-active`:``}`,onClick:e=>E?D(!1):Ue(e.currentTarget),title:e.o(`editor.toolbar.aiTitle`),"aria-label":e.o(`editor.toolbar.ai`),"aria-pressed":E,children:(0,a.jsxs)(`svg`,{fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,strokeWidth:2,"aria-hidden":`true`,children:[(0,a.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M12 3l1.6 4.4L18 9l-4.4 1.6L12 15l-1.6-4.4L6 9l4.4-1.6L12 3z`}),(0,a.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M18.5 14l.7 1.9 1.9.7-1.9.7-.7 1.9-.7-1.9-1.9-.7 1.9-.7.7-1.9z`})]})})]}),(0,a.jsxs)(`div`,{className:`qed-toolbar__group`,children:[(0,a.jsxs)(`button`,{type:`button`,className:`qed-tb-btn qed-tb-btn--solid`,onClick:()=>ae(!0),title:e.o(`editor.toolbar.exportTitle`),children:[(0,a.jsx)(`svg`,{fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,strokeWidth:2,"aria-hidden":`true`,children:(0,a.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M4 16v1a3 3 0 003 3h10a3 3 0 003-3v-1m-4-4l-4 4m0 0l-4-4m4 4V4`})}),(0,a.jsx)(`span`,{className:`qed-tb-btn__label`,children:e.o(`editor.toolbar.export`)})]}),(0,a.jsx)(`button`,{type:`button`,className:`qed-tb-btn${Y?` is-active`:``}`,onClick:De,title:Y?`退出网页全屏`:`网页全屏`,"aria-label":Y?`退出网页全屏`:`网页全屏`,"aria-pressed":Y,children:(0,a.jsx)(`svg`,{fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,strokeWidth:2,"aria-hidden":`true`,children:(0,a.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M8 3H5a2 2 0 00-2 2v3m18 0V5a2 2 0 00-2-2h-3m0 18h3a2 2 0 002-2v-3M3 16v3a2 2 0 002 2h3`})})}),(0,a.jsx)(`button`,{type:`button`,className:`qed-tb-btn${we?` is-active`:``}`,onClick:Oe,title:we?`退出全屏`:`全屏`,"aria-label":we?`退出全屏`:`全屏`,"aria-pressed":we,children:(0,a.jsx)(`svg`,{fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,strokeWidth:2,"aria-hidden":`true`,children:(0,a.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M15 3h6v6M9 21H3v-6M21 3l-7 7M3 21l7-7`})})})]})]}),X&&!w&&X.isEditable&&(0,a.jsx)(l.BubbleMenu,{editor:X,shouldShow:({editor:e,state:t})=>!(e.isActive(`image`)||e.isActive(`videoEmbed`)||e.isActive(`codeBlock`)||e.isActive(`audioEmbed`)||e.isActive(`attachmentEmbed`)||t.selection.empty),options:{placement:`bottom`,offset:8,flip:!0},className:`bubble-menu-pop bg-background border border-default-200 rounded-xl p-1 shadow-lg`,children:(0,a.jsxs)(`div`,{ref:be,className:`bubble-menu-items relative flex items-center gap-0.5`,onPointerDown:e=>{e.target.closest(`button`)&&e.preventDefault()},children:[Pe.map(e=>(0,a.jsx)(`button`,{type:`button`,className:`flex items-center justify-center w-7 h-7 rounded-lg transition-colors ${e.isActive(X)?`bg-primary/10 text-primary`:`text-default-600 hover:bg-default-100`}`,onClick:t=>{t.preventDefault(),Z(e)},title:e.label,"aria-label":e.label,children:e.icon},e.key)),(0,a.jsx)(`span`,{className:`w-px h-4 bg-default-200 mx-0.5 shrink-0`,"aria-hidden":`true`}),(0,a.jsx)(`button`,{type:`button`,className:`flex items-center justify-center w-7 h-7 rounded-lg transition-colors ${E?`bg-primary/15 text-primary`:`text-primary hover:bg-primary/10`}`,onClick:e=>{e.preventDefault(),Se(!1),Fe?.command(X)},title:Fe?.label,"aria-label":Fe?.label,children:(0,a.jsx)($e,{})}),(0,a.jsx)(`span`,{className:`w-px h-4 bg-default-200 mx-0.5 shrink-0`,"aria-hidden":`true`}),(0,a.jsx)(`button`,{type:`button`,"aria-expanded":xe,className:`flex items-center justify-center w-7 h-7 rounded-lg transition-colors ${xe?`bg-default-100 text-default-900`:`text-default-600 hover:bg-default-100`}`,onClick:e=>{e.preventDefault(),Se(e=>!e)},title:e.o(`editor.bubble.more`),"aria-label":e.o(`editor.bubble.more`),children:(0,a.jsx)(et,{})}),xe&&(0,a.jsx)(`div`,{role:`menu`,className:`bubble-more-menu absolute right-0 top-full z-[9999] mt-1 w-max max-h-[70vh] overflow-y-auto flex-col gap-1 rounded-xl border border-default-200 bg-background p-1.5 shadow-xl`,onPointerDown:e=>{e.target.closest(`button`)&&e.preventDefault()},children:Ne.map(e=>(0,a.jsxs)(`button`,{type:`button`,role:`menuitem`,className:`flex items-center gap-2 w-full whitespace-nowrap px-3 py-1.5 text-xs rounded-md transition-colors ${Ie(e)?`bg-primary/10 text-primary`:`text-default-600 hover:bg-default-100`}`,onClick:t=>{t.preventDefault(),Z(e)},title:e.label,children:[(0,a.jsx)(`span`,{className:`w-4 h-4 flex items-center justify-center shrink-0`,children:e.icon}),(0,a.jsx)(`span`,{className:`tracking-wide`,children:e.label})]},e.key))})]})}),X&&L!==`none`&&(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(`div`,{className:`fixed inset-0 z-[9998]`,onClick:()=>R(`none`)}),(0,a.jsx)(`div`,{style:z,className:`bg-background border border-default-200 rounded-xl shadow-xl`,onClick:e=>e.stopPropagation(),children:L===`highlight`?(0,a.jsxs)(`div`,{className:`flex items-center gap-1 p-1.5 flex-wrap`,children:[Dr.map(e=>(0,a.jsx)(`button`,{type:`button`,className:`w-5 h-5 rounded-full border border-default-200 hover:scale-110 transition-transform`,style:{background:e.color},title:e.name,onClick:()=>{X.chain().focus().setHighlight({color:e.color}).run(),R(`none`)}},e.color)),(0,a.jsxs)(`button`,{type:`button`,className:`w-5 h-5 rounded-full border border-default-200 text-default-500 hover:bg-default-100 flex items-center justify-center text-[10px]`,title:`清除高亮`,onClick:()=>{X.chain().focus().unsetHighlight().run(),R(`none`)},children:[`✕`,` `]})]}):(0,a.jsxs)(`div`,{className:`flex items-center gap-1.5 p-1.5`,children:[(0,a.jsx)(`input`,{type:`url`,autoFocus:!0,className:`flex-1 px-2 py-1 text-xs rounded-md border border-default-200 bg-background focus:outline-none focus:border-primary`,placeholder:`https://...`,value:V,onChange:e=>oe(e.target.value),onKeyDown:e=>{e.key===`Enter`?(V.trim()&&X.chain().focus().setLink({href:V.trim()}).run(),R(`none`)):e.key===`Escape`&&R(`none`)}}),(0,a.jsx)(`button`,{type:`button`,className:`px-2 py-1 text-xs rounded-md bg-primary text-white hover:opacity-90`,onClick:()=>{V.trim()&&X.chain().focus().setLink({href:V.trim()}).run(),R(`none`)},children:`确定`})]})})]}),!w&&E&&(0,u.createPortal)((0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(`div`,{className:`fixed inset-0 z-[9998]`,onClick:()=>D(!1)}),(0,a.jsxs)(`div`,{ref:N,"data-lenis-prevent":!0,style: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:`${ee}%`},"aria-hidden":`true`}),(0,a.jsx)(vt,{editor:X,onClose:()=>D(!1)})]})]}),document.body),P&&(0,a.jsx)(i.Suspense,{fallback:(0,a.jsx)(zr,{}),children:(0,a.jsx)(Pr,{open:P,onClose:()=>te(!1),onInsert:We,validate:e=>X?Ct(X.state.doc,e,{maxAttachmentSize:p,maxTotalAttachmentSize:m}):null})}),F&&(0,a.jsx)(i.Suspense,{fallback:(0,a.jsx)(zr,{}),children:(0,a.jsx)(Lr,{open:F,onClose:()=>I(!1),onInsert:Ge})}),ne&&(0,a.jsx)(i.Suspense,{fallback:(0,a.jsx)(zr,{}),children:(0,a.jsx)(Fr,{open:ne,onClose:()=>re(!1)})}),ie&&(0,a.jsx)(i.Suspense,{fallback:(0,a.jsx)(zr,{}),children:(0,a.jsx)(Ir,{open:ie,onClose:()=>ae(!1),editor:X})}),H&&(0,a.jsx)(i.Suspense,{fallback:(0,a.jsx)(zr,{}),children:(0,a.jsx)(Rr,{open:!!H,filename:H.filename,onRender:()=>{H.resolve(`render`),U(null)},onAttach:()=>{H.resolve(`attach`),U(null)},onClose:()=>{H.resolve(null),U(null)}})}),(0,a.jsx)(`div`,{ref:he,className:`flex editor-body`,children:(0,a.jsxs)(`div`,{className:`relative min-w-0 flex-1`,children:[(0,a.jsx)(c.EditorContent,{editor:X}),!w&&(0,a.jsx)(Er,{editor:X}),(0,a.jsx)(`div`,{className:`${Y||we?`fixed`:`absolute`} bottom-2 right-4 z-10 pointer-events-none select-none`,children:(0,a.jsxs)(`span`,{className:`text-xs ${Q?`bg-danger/10 text-danger font-medium px-2 py-0.5 rounded`:f&&Ve>f*.9?`bg-warning/10 text-warning px-2 py-0.5 rounded`:`text-default-300`}`,children:[Ve,f?` / ${f}`:``,` 字`]})})]})}),b&&le&&(0,a.jsx)(He,{editor:X,onClose:()=>ue(!1)}),qe&&(0,a.jsx)(`button`,{type:`button`,className:`qingwu-toc-fab`,onClick:()=>ce(!0),title:`目录`,"aria-label":`打开目录`,children:(0,a.jsx)(`svg`,{fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,strokeWidth:2,"aria-hidden":`true`,children:(0,a.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M4 6h16M4 12h10M4 18h7`})})}),G&&(0,a.jsxs)(`div`,{className:`qingwu-toc-drawer toc-scroll`,children:[(0,a.jsxs)(`div`,{className:`qed-drawer-head`,children:[(0,a.jsx)(`span`,{className:`qed-drawer-head__title`,children:`目录`}),(0,a.jsx)(`button`,{type:`button`,className:`qed-drawer-head__close`,onClick:()=>ce(!1),"aria-label":`关闭目录`,children:(0,a.jsx)(`svg`,{fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,strokeWidth:2,"aria-hidden":`true`,children:(0,a.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M6 18L18 6M6 6l12 12`})})})]}),(0,a.jsx)(Ee,{editor:X,className:`!p-3`,onClose:()=>{ce(!1),se(!1)}})]})]}),Ke&&(0,a.jsx)(`aside`,{className:`qingwu-toc-desktop toc-scroll`,children:(0,a.jsx)(Ee,{editor:X,onClose:()=>se(!1)})})]}):(0,a.jsx)(`div`,{className:`flex items-center justify-center h-32 text-default-400`,children:e.o(`editor.loading`)})};function Vr(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 Hr(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 Ur(e){return r.n({endpoint:`https://${e.bucket}.${e.region}.aliyuncs.com`,bucket:e.bucket,region:e.region,accessKeyId:e.accessKeyId,secretAccessKey:e.accessKeySecret,customDomain:e.customDomain,uploadPrefix:e.uploadPrefix,nameTemplate:e.nameTemplate})}exports.CODE_LANGUAGES=mn,exports.CodeBlock=gn,exports.ImageUpload=Bn,exports.ImageUploadDialog=ye,exports.QingWuAIEditor=Br,exports.RelativeMedia=dr,exports.SearchHighlight=Be,exports.TocPanel=Ee,exports.VideoEmbed=on,exports.buildSystemPrompt=De,exports.createAILanguageModelProvider=X,exports.createCOSStorage=Hr,exports.createDeepSeekProvider=Me,exports.createLocalStorage=r.t,exports.createOSSStorage=Ur,exports.createOpenAICompatProvider=je,exports.createOpenAIProvider=Ne,exports.createQwenProvider=Pe,exports.createS3Storage=r.n,exports.createSlashCommandExtension=pr,exports.escapeHtml=e.t,exports.formatBytes=xt,exports.getAIProvider=Ae,exports.getBubbleMenuActions=br,exports.getDefaultSlashCommands=mr,exports.getDocAttachmentTotal=bt,exports.getEditorExtensions=gr,exports.getLocale=e.i,exports.getSearchEngine=yr,exports.getSearchState=Ve,exports.getStorageInfo=n.t,exports.getStorageProvider=n.n,exports.loadStorageConfig=n.r,exports.registerS3PreviewConfig=t.t,exports.sanitizeHtml=e.n,exports.sanitizeSvg=e.r,exports.setAIProvider=ke,exports.setConfirmProvider=kt,exports.setLocale=e.a,exports.setSearchEngine=vr,exports.setStorageProvider=n.a,exports.setToastProvider=ge,exports.signPreviewUrlHeaders=t.r,exports.startBrowserClipperReceiver=Vr,exports.subscribeToast=_e,exports.t=e.o,exports.tf=e.s,exports.toast=J,exports.validateAttachmentFile=Ct;
9
+ `)}function Tr(e){let t=e.trim();if(!t)return null;let n=t.split(/\r?\n/);if(n.length>=2&&n.every(e=>e.includes(`|`))){let e=n.filter(e=>!/^\s*\|?[\s:|-]+\|?\s*$/.test(e)).map(e=>e.replace(/^\s*\|/,``).replace(/\|\s*$/,``).split(`|`).map(e=>e.trim()));if(e.length>0&&e[0].length>1)return e}if(n.length>=1){let e=n[0].includes(` `)?` `:`,`,t=n.map(t=>t.split(e).map(e=>e.trim()));if(t.length>0&&t[0].length>1)return t}return null}function Er({editor:e}){let[t,n]=(0,i.useState)(null),[r,o]=(0,i.useState)(!1),[s,c]=(0,i.useState)(!1),l=(0,i.useRef)(null),u=(0,i.useRef)(null),d=e.isEditable,f=(0,i.useCallback)(()=>{u.current!=null&&cancelAnimationFrame(u.current),u.current=requestAnimationFrame(()=>{u.current=null;let n=l.current;if(n==null||t==null)return;let r=e.view.nodeDOM(t);if(!(r instanceof HTMLElement))return;let i=r.getBoundingClientRect(),a=i.top>40?i.top-34:Math.min(i.bottom+4,window.innerHeight-40);n.style.top=`${a}px`,n.style.left=`${Math.max(8,Math.min(i.left,window.innerWidth-160))}px`})},[e,t]),p=(0,i.useCallback)(()=>{if(!e.isEditable||!e.isActive(`table`)){n(null);return}let t=xr(e);if(!t){n(null);return}n(e=>e===t.pos?e:t.pos)},[e]);(0,i.useEffect)(()=>(p(),e.on(`selectionUpdate`,p),e.on(`focus`,p),window.addEventListener(`scroll`,f,!0),window.addEventListener(`resize`,f),()=>{e.off(`selectionUpdate`,p),e.off(`focus`,p),window.removeEventListener(`scroll`,f,!0),window.removeEventListener(`resize`,f),u.current!=null&&cancelAnimationFrame(u.current)}),[e,p,f]),(0,i.useEffect)(()=>{f()},[t,f]);let m=t=>{let{schema:n}=e.state;if(!n.nodes.table||!n.nodes.tableRow||!n.nodes.tableCell||!n.nodes.tableHeader)return null;let r=Math.max(...t.map(e=>e.length)),i=t.map((e,t)=>{let i=[];for(let a=0;a<r;a++){let r=e[a]??``,o=t===0?n.nodes.tableHeader:n.nodes.tableCell,s=r?n.text(r):null;i.push(o.create(null,s?[s]:[]))}return n.nodes.tableRow.create(null,i)});return n.nodes.table.create(null,i)},h=()=>{let t=xr(e);if(!t)return;let n=Cr(Sr(t.node));navigator.clipboard?.writeText(n),o(!0),setTimeout(()=>o(!1),1500)},g=()=>{let t=xr(e);if(!t)return;let n=wr(Sr(t.node)),r=new Blob([`\ufeff${n}`],{type:`text/csv;charset=utf-8`}),i=URL.createObjectURL(r),a=document.createElement(`a`);a.href=i,a.download=`table.csv`,document.body.appendChild(a),a.click(),document.body.removeChild(a),URL.revokeObjectURL(i)},_=async()=>{if(d)try{let t=await navigator.clipboard?.readText();if(!t)return;let n=Tr(t);if(!n||n.length===0)return;let r=m(n);if(!r)return;let i=xr(e),a=e.chain().focus();if(i){let t=Math.min(i.pos+i.node.nodeSize,e.state.doc.content.size);a.setTextSelection(t)}a.insertContent(r).run()}catch{}},v=()=>{d&&t!=null&&(e.chain().focus().setNodeSelection(t).run(),e.storage.qingwuUI?.openAI?.())},y=()=>{d&&e.chain().focus().deleteTable().run()};return!d||t==null?null:(0,a.jsxs)(`div`,{ref:l,style:{position:`fixed`,top:0,left:0,zIndex:1e5},className:`tbl-toolbar`,contentEditable:!1,children:[(0,a.jsx)(`button`,{type:`button`,className:`tbl-btn`,onClick:h,title:`复制`,children:r?(0,a.jsx)(`svg`,{className:`tbl-btn-icon tbl-btn-icon--check`,width:`14`,height:`14`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,children:(0,a.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M5 13l4 4L19 7`})}):(0,a.jsx)(`svg`,{className:`tbl-btn-icon`,width:`14`,height:`14`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,children:(0,a.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M8 5H6a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2v-2M8 5a2 2 0 002 2h2a2 2 0 002-2M8 5a2 2 0 012-2h2a2 2 0 012 2m0 0h2a2 2 0 012 2v3`})})}),(0,a.jsx)(`button`,{type:`button`,className:`tbl-btn`,onClick:g,title:`下载`,children:(0,a.jsx)(`svg`,{className:`tbl-btn-icon`,width:`14`,height:`14`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,children:(0,a.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M4 16v1a3 3 0 003 3h10a3 3 0 003-3v-1m-4-4l-4 4m0 0l-4-4m4 4V4`})})}),(0,a.jsx)(`button`,{type:`button`,className:`tbl-btn`,onClick:_,title:`粘贴`,children:(0,a.jsx)(`svg`,{className:`tbl-btn-icon`,width:`14`,height:`14`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,children:(0,a.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2`})})}),(0,a.jsx)(`button`,{type:`button`,className:`tbl-btn tbl-btn--ai`,onClick:v,title:`AI 助手`,children:(0,a.jsx)(`svg`,{className:`tbl-btn-icon`,width:`14`,height:`14`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,children:(0,a.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M13 10V3L4 14h7v7l9-11h-7z`})})}),(0,a.jsx)(`button`,{type:`button`,className:`tbl-btn tbl-btn--del`,onClick:()=>{!d||Dt()||($(!0),c(!0))},title:`删除`,children:(0,a.jsx)(`svg`,{className:`tbl-btn-icon`,width:`14`,height:`14`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,children:(0,a.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16`})})}),(0,a.jsx)(Mt,{open:s,title:`确认删除表格`,message:`此操作不可撤销。`,onCancel:()=>{$(!1),c(!1)},onConfirm:async()=>{await new Promise(e=>setTimeout(e,300)),$(!1),y()}})]})}var Dr=[{color:`#fef08a`,name:`黄`},{color:`#bbf7d0`,name:`绿`},{color:`#bfdbfe`,name:`蓝`},{color:`#fbcfe8`,name:`粉`},{color:`#fed7aa`,name:`橙`},{color:`#ddd6fe`,name:`紫`}],Or=288,kr=480,Ar=320;function jr(e,t,n={}){let r=window.innerWidth,i=window.innerHeight,a=Math.min(n.panelWidth||Or,kr,r-32),o=Math.max(t||Ar,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 Mr(e){return/(^|\n)```|(^|\n)#{1,6}\s|(^|\n)>\s?|(^|\n)\s*([-*_])(?:\s*\4){2,}\s*(?=\n|$)|(^|\n)\s*[-*+]\s+|(^|\n)\s*\d+[.)]\s+|(^|\n)\s*<img\s+|(^|\n)\s*\|.+\|/i.test(e)}function Nr(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 Pr=(0,i.lazy)(()=>Promise.resolve().then(()=>ve).then(e=>({default:e.ImageUploadDialog}))),Fr=(0,i.lazy)(()=>Promise.resolve().then(()=>require("./storage-settings-dialog-ZtMUoApJ.cjs")).then(e=>({default:e.StorageSettingsDialog}))),Ir=(0,i.lazy)(()=>Promise.resolve().then(()=>require("./export-dialog-BSEeEEHv.cjs")).then(e=>({default:e.ExportDialog}))),Lr=(0,i.lazy)(()=>Promise.resolve().then(()=>require("./video-embed-dialog-BbVHq51W.cjs")).then(e=>({default:e.VideoEmbedDialog}))),Rr=(0,i.lazy)(()=>Promise.resolve().then(()=>require("./md-import-dialog-CnstzrIK.cjs")).then(e=>({default:e.MdImportDialog}))),zr=()=>(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`})})]}),Br=({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)(()=>Mr(t)?t:e.n(t),[t]),[E,D]=(0,i.useState)(!1),[O,k]=(0,i.useState)({}),[A,j]=(0,i.useState)(`below`),[ee,M]=(0,i.useState)(50),N=(0,i.useRef)(null),[P,te]=(0,i.useState)(!1),[F,I]=(0,i.useState)(!1),[ne,re]=(0,i.useState)(!1),[ie,ae]=(0,i.useState)(!1),[L,R]=(0,i.useState)(`none`),[z,B]=(0,i.useState)({}),[V,oe]=(0,i.useState)(``),[H,U]=(0,i.useState)(null),[W,se]=(0,i.useState)(y),[G,ce]=(0,i.useState)(!1);(0,i.useEffect)(()=>{se(y)},[y]);let[le,ue]=(0,i.useState)(!1),[de,fe]=(0,i.useState)(()=>typeof window<`u`&&typeof window.matchMedia==`function`?window.matchMedia(`(min-width: 80rem)`).matches:!0),[pe,K]=(0,i.useState)(()=>typeof window<`u`&&typeof window.matchMedia==`function`?window.matchMedia(`(min-width: 64rem)`).matches:!0),me=(0,i.useRef)(null),q=(0,i.useRef)(null),he=(0,i.useRef)(null),ge=(0,i.useRef)(0),ve=(0,i.useRef)(null),ye=(0,i.useRef)(null),be=(0,i.useRef)(null),[xe,Se]=(0,i.useState)(!1),[Y,Ce]=(0,i.useState)(!1),[we,Te]=(0,i.useState)(!1),De=(0,i.useCallback)(()=>{let e=q.current,t=he.current;e&&(Y?(document.body.style.overflow=``,Object.assign(e.style,{position:``,top:``,left:``,width:``,height:``,zIndex:``,background:``,borderRadius:``,overflow:``,display:``,flexDirection:``}),t&&Object.assign(t.style,{flex:``,overflow:``,minHeight:``}),Ce(!1),requestAnimationFrame(()=>{window.scrollTo(0,ge.current)})):(document.fullscreenElement&&document.exitFullscreen(),ge.current=window.scrollY,Object.assign(e.style,{position:`fixed`,top:`0`,left:`0`,width:`100vw`,height:`100vh`,zIndex:`99999`,background:`var(--background, #fff)`,borderRadius:`0`,overflow:`hidden`,display:`flex`,flexDirection:`column`}),t&&Object.assign(t.style,{flex:`1`,overflow:`auto`,minHeight:`0`}),document.body.style.overflow=`hidden`,Ce(!0)))},[Y]),Oe=(0,i.useCallback)(()=>{let e=q.current;e&&(document.fullscreenElement?document.exitFullscreen():(Y&&De(),ge.current=window.scrollY,e.requestFullscreen()))},[Y,De]);(0,i.useEffect)(()=>{let e=e=>{e.key===`Escape`&&Y&&De()},t=()=>{document.fullscreenElement?Te(!0):(Te(!1),requestAnimationFrame(()=>{window.scrollTo(0,ge.current)}))};return window.addEventListener(`keydown`,e),document.addEventListener(`fullscreenchange`,t),()=>{window.removeEventListener(`keydown`,e),document.removeEventListener(`fullscreenchange`,t)}},[Y,De]),(0,i.useEffect)(()=>{if(!b)return;let e=e=>{if((e.ctrlKey||e.metaKey)&&(e.key===`f`||e.key===`F`)){if(!q.current)return;e.preventDefault(),e.stopPropagation(),ue(!0)}};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[b]),(0,i.useEffect)(()=>{if(typeof window>`u`||typeof window.matchMedia!=`function`)return;let e=window.matchMedia(`(min-width: 80rem)`),t=e=>fe(e.matches);return fe(e.matches),e.addEventListener(`change`,t),()=>e.removeEventListener(`change`,t)},[]),(0,i.useEffect)(()=>{if(typeof window>`u`||typeof window.matchMedia!=`function`)return;let e=window.matchMedia(`(min-width: 64rem)`),t=e=>K(e.matches);return K(e.matches),e.addEventListener(`change`,t),()=>e.removeEventListener(`change`,t)},[]);let X=(0,c.useEditor)({extensions:gr({placeholder:r||e.o(`editor.placeholder`),maxLength:f,maxAttachmentSize:p,maxTotalAttachmentSize:m}),content:T,editable:!w,immediatelyRender:S,onUpdate:({editor:e})=>{n&&(me.current&&clearTimeout(me.current),me.current=setTimeout(()=>{n?.(e.getHTML(),e.getJSON())},300))},onCreate:()=>{},editorProps:{attributes:{class:`prose prose-neutral dark:prose-invert max-w-none focus:outline-none min-h-[200px] px-4 sm:px-8 py-4`},handlePaste(e,t){let n=t.clipboardData;if(!n)return!1;let r=n.getData(`text/plain`);if(!r||!r.includes(`[[`))return!1;t.preventDefault();let i=ye.current?.storage?.relativeMedia;i&&(i.clipboardFiles=new Map(Array.from(n.files??[]).map(e=>[e.name.toLowerCase(),e])),i.pausedUntilPaste=!1);let a=ye.current?Nr(ye.current,r):null;if(a){let t=new s.Slice(a,0,0);e.dispatch(e.state.tr.replaceSelection(t).scrollIntoView())}else e.dispatch(e.state.tr.insertText(r).scrollIntoView());return!0}}});(0,i.useEffect)(()=>{ye.current=X,window.__editor=X},[X]),(0,i.useEffect)(()=>{if(X)return()=>lt(X)},[X]),(0,i.useEffect)(()=>{!X||!x||x(X)},[X,x]),(0,i.useEffect)(()=>{if(!X)return;let e=()=>{X.state.selection.empty&&(R(`none`),Se(!1))};return X.on(`selectionUpdate`,e),()=>{X.off(`selectionUpdate`,e)}},[X]),(0,i.useEffect)(()=>{X&&X.setOptions({extensions:gr({placeholder:r||e.o(`editor.placeholder`),maxLength:f,maxAttachmentSize:p,maxTotalAttachmentSize:m})})},[r,f,p,m]);let ke=(0,i.useRef)(t);(0,i.useEffect)(()=>{if(!X||t===ke.current)return;ke.current=t;let n=Mr(t)?t:e.n(t);X.commands.setContent(n,{emitUpdate:!1})},[X,t]),(0,i.useEffect)(()=>{X&&X.setEditable(!w,!1)},[X,w]),(0,i.useEffect)(()=>{if(C)return _e(C)},[C]),(0,i.useEffect)(()=>{if(!X)return;let e=bt(X.state.doc);e>m&&J(`文档内附件总大小 ${xt(e)} 已超过限制 ${xt(m)}`,`info`)},[X,m]),(0,i.useEffect)(()=>{if(!X)return;let e=X.storage.qingwuUI;e&&(e.limits={maxAttachmentSize:p,maxTotalAttachmentSize:m})},[X,p,m]);let Ae=(0,i.useCallback)(e=>{let t=be.current?.getBoundingClientRect();R(e),Se(!1),B({position:`fixed`,top:t?t.bottom+8:void 0,left:t?Math.max(8,Math.min(t.left,window.innerWidth-240)):8,zIndex:9999})},[]),je=br(t=>e.o(t)),Me=je.filter(e=>!e.more),Ne=je.filter(e=>e.more),Pe=Me.filter(e=>e.key!==`ai`),Fe=Me.find(e=>e.key===`ai`),Z=(0,i.useCallback)(e=>{if(X)if(Se(!1),e.key===`link`)if(X.isActive(`link`))X.chain().focus().unsetLink().run();else{let e=X.getAttributes(`link`).href||``;oe(e),Ae(`link`)}else e.key===`highlight`?L===`highlight`?R(`none`):Ae(`highlight`):e.command(X)},[X,L,Ae]),Ie=(0,i.useCallback)(e=>X?e.key===`highlight`?L===`highlight`:e.key===`link`?X.isActive(`link`):e.isActive(X):!1,[X,L]),[Le,Re]=(0,i.useState)(0);(0,i.useEffect)(()=>{if(!X)return;let e=()=>Re(e=>(e+1)%1e6);return X.on(`update`,e),()=>{X.off(`update`,e)}},[X]);let[ze,Be]=(0,i.useState)(!1);(0,i.useEffect)(()=>{if(!X)return;let e=()=>{let e=!1;X.state.doc.descendants(t=>{t.type.name===`heading`&&(e=!0)}),Be(e)};return e(),X.on(`update`,e),()=>{X.off(`update`,e)}},[X]);let Ve=(0,i.useMemo)(()=>X?.storage?.characterCount?.characters?.()??0,[X,Le]),Q=f?Ve>f:!1;(0,i.useEffect)(()=>()=>{me.current&&clearTimeout(me.current)},[]),(0,i.useEffect)(()=>()=>{H&&H.resolve(null)},[]);let Ue=(0,i.useCallback)(e=>{if(!X?.isEditable)return;let t=window.getSelection(),n;if(e){let t=e.getBoundingClientRect();n={top:t.bottom,left:t.left,width:t.width}}else if(t&&t.rangeCount>0&&!t.isCollapsed){let e=t.getRangeAt(0).getBoundingClientRect();n={top:e.bottom,left:e.left,width:e.width}}else{let e=X.view.coordsAtPos(X.state.selection.from);n={top:e.bottom,left:e.left,width:0}}ve.current=n;let r=q.current?.getBoundingClientRect(),i=jr(n,void 0,{panelWidth:r?.width,editorLeft:r?.left});D(!0),k(i.style),j(i.placement),M(i.arrowLeft)},[X]);(0,i.useEffect)(()=>{if(!X)return;let e=X.storage.qingwuUI;if(e)return e.openImageDialog=()=>te(!0),e.openVideoDialog=()=>I(!0),e.chooseMd=(e,t)=>{U({filename:e,resolve:t})},e.openAI=Ue,e.parseMd=(e,t)=>X?Nr(X,t):null,()=>{delete e.openImageDialog,delete e.openVideoDialog,delete e.openAI,delete e.parseMd,delete e.chooseMd}},[X,Ue]),(0,i.useLayoutEffect)(()=>{if(!E||!X)return;let e=ve.current;if(!e)return;let t=N.current,n=q.current?.getBoundingClientRect(),r=jr(e,t?.offsetHeight||void 0,{panelWidth:n?.width,editorLeft:n?.left});j(r.placement),M(r.arrowLeft),k(r.style)},[E,X]),(0,i.useEffect)(()=>{if(!E||!X)return;let e=()=>{let e=ve.current;if(!e)return;let t=N.current,n=q.current?.getBoundingClientRect(),r=jr(e,t?.offsetHeight||void 0,{panelWidth:n?.width,editorLeft:n?.left});j(r.placement),M(r.arrowLeft),k(r.style)};return window.addEventListener(`resize`,e),()=>window.removeEventListener(`resize`,e)},[E,X]),(0,i.useEffect)(()=>{E||(ve.current=null)},[E]);let We=(0,i.useCallback)(e=>{X?.chain().focus().setImage({src:e}).run()},[X]),Ge=(0,i.useCallback)(e=>{(X?.commands).insertVideo?.({src:e})},[X]),Ke=W&&de&&!Y&&!we,qe=!Ke&&!G&&(W||ze&&!(!w&&pe)),Je=(0,i.useRef)(!1);return(0,i.useEffect)(()=>{Je.current||(Je.current=!0,W&&!Ke&&ce(!0))},[W,Ke]),X?(0,a.jsxs)(`div`,{className:`qingwu-editor-row`,children:[(0,a.jsxs)(`div`,{ref:q,className:`qingwu-editor relative flex-1 min-w-0 bg-background ${w?`qingwu-editor--readonly`:``} ${g?``:`rounded-xl border border-default-200`} ${h}`,style:_,children:[v&&(0,a.jsxs)(`div`,{className:`qed-toolbar`,children:[(0,a.jsxs)(`div`,{className:`qed-toolbar__group`,children:[(0,a.jsx)(`button`,{type:`button`,className:`qed-tb-btn qed-tb-btn--desktop-only${W?` is-active`:``}`,onClick:()=>{W?(se(!1),ce(!1)):(se(!0),de&&!Y&&!we||ce(!0))},title:W?`隐藏目录`:`显示目录`,"aria-label":W?`隐藏目录`:`显示目录`,"aria-pressed":W,children:(0,a.jsx)(`svg`,{fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,strokeWidth:2,"aria-hidden":`true`,children:(0,a.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M4 6h16M4 12h10M4 18h7`})})}),b&&(0,a.jsx)(`button`,{type:`button`,className:`qed-tb-btn${le?` is-active`:``}`,onClick:()=>ue(!le),title:`查找 (Ctrl+F)`,"aria-label":`查找`,"aria-pressed":le,children:(0,a.jsx)(`svg`,{fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,strokeWidth:2,"aria-hidden":`true`,children:(0,a.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M21 21l-6-6m2-5a7 7 0 11-14 0 7 7 0 0114 0z`})})}),!w&&(0,a.jsx)(`button`,{type:`button`,className:`qed-tb-btn qed-tb-btn--ai${E?` is-active`:``}`,onClick:e=>E?D(!1):Ue(e.currentTarget),title:e.o(`editor.toolbar.aiTitle`),"aria-label":e.o(`editor.toolbar.ai`),"aria-pressed":E,children:(0,a.jsxs)(`svg`,{fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,strokeWidth:2,"aria-hidden":`true`,children:[(0,a.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M12 3l1.6 4.4L18 9l-4.4 1.6L12 15l-1.6-4.4L6 9l4.4-1.6L12 3z`}),(0,a.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M18.5 14l.7 1.9 1.9.7-1.9.7-.7 1.9-.7-1.9-1.9-.7 1.9-.7.7-1.9z`})]})})]}),(0,a.jsxs)(`div`,{className:`qed-toolbar__group`,children:[(0,a.jsxs)(`button`,{type:`button`,className:`qed-tb-btn qed-tb-btn--solid`,onClick:()=>ae(!0),title:e.o(`editor.toolbar.exportTitle`),children:[(0,a.jsx)(`svg`,{fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,strokeWidth:2,"aria-hidden":`true`,children:(0,a.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M4 16v1a3 3 0 003 3h10a3 3 0 003-3v-1m-4-4l-4 4m0 0l-4-4m4 4V4`})}),(0,a.jsx)(`span`,{className:`qed-tb-btn__label`,children:e.o(`editor.toolbar.export`)})]}),(0,a.jsx)(`button`,{type:`button`,className:`qed-tb-btn${Y?` is-active`:``}`,onClick:De,title:Y?`退出网页全屏`:`网页全屏`,"aria-label":Y?`退出网页全屏`:`网页全屏`,"aria-pressed":Y,children:(0,a.jsx)(`svg`,{fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,strokeWidth:2,"aria-hidden":`true`,children:(0,a.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M8 3H5a2 2 0 00-2 2v3m18 0V5a2 2 0 00-2-2h-3m0 18h3a2 2 0 002-2v-3M3 16v3a2 2 0 002 2h3`})})}),(0,a.jsx)(`button`,{type:`button`,className:`qed-tb-btn${we?` is-active`:``}`,onClick:Oe,title:we?`退出全屏`:`全屏`,"aria-label":we?`退出全屏`:`全屏`,"aria-pressed":we,children:(0,a.jsx)(`svg`,{fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,strokeWidth:2,"aria-hidden":`true`,children:(0,a.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M15 3h6v6M9 21H3v-6M21 3l-7 7M3 21l7-7`})})})]})]}),X&&!w&&X.isEditable&&(0,a.jsx)(l.BubbleMenu,{editor:X,shouldShow:({editor:e,state:t})=>!(e.isActive(`image`)||e.isActive(`videoEmbed`)||e.isActive(`codeBlock`)||e.isActive(`audioEmbed`)||e.isActive(`attachmentEmbed`)||t.selection.empty),options:{placement:`bottom`,offset:8,flip:!0},className:`bubble-menu-pop bg-background border border-default-200 rounded-xl p-1 shadow-lg`,children:(0,a.jsxs)(`div`,{ref:be,className:`bubble-menu-items relative flex items-center gap-0.5`,onPointerDown:e=>{e.target.closest(`button`)&&e.preventDefault()},children:[Pe.map(e=>(0,a.jsx)(`button`,{type:`button`,className:`flex items-center justify-center w-7 h-7 rounded-lg transition-colors ${e.isActive(X)?`bg-primary/10 text-primary`:`text-default-600 hover:bg-default-100`}`,onClick:t=>{t.preventDefault(),Z(e)},title:e.label,"aria-label":e.label,children:e.icon},e.key)),(0,a.jsx)(`span`,{className:`w-px h-4 bg-default-200 mx-0.5 shrink-0`,"aria-hidden":`true`}),(0,a.jsx)(`button`,{type:`button`,className:`flex items-center justify-center w-7 h-7 rounded-lg transition-colors ${E?`bg-primary/15 text-primary`:`text-primary hover:bg-primary/10`}`,onClick:e=>{e.preventDefault(),Se(!1),Fe?.command(X)},title:Fe?.label,"aria-label":Fe?.label,children:(0,a.jsx)($e,{})}),(0,a.jsx)(`span`,{className:`w-px h-4 bg-default-200 mx-0.5 shrink-0`,"aria-hidden":`true`}),(0,a.jsx)(`button`,{type:`button`,"aria-expanded":xe,className:`flex items-center justify-center w-7 h-7 rounded-lg transition-colors ${xe?`bg-default-100 text-default-900`:`text-default-600 hover:bg-default-100`}`,onClick:e=>{e.preventDefault(),Se(e=>!e)},title:e.o(`editor.bubble.more`),"aria-label":e.o(`editor.bubble.more`),children:(0,a.jsx)(et,{})}),xe&&(0,a.jsx)(`div`,{role:`menu`,className:`bubble-more-menu absolute right-0 top-full z-[9999] mt-1 w-max max-h-[70vh] overflow-y-auto flex-col gap-1 rounded-xl border border-default-200 bg-background p-1.5 shadow-xl`,onPointerDown:e=>{e.target.closest(`button`)&&e.preventDefault()},children:Ne.map(e=>(0,a.jsxs)(`button`,{type:`button`,role:`menuitem`,className:`flex items-center gap-2 w-full whitespace-nowrap px-3 py-1.5 text-xs rounded-md transition-colors ${Ie(e)?`bg-primary/10 text-primary`:`text-default-600 hover:bg-default-100`}`,onClick:t=>{t.preventDefault(),Z(e)},title:e.label,children:[(0,a.jsx)(`span`,{className:`w-4 h-4 flex items-center justify-center shrink-0`,children:e.icon}),(0,a.jsx)(`span`,{className:`tracking-wide`,children:e.label})]},e.key))})]})}),X&&L!==`none`&&(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(`div`,{className:`fixed inset-0 z-[9998]`,onClick:()=>R(`none`)}),(0,a.jsx)(`div`,{style:z,className:`bg-background border border-default-200 rounded-xl shadow-xl`,onClick:e=>e.stopPropagation(),children:L===`highlight`?(0,a.jsxs)(`div`,{className:`flex items-center gap-1 p-1.5 flex-wrap`,children:[Dr.map(e=>(0,a.jsx)(`button`,{type:`button`,className:`w-5 h-5 rounded-full border border-default-200 hover:scale-110 transition-transform`,style:{background:e.color},title:e.name,onClick:()=>{X.chain().focus().setHighlight({color:e.color}).run(),R(`none`)}},e.color)),(0,a.jsxs)(`button`,{type:`button`,className:`w-5 h-5 rounded-full border border-default-200 text-default-500 hover:bg-default-100 flex items-center justify-center text-[10px]`,title:`清除高亮`,onClick:()=>{X.chain().focus().unsetHighlight().run(),R(`none`)},children:[`✕`,` `]})]}):(0,a.jsxs)(`div`,{className:`flex items-center gap-1.5 p-1.5`,children:[(0,a.jsx)(`input`,{type:`url`,autoFocus:!0,className:`flex-1 px-2 py-1 text-xs rounded-md border border-default-200 bg-background focus:outline-none focus:border-primary`,placeholder:`https://...`,value:V,onChange:e=>oe(e.target.value),onKeyDown:e=>{e.key===`Enter`?(V.trim()&&X.chain().focus().setLink({href:V.trim()}).run(),R(`none`)):e.key===`Escape`&&R(`none`)}}),(0,a.jsx)(`button`,{type:`button`,className:`px-2 py-1 text-xs rounded-md bg-primary text-white hover:opacity-90`,onClick:()=>{V.trim()&&X.chain().focus().setLink({href:V.trim()}).run(),R(`none`)},children:`确定`})]})})]}),!w&&E&&(0,u.createPortal)((0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(`div`,{className:`fixed inset-0 z-[9998]`,onClick:()=>D(!1)}),(0,a.jsxs)(`div`,{ref:N,"data-lenis-prevent":!0,style: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:`${ee}%`},"aria-hidden":`true`}),(0,a.jsx)(vt,{editor:X,onClose:()=>D(!1)})]})]}),document.body),P&&(0,a.jsx)(i.Suspense,{fallback:(0,a.jsx)(zr,{}),children:(0,a.jsx)(Pr,{open:P,onClose:()=>te(!1),onInsert:We,validate:e=>X?Ct(X.state.doc,e,{maxAttachmentSize:p,maxTotalAttachmentSize:m}):null})}),F&&(0,a.jsx)(i.Suspense,{fallback:(0,a.jsx)(zr,{}),children:(0,a.jsx)(Lr,{open:F,onClose:()=>I(!1),onInsert:Ge})}),ne&&(0,a.jsx)(i.Suspense,{fallback:(0,a.jsx)(zr,{}),children:(0,a.jsx)(Fr,{open:ne,onClose:()=>re(!1)})}),ie&&(0,a.jsx)(i.Suspense,{fallback:(0,a.jsx)(zr,{}),children:(0,a.jsx)(Ir,{open:ie,onClose:()=>ae(!1),editor:X})}),H&&(0,a.jsx)(i.Suspense,{fallback:(0,a.jsx)(zr,{}),children:(0,a.jsx)(Rr,{open:!!H,filename:H.filename,onRender:()=>{H.resolve(`render`),U(null)},onAttach:()=>{H.resolve(`attach`),U(null)},onClose:()=>{H.resolve(null),U(null)}})}),(0,a.jsx)(`div`,{ref:he,className:`flex editor-body`,children:(0,a.jsxs)(`div`,{className:`relative min-w-0 flex-1`,children:[(0,a.jsx)(c.EditorContent,{editor:X}),!w&&(0,a.jsx)(Er,{editor:X}),(0,a.jsx)(`div`,{className:`${Y||we?`fixed`:`absolute`} bottom-2 right-4 z-10 pointer-events-none select-none`,children:(0,a.jsxs)(`span`,{className:`text-xs ${Q?`bg-danger/10 text-danger font-medium px-2 py-0.5 rounded`:f&&Ve>f*.9?`bg-warning/10 text-warning px-2 py-0.5 rounded`:`text-default-300`}`,children:[Ve,f?` / ${f}`:``,` 字`]})})]})}),b&&le&&(0,a.jsx)(He,{editor:X,onClose:()=>ue(!1)}),qe&&(0,a.jsx)(`button`,{type:`button`,className:`qingwu-toc-fab`,onClick:()=>ce(!0),title:`目录`,"aria-label":`打开目录`,children:(0,a.jsx)(`svg`,{fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,strokeWidth:2,"aria-hidden":`true`,children:(0,a.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M4 6h16M4 12h10M4 18h7`})})}),G&&(0,a.jsxs)(`div`,{className:`qingwu-toc-drawer toc-scroll`,children:[(0,a.jsxs)(`div`,{className:`qed-drawer-head`,children:[(0,a.jsx)(`span`,{className:`qed-drawer-head__title`,children:`目录`}),(0,a.jsx)(`button`,{type:`button`,className:`qed-drawer-head__close`,onClick:()=>ce(!1),"aria-label":`关闭目录`,children:(0,a.jsx)(`svg`,{fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,strokeWidth:2,"aria-hidden":`true`,children:(0,a.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M6 18L18 6M6 6l12 12`})})})]}),(0,a.jsx)(Ee,{editor:X,className:`!p-3`,onClose:()=>{ce(!1),se(!1)}})]})]}),Ke&&(0,a.jsx)(`aside`,{className:`qingwu-toc-desktop toc-scroll`,children:(0,a.jsx)(Ee,{editor:X,onClose:()=>se(!1)})})]}):(0,a.jsx)(`div`,{className:`flex items-center justify-center h-32 text-default-400`,children:e.o(`editor.loading`)})};function Vr(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 Hr(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 Ur(e){return r.n({endpoint:`https://${e.bucket}.${e.region}.aliyuncs.com`,bucket:e.bucket,region:e.region,accessKeyId:e.accessKeyId,secretAccessKey:e.accessKeySecret,customDomain:e.customDomain,uploadPrefix:e.uploadPrefix,nameTemplate:e.nameTemplate})}exports.CODE_LANGUAGES=mn,exports.CodeBlock=gn,exports.ImageUpload=Bn,exports.ImageUploadDialog=ye,exports.QingWuAIEditor=Br,exports.RelativeMedia=dr,exports.SearchHighlight=Be,exports.TocPanel=Ee,exports.VideoEmbed=on,exports.buildSystemPrompt=De,exports.createAILanguageModelProvider=X,exports.createCOSStorage=Hr,exports.createDeepSeekProvider=Me,exports.createLocalStorage=r.t,exports.createOSSStorage=Ur,exports.createOpenAICompatProvider=je,exports.createOpenAIProvider=Ne,exports.createQwenProvider=Pe,exports.createS3Storage=r.n,exports.createSlashCommandExtension=pr,exports.escapeHtml=e.t,exports.formatBytes=xt,exports.getAIProvider=Ae,exports.getBubbleMenuActions=br,exports.getDefaultSlashCommands=mr,exports.getDocAttachmentTotal=bt,exports.getEditorExtensions=gr,exports.getLocale=e.i,exports.getSearchEngine=yr,exports.getSearchState=Ve,exports.getStorageInfo=n.t,exports.getStorageProvider=n.n,exports.loadStorageConfig=n.r,exports.registerS3PreviewConfig=t.t,exports.sanitizeHtml=e.n,exports.sanitizeSvg=e.r,exports.setAIProvider=ke,exports.setConfirmProvider=kt,exports.setLocale=e.a,exports.setSearchEngine=vr,exports.setStorageProvider=n.a,exports.setToastProvider=ge,exports.signPreviewUrlHeaders=t.r,exports.startBrowserClipperReceiver=Vr,exports.subscribeToast=_e,exports.t=e.o,exports.tf=e.s,exports.toast=J,exports.validateAttachmentFile=Ct;
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { a as e, n as t, r as n, t as r } from "./signed-fetch-CPPWCUUS.js";
2
2
  import { a as i, i as a, n as o, r as s, t as c } from "./storage-DUcmM2Ex.js";
3
- import { a as l, i as u, n as d, o as f, r as p, s as m, t as h } from "./sanitize-OUn05c7P.js";
3
+ import { a as l, i as u, n as d, o as f, r as p, s as m, t as h } from "./sanitize-z8gMk0lV.js";
4
4
  import { n as g, t as _ } from "./local-B20eAPCo.js";
5
5
  import { Suspense as v, lazy as y, useCallback as b, useEffect as x, useLayoutEffect as S, useMemo as C, useRef as w, useState as T } from "react";
6
6
  import { Fragment as E, jsx as D, jsxs as O } from "react/jsx-runtime";
@@ -6437,7 +6437,7 @@ function hi(e, t) {
6437
6437
  return null;
6438
6438
  }
6439
6439
  }
6440
- var gi = y(() => Promise.resolve().then(() => Qe).then((e) => ({ default: e.ImageUploadDialog }))), _i = y(() => import("./storage-settings-dialog-DZqqDAiO.js").then((e) => ({ default: e.StorageSettingsDialog }))), vi = y(() => import("./export-dialog-DLCACwRK.js").then((e) => ({ default: e.ExportDialog }))), yi = y(() => import("./video-embed-dialog-AeGcMb4X.js").then((e) => ({ default: e.VideoEmbedDialog }))), bi = y(() => import("./md-import-dialog-Cf3ZOwA_.js").then((e) => ({ default: e.MdImportDialog }))), xi = () => /* @__PURE__ */ O("div", {
6440
+ var gi = y(() => Promise.resolve().then(() => Qe).then((e) => ({ default: e.ImageUploadDialog }))), _i = y(() => import("./storage-settings-dialog-DZqqDAiO.js").then((e) => ({ default: e.StorageSettingsDialog }))), vi = y(() => import("./export-dialog-CL7ie13Z.js").then((e) => ({ default: e.ExportDialog }))), yi = y(() => import("./video-embed-dialog-AeGcMb4X.js").then((e) => ({ default: e.VideoEmbedDialog }))), bi = y(() => import("./md-import-dialog-Cf3ZOwA_.js").then((e) => ({ default: e.MdImportDialog }))), xi = () => /* @__PURE__ */ O("div", {
6441
6441
  className: "fixed inset-0 z-[9999] flex items-center justify-center",
6442
6442
  children: [/* @__PURE__ */ D("div", { className: "absolute inset-0 bg-black/40 backdrop-blur-sm" }), /* @__PURE__ */ D("div", {
6443
6443
  className: "relative bg-background rounded-2xl border border-default-200 p-8 flex items-center justify-center",
@@ -1 +1 @@
1
- var e=Object.create,t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,r=Object.getOwnPropertyNames,i=Object.getPrototypeOf,a=Object.prototype.hasOwnProperty,o=(e,n)=>{let r={};for(var i in e)t(r,i,{get:e[i],enumerable:!0});return n||t(r,Symbol.toStringTag,{value:`Module`}),r},s=(e,i,o,s)=>{if(i&&typeof i==`object`||typeof i==`function`)for(var c=r(i),l=0,u=c.length,d;l<u;l++)d=c[l],!a.call(e,d)&&d!==o&&t(e,d,{get:(e=>i[e]).bind(null,d),enumerable:!(s=n(i,d))||s.enumerable});return e},c=(n,r,a)=>(a=n==null?{}:e(i(n)),s(r||!n||!n.__esModule?t(a,`default`,{value:n,enumerable:!0}):a,n));let l=require("dompurify");l=c(l,1);var u={"zh-CN":{editor:{placeholder:`输入 '/' 打开命令菜单,或继续输入内容…`,wordCount:`共 {count} 字`,characterCount:`共 {count} 字符`,toolbar:{export:`导出`,exportTitle:`导出文档`,ai:`AI 编写`,aiTitle:`AI 编写助手`},loading:`加载编辑器中…`,prompt:`输入 / 打开命令菜单 · 选中文本弹出格式菜单 · 点击写作助手辅助写作`,attachment:{preview:`预览`,download:`下载`,delete:`删除`,loadingPreview:`加载预览中…`,lost:`附件已丢失`},slash:{heading1:`一级标题`,heading1Desc:`大号标题`,heading2:`二级标题`,heading2Desc:`中号标题`,heading3:`三级标题`,heading3Desc:`小号标题`,heading4:`四级标题`,heading4Desc:`更小标题`,heading5:`五级标题`,heading5Desc:`小小标题`,heading6:`六级标题`,heading6Desc:`最小标题`,searchPlaceholder:`搜索命令…`,bulletList:`无序列表`,bulletListDesc:`创建无序列表`,numberedList:`有序列表`,numberedListDesc:`创建有序列表`,taskList:`任务列表`,taskListDesc:`创建可勾选的任务`,blockquote:`引用块`,blockquoteDesc:`插入引用`,codeBlock:`代码块`,codeBlockDesc:`插入代码块`,image:`图片`,imageDesc:`上传或粘贴图片`,horizontalRule:`分隔线`,horizontalRuleDesc:`插入分隔线`,video:`导入视频`,videoDesc:`导入 B站、直链 mp4/m3u8、小红书等视频`,audio:`导入音频`,audioDesc:`从本地选择音频文件,支持 mp3/wav/flac/aac 等`,attachment:`添加附件`,attachmentDesc:`上传任意类型文件,以附件链接形式插入`,xiaohongshu:`小红书`,xiaohongshuDesc:`嵌入小红书笔记`},bubble:{bold:`加粗`,italic:`斜体`,underline:`下划线`,strikethrough:`删除线`,code:`行内代码`,emphasis:`强调`,link:`链接`,highlight:`高亮`,copy:`复制`,search:`搜索`,table:`表格`,more:`更多`},ai:{trigger:`写作助手`,triggerDesc:`选中文字后选择 AI 操作,生成结果可替换或插入原文。`,close:`关闭`,continue:`续写`,continueDesc:`从当前位置继续写作`,improve:`润色`,improveDesc:`优化表达,提升文采`,shorter:`精简`,shorterDesc:`让文字更简洁`,longer:`扩写`,longerDesc:`丰富内容细节`,fix:`修正`,fixDesc:`修正语法和错别字`,translate:`翻译`,translateDesc:`翻译为其他语言`,zap:`自定义指令`,zapDesc:`输入自定义指令`,thinking:`正在思考…`,replace:`替换选中`,replaceAll:`全文替换`,replaceTitle:`确认替换选中`,replaceAllTitle:`确认全文替换`,replaceText:`将用 AI 生成结果替换当前选中内容。`,replaceAllText:`将用 AI 生成结果替换当前全部内容。`,removeNodes:`以下媒体节点将被移除:`,nodeImage:`图片`,nodeAttachment:`附件`,nodeVideo:`视频`,nodeAudio:`音频`,confirmReplace:`确认替换`,cancel:`取消`,insert:`在下方插入`,discard:`放弃`,error:`请求失败,请重试`,confirm:`确定`,back:`返回`,customPlaceholder:`例如:把这段内容改写成小红书风格`},export:{title:`导出文档`,html:`HTML`,htmlDesc:`导出为 HTML 文件`,json:`JSON (Tiptap)`,jsonDesc:`导出为 Tiptap JSON 格式`,md:`Markdown`,mdDesc:`导出为 Markdown 文件`,plainText:`纯文本`,plainTextDesc:`导出为纯文本`,pdf:`PDF`,pdfDesc:`打印为 PDF`,copy:`复制到剪贴板`,copied:`已复制`,download:`下载`},image:{upload:`上传图片`,uploading:`上传中…`,error:`上传失败`,dragTip:`拖拽图片到此处或点击上传`},link:{placeholder:`输入链接地址…`,save:`确定`,remove:`移除链接`}},app:{title:`青梧`,subtitle:`智能编辑器`,settings:`设置`,theme:{label:`主题`,light:`浅色`,dark:`深色`,system:`跟随系统`},themeToggle:{toDark:`切换深色`,toLight:`切换浅色`},font:{label:`字体`,sans:`默认字体`,serif:`宋体/衬线`,mono:`等宽字体`},language:`语言`,about:`关于青梧`,footer:{line1:`青梧 QingWu · 基于 Tiptap 构建 · 支持 DeepSeek / 通义千问 / OpenAI 等大模型`,license:`Apache-2.0 License`}},tour:{welcome:{title:`欢迎使用青梧编辑器`,description:`青梧是一款面向中文用户的 AI 智能编辑器,支持 Markdown、代码高亮、Mermaid 图表等丰富功能。点击「下一步」开始了解。`},mode:{title:`编辑 / 查看模式`,description:`点击此按钮可在「编辑模式」和「查看模式」之间切换。查看模式下内容只读,操作按钮会隐藏,适合阅读和展示。`},fullscreen:{title:`全屏模式`,description:`提供「网页全屏」和「浏览器全屏」两种沉浸式写作体验,让你专注于内容创作。`},ai:{title:`AI 写作助手`,description:`配置 DeepSeek、通义千问、OpenAI 等大模型后,可使用续写、润色、精简、扩写、修正、翻译等 AI 辅助功能。`},lang:{title:`中英文切换`,description:`编辑器和界面支持中文和英文两种语言,点击即可切换。`},font:{title:`字体切换`,description:`提供默认字体、衬线字体和等宽字体三种阅读体验,满足不同场景需求。`},editor:{title:`编辑器内容区`,description:`在此区域输入内容。输入 / 打开命令菜单插入各种元素,选中文本弹出格式菜单,点击写作助手触发 AI 辅助。`}}},"en-US":{editor:{placeholder:`Type '/' for commands, or continue writing…`,wordCount:`{count} words`,characterCount:`{count} characters`,toolbar:{export:`Export`,exportTitle:`Export Document`,ai:`AI Write`,aiTitle:`AI Writing Assistant`},loading:`Loading editor…`,prompt:`Type / for commands · Select text for formatting · Click Writing Assistant for help`,attachment:{preview:`Preview`,download:`Download`,delete:`Delete`,loadingPreview:`Loading preview…`,lost:`Attachment lost`},slash:{heading1:`Heading 1`,heading1Desc:`Large heading`,heading2:`Heading 2`,heading2Desc:`Medium heading`,heading3:`Heading 3`,heading3Desc:`Small heading`,heading4:`Heading 4`,heading4Desc:`Smaller heading`,heading5:`Heading 5`,heading5Desc:`Tiny heading`,heading6:`Heading 6`,heading6Desc:`Smallest heading`,searchPlaceholder:`Search commands…`,bulletList:`Bullet List`,bulletListDesc:`Create a bullet list`,numberedList:`Numbered List`,numberedListDesc:`Create a numbered list`,taskList:`Task List`,taskListDesc:`Create a task list`,blockquote:`Blockquote`,blockquoteDesc:`Insert a blockquote`,codeBlock:`Code Block`,codeBlockDesc:`Insert code block`,image:`Image`,imageDesc:`Upload or paste an image`,horizontalRule:`Divider`,horizontalRuleDesc:`Insert a divider`,video:`Import Video`,videoDesc:`Import Bilibili, direct mp4/m3u8, RedNote videos`,audio:`Import Audio`,audioDesc:`Select audio file from local (mp3/wav/flac/aac)`,attachment:`Add Attachment`,attachmentDesc:`Upload any file type as attachment link`,xiaohongshu:`RedNote`,xiaohongshuDesc:`Embed RedNote post`},bubble:{bold:`Bold`,italic:`Italic`,underline:`Underline`,strikethrough:`Strikethrough`,code:`Inline Code`,emphasis:`Emphasis`,link:`Link`,highlight:`Highlight`,copy:`Copy`,search:`Search`,table:`Table`,more:`More`},ai:{trigger:`Writing Assistant`,triggerDesc:`Select text and pick an AI action. The result can replace or insert into the document.`,close:`Close`,continue:`Continue`,continueDesc:`Continue writing from here`,improve:`Improve`,improveDesc:`Polish and improve text`,shorter:`Shorten`,shorterDesc:`Make it more concise`,longer:`Expand`,longerDesc:`Add more detail`,fix:`Fix`,fixDesc:`Fix grammar and typos`,translate:`Translate`,translateDesc:`Translate to another language`,zap:`Custom`,zapDesc:`Enter a custom command`,thinking:`Thinking…`,replace:`Replace selection`,replaceAll:`Replace all`,replaceTitle:`Replace selection`,replaceAllTitle:`Replace all content`,replaceText:`The AI result will replace the current selection.`,replaceAllText:`The AI result will replace the entire document.`,removeNodes:`The following media nodes will be removed:`,nodeImage:`Image`,nodeAttachment:`Attachment`,nodeVideo:`Video`,nodeAudio:`Audio`,confirmReplace:`Replace`,cancel:`Cancel`,insert:`Insert below`,discard:`Discard`,error:`Request failed, please retry`,confirm:`Confirm`,back:`Back`,customPlaceholder:`e.g. Rewrite this in a more casual tone`},export:{title:`Export Document`,html:`HTML`,htmlDesc:`Export as HTML`,json:`JSON (Tiptap)`,jsonDesc:`Export as Tiptap JSON`,md:`Markdown`,mdDesc:`Export as Markdown`,plainText:`Plain Text`,plainTextDesc:`Export as plain text`,pdf:`PDF`,pdfDesc:`Print as PDF`,copy:`Copy to clipboard`,copied:`Copied`,download:`Download`},image:{upload:`Upload image`,uploading:`Uploading…`,error:`Upload failed`,dragTip:`Drag image here or click to upload`},link:{placeholder:`Enter link URL…`,save:`Save`,remove:`Remove link`}},app:{title:`QingWu`,subtitle:`Smart Editor`,settings:`Settings`,theme:{label:`Theme`,light:`Light`,dark:`Dark`,system:`System`},themeToggle:{toDark:`Switch to dark`,toLight:`Switch to light`},font:{label:`Font`,sans:`Default`,serif:`Serif`,mono:`Mono`},language:`Language`,about:`About QingWu`,footer:{line1:`QingWu · Built on Tiptap · Supports DeepSeek / Qwen / OpenAI models`,license:`Apache-2.0 License`}},tour:{welcome:{title:`Welcome to QingWu Editor`,description:`QingWu is an AI-powered smart editor for Chinese users, supporting Markdown, code highlighting, Mermaid diagrams, and more. Click 'Next' to get started.`},mode:{title:`Edit / View Mode`,description:`Toggle between edit mode and view (read-only) mode. In view mode, content is read-only and action buttons are hidden — ideal for reading and presenting.`},fullscreen:{title:`Fullscreen Mode`,description:`Choose between 'page fullscreen' and 'browser fullscreen' for a focused, distraction-free writing experience.`},ai:{title:`AI Writing Assistant`,description:`After configuring DeepSeek, Qwen, OpenAI, or compatible models, access AI features like continue writing, polish, shorten, expand, fix grammar, and translate.`},lang:{title:`Language Toggle`,description:`Switch between Chinese and English for the editor interface and UI.`},font:{title:`Font Switcher`,description:`Choose between default, serif, and monospace fonts for different reading experiences.`},editor:{title:`Editor Content Area`,description:`Type your content here. Type '/' to open the command menu, select text for the formatting bubble menu, and use the AI assistant for smart writing help.`}}}},d=`zh-CN`;function f(e){d=e,typeof document<`u`&&(document.documentElement.lang=e)}function p(){return d}function m(e){let t=u[d],n=e.split(`.`),r=t;for(let t of n)if(r&&typeof r==`object`&&t in r)r=r[t];else return e;return typeof r==`string`?r:e}function h(e,...t){let n=m(e);if(t.length===0)return n;if(t.length===1&&typeof t[0]==`object`){let e=t[0];for(let[t,r]of Object.entries(e))n=n.replaceAll(`{${t}}`,String(r));return n}for(let e=0;e<t.length;e++)n=n.replaceAll(`{${e}}`,String(t[e]));return t.length===1&&/\{\w+\}/.test(n)&&(n=n.replace(/\{\w+\}/,String(t[0]))),n}var g=null;function _(){return g===!1?null:g===!0?l.default:typeof window>`u`||!window.document?(g=!1,null):(g=!!l.default.isSupported,g?l.default:null)}function v(e){let t={"&":`&amp;`,"<":`&lt;`,">":`&gt;`,'"':`&quot;`,"'":`&#39;`};return e.replace(/[&<>"']/g,e=>t[e]||e)}function y(e){return e.replace(/<(script|style|iframe|object|embed|svg|math|frame|applet|link|meta|base)\b[^>]*>[\s\S]*?<\/\1\s*>/gi,``).replace(/<(script|style|iframe|object|embed|svg|math|frame|applet|link|meta|base)\b[^>]*\/?>/gi,``).replace(/(?:\s|\/)+on\w+\s*=\s*(?:"[^"]*"|'[^']*'|[^\s>]+)/gi,` `).replace(/((?:href|src|action|formaction|xlink:href|data|background|dynsrc|lowsrc)\s*=\s*["'])\s*(?:javascript|vbscript|livescript|mocha):/gi,`$1#`).replace(/((?:href|src|action|formaction)\s*=\s*["'])\s*data:\s*(?:text\/html|image\/svg\+xml|application\/x-javascript|application\/javascript)/gi,`$1#`).replace(/expression\s*\(/gi,`(`).replace(/url\s*\(\s*["']?\s*(?:javascript|vbscript|data:text\/html|data:image\/svg\+xml)[^)]*\)/gi,`url(#)`)}function b(e){let t=_();return t?t.sanitize(e,{ALLOW_DATA_ATTR:!0,ADD_ATTR:[`target`,`rel`]}):y(e)}function x(e){return e.replace(/<script\b[^>]*>[\s\S]*?<\/script\s*>/gi,``).replace(/<foreignObject\b[^>]*>[\s\S]*?<\/foreignObject\s*>/gi,``).replace(/\s+on\w+\s*=\s*(?:"[^"]*"|'[^']*'|[^\s>]+)/gi,``).replace(/((?:href|xlink:href|src)\s*=\s*["'])\s*(?:javascript|vbscript|livescript|mocha):/gi,`$1#`).replace(/((?:href|xlink:href|src)\s*=\s*["'])\s*data:\s*(?:text\/html|application\/javascript)/gi,`$1#`)}Object.defineProperty(exports,"a",{enumerable:!0,get:function(){return f}}),Object.defineProperty(exports,"c",{enumerable:!0,get:function(){return o}}),Object.defineProperty(exports,"i",{enumerable:!0,get:function(){return p}}),Object.defineProperty(exports,"l",{enumerable:!0,get:function(){return c}}),Object.defineProperty(exports,"n",{enumerable:!0,get:function(){return b}}),Object.defineProperty(exports,"o",{enumerable:!0,get:function(){return m}}),Object.defineProperty(exports,"r",{enumerable:!0,get:function(){return x}}),Object.defineProperty(exports,"s",{enumerable:!0,get:function(){return h}}),Object.defineProperty(exports,"t",{enumerable:!0,get:function(){return v}});
1
+ var e=Object.create,t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,r=Object.getOwnPropertyNames,i=Object.getPrototypeOf,a=Object.prototype.hasOwnProperty,o=(e,n)=>{let r={};for(var i in e)t(r,i,{get:e[i],enumerable:!0});return n||t(r,Symbol.toStringTag,{value:`Module`}),r},s=(e,i,o,s)=>{if(i&&typeof i==`object`||typeof i==`function`)for(var c=r(i),l=0,u=c.length,d;l<u;l++)d=c[l],!a.call(e,d)&&d!==o&&t(e,d,{get:(e=>i[e]).bind(null,d),enumerable:!(s=n(i,d))||s.enumerable});return e},c=(n,r,a)=>(a=n==null?{}:e(i(n)),s(r||!n||!n.__esModule?t(a,`default`,{value:n,enumerable:!0}):a,n));let l=require("dompurify");l=c(l,1);var u={"zh-CN":{editor:{placeholder:`输入 '/' 打开命令菜单,或继续输入内容…`,wordCount:`共 {count} 字`,characterCount:`共 {count} 字符`,toolbar:{export:`导出`,exportTitle:`导出文档`,ai:`AI 编写`,aiTitle:`AI 编写助手`},loading:`加载编辑器中…`,prompt:`输入 / 打开命令菜单 · 选中文本弹出格式菜单 · 点击写作助手辅助写作`,attachment:{preview:`预览`,download:`下载`,delete:`删除`,loadingPreview:`加载预览中…`,lost:`附件已丢失`},slash:{heading1:`一级标题`,heading1Desc:`大号标题`,heading2:`二级标题`,heading2Desc:`中号标题`,heading3:`三级标题`,heading3Desc:`小号标题`,heading4:`四级标题`,heading4Desc:`更小标题`,heading5:`五级标题`,heading5Desc:`小小标题`,heading6:`六级标题`,heading6Desc:`最小标题`,searchPlaceholder:`搜索命令…`,bulletList:`无序列表`,bulletListDesc:`创建无序列表`,numberedList:`有序列表`,numberedListDesc:`创建有序列表`,taskList:`任务列表`,taskListDesc:`创建可勾选的任务`,blockquote:`引用块`,blockquoteDesc:`插入引用`,codeBlock:`代码块`,codeBlockDesc:`插入代码块`,image:`图片`,imageDesc:`上传或粘贴图片`,horizontalRule:`分隔线`,horizontalRuleDesc:`插入分隔线`,video:`导入视频`,videoDesc:`导入 B站、直链 mp4/m3u8、小红书等视频`,audio:`导入音频`,audioDesc:`从本地选择音频文件,支持 mp3/wav/flac/aac 等`,attachment:`添加附件`,attachmentDesc:`上传任意类型文件,以附件链接形式插入`,xiaohongshu:`小红书`,xiaohongshuDesc:`嵌入小红书笔记`},bubble:{bold:`加粗`,italic:`斜体`,underline:`下划线`,strikethrough:`删除线`,code:`行内代码`,emphasis:`强调`,link:`链接`,highlight:`高亮`,copy:`复制`,search:`搜索`,table:`表格`,more:`更多`},ai:{trigger:`写作助手`,triggerDesc:`选中文字后选择 AI 操作,生成结果可替换或插入原文。`,close:`关闭`,continue:`续写`,continueDesc:`从当前位置继续写作`,improve:`润色`,improveDesc:`优化表达,提升文采`,shorter:`精简`,shorterDesc:`让文字更简洁`,longer:`扩写`,longerDesc:`丰富内容细节`,fix:`修正`,fixDesc:`修正语法和错别字`,translate:`翻译`,translateDesc:`翻译为其他语言`,zap:`自定义指令`,zapDesc:`输入自定义指令`,thinking:`正在思考…`,replace:`替换选中`,replaceAll:`全文替换`,replaceTitle:`确认替换选中`,replaceAllTitle:`确认全文替换`,replaceText:`将用 AI 生成结果替换当前选中内容。`,replaceAllText:`将用 AI 生成结果替换当前全部内容。`,removeNodes:`以下媒体节点将被移除:`,nodeImage:`图片`,nodeAttachment:`附件`,nodeVideo:`视频`,nodeAudio:`音频`,confirmReplace:`确认替换`,cancel:`取消`,insert:`在下方插入`,discard:`放弃`,error:`请求失败,请重试`,confirm:`确定`,back:`返回`,customPlaceholder:`例如:把这段内容改写成小红书风格`},export:{title:`导出文档`,html:`HTML`,htmlDesc:`导出为 HTML 文件`,json:`JSON (Tiptap)`,jsonDesc:`导出为 Tiptap JSON 格式`,md:`Markdown`,mdDesc:`导出为 Markdown 文件`,plainText:`纯文本`,plainTextDesc:`导出为纯文本`,pdf:`PDF`,pdfDesc:`打印为 PDF`,copy:`复制到剪贴板`,copied:`已复制`,download:`下载`},image:{upload:`上传图片`,uploading:`上传中…`,error:`上传失败`,dragTip:`拖拽图片到此处或点击上传`},link:{placeholder:`输入链接地址…`,save:`确定`,remove:`移除链接`}},app:{title:`青梧`,subtitle:`智能编辑器`,settings:`设置`,theme:{label:`主题`,light:`浅色`,dark:`深色`,system:`跟随系统`},themeToggle:{toDark:`切换深色`,toLight:`切换浅色`},font:{label:`字体`,sans:`默认字体`,serif:`宋体/衬线`,mono:`等宽字体`},language:`语言`,about:`关于青梧`,footer:{line1:`青梧 QingWu · 基于 Tiptap 构建 · 支持 DeepSeek / 通义千问 / OpenAI 等大模型`,license:`Apache-2.0 License`}},tour:{welcome:{title:`欢迎使用青梧编辑器`,description:`青梧是一款面向中文用户的 AI 智能编辑器,支持 Markdown、代码高亮、Mermaid 图表等丰富功能。点击「下一步」开始了解。`},mode:{title:`编辑 / 查看模式`,description:`点击此按钮可在「编辑模式」和「查看模式」之间切换。查看模式下内容只读,操作按钮会隐藏,适合阅读和展示。`},fullscreen:{title:`全屏模式`,description:`提供「网页全屏」和「浏览器全屏」两种沉浸式写作体验,让你专注于内容创作。`},ai:{title:`AI 写作助手`,description:`配置 DeepSeek、通义千问、OpenAI 等大模型后,可使用续写、润色、精简、扩写、修正、翻译等 AI 辅助功能。`},lang:{title:`中英文切换`,description:`编辑器和界面支持中文和英文两种语言,点击即可切换。`},font:{title:`字体切换`,description:`提供默认字体、衬线字体和等宽字体三种阅读体验,满足不同场景需求。`},editor:{title:`编辑器内容区`,description:`在此区域输入内容。输入 / 打开命令菜单插入各种元素,选中文本弹出格式菜单,点击写作助手触发 AI 辅助。`}}},"en-US":{editor:{placeholder:`Type '/' for commands, or continue writing…`,wordCount:`{count} words`,characterCount:`{count} characters`,toolbar:{export:`Export`,exportTitle:`Export Document`,ai:`AI Write`,aiTitle:`AI Writing Assistant`},loading:`Loading editor…`,prompt:`Type / for commands · Select text for formatting · Click Writing Assistant for help`,attachment:{preview:`Preview`,download:`Download`,delete:`Delete`,loadingPreview:`Loading preview…`,lost:`Attachment lost`},slash:{heading1:`Heading 1`,heading1Desc:`Large heading`,heading2:`Heading 2`,heading2Desc:`Medium heading`,heading3:`Heading 3`,heading3Desc:`Small heading`,heading4:`Heading 4`,heading4Desc:`Smaller heading`,heading5:`Heading 5`,heading5Desc:`Tiny heading`,heading6:`Heading 6`,heading6Desc:`Smallest heading`,searchPlaceholder:`Search commands…`,bulletList:`Bullet List`,bulletListDesc:`Create a bullet list`,numberedList:`Numbered List`,numberedListDesc:`Create a numbered list`,taskList:`Task List`,taskListDesc:`Create a task list`,blockquote:`Blockquote`,blockquoteDesc:`Insert a blockquote`,codeBlock:`Code Block`,codeBlockDesc:`Insert code block`,image:`Image`,imageDesc:`Upload or paste an image`,horizontalRule:`Divider`,horizontalRuleDesc:`Insert a divider`,video:`Import Video`,videoDesc:`Import Bilibili, direct mp4/m3u8, RedNote videos`,audio:`Import Audio`,audioDesc:`Select audio file from local (mp3/wav/flac/aac)`,attachment:`Add Attachment`,attachmentDesc:`Upload any file type as attachment link`,xiaohongshu:`RedNote`,xiaohongshuDesc:`Embed RedNote post`},bubble:{bold:`Bold`,italic:`Italic`,underline:`Underline`,strikethrough:`Strikethrough`,code:`Inline Code`,emphasis:`Emphasis`,link:`Link`,highlight:`Highlight`,copy:`Copy`,search:`Search`,table:`Table`,more:`More`},ai:{trigger:`Writing Assistant`,triggerDesc:`Select text and pick an AI action. The result can replace or insert into the document.`,close:`Close`,continue:`Continue`,continueDesc:`Continue writing from here`,improve:`Improve`,improveDesc:`Polish and improve text`,shorter:`Shorten`,shorterDesc:`Make it more concise`,longer:`Expand`,longerDesc:`Add more detail`,fix:`Fix`,fixDesc:`Fix grammar and typos`,translate:`Translate`,translateDesc:`Translate to another language`,zap:`Custom`,zapDesc:`Enter a custom command`,thinking:`Thinking…`,replace:`Replace selection`,replaceAll:`Replace all`,replaceTitle:`Replace selection`,replaceAllTitle:`Replace all content`,replaceText:`The AI result will replace the current selection.`,replaceAllText:`The AI result will replace the entire document.`,removeNodes:`The following media nodes will be removed:`,nodeImage:`Image`,nodeAttachment:`Attachment`,nodeVideo:`Video`,nodeAudio:`Audio`,confirmReplace:`Replace`,cancel:`Cancel`,insert:`Insert below`,discard:`Discard`,error:`Request failed, please retry`,confirm:`Confirm`,back:`Back`,customPlaceholder:`e.g. Rewrite this in a more casual tone`},export:{title:`Export Document`,html:`HTML`,htmlDesc:`Export as HTML`,json:`JSON (Tiptap)`,jsonDesc:`Export as Tiptap JSON`,md:`Markdown`,mdDesc:`Export as Markdown`,plainText:`Plain Text`,plainTextDesc:`Export as plain text`,pdf:`PDF`,pdfDesc:`Print as PDF`,copy:`Copy to clipboard`,copied:`Copied`,download:`Download`},image:{upload:`Upload image`,uploading:`Uploading…`,error:`Upload failed`,dragTip:`Drag image here or click to upload`},link:{placeholder:`Enter link URL…`,save:`Save`,remove:`Remove link`}},app:{title:`QingWu`,subtitle:`Smart Editor`,settings:`Settings`,theme:{label:`Theme`,light:`Light`,dark:`Dark`,system:`System`},themeToggle:{toDark:`Switch to dark`,toLight:`Switch to light`},font:{label:`Font`,sans:`Default`,serif:`Serif`,mono:`Mono`},language:`Language`,about:`About QingWu`,footer:{line1:`QingWu · Built on Tiptap · Supports DeepSeek / Qwen / OpenAI models`,license:`Apache-2.0 License`}},tour:{welcome:{title:`Welcome to QingWu Editor`,description:`QingWu is an AI-powered smart editor for Chinese users, supporting Markdown, code highlighting, Mermaid diagrams, and more. Click 'Next' to get started.`},mode:{title:`Edit / View Mode`,description:`Toggle between edit mode and view (read-only) mode. In view mode, content is read-only and action buttons are hidden — ideal for reading and presenting.`},fullscreen:{title:`Fullscreen Mode`,description:`Choose between 'page fullscreen' and 'browser fullscreen' for a focused, distraction-free writing experience.`},ai:{title:`AI Writing Assistant`,description:`After configuring DeepSeek, Qwen, OpenAI, or compatible models, access AI features like continue writing, polish, shorten, expand, fix grammar, and translate.`},lang:{title:`Language Toggle`,description:`Switch between Chinese and English for the editor interface and UI.`},font:{title:`Font Switcher`,description:`Choose between default, serif, and monospace fonts for different reading experiences.`},editor:{title:`Editor Content Area`,description:`Type your content here. Type '/' to open the command menu, select text for the formatting bubble menu, and use the AI assistant for smart writing help.`}}}},d=`zh-CN`;function f(e){d=e,typeof document<`u`&&(document.documentElement.lang=e)}function p(){return d}function m(e){let t=u[d],n=e.split(`.`),r=t;for(let t of n)if(r&&typeof r==`object`&&t in r)r=r[t];else return e;return typeof r==`string`?r:e}function h(e,...t){let n=m(e);if(t.length===0)return n;if(t.length===1&&typeof t[0]==`object`){let e=t[0];for(let[t,r]of Object.entries(e))n=n.replaceAll(`{${t}}`,String(r));return n}for(let e=0;e<t.length;e++)n=n.replaceAll(`{${e}}`,String(t[e]));return t.length===1&&/\{\w+\}/.test(n)&&(n=n.replace(/\{\w+\}/,String(t[0]))),n}var g=null;function _(){return g===!1?null:g===!0?l.default:typeof window>`u`||!window.document?(g=!1,null):(g=!!l.default.isSupported,g?l.default:null)}function v(e){let t={"&":`&amp;`,"<":`&lt;`,">":`&gt;`,'"':`&quot;`,"'":`&#39;`};return e.replace(/[&<>"']/g,e=>t[e]||e)}function y(e){return e.replace(/<(script|style|iframe|object|embed|svg|math|frame|applet|link|meta|base)\b[^>]*>[\s\S]*?<\/\1\s*>/gi,``).replace(/<(script|style|iframe|object|embed|svg|math|frame|applet|link|meta|base)\b[^>]*\/?>/gi,``).replace(/(?:\s|\/)+on\w+\s*=\s*(?:"[^"]*"|'[^']*'|[^\s>]+)/gi,` `).replace(/((?:href|src|action|formaction|xlink:href|data|background|dynsrc|lowsrc)\s*=\s*["'])\s*(?:javascript|vbscript|livescript|mocha):/gi,`$1#`).replace(/((?:href|src|action|formaction)\s*=\s*["'])\s*data:\s*(?:text\/html|image\/svg\+xml|application\/x-javascript|application\/javascript)/gi,`$1#`).replace(/expression\s*\(/gi,`(`).replace(/url\s*\(\s*["']?\s*(?:javascript|vbscript|data:text\/html|data:image\/svg\+xml)[^)]*\)/gi,`url(#)`)}function b(e){let t=_();return t?t.sanitize(e,{ALLOW_DATA_ATTR:!0,ADD_ATTR:[`target`,`rel`],ALLOWED_URI_REGEXP:/^(?:(?:(?:f|ht)tps?|mailto|tel|callto|sms|cid|xmpp|blob):|[^a-z]|[a-z+.\-]+(?:[^a-z+.\-:]|$))/i}):y(e)}function x(e){return e.replace(/<script\b[^>]*>[\s\S]*?<\/script\s*>/gi,``).replace(/<foreignObject\b[^>]*>[\s\S]*?<\/foreignObject\s*>/gi,``).replace(/\s+on\w+\s*=\s*(?:"[^"]*"|'[^']*'|[^\s>]+)/gi,``).replace(/((?:href|xlink:href|src)\s*=\s*["'])\s*(?:javascript|vbscript|livescript|mocha):/gi,`$1#`).replace(/((?:href|xlink:href|src)\s*=\s*["'])\s*data:\s*(?:text\/html|application\/javascript)/gi,`$1#`)}Object.defineProperty(exports,"a",{enumerable:!0,get:function(){return f}}),Object.defineProperty(exports,"c",{enumerable:!0,get:function(){return o}}),Object.defineProperty(exports,"i",{enumerable:!0,get:function(){return p}}),Object.defineProperty(exports,"l",{enumerable:!0,get:function(){return c}}),Object.defineProperty(exports,"n",{enumerable:!0,get:function(){return b}}),Object.defineProperty(exports,"o",{enumerable:!0,get:function(){return m}}),Object.defineProperty(exports,"r",{enumerable:!0,get:function(){return x}}),Object.defineProperty(exports,"s",{enumerable:!0,get:function(){return h}}),Object.defineProperty(exports,"t",{enumerable:!0,get:function(){return v}});
@@ -441,7 +441,8 @@ function d(e) {
441
441
  let t = c();
442
442
  return t ? t.sanitize(e, {
443
443
  ALLOW_DATA_ATTR: !0,
444
- ADD_ATTR: ["target", "rel"]
444
+ ADD_ATTR: ["target", "rel"],
445
+ ALLOWED_URI_REGEXP: /^(?:(?:(?:f|ht)tps?|mailto|tel|callto|sms|cid|xmpp|blob):|[^a-z]|[a-z+.\-]+(?:[^a-z+.\-:]|$))/i
445
446
  }) : u(e);
446
447
  }
447
448
  function f(e) {
@@ -1,4 +1,4 @@
1
- var e=require("./sanitize-BLVk_EcE.cjs").c({registerS3PreviewConfig:()=>n,signPreviewUrl:()=>d,signPreviewUrlHeaders:()=>u,signUrl:()=>c}),t=null;function n(e){t=e}function r(e){return e instanceof ArrayBuffer?e:e.buffer.slice(e.byteOffset,e.byteOffset+e.byteLength)}async function i(e){let t=typeof e==`string`?new TextEncoder().encode(e):e;return crypto.subtle.digest(`SHA-256`,r(t)).then(e=>Array.from(new Uint8Array(e)).map(e=>e.toString(16).padStart(2,`0`)).join(``))}async function a(e,t){let n=r(e),i=await crypto.subtle.importKey(`raw`,n,{name:`HMAC`,hash:`SHA-256`},!1,[`sign`]);return crypto.subtle.sign(`HMAC`,i,new TextEncoder().encode(t))}async function o(e,t,n,r){let i=new TextEncoder;return a(await a(await a(await a(new Uint8Array(i.encode(`AWS4${e}`)).buffer,t),n),r),`aws4_request`)}async function s(e,t,n,r){let s=new URL(e),c=s.host,l=s.pathname,u=s.searchParams.toString(),d=new Date().toISOString().replace(/[:-]|\.\d{3}/g,``),f=d.slice(0,8),p=`AWS4-HMAC-SHA256`,m=`${f}/${t}/s3/aws4_request`,h=await i(``),g=`host;x-amz-content-sha256;x-amz-date`,_=[p,d,m,await i([`GET`,l,u,`host:${c}`,`x-amz-content-sha256:${h}`,`x-amz-date:${d}`,``,g,h].join(`
1
+ var e=require("./sanitize-CrbFQE46.cjs").c({registerS3PreviewConfig:()=>n,signPreviewUrl:()=>d,signPreviewUrlHeaders:()=>u,signUrl:()=>c}),t=null;function n(e){t=e}function r(e){return e instanceof ArrayBuffer?e:e.buffer.slice(e.byteOffset,e.byteOffset+e.byteLength)}async function i(e){let t=typeof e==`string`?new TextEncoder().encode(e):e;return crypto.subtle.digest(`SHA-256`,r(t)).then(e=>Array.from(new Uint8Array(e)).map(e=>e.toString(16).padStart(2,`0`)).join(``))}async function a(e,t){let n=r(e),i=await crypto.subtle.importKey(`raw`,n,{name:`HMAC`,hash:`SHA-256`},!1,[`sign`]);return crypto.subtle.sign(`HMAC`,i,new TextEncoder().encode(t))}async function o(e,t,n,r){let i=new TextEncoder;return a(await a(await a(await a(new Uint8Array(i.encode(`AWS4${e}`)).buffer,t),n),r),`aws4_request`)}async function s(e,t,n,r){let s=new URL(e),c=s.host,l=s.pathname,u=s.searchParams.toString(),d=new Date().toISOString().replace(/[:-]|\.\d{3}/g,``),f=d.slice(0,8),p=`AWS4-HMAC-SHA256`,m=`${f}/${t}/s3/aws4_request`,h=await i(``),g=`host;x-amz-content-sha256;x-amz-date`,_=[p,d,m,await i([`GET`,l,u,`host:${c}`,`x-amz-content-sha256:${h}`,`x-amz-date:${d}`,``,g,h].join(`
2
2
  `))].join(`
3
3
  `),v=await o(r,f,t,`s3`),y=Array.from(new Uint8Array(await a(v,_))).map(e=>e.toString(16).padStart(2,`0`)).join(``),b=new Headers;return b.set(`x-amz-content-sha256`,h),b.set(`x-amz-date`,d),b.set(`Authorization`,`${p} Credential=${n}/${m}, SignedHeaders=${g}, Signature=${y}`),b}async function c(e,t,n,r,s=3600){let c=new URL(e),l=c.host,u=c.pathname,d=new Date().toISOString().replace(/[:-]|\.\d{3}/g,``),f=d.slice(0,8),p=`AWS4-HMAC-SHA256`,m=`${f}/${t}/s3/aws4_request`,h=`host`,g=[[`X-Amz-Algorithm`,p],[`X-Amz-Credential`,`${n}/${m}`],[`X-Amz-Date`,d],[`X-Amz-Expires`,String(s)],[`X-Amz-SignedHeaders`,h]];g.sort((e,t)=>e[0]<t[0]?-1:+(e[0]>t[0]));let _=[p,d,m,await i([`GET`,u,g.map(e=>`${encodeURIComponent(e[0])}=${encodeURIComponent(e[1])}`).join(`&`),`host:${l}`,``,h,`UNSIGNED-PAYLOAD`].join(`
4
4
  `))].join(`
@@ -1 +1 @@
1
- const e=require("./signed-fetch-D8Rk6R5t.cjs"),t=require("./storage-VaeLS7eM.cjs"),n=require("./local-D4481lUa.cjs");let r=require("react"),i=require("react/jsx-runtime");var a=[{key:`local`,label:`本地`,icon:`💻`},{key:`s3`,label:`S3 对象存储`,icon:`☁️`}],o=({open:o,onClose:s})=>{let c=t.t(),[l,u]=(0,r.useState)(c?.type===`local`?`local`:`s3`),[d,f]=(0,r.useState)(!1),[p,m]=(0,r.useState)(!1),[h,g]=(0,r.useState)(null),[_,v]=(0,r.useState)(``),[y,b]=(0,r.useState)(``),[x,S]=(0,r.useState)(`auto`),[C,w]=(0,r.useState)(``),[T,E]=(0,r.useState)(``),[D,O]=(0,r.useState)(``),[k,A]=(0,r.useState)(`qingwu`),[j,M]=(0,r.useState)(`{ts}{tz}_{src}_{name}_{rand}{ext}`);(0,r.useEffect)(()=>{let e=t.r();e?.type===`s3`?(v(e.endpoint||``),b(e.bucket||``),S(e.region||`auto`),w(e.accessKeyId||``),E(e.secretAccessKey||``),O(e.customDomain||``),A(e.uploadPrefix||`qingwu`),M(e.nameTemplate||`{ts}{tz}_{src}_{name}_{rand}{ext}`),u(`s3`)):e?.type===`oss`?(v(`https://${e.bucket}.${e.region}.aliyuncs.com`),b(e.bucket||``),S(e.region||`oss-cn-hangzhou`),w(e.accessKeyId||``),E(e.accessKeySecret||``),O(e.customDomain||``),A(e.uploadPrefix||`qingwu`),M(e.nameTemplate||`{ts}{tz}_{src}_{name}_{rand}{ext}`),u(`s3`)):e?.type===`cos`&&(v(`https://${e.bucket}.cos.${e.region}.myqcloud.com`),b(e.bucket||``),S(e.region||`ap-guangzhou`),w(e.secretId||``),E(e.secretKey||``),O(e.customDomain||``),A(e.uploadPrefix||`qingwu`),M(e.nameTemplate||`{ts}{tz}_{src}_{name}_{rand}{ext}`),u(`s3`))},[]),(0,r.useEffect)(()=>{if(!h)return;let e=window.setTimeout(()=>g(null),4e3);return()=>window.clearTimeout(e)},[h]);let N=(0,r.useCallback)(()=>{g(null),t.a(n.t(),{type:`local`,location:`浏览器内存 (Base64 编码)`}),f(!0),setTimeout(()=>{f(!1),s()},600)},[s]),P=(0,r.useCallback)(async()=>{if(!p){m(!0),g(null);try{let e=n.t(),t=new File([`qingwu storage test`],`qingwu-storage-test.txt`,{type:`text/plain`}),r=await e.upload(t,`editor`);await e.remove(r).catch(()=>{}),g({type:`success`,message:`本地存储可用`})}catch(e){g({type:`error`,message:e instanceof Error?e.message:`本地存储测试失败`})}finally{m(!1)}}},[p]),F=(0,r.useCallback)(()=>{if(!_||!y||!C)return;g(null);let r={endpoint:_,bucket:y,region:x,accessKeyId:C,secretAccessKey:T,customDomain:D||void 0,uploadPrefix:k||`qingwu`,nameTemplate:j||`{ts}{tz}_{src}_{name}_{rand}{ext}`};t.a(n.n(r),{type:`s3`,endpoint:_,bucket:y,region:x,accessKeyId:C,secretAccessKey:T,customDomain:D||void 0,uploadPrefix:k||`qingwu`,nameTemplate:j||`{ts}{tz}_{src}_{name}_{rand}{ext}`}),e.t(r),f(!0),setTimeout(()=>{f(!1),s()},600)},[_,y,x,C,T,D,k,j,s]),I=(0,r.useCallback)(async()=>{if(!_||!y||!C||p)return;m(!0),g(null);let e=``;try{let t=n.n({endpoint:_,bucket:y,region:x,accessKeyId:C,secretAccessKey:T,customDomain:D||void 0}),r=new File([`qingwu storage test`],`qingwu-storage-test.txt`,{type:`text/plain`});e=await t.upload(r,`editor`);let i=!1,a=!1;try{i=(await fetch(e,{method:`GET`})).ok}catch{i=!1}if(!i)try{let{signPreviewUrlHeaders:t}=await Promise.resolve().then(()=>require("./signed-fetch-D8Rk6R5t.cjs")).then(e=>e.i),{registerS3PreviewConfig:n}=await Promise.resolve().then(()=>require("./signed-fetch-D8Rk6R5t.cjs")).then(e=>e.i);n({endpoint:_,bucket:y,region:x,accessKeyId:C,secretAccessKey:T,customDomain:D||void 0});let r=await t(e);r&&(await fetch(e,{headers:r})).ok&&(i=!0,a=!0)}catch{}if(!i)throw Error(`上传成功,但访问失败。请确认 Bucket 读写权限配置正确。`);g({type:`success`,message:a?`存储连接成功(私有桶,通过签名访问)`:`存储连接和公开访问均成功`})}catch(e){g({type:`error`,message:e instanceof Error?e.message:`存储连接失败`})}finally{e&&await n.n({endpoint:_,bucket:y,region:x,accessKeyId:C,secretAccessKey:T,customDomain:D||void 0}).remove(e).catch(()=>{}),m(!1)}},[_,y,x,C,T,D,p]);return o?(0,i.jsxs)(`div`,{className:`fixed inset-0 z-[9999] flex items-center justify-center`,children:[h&&(0,i.jsx)(`div`,{className:`fixed right-4 top-4 z-[10001] w-[calc(100vw-32px)] max-w-sm rounded-xl border px-4 py-3 text-sm shadow-2xl backdrop-blur-sm ${h.type===`success`?`border-green-200 bg-green-50/95 text-green-700`:`border-danger-200 bg-danger-50/95 text-danger`}`,children:(0,i.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,i.jsx)(`span`,{className:`mt-0.5 shrink-0`,children:h.type===`success`?`✓`:`!`}),(0,i.jsx)(`span`,{className:`min-w-0 break-words`,children:h.message})]})}),(0,i.jsx)(`div`,{className:`absolute inset-0 bg-black/40 backdrop-blur-sm`,onClick:s}),(0,i.jsxs)(`div`,{className:`relative w-[calc(100vw-32px)] max-w-[460px] max-h-[85vh] bg-background rounded-2xl shadow-2xl border border-default-200 overflow-hidden animate-in`,children:[(0,i.jsxs)(`div`,{className:`flex items-center justify-between px-5 py-4 border-b border-default-100`,children:[(0,i.jsx)(`h2`,{className:`text-base font-semibold`,children:`存储设置`}),(0,i.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:s,children:`✕`})]}),c&&(0,i.jsxs)(`div`,{className:`mx-5 mt-4 p-3 rounded-xl bg-default-50 border border-default-100`,children:[(0,i.jsxs)(`div`,{className:`flex items-center gap-2 text-xs text-default-500 mb-1`,children:[(0,i.jsx)(`span`,{className:`w-1.5 h-1.5 rounded-full bg-green-500`}),`当前存储服务`]}),(0,i.jsx)(`div`,{className:`text-sm font-medium`,children:c.name}),(0,i.jsx)(`div`,{className:`text-[11px] text-default-400 mt-0.5`,children:c.type===`local`?`位置:浏览器内存 · Base64 编码 · 关闭页面后丢失`:c.type===`s3`&&c.config?.type===`s3`?`${c.config.endpoint} · ${c.config.bucket}${c.config.customDomain?` → ${c.config.customDomain}`:``}`:``})]}),(0,i.jsx)(`div`,{className:`flex border-b border-default-100 px-5 mt-4`,children:a.map(({key:e,label:t,icon:n})=>(0,i.jsxs)(`button`,{type:`button`,className:`flex items-center gap-1.5 px-3 py-2.5 text-sm font-medium transition-colors border-b-2 -mb-[1px] ${l===e?`border-primary text-primary`:`border-transparent text-default-400 hover:text-default-600`}`,onClick:()=>{u(e),f(!1)},children:[(0,i.jsx)(`span`,{children:n}),t]},e))}),(0,i.jsxs)(`div`,{className:`p-5 max-h-[50vh] overflow-y-auto`,children:[l===`local`&&(0,i.jsxs)(`div`,{className:`space-y-4`,children:[(0,i.jsxs)(`div`,{className:`p-4 rounded-xl bg-blue-50 border border-blue-100`,children:[(0,i.jsx)(`p`,{className:`text-sm font-medium text-blue-800 mb-1`,children:`💻 浏览器内存存储`}),(0,i.jsx)(`p`,{className:`text-xs text-blue-600 leading-relaxed`,children:`文件以 Base64 编码存储在浏览器内存中,页面关闭后清除。 适合演示和临时使用,不建议用于生产环境。`})]}),(0,i.jsx)(`button`,{type:`button`,className:`w-full py-2.5 rounded-xl text-sm font-medium transition-all ${d?`bg-green-500 text-white`:`bg-primary text-white hover:opacity-90`}`,onClick:N,children:d?`✓ 已保存`:`使用本地存储`}),(0,i.jsx)(`button`,{type:`button`,className:`w-full py-2.5 rounded-xl text-sm font-medium border border-default-200 hover:bg-default-100 transition-all disabled:opacity-40`,disabled:p,onClick:P,children:p?`测试中...`:`测试连接`})]}),l===`s3`&&(0,i.jsxs)(`div`,{className:`space-y-3`,children:[(0,i.jsx)(`div`,{className:`p-3 rounded-lg bg-default-50 text-xs text-default-500 leading-relaxed mb-1`,children:`兼容 AWS S3、Cloudflare R2、MinIO、阿里云 OSS、腾讯云 COS 等所有 S3 协议对象存储服务。`}),(0,i.jsxs)(`div`,{children:[(0,i.jsx)(`label`,{className:`block text-xs text-default-500 mb-1`,children:`Endpoint *`}),(0,i.jsx)(`input`,{className:`w-full px-3 py-2 rounded-lg border border-default-200 bg-background text-sm focus:outline-none focus:border-primary`,placeholder:`https://<account>.r2.cloudflarestorage.com`,value:_,onChange:e=>v(e.target.value)})]}),(0,i.jsxs)(`div`,{children:[(0,i.jsx)(`label`,{className:`block text-xs text-default-500 mb-1`,children:`Bucket 名称 *`}),(0,i.jsx)(`input`,{className:`w-full px-3 py-2 rounded-lg border border-default-200 bg-background text-sm focus:outline-none focus:border-primary`,placeholder:`my-bucket`,value:y,onChange:e=>b(e.target.value)})]}),(0,i.jsxs)(`div`,{children:[(0,i.jsx)(`label`,{className:`block text-xs text-default-500 mb-1`,children:`Region`}),(0,i.jsx)(`input`,{className:`w-full px-3 py-2 rounded-lg border border-default-200 bg-background text-sm focus:outline-none focus:border-primary`,placeholder:`auto / us-east-1 / ap-northeast-1`,value:x,onChange:e=>S(e.target.value)}),(0,i.jsxs)(`p`,{className:`text-[11px] text-default-400 mt-0.5`,children:[`R2 / MinIO 填 `,(0,i.jsx)(`code`,{children:`auto`}),`,AWS 按实际区域填写`]})]}),(0,i.jsxs)(`div`,{children:[(0,i.jsx)(`label`,{className:`block text-xs text-default-500 mb-1`,children:`Access Key ID *`}),(0,i.jsx)(`input`,{className:`w-full px-3 py-2 rounded-lg border border-default-200 bg-background text-sm focus:outline-none focus:border-primary`,placeholder:`AKIAIOSFODNN7EXAMPLE`,value:C,onChange:e=>w(e.target.value)})]}),(0,i.jsxs)(`div`,{children:[(0,i.jsx)(`label`,{className:`block text-xs text-default-500 mb-1`,children:`Secret Access Key`}),(0,i.jsx)(`input`,{type:`password`,className:`w-full px-3 py-2 rounded-lg border border-default-200 bg-background text-sm focus:outline-none focus:border-primary`,placeholder:`••••••••`,value:T,onChange:e=>E(e.target.value)})]}),(0,i.jsxs)(`div`,{children:[(0,i.jsx)(`label`,{className:`block text-xs text-default-500 mb-1`,children:`自定义访问域名(CDN,可选)`}),(0,i.jsx)(`input`,{className:`w-full px-3 py-2 rounded-lg border border-default-200 bg-background text-sm focus:outline-none focus:border-primary`,placeholder:`cdn.example.com`,value:D,onChange:e=>O(e.target.value)}),(0,i.jsx)(`p`,{className:`text-[11px] text-default-400 mt-0.5`,children:`设置后,上传返回的资源 URL 将使用此域名`})]}),(0,i.jsxs)(`div`,{children:[(0,i.jsx)(`label`,{className:`block text-xs text-default-500 mb-1`,children:`资源目录`}),(0,i.jsx)(`input`,{className:`w-full px-3 py-2 rounded-lg border border-default-200 bg-background text-sm focus:outline-none focus:border-primary`,placeholder:`qingwu`,value:k,onChange:e=>A(e.target.value)}),(0,i.jsx)(`p`,{className:`text-[11px] text-default-400 mt-0.5`,children:`上传文件的存储目录,默认 qingwu(MinIO/S3 路径风格需填 bucket 名)`})]}),(0,i.jsxs)(`div`,{children:[(0,i.jsx)(`label`,{className:`block text-xs text-default-500 mb-1`,children:`文件名模板`}),(0,i.jsx)(`input`,{className:`w-full px-3 py-2 rounded-lg border border-default-200 bg-background text-sm focus:outline-none focus:border-primary`,placeholder:`{ts}{tz}_{src}_{name}_{rand}{ext}`,value:j,onChange:e=>M(e.target.value)}),(0,i.jsx)(`p`,{className:`text-[11px] text-default-400 mt-0.5`,children:`占位符: {ts}=时间戳, {tz}=时区, {src}=出处(editor/cover), {name}=原名, {ext}=扩展名, {rand}=随机串`})]}),(0,i.jsxs)(`div`,{className:`p-3 rounded-lg bg-default-50 text-[11px] text-default-500 leading-relaxed`,children:[`上传路径:`,_&&y?`${_}/${y}/qingwu/...`:`请填写 Endpoint 和 Bucket`,D?`\n访问域名:https://${D}/qingwu/...`:``]}),(0,i.jsxs)(`div`,{className:`grid grid-cols-2 gap-2`,children:[(0,i.jsx)(`button`,{type:`button`,className:`py-2.5 rounded-xl text-sm font-medium border border-default-200 hover:bg-default-100 transition-all disabled:opacity-40`,disabled:!_||!y||!C||p,onClick:I,children:p?`测试中...`:`测试连接`}),(0,i.jsx)(`button`,{type:`button`,className:`py-2.5 rounded-xl text-sm font-medium transition-all disabled:opacity-40 ${d?`bg-green-500 text-white`:`bg-primary text-white hover:opacity-90`}`,disabled:!_||!y||!C||p,onClick:F,children:d?`✓ 已保存`:`保存并应用`})]})]})]})]})]}):null};exports.StorageSettingsDialog=o;
1
+ const e=require("./signed-fetch-DiWXujJ1.cjs"),t=require("./storage-VaeLS7eM.cjs"),n=require("./local-D4481lUa.cjs");let r=require("react"),i=require("react/jsx-runtime");var a=[{key:`local`,label:`本地`,icon:`💻`},{key:`s3`,label:`S3 对象存储`,icon:`☁️`}],o=({open:o,onClose:s})=>{let c=t.t(),[l,u]=(0,r.useState)(c?.type===`local`?`local`:`s3`),[d,f]=(0,r.useState)(!1),[p,m]=(0,r.useState)(!1),[h,g]=(0,r.useState)(null),[_,v]=(0,r.useState)(``),[y,b]=(0,r.useState)(``),[x,S]=(0,r.useState)(`auto`),[C,w]=(0,r.useState)(``),[T,E]=(0,r.useState)(``),[D,O]=(0,r.useState)(``),[k,A]=(0,r.useState)(`qingwu`),[j,M]=(0,r.useState)(`{ts}{tz}_{src}_{name}_{rand}{ext}`);(0,r.useEffect)(()=>{let e=t.r();e?.type===`s3`?(v(e.endpoint||``),b(e.bucket||``),S(e.region||`auto`),w(e.accessKeyId||``),E(e.secretAccessKey||``),O(e.customDomain||``),A(e.uploadPrefix||`qingwu`),M(e.nameTemplate||`{ts}{tz}_{src}_{name}_{rand}{ext}`),u(`s3`)):e?.type===`oss`?(v(`https://${e.bucket}.${e.region}.aliyuncs.com`),b(e.bucket||``),S(e.region||`oss-cn-hangzhou`),w(e.accessKeyId||``),E(e.accessKeySecret||``),O(e.customDomain||``),A(e.uploadPrefix||`qingwu`),M(e.nameTemplate||`{ts}{tz}_{src}_{name}_{rand}{ext}`),u(`s3`)):e?.type===`cos`&&(v(`https://${e.bucket}.cos.${e.region}.myqcloud.com`),b(e.bucket||``),S(e.region||`ap-guangzhou`),w(e.secretId||``),E(e.secretKey||``),O(e.customDomain||``),A(e.uploadPrefix||`qingwu`),M(e.nameTemplate||`{ts}{tz}_{src}_{name}_{rand}{ext}`),u(`s3`))},[]),(0,r.useEffect)(()=>{if(!h)return;let e=window.setTimeout(()=>g(null),4e3);return()=>window.clearTimeout(e)},[h]);let N=(0,r.useCallback)(()=>{g(null),t.a(n.t(),{type:`local`,location:`浏览器内存 (Base64 编码)`}),f(!0),setTimeout(()=>{f(!1),s()},600)},[s]),P=(0,r.useCallback)(async()=>{if(!p){m(!0),g(null);try{let e=n.t(),t=new File([`qingwu storage test`],`qingwu-storage-test.txt`,{type:`text/plain`}),r=await e.upload(t,`editor`);await e.remove(r).catch(()=>{}),g({type:`success`,message:`本地存储可用`})}catch(e){g({type:`error`,message:e instanceof Error?e.message:`本地存储测试失败`})}finally{m(!1)}}},[p]),F=(0,r.useCallback)(()=>{if(!_||!y||!C)return;g(null);let r={endpoint:_,bucket:y,region:x,accessKeyId:C,secretAccessKey:T,customDomain:D||void 0,uploadPrefix:k||`qingwu`,nameTemplate:j||`{ts}{tz}_{src}_{name}_{rand}{ext}`};t.a(n.n(r),{type:`s3`,endpoint:_,bucket:y,region:x,accessKeyId:C,secretAccessKey:T,customDomain:D||void 0,uploadPrefix:k||`qingwu`,nameTemplate:j||`{ts}{tz}_{src}_{name}_{rand}{ext}`}),e.t(r),f(!0),setTimeout(()=>{f(!1),s()},600)},[_,y,x,C,T,D,k,j,s]),I=(0,r.useCallback)(async()=>{if(!_||!y||!C||p)return;m(!0),g(null);let e=``;try{let t=n.n({endpoint:_,bucket:y,region:x,accessKeyId:C,secretAccessKey:T,customDomain:D||void 0}),r=new File([`qingwu storage test`],`qingwu-storage-test.txt`,{type:`text/plain`});e=await t.upload(r,`editor`);let i=!1,a=!1;try{i=(await fetch(e,{method:`GET`})).ok}catch{i=!1}if(!i)try{let{signPreviewUrlHeaders:t}=await Promise.resolve().then(()=>require("./signed-fetch-DiWXujJ1.cjs")).then(e=>e.i),{registerS3PreviewConfig:n}=await Promise.resolve().then(()=>require("./signed-fetch-DiWXujJ1.cjs")).then(e=>e.i);n({endpoint:_,bucket:y,region:x,accessKeyId:C,secretAccessKey:T,customDomain:D||void 0});let r=await t(e);r&&(await fetch(e,{headers:r})).ok&&(i=!0,a=!0)}catch{}if(!i)throw Error(`上传成功,但访问失败。请确认 Bucket 读写权限配置正确。`);g({type:`success`,message:a?`存储连接成功(私有桶,通过签名访问)`:`存储连接和公开访问均成功`})}catch(e){g({type:`error`,message:e instanceof Error?e.message:`存储连接失败`})}finally{e&&await n.n({endpoint:_,bucket:y,region:x,accessKeyId:C,secretAccessKey:T,customDomain:D||void 0}).remove(e).catch(()=>{}),m(!1)}},[_,y,x,C,T,D,p]);return o?(0,i.jsxs)(`div`,{className:`fixed inset-0 z-[9999] flex items-center justify-center`,children:[h&&(0,i.jsx)(`div`,{className:`fixed right-4 top-4 z-[10001] w-[calc(100vw-32px)] max-w-sm rounded-xl border px-4 py-3 text-sm shadow-2xl backdrop-blur-sm ${h.type===`success`?`border-green-200 bg-green-50/95 text-green-700`:`border-danger-200 bg-danger-50/95 text-danger`}`,children:(0,i.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,i.jsx)(`span`,{className:`mt-0.5 shrink-0`,children:h.type===`success`?`✓`:`!`}),(0,i.jsx)(`span`,{className:`min-w-0 break-words`,children:h.message})]})}),(0,i.jsx)(`div`,{className:`absolute inset-0 bg-black/40 backdrop-blur-sm`,onClick:s}),(0,i.jsxs)(`div`,{className:`relative w-[calc(100vw-32px)] max-w-[460px] max-h-[85vh] bg-background rounded-2xl shadow-2xl border border-default-200 overflow-hidden animate-in`,children:[(0,i.jsxs)(`div`,{className:`flex items-center justify-between px-5 py-4 border-b border-default-100`,children:[(0,i.jsx)(`h2`,{className:`text-base font-semibold`,children:`存储设置`}),(0,i.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:s,children:`✕`})]}),c&&(0,i.jsxs)(`div`,{className:`mx-5 mt-4 p-3 rounded-xl bg-default-50 border border-default-100`,children:[(0,i.jsxs)(`div`,{className:`flex items-center gap-2 text-xs text-default-500 mb-1`,children:[(0,i.jsx)(`span`,{className:`w-1.5 h-1.5 rounded-full bg-green-500`}),`当前存储服务`]}),(0,i.jsx)(`div`,{className:`text-sm font-medium`,children:c.name}),(0,i.jsx)(`div`,{className:`text-[11px] text-default-400 mt-0.5`,children:c.type===`local`?`位置:浏览器内存 · Base64 编码 · 关闭页面后丢失`:c.type===`s3`&&c.config?.type===`s3`?`${c.config.endpoint} · ${c.config.bucket}${c.config.customDomain?` → ${c.config.customDomain}`:``}`:``})]}),(0,i.jsx)(`div`,{className:`flex border-b border-default-100 px-5 mt-4`,children:a.map(({key:e,label:t,icon:n})=>(0,i.jsxs)(`button`,{type:`button`,className:`flex items-center gap-1.5 px-3 py-2.5 text-sm font-medium transition-colors border-b-2 -mb-[1px] ${l===e?`border-primary text-primary`:`border-transparent text-default-400 hover:text-default-600`}`,onClick:()=>{u(e),f(!1)},children:[(0,i.jsx)(`span`,{children:n}),t]},e))}),(0,i.jsxs)(`div`,{className:`p-5 max-h-[50vh] overflow-y-auto`,children:[l===`local`&&(0,i.jsxs)(`div`,{className:`space-y-4`,children:[(0,i.jsxs)(`div`,{className:`p-4 rounded-xl bg-blue-50 border border-blue-100`,children:[(0,i.jsx)(`p`,{className:`text-sm font-medium text-blue-800 mb-1`,children:`💻 浏览器内存存储`}),(0,i.jsx)(`p`,{className:`text-xs text-blue-600 leading-relaxed`,children:`文件以 Base64 编码存储在浏览器内存中,页面关闭后清除。 适合演示和临时使用,不建议用于生产环境。`})]}),(0,i.jsx)(`button`,{type:`button`,className:`w-full py-2.5 rounded-xl text-sm font-medium transition-all ${d?`bg-green-500 text-white`:`bg-primary text-white hover:opacity-90`}`,onClick:N,children:d?`✓ 已保存`:`使用本地存储`}),(0,i.jsx)(`button`,{type:`button`,className:`w-full py-2.5 rounded-xl text-sm font-medium border border-default-200 hover:bg-default-100 transition-all disabled:opacity-40`,disabled:p,onClick:P,children:p?`测试中...`:`测试连接`})]}),l===`s3`&&(0,i.jsxs)(`div`,{className:`space-y-3`,children:[(0,i.jsx)(`div`,{className:`p-3 rounded-lg bg-default-50 text-xs text-default-500 leading-relaxed mb-1`,children:`兼容 AWS S3、Cloudflare R2、MinIO、阿里云 OSS、腾讯云 COS 等所有 S3 协议对象存储服务。`}),(0,i.jsxs)(`div`,{children:[(0,i.jsx)(`label`,{className:`block text-xs text-default-500 mb-1`,children:`Endpoint *`}),(0,i.jsx)(`input`,{className:`w-full px-3 py-2 rounded-lg border border-default-200 bg-background text-sm focus:outline-none focus:border-primary`,placeholder:`https://<account>.r2.cloudflarestorage.com`,value:_,onChange:e=>v(e.target.value)})]}),(0,i.jsxs)(`div`,{children:[(0,i.jsx)(`label`,{className:`block text-xs text-default-500 mb-1`,children:`Bucket 名称 *`}),(0,i.jsx)(`input`,{className:`w-full px-3 py-2 rounded-lg border border-default-200 bg-background text-sm focus:outline-none focus:border-primary`,placeholder:`my-bucket`,value:y,onChange:e=>b(e.target.value)})]}),(0,i.jsxs)(`div`,{children:[(0,i.jsx)(`label`,{className:`block text-xs text-default-500 mb-1`,children:`Region`}),(0,i.jsx)(`input`,{className:`w-full px-3 py-2 rounded-lg border border-default-200 bg-background text-sm focus:outline-none focus:border-primary`,placeholder:`auto / us-east-1 / ap-northeast-1`,value:x,onChange:e=>S(e.target.value)}),(0,i.jsxs)(`p`,{className:`text-[11px] text-default-400 mt-0.5`,children:[`R2 / MinIO 填 `,(0,i.jsx)(`code`,{children:`auto`}),`,AWS 按实际区域填写`]})]}),(0,i.jsxs)(`div`,{children:[(0,i.jsx)(`label`,{className:`block text-xs text-default-500 mb-1`,children:`Access Key ID *`}),(0,i.jsx)(`input`,{className:`w-full px-3 py-2 rounded-lg border border-default-200 bg-background text-sm focus:outline-none focus:border-primary`,placeholder:`AKIAIOSFODNN7EXAMPLE`,value:C,onChange:e=>w(e.target.value)})]}),(0,i.jsxs)(`div`,{children:[(0,i.jsx)(`label`,{className:`block text-xs text-default-500 mb-1`,children:`Secret Access Key`}),(0,i.jsx)(`input`,{type:`password`,className:`w-full px-3 py-2 rounded-lg border border-default-200 bg-background text-sm focus:outline-none focus:border-primary`,placeholder:`••••••••`,value:T,onChange:e=>E(e.target.value)})]}),(0,i.jsxs)(`div`,{children:[(0,i.jsx)(`label`,{className:`block text-xs text-default-500 mb-1`,children:`自定义访问域名(CDN,可选)`}),(0,i.jsx)(`input`,{className:`w-full px-3 py-2 rounded-lg border border-default-200 bg-background text-sm focus:outline-none focus:border-primary`,placeholder:`cdn.example.com`,value:D,onChange:e=>O(e.target.value)}),(0,i.jsx)(`p`,{className:`text-[11px] text-default-400 mt-0.5`,children:`设置后,上传返回的资源 URL 将使用此域名`})]}),(0,i.jsxs)(`div`,{children:[(0,i.jsx)(`label`,{className:`block text-xs text-default-500 mb-1`,children:`资源目录`}),(0,i.jsx)(`input`,{className:`w-full px-3 py-2 rounded-lg border border-default-200 bg-background text-sm focus:outline-none focus:border-primary`,placeholder:`qingwu`,value:k,onChange:e=>A(e.target.value)}),(0,i.jsx)(`p`,{className:`text-[11px] text-default-400 mt-0.5`,children:`上传文件的存储目录,默认 qingwu(MinIO/S3 路径风格需填 bucket 名)`})]}),(0,i.jsxs)(`div`,{children:[(0,i.jsx)(`label`,{className:`block text-xs text-default-500 mb-1`,children:`文件名模板`}),(0,i.jsx)(`input`,{className:`w-full px-3 py-2 rounded-lg border border-default-200 bg-background text-sm focus:outline-none focus:border-primary`,placeholder:`{ts}{tz}_{src}_{name}_{rand}{ext}`,value:j,onChange:e=>M(e.target.value)}),(0,i.jsx)(`p`,{className:`text-[11px] text-default-400 mt-0.5`,children:`占位符: {ts}=时间戳, {tz}=时区, {src}=出处(editor/cover), {name}=原名, {ext}=扩展名, {rand}=随机串`})]}),(0,i.jsxs)(`div`,{className:`p-3 rounded-lg bg-default-50 text-[11px] text-default-500 leading-relaxed`,children:[`上传路径:`,_&&y?`${_}/${y}/qingwu/...`:`请填写 Endpoint 和 Bucket`,D?`\n访问域名:https://${D}/qingwu/...`:``]}),(0,i.jsxs)(`div`,{className:`grid grid-cols-2 gap-2`,children:[(0,i.jsx)(`button`,{type:`button`,className:`py-2.5 rounded-xl text-sm font-medium border border-default-200 hover:bg-default-100 transition-all disabled:opacity-40`,disabled:!_||!y||!C||p,onClick:I,children:p?`测试中...`:`测试连接`}),(0,i.jsx)(`button`,{type:`button`,className:`py-2.5 rounded-xl text-sm font-medium transition-all disabled:opacity-40 ${d?`bg-green-500 text-white`:`bg-primary text-white hover:opacity-90`}`,disabled:!_||!y||!C||p,onClick:F,children:d?`✓ 已保存`:`保存并应用`})]})]})]})]})]}):null};exports.StorageSettingsDialog=o;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@qingwu-ui/ai-editor",
3
- "version": "0.9.0-beta.10",
3
+ "version": "0.9.0-beta.11",
4
4
  "description": "青梧 - 一款面向中文用户的 AI 智能编辑器",
5
5
  "type": "module",
6
6
  "license": "Apache-2.0",