clipoox-render 0.4.3 → 0.4.5

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 (191) hide show
  1. package/package.json +4 -3
  2. package/scripts/render-local.mjs +5160 -1446
  3. package/web/assets/FxEmbed-DbfuM8Yo.js +1 -0
  4. package/web/assets/MotionEmbed-CBQ-8Tzh.js +1 -0
  5. package/web/assets/PluginStore-OOEx0lP5.js +3 -0
  6. package/web/assets/ShotComposer-Cng515xa.js +287 -0
  7. package/web/assets/{ShotComposer-VixLbeMe.css → ShotComposer-deLi4grZ.css} +1 -1
  8. package/web/assets/TemplateEmbed-hjwM2b0o.js +2 -0
  9. package/web/assets/{TimelinePlugins-BYZ9y4m3.js → TimelinePlugins-D-NakABP.js} +4 -4
  10. package/web/assets/TimelineShotFx-D3kGhHN3.js +2 -0
  11. package/web/assets/TransitionEmbed-DR26yI3a.js +1 -0
  12. package/web/assets/{Whiteboard-BP_DvIAV.js → Whiteboard-BhxY0D0Z.js} +3 -3
  13. package/web/assets/aerial-BisYSXzG.js +2 -0
  14. package/web/assets/agentTools-CPFQeiDP.js +2 -0
  15. package/web/assets/aiInbetween-AOOM1e6p.js +2 -0
  16. package/web/assets/analyzerRun-Dtp2o7gT.js +1 -0
  17. package/web/assets/analyzerSandbox-BG_3Cea1.js +33 -0
  18. package/web/assets/api-BFN7blbw.js +3158 -0
  19. package/web/assets/auraTrack-D_gxHNVe.js +1 -0
  20. package/web/assets/breakthrough-0qFpZW-V.js +2 -0
  21. package/web/assets/{cameraPresets-CYw0OdM3.js → cameraPresets-eK3mP7qb.js} +1 -1
  22. package/web/assets/cameraTracker-BAQHuTV-.js +72 -0
  23. package/web/assets/captionLayout-CWPcbid-.js +1 -0
  24. package/web/assets/clientExport-DvpTTndR.js +1 -0
  25. package/web/assets/clientJobs-CIrYTMpn.js +2 -0
  26. package/web/assets/clientJobs-CuuUyhEy.js +1 -0
  27. package/web/assets/cutoutClean-CLYYAuXg.js +1 -0
  28. package/web/assets/depthEstimate-B7D7cGCl.js +1 -0
  29. package/web/assets/directorTools-CJD4Huqk.js +1 -0
  30. package/web/assets/distortFrames-BLt1icUb.js +2 -0
  31. package/web/assets/{distortGL-QalhICvi.js → distortGL-BA5molk-.js} +3 -3
  32. package/web/assets/draco_decoder-C32yEggz.wasm +0 -0
  33. package/web/assets/draco_decoder-Z1_iN-Ht.wasm +0 -0
  34. package/web/assets/draco_decoder-fzg4nYZr.js +34 -0
  35. package/web/assets/draco_wasm_wrapper-DxJM36Ib.js +117 -0
  36. package/web/assets/draco_wasm_wrapper-fZCQGLGb.js +116 -0
  37. package/web/assets/editTools-NKLsWZD1.js +1 -0
  38. package/web/assets/{engine-BedcnK45.js → engine-DioUF2mX.js} +1 -1
  39. package/web/assets/exportGlb-BOdI9cVS.js +2 -0
  40. package/web/assets/faceTracker-D7CbF-qX.js +1 -0
  41. package/web/assets/fightDirector-CYP8jxo8.js +1 -0
  42. package/web/assets/fightDrama-DIPcRKnc.js +2 -0
  43. package/web/assets/focusTool-vfabPqQ5.js +1 -0
  44. package/web/assets/{frameSink-DeM8xC8_.js → frameSink-DYs2gTzq.js} +3 -3
  45. package/web/assets/glTransitionSources.generated-DM5sRMX2.js +3695 -0
  46. package/web/assets/gltfLoader-U0Eebg7v.js +2 -0
  47. package/web/assets/{gpuCompose-CA3UmOl4.js → gpuCompose-DbnZuelB.js} +1 -1
  48. package/web/assets/gpuExport-CQ7ZhpsX.js +198 -0
  49. package/web/assets/handMatte-DIbMuqCu.js +1 -0
  50. package/web/assets/handTracker-DY_g5Xmg.js +2 -0
  51. package/web/assets/i18n-BJppIrtF.js +3 -0
  52. package/web/assets/index-BfrDwjDI.js +4247 -0
  53. package/web/assets/index-CKtv7gGE.js +9 -0
  54. package/web/assets/{index-D5oyVCRl.js → index-DxdDhmLR.js} +2 -2
  55. package/web/assets/layer-worker-DK67WH1a.js +5 -0
  56. package/web/assets/library-B6KsZUKq.js +1 -0
  57. package/web/assets/lottieLayer-C2YbiXhK.js +161 -0
  58. package/web/assets/{lottie_light_canvas-B-d7-ATe.js → lottie_light_canvas-DX9Wf-DS.js} +1 -1
  59. package/web/assets/main-B27kf5aL.css +1 -0
  60. package/web/assets/main-BKatDoGw.js +309 -0
  61. package/web/assets/mapBake-C-G7WpFM.js +1 -0
  62. package/web/assets/maskTrack-LMrwm5ub.js +1 -0
  63. package/web/assets/matteFixRun-B38CbeEt.js +1 -0
  64. package/web/assets/matteQuality-9X-jgJrH.js +1 -0
  65. package/web/assets/objectLocate-CKi3OTnL.js +1 -0
  66. package/web/assets/objectSegmenter-CziPuM61.js +1 -0
  67. package/web/assets/{objectTrack.worker-BlZkgpOX.js → objectTrack.worker-b7DJ-ub6.js} +196 -196
  68. package/web/assets/pathTracer-bqau16sX.js +2 -0
  69. package/web/assets/pendingMatte-CQb7jPg1.js +2 -0
  70. package/web/assets/personAi-CQntGDqK.js +2 -0
  71. package/web/assets/personHq-B1c0QVJT.js +2 -0
  72. package/web/assets/plateCamera-D7iLiNBy.js +1 -0
  73. package/web/assets/plateCameraMatch-BM88dx-a.js +2 -0
  74. package/web/assets/plateFollow-4iGUDTu1.js +2 -0
  75. package/web/assets/plateMatte-zTyuHHqh.js +2 -0
  76. package/web/assets/plugin-guide.en-DO_fHbzT.js +1 -0
  77. package/web/assets/plugin-guide.vi-CMJDxOhi.js +1 -0
  78. package/web/assets/pluginAutomation-DSg-sYLF.js +1 -0
  79. package/web/assets/poseTracker-DZl8l2qS.js +1 -0
  80. package/web/assets/productTools-B-jh8ukh.js +2 -0
  81. package/web/assets/remote-DJd9xWjn.js +963 -0
  82. package/web/assets/{rigTrack-urT3nDK0.js → rigTrack-XaMj1yaH.js} +1 -1
  83. package/web/assets/rotoMaskStore-DdpmT9C3.js +1 -0
  84. package/web/assets/{rotoMatte-C-2o3vv0.js → rotoMatte-i-cJTYmK.js} +1 -1
  85. package/web/assets/rotoscope-DqRSWmHR.js +1 -0
  86. package/web/assets/sceneTrack-Bbov7zET.js +1 -0
  87. package/web/assets/sceneTrack-DIPzBmMK.js +1 -0
  88. package/web/assets/{sceneTrack.worker-CT4uoTKn.js → sceneTrack.worker-Bav9h0pv.js} +180 -180
  89. package/web/assets/shot-worker-m-q77W9f.js +1 -0
  90. package/web/assets/{shotFxAgent-BFLkqs8v.js → shotFxAgent-DIMS7BGA.js} +2 -2
  91. package/web/assets/{skin-DY4QLaBI.js → skin-DrUzJE1u.js} +1 -1
  92. package/web/assets/{spark.module-DzziUgOj.js → spark.module-Y1SEI8Xz.js} +10 -10
  93. package/web/assets/spellDuel-DNnyQDVr.js +2 -0
  94. package/web/assets/store-GFMJzaWS.js +1 -0
  95. package/web/assets/surfaceLight-C--moyc9.js +1 -0
  96. package/web/assets/surfacePin-B4-1UqXD.js +2 -0
  97. package/web/assets/{textAnimators-DUZjhVGO.js → textAnimators-BVXTl8bU.js} +1 -1
  98. package/web/assets/{thumb-CS0ZuiGS.js → thumb-CTfDJgLp.js} +1 -1
  99. package/web/assets/timeline3d-Dn7PqmEe.js +2 -0
  100. package/web/assets/timeline3dExport-DCOr6ARB.js +1 -0
  101. package/web/assets/timelineComp-Dx_kED5V.js +1 -0
  102. package/web/assets/timelineOps-afzSo188.js +525 -0
  103. package/web/assets/timelineProps-eYgO6gs5.js +1 -0
  104. package/web/assets/timelineText-RKyRP988.js +1 -0
  105. package/web/assets/{titleArt-Drsrtfiv.js → titleArt-CUtA0C3I.js} +4 -4
  106. package/web/assets/{titleFrameBudget-CLZWaFHO.js → titleFrameBudget-X7HLSDre.js} +721 -704
  107. package/web/assets/titleFrames-aMG7HdVe.js +1 -0
  108. package/web/assets/{tool-DktQYmS6.js → tool-DpFjybaq.js} +1 -1
  109. package/web/assets/{tools-Co9aRDiT.js → tools-CeOU0p13.js} +1 -1
  110. package/web/assets/toonTools-DLmo37Z_.js +2 -0
  111. package/web/assets/trackAnchor-hAOtEhKO.js +1 -0
  112. package/web/assets/userFonts-1kuRjWOo.js +1 -0
  113. package/web/assets/{vfxAlpha-71tSN86T.js → vfxAlpha-DxS5-QwY.js} +2 -2
  114. package/web/assets/vfxBackground-CYpaQaTa.js +2 -0
  115. package/web/assets/videoExport-Cg4B2Nyh.js +1 -0
  116. package/web/assets/views-CUXyRb9x.js +1 -0
  117. package/web/assets/weaponDuel-nFECu9nk.js +1 -0
  118. package/web/assets/windowFrames-1wAkkWnv.js +1 -0
  119. package/web/layer-worker.html +3 -3
  120. package/web/shot-worker.html +41 -0
  121. package/web/assets/FxEmbed-BCmj9Q5C.js +0 -1
  122. package/web/assets/GLTFLoader-BHWu1lKg.js +0 -1
  123. package/web/assets/MotionEmbed-CEmbcq8Z.js +0 -1
  124. package/web/assets/PluginStore-C5hyahvG.js +0 -3
  125. package/web/assets/ShotComposer-0DUtMTVI.js +0 -287
  126. package/web/assets/TemplateEmbed-ANxSs7H5.js +0 -2
  127. package/web/assets/TimelineShotFx-q5PQwq-V.js +0 -2
  128. package/web/assets/TransitionEmbed-O6LInGWq.js +0 -1
  129. package/web/assets/aerial-CGLDKKtP.js +0 -2
  130. package/web/assets/agentTools-2Ghb80VH.js +0 -2
  131. package/web/assets/analyzerRun-DRgxrcJA.js +0 -1
  132. package/web/assets/analyzerSandbox-DuIVFnsk.js +0 -33
  133. package/web/assets/api-CJ8PdbfZ.js +0 -3168
  134. package/web/assets/auraTrack-DQw9sVU6.js +0 -1
  135. package/web/assets/breakthrough-BNj_iTDr.js +0 -2
  136. package/web/assets/captionLayout-DvDPTwO9.js +0 -1
  137. package/web/assets/clientExport-xhoXY6Dh.js +0 -1
  138. package/web/assets/depthEstimate-DEpeCojm.js +0 -1
  139. package/web/assets/directorTools-C5CpTmci.js +0 -1
  140. package/web/assets/distortFrames-Dia8O1NM.js +0 -2
  141. package/web/assets/editTools-CY_JrQfw.js +0 -1
  142. package/web/assets/exportEncode-QYsT9JBO.js +0 -1
  143. package/web/assets/exportGlb-TSj09XoV.js +0 -2
  144. package/web/assets/faceTracker-CnCWOwnJ.js +0 -1
  145. package/web/assets/fightDirector-DCI_FWTh.js +0 -1
  146. package/web/assets/fightDrama-Bg7uP_2Q.js +0 -2
  147. package/web/assets/gpuExport-D31azOQA.js +0 -198
  148. package/web/assets/handMatte-Dl-xVXFR.js +0 -1
  149. package/web/assets/handTracker-CplBsAFg.js +0 -2
  150. package/web/assets/layer-worker-DFuo32bk.js +0 -5
  151. package/web/assets/library-BufgA-Pl.js +0 -1
  152. package/web/assets/lottieLayer-DzbA3bHV.js +0 -158
  153. package/web/assets/main-Ca_CVxMz.css +0 -1
  154. package/web/assets/main-VVYiW8XD.js +0 -309
  155. package/web/assets/mapBake-BKOcEd0w.js +0 -1
  156. package/web/assets/maskTrack-CHGXtBRy.js +0 -1
  157. package/web/assets/matteFixRun-vgYrINet.js +0 -1
  158. package/web/assets/objectLocate-BJltm8Ob.js +0 -1
  159. package/web/assets/pendingMatte-BPyzzx4y.js +0 -2
  160. package/web/assets/personAi-gJu03SjU.js +0 -2
  161. package/web/assets/plateCamera-B2JvhjJw.js +0 -1
  162. package/web/assets/plateCameraMatch-ByB9nVQT.js +0 -2
  163. package/web/assets/plateFollow-C9S-l7RH.js +0 -2
  164. package/web/assets/plateMatte-J4qlNHnY.js +0 -2
  165. package/web/assets/plugin-guide.en-CGYh_9Su.js +0 -1
  166. package/web/assets/plugin-guide.vi-DMphSELb.js +0 -1
  167. package/web/assets/pluginAutomation-CkP3tA9r.js +0 -1
  168. package/web/assets/poseTracker-DGLbouqt.js +0 -1
  169. package/web/assets/productTools-CkaWF1bM.js +0 -2
  170. package/web/assets/remote-C7J0Tqhb.js +0 -1433
  171. package/web/assets/rotoMaskStore-DPziPKAN.js +0 -1
  172. package/web/assets/rotoscope-GvPFRUBg.js +0 -1
  173. package/web/assets/shot-worker-6dYkHPoL.js +0 -1
  174. package/web/assets/spellDuel-BD3m2ebA.js +0 -2
  175. package/web/assets/store-DW4E9xnW.js +0 -1
  176. package/web/assets/surfaceLight-aDSYU8Jg.js +0 -1
  177. package/web/assets/surfacePin-m83hCgGP.js +0 -2
  178. package/web/assets/timeline3d-DOw-CpZI.js +0 -2
  179. package/web/assets/timeline3dExport-BtYLU1pw.js +0 -1
  180. package/web/assets/timelineComp-B4GtoH2f.js +0 -1
  181. package/web/assets/timelineProps-D7MVutxu.js +0 -1
  182. package/web/assets/timelineText-BH09jfSM.js +0 -1
  183. package/web/assets/titleFrames-BI1DnLBn.js +0 -1
  184. package/web/assets/toonTools-CD9clJvN.js +0 -2
  185. package/web/assets/trackAnchor-sOjTtd3I.js +0 -1
  186. package/web/assets/userFonts-CwlKh9NR.js +0 -1
  187. package/web/assets/vfxBackground-Bq7lJvmZ.js +0 -2
  188. package/web/assets/videoExport-D4KbireJ.js +0 -1
  189. package/web/assets/views-ozVF4ABO.js +0 -1
  190. package/web/assets/weaponDuel-ZhX-tjGZ.js +0 -1
  191. package/web/assets/windowFrames-CpqX3kOM.js +0 -1
@@ -1 +0,0 @@
1
- import{_ as Vo,g0 as Ct,ed as no,ee as vt,cd as Gt,kh as ko,ec as wt,d7 as yt,fw as it,fn as Bo,g1 as yo,fP as Uo,iM as Go,au as Et,F as ut,c0 as Jo,jf as go,mS as bo,mT as Qo,ij as so,ii as ro,jh as Zo,fr as Ho,jj as xo,mU as wo,mV as Wo,mW as ao,mX as te,mY as oe,ji as Jt,jk as ee,cC as vo,dD as Yt,kj as ne,mZ as se}from"./titleFrameBudget-CLZWaFHO.js";import{bW as re,bX as ae}from"./api-CJ8PdbfZ.js";const qt=.1,Kt=t=>Math.abs(t)>180?(t%360+540)%360-180:t;function Eo(t,o,s,n,e,a,r,l,i){const c=l-r,f=t==null?s-o:(s-t)/Math.max(1e-9,l-a)*c,h=n==null?s-o:(n-o)/Math.max(1e-9,i-r)*c,p=e*e,u=p*e;return(2*u-3*p+1)*o+(u-2*p+e)*f+(-2*u+3*p)*s+(u-p)*h}function Ao(t,o,s,n,e,a,r,l,i){const c=o+Kt(s-o),f=t==null?null:o+Kt(t-o),h=n==null?null:c+Kt(n-c);return Eo(f,o,c,h,e,a,r,l,i)}function ie(t,o,s=n=>n.time){if(globalThis.__clipooxLinearKeys)return!1;const n=(e,a)=>s(t[a])-s(t[e]);return!(n(o,o+1)>qt||o>0&&n(o-1,o)>qt||o+2<t.length&&n(o+1,o+2)>qt)}function Qt(t,o,s,n){let e=o>0,a=o+2<t.length;if(n!=null){const l=e?s(t[o-1]):null,i=s(t[o]),c=s(t[o+1]),f=a?s(t[o+2]):null;if(i<n-1e-9&&c>=n-1e-9)return{before:!1,after:!1};a&&c<n-1e-9&&f>=n-1e-9&&(a=!1),e&&i>=n-1e-9&&l<n-1e-9&&(e=!1)}return{before:e,after:a}}function Be(t,o,s,n=r=>r.pose,e=r=>r.time,a=null){const r=Qt(t,o,e,a),l=n(t[o]),i=n(t[o+1]),c=r.before?n(t[o-1]):null,f=r.after?n(t[o+2]):null,h=e(t[o]),p=e(t[o+1]),u=c?e(t[o-1]):h-(p-h),m=f?e(t[o+2]):p+(p-h),y={};for(const M of new Set([...Object.keys(l),...Object.keys(i)])){const d=l[M]??0,x=i[M]??0;if(typeof d!="number"||typeof x!="number")continue;const g=c&&typeof c[M]=="number"?c[M]:null,w=f&&typeof f[M]=="number"?f[M]:null;y[M]=Ao(g,d,x,w,s,u,h,p,m)}return y}function le(t,o,s,n=r=>r.position,e=r=>r.time,a=null){const r=Qt(t,o,e,a),l=n(t[o]),i=n(t[o+1]),c=r.before?n(t[o-1]):null,f=r.after?n(t[o+2]):null,h=e(t[o]),p=e(t[o+1]),u=c?e(t[o-1]):h-(p-h),m=f?e(t[o+2]):p+(p-h);return l.map((y,M)=>Eo(c?c[M]:null,y,i[M],f?f[M]:null,s,u,h,p,m))}function ce(t,o,s,n,e=r=>r.time,a=null){const r=Qt(t,o,e,a),l=n(t[o]),i=n(t[o+1]),c=r.before?n(t[o-1]):null,f=r.after?n(t[o+2]):null,h=e(t[o]),p=e(t[o+1]),u=c!=null?e(t[o-1]):h-(p-h),m=f!=null?e(t[o+2]):p+(p-h);return Ao(c,l,i,f,s,u,h,p,m)}const At=30,io=4,bt=Object.freeze({min:.25,max:6,default:3}),Rt=40,Po=300,Co=Object.freeze({position:.01,rotation:2}),So=80,To=Object.freeze(["here","above","explode","throw"]),$t=Object.freeze({bouncy:Object.freeze({restitution:.6,friction:.45}),normal:Object.freeze({restitution:.25,friction:.6}),heavy:Object.freeze({restitution:.04,friction:.9})}),fe=9.81;let Xt=null,Ro=null;const Io=()=>Ro;function jo(){return Xt??=(async()=>{const t=await Vo(()=>import("./rapier-DBjBuyhF.js"),[]),o=t.default??t,s=console.warn;console.warn=(...n)=>{String(n[0]).includes("deprecated parameters")||s(...n)};try{await o.init()}finally{console.warn=s}return Ro=o,o})().catch(t=>{throw Xt=null,t}),Xt}const ot=t=>typeof t=="number"&&Number.isFinite(t),Y=(t,o)=>Array.isArray(t)&&t.length===3&&t.every(ot)?[t[0],t[1],t[2]]:o,Q=Math.PI/180,St=t=>(t%360+540)%360-180,Tt=t=>Math.round(t*1e4)/1e4,Vt=t=>Math.round(t*100)/100;function Pt(t){const o=Math.cos(t[0]*Q/2),s=Math.cos(t[1]*Q/2),n=Math.cos(t[2]*Q/2),e=Math.sin(t[0]*Q/2),a=Math.sin(t[1]*Q/2),r=Math.sin(t[2]*Q/2);return[e*s*n+o*a*r,o*a*n-e*s*r,o*s*r+e*a*n,o*s*n-e*a*r]}function _o(t){const[o,s,n,e]=t,a=1-2*(s*s+n*n),r=2*(o*s-n*e),l=2*(o*n+s*e),i=1-2*(o*o+n*n),c=2*(s*n-o*e),f=2*(s*n+o*e),h=1-2*(o*o+s*s),p=Math.asin(Math.max(-1,Math.min(1,l)));return Math.abs(l)<.9999999?[Math.atan2(-c,h)/Q,p/Q,Math.atan2(-r,a)/Q]:[Math.atan2(f,i)/Q,p/Q,0]}const lo=(t,o)=>{const[s,n,e,a]=t,r=a*o[0]+n*o[2]-e*o[1],l=a*o[1]+e*o[0]-s*o[2],i=a*o[2]+s*o[1]-n*o[0],c=-s*o[0]-n*o[1]-e*o[2];return[r*a+c*-s+l*-e-i*-n,l*a+c*-n+i*-s-r*-e,i*a+c*-e+r*-n-l*-s]},Do=(t,o)=>2*Math.acos(Math.min(1,Math.abs(t[0]*o[0]+t[1]*o[1]+t[2]*o[2]+t[3]*o[3])))/Q;function Fo(t){let o=2166136261;for(const n of String(t))o=Math.imul(o^n.codePointAt(0),16777619);let s=o>>>0;return()=>{s=s+1831565813|0;let n=Math.imul(s^s>>>15,1|s);return n=n+Math.imul(n^n>>>7,61|n)^n,((n^n>>>14)>>>0)/4294967296}}const co=new Set(["box","sphere","cylinder","wall","platform"]),he=new Set(["person","fx","splat","set","floor"]);function ue(t){return t?t.locked?"Đối tượng đang khoá":t.hold?"Đồ đang cầm đi theo tay người cầm":t.kind==="person"||t.kind==="model"&&(t.skeleton==="native"||t.rig?.kind==="humanoid")?"Nhân vật không rơi như vật thể — dùng chuyển động":he.has(t.kind)?"Loại đối tượng này không rơi được":null:"Chưa chọn đối tượng"}function pe(t){const o=Y(t.scale,[1,1,1]);return t.kind==="sphere"&&Math.abs(o[0]-o[1])<1e-6&&Math.abs(o[1]-o[2])<1e-6||t.kind==="prop"&&t.prop?.kind==="ball"?"ball":t.kind==="cylinder"&&Math.abs(o[0]-o[2])<1e-6?"cylinder":"box"}function me(t){const o=Y(t.scale,[1,1,1]).map(Math.abs),s=Y(t.mirror,[1,1,1]),n=Y(t.origin,[0,0,0]);let e=[1,1,1],a=[0,.5,0];if(t.kind==="proxy"&&t.proxy?.dims)e=Y(t.proxy.dims,e),a=[0,e[1]/2,0];else if(t.kind==="prop"){const i=t.prop?.kind==="ball"?.12:.15;e=[2*i,2*i,2*i],a=[0,t.prop?.kind==="ball"?0:i,0]}else if(t.kind==="model"){const i=t.model?.height??2;e=[i*.6,i,i*.6],a=[0,i/2,0]}else co.has(t.kind)||(e=[.5,.5,.5],a=[0,.25,0]);const r=co.has(t.kind)?[(a[0]-n[0])*s[0],(a[1]-n[1])*s[1],(a[2]-n[2])*s[2]]:a,l=i=>[i[0]*(t.scale?.[0]??1),i[1]*(t.scale?.[1]??1),i[2]*(t.scale?.[2]??1)];return{half:[e[0]*o[0]/2,e[1]*o[1]/2,e[2]*o[2]/2],offset:l(r)}}function de(t,o){let s=0,n=t.length-1;for(;n-s>1;){const e=s+n>>1;t[e].time<=o?s=e:n=e}return s}function zo(t,o,s=null,n=null){const e=t[0],a=t[t.length-1];if(o<=e.time)return{position:e.position,rotation:e.rotation};if(o>=a.time)return{position:a.position,rotation:a.rotation};const r=de(t,o),l=t[r],i=t[r+1],c=(o-l.time)/(i.time-l.time),f=h=>l.rotation[h]+St(i.rotation[h]-l.rotation[h])*c;return ie(t,r,n>0?h=>h.time*n:void 0)?{position:le(t,r,c,h=>h.position,h=>h.time,s),rotation:[f(0),ce(t,r,c,h=>h.rotation[1],h=>h.time,s),f(2)]}:{position:[0,1,2].map(h=>l.position[h]+(i.position[h]-l.position[h])*c),rotation:[f(0),f(1),f(2)]}}function qo(t,{tolerance:o=Co,maxKeys:s=So,before:n=null,seam:e=null,duration:a=null}={}){const r=t.length;if(r<=2)return{keys:t.map(({time:f,position:h,rotation:p})=>({time:f,position:h,rotation:p})),error:{position:0,rotation:0}};const l=new Set([0,r-1]),i=()=>[...l].sort((f,h)=>f-h).map(f=>t[f]);let c={position:0,rotation:0};for(;;){const f=i(),h=n?[n,...f]:f;let p=-1,u=1;c={position:0,rotation:0};for(let m=1;m<r-1;m++){if(l.has(m))continue;const y=t[m],M=zo(h,y.time,e,a),d=Math.hypot(M.position[0]-y.position[0],M.position[1]-y.position[1],M.position[2]-y.position[2]),x=Do(Pt(M.rotation),y.quat);c={position:Math.max(c.position,d),rotation:Math.max(c.rotation,x)};const g=Math.max(d/o.position,x/o.rotation);g>u&&(u=g,p=m)}if(p<0||l.size>=s)break;l.add(p)}return{keys:i().map(({time:f,position:h,rotation:p})=>({time:f,position:h,rotation:p})),error:{position:Tt(c.position),rotation:Vt(c.rotation)}}}const Me=t=>ot(t)?{restitution:Math.max(0,Math.min(.95,t)),friction:.6}:$t[t]??$t.normal;async function ye(t){const o=Zt(await jo(),t),{duration:s,mode:n}=o,e=ot(t.start)?Math.max(0,t.start):0,a=ot(t.shotDuration)&&t.shotDuration>0?t.shotDuration:e+s,r={},l=e/a;for(const i of o.bodies){let c=null;const f=i.samples.map(m=>{let y=_o(m.q);if(c){const M=[y[0]+180,180-y[1],y[2]+180],d=x=>x.reduce((g,w,b)=>g+Math.abs(St(w-c[b])),0);d(M)<d(y)&&(y=M)}return y=y.map(M=>Vt(St(M)===-180?180:St(M))),c=y,{time:l+m.sec/a,position:m.pivot.map(Tt),rotation:y,quat:Pt(y)}}),h=t.before?.[i.id],{keys:p,error:u}=qo(f,{before:h&&ot(h.time)&&h.time<l?h:null,seam:ot(t.seam)?t.seam:null,duration:a});r[i.id]={keys:p,error:u,settledAt:i.settledAt,from:{position:i.position.map(Tt),rotation:i.rotation.map(Vt)},rest:f[f.length-1].position,restCentre:i.samples[i.samples.length-1].centre.map(Tt),restQuat:i.samples[i.samples.length-1].q}}return{tracks:r,settled:o.settled,seconds:s,mode:n}}function Zt(t,o){const s=!!o.planar,n=To.includes(o.mode)?o.mode:"here",e=Math.max(bt.min,Math.min(bt.max,ot(o.duration)?o.duration:bt.default)),a=ot(o.floor)?o.floor:0,r=Me(o.bounciness),l=Fo(`${o.seed??"drop"}|${n}`),i=m=>(l()*2-1)*m,c=(o.bodies||[]).filter(m=>m&&m.id!=null).map(m=>({id:String(m.id),shape:["ball","cylinder"].includes(m.shape)?m.shape:"box",position:Y(m.position,[0,0,0]),rotation:Y(m.rotation,[0,0,0]),half:Y(m.half,[.25,.25,.25]).map(y=>Math.max(.01,Math.abs(y))),offset:Y(m.offset,[0,0,0])})).sort((m,y)=>m.id<y.id?-1:m.id>y.id?1:0).slice(0,Rt);if(!c.length)throw new Error("no objects to drop");const f=m=>Math.hypot(...m.half);for(const m of c){m.q=Pt(m.rotation);const y=lo(m.q,m.offset);m.c=[m.position[0]+y[0],m.position[1]+y[1],m.position[2]+y[2]],m.v=[0,0,0],m.w=[0,0,0]}if(n==="above"){const m=ot(o.height)?Math.max(.3,Math.min(20,o.height)):2,y=Math.max(...c.map(d=>d.c[1]+f(d))),M=[];for(const d of[...c].sort((x,g)=>x.c[1]-g.c[1]||(x.id<g.id?-1:1))){d.q=Pt(s?[d.rotation[0],d.rotation[1],d.rotation[2]+i(35)]:[d.rotation[0]+i(35),d.rotation[1]+i(180),d.rotation[2]+i(35)]);let x=y+m+f(d);for(const g of M)Math.hypot(g.c[0]-d.c[0],g.c[2]-d.c[2])<f(g)+f(d)&&(x=Math.max(x,g.c[1]+f(g)+f(d)+.05));d.c=s?[d.c[0],x,d.c[2]]:[d.c[0]+i(.05),x,d.c[2]+i(.05)],M.push(d)}}if(n==="here")for(const m of c)m.w=[i(1.2),i(1.2),i(1.2)];const h=m=>s?[0,0,m[2]]:m,p=m=>s?[m[0],m[1],0]:m;if(n==="explode"){const m=Y(o.center,[0,1,2].map(M=>c.reduce((d,x)=>d+x.c[M],0)/c.length)),y=ot(o.strength)?Math.max(.5,Math.min(20,o.strength)):4;for(const M of c){let d=M.c[0]-m[0],x=s?0:M.c[2]-m[2],g=Math.hypot(d,x);if(g<.001){const b=l()*Math.PI*2;d=Math.cos(b),x=s?0:Math.sin(b),g=Math.hypot(d,x)||1}const w=y*(.75+l()*.5);M.v=[d/g*w,w*(.6+l()*.4),x/g*w],M.w=[i(7),i(7),i(7)]}}if(n==="throw"){const m=Y(o.velocity,[0,2,3]);for(const y of c)y.v=m.map(M=>M*(1+i(.08))),y.w=[i(5),i(5),i(5)]}const u=new t.World({x:0,y:-(ot(o.gravity)?o.gravity:fe),z:0});try{u.timestep=1/(At*io);for(const g of c)g.v=p(g.v),g.w=h(g.w);const m=(g,w)=>{const b=u.createRigidBody(t.RigidBodyDesc.fixed().setTranslation(g[0],g[1],g[2]));u.createCollider(t.ColliderDesc.cuboid(w[0],w[1],w[2]).setRestitution(r.restitution).setFriction(r.friction),b)};m([0,a-1,0],[1e3,1,1e3]);let y=0;for(const g of o.statics||[]){const w=Y(g?.min,null),b=Y(g?.max,null);if(!w||!b||y>=Po)continue;const v=[0,1,2].map(R=>(b[R]-w[R])/2);v.some(R=>!(R>.002))||b[1]<=a+.001||(m([0,1,2].map(R=>(w[R]+b[R])/2),v),y++)}for(const g of c){g.rb=u.createRigidBody(t.RigidBodyDesc.dynamic().setTranslation(g.c[0],g.c[1],g.c[2]).setRotation({x:g.q[0],y:g.q[1],z:g.q[2],w:g.q[3]}).setLinvel(g.v[0],g.v[1],g.v[2]).setAngvel({x:g.w[0],y:g.w[1],z:g.w[2]}).setLinearDamping(.05).setAngularDamping(g.shape==="box"?.2:1.2).setCcdEnabled(!0)),s&&(g.rb.setEnabledTranslations(!0,!0,!1,!1),g.rb.setEnabledRotations(!1,!1,!0,!1));const w=g.shape==="ball"?t.ColliderDesc.ball(Math.max(...g.half)):g.shape==="cylinder"?t.ColliderDesc.cylinder(g.half[1],Math.max(g.half[0],g.half[2])):t.ColliderDesc.cuboid(g.half[0],g.half[1],g.half[2]);u.createCollider(w.setRestitution(r.restitution).setFriction(r.friction).setDensity(400),g.rb),g.samples=[]}const M=Math.round(e*At);for(let g=0;g<=M;g++){if(g)for(let w=0;w<io;w++)u.step();for(const w of c){const b=w.rb.translation(),v=w.rb.rotation(),R=[v.x,v.y,v.z,v.w],T=lo(R,w.offset),D=w.rb.linvel(),q=w.rb.angvel();w.samples.push({sec:g/At,centre:[b.x,b.y,b.z],pivot:[b.x-T[0],b.y-T[1],b.z-T[2]],q:R,speed:Math.hypot(D.x,D.y,D.z)+Math.hypot(q.x,q.y,q.z)*f(w)})}}let d=!0;return{bodies:c.map(g=>{let w=null;for(let b=g.samples.length-1;b>=0&&g.samples[b].speed<.05;b--)w=g.samples[b].sec;return w==null&&(d=!1),{id:g.id,position:g.position,rotation:g.rotation,half:g.half,offset:g.offset,samples:g.samples,settledAt:w}}),settled:d,duration:e,mode:n}}finally{u.free()}}function ge(t,o,s,{scale:n={},newId:e,lifted:a=!1}={}){const r=e??(()=>globalThis.crypto.randomUUID());return{...t,shots:t.shots.map(l=>{if(l.id!==o)return l;const i={...l.objectKeys};for(const[c,f]of Object.entries(s)){if(!f.keys.length)continue;const h=f.keys[0].time,p=t.items.find(M=>M.id===c),u=Y(n[c],Y(p?.scale,[1,1,1])),m=(i[c]||[]).filter(M=>M.time<h-1e-6),y=1/(At*Math.max(1e-6,l.duration||1));a&&f.from&&m.length&&h-y>m[m.length-1].time+1e-6&&m.push({id:r(),time:h-y,position:[...f.from.position],rotation:[...f.from.rotation],scale:[...u]}),i[c]=[...m,...f.keys.map(M=>({id:r(),time:M.time,position:[...M.position],rotation:[...M.rotation],scale:[...u]}))]}return{...l,objectKeys:i}})}}const Ue=Object.freeze(Object.defineProperty({__proto__:null,BOUNCE_PRESETS:$t,DROP_MODES:To,DROP_SECONDS:bt,KEY_TOLERANCE:Co,MAX_KEYS_PER_BODY:So,MAX_PHYSICS_BODIES:Rt,MAX_PHYSICS_STATICS:Po,PHYSICS_FPS:At,applyDropKeys:ge,bakeDrop:ye,dropUnavailable:ue,eulerFromQuat:_o,fallbackShape:me,loadRapier:jo,quatAngle:Do,quatFromEuler:Pt,rapierReady:Io,sampleBakedKeys:zo,seededRandom:Fo,shapeKind:pe,simulateDrop:Zt,thinKeys:qo},Symbol.toStringTag,{value:"Module"})),Ko=["x","y","zoom","rot","opacity","depth"],N=t=>Math.round(t*1e4)/1e4,Dt=(t,o)=>Object.keys(it).filter(s=>(!o||o.includes(s))&&Bo(t,s));function Ge(t,{in:o=.33,out:s=.33}={},n){const e=ko([Math.max(0,Math.min(1,s)),0,Math.max(0,Math.min(1,1-o)),1]);let a={...t},r={};for(const l of Dt(t)){const i=wt(a,l),c=n?n.filter(h=>h.prop===l):i;if(!c.length)continue;const f=i.map((h,p)=>p<i.length-1&&c.some(u=>Math.abs(u.time-h.time)<1/120)?{...h,ease:e}:h);r={...r,...yt(a,l,f)},a={...a,...r}}return r}const Ht={tl:[0,0],t:[.5,0],tr:[1,0],l:[0,.5],c:[.5,.5],r:[1,.5],bl:[0,1],b:[.5,1],br:[1,1]},Je=Object.keys(Ht);function Qe(t,o,s,n,e,a){const[r,l]=Ht[s],i=o.angle*Math.PI/180,c=Math.abs(o.w*Math.cos(i))+Math.abs(o.h*Math.sin(i)),f=Math.abs(o.w*Math.sin(i))+Math.abs(o.h*Math.cos(i)),h=c/2+(e-c)*r,p=f/2+(a-f)*l,u=(h-o.cx)/e,m=(p-o.cy)/a,y=(d,x)=>Math.max(it[d].min,Math.min(it[d].max,x));let M=no(t,"x",N(y("x",vt(t,"x",n)+u)),n);return M={...M,...no({...t,...M},"y",N(y("y",vt(t,"y",n)+m)),n)},M}function Ze(t,o,s,n,e,a){const[r,l]=Ht[s],i=Gt(t,n,e,a).zoom||1;return Go(t,n,N((r-.5)*o.w/(e*i)),N((l-.5)*o.h/(a*i)),e,a)}function He(t,o,s,n="forward",e=1){let a=t.filter(i=>o.includes(i.id)).sort((i,c)=>c.track-i.track||i.start-c.start);if(a.length<2)return t;if(n==="reverse")a.reverse();else if(n==="center"){const i=(a.length-1)/2;a=[...a].sort((c,f)=>Math.abs(a.indexOf(c)-i)-Math.abs(a.indexOf(f)-i))}else if(n==="random"){let i=e>>>0||1;const c=()=>(i=Math.imul(i^i>>>15,2246822507)>>>0)/4294967295;a=a.map(f=>[c(),f]).sort((f,h)=>f[0]-h[0]).map(f=>f[1])}const r=Math.min(...a.map(i=>i.start)),l=new Map(a.map((i,c)=>[i.id,N(Math.max(0,r+c*s))]));return t.map(i=>l.has(i.id)?{...i,start:Math.min(l.get(i.id),600-i.duration)}:i)}function We(t,o){const s={};for(const e of Dt(t)){const a=wt(t,e).filter(r=>!o||o.some(l=>l.prop===e&&Math.abs(l.time-r.time)<.008333333333333333));a.length&&(s[e]=a)}const n=Math.min(...Object.values(s).flat().map(e=>e.time));return Object.keys(s).length?{props:Object.fromEntries(Object.entries(s).map(([e,a])=>[e,a.map(r=>({...r,time:N(r.time-n)}))]))}:null}function tn(t,o,s){let n={...t},e={};for(const[a,r]of Object.entries(o.props)){if(!it[a]||t.kind==="model"&&a==="rot"||t.kind!=="model"&&["rx","ry","rz"].includes(a))continue;const l=r.map(c=>({...c,time:N(s+c.time)})).filter(c=>c.time<=t.duration+1e-6),i=wt(n,a).filter(c=>!l.some(f=>Math.abs(f.time-c.time)<1/120));e={...e,...yt(n,a,[...i,...l].sort((c,f)=>c.time-f.time))},n={...n,...e}}return e}function on(t,o="elastic",{amount:s=.5,cycles:n=3,props:e}={}){let a={...t},r={};for(const l of Dt(t,e??Ko)){const i=wt(a,l);if(i.length<2)continue;const c=i.at(-2),f=i.at(-1),h=f.time-c.time,p=t.duration-f.time;if(h<=0||p<.1)continue;const u=f.value-c.value;if(Math.abs(u)<1e-6)continue;const m=Math.max(1,Math.min(6,Math.round(n))),y=Math.min(p/(m*2),Math.max(.06,h*.6)),M=[];for(let d=1;d<=m*2;d++){const x=s*Math.pow(.45,Math.ceil(d/2)-1),g=o==="bounce"?(d%2?-1:0)*Math.abs(u)*x*Math.sign(u):(d%2?1:-1)*u*x*.5,w=d===m*2?f.value:f.value+g,b=it[l].min,v=it[l].max;M.push({time:N(f.time+y*d),value:N(Math.max(b,Math.min(v,w))),ease:fo})}r={...r,...yt(a,l,[...i.map((d,x)=>x===i.length-1?{...d,ease:fo}:d),...M])},a={...a,...r}}return r}const fo=[.33,0,.67,1];function en(t,o="cycle",{props:s,maxKeys:n=60}={}){let e={...t},a={};for(const r of Dt(t,s)){const l=wt(e,r);if(l.length<2)continue;const i=l[0].time,c=l.at(-1).time,f=c-i;if(f<=1/30)continue;const h=[...l],p=l.at(-1).value-l[0].value;for(let u=1;h.length<n;u++){const m=o==="pingpong"&&u%2?[...l].reverse().map(M=>({...M,time:c-(M.time-i)})):l;let y=!1;for(const M of m.slice(1)){const d=N(M.time+f*u);if(d>t.duration+1e-6||h.length>=n)break;const x=o==="offset"?M.value+p*u:M.value,{min:g,max:w}=it[r];h.push({...M,time:d,value:N(Math.max(g,Math.min(w,x)))}),y=!0}if(!y)break}a={...a,...yt(e,r,h)},e={...e,...a}}return a}function nn(t,o){const s=Ct(t.shape)?t.shape:yo(t.shape);return s.items.map(n=>({...t,id:o(),label:`${t.label} · ${n.name}`.slice(0,60),shape:{...s,items:[{...n}]}}))}const be=["posX","posY","scale","rotation","anchorX","anchorY","parentId","opacity"];function sn(t){if(t.length<2)throw Error("Chọn ít nhất 2 layer Shape để gộp");const[o,...s]=t,n=a=>be.every(r=>(a[r]??null)===(o[r]??null))&&!a.motionKeys?.some(r=>Ko.some(l=>l in r));if(!t.every(n))throw Error("Chỉ gộp được các layer Shape cùng vị trí / tỉ lệ / góc xoay và không có key chuyển động");const e=[];for(const a of t){const r=Ct(a.shape)?a.shape:yo(a.shape);for(const l of r.items)e.push({...l,id:Uo(e)})}if(e.length>24)throw Error("Một layer Shape chứa tối đa 24 hình");return{...o,start:Math.min(...t.map(a=>a.start)),duration:Math.max(...t.map(a=>a.start+a.duration))-Math.min(...t.map(a=>a.start)),shape:{v:2,items:e}}}function rn(t,o,s,{fps:n=10,makeId:e,label:a}={}){const r=Math.min(o/1280,s/720),l=(y,M)=>[N(((y-o/2)/r+640-280)/.72),N(((M-s/2)/r+360)/.72)],i=Math.max(2,Math.min(255,Math.round(t.duration*n)+1)),c=[];for(let y=0;y<i;y++){const M=Gt(t,t.duration*y/(i-1),o,s);c.push(l(o/2+M.x*o,s/2+M.y*s))}const f=c.map(y=>y[0]),h=c.map(y=>y[1]),p=(Math.min(...f)+Math.max(...f))/2,u=(Math.min(...h)+Math.max(...h))/2,m={id:"s1",name:"Position Trace",type:"path",params:{pts:c.map(([y,M])=>[N(y-p),N(M-u)]),closed:!1},pos:[N(p),N(u)],rot:0,scale:[1,1],opacity:1,fill:{type:"none"},stroke:{color:"#c6f432",width:8,cap:"round",join:"round"}};return{id:e(),nodeId:"",kind:"image",url:"",label:a??`${t.label} · trace`.slice(0,60),track:t.track,start:t.start,duration:t.duration,volume:0,motionV:2,shape:{v:2,items:[m]}}}const Wt=/^#[0-9a-fA-F]{6}$/,xe=24,an=["#c6f432","#2bd4c9","#ffffff","#0d0f12","#ff5bd1"];function ln(t,o=16){const s=new Map,n=e=>{if(typeof e=="string"&&Wt.test(e)){const a=e.toLowerCase();s.set(a,(s.get(a)||0)+1)}};for(const e of t){e.title&&(n(e.title.color),n(e.title.accentColor));const a=e.shape;if(a)if(Ct(a))for(const r of a.items){n(r.fill.color);for(const l of r.fill.stops||[])n(l[0]);n(r.stroke?.color)}else for(const r of a.paths)n(r.stroke),n(r.fill)}return[...s.entries()].sort((e,a)=>a[1]-e[1]).slice(0,o).map(e=>e[0])}function cn(t,o,{stroke:s=!1,itemId:n}={}){if(!Wt.test(o))throw Error("Invalid colour");if(t.title)return{title:{...t.title,[s?"accentColor":"color"]:o}};if(!t.shape)throw Error("Chọn layer Shape hoặc chữ để áp màu");return Ct(t.shape)?{shape:{...t.shape,items:t.shape.items.map(e=>n&&e.id!==n?e:s?{...e,stroke:{...e.stroke??{width:8,cap:"round",join:"round"},color:o}}:{...e,fill:e.fill.type==="linear"||e.fill.type==="radial"?{...e.fill,stops:e.fill.stops.map((a,r)=>r===0?[o,a[1]]:a)}:{...e.fill,type:"color",color:o}})}}:{shape:{...t.shape,paths:t.shape.paths.map(e=>s||!e.fill?{...e,stroke:o}:{...e,fill:o})}}}function fn(t,o){if(!Array.isArray(o)||!o.length||o.length>xe||!o.every(e=>Wt.test(e)))throw Error("Invalid palette");const s=e=>o[e%o.length];if(t.title)return{title:{...t.title,color:s(0),...o.length>1?{accentColor:s(1)}:{}}};if(!t.shape)throw Error("Chọn layer Shape hoặc chữ để áp màu");if(!Ct(t.shape))return{shape:{...t.shape,paths:t.shape.paths.map((e,a)=>({...e,...e.fill?{fill:s(a)}:{},...e.stroke?{stroke:e.fill?e.stroke:s(a)}:{}}))}};let n=0;return{shape:{...t.shape,items:t.shape.items.map(e=>{const a=e.fill;return a.type==="linear"||a.type==="radial"?{...e,fill:{...a,stops:a.stops.map(r=>[s(n++),r[1]])}}:a.type==="color"?{...e,fill:{...a,color:s(n++)}}:e.stroke?{...e,stroke:{...e.stroke,color:s(n++)}}:e})}}}function we(t,o,s,n){const e=Gt(t,o,s,n),a=t.card?t.card.width/t.card.height:t.lottie?t.lottie.w/t.lottie.h:null,[r,l]=a&&Number.isFinite(a)&&a>0?a>s/n?[s,s/a]:[n*a,n]:[s,n];return{cx:s/2+e.x*s,cy:n/2+e.y*n,w:r*e.zoom,h:l*e.zoom,angle:e.rot}}const ve=3,kt=30,Ot=Object.freeze({xy:.002,rot:1.5}),Ee=.2,ho=t=>typeof t=="number"&&Number.isFinite(t),uo=t=>Math.round(t*1e4)/1e4;function Ae(t){return t?t.kind==="audio"?"Âm thanh không rơi được":t.adjust===!0?"Lớp điều chỉnh không có hình để rơi":t.parentId?"Lớp đang gắn vào lớp cha — bỏ gắn rồi thử lại":null:"Không tìm thấy lớp"}function to(t,o,s,n=kt){const e=t.length;if(e<=2)return[...Array(e).keys()];const a=[0,e-1];for(;;){a.sort((i,c)=>i-c);let r=-1,l=s;for(let i=0;i+1<a.length;i++){const c=a[i],f=a[i+1];for(let h=c+1;h<f;h++){const p=o[c]+(o[f]-o[c])*(t[h]-t[c])/(t[f]-t[c]),u=Math.abs(p-o[h]);u>l&&(l=u,r=h)}}if(r<0||a.length>=n)return a;a.push(r)}}function Pe(t,o,s){let n=0;for(let e=0;e+1<s.length;e++)for(let a=s[e]+1;a<s[e+1];a++){const r=s[e],l=s[e+1];n=Math.max(n,Math.abs(o[r]+(o[l]-o[r])*(t[a]-t[r])/(t[l]-t[r])-o[a]))}return n}function Ce(t,o,s){const n=[],e=r=>Math.floor((r+180)/360),a=(r,l)=>r-360*l;for(let r=0;r<s.length;r++){const l=s[r],i=o[l],c=e(i);if(r){const f=s[r-1],h=e(o[f]);if(h!==c){const p=c>h,u=(p?h+1:h)*360-180,m=(u-o[f])/(i-o[f]),y=Et(t[f]+(t[l]-t[f])*m),M=Math.max(n.at(-1).time+1/ut,Math.min(y,Et(t[l]-2/ut))),d=M+1/ut;d<t[l]-1e-6?n.push({time:M,value:p?180:-180,ease:"hold"},{time:d,value:p?-180:180}):n[n.length-1]={...n[n.length-1],ease:"hold"}}}n.push({time:t[l],value:Math.max(-180,Math.min(180,a(i,c)))})}return n}function hn(t,o,s={}){const n=s.R??Io();if(!n)throw Error("Physics engine not loaded yet — try again");const e=s.W??1280,a=s.H??720,r=ve/a,l=ho(s.at)?s.at:0,i=Math.max(1,Math.min(bt.max,ho(s.duration)?s.duration:bt.default)),c=s.mode==="above"?"above":"here",f=[...new Set(o)].map(b=>t.find(v=>v.id===b));if(!f.length)throw Error("physicsDrop needs clipIds");if(f.length>Rt)throw Error(`At most ${Rt} layers per drop`);for(const[b,v]of f.entries()){const R=Ae(v);if(R)throw Error(`${v?.label??o[b]}: ${R}`)}const h=f.map(b=>{const v=Et(l-b.start);if(v<0||v>b.duration-2/ut)throw Error(`${b.label??b.id}: the playhead is outside the layer`);const R=vt(b,"x",v),T=vt(b,"y",v),D=vt(b,"rot",v),q=s.rectOf?.(b)??we(b,v,e,a),O=[R*e*r,-T*a*r],X=[(q.cx-e/2)*r,-(q.cy-a/2)*r],P=D*Math.PI/180,E=[X[0]-O[0],X[1]-O[1]],I=[E[0]*Math.cos(P)-E[1]*Math.sin(P),E[0]*Math.sin(P)+E[1]*Math.cos(P)];return{id:b.id,position:[O[0],O[1],0],rotation:[0,0,-D],half:[Math.max(4,q.w)*r/2,Math.max(4,q.h)*r/2,Ee],offset:[I[0],I[1],0],local:v,x:R,y:T,rot:D}}),p=-a*r/2,u=a*r/2,m=e*r/2,y=s.walls?[{min:[-m-2,p,-2],max:[-m,u+20,2]},{min:[m,p,-2],max:[m+2,u+20,2]}]:[],M=b=>Math.hypot(b.half[0],b.half[1],b.half[2]),d=Math.max(...h.map(b=>b.position[1]+M(b))),x=Zt(n,{bodies:h,statics:y,floor:p,mode:c,bounciness:s.bounciness,duration:i,height:Math.max(.3,u-d+.05),seed:s.seed??[...o].sort().join(","),planar:!0}),g={},w=t.map(b=>({...b}));for(const b of h){const v=x.bodies.find(F=>F.id===b.id),R=w.findIndex(F=>F.id===b.id);let T=w[R];const D=[],q=[],O=[],X=[];let P=b.rot;for(const F of v.samples){const G=Et(b.local+F.sec);if(G>T.duration+1e-6)break;let H=-2*Math.atan2(F.q[2],F.q[3])*180/Math.PI;H+=360*Math.round((P-H)/360),P=H,D.push(G),q.push(F.pivot[0]/r/e),O.push(-F.pivot[1]/r/a),X.push(H)}const E=c==="above"&&b.local>=1/ut,I={},V={},K=Math.min(...X),k=Math.max(...X),B=k-K<360?Math.ceil((k-180)/360)*360:0,mt=B&&K-B>=-180?X.map(F=>F-B):X,dt=mt!==X&&b.local>=1/ut;for(const[F,G,H]of[["x",q,Ot.xy],["y",O,Ot.xy],["rot",mt,Ot.rot]]){const Mt=E||F==="rot"&&dt,W=wt(T,F).filter(L=>L.time<b.local-(Mt?1.5:.5)/ut),tt=Mt?[{time:Et(b.local-1/ut),value:F==="x"?b.x:F==="y"?b.y:b.rot,...F==="rot"&&dt?{ease:"hold"}:{}}]:[],ft=F==="rot"?G.reduce((L,J,at)=>L+(at&&Math.floor((J+180)/360)!==Math.floor((G[at-1]+180)/360)?1:0),0):0,rt=kt-W.length-tt.length-2*ft;if(rt<2)throw Error(`${T.label??T.id}: too many ${F} keys before the playhead (or too many turns) to add the drop`);const ht=to(D,G,H,rt),gt=it[F].min,_=it[F].max,z=F==="rot"?Ce(D,G,ht):ht.map(L=>({time:D[L],value:Math.max(gt,Math.min(_,G[L]))})),nt=[...W,...tt,...z].map(L=>({time:L.time,value:uo(L.value),...L.ease?{ease:L.ease}:{}}));T={...T,...yt(T,F,nt.slice(0,kt))},I[F]=z.length,V[F]=uo(Pe(D,G,ht))}w[R]=T,g[b.id]={keys:I,error:V,settledAt:v.settledAt==null?null:Math.round((l+v.settledAt)*1e3)/1e3}}return{clips:w,report:g,settled:x.settled}}const $=Object.freeze({work:480,focals:[.45,.55,.7,.85,1,1.25],maxFrames:900,keyTolPx:.05,points:400,smooth:.3,smoothFrames:4,smoothTolPx:.25,dense:{cols:40,rows:22,keep:700,minFrames:8,max:1500},slide:.01}),C=t=>Math.round(t*1e6)/1e6,A=(t,o)=>[t[0]-o[0],t[1]-o[1],t[2]-o[2]],U=(t,o)=>[t[0]+o[0],t[1]+o[1],t[2]+o[2]],j=(t,o)=>[t[0]*o,t[1]*o,t[2]*o],S=(t,o)=>t[0]*o[0]+t[1]*o[1]+t[2]*o[2],st=(t,o)=>[t[1]*o[2]-t[2]*o[1],t[2]*o[0]-t[0]*o[2],t[0]*o[1]-t[1]*o[0]],et=t=>{const o=Math.hypot(...t)||1;return j(t,1/o)},Z=(t,o)=>[S(t[0],o),S(t[1],o),S(t[2],o)],pt=t=>[0,1,2].map(o=>[t[0][o],t[1][o],t[2][o]]),po=(t,o)=>t.map(s=>[0,1,2].map(n=>s[0]*o[0][n]+s[1]*o[1][n]+s[2]*o[2][n]));function Se(t,o,s,n=bo(29)){const e=t;if(e.length<20)return null;const a=e.map(r=>Math.hypot(...A(r,s))).sort((r,l)=>r-l)[e.length>>1];for(const r of[.015,.03,.05]){const l=a*r;let i=null;for(let u=0;u<2e3;u++){const m=e[Math.floor(n()*e.length)],y=e[Math.floor(n()*e.length)],M=e[Math.floor(n()*e.length)];let d=st(A(y,m),A(M,m));const x=Math.hypot(...d);if(x<1e-9||(d=j(d,1/x),S(d,o)<0&&(d=j(d,-1)),S(d,o)<Math.cos(35*Math.PI/180)))continue;const g=-S(d,m);if(S(d,s)+g<=l)continue;let w=0;for(const b of e)Math.abs(S(d,b)+g)<l&&w++;(!i||w>i.k)&&(i={n:d,d:g,k:w})}if(!i||i.k<e.length*.2)continue;const c=e.filter(u=>Math.abs(S(i.n,u)+i.d)<l),f=j(c.reduce((u,m)=>U(u,m),[0,0,0]),1/c.length),h=[[0,0,0],[0,0,0],[0,0,0]];for(const u of c){const m=A(u,f);for(let y=0;y<3;y++)for(let M=0;M<3;M++)h[y][M]+=m[y]*m[M]}let p=Ft(h);return S(p,o)<0&&(p=j(p,-1)),{n:p,d:-S(p,f),count:c.length}}return null}function Ft(t){const o=t.map(e=>[...e]),s=[[1,0,0],[0,1,0],[0,0,1]];for(let e=0;e<30;e++){let a=0;for(let r=0;r<3;r++)for(let l=r+1;l<3;l++)a+=o[r][l]**2;if(a<1e-24)break;for(let r=0;r<3;r++)for(let l=r+1;l<3;l++){if(Math.abs(o[r][l])<1e-30)continue;const i=(o[l][l]-o[r][r])/(2*o[r][l]),c=Math.sign(i||1)/(Math.abs(i)+Math.sqrt(i*i+1)),f=1/Math.sqrt(c*c+1),h=c*f;for(let p=0;p<3;p++){const u=o[p][r],m=o[p][l];o[p][r]=f*u-h*m,o[p][l]=h*u+f*m}for(let p=0;p<3;p++){const u=o[r][p],m=o[l][p];o[r][p]=f*u-h*m,o[l][p]=h*u+f*m}for(let p=0;p<3;p++){const u=s[p][r],m=s[p][l];s[p][r]=f*u-h*m,s[p][l]=h*u+f*m}}}const n=[0,1,2].reduce((e,a)=>o[a][a]<o[e][e]?a:e,0);return et([s[0][n],s[1][n],s[2][n]])}function It(t,o,s,n){const e=new Map;t.poses.forEach((a,r)=>{if(!(!a||a.lost))for(const[l,i]of t.obs[r]){const c=t.points.get(l);if(!c)continue;const f=Z(a.R,A(c,a.C)),h=f[2]>-1e-6?50:Math.hypot(s+o*f[0]/-f[2]-i[0],n-o*f[1]/-f[2]-i[1]),p=e.get(l)??[0,0,0];p[0]+=h,p[1]++,p[2]=Math.max(p[2],h),e.set(l,p)}});for(const a of e.values())a[0]/=a[1];return e}function jt(t,o,s,n){const e=[...It(t,o,s,n).values()].map(r=>r[0]).sort((r,l)=>r-l),a=Math.floor(e.length*.8);return a>30?e.slice(0,a).reduce((r,l)=>r+l,0)/a:1/0}function mo(t,o,s,n){const{solved:e,keyframes:a}=Xo(t);for(let r=0;r<3;r++){const l=It(t,o,s,n),i=[...l.values()].map(h=>h[2]).sort((h,p)=>h-p),c=Math.max(1.2,2*(i[i.length>>1]??1));let f=0;for(const[h,p]of l)p[2]>c&&(t.points.delete(h),f++);if(!f)break;Jt(t.poses,t.points,t.obs,a,o,s,n,8),Oo(t,a,e,o,s,n)}}function Xo(t){const o=t.poses.map((n,e)=>n&&!n.lost?e:-1).filter(n=>n>=0),s=Math.max(1,Math.ceil(o.length/60));return{solved:o,keyframes:[t.pair[0],...o.filter((n,e)=>n!==t.pair[0]&&(e%s===0||e===o.length-1))]}}function Oo(t,o,s,n,e,a){const r=Math.hypot(...A(t.poses[t.pair[1]].C,t.poses[t.pair[0]].C))||1,l=new Set(o);for(const i of s){if(l.has(i))continue;const c=[];for(const[f,h]of t.obs[i])t.points.has(f)&&c.push({X:t.points.get(f),px:h});c.length>=10&&(t.poses[i]=ee(c,t.poses[i],n,e,a,r).pose)}}function Te(t,o,s,n){const{solved:e,keyframes:a}=Xo(t),r={poses:t.poses.map(c=>c&&{...c,R:c.R.map(f=>[...f]),C:[...c.C]}),points:new Map([...t.points].map(([c,f])=>[c,[...f]]))},l=jt(t,o,s,n),i=Jt(t.poses,t.points,t.obs,a,o,s,n,12,{focal:!0});return Math.abs(i/o-1)<1e-4?o:(Oo(t,a,e,i,s,n),Math.abs(i/o-1)<.15&&jt(t,i,s,n)<l?i:(t.poses=r.poses,t.points=r.points,o))}function Re(t,o,{w:s,h:n,mw:e,mh:a,focals:r=$.focals,focal:l=null,onProgress:i=null}={}){const c=s/2,f=n/2;let h=l,p=0;const u=l?1:r.length+9;if(!h){const P=new Map,E=Math.max(s,n)/s;let I=t;const V=_=>{if(_=Math.round(_*1e3)/1e3,!(_>.2&&_<3)||P.has(_))return;const z=ao(null,_*s,{obs:I,w:s,h:n});z.mode==="free"&&mo(z,_*s,c,f),P.set(_,{s:z,e:z.mode==="free"?jt(z,_*s,c,f):1/0}),i?.(++p/u)};let K=[];for(let _=Math.max(1,Math.round(t.length/25));;_=Math.max(1,_>>1)){I=t.filter((z,nt)=>nt%_===0),P.clear(),p=0;for(const z of r)V(z*E);if(K=[...P.entries()].filter(([,z])=>Number.isFinite(z.e)).sort((z,nt)=>z[0]-nt[0]),K.length||_===1)break}if(!K.length)return i?.(1),null;const k=K.reduce((_,z,nt)=>z[1].e<K[_][1].e?nt:_,0),B=K[k][1].s,mt=k>0?K[k-1][0]:K[k][0]*.8,dt=k<K.length-1?K[k+1][0]:K[k][0]*1.25,F=B.poses.map((_,z)=>_&&!_.lost?z:-1).filter(_=>_>=0),G=B.pair[0],H=_=>{const z={...B,poses:B.poses.map(J=>J&&{...J,R:J.R.map(at=>[...at]),C:[...J.C]}),points:new Map([...B.points].map(([J,at])=>[J,[...at]]))};Jt(z.poses,z.points,z.obs,[G,...F.filter(J=>J!==G)],_*s,c,f,8),i?.(++p/u);let nt=0,L=0;for(const[J,at]of It(z,_*s,c,f).values())nt+=J*at,L+=at;return L?nt/L:1/0},Mt=(Math.sqrt(5)-1)/2;let W=mt,tt=dt,ft=tt-Mt*(tt-W),rt=W+Mt*(tt-W),ht=H(ft),gt=H(rt);for(let _=0;_<7;_++)ht<gt?(tt=rt,rt=ft,gt=ht,ft=tt-Mt*(tt-W),ht=H(ft)):(W=ft,ft=rt,ht=gt,rt=W+Mt*(tt-W),gt=H(rt));h=(W+tt)/2}const m=ao(null,h*s,{obs:t,w:s,h:n});if(i?.(1),m.mode!=="free")return null;let y=h*s;const M=m.poses[m.pair[0]].C,d=m.poses[m.pair[0]].R;if(mo(m,y,c,f),!l)for(let P=0;P<3;P++){const E=Te(m,y,c,f),I=Math.abs(E/y-1)<5e-4;if(y=E,I)break}const x=It(m,y,c,f),g=[...x.values()].map(P=>P[0]).sort((P,E)=>P-E),w=Math.max(1.5,3*(g[g.length>>1]??1)),b=[...x.entries()].filter(([P,E])=>m.points.has(P)&&E[0]<=w&&E[1]>=2),v=P=>t.flatMap((E,I)=>E.has(P)?[o[I]]:[]);let R=0,T=0;for(const[,P]of b)R+=P[0]*P[1],T+=P[1];const D=Z(pt(d),[0,1,0]),q=Se([...m.points.values()],D,M)??te(m.points,D,M)??oe(m.points,D,M),O={v:1,w:s,h:n,mw:e||s,mh:a||n,mode:"free",f:C(y),err:C(T?R/T:jt(m,y,c,f)),frames:m.poses.map((P,E)=>[C(o[E]),...xo(P.R).map(C),...P.C.map(C)]),floor:q?[...q.n.map(C),C(q.d)]:null},X=[];for(const[P]of b.sort((E,I)=>I[1][1]-E[1][1])){if(X.length>=$.points)break;const E=m.points.get(P),I=v(P);No(O,E,I)<=$.slide*s&&X.push([E.map(C),[C(I[0]),C(I.at(-1))]])}return{...O,points:X.map(P=>P[0]),seen:X.map(P=>P[1])}}function No(t,o,s){if(!s.length)return 1/0;const e=(s.length>24?s.filter((p,u)=>u%Math.ceil(s.length/24)===0||u===s.length-1):s).map(p=>et(A(o,lt(t,p).C)));let a=0;for(const p of[e[0],e.at(-1)])for(const u of e)a=Math.max(a,Math.acos(Math.min(1,S(p,u))));const r=lt(t,s[s.length>>1]).C,l=Math.hypot(...A(o,r)),i=U(o,j(et(A(o,r)),l*(.5/t.f)/Math.max(.001,Math.sin(a)))),c=t.frames,f=Math.max(1,Math.floor(c.length/40));let h=0;for(let p=0;p<c.length;p+=f){const u=ct(t,o,c[p][0]),m=ct(t,i,c[p][0]);u&&m&&(h=Math.max(h,Math.hypot(u[0]-m[0],u[1]-m[1])))}return h}function un(t,o,{mw:s,mh:n,focals:e=$.focals,focal:a=null,onProgress:r=null,dense:l=!0}={}){if(t.length<3)throw Error("FLAT");const i=t[0].w,c=t[0].h,f=wo(t,{anchor:!0,onProgress:r&&(u=>r(u*.35))}),h=Re(f,o,{w:i,h:c,mw:s,mh:n,focals:e,focal:a,onProgress:r&&(u=>r(.35+u*.57))});if(h){const u=l?Ie(h,t,o,r&&(m=>r(.92+m*.08))):h;return r?.(1),u}const p=Wo(t,(a??.7)*i);if(p.filter(u=>!u.lost).length<t.length*.5)throw Error("FLAT");return{v:1,w:i,h:c,mw:s||i,mh:n||c,mode:"tripod",frames:p.map((u,m)=>[C(o[m]),...u.q.map(C),C(u.f)])}}function Ie(t,o,s,n=null,e=$.dense){const a=wo(o,{anchor:!0,keep:e.keep,cols:e.cols,rows:e.rows,onProgress:n&&(u=>n(u*.8))}),r=new Map;a.forEach((u,m)=>{for(const[y,M]of u){let d=r.get(y);d||r.set(y,d=[]),d.push([s[m],M[0],M[1]])}});const l=[...r.values()].filter(u=>u.length>=e.minFrames),i=t.points??[],c=u=>i.some(m=>Math.abs(m[0]-u[0])+Math.abs(m[1]-u[1])+Math.abs(m[2]-u[2])<1e-6),f=t.seen??i.map(()=>[t.frames[0][0],t.frames.at(-1)[0]]),h=[...i],p=[...f];for(const u of l){if(h.length>=e.max)break;const m=Lo(t,u);!m||c(m)||No(t,m,u.map(y=>y[0]))>$.slide*t.w||(h.push(m.map(C)),p.push([C(u[0][0]),C(u.at(-1)[0])]))}return n?.(1),{...t,points:h,seen:p}}const _t=t=>!!t&&typeof t.ref=="string"&&!Array.isArray(t.frames);function je(t){if(!t||t.v!==1||!["free","tripod"].includes(t.mode))throw Error("Invalid scene track");for(const n of["w","h","mw","mh"])if(!(Number.isFinite(t[n])&&t[n]>0&&t[n]<=2e4))throw Error("Invalid scene track");if(t.smooth!==void 0&&!(Number.isFinite(t.smooth)&&t.smooth>=0&&t.smooth<=1))throw Error("Invalid scene track");if(_t(t)){if(!/^[0-9a-f]{64}$/.test(t.ref))throw Error("Invalid scene track");return t}const o=t.mode==="free"?8:6;if(!Array.isArray(t.frames)||t.frames.length<2)throw Error("Invalid scene track");let s=-1/0;for(const n of t.frames){if(!Array.isArray(n)||n.length!==o||!n.every(Number.isFinite)||n[0]<s)throw Error("Invalid scene track");s=n[0]}if(t.mode==="free"&&(!(Number.isFinite(t.f)&&t.f>0)||t.floor!=null&&!(Array.isArray(t.floor)&&t.floor.length===4&&t.floor.every(Number.isFinite))||!Array.isArray(t.points)||t.points.length>5e3||!t.points.every(n=>Array.isArray(n)&&n.length===3&&n.every(Number.isFinite))||t.seen!=null&&!(Array.isArray(t.seen)&&t.seen.length===t.points.length&&t.seen.every(n=>Array.isArray(n)&&n.length===2&&n.every(Number.isFinite)&&n[0]<=n[1]))))throw Error("Invalid scene track");return t}function lt(t,o){const s=t.frames,n=s.length;let e=0,a=Math.max(0,n-2);for(;e<a;){const u=e+a+1>>1;s[u][0]<=o?e=u:a=u-1}const r=s[e],l=s[Math.min(n-1,e+1)],i=l[0]>r[0]?Math.max(0,Math.min(1,(o-r[0])/(l[0]-r[0]))):0;let c=r.slice(1,5),f=l.slice(1,5);oo(c,f)<0&&(f=f.map(u=>-u));const h=_e(c,f,i),p=go(h);return t.mode==="tripod"?{R:p,C:[0,0,0],f:r[5]+(l[5]-r[5])*i}:{R:p,C:[0,1,2].map(u=>r[5+u]+(l[5+u]-r[5+u])*i),f:t.f}}const oo=(t,o)=>t[0]*o[0]+t[1]*o[1]+t[2]*o[2]+t[3]*o[3];function _e(t,o,s){const n=Math.min(1,Math.max(-1,oo(t,o)));if(n>.9995){const i=t.map((f,h)=>f+(o[h]-f)*s),c=Math.hypot(...i);return i.map(f=>f/c)}const e=Math.acos(n),a=Math.sin(e),r=Math.sin((1-s)*e)/a,l=Math.sin(s*e)/a;return t.map((i,c)=>i*r+o[c]*l)}function De(t,o,s){const n=t.seen?.[o];if(!n)return!0;const e=t.frames.length>1?(t.frames.at(-1)[0]-t.frames[0][0])/(t.frames.length-1):0;return s>=n[0]-e-1e-4&&s<=n[1]+e+1e-4}const eo=(t,o)=>(t.points??[]).map((s,n)=>[s,n]).filter(([,s])=>De(t,s,o));function ct(t,o,s){const n=lt(t,s),e=Z(n.R,t.mode==="tripod"?o:A(o,n.C));return e[2]>-1e-6?null:[t.w/2+n.f*e[0]/-e[2],t.h/2-n.f*e[1]/-e[2]]}function zt(t,o,s,n){const e=lt(t,n),a=et([(o-t.w/2)/e.f,-(s-t.h/2)/e.f,-1]);return{o:e.C,d:Z(pt(e.R),a),pose:e}}function Fe(t,o,s,n,{radius:e=null}={}){const{o:a,d:r}=zt(t,o,s,n);if(t.mode==="tripod")return r.map(C);const l=e??Math.max(10,t.w*.04),i=[];for(const[h]of eo(t,n)){const p=ct(t,h,n);if(!p)continue;const u=Math.hypot(p[0]-o,p[1]-s),m=S(A(h,a),r);m>0&&u<=t.w*.15&&i.push({X:h,depth:m,dist:u,w:1/(1+u)})}i.sort((h,p)=>h.dist-p.dist);const c=i.filter((h,p)=>h.dist<=l||p<6);let f=null;if(c.length>=3&&(f=ze(c,a,r)),f===null&&c.length>=2){c.sort((u,m)=>u.depth-m.depth);const h=c.reduce((u,m)=>u+m.w,0);let p=0;for(const u of c)if(p+=u.w,p>=h/2){f=u.depth;break}}else if(f===null&&t.floor){const h=t.floor.slice(0,3),p=S(h,r);if(Math.abs(p)>1e-6){const u=-(S(h,a)+t.floor[3])/p;u>0&&(f=u)}}if(f===null){const h=(t.points??[]).map(p=>S(A(p,a),r)).filter(p=>p>0).sort((p,u)=>p-u);f=h.length?h[h.length>>1]:1}return U(a,j(r,f)).map(C)}function ze(t,o,s){const n=t.slice(0,20),e=n.map(d=>d.depth).sort((d,x)=>d-x),a=e[e.length>>1]*.015,r=n.reduce((d,x)=>d+x.w,0);let l=null,i=0;for(let d=0;d<n.length;d++)for(let x=d+1;x<n.length;x++)for(let g=x+1;g<n.length;g++){let w=st(A(n[x].X,n[d].X),A(n[g].X,n[d].X));const b=Math.hypot(...w);if(b<1e-12)continue;w=j(w,1/b);const v=n.filter(T=>Math.abs(S(w,A(T.X,n[d].X)))<a),R=v.reduce((T,D)=>T+D.w,0);R>i&&(l=v,i=R)}if(!l||l.length<3||i<r*.5)return null;const c=j(l.reduce((d,x)=>U(d,x.X),[0,0,0]),1/l.length),f=[[0,0,0],[0,0,0],[0,0,0]];for(const{X:d}of l){const x=A(d,c);for(let g=0;g<3;g++)for(let w=0;w<3;w++)f[g][w]+=x[g]*x[w]}if(!(f[0][0]+f[1][1]+f[2][2]>0))return null;const p=Ft(f),u=S(p,s);if(Math.abs(u)<.05)return null;const m=Math.min(...l.map(d=>d.depth)),y=Math.max(...l.map(d=>d.depth)),M=S(p,A(c,o))/u;return M>=m*.7&&M<=y*1.4?M:null}function qe(t,o,s,n){if(t.mode!=="free"||!t.floor)return null;const{o:e,d:a}=zt(t,o,s,n),r=t.floor.slice(0,3),l=S(r,a);if(Math.abs(l)<1e-6)return null;const i=-(S(r,e)+t.floor[3])/l;return i>0?U(e,j(a,i)):null}function pn(t,o){return t.mode!=="free"?[]:o.map(s=>Lo(t,s)).filter(Boolean)}function Lo(t,o){if(t.mode!=="free"||o.length<4)return null;const s=o.map(([l,i,c])=>zt(t,i,c,l));let n=0;for(const l of s)n=Math.max(n,Math.acos(Math.min(1,S(l.d,s[0].d))));if(n<.5*Math.PI/180)return null;const e=[[0,0,0],[0,0,0],[0,0,0]],a=[0,0,0];for(const{o:l,d:i}of s)for(let c=0;c<3;c++)for(let f=0;f<3;f++){const h=(c===f?1:0)-i[c]*i[f];e[c][f]+=h,a[c]+=h*l[f]}const r=Ke(e,a);return r&&o.every(([l,i,c])=>{const f=ct(t,r,l);return f&&Math.hypot(f[0]-i,f[1]-c)<1.5})?r:null}function Ke(t,o){const s=e=>e[0][0]*(e[1][1]*e[2][2]-e[1][2]*e[2][1])-e[0][1]*(e[1][0]*e[2][2]-e[1][2]*e[2][0])+e[0][2]*(e[1][0]*e[2][1]-e[1][1]*e[2][0]),n=s(t);return Math.abs(n)<1e-12?null:[0,1,2].map(e=>s(t.map((a,r)=>a.map((l,i)=>i===e?o[r]:l)))/n)}function mn(t,o,s,{extra:n=[]}={}){if(t.mode!=="free")return null;const e=(p,u)=>{let m=0;for(let y=0;y<4;y++){const[M,d]=o[y],[x,g]=o[(y+1)%4],w=(x-M)*(u-d)-(g-d)*(p-M);if(w){if(m&&Math.sign(w)!==m)return!1;m=Math.sign(w)}}return!0},a=lt(t,s),r=[...n,...eo(t,s).map(([p])=>p)].filter(p=>{const u=ct(t,p,s);return u&&e(u[0],u[1])}),l=o.map(([p,u])=>zt(t,p,u,s)),i=(p,u)=>{const m=[];for(const{o:y,d:M}of l){const d=S(p,M);if(Math.abs(d)<1e-9)return null;const x=-(S(p,y)+u)/d;if(!(x>0))return null;m.push(U(y,j(M,x)))}return m};let c=null,f="points";if(r.length>=4){const p=r.map(y=>Math.hypot(...A(y,a.C))).sort((y,M)=>y-M)[r.length>>1],u=p*.015;let m=null;for(let y=0;y<r.length;y++)for(let M=y+1;M<r.length;M++)for(let d=M+1;d<r.length&&d<M+12;d++){let x=st(A(r[M],r[y]),A(r[d],r[y]));const g=Math.hypot(...x);if(g<1e-12)continue;x=j(x,1/g);const w=-S(x,r[y]);let b=0;for(const v of r)Math.abs(S(x,v)+w)<u&&b++;(!m||b>m.c)&&(m={n:x,d:w,c:b})}if(m&&m.c>=4){const y=r.filter(g=>Math.abs(S(m.n,g)+m.d)<u),M=j(y.reduce((g,w)=>U(g,w),[0,0,0]),1/y.length),d=[[0,0,0],[0,0,0],[0,0,0]];for(const g of y){const w=A(g,M);for(let b=0;b<3;b++)for(let v=0;v<3;v++)d[b][v]+=w[b]*w[v]}let x=Ft(d);S(x,A(a.C,M))<0&&(x=j(x,-1)),c={n:x,d:-S(x,M),count:y.length}}}if(!c){const p=o.reduce((d,x)=>d+x[0],0)/4,u=o.reduce((d,x)=>d+x[1],0)/4,m=Fe(t,p,u,s),y=t.floor?qe(t,p,u,s):null,M=Math.hypot(...A(m,a.C));if(y&&Math.abs(Math.hypot(...A(y,a.C))-M)<M*.12)c={n:t.floor.slice(0,3),d:t.floor[3],count:0},f="ground";else{const d=t.floor?t.floor.slice(0,3):Z(pt(a.R),[0,1,0]),x=A(a.C,m);let g=A(x,j(d,S(x,d)));Math.hypot(...g)<1e-9&&(g=x),g=et(g),c={n:g,d:-S(g,m),count:0},f="upright"}}const h=i(c.n,c.d);return h?{corners:h.map(p=>p.map(C)),n:c.n.map(C),d:C(c.d),count:c.count,by:f}:null}function dn(t,o,s,n=null){const e=o.crop||{left:0,right:0,top:0,bottom:0},a=1-e.left-e.right,r=1-e.top-e.bottom,l=[];for(const i of n??t.frames.map(c=>c[0])){const c=s.map(f=>ct(t,f,i));c.some(f=>!f)||l.push([+i.toFixed(4),...c.flatMap(([f,h])=>[C((f/t.w-e.left)/a),C((h/t.h-e.top)/r)]),1])}return l}function Mn(t,o,s,n){const e=o.crop||{left:0,right:0,top:0,bottom:0};return[(e.left+s*(1-e.left-e.right))*t.w,(e.top+n*(1-e.top-e.bottom))*t.h]}function Bt(t,o,s,n,e,a,r){const l=o.crop||{left:0,right:0,top:0,bottom:0},i=(s/t.w-l.left)/(1-l.left-l.right),c=(n/t.h-l.top)/(1-l.top-l.bottom),f=Jo(o,i,c,e,a,r,t.mw,t.mh);return[f.px,f.py]}function yn(t,o,s,n,e,a){const r=Math.max(t.start,o.start),l=Math.min(t.start+t.duration,o.start+o.duration);if(!(l>r))return{};const i=[],c=[],f=[r,...s.frames.map(p=>o.start+p[0]).filter(p=>p>r+1e-4&&p<l-1e-4),l];for(const p of f){const u=ct(s,n,p-o.start);if(!u)continue;const[m,y]=Bt(s,o,u[0],u[1],p-o.start,e,a),M=+(p-t.start).toFixed(4);i.push({time:M,value:C((m-e/2)/e)}),c.push({time:M,value:C((y-a/2)/a)})}if(!i.length)return{};let h={...t,motionV:2};return delete h.posX,delete h.posY,h={...h,...yt(h,"x",Mo(i,$.keyTolPx/e))},h={...h,...yt(h,"y",Mo(c,$.keyTolPx/a))},{motionV:2,motionKeys:h.motionKeys,posX:void 0,posY:void 0}}const Mo=(t,o)=>to(t.map(s=>s.time),t.map(s=>s.value),o,1/0).map(s=>t[s]);function Xe(t,o,s){if(!(s>0)||o.length<3)return o;const n=s*$.smoothFrames,e=Math.ceil(n*2.5),a=t.mode==="free",r=$.smoothTolPx,l=a?(t.points??[]).filter((h,p)=>p%Math.max(1,Math.floor((t.points?.length??0)/80))===0):[-.4,0,.4].flatMap(h=>[-.25,0,.25].map(p=>[h,p,-1])),i=(h,p)=>{const u=Z(h.R,a?A(p,h.C):Z(pt(o[0].R),p));return u[2]>-1e-6?null:[h.f*u[0]/-u[2],-h.f*u[1]/-u[2]]},c=(h,p)=>{let u=0,m=0;for(const y of l){const M=i(h,y),d=i(p,y);M&&d&&(u=Math.max(u,Math.hypot(M[0]-d[0],M[1]-d[1])),m++)}return m?u:0},f=o.map(h=>xo(h.R));return o.map((h,p)=>{let u=0,m=[0,0,0],y=[0,0,0,0],M=0;for(let b=Math.max(0,p-e);b<=Math.min(o.length-1,p+e);b++){const v=Math.exp(-((b-p)**2)/(2*n*n)),R=oo(f[b],f[p])<0?f[b].map(T=>-T):f[b];u+=v,m=U(m,j(o[b].C,v)),y=y.map((T,D)=>T+R[D]*v),M+=o[b].f*v}const d=b=>{const v=f[p].map((T,D)=>T+(y[D]/u-T)*b),R=Math.hypot(...v);return{R:go(v.map(T=>T/R)),C:U(h.C,j(A(j(m,1/u),h.C),b)),f:h.f+(M/u-h.f)*b}};let x=1,g=d(1),w=c(h,g);for(let b=0;b<6&&w>r;b++)x*=Math.max(.3,r/w*.95),g=d(x),w=c(h,g);return w>r?h:g})}function Yo(t,o,s,n){const e=Ho(s,n),a=lt(t,t.frames[0][0]),r=t.mode==="free",l=r&&t.floor?t.floor.slice(0,3):Z(pt(a.R),[0,1,0]),i=Z(pt(a.R),[0,0,-1]),c=[0,1,2].map(E=>{const I=(t.points??[]).map(V=>V[E]).sort((V,K)=>V-K);return I.length?I[I.length>>1]:a.C[E]+(r?0:i[E])}),f=r&&t.floor?A(c,j(t.floor.slice(0,3),S(t.floor.slice(0,3),c)+t.floor[3])):c,h=et(A(i,j(l,S(i,l)))),u=[st(j(l,-1),h),j(l,-1),h],m=8*e/Math.max(1e-9,Math.hypot(...A(a.C,f))),y=E=>j(Z(u,A(E,f)),m),M=Bt(t,o,t.w/2,t.h/2,0,s,n),d=Bt(t,o,t.w/2+10,t.h/2,0,s,n),x=Math.hypot(d[0]-M[0],d[1]-M[1])/10,g=[[1,0,0],[0,-1,0],[0,0,-1]],w=t.frames.filter(E=>E[0]>=-1e-6&&E[0]<=o.duration+1e-6),b=[],v={},R=(E,I)=>{if(E===void 0)return I;for(;I-E>180;)I-=360;for(;I-E<-180;)I+=360;return I},T=Xe(t,w.map(E=>lt(t,E[0])),t.smooth??0);for(const[E,I]of w.entries()){const V=T[E],K=po(po(u,pt(V.R)),g),k=y(V.C),B=Qo(K),mt=R(v.pan,B.pan),dt=R(v.roll,B.roll);v.pan=mt,v.roll=dt,b.push({time:+(o.start+I[0]).toFixed(4),cx:C(k[0]/s),cy:C(k[1]/n),cz:C(k[2]/e),pan:C(mt),tilt:C(B.tilt),roll:C(dt),zoom:C(V.f*x/(5*e))})}const D=5*e*(b[0]?.zoom??1),q=$.keyTolPx/D*180/Math.PI,O={cx:$.keyTolPx/s,cy:$.keyTolPx/n,cz:$.keyTolPx/e,pan:q,tilt:q,roll:q,zoom:$.keyTolPx/D},X=new Set;for(const[E,I]of Object.entries(O))for(const V of to(b.map(K=>K.time),b.map(K=>K[E]),I,1/0))X.add(V);return{camera:{enabled:!0,motionV:2,motionKeys:b.filter((E,I)=>X.has(I))},toTimeline:y,fromTimeline:E=>U(Z(pt(u),j(E,1/m)),f),M:u,k:m,U:e,first:a}}function Oe(t,o,s,n,e,{size:a=null,fill:r=1}={}){if(t.mode!=="free")throw Error("TRIPOD");const{camera:l,toTimeline:i,k:c,U:f,first:h}=Yo(t,o,n,e),p=(a??Math.hypot(...A(h.C,s))*.2)*c*r,u=i(s),m=A(i(h.C),u),y=Math.atan2(m[0],-m[2])*180/Math.PI;return{camera:l,place:{is3D:!0,posX:C(u[0]/n),posY:C(u[1]/e),spatialDepth:C(-u[2]/f),modelDepth:C(-u[2]/f),modelGround:!0,modelRotation:{x:0,y:C(y),z:0},scale:C(Math.max(1e-6,p/(1.8*f)))},toTimeline:i}}function Ne(t,o,s,n,e){const a=[];for(const[r,l]of eo(t,n)){const i=ct(t,r,n);if(i){const c=Math.hypot(i[0]-o,i[1]-s);c<=e&&a.push([l,c])}}return a.sort((r,l)=>r[1]-l[1]).map(r=>r[0])}function gn(t,o,s){if(!o.length)return null;const n=lt(t,s),e=t.mode==="free"?n.C:[0,0,0],a=h=>j(h.reduce((p,u)=>U(p,u),[0,0,0]),1/h.length);let r=o.map(h=>t.mode==="free"?h:et(h)),l=a(r),i=r,c="points";if(t.mode==="free"&&r.length<3){const h=ct(t,l,s),p=Math.hypot(...A(l,e));if(h){const u=Ne(t,h[0],h[1],s,t.w*.12).map(d=>t.points[d]).filter(d=>Math.abs(Math.hypot(...A(d,e))/p-1)<.25).slice(0,14),m=p*.02,y=r[0];let M=null;for(let d=0;d<u.length;d++)for(let x=d+1;x<u.length;x++){let g=st(A(u[d],y),A(u[x],y));const w=Math.hypot(...g);if(w<1e-12)continue;g=j(g,1/w);const b=u.filter(v=>Math.abs(S(g,A(v,y)))<m);r.every(v=>Math.abs(S(g,A(v,y)))<m)&&(!M||b.length>M.length)&&(M=b)}M&&M.length>=3&&(i=[...r,...M],c="around")}}let f=null;if(t.mode==="free"&&i.length>=3){if(c==="points"&&i.length>=6){const u=Math.hypot(...A(l,e)),m=u*.01,y=bo(31);let M=null;for(let d=0;d<300;d++){const x=i[Math.floor(y()*i.length)],g=i[Math.floor(y()*i.length)],w=i[Math.floor(y()*i.length)];let b=st(A(g,x),A(w,x));const v=Math.hypot(...b);if(v<1e-12)continue;b=j(b,1/v);const R=i.filter(T=>Math.abs(S(b,A(T,x)))<m);(!M||R.length>M.length)&&(M=R)}M&&M.length>=Math.max(3,i.length*.5)&&(i=M)}const h=a(i),p=[[0,0,0],[0,0,0],[0,0,0]];for(const u of i){const m=A(u,h);for(let y=0;y<3;y++)for(let M=0;M<3;M++)p[y][M]+=m[y]*m[M]}f=Ft(p),c!=="around"&&(l=h)}return f||(f=et(A(e,l)),c="facing"),S(f,A(e,l))<0&&(f=j(f,-1)),{center:l.map(C),n:f.map(C),radius:C(Math.hypot(...A(l,e))*.08),by:c}}function bn(t,o=t.radius,s=36){const n=t.n,e=et(Math.abs(n[1])<.9?st(n,[0,1,0]):st(n,[1,0,0])),a=st(n,e);return Array.from({length:s},(r,l)=>{const i=l/s*2*Math.PI;return U(t.center,U(j(e,o*Math.cos(i)),j(a,o*Math.sin(i))))})}const Le=["x","y","depth","zoom","rot","tiltX","tiltY"];function xn(t,o,s,n,e,a,{width:r=null}={}){if(t.kind==="model"){const{camera:P,place:E}=Oe(o,s,n.center,e,a,{size:n.radius*2});if(!(E.spatialDepth>=so&&E.spatialDepth<=ro))throw Error("FAR");return{camera:P,patch:E}}const{camera:l,toTimeline:i,M:c,k:f,U:h,first:p}=Yo(o,s,e,a),u=i(n.center),m=et(Z(c,n.n)),y=i(o.mode==="free"?lt(o,o.frames[0][0]).C:p.C),M=-u[2]/h;if(!(M>=so&&M<=ro))throw Error("FAR");const d=P=>A(P,j(m,S(P,m)));let x=Math.abs(m[1])<.85?d([0,1,0]):d(A(y,u));Math.hypot(...x)<1e-6&&(x=d([0,1,0])),x=et(x);const g=j(m,-1),w=st(x,g),b=Math.asin(Math.max(-1,Math.min(1,g[1]))),v=Math.atan2(-g[0],g[2]),R=[Math.cos(v),0,Math.sin(v)],T=[Math.sin(b)*Math.sin(v),Math.cos(b),-Math.sin(b)*Math.cos(v)],D=Math.atan2(S(w,T),S(w,R)),q=P=>C(P*180/Math.PI);let O={...t,motionV:2};for(const P of Le)(O.motionKeys??[]).some(E=>E[P]!==void 0)&&(O={...O,motionKeys:Zo(O,P,[])});const X=(r??n.radius*6)*f;return{camera:l,patch:{is3D:!0,motionV:2,motionKeys:O.motionKeys??[],posX:C(u[0]/e),posY:C(u[1]/a),spatialDepth:C(M),scale:C(Math.max(1e-4,X/e)),rotation:q(D),tiltX:q(b),tiltY:q(v)}}}const $o=24e3,xt=new WeakMap,Ut=new Map;function Nt(t){let o=xt.get(t);if(!o){const s=JSON.stringify(t);o=s.length<=$o?Promise.resolve(null):re(s).then(n=>(Ut.set(n,t),n)),o.catch(()=>xt.delete(t)),xt.set(t,o)}return o}async function Ye(t){return Promise.all(t.map(async o=>{let s=o;const n=o.mask;if(n&&n.v===2&&!vo(n)){const r=await Nt(n);r&&(s={...s,mask:{v:2,mw:n.mw,mh:n.mh,ref:r}})}const e=o.planar;if(e&&!Yt(e)){const r=await Nt(e);r&&(s={...s,planar:{v:1,mw:e.mw,mh:e.mh,ref:r}})}const a=o.sceneTrack;if(a&&!_t(a)){const r=await Nt(a);r&&(s={...s,sceneTrack:{v:1,mode:a.mode,w:a.w,h:a.h,mw:a.mw,mh:a.mh,ref:r,...a.key?{key:a.key}:{}}})}return s}))}async function Lt(t){const o=Ut.get(t);if(o)return o;const s=JSON.parse(await ae(t));return Ut.set(t,s),s}async function $e(t){let o=0;return{clips:await Promise.all(t.map(async n=>{let e=n;const a=n.mask;if(vo(a))try{const i=ne(await Lt(a.ref),n.duration);if(i.v!==2||!("masks"in i))throw Error("Invalid mask");xt.set(i,Promise.resolve(a.ref)),e={...e,mask:i}}catch{o++}const r=n.planar;if(Yt(r))try{const i=se(await Lt(r.ref),n.duration);if(Yt(i))throw Error("Invalid planar track");xt.set(i,Promise.resolve(r.ref)),e={...e,planar:i}}catch{o++}const l=n.sceneTrack;if(_t(l))try{const i=je(await Lt(l.ref));if(_t(i))throw Error("Invalid scene track");xt.set(i,Promise.resolve(l.ref)),e={...e,sceneTrack:{...i,...l.key?{key:l.key}:{}}}}catch{o++}return e})),missing:o}}const wn=Object.freeze(Object.defineProperty({__proto__:null,MASK_INLINE_MAX:$o,packMasks:Ye,unpackMasks:$e},Symbol.toStringTag,{value:"Module"}));export{Ae as A,Mn as B,to as C,an as D,lt as E,qe as F,Je as G,Fe as H,De as I,Ne as J,fn as K,hn as L,we as M,ue as N,ie as O,xe as P,ce as Q,le as R,$ as S,Be as T,Oe as U,yn as V,Ue as W,wn as X,dn as a,un as b,gn as c,Yo as d,xn as e,Bt as f,ct as g,bn as h,ln as i,rn as j,nn as k,We as l,sn as m,He as n,cn as o,Ye as p,en as q,on as r,mn as s,pn as t,$e as u,tn as v,Ze as w,Qe as x,Ge as y,jo as z};
@@ -1 +0,0 @@
1
- import{t as e,b as u,h}from"./api-CJ8PdbfZ.js";import{i7 as p}from"./remote-C7J0Tqhb.js";import"./titleFrameBudget-CLZWaFHO.js";import"./three.module-Bx43vjkH.js";import"./GLTFLoader-BHWu1lKg.js";import"./store-DW4E9xnW.js";import"./rotoMaskStore-DPziPKAN.js";import"./textAnimators-DUZjhVGO.js";import"./timelineComp-B4GtoH2f.js";import"./rigTrack-urT3nDK0.js";const a=new Map,s=n=>new Promise(r=>setTimeout(r,n));async function m(n){for(let r=0;r<100;r++){const o=await u(n,!0).catch(t=>{if(r<20)return null;throw t});if(!o){await s(3e3);continue}if(o.status==="failed")throw Error(e("Vẽ Animation không thành công (credit đã được hoàn)"));if(o.status==="succeeded"&&o.output?.url){const t=await fetch(o.output.url);if(!t.ok)throw Error(e("Không tải được hình vẽ"));return t.json()}await s(3e3)}throw Error(e("Vẽ Animation quá lâu — thử lại sau"))}async function V(n,r){const o=r.params??{},t=o.job;if(!t)throw Error(e("Thiếu job Vẽ Animation"));let i=a.get(t);i||(i=m(t),a.set(t,i),i.catch(()=>a.delete(t)));const c=await i;return p(c,o,{en:h()==="en"})}export{V as runRotoscope};
@@ -1 +0,0 @@
1
- import"./titleFrameBudget-CLZWaFHO.js";import{R as _}from"./api-CJ8PdbfZ.js";import{dt as N,du as T,n as I,dv as L,c as C,ds as A,dw as b}from"./remote-C7J0Tqhb.js";import j from"./ShotComposer-0DUtMTVI.js";import{u as B}from"./store-DW4E9xnW.js";import"./three.module-Bx43vjkH.js";import"./GLTFLoader-BHWu1lKg.js";import"./rotoMaskStore-DPziPKAN.js";import"./textAnimators-DUZjhVGO.js";import"./timelineComp-B4GtoH2f.js";import"./rigTrack-urT3nDK0.js";import"./RoomEnvironment-Dmv_G5ka.js";import"./tool-DktQYmS6.js";import"./timelineProps-D7MVutxu.js";import"./thumb-CS0ZuiGS.js";import"./shotFxAgent-BFLkqs8v.js";import"./cameraPresets-CYw0OdM3.js";import"./weaponDuel-ZhX-tjGZ.js";import"./skin-DY4QLaBI.js";import"./views-ozVF4ABO.js";import"./motionBlur-uAm030t9.js";import"./library-BufgA-Pl.js";globalThis.__CLIPOOX_THUMB_LIMIT=0;const w="shot-worker";let E=null,i=null,F=0;const S=(t,o)=>window.shotWorkerRpc?window.shotWorkerRpc(t,o):Promise.reject(new Error("no account bridge")),O=t=>({...t,saveSet:(o,a,r)=>S("saveSet",{id:o,name:a,recipe:r}),loadSet:async o=>await S("loadSet",{id:o}),listLibrary:async()=>await S("listLibrary",{}),uploadFile:async()=>{throw new Error("uploads are not available to the 3D Shot worker")}}),P=async(t,o,a)=>{const r=Date.now()+o;for(;!t();){if(Date.now()>r)throw new Error(`${a} timed out`);await new Promise(e=>setTimeout(e,50))}},x=()=>{const t=b();if(!t)throw new Error("no scene open");return t},U={async open(t,o,a={}){t||(t=I(),t.items=[]),L(a.regionClips===!0),B.setState({user:{uid:o},saveState:"saved"}),i={id:w,type:"placeholder",position:{x:0,y:0},data:{tool:"3d-shot",label:"3D Shot",shotScene:t}},C.current={nodes:()=>i?[i]:[],getNode:e=>e===w?i:void 0,addNode:()=>"",updateNodeData:(e,n)=>{i&&e===w&&(i.data={...i.data,...n})}};const r=b();return E??=A.createRoot(document.getElementById("root")),E.render(_.createElement(j,{key:++F,nodeId:w,headless:!0})),await P(()=>{const e=b();return!!e&&e!==r&&!!e.engine()},6e4,"opening the scene"),{ok:!0}},async run(t){const o=[];for(const a of t){let r;try{r=await N(a.tool,a.args||{},O(x()))}catch(c){r={ok:!1,error:String(c?.message||c).slice(0,500)}}const{_image:e,...n}=r;if(o.push({tool:a.tool,ok:r.ok!==!1,result:T(n),...typeof e=="string"?{image:e}:{}}),r.ok===!1)break}return o},stage:()=>x().getStage(),async clip(t={}){const o=x(),a=o.engine(),r=o.getStage(),e=r.shots.find(h=>h.id===r.activeShot);if(!a||!e)throw new Error("renderer not ready");const n=Math.max(2,Math.min(12,Number(t.fps)||8)),c=Math.max(.25,Math.min(4,Number(t.seconds)||2)),g=Math.max(0,Math.min(e.duration,Number(t.from)||0)),R=Math.max(1,Math.min(48,Math.round(c*n))),d=Array.from({length:R},(h,l)=>Math.min(e.duration,g+l/n));a.sync(r,null);const m=await a.renderFrames(e,d,Math.max(180,Math.min(480,Number(t.height)||270)),t.quality==="high"?"high":"draft");if(!t.sheet)return{fps:n,from:g,times:d,frames:m.map(h=>h.toDataURL("image/jpeg",.7))};const p=Math.min(4,m.length),D=Math.ceil(m.length/p),k=m[0].width,u=m[0].height,f=document.createElement("canvas");f.width=p*k,f.height=D*u;const s=f.getContext("2d");return s.font=`${Math.max(12,Math.round(u/14))}px sans-serif`,s.textBaseline="top",m.forEach((h,l)=>{const y=l%p*k,M=Math.floor(l/p)*u;s.drawImage(h,y,M);const v=`${d[l].toFixed(2)} s`;s.fillStyle="rgba(0,0,0,0.55)",s.fillRect(y+4,M+4,s.measureText(v).width+8,Math.round(u/14)+6),s.fillStyle="#fff",s.fillText(v,y+8,M+7)}),{fps:n,from:g,times:d,sheet:f.toDataURL("image/jpeg",.72)}}};window.__shotWorker=U;
@@ -1,2 +0,0 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/remote-C7J0Tqhb.js","assets/api-CJ8PdbfZ.js","assets/titleFrameBudget-CLZWaFHO.js","assets/three.module-Bx43vjkH.js","assets/GLTFLoader-BHWu1lKg.js","assets/store-DW4E9xnW.js","assets/rotoMaskStore-DPziPKAN.js","assets/textAnimators-DUZjhVGO.js","assets/timelineComp-B4GtoH2f.js","assets/rigTrack-urT3nDK0.js"])))=>i.map(i=>d[i]);
2
- import{_ as U}from"./titleFrameBudget-CLZWaFHO.js";import{jp as st,iY as Q,fq as W,gM as v,dH as D,fs as B,hG as Y,fD as J,fE as R,ft as rt,jq as pt,iR as at,fF as nt,fG as dt,fw as mt,hD as ut}from"./remote-C7J0Tqhb.js";import{c as ct}from"./cameraPresets-CYw0OdM3.js";import"./api-CJ8PdbfZ.js";import"./three.module-Bx43vjkH.js";import"./GLTFLoader-BHWu1lKg.js";import"./store-DW4E9xnW.js";import"./rotoMaskStore-DPziPKAN.js";import"./textAnimators-DUZjhVGO.js";import"./timelineComp-B4GtoH2f.js";import"./rigTrack-urT3nDK0.js";const gt=s=>{let l=Math.abs(Math.floor(s))%2147483646+1;return()=>(l=l*16807%2147483647)/2147483647},z=s=>st(s)?.keys.find(l=>l.strike)?.t??.4,it={"xx-palm-shield":.22,"xx-teleport":.26,"xx-float-back":.3},L=Object.freeze({palm:{clip:"xx-palm-strike",fx:"chuong-luc",twin:"chuong-luc",kind:"path",travel:.32,power:1},twin:{clip:"xx-double-palm",fx:"cau-nang-luong",twin:"cau-nang-luong",kind:"path",travel:.5,power:2},sword:{clip:"xx-sword-command",fx:"phi-kiem",twin:"phi-kiem-vang",kind:"path",travel:.42,power:1},volley:{clip:"xx-hand-seals",fx:"van-kiem",twin:"van-kiem",kind:"path",travel:.6,power:3},wave:{clip:"xx-sleeve-sweep",fx:"tram-nguyet",twin:"tram-nguyet-tim",kind:"wave",travel:.4,power:2},spin:{clip:"xx-spin-palm",fx:"chuong-luc",twin:"chuong-luc",kind:"path",travel:.32,power:1},lightning:{clip:"xx-call-lightning",fx:"loi-kiep",twin:"loi-kiep",kind:"sky",travel:.18,power:3},palmSky:{clip:"xx-ground-seal",fx:"cu-chuong-vang",twin:"cu-chuong-tim",kind:"sky",travel:.8,power:3},dragon:{clip:"xx-sword-command",fx:"loi-long-lam",twin:"loi-long-tim",kind:"path",travel:.7,power:3}}),F=Object.freeze({shield:{clip:"xx-palm-shield",fx:"khien-nang-luong",result:"blocked"},blink:{clip:"xx-teleport",fx:"dich-chuyen",result:"evaded"},float:{clip:"xx-float-back",fx:null,result:"evaded"}}),xt=["lightning","volley","twin","wave","palmSky","dragon"];function lt({exchanges:s=5,seed:l=1,rush:j=!0}={}){const S=gt(l),u=Math.max(2,Math.min(8,Math.round(s))),a=[],c=$=>$[Math.floor(S()*$.length)];let o=2.3;const K={seals:0,until:o};let h=0,P=null;for(let $=0;$<u;$++){const q=$===u-1;if(j&&!q&&$===Math.floor(u/2)){const p=st("xx-air-dash"),_=o+p.duration-.2+z("xx-sky-slam");a.push({time:o,attacker:h,technique:"rush",clip:"xx-air-dash",then:"xx-sky-slam",thenAt:o+p.duration-.2,fx:"xung-kich",kind:"ground",travel:0,impact:_,defence:"float",defenceClip:F.float.clip,defenceAt:_-it["xx-float-back"],defenceFx:null,result:"evaded"}),o=_+1,h=1-h;continue}const w=c(q?xt:Object.keys(L).filter(p=>p!==P&&p!=="volley"&&p!=="palmSky"));P=w;const x=L[w],I=o+z(x.clip),C=I+x.travel,y=S();let M=null,b="hit";q||(y<.28&&x.kind==="path"?b="clash":(M=y<.62?"shield":y<.84?"blink":"float",b=F[M].result));const T={time:o,attacker:h,technique:w,clip:x.clip,fx:h?x.twin:x.fx,kind:x.kind,travel:x.travel,release:I,impact:C,result:b};if(M&&Object.assign(T,{defence:M,defenceClip:F[M].clip,defenceAt:C-it[F[M].clip],defenceFx:F[M].fx}),b==="clash"){const p=L[c(["palm","twin","sword"])],_=I+x.travel/2,i=_-p.travel/2;Object.assign(T,{counter:{clip:p.clip,fx:h?p.fx:p.twin,start:i-z(p.clip),release:i,travel:p.travel/2},impact:_})}a.push(T);const A=b==="blocked"||b==="evaded";o=Math.max(C,T.defenceAt!=null?T.defenceAt+.9:C)+(A?.25+S()*.25:.6+S()*.5),h=A&&S()<.7||S()<.5?1-h:h}const d=a[a.length-1];return{opening:K,beats:a,end:d.impact+1.6}}const ft=Object.freeze([{id:"phap-tuong",name:"Pháp tướng kim thân",nameEn:"Golden dharma avatar",clip:"xx-summon-avatar",role:"buff",effects:[{fx:"phap-tuong-vang",at:"start",offset:.6,place:"self",duration:4}]},{id:"linh-thuong",name:"Huyết linh thương",nameEn:"Crimson spear of light",clip:"xx-conjure-spear",role:"attack",hit:.4,effects:[{fx:"linh-thuong-do",at:"release",offset:-.6,place:"path",duration:1.4}]},{id:"kim-diem",name:"Kim diễm hộ thể",nameEn:"Golden flame aura",clip:"xx-flame-surge",role:"buff",effects:[{fx:"kim-diem",at:"release",offset:-.1,place:"self",duration:2.5}]},{id:"an-xoay",name:"Phong ấn xoay",nameEn:"Spinning seal",clip:"xx-throw-seal",role:"attack",hit:.6,effects:[{fx:"an-xoay-vang",at:"release",place:"path",duration:1.2}]},{id:"that-tinh",name:"Thất tinh phong ấn",nameEn:"Seven-star seal",clip:"xx-seven-star",role:"control",hit:.4,effects:[{fx:"that-tinh-an",at:"start",offset:.2,place:"target",duration:2}]},{id:"cu-kiem",name:"Cự kiếm khai thiên",nameEn:"Heaven-cleaving sword",clip:"xx-heaven-cleave",role:"attack",hit:.3,effects:[{fx:"cu-kiem-khai-thien",at:"release",offset:-.8,place:"self",duration:2.2}]},{id:"hu-khong-chi",name:"Hư không chỉ",nameEn:"Void-piercing finger",clip:"xx-void-finger",role:"attack",hit:.08,effects:[{fx:"chi-quang",at:"release",place:"path",duration:.9}]},{id:"long-hong",name:"Long hống",nameEn:"Dragon's roar",clip:"xx-dragon-roar",role:"attack",hit:.4,effects:[{fx:"long-hong",at:"release",place:"self",duration:1.6}]},{id:"bat-quai",name:"Bát quái chưởng",nameEn:"Bagua palm",clip:"xx-bagua-palm",role:"attack",hit:.35,effects:[{fx:"bat-quai",at:"start",place:"self",duration:2.2},{fx:"chuong-luc",at:"release",place:"path",duration:.7}]},{id:"hon-ky",name:"Chiêu hồn kỳ",nameEn:"Soul banner",clip:"xx-plant-banner",role:"buff",effects:[{fx:"hon-ky",at:"release",place:"self",duration:4}]},{id:"kiem-y-mua",name:"Kiếm ý trong mưa",nameEn:"Sword intent in the rain",clip:"xx-rain-sword-intent",role:"attack",hit:.4,effects:[{fx:"kiem-vu-lam",at:"release",place:"area",duration:2}]},{id:"lien-hoa-chuong",name:"Liên hoa chưởng",nameEn:"Lotus palm",clip:"xx-lotus-palm",role:"attack",hit:.6,effects:[{fx:"lien-hoa-tim",at:"release",place:"target",duration:2,params:{dist:0,height:1.2,size:.8}}]},{id:"loi-long",name:"Lôi long xuất hải",nameEn:"Lightning dragon",clip:"xx-dragon-call",role:"attack",hit:.7,effects:[{fx:"loi-long-lam",at:"release",place:"path",duration:1.2}]},{id:"don-quang",name:"Hoá độn quang",nameEn:"Escape light",clip:"xx-escape-light",role:"escape",effects:[{fx:"don-quang-cau-vong",at:"release",place:"ahead",ahead:6,duration:.8}]},{id:"kiem-luan-tram",name:"Kiếm luân trảm",nameEn:"Sword-halo slash",clip:"xx-halo-slash",role:"attack",hit:.45,effects:[{fx:"kiem-luan-lam",at:"start",place:"self",duration:1.6},{fx:"tram-nguyet",at:"release",place:"self",duration:1}]},{id:"thai-cuc",name:"Thái cực hoá giải",nameEn:"Taiji deflection",clip:"xx-taiji-deflect",role:"defence",effects:[{fx:"thai-cuc-trang",at:"start",place:"self",duration:1.6}]},{id:"huyet-ma",name:"Huyết ma công",nameEn:"Blood art",clip:"xx-blood-art",role:"buff",effects:[{fx:"huyet-vu",at:"start",place:"self",duration:2.4},{fx:"to-khi-do",at:"release",place:"self",duration:1.5}]},{id:"thien-quang",name:"Thỉnh thiên quang",nameEn:"Heavenly light",clip:"xx-heaven-light",role:"attack",hit:.25,effects:[{fx:"thien-quang-vang",at:"release",place:"target",duration:1.6}]},{id:"tran-ap",name:"Trấn áp chưởng",nameEn:"Suppressing palm",clip:"xx-suppress-palm",role:"attack",hit:.5,effects:[{fx:"cu-chuong-vang",at:"release",offset:-.3,place:"target",duration:1.6,params:{dist:0}}]},{id:"phu-chu",name:"Phóng phù chú",nameEn:"Talisman volley",clip:"xx-talisman-cast",role:"attack",hit:.6,effects:[{fx:"phu-chu-vang",at:"start",place:"self",duration:.6},{fx:"an-xoay-tim",at:"release",place:"path",duration:1.2}]},{id:"bang-quang-tu-luc",name:"Băng quang tụ lực",nameEn:"Ice-light charge",clip:"xx-power-burst",role:"buff",effects:[{fx:"bang-quang-tu",at:"start",offset:.1,place:"self",duration:2}]},{id:"bang-nguyet-tram",name:"Băng nguyệt trảm",nameEn:"Ice crescent slash",clip:"xx-backhand-slash",role:"attack",hit:.15,effects:[{fx:"nguyet-tram-bang",at:"release",offset:-.08,place:"self",duration:1.2},{fx:"tinh-bao-bang",at:"release",offset:.15,place:"target",duration:1.6}]},{id:"bang-thich-lan",name:"Băng thích lan",nameEn:"Ice spike surge",clip:"xx-ground-seal",role:"attack",hit:.7,effects:[{fx:"gai-bang-lan",at:"release",place:"ground",duration:2.4}]},{id:"bang-quang-phao",name:"Băng quang pháo",nameEn:"Ice-light cannon",clip:"xx-double-palm",role:"attack",hit:.2,effects:[{fx:"bang-quang-tu",at:"start",place:"self",duration:.9,params:{size:.8}},{fx:"bang-quang-phao",at:"release",place:"path",duration:1.6},{fx:"tinh-bao-bang",at:"release",offset:.2,place:"target",duration:1.6}]},{id:"hoa-bang-ho-the",name:"Hoa băng hộ thể",nameEn:"Ice flower guard",clip:"xx-palm-shield",role:"defence",effects:[{fx:"hoa-bang-ho-the",at:"release",offset:-.1,place:"self",duration:2.6}]},{id:"thien-kiem-giang",name:"Thiên kiếm giáng",nameEn:"Sky sword descends",clip:"xx-call-lightning",role:"attack",hit:.95,effects:[{fx:"thanh-truc-thien-kiem",at:"release",offset:-.6,place:"area",duration:4.5}]}]),kt=s=>ft.find(l=>l.id===s)??null,wt=Object.freeze(Object.defineProperty({__proto__:null,DEFENCES:F,TECHNIQUES:L,XIANXIA_SETS:ft,planSpellDuel:lt,releaseAt:z,xianxiaSet:kt},Symbol.toStringTag,{value:"Module"})),N=()=>crypto.randomUUID(),E=s=>Math.round(s*100)/100,Z=s=>s*Math.PI/180,ot=s=>(s.kind==="model"?(s.model?.height??2)/1.8:ut(s))*(s.scale[1]||1);function tt(s,l){const j=v(s),S=j.duration/l,u=c=>c?.map(o=>({...o,time:Math.min(1,o.time*S)})),a={...j,duration:l,cameraKeys:u(j.cameraKeys)??[],objectKeys:Object.fromEntries(Object.entries(j.objectKeys||{}).map(([c,o])=>[c,u(o)||[]])),...j.flight?{flight:Object.fromEntries(Object.entries(j.flight).map(([c,o])=>[c,u(o)||[]]))}:{}};return{...s,shots:s.shots.map(c=>c.id===j.id?a:c)}}async function At(s,l){const j=l.getStage(),S=Array.isArray(s.fighters)?s.fighters.map(String):[];if(S.length!==2)return{ok:!1,error:"give fighters: [first caster, opponent] (two person names)"};let u;try{u=S.map(t=>Q(j,t))}catch(t){return{ok:!1,error:t.message}}for(const t of u)if(!W(t))return{ok:!1,error:`'${t.name}' is not a person (or a humanoid-rigged model)`};if(u[0].id===u[1].id)return{ok:!1,error:"two different people are needed"};const a=Math.max(0,Number(s.start??0)||0),c=lt({exchanges:Number(s.exchanges??5)||5,seed:Number(s.seed)||1,rush:s.rush!==!1});try{await pt(["mc-react-fall-back"])}catch{}let o=j;const K=a+c.end;K>v(o).duration&&(o=tt(o,Math.min(300,Math.ceil(K*10)/10)));const h=v(o).duration,P=v(o),d=D(u[0],{...P,flight:void 0},a/h),$=(ot(u[0])+ot(u[1]))/2,q=Math.max(3,Math.min(14,Number(s.distance)||7))*$,w=d.rotation[1],x=[Math.sin(Z(w)),Math.cos(Z(w))],I=[d.position[0]+x[0]*q,d.position[1],d.position[2]+x[1]*q],C=(t,e,n)=>{const r=v(o),f=(r.objectKeys?.[t]||[]).filter(g=>g.time*h<a-1e-6);o={...o,shots:o.shots.map(g=>g.id===r.id?{...g,objectKeys:{...g.objectKeys,[t]:[...f,{id:N(),time:a/h,position:e.map(k=>+k.toFixed(3)),rotation:[0,+n.toFixed(1),0],scale:o.items.find(k=>k.id===t).scale}]}}:g)}};if(C(u[0].id,d.position,w),C(u[1].id,I,w+180),s.air===!0){const t=v(o),e=Math.max(1.5,Math.min(20,Number(s.height)||3));for(const n of u){let r=at(t.flight?.[n.id],{time:a/h,on:!0,height:e,ground:d.position[1]});r=at(r,{time:Math.min(1,(a+c.end-.2)/h),on:!1}),o={...o,shots:o.shots.map(f=>f.id===t.id?{...f,flight:{...f.flight,[n.id]:r}}:f)}}}const y=[{who:0,clip:"xx-hand-seals",at:0},{who:1,clip:"xx-stand-calm",at:0}];for(const t of c.beats)y.push({who:t.attacker,clip:t.clip,at:t.time}),t.then&&y.push({who:t.attacker,clip:t.then,at:t.thenAt}),t.defenceClip&&y.push({who:1-t.attacker,clip:t.defenceClip,at:t.defenceAt}),t.counter&&y.push({who:1-t.attacker,clip:t.counter.clip,at:t.counter.start});const M=c.beats[c.beats.length-1];y.push({who:1-M.attacker,clip:B("mc-react-fall-back")?"mc-react-fall-back":"fist-hit",at:M.impact}),y.sort((t,e)=>t.at-e.at);const b=[];for(const t of y){const e=B(t.clip);if(!e){b.push(`missing clip ${t.clip}`);continue}const n=Y(o,u[t.who].id,e,{start:Math.max(0,a+t.at)/h,newId:N,loop:!1});n.ok?o=n.stage:b.push(`${u[t.who].name} ${t.clip}: ${n.error}`)}l.setStage(()=>o);const{runTool:T}=await U(async()=>{const{runTool:t}=await import("./remote-C7J0Tqhb.js").then(e=>e.jA);return{runTool:t}},__vite__mapDeps([0,1,2,3,4,5,6,7,8,9])),A=[],p=async t=>{const e=await T("add_effect",t,l);e.ok?A.push(String(t.effect)):b.push(`${String(t.effect)}: ${String(e.error)}`)},_=t=>u[t].name;if(s.vfx!==!1){await p({effect:["hao-quang-lam","hao-quang-tim"][0],attach_to:_(0),start:a+.1,duration:c.opening.until,intensity:.55}),await p({effect:"phap-tran",attach_to:_(0),start:a+.3,duration:c.opening.until,intensity:.5}),s.ambience!==!1&&await p({effect:"dom-linh-vang",at:[(d.position[0]+I[0])/2,1.2,(d.position[2]+I[2])/2],start:a,duration:c.end,intensity:.5});for(const e of c.beats){const n=_(e.attacker),r=_(1-e.attacker),f=a+(e.release??e.time);if(e.kind==="path"?await p({effect:e.fx,from:`${n}.hand_right`,to:`${r}.chest`,start:f,duration:(e.counter?e.travel/2+.05:e.travel)+.3,intensity:.75}):e.kind==="sky"?await p(e.fx.startsWith("cu-chuong")?{effect:e.fx,attach_to:r,start:f,duration:e.travel+.6,intensity:.7,params:{dist:0,fall:e.travel}}:{effect:e.fx,from:`${n}.hand_right`,to:`${r}.chest`,start:a+e.impact-.12,duration:.6,intensity:.6}):e.kind==="wave"?await p({effect:e.fx,attach_to:n,start:f,duration:e.travel+.5,intensity:.7}):e.kind==="ground"&&(await p({effect:"xung-kich",attach_to:n,start:a+e.impact,duration:.7,intensity:.45}),await p({effect:"mat-dat-vo",attach_to:n,start:a+e.impact,duration:1.2,intensity:.5})),e.technique==="rush"&&await p({effect:"luot-chem-loi",attach_to:n,start:a+e.time+.1,duration:.6,intensity:.6}),e.defenceFx&&await p({effect:e.defenceFx,attach_to:r,start:a+e.defenceAt,duration:.7,intensity:.6}),e.result==="blocked"&&await p({effect:"vong-xung-kich",attach_to:r,start:a+e.impact,duration:.35,intensity:.4}),e.counter){await p({effect:e.counter.fx,from:`${r}.hand_right`,to:`${n}.chest`,start:a+e.counter.release,duration:e.counter.travel+.25,intensity:.75});const g=v(l.getStage()),k=D(u[0],g,(a+e.impact)/g.duration).position,H=D(u[1],g,(a+e.impact)/g.duration).position;await p({effect:"vong-xung-kich",at:[(k[0]+H[0])/2,(k[1]+H[1])/2+1.3*$,(k[2]+H[2])/2],start:a+e.impact,duration:.6,intensity:.65})}e.result==="hit"&&await p({effect:"hoa-loi",attach_to:r,start:a+e.impact,duration:.6,intensity:.5})}}if(s.timing!==!1){const t=v(l.getStage());let e=rt(t.timing,t.duration);e=J(e,c.beats.filter(n=>n.result==="blocked"||n.result==="clash").map(n=>a+n.impact),R.light,t.duration),e=J(e,[a+M.impact],R.heavy,t.duration);for(const n of c.beats.filter(r=>r.result==="clash"))e=nt(e,a+n.impact,.25,.4,t.duration);e=nt(e,a+M.impact-.05,.3,.3,t.duration),l.setStage(n=>({...n,shots:n.shots.map(r=>r.id===t.id?{...r,timing:e??void 0}:r)}))}let i=null;if(s.camera!==!1&&s.director_camera!==!1){const t=[["orbit-180",0,a,a+c.opening.until]];c.beats.forEach((n,r)=>{const f=c.beats[r+1],g=a+(n.release??n.thenAt??n.time),k=f?a+f.time:a+c.end;t.push(["low-hero",n.attacker,a+n.time,Math.max(a+n.time+.3,g-.05)]),t.push([f?"wide-track":"crash-zoom",f?n.attacker:1-n.attacker,Math.max(a+n.time+.3,g-.05),k])});const e=[];for(const[n,r,f,g]of t){if(g-f<.25)continue;const k=ct(l.getStage(),{preset:n,subject:u[r].id,start:f,end:g});k.ok&&(l.setStage(()=>k.stage),e.push(`${n} ${E(f)}–${E(g)} s on ${u[r].name}`))}i={director:e}}else if(s.camera!==!1)try{const t=dt(l.getStage(),{fighters:S,start:a,end:a+c.end,focal_length_mm:Number(s.focal_length_mm)||28});l.setStage(()=>t.stage),i=t.result}catch(t){i={error:t.message}}const m=v(l.getStage());return{ok:!0,fighters:S,distance_m:E(q),opening_until_s:E(a+c.opening.until),exchange:c.beats.map(t=>({time_s:E(a+t.time),caster:_(t.attacker),technique:t.technique,impact_s:E(a+t.impact),result:t.result,...t.defence?{defence:t.defence}:{}})),effects:A.length,shot_s:m.duration,video_s:E(mt(m)),...b.length?{notes:b.slice(0,12)}:{},...i?{camera:i}:{},hint:"tune any effect with update_effect (colour, size); camera_preset for wide-track / low-hero shots; set_character for robes and hair"}}async function It(s,l){const{xianxiaSet:j,releaseAt:S,XIANXIA_SETS:u}=await U(async()=>{const{xianxiaSet:i,releaseAt:m,XIANXIA_SETS:t}=await Promise.resolve().then(()=>wt);return{xianxiaSet:i,releaseAt:m,XIANXIA_SETS:t}},void 0),a=j(String(s.technique??""));if(!a)return{ok:!1,error:`unknown technique; use one of ${u.map(i=>i.id).join(", ")}`};const c=l.getStage();let o;try{o=Q(c,String(s.name??""))}catch(i){return{ok:!1,error:i.message}}if(!W(o))return{ok:!1,error:`'${o.name}' is not a person`};const K=v(c),h=Math.max(0,Number(s.time??0)||0),P=Math.min(1,h/K.duration);let d=null;if(s.target!=null)try{d=Q(c,String(s.target))}catch(i){return{ok:!1,error:i.message}}else{const i=D(o,K,P).position;d=c.items.filter(m=>m.id!==o.id&&W(m)&&!m.hidden).map(m=>{const t=D(m,K,P).position;return{i:m,d:Math.hypot(t[0]-i[0],t[2]-i[2])}}).sort((m,t)=>m.d-t.d)[0]?.i??null}const $=a.effects.some(i=>i.place==="target"||i.place==="path"||i.place==="area"||i.place==="ground");if($&&!d)return{ok:!1,error:`${a.name} needs a target (another person in the scene, or give target)`};const q=B(a.clip);if(!q)return{ok:!1,error:`the clip ${a.clip} is missing`};let w=c;q.duration+h>K.duration&&(w=tt(w,Math.min(300,Math.ceil((h+q.duration+.5)*10)/10)));const x=v(w).duration;if(d){const i=v(w),m=D(o,{...i,flight:void 0},Math.min(1,h/x)),t=D(d,i,Math.min(1,h/x)).position,e=Math.atan2(t[0]-m.position[0],t[2]-m.position[2])*180/Math.PI,n=(i.objectKeys?.[o.id]||[]).filter(r=>r.time*x<h-1e-6);w={...w,shots:w.shots.map(r=>r.id===i.id?{...r,objectKeys:{...r.objectKeys,[o.id]:[...n,{id:N(),time:h/x,position:m.position.map(f=>+f.toFixed(3)),rotation:[0,+e.toFixed(1),0],scale:o.scale}]}}:r)}}const I=Y(w,o.id,q,{start:h/x,newId:N,loop:!1});if(!I.ok)return{ok:!1,error:I.error};l.setStage(()=>I.stage);const{runTool:C}=await U(async()=>{const{runTool:i}=await import("./remote-C7J0Tqhb.js").then(m=>m.jA);return{runTool:i}},__vite__mapDeps([0,1,2,3,4,5,6,7,8,9])),y=h+S(a.clip),M=[],b=[];for(const i of a.effects){const m=Math.max(0,(i.at==="release"?y:h)+(i.offset??0)),t={effect:i.fx,start:m,duration:i.duration,...i.params?{params:i.params}:{},...s.color?{color:s.color}:{}};let e;if(i.place==="self")e={...t,attach_to:o.name};else if(i.place==="target")e={...t,attach_to:d.name};else if(i.place==="path")e={...t,from:`${o.name}.hand_right`,to:`${d.name}.chest`};else if(i.place==="ground")e={...t,from:`${o.name}.feet`,to:`${d.name}.feet`};else if(i.place==="area"){const r=v(l.getStage()),f=D(d,r,Math.min(1,m/r.duration)).position;e={...t,at:[f[0],0,f[2]]}}else{const r=v(l.getStage()),f=D(o,r,Math.min(1,m/r.duration)),g=Z(f.rotation[1]),k=i.ahead??6;e={...t,from:`${o.name}.chest`,to:[f.position[0]+Math.sin(g)*k,f.position[1]+1.2,f.position[2]+Math.cos(g)*k]}}const n=await C("add_effect",e,l);n.ok?M.push({effect:i.fx,start_s:E(m)}):b.push(`${i.fx}: ${String(n.error)}`)}const T=y+(a.hit??.4),A=String(s.react??"hit");let p=null;if(d&&(a.role==="attack"||a.role==="control")&&A!=="none"){const i=A==="block"?"xx-palm-shield":A==="evade"?"xx-teleport":a.role==="control"?"xx-kneel-wounded":"xx-knocked-flying",m=A==="block"?.22:A==="evade"?.26:0,t=Math.max(0,T-m),e=B(i);if(e){let n=l.getStage();const r=v(n),f=r.duration,g=D(d,{...r,flight:void 0},Math.min(1,t/f)),k=D(o,r,Math.min(1,t/f)).position,H=Math.atan2(k[0]-g.position[0],k[2]-g.position[2])*180/Math.PI,ht=(r.objectKeys?.[d.id]||[]).filter(O=>O.time*f<t-1e-6);n={...n,shots:n.shots.map(O=>O.id===r.id?{...O,objectKeys:{...O.objectKeys,[d.id]:[...ht,{id:N(),time:t/f,position:g.position.map(G=>+G.toFixed(3)),rotation:[0,+H.toFixed(1),0],scale:d.scale}]}}:O)},t+e.duration>f&&(n=tt(n,Math.min(300,Math.ceil((t+e.duration+.3)*10)/10)));const X=Y(n,d.id,e,{start:t/v(n).duration,newId:N,loop:!1});if(X.ok){if(l.setStage(()=>X.stage),p={motion:i,at_s:E(t)},A==="hit"&&s.timing!==!1){const O=v(l.getStage()),G=J(rt(O.timing,O.duration),[T],a.role==="control"?R.light:R.medium,O.duration);l.setStage(et=>({...et,shots:et.shots.map(V=>V.id===O.id?{...V,timing:G??void 0}:V)}))}}else b.push(`${d.name} ${i}: ${X.error}`)}}const _=[];if(s.camera===!0){const i=[["low-hero",o,h,Math.max(h+.4,y)]];d&&$&&i.push(["wide-track",d,Math.max(h+.4,y),T+1]);for(const[m,t,e,n]of i){const r=ct(l.getStage(),{preset:m,subject:t.id,start:e,end:n});r.ok&&(l.setStage(()=>r.stage),_.push(`${m} ${E(e)}–${E(n)} s`))}}return{ok:!0,technique:a.id,name:a.name,role:a.role,caster:o.name,...d?{target:d.name}:{},start_s:E(h),release_s:E(y),impact_s:E(T),end_s:E(h+q.duration),effects:M,...p?{reaction:p}:{},..._.length?{camera:_}:{},...b.length?{notes:b}:{}}}export{It as castTechnique,At as stageSpellDuel};
@@ -1 +0,0 @@
1
- import{d7 as A,ec as O,fw as w,ee as b,k as K,nf as N}from"./titleFrameBudget-CLZWaFHO.js";import{R as y}from"./api-CJ8PdbfZ.js";const E=n=>{let i;const e=new Set,t=(s,m)=>{const c=typeof s=="function"?s(i):s;if(!Object.is(c,i)){const d=i;i=m??(typeof c!="object"||c===null)?c:Object.assign({},i,c),e.forEach(h=>h(i,d))}},o=()=>i,l={setState:t,getState:o,getInitialState:()=>u,subscribe:s=>(e.add(s),()=>e.delete(s))},u=i=n(t,o,l);return l},U=(n=>n?E(n):E),D=n=>n;function F(n,i=D){const e=y.useSyncExternalStore(n.subscribe,y.useCallback(()=>i(n.getState()),[n,i]),y.useCallback(()=>i(n.getInitialState()),[n,i]));return y.useDebugValue(e),e}const C=n=>{const i=U(n),e=t=>F(i,t);return Object.assign(e,i),e},V=(n=>n?C(n):C),S=Object.freeze(["x","y","zoom","sx","sy","rot","opacity","depth","tiltX","tiltY","trimStart","trimEnd","reveal"]),f=Object.freeze({links:8,factor:100,offset:1e4,delay:30,chain:12}),k=n=>Math.round(n*1e4)/1e4,M=(n,i)=>Math.max(w[n].min,Math.min(w[n].max,i));function _(n,i){if(!Array.isArray(n)||n.length>f.links)throw Error(`Links: at most ${f.links}`);const e=new Set;return n.map(t=>{if(!t||typeof t!="object")throw Error("Invalid link");const o=t.fromProp??t.prop;if(!S.includes(t.prop)||!S.includes(o))throw Error(`Link property must be one of ${S.join(", ")}`);if(typeof t.from!="string"||!t.from||t.from===i)throw Error("A link needs another layer (from)");if(e.has(t.prop))throw Error(`Property "${t.prop}" is linked twice`);e.add(t.prop);const r={prop:t.prop,from:t.from};o!==t.prop&&(r.fromProp=o);for(const[a,l]of[["factor",f.factor],["offset",f.offset],["delay",f.delay]])if(t[a]!==void 0){if(!Number.isFinite(t[a])||Math.abs(t[a])>l||a==="delay"&&t[a]<0)throw Error(`Invalid link ${a}`);t[a]!==(a==="factor"?1:0)&&(r[a]=k(t[a]))}if(t.add!==void 0){if(typeof t.add!="boolean")throw Error("Invalid link add");t.add&&(r.add=!0)}return r})}function x(n,i,e){const t=e.fromProp??e.prop,o=e.factor??1,r=e.offset??0,a=i.start+(e.delay??0)-n.start,l=O(i,t),u=w[e.prop].base(n),s=l.length?l[0].value:b(i,t,0),m=e.add?p=>k(M(e.prop,u+(p-s)*o+r)):p=>k(M(e.prop,p*o+r));if(!l.length)return[{time:0,value:m(b(i,t,0))}];const c=l.map(p=>({...p,time:k(p.time+a),value:m(p.value)})),d=c.filter(p=>p.time>=0&&p.time<=n.duration+1e-6),h=c.filter(p=>p.time<0);if(h.length){const p=m(b(i,t,-a));(!d.length||d[0].time>1e-6)&&d.unshift({...h.at(-1),time:0,value:p})}return d.length?d.map(({time:p,value:L,ease:I})=>({time:p,value:L,...I!==void 0?{ease:I}:{}})):[{time:0,value:m(b(i,t,Math.max(0,Math.min(i.duration,n.duration-a))))}]}function j(n,i,e){if(!e||!e.length)return{links:void 0};const t=_(e,i.id),o=new Map(n.map(l=>[l.id,l]));for(const l of t){if(!o.get(l.from))throw Error(`Link source "${l.from}" not found`);if(P(n,i.id,l.from))throw Error("Links would loop")}let r={...i,links:t},a={links:t};for(const l of t){const u=A(r,l.prop,x(r,o.get(l.from),l));r={...r,...u},a={...a,...u}}return a}function P(n,i,e){const t=new Map(n.map(a=>[a.id,a])),o=[e],r=new Set;for(;o.length;){const a=o.pop();if(a===i)return!0;if(!(r.has(a)||r.size>200)){r.add(a);for(const l of t.get(a)?.links??[])o.push(l.from)}}return!1}function G(n){if(!n.some(a=>a.links?.length))return n;const i=new Map(n.map(a=>[a.id,a])),e=new Map,t=[],o=(a,l=0)=>{if(!(e.has(a.id)||l>f.chain)){e.set(a.id,!0);for(const u of a.links??[]){const s=i.get(u.from);s&&o(s,l+1)}t.push(a)}};for(const a of n)a.links?.length&&o(a);let r=!1;for(const a of t){if(!a.links?.length)continue;const l=i.get(a.id),u=l.links.filter(m=>i.has(m.from)&&!P([...i.values()],l.id,m.from));let s={...l,...u.length?{links:u}:{links:void 0}};for(const m of u)s={...s,...A(s,m.prop,x(s,i.get(m.from),m))};JSON.stringify(s)!==JSON.stringify(l)&&(i.set(a.id,s),r=!0)}return r?n.map(a=>i.get(a.id)):n}function Y(n,i,e,t=["x","y","rot"],o=.08){if(!Array.isArray(e)||!e.length||e.length>f.chain)throw Error(`Follow chain: 1–${f.chain} layers`);if(!Number.isFinite(o)||o<0||o>2)throw Error("Follow chain delay: 0–2 s");const r=new Map(n.map(s=>[s.id,s])),a={};let l=i,u=[...n];for(const s of e){const m=r.get(s);if(!m||s===l)throw Error(`Layer "${s}" not found`);const c=(m.links??[]).filter(h=>!t.includes(h.prop)),d=j(u,m,[...c,...t.map(h=>({prop:h,from:l,delay:o,add:!0}))]);a[s]=d,u=u.map(h=>h.id===s?{...h,...d}:h),l=s}return a}const Q={image:["16:9","9:16","1:1","4:3","3:4","3:2","2:3","4:5","5:4","21:9","9:21","2:1","1:2"],video:["Adaptive","16:9","9:16","1:1","4:3","3:4","21:9"],audio:[],world:[],model:[]},W={image:["1K","2K","4K"],video:["720p","1080p"],audio:[],world:[],model:[]},X=["Low","Medium","High"],$={min:3,max:30,default:5},ee={min:10,max:120},T={image:"muapi:nano-banana-2",video:"kling:3.0-turbo",audio:"muapi:minimax-music",world:"worldlabs:marble-1.1",model:"muapi:tripo-h31-text-3d"},te=[{id:"arri-alexa",label:"ARRI Alexa 35",hint:"cinematic, soft highlight roll-off"},{id:"red-8k",label:"Modular 8K Digital",hint:"ultra sharp, high dynamic range"},{id:"film-35",label:"35mm Film",hint:"film grain, warm halation"},{id:"tilt-lens",label:"Creative Tilt Lens",hint:"tilt-shift miniature focus"},{id:"anamorphic",label:"Anamorphic",hint:"oval bokeh, horizontal flares"},{id:"macro",label:"Macro 100mm",hint:"extreme close-up detail"},{id:"wide-24",label:"Wide 24mm",hint:"expansive, slight distortion"},{id:"tele-85",label:"Portrait 85mm",hint:"compressed background, creamy bokeh"}],ne=[{id:"script",label:"Viết kịch bản",prompt:"Giúp tôi viết kịch bản video ngắn. Ý tưởng/yêu cầu: [chủ đề, sản phẩm, khán giả, thời lượng]"},{id:"product-ad",label:"Quảng cáo sản phẩm",prompt:"Giúp tôi làm video quảng cáo sản phẩm. Thông tin sản phẩm: [tên, USP, khách hàng mục tiêu]"},{id:"ugc",label:"UGC review",prompt:"Tạo video UGC tự nhiên, chân thật, nêu bật lợi ích chính của sản phẩm. Sản phẩm: [...]"},{id:"batch",label:"Tạo hàng loạt",prompt:"Giúp tôi tạo một bộ video hàng loạt. Yêu cầu hoặc tư liệu: [chủ đề, số lượng, biến thể]"},{id:"micro-film",label:"Phim ngắn AI",prompt:"Tạo phim ngắn AI với hook cuốn hút, hình ảnh điện ảnh, xung đột cảm xúc và kết thúc đáng nhớ. Ý tưởng: [...]"},{id:"microdrama",label:"Microdrama",prompt:"Tạo microdrama nhịp nhanh với hook ngay lập tức, xung đột nhân vật mạnh và twist cảm xúc. Ý tưởng: [...]"},{id:"launch",label:"Ra mắt sản phẩm",prompt:"Tạo video ra mắt sản phẩm với mở đầu mạnh, làm nổi bật tính năng và kêu gọi hành động. Sản phẩm: [...]"},{id:"explainer",label:"Video giải thích",prompt:"Tạo video giải thích rõ ràng, giới thiệu chủ đề và chia nhỏ ý chính từng bước. Chủ đề: [...]"},{id:"social-ad",label:"Ads mạng xã hội",prompt:"Tạo quảng cáo dọc 15 giây với hook đậm trong 2 giây đầu, nhịp nhanh. Sản phẩm: [...]"},{id:"brand-story",label:"Câu chuyện thương hiệu",prompt:"Tạo video ngắn kể câu chuyện thương hiệu: chúng tôi là ai, giải quyết vấn đề gì, vì sao khách hàng chọn. Thương hiệu: [...]"},{id:"livestream",label:"Teaser livestream",prompt:"Tạo teaser 10 giây cho buổi livestream bán hàng. Sản phẩm/ưu đãi: [...]"},{id:"wedding",label:"Highlight đám cưới",prompt:"Tạo video highlight đám cưới cảm xúc từ các ảnh tham chiếu. Phong cách: [...]"},{id:"character",label:"Thiết kế nhân vật",prompt:"Thiết kế character sheet nhất quán (mặt trước, nghiêng, sau, biểu cảm) cho nhân vật: [...]"},{id:"poster",label:"Thiết kế poster",prompt:"Thiết kế poster nổi bật với hệ thống phân cấp rõ, tiêu đề cuốn hút. Nội dung: [...]"},{id:"thumbnail",label:"Thumbnail video",prompt:"Thiết kế thumbnail video có điểm nhấn rõ, chữ đậm dễ đọc, tương phản mạnh. Chủ đề: [...]"},{id:"music",label:"Thiết kế nhạc",prompt:"Thiết kế nhạc nền cho video, hợp mood, nhịp và các điểm chuyển cảnh. Mô tả video: [...]"}],oe=[{group:"Cơ bản",items:[["Xoá","⌫"],["Undo","⌘ Z"],["Redo","⇧ ⌘ Z"],["Copy","⌘ C"],["Paste","⌘ V"],["Duplicate","⌘ D"],["Multi-select","⇧ + click"]]},{group:"Di chuyển",items:[["Pan","Space + kéo"],["Pan","Chuột giữa / cuộn"]]},{group:"Zoom",items:[["Zoom in","⌘ +"],["Zoom out","⌘ −"],["Zoom","⌘ + cuộn"],["Fit to screen","⇧ 1"],["Zoom to selection","⇧ 2"]]},{group:"Khác",items:[["Select tool","V"],["Hand tool","H"],["Duplicate node","⌥ + kéo"],["Canvas Agent","/"],["Phím tắt","?"]]}],R="clipoox.settings",g=(n=null,i=null)=>({generator:n,resolution:i}),v={lineage:"selected",agent:{image:g("openai:gpt-image","1K"),omni:g("muapi:seedance-2.5","480p"),frames:g("muapi:seedance-2.5","480p"),music:T.audio},user:{image:g(T.image,"1K"),video:g(T.video,"480p")}};function q(){try{const n=localStorage.getItem(R);if(!n)return v;const i=JSON.parse(n);return{lineage:["none","selected","all"].includes(i.lineage)?i.lineage:v.lineage,agent:{...v.agent,...i.agent||{}},user:{...v.user,...i.user||{}}}}catch{return v}}function Z(n){try{localStorage.setItem(R,JSON.stringify(n))}catch{}}const H={open:!1,mode:"video",refs:[],prompt:"",generator:null,resolution:"720p",quality:"Medium",duration:$.default,aspectRatio:"Adaptive",count:1,instrumental:!1,lyrics:"",transparent:!1,complexity:"",videoMode:"omni",draft:!1,camera:null,camerawork:null,palette:null,lighting:null,camBody:null,camLens:null,focal:null,aperture:null,looks:{},paletteColors:[],tempo:null,pose:null,anchor:null,targetId:null};let z=1;const ie=V((n,i)=>({user:void 0,wallet:null,setUser:e=>n({user:e}),setWallet:e=>n({wallet:e}),canvasId:null,title:"",saveState:"idle",saveError:null,saveRetry:0,retrySave:()=>n(e=>({saveRetry:e.saveRetry+1})),view:"canvas",tool:"select",generators:[],setCanvasMeta:e=>n(e),setView:e=>n({view:e}),setTool:e=>n({tool:e}),setGenerators:e=>n({generators:e}),past:[],future:[],pushHistory:e=>n(t=>({past:[...t.past.slice(-49),e],future:[]})),popUndo:e=>{const{past:t,future:o}=i();if(!t.length)return null;const r=t[t.length-1];return n({past:t.slice(0,-1),future:[e,...o].slice(0,50)}),r},popRedo:e=>{const{past:t,future:o}=i();if(!o.length)return null;const r=o[0];return n({future:o.slice(1),past:[...t,e].slice(-50)}),r},composer:H,openComposer:(e={})=>n(t=>{const o=e.mode||t.composer.mode,r=t.generators.filter(c=>c.kind===o&&!c.tool),a=o==="image"?t.settings.user.image:o==="video"?t.settings.user.video:null,l=e.generator||(t.composer.mode===o&&t.composer.generator&&r.some(c=>c.name===t.composer.generator&&c.available)?t.composer.generator:null)||a?.generator&&r.find(c=>c.name===a.generator&&c.available)?.name||r.find(c=>c.name===T[o]&&c.available)?.name||r.find(c=>c.available)?.name||r[0]?.name||null,u=e.resolution||(t.composer.mode===o&&t.composer.generator?t.composer.resolution:null)||a?.resolution||(o==="image"?"1K":"720p"),s=e.aspectRatio||(o==="image"?"16:9":"Adaptive"),m=o==="world"||o==="model"?1:e.count??t.composer.count;return{composer:{...t.composer,...e,open:!0,mode:o,generator:l,resolution:u,aspectRatio:s,count:m,targetId:e.targetId??null,anchor:e.anchor??null,draft:e.draft??!1}}}),closeComposer:()=>n(e=>({composer:{...e.composer,open:!1}})),patchComposer:e=>n(t=>({composer:{...t.composer,...e}})),toggleRef:e=>n(t=>{const o=t.composer.refs.includes(e)?t.composer.refs.filter(r=>r!==e):[...t.composer.refs,e];return{composer:{...t.composer,refs:o}}}),panels:{agent:!1,history:!1,assets:!1,shortcuts:!1,settings:!1,minimap:!1,lineage:!1,snapping:!0,chatgpt:!1},settings:q(),setSettings:e=>n(t=>{const o=typeof e=="function"?e(t.settings):{...t.settings,...e};return Z(o),{settings:o}}),togglePanel:(e,t)=>n(o=>({panels:{...o.panels,[e]:t??!o.panels[e]}})),clipEdit:{open:!1,nodeId:null,tool:"edit"},openClipEdit:(e,t="edit")=>n(o=>({clipEdit:{open:!0,nodeId:e,tool:t},composer:{...o.composer,open:!1}})),closeClipEdit:()=>n(e=>({clipEdit:{...e.clipEdit,open:!1}})),selected:[],setSelected:e=>n({selected:e}),contextMenu:null,setContextMenu:e=>n({contextMenu:e}),agent:{messages:[],busy:!1,model:(()=>{try{return localStorage.getItem("clipoox.agent.model")}catch{return null}})(),models:[],provider:null},pushAgentMessage:e=>n(t=>({agent:{...t.agent,messages:[...t.agent.messages,e]}})),setAgentBusy:e=>n(t=>({agent:{...t.agent,busy:e}})),setAgentModel:e=>{try{e&&localStorage.setItem("clipoox.agent.model",e)}catch{}n(t=>({agent:{...t.agent,model:e}}))},setAgentModels:(e,t,o)=>n(r=>({agent:{...r.agent,models:e,provider:t,model:r.agent.model&&e.includes(r.agent.model)?r.agent.model:o}})),clearAgent:()=>n(e=>({agent:{...e.agent,messages:[]}})),timelineTracks:{},setTimelineTracks:e=>n({timelineTracks:e}),timelineFormat:{...K},setTimelineFormat:e=>n({timelineFormat:e}),timelineCamera:null,timelineLook:null,setTimelineLook:e=>n({timelineLook:e}),timelinePalette:[],setTimelinePalette:e=>n({timelinePalette:e}),timelineBrand:null,setTimelineBrand:e=>n({timelineBrand:e}),timelineMotion:null,setTimelineMotion:e=>n({timelineMotion:e}),timelinePins:[],setTimelinePins:e=>n(t=>({timelinePins:typeof e=="function"?e(t.timelinePins):e})),timelineVideoType:null,setTimelineVideoType:e=>n({timelineVideoType:e}),timelineExportRange:null,setTimelineExportRange:e=>n({timelineExportRange:e}),timelineComments:[],setTimelineComments:e=>n(t=>({timelineComments:typeof e=="function"?e(t.timelineComments):e})),setTimelineCamera:e=>n({timelineCamera:e}),timelineMedia:[],setTimelineMedia:e=>n(t=>({timelineMedia:typeof e=="function"?e(t.timelineMedia):e})),clips:[],timelineCompPath:[],setClips:e=>n(t=>({clips:N(t.clips,G(typeof e=="function"?e(t.clips):e),t.timelineTracks)})),toasts:[],toast:(e,t="info")=>{const o=z++;n(r=>({toasts:[...r.toasts,{id:o,text:e,kind:t}]})),setTimeout(()=>i().dismissToast(o),t==="error"?6e3:3200)},dismissToast:e=>n(t=>({toasts:t.toasts.filter(o=>o.id!==e)}))}));export{ee as A,te as C,v as D,S as L,X as Q,W as R,ne as S,$ as V,Q as a,oe as b,V as c,Y as f,G as r,j as s,ie as u};
@@ -1 +0,0 @@
1
- import{bh as C,dF as I,nr as j,ns as q}from"./titleFrameBudget-CLZWaFHO.js";const e=160;async function F(p,g,x,y){const u=g.frames;if(!u.length)return null;const t=Object.assign(document.createElement("video"),{muted:!0,playsInline:!0,preload:"auto",crossOrigin:"anonymous"});t.src=x;try{await new Promise((a,d)=>{t.onloadeddata=()=>a(),t.onerror=()=>d(Error("video"))});const o=Math.max(2,Math.round(e*t.videoHeight/t.videoWidth)),E=Object.assign(document.createElement("canvas"),{width:e,height:o}),w=E.getContext("2d",{willReadFrequently:!0}),r=p.crop||{left:0,right:0,top:0,bottom:0},S=1-r.left-r.right,T=1-r.top-r.bottom,s=u[0][0],M=u.at(-1)[0],m=Math.max(1/6,(M-s)/80),O=Math.max(1,Math.floor((M-s)/m+1e-6)+1),b=[];for(let a=0;a<O;a++){if(y?.aborted)throw new DOMException("cancelled","AbortError");const d=s+a*m,v=Math.min(t.duration-1/60,C(p,d));Math.abs(t.currentTime-v)>1e-4&&await new Promise((n,c)=>{const i=window.setTimeout(()=>c(Error("seek")),8e3);t.onseeked=()=>{window.clearTimeout(i),n()},t.currentTime=v}),w.drawImage(t,0,0,e,o);const l=w.getImageData(0,0,e,o).data,k=(n,c)=>{const i=Math.round(n),h=Math.round(c);if(i<0||h<0||i>=e||h>=o)return null;const f=(h*e+i)*4;return[l[f]/255,l[f+1]/255,l[f+2]/255]},A=I(g,d).map(([n,c])=>[(r.left+n*S)*e,(r.top+c*T)*o]);b.push(j(k,A))}return q(b,s,m)}finally{t.removeAttribute("src"),t.load()}}export{F as measureSurfaceLight};
@@ -1,2 +0,0 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/pendingMatte-BPyzzx4y.js","assets/titleFrameBudget-CLZWaFHO.js","assets/remote-C7J0Tqhb.js","assets/api-CJ8PdbfZ.js","assets/three.module-Bx43vjkH.js","assets/GLTFLoader-BHWu1lKg.js","assets/store-DW4E9xnW.js","assets/rotoMaskStore-DPziPKAN.js","assets/textAnimators-DUZjhVGO.js","assets/timelineComp-B4GtoH2f.js","assets/rigTrack-urT3nDK0.js","assets/main-VVYiW8XD.js","assets/spark.module-DzziUgOj.js","assets/userFonts-CwlKh9NR.js","assets/lottieLayer-DzbA3bHV.js","assets/timeline3d-DOw-CpZI.js","assets/RoomEnvironment-Dmv_G5ka.js","assets/exportEncode-QYsT9JBO.js","assets/captionLayout-DvDPTwO9.js","assets/timelineText-BH09jfSM.js","assets/titleArt-Drsrtfiv.js","assets/rotoMatte-C-2o3vv0.js","assets/distortGL-QalhICvi.js","assets/motionBlur-uAm030t9.js","assets/main-Ca_CVxMz.css"])))=>i.map(i=>d[i]);
2
- import{c0 as L,c2 as ft,m_ as j,dH as pt,dF as dt,m$ as gt,n0 as B,n1 as yt,n2 as ct,dM as wt,dR as kt,dU as tt,c1 as R,n3 as Mt,n4 as bt,dV as xt,fr as vt,n5 as St,dT as Pt,n6 as Ft,_ as Tt,a7 as At,b_ as Et,b$ as _t,dB as qt,n7 as Ct,n8 as It,n9 as Ot}from"./titleFrameBudget-CLZWaFHO.js";import{X as lt,Y as Dt,Z as Nt,_ as Bt,$ as Rt,a0 as Vt,a1 as et}from"./main-VVYiW8XD.js";import{i5 as Kt,i6 as Ht}from"./remote-C7J0Tqhb.js";import{measureSurfaceLight as Qt}from"./surfaceLight-aDSYU8Jg.js";import{u as C}from"./store-DW4E9xnW.js";import{B as Y,F as Z,H as nt,U as Ut,V as $t}from"./rotoMaskStore-DPziPKAN.js";import{t as A}from"./api-CJ8PdbfZ.js";import"./three.module-Bx43vjkH.js";import"./spark.module-DzziUgOj.js";import"./timelineComp-B4GtoH2f.js";import"./textAnimators-DUZjhVGO.js";import"./userFonts-CwlKh9NR.js";import"./lottieLayer-DzbA3bHV.js";import"./rigTrack-urT3nDK0.js";import"./timeline3d-DOw-CpZI.js";import"./GLTFLoader-BHWu1lKg.js";import"./RoomEnvironment-Dmv_G5ka.js";import"./exportEncode-QYsT9JBO.js";import"./captionLayout-DvDPTwO9.js";import"./timelineText-BH09jfSM.js";import"./titleArt-Drsrtfiv.js";import"./rotoMatte-C-2o3vv0.js";import"./distortGL-QalhICvi.js";import"./motionBlur-uAm030t9.js";const rt=(t,a,m,n,e)=>{if(n<0||e<0||n>a-1.001||e>m-1.001)return NaN;const h=Math.floor(n),o=Math.floor(e),i=n-h,c=e-o,r=o*a+h;return(t[r]*(1-i)+t[r+1]*i)*(1-c)+(t[r+a]*(1-i)+t[r+a+1]*i)*c};function ot(t,a,m,n,e,h,{radius:o=10,samples:i=28,min:c=10,sign:r=null}={}){const s=Math.hypot(e[0]-n[0],e[1]-n[1]);if(s<8)return null;const f=[(e[0]-n[0])/s,(e[1]-n[1])/s];let u=[-f[1],f[0]];const l=[(n[0]+e[0])/2,(n[1]+e[1])/2];(l[0]-h[0])*u[0]+(l[1]-h[1])*u[1]<0&&(u=[-u[0],-u[1]]);const p={drop:[],rise:[]};for(let S=0;S<i;S++){const T=.08+.84*S/(i-1),x=[n[0]+(e[0]-n[0])*T,n[1]+(e[1]-n[1])*T];let k=null,M=null;for(let v=-o;v<=o;v+=.5){const _=x[0]+u[0]*v,q=x[1]+u[1]*v,P=rt(t,a,m,_+u[0],q+u[1])-rt(t,a,m,_-u[0],q-u[1]);if(!Number.isFinite(P)||Math.abs(P)<c)continue;const E=Math.abs(P)*(1-.7*Math.abs(v)/o);P<0&&(!k||E>k.score)&&(k={x:_,y:q,score:E}),P>0&&(!M||E>M.score)&&(M={x:_,y:q,score:E})}k&&p.drop.push(k),M&&p.rise.push(M)}const g=S=>S.reduce((T,x)=>T+x.score,0),d=r?p[r]:g(p.drop)*1.25>=g(p.rise)?p.drop:p.rise;if(d.length<i*.5)return null;const w=(S,T,x)=>{const k=x.x-T.x,M=x.y-T.y,v=Math.hypot(k,M)||1;return Math.abs((S.x-T.x)*M-(S.y-T.y)*k)/v};let y=null;for(let S=0;S<d.length;S++)for(let T=S+2;T<d.length;T++){const x=d.filter(k=>w(k,d[S],d[T])<=1.2);(!y||x.length>y.length||x.length===y.length&&x.reduce((k,M)=>k+M.score,0)>y.reduce((k,M)=>k+M.score,0))&&(y=x)}if(!y||y.length<i*.4)return null;const b=zt(y);return b&&{...b,inliers:y.length/i}}function zt(t){if(t.length<2)return null;let a=0,m=0;for(const i of t)a+=i.x,m+=i.y;a/=t.length,m/=t.length;let n=0,e=0,h=0;for(const i of t){const c=i.x-a,r=i.y-m;n+=c*c,e+=c*r,h+=r*r}const o=.5*Math.atan2(2*e,n-h);return{p:[a,m],d:[Math.cos(o),Math.sin(o)]}}const z=(t,a)=>{const m=t.d[0]*a.d[1]-t.d[1]*a.d[0];if(Math.abs(m)<1e-6)return null;const n=((a.p[0]-t.p[0])*a.d[1]-(a.p[1]-t.p[1])*a.d[0])/m;return[t.p[0]+t.d[0]*n,t.p[1]+t.d[1]*n]},Gt=t=>{let a=0;for(let m=0;m<4;m++){const n=t[m],e=t[(m+1)%4],h=t[(m+2)%4],o=(e[0]-n[0])*(h[1]-e[1])-(e[1]-n[1])*(h[0]-e[0]);if(!o||a&&Math.sign(o)!==a)return!1;a=Math.sign(o)}return!0};function at(t,a,m,n,e={}){const h=e.radius??10,o=[n.reduce((l,p)=>l+p[0],0)/4,n.reduce((l,p)=>l+p[1],0)/4],i=l=>[0,1,2,3].map(p=>ot(t,a,m,n[p],n[(p+1)%4],o,{...e,sign:l})),c=l=>l.every(Boolean)?l.reduce((p,g)=>p+g.inliers,0):-1,r=i("drop"),s=i("rise"),f=c(r)*1.15>=c(s)?r:s;if(f.some(l=>!l))return null;const u=[z(f[3],f[0]),z(f[0],f[1]),z(f[1],f[2]),z(f[2],f[3])];if(u.some(l=>!l)||!Gt(u)||u.some((l,p)=>Math.hypot(l[0]-n[p][0],l[1]-n[p][1])>2*h))return null;if(e.clean){const l=f===r?"drop":"rise",p=[u.reduce((d,w)=>d+w[0],0)/4,u.reduce((d,w)=>d+w[1],0)/4],g=[0,1,2,3].map(d=>ot(t,a,m,u[d],u[(d+1)%4],p,{...e,radius:Math.min(h,4),samples:48,sign:l}));if(g.some(d=>!d)||g.filter(d=>d.inliers>=.97).length<3||g.some(d=>d.inliers<.6))return null}return u}function Lt(t,a,{jump:m=3}={}){const n=t.length,e=t.map((i,c)=>i??null);for(let i=0;i<n;i++)if(!e[i]){let c=i-1;for(;c>=0&&!t[c];)c--;let r=i+1;for(;r<n&&!t[r];)r++;e[i]=c>=0&&r<n?t[c].map((s,f)=>s.map((u,l)=>u+(t[r][f][l]-u)*(i-c)/(r-c))):c>=0?t[c]:r<n?t[r]:a[i]}const h=e.map((i,c)=>i.map((r,s)=>r.map((f,u)=>{const l=[];for(let p=-2;p<=2;p++){const g=e[Math.min(n-1,Math.max(0,c+p))];l.push(g[s][u])}return l.sort((p,g)=>p-g),l[2]}))),o=e.map((i,c)=>i.map((r,s)=>Math.hypot(r[0]-h[c][s][0],r[1]-h[c][s][1])>m?h[c][s]:r));return o.map((i,c)=>i.map((r,s)=>r.map((f,u)=>{let l=0,p=0;for(let g=-1;g<=1;g++){const d=o[c+g];d&&(l+=d[s][u],p++)}return l/p})))}const it=[15,100],st=46,V=(t,a)=>t[0]*a[0]+t[1]*a[1]+t[2]*a[2],mt=t=>Math.hypot(...t),U=t=>{const a=mt(t)||1;return t.map(m=>m/a)},W=(t,a)=>[t[1]*a[2]-t[2]*a[1],t[2]*a[0]-t[0]*a[2],t[0]*a[1]-t[1]*a[0]],J=(t,a)=>t.map(m=>[0,1,2].map(n=>m[0]*a[0][n]+m[1]*a[1][n]+m[2]*a[2][n])),Wt=t=>[0,1,2].map(a=>[0,1,2].map(m=>t[m][a]));function Xt(t){const a=t.map(n=>[...n]),m=[[1,0,0],[0,1,0],[0,0,1]];for(let n=0;n<60;n++){let e=0,h=1;if(Math.abs(a[0][2])>Math.abs(a[e][h])&&(e=0,h=2),Math.abs(a[1][2])>Math.abs(a[e][h])&&(e=1,h=2),Math.abs(a[e][h])<1e-15)break;const o=(a[h][h]-a[e][e])/(2*a[e][h]),i=(o>=0?1:-1)/(Math.abs(o)+Math.sqrt(o*o+1)),c=1/Math.sqrt(i*i+1),r=i*c;for(let s=0;s<3;s++){const f=a[s][e],u=a[s][h];a[s][e]=c*f-r*u,a[s][h]=r*f+c*u}for(let s=0;s<3;s++){const f=a[e][s],u=a[h][s];a[e][s]=c*f-r*u,a[h][s]=r*f+c*u}for(let s=0;s<3;s++){const f=m[s][e],u=m[s][h];m[s][e]=c*f-r*u,m[s][h]=r*f+c*u}}return[0,1,2].map(n=>({v:a[n][n],e:[m[0][n],m[1][n],m[2][n]]})).sort((n,e)=>e.v-n.v)}function Yt(t){const a=J(Wt(t),t),[m,n,e]=Xt(a),h=Math.sqrt(Math.max(1e-18,n.v)),o=m.v/(h*h),i=e.v/(h*h);if(o-i<2e-4)return null;const c=Math.sqrt(o-i),r=Math.sqrt(Math.max(0,1-i)),s=Math.sqrt(Math.max(0,o-1)),f=m.e.map((p,g)=>(r*p+s*e.e[g])/c),u=m.e.map((p,g)=>(r*p-s*e.e[g])/c),l=[W(n.e,f),W(n.e,u)].map(p=>(p=U(p),p[2]<0?p.map(g=>-g):p));return l.w=o-i,l}const Zt=t=>[[t[0],t[1],t[2]],[t[3],t[4],t[5]],[t[6],t[7],t[8]]];function Jt(t){let a={cost:1/0,n:null};for(const m of t[0]){const n=t.map(c=>c.w*c.w),e=n.reduce((c,r)=>c+r,0)||1,h=t.map(c=>c.reduce((r,s)=>V(r,m)>V(s,m)?r:s)),o=U(h.reduce((c,r,s)=>c.map((f,u)=>f+r[u]*n[s]),[0,0,0])),i=h.reduce((c,r,s)=>c+n[s]*Math.acos(Math.max(-1,Math.min(1,V(r,o)))),0)/e;i<a.cost&&(a={cost:i,n:o})}return a}function jt(t,a,m,n){const e=t.planar,h=e.frames.filter(l=>Math.abs(l[0]-n)>1/20),o=Math.min(30,h.length);if(o<2)return null;const i=l=>l.map(([p,g])=>[p-a/2,g-m/2]),c=i(j(t,n,a,m)),r=Array.from({length:o},(l,p)=>h[Math.round(p*(h.length-1)/Math.max(1,o-1))]).map(l=>pt(c,i(j(t,l[0],a,m)))).filter(Boolean);if(r.length<2)return null;const s=l=>{const p=m/2/Math.tan(l*Math.PI/360),g=[[p,0,0],[0,p,0],[0,0,1]],d=[[1/p,0,0],[0,1/p,0],[0,0,1]],w=r.map(b=>Yt(J(J(d,Zt(b)),g))).filter(Boolean);if(w.length<2)return null;const y=Jt(w);return{...y,cost:y.cost+.008*((l-st)/30)**2,raw:y.cost}};let f=null,u=st;for(let l=it[0];l<=it[1];l+=1){const p=s(l);p&&(!f||p.cost<f.cost)&&(f=p,u=l)}if(!f)return null;for(let l=u-1;l<=u+1;l+=.1){const p=s(l);p&&p.cost<f.cost&&(f=p,u=l)}return{fov:+u.toFixed(2),n:f.n,spread:+f.raw.toFixed(5)}}function te(t,a,m,n,e){const h=jt(t,a,m,n);if(!h)return null;const o=m/2/Math.tan(h.fov*Math.PI/360),i=h.n,{mw:c,mh:r}=t.planar,s=e.map(([x,k])=>{const M=L(t,x,k,n,a,m,c,r),v=[(M.px-a/2)/o,(M.py-m/2)/o,1],_=V(i,v);return _>1e-6?v.map(q=>q/_):null});if(s.some(x=>!x))return null;const f=W(i,[0,-1,0]),u=mt(f)>.15?U(f[0]<0?f.map(x=>-x):f):U([1-i[0]*i[0],-i[0]*i[1],-i[0]*i[2]]);let l=U(W(i,u));l[1]<0&&(l=l.map(x=>-x));const p=s.map(x=>V(x,u)),g=s.map(x=>V(x,l)),d=(p[0]+p[3])/2,w=(p[1]+p[2])/2,y=(g[0]+g[1])/2,b=(g[2]+g[3])/2;if(!(w>d&&b>y))return null;const S=(x,k)=>i.map((M,v)=>M+x*u[v]+k*l[v]),T=[[d,y],[w,y],[w,b],[d,b]].map(([x,k])=>{const M=S(x,k),v=ft(t,o*M[0]/M[2]+a/2,o*M[1]/M[2]+m/2,n,a,m,c,r);return[+v.u.toFixed(5),+v.v.toFixed(5)]});return{fov:h.fov,surface:T,n:i}}const G=new Map,ee=1/30;async function ht(t,a,m,n,e=null){const h=[];let o=0,i=0;for(const[c,r]of[[1,n.fwd],[-1,n.back]])if(!(Math.abs(r-n.from)<ee))try{const s=await Rt({clip:t,url:a,quad:m,mode:"perspective",from:n.from,to:r,scene:e});o=s.mw,i=s.mh,h.push({dir:c,frames:s.frames,lostAt:s.lostAt,expected:Math.round(Math.abs(r-n.from)*30)})}catch(s){if(s.message!=="FLAT")throw s;h.push({dir:c,frames:[],lostAt:n.from,expected:Math.round(Math.abs(r-n.from)*30)})}return{runs:h,mw:o,mh:i,quality:Ot(h)}}const Q=new Map;function ne(t,a,m){const n=[t.id,a,t.start,t.inPoint??0,t.duration,t.playbackRate??1,m.from,m.back,m.fwd].join("|"),e=Date.now();for(const[o,i]of Q)e-i.at>6e4&&Q.delete(o);let h=Q.get(n);return h||(h={at:e,p:ht(t,a,B(ct),m)},Q.set(n,h),h.p.catch(()=>Q.delete(n))),h.p}async function re(t,a,m,n){const e=await lt(t,a);try{const h=await e.grab(n),o=r=>qt(h,e.w,e.h,B(r).map(([s,f])=>{const u=e.toPx(s,f);return[u.x,u.y]}),"perspective").features.length,i=o(m);if(i>=Ct)return{region:m,score:i,moved:!1};let c={region:m,score:i,moved:!1};for(const r of It(m)){const s=o(r);s>c.score&&(c={region:r,score:s,moved:!0})}return c}finally{e.close()}}async function ut(t,a,m,n,e){let h;const o={clip:t,url:a,u:m.x+m.w/2,v:m.y+m.h/2,from:n,to:e},i=r=>r?r.lostAt??e:-1,c=await Vt(o).catch(r=>{if(r.name==="AbortError")throw r;return null});if(c&&c.lostAt===null)h=c;else if(c&&i(c)>=n+.6*(e-n)){const r=c.track.points.at(-1),s=r[0]<e-.1?await et({...o,u:r[1],v:r[2],from:r[0]}).catch(f=>{if(f.name==="AbortError")throw f;return null}):null;h=s&&s.track.points.length>1?{track:{...c.track,points:[...c.track.points,...s.track.points.filter(f=>f[0]>r[0]+1e-4)]},lostAt:s.lostAt}:c}else{const r=await et(o).catch(s=>{if(s.name==="AbortError"||!c)throw s;return null});h=r&&i(r)>=i(c)?r:c}return h}async function oe(t,a,m,n,e,h){const o=Math.max(0,n.at-a.start),i=Math.min(a.duration,t.start+t.duration-a.start),c=n.region;let r;try{r=await ut(a,m,c,o,i)}catch(w){if(w.name==="AbortError")throw w;return e(A("“{0}”: không bám được vật này — chọn chỗ có nhiều chi tiết hơn.",[t.label]))}const s=C.getState(),f=s.clips.find(w=>w.id===t.id),u=s.clips.find(w=>w.id===a.id);if(!f||f.pendingPin!==n||!u)return{clipId:t.id,ok:!1,message:A("Timeline đã thay đổi. Hãy thử lại.")};const{width:l,height:p}=R(s.timelineFormat),g=r.track.points.map(([w,y,b])=>{const S=L(u,y,b,w,l,p,r.track.mw,r.track.mh);return[u.start+w-f.start,S.px,S.py]}).filter(w=>w[0]>=-1e-6);if(g.length<2)return e(A("“{0}”: không bám được vật này — chọn chỗ có nhiều chi tiết hơn.",[t.label]));const d=Kt(f,g,l,p);return h?.(),C.setState(w=>({clips:w.clips.map(y=>y.id===f.id?{...y,...d}:y)})),{clipId:f.id,ok:!0,path:"region",message:r.lostAt!==null?A("Vệt theo vật: bám được tới giây {0}.",[r.lostAt.toFixed(2)]):A("Vệt theo vật: đã bám {0} khung.",[g.length])}}async function ae(t,a,m,n,e,h){let o=a;const i=Math.max(0,n.at-o.start),c=Math.min(o.duration,t.start+t.duration-o.start),{width:r,height:s}=R(C.getState().timelineFormat);let f;try{if(n.person){const w=()=>{const k=C.getState().clips,M=k.find(v=>v.id===o.id);return M?.person&&M.person.src!=="object"?M.person:k.find(v=>v.id!==o.id&&v.kind==="video"&&v.url===o.url&&v.person&&v.person.src!=="object")?.person};let y=w();for(let k=0;k<1200&&!y&&C.getState().clips.some(M=>M.url===o.url&&M.personPending);k++)await new Promise(M=>setTimeout(M,500)),y=w();if(!y){const{segmentClipMatte:k}=await Tt(async()=>{const{segmentClipMatte:M}=await import("./pendingMatte-BPyzzx4y.js");return{segmentClipMatte:M}},__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24]));y=await k(o)}if(!y)return e(A("“{0}”: chưa tách người trên clip này — mở Roto → Tách người, hoặc chọn điểm người chạy.",[t.label]));const b=await At(y),S=1/30,T=[],x=y;for(let k=i;k<=c+1e-6;k+=S){const M=Bt(Et(b,x,_t(o,k)),x.w,x.h);if(!M)continue;const v=L(o,M.x+M.w/2,M.y+M.h*.42,k,r,s,x.mw,x.mh);T.push([k,v.px/r,v.py/s])}f=T.map((k,M)=>{const v=T.slice(Math.max(0,M-2),M+3);return[k[0],v.reduce((_,q)=>_+q[1],0)/v.length,v.reduce((_,q)=>_+q[2],0)/v.length]})}else{const w=await ut(o,m,n.region,i,c);f=w.track.points.map(([y,b,S])=>{const T=L(o,b,S,y,r,s,w.track.mw,w.track.mh);return[y,T.px/r,T.py/s]})}}catch(w){if(w.name==="AbortError")throw w;return e(A("“{0}”: không bám được vật này — chọn chỗ có nhiều chi tiết hơn.",[t.label]))}const u=C.getState(),l=u.clips.find(w=>w.id===t.id),p=u.clips.find(w=>w.id===o.id);if(!l||l.pendingPin!==n||!p)return{clipId:t.id,ok:!1,message:A("Timeline đã thay đổi. Hãy thử lại.")};const g=f.map(([w,y,b])=>[p.start+w-l.start,y,b]).filter(w=>w[0]>=-1e-6);if(g.length<2)return e(A("“{0}”: không bám được vật này — chọn chỗ có nhiều chi tiết hơn.",[t.label]));const d=Ht(l,g);return h?.(),C.setState(w=>({clips:w.clips.map(y=>y.id===l.id?{...y,...d}:y)})),{clipId:l.id,ok:!0,path:"region",message:A("Vệt sét: đã bám {0} khung.",[g.length])}}async function ie(t,a,m,n,e,h){let o;try{o=await Nt(a,m)}catch(y){if(y.name==="AbortError")throw y;return e(A("“{0}”: video quá ít chi tiết để dựng camera 3D — thử một cảnh có nhiều mái nhà, đường, cây.",[t.label]))}const i=C.getState(),c=i.clips.find(y=>y.id===t.id),r=i.clips.find(y=>y.id===a.id);if(!c||c.pendingPin!==n||!r)return{clipId:t.id,ok:!1,message:A("Timeline đã thay đổi. Hãy thử lại.")};const{width:s,height:f}=R(i.timelineFormat),u=n.at-r.start,l=n.region,[p,g]=Y(o,r,l.x+l.w/2,l.y+l.h/2);let d,w=i.timelineCamera;if(c.kind==="model"){if(o.mode!=="free")return e(A("“{0}”: máy quay chỉ xoay tại chỗ — toà nhà 3D cần cảnh máy bay / di chuyển.",[c.label]));const y=Z(o,p,g,u)??nt(o,p,g,u),b=Z(o,...Y(o,r,l.x,l.y+l.h/2),u),S=Z(o,...Y(o,r,l.x+l.w,l.y+l.h/2),u),T=Ut(o,r,y,s,f,{size:b&&S?Math.hypot(b[0]-S[0],b[1]-S[1],b[2]-S[2]):null,fill:.8});w=T.camera,d={pendingPin:void 0,pin:void 0,...T.place}}else d={pendingPin:void 0,pin:void 0,...$t(c,r,o,nt(o,p,g,u),s,f)};return h?.(),C.setState(y=>({timelineCamera:w,clips:y.clips.map(b=>b.id===r.id?{...b,sceneTrack:o}:b.id===c.id?{...b,...d}:b)})),{clipId:c.id,ok:!0,path:"scene",message:A("“{0}” đã dính vào cảnh 3D của video (camera dựng từ {1} khung, như 3D Camera Tracker).",[c.label,o.frames.length])}}async function se(t,a,m,n){if(!m.frames.length)return null;const e=await lt(t,a);try{const h=Math.max(6,Math.round(e.w*.025)),o=[],i=[],c=g=>e.grab(g+.002);for(const g of m.frames){const d=dt(m,g[0]).map(([w,y])=>{const b=e.toPx(w,y);return[b.x,b.y]});o.push(d),i.push(at(await c(g[0]),e.w,e.h,d,{radius:h}))}if(i.filter(Boolean).length<i.length*.6)return null;const r=m.frames.map(g=>g[0]),s=m.frames.map(g=>g[9]);if(n){const g=.03333333333333333,d=async(P,E)=>{const N=[];let O=P<0?i.findIndex(Boolean):i.length-1-[...i].reverse().findIndex(Boolean),K=i[O],D=r[O];for(let $=0;$<600&&(D=+(D+P*g).toFixed(4),!(P<0?D<E-1e-6:D>E+1e-6));$++){const H=at(await c(D),e.w,e.h,K,{radius:h,clean:!0});if(!H)break;N.push({t:D,q:H}),K=H}return{k:O,out:N}},w=await d(-1,Math.max(0,n.back)),y=await d(1,Math.min(t.duration,n.fwd)),b=w.out.reverse(),S=y.out,T=w.k,x=y.k,k=P=>P>=T&&P<=x,M=[...b.map(P=>P.t),...r.filter((P,E)=>k(E)),...S.map(P=>P.t)],v=[...b.map(P=>P.q),...i.filter((P,E)=>k(E)),...S.map(P=>P.q)],_=[...b.map(P=>P.q),...o.filter((P,E)=>k(E)),...S.map(P=>P.q)],q=[...b.map(()=>.9),...s.filter((P,E)=>k(E)),...S.map(()=>.9)];r.splice(0,r.length,...M),i.splice(0,i.length,...v),o.splice(0,o.length,..._),s.splice(0,s.length,...q)}const f=Lt(i,o).map(g=>g.map(([d,w])=>{const y=e.toUv(d,w);return[+y.u.toFixed(5),+y.v.toFixed(5)]})),u=r.map((g,d)=>[g,...f[d].flat(),s[d]]),l=m.surface?.t??u[0][0];let p=0;return u.forEach((g,d)=>{Math.abs(g[0]-l)<Math.abs(u[p][0]-l)&&(p=d)}),{...m,frames:u,surface:{t:u[p][0],pts:f[p]}}}finally{e.close()}}async function ce(t,a){const m=C.getState(),n=m.clips.find(s=>s.id===t),e=n?.pendingPin;if(!n||!e)return{clipId:t,ok:!1,message:A("Không còn lớp cần gắn.")};const h=s=>(C.setState(f=>({clips:f.clips.map(u=>u.id===t&&u.pendingPin===e?{...u,pendingPin:void 0}:u)})),{clipId:t,ok:!1,message:s}),o=m.clips.find(s=>s.id===e.source);if(!o||o.kind!=="video")return h(A("“{0}”: không tìm thấy video để bám.",[n.label]));const i=document.querySelector(`video[data-clip-media="${o.id}"]`)?.currentSrc||o.url;if(e.mode==="scene")return ie(n,o,i,e,h,a);if(e.mode==="trail")return oe(n,o,i,e,h,a);if(e.mode==="bolt")return ae(n,o,i,e,h,a);const c=gt(n,o,e.at),r=B(e.region);try{const s=await re(o,i,e.region,c.from);let f=s.moved?"nearby":"region";const u=o.sceneTrack?.mode==="free"&&o.sceneTrack.key===Dt(o,i)?o.sceneTrack:null;let l=s.score>=yt||u?await ht(o,i,B(s.region),c,u):null,p=B(s.region);const g={plane:l?.quality??null};if((e.mode==="camera3d"||e.mode==="point")&&(!l||l.quality.weak)){const F=await ne(o,i,c);g.frame=F.quality,(!l||F.quality.score>l.quality.score*1.25+.05)&&(l=F,p=B(ct),f="frame")}if(!l||!l.mw||!l.runs.some(F=>F.frames.length))throw Error("FLAT");let d=wt({v:1,mw:l.mw,mh:l.mh,mode:"perspective",frames:[]},c.from,p);for(const F of l.runs)d=kt(d,F.frames,c.from,F.dir);f!=="region"&&(d=tt(d,c.from,r));const{width:w,height:y}=R(C.getState().timelineFormat),b=te({...o,planar:d},w,y,c.from,r);if(b&&(d=tt(d,c.from,b.surface)),e.mode==="plane"){const F=await se(o,i,d,c).catch(()=>null);F&&(d=F)}const S=C.getState(),T=S.clips.find(F=>F.id===t),x=S.clips.find(F=>F.id===o.id);if(!T||T.pendingPin!==e||!x)return{clipId:t,ok:!1,message:A("Timeline đã thay đổi. Hãy thử lại.")};const{patch:k,solve:M,follow:v}=Mt(T,x.id,e.mode);if(k.pin?.scene){const F=await Qt(x,d,i).catch(()=>null);k.pin={...k.pin,...b?{lens:b.fov}:{},...F?{light:F}:{}}}const _=C.getState(),q=_.clips.find(F=>F.id===t),P=_.clips.find(F=>F.id===o.id);if(!q||q.pendingPin!==e||!P)return{clipId:t,ok:!1,message:A("Timeline đã thay đổi. Hãy thử lại.")};let E=k,N=_.timelineCamera;if(v){const{width:F,height:I}=R(_.timelineFormat);E={...k,...bt(q,{...P,planar:d},F,I)}}if(M){const{width:F,height:I}=R(_.timelineFormat),X=xt({...P,planar:d},F,I,N,b?{zoom:I/2/Math.tan(b.fov*Math.PI/360)/(5*vt(F,I))}:{});N?.motionKeys?.length||(N=X.camera),E={...k,...q.kind==="model"?St(X.plane,F,I):Pt(X.plane,F,{fill:.6})}}const O=k.pin&&!k.pin.scene?Ft({...q,...E},P,d,_.timelineFormat?.fps||30):null;O&&(E={...E,...O}),a?.(),C.setState(F=>({timelineCamera:N,clips:F.clips.map(I=>I.id===P.id&&!v?{...I,planar:d}:I.id===t?{...I,...E}:I)}));const K=l.runs.find(F=>F.lostAt!==null&&F.frames.length),D=d.frames.length,$=f==="region"?"":f==="nearby"?A(" (vùng được dời sang chỗ nhiều chi tiết hơn)"):A(" (bám theo chuyển động cả khung hình)"),H=O?A(" Lớp hiện từ giây {0} đến {1} — đúng các khung thấy trọn mặt phẳng.",[O.start.toFixed(2),(O.start+O.duration).toFixed(2)]):"";return{clipId:t,ok:!0,path:f,quality:g,message:(K&&!O?A("“{0}” đã dính vào cảnh ({1} khung) — mất mặt phẳng ở giây {2}; sửa góc ở tab Roto rồi track tiếp.",[n.label,D,(K.lostAt+o.start).toFixed(2)]):A("“{0}” đã dính vào cảnh: track {1} khung trên “{2}”.",[n.label,D,o.label]))+$+H}}catch(s){const f=s.message,u=f==="FLAT"?A("vùng này quá trơn để track — chọn mặt phẳng có nhiều chi tiết hơn"):["NO_TRACK","NOT_PERSPECTIVE","DEGENERATE","OUT_OF_RANGE"].includes(f)?A("không dựng được camera 3D từ track ({0})",[f]):f;return h(A("“{0}” chưa dính vào cảnh: {1}.",[n.label,u]))}}function Ie({ids:t,checkpoint:a,skipRunning:m=!1}={}){const n=C.getState().clips.filter(e=>e.pendingPin&&(!t||t.includes(e.id))&&!(m&&G.has(e.id))).map(e=>e.id);return Promise.all(n.map(e=>{let h=G.get(e);return h||(h=ce(e,a).finally(()=>G.delete(e)),G.set(e,h)),h}))}export{Ie as runSurfacePins,se as snapPlanarToEdges};
@@ -1,2 +0,0 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/api-CJ8PdbfZ.js","assets/titleFrameBudget-CLZWaFHO.js"])))=>i.map(i=>d[i]);
2
- import{PMREMGenerator as he,SRGBColorSpace as ke,Texture as de,CanvasTexture as le,Group as k,MeshStandardMaterial as B,Color as ue,BoxGeometry as q,Mesh as p,PlaneGeometry as N,CircleGeometry as pe,MeshBasicMaterial as Z,CylinderGeometry as Oe,ExtrudeGeometry as Ee,ShapeGeometry as Fe,Shape as Te,Vector3 as l,Euler as $,Quaternion as A,Matrix4 as H,PerspectiveCamera as me,Raycaster as fe,Vector2 as we,Plane as _,Scene as Le,WebGLRenderer as Ie,HemisphereLight as qe,DirectionalLight as De,NoToneMapping as Re,PCFShadowMap as je,ShadowMaterial as Ve,ACESFilmicToneMapping as _e,Box3 as P,AnimationMixer as Ge,Matrix3 as Be,BufferGeometry as ne,BufferAttribute as X,ShaderMaterial as We,Points as Ue,GridHelper as Ye,LoopRepeat as Xe,Line as Ke,LineBasicMaterial as Ne}from"./three.module-Bx43vjkH.js";import{G as se}from"./GLTFLoader-BHWu1lKg.js";import{az as Qe}from"./api-CJ8PdbfZ.js";import{lW as R,_ as Je,ee as K,lX as Ze,lY as $e,f9 as He,fb as et,cd as tt,fr as ye,fA as oe,fB as nt,lZ as st,l_ as ot,l$ as it,m0 as at,m1 as rt,m2 as ct,lV as ht}from"./titleFrameBudget-CLZWaFHO.js";import{R as ge}from"./RoomEnvironment-Dmv_G5ka.js";const dt=new Map;async function lt(a){try{const e=await(await Je(async()=>{const{signOutput:t}=await import("./api-CJ8PdbfZ.js").then(n=>n.c2);return{signOutput:t}},__vite__mapDeps([0,1]))).signOutput({gcsUri:a});return typeof e=="string"&&e?e:null}catch{return null}}function xe(a,e,t){const n=new Te,s=-a/2,o=-e/2;return t=Math.min(t,a/2,e/2),n.moveTo(s+t,o),n.lineTo(s+a-t,o),n.quadraticCurveTo(s+a,o,s+a,o+t),n.lineTo(s+a,o+e-t),n.quadraticCurveTo(s+a,o+e,s+a-t,o+e),n.lineTo(s+t,o+e),n.quadraticCurveTo(s,o+e,s,o+e-t),n.lineTo(s,o+t),n.quadraticCurveTo(s,o,s+t,o),n}function C(a,e,t){const n=new Fe(xe(a,e,t),12),s=n.attributes.uv,o=n.attributes.position;for(let i=0;i<s.count;i++)s.setXY(i,o.getX(i)/a+.5,o.getY(i)/e+.5);return n}function T(a,e,t,n,s=.012){const o=new Ee(xe(a-s*2,e-s*2,Math.max(.001,n-s)),{depth:t-s*2,bevelEnabled:!0,bevelThickness:s,bevelSize:s,bevelSegments:4,curveSegments:14});return o.translate(0,0,-(t-s*2)/2),o}const S=(a,e=.32)=>new B({color:a,metalness:.85,roughness:e}),G=()=>new B({color:"#050506",metalness:.2,roughness:.08}),ie=a=>new B({color:a,metalness:.1,roughness:.75}),W=()=>new Z({color:"#ffffff",toneMapped:!1});function ae(a,{w:e,h:t,d:n,r:s,bezel:o,island:i,lenses:r}){const c=new k;c.add(new p(T(e,t,n,s),S(a)));const h=new p(C(e-.012,t-.012,s-.006),G());h.position.z=n/2+.0015,c.add(h);const m=e-o*2,d=t-o*2,f=new p(C(m,d,Math.max(.01,s-o)),W());if(f.position.z=n/2+.003,c.add(f),i){const u=new p(C(m*.3,d*.032,d*.016),new Z({color:"#000"}));u.position.set(0,d/2-d*.035,n/2+.004),c.add(u)}if(r){const u=new p(T(e*.42,e*.42,.02,e*.1,.006),G());u.position.set(-e/2+e*.27,t/2-e*.27,-n/2-.008),c.add(u);for(let g=0;g<r;g++){const M=g*2*Math.PI/Math.max(1,r)+.6,x=new p(new Oe(e*.075,e*.08,.018,28),S("#2a2a2c",.2));x.rotation.x=Math.PI/2,x.position.set(u.position.x+Math.cos(M)*e*.09,u.position.y+Math.sin(M)*e*.09,-n/2-.022),c.add(x);const w=new p(new pe(e*.05,24),G());w.rotation.y=Math.PI,w.position.set(x.position.x,x.position.y,-n/2-.0315),c.add(w)}}for(const[u,g]of[[t*.22,t*.08],[t*.09,t*.08]]){const M=new p(new q(.008,g,n*.35),S(a));M.position.set(-e/2-.002,u,0),c.add(M)}const v=new p(new q(.008,t*.12,n*.35),S(a));return v.position.set(e/2+.002,t*.14,0),c.add(v),{object:c,screen:f,screenAspect:m/d}}function ut(a,e){const t=new k,n=1.8,s=1.22,o=.045,i=new p(T(n,s,o,.06),S(a));i.rotation.x=-Math.PI/2,t.add(i);const r=new p(C(n*.86,s*.42,.02),ie("#111214"));r.rotation.x=-Math.PI/2,r.position.set(0,o/2+.001,-s*.15),t.add(r);const c=new q(n*.86/15*.82,.006,s*.42/6*.78),h=ie("#1b1c1f");for(let O=0;O<6;O++)for(let E=0;E<15;E++){const F=new p(c,h);F.position.set(-n*.43+(E+.5)*n*.86/15,o/2+.004,-s*.15-s*.21+(O+.5)*s*.42/6),t.add(F)}const m=new p(C(n*.36,s*.26,.025),S(a,.5));m.rotation.x=-Math.PI/2,m.position.set(0,o/2+.0012,s*.27),t.add(m);const d=new k;d.position.set(0,o/2,-s/2),t.add(d);const f=1.16,v=.022,u=new k;u.position.set(0,f/2,0),d.add(u),u.add(new p(T(n,f,v,.05),S(a)));const g=new p(C(n-.01,f-.01,.045),G());g.position.z=v/2+.0015,u.add(g);const M=n-.09,x=f-.1,w=new p(C(M,x,.012),W());w.position.set(0,.01,v/2+.003),u.add(w);const y=new p(new pe(.07,40),S("#e9e9ea",.15));y.rotation.y=Math.PI,y.position.z=-v/2-.002,u.add(y);const z=Math.max(0,Math.min(1,e));return d.rotation.x=(1-z)*Math.PI/2-z*.26,{object:t,screen:w,screenAspect:M/x}}function pt(a){const e=new k,t=1.8,n=1.04,s=.035;e.add(new p(T(t,n,s,.02,.006),S(a,.45)));const o=t-.04,i=n-.04,r=new p(C(o,i,.006),W());r.position.z=s/2+.002,e.add(r);const c=new p(new q(.12,.32,.04),S(a,.4));c.position.set(0,-n/2-.14,-.05),e.add(c);const h=new p(T(.62,.26,.025,.08,.006),S(a,.4));return h.rotation.x=-Math.PI/2,h.position.set(0,-n/2-.3,-.02),e.add(h),{object:e,screen:r,screenAspect:o/i}}function mt(a){const e=new k,t=1.2,n=1.6,s=.42,o=new B({color:new ue(a).multiplyScalar(.62),metalness:0,roughness:.85}),i=new q(t,n,s);e.add(new p(i,o));const r=new p(new N(t*.98,n*.98),W());return r.position.z=s/2+.002,e.add(r),{object:e,screen:r,screenAspect:t/n}}function ft(a){const e=a.color??(a.type==="box"?R.white:a.type==="tv"?R.black:a.type==="laptop"?R.silver:R.titanium);switch(a.type){case"phone":return ae(e,{w:.83,h:1.8,d:.075,r:.13,bezel:.032,island:!0,lenses:3});case"tablet":return ae(e,{w:1.35,h:1.8,d:.06,r:.09,bezel:.05,island:!1,lenses:1});case"laptop":return ut(e,a.open??1);case"tv":return pt(e);default:return mt(e)}}const re=new WeakMap;function wt(a){let e=re.get(a);if(!e){const t=new he(a);e=t.fromScene(new ge,0,.1,100,{size:64}).texture,t.dispose(),re.set(a,e)}return e}class yt{constructor(e,t,n){this.mesh=e,this.aspect=t,this.media=n;const s=o=>n.kind==="video"?this.loadVideo(o):this.loadImage(o);this.ready=n?.url?s(n.url).catch(async o=>{const i=n.gcsUri?await lt(n.gcsUri):null;if(!i||i===n.url)throw o;return s(i)}):Promise.resolve(),n?.url||e.material.color.set("#0d0f12")}texture=null;video=null;ready;whenReady(){return this.ready}fit(e,t){const n=this.texture,s=e/t;s>this.aspect?(n.repeat.set(this.aspect/s,1),n.offset.set((1-this.aspect/s)/2,0)):(n.repeat.set(1,s/this.aspect),n.offset.set(0,(1-s/this.aspect)/2))}apply(e,t,n){e.colorSpace=ke,e.anisotropy=4,this.texture=e,this.fit(t,n);const s=this.mesh.material;s.map=e,s.needsUpdate=!0}loadImage(e){return new Promise((t,n)=>{const s=new Image;s.crossOrigin="anonymous",s.onload=()=>{this.apply(new de(s),s.naturalWidth,s.naturalHeight),this.texture.needsUpdate=!0,t()},s.onerror=()=>n(Error("Không tải được ảnh màn hình thiết bị")),s.src=e})}canvas=null;draw(){const e=this.video,t=this.canvas;!e||!t||e.readyState<2||(t.getContext("2d").drawImage(e,0,0,t.width,t.height),this.texture&&(this.texture.needsUpdate=!0))}loadVideo(e){const t=document.createElement("video");return t.crossOrigin="anonymous",t.muted=!0,t.playsInline=!0,t.preload="auto",this.video=t,new Promise((n,s)=>{t.onloadeddata=()=>{const o=Math.min(1,1280/Math.max(t.videoWidth,t.videoHeight)),i=document.createElement("canvas");i.width=Math.max(2,Math.round(t.videoWidth*o)),i.height=Math.max(2,Math.round(t.videoHeight*o)),this.canvas=i,this.apply(new le(i),t.videoWidth,t.videoHeight),this.draw(),n()},t.onerror=()=>s(Error("Không tải được video màn hình thiết bị")),t.src=e})}async sync(e,t=!1){const n=this.video,s=this.media;if(!n||!s||!this.texture)return;const o=Number.isFinite(n.duration)&&n.duration>0?n.duration:0;let i=(s.inPoint||0)+Math.max(0,e)*(s.speed||1);if(o&&(i=Math.min(i,o-.04)),Math.abs(n.currentTime-i)>(t?.004:.12)){const r=new Promise(c=>{const h=()=>{n.removeEventListener("seeked",h),c()};n.addEventListener("seeked",h),setTimeout(h,t?4e3:600)});if(n.currentTime=i,t)await r;else{r.then(()=>this.draw());return}}this.draw()}dispose(){this.texture?.dispose(),this.video&&(this.video.removeAttribute("src"),this.video.load(),this.video=null)}}const gt=1.8,b=Math.PI/180;function I(a,e,t,n,s){if(He(t)&&a.is3D!==!1){const o=ye(n,s),i=et(t,a.start+Math.max(0,e),n,s),r=c=>new l(i.R[0][c],-i.R[1][c],-i.R[2][c]);return{pos:new l(i.pos[0]/o,-i.pos[1]/o,-i.pos[2]/o),quat:new A().setFromRotationMatrix(new H().makeBasis(r(0),r(1).negate(),r(2).negate())),fov:2*Math.atan(s/2/i.f)/b,on:!0}}return{pos:new l(0,0,5),quat:new A,fov:40,on:!1}}function Q(a,e,t,n,s){const o=tt(a,Math.max(0,e),n,s);if(t.on){const r=ye(n,s);return{pos:new l(o.x*n/r,-o.y*s/r,o.depth),zoom:o.zoom}}const i=2*(5-o.depth)*Math.tan(t.fov*b/2);return{pos:new l(o.x*i*(n/s),-o.y*i,o.depth),zoom:o.zoom}}function ve(a){const e=a.modelRotation||{x:0,y:0,z:0};return new l(0,1,0).applyEuler(new $(e.x*b,e.y*b,e.z*b)).normalize()}function Me(a,e,t,n,s){const o=Math.min(48,Math.max(2,Math.ceil(a.duration/.1)));let i=1/0;for(let r=0;r<=o;r++){const c=a.duration*r/o;i=Math.min(i,Q(a,c,I(a,c,t,n,s),n,s).pos.dot(e))}return i}function xt(a,e,t,n,s,o){const i=new me(a.fov,s/o,.01,100);i.position.copy(a.pos),i.quaternion.copy(a.quat),i.updateMatrixWorld(!0),i.updateProjectionMatrix();const r=new fe;return r.setFromCamera(new we(e[0]*2-1,1-e[1]*2),i),r.ray.intersectPlane(new _(t.clone(),-n),new l)}function vt(a,e,t,n,s,o,i){const r=I(a,e,t,n,s),{pos:c,zoom:h}=Q(a,e,r,n,s),m={x:K(a,"rx",e),y:K(a,"ry",e),z:K(a,"rz",e)},d=a.modelSpin||{x:0,y:0,z:0},f=(a.inPoint||0)+e,v=new $((m.x+d.x*f)*b,(m.y+d.y*f)*b,(m.z+d.z*f)*b),u=ve(a),g=gt*h,x=!!a.modelLaunch||!!a.modelLook?i??Me(a,u,t,n,s):null,w=a.modelLaunch,y=w?Ze(w,e):null;if(w&&y){const E=Q(a,w.at,I(a,w.at,t,n,s),n,s).pos,F=E.clone().addScaledVector(u,x-E.dot(u)),ee=xt(I(a,w.at+w.duration,t,n,s),w.to,u,x,n,s)??F.clone(),ze=F.clone().lerp(ee,y.g),L=ee.clone().sub(F);L.addScaledVector(u,-L.dot(u));const Ae=$e(y,L.length()/g);let D;if(w.face!==!1&&L.lengthSq()>1e-8){const Y=L.normalize(),te=new l().crossVectors(u,Y).normalize(),Ce=new l().crossVectors(Y,te);D=new A().setFromRotationMatrix(new H().makeBasis(te,Ce,Y))}else D=new A().setFromEuler(v);D.multiply(new A().setFromAxisAngle(new l(1,0,0),-Ae*b)).multiply(new A().setFromAxisAngle(new l(0,0,1),y.roll*b));const U=y.jolt*.035*g,Pe=new l(Math.sin(e*91)*U,Math.sin(e*67+1)*U*.6,Math.sin(e*53+2)*U);return{cam:r,pos:ze.addScaledVector(u,o*h+y.h*g).add(Pe),quat:D,zoom:h,N:u,d:x,len:g}}const z=new A().setFromEuler(v),O=c.clone();return a.modelGround&&O.add(new l(0,1,0).applyQuaternion(z).multiplyScalar(o*h)),{cam:r,pos:O,quat:z,zoom:h,N:u,d:x,len:g}}function Mt(a,e,t){const n=new l(1,0,0).applyQuaternion(t.quat),o=e.clone().cross(n).normalize().clone().negate(),i=new l().crossVectors(e,o).normalize(),r=a.azimuth*b,c=a.elevation*b;return o.multiplyScalar(Math.cos(c)*Math.cos(r)).addScaledVector(i,Math.cos(c)*Math.sin(r)).addScaledVector(e,Math.sin(c)).normalize()}const be=new Map,J=new Set,bt=a=>a?be.get(a):void 0;function St(a){return J.add(a),()=>{J.delete(a)}}const ce=(a,e)=>a.name||`Animation ${e+1}`,Se=new Map,zt=a=>a?Se.get(a):void 0,j=600,At="attribute float aAlpha;attribute float aSize;varying float vA;uniform float uScale;void main(){vA=aAlpha;vec4 mv=modelViewMatrix*vec4(position,1.);gl_PointSize=aSize*uScale/max(.05,-mv.z);gl_Position=projectionMatrix*mv;}",Pt="uniform vec3 uColor;varying float vA;void main(){vec2 d=gl_PointCoord-.5;float r=length(d);if(r>.5)discard;gl_FragColor=vec4(uColor,vA*smoothstep(.5,.05,r));}";let V=null;function Ct(){if(V)return V;const a=document.createElement("canvas");a.width=a.height=128;const e=a.getContext("2d"),t=e.createRadialGradient(64,64,0,64,64,64);return t.addColorStop(0,"rgba(0,0,0,1)"),t.addColorStop(.35,"rgba(0,0,0,.75)"),t.addColorStop(.7,"rgba(0,0,0,.22)"),t.addColorStop(1,"rgba(0,0,0,0)"),e.fillStyle=t,e.fillRect(0,0,128,128),V=new le(a),V}class kt{canvas;renderer;scene=new Le;camera=new me(40,1,.01,100);halfY=0;group=new k;disposed=!1;mixer=null;clips=[];action=null;rest=[];width;height;screen=null;pieces=[];dust=null;cut=[new _,new _];guides=null;buildOn=!1;constructor(e,t){this.width=e,this.height=t,this.renderer=new Ie({alpha:!0,antialias:!0,preserveDrawingBuffer:!0}),this.renderer.setPixelRatio(1),this.renderer.setSize(e,t,!1),this.renderer.setClearColor(0,0),this.canvas=this.renderer.domElement,this.camera.aspect=e/t,this.camera.position.set(0,0,5),this.camera.lookAt(0,0,0),this.camera.updateProjectionMatrix(),this.scene.add(this.group,this.hemi,this.key,this.key.target),this.key.position.set(3,5,5)}hemi=new qe(16777215,7829367,3);key=new De(16777215,3);catcher=null;contact=null;lookEnv=null;lookOn=!1;groundCache=null;applyLook(e){const t=this.renderer;if(!e){if(!this.lookOn)return;this.lookOn=!1,t.shadowMap.enabled=!1,t.toneMapping=Re,t.toneMappingExposure=1,this.hemi.color.set(16777215),this.hemi.groundColor.set(7829367),this.hemi.intensity=3,this.key.color.set(16777215),this.key.intensity=3,this.key.castShadow=!1,this.key.position.set(3,5,5),this.key.target.position.set(0,0,0),this.scene.environment===this.lookEnv&&(this.scene.environment=null),this.catcher&&(this.catcher.visible=!1),this.contact&&(this.contact.visible=!1);return}if(!this.lookOn&&(this.lookOn=!0,t.shadowMap.enabled=!0,t.shadowMap.type=je,this.key.castShadow=!0,this.key.shadow.mapSize.set(2048,2048),this.key.shadow.bias=-4e-4,this.key.shadow.normalBias=.02,this.group.traverse(n=>{const s=n;s.isMesh&&(s.castShadow=!0,s.receiveShadow=!0)}),this.catcher||(this.catcher=new p(new N(1,1),new Ve({opacity:.4,depthWrite:!1})),this.catcher.receiveShadow=!0,this.catcher.renderOrder=-2,this.scene.add(this.catcher)),this.contact||(this.contact=new p(new N(1,1),new Z({map:Ct(),transparent:!0,depthWrite:!1,color:0})),this.contact.renderOrder=-1,this.scene.add(this.contact)),!this.lookEnv&&!this.screen)){const n=new he(t);this.lookEnv=n.fromScene(new ge,.04,.1,100,{size:128}).texture,n.dispose()}t.toneMapping=_e,t.toneMappingExposure=e.exposure,!this.screen&&this.lookEnv&&(this.scene.environment=this.lookEnv),this.scene.environmentIntensity=e.env,this.hemi.color.set(e.ambient),this.hemi.groundColor.set(e.ambient).multiplyScalar(.45),this.hemi.intensity=e.ambientIntensity,this.key.color.set(e.color),this.key.intensity=e.intensity,this.key.shadow.radius=1+e.softness*9,this.key.shadow.blurSamples=8+Math.round(e.softness*16),this.catcher.material.opacity=e.shadow,this.catcher.visible=e.shadow>0}groundFor(e,t){const n=JSON.stringify([e.id,e.start,e.duration,e.posX,e.posY,e.spatialDepth,e.modelDepth,e.scale,e.motionKeys,e.modelRotation,e.parentId,t?JSON.stringify(t):""]);if(this.groundCache?.key===n)return this.groundCache.d;const s=Me(e,ve(e),t,this.width,this.height);return this.groundCache={key:n,d:s},s}async load(e){const t=await Qe(e);this.add(await new se().loadAsync(t),e)}async loadBuffer(e,t){this.add(await new se().parseAsync(e,""),t)}async loadDevice(e){if(!e.device)throw Error("Không phải thiết bị 3D");const t=ft(e.device);this.scene.environment=wt(this.renderer),this.addObject(t.object),!this.disposed&&(this.screen=new yt(t.screen,t.screenAspect,e.deviceScreen),await this.screen.whenReady())}async prepare(e){await this.screen?.sync(e,!0)}addObject(e){if(this.disposed){this.disposeObject(e);return}const t=new P().setFromObject(e),n=t.getSize(new l),s=Math.max(n.x,n.y,n.z);e.scale.setScalar(1.8/s),e.updateMatrixWorld(!0),this.halfY=n.y*1.8/s/2,e.position.sub(new P().setFromObject(e).getCenter(new l)),e.updateMatrixWorld(!0),this.group.add(e)}add(e,t){if(this.disposed){this.disposeObject(e.scene);return}const s=new P().setFromObject(e.scene).getSize(new l),o=Math.max(s.x,s.y,s.z);if(!Number.isFinite(o)||o<=0)throw Error("GLB không có hình học hợp lệ");e.scene.scale.setScalar(1.8/o),e.scene.updateMatrixWorld(!0);const i=new P().setFromObject(e.scene).getCenter(new l);e.scene.position.sub(i),e.scene.updateMatrixWorld(!0),this.halfY=s.y*1.8/o/2,this.group.add(e.scene),this.clips=e.animations||[],this.clips.length&&(this.mixer=new Ge(e.scene),e.scene.traverse(r=>{r!==e.scene&&this.rest.push({o:r,p:r.position.clone(),q:r.quaternion.clone(),s:r.scale.clone()})})),this.collectPieces(e.scene),Se.set(t,this.pieces.length),be.set(t,this.clips.map((r,c)=>({name:ce(r,c),duration:r.duration}))),J.forEach(r=>r())}collectPieces(e){this.group.updateMatrixWorld(!0);const t=[];e.traverse(c=>{c.isMesh&&t.push(c)});const n=new P().setFromObject(e),s=c=>{const h=c.getSize(new l);return h.x*h.y*h.z},o=s(n)*.02,i=n.getSize(new l),r=i.x*i.z;for(const c of t.slice(0,oe.maxPieces)){const h=new P().setFromObject(c),m=h.getCenter(new l),d=h.getSize(new l),f=new H().copy(c.parent.matrixWorld).invert();this.pieces.push({o:c,p:c.position.clone(),q:c.quaternion.clone(),s:c.scale.clone(),toParent:new Be().setFromMatrix4(f),box:{bottom:h.min.y,cx:m.x,cz:m.z,h:d.y,r:Math.max(d.x,d.z)/2,big:s(h)>o,base:d.x*d.z>=r*.25&&h.min.y<=n.min.y+i.y*.03}})}}build(e,t){let n=null;try{n=e.modelBuild?nt(e.modelBuild):null}catch{n=null}const s=new Set;this.group.traverse(i=>{const r=i.material;if(r)for(const c of Array.isArray(r)?r:[r])s.add(c)});const o=[];if(n){const i=st(this.pieces.map(h=>h.box),n);this.pieces.forEach((h,m)=>{const d=ot(n.style,h.box,i[m],t,m,n.seed);h.o.position.copy(h.p),h.o.quaternion.copy(h.q),h.o.scale.copy(h.s),h.o.visible=d.visible,(d.dx||d.dy||d.dz)&&h.o.position.add(new l(d.dx,d.dy,d.dz).applyMatrix3(h.toParent)),(d.rx||d.ry||d.rz)&&h.o.quaternion.multiply(new A().setFromEuler(new $(d.rx,d.ry,d.rz)))}),this.group.updateMatrixWorld(!0);const r=new l(0,1,0).applyQuaternion(this.group.getWorldQuaternion(new A)).normalize();it(n,t)&&o.push(this.cut[0].setFromNormalAndCoplanarPoint(r,this.group.localToWorld(new l(0,-this.halfY,0))));const c=at(n,t,this.halfY);c!==null&&o.push(this.cut[1].setFromNormalAndCoplanarPoint(r.clone().negate(),this.group.localToWorld(new l(0,c,0)))),this.dustAt(rt(this.pieces.map(h=>h.box),i,n,t,j),n.dustColor),this.buildOn=!0}else{for(const i of this.pieces)i.o.position.copy(i.p),i.o.quaternion.copy(i.q),i.o.scale.copy(i.s),i.o.visible=!0;this.dustAt([],oe.dustColor),this.buildOn=!1}this.renderer.localClippingEnabled=o.length>0;for(const i of s){const r=o.length?o:null;i.clippingPlanes!==r&&(i.clippingPlanes?.length||r)&&(i.clippingPlanes=r,i.needsUpdate=!0)}}dustAt(e,t){if(!e.length&&!this.dust)return;if(!this.dust){const r=new ne;r.setAttribute("position",new X(new Float32Array(j*3),3)),r.setAttribute("aAlpha",new X(new Float32Array(j),1)),r.setAttribute("aSize",new X(new Float32Array(j),1));const c=new We({uniforms:{uColor:{value:new ue(t)},uScale:{value:this.height*1.2}},vertexShader:At,fragmentShader:Pt,transparent:!0,depthWrite:!1});this.dust=new Ue(r,c),this.dust.frustumCulled=!1,this.group.add(this.dust)}const n=this.dust.geometry,s=n.getAttribute("position"),o=n.getAttribute("aAlpha"),i=n.getAttribute("aSize");e.forEach((r,c)=>{s.setXYZ(c,r[0],r[1],r[2]),o.setX(c,r[3]),i.setX(c,r[4])}),n.setDrawRange(0,e.length),s.needsUpdate=o.needsUpdate=i.needsUpdate=!0,this.dust.material.uniforms.uColor.value.set(t)}setGuides(e,t=4){if(!e){this.guides&&(this.scene.remove(this.guides),this.disposeObject(this.guides),this.guides=null);return}if(this.guides)return;const n=new k,s=new Ye(t,16,6742271,2781056);s.rotation.x=Math.PI/2;for(const i of Array.isArray(s.material)?s.material:[s.material])i.transparent=!0,i.opacity=.85,i.depthWrite=!1;const o=(i,r)=>new Ke(new ne().setFromPoints([new l,i]),new Ne({color:r}));n.add(s,o(new l(.5,0,0),16731469),o(new l(0,.5,0),5111674),o(new l(0,0,.5),5086207)),this.guides=n,this.scene.add(n)}surfaceAt(e,t){const n=new fe;n.setFromCamera(new we(e/this.width*2-1,1-t/this.height*2),this.camera);const s=n.ray.intersectPlane(new _(new l(0,0,1),0),new l);return s?{x:s.x,y:s.y}:null}pose(e,t){if(!this.mixer)return;const n=e.modelAnim,s=n?this.clips.find((i,r)=>ce(i,r)===n.clip):void 0;if(!n||!s){if(this.action){this.mixer.stopAllAction(),this.action=null;for(const i of this.rest)i.o.position.copy(i.p),i.o.quaternion.copy(i.q),i.o.scale.copy(i.s)}return}const o=this.mixer.clipAction(s);this.action!==o&&(this.mixer.stopAllAction(),o.setLoop(Xe,1/0),o.play(),this.action=o),o.time=ct(n,s.duration,t,e.inPoint||0),this.mixer.update(0)}render(e,t,n=!1,s){const o=e.modelLook?ht(e.modelLook):null;this.applyLook(o);const i=this.width,r=this.height,c=e.modelLook||e.modelLaunch?this.groundFor(e,s):void 0,h=vt(e,t,s,i,r,this.halfY,c);this.camera.position.copy(h.cam.pos),this.camera.quaternion.copy(h.cam.quat),this.camera.fov=h.cam.fov,this.camera.updateProjectionMatrix(),this.camera.updateMatrixWorld(!0),this.group.scale.setScalar(h.zoom),this.group.quaternion.copy(h.quat),this.group.position.copy(h.pos),this.pose(e,t),(e.modelBuild||this.buildOn)&&this.build(e,t),o&&this.placeShadows(e,o,h.N,h.d??0,h.len,s),n&&this.screen?.sync(t),this.renderer.render(this.scene,this.camera),n&&this.publish(e.id)}placeShadows(e,t,n,s,o,i){const r=this.group.getWorldPosition(new l),c=r.dot(n)-s,h=r.clone().addScaledVector(n,-c),m=new A().setFromUnitVectors(new l(0,0,1),n),d=Math.max(0,c-this.halfY*this.group.scale.x),f=Math.max(6*o,d*4+3*o);this.catcher.position.copy(h).addScaledVector(n,.001*o),this.catcher.quaternion.copy(m),this.catcher.scale.set(f,f,1);const v=new P().setFromObject(this.group),u=v.getSize(new l),g=Math.max(.2*o,Math.hypot(u.x,u.y,u.z)-Math.abs(u.clone().dot(n)))*.62,M=Math.max(0,1-d/(.8*o));this.contact.visible=t.contact>0&&M>0,this.contact.position.copy(h).addScaledVector(n,.002*o),this.contact.quaternion.copy(m),this.contact.scale.set(g*(1+d/o),g*.75*(1+d/o),1),this.contact.material.opacity=t.contact*.85*M;const x=Mt(t,n,I(e,0,i,this.width,this.height)),w=12*o;this.key.target.position.copy(h),this.key.position.copy(h).addScaledVector(x,w),this.key.target.updateMatrixWorld();const y=this.key.shadow.camera,z=f*.6;y.left=-z,y.right=z,y.top=z,y.bottom=-z,y.near=Math.max(.01,w-4*o-d),y.far=w+4*o+d,y.updateProjectionMatrix()}publish(e){const t=new P().setFromObject(this.group);if(t.isEmpty())return;let n=1/0,s=1/0,o=-1/0,i=-1/0;for(const r of[t.min.x,t.max.x])for(const c of[t.min.y,t.max.y])for(const h of[t.min.z,t.max.z]){const m=new l(r,c,h).project(this.camera),d=(m.x+1)/2*this.width,f=(1-m.y)/2*this.height;n=Math.min(n,d),o=Math.max(o,d),s=Math.min(s,f),i=Math.max(i,f)}dt.set(e,{cx:(n+o)/2,cy:(s+i)/2,w:o-n,h:i-s,angle:0,W:this.width,H:this.height})}async frame(e){const t=await new Promise(o=>(e??this.canvas).toBlob(o,"image/webp",.8));if(!t)throw Error("Không xuất được frame 3D");const n=new Uint8Array(await t.arrayBuffer());let s="";for(let o=0;o<n.length;o+=16384)s+=String.fromCharCode(...n.subarray(o,o+16384));return btoa(s)}disposeObject(e){e.traverse(t=>{const n=t;n.geometry?.dispose();for(const s of n.material?Array.isArray(n.material)?n.material:[n.material]:[]){for(const o of Object.values(s))o instanceof de&&o.dispose();s.dispose()}})}dispose(){this.disposed=!0,this.screen?.dispose(),this.screen=null,this.mixer?.stopAllAction(),this.disposeObject(this.group),this.renderer.dispose(),this.canvas.remove()}}const It=Object.freeze(Object.defineProperty({__proto__:null,Timeline3DScene:kt,modelAnimations:bt,modelPieces:zt,onModelAnimations:St},Symbol.toStringTag,{value:"Module"}));export{kt as T,zt as a,dt as l,bt as m,St as o,It as t};
@@ -1 +0,0 @@
1
- import{c1 as E,eQ as M,eR as D,lV as F,eS as v}from"./titleFrameBudget-CLZWaFHO.js";import{T as C}from"./timeline3d-DOw-CpZI.js";import{wantsFrame as u,SKIPPED_FRAME as L}from"./frameSink-DeM8xC8_.js";import"./three.module-Bx43vjkH.js";import"./GLTFLoader-BHWu1lKg.js";import"./api-CJ8PdbfZ.js";import"./RoomEnvironment-Dmv_G5ka.js";const d=6;async function T(p,w,a,g,f){const{width:s,height:c,fps:r}=E(w),b=M(D(p));for(const e of p.filter(l=>l.kind==="model")){if(!u(a,"modelFrames",e.id))continue;if(!e.gcsUri&&!e.device)throw Error("Clip 3D chưa có GLB");const l=Math.ceil(e.duration*r);if(l>3600)throw Error("Mỗi clip 3D tối đa 2 phút khi xuất MP4. Hãy chia clip dài thành nhiều đoạn.");const o=new C(s,c),h=e.modelLook?F(e.modelLook).blur:e.motionBlur?.5:0,m=h>0?Object.assign(document.createElement("canvas"),{width:s,height:c}):null,t=m?.getContext("2d");try{e.device?await o.loadDevice(e):await o.load(e.gcsUri);for(let i=0;i<l;i++){if(g?.aborted)throw new DOMException("Export cancelled","AbortError");if(!u(a,"modelFrames",e.id,i)){await a.push("modelFrames",e.id,L);continue}if(v(b),await o.prepare(i/r),m&&t){t.globalCompositeOperation="copy",t.clearRect(0,0,s,c),t.globalCompositeOperation="lighter",t.globalAlpha=1/d;for(let n=0;n<d;n++){const x=Math.max(0,Math.min(e.duration,i/r+(n/(d-1)-.5)*h/r));o.render(e,x,!1,f),t.drawImage(o.canvas,0,0)}t.globalAlpha=1,t.globalCompositeOperation="source-over",await a.push("modelFrames",e.id,await o.frame(m))}else o.render(e,i/r,!1,f),await a.push("modelFrames",e.id,await o.frame());i%8===0&&await new Promise(n=>setTimeout(n,0))}}finally{o.dispose()}}}export{T as render3DFrames};
@@ -1 +0,0 @@
1
- import{f as R,au as b,io as C,eQ as nt,eR as ot,eS as Mt,jh as bt,ia as T,F as vt,fp as _t,gV as it,ee as L,h1 as at,h5 as St,gW as Pt,gY as Ot,fu as tt,jl as rt,m as E,l as A,gU as st,fe as Q,lQ as ut,lR as z,it as et,ec as G,d7 as dt,lS as lt,h as U,s as pt,i2 as $t,i3 as Et}from"./titleFrameBudget-CLZWaFHO.js";const O=1/vt,w=1e-6,X=t=>typeof t=="number"&&Number.isFinite(t);function jt(t){if(t===null)return null;if(!t||typeof t!="object"||Array.isArray(t)||Object.keys(t).some(i=>i!=="in"&&i!=="out")||!X(t.in)||!X(t.out))throw Error("Invalid export range");const n=b(t.in),e=b(t.out);if(n<0||e>R||e-n<O-w)throw Error("Invalid export range");return{in:n,out:e}}function Y(t,n){if(t==null&&n==null)return null;const e=jt({in:t??0,out:n??R});return e.in<=w&&e.out>=R-w?null:e}function Jt(t,n,e){const i=Math.max(0,Math.min(R,b(e))),o=t?.in??0,s=t?.out??R;try{return n==="in"?i>=R-O+w?void 0:Y(i,i>=s-w?null:s):i<O-w?void 0:Y(i<=o+w?null:o,i)}catch{return}}function qt(t,n,e,i){if(!(i>=O))return t??null;const o=t?.in??0,s=t?.out??R;try{if(n==="in")return Y(Math.max(0,Math.min(b(e),b(Math.min(s,i)-O))),s>=R-w?null:s);const f=Math.max(b(o+O),Math.min(b(e),i));return Y(o,f>=i-w?null:f)}catch{return t??null}}function Zt(t,n){if(!t||!X(t.in)||!X(t.out)||!(n>0))return null;const e=Math.max(0,Math.min(n,t.in)),i=Math.max(0,Math.min(n,t.out));return i-e<O-w||e<=w&&i>=n-w?null:{in:e,out:i}}function Rt(t,n,e){if(!t||!Array.isArray(t.motionKeys)||!t.motionKeys.length)return t;let i={...t,motionKeys:[]};for(const o of St){const s=Pt(t,o);if(!s.length)continue;const f=s.some(a=>a.time<n-w),l=s.some(a=>a.time>e+w),p=[...s].reverse().find(a=>a.time<=n+w);i=Ot(i,o,[...f?[{time:0,value:tt(t,o,n),...p?.ease!==void 0?{ease:p.ease}:{}}]:[],...s.filter(a=>(f?a.time>n+w:a.time>=n-w)&&(l?a.time<e-w:a.time<=e+w)).map(a=>({...a,time:Math.max(0,b(a.time-n))})),...l?[{time:b(e-n),value:tt(t,o,e)}]:[]])}return i}const At=t=>[...t.parentId?[t.parentId]:[],...Array.isArray(t.shape?.items)?t.shape.items.flatMap(n=>n?.pins&&typeof n.pins=="object"?Object.values(n.pins):[]):[]];function Ft(t,n,e,i,o,s){const f=n.find(I=>I.id===t.id)??t,l=t.start+t.duration<=e+w?t.duration:0,p=_t(f,l,o,s),a=p.sx??1,r=p.sy??1,v=it("image",t.track)?t.track:0;return{...at({id:t.id,track:v,start:0,duration:i,label:String(t.label||"Null").slice(0,160)}),posX:p.x,posY:p.y,scale:p.zoom,rotation:p.rot,anchorX:L(t,"ax",l),anchorY:L(t,"ay",l),...a!==1||r!==1?{motionKeys:[{time:0,sx:a,sy:r}]}:{}}}function J({clips:t,camera:n=null},e,{W:i=1280,H:o=720}={}){if(!e||!Array.isArray(t))return{clips:t,camera:n};const s=e.in,f=e.out,l=b(f-s),p=[];for(const m of t){if(m.start+m.duration<=s+w||m.start>=f-w)continue;let k=m;if(k.start<s-w){const g=b(s-k.start);if(k.duration-g<O-w)continue;if(g>=O-w){const _=C(k,s,`${m.id}~in`);_.length===2&&(k={..._[1],id:m.id})}}if(k.start+k.duration>f+w){const g=b(f-k.start);if(g<O-w)continue;k.duration-g>=O-w&&(k=C(k,f,`${m.id}~out`)[0])}p.push({...k,start:Math.max(0,b(k.start-s))})}const a=new Set(p.map(m=>m.id)),r=new Map(t.map(m=>[m.id,m])),v=[...new Set(p.flatMap(At))].filter(m=>!a.has(m)&&r.get(m)&&!r.get(m).disabled&&r.get(m).kind!=="audio");let I=[];if(v.length){const m=nt(ot(t.filter(k=>!k.disabled)));Mt(m),I=v.map(k=>Ft(r.get(k),m,s,l,i,o))}const y=new Set([...a,...I.map(m=>m.id)]);return{clips:[...p.map(m=>{const k=r.get(m.id),g=[];let _=m;if(m.parentId&&!y.has(m.parentId)&&g.push("parentId"),m.matte&&!a.has(m.matte.source)&&(g.push("matte"),m.matte.mode?.endsWith("-inverted")||(_={...m,opacity:0,motionKeys:bt(m,"opacity",[])})),m.transition&&k&&T(t,k)&&!T(p,m)&&g.push("transition"),m.join&&k&&T(t,k)&&!T(p,m)&&g.push("join"),!g.length)return _;_={..._};for(const F of g)delete _[F];return _}),...I],camera:Rt(n,s,f)}}const j=t=>!!t&&!!t.comp&&Array.isArray(t.comp.clips),D=">",q=t=>j(t)?1+Math.max(0,...t.comp.clips.map(q)):0,mt=t=>j(t)?t.comp.clips.reduce((n,e)=>n+1+mt(e),0):0,Tt=t=>j(t)?Math.max(0,...t.comp.clips.map(n=>n.start+n.duration)):0,ft=t=>{let n=1;for(;t.some(e=>e.label===`Comp ${n}`);)n++;return`Comp ${n}`},K=t=>String(t).padStart(3,"0"),V=["x","y","zoom","rot","ax","ay"],zt={x:0,y:0,zoom:1,rot:0,ax:0,ay:0};function Z(t){return t.parentId||V.some(n=>G(t,n).length||Math.abs(L(t,n,0)-zt[n])>1e-9)?!0:["enter","exit"].some(n=>t[n]&&t[n].type!=="fade")}const ct=t=>G(t,"opacity").length>0||["enter","exit"].some(n=>t[n]&&(t[n].type==="fade"||t[n].fade!==!1));function ht(t,n){const e=[];for(const o of t.motionKeys||[]){const s={time:o.time};for(const l of V)Number.isFinite(o[l])&&(s[l]=o[l]);if(Object.keys(s).length===1)continue;const f=o.ease&&Object.fromEntries(Object.entries(o.ease).filter(([l])=>V.includes(l)));f&&Object.keys(f).length&&(s.ease=f),e.push(s)}const i=Object.fromEntries(["posX","posY","scale","rotation","anchorX","anchorY","parentId","zIndex","enter","exit"].filter(o=>t[o]!==void 0).map(o=>[o,t[o]]));return{...at({id:n,track:t.track,start:t.start,duration:t.duration,label:t.label}),...i,motionKeys:e,_comp:t.id}}function Kt(t,n){if(Math.abs(n-1)<1e-9)return t;const e=G(t,"opacity"),i={...t,opacity:(t.opacity??1)*n};return e.length?{...i,...dt(i,"opacity",e.map(o=>({...o,value:o.value*n})))}:i}function Nt(t,n){const e=Math.max(1,Math.ceil(t.duration*60-1e-6)),i=[];for(let o=0;o<=e;o++){const s=Math.min(t.duration,o/60);i.push({time:+s.toFixed(6),value:Math.max(0,Math.min(1,L(t,"opacity",s)*n(s)))})}return{...t,...dt(t,"opacity",i)}}function W(t,n){const e={...t},i=o=>n(o);if(e.parentId!==void 0){const o=i(e.parentId);o?e.parentId=o:delete e.parentId}if(e.matte?.source!==void 0){const o=i(e.matte.source);o?e.matte={...e.matte,source:o}:delete e.matte}e._virtual!==void 0&&(e._virtual=i(e._virtual)??e._virtual),typeof e.space=="string"&&(e.space=i(e.space)??e.space);for(const o of["bend","vfx"])typeof e[o]?.source=="string"&&(e[o]={...e[o],source:i(e[o].source)??e[o].source});return Array.isArray(e.shape?.items)&&e.shape.items.some(o=>o?.pins)&&(e.shape={...e.shape,items:e.shape.items.map(o=>o?.pins&&typeof o.pins=="object"?{...o,pins:Object.fromEntries(Object.entries(o.pins).map(([s,f])=>[s,i(f)??f]))}:o)}),e}const Dt=t=>{if(t.transition===void 0&&t.join===void 0)return t;const{transition:n,join:e,...i}=t;return i};function H(t){const n=t.comp.tracks||{};return t.comp.clips.filter(e=>!e.disabled&&!(e.kind!=="audio"&&n[e.track]?.hidden)).map(e=>n[e.track]?.muted?{...e,volume:0}:e)}function kt(t,n,e,i){const o=t.inPoint||0,s=t.start-o;return J({clips:n},{in:o,out:o+t.duration},{W:e,H:i}).clips.map(l=>{const p={...l,start:b(t.start+l.start)};for(const a of["_txIn","_txOut"])p[a]&&(p[a]={...p[a],t0:p[a].t0+s});return p})}function Lt(t,n){const e=t.inPoint||0;if(U(t)&&!t.reverse)return e+pt(t,Math.max(0,Math.min(t.duration,n)));const i=t.playbackRate||1,o=Math.max(0,Math.min(t.duration,n));return e+(t.reverse?Math.max(0,t.duration-o-1/30):o)*i}function yt(t){const n=t.inPoint||0,e=U(t)&&!t.reverse?pt(t,t.duration):t.duration*(t.playbackRate||1);return{from:n,to:n+e}}function wt(t){const n=H(t),e=new Set(n.map(o=>o.id)),i=`${t.id}${D}`;return n.map(o=>({...W(o,s=>e.has(s)?i+s:null),id:i+o.id}))}function It(t,{W:n=1280,H:e=720}={}){const{from:i,to:o}=yt(t);return J({clips:wt(t)},{in:i,out:o},{W:n,H:e}).clips.map(s=>({...s,volume:0}))}function Ut(t,{W:n=1280,H:e=720}={}){const i=[],o=(s,f)=>{for(const l of s)if(l?._group&&j(l)&&f<z){const p=N(It(l,{W:n,H:e}),{W:n,H:e});i.push(p),o(p,f+1)}};return o(N(t||[],{W:n,H:e}),0),i}function Xt(t,n,e,i){if(t.reverse||U(t))return[];const o=t.playbackRate||1,s=t.inPoint||0,f=`${t.id}${D}`,l=N(H(t),{W:e,H:i,depth:n+1}).filter(a=>a.url&&(a.volume??1)>0&&(a.kind==="audio"||a.kind==="video"&&!a.freeze&&!a.reverse));return J({clips:l},{in:s,out:s+t.duration*o},{W:e,H:i}).clips.flatMap(a=>{const r=(a.playbackRate||1)*o;return r>8||U(a)&&o!==1?[]:[{...Object.fromEntries(["nodeId","url","gcsUri","label","inPoint","sourceDuration","audioFx","duck","muffle"].filter(I=>a[I]!==void 0).map(I=>[I,a[I]])),id:`${f}${a.id}~a`,kind:"audio",track:a.kind==="audio"?a.track:st[0],start:b(t.start+a.start/o),duration:Math.max(1/30,b(a.duration/o)),volume:(a.volume??1)*(t.volume??1),...r!==1?{playbackRate:r}:{},...a.speedRamp&&o===1?{speedRamp:a.speedRamp}:{},...a.audioFadeIn?{audioFadeIn:a.audioFadeIn/o}:{},...a.audioFadeOut?{audioFadeOut:a.audioFadeOut/o}:{},_comp:t.id,_slot:`§a${f}${a.id}`}]})}function xt(t,n,e){let i=n;return n.kind!=="audio"&&!n.nullLayer&&(i=e!==null?Kt(i,e):Nt(i,o=>Q(t,i.start-t.start+o).opacity)),t.volume!==void 0&&t.volume!==1&&(n.kind==="video"||n.kind==="audio")&&(i={...i,volume:(i.volume??1)*t.volume}),t.lookBypass&&(i={...i,lookBypass:!0}),i}function Yt(t,n,e,i,o){if(n>=z)return[];t={...t,...rt(t)};let s=nt(ot(H(t))).map(Dt);s=N(s,{W:e,H:i,depth:n+1});const f=kt(t,s,e,i),l=new Set(f.map(y=>y.id)),p=`${t.id}${D}`,a=o?`${p}~comp`:null,r=ct(t)?null:Q(t,0).opacity,v=[...new Set(f.filter(y=>y.kind!=="audio").map(y=>`${K((y.zIndex??0)+200)}:${K(E(y.track)+1)}`))].sort(),I=f.map(y=>{let x=W(y,m=>l.has(m)?p+m:null);return x={...xt(t,x,r),id:p+y.id,_comp:t.id,...x.parentId===void 0&&a&&y.kind!=="audio"?{parentId:a}:{}},y.kind!=="audio"?(x.track=t.track,x._slot=`§${K(v.indexOf(`${K((y.zIndex??0)+200)}:${K(E(y.track)+1)}`))}${y._slot??""}`,t.zIndex!==void 0?x.zIndex=t.zIndex:delete x.zIndex):x._slot=`§${y._slot??""}${y.id}`,x});return I.sort((y,x)=>y._slot<x._slot?-1:y._slot>x._slot?1:0),a?[ht(t,a),...I]:I}function N(t,{W:n=1280,H:e=720,depth:i=0}={}){if(!Array.isArray(t)||!t.some(r=>j(r)&&!r._group))return t;const o=new Set(t.filter(r=>r.transition).map(r=>T(t,r)?.id).filter(Boolean)),s=r=>lt(r)||o.has(r.id),f=new Set(t.filter(r=>r.parentId).map(r=>r.parentId)),l=new Set(t.filter(r=>j(r)&&!s(r)).map(r=>r.id)),p=new Map,a=[];for(const r of t){if(!j(r)||r._group){a.push(r);continue}if(r.disabled)continue;if(s(r)){i<z&&a.push({...r,_group:!0},...Xt(r,i,n,e));continue}const v=Z(r)||f.has(r.id);v&&p.set(r.id,`${r.id}${D}~comp`),a.push(...Yt(r,i,n,e,v))}return a.map(r=>{if(r.parentId&&p.has(r.parentId))return{...r,parentId:p.get(r.parentId)};if(r.matte&&l.has(r.matte.source)){const{matte:v,...I}=r;return I}return r})}function Bt(t,n,{id:e,label:i,tracks:o={},W:s=1280,H:f=720}={}){const l=new Set(n||[]),p=t.filter(u=>l.has(u.id));if(!p.length)throw Error("Precompose: select at least one layer");if(!p.some(u=>u.kind!=="audio"))throw Error("Precompose needs at least one picture layer");if(p.some(u=>o[u.track]?.locked))throw Error("Track đã khóa");if(1+Math.max(0,...p.map(q))>z)throw Error(`Comps nest at most ${z} deep`);const a=t.filter(u=>!l.has(u.id)),r=[...p.filter(u=>u.matte&&!l.has(u.matte.source)),...a.filter(u=>u.matte&&l.has(u.matte.source))];if(r.length)throw Error(`Precompose: the track matte of "${r[0].label||r[0].id}" crosses the comp's edge — take the matte layer in too, or remove the matte`);const v=b(Math.min(...p.map(u=>u.start))),I=b(Math.max(...p.map(u=>u.start+u.duration))),y=Math.max(1/30,b(I-v)),x=u=>a.some(c=>c.track===u&&c.kind!=="audio"&&c.start<I-1e-6&&c.start+c.duration>v+1e-6)||o[u]?.locked,m=[...new Set(p.filter(u=>u.kind!=="audio").map(u=>u.track))].sort((u,c)=>E(c)-E(u));let k=m.find(u=>!x(u));for(let u=E(m[0])+1;k===void 0;u++)x(A(u))||(k=A(u));const g=u=>T(t,u),_=p.map(u=>{let c={...u};return c.parentId&&!l.has(c.parentId)&&(c={...c,...et(t,u,null,0,s,f)}),c.transition&&!l.has(g(u)?.id)&&delete c.transition,c.join&&!l.has(g(u)?.id)&&delete c.join,c.parentId===void 0&&delete c.parentId,{...c,start:b(u.start-v)}}),F=a.map(u=>{let c=u;return u.parentId&&l.has(u.parentId)&&(c={...c,...et(t,u,null,0,s,f)},c.parentId===void 0&&(c={...c},delete c.parentId)),(c.transition||c.join)&&l.has(g(u)?.id)&&(c={...c},delete c.transition,delete c.join),c}),$=[...new Set(p.map(u=>u.track))].filter(u=>o[u]?.hidden||o[u]?.muted),B=Object.fromEntries($.map(u=>[u,{...o[u].hidden?{hidden:!0}:{},...o[u].muted?{muted:!0}:{}}])),P={id:e||`comp-${Date.now().toString(36)}`,nodeId:"",kind:"image",url:"",label:i||ft(t),track:k,start:v,duration:y,inPoint:0,sourceDuration:y,motionV:2,comp:{clips:_,...$.length?{tracks:B}:{}}};return{clips:[...F,P],id:P.id,track:k}}function Vt(t,n,{tracks:e={},W:i=1280,H:o=720,newId:s=()=>`null-${Math.random().toString(36).slice(2,9)}`}={}){const f=t.find(d=>d.id===n);if(!j(f))throw Error("Uncompose needs a comp layer");if(e[f.track]?.locked)throw Error("Track đã khóa");const l={...f,...rt(f)},p=t.filter(d=>d.id!==n),a=new Set(p.map(d=>d.id)),r=l.comp.tracks||{},v=l.comp.clips.map(d=>({...d,...r[d.track]?.hidden&&d.kind!=="audio"?{disabled:!0}:{},...r[d.track]?.muted?{volume:0}:{}})),I=kt(l,v,i,o),y=new Map;for(const d of I){let h=d.id,M=2;for(;a.has(h)||[...y.values()].includes(h);)h=`${d.id}-${M++}`;y.set(d.id,h)}const x=[...p],m=(d,h)=>!e[d]?.locked&&!x.some(M=>M.track===d&&h.some(S=>M.start<S.start+S.duration-1e-6&&M.start+M.duration>S.start+1e-6)),k=new Map,g=[...new Set(I.filter(d=>d.kind!=="audio").map(d=>d.track))].sort((d,h)=>E(d)-E(h)),_=d=>I.filter(h=>h.kind!=="audio"&&h.track===d),F=g.every(d=>m(d,_(d)));let $=F?E(g.at(-1)??l.track)+1:E(l.track);for(const d of g){const h=_(d);if(F){k.set(d,d),x.push(...h);continue}for(;!m(A($),h);)$++;k.set(d,A($)),x.push(...h.map(M=>({...M,track:A($)}))),$++}for(const d of[...new Set(I.filter(h=>h.kind==="audio").map(h=>h.track))]){const h=I.filter(S=>S.kind==="audio"&&S.track===d),M=[d,...st.filter(S=>S!==d)].find(S=>m(S,h));if(M===void 0)throw Error("Uncompose: no free audio row for the comp's sounds");k.set(d,M),x.push(...h.map(S=>({...S,track:M})))}const B=Z(l)||p.some(d=>d.parentId===n);let P=null;if(B){let d=$;const h=[{start:l.start,duration:l.duration}];for(;!m(A(d),h);)d++;let M=s();for(;a.has(M);)M=s();const{_comp:S,...gt}=ht(l,M);P={...gt,track:A(d),label:l.label||"Null"}}const u=ct(l)?null:Q(l,0).opacity,c=I.map(d=>{let h=W(d,M=>y.get(M)??null);if(h={...xt(l,h,u),id:y.get(d.id),track:k.get(d.track)??d.track},h.parentId===void 0&&P&&d.kind!=="audio"&&(h.parentId=P.id),!it(h.kind,h.track))throw Error("Uncompose: no free row");return h});return{clips:[...p.map(d=>d.parentId===n?P?{...d,parentId:P.id}:(({parentId:h,...M})=>M)(d):d),...P?[P]:[],...c],ids:c.map(d=>d.id),nullId:P?.id??null,dropped:ut(f)}}const Wt=Object.freeze(Object.defineProperty({__proto__:null,COMP_DEPTH:z,COMP_SEP:D,compBlockers:$t,compClipCount:mt,compContentEnd:Tt,compDepth:q,compGrouped:lt,compInner:wt,compLabel:ft,compMoves:Z,compPictureFields:ut,compRange:yt,compRenderLevel:It,compTime:Lt,expandComps:N,groupedLevels:Ut,isComp:j,precompose:Bt,stripComp:Et,uncompose:Vt},Symbol.toStringTag,{value:"Module"}));export{wt as a,Lt as b,Tt as c,Zt as d,N as e,ft as f,mt as g,qt as h,j as i,Jt as j,Y as m,Bt as p,J as s,Wt as t,Vt as u};
@@ -1 +0,0 @@
1
- import{dG as P,eI as O,dH as M,ia as R,fK as E,fM as j}from"./remote-C7J0Tqhb.js";import"./api-CJ8PdbfZ.js";import"./titleFrameBudget-CLZWaFHO.js";import"./three.module-Bx43vjkH.js";import"./GLTFLoader-BHWu1lKg.js";import"./store-DW4E9xnW.js";import"./rotoMaskStore-DPziPKAN.js";import"./textAnimators-DUZjhVGO.js";import"./timelineComp-B4GtoH2f.js";import"./rigTrack-urT3nDK0.js";const K=(t,e,i=.1)=>["X","Y","Z"].map((o,s)=>({id:t+s,label:`${e} ${o}`,step:i})),A=[...K("p","Vị trí"),...K("t","Nhìn tới"),{id:"lens",label:"Tiêu cự (mm)",step:1,min:14,max:200},{id:"roll",label:"Nghiêng (°)",step:1}],U=[...K("p","Vị trí"),...K("r","Xoay",1),{id:"s",label:"Kích thước",step:.05,min:.05}],_=K("o","Lệch"),X=[...K("p","Vị trí"),{id:"s",label:"Kích thước",step:.05,min:.05}],p=t=>t.shots.find(e=>e.id===t.activeShot)||t.shots[0];function H(t,e){if(e==="camera")return A;const i=t.items.find(o=>o.id===e);return i?i.kind==="fx"?i.fx?.attach?_:X:U:[]}function I(t,e){return e==="camera"?t.motion==="path"&&!!t.cameraKeys?.length:(t.objectKeys?.[e]?.length??0)>0}const y=t=>+t.slice(1);function J(t,e,i,o){const s=p(t);if(e==="camera"){const c=P(s,o);return i==="lens"?c.lens:i==="roll"?c.roll:(i[0]==="p"?c.position:c.target)[y(i)]}const r=t.items.find(c=>c.id===e);if(!r)return 0;if(i[0]==="o")return O(r,s,o).position[y(i)];const n=M(r,s,o);return i==="s"?n.scale[0]:(i[0]==="p"?n.position:n.rotation)[y(i)]}const C=t=>+t.toFixed(3);function q(t,e,i,o,s,r=()=>crypto.randomUUID()){const n=p(t);if(!n||!Number.isFinite(s))return t;const c=f=>({...t,shots:t.shots.map(l=>l.id===n.id?{...l,...f}:l)});if(e==="camera"){const f=P(n,o),l={position:[...f.position],target:[...f.target],roll:f.roll};return i==="roll"?l.roll=s:i!=="lens"&&((i[0]==="p"?l.position:l.target)[y(i)]=s),c(R(n,o,l,r,i==="lens"?s:void 0))}const a=t.items.find(f=>f.id===e);if(!a||a.locked)return t;if(i[0]==="o"){const f=O(a,n,o).position.slice();if(f[y(i)]=s,E(a,n))return j(t,e,o,{position:f});const l={...a.fx.attach,offset:f};return{...t,items:t.items.map(u=>u.id===e?{...u,fx:{...u.fx,attach:l}}:u)}}const d=M(a,n,o),m={position:[...d.position],rotation:[...d.rotation],scale:[...d.scale]};i==="s"?m.scale=d.scale[0]>1e-6?d.scale.map(f=>C(f*s/d.scale[0])):[s,s,s]:(i[0]==="p"?m.position:m.rotation)[y(i)]=s;const h=n.objectKeys?.[e]||[];if(h.length){const f=h.find(u=>Math.abs(u.time-o)<1e-6),l={...f,id:f?.id??r(),time:o,...m};return c({objectKeys:{...n.objectKeys,[e]:[...h.filter(u=>u.id!==l.id),l].sort((u,F)=>u.time-F.time)}})}return{...t,items:t.items.map(f=>f.id===e?{...f,...m}:f)}}const b=1e-6,S=(t,e)=>e==="camera"?t.motion==="path"?t.cameraKeys||[]:[]:t.objectKeys?.[e]||[];function x(t,e,i){const o=p(t),s=[...i].sort((r,n)=>r.time-n.time);if(e==="camera"){const r=s,n=r[0],c=r[r.length-1],a={cameraKeys:r,motion:r.length?"path":"static",...n&&c?{position:n.position,target:n.target,lens:n.lens,roll:n.roll,endPosition:c.position,endTarget:c.target,endLens:c.lens}:{}};return{...t,shots:t.shots.map(d=>d.id===o.id?{...d,...a}:d)}}return{...t,shots:t.shots.map(r=>r.id===o.id?{...r,objectKeys:{...r.objectKeys,[e]:s}}:r)}}const k=(t,e)=>e!=="camera"&&!!t.items.find(i=>i.id===e)?.locked;function T(t,e,i,o=()=>crypto.randomUUID()){const s=p(t);if(!s||k(t,e))return t;const r=S(s,e);if(r.some(a=>Math.abs(a.time-i)<b))return t;if(e==="camera"){const a=P(s,i);return x(t,e,[...r,{id:o(),time:i,position:a.position,target:a.target,lens:a.lens,roll:a.roll}])}const n=t.items.find(a=>a.id===e);if(!n)return t;if(n.kind==="fx"&&n.fx?.attach)return j(t,e,i,{id:o()});const c=M(n,s,i);return x(t,e,[...r,{id:o(),time:i,position:c.position,rotation:c.rotation,scale:c.scale}])}function z(t,e,i){return["camera",...t.items.filter(o=>!o.hidden).map(o=>o.id)].reduce((o,s)=>T(o,s,e,i),t)}function Q(t,e){const i=p(t);return e.flatMap(o=>{const s=S(i,o.row).find(r=>r.id===o.id);return s?[{row:o.row,key:structuredClone(s)}]:[]})}function W(t,e,i,o=()=>crypto.randomUUID()){if(!e.length)return{stage:t,pasted:[]};const s=Math.min(...e.map(c=>c.key.time)),r=[];let n=t;for(const c of new Set(e.map(a=>a.row))){if(k(n,c)||c!=="camera"&&!n.items.some(d=>d.id===c))continue;let a=[...S(p(n),c)];for(const d of e.filter(m=>m.row===c)){const m=Math.min(1,Math.max(0,d.key.time-s+i)),h={...structuredClone(d.key),id:o(),time:m};a=[...a.filter(f=>Math.abs(f.time-m)>=b),h],r.push({row:c,id:h.id})}n=x(n,c,a)}return{stage:n,pasted:r}}function v(t,e,i){let o=t;for(const s of new Set(e.map(r=>r.row))){if(k(o,s))continue;const r=new Set(e.filter(n=>n.row===s).map(n=>n.id));o=x(o,s,S(p(o),s).map(n=>r.has(n.id)?{...n,ease:i}:n))}return o}function g(t,e,i){let o=t,s=!1;for(const r of new Set(e.map(n=>n.row))){if(k(o,r))continue;const n=new Set(e.filter(m=>m.row===r).map(m=>m.id)),a=S(p(o),r).map(m=>n.has(m.id)?{...m,time:m.time+i}:m);a.every(m=>m.time>=-b&&m.time<=1+b)&&a.every((m,h)=>a.every((f,l)=>h>=l||Math.abs(m.time-f.time)>b))&&(s=!0,o=x(o,r,a.map(m=>({...m,time:Math.min(1,Math.max(0,m.time))}))))}return{stage:o,moved:s}}export{A as CAMERA_PROPS,X as FX_FREE_PROPS,_ as FX_OFFSET_PROPS,U as OBJECT_PROPS,T as addKeyAt,Q as copyKeys,v as easeKeys,z as keyAllAt,g as nudgeKeys,W as pasteKeys,J as readProp,I as rowKeyed,H as rowProps,q as writeProp};
@@ -1 +0,0 @@
1
- import{u as o}from"./store-DW4E9xnW.js";import{t as l,c as w}from"./api-CJ8PdbfZ.js";import{l as v,d as C}from"./titleArt-Drsrtfiv.js";import{i as h}from"./textAnimators-DUZjhVGO.js";import"./titleFrameBudget-CLZWaFHO.js";async function y(g){const e=[],m=o.getState().canvasId;for(const t of g){if(!t.title||t.url){e.push(t);continue}const n=document.createElement("canvas");n.width=1280,n.height=720;const a=n.getContext("2d");if(!a)throw Error("Canvas unavailable");const r=await v(t.title),f=r.filter(h),c=r.filter(i=>!h(i));c.length&&o.getState().toast(l("Font {0} chưa tải được (mạng chập chờn) — chữ tạm dùng font thay thế. Chọn lại font để thử lại.",[c.join(", ")]),"info"),f.length&&o.getState().toast(l("Font riêng của chữ này không còn trong tài khoản của bạn — chữ dùng font mặc định. Tải font lên lại (Chữ → Font) hoặc chọn font khác."),"info"),C(a,t.title);const p=await new Promise((i,d)=>n.toBlob(s=>s?i(s):d(Error("Cannot create title")),"image/png")),u=await w(new File([p],"timeline-title.png",{type:"image/png"}));if(o.getState().canvasId!==m)throw Error("Canvas changed while creating text");e.push({...t,...u})}return e}export{y as materializeTitles};
@@ -1 +0,0 @@
1
- import{c1 as T,eQ as ot,eR as rt,m3 as nt,eV as B,m4 as it,ec as st,eW as lt,eS as O,ee as V,eU as Q,eZ as X,eY as Z,e_ as q,eX as z}from"./titleFrameBudget-CLZWaFHO.js";import{l as ht,d as dt}from"./titleArt-Drsrtfiv.js";import{i as R,j as mt,s as k,d as P,l as ct,k as j,f as ft,e as G,a as ut,p as pt,t as wt,m as tt}from"./lottieLayer-DzbA3bHV.js";import{wantsFrame as J,SKIPPED_FRAME as gt}from"./frameSink-DeM8xC8_.js";import{t as N}from"./api-CJ8PdbfZ.js";import"./textAnimators-DUZjhVGO.js";import"./rigTrack-urT3nDK0.js";const xt=e=>Q(e.title)||!!e.shape||!!e.motion||!!e.lottie||!!e.card||!!e.geo,U=e=>e.kind==="image"&&!!e.title?.text&&!e.url&&!Q(e.title),H=4,Y=192*1024*1024,g=new Map;let A=0;function Et(e,s){if(e.geo||e.shape&&R(e.shape)||e.pin?.scene||e.space)return null;const{start:i,track:h,...n}=e;return JSON.stringify([s,n])}function Mt(e,s){const i=s.reduce((h,n)=>h+n.length,0);if(!(i>Y/4)){g.delete(e),g.set(e,{frames:s,bytes:i}),A+=i;for(const[h,n]of g){if(A<=Y)break;g.delete(h),A-=n.bytes}}}function Tt(){g.clear(),A=0}const bt=e=>new Promise((s,i)=>e.toBlob(h=>{if(!h)return i(Error("Cannot encode title frame"));const n=new FileReader;n.onload=()=>s(String(n.result).slice(String(n.result).indexOf(",")+1)),n.onerror=()=>i(n.error),n.readAsDataURL(h)},"image/webp",.9));async function Pt(e,s,i,h,n){const{fps:o,width:f,height:S}=T(s),u=T({...s,resolution:"720p"}),y=e.some(t=>t.shape&&R(t.shape))?ot(rt(e)):null,$=!!i.wants;for(const t of e.filter(d=>(xt(d)||U(d))&&!d.warped)){if(!J(i,"titleFrames",t.id))continue;const d=a=>J(i,"titleFrames",t.id,a),m=Et(t,s),r=m?g.get(m):void 0;if(r){g.delete(m),g.set(m,r);for(const a of r.frames){if(h?.aborted)throw new DOMException("Export cancelled","AbortError");await i.push("titleFrames",t.id,a)}continue}const x=[],E=t.title,M=nt(t)||U(t)?1:Math.ceil(t.duration*o);if(M>1&&Math.ceil(t.duration*o)>3600)throw Error("Mỗi tiêu đề động / Motion tối đa 2 phút khi xuất MP4.");E&&!t.shape&&!t.motion&&!t.lottie&&!t.card&&!t.geo&&await ht(E);const b=t.card?await mt(t.card).catch(a=>{throw Error(N("Thẻ HTML “{0}”: {1}",[t.label,a.message]))}):null,[p,w]=b?[b.width,b.height]:t.geo?[u.width,u.height]:t.lottie?[B(t.lottie).W,B(t.lottie).H]:t.motion?[u.width,u.height]:t.shape?[k(t.shape).W,k(t.shape).H]:[1280,720],C=Object.assign(document.createElement("canvas"),{width:p,height:w}),F=C.getContext("2d");if(!F)throw Error("Canvas unavailable");let _="",D=null;const I=(a,l)=>tt({layer:`export:${a.id}`,motion:a.motion,t:z(a,l/o),width:p,height:w,duration:q(a),fps:o,surface:a.pin?.scene?Z(a,e,a.start+l/o,p,w):null,space:a.space?(O(e),X(a,e,a.start+l/o,p,w,n)):null}),c=[],L="\0same",W="\0skip",K=t.shape&&!t.motion&&!t.card&&!t.lottie&&!t.geo&&!R(t.shape)?it(t.shape):null,et=K==null?1/0:Math.max(K,...["trimStart","trimEnd"].flatMap(a=>st(t,a).map(l=>l.time))),v=async()=>{const a=await c.shift();if(a===W){await i.push("titleFrames",t.id,gt);return}if(a===L||a===_){x.push("="),await i.push("titleFrames",t.id,"=");return}_=a,x.push(a),await i.push("titleFrames",t.id,a)};try{for(let a=0;a<M;a++){if(h?.aborted)throw new DOMException("Export cancelled","AbortError");if(!d(a)){c.push(Promise.resolve(W)),c.length>=H&&await v();continue}if(!$&&a>0&&(a-1)/o>et+1e-6){c.push(Promise.resolve(L)),c.length>=H&&await v();continue}if(F.clearRect(0,0,p,w),t.motion){let l;try{l=await(D??I(t,a)),D=a+1<M&&d(a+1)?I(t,a+1):null}catch(at){throw D?.catch(()=>{}),P(`export:${t.id}`),Error(`Motion “${t.label}”: ${at.message}`)}F.drawImage(l,0,0),l.close()}else if(t.lottie)try{await ct(`export:${t.id}`,t.url,{W:p,H:w},lt(t,a/o),C)}catch(l){throw j(`export:${t.id}`),Error(`Lottie “${t.label}”: ${l.message}`)}else if(t.geo)try{await ft(`export:${t.id}`,t.geo,{W:p,H:w},a/o,C,{wait:2e4,duration:t.duration})}catch(l){throw G(`export:${t.id}`),Error(N("Bản đồ “{0}”: {1}",[t.label,l.message]))}else b?F.drawImage(b,0,0):t.shape?(y&&O(y),ut(F,pt(t,e,a/o,f,S),{start:V(t,"trimStart",a/o),end:V(t,"trimEnd",a/o),offset:wt(t.shape)},p,w,a/o)):dt(F,E,{time:a/o,duration:t.duration});c.push(bt(C)),c.length>=H&&await v()}for(;c.length;)await v();m&&!$&&Mt(m,x)}finally{for(const a of c)a.catch(()=>{})}t.motion&&P(`export:${t.id}`),t.lottie&&j(`export:${t.id}`),t.geo&&G(`export:${t.id}`)}}function Dt(e,s,i,h){const{fps:n}=T(i),{width:o,height:f}=T({...i,resolution:"720p"}),S=Math.ceil(e.duration*n)-1,u=Object.assign(document.createElement("canvas"),{width:o,height:f}),y=u.getContext("2d");if(!y)throw Error("Canvas unavailable");const $=r=>tt({layer:`export:${e.id}`,motion:e.motion,t:z(e,r/n),width:o,height:f,duration:q(e),fps:n,surface:e.pin?.scene?Z(e,s,e.start+r/n,o,f):null,space:e.space?(O(s),X(e,s,e.start+r/n,o,f,h)):null});let t=null,d=-1;const m=r=>{r?.p.then(x=>x.close(),()=>{})};return{W:o,H:f,async frame(r){if(r=Math.max(0,Math.min(S,r)),r===d)return u;for(;t&&t.i<r;){const M=t;t=null,await M.p.then(b=>b.close(),()=>{})}const x=t&&t.i===r?t.p:$(r);t&&t.i!==r&&m(t),t=null;let E;try{E=await x}catch(M){throw P(`export:${e.id}`),Error(`Motion “${e.label}”: ${M.message}`)}return t=r<S?{i:r+1,p:$(r+1)}:null,y.clearRect(0,0,o,f),y.drawImage(E,0,0),E.close(),d=r,u},close(){m(t),t=null,P(`export:${e.id}`)}}}export{Tt as clearFrameCache,Et as frameCacheKey,Dt as liveMotion,Pt as renderTitleFrames};
@@ -1,2 +0,0 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/rotoMaskStore-DPziPKAN.js","assets/titleFrameBudget-CLZWaFHO.js","assets/api-CJ8PdbfZ.js"])))=>i.map(i=>d[i]);
2
- import{_ as U}from"./titleFrameBudget-CLZWaFHO.js";import{gM as O,iY as j,fq as C,g1 as P,dU as L,jl as B,jm as E,jn as F,fU as $,f$ as D,g0 as I}from"./remote-C7J0Tqhb.js";import"./api-CJ8PdbfZ.js";import"./three.module-Bx43vjkH.js";import"./GLTFLoader-BHWu1lKg.js";import"./store-DW4E9xnW.js";import"./rotoMaskStore-DPziPKAN.js";import"./textAnimators-DUZjhVGO.js";import"./timelineComp-B4GtoH2f.js";import"./rigTrack-urT3nDK0.js";const T=["twos","snap","anticipation","exaggerate","squash","smear"],A=t=>Array.isArray(t)&&t.length===3&&t.every(p=>Number.isFinite(Number(p)))?t.map(Number):null,q=t=>t==="left"?"L":t==="both"?"both":"R",w=t=>Math.round(t*1e3)/1e3;function Z(t,p){const c=p.getStage(),d=O(c),a=t.on!==!1&&t.on!=="false",s={on:a};if(t.amount!=null){const r=Number(t.amount);if(!Number.isFinite(r))return{ok:!1,error:"amount must be a number 0–1"};s.amount=Math.max(0,Math.min(1,r))}for(const r of T)typeof t[r]=="boolean"&&(s[r]=t[r]);if(t.shot_default){const r=D({...d.toon||I,...s});return p.setStage(m=>({...m,shots:m.shots.map(f=>f.id===d.id?{...f,toon:r}:f)})),{ok:!0,shot_default:r,note:"every person / prop without its own setting uses it (set_toon on a name overrides one object)"}}const o=Array.isArray(t.names)?t.names.map(String):t.name!=null?[String(t.name)]:[];if(!o.length)return{ok:!1,error:"give names (people / props) or shot_default:true"};let l;try{l=o.map(r=>j(c,r))}catch(r){return{ok:!1,error:r.message}}const k=l.filter(r=>!["person","prop","box","sphere","cylinder","model"].includes(r.kind));if(k.length)return{ok:!1,error:`the cartoon style works on people, props and simple objects, not on ${k.map(r=>`'${r.name}' (${r.kind})`).join(", ")}`};const u={};return p.setStage(r=>({...r,items:r.items.map(m=>{if(!l.some(h=>h.id===m.id))return m;const f=D({...D(m.toon)||I,...s});return u[m.name]=f,{...m,toon:f}})})),{ok:!0,toon:u,note:a?"applied at render time on top of the keyed motion (anticipation before strong moves, overshoot + settle after stops, snappy key poses, exaggerated angles, squash & stretch, smears); keys are unchanged":"off: the keyed motion plays exactly as keyed"}}async function tt(t,p){const c=p.getStage(),d=O(c),a=String(t.action||"drop");if(!["drop","bounce","hold","throw","catch","dribble"].includes(a))return{ok:!1,error:`unknown action '${a}'; use drop, bounce, hold, throw, catch or dribble`};const s=Math.max(0,Math.min(d.duration,Number(t.time??0)||0));let o;if(t.person!=null){try{o=j(c,String(t.person))}catch(e){return{ok:!1,error:e.message}}if(!C(o))return{ok:!1,error:`'${o.name}' is not a person`}}if(["hold","throw","dribble","catch"].includes(a)&&!o&&a!=="throw")return{ok:!1,error:`${a} needs person`};let l=t.name!=null?c.items.find(e=>e.name===String(t.name)&&e.kind==="prop"&&e.prop?.kind==="ball"):void 0;const k=!l,u=A(t.position),r=P.radius;if(!l){const e=o?[o.position[0]+Math.sin(o.rotation[1]*Math.PI/180)*.6,o.position[1]+r,o.position[2]+Math.cos(o.rotation[1]*Math.PI/180)*.6]:[0,r,0];l=L(c,{kind:"prop",name:String(t.name||"Bóng rổ"),prop:{kind:"ball"},color:"#d8641c",position:u?[u[0],Math.max(r,u[1]),u[2]]:e})}t.toon!==!1&&!l.toon&&(l={...l,toon:{on:!0,amount:Math.max(0,Math.min(1,Number(t.amount??.6)))}}),t.bounciness!=null&&(l={...l,ball:{restitution:Math.max(.3,Math.min(.95,Number(t.bounciness)||P.restitution))}});const m=q(t.hand),f=(d.ball?.[l.id]||[]).filter(e=>e.t<s-1e-6),h=[],y=A(t.velocity);let N=A(t.target),b=null;if(a==="throw"&&!y&&!N&&t.target_person==null){if(b=B((await E(p,c)).colliders,o?.position??l.position),!b&&t.target==="hoop")return{ok:!1,error:"no hoop in the scene: build_set a court with parts named rim / vành rổ and backboard / bảng rổ, or give target [x,y,z]"};b&&(N=[...b.rim])}let v;if(t.target_person!=null)try{v=j(c,String(t.target_person))}catch(e){return{ok:!1,error:e.message}}if(a==="drop"||a==="bounce")h.push({t:s,kind:"launch",from:u??[...l.position],vel:y??(a==="bounce"?[0,3.5,0]:[0,0,0])});else if(a==="hold")h.push({t:s,kind:"hold",by:o.id,hand:m});else if(a==="dribble")h.push({t:s,kind:"dribble",by:o.id,hand:m==="both"?"R":m,period:Math.max(.3,Math.min(1.2,Number(t.period)||.55))});else if(a==="throw"){const e=[...f].reverse().find(g=>g.kind==="hold"||g.kind==="dribble");if(o&&!(e&&"by"in e&&e.by===o.id))h.push({t:Math.max(0,s-.001),kind:"hold",by:o.id,hand:m});else if(!o&&!e)return{ok:!1,error:"throw needs person (or an earlier hold / dribble of this ball)"};const i=t.arrive!=null?Math.max(.2,Number(t.arrive)):void 0;h.push({t:s,kind:"throw",...y?{vel:y}:v?{to:{by:v.id,hand:"both"},arrive:i??.9}:{to:N??[l.position[0],3.05,l.position[2]+4],...i?{arrive:i}:{},apex:Number(t.apex)||(b?1:.9),...b?{net:!0}:{}}}),v&&h.push({t:s+(i??.9),kind:"hold",by:v.id,hand:"both"})}else if(a==="catch"){const e=Math.max(.3,Math.min(3,Number(t.flight)||.9)),i=u??(o?[o.position[0]+Math.sin(o.rotation[1]*Math.PI/180)*4.5,o.position[1]+1.5,o.position[2]+Math.cos(o.rotation[1]*Math.PI/180)*4.5]:[...l.position]);h.push({t:Math.max(0,s-e),kind:"launch",from:i,to:{by:o.id,hand:m}},{t:s,kind:"hold",by:o.id,hand:m})}const x=[...f.filter(e=>!h.some(i=>i.t<=e.t+1e-6)),...h].sort((e,i)=>e.t-i.t),_=l.id,M=l;p.setStage(e=>({...e,items:k?[...e.items,M]:e.items.map(i=>i.id===_?M:i),shots:e.shots.map(i=>i.id===d.id?{...i,ball:{...i.ball,[_]:x}}:i)}));const S=h.find(e=>e.kind==="launch"&&Array.isArray(e.vel)),n=S&&S.kind==="launch"?F(S.from??M.position,S.vel,S.t,d.duration,{radius:r,restitution:M.ball?.restitution}).impacts.slice(0,8).map(e=>w(e.time)):void 0;return{ok:!0,name:M.name,created:k,...b?{hoop:"aimed through the rim centre, drops through the net"}:{},events:x.map(e=>({...e,t:w(e.t)})),...n?{bounce_times:n}:{},note:"the ball moves analytically (ballistic arcs, bounces losing height by its bounciness, squash on each bounce with the cartoon style on); it follows the hand while held / dribbled"}}async function et(t,p){const c=p.getStage(),d=O(c),a=await U(()=>import("./rotoMaskStore-DPziPKAN.js").then(n=>n.W),__vite__mapDeps([0,1,2]));let s;if(t.all_props===!0)s=c.items.filter(n=>!n.hidden&&["box","sphere","cylinder","prop","proxy","model"].includes(n.kind)&&!a.dropUnavailable(n));else{const n=Array.isArray(t.objects)?t.objects.map(String):Array.isArray(t.names)?t.names.map(String):[];if(!n.length)return{ok:!1,error:"give objects (names) or all_props:true"};try{s=n.map(i=>j(c,i))}catch(i){return{ok:!1,error:i.message}}const e=s.map(i=>[i,a.dropUnavailable(i)]).filter(([,i])=>i);if(e.length)return{ok:!1,error:`cannot drop ${e.map(([i])=>`'${i.name}' (${i.kind}${i.locked?", locked":i.hold?", held":""})`).join(", ")}: physics_drop moves objects and props, not people, effects, sets or the floor`}}if(s=s.filter(n=>!(n.kind==="prop"&&n.prop?.kind==="ball"&&d.ball?.[n.id]?.length)),!s.length)return{ok:!1,error:"nothing to drop (a ball with add_ball motion keeps its own motion)"};if(s.length>a.MAX_PHYSICS_BODIES)return{ok:!1,error:`at most ${a.MAX_PHYSICS_BODIES} objects per drop`};const o=Math.max(0,Math.min(d.duration,Number(t.time??0)||0)),l=d.duration-o;if(l<a.DROP_SECONDS.min)return{ok:!1,error:`time ${w(o)} s is too close to the end of the shot (${d.duration} s)`};const k=Math.min(l,Math.max(1,Math.min(a.DROP_SECONDS.max,Number(t.duration)||a.DROP_SECONDS.default))),u=o/d.duration,r=a.DROP_MODES.includes(t.mode)?t.mode:"above",m=t.bounciness,f=typeof m=="number"||m==="bouncy"||m==="heavy"?m:"normal",h=p.engine(),y=s.map(n=>n.id);h&&h.sync(c,null);const N=h?.physicsShapes(y)??{},b=(await E(p,c)).colliders.filter(n=>!y.includes(n.itemId)),v={},x=s.map(n=>{const e=$(n,d,u),i=[...d.objectKeys?.[n.id]||[]].filter(g=>g.time<u-1e-6).sort((g,R)=>g.time-R.time).pop();return v[n.id]=i,{id:n.id,position:e.position,rotation:e.rotation,shape:a.shapeKind(n),...N[n.id]??a.fallbackShape(n)}}),_=await a.bakeDrop({bodies:x,statics:b,mode:r,bounciness:f,duration:k,start:o,shotDuration:d.duration,height:Number(t.height)||void 0,strength:Number(t.strength)||void 0,velocity:A(t.velocity)??void 0,seed:t.seed!=null?String(t.seed):y.join(","),before:v,seam:d.lockUntil?d.lockUntil/d.duration:null}),M=Object.fromEntries(s.map(n=>[n.id,$(n,d,u).scale]));p.setStage(n=>a.applyDropKeys(n,d.id,_.tracks,{scale:M,lifted:r==="above"}));const S={};for(const n of s){const e=_.tracks[n.id];e&&(S[n.name]={keys:e.keys.length,rest:e.rest,settled_at:e.settledAt==null?null:w(o+e.settledAt)})}return{ok:!0,mode:r,from:w(o),until:w(o+k),objects:S,settled:_.settled,note:"baked into ordinary keys (no physics at playback); their keys after `from` were replaced. Run again with another seed for a different tumble."}}export{tt as addBall,et as physicsDrop,Z as setToon};
@@ -1 +0,0 @@
1
- import{b as v,gM as b,je as j,dH as $,jg as F,jh as y,ji as N}from"./remote-C7J0Tqhb.js";import{a as A}from"./shotFxAgent-BFLkqs8v.js";import{Vector3 as _}from"./three.module-Bx43vjkH.js";import"./api-CJ8PdbfZ.js";import"./titleFrameBudget-CLZWaFHO.js";import"./GLTFLoader-BHWu1lKg.js";import"./store-DW4E9xnW.js";import"./rotoMaskStore-DPziPKAN.js";import"./textAnimators-DUZjhVGO.js";import"./timelineComp-B4GtoH2f.js";import"./rigTrack-urT3nDK0.js";const C=4,T=1.25;function w(t,c,r){return t.updateMatrixWorld(),new _(c*2-1,1-r*2,.5).unproject(t).sub(t.position).normalize()}function M(t,c,r){const o=b(t),s=Math.max(1e-6,o.duration),f=t.items.find(n=>n.kind==="person"&&!n.hidden);return c.points.map(([n,d,l])=>{const m=Math.max(0,Math.min(1,n/s)),p=j(o,m),a=w(p,d,l);let u=r??NaN;if(!Number.isFinite(u)&&f){const h=$(f,o,m);u=new _(h.position[0],h.position[1]+T*Math.max(.3,h.scale[1]),h.position[2]).sub(p.position).dot(a)}(!Number.isFinite(u)||u<.3)&&(u=C);const k=p.position.clone().addScaledVector(a,u);return{t:m,d:u,position:[k.x,k.y,k.z].map(h=>Math.round(h*1e4)/1e4)}})}function B(t,c,r,o,s){const f=b(t),n=Math.max(1e-6,f.duration),d=j(f,Math.max(0,Math.min(1,c/n))),l=w(d,r,o);if(s&&l.y<-.01){const m=-d.position.y/l.y;if(m>.3&&m<80){const p=d.position.clone().addScaledVector(l,m);return[p.x,0,p.z].map(a=>Math.round(a*1e4)/1e4)}}return M(t,{points:[[Math.max(0,Math.min(n,c)),r,o]]})[0].position}function K(t,c,r){const o=b(c).duration;try{if(t.track!=null)return F(t.track,o);const s=String(t.source??"");if(!y.includes(s))return`give track {fps, points} or source ${y.join(" / ")}`;const f=c.plate?.timelineClipId,n=f?r.timelineClip?.(f):void 0;return n?N(n,s,{side:t.side==="left"?"left":"right",point:typeof t.point=="string"?t.point:"palm",...typeof t.object=="string"?{object:t.object}:{},to:o}):"the Timeline clip of this VFX scene is not open in this tab: pass `track` (MCP: shot_run_tool follow_track with timeline {project_id, clip_id} fills it)"}catch(s){return s.message}}function L(t,c){const r=c.getStage();if(!r.plate)return{ok:!1,error:"follow_track needs a VFX scene: one made from a filmed Timeline clip (MCP shot_create_scene with from_clip, or the clip's 3D button)"};const o=A(r.items.filter(i=>i.kind==="fx"),String(t.name??""));if(!o?.fx)return{ok:!1,error:`no effect named '${String(t.name)}' (scene_summary lists the effects)`};const s=r.items.find(i=>i.trackAnchor?.effect===o.id);if(t.stop===!0)return s?(c.setStage(i=>({...i,items:i.items.filter(e=>e.id!==s.id).map(e=>e.id===o.id?{...e,fx:{...e.fx,...e.fx.attach?.to===s.id?{attach:void 0}:{},...e.fx.target?.to===s.id?{target:void 0}:{}}}:e),shots:i.shots.map(e=>({...e,...e.objectKeys?{objectKeys:Object.fromEntries(Object.entries(e.objectKeys).filter(([S])=>S!==s.id))}:{}}))})),{ok:!0,name:o.name,stopped:!0}):{ok:!1,error:`${o.name} follows no track`};const f=K(t,r,c);if(typeof f=="string")return{ok:!1,error:f};const n=t.depth_m==null?void 0:Number(t.depth_m);if(n!==void 0&&!(n>=.3&&n<=200))return{ok:!1,error:"depth_m must be 0.3–200 (metres from the camera)"};const d=t.offset==null?void 0:Array.isArray(t.offset)&&t.offset.length===3&&t.offset.every(i=>Number.isFinite(Number(i))&&Math.abs(Number(i))<=20)?t.offset.map(Number):null;if(d===null)return{ok:!1,error:"offset must be [x, y, z] metres (±20)"};const l=t.role==="target"?"target":"attach",m=M(r,f,n),p=t.track!=null?"given":t.source==="hand"?`hand:${t.side==="left"?"left":"right"}:${typeof t.point=="string"?t.point:"palm"}`:t.source==="object"&&typeof t.object=="string"?`object:${t.object}`:String(t.source),a=s?{...s,trackAnchor:{effect:o.id,source:p}}:{...v("sphere",r.items.length),name:`${o.name} · điểm bám`.slice(0,60),color:"#ffffff",trackAnchor:{effect:o.id,source:p}};a.position=m[0].position,a.rotation=[0,0,0],a.scale=[1,1,1];const u=m.map((i,e)=>({id:`${a.id}-t${e}`,time:i.t,position:i.position,rotation:[0,0,0],scale:[1,1,1]})),k={...o.fx,...l==="attach"?{attach:{to:a.id,follow:"position",...d?{offset:d}:{}}}:{target:{to:a.id,part:"center"}}};c.setStage(i=>({...i,items:[...i.items.filter(e=>e.id!==a.id).map(e=>e.id===o.id?{...e,fx:k}:e),a],shots:i.shots.map(e=>e.id===i.activeShot?{...e,objectKeys:{...e.objectKeys,[a.id]:u}}:e)}));const h=m.map(i=>i.d).sort((i,e)=>i-e),x=b(r).duration;return{ok:!0,name:o.name,anchor:a.name,source:p,role:l,samples:m.length,from_s:+f.points[0][0].toFixed(2),to_s:+f.points.at(-1)[0].toFixed(2),depth_m:+h[h.length>>1].toFixed(2),note:`${o.name} now ${l==="attach"?"rides on":"aims at"} the tracked point (${m.length} keys over ${x.toFixed(1)} s, ${n?`${n} m from the camera`:"at the filmed person's distance (the stand-in; run follow_plate first for a person who walks toward / away from the camera)"}). Re-run after the track changes; stop:true detaches. Export again (export_video vfx) to update the Timeline passes.`}}export{L as followTrack,B as scenePoint,M as trackWorldPoints};
@@ -1 +0,0 @@
1
- import{t as f,bZ as p,b_ as b,c as S,b$ as _,r as U}from"./api-CJ8PdbfZ.js";import{u as C}from"./store-DW4E9xnW.js";import{i as w}from"./textAnimators-DUZjhVGO.js";import"./titleFrameBudget-CLZWaFHO.js";let e={fonts:[],loaded:!1,error:null};const l=new Set,c=t=>{e={...e,...t},l.forEach(o=>o())},E=t=>(l.add(t),()=>{l.delete(t)}),$=()=>U.useSyncExternalStore(E,()=>e),N=()=>e,x={ttf:"font/ttf",otf:"font/otf",woff:"font/woff",woff2:"font/woff2"},O=".ttf,.otf,.woff,.woff2,font/ttf,font/otf,font/woff,font/woff2",d=10,u=new Map;function h(t){if(!t.url||u.has(t.family)||typeof FontFace>"u")return;const o=new FontFace(t.family,`url(${JSON.stringify(t.url)})`,{weight:t.wght?`${t.wght[0]} ${t.wght[1]}`:"1 1000",style:"normal",display:"block"});document.fonts.add(o),u.set(t.family,o)}function m(t){const o=u.get(t);o&&(document.fonts.delete(o),u.delete(t))}let a=null,g=!1;function y(t=!1){return g||(g=!0,C.subscribe((o,r)=>{const n=o.user?.uid??null,i=r.user?.uid??null;if(n!==i)if(n)y(!0);else{for(const s of e.fonts)m(s.family);a=Promise.resolve(),c({fonts:[],loaded:!0,error:null})}})),a&&!t||(a=p().then(o=>{const r=(Array.isArray(o?.fonts)?o.fonts:[]).filter(n=>n&&w(n.family)&&typeof n.name=="string");for(const n of e.fonts)r.some(i=>i.family===n.family)||m(n.family);for(const n of r)try{h(n)}catch{}c({fonts:r,loaded:!0,error:null})}).catch(o=>{c({loaded:!0,error:o?.message||"fonts"})})),a}const v=()=>y();function B(t){return t?w(t)?e.fonts.find(o=>o.family===t)?.name??f("Font đã xoá"):t:"Arial"}const P=t=>!!t&&w(t)&&e.loaded&&!e.error&&!e.fonts.some(o=>o.family===t);function z(t){const o=t?.code;return o==="bad_font"?f("File này không phải font dùng được (.ttf, .otf, .woff, .woff2 · không nhận bộ .ttc · tối đa {0} MB).",[String(d)]):o==="font_limit"?f("Tối đa 50 font — xoá bớt font không dùng rồi tải lên lại."):o==="font_rights"?f("Cần xác nhận bạn có quyền dùng font trước khi tải lên."):o==="font_not_found"?f("Không tìm thấy font."):t?.message||String(t)}async function L(t,o){const r=(t.name.match(/\.([a-z0-9]+)$/i)?.[1]||"").toLowerCase(),n=x[r];if(!n)throw new Error(f("Chỉ nhận file font .ttf, .otf, .woff hoặc .woff2"));if(t.size>d*1024*1024)throw new Error(f("Font tối đa {0} MB",[String(d)]));const i=await S(new File([t],t.name,{type:n}),o,"font"),s=await _({gcsUri:i.gcsUri,rightsConfirmed:!0});return h(s.font),c({fonts:[s.font,...e.fonts.filter(F=>F.family!==s.font.family)]}),s}async function q(t){await b(t.id),m(t.family),c({fonts:e.fonts.filter(o=>o.id!==t.id)})}export{O as FONT_ACCEPT,d as FONT_MAX_MB,x as FONT_TYPES,z as fontError,B as fontLabel,P as isMissingCustomFont,y as loadUserFonts,q as removeUserFont,L as uploadUserFont,$ as useUserFonts,v as userFontsReady,N as userFontsState};
@@ -1,2 +0,0 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/ShotComposer-0DUtMTVI.js","assets/titleFrameBudget-CLZWaFHO.js","assets/remote-C7J0Tqhb.js","assets/api-CJ8PdbfZ.js","assets/three.module-Bx43vjkH.js","assets/GLTFLoader-BHWu1lKg.js","assets/store-DW4E9xnW.js","assets/rotoMaskStore-DPziPKAN.js","assets/textAnimators-DUZjhVGO.js","assets/timelineComp-B4GtoH2f.js","assets/rigTrack-urT3nDK0.js","assets/RoomEnvironment-Dmv_G5ka.js","assets/tool-DktQYmS6.js","assets/timelineProps-D7MVutxu.js","assets/thumb-CS0ZuiGS.js","assets/shotFxAgent-BFLkqs8v.js","assets/cameraPresets-CYw0OdM3.js","assets/weaponDuel-ZhX-tjGZ.js","assets/skin-DY4QLaBI.js","assets/views-ozVF4ABO.js","assets/motionBlur-uAm030t9.js","assets/library-BufgA-Pl.js","assets/ShotComposer-VixLbeMe.css"])))=>i.map(i=>d[i]);
2
- import{_ as l}from"./titleFrameBudget-CLZWaFHO.js";import{R as h}from"./api-CJ8PdbfZ.js";import{ds as w}from"./remote-C7J0Tqhb.js";import"./three.module-Bx43vjkH.js";import"./GLTFLoader-BHWu1lKg.js";import"./store-DW4E9xnW.js";import"./rotoMaskStore-DPziPKAN.js";import"./textAnimators-DUZjhVGO.js";import"./timelineComp-B4GtoH2f.js";import"./rigTrack-urT3nDK0.js";let m=Promise.resolve();const p=o=>new Promise(r=>setTimeout(r,o));function R(o,r,{timeoutMs:d=6e4}={}){const i=async()=>{const e=document.createElement("div");Object.assign(e.style,{position:"fixed",left:"-20000px",top:"0",width:"960px",height:"540px",pointerEvents:"none",contain:"strict"}),e.setAttribute("aria-hidden","true"),document.body.appendChild(e);const s=w.createRoot(e);try{const{default:u}=await l(async()=>{const{default:t}=await import("./ShotComposer-0DUtMTVI.js");return{default:t}},__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22]));let n=null;s.render(h.createElement(u,{nodeId:o,background:t=>{n=t}}));const c=Date.now()+d;for(;!n?.ready();){if(Date.now()>c)throw new Error("3D Shot did not start in time");await p(60)}for(;;)try{return await r(n)}catch(t){if(!/chưa tải xong/.test(t.message)||Date.now()>c)throw t;await p(500)}}finally{s.unmount(),e.remove()}},a=m.then(i,i);return m=a.catch(()=>{}),a}export{R as withBackgroundScene};
@@ -1 +0,0 @@
1
- import{gK as S}from"./remote-C7J0Tqhb.js";import{s as U}from"./motionBlur-uAm030t9.js";import{M as Y}from"./motionBlur-uAm030t9.js";import{bF as C,c as M}from"./id3-arvEpAg7.js";import{S as O,B as D,O as H,W as P,a as B,C as I}from"./output-p-Q7qous.js";import"./api-CJ8PdbfZ.js";import"./titleFrameBudget-CLZWaFHO.js";import"./three.module-Bx43vjkH.js";import"./GLTFLoader-BHWu1lKg.js";import"./store-DW4E9xnW.js";import"./rotoMaskStore-DPziPKAN.js";import"./textAnimators-DUZjhVGO.js";import"./timelineComp-B4GtoH2f.js";import"./rigTrack-urT3nDK0.js";async function G(s,T,h){const{start:d,end:F,fps:a,signal:w,progress:p}=h,r=F-d,n=Math.ceil(r*a);if(!(r>0)||!Number.isFinite(r)||!S.includes(a))throw new Error("Khoảng thời gian hoặc FPS không hợp lệ");const g=new C({bitrate:h.height>=1080?6e6:3e6}),o=h.alpha===!0,f=o?"vp9":"avc",k=o?"webm":"mp4";if(!await M(f,{width:s.width,height:s.height,quality:g}))throw new Error(o?"Trình duyệt chưa hỗ trợ xuất VP9 có kênh trong suốt. Hãy dùng Chrome/Edge mới.":"Trình duyệt chưa hỗ trợ xuất H.264. Hãy dùng Chrome/Edge mới, hoặc thử 720p.");let m,c;const l=`camera-export-${crypto.randomUUID()}.${k}`;let t;const y=async()=>{m&&await m.removeEntry(l).catch(()=>{})};try{let i;if(navigator.storage?.getDirectory)m=await navigator.storage.getDirectory(),c=await m.getFileHandle(l,{create:!0}),i=new O(await c.createWritable(),{chunked:!0,chunkSize:1024*1024});else{if(r*(h.height>=1080?6e6:3e6)/8>1e8)throw new Error("Trình duyệt này thiếu bộ nhớ tạm cho video dài. Dùng Chrome/Edge hoặc xuất một đoạn ngắn hơn.");i=new D}t=new H({format:o?new P:new B({fastStart:"reserve"}),target:i});const u=new I(s,{codec:f,quality:g,...o?{alpha:"keep"}:{}});t.addVideoTrack(u,{frameRate:a,maximumPacketCount:n}),await t.start();for(let e=0;e<n;e++){w.throwIfAborted();const b=e/a,x=Math.min(1/a,r-b);await T(d+(n>1?e/(n-1):0)*r),await u.add(b,x,{keyFrame:e%a===0}),e%6===0&&(p(Math.round((e+1)/n*95)),await new Promise(E=>setTimeout(E,0)))}w.throwIfAborted(),u.close(),await t.finalize();const v=c?await c.getFile():new Blob([i.buffer],{type:o?"video/webm":"video/mp4"});return p(100),{blob:v,cleanup:y}}catch(i){throw t&&t.state!=="finalized"&&t.state!=="canceled"&&await t.cancel().catch(()=>{}),await y(),i}}export{Y as MOTION_BLUR,G as encodeCameraVideo,U as shutterTimes};
@@ -1 +0,0 @@
1
- import{Bone as k,SkinnedMesh as g,Vector3 as a,Scene as L,Color as M,MeshLambertMaterial as b,HemisphereLight as S,DirectionalLight as h,WebGLRenderer as z,OrthographicCamera as C}from"./three.module-Bx43vjkH.js";import{c as D}from"./GLTFLoader-BHWu1lKg.js";import{f as E}from"./skin-DY4QLaBI.js";import"./remote-C7J0Tqhb.js";import"./api-CJ8PdbfZ.js";import"./titleFrameBudget-CLZWaFHO.js";import"./store-DW4E9xnW.js";import"./rotoMaskStore-DPziPKAN.js";import"./textAnimators-DUZjhVGO.js";import"./timelineComp-B4GtoH2f.js";import"./rigTrack-urT3nDK0.js";const B=640;function U(y,c=B){const t=D(y);t.position.set(0,0,0),t.quaternion.identity(),t.scale.set(1,1,1);const p=[];t.traverse(e=>{e.userData.rigOverlay&&p.push(e),e instanceof k&&e.quaternion.identity()}),p.forEach(e=>e.parent?.remove(e)),t.traverse(e=>{e instanceof g&&e.skeleton.pose()});const d=E(t),n=d.getCenter(new a),f=d.getSize(new a),r=Math.max(f.x,f.y,f.z)/2*1.08,o=new L;o.background=new M("#ffffff");const m=new b({color:"#8d949b"});o.overrideMaterial=m,o.add(new S("#ffffff","#5a6066",2.2));const l=new h("#ffffff",1.4);l.position.set(.4,1,1),o.add(l);const u=new h("#ffffff",.6);u.position.set(1,.5,.3),o.add(u),o.add(t);const i=new z({antialias:!0,preserveDrawingBuffer:!0});i.setSize(c,c,!1);const s=new C(-r,r,r,-r,.01,100),w=e=>(s.position.copy(n).add(e),s.up.set(0,1,0),s.lookAt(n),s.updateProjectionMatrix(),i.render(o,s),i.domElement.toDataURL("image/jpeg",.88));try{const e=r*4,x=w(new a(0,0,e)),v=w(new a(e,0,0));return{front:x,side:v,frame:{cx:n.x,cy:n.y,cz:n.z,half:r}}}finally{m.dispose(),i.dispose(),i.forceContextLoss(),t.traverse(e=>{e instanceof g&&e.skeleton.dispose()})}}export{B as VIEW_SIZE,U as renderRigViews};
@@ -1 +0,0 @@
1
- import{iz as pt,iA as Y,fo as ut,fn as mt,fq as Z,fs as R,hH as kt,b as gt,ft as bt,fD as tt,fE as et,hD as Mt,fU as yt,hG as wt}from"./remote-C7J0Tqhb.js";import{F as vt}from"./rigTrack-urT3nDK0.js";const C=t=>pt(t)??(Y(t)?{clip:Y(t),pack:{id:"fist"}}:null),st=Object.freeze({spear:{"spear-thrust":"thrust","spear-overhead":"high","spear-sweep":"low","spear-spin":"side","spear-dive-thrust":"thrust"},katana:{"katana-overhead":"high","katana-diagonal":"high","katana-horizontal":"side","katana-rising":"side","katana-thrust":"thrust","katana-spin-cut":"side"},staff:{"staff-jab":"thrust","staff-overhead":"high","staff-sweep":"low","staff-rising":"side","staff-spin":"side"},fist:{"fist-lunge-punch":"thrust","fist-rising-uppercut":"side","fist-flying-kick":"side","fist-ground-slam":"high","fist-low-lunge":"thrust"}}),it={high:"block-high",side:"block-side",thrust:"block-side",low:null},jt=Object.freeze({spear:1.42,katana:.98,staff:1.1,fist:0}),Ot={body:.05,blocked:.22,miss:.18},At=1.05,at=new Map,dt=t=>{let e=at.get(t);return e||(e=mt(C(t).clip),at.set(t,e)),e},Ft=(t,e)=>t[Math.max(0,Math.min(t.length-1,Math.round(e*30)))];function ht(t){const e=C(t).clip.keys.filter(a=>a.strike).at(-1);return e?e.t:0}const Kt=t=>C(t).clip.keys.filter(e=>e.strike).at(-1)?.limb??"handR",ot=(t,e)=>Ft(dt(t),e).dz??0;function $t(t){const{pack:e}=C(t),a=dt(t),h=ht(t),o=Kt(t);let f=0;for(const l of a){if(Math.abs(l.t-h)>.1)continue;if(e.id==="fist"){const j=vt(l.pose),m=j[o.replace("foot","toe")];f=Math.max(f,m[2]-j.pelvis[2]);continue}const r=ut(l.pose),u=r.front[2]+r.dir[2]*jt[e.id];f=Math.max(f,u)}return f}function St(t){let e=t>>>0||1;return()=>{e=e+1831565813>>>0;let a=Math.imul(e^e>>>15,1|e);return a=a+Math.imul(a^a>>>7,61|a)^a,((a^a>>>14)>>>0)/4294967296}}function Tt(t,e=4,a=1){const h=St(a),o=[];let f=0,l=["",""];for(let r=0;r<e;r++){r>0&&h()<.62&&(f=1-f);const u=t[f],j=t[1-f],m=Object.keys(st[u]).filter(S=>S!==l[f]),g=m[Math.floor(h()*m.length)],D=st[u][g];l[f]=g;const i=h();let y=r===e-1?"body":i<.5?"blocked":i<.78?"miss":"body";y==="blocked"&&!it[D]&&(y="miss");const $=`${j}-${y==="blocked"?it[D]:y==="miss"?"dodge-back":"hit"}`,P=ht(g),O=C($).clip.contact??0,b=Math.max(At,$t(g)+Ot[y]+ot(g,P)+ot($,O));o.push({attacker:f,attack:g,defence:$,result:y,strike:P,contact:O,gap:Math.round(b*1e3)/1e3})}return o}const q=[.18,.42],nt=t=>(t.kind==="model"?(t.model?.height??2)/1.8:Mt(t))*(t.scale[1]||1),H=t=>t*Math.PI/180,v=t=>t.shots.find(e=>e.id===t.activeShot);function rt(t,e){const a=v(t),h=a.duration/e,o=l=>l?.map(r=>({...r,time:Math.min(1,r.time*h)})),f={...a,duration:e,cameraKeys:o(a.cameraKeys)??[],objectKeys:Object.fromEntries(Object.entries(a.objectKeys||{}).map(([l,r])=>[l,o(r)||[]])),...a.impacts?{impacts:o(a.impacts)}:{},...a.flight?{flight:Object.fromEntries(Object.entries(a.flight).map(([l,r])=>[l,o(r)||[]]))}:{}};return{...t,shots:t.shots.map(l=>l.id===a.id?f:l)}}const ct=(t,e,a)=>{const h=v(t);return{...t,shots:t.shots.map(o=>o.id===h.id?{...o,objectKeys:{...o.objectKeys,[e]:a(o.objectKeys?.[e]||[],o)}}:o)}},T=(t,e,a)=>{const h=v(t),o=yt(t.items.find(f=>f.id===e.id),h,Math.min(1,a/h.duration));return{position:o.position,yaw:o.rotation[1]}};function Ct(t,e,a){const h=t.items.find(s=>s.id===e.a),o=t.items.find(s=>s.id===e.b);if(!h||!o||!Z(h)||!Z(o))return{ok:!1,error:"two people are needed"};if(h.id===o.id)return{ok:!1,error:"two different people are needed"};const f=Math.max(1,Math.min(10,Math.round(e.exchanges))),l=Tt(e.packs,f,e.seed),r=[h,o],u=[nt(h),nt(o)],j=[],m=Math.max(0,e.start),g=v(t),D=m+.5+l.reduce((s,c)=>s+Math.max(R(c.attack).duration,c.strike-c.contact+R(c.defence).duration)+1.4+q[1],0);let i=D>g.duration?rt(t,Math.min(300,D)):t;const M=T(i,h,m),y=l[0].gap*(u[0]+u[1])/2,$=[Math.sin(H(M.yaw)),0,Math.cos(H(M.yaw))],P=[M.position[0]+$[0]*y,M.position[1],M.position[2]+$[2]*y];for(const[s,c,n]of[[h,M.position,M.yaw],[o,P,M.yaw+180]])i=ct(i,s.id,(d,k)=>[...d.filter(p=>p.time*k.duration<m-1e-6),{id:a(),time:m/k.duration,position:c.map(p=>+p.toFixed(3)),rotation:[0,+n.toFixed(1),0],scale:s.scale}]);const O=(s,c,n)=>{const d=v(i),k=R(c),p=wt(i,r[s].id,k,{start:n/d.duration,newId:a,loop:!1});if(!p.ok)throw new Error(`${r[s].name}: ${p.error}`);return i=p.stage,n+k.duration};let b=m+.35,S=m;const E=[];let x=(e.seed*9301+49297)%233280;const lt=()=>(x=(x*9301+49297)%233280,x/233280);try{l.forEach((s,c)=>{const n=s.attacker,d=1-n,k=(u[0]+u[1])/2,p=()=>{const A=T(i,r[0],b).position,F=T(i,r[1],b).position;return Math.hypot(F[0]-A[0],F[2]-A[2])};for(let A=0;A<3;A++){const F=p()-s.gap*k;if(Math.abs(F)<.3*k)break;F>0?b=O(n,`${e.packs[n]}-advance`,b):b=O(d,`${e.packs[d]}-retreat`,b)}const N=Math.max(0,s.contact-s.strike),w=b+N,_=w+s.strike-s.contact,z=p()-s.gap*k,U=O(n,s.attack,w),ft=O(d,s.defence,_),G=r[n],B=T(i,G,w).yaw,W=[Math.sin(H(B)),Math.cos(H(B))],J=w+s.strike,V=Math.max(-.3,Math.min(.3,z));i=ct(i,G.id,(A,F)=>A.map(K=>{const I=K.time*F.duration;if(I<w-1e-6||I>U+1e-6)return K;const L=Math.min(1,(I-w)/Math.max(.001,s.strike)),Q=L*L*(3-2*L),X={...K,position:[+(K.position[0]+W[0]*V*Q).toFixed(3),K.position[1],+(K.position[2]+W[1]*V*Q).toFixed(3)]};return K.strike&&Math.abs(I-J)<.06?{...X,hit:s.result}:X})),E.push({...s,time:+J.toFixed(2),attackerName:G.name}),S=Math.max(U,ft),b=S+q[0]+(q[1]-q[0])*lt(),c===l.length-1&&j.push(`${r[d].name} dính đòn kết`)})}catch(s){return{ok:!1,error:s.message}}if(v(i).duration>g.duration&&(i=rt(i,Math.max(g.duration,Math.min(300,Math.ceil((S+.6)*10)/10)))),i=kt(i).stage,e.packs.includes("fist")){const s=v(i),c=[],n={};E.forEach((d,k)=>{if(d.result==="miss"||e.packs[d.attacker]!=="fist")return;const p=T(i,r[0],d.time).position,N=T(i,r[1],d.time).position,w=(u[0]+u[1])/2,_=`duelfx-${r[d.attacker].id}-${Math.round(d.time*1e3)}`,z=d.result==="body";c.push({...gt("fx",i.items.length+c.length),id:_,name:`Vòng xung kích ${c.length+1}`,position:[+((p[0]+N[0])/2).toFixed(2),0,+((p[2]+N[2])/2).toFixed(2)],color:z?"#ffd27a":"#9fdcff",fx:{preset:"vong_xung_kich",cat:"vong-xung-kich",intensity:z?.9:.75,seed:500+k,start:d.time,duration:.6,loop:!1,auto:"hit",params:{size:(z?1.05:.85)*w,height:+(1.35*w).toFixed(2),hits:1,gap:.3}}}),n[_]={start:d.time,duration:.6}}),c.length&&(i={...i,items:[...i.items,...c],shots:i.shots.map(d=>d.id===s.id?{...d,fxTiming:{...d.fxTiming,...n}}:d)})}if(e.hitStops!==!1){const s=v(i);let c=bt(s.timing,s.duration);c=tt(c,E.filter(n=>n.result==="blocked").map(n=>n.time),et.light,s.duration),c=tt(c,E.filter(n=>n.result==="body").map(n=>n.time),et.heavy,s.duration),i={...i,shots:i.shots.map(n=>n.id===s.id&&c?{...n,timing:c}:n)}}return{ok:!0,stage:i,plan:E,end:+S.toFixed(2),notes:j}}export{st as D,Ct as s};
@@ -1 +0,0 @@
1
- import{mR as P,a7 as b,U as W,$ as y,Z as E,a0 as F,lG as x}from"./titleFrameBudget-CLZWaFHO.js";import"./rotoMatte-C-2o3vv0.js";import"./api-CJ8PdbfZ.js";import"./store-DW4E9xnW.js";const R=e=>P(e).length>0,O=new Map;function D(e){const r=e.face??e.colorPerson??e.person??e.roto??e.mask;if(r?.mw&&r?.mh)return Promise.resolve(r.mh/r.mw);let o=O.get(e.url);return o||(o=new Promise(n=>{if(e.kind==="image"){const a=new Image;a.crossOrigin="anonymous",a.onload=()=>n(a.naturalHeight/Math.max(1,a.naturalWidth)),a.onerror=()=>n(9/16),a.src=e.url;return}const t=document.createElement("video");t.preload="metadata",t.muted=!0,t.crossOrigin="anonymous",t.onloadedmetadata=()=>{n(t.videoHeight/Math.max(1,t.videoWidth)),t.removeAttribute("src"),t.load()},t.onerror=()=>n(9/16),t.src=e.url}),O.set(e.url,o)),o}function I(e,r,o,n,t,a,g){const i=W(e.grade)[r],h=e.colorPerson?E(e.colorPerson):null,f=F(i,e,o,a,h),c=g??document.createElement("canvas");(c.width!==n||c.height!==t)&&Object.assign(c,{width:n,height:t});const l=c.getContext("2d"),d=l.createImageData(n,t);for(let w=0;w<t;w++)for(let u=0;u<n;u++){const m=(w*n+u)*4,s=Math.round(f((u+.5)/n,(w+.5)/t,0,0,0)*255);d.data[m]=d.data[m+1]=d.data[m+2]=s,d.data[m+3]=255}return l.putImageData(d,0,0),c}async function U(e,r,o,n){const t=document.createElement("canvas");for(const{key:a,k:g,clip:i}of P(e)){if(o.wants&&!o.wants("windowFrames",a))continue;i.colorPerson&&await b(i.colorPerson);const h=await D(i),f=x,c=Math.max(2,Math.min(x*2,Math.round(f*h))),l=W(i.grade)[g],d=Math.ceil(i.duration*r),w=!!l.motion;let u="",m="";for(let s=0;s<d;s++){if(n?.aborted)throw new DOMException("Export cancelled","AbortError");if(o.wants&&!o.wants("windowFrames",a,s)){await o.push("windowFrames",a,""),m="";continue}if(w){const p=JSON.stringify(y(l,i,s/r));if(s&&p===m){await o.push("windowFrames",a,"=");continue}m=p}I(i,g,s/r,f,c,h,t);const M=t.toDataURL("image/webp",.9),v=M.slice(M.indexOf(",")+1);if(v===u){await o.push("windowFrames",a,"=");continue}u=v,await o.push("windowFrames",a,v),s%5===0&&await new Promise(p=>setTimeout(p,0))}}}export{R as hasMovingWindows,D as pictureAspect,U as renderWindowFrames,I as windowMatteImage};