aitu-app 0.6.63 → 0.6.64
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-Du5kXrAd.js → CanvasAudioPlayer-B2W5__ni.js} +1 -1
- package/assets/{ChatDrawer-CqZHx7x_.js → ChatDrawer-M1q92KNU.js} +2 -2
- package/assets/{ChatMessagesArea-AG3RXe34.js → ChatMessagesArea-D9LNDmbK.js} +2 -2
- package/assets/{DeferredAIInputBar-CNAPl6C2.js → DeferredAIInputBar-CKhI8Jhd.js} +2 -2
- package/assets/{DrawnixDeferredFeatures-BrhbEEBa.js → DrawnixDeferredFeatures-DxyxvT2y.js} +1 -1
- package/assets/{KnowledgeBaseContent-3hE8vBra.js → KnowledgeBaseContent-C_JxGQXg.js} +3 -3
- package/assets/{MVCreator-2NIxaaSL.js → MVCreator-DOt6pxq2.js} +1 -1
- package/assets/{ModelBenchmarkWorkbench-CacNyFbi.js → ModelBenchmarkWorkbench-3j77ocpe.js} +1 -1
- package/assets/{ModelDropdown-3MjTl1AO.js → ModelDropdown-CHYgRb1r.js} +1 -1
- package/assets/{MusicAnalyzer-Mmu92A4Y.js → MusicAnalyzer-BTXks5oV.js} +1 -1
- package/assets/{MusicAnalyzer-Drf2j8jn.js → MusicAnalyzer-Dr-DPePj.js} +1 -1
- package/assets/{ResizableDivider-B_67th7H.js → ResizableDivider-P1jpoJ3i.js} +1 -1
- package/assets/{TaskQueuePanel-VfjKIooN.js → TaskQueuePanel-D6NtMAbm.js} +1 -1
- package/assets/{VideoAnalyzer-DNWjNcIx.js → VideoAnalyzer-BHZMqLIa.js} +1 -1
- package/assets/{ai-generation-preferences-service-Ch1XhjkZ.js → ai-generation-preferences-service-CabuQA69.js} +1 -1
- package/assets/{arc-DE4qRd9D.js → arc-BajUk0_Z.js} +1 -1
- package/assets/{arc-DJ5Mb9x1.js → arc-Z9PGo_2L.js} +1 -1
- package/assets/{batch-image-generation-Bk8HSFol.js → batch-image-generation-RKz5tz-Y.js} +1 -1
- package/assets/{blockDiagram-38ab4fdb-B62iB8ti.js → blockDiagram-38ab4fdb-BsEJDcLK.js} +1 -1
- package/assets/{blockDiagram-38ab4fdb-D2MnfN1Q.js → blockDiagram-38ab4fdb-Cfmk3_6A.js} +1 -1
- package/assets/{c4Diagram-3d4e48cf-CgUaipiZ.js → c4Diagram-3d4e48cf-D2OyfHpd.js} +1 -1
- package/assets/{c4Diagram-3d4e48cf-DHV35ltP.js → c4Diagram-3d4e48cf-K-ewbsK1.js} +1 -1
- package/assets/{canvas-insertion-ZEZkcXvB.js → canvas-insertion-CYbFgP4L.js} +1 -1
- package/assets/channel-6DAc0JPc.js +1 -0
- package/assets/channel-WrMsNCbC.js +1 -0
- package/assets/{classDiagram-70f12bd4-C6X-VZXt.js → classDiagram-70f12bd4-BGEF352u.js} +1 -1
- package/assets/{classDiagram-70f12bd4-OH5sF1K-.js → classDiagram-70f12bd4-Gn3MZjEL.js} +1 -1
- package/assets/{classDiagram-v2-f2320105-otk4V9KH.js → classDiagram-v2-f2320105-C_aAfIgL.js} +1 -1
- package/assets/{classDiagram-v2-f2320105-D1I5s2af.js → classDiagram-v2-f2320105-DYPMFlcT.js} +1 -1
- package/assets/{clipper-BWlMmsTH.js → clipper-ByL4oIbZ.js} +1 -1
- package/assets/clone-keJVIubx.js +1 -0
- package/assets/{createText-2e5e7dd3-DuiUpOXV.js → createText-2e5e7dd3-C0UgSBh5.js} +1 -1
- package/assets/{createText-2e5e7dd3-D78Dn_q8.js → createText-2e5e7dd3-CoA6JNKB.js} +1 -1
- package/assets/{edges-e0da2a9e-Br3GgeJK.js → edges-e0da2a9e-DmyL0L_b.js} +1 -1
- package/assets/{edges-e0da2a9e-Dio4S9-4.js → edges-e0da2a9e-qdTreft0.js} +1 -1
- package/assets/{erDiagram-9861fffd-BYkBBs0M.js → erDiagram-9861fffd-Bjyf78Da.js} +1 -1
- package/assets/{erDiagram-9861fffd-DuZccGHy.js → erDiagram-9861fffd-DYWtVkXG.js} +1 -1
- package/assets/{flowDb-956e92f1-BvHxN76x.js → flowDb-956e92f1-Clfuqh48.js} +1 -1
- package/assets/{flowDb-956e92f1-D6cTY_st.js → flowDb-956e92f1-vnfymslR.js} +1 -1
- package/assets/{flowDiagram-66a62f08-Bh5LanWu.js → flowDiagram-66a62f08-54OX2XOH.js} +1 -1
- package/assets/{flowDiagram-66a62f08-rCNbZEwY.js → flowDiagram-66a62f08-lS8fOa4T.js} +1 -1
- package/assets/flowDiagram-v2-96b9c2cf-Bw7qAcFu.js +1 -0
- package/assets/flowDiagram-v2-96b9c2cf-DGyrUMgR.js +1 -0
- package/assets/{flowchart-elk-definition-4a651766-llVLlxyE.js → flowchart-elk-definition-4a651766-CXdElD40.js} +1 -1
- package/assets/{flowchart-elk-definition-4a651766-CIShIr5E.js → flowchart-elk-definition-4a651766-D4UghemK.js} +1 -1
- package/assets/{ganttDiagram-c361ad54-j2pPvoOi.js → ganttDiagram-c361ad54-Bl7rQCLW.js} +1 -1
- package/assets/{ganttDiagram-c361ad54-CUtUP4cJ.js → ganttDiagram-c361ad54-CwAjbWcn.js} +1 -1
- package/assets/{gitGraphDiagram-72cf32ee-hQmVrZTT.js → gitGraphDiagram-72cf32ee-B-ykaDuR.js} +1 -1
- package/assets/{gitGraphDiagram-72cf32ee-BijhDF7a.js → gitGraphDiagram-72cf32ee-ChvlaDvG.js} +1 -1
- package/assets/{graph-CVdXivUk.js → graph-Bq1HvHkL.js} +1 -1
- package/assets/{graph-iERr38Mn.js → graph-DM094zt_.js} +1 -1
- package/assets/{index-3862675e-BCU8UapW.js → index-3862675e-CA0xjB9W.js} +1 -1
- package/assets/{index-3862675e-BdD6mhWW.js → index-3862675e-DGrSmeWu.js} +1 -1
- package/assets/{index-CxqCKbLy.js → index-AFp_qpAI.js} +1 -1
- package/assets/{index-q02ppfIX.js → index-B4dceFKj.js} +1 -1
- package/assets/{index-BmNN2uGW.js → index-B67KSDhv.js} +1 -1
- package/assets/{index-ByxyNkwM.js → index-BC221_MJ.js} +1 -1
- package/assets/{index-nPSeKWRU.js → index-BGFWA6Zt.js} +1 -1
- package/assets/{index-DCjrDHEd.js → index-BH3jS3gm.js} +1 -1
- package/assets/{index-B-bas2QJ.js → index-BKTLxghO.js} +1 -1
- package/assets/{index-CW9BeyEu.js → index-Bks4xBST.js} +1 -1
- package/assets/{index-CvlBHvN3.js → index-BmEFRKV7.js} +1 -1
- package/assets/{index-DuFyvKRm.js → index-C3h-b0UN.js} +1 -1
- package/assets/{index-CmOEsqBQ.js → index-C5Onm0uO.js} +1 -1
- package/assets/{index-DYtXgeSz.js → index-CGelrSXy.js} +1 -1
- package/assets/{index-vw8fjMik.js → index-CKBsqCzR.js} +1 -1
- package/assets/{index-DjGrNkrV.js → index-CKjzms_e.js} +1 -1
- package/assets/{index-CxUWaNUo.js → index-CMLI8gQy.js} +1 -1
- package/assets/{index-CkjuY786.js → index-CVEllvWf.js} +1 -1
- package/assets/{index-BUZUbTWS.js → index-CW_ala_3.js} +1 -1
- package/assets/{index-BxdH1-er.js → index-Ci5Z3DWY.js} +1 -1
- package/assets/{index-BeRhCeQu.js → index-CtNjfEqK.js} +1 -1
- package/assets/{index-BakDREx4.js → index-CvbEsbIE.js} +1 -1
- package/assets/{index-BnaNWg7x.js → index-DM-iV9Y8.js} +2 -2
- package/assets/{index-DMfHKITi.js → index-DTqVJVfv.js} +1 -1
- package/assets/{index-BdSFouqR.js → index-DZtf3zC8.js} +1 -1
- package/assets/{index-ByECpktB.js → index-D_LadtY8.js} +1 -1
- package/assets/{index-UeGDfQIX.js → index-DiSWR48t.js} +1 -1
- package/assets/{index-D0O0qYML.js → index-DsFroXrj.js} +1 -1
- package/assets/{index-BN7eABQE.js → index-DxqCsnoj.js} +1 -1
- package/assets/{index-B_eFETCZ.js → index-Jvh12pKI.js} +1 -1
- package/assets/{index-CMQMxwMb.js → index-gHdnUGOu.js} +3 -3
- package/assets/{index-CE0NChcB.js → index-kKjFXTNL.js} +1 -1
- package/assets/{index-D4R9cQ86.js → index-v1v0x1ci.js} +3 -3
- package/assets/{infoDiagram-f8f76790-Cmv7jbWa.js → infoDiagram-f8f76790-C-wYgjah.js} +1 -1
- package/assets/{infoDiagram-f8f76790-D0DSz5Ue.js → infoDiagram-f8f76790-Cu-3eq4R.js} +1 -1
- package/assets/{journeyDiagram-49397b02-D6HU8bXU.js → journeyDiagram-49397b02-BG8aYQK6.js} +1 -1
- package/assets/{journeyDiagram-49397b02-Db00D03K.js → journeyDiagram-49397b02-DXPaY9vn.js} +1 -1
- package/assets/{layout-CPj4wl_r.js → layout-DvIBYRXu.js} +1 -1
- package/assets/{layout-DGJFFi9s.js → layout-SoDWNnQD.js} +1 -1
- package/assets/{line-D_WC7vRh.js → line-Bxc-zIvZ.js} +1 -1
- package/assets/{line-CpXi5g86.js → line-CFFXuH78.js} +1 -1
- package/assets/{linear-n85WiAhX.js → linear-BF0xIQKP.js} +1 -1
- package/assets/{linear-UpmxQM2f.js → linear-DQ3XkjOP.js} +1 -1
- package/assets/{main-DX4kRYQX.js → main-8GBlYJSO.js} +8 -8
- package/assets/{mermaid.core-N7WwfYcf.js → mermaid.core-BGyfnsLl.js} +3 -3
- package/assets/{mindmap-definition-fc14e90a-C8U6pdZ2.js → mindmap-definition-fc14e90a-CrYWIUXi.js} +1 -1
- package/assets/{mindmap-definition-fc14e90a-D2hbUBx2.js → mindmap-definition-fc14e90a-DOkI3ebm.js} +1 -1
- package/assets/{model-benchmark-launcher-BrOG9Vlm.js → model-benchmark-launcher-DtJmU6Wc.js} +1 -1
- package/assets/{model-benchmark-service-DDklUBjC.js → model-benchmark-service-B0QCqInK.js} +1 -1
- package/assets/{model-selection-BaH65gMK.js → model-selection-CbzU26xQ.js} +1 -1
- package/assets/{photo-wall-splitter-QuaIbsZ1.js → photo-wall-splitter-BPzdMtA1.js} +1 -1
- package/assets/{pieDiagram-8a3498a8-BPHw5PxR.js → pieDiagram-8a3498a8-ChLZxjKv.js} +1 -1
- package/assets/{pieDiagram-8a3498a8-DKV5uwrs.js → pieDiagram-8a3498a8-DAWd9-jL.js} +1 -1
- package/assets/{quadrantDiagram-120e2f19-pe-wI-U4.js → quadrantDiagram-120e2f19-CBBovNE2.js} +1 -1
- package/assets/{quadrantDiagram-120e2f19-DQdaeBYM.js → quadrantDiagram-120e2f19-DSvfgE7I.js} +1 -1
- package/assets/{requirementDiagram-deff3bca-DYepoptc.js → requirementDiagram-deff3bca-De51fyhT.js} +1 -1
- package/assets/{requirementDiagram-deff3bca-QX4OaNTO.js → requirementDiagram-deff3bca-ke6SiEw1.js} +1 -1
- package/assets/{sankeyDiagram-04a897e0-DJkKTFXr.js → sankeyDiagram-04a897e0-BxiqkhtK.js} +1 -1
- package/assets/{sankeyDiagram-04a897e0-1bYf2R8i.js → sankeyDiagram-04a897e0-Clr8_HiZ.js} +1 -1
- package/assets/{sequenceDiagram-704730f1-B52OA1Y3.js → sequenceDiagram-704730f1-Bc8zPHLG.js} +1 -1
- package/assets/{sequenceDiagram-704730f1-B4QsYTCd.js → sequenceDiagram-704730f1-BfBUJmAu.js} +1 -1
- package/assets/{settings-dialog-Bueh6yYA.js → settings-dialog-C9BMj8Zj.js} +1 -1
- package/assets/{skill-dsl-parser-CPpdtdC1.js → skill-dsl-parser-BxkJ9Ixc.js} +1 -1
- package/assets/{stateDiagram-587899a1-D221rMST.js → stateDiagram-587899a1-DAil8S_m.js} +1 -1
- package/assets/{stateDiagram-587899a1-X7bhoHKe.js → stateDiagram-587899a1-Vop8VRn5.js} +1 -1
- package/assets/{stateDiagram-v2-d93cdb3a-D9VdRPIN.js → stateDiagram-v2-d93cdb3a-8b1lkei5.js} +1 -1
- package/assets/{stateDiagram-v2-d93cdb3a-CGMASaM9.js → stateDiagram-v2-d93cdb3a-BHm8pPuv.js} +1 -1
- package/assets/{styles-6aaf32cf-D_xcN1dm.js → styles-6aaf32cf-BlD8JxQr.js} +1 -1
- package/assets/{styles-6aaf32cf-DHTzglnJ.js → styles-6aaf32cf-C4CEUYqK.js} +1 -1
- package/assets/{styles-9a916d00-w5Yn3LRO.js → styles-9a916d00-C6tkW5rH.js} +1 -1
- package/assets/{styles-9a916d00-BVoYXPeR.js → styles-9a916d00-Oss0YMv5.js} +1 -1
- package/assets/{styles-c10674c1-xX_gtHzZ.js → styles-c10674c1-D4YQTLGD.js} +1 -1
- package/assets/{styles-c10674c1-C3cgfc7I.js → styles-c10674c1-D6N_fge5.js} +1 -1
- package/assets/{svgDrawCommon-08f97a94-DFof-iml.js → svgDrawCommon-08f97a94-BOSx1sQS.js} +1 -1
- package/assets/{svgDrawCommon-08f97a94-DxU2UGYh.js → svgDrawCommon-08f97a94-RZvmFGZL.js} +1 -1
- package/assets/{timeline-definition-85554ec2-CzV_JohE.js → timeline-definition-85554ec2-BL5y0l6c.js} +1 -1
- package/assets/{timeline-definition-85554ec2-FPml3o0r.js → timeline-definition-85554ec2-BY6Jx-ZP.js} +1 -1
- package/assets/{tool-windows-hjm6YiPY.js → tool-windows-C4D0lII2.js} +137 -137
- package/assets/{ttd-dialog-CqISZ7cy.js → ttd-dialog-qD0QkDID.js} +4 -4
- package/assets/{use-runtime-models-C0uyCfar.js → use-runtime-models-BLwgp0M1.js} +1 -1
- package/assets/{useCharacters-BGdX9007.js → useCharacters-945b6dqW.js} +1 -1
- package/assets/{useWorkflowSubmission-BmFQdWt3.js → useWorkflowSubmission-Z0u0KCNN.js} +2 -2
- package/assets/{video-analyze-DszumYAr.js → video-analyze-Co9na7Gr.js} +1 -1
- package/assets/{video-generation-DEL-kJgF.js → video-generation-x2UMMPYg.js} +1 -1
- package/assets/{video-recovery-service-C9y_bfU1.js → video-recovery-service-BsV5nlEP.js} +1 -1
- package/assets/{workflow-generation-utils-Da12qXTb.js → workflow-generation-utils-CZULSJWQ.js} +2 -2
- package/assets/{workflow-submission-service-BuFuRV_m.js → workflow-submission-service-C-eCWm_8.js} +1 -1
- package/assets/{xychartDiagram-e933f94c-C41tCiSk.js → xychartDiagram-e933f94c-CNjZprqQ.js} +1 -1
- package/assets/{xychartDiagram-e933f94c-HanO46iU.js → xychartDiagram-e933f94c-DjIBec-i.js} +1 -1
- package/changelog.json +16 -0
- package/idle-prefetch-manifest.json +6 -6
- package/manifest.json +3 -3
- package/package.json +1 -1
- package/precache-manifest.json +304 -304
- package/sw.js +5 -5
- package/version.json +7 -3
- package/assets/channel-B5QZCgOy.js +0 -1
- package/assets/channel-CU3dhzIS.js +0 -1
- package/assets/clone-BAOxFbud.js +0 -1
- package/assets/flowDiagram-v2-96b9c2cf-BEdEe3Ip.js +0 -1
- package/assets/flowDiagram-v2-96b9c2cf-CVItVSoD.js +0 -1
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["./tool-windows-Cos6lOhr.css","./use-runtime-models-BgWWl4Ng.css","./ModelDropdown-CQTTHEI7.css","./batch-image-generation-BePygpHd.css"])))=>i.map(i=>d[i]);
|
|
2
|
-
import{y as e,z as $t,hR as qs,hS as Ys,r as t,dw as Vt,gr as Xs,gt as Js,gs as Qs,gE as Zs,hT as Ft,bL as ft,b8 as Ye,_ as kt,hU as ps,P as fs,G as hs,ai as Tt,hV as ea,W as gs,ge as xs,cX as he,eK as Mt,h1 as ve,bV as Fe,f$ as bs,fF as ut,hW as ta,fR as sa,dM as vs,bP as et,al as Ne,bT as aa,hn as oa,g_ as na,bD as ra,hX as ia,hY as la,hZ as ca,h_ as da,h$ as ua,i0 as ma,i1 as pa,i2 as lt,i3 as dt,i4 as fa,i5 as ha,i6 as ga,fI as xa,i7 as Ut,fY as ws,i8 as ba,i9 as ys,f_ as va,hm as wa,ia as ya,ib as Ia,ic as Sa,id as _a,ie as Gt,g$ as ja,h0 as Ve,h8 as Ca,ig as Ta,ih as Ea,fP as Wt,ii as ka,dj as Ma,eI as Pa,ij as Na,d2 as Da,hw as qe,hv as Ae,hy as mt,ik as wt,eP as Pt,aI as de,il as Ra,hz as Oa,hd as ze,gP as tt,hH as Aa,hI as za,im as Bt,io as yt,hB as La,ip as It,hc as $a,iq as Va,ir as Kt,is as St,it as Ht,iu as qt,iv as _t,iw as Yt,ix as Xt,iy as Jt,iz as Qt,iA as Zt,U as Fa,bI as Ua,hN as es,iB as ts}from"./tool-windows-
|
|
2
|
+
import{y as e,z as $t,hR as qs,hS as Ys,r as t,dw as Vt,gr as Xs,gt as Js,gs as Qs,gE as Zs,hT as Ft,bL as ft,b8 as Ye,_ as kt,hU as ps,P as fs,G as hs,ai as Tt,hV as ea,W as gs,ge as xs,cX as he,eK as Mt,h1 as ve,bV as Fe,f$ as bs,fF as ut,hW as ta,fR as sa,dM as vs,bP as et,al as Ne,bT as aa,hn as oa,g_ as na,bD as ra,hX as ia,hY as la,hZ as ca,h_ as da,h$ as ua,i0 as ma,i1 as pa,i2 as lt,i3 as dt,i4 as fa,i5 as ha,i6 as ga,fI as xa,i7 as Ut,fY as ws,i8 as ba,i9 as ys,f_ as va,hm as wa,ia as ya,ib as Ia,ic as Sa,id as _a,ie as Gt,g$ as ja,h0 as Ve,h8 as Ca,ig as Ta,ih as Ea,fP as Wt,ii as ka,dj as Ma,eI as Pa,ij as Na,d2 as Da,hw as qe,hv as Ae,hy as mt,ik as wt,eP as Pt,aI as de,il as Ra,hz as Oa,hd as ze,gP as tt,hH as Aa,hI as za,im as Bt,io as yt,hB as La,ip as It,hc as $a,iq as Va,ir as Kt,is as St,it as Ht,iu as qt,iv as _t,iw as Yt,ix as Xt,iy as Jt,iz as Qt,iA as Zt,U as Fa,bI as Ua,hN as es,iB as ts}from"./tool-windows-C4D0lII2.js";import{W as Ga,w as Wa,B as Ba,b as Nt,g as Ka,c as Ha}from"./main-8GBlYJSO.js";import{M as Is}from"./ModelDropdown-CHYgRb1r.js";import{g as qa,d as Ya,e as ss,u as Ss,f as Xa,h as _s,P as js,b as as,i as os,j as Ja,k as Qa}from"./ai-generation-preferences-service-CabuQA69.js";import{u as Cs,C as Za,V as eo,a as to}from"./useCharacters-945b6dqW.js";/* empty css */import{R as Ts}from"./ResizableDivider-P1jpoJ3i.js";import{u as Es}from"./use-runtime-models-BLwgp0M1.js";import{f as Le,g as Oe,a as Ie}from"./model-selection-CbzU26xQ.js";/* empty css */import"./model-benchmark-service-B0QCqInK.js";const ks=({children:o})=>e.jsx("div",{className:"ttd-dialog-panels",children:o}),pt=({label:o,children:s,panelAction:n,panelActionDisabled:i=!1,onTextSubmitInProgress:a,renderTopRight:r,renderSubmitShortcut:x,renderBottomRight:y})=>e.jsxs("div",{className:"ttd-dialog-panel",children:[e.jsxs("div",{className:"ttd-dialog-panel__header",children:[e.jsx("label",{children:o}),r==null?void 0:r()]}),s,e.jsxs("div",{className:$t("ttd-dialog-panel-button-container",{invisible:!n}),style:{display:"flex",alignItems:"center"},children:[e.jsx("button",{className:"ttd-dialog-panel-button drawnix-button ","data-track":"ttd_click_panel_action",onClick:n&&n.action,disabled:i||a,children:e.jsxs("div",{className:$t({invisible:a}),children:[n==null?void 0:n.label,(n==null?void 0:n.icon)&&e.jsx("span",{children:n.icon})]})}),!i&&!a&&(x==null?void 0:x()),y==null?void 0:y()]})]}),ns={CTRL_OR_CMD:qs||Ys?"metaKey":"ctrlKey",ENTER:"Enter"},Ms=({input:o,placeholder:s,onChange:n,onKeyboardSubmit:i})=>{const a=t.useRef(null),r=t.useRef(i);return r.current=i,t.useEffect(()=>{if(!r.current)return;const x=a.current;if(x){const y=C=>{var l;C[ns.CTRL_OR_CMD]&&C.key===ns.ENTER&&(C.preventDefault(),(l=r.current)==null||l.call(r))};return x.addEventListener(Vt.KEYDOWN,y),()=>{x.removeEventListener(Vt.KEYDOWN,y)}}},[]),e.jsx("textarea",{className:"ttd-dialog-input",onChange:n,value:o,placeholder:s,autoFocus:!0,ref:a})},so=({error:o})=>e.jsxs("div",{"data-testid":"ttd-dialog-output-error",className:"ttd-dialog-output-error",children:["Error! ",e.jsx("p",{children:o})]}),Ps=({error:o,value:s,loaded:n})=>{const i=[Xs,Js,Qs,Wa],a={readonly:!0,hideScrollbar:!1,disabledScrollOnNonFocus:!0,themeColors:Zs};return e.jsxs("div",{className:"ttd-dialog-output-wrapper",children:[o&&e.jsx(so,{error:o.message}),e.jsx("div",{style:{opacity:o?"0.15":1},className:"ttd-dialog-output-canvas-container",children:e.jsx(Ga,{value:s,options:a,plugins:i,children:e.jsx(Ba,{})})})]})},Ns=()=>e.jsxs("div",{className:"ttd-dialog-submit-shortcut",children:[e.jsx("div",{className:"ttd-dialog-submit-shortcut__key",children:Ft("CtrlOrCmd")}),e.jsx("div",{className:"ttd-dialog-submit-shortcut__key",children:Ft("Enter")})]}),ao=`flowchart TD
|
|
3
3
|
A[Christmas] -->|Get money| B(Go shopping)
|
|
4
4
|
B --> C{Let me think}
|
|
5
5
|
C -->|One| D[Laptop]
|
|
6
6
|
C -->|Two| E[iPhone]
|
|
7
|
-
C -->|Three| F[Car]`,oo=()=>{const{closeDialog:o}=ft(),{t:s,language:n}=Ye(),[i,a]=t.useState({loaded:!1,api:Promise.resolve({parseMermaidToDrawnix:async()=>({elements:[]})})});t.useEffect(()=>{(async()=>{try{const v=await kt(()=>import("./index-
|
|
7
|
+
C -->|Three| F[Car]`,oo=()=>{const{closeDialog:o}=ft(),{t:s,language:n}=Ye(),[i,a]=t.useState({loaded:!1,api:Promise.resolve({parseMermaidToDrawnix:async()=>({elements:[]})})});t.useEffect(()=>{(async()=>{try{const v=await kt(()=>import("./index-gHdnUGOu.js").then(u=>u.aq),__vite__mapDeps([0]),import.meta.url);a({loaded:!0,api:Promise.resolve(v)})}catch(v){console.error("Failed to load mermaid library:",v),T(new Error(s("dialog.error.loadMermaid")))}})()},[]);const[r,x]=t.useState(()=>ao),[y,C]=t.useState(()=>[]),l=t.useDeferredValue(r.trim()),[p,T]=t.useState(null),k=Nt();t.useEffect(()=>{(async()=>{try{const v=await i.api;let u;try{u=await v.parseMermaidToDrawnix(l)}catch{u=await v.parseMermaidToDrawnix(l.replace(/"/g,"'"))}const{elements:D}=u;C(D),T(null)}catch(v){T(v)}})()},[l,i]);const g=()=>{if(!y.length)return;let f;const v=ps(k);if(v)f=v;else{const u=fs.getBoardContainer(k).getBoundingClientRect(),D=[u.width/2,u.height/2],N=k.viewport.zoom,j=hs(k),W=j[0]+D[0]/N,c=j[1]+D[1]/N,M=y,R=Tt.getBoundingRectangle(M.filter(V=>!ea.isGroup(V)).map(V=>Tt.getRectangleByPoints(V.points)));f=[W-R.width/2,c-R.height/2]}k.insertFragment({elements:JSON.parse(JSON.stringify(y))},f,gs.paste),f&&requestAnimationFrame(()=>{xs(k,f)}),o(he.mermaidToDrawnix)};return e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"ttd-dialog-desc",children:n==="zh"?e.jsxs(e.Fragment,{children:[s("dialog.mermaid.description")," ",e.jsx("a",{href:"https://mermaid.js.org/syntax/flowchart.html",target:"_blank",rel:"noreferrer",children:s("dialog.mermaid.flowchart")}),"、",e.jsx("a",{href:"https://mermaid.js.org/syntax/sequenceDiagram.html",target:"_blank",rel:"noreferrer",children:s("dialog.mermaid.sequence")})," ","和"," ",e.jsx("a",{href:"https://mermaid.js.org/syntax/classDiagram.html",target:"_blank",rel:"noreferrer",children:s("dialog.mermaid.class")}),s("dialog.mermaid.otherTypes")]}):e.jsxs(e.Fragment,{children:[s("dialog.mermaid.description")," ",e.jsx("a",{href:"https://mermaid.js.org/syntax/flowchart.html",target:"_blank",rel:"noreferrer",children:s("dialog.mermaid.flowchart")}),","," ",e.jsx("a",{href:"https://mermaid.js.org/syntax/sequenceDiagram.html",target:"_blank",rel:"noreferrer",children:s("dialog.mermaid.sequence")}),","," ",e.jsx("a",{href:"https://mermaid.js.org/syntax/classDiagram.html",target:"_blank",rel:"noreferrer",children:s("dialog.mermaid.class")}),s("dialog.mermaid.otherTypes")]})}),e.jsxs(ks,{children:[e.jsx(pt,{label:s("dialog.mermaid.syntax"),children:e.jsx(Ms,{input:r,placeholder:s("dialog.mermaid.placeholder"),onChange:f=>x(f.target.value),onKeyboardSubmit:()=>{g()}})}),e.jsx(pt,{label:s("dialog.mermaid.preview"),panelAction:{action:()=>{g()},label:s("dialog.mermaid.insert")},renderSubmitShortcut:()=>e.jsx(Ns,{}),children:e.jsx(Ps,{value:y,loaded:i.loaded,error:p})})]})]})},rs=o=>o==="zh"?`# Milkdown 入门
|
|
8
8
|
|
|
9
9
|
Milkdown 是一个强大的所见即所得 Markdown 编辑器,兼具 Markdown 的简洁和现代编辑器的灵活性。它轻量且可扩展,适合从简单到复杂的编辑需求。
|
|
10
10
|
|
|
@@ -92,8 +92,8 @@ Use this if you want full control and a custom editor from the ground up.
|
|
|
92
92
|
Use this if you want a production-ready editor with minimal setup.
|
|
93
93
|
|
|
94
94
|
## Next Steps
|
|
95
|
-
🍼 Fun fact: This documentation is rendered by Milkdown itself!`,no=()=>{const{closeDialog:o}=ft(),{t:s,language:n}=Ye(),[i,a]=t.useState({loaded:!1,api:Promise.resolve({parseMarkdownToDrawnix:(f,v)=>null})});t.useEffect(()=>{(async()=>{try{const v=await kt(()=>import("./index-BmNN2uGW.js"),__vite__mapDeps([0]),import.meta.url);a({loaded:!0,api:Promise.resolve(v)})}catch(v){console.error("Failed to load mermaid library:",v),T(new Error(s("dialog.error.loadMermaid")))}})()},[]);const[r,x]=t.useState(()=>rs(n)),[y,C]=t.useState(()=>[]),l=t.useDeferredValue(r.trim()),[p,T]=t.useState(null),k=Nt();t.useEffect(()=>{x(rs(n))},[n]),t.useEffect(()=>{(async()=>{try{const v=await i.api;let u;try{u=await v.parseMarkdownToDrawnix(l)}catch{u=await v.parseMarkdownToDrawnix(l.replace(/"/g,"'"))}const D=u;D.points=[[0,0]],D&&(C([D]),T(null))}catch(v){T(v)}})()},[l,i]);const g=()=>{if(!y.length)return;let f;const v=ps(k);if(v)f=v;else{const D=fs.getBoardContainer(k).getBoundingClientRect(),N=[D.width/4,D.height/2-20],j=k.viewport.zoom,W=hs(k),c=W[0]+N[0]/j,M=W[1]+N[1]/j;f=[c,M]}const u=y;k.insertFragment({elements:JSON.parse(JSON.stringify(u))},f,gs.paste),f&&requestAnimationFrame(()=>{xs(k,f)}),o(he.markdownToDrawnix)};return e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"ttd-dialog-desc",children:s("dialog.markdown.description")}),e.jsxs(ks,{children:[e.jsx(pt,{label:s("dialog.markdown.syntax"),children:e.jsx(Ms,{input:r,placeholder:s("dialog.markdown.placeholder"),onChange:f=>x(f.target.value),onKeyboardSubmit:()=>{g()}})}),e.jsx(pt,{label:s("dialog.markdown.preview"),panelAction:{action:()=>{g()},label:s("dialog.markdown.insert")},renderSubmitShortcut:()=>e.jsx(Ns,{}),children:e.jsx(Ps,{value:y,loaded:i.loaded,error:p})})]})]})};function Ds(){const{completedTasks:o}=Mt(),s=t.useMemo(()=>o.filter(a=>{var r;return a.type===ve.IMAGE&&((r=a.result)==null?void 0:r.url)}).map(a=>({id:a.id,type:"image",prompt:a.params.prompt,timestamp:a.completedAt||a.createdAt,imageUrl:a.result.url,width:a.result.width||1024,height:a.result.height||1024,uploadedImages:a.params.uploadedImages})).sort((a,r)=>r.timestamp-a.timestamp),[o]),n=t.useMemo(()=>o.filter(a=>{var r;return a.type===ve.VIDEO&&((r=a.result)==null?void 0:r.url)}).map(a=>({id:a.id,type:"video",prompt:a.params.prompt,timestamp:a.completedAt||a.createdAt,imageUrl:a.result.thumbnailUrl||a.result.url,width:a.result.width||400,height:a.result.height||225,previewUrl:a.result.url,downloadUrl:a.result.url,uploadedImage:a.params.uploadedImage})).sort((a,r)=>r.timestamp-a.timestamp),[o]),i=t.useMemo(()=>[...s,...n].sort((a,r)=>r.timestamp-a.timestamp),[s,n]);return{imageHistory:s,videoHistory:n,allHistory:i}}const ro=[1,2,3,4,5,10,20,50,100],io="aitu_image_generation_quantity",lo="aitu_video_generation_quantity",jt=100,Rs=({language:o,type:s,isGenerating:n,hasGenerated:i,canGenerate:a,onGenerate:r,onReset:x,leftContent:y})=>{const C=s==="video"?lo:io,[l,p]=t.useState(()=>{try{const c=localStorage.getItem(C);if(c){const M=parseInt(c,10);if(!isNaN(M)&&M>=1&&M<=jt)return M}}catch{}return 1}),[T,k]=t.useState(!1),[g,f]=t.useState(()=>l.toString()),v=t.useRef(null);t.useEffect(()=>{f(l.toString());try{localStorage.setItem(C,l.toString())}catch{}},[l,C]),t.useEffect(()=>{const c=M=>{v.current&&!v.current.contains(M.target)&&(k(!1),u())};return document.addEventListener("mousedown",c),()=>document.removeEventListener("mousedown",c)},[g]);const u=()=>{let c=parseInt(g,10);(isNaN(c)||c<1)&&(c=1),c>jt&&(c=jt),f(c.toString()),p(c)},D=c=>{const M=c.target.value;(M===""||/^\d*$/.test(M))&&f(M)},N=c=>{p(c),f(c.toString()),k(!1)},j=()=>{n||k(!T)},W=()=>{r(l)};return e.jsxs("div",{className:"section-actions unified-action-bar",children:[y&&e.jsx("div",{className:"action-bar-left",children:y}),e.jsxs("div",{className:`unified-action-box ${n?"is-generating":""} ${a?"can-generate":""}`,children:[e.jsxs("div",{className:"quantity-section",ref:v,children:[e.jsx(Fe,{content:o==="zh"?"生成数量":"Quantity",theme:"light",children:e.jsxs("div",{className:`quantity-control ${T?"is-open":""} ${n?"is-disabled":""}`,children:[e.jsx("input",{type:"text",inputMode:"numeric",value:g,onChange:D,onBlur:u,"data-track":"ai_click_quantity_input",onClick:()=>!n&&k(!0),disabled:n,className:"quantity-input"}),e.jsx("button",{type:"button","data-track":"ai_click_quantity_toggle",onClick:c=>{c.stopPropagation(),j()},disabled:n,className:"quantity-toggle",children:e.jsx(bs,{className:`quantity-icon ${T?"is-open":""}`})})]})}),T&&e.jsxs("div",{className:"quantity-dropdown",children:[e.jsx("div",{className:"quantity-dropdown-header",children:o==="zh"?"选择数量":"Select Quantity"}),ro.map(c=>e.jsxs("button",{type:"button","data-track":"ai_click_quantity_select",onClick:()=>N(c),className:`quantity-option ${l===c?"is-selected":""}`,children:[e.jsxs("span",{children:[c," ",s==="video"?o==="zh"?"个":c>1?"videos":"video":o==="zh"?"张":c>1?"images":"image"]}),l===c&&e.jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:e.jsx("polyline",{points:"20 6 9 17 4 12"})})]},c))]})]}),e.jsx("div",{className:"action-divider"}),e.jsx("button",{"data-track":"ai_click_generate",onClick:W,disabled:n||!a,className:`generate-button ${n?"loading":""}`,children:n?o==="zh"?"生成中...":"Generating...":i?o==="zh"?"重新生成":"Regenerate":s==="video"?o==="zh"?"生成视频":"Generate Video":o==="zh"?"生成":"Generate"})]}),e.jsx(Fe,{content:o==="zh"?"重置表单":"Reset form",theme:"light",children:e.jsx(ut,{"data-track":"ai_click_reset",onClick:x,disabled:n,variant:"text",shape:"circle",icon:e.jsx(ta,{}),className:"action-button--reset-subtle"})})]})},Os=({error:o})=>o?e.jsx("div",{className:"form-error",children:o}):null,As=({visible:o,query:s,position:n,showBelow:i=!1,selectedIndex:a,onSelect:r,onClose:x})=>{const{completedCharacters:y,isLoading:C}=Cs(),l=t.useRef(null),p=t.useMemo(()=>{if(!s)return y;const g=s.toLowerCase();return y.filter(f=>f.username.toLowerCase().includes(g))},[y,s]);t.useEffect(()=>{if(!o||!l.current)return;const g=l.current.querySelector(".character-mention-popup__item--selected");g&&g.scrollIntoView({block:"nearest"})},[o,a]),t.useEffect(()=>{if(!o)return;const g=f=>{l.current&&!l.current.contains(f.target)&&x()};return document.addEventListener("mousedown",g),()=>document.removeEventListener("mousedown",g)},[o,x]);const T=t.useCallback(g=>{sa.track("character_used_in_prompt",{characterId:g.id,username:g.username}),r(g)},[r]);if(!o)return null;const k={position:"fixed",top:n.top,left:n.left,transform:i?"none":"translateY(-100%)",zIndex:vs.DROPDOWN_PORTAL,maxHeight:"200px",overflowY:"auto"};return C?e.jsx("div",{ref:l,className:"character-mention-popup",style:k,children:e.jsx("div",{className:"character-mention-popup__empty",children:"加载中..."})}):p.length===0?e.jsx("div",{ref:l,className:"character-mention-popup",style:k,children:e.jsx("div",{className:"character-mention-popup__empty",children:s?`未找到 "${s}" 相关角色`:"暂无可用角色"})}):e.jsx("div",{ref:l,className:"character-mention-popup",style:k,children:p.map((g,f)=>e.jsxs("div",{className:`character-mention-popup__item ${f===a?"character-mention-popup__item--selected":""}`,onClick:()=>T(g),"data-track":"character_click_mention",children:[e.jsx("div",{className:"character-mention-popup__item-avatar",children:e.jsx(Za,{characterId:g.id,profilePictureUrl:g.profilePictureUrl,alt:g.username})}),e.jsxs("span",{className:"character-mention-popup__item-name",children:["@",g.username]})]},g.id))})},co={visible:!1,query:"",position:{top:0,left:0},showBelow:!1,startIndex:-1,selectedIndex:0};function zs({enabled:o=!0,onPromptChange:s,prompt:n}){const[i,a]=t.useState(co),r=t.useRef(null),{completedCharacters:x}=Cs(),y=t.useCallback(g=>{if(!r.current)return{top:0,left:0,showBelow:!1};const f=r.current,v=f.getBoundingClientRect(),u=document.createElement("div"),D=window.getComputedStyle(f),N=["fontFamily","fontSize","fontWeight","fontStyle","letterSpacing","lineHeight","textTransform","wordSpacing","whiteSpace","paddingTop","paddingRight","paddingBottom","paddingLeft","borderTopWidth","borderRightWidth","borderBottomWidth","borderLeftWidth","boxSizing"];u.style.position="absolute",u.style.top="0",u.style.left="-9999px",u.style.visibility="hidden",u.style.whiteSpace="pre-wrap",u.style.overflowWrap="break-word",u.style.overflow="hidden",u.style.width=`${f.clientWidth}px`,N.forEach(G=>{u.style[G]=D.getPropertyValue(G.replace(/([A-Z])/g,"-$1").toLowerCase())}),document.body.appendChild(u);let j=0,W=0;try{const G=f.value.substring(0,g),ge=document.createTextNode(G),J=document.createElement("span");J.textContent="",u.appendChild(ge),u.appendChild(J);const ye=J.getBoundingClientRect(),O=u.getBoundingClientRect();j=ye.top-O.top,W=ye.left-O.left}finally{document.body.removeChild(u)}const c=f.scrollTop,M=parseInt(D.lineHeight)||20;let R=v.top+j-c,V=v.left+W;const A=240,X=window.innerWidth;V+A>X-16&&(V=X-A-16),V<16&&(V=16);const le=R<220+16;return le?R=R+M+4:R=R-48,{top:R,left:V,showBelow:le}},[]),C=t.useCallback((g,f)=>{if(!o)return;const v=g.substring(0,f),u=v.lastIndexOf("@");if(u===-1){a(W=>({...W,visible:!1}));return}const D=u>0?g[u-1]:" ";if(!/\s/.test(D)&&u!==0){a(W=>({...W,visible:!1}));return}const N=v.substring(u+1);if(N.includes(" ")){a(W=>({...W,visible:!1}));return}const j=y(f);a({visible:!0,query:N,position:{top:j.top,left:j.left},showBelow:j.showBelow,startIndex:u,selectedIndex:0})},[o,y]),l=t.useCallback(g=>{var N;if(i.startIndex===-1)return;const f=n.substring(0,i.startIndex),v=((N=r.current)==null?void 0:N.selectionStart)||n.length,u=n.substring(v),D=`${f}@${g.username} ${u}`;s(D),a(j=>({...j,visible:!1})),setTimeout(()=>{if(r.current){const j=f.length+g.username.length+2;r.current.focus(),r.current.setSelectionRange(j,j)}},0)},[i.startIndex,n,s]),p=t.useCallback(g=>{if(!i.visible)return;const f=i.query?x.filter(v=>v.username.toLowerCase().includes(i.query.toLowerCase())):x;switch(g.key){case"ArrowDown":g.preventDefault(),a(v=>({...v,selectedIndex:Math.min(v.selectedIndex+1,f.length-1)}));break;case"ArrowUp":g.preventDefault(),a(v=>({...v,selectedIndex:Math.max(v.selectedIndex-1,0)}));break;case"Enter":case"Tab":f.length>0&&(g.preventDefault(),l(f[i.selectedIndex]));break;case"Escape":g.preventDefault(),a(v=>({...v,visible:!1}));break}},[i,x,l]),T=t.useCallback((g,f)=>{s(g),C(g,f)},[s,C]),k=t.useCallback(()=>{a(g=>({...g,visible:!1}))},[]);return{mentionState:i,setMentionState:a,textareaRef:r,completedCharacters:x,handleTextChange:T,handleKeyDown:p,handleCharacterSelect:l,closeMentionPopup:k,calculateMentionPosition:y}}const Ls=({prompt:o,onPromptChange:s,presetPrompts:n,language:i,type:a,disabled:r=!1,onError:x,enableMention:y=!0,videoProvider:C})=>{const[l,p]=t.useState(!1),[T,k]=t.useState(!1),g=t.useRef(null),f=t.useRef(null),[v,u]=t.useState(null),[D,N]=t.useState(0),j=t.useMemo(()=>et.sortPrompts(a,n).map((E,Q)=>({id:`preset-${Q}-${E.slice(0,20)}`,content:E,pinned:et.isPinned(a,E)})),[a,n,D]),W=y&&a==="video"&&C==="sora",{mentionState:c,textareaRef:M,handleTextChange:R,handleKeyDown:V,handleCharacterSelect:A,closeMentionPopup:X}=zs({enabled:W,onPromptChange:s,prompt:o}),K=t.useCallback(()=>{if(f.current&&l){const L=f.current.getBoundingClientRect(),E=8,Q=320,oe=400,Se=window.innerHeight-L.top+4,ne=Math.min(Q,window.innerWidth-E*2),ae=window.innerWidth-L.right,xe=window.innerWidth-ne-E,Ce=Math.max(Math.min(ae,xe),E),ie=Math.min(oe,L.top-E,window.innerHeight*.45);u({bottom:Se,right:Ce,maxHeight:ie})}},[l]);t.useEffect(()=>{if(l)return K(),window.addEventListener("scroll",K,!0),window.addEventListener("resize",K),()=>{window.removeEventListener("scroll",K,!0),window.removeEventListener("resize",K)}},[l,K]),t.useEffect(()=>{const L=E=>{const Q=E.target;if(g.current&&!g.current.contains(Q)){const oe=document.querySelector(".preset-prompt-panel-portal");oe!=null&&oe.contains(Q)||p(!1)}};if(l)return document.addEventListener("mousedown",L),()=>document.removeEventListener("mousedown",L)},[l]);const le=t.useCallback(L=>{const E=typeof L=="string"?L:L.content;s(E),x==null||x(null),p(!1)},[s,x]),G=t.useCallback(L=>{const E=j.find(Q=>Q.id===L);E&&(E.pinned?et.unpinPrompt(a,E.content):et.pinPrompt(a,E.content),N(Q=>Q+1))},[a,j]),ge=t.useCallback(L=>{const E=j.find(Q=>Q.id===L);E&&(et.deletePrompt(a,E.content),N(Q=>Q+1))},[a,j]),J=t.useCallback(L=>{const E=L.target.value,Q=L.target.selectionStart||0;R(E,Q),x==null||x(null)},[R,x]);t.useEffect(()=>{a!=="video"&&X()},[a,X]);const ye=t.useCallback(()=>{if(console.info("[PromptOptimize] handleOpenOptimizeDialog",{type:a,language:i,promptLength:o.trim().length,disabled:r}),!o.trim()){Ne.warning(i==="zh"?"请先输入提示词":"Please enter a prompt first");return}k(!0)},[r,i,o,a]),O=()=>{if(!l||!v)return null;const L=i==="zh"?`${a==="image"?"图片":"视频"}描述预设`:`${a==="image"?"Image":"Video"} Description Presets`,E=e.jsx("div",{className:"preset-prompt-panel-portal",style:{position:"fixed",bottom:v.bottom,right:v.right,zIndex:vs.DIALOG_POPOVER,"--panel-max-width":"calc(100vw - 16px)","--panel-max-height":`${v.maxHeight}px`},children:e.jsx(na,{title:L,items:j,onSelect:le,onTogglePin:G,onDelete:ge,language:i,disabled:r,showCount:!0})});return ra.createPortal(E,document.body)};return e.jsxs("div",{className:"form-field form-field--prompt",children:[e.jsxs("div",{className:"form-label-with-icon",children:[e.jsx("label",{className:"form-label",children:i==="zh"?`${a==="image"?"图片":"视频"}描述`:`${a==="image"?"Image":"Video"} Description`}),e.jsx("div",{className:"textarea-with-preset",children:e.jsxs("div",{className:"preset-tooltip-container",ref:g,children:[e.jsx("button",{ref:f,type:"button",className:"preset-icon-button",disabled:r,onClick:()=>p(!l),children:e.jsx(aa,{size:16})}),O()]})})]}),e.jsxs("div",{className:"prompt-textarea-wrapper",children:[e.jsx("textarea",{ref:M,className:"form-textarea",value:o,onChange:J,onKeyDown:V,placeholder:qa(i,a,C),rows:4,disabled:r}),e.jsx("button",{type:"button",className:"prompt-optimize-button",onClick:ye,disabled:r,"aria-label":i==="zh"?"优化提示词":"Optimize prompt",title:i==="zh"?"优化提示词":"Optimize prompt",children:e.jsx(oa,{size:16})})]}),W&&e.jsx(As,{visible:c.visible,query:c.query,position:c.position,showBelow:c.showBelow,selectedIndex:c.selectedIndex,onSelect:A,onClose:X}),e.jsx(Ya,{open:T,onOpenChange:k,originalPrompt:o,language:i,type:a,allowStructuredMode:!0,onApply:L=>{s(L),x==null||x(null)}})]})};function uo(o){return o.map(s=>s.prompt.trim()).filter(s=>s.length>0).filter((s,n,i)=>i.indexOf(s)===n)}const $s=(o,s,n)=>{const i=o==="image"?Ka(s):Ha(s),a=uo(n);return[...[...o==="video"?ia():la(),...a].filter((C,l,p)=>p.indexOf(C)===l).slice(0,ca),...i].filter((C,l,p)=>p.indexOf(C)===l).slice(0,da)},Vs=(o,s,n)=>{!s||!s.trim()||(o==="video"?ua(s.trim()):ma(s.trim()))},mo=({model:o,configOverride:s,duration:n,size:i,onDurationChange:a,onSizeChange:r,disabled:x=!1})=>{const y=s||pa(o),C=y.durationOptions,l=y.sizeOptions,p=C.some(u=>u.value===n),T=l.some(u=>u.value===i),k=p?n:y.defaultDuration,g=T?i:y.defaultSize,f=C.map(u=>({label:u.label,value:u.value})),v=l.map(u=>({label:u.label,value:u.value}));return e.jsxs("div",{className:"video-model-options",children:[e.jsxs("div",{className:"video-model-options__row",children:[e.jsx("label",{className:"video-model-options__label",children:"时长"}),e.jsx("div",{className:"video-model-options__control",children:C.length===1?e.jsx("span",{className:"video-model-options__fixed-value",children:C[0].label}):e.jsx(lt.Group,{value:k,onChange:u=>{const D=u;D!==k&&a(D)},disabled:x,variant:"default-filled",size:"small",children:f.map(u=>e.jsx(lt.Button,{value:u.value,children:u.label},u.value))})})]}),e.jsxs("div",{className:"video-model-options__row",children:[e.jsx("label",{className:"video-model-options__label",children:"尺寸"}),e.jsx("div",{className:"video-model-options__control",children:l.length===1?e.jsx("span",{className:"video-model-options__fixed-value",children:l[0].label}):e.jsx(lt.Group,{value:g,onChange:u=>{const D=u;D!==g&&r(D)},disabled:x,variant:"default-filled",size:"small",children:v.map(u=>e.jsx(lt.Button,{value:u.value,children:u.label},u.value))})})]})]})},po=({value:o,onChange:s,compact:n=!0,options:i})=>{const{language:a}=Ye(),[r,x]=t.useState(!1),y=t.useRef(null),C=i&&i.length>0?i:dt,l=t.useMemo(()=>o==="auto"?fa:ha(o),[o]);t.useEffect(()=>{const T=k=>{y.current&&!y.current.contains(k.target)&&x(!1)};return r&&document.addEventListener("mousedown",T),()=>{document.removeEventListener("mousedown",T)}},[r]);const p=T=>{s(T.value),x(!1)};return n?e.jsxs("div",{className:"aspect-ratio-selector aspect-ratio-selector--compact",ref:y,children:[e.jsx(Fe,{content:a==="zh"?"选择图片比例":"Select aspect ratio",theme:"light",children:e.jsxs("div",{className:`aspect-ratio-selector__trigger ${r?"aspect-ratio-selector__trigger--open":""}`,"data-track":"ai_click_ratio_toggle",onClick:()=>x(!r),children:[e.jsx("span",{className:"aspect-ratio-selector__trigger-value",children:(l==null?void 0:l.label)||o}),e.jsx(bs,{className:`aspect-ratio-selector__trigger-icon ${r?"aspect-ratio-selector__trigger-icon--open":""}`})]})}),r&&e.jsx("div",{className:"aspect-ratio-selector__dropdown",children:e.jsx("div",{className:"aspect-ratio-selector__dropdown-grid",children:C.map(T=>e.jsx(Fe,{content:T.description,theme:"light",placement:"top",showArrow:!1,children:e.jsx("div",{className:`aspect-ratio-selector__dropdown-item ${o===T.value?"aspect-ratio-selector__dropdown-item--selected":""}`,"data-track":"ai_click_ratio_select",onClick:()=>p(T),children:T.label})},T.value))})})]}):e.jsxs("div",{className:"aspect-ratio-selector",children:[e.jsx("div",{className:"aspect-ratio-selector__label",children:a==="zh"?"图片比例":"Aspect Ratio"}),e.jsx("div",{className:"aspect-ratio-selector__options",children:C.map(T=>e.jsx(Fe,{content:T.description,theme:"light",placement:"top",showArrow:!1,children:e.jsx("div",{className:`aspect-ratio-selector__option ${o===T.value?"aspect-ratio-selector__option--selected":""}`,"data-track":"ai_click_ratio_select",onClick:()=>s(T.value),children:e.jsx("span",{className:"aspect-ratio-selector__option-ratio",children:T.label})})},T.value))})]})};function Fs(){return ga("scene")}function is(o,s){return{id:Fs(),order:o,duration:s,prompt:""}}function fo(o,s,n=1){if(o.length===0)return{valid:!1,error:"至少需要一个场景"};for(const a of o){if(a.duration<n)return{valid:!1,error:`场景 ${a.order} 时长不能少于 ${n} 秒`};if(a.duration>s)return{valid:!1,error:`场景 ${a.order} 时长不能超过 ${s} 秒`}}const i=o.find(a=>!a.prompt.trim());return i?{valid:!1,error:`场景 ${i.order} 需要填写提示词`}:{valid:!0}}function ho(o){return o.sort((s,n)=>s.order-n.order).map((s,n)=>`Shot ${n+1}:
|
|
95
|
+
🍼 Fun fact: This documentation is rendered by Milkdown itself!`,no=()=>{const{closeDialog:o}=ft(),{t:s,language:n}=Ye(),[i,a]=t.useState({loaded:!1,api:Promise.resolve({parseMarkdownToDrawnix:(f,v)=>null})});t.useEffect(()=>{(async()=>{try{const v=await kt(()=>import("./index-B67KSDhv.js"),__vite__mapDeps([0]),import.meta.url);a({loaded:!0,api:Promise.resolve(v)})}catch(v){console.error("Failed to load mermaid library:",v),T(new Error(s("dialog.error.loadMermaid")))}})()},[]);const[r,x]=t.useState(()=>rs(n)),[y,C]=t.useState(()=>[]),l=t.useDeferredValue(r.trim()),[p,T]=t.useState(null),k=Nt();t.useEffect(()=>{x(rs(n))},[n]),t.useEffect(()=>{(async()=>{try{const v=await i.api;let u;try{u=await v.parseMarkdownToDrawnix(l)}catch{u=await v.parseMarkdownToDrawnix(l.replace(/"/g,"'"))}const D=u;D.points=[[0,0]],D&&(C([D]),T(null))}catch(v){T(v)}})()},[l,i]);const g=()=>{if(!y.length)return;let f;const v=ps(k);if(v)f=v;else{const D=fs.getBoardContainer(k).getBoundingClientRect(),N=[D.width/4,D.height/2-20],j=k.viewport.zoom,W=hs(k),c=W[0]+N[0]/j,M=W[1]+N[1]/j;f=[c,M]}const u=y;k.insertFragment({elements:JSON.parse(JSON.stringify(u))},f,gs.paste),f&&requestAnimationFrame(()=>{xs(k,f)}),o(he.markdownToDrawnix)};return e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"ttd-dialog-desc",children:s("dialog.markdown.description")}),e.jsxs(ks,{children:[e.jsx(pt,{label:s("dialog.markdown.syntax"),children:e.jsx(Ms,{input:r,placeholder:s("dialog.markdown.placeholder"),onChange:f=>x(f.target.value),onKeyboardSubmit:()=>{g()}})}),e.jsx(pt,{label:s("dialog.markdown.preview"),panelAction:{action:()=>{g()},label:s("dialog.markdown.insert")},renderSubmitShortcut:()=>e.jsx(Ns,{}),children:e.jsx(Ps,{value:y,loaded:i.loaded,error:p})})]})]})};function Ds(){const{completedTasks:o}=Mt(),s=t.useMemo(()=>o.filter(a=>{var r;return a.type===ve.IMAGE&&((r=a.result)==null?void 0:r.url)}).map(a=>({id:a.id,type:"image",prompt:a.params.prompt,timestamp:a.completedAt||a.createdAt,imageUrl:a.result.url,width:a.result.width||1024,height:a.result.height||1024,uploadedImages:a.params.uploadedImages})).sort((a,r)=>r.timestamp-a.timestamp),[o]),n=t.useMemo(()=>o.filter(a=>{var r;return a.type===ve.VIDEO&&((r=a.result)==null?void 0:r.url)}).map(a=>({id:a.id,type:"video",prompt:a.params.prompt,timestamp:a.completedAt||a.createdAt,imageUrl:a.result.thumbnailUrl||a.result.url,width:a.result.width||400,height:a.result.height||225,previewUrl:a.result.url,downloadUrl:a.result.url,uploadedImage:a.params.uploadedImage})).sort((a,r)=>r.timestamp-a.timestamp),[o]),i=t.useMemo(()=>[...s,...n].sort((a,r)=>r.timestamp-a.timestamp),[s,n]);return{imageHistory:s,videoHistory:n,allHistory:i}}const ro=[1,2,3,4,5,10,20,50,100],io="aitu_image_generation_quantity",lo="aitu_video_generation_quantity",jt=100,Rs=({language:o,type:s,isGenerating:n,hasGenerated:i,canGenerate:a,onGenerate:r,onReset:x,leftContent:y})=>{const C=s==="video"?lo:io,[l,p]=t.useState(()=>{try{const c=localStorage.getItem(C);if(c){const M=parseInt(c,10);if(!isNaN(M)&&M>=1&&M<=jt)return M}}catch{}return 1}),[T,k]=t.useState(!1),[g,f]=t.useState(()=>l.toString()),v=t.useRef(null);t.useEffect(()=>{f(l.toString());try{localStorage.setItem(C,l.toString())}catch{}},[l,C]),t.useEffect(()=>{const c=M=>{v.current&&!v.current.contains(M.target)&&(k(!1),u())};return document.addEventListener("mousedown",c),()=>document.removeEventListener("mousedown",c)},[g]);const u=()=>{let c=parseInt(g,10);(isNaN(c)||c<1)&&(c=1),c>jt&&(c=jt),f(c.toString()),p(c)},D=c=>{const M=c.target.value;(M===""||/^\d*$/.test(M))&&f(M)},N=c=>{p(c),f(c.toString()),k(!1)},j=()=>{n||k(!T)},W=()=>{r(l)};return e.jsxs("div",{className:"section-actions unified-action-bar",children:[y&&e.jsx("div",{className:"action-bar-left",children:y}),e.jsxs("div",{className:`unified-action-box ${n?"is-generating":""} ${a?"can-generate":""}`,children:[e.jsxs("div",{className:"quantity-section",ref:v,children:[e.jsx(Fe,{content:o==="zh"?"生成数量":"Quantity",theme:"light",children:e.jsxs("div",{className:`quantity-control ${T?"is-open":""} ${n?"is-disabled":""}`,children:[e.jsx("input",{type:"text",inputMode:"numeric",value:g,onChange:D,onBlur:u,"data-track":"ai_click_quantity_input",onClick:()=>!n&&k(!0),disabled:n,className:"quantity-input"}),e.jsx("button",{type:"button","data-track":"ai_click_quantity_toggle",onClick:c=>{c.stopPropagation(),j()},disabled:n,className:"quantity-toggle",children:e.jsx(bs,{className:`quantity-icon ${T?"is-open":""}`})})]})}),T&&e.jsxs("div",{className:"quantity-dropdown",children:[e.jsx("div",{className:"quantity-dropdown-header",children:o==="zh"?"选择数量":"Select Quantity"}),ro.map(c=>e.jsxs("button",{type:"button","data-track":"ai_click_quantity_select",onClick:()=>N(c),className:`quantity-option ${l===c?"is-selected":""}`,children:[e.jsxs("span",{children:[c," ",s==="video"?o==="zh"?"个":c>1?"videos":"video":o==="zh"?"张":c>1?"images":"image"]}),l===c&&e.jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:e.jsx("polyline",{points:"20 6 9 17 4 12"})})]},c))]})]}),e.jsx("div",{className:"action-divider"}),e.jsx("button",{"data-track":"ai_click_generate",onClick:W,disabled:n||!a,className:`generate-button ${n?"loading":""}`,children:n?o==="zh"?"生成中...":"Generating...":i?o==="zh"?"重新生成":"Regenerate":s==="video"?o==="zh"?"生成视频":"Generate Video":o==="zh"?"生成":"Generate"})]}),e.jsx(Fe,{content:o==="zh"?"重置表单":"Reset form",theme:"light",children:e.jsx(ut,{"data-track":"ai_click_reset",onClick:x,disabled:n,variant:"text",shape:"circle",icon:e.jsx(ta,{}),className:"action-button--reset-subtle"})})]})},Os=({error:o})=>o?e.jsx("div",{className:"form-error",children:o}):null,As=({visible:o,query:s,position:n,showBelow:i=!1,selectedIndex:a,onSelect:r,onClose:x})=>{const{completedCharacters:y,isLoading:C}=Cs(),l=t.useRef(null),p=t.useMemo(()=>{if(!s)return y;const g=s.toLowerCase();return y.filter(f=>f.username.toLowerCase().includes(g))},[y,s]);t.useEffect(()=>{if(!o||!l.current)return;const g=l.current.querySelector(".character-mention-popup__item--selected");g&&g.scrollIntoView({block:"nearest"})},[o,a]),t.useEffect(()=>{if(!o)return;const g=f=>{l.current&&!l.current.contains(f.target)&&x()};return document.addEventListener("mousedown",g),()=>document.removeEventListener("mousedown",g)},[o,x]);const T=t.useCallback(g=>{sa.track("character_used_in_prompt",{characterId:g.id,username:g.username}),r(g)},[r]);if(!o)return null;const k={position:"fixed",top:n.top,left:n.left,transform:i?"none":"translateY(-100%)",zIndex:vs.DROPDOWN_PORTAL,maxHeight:"200px",overflowY:"auto"};return C?e.jsx("div",{ref:l,className:"character-mention-popup",style:k,children:e.jsx("div",{className:"character-mention-popup__empty",children:"加载中..."})}):p.length===0?e.jsx("div",{ref:l,className:"character-mention-popup",style:k,children:e.jsx("div",{className:"character-mention-popup__empty",children:s?`未找到 "${s}" 相关角色`:"暂无可用角色"})}):e.jsx("div",{ref:l,className:"character-mention-popup",style:k,children:p.map((g,f)=>e.jsxs("div",{className:`character-mention-popup__item ${f===a?"character-mention-popup__item--selected":""}`,onClick:()=>T(g),"data-track":"character_click_mention",children:[e.jsx("div",{className:"character-mention-popup__item-avatar",children:e.jsx(Za,{characterId:g.id,profilePictureUrl:g.profilePictureUrl,alt:g.username})}),e.jsxs("span",{className:"character-mention-popup__item-name",children:["@",g.username]})]},g.id))})},co={visible:!1,query:"",position:{top:0,left:0},showBelow:!1,startIndex:-1,selectedIndex:0};function zs({enabled:o=!0,onPromptChange:s,prompt:n}){const[i,a]=t.useState(co),r=t.useRef(null),{completedCharacters:x}=Cs(),y=t.useCallback(g=>{if(!r.current)return{top:0,left:0,showBelow:!1};const f=r.current,v=f.getBoundingClientRect(),u=document.createElement("div"),D=window.getComputedStyle(f),N=["fontFamily","fontSize","fontWeight","fontStyle","letterSpacing","lineHeight","textTransform","wordSpacing","whiteSpace","paddingTop","paddingRight","paddingBottom","paddingLeft","borderTopWidth","borderRightWidth","borderBottomWidth","borderLeftWidth","boxSizing"];u.style.position="absolute",u.style.top="0",u.style.left="-9999px",u.style.visibility="hidden",u.style.whiteSpace="pre-wrap",u.style.overflowWrap="break-word",u.style.overflow="hidden",u.style.width=`${f.clientWidth}px`,N.forEach(G=>{u.style[G]=D.getPropertyValue(G.replace(/([A-Z])/g,"-$1").toLowerCase())}),document.body.appendChild(u);let j=0,W=0;try{const G=f.value.substring(0,g),ge=document.createTextNode(G),J=document.createElement("span");J.textContent="",u.appendChild(ge),u.appendChild(J);const ye=J.getBoundingClientRect(),O=u.getBoundingClientRect();j=ye.top-O.top,W=ye.left-O.left}finally{document.body.removeChild(u)}const c=f.scrollTop,M=parseInt(D.lineHeight)||20;let R=v.top+j-c,V=v.left+W;const A=240,X=window.innerWidth;V+A>X-16&&(V=X-A-16),V<16&&(V=16);const le=R<220+16;return le?R=R+M+4:R=R-48,{top:R,left:V,showBelow:le}},[]),C=t.useCallback((g,f)=>{if(!o)return;const v=g.substring(0,f),u=v.lastIndexOf("@");if(u===-1){a(W=>({...W,visible:!1}));return}const D=u>0?g[u-1]:" ";if(!/\s/.test(D)&&u!==0){a(W=>({...W,visible:!1}));return}const N=v.substring(u+1);if(N.includes(" ")){a(W=>({...W,visible:!1}));return}const j=y(f);a({visible:!0,query:N,position:{top:j.top,left:j.left},showBelow:j.showBelow,startIndex:u,selectedIndex:0})},[o,y]),l=t.useCallback(g=>{var N;if(i.startIndex===-1)return;const f=n.substring(0,i.startIndex),v=((N=r.current)==null?void 0:N.selectionStart)||n.length,u=n.substring(v),D=`${f}@${g.username} ${u}`;s(D),a(j=>({...j,visible:!1})),setTimeout(()=>{if(r.current){const j=f.length+g.username.length+2;r.current.focus(),r.current.setSelectionRange(j,j)}},0)},[i.startIndex,n,s]),p=t.useCallback(g=>{if(!i.visible)return;const f=i.query?x.filter(v=>v.username.toLowerCase().includes(i.query.toLowerCase())):x;switch(g.key){case"ArrowDown":g.preventDefault(),a(v=>({...v,selectedIndex:Math.min(v.selectedIndex+1,f.length-1)}));break;case"ArrowUp":g.preventDefault(),a(v=>({...v,selectedIndex:Math.max(v.selectedIndex-1,0)}));break;case"Enter":case"Tab":f.length>0&&(g.preventDefault(),l(f[i.selectedIndex]));break;case"Escape":g.preventDefault(),a(v=>({...v,visible:!1}));break}},[i,x,l]),T=t.useCallback((g,f)=>{s(g),C(g,f)},[s,C]),k=t.useCallback(()=>{a(g=>({...g,visible:!1}))},[]);return{mentionState:i,setMentionState:a,textareaRef:r,completedCharacters:x,handleTextChange:T,handleKeyDown:p,handleCharacterSelect:l,closeMentionPopup:k,calculateMentionPosition:y}}const Ls=({prompt:o,onPromptChange:s,presetPrompts:n,language:i,type:a,disabled:r=!1,onError:x,enableMention:y=!0,videoProvider:C})=>{const[l,p]=t.useState(!1),[T,k]=t.useState(!1),g=t.useRef(null),f=t.useRef(null),[v,u]=t.useState(null),[D,N]=t.useState(0),j=t.useMemo(()=>et.sortPrompts(a,n).map((E,Q)=>({id:`preset-${Q}-${E.slice(0,20)}`,content:E,pinned:et.isPinned(a,E)})),[a,n,D]),W=y&&a==="video"&&C==="sora",{mentionState:c,textareaRef:M,handleTextChange:R,handleKeyDown:V,handleCharacterSelect:A,closeMentionPopup:X}=zs({enabled:W,onPromptChange:s,prompt:o}),K=t.useCallback(()=>{if(f.current&&l){const L=f.current.getBoundingClientRect(),E=8,Q=320,oe=400,Se=window.innerHeight-L.top+4,ne=Math.min(Q,window.innerWidth-E*2),ae=window.innerWidth-L.right,xe=window.innerWidth-ne-E,Ce=Math.max(Math.min(ae,xe),E),ie=Math.min(oe,L.top-E,window.innerHeight*.45);u({bottom:Se,right:Ce,maxHeight:ie})}},[l]);t.useEffect(()=>{if(l)return K(),window.addEventListener("scroll",K,!0),window.addEventListener("resize",K),()=>{window.removeEventListener("scroll",K,!0),window.removeEventListener("resize",K)}},[l,K]),t.useEffect(()=>{const L=E=>{const Q=E.target;if(g.current&&!g.current.contains(Q)){const oe=document.querySelector(".preset-prompt-panel-portal");oe!=null&&oe.contains(Q)||p(!1)}};if(l)return document.addEventListener("mousedown",L),()=>document.removeEventListener("mousedown",L)},[l]);const le=t.useCallback(L=>{const E=typeof L=="string"?L:L.content;s(E),x==null||x(null),p(!1)},[s,x]),G=t.useCallback(L=>{const E=j.find(Q=>Q.id===L);E&&(E.pinned?et.unpinPrompt(a,E.content):et.pinPrompt(a,E.content),N(Q=>Q+1))},[a,j]),ge=t.useCallback(L=>{const E=j.find(Q=>Q.id===L);E&&(et.deletePrompt(a,E.content),N(Q=>Q+1))},[a,j]),J=t.useCallback(L=>{const E=L.target.value,Q=L.target.selectionStart||0;R(E,Q),x==null||x(null)},[R,x]);t.useEffect(()=>{a!=="video"&&X()},[a,X]);const ye=t.useCallback(()=>{if(console.info("[PromptOptimize] handleOpenOptimizeDialog",{type:a,language:i,promptLength:o.trim().length,disabled:r}),!o.trim()){Ne.warning(i==="zh"?"请先输入提示词":"Please enter a prompt first");return}k(!0)},[r,i,o,a]),O=()=>{if(!l||!v)return null;const L=i==="zh"?`${a==="image"?"图片":"视频"}描述预设`:`${a==="image"?"Image":"Video"} Description Presets`,E=e.jsx("div",{className:"preset-prompt-panel-portal",style:{position:"fixed",bottom:v.bottom,right:v.right,zIndex:vs.DIALOG_POPOVER,"--panel-max-width":"calc(100vw - 16px)","--panel-max-height":`${v.maxHeight}px`},children:e.jsx(na,{title:L,items:j,onSelect:le,onTogglePin:G,onDelete:ge,language:i,disabled:r,showCount:!0})});return ra.createPortal(E,document.body)};return e.jsxs("div",{className:"form-field form-field--prompt",children:[e.jsxs("div",{className:"form-label-with-icon",children:[e.jsx("label",{className:"form-label",children:i==="zh"?`${a==="image"?"图片":"视频"}描述`:`${a==="image"?"Image":"Video"} Description`}),e.jsx("div",{className:"textarea-with-preset",children:e.jsxs("div",{className:"preset-tooltip-container",ref:g,children:[e.jsx("button",{ref:f,type:"button",className:"preset-icon-button",disabled:r,onClick:()=>p(!l),children:e.jsx(aa,{size:16})}),O()]})})]}),e.jsxs("div",{className:"prompt-textarea-wrapper",children:[e.jsx("textarea",{ref:M,className:"form-textarea",value:o,onChange:J,onKeyDown:V,placeholder:qa(i,a,C),rows:4,disabled:r}),e.jsx("button",{type:"button",className:"prompt-optimize-button",onClick:ye,disabled:r,"aria-label":i==="zh"?"优化提示词":"Optimize prompt",title:i==="zh"?"优化提示词":"Optimize prompt",children:e.jsx(oa,{size:16})})]}),W&&e.jsx(As,{visible:c.visible,query:c.query,position:c.position,showBelow:c.showBelow,selectedIndex:c.selectedIndex,onSelect:A,onClose:X}),e.jsx(Ya,{open:T,onOpenChange:k,originalPrompt:o,language:i,type:a,allowStructuredMode:!0,onApply:L=>{s(L),x==null||x(null)}})]})};function uo(o){return o.map(s=>s.prompt.trim()).filter(s=>s.length>0).filter((s,n,i)=>i.indexOf(s)===n)}const $s=(o,s,n)=>{const i=o==="image"?Ka(s):Ha(s),a=uo(n);return[...[...o==="video"?ia():la(),...a].filter((C,l,p)=>p.indexOf(C)===l).slice(0,ca),...i].filter((C,l,p)=>p.indexOf(C)===l).slice(0,da)},Vs=(o,s,n)=>{!s||!s.trim()||(o==="video"?ua(s.trim()):ma(s.trim()))},mo=({model:o,configOverride:s,duration:n,size:i,onDurationChange:a,onSizeChange:r,disabled:x=!1})=>{const y=s||pa(o),C=y.durationOptions,l=y.sizeOptions,p=C.some(u=>u.value===n),T=l.some(u=>u.value===i),k=p?n:y.defaultDuration,g=T?i:y.defaultSize,f=C.map(u=>({label:u.label,value:u.value})),v=l.map(u=>({label:u.label,value:u.value}));return e.jsxs("div",{className:"video-model-options",children:[e.jsxs("div",{className:"video-model-options__row",children:[e.jsx("label",{className:"video-model-options__label",children:"时长"}),e.jsx("div",{className:"video-model-options__control",children:C.length===1?e.jsx("span",{className:"video-model-options__fixed-value",children:C[0].label}):e.jsx(lt.Group,{value:k,onChange:u=>{const D=u;D!==k&&a(D)},disabled:x,variant:"default-filled",size:"small",children:f.map(u=>e.jsx(lt.Button,{value:u.value,children:u.label},u.value))})})]}),e.jsxs("div",{className:"video-model-options__row",children:[e.jsx("label",{className:"video-model-options__label",children:"尺寸"}),e.jsx("div",{className:"video-model-options__control",children:l.length===1?e.jsx("span",{className:"video-model-options__fixed-value",children:l[0].label}):e.jsx(lt.Group,{value:g,onChange:u=>{const D=u;D!==g&&r(D)},disabled:x,variant:"default-filled",size:"small",children:v.map(u=>e.jsx(lt.Button,{value:u.value,children:u.label},u.value))})})]})]})},po=({value:o,onChange:s,compact:n=!0,options:i})=>{const{language:a}=Ye(),[r,x]=t.useState(!1),y=t.useRef(null),C=i&&i.length>0?i:dt,l=t.useMemo(()=>o==="auto"?fa:ha(o),[o]);t.useEffect(()=>{const T=k=>{y.current&&!y.current.contains(k.target)&&x(!1)};return r&&document.addEventListener("mousedown",T),()=>{document.removeEventListener("mousedown",T)}},[r]);const p=T=>{s(T.value),x(!1)};return n?e.jsxs("div",{className:"aspect-ratio-selector aspect-ratio-selector--compact",ref:y,children:[e.jsx(Fe,{content:a==="zh"?"选择图片比例":"Select aspect ratio",theme:"light",children:e.jsxs("div",{className:`aspect-ratio-selector__trigger ${r?"aspect-ratio-selector__trigger--open":""}`,"data-track":"ai_click_ratio_toggle",onClick:()=>x(!r),children:[e.jsx("span",{className:"aspect-ratio-selector__trigger-value",children:(l==null?void 0:l.label)||o}),e.jsx(bs,{className:`aspect-ratio-selector__trigger-icon ${r?"aspect-ratio-selector__trigger-icon--open":""}`})]})}),r&&e.jsx("div",{className:"aspect-ratio-selector__dropdown",children:e.jsx("div",{className:"aspect-ratio-selector__dropdown-grid",children:C.map(T=>e.jsx(Fe,{content:T.description,theme:"light",placement:"top",showArrow:!1,children:e.jsx("div",{className:`aspect-ratio-selector__dropdown-item ${o===T.value?"aspect-ratio-selector__dropdown-item--selected":""}`,"data-track":"ai_click_ratio_select",onClick:()=>p(T),children:T.label})},T.value))})})]}):e.jsxs("div",{className:"aspect-ratio-selector",children:[e.jsx("div",{className:"aspect-ratio-selector__label",children:a==="zh"?"图片比例":"Aspect Ratio"}),e.jsx("div",{className:"aspect-ratio-selector__options",children:C.map(T=>e.jsx(Fe,{content:T.description,theme:"light",placement:"top",showArrow:!1,children:e.jsx("div",{className:`aspect-ratio-selector__option ${o===T.value?"aspect-ratio-selector__option--selected":""}`,"data-track":"ai_click_ratio_select",onClick:()=>s(T.value),children:e.jsx("span",{className:"aspect-ratio-selector__option-ratio",children:T.label})})},T.value))})]})};function Fs(){return ga("scene")}function is(o,s){return{id:Fs(),order:o,duration:s,prompt:""}}function fo(o,s,n=1){if(o.length===0)return{valid:!1,error:"至少需要一个场景"};for(const a of o){if(a.duration<n)return{valid:!1,error:`场景 ${a.order} 时长不能少于 ${n} 秒`};if(a.duration>s)return{valid:!1,error:`场景 ${a.order} 时长不能超过 ${s} 秒`}}const i=o.find(a=>!a.prompt.trim());return i?{valid:!1,error:`场景 ${i.order} 需要填写提示词`}:{valid:!0}}function ho(o){return o.sort((s,n)=>s.order-n.order).map((s,n)=>`Shot ${n+1}:
|
|
96
96
|
duration: ${s.duration}sec
|
|
97
97
|
Scene: ${s.prompt.trim()}`).join(`
|
|
98
98
|
|
|
99
|
-
`)}function go(o){const s=/Shot\s+(\d+):\s*\n\s*duration:\s*([\d.]+)\s*sec\s*\n\s*Scene:\s*([^\n]+(?:\n(?!Shot\s+\d+:)[^\n]*)*)/gi,n=[];let i;for(;(i=s.exec(o))!==null;){const a=parseInt(i[1],10),r=parseFloat(i[2]),x=i[3].trim();n.push({id:Fs(),order:a,duration:r,prompt:x})}return n.length===0?null:n.sort((a,r)=>a.order-r.order)}const xo=({value:o,onChange:s,placeholder:n,disabled:i=!1,autoFocus:a=!1,enableMention:r=!0})=>{const{mentionState:x,textareaRef:y,handleTextChange:C,handleKeyDown:l,handleCharacterSelect:p,closeMentionPopup:T}=zs({enabled:r,onPromptChange:s,prompt:o}),k=t.useCallback(g=>{const f=g.target.value,v=g.target.selectionStart||0;C(f,v)},[C]);return t.useEffect(()=>{a&&y.current&&y.current.focus()},[a,y]),e.jsxs("div",{className:"scene-prompt-input",children:[e.jsx("textarea",{ref:y,className:"scene-prompt-input__textarea",value:o,onChange:k,onKeyDown:l,placeholder:n,disabled:i,rows:3}),r&&e.jsx(As,{visible:x.visible,query:x.query,position:x.position,showBelow:x.showBelow,selectedIndex:x.selectedIndex,onSelect:p,onClose:T})]})},bo=({enabled:o,onEnabledChange:s,totalDuration:n,maxScenes:i,minSceneDuration:a,scenes:r,onScenesChange:x,disabled:y=!1})=>{const[C,l]=t.useState(null),p=t.useRef(null),T=r.map(c=>c.id).join("|");t.useEffect(()=>{if(!o||r.length===0)return;!(C?r.some(M=>M.id===C):!1)&&C!==r[0].id&&l(r[0].id)},[o,T,r,C]);const k=t.useCallback(()=>{if(r.length>=i)return;const c=r.reduce((A,X)=>A+X.duration,0),M=n-c;let R=Math.max(a,M/2);R=parseFloat(R.toFixed(1)),R<a&&(R=a);const V=is(r.length+1,R);x([...r,V]),l(V.id),setTimeout(()=>{var A;(A=p.current)==null||A.scrollIntoView({behavior:"smooth"})},100)},[r,i,n,a,x]),g=t.useCallback(c=>{var V;if(r.length<=1)return;const R=r.filter(A=>A.id!==c).map((A,X)=>({...A,order:X+1}));x(R),C===c&&l(((V=R[0])==null?void 0:V.id)||null)},[r,x,C]),f=t.useCallback(c=>{const M=r.filter(R=>R.id!==c).reduce((R,V)=>R+V.duration,0);return Math.max(a,n-M)},[r,n,a]),v=t.useCallback(c=>{const M=f(c),R=[],V=.1;for(let A=a;A<=M+.001;A+=V){const X=parseFloat(A.toFixed(1));X<=M&&R.push({label:`${X}`,value:X})}return R},[a,f]),u=t.useCallback((c,M)=>{const R=typeof M=="string"?parseFloat(M):M;if(isNaN(R))return;const V=f(c),A=r.map(X=>{if(X.id===c){const K=Math.max(a,Math.min(R,V)),le=parseFloat(K.toFixed(1));return le===X.duration?X:{...X,duration:le}}return X});A.every((X,K)=>X===r[K])||x(A)},[r,a,f,x]),D=t.useCallback((c,M)=>{const R=r.find(A=>A.id===c);if((R==null?void 0:R.prompt)===M)return;const V=r.map(A=>A.id===c?{...A,prompt:M}:A);x(V)},[r,x]),N=t.useCallback(c=>{if(s(c),c&&r.length===0){const M=is(1,n);x([M]),l(M.id)}},[r,n,s,x]),j=t.useCallback(c=>{l(c)},[]),W=r.length<i;return e.jsxs("div",{className:"storyboard-editor",children:[e.jsxs("div",{className:"storyboard-editor__header",children:[e.jsxs("div",{className:"storyboard-editor__toggle",children:[e.jsx(xa,{value:o,onChange:N,disabled:y,size:"small"}),e.jsxs("div",{className:"storyboard-editor__title",children:[e.jsx("span",{className:"storyboard-editor__title-text",children:"故事场景模式"}),e.jsx("span",{className:"storyboard-editor__title-desc",children:"定义多个场景及其时长"})]})]}),o&&e.jsx("span",{className:"storyboard-editor__new-badge",children:"NEW"})]}),o&&e.jsxs("div",{className:"storyboard-editor__content",children:[e.jsxs("div",{className:"storyboard-editor__section-header",children:[e.jsx("span",{className:"storyboard-editor__section-title",children:"场景列表"}),e.jsxs("span",{className:"storyboard-editor__section-hint",children:["共 ",r.length," 个场景,已用 ",r.reduce((c,M)=>c+M.duration,0).toFixed(1)," 秒 / 总时长 ",n," 秒"]})]}),e.jsxs("div",{className:"storyboard-editor__scenes",children:[r.map((c,M)=>{const R=C===c.id,V=M===r.length-1;return e.jsxs("div",{className:`storyboard-editor__scene-wrapper ${R?"is-selected":""}`,children:[e.jsx("div",{className:`storyboard-editor__timeline-line ${V?"is-last":""}`}),e.jsx("div",{className:`storyboard-editor__timeline-node ${R?"is-selected":""}`,children:R?M+1:""}),!R&&e.jsxs("div",{className:"storyboard-editor__scene storyboard-editor__scene--compact",onClick:()=>j(c.id),children:[e.jsx("span",{className:"storyboard-editor__scene-index",children:M+1}),e.jsx("div",{className:"storyboard-editor__scene-preview",children:e.jsx("p",{className:"storyboard-editor__scene-preview-text",children:c.prompt||"暂无场景描述..."})}),e.jsxs("div",{className:"storyboard-editor__scene-duration-badge",children:[e.jsx(Ut,{size:"12px"}),e.jsxs("span",{children:[c.duration,"s"]})]}),e.jsx(ws,{className:"storyboard-editor__scene-arrow",size:"14px"})]}),R&&e.jsxs("div",{className:"storyboard-editor__scene storyboard-editor__scene--expanded",children:[e.jsxs("div",{className:"storyboard-editor__scene-header",children:[e.jsx("div",{className:"storyboard-editor__scene-info",children:e.jsxs("span",{className:"storyboard-editor__scene-label",children:[e.jsx("span",{className:"storyboard-editor__active-indicator"}),"场景 ",M+1]})}),e.jsxs("div",{className:"storyboard-editor__scene-controls",children:[e.jsx(Ut,{className:"storyboard-editor__time-icon"}),e.jsx(ba,{value:parseFloat(c.duration.toFixed(1)),onChange:A=>u(c.id,A),disabled:y,className:"storyboard-editor__duration-select",size:"small",options:v(c.id),filterable:!0,creatable:!0,popupProps:{overlayClassName:"storyboard-editor__duration-popup"}}),r.length>1&&e.jsx(ut,{theme:"default",variant:"text",size:"small",icon:e.jsx(ys,{}),onClick:A=>{A.stopPropagation(),g(c.id)},disabled:y,className:"storyboard-editor__scene-delete"})]})]}),e.jsx("div",{className:"storyboard-editor__scene-prompt",children:e.jsx(xo,{value:c.prompt,onChange:A=>D(c.id,A),placeholder:`描述场景 ${M+1} 的内容,输入 @ 可引用角色`,disabled:y,autoFocus:!0,enableMention:!0})})]})]},c.id)}),e.jsx("div",{ref:p})]}),W&&e.jsx(ut,{theme:"default",variant:"dashed",size:"medium",icon:e.jsx(va,{}),onClick:k,disabled:y,className:"storyboard-editor__add-btn",block:!0,children:"添加场景"})]})]})},Us="aitu-dialog-task-list-width-",Dt=240,Rt=800,vo=()=>{const o=Math.round(660);return Math.max(Dt,Math.min(Rt,o))},Gs=o=>{try{const s=localStorage.getItem(Us+o);if(s){const n=parseInt(s,10);if(!isNaN(n)&&n>=Dt&&n<=Rt)return n}}catch{}return vo()},ls=(o,s)=>{try{localStorage.setItem(Us+o,s.toString())}catch{}},Ws=({isRightPanelVisible:o,onToggleRightPanel:s,onWidthChange:n,rightPanelWidth:i,minWidth:a=Dt,maxWidth:r=Rt,onResizeStart:x,onResizeEnd:y,language:C="zh",disabled:l=!1,storageKey:p="image"})=>{const[T,k]=t.useState(!1),g=t.useRef(0),f=t.useRef(0);t.useEffect(()=>(T?(document.body.style.userSelect="none",document.body.style.cursor="col-resize"):(document.body.style.userSelect="",document.body.style.cursor=""),()=>{document.body.style.userSelect="",document.body.style.cursor=""}),[T]);const v=t.useCallback(D=>{if(l||!o)return;D.preventDefault(),D.stopPropagation(),k(!0),g.current=D.clientX,f.current=i,x==null||x();const N=W=>{const c=g.current-W.clientX,M=Math.max(a,Math.min(r,f.current+c));n(M)},j=()=>{k(!1),y==null||y(),f.current+(g.current-document.body.getBoundingClientRect().left),ls(p,i),document.removeEventListener("mousemove",N),document.removeEventListener("mouseup",j)};document.addEventListener("mousemove",N),document.addEventListener("mouseup",j)},[l,o,i,a,r,n,x,y,p]);t.useEffect(()=>{!T&&o&&ls(p,i)},[i,T,o,p]);const u=o?C==="zh"?"隐藏任务列表":"Hide Task List":C==="zh"?"显示任务列表":"Show Task List";return e.jsxs("div",{className:`resizable-divider ${T?"is-dragging":""} ${o?"":"is-collapsed"} ${l?"is-disabled":""}`,onMouseDown:v,children:[e.jsx("div",{className:"resizable-divider__bar"}),e.jsx(Fe,{content:u,placement:"left",children:e.jsx("button",{type:"button",className:"resizable-divider__toggle",onClick:D=>{D.stopPropagation(),s()},"aria-label":u,children:o?e.jsx(ws,{size:"14px"}):e.jsx(wa,{size:"14px"})})})]})},Bs=({storageKey:o,language:s})=>{const[n,i]=t.useState(()=>{try{return localStorage.getItem(o)!=="false"}catch{return!0}}),a=t.useCallback(r=>{i(r);try{localStorage.setItem(o,String(r))}catch{}},[o]);return e.jsx(Fe,{content:s==="zh"?"生成后自动插入画布":"Auto insert to canvas after generation",theme:"light",children:e.jsx(ya,{checked:n,onChange:a,className:"auto-insert-checkbox"})})};function Et(o){try{return localStorage.getItem(o)!=="false"}catch{return!0}}function wo(o={}){const{taskType:s}=o,{tasks:n,isLoading:i}=Ia(),{retryTask:a,deleteTask:r}=Sa(),x=t.useMemo(()=>[...s?n.filter(p=>p.type===s):n].sort((p,T)=>T.createdAt-p.createdAt),[n,s]),y=t.useCallback(async()=>{},[]),C=t.useCallback(async()=>{if(_a(),!await Gt.isAvailable())return;const p=await Gt.getAllTasks();p.length>0&&ja.restoreTasks(p)},[]);return{tasks:x,isLoading:i,isLoadingMore:!1,hasMore:!1,totalCount:x.length,loadedCount:x.length,loadMore:y,refresh:C,retryTask:a,deleteTask:r}}const Ks=({taskIds:o,taskType:s,onEditTask:n})=>{const{tasks:i,isLoading:a,isLoadingMore:r,hasMore:x,totalCount:y,loadedCount:C,loadMore:l,retryTask:p,deleteTask:T}=wo({taskType:s}),{board:k,openDialog:g}=ft(),[f,v]=t.useState(!1),[u,D]=t.useState(null),[N,j]=t.useState(!1),[W,c]=t.useState(0),[M,R]=t.useState("single"),[V,A]=t.useState(""),[X,K]=t.useState(null),[le,G]=t.useState(!1),ge=t.useMemo(()=>i.filter(d=>d.status===Ve.FAILED).length,[i]),J=t.useCallback(()=>{const d=i.filter(m=>m.status===Ve.FAILED);d.forEach(m=>T(m.id)),G(!1),Ne.success(`已清除 ${d.length} 个失败任务`)},[i,T]),ye=(d,m)=>{var me,z,_e,pe,Ee,ce,fe,ue,re,we,Te;if(!m.trim())return!0;const P=m.toLowerCase().split(/\s+/).filter(Boolean),S={[Ve.PENDING]:"处理中",[Ve.PROCESSING]:"处理中",[Ve.COMPLETED]:"已完成",[Ve.FAILED]:"失败",[Ve.CANCELLED]:"已取消"},$=[],U=(me=d.params)!=null&&me.params&&typeof d.params.params=="object"?d.params.params:null;$.push(((z=d.params)==null?void 0:z.prompt)??""),$.push(((_e=d.params)==null?void 0:_e.model)??""),$.push(d.id??""),$.push(S[d.status]??String(d.status)),(pe=d.params)!=null&&pe.batchId&&$.push(String(d.params.batchId)),(Ee=d.params)!=null&&Ee.batchIndex&&$.push(String(d.params.batchIndex)),(ce=d.params)!=null&&ce.batchTotal&&$.push(String(d.params.batchTotal)),typeof(U==null?void 0:U.model_name)=="string"&&$.push(U.model_name),typeof(U==null?void 0:U.mode)=="string"&&$.push(U.mode),typeof(U==null?void 0:U.klingAction2)=="string"&&$.push(U.klingAction2),(fe=d.result)!=null&&fe.format&&$.push(String(d.result.format)),(ue=d.result)!=null&&ue.width&&((re=d.result)!=null&&re.height)?$.push(`${d.result.width}x${d.result.height}`):(we=d.params)!=null&&we.width&&((Te=d.params)!=null&&Te.height)&&$.push(`${d.params.width}x${d.params.height}`);const B=$.join(" ").toLowerCase();return P.every(Me=>B.includes(Me))},O=t.useMemo(()=>{let d=i;return o&&o.length>0&&(d=d.filter(m=>o.includes(m.id))),V.trim()&&(d=d.filter(m=>ye(m,V))),d.sort((m,P)=>P.createdAt-m.createdAt)},[i,o,V]),L=d=>{p(d)},E=d=>{D(d),v(!0)},Q=()=>{u&&T(u),v(!1),D(null)},oe=async d=>{const m=i.find(S=>S.id===d);if(!m)return;const P=Na(m);if(P.length!==0)try{const S=await Da(P);S.openedCount>0&&S.downloadedCount===0?Ne.success(S.openedCount>1?`已打开 ${S.openedCount} 个链接,请在新标签页下载`:"资源不支持直接下载,已打开链接"):Ne.success(m.type===ve.AUDIO?P.length>1?"多条音频已开始下载":"音频下载成功":P.length>1?"多图已开始下载":"下载成功")}catch(S){console.error("Download failed:",S),Ne.error("下载失败,请稍后重试")}},Se=async d=>{var P,S,$,U;const m=i.find(B=>B.id===d);if(!((P=m==null?void 0:m.result)!=null&&P.url)&&!(($=(S=m==null?void 0:m.result)==null?void 0:S.urls)!=null&&$.length)||!k){console.warn("Cannot insert: task result or board not available"),Ne.warning("无法插入:白板未就绪");return}try{if(m.type===ve.IMAGE){const B=(U=m.result.urls)!=null&&U.length?m.result.urls:[m.result.url];for(const me of B)await Ma(k,me);Ne.success(B.length>1?"多图已插入到白板":"图片已插入到白板")}else m.type===ve.VIDEO&&(await Pa(k,m.result.url),Ne.success("视频已插入到白板"))}catch(B){console.error("Failed to insert to board:",B),Ne.error(`插入失败: ${B instanceof Error?B.message:"未知错误"}`)}},ne=d=>{var P,S,$,U;const m=i.find(B=>B.id===d);if(!m){console.warn("Cannot edit: task not found");return}if(n){n(m);return}if(m.type===ve.IMAGE){const B={initialPrompt:m.params.prompt,initialWidth:m.params.width,initialHeight:m.params.height,initialImages:m.params.uploadedImages,initialResultUrl:(P=m.result)==null?void 0:P.url,initialResultUrls:(S=m.result)==null?void 0:S.urls};g(he.aiImageGeneration,B)}else if(m.type===ve.VIDEO){const B={initialPrompt:m.params.prompt,initialDuration:typeof m.params.seconds=="string"?parseInt(m.params.seconds,10):m.params.seconds,initialModel:m.params.model,initialSize:m.params.size,initialImages:m.params.uploadedImages,initialResultUrl:($=m.result)==null?void 0:$.url,initialResultUrls:(U=m.result)==null?void 0:U.urls};g(he.aiVideoGeneration,B)}},ae=d=>{const m=i.find(P=>P.id===d);m&&K(m)},xe=t.useMemo(()=>{const d=new Set;return O.filter(m=>{var P,S,$,U;return m.status!==Ve.COMPLETED||!((P=m.result)!=null&&P.url)&&!(($=(S=m.result)==null?void 0:S.urls)!=null&&$.length)||m.type!==ve.IMAGE&&m.type!==ve.VIDEO&&!(m.type===ve.AUDIO&&((U=m.result)==null?void 0:U.resultKind)!=="lyrics")||d.has(m.id)?!1:(d.add(m.id),!0)})},[O]),{previewMediaItems:Ce,taskIdToPreviewConfig:ie}=t.useMemo(()=>{var P,S,$,U,B,me;const d=[],m=new Map;for(const z of xe){const _e=d.length,pe=((P=z.result)==null?void 0:P.title)||z.params.title||((S=z.params.prompt)==null?void 0:S.substring(0,50))||"媒体预览";if(z.type===ve.AUDIO){const ce=((U=($=z.result)==null?void 0:$.clips)==null?void 0:U.filter(re=>!!re.audioUrl).map((re,we)=>{var Te,Me,Ue;return{id:re.clipId||re.id||`${z.id}-${we}`,url:re.audioUrl,type:"audio",title:re.title||((Te=z.result)!=null&&Te.clips&&z.result.clips.length>1?`${pe} (${we+1}/${z.result.clips.length})`:pe),posterUrl:re.imageLargeUrl||re.imageUrl||((Me=z.result)==null?void 0:Me.previewImageUrl),duration:typeof re.duration=="number"?re.duration:(Ue=z.result)==null?void 0:Ue.duration,prompt:z.params.prompt,tags:typeof z.params.tags=="string"?z.params.tags:void 0,artist:z.params.model||z.params.mv||"Aitu",album:"Aitu Generated"}}))??[],fe=(B=z.result.urls)!=null&&B.length?z.result.urls:z.result.url?[z.result.url]:[],ue=ce.length>0?ce:fe.map((re,we)=>{var Te,Me;return{id:fe.length>1?`${z.id}-${we}`:z.id,url:re,type:"audio",title:fe.length>1?`${pe} (${we+1}/${fe.length})`:pe,posterUrl:(Te=z.result)==null?void 0:Te.previewImageUrl,duration:(Me=z.result)==null?void 0:Me.duration,prompt:z.params.prompt,tags:typeof z.params.tags=="string"?z.params.tags:void 0,artist:z.params.model||z.params.mv||"Aitu",album:"Aitu Generated"}});d.push(...ue)}else{const ce=(me=z.result.urls)!=null&&me.length?z.result.urls:[z.result.url],fe=z.type===ve.VIDEO?"video":"image";for(let ue=0;ue<ce.length;ue++)d.push({id:ce.length>1?`${z.id}-${ue}`:z.id,url:fe==="image"?Ca(ce[ue]):ce[ue],type:fe,title:ce.length>1?`${pe} (${ue+1}/${ce.length})`:pe})}const Ee=d.length-_e;m.set(z.id,{mode:z.type===ve.AUDIO&&Ee>1?"compare":"single",index:z.type===ve.AUDIO&&Ee>1?Array.from({length:Math.min(Ee,4)},(ce,fe)=>_e+fe):_e})}return{previewMediaItems:d,taskIdToPreviewConfig:m}},[xe]),I=t.useCallback(d=>{const m=ie.get(d);m!==void 0&&(R(m.mode),c(m.index),j(!0))},[ie]),Z=t.useCallback(()=>{j(!1)},[]),be=V.trim()&&O.length===0&&i.length>0,ke=y>0?y:i.length;return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"dialog-task-list",children:[e.jsxs("div",{className:"dialog-task-list__header",children:[e.jsxs("div",{className:"dialog-task-list__header-main",children:[e.jsxs("h4",{children:["生成任务 (",ke,")"]}),e.jsx("div",{className:"dialog-task-list__header-actions",children:ge>0&&e.jsx(Fe,{content:`清除全部失败任务 (${ge})`,theme:"light",children:e.jsx(ut,{size:"small",variant:"text",icon:e.jsx(ys,{}),onClick:()=>G(!0)})})})]}),e.jsx("div",{className:"dialog-task-list__search",children:e.jsx(Ta,{value:V,onChange:d=>A(d),placeholder:"搜索任务(提示词/模型/...)",clearable:!0,prefixIcon:e.jsx(Ea,{}),size:"small"})})]}),e.jsx(eo,{tasks:O,onRetry:L,onDelete:E,onDownload:oe,onInsert:Se,onEdit:ne,onPreviewOpen:I,onExtractCharacter:ae,hasMore:x,isLoadingMore:r,onLoadMore:l,totalCount:ke,loadedCount:C,className:"dialog-task-list__content",emptyContent:e.jsx("div",{className:"dialog-task-list__empty",children:a?e.jsx("p",{children:"加载中..."}):be?e.jsx("p",{children:"未找到匹配的任务"}):e.jsx("p",{children:"暂无生成任务"})})})]}),e.jsx(Wt,{open:f,title:"确认删除",description:"确定要删除此任务吗?此操作无法撤销。",confirmText:"删除",cancelText:"取消",danger:!0,onOpenChange:v,onConfirm:Q}),e.jsx(Wt,{open:le,title:"清除失败任务",description:`确定要清除全部 ${ge} 个失败任务吗?此操作无法撤销。`,confirmText:"清除",cancelText:"取消",danger:!0,onOpenChange:G,onConfirm:J}),e.jsx(ka,{visible:N,items:Ce,initialMode:M,initialIndex:W,onClose:Z,showThumbnails:!0}),e.jsx(to,{visible:!!X,task:X,onClose:()=>K(null),onCreateComplete:d=>{K(null)}})]})},yo=({initialPrompt:o="",initialImages:s=[],selectedElementIds:n=[],initialWidth:i,initialHeight:a,initialResultUrl:r,initialAspectRatio:x,targetFrameId:y,targetFrameDimensions:C,selectedModel:l,selectedModelRef:p,onModelChange:T,onModelRefChange:k,externalBatchId:g,initialAutoInsertToCanvas:f,onDraftChange:v}={})=>{var De,at,ot;const u=Es("image"),D=qe("image"),N=Le(u,D.modelId,Ae(D.profileId,D.modelId))||mt("image",D.modelId,Ae(D.profileId,D.modelId)),[j,W]=t.useState((N==null?void 0:N.id)||((De=u[0])==null?void 0:De.id)||"gemini-2.5-flash-image-vip"),[c,M]=t.useState(Oe(N)||Ae(D.profileId,D.modelId)),R=Ie((N==null?void 0:N.id)||((at=u[0])==null?void 0:at.id)||"gemini-2.5-flash-image-vip",Oe(N)||Ae(D.profileId,D.modelId)),V=ss((N==null?void 0:N.id)||((ot=u[0])==null?void 0:ot.id)||"gemini-2.5-flash-image-vip",R),[A,X]=t.useState(o),[K,le]=t.useState(V.extraParams),G=t.useMemo(()=>{if(Le(u,j,c)||!j)return u;const F=mt("image",j,c);return F?[F,...u]:u},[j,c,u]),[ge,J]=t.useState(i||1024),[ye,O]=t.useState(a||1024),[L,E]=t.useState(x||V.aspectRatio||wt),[Q,oe]=t.useState(null),[Se,ne]=t.useState(s),[ae,xe]=t.useState(!0),[Ce,ie]=t.useState(()=>Gs("image")),[I,Z]=t.useState("config"),be=t.useRef(null),{viewportWidth:ke}=Pt(),d=ke<=768,{imageHistory:m}=Ds(),{isGenerating:P}=Ss("image"),{language:S}=Ye(),{createTask:$}=Mt(),U=t.useRef(!1),B=j.startsWith("mj"),me=de.useMemo(()=>{if(B)return[];const b=Ra(j);if(b.length===0)return dt;const F=new Map(dt.map(Y=>[Y.value,Y])),H=[];return b.forEach(Y=>{const je=Y.value==="auto"?"auto":Y.value.replace("x",":"),Pe=F.get(je);Pe&&!H.some(Re=>Re.value===Pe.value)&&H.push(Pe)}),H.length>0?H:dt},[j,B]),z=de.useMemo(()=>{const b=Oa(j);return B?b.length>0:b.some(F=>F.id!=="size")},[j,B]),[_e,pe]=t.useState(!1);t.useEffect(()=>{if(_e)return;const b=ss(j,Ie(j,c));le(b.extraParams),E(b.aspectRatio)},[j,c,_e]);const Ee=t.useCallback((b,F)=>{if(!F||F==="default"){le(H=>{const Y={...H};return delete Y[b],Y});return}le(H=>({...H,[b]:F}))},[]),ce=t.useCallback(b=>{ie(b)},[]),fe=t.useCallback(()=>{xe(b=>!b)},[]),ue=de.useRef("");t.useEffect(()=>{if(_e)return;const b=JSON.stringify({prompt:o,images:s==null?void 0:s.map(F=>F.url),elementIds:n,width:i,height:a,result:r,aspectRatio:x});ue.current!==b&&(ue.current=b,X(o),ne(s||[]),i&&J(i),a&&O(a),x&&E(x))},[o,s,n,i,a,r,x,_e]);const re=t.useRef("");t.useEffect(()=>{if(!v)return;const b={prompt:A,images:Se.map(Y=>({url:Y.url,name:Y.name})),aspectRatio:L},F=JSON.stringify(b);if(re.current===F)return;const H=window.setTimeout(()=>{re.current!==F&&(re.current=F,v(b))},200);return()=>{window.clearTimeout(H)}},[L,v,A,Se]),t.useEffect(()=>{const b=F=>{var Y;const H=F.imageModelName||((Y=G[0])==null?void 0:Y.id)||"gemini-2.5-flash-image-vip";if(H!==j){W(H);const je=Le(G,H,c);M(Oe(je)||null)}};return ze.addListener(b),()=>ze.removeListener(b)},[j,c,G]),t.useEffect(()=>{if(G.length===0)return;if(!Le(G,j,c)){const F=G[0];W(F.id);const H=Oe(F);M(Y=>Y&&H&&Y.profileId===H.profileId&&Y.modelId===H.modelId?Y:H)}},[j,c,G]),t.useEffect(()=>{if(!l)return;const b=Ie(j,c),F=Ie(l,p);if(b!==F){W(l);const H=Le(G,l,p),Y=Oe(H)||p||null;M(je=>je&&Y&&je.profileId===Y.profileId&&je.modelId===Y.modelId?je:Y)}},[j,c,l,p,G]),t.useEffect(()=>{!z&&Object.keys(K).length>0&&le({})},[z,K]),t.useEffect(()=>{var F;if(B||me.length===0)return;const b=new Set(me.map(H=>H.value));if(!b.has(L)){const H=b.has("auto")?"auto":((F=me[0])==null?void 0:F.value)||wt;E(H)}},[L,B,me]),t.useEffect(()=>{Xa({currentModel:j,currentSelectionKey:Ie(j,c),extraParams:K,aspectRatio:L})},[j,c,K,L]),t.useEffect(()=>(oe(null),()=>{oe(null)}),[]);const we=()=>{X(""),le({}),ne([]),oe(null),E(wt),Z("config"),pe(!1),window.dispatchEvent(new CustomEvent("ai-image-clear"))},Te=de.useMemo(()=>$s("image",S,m),[m,S]),Me=b=>{Vs("image",b)},Ue=b=>{if(pe(!0),Z("config"),X(b.params.prompt||""),le({}),J(b.params.width||1024),O(b.params.height||1024),b.params.uploadedImages&&b.params.uploadedImages.length>0?ne(b.params.uploadedImages):ne([]),b.params.model){W(b.params.model),M(b.params.modelRef||null);const F=ze.get();ze.update({...F,imageModelName:b.params.model})}b.params.aspectRatio&&E(b.params.aspectRatio),oe(null)},ht=async()=>Promise.all(Se.map(async b=>{if(b.file)return new Promise((F,H)=>{const Y=new FileReader;Y.onload=()=>{F({type:"url",url:Y.result,name:b.name})},Y.onerror=H,Y.readAsDataURL(b.file)});if(b.url)return{type:"url",url:b.url,name:b.name};throw new Error("Invalid image data")})),st=async(b=1)=>{if(!U.current){U.current=!0;try{if(!A||!A.trim()){oe(S==="zh"?"请输入图像描述":"Please enter image description");return}if(!Aa("image",c||j)&&!await za()){oe(S==="zh"?"需要 API Key 才能生成图片":"API Key is required to generate images");return}B&&oe(null);try{const F=typeof ge=="string"?parseInt(ge)||1024:ge,H=typeof ye=="string"?parseInt(ye)||1024:ye,Y=await ht();if(b>1){const Ge=[],xt=`batch_${Date.now()}`,Be=j||qe("image").modelId,rt=Be.startsWith("mj")?[A.trim(),as(K)].filter(Boolean).join(" "):(A||"").trim(),$e=!Be.startsWith("mj")&&Object.keys(K).length>0?K:void 0,bt=$e!=null&&$e.size?$e.size:Bt(L);for(let Je=0;Je<b;Je++){const Qe={prompt:rt,width:F,height:H,aspectRatio:L,size:bt,model:Be,modelRef:c||null,uploadedImages:Y,batchId:xt,batchIndex:Je+1,batchTotal:b,autoInsertToCanvas:f??Et(tt.AI_IMAGE_AUTO_INSERT),targetFrameId:y,targetFrameDimensions:C,...$e?{params:$e}:{}},it=$(Qe,ve.IMAGE);it&&Ge.push(it.id)}Ge.length>0?(Ne.success(S==="zh"?`已添加 ${Ge.length} 个任务到队列`:`Added ${Ge.length} tasks to queue`),Me(rt),oe(null),Z("tasks"),pe(!1)):oe(S==="zh"?"批量任务创建失败,请稍后重试":"Failed to create batch tasks, please try again later");return}const je=j||qe("image").modelId,Pe=je.startsWith("mj")?[A.trim(),as(K)].filter(Boolean).join(" "):(A||"").trim(),Re=!je.startsWith("mj")&&Object.keys(K).length>0?K:void 0,Xe=Re!=null&&Re.size?Re.size:Bt(L),nt={prompt:Pe,width:F,height:H,aspectRatio:L,size:Xe,model:je,modelRef:c||null,uploadedImages:Y,autoInsertToCanvas:f??Et(tt.AI_IMAGE_AUTO_INSERT),batchId:g||`image_single_${Date.now()}`,batchIndex:1,batchTotal:1,targetFrameId:y,targetFrameDimensions:C,...Re?{params:Re}:{}};$(nt,ve.IMAGE)?(Ne.success(S==="zh"?"任务已添加到队列,将在后台生成":"Task added to queue, will be generated in background"),Me(Pe),oe(null),Z("tasks"),pe(!1)):oe(S==="zh"?"任务创建失败,请检查参数或稍后重试":"Failed to create task, please check parameters or try again later")}catch(F){console.error("Failed to create task:",F);let H=S==="zh"?"任务创建失败,请检查参数或稍后重试":"Failed to create task, please check parameters or try again later";F.message&&(F.message.includes("exceed 5000 characters")?H=S==="zh"?"提示词不能超过 5000 字符":"Prompt must not exceed 5000 characters":F.message.includes("Duplicate submission")?H=S==="zh"?"请勿重复提交,请等待 5 秒后再试":"Duplicate submission. Please wait 5 seconds.":F.message.includes("Invalid parameters")&&(H=S==="zh"?`参数错误: ${F.message.replace("Invalid parameters: ","")}`:F.message)),oe(H)}}finally{U.current=!1}}};return _s(P,A,()=>st(1)),e.jsxs("div",{className:"ai-image-generation-container",children:[d?e.jsxs("div",{className:"ai-generation-mobile-switcher",role:"tablist",children:[e.jsx("button",{type:"button",className:`ai-generation-mobile-switcher__tab ${I==="config"?"ai-generation-mobile-switcher__tab--active":""}`,onClick:()=>Z("config"),children:"生成设置"}),e.jsx("button",{type:"button",className:`ai-generation-mobile-switcher__tab ${I==="tasks"?"ai-generation-mobile-switcher__tab--active":""}`,onClick:()=>Z("tasks"),children:"生成任务"})]}):null,e.jsxs("div",{className:`main-content ${d?"main-content--mobile-panels":""}`,ref:be,children:[e.jsxs("div",{className:`ai-image-generation-section ${d&&I!=="config"?"ai-generation-mobile-panel--hidden":""}`,children:[e.jsxs("div",{className:"ai-image-generation-form",children:[l!==void 0&&T&&e.jsx("div",{className:"form-header-row",children:e.jsx("div",{className:"model-selector-wrapper",children:e.jsx(Is,{selectedModel:j,selectedSelectionKey:Ie(j,c),onSelect:b=>{W(b),M(null),T(b),k==null||k(null)},onSelectModel:b=>{W(b.id);const F=Oe(b);M(F),T(b.id),k==null||k(F)},language:S,models:G,placement:"down",variant:"form",disabled:P})})}),z&&e.jsx("div",{className:"model-params-row",children:e.jsx(js,{selectedParams:K,onParamChange:Ee,modelId:j,language:S,disabled:P,excludeParamIds:B?void 0:["size"]})}),e.jsx(Ts,{images:Se,onImagesChange:ne,language:S,disabled:P,multiple:!0,label:S==="zh"?"参考图片 (可选)":"Reference Images (Optional)",onError:oe}),e.jsx(Ls,{prompt:A,onPromptChange:X,presetPrompts:Te,language:S,type:"image",disabled:P,onError:oe}),e.jsx(Os,{error:Q})]}),e.jsx(Rs,{language:S,type:"image",isGenerating:P,hasGenerated:!1,canGenerate:!!(A&&A.trim()),onGenerate:st,onReset:we,leftContent:e.jsxs(e.Fragment,{children:[e.jsx(Bs,{storageKey:tt.AI_IMAGE_AUTO_INSERT,language:S}),!B&&e.jsx(po,{value:L,onChange:E,compact:!0,options:me})]})})]}),d?null:e.jsx(Ws,{isRightPanelVisible:ae,onToggleRightPanel:fe,onWidthChange:ce,rightPanelWidth:Ce,language:S,storageKey:"image"}),(d||ae)&&e.jsx("div",{className:`task-sidebar ${d?"task-sidebar--mobile-panel":""} ${d&&I!=="tasks"?"ai-generation-mobile-panel--hidden":""}`,style:d?void 0:{width:Ce,flexShrink:0},children:e.jsx(Ks,{taskType:ve.IMAGE,onEditTask:Ue})})]})]})};function cs(o,s){const n=Object.keys(o),i=Object.keys(s);return n.length!==i.length?!1:n.every(a=>o[a]===s[a])}function ds(o,s,n){return o.slice(0,s).map((i,a)=>({...i,slot:a,slotLabel:n[a]||`参考图${a+1}`}))}function Io(o,s){return o.length===s.length&&o.every((n,i)=>{const a=s[i];return n.slot===a.slot&&n.slotLabel===a.slotLabel&&n.url===a.url&&n.name===a.name&&n.file===a.file})}function us(o,s){return s.some(n=>n.value===o)}function ms(o){const s=o==null?void 0:o.trim().replace(/[xX]/g,":");return s&&/^\d+:\d+$/.test(s)?s:null}function ct(o){var n;const s=(n=o==null?void 0:o.split("@")[0])==null?void 0:n.trim();return s&&/^\d+p$/.test(s)?s:null}function Ct(o,s){return((o==null?void 0:o.profileId)||null)===((s==null?void 0:s.profileId)||null)&&((o==null?void 0:o.modelId)||null)===((s==null?void 0:s.modelId)||null)}function Hs(o,s){const n=Ae(s==null?void 0:s.profileId,s==null?void 0:s.modelId);return(n==null?void 0:n.modelId)===(o||null)?n:null}function We(o,s,n){if(!s)return null;const i=Hs(s,n),a=Le(o,s,i);return Oe(a)||i}const So=({initialPrompt:o="",initialImage:s,initialImages:n,initialDuration:i,initialModel:a,initialSize:r,initialResultUrl:x,selectedModel:y,selectedModelRef:C,onModelChange:l,onModelRefChange:p,externalBatchId:T,initialAutoInsertToCanvas:k,onDraftChange:g}={})=>{var At,zt,Lt;const f=Es("video"),[v,u]=t.useState(o),[D,N]=t.useState(null),[j,W]=t.useState(!0),[c,M]=t.useState(()=>Gs("video")),[R,V]=t.useState("config"),A=t.useRef(null),{viewportWidth:X}=Pt(),K=X<=768,le=qe("video"),G=a||le.modelId,ge=Hs(G,a&&a===y?C:le.modelId===G?Ae(le.profileId,le.modelId):null),J=Le(f,G,ge)||mt("video",G,ge),ye=We(f,(J==null?void 0:J.id)||G,Oe(J)||ge),[O,L]=t.useState((J==null?void 0:J.id)||((At=f[0])==null?void 0:At.id)||yt("veo3")),[E,Q]=t.useState(ye),oe=Ie((J==null?void 0:J.id)||((zt=f[0])==null?void 0:zt.id)||yt("veo3"),ye),Se=os((J==null?void 0:J.id)||((Lt=f[0])==null?void 0:Lt.id)||yt("veo3"),oe),ne=de.useMemo(()=>{if(Le(f,O,E)||!O)return f;const w=mt("video",O,E);return w?[w,...f]:f},[O,E,f]),[ae,xe]=t.useState(()=>Se.extraParams),Ce=de.useMemo(()=>La(O,E||O,ae),[O,E,ae]),ie=de.useMemo(()=>It(O,E||O,ae),[O,E,ae]),I=de.useMemo(()=>{if(ie.provider!=="seedance")return ie;const h=ms(ae.aspect_ratio)||ms(ae.aspectRatio)||"16:9",w=new Set,_=ie.sizeOptions.map(te=>ct(te.value)).filter(te=>!te||w.has(te)?!1:(w.add(te),!0)),q=_.map(te=>({label:te,value:`${te}@${h}`,aspectRatio:h})),ee=ct(ie.defaultSize)||_[0]||"720p";return{...ie,sizeOptions:q,defaultSize:`${ee}@${h}`}},[ie,ae.aspectRatio,ae.aspect_ratio]),Z=de.useMemo(()=>$a(O,E||O,ae),[O,E,ae]),be=de.useMemo(()=>(ie.imageUpload.labels||[]).join("|"),[ie.imageUpload.labels]),ke=de.useMemo(()=>be?be.split("|"):[],[be]),d=de.useMemo(()=>({maxCount:ie.imageUpload.maxCount,mode:ie.imageUpload.mode,labels:ke,labelsSignature:be}),[ie.imageUpload.maxCount,ie.imageUpload.mode,ke,be]),[m,P]=t.useState((i==null?void 0:i.toString())||Se.duration),[S,$]=t.useState(r||Se.size),U=de.useMemo(()=>us(m,I.durationOptions)?m:I.defaultDuration,[m,I.defaultDuration,I.durationOptions]),B=de.useMemo(()=>{if(us(S,I.sizeOptions))return S;if(I.provider==="seedance"){const h=ct(S),w=I.sizeOptions.find(_=>ct(_.value)===h);if(w)return w.value}return I.defaultSize},[S,I]),me=de.useMemo(()=>Ce.some(h=>h.id!=="size"&&h.id!=="duration"),[Ce]),z=t.useCallback((h,w)=>{if(!w||w==="default"){xe(_=>{const q={..._};return delete q[h],q});return}xe(_=>({..._,[h]:w}))},[]);t.useEffect(()=>{const h=Ce.reduce((w,_)=>{const q=ae[_.id],ee=!q||_.valueType!=="enum"||!_.options||_.options.some(te=>te.value===q);return q&&ee?w[_.id]=q:_.defaultValue&&(w[_.id]=_.defaultValue),w},{});cs(ae,h)||xe(h)},[Ce,ae]);const[_e,pe]=t.useState(()=>n&&n.length>0?n:s?[{slot:0,slotLabel:"参考图",url:s.url||"",name:s.name,file:s.file}]:[]),[Ee,ce]=t.useState(()=>{const h=ie.imageUpload.maxCount,w=ie.imageUpload.labels||[];let _=[];return n&&n.length>0?_=n:s&&(_=[{slot:0,slotLabel:w[0]||"参考图",url:s.url||"",name:s.name,file:s.file}]),_.slice(0,h).map((q,ee)=>({...q,slot:ee,slotLabel:w[ee]||`参考图${ee+1}`}))}),[fe,ue]=t.useState(!1),[re,we]=t.useState([]),Te=de.useMemo(()=>Va(O),[O]),Me=Kt(O),{videoHistory:Ue}=Ds(),[ht,st]=t.useState(0),{isGenerating:De}=Ss("video"),at=t.useCallback(h=>{M(h)},[]),ot=t.useCallback(()=>{W(h=>!h)},[]),{language:b}=Ye(),{createTask:F}=Mt(),H=t.useRef(!1),Y=y!==void 0,je=de.useRef(null),Pe=de.useRef(null);t.useEffect(()=>{if(Y)return;const h=w=>{const _=w.videoModelName||"veo3";if(_!==O){L(_);const q=We(ne,_,E);Q(q)}};return ze.addListener(h),()=>ze.removeListener(h)},[O,E,Y,y,C,ne]),t.useEffect(()=>{if(ne.length===0)return;const h=Le(ne,O,E),w=We(ne,O,E);if(!h){const _=ne[0],q=Oe(_);L(_.id),Q(ee=>Ct(ee,q)?ee:q);return}Q(_=>Ct(_,w)?_:w)},[O,E,ne]),t.useEffect(()=>{if(!y)return;const h=Ie(y,C);if(je.current===h||Pe.current&&Pe.current!==y)return;je.current=h,L(_=>_===y?_:y);const w=We(ne,y,C);Q(_=>Ct(_,w)?_:w)},[y,C,ne,a]);const[Re,Xe]=t.useState(!1),[nt,gt]=t.useState(!1);t.useEffect(()=>{if(nt){gt(!1);return}const h=os(O,Ie(O,E)),w=It(O,E||O,h.extraParams),_=w.durationOptions.some(se=>se.value===h.duration)?h.duration:w.defaultDuration,q=w.sizeOptions.some(se=>se.value===h.size)?h.size:w.defaultSize;xe(se=>cs(se,h.extraParams)?se:h.extraParams);const ee=i!==void 0?i.toString():_,te=r||q;P(se=>se===ee?se:ee),$(se=>se===te?se:te),Kt(O)||(ue(se=>se&&!1),we(se=>se.length>0?[]:se))},[O,E,nt,i,r]),t.useEffect(()=>{const h=_e.length>0?ds(_e,d.maxCount,d.labels):[];ce(w=>Io(w,h)?w:h)},[_e,d.labels,d.labelsSignature,d.maxCount]),t.useEffect(()=>{Ja({currentModel:O,currentSelectionKey:Ie(O,E),extraParams:ae,duration:U,size:B})},[O,E,U,B,ae]);const Ge=de.useRef("");t.useEffect(()=>{if(Re)return;const h=JSON.stringify({prompt:o,image:s==null?void 0:s.url,images:n==null?void 0:n.map(q=>q.url),duration:i,model:a,size:r,result:x});if(Ge.current===h)return;Ge.current=h,a&&(Pe.current=a,L(a),Q(We(f,a,C))),u(o);let w=[];n&&n.length>0?w=n:s&&(w=[{slot:0,slotLabel:"参考图",url:s.url||"",name:s.name,file:s.file}]),pe(w);const _=ds(w,d.maxCount,d.labels);ce(_),i!==void 0&&P(i.toString()),r&&$(r),N(null)},[o,s,n,i,r,x,d.labels,d.labelsSignature,d.maxCount,Re]),t.useEffect(()=>(N(null),()=>{N(null)}),[]);const xt=()=>{u(""),pe([]),ce([]),N(null),V("config"),P(Z.duration),$(Z.size),Xe(!1),ue(!1),we([]),xe(St(O,E||O)),window.dispatchEvent(new CustomEvent("ai-video-clear"))},Be=de.useCallback((h,w)=>h.map((_,q)=>({slot:q,slotLabel:w[q]||`参考图${q+1}`,url:_.url,name:_.name,file:_.file})),[]),rt=de.useCallback(h=>h.map(w=>({url:w.url,name:w.name,file:w.file})),[]),$e=de.useCallback(h=>{const w=Be(h,d.labels);ce(w),pe(w)},[d.labels,Be]),bt=de.useMemo(()=>$s("video",b,Ue),[Ue,b,ht]),Je=h=>{Vs("video",h),st(w=>w+1)},Qe=t.useRef("");t.useEffect(()=>{if(!g)return;const h=Number.parseFloat(U),w={prompt:v,images:Ee.map(ee=>({url:ee.url,name:ee.name})),duration:Number.isFinite(h)?h:void 0,size:B||void 0},_=JSON.stringify(w);if(Qe.current===_)return;const q=window.setTimeout(()=>{Qe.current!==_&&(Qe.current=_,g(w))},200);return()=>{window.clearTimeout(q)}},[U,B,g,v,Ee]);const it=h=>{var _,q;if(Xe(!0),V("config"),gt(!0),h.params.model){L(h.params.model),Q(h.params.modelRef||null);const ee=ze.get();ze.update({...ee,videoModelName:h.params.model})}if((_=h.params.storyboard)!=null&&_.enabled&&((q=h.params.storyboard)!=null&&q.scenes))ue(!0),we(h.params.storyboard.scenes),u("");else{const ee=h.params.prompt||"",te=go(ee);te&&te.length>0?(ue(!0),we(te),u("")):(ue(!1),we([]),u(ee))}if(h.params.seconds!==void 0){const ee=typeof h.params.seconds=="string"?h.params.seconds:h.params.seconds.toString();P(ee)}const w=h.params.params&&typeof h.params.params=="object"?Object.entries(h.params.params).reduce((ee,[te,se])=>(se!=null&&String(se).trim()&&(ee[te]=String(se)),ee),{}):{};if(xe(w),h.params.size&&$(h.params.size),h.params.uploadedImages&&h.params.uploadedImages.length>0){pe(h.params.uploadedImages);const ee=h.params.model||O,te=It(ee,h.params.modelRef||ee,w),se=te.imageUpload.maxCount,Ze=te.imageUpload.labels||[],Ke=h.params.uploadedImages.slice(0,se).map((He,vt)=>({...He,slot:vt,slotLabel:Ze[vt]||`参考图${vt+1}`}));ce(Ke)}else pe([]),ce([]);N(null)},Ot=async(h=1)=>{if(!H.current){H.current=!0;try{if(fe){const w=fo(re,parseFloat(U),Te.minSceneDuration);if(!w.valid){N(w.error||"场景配置无效");return}}else if(!v||!v.trim()){N(b==="zh"?"请输入视频描述":"Please enter video description");return}try{const w=[];for(const te of Ee)if(te.file){const se=await new Promise((Ze,Ke)=>{const He=new FileReader;He.onload=()=>Ze(He.result),He.onerror=Ke,He.readAsDataURL(te.file)});w.push({...te,url:se,file:void 0})}else w.push({...te,file:void 0});const _=fe?ho(re):(v||"").trim(),q=[],ee=T||`video_batch_${Date.now()}`;for(let te=0;te<h;te++){const se=Object.keys(ae).length>0?ae:void 0,Ze={prompt:_,model:O,modelRef:E||null,seconds:U,size:B,uploadedImages:w,...fe&&{storyboard:{enabled:!0,scenes:re,totalDuration:parseFloat(U)}},batchId:ee,batchIndex:te+1,batchTotal:h,autoInsertToCanvas:k??Et(tt.AI_VIDEO_AUTO_INSERT),...se?{params:se}:{}},Ke=F(Ze,ve.VIDEO);Ke&&q.push(Ke.id)}q.length>0?(Ne.success(b==="zh"?h>1?`${q.length} 个视频任务已添加到队列,将在后台生成`:"视频任务已添加到队列,将在后台生成":h>1?`${q.length} video tasks added to queue, will be generated in background`:"Video task added to queue, will be generated in background"),Je(_),u(""),pe([]),ce([]),ue(!1),we([]),N(null),V("tasks"),Xe(!1)):N(b==="zh"?"任务创建失败,请检查参数或稍后重试":"Failed to create task, please check parameters or try again later")}catch(w){console.error("Failed to create task:",w);let _=b==="zh"?"任务创建失败,请检查参数或稍后重试":"Failed to create task, please check parameters or try again later";w.message&&(w.message.includes("exceed 5000 characters")?_=b==="zh"?"提示词不能超过 5000 字符":"Prompt must not exceed 5000 characters":w.message.includes("Duplicate submission")?_=b==="zh"?"请勿重复提交,请等待 5 秒后再试":"Duplicate submission. Please wait 5 seconds.":w.message.includes("Invalid parameters")&&(_=b==="zh"?`参数错误: ${w.message.replace("Invalid parameters: ","")}`:w.message)),N(_)}}finally{H.current=!1}}};return _s(De,v,Ot),e.jsxs("div",{className:"ai-video-generation-container",children:[K?e.jsxs("div",{className:"ai-generation-mobile-switcher",role:"tablist",children:[e.jsx("button",{type:"button",className:`ai-generation-mobile-switcher__tab ${R==="config"?"ai-generation-mobile-switcher__tab--active":""}`,onClick:()=>V("config"),children:"生成设置"}),e.jsx("button",{type:"button",className:`ai-generation-mobile-switcher__tab ${R==="tasks"?"ai-generation-mobile-switcher__tab--active":""}`,onClick:()=>V("tasks"),children:"生成任务"})]}):null,e.jsxs("div",{className:`main-content ${K?"main-content--mobile-panels":""}`,ref:A,children:[e.jsxs("div",{className:`ai-image-generation-section ${K&&R!=="config"?"ai-generation-mobile-panel--hidden":""}`,children:[e.jsxs("div",{className:"ai-image-generation-form",children:[y!==void 0&&l&&e.jsx("div",{className:"form-header-row",children:e.jsx("div",{className:"model-selector-wrapper",children:e.jsx(Is,{selectedModel:O,selectedSelectionKey:Ie(O,E),onSelect:(h,w)=>{const _=h,q=We(ne,_,w||null);Pe.current=null,L(_),Q(q),xe(St(_,q||_)),l(h),p==null||p(q)},onSelectModel:h=>{const w=h.id;Pe.current=null,L(w);const _=We(ne,w,Oe(h));Q(_),xe(St(w,_||w)),l(h.id),p==null||p(_)},language:b,models:ne,placement:"down",variant:"form",placeholder:b==="zh"?"选择视频模型":"Select Video Model",disabled:De})})}),me&&e.jsx("div",{className:"model-params-row",children:e.jsx(js,{selectedParams:ae,onParamChange:z,compatibleParams:Ce,modelId:O,language:b,disabled:De,excludeParamIds:["size","duration"]})}),e.jsx(mo,{model:O,configOverride:I,duration:U,size:B,onDurationChange:P,onSizeChange:$,disabled:De}),e.jsx(Ts,{images:rt(Ee),onImagesChange:$e,language:b,disabled:De,multiple:d.maxCount>1,maxCount:d.maxCount,slotLabels:d.mode==="frames"?d.labels:void 0,label:d.mode==="frames"?b==="zh"?"首尾帧图片 (可选)":"Start/End Frames (Optional)":b==="zh"?"参考图片 (可选)":"Reference Images (Optional)"}),Me&&e.jsx(bo,{enabled:fe,onEnabledChange:ue,totalDuration:parseFloat(U),maxScenes:Te.maxScenes,minSceneDuration:Te.minSceneDuration,scenes:re,onScenesChange:we,disabled:De}),!fe&&e.jsx(Ls,{prompt:v,onPromptChange:u,presetPrompts:bt,language:b,type:"video",disabled:De,onError:N,videoProvider:ie.provider}),e.jsx(Os,{error:D})]}),e.jsx(Rs,{language:b,type:"video",isGenerating:De,hasGenerated:!1,canGenerate:fe?re.length>0:!!(v&&v.trim()),onGenerate:Ot,onReset:xt,leftContent:e.jsx(Bs,{storageKey:tt.AI_VIDEO_AUTO_INSERT,language:b})})]}),K?null:e.jsx(Ws,{isRightPanelVisible:j,onToggleRightPanel:ot,onWidthChange:at,rightPanelWidth:c,language:b,storageKey:"video"}),(K||j)&&e.jsx("div",{className:`task-sidebar ${K?"task-sidebar--mobile-panel":""} ${K&&R!=="tasks"?"ai-generation-mobile-panel--hidden":""}`,style:K?void 0:{width:c,flexShrink:0},children:e.jsx(Ks,{taskType:ve.VIDEO,onEditTask:it})})]})]})},_o=t.lazy(()=>kt(()=>import("./batch-image-generation-Bk8HSFol.js"),__vite__mapDeps([0,1,2,3]),import.meta.url)),jo=({container:o})=>{const{appState:s,openDialog:n,closeDialog:i}=ft(),{language:a}=Ye(),r=Nt(),{isMobile:x,isTablet:y}=Pt(),C=s.dialogInitialDataByType,l=(C==null?void 0:C[he.aiImageGeneration])??null,p=(C==null?void 0:C[he.aiVideoGeneration])??null,T=!x&&!y,k=t.useRef(!1),g=t.useRef(null),[f,v]=t.useState(""),[u,D]=t.useState(null),[N,j]=t.useState(""),[W,c]=t.useState(null),M=t.useRef(null),R=t.useRef(null),V=t.useCallback(()=>{const I=qe("image"),Z=qe("video"),be=I.modelId||"gemini-3-pro-image-preview-vip",ke=Ae(I.profileId,be),d=Z.modelId||"veo3",m=Ae(Z.profileId,d);v(P=>P===be?P:be),D(P=>Ie(be,P)===Ie(be,ke)?P:ke),j(P=>P===d?P:d),c(P=>Ie(d,P)===Ie(d,m)?P:m)},[]);t.useEffect(()=>{V()},[V]),t.useEffect(()=>{const I=()=>{V()};return ze.addListener(I),Ht.addListener(I),()=>{ze.removeListener(I),Ht.removeListener(I)}},[V]);const A=I=>{v(I)},X=I=>{j(I)},K=I=>{D(I)},le=I=>{c(I)};t.useEffect(()=>{if(!f)return;const I=Ie(f,u);M.current!==I&&(M.current=I,qt("image",Ae(u==null?void 0:u.profileId,f)))},[f,u]),t.useEffect(()=>{if(!N)return;const I=Ie(N,W);R.current!==I&&(R.current=I,qt("video",Ae(W==null?void 0:W.profileId,N)))},[N,W]);const[G,ge]=t.useState({initialPrompt:"",initialImages:[],selectedElementIds:[]}),[J,ye]=t.useState({initialPrompt:"",initialImage:void 0}),[O,L]=t.useState(!1),[E,Q]=t.useState(()=>{try{return localStorage.getItem(_t)==="batch"?"batch":"single"}catch{return"single"}});t.useEffect(()=>{!T&&E==="batch"&&Q("single")},[T,E]);const oe=t.useCallback(I=>{Q(I),I==="batch"&&(L(!0),setTimeout(()=>L(!1),50));try{localStorage.setItem(_t,I)}catch(Z){console.warn("Failed to save image mode:",Z)}},[]);t.useEffect(()=>{if(s.openDialogTypes.has(he.aiImageGeneration)){if(G.initialImages&&G.initialImages.length>0||G.initialPrompt&&G.initialPrompt.trim()!==""){L(!1);return}try{localStorage.getItem(_t)==="batch"&&(L(!0),setTimeout(()=>L(!1),50))}catch{L(!1)}}},[s.openDialogTypes,G.initialImages,G.initialPrompt]);const Se=t.useRef(!1),ne=t.useRef(l),ae=t.useRef(!1),xe=t.useRef(p);t.useEffect(()=>{if(!r)return;const I=s.openDialogTypes.has(he.aiImageGeneration),Z=I&&!Se.current,be=ne.current!==l;if(Se.current=I,ne.current=l,!I||!Z&&!be||k.current)return;(async()=>{k.current=!0,g.current&&clearTimeout(g.current),g.current=setTimeout(()=>{console.warn("Processing timeout, resetting processing state"),k.current=!1},1e4);try{if(l){ge({initialPrompt:l.initialPrompt||l.prompt||"",initialImages:l.initialImages||l.uploadedImages||[],selectedElementIds:[],initialResultUrl:l.initialResultUrl||l.resultUrl,initialAspectRatio:l.initialAspectRatio,targetFrameId:l.targetFrameId,targetFrameDimensions:l.targetFrameDimensions}),l.initialModel&&v(l.initialModel),l.initialModelRef!==void 0&&D(l.initialModelRef);return}const d=s.lastSelectedElementIds||[];let m,P,S;const $=Fa(r);if($.length===1&&Ua($[0])){const me=$[0],z=Tt.getRectangleByPoints(me.points);m=Qa(z.width,z.height),P=me.id,S={width:z.width,height:z.height}}const U=await es(r,d),B=[];U.remainingImages.forEach(me=>{B.push({url:me.url,name:me.name||`selected-image-${Date.now()}.png`})}),U.graphicsImage&&B.push({url:U.graphicsImage,name:`graphics-combined-${Date.now()}.png`}),ge({initialPrompt:U.remainingText||"",initialImages:B,selectedElementIds:d,initialAspectRatio:m,targetFrameId:P,targetFrameDimensions:S})}catch(d){console.warn("Error processing selected content for AI:",d);const m=ts(r),P=m.images.map(S=>({url:S.url,name:S.name||`selected-image-${Date.now()}.png`}));ge({initialPrompt:m.text||"",initialImages:P,selectedElementIds:[]})}finally{k.current=!1,g.current&&(clearTimeout(g.current),g.current=null)}})()},[s.lastSelectedElementIds,s.openDialogTypes,r,l]),t.useEffect(()=>{if(!r)return;const I=s.openDialogTypes.has(he.aiVideoGeneration),Z=I&&!ae.current,be=xe.current!==p;if(ae.current=I,xe.current=p,!I||!Z&&!be||k.current)return;(async()=>{k.current=!0,g.current&&clearTimeout(g.current),g.current=setTimeout(()=>{console.warn("Video processing timeout, resetting processing state"),k.current=!1},1e4);try{if(p){ye({initialPrompt:p.initialPrompt||p.prompt||"",initialImage:p.initialImage||p.uploadedImage,initialImages:p.initialImages||p.uploadedImages,initialDuration:p.initialDuration||p.duration,initialModel:p.initialModel||p.model,initialSize:p.initialSize||p.size,initialResultUrl:p.initialResultUrl||p.resultUrl});const S=p.initialModel||p.model;S&&j(S),p.initialModelRef!==void 0&&c(p.initialModelRef);return}const d=s.lastSelectedElementIds||[],m=await es(r,d),P=[];m.remainingImages.length>0?m.remainingImages.forEach((S,$)=>{P.push({url:S.url,name:S.name||`selected-image-${$+1}-${Date.now()}.png`})}):m.graphicsImage&&P.push({url:m.graphicsImage,name:`graphics-combined-${Date.now()}.png`}),ye({initialPrompt:m.remainingText||"",initialImage:P.length>0?P[0]:void 0,initialImages:P.map((S,$)=>({slot:$,slotLabel:`参考图${$+1}`,url:S.url,name:S.name}))})}catch(d){console.warn("Error processing selected content for AI video:",d);const m=ts(r),P=m.images.map((S,$)=>({url:S.url,name:S.name||`selected-image-${$+1}-${Date.now()}.png`}));ye({initialPrompt:m.text||"",initialImage:P.length>0?P[0]:void 0,initialImages:P.map((S,$)=>({slot:$,slotLabel:`参考图${$+1}`,url:S.url,name:S.name}))})}finally{k.current=!1,g.current&&(clearTimeout(g.current),g.current=null)}})()},[s.lastSelectedElementIds,s.openDialogTypes,r,p]),t.useEffect(()=>{s.openDialogTypes.size===0&&(k.current=!1,Se.current=!1,ne.current=null,ae.current=!1,xe.current=null,g.current&&(clearTimeout(g.current),g.current=null))},[s.openDialogTypes]);const Ce=t.useCallback(()=>{const I=localStorage.getItem(Yt);if(I)try{const Z=JSON.parse(I);Z.timestamp=Date.now(),localStorage.setItem(Yt,JSON.stringify(Z))}catch(Z){console.warn("Failed to update cache timestamp:",Z)}i(he.aiImageGeneration)},[i]),ie=t.useCallback(()=>{const I=localStorage.getItem(Xt);if(I)try{const Z=JSON.parse(I);Z.timestamp=Date.now(),localStorage.setItem(Xt,JSON.stringify(Z))}catch(Z){console.warn("Failed to update cache timestamp:",Z)}i(he.aiVideoGeneration)},[i]);return e.jsxs(e.Fragment,{children:[e.jsx(Jt,{open:s.openDialogTypes.has(he.mermaidToDrawnix),onOpenChange:I=>{I?n(he.mermaidToDrawnix):i(he.mermaidToDrawnix)},children:e.jsx(Qt,{className:"Dialog ttd-dialog",container:o,children:e.jsx(oo,{})})}),e.jsx(Jt,{open:s.openDialogTypes.has(he.markdownToDrawnix),onOpenChange:I=>{I?n(he.markdownToDrawnix):i(he.markdownToDrawnix)},children:e.jsx(Qt,{className:"Dialog ttd-dialog",container:o,children:e.jsx(no,{})})}),e.jsx(Zt,{id:"ai-image-dialog",visible:s.openDialogTypes.has(he.aiImageGeneration),title:E==="batch"?a==="zh"?"批量出图":"Batch Generation":a==="zh"?"AI 图片生成":"AI Image Generation",headerContent:T?e.jsxs("div",{className:"image-generation-mode-tabs",onMouseDown:I=>I.stopPropagation(),onTouchStart:I=>I.stopPropagation(),onPointerDown:I=>I.stopPropagation(),children:[e.jsx("button",{type:"button",className:`mode-tab ${E==="single"?"active":""}`,onClick:I=>{I.stopPropagation(),I.preventDefault(),oe("single")},children:a==="zh"?"AI 图片生成":"AI Image"}),e.jsx("button",{type:"button",className:`mode-tab ${E==="batch"?"active":""}`,onClick:I=>{I.stopPropagation(),I.preventDefault(),oe("batch")},children:a==="zh"?"批量出图":"Batch"})]}):void 0,onClose:Ce,width:"80%",height:"60%",minWidth:800,minHeight:500,x:"center",y:"center",modal:!1,minimizable:!1,className:"winbox-ai-generation winbox-ai-image-generation",container:o,autoMaximize:O||x,children:s.openDialogTypes.has(he.aiImageGeneration)&&(E==="batch"?e.jsx(t.Suspense,{fallback:e.jsx("div",{className:"loading-fallback",children:a==="zh"?"加载中...":"Loading..."}),children:e.jsx(_o,{onSwitchToSingle:()=>oe("single"),selectedModel:f,selectedModelRef:u,onModelChange:A,onModelRefChange:K})}):e.jsx(yo,{initialPrompt:G.initialPrompt,initialImages:G.initialImages,selectedElementIds:G.selectedElementIds,initialWidth:(l==null?void 0:l.initialWidth)||(l==null?void 0:l.width),initialHeight:(l==null?void 0:l.initialHeight)||(l==null?void 0:l.height),initialResultUrl:G.initialResultUrl,initialAspectRatio:G.initialAspectRatio,targetFrameId:G.targetFrameId,targetFrameDimensions:G.targetFrameDimensions,selectedModel:f,selectedModelRef:u,onModelChange:A,onModelRefChange:K,externalBatchId:l==null?void 0:l.batchId,initialAutoInsertToCanvas:l==null?void 0:l.autoInsertToCanvas,onDraftChange:l==null?void 0:l.onDraftChange},(l==null?void 0:l.batchId)||"ai-image-dialog"))}),e.jsx(Zt,{id:"ai-video-dialog",visible:s.openDialogTypes.has(he.aiVideoGeneration),title:a==="zh"?"AI 视频生成":"AI Video Generation",onClose:ie,width:"70%",height:"60%",minWidth:800,minHeight:600,x:"center",y:"center",modal:!1,minimizable:!1,className:"winbox-ai-generation winbox-ai-video-generation",container:o,autoMaximize:x,children:s.openDialogTypes.has(he.aiVideoGeneration)&&e.jsx(So,{initialPrompt:J.initialPrompt,initialImage:J.initialImage,initialImages:J.initialImages,initialDuration:J.initialDuration,initialModel:J.initialModel,initialSize:J.initialSize,initialResultUrl:J.initialResultUrl,selectedModel:N,selectedModelRef:W,onModelChange:X,onModelRefChange:le,externalBatchId:p==null?void 0:p.batchId,initialAutoInsertToCanvas:p==null?void 0:p.autoInsertToCanvas,onDraftChange:p==null?void 0:p.onDraftChange},(p==null?void 0:p.batchId)||"ai-video-dialog")})]})},zo=t.memo(jo,(o,s)=>o.container===s.container);export{zo as TTDDialog};
|
|
99
|
+
`)}function go(o){const s=/Shot\s+(\d+):\s*\n\s*duration:\s*([\d.]+)\s*sec\s*\n\s*Scene:\s*([^\n]+(?:\n(?!Shot\s+\d+:)[^\n]*)*)/gi,n=[];let i;for(;(i=s.exec(o))!==null;){const a=parseInt(i[1],10),r=parseFloat(i[2]),x=i[3].trim();n.push({id:Fs(),order:a,duration:r,prompt:x})}return n.length===0?null:n.sort((a,r)=>a.order-r.order)}const xo=({value:o,onChange:s,placeholder:n,disabled:i=!1,autoFocus:a=!1,enableMention:r=!0})=>{const{mentionState:x,textareaRef:y,handleTextChange:C,handleKeyDown:l,handleCharacterSelect:p,closeMentionPopup:T}=zs({enabled:r,onPromptChange:s,prompt:o}),k=t.useCallback(g=>{const f=g.target.value,v=g.target.selectionStart||0;C(f,v)},[C]);return t.useEffect(()=>{a&&y.current&&y.current.focus()},[a,y]),e.jsxs("div",{className:"scene-prompt-input",children:[e.jsx("textarea",{ref:y,className:"scene-prompt-input__textarea",value:o,onChange:k,onKeyDown:l,placeholder:n,disabled:i,rows:3}),r&&e.jsx(As,{visible:x.visible,query:x.query,position:x.position,showBelow:x.showBelow,selectedIndex:x.selectedIndex,onSelect:p,onClose:T})]})},bo=({enabled:o,onEnabledChange:s,totalDuration:n,maxScenes:i,minSceneDuration:a,scenes:r,onScenesChange:x,disabled:y=!1})=>{const[C,l]=t.useState(null),p=t.useRef(null),T=r.map(c=>c.id).join("|");t.useEffect(()=>{if(!o||r.length===0)return;!(C?r.some(M=>M.id===C):!1)&&C!==r[0].id&&l(r[0].id)},[o,T,r,C]);const k=t.useCallback(()=>{if(r.length>=i)return;const c=r.reduce((A,X)=>A+X.duration,0),M=n-c;let R=Math.max(a,M/2);R=parseFloat(R.toFixed(1)),R<a&&(R=a);const V=is(r.length+1,R);x([...r,V]),l(V.id),setTimeout(()=>{var A;(A=p.current)==null||A.scrollIntoView({behavior:"smooth"})},100)},[r,i,n,a,x]),g=t.useCallback(c=>{var V;if(r.length<=1)return;const R=r.filter(A=>A.id!==c).map((A,X)=>({...A,order:X+1}));x(R),C===c&&l(((V=R[0])==null?void 0:V.id)||null)},[r,x,C]),f=t.useCallback(c=>{const M=r.filter(R=>R.id!==c).reduce((R,V)=>R+V.duration,0);return Math.max(a,n-M)},[r,n,a]),v=t.useCallback(c=>{const M=f(c),R=[],V=.1;for(let A=a;A<=M+.001;A+=V){const X=parseFloat(A.toFixed(1));X<=M&&R.push({label:`${X}`,value:X})}return R},[a,f]),u=t.useCallback((c,M)=>{const R=typeof M=="string"?parseFloat(M):M;if(isNaN(R))return;const V=f(c),A=r.map(X=>{if(X.id===c){const K=Math.max(a,Math.min(R,V)),le=parseFloat(K.toFixed(1));return le===X.duration?X:{...X,duration:le}}return X});A.every((X,K)=>X===r[K])||x(A)},[r,a,f,x]),D=t.useCallback((c,M)=>{const R=r.find(A=>A.id===c);if((R==null?void 0:R.prompt)===M)return;const V=r.map(A=>A.id===c?{...A,prompt:M}:A);x(V)},[r,x]),N=t.useCallback(c=>{if(s(c),c&&r.length===0){const M=is(1,n);x([M]),l(M.id)}},[r,n,s,x]),j=t.useCallback(c=>{l(c)},[]),W=r.length<i;return e.jsxs("div",{className:"storyboard-editor",children:[e.jsxs("div",{className:"storyboard-editor__header",children:[e.jsxs("div",{className:"storyboard-editor__toggle",children:[e.jsx(xa,{value:o,onChange:N,disabled:y,size:"small"}),e.jsxs("div",{className:"storyboard-editor__title",children:[e.jsx("span",{className:"storyboard-editor__title-text",children:"故事场景模式"}),e.jsx("span",{className:"storyboard-editor__title-desc",children:"定义多个场景及其时长"})]})]}),o&&e.jsx("span",{className:"storyboard-editor__new-badge",children:"NEW"})]}),o&&e.jsxs("div",{className:"storyboard-editor__content",children:[e.jsxs("div",{className:"storyboard-editor__section-header",children:[e.jsx("span",{className:"storyboard-editor__section-title",children:"场景列表"}),e.jsxs("span",{className:"storyboard-editor__section-hint",children:["共 ",r.length," 个场景,已用 ",r.reduce((c,M)=>c+M.duration,0).toFixed(1)," 秒 / 总时长 ",n," 秒"]})]}),e.jsxs("div",{className:"storyboard-editor__scenes",children:[r.map((c,M)=>{const R=C===c.id,V=M===r.length-1;return e.jsxs("div",{className:`storyboard-editor__scene-wrapper ${R?"is-selected":""}`,children:[e.jsx("div",{className:`storyboard-editor__timeline-line ${V?"is-last":""}`}),e.jsx("div",{className:`storyboard-editor__timeline-node ${R?"is-selected":""}`,children:R?M+1:""}),!R&&e.jsxs("div",{className:"storyboard-editor__scene storyboard-editor__scene--compact",onClick:()=>j(c.id),children:[e.jsx("span",{className:"storyboard-editor__scene-index",children:M+1}),e.jsx("div",{className:"storyboard-editor__scene-preview",children:e.jsx("p",{className:"storyboard-editor__scene-preview-text",children:c.prompt||"暂无场景描述..."})}),e.jsxs("div",{className:"storyboard-editor__scene-duration-badge",children:[e.jsx(Ut,{size:"12px"}),e.jsxs("span",{children:[c.duration,"s"]})]}),e.jsx(ws,{className:"storyboard-editor__scene-arrow",size:"14px"})]}),R&&e.jsxs("div",{className:"storyboard-editor__scene storyboard-editor__scene--expanded",children:[e.jsxs("div",{className:"storyboard-editor__scene-header",children:[e.jsx("div",{className:"storyboard-editor__scene-info",children:e.jsxs("span",{className:"storyboard-editor__scene-label",children:[e.jsx("span",{className:"storyboard-editor__active-indicator"}),"场景 ",M+1]})}),e.jsxs("div",{className:"storyboard-editor__scene-controls",children:[e.jsx(Ut,{className:"storyboard-editor__time-icon"}),e.jsx(ba,{value:parseFloat(c.duration.toFixed(1)),onChange:A=>u(c.id,A),disabled:y,className:"storyboard-editor__duration-select",size:"small",options:v(c.id),filterable:!0,creatable:!0,popupProps:{overlayClassName:"storyboard-editor__duration-popup"}}),r.length>1&&e.jsx(ut,{theme:"default",variant:"text",size:"small",icon:e.jsx(ys,{}),onClick:A=>{A.stopPropagation(),g(c.id)},disabled:y,className:"storyboard-editor__scene-delete"})]})]}),e.jsx("div",{className:"storyboard-editor__scene-prompt",children:e.jsx(xo,{value:c.prompt,onChange:A=>D(c.id,A),placeholder:`描述场景 ${M+1} 的内容,输入 @ 可引用角色`,disabled:y,autoFocus:!0,enableMention:!0})})]})]},c.id)}),e.jsx("div",{ref:p})]}),W&&e.jsx(ut,{theme:"default",variant:"dashed",size:"medium",icon:e.jsx(va,{}),onClick:k,disabled:y,className:"storyboard-editor__add-btn",block:!0,children:"添加场景"})]})]})},Us="aitu-dialog-task-list-width-",Dt=240,Rt=800,vo=()=>{const o=Math.round(660);return Math.max(Dt,Math.min(Rt,o))},Gs=o=>{try{const s=localStorage.getItem(Us+o);if(s){const n=parseInt(s,10);if(!isNaN(n)&&n>=Dt&&n<=Rt)return n}}catch{}return vo()},ls=(o,s)=>{try{localStorage.setItem(Us+o,s.toString())}catch{}},Ws=({isRightPanelVisible:o,onToggleRightPanel:s,onWidthChange:n,rightPanelWidth:i,minWidth:a=Dt,maxWidth:r=Rt,onResizeStart:x,onResizeEnd:y,language:C="zh",disabled:l=!1,storageKey:p="image"})=>{const[T,k]=t.useState(!1),g=t.useRef(0),f=t.useRef(0);t.useEffect(()=>(T?(document.body.style.userSelect="none",document.body.style.cursor="col-resize"):(document.body.style.userSelect="",document.body.style.cursor=""),()=>{document.body.style.userSelect="",document.body.style.cursor=""}),[T]);const v=t.useCallback(D=>{if(l||!o)return;D.preventDefault(),D.stopPropagation(),k(!0),g.current=D.clientX,f.current=i,x==null||x();const N=W=>{const c=g.current-W.clientX,M=Math.max(a,Math.min(r,f.current+c));n(M)},j=()=>{k(!1),y==null||y(),f.current+(g.current-document.body.getBoundingClientRect().left),ls(p,i),document.removeEventListener("mousemove",N),document.removeEventListener("mouseup",j)};document.addEventListener("mousemove",N),document.addEventListener("mouseup",j)},[l,o,i,a,r,n,x,y,p]);t.useEffect(()=>{!T&&o&&ls(p,i)},[i,T,o,p]);const u=o?C==="zh"?"隐藏任务列表":"Hide Task List":C==="zh"?"显示任务列表":"Show Task List";return e.jsxs("div",{className:`resizable-divider ${T?"is-dragging":""} ${o?"":"is-collapsed"} ${l?"is-disabled":""}`,onMouseDown:v,children:[e.jsx("div",{className:"resizable-divider__bar"}),e.jsx(Fe,{content:u,placement:"left",children:e.jsx("button",{type:"button",className:"resizable-divider__toggle",onClick:D=>{D.stopPropagation(),s()},"aria-label":u,children:o?e.jsx(ws,{size:"14px"}):e.jsx(wa,{size:"14px"})})})]})},Bs=({storageKey:o,language:s})=>{const[n,i]=t.useState(()=>{try{return localStorage.getItem(o)!=="false"}catch{return!0}}),a=t.useCallback(r=>{i(r);try{localStorage.setItem(o,String(r))}catch{}},[o]);return e.jsx(Fe,{content:s==="zh"?"生成后自动插入画布":"Auto insert to canvas after generation",theme:"light",children:e.jsx(ya,{checked:n,onChange:a,className:"auto-insert-checkbox"})})};function Et(o){try{return localStorage.getItem(o)!=="false"}catch{return!0}}function wo(o={}){const{taskType:s}=o,{tasks:n,isLoading:i}=Ia(),{retryTask:a,deleteTask:r}=Sa(),x=t.useMemo(()=>[...s?n.filter(p=>p.type===s):n].sort((p,T)=>T.createdAt-p.createdAt),[n,s]),y=t.useCallback(async()=>{},[]),C=t.useCallback(async()=>{if(_a(),!await Gt.isAvailable())return;const p=await Gt.getAllTasks();p.length>0&&ja.restoreTasks(p)},[]);return{tasks:x,isLoading:i,isLoadingMore:!1,hasMore:!1,totalCount:x.length,loadedCount:x.length,loadMore:y,refresh:C,retryTask:a,deleteTask:r}}const Ks=({taskIds:o,taskType:s,onEditTask:n})=>{const{tasks:i,isLoading:a,isLoadingMore:r,hasMore:x,totalCount:y,loadedCount:C,loadMore:l,retryTask:p,deleteTask:T}=wo({taskType:s}),{board:k,openDialog:g}=ft(),[f,v]=t.useState(!1),[u,D]=t.useState(null),[N,j]=t.useState(!1),[W,c]=t.useState(0),[M,R]=t.useState("single"),[V,A]=t.useState(""),[X,K]=t.useState(null),[le,G]=t.useState(!1),ge=t.useMemo(()=>i.filter(d=>d.status===Ve.FAILED).length,[i]),J=t.useCallback(()=>{const d=i.filter(m=>m.status===Ve.FAILED);d.forEach(m=>T(m.id)),G(!1),Ne.success(`已清除 ${d.length} 个失败任务`)},[i,T]),ye=(d,m)=>{var me,z,_e,pe,Ee,ce,fe,ue,re,we,Te;if(!m.trim())return!0;const P=m.toLowerCase().split(/\s+/).filter(Boolean),S={[Ve.PENDING]:"处理中",[Ve.PROCESSING]:"处理中",[Ve.COMPLETED]:"已完成",[Ve.FAILED]:"失败",[Ve.CANCELLED]:"已取消"},$=[],U=(me=d.params)!=null&&me.params&&typeof d.params.params=="object"?d.params.params:null;$.push(((z=d.params)==null?void 0:z.prompt)??""),$.push(((_e=d.params)==null?void 0:_e.model)??""),$.push(d.id??""),$.push(S[d.status]??String(d.status)),(pe=d.params)!=null&&pe.batchId&&$.push(String(d.params.batchId)),(Ee=d.params)!=null&&Ee.batchIndex&&$.push(String(d.params.batchIndex)),(ce=d.params)!=null&&ce.batchTotal&&$.push(String(d.params.batchTotal)),typeof(U==null?void 0:U.model_name)=="string"&&$.push(U.model_name),typeof(U==null?void 0:U.mode)=="string"&&$.push(U.mode),typeof(U==null?void 0:U.klingAction2)=="string"&&$.push(U.klingAction2),(fe=d.result)!=null&&fe.format&&$.push(String(d.result.format)),(ue=d.result)!=null&&ue.width&&((re=d.result)!=null&&re.height)?$.push(`${d.result.width}x${d.result.height}`):(we=d.params)!=null&&we.width&&((Te=d.params)!=null&&Te.height)&&$.push(`${d.params.width}x${d.params.height}`);const B=$.join(" ").toLowerCase();return P.every(Me=>B.includes(Me))},O=t.useMemo(()=>{let d=i;return o&&o.length>0&&(d=d.filter(m=>o.includes(m.id))),V.trim()&&(d=d.filter(m=>ye(m,V))),d.sort((m,P)=>P.createdAt-m.createdAt)},[i,o,V]),L=d=>{p(d)},E=d=>{D(d),v(!0)},Q=()=>{u&&T(u),v(!1),D(null)},oe=async d=>{const m=i.find(S=>S.id===d);if(!m)return;const P=Na(m);if(P.length!==0)try{const S=await Da(P);S.openedCount>0&&S.downloadedCount===0?Ne.success(S.openedCount>1?`已打开 ${S.openedCount} 个链接,请在新标签页下载`:"资源不支持直接下载,已打开链接"):Ne.success(m.type===ve.AUDIO?P.length>1?"多条音频已开始下载":"音频下载成功":P.length>1?"多图已开始下载":"下载成功")}catch(S){console.error("Download failed:",S),Ne.error("下载失败,请稍后重试")}},Se=async d=>{var P,S,$,U;const m=i.find(B=>B.id===d);if(!((P=m==null?void 0:m.result)!=null&&P.url)&&!(($=(S=m==null?void 0:m.result)==null?void 0:S.urls)!=null&&$.length)||!k){console.warn("Cannot insert: task result or board not available"),Ne.warning("无法插入:白板未就绪");return}try{if(m.type===ve.IMAGE){const B=(U=m.result.urls)!=null&&U.length?m.result.urls:[m.result.url];for(const me of B)await Ma(k,me);Ne.success(B.length>1?"多图已插入到白板":"图片已插入到白板")}else m.type===ve.VIDEO&&(await Pa(k,m.result.url),Ne.success("视频已插入到白板"))}catch(B){console.error("Failed to insert to board:",B),Ne.error(`插入失败: ${B instanceof Error?B.message:"未知错误"}`)}},ne=d=>{var P,S,$,U;const m=i.find(B=>B.id===d);if(!m){console.warn("Cannot edit: task not found");return}if(n){n(m);return}if(m.type===ve.IMAGE){const B={initialPrompt:m.params.prompt,initialWidth:m.params.width,initialHeight:m.params.height,initialImages:m.params.uploadedImages,initialResultUrl:(P=m.result)==null?void 0:P.url,initialResultUrls:(S=m.result)==null?void 0:S.urls};g(he.aiImageGeneration,B)}else if(m.type===ve.VIDEO){const B={initialPrompt:m.params.prompt,initialDuration:typeof m.params.seconds=="string"?parseInt(m.params.seconds,10):m.params.seconds,initialModel:m.params.model,initialSize:m.params.size,initialImages:m.params.uploadedImages,initialResultUrl:($=m.result)==null?void 0:$.url,initialResultUrls:(U=m.result)==null?void 0:U.urls};g(he.aiVideoGeneration,B)}},ae=d=>{const m=i.find(P=>P.id===d);m&&K(m)},xe=t.useMemo(()=>{const d=new Set;return O.filter(m=>{var P,S,$,U;return m.status!==Ve.COMPLETED||!((P=m.result)!=null&&P.url)&&!(($=(S=m.result)==null?void 0:S.urls)!=null&&$.length)||m.type!==ve.IMAGE&&m.type!==ve.VIDEO&&!(m.type===ve.AUDIO&&((U=m.result)==null?void 0:U.resultKind)!=="lyrics")||d.has(m.id)?!1:(d.add(m.id),!0)})},[O]),{previewMediaItems:Ce,taskIdToPreviewConfig:ie}=t.useMemo(()=>{var P,S,$,U,B,me;const d=[],m=new Map;for(const z of xe){const _e=d.length,pe=((P=z.result)==null?void 0:P.title)||z.params.title||((S=z.params.prompt)==null?void 0:S.substring(0,50))||"媒体预览";if(z.type===ve.AUDIO){const ce=((U=($=z.result)==null?void 0:$.clips)==null?void 0:U.filter(re=>!!re.audioUrl).map((re,we)=>{var Te,Me,Ue;return{id:re.clipId||re.id||`${z.id}-${we}`,url:re.audioUrl,type:"audio",title:re.title||((Te=z.result)!=null&&Te.clips&&z.result.clips.length>1?`${pe} (${we+1}/${z.result.clips.length})`:pe),posterUrl:re.imageLargeUrl||re.imageUrl||((Me=z.result)==null?void 0:Me.previewImageUrl),duration:typeof re.duration=="number"?re.duration:(Ue=z.result)==null?void 0:Ue.duration,prompt:z.params.prompt,tags:typeof z.params.tags=="string"?z.params.tags:void 0,artist:z.params.model||z.params.mv||"Aitu",album:"Aitu Generated"}}))??[],fe=(B=z.result.urls)!=null&&B.length?z.result.urls:z.result.url?[z.result.url]:[],ue=ce.length>0?ce:fe.map((re,we)=>{var Te,Me;return{id:fe.length>1?`${z.id}-${we}`:z.id,url:re,type:"audio",title:fe.length>1?`${pe} (${we+1}/${fe.length})`:pe,posterUrl:(Te=z.result)==null?void 0:Te.previewImageUrl,duration:(Me=z.result)==null?void 0:Me.duration,prompt:z.params.prompt,tags:typeof z.params.tags=="string"?z.params.tags:void 0,artist:z.params.model||z.params.mv||"Aitu",album:"Aitu Generated"}});d.push(...ue)}else{const ce=(me=z.result.urls)!=null&&me.length?z.result.urls:[z.result.url],fe=z.type===ve.VIDEO?"video":"image";for(let ue=0;ue<ce.length;ue++)d.push({id:ce.length>1?`${z.id}-${ue}`:z.id,url:fe==="image"?Ca(ce[ue]):ce[ue],type:fe,title:ce.length>1?`${pe} (${ue+1}/${ce.length})`:pe})}const Ee=d.length-_e;m.set(z.id,{mode:z.type===ve.AUDIO&&Ee>1?"compare":"single",index:z.type===ve.AUDIO&&Ee>1?Array.from({length:Math.min(Ee,4)},(ce,fe)=>_e+fe):_e})}return{previewMediaItems:d,taskIdToPreviewConfig:m}},[xe]),I=t.useCallback(d=>{const m=ie.get(d);m!==void 0&&(R(m.mode),c(m.index),j(!0))},[ie]),Z=t.useCallback(()=>{j(!1)},[]),be=V.trim()&&O.length===0&&i.length>0,ke=y>0?y:i.length;return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"dialog-task-list",children:[e.jsxs("div",{className:"dialog-task-list__header",children:[e.jsxs("div",{className:"dialog-task-list__header-main",children:[e.jsxs("h4",{children:["生成任务 (",ke,")"]}),e.jsx("div",{className:"dialog-task-list__header-actions",children:ge>0&&e.jsx(Fe,{content:`清除全部失败任务 (${ge})`,theme:"light",children:e.jsx(ut,{size:"small",variant:"text",icon:e.jsx(ys,{}),onClick:()=>G(!0)})})})]}),e.jsx("div",{className:"dialog-task-list__search",children:e.jsx(Ta,{value:V,onChange:d=>A(d),placeholder:"搜索任务(提示词/模型/...)",clearable:!0,prefixIcon:e.jsx(Ea,{}),size:"small"})})]}),e.jsx(eo,{tasks:O,onRetry:L,onDelete:E,onDownload:oe,onInsert:Se,onEdit:ne,onPreviewOpen:I,onExtractCharacter:ae,hasMore:x,isLoadingMore:r,onLoadMore:l,totalCount:ke,loadedCount:C,className:"dialog-task-list__content",emptyContent:e.jsx("div",{className:"dialog-task-list__empty",children:a?e.jsx("p",{children:"加载中..."}):be?e.jsx("p",{children:"未找到匹配的任务"}):e.jsx("p",{children:"暂无生成任务"})})})]}),e.jsx(Wt,{open:f,title:"确认删除",description:"确定要删除此任务吗?此操作无法撤销。",confirmText:"删除",cancelText:"取消",danger:!0,onOpenChange:v,onConfirm:Q}),e.jsx(Wt,{open:le,title:"清除失败任务",description:`确定要清除全部 ${ge} 个失败任务吗?此操作无法撤销。`,confirmText:"清除",cancelText:"取消",danger:!0,onOpenChange:G,onConfirm:J}),e.jsx(ka,{visible:N,items:Ce,initialMode:M,initialIndex:W,onClose:Z,showThumbnails:!0}),e.jsx(to,{visible:!!X,task:X,onClose:()=>K(null),onCreateComplete:d=>{K(null)}})]})},yo=({initialPrompt:o="",initialImages:s=[],selectedElementIds:n=[],initialWidth:i,initialHeight:a,initialResultUrl:r,initialAspectRatio:x,targetFrameId:y,targetFrameDimensions:C,selectedModel:l,selectedModelRef:p,onModelChange:T,onModelRefChange:k,externalBatchId:g,initialAutoInsertToCanvas:f,onDraftChange:v}={})=>{var De,at,ot;const u=Es("image"),D=qe("image"),N=Le(u,D.modelId,Ae(D.profileId,D.modelId))||mt("image",D.modelId,Ae(D.profileId,D.modelId)),[j,W]=t.useState((N==null?void 0:N.id)||((De=u[0])==null?void 0:De.id)||"gemini-2.5-flash-image-vip"),[c,M]=t.useState(Oe(N)||Ae(D.profileId,D.modelId)),R=Ie((N==null?void 0:N.id)||((at=u[0])==null?void 0:at.id)||"gemini-2.5-flash-image-vip",Oe(N)||Ae(D.profileId,D.modelId)),V=ss((N==null?void 0:N.id)||((ot=u[0])==null?void 0:ot.id)||"gemini-2.5-flash-image-vip",R),[A,X]=t.useState(o),[K,le]=t.useState(V.extraParams),G=t.useMemo(()=>{if(Le(u,j,c)||!j)return u;const F=mt("image",j,c);return F?[F,...u]:u},[j,c,u]),[ge,J]=t.useState(i||1024),[ye,O]=t.useState(a||1024),[L,E]=t.useState(x||V.aspectRatio||wt),[Q,oe]=t.useState(null),[Se,ne]=t.useState(s),[ae,xe]=t.useState(!0),[Ce,ie]=t.useState(()=>Gs("image")),[I,Z]=t.useState("config"),be=t.useRef(null),{viewportWidth:ke}=Pt(),d=ke<=768,{imageHistory:m}=Ds(),{isGenerating:P}=Ss("image"),{language:S}=Ye(),{createTask:$}=Mt(),U=t.useRef(!1),B=j.startsWith("mj"),me=de.useMemo(()=>{if(B)return[];const b=Ra(j);if(b.length===0)return dt;const F=new Map(dt.map(Y=>[Y.value,Y])),H=[];return b.forEach(Y=>{const je=Y.value==="auto"?"auto":Y.value.replace("x",":"),Pe=F.get(je);Pe&&!H.some(Re=>Re.value===Pe.value)&&H.push(Pe)}),H.length>0?H:dt},[j,B]),z=de.useMemo(()=>{const b=Oa(j);return B?b.length>0:b.some(F=>F.id!=="size")},[j,B]),[_e,pe]=t.useState(!1);t.useEffect(()=>{if(_e)return;const b=ss(j,Ie(j,c));le(b.extraParams),E(b.aspectRatio)},[j,c,_e]);const Ee=t.useCallback((b,F)=>{if(!F||F==="default"){le(H=>{const Y={...H};return delete Y[b],Y});return}le(H=>({...H,[b]:F}))},[]),ce=t.useCallback(b=>{ie(b)},[]),fe=t.useCallback(()=>{xe(b=>!b)},[]),ue=de.useRef("");t.useEffect(()=>{if(_e)return;const b=JSON.stringify({prompt:o,images:s==null?void 0:s.map(F=>F.url),elementIds:n,width:i,height:a,result:r,aspectRatio:x});ue.current!==b&&(ue.current=b,X(o),ne(s||[]),i&&J(i),a&&O(a),x&&E(x))},[o,s,n,i,a,r,x,_e]);const re=t.useRef("");t.useEffect(()=>{if(!v)return;const b={prompt:A,images:Se.map(Y=>({url:Y.url,name:Y.name})),aspectRatio:L},F=JSON.stringify(b);if(re.current===F)return;const H=window.setTimeout(()=>{re.current!==F&&(re.current=F,v(b))},200);return()=>{window.clearTimeout(H)}},[L,v,A,Se]),t.useEffect(()=>{const b=F=>{var Y;const H=F.imageModelName||((Y=G[0])==null?void 0:Y.id)||"gemini-2.5-flash-image-vip";if(H!==j){W(H);const je=Le(G,H,c);M(Oe(je)||null)}};return ze.addListener(b),()=>ze.removeListener(b)},[j,c,G]),t.useEffect(()=>{if(G.length===0)return;if(!Le(G,j,c)){const F=G[0];W(F.id);const H=Oe(F);M(Y=>Y&&H&&Y.profileId===H.profileId&&Y.modelId===H.modelId?Y:H)}},[j,c,G]),t.useEffect(()=>{if(!l)return;const b=Ie(j,c),F=Ie(l,p);if(b!==F){W(l);const H=Le(G,l,p),Y=Oe(H)||p||null;M(je=>je&&Y&&je.profileId===Y.profileId&&je.modelId===Y.modelId?je:Y)}},[j,c,l,p,G]),t.useEffect(()=>{!z&&Object.keys(K).length>0&&le({})},[z,K]),t.useEffect(()=>{var F;if(B||me.length===0)return;const b=new Set(me.map(H=>H.value));if(!b.has(L)){const H=b.has("auto")?"auto":((F=me[0])==null?void 0:F.value)||wt;E(H)}},[L,B,me]),t.useEffect(()=>{Xa({currentModel:j,currentSelectionKey:Ie(j,c),extraParams:K,aspectRatio:L})},[j,c,K,L]),t.useEffect(()=>(oe(null),()=>{oe(null)}),[]);const we=()=>{X(""),le({}),ne([]),oe(null),E(wt),Z("config"),pe(!1),window.dispatchEvent(new CustomEvent("ai-image-clear"))},Te=de.useMemo(()=>$s("image",S,m),[m,S]),Me=b=>{Vs("image",b)},Ue=b=>{if(pe(!0),Z("config"),X(b.params.prompt||""),le({}),J(b.params.width||1024),O(b.params.height||1024),b.params.uploadedImages&&b.params.uploadedImages.length>0?ne(b.params.uploadedImages):ne([]),b.params.model){W(b.params.model),M(b.params.modelRef||null);const F=ze.get();ze.update({...F,imageModelName:b.params.model})}b.params.aspectRatio&&E(b.params.aspectRatio),oe(null)},ht=async()=>Promise.all(Se.map(async b=>{if(b.file)return new Promise((F,H)=>{const Y=new FileReader;Y.onload=()=>{F({type:"url",url:Y.result,name:b.name})},Y.onerror=H,Y.readAsDataURL(b.file)});if(b.url)return{type:"url",url:b.url,name:b.name};throw new Error("Invalid image data")})),st=async(b=1)=>{if(!U.current){U.current=!0;try{if(!A||!A.trim()){oe(S==="zh"?"请输入图像描述":"Please enter image description");return}if(!Aa("image",c||j)&&!await za()){oe(S==="zh"?"需要 API Key 才能生成图片":"API Key is required to generate images");return}B&&oe(null);try{const F=typeof ge=="string"?parseInt(ge)||1024:ge,H=typeof ye=="string"?parseInt(ye)||1024:ye,Y=await ht();if(b>1){const Ge=[],xt=`batch_${Date.now()}`,Be=j||qe("image").modelId,rt=Be.startsWith("mj")?[A.trim(),as(K)].filter(Boolean).join(" "):(A||"").trim(),$e=!Be.startsWith("mj")&&Object.keys(K).length>0?K:void 0,bt=$e!=null&&$e.size?$e.size:Bt(L);for(let Je=0;Je<b;Je++){const Qe={prompt:rt,width:F,height:H,aspectRatio:L,size:bt,model:Be,modelRef:c||null,uploadedImages:Y,batchId:xt,batchIndex:Je+1,batchTotal:b,autoInsertToCanvas:f??Et(tt.AI_IMAGE_AUTO_INSERT),targetFrameId:y,targetFrameDimensions:C,...$e?{params:$e}:{}},it=$(Qe,ve.IMAGE);it&&Ge.push(it.id)}Ge.length>0?(Ne.success(S==="zh"?`已添加 ${Ge.length} 个任务到队列`:`Added ${Ge.length} tasks to queue`),Me(rt),oe(null),Z("tasks"),pe(!1)):oe(S==="zh"?"批量任务创建失败,请稍后重试":"Failed to create batch tasks, please try again later");return}const je=j||qe("image").modelId,Pe=je.startsWith("mj")?[A.trim(),as(K)].filter(Boolean).join(" "):(A||"").trim(),Re=!je.startsWith("mj")&&Object.keys(K).length>0?K:void 0,Xe=Re!=null&&Re.size?Re.size:Bt(L),nt={prompt:Pe,width:F,height:H,aspectRatio:L,size:Xe,model:je,modelRef:c||null,uploadedImages:Y,autoInsertToCanvas:f??Et(tt.AI_IMAGE_AUTO_INSERT),batchId:g||`image_single_${Date.now()}`,batchIndex:1,batchTotal:1,targetFrameId:y,targetFrameDimensions:C,...Re?{params:Re}:{}};$(nt,ve.IMAGE)?(Ne.success(S==="zh"?"任务已添加到队列,将在后台生成":"Task added to queue, will be generated in background"),Me(Pe),oe(null),Z("tasks"),pe(!1)):oe(S==="zh"?"任务创建失败,请检查参数或稍后重试":"Failed to create task, please check parameters or try again later")}catch(F){console.error("Failed to create task:",F);let H=S==="zh"?"任务创建失败,请检查参数或稍后重试":"Failed to create task, please check parameters or try again later";F.message&&(F.message.includes("exceed 5000 characters")?H=S==="zh"?"提示词不能超过 5000 字符":"Prompt must not exceed 5000 characters":F.message.includes("Duplicate submission")?H=S==="zh"?"请勿重复提交,请等待 5 秒后再试":"Duplicate submission. Please wait 5 seconds.":F.message.includes("Invalid parameters")&&(H=S==="zh"?`参数错误: ${F.message.replace("Invalid parameters: ","")}`:F.message)),oe(H)}}finally{U.current=!1}}};return _s(P,A,()=>st(1)),e.jsxs("div",{className:"ai-image-generation-container",children:[d?e.jsxs("div",{className:"ai-generation-mobile-switcher",role:"tablist",children:[e.jsx("button",{type:"button",className:`ai-generation-mobile-switcher__tab ${I==="config"?"ai-generation-mobile-switcher__tab--active":""}`,onClick:()=>Z("config"),children:"生成设置"}),e.jsx("button",{type:"button",className:`ai-generation-mobile-switcher__tab ${I==="tasks"?"ai-generation-mobile-switcher__tab--active":""}`,onClick:()=>Z("tasks"),children:"生成任务"})]}):null,e.jsxs("div",{className:`main-content ${d?"main-content--mobile-panels":""}`,ref:be,children:[e.jsxs("div",{className:`ai-image-generation-section ${d&&I!=="config"?"ai-generation-mobile-panel--hidden":""}`,children:[e.jsxs("div",{className:"ai-image-generation-form",children:[l!==void 0&&T&&e.jsx("div",{className:"form-header-row",children:e.jsx("div",{className:"model-selector-wrapper",children:e.jsx(Is,{selectedModel:j,selectedSelectionKey:Ie(j,c),onSelect:b=>{W(b),M(null),T(b),k==null||k(null)},onSelectModel:b=>{W(b.id);const F=Oe(b);M(F),T(b.id),k==null||k(F)},language:S,models:G,placement:"down",variant:"form",disabled:P})})}),z&&e.jsx("div",{className:"model-params-row",children:e.jsx(js,{selectedParams:K,onParamChange:Ee,modelId:j,language:S,disabled:P,excludeParamIds:B?void 0:["size"]})}),e.jsx(Ts,{images:Se,onImagesChange:ne,language:S,disabled:P,multiple:!0,label:S==="zh"?"参考图片 (可选)":"Reference Images (Optional)",onError:oe}),e.jsx(Ls,{prompt:A,onPromptChange:X,presetPrompts:Te,language:S,type:"image",disabled:P,onError:oe}),e.jsx(Os,{error:Q})]}),e.jsx(Rs,{language:S,type:"image",isGenerating:P,hasGenerated:!1,canGenerate:!!(A&&A.trim()),onGenerate:st,onReset:we,leftContent:e.jsxs(e.Fragment,{children:[e.jsx(Bs,{storageKey:tt.AI_IMAGE_AUTO_INSERT,language:S}),!B&&e.jsx(po,{value:L,onChange:E,compact:!0,options:me})]})})]}),d?null:e.jsx(Ws,{isRightPanelVisible:ae,onToggleRightPanel:fe,onWidthChange:ce,rightPanelWidth:Ce,language:S,storageKey:"image"}),(d||ae)&&e.jsx("div",{className:`task-sidebar ${d?"task-sidebar--mobile-panel":""} ${d&&I!=="tasks"?"ai-generation-mobile-panel--hidden":""}`,style:d?void 0:{width:Ce,flexShrink:0},children:e.jsx(Ks,{taskType:ve.IMAGE,onEditTask:Ue})})]})]})};function cs(o,s){const n=Object.keys(o),i=Object.keys(s);return n.length!==i.length?!1:n.every(a=>o[a]===s[a])}function ds(o,s,n){return o.slice(0,s).map((i,a)=>({...i,slot:a,slotLabel:n[a]||`参考图${a+1}`}))}function Io(o,s){return o.length===s.length&&o.every((n,i)=>{const a=s[i];return n.slot===a.slot&&n.slotLabel===a.slotLabel&&n.url===a.url&&n.name===a.name&&n.file===a.file})}function us(o,s){return s.some(n=>n.value===o)}function ms(o){const s=o==null?void 0:o.trim().replace(/[xX]/g,":");return s&&/^\d+:\d+$/.test(s)?s:null}function ct(o){var n;const s=(n=o==null?void 0:o.split("@")[0])==null?void 0:n.trim();return s&&/^\d+p$/.test(s)?s:null}function Ct(o,s){return((o==null?void 0:o.profileId)||null)===((s==null?void 0:s.profileId)||null)&&((o==null?void 0:o.modelId)||null)===((s==null?void 0:s.modelId)||null)}function Hs(o,s){const n=Ae(s==null?void 0:s.profileId,s==null?void 0:s.modelId);return(n==null?void 0:n.modelId)===(o||null)?n:null}function We(o,s,n){if(!s)return null;const i=Hs(s,n),a=Le(o,s,i);return Oe(a)||i}const So=({initialPrompt:o="",initialImage:s,initialImages:n,initialDuration:i,initialModel:a,initialSize:r,initialResultUrl:x,selectedModel:y,selectedModelRef:C,onModelChange:l,onModelRefChange:p,externalBatchId:T,initialAutoInsertToCanvas:k,onDraftChange:g}={})=>{var At,zt,Lt;const f=Es("video"),[v,u]=t.useState(o),[D,N]=t.useState(null),[j,W]=t.useState(!0),[c,M]=t.useState(()=>Gs("video")),[R,V]=t.useState("config"),A=t.useRef(null),{viewportWidth:X}=Pt(),K=X<=768,le=qe("video"),G=a||le.modelId,ge=Hs(G,a&&a===y?C:le.modelId===G?Ae(le.profileId,le.modelId):null),J=Le(f,G,ge)||mt("video",G,ge),ye=We(f,(J==null?void 0:J.id)||G,Oe(J)||ge),[O,L]=t.useState((J==null?void 0:J.id)||((At=f[0])==null?void 0:At.id)||yt("veo3")),[E,Q]=t.useState(ye),oe=Ie((J==null?void 0:J.id)||((zt=f[0])==null?void 0:zt.id)||yt("veo3"),ye),Se=os((J==null?void 0:J.id)||((Lt=f[0])==null?void 0:Lt.id)||yt("veo3"),oe),ne=de.useMemo(()=>{if(Le(f,O,E)||!O)return f;const w=mt("video",O,E);return w?[w,...f]:f},[O,E,f]),[ae,xe]=t.useState(()=>Se.extraParams),Ce=de.useMemo(()=>La(O,E||O,ae),[O,E,ae]),ie=de.useMemo(()=>It(O,E||O,ae),[O,E,ae]),I=de.useMemo(()=>{if(ie.provider!=="seedance")return ie;const h=ms(ae.aspect_ratio)||ms(ae.aspectRatio)||"16:9",w=new Set,_=ie.sizeOptions.map(te=>ct(te.value)).filter(te=>!te||w.has(te)?!1:(w.add(te),!0)),q=_.map(te=>({label:te,value:`${te}@${h}`,aspectRatio:h})),ee=ct(ie.defaultSize)||_[0]||"720p";return{...ie,sizeOptions:q,defaultSize:`${ee}@${h}`}},[ie,ae.aspectRatio,ae.aspect_ratio]),Z=de.useMemo(()=>$a(O,E||O,ae),[O,E,ae]),be=de.useMemo(()=>(ie.imageUpload.labels||[]).join("|"),[ie.imageUpload.labels]),ke=de.useMemo(()=>be?be.split("|"):[],[be]),d=de.useMemo(()=>({maxCount:ie.imageUpload.maxCount,mode:ie.imageUpload.mode,labels:ke,labelsSignature:be}),[ie.imageUpload.maxCount,ie.imageUpload.mode,ke,be]),[m,P]=t.useState((i==null?void 0:i.toString())||Se.duration),[S,$]=t.useState(r||Se.size),U=de.useMemo(()=>us(m,I.durationOptions)?m:I.defaultDuration,[m,I.defaultDuration,I.durationOptions]),B=de.useMemo(()=>{if(us(S,I.sizeOptions))return S;if(I.provider==="seedance"){const h=ct(S),w=I.sizeOptions.find(_=>ct(_.value)===h);if(w)return w.value}return I.defaultSize},[S,I]),me=de.useMemo(()=>Ce.some(h=>h.id!=="size"&&h.id!=="duration"),[Ce]),z=t.useCallback((h,w)=>{if(!w||w==="default"){xe(_=>{const q={..._};return delete q[h],q});return}xe(_=>({..._,[h]:w}))},[]);t.useEffect(()=>{const h=Ce.reduce((w,_)=>{const q=ae[_.id],ee=!q||_.valueType!=="enum"||!_.options||_.options.some(te=>te.value===q);return q&&ee?w[_.id]=q:_.defaultValue&&(w[_.id]=_.defaultValue),w},{});cs(ae,h)||xe(h)},[Ce,ae]);const[_e,pe]=t.useState(()=>n&&n.length>0?n:s?[{slot:0,slotLabel:"参考图",url:s.url||"",name:s.name,file:s.file}]:[]),[Ee,ce]=t.useState(()=>{const h=ie.imageUpload.maxCount,w=ie.imageUpload.labels||[];let _=[];return n&&n.length>0?_=n:s&&(_=[{slot:0,slotLabel:w[0]||"参考图",url:s.url||"",name:s.name,file:s.file}]),_.slice(0,h).map((q,ee)=>({...q,slot:ee,slotLabel:w[ee]||`参考图${ee+1}`}))}),[fe,ue]=t.useState(!1),[re,we]=t.useState([]),Te=de.useMemo(()=>Va(O),[O]),Me=Kt(O),{videoHistory:Ue}=Ds(),[ht,st]=t.useState(0),{isGenerating:De}=Ss("video"),at=t.useCallback(h=>{M(h)},[]),ot=t.useCallback(()=>{W(h=>!h)},[]),{language:b}=Ye(),{createTask:F}=Mt(),H=t.useRef(!1),Y=y!==void 0,je=de.useRef(null),Pe=de.useRef(null);t.useEffect(()=>{if(Y)return;const h=w=>{const _=w.videoModelName||"veo3";if(_!==O){L(_);const q=We(ne,_,E);Q(q)}};return ze.addListener(h),()=>ze.removeListener(h)},[O,E,Y,y,C,ne]),t.useEffect(()=>{if(ne.length===0)return;const h=Le(ne,O,E),w=We(ne,O,E);if(!h){const _=ne[0],q=Oe(_);L(_.id),Q(ee=>Ct(ee,q)?ee:q);return}Q(_=>Ct(_,w)?_:w)},[O,E,ne]),t.useEffect(()=>{if(!y)return;const h=Ie(y,C);if(je.current===h||Pe.current&&Pe.current!==y)return;je.current=h,L(_=>_===y?_:y);const w=We(ne,y,C);Q(_=>Ct(_,w)?_:w)},[y,C,ne,a]);const[Re,Xe]=t.useState(!1),[nt,gt]=t.useState(!1);t.useEffect(()=>{if(nt){gt(!1);return}const h=os(O,Ie(O,E)),w=It(O,E||O,h.extraParams),_=w.durationOptions.some(se=>se.value===h.duration)?h.duration:w.defaultDuration,q=w.sizeOptions.some(se=>se.value===h.size)?h.size:w.defaultSize;xe(se=>cs(se,h.extraParams)?se:h.extraParams);const ee=i!==void 0?i.toString():_,te=r||q;P(se=>se===ee?se:ee),$(se=>se===te?se:te),Kt(O)||(ue(se=>se&&!1),we(se=>se.length>0?[]:se))},[O,E,nt,i,r]),t.useEffect(()=>{const h=_e.length>0?ds(_e,d.maxCount,d.labels):[];ce(w=>Io(w,h)?w:h)},[_e,d.labels,d.labelsSignature,d.maxCount]),t.useEffect(()=>{Ja({currentModel:O,currentSelectionKey:Ie(O,E),extraParams:ae,duration:U,size:B})},[O,E,U,B,ae]);const Ge=de.useRef("");t.useEffect(()=>{if(Re)return;const h=JSON.stringify({prompt:o,image:s==null?void 0:s.url,images:n==null?void 0:n.map(q=>q.url),duration:i,model:a,size:r,result:x});if(Ge.current===h)return;Ge.current=h,a&&(Pe.current=a,L(a),Q(We(f,a,C))),u(o);let w=[];n&&n.length>0?w=n:s&&(w=[{slot:0,slotLabel:"参考图",url:s.url||"",name:s.name,file:s.file}]),pe(w);const _=ds(w,d.maxCount,d.labels);ce(_),i!==void 0&&P(i.toString()),r&&$(r),N(null)},[o,s,n,i,r,x,d.labels,d.labelsSignature,d.maxCount,Re]),t.useEffect(()=>(N(null),()=>{N(null)}),[]);const xt=()=>{u(""),pe([]),ce([]),N(null),V("config"),P(Z.duration),$(Z.size),Xe(!1),ue(!1),we([]),xe(St(O,E||O)),window.dispatchEvent(new CustomEvent("ai-video-clear"))},Be=de.useCallback((h,w)=>h.map((_,q)=>({slot:q,slotLabel:w[q]||`参考图${q+1}`,url:_.url,name:_.name,file:_.file})),[]),rt=de.useCallback(h=>h.map(w=>({url:w.url,name:w.name,file:w.file})),[]),$e=de.useCallback(h=>{const w=Be(h,d.labels);ce(w),pe(w)},[d.labels,Be]),bt=de.useMemo(()=>$s("video",b,Ue),[Ue,b,ht]),Je=h=>{Vs("video",h),st(w=>w+1)},Qe=t.useRef("");t.useEffect(()=>{if(!g)return;const h=Number.parseFloat(U),w={prompt:v,images:Ee.map(ee=>({url:ee.url,name:ee.name})),duration:Number.isFinite(h)?h:void 0,size:B||void 0},_=JSON.stringify(w);if(Qe.current===_)return;const q=window.setTimeout(()=>{Qe.current!==_&&(Qe.current=_,g(w))},200);return()=>{window.clearTimeout(q)}},[U,B,g,v,Ee]);const it=h=>{var _,q;if(Xe(!0),V("config"),gt(!0),h.params.model){L(h.params.model),Q(h.params.modelRef||null);const ee=ze.get();ze.update({...ee,videoModelName:h.params.model})}if((_=h.params.storyboard)!=null&&_.enabled&&((q=h.params.storyboard)!=null&&q.scenes))ue(!0),we(h.params.storyboard.scenes),u("");else{const ee=h.params.prompt||"",te=go(ee);te&&te.length>0?(ue(!0),we(te),u("")):(ue(!1),we([]),u(ee))}if(h.params.seconds!==void 0){const ee=typeof h.params.seconds=="string"?h.params.seconds:h.params.seconds.toString();P(ee)}const w=h.params.params&&typeof h.params.params=="object"?Object.entries(h.params.params).reduce((ee,[te,se])=>(se!=null&&String(se).trim()&&(ee[te]=String(se)),ee),{}):{};if(xe(w),h.params.size&&$(h.params.size),h.params.uploadedImages&&h.params.uploadedImages.length>0){pe(h.params.uploadedImages);const ee=h.params.model||O,te=It(ee,h.params.modelRef||ee,w),se=te.imageUpload.maxCount,Ze=te.imageUpload.labels||[],Ke=h.params.uploadedImages.slice(0,se).map((He,vt)=>({...He,slot:vt,slotLabel:Ze[vt]||`参考图${vt+1}`}));ce(Ke)}else pe([]),ce([]);N(null)},Ot=async(h=1)=>{if(!H.current){H.current=!0;try{if(fe){const w=fo(re,parseFloat(U),Te.minSceneDuration);if(!w.valid){N(w.error||"场景配置无效");return}}else if(!v||!v.trim()){N(b==="zh"?"请输入视频描述":"Please enter video description");return}try{const w=[];for(const te of Ee)if(te.file){const se=await new Promise((Ze,Ke)=>{const He=new FileReader;He.onload=()=>Ze(He.result),He.onerror=Ke,He.readAsDataURL(te.file)});w.push({...te,url:se,file:void 0})}else w.push({...te,file:void 0});const _=fe?ho(re):(v||"").trim(),q=[],ee=T||`video_batch_${Date.now()}`;for(let te=0;te<h;te++){const se=Object.keys(ae).length>0?ae:void 0,Ze={prompt:_,model:O,modelRef:E||null,seconds:U,size:B,uploadedImages:w,...fe&&{storyboard:{enabled:!0,scenes:re,totalDuration:parseFloat(U)}},batchId:ee,batchIndex:te+1,batchTotal:h,autoInsertToCanvas:k??Et(tt.AI_VIDEO_AUTO_INSERT),...se?{params:se}:{}},Ke=F(Ze,ve.VIDEO);Ke&&q.push(Ke.id)}q.length>0?(Ne.success(b==="zh"?h>1?`${q.length} 个视频任务已添加到队列,将在后台生成`:"视频任务已添加到队列,将在后台生成":h>1?`${q.length} video tasks added to queue, will be generated in background`:"Video task added to queue, will be generated in background"),Je(_),u(""),pe([]),ce([]),ue(!1),we([]),N(null),V("tasks"),Xe(!1)):N(b==="zh"?"任务创建失败,请检查参数或稍后重试":"Failed to create task, please check parameters or try again later")}catch(w){console.error("Failed to create task:",w);let _=b==="zh"?"任务创建失败,请检查参数或稍后重试":"Failed to create task, please check parameters or try again later";w.message&&(w.message.includes("exceed 5000 characters")?_=b==="zh"?"提示词不能超过 5000 字符":"Prompt must not exceed 5000 characters":w.message.includes("Duplicate submission")?_=b==="zh"?"请勿重复提交,请等待 5 秒后再试":"Duplicate submission. Please wait 5 seconds.":w.message.includes("Invalid parameters")&&(_=b==="zh"?`参数错误: ${w.message.replace("Invalid parameters: ","")}`:w.message)),N(_)}}finally{H.current=!1}}};return _s(De,v,Ot),e.jsxs("div",{className:"ai-video-generation-container",children:[K?e.jsxs("div",{className:"ai-generation-mobile-switcher",role:"tablist",children:[e.jsx("button",{type:"button",className:`ai-generation-mobile-switcher__tab ${R==="config"?"ai-generation-mobile-switcher__tab--active":""}`,onClick:()=>V("config"),children:"生成设置"}),e.jsx("button",{type:"button",className:`ai-generation-mobile-switcher__tab ${R==="tasks"?"ai-generation-mobile-switcher__tab--active":""}`,onClick:()=>V("tasks"),children:"生成任务"})]}):null,e.jsxs("div",{className:`main-content ${K?"main-content--mobile-panels":""}`,ref:A,children:[e.jsxs("div",{className:`ai-image-generation-section ${K&&R!=="config"?"ai-generation-mobile-panel--hidden":""}`,children:[e.jsxs("div",{className:"ai-image-generation-form",children:[y!==void 0&&l&&e.jsx("div",{className:"form-header-row",children:e.jsx("div",{className:"model-selector-wrapper",children:e.jsx(Is,{selectedModel:O,selectedSelectionKey:Ie(O,E),onSelect:(h,w)=>{const _=h,q=We(ne,_,w||null);Pe.current=null,L(_),Q(q),xe(St(_,q||_)),l(h),p==null||p(q)},onSelectModel:h=>{const w=h.id;Pe.current=null,L(w);const _=We(ne,w,Oe(h));Q(_),xe(St(w,_||w)),l(h.id),p==null||p(_)},language:b,models:ne,placement:"down",variant:"form",placeholder:b==="zh"?"选择视频模型":"Select Video Model",disabled:De})})}),me&&e.jsx("div",{className:"model-params-row",children:e.jsx(js,{selectedParams:ae,onParamChange:z,compatibleParams:Ce,modelId:O,language:b,disabled:De,excludeParamIds:["size","duration"]})}),e.jsx(mo,{model:O,configOverride:I,duration:U,size:B,onDurationChange:P,onSizeChange:$,disabled:De}),e.jsx(Ts,{images:rt(Ee),onImagesChange:$e,language:b,disabled:De,multiple:d.maxCount>1,maxCount:d.maxCount,slotLabels:d.mode==="frames"?d.labels:void 0,label:d.mode==="frames"?b==="zh"?"首尾帧图片 (可选)":"Start/End Frames (Optional)":b==="zh"?"参考图片 (可选)":"Reference Images (Optional)"}),Me&&e.jsx(bo,{enabled:fe,onEnabledChange:ue,totalDuration:parseFloat(U),maxScenes:Te.maxScenes,minSceneDuration:Te.minSceneDuration,scenes:re,onScenesChange:we,disabled:De}),!fe&&e.jsx(Ls,{prompt:v,onPromptChange:u,presetPrompts:bt,language:b,type:"video",disabled:De,onError:N,videoProvider:ie.provider}),e.jsx(Os,{error:D})]}),e.jsx(Rs,{language:b,type:"video",isGenerating:De,hasGenerated:!1,canGenerate:fe?re.length>0:!!(v&&v.trim()),onGenerate:Ot,onReset:xt,leftContent:e.jsx(Bs,{storageKey:tt.AI_VIDEO_AUTO_INSERT,language:b})})]}),K?null:e.jsx(Ws,{isRightPanelVisible:j,onToggleRightPanel:ot,onWidthChange:at,rightPanelWidth:c,language:b,storageKey:"video"}),(K||j)&&e.jsx("div",{className:`task-sidebar ${K?"task-sidebar--mobile-panel":""} ${K&&R!=="tasks"?"ai-generation-mobile-panel--hidden":""}`,style:K?void 0:{width:c,flexShrink:0},children:e.jsx(Ks,{taskType:ve.VIDEO,onEditTask:it})})]})]})},_o=t.lazy(()=>kt(()=>import("./batch-image-generation-RKz5tz-Y.js"),__vite__mapDeps([0,1,2,3]),import.meta.url)),jo=({container:o})=>{const{appState:s,openDialog:n,closeDialog:i}=ft(),{language:a}=Ye(),r=Nt(),{isMobile:x,isTablet:y}=Pt(),C=s.dialogInitialDataByType,l=(C==null?void 0:C[he.aiImageGeneration])??null,p=(C==null?void 0:C[he.aiVideoGeneration])??null,T=!x&&!y,k=t.useRef(!1),g=t.useRef(null),[f,v]=t.useState(""),[u,D]=t.useState(null),[N,j]=t.useState(""),[W,c]=t.useState(null),M=t.useRef(null),R=t.useRef(null),V=t.useCallback(()=>{const I=qe("image"),Z=qe("video"),be=I.modelId||"gemini-3-pro-image-preview-vip",ke=Ae(I.profileId,be),d=Z.modelId||"veo3",m=Ae(Z.profileId,d);v(P=>P===be?P:be),D(P=>Ie(be,P)===Ie(be,ke)?P:ke),j(P=>P===d?P:d),c(P=>Ie(d,P)===Ie(d,m)?P:m)},[]);t.useEffect(()=>{V()},[V]),t.useEffect(()=>{const I=()=>{V()};return ze.addListener(I),Ht.addListener(I),()=>{ze.removeListener(I),Ht.removeListener(I)}},[V]);const A=I=>{v(I)},X=I=>{j(I)},K=I=>{D(I)},le=I=>{c(I)};t.useEffect(()=>{if(!f)return;const I=Ie(f,u);M.current!==I&&(M.current=I,qt("image",Ae(u==null?void 0:u.profileId,f)))},[f,u]),t.useEffect(()=>{if(!N)return;const I=Ie(N,W);R.current!==I&&(R.current=I,qt("video",Ae(W==null?void 0:W.profileId,N)))},[N,W]);const[G,ge]=t.useState({initialPrompt:"",initialImages:[],selectedElementIds:[]}),[J,ye]=t.useState({initialPrompt:"",initialImage:void 0}),[O,L]=t.useState(!1),[E,Q]=t.useState(()=>{try{return localStorage.getItem(_t)==="batch"?"batch":"single"}catch{return"single"}});t.useEffect(()=>{!T&&E==="batch"&&Q("single")},[T,E]);const oe=t.useCallback(I=>{Q(I),I==="batch"&&(L(!0),setTimeout(()=>L(!1),50));try{localStorage.setItem(_t,I)}catch(Z){console.warn("Failed to save image mode:",Z)}},[]);t.useEffect(()=>{if(s.openDialogTypes.has(he.aiImageGeneration)){if(G.initialImages&&G.initialImages.length>0||G.initialPrompt&&G.initialPrompt.trim()!==""){L(!1);return}try{localStorage.getItem(_t)==="batch"&&(L(!0),setTimeout(()=>L(!1),50))}catch{L(!1)}}},[s.openDialogTypes,G.initialImages,G.initialPrompt]);const Se=t.useRef(!1),ne=t.useRef(l),ae=t.useRef(!1),xe=t.useRef(p);t.useEffect(()=>{if(!r)return;const I=s.openDialogTypes.has(he.aiImageGeneration),Z=I&&!Se.current,be=ne.current!==l;if(Se.current=I,ne.current=l,!I||!Z&&!be||k.current)return;(async()=>{k.current=!0,g.current&&clearTimeout(g.current),g.current=setTimeout(()=>{console.warn("Processing timeout, resetting processing state"),k.current=!1},1e4);try{if(l){ge({initialPrompt:l.initialPrompt||l.prompt||"",initialImages:l.initialImages||l.uploadedImages||[],selectedElementIds:[],initialResultUrl:l.initialResultUrl||l.resultUrl,initialAspectRatio:l.initialAspectRatio,targetFrameId:l.targetFrameId,targetFrameDimensions:l.targetFrameDimensions}),l.initialModel&&v(l.initialModel),l.initialModelRef!==void 0&&D(l.initialModelRef);return}const d=s.lastSelectedElementIds||[];let m,P,S;const $=Fa(r);if($.length===1&&Ua($[0])){const me=$[0],z=Tt.getRectangleByPoints(me.points);m=Qa(z.width,z.height),P=me.id,S={width:z.width,height:z.height}}const U=await es(r,d),B=[];U.remainingImages.forEach(me=>{B.push({url:me.url,name:me.name||`selected-image-${Date.now()}.png`})}),U.graphicsImage&&B.push({url:U.graphicsImage,name:`graphics-combined-${Date.now()}.png`}),ge({initialPrompt:U.remainingText||"",initialImages:B,selectedElementIds:d,initialAspectRatio:m,targetFrameId:P,targetFrameDimensions:S})}catch(d){console.warn("Error processing selected content for AI:",d);const m=ts(r),P=m.images.map(S=>({url:S.url,name:S.name||`selected-image-${Date.now()}.png`}));ge({initialPrompt:m.text||"",initialImages:P,selectedElementIds:[]})}finally{k.current=!1,g.current&&(clearTimeout(g.current),g.current=null)}})()},[s.lastSelectedElementIds,s.openDialogTypes,r,l]),t.useEffect(()=>{if(!r)return;const I=s.openDialogTypes.has(he.aiVideoGeneration),Z=I&&!ae.current,be=xe.current!==p;if(ae.current=I,xe.current=p,!I||!Z&&!be||k.current)return;(async()=>{k.current=!0,g.current&&clearTimeout(g.current),g.current=setTimeout(()=>{console.warn("Video processing timeout, resetting processing state"),k.current=!1},1e4);try{if(p){ye({initialPrompt:p.initialPrompt||p.prompt||"",initialImage:p.initialImage||p.uploadedImage,initialImages:p.initialImages||p.uploadedImages,initialDuration:p.initialDuration||p.duration,initialModel:p.initialModel||p.model,initialSize:p.initialSize||p.size,initialResultUrl:p.initialResultUrl||p.resultUrl});const S=p.initialModel||p.model;S&&j(S),p.initialModelRef!==void 0&&c(p.initialModelRef);return}const d=s.lastSelectedElementIds||[],m=await es(r,d),P=[];m.remainingImages.length>0?m.remainingImages.forEach((S,$)=>{P.push({url:S.url,name:S.name||`selected-image-${$+1}-${Date.now()}.png`})}):m.graphicsImage&&P.push({url:m.graphicsImage,name:`graphics-combined-${Date.now()}.png`}),ye({initialPrompt:m.remainingText||"",initialImage:P.length>0?P[0]:void 0,initialImages:P.map((S,$)=>({slot:$,slotLabel:`参考图${$+1}`,url:S.url,name:S.name}))})}catch(d){console.warn("Error processing selected content for AI video:",d);const m=ts(r),P=m.images.map((S,$)=>({url:S.url,name:S.name||`selected-image-${$+1}-${Date.now()}.png`}));ye({initialPrompt:m.text||"",initialImage:P.length>0?P[0]:void 0,initialImages:P.map((S,$)=>({slot:$,slotLabel:`参考图${$+1}`,url:S.url,name:S.name}))})}finally{k.current=!1,g.current&&(clearTimeout(g.current),g.current=null)}})()},[s.lastSelectedElementIds,s.openDialogTypes,r,p]),t.useEffect(()=>{s.openDialogTypes.size===0&&(k.current=!1,Se.current=!1,ne.current=null,ae.current=!1,xe.current=null,g.current&&(clearTimeout(g.current),g.current=null))},[s.openDialogTypes]);const Ce=t.useCallback(()=>{const I=localStorage.getItem(Yt);if(I)try{const Z=JSON.parse(I);Z.timestamp=Date.now(),localStorage.setItem(Yt,JSON.stringify(Z))}catch(Z){console.warn("Failed to update cache timestamp:",Z)}i(he.aiImageGeneration)},[i]),ie=t.useCallback(()=>{const I=localStorage.getItem(Xt);if(I)try{const Z=JSON.parse(I);Z.timestamp=Date.now(),localStorage.setItem(Xt,JSON.stringify(Z))}catch(Z){console.warn("Failed to update cache timestamp:",Z)}i(he.aiVideoGeneration)},[i]);return e.jsxs(e.Fragment,{children:[e.jsx(Jt,{open:s.openDialogTypes.has(he.mermaidToDrawnix),onOpenChange:I=>{I?n(he.mermaidToDrawnix):i(he.mermaidToDrawnix)},children:e.jsx(Qt,{className:"Dialog ttd-dialog",container:o,children:e.jsx(oo,{})})}),e.jsx(Jt,{open:s.openDialogTypes.has(he.markdownToDrawnix),onOpenChange:I=>{I?n(he.markdownToDrawnix):i(he.markdownToDrawnix)},children:e.jsx(Qt,{className:"Dialog ttd-dialog",container:o,children:e.jsx(no,{})})}),e.jsx(Zt,{id:"ai-image-dialog",visible:s.openDialogTypes.has(he.aiImageGeneration),title:E==="batch"?a==="zh"?"批量出图":"Batch Generation":a==="zh"?"AI 图片生成":"AI Image Generation",headerContent:T?e.jsxs("div",{className:"image-generation-mode-tabs",onMouseDown:I=>I.stopPropagation(),onTouchStart:I=>I.stopPropagation(),onPointerDown:I=>I.stopPropagation(),children:[e.jsx("button",{type:"button",className:`mode-tab ${E==="single"?"active":""}`,onClick:I=>{I.stopPropagation(),I.preventDefault(),oe("single")},children:a==="zh"?"AI 图片生成":"AI Image"}),e.jsx("button",{type:"button",className:`mode-tab ${E==="batch"?"active":""}`,onClick:I=>{I.stopPropagation(),I.preventDefault(),oe("batch")},children:a==="zh"?"批量出图":"Batch"})]}):void 0,onClose:Ce,width:"80%",height:"60%",minWidth:800,minHeight:500,x:"center",y:"center",modal:!1,minimizable:!1,className:"winbox-ai-generation winbox-ai-image-generation",container:o,autoMaximize:O||x,children:s.openDialogTypes.has(he.aiImageGeneration)&&(E==="batch"?e.jsx(t.Suspense,{fallback:e.jsx("div",{className:"loading-fallback",children:a==="zh"?"加载中...":"Loading..."}),children:e.jsx(_o,{onSwitchToSingle:()=>oe("single"),selectedModel:f,selectedModelRef:u,onModelChange:A,onModelRefChange:K})}):e.jsx(yo,{initialPrompt:G.initialPrompt,initialImages:G.initialImages,selectedElementIds:G.selectedElementIds,initialWidth:(l==null?void 0:l.initialWidth)||(l==null?void 0:l.width),initialHeight:(l==null?void 0:l.initialHeight)||(l==null?void 0:l.height),initialResultUrl:G.initialResultUrl,initialAspectRatio:G.initialAspectRatio,targetFrameId:G.targetFrameId,targetFrameDimensions:G.targetFrameDimensions,selectedModel:f,selectedModelRef:u,onModelChange:A,onModelRefChange:K,externalBatchId:l==null?void 0:l.batchId,initialAutoInsertToCanvas:l==null?void 0:l.autoInsertToCanvas,onDraftChange:l==null?void 0:l.onDraftChange},(l==null?void 0:l.batchId)||"ai-image-dialog"))}),e.jsx(Zt,{id:"ai-video-dialog",visible:s.openDialogTypes.has(he.aiVideoGeneration),title:a==="zh"?"AI 视频生成":"AI Video Generation",onClose:ie,width:"70%",height:"60%",minWidth:800,minHeight:600,x:"center",y:"center",modal:!1,minimizable:!1,className:"winbox-ai-generation winbox-ai-video-generation",container:o,autoMaximize:x,children:s.openDialogTypes.has(he.aiVideoGeneration)&&e.jsx(So,{initialPrompt:J.initialPrompt,initialImage:J.initialImage,initialImages:J.initialImages,initialDuration:J.initialDuration,initialModel:J.initialModel,initialSize:J.initialSize,initialResultUrl:J.initialResultUrl,selectedModel:N,selectedModelRef:W,onModelChange:X,onModelRefChange:le,externalBatchId:p==null?void 0:p.batchId,initialAutoInsertToCanvas:p==null?void 0:p.autoInsertToCanvas,onDraftChange:p==null?void 0:p.onDraftChange},(p==null?void 0:p.batchId)||"ai-video-dialog")})]})},zo=t.memo(jo,(o,s)=>o.container===s.container);export{zo as TTDDialog};
|