aitu-app 0.9.0 → 0.9.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -3
- package/assets/{CanvasAudioPlayer-cp00LGgR.js → CanvasAudioPlayer-C_USx5uz.js} +1 -1
- package/assets/{ComicCreator-CAmJF3JX.js → ComicCreator-qGQaXp7h.js} +2 -2
- package/assets/DeferredAIInputBar-CPykEFYX.css +1 -0
- package/assets/DeferredAIInputBar-LmZGQCLT.js +107 -0
- package/assets/{DrawnixDeferredFeatures-DIznfzB7.js → DrawnixDeferredFeatures-Hy_-quZ1.js} +1 -1
- package/assets/{KnowledgeBaseContent-CxilHI-j.js → KnowledgeBaseContent-DSKNA70H.js} +8 -8
- package/assets/{MVCreator-ZrinzYPm.js → MVCreator-C3iClDLU.js} +12 -10
- package/assets/{ModelBenchmarkWorkbench-DbesnX6E.js → ModelBenchmarkWorkbench-BxwdcZ0q.js} +2 -2
- package/assets/{MusicAnalyzer-BzXD1qYH.js → MusicAnalyzer-f_T6_YPJ.js} +2 -2
- package/assets/{ParametersDropdown-DBQCDv3g.js → ParametersDropdown-CTSN3ClD.js} +1 -1
- package/assets/{PromptHistoryTool-CUCIE0Ld.js → PromptHistoryTool-DV-8RSdz.js} +2 -2
- package/assets/{ResizableDivider-CdfJF8GW.js → ResizableDivider-CUQBmPpx.js} +1 -1
- package/assets/TaskQueuePanel-CtjY1W4t.js +1 -0
- package/assets/{VideoAnalyzer-wtxorxD3.js → VideoAnalyzer-BBVBSONO.js} +3 -3
- package/assets/{VideoAnalyzer-C90c84gt.js → VideoAnalyzer-BmAjGvN8.js} +1 -1
- package/assets/{ai-chat-B5qFht2H.js → ai-chat-BO5vbKZW.js} +5 -5
- package/assets/{ai-generation-preferences-service-CvWbMxv3.js → ai-generation-preferences-service-ZmPTR-wz.js} +1 -1
- package/assets/{batch-image-generation-Bo3h_Eop.js → batch-image-generation-BLBSv-t6.js} +6 -6
- package/assets/{diagram-engines-C9ewAq_o.js → diagram-engines-CSzW_-6N.js} +2 -2
- package/assets/{editor-engines-CvxZrFyB.js → editor-engines-C573k8UM.js} +1 -1
- package/assets/{index-Dw6PsLbq.js → index-BT-rxxI3.js} +2 -2
- package/assets/{index-BCqdmg38.js → index-Dw_8lcIi.js} +1 -1
- package/assets/{index-BSlnQdcy.js → index-IHNaVKGH.js} +1 -1
- package/assets/{index-CjBeKr1R.js → index-N8asYyaz.js} +1 -1
- package/assets/{index-CylhK_f5.js → index-jxwTv7c1.js} +1 -1
- package/assets/{index.es-BKVY-J2g.js → index.es-BLXvmueB.js} +1 -1
- package/assets/{jspdf.es.min-BM9ML7Zw.js → jspdf.es.min-DxWvbkh4.js} +2 -2
- package/assets/{markdown-to-drawnix-COS1iVyq.js → markdown-to-drawnix-BVFYnimo.js} +2 -2
- package/assets/{mermaid-to-drawnix-oplawQO0.js → mermaid-to-drawnix-nGs2aeZ7.js} +2 -2
- package/assets/{model-benchmark-launcher-DD4vN0Ca.js → model-benchmark-launcher-DAWoSySc.js} +1 -1
- package/assets/{photo-wall-splitter-CbKqFOIV.js → photo-wall-splitter-CCUURzGk.js} +1 -1
- package/assets/{prompt-utils-7t-jk6n6.js → prompt-utils-MF_LILNU.js} +1 -1
- package/assets/{settings-dialog-D2yEWl8J.js → settings-dialog-Ac7R-_CG.js} +1 -1
- package/assets/{skill-dsl-parser-C-utRXFg.js → skill-dsl-parser-Do9iAYbB.js} +1 -1
- package/assets/{startup-app-DxX-P1pm.js → startup-app-eD_rQhSh.js} +531 -527
- package/assets/{task-sync-Dr7Nza2v.js → task-sync-BJVOunRa.js} +1 -1
- package/assets/{tool-windows-BIjc1zsU.js → tool-windows-CmgL3thd.js} +17 -17
- package/assets/ttd-dialog-B12v0SVY.js +6 -0
- package/assets/{ttd-dialog-submit-shortcut-yUk15rsg.js → ttd-dialog-submit-shortcut-C2lJygXA.js} +1 -1
- package/assets/useCharacters-BAKE4TeJ.js +2 -0
- package/assets/{useMediaViewer-CEvHYype.js → useMediaViewer-BGw5RkSR.js} +1 -1
- package/assets/{useWorkflowSubmission-Cxhdsl2b.js → useWorkflowSubmission-iAPmKke9.js} +6 -6
- package/assets/{video-recovery-service-CB8hyRf5.js → video-recovery-service-CW7bErP2.js} +1 -1
- package/assets/{workflow-generation-utils-JoRODaP7.js → workflow-generation-utils-DhIVnOHO.js} +2 -2
- package/assets/workflow-submission-service-Ce0cpj8E.js +4 -0
- package/changelog.json +18 -13
- package/idle-prefetch-manifest.json +306 -306
- package/manifest.json +3 -3
- package/package.json +1 -1
- package/precache-manifest.json +6 -6
- package/sw.js +1 -1
- package/version.json +6 -3
- package/assets/DeferredAIInputBar-CzMATNng.js +0 -107
- package/assets/DeferredAIInputBar-D_e6qG1y.css +0 -1
- package/assets/TaskQueuePanel-oLG4DAzJ.js +0 -1
- package/assets/ttd-dialog-CNSSc4wk.js +0 -6
- package/assets/useCharacters-DzXMuknh.js +0 -2
- package/assets/workflow-submission-service-BIGFW4s4.js +0 -4
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["./startup-app-CKHrOmQ0.css","./editor-engines-B8u8agiX.css","./tool-windows-CegtMid1.css"])))=>i.map(i=>d[i]);
|
|
2
|
-
import{r as a,n as ut,s as _s,j as s,P as Vo,i as ar,g as Bn,a as Gn,C as Ue,b as qt,c as Rn,d as cr,H as Bo,M as Ke,A as lr,R as Tt,G as Go,Z as dr,e as ur,f as Kt,h as mr,F as pr,k as hr,l as fr,D as gr,m as wr,o as yr,p as qo,q as Ko,t as Zo,u as cn,X as Mt,v as gn,w as xr,x as bs,y as it,z as Yo,B as Xo,L as Jo,U as Qo,S as ei,E as je,I as ti,J as ni,K as si,N as ri,O as oi,Q as ii,T as ai,V as ci,W as li,Y as di,_ as Rt,$ as ui,a0 as qn,a1 as _r,a2 as mi,a3 as vs,a4 as pi,a5 as hi,a6 as Fe,a7 as vn,a8 as fi,a9 as gi,aa as wi,ab as yi,ac as xi,ad as Ss,ae as Kn,af as _i,ag as bi,ah as se,ai as vi,aj as Si,ak as Zn,al as ht,am as ye,an as Ii,ao as ln,ap as ki,aq as br,ar as Dt,as as vr,at as Mi,au as Sr,av as zn,aw as Ci,ax as Ir,ay as Is,az as Dn,aA as ji,aB as ks,aC as Ht,aD as Ln,aE as Ti,aF as Sn,aG as Ni,aH as Ei,aI as Pi,aJ as Ai,aK as Ri,aL as zi,aM as kr,aN as Di,aO as Li,aP as Ms,aQ as $i,aR as Yn,aS as Oi,aT as Fi,aU as Mr,aV as Cr,aW as jr,aX as at,aY as Xn,aZ as Jn,a_ as Qn,a$ as Ui,b0 as Wi,b1 as Tr,b2 as Nr,b3 as Zt,b4 as Er,b5 as Pr,b6 as Hi,b7 as Vi,b8 as Cs,b9 as Bi,ba as Ar,bb as Yt,bc as Ct,bd as Gi,be as wn,bf as Rr,bg as xt,bh as yn,bi as qi,bj as Ki,bk as zr,bl as Zi,bm as Yi,bn as es,bo as Xi,bp as Dr,bq as $n,br as Ji,bs as Lr,bt as ts,bu as $r,bv as Qi,bw as ns,bx as ss,by as Or,bz as ft,bA as ea,bB as ta,bC as Fr,bD as na,bE as sa,bF as ra,bG as oa,bH as ia,bI as aa,bJ as ca,bK as Ur,bL as la,bM as da,bN as ua,bO as ma,bP as pa,bQ as ha,bR as js,bS as fa,bT as ga,bU as wa,bV as ya,bW as xa,bX as _a,bY as ba,bZ as va,b_ as Sa,b$ as Ia,c0 as Wr,c1 as ka,c2 as Ma,c3 as Ca,c4 as ja,c5 as Ts,c6 as Ta,c7 as Na,c8 as Ea,c9 as Pa,ca as Aa,cb as Ra,cc as za,cd as Da,ce as Hr,cf as La,cg as $a,ch as Oa,ci as Fa,cj as Ua,ck as Wa,cl as Ha,cm as Vr,cn as Va,co as Br,cp as In,cq as kn,cr as Ns,cs as Es,ct as Ba,cu as Ga}from"./startup-app-DxX-P1pm.js";import{_ as dt}from"./startup-runtime-DTmhLESk.js";const St=new Map,Gr=300*1e3,Ps=500,gt=new Set;let zt=!1,Mn=null,Cn=null;function qa(){return Mn||(Mn=caches.open("drawnix-images-thumb")),Mn}function Ka(){return Cn||(Cn=caches.open("drawnix-images")),Cn}function qr(t,e){return`${t}|${e}`}function Za(t,e){try{const n=new URL(t,window.location.origin);return n.searchParams.delete("thumbnail"),n.searchParams.set("_thumb",e),n.toString()}catch{const n=t.replace(/[?&]thumbnail=[^&]*/g,"").replace(/thumbnail=[^&]*&?/g,""),r=n.includes("?")?"&":"?";return`${n}${r}_thumb=${e}`}}function xn(t,e){return t.startsWith("data:")||t.startsWith("blob:")||e!=="video"&&(t.startsWith("http://")||t.startsWith("https://"))}function As(t,e="small",n){const r=ut(t);if(xn(r,n))return r;try{const i=new URL(r,window.location.origin);return i.searchParams.set("thumbnail",e),i.toString()}catch{const i=r.includes("?")?"&":"?";return`${r}${i}thumbnail=${e}`}}async function Vt(){if(!(zt||gt.size===0)){zt=!0;try{const t=Date.now();if(St.size>Ps)for(const[r,i]of St)(t-i>Gr||St.size>Ps)&&St.delete(r);const n=Array.from(gt).slice(0,5);for(const r of n){gt.delete(r);const[i,o,c="small"]=r.split("|");try{await Kr(i,o,c),St.set(qr(i,c),Date.now())}catch(l){console.warn("Failed to ensure thumbnail:",i,l)}}gt.size>0&&("requestIdleCallback"in window?window.requestIdleCallback(Vt):setTimeout(Vt,100))}finally{zt=!1}}}async function Kr(t,e,n){const r=ut(t);if(xn(r,e))return;const i=Za(r,n);if(await(await qa()).match(i))return;const l=await Ka();let m=await l.match(r);if(!m)try{const u=new URL(r,window.location.origin);(u.pathname.startsWith("/__aitu_cache__/")||u.pathname.startsWith("/asset-library/"))&&(m=await l.match(u.pathname))}catch{}if(m){const u=await m.blob();if(_s.isInitialized()){const d=await u.arrayBuffer();await _s.generateThumbnail(r,e,d,u.type,[n])}}}function Ya(t,e,n,r=!1){const i=ut(t);if(xn(i,e))return;const o=qr(i,n),c=St.get(o);if(c&&Date.now()-c<Gr)return;const l=`${i}|${e}|${n}`;if(!gt.has(l)){if(gt.add(l),r){(async()=>{if(!zt)try{zt=!0,gt.delete(l),await Kr(i,e,n),St.set(o,Date.now())}catch(m){console.warn("Failed to ensure thumbnail immediately:",i,m)}finally{zt=!1,gt.size>0&&setTimeout(Vt,0)}})();return}"requestIdleCallback"in window?window.requestIdleCallback(Vt,{timeout:2e3}):setTimeout(Vt,200)}}function Xa(t,e,n="small"){const[r,i]=a.useState(t?As(t,n,e):void 0);return a.useEffect(()=>{if(!t){i(void 0);return}const o=ut(t),c=As(o,n,e);i(c),e&&!xn(t,e)&&Ya(t,e,n,e==="video")},[t,e,n]),r}const Rs=1,Ja=4,Zr=600*1e3,Yr=600*1e3,dn=new Map,un=new Map;function Xr(t){dn.forEach((e,n)=>{t-e>Zr&&dn.delete(n)})}function Qa(t){const e=Date.now();Xr(e),dn.set(t,e)}function ec(t){const e=Date.now();Xr(e);const n=dn.get(t);return typeof n=="number"&&e-n<=Zr}function Jr(t){un.forEach((e,n)=>{t-e.resolvedAt>Yr&&un.delete(n)})}function tc(t,e){const n=Date.now();Jr(n),un.set(t,{resolvedPoster:e,resolvedAt:n})}function zs(t){if(!t)return null;const e=Date.now();Jr(e);const n=un.get(t);return n&&e-n.resolvedAt<=Yr?n.resolvedPoster:null}function nc(t,e){if(e<=0||!t)return t;try{const n=new URL(t,window.location.origin);return n.searchParams.set("_poster_retry",String(e)),n.toString()}catch{const n=t.includes("?")?"&":"?";return`${t}${n}_poster_retry=${e}`}}function jn(t,e){return s.jsxs("div",{className:"video-poster-preview",children:[t,e&&s.jsx("div",{className:"video-poster-preview__play-overlay","aria-hidden":"true",children:s.jsx(Vo,{size:"32px"})})]})}const sc=({src:t,poster:e,alt:n="",className:r,thumbnailSize:i="small",imageLoading:o="lazy",activateVideoOnClick:c=!1,playOnActivate:l=!1,onClick:m,videoProps:u})=>{const d=a.useMemo(()=>typeof e=="string"&&e.trim()?e.trim():void 0,[e]),p=a.useMemo(()=>d?ec(d):!1,[d]),h=Xa(t,"video",i),[g,y]=a.useState(p),f=g?h:d||h,x=!!(d&&!g),z=!!(f&&f===h&&f!==t),N=a.useRef(null),O=a.useRef(!1),T=a.useRef(null),[I,b]=a.useState(()=>zs(f)),[S,C]=a.useState(0),[R,U]=a.useState(!1),P=c;a.useEffect(()=>{y(p)},[p]),a.useEffect(()=>{b(zs(f)),C(0),U(!1),O.current=!1,T.current!==null&&(window.clearTimeout(T.current),T.current=null)},[t,f,c,h,d,i]),a.useEffect(()=>{if(R||I&&I===f)return;if(!f){P||U(!0);return}const Q=x?f:nc(f,S);let B=!1;const _=new Image,E=()=>{if(!z||S>=Ja){P||U(!0);return}T.current=window.setTimeout(()=>{C(M=>M+1)},180+S*220)};return _.onload=()=>{if(!B){if(x||_.naturalWidth>Rs||_.naturalHeight>Rs){tc(f,f),b(f);return}E()}},_.onerror=()=>{if(!B){if(x&&d){Qa(d),y(!0),b(null),C(0);return}E()}},_.src=Q,()=>{B=!0,_.onload=null,_.onerror=null,T.current!==null&&(window.clearTimeout(T.current),T.current=null)}},[t,f,S,x,z,R,d,I,P]),a.useEffect(()=>{var Q;!R||!l||!O.current||(O.current=!1,(Q=N.current)==null||Q.play().catch(()=>{}))},[R,l]),a.useEffect(()=>()=>{const Q=N.current;if(Q)try{Q.pause(),Q.removeAttribute("src"),Q.load()}catch{}},[]);const J=Q=>{c&&(O.current=!0,U(!0)),m==null||m(Q)},ee=Q=>{m==null||m(Q)},X=c&&!R;return!R&&I?jn(s.jsx("img",{src:I,alt:n,className:`video-poster-preview__media${r?` ${r}`:""}`,loading:o,decoding:"async",draggable:!1,referrerPolicy:"no-referrer",onClick:J}),X):!R&&!I?jn(s.jsx("div",{className:`video-poster-preview__placeholder${r?` ${r}`:""}`,"aria-hidden":"true",onClick:c?()=>{O.current=!0,U(!0)}:void 0}),X):jn(s.jsx("video",{ref:N,src:t,poster:I||d,className:`video-poster-preview__media${r?` ${r}`:""}`,playsInline:!0,...u,onClick:ee}),!1)},rc=.1,oc=5,Ds=t=>Math.max(rc,Math.min(oc,t));function ic(t){const{items:e,initialMode:n="single",initialIndex:r=0,maxCompareSlots:i=4,defaultCompareLayout:o="horizontal",visible:c,onModeChange:l}=t,m=a.useCallback(()=>{if(Array.isArray(r))return r.slice(0,i);const q=typeof r=="number"?r:0,ce=(q+1)%e.length;return e.length>1?[q,ce]:[q]},[r,i,e.length]),u=a.useCallback(()=>{const q=m().length;return q>=4?4:q===3?3:2},[m]),[d,p]=a.useState(n),[h,g]=a.useState(typeof r=="number"?r:0),[y,f]=a.useState(m),[x,z]=a.useState(o),[N,O]=a.useState(!1),[T,I]=a.useState(1),[b,S]=a.useState({x:0,y:0}),[C,R]=a.useState(0),[U,P]=a.useState(u);a.useEffect(()=>{if(c){const q=m();p(n),g(typeof r=="number"?r:0),f(q),P(q.length>=4?4:q.length===3?3:2),I(1),S({x:0,y:0}),R(0)}},[c,n,r,m]);const J=a.useRef(e);a.useEffect(()=>{if(!c||e===J.current){J.current=e;return}const q=J.current;J.current=e;const ce=q[h];if(!(ce!=null&&ce.id))return;const ve=e.findIndex(me=>me.id===ce.id);ve!==-1&&ve!==h&&g(ve)},[c,e,h]);const ee=a.useMemo(()=>({mode:d,currentIndex:h,compareIndices:y,compareLayout:x,syncMode:N,zoomLevel:T,panOffset:b,focusedSlot:C}),[d,h,y,x,N,T,b,C]),X=a.useCallback(q=>{if(q!==d){if(q==="compare"){const ce=(h+1)%e.length;f(e.length>1?[h,ce]:[h])}else{const ce=y[C]??y[0]??0;g(ce)}p(q),I(1),S({x:0,y:0}),l==null||l(q)}},[d,h,e.length,y,C,l]),Q=a.useCallback(q=>{q>=0&&q<e.length&&(g(q),I(1),S({x:0,y:0}))},[e.length]),B=a.useCallback(()=>{const q=h>0?h-1:e.length-1;Q(q)},[h,e.length,Q]),_=a.useCallback(()=>{const q=h<e.length-1?h+1:0;Q(q)},[h,e.length,Q]),E=a.useCallback((q,ce)=>{f(ve=>{const me=[...ve];return typeof ce=="number"&&ce<U?me[ce]=q:me.length<U?me.push(q):me[C]=q,me})},[U,C]),M=a.useCallback(q=>{f(ce=>{if(ce.length<=2)return ce;const ve=[...ce];return ve.splice(q,1),ve}),C>=q&&C>0&&R(C-1)},[C]),$=a.useCallback((q,ce)=>{f(ve=>{const me=[...ve],Re=me[q];return me[q]=me[ce],me[ce]=Re,me})},[]),re=a.useCallback(q=>{z(q)},[]),fe=a.useCallback(()=>{O(q=>!q)},[]),K=a.useCallback(q=>{I(ce=>{const ve=ce+q;return Ds(ve)})},[]),de=a.useCallback(q=>{I(Ds(q))},[]),ie=a.useCallback(()=>{I(1),S({x:0,y:0})},[]),ue=a.useCallback(q=>{S(q)},[]),xe=a.useCallback(q=>{R(q)},[]),pe=a.useCallback(q=>{P(q),f(ce=>{if(ce.length>q)return ce.slice(0,q);if(ce.length<q&&e.length>ce.length){const ve=[...ce];let me=(ce[ce.length-1]+1)%e.length;for(;ve.length<q&&ve.length<e.length;)ve.includes(me)||ve.push(me),me=(me+1)%e.length;return ve}return ce})},[e.length]),ae=a.useMemo(()=>({setMode:X,goTo:Q,goToPrev:B,goToNext:_,addToCompare:E,removeFromCompare:M,swapSlots:$,setCompareLayout:re,toggleSyncMode:fe,zoom:K,setZoomLevel:de,setPan:ue,resetView:ie,setFocusedSlot:xe,setSlotCount:pe}),[X,Q,B,_,E,M,$,re,fe,K,de,ue,ie,xe,pe]);return[ee,ae]}let Qr=null;function om(t){Qr=t}function ac(){return Qr}const Nt=400;function cc(t){return t==="video"?{width:Nt,height:Math.round(Nt*(9/16))}:{width:Nt,height:Nt}}async function lc(t,e,n,r,i){const o=i||cc(e);return e==="video"?(await Rn(t,n,r,!1,o,!0,!0),o):(await cr(t,n,r,!1,o,!0,!0),o)}async function dc(t,e,n,r){const i=ac();if(!i)return{success:!1,error:"画布未初始化,请先打开画布",type:"error"};try{if(!n){const u=await ar(i,e,t,r);if(u)return{success:!0,data:{insertedCount:1,items:[{type:t,point:u.point,elementId:u.elementId,size:u.size}],firstElementId:u.elementId,firstElementPosition:u.point,firstElementSize:u.size},type:"text"}}const o=n||Bn(i,{logPrefix:"MediaQuickInsert"})||Gn(i,{emptyPoint:Ue.DEFAULT_POINT})||Ue.DEFAULT_POINT,c=i.children.length,l=await lc(i,t,e,o,r),m=i.children[c];return requestAnimationFrame(()=>{qt(i,[o[0]+Nt/2,o[1]+Nt/2])}),{success:!0,data:{insertedCount:1,items:[{type:t,point:o,elementId:m==null?void 0:m.id,size:l}],firstElementId:m==null?void 0:m.id,firstElementPosition:o,firstElementSize:l},type:"text"}}catch(o){return console.error("[MediaQuickInsert] Failed to insert media:",o),{success:!1,error:`插入失败: ${o.message||"未知错误"}`,type:"error"}}}const ke=({content:t,children:e,placement:n="bottom",sideOffset:r=8,crossAxisOffset:i=0,contentClassName:o,closeDelay:c=100})=>s.jsx(Bo,{content:t,placement:n,sideOffset:r,crossAxisOffset:i,contentClassName:o||"viewer-popover",closeDelay:c,children:e}),tn={x:0,y:0},uc=.1,mc=5,Ft=.001,Ls=.25,pc=.0025,$s=.08,hc=1,fc=2,gc=16,wc=800,yc=32,xc=88,_c=140,bc=t=>Math.max(uc,Math.min(mc,t)),vc=t=>t.deltaMode===hc?t.deltaY*gc:t.deltaMode===fc?t.deltaY*wc:t.deltaY,Sc=t=>Math.max(-$s,Math.min($s,t)),Ic=(t,e)=>{if(t.offsetWidth>0&&t.offsetHeight>0)return{width:t.offsetWidth,height:t.offsetHeight};const n=t.getBoundingClientRect(),r=Math.max(Math.abs(e),Ft);return{width:n.width/r,height:n.height/r}},eo="media-viewport-toolbar-state-single",kc=()=>{try{const t=localStorage.getItem(eo);if(t)return JSON.parse(t)}catch{}return{orientation:"horizontal",position:null}},Mc=t=>{try{localStorage.setItem(eo,JSON.stringify(t))}catch{}},On=a.forwardRef(({item:t,slotIndex:e,isFocused:n=!1,zoomLevel:r=1,panOffset:i,onClick:o,videoAutoPlay:c=!1,videoLoop:l=!0,onZoomChange:m,onPanChange:u,isCompareMode:d=!1,onInsertToCanvas:p,onDownload:h,onEdit:g,onVideoPlayStateChange:y,onVideoTimeUpdate:f,isSyncMode:x=!1},z)=>{var Ze;const N=a.useRef(null),O=a.useRef(null),T=a.useRef(null),[I,b]=a.useState(!1),[S,C]=a.useState(!0),[R,U]=a.useState(!1),[P,J]=a.useState({x:0,y:0}),[ee,X]=a.useState(i??tn),[Q,B]=a.useState(r),_=a.useRef(r),[E,M]=a.useState(0),[$,re]=a.useState(!1),[fe,K]=a.useState(!1),[de,ie]=a.useState(!1),[ue,xe]=a.useState(!1),[pe,ae]=a.useState(!1),q=a.useRef(null),ce=a.useRef(!1),ve=a.useRef(r),me=a.useRef(i);a.useImperativeHandle(z,()=>({resetVideo:()=>{O.current&&(O.current.currentTime=0,O.current.play().catch(()=>{}))},playVideo:()=>{O.current&&O.current.play().catch(()=>{})},pauseVideo:()=>{O.current&&O.current.pause()},toggleVideoPlayback:()=>{if(O.current){if(O.current.paused||O.current.ended){O.current.play().catch(()=>{});return}O.current.pause()}},setVideoTime:A=>{O.current&&(O.current.currentTime=A)},getVideoTime:()=>{var A;return((A=O.current)==null?void 0:A.currentTime)??0},isVideo:()=>(t==null?void 0:t.type)==="video"}),[t]);const[Re]=a.useState(()=>d?{orientation:"horizontal",position:null}:kc()),[Me,We]=a.useState(Re.orientation),[Ee,Te]=a.useState(Re.position),[Ye,$e]=a.useState(!1),be=a.useRef({x:0,y:0,posX:0,posY:0}),Ie=(t==null?void 0:t.type)==="video",he=(t==null?void 0:t.type)==="audio",ze=((Ze=t==null?void 0:t.prompt)==null?void 0:Ze.trim())||"",De=!!ze&&(de||ue)&&!pe,He=t?Ie||he?t.url:ut(t.url):"",Be=t!=null&&t.posterUrl?ut(t.posterUrl):"",Ge=t?`${t.type}:${t.id||t.url}`:"empty",Qe=!!(t!=null&&t.url&&!he&&!d&&!I),Ne=a.useCallback(()=>{q.current!==null&&(window.clearTimeout(q.current),q.current=null)},[]),L=a.useCallback(()=>{Ne(),ie(!0)},[Ne]),w=a.useCallback(()=>{ie(!1),Ne(),q.current=window.setTimeout(()=>{xe(!1),q.current=null},120)},[Ne]),V=a.useCallback(()=>{Ne(),xe(!0)},[Ne]),v=a.useCallback(()=>{xe(!1)},[]);a.useLayoutEffect(()=>{b(!1),C(!(t!=null&&t.url)||he||d),U(!1);const A=me.current??tn,ge=ve.current;X(A),_.current=ge,B(ge),M(0),re(!1),K(!1),ce.current=!1},[Ge,t==null?void 0:t.url,he,d]),a.useEffect(()=>()=>{Ne()},[Ne]),a.useEffect(()=>{d||Mc({orientation:Me,position:Ee})},[Me,Ee,d]),a.useLayoutEffect(()=>{const A=i??tn;me.current=i,X(ge=>ge.x===A.x&&ge.y===A.y?ge:A)},[i]),a.useLayoutEffect(()=>{ve.current=r,_.current=r,B(A=>A===r?A:r)},[r]);const D=a.useCallback((A,ge="manual")=>{const Le=bc(A);ge==="manual"&&(ce.current=!0),!(Math.abs(_.current-Le)<=Ft)&&(_.current=Le,B(tt=>Math.abs(tt-Le)<=Ft?tt:Le),m==null||m(Le))},[m]),W=a.useCallback(A=>{const ge=me.current??tn;Math.abs(ge.x-A.x)<=Ft&&Math.abs(ge.y-A.y)<=Ft||(me.current=A,X(A),u==null||u(A))},[u]),G=a.useCallback(()=>{if(d||he||!N.current)return;if(ce.current){C(!0);return}const A=Ie?O.current:T.current;if(!A||!N.current)return;const ge=N.current.getBoundingClientRect();if(ge.width<=0||ge.height<=0)return;const Le=Ie?A.videoWidth:A.naturalWidth,tt=Ie?A.videoHeight:A.naturalHeight;if(Le<=0||tt<=0)return;const Xe=Ic(A,_.current);if(Xe.width<=0||Xe.height<=0)return;const Je=Ie?_c:xc,rt=Math.max(ge.width-yc,0),mt=Math.max(ge.height-Je,0);if(rt<=0||mt<=0)return;const ct=Math.min(rt/Xe.width,mt/Xe.height);!Number.isFinite(ct)||ct<=0||(W({x:0,y:-Je/2}),D(ct,"auto"),C(!0))},[d,he,Ie,W,D]);a.useLayoutEffect(()=>{if(!(t!=null&&t.url)||he||d)return;const A=Ie?O.current:T.current;if(!A)return;if(Ie){A.readyState>=1&&G();return}const ge=A;ge.complete&&ge.naturalWidth>0&&G()},[t,he,d,Ie,G]),a.useEffect(()=>{if(!(t!=null&&t.url)||he||d||typeof ResizeObserver>"u"||!N.current)return;const A=new ResizeObserver(()=>{G()});return A.observe(N.current),()=>{A.disconnect()}},[t==null?void 0:t.url,he,d,G]);const Y=a.useCallback(A=>{A.button===0&&(A.preventDefault(),U(!0),J({x:A.clientX-ee.x,y:A.clientY-ee.y}))},[ee]),le=a.useCallback(A=>{if(!R)return;ce.current=!0;const ge={x:A.clientX-P.x,y:A.clientY-P.y};me.current=ge,X(ge),u==null||u(ge)},[R,P,u]),_e=a.useCallback(()=>{U(!1)},[]),k=a.useCallback(A=>{A.preventDefault();const ge=vc(A);if(!Number.isFinite(ge)||ge===0)return;const Le=Sc(-ge*pc);D(_.current+Le)},[D]),H=a.useCallback(()=>{D(_.current+Ls)},[D]),F=a.useCallback(()=>{D(_.current-Ls)},[D]),Z=a.useCallback(()=>{M(A=>A-90)},[]),oe=a.useCallback(()=>{M(A=>A+90)},[]),te=a.useCallback(()=>{re(A=>!A)},[]),Pe=a.useCallback(()=>{K(A=>!A)},[]),Ce=a.useCallback(async()=>{if(t)try{const A=t.type==="video"?"video":"image";if(t.type==="audio"){Ke.warning("音频暂不支持直接插入到画布");return}const ge=await dc(A,He);ge.success?Ke.success(t.type==="video"?"视频已插入到画布":"图片已插入到画布"):Ke.error(ge.error||"插入失败")}catch(A){console.error("Failed to insert to canvas:",A),Ke.error("插入失败")}},[t,He]),Ae=a.useCallback(()=>{We(A=>A==="horizontal"?"vertical":"horizontal")},[]),qe=a.useCallback(A=>{A.preventDefault(),A.stopPropagation(),$e(!0);const ge=Ee||{x:0,y:0};be.current={x:A.clientX,y:A.clientY,posX:ge.x,posY:ge.y};const Le=Xe=>{const Je=Xe.clientX-be.current.x,rt=Xe.clientY-be.current.y;Te({x:be.current.posX+Je,y:be.current.posY+rt})},tt=()=>{$e(!1),document.removeEventListener("mousemove",Le),document.removeEventListener("mouseup",tt)};document.addEventListener("mousemove",Le),document.addEventListener("mouseup",tt)},[Ee]),et=a.useCallback(A=>{if(A.stopPropagation(),A.touches.length!==1)return;const ge=A.touches[0];$e(!0);const Le=Ee||{x:0,y:0};be.current={x:ge.clientX,y:ge.clientY,posX:Le.x,posY:Le.y};const tt=Je=>{if(Je.touches.length!==1)return;Je.preventDefault();const rt=Je.touches[0],mt=rt.clientX-be.current.x,ct=rt.clientY-be.current.y;Te({x:be.current.posX+mt,y:be.current.posY+ct})},Xe=()=>{$e(!1),document.removeEventListener("touchmove",tt),document.removeEventListener("touchend",Xe),document.removeEventListener("touchcancel",Xe)};document.addEventListener("touchmove",tt,{passive:!1}),document.addEventListener("touchend",Xe),document.addEventListener("touchcancel",Xe)},[Ee]),Ve=a.useCallback(()=>{Te(null)},[]);if(!t)return s.jsx("div",{className:`media-viewport media-viewport--empty ${n?"media-viewport--focused":""}`,onClick:o,children:s.jsx("div",{className:"media-viewport__placeholder",children:s.jsx("span",{children:"点击底部缩略图添加媒体"})})});const j=$?-Q:Q,ne=fe?-Q:Q,we={transform:`translate(${ee.x}px, ${ee.y}px) scale(${j}, ${ne}) rotate(${E}deg)`},Oe=Qe&&!S;return s.jsxs("div",{ref:N,className:`media-viewport ${n?"media-viewport--focused":""} ${he?"media-viewport--audio":""} ${Ie?"media-viewport--video":""} ${d?"":"media-viewport--single"}`,onClick:o,onMouseDown:he?void 0:Y,onMouseMove:he?void 0:le,onMouseUp:he?void 0:_e,onWheel:he?void 0:k,onMouseLeave:()=>{he||_e(),ie(!1),xe(!1),ae(!1),Ne()},"data-slot":e,children:[s.jsx("div",{className:`media-viewport__content ${Oe?"media-viewport__content--auto-fitting":""}`,style:he?void 0:we,children:Ie?s.jsx("div",{className:"media-viewport__media-hitbox",onMouseEnter:L,onMouseLeave:w,children:s.jsx("video",{ref:O,src:He,autoPlay:c,loop:l,controls:!0,className:"media-viewport__video",referrerPolicy:"no-referrer",onClick:A=>A.stopPropagation(),onPlay:()=>{x&&y&&y(!0)},onPause:()=>{x&&y&&y(!1)},onSeeked:()=>{x&&f&&O.current&&f(O.current.currentTime)},onLoadedMetadata:G})}):he?s.jsx("div",{className:"media-viewport__audio-shell",onClick:A=>A.stopPropagation(),children:s.jsxs("div",{className:"media-viewport__audio-card",children:[s.jsx(lr,{src:Be,alt:t.alt||t.title||"",imageClassName:"media-viewport__audio-poster",fallbackClassName:"media-viewport__audio-poster media-viewport__audio-poster--fallback",iconSize:56}),s.jsxs("div",{className:"media-viewport__audio-meta",children:[t.title&&s.jsx("div",{className:"media-viewport__audio-title",children:t.title}),typeof t.duration=="number"&&Number.isFinite(t.duration)&&t.duration>0&&s.jsxs("div",{className:"media-viewport__audio-duration",children:[Math.floor(t.duration/60),":",String(Math.round(t.duration%60)).padStart(2,"0")]})]}),s.jsx("audio",{src:He,controls:!0,preload:"metadata",className:"media-viewport__audio",referrerPolicy:"no-referrer"})]})}):I?s.jsx("div",{className:"media-viewport__media-hitbox",onMouseEnter:L,onMouseLeave:w,children:s.jsx("div",{className:"media-viewport__image-fallback",children:s.jsx("span",{children:"图片加载失败"})})}):s.jsx("div",{className:"media-viewport__media-hitbox",onMouseEnter:L,onMouseLeave:w,children:s.jsx(Tt,{ref:T,src:He,alt:t.alt||t.title||"",className:"media-viewport__image",draggable:!1,showSkeleton:!1,eager:!0,onLoad:G,onError:()=>{b(!0),C(!0)}})})}),s.jsxs("div",{className:`media-viewport__toolbar media-viewport__toolbar--${Me} ${Ye?"media-viewport__toolbar--dragging":""} ${d?"media-viewport__toolbar--compact":""}`,style:!d&&Ee?{transform:`translate(calc(-50% + ${Ee.x}px), ${Ee.y}px)`}:void 0,onMouseEnter:()=>ae(!0),onMouseLeave:()=>ae(!1),onMouseDown:A=>A.stopPropagation(),onClick:A=>A.stopPropagation(),children:[!he&&s.jsxs(s.Fragment,{children:[!d&&s.jsxs(s.Fragment,{children:[s.jsx(ke,{content:"拖拽移动工具栏,双击重置位置",placement:"top",contentClassName:"viewer-popover",children:s.jsx("div",{className:"media-viewport__toolbar-handle",onMouseDown:qe,onTouchStart:et,onDoubleClick:A=>{A.stopPropagation(),Ve()},children:s.jsx(Go,{size:14})})}),s.jsx(ke,{content:Me==="horizontal"?"切换为垂直布局":"切换为水平布局",placement:"top",contentClassName:"viewer-popover",children:s.jsx("button",{type:"button",className:"media-viewport__toolbar-orientation-btn",onClick:A=>{A.stopPropagation(),A.preventDefault(),Ae()},children:s.jsx("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:Me==="horizontal"?s.jsxs(s.Fragment,{children:[s.jsx("line",{x1:"12",y1:"3",x2:"12",y2:"21"}),s.jsx("polyline",{points:"8 7 12 3 16 7"}),s.jsx("polyline",{points:"8 17 12 21 16 17"})]}):s.jsxs(s.Fragment,{children:[s.jsx("line",{x1:"3",y1:"12",x2:"21",y2:"12"}),s.jsx("polyline",{points:"7 8 3 12 7 16"}),s.jsx("polyline",{points:"17 8 21 12 17 16"})]})})})}),s.jsx("div",{className:"media-viewport__toolbar-divider"})]}),s.jsxs("div",{className:"media-viewport__toolbar-group",children:[s.jsx(ke,{content:"缩小",placement:"top",contentClassName:"viewer-popover",children:s.jsx("button",{type:"button","aria-label":"缩小",onClick:A=>{A.stopPropagation(),A.preventDefault(),F()},children:s.jsx(dr,{size:16})})}),s.jsxs("span",{className:"media-viewport__zoom-level",children:[Math.round(Q*100),"%"]}),s.jsx(ke,{content:"放大",placement:"top",contentClassName:"viewer-popover",children:s.jsx("button",{type:"button","aria-label":"放大",onClick:A=>{A.stopPropagation(),A.preventDefault(),H()},children:s.jsx(ur,{size:16})})})]}),s.jsx("div",{className:"media-viewport__toolbar-divider"}),s.jsxs("div",{className:"media-viewport__toolbar-group",children:[s.jsx(ke,{content:"向左旋转 90°",placement:"top",contentClassName:"viewer-popover",children:s.jsx("button",{type:"button","aria-label":"向左旋转 90°",onClick:A=>{A.stopPropagation(),A.preventDefault(),Z()},children:s.jsx(Kt,{size:16})})}),s.jsx(ke,{content:"向右旋转 90°",placement:"top",contentClassName:"viewer-popover",children:s.jsx("button",{type:"button","aria-label":"向右旋转 90°",onClick:A=>{A.stopPropagation(),A.preventDefault(),oe()},children:s.jsx(mr,{size:16})})})]}),s.jsx("div",{className:"media-viewport__toolbar-divider"}),s.jsxs("div",{className:"media-viewport__toolbar-group",children:[s.jsx(ke,{content:"水平翻转",placement:"top",contentClassName:"viewer-popover",children:s.jsx("button",{type:"button","aria-label":"水平翻转",className:$?"active":"",onClick:A=>{A.stopPropagation(),A.preventDefault(),te()},children:s.jsx(pr,{size:16})})}),s.jsx(ke,{content:"垂直翻转",placement:"top",contentClassName:"viewer-popover",children:s.jsx("button",{type:"button","aria-label":"垂直翻转",className:fe?"active":"",onClick:A=>{A.stopPropagation(),A.preventDefault(),Pe()},children:s.jsx(hr,{size:16})})})]})]}),!d&&!he&&s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"media-viewport__toolbar-divider"}),s.jsx(ke,{content:"插入到画布",placement:"top",contentClassName:"viewer-popover",children:s.jsx("button",{type:"button",onClick:A=>{A.stopPropagation(),A.preventDefault(),p?p():Ce()},children:s.jsx(fr,{size:16})})})]}),!d&&h&&s.jsxs(s.Fragment,{children:[he&&s.jsx("div",{className:"media-viewport__toolbar-divider"}),s.jsx(ke,{content:"下载",placement:"top",contentClassName:"viewer-popover",children:s.jsx("button",{type:"button",onClick:A=>{A.stopPropagation(),A.preventDefault(),h()},children:s.jsx(gr,{size:16})})})]}),!d&&g&&(t==null?void 0:t.type)==="image"&&s.jsx(ke,{content:"编辑图片",placement:"top",contentClassName:"viewer-popover",children:s.jsx("button",{type:"button",onClick:A=>{A.stopPropagation(),A.preventDefault(),g()},children:s.jsx(wr,{size:16})})})]}),ze&&!he&&s.jsx(ke,{content:ze,placement:"bottom",sideOffset:10,contentClassName:"viewer-popover viewer-popover--prompt",children:s.jsx("div",{className:`media-viewport__prompt ${De?"media-viewport__prompt--visible":""} ${ue?"media-viewport__prompt--expanded":""}`,onMouseEnter:V,onMouseLeave:v,children:ze})})]})});On.displayName="MediaViewport";const Cc=({src:t,fallbackSrc:e,alt:n})=>{const[r,i]=a.useState(t),[o,c]=a.useState(!1);return a.useEffect(()=>{i(t),c(!1)},[t]),o?s.jsx("div",{className:"thumbnail-queue__image thumbnail-queue__image-fallback",children:s.jsx("span",{children:"加载失败"})}):s.jsx(Tt,{src:r,alt:n,className:"thumbnail-queue__image",showSkeleton:!1,onError:()=>{if(e&&r!==e){i(e);return}c(!0)}})};function jc(t,e="small"){const n=ut(t);if(n.startsWith("http://")||n.startsWith("https://")||n.startsWith("blob:")||Zo(n))return n;try{const r=new URL(n,window.location.origin);return r.searchParams.set("thumbnail",e),r.toString()}catch{const r=n.includes("?")?"&":"?";return`${n}${r}thumbnail=${e}`}}const Tc=({items:t,mode:e,currentIndex:n,compareIndices:r,onThumbnailClick:i,onDragStart:o})=>{const c=a.useRef(null),[l,m]=a.useState(null);a.useEffect(()=>{if(e==="single"&&c.current){const y=c.current.querySelector(".thumbnail-queue__item--active");y&&y.scrollIntoView({behavior:"smooth",block:"nearest",inline:"center"})}},[n,e]);const u=a.useCallback((y,f)=>{f.dataTransfer.setData("text/plain",String(y)),f.dataTransfer.effectAllowed="move",m(y),o==null||o(y)},[o]),d=a.useCallback(()=>{m(null)},[]),p=a.useCallback(y=>e==="single"?y===n:r.includes(y),[e,n,r]),h=a.useCallback(y=>{if(e!=="compare")return;const f=r.indexOf(y);return f>=0?f+1:void 0},[e,r]),g=a.useCallback((y,f)=>{const x=p(f),z=h(f),N=l===f,O=y.type==="video",T=y.type==="audio",I=ut(y.url),b=y.posterUrl?ut(y.posterUrl):"",S=jc(T&&b?b:I,"small");return s.jsxs("div",{className:`thumbnail-queue__item ${x?"thumbnail-queue__item--active":""} ${N?"thumbnail-queue__item--dragging":""}`,onClick:()=>i(f),draggable:e==="compare",onDragStart:C=>u(f,C),onDragEnd:d,role:"button",tabIndex:0,onKeyDown:C=>{(C.key==="Enter"||C.key===" ")&&(C.preventDefault(),i(f))},children:[s.jsx("div",{className:"thumbnail-queue__thumb",children:O?s.jsxs(s.Fragment,{children:[s.jsx(sc,{src:I,poster:b||void 0,className:"thumbnail-queue__video",alt:y.alt||y.title||"",thumbnailSize:"small",videoProps:{muted:!0,preload:"metadata"}}),s.jsx("div",{className:"thumbnail-queue__video-icon",children:s.jsx(yr,{size:16})})]}):T?s.jsxs(s.Fragment,{children:[s.jsx(lr,{src:b?S:void 0,fallbackSrc:b,alt:y.alt||y.title||"",imageClassName:"thumbnail-queue__image",fallbackClassName:"thumbnail-queue__image thumbnail-queue__audio-fallback",iconSize:18,loading:"lazy"}),s.jsx("div",{className:"thumbnail-queue__video-icon",children:s.jsx(qo,{size:16})})]}):s.jsx(Cc,{src:S,alt:y.alt||y.title||"",fallbackSrc:I})}),x&&s.jsx("div",{className:"thumbnail-queue__check",children:z?s.jsx("span",{className:"thumbnail-queue__slot-number",children:z}):s.jsx(Ko,{size:18})})]},y.id||`${y.url}-${f}`)},[p,h,l,e,i,u,d]);return t.length===0?null:s.jsx("div",{className:"thumbnail-queue",ref:c,children:s.jsx("div",{className:"thumbnail-queue__list",children:t.map((y,f)=>g(y,f))})})},Nc=({mode:t,currentIndex:e,totalCount:n,slotCount:r,compareLayout:i,syncMode:o,onModeChange:c,onSlotCountChange:l,onLayoutChange:m,onSyncToggle:u,onResetView:d,onClose:p,onFullscreen:h,isImage:g=!1,showEditButton:y=!1,onBackToPreview:f,onResetEdit:x,onSaveEdit:z})=>{const N=a.useCallback(C=>{m(C),C==="grid"&&r<4&&l(4)},[m,l,r]),O=()=>s.jsxs(s.Fragment,{children:[s.jsxs("div",{className:"viewer-toolbar__indicator",children:[s.jsx("span",{className:"viewer-toolbar__current",children:e+1}),s.jsx("span",{className:"viewer-toolbar__separator",children:"/"}),s.jsx("span",{className:"viewer-toolbar__total",children:n})]}),n>1&&s.jsx(ke,{content:"对比模式",placement:"bottom",contentClassName:"viewer-popover",children:s.jsx("button",{className:"viewer-toolbar__btn",onClick:()=>c("compare"),"aria-label":"对比模式",children:s.jsx(bs,{size:18})})}),y&&g&&s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"viewer-toolbar__divider"}),s.jsx(ke,{content:"编辑图片",placement:"bottom",contentClassName:"viewer-popover",children:s.jsx("button",{className:"viewer-toolbar__btn",onClick:()=>c("edit"),"aria-label":"编辑图片",children:s.jsx(wr,{size:18})})})]})]}),T=()=>s.jsxs(s.Fragment,{children:[s.jsx(ke,{content:"返回预览",placement:"bottom",contentClassName:"viewer-popover",children:s.jsxs("button",{className:"viewer-toolbar__btn",onClick:f,"aria-label":"返回预览",children:[s.jsx(cn,{size:18}),s.jsx("span",{className:"viewer-toolbar__btn-text",children:"返回"})]})}),s.jsx("div",{className:"viewer-toolbar__divider"}),s.jsx("div",{className:"viewer-toolbar__title",children:"编辑图片"})]}),I=()=>s.jsxs(s.Fragment,{children:[s.jsx(ke,{content:"单图模式",placement:"bottom",contentClassName:"viewer-popover",children:s.jsxs("button",{className:"viewer-toolbar__btn",onClick:()=>c("single"),"aria-label":"单图模式",children:[s.jsx(cn,{size:18}),s.jsx("span",{className:"viewer-toolbar__btn-text",children:"单图"})]})}),s.jsx("div",{className:"viewer-toolbar__divider"}),s.jsxs("div",{className:"viewer-toolbar__group",children:[s.jsx("span",{className:"viewer-toolbar__label",children:"分屏"}),[2,3,4].map(C=>s.jsx(it.Fragment,{children:s.jsx(ke,{content:`${C}分屏`,placement:"bottom",contentClassName:"viewer-popover",children:s.jsx("button",{className:`viewer-toolbar__btn viewer-toolbar__btn--small ${r===C?"viewer-toolbar__btn--active":""}`,onClick:()=>l(C),"aria-label":`${C}分屏`,children:C})})},C))]}),s.jsx("div",{className:"viewer-toolbar__divider"}),s.jsxs("div",{className:"viewer-toolbar__group",children:[s.jsx(ke,{content:"水平布局",placement:"bottom",contentClassName:"viewer-popover",children:s.jsx("button",{className:`viewer-toolbar__btn ${i==="horizontal"?"viewer-toolbar__btn--active":""}`,onClick:()=>N("horizontal"),"aria-label":"水平布局",children:s.jsx(bs,{size:18})})}),s.jsx(ke,{content:"垂直布局",placement:"bottom",contentClassName:"viewer-popover",children:s.jsx("button",{className:`viewer-toolbar__btn ${i==="vertical"?"viewer-toolbar__btn--active":""}`,onClick:()=>N("vertical"),"aria-label":"垂直布局",children:s.jsx(Yo,{size:18})})}),s.jsx(ke,{content:"网格布局",placement:"bottom",contentClassName:"viewer-popover",children:s.jsx("button",{className:`viewer-toolbar__btn ${i==="grid"?"viewer-toolbar__btn--active":""}`,onClick:()=>N("grid"),"aria-label":"网格布局",children:s.jsx(Xo,{size:18})})})]}),s.jsx("div",{className:"viewer-toolbar__divider"}),s.jsx(ke,{content:o?"取消联动(快捷键 S)":"联动缩放/拖拽(快捷键 S)",placement:"bottom",contentClassName:"viewer-popover",children:s.jsx("button",{className:`viewer-toolbar__btn ${o?"viewer-toolbar__btn--active":""}`,onClick:u,"aria-label":o?"取消联动":"联动缩放/拖拽",children:o?s.jsx(Jo,{size:18}):s.jsx(Qo,{size:18})})}),o&&s.jsx(ke,{content:"重置视图",placement:"bottom",contentClassName:"viewer-popover",children:s.jsx("button",{className:"viewer-toolbar__btn",onClick:d,children:s.jsx(Kt,{size:18})})})]}),b=()=>{switch(t){case"edit":return T();case"compare":return I();default:return O()}},S=()=>t==="edit"?s.jsxs(s.Fragment,{children:[s.jsx(ke,{content:"重置",placement:"bottom",contentClassName:"viewer-popover",children:s.jsx("button",{className:"viewer-toolbar__btn",onClick:x,children:s.jsx(Kt,{size:18})})}),s.jsx(ke,{content:"保存",placement:"bottom",contentClassName:"viewer-popover",children:s.jsx("button",{className:"viewer-toolbar__btn viewer-toolbar__btn--primary",onClick:z,"aria-label":"保存",children:s.jsx(gn,{size:18})})}),s.jsx(ke,{content:"关闭(Esc)",placement:"bottom",contentClassName:"viewer-popover",children:s.jsx("button",{className:"viewer-toolbar__btn viewer-toolbar__btn--close",onClick:p,"aria-label":"关闭",children:s.jsx(Mt,{size:20})})})]}):s.jsxs(s.Fragment,{children:[h&&s.jsx(ke,{content:"全屏",placement:"bottom",contentClassName:"viewer-popover",children:s.jsx("button",{className:"viewer-toolbar__btn",onClick:h,children:s.jsx(xr,{size:18})})}),s.jsx(ke,{content:"关闭(Esc)",placement:"bottom",contentClassName:"viewer-popover",children:s.jsx("button",{className:"viewer-toolbar__btn viewer-toolbar__btn--close",onClick:p,"aria-label":"关闭",children:s.jsx(Mt,{size:20})})})]});return t==="edit"?s.jsxs("div",{className:"viewer-toolbar viewer-toolbar--edit-simplified",children:[s.jsx(ke,{content:"返回预览",placement:"bottom",contentClassName:"viewer-popover",children:s.jsxs("button",{className:"viewer-toolbar__corner-btn viewer-toolbar__corner-btn--left",onClick:f,"aria-label":"返回预览",children:[s.jsx(cn,{size:20}),s.jsx("span",{children:"返回"})]})}),s.jsx(ke,{content:"关闭(Esc)",placement:"bottom",contentClassName:"viewer-popover",children:s.jsx("button",{className:"viewer-toolbar__corner-btn viewer-toolbar__corner-btn--right",onClick:p,"aria-label":"关闭",children:s.jsx(Mt,{size:20})})})]}):s.jsxs("div",{className:"viewer-toolbar",children:[s.jsx("div",{className:"viewer-toolbar__left",children:b()}),s.jsx("div",{className:"viewer-toolbar__right",children:S()})]})},_t={brightness:100,contrast:100,saturate:100,blur:0,grayscale:0,sepia:0,hueRotate:0,invert:0},Ec=[{label:"自由",value:null},{label:"1:1",value:1},{label:"4:3",value:4/3},{label:"3:4",value:3/4},{label:"16:9",value:16/9},{label:"9:16",value:9/16},{label:"3:2",value:3/2},{label:"2:3",value:2/3}],Os=[{label:"原图",type:"none",filter:"none"},{label:"黑白",type:"grayscale",filter:"grayscale(100%)"},{label:"怀旧",type:"sepia",filter:"sepia(80%)"},{label:"复古",type:"vintage",filter:"sepia(40%) contrast(110%) brightness(90%)"},{label:"冷色",type:"cold",filter:"saturate(80%) hue-rotate(180deg) brightness(105%)"},{label:"暖色",type:"warm",filter:"saturate(120%) sepia(20%) brightness(105%)"},{label:"高对比",type:"contrast",filter:"contrast(150%)"},{label:"高饱和",type:"saturate",filter:"saturate(180%)"},{label:"反转",type:"invert",filter:"invert(100%)"}],Pc=({aspectRatio:t,presets:e,onAspectRatioChange:n,rotation:r,flipH:i,flipV:o,onRotate:c,onFlipH:l,onFlipV:m,onConfirmCrop:u,hasCropArea:d=!1,onAutoTrimWhitespace:p,isDetectingWhitespace:h=!1})=>s.jsxs("div",{className:"crop-panel",children:[p&&s.jsxs("div",{className:"crop-panel__section",children:[s.jsx("div",{className:"crop-panel__section-title",children:"智能裁剪"}),s.jsxs("button",{type:"button",className:`crop-panel__auto-trim-btn ${h?"loading":""}`,onClick:p,disabled:h,children:[s.jsx(ei,{size:16}),s.jsx("span",{children:h?"检测中...":"智能去白边"})]}),s.jsx("div",{className:"crop-panel__auto-trim-hint",children:"自动检测并移除图片周围的白色边框"})]}),s.jsxs("div",{className:"crop-panel__section",children:[s.jsx("div",{className:"crop-panel__section-title",children:"裁剪比例"}),s.jsx("div",{className:"crop-panel__ratio-grid",children:e.map(g=>s.jsx("button",{type:"button",className:`crop-panel__ratio-btn ${t===g.value?"active":""}`,onClick:()=>n(g.value),children:g.label},g.label))})]}),s.jsxs("div",{className:"crop-panel__section",children:[s.jsx("div",{className:"crop-panel__section-title",children:"旋转和翻转"}),s.jsxs("div",{className:"crop-panel__transform-row",children:[s.jsx(je,{content:"向左旋转 90°",placement:"top",children:s.jsx("button",{type:"button",className:"crop-panel__transform-btn",onClick:()=>c(-90),children:s.jsx(Kt,{size:18})})}),s.jsx(je,{content:"向右旋转 90°",placement:"top",children:s.jsx("button",{type:"button",className:"crop-panel__transform-btn",onClick:()=>c(90),children:s.jsx(mr,{size:18})})}),s.jsx(je,{content:"水平翻转",placement:"top",children:s.jsx("button",{type:"button",className:`crop-panel__transform-btn ${i?"active":""}`,onClick:l,children:s.jsx(pr,{size:18})})}),s.jsx(je,{content:"垂直翻转",placement:"top",children:s.jsx("button",{type:"button",className:`crop-panel__transform-btn ${o?"active":""}`,onClick:m,children:s.jsx(hr,{size:18})})})]}),r!==0&&s.jsxs("div",{className:"crop-panel__rotation-info",children:["当前旋转: ",r,"°"]})]}),u&&s.jsxs("div",{className:"crop-panel__section",children:[s.jsxs("button",{type:"button",className:`crop-panel__confirm-btn ${d?"":"disabled"}`,onClick:u,disabled:!d,children:[s.jsx(gn,{size:16}),s.jsx("span",{children:"应用裁剪"})]}),s.jsx("div",{className:"crop-panel__confirm-hint",children:"按 Enter 键快速确认"})]}),s.jsxs("div",{className:"crop-panel__tips",children:[s.jsx("p",{children:"拖动裁剪框调整位置"}),s.jsx("p",{children:"拖动边角调整大小"})]})]}),Ac=({filterType:t,filterParams:e,presets:n,imageUrl:r,onPresetSelect:i,onParamChange:o})=>s.jsxs("div",{className:"filter-panel",children:[s.jsxs("div",{className:"filter-panel__section",children:[s.jsx("div",{className:"filter-panel__section-title",children:"滤镜预设"}),s.jsx("div",{className:"filter-panel__preset-grid",children:n.map(c=>s.jsxs("button",{type:"button",className:`filter-panel__preset-btn ${t===c.type?"active":""}`,onClick:()=>i(c.type),children:[s.jsx("div",{className:"filter-panel__preset-preview",style:{backgroundImage:`url(${r})`,filter:c.filter}}),s.jsx("span",{className:"filter-panel__preset-label",children:c.label})]},c.type))})]}),s.jsxs("div",{className:"filter-panel__section",children:[s.jsx("div",{className:"filter-panel__section-title",children:"参数调节"}),s.jsxs("div",{className:"filter-panel__sliders",children:[s.jsx(bt,{label:"亮度",value:e.brightness,min:0,max:200,defaultValue:100,onChange:c=>o("brightness",c)}),s.jsx(bt,{label:"对比度",value:e.contrast,min:0,max:200,defaultValue:100,onChange:c=>o("contrast",c)}),s.jsx(bt,{label:"饱和度",value:e.saturate,min:0,max:200,defaultValue:100,onChange:c=>o("saturate",c)}),s.jsx(bt,{label:"灰度",value:e.grayscale,min:0,max:100,defaultValue:0,onChange:c=>o("grayscale",c)}),s.jsx(bt,{label:"复古",value:e.sepia,min:0,max:100,defaultValue:0,onChange:c=>o("sepia",c)}),s.jsx(bt,{label:"色相",value:e.hueRotate,min:0,max:360,defaultValue:0,onChange:c=>o("hueRotate",c)}),s.jsx(bt,{label:"模糊",value:e.blur,min:0,max:10,defaultValue:0,step:.5,onChange:c=>o("blur",c)})]})]})]}),bt=({label:t,value:e,min:n,max:r,defaultValue:i,step:o=1,onChange:c})=>{const l=e===i;return s.jsxs("div",{className:"filter-slider",children:[s.jsxs("div",{className:"filter-slider__header",children:[s.jsx("span",{className:"filter-slider__label",children:t}),s.jsx("span",{className:`filter-slider__value ${l?"":"modified"}`,children:e})]}),s.jsx(ti,{value:e,min:n,max:r,step:o,onChange:m=>c(m)})]})},pt=10010;function Rc(t,e={}){const{threshold:n=250,tolerance:r=.02,minContentSize:i=50}=e,o=t.naturalWidth,c=t.naturalHeight,l=document.createElement("canvas");l.width=o,l.height=c;const m=l.getContext("2d");if(!m)return null;m.drawImage(t,0,0);const d=m.getImageData(0,0,o,c).data,p=b=>{const S=d[b],C=d[b+1],R=d[b+2];return d[b+3]<10?!0:S>=n&&C>=n&&R>=n},h=b=>{let S=0;for(let C=0;C<o;C++){const R=(b*o+C)*4;p(R)&&S++}return S/o>=1-r},g=b=>{let S=0;for(let C=0;C<c;C++){const R=(C*o+b)*4;p(R)&&S++}return S/c>=1-r};let y=0;for(;y<c&&h(y);)y++;let f=c-1;for(;f>y&&h(f);)f--;let x=0;for(;x<o&&g(x);)x++;let z=o-1;for(;z>x&&g(z);)z--;const N=z-x+1,O=f-y+1,T=y>0||x>0||z<o-1||f<c-1,I=N>=i&&O>=i;return!T||!I?null:{x,y,width:N,height:O}}const to=a.forwardRef(({imageUrl:t,showOverwrite:e=!1,onOverwrite:n,onInsert:r,onClose:i,onSave:o,className:c},l)=>{const[m,u]=a.useState("crop"),[d,p]=a.useState(null),[h,g]=a.useState(null),[y,f]=a.useState("none"),[x,z]=a.useState(_t),[N,O]=a.useState(0),[T,I]=a.useState(!1),[b,S]=a.useState(!1),[C,R]=a.useState({width:0,height:0}),[U,P]=a.useState(1),[J,ee]=a.useState(1),X=.1,Q=5,B=.1,[_,E]=a.useState({x:0,y:0}),[M,$]=a.useState(!1),[re,fe]=a.useState({x:0,y:0}),[K,de]=a.useState(!1),[ie,ue]=a.useState(null),[xe,pe]=a.useState(!1),[ae,q]=a.useState(null),[ce,ve]=a.useState(!1),[me,Re]=a.useState([]),[Me,We]=a.useState(-1),Ee=a.useRef(!1),Te=a.useRef(null),Ye=a.useRef(null),$e=a.useRef(null);a.useEffect(()=>{$e.current!==null&&$e.current!==t&&(p(null),q(null),g(null),f("none"),z(_t),O(0),I(!1),S(!1),ee(1),P(1),R({width:0,height:0}),E({x:0,y:0}),u("crop"),Re([{cropArea:null,confirmedCropArea:null,aspectRatio:null,filterType:"none",filterParams:_t,rotation:0,flipH:!1,flipV:!1}]),We(0)),$e.current=t},[t]),a.useEffect(()=>{if(!t)return;const j=new Image;return j.crossOrigin="anonymous",j.onload=()=>{Te.current=j,R({width:j.naturalWidth,height:j.naturalHeight})},j.onerror=()=>{Ke.error("图片加载失败")},j.src=t,()=>{Te.current=null}},[t]),a.useEffect(()=>{t&&me.length===0&&(Re([{cropArea:null,confirmedCropArea:null,aspectRatio:null,filterType:"none",filterParams:_t,rotation:0,flipH:!1,flipV:!1}]),We(0))},[t,me.length]),a.useEffect(()=>{if(!Ye.current||C.width===0)return;const j=()=>{const we=Ye.current;if(!we)return;const Oe=we.clientWidth-80,Ze=we.clientHeight-80;if(Oe<=0||Ze<=0)return;const A=Oe/C.width,ge=Ze/C.height,Le=Math.min(A,ge,1);Le>0&&isFinite(Le)&&P(Le)};requestAnimationFrame(j);const ne=new ResizeObserver(j);return ne.observe(Ye.current),()=>ne.disconnect()},[C]);const be=a.useRef(null);a.useEffect(()=>{if(!(Ee.current||me.length===0))return be.current&&clearTimeout(be.current),be.current=setTimeout(()=>{He()},300),()=>{be.current&&clearTimeout(be.current)}},[N,T,b,y,x,h,ae]);const Ie=a.useCallback(()=>{if(y!=="none"){const ne=Os.find(we=>we.type===y);if(ne)return ne.filter}const j=[];return x.brightness!==100&&j.push(`brightness(${x.brightness}%)`),x.contrast!==100&&j.push(`contrast(${x.contrast}%)`),x.saturate!==100&&j.push(`saturate(${x.saturate}%)`),x.blur>0&&j.push(`blur(${x.blur}px)`),x.grayscale>0&&j.push(`grayscale(${x.grayscale}%)`),x.sepia>0&&j.push(`sepia(${x.sepia}%)`),x.hueRotate!==0&&j.push(`hue-rotate(${x.hueRotate}deg)`),x.invert>0&&j.push(`invert(${x.invert}%)`),j.length>0?j.join(" "):"none"},[y,x]),he=a.useCallback(()=>{const j=[];return N!==0&&j.push(`rotate(${N}deg)`),T&&j.push("scaleX(-1)"),b&&j.push("scaleY(-1)"),j.length>0?j.join(" "):"none"},[N,T,b]),ze=a.useCallback(()=>({cropArea:d,confirmedCropArea:ae,aspectRatio:h,filterType:y,filterParams:x,rotation:N,flipH:T,flipV:b}),[d,ae,h,y,x,N,T,b]),De=a.useCallback(j=>{Ee.current=!0,p(j.cropArea),q(j.confirmedCropArea),g(j.aspectRatio),f(j.filterType),z(j.filterParams),O(j.rotation),I(j.flipH),S(j.flipV),requestAnimationFrame(()=>{Ee.current=!1})},[]),He=a.useCallback(()=>{if(Ee.current)return;const j=ze();Re(ne=>{const we=ne.slice(0,Me+1);return we.push(j),we.length>50&&we.shift(),we}),We(ne=>Math.min(ne+1,49))},[ze,Me]),Be=a.useCallback(()=>{if(Me<=0)return;const j=Me-1;We(j),De(me[j])},[Me,me,De]),Ge=a.useCallback(()=>{if(Me>=me.length-1)return;const j=Me+1;We(j),De(me[j])},[Me,me,De]),Qe=Me>0,Ne=Me<me.length-1,L=a.useCallback(()=>ae!==null||d!==null||N!==0||T||b||y!=="none"||Object.keys(x).some(j=>x[j]!==_t[j]),[ae,d,N,T,b,y,x]),w=a.useCallback(()=>{p(null),q(null),g(null),f("none"),z(_t),O(0),I(!1),S(!1),ee(1),E({x:0,y:0}),Re([]),We(-1)},[]),V=a.useCallback(async()=>{const j=Te.current;if(!j){Ke.error("图片未加载");return}const ne=Ke.loading("正在处理图片...",0);try{const we=document.createElement("canvas"),Oe=we.getContext("2d");if(!Oe)throw new Error("无法创建 Canvas 上下文");let Ze=j.naturalWidth,A=j.naturalHeight,ge=0,Le=0,tt=j.naturalWidth,Xe=j.naturalHeight;const Je=ae||d;Je&&(ge=Je.x,Le=Je.y,tt=Je.width,Xe=Je.height,Ze=Je.width,A=Je.height);const rt=(N%360+360)%360;(rt===90||rt===270)&&([Ze,A]=[A,Ze]),we.width=Ze,we.height=A,Oe.save(),Oe.translate(Ze/2,A/2),N!==0&&Oe.rotate(N*Math.PI/180),T&&Oe.scale(-1,1),b&&Oe.scale(1,-1);let mt=tt,ct=Xe;(rt===90||rt===270)&&([mt,ct]=[ct,mt]);const ys=Ie();ys!=="none"&&(Oe.filter=ys),Oe.drawImage(j,ge,Le,tt,Xe,-mt/2,-ct/2,mt,ct),Oe.restore();const xs=we.toDataURL("image/png");if(Ke.close(ne),o){o(xs);return}ue(xs),de(!0)}catch(we){Ke.close(ne),Ke.error(we instanceof Error?we.message:"图片处理失败")}},[ae,d,N,T,b,Ie,o]),v=a.useCallback(j=>{if(ie){switch(j){case"overwrite":n==null||n(ie);break;case"insert":r==null||r(ie);break;case"download":{const ne=document.createElement("a");ne.href=ie,ne.download=`edited-image-${Date.now()}.png`,ne.click(),Ke.success("图片已下载");break}}de(!1),ue(null),i==null||i()}},[ie,n,r,i]),D=a.useCallback(j=>{g(j),p(null),q(null)},[]),W=a.useCallback(j=>{f(j),j!=="none"&&z(_t)},[]),G=a.useCallback((j,ne)=>{z(we=>({...we,[j]:ne})),f("none")},[]),Y=a.useCallback(j=>{O(ne=>ne+j)},[]),le=a.useCallback(()=>{I(j=>!j)},[]),_e=a.useCallback(()=>{S(j=>!j)},[]),k=a.useCallback(()=>{!d||!Te.current||(q({...d}),u("filter"))},[d]),H=a.useCallback(()=>{const j=Te.current;if(!j){Ke.warning("图片未加载完成");return}ve(!0),requestAnimationFrame(()=>{try{const ne=Rc(j);ne?(g(null),p(ne),Ke.success("已检测到白边,裁剪框已自动调整")):Ke.info("未检测到明显的白边")}catch{Ke.error("检测白边失败")}finally{ve(!1)}})},[]);a.useEffect(()=>{const j=ne=>{ne.target instanceof HTMLInputElement||ne.target instanceof HTMLTextAreaElement||(ne.key==="Enter"&&m==="crop"&&d&&(ne.preventDefault(),k()),(ne.ctrlKey||ne.metaKey)&&ne.key==="z"&&!ne.shiftKey&&(ne.preventDefault(),Be()),(ne.ctrlKey||ne.metaKey)&&(ne.key==="y"||ne.key==="z"&&ne.shiftKey)&&(ne.preventDefault(),Ge()))};return window.addEventListener("keydown",j),()=>window.removeEventListener("keydown",j)},[m,d,k,Be,Ge]);const F=a.useCallback(()=>{ee(j=>Math.min(j+B,Q))},[]),Z=a.useCallback(()=>{ee(j=>Math.max(j-B,X))},[]),oe=a.useCallback(()=>{ee(1),E({x:0,y:0})},[]),te=a.useCallback(j=>{j.preventDefault();const ne=Math.abs(j.deltaY);let we;ne>50?we=j.deltaY>0?-.15:.15:we=-j.deltaY*.008,ee(Oe=>Math.max(X,Math.min(Q,Oe+we)))},[]);a.useEffect(()=>{const j=Ye.current;if(j)return j.addEventListener("wheel",te,{passive:!1}),()=>j.removeEventListener("wheel",te)},[te]);const Pe=a.useCallback(j=>{j==="crop"&&ae&&!d&&p({...ae}),u(j)},[ae,d]),Ce=a.useCallback(j=>{m!=="crop"&&($(!0),fe({x:j.clientX-_.x,y:j.clientY-_.y}))},[m,_]),Ae=a.useCallback(j=>{M&&E({x:j.clientX-re.x,y:j.clientY-re.y})},[M,re]),qe=a.useCallback(()=>{$(!1)},[]);a.useEffect(()=>{if(!M)return;const j=we=>{E({x:we.clientX-re.x,y:we.clientY-re.y})},ne=()=>{$(!1)};return document.addEventListener("mousemove",j),document.addEventListener("mouseup",ne),()=>{document.removeEventListener("mousemove",j),document.removeEventListener("mouseup",ne)}},[M,re]),a.useEffect(()=>{ee(1),E({x:0,y:0})},[m]),a.useImperativeHandle(l,()=>({reset:w,save:V,hasChanges:L,getState:ze,setState:De}));const et=Ie(),Ve=he();return s.jsxs("div",{className:`image-editor-core ${c||""}`,children:[s.jsxs("div",{className:"image-editor-core__header",children:[s.jsx("div",{className:"image-editor-core__title",children:"编辑图片"}),s.jsxs("div",{className:"image-editor-core__actions",children:[s.jsx(je,{content:"撤销 (Ctrl+Z)",theme:"light",placement:"bottom",zIndex:pt,children:s.jsx("button",{type:"button",className:`image-editor-core__btn ${Qe?"":"disabled"}`,onClick:Be,disabled:!Qe,children:s.jsx(ni,{size:18})})}),s.jsx(je,{content:"重做 (Ctrl+Y)",theme:"light",placement:"bottom",zIndex:pt,children:s.jsx("button",{type:"button",className:`image-editor-core__btn ${Ne?"":"disabled"}`,onClick:Ge,disabled:!Ne,children:s.jsx(si,{size:18})})}),s.jsx("div",{className:"image-editor-core__divider"}),s.jsx(je,{content:"对比原图(按住查看)",theme:"light",placement:"bottom",zIndex:pt,children:s.jsx("button",{type:"button",className:`image-editor-core__btn ${xe?"active":""}`,onMouseDown:()=>pe(!0),onMouseUp:()=>pe(!1),onMouseLeave:()=>pe(!1),children:s.jsx(ri,{size:18})})}),s.jsx(je,{content:"重置",theme:"light",placement:"bottom",zIndex:pt,children:s.jsx("button",{type:"button",className:"image-editor-core__btn",onClick:w,children:s.jsx(Kt,{size:18})})}),i&&s.jsx(je,{content:"取消",theme:"light",placement:"bottom",zIndex:pt,children:s.jsx("button",{type:"button",className:"image-editor-core__btn",onClick:i,children:s.jsx(Mt,{size:18})})}),(o||n||r)&&s.jsx(je,{content:"保存",theme:"light",placement:"bottom",zIndex:pt,children:s.jsx("button",{type:"button",className:"image-editor-core__btn image-editor-core__btn--primary",onClick:V,children:s.jsx(gn,{size:18})})})]})]}),s.jsxs("div",{className:"image-editor-core__main",children:[s.jsxs("div",{className:"image-editor-core__sidebar",children:[s.jsxs("div",{className:"image-editor-core__mode-tabs",children:[s.jsxs("button",{type:"button",className:`image-editor-core__mode-tab ${m==="crop"?"active":""}`,onClick:()=>Pe("crop"),children:[s.jsx(oi,{size:16}),s.jsx("span",{children:"裁剪"})]}),s.jsxs("button",{type:"button",className:`image-editor-core__mode-tab ${m==="filter"?"active":""}`,onClick:()=>Pe("filter"),children:[s.jsx(ii,{size:16}),s.jsx("span",{children:"滤镜"})]})]}),s.jsx("div",{className:"image-editor-core__panel",children:m==="crop"?s.jsx(Pc,{aspectRatio:h,presets:Ec,onAspectRatioChange:D,rotation:N,flipH:T,flipV:b,onRotate:Y,onFlipH:le,onFlipV:_e,onConfirmCrop:k,hasCropArea:!!d,onAutoTrimWhitespace:H,isDetectingWhitespace:ce}):s.jsx(Ac,{filterType:y,filterParams:x,presets:Os,imageUrl:t,onPresetSelect:W,onParamChange:G})})]}),s.jsxs("div",{className:"image-editor-core__preview",ref:Ye,onMouseDown:Ce,onMouseMove:Ae,onMouseUp:qe,onMouseLeave:qe,style:{cursor:M?"grabbing":"grab"},children:[s.jsx("div",{className:"image-editor-core__canvas-wrapper",style:{transform:`translate(${_.x}px, ${_.y}px)`},children:xe?ae?(()=>{const j=ae.y/C.height*100,ne=(C.width-ae.x-ae.width)/C.width*100,we=(C.height-ae.y-ae.height)/C.height*100,Oe=ae.x/C.width*100;return s.jsx("div",{className:"image-editor-core__filter-preview",style:{transform:`${Ve} scale(${U*J})`.trim(),clipPath:`inset(${j}% ${ne}% ${we}% ${Oe}%)`},children:s.jsx("img",{src:t,alt:"Original",draggable:!1})})})():s.jsx("div",{className:"image-editor-core__filter-preview",style:{transform:`${Ve} scale(${U*J})`.trim()},children:s.jsx("img",{src:t,alt:"Original",draggable:!1})}):m==="crop"?s.jsx(zc,{imageUrl:t,imageSize:C,cropArea:d,aspectRatio:h,rotation:N,displayScale:U,flipH:T,flipV:b,zoom:J,filterCSS:et,onCropChange:p},t):ae?(()=>{const j=ae.y/C.height*100,ne=(C.width-ae.x-ae.width)/C.width*100,we=(C.height-ae.y-ae.height)/C.height*100,Oe=ae.x/C.width*100;return s.jsx("div",{className:"image-editor-core__filter-preview",style:{filter:et,transform:`${Ve} scale(${U*J})`.trim(),clipPath:`inset(${j}% ${ne}% ${we}% ${Oe}%)`},children:s.jsx("img",{src:t,alt:"Preview",draggable:!1})})})():s.jsx("div",{className:"image-editor-core__filter-preview",style:{filter:et,transform:`${Ve} scale(${U*J})`.trim()},children:s.jsx("img",{src:t,alt:"Preview",draggable:!1})})}),s.jsxs("div",{className:"image-editor-core__zoom-controls",children:[s.jsx(je,{content:"缩小",theme:"light",placement:"top",zIndex:pt,children:s.jsx("button",{type:"button",className:"image-editor-core__zoom-btn",onClick:Z,disabled:J<=X,children:s.jsx(dr,{size:16})})}),s.jsxs("span",{className:"image-editor-core__zoom-value",children:[Math.round(J*100),"%"]}),s.jsx(je,{content:"放大",theme:"light",placement:"top",zIndex:pt,children:s.jsx("button",{type:"button",className:"image-editor-core__zoom-btn",onClick:F,disabled:J>=Q,children:s.jsx(ur,{size:16})})}),s.jsx(je,{content:"重置视图",theme:"light",placement:"top",zIndex:pt,children:s.jsx("button",{type:"button",className:"image-editor-core__zoom-btn",onClick:oe,children:s.jsx(xr,{size:16})})})]})]})]}),K&&ie&&s.jsxs("div",{className:"image-editor-core__save-dialog",children:[s.jsx("div",{className:"image-editor-core__save-dialog-backdrop",onClick:()=>de(!1)}),s.jsxs("div",{className:"image-editor-core__save-dialog-content",children:[s.jsx("h3",{className:"image-editor-core__save-dialog-title",children:"保存图片"}),s.jsxs("div",{className:"image-editor-core__save-options",children:[e&&n&&s.jsxs("button",{type:"button",className:"image-editor-core__save-option",onClick:()=>v("overwrite"),children:[s.jsx(ai,{size:20}),s.jsxs("div",{className:"image-editor-core__save-option-content",children:[s.jsx("span",{className:"image-editor-core__save-option-label",children:"覆盖原图"}),s.jsx("span",{className:"image-editor-core__save-option-desc",children:"替换画布中的原图片"})]})]}),r&&s.jsxs("button",{type:"button",className:"image-editor-core__save-option",onClick:()=>v("insert"),children:[s.jsx(ci,{size:20}),s.jsxs("div",{className:"image-editor-core__save-option-content",children:[s.jsx("span",{className:"image-editor-core__save-option-label",children:"插入新图片"}),s.jsx("span",{className:"image-editor-core__save-option-desc",children:"在画布中插入编辑后的图片"})]})]}),s.jsxs("button",{type:"button",className:"image-editor-core__save-option",onClick:()=>v("download"),children:[s.jsx(gr,{size:20}),s.jsxs("div",{className:"image-editor-core__save-option-content",children:[s.jsx("span",{className:"image-editor-core__save-option-label",children:"下载到本地"}),s.jsx("span",{className:"image-editor-core__save-option-desc",children:"保存编辑后的图片到本地"})]})]})]}),s.jsx("button",{type:"button",className:"image-editor-core__save-cancel",onClick:()=>de(!1),children:"取消"})]})]})]})});to.displayName="ImageEditorCore";const zc=({imageUrl:t,imageSize:e,cropArea:n,aspectRatio:r,rotation:i,flipH:o,flipV:c,zoom:l,displayScale:m,filterCSS:u,onCropChange:d})=>{const p=a.useRef(null),[h,g]=a.useState(!1),[y,f]=a.useState(null),[x,z]=a.useState(null),[N,O]=a.useState({x:0,y:0}),[T,I]=a.useState(null);a.useEffect(()=>{if(!n&&e.width>0){let P;if(r)if(e.width/e.height>r){const ee=e.height,X=ee*r;P={x:(e.width-X)/2,y:0,width:X,height:ee}}else{const ee=e.width,X=ee/r;P={x:0,y:(e.height-X)/2,width:ee,height:X}}else P={x:0,y:0,width:e.width,height:e.height};d(P)}},[r,e,n,d]);const b=a.useCallback((P,J,ee)=>{P.preventDefault(),P.stopPropagation(),g(!0),f(J),z(ee||null),O({x:P.clientX,y:P.clientY}),I(n)},[n]);a.useEffect(()=>{if(!h||!T)return;const P=ee=>{let X=(ee.clientX-N.x)/(m*l),Q=(ee.clientY-N.y)/(m*l);const B=(i%360+360)%360;let _,E;switch(B){case 90:_=Q,E=-X;break;case 180:_=-X,E=-Q;break;case 270:_=-Q,E=X;break;default:_=X,E=Q}o&&(_=-_),c&&(E=-E);const M={...T};if(y==="move")M.x=Math.max(0,Math.min(T.x+_,e.width-T.width)),M.y=Math.max(0,Math.min(T.y+E,e.height-T.height));else if(y==="resize"&&x){switch(x){case"nw":M.x=Math.min(T.x+_,T.x+T.width-20),M.y=Math.min(T.y+E,T.y+T.height-20),M.width=Math.max(20,T.width-_),M.height=Math.max(20,T.height-E);break;case"ne":M.y=Math.min(T.y+E,T.y+T.height-20),M.width=Math.max(20,T.width+_),M.height=Math.max(20,T.height-E);break;case"sw":M.x=Math.min(T.x+_,T.x+T.width-20),M.width=Math.max(20,T.width-_),M.height=Math.max(20,T.height+E);break;case"se":M.width=Math.max(20,T.width+_),M.height=Math.max(20,T.height+E);break;case"n":M.y=Math.min(T.y+E,T.y+T.height-20),M.height=Math.max(20,T.height-E);break;case"s":M.height=Math.max(20,T.height+E);break;case"w":M.x=Math.min(T.x+_,T.x+T.width-20),M.width=Math.max(20,T.width-_);break;case"e":M.width=Math.max(20,T.width+_);break}if(r&&(["e","w","ne","nw","se","sw"].includes(x)?M.height=M.width/r:["n","s"].includes(x)&&(M.width=M.height*r)),M.x<0&&(M.width+=M.x,M.x=0),M.y<0&&(M.height+=M.y,M.y=0),M.width=Math.min(M.width,e.width-M.x),M.height=Math.min(M.height,e.height-M.y),M.width=Math.max(20,M.width),M.height=Math.max(20,M.height),r){const re=M.height*r,fe=M.width/r;M.width>re?M.width=re:M.height>fe&&(M.height=fe)}}d(M)},J=()=>{g(!1),f(null),z(null)};return document.addEventListener("mousemove",P),document.addEventListener("mouseup",J),()=>{document.removeEventListener("mousemove",P),document.removeEventListener("mouseup",J)}},[h,y,x,N,T,m,l,i,o,c,e,r,d]);const S=e.width*m*l,C=e.height*m*l,R={transform:`rotate(${i}deg) ${o?"scaleX(-1)":""} ${c?"scaleY(-1)":""}`.trim()},U=P=>{const J={nw:"nw-resize",ne:"ne-resize",sw:"sw-resize",se:"se-resize",n:"n-resize",s:"s-resize",w:"w-resize",e:"e-resize"},ee={nw:"ne",ne:"se",se:"sw",sw:"nw",n:"e",e:"s",s:"w",w:"n"};let X=P;const Q=(i%360+360)%360,B=Math.round(Q/90)%4;for(let _=0;_<B;_++)X=ee[X]||X;return o&&(X.includes("w")?X=X.replace("w","e"):X.includes("e")&&(X=X.replace("e","w"))),c&&(X.includes("n")?X=X.replace("n","s"):X.includes("s")&&(X=X.replace("s","n"))),J[X]||"pointer"};return s.jsx("div",{ref:p,className:"crop-canvas",children:s.jsxs("div",{className:"crop-canvas__image-container",style:{width:S,height:C,...R},children:[s.jsx("img",{src:t,alt:"Crop",draggable:!1,style:{filter:u||"none"}}),n&&s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"crop-canvas__overlay"}),s.jsxs("div",{className:"crop-canvas__crop-area",style:{left:n.x*m*l,top:n.y*m*l,width:n.width*m*l,height:n.height*m*l},onMouseDown:P=>b(P,"move"),children:[s.jsx("div",{className:"crop-canvas__crop-image",style:{backgroundImage:`url(${t})`,backgroundPosition:`-${n.x*m*l}px -${n.y*m*l}px`,backgroundSize:`${S}px ${C}px`,filter:u||"none"}}),s.jsxs("div",{className:"crop-canvas__grid",children:[s.jsx("div",{className:"crop-canvas__grid-line crop-canvas__grid-line--h1"}),s.jsx("div",{className:"crop-canvas__grid-line crop-canvas__grid-line--h2"}),s.jsx("div",{className:"crop-canvas__grid-line crop-canvas__grid-line--v1"}),s.jsx("div",{className:"crop-canvas__grid-line crop-canvas__grid-line--v2"})]}),s.jsx("div",{className:"crop-canvas__handle crop-canvas__handle--nw",style:{cursor:U("nw")},onMouseDown:P=>b(P,"resize","nw")}),s.jsx("div",{className:"crop-canvas__handle crop-canvas__handle--ne",style:{cursor:U("ne")},onMouseDown:P=>b(P,"resize","ne")}),s.jsx("div",{className:"crop-canvas__handle crop-canvas__handle--sw",style:{cursor:U("sw")},onMouseDown:P=>b(P,"resize","sw")}),s.jsx("div",{className:"crop-canvas__handle crop-canvas__handle--se",style:{cursor:U("se")},onMouseDown:P=>b(P,"resize","se")}),s.jsx("div",{className:"crop-canvas__handle crop-canvas__handle--n",style:{cursor:U("n")},onMouseDown:P=>b(P,"resize","n")}),s.jsx("div",{className:"crop-canvas__handle crop-canvas__handle--s",style:{cursor:U("s")},onMouseDown:P=>b(P,"resize","s")}),s.jsx("div",{className:"crop-canvas__handle crop-canvas__handle--w",style:{cursor:U("w")},onMouseDown:P=>b(P,"resize","w")}),s.jsx("div",{className:"crop-canvas__handle crop-canvas__handle--e",style:{cursor:U("e")},onMouseDown:P=>b(P,"resize","e")})]})]})]})})},no=a.forwardRef(({imageUrl:t,showOverwrite:e=!1,onOverwrite:n,onInsert:r},i)=>s.jsx(to,{ref:i,imageUrl:t,showOverwrite:e,onOverwrite:n,onInsert:r,className:"embedded-editor"}));no.displayName="ImageEditorContent";const mn=({visible:t,items:e,initialMode:n="single",initialIndex:r=0,onClose:i,onModeChange:o,showThumbnails:c=!0,maxCompareSlots:l=4,defaultCompareLayout:m="horizontal",className:u="",showTitle:d=!0,videoAutoPlay:p=!1,videoLoop:h=!0,onInsertToCanvas:g,onEdit:y,useBuiltInEditor:f=!1,onEditOverwrite:x,onEditInsert:z,showEditOverwrite:N=!1})=>{const O=a.useRef(null),T=a.useRef(null),[I,b]=a.useState(2),[S,C]=a.useState(!1),[R,U]=a.useState(null),P=a.useRef(null),J=a.useRef(new Map),ee=a.useRef([]),X=a.useRef(null),Q=a.useRef(!1),[B,_]=ic({items:e,initialMode:n,initialIndex:r,maxCompareSlots:l,defaultCompareLayout:m,visible:t,onModeChange:o}),{mode:E,currentIndex:M,compareIndices:$,compareLayout:re,syncMode:fe,zoomLevel:K,panOffset:de,focusedSlot:ie}=B,ue=a.useCallback(v=>{P.current=v,U(v)},[]);a.useEffect(()=>{t||(J.current.clear(),ue(null))},[t,ue]);const xe=a.useCallback(()=>{if(e.length<=I)return;const D=Math.max(...$)+1;if(D>=e.length){const W=[];for(let G=0;G<I&&G<e.length;G++)W.push(G);W.forEach((G,Y)=>_.addToCompare(G,Y))}else{const W=[];for(let G=0;G<I;G++){const Y=(D+G)%e.length;W.push(Y)}W.forEach((G,Y)=>_.addToCompare(G,Y))}},[e.length,I,$,_]),pe=a.useCallback(()=>{if(e.length<=I)return;const D=Math.min(...$)-I;if(D<0){const W=Math.max(0,e.length-I),G=[];for(let Y=0;Y<I&&W+Y<e.length;Y++)G.push(W+Y);G.forEach((Y,le)=>_.addToCompare(Y,le))}else{const W=[];for(let G=0;G<I;G++)W.push(D+G);W.forEach((G,Y)=>_.addToCompare(G,Y))}},[e.length,I,$,_]),ae=a.useCallback(v=>{const D=e[v];if(!D||D.type!=="image")return!1;const W=P.current;if(W&&T.current){const G=T.current.getState();J.current.set(W.url,G)}return _.goTo(v),ue(D),setTimeout(()=>{const G=J.current.get(D.url);G&&T.current&&T.current.setState(G)},50),!0},[e,_,ue]),q=a.useCallback(()=>{_.resetView(),ee.current.forEach(v=>{v!=null&&v.isVideo()&&v.resetVideo()})},[_]);a.useEffect(()=>{if(!t)return;const v=D=>{const W=D.target instanceof HTMLElement?D.target:null;if(W instanceof HTMLInputElement||W instanceof HTMLTextAreaElement||W instanceof HTMLSelectElement||W instanceof HTMLButtonElement||W!=null&&W.isContentEditable)return;const G=E==="single"?X.current:ee.current[ie]||null;switch(D.key){case"Escape":D.preventDefault(),i();break;case"ArrowLeft":case"ArrowUp":if(D.preventDefault(),E==="edit"){const Y=(M-1+e.length)%e.length;ae(Y)}else E==="single"?_.goToPrev():pe();break;case"ArrowRight":case"ArrowDown":if(D.preventDefault(),E==="edit"){const Y=(M+1)%e.length;ae(Y)}else E==="single"?_.goToNext():xe();break;case"c":case"C":e.length>1&&(D.preventDefault(),_.setMode(E==="single"?"compare":"single"));break;case"1":case"2":case"3":case"4":if(E==="compare"){const Y=parseInt(D.key,10)-1;Y<I&&(D.preventDefault(),_.setFocusedSlot(Y))}break;case"+":case"=":D.preventDefault(),_.zoom(.25);break;case"-":case"_":D.preventDefault(),_.zoom(-.25);break;case"0":D.preventDefault(),E==="compare"?q():_.resetView();break;case" ":case"Spacebar":G!=null&&G.isVideo()&&(D.preventDefault(),G.toggleVideoPlayback());break;case"s":case"S":E==="compare"&&(D.preventDefault(),_.toggleSyncMode());break}};return window.addEventListener("keydown",v),()=>window.removeEventListener("keydown",v)},[t,E,e.length,e,M,ie,_,i,I,xe,pe,ae,q]);const ce=a.useCallback(()=>{if(O.current)if(S){const v=di();v==null||v.catch(()=>{})}else{const v=li(O.current);v==null||v.catch(()=>{})}},[S]);a.useEffect(()=>{const v=()=>{C(!!document.fullscreenElement)};return document.addEventListener("fullscreenchange",v),()=>document.removeEventListener("fullscreenchange",v)},[]);const ve=a.useCallback(v=>{v.target===v.currentTarget&&i()},[i]),me=a.useCallback(v=>{E==="edit"?ae(v):E==="single"?_.goTo(v):_.addToCompare(v,ie)},[E,_,ie,ae]),Re=a.useCallback(v=>{b(v),_.setSlotCount(v)},[_]),Me=a.useCallback((v,D)=>v==="grid"?D<=2?"layout-horizontal":"layout-grid":`layout-${v}`,[]),We=a.useCallback(()=>{const v=e[M];v&&g&&g(v)},[e,M,g]),Ee=a.useCallback(async()=>{const v=e[M];if(!v)return;const D=v.type==="image"?ut(v.url):v.url;if(D.startsWith("blob:")){const{unifiedCacheService:Y}=await dt(async()=>{const{unifiedCacheService:H}=await import("./startup-app-DxX-P1pm.js").then(F=>F.nI);return{unifiedCacheService:H}},__vite__mapDeps([0]),import.meta.url),{downloadFromBlob:le}=await dt(async()=>{const{downloadFromBlob:H}=await import("./startup-app-DxX-P1pm.js").then(F=>F.nG);return{downloadFromBlob:H}},__vite__mapDeps([0]),import.meta.url),_e=D.indexOf("#"),k=_e>0?D.substring(_e+1):null;if(k&&k.startsWith("merged-video-")){const H=await Y.getCachedBlob(k);if(H){const F=H.type||"video/webm",Z=F.startsWith("video/mp4")?"mp4":F.startsWith("video/webm")?"webm":"bin";le(H,`merged-video-${Date.now()}.${Z}`);return}}try{const F=await(await fetch(D)).blob(),Z=F.type.startsWith("video/mp4")?"mp4":F.type.startsWith("video/webm")?"webm":F.type.startsWith("audio/mpeg")?"mp3":F.type.startsWith("audio/wav")?"wav":F.type.startsWith("audio/")?"m4a":F.type.startsWith("image/")?"png":"bin";le(F,`${v.type}_${Date.now()}.${Z}`)}catch(H){console.error("[UnifiedMediaViewer] Failed to fetch blob URL:",H)}return}const{smartDownload:W,buildDownloadFilename:G}=await dt(async()=>{const{smartDownload:Y,buildDownloadFilename:le}=await import("./startup-app-DxX-P1pm.js").then(_e=>_e.nU);return{smartDownload:Y,buildDownloadFilename:le}},__vite__mapDeps([0]),import.meta.url);await W([{url:D,type:v.type,filename:v.type==="audio"?G(v.title,"audio","mp3"):void 0,audioMetadata:v.type==="audio"?{title:v.title,prompt:v.prompt,tags:v.tags,coverUrl:v.posterUrl,artist:v.artist,album:v.album}:void 0}])},[e,M]),Te=a.useCallback(()=>{const v=e[M];v&&v.type==="image"&&(f?(ue(v),_.setMode("edit")):y&&y(v))},[e,M,y,f,_,ue]),Ye=a.useCallback(v=>{if(v==="edit"){const D=e[M];D&&D.type==="image"&&ue(D)}_.setMode(v)},[e,M,_,ue]),$e=a.useCallback(()=>{J.current.clear(),ue(null),_.setMode("single")},[_,ue]),be=a.useCallback(()=>{var v;(v=T.current)==null||v.reset()},[]),Ie=a.useCallback(()=>{var v;(v=T.current)==null||v.save()},[]),he=a.useCallback(v=>{const D=P.current;x&&D&&x(v,D),$e()},[x,$e]),ze=a.useCallback(v=>{z&&z(v),$e()},[z,$e]),De=a.useCallback((v,D)=>{ee.current[v]=D},[]),He=a.useCallback((v,D)=>{Q.current||(Q.current=!0,ee.current.forEach((W,G)=>{G!==v&&(W!=null&&W.isVideo())&&(D?W.playVideo():W.pauseVideo())}),setTimeout(()=>{Q.current=!1},50))},[]),Be=a.useCallback((v,D)=>{Q.current||(Q.current=!0,ee.current.forEach((W,G)=>{G!==v&&(W!=null&&W.isVideo())&&W.setVideoTime(D)}),setTimeout(()=>{Q.current=!1},50))},[]),Ge=()=>{const v=e[M]||null;return s.jsxs("div",{className:"unified-viewer__single",children:[e.length>1&&s.jsx("button",{className:"unified-viewer__nav unified-viewer__nav--prev",onClick:_.goToPrev,"aria-label":"上一个",children:s.jsx(cn,{size:32})}),s.jsx(On,{ref:X,item:v,zoomLevel:K,panOffset:de,videoAutoPlay:p,videoLoop:h,onZoomChange:_.setZoomLevel,onPanChange:()=>{},onInsertToCanvas:g?We:void 0,onDownload:Ee,onEdit:y?Te:void 0}),e.length>1&&s.jsx("button",{className:"unified-viewer__nav unified-viewer__nav--next",onClick:_.goToNext,"aria-label":"下一个",children:s.jsx(ui,{size:32})})]})},Qe=()=>{const v=Me(re,I);return s.jsx("div",{className:`unified-viewer__compare ${v}`,children:Array.from({length:I}).map((D,W)=>{const G=$[W],Y=typeof G=="number"?e[G]:null;return s.jsx(On,{ref:le=>De(W,le),item:Y,slotIndex:W,isFocused:ie===W,zoomLevel:fe?K:void 0,panOffset:fe?de:void 0,onClick:()=>_.setFocusedSlot(W),onClose:I>2?()=>_.removeFromCompare(W):void 0,videoAutoPlay:p,videoLoop:h,onZoomChange:fe?_.setZoomLevel:void 0,onPanChange:fe?_.setPan:void 0,isCompareMode:!0,isSyncMode:fe,onVideoPlayStateChange:fe?le=>He(W,le):void 0,onVideoTimeUpdate:fe?le=>Be(W,le):void 0},W)})})},Ne=()=>{const v=R||e[M];return!v||v.type!=="image"?null:s.jsx("div",{className:"unified-viewer__edit",children:s.jsx(no,{ref:T,imageUrl:v.url,showOverwrite:N,onOverwrite:x?he:void 0,onInsert:z?ze:void 0})})},L=e[M]||null;if(!t||e.length===0)return null;const w=()=>{switch(E){case"edit":return Ne();case"compare":return Qe();default:return Ge()}},V=s.jsx("div",{ref:O,className:`unified-viewer ${u} ${S?"unified-viewer--fullscreen":""} ${E==="edit"?"unified-viewer--edit-mode":""}`,onClick:ve,children:s.jsxs("div",{className:"unified-viewer__container",children:[s.jsx(Nc,{mode:E,currentIndex:M,totalCount:e.length,slotCount:I,compareLayout:re,syncMode:fe,onModeChange:Ye,onSlotCountChange:Re,onLayoutChange:_.setCompareLayout,onSyncToggle:_.toggleSyncMode,onResetView:E==="compare"?q:_.resetView,onClose:i,onFullscreen:ce,isImage:(L==null?void 0:L.type)==="image",showEditButton:f||!!y,onBackToPreview:$e,onResetEdit:be,onSaveEdit:Ie}),s.jsx("div",{className:"unified-viewer__content",children:w()}),c&&e.length>1&&s.jsx(Tc,{items:e,mode:E==="edit"?"single":E,currentIndex:M,compareIndices:$,onThumbnailClick:me})]})});return Rt.createPortal(V,document.body)},im=Object.freeze(Object.defineProperty({__proto__:null,UnifiedMediaViewer:mn,default:mn},Symbol.toStringTag,{value:"Module"})),Dc=qn.DIALOG_AI_IMAGE;class Et{constructor(){this.windows=new Map,this.counter=0}static getInstance(){return Et.instance||(Et.instance=new Et),Et.instance}register(e,n){const r=this.windows.get(e);r?(r.element=n,r.activationOrder=++this.counter):this.windows.set(e,{windowId:e,activationOrder:++this.counter,element:n}),this.applyAllZIndexes()}unregister(e){this.windows.delete(e)&&this.applyAllZIndexes()}bringToFront(e){const n=this.windows.get(e);n&&(this.isTopWindow(e)||(n.activationOrder=++this.counter,this.applyAllZIndexes()))}updateElement(e,n){const r=this.windows.get(e);r&&(r.element=n,this.applyZIndex(r,this.getPositionIndex(e)))}getTopWindowId(){let e=null,n=-1;return this.windows.forEach(r=>{r.activationOrder>n&&(n=r.activationOrder,e=r.windowId)}),e}isTopWindow(e){return this.getTopWindowId()===e}getPositionIndex(e){return this.getSortedEntries().findIndex(r=>r.windowId===e)}getSortedEntries(){return Array.from(this.windows.values()).sort((e,n)=>e.activationOrder-n.activationOrder)}applyAllZIndexes(){this.getSortedEntries().forEach((n,r)=>{this.applyZIndex(n,r)})}applyZIndex(e,n){!e.element||n<0||e.element.style.setProperty("--aitu-winbox-z-index",String(Dc+n))}}const vt=Et.getInstance();let nt=null,nn=null;const Lc=async()=>nt||(typeof window<"u"&&window.WinBox?(nt=window.WinBox,nt):nn||(nn=(async()=>{try{if(await dt(()=>import("./winbox.bundle.min-CoRPjCs5.js"),[],import.meta.url),nt=window.WinBox,nt)return nt;throw new Error("WinBox not found after import")}catch(t){return console.warn("Dynamic import failed, falling back to CDN:",t),new Promise((e,n)=>{const r=document.createElement("script");r.src="https://cdn.jsdelivr.net/npm/winbox@0.2.82/dist/winbox.bundle.min.js",r.async=!0,r.onload=()=>{nt=window.WinBox,nt?e(nt):n(new Error("WinBox not found after CDN loading"))},r.onerror=n,document.head.appendChild(r)})}})(),nn)),$c=({visible:t,title:e,icon:n,onClose:r,children:i,width:o="80%",height:c="80%",minWidth:l=400,minHeight:m=300,x:u="center",y:d="center",maximizable:p=!0,minimizable:h=!0,resizable:g=!0,movable:y=!0,modal:f=!1,background:x="linear-gradient(135deg, #5A4FCF 0%, #7B68EE 50%, #E91E63 100%)",border:z=0,className:N,id:O,headerContent:T,container:I,onMaximize:b,onMinimize:S,onRestore:C,onFocus:R,onBlur:U,onMove:P,onResize:J,autoMaximize:ee=!1,minVisiblePixels:X=50,onInsertToCanvas:Q,keepAlive:B=!1,minimizeTargetSelector:_,onActivate:E})=>{var _e;const M=a.useRef(O||`winbox-${_r()}`),$=a.useRef(null),re=a.useRef(null),fe=a.useRef(r),K=a.useRef(E),de=a.useRef(!0),ie=a.useRef(!1),ue=a.useRef(null),xe=a.useRef([]);fe.current=r,K.current=E;const pe=a.useRef(null),ae=a.useRef(!1),[q,ce]=a.useState(null),[ve,me]=a.useState(null),[Re,Me]=a.useState(null),[We,Ee]=a.useState(!1),[Te,Ye]=a.useState(!!nt),[$e,be]=a.useState(null),Ie=a.useRef(null),he=a.useRef(null),ze=a.useCallback(()=>{xe.current.forEach(k=>{window.clearTimeout(k)}),xe.current=[]},[]),De=a.useCallback((k,H)=>{const F=window.setTimeout(()=>{xe.current=xe.current.filter(Z=>Z!==F),k()},H);return xe.current.push(F),F},[]),He=a.useCallback(()=>{de.current&&(ce(null),me(null),Me(null),Ee(!1))},[]),Be=a.useCallback((k,H=!0)=>{if(k){ze(),H&&(k.onclose=null);try{k.close(!0)}catch{}}},[ze]),Ge=a.useCallback(()=>{const k=ue.current;k&&(ue.current=null,Be(k))},[Be]),Qe=a.useCallback(k=>{if(k){ze(),ue.current=k;try{k.hide()}catch{}De(()=>{ie.current=!1,Ge()},800)}},[ze,Ge,De]),Ne=a.useCallback(k=>{be(k),Ie.current=k,k===null&&he.current!==null&&$.current&&($.current.minwidth=he.current,he.current=null)},[]),L=a.useCallback(()=>{const k={left:!1,right:!1};if(typeof window>"u"||!window.WinBox)return k;const F=window.WinBox.stack(),Z=window.innerWidth;return F.forEach(oe=>{if(oe===$.current)return;Math.abs(oe.width-Z/2)<20&&(oe.x<20&&(k.left=!0),Math.abs(oe.x+oe.width-Z)<20&&(k.right=!0))}),k},[]),w=a.useCallback(k=>{if(!k||!k.window)return;const H=window.innerWidth,F=window.innerHeight;he.current!==null&&(k.minwidth=he.current,he.current=null),k.left=0,k.right=0,k.top=0,k.bottom=0;let Z,oe;typeof o=="string"&&o.endsWith("%")?Z=Math.floor(H*parseInt(o)/100):Z=typeof o=="number"?o:Math.floor(H*.8),typeof c=="string"&&c.endsWith("%")?oe=Math.floor(F*parseInt(c)/100):oe=typeof c=="number"?c:Math.floor(F*.8),Z=Math.max(Z,l),oe=Math.max(oe,m);const te=Math.floor((H-Z)/2),Pe=Math.floor((F-oe)/2);k.resize(Z,oe).move(te,Pe),Ne(null)},[o,c,l,m,Ne]),V=a.useCallback((k,H,F,Z,oe)=>{!k||!k.window||(k.left=0,k.right=0,k.top=0,k.bottom=0,H==="left"?(k.resize(F,oe).move(0,0),Ne("left")):(k.resize(F,oe).move(Z-F,0),Ne("right")))},[Ne]),v=a.useCallback(()=>{const k=$.current,H=Ie.current;if(!k||!k.window)return;const F=window.innerWidth,Z=window.innerHeight,oe=L(),te=Math.floor(F/2),Pe=Ae=>{he.current===null&&(he.current=k.minwidth),k.minwidth=Math.min(200,te),k.max?(k.restore(),requestAnimationFrame(()=>{!k||!k.window||V(k,Ae,te,F,Z)})):V(k,Ae,te,F,Z)},Ce=()=>{k.max?(k.restore(),requestAnimationFrame(()=>{!k||!k.window||w(k)})):w(k)};if(H==="left"){Ce();return}if(H==="right"){oe.left?Ce():Pe("left");return}oe.right&&!oe.left?Pe("left"):Pe("right")},[L,w,V]),D=mi(re,{enablePositionTracking:!1,enableScaleCompensation:!$e&&!((_e=$.current)!=null&&_e.max)});a.useEffect(()=>{Te||Lc().then(()=>Ye(!0))},[Te]),a.useEffect(()=>(de.current=!0,()=>{de.current=!1}),[]);const W=a.useRef(!1),G=a.useCallback(()=>{var k;return vt.unregister(M.current),(k=fe.current)==null||k.call(fe),!1},[]),Y=a.useCallback(()=>{var k;vt.bringToFront(M.current),(k=K.current)==null||k.call(K)},[]);a.useEffect(()=>{if(!(!Te||!nt)){if(!t){if($.current)if(vt.unregister(M.current),ze(),B)try{$.current.hide()}catch{}else{const k=$.current;ie.current?Qe(k):Be(k),$.current=null,re.current=null,He()}return}if(t&&$.current){$.current.show(),$.current.focus(),vt.register(M.current,$.current.window);return}if(t&&!$.current){Ge();const k=["winbox-react"];p||k.push("no-max"),h||k.push("no-min"),g||k.push("no-resize"),y||k.push("no-move"),k.push("no-full"),N&&k.push(N);const H=new nt({id:O,title:e,width:o,height:c,minwidth:l,minheight:m,x:u,y:d,modal:f,background:x,border:z,overflow:!0,class:k,root:I||document.body,onclose:G,onmaximize:b,onminimize:function(){ae.current=!0;const F=pe.current,Z=F?{x:F.x,y:F.y}:{x:this.x||0,y:this.y||0},oe=F?{width:F.width,height:F.height}:{width:this.width||800,height:this.height||600},te=this.window;if(_&&te){const Pe=document.querySelector(_);if(Pe){te.style.transition="none",te.style.transform="",te.style.opacity="1",F&&(te.style.left=`${F.x}px`,te.style.top=`${F.y}px`,te.style.width=`${F.width}px`,te.style.height=`${F.height}px`),te.offsetHeight;const Ce=te.getBoundingClientRect(),Ae=Pe.getBoundingClientRect(),qe=Ae.left+Ae.width/2,et=Ae.top+Ae.height/2,Ve=Ce.left,j=Ce.top+Ce.height/2,ne=qe-Ve,we=et-j,Oe=Math.min(Ae.width/Ce.width,Ae.height/Ce.height,.06);te.style.transformOrigin="left center";const Ze=te.parentElement;Ze&&(Ze.style.perspective="1000px",Ze.style.perspectiveOrigin="left center"),te.offsetHeight;const A=400;return te.style.transition=`transform ${A}ms cubic-bezier(0.4, 0, 0.2, 1), opacity ${A}ms ease-out`,te.style.transform=`translate(${ne}px, ${we}px) scale(${Oe}) rotateY(-30deg)`,te.style.opacity="0",De(()=>{te.isConnected&&(te.style.transition="none",te.style.transform="",te.style.opacity="",Ze&&(Ze.style.perspective="",Ze.style.perspectiveOrigin=""),this.hide(),S==null||S(Z,oe))},A),!0}}return this.hide(),S==null||S(Z,oe),!0},onrestore:C,onfocus:function(){R==null||R(),Y()},onblur:U,onmove:function(F,Z){if(this.max||this.min||W.current)return;const oe=window.innerWidth,te=window.innerHeight,Pe=this.width;this.height;const Ce=X;if(Ie.current){const j=Ie.current==="left"?0:oe-Pe;Math.abs(F-j)>50&&Ne(null)}let Ae=F,qe=Z;F<Ce-Pe&&(Ae=Ce-Pe),F>oe-Ce&&(Ae=oe-Ce),Z<0&&(qe=0),Z>te-Ce&&(qe=te-Ce),(Ae!==F||qe!==Z)&&(W.current=!0,this.move(Ae,qe),W.current=!1);const et=pe.current,Ve=et&&qe-et.y>200;!this.min&&!this.max&&!ae.current&&!Ve&&(pe.current={x:Ae,y:qe,width:this.width,height:this.height}),P==null||P(Ae,qe)},onresize:function(F,Z){const oe=pe.current,te=oe&&(Z<100||oe.height-Z>200);!this.min&&!this.max&&!ae.current&&!te&&(pe.current={x:this.x,y:this.y,width:F,height:Z}),J==null||J(F,Z)}});if($.current=H,H.addControl({index:0,class:"wb-split",image:"data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIyNCIgaGVpZ2h0PSIyNCIgdmlld0JveD0iMCAwIDI0IDI0IiBmaWxsPSJub25lIiBzdHJva2U9ImN1cnJlbnRDb2xvciIgc3Ryb2tlLXdpZHRoPSIyIiBzdHJva2UtbGluZWNhcD0icm91bmQiIHN0cm9rZS1saW5lam9pbj0icm91bmQiPjxyZWN0IHg9IjMiIHk9IjMiIHdpZHRoPSIxOCIgaGVpZ2h0PSIxOCIgcng9IjIiIHJ5PSIyIj48L3JlY3Q+PGxpbmUgeDE9IjEyIiB5MT0iMyIgeDI9IjEyIiB5Mj0iMjEiPjwvbGluZT48L3N2Zz4=",click:F=>{F.preventDefault(),F.stopPropagation(),v()}}),Q&&H.addControl({index:0,class:"wb-insert-canvas",image:"data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIyNCIgaGVpZ2h0PSIyNCIgdmlld0JveD0iMCAwIDI0IDI0IiBmaWxsPSJub25lIiBzdHJva2U9ImN1cnJlbnRDb2xvciIgc3Ryb2tlLXdpZHRoPSIyIiBzdHJva2UtbGluZWNhcD0icm91bmQiIHN0cm9rZS1saW5lam9pbj0icm91bmQiPjxyZWN0IHg9IjMiIHk9IjMiIHdpZHRoPSIxOCIgaGVpZ2h0PSIxOCIgcng9IjIiLz48cGF0aCBkPSJNMTIgOHY4Ii8+PHBhdGggZD0iTTggMTJoOCIvPjwvc3ZnPg==",click:F=>{F.preventDefault(),F.stopPropagation();const Z=H.window;if(Z){const oe=Z.getBoundingClientRect(),te={x:oe.left,y:oe.top,width:oe.width,height:oe.height};Q(te)}else{const oe={x:H.x||0,y:H.y||0,width:H.width||800,height:H.height||600};Q(oe)}}}),H.window){re.current=H.window,vt.register(M.current,re.current),requestAnimationFrame(()=>{D()});const F=H.window.querySelector(".wb-body");if(F&&me(F),n){const Z=H.window.querySelector(".wb-drag"),oe=H.window.querySelector(".wb-title");if(Z&&oe){const te=document.createElement("div");te.className="wb-icon-container",Z.insertBefore(te,oe),Me(te)}}}if(T&&H.window){const F=H.window.querySelector(".wb-drag");if(F){const Z=document.createElement("div");Z.className="wb-header-custom";const oe=te=>{te.stopPropagation()};Z.addEventListener("mousedown",oe,!0),Z.addEventListener("touchstart",oe,!0),Z.addEventListener("pointerdown",oe,!0),F.appendChild(Z),ce(Z)}}H&&!H.min&&!H.max&&(pe.current={x:H.x,y:H.y,width:H.width,height:H.height}),Ee(!0),ee&&De(()=>{$.current&&$.current.maximize()},100)}}},[t,Te,ee,B,ze,Be,Qe,Ge,He,De]),a.useEffect(()=>{const k=M.current;return()=>{if(vt.unregister(k),$.current){const H=$.current;ie.current?Qe(H):Be(H),$.current=null,re.current=null}ue.current||ze()}},[ze,Be,Qe]),a.useEffect(()=>{$.current&&e&&$.current.setTitle(e)},[e]),a.useEffect(()=>{var k,H;if($.current&&n&&!Re){const F=$.current,Z=(k=F.window)==null?void 0:k.querySelector(".wb-drag"),oe=(H=F.window)==null?void 0:H.querySelector(".wb-title");if(Z&&oe&&!Z.querySelector(".wb-icon-container")){const Pe=document.createElement("div");Pe.className="wb-icon-container",Z.insertBefore(Pe,oe),Me(Pe)}}},[n,Re]),a.useEffect(()=>{if($.current){const k=pe.current;if(t){const H=$.current.min||$.current.hidden;$.current.min&&($.current.restore(),k&&($.current.move(k.x,k.y),$.current.resize(k.width,k.height)),ae.current=!1),$.current.show(),$.current.focus(),vt.bringToFront(M.current),H&&_&&requestAnimationFrame(()=>{le()})}else $.current.hide()}},[t]);const le=a.useCallback(()=>{if(!_||!$.current)return;const k=$.current.window,H=document.querySelector(_);if(!k||!H)return;const F=pe.current;if(!F)return;const Z=H.getBoundingClientRect(),oe=Z.left+Z.width/2,te=Z.top+Z.height/2,Pe=F.x,Ce=F.y+F.height/2,Ae=oe-Pe,qe=te-Ce,et=Math.min(Z.width/F.width,Z.height/F.height,.06),Ve=k.parentElement;Ve&&(Ve.style.perspective="1000px",Ve.style.perspectiveOrigin="left center"),k.style.transition="none",k.style.transformOrigin="left center",k.style.transform=`translate(${Ae}px, ${qe}px) scale(${et}) rotateY(-30deg)`,k.style.opacity="0",k.offsetHeight;const j=350;k.style.transition=`transform ${j}ms cubic-bezier(0.2, 0, 0.4, 1), opacity ${j*.6}ms ease-out`,k.style.transform="",k.style.opacity="1",De(()=>{k.isConnected&&(k.style.transition="none",k.style.transform="",k.style.transformOrigin="",Ve&&(Ve.style.perspective="",Ve.style.perspectiveOrigin=""))},j)},[_,De]);return a.useEffect(()=>{const k=re.current;if(!k)return;const H=[".wb-drag",".wb-n",".wb-s",".wb-e",".wb-w",".wb-ne",".wb-nw",".wb-se",".wb-sw"].join(", "),F=oe=>{const te=oe.target;te instanceof Element&&te.closest(H)&&(ie.current=!0)},Z=()=>{!ie.current&&!ue.current||(ie.current=!1,Ge())};return k.addEventListener("mousedown",F,!0),k.addEventListener("touchstart",F,!0),window.addEventListener("mouseup",Z,!0),window.addEventListener("touchend",Z,!0),window.addEventListener("touchcancel",Z,!0),window.addEventListener("blur",Z),()=>{k.removeEventListener("mousedown",F,!0),k.removeEventListener("touchstart",F,!0),window.removeEventListener("mouseup",Z,!0),window.removeEventListener("touchend",Z,!0),window.removeEventListener("touchcancel",Z,!0),window.removeEventListener("blur",Z)}},[We,Ge]),a.useEffect(()=>{$.current&&ee&&$.current.maximize()},[ee]),a.useEffect(()=>{const k=re.current;if(!k)return;const H=()=>{Y()},F=()=>{Y()};return k.addEventListener("pointerdown",H,!0),k.addEventListener("focusin",F,!0),()=>{k.removeEventListener("pointerdown",H,!0),k.removeEventListener("focusin",F,!0)}},[We,Y]),a.useEffect(()=>{if(!$.current||!t||Ie.current)return;const k=typeof o=="number"?o:$.current.width,H=typeof c=="number"?c:$.current.height;typeof k!="number"||typeof H!="number"||$.current.width===k&&$.current.height===H&&$.current.minwidth===l&&$.current.minheight===m||($.current.minwidth=l,$.current.minheight=m,$.current.resize(k,H))},[c,m,l,t,o]),s.jsxs(s.Fragment,{children:[We&&n&&Re&&Rt.createPortal(s.jsx("span",{className:"wb-icon-content",children:n}),Re),We&&ve&&Rt.createPortal(s.jsx("div",{className:"winbox-content-wrapper",children:i}),ve),We&&T&&q&&Rt.createPortal(T,q)]})},Oc={image:"prompt-list-item__tag--image",video:"prompt-list-item__tag--video",audio:"prompt-list-item__tag--audio",text:"prompt-list-item__tag--text",agent:"prompt-list-item__tag--agent","ppt-common":"prompt-list-item__tag--ppt-common","ppt-slide":"prompt-list-item__tag--ppt-slide"},Fc=({content:t,title:e,sentPrompt:n,tags:r,resultPreview:i,pinned:o=!1,isPreset:c=!1,modelType:l,scene:m,previewExamples:u,onClick:d,onTogglePin:p,onDelete:h,onPreviewExample:g,language:y="zh",disabled:f=!1})=>{const x=B=>{B.stopPropagation(),p==null||p()},z=B=>{B.stopPropagation(),h==null||h()},N=(u==null?void 0:u.slice(0,3))??[],O=N.length>0,T=(e==null?void 0:e.trim())||t,I=(r||[]).filter(Boolean).slice(0,4),b=!!(n||i||I.length>0)&&!O,S=N.length===1,C=!!(g&&!f),R=B=>_=>{_.preventDefault(),_.stopPropagation(),C&&(g==null||g({content:t,previewExamples:N,initialIndex:B}))},U=B=>{B.preventDefault(),B.stopPropagation()},P=B=>_=>{_.key!=="Enter"&&_.key!==" "||(_.preventDefault(),_.stopPropagation(),C&&(g==null||g({content:t,previewExamples:N,initialIndex:B})))},J=s.jsxs("div",{className:`prompt-list-item ${o?"prompt-list-item--pinned":""} ${c?"prompt-list-item--preset":""} ${f?"prompt-list-item--disabled":""}`,onClick:f?void 0:d,children:[o&&s.jsx("div",{className:"prompt-list-item__pin-badge",children:s.jsx(vs,{size:10})}),c&&s.jsx("div",{className:"prompt-list-item__preset-badge",children:s.jsx(pi,{size:10})}),m&&s.jsx("span",{className:`prompt-list-item__tag ${l&&Oc[l]||""}`,children:m}),s.jsx("span",{className:"prompt-list-item__text",children:T}),s.jsxs("div",{className:"prompt-list-item__actions",children:[p&&s.jsx(je,{content:o?y==="zh"?"取消置顶":"Unpin":y==="zh"?"置顶":"Pin",children:s.jsx("button",{type:"button",className:"prompt-list-item__action",onClick:x,children:o?s.jsx(hi,{size:14}):s.jsx(vs,{size:14})})}),h&&s.jsx(je,{content:y==="zh"?"删除":"Delete",children:s.jsx("button",{type:"button",className:"prompt-list-item__action prompt-list-item__action--delete",onClick:z,children:s.jsx(Mt,{size:14})})})]})]}),ee=O?s.jsxs("div",{className:"prompt-list-item__hover-card",children:[s.jsx("div",{className:"prompt-list-item__hover-text",children:t}),s.jsx("div",{className:`prompt-list-item__hover-gallery ${S?"prompt-list-item__hover-gallery--single":""}`,children:N.map((B,_)=>s.jsx("div",{className:`prompt-list-item__hover-thumb ${S?"prompt-list-item__hover-thumb--single":""}`,children:C?s.jsx("button",{type:"button",className:"prompt-list-item__hover-thumb-button","aria-label":`${y==="zh"?"预览示例图":"Preview example"} ${_+1}`,onMouseDown:R(_),onClick:U,onKeyDown:P(_),children:s.jsx(Tt,{src:B.kind==="video"&&B.posterSrc||B.src,alt:B.alt,showSkeleton:!1})}):s.jsx(Tt,{src:B.kind==="video"&&B.posterSrc||B.src,alt:B.alt,showSkeleton:!1})},`${B.src}-${B.alt}`))}),C&&s.jsx("div",{className:"prompt-list-item__hover-hint",children:y==="zh"?"点击预览":"Click to preview"})]}):null,X=i?s.jsxs("div",{className:"prompt-list-item__result-preview",children:[(i.kind==="image"||i.kind==="video")&&s.jsx("div",{className:"prompt-list-item__result-media",children:s.jsx(Tt,{src:i.kind==="video"&&i.posterUrl||i.url,alt:i.title||T,showSkeleton:!1})}),i.kind==="audio"&&s.jsxs("div",{className:"prompt-list-item__result-audio",children:[i.coverUrl&&s.jsx(Tt,{src:i.coverUrl,alt:i.title||T,showSkeleton:!1}),s.jsxs("div",{children:[s.jsx("div",{className:"prompt-list-item__result-title",children:i.title||"音频结果"}),i.text&&s.jsx("div",{className:"prompt-list-item__result-text",children:i.text})]})]}),(i.kind==="text"||i.kind==="error"||i.kind==="none")&&s.jsxs("div",{className:`prompt-list-item__result-text ${i.kind==="error"?"prompt-list-item__result-text--error":""}`,children:[i.kind==="text"&&i.title&&s.jsx("strong",{children:i.title}),i.text]})]}):null,Q=b?s.jsxs("div",{className:"prompt-list-item__history-card",children:[s.jsx("div",{className:"prompt-list-item__history-title",children:T}),n&&s.jsxs("div",{className:"prompt-list-item__history-section",children:[s.jsx("div",{className:"prompt-list-item__history-label",children:"发送提示词"}),s.jsx("div",{className:"prompt-list-item__history-text",children:n})]}),I.length>0&&s.jsx("div",{className:"prompt-list-item__history-tags",children:I.map(B=>s.jsx("span",{children:B},B))}),X&&s.jsxs("div",{className:"prompt-list-item__history-section",children:[s.jsx("div",{className:"prompt-list-item__history-label",children:"结果预览"}),X]})]}):null;return ee?s.jsx(je,{content:ee,placement:"right",delay:40,overlayClassName:"prompt-list-item__hover-card-popover",children:J}):Q?s.jsx(je,{content:Q,placement:"right",delay:60,overlayClassName:"prompt-list-item__history-card-popover",children:J}):s.jsx(je,{content:T===t?t:`${T}
|
|
2
|
+
import{r as a,n as ut,s as _s,j as s,P as Vo,i as ar,g as Bn,a as Gn,C as Ue,b as qt,c as Rn,d as cr,H as Bo,M as Ke,A as lr,R as Tt,G as Go,Z as dr,e as ur,f as Kt,h as mr,F as pr,k as hr,l as fr,D as gr,m as wr,o as yr,p as qo,q as Ko,t as Zo,u as cn,X as Mt,v as gn,w as xr,x as bs,y as it,z as Yo,B as Xo,L as Jo,U as Qo,S as ei,E as je,I as ti,J as ni,K as si,N as ri,O as oi,Q as ii,T as ai,V as ci,W as li,Y as di,_ as Rt,$ as ui,a0 as qn,a1 as _r,a2 as mi,a3 as vs,a4 as pi,a5 as hi,a6 as Fe,a7 as vn,a8 as fi,a9 as gi,aa as wi,ab as yi,ac as xi,ad as Ss,ae as Kn,af as _i,ag as bi,ah as se,ai as vi,aj as Si,ak as Zn,al as ht,am as ye,an as Ii,ao as ln,ap as ki,aq as br,ar as Dt,as as vr,at as Mi,au as Sr,av as zn,aw as Ci,ax as Ir,ay as Is,az as Dn,aA as ji,aB as ks,aC as Ht,aD as Ln,aE as Ti,aF as Sn,aG as Ni,aH as Ei,aI as Pi,aJ as Ai,aK as Ri,aL as zi,aM as kr,aN as Di,aO as Li,aP as Ms,aQ as $i,aR as Yn,aS as Oi,aT as Fi,aU as Mr,aV as Cr,aW as jr,aX as at,aY as Xn,aZ as Jn,a_ as Qn,a$ as Ui,b0 as Wi,b1 as Tr,b2 as Nr,b3 as Zt,b4 as Er,b5 as Pr,b6 as Hi,b7 as Vi,b8 as Cs,b9 as Bi,ba as Ar,bb as Yt,bc as Ct,bd as Gi,be as wn,bf as Rr,bg as xt,bh as yn,bi as qi,bj as Ki,bk as zr,bl as Zi,bm as Yi,bn as es,bo as Xi,bp as Dr,bq as $n,br as Ji,bs as Lr,bt as ts,bu as $r,bv as Qi,bw as ns,bx as ss,by as Or,bz as ft,bA as ea,bB as ta,bC as Fr,bD as na,bE as sa,bF as ra,bG as oa,bH as ia,bI as aa,bJ as ca,bK as Ur,bL as la,bM as da,bN as ua,bO as ma,bP as pa,bQ as ha,bR as js,bS as fa,bT as ga,bU as wa,bV as ya,bW as xa,bX as _a,bY as ba,bZ as va,b_ as Sa,b$ as Ia,c0 as Wr,c1 as ka,c2 as Ma,c3 as Ca,c4 as ja,c5 as Ts,c6 as Ta,c7 as Na,c8 as Ea,c9 as Pa,ca as Aa,cb as Ra,cc as za,cd as Da,ce as Hr,cf as La,cg as $a,ch as Oa,ci as Fa,cj as Ua,ck as Wa,cl as Ha,cm as Vr,cn as Va,co as Br,cp as In,cq as kn,cr as Ns,cs as Es,ct as Ba,cu as Ga}from"./startup-app-eD_rQhSh.js";import{_ as dt}from"./startup-runtime-DTmhLESk.js";const St=new Map,Gr=300*1e3,Ps=500,gt=new Set;let zt=!1,Mn=null,Cn=null;function qa(){return Mn||(Mn=caches.open("drawnix-images-thumb")),Mn}function Ka(){return Cn||(Cn=caches.open("drawnix-images")),Cn}function qr(t,e){return`${t}|${e}`}function Za(t,e){try{const n=new URL(t,window.location.origin);return n.searchParams.delete("thumbnail"),n.searchParams.set("_thumb",e),n.toString()}catch{const n=t.replace(/[?&]thumbnail=[^&]*/g,"").replace(/thumbnail=[^&]*&?/g,""),r=n.includes("?")?"&":"?";return`${n}${r}_thumb=${e}`}}function xn(t,e){return t.startsWith("data:")||t.startsWith("blob:")||e!=="video"&&(t.startsWith("http://")||t.startsWith("https://"))}function As(t,e="small",n){const r=ut(t);if(xn(r,n))return r;try{const i=new URL(r,window.location.origin);return i.searchParams.set("thumbnail",e),i.toString()}catch{const i=r.includes("?")?"&":"?";return`${r}${i}thumbnail=${e}`}}async function Vt(){if(!(zt||gt.size===0)){zt=!0;try{const t=Date.now();if(St.size>Ps)for(const[r,i]of St)(t-i>Gr||St.size>Ps)&&St.delete(r);const n=Array.from(gt).slice(0,5);for(const r of n){gt.delete(r);const[i,o,c="small"]=r.split("|");try{await Kr(i,o,c),St.set(qr(i,c),Date.now())}catch(l){console.warn("Failed to ensure thumbnail:",i,l)}}gt.size>0&&("requestIdleCallback"in window?window.requestIdleCallback(Vt):setTimeout(Vt,100))}finally{zt=!1}}}async function Kr(t,e,n){const r=ut(t);if(xn(r,e))return;const i=Za(r,n);if(await(await qa()).match(i))return;const l=await Ka();let m=await l.match(r);if(!m)try{const u=new URL(r,window.location.origin);(u.pathname.startsWith("/__aitu_cache__/")||u.pathname.startsWith("/asset-library/"))&&(m=await l.match(u.pathname))}catch{}if(m){const u=await m.blob();if(_s.isInitialized()){const d=await u.arrayBuffer();await _s.generateThumbnail(r,e,d,u.type,[n])}}}function Ya(t,e,n,r=!1){const i=ut(t);if(xn(i,e))return;const o=qr(i,n),c=St.get(o);if(c&&Date.now()-c<Gr)return;const l=`${i}|${e}|${n}`;if(!gt.has(l)){if(gt.add(l),r){(async()=>{if(!zt)try{zt=!0,gt.delete(l),await Kr(i,e,n),St.set(o,Date.now())}catch(m){console.warn("Failed to ensure thumbnail immediately:",i,m)}finally{zt=!1,gt.size>0&&setTimeout(Vt,0)}})();return}"requestIdleCallback"in window?window.requestIdleCallback(Vt,{timeout:2e3}):setTimeout(Vt,200)}}function Xa(t,e,n="small"){const[r,i]=a.useState(t?As(t,n,e):void 0);return a.useEffect(()=>{if(!t){i(void 0);return}const o=ut(t),c=As(o,n,e);i(c),e&&!xn(t,e)&&Ya(t,e,n,e==="video")},[t,e,n]),r}const Rs=1,Ja=4,Zr=600*1e3,Yr=600*1e3,dn=new Map,un=new Map;function Xr(t){dn.forEach((e,n)=>{t-e>Zr&&dn.delete(n)})}function Qa(t){const e=Date.now();Xr(e),dn.set(t,e)}function ec(t){const e=Date.now();Xr(e);const n=dn.get(t);return typeof n=="number"&&e-n<=Zr}function Jr(t){un.forEach((e,n)=>{t-e.resolvedAt>Yr&&un.delete(n)})}function tc(t,e){const n=Date.now();Jr(n),un.set(t,{resolvedPoster:e,resolvedAt:n})}function zs(t){if(!t)return null;const e=Date.now();Jr(e);const n=un.get(t);return n&&e-n.resolvedAt<=Yr?n.resolvedPoster:null}function nc(t,e){if(e<=0||!t)return t;try{const n=new URL(t,window.location.origin);return n.searchParams.set("_poster_retry",String(e)),n.toString()}catch{const n=t.includes("?")?"&":"?";return`${t}${n}_poster_retry=${e}`}}function jn(t,e){return s.jsxs("div",{className:"video-poster-preview",children:[t,e&&s.jsx("div",{className:"video-poster-preview__play-overlay","aria-hidden":"true",children:s.jsx(Vo,{size:"32px"})})]})}const sc=({src:t,poster:e,alt:n="",className:r,thumbnailSize:i="small",imageLoading:o="lazy",activateVideoOnClick:c=!1,playOnActivate:l=!1,onClick:m,videoProps:u})=>{const d=a.useMemo(()=>typeof e=="string"&&e.trim()?e.trim():void 0,[e]),p=a.useMemo(()=>d?ec(d):!1,[d]),h=Xa(t,"video",i),[g,y]=a.useState(p),f=g?h:d||h,x=!!(d&&!g),z=!!(f&&f===h&&f!==t),N=a.useRef(null),O=a.useRef(!1),T=a.useRef(null),[I,b]=a.useState(()=>zs(f)),[S,C]=a.useState(0),[R,U]=a.useState(!1),P=c;a.useEffect(()=>{y(p)},[p]),a.useEffect(()=>{b(zs(f)),C(0),U(!1),O.current=!1,T.current!==null&&(window.clearTimeout(T.current),T.current=null)},[t,f,c,h,d,i]),a.useEffect(()=>{if(R||I&&I===f)return;if(!f){P||U(!0);return}const Q=x?f:nc(f,S);let B=!1;const _=new Image,E=()=>{if(!z||S>=Ja){P||U(!0);return}T.current=window.setTimeout(()=>{C(M=>M+1)},180+S*220)};return _.onload=()=>{if(!B){if(x||_.naturalWidth>Rs||_.naturalHeight>Rs){tc(f,f),b(f);return}E()}},_.onerror=()=>{if(!B){if(x&&d){Qa(d),y(!0),b(null),C(0);return}E()}},_.src=Q,()=>{B=!0,_.onload=null,_.onerror=null,T.current!==null&&(window.clearTimeout(T.current),T.current=null)}},[t,f,S,x,z,R,d,I,P]),a.useEffect(()=>{var Q;!R||!l||!O.current||(O.current=!1,(Q=N.current)==null||Q.play().catch(()=>{}))},[R,l]),a.useEffect(()=>()=>{const Q=N.current;if(Q)try{Q.pause(),Q.removeAttribute("src"),Q.load()}catch{}},[]);const J=Q=>{c&&(O.current=!0,U(!0)),m==null||m(Q)},ee=Q=>{m==null||m(Q)},X=c&&!R;return!R&&I?jn(s.jsx("img",{src:I,alt:n,className:`video-poster-preview__media${r?` ${r}`:""}`,loading:o,decoding:"async",draggable:!1,referrerPolicy:"no-referrer",onClick:J}),X):!R&&!I?jn(s.jsx("div",{className:`video-poster-preview__placeholder${r?` ${r}`:""}`,"aria-hidden":"true",onClick:c?()=>{O.current=!0,U(!0)}:void 0}),X):jn(s.jsx("video",{ref:N,src:t,poster:I||d,className:`video-poster-preview__media${r?` ${r}`:""}`,playsInline:!0,...u,onClick:ee}),!1)},rc=.1,oc=5,Ds=t=>Math.max(rc,Math.min(oc,t));function ic(t){const{items:e,initialMode:n="single",initialIndex:r=0,maxCompareSlots:i=4,defaultCompareLayout:o="horizontal",visible:c,onModeChange:l}=t,m=a.useCallback(()=>{if(Array.isArray(r))return r.slice(0,i);const q=typeof r=="number"?r:0,ce=(q+1)%e.length;return e.length>1?[q,ce]:[q]},[r,i,e.length]),u=a.useCallback(()=>{const q=m().length;return q>=4?4:q===3?3:2},[m]),[d,p]=a.useState(n),[h,g]=a.useState(typeof r=="number"?r:0),[y,f]=a.useState(m),[x,z]=a.useState(o),[N,O]=a.useState(!1),[T,I]=a.useState(1),[b,S]=a.useState({x:0,y:0}),[C,R]=a.useState(0),[U,P]=a.useState(u);a.useEffect(()=>{if(c){const q=m();p(n),g(typeof r=="number"?r:0),f(q),P(q.length>=4?4:q.length===3?3:2),I(1),S({x:0,y:0}),R(0)}},[c,n,r,m]);const J=a.useRef(e);a.useEffect(()=>{if(!c||e===J.current){J.current=e;return}const q=J.current;J.current=e;const ce=q[h];if(!(ce!=null&&ce.id))return;const ve=e.findIndex(me=>me.id===ce.id);ve!==-1&&ve!==h&&g(ve)},[c,e,h]);const ee=a.useMemo(()=>({mode:d,currentIndex:h,compareIndices:y,compareLayout:x,syncMode:N,zoomLevel:T,panOffset:b,focusedSlot:C}),[d,h,y,x,N,T,b,C]),X=a.useCallback(q=>{if(q!==d){if(q==="compare"){const ce=(h+1)%e.length;f(e.length>1?[h,ce]:[h])}else{const ce=y[C]??y[0]??0;g(ce)}p(q),I(1),S({x:0,y:0}),l==null||l(q)}},[d,h,e.length,y,C,l]),Q=a.useCallback(q=>{q>=0&&q<e.length&&(g(q),I(1),S({x:0,y:0}))},[e.length]),B=a.useCallback(()=>{const q=h>0?h-1:e.length-1;Q(q)},[h,e.length,Q]),_=a.useCallback(()=>{const q=h<e.length-1?h+1:0;Q(q)},[h,e.length,Q]),E=a.useCallback((q,ce)=>{f(ve=>{const me=[...ve];return typeof ce=="number"&&ce<U?me[ce]=q:me.length<U?me.push(q):me[C]=q,me})},[U,C]),M=a.useCallback(q=>{f(ce=>{if(ce.length<=2)return ce;const ve=[...ce];return ve.splice(q,1),ve}),C>=q&&C>0&&R(C-1)},[C]),$=a.useCallback((q,ce)=>{f(ve=>{const me=[...ve],Re=me[q];return me[q]=me[ce],me[ce]=Re,me})},[]),re=a.useCallback(q=>{z(q)},[]),fe=a.useCallback(()=>{O(q=>!q)},[]),K=a.useCallback(q=>{I(ce=>{const ve=ce+q;return Ds(ve)})},[]),de=a.useCallback(q=>{I(Ds(q))},[]),ie=a.useCallback(()=>{I(1),S({x:0,y:0})},[]),ue=a.useCallback(q=>{S(q)},[]),xe=a.useCallback(q=>{R(q)},[]),pe=a.useCallback(q=>{P(q),f(ce=>{if(ce.length>q)return ce.slice(0,q);if(ce.length<q&&e.length>ce.length){const ve=[...ce];let me=(ce[ce.length-1]+1)%e.length;for(;ve.length<q&&ve.length<e.length;)ve.includes(me)||ve.push(me),me=(me+1)%e.length;return ve}return ce})},[e.length]),ae=a.useMemo(()=>({setMode:X,goTo:Q,goToPrev:B,goToNext:_,addToCompare:E,removeFromCompare:M,swapSlots:$,setCompareLayout:re,toggleSyncMode:fe,zoom:K,setZoomLevel:de,setPan:ue,resetView:ie,setFocusedSlot:xe,setSlotCount:pe}),[X,Q,B,_,E,M,$,re,fe,K,de,ue,ie,xe,pe]);return[ee,ae]}let Qr=null;function om(t){Qr=t}function ac(){return Qr}const Nt=400;function cc(t){return t==="video"?{width:Nt,height:Math.round(Nt*(9/16))}:{width:Nt,height:Nt}}async function lc(t,e,n,r,i){const o=i||cc(e);return e==="video"?(await Rn(t,n,r,!1,o,!0,!0),o):(await cr(t,n,r,!1,o,!0,!0),o)}async function dc(t,e,n,r){const i=ac();if(!i)return{success:!1,error:"画布未初始化,请先打开画布",type:"error"};try{if(!n){const u=await ar(i,e,t,r);if(u)return{success:!0,data:{insertedCount:1,items:[{type:t,point:u.point,elementId:u.elementId,size:u.size}],firstElementId:u.elementId,firstElementPosition:u.point,firstElementSize:u.size},type:"text"}}const o=n||Bn(i,{logPrefix:"MediaQuickInsert"})||Gn(i,{emptyPoint:Ue.DEFAULT_POINT})||Ue.DEFAULT_POINT,c=i.children.length,l=await lc(i,t,e,o,r),m=i.children[c];return requestAnimationFrame(()=>{qt(i,[o[0]+Nt/2,o[1]+Nt/2])}),{success:!0,data:{insertedCount:1,items:[{type:t,point:o,elementId:m==null?void 0:m.id,size:l}],firstElementId:m==null?void 0:m.id,firstElementPosition:o,firstElementSize:l},type:"text"}}catch(o){return console.error("[MediaQuickInsert] Failed to insert media:",o),{success:!1,error:`插入失败: ${o.message||"未知错误"}`,type:"error"}}}const ke=({content:t,children:e,placement:n="bottom",sideOffset:r=8,crossAxisOffset:i=0,contentClassName:o,closeDelay:c=100})=>s.jsx(Bo,{content:t,placement:n,sideOffset:r,crossAxisOffset:i,contentClassName:o||"viewer-popover",closeDelay:c,children:e}),tn={x:0,y:0},uc=.1,mc=5,Ft=.001,Ls=.25,pc=.0025,$s=.08,hc=1,fc=2,gc=16,wc=800,yc=32,xc=88,_c=140,bc=t=>Math.max(uc,Math.min(mc,t)),vc=t=>t.deltaMode===hc?t.deltaY*gc:t.deltaMode===fc?t.deltaY*wc:t.deltaY,Sc=t=>Math.max(-$s,Math.min($s,t)),Ic=(t,e)=>{if(t.offsetWidth>0&&t.offsetHeight>0)return{width:t.offsetWidth,height:t.offsetHeight};const n=t.getBoundingClientRect(),r=Math.max(Math.abs(e),Ft);return{width:n.width/r,height:n.height/r}},eo="media-viewport-toolbar-state-single",kc=()=>{try{const t=localStorage.getItem(eo);if(t)return JSON.parse(t)}catch{}return{orientation:"horizontal",position:null}},Mc=t=>{try{localStorage.setItem(eo,JSON.stringify(t))}catch{}},On=a.forwardRef(({item:t,slotIndex:e,isFocused:n=!1,zoomLevel:r=1,panOffset:i,onClick:o,videoAutoPlay:c=!1,videoLoop:l=!0,onZoomChange:m,onPanChange:u,isCompareMode:d=!1,onInsertToCanvas:p,onDownload:h,onEdit:g,onVideoPlayStateChange:y,onVideoTimeUpdate:f,isSyncMode:x=!1},z)=>{var Ze;const N=a.useRef(null),O=a.useRef(null),T=a.useRef(null),[I,b]=a.useState(!1),[S,C]=a.useState(!0),[R,U]=a.useState(!1),[P,J]=a.useState({x:0,y:0}),[ee,X]=a.useState(i??tn),[Q,B]=a.useState(r),_=a.useRef(r),[E,M]=a.useState(0),[$,re]=a.useState(!1),[fe,K]=a.useState(!1),[de,ie]=a.useState(!1),[ue,xe]=a.useState(!1),[pe,ae]=a.useState(!1),q=a.useRef(null),ce=a.useRef(!1),ve=a.useRef(r),me=a.useRef(i);a.useImperativeHandle(z,()=>({resetVideo:()=>{O.current&&(O.current.currentTime=0,O.current.play().catch(()=>{}))},playVideo:()=>{O.current&&O.current.play().catch(()=>{})},pauseVideo:()=>{O.current&&O.current.pause()},toggleVideoPlayback:()=>{if(O.current){if(O.current.paused||O.current.ended){O.current.play().catch(()=>{});return}O.current.pause()}},setVideoTime:A=>{O.current&&(O.current.currentTime=A)},getVideoTime:()=>{var A;return((A=O.current)==null?void 0:A.currentTime)??0},isVideo:()=>(t==null?void 0:t.type)==="video"}),[t]);const[Re]=a.useState(()=>d?{orientation:"horizontal",position:null}:kc()),[Me,We]=a.useState(Re.orientation),[Ee,Te]=a.useState(Re.position),[Ye,$e]=a.useState(!1),be=a.useRef({x:0,y:0,posX:0,posY:0}),Ie=(t==null?void 0:t.type)==="video",he=(t==null?void 0:t.type)==="audio",ze=((Ze=t==null?void 0:t.prompt)==null?void 0:Ze.trim())||"",De=!!ze&&(de||ue)&&!pe,He=t?Ie||he?t.url:ut(t.url):"",Be=t!=null&&t.posterUrl?ut(t.posterUrl):"",Ge=t?`${t.type}:${t.id||t.url}`:"empty",Qe=!!(t!=null&&t.url&&!he&&!d&&!I),Ne=a.useCallback(()=>{q.current!==null&&(window.clearTimeout(q.current),q.current=null)},[]),L=a.useCallback(()=>{Ne(),ie(!0)},[Ne]),w=a.useCallback(()=>{ie(!1),Ne(),q.current=window.setTimeout(()=>{xe(!1),q.current=null},120)},[Ne]),V=a.useCallback(()=>{Ne(),xe(!0)},[Ne]),v=a.useCallback(()=>{xe(!1)},[]);a.useLayoutEffect(()=>{b(!1),C(!(t!=null&&t.url)||he||d),U(!1);const A=me.current??tn,ge=ve.current;X(A),_.current=ge,B(ge),M(0),re(!1),K(!1),ce.current=!1},[Ge,t==null?void 0:t.url,he,d]),a.useEffect(()=>()=>{Ne()},[Ne]),a.useEffect(()=>{d||Mc({orientation:Me,position:Ee})},[Me,Ee,d]),a.useLayoutEffect(()=>{const A=i??tn;me.current=i,X(ge=>ge.x===A.x&&ge.y===A.y?ge:A)},[i]),a.useLayoutEffect(()=>{ve.current=r,_.current=r,B(A=>A===r?A:r)},[r]);const D=a.useCallback((A,ge="manual")=>{const Le=bc(A);ge==="manual"&&(ce.current=!0),!(Math.abs(_.current-Le)<=Ft)&&(_.current=Le,B(tt=>Math.abs(tt-Le)<=Ft?tt:Le),m==null||m(Le))},[m]),W=a.useCallback(A=>{const ge=me.current??tn;Math.abs(ge.x-A.x)<=Ft&&Math.abs(ge.y-A.y)<=Ft||(me.current=A,X(A),u==null||u(A))},[u]),G=a.useCallback(()=>{if(d||he||!N.current)return;if(ce.current){C(!0);return}const A=Ie?O.current:T.current;if(!A||!N.current)return;const ge=N.current.getBoundingClientRect();if(ge.width<=0||ge.height<=0)return;const Le=Ie?A.videoWidth:A.naturalWidth,tt=Ie?A.videoHeight:A.naturalHeight;if(Le<=0||tt<=0)return;const Xe=Ic(A,_.current);if(Xe.width<=0||Xe.height<=0)return;const Je=Ie?_c:xc,rt=Math.max(ge.width-yc,0),mt=Math.max(ge.height-Je,0);if(rt<=0||mt<=0)return;const ct=Math.min(rt/Xe.width,mt/Xe.height);!Number.isFinite(ct)||ct<=0||(W({x:0,y:-Je/2}),D(ct,"auto"),C(!0))},[d,he,Ie,W,D]);a.useLayoutEffect(()=>{if(!(t!=null&&t.url)||he||d)return;const A=Ie?O.current:T.current;if(!A)return;if(Ie){A.readyState>=1&&G();return}const ge=A;ge.complete&&ge.naturalWidth>0&&G()},[t,he,d,Ie,G]),a.useEffect(()=>{if(!(t!=null&&t.url)||he||d||typeof ResizeObserver>"u"||!N.current)return;const A=new ResizeObserver(()=>{G()});return A.observe(N.current),()=>{A.disconnect()}},[t==null?void 0:t.url,he,d,G]);const Y=a.useCallback(A=>{A.button===0&&(A.preventDefault(),U(!0),J({x:A.clientX-ee.x,y:A.clientY-ee.y}))},[ee]),le=a.useCallback(A=>{if(!R)return;ce.current=!0;const ge={x:A.clientX-P.x,y:A.clientY-P.y};me.current=ge,X(ge),u==null||u(ge)},[R,P,u]),_e=a.useCallback(()=>{U(!1)},[]),k=a.useCallback(A=>{A.preventDefault();const ge=vc(A);if(!Number.isFinite(ge)||ge===0)return;const Le=Sc(-ge*pc);D(_.current+Le)},[D]),H=a.useCallback(()=>{D(_.current+Ls)},[D]),F=a.useCallback(()=>{D(_.current-Ls)},[D]),Z=a.useCallback(()=>{M(A=>A-90)},[]),oe=a.useCallback(()=>{M(A=>A+90)},[]),te=a.useCallback(()=>{re(A=>!A)},[]),Pe=a.useCallback(()=>{K(A=>!A)},[]),Ce=a.useCallback(async()=>{if(t)try{const A=t.type==="video"?"video":"image";if(t.type==="audio"){Ke.warning("音频暂不支持直接插入到画布");return}const ge=await dc(A,He);ge.success?Ke.success(t.type==="video"?"视频已插入到画布":"图片已插入到画布"):Ke.error(ge.error||"插入失败")}catch(A){console.error("Failed to insert to canvas:",A),Ke.error("插入失败")}},[t,He]),Ae=a.useCallback(()=>{We(A=>A==="horizontal"?"vertical":"horizontal")},[]),qe=a.useCallback(A=>{A.preventDefault(),A.stopPropagation(),$e(!0);const ge=Ee||{x:0,y:0};be.current={x:A.clientX,y:A.clientY,posX:ge.x,posY:ge.y};const Le=Xe=>{const Je=Xe.clientX-be.current.x,rt=Xe.clientY-be.current.y;Te({x:be.current.posX+Je,y:be.current.posY+rt})},tt=()=>{$e(!1),document.removeEventListener("mousemove",Le),document.removeEventListener("mouseup",tt)};document.addEventListener("mousemove",Le),document.addEventListener("mouseup",tt)},[Ee]),et=a.useCallback(A=>{if(A.stopPropagation(),A.touches.length!==1)return;const ge=A.touches[0];$e(!0);const Le=Ee||{x:0,y:0};be.current={x:ge.clientX,y:ge.clientY,posX:Le.x,posY:Le.y};const tt=Je=>{if(Je.touches.length!==1)return;Je.preventDefault();const rt=Je.touches[0],mt=rt.clientX-be.current.x,ct=rt.clientY-be.current.y;Te({x:be.current.posX+mt,y:be.current.posY+ct})},Xe=()=>{$e(!1),document.removeEventListener("touchmove",tt),document.removeEventListener("touchend",Xe),document.removeEventListener("touchcancel",Xe)};document.addEventListener("touchmove",tt,{passive:!1}),document.addEventListener("touchend",Xe),document.addEventListener("touchcancel",Xe)},[Ee]),Ve=a.useCallback(()=>{Te(null)},[]);if(!t)return s.jsx("div",{className:`media-viewport media-viewport--empty ${n?"media-viewport--focused":""}`,onClick:o,children:s.jsx("div",{className:"media-viewport__placeholder",children:s.jsx("span",{children:"点击底部缩略图添加媒体"})})});const j=$?-Q:Q,ne=fe?-Q:Q,we={transform:`translate(${ee.x}px, ${ee.y}px) scale(${j}, ${ne}) rotate(${E}deg)`},Oe=Qe&&!S;return s.jsxs("div",{ref:N,className:`media-viewport ${n?"media-viewport--focused":""} ${he?"media-viewport--audio":""} ${Ie?"media-viewport--video":""} ${d?"":"media-viewport--single"}`,onClick:o,onMouseDown:he?void 0:Y,onMouseMove:he?void 0:le,onMouseUp:he?void 0:_e,onWheel:he?void 0:k,onMouseLeave:()=>{he||_e(),ie(!1),xe(!1),ae(!1),Ne()},"data-slot":e,children:[s.jsx("div",{className:`media-viewport__content ${Oe?"media-viewport__content--auto-fitting":""}`,style:he?void 0:we,children:Ie?s.jsx("div",{className:"media-viewport__media-hitbox",onMouseEnter:L,onMouseLeave:w,children:s.jsx("video",{ref:O,src:He,autoPlay:c,loop:l,controls:!0,className:"media-viewport__video",referrerPolicy:"no-referrer",onClick:A=>A.stopPropagation(),onPlay:()=>{x&&y&&y(!0)},onPause:()=>{x&&y&&y(!1)},onSeeked:()=>{x&&f&&O.current&&f(O.current.currentTime)},onLoadedMetadata:G})}):he?s.jsx("div",{className:"media-viewport__audio-shell",onClick:A=>A.stopPropagation(),children:s.jsxs("div",{className:"media-viewport__audio-card",children:[s.jsx(lr,{src:Be,alt:t.alt||t.title||"",imageClassName:"media-viewport__audio-poster",fallbackClassName:"media-viewport__audio-poster media-viewport__audio-poster--fallback",iconSize:56}),s.jsxs("div",{className:"media-viewport__audio-meta",children:[t.title&&s.jsx("div",{className:"media-viewport__audio-title",children:t.title}),typeof t.duration=="number"&&Number.isFinite(t.duration)&&t.duration>0&&s.jsxs("div",{className:"media-viewport__audio-duration",children:[Math.floor(t.duration/60),":",String(Math.round(t.duration%60)).padStart(2,"0")]})]}),s.jsx("audio",{src:He,controls:!0,preload:"metadata",className:"media-viewport__audio",referrerPolicy:"no-referrer"})]})}):I?s.jsx("div",{className:"media-viewport__media-hitbox",onMouseEnter:L,onMouseLeave:w,children:s.jsx("div",{className:"media-viewport__image-fallback",children:s.jsx("span",{children:"图片加载失败"})})}):s.jsx("div",{className:"media-viewport__media-hitbox",onMouseEnter:L,onMouseLeave:w,children:s.jsx(Tt,{ref:T,src:He,alt:t.alt||t.title||"",className:"media-viewport__image",draggable:!1,showSkeleton:!1,eager:!0,onLoad:G,onError:()=>{b(!0),C(!0)}})})}),s.jsxs("div",{className:`media-viewport__toolbar media-viewport__toolbar--${Me} ${Ye?"media-viewport__toolbar--dragging":""} ${d?"media-viewport__toolbar--compact":""}`,style:!d&&Ee?{transform:`translate(calc(-50% + ${Ee.x}px), ${Ee.y}px)`}:void 0,onMouseEnter:()=>ae(!0),onMouseLeave:()=>ae(!1),onMouseDown:A=>A.stopPropagation(),onClick:A=>A.stopPropagation(),children:[!he&&s.jsxs(s.Fragment,{children:[!d&&s.jsxs(s.Fragment,{children:[s.jsx(ke,{content:"拖拽移动工具栏,双击重置位置",placement:"top",contentClassName:"viewer-popover",children:s.jsx("div",{className:"media-viewport__toolbar-handle",onMouseDown:qe,onTouchStart:et,onDoubleClick:A=>{A.stopPropagation(),Ve()},children:s.jsx(Go,{size:14})})}),s.jsx(ke,{content:Me==="horizontal"?"切换为垂直布局":"切换为水平布局",placement:"top",contentClassName:"viewer-popover",children:s.jsx("button",{type:"button",className:"media-viewport__toolbar-orientation-btn",onClick:A=>{A.stopPropagation(),A.preventDefault(),Ae()},children:s.jsx("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:Me==="horizontal"?s.jsxs(s.Fragment,{children:[s.jsx("line",{x1:"12",y1:"3",x2:"12",y2:"21"}),s.jsx("polyline",{points:"8 7 12 3 16 7"}),s.jsx("polyline",{points:"8 17 12 21 16 17"})]}):s.jsxs(s.Fragment,{children:[s.jsx("line",{x1:"3",y1:"12",x2:"21",y2:"12"}),s.jsx("polyline",{points:"7 8 3 12 7 16"}),s.jsx("polyline",{points:"17 8 21 12 17 16"})]})})})}),s.jsx("div",{className:"media-viewport__toolbar-divider"})]}),s.jsxs("div",{className:"media-viewport__toolbar-group",children:[s.jsx(ke,{content:"缩小",placement:"top",contentClassName:"viewer-popover",children:s.jsx("button",{type:"button","aria-label":"缩小",onClick:A=>{A.stopPropagation(),A.preventDefault(),F()},children:s.jsx(dr,{size:16})})}),s.jsxs("span",{className:"media-viewport__zoom-level",children:[Math.round(Q*100),"%"]}),s.jsx(ke,{content:"放大",placement:"top",contentClassName:"viewer-popover",children:s.jsx("button",{type:"button","aria-label":"放大",onClick:A=>{A.stopPropagation(),A.preventDefault(),H()},children:s.jsx(ur,{size:16})})})]}),s.jsx("div",{className:"media-viewport__toolbar-divider"}),s.jsxs("div",{className:"media-viewport__toolbar-group",children:[s.jsx(ke,{content:"向左旋转 90°",placement:"top",contentClassName:"viewer-popover",children:s.jsx("button",{type:"button","aria-label":"向左旋转 90°",onClick:A=>{A.stopPropagation(),A.preventDefault(),Z()},children:s.jsx(Kt,{size:16})})}),s.jsx(ke,{content:"向右旋转 90°",placement:"top",contentClassName:"viewer-popover",children:s.jsx("button",{type:"button","aria-label":"向右旋转 90°",onClick:A=>{A.stopPropagation(),A.preventDefault(),oe()},children:s.jsx(mr,{size:16})})})]}),s.jsx("div",{className:"media-viewport__toolbar-divider"}),s.jsxs("div",{className:"media-viewport__toolbar-group",children:[s.jsx(ke,{content:"水平翻转",placement:"top",contentClassName:"viewer-popover",children:s.jsx("button",{type:"button","aria-label":"水平翻转",className:$?"active":"",onClick:A=>{A.stopPropagation(),A.preventDefault(),te()},children:s.jsx(pr,{size:16})})}),s.jsx(ke,{content:"垂直翻转",placement:"top",contentClassName:"viewer-popover",children:s.jsx("button",{type:"button","aria-label":"垂直翻转",className:fe?"active":"",onClick:A=>{A.stopPropagation(),A.preventDefault(),Pe()},children:s.jsx(hr,{size:16})})})]})]}),!d&&!he&&s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"media-viewport__toolbar-divider"}),s.jsx(ke,{content:"插入到画布",placement:"top",contentClassName:"viewer-popover",children:s.jsx("button",{type:"button",onClick:A=>{A.stopPropagation(),A.preventDefault(),p?p():Ce()},children:s.jsx(fr,{size:16})})})]}),!d&&h&&s.jsxs(s.Fragment,{children:[he&&s.jsx("div",{className:"media-viewport__toolbar-divider"}),s.jsx(ke,{content:"下载",placement:"top",contentClassName:"viewer-popover",children:s.jsx("button",{type:"button",onClick:A=>{A.stopPropagation(),A.preventDefault(),h()},children:s.jsx(gr,{size:16})})})]}),!d&&g&&(t==null?void 0:t.type)==="image"&&s.jsx(ke,{content:"编辑图片",placement:"top",contentClassName:"viewer-popover",children:s.jsx("button",{type:"button",onClick:A=>{A.stopPropagation(),A.preventDefault(),g()},children:s.jsx(wr,{size:16})})})]}),ze&&!he&&s.jsx(ke,{content:ze,placement:"bottom",sideOffset:10,contentClassName:"viewer-popover viewer-popover--prompt",children:s.jsx("div",{className:`media-viewport__prompt ${De?"media-viewport__prompt--visible":""} ${ue?"media-viewport__prompt--expanded":""}`,onMouseEnter:V,onMouseLeave:v,children:ze})})]})});On.displayName="MediaViewport";const Cc=({src:t,fallbackSrc:e,alt:n})=>{const[r,i]=a.useState(t),[o,c]=a.useState(!1);return a.useEffect(()=>{i(t),c(!1)},[t]),o?s.jsx("div",{className:"thumbnail-queue__image thumbnail-queue__image-fallback",children:s.jsx("span",{children:"加载失败"})}):s.jsx(Tt,{src:r,alt:n,className:"thumbnail-queue__image",showSkeleton:!1,onError:()=>{if(e&&r!==e){i(e);return}c(!0)}})};function jc(t,e="small"){const n=ut(t);if(n.startsWith("http://")||n.startsWith("https://")||n.startsWith("blob:")||Zo(n))return n;try{const r=new URL(n,window.location.origin);return r.searchParams.set("thumbnail",e),r.toString()}catch{const r=n.includes("?")?"&":"?";return`${n}${r}thumbnail=${e}`}}const Tc=({items:t,mode:e,currentIndex:n,compareIndices:r,onThumbnailClick:i,onDragStart:o})=>{const c=a.useRef(null),[l,m]=a.useState(null);a.useEffect(()=>{if(e==="single"&&c.current){const y=c.current.querySelector(".thumbnail-queue__item--active");y&&y.scrollIntoView({behavior:"smooth",block:"nearest",inline:"center"})}},[n,e]);const u=a.useCallback((y,f)=>{f.dataTransfer.setData("text/plain",String(y)),f.dataTransfer.effectAllowed="move",m(y),o==null||o(y)},[o]),d=a.useCallback(()=>{m(null)},[]),p=a.useCallback(y=>e==="single"?y===n:r.includes(y),[e,n,r]),h=a.useCallback(y=>{if(e!=="compare")return;const f=r.indexOf(y);return f>=0?f+1:void 0},[e,r]),g=a.useCallback((y,f)=>{const x=p(f),z=h(f),N=l===f,O=y.type==="video",T=y.type==="audio",I=ut(y.url),b=y.posterUrl?ut(y.posterUrl):"",S=jc(T&&b?b:I,"small");return s.jsxs("div",{className:`thumbnail-queue__item ${x?"thumbnail-queue__item--active":""} ${N?"thumbnail-queue__item--dragging":""}`,onClick:()=>i(f),draggable:e==="compare",onDragStart:C=>u(f,C),onDragEnd:d,role:"button",tabIndex:0,onKeyDown:C=>{(C.key==="Enter"||C.key===" ")&&(C.preventDefault(),i(f))},children:[s.jsx("div",{className:"thumbnail-queue__thumb",children:O?s.jsxs(s.Fragment,{children:[s.jsx(sc,{src:I,poster:b||void 0,className:"thumbnail-queue__video",alt:y.alt||y.title||"",thumbnailSize:"small",videoProps:{muted:!0,preload:"metadata"}}),s.jsx("div",{className:"thumbnail-queue__video-icon",children:s.jsx(yr,{size:16})})]}):T?s.jsxs(s.Fragment,{children:[s.jsx(lr,{src:b?S:void 0,fallbackSrc:b,alt:y.alt||y.title||"",imageClassName:"thumbnail-queue__image",fallbackClassName:"thumbnail-queue__image thumbnail-queue__audio-fallback",iconSize:18,loading:"lazy"}),s.jsx("div",{className:"thumbnail-queue__video-icon",children:s.jsx(qo,{size:16})})]}):s.jsx(Cc,{src:S,alt:y.alt||y.title||"",fallbackSrc:I})}),x&&s.jsx("div",{className:"thumbnail-queue__check",children:z?s.jsx("span",{className:"thumbnail-queue__slot-number",children:z}):s.jsx(Ko,{size:18})})]},y.id||`${y.url}-${f}`)},[p,h,l,e,i,u,d]);return t.length===0?null:s.jsx("div",{className:"thumbnail-queue",ref:c,children:s.jsx("div",{className:"thumbnail-queue__list",children:t.map((y,f)=>g(y,f))})})},Nc=({mode:t,currentIndex:e,totalCount:n,slotCount:r,compareLayout:i,syncMode:o,onModeChange:c,onSlotCountChange:l,onLayoutChange:m,onSyncToggle:u,onResetView:d,onClose:p,onFullscreen:h,isImage:g=!1,showEditButton:y=!1,onBackToPreview:f,onResetEdit:x,onSaveEdit:z})=>{const N=a.useCallback(C=>{m(C),C==="grid"&&r<4&&l(4)},[m,l,r]),O=()=>s.jsxs(s.Fragment,{children:[s.jsxs("div",{className:"viewer-toolbar__indicator",children:[s.jsx("span",{className:"viewer-toolbar__current",children:e+1}),s.jsx("span",{className:"viewer-toolbar__separator",children:"/"}),s.jsx("span",{className:"viewer-toolbar__total",children:n})]}),n>1&&s.jsx(ke,{content:"对比模式",placement:"bottom",contentClassName:"viewer-popover",children:s.jsx("button",{className:"viewer-toolbar__btn",onClick:()=>c("compare"),"aria-label":"对比模式",children:s.jsx(bs,{size:18})})}),y&&g&&s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"viewer-toolbar__divider"}),s.jsx(ke,{content:"编辑图片",placement:"bottom",contentClassName:"viewer-popover",children:s.jsx("button",{className:"viewer-toolbar__btn",onClick:()=>c("edit"),"aria-label":"编辑图片",children:s.jsx(wr,{size:18})})})]})]}),T=()=>s.jsxs(s.Fragment,{children:[s.jsx(ke,{content:"返回预览",placement:"bottom",contentClassName:"viewer-popover",children:s.jsxs("button",{className:"viewer-toolbar__btn",onClick:f,"aria-label":"返回预览",children:[s.jsx(cn,{size:18}),s.jsx("span",{className:"viewer-toolbar__btn-text",children:"返回"})]})}),s.jsx("div",{className:"viewer-toolbar__divider"}),s.jsx("div",{className:"viewer-toolbar__title",children:"编辑图片"})]}),I=()=>s.jsxs(s.Fragment,{children:[s.jsx(ke,{content:"单图模式",placement:"bottom",contentClassName:"viewer-popover",children:s.jsxs("button",{className:"viewer-toolbar__btn",onClick:()=>c("single"),"aria-label":"单图模式",children:[s.jsx(cn,{size:18}),s.jsx("span",{className:"viewer-toolbar__btn-text",children:"单图"})]})}),s.jsx("div",{className:"viewer-toolbar__divider"}),s.jsxs("div",{className:"viewer-toolbar__group",children:[s.jsx("span",{className:"viewer-toolbar__label",children:"分屏"}),[2,3,4].map(C=>s.jsx(it.Fragment,{children:s.jsx(ke,{content:`${C}分屏`,placement:"bottom",contentClassName:"viewer-popover",children:s.jsx("button",{className:`viewer-toolbar__btn viewer-toolbar__btn--small ${r===C?"viewer-toolbar__btn--active":""}`,onClick:()=>l(C),"aria-label":`${C}分屏`,children:C})})},C))]}),s.jsx("div",{className:"viewer-toolbar__divider"}),s.jsxs("div",{className:"viewer-toolbar__group",children:[s.jsx(ke,{content:"水平布局",placement:"bottom",contentClassName:"viewer-popover",children:s.jsx("button",{className:`viewer-toolbar__btn ${i==="horizontal"?"viewer-toolbar__btn--active":""}`,onClick:()=>N("horizontal"),"aria-label":"水平布局",children:s.jsx(bs,{size:18})})}),s.jsx(ke,{content:"垂直布局",placement:"bottom",contentClassName:"viewer-popover",children:s.jsx("button",{className:`viewer-toolbar__btn ${i==="vertical"?"viewer-toolbar__btn--active":""}`,onClick:()=>N("vertical"),"aria-label":"垂直布局",children:s.jsx(Yo,{size:18})})}),s.jsx(ke,{content:"网格布局",placement:"bottom",contentClassName:"viewer-popover",children:s.jsx("button",{className:`viewer-toolbar__btn ${i==="grid"?"viewer-toolbar__btn--active":""}`,onClick:()=>N("grid"),"aria-label":"网格布局",children:s.jsx(Xo,{size:18})})})]}),s.jsx("div",{className:"viewer-toolbar__divider"}),s.jsx(ke,{content:o?"取消联动(快捷键 S)":"联动缩放/拖拽(快捷键 S)",placement:"bottom",contentClassName:"viewer-popover",children:s.jsx("button",{className:`viewer-toolbar__btn ${o?"viewer-toolbar__btn--active":""}`,onClick:u,"aria-label":o?"取消联动":"联动缩放/拖拽",children:o?s.jsx(Jo,{size:18}):s.jsx(Qo,{size:18})})}),o&&s.jsx(ke,{content:"重置视图",placement:"bottom",contentClassName:"viewer-popover",children:s.jsx("button",{className:"viewer-toolbar__btn",onClick:d,children:s.jsx(Kt,{size:18})})})]}),b=()=>{switch(t){case"edit":return T();case"compare":return I();default:return O()}},S=()=>t==="edit"?s.jsxs(s.Fragment,{children:[s.jsx(ke,{content:"重置",placement:"bottom",contentClassName:"viewer-popover",children:s.jsx("button",{className:"viewer-toolbar__btn",onClick:x,children:s.jsx(Kt,{size:18})})}),s.jsx(ke,{content:"保存",placement:"bottom",contentClassName:"viewer-popover",children:s.jsx("button",{className:"viewer-toolbar__btn viewer-toolbar__btn--primary",onClick:z,"aria-label":"保存",children:s.jsx(gn,{size:18})})}),s.jsx(ke,{content:"关闭(Esc)",placement:"bottom",contentClassName:"viewer-popover",children:s.jsx("button",{className:"viewer-toolbar__btn viewer-toolbar__btn--close",onClick:p,"aria-label":"关闭",children:s.jsx(Mt,{size:20})})})]}):s.jsxs(s.Fragment,{children:[h&&s.jsx(ke,{content:"全屏",placement:"bottom",contentClassName:"viewer-popover",children:s.jsx("button",{className:"viewer-toolbar__btn",onClick:h,children:s.jsx(xr,{size:18})})}),s.jsx(ke,{content:"关闭(Esc)",placement:"bottom",contentClassName:"viewer-popover",children:s.jsx("button",{className:"viewer-toolbar__btn viewer-toolbar__btn--close",onClick:p,"aria-label":"关闭",children:s.jsx(Mt,{size:20})})})]});return t==="edit"?s.jsxs("div",{className:"viewer-toolbar viewer-toolbar--edit-simplified",children:[s.jsx(ke,{content:"返回预览",placement:"bottom",contentClassName:"viewer-popover",children:s.jsxs("button",{className:"viewer-toolbar__corner-btn viewer-toolbar__corner-btn--left",onClick:f,"aria-label":"返回预览",children:[s.jsx(cn,{size:20}),s.jsx("span",{children:"返回"})]})}),s.jsx(ke,{content:"关闭(Esc)",placement:"bottom",contentClassName:"viewer-popover",children:s.jsx("button",{className:"viewer-toolbar__corner-btn viewer-toolbar__corner-btn--right",onClick:p,"aria-label":"关闭",children:s.jsx(Mt,{size:20})})})]}):s.jsxs("div",{className:"viewer-toolbar",children:[s.jsx("div",{className:"viewer-toolbar__left",children:b()}),s.jsx("div",{className:"viewer-toolbar__right",children:S()})]})},_t={brightness:100,contrast:100,saturate:100,blur:0,grayscale:0,sepia:0,hueRotate:0,invert:0},Ec=[{label:"自由",value:null},{label:"1:1",value:1},{label:"4:3",value:4/3},{label:"3:4",value:3/4},{label:"16:9",value:16/9},{label:"9:16",value:9/16},{label:"3:2",value:3/2},{label:"2:3",value:2/3}],Os=[{label:"原图",type:"none",filter:"none"},{label:"黑白",type:"grayscale",filter:"grayscale(100%)"},{label:"怀旧",type:"sepia",filter:"sepia(80%)"},{label:"复古",type:"vintage",filter:"sepia(40%) contrast(110%) brightness(90%)"},{label:"冷色",type:"cold",filter:"saturate(80%) hue-rotate(180deg) brightness(105%)"},{label:"暖色",type:"warm",filter:"saturate(120%) sepia(20%) brightness(105%)"},{label:"高对比",type:"contrast",filter:"contrast(150%)"},{label:"高饱和",type:"saturate",filter:"saturate(180%)"},{label:"反转",type:"invert",filter:"invert(100%)"}],Pc=({aspectRatio:t,presets:e,onAspectRatioChange:n,rotation:r,flipH:i,flipV:o,onRotate:c,onFlipH:l,onFlipV:m,onConfirmCrop:u,hasCropArea:d=!1,onAutoTrimWhitespace:p,isDetectingWhitespace:h=!1})=>s.jsxs("div",{className:"crop-panel",children:[p&&s.jsxs("div",{className:"crop-panel__section",children:[s.jsx("div",{className:"crop-panel__section-title",children:"智能裁剪"}),s.jsxs("button",{type:"button",className:`crop-panel__auto-trim-btn ${h?"loading":""}`,onClick:p,disabled:h,children:[s.jsx(ei,{size:16}),s.jsx("span",{children:h?"检测中...":"智能去白边"})]}),s.jsx("div",{className:"crop-panel__auto-trim-hint",children:"自动检测并移除图片周围的白色边框"})]}),s.jsxs("div",{className:"crop-panel__section",children:[s.jsx("div",{className:"crop-panel__section-title",children:"裁剪比例"}),s.jsx("div",{className:"crop-panel__ratio-grid",children:e.map(g=>s.jsx("button",{type:"button",className:`crop-panel__ratio-btn ${t===g.value?"active":""}`,onClick:()=>n(g.value),children:g.label},g.label))})]}),s.jsxs("div",{className:"crop-panel__section",children:[s.jsx("div",{className:"crop-panel__section-title",children:"旋转和翻转"}),s.jsxs("div",{className:"crop-panel__transform-row",children:[s.jsx(je,{content:"向左旋转 90°",placement:"top",children:s.jsx("button",{type:"button",className:"crop-panel__transform-btn",onClick:()=>c(-90),children:s.jsx(Kt,{size:18})})}),s.jsx(je,{content:"向右旋转 90°",placement:"top",children:s.jsx("button",{type:"button",className:"crop-panel__transform-btn",onClick:()=>c(90),children:s.jsx(mr,{size:18})})}),s.jsx(je,{content:"水平翻转",placement:"top",children:s.jsx("button",{type:"button",className:`crop-panel__transform-btn ${i?"active":""}`,onClick:l,children:s.jsx(pr,{size:18})})}),s.jsx(je,{content:"垂直翻转",placement:"top",children:s.jsx("button",{type:"button",className:`crop-panel__transform-btn ${o?"active":""}`,onClick:m,children:s.jsx(hr,{size:18})})})]}),r!==0&&s.jsxs("div",{className:"crop-panel__rotation-info",children:["当前旋转: ",r,"°"]})]}),u&&s.jsxs("div",{className:"crop-panel__section",children:[s.jsxs("button",{type:"button",className:`crop-panel__confirm-btn ${d?"":"disabled"}`,onClick:u,disabled:!d,children:[s.jsx(gn,{size:16}),s.jsx("span",{children:"应用裁剪"})]}),s.jsx("div",{className:"crop-panel__confirm-hint",children:"按 Enter 键快速确认"})]}),s.jsxs("div",{className:"crop-panel__tips",children:[s.jsx("p",{children:"拖动裁剪框调整位置"}),s.jsx("p",{children:"拖动边角调整大小"})]})]}),Ac=({filterType:t,filterParams:e,presets:n,imageUrl:r,onPresetSelect:i,onParamChange:o})=>s.jsxs("div",{className:"filter-panel",children:[s.jsxs("div",{className:"filter-panel__section",children:[s.jsx("div",{className:"filter-panel__section-title",children:"滤镜预设"}),s.jsx("div",{className:"filter-panel__preset-grid",children:n.map(c=>s.jsxs("button",{type:"button",className:`filter-panel__preset-btn ${t===c.type?"active":""}`,onClick:()=>i(c.type),children:[s.jsx("div",{className:"filter-panel__preset-preview",style:{backgroundImage:`url(${r})`,filter:c.filter}}),s.jsx("span",{className:"filter-panel__preset-label",children:c.label})]},c.type))})]}),s.jsxs("div",{className:"filter-panel__section",children:[s.jsx("div",{className:"filter-panel__section-title",children:"参数调节"}),s.jsxs("div",{className:"filter-panel__sliders",children:[s.jsx(bt,{label:"亮度",value:e.brightness,min:0,max:200,defaultValue:100,onChange:c=>o("brightness",c)}),s.jsx(bt,{label:"对比度",value:e.contrast,min:0,max:200,defaultValue:100,onChange:c=>o("contrast",c)}),s.jsx(bt,{label:"饱和度",value:e.saturate,min:0,max:200,defaultValue:100,onChange:c=>o("saturate",c)}),s.jsx(bt,{label:"灰度",value:e.grayscale,min:0,max:100,defaultValue:0,onChange:c=>o("grayscale",c)}),s.jsx(bt,{label:"复古",value:e.sepia,min:0,max:100,defaultValue:0,onChange:c=>o("sepia",c)}),s.jsx(bt,{label:"色相",value:e.hueRotate,min:0,max:360,defaultValue:0,onChange:c=>o("hueRotate",c)}),s.jsx(bt,{label:"模糊",value:e.blur,min:0,max:10,defaultValue:0,step:.5,onChange:c=>o("blur",c)})]})]})]}),bt=({label:t,value:e,min:n,max:r,defaultValue:i,step:o=1,onChange:c})=>{const l=e===i;return s.jsxs("div",{className:"filter-slider",children:[s.jsxs("div",{className:"filter-slider__header",children:[s.jsx("span",{className:"filter-slider__label",children:t}),s.jsx("span",{className:`filter-slider__value ${l?"":"modified"}`,children:e})]}),s.jsx(ti,{value:e,min:n,max:r,step:o,onChange:m=>c(m)})]})},pt=10010;function Rc(t,e={}){const{threshold:n=250,tolerance:r=.02,minContentSize:i=50}=e,o=t.naturalWidth,c=t.naturalHeight,l=document.createElement("canvas");l.width=o,l.height=c;const m=l.getContext("2d");if(!m)return null;m.drawImage(t,0,0);const d=m.getImageData(0,0,o,c).data,p=b=>{const S=d[b],C=d[b+1],R=d[b+2];return d[b+3]<10?!0:S>=n&&C>=n&&R>=n},h=b=>{let S=0;for(let C=0;C<o;C++){const R=(b*o+C)*4;p(R)&&S++}return S/o>=1-r},g=b=>{let S=0;for(let C=0;C<c;C++){const R=(C*o+b)*4;p(R)&&S++}return S/c>=1-r};let y=0;for(;y<c&&h(y);)y++;let f=c-1;for(;f>y&&h(f);)f--;let x=0;for(;x<o&&g(x);)x++;let z=o-1;for(;z>x&&g(z);)z--;const N=z-x+1,O=f-y+1,T=y>0||x>0||z<o-1||f<c-1,I=N>=i&&O>=i;return!T||!I?null:{x,y,width:N,height:O}}const to=a.forwardRef(({imageUrl:t,showOverwrite:e=!1,onOverwrite:n,onInsert:r,onClose:i,onSave:o,className:c},l)=>{const[m,u]=a.useState("crop"),[d,p]=a.useState(null),[h,g]=a.useState(null),[y,f]=a.useState("none"),[x,z]=a.useState(_t),[N,O]=a.useState(0),[T,I]=a.useState(!1),[b,S]=a.useState(!1),[C,R]=a.useState({width:0,height:0}),[U,P]=a.useState(1),[J,ee]=a.useState(1),X=.1,Q=5,B=.1,[_,E]=a.useState({x:0,y:0}),[M,$]=a.useState(!1),[re,fe]=a.useState({x:0,y:0}),[K,de]=a.useState(!1),[ie,ue]=a.useState(null),[xe,pe]=a.useState(!1),[ae,q]=a.useState(null),[ce,ve]=a.useState(!1),[me,Re]=a.useState([]),[Me,We]=a.useState(-1),Ee=a.useRef(!1),Te=a.useRef(null),Ye=a.useRef(null),$e=a.useRef(null);a.useEffect(()=>{$e.current!==null&&$e.current!==t&&(p(null),q(null),g(null),f("none"),z(_t),O(0),I(!1),S(!1),ee(1),P(1),R({width:0,height:0}),E({x:0,y:0}),u("crop"),Re([{cropArea:null,confirmedCropArea:null,aspectRatio:null,filterType:"none",filterParams:_t,rotation:0,flipH:!1,flipV:!1}]),We(0)),$e.current=t},[t]),a.useEffect(()=>{if(!t)return;const j=new Image;return j.crossOrigin="anonymous",j.onload=()=>{Te.current=j,R({width:j.naturalWidth,height:j.naturalHeight})},j.onerror=()=>{Ke.error("图片加载失败")},j.src=t,()=>{Te.current=null}},[t]),a.useEffect(()=>{t&&me.length===0&&(Re([{cropArea:null,confirmedCropArea:null,aspectRatio:null,filterType:"none",filterParams:_t,rotation:0,flipH:!1,flipV:!1}]),We(0))},[t,me.length]),a.useEffect(()=>{if(!Ye.current||C.width===0)return;const j=()=>{const we=Ye.current;if(!we)return;const Oe=we.clientWidth-80,Ze=we.clientHeight-80;if(Oe<=0||Ze<=0)return;const A=Oe/C.width,ge=Ze/C.height,Le=Math.min(A,ge,1);Le>0&&isFinite(Le)&&P(Le)};requestAnimationFrame(j);const ne=new ResizeObserver(j);return ne.observe(Ye.current),()=>ne.disconnect()},[C]);const be=a.useRef(null);a.useEffect(()=>{if(!(Ee.current||me.length===0))return be.current&&clearTimeout(be.current),be.current=setTimeout(()=>{He()},300),()=>{be.current&&clearTimeout(be.current)}},[N,T,b,y,x,h,ae]);const Ie=a.useCallback(()=>{if(y!=="none"){const ne=Os.find(we=>we.type===y);if(ne)return ne.filter}const j=[];return x.brightness!==100&&j.push(`brightness(${x.brightness}%)`),x.contrast!==100&&j.push(`contrast(${x.contrast}%)`),x.saturate!==100&&j.push(`saturate(${x.saturate}%)`),x.blur>0&&j.push(`blur(${x.blur}px)`),x.grayscale>0&&j.push(`grayscale(${x.grayscale}%)`),x.sepia>0&&j.push(`sepia(${x.sepia}%)`),x.hueRotate!==0&&j.push(`hue-rotate(${x.hueRotate}deg)`),x.invert>0&&j.push(`invert(${x.invert}%)`),j.length>0?j.join(" "):"none"},[y,x]),he=a.useCallback(()=>{const j=[];return N!==0&&j.push(`rotate(${N}deg)`),T&&j.push("scaleX(-1)"),b&&j.push("scaleY(-1)"),j.length>0?j.join(" "):"none"},[N,T,b]),ze=a.useCallback(()=>({cropArea:d,confirmedCropArea:ae,aspectRatio:h,filterType:y,filterParams:x,rotation:N,flipH:T,flipV:b}),[d,ae,h,y,x,N,T,b]),De=a.useCallback(j=>{Ee.current=!0,p(j.cropArea),q(j.confirmedCropArea),g(j.aspectRatio),f(j.filterType),z(j.filterParams),O(j.rotation),I(j.flipH),S(j.flipV),requestAnimationFrame(()=>{Ee.current=!1})},[]),He=a.useCallback(()=>{if(Ee.current)return;const j=ze();Re(ne=>{const we=ne.slice(0,Me+1);return we.push(j),we.length>50&&we.shift(),we}),We(ne=>Math.min(ne+1,49))},[ze,Me]),Be=a.useCallback(()=>{if(Me<=0)return;const j=Me-1;We(j),De(me[j])},[Me,me,De]),Ge=a.useCallback(()=>{if(Me>=me.length-1)return;const j=Me+1;We(j),De(me[j])},[Me,me,De]),Qe=Me>0,Ne=Me<me.length-1,L=a.useCallback(()=>ae!==null||d!==null||N!==0||T||b||y!=="none"||Object.keys(x).some(j=>x[j]!==_t[j]),[ae,d,N,T,b,y,x]),w=a.useCallback(()=>{p(null),q(null),g(null),f("none"),z(_t),O(0),I(!1),S(!1),ee(1),E({x:0,y:0}),Re([]),We(-1)},[]),V=a.useCallback(async()=>{const j=Te.current;if(!j){Ke.error("图片未加载");return}const ne=Ke.loading("正在处理图片...",0);try{const we=document.createElement("canvas"),Oe=we.getContext("2d");if(!Oe)throw new Error("无法创建 Canvas 上下文");let Ze=j.naturalWidth,A=j.naturalHeight,ge=0,Le=0,tt=j.naturalWidth,Xe=j.naturalHeight;const Je=ae||d;Je&&(ge=Je.x,Le=Je.y,tt=Je.width,Xe=Je.height,Ze=Je.width,A=Je.height);const rt=(N%360+360)%360;(rt===90||rt===270)&&([Ze,A]=[A,Ze]),we.width=Ze,we.height=A,Oe.save(),Oe.translate(Ze/2,A/2),N!==0&&Oe.rotate(N*Math.PI/180),T&&Oe.scale(-1,1),b&&Oe.scale(1,-1);let mt=tt,ct=Xe;(rt===90||rt===270)&&([mt,ct]=[ct,mt]);const ys=Ie();ys!=="none"&&(Oe.filter=ys),Oe.drawImage(j,ge,Le,tt,Xe,-mt/2,-ct/2,mt,ct),Oe.restore();const xs=we.toDataURL("image/png");if(Ke.close(ne),o){o(xs);return}ue(xs),de(!0)}catch(we){Ke.close(ne),Ke.error(we instanceof Error?we.message:"图片处理失败")}},[ae,d,N,T,b,Ie,o]),v=a.useCallback(j=>{if(ie){switch(j){case"overwrite":n==null||n(ie);break;case"insert":r==null||r(ie);break;case"download":{const ne=document.createElement("a");ne.href=ie,ne.download=`edited-image-${Date.now()}.png`,ne.click(),Ke.success("图片已下载");break}}de(!1),ue(null),i==null||i()}},[ie,n,r,i]),D=a.useCallback(j=>{g(j),p(null),q(null)},[]),W=a.useCallback(j=>{f(j),j!=="none"&&z(_t)},[]),G=a.useCallback((j,ne)=>{z(we=>({...we,[j]:ne})),f("none")},[]),Y=a.useCallback(j=>{O(ne=>ne+j)},[]),le=a.useCallback(()=>{I(j=>!j)},[]),_e=a.useCallback(()=>{S(j=>!j)},[]),k=a.useCallback(()=>{!d||!Te.current||(q({...d}),u("filter"))},[d]),H=a.useCallback(()=>{const j=Te.current;if(!j){Ke.warning("图片未加载完成");return}ve(!0),requestAnimationFrame(()=>{try{const ne=Rc(j);ne?(g(null),p(ne),Ke.success("已检测到白边,裁剪框已自动调整")):Ke.info("未检测到明显的白边")}catch{Ke.error("检测白边失败")}finally{ve(!1)}})},[]);a.useEffect(()=>{const j=ne=>{ne.target instanceof HTMLInputElement||ne.target instanceof HTMLTextAreaElement||(ne.key==="Enter"&&m==="crop"&&d&&(ne.preventDefault(),k()),(ne.ctrlKey||ne.metaKey)&&ne.key==="z"&&!ne.shiftKey&&(ne.preventDefault(),Be()),(ne.ctrlKey||ne.metaKey)&&(ne.key==="y"||ne.key==="z"&&ne.shiftKey)&&(ne.preventDefault(),Ge()))};return window.addEventListener("keydown",j),()=>window.removeEventListener("keydown",j)},[m,d,k,Be,Ge]);const F=a.useCallback(()=>{ee(j=>Math.min(j+B,Q))},[]),Z=a.useCallback(()=>{ee(j=>Math.max(j-B,X))},[]),oe=a.useCallback(()=>{ee(1),E({x:0,y:0})},[]),te=a.useCallback(j=>{j.preventDefault();const ne=Math.abs(j.deltaY);let we;ne>50?we=j.deltaY>0?-.15:.15:we=-j.deltaY*.008,ee(Oe=>Math.max(X,Math.min(Q,Oe+we)))},[]);a.useEffect(()=>{const j=Ye.current;if(j)return j.addEventListener("wheel",te,{passive:!1}),()=>j.removeEventListener("wheel",te)},[te]);const Pe=a.useCallback(j=>{j==="crop"&&ae&&!d&&p({...ae}),u(j)},[ae,d]),Ce=a.useCallback(j=>{m!=="crop"&&($(!0),fe({x:j.clientX-_.x,y:j.clientY-_.y}))},[m,_]),Ae=a.useCallback(j=>{M&&E({x:j.clientX-re.x,y:j.clientY-re.y})},[M,re]),qe=a.useCallback(()=>{$(!1)},[]);a.useEffect(()=>{if(!M)return;const j=we=>{E({x:we.clientX-re.x,y:we.clientY-re.y})},ne=()=>{$(!1)};return document.addEventListener("mousemove",j),document.addEventListener("mouseup",ne),()=>{document.removeEventListener("mousemove",j),document.removeEventListener("mouseup",ne)}},[M,re]),a.useEffect(()=>{ee(1),E({x:0,y:0})},[m]),a.useImperativeHandle(l,()=>({reset:w,save:V,hasChanges:L,getState:ze,setState:De}));const et=Ie(),Ve=he();return s.jsxs("div",{className:`image-editor-core ${c||""}`,children:[s.jsxs("div",{className:"image-editor-core__header",children:[s.jsx("div",{className:"image-editor-core__title",children:"编辑图片"}),s.jsxs("div",{className:"image-editor-core__actions",children:[s.jsx(je,{content:"撤销 (Ctrl+Z)",theme:"light",placement:"bottom",zIndex:pt,children:s.jsx("button",{type:"button",className:`image-editor-core__btn ${Qe?"":"disabled"}`,onClick:Be,disabled:!Qe,children:s.jsx(ni,{size:18})})}),s.jsx(je,{content:"重做 (Ctrl+Y)",theme:"light",placement:"bottom",zIndex:pt,children:s.jsx("button",{type:"button",className:`image-editor-core__btn ${Ne?"":"disabled"}`,onClick:Ge,disabled:!Ne,children:s.jsx(si,{size:18})})}),s.jsx("div",{className:"image-editor-core__divider"}),s.jsx(je,{content:"对比原图(按住查看)",theme:"light",placement:"bottom",zIndex:pt,children:s.jsx("button",{type:"button",className:`image-editor-core__btn ${xe?"active":""}`,onMouseDown:()=>pe(!0),onMouseUp:()=>pe(!1),onMouseLeave:()=>pe(!1),children:s.jsx(ri,{size:18})})}),s.jsx(je,{content:"重置",theme:"light",placement:"bottom",zIndex:pt,children:s.jsx("button",{type:"button",className:"image-editor-core__btn",onClick:w,children:s.jsx(Kt,{size:18})})}),i&&s.jsx(je,{content:"取消",theme:"light",placement:"bottom",zIndex:pt,children:s.jsx("button",{type:"button",className:"image-editor-core__btn",onClick:i,children:s.jsx(Mt,{size:18})})}),(o||n||r)&&s.jsx(je,{content:"保存",theme:"light",placement:"bottom",zIndex:pt,children:s.jsx("button",{type:"button",className:"image-editor-core__btn image-editor-core__btn--primary",onClick:V,children:s.jsx(gn,{size:18})})})]})]}),s.jsxs("div",{className:"image-editor-core__main",children:[s.jsxs("div",{className:"image-editor-core__sidebar",children:[s.jsxs("div",{className:"image-editor-core__mode-tabs",children:[s.jsxs("button",{type:"button",className:`image-editor-core__mode-tab ${m==="crop"?"active":""}`,onClick:()=>Pe("crop"),children:[s.jsx(oi,{size:16}),s.jsx("span",{children:"裁剪"})]}),s.jsxs("button",{type:"button",className:`image-editor-core__mode-tab ${m==="filter"?"active":""}`,onClick:()=>Pe("filter"),children:[s.jsx(ii,{size:16}),s.jsx("span",{children:"滤镜"})]})]}),s.jsx("div",{className:"image-editor-core__panel",children:m==="crop"?s.jsx(Pc,{aspectRatio:h,presets:Ec,onAspectRatioChange:D,rotation:N,flipH:T,flipV:b,onRotate:Y,onFlipH:le,onFlipV:_e,onConfirmCrop:k,hasCropArea:!!d,onAutoTrimWhitespace:H,isDetectingWhitespace:ce}):s.jsx(Ac,{filterType:y,filterParams:x,presets:Os,imageUrl:t,onPresetSelect:W,onParamChange:G})})]}),s.jsxs("div",{className:"image-editor-core__preview",ref:Ye,onMouseDown:Ce,onMouseMove:Ae,onMouseUp:qe,onMouseLeave:qe,style:{cursor:M?"grabbing":"grab"},children:[s.jsx("div",{className:"image-editor-core__canvas-wrapper",style:{transform:`translate(${_.x}px, ${_.y}px)`},children:xe?ae?(()=>{const j=ae.y/C.height*100,ne=(C.width-ae.x-ae.width)/C.width*100,we=(C.height-ae.y-ae.height)/C.height*100,Oe=ae.x/C.width*100;return s.jsx("div",{className:"image-editor-core__filter-preview",style:{transform:`${Ve} scale(${U*J})`.trim(),clipPath:`inset(${j}% ${ne}% ${we}% ${Oe}%)`},children:s.jsx("img",{src:t,alt:"Original",draggable:!1})})})():s.jsx("div",{className:"image-editor-core__filter-preview",style:{transform:`${Ve} scale(${U*J})`.trim()},children:s.jsx("img",{src:t,alt:"Original",draggable:!1})}):m==="crop"?s.jsx(zc,{imageUrl:t,imageSize:C,cropArea:d,aspectRatio:h,rotation:N,displayScale:U,flipH:T,flipV:b,zoom:J,filterCSS:et,onCropChange:p},t):ae?(()=>{const j=ae.y/C.height*100,ne=(C.width-ae.x-ae.width)/C.width*100,we=(C.height-ae.y-ae.height)/C.height*100,Oe=ae.x/C.width*100;return s.jsx("div",{className:"image-editor-core__filter-preview",style:{filter:et,transform:`${Ve} scale(${U*J})`.trim(),clipPath:`inset(${j}% ${ne}% ${we}% ${Oe}%)`},children:s.jsx("img",{src:t,alt:"Preview",draggable:!1})})})():s.jsx("div",{className:"image-editor-core__filter-preview",style:{filter:et,transform:`${Ve} scale(${U*J})`.trim()},children:s.jsx("img",{src:t,alt:"Preview",draggable:!1})})}),s.jsxs("div",{className:"image-editor-core__zoom-controls",children:[s.jsx(je,{content:"缩小",theme:"light",placement:"top",zIndex:pt,children:s.jsx("button",{type:"button",className:"image-editor-core__zoom-btn",onClick:Z,disabled:J<=X,children:s.jsx(dr,{size:16})})}),s.jsxs("span",{className:"image-editor-core__zoom-value",children:[Math.round(J*100),"%"]}),s.jsx(je,{content:"放大",theme:"light",placement:"top",zIndex:pt,children:s.jsx("button",{type:"button",className:"image-editor-core__zoom-btn",onClick:F,disabled:J>=Q,children:s.jsx(ur,{size:16})})}),s.jsx(je,{content:"重置视图",theme:"light",placement:"top",zIndex:pt,children:s.jsx("button",{type:"button",className:"image-editor-core__zoom-btn",onClick:oe,children:s.jsx(xr,{size:16})})})]})]})]}),K&&ie&&s.jsxs("div",{className:"image-editor-core__save-dialog",children:[s.jsx("div",{className:"image-editor-core__save-dialog-backdrop",onClick:()=>de(!1)}),s.jsxs("div",{className:"image-editor-core__save-dialog-content",children:[s.jsx("h3",{className:"image-editor-core__save-dialog-title",children:"保存图片"}),s.jsxs("div",{className:"image-editor-core__save-options",children:[e&&n&&s.jsxs("button",{type:"button",className:"image-editor-core__save-option",onClick:()=>v("overwrite"),children:[s.jsx(ai,{size:20}),s.jsxs("div",{className:"image-editor-core__save-option-content",children:[s.jsx("span",{className:"image-editor-core__save-option-label",children:"覆盖原图"}),s.jsx("span",{className:"image-editor-core__save-option-desc",children:"替换画布中的原图片"})]})]}),r&&s.jsxs("button",{type:"button",className:"image-editor-core__save-option",onClick:()=>v("insert"),children:[s.jsx(ci,{size:20}),s.jsxs("div",{className:"image-editor-core__save-option-content",children:[s.jsx("span",{className:"image-editor-core__save-option-label",children:"插入新图片"}),s.jsx("span",{className:"image-editor-core__save-option-desc",children:"在画布中插入编辑后的图片"})]})]}),s.jsxs("button",{type:"button",className:"image-editor-core__save-option",onClick:()=>v("download"),children:[s.jsx(gr,{size:20}),s.jsxs("div",{className:"image-editor-core__save-option-content",children:[s.jsx("span",{className:"image-editor-core__save-option-label",children:"下载到本地"}),s.jsx("span",{className:"image-editor-core__save-option-desc",children:"保存编辑后的图片到本地"})]})]})]}),s.jsx("button",{type:"button",className:"image-editor-core__save-cancel",onClick:()=>de(!1),children:"取消"})]})]})]})});to.displayName="ImageEditorCore";const zc=({imageUrl:t,imageSize:e,cropArea:n,aspectRatio:r,rotation:i,flipH:o,flipV:c,zoom:l,displayScale:m,filterCSS:u,onCropChange:d})=>{const p=a.useRef(null),[h,g]=a.useState(!1),[y,f]=a.useState(null),[x,z]=a.useState(null),[N,O]=a.useState({x:0,y:0}),[T,I]=a.useState(null);a.useEffect(()=>{if(!n&&e.width>0){let P;if(r)if(e.width/e.height>r){const ee=e.height,X=ee*r;P={x:(e.width-X)/2,y:0,width:X,height:ee}}else{const ee=e.width,X=ee/r;P={x:0,y:(e.height-X)/2,width:ee,height:X}}else P={x:0,y:0,width:e.width,height:e.height};d(P)}},[r,e,n,d]);const b=a.useCallback((P,J,ee)=>{P.preventDefault(),P.stopPropagation(),g(!0),f(J),z(ee||null),O({x:P.clientX,y:P.clientY}),I(n)},[n]);a.useEffect(()=>{if(!h||!T)return;const P=ee=>{let X=(ee.clientX-N.x)/(m*l),Q=(ee.clientY-N.y)/(m*l);const B=(i%360+360)%360;let _,E;switch(B){case 90:_=Q,E=-X;break;case 180:_=-X,E=-Q;break;case 270:_=-Q,E=X;break;default:_=X,E=Q}o&&(_=-_),c&&(E=-E);const M={...T};if(y==="move")M.x=Math.max(0,Math.min(T.x+_,e.width-T.width)),M.y=Math.max(0,Math.min(T.y+E,e.height-T.height));else if(y==="resize"&&x){switch(x){case"nw":M.x=Math.min(T.x+_,T.x+T.width-20),M.y=Math.min(T.y+E,T.y+T.height-20),M.width=Math.max(20,T.width-_),M.height=Math.max(20,T.height-E);break;case"ne":M.y=Math.min(T.y+E,T.y+T.height-20),M.width=Math.max(20,T.width+_),M.height=Math.max(20,T.height-E);break;case"sw":M.x=Math.min(T.x+_,T.x+T.width-20),M.width=Math.max(20,T.width-_),M.height=Math.max(20,T.height+E);break;case"se":M.width=Math.max(20,T.width+_),M.height=Math.max(20,T.height+E);break;case"n":M.y=Math.min(T.y+E,T.y+T.height-20),M.height=Math.max(20,T.height-E);break;case"s":M.height=Math.max(20,T.height+E);break;case"w":M.x=Math.min(T.x+_,T.x+T.width-20),M.width=Math.max(20,T.width-_);break;case"e":M.width=Math.max(20,T.width+_);break}if(r&&(["e","w","ne","nw","se","sw"].includes(x)?M.height=M.width/r:["n","s"].includes(x)&&(M.width=M.height*r)),M.x<0&&(M.width+=M.x,M.x=0),M.y<0&&(M.height+=M.y,M.y=0),M.width=Math.min(M.width,e.width-M.x),M.height=Math.min(M.height,e.height-M.y),M.width=Math.max(20,M.width),M.height=Math.max(20,M.height),r){const re=M.height*r,fe=M.width/r;M.width>re?M.width=re:M.height>fe&&(M.height=fe)}}d(M)},J=()=>{g(!1),f(null),z(null)};return document.addEventListener("mousemove",P),document.addEventListener("mouseup",J),()=>{document.removeEventListener("mousemove",P),document.removeEventListener("mouseup",J)}},[h,y,x,N,T,m,l,i,o,c,e,r,d]);const S=e.width*m*l,C=e.height*m*l,R={transform:`rotate(${i}deg) ${o?"scaleX(-1)":""} ${c?"scaleY(-1)":""}`.trim()},U=P=>{const J={nw:"nw-resize",ne:"ne-resize",sw:"sw-resize",se:"se-resize",n:"n-resize",s:"s-resize",w:"w-resize",e:"e-resize"},ee={nw:"ne",ne:"se",se:"sw",sw:"nw",n:"e",e:"s",s:"w",w:"n"};let X=P;const Q=(i%360+360)%360,B=Math.round(Q/90)%4;for(let _=0;_<B;_++)X=ee[X]||X;return o&&(X.includes("w")?X=X.replace("w","e"):X.includes("e")&&(X=X.replace("e","w"))),c&&(X.includes("n")?X=X.replace("n","s"):X.includes("s")&&(X=X.replace("s","n"))),J[X]||"pointer"};return s.jsx("div",{ref:p,className:"crop-canvas",children:s.jsxs("div",{className:"crop-canvas__image-container",style:{width:S,height:C,...R},children:[s.jsx("img",{src:t,alt:"Crop",draggable:!1,style:{filter:u||"none"}}),n&&s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"crop-canvas__overlay"}),s.jsxs("div",{className:"crop-canvas__crop-area",style:{left:n.x*m*l,top:n.y*m*l,width:n.width*m*l,height:n.height*m*l},onMouseDown:P=>b(P,"move"),children:[s.jsx("div",{className:"crop-canvas__crop-image",style:{backgroundImage:`url(${t})`,backgroundPosition:`-${n.x*m*l}px -${n.y*m*l}px`,backgroundSize:`${S}px ${C}px`,filter:u||"none"}}),s.jsxs("div",{className:"crop-canvas__grid",children:[s.jsx("div",{className:"crop-canvas__grid-line crop-canvas__grid-line--h1"}),s.jsx("div",{className:"crop-canvas__grid-line crop-canvas__grid-line--h2"}),s.jsx("div",{className:"crop-canvas__grid-line crop-canvas__grid-line--v1"}),s.jsx("div",{className:"crop-canvas__grid-line crop-canvas__grid-line--v2"})]}),s.jsx("div",{className:"crop-canvas__handle crop-canvas__handle--nw",style:{cursor:U("nw")},onMouseDown:P=>b(P,"resize","nw")}),s.jsx("div",{className:"crop-canvas__handle crop-canvas__handle--ne",style:{cursor:U("ne")},onMouseDown:P=>b(P,"resize","ne")}),s.jsx("div",{className:"crop-canvas__handle crop-canvas__handle--sw",style:{cursor:U("sw")},onMouseDown:P=>b(P,"resize","sw")}),s.jsx("div",{className:"crop-canvas__handle crop-canvas__handle--se",style:{cursor:U("se")},onMouseDown:P=>b(P,"resize","se")}),s.jsx("div",{className:"crop-canvas__handle crop-canvas__handle--n",style:{cursor:U("n")},onMouseDown:P=>b(P,"resize","n")}),s.jsx("div",{className:"crop-canvas__handle crop-canvas__handle--s",style:{cursor:U("s")},onMouseDown:P=>b(P,"resize","s")}),s.jsx("div",{className:"crop-canvas__handle crop-canvas__handle--w",style:{cursor:U("w")},onMouseDown:P=>b(P,"resize","w")}),s.jsx("div",{className:"crop-canvas__handle crop-canvas__handle--e",style:{cursor:U("e")},onMouseDown:P=>b(P,"resize","e")})]})]})]})})},no=a.forwardRef(({imageUrl:t,showOverwrite:e=!1,onOverwrite:n,onInsert:r},i)=>s.jsx(to,{ref:i,imageUrl:t,showOverwrite:e,onOverwrite:n,onInsert:r,className:"embedded-editor"}));no.displayName="ImageEditorContent";const mn=({visible:t,items:e,initialMode:n="single",initialIndex:r=0,onClose:i,onModeChange:o,showThumbnails:c=!0,maxCompareSlots:l=4,defaultCompareLayout:m="horizontal",className:u="",showTitle:d=!0,videoAutoPlay:p=!1,videoLoop:h=!0,onInsertToCanvas:g,onEdit:y,useBuiltInEditor:f=!1,onEditOverwrite:x,onEditInsert:z,showEditOverwrite:N=!1})=>{const O=a.useRef(null),T=a.useRef(null),[I,b]=a.useState(2),[S,C]=a.useState(!1),[R,U]=a.useState(null),P=a.useRef(null),J=a.useRef(new Map),ee=a.useRef([]),X=a.useRef(null),Q=a.useRef(!1),[B,_]=ic({items:e,initialMode:n,initialIndex:r,maxCompareSlots:l,defaultCompareLayout:m,visible:t,onModeChange:o}),{mode:E,currentIndex:M,compareIndices:$,compareLayout:re,syncMode:fe,zoomLevel:K,panOffset:de,focusedSlot:ie}=B,ue=a.useCallback(v=>{P.current=v,U(v)},[]);a.useEffect(()=>{t||(J.current.clear(),ue(null))},[t,ue]);const xe=a.useCallback(()=>{if(e.length<=I)return;const D=Math.max(...$)+1;if(D>=e.length){const W=[];for(let G=0;G<I&&G<e.length;G++)W.push(G);W.forEach((G,Y)=>_.addToCompare(G,Y))}else{const W=[];for(let G=0;G<I;G++){const Y=(D+G)%e.length;W.push(Y)}W.forEach((G,Y)=>_.addToCompare(G,Y))}},[e.length,I,$,_]),pe=a.useCallback(()=>{if(e.length<=I)return;const D=Math.min(...$)-I;if(D<0){const W=Math.max(0,e.length-I),G=[];for(let Y=0;Y<I&&W+Y<e.length;Y++)G.push(W+Y);G.forEach((Y,le)=>_.addToCompare(Y,le))}else{const W=[];for(let G=0;G<I;G++)W.push(D+G);W.forEach((G,Y)=>_.addToCompare(G,Y))}},[e.length,I,$,_]),ae=a.useCallback(v=>{const D=e[v];if(!D||D.type!=="image")return!1;const W=P.current;if(W&&T.current){const G=T.current.getState();J.current.set(W.url,G)}return _.goTo(v),ue(D),setTimeout(()=>{const G=J.current.get(D.url);G&&T.current&&T.current.setState(G)},50),!0},[e,_,ue]),q=a.useCallback(()=>{_.resetView(),ee.current.forEach(v=>{v!=null&&v.isVideo()&&v.resetVideo()})},[_]);a.useEffect(()=>{if(!t)return;const v=D=>{const W=D.target instanceof HTMLElement?D.target:null;if(W instanceof HTMLInputElement||W instanceof HTMLTextAreaElement||W instanceof HTMLSelectElement||W instanceof HTMLButtonElement||W!=null&&W.isContentEditable)return;const G=E==="single"?X.current:ee.current[ie]||null;switch(D.key){case"Escape":D.preventDefault(),i();break;case"ArrowLeft":case"ArrowUp":if(D.preventDefault(),E==="edit"){const Y=(M-1+e.length)%e.length;ae(Y)}else E==="single"?_.goToPrev():pe();break;case"ArrowRight":case"ArrowDown":if(D.preventDefault(),E==="edit"){const Y=(M+1)%e.length;ae(Y)}else E==="single"?_.goToNext():xe();break;case"c":case"C":e.length>1&&(D.preventDefault(),_.setMode(E==="single"?"compare":"single"));break;case"1":case"2":case"3":case"4":if(E==="compare"){const Y=parseInt(D.key,10)-1;Y<I&&(D.preventDefault(),_.setFocusedSlot(Y))}break;case"+":case"=":D.preventDefault(),_.zoom(.25);break;case"-":case"_":D.preventDefault(),_.zoom(-.25);break;case"0":D.preventDefault(),E==="compare"?q():_.resetView();break;case" ":case"Spacebar":G!=null&&G.isVideo()&&(D.preventDefault(),G.toggleVideoPlayback());break;case"s":case"S":E==="compare"&&(D.preventDefault(),_.toggleSyncMode());break}};return window.addEventListener("keydown",v),()=>window.removeEventListener("keydown",v)},[t,E,e.length,e,M,ie,_,i,I,xe,pe,ae,q]);const ce=a.useCallback(()=>{if(O.current)if(S){const v=di();v==null||v.catch(()=>{})}else{const v=li(O.current);v==null||v.catch(()=>{})}},[S]);a.useEffect(()=>{const v=()=>{C(!!document.fullscreenElement)};return document.addEventListener("fullscreenchange",v),()=>document.removeEventListener("fullscreenchange",v)},[]);const ve=a.useCallback(v=>{v.target===v.currentTarget&&i()},[i]),me=a.useCallback(v=>{E==="edit"?ae(v):E==="single"?_.goTo(v):_.addToCompare(v,ie)},[E,_,ie,ae]),Re=a.useCallback(v=>{b(v),_.setSlotCount(v)},[_]),Me=a.useCallback((v,D)=>v==="grid"?D<=2?"layout-horizontal":"layout-grid":`layout-${v}`,[]),We=a.useCallback(()=>{const v=e[M];v&&g&&g(v)},[e,M,g]),Ee=a.useCallback(async()=>{const v=e[M];if(!v)return;const D=v.type==="image"?ut(v.url):v.url;if(D.startsWith("blob:")){const{unifiedCacheService:Y}=await dt(async()=>{const{unifiedCacheService:H}=await import("./startup-app-eD_rQhSh.js").then(F=>F.nQ);return{unifiedCacheService:H}},__vite__mapDeps([0]),import.meta.url),{downloadFromBlob:le}=await dt(async()=>{const{downloadFromBlob:H}=await import("./startup-app-eD_rQhSh.js").then(F=>F.nO);return{downloadFromBlob:H}},__vite__mapDeps([0]),import.meta.url),_e=D.indexOf("#"),k=_e>0?D.substring(_e+1):null;if(k&&k.startsWith("merged-video-")){const H=await Y.getCachedBlob(k);if(H){const F=H.type||"video/webm",Z=F.startsWith("video/mp4")?"mp4":F.startsWith("video/webm")?"webm":"bin";le(H,`merged-video-${Date.now()}.${Z}`);return}}try{const F=await(await fetch(D)).blob(),Z=F.type.startsWith("video/mp4")?"mp4":F.type.startsWith("video/webm")?"webm":F.type.startsWith("audio/mpeg")?"mp3":F.type.startsWith("audio/wav")?"wav":F.type.startsWith("audio/")?"m4a":F.type.startsWith("image/")?"png":"bin";le(F,`${v.type}_${Date.now()}.${Z}`)}catch(H){console.error("[UnifiedMediaViewer] Failed to fetch blob URL:",H)}return}const{smartDownload:W,buildDownloadFilename:G}=await dt(async()=>{const{smartDownload:Y,buildDownloadFilename:le}=await import("./startup-app-eD_rQhSh.js").then(_e=>_e.o0);return{smartDownload:Y,buildDownloadFilename:le}},__vite__mapDeps([0]),import.meta.url);await W([{url:D,type:v.type,filename:v.type==="audio"?G(v.title,"audio","mp3"):void 0,audioMetadata:v.type==="audio"?{title:v.title,prompt:v.prompt,tags:v.tags,coverUrl:v.posterUrl,artist:v.artist,album:v.album}:void 0}])},[e,M]),Te=a.useCallback(()=>{const v=e[M];v&&v.type==="image"&&(f?(ue(v),_.setMode("edit")):y&&y(v))},[e,M,y,f,_,ue]),Ye=a.useCallback(v=>{if(v==="edit"){const D=e[M];D&&D.type==="image"&&ue(D)}_.setMode(v)},[e,M,_,ue]),$e=a.useCallback(()=>{J.current.clear(),ue(null),_.setMode("single")},[_,ue]),be=a.useCallback(()=>{var v;(v=T.current)==null||v.reset()},[]),Ie=a.useCallback(()=>{var v;(v=T.current)==null||v.save()},[]),he=a.useCallback(v=>{const D=P.current;x&&D&&x(v,D),$e()},[x,$e]),ze=a.useCallback(v=>{z&&z(v),$e()},[z,$e]),De=a.useCallback((v,D)=>{ee.current[v]=D},[]),He=a.useCallback((v,D)=>{Q.current||(Q.current=!0,ee.current.forEach((W,G)=>{G!==v&&(W!=null&&W.isVideo())&&(D?W.playVideo():W.pauseVideo())}),setTimeout(()=>{Q.current=!1},50))},[]),Be=a.useCallback((v,D)=>{Q.current||(Q.current=!0,ee.current.forEach((W,G)=>{G!==v&&(W!=null&&W.isVideo())&&W.setVideoTime(D)}),setTimeout(()=>{Q.current=!1},50))},[]),Ge=()=>{const v=e[M]||null;return s.jsxs("div",{className:"unified-viewer__single",children:[e.length>1&&s.jsx("button",{className:"unified-viewer__nav unified-viewer__nav--prev",onClick:_.goToPrev,"aria-label":"上一个",children:s.jsx(cn,{size:32})}),s.jsx(On,{ref:X,item:v,zoomLevel:K,panOffset:de,videoAutoPlay:p,videoLoop:h,onZoomChange:_.setZoomLevel,onPanChange:()=>{},onInsertToCanvas:g?We:void 0,onDownload:Ee,onEdit:y?Te:void 0}),e.length>1&&s.jsx("button",{className:"unified-viewer__nav unified-viewer__nav--next",onClick:_.goToNext,"aria-label":"下一个",children:s.jsx(ui,{size:32})})]})},Qe=()=>{const v=Me(re,I);return s.jsx("div",{className:`unified-viewer__compare ${v}`,children:Array.from({length:I}).map((D,W)=>{const G=$[W],Y=typeof G=="number"?e[G]:null;return s.jsx(On,{ref:le=>De(W,le),item:Y,slotIndex:W,isFocused:ie===W,zoomLevel:fe?K:void 0,panOffset:fe?de:void 0,onClick:()=>_.setFocusedSlot(W),onClose:I>2?()=>_.removeFromCompare(W):void 0,videoAutoPlay:p,videoLoop:h,onZoomChange:fe?_.setZoomLevel:void 0,onPanChange:fe?_.setPan:void 0,isCompareMode:!0,isSyncMode:fe,onVideoPlayStateChange:fe?le=>He(W,le):void 0,onVideoTimeUpdate:fe?le=>Be(W,le):void 0},W)})})},Ne=()=>{const v=R||e[M];return!v||v.type!=="image"?null:s.jsx("div",{className:"unified-viewer__edit",children:s.jsx(no,{ref:T,imageUrl:v.url,showOverwrite:N,onOverwrite:x?he:void 0,onInsert:z?ze:void 0})})},L=e[M]||null;if(!t||e.length===0)return null;const w=()=>{switch(E){case"edit":return Ne();case"compare":return Qe();default:return Ge()}},V=s.jsx("div",{ref:O,className:`unified-viewer ${u} ${S?"unified-viewer--fullscreen":""} ${E==="edit"?"unified-viewer--edit-mode":""}`,onClick:ve,children:s.jsxs("div",{className:"unified-viewer__container",children:[s.jsx(Nc,{mode:E,currentIndex:M,totalCount:e.length,slotCount:I,compareLayout:re,syncMode:fe,onModeChange:Ye,onSlotCountChange:Re,onLayoutChange:_.setCompareLayout,onSyncToggle:_.toggleSyncMode,onResetView:E==="compare"?q:_.resetView,onClose:i,onFullscreen:ce,isImage:(L==null?void 0:L.type)==="image",showEditButton:f||!!y,onBackToPreview:$e,onResetEdit:be,onSaveEdit:Ie}),s.jsx("div",{className:"unified-viewer__content",children:w()}),c&&e.length>1&&s.jsx(Tc,{items:e,mode:E==="edit"?"single":E,currentIndex:M,compareIndices:$,onThumbnailClick:me})]})});return Rt.createPortal(V,document.body)},im=Object.freeze(Object.defineProperty({__proto__:null,UnifiedMediaViewer:mn,default:mn},Symbol.toStringTag,{value:"Module"})),Dc=qn.DIALOG_AI_IMAGE;class Et{constructor(){this.windows=new Map,this.counter=0}static getInstance(){return Et.instance||(Et.instance=new Et),Et.instance}register(e,n){const r=this.windows.get(e);r?(r.element=n,r.activationOrder=++this.counter):this.windows.set(e,{windowId:e,activationOrder:++this.counter,element:n}),this.applyAllZIndexes()}unregister(e){this.windows.delete(e)&&this.applyAllZIndexes()}bringToFront(e){const n=this.windows.get(e);n&&(this.isTopWindow(e)||(n.activationOrder=++this.counter,this.applyAllZIndexes()))}updateElement(e,n){const r=this.windows.get(e);r&&(r.element=n,this.applyZIndex(r,this.getPositionIndex(e)))}getTopWindowId(){let e=null,n=-1;return this.windows.forEach(r=>{r.activationOrder>n&&(n=r.activationOrder,e=r.windowId)}),e}isTopWindow(e){return this.getTopWindowId()===e}getPositionIndex(e){return this.getSortedEntries().findIndex(r=>r.windowId===e)}getSortedEntries(){return Array.from(this.windows.values()).sort((e,n)=>e.activationOrder-n.activationOrder)}applyAllZIndexes(){this.getSortedEntries().forEach((n,r)=>{this.applyZIndex(n,r)})}applyZIndex(e,n){!e.element||n<0||e.element.style.setProperty("--aitu-winbox-z-index",String(Dc+n))}}const vt=Et.getInstance();let nt=null,nn=null;const Lc=async()=>nt||(typeof window<"u"&&window.WinBox?(nt=window.WinBox,nt):nn||(nn=(async()=>{try{if(await dt(()=>import("./winbox.bundle.min-CoRPjCs5.js"),[],import.meta.url),nt=window.WinBox,nt)return nt;throw new Error("WinBox not found after import")}catch(t){return console.warn("Dynamic import failed, falling back to CDN:",t),new Promise((e,n)=>{const r=document.createElement("script");r.src="https://cdn.jsdelivr.net/npm/winbox@0.2.82/dist/winbox.bundle.min.js",r.async=!0,r.onload=()=>{nt=window.WinBox,nt?e(nt):n(new Error("WinBox not found after CDN loading"))},r.onerror=n,document.head.appendChild(r)})}})(),nn)),$c=({visible:t,title:e,icon:n,onClose:r,children:i,width:o="80%",height:c="80%",minWidth:l=400,minHeight:m=300,x:u="center",y:d="center",maximizable:p=!0,minimizable:h=!0,resizable:g=!0,movable:y=!0,modal:f=!1,background:x="linear-gradient(135deg, #5A4FCF 0%, #7B68EE 50%, #E91E63 100%)",border:z=0,className:N,id:O,headerContent:T,container:I,onMaximize:b,onMinimize:S,onRestore:C,onFocus:R,onBlur:U,onMove:P,onResize:J,autoMaximize:ee=!1,minVisiblePixels:X=50,onInsertToCanvas:Q,keepAlive:B=!1,minimizeTargetSelector:_,onActivate:E})=>{var _e;const M=a.useRef(O||`winbox-${_r()}`),$=a.useRef(null),re=a.useRef(null),fe=a.useRef(r),K=a.useRef(E),de=a.useRef(!0),ie=a.useRef(!1),ue=a.useRef(null),xe=a.useRef([]);fe.current=r,K.current=E;const pe=a.useRef(null),ae=a.useRef(!1),[q,ce]=a.useState(null),[ve,me]=a.useState(null),[Re,Me]=a.useState(null),[We,Ee]=a.useState(!1),[Te,Ye]=a.useState(!!nt),[$e,be]=a.useState(null),Ie=a.useRef(null),he=a.useRef(null),ze=a.useCallback(()=>{xe.current.forEach(k=>{window.clearTimeout(k)}),xe.current=[]},[]),De=a.useCallback((k,H)=>{const F=window.setTimeout(()=>{xe.current=xe.current.filter(Z=>Z!==F),k()},H);return xe.current.push(F),F},[]),He=a.useCallback(()=>{de.current&&(ce(null),me(null),Me(null),Ee(!1))},[]),Be=a.useCallback((k,H=!0)=>{if(k){ze(),H&&(k.onclose=null);try{k.close(!0)}catch{}}},[ze]),Ge=a.useCallback(()=>{const k=ue.current;k&&(ue.current=null,Be(k))},[Be]),Qe=a.useCallback(k=>{if(k){ze(),ue.current=k;try{k.hide()}catch{}De(()=>{ie.current=!1,Ge()},800)}},[ze,Ge,De]),Ne=a.useCallback(k=>{be(k),Ie.current=k,k===null&&he.current!==null&&$.current&&($.current.minwidth=he.current,he.current=null)},[]),L=a.useCallback(()=>{const k={left:!1,right:!1};if(typeof window>"u"||!window.WinBox)return k;const F=window.WinBox.stack(),Z=window.innerWidth;return F.forEach(oe=>{if(oe===$.current)return;Math.abs(oe.width-Z/2)<20&&(oe.x<20&&(k.left=!0),Math.abs(oe.x+oe.width-Z)<20&&(k.right=!0))}),k},[]),w=a.useCallback(k=>{if(!k||!k.window)return;const H=window.innerWidth,F=window.innerHeight;he.current!==null&&(k.minwidth=he.current,he.current=null),k.left=0,k.right=0,k.top=0,k.bottom=0;let Z,oe;typeof o=="string"&&o.endsWith("%")?Z=Math.floor(H*parseInt(o)/100):Z=typeof o=="number"?o:Math.floor(H*.8),typeof c=="string"&&c.endsWith("%")?oe=Math.floor(F*parseInt(c)/100):oe=typeof c=="number"?c:Math.floor(F*.8),Z=Math.max(Z,l),oe=Math.max(oe,m);const te=Math.floor((H-Z)/2),Pe=Math.floor((F-oe)/2);k.resize(Z,oe).move(te,Pe),Ne(null)},[o,c,l,m,Ne]),V=a.useCallback((k,H,F,Z,oe)=>{!k||!k.window||(k.left=0,k.right=0,k.top=0,k.bottom=0,H==="left"?(k.resize(F,oe).move(0,0),Ne("left")):(k.resize(F,oe).move(Z-F,0),Ne("right")))},[Ne]),v=a.useCallback(()=>{const k=$.current,H=Ie.current;if(!k||!k.window)return;const F=window.innerWidth,Z=window.innerHeight,oe=L(),te=Math.floor(F/2),Pe=Ae=>{he.current===null&&(he.current=k.minwidth),k.minwidth=Math.min(200,te),k.max?(k.restore(),requestAnimationFrame(()=>{!k||!k.window||V(k,Ae,te,F,Z)})):V(k,Ae,te,F,Z)},Ce=()=>{k.max?(k.restore(),requestAnimationFrame(()=>{!k||!k.window||w(k)})):w(k)};if(H==="left"){Ce();return}if(H==="right"){oe.left?Ce():Pe("left");return}oe.right&&!oe.left?Pe("left"):Pe("right")},[L,w,V]),D=mi(re,{enablePositionTracking:!1,enableScaleCompensation:!$e&&!((_e=$.current)!=null&&_e.max)});a.useEffect(()=>{Te||Lc().then(()=>Ye(!0))},[Te]),a.useEffect(()=>(de.current=!0,()=>{de.current=!1}),[]);const W=a.useRef(!1),G=a.useCallback(()=>{var k;return vt.unregister(M.current),(k=fe.current)==null||k.call(fe),!1},[]),Y=a.useCallback(()=>{var k;vt.bringToFront(M.current),(k=K.current)==null||k.call(K)},[]);a.useEffect(()=>{if(!(!Te||!nt)){if(!t){if($.current)if(vt.unregister(M.current),ze(),B)try{$.current.hide()}catch{}else{const k=$.current;ie.current?Qe(k):Be(k),$.current=null,re.current=null,He()}return}if(t&&$.current){$.current.show(),$.current.focus(),vt.register(M.current,$.current.window);return}if(t&&!$.current){Ge();const k=["winbox-react"];p||k.push("no-max"),h||k.push("no-min"),g||k.push("no-resize"),y||k.push("no-move"),k.push("no-full"),N&&k.push(N);const H=new nt({id:O,title:e,width:o,height:c,minwidth:l,minheight:m,x:u,y:d,modal:f,background:x,border:z,overflow:!0,class:k,root:I||document.body,onclose:G,onmaximize:b,onminimize:function(){ae.current=!0;const F=pe.current,Z=F?{x:F.x,y:F.y}:{x:this.x||0,y:this.y||0},oe=F?{width:F.width,height:F.height}:{width:this.width||800,height:this.height||600},te=this.window;if(_&&te){const Pe=document.querySelector(_);if(Pe){te.style.transition="none",te.style.transform="",te.style.opacity="1",F&&(te.style.left=`${F.x}px`,te.style.top=`${F.y}px`,te.style.width=`${F.width}px`,te.style.height=`${F.height}px`),te.offsetHeight;const Ce=te.getBoundingClientRect(),Ae=Pe.getBoundingClientRect(),qe=Ae.left+Ae.width/2,et=Ae.top+Ae.height/2,Ve=Ce.left,j=Ce.top+Ce.height/2,ne=qe-Ve,we=et-j,Oe=Math.min(Ae.width/Ce.width,Ae.height/Ce.height,.06);te.style.transformOrigin="left center";const Ze=te.parentElement;Ze&&(Ze.style.perspective="1000px",Ze.style.perspectiveOrigin="left center"),te.offsetHeight;const A=400;return te.style.transition=`transform ${A}ms cubic-bezier(0.4, 0, 0.2, 1), opacity ${A}ms ease-out`,te.style.transform=`translate(${ne}px, ${we}px) scale(${Oe}) rotateY(-30deg)`,te.style.opacity="0",De(()=>{te.isConnected&&(te.style.transition="none",te.style.transform="",te.style.opacity="",Ze&&(Ze.style.perspective="",Ze.style.perspectiveOrigin=""),this.hide(),S==null||S(Z,oe))},A),!0}}return this.hide(),S==null||S(Z,oe),!0},onrestore:C,onfocus:function(){R==null||R(),Y()},onblur:U,onmove:function(F,Z){if(this.max||this.min||W.current)return;const oe=window.innerWidth,te=window.innerHeight,Pe=this.width;this.height;const Ce=X;if(Ie.current){const j=Ie.current==="left"?0:oe-Pe;Math.abs(F-j)>50&&Ne(null)}let Ae=F,qe=Z;F<Ce-Pe&&(Ae=Ce-Pe),F>oe-Ce&&(Ae=oe-Ce),Z<0&&(qe=0),Z>te-Ce&&(qe=te-Ce),(Ae!==F||qe!==Z)&&(W.current=!0,this.move(Ae,qe),W.current=!1);const et=pe.current,Ve=et&&qe-et.y>200;!this.min&&!this.max&&!ae.current&&!Ve&&(pe.current={x:Ae,y:qe,width:this.width,height:this.height}),P==null||P(Ae,qe)},onresize:function(F,Z){const oe=pe.current,te=oe&&(Z<100||oe.height-Z>200);!this.min&&!this.max&&!ae.current&&!te&&(pe.current={x:this.x,y:this.y,width:F,height:Z}),J==null||J(F,Z)}});if($.current=H,H.addControl({index:0,class:"wb-split",image:"data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIyNCIgaGVpZ2h0PSIyNCIgdmlld0JveD0iMCAwIDI0IDI0IiBmaWxsPSJub25lIiBzdHJva2U9ImN1cnJlbnRDb2xvciIgc3Ryb2tlLXdpZHRoPSIyIiBzdHJva2UtbGluZWNhcD0icm91bmQiIHN0cm9rZS1saW5lam9pbj0icm91bmQiPjxyZWN0IHg9IjMiIHk9IjMiIHdpZHRoPSIxOCIgaGVpZ2h0PSIxOCIgcng9IjIiIHJ5PSIyIj48L3JlY3Q+PGxpbmUgeDE9IjEyIiB5MT0iMyIgeDI9IjEyIiB5Mj0iMjEiPjwvbGluZT48L3N2Zz4=",click:F=>{F.preventDefault(),F.stopPropagation(),v()}}),Q&&H.addControl({index:0,class:"wb-insert-canvas",image:"data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIyNCIgaGVpZ2h0PSIyNCIgdmlld0JveD0iMCAwIDI0IDI0IiBmaWxsPSJub25lIiBzdHJva2U9ImN1cnJlbnRDb2xvciIgc3Ryb2tlLXdpZHRoPSIyIiBzdHJva2UtbGluZWNhcD0icm91bmQiIHN0cm9rZS1saW5lam9pbj0icm91bmQiPjxyZWN0IHg9IjMiIHk9IjMiIHdpZHRoPSIxOCIgaGVpZ2h0PSIxOCIgcng9IjIiLz48cGF0aCBkPSJNMTIgOHY4Ii8+PHBhdGggZD0iTTggMTJoOCIvPjwvc3ZnPg==",click:F=>{F.preventDefault(),F.stopPropagation();const Z=H.window;if(Z){const oe=Z.getBoundingClientRect(),te={x:oe.left,y:oe.top,width:oe.width,height:oe.height};Q(te)}else{const oe={x:H.x||0,y:H.y||0,width:H.width||800,height:H.height||600};Q(oe)}}}),H.window){re.current=H.window,vt.register(M.current,re.current),requestAnimationFrame(()=>{D()});const F=H.window.querySelector(".wb-body");if(F&&me(F),n){const Z=H.window.querySelector(".wb-drag"),oe=H.window.querySelector(".wb-title");if(Z&&oe){const te=document.createElement("div");te.className="wb-icon-container",Z.insertBefore(te,oe),Me(te)}}}if(T&&H.window){const F=H.window.querySelector(".wb-drag");if(F){const Z=document.createElement("div");Z.className="wb-header-custom";const oe=te=>{te.stopPropagation()};Z.addEventListener("mousedown",oe,!0),Z.addEventListener("touchstart",oe,!0),Z.addEventListener("pointerdown",oe,!0),F.appendChild(Z),ce(Z)}}H&&!H.min&&!H.max&&(pe.current={x:H.x,y:H.y,width:H.width,height:H.height}),Ee(!0),ee&&De(()=>{$.current&&$.current.maximize()},100)}}},[t,Te,ee,B,ze,Be,Qe,Ge,He,De]),a.useEffect(()=>{const k=M.current;return()=>{if(vt.unregister(k),$.current){const H=$.current;ie.current?Qe(H):Be(H),$.current=null,re.current=null}ue.current||ze()}},[ze,Be,Qe]),a.useEffect(()=>{$.current&&e&&$.current.setTitle(e)},[e]),a.useEffect(()=>{var k,H;if($.current&&n&&!Re){const F=$.current,Z=(k=F.window)==null?void 0:k.querySelector(".wb-drag"),oe=(H=F.window)==null?void 0:H.querySelector(".wb-title");if(Z&&oe&&!Z.querySelector(".wb-icon-container")){const Pe=document.createElement("div");Pe.className="wb-icon-container",Z.insertBefore(Pe,oe),Me(Pe)}}},[n,Re]),a.useEffect(()=>{if($.current){const k=pe.current;if(t){const H=$.current.min||$.current.hidden;$.current.min&&($.current.restore(),k&&($.current.move(k.x,k.y),$.current.resize(k.width,k.height)),ae.current=!1),$.current.show(),$.current.focus(),vt.bringToFront(M.current),H&&_&&requestAnimationFrame(()=>{le()})}else $.current.hide()}},[t]);const le=a.useCallback(()=>{if(!_||!$.current)return;const k=$.current.window,H=document.querySelector(_);if(!k||!H)return;const F=pe.current;if(!F)return;const Z=H.getBoundingClientRect(),oe=Z.left+Z.width/2,te=Z.top+Z.height/2,Pe=F.x,Ce=F.y+F.height/2,Ae=oe-Pe,qe=te-Ce,et=Math.min(Z.width/F.width,Z.height/F.height,.06),Ve=k.parentElement;Ve&&(Ve.style.perspective="1000px",Ve.style.perspectiveOrigin="left center"),k.style.transition="none",k.style.transformOrigin="left center",k.style.transform=`translate(${Ae}px, ${qe}px) scale(${et}) rotateY(-30deg)`,k.style.opacity="0",k.offsetHeight;const j=350;k.style.transition=`transform ${j}ms cubic-bezier(0.2, 0, 0.4, 1), opacity ${j*.6}ms ease-out`,k.style.transform="",k.style.opacity="1",De(()=>{k.isConnected&&(k.style.transition="none",k.style.transform="",k.style.transformOrigin="",Ve&&(Ve.style.perspective="",Ve.style.perspectiveOrigin=""))},j)},[_,De]);return a.useEffect(()=>{const k=re.current;if(!k)return;const H=[".wb-drag",".wb-n",".wb-s",".wb-e",".wb-w",".wb-ne",".wb-nw",".wb-se",".wb-sw"].join(", "),F=oe=>{const te=oe.target;te instanceof Element&&te.closest(H)&&(ie.current=!0)},Z=()=>{!ie.current&&!ue.current||(ie.current=!1,Ge())};return k.addEventListener("mousedown",F,!0),k.addEventListener("touchstart",F,!0),window.addEventListener("mouseup",Z,!0),window.addEventListener("touchend",Z,!0),window.addEventListener("touchcancel",Z,!0),window.addEventListener("blur",Z),()=>{k.removeEventListener("mousedown",F,!0),k.removeEventListener("touchstart",F,!0),window.removeEventListener("mouseup",Z,!0),window.removeEventListener("touchend",Z,!0),window.removeEventListener("touchcancel",Z,!0),window.removeEventListener("blur",Z)}},[We,Ge]),a.useEffect(()=>{$.current&&ee&&$.current.maximize()},[ee]),a.useEffect(()=>{const k=re.current;if(!k)return;const H=()=>{Y()},F=()=>{Y()};return k.addEventListener("pointerdown",H,!0),k.addEventListener("focusin",F,!0),()=>{k.removeEventListener("pointerdown",H,!0),k.removeEventListener("focusin",F,!0)}},[We,Y]),a.useEffect(()=>{if(!$.current||!t||Ie.current)return;const k=typeof o=="number"?o:$.current.width,H=typeof c=="number"?c:$.current.height;typeof k!="number"||typeof H!="number"||$.current.width===k&&$.current.height===H&&$.current.minwidth===l&&$.current.minheight===m||($.current.minwidth=l,$.current.minheight=m,$.current.resize(k,H))},[c,m,l,t,o]),s.jsxs(s.Fragment,{children:[We&&n&&Re&&Rt.createPortal(s.jsx("span",{className:"wb-icon-content",children:n}),Re),We&&ve&&Rt.createPortal(s.jsx("div",{className:"winbox-content-wrapper",children:i}),ve),We&&T&&q&&Rt.createPortal(T,q)]})},Oc={image:"prompt-list-item__tag--image",video:"prompt-list-item__tag--video",audio:"prompt-list-item__tag--audio",text:"prompt-list-item__tag--text",agent:"prompt-list-item__tag--agent","ppt-common":"prompt-list-item__tag--ppt-common","ppt-slide":"prompt-list-item__tag--ppt-slide"},Fc=({content:t,title:e,sentPrompt:n,tags:r,resultPreview:i,pinned:o=!1,isPreset:c=!1,modelType:l,scene:m,previewExamples:u,onClick:d,onTogglePin:p,onDelete:h,onPreviewExample:g,language:y="zh",disabled:f=!1})=>{const x=B=>{B.stopPropagation(),p==null||p()},z=B=>{B.stopPropagation(),h==null||h()},N=(u==null?void 0:u.slice(0,3))??[],O=N.length>0,T=(e==null?void 0:e.trim())||t,I=(r||[]).filter(Boolean).slice(0,4),b=!!(n||i||I.length>0)&&!O,S=N.length===1,C=!!(g&&!f),R=B=>_=>{_.preventDefault(),_.stopPropagation(),C&&(g==null||g({content:t,previewExamples:N,initialIndex:B}))},U=B=>{B.preventDefault(),B.stopPropagation()},P=B=>_=>{_.key!=="Enter"&&_.key!==" "||(_.preventDefault(),_.stopPropagation(),C&&(g==null||g({content:t,previewExamples:N,initialIndex:B})))},J=s.jsxs("div",{className:`prompt-list-item ${o?"prompt-list-item--pinned":""} ${c?"prompt-list-item--preset":""} ${f?"prompt-list-item--disabled":""}`,onClick:f?void 0:d,children:[o&&s.jsx("div",{className:"prompt-list-item__pin-badge",children:s.jsx(vs,{size:10})}),c&&s.jsx("div",{className:"prompt-list-item__preset-badge",children:s.jsx(pi,{size:10})}),m&&s.jsx("span",{className:`prompt-list-item__tag ${l&&Oc[l]||""}`,children:m}),s.jsx("span",{className:"prompt-list-item__text",children:T}),s.jsxs("div",{className:"prompt-list-item__actions",children:[p&&s.jsx(je,{content:o?y==="zh"?"取消置顶":"Unpin":y==="zh"?"置顶":"Pin",children:s.jsx("button",{type:"button",className:"prompt-list-item__action",onClick:x,children:o?s.jsx(hi,{size:14}):s.jsx(vs,{size:14})})}),h&&s.jsx(je,{content:y==="zh"?"删除":"Delete",children:s.jsx("button",{type:"button",className:"prompt-list-item__action prompt-list-item__action--delete",onClick:z,children:s.jsx(Mt,{size:14})})})]})]}),ee=O?s.jsxs("div",{className:"prompt-list-item__hover-card",children:[s.jsx("div",{className:"prompt-list-item__hover-text",children:t}),s.jsx("div",{className:`prompt-list-item__hover-gallery ${S?"prompt-list-item__hover-gallery--single":""}`,children:N.map((B,_)=>s.jsx("div",{className:`prompt-list-item__hover-thumb ${S?"prompt-list-item__hover-thumb--single":""}`,children:C?s.jsx("button",{type:"button",className:"prompt-list-item__hover-thumb-button","aria-label":`${y==="zh"?"预览示例图":"Preview example"} ${_+1}`,onMouseDown:R(_),onClick:U,onKeyDown:P(_),children:s.jsx(Tt,{src:B.kind==="video"&&B.posterSrc||B.src,alt:B.alt,showSkeleton:!1})}):s.jsx(Tt,{src:B.kind==="video"&&B.posterSrc||B.src,alt:B.alt,showSkeleton:!1})},`${B.src}-${B.alt}`))}),C&&s.jsx("div",{className:"prompt-list-item__hover-hint",children:y==="zh"?"点击预览":"Click to preview"})]}):null,X=i?s.jsxs("div",{className:"prompt-list-item__result-preview",children:[(i.kind==="image"||i.kind==="video")&&s.jsx("div",{className:"prompt-list-item__result-media",children:s.jsx(Tt,{src:i.kind==="video"&&i.posterUrl||i.url,alt:i.title||T,showSkeleton:!1})}),i.kind==="audio"&&s.jsxs("div",{className:"prompt-list-item__result-audio",children:[i.coverUrl&&s.jsx(Tt,{src:i.coverUrl,alt:i.title||T,showSkeleton:!1}),s.jsxs("div",{children:[s.jsx("div",{className:"prompt-list-item__result-title",children:i.title||"音频结果"}),i.text&&s.jsx("div",{className:"prompt-list-item__result-text",children:i.text})]})]}),(i.kind==="text"||i.kind==="error"||i.kind==="none")&&s.jsxs("div",{className:`prompt-list-item__result-text ${i.kind==="error"?"prompt-list-item__result-text--error":""}`,children:[i.kind==="text"&&i.title&&s.jsx("strong",{children:i.title}),i.text]})]}):null,Q=b?s.jsxs("div",{className:"prompt-list-item__history-card",children:[s.jsx("div",{className:"prompt-list-item__history-title",children:T}),n&&s.jsxs("div",{className:"prompt-list-item__history-section",children:[s.jsx("div",{className:"prompt-list-item__history-label",children:"发送提示词"}),s.jsx("div",{className:"prompt-list-item__history-text",children:n})]}),I.length>0&&s.jsx("div",{className:"prompt-list-item__history-tags",children:I.map(B=>s.jsx("span",{children:B},B))}),X&&s.jsxs("div",{className:"prompt-list-item__history-section",children:[s.jsx("div",{className:"prompt-list-item__history-label",children:"结果预览"}),X]})]}):null;return ee?s.jsx(je,{content:ee,placement:"right",delay:40,overlayClassName:"prompt-list-item__hover-card-popover",children:J}):Q?s.jsx(je,{content:Q,placement:"right",delay:60,overlayClassName:"prompt-list-item__history-card-popover",children:J}):s.jsx(je,{content:T===t?t:`${T}
|
|
3
3
|
|
|
4
4
|
${t}`,placement:"right-top",delay:80,overlayClassName:"prompt-list-item__text-tip-popover",overlayInnerClassName:"prompt-list-item__text-tip",children:J})},so="drawnix-runtime-model-discovery";function sn(t){return{profileId:t,status:"idle",sourceBaseUrl:"",signature:"",discoveredAt:null,discoveredModels:[],selectedModelIds:[],models:[],error:null}}function Uc(t){let e=5381;for(let n=0;n<t.length;n+=1)e=(e<<5)+e^t.charCodeAt(n);return Math.abs(e>>>0).toString(16)}function ro(t){const e=(t||"").trim(),n="https://api.tu-zi.com/v1";if(!e)return n;let r=e.replace(/\/+$/,"");return r=r.replace(/\/models$/i,""),/\/v1$/i.test(r)||(r=`${_i(r)}/v1`),r}function Fs(t,e){return`${ro(t)}::${Uc(e.trim())}`}function Wc(t,e){var r,i;const n=t.trim();if(!n)return e;try{const o=JSON.parse(n),c=typeof o.error=="string"?o.error:((r=o.error)==null?void 0:r.message)||((i=o.error)==null?void 0:i.details);return o.message||c||o.detail||e}catch{return n.replace(/\s+/g," ").slice(0,120)||e}}function Hc(t,e){return typeof e=="string"?t.includes(e):e.test(t)}function Ut(t,e){return e.some(n=>Hc(t,n))}function Vc(t,e){return t.some(n=>Ut(n,e))}function oo(t){const e=t.toLowerCase(),n=/(^|[^a-z0-9])(o1|o3|o4|o4-mini|gpt-4o|gpt-4\.1|chatgpt)([^a-z0-9]|$)/;return e.includes("flux")?se.FLUX:e.startsWith("mj")||e.includes("midjourney")?se.MIDJOURNEY:e.includes("grok")||e.includes("xai")||e.includes("supergrok")?se.GROK:e.includes("qwen")||e.includes("qwq")||e.includes("qvq")||e.includes("wanx")?se.QWEN:e.includes("glm")||e.includes("zhipu")||e.includes("bigmodel")||e.includes("cogview")||e.includes("cogvideo")?se.GLM:e.includes("minimax")||e.includes("abab")||e.includes("hailuo")||e.includes("speech-02")||e.includes("music-01")?se.MINIMAX:e.includes("mistral")||e.includes("mixtral")||e.includes("pixtral")||e.includes("ministral")||e.includes("codestral")?se.MISTRAL:e.includes("runway")||e.includes("runwayml")||/^gen[-_]?3/.test(e)||/^gen[-_]?4/.test(e)?se.RUNWAY:e.includes("pika")?se.PIKA:e.includes("llama")||e.includes("meta-llama")||e.includes("llama3")||e.includes("llama-3")||e.includes("llama-4")?se.LLAMA:e.includes("hunyuan")||e.includes("hunyuan-video")||e.includes("hunyuanimage")||e.includes("hunyuan-image")?se.HUNYUAN:e.includes("stepfun")||e.includes("jieyue")||/^step[-_]?1/.test(e)||e.startsWith("step-")?se.STEPFUN:e.includes("claude")||e.includes("sonnet")||e.includes("haiku")||e.includes("opus")?se.ANTHROPIC:e.includes("deepseek")?se.DEEPSEEK:e.includes("kling")?se.KLING:e.includes("happyhorse")?se.HAPPYHORSE:e.includes("veo")?se.VEO:e.includes("sora")?se.SORA:e.includes("suno")||e.includes("chirp")?se.SUNO:e.includes("seedream")||e.includes("seedance")||e.includes("doubao")||e.includes("jimeng")?se.DOUBAO:e.includes("gpt")||e.includes("openai")||e.includes("dall-e")||e.includes("whisper")||e.includes("codex")||e.includes("text-embedding")||e.includes("omni")||e.includes("tts-")||e.includes("babbage")||e.includes("davinci")||e.includes("computer-use")||n.test(e)?se.GPT:e.includes("gemini")||e.includes("banana")||e.includes("gemma")||e.includes("imagen")||e.includes("learnlm")?se.GEMINI:e.includes("google")?se.GOOGLE:se.OTHER}function io(t){const e=(t.owned_by||"").trim().toLowerCase(),n=oo(t.id);return e==="openai"||e.includes("openai")?se.GPT:e==="xai"||e.includes("x.ai")||e.includes("grok")?se.GROK:e==="qwen"||e.includes("alibaba")||e.includes("dashscope")||e.includes("tongyi")?se.QWEN:e==="zhipu"||e.includes("zhipu")||e.includes("bigmodel")||e.includes("glm")?se.GLM:e==="minimax"||e.includes("minimax")||e.includes("abab")||e.includes("hailuo")?se.MINIMAX:e==="mistral"||e.includes("mistral")?se.MISTRAL:e==="runway"||e.includes("runway")||e.includes("runwayml")?se.RUNWAY:e==="pika"||e.includes("pika")?se.PIKA:e==="meta"||e.includes("meta")||e.includes("llama")?se.LLAMA:e==="hunyuan"||e.includes("hunyuan")||e.includes("tencent")?se.HUNYUAN:e==="stepfun"||e.includes("stepfun")||e.includes("jieyue")?se.STEPFUN:e==="deepseek"||e.includes("deepseek")?se.DEEPSEEK:e==="anthropic"||e==="claude"||e.includes("anthropic")||e.includes("claude")?se.ANTHROPIC:e==="volcengine"||e==="doubao-video"||e==="doubao"||e.includes("volc")||e.includes("doubao")?se.DOUBAO:e==="suno"||e.includes("suno")||e.includes("chirp")?se.SUNO:e==="happyhorse"||e.includes("happyhorse")?se.HAPPYHORSE:e==="google"||e.includes("google")?n!==se.OTHER?n:se.GOOGLE:e==="vertex-ai"||e.includes("vertex")||e.includes("gemini")?n!==se.OTHER?n:se.GOOGLE:n}function Bc(t){const e=(t.supported_endpoint_types||[]).map(h=>h.toLowerCase()).filter(Boolean),n=t.id.toLowerCase(),r=io(t),i=(...h)=>Ut(n,[/(^|[^a-z0-9])t2v([^a-z0-9]|$)/,/(^|[^a-z0-9])i2v([^a-z0-9]|$)/,"video",...h]),o=(...h)=>Ut(n,[/(^|[^a-z0-9])t2i([^a-z0-9]|$)/,/(^|[^a-z0-9])i2i([^a-z0-9]|$)/,"image",...h]),c=(...h)=>Ut(n,["audio","music","suno","chirp","lyrics","midi","stems",...h]),l=(...h)=>Ut(n,h),m=(...h)=>Vc(e,h);if(m("audio","music","audio_generation","music-generation","lyrics","stems","midi"))return"audio";if(m("video","videos","video_generation","video-generation","videos.generate","video/generations","text-to-video","image-to-video","t2v","i2v","video-edit","video_edit"))return"video";if(m("image","images","image_generation","image-generation","images.generate","image/generations","image-edit","image_edit","images.edit","text-to-image","image-to-image","t2i","i2i"))return"image";switch(r){case se.FLUX:case se.MIDJOURNEY:return"image";case se.SORA:case se.VEO:case se.HAPPYHORSE:return"video";case se.RUNWAY:return o("frame","keyframe","reference-image","image-to-video")?"image":"video";case se.PIKA:return o("pikadditions","pikaswaps","pikascenes","reference-image")?"image":"video";case se.KLING:return o("kling_image","kling-image","img","picture","photo","poster","design")?"image":(i("kling_video","kling-video","motion","animate"),"video");case se.GLM:if(l("cogvideo"))return"video";if(l("cogview"))return"image";break;case se.MINIMAX:if(l("hailuo",/(^|[^a-z0-9])video[-_]?0\d/,"video-01","video-02","minimax-video","abab-video"))return"video";if(l("image-01","image-02","minimax-image","abab-image","visual-generation"))return"image";break;case se.DOUBAO:if(l("seedance"))return"video";if(l("seedream","jimeng"))return"image";break;case se.HUNYUAN:if(i("hunyuan-video","tencent-video","video-generation"))return"video";if(o("hunyuan-image","hunyuanimage","vision"))return"image";break;case se.QWEN:if(l("wanx",/(^|[^a-z0-9])wan([0-9.-]|$)/,/(^|[^a-z0-9])wan2([^a-z0-9]|$)/)&&i("wan-video","wanx-video","animate","motion"))return"video";if(l("wanx",/(^|[^a-z0-9])wan([0-9.-]|$)/,/(^|[^a-z0-9])wan2([^a-z0-9]|$)/)&&o("wanx-image","wan-image","poster","illustration")||l("wanx"))return"image";if(l(/(^|[^a-z0-9])wan([0-9.-]|$)/,/(^|[^a-z0-9])wan2([^a-z0-9]|$)/))return"video";break;case se.GEMINI:case se.GOOGLE:if(l("veo"))return"video";if(l("imagen","gpt-image"))return"image";break;case se.SUNO:return"audio";case se.OTHER:if(c())return"audio";break}return l("sora-2")||n.includes("veo")||n.includes("sora")||n.includes("runway")||n.includes("gen-3")||n.includes("gen3")||n.includes("gen-4")||n.includes("gen4")||n.includes("pika")||n.includes("kling")||n.includes("hunyuan-video")||n.includes("cogvideo")||n.includes("seedance")||n.includes("t2v")||n.includes("i2v")||n.includes("video")?"video":m("banana")||n.includes("image")||n.includes("banana")||n.includes("flux")||n.startsWith("mj")||n.includes("midjourney")||n.includes("cogview")||n.includes("hunyuan-image")||n.includes("hunyuanimage")||n.includes("seedream")||n.includes("jimeng")||n.includes("imagen")||n.includes("gpt-image")?"image":n.includes("suno")||n.includes("chirp")||n.includes("music")||n.includes("lyrics")||n.includes("midi")||n.includes("stems")||n.includes("remix")||n.includes("infill")?"audio":"text"}function Fn(t,e){const n=t.split(/[^a-zA-Z0-9]+/).filter(Boolean).slice(0,4).map(r=>{var i;return((i=r[0])==null?void 0:i.toLowerCase())||""}).join("");return n?n.slice(0,6):e==="audio"?"aud":e==="video"?"vid":e==="text"?"txt":"img"}function Gc(t){const e=Bc(t),n=io(t),r=Zn[n],i=t.id.toLowerCase(),o=e==="text"&&(t.supported_endpoint_types||[]).some(l=>l.toLowerCase().includes("openai-chat"));if(t.id.toLowerCase()==="kling_video")return{id:t.id,label:"Kling",shortLabel:"Kling",shortCode:Fn(t.id,"video"),description:"Kling 标准视频能力,版本通过 model_name 选择",type:"video",vendor:se.KLING,supportsTools:!1,tags:["runtime","kling"],videoDefaults:{duration:"5",size:"1280x720",aspectRatio:"16:9"}};const c={id:t.id,label:t.id,shortLabel:t.id,shortCode:Fn(t.id,e),description:`${r} ${e==="image"?"图片模型":e==="video"?"视频模型":e==="audio"?"音频模型":"文本模型"}`,type:e,vendor:n,supportsTools:o,tags:e==="audio"&&vi(i)?["runtime","suno","audio","music"]:["runtime"],imageDefaults:e==="image"?{aspectRatio:"auto",width:1024,height:1024}:void 0,videoDefaults:e==="video"?{duration:"8",size:"1280x720",aspectRatio:"16:9"}:void 0};return e==="audio"?Si(c):c}function ao(t){return{...t,tags:t.tags?[...t.tags]:void 0,imageDefaults:t.imageDefaults?{...t.imageDefaults}:void 0,videoDefaults:t.videoDefaults?{...t.videoDefaults}:void 0}}function qc(t){if(!(t!=null&&t.id)||typeof t.id!="string")return null;const e=Kn(t.id);return e?ao(e):Gc(t)}function It(t,e){const n=new Set(t.map(r=>r.id));return Array.from(new Set(e.filter(r=>n.has(r))))}function Bt(t,e){return t.filter(n=>e.includes(n.id))}function Kc(t,e){const n=[...e],r=new Set(e.map(i=>i.id));for(const i of t)r.has(i.id)||n.push(i);return n}function Zc(t){const e=Array.isArray(t)?[...t]:[];return e.includes("runtime")||e.push("runtime"),e}function kt(t,e){return t?`${t}::${e}`:e}function rs(t){return bi.get().find(e=>e.id===t)||null}function Yc(t){var e;return t===Fe?!0:((e=rs(t))==null?void 0:e.enabled)!==!1}function os(t,e){var r;const n=((r=rs(t))==null?void 0:r.name)||null;return{...e,tags:Zc(e.tags),sourceProfileId:t,sourceProfileName:n,selectionKey:kt(t,e.id)}}function Xc(t){const e=Kn(t.id);if(e)return ao(e);const n=t.id.toLowerCase(),r=(t.tags||[]).map(i=>i.toLowerCase());return n.includes("happyhorse")||r.includes("happyhorse")?{...t,type:"video",vendor:se.HAPPYHORSE,tags:Array.from(new Set([...t.tags||[],"happyhorse"]))}:t}function co(t,e){return e.map(n=>os(t,Xc(n)))}function Us(t){return t.map(e=>({...e,selectionKey:e.selectionKey||kt(null,e.id)}))}function Jc(t,e,n){var o;const r=((o=rs(t))==null?void 0:o.name)||"供应商模型",i=oo(e);return os(t,{id:e,label:e,shortLabel:e,shortCode:Fn(e,n),description:`${r} · ${e}`,type:n,vendor:i})}function Ws(t){const e=co(t.profileId,Array.isArray(t.discoveredModels)?t.discoveredModels:[]),n=It(e,Array.isArray(t.selectedModelIds)?t.selectedModelIds:[]),r=Bt(e,n);return{profileId:t.profileId,status:t.error?"error":e.length>0?"ready":"idle",sourceBaseUrl:t.sourceBaseUrl||"",signature:t.signature||"",discoveredAt:Number.isFinite(t.discoveredAt)?t.discoveredAt:null,discoveredModels:e,selectedModelIds:n,models:r,error:t.error||null}}function Hs(t){return{profileId:t.profileId,discoveredAt:t.discoveredAt,discoveredModels:t.discoveredModels,selectedModelIds:t.selectedModelIds,sourceBaseUrl:t.sourceBaseUrl||void 0,signature:t.signature||void 0,error:t.error}}function Qc(){if(typeof window>"u")return null;try{const t=window.localStorage.getItem(so);if(!t)return null;const e=JSON.parse(t);if(!e||!Array.isArray(e.discoveredModels))return null;const n=co(Fe,e.discoveredModels),r=It(n,Array.isArray(e.selectedModelIds)?e.selectedModelIds:[]);return{profileId:Fe,status:"ready",sourceBaseUrl:e.sourceBaseUrl||"",signature:e.signature||"",discoveredAt:Number.isFinite(e.discoveredAt)?e.discoveredAt:Date.now(),discoveredModels:n,selectedModelIds:r,models:Bt(n,r),error:null}}catch{return null}}function Tn(){if(!(typeof window>"u"))try{window.localStorage.removeItem(so)}catch{}}class el{constructor(){this.catalogStates=new Map,this.listeners=new Set,this.handleCatalogSettingsChange=e=>{const n=new Map;for(const r of e)n.set(r.profileId,Ws(r));n.has(Fe)||n.set(Fe,sn(Fe)),this.catalogStates=n,this.syncRuntimeModelConfigs(),this.emit()},this.handlePresetSettingsChange=()=>{this.syncRuntimeModelConfigs(),this.emit()},this.handleActivePresetIdChange=()=>{this.syncRuntimeModelConfigs(),this.emit()},this.catalogStates=this.loadCatalogStatesFromSettings(),this.migrateLegacyCacheIfNeeded(),this.syncRuntimeModelConfigs(),vn.addListener(this.handleCatalogSettingsChange),fi.addListener(this.handlePresetSettingsChange),gi.addListener("activePresetId",this.handleActivePresetIdChange)}loadCatalogStatesFromSettings(){const e=new Map;for(const n of vn.get())e.set(n.profileId,Ws(n));return e.has(Fe)||e.set(Fe,sn(Fe)),e}migrateLegacyCacheIfNeeded(){const e=Qc();if(!e)return;const n=this.catalogStates.get(Fe);if(!!n&&(n.discoveredModels.length>0||n.selectedModelIds.length>0)){Tn();return}this.catalogStates.set(Fe,e),this.persistCatalogs(),Tn()}emit(){for(const e of this.listeners)e()}async persistCatalogs(){const e=Array.from(this.catalogStates.values()).map(Hs);await vn.update(e)}setCatalogState(e,n,r=!0){this.catalogStates.set(e,{...n,profileId:e,selectedModelIds:It(n.discoveredModels,n.selectedModelIds),models:Bt(n.discoveredModels,It(n.discoveredModels,n.selectedModelIds))}),this.syncRuntimeModelConfigs(),r&&this.persistCatalogs(),this.emit()}getCatalogState(e){return this.catalogStates.get(e)||sn(e)}resolveRuntimeModels(){const e=new Set,n=[];for(const r of this.catalogStates.values())for(const i of r.models)e.has(i.id)||(e.add(i.id),n.push(i));return n}syncRuntimeModelConfigs(){wi(this.resolveRuntimeModels())}subscribe(e){return this.listeners.add(e),()=>this.listeners.delete(e)}getState(e=Fe){return this.getCatalogState(e)}getCatalogs(e){const n=e?new Set(e):null;return Array.from(this.catalogStates.values()).filter(r=>!n||n.has(r.profileId)).map(r=>Hs(r))}getDiscoveredModels(e=Fe,n){const r=this.getCatalogState(e);return n?r.discoveredModels.filter(i=>i.type===n):r.discoveredModels}getSelectedModelIds(e=Fe){return[...this.getCatalogState(e).selectedModelIds]}getPreferredModels(e){return yi(e)}getSelectableModels(e){const n=[];for(const r of this.catalogStates.values())Yc(r.profileId)&&n.push(...r.models.filter(i=>i.type===e));return xi([...n,...Us(Ss(e))])}getPinnedSelectableModel(e,n,r){if(!n)return null;const i=(r==null?void 0:r.profileId)||null,o=kt(i,n);if(i){const l=this.catalogStates.get(i),m=(l==null?void 0:l.models.find(d=>d.type===e&&(d.selectionKey||kt(i,d.id))===o))||(l==null?void 0:l.discoveredModels.find(d=>d.type===e&&(d.selectionKey||kt(i,d.id))===o));return m||((l==null?void 0:l.models.find(d=>(d.selectionKey||kt(i,d.id))===o))||(l==null?void 0:l.discoveredModels.find(d=>(d.selectionKey||kt(i,d.id))===o))?null:Jc(i,n,e))}const c=Kn(n);if(c&&c.type===e)return Us([c])[0];for(const l of this.catalogStates.values()){const m=l.models.find(u=>u.type===e&&u.id===n)||l.discoveredModels.find(u=>u.type===e&&u.id===n);if(m)return m}return null}getProfilePreferredModels(e=Fe,n){const i=this.getCatalogState(e).models.filter(o=>o.type===n);return Kc(Ss(n),i)}invalidateIfConfigChanged(e=Fe,n,r){const i=this.getCatalogState(e),o=Fs(n,r);!i.signature||i.signature===o||this.clear(e)}applySelection(e=Fe,n){const r=this.getCatalogState(e),i=It(r.discoveredModels,r.selectedModelIds),o=It(r.discoveredModels,n),c=new Set(i),l=new Set(o),m=Bt(r.discoveredModels,o),u=o.filter(p=>!c.has(p)),d=i.filter(p=>!l.has(p));return this.setCatalogState(e,{...r,status:r.discoveredModels.length>0?"ready":r.status,selectedModelIds:o,models:m,error:null}),{models:m,addedModelIds:u,removedModelIds:d}}clear(e=Fe){this.setCatalogState(e,sn(e)),e===Fe&&Tn()}async discover(e=Fe,n,r){const i=r.trim();if(!i)throw new Error("缺少 API Key");const o=this.getCatalogState(e),c=ro(n),l=Fs(c,i);this.setCatalogState(e,{...o,status:"loading",sourceBaseUrl:c,signature:l,error:null},!1);const m=await fetch(`${c}/models`,{headers:{Authorization:`Bearer ${i}`}}),u=await m.text();if(!m.ok)throw new Error(Wc(u,`获取模型列表失败: HTTP ${m.status}`));let d;try{d=JSON.parse(u)}catch{throw new Error("模型列表接口未返回有效 JSON")}const p=d.data;if(!Array.isArray(p))throw new Error("模型列表接口缺少 data 数组");const h=[],g=new Set;for(const x of p){const z=qc(x);!z||g.has(z.id)||(g.add(z.id),h.push(os(e,z)))}if(h.length===0)throw new Error("模型列表为空");const y=o.signature===l?It(h,o.selectedModelIds):[],f=Bt(h,y);return this.setCatalogState(e,{profileId:e,status:"ready",sourceBaseUrl:c,signature:l,discoveredAt:Date.now(),discoveredModels:h,selectedModelIds:y,models:f,error:null}),h}setError(e=Fe,n){const r=this.getCatalogState(e);this.setCatalogState(e,{...r,status:"error",error:n})}}const wt=new el;function am(t){return wt.getPreferredModels(t)}function tl(t){return wt.getSelectableModels(t)}function Un(t,e,n){return wt.getPinnedSelectableModel(t,e,n)}function nl(t,e){return wt.getProfilePreferredModels(t,e)}function lo(t=Fe){const[e,n]=a.useState(()=>wt.getState(t));return a.useEffect(()=>(n(wt.getState(t)),wt.subscribe(()=>{n(wt.getState(t))})),[t]),e}function uo(t,e){if(t.length!==e.length)return!1;for(let n=0;n<t.length;n++)if(t[n].id!==e[n].id||t[n].selectionKey!==e[n].selectionKey)return!1;return!0}function mo(t){const e=lo(),n=a.useRef([]);return a.useMemo(()=>{const r=tl(t);return uo(n.current,r)?n.current:(n.current=r,r)},[t,e])}function cm(t,e){const n=lo(t),r=a.useRef([]);return a.useMemo(()=>{const i=nl(t,e);return uo(r.current,i)?r.current:(r.current=i,i)},[t,e,n])}function is(t,e){return e!=null&&e.profileId?`${e.profileId}::${t}`:t}function po(t){return t.selectionKey||(t.sourceProfileId?`${t.sourceProfileId}::${t.id}`:t.id)}function Vs(t){return t?ht(t.sourceProfileId||null,t.id):null}function pn(t,e,n){if(!e)return;const r=is(e,n),i=(n==null?void 0:n.profileId)||null;return t.find(o=>po(o)===r)||t.find(o=>o.id===e&&(o.sourceProfileId||null)===i)||(i===null?t.find(o=>o.id===e&&!o.sourceProfileId):void 0)||t.find(o=>o.id===e)}const sl=({title:t,items:e,onSelect:n,onTogglePin:r,onDelete:i,language:o="zh",disabled:c=!1,showCount:l=!0,onTitleClick:m,className:u="",analyticsSurface:d="prompt_list",analyticsPromptType:p})=>{const[h,g]=a.useState(!1),[y,f]=a.useState([]),[x,z]=a.useState(0),N=a.useCallback((b,{content:S,previewExamples:C,initialIndex:R})=>{f(C.map((U,P)=>{const J=U.kind==="video"&&U.playable!==!1;return{id:`${b}-preview-${P}`,url:J?U.src:U.kind==="video"&&U.posterSrc||U.src,type:J?"video":"image",posterUrl:J?U.posterSrc:void 0,alt:U.alt,title:S}})),z(R),g(!0),ye.trackPromptAction({action:"preview_example",surface:d,promptType:p,prompt:S,itemCount:C.length})},[p,d]),O=a.useCallback(b=>{ye.trackPromptAction({action:"select",surface:d,promptType:p||b.modelType,prompt:b.content,source:b.isPreset?"preset":b.pinned?"pinned":"history"}),n==null||n(b)},[p,d,n]),T=a.useCallback(b=>{ye.trackPromptAction({action:b.pinned?"unpin":"pin",surface:d,promptType:p||b.modelType,prompt:b.content}),r==null||r(b.id)},[p,d,r]),I=a.useCallback(b=>{ye.trackPromptAction({action:"delete",surface:d,promptType:p||b.modelType,prompt:b.content}),i==null||i(b.id)},[p,d,i]);return s.jsxs(s.Fragment,{children:[s.jsxs("div",{className:`prompt-list-panel ${u}`,children:[s.jsxs("div",{className:"prompt-list-panel__header",children:[m?s.jsx("button",{type:"button",className:"prompt-list-panel__title prompt-list-panel__title-button",onClick:m,children:t}):s.jsx("span",{className:"prompt-list-panel__title",children:t}),l&&s.jsx("span",{className:"prompt-list-panel__count",children:e.length})]}),s.jsx("div",{className:"prompt-list-panel__list",children:e.map(b=>s.jsx(Fc,{content:b.content,title:b.title,sentPrompt:b.sentPrompt,tags:b.tags,resultPreview:b.resultPreview,pinned:b.pinned,isPreset:b.isPreset,modelType:b.modelType,scene:b.scene,previewExamples:b.previewExamples,onClick:()=>O(b),onTogglePin:r&&!b.isPreset?()=>T(b):void 0,onDelete:i&&!b.isPreset?()=>I(b):void 0,onPreviewExample:S=>N(b.id,S),language:o,disabled:c},b.id))})]}),s.jsx(mn,{visible:h,items:y,initialIndex:x,onClose:()=>g(!1),showThumbnails:y.length>1,videoAutoPlay:!0})]})},rl=["结构化 JSON 视觉提示词 schema:","- 每个页面图片提示词必须是一个可直接用于图片生成的 JSON 对象,顶层只使用 layout 和 style。","- layout.header 包含 location_title、main_title、subtitle,用于页面顶部地点/分类、主标题和副标题。","- layout.body.content_blocks 包含 block_type、left_column、right_column;左右栏都包含 title 和 content 数组。","- layout.footer.elements 描述页脚、CTA、滚动提示、页码或辅助信息。","- style.background 描述背景、摄影/插画质感、光影、景深和构图。","- style.elements 描述核心视觉元素、图标、建筑、产品、人物、道具或装饰。","- style.colors 使用数组,包含颜色名称、用途和可选 HEX。","- style.fonts 使用数组,描述标题、副标和正文的字体方向。","- 不要输出 subject、scene、negativePrompt 等旧式字段作为顶层字段;如确实需要,放入 style.elements 或对应内容字段中。","","目标结构示例:","{",' "layout": {',' "header": {',' "location_title": "中国 · 广东 | CHINA GUANGDONG",',' "main_title": "潮起岭南 寻味山海",',' "subtitle": "汕头 × 潮州 × 南澳 × 揭阳 · 4天3晚高定纯玩之旅"'," },",' "body": {',' "content_blocks": {',' "block_type": "首页视觉海报",',' "left_column": { "title": "文化与海岸的交响", "content": ["英歌舞非遗脸谱虚影", "民国骑楼复古剪影"] },',' "right_column": { "title": "留白与张力", "content": [] }'," }"," },",' "footer": { "elements": "SCROLL TO DISCOVER 开启寻味之旅" }'," },",' "style": {',' "background": "电影级光影质感,暖色文化元素平滑过渡至蓝色海浪,景深丰富,光影对比高级",',' "elements": "广济桥灯光、南澳长山尾灯塔、高级几何留白排版",',' "colors": ["潮汕非遗红 (#D13B3B)", "南澳海岛蓝 (#1A4B82)", "骑楼复古暖棕 (#B59372)"],',' "fonts": ["主标题:苍劲大气书法体", "副标及正文:现代极简无衬线几何体"]'," }","}"].join(`
|
|
5
5
|
`),ol=["Structured JSON visual prompt schema:","- Each page image prompt must be a JSON object for image generation with only layout and style at the top level.","- layout.header includes location_title, main_title, subtitle.","- layout.body.content_blocks includes block_type, left_column, right_column; each column includes title and content array.","- layout.footer.elements describes footer, CTA, scroll cue, page number, or auxiliary information.","- style.background describes background, rendering/photography quality, lighting, depth of field, and composition.","- style.elements describes key visual elements, icons, architecture, product, people, props, or decorations.","- style.colors is an array with color names, usage, and optional HEX values.","- style.fonts is an array describing title, subtitle, and body font direction.","- Do not use old top-level fields such as subject, scene, or negativePrompt; fold them into style.elements or the matching content fields if needed."].join(`
|
|
@@ -322,7 +322,7 @@ ${S}`))}if(z&&g.length>0&&!Wi(O)){const S=await Tr(g,N);O=Nr(O,S)}let T=0,I="";c
|
|
|
322
322
|
- 用户选择了文本内容作为生成素材
|
|
323
323
|
|
|
324
324
|
不适用场景:
|
|
325
|
-
- 简单的直接生成(使用 generate_image 或 generate_video)`,inputSchema:{type:"object",properties:{context:{type:"object",description:"Agent 执行上下文,包含用户指令、选中内容等"},textModel:{type:"string",description:"使用的文本模型 ID"},messages:{type:"array",description:"预构建的消息数组,传入时直接使用,不再生成默认系统提示词(用于 Skill 角色扮演/精准工具注入)"},knowledgeContextRefs:{type:"array",description:"本次 Agent 分析使用的知识库笔记轻量引用"}},required:["context"]},supportedModes:["async"],execute:async(t,e)=>{const{context:n,textModel:r,messages:i,modelRef:o,knowledgeContextRefs:c}=t;if(!n)return{success:!1,error:"缺少必填参数 context",type:"error"};const l=Date.now(),m=[],u=Ln(c||n.knowledgeContextRefs),d={...n,knowledgeContextRefs:u.length>0?u:void 0};try{const p=await Ll.execute(d,{model:r||d.model.id,modelRef:o||null,messages:i,onChunk:g=>{var y;(y=e==null?void 0:e.onChunk)==null||y.call(e,g)},onToolCall:g=>{var z;const y=at.get(),f=vo(g.name,{...g.arguments},{defaultModels:d.defaultModels,defaultModelRefs:d.defaultModelRefs,contextModel:d.model,contextModelRef:o||null,fallbackModels:{image:y.imageModelName||Dr(),video:y.videoModelName||Yt(),audio:y.audioModelName||es()}});u.length>0&&["generate_image","generate_video","generate_long_video","generate_audio","generate_text"].includes(g.name)&&!f.knowledgeContextRefs&&(f.knowledgeContextRefs=u);const x={id:`step-tool-${Date.now()}-${Math.random().toString(36).substring(2,6)}`,mcp:g.name,args:f,description:ad(g.name,f),status:"running"};m.push(x),(z=e==null?void 0:e.onAddSteps)==null||z.call(e,[x])},onToolResult:g=>{var y;if(m.length>0){const f=m[m.length-1];f.status=g.success?"completed":"failed",(y=e==null?void 0:e.onUpdateStep)==null||y.call(e,f.id,f.status,g.data,g.error)}}}),h=Date.now()-l;return p.success?{success:!0,type:"text",data:{response:p.response,generatedSteps:m,duration:h}}:{success:!1,error:p.error||"AI 分析失败",type:"error",data:{duration:h,generatedSteps:m}}}catch(p){return console.error("[AIAnalyzeTool] Analysis failed:",p),{success:!1,error:p.message||"AI 分析失败",type:"error",data:{duration:Date.now()-l,generatedSteps:m}}}}};function ad(t,e){switch(t){case"generate_image":return`生成图片: ${((e==null?void 0:e.prompt)||"").substring(0,30)}...`;case"generate_video":return`生成视频: ${((e==null?void 0:e.prompt)||"").substring(0,30)}...`;case"generate_audio":return`生成音频: ${((e==null?void 0:e.prompt)||"").substring(0,30)}...`;case"generate_ppt":return`生成PPT: ${((e==null?void 0:e.topic)||"").substring(0,30)}...`;case"generate_grid_image":return`生成宫格图: ${((e==null?void 0:e.theme)||"").substring(0,30)}...`;case"insert_svg":return"插入SVG矢量图";case"canvas_insertion":case"insert_to_canvas":return"插入到画布";default:return`执行 ${t}`}}let Xt=null;function cd(t){Xt=t}function en(){return Xt}function ld(){return Xt!==null}function dd(){if(!Xt)throw new Error("画布未初始化,请先打开画布");return Xt}const Jt=20,_n=50,ud=100;function Qt(t,e){if(e){const i=new RegExp(`\`\`\`(?:${e}|${e.charAt(0).toUpperCase()+e.slice(1)})\\s*([\\s\\S]*?)\`\`\``,"i"),o=t.match(i);if(o)return o[1].trim()}const n=/```(?:\w+)?\s*([\s\S]*?)```/,r=t.match(n);return r?r[1].trim():t.trim()}function Io(t){return $n.getBoundingRectangle(t.filter(e=>!Ji.isGroup(e)).map(e=>$n.getRectangleByPoints(e.points)))}function ko(t,e,n=Jt){const r=t.x-n,i=t.x+t.width+n,o=t.y-n,c=t.y+t.height+n,l=e.x,m=e.x+e.width,u=e.y,d=e.y+e.height;return!(i<l||r>m||c<u||o>d)}function ms(t){const e=[];if(!t.children||t.children.length===0)return e;for(const n of t.children)try{const r=ns(t,[n],!1);e.push({x:r.x,y:r.y,width:r.width,height:r.height})}catch(r){console.warn("[InsertUtils] Failed to get bounding box for element:",r)}return e}function ps(t,e,n=Jt){for(const r of e)if(ko(t,r,n))return!0;return!1}function hs(t,e,n,r=Jt,i=_n){let o=[...t],c=0;for(;c<ud;){const l={x:o[0],y:o[1],width:e.width,height:e.height};if(!ps(l,n,r))return o;o=[o[0],o[1]+i],c++}return console.warn("[InsertUtils] Max iterations reached, returning current position:",o),o}function md(t,e){const n=Io(e),r=n.width,i=n.height,o=ms(t);let c;const l=Lr(t);if(l)c=[l[0]-r/2,l[1]];else if(o.length>0){let u=-1/0,d=0;for(const p of o){const h=p.y+p.height;h>u&&(u=h,d=p.x+p.width/2)}c=[d-r/2,u+_n]}else{const u=ts.getBoardContainer(t).getBoundingClientRect(),d=[u.width/2,u.height/2],p=t.viewport.zoom,h=$r(t),g=h[0]+d[0]/p,y=h[1]+d[1]/p;c=[g-r/2,y-i/2]}return hs(c,{width:r,height:i},o)}function Mo(t,e){try{const n=ns(t,[e],!1);return{x:n.x,y:n.y,width:n.width,height:n.height}}catch(n){return console.warn("[InsertUtils] Failed to get actual bounding box:",n),null}}function Co(t,e){const n=[];if(!t.children||t.children.length===0)return n;for(const r of t.children){const i=r;if(!e.has(i.id))try{const o=ns(t,[i],!1);n.push({x:o.x,y:o.y,width:o.width,height:o.height})}catch{}}return n}function jo(t,e,n,r){try{const i=t.children.findIndex(l=>l.id===e.id);if(i<0)return console.warn("[InsertUtils] Element not found in board:",e.id),!1;const o=e.points;if(!o||o.length===0)return console.warn("[InsertUtils] Element has no points:",e.id),!1;const c=o.map(l=>[l[0]+n,l[1]+r]);return ss.setNode(t,{points:c},[i]),!0}catch(i){return console.error("[InsertUtils] Failed to move element:",i),!1}}function To(t){const e=Lr(t);if(e)return e;const n=ms(t);if(n.length>0){let u=-1/0,d=0;for(const p of n){const h=p.y+p.height;h>u&&(u=h,d=p.x+p.width/2)}return[d,u+_n]}const r=ts.getBoardContainer(t).getBoundingClientRect(),i=[r.width/2,r.height/2],o=t.viewport.zoom,c=$r(t),l=c[0]+i[0]/o,m=c[1]+i[1]/o;return[l,m]}function No(t,e){let n=!1;for(const r of e){const i=t.children.find(d=>d.id===r);if(!i)continue;const o=Mo(t,i);if(!o)continue;const c=Co(t,e);if(c.length===0||!ps(o,c,Jt))continue;const l=hs([o.x,o.y],{width:o.width,height:o.height},c,Jt,_n),m=l[0]-o.x,u=l[1]-o.y;(m!==0||u!==0)&&jo(t,i,m,u)&&(n=!0)}return n}function fs(t,e,n){if(!e||e.length===0)return{success:!1,error:"没有可插入的元素"};try{const r=new Set(t.children.map(c=>c.id)),i=n||To(t);t.insertFragment({elements:JSON.parse(JSON.stringify(e))},i,Qi.paste);const o=new Set;for(const c of t.children){const l=c;r.has(l.id)||o.add(l.id)}return o.size>0?requestAnimationFrame(()=>{const c=No(t,o);i&&qt(t,i)}):i&&requestAnimationFrame(()=>{qt(t,i)}),{success:!0,elementsCount:e.length}}catch(r){return console.error("[InsertUtils] Failed to insert elements:",r),{success:!1,error:r.message||"插入元素失败"}}}const fm=Object.freeze(Object.defineProperty({__proto__:null,adjustOverlappingElements:No,calculateElementsBoundingRect:Io,createQueueTask:wn,extractCodeBlock:Qt,findNonOverlappingPosition:hs,getAllElementBoundingBoxes:ms,getBoard:en,getElementActualBoundingBox:Mo,getInitialInsertionPoint:To,getInsertionPoint:md,getOtherElementBoundingBoxes:Co,hasOverlapWithAny:ps,insertElementsToCanvas:fs,isBoardAvailable:ld,isOverlapping:ko,moveElement:jo,requireBoard:dd,setBoard:cd,toUploadedImages:Rr,validatePrompt:yn,wrapApiError:zr},Symbol.toStringTag,{value:"Module"}));let rn=null;function pd(){return rn||(rn=dt(()=>import("./index-
|
|
325
|
+
- 简单的直接生成(使用 generate_image 或 generate_video)`,inputSchema:{type:"object",properties:{context:{type:"object",description:"Agent 执行上下文,包含用户指令、选中内容等"},textModel:{type:"string",description:"使用的文本模型 ID"},messages:{type:"array",description:"预构建的消息数组,传入时直接使用,不再生成默认系统提示词(用于 Skill 角色扮演/精准工具注入)"},knowledgeContextRefs:{type:"array",description:"本次 Agent 分析使用的知识库笔记轻量引用"}},required:["context"]},supportedModes:["async"],execute:async(t,e)=>{const{context:n,textModel:r,messages:i,modelRef:o,knowledgeContextRefs:c}=t;if(!n)return{success:!1,error:"缺少必填参数 context",type:"error"};const l=Date.now(),m=[],u=Ln(c||n.knowledgeContextRefs),d={...n,knowledgeContextRefs:u.length>0?u:void 0};try{const p=await Ll.execute(d,{model:r||d.model.id,modelRef:o||null,messages:i,onChunk:g=>{var y;(y=e==null?void 0:e.onChunk)==null||y.call(e,g)},onToolCall:g=>{var z;const y=at.get(),f=vo(g.name,{...g.arguments},{defaultModels:d.defaultModels,defaultModelRefs:d.defaultModelRefs,contextModel:d.model,contextModelRef:o||null,fallbackModels:{image:y.imageModelName||Dr(),video:y.videoModelName||Yt(),audio:y.audioModelName||es()}});u.length>0&&["generate_image","generate_video","generate_long_video","generate_audio","generate_text"].includes(g.name)&&!f.knowledgeContextRefs&&(f.knowledgeContextRefs=u);const x={id:`step-tool-${Date.now()}-${Math.random().toString(36).substring(2,6)}`,mcp:g.name,args:f,description:ad(g.name,f),status:"running"};m.push(x),(z=e==null?void 0:e.onAddSteps)==null||z.call(e,[x])},onToolResult:g=>{var y;if(m.length>0){const f=m[m.length-1];f.status=g.success?"completed":"failed",(y=e==null?void 0:e.onUpdateStep)==null||y.call(e,f.id,f.status,g.data,g.error)}}}),h=Date.now()-l;return p.success?{success:!0,type:"text",data:{response:p.response,generatedSteps:m,duration:h}}:{success:!1,error:p.error||"AI 分析失败",type:"error",data:{duration:h,generatedSteps:m}}}catch(p){return console.error("[AIAnalyzeTool] Analysis failed:",p),{success:!1,error:p.message||"AI 分析失败",type:"error",data:{duration:Date.now()-l,generatedSteps:m}}}}};function ad(t,e){switch(t){case"generate_image":return`生成图片: ${((e==null?void 0:e.prompt)||"").substring(0,30)}...`;case"generate_video":return`生成视频: ${((e==null?void 0:e.prompt)||"").substring(0,30)}...`;case"generate_audio":return`生成音频: ${((e==null?void 0:e.prompt)||"").substring(0,30)}...`;case"generate_ppt":return`生成PPT: ${((e==null?void 0:e.topic)||"").substring(0,30)}...`;case"generate_grid_image":return`生成宫格图: ${((e==null?void 0:e.theme)||"").substring(0,30)}...`;case"insert_svg":return"插入SVG矢量图";case"canvas_insertion":case"insert_to_canvas":return"插入到画布";default:return`执行 ${t}`}}let Xt=null;function cd(t){Xt=t}function en(){return Xt}function ld(){return Xt!==null}function dd(){if(!Xt)throw new Error("画布未初始化,请先打开画布");return Xt}const Jt=20,_n=50,ud=100;function Qt(t,e){if(e){const i=new RegExp(`\`\`\`(?:${e}|${e.charAt(0).toUpperCase()+e.slice(1)})\\s*([\\s\\S]*?)\`\`\``,"i"),o=t.match(i);if(o)return o[1].trim()}const n=/```(?:\w+)?\s*([\s\S]*?)```/,r=t.match(n);return r?r[1].trim():t.trim()}function Io(t){return $n.getBoundingRectangle(t.filter(e=>!Ji.isGroup(e)).map(e=>$n.getRectangleByPoints(e.points)))}function ko(t,e,n=Jt){const r=t.x-n,i=t.x+t.width+n,o=t.y-n,c=t.y+t.height+n,l=e.x,m=e.x+e.width,u=e.y,d=e.y+e.height;return!(i<l||r>m||c<u||o>d)}function ms(t){const e=[];if(!t.children||t.children.length===0)return e;for(const n of t.children)try{const r=ns(t,[n],!1);e.push({x:r.x,y:r.y,width:r.width,height:r.height})}catch(r){console.warn("[InsertUtils] Failed to get bounding box for element:",r)}return e}function ps(t,e,n=Jt){for(const r of e)if(ko(t,r,n))return!0;return!1}function hs(t,e,n,r=Jt,i=_n){let o=[...t],c=0;for(;c<ud;){const l={x:o[0],y:o[1],width:e.width,height:e.height};if(!ps(l,n,r))return o;o=[o[0],o[1]+i],c++}return console.warn("[InsertUtils] Max iterations reached, returning current position:",o),o}function md(t,e){const n=Io(e),r=n.width,i=n.height,o=ms(t);let c;const l=Lr(t);if(l)c=[l[0]-r/2,l[1]];else if(o.length>0){let u=-1/0,d=0;for(const p of o){const h=p.y+p.height;h>u&&(u=h,d=p.x+p.width/2)}c=[d-r/2,u+_n]}else{const u=ts.getBoardContainer(t).getBoundingClientRect(),d=[u.width/2,u.height/2],p=t.viewport.zoom,h=$r(t),g=h[0]+d[0]/p,y=h[1]+d[1]/p;c=[g-r/2,y-i/2]}return hs(c,{width:r,height:i},o)}function Mo(t,e){try{const n=ns(t,[e],!1);return{x:n.x,y:n.y,width:n.width,height:n.height}}catch(n){return console.warn("[InsertUtils] Failed to get actual bounding box:",n),null}}function Co(t,e){const n=[];if(!t.children||t.children.length===0)return n;for(const r of t.children){const i=r;if(!e.has(i.id))try{const o=ns(t,[i],!1);n.push({x:o.x,y:o.y,width:o.width,height:o.height})}catch{}}return n}function jo(t,e,n,r){try{const i=t.children.findIndex(l=>l.id===e.id);if(i<0)return console.warn("[InsertUtils] Element not found in board:",e.id),!1;const o=e.points;if(!o||o.length===0)return console.warn("[InsertUtils] Element has no points:",e.id),!1;const c=o.map(l=>[l[0]+n,l[1]+r]);return ss.setNode(t,{points:c},[i]),!0}catch(i){return console.error("[InsertUtils] Failed to move element:",i),!1}}function To(t){const e=Lr(t);if(e)return e;const n=ms(t);if(n.length>0){let u=-1/0,d=0;for(const p of n){const h=p.y+p.height;h>u&&(u=h,d=p.x+p.width/2)}return[d,u+_n]}const r=ts.getBoardContainer(t).getBoundingClientRect(),i=[r.width/2,r.height/2],o=t.viewport.zoom,c=$r(t),l=c[0]+i[0]/o,m=c[1]+i[1]/o;return[l,m]}function No(t,e){let n=!1;for(const r of e){const i=t.children.find(d=>d.id===r);if(!i)continue;const o=Mo(t,i);if(!o)continue;const c=Co(t,e);if(c.length===0||!ps(o,c,Jt))continue;const l=hs([o.x,o.y],{width:o.width,height:o.height},c,Jt,_n),m=l[0]-o.x,u=l[1]-o.y;(m!==0||u!==0)&&jo(t,i,m,u)&&(n=!0)}return n}function fs(t,e,n){if(!e||e.length===0)return{success:!1,error:"没有可插入的元素"};try{const r=new Set(t.children.map(c=>c.id)),i=n||To(t);t.insertFragment({elements:JSON.parse(JSON.stringify(e))},i,Qi.paste);const o=new Set;for(const c of t.children){const l=c;r.has(l.id)||o.add(l.id)}return o.size>0?requestAnimationFrame(()=>{const c=No(t,o);i&&qt(t,i)}):i&&requestAnimationFrame(()=>{qt(t,i)}),{success:!0,elementsCount:e.length}}catch(r){return console.error("[InsertUtils] Failed to insert elements:",r),{success:!1,error:r.message||"插入元素失败"}}}const fm=Object.freeze(Object.defineProperty({__proto__:null,adjustOverlappingElements:No,calculateElementsBoundingRect:Io,createQueueTask:wn,extractCodeBlock:Qt,findNonOverlappingPosition:hs,getAllElementBoundingBoxes:ms,getBoard:en,getElementActualBoundingBox:Mo,getInitialInsertionPoint:To,getInsertionPoint:md,getOtherElementBoundingBoxes:Co,hasOverlapWithAny:ps,insertElementsToCanvas:fs,isBoardAvailable:ld,isOverlapping:ko,moveElement:jo,requireBoard:dd,setBoard:cd,toUploadedImages:Rr,validatePrompt:yn,wrapApiError:zr},Symbol.toStringTag,{value:"Module"}));let rn=null;function pd(){return rn||(rn=dt(()=>import("./index-jxwTv7c1.js"),__vite__mapDeps([0]),import.meta.url).catch(t=>{throw rn=null,t})),rn}function hd(t){return Qt(t,"mermaid")}function fd(t){const e=t.trim().toLowerCase();return e.startsWith("flowchart")||e.startsWith("graph")?"flowchart":e.startsWith("sequencediagram")?"sequence":e.startsWith("classdiagram")?"classDiagram":e.startsWith("statediagram")?"stateDiagram":e.startsWith("erdiagram")?"erDiagram":e.startsWith("gantt")?"gantt":e.startsWith("pie")?"pie":e.startsWith("mindmap")?"mindmap":"unknown"}async function gd(t){const e=en();if(!e)return{success:!1,error:"画布未初始化,请先打开画布",type:"error"};const{mermaid:n}=t;if(!n||typeof n!="string"||n.trim()==="")return{success:!1,error:"缺少必填参数 mermaid,请提供有效的Mermaid markdown字符串",type:"error"};try{const r=hd(n),i=fd(r),o=await pd();let c;try{c=await o.parseMermaidToDrawnix(r)}catch(u){console.warn("[MermaidTool] First parse attempt failed, retrying with quote replacement:",u.message),c=await o.parseMermaidToDrawnix(r.replace(/"/g,"'"))}const{elements:l}=c;if(!l||l.length===0)return{success:!1,error:"Mermaid代码解析成功,但未生成任何图表元素",type:"error"};const m=fs(e,l);return m.success?{success:!0,data:{diagramType:i,elementsCount:m.elementsCount,mermaidCode:r.substring(0,200)+(r.length>200?"...":"")},type:"canvas"}:{success:!1,error:m.error||"插入图表失败",type:"error"}}catch(r){return console.error("[MermaidTool] Failed to process mermaid:",r),{success:!1,error:`Mermaid转换失败: ${r.message||"未知错误"}`,type:"error"}}}const wd={name:"insert_mermaid",description:`将Mermaid图表插入到画布工具。将Mermaid markdown语法转换为可视化图表并插入到画布中。
|
|
326
326
|
|
|
327
327
|
使用场景:
|
|
328
328
|
- 用户需要在画布上创建流程图、时序图、类图等图表
|
|
@@ -355,7 +355,7 @@ sequenceDiagram
|
|
|
355
355
|
AuthServer->>Client: 返回Access Token
|
|
356
356
|
Client->>ResourceServer: 携带Token请求资源
|
|
357
357
|
ResourceServer->>Client: 返回资源
|
|
358
|
-
\`\`\``,inputSchema:{type:"object",properties:{mermaid:{type:"string",description:"Mermaid markdown字符串,可以是纯Mermaid代码或包含```mermaid代码块的markdown"}},required:["mermaid"]},execute:async t=>gd(t)};let on=null;function yd(){return on||(on=dt(()=>import("./index-
|
|
358
|
+
\`\`\``,inputSchema:{type:"object",properties:{mermaid:{type:"string",description:"Mermaid markdown字符串,可以是纯Mermaid代码或包含```mermaid代码块的markdown"}},required:["mermaid"]},execute:async t=>gd(t)};let on=null;function yd(){return on||(on=dt(()=>import("./index-IHNaVKGH.js"),__vite__mapDeps([0,1]),import.meta.url).catch(t=>{throw on=null,t})),on}function xd(t){const e=Qt(t,"markdown");return e===t.trim(),e}async function _d(t){const e=en();if(!e)return{success:!1,error:"画布未初始化,请先打开画布",type:"error"};const{markdown:n}=t;if(!n||typeof n!="string"||n.trim()==="")return{success:!1,error:"缺少必填参数 markdown,请提供有效的 Markdown 思维导图定义",type:"error"};try{const r=xd(n),i=await yd();let o;try{o=await i.parseMarkdownToDrawnix(r)}catch(m){console.warn("[MindmapTool] First parse attempt failed, retrying with quote replacement:",m.message),o=await i.parseMarkdownToDrawnix(r.replace(/"/g,"'"))}if(!o)return{success:!1,error:"Markdown 解析成功,但未生成思维导图元素",type:"error"};o.points=[[0,0]];const l=fs(e,[o]);return l.success?{success:!0,data:{type:"mindmap",elementsCount:l.elementsCount,markdownPreview:r.substring(0,200)+(r.length>200?"...":"")},type:"canvas"}:{success:!1,error:l.error||"插入思维导图失败",type:"error"}}catch(r){return console.error("[MindmapTool] Failed to process markdown:",r),{success:!1,error:`思维导图转换失败: ${r.message||"未知错误"}`,type:"error"}}}const bd={name:"insert_mindmap",description:`将 Markdown 思维导图插入到画布工具。将 Markdown 语法转换为可视化思维导图并插入到画布中。
|
|
359
359
|
|
|
360
360
|
使用场景:
|
|
361
361
|
- 用户需要在画布上创建思维导图
|
|
@@ -633,7 +633,7 @@ ${r}
|
|
|
633
633
|
使用场景:
|
|
634
634
|
- 需要了解知识库的目录结构
|
|
635
635
|
- 创建笔记前查看可用目录`,inputSchema:{type:"object",properties:{}},execute:async()=>{try{return{success:!0,type:"text",data:(await Dt()).map(e=>({id:e.id,name:e.name,isDefault:e.isDefault,createdAt:new Date(e.createdAt).toISOString()}))}}catch(t){return{success:!1,error:`获取目录失败: ${t.message}`,type:"error"}}}},lu=[ou,iu,au,cu];function du(t){const e=t.prompt||xa,n=t.videoAnalyzerAction||"analyze";if(n!=="prompt-generate"&&!t.videoData&&!t.youtubeUrl&&!t.videoCacheUrl)return{success:!1,error:"需要提供 videoData、videoCacheUrl 或 youtubeUrl",type:"error"};const r=ft.createTask({prompt:t.taskLabel||"视频分析",model:t.model,modelRef:t.modelRef||null,mimeType:t.mimeType||"video/mp4",youtubeUrl:t.youtubeUrl,videoData:t.videoData,videoCacheUrl:t.videoCacheUrl,pdfCacheUrl:t.pdfCacheUrl,pdfMimeType:t.pdfMimeType,pdfName:t.pdfName,videoAnalyzerAction:n,videoAnalyzerPrompt:e,videoAnalyzerSource:t.videoAnalyzerSource,videoAnalyzerSourceLabel:t.videoAnalyzerSourceLabel,videoAnalyzerSourceSnapshot:t.videoAnalyzerSourceSnapshot,videoAnalyzerProductInfo:t.videoAnalyzerProductInfo,knowledgeContextRefs:t.knowledgeContextRefs,autoInsertToCanvas:!1},xt.CHAT);return{success:!0,data:{taskId:r.id,prompt:t.taskLabel||"视频分析",model:t.model},type:"text",taskId:r.id,task:r}}const uu={name:"video_analyze",description:"分析视频内容,返回结构化的镜头拆解、脚本提取、风格分析等数据",supportedModes:["async","queue"],inputSchema:{type:"object",properties:{videoData:{type:"string",description:"base64 编码的视频数据(不含 data: 前缀),≤20MB"},mimeType:{type:"string",description:"视频 MIME 类型,默认 video/mp4",default:"video/mp4"},youtubeUrl:{type:"string",description:"YouTube 视频 URL"},videoCacheUrl:{type:"string",description:"本地缓存的视频 URL(队列模式)"},pdfCacheUrl:{type:"string",description:"本地缓存的 PDF URL(提示词生成上下文)"},pdfMimeType:{type:"string",description:"PDF MIME 类型,默认 application/pdf"},pdfName:{type:"string",description:"PDF 文件名"},prompt:{type:"string",description:"自定义分析 prompt(可选,有内置默认值)"},videoAnalyzerAction:{type:"string",description:"视频工具动作:analyze 或 prompt-generate"},videoAnalyzerProductInfo:{type:"object",description:"提示词生成时的画面风格、视频模型、单段时长等表单参数"},model:{type:"string",description:"模型 ID,默认使用当前文本模型"}},required:[]},execute:async(t,e)=>(e==null?void 0:e.mode)==="queue"?du(t):ya(t)};function mu(t){const e=t.prompt||ba;if(!t.audioData&&!t.audioCacheUrl)return{success:!1,error:"需要提供 audioData 或 audioCacheUrl",type:"error"};const n=ft.createTask({prompt:t.taskLabel||"音频分析",model:t.model,modelRef:t.modelRef||null,mimeType:t.mimeType||"audio/mpeg",audioData:t.audioData,audioCacheUrl:t.audioCacheUrl,musicAnalyzerAction:"analyze",musicAnalyzerPrompt:e,musicAnalyzerSource:t.musicAnalyzerSource,musicAnalyzerSourceLabel:t.musicAnalyzerSourceLabel,musicAnalyzerSourceSnapshot:t.musicAnalyzerSourceSnapshot,autoInsertToCanvas:!1},xt.CHAT);return{success:!0,data:{taskId:n.id,prompt:t.taskLabel||"音频分析",model:t.model},type:"text",taskId:n.id,task:n}}const pu={name:"audio_analyze",description:"分析音频内容,返回结构化的音乐风格、情绪、Suno 标签和歌词改写建议",supportedModes:["async","queue"],inputSchema:{type:"object",properties:{audioData:{type:"string",description:"base64 编码的音频数据(不含 data: 前缀)"},mimeType:{type:"string",description:"音频 MIME 类型,默认 audio/mpeg",default:"audio/mpeg"},audioCacheUrl:{type:"string",description:"本地缓存的音频 URL(队列模式)"},prompt:{type:"string",description:"自定义分析 prompt(可选,有内置默认值)"},model:{type:"string",description:"Gemini 多模态模型 ID,默认使用当前文本模型"}},required:[]},execute:async(t,e)=>(e==null?void 0:e.mode)==="queue"?mu(t):_a(t)};let Js=!1;function hu(){Js||(Js=!0,ls.registerAll([va,us,ed,od,Wd,xo,id,wd,bd,kd,jd,Ed,zd,gs,...lu,uu,pu]))}const Ro=it.memo(({session:t,isActive:e,onSelect:n,onDelete:r,onRename:i})=>{const[o,c]=a.useState(!1),[l,m]=a.useState(t.title),u=a.useRef(null),d=a.useCallback(()=>{o||n()},[n,o]),p=a.useCallback(N=>{N.stopPropagation(),r()},[r]),h=a.useCallback(N=>{N.stopPropagation(),m(t.title),c(!0)},[t.title]),g=a.useCallback(()=>{const N=l.trim();N&&N!==t.title&&i(N),c(!1)},[l,t.title,i]),y=a.useCallback(()=>{m(t.title),c(!1)},[t.title]),f=a.useCallback(N=>{N.key==="Enter"?(N.preventDefault(),g()):N.key==="Escape"&&(N.preventDefault(),y())},[g,y]),x=a.useCallback(N=>{m(N.target.value)},[]);a.useEffect(()=>{o&&u.current&&(u.current.focus(),u.current.select())},[o]);const z=a.useMemo(()=>{const N=new Date(t.updatedAt),O=new Date;return N.toDateString()===O.toDateString()?N.toLocaleTimeString("zh-CN",{hour:"2-digit",minute:"2-digit"}):N.toLocaleDateString("zh-CN",{month:"short",day:"numeric"})},[t.updatedAt]);return s.jsxs("div",{className:`session-item ${e?"session-item--active":""} ${o?"session-item--editing":""}`,"data-track":"chat_click_session_select",onClick:d,role:"button",tabIndex:0,onKeyDown:N=>!o&&N.key==="Enter"&&d(),children:[s.jsxs("div",{className:"session-item__content",children:[o?s.jsx("input",{ref:u,className:"session-item__title-input",value:l,onChange:x,onKeyDown:f,onBlur:g,onClick:N=>N.stopPropagation(),maxLength:50}):s.jsx("div",{className:"session-item__title",children:t.title}),s.jsx("div",{className:"session-item__time",children:z})]}),!o&&s.jsxs("div",{className:"session-item__actions",children:[s.jsx("button",{className:"session-item__edit","data-track":"chat_click_session_edit",onClick:h,"aria-label":`编辑会话标题: ${t.title}`,children:s.jsx(Sa,{size:14})}),s.jsx("button",{className:"session-item__delete","data-track":"chat_click_session_delete",onClick:p,"aria-label":`删除会话: ${t.title}`,children:s.jsx(Ia,{size:14})})]})]})});Ro.displayName="SessionItem";const zo=it.memo(({sessions:t,activeSessionId:e,onSelectSession:n,onNewSession:r,onDeleteSession:i,onRenameSession:o})=>{const[c,l]=it.useState(null),m=a.useCallback(g=>{n(g)},[n]),u=a.useCallback(g=>{l(g)},[]),d=a.useCallback(()=>{c&&(i(c),l(null))},[c,i]),p=a.useCallback(()=>{l(null)},[]),h=a.useCallback((g,y)=>{o(g,y)},[o]);return s.jsxs("div",{className:"session-list",children:[s.jsxs("div",{className:"session-list__header",children:[s.jsx("span",{className:"session-list__title",children:"会话列表"}),s.jsxs("button",{className:"session-list__new-btn","data-track":"chat_click_session_new",onClick:r,"aria-label":"新建会话",children:[s.jsx(Wr,{size:14}),s.jsx("span",{children:"新建"})]})]}),s.jsx("div",{className:"session-list__items",children:t.length===0?s.jsx("div",{className:"session-list__empty",children:"暂无会话"}):t.map(g=>s.jsx(Ro,{session:g,isActive:g.id===e,onSelect:()=>m(g.id),onDelete:()=>u(g.id),onRename:y=>h(g.id,y)},g.id))}),s.jsx(ka,{open:c!==null,title:"删除会话",description:"确定删除此会话吗?删除后无法恢复。",confirmText:"删除",cancelText:"取消",danger:!0,onOpenChange:g=>{g||p()},onConfirm:d})]})});zo.displayName="SessionList";const Do=it.memo(({isOpen:t,onClick:e,drawerWidth:n})=>{const r={right:t&&n?`calc(var(--aitu-toolbar-right-dock-width, 0px) + ${n-18}px)`:"var(--aitu-toolbar-right-dock-width, 0px)"};return s.jsx(je,{content:t?"收起对话":"展开对话",children:s.jsx("button",{className:`chat-drawer-trigger ${t?"chat-drawer-trigger--active":""}`,"data-track":t?"chat_click_drawer_close":"chat_click_drawer_open",onClick:e,"aria-label":t?"收起对话":"展开对话","aria-expanded":t,style:r,children:s.jsx(Ma,{size:16,className:"chat-drawer-trigger__icon"})})})});Do.displayName="ChatDrawerTrigger";function fn(t){return t.sourceProfileName||Zn[t.vendor]||t.id}const fu=it.memo(({model:t})=>{const{summary:e,detail:n}=Ra(t.sourceProfileId,t.id);return e?s.jsx(je,{content:n,placement:"top",disabled:n===e,children:s.jsx("span",{className:"model-selector__item-price",children:e})}):null}),gu=it.memo(({model:t})=>{const e=za(t.sourceProfileId,t.id);return e!=null&&e.description?s.jsx("div",{className:"model-selector__item-desc",children:e.description}):null});function wu(t,e){var o;const n=fn(t),r=(o=t.description)==null?void 0:o.trim(),i=(e==null?void 0:e.includeProvider)??!0;return r?!i||r.includes(n)?r:`${n} · ${r}`:i?n:""}function yu(t){return fn(t).trim().slice(0,1).toUpperCase()||"M"}const Lo=it.memo(({className:t,value:e,valueRef:n,onChange:r,variant:i="capsule"})=>{var B;const o=mo("text"),c=((B=o[0])==null?void 0:B.id)||Ca,[l,m]=a.useState(c),[u,d]=a.useState(()=>ht(null,c)),p=e??l,h=n===void 0?u:n,[g,y]=a.useState(!1),[f,x]=a.useState(""),[z,N]=a.useState(null),O=a.useRef(null),T=a.useRef(null);a.useEffect(()=>{!e&&c&&l!==c&&(m(c),d(ht(null,c)))},[c,l,e]),a.useEffect(()=>{if(!g)return;const _=M=>{const $=M.target;O.current&&!O.current.contains($)&&T.current&&!T.current.contains($)&&(y(!1),x(""))},E=setTimeout(()=>{document.addEventListener("mousedown",_)},100);return()=>{clearTimeout(E),document.removeEventListener("mousedown",_)}},[g]);const I=a.useMemo(()=>p?is(p,h):null,[p,h]),b=a.useMemo(()=>{if(pn(o,p,h)||!p)return o;const E=Un("text",p,h);return E?[E,...o]:o},[o,p,h]),S=a.useMemo(()=>pn(b,p,h)||b.find(_=>_.id===p),[b,p,h]),C=a.useCallback(_=>{const E=ht(_.sourceProfileId||null,_.id);e===void 0&&m(_.id),n===void 0&&d(E),r==null||r(_.id,E),y(!1),x("")},[e,n,r]),R=a.useCallback(()=>{const _=!g;y(_),_?N((S==null?void 0:S.vendor)||null):x("")},[S==null?void 0:S.vendor,g]),U=a.useMemo(()=>{const _=new Map,E=[];return b.forEach(M=>{_.has(M.vendor)||(E.push(M.vendor),_.set(M.vendor,0)),_.set(M.vendor,(_.get(M.vendor)??0)+1)}),E.map(M=>({id:M,label:Zn[M],count:_.get(M)??0,icon:s.jsx(ja,{vendor:M,size:14})}))},[b]),P=a.useCallback(_=>{N(_)},[]),J=a.useMemo(()=>{const _=f.toLowerCase().trim();return _?b.filter(E=>{var $,re;const M=fn(E).toLowerCase();return E.id.toLowerCase().includes(_)||E.label.toLowerCase().includes(_)||(($=E.shortLabel)==null?void 0:$.toLowerCase().includes(_))||((re=E.description)==null?void 0:re.toLowerCase().includes(_))||M.includes(_)}):z?b.filter(E=>E.vendor===z):b},[f,z,b]),[ee,X]=a.useState({top:0,left:0,width:0,bottom:0,placement:"bottom",maxHeight:480});a.useLayoutEffect(()=>{if(!g)return;const _=()=>{if(!T.current)return;const E=T.current.getBoundingClientRect(),M=window.innerHeight,$=M-E.bottom,re=E.top,fe=$<400&&re>$?"top":"bottom",K=fe==="top"?re-16:M-E.bottom-16;X({top:E.top,left:E.left,width:E.width,bottom:E.bottom,placement:fe,maxHeight:Math.min(Math.max(K,200),600)})};return _(),window.addEventListener("resize",_),window.addEventListener("scroll",_,!0),()=>{window.removeEventListener("resize",_),window.removeEventListener("scroll",_,!0)}},[g]);const Q=()=>{if(!g)return null;const _=s.jsxs("div",{ref:O,className:"model-selector__dropdown",style:{position:"fixed",zIndex:qn.DROPDOWN_PORTAL,left:ee.left,top:ee.placement==="bottom"?ee.bottom+8:"auto",bottom:ee.placement==="top"?window.innerHeight-ee.top+8:"auto",minWidth:360,width:i==="form"?ee.width:"auto",maxHeight:ee.maxHeight,visibility:ee.width===0?"hidden":"visible",transformOrigin:ee.placement==="bottom"?"top left":"bottom left",display:"flex",flexDirection:"column"},onClick:E=>E.stopPropagation(),children:[s.jsx("div",{className:"model-selector__search",children:s.jsx(Na,{value:f,onChange:x,placeholder:"搜索模型...",prefixIcon:s.jsx(Ea,{}),clearable:!0,autofocus:!0})}),s.jsx(Pa,{tabs:U,activeTab:z,onTabChange:P,searchQuery:f,compact:!0,children:s.jsx("div",{className:"model-selector__list",children:J.length===0?s.jsx("div",{className:"model-selector__empty",children:"未找到匹配的模型"}):J.map(E=>{const M=po(E),$=M===I,re=!!f.trim(),fe=wu(E,{includeProvider:!re});return s.jsxs("button",{className:`model-selector__item ${$?"model-selector__item--active":""}`,"data-track":"chat_click_model_select",onClick:()=>C(E),children:[s.jsx("span",{className:"model-selector__item-icon model-selector__item-icon--text","aria-hidden":"true",children:yu(E)}),s.jsxs("div",{className:"model-selector__item-content",children:[s.jsxs("div",{className:"model-selector__item-header",children:[s.jsx("span",{className:"model-selector__item-name",children:E.shortLabel||E.label}),re?s.jsx("span",{className:"model-selector__item-provider",children:fn(E)}):null,s.jsx(Ts,{modelId:E.id,profileId:E.sourceProfileId||null}),s.jsx(Aa,{modelId:E.id}),s.jsx(fu,{model:E})]}),fe?s.jsx("div",{className:"model-selector__item-desc",children:fe}):s.jsx(gu,{model:E})]}),$&&s.jsx("svg",{className:"model-selector__check",width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",children:s.jsx("path",{d:"M13.3334 4L6.00002 11.3333L2.66669 8",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})})]},M)})})})]});return Rt.createPortal(_,document.body)};return s.jsxs("div",{className:`model-selector ${t||""} model-selector--variant-${i}`,children:[s.jsxs("button",{ref:T,className:`model-selector__trigger ${g?"model-selector__trigger--active":""}`,"data-track":"chat_click_model_selector",onClick:R,"aria-label":"选择模型","aria-expanded":g,children:[s.jsxs("div",{className:"model-selector__trigger-content",children:[s.jsx(Ts,{modelId:(S==null?void 0:S.id)||p,profileId:(S==null?void 0:S.sourceProfileId)||null,className:"model-selector__trigger-health"}),s.jsx("span",{className:"model-selector__trigger-text",children:(S==null?void 0:S.shortLabel)||(S==null?void 0:S.label)||"选择模型"})]}),s.jsx(Ta,{size:16,className:`model-selector__trigger-icon ${g?"model-selector__trigger-icon--open":""}`})]}),Q()]})});Lo.displayName="ModelSelector";const $o=a.forwardRef(({selectedContent:t,onSend:e,disabled:n=!1,placeholder:r="输入消息..."},i)=>{const o=a.useRef(null),c=a.useRef(null),[l,m]=a.useState(""),u=t.length>0,{addHistory:d}=Sr();a.useImperativeHandle(i,()=>({setContent:f=>{var x;m(f),(x=o.current)==null||x.focus()},getContent:()=>l,focus:()=>{var f;return(f=o.current)==null?void 0:f.focus()}}),[l]);const p=a.useCallback(()=>{const f=l.trim();if(!f&&t.length===0)return;const x=[];f&&x.push({type:"text",text:f}),t.forEach((N,O)=>{N.type==="image"||N.type==="graphics"?x.push({type:"data-file",data:{filename:`${N.type}-${O+1}.png`,mediaType:"image/png",url:N.url||""}}):N.type==="video"&&x.push({type:"data-file",data:{filename:`video-${O+1}.mp4`,mediaType:"video/mp4",url:N.url||""}})});const z={id:`msg_${Date.now()}`,role:"user",parts:x};f&&d(f,u,"agent"),Promise.resolve(e(z)).catch(N=>{console.error("[EnhancedChatInput] send failed:",N)}),m("")},[l,t,e,d,u]),h=a.useCallback(f=>{f.nativeEvent.isComposing||f.key==="Enter"&&!f.shiftKey&&(f.preventDefault(),p())},[p]);a.useEffect(()=>{o.current&&(o.current.style.height="auto",o.current.style.height=`${Math.min(o.current.scrollHeight,120)}px`)},[l]);const g=()=>t.length===0?null:s.jsx("div",{className:"enhanced-chat-input__selection",children:s.jsx(Hl,{items:t,language:"zh",enableHoverPreview:!0})}),y=(l.trim()||t.length>0)&&!n;return s.jsxs("div",{className:"enhanced-chat-input",ref:c,children:[g(),s.jsxs("div",{className:"enhanced-chat-input__form",children:[s.jsx("div",{className:"enhanced-chat-input__input-wrapper",children:s.jsx("textarea",{ref:o,className:"enhanced-chat-input__textarea",value:l,onChange:f=>m(f.target.value),onKeyDown:h,placeholder:u?"描述你想要的效果...":r,disabled:n,rows:4})}),s.jsx("button",{className:`enhanced-chat-input__send ${y?"enhanced-chat-input__send--active":""}`,onClick:p,disabled:!y,"aria-label":"发送",children:s.jsx(Da,{size:20})})]})]})});$o.displayName="EnhancedChatInput";const Gt={MAX_TITLE_LENGTH:30,DRAWER_MIN_WIDTH:320,DRAWER_MAX_WIDTH:500,DRAWER_DEFAULT_WIDTH_RATIO:.3},jt={DRAWER_STATE:"aitu:chat:drawer-state",ACTIVE_SESSION:"aitu:chat:active-session",DATABASE_NAME:"aitu-chat",SESSIONS_STORE:"sessions",MESSAGES_STORE:"messages"},Lt=Hr.createInstance({name:jt.DATABASE_NAME,storeName:jt.SESSIONS_STORE}),yt=Hr.createInstance({name:jt.DATABASE_NAME,storeName:jt.MESSAGES_STORE});function Oo(){return _r()}function xu(t){const e=t.trim().replace(/\n/g," ");return e.length<=Gt.MAX_TITLE_LENGTH?e:e.slice(0,Gt.MAX_TITLE_LENGTH-3)+"..."}async function _u(){const t=Date.now(),e={id:Oo(),title:"新对话",createdAt:t,updatedAt:t,messageCount:0};return await Lt.setItem(e.id,e),e}async function bn(t){return Lt.getItem(t)}async function bu(){const t=[];return await Lt.iterate(e=>{t.push(e)}),await new Promise(e=>{typeof window<"u"&&"requestIdleCallback"in window?window.requestIdleCallback(()=>e(),{timeout:50}):setTimeout(e,0)}),t.sort((e,n)=>n.updatedAt-e.updatedAt)}async function ws(t,e){const n=await bn(t);if(n){const r={...n,...e,updatedAt:Date.now()};await Lt.setItem(t,r)}}async function vu(t){const e=await Fo(t);for(const n of e)await yt.removeItem(n.id);await Lt.removeItem(t)}async function Su(t){await yt.setItem(t.id,t);const e=await bn(t.sessionId);if(e){const n={messageCount:e.messageCount+1,updatedAt:Date.now()};await ws(t.sessionId,n)}}async function Fo(t){const e=[];return await yt.iterate(n=>{n.sessionId===t&&e.push(n)}),e.sort((n,r)=>n.timestamp-r.timestamp)}async function Iu(t,e){const n=await yt.getItem(t);if(n){const r={...n,...e};await yt.setItem(t,r)}}async function ku(t){const e=await yt.getItem(t);if(e){await yt.removeItem(t);const n=await bn(e.sessionId);n&&await ws(e.sessionId,{messageCount:Math.max(0,n.messageCount-1)})}}const Qs={isOpen:!1,width:Math.min(Gt.DRAWER_MAX_WIDTH,Math.max(Gt.DRAWER_MIN_WIDTH,window.innerWidth*Gt.DRAWER_DEFAULT_WIDTH_RATIO)),activeSessionId:null};function Uo(){try{const t=localStorage.getItem(jt.DRAWER_STATE);if(t)return{...Qs,...JSON.parse(t)}}catch(t){console.error("[ChatStorage] Failed to get drawer state:",t)}return Qs}function Mu(t){try{const n={...Uo(),...t};localStorage.setItem(jt.DRAWER_STATE,JSON.stringify(n))}catch(e){console.error("[ChatStorage] Failed to set drawer state:",e)}}async function Cu(){await Lt.clear(),await yt.clear(),localStorage.removeItem(jt.DRAWER_STATE)}const Se={createSession:_u,getSession:bn,getAllSessions:bu,updateSession:ws,deleteSession:vu,addMessage:Su,getMessages:Fo,updateMessage:Iu,deleteMessage:ku,getDrawerState:Uo,setDrawerState:Mu,clearAllData:Cu,generateId:Oo,generateTitle:xu};var st=(t=>(t.SENDING="sending",t.STREAMING="streaming",t.SUCCESS="success",t.FAILED="failed",t))(st||{}),ot=(t=>(t.USER="user",t.ASSISTANT="assistant",t))(ot||{});let lt=null;function Wo(t){const e={};let n=1,r=1,i=1,o=t;return o=o.replace(/data:image\/[^;]+;base64,[A-Za-z0-9+/=]+/g,c=>{const l=`[图片${n}]`;return e[l]=c,n++,l}),o=o.replace(/data:video\/[^;]+;base64,[A-Za-z0-9+/=]+/g,c=>{const l=`[视频${r}]`;return e[l]=c,r++,l}),o=o.replace(/blob:[^\s"'<>]+/g,c=>{const l=`[媒体${i}]`;return e[l]=c,i++,l}),o=o.replace(/https?:\/\/[^\s"'<>]+\.(png|jpg|jpeg|gif|webp|svg|bmp)(\?[^\s"'<>]*)?/gi,c=>{const l=`[图片${n}]`;return e[l]=c,n++,l}),o=o.replace(/https?:\/\/[^\s"'<>]+\.(mp4|webm|mov|avi|mkv)(\?[^\s"'<>]*)?/gi,c=>{const l=`[视频${r}]`;return e[l]=c,r++,l}),{sanitized:o,urlMap:e}}function ju(t,e){let n=t;for(const[r,i]of Object.entries(e))n=n.split(r).join(i);return n}async function Tu(t,e={}){const n={};let r=e.maxImageCount??Number.POSITIVE_INFINITY;return{geminiMessages:await Promise.all(t.filter(o=>o.status==="success"||o.status==="streaming").map(async o=>{const{sanitized:c,urlMap:l}=Wo(o.content);Object.assign(n,l);const m=[{type:"text",text:c}];if(e.includeImageAttachments&&o.role===ot.USER&&o.attachments&&o.attachments.length>0&&r>0){const u=await Fa(o.attachments,r);r-=u.length,m.push(...u)}return{role:o.role===ot.USER?"user":"assistant",content:m}})),urlMap:n}}async function Nu(t,e,n=[],r,i,o){return Eu(t,e,n,r,i,o)}async function Eu(t,e,n=[],r,i,o){lt&<.abort(),lt=new AbortController;const c=lt.signal,l=Date.now().toString(),m=Date.now(),u=(typeof i=="string"?i:i==null?void 0:i.modelId)||Zt.getConfig().modelName||"unknown";try{ye.trackModelCall({taskId:l,taskType:"chat",model:u,promptLength:e.length,hasUploadedImage:n.length>0,startTime:m});const d=Xn("text",i),p=Jn(d==null?void 0:d.binding),h=Qn(d==null?void 0:d.binding),g=La(n),y=Math.max(h-g,0),{geminiMessages:f,urlMap:x}=await Tu(t,{includeImageAttachments:p,maxImageCount:y}),{sanitized:z,urlMap:N}=Wo(e),O={...x,...N},T=$a(f),I=Math.max(h-T,0),b=[{type:"text",text:z}];if(p&&n.length>0&&I>0){const U=await Oa(n,I);b.push(...U)}const S=[];o&&S.push({role:"system",content:[{type:"text",text:o}]}),S.push(...f,{role:"user",content:b});let C="";if(await Zt.sendChat(S,U=>{if(c.aborted)return;const P=ju(U,O);C=P,r({type:"content",content:P})},c,i||void 0),c.aborted)throw new Error("Request cancelled");const R=Date.now()-m;return ye.trackModelSuccess({taskId:l,taskType:"chat",model:u,duration:R,resultSize:C.length}),r({type:"done"}),lt=null,C}catch(d){lt=null;const p=Date.now()-m;if(c.aborted||d.message==="Request cancelled"||d.name==="AbortError")throw ye.trackTaskCancellation({taskId:l,taskType:"chat",duration:p}),r({type:"done"}),new Error("Request cancelled");const h=d instanceof Error?d.message:"Unknown error occurred";throw ye.trackModelFailure({taskId:l,taskType:"chat",model:u,duration:p,error:h}),r({type:"error",error:h}),d}}function Pu(){lt&&(lt.abort(),lt=null)}function Au(){return lt!==null}const er={sendChatMessage:Nu,stopGeneration:Pu,isGenerating:Au},Vn="[[WORKFLOW_MESSAGE]]",Ru=["generate_image","generate_video","generate_long_video","generate_audio","generate_grid_image","generate_photo_wall","generate_inspiration_board","generate_ppt"];function zu(t){if(!Ru.includes(t.name)||!bo(t.name))return t;const e=at.get(),n=vo(t.name,{...t.arguments},{fallbackModels:{image:e.imageModelName||Dr(),video:e.videoModelName||Yt(),audio:e.audioModelName||es()}});return{...t,arguments:n}}function Du(t){const e=[];t.aiAnalysis&&e.push(t.aiAnalysis);const n=t.steps.filter(c=>c.status==="completed"),r=t.steps.filter(c=>c.status==="failed");if(n.length>0||r.length>0){const c=[];n.length>0&&c.push(`成功执行 ${n.length} 个工具`),r.length>0&&c.push(`${r.length} 个工具执行失败`),c.length>0&&e.push(`[执行结果: ${c.join(",")}]`)}const i=t.steps.map(c=>{const l={};for(const[m,u]of Object.entries(c.args||{}))m!=="context"&&(typeof u=="string"&&u.length>200?l[m]=u.substring(0,200)+"...":l[m]=u);return{mcp:c.mcp,args:l}}),o={content:e.join(`
|
|
636
|
-
`)||`已完成任务: ${t.name}`,next:i};return JSON.stringify(o)}function Lu(t){const e=[{type:"text",text:t.content}];if(t.attachments&&t.attachments.length>0)for(const n of t.attachments)e.push({type:"data-file",data:{filename:n.name,mediaType:n.type,url:n.data}});return{id:t.id,role:t.role===ot.USER?"user":"assistant",parts:e}}function $u(t,e){const r=t.parts.filter(c=>c.type==="text").map(c=>c.text).join(""),o=t.parts.filter(c=>c.type==="data-file").map((c,l)=>{const m=c.data;return{id:`${t.id}-att-${l}`,name:m.filename,type:m.mediaType,size:0,data:m.url,isBlob:!1}});return{id:t.id,sessionId:e,role:t.role==="user"?ot.USER:ot.ASSISTANT,content:r,timestamp:Date.now(),status:st.SUCCESS,attachments:o.length>0?o:void 0}}function Ou(t){return t.workflow&&t.content.startsWith(Vn)?{...t,content:Du(t.workflow)}:t}function tr(t){return t.parts.filter(e=>e.type==="text").map(e=>e.text).join("")}hu();function Fu(t){const{sessionId:e,temporaryModel:n,onToolCalls:r,onWorkflowUpdate:i}=t,o=a.useRef(_o()),c=a.useRef(r);c.current=r;const l=a.useRef(i);l.current=i;const m=a.useRef(n);m.current=n;const[u,d]=a.useState([]),[p,h]=a.useState("ready"),[g,y]=a.useState(!1),f=a.useRef(null),x=a.useRef([]),z=a.useRef(!1);a.useEffect(()=>{if(!e){d([]),x.current=[];return}(async()=>{y(!0);try{const C=await Se.getMessages(e);x.current=C,d(C.map(Lu))}catch(C){console.error("[useChatHandler] Failed to load messages:",C),d([]),x.current=[]}finally{y(!1)}})()},[e]);const N=a.useCallback(async S=>{if(!e)return;if(z.current){console.warn("[useChatHandler] Message already being sent, ignoring duplicate call");return}z.current=!0,h("submitted");const C=$u(S,e);await Se.addMessage(C),d(B=>[...B,S]);const R=await Se.getSession(e);await Se.updateSession(e,{updatedAt:Date.now(),messageCount:((R==null?void 0:R.messageCount)||0)+1});const U=Se.generateId();f.current=U;const P={id:U,role:"assistant",parts:[{type:"text",text:""}]};d(B=>[...B,P]),h("streaming");const J=x.current.map(Ou);J.push(C),x.current=[...x.current,C];const ee=tr(S);let X="",Q=!1;try{await er.sendChatMessage(J.slice(0,-1),ee,C.attachments||[],B=>{if(B.type==="content"&&B.content)X=B.content,d(_=>_.map(E=>E.id===U?{...E,parts:[{type:"text",text:X}]}:E));else if(B.type==="done"){const _=Er(X),E=Pr(X)||X;if(_.length>0&&c.current){const $=_.map(K=>zu(K)),re=async()=>{const K=[];for(const de of $)try{const ie=await ls.executeTool(de);K.push({toolCall:de,success:ie.success,data:ie.data,error:ie.error,taskId:ie.taskId})}catch(ie){K.push({toolCall:de,success:!1,error:ie.message||"工具执行失败"})}return K},fe=`${Vn}${U}`;d(K=>K.map(de=>de.id===U?{...de,parts:[{type:"text",text:fe}]}:de)),c.current($,U,re,E)}h("ready");const M={id:U,sessionId:e,role:ot.ASSISTANT,content:_.length>0?`${Vn}${U}`:X,timestamp:Date.now(),status:_.length>0?st.STREAMING:st.SUCCESS};Se.addMessage(M),x.current=[...x.current,M],Se.updateSession(e,{updatedAt:Date.now(),messageCount:((R==null?void 0:R.messageCount)||0)+2}),f.current=null,z.current=!1}else if(B.type==="error"&&B.error){Q=!0,h("error");const _=`❌ 错误: ${B.error}`;d(M=>M.map($=>$.id===U?{...$,parts:[{type:"text",text:_}]}:$));const E={id:U,sessionId:e,role:ot.ASSISTANT,content:_,timestamp:Date.now(),status:st.FAILED,error:B.error};Se.addMessage(E),x.current=[...x.current,E],f.current=null,z.current=!1}},m.current,o.current)}catch(B){if(B.message!=="Request cancelled"&&!Q){h("error"),console.error("[useChatHandler] Stream error:",B);const _=`❌ 错误: ${B.message||"未知错误"}`;if(d(E=>E.map(M=>M.id===U?{...M,parts:[{type:"text",text:_}]}:M)),e&&U){const E={id:U,sessionId:e,role:ot.ASSISTANT,content:_,timestamp:Date.now(),status:st.FAILED,error:B.message||"未知错误"};Se.addMessage(E),x.current=[...x.current,E]}}f.current=null,z.current=!1}},[e]),O=a.useCallback(async()=>{if(er.stopGeneration(),h("ready"),f.current&&e){const S=u.find(C=>C.id===f.current);if(S){const C=tr(S),R={id:S.id,sessionId:e,role:ot.ASSISTANT,content:C,timestamp:Date.now(),status:st.SUCCESS};await Se.addMessage(R)}f.current=null}},[e,u]),T=a.useCallback(S=>{if(u.length<2)return;const C=[...u].reverse().findIndex(J=>J.role==="user");if(C===-1)return;const R=u.length-1-C,U=u[R],P=u.slice(0,R+1);d(P),N(U)},[u,N]),I=a.useCallback((S,C)=>{d(S),C&&(x.current=C)},[]),b=a.useCallback((S,C)=>{x.current=x.current.map(R=>R.id===S?{...R,workflow:C}:R)},[]);return{messages:u,status:p,sendMessage:N,stop:O,regenerate:T,setMessages:d,setMessagesWithRaw:I,updateRawMessageWorkflow:b,isLoading:g}}const Uu=it.lazy(()=>dt(()=>Promise.resolve().then(()=>Qu),void 0,import.meta.url)),nr="[[WORKFLOW_MESSAGE]]";function Wu(t,e){switch(t){case"generate_image":return`生成图片: ${((e==null?void 0:e.prompt)||"").substring(0,30)}...`;case"generate_video":return`生成视频: ${((e==null?void 0:e.prompt)||"").substring(0,30)}...`;case"generate_audio":return`生成音频: ${((e==null?void 0:e.prompt)||"").substring(0,30)}...`;case"generate_text":return`生成文本: ${((e==null?void 0:e.prompt)||"").substring(0,30)}...`;case"generate_grid_image":return`生成宫格图: ${((e==null?void 0:e.theme)||"").substring(0,30)}...`;case"canvas_insertion":return"插入到画布";case"generate_mermaid":return"生成流程图";case"generate_mindmap":return"生成思维导图";default:return`执行 ${t}`}}const sr="chat-drawer-width",Hu=Math.max(375,window.innerWidth*.5),rr=375,Ho=a.forwardRef(({defaultOpen:t=!1,onOpenChange:e},n)=>{const[r,i]=a.useState(()=>Se.getDrawerState().isOpen??t),[o,c]=a.useState([]),[l,m]=a.useState(null),[u,d]=a.useState(!1),[p,h]=a.useState(()=>{const L=localStorage.getItem(sr);if(L){const w=parseInt(L,10);if(!isNaN(w)&&w>=rr)return Math.min(w,window.innerWidth-60)}return Hu}),[g,y]=a.useState(!1),f=a.useRef(null),[x,z]=a.useState(()=>zn("text").modelId),[N,O]=a.useState(()=>{const L=zn("text");return ht(L.profileId,L.modelId)}),[T,I]=a.useState(new Map),b=a.useRef(null),[S,C]=a.useState(null),{executeRetry:R,selectedContent:U,setIsDrawerOpen:P,setDrawerWidth:J}=Ua();a.useEffect(()=>{P(r)},[r,P]),a.useEffect(()=>{J(p)},[p,J]);const ee=it.useRef(null),X=it.useRef(null),{appState:Q,setAppState:B}=Wa();a.useEffect(()=>{if(!g)return;const L=V=>{const v=window.innerWidth-V.clientX,D=Math.max(rr,Math.min(v,window.innerWidth-60));h(D)},w=()=>{y(!1),localStorage.setItem(sr,String(p))};return document.addEventListener("mousemove",L),document.addEventListener("mouseup",w),document.body.style.userSelect="none",document.body.style.cursor="ew-resize",()=>{document.removeEventListener("mousemove",L),document.removeEventListener("mouseup",w),document.body.style.userSelect="",document.body.style.cursor=""}},[g,p]),a.useEffect(()=>{const L=()=>{const w=window.innerWidth-60;p>w&&h(w)};return window.addEventListener("resize",L),()=>window.removeEventListener("resize",L)},[p]);const _=a.useCallback(L=>{L.preventDefault(),y(!0)},[]),E=a.useCallback(async(L,w,V,v)=>{var G,Y;const W={id:`workflow-${Date.now()}`,name:"AI 智能生成",generationType:(G=L[0])!=null&&G.name.includes("video")?"video":(Y=L[0])!=null&&Y.name.includes("audio")?"audio":"image",prompt:v||"",aiAnalysis:v,count:L.length,steps:L.map((le,_e)=>({id:`step-${_e}`,mcp:le.name,status:"pending",description:Wu(le.name,le.arguments),args:le.arguments}))};I(le=>{const _e=new Map(le);return _e.set(w,W),_e}),b.current=w,Se.updateMessage(w,{workflow:W});try{const le=await V();ye.track("chat_tool_execution_complete",{success:!0,resultCount:le.length}),ye.track("ai_modality_used",{modality:"agent",action:"tool_execution_completed",source:"chat_drawer",success:!0,toolCount:L.length,resultCount:le.length}),I(_e=>{const k=new Map(_e),H=k.get(w);if(H){const F={...H,steps:H.steps.map((Z,oe)=>{const te=le[oe];return{...Z,status:te!=null&&te.success?"completed":"failed",error:te==null?void 0:te.error,result:te==null?void 0:te.data}})};k.set(w,F),Se.updateMessage(w,{workflow:F,status:st.SUCCESS})}return k})}catch(le){console.error("[ChatDrawer] Tool execution failed:",le),I(_e=>{const k=new Map(_e),H=k.get(w);if(H){const F={...H,steps:H.steps.map(Z=>({...Z,status:"failed",error:le.message||"执行失败"}))};k.set(w,F),Se.updateMessage(w,{workflow:F,status:st.FAILED})}return k})}},[]),M=Fu({sessionId:l,temporaryModel:N||x,onToolCalls:E}),$=a.useRef(M.sendMessage);$.current=M.sendMessage,a.useEffect(()=>{(async()=>{const w=Se.getDrawerState(),V=await Se.getAllSessions();c(V);let v=null;if(w.activeSessionId?(v=w.activeSessionId,m(w.activeSessionId)):V.length>0&&(v=V[0].id,m(V[0].id)),v)try{const D=await Se.getMessages(v),W=new Map;for(const Y of D)Y.workflow&&W.set(Y.id,Y.workflow);I(W);const G=D.find(Y=>Y.workflow&&Y.status===st.STREAMING);b.current=(G==null?void 0:G.id)||null}catch(D){console.error("[ChatDrawer] Failed to load workflow messages:",D)}})()},[]),a.useEffect(()=>{Se.setDrawerState({isOpen:r,activeSessionId:l})},[r,l]),a.useEffect(()=>{if(l&&pe.current){const L=pe.current;pe.current=null,setTimeout(()=>{$.current(L)},100)}},[l]),a.useEffect(()=>{if(!Q.openSettings&&pe.current){const L=at.get();if(L!=null&&L.apiKey){const w=pe.current;pe.current=null,l?setTimeout(()=>{$.current(w)},100):(async()=>{const V=await Se.createSession();c(v=>[V,...v]),m(V.id),pe.current=w})()}}},[Q.openSettings,l]),a.useEffect(()=>{const L=w=>{w.key==="Escape"&&r&&(i(!1),e==null||e(!1))};return window.addEventListener("keydown",L),()=>window.removeEventListener("keydown",L)},[r,e]),a.useEffect(()=>{let L=null;return(async()=>{const{workflowSubmissionService:V}=await dt(async()=>{const{workflowSubmissionService:v}=await import("./workflow-submission-service-BIGFW4s4.js").then(D=>D.a);return{workflowSubmissionService:v}},__vite__mapDeps([0,2]),import.meta.url);L=V.subscribeToAllEvents(v=>{const D=v;I(W=>{let G=null;for(const[k,H]of W.entries())if(H.id===D.workflowId){G=k;break}if(!G)return W;const Y=W.get(G);if(!Y)return W;const le=new Map(W);let _e;switch(D.type){case"step":{_e={...Y,steps:Y.steps.map(k=>k.id===D.stepId?{...k,status:D.status||k.status,result:D.result??k.result,error:D.error??k.error}:k)};break}case"steps_added":{const H=(D.steps||[]).map(F=>({id:F.id,mcp:F.mcp,args:F.args,description:F.description,status:F.status}));_e={...Y,steps:[...Y.steps,...H]};break}case"completed":case"failed":{const k=D.type==="completed"?"completed":"failed";_e={...Y,status:k,steps:Y.steps.map(H=>{if(H.status==="running"||H.status==="pending"){const F=H.result;return F!=null&&F.taskId?H:{...H,status:k,error:D.type==="failed"?D.error:void 0}}return H})};break}default:return W}return le.set(G,_e),Se.updateMessage(G,{workflow:_e}),le})})})().catch(V=>{console.error("[ChatDrawer] Failed to setup workflow sync:",V)}),()=>{L==null||L.unsubscribe()}},[]),a.useEffect(()=>{if(!u)return;const L=V=>{const v=V.target;v.closest(".t-dialog")===null&&ee.current&&!ee.current.contains(v)&&X.current&&!X.current.contains(v)&&d(!1)},w=setTimeout(()=>{document.addEventListener("mousedown",L)},100);return()=>{clearTimeout(w),document.removeEventListener("mousedown",L)}},[u]);const re=a.useCallback(()=>{i(L=>{const w=!L;return e==null||e(w),w})},[e]),fe=a.useCallback(()=>{i(!1),e==null||e(!1)},[e]),K=a.useCallback(async()=>{ye.track("chat_session_create");const L=await Se.createSession();c(w=>[L,...w]),m(L.id),d(!1),I(new Map),b.current=null,z(void 0)},[]),de=a.useCallback(()=>{d(L=>!L)},[]),ie=a.useCallback(async L=>{ye.track("chat_session_select"),m(L),d(!1),z(void 0);try{const w=await Se.getMessages(L),V=new Map;for(const D of w)D.workflow&&V.set(D.id,D.workflow);I(V);const v=w.find(D=>D.workflow&&D.status===st.STREAMING);b.current=(v==null?void 0:v.id)||null}catch(w){console.error("[ChatDrawer] Failed to load workflow messages:",w),I(new Map),b.current=null}},[]),ue=a.useCallback(async L=>{ye.track("chat_session_delete"),await Se.deleteSession(L),c(w=>{const V=w.filter(v=>v.id!==L);if(l===L){const v=V[0]||null;m((v==null?void 0:v.id)||null)}return V})},[l]),xe=a.useCallback(async(L,w)=>{ye.track("chat_session_rename"),await Se.updateSession(L,{title:w}),c(V=>V.map(v=>v.id===L?{...v,title:w}:v))},[]),pe=it.useRef(null),ae=a.useCallback(async L=>{try{ye.track("chat_message_send",{hasImages:L.parts.some(V=>V.type==="image_url")}),ye.track("ai_modality_used",{modality:"agent",action:"message_send",source:"chat_drawer",hasImages:L.parts.some(V=>V.type==="image_url"),partCount:L.parts.length,textLength:L.parts.filter(V=>V.type==="text").reduce((V,v)=>V+String(v.text||"").length,0)});const w=at.get();if(!(w!=null&&w.apiKey)){pe.current=L,B({...Q,openSettings:!0});return}if(pe.current=null,!l){const V=await Se.createSession();c(v=>[V,...v]),m(V.id),pe.current=L;return}await M.sendMessage(L)}catch(w){console.error("[ChatDrawer] send message failed:",w),pe.current=L}},[l,M,Q,B]),q=a.useCallback(async L=>{var Ve;const{context:w,workflow:V,textModel:v,autoOpen:D=!0}=L;D&&(i(!0),e==null||e(!0)),v&&z(v);const W=await Se.createSession(),G=[];w.userInstruction&&G.push(w.userInstruction),w.selection.texts.length>0&&G.push(`
|
|
636
|
+
`)||`已完成任务: ${t.name}`,next:i};return JSON.stringify(o)}function Lu(t){const e=[{type:"text",text:t.content}];if(t.attachments&&t.attachments.length>0)for(const n of t.attachments)e.push({type:"data-file",data:{filename:n.name,mediaType:n.type,url:n.data}});return{id:t.id,role:t.role===ot.USER?"user":"assistant",parts:e}}function $u(t,e){const r=t.parts.filter(c=>c.type==="text").map(c=>c.text).join(""),o=t.parts.filter(c=>c.type==="data-file").map((c,l)=>{const m=c.data;return{id:`${t.id}-att-${l}`,name:m.filename,type:m.mediaType,size:0,data:m.url,isBlob:!1}});return{id:t.id,sessionId:e,role:t.role==="user"?ot.USER:ot.ASSISTANT,content:r,timestamp:Date.now(),status:st.SUCCESS,attachments:o.length>0?o:void 0}}function Ou(t){return t.workflow&&t.content.startsWith(Vn)?{...t,content:Du(t.workflow)}:t}function tr(t){return t.parts.filter(e=>e.type==="text").map(e=>e.text).join("")}hu();function Fu(t){const{sessionId:e,temporaryModel:n,onToolCalls:r,onWorkflowUpdate:i}=t,o=a.useRef(_o()),c=a.useRef(r);c.current=r;const l=a.useRef(i);l.current=i;const m=a.useRef(n);m.current=n;const[u,d]=a.useState([]),[p,h]=a.useState("ready"),[g,y]=a.useState(!1),f=a.useRef(null),x=a.useRef([]),z=a.useRef(!1);a.useEffect(()=>{if(!e){d([]),x.current=[];return}(async()=>{y(!0);try{const C=await Se.getMessages(e);x.current=C,d(C.map(Lu))}catch(C){console.error("[useChatHandler] Failed to load messages:",C),d([]),x.current=[]}finally{y(!1)}})()},[e]);const N=a.useCallback(async S=>{if(!e)return;if(z.current){console.warn("[useChatHandler] Message already being sent, ignoring duplicate call");return}z.current=!0,h("submitted");const C=$u(S,e);await Se.addMessage(C),d(B=>[...B,S]);const R=await Se.getSession(e);await Se.updateSession(e,{updatedAt:Date.now(),messageCount:((R==null?void 0:R.messageCount)||0)+1});const U=Se.generateId();f.current=U;const P={id:U,role:"assistant",parts:[{type:"text",text:""}]};d(B=>[...B,P]),h("streaming");const J=x.current.map(Ou);J.push(C),x.current=[...x.current,C];const ee=tr(S);let X="",Q=!1;try{await er.sendChatMessage(J.slice(0,-1),ee,C.attachments||[],B=>{if(B.type==="content"&&B.content)X=B.content,d(_=>_.map(E=>E.id===U?{...E,parts:[{type:"text",text:X}]}:E));else if(B.type==="done"){const _=Er(X),E=Pr(X)||X;if(_.length>0&&c.current){const $=_.map(K=>zu(K)),re=async()=>{const K=[];for(const de of $)try{const ie=await ls.executeTool(de);K.push({toolCall:de,success:ie.success,data:ie.data,error:ie.error,taskId:ie.taskId})}catch(ie){K.push({toolCall:de,success:!1,error:ie.message||"工具执行失败"})}return K},fe=`${Vn}${U}`;d(K=>K.map(de=>de.id===U?{...de,parts:[{type:"text",text:fe}]}:de)),c.current($,U,re,E)}h("ready");const M={id:U,sessionId:e,role:ot.ASSISTANT,content:_.length>0?`${Vn}${U}`:X,timestamp:Date.now(),status:_.length>0?st.STREAMING:st.SUCCESS};Se.addMessage(M),x.current=[...x.current,M],Se.updateSession(e,{updatedAt:Date.now(),messageCount:((R==null?void 0:R.messageCount)||0)+2}),f.current=null,z.current=!1}else if(B.type==="error"&&B.error){Q=!0,h("error");const _=`❌ 错误: ${B.error}`;d(M=>M.map($=>$.id===U?{...$,parts:[{type:"text",text:_}]}:$));const E={id:U,sessionId:e,role:ot.ASSISTANT,content:_,timestamp:Date.now(),status:st.FAILED,error:B.error};Se.addMessage(E),x.current=[...x.current,E],f.current=null,z.current=!1}},m.current,o.current)}catch(B){if(B.message!=="Request cancelled"&&!Q){h("error"),console.error("[useChatHandler] Stream error:",B);const _=`❌ 错误: ${B.message||"未知错误"}`;if(d(E=>E.map(M=>M.id===U?{...M,parts:[{type:"text",text:_}]}:M)),e&&U){const E={id:U,sessionId:e,role:ot.ASSISTANT,content:_,timestamp:Date.now(),status:st.FAILED,error:B.message||"未知错误"};Se.addMessage(E),x.current=[...x.current,E]}}f.current=null,z.current=!1}},[e]),O=a.useCallback(async()=>{if(er.stopGeneration(),h("ready"),f.current&&e){const S=u.find(C=>C.id===f.current);if(S){const C=tr(S),R={id:S.id,sessionId:e,role:ot.ASSISTANT,content:C,timestamp:Date.now(),status:st.SUCCESS};await Se.addMessage(R)}f.current=null}},[e,u]),T=a.useCallback(S=>{if(u.length<2)return;const C=[...u].reverse().findIndex(J=>J.role==="user");if(C===-1)return;const R=u.length-1-C,U=u[R],P=u.slice(0,R+1);d(P),N(U)},[u,N]),I=a.useCallback((S,C)=>{d(S),C&&(x.current=C)},[]),b=a.useCallback((S,C)=>{x.current=x.current.map(R=>R.id===S?{...R,workflow:C}:R)},[]);return{messages:u,status:p,sendMessage:N,stop:O,regenerate:T,setMessages:d,setMessagesWithRaw:I,updateRawMessageWorkflow:b,isLoading:g}}const Uu=it.lazy(()=>dt(()=>Promise.resolve().then(()=>Qu),void 0,import.meta.url)),nr="[[WORKFLOW_MESSAGE]]";function Wu(t,e){switch(t){case"generate_image":return`生成图片: ${((e==null?void 0:e.prompt)||"").substring(0,30)}...`;case"generate_video":return`生成视频: ${((e==null?void 0:e.prompt)||"").substring(0,30)}...`;case"generate_audio":return`生成音频: ${((e==null?void 0:e.prompt)||"").substring(0,30)}...`;case"generate_text":return`生成文本: ${((e==null?void 0:e.prompt)||"").substring(0,30)}...`;case"generate_grid_image":return`生成宫格图: ${((e==null?void 0:e.theme)||"").substring(0,30)}...`;case"canvas_insertion":return"插入到画布";case"generate_mermaid":return"生成流程图";case"generate_mindmap":return"生成思维导图";default:return`执行 ${t}`}}const sr="chat-drawer-width",Hu=Math.max(375,window.innerWidth*.5),rr=375,Ho=a.forwardRef(({defaultOpen:t=!1,onOpenChange:e},n)=>{const[r,i]=a.useState(()=>Se.getDrawerState().isOpen??t),[o,c]=a.useState([]),[l,m]=a.useState(null),[u,d]=a.useState(!1),[p,h]=a.useState(()=>{const L=localStorage.getItem(sr);if(L){const w=parseInt(L,10);if(!isNaN(w)&&w>=rr)return Math.min(w,window.innerWidth-60)}return Hu}),[g,y]=a.useState(!1),f=a.useRef(null),[x,z]=a.useState(()=>zn("text").modelId),[N,O]=a.useState(()=>{const L=zn("text");return ht(L.profileId,L.modelId)}),[T,I]=a.useState(new Map),b=a.useRef(null),[S,C]=a.useState(null),{executeRetry:R,selectedContent:U,setIsDrawerOpen:P,setDrawerWidth:J}=Ua();a.useEffect(()=>{P(r)},[r,P]),a.useEffect(()=>{J(p)},[p,J]);const ee=it.useRef(null),X=it.useRef(null),{appState:Q,setAppState:B}=Wa();a.useEffect(()=>{if(!g)return;const L=V=>{const v=window.innerWidth-V.clientX,D=Math.max(rr,Math.min(v,window.innerWidth-60));h(D)},w=()=>{y(!1),localStorage.setItem(sr,String(p))};return document.addEventListener("mousemove",L),document.addEventListener("mouseup",w),document.body.style.userSelect="none",document.body.style.cursor="ew-resize",()=>{document.removeEventListener("mousemove",L),document.removeEventListener("mouseup",w),document.body.style.userSelect="",document.body.style.cursor=""}},[g,p]),a.useEffect(()=>{const L=()=>{const w=window.innerWidth-60;p>w&&h(w)};return window.addEventListener("resize",L),()=>window.removeEventListener("resize",L)},[p]);const _=a.useCallback(L=>{L.preventDefault(),y(!0)},[]),E=a.useCallback(async(L,w,V,v)=>{var G,Y;const W={id:`workflow-${Date.now()}`,name:"AI 智能生成",generationType:(G=L[0])!=null&&G.name.includes("video")?"video":(Y=L[0])!=null&&Y.name.includes("audio")?"audio":"image",prompt:v||"",aiAnalysis:v,count:L.length,steps:L.map((le,_e)=>({id:`step-${_e}`,mcp:le.name,status:"pending",description:Wu(le.name,le.arguments),args:le.arguments}))};I(le=>{const _e=new Map(le);return _e.set(w,W),_e}),b.current=w,Se.updateMessage(w,{workflow:W});try{const le=await V();ye.track("chat_tool_execution_complete",{success:!0,resultCount:le.length}),ye.track("ai_modality_used",{modality:"agent",action:"tool_execution_completed",source:"chat_drawer",success:!0,toolCount:L.length,resultCount:le.length}),I(_e=>{const k=new Map(_e),H=k.get(w);if(H){const F={...H,steps:H.steps.map((Z,oe)=>{const te=le[oe];return{...Z,status:te!=null&&te.success?"completed":"failed",error:te==null?void 0:te.error,result:te==null?void 0:te.data}})};k.set(w,F),Se.updateMessage(w,{workflow:F,status:st.SUCCESS})}return k})}catch(le){console.error("[ChatDrawer] Tool execution failed:",le),I(_e=>{const k=new Map(_e),H=k.get(w);if(H){const F={...H,steps:H.steps.map(Z=>({...Z,status:"failed",error:le.message||"执行失败"}))};k.set(w,F),Se.updateMessage(w,{workflow:F,status:st.FAILED})}return k})}},[]),M=Fu({sessionId:l,temporaryModel:N||x,onToolCalls:E}),$=a.useRef(M.sendMessage);$.current=M.sendMessage,a.useEffect(()=>{(async()=>{const w=Se.getDrawerState(),V=await Se.getAllSessions();c(V);let v=null;if(w.activeSessionId?(v=w.activeSessionId,m(w.activeSessionId)):V.length>0&&(v=V[0].id,m(V[0].id)),v)try{const D=await Se.getMessages(v),W=new Map;for(const Y of D)Y.workflow&&W.set(Y.id,Y.workflow);I(W);const G=D.find(Y=>Y.workflow&&Y.status===st.STREAMING);b.current=(G==null?void 0:G.id)||null}catch(D){console.error("[ChatDrawer] Failed to load workflow messages:",D)}})()},[]),a.useEffect(()=>{Se.setDrawerState({isOpen:r,activeSessionId:l})},[r,l]),a.useEffect(()=>{if(l&&pe.current){const L=pe.current;pe.current=null,setTimeout(()=>{$.current(L)},100)}},[l]),a.useEffect(()=>{if(!Q.openSettings&&pe.current){const L=at.get();if(L!=null&&L.apiKey){const w=pe.current;pe.current=null,l?setTimeout(()=>{$.current(w)},100):(async()=>{const V=await Se.createSession();c(v=>[V,...v]),m(V.id),pe.current=w})()}}},[Q.openSettings,l]),a.useEffect(()=>{const L=w=>{w.key==="Escape"&&r&&(i(!1),e==null||e(!1))};return window.addEventListener("keydown",L),()=>window.removeEventListener("keydown",L)},[r,e]),a.useEffect(()=>{let L=null;return(async()=>{const{workflowSubmissionService:V}=await dt(async()=>{const{workflowSubmissionService:v}=await import("./workflow-submission-service-Ce0cpj8E.js").then(D=>D.a);return{workflowSubmissionService:v}},__vite__mapDeps([0,2]),import.meta.url);L=V.subscribeToAllEvents(v=>{const D=v;I(W=>{let G=null;for(const[k,H]of W.entries())if(H.id===D.workflowId){G=k;break}if(!G)return W;const Y=W.get(G);if(!Y)return W;const le=new Map(W);let _e;switch(D.type){case"step":{_e={...Y,steps:Y.steps.map(k=>k.id===D.stepId?{...k,status:D.status||k.status,result:D.result??k.result,error:D.error??k.error}:k)};break}case"steps_added":{const H=(D.steps||[]).map(F=>({id:F.id,mcp:F.mcp,args:F.args,description:F.description,status:F.status}));_e={...Y,steps:[...Y.steps,...H]};break}case"completed":case"failed":{const k=D.type==="completed"?"completed":"failed";_e={...Y,status:k,steps:Y.steps.map(H=>{if(H.status==="running"||H.status==="pending"){const F=H.result;return F!=null&&F.taskId?H:{...H,status:k,error:D.type==="failed"?D.error:void 0}}return H})};break}default:return W}return le.set(G,_e),Se.updateMessage(G,{workflow:_e}),le})})})().catch(V=>{console.error("[ChatDrawer] Failed to setup workflow sync:",V)}),()=>{L==null||L.unsubscribe()}},[]),a.useEffect(()=>{if(!u)return;const L=V=>{const v=V.target;v.closest(".t-dialog")===null&&ee.current&&!ee.current.contains(v)&&X.current&&!X.current.contains(v)&&d(!1)},w=setTimeout(()=>{document.addEventListener("mousedown",L)},100);return()=>{clearTimeout(w),document.removeEventListener("mousedown",L)}},[u]);const re=a.useCallback(()=>{i(L=>{const w=!L;return e==null||e(w),w})},[e]),fe=a.useCallback(()=>{i(!1),e==null||e(!1)},[e]),K=a.useCallback(async()=>{ye.track("chat_session_create");const L=await Se.createSession();c(w=>[L,...w]),m(L.id),d(!1),I(new Map),b.current=null,z(void 0)},[]),de=a.useCallback(()=>{d(L=>!L)},[]),ie=a.useCallback(async L=>{ye.track("chat_session_select"),m(L),d(!1),z(void 0);try{const w=await Se.getMessages(L),V=new Map;for(const D of w)D.workflow&&V.set(D.id,D.workflow);I(V);const v=w.find(D=>D.workflow&&D.status===st.STREAMING);b.current=(v==null?void 0:v.id)||null}catch(w){console.error("[ChatDrawer] Failed to load workflow messages:",w),I(new Map),b.current=null}},[]),ue=a.useCallback(async L=>{ye.track("chat_session_delete"),await Se.deleteSession(L),c(w=>{const V=w.filter(v=>v.id!==L);if(l===L){const v=V[0]||null;m((v==null?void 0:v.id)||null)}return V})},[l]),xe=a.useCallback(async(L,w)=>{ye.track("chat_session_rename"),await Se.updateSession(L,{title:w}),c(V=>V.map(v=>v.id===L?{...v,title:w}:v))},[]),pe=it.useRef(null),ae=a.useCallback(async L=>{try{ye.track("chat_message_send",{hasImages:L.parts.some(V=>V.type==="image_url")}),ye.track("ai_modality_used",{modality:"agent",action:"message_send",source:"chat_drawer",hasImages:L.parts.some(V=>V.type==="image_url"),partCount:L.parts.length,textLength:L.parts.filter(V=>V.type==="text").reduce((V,v)=>V+String(v.text||"").length,0)});const w=at.get();if(!(w!=null&&w.apiKey)){pe.current=L,B({...Q,openSettings:!0});return}if(pe.current=null,!l){const V=await Se.createSession();c(v=>[V,...v]),m(V.id),pe.current=L;return}await M.sendMessage(L)}catch(w){console.error("[ChatDrawer] send message failed:",w),pe.current=L}},[l,M,Q,B]),q=a.useCallback(async L=>{var Ve;const{context:w,workflow:V,textModel:v,autoOpen:D=!0}=L;D&&(i(!0),e==null||e(!0)),v&&z(v);const W=await Se.createSession(),G=[];w.userInstruction&&G.push(w.userInstruction),w.selection.texts.length>0&&G.push(`
|
|
637
637
|
📝 选中的文本:
|
|
638
638
|
${w.selection.texts.join(`
|
|
639
639
|
`)}`),w.selection.texts.length===0&&!w.userInstruction&&w.finalPrompt&&G.push(`
|
|
@@ -647,4 +647,4 @@ ${Y.join(" • ")}`);const _e=G.join(`
|
|
|
647
647
|
---
|
|
648
648
|
`);h=I[0],I[1].split(" • ").forEach(S=>{const C=S.replace(/模型:\s*/,"").replace(/数量:\s*/,"").replace(/尺寸:\s*/,"").trim();if(C){let R=s.jsx(In,{size:"12px"});S.includes("数量")&&(R=s.jsx(kn,{size:"12px"})),S.includes("尺寸")&&(R=s.jsx(Ns,{size:"12px"})),g.push({label:C,icon:R})}})}else{const I=h.split(`
|
|
649
649
|
`),b=[];for(const S of I){const C=S.trim();if(C.startsWith("模型:")||C.startsWith("数量:")||C.startsWith("提示词:")){const R=C.replace(/.*:\s*/,"").trim();let U=s.jsx(In,{size:"12px"});C.includes("数量")&&(U=s.jsx(kn,{size:"12px"})),g.push({label:R,icon:U})}else C.startsWith("📝 选中的文本:")?g.push({label:C.replace("📝 ","").trim(),icon:s.jsx(Es,{size:"12px"})}):C&&!C.startsWith("💬 用户指令:")&&b.push(S)}h=b.join(`
|
|
650
|
-
`).trim()}if(!h&&g.length>0){const I=u.match(/💬 用户指令:\s*([\s\S]*?)(?=\n模型:|\n数量:|$)/);I&&I[1].trim()&&(h=I[1].trim())}return{text:h||u,meta:g,images:d}},[t.parts,t.aiContext]),c=a.useCallback(u=>{u.stopPropagation()},[]),l=a.useCallback(u=>{if((u.ctrlKey||u.metaKey)&&u.key==="c"){const p=window.getSelection(),h=p==null?void 0:p.toString();h&&(Ar(h).catch(g=>{console.error("Failed to copy text:",g)}),u.stopPropagation())}},[]);a.useEffect(()=>{const u=n.current;if(u)return u.addEventListener("pointerdown",c),u.addEventListener("pointerup",c),u.addEventListener("mousedown",c),u.addEventListener("mouseup",c),u.addEventListener("click",c),u.addEventListener("keydown",l),()=>{u.removeEventListener("pointerdown",c),u.removeEventListener("pointerup",c),u.removeEventListener("mousedown",c),u.removeEventListener("mouseup",c),u.removeEventListener("click",c),u.removeEventListener("keydown",l)}},[c,l]);const m=o.length===0&&(!i||i.length===0);return s.jsxs("div",{className:`user-bubble chat-message chat-message--user ${m?"user-bubble--text-only":""} ${e}`,children:[s.jsx("div",{className:"chat-message-avatar",children:s.jsx("span",{children:"👤"})}),s.jsxs("div",{className:"user-bubble__content chat-message-content",children:[o.length>0&&s.jsx("div",{className:`user-bubble__images user-bubble__images--${Math.min(o.length,4)}`,children:o.map((u,d)=>s.jsx("div",{className:"user-bubble__image-wrapper",children:s.jsx("img",{src:u.url,alt:u.filename,className:"user-bubble__image",loading:"lazy"})},d))}),r&&s.jsx("div",{ref:n,className:"user-bubble__text user-bubble__text--selectable",children:r}),i&&i.length>0&&s.jsx("div",{className:"user-bubble__meta-tags",children:i.map((u,d)=>s.jsxs("div",{className:"user-bubble__meta-tag",children:[s.jsx("span",{className:"user-bubble__meta-icon",children:u.icon}),s.jsx("span",{className:"user-bubble__meta-label",children:u.label})]},d))})]})]})},or="[[WORKFLOW_MESSAGE]]",ir=({handler:t,workflowMessages:e,retryingWorkflowId:n,handleWorkflowRetry:r,className:i="chat-section"})=>{const o=a.useCallback(d=>{const p=d.parts.find(h=>h.type==="text");if(p&&"text"in p){const h=p.text;if(h.startsWith(or))return h.replace(or,"")}return null},[]),c=a.useCallback(d=>d.parts.some(p=>p.type==="data-file"),[]),l=a.useCallback(d=>{let p=null,h=null;for(const g of d.parts)if(g.type==="text"){if(p===null){p=g.text;continue}h||(h=[p]),h.push(g.text)}return h?h.join(""):p??""},[]),m=t.status==="submitted"||t.status==="streaming",u=t.messages.length===0&&!m;return s.jsx("div",{className:i,children:s.jsx("div",{className:"chat-messages",children:s.jsxs("div",{className:"chat-messages-list",children:[t.messages.map((d,p)=>{const h=o(d);if(h){const f=e.get(h);if(f)return s.jsx(Xu,{workflow:f,onRetry:x=>r(h,f,x),isRetrying:n===h},d.id)}const g=d.parts.some(f=>f.type==="text"&&"text"in f&&typeof f.text=="string"&&f.text.startsWith("❌ 错误")),y=`chat-message chat-message--${d.role} ${g?"chat-message--error":""}`;return d.role==="user"&&c(d)?s.jsx(Ju,{message:d},d.id):s.jsxs("div",{className:y,"data-message-id":d.id,"data-message-last":p===t.messages.length-1,children:[s.jsx("div",{className:"chat-message-avatar",children:s.jsx("span",{children:d.role==="user"?"👤":"🤖"})}),s.jsx("div",{className:"chat-message-content",children:s.jsx(Br,{markdown:l(d),className:"chat-markdown"})}),d.role==="assistant"&&!g&&s.jsx("div",{className:"chat-message-actions"})]},d.id)}),m&&s.jsxs("div",{className:"chat-loading",children:[s.jsx("div",{className:"chat-loading__spinner"}),s.jsx("span",{children:"思考中..."})]}),u&&s.jsxs("div",{className:"chat-empty",children:[s.jsx("h3",{children:"开始对话"}),s.jsx("p",{children:"输入消息与AI助手交流"})]})]})})})},Qu=Object.freeze(Object.defineProperty({__proto__:null,ChatMessagesArea:ir,default:ir},Symbol.toStringTag,{value:"Module"}));function em(t){let e=t;return e=e.replace(/\[([^\]]*[:\,\=\(\)\|\/\\][^\]]*)\]/g,(n,r)=>r.startsWith('"')&&r.endsWith('"')||r.startsWith("'")&&r.endsWith("'")?n:`["${r}"]`),e=e.replace(/\(([^\)]*[:\,\=\[\]\|\/\\][^\)]*)\)/g,(n,r)=>r.startsWith('"')&&r.endsWith('"')||r.startsWith("'")&&r.endsWith("'")?n:`("${r}")`),e=e.replace(/\{([^\}]*[:\,\=\[\]\(\)\|\/\\][^\}]*)\}/g,(n,r)=>r.startsWith('"')&&r.endsWith('"')||r.startsWith("'")&&r.endsWith("'")?n:`{"${r}"}`),e}const tm=({code:t,className:e=""})=>{const n=a.useRef(null),[r,i]=a.useState(null),[o,c]=a.useState(!0),[l,m]=a.useState(""),[u,d]=a.useState(!1),[p,h]=a.useState("");if(a.useEffect(()=>{let y=!1;return(async()=>{if(!(!n.current||!t))try{c(!0),i(null);const x=em(t);m(x);const z=(await dt(async()=>{const{default:T}=await import("./diagram-engines-
|
|
650
|
+
`).trim()}if(!h&&g.length>0){const I=u.match(/💬 用户指令:\s*([\s\S]*?)(?=\n模型:|\n数量:|$)/);I&&I[1].trim()&&(h=I[1].trim())}return{text:h||u,meta:g,images:d}},[t.parts,t.aiContext]),c=a.useCallback(u=>{u.stopPropagation()},[]),l=a.useCallback(u=>{if((u.ctrlKey||u.metaKey)&&u.key==="c"){const p=window.getSelection(),h=p==null?void 0:p.toString();h&&(Ar(h).catch(g=>{console.error("Failed to copy text:",g)}),u.stopPropagation())}},[]);a.useEffect(()=>{const u=n.current;if(u)return u.addEventListener("pointerdown",c),u.addEventListener("pointerup",c),u.addEventListener("mousedown",c),u.addEventListener("mouseup",c),u.addEventListener("click",c),u.addEventListener("keydown",l),()=>{u.removeEventListener("pointerdown",c),u.removeEventListener("pointerup",c),u.removeEventListener("mousedown",c),u.removeEventListener("mouseup",c),u.removeEventListener("click",c),u.removeEventListener("keydown",l)}},[c,l]);const m=o.length===0&&(!i||i.length===0);return s.jsxs("div",{className:`user-bubble chat-message chat-message--user ${m?"user-bubble--text-only":""} ${e}`,children:[s.jsx("div",{className:"chat-message-avatar",children:s.jsx("span",{children:"👤"})}),s.jsxs("div",{className:"user-bubble__content chat-message-content",children:[o.length>0&&s.jsx("div",{className:`user-bubble__images user-bubble__images--${Math.min(o.length,4)}`,children:o.map((u,d)=>s.jsx("div",{className:"user-bubble__image-wrapper",children:s.jsx("img",{src:u.url,alt:u.filename,className:"user-bubble__image",loading:"lazy"})},d))}),r&&s.jsx("div",{ref:n,className:"user-bubble__text user-bubble__text--selectable",children:r}),i&&i.length>0&&s.jsx("div",{className:"user-bubble__meta-tags",children:i.map((u,d)=>s.jsxs("div",{className:"user-bubble__meta-tag",children:[s.jsx("span",{className:"user-bubble__meta-icon",children:u.icon}),s.jsx("span",{className:"user-bubble__meta-label",children:u.label})]},d))})]})]})},or="[[WORKFLOW_MESSAGE]]",ir=({handler:t,workflowMessages:e,retryingWorkflowId:n,handleWorkflowRetry:r,className:i="chat-section"})=>{const o=a.useCallback(d=>{const p=d.parts.find(h=>h.type==="text");if(p&&"text"in p){const h=p.text;if(h.startsWith(or))return h.replace(or,"")}return null},[]),c=a.useCallback(d=>d.parts.some(p=>p.type==="data-file"),[]),l=a.useCallback(d=>{let p=null,h=null;for(const g of d.parts)if(g.type==="text"){if(p===null){p=g.text;continue}h||(h=[p]),h.push(g.text)}return h?h.join(""):p??""},[]),m=t.status==="submitted"||t.status==="streaming",u=t.messages.length===0&&!m;return s.jsx("div",{className:i,children:s.jsx("div",{className:"chat-messages",children:s.jsxs("div",{className:"chat-messages-list",children:[t.messages.map((d,p)=>{const h=o(d);if(h){const f=e.get(h);if(f)return s.jsx(Xu,{workflow:f,onRetry:x=>r(h,f,x),isRetrying:n===h},d.id)}const g=d.parts.some(f=>f.type==="text"&&"text"in f&&typeof f.text=="string"&&f.text.startsWith("❌ 错误")),y=`chat-message chat-message--${d.role} ${g?"chat-message--error":""}`;return d.role==="user"&&c(d)?s.jsx(Ju,{message:d},d.id):s.jsxs("div",{className:y,"data-message-id":d.id,"data-message-last":p===t.messages.length-1,children:[s.jsx("div",{className:"chat-message-avatar",children:s.jsx("span",{children:d.role==="user"?"👤":"🤖"})}),s.jsx("div",{className:"chat-message-content",children:s.jsx(Br,{markdown:l(d),className:"chat-markdown"})}),d.role==="assistant"&&!g&&s.jsx("div",{className:"chat-message-actions"})]},d.id)}),m&&s.jsxs("div",{className:"chat-loading",children:[s.jsx("div",{className:"chat-loading__spinner"}),s.jsx("span",{children:"思考中..."})]}),u&&s.jsxs("div",{className:"chat-empty",children:[s.jsx("h3",{children:"开始对话"}),s.jsx("p",{children:"输入消息与AI助手交流"})]})]})})})},Qu=Object.freeze(Object.defineProperty({__proto__:null,ChatMessagesArea:ir,default:ir},Symbol.toStringTag,{value:"Module"}));function em(t){let e=t;return e=e.replace(/\[([^\]]*[:\,\=\(\)\|\/\\][^\]]*)\]/g,(n,r)=>r.startsWith('"')&&r.endsWith('"')||r.startsWith("'")&&r.endsWith("'")?n:`["${r}"]`),e=e.replace(/\(([^\)]*[:\,\=\[\]\|\/\\][^\)]*)\)/g,(n,r)=>r.startsWith('"')&&r.endsWith('"')||r.startsWith("'")&&r.endsWith("'")?n:`("${r}")`),e=e.replace(/\{([^\}]*[:\,\=\[\]\(\)\|\/\\][^\}]*)\}/g,(n,r)=>r.startsWith('"')&&r.endsWith('"')||r.startsWith("'")&&r.endsWith("'")?n:`{"${r}"}`),e}const tm=({code:t,className:e=""})=>{const n=a.useRef(null),[r,i]=a.useState(null),[o,c]=a.useState(!0),[l,m]=a.useState(""),[u,d]=a.useState(!1),[p,h]=a.useState("");if(a.useEffect(()=>{let y=!1;return(async()=>{if(!(!n.current||!t))try{c(!0),i(null);const x=em(t);m(x);const z=(await dt(async()=>{const{default:T}=await import("./diagram-engines-CSzW_-6N.js").then(I=>I.b);return{default:T}},__vite__mapDeps([0]),import.meta.url)).default;z.initialize({startOnLoad:!1,theme:"default",securityLevel:"loose",fontFamily:"Inter, SF Pro Display, -apple-system, sans-serif"});const N=`mermaid-${Math.random().toString(36).substr(2,9)}`,{svg:O}=await z.render(N,x);!y&&n.current&&(n.current.innerHTML=O,h(O),c(!1))}catch(x){console.error("[MermaidRenderer] Failed to render:",x),y||(i(x.message||"Failed to render diagram"),c(!1))}})(),()=>{y=!0}},[t]),r){const y=l&&l!==t;return s.jsx("div",{className:`mermaid-renderer mermaid-renderer--error ${e}`,children:s.jsxs("div",{className:"mermaid-renderer__error",children:[s.jsx("strong",{children:"Mermaid渲染错误:"}),s.jsx("pre",{children:r}),s.jsxs("details",{children:[s.jsx("summary",{children:"查看原始代码"}),s.jsx("pre",{children:t})]}),y&&s.jsxs("details",{children:[s.jsx("summary",{children:"查看预处理后的代码(已自动添加引号)"}),s.jsx("pre",{children:l})]})]})})}const g=()=>{!o&&p&&d(!0)};return s.jsxs(s.Fragment,{children:[s.jsxs("div",{className:`mermaid-renderer ${e}`,children:[o&&s.jsx("div",{className:"mermaid-renderer__loading",children:"渲染中..."}),s.jsx(je,{content:"点击查看大图",showArrow:!1,children:s.jsx("div",{ref:n,className:"mermaid-renderer__container",style:{display:o?"none":"block"},onClick:g})}),!o&&p&&s.jsxs("div",{className:"mermaid-renderer__hint",children:[s.jsx(Ba,{size:16}),s.jsx("span",{children:"点击查看大图"})]})]}),s.jsx(Ga,{visible:u,onClose:()=>d(!1),header:"Mermaid 图表",width:"90vw",className:"mermaid-preview-dialog",footer:null,closeBtn:s.jsx(Vr,{}),children:s.jsx("div",{className:"mermaid-preview-content",dangerouslySetInnerHTML:{__html:p}})})]})},nm=Object.freeze(Object.defineProperty({__proto__:null,MermaidRenderer:tm},Symbol.toStringTag,{value:"Module"}));export{fm as $,Ec as A,wt as B,Pc as C,_t as D,ro as E,Ac as F,$t as G,Al as H,to as I,zl as J,um as K,_o as L,mm as M,ru as N,Lo as O,sl as P,lm as Q,Cl as R,Hl as S,uu as T,mn as U,sc as V,$c as W,il as X,im as Y,pm as Z,hm as _,Os as a,gm as a0,wm as a1,El as b,Tl as c,Nl as d,Ll as e,vo as f,am as g,ac as h,mo as i,pn as j,Vs as k,Un as l,is as m,bl as n,bo as o,Bl as p,ls as q,dm as r,hu as s,om as t,Xa as u,Ml as v,vt as w,cd as x,lo as y,cm as z};
|