aitu-app 1.0.0 → 1.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (106) hide show
  1. package/README.md +3 -3
  2. package/assets/{CanvasAudioPlayer-DyUPmMV6.js → CanvasAudioPlayer-HtUs8HDj.js} +2 -2
  3. package/assets/ComicCreator-DhxXCyJR.js +43 -0
  4. package/assets/{DeferredAIInputBar-Cq0t7wNK.js → DeferredAIInputBar-B2R2-2RU.js} +3 -3
  5. package/assets/{DrawnixDeferredFeatures-B9y0GPYR.js → DrawnixDeferredFeatures-DHTr0c-V.js} +2 -2
  6. package/assets/{KnowledgeBaseContent-C8zmce09.js → KnowledgeBaseContent-CAq5kXdt.js} +6 -6
  7. package/assets/{MVCreator-Bl8GH4mR.js → MVCreator-B9uaRsGE.js} +16 -16
  8. package/assets/{ModelBenchmarkWorkbench-BwfeZDt-.js → ModelBenchmarkWorkbench-CK33zizl.js} +1 -1
  9. package/assets/{MusicAnalyzer-CdMhl-kU.js → MusicAnalyzer-D2NTonEA.js} +1 -1
  10. package/assets/{PromptHistoryTool-CCxoST3H.js → PromptHistoryTool-q6vOxFr6.js} +1 -1
  11. package/assets/{ResizableDivider-D1jgqdmh.js → ResizableDivider-BvT-DCEo.js} +2 -2
  12. package/assets/{TaskQueuePanel-WF6aq1G7.js → TaskQueuePanel-PayswYlG.js} +1 -1
  13. package/assets/{VideoAnalyzer-BOqRFjZ9.js → VideoAnalyzer-DnowtohS.js} +1 -1
  14. package/assets/{VideoAnalyzer-BrEKSLeh.js → VideoAnalyzer-DoaGlK92.js} +2 -2
  15. package/assets/{ai-chat-DbjmzngX.css → ai-chat-BlxYfB4O.css} +1 -1
  16. package/assets/ai-chat-BnWVpTEI.js +2977 -0
  17. package/assets/{batch-image-generation-DyWeiTsw.js → batch-image-generation-CkmX4dem.js} +5 -5
  18. package/assets/{bootstrap-DadYvnge.js → bootstrap-CQRLkOtk.js} +7 -7
  19. package/assets/{clean-confirm-CpWpcTF5.js → clean-confirm-CIViVQ8s.js} +1 -1
  20. package/assets/{diagram-engines-C0Ljec4Z.js → diagram-engines-DpAsX7pc.js} +3 -3
  21. package/assets/{editor-engines-Dz5Mk5YB.js → editor-engines-9_72Ghfn.js} +1 -1
  22. package/assets/{external-skill-service-BQUJLLLc.js → external-skill-service-BN8ZCtPn.js} +1 -1
  23. package/assets/{frame-size-matcher-2sxA9X-P.js → frame-size-matcher-9rxQ-bAY.js} +1 -1
  24. package/assets/{index-CRuDVxTu.js → index-291TeU7i.js} +1 -1
  25. package/assets/{index-BNtKpMlh.js → index-BJ-vS89P.js} +1 -1
  26. package/assets/{index-Ct7MFvFo.js → index-BSZAS0wO.js} +1 -1
  27. package/assets/{index-BfdBtWT6.js → index-C7DAD_xK.js} +1 -1
  28. package/assets/{index-o8hm5yhT.js → index-CIgiIDgZ.js} +1 -1
  29. package/assets/{index-BwW4Qp-A.js → index-CpHWUe__.js} +1 -1
  30. package/assets/{index-D7UBK5T7.js → index-D1LQ9eQM.js} +1 -1
  31. package/assets/{index-D_Yn26AT.js → index-DRGxmFyd.js} +1 -1
  32. package/assets/{index-CBMgStgL.js → index-DmtcRYr8.js} +1 -1
  33. package/assets/{index.es-CYBRnsv6.js → index.es-Ch45-H39.js} +1 -1
  34. package/assets/{jspdf.es.min-I7TkFvGI.js → jspdf.es.min-bNprb1JY.js} +3 -3
  35. package/assets/{link-popup-fCfgZp17.js → link-popup-B6ReK6iq.js} +1 -1
  36. package/assets/{markdown-to-drawnix-3yksNvbU.js → markdown-to-drawnix-BqT-3zQO.js} +3 -3
  37. package/assets/{mermaid-to-drawnix-C7rF-30X.js → mermaid-to-drawnix-CSctnpU0.js} +3 -3
  38. package/assets/{model-benchmark-launcher-uYoranwQ.js → model-benchmark-launcher-DNMp2MLQ.js} +1 -1
  39. package/assets/{photo-wall-splitter-CfRBAwCy.js → photo-wall-splitter-DhBTEpdG.js} +1 -1
  40. package/assets/{popup-toolbar-tKtYPGvw.js → popup-toolbar-BChsudwW.js} +7 -7
  41. package/assets/{prompt-utils-C_mjEqkz.js → prompt-utils-BX0pRV-Z.js} +1 -1
  42. package/assets/quick-creation-toolbar-3-AYFpEF.js +2 -0
  43. package/assets/{settings-dialog-DfK6bcBd.js → settings-dialog-Ccemaout.js} +1 -1
  44. package/assets/{size-picker-DvMt8S3Z.js → size-picker-DTrdjyLh.js} +1 -1
  45. package/assets/{skill-dsl-parser-CTM4hEIp.js → skill-dsl-parser-ZR--uu5h.js} +1 -1
  46. package/assets/{startup-app-9gZEGv85.js → startup-app-CH3QzBb4.js} +2 -2
  47. package/assets/{task-sync-D7bw59_K.js → task-sync-C5XXOQ5m.js} +1 -1
  48. package/assets/{tool-windows-BnDZa9FH.js → tool-windows-Bf_pMml-.js} +6 -6
  49. package/assets/ttd-dialog-CohjwODB.js +6 -0
  50. package/assets/{ttd-dialog-submit-shortcut-UfHT9Z9k.js → ttd-dialog-submit-shortcut-BVB8O_wE.js} +1 -1
  51. package/assets/{useCharacters-6u0Wuwt4.js → useCharacters-CFlPvydq.js} +1 -1
  52. package/assets/{useWorkflowSubmission-DTWha6Vn.js → useWorkflowSubmission-CKkOEcAT.js} +3 -3
  53. package/assets/{video-merge-webcodecs-Cwy2df91.js → video-merge-webcodecs-BInWo9HA.js} +2 -2
  54. package/assets/{video-recovery-service-CgZ3pA_1.js → video-recovery-service-DITdD0pC.js} +1 -1
  55. package/assets/{workflow-generation-utils-BPT49S-Z.js → workflow-generation-utils-e0nRpAgJ.js} +3 -3
  56. package/assets/{workflow-submission-service-C-6Uf9FA.js → workflow-submission-service-BqiL_5Cj.js} +3 -3
  57. package/changelog.json +105 -6
  58. package/idle-prefetch-manifest.json +136 -288
  59. package/manifest.json +3 -3
  60. package/package.json +1 -1
  61. package/precache-manifest.json +6 -6
  62. package/sw.js +1 -1
  63. package/version.json +63 -3
  64. package/.DS_Store +0 -0
  65. package/assets/ComicCreator-DjOhYrZt.js +0 -43
  66. package/assets/ai-chat-B-XdoWBQ.js +0 -2976
  67. package/assets/quick-creation-toolbar-CrQ0g0kO.js +0 -2
  68. package/assets/ttd-dialog-DS6KiOOa.js +0 -6
  69. package/assets/useMediaViewer-BrBFopM-.js +0 -1
  70. package/user-manual/gifs//346/200/235/347/273/264/345/257/274/345/233/276/345/210/233/345/273/272/346/274/224/347/244/272.gif +0 -0
  71. package/user-manual/screenshots/ai-step-0.png +0 -0
  72. package/user-manual/screenshots/ai-step-1.png +0 -0
  73. package/user-manual/screenshots/ai-step-2.png +0 -0
  74. package/user-manual/screenshots/ai-step-3.png +0 -0
  75. package/user-manual/screenshots/app-menu.png +0 -0
  76. package/user-manual/screenshots/backup-restore.png +0 -0
  77. package/user-manual/screenshots/canvas-tools.png +0 -0
  78. package/user-manual/screenshots/debug-panel.png +0 -0
  79. package/user-manual/screenshots/drawing-step-0.png +0 -0
  80. package/user-manual/screenshots/drawing-step-1.png +0 -0
  81. package/user-manual/screenshots/drawing-step-2.png +0 -0
  82. package/user-manual/screenshots/edit-selected.png +0 -0
  83. package/user-manual/screenshots/element-selected.png +0 -0
  84. package/user-manual/screenshots/flowchart-step-1.png +0 -0
  85. package/user-manual/screenshots/flowchart-step-2.png +0 -0
  86. package/user-manual/screenshots/flowchart-step-3.png +0 -0
  87. package/user-manual/screenshots/image-preview-empty.png +0 -0
  88. package/user-manual/screenshots/insert-from-library.png +0 -0
  89. package/user-manual/screenshots/insert-tools.png +0 -0
  90. package/user-manual/screenshots/inspiration-step-1.png +0 -0
  91. package/user-manual/screenshots/inspiration-step-2.png +0 -0
  92. package/user-manual/screenshots/media-library.png +0 -0
  93. package/user-manual/screenshots/mindmap-step-1.png +0 -0
  94. package/user-manual/screenshots/mindmap-step-2.png +0 -0
  95. package/user-manual/screenshots/mindmap-toolbar-menu.png +0 -0
  96. package/user-manual/screenshots/project-drawer.png +0 -0
  97. package/user-manual/screenshots/settings-dialog.png +0 -0
  98. package/user-manual/screenshots/shape-step-1.png +0 -0
  99. package/user-manual/screenshots/shape-step-2.png +0 -0
  100. package/user-manual/screenshots/text-step-1.png +0 -0
  101. package/user-manual/screenshots/text-step-2.png +0 -0
  102. package/user-manual/screenshots/toolbox-drawer.png +0 -0
  103. package/user-manual/screenshots/toolbox-entry.png +0 -0
  104. package/user-manual/screenshots/video-entry.png +0 -0
  105. package/user-manual/screenshots/view-navigation.png +0 -0
  106. package/user-manual/screenshots/zoom-menu.png +0 -0
@@ -1,18 +1,18 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["./ai-chat-DbjmzngX.css","./MediaLibrarySidebar-CcSibzET.css","./tool-windows-DW-CDfPc.css"])))=>i.map(i=>d[i]);
2
- import{_ as De}from"./startup-runtime-BrfuwjQS.js";import{lz as Ke,lA as Qe,lB as Nt,bu as En,bj as K,lC as In,lD as It,lE as zt,ak as Se,jU as we,lF as Gs,lG as pt,lH as cs,lI as ot,lJ as me,lK as ye,W as Z,lL as Ct,cd as ht,P as i,bd as te,a8 as t,i5 as Ne,i6 as _e,aa as z,i7 as Ee,iq as Ie,cm as je,lM as Ye,R as ds,lN as us,ar as fn,d$ as Vs,e0 as Xs,e1 as Ys,lO as Zs,lP as qs,lQ as hs,lR as ps,c8 as Ks,lS as cn,lT as An,ab as ae,ep as zn,S as St,U as ms,lU as fs,lV as Qs,ao as W,lW as Js,lX as eo,f6 as to,iP as no,gx as so,gy as gs,cO as xs,eI as ys,lY as bs,lZ as Yt,l_ as oo,l$ as ao,aw as qe,dU as io,bp as st,m0 as lo,m1 as ro,bk as Be,bq as U,ca as Le,bt as at,el as vs,m2 as co,a7 as gn,m3 as uo,em as ho,fS as po,fR as mo,m4 as fo,m5 as Pn,m6 as Mn,bK as go,gz as ws,m7 as xo,m8 as yo,m9 as bo,ma as vo,mb as wo,mc as ko,md as jo,me as Co,mf as So,mg as No,mh as _o,mi as Eo,mj as Io,mk as zo,ml as Po,mm as To,mn as Fo,mo as Ao,mp as Mo,mq as Do,mr as Bo,ms as Lo,mt as Ro,mu as Oo,c0 as nn,hB as Zt,mv as ks,mw as Uo,mx as $o,c4 as Wo,eB as Ho,d1 as Go,b8 as js,at as qt,ec as Vo,my as Xo,cE as Yo,hO as Zo,mz as qo,mA as Ko,mB as Qo,mC as Jo,ic as dt,jR as Wt,mD as Dn,hA as ea,mE as Bn,mF as ta,Q as na,eP as xn,eG as sa,eD as oa,eF as aa,eO as ia,fb as la,eQ as ra,mG as Ln,js as Rn,jp as On,hX as Un,mH as ca,mI as da,mJ as $n,cT as ua,cS as ha,mK as pa,dE as ma,mL as fa,eV as ga,mM as Wn,i9 as xa,mN as ya,mO as Hn,f5 as ba,iO as va,mP as wa,mQ as ka,du as ja,mR as Ca,mS as Sa,mT as Na,mU as _a,eZ as Ea,ka as Ia,ek as za,mV as Pa,br as Gn,bf as Vn,bs as Xn,mW as Ta,cJ as Yn,jN as Fa,cR as Aa,cQ as Ma,mX as Da,mY as Ba,mZ as La,ib as Ra,fy as Oa,b9 as Ua,cl as Cs,ci as $a,m_ as dn,ck as Wa,cj as Ha,cc as Ga,ei as Va,cb as Ss,bv as Xa,m$ as Ya}from"./ai-chat-B-XdoWBQ.js";import{I as ze,S as Xt,g as Za,h as qa,o as Ka,j as Qa,k as Ja,l as ei,n as ti}from"./bootstrap-DadYvnge.js";import{I as Kt,$ as Ns,a0 as _s,c as oe,a2 as _t,a3 as ni,R as si,A as jt,D as yn,B as Ht,a4 as oi,a5 as Zn,a6 as qn,a7 as sn,a8 as ai,a9 as Es,aa as ii,ab as li,y as ri,ac as ci,ad as di,ae as ui,V as hi}from"./tool-windows-BnDZa9FH.js";import{m as pi}from"./video-merge-webcodecs-Cwy2df91.js";import{m as mi}from"./frame-size-matcher-2sxA9X-P.js";import{b as fi}from"./image-task-prefill-DtECrkJn.js";import"./startup-app-9gZEGv85.js";const Is=e=>e?typeof e=="string"?e:ht(e)&&e.type==="solid"&&e.solid?e.solid.color:null:null,gi=(e,n)=>{Ke.setFillColor(e,null,{getMemorizeKey:Qe,callback:(s,a)=>{if(!Kt(e,s))return;const o=s.fill,l=Is(o)||Ns(e,s);if(!Gs(l))return;const d=pt(l),m=It(n)?d:zt(d,n);K.setNode(e,{fill:m},a)}})},xi=(e,n)=>{Ke.setFillColor(e,null,{getMemorizeKey:Qe,callback:(s,a)=>{if(!Kt(e,s))return;const o=s.fill,l=Is(o)||Ns(e,s),d=typeof l=="string"?Nt(l):void 0;En(n)?K.setNode(e,{fill:"none"},a):In(d)||It(d)?K.setNode(e,{fill:n},a):K.setNode(e,{fill:zt(n,d)},a)}})},yi=(e,n)=>{Ke.setStrokeColor(e,null,{getMemorizeKey:Qe,callback:(s,a)=>{const o=_s(e,s),l=pt(o),d=It(n)?l:zt(l,n);K.setNode(e,{strokeColor:d},a)}})},bi=(e,n)=>{Ke.setStrokeColor(e,null,{getMemorizeKey:Qe,callback:(s,a)=>{const o=_s(e,s),l=Nt(o);En(n)?K.setNode(e,{strokeColor:"none"},a):In(l)||It(l)?K.setNode(e,{strokeColor:n},a):K.setNode(e,{strokeColor:zt(n,l)},a)}})},vi=(e,n)=>{Ke.setStrokeStyle(e,n,{getMemorizeKey:Qe,callback:(s,a)=>{K.setNode(e,{strokeStyle:n},a)}})},Kn=(e,n)=>{Ke.setStrokeWidth(e,n,{getMemorizeKey:Qe,callback:(s,a)=>{K.setNode(e,{strokeWidth:n},a)}})},wi=(e,n,s)=>{const a=Nt(n);En(s)?ot.setTextColor(e,null):In(a)||It(a)?ot.setTextColor(e,s):ot.setTextColor(e,zt(s,a))},ki=(e,n,s)=>{const a=pt(n),o=It(s)?a:zt(a,s);ot.setTextColor(e,o)},zs=(e,n)=>{try{ot.setFontSize(e,n,16)}catch{const a=me(e);a&&a.length>0&&a.forEach(o=>{try{o.addMark("font-size",n)}catch(l){console.error("Failed to set font size mark:",l)}})}},ji=(e,n)=>{const s=me(e);s&&s.length>0&&s.forEach(a=>{try{ye(a),Z.addMark(a,"font-family",n)}catch(o){console.error("Failed to set font family:",o)}})},bn=(e,n)=>{const s=me(e);s&&s.length>0&&s.forEach(a=>{try{ye(a),n?Z.addMark(a,"text-shadow",n):Z.removeMark(a,"text-shadow")}catch(o){console.error("Failed to set text shadow:",o)}})},Qn=(e,n)=>{const s=me(e);s&&s.length>0&&s.forEach(a=>{try{ye(a),n?Z.addMark(a,"text-gradient",n):Z.removeMark(a,"text-gradient")}catch(o){console.error("Failed to set text gradient:",o)}})},Ps=(e,n)=>{const s=me(e);s&&s.length>0&&s.forEach(a=>{try{ye(a),Z.addMark(a,"font-weight",String(n))}catch(o){console.error("Failed to set font weight:",o)}})},Ci=(e,n)=>{try{let s;n==="left"?s=Ct.left:n==="center"?s=Ct.center:s=Ct.right,ot.setTextAlign(e,s)}catch(s){console.error("Failed to set text align:",s)}},Si=(e,n)=>{const s=me(e);s&&s.length>0&&s.forEach(a=>{try{ye(a),Z.addMark(a,"line-height",String(n))}catch(o){console.error("Failed to set line height:",o)}})},Ni=(e,n)=>{const s=me(e);s&&s.length>0&&s.forEach(a=>{try{ye(a);const o=typeof n=="number"?`${n}px`:n;Z.addMark(a,"letter-spacing",o)}catch(o){console.error("Failed to set letter spacing:",o)}})},_i=e=>{const n=me(e);n&&n.length>0&&n.forEach(s=>{try{ye(s);const a=Z.marks(s);(a?!!a.bold:!1)?Z.removeMark(s,"bold"):Z.addMark(s,"bold",!0)}catch(a){console.error("Failed to toggle bold:",a)}})},Ei=e=>{const n=me(e);n&&n.length>0&&n.forEach(s=>{try{ye(s);const a=Z.marks(s);(a?!!a.italic:!1)?Z.removeMark(s,"italic"):Z.addMark(s,"italic",!0)}catch(a){console.error("Failed to toggle italic:",a)}})},Ii=e=>{const n=me(e);n&&n.length>0&&n.forEach(s=>{try{ye(s);const a=Z.marks(s);(a?!!a.underlined:!1)?Z.removeMark(s,"underlined"):Z.addMark(s,"underlined",!0)}catch(a){console.error("Failed to toggle underline:",a)}})},zi=e=>{const n=me(e);n&&n.length>0&&n.forEach(s=>{try{ye(s);const a=Z.marks(s);(a?!!a.strikethrough:!1)?Z.removeMark(s,"strikethrough"):Z.addMark(s,"strikethrough",!0)}catch(a){console.error("Failed to toggle strikethrough:",a)}})},Pi=e=>{const n=me(e);n&&n.length>0&&n.forEach(s=>{try{ye(s);const a=Z.marks(s);(a?!!a.superscript:!1)?Z.removeMark(s,"superscript"):(Z.removeMark(s,"subscript"),Z.addMark(s,"superscript",!0))}catch(a){console.error("Failed to toggle superscript:",a)}})},Ti=e=>{const n=me(e);n&&n.length>0&&n.forEach(s=>{try{ye(s);const a=Z.marks(s);(a?!!a.subscript:!1)?Z.removeMark(s,"subscript"):(Z.removeMark(s,"superscript"),Z.addMark(s,"subscript",!0))}catch(a){console.error("Failed to toggle subscript:",a)}})},Fi=(e,n)=>{const s=me(e);s&&s.length>0&&s.forEach(a=>{try{ye(a),n?Z.addMark(a,"background-color",n):Z.removeMark(a,"background-color")}catch(o){console.error("Failed to set background color:",o)}})},Ai=(e,n)=>{const s=me(e);s&&s.length>0&&s.forEach(a=>{try{ye(a),n&&n!=="none"?Z.addMark(a,"text-transform",n):Z.removeMark(a,"text-transform")}catch(o){console.error("Failed to set text transform:",o)}})},Mi=(e,n,s)=>{const a=me(e);a&&a.length>0&&a.forEach(o=>{try{ye(o),n&&n>0?(Z.addMark(o,"text-stroke",n),s&&Z.addMark(o,"text-stroke-color",s)):(Z.removeMark(o,"text-stroke"),Z.removeMark(o,"text-stroke-color"))}catch(l){console.error("Failed to set text stroke:",l)}})},Di=(e,n)=>{const s=me(e);s&&s.length>0&&s.forEach(a=>{try{ye(a),n?Z.addMark(a,"text-decoration-style",n):Z.removeMark(a,"text-decoration-style")}catch(o){console.error("Failed to set text decoration style:",o)}})},Bi=(e,n)=>{const s=me(e);s&&s.length>0&&s.forEach(a=>{try{ye(a),n?Z.addMark(a,"text-decoration-color",n):Z.removeMark(a,"text-decoration-color")}catch(o){console.error("Failed to set text decoration color:",o)}})},Li=e=>{const n=me(e);if(n&&n.length>0){const s=n[0];try{return ye(s),Z.marks(s)||{}}catch(a){return console.error("Failed to get text marks:",a),{}}}return{}},Ri=e=>{const n=me(e);if(n&&n.length>0){const s=n[0];try{const{selection:a}=s;if(a){const o=Array.from(Z.nodes(s,{at:a,match:l=>{const d=l.type==="paragraph",m="align"in l;return Z.isBlock(s,l)&&(d||m)}}));if(o.length>0){const[l]=o[0],d=l.align;if(d===Ct.right||d==="right")return"right";if(d===Ct.center||d==="center")return"center";if(d===Ct.left||d==="left")return"left"}}}catch(a){console.error("Failed to get text align:",a)}}return"left"},Oi=(e,n)=>{Ke.setFillColor(e,null,{getMemorizeKey:Qe,callback:(s,a)=>{if(!Kt(e,s))return;const o=cs(n),l={type:"gradient",gradient:n,fallbackColor:o};K.setNode(e,{fill:o,fillConfig:l},a)}})},Jn=(e,n)=>{Ke.setFillColor(e,null,{getMemorizeKey:Qe,callback:(s,a)=>{if(!Kt(e,s))return;const o="#FFFFFF",l={type:"image",image:n,fallbackColor:o};K.setNode(e,{fill:o,fillConfig:l},a)}})},Ui=(e,n)=>{Ke.setFillColor(e,null,{getMemorizeKey:Qe,callback:(s,a)=>{if(!Kt(e,s))return;const o=s.fillConfig,l=s.fill;if((o==null?void 0:o.type)!==n)switch(n){case"solid":{let d="#FFFFFF";typeof l=="string"&&l!=="none"?d=l:o!=null&&o.solid&&(d=o.solid.color),K.setNode(e,{fill:d,fillConfig:void 0},a);break}case"gradient":{const d={type:"linear",angle:90,stops:[{offset:0,color:"#FFFFFF"},{offset:1,color:"#000000"}]},m=(o==null?void 0:o.gradient)||d,x=cs(m),h={type:"gradient",gradient:m,fallbackColor:x};K.setNode(e,{fill:x,fillConfig:h},a);break}case"image":{const d={imageUrl:"",mode:"stretch",scale:1,offsetX:0,offsetY:0,rotation:0},m="#FFFFFF",x={type:"image",image:(o==null?void 0:o.image)||d,fallbackColor:m};K.setNode(e,{fill:m,fillConfig:x},a);break}default:return}}})},$i=(e,n)=>{const s=Se(e);for(const a of s)if(we(a)){const o=e.children.findIndex(l=>l.id===a.id);o!==-1&&K.setNode(e,{fillColor:n},[o])}},Wi=({board:e,currentColor:n,fontColorIcon:s,title:a})=>{const[o,l]=i.useState(!1),d=te.getBoardContainer(e),m=i.useCallback(h=>{wi(e,n||h,h)},[e,n]),x=i.useCallback(h=>{n&&ki(e,n,h)},[e,n]);return t.jsxs(Ne,{sideOffset:12,open:o,onOpenChange:h=>{l(h)},placement:"top",children:[t.jsx(_e,{asChild:!0,children:t.jsx(oe,{className:z("property-button"),selected:o,visible:!0,icon:s,type:"button",tooltip:a,"aria-label":a,onPointerUp:()=>{l(!o)}})}),t.jsx(Ee,{container:d,children:t.jsx(ze,{padding:4,className:z(`${Ie}`),children:t.jsx(_t,{value:n,onChange:m,onOpacityChange:x})})})]})},Nn=[{key:"title",labelZh:"标题",labelEn:"Title",previewSize:26,...Ye.title},{key:"subtitle",labelZh:"副标题",labelEn:"Subtitle",previewSize:22,...Ye.subtitle},{key:"h1",labelZh:"标题 1",labelEn:"Heading 1",previewSize:20,...Ye.h1,divider:!0},{key:"h2",labelZh:"标题 2",labelEn:"Heading 2",previewSize:18,...Ye.h2},{key:"h3",labelZh:"标题 3",labelEn:"Heading 3",previewSize:16,...Ye.h3},{key:"h4",labelZh:"标题 4",labelEn:"Heading 4",previewSize:15,...Ye.h4},{key:"body",labelZh:"正文",labelEn:"Body",previewSize:14,...Ye.body,divider:!0},{key:"caption",labelZh:"注释",labelEn:"Caption",previewSize:13,...Ye.caption},{key:"footnote",labelZh:"脚注",labelEn:"Footnote",previewSize:12,...Ye.footnote}],Hi=e=>{if(!e)return null;const n=parseInt(e,10);if(isNaN(n))return null;for(const s of Nn)if(s.fontSize===n)return s.key;return null},Gi=({board:e,currentFontSize:n,title:s})=>{const[a,o]=i.useState(!1),{language:l}=je(),d=te.getBoardContainer(e),m=Hi(n),x=i.useCallback(p=>{zs(e,String(p.fontSize)),Ps(e,p.fontWeight),ot.setTextColor(e,p.color),o(!1)},[e]),h=(()=>{if(m){const p=Nn.find(j=>j.key===m);if(p)return l==="zh"?p.labelZh:p.labelEn}return n||"16"})();return t.jsxs(Ne,{sideOffset:12,open:a,onOpenChange:o,placement:"bottom",children:[t.jsx(_e,{asChild:!0,children:t.jsx(oe,{className:z("property-button"),selected:a,visible:!0,type:"button",tooltip:s,"aria-label":s,onPointerUp:()=>o(!a),children:t.jsx("div",{style:{fontSize:"12px",fontWeight:"bold",minWidth:"20px"},children:h})})}),t.jsx(Ee,{container:d,children:t.jsx(ze,{padding:4,className:z(`${Ie}`),children:t.jsxs(Xt.Col,{gap:0,style:{minWidth:"200px"},children:[t.jsx("div",{style:{fontSize:"12px",color:"#666",marginBottom:"2px",padding:"4px 10px 0"},children:l==="zh"?"字体样式":"Font Style"}),t.jsx("div",{style:{maxHeight:"320px",overflowY:"auto"},children:Nn.map(p=>{const j=m===p.key;return t.jsxs(ds.Fragment,{children:[p.divider&&t.jsx("div",{style:{height:"1px",backgroundColor:"#e8e8e8",margin:"4px 10px"}}),t.jsxs("div",{onClick:()=>x(p),style:{padding:"6px 10px",cursor:"pointer",backgroundColor:j?"#f0f7ff":"transparent",borderLeft:j?"3px solid #0052d9":"3px solid transparent",borderRadius:"2px",transition:"background-color 0.15s",display:"flex",alignItems:"baseline",justifyContent:"space-between",gap:"8px"},onMouseEnter:f=>{j||(f.currentTarget.style.backgroundColor="#f5f5f5")},onMouseLeave:f=>{j||(f.currentTarget.style.backgroundColor="transparent")},children:[t.jsx("span",{style:{fontSize:`${p.previewSize}px`,fontWeight:p.fontWeight,color:p.color,lineHeight:1.4},children:l==="zh"?p.labelZh:p.labelEn}),t.jsxs("span",{style:{fontSize:"11px",color:"#bbb",flexShrink:0},children:[p.fontSize,"px"]})]})]},p.key)})})]})})})]})},Vi=({board:e,currentColor:n,title:s,hasStrokeStyle:a,hasStrokeWidth:o,currentStrokeWidth:l,children:d})=>{const[m,x]=i.useState(!1),[h,p]=i.useState(String(l||2)),j=n&&pt(n),f=n?Nt(n):100,M=te.getBoardContainer(e);ds.useEffect(()=>{p(String(l||2))},[l]);const S=hs(f)?Zs:ps(j)?qs:void 0,T=S?t.jsx(S,{}):void 0,v=c=>{vi(e,c)},P=i.useCallback(c=>{bi(e,c)},[e]),ne=i.useCallback(c=>{yi(e,c)},[e]),Q=i.useCallback(c=>{Kn(e,c),p(String(c))},[e]),$=i.useCallback(c=>{p(c.target.value)},[]),w=i.useCallback(()=>{const c=parseInt(h,10);!isNaN(c)&&c>=1&&c<=100?Kn(e,c):p(String(l||2))},[e,h,l]),g=i.useCallback(c=>{c.key==="Enter"?(w(),c.target.blur()):c.key==="Escape"&&(p(String(l||2)),c.target.blur())},[w,l]);return t.jsxs(Ne,{sideOffset:12,crossAxisOffset:40,open:m,onOpenChange:c=>{x(c)},placement:"left",children:[t.jsx(_e,{asChild:!0,children:t.jsx(oe,{className:z("property-button"),visible:!0,icon:T,type:"button",tooltip:s,"aria-label":s,onPointerUp:()=>{x(!m)},children:!T&&d})}),t.jsx(Ee,{container:M,children:t.jsx(ze,{padding:4,className:z(`${Ie}`,"stroke-setting",{"has-stroke-style":a}),children:t.jsxs(Xt.Col,{children:[o&&t.jsx("div",{className:"stroke-width-section",style:{marginBottom:"8px"},children:t.jsxs(Xt.Row,{gap:2,align:"center",children:[t.jsx("span",{style:{fontSize:"12px",color:"var(--color-on-surface)",whiteSpace:"nowrap"},children:"线宽:"}),t.jsx("div",{style:{flex:1,minWidth:"100px"},children:t.jsx(us,{value:l||2,min:1,max:100,step:1,onChange:c=>Q(c),label:!1})}),t.jsxs("div",{className:"stroke-width-input-wrapper",children:[t.jsx("input",{type:"text",inputMode:"numeric",pattern:"[0-9]*",value:h,onChange:$,onBlur:w,onKeyDown:g,className:"stroke-width-input"}),t.jsx("span",{className:"stroke-width-input-unit",children:"px"})]})]})}),a&&t.jsxs("div",{className:"stroke-style-section",children:[t.jsx("span",{className:"stroke-style-label",children:"样式:"}),t.jsxs(Xt.Row,{className:z("stroke-style-picker"),children:[t.jsx(oe,{visible:!0,icon:t.jsx(Vs,{}),type:"button",tooltip:"实线","aria-label":"实线",onPointerUp:()=>v(fn.solid)}),t.jsx(oe,{visible:!0,icon:t.jsx(Xs,{}),type:"button",tooltip:"虚线","aria-label":"虚线",onPointerUp:()=>v(fn.dashed)}),t.jsx(oe,{visible:!0,icon:t.jsx(Ys,{}),type:"button",tooltip:"点线","aria-label":"点线",onPointerUp:()=>v(fn.dotted)})]})]}),t.jsx(_t,{value:n,onChange:P,onOpacityChange:ne})]})})})]})},Xi="drawnix-color-history",es=24,ts=12,ns=Ks.createInstance({name:"drawnix",storeName:Xi});let ee=null;function _n(e){const n=e.stops.map(s=>`${s.color}@${s.offset}`).join("|");return e.type==="linear"?`linear-${e.angle}-${n}`:`radial-${e.centerX}-${e.centerY}-${n}`}function Yi(e,n){return _n(e)===_n(n)}class Zi{constructor(){this.initialized=!1}async initialize(){if(!this.initialized)try{ee=await ns.getItem("history")||{colors:[],gradients:[]},this.initialized=!0}catch(n){console.error("[ColorHistoryService] Failed to initialize:",n),ee={colors:[],gradients:[]},this.initialized=!0}}async saveData(){if(ee)try{await ns.setItem("history",ee)}catch(n){console.error("[ColorHistoryService] Failed to save data:",n)}}async addColor(n){if(await this.initialize(),!ee)return;const s=n.toUpperCase(),a=ee.colors.findIndex(o=>o.color.toUpperCase()===s);if(a>=0){ee.colors[a].lastUsedAt=Date.now(),ee.colors[a].useCount+=1;const[o]=ee.colors.splice(a,1);ee.colors.unshift(o)}else ee.colors.unshift({color:s,lastUsedAt:Date.now(),useCount:1}),ee.colors.length>es&&(ee.colors=ee.colors.slice(0,es));await this.saveData()}async addGradient(n){if(await this.initialize(),!ee)return;const s=_n(n),a=ee.gradients.findIndex(o=>Yi(o.config,n));if(a>=0){ee.gradients[a].lastUsedAt=Date.now(),ee.gradients[a].useCount+=1;const[o]=ee.gradients.splice(a,1);ee.gradients.unshift(o)}else ee.gradients.unshift({id:s,config:{...n},lastUsedAt:Date.now(),useCount:1}),ee.gradients.length>ts&&(ee.gradients=ee.gradients.slice(0,ts));await this.saveData()}async getColors(){return await this.initialize(),(ee==null?void 0:ee.colors)||[]}async getGradients(){return await this.initialize(),(ee==null?void 0:ee.gradients)||[]}async removeColor(n){if(await this.initialize(),!ee)return;const s=n.toUpperCase();ee.colors=ee.colors.filter(a=>a.color.toUpperCase()!==s),await this.saveData()}async removeGradient(n){await this.initialize(),ee&&(ee.gradients=ee.gradients.filter(s=>s.id!==n),await this.saveData())}async clearAll(){ee={colors:[],gradients:[]},await this.saveData()}resetCache(){ee=null,this.initialized=!1}}const Ge=new Zi;function qi(){const[e,n]=i.useState([]),[s,a]=i.useState([]),[o,l]=i.useState(!0),d=i.useCallback(async()=>{try{const[j,f]=await Promise.all([Ge.getColors(),Ge.getGradients()]);n(j),a(f)}catch(j){console.error("[useColorHistory] Failed to load data:",j)}finally{l(!1)}},[]);i.useEffect(()=>{d()},[d]);const m=i.useCallback(async j=>{await Ge.addColor(j);const f=await Ge.getColors();n(f)},[]),x=i.useCallback(async j=>{await Ge.addGradient(j);const f=await Ge.getGradients();a(f)},[]),h=i.useCallback(async j=>{await Ge.removeColor(j);const f=await Ge.getColors();n(f)},[]),p=i.useCallback(async j=>{await Ge.removeGradient(j);const f=await Ge.getGradients();a(f)},[]);return{colors:e,gradients:s,isLoading:o,addColor:m,addGradient:x,removeColor:h,removeGradient:p,refresh:d}}function ut(e){const n=e.stops.map(s=>`${s.color} ${Math.round(s.offset*100)}%`).join(", ");if(e.type==="linear")return`linear-gradient(${e.angle}deg, ${n})`;{const s=Math.round(e.centerX*100),a=Math.round(e.centerY*100);return`radial-gradient(circle at ${s}% ${a}%, ${n})`}}function Ki(e){const n=e.match(/linear-gradient\((\d+)deg,\s*(.+)\)/);if(n){const a=parseInt(n[1],10),o=n[2],l=ss(o);return{type:"linear",angle:a,stops:l.length>=2?l:[{color:"#FF6B6B",offset:0},{color:"#4ECDC4",offset:1}]}}const s=e.match(/radial-gradient\(circle(?:\s+at\s+(\d+)%\s+(\d+)%)?,\s*(.+)\)/);if(s){const a=s[1]?parseInt(s[1],10)/100:.5,o=s[2]?parseInt(s[2],10)/100:.5,l=s[3],d=ss(l);return{type:"radial",centerX:a,centerY:o,stops:d.length>=2?d:[{color:"#FF6B6B",offset:0},{color:"#4ECDC4",offset:1}]}}return cn}function ss(e){const n=[],s=/(#[0-9a-fA-F]{3,8}|rgba?\([^)]+\))\s+(\d+)%/g;let a;for(;(a=s.exec(e))!==null;)n.push({color:a[1],offset:parseInt(a[2],10)/100});return n}const os=[{key:"left",labelZh:"左",labelEn:"Left",x:0,y:.5},{key:"center",labelZh:"中心",labelEn:"Center",x:.5,y:.5},{key:"top-left",labelZh:"左上",labelEn:"Top left",x:0,y:0},{key:"top",labelZh:"上",labelEn:"Top",x:.5,y:0},{key:"right",labelZh:"右",labelEn:"Right",x:1,y:.5},{key:"bottom",labelZh:"下",labelEn:"Bottom",x:.5,y:1}],Ts=({value:e,onChange:n,showPresets:s=!0,showHistory:a=!0,presetCategories:o,customPresets:l,compact:d=!1,inline:m=!1,onSavePreset:x,onDeletePreset:h})=>{const{language:p}=je(),{addGradient:j}=qi(),[f,M]=i.useState(e||cn),[S,T]=i.useState(0),[v,P]=i.useState(null),[ne,Q]=i.useState(!1),$=i.useRef(null);i.useEffect(()=>{e&&M(e)},[e]);const w=i.useCallback(_=>{M(_),n==null||n(_),j(_)},[n,j]),g=i.useCallback(_=>{w(_.config)},[w]),c=i.useCallback(_=>{const q={...f,..._};w(q)},[f,w]),C=i.useCallback(_=>{if(f.type!==_)if(_==="linear"){const q={type:"linear",angle:90,stops:f.stops};w(q)}else{const q={type:"radial",centerX:.5,centerY:.5,stops:f.stops};w(q)}},[f,w]),N=i.useCallback((_,q)=>{const X=[...f.stops];X[_]={...X[_],...q},X.sort((ce,ge)=>ce.offset-ge.offset);const le=X.findIndex(ce=>ce.color===(q.color??f.stops[_].color));le!==-1&&le!==S&&T(le),c({stops:X})},[f.stops,S,c]),Y=i.useCallback(()=>{if(f.stops.length>=8)return;const _=.5,X=[...f.stops,{color:"#888888",offset:_}].sort((le,ce)=>le.offset-ce.offset);c({stops:X}),T(X.findIndex(le=>le.offset===_))},[f.stops,c]),se=i.useCallback(_=>{if(f.stops.length<=2)return;const q=f.stops.filter((X,le)=>le!==_);c({stops:q}),T(Math.min(S,q.length-1))},[f.stops,S,c]),B=i.useCallback((_,q)=>{if(!$.current)return;const X=$.current.getBoundingClientRect(),ce=Math.max(0,Math.min(_.clientX-X.left,X.width))/X.width;N(q,{offset:ce})},[N]),he=i.useCallback((_,q)=>{_.preventDefault(),_.stopPropagation(),T(q);const X=_.clientX,le=_.clientY;let ce=!1;const ge=3,k=Me=>{const Oe=Math.abs(Me.clientX-X),xe=Math.abs(Me.clientY-le);(Oe>ge||xe>ge)&&(ce=!0,Q(!0),B(Me,q))},Te=()=>{document.removeEventListener("mousemove",k),document.removeEventListener("mouseup",Te),ce||P(q),setTimeout(()=>{Q(!1)},0)};document.addEventListener("mousemove",k),document.addEventListener("mouseup",Te)},[B]),V=i.useCallback(_=>{if(ne||f.stops.length>=8||_.target!==$.current||!$.current)return;const X=$.current.getBoundingClientRect(),le=_.clientX-X.left,ce=Math.max(0,Math.min(le/X.width,1)),ge=[...f.stops].sort((xe,Ve)=>xe.offset-Ve.offset);let k=ge[0];for(let xe=0;xe<ge.length-1;xe++)if(ge[xe].offset<=ce&&ge[xe+1].offset>=ce){k=ge[xe];break}const Te=k.color,Me=[...f.stops,{color:Te,offset:ce}].sort((xe,Ve)=>xe.offset-Ve.offset);c({stops:Me});const Oe=Me.findIndex(xe=>xe.offset===ce);T(Oe)},[ne,f.stops,c]);i.useMemo(()=>ut(f),[f]),i.useMemo(()=>{const _=[{key:"basic",label:p==="zh"?"基础":"Basic"},{key:"colorful",label:p==="zh"?"多彩":"Colorful"},{key:"sunset",label:p==="zh"?"日落":"Sunset"},{key:"nature",label:p==="zh"?"自然":"Nature"},{key:"metal",label:p==="zh"?"金属":"Metal"}];return o?_.filter(q=>o.includes(q.key)):_},[p,o]);const F=i.useMemo(()=>l?l.length>0&&typeof l[0]=="string"?l.map((_,q)=>({id:`custom-${q}`,name:`Custom ${q+1}`,nameZh:`自定义 ${q+1}`,category:"custom",config:Ki(_),css:_})):l:An,[l]),L=i.useCallback(()=>{var X;if(f.type!=="radial")return null;const{centerX:_,centerY:q}=f;return(X=os.find(le=>Math.abs(le.x-_)<.01&&Math.abs(le.y-q)<.01))==null?void 0:X.key},[f]),ie=i.useMemo(()=>l&&l.length>0&&typeof l[0]=="string",[l]),ke=i.useMemo(()=>ut(f),[f]),Pe=i.useCallback(_=>ke===_,[ke]),mt=()=>{const _=An.slice(0,10),q=ie?F:[];return t.jsxs("div",{className:"ge-quick-presets",children:[t.jsx("div",{className:"ge-quick-presets-header",children:t.jsx("span",{className:"ge-quick-presets-title",children:p==="zh"?"预设":"Presets"})}),t.jsxs("div",{className:"ge-quick-presets-grid",children:[q.map((X,le)=>{const ce=X.css||ut(X.config);return t.jsx(ae,{content:p==="zh"?X.nameZh:X.name,showArrow:!1,children:t.jsxs("button",{className:z("ge-quick-preset-item ge-quick-preset-item--custom",{"ge-quick-preset-item--selected":Pe(ce)}),onClick:()=>g(X),children:[t.jsx("div",{className:"ge-quick-preset-preview",style:{background:ce}}),h&&t.jsx("button",{className:"ge-quick-preset-delete",onClick:ge=>{ge.stopPropagation(),h(le)},children:"×"})]})},X.id)}),_.map(X=>{const le=ut(X.config);return t.jsx(ae,{content:p==="zh"?X.nameZh:X.name,showArrow:!1,children:t.jsx("button",{className:z("ge-quick-preset-item",{"ge-quick-preset-item--selected":Pe(le)}),onClick:()=>g(X),children:t.jsx("div",{className:"ge-quick-preset-preview",style:{background:le}})})},X.id)})]})]})},Re=()=>t.jsxs("div",{className:z("ge-custom-editor",{"ge-custom-editor--inline":m}),children:[t.jsx("div",{className:"ge-type-section",children:t.jsxs("div",{className:"ge-type-buttons",children:[t.jsx("button",{className:z("ge-type-btn",{active:f.type==="linear"}),onClick:()=>C("linear"),children:p==="zh"?"线性":"Linear"}),t.jsx("button",{className:z("ge-type-btn",{active:f.type==="radial"}),onClick:()=>C("radial"),children:p==="zh"?"径向":"Radial"})]})}),t.jsxs("div",{className:"ge-color-section",children:[t.jsxs("div",{className:"ge-section-header",children:[t.jsx("span",{className:"ge-section-title",children:p==="zh"?"颜色":"Colors"}),t.jsxs("div",{className:"ge-stop-actions",children:[t.jsx(ae,{content:p==="zh"?"添加色标":"Add stop",showArrow:!1,children:t.jsx("button",{className:"ge-action-btn",onClick:Y,disabled:f.stops.length>=8,children:"+"})}),t.jsx(ae,{content:p==="zh"?"删除色标":"Remove stop",showArrow:!1,children:t.jsx("button",{className:"ge-action-btn",onClick:()=>se(S),disabled:f.stops.length<=2,children:"−"})})]})]}),t.jsx("div",{className:"ge-gradient-bar-wrapper",children:t.jsx("div",{ref:$,className:"ge-gradient-bar",style:{background:`linear-gradient(90deg, ${f.stops.map(_=>`${_.color} ${Math.round(_.offset*100)}%`).join(", ")})`},onClick:V,children:f.stops.map((_,q)=>t.jsxs(Ne,{open:v===q,onOpenChange:X=>P(X?q:null),children:[t.jsx(_e,{asChild:!0,children:t.jsx("button",{className:z("ge-stop-handle",{selected:S===q}),style:{left:`${_.offset*100}%`,backgroundColor:_.color},onMouseDown:X=>{he(X,q)}})}),t.jsx(Ee,{children:t.jsx(ze,{padding:4,className:"ge-color-picker-popover "+Ie,children:t.jsx(_t,{value:_.color,onChange:X=>N(q,{color:X}),showAlpha:!1,showEyeDropper:!0,showPresets:!0,showRecentColors:!0,showHexInput:!0})})})]},q))})})]}),f.type==="radial"&&t.jsxs("div",{className:"ge-origin-section",children:[t.jsx("span",{className:"ge-section-title",children:p==="zh"?"原点":"Origin"}),t.jsx("div",{className:"ge-origin-buttons",children:os.map(_=>t.jsx("button",{className:z("ge-origin-btn",{active:L()===_.key}),onClick:()=>c({centerX:_.x,centerY:_.y}),children:p==="zh"?_.labelZh:_.labelEn},_.key))})]}),f.type==="linear"&&t.jsxs("div",{className:"ge-angle-section",children:[t.jsxs("div",{className:"ge-section-header",children:[t.jsx("span",{className:"ge-section-title",children:p==="zh"?"角度":"Angle"}),t.jsxs("span",{className:"ge-angle-value",children:[f.angle,"°"]})]}),t.jsx("input",{type:"range",min:0,max:360,value:f.angle,onChange:_=>c({angle:Number(_.target.value)}),className:"ge-angle-slider"})]}),x&&t.jsx("div",{className:"ge-save-section",children:t.jsx("button",{className:"ge-save-btn",onClick:x,children:p==="zh"?"保存":"Save"})}),mt()]});return d||m?t.jsx("div",{className:z("gradient-editor",{"gradient-editor--compact":d,"gradient-editor--inline":m}),children:Re()}):t.jsx("div",{className:"gradient-editor",children:Re()})},vn=ms.CUSTOM_GRADIENTS,Qi=({value:e,onChange:n,inline:s=!1})=>{const{language:a}=je(),{confirm:o,confirmDialog:l}=zn(),[d,m]=i.useState([]),[x,h]=i.useState(e||cn);i.useEffect(()=>{let M=!0;return St.get(vn).then(S=>{M&&S&&m(S)}).catch(S=>{console.warn("Failed to load gradient data:",S)}),()=>{M=!1}},[]),i.useEffect(()=>{e&&h(e)},[e]);const p=i.useCallback(M=>{h(M),n==null||n(M)},[n]),j=i.useCallback(()=>{const M=ut(x),T=[{id:`custom-${Date.now()}`,css:M},...d].slice(0,8);m(T),St.set(vn,T).catch(v=>{console.warn("Failed to save custom gradients:",v)})},[x,d]),f=i.useCallback(async M=>{const S=d[M];if(!S||!await o({title:a==="zh"?"确认删除渐变预设":"Delete Gradient Preset",description:a==="zh"?"确定要删除这个自定义渐变预设吗?":"Are you sure you want to delete this custom gradient preset?",confirmText:a==="zh"?"删除":"Delete",cancelText:a==="zh"?"取消":"Cancel",danger:!0}))return;const v=d.filter(P=>P.id!==S.id);m(v),St.set(vn,v).catch(P=>{console.warn("Failed to save custom gradients:",P)})},[o,d,a]);return t.jsxs(t.Fragment,{children:[t.jsx(Ts,{value:x,onChange:p,showPresets:!0,showHistory:!0,inline:s,customPresets:d.map(M=>M.css),onSavePreset:j,onDeletePreset:f}),l]})},Ji=i.lazy(()=>De(()=>import("./ai-chat-B-XdoWBQ.js").then(e=>e.sZ),__vite__mapDeps([0]),import.meta.url).then(e=>({default:e.MediaLibraryModal}))),el=[{value:"stretch",labelZh:"拉伸",labelEn:"Stretch",icon:"⬌"},{value:"tile",labelZh:"平铺",labelEn:"Tile",icon:"⊞"},{value:"fit",labelZh:"适应",labelEn:"Fit",icon:"⊡"}],tl=({value:e,onChange:n,onOpenMediaLibrary:s,externalMediaLibraryControl:a=!1})=>{const{language:o}=je(),[l,d]=i.useState(e||fs),[m,x]=i.useState(!1),[h,p]=i.useState(!1),j=i.useRef(null);i.useEffect(()=>{e&&d(e)},[e]);const f=i.useCallback(w=>{const g={...l,...w};d(g),n==null||n(g)},[l,n]),M=i.useMemo(()=>Qs(w=>{n==null||n(w)},300),[n]),S=i.useCallback(w=>{const g={...l,...w};d(g),M(g)},[l,M]),T=i.useCallback((w,g,c,C,N=1)=>{const Y=parseFloat(g);if(isNaN(Y))return;const se=Math.max(c,Math.min(C,Y)),B=N===1?se:se/N;f({[w]:B})},[f]),v=i.useCallback(w=>{f({imageUrl:w.url}),x(!1)},[f]),P=i.useCallback(async w=>{var N;const g=(N=w.target.files)==null?void 0:N[0];if(!g)return;if(!g.type.startsWith("image/")){W.warning(o==="zh"?"请选择图片文件":"Please select an image file");return}if(g.size>25*1024*1024){W.warning(o==="zh"?"图片大小不能超过 25MB":"Image size cannot exceed 25MB");return}let c=g;if(g.size>10*1024*1024){const Y=Js(g.size/1048576),se=W.loading({content:o==="zh"?`正在压缩图片 (${(g.size/1024/1024).toFixed(1)}MB)...`:`Compressing image (${(g.size/1024/1024).toFixed(1)}MB)...`,duration:0,placement:"top"});try{c=await eo(g,Y.targetSizeMB),W.close(se),W.success({content:o==="zh"?`压缩完成: ${(g.size/1024/1024).toFixed(1)}MB → ${(c.size/1024/1024).toFixed(1)}MB`:`Compressed: ${(g.size/1024/1024).toFixed(1)}MB → ${(c.size/1024/1024).toFixed(1)}MB`,duration:2})}catch(B){W.close(se),console.error("[ImageFillPanel] Compression failed:",B),W.warning(o==="zh"?"图片压缩失败":"Image compression failed");return}}const C=new FileReader;C.onload=Y=>{var B;const se=(B=Y.target)==null?void 0:B.result;f({imageUrl:se})},C.readAsDataURL(c),w.target.value=""},[o,f]),ne=i.useCallback(()=>{var w;(w=j.current)==null||w.click()},[]),Q=i.useCallback(()=>{a&&s?s():x(!0)},[a,s]),$=()=>l.imageUrl?t.jsxs("div",{className:"ifp-image-preview",children:[t.jsx("img",{src:l.imageUrl,alt:"Fill preview"}),t.jsx(ae,{content:o==="zh"?"移除图片":"Remove image",showArrow:!1,children:t.jsx("button",{className:"ifp-image-remove",onClick:()=>f({imageUrl:""}),children:"×"})})]}):t.jsxs("div",{className:"ifp-image-placeholder",children:[t.jsx(bs,{size:32,className:"ifp-placeholder-icon"}),t.jsx("span",{className:"ifp-placeholder-text",children:o==="zh"?"选择图片":"Select Image"})]});return t.jsxs("div",{className:"image-fill-panel",children:[t.jsx("input",{ref:j,type:"file",accept:"image/*",style:{display:"none"},onChange:P}),t.jsxs("div",{className:"ifp-image-section",children:[t.jsx("div",{className:"ifp-image-container",onClick:()=>!l.imageUrl&&Q(),children:$()}),t.jsxs("div",{className:"ifp-image-actions",children:[t.jsxs("button",{className:"ifp-action-btn ifp-action-btn--primary",onClick:Q,children:[t.jsx(to,{size:14}),t.jsx("span",{children:o==="zh"?"素材库":"Library"})]}),t.jsxs("button",{className:"ifp-action-btn",onClick:ne,children:[t.jsx(no,{size:14}),t.jsx("span",{children:o==="zh"?"上传":"Upload"})]})]})]}),l.imageUrl&&t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"ifp-control-section",children:[t.jsx("div",{className:"ifp-section-title",children:o==="zh"?"平铺模式":"Fill Mode"}),t.jsx("div",{className:"ifp-mode-buttons",children:el.map(w=>t.jsx(ae,{content:o==="zh"?w.labelZh:w.labelEn,showArrow:!1,children:t.jsxs("button",{className:z("ifp-mode-btn",{active:l.mode===w.value}),onClick:()=>f({mode:w.value}),children:[t.jsx("span",{className:"ifp-mode-icon",children:w.icon}),t.jsx("span",{className:"ifp-mode-label",children:o==="zh"?w.labelZh:w.labelEn})]})},w.value))})]}),t.jsxs("div",{className:"ifp-advanced-section",children:[t.jsxs("button",{className:"ifp-advanced-toggle",onClick:()=>p(!h),children:[t.jsx("span",{children:o==="zh"?"高级设置":"Advanced"}),h?t.jsx(so,{size:14}):t.jsx(gs,{size:14})]}),h&&t.jsxs("div",{className:"ifp-advanced-content",children:[t.jsxs("div",{className:"ifp-control-row",children:[t.jsx("label",{className:"ifp-control-label",children:o==="zh"?"缩放":"Scale"}),t.jsxs("div",{className:"ifp-control-input",children:[t.jsx("input",{type:"range",min:50,max:200,value:(l.scale??1)*100,onChange:w=>S({scale:Number(w.target.value)/100}),className:"ifp-slider"}),t.jsxs("div",{className:"ifp-control-value-wrapper",children:[t.jsx("input",{type:"number",className:"ifp-control-value-input",value:Math.round((l.scale??1)*100),min:50,max:200,onChange:w=>T("scale",w.target.value,50,200,100)}),t.jsx("span",{className:"ifp-control-unit",children:"%"})]})]})]}),t.jsxs("div",{className:"ifp-control-row",children:[t.jsx("label",{className:"ifp-control-label",children:o==="zh"?"X 偏移":"Offset X"}),t.jsxs("div",{className:"ifp-control-input",children:[t.jsx("input",{type:"range",min:-100,max:100,value:(l.offsetX??0)*100,onChange:w=>S({offsetX:Number(w.target.value)/100}),className:"ifp-slider"}),t.jsxs("div",{className:"ifp-control-value-wrapper",children:[t.jsx("input",{type:"number",className:"ifp-control-value-input",value:Math.round((l.offsetX??0)*100),min:-100,max:100,onChange:w=>T("offsetX",w.target.value,-100,100,100)}),t.jsx("span",{className:"ifp-control-unit",children:"%"})]})]})]}),t.jsxs("div",{className:"ifp-control-row",children:[t.jsx("label",{className:"ifp-control-label",children:o==="zh"?"Y 偏移":"Offset Y"}),t.jsxs("div",{className:"ifp-control-input",children:[t.jsx("input",{type:"range",min:-100,max:100,value:(l.offsetY??0)*100,onChange:w=>S({offsetY:Number(w.target.value)/100}),className:"ifp-slider"}),t.jsxs("div",{className:"ifp-control-value-wrapper",children:[t.jsx("input",{type:"number",className:"ifp-control-value-input",value:Math.round((l.offsetY??0)*100),min:-100,max:100,onChange:w=>T("offsetY",w.target.value,-100,100,100)}),t.jsx("span",{className:"ifp-control-unit",children:"%"})]})]})]}),t.jsxs("div",{className:"ifp-control-row",children:[t.jsx("label",{className:"ifp-control-label",children:o==="zh"?"旋转":"Rotation"}),t.jsxs("div",{className:"ifp-control-input",children:[t.jsx("input",{type:"range",min:0,max:360,value:l.rotation??0,onChange:w=>S({rotation:Number(w.target.value)}),className:"ifp-slider"}),t.jsxs("div",{className:"ifp-control-value-wrapper",children:[t.jsx("input",{type:"number",className:"ifp-control-value-input",value:l.rotation??0,min:0,max:360,onChange:w=>T("rotation",w.target.value,0,360,1)}),t.jsx("span",{className:"ifp-control-unit",children:"°"})]})]})]}),t.jsx("button",{className:"ifp-reset-btn",onClick:()=>f({scale:1,offsetX:0,offsetY:0,rotation:0}),children:o==="zh"?"重置":"Reset"})]})]})]}),!a&&m&&t.jsx(i.Suspense,{fallback:null,children:t.jsx(Ji,{isOpen:m,onClose:()=>x(!1),mode:ys.SELECT,filterType:xs.IMAGE,onSelect:v,selectButtonText:o==="zh"?"使用此图片":"Use this image"})})]})},nl=[{value:"solid",labelZh:"纯色",labelEn:"Solid"},{value:"gradient",labelZh:"渐变",labelEn:"Gradient"},{value:"image",labelZh:"图片",labelEn:"Image"}],sl=({value:e,onSolidChange:n,onOpacityChange:s,onGradientChange:a,onImageChange:o,onFillTypeChange:l,showClose:d=!1,onClose:m,onOpenMediaLibrary:x})=>{const{language:h}=je(),p=i.useMemo(()=>e?Yt(e)?oo(e):ht(e)?e:{type:"solid",solid:{color:"#FFFFFF"}}:{type:"solid",solid:{color:"#FFFFFF"}},[e]),[j,f]=i.useState(p.type);i.useEffect(()=>{f(p.type)},[p.type]);const[M,S]=i.useState(p.gradient||cn),[T,v]=i.useState(p.image||fs);i.useEffect(()=>{p.gradient&&S(p.gradient)},[p.gradient]),i.useEffect(()=>{p.image&&v(p.image)},[p.image]);const P=i.useCallback(g=>{f(g)},[]),ne=i.useCallback(g=>{l==null||l("solid"),n==null||n(g)},[n,l]),Q=i.useCallback(g=>{S(g),l==null||l("gradient"),a==null||a(g)},[a,l]),$=i.useCallback(g=>{v(g),l==null||l("image"),o==null||o(g)},[o,l]),w=i.useMemo(()=>Yt(e)?e:ht(e)&&e.solid?e.solid.color:"#FFFFFF",[e]);return t.jsxs("div",{className:"fill-panel",children:[t.jsxs("div",{className:"fill-panel__header",children:[t.jsx("span",{className:"fill-panel__title",children:h==="zh"?"填充":"Fill"}),d&&t.jsx("button",{className:"fill-panel__close",onClick:m,children:"×"})]}),t.jsx("div",{className:"fill-panel__tabs",children:nl.map(g=>t.jsx("button",{className:z("fill-panel__tab",{active:j===g.value}),onClick:()=>P(g.value),children:h==="zh"?g.labelZh:g.labelEn},g.value))}),t.jsxs("div",{className:"fill-panel__content",children:[j==="solid"&&t.jsx("div",{className:"fill-panel__solid",children:t.jsx(_t,{value:w,onChange:ne,onOpacityChange:s})}),j==="gradient"&&t.jsx(Qi,{value:M,onChange:Q}),j==="image"&&t.jsx(tl,{value:T,onChange:$,onOpenMediaLibrary:x,externalMediaLibraryControl:!!x})]})]})},ol=i.lazy(()=>De(()=>import("./index-CRuDVxTu.js"),__vite__mapDeps([0,1]),import.meta.url).then(e=>({default:e.MediaLibraryModal}))),al=({board:e,currentColor:n,title:s,children:a})=>{const{language:o}=je(),[l,d]=i.useState(!1),[m,x]=i.useState(!1),{hexColor:h,opacity:p}=i.useMemo(()=>{var $;if(!n)return{hexColor:void 0,opacity:100};if(Yt(n)){const w=pt(n),g=Nt(n);return{hexColor:w,opacity:g}}if(ht(n))switch(n.type){case"solid":if(n.solid){const w=pt(n.solid.color),g=Nt(n.solid.color);return{hexColor:w,opacity:g}}break;case"gradient":if(($=n.gradient)!=null&&$.stops[0])return{hexColor:n.gradient.stops[0].color,opacity:100};break;case"image":return{hexColor:"#888888",opacity:100}}return{hexColor:void 0,opacity:100}},[n]),j=!h||hs(p)?t.jsx(ao,{}):void 0,f=i.useCallback($=>{xi(e,$),$i(e,$)},[e]),M=i.useCallback($=>{gi(e,$)},[e]),S=i.useCallback($=>{Oi(e,$)},[e]),T=i.useCallback($=>{Jn(e,$)},[e]),v=i.useCallback($=>{Ui(e,$)},[e]),P=i.useCallback(()=>{d(!1)},[]),ne=i.useCallback(()=>{x(!0)},[]),Q=i.useCallback($=>{Jn(e,{imageUrl:$.url,mode:"stretch",scale:1,offsetX:0,offsetY:0,rotation:0}),x(!1)},[e]);return t.jsxs(Ne,{sideOffset:12,crossAxisOffset:40,open:l,onOpenChange:$=>{!$&&m||d($)},placement:"left",children:[t.jsx(_e,{asChild:!0,children:t.jsx(oe,{className:z("property-button"),visible:!0,icon:j,type:"button",tooltip:s,"aria-label":s,onPointerUp:()=>{d(!l)},children:!j&&a})}),t.jsx(Ee,{children:t.jsx(ze,{padding:0,className:z(`${Ie}`,"fill-setting"),children:t.jsx(sl,{value:n,onSolidChange:f,onOpacityChange:M,onGradientChange:S,onImageChange:T,onFillTypeChange:v,showClose:!0,onClose:P,onOpenMediaLibrary:ne})})}),m&&t.jsx(i.Suspense,{fallback:null,children:t.jsx(ol,{isOpen:m,onClose:()=>x(!1),mode:ys.SELECT,filterType:xs.IMAGE,onSelect:Q,selectButtonText:o==="zh"?"使用此图片":"Use this image"})})]})},il=({board:e,currentRadius:n,title:s,selectionRect:a})=>{const[o,l]=i.useState(!1),[d,m]=i.useState({top:0,left:0}),[x,h]=i.useState(""),p=i.useRef(null),j=i.useRef(null),f=te.getBoardContainer(e),{t:M}=je(),S=s||M("toolbar.cornerRadius")||"圆角",T=n??0;i.useEffect(()=>{h(String(T))},[T]),i.useEffect(()=>{if(o&&p.current){const g=p.current.getBoundingClientRect(),c=220,C=8;let N=g.left+g.width/2-c/2,Y=g.bottom+C;const se=window.innerWidth,B=window.innerHeight;N+c>se-16&&(N=se-c-16),N<16&&(N=16),Y+40>B-16&&(Y=g.top-40-C),m({left:N,top:Y})}},[o]),i.useEffect(()=>{if(!o)return;const g=C=>{const N=C.target;j.current&&j.current.contains(N)||p.current&&p.current.contains(N)||N.closest(".popup-toolbar")!==null||l(!1)},c=setTimeout(()=>{document.addEventListener("mousedown",g)},100);return()=>{clearTimeout(c),document.removeEventListener("mousedown",g)}},[o]);const v=i.useCallback(g=>{const c=Math.max(0,Math.min(100,g));Se(e).filter(N=>qe.isPenPath(N)).forEach(N=>{const Y=e.children.findIndex(se=>se.id===N.id);Y>=0&&K.setNode(e,{cornerRadius:c},[Y])})},[e]),P=i.useCallback(g=>{h(String(g)),v(g)},[v]),ne=i.useCallback(g=>{h(g.target.value)},[]),Q=i.useCallback(()=>{const g=parseInt(x,10);if(isNaN(g))h(String(T));else{const c=Math.max(0,Math.min(100,g));h(String(c)),v(c)}},[x,T,v]),$=i.useCallback(g=>{g.key==="Enter"&&g.target.blur()},[]),w=i.useCallback(()=>{l(!o)},[o]);return t.jsxs(t.Fragment,{children:[t.jsx(oe,{ref:p,className:z("property-button","corner-radius-button",{"is-active":o}),visible:!0,type:"button",tooltip:S,"aria-label":S,onPointerUp:w,children:t.jsx("svg",{viewBox:"0 0 24 24",width:"18",height:"18",children:t.jsx("path",{d:"M4 4 L4 14 Q4 20 10 20 L20 20",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})})}),o&&f&&io.createPortal(t.jsx("div",{ref:j,className:z(Ie,"corner-radius-panel"),style:{position:"fixed",top:d.top,left:d.left,zIndex:5e3},onPointerDown:g=>g.stopPropagation(),onMouseDown:g=>g.stopPropagation(),children:t.jsx(ze,{padding:2,className:"corner-radius-setting-compact",children:t.jsxs("div",{className:"corner-radius-row",children:[t.jsx("span",{className:"corner-radius-label",children:S}),t.jsx("div",{className:"corner-radius-slider",children:t.jsx(us,{value:T,min:0,max:100,step:1,onChange:g=>P(g),label:!1})}),t.jsx("input",{type:"text",className:"corner-radius-input",value:x,onChange:ne,onBlur:Q,onKeyDown:$}),t.jsx("span",{className:"corner-radius-unit",children:"%"})]})})}),f)]})},ll=(e,n)=>{try{return st(e,[n],!1)}catch{return null}},as=(e,n,s,a,o,l)=>{const d=e.children.findIndex(S=>S.id===n.id);if(d<0)return;const m=ll(e,n);if(!m)return;const x=(m.x-s.x)/s.width,h=(m.y-s.y)/s.height,p=a.x+x*a.width,j=a.y+h*a.height,f=m.width*o,M=m.height*l;if(Be(n)){const S=[[p,j],[p+f,j+M]];K.setNode(e,{points:S},[d])}else if(U.isDrawElement(n)){const S=[[p,j],[p+f,j+M]];K.setNode(e,{points:S},[d])}else if(Le.isMindElement(e,n)){const S=[[p,j],[p+f,j+M]];K.setNode(e,{points:S},[d])}else if(at.isFreehand(n)){const T=n.points.map(v=>{const P=(v[0]-s.x)/s.width,ne=(v[1]-s.y)/s.height;return[a.x+P*a.width,a.y+ne*a.height]});K.setNode(e,{points:T},[d])}else if(qe.isPenPath(n)){const T=n.anchors.map(P=>{const ne=[P.point[0]*o,P.point[1]*l],Q=P.handleIn?[P.handleIn[0]*o,P.handleIn[1]*l]:void 0,$=P.handleOut?[P.handleOut[0]*o,P.handleOut[1]*l]:void 0;return{...P,point:ne,handleIn:Q,handleOut:$}}),v=[p,j];K.setNode(e,{points:[v,v],anchors:T},[d])}},rl=({board:e})=>{const{language:n}=je(),s=n==="zh",a=Se(e),[o,l]=i.useState(!0),[d,m]=i.useState(""),[x,h]=i.useState(""),[p,j]=i.useState(1),[f,M]=i.useState(!1),S=i.useRef(null),T=te.getBoardContainer(e),v=a.length>0?st(e,a,!1):null;i.useEffect(()=>{v&&(S.current?(m(Math.round(S.current.width).toString()),h(Math.round(S.current.height).toString()),S.current=null):(m(Math.round(v.width).toString()),h(Math.round(v.height).toString())),j(v.width/v.height))},[v==null?void 0:v.width,v==null?void 0:v.height]);const P=i.useCallback(g=>{const c=g.target.value;if(m(c),o&&v){const C=parseFloat(c);if(!isNaN(C)&&C>0){const N=Math.round(C/p);h(N.toString())}}},[o,p,v]),ne=i.useCallback(g=>{const c=g.target.value;if(h(c),o&&v){const C=parseFloat(c);if(!isNaN(C)&&C>0){const N=Math.round(C*p);m(N.toString())}}},[o,p,v]),Q=i.useCallback(()=>{if(!v||a.length===0)return;const g=parseFloat(d),c=parseFloat(x);if(isNaN(g)||isNaN(c)||g<=0||c<=0){m(Math.round(v.width).toString()),h(Math.round(v.height).toString());return}if(Math.abs(g-v.width)<.5&&Math.abs(c-v.height)<.5)return;S.current={width:g,height:c};const C=g/v.width,N=c/v.height,Y={x:v.x,y:v.y,width:g,height:c};a.forEach(se=>{as(e,se,v,Y,C,N)})},[e,a,v,d,x]),$=i.useCallback(g=>{if(!v||a.length===0)return;const c=g.width,C=g.height;m(c.toString()),h(C.toString()),S.current={width:c,height:C};const N=c/v.width,Y=C/v.height,se={x:v.x,y:v.y,width:c,height:C};a.forEach(B=>{as(e,B,v,se,N,Y)}),j(c/C),M(!1)},[e,a,v]),w=i.useCallback(g=>{g.key==="Enter"?(Q(),g.target.blur()):g.key==="Escape"&&(v&&(m(Math.round(v.width).toString()),h(Math.round(v.height).toString())),g.target.blur())},[Q,v]);return v?t.jsxs("div",{className:"size-input-container",children:[t.jsxs("div",{className:"size-input-group",children:[t.jsx("span",{className:"size-input-label",children:"W"}),t.jsx("input",{type:"text",inputMode:"numeric",pattern:"[0-9]*",className:"size-input",value:d,onChange:P,onBlur:Q,onKeyDown:w})]}),t.jsx(ae,{content:o?"解锁比例":"锁定比例",showArrow:!1,children:t.jsx("button",{className:`size-lock-button ${o?"locked":""}`,onClick:()=>l(!o),children:o?t.jsx(lo,{}):t.jsx(ro,{})})}),t.jsxs("div",{className:"size-input-group",children:[t.jsx("span",{className:"size-input-label",children:"H"}),t.jsx("input",{type:"text",inputMode:"numeric",pattern:"[0-9]*",className:"size-input",value:x,onChange:ne,onBlur:Q,onKeyDown:w})]}),t.jsxs(Ne,{open:f,onOpenChange:M,placement:"bottom-end",sideOffset:8,children:[t.jsx(ae,{content:s?"常用尺寸":"Preset Sizes",showArrow:!1,children:t.jsx(_e,{className:`size-preset-button ${f?"active":""}`,onClick:()=>M(!f),children:t.jsx(gs,{size:12})})}),t.jsx(Ee,{container:T,children:t.jsx("div",{className:"size-preset-panel",children:ni.map(g=>t.jsxs("div",{className:"size-preset-category",children:[t.jsx("div",{className:"size-preset-category-label",children:s?g.category:g.categoryEn}),g.items.map(c=>t.jsxs("button",{className:"size-preset-item",onClick:()=>$(c),children:[t.jsx("span",{className:"size-preset-item-label",children:s?c.label:c.labelEn}),t.jsxs("span",{className:"size-preset-item-size",children:[c.width," x ",c.height]})]},`${c.width}x${c.height}-${c.label}`))]},g.category))})})]})]}):null},cl=({board:e,title:n})=>{const{appState:s,setAppState:a}=vs();return t.jsx(oe,{className:z("property-button"),visible:!0,icon:t.jsx(uo,{}),type:"button",tooltip:n,"aria-label":n,onPointerUp:()=>{const o=Se(e)[0],l=co(o);gn.getLinkElement(l)||gn.wrapLink(l,"链接",""),setTimeout(()=>{const x=gn.getLinkElement(l)[0],h=si.toDOMNode(l,x);a({...s,linkState:{editor:l,targetDom:h,targetElement:x,isEditing:!0,isHovering:!1,isHoveringOrigin:!1}})},0)}})},Gt=8,dl=60,ul=600,is=24,hl='16px -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif';let wn=null,on=null;function pl(){if(wn||(wn=document.createElement("canvas"),on=wn.getContext("2d")),!on)throw new Error("Failed to get canvas context");return on.font=hl,on}function kn(e){return pl().measureText(e).width}function ml(e){const n=e.split(`
3
- `);let s=0;for(const m of n){const x=kn(m);s=Math.max(s,x)}const a=Math.min(ul-Gt*2,Math.max(dl-Gt*2,s)),o=a+Gt*2;let l=0;for(const m of n){if(m.length===0){l+=1;continue}if(kn(m)<=a)l+=1;else{let h=0,p=1;for(const j of m){const f=kn(j);h+f>a?(p++,h=f):h+=f}l+=p}}const d=Math.max(is+Gt*2,l*is+Gt*2);return{width:o,height:d}}function fl(e){switch(e){case"ai-input":return t.jsx(yo,{size:12});case"image":return t.jsx(bs,{size:12});case"video":return t.jsx(xo,{size:12});default:return null}}function gl(e,n){return{"ai-input":{zh:"AI输入",en:"AI Input"},image:{zh:"图片",en:"Image"},video:{zh:"视频",en:"Video"},preset:{zh:"预设",en:"Preset"}}[e][n]}const xl=({board:e,language:n,title:s})=>{const[a,o]=i.useState(!1),[l,d]=i.useState(0),{history:m,addHistory:x,removeHistory:h}=ho({deduplicateWithPresets:!1}),{confirm:p,confirmDialog:j}=zn({container:e?te.getBoardContainer(e):null}),f=i.useRef(null),[M,S]=i.useState([]),[T,v]=i.useState([]);i.useEffect(()=>{a&&(S(po()),v(mo()))},[a]);const P=i.useMemo(()=>{const c=fo[n].map((F,L)=>({id:`preset_${L}`,content:F,source:"preset"})),C=m.map(F=>({id:F.id,content:F.content,source:"ai-input",timestamp:F.timestamp})),N=M.map(F=>({id:F.id,content:F.content,source:"image",timestamp:F.timestamp})),Y=T.map(F=>({id:F.id,content:F.content,source:"video",timestamp:F.timestamp})),se=[...C,...N,...Y];se.sort((F,L)=>(L.timestamp||0)-(F.timestamp||0));const B=new Set,he=[];for(const F of se){const L=F.content.trim();B.has(L)||(B.add(L),he.push(F))}const V=c.filter(F=>!B.has(F.content.trim()));return[...he,...V]},[n,m,M,T]),{historyPrompts:ne,presetPrompts:Q}=i.useMemo(()=>{const c=P.filter(N=>N.source!=="preset"),C=P.filter(N=>N.source==="preset");return{historyPrompts:c,presetPrompts:C}},[P]),$=i.useCallback((c,C)=>c==="history"?C:ne.length+C,[ne.length]);i.useEffect(()=>{a&&d(0)},[a]);const w=i.useCallback(c=>{x(c.content),o(!1);const C=Se(e);if(C.length===0)return;const N=B=>({type:"paragraph",children:[{text:B}]}),{width:Y,height:se}=ml(c.content);for(const B of C){const he=e.children.findIndex(F=>F.id===B.id);if(he<0)continue;const V={};if(Le.isMindElement(e,B)){const F=[N(c.content)];K.setNode(e,{data:F},[he]);continue}if(U.isText&&U.isText(B)){if(V.text=N(c.content),"points"in B&&Array.isArray(B.points)&&B.points.length>=2){const F=B.points,[L]=F,ie=[L,[L[0]+Y,L[1]+se]];V.points=ie}K.setNode(e,V,[he]);continue}if(U.isDrawElement(B)&&Pn([B])){if("text"in B&&B.text){if(V.text=N(c.content),"points"in B&&Array.isArray(B.points)&&B.points.length>=2){const F=B.points,[L]=F,ie=[L,[L[0]+Y,L[1]+se]];V.points=ie}K.setNode(e,V,[he]);continue}if("data"in B&&Array.isArray(B.data)){if(V.data=[N(c.content)],"points"in B&&Array.isArray(B.points)&&B.points.length>=2){const F=B.points,[L]=F,ie=[L,[L[0]+Y,L[1]+se]];V.points=ie}K.setNode(e,V,[he]);continue}}if("text"in B&&B.text){if(V.text=N(c.content),"points"in B&&Array.isArray(B.points)&&B.points.length>=2){const F=B.points,[L]=F,ie=[L,[L[0]+Y,L[1]+se]];V.points=ie}K.setNode(e,V,[he]);continue}"textContent"in B&&K.setNode(e,{textContent:c.content},[he])}},[e,x]),g=i.useCallback(async(c,C)=>{c.stopPropagation(),await p({title:n==="zh"?"确认删除提示词":"Delete Prompt",description:n==="zh"?"确定要删除这条历史提示词吗?此操作不可撤销。":"Are you sure you want to delete this prompt history item? This action cannot be undone.",confirmText:n==="zh"?"删除":"Delete",cancelText:n==="zh"?"取消":"Cancel",danger:!0})&&h(C)},[p,n,h]);return i.useEffect(()=>{if(!a)return;const c=C=>{if(P.length===0){C.key==="Escape"&&(C.preventDefault(),o(!1));return}switch(C.key){case"ArrowUp":C.preventDefault(),d(N=>N<=0?P.length-1:N-1);break;case"ArrowDown":C.preventDefault(),d(N=>N>=P.length-1?0:N+1);break;case"Enter":C.preventDefault(),P[l]&&w(P[l]);break;case"Escape":C.preventDefault(),o(!1);break}};return document.addEventListener("keydown",c),()=>document.removeEventListener("keydown",c)},[a,P,l,w]),i.useEffect(()=>{var C;if(!a||P.length===0)return;const c=(C=f.current)==null?void 0:C.querySelector(".popup-prompt-panel__item--highlighted");c&&c.scrollIntoView({block:"nearest",behavior:"smooth"})},[l,a,P.length]),t.jsxs(Ne,{open:a,onOpenChange:o,placement:"top",sideOffset:8,children:[t.jsx(_e,{asChild:!0,children:t.jsx(oe,{className:"prompt-button",type:"icon",icon:t.jsx(Mn,{size:16}),visible:!0,tooltip:s||(n==="zh"?"提示词":"Prompts"),"aria-label":s||(n==="zh"?"提示词":"Prompts"),onPointerUp:()=>o(!a)})}),t.jsx(Ee,{className:`popup-prompt-panel ${Ie}`,onMouseDown:c=>c.preventDefault(),children:t.jsxs("div",{ref:f,className:"popup-prompt-panel__content",children:[ne.length>0&&t.jsxs("div",{className:"popup-prompt-panel__section",children:[t.jsxs("div",{className:"popup-prompt-panel__section-header",children:[t.jsx(go,{size:14}),t.jsx("span",{children:n==="zh"?"历史记录":"History"})]}),t.jsx("div",{className:"popup-prompt-panel__list",children:ne.map((c,C)=>t.jsxs("div",{className:`popup-prompt-panel__item popup-prompt-panel__item--history ${$("history",C)===l?"popup-prompt-panel__item--highlighted":""}`,onClick:()=>w(c),onMouseEnter:()=>d($("history",C)),children:[t.jsxs("div",{className:"popup-prompt-panel__item-content",children:[t.jsx("span",{className:"popup-prompt-panel__item-text",children:c.content}),t.jsxs("span",{className:`popup-prompt-panel__item-source popup-prompt-panel__item-source--${c.source}`,children:[fl(c.source),t.jsx("span",{children:gl(c.source,n)})]})]}),c.source==="ai-input"&&t.jsx(ae,{content:n==="zh"?"删除":"Delete",showArrow:!1,children:t.jsx("button",{className:"popup-prompt-panel__item-delete",onClick:N=>g(N,c.id),children:t.jsx(ws,{size:12})})})]},c.id))})]}),Q.length>0&&t.jsxs("div",{className:"popup-prompt-panel__section",children:[t.jsxs("div",{className:"popup-prompt-panel__section-header",children:[t.jsx(Mn,{size:14}),t.jsx("span",{children:n==="zh"?"推荐提示词":"Suggestions"})]}),t.jsx("div",{className:"popup-prompt-panel__list",children:Q.map((c,C)=>t.jsx("div",{className:`popup-prompt-panel__item ${$("preset",C)===l?"popup-prompt-panel__item--highlighted":""}`,onClick:()=>w(c),onMouseEnter:()=>d($("preset",C)),children:t.jsx("span",{className:"popup-prompt-panel__item-text",children:c.content})},c.id))})]})]})}),j]})},Vt={bringToFront(e){const n=Se(e);if(n.length===0)return;const s=e.children.length-1,a=n.map(o=>({element:o,index:e.children.findIndex(l=>l.id===o.id)})).sort((o,l)=>l.index-o.index);for(const{element:o,index:l}of a)l>=0&&l<s&&K.moveNode(e,[l],[s])},bringForward(e){const n=Se(e);if(n.length===0)return;const s=e.children.length-1,a=n.map(o=>({element:o,index:e.children.findIndex(l=>l.id===o.id)})).sort((o,l)=>l.index-o.index);for(const{element:o,index:l}of a)l>=0&&l<s&&K.moveNode(e,[l],[l+2])},sendBackward(e){const n=Se(e);if(n.length===0)return;const s=n.map(a=>({element:a,index:e.children.findIndex(o=>o.id===a.id)})).sort((a,o)=>a.index-o.index);for(const{element:a,index:o}of s)o>0&&K.moveNode(e,[o],[o-1])},sendToBack(e){const n=Se(e);if(n.length===0)return;const s=n.map(a=>({element:a,index:e.children.findIndex(o=>o.id===a.id)})).sort((a,o)=>a.index-o.index);for(const{element:a,index:o}of s)o>0&&K.moveNode(e,[o],[0])},getLayerInfo(e,n){const s=e.children.findIndex(o=>o.id===n);if(s<0)return null;const a=e.children.length;return{index:s,total:a,canMoveUp:s<a-1,canMoveDown:s>0}}},yl=({board:e,title:n})=>{const{language:s}=je(),[a,o]=i.useState(!1),[l,d]=i.useState(0),m=te.getBoardContainer(e),x=i.useMemo(()=>{const T=Se(e);if(T.length===0)return null;const v=T[0];return Vt.getLayerInfo(e,v.id)},[e,l]),h=i.useCallback(()=>{Vt.bringToFront(e),d(T=>T+1)},[e]),p=i.useCallback(()=>{Vt.bringForward(e),d(T=>T+1)},[e]),j=i.useCallback(()=>{Vt.sendBackward(e),d(T=>T+1)},[e]),f=i.useCallback(()=>{Vt.sendToBack(e),d(T=>T+1)},[e]),M=(x==null?void 0:x.canMoveUp)??!1,S=(x==null?void 0:x.canMoveDown)??!1;return t.jsxs(Ne,{sideOffset:12,crossAxisOffset:-100,open:a,onOpenChange:o,placement:"top-start",children:[t.jsx(_e,{asChild:!0,children:t.jsx(oe,{className:z("property-button","layer-control-button"),selected:a,visible:!0,icon:t.jsx(bo,{}),type:"button",tooltip:n,"aria-label":n,onPointerUp:()=>o(!a)})}),t.jsx(Ee,{container:m,children:t.jsx(ze,{padding:1,className:z(Ie,"layer-control-panel"),children:t.jsxs("div",{className:"layer-actions",children:[t.jsx(ae,{content:s==="zh"?"置顶":"Bring to Front",showArrow:!1,children:t.jsxs("button",{className:z("layer-action-btn",{disabled:!M}),onClick:h,disabled:!M,children:[t.jsx(vo,{}),t.jsx("span",{children:s==="zh"?"置顶":"Front"})]})}),t.jsx(ae,{content:s==="zh"?"上移一层":"Bring Forward",showArrow:!1,children:t.jsxs("button",{className:z("layer-action-btn",{disabled:!M}),onClick:p,disabled:!M,children:[t.jsx(wo,{}),t.jsx("span",{children:s==="zh"?"上移":"Forward"})]})}),t.jsx(ae,{content:s==="zh"?"下移一层":"Send Backward",showArrow:!1,children:t.jsxs("button",{className:z("layer-action-btn",{disabled:!S}),onClick:j,disabled:!S,children:[t.jsx(ko,{}),t.jsx("span",{children:s==="zh"?"下移":"Backward"})]})}),t.jsx(ae,{content:s==="zh"?"置底":"Send to Back",showArrow:!1,children:t.jsxs("button",{className:z("layer-action-btn",{disabled:!S}),onClick:f,disabled:!S,children:[t.jsx(jo,{}),t.jsx("span",{children:s==="zh"?"置底":"Back"})]})}),x&&t.jsxs("span",{className:"layer-info",children:[x.index+1,"/",x.total]})]})})})]})},bl=({board:e,title:n})=>{const{language:s}=je(),[a,o]=i.useState(!1),l=te.getBoardContainer(e),d=i.useCallback(()=>{jt.alignLeft(e)},[e]),m=i.useCallback(()=>{jt.alignCenter(e)},[e]),x=i.useCallback(()=>{jt.alignRight(e)},[e]),h=i.useCallback(()=>{jt.alignTop(e)},[e]),p=i.useCallback(()=>{jt.alignMiddle(e)},[e]),j=i.useCallback(()=>{jt.alignBottom(e)},[e]),f=[{key:"left",icon:t.jsx(So,{size:16}),label:s==="zh"?"左对齐":"Align Left",shortcut:"⌥ A",handler:d},{key:"center",icon:t.jsx(No,{size:16}),label:s==="zh"?"水平居中":"Align Center",shortcut:"⌥ H",handler:m},{key:"right",icon:t.jsx(_o,{size:16}),label:s==="zh"?"右对齐":"Align Right",shortcut:"⌥ D",handler:x},{key:"top",icon:t.jsx(Eo,{size:16}),label:s==="zh"?"顶部对齐":"Align Top",shortcut:"⌥ W",handler:h},{key:"middle",icon:t.jsx(Io,{size:16}),label:s==="zh"?"垂直居中":"Align Middle",shortcut:"⌥ V",handler:p},{key:"bottom",icon:t.jsx(zo,{size:16}),label:s==="zh"?"底部对齐":"Align Bottom",shortcut:"⌥ S",handler:j}];return t.jsxs(Ne,{sideOffset:12,crossAxisOffset:-100,open:a,onOpenChange:o,placement:"top-start",children:[t.jsx(_e,{asChild:!0,children:t.jsx(oe,{className:z("property-button","alignment-button"),selected:a,visible:!0,icon:t.jsx(Co,{size:16}),type:"button",tooltip:n,"aria-label":n,onPointerUp:()=>o(!a)})}),t.jsx(Ee,{container:l,children:t.jsx(ze,{padding:1,className:z(Ie,"alignment-panel"),children:t.jsx("div",{className:"alignment-actions",children:f.map(M=>t.jsx(ae,{content:M.label,showArrow:!1,children:t.jsxs("button",{className:"alignment-action-btn",onClick:M.handler,children:[M.icon,t.jsx("span",{className:"alignment-label",children:M.label}),t.jsx("span",{className:"alignment-shortcut",children:M.shortcut})]})},M.key))})})})]})},vl=({board:e,title:n})=>{const{language:s}=je(),[a,o]=i.useState(!1),l=te.getBoardContainer(e),d=i.useCallback(()=>{yn.distributeHorizontal(e)},[e]),m=i.useCallback(()=>{yn.distributeVertical(e)},[e]),x=i.useCallback(()=>{yn.autoArrange(e)},[e]),h=[{key:"horizontal",icon:t.jsx(To,{size:16}),label:s==="zh"?"水平间距":"Horizontal Spacing",shortcut:"⇧ H",handler:d},{key:"vertical",icon:t.jsx(Fo,{size:16}),label:s==="zh"?"垂直间距":"Vertical Spacing",shortcut:"⇧ V",handler:m},{key:"auto",icon:t.jsx(Ao,{size:16}),label:s==="zh"?"自动排列":"Auto Arrange",shortcut:"⇧ A",handler:x}];return t.jsxs(Ne,{sideOffset:12,crossAxisOffset:-100,open:a,onOpenChange:o,placement:"top-start",children:[t.jsx(_e,{asChild:!0,children:t.jsx(oe,{className:z("property-button","distribute-button"),selected:a,visible:!0,icon:t.jsx(Po,{size:16}),type:"button",tooltip:n,"aria-label":n,onPointerUp:()=>o(!a)})}),t.jsx(Ee,{container:l,children:t.jsx(ze,{padding:1,className:z(Ie,"distribute-panel"),children:t.jsx("div",{className:"distribute-actions",children:h.map(p=>t.jsx(ae,{content:p.label,showArrow:!1,children:t.jsxs("button",{className:"distribute-action-btn",onClick:p.handler,children:[p.icon,t.jsx("span",{className:"distribute-label",children:p.label}),t.jsx("span",{className:"distribute-shortcut",children:p.shortcut})]})},p.key))})})})]})},wl=({board:e,title:n})=>{const{language:s}=je(),[a,o]=i.useState(!1),l=te.getBoardContainer(e),d=i.useCallback(()=>{Ht.union(e,s),o(!1)},[e,s]),m=i.useCallback(()=>{Ht.subtract(e,s)},[e,s]),x=i.useCallback(()=>{Ht.intersect(e,s)},[e,s]),h=i.useCallback(()=>{Ht.exclude(e,s)},[e,s]),p=i.useCallback(()=>{Ht.flatten(e,s)},[e,s]),j=[{key:"union",icon:t.jsx(Do,{size:16}),label:s==="zh"?"合并":"Union",shortcut:"⌥⇧U",handler:d},{key:"subtract",icon:t.jsx(Bo,{size:16}),label:s==="zh"?"减去":"Subtract",shortcut:"⌥⇧S",handler:m},{key:"intersect",icon:t.jsx(Lo,{size:16}),label:s==="zh"?"相交":"Intersect",shortcut:"⌥⇧I",handler:x},{key:"exclude",icon:t.jsx(Ro,{size:16}),label:s==="zh"?"排除":"Exclude",shortcut:"⌥⇧E",handler:h},{key:"flatten",icon:t.jsx(Oo,{size:16}),label:s==="zh"?"扁平化":"Flatten",shortcut:"⇧⌥F",handler:p}];return t.jsxs(Ne,{sideOffset:12,crossAxisOffset:-100,open:a,onOpenChange:o,placement:"top-start",children:[t.jsx(_e,{asChild:!0,children:t.jsx(oe,{className:z("property-button","boolean-button"),selected:a,visible:!0,icon:t.jsx(Mo,{size:16}),type:"button",tooltip:n,"aria-label":n,onPointerUp:()=>o(!a)})}),t.jsx(Ee,{container:l,children:t.jsx(ze,{padding:1,className:z(Ie,"boolean-panel"),children:t.jsx("div",{className:"boolean-actions",children:j.map(f=>t.jsx(ae,{content:f.label,showArrow:!1,children:t.jsxs("button",{className:"boolean-action-btn",onClick:f.handler,children:[f.icon,t.jsx("span",{className:"boolean-label",children:f.label}),t.jsx("span",{className:"boolean-shortcut",children:f.shortcut})]})},f.key))})})})]})};function kl(e){return e.sort((n,s)=>n.position-s.position).map(n=>`${n.color} ${n.position}%`).join(", ")}function jl(e){const n=kl(e.stops);return e.type==="linear"?`linear-gradient(${e.angle}deg, ${n})`:`radial-gradient(circle, ${n})`}function jn(e){return e.enabled?`${e.offsetX}px ${e.offsetY}px ${e.blur}px ${e.color}`:""}const Cn=ms.CUSTOM_GRADIENTS,Cl=({board:e,isOpen:n,onClose:s,currentFontSize:a,currentFontFamily:o,currentColor:l,toolbarRect:d,selectionRect:m})=>{var Tn,Fn;const{t:x,language:h}=je(),{confirm:p,confirmDialog:j}=zn({container:te.getBoardContainer(e)}),f=i.useRef(null),[M,S]=i.useState({top:0,left:0}),[T,v]=i.useState(a||"16"),[P,ne]=i.useState(!1),[Q,$]=i.useState(o||"PingFang SC"),[w,g]=i.useState(new Set),[c,C]=i.useState(400),[N,Y]=i.useState("left"),[se,B]=i.useState(1.5),[he,V]=i.useState(0),[F,L]=i.useState(!1),[ie,ke]=i.useState(!1),[Pe,mt]=i.useState(!1),[Re,_]=i.useState(!1),[q,X]=i.useState(!1),[le,ce]=i.useState(!1),[ge,k]=i.useState(null),[Te,Me]=i.useState(null),[Oe,xe]=i.useState(0),[Ve,Pt]=i.useState("#000000"),[Tt,Ft]=i.useState(null),[At,Mt]=i.useState(null),[lt,rt]=i.useState(!1),[u,y]=i.useState(null),[b,A]=i.useState({color:"rgba(0, 0, 0, 0.5)",offsetX:2,offsetY:2,blur:4}),[H,G]=i.useState(!1),[R,I]=i.useState(null),[O,ue]=i.useState({type:"linear",angle:135,stops:[{color:"#FF6B6B",offset:0},{color:"#4ECDC4",offset:1}]}),[re,pe]=i.useState([]),[be,Ce]=i.useState(l||"#000000"),[Je,ft]=i.useState(!1);i.useEffect(()=>{let r=!0;return St.get(Cn).then(D=>{r&&D&&pe(D)}).catch(D=>{console.warn("Failed to load gradient data:",D)}),()=>{r=!1}},[]),i.useEffect(()=>{if(n){const r=Li(e);if(r["text-gradient"]){G(!0);const J=oi.find(de=>jl(de.config)===r["text-gradient"]);I(J?J.id:null)}else G(!1),I(null);if(r["text-shadow"]){rt(!0);const J=r["text-shadow"];let de=null;for(const[Ae,et]of Object.entries(Zn.textShadow))if(jn(et)===J){de=Ae;break}y(de||null)}else rt(!1),y(null);if(r["font-family"]&&$(r["font-family"]),r["font-weight"]&&C(Number(r["font-weight"])),r["line-height"]&&B(Number(r["line-height"])),r["letter-spacing"]){const J=String(r["letter-spacing"]).replace("px","");V(Number(J))}const D=Ri(e);Y(D),L(!!r.bold),ke(!!r.italic),mt(!!r.underlined),_(!!r.strikethrough),X(!!r.superscript),ce(!!r.subscript),k(r["background-color"]||null),Me(r["text-transform"]||null),xe(r["text-stroke"]||0),Pt(r["text-stroke-color"]||"#000000"),Ft(r["text-decoration-style"]||null),Mt(r["text-decoration-color"]||null)}},[n,e]),i.useEffect(()=>{if(n&&!P){const r=setTimeout(()=>{qn.forEach(D=>{sn.isFontLoaded(D.family)||sn.loadGoogleFont(D.family).catch(J=>{console.warn(`Failed to preload font ${D.family}:`,J)})})},500);return()=>clearTimeout(r)}},[n,P]),i.useEffect(()=>{if(n&&d&&m){let de=m.right+12,Ae=d.top+d.height+8;const et=window.innerWidth,mn=window.innerHeight;de+320>et-16&&(de=m.left-320-12,de<16&&(de=et-320-16)),Ae+520>mn-16&&(Ae=Math.max(16,mn-520-16)),S({left:Math.max(16,de),top:Math.max(16,Ae)})}},[n,d,m]);const Dt=i.useCallback(r=>{const D=parseInt(r,10);!isNaN(D)&&D>=8&&D<=100&&(v(r),zs(e,r))},[e]),gt=i.useCallback(async r=>{if($(r.family),ne(!1),r.source==="google"&&!sn.isFontLoaded(r.family)){g(D=>new Set(D).add(r.family));try{await sn.loadGoogleFont(r.family)}catch(D){console.error("Failed to load Google font:",D)}finally{g(D=>{const J=new Set(D);return J.delete(r.family),J})}}ji(e,r.family)},[e]);i.useEffect(()=>{l&&Ce(l)},[l]);const xt=i.useCallback(r=>{Ce(r),ot.setTextColor(e,r)},[e]),Qt=i.useCallback((r,D)=>{y(r),rt(!0),A({color:D.color,offsetX:D.offsetX,offsetY:D.offsetY,blur:D.blur});const J=jn(D);bn(e,J)},[e]),Fe=i.useCallback((r,D)=>{const J={...b,[r]:D};A(J),y(null);const de=`${J.offsetX}px ${J.offsetY}px ${J.blur}px ${J.color}`;bn(e,de)},[e,b]),Ue=i.useCallback(r=>{ue(r),I(null);const D=ut(r);Qn(e,D)},[e]),Bt=i.useCallback(()=>{const r=ut(O),J=[{id:`custom-${Date.now()}`,css:r},...re].slice(0,8);pe(J),St.set(Cn,J).catch(de=>{console.warn("Failed to save custom gradients:",de)})},[O,re]),yt=i.useCallback(async r=>{if(!await p({title:h==="zh"?"确认删除渐变预设":"Delete Gradient Preset",description:h==="zh"?"确定要删除这个自定义渐变预设吗?":"Are you sure you want to delete this custom gradient preset?",confirmText:h==="zh"?"删除":"Delete",cancelText:h==="zh"?"取消":"Cancel",danger:!0}))return;const J=re.filter(de=>de.id!==r);pe(J),St.set(Cn,J).catch(de=>{console.warn("Failed to save custom gradients:",de)})},[p,re,h]),bt=i.useCallback(()=>{const r=!lt;rt(r),r||(bn(e,null),y(null))},[e,lt]),Lt=i.useCallback(()=>{const r=!H;G(r),r||(Qn(e,null),I(null))},[e,H]),vt=i.useCallback(r=>{C(r),Ps(e,r)},[e]),$e=i.useCallback(r=>{Y(r),Ci(e,r)},[e]),ve=i.useCallback(r=>{B(r),Si(e,r)},[e]),fe=i.useCallback(r=>{V(r),Ni(e,r)},[e]),We=i.useCallback(()=>{L(!F),_i(e)},[e,F]),He=i.useCallback(()=>{ke(!ie),Ei(e)},[e,ie]),Xe=i.useCallback(()=>{mt(!Pe),Ii(e)},[e,Pe]),wt=i.useCallback(()=>{_(!Re),zi(e)},[e,Re]),Rt=i.useCallback(()=>{const r=!q;X(r),r&&ce(!1),Pi(e)},[e,q]),Ot=i.useCallback(()=>{const r=!le;ce(r),r&&X(!1),Ti(e)},[e,le]),Jt=i.useCallback(r=>{k(r),Fi(e,r)},[e]),Ut=i.useCallback(r=>{const D=r===Te?null:r;Me(D),Ai(e,D)},[e,Te]),en=i.useCallback((r,D)=>{xe(r),D&&Pt(D),Mi(e,r>0?r:null,D||Ve)},[e,Ve]),un=i.useCallback(r=>{Ft(r),Di(e,r)},[e]),tn=i.useCallback(r=>{Mt(r),Bi(e,r)},[e]);i.useEffect(()=>{if(!n)return;const r=J=>{const de=J.target;f.current&&f.current.contains(de)||de.closest(".popup-toolbar")!==null||s()},D=setTimeout(()=>{document.addEventListener("mousedown",r)},100);return()=>{clearTimeout(D),document.removeEventListener("mousedown",r)}},[n,s]);const hn=i.useCallback(r=>{r.target===r.currentTarget&&s()},[s]),[kt,$t]=i.useState(!1),E=[{value:100,label:"Thin",labelZh:"极细"},{value:200,label:"Extra Light",labelZh:"特细"},{value:300,label:"Light",labelZh:"细体"},{value:400,label:"Regular",labelZh:"常规"},{value:500,label:"Medium",labelZh:"中等"},{value:600,label:"Semi Bold",labelZh:"半粗"},{value:700,label:"Bold",labelZh:"粗体"},{value:800,label:"Extra Bold",labelZh:"特粗"},{value:900,label:"Black",labelZh:"黑体"}],pn=i.useCallback(r=>{const D=E.find(J=>J.value===r);return D?h==="zh"?D.labelZh:D.label:String(r)},[h]),ct=[...ai,...qn],Hs=i.useCallback(r=>{const D=ct.find(J=>J.family===r);return(D==null?void 0:D.displayName)||r},[ct]);return n?t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"text-property-panel-overlay",onClick:hn,onPointerDown:r=>r.stopPropagation(),onMouseDown:r=>r.stopPropagation()}),t.jsxs("div",{ref:f,className:z("text-property-panel",{"is-open":n}),style:{top:M.top,left:M.left},onPointerDown:r=>r.stopPropagation(),onMouseDown:r=>r.stopPropagation(),onClick:r=>r.stopPropagation(),onPointerUp:r=>r.stopPropagation(),children:[t.jsxs("div",{className:"text-property-panel__header",children:[t.jsx("span",{className:"text-property-panel__header-title",children:x("propertyPanel.title")}),t.jsx("button",{className:"text-property-panel__header-close",onClick:s,children:t.jsx("svg",{width:"14",height:"14",viewBox:"0 0 14 14",fill:"none",children:t.jsx("path",{d:"M1 1L13 13M1 13L13 1",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round"})})})]}),t.jsxs("div",{className:"text-property-panel__content",children:[t.jsx("div",{className:"text-property-panel__section",children:t.jsxs("div",{className:"text-property-panel__section-content",children:[t.jsxs("div",{className:"inline-control",children:[t.jsx("label",{className:"inline-control__label",children:h==="zh"?"字号":"Size"}),t.jsxs("div",{className:"inline-control__slider-group",children:[t.jsx("input",{type:"range",className:"inline-control__slider",value:T,min:8,max:100,step:1,onChange:r=>{v(r.target.value),Dt(r.target.value)}}),t.jsx("span",{className:"inline-control__value",children:T})]})]}),t.jsxs("div",{className:"inline-control inline-control--dropdown",children:[t.jsx("label",{className:"inline-control__label",children:h==="zh"?"字体":"Font"}),t.jsxs("div",{className:"custom-dropdown",children:[t.jsxs("div",{className:z("custom-dropdown__trigger",{"is-expanded":P}),onClick:()=>{ne(!P),$t(!1)},children:[t.jsx("span",{className:"custom-dropdown__value",style:{fontFamily:`'${Q}', sans-serif`},children:Hs(Q)}),t.jsx("svg",{className:"custom-dropdown__arrow",width:"12",height:"12",viewBox:"0 0 12 12",fill:"none",children:t.jsx("path",{d:"M3 4.5L6 7.5L9 4.5",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round"})})]}),t.jsx("div",{className:z("custom-dropdown__menu custom-dropdown__menu--font",{"is-open":P}),children:ct.map(r=>t.jsxs("div",{className:z("custom-dropdown__item custom-dropdown__item--font",{"is-active":Q===r.family}),onClick:()=>{gt(r),ne(!1)},children:[t.jsx("span",{className:"custom-dropdown__item-label",children:r.displayName}),t.jsx("span",{className:"custom-dropdown__item-preview",style:{fontFamily:`'${r.family}', sans-serif`},children:r.previewText})]},r.family))})]})]}),t.jsxs("div",{className:"inline-control inline-control--dropdown",children:[t.jsx("label",{className:"inline-control__label",children:h==="zh"?"字重":"Weight"}),t.jsxs("div",{className:"custom-dropdown",children:[t.jsxs("div",{className:z("custom-dropdown__trigger",{"is-expanded":kt}),onClick:()=>{$t(!kt),ne(!1)},children:[t.jsx("span",{className:"custom-dropdown__value",style:{fontWeight:c},children:pn(c)}),t.jsx("svg",{className:"custom-dropdown__arrow",width:"12",height:"12",viewBox:"0 0 12 12",fill:"none",children:t.jsx("path",{d:"M3 4.5L6 7.5L9 4.5",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round"})})]}),t.jsx("div",{className:z("custom-dropdown__menu",{"is-open":kt}),children:E.map(r=>t.jsx("div",{className:z("custom-dropdown__item",{"is-active":c===r.value}),onClick:()=>{vt(r.value),$t(!1)},children:t.jsx("span",{className:"custom-dropdown__item-label",style:{fontWeight:r.value},children:h==="zh"?r.labelZh:r.label})},r.value))})]})]}),t.jsxs("div",{className:"inline-control",children:[t.jsx("label",{className:"inline-control__label",children:h==="zh"?"对齐":"Align"}),t.jsxs("div",{className:"align-buttons align-buttons--compact",children:[t.jsx(ae,{content:h==="zh"?"左对齐":"Align Left",showArrow:!1,children:t.jsx("button",{className:z("align-buttons__btn",{"is-active":N==="left"}),onClick:()=>$e("left"),children:t.jsx("svg",{width:"14",height:"14",viewBox:"0 0 16 16",fill:"currentColor",children:t.jsx("path",{d:"M2 3h12v2H2V3zm0 4h8v2H2V7zm0 4h12v2H2v-2z"})})})}),t.jsx(ae,{content:h==="zh"?"居中对齐":"Align Center",showArrow:!1,children:t.jsx("button",{className:z("align-buttons__btn",{"is-active":N==="center"}),onClick:()=>$e("center"),children:t.jsx("svg",{width:"14",height:"14",viewBox:"0 0 16 16",fill:"currentColor",children:t.jsx("path",{d:"M2 3h12v2H2V3zm2 4h8v2H4V7zm-2 4h12v2H2v-2z"})})})}),t.jsx(ae,{content:h==="zh"?"右对齐":"Align Right",showArrow:!1,children:t.jsx("button",{className:z("align-buttons__btn",{"is-active":N==="right"}),onClick:()=>$e("right"),children:t.jsx("svg",{width:"14",height:"14",viewBox:"0 0 16 16",fill:"currentColor",children:t.jsx("path",{d:"M2 3h12v2H2V3zm4 4h8v2H6V7zm-4 4h12v2H2v-2z"})})})})]})]}),t.jsxs("div",{className:"inline-control",children:[t.jsx("label",{className:"inline-control__label",children:h==="zh"?"样式":"Style"}),t.jsxs("div",{className:"style-buttons",children:[t.jsx(ae,{content:h==="zh"?"加粗":"Bold",showArrow:!1,children:t.jsx("button",{className:z("style-buttons__btn",{"is-active":F}),onClick:We,children:t.jsx("span",{className:"style-buttons__icon style-buttons__icon--bold",children:"B"})})}),t.jsx(ae,{content:h==="zh"?"斜体":"Italic",showArrow:!1,children:t.jsx("button",{className:z("style-buttons__btn",{"is-active":ie}),onClick:He,children:t.jsx("span",{className:"style-buttons__icon style-buttons__icon--italic",children:"I"})})}),t.jsx(ae,{content:h==="zh"?"下划线":"Underline",showArrow:!1,children:t.jsx("button",{className:z("style-buttons__btn",{"is-active":Pe}),onClick:Xe,children:t.jsx("span",{className:"style-buttons__icon style-buttons__icon--underline",children:"U"})})}),t.jsx(ae,{content:h==="zh"?"删除线":"Strikethrough",showArrow:!1,children:t.jsx("button",{className:z("style-buttons__btn",{"is-active":Re}),onClick:wt,children:t.jsx("span",{className:"style-buttons__icon style-buttons__icon--strikethrough",children:"S"})})}),t.jsx(ae,{content:h==="zh"?"上标":"Superscript",showArrow:!1,children:t.jsx("button",{className:z("style-buttons__btn",{"is-active":q}),onClick:Rt,children:t.jsxs("span",{className:"style-buttons__icon style-buttons__icon--superscript",children:["X",t.jsx("sup",{children:"2"})]})})}),t.jsx(ae,{content:h==="zh"?"下标":"Subscript",showArrow:!1,children:t.jsx("button",{className:z("style-buttons__btn",{"is-active":le}),onClick:Ot,children:t.jsxs("span",{className:"style-buttons__icon style-buttons__icon--subscript",children:["X",t.jsx("sub",{children:"2"})]})})})]})]}),t.jsxs("div",{className:"inline-control",children:[t.jsx("label",{className:"inline-control__label",children:h==="zh"?"大小写":"Case"}),t.jsxs("div",{className:"case-buttons",children:[t.jsx(ae,{content:h==="zh"?"全大写":"Uppercase",showArrow:!1,children:t.jsx("button",{className:z("case-buttons__btn",{"is-active":Te==="uppercase"}),onClick:()=>Ut("uppercase"),children:"AA"})}),t.jsx(ae,{content:h==="zh"?"全小写":"Lowercase",showArrow:!1,children:t.jsx("button",{className:z("case-buttons__btn",{"is-active":Te==="lowercase"}),onClick:()=>Ut("lowercase"),children:"aa"})}),t.jsx(ae,{content:h==="zh"?"首字母大写":"Capitalize",showArrow:!1,children:t.jsx("button",{className:z("case-buttons__btn",{"is-active":Te==="capitalize"}),onClick:()=>Ut("capitalize"),children:"Aa"})})]})]}),t.jsxs("div",{className:"inline-control",children:[t.jsx("label",{className:"inline-control__label",children:h==="zh"?"行高":"Line"}),t.jsxs("div",{className:"inline-control__slider-group",children:[t.jsx("input",{type:"range",className:"inline-control__slider",value:se,min:.8,max:3,step:.1,onChange:r=>ve(Number(r.target.value))}),t.jsx("span",{className:"inline-control__value",children:se.toFixed(1)})]})]}),t.jsxs("div",{className:"inline-control",children:[t.jsx("label",{className:"inline-control__label",children:h==="zh"?"字距":"Spacing"}),t.jsxs("div",{className:"inline-control__slider-group",children:[t.jsx("input",{type:"range",className:"inline-control__slider",value:he,min:-2,max:10,step:.5,onChange:r=>fe(Number(r.target.value))}),t.jsxs("span",{className:"inline-control__value",children:[he,"px"]})]})]})]})}),t.jsxs("div",{className:"text-property-panel__section",children:[t.jsx("div",{className:"text-property-panel__section-title",children:x("propertyPanel.textColor")}),t.jsx("div",{className:"text-property-panel__section-content text-color-picker",children:t.jsx(_t,{value:be,onChange:xt,showAlpha:!0,showEyeDropper:!0,showPresets:!0,showRecentColors:!0,showHexInput:!0})})]}),t.jsx("div",{className:"text-property-panel__section",children:t.jsxs("div",{className:"text-property-panel__section-content",children:[t.jsxs("div",{className:"inline-control",children:[t.jsx("label",{className:"inline-control__label",children:h==="zh"?"高亮":"Highlight"}),t.jsxs("div",{className:"highlight-colors",children:[t.jsx(ae,{content:h==="zh"?"无":"None",showArrow:!1,children:t.jsx("button",{className:z("highlight-colors__btn highlight-colors__btn--none",{"is-active":!ge}),onClick:()=>Jt(null),children:t.jsx("svg",{width:"12",height:"12",viewBox:"0 0 16 16",children:t.jsx("line",{x1:"2",y1:"2",x2:"14",y2:"14",stroke:"currentColor",strokeWidth:"2"})})})}),["#FFEB3B","#4CAF50","#2196F3","#E91E63","#FF9800","#9C27B0"].map(r=>t.jsx(ae,{content:r,showArrow:!1,children:t.jsx("button",{className:z("highlight-colors__btn",{"is-active":ge===r}),style:{backgroundColor:r},onClick:()=>Jt(r)})},r))]})]}),t.jsxs("div",{className:"inline-control",children:[t.jsx("label",{className:"inline-control__label",children:h==="zh"?"描边":"Stroke"}),t.jsxs("div",{className:"inline-control__slider-group",children:[t.jsx("input",{type:"range",className:"inline-control__slider",value:Oe,min:0,max:3,step:.5,onChange:r=>en(Number(r.target.value))}),t.jsxs("span",{className:"inline-control__value",children:[Oe,"px"]}),Oe>0&&t.jsx("input",{type:"color",className:"inline-control__color-input",value:Ve,onChange:r=>en(Oe,r.target.value)})]})]}),(Pe||Re)&&t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"inline-control",children:[t.jsx("label",{className:"inline-control__label",children:h==="zh"?"线型":"Line Style"}),t.jsx("div",{className:"decoration-style-buttons",children:["solid","double","dotted","dashed","wavy"].map(r=>t.jsx(ae,{content:r,showArrow:!1,children:t.jsx("button",{className:z("decoration-style-buttons__btn",{"is-active":Tt===r}),onClick:()=>un(Tt===r?null:r),children:t.jsx("span",{className:`decoration-preview decoration-preview--${r}`,children:"Ab"})})},r))})]}),t.jsxs("div",{className:"inline-control",children:[t.jsx("label",{className:"inline-control__label",children:h==="zh"?"线色":"Line Color"}),t.jsxs("div",{className:"highlight-colors",children:[t.jsx(ae,{content:h==="zh"?"默认":"Default",showArrow:!1,children:t.jsx("button",{className:z("highlight-colors__btn highlight-colors__btn--none",{"is-active":!At}),onClick:()=>tn(null),children:t.jsx("svg",{width:"12",height:"12",viewBox:"0 0 16 16",children:t.jsx("line",{x1:"2",y1:"2",x2:"14",y2:"14",stroke:"currentColor",strokeWidth:"2"})})})}),["#E91E63","#FF5722","#4CAF50","#2196F3","#9C27B0","#000000"].map(r=>t.jsx(ae,{content:r,showArrow:!1,children:t.jsx("button",{className:z("highlight-colors__btn",{"is-active":At===r}),style:{backgroundColor:r},onClick:()=>tn(r)})},r))]})]})]})]})}),t.jsx("div",{className:"text-property-panel__section",children:t.jsxs("div",{className:"text-property-panel__section-content",children:[t.jsxs("div",{className:"inline-control",children:[t.jsx("label",{className:"inline-control__label",children:h==="zh"?"阴影":"Shadow"}),t.jsx("div",{className:z("toggle-switch__control toggle-switch__control--inline",{"is-active":lt}),onClick:bt})]}),lt&&t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"effect-presets",children:Object.entries(Zn.textShadow).map(([r,D])=>t.jsx(ae,{content:r,showArrow:!1,children:t.jsx("div",{className:z("effect-presets__item",{"is-active":u===r}),onClick:()=>Qt(r,D),children:t.jsx("span",{style:{textShadow:jn(D)},children:"Aa"})})},r))}),t.jsxs("div",{className:"effect-config",children:[t.jsxs("div",{className:"inline-control",children:[t.jsx("label",{className:"inline-control__label",children:h==="zh"?"颜色":"Color"}),t.jsxs("div",{className:"inline-control__color-group",children:[t.jsxs(Ne,{open:Je,onOpenChange:ft,placement:"bottom",sideOffset:8,children:[t.jsx(_e,{asChild:!0,children:t.jsx("button",{className:"inline-control__color-trigger",style:{backgroundColor:b.color.startsWith("rgba")?`#${((Tn=b.color.match(/\d+/g))==null?void 0:Tn.slice(0,3).map(r=>parseInt(r).toString(16).padStart(2,"0")).join(""))||"000000"}`:b.color},onClick:()=>ft(!Je)})}),t.jsx(Ee,{children:t.jsx(ze,{padding:4,className:"color-picker-popover",children:t.jsx(_t,{value:b.color.startsWith("rgba")?`#${((Fn=b.color.match(/\d+/g))==null?void 0:Fn.slice(0,3).map(r=>parseInt(r).toString(16).padStart(2,"0")).join(""))||"000000"}`:b.color,onChange:r=>{const D=parseInt(r.slice(1,3),16),J=parseInt(r.slice(3,5),16),de=parseInt(r.slice(5,7),16),Ae=b.color.match(/[\d.]+\)$/),et=Ae?parseFloat(Ae[0]):.5;Fe("color",`rgba(${D}, ${J}, ${de}, ${et})`)},showAlpha:!1,showEyeDropper:!0,showPresets:!0,showRecentColors:!0,showHexInput:!0})})})]}),t.jsx(ae,{content:h==="zh"?"透明度":"Opacity",showArrow:!1,children:t.jsx("input",{type:"range",className:"inline-control__slider inline-control__slider--short",value:(()=>{const r=b.color.match(/[\d.]+\)$/);return r?parseFloat(r[0])*100:50})(),min:0,max:100,step:5,"aria-label":h==="zh"?"透明度":"Opacity",onChange:r=>{const D=Number(r.target.value)/100,J=b.color.match(/\d+/g);if(J&&J.length>=3){const[de,Ae,et]=J.slice(0,3);Fe("color",`rgba(${de}, ${Ae}, ${et}, ${D})`)}}})}),t.jsxs("span",{className:"inline-control__value inline-control__value--narrow",children:[(()=>{const r=b.color.match(/[\d.]+\)$/);return r?Math.round(parseFloat(r[0])*100):50})(),"%"]})]})]}),t.jsxs("div",{className:"inline-control",children:[t.jsx("label",{className:"inline-control__label",children:h==="zh"?"X偏移":"X"}),t.jsxs("div",{className:"inline-control__slider-group",children:[t.jsx("input",{type:"range",className:"inline-control__slider",value:b.offsetX,min:-20,max:20,step:1,onChange:r=>Fe("offsetX",Number(r.target.value))}),t.jsxs("span",{className:"inline-control__value",children:[b.offsetX,"px"]})]})]}),t.jsxs("div",{className:"inline-control",children:[t.jsx("label",{className:"inline-control__label",children:h==="zh"?"Y偏移":"Y"}),t.jsxs("div",{className:"inline-control__slider-group",children:[t.jsx("input",{type:"range",className:"inline-control__slider",value:b.offsetY,min:-20,max:20,step:1,onChange:r=>Fe("offsetY",Number(r.target.value))}),t.jsxs("span",{className:"inline-control__value",children:[b.offsetY,"px"]})]})]}),t.jsxs("div",{className:"inline-control",children:[t.jsx("label",{className:"inline-control__label",children:h==="zh"?"模糊":"Blur"}),t.jsxs("div",{className:"inline-control__slider-group",children:[t.jsx("input",{type:"range",className:"inline-control__slider",value:b.blur,min:0,max:30,step:1,onChange:r=>Fe("blur",Number(r.target.value))}),t.jsxs("span",{className:"inline-control__value",children:[b.blur,"px"]})]})]})]})]})]})}),t.jsx("div",{className:"text-property-panel__section",children:t.jsxs("div",{className:"text-property-panel__section-content",children:[t.jsxs("div",{className:"inline-control",children:[t.jsx("label",{className:"inline-control__label",children:h==="zh"?"渐变":"Gradient"}),t.jsx("div",{className:z("toggle-switch__control toggle-switch__control--inline",{"is-active":H}),onClick:Lt})]}),H&&t.jsx("div",{className:"gradient-editor-wrapper",children:t.jsx(Ts,{value:O,onChange:Ue,showPresets:!0,showHistory:!1,inline:!0,customPresets:re.map(r=>r.css),onSavePreset:Bt,onDeletePreset:r=>{const D=re[r];D&&yt(D.id)}})})]})})]})]}),j]}):null},Sl=320,Nl=252,tt=12,_l=220;function El(e,n){return e.children.findIndex(s=>s.id===n)}function Sn(e){return Zt(e.transform3d)}function ls(e){return{rotateX:(e==null?void 0:e.rotateX)??0,rotateY:(e==null?void 0:e.rotateY)??0,perspective:(e==null?void 0:e.perspective)??ks}}function Il(e,n){const s=Zt(e),a=Zt(n);return!s&&!a?!0:!s||!a?!1:s.rotateX===a.rotateX&&s.rotateY===a.rotateY&&s.perspective===a.perspective}function an(e,n,s){const a=El(e,n);a<0||K.setNode(e,{transform3d:s},[a])}function ln(e,n,s){return Math.min(s,Math.max(n,e))}function zl(e,n,s){const a=s-n;return a<=0?"0%":`${((ln(e,n,s)-n)/a*100).toFixed(2)}%`}function Pl(e){if(typeof window>"u"||!e)return{};const n=window.innerWidth,s=window.innerHeight,a=e.left,o=n-e.right,l=o>=a,m=ln((l?o:a)-tt*2,Nl,Sl),x=l?Math.min(e.right+tt,n-m-tt):Math.max(tt,e.left-m-tt),h=ln(e.top,tt,Math.max(tt,s-_l-tt));return{contentStyle:{left:x,top:h,position:"fixed",transform:"none"},panelStyle:{width:m}}}const Tl=({board:e,element:n,selectionRect:s,title:a,language:o})=>{const[l,d]=i.useState(!1),[m,x]=i.useState(()=>ls(Sn(n))),h=i.useRef(void 0),p=i.useRef(!1),j=n.id,f=te.getBoardContainer(e),M=Pl(s),S=i.useCallback(c=>{x(c),nn.withoutSaving(e,()=>{an(e,j,Zt(c))})},[e,j]),T=i.useCallback(()=>{nn.withoutSaving(e,()=>{an(e,j,h.current)})},[e,j]),v=i.useCallback(c=>{if(c){const C=Sn(n);h.current=C,p.current=!1,x(ls(C)),d(!0);return}l&&!p.current&&T(),d(!1)},[n,l,T]),P=i.useCallback((c,C)=>{const N=c==="perspective"?{min:200,max:3e3}:{min:-180,max:180};S({...m,[c]:ln(C,N.min,N.max)})},[m,S]),ne=i.useCallback(()=>{S({rotateX:0,rotateY:0,perspective:ks})},[S]),Q=i.useCallback(()=>{const c=Zt(m);p.current=!0,nn.withoutSaving(e,()=>{an(e,j,h.current)}),Il(h.current,c)||nn.withNewBatch(e,()=>{an(e,j,c)}),Uo(),d(!1)},[e,m,j]),$=i.useCallback(()=>{p.current=!0,T(),d(!1)},[T]);i.useEffect(()=>{l&&v(!1)},[j]);const w={rotateX:o==="zh"?"上下倾斜":"Rotate X",rotateY:o==="zh"?"左右倾斜":"Rotate Y",perspective:o==="zh"?"透视距离":"Perspective",reset:o==="zh"?"重置":"Reset",cancel:o==="zh"?"取消":"Cancel",confirm:o==="zh"?"确定":"Apply"},g=(c,C,N,Y,se,B)=>t.jsxs("label",{className:"image-3d-control-row",children:[t.jsx("span",{className:"image-3d-control-label",children:C}),t.jsx("input",{className:"image-3d-control-slider",type:"range",min:N,max:Y,step:se,value:m[c],style:{"--image-3d-slider-progress":zl(m[c],N,Y)},onChange:he=>P(c,Number(he.target.value))}),t.jsxs("span",{className:"image-3d-control-number",children:[t.jsx("input",{type:"number",min:N,max:Y,step:se,value:m[c],onChange:he=>P(c,Number(he.target.value))}),t.jsx("em",{children:B})]})]});return t.jsxs(Ne,{sideOffset:12,open:l,onOpenChange:v,placement:"right-start",children:[t.jsx(_e,{asChild:!0,children:t.jsx(oe,{className:z("property-button","image-3d-transform-button"),selected:l||!!Sn(n),visible:!0,icon:t.jsx($o,{size:15}),type:"button",tooltip:a,"aria-label":a,"data-track":"toolbar_click_image_3d_transform",onPointerUp:()=>v(!l)})}),t.jsx(Ee,{container:f,style:M.contentStyle,children:t.jsxs(ze,{padding:1,style:M.panelStyle,className:z(Ie,"image-3d-transform-panel"),children:[t.jsxs("div",{className:"image-3d-control-list",children:[g("rotateY",w.rotateY,-180,180,1,"deg"),g("rotateX",w.rotateX,-180,180,1,"deg"),g("perspective",w.perspective,200,3e3,20,"px")]}),t.jsxs("div",{className:"image-3d-control-actions",children:[t.jsxs("button",{type:"button",onClick:ne,children:[t.jsx(Wo,{size:14}),t.jsx("span",{children:w.reset})]}),t.jsxs("button",{type:"button",onClick:$,children:[t.jsx(ws,{size:14}),t.jsx("span",{children:w.cancel})]}),t.jsxs("button",{type:"button",className:"image-3d-control-confirm",onClick:Q,children:[t.jsx(Ho,{size:14}),t.jsx("span",{children:w.confirm})]})]})]})})]})};let it={x:0,y:0},Et=new Set,rn=!1;const Fs=e=>{it={x:e.clientX,y:e.clientY},Et.forEach(n=>n(it))},As=e=>{it={x:e.clientX,y:e.clientY},Et.forEach(n=>n(it))},Ms=e=>{it={x:e.clientX,y:e.clientY},Et.forEach(n=>n(it))},Fl=()=>{rn||(document.addEventListener("mousemove",Fs,!0),document.addEventListener("mousedown",As,!0),document.addEventListener("mouseup",Ms,!0),rn=!0)},Al=()=>{rn&&Et.size===0&&(document.removeEventListener("mousemove",Fs,!0),document.removeEventListener("mousedown",As,!0),document.removeEventListener("mouseup",Ms,!0),rn=!1)},Ml=()=>{const[e,n]=i.useState(()=>it),s=i.useRef();return i.useEffect(()=>(s.current=a=>{n(a)},Et.add(s.current),Fl(),n(it),()=>{s.current&&Et.delete(s.current),Al()}),[]),e},Dl=({visible:e,videoUrl:n,onClose:s,onConfirm:a})=>{const{language:o}=je(),l=i.useRef(null),d=i.useRef(null),m=i.useRef(null),[x,h]=i.useState(!0),[p,j]=i.useState(0),[f,M]=i.useState(0),[S,T]=i.useState(""),[v,P]=i.useState(!1),[ne,Q]=i.useState(!1);i.useEffect(()=>(e&&n&&(h(!0),T(""),P(!1),Q(!1)),()=>{m.current!==null&&window.clearTimeout(m.current)}),[e,n]);const $=()=>{const V=l.current;V&&(j(V.duration),P(!0))},w=i.useCallback((V,F=!1)=>{const L=l.current;if(!L)return;m.current!==null&&(window.clearTimeout(m.current),m.current=null);const ie=()=>{if(L.readyState<2){console.warn("Video not ready for seeking, readyState:",L.readyState);const ke=()=>{L.currentTime=V,L.removeEventListener("canplay",ke)};L.addEventListener("canplay",ke);return}L.currentTime=V};F?ie():m.current=window.setTimeout(ie,150)},[]);i.useEffect(()=>{const V=l.current;if(v&&V&&p>0){const F=Math.max(0,p-.1);M(F),w(F,!0)}},[v,p,w]);const g=i.useCallback(()=>{const V=l.current,F=d.current;if(!V||!F)return;const L=F.getContext("2d");if(L)try{F.width=V.videoWidth,F.height=V.videoHeight,L.drawImage(V,0,0,F.width,F.height);const ie=F.toDataURL("image/png");T(ie)}catch(ie){console.warn("Failed to generate frame image (likely due to CORS):",ie);try{L.fillStyle="#000",L.fillRect(0,0,F.width,F.height),L.fillStyle="#fff",L.font="16px Arial",L.textAlign="center",L.fillText("视频帧预览不可用",F.width/2,F.height/2);const ke=F.toDataURL("image/png");T(ke)}catch(ke){console.error("Failed to create placeholder image:",ke),T("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNk+M9QDwADhgGAWjR9awAAAABJRU5ErkJggg==")}}},[]),c=i.useCallback(()=>{ne||(g(),h(!1))},[ne,g]),C=()=>{Q(!0)},N=V=>{if(l.current&&p>0&&v){const L=V/100*p;M(L),w(L,!1)}},Y=()=>{Q(!1),h(!0),l.current&&v&&w(f,!0)},se=V=>{if(!l.current||p===0||!v)return;const L=parseFloat(V.target.value);if(isNaN(L))return;const ie=Math.max(0,Math.min(p,L));M(ie),w(ie,!0),h(!0)},B=()=>{S&&(a(S,f),s())},he=V=>{const F=Math.floor(V/60),L=(V%60).toFixed(1);return`${F}:${L.padStart(4,"0")}`};return t.jsx(Go,{visible:e,onClose:s,header:o==="zh"?"选择视频帧":"Select Video Frame",width:600,destroyOnClose:!0,footer:!1,children:t.jsxs("div",{className:"video-frame-selector",children:[t.jsx("video",{ref:l,src:n,style:{display:"none"},muted:!0,playsInline:!0,preload:"auto",crossOrigin:"anonymous",onLoadedMetadata:$,onSeeked:c}),t.jsx("canvas",{ref:d,style:{display:"none"}}),t.jsx("div",{className:"frame-preview",children:x?t.jsxs("div",{className:"loading-placeholder",children:[t.jsx("div",{className:"loading-spinner"}),t.jsx("div",{className:"loading-text",children:o==="zh"?"加载视频中...":"Loading video..."})]}):t.jsx("div",{className:"frame-image-container",children:t.jsx("img",{src:S,alt:"Video frame",className:"frame-image"})})}),t.jsxs("div",{className:"time-controls",children:[t.jsxs("div",{className:"time-display",children:[t.jsx("span",{className:"current-time",children:he(f)}),t.jsx("span",{className:"separator",children:"/"}),t.jsx("span",{className:"total-time",children:he(p)})]}),t.jsx("div",{className:"progress-container",children:t.jsx("input",{type:"range",min:0,max:100,value:p>0?f/p*100:0,onChange:V=>N(Number(V.target.value)),onMouseDown:C,onMouseUp:Y,onTouchStart:C,onTouchEnd:Y,className:"progress-slider",disabled:x&&!ne})}),t.jsxs("div",{className:"time-input-container",children:[t.jsx("label",{className:"time-input-label",children:o==="zh"?"精确时间 (秒):":"Precise time (seconds):"}),t.jsx("input",{type:"number",min:0,max:p,step:.1,value:f.toFixed(1),onChange:se,className:"time-input",disabled:x})]})]}),t.jsxs("div",{className:"actions",children:[t.jsx("button",{className:"action-button secondary",onClick:s,children:o==="zh"?"取消":"Cancel"}),t.jsx("button",{className:"action-button primary",onClick:B,disabled:x||!S,children:o==="zh"?"确认插入":"Confirm Insert"})]})]})})},Bl=async(e,n,s,a)=>{if(!e||!n)throw new Error("Board and video element are required");try{const o=st(e,[n],!1),l=[o.x,o.y+o.height+20],d=new Image,m=await new Promise(h=>{d.onload=()=>{h({width:d.naturalWidth,height:d.naturalHeight})},d.onerror=()=>{h({width:o.width,height:o.height})},d.src=s}),x={url:s,width:m.width,height:m.height,isVideoFrame:!0,videoTimestamp:a,sourceVideoId:n.id||"unknown"};js.insertImage(e,x,l)}catch(o){throw console.error("Failed to insert video frame:",o),new Error(`Video frame insertion failed: ${o instanceof Error?o.message:"Unknown error"}`)}};function Ze(e){return typeof e=="number"&&Number.isFinite(e)&&e>0}function Ll(e){const n=e;return n.isAudio===!0||n.audioType==="music-card"||typeof n.audioUrl=="string"&&n.audioUrl.length>0}function Rl(e){return U.isDrawElement(e)&&U.isImage(e)&&typeof e.url=="string"&&!Ll(e)&&!e.pptImagePlaceholder}function Ds(e,n){const s=n.points;if(s&&s.length>=2)return qt.getRectangleByPoints(s);try{return st(e,[n],!1)}catch{return null}}function Ol(e,n){const s=Math.max(e.x,n.x),a=Math.max(e.y,n.y),o=Math.min(e.x+e.width,n.x+n.width),l=Math.min(e.y+e.height,n.y+n.height);return Math.max(0,o-s)*Math.max(0,l-a)}function Ul(e,n){if(!n)return null;const s=e.children.find(a=>a.id===n&&Be(a));return s&&Be(s)?s:null}function Bs(e,n){const s=Ul(e,n.frameId);if(s)return s;const a=Ds(e,n);if(!a)return null;let o=null,l=0;for(const d of e.children){if(!Be(d))continue;const m=qt.getRectangleByPoints(d.points),x=Ol(a,m);x>l&&(l=x,o=d)}return l>0?o:null}function $l(e,n){return e.children.filter(s=>{var o;return s.id===n.id||Be(s)||!Rl(s)?!1:s.frameId===n.id?!0:((o=Bs(e,s))==null?void 0:o.id)===n.id})}function Wl(e,n){const s=e;return Ze(s.width)&&Ze(s.height)?s.width/s.height:Ze(n.width)&&Ze(n.height)?n.width/n.height:null}function Hl(e){const n=e.toLowerCase();return n.includes("#video")||n.includes("#merged-video-")||[".mp4",".avi",".mov",".wmv",".flv",".webm",".mkv"].some(s=>n.includes(s))}function Gl(e){return typeof Image>"u"||Hl(e)?Promise.resolve(null):new Promise(n=>{const s=new Image;let a;const o=()=>{a&&clearTimeout(a),s.onload=null,s.onerror=null};s.referrerPolicy="no-referrer",s.onload=()=>{const l=s.naturalWidth||s.width,d=s.naturalHeight||s.height;o(),n(Ze(l)&&Ze(d)?l/d:null)},s.onerror=()=>{o(),n(null)},a=setTimeout(()=>{o(),n(null)},3e3),s.src=e})}async function Vl(e){const n=e.url;return typeof n=="string"&&n.length>0?Gl(n):null}function Xl(e,n){if(!Ze(e)||!Ze(n.width)||!Ze(n.height))return null;const s=n.width/n.height;let a,o;return e>s?(a=n.width,o=a/e):(o=n.height,a=o*e),{x:n.x+(n.width-a)/2,y:n.y+(n.height-o)/2,width:a,height:o}}function Yl(e,n,s,a){const o=e.children.findIndex(p=>p.id===n.id);if(o===-1)return!1;const l=Ds(e,n);if(!l)return!1;const d=a||Wl(n,l);if(!d)return!1;const m=qt.getRectangleByPoints(s.points),x=Xl(d,m);if(!x)return!1;const h=[[x.x,x.y],[x.x+x.width,x.y+x.height]];return K.setNode(e,{points:h,frameId:s.id},[o]),!0}async function Zl(e,n,s){return Yl(e,n,s,await Vl(n))}async function ql(e,n){let s=0,a=0;for(const o of $l(e,n)){const l=Bs(e,o);if(!l||!await Zl(e,o,l)){a+=1;continue}s+=1}return{fittedCount:s,skippedCount:a}}function rs(e){return Yo(e).replace(/\u00a0/g," ").replace(/[ \t]+\n/g,`
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["./ai-chat-BlxYfB4O.css","./MediaLibrarySidebar-CcSibzET.css","./tool-windows-DW-CDfPc.css"])))=>i.map(i=>d[i]);
2
+ import{_ as De}from"./startup-runtime-BrfuwjQS.js";import{lz as qe,lA as Qe,lB as Nt,bu as En,bj as q,lC as In,lD as It,lE as zt,ak as Se,jU as we,lF as Gs,lG as pt,lH as cs,lI as ot,lJ as me,lK as ye,W as Z,lL as Ct,cd as ht,P as i,bd as te,a8 as t,i5 as Ne,i6 as _e,aa as z,i7 as Ee,iq as Ie,cm as je,lM as Ye,R as ds,lN as us,ar as fn,d$ as Vs,e0 as Xs,e1 as Ys,lO as Zs,lP as Ks,lQ as hs,lR as ps,c8 as qs,lS as cn,lT as An,ab as ae,ep as zn,S as St,U as ms,lU as fs,lV as Qs,ao as W,lW as Js,lX as eo,f6 as to,iP as no,gx as so,gy as gs,cO as xs,eI as ys,lY as bs,lZ as Yt,l_ as oo,l$ as ao,aw as Ke,dU as io,bp as st,m0 as lo,m1 as ro,bk as Be,bq as U,ca as Le,bt as at,el as vs,m2 as co,a7 as gn,m3 as uo,em as ho,fS as po,fR as mo,m4 as fo,m5 as Pn,m6 as Mn,bK as go,gz as ws,m7 as xo,m8 as yo,m9 as bo,ma as vo,mb as wo,mc as ko,md as jo,me as Co,mf as So,mg as No,mh as _o,mi as Eo,mj as Io,mk as zo,ml as Po,mm as To,mn as Fo,mo as Ao,mp as Mo,mq as Do,mr as Bo,ms as Lo,mt as Ro,mu as Oo,c0 as nn,hB as Zt,mv as ks,mw as Uo,mx as $o,c4 as Wo,eB as Ho,d1 as Go,b8 as js,at as Kt,ec as Vo,my as Xo,cE as Yo,hO as Zo,mz as Ko,mA as qo,mB as Qo,mC as Jo,ic as dt,jR as Wt,mD as Dn,hA as ea,mE as Bn,mF as ta,Q as na,eP as xn,eG as sa,eD as oa,eF as aa,eO as ia,fb as la,eQ as ra,mG as Ln,js as Rn,jp as On,hX as Un,mH as ca,mI as da,mJ as $n,cT as ua,cS as ha,mK as pa,dE as ma,mL as fa,eV as ga,mM as Wn,i9 as xa,mN as ya,mO as Hn,f5 as ba,iO as va,mP as wa,mQ as ka,du as ja,mR as Ca,mS as Sa,mT as Na,mU as _a,eZ as Ea,ka as Ia,ek as za,mV as Pa,br as Gn,bf as Vn,bs as Xn,mW as Ta,cJ as Yn,jN as Fa,cR as Aa,cQ as Ma,mX as Da,mY as Ba,mZ as La,ib as Ra,fy as Oa,b9 as Ua,cl as Cs,ci as $a,m_ as dn,ck as Wa,cj as Ha,cc as Ga,ei as Va,cb as Ss,bv as Xa,m$ as Ya}from"./ai-chat-BnWVpTEI.js";import{I as ze,S as Xt,g as Za,h as Ka,o as qa,j as Qa,k as Ja,l as ei,n as ti}from"./bootstrap-CQRLkOtk.js";import{I as qt,$ as Ns,a0 as _s,c as oe,a2 as _t,a3 as ni,R as si,A as jt,D as yn,B as Ht,a4 as oi,a5 as Zn,a6 as Kn,a7 as sn,a8 as ai,a9 as Es,aa as ii,ab as li,y as ri,ac as ci,ad as di,ae as ui,V as hi}from"./tool-windows-Bf_pMml-.js";import{m as pi}from"./video-merge-webcodecs-BInWo9HA.js";import{m as mi}from"./frame-size-matcher-9rxQ-bAY.js";import{b as fi}from"./image-task-prefill-DtECrkJn.js";import"./startup-app-CH3QzBb4.js";const Is=e=>e?typeof e=="string"?e:ht(e)&&e.type==="solid"&&e.solid?e.solid.color:null:null,gi=(e,n)=>{qe.setFillColor(e,null,{getMemorizeKey:Qe,callback:(s,a)=>{if(!qt(e,s))return;const o=s.fill,l=Is(o)||Ns(e,s);if(!Gs(l))return;const d=pt(l),m=It(n)?d:zt(d,n);q.setNode(e,{fill:m},a)}})},xi=(e,n)=>{qe.setFillColor(e,null,{getMemorizeKey:Qe,callback:(s,a)=>{if(!qt(e,s))return;const o=s.fill,l=Is(o)||Ns(e,s),d=typeof l=="string"?Nt(l):void 0;En(n)?q.setNode(e,{fill:"none"},a):In(d)||It(d)?q.setNode(e,{fill:n},a):q.setNode(e,{fill:zt(n,d)},a)}})},yi=(e,n)=>{qe.setStrokeColor(e,null,{getMemorizeKey:Qe,callback:(s,a)=>{const o=_s(e,s),l=pt(o),d=It(n)?l:zt(l,n);q.setNode(e,{strokeColor:d},a)}})},bi=(e,n)=>{qe.setStrokeColor(e,null,{getMemorizeKey:Qe,callback:(s,a)=>{const o=_s(e,s),l=Nt(o);En(n)?q.setNode(e,{strokeColor:"none"},a):In(l)||It(l)?q.setNode(e,{strokeColor:n},a):q.setNode(e,{strokeColor:zt(n,l)},a)}})},vi=(e,n)=>{qe.setStrokeStyle(e,n,{getMemorizeKey:Qe,callback:(s,a)=>{q.setNode(e,{strokeStyle:n},a)}})},qn=(e,n)=>{qe.setStrokeWidth(e,n,{getMemorizeKey:Qe,callback:(s,a)=>{q.setNode(e,{strokeWidth:n},a)}})},wi=(e,n,s)=>{const a=Nt(n);En(s)?ot.setTextColor(e,null):In(a)||It(a)?ot.setTextColor(e,s):ot.setTextColor(e,zt(s,a))},ki=(e,n,s)=>{const a=pt(n),o=It(s)?a:zt(a,s);ot.setTextColor(e,o)},zs=(e,n)=>{try{ot.setFontSize(e,n,16)}catch{const a=me(e);a&&a.length>0&&a.forEach(o=>{try{o.addMark("font-size",n)}catch(l){console.error("Failed to set font size mark:",l)}})}},ji=(e,n)=>{const s=me(e);s&&s.length>0&&s.forEach(a=>{try{ye(a),Z.addMark(a,"font-family",n)}catch(o){console.error("Failed to set font family:",o)}})},bn=(e,n)=>{const s=me(e);s&&s.length>0&&s.forEach(a=>{try{ye(a),n?Z.addMark(a,"text-shadow",n):Z.removeMark(a,"text-shadow")}catch(o){console.error("Failed to set text shadow:",o)}})},Qn=(e,n)=>{const s=me(e);s&&s.length>0&&s.forEach(a=>{try{ye(a),n?Z.addMark(a,"text-gradient",n):Z.removeMark(a,"text-gradient")}catch(o){console.error("Failed to set text gradient:",o)}})},Ps=(e,n)=>{const s=me(e);s&&s.length>0&&s.forEach(a=>{try{ye(a),Z.addMark(a,"font-weight",String(n))}catch(o){console.error("Failed to set font weight:",o)}})},Ci=(e,n)=>{try{let s;n==="left"?s=Ct.left:n==="center"?s=Ct.center:s=Ct.right,ot.setTextAlign(e,s)}catch(s){console.error("Failed to set text align:",s)}},Si=(e,n)=>{const s=me(e);s&&s.length>0&&s.forEach(a=>{try{ye(a),Z.addMark(a,"line-height",String(n))}catch(o){console.error("Failed to set line height:",o)}})},Ni=(e,n)=>{const s=me(e);s&&s.length>0&&s.forEach(a=>{try{ye(a);const o=typeof n=="number"?`${n}px`:n;Z.addMark(a,"letter-spacing",o)}catch(o){console.error("Failed to set letter spacing:",o)}})},_i=e=>{const n=me(e);n&&n.length>0&&n.forEach(s=>{try{ye(s);const a=Z.marks(s);(a?!!a.bold:!1)?Z.removeMark(s,"bold"):Z.addMark(s,"bold",!0)}catch(a){console.error("Failed to toggle bold:",a)}})},Ei=e=>{const n=me(e);n&&n.length>0&&n.forEach(s=>{try{ye(s);const a=Z.marks(s);(a?!!a.italic:!1)?Z.removeMark(s,"italic"):Z.addMark(s,"italic",!0)}catch(a){console.error("Failed to toggle italic:",a)}})},Ii=e=>{const n=me(e);n&&n.length>0&&n.forEach(s=>{try{ye(s);const a=Z.marks(s);(a?!!a.underlined:!1)?Z.removeMark(s,"underlined"):Z.addMark(s,"underlined",!0)}catch(a){console.error("Failed to toggle underline:",a)}})},zi=e=>{const n=me(e);n&&n.length>0&&n.forEach(s=>{try{ye(s);const a=Z.marks(s);(a?!!a.strikethrough:!1)?Z.removeMark(s,"strikethrough"):Z.addMark(s,"strikethrough",!0)}catch(a){console.error("Failed to toggle strikethrough:",a)}})},Pi=e=>{const n=me(e);n&&n.length>0&&n.forEach(s=>{try{ye(s);const a=Z.marks(s);(a?!!a.superscript:!1)?Z.removeMark(s,"superscript"):(Z.removeMark(s,"subscript"),Z.addMark(s,"superscript",!0))}catch(a){console.error("Failed to toggle superscript:",a)}})},Ti=e=>{const n=me(e);n&&n.length>0&&n.forEach(s=>{try{ye(s);const a=Z.marks(s);(a?!!a.subscript:!1)?Z.removeMark(s,"subscript"):(Z.removeMark(s,"superscript"),Z.addMark(s,"subscript",!0))}catch(a){console.error("Failed to toggle subscript:",a)}})},Fi=(e,n)=>{const s=me(e);s&&s.length>0&&s.forEach(a=>{try{ye(a),n?Z.addMark(a,"background-color",n):Z.removeMark(a,"background-color")}catch(o){console.error("Failed to set background color:",o)}})},Ai=(e,n)=>{const s=me(e);s&&s.length>0&&s.forEach(a=>{try{ye(a),n&&n!=="none"?Z.addMark(a,"text-transform",n):Z.removeMark(a,"text-transform")}catch(o){console.error("Failed to set text transform:",o)}})},Mi=(e,n,s)=>{const a=me(e);a&&a.length>0&&a.forEach(o=>{try{ye(o),n&&n>0?(Z.addMark(o,"text-stroke",n),s&&Z.addMark(o,"text-stroke-color",s)):(Z.removeMark(o,"text-stroke"),Z.removeMark(o,"text-stroke-color"))}catch(l){console.error("Failed to set text stroke:",l)}})},Di=(e,n)=>{const s=me(e);s&&s.length>0&&s.forEach(a=>{try{ye(a),n?Z.addMark(a,"text-decoration-style",n):Z.removeMark(a,"text-decoration-style")}catch(o){console.error("Failed to set text decoration style:",o)}})},Bi=(e,n)=>{const s=me(e);s&&s.length>0&&s.forEach(a=>{try{ye(a),n?Z.addMark(a,"text-decoration-color",n):Z.removeMark(a,"text-decoration-color")}catch(o){console.error("Failed to set text decoration color:",o)}})},Li=e=>{const n=me(e);if(n&&n.length>0){const s=n[0];try{return ye(s),Z.marks(s)||{}}catch(a){return console.error("Failed to get text marks:",a),{}}}return{}},Ri=e=>{const n=me(e);if(n&&n.length>0){const s=n[0];try{const{selection:a}=s;if(a){const o=Array.from(Z.nodes(s,{at:a,match:l=>{const d=l.type==="paragraph",m="align"in l;return Z.isBlock(s,l)&&(d||m)}}));if(o.length>0){const[l]=o[0],d=l.align;if(d===Ct.right||d==="right")return"right";if(d===Ct.center||d==="center")return"center";if(d===Ct.left||d==="left")return"left"}}}catch(a){console.error("Failed to get text align:",a)}}return"left"},Oi=(e,n)=>{qe.setFillColor(e,null,{getMemorizeKey:Qe,callback:(s,a)=>{if(!qt(e,s))return;const o=cs(n),l={type:"gradient",gradient:n,fallbackColor:o};q.setNode(e,{fill:o,fillConfig:l},a)}})},Jn=(e,n)=>{qe.setFillColor(e,null,{getMemorizeKey:Qe,callback:(s,a)=>{if(!qt(e,s))return;const o="#FFFFFF",l={type:"image",image:n,fallbackColor:o};q.setNode(e,{fill:o,fillConfig:l},a)}})},Ui=(e,n)=>{qe.setFillColor(e,null,{getMemorizeKey:Qe,callback:(s,a)=>{if(!qt(e,s))return;const o=s.fillConfig,l=s.fill;if((o==null?void 0:o.type)!==n)switch(n){case"solid":{let d="#FFFFFF";typeof l=="string"&&l!=="none"?d=l:o!=null&&o.solid&&(d=o.solid.color),q.setNode(e,{fill:d,fillConfig:void 0},a);break}case"gradient":{const d={type:"linear",angle:90,stops:[{offset:0,color:"#FFFFFF"},{offset:1,color:"#000000"}]},m=(o==null?void 0:o.gradient)||d,x=cs(m),h={type:"gradient",gradient:m,fallbackColor:x};q.setNode(e,{fill:x,fillConfig:h},a);break}case"image":{const d={imageUrl:"",mode:"stretch",scale:1,offsetX:0,offsetY:0,rotation:0},m="#FFFFFF",x={type:"image",image:(o==null?void 0:o.image)||d,fallbackColor:m};q.setNode(e,{fill:m,fillConfig:x},a);break}default:return}}})},$i=(e,n)=>{const s=Se(e);for(const a of s)if(we(a)){const o=e.children.findIndex(l=>l.id===a.id);o!==-1&&q.setNode(e,{fillColor:n},[o])}},Wi=({board:e,currentColor:n,fontColorIcon:s,title:a})=>{const[o,l]=i.useState(!1),d=te.getBoardContainer(e),m=i.useCallback(h=>{wi(e,n||h,h)},[e,n]),x=i.useCallback(h=>{n&&ki(e,n,h)},[e,n]);return t.jsxs(Ne,{sideOffset:12,open:o,onOpenChange:h=>{l(h)},placement:"top",children:[t.jsx(_e,{asChild:!0,children:t.jsx(oe,{className:z("property-button"),selected:o,visible:!0,icon:s,type:"button",tooltip:a,"aria-label":a,onPointerUp:()=>{l(!o)}})}),t.jsx(Ee,{container:d,children:t.jsx(ze,{padding:4,className:z(`${Ie}`),children:t.jsx(_t,{value:n,onChange:m,onOpacityChange:x})})})]})},Nn=[{key:"title",labelZh:"标题",labelEn:"Title",previewSize:26,...Ye.title},{key:"subtitle",labelZh:"副标题",labelEn:"Subtitle",previewSize:22,...Ye.subtitle},{key:"h1",labelZh:"标题 1",labelEn:"Heading 1",previewSize:20,...Ye.h1,divider:!0},{key:"h2",labelZh:"标题 2",labelEn:"Heading 2",previewSize:18,...Ye.h2},{key:"h3",labelZh:"标题 3",labelEn:"Heading 3",previewSize:16,...Ye.h3},{key:"h4",labelZh:"标题 4",labelEn:"Heading 4",previewSize:15,...Ye.h4},{key:"body",labelZh:"正文",labelEn:"Body",previewSize:14,...Ye.body,divider:!0},{key:"caption",labelZh:"注释",labelEn:"Caption",previewSize:13,...Ye.caption},{key:"footnote",labelZh:"脚注",labelEn:"Footnote",previewSize:12,...Ye.footnote}],Hi=e=>{if(!e)return null;const n=parseInt(e,10);if(isNaN(n))return null;for(const s of Nn)if(s.fontSize===n)return s.key;return null},Gi=({board:e,currentFontSize:n,title:s})=>{const[a,o]=i.useState(!1),{language:l}=je(),d=te.getBoardContainer(e),m=Hi(n),x=i.useCallback(p=>{zs(e,String(p.fontSize)),Ps(e,p.fontWeight),ot.setTextColor(e,p.color),o(!1)},[e]),h=(()=>{if(m){const p=Nn.find(j=>j.key===m);if(p)return l==="zh"?p.labelZh:p.labelEn}return n||"16"})();return t.jsxs(Ne,{sideOffset:12,open:a,onOpenChange:o,placement:"bottom",children:[t.jsx(_e,{asChild:!0,children:t.jsx(oe,{className:z("property-button"),selected:a,visible:!0,type:"button",tooltip:s,"aria-label":s,onPointerUp:()=>o(!a),children:t.jsx("div",{style:{fontSize:"12px",fontWeight:"bold",minWidth:"20px"},children:h})})}),t.jsx(Ee,{container:d,children:t.jsx(ze,{padding:4,className:z(`${Ie}`),children:t.jsxs(Xt.Col,{gap:0,style:{minWidth:"200px"},children:[t.jsx("div",{style:{fontSize:"12px",color:"#666",marginBottom:"2px",padding:"4px 10px 0"},children:l==="zh"?"字体样式":"Font Style"}),t.jsx("div",{style:{maxHeight:"320px",overflowY:"auto"},children:Nn.map(p=>{const j=m===p.key;return t.jsxs(ds.Fragment,{children:[p.divider&&t.jsx("div",{style:{height:"1px",backgroundColor:"#e8e8e8",margin:"4px 10px"}}),t.jsxs("div",{onClick:()=>x(p),style:{padding:"6px 10px",cursor:"pointer",backgroundColor:j?"#f0f7ff":"transparent",borderLeft:j?"3px solid #0052d9":"3px solid transparent",borderRadius:"2px",transition:"background-color 0.15s",display:"flex",alignItems:"baseline",justifyContent:"space-between",gap:"8px"},onMouseEnter:f=>{j||(f.currentTarget.style.backgroundColor="#f5f5f5")},onMouseLeave:f=>{j||(f.currentTarget.style.backgroundColor="transparent")},children:[t.jsx("span",{style:{fontSize:`${p.previewSize}px`,fontWeight:p.fontWeight,color:p.color,lineHeight:1.4},children:l==="zh"?p.labelZh:p.labelEn}),t.jsxs("span",{style:{fontSize:"11px",color:"#bbb",flexShrink:0},children:[p.fontSize,"px"]})]})]},p.key)})})]})})})]})},Vi=({board:e,currentColor:n,title:s,hasStrokeStyle:a,hasStrokeWidth:o,currentStrokeWidth:l,children:d})=>{const[m,x]=i.useState(!1),[h,p]=i.useState(String(l||2)),j=n&&pt(n),f=n?Nt(n):100,M=te.getBoardContainer(e);ds.useEffect(()=>{p(String(l||2))},[l]);const S=hs(f)?Zs:ps(j)?Ks:void 0,T=S?t.jsx(S,{}):void 0,v=c=>{vi(e,c)},P=i.useCallback(c=>{bi(e,c)},[e]),ne=i.useCallback(c=>{yi(e,c)},[e]),Q=i.useCallback(c=>{qn(e,c),p(String(c))},[e]),$=i.useCallback(c=>{p(c.target.value)},[]),w=i.useCallback(()=>{const c=parseInt(h,10);!isNaN(c)&&c>=1&&c<=100?qn(e,c):p(String(l||2))},[e,h,l]),g=i.useCallback(c=>{c.key==="Enter"?(w(),c.target.blur()):c.key==="Escape"&&(p(String(l||2)),c.target.blur())},[w,l]);return t.jsxs(Ne,{sideOffset:12,crossAxisOffset:40,open:m,onOpenChange:c=>{x(c)},placement:"left",children:[t.jsx(_e,{asChild:!0,children:t.jsx(oe,{className:z("property-button"),visible:!0,icon:T,type:"button",tooltip:s,"aria-label":s,onPointerUp:()=>{x(!m)},children:!T&&d})}),t.jsx(Ee,{container:M,children:t.jsx(ze,{padding:4,className:z(`${Ie}`,"stroke-setting",{"has-stroke-style":a}),children:t.jsxs(Xt.Col,{children:[o&&t.jsx("div",{className:"stroke-width-section",style:{marginBottom:"8px"},children:t.jsxs(Xt.Row,{gap:2,align:"center",children:[t.jsx("span",{style:{fontSize:"12px",color:"var(--color-on-surface)",whiteSpace:"nowrap"},children:"线宽:"}),t.jsx("div",{style:{flex:1,minWidth:"100px"},children:t.jsx(us,{value:l||2,min:1,max:100,step:1,onChange:c=>Q(c),label:!1})}),t.jsxs("div",{className:"stroke-width-input-wrapper",children:[t.jsx("input",{type:"text",inputMode:"numeric",pattern:"[0-9]*",value:h,onChange:$,onBlur:w,onKeyDown:g,className:"stroke-width-input"}),t.jsx("span",{className:"stroke-width-input-unit",children:"px"})]})]})}),a&&t.jsxs("div",{className:"stroke-style-section",children:[t.jsx("span",{className:"stroke-style-label",children:"样式:"}),t.jsxs(Xt.Row,{className:z("stroke-style-picker"),children:[t.jsx(oe,{visible:!0,icon:t.jsx(Vs,{}),type:"button",tooltip:"实线","aria-label":"实线",onPointerUp:()=>v(fn.solid)}),t.jsx(oe,{visible:!0,icon:t.jsx(Xs,{}),type:"button",tooltip:"虚线","aria-label":"虚线",onPointerUp:()=>v(fn.dashed)}),t.jsx(oe,{visible:!0,icon:t.jsx(Ys,{}),type:"button",tooltip:"点线","aria-label":"点线",onPointerUp:()=>v(fn.dotted)})]})]}),t.jsx(_t,{value:n,onChange:P,onOpacityChange:ne})]})})})]})},Xi="drawnix-color-history",es=24,ts=12,ns=qs.createInstance({name:"drawnix",storeName:Xi});let ee=null;function _n(e){const n=e.stops.map(s=>`${s.color}@${s.offset}`).join("|");return e.type==="linear"?`linear-${e.angle}-${n}`:`radial-${e.centerX}-${e.centerY}-${n}`}function Yi(e,n){return _n(e)===_n(n)}class Zi{constructor(){this.initialized=!1}async initialize(){if(!this.initialized)try{ee=await ns.getItem("history")||{colors:[],gradients:[]},this.initialized=!0}catch(n){console.error("[ColorHistoryService] Failed to initialize:",n),ee={colors:[],gradients:[]},this.initialized=!0}}async saveData(){if(ee)try{await ns.setItem("history",ee)}catch(n){console.error("[ColorHistoryService] Failed to save data:",n)}}async addColor(n){if(await this.initialize(),!ee)return;const s=n.toUpperCase(),a=ee.colors.findIndex(o=>o.color.toUpperCase()===s);if(a>=0){ee.colors[a].lastUsedAt=Date.now(),ee.colors[a].useCount+=1;const[o]=ee.colors.splice(a,1);ee.colors.unshift(o)}else ee.colors.unshift({color:s,lastUsedAt:Date.now(),useCount:1}),ee.colors.length>es&&(ee.colors=ee.colors.slice(0,es));await this.saveData()}async addGradient(n){if(await this.initialize(),!ee)return;const s=_n(n),a=ee.gradients.findIndex(o=>Yi(o.config,n));if(a>=0){ee.gradients[a].lastUsedAt=Date.now(),ee.gradients[a].useCount+=1;const[o]=ee.gradients.splice(a,1);ee.gradients.unshift(o)}else ee.gradients.unshift({id:s,config:{...n},lastUsedAt:Date.now(),useCount:1}),ee.gradients.length>ts&&(ee.gradients=ee.gradients.slice(0,ts));await this.saveData()}async getColors(){return await this.initialize(),(ee==null?void 0:ee.colors)||[]}async getGradients(){return await this.initialize(),(ee==null?void 0:ee.gradients)||[]}async removeColor(n){if(await this.initialize(),!ee)return;const s=n.toUpperCase();ee.colors=ee.colors.filter(a=>a.color.toUpperCase()!==s),await this.saveData()}async removeGradient(n){await this.initialize(),ee&&(ee.gradients=ee.gradients.filter(s=>s.id!==n),await this.saveData())}async clearAll(){ee={colors:[],gradients:[]},await this.saveData()}resetCache(){ee=null,this.initialized=!1}}const Ge=new Zi;function Ki(){const[e,n]=i.useState([]),[s,a]=i.useState([]),[o,l]=i.useState(!0),d=i.useCallback(async()=>{try{const[j,f]=await Promise.all([Ge.getColors(),Ge.getGradients()]);n(j),a(f)}catch(j){console.error("[useColorHistory] Failed to load data:",j)}finally{l(!1)}},[]);i.useEffect(()=>{d()},[d]);const m=i.useCallback(async j=>{await Ge.addColor(j);const f=await Ge.getColors();n(f)},[]),x=i.useCallback(async j=>{await Ge.addGradient(j);const f=await Ge.getGradients();a(f)},[]),h=i.useCallback(async j=>{await Ge.removeColor(j);const f=await Ge.getColors();n(f)},[]),p=i.useCallback(async j=>{await Ge.removeGradient(j);const f=await Ge.getGradients();a(f)},[]);return{colors:e,gradients:s,isLoading:o,addColor:m,addGradient:x,removeColor:h,removeGradient:p,refresh:d}}function ut(e){const n=e.stops.map(s=>`${s.color} ${Math.round(s.offset*100)}%`).join(", ");if(e.type==="linear")return`linear-gradient(${e.angle}deg, ${n})`;{const s=Math.round(e.centerX*100),a=Math.round(e.centerY*100);return`radial-gradient(circle at ${s}% ${a}%, ${n})`}}function qi(e){const n=e.match(/linear-gradient\((\d+)deg,\s*(.+)\)/);if(n){const a=parseInt(n[1],10),o=n[2],l=ss(o);return{type:"linear",angle:a,stops:l.length>=2?l:[{color:"#FF6B6B",offset:0},{color:"#4ECDC4",offset:1}]}}const s=e.match(/radial-gradient\(circle(?:\s+at\s+(\d+)%\s+(\d+)%)?,\s*(.+)\)/);if(s){const a=s[1]?parseInt(s[1],10)/100:.5,o=s[2]?parseInt(s[2],10)/100:.5,l=s[3],d=ss(l);return{type:"radial",centerX:a,centerY:o,stops:d.length>=2?d:[{color:"#FF6B6B",offset:0},{color:"#4ECDC4",offset:1}]}}return cn}function ss(e){const n=[],s=/(#[0-9a-fA-F]{3,8}|rgba?\([^)]+\))\s+(\d+)%/g;let a;for(;(a=s.exec(e))!==null;)n.push({color:a[1],offset:parseInt(a[2],10)/100});return n}const os=[{key:"left",labelZh:"左",labelEn:"Left",x:0,y:.5},{key:"center",labelZh:"中心",labelEn:"Center",x:.5,y:.5},{key:"top-left",labelZh:"左上",labelEn:"Top left",x:0,y:0},{key:"top",labelZh:"上",labelEn:"Top",x:.5,y:0},{key:"right",labelZh:"右",labelEn:"Right",x:1,y:.5},{key:"bottom",labelZh:"下",labelEn:"Bottom",x:.5,y:1}],Ts=({value:e,onChange:n,showPresets:s=!0,showHistory:a=!0,presetCategories:o,customPresets:l,compact:d=!1,inline:m=!1,onSavePreset:x,onDeletePreset:h})=>{const{language:p}=je(),{addGradient:j}=Ki(),[f,M]=i.useState(e||cn),[S,T]=i.useState(0),[v,P]=i.useState(null),[ne,Q]=i.useState(!1),$=i.useRef(null);i.useEffect(()=>{e&&M(e)},[e]);const w=i.useCallback(_=>{M(_),n==null||n(_),j(_)},[n,j]),g=i.useCallback(_=>{w(_.config)},[w]),c=i.useCallback(_=>{const K={...f,..._};w(K)},[f,w]),C=i.useCallback(_=>{if(f.type!==_)if(_==="linear"){const K={type:"linear",angle:90,stops:f.stops};w(K)}else{const K={type:"radial",centerX:.5,centerY:.5,stops:f.stops};w(K)}},[f,w]),N=i.useCallback((_,K)=>{const X=[...f.stops];X[_]={...X[_],...K},X.sort((ce,ge)=>ce.offset-ge.offset);const le=X.findIndex(ce=>ce.color===(K.color??f.stops[_].color));le!==-1&&le!==S&&T(le),c({stops:X})},[f.stops,S,c]),Y=i.useCallback(()=>{if(f.stops.length>=8)return;const _=.5,X=[...f.stops,{color:"#888888",offset:_}].sort((le,ce)=>le.offset-ce.offset);c({stops:X}),T(X.findIndex(le=>le.offset===_))},[f.stops,c]),se=i.useCallback(_=>{if(f.stops.length<=2)return;const K=f.stops.filter((X,le)=>le!==_);c({stops:K}),T(Math.min(S,K.length-1))},[f.stops,S,c]),B=i.useCallback((_,K)=>{if(!$.current)return;const X=$.current.getBoundingClientRect(),ce=Math.max(0,Math.min(_.clientX-X.left,X.width))/X.width;N(K,{offset:ce})},[N]),he=i.useCallback((_,K)=>{_.preventDefault(),_.stopPropagation(),T(K);const X=_.clientX,le=_.clientY;let ce=!1;const ge=3,k=Me=>{const Oe=Math.abs(Me.clientX-X),xe=Math.abs(Me.clientY-le);(Oe>ge||xe>ge)&&(ce=!0,Q(!0),B(Me,K))},Te=()=>{document.removeEventListener("mousemove",k),document.removeEventListener("mouseup",Te),ce||P(K),setTimeout(()=>{Q(!1)},0)};document.addEventListener("mousemove",k),document.addEventListener("mouseup",Te)},[B]),V=i.useCallback(_=>{if(ne||f.stops.length>=8||_.target!==$.current||!$.current)return;const X=$.current.getBoundingClientRect(),le=_.clientX-X.left,ce=Math.max(0,Math.min(le/X.width,1)),ge=[...f.stops].sort((xe,Ve)=>xe.offset-Ve.offset);let k=ge[0];for(let xe=0;xe<ge.length-1;xe++)if(ge[xe].offset<=ce&&ge[xe+1].offset>=ce){k=ge[xe];break}const Te=k.color,Me=[...f.stops,{color:Te,offset:ce}].sort((xe,Ve)=>xe.offset-Ve.offset);c({stops:Me});const Oe=Me.findIndex(xe=>xe.offset===ce);T(Oe)},[ne,f.stops,c]);i.useMemo(()=>ut(f),[f]),i.useMemo(()=>{const _=[{key:"basic",label:p==="zh"?"基础":"Basic"},{key:"colorful",label:p==="zh"?"多彩":"Colorful"},{key:"sunset",label:p==="zh"?"日落":"Sunset"},{key:"nature",label:p==="zh"?"自然":"Nature"},{key:"metal",label:p==="zh"?"金属":"Metal"}];return o?_.filter(K=>o.includes(K.key)):_},[p,o]);const F=i.useMemo(()=>l?l.length>0&&typeof l[0]=="string"?l.map((_,K)=>({id:`custom-${K}`,name:`Custom ${K+1}`,nameZh:`自定义 ${K+1}`,category:"custom",config:qi(_),css:_})):l:An,[l]),L=i.useCallback(()=>{var X;if(f.type!=="radial")return null;const{centerX:_,centerY:K}=f;return(X=os.find(le=>Math.abs(le.x-_)<.01&&Math.abs(le.y-K)<.01))==null?void 0:X.key},[f]),ie=i.useMemo(()=>l&&l.length>0&&typeof l[0]=="string",[l]),ke=i.useMemo(()=>ut(f),[f]),Pe=i.useCallback(_=>ke===_,[ke]),mt=()=>{const _=An.slice(0,10),K=ie?F:[];return t.jsxs("div",{className:"ge-quick-presets",children:[t.jsx("div",{className:"ge-quick-presets-header",children:t.jsx("span",{className:"ge-quick-presets-title",children:p==="zh"?"预设":"Presets"})}),t.jsxs("div",{className:"ge-quick-presets-grid",children:[K.map((X,le)=>{const ce=X.css||ut(X.config);return t.jsx(ae,{content:p==="zh"?X.nameZh:X.name,showArrow:!1,children:t.jsxs("button",{className:z("ge-quick-preset-item ge-quick-preset-item--custom",{"ge-quick-preset-item--selected":Pe(ce)}),onClick:()=>g(X),children:[t.jsx("div",{className:"ge-quick-preset-preview",style:{background:ce}}),h&&t.jsx("button",{className:"ge-quick-preset-delete",onClick:ge=>{ge.stopPropagation(),h(le)},children:"×"})]})},X.id)}),_.map(X=>{const le=ut(X.config);return t.jsx(ae,{content:p==="zh"?X.nameZh:X.name,showArrow:!1,children:t.jsx("button",{className:z("ge-quick-preset-item",{"ge-quick-preset-item--selected":Pe(le)}),onClick:()=>g(X),children:t.jsx("div",{className:"ge-quick-preset-preview",style:{background:le}})})},X.id)})]})]})},Re=()=>t.jsxs("div",{className:z("ge-custom-editor",{"ge-custom-editor--inline":m}),children:[t.jsx("div",{className:"ge-type-section",children:t.jsxs("div",{className:"ge-type-buttons",children:[t.jsx("button",{className:z("ge-type-btn",{active:f.type==="linear"}),onClick:()=>C("linear"),children:p==="zh"?"线性":"Linear"}),t.jsx("button",{className:z("ge-type-btn",{active:f.type==="radial"}),onClick:()=>C("radial"),children:p==="zh"?"径向":"Radial"})]})}),t.jsxs("div",{className:"ge-color-section",children:[t.jsxs("div",{className:"ge-section-header",children:[t.jsx("span",{className:"ge-section-title",children:p==="zh"?"颜色":"Colors"}),t.jsxs("div",{className:"ge-stop-actions",children:[t.jsx(ae,{content:p==="zh"?"添加色标":"Add stop",showArrow:!1,children:t.jsx("button",{className:"ge-action-btn",onClick:Y,disabled:f.stops.length>=8,children:"+"})}),t.jsx(ae,{content:p==="zh"?"删除色标":"Remove stop",showArrow:!1,children:t.jsx("button",{className:"ge-action-btn",onClick:()=>se(S),disabled:f.stops.length<=2,children:"−"})})]})]}),t.jsx("div",{className:"ge-gradient-bar-wrapper",children:t.jsx("div",{ref:$,className:"ge-gradient-bar",style:{background:`linear-gradient(90deg, ${f.stops.map(_=>`${_.color} ${Math.round(_.offset*100)}%`).join(", ")})`},onClick:V,children:f.stops.map((_,K)=>t.jsxs(Ne,{open:v===K,onOpenChange:X=>P(X?K:null),children:[t.jsx(_e,{asChild:!0,children:t.jsx("button",{className:z("ge-stop-handle",{selected:S===K}),style:{left:`${_.offset*100}%`,backgroundColor:_.color},onMouseDown:X=>{he(X,K)}})}),t.jsx(Ee,{children:t.jsx(ze,{padding:4,className:"ge-color-picker-popover "+Ie,children:t.jsx(_t,{value:_.color,onChange:X=>N(K,{color:X}),showAlpha:!1,showEyeDropper:!0,showPresets:!0,showRecentColors:!0,showHexInput:!0})})})]},K))})})]}),f.type==="radial"&&t.jsxs("div",{className:"ge-origin-section",children:[t.jsx("span",{className:"ge-section-title",children:p==="zh"?"原点":"Origin"}),t.jsx("div",{className:"ge-origin-buttons",children:os.map(_=>t.jsx("button",{className:z("ge-origin-btn",{active:L()===_.key}),onClick:()=>c({centerX:_.x,centerY:_.y}),children:p==="zh"?_.labelZh:_.labelEn},_.key))})]}),f.type==="linear"&&t.jsxs("div",{className:"ge-angle-section",children:[t.jsxs("div",{className:"ge-section-header",children:[t.jsx("span",{className:"ge-section-title",children:p==="zh"?"角度":"Angle"}),t.jsxs("span",{className:"ge-angle-value",children:[f.angle,"°"]})]}),t.jsx("input",{type:"range",min:0,max:360,value:f.angle,onChange:_=>c({angle:Number(_.target.value)}),className:"ge-angle-slider"})]}),x&&t.jsx("div",{className:"ge-save-section",children:t.jsx("button",{className:"ge-save-btn",onClick:x,children:p==="zh"?"保存":"Save"})}),mt()]});return d||m?t.jsx("div",{className:z("gradient-editor",{"gradient-editor--compact":d,"gradient-editor--inline":m}),children:Re()}):t.jsx("div",{className:"gradient-editor",children:Re()})},vn=ms.CUSTOM_GRADIENTS,Qi=({value:e,onChange:n,inline:s=!1})=>{const{language:a}=je(),{confirm:o,confirmDialog:l}=zn(),[d,m]=i.useState([]),[x,h]=i.useState(e||cn);i.useEffect(()=>{let M=!0;return St.get(vn).then(S=>{M&&S&&m(S)}).catch(S=>{console.warn("Failed to load gradient data:",S)}),()=>{M=!1}},[]),i.useEffect(()=>{e&&h(e)},[e]);const p=i.useCallback(M=>{h(M),n==null||n(M)},[n]),j=i.useCallback(()=>{const M=ut(x),T=[{id:`custom-${Date.now()}`,css:M},...d].slice(0,8);m(T),St.set(vn,T).catch(v=>{console.warn("Failed to save custom gradients:",v)})},[x,d]),f=i.useCallback(async M=>{const S=d[M];if(!S||!await o({title:a==="zh"?"确认删除渐变预设":"Delete Gradient Preset",description:a==="zh"?"确定要删除这个自定义渐变预设吗?":"Are you sure you want to delete this custom gradient preset?",confirmText:a==="zh"?"删除":"Delete",cancelText:a==="zh"?"取消":"Cancel",danger:!0}))return;const v=d.filter(P=>P.id!==S.id);m(v),St.set(vn,v).catch(P=>{console.warn("Failed to save custom gradients:",P)})},[o,d,a]);return t.jsxs(t.Fragment,{children:[t.jsx(Ts,{value:x,onChange:p,showPresets:!0,showHistory:!0,inline:s,customPresets:d.map(M=>M.css),onSavePreset:j,onDeletePreset:f}),l]})},Ji=i.lazy(()=>De(()=>import("./ai-chat-BnWVpTEI.js").then(e=>e.s_),__vite__mapDeps([0]),import.meta.url).then(e=>({default:e.MediaLibraryModal}))),el=[{value:"stretch",labelZh:"拉伸",labelEn:"Stretch",icon:"⬌"},{value:"tile",labelZh:"平铺",labelEn:"Tile",icon:"⊞"},{value:"fit",labelZh:"适应",labelEn:"Fit",icon:"⊡"}],tl=({value:e,onChange:n,onOpenMediaLibrary:s,externalMediaLibraryControl:a=!1})=>{const{language:o}=je(),[l,d]=i.useState(e||fs),[m,x]=i.useState(!1),[h,p]=i.useState(!1),j=i.useRef(null);i.useEffect(()=>{e&&d(e)},[e]);const f=i.useCallback(w=>{const g={...l,...w};d(g),n==null||n(g)},[l,n]),M=i.useMemo(()=>Qs(w=>{n==null||n(w)},300),[n]),S=i.useCallback(w=>{const g={...l,...w};d(g),M(g)},[l,M]),T=i.useCallback((w,g,c,C,N=1)=>{const Y=parseFloat(g);if(isNaN(Y))return;const se=Math.max(c,Math.min(C,Y)),B=N===1?se:se/N;f({[w]:B})},[f]),v=i.useCallback(w=>{f({imageUrl:w.url}),x(!1)},[f]),P=i.useCallback(async w=>{var N;const g=(N=w.target.files)==null?void 0:N[0];if(!g)return;if(!g.type.startsWith("image/")){W.warning(o==="zh"?"请选择图片文件":"Please select an image file");return}if(g.size>25*1024*1024){W.warning(o==="zh"?"图片大小不能超过 25MB":"Image size cannot exceed 25MB");return}let c=g;if(g.size>10*1024*1024){const Y=Js(g.size/1048576),se=W.loading({content:o==="zh"?`正在压缩图片 (${(g.size/1024/1024).toFixed(1)}MB)...`:`Compressing image (${(g.size/1024/1024).toFixed(1)}MB)...`,duration:0,placement:"top"});try{c=await eo(g,Y.targetSizeMB),W.close(se),W.success({content:o==="zh"?`压缩完成: ${(g.size/1024/1024).toFixed(1)}MB → ${(c.size/1024/1024).toFixed(1)}MB`:`Compressed: ${(g.size/1024/1024).toFixed(1)}MB → ${(c.size/1024/1024).toFixed(1)}MB`,duration:2})}catch(B){W.close(se),console.error("[ImageFillPanel] Compression failed:",B),W.warning(o==="zh"?"图片压缩失败":"Image compression failed");return}}const C=new FileReader;C.onload=Y=>{var B;const se=(B=Y.target)==null?void 0:B.result;f({imageUrl:se})},C.readAsDataURL(c),w.target.value=""},[o,f]),ne=i.useCallback(()=>{var w;(w=j.current)==null||w.click()},[]),Q=i.useCallback(()=>{a&&s?s():x(!0)},[a,s]),$=()=>l.imageUrl?t.jsxs("div",{className:"ifp-image-preview",children:[t.jsx("img",{src:l.imageUrl,alt:"Fill preview"}),t.jsx(ae,{content:o==="zh"?"移除图片":"Remove image",showArrow:!1,children:t.jsx("button",{className:"ifp-image-remove",onClick:()=>f({imageUrl:""}),children:"×"})})]}):t.jsxs("div",{className:"ifp-image-placeholder",children:[t.jsx(bs,{size:32,className:"ifp-placeholder-icon"}),t.jsx("span",{className:"ifp-placeholder-text",children:o==="zh"?"选择图片":"Select Image"})]});return t.jsxs("div",{className:"image-fill-panel",children:[t.jsx("input",{ref:j,type:"file",accept:"image/*",style:{display:"none"},onChange:P}),t.jsxs("div",{className:"ifp-image-section",children:[t.jsx("div",{className:"ifp-image-container",onClick:()=>!l.imageUrl&&Q(),children:$()}),t.jsxs("div",{className:"ifp-image-actions",children:[t.jsxs("button",{className:"ifp-action-btn ifp-action-btn--primary",onClick:Q,children:[t.jsx(to,{size:14}),t.jsx("span",{children:o==="zh"?"素材库":"Library"})]}),t.jsxs("button",{className:"ifp-action-btn",onClick:ne,children:[t.jsx(no,{size:14}),t.jsx("span",{children:o==="zh"?"上传":"Upload"})]})]})]}),l.imageUrl&&t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"ifp-control-section",children:[t.jsx("div",{className:"ifp-section-title",children:o==="zh"?"平铺模式":"Fill Mode"}),t.jsx("div",{className:"ifp-mode-buttons",children:el.map(w=>t.jsx(ae,{content:o==="zh"?w.labelZh:w.labelEn,showArrow:!1,children:t.jsxs("button",{className:z("ifp-mode-btn",{active:l.mode===w.value}),onClick:()=>f({mode:w.value}),children:[t.jsx("span",{className:"ifp-mode-icon",children:w.icon}),t.jsx("span",{className:"ifp-mode-label",children:o==="zh"?w.labelZh:w.labelEn})]})},w.value))})]}),t.jsxs("div",{className:"ifp-advanced-section",children:[t.jsxs("button",{className:"ifp-advanced-toggle",onClick:()=>p(!h),children:[t.jsx("span",{children:o==="zh"?"高级设置":"Advanced"}),h?t.jsx(so,{size:14}):t.jsx(gs,{size:14})]}),h&&t.jsxs("div",{className:"ifp-advanced-content",children:[t.jsxs("div",{className:"ifp-control-row",children:[t.jsx("label",{className:"ifp-control-label",children:o==="zh"?"缩放":"Scale"}),t.jsxs("div",{className:"ifp-control-input",children:[t.jsx("input",{type:"range",min:50,max:200,value:(l.scale??1)*100,onChange:w=>S({scale:Number(w.target.value)/100}),className:"ifp-slider"}),t.jsxs("div",{className:"ifp-control-value-wrapper",children:[t.jsx("input",{type:"number",className:"ifp-control-value-input",value:Math.round((l.scale??1)*100),min:50,max:200,onChange:w=>T("scale",w.target.value,50,200,100)}),t.jsx("span",{className:"ifp-control-unit",children:"%"})]})]})]}),t.jsxs("div",{className:"ifp-control-row",children:[t.jsx("label",{className:"ifp-control-label",children:o==="zh"?"X 偏移":"Offset X"}),t.jsxs("div",{className:"ifp-control-input",children:[t.jsx("input",{type:"range",min:-100,max:100,value:(l.offsetX??0)*100,onChange:w=>S({offsetX:Number(w.target.value)/100}),className:"ifp-slider"}),t.jsxs("div",{className:"ifp-control-value-wrapper",children:[t.jsx("input",{type:"number",className:"ifp-control-value-input",value:Math.round((l.offsetX??0)*100),min:-100,max:100,onChange:w=>T("offsetX",w.target.value,-100,100,100)}),t.jsx("span",{className:"ifp-control-unit",children:"%"})]})]})]}),t.jsxs("div",{className:"ifp-control-row",children:[t.jsx("label",{className:"ifp-control-label",children:o==="zh"?"Y 偏移":"Offset Y"}),t.jsxs("div",{className:"ifp-control-input",children:[t.jsx("input",{type:"range",min:-100,max:100,value:(l.offsetY??0)*100,onChange:w=>S({offsetY:Number(w.target.value)/100}),className:"ifp-slider"}),t.jsxs("div",{className:"ifp-control-value-wrapper",children:[t.jsx("input",{type:"number",className:"ifp-control-value-input",value:Math.round((l.offsetY??0)*100),min:-100,max:100,onChange:w=>T("offsetY",w.target.value,-100,100,100)}),t.jsx("span",{className:"ifp-control-unit",children:"%"})]})]})]}),t.jsxs("div",{className:"ifp-control-row",children:[t.jsx("label",{className:"ifp-control-label",children:o==="zh"?"旋转":"Rotation"}),t.jsxs("div",{className:"ifp-control-input",children:[t.jsx("input",{type:"range",min:0,max:360,value:l.rotation??0,onChange:w=>S({rotation:Number(w.target.value)}),className:"ifp-slider"}),t.jsxs("div",{className:"ifp-control-value-wrapper",children:[t.jsx("input",{type:"number",className:"ifp-control-value-input",value:l.rotation??0,min:0,max:360,onChange:w=>T("rotation",w.target.value,0,360,1)}),t.jsx("span",{className:"ifp-control-unit",children:"°"})]})]})]}),t.jsx("button",{className:"ifp-reset-btn",onClick:()=>f({scale:1,offsetX:0,offsetY:0,rotation:0}),children:o==="zh"?"重置":"Reset"})]})]})]}),!a&&m&&t.jsx(i.Suspense,{fallback:null,children:t.jsx(Ji,{isOpen:m,onClose:()=>x(!1),mode:ys.SELECT,filterType:xs.IMAGE,onSelect:v,selectButtonText:o==="zh"?"使用此图片":"Use this image"})})]})},nl=[{value:"solid",labelZh:"纯色",labelEn:"Solid"},{value:"gradient",labelZh:"渐变",labelEn:"Gradient"},{value:"image",labelZh:"图片",labelEn:"Image"}],sl=({value:e,onSolidChange:n,onOpacityChange:s,onGradientChange:a,onImageChange:o,onFillTypeChange:l,showClose:d=!1,onClose:m,onOpenMediaLibrary:x})=>{const{language:h}=je(),p=i.useMemo(()=>e?Yt(e)?oo(e):ht(e)?e:{type:"solid",solid:{color:"#FFFFFF"}}:{type:"solid",solid:{color:"#FFFFFF"}},[e]),[j,f]=i.useState(p.type);i.useEffect(()=>{f(p.type)},[p.type]);const[M,S]=i.useState(p.gradient||cn),[T,v]=i.useState(p.image||fs);i.useEffect(()=>{p.gradient&&S(p.gradient)},[p.gradient]),i.useEffect(()=>{p.image&&v(p.image)},[p.image]);const P=i.useCallback(g=>{f(g)},[]),ne=i.useCallback(g=>{l==null||l("solid"),n==null||n(g)},[n,l]),Q=i.useCallback(g=>{S(g),l==null||l("gradient"),a==null||a(g)},[a,l]),$=i.useCallback(g=>{v(g),l==null||l("image"),o==null||o(g)},[o,l]),w=i.useMemo(()=>Yt(e)?e:ht(e)&&e.solid?e.solid.color:"#FFFFFF",[e]);return t.jsxs("div",{className:"fill-panel",children:[t.jsxs("div",{className:"fill-panel__header",children:[t.jsx("span",{className:"fill-panel__title",children:h==="zh"?"填充":"Fill"}),d&&t.jsx("button",{className:"fill-panel__close",onClick:m,children:"×"})]}),t.jsx("div",{className:"fill-panel__tabs",children:nl.map(g=>t.jsx("button",{className:z("fill-panel__tab",{active:j===g.value}),onClick:()=>P(g.value),children:h==="zh"?g.labelZh:g.labelEn},g.value))}),t.jsxs("div",{className:"fill-panel__content",children:[j==="solid"&&t.jsx("div",{className:"fill-panel__solid",children:t.jsx(_t,{value:w,onChange:ne,onOpacityChange:s})}),j==="gradient"&&t.jsx(Qi,{value:M,onChange:Q}),j==="image"&&t.jsx(tl,{value:T,onChange:$,onOpenMediaLibrary:x,externalMediaLibraryControl:!!x})]})]})},ol=i.lazy(()=>De(()=>import("./index-291TeU7i.js"),__vite__mapDeps([0,1]),import.meta.url).then(e=>({default:e.MediaLibraryModal}))),al=({board:e,currentColor:n,title:s,children:a})=>{const{language:o}=je(),[l,d]=i.useState(!1),[m,x]=i.useState(!1),{hexColor:h,opacity:p}=i.useMemo(()=>{var $;if(!n)return{hexColor:void 0,opacity:100};if(Yt(n)){const w=pt(n),g=Nt(n);return{hexColor:w,opacity:g}}if(ht(n))switch(n.type){case"solid":if(n.solid){const w=pt(n.solid.color),g=Nt(n.solid.color);return{hexColor:w,opacity:g}}break;case"gradient":if(($=n.gradient)!=null&&$.stops[0])return{hexColor:n.gradient.stops[0].color,opacity:100};break;case"image":return{hexColor:"#888888",opacity:100}}return{hexColor:void 0,opacity:100}},[n]),j=!h||hs(p)?t.jsx(ao,{}):void 0,f=i.useCallback($=>{xi(e,$),$i(e,$)},[e]),M=i.useCallback($=>{gi(e,$)},[e]),S=i.useCallback($=>{Oi(e,$)},[e]),T=i.useCallback($=>{Jn(e,$)},[e]),v=i.useCallback($=>{Ui(e,$)},[e]),P=i.useCallback(()=>{d(!1)},[]),ne=i.useCallback(()=>{x(!0)},[]),Q=i.useCallback($=>{Jn(e,{imageUrl:$.url,mode:"stretch",scale:1,offsetX:0,offsetY:0,rotation:0}),x(!1)},[e]);return t.jsxs(Ne,{sideOffset:12,crossAxisOffset:40,open:l,onOpenChange:$=>{!$&&m||d($)},placement:"left",children:[t.jsx(_e,{asChild:!0,children:t.jsx(oe,{className:z("property-button"),visible:!0,icon:j,type:"button",tooltip:s,"aria-label":s,onPointerUp:()=>{d(!l)},children:!j&&a})}),t.jsx(Ee,{children:t.jsx(ze,{padding:0,className:z(`${Ie}`,"fill-setting"),children:t.jsx(sl,{value:n,onSolidChange:f,onOpacityChange:M,onGradientChange:S,onImageChange:T,onFillTypeChange:v,showClose:!0,onClose:P,onOpenMediaLibrary:ne})})}),m&&t.jsx(i.Suspense,{fallback:null,children:t.jsx(ol,{isOpen:m,onClose:()=>x(!1),mode:ys.SELECT,filterType:xs.IMAGE,onSelect:Q,selectButtonText:o==="zh"?"使用此图片":"Use this image"})})]})},il=({board:e,currentRadius:n,title:s,selectionRect:a})=>{const[o,l]=i.useState(!1),[d,m]=i.useState({top:0,left:0}),[x,h]=i.useState(""),p=i.useRef(null),j=i.useRef(null),f=te.getBoardContainer(e),{t:M}=je(),S=s||M("toolbar.cornerRadius")||"圆角",T=n??0;i.useEffect(()=>{h(String(T))},[T]),i.useEffect(()=>{if(o&&p.current){const g=p.current.getBoundingClientRect(),c=220,C=8;let N=g.left+g.width/2-c/2,Y=g.bottom+C;const se=window.innerWidth,B=window.innerHeight;N+c>se-16&&(N=se-c-16),N<16&&(N=16),Y+40>B-16&&(Y=g.top-40-C),m({left:N,top:Y})}},[o]),i.useEffect(()=>{if(!o)return;const g=C=>{const N=C.target;j.current&&j.current.contains(N)||p.current&&p.current.contains(N)||N.closest(".popup-toolbar")!==null||l(!1)},c=setTimeout(()=>{document.addEventListener("mousedown",g)},100);return()=>{clearTimeout(c),document.removeEventListener("mousedown",g)}},[o]);const v=i.useCallback(g=>{const c=Math.max(0,Math.min(100,g));Se(e).filter(N=>Ke.isPenPath(N)).forEach(N=>{const Y=e.children.findIndex(se=>se.id===N.id);Y>=0&&q.setNode(e,{cornerRadius:c},[Y])})},[e]),P=i.useCallback(g=>{h(String(g)),v(g)},[v]),ne=i.useCallback(g=>{h(g.target.value)},[]),Q=i.useCallback(()=>{const g=parseInt(x,10);if(isNaN(g))h(String(T));else{const c=Math.max(0,Math.min(100,g));h(String(c)),v(c)}},[x,T,v]),$=i.useCallback(g=>{g.key==="Enter"&&g.target.blur()},[]),w=i.useCallback(()=>{l(!o)},[o]);return t.jsxs(t.Fragment,{children:[t.jsx(oe,{ref:p,className:z("property-button","corner-radius-button",{"is-active":o}),visible:!0,type:"button",tooltip:S,"aria-label":S,onPointerUp:w,children:t.jsx("svg",{viewBox:"0 0 24 24",width:"18",height:"18",children:t.jsx("path",{d:"M4 4 L4 14 Q4 20 10 20 L20 20",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})})}),o&&f&&io.createPortal(t.jsx("div",{ref:j,className:z(Ie,"corner-radius-panel"),style:{position:"fixed",top:d.top,left:d.left,zIndex:5e3},onPointerDown:g=>g.stopPropagation(),onMouseDown:g=>g.stopPropagation(),children:t.jsx(ze,{padding:2,className:"corner-radius-setting-compact",children:t.jsxs("div",{className:"corner-radius-row",children:[t.jsx("span",{className:"corner-radius-label",children:S}),t.jsx("div",{className:"corner-radius-slider",children:t.jsx(us,{value:T,min:0,max:100,step:1,onChange:g=>P(g),label:!1})}),t.jsx("input",{type:"text",className:"corner-radius-input",value:x,onChange:ne,onBlur:Q,onKeyDown:$}),t.jsx("span",{className:"corner-radius-unit",children:"%"})]})})}),f)]})},ll=(e,n)=>{try{return st(e,[n],!1)}catch{return null}},as=(e,n,s,a,o,l)=>{const d=e.children.findIndex(S=>S.id===n.id);if(d<0)return;const m=ll(e,n);if(!m)return;const x=(m.x-s.x)/s.width,h=(m.y-s.y)/s.height,p=a.x+x*a.width,j=a.y+h*a.height,f=m.width*o,M=m.height*l;if(Be(n)){const S=[[p,j],[p+f,j+M]];q.setNode(e,{points:S},[d])}else if(U.isDrawElement(n)){const S=[[p,j],[p+f,j+M]];q.setNode(e,{points:S},[d])}else if(Le.isMindElement(e,n)){const S=[[p,j],[p+f,j+M]];q.setNode(e,{points:S},[d])}else if(at.isFreehand(n)){const T=n.points.map(v=>{const P=(v[0]-s.x)/s.width,ne=(v[1]-s.y)/s.height;return[a.x+P*a.width,a.y+ne*a.height]});q.setNode(e,{points:T},[d])}else if(Ke.isPenPath(n)){const T=n.anchors.map(P=>{const ne=[P.point[0]*o,P.point[1]*l],Q=P.handleIn?[P.handleIn[0]*o,P.handleIn[1]*l]:void 0,$=P.handleOut?[P.handleOut[0]*o,P.handleOut[1]*l]:void 0;return{...P,point:ne,handleIn:Q,handleOut:$}}),v=[p,j];q.setNode(e,{points:[v,v],anchors:T},[d])}},rl=({board:e})=>{const{language:n}=je(),s=n==="zh",a=Se(e),[o,l]=i.useState(!0),[d,m]=i.useState(""),[x,h]=i.useState(""),[p,j]=i.useState(1),[f,M]=i.useState(!1),S=i.useRef(null),T=te.getBoardContainer(e),v=a.length>0?st(e,a,!1):null;i.useEffect(()=>{v&&(S.current?(m(Math.round(S.current.width).toString()),h(Math.round(S.current.height).toString()),S.current=null):(m(Math.round(v.width).toString()),h(Math.round(v.height).toString())),j(v.width/v.height))},[v==null?void 0:v.width,v==null?void 0:v.height]);const P=i.useCallback(g=>{const c=g.target.value;if(m(c),o&&v){const C=parseFloat(c);if(!isNaN(C)&&C>0){const N=Math.round(C/p);h(N.toString())}}},[o,p,v]),ne=i.useCallback(g=>{const c=g.target.value;if(h(c),o&&v){const C=parseFloat(c);if(!isNaN(C)&&C>0){const N=Math.round(C*p);m(N.toString())}}},[o,p,v]),Q=i.useCallback(()=>{if(!v||a.length===0)return;const g=parseFloat(d),c=parseFloat(x);if(isNaN(g)||isNaN(c)||g<=0||c<=0){m(Math.round(v.width).toString()),h(Math.round(v.height).toString());return}if(Math.abs(g-v.width)<.5&&Math.abs(c-v.height)<.5)return;S.current={width:g,height:c};const C=g/v.width,N=c/v.height,Y={x:v.x,y:v.y,width:g,height:c};a.forEach(se=>{as(e,se,v,Y,C,N)})},[e,a,v,d,x]),$=i.useCallback(g=>{if(!v||a.length===0)return;const c=g.width,C=g.height;m(c.toString()),h(C.toString()),S.current={width:c,height:C};const N=c/v.width,Y=C/v.height,se={x:v.x,y:v.y,width:c,height:C};a.forEach(B=>{as(e,B,v,se,N,Y)}),j(c/C),M(!1)},[e,a,v]),w=i.useCallback(g=>{g.key==="Enter"?(Q(),g.target.blur()):g.key==="Escape"&&(v&&(m(Math.round(v.width).toString()),h(Math.round(v.height).toString())),g.target.blur())},[Q,v]);return v?t.jsxs("div",{className:"size-input-container",children:[t.jsxs("div",{className:"size-input-group",children:[t.jsx("span",{className:"size-input-label",children:"W"}),t.jsx("input",{type:"text",inputMode:"numeric",pattern:"[0-9]*",className:"size-input",value:d,onChange:P,onBlur:Q,onKeyDown:w})]}),t.jsx(ae,{content:o?"解锁比例":"锁定比例",showArrow:!1,children:t.jsx("button",{className:`size-lock-button ${o?"locked":""}`,onClick:()=>l(!o),children:o?t.jsx(lo,{}):t.jsx(ro,{})})}),t.jsxs("div",{className:"size-input-group",children:[t.jsx("span",{className:"size-input-label",children:"H"}),t.jsx("input",{type:"text",inputMode:"numeric",pattern:"[0-9]*",className:"size-input",value:x,onChange:ne,onBlur:Q,onKeyDown:w})]}),t.jsxs(Ne,{open:f,onOpenChange:M,placement:"bottom-end",sideOffset:8,children:[t.jsx(ae,{content:s?"常用尺寸":"Preset Sizes",showArrow:!1,children:t.jsx(_e,{className:`size-preset-button ${f?"active":""}`,onClick:()=>M(!f),children:t.jsx(gs,{size:12})})}),t.jsx(Ee,{container:T,children:t.jsx("div",{className:"size-preset-panel",children:ni.map(g=>t.jsxs("div",{className:"size-preset-category",children:[t.jsx("div",{className:"size-preset-category-label",children:s?g.category:g.categoryEn}),g.items.map(c=>t.jsxs("button",{className:"size-preset-item",onClick:()=>$(c),children:[t.jsx("span",{className:"size-preset-item-label",children:s?c.label:c.labelEn}),t.jsxs("span",{className:"size-preset-item-size",children:[c.width," x ",c.height]})]},`${c.width}x${c.height}-${c.label}`))]},g.category))})})]})]}):null},cl=({board:e,title:n})=>{const{appState:s,setAppState:a}=vs();return t.jsx(oe,{className:z("property-button"),visible:!0,icon:t.jsx(uo,{}),type:"button",tooltip:n,"aria-label":n,onPointerUp:()=>{const o=Se(e)[0],l=co(o);gn.getLinkElement(l)||gn.wrapLink(l,"链接",""),setTimeout(()=>{const x=gn.getLinkElement(l)[0],h=si.toDOMNode(l,x);a({...s,linkState:{editor:l,targetDom:h,targetElement:x,isEditing:!0,isHovering:!1,isHoveringOrigin:!1}})},0)}})},Gt=8,dl=60,ul=600,is=24,hl='16px -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif';let wn=null,on=null;function pl(){if(wn||(wn=document.createElement("canvas"),on=wn.getContext("2d")),!on)throw new Error("Failed to get canvas context");return on.font=hl,on}function kn(e){return pl().measureText(e).width}function ml(e){const n=e.split(`
3
+ `);let s=0;for(const m of n){const x=kn(m);s=Math.max(s,x)}const a=Math.min(ul-Gt*2,Math.max(dl-Gt*2,s)),o=a+Gt*2;let l=0;for(const m of n){if(m.length===0){l+=1;continue}if(kn(m)<=a)l+=1;else{let h=0,p=1;for(const j of m){const f=kn(j);h+f>a?(p++,h=f):h+=f}l+=p}}const d=Math.max(is+Gt*2,l*is+Gt*2);return{width:o,height:d}}function fl(e){switch(e){case"ai-input":return t.jsx(yo,{size:12});case"image":return t.jsx(bs,{size:12});case"video":return t.jsx(xo,{size:12});default:return null}}function gl(e,n){return{"ai-input":{zh:"AI输入",en:"AI Input"},image:{zh:"图片",en:"Image"},video:{zh:"视频",en:"Video"},preset:{zh:"预设",en:"Preset"}}[e][n]}const xl=({board:e,language:n,title:s})=>{const[a,o]=i.useState(!1),[l,d]=i.useState(0),{history:m,addHistory:x,removeHistory:h}=ho({deduplicateWithPresets:!1}),{confirm:p,confirmDialog:j}=zn({container:e?te.getBoardContainer(e):null}),f=i.useRef(null),[M,S]=i.useState([]),[T,v]=i.useState([]);i.useEffect(()=>{a&&(S(po()),v(mo()))},[a]);const P=i.useMemo(()=>{const c=fo[n].map((F,L)=>({id:`preset_${L}`,content:F,source:"preset"})),C=m.map(F=>({id:F.id,content:F.content,source:"ai-input",timestamp:F.timestamp})),N=M.map(F=>({id:F.id,content:F.content,source:"image",timestamp:F.timestamp})),Y=T.map(F=>({id:F.id,content:F.content,source:"video",timestamp:F.timestamp})),se=[...C,...N,...Y];se.sort((F,L)=>(L.timestamp||0)-(F.timestamp||0));const B=new Set,he=[];for(const F of se){const L=F.content.trim();B.has(L)||(B.add(L),he.push(F))}const V=c.filter(F=>!B.has(F.content.trim()));return[...he,...V]},[n,m,M,T]),{historyPrompts:ne,presetPrompts:Q}=i.useMemo(()=>{const c=P.filter(N=>N.source!=="preset"),C=P.filter(N=>N.source==="preset");return{historyPrompts:c,presetPrompts:C}},[P]),$=i.useCallback((c,C)=>c==="history"?C:ne.length+C,[ne.length]);i.useEffect(()=>{a&&d(0)},[a]);const w=i.useCallback(c=>{x(c.content),o(!1);const C=Se(e);if(C.length===0)return;const N=B=>({type:"paragraph",children:[{text:B}]}),{width:Y,height:se}=ml(c.content);for(const B of C){const he=e.children.findIndex(F=>F.id===B.id);if(he<0)continue;const V={};if(Le.isMindElement(e,B)){const F=[N(c.content)];q.setNode(e,{data:F},[he]);continue}if(U.isText&&U.isText(B)){if(V.text=N(c.content),"points"in B&&Array.isArray(B.points)&&B.points.length>=2){const F=B.points,[L]=F,ie=[L,[L[0]+Y,L[1]+se]];V.points=ie}q.setNode(e,V,[he]);continue}if(U.isDrawElement(B)&&Pn([B])){if("text"in B&&B.text){if(V.text=N(c.content),"points"in B&&Array.isArray(B.points)&&B.points.length>=2){const F=B.points,[L]=F,ie=[L,[L[0]+Y,L[1]+se]];V.points=ie}q.setNode(e,V,[he]);continue}if("data"in B&&Array.isArray(B.data)){if(V.data=[N(c.content)],"points"in B&&Array.isArray(B.points)&&B.points.length>=2){const F=B.points,[L]=F,ie=[L,[L[0]+Y,L[1]+se]];V.points=ie}q.setNode(e,V,[he]);continue}}if("text"in B&&B.text){if(V.text=N(c.content),"points"in B&&Array.isArray(B.points)&&B.points.length>=2){const F=B.points,[L]=F,ie=[L,[L[0]+Y,L[1]+se]];V.points=ie}q.setNode(e,V,[he]);continue}"textContent"in B&&q.setNode(e,{textContent:c.content},[he])}},[e,x]),g=i.useCallback(async(c,C)=>{c.stopPropagation(),await p({title:n==="zh"?"确认删除提示词":"Delete Prompt",description:n==="zh"?"确定要删除这条历史提示词吗?此操作不可撤销。":"Are you sure you want to delete this prompt history item? This action cannot be undone.",confirmText:n==="zh"?"删除":"Delete",cancelText:n==="zh"?"取消":"Cancel",danger:!0})&&h(C)},[p,n,h]);return i.useEffect(()=>{if(!a)return;const c=C=>{if(P.length===0){C.key==="Escape"&&(C.preventDefault(),o(!1));return}switch(C.key){case"ArrowUp":C.preventDefault(),d(N=>N<=0?P.length-1:N-1);break;case"ArrowDown":C.preventDefault(),d(N=>N>=P.length-1?0:N+1);break;case"Enter":C.preventDefault(),P[l]&&w(P[l]);break;case"Escape":C.preventDefault(),o(!1);break}};return document.addEventListener("keydown",c),()=>document.removeEventListener("keydown",c)},[a,P,l,w]),i.useEffect(()=>{var C;if(!a||P.length===0)return;const c=(C=f.current)==null?void 0:C.querySelector(".popup-prompt-panel__item--highlighted");c&&c.scrollIntoView({block:"nearest",behavior:"smooth"})},[l,a,P.length]),t.jsxs(Ne,{open:a,onOpenChange:o,placement:"top",sideOffset:8,children:[t.jsx(_e,{asChild:!0,children:t.jsx(oe,{className:"prompt-button",type:"icon",icon:t.jsx(Mn,{size:16}),visible:!0,tooltip:s||(n==="zh"?"提示词":"Prompts"),"aria-label":s||(n==="zh"?"提示词":"Prompts"),onPointerUp:()=>o(!a)})}),t.jsx(Ee,{className:`popup-prompt-panel ${Ie}`,onMouseDown:c=>c.preventDefault(),children:t.jsxs("div",{ref:f,className:"popup-prompt-panel__content",children:[ne.length>0&&t.jsxs("div",{className:"popup-prompt-panel__section",children:[t.jsxs("div",{className:"popup-prompt-panel__section-header",children:[t.jsx(go,{size:14}),t.jsx("span",{children:n==="zh"?"历史记录":"History"})]}),t.jsx("div",{className:"popup-prompt-panel__list",children:ne.map((c,C)=>t.jsxs("div",{className:`popup-prompt-panel__item popup-prompt-panel__item--history ${$("history",C)===l?"popup-prompt-panel__item--highlighted":""}`,onClick:()=>w(c),onMouseEnter:()=>d($("history",C)),children:[t.jsxs("div",{className:"popup-prompt-panel__item-content",children:[t.jsx("span",{className:"popup-prompt-panel__item-text",children:c.content}),t.jsxs("span",{className:`popup-prompt-panel__item-source popup-prompt-panel__item-source--${c.source}`,children:[fl(c.source),t.jsx("span",{children:gl(c.source,n)})]})]}),c.source==="ai-input"&&t.jsx(ae,{content:n==="zh"?"删除":"Delete",showArrow:!1,children:t.jsx("button",{className:"popup-prompt-panel__item-delete",onClick:N=>g(N,c.id),children:t.jsx(ws,{size:12})})})]},c.id))})]}),Q.length>0&&t.jsxs("div",{className:"popup-prompt-panel__section",children:[t.jsxs("div",{className:"popup-prompt-panel__section-header",children:[t.jsx(Mn,{size:14}),t.jsx("span",{children:n==="zh"?"推荐提示词":"Suggestions"})]}),t.jsx("div",{className:"popup-prompt-panel__list",children:Q.map((c,C)=>t.jsx("div",{className:`popup-prompt-panel__item ${$("preset",C)===l?"popup-prompt-panel__item--highlighted":""}`,onClick:()=>w(c),onMouseEnter:()=>d($("preset",C)),children:t.jsx("span",{className:"popup-prompt-panel__item-text",children:c.content})},c.id))})]})]})}),j]})},Vt={bringToFront(e){const n=Se(e);if(n.length===0)return;const s=e.children.length-1,a=n.map(o=>({element:o,index:e.children.findIndex(l=>l.id===o.id)})).sort((o,l)=>l.index-o.index);for(const{element:o,index:l}of a)l>=0&&l<s&&q.moveNode(e,[l],[s])},bringForward(e){const n=Se(e);if(n.length===0)return;const s=e.children.length-1,a=n.map(o=>({element:o,index:e.children.findIndex(l=>l.id===o.id)})).sort((o,l)=>l.index-o.index);for(const{element:o,index:l}of a)l>=0&&l<s&&q.moveNode(e,[l],[l+2])},sendBackward(e){const n=Se(e);if(n.length===0)return;const s=n.map(a=>({element:a,index:e.children.findIndex(o=>o.id===a.id)})).sort((a,o)=>a.index-o.index);for(const{element:a,index:o}of s)o>0&&q.moveNode(e,[o],[o-1])},sendToBack(e){const n=Se(e);if(n.length===0)return;const s=n.map(a=>({element:a,index:e.children.findIndex(o=>o.id===a.id)})).sort((a,o)=>a.index-o.index);for(const{element:a,index:o}of s)o>0&&q.moveNode(e,[o],[0])},getLayerInfo(e,n){const s=e.children.findIndex(o=>o.id===n);if(s<0)return null;const a=e.children.length;return{index:s,total:a,canMoveUp:s<a-1,canMoveDown:s>0}}},yl=({board:e,title:n})=>{const{language:s}=je(),[a,o]=i.useState(!1),[l,d]=i.useState(0),m=te.getBoardContainer(e),x=i.useMemo(()=>{const T=Se(e);if(T.length===0)return null;const v=T[0];return Vt.getLayerInfo(e,v.id)},[e,l]),h=i.useCallback(()=>{Vt.bringToFront(e),d(T=>T+1)},[e]),p=i.useCallback(()=>{Vt.bringForward(e),d(T=>T+1)},[e]),j=i.useCallback(()=>{Vt.sendBackward(e),d(T=>T+1)},[e]),f=i.useCallback(()=>{Vt.sendToBack(e),d(T=>T+1)},[e]),M=(x==null?void 0:x.canMoveUp)??!1,S=(x==null?void 0:x.canMoveDown)??!1;return t.jsxs(Ne,{sideOffset:12,crossAxisOffset:-100,open:a,onOpenChange:o,placement:"top-start",children:[t.jsx(_e,{asChild:!0,children:t.jsx(oe,{className:z("property-button","layer-control-button"),selected:a,visible:!0,icon:t.jsx(bo,{}),type:"button",tooltip:n,"aria-label":n,onPointerUp:()=>o(!a)})}),t.jsx(Ee,{container:m,children:t.jsx(ze,{padding:1,className:z(Ie,"layer-control-panel"),children:t.jsxs("div",{className:"layer-actions",children:[t.jsx(ae,{content:s==="zh"?"置顶":"Bring to Front",showArrow:!1,children:t.jsxs("button",{className:z("layer-action-btn",{disabled:!M}),onClick:h,disabled:!M,children:[t.jsx(vo,{}),t.jsx("span",{children:s==="zh"?"置顶":"Front"})]})}),t.jsx(ae,{content:s==="zh"?"上移一层":"Bring Forward",showArrow:!1,children:t.jsxs("button",{className:z("layer-action-btn",{disabled:!M}),onClick:p,disabled:!M,children:[t.jsx(wo,{}),t.jsx("span",{children:s==="zh"?"上移":"Forward"})]})}),t.jsx(ae,{content:s==="zh"?"下移一层":"Send Backward",showArrow:!1,children:t.jsxs("button",{className:z("layer-action-btn",{disabled:!S}),onClick:j,disabled:!S,children:[t.jsx(ko,{}),t.jsx("span",{children:s==="zh"?"下移":"Backward"})]})}),t.jsx(ae,{content:s==="zh"?"置底":"Send to Back",showArrow:!1,children:t.jsxs("button",{className:z("layer-action-btn",{disabled:!S}),onClick:f,disabled:!S,children:[t.jsx(jo,{}),t.jsx("span",{children:s==="zh"?"置底":"Back"})]})}),x&&t.jsxs("span",{className:"layer-info",children:[x.index+1,"/",x.total]})]})})})]})},bl=({board:e,title:n})=>{const{language:s}=je(),[a,o]=i.useState(!1),l=te.getBoardContainer(e),d=i.useCallback(()=>{jt.alignLeft(e)},[e]),m=i.useCallback(()=>{jt.alignCenter(e)},[e]),x=i.useCallback(()=>{jt.alignRight(e)},[e]),h=i.useCallback(()=>{jt.alignTop(e)},[e]),p=i.useCallback(()=>{jt.alignMiddle(e)},[e]),j=i.useCallback(()=>{jt.alignBottom(e)},[e]),f=[{key:"left",icon:t.jsx(So,{size:16}),label:s==="zh"?"左对齐":"Align Left",shortcut:"⌥ A",handler:d},{key:"center",icon:t.jsx(No,{size:16}),label:s==="zh"?"水平居中":"Align Center",shortcut:"⌥ H",handler:m},{key:"right",icon:t.jsx(_o,{size:16}),label:s==="zh"?"右对齐":"Align Right",shortcut:"⌥ D",handler:x},{key:"top",icon:t.jsx(Eo,{size:16}),label:s==="zh"?"顶部对齐":"Align Top",shortcut:"⌥ W",handler:h},{key:"middle",icon:t.jsx(Io,{size:16}),label:s==="zh"?"垂直居中":"Align Middle",shortcut:"⌥ V",handler:p},{key:"bottom",icon:t.jsx(zo,{size:16}),label:s==="zh"?"底部对齐":"Align Bottom",shortcut:"⌥ S",handler:j}];return t.jsxs(Ne,{sideOffset:12,crossAxisOffset:-100,open:a,onOpenChange:o,placement:"top-start",children:[t.jsx(_e,{asChild:!0,children:t.jsx(oe,{className:z("property-button","alignment-button"),selected:a,visible:!0,icon:t.jsx(Co,{size:16}),type:"button",tooltip:n,"aria-label":n,onPointerUp:()=>o(!a)})}),t.jsx(Ee,{container:l,children:t.jsx(ze,{padding:1,className:z(Ie,"alignment-panel"),children:t.jsx("div",{className:"alignment-actions",children:f.map(M=>t.jsx(ae,{content:M.label,showArrow:!1,children:t.jsxs("button",{className:"alignment-action-btn",onClick:M.handler,children:[M.icon,t.jsx("span",{className:"alignment-label",children:M.label}),t.jsx("span",{className:"alignment-shortcut",children:M.shortcut})]})},M.key))})})})]})},vl=({board:e,title:n})=>{const{language:s}=je(),[a,o]=i.useState(!1),l=te.getBoardContainer(e),d=i.useCallback(()=>{yn.distributeHorizontal(e)},[e]),m=i.useCallback(()=>{yn.distributeVertical(e)},[e]),x=i.useCallback(()=>{yn.autoArrange(e)},[e]),h=[{key:"horizontal",icon:t.jsx(To,{size:16}),label:s==="zh"?"水平间距":"Horizontal Spacing",shortcut:"⇧ H",handler:d},{key:"vertical",icon:t.jsx(Fo,{size:16}),label:s==="zh"?"垂直间距":"Vertical Spacing",shortcut:"⇧ V",handler:m},{key:"auto",icon:t.jsx(Ao,{size:16}),label:s==="zh"?"自动排列":"Auto Arrange",shortcut:"⇧ A",handler:x}];return t.jsxs(Ne,{sideOffset:12,crossAxisOffset:-100,open:a,onOpenChange:o,placement:"top-start",children:[t.jsx(_e,{asChild:!0,children:t.jsx(oe,{className:z("property-button","distribute-button"),selected:a,visible:!0,icon:t.jsx(Po,{size:16}),type:"button",tooltip:n,"aria-label":n,onPointerUp:()=>o(!a)})}),t.jsx(Ee,{container:l,children:t.jsx(ze,{padding:1,className:z(Ie,"distribute-panel"),children:t.jsx("div",{className:"distribute-actions",children:h.map(p=>t.jsx(ae,{content:p.label,showArrow:!1,children:t.jsxs("button",{className:"distribute-action-btn",onClick:p.handler,children:[p.icon,t.jsx("span",{className:"distribute-label",children:p.label}),t.jsx("span",{className:"distribute-shortcut",children:p.shortcut})]})},p.key))})})})]})},wl=({board:e,title:n})=>{const{language:s}=je(),[a,o]=i.useState(!1),l=te.getBoardContainer(e),d=i.useCallback(()=>{Ht.union(e,s),o(!1)},[e,s]),m=i.useCallback(()=>{Ht.subtract(e,s)},[e,s]),x=i.useCallback(()=>{Ht.intersect(e,s)},[e,s]),h=i.useCallback(()=>{Ht.exclude(e,s)},[e,s]),p=i.useCallback(()=>{Ht.flatten(e,s)},[e,s]),j=[{key:"union",icon:t.jsx(Do,{size:16}),label:s==="zh"?"合并":"Union",shortcut:"⌥⇧U",handler:d},{key:"subtract",icon:t.jsx(Bo,{size:16}),label:s==="zh"?"减去":"Subtract",shortcut:"⌥⇧S",handler:m},{key:"intersect",icon:t.jsx(Lo,{size:16}),label:s==="zh"?"相交":"Intersect",shortcut:"⌥⇧I",handler:x},{key:"exclude",icon:t.jsx(Ro,{size:16}),label:s==="zh"?"排除":"Exclude",shortcut:"⌥⇧E",handler:h},{key:"flatten",icon:t.jsx(Oo,{size:16}),label:s==="zh"?"扁平化":"Flatten",shortcut:"⇧⌥F",handler:p}];return t.jsxs(Ne,{sideOffset:12,crossAxisOffset:-100,open:a,onOpenChange:o,placement:"top-start",children:[t.jsx(_e,{asChild:!0,children:t.jsx(oe,{className:z("property-button","boolean-button"),selected:a,visible:!0,icon:t.jsx(Mo,{size:16}),type:"button",tooltip:n,"aria-label":n,onPointerUp:()=>o(!a)})}),t.jsx(Ee,{container:l,children:t.jsx(ze,{padding:1,className:z(Ie,"boolean-panel"),children:t.jsx("div",{className:"boolean-actions",children:j.map(f=>t.jsx(ae,{content:f.label,showArrow:!1,children:t.jsxs("button",{className:"boolean-action-btn",onClick:f.handler,children:[f.icon,t.jsx("span",{className:"boolean-label",children:f.label}),t.jsx("span",{className:"boolean-shortcut",children:f.shortcut})]})},f.key))})})})]})};function kl(e){return e.sort((n,s)=>n.position-s.position).map(n=>`${n.color} ${n.position}%`).join(", ")}function jl(e){const n=kl(e.stops);return e.type==="linear"?`linear-gradient(${e.angle}deg, ${n})`:`radial-gradient(circle, ${n})`}function jn(e){return e.enabled?`${e.offsetX}px ${e.offsetY}px ${e.blur}px ${e.color}`:""}const Cn=ms.CUSTOM_GRADIENTS,Cl=({board:e,isOpen:n,onClose:s,currentFontSize:a,currentFontFamily:o,currentColor:l,toolbarRect:d,selectionRect:m})=>{var Tn,Fn;const{t:x,language:h}=je(),{confirm:p,confirmDialog:j}=zn({container:te.getBoardContainer(e)}),f=i.useRef(null),[M,S]=i.useState({top:0,left:0}),[T,v]=i.useState(a||"16"),[P,ne]=i.useState(!1),[Q,$]=i.useState(o||"PingFang SC"),[w,g]=i.useState(new Set),[c,C]=i.useState(400),[N,Y]=i.useState("left"),[se,B]=i.useState(1.5),[he,V]=i.useState(0),[F,L]=i.useState(!1),[ie,ke]=i.useState(!1),[Pe,mt]=i.useState(!1),[Re,_]=i.useState(!1),[K,X]=i.useState(!1),[le,ce]=i.useState(!1),[ge,k]=i.useState(null),[Te,Me]=i.useState(null),[Oe,xe]=i.useState(0),[Ve,Pt]=i.useState("#000000"),[Tt,Ft]=i.useState(null),[At,Mt]=i.useState(null),[lt,rt]=i.useState(!1),[u,y]=i.useState(null),[b,A]=i.useState({color:"rgba(0, 0, 0, 0.5)",offsetX:2,offsetY:2,blur:4}),[H,G]=i.useState(!1),[R,I]=i.useState(null),[O,ue]=i.useState({type:"linear",angle:135,stops:[{color:"#FF6B6B",offset:0},{color:"#4ECDC4",offset:1}]}),[re,pe]=i.useState([]),[be,Ce]=i.useState(l||"#000000"),[Je,ft]=i.useState(!1);i.useEffect(()=>{let r=!0;return St.get(Cn).then(D=>{r&&D&&pe(D)}).catch(D=>{console.warn("Failed to load gradient data:",D)}),()=>{r=!1}},[]),i.useEffect(()=>{if(n){const r=Li(e);if(r["text-gradient"]){G(!0);const J=oi.find(de=>jl(de.config)===r["text-gradient"]);I(J?J.id:null)}else G(!1),I(null);if(r["text-shadow"]){rt(!0);const J=r["text-shadow"];let de=null;for(const[Ae,et]of Object.entries(Zn.textShadow))if(jn(et)===J){de=Ae;break}y(de||null)}else rt(!1),y(null);if(r["font-family"]&&$(r["font-family"]),r["font-weight"]&&C(Number(r["font-weight"])),r["line-height"]&&B(Number(r["line-height"])),r["letter-spacing"]){const J=String(r["letter-spacing"]).replace("px","");V(Number(J))}const D=Ri(e);Y(D),L(!!r.bold),ke(!!r.italic),mt(!!r.underlined),_(!!r.strikethrough),X(!!r.superscript),ce(!!r.subscript),k(r["background-color"]||null),Me(r["text-transform"]||null),xe(r["text-stroke"]||0),Pt(r["text-stroke-color"]||"#000000"),Ft(r["text-decoration-style"]||null),Mt(r["text-decoration-color"]||null)}},[n,e]),i.useEffect(()=>{if(n&&!P){const r=setTimeout(()=>{Kn.forEach(D=>{sn.isFontLoaded(D.family)||sn.loadGoogleFont(D.family).catch(J=>{console.warn(`Failed to preload font ${D.family}:`,J)})})},500);return()=>clearTimeout(r)}},[n,P]),i.useEffect(()=>{if(n&&d&&m){let de=m.right+12,Ae=d.top+d.height+8;const et=window.innerWidth,mn=window.innerHeight;de+320>et-16&&(de=m.left-320-12,de<16&&(de=et-320-16)),Ae+520>mn-16&&(Ae=Math.max(16,mn-520-16)),S({left:Math.max(16,de),top:Math.max(16,Ae)})}},[n,d,m]);const Dt=i.useCallback(r=>{const D=parseInt(r,10);!isNaN(D)&&D>=8&&D<=100&&(v(r),zs(e,r))},[e]),gt=i.useCallback(async r=>{if($(r.family),ne(!1),r.source==="google"&&!sn.isFontLoaded(r.family)){g(D=>new Set(D).add(r.family));try{await sn.loadGoogleFont(r.family)}catch(D){console.error("Failed to load Google font:",D)}finally{g(D=>{const J=new Set(D);return J.delete(r.family),J})}}ji(e,r.family)},[e]);i.useEffect(()=>{l&&Ce(l)},[l]);const xt=i.useCallback(r=>{Ce(r),ot.setTextColor(e,r)},[e]),Qt=i.useCallback((r,D)=>{y(r),rt(!0),A({color:D.color,offsetX:D.offsetX,offsetY:D.offsetY,blur:D.blur});const J=jn(D);bn(e,J)},[e]),Fe=i.useCallback((r,D)=>{const J={...b,[r]:D};A(J),y(null);const de=`${J.offsetX}px ${J.offsetY}px ${J.blur}px ${J.color}`;bn(e,de)},[e,b]),Ue=i.useCallback(r=>{ue(r),I(null);const D=ut(r);Qn(e,D)},[e]),Bt=i.useCallback(()=>{const r=ut(O),J=[{id:`custom-${Date.now()}`,css:r},...re].slice(0,8);pe(J),St.set(Cn,J).catch(de=>{console.warn("Failed to save custom gradients:",de)})},[O,re]),yt=i.useCallback(async r=>{if(!await p({title:h==="zh"?"确认删除渐变预设":"Delete Gradient Preset",description:h==="zh"?"确定要删除这个自定义渐变预设吗?":"Are you sure you want to delete this custom gradient preset?",confirmText:h==="zh"?"删除":"Delete",cancelText:h==="zh"?"取消":"Cancel",danger:!0}))return;const J=re.filter(de=>de.id!==r);pe(J),St.set(Cn,J).catch(de=>{console.warn("Failed to save custom gradients:",de)})},[p,re,h]),bt=i.useCallback(()=>{const r=!lt;rt(r),r||(bn(e,null),y(null))},[e,lt]),Lt=i.useCallback(()=>{const r=!H;G(r),r||(Qn(e,null),I(null))},[e,H]),vt=i.useCallback(r=>{C(r),Ps(e,r)},[e]),$e=i.useCallback(r=>{Y(r),Ci(e,r)},[e]),ve=i.useCallback(r=>{B(r),Si(e,r)},[e]),fe=i.useCallback(r=>{V(r),Ni(e,r)},[e]),We=i.useCallback(()=>{L(!F),_i(e)},[e,F]),He=i.useCallback(()=>{ke(!ie),Ei(e)},[e,ie]),Xe=i.useCallback(()=>{mt(!Pe),Ii(e)},[e,Pe]),wt=i.useCallback(()=>{_(!Re),zi(e)},[e,Re]),Rt=i.useCallback(()=>{const r=!K;X(r),r&&ce(!1),Pi(e)},[e,K]),Ot=i.useCallback(()=>{const r=!le;ce(r),r&&X(!1),Ti(e)},[e,le]),Jt=i.useCallback(r=>{k(r),Fi(e,r)},[e]),Ut=i.useCallback(r=>{const D=r===Te?null:r;Me(D),Ai(e,D)},[e,Te]),en=i.useCallback((r,D)=>{xe(r),D&&Pt(D),Mi(e,r>0?r:null,D||Ve)},[e,Ve]),un=i.useCallback(r=>{Ft(r),Di(e,r)},[e]),tn=i.useCallback(r=>{Mt(r),Bi(e,r)},[e]);i.useEffect(()=>{if(!n)return;const r=J=>{const de=J.target;f.current&&f.current.contains(de)||de.closest(".popup-toolbar")!==null||s()},D=setTimeout(()=>{document.addEventListener("mousedown",r)},100);return()=>{clearTimeout(D),document.removeEventListener("mousedown",r)}},[n,s]);const hn=i.useCallback(r=>{r.target===r.currentTarget&&s()},[s]),[kt,$t]=i.useState(!1),E=[{value:100,label:"Thin",labelZh:"极细"},{value:200,label:"Extra Light",labelZh:"特细"},{value:300,label:"Light",labelZh:"细体"},{value:400,label:"Regular",labelZh:"常规"},{value:500,label:"Medium",labelZh:"中等"},{value:600,label:"Semi Bold",labelZh:"半粗"},{value:700,label:"Bold",labelZh:"粗体"},{value:800,label:"Extra Bold",labelZh:"特粗"},{value:900,label:"Black",labelZh:"黑体"}],pn=i.useCallback(r=>{const D=E.find(J=>J.value===r);return D?h==="zh"?D.labelZh:D.label:String(r)},[h]),ct=[...ai,...Kn],Hs=i.useCallback(r=>{const D=ct.find(J=>J.family===r);return(D==null?void 0:D.displayName)||r},[ct]);return n?t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"text-property-panel-overlay",onClick:hn,onPointerDown:r=>r.stopPropagation(),onMouseDown:r=>r.stopPropagation()}),t.jsxs("div",{ref:f,className:z("text-property-panel",{"is-open":n}),style:{top:M.top,left:M.left},onPointerDown:r=>r.stopPropagation(),onMouseDown:r=>r.stopPropagation(),onClick:r=>r.stopPropagation(),onPointerUp:r=>r.stopPropagation(),children:[t.jsxs("div",{className:"text-property-panel__header",children:[t.jsx("span",{className:"text-property-panel__header-title",children:x("propertyPanel.title")}),t.jsx("button",{className:"text-property-panel__header-close",onClick:s,children:t.jsx("svg",{width:"14",height:"14",viewBox:"0 0 14 14",fill:"none",children:t.jsx("path",{d:"M1 1L13 13M1 13L13 1",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round"})})})]}),t.jsxs("div",{className:"text-property-panel__content",children:[t.jsx("div",{className:"text-property-panel__section",children:t.jsxs("div",{className:"text-property-panel__section-content",children:[t.jsxs("div",{className:"inline-control",children:[t.jsx("label",{className:"inline-control__label",children:h==="zh"?"字号":"Size"}),t.jsxs("div",{className:"inline-control__slider-group",children:[t.jsx("input",{type:"range",className:"inline-control__slider",value:T,min:8,max:100,step:1,onChange:r=>{v(r.target.value),Dt(r.target.value)}}),t.jsx("span",{className:"inline-control__value",children:T})]})]}),t.jsxs("div",{className:"inline-control inline-control--dropdown",children:[t.jsx("label",{className:"inline-control__label",children:h==="zh"?"字体":"Font"}),t.jsxs("div",{className:"custom-dropdown",children:[t.jsxs("div",{className:z("custom-dropdown__trigger",{"is-expanded":P}),onClick:()=>{ne(!P),$t(!1)},children:[t.jsx("span",{className:"custom-dropdown__value",style:{fontFamily:`'${Q}', sans-serif`},children:Hs(Q)}),t.jsx("svg",{className:"custom-dropdown__arrow",width:"12",height:"12",viewBox:"0 0 12 12",fill:"none",children:t.jsx("path",{d:"M3 4.5L6 7.5L9 4.5",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round"})})]}),t.jsx("div",{className:z("custom-dropdown__menu custom-dropdown__menu--font",{"is-open":P}),children:ct.map(r=>t.jsxs("div",{className:z("custom-dropdown__item custom-dropdown__item--font",{"is-active":Q===r.family}),onClick:()=>{gt(r),ne(!1)},children:[t.jsx("span",{className:"custom-dropdown__item-label",children:r.displayName}),t.jsx("span",{className:"custom-dropdown__item-preview",style:{fontFamily:`'${r.family}', sans-serif`},children:r.previewText})]},r.family))})]})]}),t.jsxs("div",{className:"inline-control inline-control--dropdown",children:[t.jsx("label",{className:"inline-control__label",children:h==="zh"?"字重":"Weight"}),t.jsxs("div",{className:"custom-dropdown",children:[t.jsxs("div",{className:z("custom-dropdown__trigger",{"is-expanded":kt}),onClick:()=>{$t(!kt),ne(!1)},children:[t.jsx("span",{className:"custom-dropdown__value",style:{fontWeight:c},children:pn(c)}),t.jsx("svg",{className:"custom-dropdown__arrow",width:"12",height:"12",viewBox:"0 0 12 12",fill:"none",children:t.jsx("path",{d:"M3 4.5L6 7.5L9 4.5",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round"})})]}),t.jsx("div",{className:z("custom-dropdown__menu",{"is-open":kt}),children:E.map(r=>t.jsx("div",{className:z("custom-dropdown__item",{"is-active":c===r.value}),onClick:()=>{vt(r.value),$t(!1)},children:t.jsx("span",{className:"custom-dropdown__item-label",style:{fontWeight:r.value},children:h==="zh"?r.labelZh:r.label})},r.value))})]})]}),t.jsxs("div",{className:"inline-control",children:[t.jsx("label",{className:"inline-control__label",children:h==="zh"?"对齐":"Align"}),t.jsxs("div",{className:"align-buttons align-buttons--compact",children:[t.jsx(ae,{content:h==="zh"?"左对齐":"Align Left",showArrow:!1,children:t.jsx("button",{className:z("align-buttons__btn",{"is-active":N==="left"}),onClick:()=>$e("left"),children:t.jsx("svg",{width:"14",height:"14",viewBox:"0 0 16 16",fill:"currentColor",children:t.jsx("path",{d:"M2 3h12v2H2V3zm0 4h8v2H2V7zm0 4h12v2H2v-2z"})})})}),t.jsx(ae,{content:h==="zh"?"居中对齐":"Align Center",showArrow:!1,children:t.jsx("button",{className:z("align-buttons__btn",{"is-active":N==="center"}),onClick:()=>$e("center"),children:t.jsx("svg",{width:"14",height:"14",viewBox:"0 0 16 16",fill:"currentColor",children:t.jsx("path",{d:"M2 3h12v2H2V3zm2 4h8v2H4V7zm-2 4h12v2H2v-2z"})})})}),t.jsx(ae,{content:h==="zh"?"右对齐":"Align Right",showArrow:!1,children:t.jsx("button",{className:z("align-buttons__btn",{"is-active":N==="right"}),onClick:()=>$e("right"),children:t.jsx("svg",{width:"14",height:"14",viewBox:"0 0 16 16",fill:"currentColor",children:t.jsx("path",{d:"M2 3h12v2H2V3zm4 4h8v2H6V7zm-4 4h12v2H2v-2z"})})})})]})]}),t.jsxs("div",{className:"inline-control",children:[t.jsx("label",{className:"inline-control__label",children:h==="zh"?"样式":"Style"}),t.jsxs("div",{className:"style-buttons",children:[t.jsx(ae,{content:h==="zh"?"加粗":"Bold",showArrow:!1,children:t.jsx("button",{className:z("style-buttons__btn",{"is-active":F}),onClick:We,children:t.jsx("span",{className:"style-buttons__icon style-buttons__icon--bold",children:"B"})})}),t.jsx(ae,{content:h==="zh"?"斜体":"Italic",showArrow:!1,children:t.jsx("button",{className:z("style-buttons__btn",{"is-active":ie}),onClick:He,children:t.jsx("span",{className:"style-buttons__icon style-buttons__icon--italic",children:"I"})})}),t.jsx(ae,{content:h==="zh"?"下划线":"Underline",showArrow:!1,children:t.jsx("button",{className:z("style-buttons__btn",{"is-active":Pe}),onClick:Xe,children:t.jsx("span",{className:"style-buttons__icon style-buttons__icon--underline",children:"U"})})}),t.jsx(ae,{content:h==="zh"?"删除线":"Strikethrough",showArrow:!1,children:t.jsx("button",{className:z("style-buttons__btn",{"is-active":Re}),onClick:wt,children:t.jsx("span",{className:"style-buttons__icon style-buttons__icon--strikethrough",children:"S"})})}),t.jsx(ae,{content:h==="zh"?"上标":"Superscript",showArrow:!1,children:t.jsx("button",{className:z("style-buttons__btn",{"is-active":K}),onClick:Rt,children:t.jsxs("span",{className:"style-buttons__icon style-buttons__icon--superscript",children:["X",t.jsx("sup",{children:"2"})]})})}),t.jsx(ae,{content:h==="zh"?"下标":"Subscript",showArrow:!1,children:t.jsx("button",{className:z("style-buttons__btn",{"is-active":le}),onClick:Ot,children:t.jsxs("span",{className:"style-buttons__icon style-buttons__icon--subscript",children:["X",t.jsx("sub",{children:"2"})]})})})]})]}),t.jsxs("div",{className:"inline-control",children:[t.jsx("label",{className:"inline-control__label",children:h==="zh"?"大小写":"Case"}),t.jsxs("div",{className:"case-buttons",children:[t.jsx(ae,{content:h==="zh"?"全大写":"Uppercase",showArrow:!1,children:t.jsx("button",{className:z("case-buttons__btn",{"is-active":Te==="uppercase"}),onClick:()=>Ut("uppercase"),children:"AA"})}),t.jsx(ae,{content:h==="zh"?"全小写":"Lowercase",showArrow:!1,children:t.jsx("button",{className:z("case-buttons__btn",{"is-active":Te==="lowercase"}),onClick:()=>Ut("lowercase"),children:"aa"})}),t.jsx(ae,{content:h==="zh"?"首字母大写":"Capitalize",showArrow:!1,children:t.jsx("button",{className:z("case-buttons__btn",{"is-active":Te==="capitalize"}),onClick:()=>Ut("capitalize"),children:"Aa"})})]})]}),t.jsxs("div",{className:"inline-control",children:[t.jsx("label",{className:"inline-control__label",children:h==="zh"?"行高":"Line"}),t.jsxs("div",{className:"inline-control__slider-group",children:[t.jsx("input",{type:"range",className:"inline-control__slider",value:se,min:.8,max:3,step:.1,onChange:r=>ve(Number(r.target.value))}),t.jsx("span",{className:"inline-control__value",children:se.toFixed(1)})]})]}),t.jsxs("div",{className:"inline-control",children:[t.jsx("label",{className:"inline-control__label",children:h==="zh"?"字距":"Spacing"}),t.jsxs("div",{className:"inline-control__slider-group",children:[t.jsx("input",{type:"range",className:"inline-control__slider",value:he,min:-2,max:10,step:.5,onChange:r=>fe(Number(r.target.value))}),t.jsxs("span",{className:"inline-control__value",children:[he,"px"]})]})]})]})}),t.jsxs("div",{className:"text-property-panel__section",children:[t.jsx("div",{className:"text-property-panel__section-title",children:x("propertyPanel.textColor")}),t.jsx("div",{className:"text-property-panel__section-content text-color-picker",children:t.jsx(_t,{value:be,onChange:xt,showAlpha:!0,showEyeDropper:!0,showPresets:!0,showRecentColors:!0,showHexInput:!0})})]}),t.jsx("div",{className:"text-property-panel__section",children:t.jsxs("div",{className:"text-property-panel__section-content",children:[t.jsxs("div",{className:"inline-control",children:[t.jsx("label",{className:"inline-control__label",children:h==="zh"?"高亮":"Highlight"}),t.jsxs("div",{className:"highlight-colors",children:[t.jsx(ae,{content:h==="zh"?"无":"None",showArrow:!1,children:t.jsx("button",{className:z("highlight-colors__btn highlight-colors__btn--none",{"is-active":!ge}),onClick:()=>Jt(null),children:t.jsx("svg",{width:"12",height:"12",viewBox:"0 0 16 16",children:t.jsx("line",{x1:"2",y1:"2",x2:"14",y2:"14",stroke:"currentColor",strokeWidth:"2"})})})}),["#FFEB3B","#4CAF50","#2196F3","#E91E63","#FF9800","#9C27B0"].map(r=>t.jsx(ae,{content:r,showArrow:!1,children:t.jsx("button",{className:z("highlight-colors__btn",{"is-active":ge===r}),style:{backgroundColor:r},onClick:()=>Jt(r)})},r))]})]}),t.jsxs("div",{className:"inline-control",children:[t.jsx("label",{className:"inline-control__label",children:h==="zh"?"描边":"Stroke"}),t.jsxs("div",{className:"inline-control__slider-group",children:[t.jsx("input",{type:"range",className:"inline-control__slider",value:Oe,min:0,max:3,step:.5,onChange:r=>en(Number(r.target.value))}),t.jsxs("span",{className:"inline-control__value",children:[Oe,"px"]}),Oe>0&&t.jsx("input",{type:"color",className:"inline-control__color-input",value:Ve,onChange:r=>en(Oe,r.target.value)})]})]}),(Pe||Re)&&t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"inline-control",children:[t.jsx("label",{className:"inline-control__label",children:h==="zh"?"线型":"Line Style"}),t.jsx("div",{className:"decoration-style-buttons",children:["solid","double","dotted","dashed","wavy"].map(r=>t.jsx(ae,{content:r,showArrow:!1,children:t.jsx("button",{className:z("decoration-style-buttons__btn",{"is-active":Tt===r}),onClick:()=>un(Tt===r?null:r),children:t.jsx("span",{className:`decoration-preview decoration-preview--${r}`,children:"Ab"})})},r))})]}),t.jsxs("div",{className:"inline-control",children:[t.jsx("label",{className:"inline-control__label",children:h==="zh"?"线色":"Line Color"}),t.jsxs("div",{className:"highlight-colors",children:[t.jsx(ae,{content:h==="zh"?"默认":"Default",showArrow:!1,children:t.jsx("button",{className:z("highlight-colors__btn highlight-colors__btn--none",{"is-active":!At}),onClick:()=>tn(null),children:t.jsx("svg",{width:"12",height:"12",viewBox:"0 0 16 16",children:t.jsx("line",{x1:"2",y1:"2",x2:"14",y2:"14",stroke:"currentColor",strokeWidth:"2"})})})}),["#E91E63","#FF5722","#4CAF50","#2196F3","#9C27B0","#000000"].map(r=>t.jsx(ae,{content:r,showArrow:!1,children:t.jsx("button",{className:z("highlight-colors__btn",{"is-active":At===r}),style:{backgroundColor:r},onClick:()=>tn(r)})},r))]})]})]})]})}),t.jsx("div",{className:"text-property-panel__section",children:t.jsxs("div",{className:"text-property-panel__section-content",children:[t.jsxs("div",{className:"inline-control",children:[t.jsx("label",{className:"inline-control__label",children:h==="zh"?"阴影":"Shadow"}),t.jsx("div",{className:z("toggle-switch__control toggle-switch__control--inline",{"is-active":lt}),onClick:bt})]}),lt&&t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"effect-presets",children:Object.entries(Zn.textShadow).map(([r,D])=>t.jsx(ae,{content:r,showArrow:!1,children:t.jsx("div",{className:z("effect-presets__item",{"is-active":u===r}),onClick:()=>Qt(r,D),children:t.jsx("span",{style:{textShadow:jn(D)},children:"Aa"})})},r))}),t.jsxs("div",{className:"effect-config",children:[t.jsxs("div",{className:"inline-control",children:[t.jsx("label",{className:"inline-control__label",children:h==="zh"?"颜色":"Color"}),t.jsxs("div",{className:"inline-control__color-group",children:[t.jsxs(Ne,{open:Je,onOpenChange:ft,placement:"bottom",sideOffset:8,children:[t.jsx(_e,{asChild:!0,children:t.jsx("button",{className:"inline-control__color-trigger",style:{backgroundColor:b.color.startsWith("rgba")?`#${((Tn=b.color.match(/\d+/g))==null?void 0:Tn.slice(0,3).map(r=>parseInt(r).toString(16).padStart(2,"0")).join(""))||"000000"}`:b.color},onClick:()=>ft(!Je)})}),t.jsx(Ee,{children:t.jsx(ze,{padding:4,className:"color-picker-popover",children:t.jsx(_t,{value:b.color.startsWith("rgba")?`#${((Fn=b.color.match(/\d+/g))==null?void 0:Fn.slice(0,3).map(r=>parseInt(r).toString(16).padStart(2,"0")).join(""))||"000000"}`:b.color,onChange:r=>{const D=parseInt(r.slice(1,3),16),J=parseInt(r.slice(3,5),16),de=parseInt(r.slice(5,7),16),Ae=b.color.match(/[\d.]+\)$/),et=Ae?parseFloat(Ae[0]):.5;Fe("color",`rgba(${D}, ${J}, ${de}, ${et})`)},showAlpha:!1,showEyeDropper:!0,showPresets:!0,showRecentColors:!0,showHexInput:!0})})})]}),t.jsx(ae,{content:h==="zh"?"透明度":"Opacity",showArrow:!1,children:t.jsx("input",{type:"range",className:"inline-control__slider inline-control__slider--short",value:(()=>{const r=b.color.match(/[\d.]+\)$/);return r?parseFloat(r[0])*100:50})(),min:0,max:100,step:5,"aria-label":h==="zh"?"透明度":"Opacity",onChange:r=>{const D=Number(r.target.value)/100,J=b.color.match(/\d+/g);if(J&&J.length>=3){const[de,Ae,et]=J.slice(0,3);Fe("color",`rgba(${de}, ${Ae}, ${et}, ${D})`)}}})}),t.jsxs("span",{className:"inline-control__value inline-control__value--narrow",children:[(()=>{const r=b.color.match(/[\d.]+\)$/);return r?Math.round(parseFloat(r[0])*100):50})(),"%"]})]})]}),t.jsxs("div",{className:"inline-control",children:[t.jsx("label",{className:"inline-control__label",children:h==="zh"?"X偏移":"X"}),t.jsxs("div",{className:"inline-control__slider-group",children:[t.jsx("input",{type:"range",className:"inline-control__slider",value:b.offsetX,min:-20,max:20,step:1,onChange:r=>Fe("offsetX",Number(r.target.value))}),t.jsxs("span",{className:"inline-control__value",children:[b.offsetX,"px"]})]})]}),t.jsxs("div",{className:"inline-control",children:[t.jsx("label",{className:"inline-control__label",children:h==="zh"?"Y偏移":"Y"}),t.jsxs("div",{className:"inline-control__slider-group",children:[t.jsx("input",{type:"range",className:"inline-control__slider",value:b.offsetY,min:-20,max:20,step:1,onChange:r=>Fe("offsetY",Number(r.target.value))}),t.jsxs("span",{className:"inline-control__value",children:[b.offsetY,"px"]})]})]}),t.jsxs("div",{className:"inline-control",children:[t.jsx("label",{className:"inline-control__label",children:h==="zh"?"模糊":"Blur"}),t.jsxs("div",{className:"inline-control__slider-group",children:[t.jsx("input",{type:"range",className:"inline-control__slider",value:b.blur,min:0,max:30,step:1,onChange:r=>Fe("blur",Number(r.target.value))}),t.jsxs("span",{className:"inline-control__value",children:[b.blur,"px"]})]})]})]})]})]})}),t.jsx("div",{className:"text-property-panel__section",children:t.jsxs("div",{className:"text-property-panel__section-content",children:[t.jsxs("div",{className:"inline-control",children:[t.jsx("label",{className:"inline-control__label",children:h==="zh"?"渐变":"Gradient"}),t.jsx("div",{className:z("toggle-switch__control toggle-switch__control--inline",{"is-active":H}),onClick:Lt})]}),H&&t.jsx("div",{className:"gradient-editor-wrapper",children:t.jsx(Ts,{value:O,onChange:Ue,showPresets:!0,showHistory:!1,inline:!0,customPresets:re.map(r=>r.css),onSavePreset:Bt,onDeletePreset:r=>{const D=re[r];D&&yt(D.id)}})})]})})]})]}),j]}):null},Sl=320,Nl=252,tt=12,_l=220;function El(e,n){return e.children.findIndex(s=>s.id===n)}function Sn(e){return Zt(e.transform3d)}function ls(e){return{rotateX:(e==null?void 0:e.rotateX)??0,rotateY:(e==null?void 0:e.rotateY)??0,perspective:(e==null?void 0:e.perspective)??ks}}function Il(e,n){const s=Zt(e),a=Zt(n);return!s&&!a?!0:!s||!a?!1:s.rotateX===a.rotateX&&s.rotateY===a.rotateY&&s.perspective===a.perspective}function an(e,n,s){const a=El(e,n);a<0||q.setNode(e,{transform3d:s},[a])}function ln(e,n,s){return Math.min(s,Math.max(n,e))}function zl(e,n,s){const a=s-n;return a<=0?"0%":`${((ln(e,n,s)-n)/a*100).toFixed(2)}%`}function Pl(e){if(typeof window>"u"||!e)return{};const n=window.innerWidth,s=window.innerHeight,a=e.left,o=n-e.right,l=o>=a,m=ln((l?o:a)-tt*2,Nl,Sl),x=l?Math.min(e.right+tt,n-m-tt):Math.max(tt,e.left-m-tt),h=ln(e.top,tt,Math.max(tt,s-_l-tt));return{contentStyle:{left:x,top:h,position:"fixed",transform:"none"},panelStyle:{width:m}}}const Tl=({board:e,element:n,selectionRect:s,title:a,language:o})=>{const[l,d]=i.useState(!1),[m,x]=i.useState(()=>ls(Sn(n))),h=i.useRef(void 0),p=i.useRef(!1),j=n.id,f=te.getBoardContainer(e),M=Pl(s),S=i.useCallback(c=>{x(c),nn.withoutSaving(e,()=>{an(e,j,Zt(c))})},[e,j]),T=i.useCallback(()=>{nn.withoutSaving(e,()=>{an(e,j,h.current)})},[e,j]),v=i.useCallback(c=>{if(c){const C=Sn(n);h.current=C,p.current=!1,x(ls(C)),d(!0);return}l&&!p.current&&T(),d(!1)},[n,l,T]),P=i.useCallback((c,C)=>{const N=c==="perspective"?{min:200,max:3e3}:{min:-180,max:180};S({...m,[c]:ln(C,N.min,N.max)})},[m,S]),ne=i.useCallback(()=>{S({rotateX:0,rotateY:0,perspective:ks})},[S]),Q=i.useCallback(()=>{const c=Zt(m);p.current=!0,nn.withoutSaving(e,()=>{an(e,j,h.current)}),Il(h.current,c)||nn.withNewBatch(e,()=>{an(e,j,c)}),Uo(),d(!1)},[e,m,j]),$=i.useCallback(()=>{p.current=!0,T(),d(!1)},[T]);i.useEffect(()=>{l&&v(!1)},[j]);const w={rotateX:o==="zh"?"上下倾斜":"Rotate X",rotateY:o==="zh"?"左右倾斜":"Rotate Y",perspective:o==="zh"?"透视距离":"Perspective",reset:o==="zh"?"重置":"Reset",cancel:o==="zh"?"取消":"Cancel",confirm:o==="zh"?"确定":"Apply"},g=(c,C,N,Y,se,B)=>t.jsxs("label",{className:"image-3d-control-row",children:[t.jsx("span",{className:"image-3d-control-label",children:C}),t.jsx("input",{className:"image-3d-control-slider",type:"range",min:N,max:Y,step:se,value:m[c],style:{"--image-3d-slider-progress":zl(m[c],N,Y)},onChange:he=>P(c,Number(he.target.value))}),t.jsxs("span",{className:"image-3d-control-number",children:[t.jsx("input",{type:"number",min:N,max:Y,step:se,value:m[c],onChange:he=>P(c,Number(he.target.value))}),t.jsx("em",{children:B})]})]});return t.jsxs(Ne,{sideOffset:12,open:l,onOpenChange:v,placement:"right-start",children:[t.jsx(_e,{asChild:!0,children:t.jsx(oe,{className:z("property-button","image-3d-transform-button"),selected:l||!!Sn(n),visible:!0,icon:t.jsx($o,{size:15}),type:"button",tooltip:a,"aria-label":a,"data-track":"toolbar_click_image_3d_transform",onPointerUp:()=>v(!l)})}),t.jsx(Ee,{container:f,style:M.contentStyle,children:t.jsxs(ze,{padding:1,style:M.panelStyle,className:z(Ie,"image-3d-transform-panel"),children:[t.jsxs("div",{className:"image-3d-control-list",children:[g("rotateY",w.rotateY,-180,180,1,"deg"),g("rotateX",w.rotateX,-180,180,1,"deg"),g("perspective",w.perspective,200,3e3,20,"px")]}),t.jsxs("div",{className:"image-3d-control-actions",children:[t.jsxs("button",{type:"button",onClick:ne,children:[t.jsx(Wo,{size:14}),t.jsx("span",{children:w.reset})]}),t.jsxs("button",{type:"button",onClick:$,children:[t.jsx(ws,{size:14}),t.jsx("span",{children:w.cancel})]}),t.jsxs("button",{type:"button",className:"image-3d-control-confirm",onClick:Q,children:[t.jsx(Ho,{size:14}),t.jsx("span",{children:w.confirm})]})]})]})})]})};let it={x:0,y:0},Et=new Set,rn=!1;const Fs=e=>{it={x:e.clientX,y:e.clientY},Et.forEach(n=>n(it))},As=e=>{it={x:e.clientX,y:e.clientY},Et.forEach(n=>n(it))},Ms=e=>{it={x:e.clientX,y:e.clientY},Et.forEach(n=>n(it))},Fl=()=>{rn||(document.addEventListener("mousemove",Fs,!0),document.addEventListener("mousedown",As,!0),document.addEventListener("mouseup",Ms,!0),rn=!0)},Al=()=>{rn&&Et.size===0&&(document.removeEventListener("mousemove",Fs,!0),document.removeEventListener("mousedown",As,!0),document.removeEventListener("mouseup",Ms,!0),rn=!1)},Ml=()=>{const[e,n]=i.useState(()=>it),s=i.useRef();return i.useEffect(()=>(s.current=a=>{n(a)},Et.add(s.current),Fl(),n(it),()=>{s.current&&Et.delete(s.current),Al()}),[]),e},Dl=({visible:e,videoUrl:n,onClose:s,onConfirm:a})=>{const{language:o}=je(),l=i.useRef(null),d=i.useRef(null),m=i.useRef(null),[x,h]=i.useState(!0),[p,j]=i.useState(0),[f,M]=i.useState(0),[S,T]=i.useState(""),[v,P]=i.useState(!1),[ne,Q]=i.useState(!1);i.useEffect(()=>(e&&n&&(h(!0),T(""),P(!1),Q(!1)),()=>{m.current!==null&&window.clearTimeout(m.current)}),[e,n]);const $=()=>{const V=l.current;V&&(j(V.duration),P(!0))},w=i.useCallback((V,F=!1)=>{const L=l.current;if(!L)return;m.current!==null&&(window.clearTimeout(m.current),m.current=null);const ie=()=>{if(L.readyState<2){console.warn("Video not ready for seeking, readyState:",L.readyState);const ke=()=>{L.currentTime=V,L.removeEventListener("canplay",ke)};L.addEventListener("canplay",ke);return}L.currentTime=V};F?ie():m.current=window.setTimeout(ie,150)},[]);i.useEffect(()=>{const V=l.current;if(v&&V&&p>0){const F=Math.max(0,p-.1);M(F),w(F,!0)}},[v,p,w]);const g=i.useCallback(()=>{const V=l.current,F=d.current;if(!V||!F)return;const L=F.getContext("2d");if(L)try{F.width=V.videoWidth,F.height=V.videoHeight,L.drawImage(V,0,0,F.width,F.height);const ie=F.toDataURL("image/png");T(ie)}catch(ie){console.warn("Failed to generate frame image (likely due to CORS):",ie);try{L.fillStyle="#000",L.fillRect(0,0,F.width,F.height),L.fillStyle="#fff",L.font="16px Arial",L.textAlign="center",L.fillText("视频帧预览不可用",F.width/2,F.height/2);const ke=F.toDataURL("image/png");T(ke)}catch(ke){console.error("Failed to create placeholder image:",ke),T("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNk+M9QDwADhgGAWjR9awAAAABJRU5ErkJggg==")}}},[]),c=i.useCallback(()=>{ne||(g(),h(!1))},[ne,g]),C=()=>{Q(!0)},N=V=>{if(l.current&&p>0&&v){const L=V/100*p;M(L),w(L,!1)}},Y=()=>{Q(!1),h(!0),l.current&&v&&w(f,!0)},se=V=>{if(!l.current||p===0||!v)return;const L=parseFloat(V.target.value);if(isNaN(L))return;const ie=Math.max(0,Math.min(p,L));M(ie),w(ie,!0),h(!0)},B=()=>{S&&(a(S,f),s())},he=V=>{const F=Math.floor(V/60),L=(V%60).toFixed(1);return`${F}:${L.padStart(4,"0")}`};return t.jsx(Go,{visible:e,onClose:s,header:o==="zh"?"选择视频帧":"Select Video Frame",width:600,destroyOnClose:!0,footer:!1,children:t.jsxs("div",{className:"video-frame-selector",children:[t.jsx("video",{ref:l,src:n,style:{display:"none"},muted:!0,playsInline:!0,preload:"auto",crossOrigin:"anonymous",onLoadedMetadata:$,onSeeked:c}),t.jsx("canvas",{ref:d,style:{display:"none"}}),t.jsx("div",{className:"frame-preview",children:x?t.jsxs("div",{className:"loading-placeholder",children:[t.jsx("div",{className:"loading-spinner"}),t.jsx("div",{className:"loading-text",children:o==="zh"?"加载视频中...":"Loading video..."})]}):t.jsx("div",{className:"frame-image-container",children:t.jsx("img",{src:S,alt:"Video frame",className:"frame-image"})})}),t.jsxs("div",{className:"time-controls",children:[t.jsxs("div",{className:"time-display",children:[t.jsx("span",{className:"current-time",children:he(f)}),t.jsx("span",{className:"separator",children:"/"}),t.jsx("span",{className:"total-time",children:he(p)})]}),t.jsx("div",{className:"progress-container",children:t.jsx("input",{type:"range",min:0,max:100,value:p>0?f/p*100:0,onChange:V=>N(Number(V.target.value)),onMouseDown:C,onMouseUp:Y,onTouchStart:C,onTouchEnd:Y,className:"progress-slider",disabled:x&&!ne})}),t.jsxs("div",{className:"time-input-container",children:[t.jsx("label",{className:"time-input-label",children:o==="zh"?"精确时间 (秒):":"Precise time (seconds):"}),t.jsx("input",{type:"number",min:0,max:p,step:.1,value:f.toFixed(1),onChange:se,className:"time-input",disabled:x})]})]}),t.jsxs("div",{className:"actions",children:[t.jsx("button",{className:"action-button secondary",onClick:s,children:o==="zh"?"取消":"Cancel"}),t.jsx("button",{className:"action-button primary",onClick:B,disabled:x||!S,children:o==="zh"?"确认插入":"Confirm Insert"})]})]})})},Bl=async(e,n,s,a)=>{if(!e||!n)throw new Error("Board and video element are required");try{const o=st(e,[n],!1),l=[o.x,o.y+o.height+20],d=new Image,m=await new Promise(h=>{d.onload=()=>{h({width:d.naturalWidth,height:d.naturalHeight})},d.onerror=()=>{h({width:o.width,height:o.height})},d.src=s}),x={url:s,width:m.width,height:m.height,isVideoFrame:!0,videoTimestamp:a,sourceVideoId:n.id||"unknown"};js.insertImage(e,x,l)}catch(o){throw console.error("Failed to insert video frame:",o),new Error(`Video frame insertion failed: ${o instanceof Error?o.message:"Unknown error"}`)}};function Ze(e){return typeof e=="number"&&Number.isFinite(e)&&e>0}function Ll(e){const n=e;return n.isAudio===!0||n.audioType==="music-card"||typeof n.audioUrl=="string"&&n.audioUrl.length>0}function Rl(e){return U.isDrawElement(e)&&U.isImage(e)&&typeof e.url=="string"&&!Ll(e)&&!e.pptImagePlaceholder}function Ds(e,n){const s=n.points;if(s&&s.length>=2)return Kt.getRectangleByPoints(s);try{return st(e,[n],!1)}catch{return null}}function Ol(e,n){const s=Math.max(e.x,n.x),a=Math.max(e.y,n.y),o=Math.min(e.x+e.width,n.x+n.width),l=Math.min(e.y+e.height,n.y+n.height);return Math.max(0,o-s)*Math.max(0,l-a)}function Ul(e,n){if(!n)return null;const s=e.children.find(a=>a.id===n&&Be(a));return s&&Be(s)?s:null}function Bs(e,n){const s=Ul(e,n.frameId);if(s)return s;const a=Ds(e,n);if(!a)return null;let o=null,l=0;for(const d of e.children){if(!Be(d))continue;const m=Kt.getRectangleByPoints(d.points),x=Ol(a,m);x>l&&(l=x,o=d)}return l>0?o:null}function $l(e,n){return e.children.filter(s=>{var o;return s.id===n.id||Be(s)||!Rl(s)?!1:s.frameId===n.id?!0:((o=Bs(e,s))==null?void 0:o.id)===n.id})}function Wl(e,n){const s=e;return Ze(s.width)&&Ze(s.height)?s.width/s.height:Ze(n.width)&&Ze(n.height)?n.width/n.height:null}function Hl(e){const n=e.toLowerCase();return n.includes("#video")||n.includes("#merged-video-")||[".mp4",".avi",".mov",".wmv",".flv",".webm",".mkv"].some(s=>n.includes(s))}function Gl(e){return typeof Image>"u"||Hl(e)?Promise.resolve(null):new Promise(n=>{const s=new Image;let a;const o=()=>{a&&clearTimeout(a),s.onload=null,s.onerror=null};s.referrerPolicy="no-referrer",s.onload=()=>{const l=s.naturalWidth||s.width,d=s.naturalHeight||s.height;o(),n(Ze(l)&&Ze(d)?l/d:null)},s.onerror=()=>{o(),n(null)},a=setTimeout(()=>{o(),n(null)},3e3),s.src=e})}async function Vl(e){const n=e.url;return typeof n=="string"&&n.length>0?Gl(n):null}function Xl(e,n){if(!Ze(e)||!Ze(n.width)||!Ze(n.height))return null;const s=n.width/n.height;let a,o;return e>s?(a=n.width,o=a/e):(o=n.height,a=o*e),{x:n.x+(n.width-a)/2,y:n.y+(n.height-o)/2,width:a,height:o}}function Yl(e,n,s,a){const o=e.children.findIndex(p=>p.id===n.id);if(o===-1)return!1;const l=Ds(e,n);if(!l)return!1;const d=a||Wl(n,l);if(!d)return!1;const m=Kt.getRectangleByPoints(s.points),x=Xl(d,m);if(!x)return!1;const h=[[x.x,x.y],[x.x+x.width,x.y+x.height]];return q.setNode(e,{points:h,frameId:s.id},[o]),!0}async function Zl(e,n,s){return Yl(e,n,s,await Vl(n))}async function Kl(e,n){let s=0,a=0;for(const o of $l(e,n)){const l=Bs(e,o);if(!l||!await Zl(e,o,l)){a+=1;continue}s+=1}return{fittedCount:s,skippedCount:a}}function rs(e){return Yo(e).replace(/\u00a0/g," ").replace(/[ \t]+\n/g,`
4
4
  `).replace(/\n{3,}/g,`
5
5
 
6
6
  `).trim()}function nt(e){if(!e)return"";if(typeof e=="string")return e;if(Array.isArray(e))return e.map(a=>nt(a)).filter(Boolean).join(`
7
7
  `);if(typeof e!="object")return"";const n=e,s=[];return typeof n.text=="string"&&s.push(n.text),Array.isArray(n.children)&&s.push(nt(n.children)),Array.isArray(n.data)&&s.push(nt(n.data)),s.filter(Boolean).join(`
8
- `)}function Kl(e){if(!e||typeof window>"u")return"";const n=window.getSelection();if(!n||n.rangeCount===0||n.isCollapsed)return"";const s=n.getRangeAt(0);return e.contains(s.commonAncestorContainer)?n.toString().trim():""}function Ql(e,n){if(we(n))return[n.title,n.body].filter(Boolean).join(`
8
+ `)}function ql(e){if(!e||typeof window>"u")return"";const n=window.getSelection();if(!n||n.rangeCount===0||n.isCollapsed)return"";const s=n.getRangeAt(0);return e.contains(s.commonAncestorContainer)?n.toString().trim():""}function Ql(e,n){if(we(n))return[n.title,n.body].filter(Boolean).join(`
9
9
 
10
- `);if(Le.isMindElement(e,n))return nt(n.data);if(U.isDrawElement(n)){const a=n,o=nt(a.text);if(o)return o;const l=nt(a.data);if(l)return l;if(typeof a.textContent=="string")return a.textContent}const s=n;return nt(s.text)||nt(s.data)}function Jl(e,n){if(n.length===0)return{text:"",source:null,title:""};if(n.length===1&&we(n[0])){const l=n[0],d=rs(Kl(Xo(l.id)));if(d)return{text:d,source:"selection",title:l.title||"卡片朗读",sourceId:`card:${l.id}:selection`,origin:{kind:"card",id:l.id}}}const s=n[0],a=n.length===1&&we(s)?s:null,o=rs(n.map(l=>Ql(e,l)).filter(Boolean).join(`
10
+ `);if(Le.isMindElement(e,n))return nt(n.data);if(U.isDrawElement(n)){const a=n,o=nt(a.text);if(o)return o;const l=nt(a.data);if(l)return l;if(typeof a.textContent=="string")return a.textContent}const s=n;return nt(s.text)||nt(s.data)}function Jl(e,n){if(n.length===0)return{text:"",source:null,title:""};if(n.length===1&&we(n[0])){const l=n[0],d=rs(ql(Xo(l.id)));if(d)return{text:d,source:"selection",title:l.title||"卡片朗读",sourceId:`card:${l.id}:selection`,origin:{kind:"card",id:l.id}}}const s=n[0],a=n.length===1&&we(s)?s:null,o=rs(n.map(l=>Ql(e,l)).filter(Boolean).join(`
11
11
 
12
12
  `));return{text:o,source:o?"element":null,title:(a==null?void 0:a.title)||(n.length===1?"画布朗读":`已选 ${n.length} 个元素`),sourceId:n.length===1?`${n[0].type}:${n[0].id}`:`selection:${n.map(l=>l.id).sort().join("|")}`,origin:a?{kind:"card",id:a.id}:void 0}}function Ls(e){return!e.text||!e.sourceId?null:Es({elementId:e.sourceId,title:e.title,content:e.text,origin:e.origin||{kind:"card",id:e.sourceId}})}function er(e,n){const s=Ls(n);if(!s)return[];if(!e.children||!n.origin||n.origin.kind!=="card")return[s];const a=Vo(e,e.children.filter(we));return a.length<=1?[s]:a.map(o=>{var l;return o.id===((l=n.origin)==null?void 0:l.id)?s:Es({elementId:`card:${o.id}`,title:o.title||"卡片朗读",content:[o.title,o.body].filter(Boolean).join(`
13
13
 
14
- `),origin:{kind:"card",id:o.id}})}).filter(o=>!!o)}const tr=i.lazy(()=>De(()=>import("./ai-chat-B-XdoWBQ.js").then(e=>e.sX),__vite__mapDeps([0]),import.meta.url).then(e=>({default:e.ImageEditor}))),nr=i.lazy(()=>De(()=>import("./tool-windows-BnDZa9FH.js").then(e=>e.b5),__vite__mapDeps([0,2]),import.meta.url).then(e=>({default:e.FrameSlideshow}))),sr=2,or=e=>typeof window.requestAnimationFrame=="function"?window.requestAnimationFrame(e):window.setTimeout(()=>e(Date.now()),0),ar=e=>{if(typeof window.cancelAnimationFrame=="function"){window.cancelAnimationFrame(e);return}window.clearTimeout(e)},vr=()=>{var Tt,Ft,At,Mt,lt,rt;const e=Za(),s=Se(e).filter(u=>!ii(u)),{openDialog:a}=vs(),{language:o,t:l}=je(),[d,m]=i.useState(!1),x=i.useRef(d),[h,p]=i.useState(!1),[j,f]=i.useState(null),[M,S]=i.useState(!1),[T,v]=i.useState(""),[P,ne]=i.useState(null),[Q,$]=i.useState(!1),w=i.useRef(!1),[g,c]=i.useState(!1),[C,N]=i.useState(),[Y,se]=i.useState({text:"",title:"",source:null}),[B,he]=i.useState(),[V,F]=i.useState(),L=i.useRef(null);Ml();const ie=li(),ke=ie.mediaType==="reading"?ie.activeReadingSourceId:void 0,Pe=!!Y.sourceId&&!!ke&&ke.startsWith(Y.sourceId),mt=i.useMemo(()=>s.map(u=>u.id).sort().join("|"),[s]),Re=Pe?ie.playing?o==="zh"?"暂停朗读":"Pause reading":o==="zh"?"继续朗读":"Resume reading":o==="zh"?"语音朗读":"Read aloud";i.useEffect(()=>{if(s.length===0||d){se(y=>y.text||y.source?{text:"",title:"",source:null}:y);return}const u=()=>{const y=Jl(e,s);se(b=>b.text===y.text&&b.source===y.source&&b.title===y.title&&b.sourceId===y.sourceId?b:y)};return u(),document.addEventListener("selectionchange",u),()=>{document.removeEventListener("selectionchange",u)}},[e,mt,d]);const _=s.length>0&&!Zo(e),{viewport:q,selection:X,children:le}=e,{refs:ce,floatingStyles:ge}=qo({placement:"top",middleware:[Ko(12),Qo({padding:16}),Jo({fallbackPlacements:["bottom","right","left"]})]});let k={fill:"red"};if(_&&!d){const u=s.some(E=>rr(e,E))&&!te.hasBeenTextEditing(e),y=s.some(E=>dr(e,E)),b=s.length>0&&s.every(E=>U.isDrawElement(E)&&U.isText(E)),A=s.some(E=>Ws(e,E))&&!te.hasBeenTextEditing(e),H=s.some(E=>cr(e,E))&&!te.hasBeenTextEditing(e),G=s.some(E=>dt(E)),R=s.some(E=>ri(E)),I=s.some(E=>we(E)),O=s.length>1&&s.every(E=>we(E)||qa(E)),ue=s.length>0&&!G&&!R&&!I&&s.some(E=>U.isDrawElement(E)&&U.isImage(E))&&!te.hasBeenTextEditing(e),re=s.length===1&&dt(s[0])&&!te.hasBeenTextEditing(e),pe=!G&&!R&&!I&&!te.hasBeenTextEditing(e),be=s[0],Ce=U.isDrawElement(be)&&U.isImage(be)&&((Tt=be.url)==null?void 0:Tt.startsWith("data:image/svg+xml")),Je=s.length===1&&!G&&!R&&U.isDrawElement(s[0])&&U.isImage(s[0])&&!Ce&&!te.hasBeenTextEditing(e),ft=Je,Dt=Je,gt=s.length>0&&!R&&s.some(E=>U.isDrawElement(E)&&U.isImage(E)||dt(E)||Wt(E))&&!te.hasBeenTextEditing(e),xt=s.length>1&&!O&&!G&&!R&&s.every(E=>U.isDrawElement(E)&&U.isImage(E)||U.isDrawElement(E)&&Pn([E])||U.isDrawElement(E)&&U.isShapeElement(E)&&!U.isImage(E)||U.isDrawElement(E)&&U.isArrowLine(E)||U.isDrawElement(E)&&U.isVectorLine(E)||U.isDrawElement(E)&&U.isTable(E)||at.isFreehand(E)||qe.isPenPath(E)||Le.isMindElement(e,E))&&!te.hasBeenTextEditing(e),Fe=s.filter(E=>dt(E)).length>1&&!te.hasBeenTextEditing(e),Ue=s.filter(E=>qe.isPenPath(E)),Bt=Ue.length>0&&!te.hasBeenTextEditing(e);let yt;if(Ue.length>0){const E=Ue[0].cornerRadius??0;yt=Ue.every(ct=>(ct.cornerRadius??0)===E)?E:void 0}const bt=s.filter(E=>at.isFreehand(E)),Lt=(Ue.length>0||bt.length>0)&&!te.hasBeenTextEditing(e);let vt;const $e=[...Ue.map(E=>E.strokeWidth??2),...bt.map(E=>E.strokeWidth??2)];if($e.length>0){const E=$e[0];vt=$e.every(ct=>ct===E)?E:void 0}const ve=s.length>0&&!R&&!te.hasBeenTextEditing(e),fe=s.length>0&&s.every(E=>Le.isMindElement(e,E)),We=s.length>1&&!fe&&!te.hasBeenTextEditing(e),He=s.length>1&&!fe&&!te.hasBeenTextEditing(e),Xe=s.length>1&&!te.hasBeenTextEditing(e)&&s.every(E=>ur(e,E)),wt=s.length>0&&!te.hasBeenTextEditing(e)&&!!Dn(e,s),Rt=s.length===1&&we(s[0])&&!!s[0].noteId&&!te.hasBeenTextEditing(e),Ot=s.length===1&&we(s[0])&&!s[0].noteId&&!te.hasBeenTextEditing(e),Jt=O&&!te.hasBeenTextEditing(e),Ut=s.length===1&&Be(s[0])&&!te.hasBeenTextEditing(e),en=s.length===1&&Wt(s[0])&&!te.hasBeenTextEditing(e),un=typeof window<"u"&&"speechSynthesis"in window&&!te.hasBeenTextEditing(e)&&Y.text.length>0,tn=s.length===1&&!te.hasBeenTextEditing(e)&&Be(s[0]),hn=s.length===1&&!te.hasBeenTextEditing(e)&&ea(s[0]),kt=s.length===1&&!te.hasBeenTextEditing(e)&&Bn(s[0])&&ta(e,s[0]).length>0,$t=kt&&!!s[0].aiMaskInverted;k={...ir(e),hasFill:u,hasFontColor:y,hasFontSize:y,hasStroke:A,hasStrokeStyle:H,hasStrokeWidth:Lt,strokeWidth:vt,hasText:y,isTextOnly:b,hasAIImage:pe,hasAIVideo:ue,hasVideoFrame:re,hasSplitImage:ft,hasImageEdit:Dt,hasRegenerateImage:Je,hasDownloadable:gt,hasMergeable:xt,hasVideoMergeable:Fe,hasCornerRadius:Bt,cornerRadius:yt,hasSizeInput:ve,hasAlignment:We,hasDistribute:He,hasBoolean:Xe,hasMindmapToPPT:wt,hasCardEdit:Rt,hasCardSave:Ot,hasContentMerge:Jt,hasFramePlay:Ut,hasAudioPlayer:en,hasTextToSpeech:un,hasMediaFitPPT:tn,hasImage3DTransform:hn,hasMaskInvert:kt,maskInverted:$t}}const Te=async(u,y)=>{if(!u)return;const b=u.title?`# ${u.title}
14
+ `),origin:{kind:"card",id:o.id}})}).filter(o=>!!o)}const tr=i.lazy(()=>De(()=>import("./ai-chat-BnWVpTEI.js").then(e=>e.sY),__vite__mapDeps([0]),import.meta.url).then(e=>({default:e.ImageEditor}))),nr=i.lazy(()=>De(()=>import("./tool-windows-Bf_pMml-.js").then(e=>e.b5),__vite__mapDeps([0,2]),import.meta.url).then(e=>({default:e.FrameSlideshow}))),sr=2,or=e=>typeof window.requestAnimationFrame=="function"?window.requestAnimationFrame(e):window.setTimeout(()=>e(Date.now()),0),ar=e=>{if(typeof window.cancelAnimationFrame=="function"){window.cancelAnimationFrame(e);return}window.clearTimeout(e)},vr=()=>{var Tt,Ft,At,Mt,lt,rt;const e=Za(),s=Se(e).filter(u=>!ii(u)),{openDialog:a}=vs(),{language:o,t:l}=je(),[d,m]=i.useState(!1),x=i.useRef(d),[h,p]=i.useState(!1),[j,f]=i.useState(null),[M,S]=i.useState(!1),[T,v]=i.useState(""),[P,ne]=i.useState(null),[Q,$]=i.useState(!1),w=i.useRef(!1),[g,c]=i.useState(!1),[C,N]=i.useState(),[Y,se]=i.useState({text:"",title:"",source:null}),[B,he]=i.useState(),[V,F]=i.useState(),L=i.useRef(null);Ml();const ie=li(),ke=ie.mediaType==="reading"?ie.activeReadingSourceId:void 0,Pe=!!Y.sourceId&&!!ke&&ke.startsWith(Y.sourceId),mt=i.useMemo(()=>s.map(u=>u.id).sort().join("|"),[s]),Re=Pe?ie.playing?o==="zh"?"暂停朗读":"Pause reading":o==="zh"?"继续朗读":"Resume reading":o==="zh"?"语音朗读":"Read aloud";i.useEffect(()=>{if(s.length===0||d){se(y=>y.text||y.source?{text:"",title:"",source:null}:y);return}const u=()=>{const y=Jl(e,s);se(b=>b.text===y.text&&b.source===y.source&&b.title===y.title&&b.sourceId===y.sourceId?b:y)};return u(),document.addEventListener("selectionchange",u),()=>{document.removeEventListener("selectionchange",u)}},[e,mt,d]);const _=s.length>0&&!Zo(e),{viewport:K,selection:X,children:le}=e,{refs:ce,floatingStyles:ge}=Ko({placement:"top",middleware:[qo(12),Qo({padding:16}),Jo({fallbackPlacements:["bottom","right","left"]})]});let k={fill:"red"};if(_&&!d){const u=s.some(E=>rr(e,E))&&!te.hasBeenTextEditing(e),y=s.some(E=>dr(e,E)),b=s.length>0&&s.every(E=>U.isDrawElement(E)&&U.isText(E)),A=s.some(E=>Ws(e,E))&&!te.hasBeenTextEditing(e),H=s.some(E=>cr(e,E))&&!te.hasBeenTextEditing(e),G=s.some(E=>dt(E)),R=s.some(E=>ri(E)),I=s.some(E=>we(E)),O=s.length>1&&s.every(E=>we(E)||Ka(E)),ue=s.length>0&&!G&&!R&&!I&&s.some(E=>U.isDrawElement(E)&&U.isImage(E))&&!te.hasBeenTextEditing(e),re=s.length===1&&dt(s[0])&&!te.hasBeenTextEditing(e),pe=!G&&!R&&!I&&!te.hasBeenTextEditing(e),be=s[0],Ce=U.isDrawElement(be)&&U.isImage(be)&&((Tt=be.url)==null?void 0:Tt.startsWith("data:image/svg+xml")),Je=s.length===1&&!G&&!R&&U.isDrawElement(s[0])&&U.isImage(s[0])&&!Ce&&!te.hasBeenTextEditing(e),ft=Je,Dt=Je,gt=s.length>0&&!R&&s.some(E=>U.isDrawElement(E)&&U.isImage(E)||dt(E)||Wt(E))&&!te.hasBeenTextEditing(e),xt=s.length>1&&!O&&!G&&!R&&s.every(E=>U.isDrawElement(E)&&U.isImage(E)||U.isDrawElement(E)&&Pn([E])||U.isDrawElement(E)&&U.isShapeElement(E)&&!U.isImage(E)||U.isDrawElement(E)&&U.isArrowLine(E)||U.isDrawElement(E)&&U.isVectorLine(E)||U.isDrawElement(E)&&U.isTable(E)||at.isFreehand(E)||Ke.isPenPath(E)||Le.isMindElement(e,E))&&!te.hasBeenTextEditing(e),Fe=s.filter(E=>dt(E)).length>1&&!te.hasBeenTextEditing(e),Ue=s.filter(E=>Ke.isPenPath(E)),Bt=Ue.length>0&&!te.hasBeenTextEditing(e);let yt;if(Ue.length>0){const E=Ue[0].cornerRadius??0;yt=Ue.every(ct=>(ct.cornerRadius??0)===E)?E:void 0}const bt=s.filter(E=>at.isFreehand(E)),Lt=(Ue.length>0||bt.length>0)&&!te.hasBeenTextEditing(e);let vt;const $e=[...Ue.map(E=>E.strokeWidth??2),...bt.map(E=>E.strokeWidth??2)];if($e.length>0){const E=$e[0];vt=$e.every(ct=>ct===E)?E:void 0}const ve=s.length>0&&!R&&!te.hasBeenTextEditing(e),fe=s.length>0&&s.every(E=>Le.isMindElement(e,E)),We=s.length>1&&!fe&&!te.hasBeenTextEditing(e),He=s.length>1&&!fe&&!te.hasBeenTextEditing(e),Xe=s.length>1&&!te.hasBeenTextEditing(e)&&s.every(E=>ur(e,E)),wt=s.length>0&&!te.hasBeenTextEditing(e)&&!!Dn(e,s),Rt=s.length===1&&we(s[0])&&!!s[0].noteId&&!te.hasBeenTextEditing(e),Ot=s.length===1&&we(s[0])&&!s[0].noteId&&!te.hasBeenTextEditing(e),Jt=O&&!te.hasBeenTextEditing(e),Ut=s.length===1&&Be(s[0])&&!te.hasBeenTextEditing(e),en=s.length===1&&Wt(s[0])&&!te.hasBeenTextEditing(e),un=typeof window<"u"&&"speechSynthesis"in window&&!te.hasBeenTextEditing(e)&&Y.text.length>0,tn=s.length===1&&!te.hasBeenTextEditing(e)&&Be(s[0]),hn=s.length===1&&!te.hasBeenTextEditing(e)&&ea(s[0]),kt=s.length===1&&!te.hasBeenTextEditing(e)&&Bn(s[0])&&ta(e,s[0]).length>0,$t=kt&&!!s[0].aiMaskInverted;k={...ir(e),hasFill:u,hasFontColor:y,hasFontSize:y,hasStroke:A,hasStrokeStyle:H,hasStrokeWidth:Lt,strokeWidth:vt,hasText:y,isTextOnly:b,hasAIImage:pe,hasAIVideo:ue,hasVideoFrame:re,hasSplitImage:ft,hasImageEdit:Dt,hasRegenerateImage:Je,hasDownloadable:gt,hasMergeable:xt,hasVideoMergeable:Fe,hasCornerRadius:Bt,cornerRadius:yt,hasSizeInput:ve,hasAlignment:We,hasDistribute:He,hasBoolean:Xe,hasMindmapToPPT:wt,hasCardEdit:Rt,hasCardSave:Ot,hasContentMerge:Jt,hasFramePlay:Ut,hasAudioPlayer:en,hasTextToSpeech:un,hasMediaFitPPT:tn,hasImage3DTransform:hn,hasMaskInvert:kt,maskInverted:$t}}const Te=async(u,y)=>{if(!u)return;const b=u.title?`# ${u.title}
15
15
 
16
16
  `:"",A=u.body||"",H=`${b}${A}`.trim();try{await Ya(H),W.success(o==="zh"?"已复制到剪贴板":"Copied to clipboard",2e3)}catch{W.error(o==="zh"?"复制失败":"Copy failed",2e3)}},Me=async()=>{const u=Ja(e,s);if(u.length<2)return;const y=u[0],b=u.map((H,G)=>G===0&&we(y)&&we(H)?(H.body||"").trim():ei(H)).filter(Boolean).join(`
17
17
 
18
- `).trim();if(!b){W.warning(o==="zh"?"没有可合并的内容":"No content to merge");return}const A=u.flatMap(H=>we(H)&&H.noteId?[H.noteId]:[]);try{const H=await ti(A,b),G=u.slice(1).map(I=>e.children.findIndex(O=>O.id===I.id)).filter(I=>I>=0).sort((I,O)=>O-I);for(const I of G)K.removeNode(e,[I]);let R;if(we(y)){const I=e.children.findIndex(ue=>ue.id===y.id);if(I<0)throw new Error(o==="zh"?"合并目标不存在":"Merge target missing");const O={body:b};H&&(O.noteId=H),K.setNode(e,O,[I]),R=e.children[I]}else{const I=st(e,[y],!1),O=e.children.findIndex(be=>be.id===y.id);if(O<0)throw new Error(o==="zh"?"合并目标不存在":"Merge target missing");const ue=Math.max(I.width,320),re=Math.max(I.height,180),pe={type:"card",id:`card-${Date.now().toString(36)}-${Math.random().toString(36).slice(2,9)}`,body:b,fillColor:"#FA8C16",points:[[I.x,I.y],[I.x+ue,I.y+re]],children:[],...H?{noteId:H}:{}};K.insertNode(e,pe,[O]),K.removeNode(e,[O+1]),R=e.children[O]}Vn(e),R&&Xn(e,R),W.success(o==="zh"?`已合并 ${u.length} 个元素`:`Merged ${u.length} elements`)}catch(H){console.error("[PopupToolbar] Failed to merge content:",H),W.error((H==null?void 0:H.message)||(o==="zh"?"合并内容失败":"Failed to merge content"))}},Oe=i.useCallback(async()=>{const u=s[0];if(!(s.length!==1||!U.isDrawElement(u)||!U.isImage(u)||!u.url))try{const y=await na.findImageTaskByResultUrl(u.url);if(!y){W.warning(o==="zh"?"未找到该图片的历史生成任务":"No historical generation task found for this image");return}ci({...fi(y),source:"canvas-toolbar"})}catch(y){console.error("[PopupToolbar] Failed to prefill image generation:",y),W.error(o==="zh"?"回填失败,请稍后重试":"Failed to load generation inputs, please try again")}},[o,s]),xe=i.useCallback(()=>{var ue;const u=s.length===1&&Be(s[0])?s[0]:null;if(!u){a(xn.aiImageGeneration);return}const y=qt.getRectangleByPoints(u.points),b=u.pptMeta,A=sa(b),H=b?((ue=b.commonPrompt)==null?void 0:ue.trim())||oa(b.styleSpec):"",G=aa(e,u.id),R=ia(e,u.id),I=[];G!=null&&G.url&&I.push({url:G.url,name:`${u.name||"frame"}-reference.png`}),R!=null&&R.url&&R.url!==(G==null?void 0:G.url)&&I.push({url:R.url,name:`${u.name||"frame"}-previous-reference.png`});const O=new Set(I.map(re=>re.url));la(b==null?void 0:b.referenceImages).forEach((re,pe)=>{O.has(re)||(O.add(re),I.push({url:re,name:`${u.name||"frame"}-deck-reference-${pe+1}.png`}))}),a(xn.aiImageGeneration,{initialPrompt:ra(H,A),initialImages:I,initialAspectRatio:mi(y.width,y.height),initialWidth:y.width,initialHeight:y.height,targetFrameId:u.id,targetFrameDimensions:{width:y.width,height:y.height},autoInsertToCanvas:!0,pptSlideImage:!0,pptSlidePrompt:A,pptReplaceElementId:G==null?void 0:G.elementId})},[e,a,s]),Ve=i.useCallback(()=>{const u=s[0];if(s.length!==1||!Bn(u))return;const y=e.children.findIndex(A=>A.id===u.id);if(y<0)return;const b=!u.aiMaskInverted;K.setNode(e,{aiMaskInverted:b||void 0},[y]),W.success(b?o==="zh"?"已开启蒙层反选":"Mask inverted":o==="zh"?"已关闭蒙层反选":"Mask inversion off",1200)},[e,o,s]),Pt=i.useCallback(()=>{if(!_||d)return;const u=Se(e);if(u.length===0){F(void 0);return}const y=st(e,u,!1),[b,A]=qt.getPoints(y),H=Ln(e,Rn(e,b)),G=Ln(e,Rn(e,A)),R=H[0]+(G[0]-H[0])/2,I=H[1];if(ce.setPositionReference({getBoundingClientRect(){return{width:1,height:1,x:R,y:I,top:I,left:R,right:R+1,bottom:I+1}}}),F({top:H[1],left:H[0],right:G[0],bottom:G[1],width:G[0]-H[0],height:G[1]-H[1]}),L.current){const O=L.current.getBoundingClientRect();he({top:O.top,left:O.left,width:O.width,height:O.height})}},[e,d,_,ce]);return i.useEffect(()=>{if(!_||d)return;let u=!1,y=0,b=null;const A=()=>{u||(Pt(),!(y>=sr)&&(y+=1,b=or(A)))};return A(),()=>{u=!0,b!==null&&ar(b)}},[_,d,q,X,le,ge,Pt]),i.useEffect(()=>{w.current=Q},[Q]),i.useEffect(()=>{if(s.length===0&&!d){const u=setTimeout(()=>{$(!1)},50);return()=>clearTimeout(u)}},[s.length,d]),i.useEffect(()=>{x.current=d},[d]),i.useEffect(()=>{const{pointerUp:u,pointerMove:y}=e;return e.pointerMove=b=>{(On(e)||Un(e))&&!x.current&&m(!0),y(b)},e.pointerUp=b=>{x.current&&(On(e)||Un(e))&&m(!1),u(b)},()=>{e.pointerUp=u,e.pointerMove=y}},[e]),t.jsxs(t.Fragment,{children:[_&&!d&&t.jsx(ze,{padding:1,className:z("popup-toolbar",Ie),ref:u=>{ce.setFloating(u),L.current=u},style:ge,"data-testid":"popup-toolbar",children:t.jsxs(Xt.Row,{gap:1,children:[k.hasFill&&t.jsx(al,{board:e,currentColor:k.fill,title:l("toolbar.fillColor"),children:t.jsx("label",{className:z("fill-label","color-label",{"color-white":k.fill&&Yt(k.fill)&&ps(pt(k.fill)),"color-mixed":k.fill===void 0,"color-gradient":k.fill&&ht(k.fill)&&k.fill.type==="gradient","color-image":k.fill&&ht(k.fill)&&k.fill.type==="image"}),style:k.fill===void 0?void 0:{background:Yt(k.fill)?k.fill:ht(k.fill)?k.fill.type==="gradient"&&k.fill.gradient?ca(k.fill.gradient):k.fill.type==="solid"&&k.fill.solid?k.fill.solid.color:k.fill.type==="image"&&((Ft=k.fill.image)!=null&&Ft.imageUrl)?`url(${k.fill.image.imageUrl}) center/cover no-repeat`:void 0:void 0}})},3),k.hasStroke&&t.jsx(Vi,{board:e,currentColor:k.strokeColor,title:l("toolbar.stroke"),hasStrokeStyle:k.hasStrokeStyle||!1,hasStrokeWidth:k.hasStrokeWidth||!1,currentStrokeWidth:k.strokeWidth,children:t.jsx("label",{className:z("stroke-label","color-label",{"color-mixed":k.strokeColor===void 0}),style:{borderColor:k.strokeColor}})},2),k.hasFontColor&&t.jsx(Wi,{board:e,currentColor:(At=k.marks)==null?void 0:At.color,title:l("toolbar.fontColor"),fontColorIcon:t.jsx(da,{currentColor:(Mt=k.marks)==null?void 0:Mt.color})},0),k.hasFontSize&&t.jsx(Gi,{board:e,currentFontSize:k.fontSize,title:l("toolbar.fontSize")},1),k.hasCornerRadius&&t.jsx(il,{board:e,currentRadius:k.cornerRadius,title:l("toolbar.cornerRadius"),selectionRect:V},"corner-radius"),k.hasText&&t.jsx(cl,{board:e,title:"Link"},4),k.isTextOnly&&t.jsx(xl,{board:e,language:o,title:o==="zh"?"提示词":"Prompts"},"prompt"),k.hasTextToSpeech&&t.jsx(oe,{className:"text-to-speech",type:"icon",icon:Pe&&ie.playing?t.jsx(pa,{size:15}):t.jsx(ma,{size:15}),visible:!0,selected:Pe&&ie.playing,tooltip:Re,"aria-label":Re,"data-track":"toolbar_click_text_to_speech",onPointerUp:()=>{if(!Y.text)return;const u=Ls(Y);if(!u)return;const y=er(e,Y);if(Pe){ie.playing?ie.pausePlayback():ie.resumePlayback();return}$n({source:u,queue:y.length>0?y:[u],queueTab:{queueId:ha,queueName:ua}})}},"text-to-speech"),k.hasText&&t.jsx(oe,{className:"property-settings",type:"icon",icon:t.jsx(fa,{}),visible:!0,selected:Q,tooltip:l("propertyPanel.title"),"aria-label":l("propertyPanel.title"),"data-track":"toolbar_click_property_settings",onPointerUp:()=>{$(!Q)}},"property-settings"),k.hasAlignment&&t.jsx(bl,{board:e,title:l("toolbar.alignment")},"alignment"),k.hasDistribute&&t.jsx(vl,{board:e,title:l("toolbar.distribute")},"distribute"),k.hasBoolean&&t.jsx(wl,{board:e,title:l("toolbar.boolean")},"boolean"),k.hasMindmapToPPT&&t.jsx(oe,{className:"mindmap-to-ppt",type:"icon",icon:t.jsx(ga,{size:15}),visible:!0,tooltip:o==="zh"?"转换为PPT":"Convert to PPT","aria-label":o==="zh"?"转换为PPT":"Convert to PPT","data-track":"toolbar_click_mindmap_to_ppt",onPointerUp:async()=>{const u=Dn(e,s);if(!u)return;const y=W.loading(o==="zh"?"正在转换为PPT...":"Converting to PPT...",0);try{const{generatePPTFromMindmap:b}=await De(async()=>{const{generatePPTFromMindmap:H}=await import("./ai-chat-B-XdoWBQ.js").then(G=>G.sP);return{generatePPTFromMindmap:H}},__vite__mapDeps([0]),import.meta.url),A=await b(e,u);W.close(y),A.success?W.success(o==="zh"?`已生成 ${A.pageCount} 页PPT`:`Generated ${A.pageCount} PPT slides`):W.error(A.error||(o==="zh"?"转换失败":"Conversion failed"))}catch(b){W.close(y),W.error(b.message||(o==="zh"?"转换失败":"Conversion failed"))}}},"mindmap-to-ppt"),k.hasCardEdit&&t.jsx(oe,{className:"card-edit",type:"icon",icon:t.jsx(Wn,{size:15}),visible:!0,tooltip:o==="zh"?"在知识库中编辑":"Edit in Knowledge Base","aria-label":o==="zh"?"在知识库中编辑":"Edit in Knowledge Base","data-track":"toolbar_click_card_edit",onPointerUp:async()=>{const u=s[0];u&&await Ka(e,u,o)}},"card-edit"),k.hasCardSave&&t.jsx(oe,{className:"card-save",type:"icon",icon:t.jsx(xa,{size:15}),visible:!0,tooltip:o==="zh"?"保存到知识库":"Save to Knowledge Base","aria-label":o==="zh"?"保存到知识库":"Save to Knowledge Base","data-track":"toolbar_click_card_save",onPointerUp:async()=>{const u=s[0];if(!u)return;await Qa(e,u,o)&&W.success(o==="zh"?"已保存到知识库":"Saved to knowledge base")}},"card-save"),(k.hasCardEdit||k.hasCardSave)&&t.jsx(oe,{className:"card-copy",type:"icon",icon:t.jsx(ya,{size:15}),visible:!0,tooltip:o==="zh"?"复制文本内容":"Copy text content","aria-label":o==="zh"?"复制文本内容":"Copy text content","data-track":"toolbar_click_card_copy",onPointerDown:({event:u})=>{u.stopPropagation()},onPointerUp:async()=>{await Te(s[0])}},"card-copy"),k.hasContentMerge&&t.jsx(oe,{className:"content-merge",type:"icon",icon:t.jsx(Hn,{}),visible:!0,tooltip:o==="zh"?"合并内容":"Merge Content","aria-label":o==="zh"?"合并内容":"Merge Content","data-track":"toolbar_click_content_merge",onPointerUp:()=>{Me()}},"content-merge"),k.hasAIImage&&t.jsx(oe,{className:"ai-image",type:"icon",icon:t.jsx(ba,{}),visible:!0,tooltip:o==="zh"?"AI图片生成":"AI Image Generation","aria-label":o==="zh"?"AI图片生成":"AI Image Generation","data-track":"toolbar_click_ai_image",onPointerUp:xe},5),k.hasAIVideo&&t.jsx(oe,{className:"ai-video",type:"icon",icon:t.jsx(va,{}),visible:!0,tooltip:o==="zh"?"AI视频生成":"AI Video Generation","aria-label":o==="zh"?"AI视频生成":"AI Video Generation","data-track":"toolbar_click_ai_video",onPointerUp:()=>{a(xn.aiVideoGeneration)}},6),k.hasVideoFrame&&t.jsx(oe,{className:"video-frame",type:"icon",icon:t.jsx(wa,{}),visible:!0,tooltip:o==="zh"?"视频帧选择":"Video Frame Selection","aria-label":o==="zh"?"视频帧选择":"Video Frame Selection","data-track":"toolbar_click_video_frame",onPointerUp:()=>{const u=s.find(y=>dt(y));u&&(f(u),p(!0))}},7),k.hasMediaFitPPT&&t.jsx(oe,{className:"media-fit-ppt",type:"icon",icon:t.jsx(ka,{size:15}),visible:!0,tooltip:o==="zh"?"素材自适应PPT":"Fit media to PPT","aria-label":o==="zh"?"素材自适应PPT":"Fit media to PPT","data-track":"toolbar_click_media_fit_ppt",onPointerUp:()=>{(async()=>{const u=s[0];if(!Be(u))return;const y=await ql(e,u);if(y.fittedCount>0){W.success(o==="zh"?`已自适应 ${y.fittedCount} 个素材`:`Fitted ${y.fittedCount} media item${y.fittedCount>1?"s":""}`);return}W.warning(o==="zh"?"未找到可自适应的PPT素材":"No media item can be fitted to PPT")})()}},"media-fit-ppt"),k.hasSplitImage&&t.jsx(oe,{className:"split-image",type:"icon",icon:t.jsx(Ca,{}),visible:!0,tooltip:o==="zh"?"智能拆图":"Smart Split","aria-label":o==="zh"?"智能拆图":"Smart Split","data-track":"toolbar_click_split_image",onPointerUp:async()=>{const u=s[0];if(U.isImage(u)&&u.url){const y=W.loading(o==="zh"?"正在分析图片...":"Analyzing image...",0);try{const b=st(e,[u],!1),A=await ja(e,u.url,{sourceRect:{x:b.x,y:b.y,width:b.width,height:b.height},scrollToResult:!0});W.close(y),A.success?W.success(o==="zh"?`成功拆分为 ${A.count} 张图片`:`Split into ${A.count} images`):W.warning(A.error||(o==="zh"?"拆图失败":"Split failed"))}catch(b){W.close(y),W.error(b.message||(o==="zh"?"拆图失败":"Split failed"))}}}},"split-image"),k.hasImageEdit&&t.jsx(oe,{className:"image-edit",type:"icon",icon:t.jsx(Wn,{size:15}),visible:!0,tooltip:o==="zh"?"编辑图片":"Edit Image","aria-label":o==="zh"?"编辑图片":"Edit Image","data-track":"toolbar_click_image_edit",onPointerUp:()=>{const u=s[0];U.isImage(u)&&u.url&&(v(u.url),ne(u),S(!0))}},"image-edit"),k.hasMaskInvert&&t.jsx(oe,{className:"mask-invert",type:"icon",icon:t.jsx(Sa,{size:15}),visible:!0,selected:k.maskInverted,tooltip:o==="zh"?"蒙层反选:反向填充图片":"Invert mask: fill the opposite area","aria-label":o==="zh"?"蒙层反选":"Invert mask","data-track":"toolbar_click_mask_invert",onPointerUp:Ve},"mask-invert"),k.hasDownloadable&&t.jsx(oe,{className:"download",type:"icon",icon:t.jsx(Ea,{}),visible:!0,tooltip:o==="zh"?"下载":"Download","aria-label":o==="zh"?"下载":"Download","data-track":"toolbar_click_download",onPointerUp:async()=>{const u=[];for(const A of s)U.isDrawElement(A)&&U.isImage(A)&&A.url?u.push({url:A.url,type:"image"}):dt(A)&&A.url?u.push({url:A.url,type:"video"}):Wt(A)&&A.audioUrl&&u.push({url:A.audioUrl,type:"audio",filename:Na(A.title,"audio","mp3"),audioMetadata:{title:A.title,prompt:A.prompt,tags:A.tags,coverUrl:A.previewImageUrl,artist:A.modelVersion||"Aitu",album:"Aitu Generated"}});if(u.length===0){W.warning(o==="zh"?"没有可下载的内容":"No downloadable content");return}const y=u.length>1?o==="zh"?"正在打包下载...":"Packaging download...":o==="zh"?"正在下载...":"Downloading...",b=W.loading(y,0);try{const{unifiedCacheService:A}=await De(async()=>{const{unifiedCacheService:I}=await import("./ai-chat-B-XdoWBQ.js").then(O=>O.sJ);return{unifiedCacheService:I}},__vite__mapDeps([0]),import.meta.url),{downloadFromBlob:H}=await De(async()=>{const{downloadFromBlob:I}=await import("./ai-chat-B-XdoWBQ.js").then(O=>O.sG);return{downloadFromBlob:I}},__vite__mapDeps([0]),import.meta.url),G=[];for(const I of u)if(I.url.startsWith("blob:")){const O=I.url.indexOf("#"),ue=O>0?I.url.substring(O+1):null;if(ue&&ue.startsWith("merged-video-")){const re=await A.getCachedBlob(ue);if(re){const pe=re.type||"video/webm",be=pe.startsWith("video/mp4")?"mp4":pe.startsWith("video/webm")?"webm":"bin",Ce=`merged-video-${Date.now()}.${be}`;H(re,Ce);continue}else console.warn("[Download] Cache not found for taskId:",ue)}try{const pe=await(await fetch(I.url)).blob(),be=pe.type.startsWith("video/mp4")?"mp4":pe.type.startsWith("video/webm")?"webm":pe.type.startsWith("image/")?"png":"bin",Ce=`${I.type}_${Date.now()}.${be}`;H(pe,Ce)}catch(re){throw console.error("[Download] Failed to fetch blob URL:",re),new Error(`Failed to download ${I.type}: Blob URL inaccessible`)}}else G.push(I);let R;G.length>0&&(R=await _a(G)),W.close(b),R!=null&&R.openedCount&&R.downloadedCount===0?W.success(o==="zh"?R.openedCount>1?`已打开 ${R.openedCount} 个链接,请在新标签页下载`:"资源不支持直接下载,已打开链接":R.openedCount>1?`Opened ${R.openedCount} links for download`:"Opened link for download"):W.success(u.length>1?o==="zh"?`已下载 ${u.length} 个文件`:`Downloaded ${u.length} files`:o==="zh"?"下载成功":"Download complete")}catch(A){W.close(b),W.error(A.message||(o==="zh"?"下载失败":"Download failed"))}}},"download"),k.hasMergeable&&t.jsx(oe,{className:"merge",type:"icon",icon:t.jsx(Hn,{}),visible:!0,tooltip:o==="zh"?"合并为图片":"Merge to Image","aria-label":o==="zh"?"合并为图片":"Merge to Image","data-track":"toolbar_click_merge",onPointerUp:async()=>{const u=Ia("图片合并"),y=W.loading(o==="zh"?"正在合并...":"Merging...",0);try{const b=s.filter(ve=>{const fe=ve.url||ve.imageUrl;if(!fe||fe.startsWith("/")||fe.startsWith("data:")||fe.startsWith("blob:"))return!1;try{return new URL(fe).origin!==location.origin}catch{return!1}});if(b.length>0){const ve=b.map(async He=>{const Xe=He.url||He.imageUrl;try{const wt=new AbortController,Rt=setTimeout(()=>wt.abort(),3e3),Ot=await fetch(Xe,{method:"HEAD",mode:"cors",signal:wt.signal});return clearTimeout(Rt),Ot.ok}catch{return!1}});if((await Promise.all(ve)).some(He=>!He)){W.close(y),W.warning(o==="zh"?"部分外部图片无法访问,请先下载到本地后再合并":"Some external images are inaccessible. Please download them locally first."),u();return}}const A=st(e,s,!1),H=[...s].sort((ve,fe)=>{const We=e.children.findIndex(Xe=>Xe.id===ve.id),He=e.children.findIndex(Xe=>Xe.id===fe.id);return We-He}),G=await za(e,{elements:H,fillStyle:"transparent",inlineStyleClassNames:".extend,.emojis,.text",ratio:2});if(!G)throw new Error(o==="zh"?"合并失败:无法生成图片":"Merge failed: Unable to generate image");const R=new Image;await new Promise((ve,fe)=>{R.onload=()=>ve(),R.onerror=()=>fe(new Error("Failed to load merged image")),R.src=G});const I=document.createElement("canvas");I.width=R.width,I.height=R.height;const O=I.getContext("2d");if(!O)throw new Error("Failed to get canvas context");O.drawImage(R,0,0);const ue=Pa(I),{canvas:re,left:pe,top:be,trimmedWidth:Ce,trimmedHeight:Je}=ue,ft=await new Promise((ve,fe)=>{re.toBlob(We=>{We?ve(We):fe(new Error("Failed to convert canvas to blob"))},"image/png")}),{unifiedCacheService:Dt}=await De(async()=>{const{unifiedCacheService:ve}=await import("./ai-chat-B-XdoWBQ.js").then(fe=>fe.sJ);return{unifiedCacheService:ve}},__vite__mapDeps([0]),import.meta.url),gt=`merged-image-${Date.now()}`,xt=`/__aitu_cache__/image/${gt}.png`,Qt=xt;await Dt.cacheMediaFromBlob(Qt,ft,"image",{taskId:gt});const Fe=2,Ue=A.x+pe/Fe,Bt=A.y+be/Fe,yt=Ce/Fe,bt=Je/Fe;Gn(e);const Lt=e.children.length,vt={url:xt,width:yt,height:bt};js.insertImage(e,vt,[Ue,Bt]);const $e=e.children[Lt];$e&&(Vn(e),Xn(e,$e)),W.close(y),u(),W.success(o==="zh"?`已将 ${s.length} 个元素合并为图片`:`Merged ${s.length} elements into image`)}catch(b){W.close(y),u(),W.error(b.message||(o==="zh"?"合并失败":"Merge failed"))}}},"merge"),k.hasVideoMergeable&&t.jsx(oe,{className:"video-merge",type:"icon",icon:t.jsx(Ta,{}),visible:!0,tooltip:o==="zh"?"合成视频":"Merge Videos","aria-label":o==="zh"?"合成视频":"Merge Videos","data-track":"toolbar_click_video_merge",onPointerUp:async()=>{const u=[];for(const b of s)dt(b)&&b.url&&u.push(b.url);if(u.length<2){W.warning(o==="zh"?"请选择至少2个视频":"Please select at least 2 videos");return}const y=W.loading(o==="zh"?"正在合成视频...":"Merging videos...",0);try{const b=await pi(u,(A,H)=>{const G={downloading:o==="zh"?"下载视频...":"Downloading videos...",decoding:o==="zh"?"解码视频...":"Decoding videos...",encoding:o==="zh"?"编码视频...":"Encoding videos...",finalizing:o==="zh"?"生成文件中...":"Finalizing..."}});W.close(y);try{const{quickInsert:A}=await De(async()=>{const{quickInsert:H}=await import("./ai-chat-B-XdoWBQ.js").then(G=>G.t0);return{quickInsert:H}},__vite__mapDeps([0]),import.meta.url);await A("video",b.url),W.success(o==="zh"?`已合成并插入 ${u.length} 个视频`:`Merged and inserted ${u.length} videos`)}catch(A){console.error("[VideoMerge] Failed to insert video:",A);const H=b.blob.type||"video/webm",G=H.startsWith("video/mp4")?"mp4":"webm",R=new Blob([b.blob],{type:H}),I=URL.createObjectURL(R),O=document.createElement("a");O.href=I,O.download=`merged-video-${Date.now()}.${G}`,document.body.appendChild(O),O.click(),document.body.removeChild(O),setTimeout(()=>URL.revokeObjectURL(I),1e3),W.warning(o==="zh"?`视频已合成,但插入失败,已自动下载 (${G.toUpperCase()})`:`Video merged but failed to insert, downloaded as ${G.toUpperCase()}`)}}catch(b){W.close(y),W.error(b.message||(o==="zh"?"视频合成失败":"Video merge failed"))}}},"video-merge"),t.jsx(yl,{board:e,title:l("textEffect.layer")},"layer-control"),k.hasImage3DTransform&&s.length===1&&t.jsx(Tl,{board:e,element:s[0],language:o,selectionRect:V,title:o==="zh"?"图片 3D 调节":"Image 3D Adjust"},"image-3d-transform"),k.hasSizeInput&&t.jsx(rl,{board:e},"size-input"),k.hasFramePlay&&t.jsx(oe,{className:"frame-play",type:"icon",icon:t.jsx(Yn,{size:15}),visible:!0,tooltip:o==="zh"?"播放幻灯片":"Play Slideshow","aria-label":o==="zh"?"播放幻灯片":"Play Slideshow","data-track":"toolbar_click_frame_play",onPointerUp:()=>{const u=s.find(y=>Be(y));u&&(N(u.id),c(!0))}},"frame-play"),k.hasAudioPlayer&&t.jsx(oe,{className:"audio-player-play",type:"icon",icon:t.jsx(Yn,{size:15}),visible:!0,tooltip:o==="zh"?"在音乐播放器中播放":"Play in Music Player","aria-label":o==="zh"?"在音乐播放器中播放":"Play in Music Player","data-track":"toolbar_click_audio_player_play",onPointerUp:()=>{const u=s.find(y=>Wt(y));!u||!Wt(u)||$n({source:{elementId:u.id,audioUrl:u.audioUrl,title:u.title,duration:u.duration,previewImageUrl:u.previewImageUrl,providerTaskId:u.providerTaskId,clipId:u.clipId,clipIds:u.clipIds},queue:Fa(e.children),queueTab:{queueId:Ma,queueName:Aa}})}},"audio-player-play"),t.jsx(oe,{className:"duplicate",type:"icon",icon:t.jsx(Ba,{}),visible:!0,tooltip:l("general.duplicate"),"aria-label":l("general.duplicate"),"data-track":"toolbar_click_duplicate",onPointerUp:()=>{if(s.length===1&&Be(s[0])){const y=di(e,s[0],o);y&&ui(e,y)}else Da(e)}},8),k.hasRegenerateImage&&t.jsx(oe,{className:"regenerate-image",type:"icon",icon:t.jsx(La,{size:15}),visible:!0,tooltip:o==="zh"?"以当前提示词再次生成":"Generate again with the current prompt","aria-label":o==="zh"?"再次生成":"Generate again","data-track":"toolbar_click_regenerate_image_prefill",onPointerUp:()=>{Oe()}},"regenerate-image"),t.jsx(oe,{className:"trash",type:"icon",icon:t.jsx(Ra,{}),visible:!0,tooltip:l("general.delete"),"aria-label":l("general.delete"),"data-track":"toolbar_click_delete",onPointerUp:()=>{Gn(e)}},9)]})}),h&&j&&t.jsx(Dl,{visible:h,videoUrl:j.url||"",onClose:()=>{p(!1),f(null)},onConfirm:async(u,y)=>{try{j&&await Bl(e,j,u,y)}catch(b){console.error("Failed to insert video frame:",b)}}}),M&&T&&t.jsx(i.Suspense,{fallback:null,children:t.jsx(tr,{visible:M,imageUrl:T,showOverwrite:!!P,onClose:()=>{S(!1),v(""),ne(null)},onOverwrite:async u=>{if(P)try{const{unifiedCacheService:y}=await De(async()=>{const{unifiedCacheService:O}=await import("./ai-chat-B-XdoWBQ.js").then(ue=>ue.sJ);return{unifiedCacheService:O}},__vite__mapDeps([0]),import.meta.url),b=`edited-image-${Date.now()}`,A=`/__aitu_cache__/image/${b}.png`,G=await(await fetch(u)).blob();await y.cacheMediaFromBlob(A,G,"image",{taskId:b});const R=new Image;await new Promise((O,ue)=>{R.onload=()=>O(),R.onerror=()=>ue(new Error("Failed to load edited image")),R.src=u});const I=e.children.findIndex(O=>O.id===P.id);if(I>=0){const O=e.children[I],{newPoints:ue}=await hi({url:O.url,width:O.width,height:O.height,points:O.points||[[0,0],[0,0]]},R.naturalWidth,R.naturalHeight);K.setNode(e,{url:A,width:R.naturalWidth,height:R.naturalHeight,points:ue},[I])}}catch(y){console.error("Failed to update image:",y),W.error(o==="zh"?"更新失败":"Update failed")}},onInsert:async u=>{try{const{unifiedCacheService:y}=await De(async()=>{const{unifiedCacheService:be}=await import("./ai-chat-B-XdoWBQ.js").then(Ce=>Ce.sJ);return{unifiedCacheService:be}},__vite__mapDeps([0]),import.meta.url),b=`edited-image-${Date.now()}`,A=`/__aitu_cache__/image/${b}.png`,G=await(await fetch(u)).blob();await y.cacheMediaFromBlob(A,G,"image",{taskId:b});const R=new Image;await new Promise((be,Ce)=>{R.onload=()=>be(),R.onerror=()=>Ce(new Error("Failed to load edited image")),R.src=u});const I=Oa(e),O=P?P.points[1][0]-P.points[0][0]+20:0,ue=P?P.points[0][0]:I?I[0]+100:100,re=P?P.points[0][1]:I?I[1]+100:100,pe=[ue+O,re];await Ua(e,A,pe,!1,{width:R.naturalWidth,height:R.naturalHeight},!1,!0)}catch(y){console.error("Failed to insert image:",y),W.error(o==="zh"?"插入失败":"Insert failed")}}})}),k.hasText&&t.jsx(Cl,{board:e,isOpen:Q,onClose:()=>$(!1),currentFontSize:k.fontSize,currentFontFamily:(lt=k.marks)==null?void 0:lt["font-family"],currentColor:(rt=k.marks)==null?void 0:rt.color,toolbarRect:B,selectionRect:V}),g&&t.jsx(i.Suspense,{fallback:null,children:t.jsx(nr,{visible:g,board:e,onClose:()=>{c(!1),N(void 0)},initialFrameId:C})})]})},Rs=(e,n)=>{const s=Cs(n);return{fill:dn(n),strokeColor:$a(e,n),fontSize:s["font-size"],marks:s}},Os=(e,n)=>{const s=Cs(n);return{fill:dn(n),strokeColor:Wa(e,n),fontSize:s["font-size"],marks:s}},ir=e=>{const n=Se(e);if(n.length===0)return{fill:void 0,strokeColor:void 0};if(n.length===1){const s=n[0];return we(s)?{fill:s.fillColor,strokeColor:void 0}:Le.isMindElement(e,s)?Rs(e,s):at.isFreehand(s)?Us(e,s):qe.isPenPath(s)?$s(e,s):Os(e,s)}return lr(e,n)},lr=(e,n)=>{const s=n.map(m=>we(m)?{fill:m.fillColor,strokeColor:void 0}:Le.isMindElement(e,m)?Rs(e,m):at.isFreehand(m)?Us(e,m):qe.isPenPath(m)?$s(e,m):U.isDrawElement(m)?Os(e,m):{fill:void 0,strokeColor:void 0}),a=s.map(m=>m.fill),o=s.map(m=>m.strokeColor),l=a.every(m=>m===a[0]),d=o.every(m=>m===o[0]);return{fill:l?a[0]:void 0,strokeColor:d?o[0]:void 0}},Us=(e,n)=>({fill:dn(n),strokeColor:Ha(e,n)}),$s=(e,n)=>({fill:dn(n),strokeColor:n.strokeColor,cornerRadius:n.cornerRadius}),rr=(e,n)=>we(n)||Le.isMindElement(e,n)||Ga(e,n)?!0:at.isFreehand(n)?Va(n.points):qe.isPenPath(n)?n.closed:U.isDrawElement(n)?U.isShapeElement(n)&&!U.isImage(n)&&!U.isText(n)&&Ss(n):!1,Ws=(e,n)=>Le.isMindElement(e,n)||at.isFreehand(n)||qe.isPenPath(n)?!0:U.isDrawElement(n)?U.isShapeElement(n)&&!U.isImage(n)&&!U.isText(n)||U.isArrowLine(n)||U.isVectorLine(n)||U.isTable(n):!1,cr=(e,n)=>Ws(e,n),dr=(e,n)=>Le.isMindElement(e,n)?!0:U.isDrawElement(n)?Pn([n]):!1,wr=e=>e===Xa?null:e,ur=(e,n)=>{if(qe.isPenPath(n))return n.closed;if(at.isFreehand(n)){const s=n.points;if(!s||s.length<3)return!1;const a=s[0],o=s[s.length-1];return Math.hypot(o[0]-a[0],o[1]-a[1])<=10}return U.isDrawElement(n)?U.isImage(n)||U.isText(n)||U.isArrowLine(n)||U.isVectorLine(n)?!1:U.isShapeElement(n)&&Ss(n):(Le.isMindElement(e,n),!1)};export{vr as PopupToolbar,wr as getColorPropertyValue,Os as getDrawElementState,ir as getElementState,Us as getFreehandElementState,Rs as getMindElementState,$s as getPenPathElementState,rr as hasFillProperty,Ws as hasStrokeProperty,cr as hasStrokeStyleProperty,dr as hasTextProperty,ur as supportsBooleanOperation};
18
+ `).trim();if(!b){W.warning(o==="zh"?"没有可合并的内容":"No content to merge");return}const A=u.flatMap(H=>we(H)&&H.noteId?[H.noteId]:[]);try{const H=await ti(A,b),G=u.slice(1).map(I=>e.children.findIndex(O=>O.id===I.id)).filter(I=>I>=0).sort((I,O)=>O-I);for(const I of G)q.removeNode(e,[I]);let R;if(we(y)){const I=e.children.findIndex(ue=>ue.id===y.id);if(I<0)throw new Error(o==="zh"?"合并目标不存在":"Merge target missing");const O={body:b};H&&(O.noteId=H),q.setNode(e,O,[I]),R=e.children[I]}else{const I=st(e,[y],!1),O=e.children.findIndex(be=>be.id===y.id);if(O<0)throw new Error(o==="zh"?"合并目标不存在":"Merge target missing");const ue=Math.max(I.width,320),re=Math.max(I.height,180),pe={type:"card",id:`card-${Date.now().toString(36)}-${Math.random().toString(36).slice(2,9)}`,body:b,fillColor:"#FA8C16",points:[[I.x,I.y],[I.x+ue,I.y+re]],children:[],...H?{noteId:H}:{}};q.insertNode(e,pe,[O]),q.removeNode(e,[O+1]),R=e.children[O]}Vn(e),R&&Xn(e,R),W.success(o==="zh"?`已合并 ${u.length} 个元素`:`Merged ${u.length} elements`)}catch(H){console.error("[PopupToolbar] Failed to merge content:",H),W.error((H==null?void 0:H.message)||(o==="zh"?"合并内容失败":"Failed to merge content"))}},Oe=i.useCallback(async()=>{const u=s[0];if(!(s.length!==1||!U.isDrawElement(u)||!U.isImage(u)||!u.url))try{const y=await na.findImageTaskByResultUrl(u.url);if(!y){W.warning(o==="zh"?"未找到该图片的历史生成任务":"No historical generation task found for this image");return}ci({...fi(y),source:"canvas-toolbar"})}catch(y){console.error("[PopupToolbar] Failed to prefill image generation:",y),W.error(o==="zh"?"回填失败,请稍后重试":"Failed to load generation inputs, please try again")}},[o,s]),xe=i.useCallback(()=>{var ue;const u=s.length===1&&Be(s[0])?s[0]:null;if(!u){a(xn.aiImageGeneration);return}const y=Kt.getRectangleByPoints(u.points),b=u.pptMeta,A=sa(b),H=b?((ue=b.commonPrompt)==null?void 0:ue.trim())||oa(b.styleSpec):"",G=aa(e,u.id),R=ia(e,u.id),I=[];G!=null&&G.url&&I.push({url:G.url,name:`${u.name||"frame"}-reference.png`}),R!=null&&R.url&&R.url!==(G==null?void 0:G.url)&&I.push({url:R.url,name:`${u.name||"frame"}-previous-reference.png`});const O=new Set(I.map(re=>re.url));la(b==null?void 0:b.referenceImages).forEach((re,pe)=>{O.has(re)||(O.add(re),I.push({url:re,name:`${u.name||"frame"}-deck-reference-${pe+1}.png`}))}),a(xn.aiImageGeneration,{initialPrompt:ra(H,A),initialImages:I,initialAspectRatio:mi(y.width,y.height),initialWidth:y.width,initialHeight:y.height,targetFrameId:u.id,targetFrameDimensions:{width:y.width,height:y.height},autoInsertToCanvas:!0,pptSlideImage:!0,pptSlidePrompt:A,pptReplaceElementId:G==null?void 0:G.elementId})},[e,a,s]),Ve=i.useCallback(()=>{const u=s[0];if(s.length!==1||!Bn(u))return;const y=e.children.findIndex(A=>A.id===u.id);if(y<0)return;const b=!u.aiMaskInverted;q.setNode(e,{aiMaskInverted:b||void 0},[y]),W.success(b?o==="zh"?"已开启蒙层反选":"Mask inverted":o==="zh"?"已关闭蒙层反选":"Mask inversion off",1200)},[e,o,s]),Pt=i.useCallback(()=>{if(!_||d)return;const u=Se(e);if(u.length===0){F(void 0);return}const y=st(e,u,!1),[b,A]=Kt.getPoints(y),H=Ln(e,Rn(e,b)),G=Ln(e,Rn(e,A)),R=H[0]+(G[0]-H[0])/2,I=H[1];if(ce.setPositionReference({getBoundingClientRect(){return{width:1,height:1,x:R,y:I,top:I,left:R,right:R+1,bottom:I+1}}}),F({top:H[1],left:H[0],right:G[0],bottom:G[1],width:G[0]-H[0],height:G[1]-H[1]}),L.current){const O=L.current.getBoundingClientRect();he({top:O.top,left:O.left,width:O.width,height:O.height})}},[e,d,_,ce]);return i.useEffect(()=>{if(!_||d)return;let u=!1,y=0,b=null;const A=()=>{u||(Pt(),!(y>=sr)&&(y+=1,b=or(A)))};return A(),()=>{u=!0,b!==null&&ar(b)}},[_,d,K,X,le,ge,Pt]),i.useEffect(()=>{w.current=Q},[Q]),i.useEffect(()=>{if(s.length===0&&!d){const u=setTimeout(()=>{$(!1)},50);return()=>clearTimeout(u)}},[s.length,d]),i.useEffect(()=>{x.current=d},[d]),i.useEffect(()=>{const{pointerUp:u,pointerMove:y}=e;return e.pointerMove=b=>{(On(e)||Un(e))&&!x.current&&m(!0),y(b)},e.pointerUp=b=>{x.current&&(On(e)||Un(e))&&m(!1),u(b)},()=>{e.pointerUp=u,e.pointerMove=y}},[e]),t.jsxs(t.Fragment,{children:[_&&!d&&t.jsx(ze,{padding:1,className:z("popup-toolbar",Ie),ref:u=>{ce.setFloating(u),L.current=u},style:ge,"data-testid":"popup-toolbar",children:t.jsxs(Xt.Row,{gap:1,children:[k.hasFill&&t.jsx(al,{board:e,currentColor:k.fill,title:l("toolbar.fillColor"),children:t.jsx("label",{className:z("fill-label","color-label",{"color-white":k.fill&&Yt(k.fill)&&ps(pt(k.fill)),"color-mixed":k.fill===void 0,"color-gradient":k.fill&&ht(k.fill)&&k.fill.type==="gradient","color-image":k.fill&&ht(k.fill)&&k.fill.type==="image"}),style:k.fill===void 0?void 0:{background:Yt(k.fill)?k.fill:ht(k.fill)?k.fill.type==="gradient"&&k.fill.gradient?ca(k.fill.gradient):k.fill.type==="solid"&&k.fill.solid?k.fill.solid.color:k.fill.type==="image"&&((Ft=k.fill.image)!=null&&Ft.imageUrl)?`url(${k.fill.image.imageUrl}) center/cover no-repeat`:void 0:void 0}})},3),k.hasStroke&&t.jsx(Vi,{board:e,currentColor:k.strokeColor,title:l("toolbar.stroke"),hasStrokeStyle:k.hasStrokeStyle||!1,hasStrokeWidth:k.hasStrokeWidth||!1,currentStrokeWidth:k.strokeWidth,children:t.jsx("label",{className:z("stroke-label","color-label",{"color-mixed":k.strokeColor===void 0}),style:{borderColor:k.strokeColor}})},2),k.hasFontColor&&t.jsx(Wi,{board:e,currentColor:(At=k.marks)==null?void 0:At.color,title:l("toolbar.fontColor"),fontColorIcon:t.jsx(da,{currentColor:(Mt=k.marks)==null?void 0:Mt.color})},0),k.hasFontSize&&t.jsx(Gi,{board:e,currentFontSize:k.fontSize,title:l("toolbar.fontSize")},1),k.hasCornerRadius&&t.jsx(il,{board:e,currentRadius:k.cornerRadius,title:l("toolbar.cornerRadius"),selectionRect:V},"corner-radius"),k.hasText&&t.jsx(cl,{board:e,title:"Link"},4),k.isTextOnly&&t.jsx(xl,{board:e,language:o,title:o==="zh"?"提示词":"Prompts"},"prompt"),k.hasTextToSpeech&&t.jsx(oe,{className:"text-to-speech",type:"icon",icon:Pe&&ie.playing?t.jsx(pa,{size:15}):t.jsx(ma,{size:15}),visible:!0,selected:Pe&&ie.playing,tooltip:Re,"aria-label":Re,"data-track":"toolbar_click_text_to_speech",onPointerUp:()=>{if(!Y.text)return;const u=Ls(Y);if(!u)return;const y=er(e,Y);if(Pe){ie.playing?ie.pausePlayback():ie.resumePlayback();return}$n({source:u,queue:y.length>0?y:[u],queueTab:{queueId:ha,queueName:ua}})}},"text-to-speech"),k.hasText&&t.jsx(oe,{className:"property-settings",type:"icon",icon:t.jsx(fa,{}),visible:!0,selected:Q,tooltip:l("propertyPanel.title"),"aria-label":l("propertyPanel.title"),"data-track":"toolbar_click_property_settings",onPointerUp:()=>{$(!Q)}},"property-settings"),k.hasAlignment&&t.jsx(bl,{board:e,title:l("toolbar.alignment")},"alignment"),k.hasDistribute&&t.jsx(vl,{board:e,title:l("toolbar.distribute")},"distribute"),k.hasBoolean&&t.jsx(wl,{board:e,title:l("toolbar.boolean")},"boolean"),k.hasMindmapToPPT&&t.jsx(oe,{className:"mindmap-to-ppt",type:"icon",icon:t.jsx(ga,{size:15}),visible:!0,tooltip:o==="zh"?"转换为PPT":"Convert to PPT","aria-label":o==="zh"?"转换为PPT":"Convert to PPT","data-track":"toolbar_click_mindmap_to_ppt",onPointerUp:async()=>{const u=Dn(e,s);if(!u)return;const y=W.loading(o==="zh"?"正在转换为PPT...":"Converting to PPT...",0);try{const{generatePPTFromMindmap:b}=await De(async()=>{const{generatePPTFromMindmap:H}=await import("./ai-chat-BnWVpTEI.js").then(G=>G.sQ);return{generatePPTFromMindmap:H}},__vite__mapDeps([0]),import.meta.url),A=await b(e,u);W.close(y),A.success?W.success(o==="zh"?`已生成 ${A.pageCount} 页PPT`:`Generated ${A.pageCount} PPT slides`):W.error(A.error||(o==="zh"?"转换失败":"Conversion failed"))}catch(b){W.close(y),W.error(b.message||(o==="zh"?"转换失败":"Conversion failed"))}}},"mindmap-to-ppt"),k.hasCardEdit&&t.jsx(oe,{className:"card-edit",type:"icon",icon:t.jsx(Wn,{size:15}),visible:!0,tooltip:o==="zh"?"在知识库中编辑":"Edit in Knowledge Base","aria-label":o==="zh"?"在知识库中编辑":"Edit in Knowledge Base","data-track":"toolbar_click_card_edit",onPointerUp:async()=>{const u=s[0];u&&await qa(e,u,o)}},"card-edit"),k.hasCardSave&&t.jsx(oe,{className:"card-save",type:"icon",icon:t.jsx(xa,{size:15}),visible:!0,tooltip:o==="zh"?"保存到知识库":"Save to Knowledge Base","aria-label":o==="zh"?"保存到知识库":"Save to Knowledge Base","data-track":"toolbar_click_card_save",onPointerUp:async()=>{const u=s[0];if(!u)return;await Qa(e,u,o)&&W.success(o==="zh"?"已保存到知识库":"Saved to knowledge base")}},"card-save"),(k.hasCardEdit||k.hasCardSave)&&t.jsx(oe,{className:"card-copy",type:"icon",icon:t.jsx(ya,{size:15}),visible:!0,tooltip:o==="zh"?"复制文本内容":"Copy text content","aria-label":o==="zh"?"复制文本内容":"Copy text content","data-track":"toolbar_click_card_copy",onPointerDown:({event:u})=>{u.stopPropagation()},onPointerUp:async()=>{await Te(s[0])}},"card-copy"),k.hasContentMerge&&t.jsx(oe,{className:"content-merge",type:"icon",icon:t.jsx(Hn,{}),visible:!0,tooltip:o==="zh"?"合并内容":"Merge Content","aria-label":o==="zh"?"合并内容":"Merge Content","data-track":"toolbar_click_content_merge",onPointerUp:()=>{Me()}},"content-merge"),k.hasAIImage&&t.jsx(oe,{className:"ai-image",type:"icon",icon:t.jsx(ba,{}),visible:!0,tooltip:o==="zh"?"AI图片生成":"AI Image Generation","aria-label":o==="zh"?"AI图片生成":"AI Image Generation","data-track":"toolbar_click_ai_image",onPointerUp:xe},5),k.hasAIVideo&&t.jsx(oe,{className:"ai-video",type:"icon",icon:t.jsx(va,{}),visible:!0,tooltip:o==="zh"?"AI视频生成":"AI Video Generation","aria-label":o==="zh"?"AI视频生成":"AI Video Generation","data-track":"toolbar_click_ai_video",onPointerUp:()=>{a(xn.aiVideoGeneration)}},6),k.hasVideoFrame&&t.jsx(oe,{className:"video-frame",type:"icon",icon:t.jsx(wa,{}),visible:!0,tooltip:o==="zh"?"视频帧选择":"Video Frame Selection","aria-label":o==="zh"?"视频帧选择":"Video Frame Selection","data-track":"toolbar_click_video_frame",onPointerUp:()=>{const u=s.find(y=>dt(y));u&&(f(u),p(!0))}},7),k.hasMediaFitPPT&&t.jsx(oe,{className:"media-fit-ppt",type:"icon",icon:t.jsx(ka,{size:15}),visible:!0,tooltip:o==="zh"?"素材自适应PPT":"Fit media to PPT","aria-label":o==="zh"?"素材自适应PPT":"Fit media to PPT","data-track":"toolbar_click_media_fit_ppt",onPointerUp:()=>{(async()=>{const u=s[0];if(!Be(u))return;const y=await Kl(e,u);if(y.fittedCount>0){W.success(o==="zh"?`已自适应 ${y.fittedCount} 个素材`:`Fitted ${y.fittedCount} media item${y.fittedCount>1?"s":""}`);return}W.warning(o==="zh"?"未找到可自适应的PPT素材":"No media item can be fitted to PPT")})()}},"media-fit-ppt"),k.hasSplitImage&&t.jsx(oe,{className:"split-image",type:"icon",icon:t.jsx(Ca,{}),visible:!0,tooltip:o==="zh"?"智能拆图":"Smart Split","aria-label":o==="zh"?"智能拆图":"Smart Split","data-track":"toolbar_click_split_image",onPointerUp:async()=>{const u=s[0];if(U.isImage(u)&&u.url){const y=W.loading(o==="zh"?"正在分析图片...":"Analyzing image...",0);try{const b=st(e,[u],!1),A=await ja(e,u.url,{sourceRect:{x:b.x,y:b.y,width:b.width,height:b.height},scrollToResult:!0});W.close(y),A.success?W.success(o==="zh"?`成功拆分为 ${A.count} 张图片`:`Split into ${A.count} images`):W.warning(A.error||(o==="zh"?"拆图失败":"Split failed"))}catch(b){W.close(y),W.error(b.message||(o==="zh"?"拆图失败":"Split failed"))}}}},"split-image"),k.hasImageEdit&&t.jsx(oe,{className:"image-edit",type:"icon",icon:t.jsx(Wn,{size:15}),visible:!0,tooltip:o==="zh"?"编辑图片":"Edit Image","aria-label":o==="zh"?"编辑图片":"Edit Image","data-track":"toolbar_click_image_edit",onPointerUp:()=>{const u=s[0];U.isImage(u)&&u.url&&(v(u.url),ne(u),S(!0))}},"image-edit"),k.hasMaskInvert&&t.jsx(oe,{className:"mask-invert",type:"icon",icon:t.jsx(Sa,{size:15}),visible:!0,selected:k.maskInverted,tooltip:o==="zh"?"蒙层反选:反向填充图片":"Invert mask: fill the opposite area","aria-label":o==="zh"?"蒙层反选":"Invert mask","data-track":"toolbar_click_mask_invert",onPointerUp:Ve},"mask-invert"),k.hasDownloadable&&t.jsx(oe,{className:"download",type:"icon",icon:t.jsx(Ea,{}),visible:!0,tooltip:o==="zh"?"下载":"Download","aria-label":o==="zh"?"下载":"Download","data-track":"toolbar_click_download",onPointerUp:async()=>{const u=[];for(const A of s)U.isDrawElement(A)&&U.isImage(A)&&A.url?u.push({url:A.url,type:"image"}):dt(A)&&A.url?u.push({url:A.url,type:"video"}):Wt(A)&&A.audioUrl&&u.push({url:A.audioUrl,type:"audio",filename:Na(A.title,"audio","mp3"),audioMetadata:{title:A.title,prompt:A.prompt,tags:A.tags,coverUrl:A.previewImageUrl,artist:A.modelVersion||"Aitu",album:"Aitu Generated"}});if(u.length===0){W.warning(o==="zh"?"没有可下载的内容":"No downloadable content");return}const y=u.length>1?o==="zh"?"正在打包下载...":"Packaging download...":o==="zh"?"正在下载...":"Downloading...",b=W.loading(y,0);try{const{unifiedCacheService:A}=await De(async()=>{const{unifiedCacheService:I}=await import("./ai-chat-BnWVpTEI.js").then(O=>O.sK);return{unifiedCacheService:I}},__vite__mapDeps([0]),import.meta.url),{downloadFromBlob:H}=await De(async()=>{const{downloadFromBlob:I}=await import("./ai-chat-BnWVpTEI.js").then(O=>O.sH);return{downloadFromBlob:I}},__vite__mapDeps([0]),import.meta.url),G=[];for(const I of u)if(I.url.startsWith("blob:")){const O=I.url.indexOf("#"),ue=O>0?I.url.substring(O+1):null;if(ue&&ue.startsWith("merged-video-")){const re=await A.getCachedBlob(ue);if(re){const pe=re.type||"video/webm",be=pe.startsWith("video/mp4")?"mp4":pe.startsWith("video/webm")?"webm":"bin",Ce=`merged-video-${Date.now()}.${be}`;H(re,Ce);continue}else console.warn("[Download] Cache not found for taskId:",ue)}try{const pe=await(await fetch(I.url)).blob(),be=pe.type.startsWith("video/mp4")?"mp4":pe.type.startsWith("video/webm")?"webm":pe.type.startsWith("image/")?"png":"bin",Ce=`${I.type}_${Date.now()}.${be}`;H(pe,Ce)}catch(re){throw console.error("[Download] Failed to fetch blob URL:",re),new Error(`Failed to download ${I.type}: Blob URL inaccessible`)}}else G.push(I);let R;G.length>0&&(R=await _a(G)),W.close(b),R!=null&&R.openedCount&&R.downloadedCount===0?W.success(o==="zh"?R.openedCount>1?`已打开 ${R.openedCount} 个链接,请在新标签页下载`:"资源不支持直接下载,已打开链接":R.openedCount>1?`Opened ${R.openedCount} links for download`:"Opened link for download"):W.success(u.length>1?o==="zh"?`已下载 ${u.length} 个文件`:`Downloaded ${u.length} files`:o==="zh"?"下载成功":"Download complete")}catch(A){W.close(b),W.error(A.message||(o==="zh"?"下载失败":"Download failed"))}}},"download"),k.hasMergeable&&t.jsx(oe,{className:"merge",type:"icon",icon:t.jsx(Hn,{}),visible:!0,tooltip:o==="zh"?"合并为图片":"Merge to Image","aria-label":o==="zh"?"合并为图片":"Merge to Image","data-track":"toolbar_click_merge",onPointerUp:async()=>{const u=Ia("图片合并"),y=W.loading(o==="zh"?"正在合并...":"Merging...",0);try{const b=s.filter(ve=>{const fe=ve.url||ve.imageUrl;if(!fe||fe.startsWith("/")||fe.startsWith("data:")||fe.startsWith("blob:"))return!1;try{return new URL(fe).origin!==location.origin}catch{return!1}});if(b.length>0){const ve=b.map(async He=>{const Xe=He.url||He.imageUrl;try{const wt=new AbortController,Rt=setTimeout(()=>wt.abort(),3e3),Ot=await fetch(Xe,{method:"HEAD",mode:"cors",signal:wt.signal});return clearTimeout(Rt),Ot.ok}catch{return!1}});if((await Promise.all(ve)).some(He=>!He)){W.close(y),W.warning(o==="zh"?"部分外部图片无法访问,请先下载到本地后再合并":"Some external images are inaccessible. Please download them locally first."),u();return}}const A=st(e,s,!1),H=[...s].sort((ve,fe)=>{const We=e.children.findIndex(Xe=>Xe.id===ve.id),He=e.children.findIndex(Xe=>Xe.id===fe.id);return We-He}),G=await za(e,{elements:H,fillStyle:"transparent",inlineStyleClassNames:".extend,.emojis,.text",ratio:2});if(!G)throw new Error(o==="zh"?"合并失败:无法生成图片":"Merge failed: Unable to generate image");const R=new Image;await new Promise((ve,fe)=>{R.onload=()=>ve(),R.onerror=()=>fe(new Error("Failed to load merged image")),R.src=G});const I=document.createElement("canvas");I.width=R.width,I.height=R.height;const O=I.getContext("2d");if(!O)throw new Error("Failed to get canvas context");O.drawImage(R,0,0);const ue=Pa(I),{canvas:re,left:pe,top:be,trimmedWidth:Ce,trimmedHeight:Je}=ue,ft=await new Promise((ve,fe)=>{re.toBlob(We=>{We?ve(We):fe(new Error("Failed to convert canvas to blob"))},"image/png")}),{unifiedCacheService:Dt}=await De(async()=>{const{unifiedCacheService:ve}=await import("./ai-chat-BnWVpTEI.js").then(fe=>fe.sK);return{unifiedCacheService:ve}},__vite__mapDeps([0]),import.meta.url),gt=`merged-image-${Date.now()}`,xt=`/__aitu_cache__/image/${gt}.png`,Qt=xt;await Dt.cacheMediaFromBlob(Qt,ft,"image",{taskId:gt});const Fe=2,Ue=A.x+pe/Fe,Bt=A.y+be/Fe,yt=Ce/Fe,bt=Je/Fe;Gn(e);const Lt=e.children.length,vt={url:xt,width:yt,height:bt};js.insertImage(e,vt,[Ue,Bt]);const $e=e.children[Lt];$e&&(Vn(e),Xn(e,$e)),W.close(y),u(),W.success(o==="zh"?`已将 ${s.length} 个元素合并为图片`:`Merged ${s.length} elements into image`)}catch(b){W.close(y),u(),W.error(b.message||(o==="zh"?"合并失败":"Merge failed"))}}},"merge"),k.hasVideoMergeable&&t.jsx(oe,{className:"video-merge",type:"icon",icon:t.jsx(Ta,{}),visible:!0,tooltip:o==="zh"?"合成视频":"Merge Videos","aria-label":o==="zh"?"合成视频":"Merge Videos","data-track":"toolbar_click_video_merge",onPointerUp:async()=>{const u=[];for(const b of s)dt(b)&&b.url&&u.push(b.url);if(u.length<2){W.warning(o==="zh"?"请选择至少2个视频":"Please select at least 2 videos");return}const y=W.loading(o==="zh"?"正在合成视频...":"Merging videos...",0);try{const b=await pi(u,(A,H)=>{const G={downloading:o==="zh"?"下载视频...":"Downloading videos...",decoding:o==="zh"?"解码视频...":"Decoding videos...",encoding:o==="zh"?"编码视频...":"Encoding videos...",finalizing:o==="zh"?"生成文件中...":"Finalizing..."}});W.close(y);try{const{quickInsert:A}=await De(async()=>{const{quickInsert:H}=await import("./ai-chat-BnWVpTEI.js").then(G=>G.t1);return{quickInsert:H}},__vite__mapDeps([0]),import.meta.url);await A("video",b.url),W.success(o==="zh"?`已合成并插入 ${u.length} 个视频`:`Merged and inserted ${u.length} videos`)}catch(A){console.error("[VideoMerge] Failed to insert video:",A);const H=b.blob.type||"video/webm",G=H.startsWith("video/mp4")?"mp4":"webm",R=new Blob([b.blob],{type:H}),I=URL.createObjectURL(R),O=document.createElement("a");O.href=I,O.download=`merged-video-${Date.now()}.${G}`,document.body.appendChild(O),O.click(),document.body.removeChild(O),setTimeout(()=>URL.revokeObjectURL(I),1e3),W.warning(o==="zh"?`视频已合成,但插入失败,已自动下载 (${G.toUpperCase()})`:`Video merged but failed to insert, downloaded as ${G.toUpperCase()}`)}}catch(b){W.close(y),W.error(b.message||(o==="zh"?"视频合成失败":"Video merge failed"))}}},"video-merge"),t.jsx(yl,{board:e,title:l("textEffect.layer")},"layer-control"),k.hasImage3DTransform&&s.length===1&&t.jsx(Tl,{board:e,element:s[0],language:o,selectionRect:V,title:o==="zh"?"图片 3D 调节":"Image 3D Adjust"},"image-3d-transform"),k.hasSizeInput&&t.jsx(rl,{board:e},"size-input"),k.hasFramePlay&&t.jsx(oe,{className:"frame-play",type:"icon",icon:t.jsx(Yn,{size:15}),visible:!0,tooltip:o==="zh"?"播放幻灯片":"Play Slideshow","aria-label":o==="zh"?"播放幻灯片":"Play Slideshow","data-track":"toolbar_click_frame_play",onPointerUp:()=>{const u=s.find(y=>Be(y));u&&(N(u.id),c(!0))}},"frame-play"),k.hasAudioPlayer&&t.jsx(oe,{className:"audio-player-play",type:"icon",icon:t.jsx(Yn,{size:15}),visible:!0,tooltip:o==="zh"?"在音乐播放器中播放":"Play in Music Player","aria-label":o==="zh"?"在音乐播放器中播放":"Play in Music Player","data-track":"toolbar_click_audio_player_play",onPointerUp:()=>{const u=s.find(y=>Wt(y));!u||!Wt(u)||$n({source:{elementId:u.id,audioUrl:u.audioUrl,title:u.title,duration:u.duration,previewImageUrl:u.previewImageUrl,providerTaskId:u.providerTaskId,clipId:u.clipId,clipIds:u.clipIds},queue:Fa(e.children),queueTab:{queueId:Ma,queueName:Aa}})}},"audio-player-play"),t.jsx(oe,{className:"duplicate",type:"icon",icon:t.jsx(Ba,{}),visible:!0,tooltip:l("general.duplicate"),"aria-label":l("general.duplicate"),"data-track":"toolbar_click_duplicate",onPointerUp:()=>{if(s.length===1&&Be(s[0])){const y=di(e,s[0],o);y&&ui(e,y)}else Da(e)}},8),k.hasRegenerateImage&&t.jsx(oe,{className:"regenerate-image",type:"icon",icon:t.jsx(La,{size:15}),visible:!0,tooltip:o==="zh"?"以当前提示词再次生成":"Generate again with the current prompt","aria-label":o==="zh"?"再次生成":"Generate again","data-track":"toolbar_click_regenerate_image_prefill",onPointerUp:()=>{Oe()}},"regenerate-image"),t.jsx(oe,{className:"trash",type:"icon",icon:t.jsx(Ra,{}),visible:!0,tooltip:l("general.delete"),"aria-label":l("general.delete"),"data-track":"toolbar_click_delete",onPointerUp:()=>{Gn(e)}},9)]})}),h&&j&&t.jsx(Dl,{visible:h,videoUrl:j.url||"",onClose:()=>{p(!1),f(null)},onConfirm:async(u,y)=>{try{j&&await Bl(e,j,u,y)}catch(b){console.error("Failed to insert video frame:",b)}}}),M&&T&&t.jsx(i.Suspense,{fallback:null,children:t.jsx(tr,{visible:M,imageUrl:T,showOverwrite:!!P,onClose:()=>{S(!1),v(""),ne(null)},onOverwrite:async u=>{if(P)try{const{unifiedCacheService:y}=await De(async()=>{const{unifiedCacheService:O}=await import("./ai-chat-BnWVpTEI.js").then(ue=>ue.sK);return{unifiedCacheService:O}},__vite__mapDeps([0]),import.meta.url),b=`edited-image-${Date.now()}`,A=`/__aitu_cache__/image/${b}.png`,G=await(await fetch(u)).blob();await y.cacheMediaFromBlob(A,G,"image",{taskId:b});const R=new Image;await new Promise((O,ue)=>{R.onload=()=>O(),R.onerror=()=>ue(new Error("Failed to load edited image")),R.src=u});const I=e.children.findIndex(O=>O.id===P.id);if(I>=0){const O=e.children[I],{newPoints:ue}=await hi({url:O.url,width:O.width,height:O.height,points:O.points||[[0,0],[0,0]]},R.naturalWidth,R.naturalHeight);q.setNode(e,{url:A,width:R.naturalWidth,height:R.naturalHeight,points:ue},[I])}}catch(y){console.error("Failed to update image:",y),W.error(o==="zh"?"更新失败":"Update failed")}},onInsert:async u=>{try{const{unifiedCacheService:y}=await De(async()=>{const{unifiedCacheService:be}=await import("./ai-chat-BnWVpTEI.js").then(Ce=>Ce.sK);return{unifiedCacheService:be}},__vite__mapDeps([0]),import.meta.url),b=`edited-image-${Date.now()}`,A=`/__aitu_cache__/image/${b}.png`,G=await(await fetch(u)).blob();await y.cacheMediaFromBlob(A,G,"image",{taskId:b});const R=new Image;await new Promise((be,Ce)=>{R.onload=()=>be(),R.onerror=()=>Ce(new Error("Failed to load edited image")),R.src=u});const I=Oa(e),O=P?P.points[1][0]-P.points[0][0]+20:0,ue=P?P.points[0][0]:I?I[0]+100:100,re=P?P.points[0][1]:I?I[1]+100:100,pe=[ue+O,re];await Ua(e,A,pe,!1,{width:R.naturalWidth,height:R.naturalHeight},!1,!0)}catch(y){console.error("Failed to insert image:",y),W.error(o==="zh"?"插入失败":"Insert failed")}}})}),k.hasText&&t.jsx(Cl,{board:e,isOpen:Q,onClose:()=>$(!1),currentFontSize:k.fontSize,currentFontFamily:(lt=k.marks)==null?void 0:lt["font-family"],currentColor:(rt=k.marks)==null?void 0:rt.color,toolbarRect:B,selectionRect:V}),g&&t.jsx(i.Suspense,{fallback:null,children:t.jsx(nr,{visible:g,board:e,onClose:()=>{c(!1),N(void 0)},initialFrameId:C})})]})},Rs=(e,n)=>{const s=Cs(n);return{fill:dn(n),strokeColor:$a(e,n),fontSize:s["font-size"],marks:s}},Os=(e,n)=>{const s=Cs(n);return{fill:dn(n),strokeColor:Wa(e,n),fontSize:s["font-size"],marks:s}},ir=e=>{const n=Se(e);if(n.length===0)return{fill:void 0,strokeColor:void 0};if(n.length===1){const s=n[0];return we(s)?{fill:s.fillColor,strokeColor:void 0}:Le.isMindElement(e,s)?Rs(e,s):at.isFreehand(s)?Us(e,s):Ke.isPenPath(s)?$s(e,s):Os(e,s)}return lr(e,n)},lr=(e,n)=>{const s=n.map(m=>we(m)?{fill:m.fillColor,strokeColor:void 0}:Le.isMindElement(e,m)?Rs(e,m):at.isFreehand(m)?Us(e,m):Ke.isPenPath(m)?$s(e,m):U.isDrawElement(m)?Os(e,m):{fill:void 0,strokeColor:void 0}),a=s.map(m=>m.fill),o=s.map(m=>m.strokeColor),l=a.every(m=>m===a[0]),d=o.every(m=>m===o[0]);return{fill:l?a[0]:void 0,strokeColor:d?o[0]:void 0}},Us=(e,n)=>({fill:dn(n),strokeColor:Ha(e,n)}),$s=(e,n)=>({fill:dn(n),strokeColor:n.strokeColor,cornerRadius:n.cornerRadius}),rr=(e,n)=>we(n)||Le.isMindElement(e,n)||Ga(e,n)?!0:at.isFreehand(n)?Va(n.points):Ke.isPenPath(n)?n.closed:U.isDrawElement(n)?U.isShapeElement(n)&&!U.isImage(n)&&!U.isText(n)&&Ss(n):!1,Ws=(e,n)=>Le.isMindElement(e,n)||at.isFreehand(n)||Ke.isPenPath(n)?!0:U.isDrawElement(n)?U.isShapeElement(n)&&!U.isImage(n)&&!U.isText(n)||U.isArrowLine(n)||U.isVectorLine(n)||U.isTable(n):!1,cr=(e,n)=>Ws(e,n),dr=(e,n)=>Le.isMindElement(e,n)?!0:U.isDrawElement(n)?Pn([n]):!1,wr=e=>e===Xa?null:e,ur=(e,n)=>{if(Ke.isPenPath(n))return n.closed;if(at.isFreehand(n)){const s=n.points;if(!s||s.length<3)return!1;const a=s[0],o=s[s.length-1];return Math.hypot(o[0]-a[0],o[1]-a[1])<=10}return U.isDrawElement(n)?U.isImage(n)||U.isText(n)||U.isArrowLine(n)||U.isVectorLine(n)?!1:U.isShapeElement(n)&&Ss(n):(Le.isMindElement(e,n),!1)};export{vr as PopupToolbar,wr as getColorPropertyValue,Os as getDrawElementState,ir as getElementState,Us as getFreehandElementState,Rs as getMindElementState,$s as getPenPathElementState,rr as hasFillProperty,Ws as hasStrokeProperty,cr as hasStrokeStyleProperty,dr as hasTextProperty,ur as supportsBooleanOperation};