clipoox-render 0.4.2 → 0.4.3

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 (105) hide show
  1. package/package.json +1 -1
  2. package/scripts/render-local.mjs +1322 -1320
  3. package/web/assets/{FxEmbed-CGqGi2Lw.js → FxEmbed-BCmj9Q5C.js} +1 -1
  4. package/web/assets/{MotionEmbed-C3CZ3_y_.js → MotionEmbed-CEmbcq8Z.js} +1 -1
  5. package/web/assets/PluginStore-C5hyahvG.js +3 -0
  6. package/web/assets/{ShotComposer-DFfaYLoV.js → ShotComposer-0DUtMTVI.js} +4 -4
  7. package/web/assets/{TemplateEmbed-C8pXcPsc.js → TemplateEmbed-ANxSs7H5.js} +1 -1
  8. package/web/assets/{TimelinePlugins-DnkV3i4G.js → TimelinePlugins-BYZ9y4m3.js} +4 -4
  9. package/web/assets/{TimelinePlugins-DYarX9RK.css → TimelinePlugins-D841ngau.css} +1 -1
  10. package/web/assets/{TimelineShotFx-foiuuogg.js → TimelineShotFx-q5PQwq-V.js} +2 -2
  11. package/web/assets/{TransitionEmbed-BueDilY0.js → TransitionEmbed-O6LInGWq.js} +1 -1
  12. package/web/assets/{Whiteboard-zBsNHh5h.js → Whiteboard-BP_DvIAV.js} +1 -1
  13. package/web/assets/{aerial-z34Nww_T.js → aerial-CGLDKKtP.js} +2 -2
  14. package/web/assets/{agentTools-ALxghYpf.js → agentTools-2Ghb80VH.js} +2 -2
  15. package/web/assets/{analyzerRun-DNwryAlU.js → analyzerRun-DRgxrcJA.js} +1 -1
  16. package/web/assets/{analyzerSandbox-A1oFsCrO.js → analyzerSandbox-DuIVFnsk.js} +1 -1
  17. package/web/assets/{api-DUp403BK.js → api-CJ8PdbfZ.js} +5 -5
  18. package/web/assets/{auraTrack-BKVZCwNt.js → auraTrack-DQw9sVU6.js} +1 -1
  19. package/web/assets/{breakthrough-Cwt8gEwK.js → breakthrough-BNj_iTDr.js} +2 -2
  20. package/web/assets/{cameraPresets-DSOPj4oy.js → cameraPresets-CYw0OdM3.js} +1 -1
  21. package/web/assets/{captionLayout-EuB59pN_.js → captionLayout-DvDPTwO9.js} +1 -1
  22. package/web/assets/{clientExport-BL1XMTF0.js → clientExport-xhoXY6Dh.js} +1 -1
  23. package/web/assets/conversion-4rhF3xRJ.js +17 -0
  24. package/web/assets/{depthEstimate-DOvsY8mn.js → depthEstimate-DEpeCojm.js} +1 -1
  25. package/web/assets/{directorTools-BkbNYbSq.js → directorTools-C5CpTmci.js} +1 -1
  26. package/web/assets/{distortFrames-Drch0LhT.js → distortFrames-Dia8O1NM.js} +2 -2
  27. package/web/assets/{distortGL-BlmBZKRU.js → distortGL-QalhICvi.js} +1 -1
  28. package/web/assets/{editTools-BcGinqHC.js → editTools-CY_JrQfw.js} +1 -1
  29. package/web/assets/engine-BedcnK45.js +1 -0
  30. package/web/assets/{exportEncode-MUwVTI52.js → exportEncode-QYsT9JBO.js} +1 -1
  31. package/web/assets/{exportGlb-SIXFRRJM.js → exportGlb-TSj09XoV.js} +1 -1
  32. package/web/assets/{faceTracker-DCbZbLMc.js → faceTracker-CnCWOwnJ.js} +1 -1
  33. package/web/assets/{fightDirector-hlF1JS_z.js → fightDirector-DCI_FWTh.js} +1 -1
  34. package/web/assets/{fightDrama-fHN5EXk3.js → fightDrama-Bg7uP_2Q.js} +2 -2
  35. package/web/assets/{frameSink-BvOXjLuw.js → frameSink-DeM8xC8_.js} +3 -3
  36. package/web/assets/{gpuCompose-CNkLwpbZ.js → gpuCompose-CA3UmOl4.js} +1 -1
  37. package/web/assets/{gpuExport-DQB6x4eh.js → gpuExport-D31azOQA.js} +13 -9
  38. package/web/assets/{handMatte-BD7OE3Zc.js → handMatte-Dl-xVXFR.js} +1 -1
  39. package/web/assets/{handTracker-BumGtRCW.js → handTracker-CplBsAFg.js} +2 -2
  40. package/web/assets/{id3-BCR9Bqgo.js → id3-arvEpAg7.js} +1 -1
  41. package/web/assets/{index-CuaB7Y0L.js → index-D5oyVCRl.js} +1 -1
  42. package/web/assets/index-_tSTJnL9.js +8 -0
  43. package/web/assets/layer-worker-DFuo32bk.js +5 -0
  44. package/web/assets/library-BufgA-Pl.js +1 -0
  45. package/web/assets/{lottieLayer-1ET89OUr.js → lottieLayer-DzbA3bHV.js} +4 -4
  46. package/web/assets/{lottie_light_canvas-DD9pkFL8.js → lottie_light_canvas-B-d7-ATe.js} +1 -1
  47. package/web/assets/main-VVYiW8XD.js +309 -0
  48. package/web/assets/{mapBake-DLoBt_k5.js → mapBake-BKOcEd0w.js} +1 -1
  49. package/web/assets/maskTrack-CHGXtBRy.js +1 -0
  50. package/web/assets/{matteFixRun-BdHKC3m5.js → matteFixRun-vgYrINet.js} +1 -1
  51. package/web/assets/{objectLocate-bZtc5AJo.js → objectLocate-BJltm8Ob.js} +1 -1
  52. package/web/assets/{output-BwZzMbp-.js → output-p-Q7qous.js} +1 -1
  53. package/web/assets/{pendingMatte-mlyLLZCT.js → pendingMatte-BPyzzx4y.js} +2 -2
  54. package/web/assets/{personAi-CUNQeseG.js → personAi-gJu03SjU.js} +2 -2
  55. package/web/assets/{plateCamera-_jP1xXnj.js → plateCamera-B2JvhjJw.js} +1 -1
  56. package/web/assets/{plateCameraMatch-rr0oUwQ2.js → plateCameraMatch-ByB9nVQT.js} +2 -2
  57. package/web/assets/{plateFollow-BjvtcT8q.js → plateFollow-C9S-l7RH.js} +2 -2
  58. package/web/assets/{plateMatte-BqyL8cQZ.js → plateMatte-J4qlNHnY.js} +2 -2
  59. package/web/assets/{pluginAutomation-Dp188qm7.js → pluginAutomation-CkP3tA9r.js} +1 -1
  60. package/web/assets/{poseTracker-DDGDhhMF.js → poseTracker-DGLbouqt.js} +1 -1
  61. package/web/assets/{productTools-CRgI88-O.js → productTools-CkaWF1bM.js} +2 -2
  62. package/web/assets/remote-C7J0Tqhb.js +1433 -0
  63. package/web/assets/{rigTrack-UYZU4P-e.js → rigTrack-urT3nDK0.js} +1 -1
  64. package/web/assets/{rotoMaskStore-BxyxB2bD.js → rotoMaskStore-DPziPKAN.js} +1 -1
  65. package/web/assets/{rotoMatte-BdYa8FSB.js → rotoMatte-C-2o3vv0.js} +1 -1
  66. package/web/assets/{rotoscope-DDixNQCt.js → rotoscope-GvPFRUBg.js} +1 -1
  67. package/web/assets/{shot-worker-D9sZS6bn.js → shot-worker-6dYkHPoL.js} +1 -1
  68. package/web/assets/{shotFxAgent-7RQNtEe4.js → shotFxAgent-BFLkqs8v.js} +1 -1
  69. package/web/assets/{skin-CVwmK130.js → skin-DY4QLaBI.js} +1 -1
  70. package/web/assets/{spark.module-B34aiScb.js → spark.module-DzziUgOj.js} +1 -1
  71. package/web/assets/{spellDuel-BkweL6pI.js → spellDuel-BD3m2ebA.js} +2 -2
  72. package/web/assets/store-Cug4GGcP.js +1 -0
  73. package/web/assets/{store-75tQUvPT.js → store-DW4E9xnW.js} +1 -1
  74. package/web/assets/{surfaceLight-DhU-zgNL.js → surfaceLight-aDSYU8Jg.js} +1 -1
  75. package/web/assets/surfacePin-m83hCgGP.js +2 -0
  76. package/web/assets/{textAnimators-nVSz_sZo.js → textAnimators-DUZjhVGO.js} +1 -1
  77. package/web/assets/{thumb-r6dlZprA.js → thumb-CS0ZuiGS.js} +1 -1
  78. package/web/assets/{timeline3d-246tBEJl.js → timeline3d-DOw-CpZI.js} +2 -2
  79. package/web/assets/{timeline3dExport-T57qnWi9.js → timeline3dExport-BtYLU1pw.js} +1 -1
  80. package/web/assets/{timelineComp-BcewYGR2.js → timelineComp-B4GtoH2f.js} +1 -1
  81. package/web/assets/{timelineProps-CJzzAWWO.js → timelineProps-D7MVutxu.js} +1 -1
  82. package/web/assets/{timelineText-BzUhNWPB.js → timelineText-BH09jfSM.js} +1 -1
  83. package/web/assets/{titleArt-B8DVR58F.js → titleArt-Drsrtfiv.js} +3 -3
  84. package/web/assets/{titleFrameBudget-BYRZAQPs.js → titleFrameBudget-CLZWaFHO.js} +1 -1
  85. package/web/assets/{titleFrames-BVgm601q.js → titleFrames-BI1DnLBn.js} +1 -1
  86. package/web/assets/{tool-CAGU3dUa.js → tool-DktQYmS6.js} +1 -1
  87. package/web/assets/{tools-DVaOkokV.js → tools-Co9aRDiT.js} +1 -1
  88. package/web/assets/{toonTools-CfGTR_H1.js → toonTools-CD9clJvN.js} +2 -2
  89. package/web/assets/{trackAnchor-DzUt1r5Q.js → trackAnchor-sOjTtd3I.js} +1 -1
  90. package/web/assets/{userFonts-DzY0A4bD.js → userFonts-CwlKh9NR.js} +1 -1
  91. package/web/assets/{vfxAlpha-DQJOaZ9v.js → vfxAlpha-71tSN86T.js} +2 -2
  92. package/web/assets/{vfxBackground-DiktQFOD.js → vfxBackground-Bq7lJvmZ.js} +2 -2
  93. package/web/assets/{videoExport-Ce0ElSQR.js → videoExport-D4KbireJ.js} +1 -1
  94. package/web/assets/{views-V3si1lOz.js → views-ozVF4ABO.js} +1 -1
  95. package/web/assets/{weaponDuel-D6sLVGmG.js → weaponDuel-ZhX-tjGZ.js} +1 -1
  96. package/web/assets/{windowFrames-D_2QJCJJ.js → windowFrames-CpqX3kOM.js} +1 -1
  97. package/web/layer-worker.html +3 -3
  98. package/web/assets/PluginStore-DKXZ-jBj.js +0 -3
  99. package/web/assets/index-DYa7fEK0.js +0 -24
  100. package/web/assets/layer-worker-DxPMMKIZ.js +0 -5
  101. package/web/assets/library-CyjJ8nGG.js +0 -1
  102. package/web/assets/main-BKjBWQik.js +0 -309
  103. package/web/assets/maskTrack-C2SJbDGO.js +0 -1
  104. package/web/assets/remote-Dva2qg58.js +0 -1241
  105. package/web/assets/surfacePin-ObK6QgDm.js +0 -2
@@ -1 +1 @@
1
- import{nw as I,_ as N}from"./titleFrameBudget-BYRZAQPs.js";import{a5 as B}from"./main-BKjBWQik.js";import{t as S}from"./api-DUp403BK.js";import"./remote-Dva2qg58.js";import"./three.module-Bx43vjkH.js";import"./GLTFLoader-BHWu1lKg.js";import"./store-75tQUvPT.js";import"./rotoMaskStore-BxyxB2bD.js";import"./textAnimators-nVSz_sZo.js";import"./timelineComp-BcewYGR2.js";import"./rigTrack-UYZU4P-e.js";import"./spark.module-B34aiScb.js";import"./userFonts-DzY0A4bD.js";import"./lottieLayer-1ET89OUr.js";import"./timeline3d-246tBEJl.js";import"./RoomEnvironment-Dmv_G5ka.js";import"./exportEncode-MUwVTI52.js";import"./captionLayout-EuB59pN_.js";import"./timelineText-BzUhNWPB.js";import"./titleArt-B8DVR58F.js";import"./rotoMatte-BdYa8FSB.js";import"./distortGL-BlmBZKRU.js";import"./motionBlur-uAm030t9.js";const _=n=>+n.toFixed(4);function V(n){const i=n.length,h=n.map(e=>!!e),o=n.map((e,t)=>{if(e)return e.slice();for(let r=1;r<i;r++){const u=n[t-r],l=n[t+r];if(u)return[0,...u.slice(1)];if(l)return[0,...l.slice(1)]}return null});if(!o.some(Boolean))return[];const a=[];for(let e=0;e<i;e++){let t=0;const r=new Array(10).fill(0);let u=0,l=0;for(let d=-2;d<=2;d++){const s=e+d;if(s<0||s>=i)continue;const c=o[s],f=(h[s]?1:.15)*(3-Math.abs(d));t+=f;for(let w=0;w<10;w++)r[w]+=c[w+1]*f;u+=h[s]?c[0]:0,l++}const m=h[e]?n[e][0]:0;a.push([_(Math.min(m,u/l*1.25)),...r.map(d=>_(d/t))])}return a}const T=180/Math.PI;function R(n,i,h){const o=p=>[n[p][0]*i,n[p][1]*h,n[p][2]*i],a=(p,b)=>{const M=o(p),x=o(b);return[(M[0]+x[0])/2,(M[1]+x[1])/2,(M[2]+x[2])/2]},e=(p,b)=>[p[0]-b[0],p[1]-b[1],p[2]-b[2]],t=p=>Math.hypot(p[0],p[1],p[2]),r=a(33,133),u=a(362,263),l=Math.atan2(u[1]-r[1],u[0]-r[0]),m=p=>{const b=Math.cos(-l),M=Math.sin(-l);return[p[0]*b-p[1]*M,p[0]*M+p[1]*b,p[2]]},d=e(o(454),o(234)),s=e(o(152),o(10)),c=m(d),f=m(s),w=[(o(234)[0]+o(454)[0])/2,(o(10)[1]+o(152)[1])/2,(o(234)[2]+o(454)[2])/2];return{cx:w[0],cy:w[1],cz:w[2],w:t(d),h:t(s),roll:l*T,yaw:Math.atan2(c[2],c[0])*T,pitch:Math.atan2(-f[2],f[1])*T,eyes:[r,u],mouth:a(13,14)}}function U(n,i,h){const o=R(n,i,h),a=Math.PI/180,[e,t,r]=[-o.pitch*a,-o.yaw*a,-o.roll*a];return n.slice(0,468).map(u=>{let l=u[2]*i-o.cz;const m=(5*o.w+l)/(5*o.w);let d=(u[0]*i-o.cx)*m,s=(u[1]*h-o.cy)*m;return[d,s]=[d*Math.cos(r)-s*Math.sin(r),d*Math.sin(r)+s*Math.cos(r)],[d,l]=[d*Math.cos(t)-l*Math.sin(t),d*Math.sin(t)+l*Math.cos(t)],[s,l]=[s*Math.cos(e)+l*Math.sin(e),-s*Math.sin(e)+l*Math.cos(e)],[d/o.w,s/o.w,l/o.w]})}function H(n){const i=n.map(e=>({f:e,p:R(e.L,e.M,e.N)})),h=i.filter(e=>Math.abs(e.p.yaw)<25&&Math.abs(e.p.pitch)<25),o=(h.length?h:i).sort((e,t)=>Math.abs(e.p.yaw)+Math.abs(e.p.pitch)-Math.abs(t.p.yaw)-Math.abs(t.p.pitch)).slice(0,40),a=new Array(468*3).fill(0);for(const{f:e}of o)U(e.L,e.M,e.N).forEach((t,r)=>{a[r*3]+=t[0],a[r*3+1]+=t[1],a[r*3+2]+=t[2]});return a.map(e=>+(e/o.length).toFixed(3))}function G(n){const i=V(n.map(e=>e?e.slice(0,11):null));if(!i.length)return[];const h=n.length,o=n.map(e=>!!e),a=(e,t)=>{if(n[e])return n[e][t];for(let r=1;r<h;r++){const u=n[e-r],l=n[e+r];if(u)return u[t];if(l)return l[t]}return 0};return i.map((e,t)=>{const r=[11,12,13].map(u=>{let l=0,m=0;for(let d=-2;d<=2;d++){const s=t+d;if(s<0||s>=h)continue;const c=(o[s]?1:.15)*(3-Math.abs(d));l+=a(s,u)*c,m+=c}return+(l/m).toFixed(2)});return[...e,...r]})}function X(n){const i=n.map(a=>a.slice()),h=[[1,0,0,0],[0,1,0,0],[0,0,1,0],[0,0,0,1]];for(let a=0;a<50;a++){let e=0;for(let t=0;t<4;t++)for(let r=t+1;r<4;r++)e+=i[t][r]*i[t][r];if(e<1e-18)break;for(let t=0;t<4;t++)for(let r=t+1;r<4;r++){if(Math.abs(i[t][r])<1e-20)continue;const u=(i[r][r]-i[t][t])/(2*i[t][r]),l=Math.sign(u||1)/(Math.abs(u)+Math.sqrt(u*u+1)),m=1/Math.sqrt(l*l+1),d=l*m;for(let s=0;s<4;s++){const c=i[s][t],f=i[s][r];i[s][t]=m*c-d*f,i[s][r]=d*c+m*f}for(let s=0;s<4;s++){const c=i[t][s],f=i[r][s];i[t][s]=m*c-d*f,i[r][s]=d*c+m*f}for(let s=0;s<4;s++){const c=h[s][t],f=h[s][r];h[s][t]=m*c-d*f,h[s][r]=d*c+m*f}}}let o=0;for(let a=1;a<4;a++)i[a][a]>i[o][o]&&(o=a);return h.map(a=>a[o])}function $(n,i){const h=n.length,o=[0,0,0],a=[0,0,0];for(let g=0;g<h;g++)for(let E=0;E<3;E++)o[E]+=n[g][E]/h,a[E]+=i[g][E]/h;const e=[[0,0,0],[0,0,0],[0,0,0]];let t=0,r=0;for(let g=0;g<h;g++){const E=[0,1,2].map(D=>n[g][D]-o[D]),O=[0,1,2].map(D=>i[g][D]-a[D]);for(let D=0;D<3;D++)for(let z=0;z<3;z++)e[D][z]+=E[D]*O[z];t+=E[0]*E[0]+E[1]*E[1]+E[2]*E[2],r+=O[0]*O[0]+O[1]*O[1]+O[2]*O[2]}const[[u,l,m],[d,s,c],[f,w,p]]=e,b=[[u+s+p,c-w,f-m,l-d],[c-w,u-s-p,l+d,f+m],[f-m,l+d,-u+s-p,c+w],[l-d,f+m,c+w,-u-s+p]],[M,x,y,k]=X(b),F=[[M*M+x*x-y*y-k*k,2*(x*y-M*k),2*(x*k+M*y)],[2*(x*y+M*k),M*M-x*x+y*y-k*k,2*(y*k-M*x)],[2*(x*k-M*y),2*(y*k+M*x),M*M-x*x-y*y+k*k]],v=Math.sqrt(r/Math.max(1e-12,t)),A=[0,1,2].map(g=>a[g]-v*(F[g][0]*o[0]+F[g][1]*o[1]+F[g][2]*o[2]));return{R:F,s:v,t:A}}function Y(n){const i=Math.asin(Math.max(-1,Math.min(1,n[2][0])));return{pitch:Math.atan2(-n[2][1],n[2][2])*T,yaw:i*T,roll:Math.atan2(n[1][0],n[0][0])*T}}const q=n=>{const i=[];for(let h=0;h<n.length;h+=3)i.push([n[h],n[h+1],n[h+2]]);return i};function j(n,i,h,o){const a=R(n,i,h),e=q(o),t=5*a.w,r=n.slice(0,468).map(w=>{const p=w[2]*i-a.cz,b=(t+p)/t;return[a.cx+(w[0]*i-a.cx)*b,a.cy+(w[1]*h-a.cy)*b,p]}),{R:u,s:l,t:m}=$(e,r),d=Y(u),s=e[10],c=e[152],f=Math.hypot(c[0]-s[0],c[1]-s[1],c[2]-s[2])*l;return{cx:m[0],cy:m[1],w:l,h:f,...d,eyes:a.eyes,mouth:a.mouth}}function J(n,i,h,o){const a=R(n,i,h),e=5*o.w,t=Math.PI/180,[r,u,l]=[-o.pitch*t,-o.yaw*t,-o.roll*t];return n.slice(0,468).map(m=>{let d=m[2]*i-a.cz;const s=(e+d)/e;let c=(m[0]*i-a.cx)*s+a.cx-o.cx,f=(m[1]*h-a.cy)*s+a.cy-o.cy;return[c,f]=[c*Math.cos(l)-f*Math.sin(l),c*Math.sin(l)+f*Math.cos(l)],[c,d]=[c*Math.cos(u)-d*Math.sin(u),c*Math.sin(u)+d*Math.cos(u)],[f,d]=[f*Math.cos(r)+d*Math.sin(r),-f*Math.sin(r)+d*Math.cos(r)],[c/o.w,f/o.w,d/o.w]})}function Z(n){const i=n.filter(Boolean);if(!i.length)return{rows:n.map(()=>null),mesh:null};let h=H(i);for(let e=0;e<2;e++){const t=i.map(c=>({f:c,p:j(c.L,c.M,c.N,h)})),r=t.filter(c=>Math.abs(c.p.yaw)<25&&Math.abs(c.p.pitch)<25),u=(r.length?r:t).sort((c,f)=>Math.abs(c.p.yaw)+Math.abs(c.p.pitch)-Math.abs(f.p.yaw)-Math.abs(f.p.pitch)).slice(0,40),l=new Array(468*3).fill(0);for(const{f:c,p:f}of u)J(c.L,c.M,c.N,f).forEach((w,p)=>{l[p*3]+=w[0],l[p*3+1]+=w[1],l[p*3+2]+=w[2]});const m=q(l.map(c=>c/u.length)),d=[(m[234][0]+m[454][0])/2,(m[10][1]+m[152][1])/2,(m[234][2]+m[454][2])/2],s=Math.hypot(m[454][0]-m[234][0],m[454][1]-m[234][1],m[454][2]-m[234][2]);h=m.flatMap(c=>[0,1,2].map(f=>+((c[f]-d[f])/s).toFixed(3)))}const o=e=>Math.max(-89,Math.min(89,e));return{rows:n.map(e=>{if(!e)return null;const t=j(e.L,e.M,e.N,h),{M:r,N:u}=e;return[1,_(t.cx/r),_(t.cy/u),_(t.w/r),_(t.h/u),_(t.eyes[0][0]/r),_(t.eyes[0][1]/u),_(t.eyes[1][0]/r),_(t.eyes[1][1]/u),_(t.mouth[0]/r),_(t.mouth[1]/u),+o(t.yaw).toFixed(2),+o(t.pitch).toFixed(2),+t.roll.toFixed(2)]}),mesh:h}}const K=`https://cdn.jsdelivr.net/npm/@mediapipe/tasks-vision@${B}/wasm`,Q="/models/blaze_face_short_range.tflite",tt=640,W=10;let L=null;function nt(){if(typeof window<"u"&&window.__faceDetectorStub){const n=window.__faceDetectorStub;return Promise.resolve(n)}return L??=(async()=>{const{FilesetResolver:n,FaceDetector:i}=await N(async()=>{const{FilesetResolver:a,FaceDetector:e}=await import("./vision_bundle-9zIsgJJP.js");return{FilesetResolver:a,FaceDetector:e}},[]),h=await n.forVisionTasks(K),o=await i.createFromOptions(h,{baseOptions:{modelAssetPath:Q,delegate:"CPU"},runningMode:"VIDEO",minDetectionConfidence:.5});return(a,e)=>o.detectForVideo(a,e).detections.map(t=>{const r=t.boundingBox,u=a.width,l=a.height;return{x:r.originX/u,y:r.originY/l,w:r.width/u,h:r.height/l,score:t.categories[0]?.score??0,keypoints:t.keypoints.map(m=>({x:m.x,y:m.y}))}})})().catch(n=>{throw L=null,n}),L}const P=n=>+n.toFixed(4);function et(n,i){const h=n.filter(o=>o.keypoints.length>=4);if(!h.length)return null;if(i){const o=e=>Math.hypot(e.x+e.w/2-i[1],e.y+e.h/2-i[2]),a=h.reduce((e,t)=>o(e)<o(t)?e:t);if(o(a)<Math.max(i[3],i[4])*1.5)return a}return h.reduce((o,a)=>o.w*o.h>a.w*a.h?o:a)}const ot=n=>[P(Math.min(1,n.score)),P(n.x+n.w/2),P(n.y+n.h/2),P(n.w),P(n.h),P(n.keypoints[0].x),P(n.keypoints[0].y),P(n.keypoints[1].x),P(n.keypoints[1].y),P(n.keypoints[3].x),P(n.keypoints[3].y)];async function at({clip:n,url:i,fps:h=W,signal:o,onProgress:a}){if(n.kind!=="video")throw Error(S("Chỉ nhận diện khuôn mặt được trên clip video"));const e=await nt(),t=Object.assign(document.createElement("video"),{muted:!0,playsInline:!0,preload:"auto",crossOrigin:"anonymous"});t.src=i;try{await new Promise((y,k)=>{t.onloadeddata=()=>y(),t.onerror=()=>k(Error(S("Không đọc được video để nhận diện khuôn mặt (CORS / định dạng)")))});const r=t.videoWidth,u=t.videoHeight,l=Math.min(tt,r),m=Math.max(2,Math.round(l*u/r)),d=n.inPoint||0,s=n.duration*(n.playbackRate||1);let c=h;for(;Math.ceil(s*c)+1>I&&c>.2;)c/=2;const f=Math.min(I,Math.max(1,Math.ceil(s*c)+1)),w=Object.assign(document.createElement("canvas"),{width:l,height:m}),p=w.getContext("2d",{willReadFrequently:!0}),b=[];let M=null;for(let y=0;y<f;y++){if(o?.aborted)throw new DOMException("Đã huỷ","AbortError");const k=Math.max(0,Math.min(t.duration-1/60,d+y/c));Math.abs(t.currentTime-k)>1e-4&&await new Promise((A,g)=>{const E=window.setTimeout(()=>g(Error(S("Seek video quá lâu"))),8e3);t.onseeked=()=>{window.clearTimeout(E),A()},t.currentTime=k}),p.drawImage(t,0,0,l,m);const F=et(e(w,y+1),M),v=F?ot(F):null;b.push(v),v&&(M=v),a?.({done:y+1,total:f}),y%4===3&&await new Promise(A=>setTimeout(A,0))}const x=V(b);if(!x.length)throw Error(S("Không thấy khuôn mặt nào trong clip này (cần mặt nhìn rõ, không quá nhỏ)."));return{v:1,mw:r,mh:u,fps:+c.toFixed(4),s0:+d.toFixed(4),n:x.length,f:x}}finally{t.removeAttribute("src"),t.load()}}const rt="/models/face_landmarker.task";let C=null;function it(){if(typeof window<"u"&&window.__faceLandmarkerStub){const n=window.__faceLandmarkerStub;return Promise.resolve(n)}return typeof window<"u"&&window.__faceDetectorStub?Promise.reject(Error("No 3D face model on this page")):(C??=(async()=>{const{FilesetResolver:n,FaceLandmarker:i}=await N(async()=>{const{FilesetResolver:a,FaceLandmarker:e}=await import("./vision_bundle-9zIsgJJP.js");return{FilesetResolver:a,FaceLandmarker:e}},[]),h=await n.forVisionTasks(K),o=await i.createFromOptions(h,{baseOptions:{modelAssetPath:rt,delegate:"CPU"},runningMode:"IMAGE",numFaces:3,minFaceDetectionConfidence:.35,minFacePresenceConfidence:.35});return a=>o.detect(a).faceLandmarks.map(e=>e.map(t=>[t.x,t.y,t.z]))})().catch(n=>{throw C=null,n}),C)}let ct=null;const zt=()=>ct??=N(()=>import("./vision_bundle-9zIsgJJP.js"),[]).then(n=>n.FaceLandmarker.FACE_LANDMARKS_TESSELATION.map(i=>[i.start,i.end]));function st(n,i){if(!n.length)return null;const h=o=>{const a=o.map(t=>t[0]),e=o.map(t=>t[1]);return[(Math.min(...a)+Math.max(...a))/2,(Math.min(...e)+Math.max(...e))/2,Math.max(...a)-Math.min(...a)]};if(i){const o=e=>{const t=h(e);return Math.hypot(t[0]-i[1],t[1]-i[2])},a=n.reduce((e,t)=>o(e)<o(t)?e:t);if(o(a)<i[3]*1.5)return a}return n.reduce((o,a)=>h(o)[2]>h(a)[2]?o:a)}function ht(n,i,h,o,a,e,t){a.getContext("2d").drawImage(i,0,0,h,o);const u=n(a,t);if(u.length)return u;const l=e.getContext("2d"),m=[];for(const[d,s]of[[0,0],[.5,0],[0,.5],[.5,.5],[.25,.25]]){l.drawImage(a,d*h,s*o,h/2,o/2,0,0,e.width,e.height);for(const c of n(e,t))m.push(c.map(([f,w,p])=>[d+f/2,s+w/2,p/2]));if(m.length)break}return m}async function lt({clip:n,url:i,fps:h=W*1.5,signal:o,onProgress:a}){if(n.kind!=="video")throw Error(S("Chỉ nhận diện khuôn mặt được trên clip video"));const e=await it(),t=Object.assign(document.createElement("video"),{muted:!0,playsInline:!0,preload:"auto",crossOrigin:"anonymous"});t.src=i;try{await new Promise((F,v)=>{t.onloadeddata=()=>F(),t.onerror=()=>v(Error(S("Không đọc được video để nhận diện khuôn mặt (CORS / định dạng)")))});const r=t.videoWidth,u=t.videoHeight,l=Math.min(960,r),m=Math.max(2,Math.round(l*u/r)),d=n.inPoint||0,s=n.duration*(n.playbackRate||1);let c=h;for(;Math.ceil(s*c)+1>I&&c>.2;)c/=2;const f=Math.min(I,Math.max(1,Math.ceil(s*c)+1)),w=Object.assign(document.createElement("canvas"),{width:l,height:m}),p=Object.assign(document.createElement("canvas"),{width:l,height:m}),b=[];let M=null;for(let F=0;F<f;F++){if(o?.aborted)throw new DOMException("Đã huỷ","AbortError");const v=Math.max(0,Math.min(t.duration-1/60,d+F/c));Math.abs(t.currentTime-v)>1e-4&&await new Promise((g,E)=>{const O=window.setTimeout(()=>E(Error(S("Seek video quá lâu"))),8e3);t.onseeked=()=>{window.clearTimeout(O),g()},t.currentTime=v});const A=st(ht(e,t,l,m,w,p,F+1),M);if(b.push(A?{L:A,M:r,N:u}:null),A){const g=R(A,r,u);M=[1,g.cx/r,g.cy/u,g.w/r]}a?.({done:F+1,total:f}),F%3===2&&await new Promise(g=>setTimeout(g,0))}const{rows:x,mesh:y}=Z(b),k=G(x);if(!k.length||!y)throw Error(S("Không thấy khuôn mặt nào trong clip này (cần mặt nhìn rõ, không quá nhỏ)."));return{v:2,mw:r,mh:u,fps:+c.toFixed(4),s0:+d.toFixed(4),n:k.length,f:k,mesh:y}}finally{t.removeAttribute("src"),t.load()}}async function It(n){try{return await lt(n)}catch(i){if(i.name==="AbortError")throw i;return at(n)}}export{zt as faceMeshEdges,ot as faceSample,et as pickFace,V as smoothFaces,at as trackFace,lt as trackFace3D,It as trackFaceBest};
1
+ import{nw as I,_ as N}from"./titleFrameBudget-CLZWaFHO.js";import{a6 as B}from"./main-VVYiW8XD.js";import{t as S}from"./api-CJ8PdbfZ.js";import"./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";import"./spark.module-DzziUgOj.js";import"./userFonts-CwlKh9NR.js";import"./lottieLayer-DzbA3bHV.js";import"./timeline3d-DOw-CpZI.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 _=n=>+n.toFixed(4);function V(n){const i=n.length,h=n.map(e=>!!e),o=n.map((e,t)=>{if(e)return e.slice();for(let r=1;r<i;r++){const u=n[t-r],l=n[t+r];if(u)return[0,...u.slice(1)];if(l)return[0,...l.slice(1)]}return null});if(!o.some(Boolean))return[];const a=[];for(let e=0;e<i;e++){let t=0;const r=new Array(10).fill(0);let u=0,l=0;for(let d=-2;d<=2;d++){const s=e+d;if(s<0||s>=i)continue;const c=o[s],f=(h[s]?1:.15)*(3-Math.abs(d));t+=f;for(let w=0;w<10;w++)r[w]+=c[w+1]*f;u+=h[s]?c[0]:0,l++}const m=h[e]?n[e][0]:0;a.push([_(Math.min(m,u/l*1.25)),...r.map(d=>_(d/t))])}return a}const T=180/Math.PI;function R(n,i,h){const o=p=>[n[p][0]*i,n[p][1]*h,n[p][2]*i],a=(p,b)=>{const M=o(p),x=o(b);return[(M[0]+x[0])/2,(M[1]+x[1])/2,(M[2]+x[2])/2]},e=(p,b)=>[p[0]-b[0],p[1]-b[1],p[2]-b[2]],t=p=>Math.hypot(p[0],p[1],p[2]),r=a(33,133),u=a(362,263),l=Math.atan2(u[1]-r[1],u[0]-r[0]),m=p=>{const b=Math.cos(-l),M=Math.sin(-l);return[p[0]*b-p[1]*M,p[0]*M+p[1]*b,p[2]]},d=e(o(454),o(234)),s=e(o(152),o(10)),c=m(d),f=m(s),w=[(o(234)[0]+o(454)[0])/2,(o(10)[1]+o(152)[1])/2,(o(234)[2]+o(454)[2])/2];return{cx:w[0],cy:w[1],cz:w[2],w:t(d),h:t(s),roll:l*T,yaw:Math.atan2(c[2],c[0])*T,pitch:Math.atan2(-f[2],f[1])*T,eyes:[r,u],mouth:a(13,14)}}function U(n,i,h){const o=R(n,i,h),a=Math.PI/180,[e,t,r]=[-o.pitch*a,-o.yaw*a,-o.roll*a];return n.slice(0,468).map(u=>{let l=u[2]*i-o.cz;const m=(5*o.w+l)/(5*o.w);let d=(u[0]*i-o.cx)*m,s=(u[1]*h-o.cy)*m;return[d,s]=[d*Math.cos(r)-s*Math.sin(r),d*Math.sin(r)+s*Math.cos(r)],[d,l]=[d*Math.cos(t)-l*Math.sin(t),d*Math.sin(t)+l*Math.cos(t)],[s,l]=[s*Math.cos(e)+l*Math.sin(e),-s*Math.sin(e)+l*Math.cos(e)],[d/o.w,s/o.w,l/o.w]})}function H(n){const i=n.map(e=>({f:e,p:R(e.L,e.M,e.N)})),h=i.filter(e=>Math.abs(e.p.yaw)<25&&Math.abs(e.p.pitch)<25),o=(h.length?h:i).sort((e,t)=>Math.abs(e.p.yaw)+Math.abs(e.p.pitch)-Math.abs(t.p.yaw)-Math.abs(t.p.pitch)).slice(0,40),a=new Array(468*3).fill(0);for(const{f:e}of o)U(e.L,e.M,e.N).forEach((t,r)=>{a[r*3]+=t[0],a[r*3+1]+=t[1],a[r*3+2]+=t[2]});return a.map(e=>+(e/o.length).toFixed(3))}function G(n){const i=V(n.map(e=>e?e.slice(0,11):null));if(!i.length)return[];const h=n.length,o=n.map(e=>!!e),a=(e,t)=>{if(n[e])return n[e][t];for(let r=1;r<h;r++){const u=n[e-r],l=n[e+r];if(u)return u[t];if(l)return l[t]}return 0};return i.map((e,t)=>{const r=[11,12,13].map(u=>{let l=0,m=0;for(let d=-2;d<=2;d++){const s=t+d;if(s<0||s>=h)continue;const c=(o[s]?1:.15)*(3-Math.abs(d));l+=a(s,u)*c,m+=c}return+(l/m).toFixed(2)});return[...e,...r]})}function X(n){const i=n.map(a=>a.slice()),h=[[1,0,0,0],[0,1,0,0],[0,0,1,0],[0,0,0,1]];for(let a=0;a<50;a++){let e=0;for(let t=0;t<4;t++)for(let r=t+1;r<4;r++)e+=i[t][r]*i[t][r];if(e<1e-18)break;for(let t=0;t<4;t++)for(let r=t+1;r<4;r++){if(Math.abs(i[t][r])<1e-20)continue;const u=(i[r][r]-i[t][t])/(2*i[t][r]),l=Math.sign(u||1)/(Math.abs(u)+Math.sqrt(u*u+1)),m=1/Math.sqrt(l*l+1),d=l*m;for(let s=0;s<4;s++){const c=i[s][t],f=i[s][r];i[s][t]=m*c-d*f,i[s][r]=d*c+m*f}for(let s=0;s<4;s++){const c=i[t][s],f=i[r][s];i[t][s]=m*c-d*f,i[r][s]=d*c+m*f}for(let s=0;s<4;s++){const c=h[s][t],f=h[s][r];h[s][t]=m*c-d*f,h[s][r]=d*c+m*f}}}let o=0;for(let a=1;a<4;a++)i[a][a]>i[o][o]&&(o=a);return h.map(a=>a[o])}function $(n,i){const h=n.length,o=[0,0,0],a=[0,0,0];for(let g=0;g<h;g++)for(let E=0;E<3;E++)o[E]+=n[g][E]/h,a[E]+=i[g][E]/h;const e=[[0,0,0],[0,0,0],[0,0,0]];let t=0,r=0;for(let g=0;g<h;g++){const E=[0,1,2].map(D=>n[g][D]-o[D]),O=[0,1,2].map(D=>i[g][D]-a[D]);for(let D=0;D<3;D++)for(let z=0;z<3;z++)e[D][z]+=E[D]*O[z];t+=E[0]*E[0]+E[1]*E[1]+E[2]*E[2],r+=O[0]*O[0]+O[1]*O[1]+O[2]*O[2]}const[[u,l,m],[d,s,c],[f,w,p]]=e,b=[[u+s+p,c-w,f-m,l-d],[c-w,u-s-p,l+d,f+m],[f-m,l+d,-u+s-p,c+w],[l-d,f+m,c+w,-u-s+p]],[M,x,y,k]=X(b),F=[[M*M+x*x-y*y-k*k,2*(x*y-M*k),2*(x*k+M*y)],[2*(x*y+M*k),M*M-x*x+y*y-k*k,2*(y*k-M*x)],[2*(x*k-M*y),2*(y*k+M*x),M*M-x*x-y*y+k*k]],v=Math.sqrt(r/Math.max(1e-12,t)),A=[0,1,2].map(g=>a[g]-v*(F[g][0]*o[0]+F[g][1]*o[1]+F[g][2]*o[2]));return{R:F,s:v,t:A}}function Y(n){const i=Math.asin(Math.max(-1,Math.min(1,n[2][0])));return{pitch:Math.atan2(-n[2][1],n[2][2])*T,yaw:i*T,roll:Math.atan2(n[1][0],n[0][0])*T}}const q=n=>{const i=[];for(let h=0;h<n.length;h+=3)i.push([n[h],n[h+1],n[h+2]]);return i};function j(n,i,h,o){const a=R(n,i,h),e=q(o),t=5*a.w,r=n.slice(0,468).map(w=>{const p=w[2]*i-a.cz,b=(t+p)/t;return[a.cx+(w[0]*i-a.cx)*b,a.cy+(w[1]*h-a.cy)*b,p]}),{R:u,s:l,t:m}=$(e,r),d=Y(u),s=e[10],c=e[152],f=Math.hypot(c[0]-s[0],c[1]-s[1],c[2]-s[2])*l;return{cx:m[0],cy:m[1],w:l,h:f,...d,eyes:a.eyes,mouth:a.mouth}}function J(n,i,h,o){const a=R(n,i,h),e=5*o.w,t=Math.PI/180,[r,u,l]=[-o.pitch*t,-o.yaw*t,-o.roll*t];return n.slice(0,468).map(m=>{let d=m[2]*i-a.cz;const s=(e+d)/e;let c=(m[0]*i-a.cx)*s+a.cx-o.cx,f=(m[1]*h-a.cy)*s+a.cy-o.cy;return[c,f]=[c*Math.cos(l)-f*Math.sin(l),c*Math.sin(l)+f*Math.cos(l)],[c,d]=[c*Math.cos(u)-d*Math.sin(u),c*Math.sin(u)+d*Math.cos(u)],[f,d]=[f*Math.cos(r)+d*Math.sin(r),-f*Math.sin(r)+d*Math.cos(r)],[c/o.w,f/o.w,d/o.w]})}function Z(n){const i=n.filter(Boolean);if(!i.length)return{rows:n.map(()=>null),mesh:null};let h=H(i);for(let e=0;e<2;e++){const t=i.map(c=>({f:c,p:j(c.L,c.M,c.N,h)})),r=t.filter(c=>Math.abs(c.p.yaw)<25&&Math.abs(c.p.pitch)<25),u=(r.length?r:t).sort((c,f)=>Math.abs(c.p.yaw)+Math.abs(c.p.pitch)-Math.abs(f.p.yaw)-Math.abs(f.p.pitch)).slice(0,40),l=new Array(468*3).fill(0);for(const{f:c,p:f}of u)J(c.L,c.M,c.N,f).forEach((w,p)=>{l[p*3]+=w[0],l[p*3+1]+=w[1],l[p*3+2]+=w[2]});const m=q(l.map(c=>c/u.length)),d=[(m[234][0]+m[454][0])/2,(m[10][1]+m[152][1])/2,(m[234][2]+m[454][2])/2],s=Math.hypot(m[454][0]-m[234][0],m[454][1]-m[234][1],m[454][2]-m[234][2]);h=m.flatMap(c=>[0,1,2].map(f=>+((c[f]-d[f])/s).toFixed(3)))}const o=e=>Math.max(-89,Math.min(89,e));return{rows:n.map(e=>{if(!e)return null;const t=j(e.L,e.M,e.N,h),{M:r,N:u}=e;return[1,_(t.cx/r),_(t.cy/u),_(t.w/r),_(t.h/u),_(t.eyes[0][0]/r),_(t.eyes[0][1]/u),_(t.eyes[1][0]/r),_(t.eyes[1][1]/u),_(t.mouth[0]/r),_(t.mouth[1]/u),+o(t.yaw).toFixed(2),+o(t.pitch).toFixed(2),+t.roll.toFixed(2)]}),mesh:h}}const K=`https://cdn.jsdelivr.net/npm/@mediapipe/tasks-vision@${B}/wasm`,Q="/models/blaze_face_short_range.tflite",tt=640,W=10;let L=null;function nt(){if(typeof window<"u"&&window.__faceDetectorStub){const n=window.__faceDetectorStub;return Promise.resolve(n)}return L??=(async()=>{const{FilesetResolver:n,FaceDetector:i}=await N(async()=>{const{FilesetResolver:a,FaceDetector:e}=await import("./vision_bundle-9zIsgJJP.js");return{FilesetResolver:a,FaceDetector:e}},[]),h=await n.forVisionTasks(K),o=await i.createFromOptions(h,{baseOptions:{modelAssetPath:Q,delegate:"CPU"},runningMode:"VIDEO",minDetectionConfidence:.5});return(a,e)=>o.detectForVideo(a,e).detections.map(t=>{const r=t.boundingBox,u=a.width,l=a.height;return{x:r.originX/u,y:r.originY/l,w:r.width/u,h:r.height/l,score:t.categories[0]?.score??0,keypoints:t.keypoints.map(m=>({x:m.x,y:m.y}))}})})().catch(n=>{throw L=null,n}),L}const P=n=>+n.toFixed(4);function et(n,i){const h=n.filter(o=>o.keypoints.length>=4);if(!h.length)return null;if(i){const o=e=>Math.hypot(e.x+e.w/2-i[1],e.y+e.h/2-i[2]),a=h.reduce((e,t)=>o(e)<o(t)?e:t);if(o(a)<Math.max(i[3],i[4])*1.5)return a}return h.reduce((o,a)=>o.w*o.h>a.w*a.h?o:a)}const ot=n=>[P(Math.min(1,n.score)),P(n.x+n.w/2),P(n.y+n.h/2),P(n.w),P(n.h),P(n.keypoints[0].x),P(n.keypoints[0].y),P(n.keypoints[1].x),P(n.keypoints[1].y),P(n.keypoints[3].x),P(n.keypoints[3].y)];async function at({clip:n,url:i,fps:h=W,signal:o,onProgress:a}){if(n.kind!=="video")throw Error(S("Chỉ nhận diện khuôn mặt được trên clip video"));const e=await nt(),t=Object.assign(document.createElement("video"),{muted:!0,playsInline:!0,preload:"auto",crossOrigin:"anonymous"});t.src=i;try{await new Promise((y,k)=>{t.onloadeddata=()=>y(),t.onerror=()=>k(Error(S("Không đọc được video để nhận diện khuôn mặt (CORS / định dạng)")))});const r=t.videoWidth,u=t.videoHeight,l=Math.min(tt,r),m=Math.max(2,Math.round(l*u/r)),d=n.inPoint||0,s=n.duration*(n.playbackRate||1);let c=h;for(;Math.ceil(s*c)+1>I&&c>.2;)c/=2;const f=Math.min(I,Math.max(1,Math.ceil(s*c)+1)),w=Object.assign(document.createElement("canvas"),{width:l,height:m}),p=w.getContext("2d",{willReadFrequently:!0}),b=[];let M=null;for(let y=0;y<f;y++){if(o?.aborted)throw new DOMException("Đã huỷ","AbortError");const k=Math.max(0,Math.min(t.duration-1/60,d+y/c));Math.abs(t.currentTime-k)>1e-4&&await new Promise((A,g)=>{const E=window.setTimeout(()=>g(Error(S("Seek video quá lâu"))),8e3);t.onseeked=()=>{window.clearTimeout(E),A()},t.currentTime=k}),p.drawImage(t,0,0,l,m);const F=et(e(w,y+1),M),v=F?ot(F):null;b.push(v),v&&(M=v),a?.({done:y+1,total:f}),y%4===3&&await new Promise(A=>setTimeout(A,0))}const x=V(b);if(!x.length)throw Error(S("Không thấy khuôn mặt nào trong clip này (cần mặt nhìn rõ, không quá nhỏ)."));return{v:1,mw:r,mh:u,fps:+c.toFixed(4),s0:+d.toFixed(4),n:x.length,f:x}}finally{t.removeAttribute("src"),t.load()}}const rt="/models/face_landmarker.task";let C=null;function it(){if(typeof window<"u"&&window.__faceLandmarkerStub){const n=window.__faceLandmarkerStub;return Promise.resolve(n)}return typeof window<"u"&&window.__faceDetectorStub?Promise.reject(Error("No 3D face model on this page")):(C??=(async()=>{const{FilesetResolver:n,FaceLandmarker:i}=await N(async()=>{const{FilesetResolver:a,FaceLandmarker:e}=await import("./vision_bundle-9zIsgJJP.js");return{FilesetResolver:a,FaceLandmarker:e}},[]),h=await n.forVisionTasks(K),o=await i.createFromOptions(h,{baseOptions:{modelAssetPath:rt,delegate:"CPU"},runningMode:"IMAGE",numFaces:3,minFaceDetectionConfidence:.35,minFacePresenceConfidence:.35});return a=>o.detect(a).faceLandmarks.map(e=>e.map(t=>[t.x,t.y,t.z]))})().catch(n=>{throw C=null,n}),C)}let ct=null;const zt=()=>ct??=N(()=>import("./vision_bundle-9zIsgJJP.js"),[]).then(n=>n.FaceLandmarker.FACE_LANDMARKS_TESSELATION.map(i=>[i.start,i.end]));function st(n,i){if(!n.length)return null;const h=o=>{const a=o.map(t=>t[0]),e=o.map(t=>t[1]);return[(Math.min(...a)+Math.max(...a))/2,(Math.min(...e)+Math.max(...e))/2,Math.max(...a)-Math.min(...a)]};if(i){const o=e=>{const t=h(e);return Math.hypot(t[0]-i[1],t[1]-i[2])},a=n.reduce((e,t)=>o(e)<o(t)?e:t);if(o(a)<i[3]*1.5)return a}return n.reduce((o,a)=>h(o)[2]>h(a)[2]?o:a)}function ht(n,i,h,o,a,e,t){a.getContext("2d").drawImage(i,0,0,h,o);const u=n(a,t);if(u.length)return u;const l=e.getContext("2d"),m=[];for(const[d,s]of[[0,0],[.5,0],[0,.5],[.5,.5],[.25,.25]]){l.drawImage(a,d*h,s*o,h/2,o/2,0,0,e.width,e.height);for(const c of n(e,t))m.push(c.map(([f,w,p])=>[d+f/2,s+w/2,p/2]));if(m.length)break}return m}async function lt({clip:n,url:i,fps:h=W*1.5,signal:o,onProgress:a}){if(n.kind!=="video")throw Error(S("Chỉ nhận diện khuôn mặt được trên clip video"));const e=await it(),t=Object.assign(document.createElement("video"),{muted:!0,playsInline:!0,preload:"auto",crossOrigin:"anonymous"});t.src=i;try{await new Promise((F,v)=>{t.onloadeddata=()=>F(),t.onerror=()=>v(Error(S("Không đọc được video để nhận diện khuôn mặt (CORS / định dạng)")))});const r=t.videoWidth,u=t.videoHeight,l=Math.min(960,r),m=Math.max(2,Math.round(l*u/r)),d=n.inPoint||0,s=n.duration*(n.playbackRate||1);let c=h;for(;Math.ceil(s*c)+1>I&&c>.2;)c/=2;const f=Math.min(I,Math.max(1,Math.ceil(s*c)+1)),w=Object.assign(document.createElement("canvas"),{width:l,height:m}),p=Object.assign(document.createElement("canvas"),{width:l,height:m}),b=[];let M=null;for(let F=0;F<f;F++){if(o?.aborted)throw new DOMException("Đã huỷ","AbortError");const v=Math.max(0,Math.min(t.duration-1/60,d+F/c));Math.abs(t.currentTime-v)>1e-4&&await new Promise((g,E)=>{const O=window.setTimeout(()=>E(Error(S("Seek video quá lâu"))),8e3);t.onseeked=()=>{window.clearTimeout(O),g()},t.currentTime=v});const A=st(ht(e,t,l,m,w,p,F+1),M);if(b.push(A?{L:A,M:r,N:u}:null),A){const g=R(A,r,u);M=[1,g.cx/r,g.cy/u,g.w/r]}a?.({done:F+1,total:f}),F%3===2&&await new Promise(g=>setTimeout(g,0))}const{rows:x,mesh:y}=Z(b),k=G(x);if(!k.length||!y)throw Error(S("Không thấy khuôn mặt nào trong clip này (cần mặt nhìn rõ, không quá nhỏ)."));return{v:2,mw:r,mh:u,fps:+c.toFixed(4),s0:+d.toFixed(4),n:k.length,f:k,mesh:y}}finally{t.removeAttribute("src"),t.load()}}async function It(n){try{return await lt(n)}catch(i){if(i.name==="AbortError")throw i;return at(n)}}export{zt as faceMeshEdges,ot as faceSample,et as pickFace,V as smoothFaces,at as trackFace,lt as trackFace3D,It as trackFaceBest};
@@ -1 +1 @@
1
- import{fG as Y,gM as Z,j2 as tt,j3 as T,j4 as et,j5 as U,j6 as G,j7 as ot,j8 as st,j9 as nt,dG as it,iA as at,hD as rt,ja as ct,jb as mt}from"./remote-Dva2qg58.js";import{N as H}from"./rigTrack-UYZU4P-e.js";import"./api-DUp403BK.js";import"./titleFrameBudget-BYRZAQPs.js";import"./three.module-Bx43vjkH.js";import"./GLTFLoader-BHWu1lKg.js";import"./store-75tQUvPT.js";import"./rotoMaskStore-BxyxB2bD.js";import"./textAnimators-nVSz_sZo.js";import"./timelineComp-BcewYGR2.js";const ft=()=>crypto.randomUUID(),L=D=>Math.round(D*1e3)/1e3;function wt(D,l){const v=Y(D,{fighters:l.fighters,start:l.start,end:l.end,focal_length_mm:l.focal_length_mm}),u=v.stage,k=Z(u),c=k.duration,[h,g]=l.fighters.map(t=>u.items.find(e=>e.name===t)),{start:A,end:M}=v.result,b=tt(l.beats,A,M),R=t=>{const e=it(k,Math.max(0,Math.min(1,t/c)));return{position:[...e.position],target:[...e.target],lens:e.lens}},x=(t,e)=>{const m=at(u,t,e);return{key:{pose:m.pose,position:m.position,yaw:m.rotation[1]},scale:rt(m)}},N=(t,e)=>{const m=t.attacker===h.name?h:g,j=m===h?g:h,f=x(m,e),s=x(j,e),w=t.limb&&/^(hand|foot)[LR]$/.test(t.limb)?t.limb:"handR",n=ct(f.key,w,f.scale),i=mt(s.key,s.scale),p=i.head.a.map((P,V)=>P+(i.head.b[V]-P)*.75),a=s.key.position[0]-f.key.position[0],r=s.key.position[2]-f.key.position[2],o=Math.hypot(a,r)||1,d=[a/o,0,r/o],y=[d[2],0,-d[0]],C=R(e).position,K=(f.key.position[0]+s.key.position[0])/2,q=(f.key.position[2]+s.key.position[2])/2,O=(C[0]-K)*y[0]+(C[2]-q)*y[2]>=0?1:-1,Q=[Math.sin(s.key.yaw*Math.PI/180),0,Math.cos(s.key.yaw*Math.PI/180)];return{contact:n,foot:w.startsWith("foot"),atk:f.key.position,def:s.key.position,defHead:p,defFace:Q,axis:d,side:[y[0]*O,0,y[2]*O],sep:o}},I=(t,e)=>({id:ft(),time:t/c,position:e.position.map(L),target:e.target.map(L),lens:Math.round(e.lens*100)/100,roll:0}),B=t=>t.time*c>=A-1e-6&&t.time*c<=M+1e-6,J=(k.cameraKeys||[]).filter(B),W=(k.cameraKeys||[]).filter(t=>!B(t)),_=[];for(const t of b){const e=t.to-.001;if(t.kind==="wide"||!t.beat){_.push(I(t.from,R(t.from)),...J.filter(n=>n.time*c>t.from+1e-6&&n.time*c<e-1e-6),I(e,R(e)));continue}const m=t.kind==="insert"?t.beat.time:Math.min(e,t.beat.time+(t.kind==="reaction"?.15:.6)),j=[];for(let n=t.from;n<=e+1e-6;n+=1/30)for(const i of[h,g]){const p=x(i,n),a=H(p.key.pose,p.key.position,p.key.yaw,p.scale);j.push(...Object.values(a))}const f=N(t.beat,m);let s=T(t.kind,f);if(t.kind==="insert"){const n=[];for(const p of[-2/30,0,2/30])for(const a of[h,g]){const r=x(a,m+p),o=H(r.key.pose,r.key.position,r.key.yaw,r.scale);n.push(...Object.values(o));for(const[d,y]of[["headA","headB"],["torsoA","torsoB"]])o[d]&&o[y]&&n.push(o[d].map((C,K)=>(C+o[y][K])/2))}let i=null;for(const p of et){const a=U(T("insert",f,{...G,insertAxis:p}),j),r=a.near??1/0,o=r>=G.clearance-1e-6,d=ot(a.position,a.target,n);(!i||o&&!i.ok||o===i.ok&&(o?d<i.n:r>i.near))&&(i={ok:o,n:d,near:r,cam:a})}s=i.cam}const w=t.kind==="insert"?s:U(s,j);_.push(I(t.from,w),I(e,w))}const S=[...W,..._].sort((t,e)=>t.time-e.time),z=S[0],F=S[S.length-1],X=b.map(t=>({from:t.from/c,to:t.to/c,kind:t.kind,frames:t.kind==="insert"&&t.beat?[t.beat.attacker]:t.kind==="reaction"&&t.beat?[t.beat.target]:[h.name,g.name]})),$=(k.cuts||[]).filter(t=>t.to*c<=A+1e-6||t.from*c>=M-1e-6),E={...k,cameraKeys:S,position:z.position,target:z.target,lens:z.lens,endPosition:F.position,endTarget:F.target,endLens:F.lens,cuts:[...$,...X].sort((t,e)=>t.from-e.from)};return{stage:{...u,items:nt(u.items,E),shots:u.shots.map(t=>t.id===k.id?E:t)},result:{ok:!0,fighters:[h.name,g.name],start:A,end:M,cuts:b.length-1,shots:b.map(t=>({kind:t.kind,from:+t.from.toFixed(2),to:+t.to.toFixed(2)})),stats:st(b,l.beats),method:"the two-shot cut on the beats: a close-up on the striking limb from 0.08 s before each impact, a reaction over the striker's shoulder after it, the wide between, the finisher held low and still (shared/fightDirector.js, measured on a reference fight)"}}}export{wt as fightDirector};
1
+ import{fG as Y,gM as Z,j2 as tt,j3 as T,j4 as et,j5 as U,j6 as G,j7 as ot,j8 as st,j9 as nt,dG as it,ix as at,hD as rt,ja as ct,jb as mt}from"./remote-C7J0Tqhb.js";import{N as H}from"./rigTrack-urT3nDK0.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";const ft=()=>crypto.randomUUID(),L=D=>Math.round(D*1e3)/1e3;function wt(D,l){const v=Y(D,{fighters:l.fighters,start:l.start,end:l.end,focal_length_mm:l.focal_length_mm}),u=v.stage,k=Z(u),c=k.duration,[h,g]=l.fighters.map(t=>u.items.find(e=>e.name===t)),{start:A,end:M}=v.result,b=tt(l.beats,A,M),R=t=>{const e=it(k,Math.max(0,Math.min(1,t/c)));return{position:[...e.position],target:[...e.target],lens:e.lens}},x=(t,e)=>{const m=at(u,t,e);return{key:{pose:m.pose,position:m.position,yaw:m.rotation[1]},scale:rt(m)}},N=(t,e)=>{const m=t.attacker===h.name?h:g,j=m===h?g:h,f=x(m,e),s=x(j,e),w=t.limb&&/^(hand|foot)[LR]$/.test(t.limb)?t.limb:"handR",n=ct(f.key,w,f.scale),i=mt(s.key,s.scale),p=i.head.a.map((P,V)=>P+(i.head.b[V]-P)*.75),a=s.key.position[0]-f.key.position[0],r=s.key.position[2]-f.key.position[2],o=Math.hypot(a,r)||1,d=[a/o,0,r/o],y=[d[2],0,-d[0]],C=R(e).position,K=(f.key.position[0]+s.key.position[0])/2,q=(f.key.position[2]+s.key.position[2])/2,O=(C[0]-K)*y[0]+(C[2]-q)*y[2]>=0?1:-1,Q=[Math.sin(s.key.yaw*Math.PI/180),0,Math.cos(s.key.yaw*Math.PI/180)];return{contact:n,foot:w.startsWith("foot"),atk:f.key.position,def:s.key.position,defHead:p,defFace:Q,axis:d,side:[y[0]*O,0,y[2]*O],sep:o}},I=(t,e)=>({id:ft(),time:t/c,position:e.position.map(L),target:e.target.map(L),lens:Math.round(e.lens*100)/100,roll:0}),B=t=>t.time*c>=A-1e-6&&t.time*c<=M+1e-6,J=(k.cameraKeys||[]).filter(B),W=(k.cameraKeys||[]).filter(t=>!B(t)),_=[];for(const t of b){const e=t.to-.001;if(t.kind==="wide"||!t.beat){_.push(I(t.from,R(t.from)),...J.filter(n=>n.time*c>t.from+1e-6&&n.time*c<e-1e-6),I(e,R(e)));continue}const m=t.kind==="insert"?t.beat.time:Math.min(e,t.beat.time+(t.kind==="reaction"?.15:.6)),j=[];for(let n=t.from;n<=e+1e-6;n+=1/30)for(const i of[h,g]){const p=x(i,n),a=H(p.key.pose,p.key.position,p.key.yaw,p.scale);j.push(...Object.values(a))}const f=N(t.beat,m);let s=T(t.kind,f);if(t.kind==="insert"){const n=[];for(const p of[-2/30,0,2/30])for(const a of[h,g]){const r=x(a,m+p),o=H(r.key.pose,r.key.position,r.key.yaw,r.scale);n.push(...Object.values(o));for(const[d,y]of[["headA","headB"],["torsoA","torsoB"]])o[d]&&o[y]&&n.push(o[d].map((C,K)=>(C+o[y][K])/2))}let i=null;for(const p of et){const a=U(T("insert",f,{...G,insertAxis:p}),j),r=a.near??1/0,o=r>=G.clearance-1e-6,d=ot(a.position,a.target,n);(!i||o&&!i.ok||o===i.ok&&(o?d<i.n:r>i.near))&&(i={ok:o,n:d,near:r,cam:a})}s=i.cam}const w=t.kind==="insert"?s:U(s,j);_.push(I(t.from,w),I(e,w))}const S=[...W,..._].sort((t,e)=>t.time-e.time),z=S[0],F=S[S.length-1],X=b.map(t=>({from:t.from/c,to:t.to/c,kind:t.kind,frames:t.kind==="insert"&&t.beat?[t.beat.attacker]:t.kind==="reaction"&&t.beat?[t.beat.target]:[h.name,g.name]})),$=(k.cuts||[]).filter(t=>t.to*c<=A+1e-6||t.from*c>=M-1e-6),E={...k,cameraKeys:S,position:z.position,target:z.target,lens:z.lens,endPosition:F.position,endTarget:F.target,endLens:F.lens,cuts:[...$,...X].sort((t,e)=>t.from-e.from)};return{stage:{...u,items:nt(u.items,E),shots:u.shots.map(t=>t.id===k.id?E:t)},result:{ok:!0,fighters:[h.name,g.name],start:A,end:M,cuts:b.length-1,shots:b.map(t=>({kind:t.kind,from:+t.from.toFixed(2),to:+t.to.toFixed(2)})),stats:st(b,l.beats),method:"the two-shot cut on the beats: a close-up on the striking limb from 0.08 s before each impact, a reaction over the striker's shoulder after it, the wide between, the finisher held low and still (shared/fightDirector.js, measured on a reference fight)"}}}export{wt as fightDirector};
@@ -1,2 +1,2 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/editTools-BcGinqHC.js","assets/remote-Dva2qg58.js","assets/api-DUp403BK.js","assets/titleFrameBudget-BYRZAQPs.js","assets/three.module-Bx43vjkH.js","assets/GLTFLoader-BHWu1lKg.js","assets/store-75tQUvPT.js","assets/rotoMaskStore-BxyxB2bD.js","assets/textAnimators-nVSz_sZo.js","assets/timelineComp-BcewYGR2.js","assets/rigTrack-UYZU4P-e.js"])))=>i.map(i=>d[i]);
2
- import{_ as q}from"./titleFrameBudget-BYRZAQPs.js";import{gM as $,iR as z,iS as at,hE as C,iT as it,iU as ot,hH as rt,ft as st,fD as U,fE as B,fF as G,fG as ht,dH as ct,iV as Y,hD as dt,iW as lt,iX as mt}from"./remote-Dva2qg58.js";import{c as ut}from"./cameraPresets-DSOPj4oy.js";import"./api-DUp403BK.js";import"./three.module-Bx43vjkH.js";import"./GLTFLoader-BHWu1lKg.js";import"./store-75tQUvPT.js";import"./rotoMaskStore-BxyxB2bD.js";import"./textAnimators-nVSz_sZo.js";import"./timelineComp-BcewYGR2.js";import"./rigTrack-UYZU4P-e.js";const K=()=>crypto.randomUUID(),M=o=>Math.round(o*100)/100,ft=o=>(o.kind==="model"?(o.model?.height??2)/1.8:dt(o))*(o.scale[1]||1),Z={none:{hit:"va-cham-anime",heavy:"va-cham-huyet",aura:"",dash:"",burst:"vong-xung-kich"},lightning:{hit:"va-cham-dien",heavy:"hoa-loi-xanh",aura:"hao-quang-lam",dash:"luot-chem-loi",burst:"vong-xung-kich"},fire:{hit:"va-cham-anime",heavy:"va-cham-huyet",aura:"hao-quang-do",dash:"cot-lua-hoat-hinh",burst:"vong-xung-kich"},dark:{hit:"va-cham-huyet",heavy:"vong-xung-kich-tim",aura:"hao-quang-tim",dash:"luot-chem-loi",burst:"vong-xung-kich-tim"}};function gt(o,g){const k=(Array.isArray(o)?o:[]).slice(0,5).map(T=>{const u=T||{};return{seconds:Math.max(1.5,Math.min(20,Number(u.seconds)||2.5)),tempo:Math.max(0,Math.min(1,Number(u.tempo??.8))),ending:["none","launch","knockdown","throw"].includes(String(u.ending))?String(u.ending):"none",...u.blocks!=null?{blocks:Number(u.blocks)}:{},...u.kicks!=null?{kicks:Number(u.kicks)}:{},...u.evades!=null?{evades:Number(u.evades)}:{},...u.air?{air:!0,height:Math.max(1.5,Math.min(12,Number(u.height)||3))}:{}}});return k.length?(k[k.length-1].ending==="launch"&&k.push({seconds:2.5,tempo:1,ending:"knockdown"}),k):[{seconds:g*.42,tempo:.75,ending:"launch"},{seconds:g*.58,tempo:1,ending:"knockdown"}]}async function Nt(o,g,k,T,u,tt){const W=g.getStage(),et=$(W),S=et.duration,O=gt(o.rounds,u-T),D=(t,n,s)=>{const r=$(n),e=ct(n.items.find(a=>a.id===t.id),{...r,flight:void 0},Math.min(1,s/r.duration));return{id:t.id,name:t.name,position:[...e.position],yaw:e.rotation[1],scale:ft(t),pose:e.pose}},F=(t,n)=>({time:t.time-n,pose:t.pose,position:t.position,yaw:t.yaw,...t.plant?{plant:t.plant}:{},...t.air?{air:!0}:{},...t.pitch!=null?{pitch:t.pitch}:{},...t.strike?{strike:t.strike}:{},...t.hit?{hit:t.hit}:{}});let h=W,x=T,_=[k[0],k[1]],H;const l=[],N=[],R=[];for(let t=0;t<O.length;t++){const n=O[t],s=t===O.length-1,r=n.ending==="throw",e=s?u:Math.min(u-2,x+n.seconds+(n.ending==="launch"?1.2:r?1.6:0)),a=r?e-(s?2.2:1.6):e;if(a-x<1.5){R.push(`round ${t+1} skipped: no time left (extend the shot)`);break}const b=!!n.air,v=b?x+.8:x,w=b?a-.8:a;if(b){const i=$(h);for(const c of _){const d=D(c,h,x).position[1];let m=z(i.flight?.[c.id],{time:x/S,on:!0,height:n.height??3,ground:d});m=z(m,{time:Math.min(1,e/S),on:!1}),h={...h,shots:h.shots.map(f=>f.id===i.id?{...f,flight:{...f.flight,[c.id]:m}}:f)}}}const P=(i,c)=>{const d=$(h),m=d.flight?.[i];if(!m?.length)return null;const f=lt(m,c/d.duration,d.duration);return f.air>0?{pose:E=>mt(E,f,c),lift:f.altitude}:null},I=_.map(i=>({...D(i,h,v),...b?{airborne:!0}:{}})),y=at(I.map(({pose:i,...c})=>c),v,w,{style:tt,seed:(Number(o.seed)||7)+t*101,intensity:Math.max(0,Math.min(1,Number(o.intensity??.85))),finisher:r?"none":s?n.ending==="none"?o.finisher==="knockdown"?"knockdown":"none":n.ending:n.ending==="launch"?"launch":"none",kicks:n.kicks??Number(o.kicks??0),evades:n.evades??Number(o.evades??0),blocks:n.blocks??Number(o.blocks??.2),tempo:n.tempo,clipKeys:i=>Y(i),...H!=null?{openAt:H}:{},airOf:P,debug:o.debug===!0});if(!y.beats.length){R.push(`round ${t+1}: ${y.notes.join("; ")||"no exchange planned"}`);break}for(const i of _)h=C(h,i.id,(y.tracks[i.id]||[]).map(c=>F(c,v)),v/S,K,{replace:"span"}).stage;l.push(...y.beats.map(i=>({...i,round:t+1}))),R.push(...y.notes.map(i=>`round ${t+1}: ${i}`));let p=y.beats[y.beats.length-1];if(r){const i=_.find(f=>f.name===p.attacker)??_[0],c=_.find(f=>f.id!==i.id),d=Math.max(p.time+.35,a-.1),m=it({atk:D(i,h,d),def:D(c,h,d),start:d});h=C(h,i.id,m.atk.map(f=>F(f,d)),d/S,K,{replace:"span"}).stage,h=C(h,c.id,m.def.map(f=>F(f,d)),d/S,K,{replace:"span"}).stage,p={...p,time:m.slam,attacker:i.name,target:c.name,clip:"throw",limb:"footR",zone:"body",planned:"body",cls:"throw"},l.push({...p,round:t+1})}const Q=n.ending==="launch"&&p.planned!=="miss"&&p.planned!=="blocked";let V=e;if(b&&Q){V=Math.min(e,p.time+1.3);const i=$(h);for(const c of _){const d=(i.flight?.[c.id]||[]).filter(m=>m.time<=p.time/S+1e-6);h={...h,shots:h.shots.map(m=>m.id===i.id?{...m,flight:{...m.flight,[c.id]:z(d,{time:Math.min(1,(V+(c.name===p.target?0:.25))/S),on:!1})}}:m)}}}if((Q||r)&&!s){const i=_.find(A=>A.name===p.target),c=_.find(A=>A.id!==i.id),d=Math.max(p.time+(r?.75:1.05),b?V+.1:0),m=D(i,h,d),f=D(c,h,d+2),E=ot({charger:m,target:f,start:d,hold:Math.max(.4,Math.min(1.4,Number(o.charge_hold??.75))),clipKeys:A=>Y(A)});h=C(h,i.id,E.keys.map(A=>F(A,d)),d/S,K,{replace:"span"}).stage,N.push({launch:p.time,landed:p.time+(r?0:.55),charge:E.chargeAt,dash:E.dashAt,arrive:E.arrive,who:i.name}),_=[i,c],x=E.arrive,H=E.arrive}else x=e,H=void 0}if(!l.length)return{ok:!1,error:`no fight could be planned (${R.join("; ")||"too short"})`};const X=rt(h);h=X.stage,g.setStage(()=>h);const J=o.land!==!1?(await q(async()=>{const{landBlows:t}=await import("./editTools-BcGinqHC.js");return{landBlows:t}},__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10]))).landBlows(g,l):null;if(o.timing!==!1){const t=$(g.getStage()),n=l[l.length-1];let s=st(t.timing,t.duration);const r=[...N.map(e=>e.launch),n.time];s=U(s,l.filter(e=>e.planned!=="blocked"&&!r.includes(e.time)).map(e=>e.time),B.light,t.duration),s=U(s,l.filter(e=>e.planned==="blocked").map(e=>e.time),B.light*.7,t.duration),s=U(s,r,B.heavy,t.duration);for(const e of N)s=G(s,e.launch+.12,.3,.35,t.duration),s=G(s,e.arrive+.1,.18,.5,t.duration);o.finisher!=="none"&&(s=G(s,n.time+.05,.25,.35,t.duration)),g.setStage(e=>({...e,shots:e.shots.map(a=>a.id===t.id?{...a,timing:s??void 0}:a)}))}const L=[];if(o.vfx===!0){const{runTool:t}=await q(async()=>{const{runTool:e}=await import("./remote-Dva2qg58.js").then(a=>a.jA);return{runTool:e}},__vite__mapDeps([1,2,3,4,5,6,7,8,9,10])),n=Z[String(o.element??"none")]??Z.none,s=l[l.length-1].time,r=async e=>{(await t("add_effect",e,g)).ok&&L.push(String(e.effect))};for(const e of l){if(e.planned==="miss")continue;const a=e.time===s||N.some(b=>b.launch===e.time);await r({effect:e.planned==="blocked"?n.burst:a?n.heavy:n.hit,attach_to:e.target,start:e.time,duration:a?.4:.26,intensity:a?.32:.26})}for(const e of N)await r({effect:"bui-hoat-hinh",attach_to:e.who,start:e.landed,duration:.7,intensity:.4,params:{power:.6,puffs:8,tint:.9}}),await r({effect:"mat-dat-vo",attach_to:e.who,start:e.charge,duration:1.2,intensity:.45}),n.aura&&await r({effect:n.aura,attach_to:e.who,start:e.charge,duration:e.dash-e.charge+.3,intensity:.6}),n.dash&&await r({effect:n.dash,attach_to:e.who,start:e.dash,duration:.45,intensity:.7}),await r({effect:"xung-kich",attach_to:e.who,start:e.arrive,duration:.5,intensity:.3});o.finisher!=="none"&&String(o.element)==="lightning"&&await r({effect:"loi-kiep",from:`${l[l.length-1].attacker}.hand_right`,to:`${l[l.length-1].target}.chest`,start:s-.05,duration:.45,intensity:.4})}let j=null;if(o.director_camera===!0){const t=l[l.length-1],n=[],s=(a,b)=>{const v=new Map;for(const w of l)w.time>=a&&w.time<=b&&v.set(w.attacker,(v.get(w.attacker)??0)+1);return[...v.entries()].sort((w,P)=>P[1]-w[1])[0]?.[0]??k[0].name};let r=T;for(const a of N)n.push(["punch-beats",s(r,a.launch),r,a.launch+.12],["side-track",a.who,a.launch+.12,a.charge],["low-hero",a.who,a.charge,a.arrive]),r=a.arrive;t.time-.5-r>.4&&n.push(["punch-beats",s(r,t.time),r,t.time-.5]),n.push(["orbit-180",t.attacker,Math.max(r,t.time-.5),u]);const e=[];for(const[a,b,v,w]of n){if(w-v<.25)continue;const P=k.find(y=>y.name===b)??k[0],I=ut(g.getStage(),{preset:a,subject:P.id,start:v,end:w});I.ok&&(g.setStage(()=>I.stage),e.push(`${a} ${M(v)}–${M(w)} s on ${b}`))}j={director:e}}else if(o.camera!==!1)try{const t=ht(g.getStage(),{fighters:k.map(n=>n.name),start:T,end:u,focal_length_mm:Number(o.focal_length_mm)||32});g.setStage(()=>t.stage),j=t.result}catch(t){j={error:t.message}}const nt=$(g.getStage());return{ok:!0,fighters:k.map(t=>t.name),rounds:O.map((t,n)=>({round:n+1,tempo:t.tempo,ending:t.ending,beats:l.filter(s=>s.round===n+1).length})),...J?.length?{contact:J}:{},exchange:l.map(t=>({time_s:M(t.time),round:t.round,attacker:t.attacker,target:t.target,strike:t.cls,result:t.planned})),drama:N.map(t=>({launched:t.who,launch_s:M(t.launch),landed_s:M(t.landed),charge_s:M(t.charge),dash_s:M(t.dash),arrive_s:M(t.arrive)})),resolved:X.outcomes.slice(0,30).map(t=>({time_s:t.time_s,attacker:t.attacker,result:t.result,gap_m:t.gap_m})),video_s:M((await q(async()=>{const{outputDuration:t}=await import("./remote-Dva2qg58.js").then(n=>n.jy);return{outputDuration:t}},__vite__mapDeps([1,2,3,4,5,6,7,8,9,10]))).outputDuration(nt)),...L.length?{effects:L.length}:{},...R.length?{notes:R}:{},...j?{camera:j}:{},hint:"camera_preset per round (punch-beats / action-director on the exchanges, low-hero / orbit-180 on the charge and the finisher) reads better than one fight camera; add_effect on the drama times for more"}}export{gt as normalizeRounds,Nt as stageFightRounds};
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/editTools-CY_JrQfw.js","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 q}from"./titleFrameBudget-CLZWaFHO.js";import{gM as $,iR as z,iS as at,hE as C,iT as it,iU as ot,hH as rt,ft as st,fD as U,fE as B,fF as G,fG as ht,dH as ct,iV as Y,hD as dt,iW as lt,iX as mt}from"./remote-C7J0Tqhb.js";import{c as ut}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 K=()=>crypto.randomUUID(),M=o=>Math.round(o*100)/100,ft=o=>(o.kind==="model"?(o.model?.height??2)/1.8:dt(o))*(o.scale[1]||1),Z={none:{hit:"va-cham-anime",heavy:"va-cham-huyet",aura:"",dash:"",burst:"vong-xung-kich"},lightning:{hit:"va-cham-dien",heavy:"hoa-loi-xanh",aura:"hao-quang-lam",dash:"luot-chem-loi",burst:"vong-xung-kich"},fire:{hit:"va-cham-anime",heavy:"va-cham-huyet",aura:"hao-quang-do",dash:"cot-lua-hoat-hinh",burst:"vong-xung-kich"},dark:{hit:"va-cham-huyet",heavy:"vong-xung-kich-tim",aura:"hao-quang-tim",dash:"luot-chem-loi",burst:"vong-xung-kich-tim"}};function gt(o,g){const k=(Array.isArray(o)?o:[]).slice(0,5).map(T=>{const u=T||{};return{seconds:Math.max(1.5,Math.min(20,Number(u.seconds)||2.5)),tempo:Math.max(0,Math.min(1,Number(u.tempo??.8))),ending:["none","launch","knockdown","throw"].includes(String(u.ending))?String(u.ending):"none",...u.blocks!=null?{blocks:Number(u.blocks)}:{},...u.kicks!=null?{kicks:Number(u.kicks)}:{},...u.evades!=null?{evades:Number(u.evades)}:{},...u.air?{air:!0,height:Math.max(1.5,Math.min(12,Number(u.height)||3))}:{}}});return k.length?(k[k.length-1].ending==="launch"&&k.push({seconds:2.5,tempo:1,ending:"knockdown"}),k):[{seconds:g*.42,tempo:.75,ending:"launch"},{seconds:g*.58,tempo:1,ending:"knockdown"}]}async function Nt(o,g,k,T,u,tt){const W=g.getStage(),et=$(W),S=et.duration,O=gt(o.rounds,u-T),D=(t,n,s)=>{const r=$(n),e=ct(n.items.find(a=>a.id===t.id),{...r,flight:void 0},Math.min(1,s/r.duration));return{id:t.id,name:t.name,position:[...e.position],yaw:e.rotation[1],scale:ft(t),pose:e.pose}},F=(t,n)=>({time:t.time-n,pose:t.pose,position:t.position,yaw:t.yaw,...t.plant?{plant:t.plant}:{},...t.air?{air:!0}:{},...t.pitch!=null?{pitch:t.pitch}:{},...t.strike?{strike:t.strike}:{},...t.hit?{hit:t.hit}:{}});let h=W,x=T,_=[k[0],k[1]],H;const l=[],N=[],R=[];for(let t=0;t<O.length;t++){const n=O[t],s=t===O.length-1,r=n.ending==="throw",e=s?u:Math.min(u-2,x+n.seconds+(n.ending==="launch"?1.2:r?1.6:0)),a=r?e-(s?2.2:1.6):e;if(a-x<1.5){R.push(`round ${t+1} skipped: no time left (extend the shot)`);break}const b=!!n.air,v=b?x+.8:x,w=b?a-.8:a;if(b){const i=$(h);for(const c of _){const d=D(c,h,x).position[1];let m=z(i.flight?.[c.id],{time:x/S,on:!0,height:n.height??3,ground:d});m=z(m,{time:Math.min(1,e/S),on:!1}),h={...h,shots:h.shots.map(f=>f.id===i.id?{...f,flight:{...f.flight,[c.id]:m}}:f)}}}const P=(i,c)=>{const d=$(h),m=d.flight?.[i];if(!m?.length)return null;const f=lt(m,c/d.duration,d.duration);return f.air>0?{pose:E=>mt(E,f,c),lift:f.altitude}:null},I=_.map(i=>({...D(i,h,v),...b?{airborne:!0}:{}})),y=at(I.map(({pose:i,...c})=>c),v,w,{style:tt,seed:(Number(o.seed)||7)+t*101,intensity:Math.max(0,Math.min(1,Number(o.intensity??.85))),finisher:r?"none":s?n.ending==="none"?o.finisher==="knockdown"?"knockdown":"none":n.ending:n.ending==="launch"?"launch":"none",kicks:n.kicks??Number(o.kicks??0),evades:n.evades??Number(o.evades??0),blocks:n.blocks??Number(o.blocks??.2),tempo:n.tempo,clipKeys:i=>Y(i),...H!=null?{openAt:H}:{},airOf:P,debug:o.debug===!0});if(!y.beats.length){R.push(`round ${t+1}: ${y.notes.join("; ")||"no exchange planned"}`);break}for(const i of _)h=C(h,i.id,(y.tracks[i.id]||[]).map(c=>F(c,v)),v/S,K,{replace:"span"}).stage;l.push(...y.beats.map(i=>({...i,round:t+1}))),R.push(...y.notes.map(i=>`round ${t+1}: ${i}`));let p=y.beats[y.beats.length-1];if(r){const i=_.find(f=>f.name===p.attacker)??_[0],c=_.find(f=>f.id!==i.id),d=Math.max(p.time+.35,a-.1),m=it({atk:D(i,h,d),def:D(c,h,d),start:d});h=C(h,i.id,m.atk.map(f=>F(f,d)),d/S,K,{replace:"span"}).stage,h=C(h,c.id,m.def.map(f=>F(f,d)),d/S,K,{replace:"span"}).stage,p={...p,time:m.slam,attacker:i.name,target:c.name,clip:"throw",limb:"footR",zone:"body",planned:"body",cls:"throw"},l.push({...p,round:t+1})}const Q=n.ending==="launch"&&p.planned!=="miss"&&p.planned!=="blocked";let V=e;if(b&&Q){V=Math.min(e,p.time+1.3);const i=$(h);for(const c of _){const d=(i.flight?.[c.id]||[]).filter(m=>m.time<=p.time/S+1e-6);h={...h,shots:h.shots.map(m=>m.id===i.id?{...m,flight:{...m.flight,[c.id]:z(d,{time:Math.min(1,(V+(c.name===p.target?0:.25))/S),on:!1})}}:m)}}}if((Q||r)&&!s){const i=_.find(A=>A.name===p.target),c=_.find(A=>A.id!==i.id),d=Math.max(p.time+(r?.75:1.05),b?V+.1:0),m=D(i,h,d),f=D(c,h,d+2),E=ot({charger:m,target:f,start:d,hold:Math.max(.4,Math.min(1.4,Number(o.charge_hold??.75))),clipKeys:A=>Y(A)});h=C(h,i.id,E.keys.map(A=>F(A,d)),d/S,K,{replace:"span"}).stage,N.push({launch:p.time,landed:p.time+(r?0:.55),charge:E.chargeAt,dash:E.dashAt,arrive:E.arrive,who:i.name}),_=[i,c],x=E.arrive,H=E.arrive}else x=e,H=void 0}if(!l.length)return{ok:!1,error:`no fight could be planned (${R.join("; ")||"too short"})`};const X=rt(h);h=X.stage,g.setStage(()=>h);const J=o.land!==!1?(await q(async()=>{const{landBlows:t}=await import("./editTools-CY_JrQfw.js");return{landBlows:t}},__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10]))).landBlows(g,l):null;if(o.timing!==!1){const t=$(g.getStage()),n=l[l.length-1];let s=st(t.timing,t.duration);const r=[...N.map(e=>e.launch),n.time];s=U(s,l.filter(e=>e.planned!=="blocked"&&!r.includes(e.time)).map(e=>e.time),B.light,t.duration),s=U(s,l.filter(e=>e.planned==="blocked").map(e=>e.time),B.light*.7,t.duration),s=U(s,r,B.heavy,t.duration);for(const e of N)s=G(s,e.launch+.12,.3,.35,t.duration),s=G(s,e.arrive+.1,.18,.5,t.duration);o.finisher!=="none"&&(s=G(s,n.time+.05,.25,.35,t.duration)),g.setStage(e=>({...e,shots:e.shots.map(a=>a.id===t.id?{...a,timing:s??void 0}:a)}))}const L=[];if(o.vfx===!0){const{runTool:t}=await q(async()=>{const{runTool:e}=await import("./remote-C7J0Tqhb.js").then(a=>a.jA);return{runTool:e}},__vite__mapDeps([1,2,3,4,5,6,7,8,9,10])),n=Z[String(o.element??"none")]??Z.none,s=l[l.length-1].time,r=async e=>{(await t("add_effect",e,g)).ok&&L.push(String(e.effect))};for(const e of l){if(e.planned==="miss")continue;const a=e.time===s||N.some(b=>b.launch===e.time);await r({effect:e.planned==="blocked"?n.burst:a?n.heavy:n.hit,attach_to:e.target,start:e.time,duration:a?.4:.26,intensity:a?.32:.26})}for(const e of N)await r({effect:"bui-hoat-hinh",attach_to:e.who,start:e.landed,duration:.7,intensity:.4,params:{power:.6,puffs:8,tint:.9}}),await r({effect:"mat-dat-vo",attach_to:e.who,start:e.charge,duration:1.2,intensity:.45}),n.aura&&await r({effect:n.aura,attach_to:e.who,start:e.charge,duration:e.dash-e.charge+.3,intensity:.6}),n.dash&&await r({effect:n.dash,attach_to:e.who,start:e.dash,duration:.45,intensity:.7}),await r({effect:"xung-kich",attach_to:e.who,start:e.arrive,duration:.5,intensity:.3});o.finisher!=="none"&&String(o.element)==="lightning"&&await r({effect:"loi-kiep",from:`${l[l.length-1].attacker}.hand_right`,to:`${l[l.length-1].target}.chest`,start:s-.05,duration:.45,intensity:.4})}let j=null;if(o.director_camera===!0){const t=l[l.length-1],n=[],s=(a,b)=>{const v=new Map;for(const w of l)w.time>=a&&w.time<=b&&v.set(w.attacker,(v.get(w.attacker)??0)+1);return[...v.entries()].sort((w,P)=>P[1]-w[1])[0]?.[0]??k[0].name};let r=T;for(const a of N)n.push(["punch-beats",s(r,a.launch),r,a.launch+.12],["side-track",a.who,a.launch+.12,a.charge],["low-hero",a.who,a.charge,a.arrive]),r=a.arrive;t.time-.5-r>.4&&n.push(["punch-beats",s(r,t.time),r,t.time-.5]),n.push(["orbit-180",t.attacker,Math.max(r,t.time-.5),u]);const e=[];for(const[a,b,v,w]of n){if(w-v<.25)continue;const P=k.find(y=>y.name===b)??k[0],I=ut(g.getStage(),{preset:a,subject:P.id,start:v,end:w});I.ok&&(g.setStage(()=>I.stage),e.push(`${a} ${M(v)}–${M(w)} s on ${b}`))}j={director:e}}else if(o.camera!==!1)try{const t=ht(g.getStage(),{fighters:k.map(n=>n.name),start:T,end:u,focal_length_mm:Number(o.focal_length_mm)||32});g.setStage(()=>t.stage),j=t.result}catch(t){j={error:t.message}}const nt=$(g.getStage());return{ok:!0,fighters:k.map(t=>t.name),rounds:O.map((t,n)=>({round:n+1,tempo:t.tempo,ending:t.ending,beats:l.filter(s=>s.round===n+1).length})),...J?.length?{contact:J}:{},exchange:l.map(t=>({time_s:M(t.time),round:t.round,attacker:t.attacker,target:t.target,strike:t.cls,result:t.planned})),drama:N.map(t=>({launched:t.who,launch_s:M(t.launch),landed_s:M(t.landed),charge_s:M(t.charge),dash_s:M(t.dash),arrive_s:M(t.arrive)})),resolved:X.outcomes.slice(0,30).map(t=>({time_s:t.time_s,attacker:t.attacker,result:t.result,gap_m:t.gap_m})),video_s:M((await q(async()=>{const{outputDuration:t}=await import("./remote-C7J0Tqhb.js").then(n=>n.jy);return{outputDuration:t}},__vite__mapDeps([1,2,3,4,5,6,7,8,9,10]))).outputDuration(nt)),...L.length?{effects:L.length}:{},...R.length?{notes:R}:{},...j?{camera:j}:{},hint:"camera_preset per round (punch-beats / action-director on the exchanges, low-hero / orbit-180 on the charge and the finisher) reads better than one fight camera; add_effect on the drama times for more"}}export{gt as normalizeRounds,Nt as stageFightRounds};
@@ -1,3 +1,3 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/api-DUp403BK.js","assets/titleFrameBudget-BYRZAQPs.js"])))=>i.map(i=>d[i]);
2
- import{_ as r}from"./titleFrameBudget-BYRZAQPs.js";const c=3,f="",m=(h,s,t,e)=>!h.wants||h.wants(s,t,e);class d{wants;inline={modelFrames:{},titleFrames:{},matteFrames:{},windowFrames:{}};refs={modelFrames:{},titleFrames:{},matteFrames:{},windowFrames:{}};open=new Map;uploads=[];bytes=0;chunked=!1;signal;put;inlineLimit;chunkBytes;constructor({signal:s,put:t=u,inlineLimit:e=16*1024*1024,chunkBytes:i=6*1024*1024}={}){this.signal=s,this.put=t,this.inlineLimit=e,this.chunkBytes=i}async push(s,t,e){if(!this.chunked){if((this.inline[s][t]??=[]).push(e),this.bytes+=e.length,this.bytes>this.inlineLimit){this.chunked=!0;for(const i of Object.keys(this.inline))for(const[a,n]of Object.entries(this.inline[i]))for(const o of n)await this.add(i,a,o);this.inline={modelFrames:{},titleFrames:{},matteFrames:{},windowFrames:{}}}return}await this.add(s,t,e)}async add(s,t,e){const i=`${s}
3
- ${t}`,a=this.refs[s][t]??={chunks:[],count:0},n=this.open.get(i)??{kind:s,clip:t,frames:[],bytes:0};this.open.set(i,n),n.frames.push(e),n.bytes+=e.length,a.count++,n.bytes>=this.chunkBytes&&await this.flush(i)}async flush(s){const t=this.open.get(s);if(!t?.frames.length)return;this.open.delete(s);const e=this.refs[t.kind][t.clip],i=e.chunks.length;e.chunks.push("");const a=this.put(t.frames).then(n=>{e.chunks[i]=n});if(a.catch(()=>{}),this.uploads.push(a),this.uploads.length>=c&&await this.uploads.shift(),this.signal?.aborted)throw new DOMException("Export cancelled","AbortError")}async finish(){for(const t of[...this.open.keys()])await this.flush(t);await Promise.all(this.uploads);const s={};for(const t of["modelFrames","titleFrames","matteFrames","windowFrames"]){const e={...this.inline[t],...this.refs[t]};Object.keys(e).length&&(s[t]=e)}return s}}async function u(h){const[s]=await(await r(async()=>{const{signFrameChunks:e}=await import("./api-DUp403BK.js").then(i=>i.c2);return{signFrameChunks:e}},__vite__mapDeps([0,1]))).signFrameChunks(1),t=await fetch(s.uploadUrl,{method:"PUT",headers:s.headers,body:JSON.stringify({frames:h})});if(!t.ok)throw Error(`Tải khung hình xuất thất bại (${t.status})`);return s.readUrl}export{d as FrameSink,f as SKIPPED_FRAME,m as wantsFrame};
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{_ as r}from"./titleFrameBudget-CLZWaFHO.js";const c=3,f="",m=(h,s,t,e)=>!h.wants||h.wants(s,t,e);class d{wants;inline={modelFrames:{},titleFrames:{},matteFrames:{},windowFrames:{}};refs={modelFrames:{},titleFrames:{},matteFrames:{},windowFrames:{}};open=new Map;uploads=[];bytes=0;chunked=!1;signal;put;inlineLimit;chunkBytes;constructor({signal:s,put:t=u,inlineLimit:e=16*1024*1024,chunkBytes:i=6*1024*1024}={}){this.signal=s,this.put=t,this.inlineLimit=e,this.chunkBytes=i}async push(s,t,e){if(!this.chunked){if((this.inline[s][t]??=[]).push(e),this.bytes+=e.length,this.bytes>this.inlineLimit){this.chunked=!0;for(const i of Object.keys(this.inline))for(const[a,n]of Object.entries(this.inline[i]))for(const o of n)await this.add(i,a,o);this.inline={modelFrames:{},titleFrames:{},matteFrames:{},windowFrames:{}}}return}await this.add(s,t,e)}async add(s,t,e){const i=`${s}
3
+ ${t}`,a=this.refs[s][t]??={chunks:[],count:0},n=this.open.get(i)??{kind:s,clip:t,frames:[],bytes:0};this.open.set(i,n),n.frames.push(e),n.bytes+=e.length,a.count++,n.bytes>=this.chunkBytes&&await this.flush(i)}async flush(s){const t=this.open.get(s);if(!t?.frames.length)return;this.open.delete(s);const e=this.refs[t.kind][t.clip],i=e.chunks.length;e.chunks.push("");const a=this.put(t.frames).then(n=>{e.chunks[i]=n});if(a.catch(()=>{}),this.uploads.push(a),this.uploads.length>=c&&await this.uploads.shift(),this.signal?.aborted)throw new DOMException("Export cancelled","AbortError")}async finish(){for(const t of[...this.open.keys()])await this.flush(t);await Promise.all(this.uploads);const s={};for(const t of["modelFrames","titleFrames","matteFrames","windowFrames"]){const e={...this.inline[t],...this.refs[t]};Object.keys(e).length&&(s[t]=e)}return s}}async function u(h){const[s]=await(await r(async()=>{const{signFrameChunks:e}=await import("./api-CJ8PdbfZ.js").then(i=>i.c2);return{signFrameChunks:e}},__vite__mapDeps([0,1]))).signFrameChunks(1),t=await fetch(s.uploadUrl,{method:"PUT",headers:s.headers,body:JSON.stringify({frames:h})});if(!t.ok)throw Error(`Tải khung hình xuất thất bại (${t.status})`);return s.readUrl}export{d as FrameSink,f as SKIPPED_FRAME,m as wantsFrame};
@@ -1 +1 @@
1
- import{nb as T,lI as U,bO as V,bR as Z,bT as R,bS as H,nc as W,nd as J}from"./titleFrameBudget-BYRZAQPs.js";const rt=(n,a,e)=>Math.round(Math.min(4e7,Math.max(2e6,n*a*e*.16)));function at(n,a,e,t,o,r){const i=n.crop||{left:0,right:0,top:0,bottom:0},m=Math.max(2,Math.floor(a*(1-i.left-i.right)/2)*2),c=Math.max(2,Math.floor(e*(1-i.top-i.bottom)/2)*2);let h=i.left,y=i.top,s=m/a,f=c/e,w=0,u=0,l=t,x=o;const d=T(n,t,o);if(d){const b=Math.max(d.w/m,d.h/c),v=d.w/b/a,z=d.h/b/e;h+=(s-v)/2,y+=(f-z)/2,s=v,f=z,w=d.x,u=d.y,l=d.w,x=d.h}else if(n.fit==="cover"){const b=Math.max(t/m,o/c),v=t/b/a,z=o/b/e;h+=(s-v)/2,y+=(f-z)/2,s=v,f=z}else{const b=Math.min(t/m,o/c);l=Math.round(m*b),x=Math.round(c*b),w=(t-l)/2,u=(o-x)/2}n.flipX&&(h+=s,s=-s),n.flipY&&(y+=f,f=-f);const M=Math.max(2,Math.trunc(t*r.zoom*(r.sx??1)/2)*2),p=Math.max(2,Math.trunc(o*r.zoom*(r.sy??1)/2)*2),k=Math.trunc((t-M)/2+r.x*t),g=Math.trunc((o-p)/2+r.y*o);return{dst:[(k+w*M/t)/t,(g+u*p/o)/o,l*M/t/t,x*p/o/o],src:[h,y,s,f]}}function et(n,a){const e=Math.min(n.visualFadeIn||0,n.duration),t=Math.min(n.visualFadeOut||0,n.duration);return e>a+1e-5?{k:Math.min(1,Math.max(0,a/e)),white:n.fadeInColor==="white"}:t>0&&a>n.duration-t+1e-5?{k:Math.min(1,Math.max(0,(n.duration-a)/t)),white:n.fadeOutColor==="white"}:{k:1,white:!1}}function tt(n,a=48e3,e=.95){const t=n[0].length,o=Math.round(a*.005),r=Math.exp(-1/(a*.05)),i=new Float32Array(t);for(let h=0;h<t;h++){let y=0;for(const s of n)y=Math.max(y,Math.abs(s[h]));i[h]=y>e?e/y:1}let m=1;const c=[];for(let h=0;h<t+o;h++){if(h<t){for(;c.length&&i[c[c.length-1]]>=i[h];)c.pop();c.push(h)}const y=h-o;if(y<0)continue;for(;c.length&&c[0]<y;)c.shift();const s=c.length?i[c[0]]:1;m=Math.min(s,1-(1-m)*r);for(const f of n)f[y]*=m}}function st(n){if(n.colorBypass)return null;const a=(n.brightness??1)*2**(n.exposure??0),e=n.contrast??1,t=n.saturation??1,o=n.hue??0;if(a===1&&e===1&&t===1&&o===0)return null;const{sat:r,rot:i}=U(t,o);return{bright:a,contrast:e,sat:r,rot:i}}function it(n,a){const e=-J*255/(255-J);return(Array.isArray(n.effects)?n.effects:[]).filter(t=>!t.off&&t.amount>.001).flatMap(t=>{if(t.type==="blur")return[{type:"blur",sigma:V(t.amount,a)}];if(t.type==="glow")return[{type:"glow",sigma:Z(a),lo:e/255,k:(255-e)/255,amount:+t.amount.toFixed(4)}];if(t.type==="rgb-split")return[{type:"shift",px:R(t.amount,a)}];if(t.type==="light-burst")return[{type:"burst",amount:t.amount,lo:e/255,k:(255-e)/255}];if(t.type==="pixelate"){const r=H(t.amount,a);return r>1?[{type:"pixel",block:r}]:[]}const o=W(t.type,t.amount);return o?[{type:"colour",m:o.m,lut:o.lut,key:`${t.type}:${t.amount}`}]:[]})}function ht(n,a,e=48e3){const t=n[0]?.length??0,o=Math.max(1,Math.round(t/a));if(Math.abs(a-1)<1e-9||t<2)return n.map(u=>u.slice(0,o));const r=2*Math.round(e*.02),i=r/2,m=Math.round(e*.01),c=4,h=new Float32Array(r);for(let u=0;u<r;u++)h[u]=.5-.5*Math.cos(2*Math.PI*u/r);const y=new Float32Array(t);for(const u of n)for(let l=0;l<t;l++)y[l]+=u[l]/n.length;const s=n.map(()=>new Float32Array(o+r)),f=new Float32Array(o+r);let w=0;for(let u=0;u*i<o;u++){const l=u*i,x=Math.min(t-1,Math.round(l*a));let d=x;if(u>0){const M=w+i;let p=-1/0;for(let k=-m;k<=m;k+=2){const g=x+k;if(g<0||g+i>t||M+i>t)continue;let F=0;for(let b=0;b<i;b+=c)F+=y[g+b]*y[M+b];F>p&&(p=F,d=g)}}for(let M=0;M<n.length;M++){const p=n[M],k=s[M];for(let g=0;g<r&&d+g<t;g++)k[l+g]+=p[d+g]*h[g]}for(let M=0;M<r&&d+M<t;M++)f[l+M]+=h[M];w=d}return s.map(u=>{const l=new Float32Array(o);for(let x=0;x<o;x++)l[x]=f[x]>.001?u[x]/f[x]:u[x];return l})}function ot(n,a=48e3){if(a!==48e3)throw Error("integratedLoudness: 48 kHz only");const e=n[0].length,t=n.map(s=>{const f=new Float64Array(e),w=new Float64Array(e);let u=0,l=0,x=0,d=0;for(let M=0;M<e;M++){const p=1.53512485958697*s[M]-2.69169618940638*u+1.19839281085285*l+1.69065929318241*x-.73248077421585*d;l=u,u=s[M],d=x,x=p,f[M]=p}u=0,l=0,x=0,d=0;for(let M=0;M<e;M++){const p=f[M]-2*u+l+1.99004745483398*x-.99007225036621*d;l=u,u=f[M],d=x,x=p,w[M]=p*p}return w}),o=.4*a,r=.1*a,i=[];for(let s=0;s+o<=e;s+=r){let f=0;for(const w of t){let u=0;for(let l=s;l<s+o;l++)u+=w[l];f+=u/o}i.push(f)}const m=s=>-.691+10*Math.log10(s),c=i.filter(s=>m(s)>-70);if(!c.length)return-1/0;const h=m(c.reduce((s,f)=>s+f,0)/c.length)-10,y=c.filter(s=>m(s)>h);return m(y.reduce((s,f)=>s+f,0)/y.length)}function ct(n,a,e=48e3){const t=ot(n,e);if(!Number.isFinite(t))return t;const o=10**((a-t)/20);for(const r of n)for(let i=0;i<r.length;i++)r[i]*=o;return tt(n,e,10**(-1.5/20)),t}function ut([n,a,e,t],o,r){return[(2+n*(o-4))/o,(2+a*(r-4))/r,e*(o-4)/o,t*(r-4)/r]}function lt(n,a,e){const[[t,o],[r,i],[m,c],[h,y]]=n,s=t-r+h-m,f=o-i+y-c;let w,u,l,x,d,M,p,k;if(Math.abs(s)<1e-9&&Math.abs(f)<1e-9)w=r-t,u=h-r,l=t,x=i-o,d=y-i,M=o,p=0,k=0;else{const N=r-h,Q=m-h,_=i-y,$=c-y,j=N*$-Q*_;p=(s*$-Q*f)/j,k=(N*f-s*_)/j,w=r-t+p*r,u=m-t+k*m,l=t,x=i-o+p*i,d=c-o+k*c,M=o}const g=[w/a,u/e,l,x/a,d/e,M,p/a,k/e,1],[F,b,v,z,O,P,I,B,C]=g,S=O*C-P*B,G=-(b*C-v*B),q=b*P-v*O,L=-(z*C-P*I),X=F*C-v*I,D=-(F*P-v*z),E=z*B-O*I,Y=-(F*B-b*I),K=F*O-b*z,A=F*S+b*L+v*E;return[S/A,G/A,q/A,L/A,X/A,D/A,E/A,Y/A,K/A]}function ft(n,a,e){const t=n.crop||{left:0,right:0,top:0,bottom:0},o=Math.max(2,Math.floor(a*(1-t.left-t.right)/2)*2),r=Math.max(2,Math.floor(e*(1-t.top-t.bottom)/2)*2);let i=t.left,m=t.top,c=o/a,h=r/e;return n.flipX&&(i+=c,c=-c),n.flipY&&(m+=h,h=-h),[i,m,c,h]}function Mt(n,a,e,t,o,r,i){const m=n.crop||{left:0,right:0,top:0,bottom:0},c=Math.max(2,Math.floor(a*(1-m.left-m.right)/2)*2),h=Math.max(2,Math.floor(e*(1-m.top-m.bottom)/2)*2),y=(r.rot||0)*Math.PI/180,s=Math.cos(y),f=Math.sin(y),w=X=>Math.ceil(X/2)*2,u=w(Math.hypot(c,h)),l=i?u:w(c*Math.abs(s)+h*Math.abs(f)),x=i?u:w(c*Math.abs(f)+h*Math.abs(s)),d=Math.round(o*l/x),M=Math.round(t*x/l),p=n.fit==="cover",k=p?Math.max(d,t):Math.min(d,t),g=p?Math.max(M,o):Math.min(M,o),F=p?-Math.trunc((k-t)/2):Math.trunc((t-k)/2),b=p?-Math.trunc((g-o)/2):Math.trunc((o-g)/2),v=k/l,z=g/x,O=F+k/2,P=b+g/2,I=Math.max(2,Math.trunc(t*r.zoom*(r.sx??1)/2)*2),B=Math.max(2,Math.trunc(o*r.zoom*(r.sy??1)/2)*2),C=Math.trunc((t-I)/2+r.x*t),S=Math.trunc((o-B)/2+r.y*o),G=I/t,q=B/o,L=(X,D)=>{const E=(X-2)/(t-4)*c-c/2,Y=(D-2)/(o-4)*h-h/2,K=O+(E*s-Y*f)*v,A=P+(E*f+Y*s)*z;return[C+K*G,S+A*q]};return{quad:[L(0,0),L(t,0),L(0,o),L(t,o)],clip:p?[C,S,I,B]:null}}function mt(n,a,e,t){const o=t*Math.PI/180,r=Math.cos(o),i=Math.sin(o),m=a/2,c=e/2,h=(y,s)=>{const f=(y-2)/(a-4),w=(s-2)/(e-4),u=(n[0]+f*n[2])*a-m,l=(n[1]+w*n[3])*e-c;return[m+u*r-l*i,c+u*i+l*r]};return[h(0,0),h(a,0),h(0,e),h(a,e)]}export{at as a,it as b,ht as c,tt as d,et as f,rt as g,st as l,ct as n,ut as p,Mt as r,ft as s,mt as t,lt as w};
1
+ import{no as T,lI as U,bO as V,bR as Z,bT as R,bS as H,np as W,nq as J}from"./titleFrameBudget-CLZWaFHO.js";const rt=(n,a,e)=>Math.round(Math.min(4e7,Math.max(2e6,n*a*e*.16)));function at(n,a,e,t,o,r){const i=n.crop||{left:0,right:0,top:0,bottom:0},m=Math.max(2,Math.floor(a*(1-i.left-i.right)/2)*2),c=Math.max(2,Math.floor(e*(1-i.top-i.bottom)/2)*2);let h=i.left,y=i.top,s=m/a,f=c/e,w=0,u=0,l=t,x=o;const d=T(n,t,o);if(d){const b=Math.max(d.w/m,d.h/c),v=d.w/b/a,z=d.h/b/e;h+=(s-v)/2,y+=(f-z)/2,s=v,f=z,w=d.x,u=d.y,l=d.w,x=d.h}else if(n.fit==="cover"){const b=Math.max(t/m,o/c),v=t/b/a,z=o/b/e;h+=(s-v)/2,y+=(f-z)/2,s=v,f=z}else{const b=Math.min(t/m,o/c);l=Math.round(m*b),x=Math.round(c*b),w=(t-l)/2,u=(o-x)/2}n.flipX&&(h+=s,s=-s),n.flipY&&(y+=f,f=-f);const M=Math.max(2,Math.trunc(t*r.zoom*(r.sx??1)/2)*2),p=Math.max(2,Math.trunc(o*r.zoom*(r.sy??1)/2)*2),k=Math.trunc((t-M)/2+r.x*t),g=Math.trunc((o-p)/2+r.y*o);return{dst:[(k+w*M/t)/t,(g+u*p/o)/o,l*M/t/t,x*p/o/o],src:[h,y,s,f]}}function et(n,a){const e=Math.min(n.visualFadeIn||0,n.duration),t=Math.min(n.visualFadeOut||0,n.duration);return e>a+1e-5?{k:Math.min(1,Math.max(0,a/e)),white:n.fadeInColor==="white"}:t>0&&a>n.duration-t+1e-5?{k:Math.min(1,Math.max(0,(n.duration-a)/t)),white:n.fadeOutColor==="white"}:{k:1,white:!1}}function tt(n,a=48e3,e=.95){const t=n[0].length,o=Math.round(a*.005),r=Math.exp(-1/(a*.05)),i=new Float32Array(t);for(let h=0;h<t;h++){let y=0;for(const s of n)y=Math.max(y,Math.abs(s[h]));i[h]=y>e?e/y:1}let m=1;const c=[];for(let h=0;h<t+o;h++){if(h<t){for(;c.length&&i[c[c.length-1]]>=i[h];)c.pop();c.push(h)}const y=h-o;if(y<0)continue;for(;c.length&&c[0]<y;)c.shift();const s=c.length?i[c[0]]:1;m=Math.min(s,1-(1-m)*r);for(const f of n)f[y]*=m}}function st(n){if(n.colorBypass)return null;const a=(n.brightness??1)*2**(n.exposure??0),e=n.contrast??1,t=n.saturation??1,o=n.hue??0;if(a===1&&e===1&&t===1&&o===0)return null;const{sat:r,rot:i}=U(t,o);return{bright:a,contrast:e,sat:r,rot:i}}function it(n,a){const e=-J*255/(255-J);return(Array.isArray(n.effects)?n.effects:[]).filter(t=>!t.off&&t.amount>.001).flatMap(t=>{if(t.type==="blur")return[{type:"blur",sigma:V(t.amount,a)}];if(t.type==="glow")return[{type:"glow",sigma:Z(a),lo:e/255,k:(255-e)/255,amount:+t.amount.toFixed(4)}];if(t.type==="rgb-split")return[{type:"shift",px:R(t.amount,a)}];if(t.type==="light-burst")return[{type:"burst",amount:t.amount,lo:e/255,k:(255-e)/255}];if(t.type==="pixelate"){const r=H(t.amount,a);return r>1?[{type:"pixel",block:r}]:[]}const o=W(t.type,t.amount);return o?[{type:"colour",m:o.m,lut:o.lut,key:`${t.type}:${t.amount}`}]:[]})}function ht(n,a,e=48e3){const t=n[0]?.length??0,o=Math.max(1,Math.round(t/a));if(Math.abs(a-1)<1e-9||t<2)return n.map(u=>u.slice(0,o));const r=2*Math.round(e*.02),i=r/2,m=Math.round(e*.01),c=4,h=new Float32Array(r);for(let u=0;u<r;u++)h[u]=.5-.5*Math.cos(2*Math.PI*u/r);const y=new Float32Array(t);for(const u of n)for(let l=0;l<t;l++)y[l]+=u[l]/n.length;const s=n.map(()=>new Float32Array(o+r)),f=new Float32Array(o+r);let w=0;for(let u=0;u*i<o;u++){const l=u*i,x=Math.min(t-1,Math.round(l*a));let d=x;if(u>0){const M=w+i;let p=-1/0;for(let k=-m;k<=m;k+=2){const g=x+k;if(g<0||g+i>t||M+i>t)continue;let F=0;for(let b=0;b<i;b+=c)F+=y[g+b]*y[M+b];F>p&&(p=F,d=g)}}for(let M=0;M<n.length;M++){const p=n[M],k=s[M];for(let g=0;g<r&&d+g<t;g++)k[l+g]+=p[d+g]*h[g]}for(let M=0;M<r&&d+M<t;M++)f[l+M]+=h[M];w=d}return s.map(u=>{const l=new Float32Array(o);for(let x=0;x<o;x++)l[x]=f[x]>.001?u[x]/f[x]:u[x];return l})}function ot(n,a=48e3){if(a!==48e3)throw Error("integratedLoudness: 48 kHz only");const e=n[0].length,t=n.map(s=>{const f=new Float64Array(e),w=new Float64Array(e);let u=0,l=0,x=0,d=0;for(let M=0;M<e;M++){const p=1.53512485958697*s[M]-2.69169618940638*u+1.19839281085285*l+1.69065929318241*x-.73248077421585*d;l=u,u=s[M],d=x,x=p,f[M]=p}u=0,l=0,x=0,d=0;for(let M=0;M<e;M++){const p=f[M]-2*u+l+1.99004745483398*x-.99007225036621*d;l=u,u=f[M],d=x,x=p,w[M]=p*p}return w}),o=.4*a,r=.1*a,i=[];for(let s=0;s+o<=e;s+=r){let f=0;for(const w of t){let u=0;for(let l=s;l<s+o;l++)u+=w[l];f+=u/o}i.push(f)}const m=s=>-.691+10*Math.log10(s),c=i.filter(s=>m(s)>-70);if(!c.length)return-1/0;const h=m(c.reduce((s,f)=>s+f,0)/c.length)-10,y=c.filter(s=>m(s)>h);return m(y.reduce((s,f)=>s+f,0)/y.length)}function ct(n,a,e=48e3){const t=ot(n,e);if(!Number.isFinite(t))return t;const o=10**((a-t)/20);for(const r of n)for(let i=0;i<r.length;i++)r[i]*=o;return tt(n,e,10**(-1.5/20)),t}function ut([n,a,e,t],o,r){return[(2+n*(o-4))/o,(2+a*(r-4))/r,e*(o-4)/o,t*(r-4)/r]}function lt(n,a,e){const[[t,o],[r,i],[m,c],[h,y]]=n,s=t-r+h-m,f=o-i+y-c;let w,u,l,x,d,M,p,k;if(Math.abs(s)<1e-9&&Math.abs(f)<1e-9)w=r-t,u=h-r,l=t,x=i-o,d=y-i,M=o,p=0,k=0;else{const N=r-h,Q=m-h,_=i-y,$=c-y,j=N*$-Q*_;p=(s*$-Q*f)/j,k=(N*f-s*_)/j,w=r-t+p*r,u=m-t+k*m,l=t,x=i-o+p*i,d=c-o+k*c,M=o}const g=[w/a,u/e,l,x/a,d/e,M,p/a,k/e,1],[F,b,v,z,O,P,I,B,C]=g,S=O*C-P*B,q=-(b*C-v*B),G=b*P-v*O,L=-(z*C-P*I),X=F*C-v*I,D=-(F*P-v*z),E=z*B-O*I,Y=-(F*B-b*I),K=F*O-b*z,A=F*S+b*L+v*E;return[S/A,q/A,G/A,L/A,X/A,D/A,E/A,Y/A,K/A]}function ft(n,a,e){const t=n.crop||{left:0,right:0,top:0,bottom:0},o=Math.max(2,Math.floor(a*(1-t.left-t.right)/2)*2),r=Math.max(2,Math.floor(e*(1-t.top-t.bottom)/2)*2);let i=t.left,m=t.top,c=o/a,h=r/e;return n.flipX&&(i+=c,c=-c),n.flipY&&(m+=h,h=-h),[i,m,c,h]}function Mt(n,a,e,t,o,r,i){const m=n.crop||{left:0,right:0,top:0,bottom:0},c=Math.max(2,Math.floor(a*(1-m.left-m.right)/2)*2),h=Math.max(2,Math.floor(e*(1-m.top-m.bottom)/2)*2),y=(r.rot||0)*Math.PI/180,s=Math.cos(y),f=Math.sin(y),w=X=>Math.ceil(X/2)*2,u=w(Math.hypot(c,h)),l=i?u:w(c*Math.abs(s)+h*Math.abs(f)),x=i?u:w(c*Math.abs(f)+h*Math.abs(s)),d=Math.round(o*l/x),M=Math.round(t*x/l),p=n.fit==="cover",k=p?Math.max(d,t):Math.min(d,t),g=p?Math.max(M,o):Math.min(M,o),F=p?-Math.trunc((k-t)/2):Math.trunc((t-k)/2),b=p?-Math.trunc((g-o)/2):Math.trunc((o-g)/2),v=k/l,z=g/x,O=F+k/2,P=b+g/2,I=Math.max(2,Math.trunc(t*r.zoom*(r.sx??1)/2)*2),B=Math.max(2,Math.trunc(o*r.zoom*(r.sy??1)/2)*2),C=Math.trunc((t-I)/2+r.x*t),S=Math.trunc((o-B)/2+r.y*o),q=I/t,G=B/o,L=(X,D)=>{const E=(X-2)/(t-4)*c-c/2,Y=(D-2)/(o-4)*h-h/2,K=O+(E*s-Y*f)*v,A=P+(E*f+Y*s)*z;return[C+K*q,S+A*G]};return{quad:[L(0,0),L(t,0),L(0,o),L(t,o)],clip:p?[C,S,I,B]:null}}function mt(n,a,e,t){const o=t*Math.PI/180,r=Math.cos(o),i=Math.sin(o),m=a/2,c=e/2,h=(y,s)=>{const f=(y-2)/(a-4),w=(s-2)/(e-4),u=(n[0]+f*n[2])*a-m,l=(n[1]+w*n[3])*e-c;return[m+u*r-l*i,c+u*i+l*r]};return[h(0,0),h(a,0),h(0,e),h(a,e)]}export{at as a,it as b,ht as c,tt as d,et as f,rt as g,st as l,ct as n,ut as p,Mt as r,ft as s,mt as t,lt as w};
@@ -1,8 +1,12 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/titleFrames-BVgm601q.js","assets/titleFrameBudget-BYRZAQPs.js","assets/titleArt-B8DVR58F.js","assets/textAnimators-nVSz_sZo.js","assets/lottieLayer-1ET89OUr.js","assets/rigTrack-UYZU4P-e.js","assets/api-DUp403BK.js","assets/frameSink-BvOXjLuw.js","assets/timeline3dExport-T57qnWi9.js","assets/timeline3d-246tBEJl.js","assets/three.module-Bx43vjkH.js","assets/GLTFLoader-BHWu1lKg.js","assets/RoomEnvironment-Dmv_G5ka.js","assets/rotoMatte-BdYa8FSB.js","assets/store-75tQUvPT.js","assets/captionLayout-EuB59pN_.js"])))=>i.map(i=>d[i]);
2
- import{c1 as oo,U as qt,eS as Xo,eQ as co,cM as Mo,au as Oo,f9 as zo,lp as Go,iQ as qo,_ as Pt,il as Zt,aq as $o,lq as Qt,aR as jo,aP as fo,i0 as Ho,i1 as Vo,lr as lo,ep as Yo,f0 as uo,cd as Jt,cf as Ko,fF as Wo,fa as $t,f8 as Qo,W as eo,eI as mo,eK as po,eJ as xo,cU as jt,eM as Jo,f6 as Zo,dW as vo,ls as er,ce as tr,f2 as or,fy as rr,f1 as ir,hW as ar,et as Vt,jY as nr,eC as ho,eB as sr,hU as cr,lt as fr,lu as lr,b2 as ur,aQ as mr,lv as pr,lw as dr,lx as xr,bH as vr,aG as So,ly as hr,h as Do,lz as Er,lA as br,eh as gr,ei as Tr,ai as wr,lB as yr,eD as Rr,eE as _r,eF as Fr,ez as Ar,eG as Mr,lC as Sr,lD as Dr,fj as Ur,cq as kr,i4 as Pr,lE as Br,h_ as Nr,eH as Eo,lF as Lr,V as Ir,X as Cr,a0 as bo,lG as go,Y as To,an as Xr,lH as Or,ek as zr,a2 as Gr,a3 as qr,lI as $r,a4 as jr,ej as Hr,a5 as Vr,ab as Yr,aa as Kr,a8 as Wr,a6 as Mt,lJ as to,eN as Qr,lK as Jr,el as Zr,lL as ei,lM as ti}from"./titleFrameBudget-BYRZAQPs.js";import{b as oi,e as ri,a as ii}from"./timelineComp-BcewYGR2.js";import{g as ro,l as ot,f as Bt,p as Nt,s as wo,w as It,r as ai,a as Lt,t as ni,n as si,b as yo,c as Uo,d as ci}from"./gpuCompose-CNkLwpbZ.js";import{t as fi}from"./motionBlur-uAm030t9.js";import{f as io,h as li,z as ui,L as mi,d as pi,c as di,l as xi,b as vi}from"./exportEncode-MUwVTI52.js";import{c as hi}from"./distortGL-BlmBZKRU.js";import{c as ao,V as Ei,a as bi,I as gi,A as Ti,U as wi,b as yi}from"./id3-BCR9Bqgo.js";import{S as Ro,B as Ri,O as _i,M as Fi,a as Ai,C as Mi,A as Si}from"./output-BwZzMbp-.js";import"./api-DUp403BK.js";const Di=p=>p.kind==="image"&&!!p.title?.text&&!p.url&&!Zt(p)&&!Mo(p),Ht=p=>cr(p)||Di(p),Ct=48e3,ko=192e3,Ui=4,Po=(p,g)=>g?.name==="AbortError"||p>=Ui?null:Math.min(2**(p-1),4);async function ki(p,g){for(let w=1;;w++){let e;try{e=await fetch(p,{signal:g})}catch(z){const E=g?.aborted?null:Po(w,z);if(E===null)throw z;await new Promise(N=>setTimeout(N,E*1e3));continue}if(!e.ok)throw Error(`media ${e.status}`);return e.blob()}}const Bo=()=>bi("aac",{numberOfChannels:2,sampleRate:Ct,bitrate:ko}).catch(()=>!1),ka=async(p,g)=>await ao("avc",{width:p,height:g}).catch(()=>!1)&&Bo();async function Pa(p){try{const{width:g,height:w,fps:e}=oo(p);return typeof VideoEncoder>"u"||!new OffscreenCanvas(2,2).getContext("webgl2")?!1:(await VideoEncoder.isConfigSupported({codec:"avc1.640034",width:g,height:w,bitrate:io(null,{width:g,height:w,fps:e},ro),framerate:e,hardwareAcceleration:"prefer-software"})).supported===!0}catch{return!1}}const Ba=(p,g)=>ao("hevc",{width:p,height:g}).catch(()=>!1);async function Na(p,g){try{const{width:w,height:e,fps:z}=oo(p),E=g?.codec==="hevc";return typeof VideoEncoder>"u"||typeof AudioEncoder>"u"||typeof OfflineAudioContext>"u"||!new OffscreenCanvas(2,2).getContext("webgl2")||!(await VideoEncoder.isConfigSupported({codec:E?"hvc1.1.6.L153.B0":"avc1.640034",width:w,height:e,bitrate:io(g,{width:w,height:e,fps:z},ro),framerate:z,hardwareAcceleration:"prefer-hardware"})).supported?!1:await ao(E?"hevc":"avc",{width:w,height:e})&&await Bo()}catch{return!1}}class Pi{frames=new Map;async push(g,w,e){let z=this.frames.get(w);z||(z=[],this.frames.set(w,z)),z.push(e)}}async function _o(p,g,w,e,z,E,N){const A=g.get(w.url);if(!A)return null;if(So(w)&&!w._still){const I=`${w.id}
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/titleFrames-BI1DnLBn.js","assets/titleFrameBudget-CLZWaFHO.js","assets/titleArt-Drsrtfiv.js","assets/textAnimators-DUZjhVGO.js","assets/lottieLayer-DzbA3bHV.js","assets/rigTrack-urT3nDK0.js","assets/api-CJ8PdbfZ.js","assets/frameSink-DeM8xC8_.js","assets/timeline3dExport-BtYLU1pw.js","assets/timeline3d-DOw-CpZI.js","assets/three.module-Bx43vjkH.js","assets/GLTFLoader-BHWu1lKg.js","assets/RoomEnvironment-Dmv_G5ka.js","assets/rotoMatte-C-2o3vv0.js","assets/store-DW4E9xnW.js","assets/captionLayout-DvDPTwO9.js"])))=>i.map(i=>d[i]);
2
+ import{c1 as oo,U as qt,eS as Xo,eQ as co,cM as Mo,au as Oo,f9 as zo,lp as Go,iQ as qo,_ as Pt,il as Zt,aq as $o,lq as Qt,aR as jo,aP as fo,i0 as Ho,i1 as Vo,lr as lo,ep as Yo,f0 as uo,cd as Jt,cf as Wo,fF as Ko,fa as $t,f8 as Qo,W as eo,eI as mo,eK as po,eJ as xo,cU as jt,eM as Jo,f6 as Zo,dW as vo,ls as er,ce as tr,f2 as or,fy as rr,f1 as ir,hW as ar,et as Vt,jY as nr,eC as ho,eB as sr,hU as cr,lt as fr,lu as lr,b2 as ur,aQ as mr,lv as pr,lw as dr,lx as xr,bH as vr,aG as So,ly as hr,h as Do,lz as Er,lA as br,eh as gr,ei as Tr,ai as wr,lB as yr,eD as Rr,eE as _r,eF as Fr,ez as Ar,eG as Mr,lC as Sr,lD as Dr,fj as kr,cq as Ur,i4 as Pr,lE as Br,h_ as Nr,eH as Eo,lF as Lr,V as Ir,X as Cr,a0 as bo,lG as go,Y as To,an as Xr,lH as Or,ek as zr,a2 as Gr,a3 as qr,lI as $r,a4 as jr,ej as Hr,a5 as Vr,ab as Yr,aa as Wr,a8 as Kr,a6 as Mt,lJ as to,eN as Qr,lK as Jr,el as Zr,lL as ei,lM as ti}from"./titleFrameBudget-CLZWaFHO.js";import{b as oi,e as ri,a as ii}from"./timelineComp-B4GtoH2f.js";import{g as ro,l as ot,f as Bt,p as Nt,s as wo,w as It,r as ai,a as Lt,t as ni,n as si,b as yo,c as ko,d as ci}from"./gpuCompose-CA3UmOl4.js";import{t as fi}from"./motionBlur-uAm030t9.js";import{f as io,h as li,z as ui,L as mi,d as pi,c as di,l as xi,b as vi}from"./exportEncode-QYsT9JBO.js";import{c as hi}from"./distortGL-QalhICvi.js";import{c as ao,V as Ei,a as bi,I as gi,A as Ti,U as wi,b as yi}from"./id3-arvEpAg7.js";import{S as Ro,B as Ri,O as _i,M as Fi,a as Ai,C as Mi,A as Si}from"./output-p-Q7qous.js";import"./api-CJ8PdbfZ.js";const Di=p=>p.kind==="image"&&!!p.title?.text&&!p.url&&!Zt(p)&&!Mo(p),Ht=p=>cr(p)||Di(p),Ct=48e3,Uo=192e3,ki=4,Po=(p,g)=>g?.name==="AbortError"||p>=ki?null:Math.min(2**(p-1),4);async function Ui(p,g){for(let w=1;;w++){let e;try{e=await fetch(p,{signal:g})}catch(G){const E=g?.aborted?null:Po(w,G);if(E===null)throw G;await new Promise(N=>setTimeout(N,E*1e3));continue}if(!e.ok)throw Error(`media ${e.status}`);return e.blob()}}const Bo=()=>bi("aac",{numberOfChannels:2,sampleRate:Ct,bitrate:Uo}).catch(()=>!1),Ua=async(p,g)=>await ao("avc",{width:p,height:g}).catch(()=>!1)&&Bo();async function Pa(p){try{const{width:g,height:w,fps:e}=oo(p);return typeof VideoEncoder>"u"||!new OffscreenCanvas(2,2).getContext("webgl2")?!1:(await VideoEncoder.isConfigSupported({codec:"avc1.640034",width:g,height:w,bitrate:io(null,{width:g,height:w,fps:e},ro),framerate:e,hardwareAcceleration:"prefer-software"})).supported===!0}catch{return!1}}const Ba=(p,g)=>ao("hevc",{width:p,height:g}).catch(()=>!1);async function Na(p,g){try{const{width:w,height:e,fps:G}=oo(p),E=g?.codec==="hevc";return typeof VideoEncoder>"u"||typeof AudioEncoder>"u"||typeof OfflineAudioContext>"u"||!new OffscreenCanvas(2,2).getContext("webgl2")||!(await VideoEncoder.isConfigSupported({codec:E?"hvc1.1.6.L153.B0":"avc1.640034",width:w,height:e,bitrate:io(g,{width:w,height:e,fps:G},ro),framerate:G,hardwareAcceleration:"prefer-hardware"})).supported?!1:await ao(E?"hevc":"avc",{width:w,height:e})&&await Bo()}catch{return!1}}class Pi{frames=new Map;async push(g,w,e){let G=this.frames.get(w);G||(G=[],this.frames.set(w,G)),G.push(e)}}async function _o(p,g,w,e,G,E,N){const A=g.get(w.url);if(!A)return null;if(So(w)&&!w._still){const C=`${w.id}
3
3
  remap
4
- ${E}`,X=Math.round((e-E)*z);let $=p.get(I);if(!$){const te=A.samplesAtTimestamps(hr(w,E-w.start,Math.max(1,Math.round(N*z)),z))[Symbol.asyncIterator]();$={iterator:te,peek:null,current:null,ts0:0,idx:0,next:async()=>{const oe=await te.next();return oe.done?null:oe.value}},p.set(I,$)}for(;($.idx??0)<=X;){const te=await $.iterator.next();if($.idx=($.idx??0)+1,te.done)break;te.value&&te.value!==$.current&&($.current?.close(),$.current=te.value)}return $.current}const W=!!(w._still||w.freeze),re=W?1:w.playbackRate||1,ae=!W&&Do(w),me=ae?Er(w,E,N).start:(w.inPoint||0)+(W?0:(E-w.start)*re),xe=`${w.id}
5
- ${W?"still":E}`;let d=p.get(xe);if(!d){const I=A.samples(Math.max(0,me-.5))[Symbol.asyncIterator]();if(d={iterator:I,peek:null,current:null,ts0:me,next:async()=>{const X=await I.next();return X.done?null:X.value}},d.peek=await d.next(),!W){for(;d.peek&&d.peek.timestamp<me-1e-4;)d.peek.close(),d.peek=await d.next();d.ts0=d.peek?.timestamp??me}if(ae){const X=O=>Number(O.toFixed(6)),$=E-w.start,te=br(w,$,$+N),oe=te.slice(0,-1).map(([O,_e],Te)=>{const[Oe,we]=te[Te+1];return{xa:X(O),dx:X(Oe-O),k:Oe-O>1e-9?X((we-_e)/(Oe-O)):0}}).filter(O=>O.dx>1e-9);d.out=O=>oe.reduce((_e,Te)=>_e+Math.min(Te.dx,Math.max(0,O-Te.xa))*Te.k,0)}p.set(xe,d)}if(W){const I=Math.round(me*z);for(;d.peek&&Math.round(d.peek.timestamp*z)<=I;)d.current?.close(),d.current=d.peek,d.peek=await d.next();return d.current??d.peek}const y=Math.round((e-E)*z),_=I=>d.out?d.out(I-d.ts0):(I-d.ts0)/re;for(;d.peek&&Math.round(_(d.peek.timestamp)*z)<=y;)d.current?.close(),d.current=d.peek,d.peek=await d.next();return d.current??d.peek}const Bi=`#version 300 es
4
+ ${E}`,L=Math.round((e-E)*G);let O=p.get(C);if(!O){const te=A.samplesAtTimestamps(hr(w,E-w.start,Math.max(1,Math.round(N*G)),G))[Symbol.asyncIterator]();O={iterator:te,peek:null,current:null,ts0:0,idx:0,next:async()=>{const oe=await te.next();return oe.done?null:oe.value}},p.set(C,O)}for(;(O.idx??0)<=L;){const te=await O.iterator.next();if(O.idx=(O.idx??0)+1,te.done)break;te.value&&te.value!==O.current&&(O.current?.close(),O.current=te.value)}return O.current}const Y=!!(w._still||w.freeze),re=Y?1:w.playbackRate||1,ae=!Y&&Do(w),me=ae?Er(w,E,N).start:(w.inPoint||0)+(Y?0:(E-w.start)*re),de=`${w.id}
5
+ ${Y?"still":E}`;let d=p.get(de);if(!d){if(!Y)for(const[L,O]of p)L!==de&&L.startsWith(`${w.id}
6
+ `)&&!L.endsWith(`
7
+ still`)&&!L.includes(`
8
+ remap
9
+ `)&&(O.current?.close(),O.peek?.close(),p.delete(L),await O.iterator.return?.());const C=A.samples(Math.max(0,me-.5))[Symbol.asyncIterator]();if(d={iterator:C,peek:null,current:null,ts0:me,next:async()=>{const L=await C.next();return L.done?null:L.value}},d.peek=await d.next(),!Y){for(;d.peek&&d.peek.timestamp<me-1e-4;)d.peek.close(),d.peek=await d.next();d.ts0=d.peek?.timestamp??me}if(ae){const L=z=>Number(z.toFixed(6)),O=E-w.start,te=br(w,O,O+N),oe=te.slice(0,-1).map(([z,_e],Te)=>{const[Oe,we]=te[Te+1];return{xa:L(z),dx:L(Oe-z),k:Oe-z>1e-9?L((we-_e)/(Oe-z)):0}}).filter(z=>z.dx>1e-9);d.out=z=>oe.reduce((_e,Te)=>_e+Math.min(Te.dx,Math.max(0,z-Te.xa))*Te.k,0)}p.set(de,d)}if(Y){const C=Math.round(me*G);for(;d.peek&&Math.round(d.peek.timestamp*G)<=C;)d.current?.close(),d.current=d.peek,d.peek=await d.next();return d.current??d.peek}const y=Math.round((e-E)*G),_=C=>d.out?d.out(C-d.ts0):(C-d.ts0)/re;for(;d.peek&&Math.round(_(d.peek.timestamp)*G)<=y;)d.current?.close(),d.current=d.peek,d.peek=await d.next();return d.current??d.peek}const Bi=`#version 300 es
6
10
  in vec2 p;uniform vec4 dst;uniform vec4 src;out vec2 uv;
7
11
  void main(){uv=src.xy+p*src.zw;vec2 q=dst.xy+p*dst.zw;gl_Position=vec4(q.x*2.-1.,1.-q.y*2.,0,1);}`,Ni=`#version 300 es
8
12
  precision highp float;in vec2 uv;uniform sampler2D tex;uniform float alpha;uniform float fade;uniform float white;
@@ -30,7 +34,7 @@ void main(){vec4 c=texture(tex,uv);vec3 rgb=c.rgb;
30
34
  if(colour>.5){rgb=clamp(rgb*bright,0.,1.);rgb=clamp((rgb-.5)*contrast+.5,0.,1.);rgb=clamp(sat*rgb,0.,1.);rgb=clamp(rot*rgb,0.,1.);}
31
35
  if(useL1>.5){ivec3 k=ivec3(floor(rgb*255.+.5));rgb=floor(vec3(texelFetch(lut1,ivec2(k.r,0),0).r,texelFetch(lut1,ivec2(k.g,0),0).g,texelFetch(lut1,ivec2(k.b,0),0).b)*255.+.5)/255.;}
32
36
  if(useL3>.5)rgb=floor(clamp(tri(floor(rgb*255.+.5)/255.),0.,1.)*255.+.5)/255.;
33
- rgb=white>.5?1.-(1.-rgb)*fade:rgb*fade;o=vec4(rgb,c.a*alpha);}`,q=`#version 300 es
37
+ rgb=white>.5?1.-(1.-rgb)*fade:rgb*fade;o=vec4(rgb,c.a*alpha);}`,$=`#version 300 es
34
38
  in vec2 p;out vec2 uv;void main(){uv=p;gl_Position=vec4(p*2.-1.,0,1);}`,Li=`#version 300 es
35
39
  precision highp float;in vec2 uv;uniform sampler2D tex;uniform vec2 step;uniform float sigma;out vec4 o;
36
40
  void main(){int r=min(int(ceil(sigma*3.)),128);vec4 acc=vec4(0);float wsum=0.;
@@ -84,11 +88,11 @@ void main(){vec4 c=texture(tex,uv),v=floor(c*255.+.5);vec3 q=v.rgb;
84
88
  o=vec4(q/255.,c.a);}`,Yi=`#version 300 es
85
89
  precision highp float;uniform sampler2D tex;uniform int px;out vec4 o;
86
90
  void main(){ivec2 p=ivec2(gl_FragCoord.xy);int W=textureSize(tex,0).x;vec4 c=texelFetch(tex,p,0);
87
- o=vec4(texelFetch(tex,ivec2(clamp(p.x+px,0,W-1),p.y),0).r,c.g,texelFetch(tex,ivec2(clamp(p.x-px,0,W-1),p.y),0).b,c.a);}`,Ki=`#version 300 es
91
+ o=vec4(texelFetch(tex,ivec2(clamp(p.x+px,0,W-1),p.y),0).r,c.g,texelFetch(tex,ivec2(clamp(p.x-px,0,W-1),p.y),0).b,c.a);}`,Wi=`#version 300 es
88
92
  precision highp float;uniform sampler2D tex;uniform int b;uniform ivec2 small;out vec4 o;
89
93
  void main(){ivec2 s=textureSize(tex,0),k=ivec2(gl_FragCoord.xy);k.y=small.y-1-k.y;vec4 sum=vec4(0);float n=0.;
90
94
  for(int j=0;j<64;j++){if(j>=b)break;int y=k.y*b+j;if(y>=s.y)break;for(int i=0;i<64;i++){if(i>=b)break;int x=k.x*b+i;if(x>=s.x)break;sum+=texelFetch(tex,ivec2(x,s.y-1-y),0);n+=1.;}}
91
- o=sum/n;}`,Wi=`#version 300 es
95
+ o=sum/n;}`,Ki=`#version 300 es
92
96
  precision highp float;uniform sampler2D small;uniform int b;uniform vec2 size;out vec4 o;
93
97
  void main(){ivec2 p=ivec2(gl_FragCoord.xy),ss=textureSize(small,0);int y=int(size.y)-1-p.y;o=texelFetch(small,ivec2(p.x/b,ss.y-1-y/b),0);}`,Qi=`#version 300 es
94
98
  precision highp float;in vec2 uv;uniform sampler2D tex;uniform vec2 off;uniform vec3 col;uniform float op;uniform float times;uniform vec2 dil;out vec4 o;
@@ -190,5 +194,5 @@ void main(){vec2 p=vec2(gl_FragCoord.x-.5,size.y-gl_FragCoord.y-.5),c=size*.5-.5
190
194
  o=acc/8.;}`,va=`#version 300 es
191
195
  precision highp float;in vec2 uv;uniform sampler2D tex;uniform float w;out vec4 o;
192
196
  void main(){vec4 c=texture(tex,uv);o=vec4(mix(c.rgb,1.-c.rgb,w),c.a);}`,ha=`#version 300 es
193
- precision highp float;in vec2 uv;uniform sampler2D tex;out vec4 o;void main(){o=texture(tex,uv);}`,Ea=["wipe","blinds","split","iris","diamond","burn"];function Fo(p,g){const w=Math.max(1e-4,p.feather??.05),e=p.progress?Vt(p.progress,g)??0:g,z=(p.angle??0)*Math.PI/180,E=Math.cos(z),N=Math.sin(z),A=Ea.indexOf(p.type??""),W=p.type==="grid";return{type:"txMask",kind:W?7:A<0?6:A,e:e*(1+2*w)-w,f:w,inv:!!p.invert,cx:p.cx??.5,cy:p.cy??.5,c:E,s:N,h:.5*(Math.abs(E)+Math.abs(N)),count:p.count??(W?Sr:8)}}function Ao(p,g,w,e,z=0,E){if(!p)return[];const N=W=>Vt(p[W],g)??0,A=[];if(p.zoomBlur&&A.push({type:"txZoom",taps:Rr(),w:N("zoomBlur"),...E?{c:[E.cx,1-E.cy]}:{}}),p.spinBlur){const W=_r(w,e),re=ae=>Math.max(2,Math.round(ae/2)*2);A.push({type:"txSpin",a:W.map(ae=>+ae.a.toFixed(6)),sx:W.map(ae=>re(w*ae.scale)/w),sy:W.map(ae=>re(e*ae.scale)/e),w:N("spinBlur")})}if(p.dirBlur){const W=Eo*w/1280,re=W/(1+W);A.push({type:"txDir",b:re,reach:Math.min(512,Math.ceil(Math.log(.001)/Math.log(re))),w:N("dirBlur")})}if(p.dirBlurV){const W=Eo*w/1280,re=W/(1+W);A.push({type:"txDir",b:re,reach:Math.min(512,Math.ceil(Math.log(.001)/Math.log(re))),w:N("dirBlurV"),v:!0})}return p.blur&&A.push({type:"txGauss",sigma:Fr*w/1280,w:N("blur")}),p.glitch&&A.push({type:"txGlitch",v:N("glitch"),fr:Math.floor(z*30+.5)}),p.rgbSplit&&A.push({type:"txRgb",px:Math.trunc(N("rgbSplit")*Ar*w/1280+.5)}),p.exposure&&A.push({type:"txExpo",gain:Mr,w:N("exposure")}),p.invert&&A.push({type:"txInv",w:N("invert")}),A}function ba(p,g){const w=new OffscreenCanvas(p,g),e=w.getContext("webgl2",{premultipliedAlpha:!1,preserveDrawingBuffer:!0,antialias:!1});if(!e)throw Error("WebGL2 unavailable");const z=(n,s)=>{const o=e.createShader(n);if(e.shaderSource(o,s),e.compileShader(o),!e.getShaderParameter(o,e.COMPILE_STATUS))throw Error(String(e.getShaderInfoLog(o)));return o},E=(n,s)=>{const o=e.createProgram();if(e.attachShader(o,z(e.VERTEX_SHADER,n)),e.attachShader(o,z(e.FRAGMENT_SHADER,s)),e.bindAttribLocation(o,0,"p"),e.linkProgram(o),!e.getProgramParameter(o,e.LINK_STATUS))throw Error(String(e.getProgramInfoLog(o)));return o},N=E(Bi,Ni),A=E(q,Qi),W=E(q,Ji),re=E(q,Zi),ae=E(q,ea),me=E(q,ta),xe=E(q,oa),d=E(q,ra),y=E(q,ia),_=E(q,Li),I=E(q,Ii),X=E(q,Ci),$=E(q,ha),te=E(q,zi),oe=E(q,aa),O=E(q,na),_e=E(q,sa),Te=E(q,ca),Oe=E(q,la),we=E(q,fa),Ye=E(q,Xi),ze=E(q,Oi),ft=E(q,Gi),Fe=E(q,qi),lt=E(q,$i),Ke=E(q,ji),ye=E(q,Hi),Ge=E(q,Vi),We=E(q,Yi),Ae=E(q,Ki),Le=E(q,Wi),rt=E(q,ua),J=E(q,ma),Ee=E(q,pa),ut=E(q,va),qe=E(q,da),De=E(q,xa),it=e.createBuffer();e.bindBuffer(e.ARRAY_BUFFER,it),e.bufferData(e.ARRAY_BUFFER,new Float32Array([0,0,1,0,0,1,1,1]),e.STATIC_DRAW),e.enableVertexAttribArray(0),e.vertexAttribPointer(0,2,e.FLOAT,!1,0,0);const $e=n=>s=>e.getUniformLocation(n,s),F=$e(N);e.pixelStorei(e.UNPACK_PREMULTIPLY_ALPHA_WEBGL,!1);const pe=()=>{const n=e.createTexture();e.bindTexture(e.TEXTURE_2D,n);for(const[s,o]of[[e.TEXTURE_MIN_FILTER,e.LINEAR],[e.TEXTURE_MAG_FILTER,e.LINEAR],[e.TEXTURE_WRAP_S,e.CLAMP_TO_EDGE],[e.TEXTURE_WRAP_T,e.CLAMP_TO_EDGE]])e.texParameteri(e.TEXTURE_2D,s,o);return n},mt=pe(),wt=pe();let je=null;const at=pe(),pt=e.createTexture(),Ie={l1:"",l3:""};let yt=!1,Xt=!1,Ue=null;const Yt={add:1,screen:2,multiply:3,overlay:4,lighten:5,darken:6,difference:7,exclusion:8};let Ce=0;const Rt=pe();let U=[],He=!1,nt=null;const St=n=>{const s=Ve(),o=(n+1)%3,l=(n+2)%3;for(const R of U){let m=n;e.disable(e.BLEND),R.sigma>.05&&(j(_,s[o].fb,[s[n].tex],h=>{e.uniform1i(h("tex"),0),e.uniform2f(h("step"),1/p,0),e.uniform1f(h("sigma"),R.sigma)}),j(_,s[l].fb,[s[o].tex],h=>{e.uniform1i(h("tex"),0),e.uniform2f(h("step"),0,1/g),e.uniform1f(h("sigma"),R.sigma)}),m=l),ue(null),e.enable(e.BLEND),e.blendFuncSeparate(e.SRC_ALPHA,e.ONE_MINUS_SRC_ALPHA,e.ONE,e.ONE_MINUS_SRC_ALPHA);const[t,c,u]=[1,3,5].map(h=>parseInt(R.color.slice(h,h+2),16)/255);j(A,null,[s[m].tex],h=>{e.uniform1i(h("tex"),0),e.uniform2f(h("off"),Math.trunc(R.dx)/p,-Math.trunc(R.dy)/g),e.uniform3f(h("col"),t,c,u),e.uniform1f(h("op"),R.opacity),e.uniform1f(h("times"),R.times),e.uniform2f(h("dil"),R.dilate?+(ei*255).toFixed(3):0,R.dilate?+(1/ti).toFixed(3):0)})}},Qe=n=>{const s=Ve();if(He){ue(nt.fb),e.enable(e.BLEND),e.blendFunc(e.ONE,e.ONE),j(xe,nt.fb,[s[n].tex],o=>e.uniform1i(o("tex"),0)),e.blendFuncSeparate(e.SRC_ALPHA,e.ONE_MINUS_SRC_ALPHA,e.ONE,e.ONE_MINUS_SRC_ALPHA);return}if(U.length&&St(n),Ce){Xe(s[n].tex);return}ue(null),e.enable(e.BLEND),e.blendFuncSeparate(e.SRC_ALPHA,e.ONE_MINUS_SRC_ALPHA,e.ONE,e.ONE_MINUS_SRC_ALPHA),j($,null,[s[n].tex],o=>e.uniform1i(o("tex"),0))},Xe=n=>{ue(null),e.bindTexture(e.TEXTURE_2D,Rt),e.copyTexImage2D(e.TEXTURE_2D,0,e.RGBA8,0,0,p,g,0),e.disable(e.BLEND),j(rt,null,[n,Rt],s=>{e.uniform1i(s("top"),0),e.uniform1i(s("bg"),1),e.uniform1i(s("mode"),Ce)})};let ke=null;const Ve=()=>ke??=[Me(),Me(),Me()],Je=new Map,_t=n=>{let s=Je.get(n);if(s)return s;const o=()=>{const l=pe();e.texImage2D(e.TEXTURE_2D,0,e.RGBA8,p*n,g*n,0,e.RGBA,e.UNSIGNED_BYTE,null);const R=e.createFramebuffer();return e.bindFramebuffer(e.FRAMEBUFFER,R),e.framebufferTexture2D(e.FRAMEBUFFER,e.COLOR_ATTACHMENT0,e.TEXTURE_2D,l,0),{tex:l,fb:R}};return s={plane:o(),out:o()},Je.set(n,s),s},Ze=new Map,Ft=new Map,Dt=n=>{let s=Ze.get(n.key);if(s)return s;s=pe();const o=new Uint8Array(256*3);(n.lut??[]).forEach((l,R)=>o.set(l,R*256)),e.pixelStorei(e.UNPACK_ALIGNMENT,1),e.texImage2D(e.TEXTURE_2D,0,e.R8,256,3,0,e.RED,e.UNSIGNED_BYTE,o),e.pixelStorei(e.UNPACK_ALIGNMENT,4);for(const l of[e.TEXTURE_MIN_FILTER,e.TEXTURE_MAG_FILTER])e.texParameteri(e.TEXTURE_2D,l,e.NEAREST);return Ze.set(n.key,s),s},Ot=(n,s)=>{const o=`${n}x${s}`;let l=Ft.get(o);if(l)return l;const R=pe();e.texImage2D(e.TEXTURE_2D,0,e.RGBA8,n,s,0,e.RGBA,e.UNSIGNED_BYTE,null);for(const t of[e.TEXTURE_MIN_FILTER,e.TEXTURE_MAG_FILTER])e.texParameteri(e.TEXTURE_2D,t,e.NEAREST);const m=e.createFramebuffer();return e.bindFramebuffer(e.FRAMEBUFFER,m),e.framebufferTexture2D(e.FRAMEBUFFER,e.COLOR_ATTACHMENT0,e.TEXTURE_2D,R,0),l={tex:R,fb:m},Ft.set(o,l),l},zt=new Map,Kt=(n,s)=>{const o=`${n}x${s}`;let l=zt.get(o);return l||(l=[0,1].map(()=>{const R=pe();e.texImage2D(e.TEXTURE_2D,0,e.RGBA8,n,s,0,e.RGBA,e.UNSIGNED_BYTE,null);const m=e.createFramebuffer();return e.bindFramebuffer(e.FRAMEBUFFER,m),e.framebufferTexture2D(e.FRAMEBUFFER,e.COLOR_ATTACHMENT0,e.TEXTURE_2D,R,0),{tex:R,fb:m}}),zt.set(o,l),l)},Me=()=>{const n=pe();e.texImage2D(e.TEXTURE_2D,0,e.RGBA8,p,g,0,e.RGBA,e.UNSIGNED_BYTE,null);const s=e.createFramebuffer();return e.bindFramebuffer(e.FRAMEBUFFER,s),e.framebufferTexture2D(e.FRAMEBUFFER,e.COLOR_ATTACHMENT0,e.TEXTURE_2D,n,0),{tex:n,fb:s}},ue=n=>{e.bindFramebuffer(e.FRAMEBUFFER,n),e.viewport(0,0,p,g)},j=(n,s,o,l)=>st(n,s,p,g,o,l),st=(n,s,o,l,R,m)=>{e.bindFramebuffer(e.FRAMEBUFFER,s),e.viewport(0,0,o,l),e.useProgram(n);const t=$e(n);R.forEach((c,u)=>{e.activeTexture(e.TEXTURE0+u),e.bindTexture(e.TEXTURE_2D,c)}),m(t),e.drawArrays(e.TRIANGLE_STRIP,0,4),R.length>1&&At(),e.activeTexture(e.TEXTURE0)},At=()=>{e.activeTexture(e.TEXTURE1),e.bindTexture(e.TEXTURE_2D,wt),e.activeTexture(e.TEXTURE2),e.bindTexture(e.TEXTURE_2D,at),e.activeTexture(e.TEXTURE3),e.bindTexture(e.TEXTURE_3D,pt),e.activeTexture(e.TEXTURE0)},dt=(n,s=0)=>{const o=Ve();let l=s;const R=(t,c,u,h)=>{j(_,o[c].fb,[o[t].tex],i=>{e.uniform1i(i("tex"),0),e.uniform2f(i("step"),1/p,0),e.uniform1f(i("sigma"),h)}),j(_,o[u].fb,[o[c].tex],i=>{e.uniform1i(i("tex"),0),e.uniform2f(i("step"),0,1/g),e.uniform1f(i("sigma"),h)})},m=(t,c,u,h)=>j(Fe,o[u].fb,[o[t].tex,o[c].tex],i=>{e.uniform1i(i("a"),0),e.uniform1i(i("b"),1),e.uniform1f(i("w"),h)});for(const t of n){const[c,u,h]=[l,(l+1)%3,(l+2)%3];if(t.type==="blur"){t.sigma>.05&&(R(c,u,h,t.sigma),l=h);continue}if(t.type==="colour"){const i=Dt(t);j(Ge,o[u].fb,[o[c].tex,i],v=>{e.uniform1i(v("tex"),0),e.uniform1i(v("lut"),1),e.uniform1f(v("useM"),t.m?1:0),e.uniform1f(v("useL"),t.lut?1:0),t.m&&e.uniform1fv(v("m"),t.m.flatMap(M=>[M[0],M[1],M[2],M[3]??0]))}),l=u;continue}if(t.type==="txRgb"){t.px>0&&(j(Ee,o[u].fb,[o[c].tex],i=>{e.uniform1i(i("tex"),0),e.uniform1i(i("px"),t.px)}),l=u);continue}if(t.type==="txGlitch"){t.v>1e-4&&(j(qe,o[u].fb,[o[c].tex],i=>{e.uniform1i(i("tex"),0),e.uniform2f(i("size"),p,g),e.uniform2f(i("msize"),Math.max(2,Math.round(p/4)),Math.max(2,Math.round(g/4))),e.uniform1f(i("v"),t.v),e.uniform1f(i("fr"),t.fr)}),l=u);continue}if(t.type==="txInv"){t.w>1e-4&&(j(ut,o[u].fb,[o[c].tex],i=>{e.uniform1i(i("tex"),0),e.uniform1f(i("w"),Math.min(1,t.w))}),l=u);continue}if(t.type==="shift"){j(We,o[u].fb,[o[c].tex],i=>{e.uniform1i(i("tex"),0),e.uniform1i(i("px"),t.px)}),l=u;continue}if(t.type==="pixel"){const i=Math.ceil(p/t.block),v=Math.ceil(g/t.block),M=Ot(i,v);e.bindFramebuffer(e.FRAMEBUFFER,M.fb),e.viewport(0,0,i,v),e.useProgram(Ae),e.activeTexture(e.TEXTURE0),e.bindTexture(e.TEXTURE_2D,o[c].tex),e.uniform1i(e.getUniformLocation(Ae,"tex"),0),e.uniform1i(e.getUniformLocation(Ae,"b"),t.block),e.uniform2i(e.getUniformLocation(Ae,"small"),i,v),e.drawArrays(e.TRIANGLE_STRIP,0,4),j(Le,o[u].fb,[M.tex],Q=>{e.uniform1i(Q("small"),0),e.uniform1i(Q("b"),t.block),e.uniform2f(Q("size"),p,g)}),l=u;continue}if(t.type==="txMask"){j(ye,o[u].fb,[o[c].tex],i=>{e.uniform1i(i("tex"),0),e.uniform2f(i("size"),p,g),e.uniform1i(i("kind"),t.kind),e.uniform1f(i("e"),t.e),e.uniform1f(i("f"),t.f),e.uniform1f(i("inv"),t.inv?1:0),e.uniform2f(i("ctr"),t.cx,t.cy),e.uniform3f(i("csh"),t.c,t.s,t.h),e.uniform1f(i("count"),t.count)}),l=u;continue}if(t.type==="txGauss"||t.type==="txDir"||t.type==="txZoom"||t.type==="txSpin"||t.type==="txExpo"){if(!(t.w>1e-4))continue;let i=u;t.type==="txGauss"?(R(c,u,h,t.sigma),i=h):t.type==="txDir"?j(Ye,o[u].fb,[o[c].tex],M=>{e.uniform1i(M("tex"),0),t.v?e.uniform2f(M("step"),0,1/g):e.uniform2f(M("step"),1/p,0),e.uniform1f(M("b"),t.b),e.uniform1i(M("reach"),t.reach)}):t.type==="txZoom"?j(ze,o[u].fb,[o[c].tex],M=>{e.uniform1i(M("tex"),0),e.uniform1fv(M("taps"),t.taps),e.uniform1i(M("n"),t.taps.length),e.uniform2f(M("ctr"),t.c?.[0]??.5,t.c?.[1]??.5)}):t.type==="txSpin"?j(De,o[u].fb,[o[c].tex],M=>{e.uniform1i(M("tex"),0),e.uniform2f(M("size"),p,g),e.uniform1fv(M("a"),t.a),e.uniform1fv(M("sx"),t.sx),e.uniform1fv(M("sy"),t.sy)}):j(ft,o[u].fb,[o[c].tex],M=>{e.uniform1i(M("tex"),0),e.uniform1f(M("gain"),t.gain)});const v=i===h?u:h;m(c,i,v,Math.min(1,t.w)),l=v;continue}if(t.type==="burst"){const{w:i,h:v}=di(p,g),[M,Q]=Kt(i,v),K=ui(mi.burst*t.amount).map(V=>pi(i,v,V));j(I,o[u].fb,[o[c].tex],V=>{e.uniform1i(V("tex"),0),e.uniform1f(V("lo"),t.lo),e.uniform1f(V("k"),t.k)}),st($,M.fb,i,v,[o[u].tex],V=>e.uniform1i(V("tex"),0)),st(te,Q.fb,i,v,[M.tex],V=>{e.uniform1i(V("tex"),0),e.uniform1i(V("n"),K.length),e.uniform1fv(V("sx"),K.map(be=>be.sw/i)),e.uniform1fv(V("sy"),K.map(be=>be.sh/v)),e.uniform3f(V("gain"),...vi(t.amount))}),j(X,o[h].fb,[o[c].tex,Q.tex],V=>{e.uniform1i(V("a"),0),e.uniform1i(V("b"),1),e.uniform1f(V("amount"),+t.amount.toFixed(4))}),l=h;continue}j(I,o[u].fb,[o[c].tex],i=>{e.uniform1i(i("tex"),0),e.uniform1f(i("lo"),t.lo),e.uniform1f(i("k"),t.k)}),R(u,h,u,t.sigma),j(X,o[h].fb,[o[c].tex,o[u].tex],i=>{e.uniform1i(i("a"),0),e.uniform1i(i("b"),1),e.uniform1f(i("amount"),t.amount)}),l=h}return l};let ct=null,r="",f=[],k="";const x=(n,s)=>{if(k!==`${n}x${s}`){for(const o of f)e.deleteTexture(o.tex),e.deleteFramebuffer(o.fb);f=Array.from({length:4},()=>{const o=pe();e.texImage2D(e.TEXTURE_2D,0,e.RGBA8,n,s,0,e.RGBA,e.UNSIGNED_BYTE,null);const l=e.createFramebuffer();return e.bindFramebuffer(e.FRAMEBUFFER,l),e.framebufferTexture2D(e.FRAMEBUFFER,e.COLOR_ATTACHMENT0,e.TEXTURE_2D,o,0),{tex:o,fb:l}}),k=`${n}x${s}`}return f},T=(n,s,o,l)=>{const R=e.getParameter(e.FRAMEBUFFER_BINDING),m=e.getParameter(e.VIEWPORT),t=e.isEnabled(e.BLEND),c=x(l.ew,l.eh),u=(i,v,M,Q)=>{e.bindFramebuffer(e.FRAMEBUFFER,c[v].fb),e.viewport(0,0,l.ew,l.eh),e.useProgram(i);const K=$e(i);M.forEach((V,be)=>{e.activeTexture(e.TEXTURE0+be),e.bindTexture(e.TEXTURE_2D,c[V].tex)}),Q(K),e.drawArrays(e.TRIANGLE_STRIP,0,4),M.length>1&&At(),e.activeTexture(e.TEXTURE0)};e.disable(e.BLEND),e.bindFramebuffer(e.FRAMEBUFFER,c[0].fb),e.viewport(0,0,l.ew,l.eh),e.clearColor(0,0,0,0),e.clear(e.COLOR_BUFFER_BIT);{const i=Ut(n,o);e.bindFramebuffer(e.FRAMEBUFFER,c[0].fb),e.viewport(0,0,l.ew,l.eh),e.disable(e.BLEND),vt(n,[0,0,1,1],s,1,1,!1,i==="win"?null:o,i)}u(W,1,[0],i=>{e.uniform1i(i("tex"),0),e.uniform1f(i("harden"),l.harden?Qr:0)});const h=(i,v,M,Q)=>{u(re,v,[i],K=>{e.uniform1i(K("tex"),0),e.uniform2i(K("dir"),1,0),e.uniform1f(K("sigma"),Q)}),u(re,M,[v],K=>{e.uniform1i(K("tex"),0),e.uniform2i(K("dir"),0,1),e.uniform1f(K("sigma"),Q)})};h(1,2,3,l.band),u(ae,2,[1,3],i=>{e.uniform1i(i("a"),0),e.uniform1i(i("b"),1);const v=l.arc;e.uniform1f(i("arc"),v?1:0),v&&(e.uniform2f(i("cw"),l.ew/to,l.eh/to),e.uniform2f(i("cen"),v.cen[0],v.cen[1]),e.uniform1f(i("start"),v.start),e.uniform1f(i("cover"),v.cover),e.uniform1f(i("comet"),v.comet?1:0),e.uniform1f(i("feather"),Jr*v.cover))}),h(2,1,3,l.glow),u(me,1,[0,2,3],i=>{e.uniform1i(i("pic"),0),e.uniform1i(i("band"),1),e.uniform1i(i("glow"),2),e.uniform3f(i("col"),...l.col),e.uniform1f(i("k"),l.k),e.uniform1f(i("am"),l.am)}),e.bindFramebuffer(e.FRAMEBUFFER,R),e.viewport(m[0],m[1],m[2],m[3]),t&&e.enable(e.BLEND)};let C=null,P="",ce=null,Y=[],Z="";const a=new Map,S=new Map,fe=new Map,ve=new Map,ne=new Map,Re=new Map,se=pe(),B=(n,s)=>{const o=pe();e.texImage2D(e.TEXTURE_2D,0,e.RGBA8,n,s,0,e.RGBA,e.UNSIGNED_BYTE,null);const l=e.createFramebuffer();return e.bindFramebuffer(e.FRAMEBUFFER,l),e.framebufferTexture2D(e.FRAMEBUFFER,e.COLOR_ATTACHMENT0,e.TEXTURE_2D,o,0),{tex:o,fb:l}},Pe=(n,s,o)=>{const l=e.getParameter(e.FRAMEBUFFER_BINDING),R=e.getParameter(e.VIEWPORT),m=e.isEnabled(e.BLEND),t=n.w,c=n.h;if(Z!==`${t}x${c}`){for(const H of Y)e.deleteTexture(H.tex),e.deleteFramebuffer(H.fb);Y=Array.from({length:7},()=>B(t,c)),Z=`${t}x${c}`}e.disable(e.BLEND),e.bindFramebuffer(e.FRAMEBUFFER,Y[0].fb),e.viewport(0,0,t,c),e.clearColor(0,0,0,0),e.clear(e.COLOR_BUFFER_BIT),vt(n,[0,1,1,-1],[0,0,1,1],1,1,!1,s,"base");let u=0;const h=H=>[H[0],H[3],H[6],H[1],H[4],H[7],H[2],H[5],H[8]],i=(H,G,ht,et)=>{e.bindFramebuffer(e.FRAMEBUFFER,Y[G].fb),e.viewport(0,0,t,c),e.useProgram(H);const Be=$e(H);ht.forEach((Et,bt)=>{e.activeTexture(e.TEXTURE0+bt),e.bindTexture(Et.d3?e.TEXTURE_3D:e.TEXTURE_2D,Et.t)}),et(Be),e.drawArrays(e.TRIANGLE_STRIP,0,4),At()},v=H=>({t:Y[H].tex}),M=(H,G,ht,et)=>{i(_,G,[v(H)],Be=>{e.uniform1i(Be("tex"),0),e.uniform2f(Be("step"),1/t,0),e.uniform1f(Be("sigma"),et)}),i(_,ht,[v(G)],Be=>{e.uniform1i(Be("tex"),0),e.uniform2f(Be("step"),0,1/c),e.uniform1f(Be("sigma"),et)})},Q=o.list,K=Q.map(H=>eo(H)),V=Ir(Q),be=new Set;for(const[H,G]of Q.entries()){const ht=V[H];if(H===ht&&Q.some((b,D)=>D>H&&V[D]===H&&K[D])&&(i($,2,[v(u)],b=>e.uniform1i(b("tex"),0)),be.add(H)),!K[H])continue;const et=H!==ht&&be.has(ht)?G.branch:void 0,Be=et?2:u;let Et=se,bt=[1,1];if(G.qualifier){const b=Math.max(2,Math.trunc((t+Mt-1)/Mt)),D=Math.max(2,Math.trunc((c+Mt-1)/Mt)),L=`${b}x${D}`;let ie=a.get(L);ie||(ie=B(b,D),a.set(L,ie));const ee=G.qualifier,de=Math.max(.001,ee.soft??.3),Se=G.window,Tt=-(Se?.rot??0)*Math.PI/180;e.bindFramebuffer(e.FRAMEBUFFER,ie.fb),e.viewport(0,0,b,D),e.useProgram(y),e.activeTexture(e.TEXTURE0),e.bindTexture(e.TEXTURE_2D,Y[Be].tex);const ge=$e(y);e.uniform1i(ge("tex"),0),e.uniform2f(ge("big"),t,c),e.uniform2f(ge("small"),b,D),e.uniform4f(ge("q1"),ee.hue,ee.hueWidth,Math.max(1,de*60),Math.max(.001,de*.2)),e.uniform4f(ge("q2"),ee.satMin,ee.satMax,ee.lumMin,ee.lumMax),e.uniform1f(ge("useQ"),1),e.uniform1f(ge("useW"),Se?1:0),Se&&(e.uniform4f(ge("w1"),Se.cx,Se.cy,Math.max(1e-4,Se.w/2),Math.max(.001,Se.feather??.2)),e.uniform4f(ge("w2"),Math.cos(Tt),Math.sin(Tt),Math.max(1e-4,Se.h/2),Se.type==="gradient"?2:Se.type==="rect"?1:0)),e.uniform1f(ge("inv"),G.invert?1:0),e.drawArrays(e.TRIANGLE_STRIP,0,4),Et=ie.tex,bt=[b*Mt,D*Mt]}else if(!G.whole&&Cr(G)&&G.window?.type!=="person"){const b=`${o.clip}#${H}`,D=`${t}x${c}@${o.local??0}`,L=go,ie=Math.max(2,Math.min(go*2,Math.round(L*c/t)));let ee=ve.get(b);if(ee||(ee={tex:pe(),at:""},ve.set(b,ee)),ee.at!==D){const de=bo(G,o.src,o.local??0,c/t,null),Se=new Uint8Array(L*ie);for(let Tt=0;Tt<ie;Tt++)for(let ge=0;ge<L;ge++)Se[Tt*L+ge]=Math.round(de((ge+.5)/L,(Tt+.5)/ie,0,0,0)*255);e.bindTexture(e.TEXTURE_2D,ee.tex),e.pixelStorei(e.UNPACK_ALIGNMENT,1),e.texImage2D(e.TEXTURE_2D,0,e.R8,L,ie,0,e.RED,e.UNSIGNED_BYTE,Se),e.pixelStorei(e.UNPACK_ALIGNMENT,4),ee.at=D}Et=ee.tex,bt=[t,c]}else if(!G.whole){const b=To(G)?o.src?.depthMap:void 0,D=`${o.clip}#${H}@${t}x${c}${b?`@${b.at}:${b.data.length}:${b.data.slice(0,24)}`:""}`;let L=S.get(D);if(!L){const ie=Xr(G,t,c,To(G)?bo(G,o.src,0,c/t):null);L=pe(),e.pixelStorei(e.UNPACK_ALIGNMENT,1),e.texImage2D(e.TEXTURE_2D,0,e.R8,ie.w4,ie.h4,0,e.RED,e.UNSIGNED_BYTE,ie.px),e.pixelStorei(e.UNPACK_ALIGNMENT,4),S.set(D,L)}Et=L,bt=[t,c]}const kt=G.adjust??{},no=Or(G),Wt=`${o.clip}#${H}`;let Gt=fe.get(Wt);if(no&&!Gt){const b=new Float32Array(1024);for(let D=0;D<256;D++)["r","g","b"].forEach((L,ie)=>{b[D*4+ie]=+zr(kt,L,D/255,G.wheels,G.curves).toFixed(6)}),b[D*4+3]=1;Gt=pe(),e.texImage2D(e.TEXTURE_2D,0,e.RGBA32F,256,1,0,e.RGBA,e.FLOAT,b);for(const D of[e.TEXTURE_MIN_FILTER,e.TEXTURE_MAG_FILTER])e.texParameteri(e.TEXTURE_2D,D,e.NEAREST);fe.set(Wt,Gt)}let gt=null;if(Gr(G)){const b=`${Wt}:${JSON.stringify([G.cst,G.look,G.lut,G.mixer])}`;if(gt=ne.get(b)??null,!gt){const D=qr(G,L=>xi(L));if(!D)throw Error(`LUT "${G.lut?.name??""}" chưa tải xong`);gt=e.createTexture(),e.activeTexture(e.TEXTURE4),e.bindTexture(e.TEXTURE_3D,gt),e.pixelStorei(e.UNPACK_ALIGNMENT,1),e.texImage3D(e.TEXTURE_3D,0,e.RGB32F,D.size,D.size,D.size,0,e.RGB,e.FLOAT,D.data),e.pixelStorei(e.UNPACK_ALIGNMENT,4);for(const L of[e.TEXTURE_MIN_FILTER,e.TEXTURE_MAG_FILTER])e.texParameteri(e.TEXTURE_3D,L,e.NEAREST);for(const L of[e.TEXTURE_WRAP_S,e.TEXTURE_WRAP_T,e.TEXTURE_WRAP_R])e.texParameteri(e.TEXTURE_3D,L,e.CLAMP_TO_EDGE);e.activeTexture(e.TEXTURE0),ne.set(b,gt)}}const{sat:No,rot:Lo}=$r(kt.saturation??1,kt.hue??0);i(oe,3,[v(Be),{t:Gt??at},{t:gt??pt,d3:!0}],b=>{e.uniform1i(b("tex"),0),e.uniform1i(b("lut"),1),e.uniform1i(b("t3"),2),e.uniform1f(b("useT"),gt?1:0),e.uniform1f(b("useL"),no?1:0),e.uniform1f(b("useS"),(kt.saturation??1)!==1?1:0),e.uniform1f(b("useR"),(kt.hue??0)!==0?1:0),e.uniformMatrix3fv(b("sat"),!1,h(No)),e.uniformMatrix3fv(b("rot"),!1,h(Lo))}),e.activeTexture(e.TEXTURE2),e.bindTexture(e.TEXTURE_3D,null),e.activeTexture(e.TEXTURE0),At();let le=3;const tt=(b,D)=>[3,4,5].find(L=>L!==b&&L!==D);if((G.blur??0)>0){const b=tt(le),D=tt(le,b);M(le,b,D,Math.max(.1,+((G.blur??0)*jr*t).toFixed(3))),le=D}const so=Hr({sharpness:G.sharpen??0});if(so){const b=tt(le);i(_e,b,[v(le)],D=>{e.uniform1i(D("tex"),0),e.uniform1fv(D("k"),so),e.uniform1f(D("rdiv"),1/Zr)}),le=b}const he=G.fx?Vr(G.fx,t):null;if(he&&(he.type==="glow"||he.type==="halation")){const b=tt(le),D=tt(le,b);i(I,b,[v(le)],de=>{e.uniform1i(de("tex"),0),e.uniform1f(de("lo"),he.lo),e.uniform1f(de("k"),he.k)});let L=b;he.tint&&(i(Ge,D,[v(b),{t:at}],de=>{e.uniform1i(de("tex"),0),e.uniform1i(de("lut"),1),e.uniform1f(de("useM"),1),e.uniform1f(de("useL"),0),e.uniform1fv(de("m"),he.tint.flat())}),L=D),M(L,L===b?D:b,L,he.sigma);const ee=6;i(X,ee,[v(le),v(L)],de=>{e.uniform1i(de("a"),0),e.uniform1i(de("b"),1),e.uniform1f(de("amount"),he.amount)}),i($,3,[v(ee)],de=>e.uniform1i(de("tex"),0)),le=3}else if(he?.type==="grain"){const b=Yr(o.frame??0),D=`${b}:${t}x${c}:${he.amp}`;let L=Re.get(D);if(!L){if(Re.size>8){for(const ee of Re.values())e.deleteTexture(ee);Re.clear()}L=pe(),e.pixelStorei(e.UNPACK_ALIGNMENT,1),e.texImage2D(e.TEXTURE_2D,0,e.R8,t,c,0,e.RED,e.UNSIGNED_BYTE,Kr(b,t,c,he.amp)),e.pixelStorei(e.UNPACK_ALIGNMENT,4),Re.set(D,L)}const ie=tt(le);i(Te,ie,[v(le),{t:L}],ee=>{e.uniform1i(ee("tex"),0),e.uniform1i(ee("grain"),1)}),le=ie}else if(he?.type==="denoise"){const b=tt(le),D=tt(le,b);M(le,b,D,he.sigma),i(Oe,6,[v(le),v(D)],L=>{e.uniform1i(L("tex"),0),e.uniform1i(L("soft"),1),e.uniform1f(L("t"),he.t)}),i($,3,[v(6)],L=>e.uniform1i(L("tex"),0)),le=3}else if(he?.type==="swirl"){const b=D=>Math.max(2,Math.round(D/2)*2);for(const D of Wr(t,c,he.deg)){const L=tt(le);i(De,L,[v(le)],ie=>{e.uniform1i(ie("tex"),0),e.uniform2f(ie("size"),t,c),e.uniform1fv(ie("a"),D.map(ee=>+ee.a.toFixed(6))),e.uniform1fv(ie("sx"),D.map(ee=>b(t*ee.scale)/t)),e.uniform1fv(ie("sy"),D.map(ee=>b(c*ee.scale)/c))}),le=L}}const Io=et==="parallel"?2:u,Co=et==="parallel"?6:1-u;i(O,Co,[v(Io),v(le),{t:Et}],b=>{e.uniform1i(b("base"),0),e.uniform1i(b("over"),1),e.uniform1i(b("mask"),2),e.uniform2f(b("msz"),bt[0],bt[1]),e.uniform1f(b("full"),G.whole?1:0)}),et==="parallel"&&i(we,1-u,[v(u),v(6),v(2)],b=>{e.uniform1i(b("res"),0),e.uniform1i(b("outp"),1),e.uniform1i(b("inp"),2)}),u=1-u}ce=Y[u].tex,e.bindFramebuffer(e.FRAMEBUFFER,l),e.viewport(R[0],R[1],R[2],R[3]),m&&e.enable(e.BLEND)},Ut=(n,s)=>C?(P!==C.key&&(Pe(n,s,C),P=C.key),"win"):"pic",xt=(n,s,o,l,R,m,t)=>{if(!ct){const M=Ut(n,t);vt(n,s,o,l,R,m,M==="win"?null:t,M);return}const c=je??[0,0,1,1];r!==ct.key&&(T(n,c,t,ct),r=ct.key);const u=(o[0]-c[0])/c[2],h=(o[1]-c[1])/c[3],i=o[2]/c[2],v=o[3]/c[3];vt(n,s,[u,1-h,i,-v],l,R,m,null,"edge")},vt=(n,s,o,l,R,m,t,c)=>{const u=c==="edge"||c==="win",h=c==="pic"||c==="base";if(e.useProgram(N),e.activeTexture(e.TEXTURE0),e.bindTexture(e.TEXTURE_2D,mt),h&&e.texImage2D(e.TEXTURE_2D,0,e.RGBA,e.RGBA,e.UNSIGNED_BYTE,n.source),e.uniform4f(F("dst"),s[0],s[1],s[2],s[3]),e.uniform4f(F("src"),o[0],o[1],o[2],o[3]),e.uniform1f(F("alpha"),l),e.uniform1f(F("fade"),R),e.uniform1f(F("white"),m?1:0),e.uniform1f(F("colour"),t?1:0),e.uniform1i(F("tex"),0),e.uniform1i(F("matte"),1),e.uniform1f(F("useMatte"),je&&(c==="pic"||c==="win")?1:0),Ue&&!u?(e.uniform4f(F("key"),Ue.u,Ue.v,Ue.similarity,Ue.blend),e.uniform4f(F("keyOpt"),1,Ue.blue?1:0,Ue.spill,n.bt709?1:0)):e.uniform4f(F("keyOpt"),0,0,0,0),e.uniform1i(F("lut1"),2),e.uniform1i(F("lut3"),3),e.uniform1f(F("useL1"),yt&&!u?1:0),e.uniform1f(F("useL3"),Xt&&!u?1:0),je&&e.uniform4f(F("mrect"),je[0],je[1],je[2],je[3]),e.activeTexture(e.TEXTURE1),e.bindTexture(e.TEXTURE_2D,wt),e.activeTexture(e.TEXTURE2),e.bindTexture(e.TEXTURE_2D,at),e.activeTexture(e.TEXTURE3),e.bindTexture(e.TEXTURE_3D,pt),e.activeTexture(e.TEXTURE0),e.bindTexture(e.TEXTURE_2D,c==="edge"?f[1].tex:c==="win"?ce:mt),t){const i=v=>[v[0],v[3],v[6],v[1],v[4],v[7],v[2],v[5],v[8]];e.uniform1f(F("bright"),t.bright),e.uniform1f(F("contrast"),t.contrast),e.uniformMatrix3fv(F("sat"),!1,i(t.sat)),e.uniformMatrix3fv(F("rot"),!1,i(t.rot))}e.drawArrays(e.TRIANGLE_STRIP,0,4)};return{canvas:w,clear(n=1){ue(null),e.clearColor(0,0,0,n),e.clear(e.COLOR_BUFFER_BIT)},pixels(){ue(null);const n=new Uint8ClampedArray(p*g*4),s=p*4,o=new Uint8ClampedArray(p*g*4);e.readPixels(0,0,p,g,e.RGBA,e.UNSIGNED_BYTE,n);for(let l=0;l<g;l++){const R=(g-1-l)*s,m=l*s;for(let t=0;t<s;t+=4){const c=n[R+t+3];if(o[m+t+3]=c,c){const u=255/c;o[m+t]=n[R+t]*u,o[m+t+1]=n[R+t+1]*u,o[m+t+2]=n[R+t+2]*u}}}return o},draw(n,s,o,l,R,m,t=null,c=[],u=null){if(!c.length&&!Ce&&!U.length&&!He){ue(null),e.enable(e.BLEND),e.blendFuncSeparate(e.SRC_ALPHA,e.ONE_MINUS_SRC_ALPHA,e.ONE,e.ONE_MINUS_SRC_ALPHA),xt(n,s,o,l,R,m,t);return}ke??=[Me(),Me(),Me()],ue(ke[0].fb),e.disable(e.BLEND),e.clearColor(0,0,0,0),e.clear(e.COLOR_BUFFER_BIT),xt(n,u??s,o,l,R,m,t);const h=dt(c);if(ue(null),e.enable(e.BLEND),e.blendFuncSeparate(e.SRC_ALPHA,e.ONE_MINUS_SRC_ALPHA,e.ONE,e.ONE_MINUS_SRC_ALPHA),Ce||U.length||He){let i=h;u&&(i=(h+1)%3,ue(ke[i].fb),e.disable(e.BLEND),e.clearColor(0,0,0,0),e.clear(e.COLOR_BUFFER_BIT),e.useProgram(N),e.activeTexture(e.TEXTURE0),e.bindTexture(e.TEXTURE_2D,ke[h].tex),e.uniform4f(F("dst"),s[0],s[1],s[2],s[3]),e.uniform4f(F("src"),0,1,1,-1),e.uniform1f(F("alpha"),1),e.uniform1f(F("fade"),1),e.uniform1f(F("white"),0),e.uniform1f(F("colour"),0),e.uniform1f(F("useMatte"),0),e.drawArrays(e.TRIANGLE_STRIP,0,4)),Qe(i);return}if(!u){j($,null,[ke[h].tex],i=>e.uniform1i(i("tex"),0));return}e.useProgram(N),e.activeTexture(e.TEXTURE0),e.bindTexture(e.TEXTURE_2D,ke[h].tex),e.uniform4f(F("dst"),s[0],s[1],s[2],s[3]),e.uniform4f(F("src"),0,1,1,-1),e.uniform1f(F("alpha"),1),e.uniform1f(F("fade"),1),e.uniform1f(F("white"),0),e.uniform1f(F("colour"),0),e.uniform1f(F("useMatte"),0),e.drawArrays(e.TRIANGLE_STRIP,0,4)},warp(n,s,o,l,R,m,t,c,u,h=null,i=null,v=[]){const M=Ve();ue(M[0].fb),e.disable(e.BLEND),e.clearColor(0,0,0,0),e.clear(e.COLOR_BUFFER_BIT),xt(n,s,o,l,R,m,t);const Q=dt(c),K=Ce||U.length||He||v.length?(Q+1)%3:-1;K>=0?(ue(M[K].fb),e.disable(e.BLEND),e.clearColor(0,0,0,0),e.clear(e.COLOR_BUFFER_BIT)):(ue(null),e.enable(e.BLEND),e.blendFuncSeparate(e.SRC_ALPHA,e.ONE_MINUS_SRC_ALPHA,e.ONE,e.ONE_MINUS_SRC_ALPHA)),i&&(e.enable(e.SCISSOR_TEST),e.scissor(i[0],g-i[1]-i[3],i[2],i[3])),j(Ke,K>=0?M[K].fb:null,[M[Q].tex],V=>{e.uniform1i(V("tex"),0),e.uniform2f(V("size"),p,g),e.uniform1f(V("keepPre"),0),e.uniformMatrix3fv(V("inv"),!1,[u[0],u[3],u[6],u[1],u[4],u[7],u[2],u[5],u[8]]),e.uniform4f(V("rnd"),h?.[0]??0,h?.[1]??0,h?.[2]??0,h?1:0)}),e.disable(e.SCISSOR_TEST),K>=0&&Qe(v.length?dt(v,K):K)},adjust(n,s,o){const l=Ve();if(ue(null),e.bindTexture(e.TEXTURE_2D,Rt),e.copyTexImage2D(e.TEXTURE_2D,0,e.RGBA8,0,0,p,g,0),ue(l[0].fb),e.disable(e.BLEND),e.useProgram(N),e.activeTexture(e.TEXTURE0),e.bindTexture(e.TEXTURE_2D,Rt),e.uniform4f(F("dst"),0,0,1,1),e.uniform4f(F("src"),0,1,1,-1),e.uniform1i(F("tex"),0),e.uniform1f(F("alpha"),1),e.uniform1f(F("fade"),1),e.uniform1f(F("white"),0),e.uniform1f(F("useMatte"),0),e.uniform1f(F("colour"),n?1:0),n){const m=t=>[t[0],t[3],t[6],t[1],t[4],t[7],t[2],t[5],t[8]];e.uniform1f(F("bright"),n.bright),e.uniform1f(F("contrast"),n.contrast),e.uniformMatrix3fv(F("sat"),!1,m(n.sat)),e.uniformMatrix3fv(F("rot"),!1,m(n.rot))}e.drawArrays(e.TRIANGLE_STRIP,0,4);const R=dt(s);ue(null),e.enable(e.BLEND),e.blendFuncSeparate(e.SRC_ALPHA,e.ONE_MINUS_SRC_ALPHA,e.ONE,e.ONE_MINUS_SRC_ALPHA),e.useProgram(N),e.activeTexture(e.TEXTURE0),e.bindTexture(e.TEXTURE_2D,l[R].tex),e.uniform4f(F("dst"),0,0,1,1),e.uniform4f(F("src"),0,1,1,-1),e.uniform1f(F("alpha"),o),e.uniform1f(F("fade"),1),e.uniform1f(F("white"),0),e.uniform1f(F("colour"),0),e.uniform1f(F("useMatte"),0),e.drawArrays(e.TRIANGLE_STRIP,0,4)},grade(n,s){if(yt=!!n,Xt=!!s,n&&Ie.l1!==n.key){const o=new Float32Array(1024);for(let l=0;l<256;l++)o[l*4]=n.r[l],o[l*4+1]=n.g[l],o[l*4+2]=n.b[l],o[l*4+3]=1;e.activeTexture(e.TEXTURE2),e.bindTexture(e.TEXTURE_2D,at),e.texImage2D(e.TEXTURE_2D,0,e.RGBA32F,256,1,0,e.RGBA,e.FLOAT,o);for(const l of[e.TEXTURE_MIN_FILTER,e.TEXTURE_MAG_FILTER])e.texParameteri(e.TEXTURE_2D,l,e.NEAREST);e.activeTexture(e.TEXTURE0),Ie.l1=n.key}if(s&&Ie.l3!==s.key){e.activeTexture(e.TEXTURE3),e.bindTexture(e.TEXTURE_3D,pt),e.pixelStorei(e.UNPACK_ALIGNMENT,1),e.texImage3D(e.TEXTURE_3D,0,e.RGB32F,s.size,s.size,s.size,0,e.RGB,e.FLOAT,s.data),e.pixelStorei(e.UNPACK_ALIGNMENT,4);for(const o of[e.TEXTURE_MIN_FILTER,e.TEXTURE_MAG_FILTER])e.texParameteri(e.TEXTURE_3D,o,e.NEAREST);for(const o of[e.TEXTURE_WRAP_S,e.TEXTURE_WRAP_T,e.TEXTURE_WRAP_R])e.texParameteri(e.TEXTURE_3D,o,e.CLAMP_TO_EDGE);e.activeTexture(e.TEXTURE0),Ie.l3=s.key}},key(n){if(!n){Ue=null;return}const[s,o,l]=[1,3,5].map(m=>parseInt(n.color.slice(m,m+2),16)),R=224/255;Ue={u:Math.round(-.168736*R*s-.331264*R*o+.5*R*l+128),v:Math.round(.5*R*s-.418688*R*o-.081312*R*l+128),similarity:n.similarity,blend:n.blend,spill:+n.spill.toFixed(3),blue:l>o}},mode(n){Ce=n&&Yt[n]||0},shadow(n){U=n},blurBegin(){nt??=Me(),ue(nt.fb),e.clearColor(0,0,0,0),e.clear(e.COLOR_BUFFER_BIT),He=!0},blurEnd(){He=!1;const n=Ve();e.disable(e.BLEND),j(d,n[0].fb,[nt.tex],s=>e.uniform1i(s("tex"),0)),Qe(0)},windows(n){C=n},edge(n){ct=n},warpBig(n,s,o,l,R,m,t,c,u,h=[]){const i=_t(u),v=p*u,M=g*u;e.bindFramebuffer(e.FRAMEBUFFER,i.plane.fb),e.viewport(0,0,v,M),e.disable(e.BLEND),e.clearColor(0,0,0,0),e.clear(e.COLOR_BUFFER_BIT),xt(n,s,o,l,R,m,t);const Q=It(c.map(([be,H])=>[be*u,H*u]),v,M);e.bindFramebuffer(e.FRAMEBUFFER,i.out.fb),e.viewport(0,0,v,M),e.useProgram(Ke),e.activeTexture(e.TEXTURE0),e.bindTexture(e.TEXTURE_2D,i.plane.tex);const K=$e(Ke);if(e.uniform1i(K("tex"),0),e.uniform2f(K("size"),v,M),e.uniform1f(K("keepPre"),1),e.uniform4f(K("rnd"),0,0,0,0),e.uniformMatrix3fv(K("inv"),!1,[Q[0],Q[3],Q[6],Q[1],Q[4],Q[7],Q[2],Q[5],Q[8]]),e.drawArrays(e.TRIANGLE_STRIP,0,4),ue(null),e.enable(e.BLEND),e.blendFuncSeparate(e.SRC_ALPHA,e.ONE_MINUS_SRC_ALPHA,e.ONE,e.ONE_MINUS_SRC_ALPHA),!h.length&&!Ce&&!U.length&&!He){j(J,null,[i.out.tex],be=>{e.uniform1i(be("tex"),0),e.uniform1i(be("ss"),u)});return}const V=Ve();e.disable(e.BLEND),j(J,V[0].fb,[i.out.tex],be=>{e.uniform1i(be("tex"),0),e.uniform1i(be("ss"),u)}),Qe(dt(h,0))},matte(n,s=[0,0,1,1]){je=n?s:null,n&&(e.activeTexture(e.TEXTURE1),e.bindTexture(e.TEXTURE_2D,wt),e.texImage2D(e.TEXTURE_2D,0,e.RGBA,e.RGBA,e.UNSIGNED_BYTE,n),e.activeTexture(e.TEXTURE0))},overlay(n,s){ue(null),e.enable(e.BLEND),e.blendFuncSeparate(e.SRC_ALPHA,e.ONE_MINUS_SRC_ALPHA,e.ONE,e.ONE_MINUS_SRC_ALPHA),s&&(e.activeTexture(e.TEXTURE0),e.bindTexture(e.TEXTURE_2D,mt),e.texImage2D(e.TEXTURE_2D,0,e.RGBA,s.w,s.h,0,e.RGBA,e.UNSIGNED_BYTE,s.data)),j(lt,null,s?[mt]:[],o=>{e.uniform1i(o("tex"),0),e.uniform1f(o("usetex"),s?1:0),e.uniform4f(o("colour"),...n??[0,0,0,0])})},finish(){e.finish()}}}let Ne="";const La=()=>Ne;async function ga(p,{format:g,encode:w=null,tracks:e={},camera:z=null,signal:E,onProgress:N,frames:A,software:W=!1,liveMotion:re=!1,range:ae,only:me,sink:xe}){const d=performance.now(),{width:y,height:_,fps:I}=oo(g);Ne="layers",await Promise.all([...new Set(p.filter(r=>!r.colorBypass).flatMap(r=>qt(r.grade).map(f=>f?.lut?.id)).filter(r=>!!r))].map(r=>li(r))),Xo(co(p.filter(r=>!r.disabled)));const X=p.filter(r=>!r.disabled&&!Mo(r)),$=co(X),te=Oo(X.reduce((r,f)=>Math.max(r,f.start+f.duration),0)),oe=Math.round(te*I);if(!(oe>0)&&!A)throw Error("Empty timeline");const O=zo(z)?z:null,_e=Go($,e,O?r=>Nr(r,O,y,_):void 0),Te=r=>_e.find(f=>r>=f.start-1e-6&&r<f.start+f.duration-1e-6)??null,Oe=()=>{if(E?.aborted)throw new DOMException("Export cancelled","AbortError")},we=r=>re&&!A&&!!r.motion&&!r._virtual&&!r.warped,Ye=r=>A||me!=="audio"&&(!ae||r.start<ae.to/I+1e-6&&r.start+r.duration>ae.from/I-1e-6),ze=new Pi,ft=[...X.filter(r=>Ht(r)&&!we(r)),...qo(X)].filter(Ye);ft.length&&await(await Pt(async()=>{const{renderTitleFrames:r}=await import("./titleFrames-BVgm601q.js");return{renderTitleFrames:r}},__vite__mapDeps([0,1,2,3,4,5,6,7]))).renderTitleFrames(ft,g,ze,E);const Fe=new Map;if(X.some(r=>we(r)&&Ye(r))){const r=await Pt(()=>import("./titleFrames-BVgm601q.js"),__vite__mapDeps([0,1,2,3,4,5,6,7]));for(const f of X.filter(k=>we(k)&&Ye(k)))Fe.set(f.id,r.liveMotion(f,X,g))}X.some(r=>r.kind==="model")&&await(await Pt(async()=>{const{render3DFrames:r}=await import("./timeline3dExport-T57qnWi9.js");return{render3DFrames:r}},__vite__mapDeps([8,1,9,10,11,6,12,7]))).render3DFrames(p.filter(r=>!r.disabled),g,ze,E,z);for(const r of $.filter(f=>f._group&&f.comp)){const f=[],k=Math.max(1,Math.ceil(r.duration*I-1e-6));await ga(ri(ii(r),{W:y,H:_}),{format:g,signal:E,frames:{times:Array.from({length:k},(x,T)=>oi(r,T/I)),push:(x,T)=>{f[x]=T}}}),ze.frames.set(r.id,f)}const lt=performance.now();Oe(),Ne="mattes";const Ke=X.filter(r=>r.mask||r.person),ye=Ke.length?await Pt(()=>import("./rotoMatte-BdYa8FSB.js").then(r=>r.r),__vite__mapDeps([13,1,6,14])):null;ye&&await ye.prepareMattes(Ke);const Ge=ye?document.createElement("canvas"):null;Ne="media";const We=new Map,Ae=new Map,Le=new Map,rt=r=>{let f=We.get(r);return f||(f=new gi({source:new wi(r,{getRetryDelay:Po}),formats:Ti}),We.set(r,f)),f};for(const r of X){if(r.kind==="video"&&!Ae.has(r.url)){const f=await rt(r.url).getPrimaryVideoTrack();f&&Ae.set(r.url,new Ei(f))}if(r.kind==="image"&&!Ht(r)&&!Zt(r)&&!r._group&&!Le.has(r.url)){const f=await createImageBitmap(await ki(r.url,E),{imageOrientation:"from-image",premultiplyAlpha:"none",colorSpaceConversion:"none"});Le.set(r.url,{source:f,w:f.width,h:f.height,close:()=>f.close()})}}const J=new Map,Ee=async(r,f)=>{const k=Fe.get(r.id);if(k)return{source:await k.frame(Math.round((f-r.start)*I)),w:k.W,h:k.H};const x=ze.frames.get(r.id);if(!x?.length)return null;let T=x.length===1?0:Math.max(0,Math.min(Math.round((f-r.start)*I),Math.ceil(r.duration*I)-1,x.length-1));for(;T>0&&x[T]==="=";)T--;const C=J.get(r.id);if(C&&C.index===T)return C.pic;C?.pic?.close?.();const P=await createImageBitmap(await(await fetch(`data:image/webp;base64,${x[T]}`)).blob(),{premultiplyAlpha:"none",colorSpaceConversion:"none"}),ce={source:P,w:P.width,h:P.height,close:()=>P.close()};return J.set(r.id,{index:T,pic:ce}),ce},ut=X.filter(r=>$o(r)),qe=ut.length?await Pt(()=>import("./captionLayout-EuB59pN_.js"),__vite__mapDeps([15,1])):null,De=new Map,it=new Map;if(qe){for(const r of new Set(ut.flatMap(f=>[Qt(jo(f.captionStyle).font),Qt(fo(f.captionStyle).font)])))if(await qe.captionFontReady(r.id),!De.has(r.id)){const f=new Uint8Array(await(await fetch(`/fonts/${r.file}`,{signal:E})).arrayBuffer());let k="";for(let x=0;x<f.length;x+=32768)k+=String.fromCharCode(...f.subarray(x,x+32768));De.set(r.id,`@font-face{font-family:'${r.family}';src:url(data:font/${r.file.endsWith(".otf")?"otf":"ttf"};base64,${btoa(k)})}`)}}const $e=new Map,F=async(r,f,k)=>{let x=$e.get(f.start);if(!x||x.owner!==r){const S=fr(r,f.start,f.duration);x={plan:S,starts:lr(S.entries,I),owner:r},$e.clear(),$e.set(f.start,x)}const T=k-Math.round(f.start*I);let C=-1;for(let S=0;S<x.starts.length&&x.starts[S]<=T;S++)C=S;const P=x.plan.entries[C];if(!P||P.blank)return null;const ce=x.plan.social?x.plan.social.style:fo(r.captionStyle),Y=x.plan.social?ur(x.plan.social,P.gi,y,_,qe.measureCaption):mr({width:y,height:_,text:P.text,style:ce,measure:qe.measureCaption,second:P.second}),Z=pr(Y,ce,x.plan.social?P.scale:1,y,_,P.active,P.motion);let a=it.get(Z);if(!a){const S=Qt(ce.font),fe=URL.createObjectURL(new Blob([Z.replace("<defs>",`<defs><style>${De.get(S.id)??""}</style>`)],{type:"image/svg+xml"}));try{const ve=new Image(y,_);ve.src=fe,await ve.decode();const ne=await createImageBitmap(ve,{premultiplyAlpha:"none"});a={source:ne,w:y,h:_,close:()=>ne.close()}}finally{URL.revokeObjectURL(fe)}if(it.size>64){const[ve,ne]=it.entries().next().value;ne.close?.(),it.delete(ve)}it.set(Z,a)}return a},pe=[0,0,1,1],mt=new Map,wt=["x","y","zoom","rot","sx","sy"],je=(r,f,k,x)=>{const T=`${r.id}@${f.start}`;let C=mt.get(T);if(!C){const ce=Math.max(1,Math.ceil(f.duration/.1-1e-6)),Y=Array.from({length:ce+1},(S,fe)=>f.start+f.duration*fe/ce),Z=Y.map(S=>Jt(r,S-r.start,y,_)),a=S=>+(+S).toFixed(3);C={ts:Y.map(S=>+S.toFixed(5)),v:Object.fromEntries(wt.map(S=>[S,Z.map(fe=>a(fe[S]??(S==="sx"||S==="sy"?1:0)))]))},mt.set(T,C)}const P={...x};for(const ce of wt){const Y=C.v[ce];if(Y.every(fe=>fe===Y[0])){P[ce]=Y[0];continue}let Z=C.ts.findIndex((fe,ve)=>ve<C.ts.length-1&&k<C.ts[ve+1]);Z<0&&(Z=C.ts.length-2);const a=+(Y[Z+1]-Y[Z]).toFixed(3),S=C.ts[Z+1]-C.ts[Z];P[ce]=Math.abs(Y[Z+1]-Y[Z])<1e-4?Y[Z]:Y[Z]+a*Math.max(0,Math.min(1,(k-C.ts[Z])/S))}return P},at=new Map,pt=new Map,Ie=(r,f,k,x=r,T="")=>{if(!dr(x))return yo(x,y);const C=`${r.id}${T}@${f.start}`;let P=pt.get(C);P||(P=xr(x,{offset:f.start-r.start,duration:f.duration,fps:I}),pt.set(C,P));const ce=k-Math.round(f.start*I),Y=P.find(Z=>ce>=Z.from&&ce<Z.to)??P[P.length-1];return yo({effects:vr(x,Y.t)},y)},yt=new Map,Xt=(r,f,k)=>{const x=`${r.id}@${f.start}`;yt.has(x)||yt.set(x,O?Dr(r,O,f.start,f.duration,y,_):null);const T=yt.get(x);return T?Ie(r,f,k,T,":dof"):[]},Ue=new Map,Yt=r=>{const f=JSON.stringify(r.grade);let k=Ue.get(f);if(!k){const x=P=>Array.from(P,ce=>+ce.toFixed(6)),T=gr(r.grade)?Tr(r.grade):null,C=r.grade.mixer&&wr(r.grade.mixer)?yr(r.grade.mixer):null;k={l1:T?{key:`1${f}`,r:x(T.r),g:x(T.g),b:x(T.b)}:null,l3:C?{key:`3${f}`,size:C.size,data:Float32Array.from(C.data,P=>+P.toFixed(6))}:null},Ue.set(f,k)}return k};let Ce=null;const Rt=async(r,f,k)=>{const x=X.find(P=>P.id===r);if(!x||f<x.start||f>=x.start+x.duration)return null;if(Ht(x)){const P=await Ee(x,f);return P&&{source:P.source,w:P.w,h:P.h}}if(x.kind==="image"){const P=Le.get(x.url);return P?{source:P.source,w:P.w,h:P.h}:null}if(x.kind!=="video")return null;const T=await _o(Me,Ae,x,f,I,Math.max(k.start,x.start),k.duration);if(!T)return null;const C=T.toVideoFrame();return{source:C,w:T.displayWidth,h:T.displayHeight,close:()=>C.close()}};Ne="output";const U=ba(y,_),He=io(w,{width:y,height:_,fps:I},ro),nt=w?.codec==="hevc",St=w?.container==="mov",Qe=!A&&!xe&&te*He/8>15e7&&!!navigator.storage?.getDirectory;let Xe=null,ke;if(Qe){const r=await navigator.storage.getDirectory(),f=`gpu-export-${crypto.randomUUID()}.${St?"mov":"mp4"}`,k=await r.getFileHandle(f,{create:!0});Xe={dir:r,handle:k,name:f},ke=new Ro(await k.createWritable(),{chunked:!0,chunkSize:1<<20})}else ke=xe&&!A?new Ro(xe,{chunked:!0,chunkSize:1<<22}):new Ri;const Ve=xe&&!A?!1:Qe?"reserve":"in-memory",Je=new _i({format:St?new Fi({fastStart:Ve}):new Ai({fastStart:Ve}),target:ke}),_t=new Mi(U.canvas,{codec:nt?"hevc":"avc",bitrate:He,keyFrameInterval:2,...nt?{hardwareAcceleration:"prefer-hardware"}:W?{hardwareAcceleration:"prefer-software"}:{}}),Ze=me==="audio"?0:Math.max(0,Math.min(oe,ae?.from??0)),Ft=me==="audio"?0:Math.max(Ze,Math.min(oe,ae?.to??oe));me!=="audio"&&Je.addVideoTrack(_t,{frameRate:I,...Qe?{maximumPacketCount:Ft-Ze+8}:{}});const Dt=new Si({codec:"aac",bitrate:ko});me!=="video"&&Je.addAudioTrack(Dt,Qe?{maximumPacketCount:Math.ceil(te*Ct/1024)+16}:{}),A||await Je.start();const Ot=A?new OffscreenCanvas(y,_):null,zt=Ot?.getContext("2d"),Kt=async r=>{zt.putImageData(new ImageData(U.pixels(),y,_),0,0);const f=new Uint8Array(await(await Ot.convertToBlob({type:"image/webp",quality:.9})).arrayBuffer());let k="";for(let x=0;x<f.length;x+=32768)k+=String.fromCharCode(...f.subarray(x,x+32768));A.push(r,btoa(k))},Me=new Map;let ue=0;const j={decode:0,matte:0,titles:0,captions:0,encode:0},st=async(r,f)=>{const k=performance.now();try{return await f}finally{j[r]+=performance.now()-k}},At=(r,f)=>{const k=performance.now();try{return f()}finally{j[r]+=performance.now()-k}};try{for(let f=A?0:Ze,k=A?A.times.length:Ft;f<k;f++){Oe(),Ne="frame";const x=A?A.times[f]:f/I,T=Te(x);U.clear(A?0:1);const C=T&&qe?Ho(X,T.start+1e-5,e):void 0,P=C&&T?Vo(T.visuals,C.captionStyle?.layerTrack):-1,ce=async()=>{const Y=C&&T&&await st("captions",F(C,T,f));Y&&(U.shadow([]),U.edge(null),U.windows(null),U.matte(null),U.mode(void 0),U.key(null),U.grade(null,null),U.draw(Y,pe,pe,1,1,!1,null,[]))};for(const[Y,Z]of(T?.visuals??[]).entries()){let a=Z;if(Y===P&&await ce(),a.kind==="audio")continue;const S=T?lo(a,T.start,T.start+T.duration):null,fe=S?a._txIn===S?"b":"a":null,ve=S?Yo(S,x):0;e:{if(a.kind==="model"){U.matte(null),U.edge(null),U.windows(null),U.mode(void 0),U.shadow(uo(a,y)),U.key(null),U.grade(null,null);const m=await Ee(a,x);m&&U.draw(m,pe,pe,1,1,!1,null,[]);break e}const ne=x-a.start,Re=Jt(a,ne,y,_),se=(Ko(a)||Wo(a))&&!S&&!(O&&$t(a))&&!a.pin?je(a,T,x,Re):Re;if(!(se.opacity>1e-4))break e;if(Zt(a)){U.adjust(ot(a),Ie(a,T,f),Math.min(1,se.opacity));break e}let B=null,Pe=null;if(Ht(a)||a._group)B=await st("titles",Ee(a,x));else if(a.kind==="image")B=Le.get(a.url)??null;else if(a.kind==="video"){const m=await st("decode",_o(Me,Ae,a,x,I,T.start,T.duration));m&&(Pe=m.toVideoFrame(),B={source:Pe,w:m.displayWidth,h:m.displayHeight,bt709:Pe.colorSpace?.matrix?Pe.colorSpace.matrix==="bt709":m.displayHeight>=720})}if(!B)break e;if(Qo(a)){const m=a.crop||{left:0,right:0,top:0,bottom:0},t=Math.floor(B.w*m.left/2)*2,c=Math.floor(B.h*m.top/2)*2,u=Math.max(2,Math.floor(B.w*(1-m.left-m.right)/2)*2),h=Math.max(2,Math.floor(B.h*(1-m.top-m.bottom)/2)*2),i=a.distort.displace?await Rt(a.distort.displace.map,x,T):null;Ce??=hi();const v=Ce.render({source:B.source,srcW:B.w,srcH:B.h,rect:[t,c,u,h],outW:u,outH:h,distort:a.distort,local:ne,map:i?.source??null,matte:ye&&(a.mask||a.person)?ye.matteCanvas(a,ne,Ge,!1,X):null});i?.close?.(),B={source:v,w:u,h,bt709:B.bt709},a={...a,crop:void 0,mask:void 0,person:void 0}}if(ye&&(a.mask||a.person)){const m=a.crop||{left:0,right:0,top:0,bottom:0},t=Math.max(2,Math.floor(B.w*(1-m.left-m.right)/2)*2),c=Math.max(2,Math.floor(B.h*(1-m.top-m.bottom)/2)*2);U.matte(At("matte",()=>ye.matteCanvas(a,ne,Ge,!1,X)),[m.left,m.top,t/B.w,c/B.h])}else U.matte(null);U.mode(a.blend),U.key(a.key),U.shadow(uo(a,y));{const m=a.colorBypass?[]:qt(a.grade).filter(eo);U.windows(m.length?{key:`${a.id}@${f}`,list:qt(a.grade),clip:a.id,src:a,frame:Math.round((x-a.start)*I),local:Math.round((x-a.start)*I)/I}:null)}if(mo(a)&&po(xo(a),ne)>.001){const m=xo(a),t=ye&&(a.mask||a.person),c=a.crop||{left:0,right:0,top:0,bottom:0},u=t?Math.max(2,Math.floor(t.mw*(1-c.left-c.right)/2)*2):B.w,h=t?Math.max(2,Math.floor(t.mh*(1-c.top-c.bottom)/2)*2):B.h,i=u>=h?jt:Math.max(8,Math.trunc(jt*u/h/8)*8),v=u>=h?Math.max(8,Math.trunc(jt*h/u/8)*8):jt,M=Jo(m),Q=po(m,ne),K=!!m.keys?.length||m.amount<.999;U.edge({key:`${a.id}@${f}`,ew:i,eh:v,band:M.band,glow:M.glow,k:m.glow,col:[1,3,5].map(V=>parseInt(m.color.slice(V,V+2),16)/255),am:K?Math.trunc(255*Q):255,harden:!!t,arc:m.cover>=.999&&!m.comet?null:{cen:t?Zo(a):[.5,.5],start:(m.angle+m.sweep*ne)*Math.PI/180,cover:m.cover,comet:!!m.comet}})}else U.edge(null);{const m=a.grade&&!a.colorBypass?Yt(a):null;U.grade(m?.l1??null,m?.l3??null)}if(a.pin&&!(O&&$t(a))&&T&&vo(a,X,T.start,y,_,O)){const m=vo(a,X,x,y,_,O)??[[0,0],[0,0],[0,0],[0,0]],t=Bt(a,ne),c=er(a,X,y,_,O),u=a.pin.dive,h=c&&!a.pin.scene?[+(c[0]*y).toFixed(3),+(c[1]*_).toFixed(3),u?Math.max(0,Math.min(1,(x-u.at)/u.dur)):0]:null;U.warp(B,Nt([0,0,1,1],y,_),wo(a,B.w,B.h),Math.min(1,se.opacity),t.k,t.white,ot(a),Ie(a,T,f),It(m,y,_),h),Pe?.close();break e}const Ut=tr(a,"rot")||or(a),xt=()=>a.motionBlur?fi(x,I).map(m=>({...Jt(a,m-a.start,y,_),rot:se.rot,opacity:se.opacity})):[se];if((Ut||Math.abs(se.rot||0)>1e-9)&&!(O&&$t(a))){const m=Bt(a,ne),t=S&&fe?[...Ao(S.spec[fe],ve,y,_,x,S.spec.zoomAt),...fe==="b"&&S.spec.mask?[Fo(S.spec.mask,ve)]:[]]:[];a.motionBlur&&U.blurBegin();for(const c of xt()){const u=ai(a,B.w,B.h,y,_,c,Ut);U.warp(B,Nt([0,0,1,1],y,_),wo(a,B.w,B.h),Math.min(1,se.opacity),m.k,m.white,ot(a),[],It(u.quad,y,_),null,u.clip,t)}a.motionBlur&&U.blurEnd(),Pe?.close();break e}if(O&&$t(a)){const m=rr(a,ne,O,x,y,_);if(m){const t=Lt(a,B.w,B.h,y,_,{x:0,y:0,zoom:1}),c=Bt(a,ne),u=Ie(a,T,f);let h=at.get(a.id);h===void 0&&(h=a.effects?.some(v=>!v.off)||a.mask||a.person||mo(a)||!a.colorBypass&&qt(a.grade).some(eo)?1:ir(ar(a,O,y,_),B.w,B.h,y,_),at.set(a.id,h));const i=Xt(a,T,f);h>1&&!u.length?U.warpBig(B,Nt(t.dst,y,_),t.src,Math.min(1,se.opacity),c.k,c.white,ot(a),m.quad,h,i):U.warp(B,Nt(t.dst,y,_),t.src,Math.min(1,se.opacity),c.k,c.white,ot(a),u,It(m.quad,y,_),null,null,i)}Pe?.close();break e}if(a.motionBlur&&!S&&!Ie(a,T,f).length){const m=Bt(a,ne);U.blurBegin();for(const t of xt()){const c=Lt(a,B.w,B.h,y,_,t);U.draw(B,c.dst,c.src,Math.min(1,se.opacity),m.k,m.white,ot(a),[])}U.blurEnd(),Pe?.close();break e}const{dst:vt,src:n}=Lt(a,B.w,B.h,y,_,se),s=Bt(a,ne),o=[...Ie(a,T,f),...S&&fe?Ao(S.spec[fe],ve,y,_,x,S.spec.zoomAt):[],...S&&fe==="b"&&S.spec.mask?[Fo(S.spec.mask,ve)]:[]],l=S&&fe?S.spec[fe]?.rot:null;if(l){const m=Vt(l,ve)??0;U.warp(B,Nt([0,0,1,1],y,_),n,Math.min(1,se.opacity),s.k,s.white,ot(a),[],It(ni(vt,y,_,m),y,_),null,null,o),Pe?.close();break e}if(o.length>0&&!!T&&!a.layout&&!lo(a,T.start,T.start+T.duration)&&nr(a,T.start,T.start+T.duration,y,_)){const m=Lt(a,B.w,B.h,y,_,{x:0,y:0,zoom:1}),t=Lt({},y,_,y,_,se);U.draw(B,t.dst,m.src,Math.min(1,se.opacity),s.k,s.white,ot(a),o,m.dst)}else U.draw(B,vt,n,Math.min(1,se.opacity),s.k,s.white,ot(a),o);Pe?.close()}if(S&&fe==="b"){if(S.spec.light){const Re=Math.max(2,Math.ceil(y/ho)),se=Math.max(2,Math.ceil(_/ho));U.overlay(null,{data:sr(S.spec,ve,Re,se),w:Re,h:se})}const ne=S.spec.flash;if(ne){const Re=Vt(ne.opacity,ve)??0;if(Re>1e-4){const se=parseInt(ne.color.slice(1),16);U.overlay([(se>>16&255)/255,(se>>8&255)/255,(se&255)/255,Math.min(1,Re)],null)}}}}P>=0&&P>=(T?.visuals.length??0)&&await ce();for(const[Y,Z]of Me){const a=Y.split(`
194
- `)[0],S=$.find(fe=>fe.id===a);(!S||x>S.start+S.duration+1)&&(Z.current?.close(),Z.peek?.close(),await Z.iterator.return?.(),Me.delete(Y))}if(A){await Kt(f);continue}Ne="video encode",await st("encode",_t.add((f-Ze)/I,1/I)),N?.((me==="video"?1:.9)*(f+1-Ze)/Math.max(1,Ft-Ze))}if(A)return{blob:new Blob,ms:{titles:0,video:0,audio:0,total:Math.round(performance.now()-d)}};const r=performance.now();if(me==="video")_t.close(),Ne="finalize",await Je.finalize();else{Ne="audio";const f=new Map($.map(x=>[x.id,x])),k=await wa(X.map(x=>f.get(x.id)??x),_e,te,e,rt,E);typeof g.loudness=="number"&&si([k.getChannelData(0),k.getChannelData(1)],g.loudness,Ct),Ne="audio encode",await Dt.add(k),ue=performance.now()-r,me!=="audio"&&_t.close(),Dt.close(),Ne="finalize",await Je.finalize()}}catch(r){throw await Je.cancel().catch(()=>{}),Xe&&await Xe.dir.removeEntry(Xe.name).catch(()=>{}),r}finally{for(const r of Me.values())r.current?.close(),r.peek?.close();Ce?.dispose();for(const r of Le.values())r.close?.();for(const r of J.values())r.pic?.close?.();for(const r of Fe.values())r.close();for(const r of it.values())r.close?.();for(const r of We.values())r.dispose?.()}N?.(1),Ne="file";const dt=Xe?await Xe.handle.getFile():xe?new Blob([]):new Blob([ke.buffer],{type:St?"video/quicktime":"video/mp4"});Xe&&setTimeout(()=>void Xe.dir.removeEntry(Xe.name).catch(()=>{}),600*1e3);const ct=performance.now()-d;return{blob:dt,ms:{titles:Math.round(lt-d),video:Math.round(ct-(lt-d)-ue),audio:Math.round(ue),total:Math.round(ct),parts:Object.fromEntries(Object.entries(j).map(([r,f])=>[r,Math.round(f)]))}}}function Ta(p,g,w,e,z){const E=[new Float32Array(Math.max(1,Math.round(z*w))),new Float32Array(Math.max(1,Math.round(z*w)))],N=Math.round(Lr*w);return g.forEach((A,W)=>{if(A.silent)return;const re=Math.round((A.t1-A.t0)*w)+(W<g.length-1?N:0),ae=Math.abs(A.rate),me=Math.round(A.t0*w),xe=Math.max(0,Math.round(((A.rate>0?A.s0:A.s0-ae*re/w)-e)*w)),d=Math.min(p[0].length,Math.round(((A.rate>0?A.s0+ae*re/w:A.s0)-e)*w));if(d-xe<2)return;const y=(d-xe)/re,_=Math.round(.06*w),I=Math.max(0,xe-_),X=Math.min(p[0].length,d+_);let $=p.map(oe=>oe.slice(I,X));A.rate<0&&$.forEach(oe=>oe.reverse());const te=Math.round((A.rate<0?X-d:xe-I)/y);$=Uo($,y,w).map(oe=>oe.subarray(te,te+re));for(let oe=0;oe<2;oe++)for(let O=0;O<re&&me+O<E[oe].length;O++){const _e=(W>0&&O<N?O/N:1)*(W<g.length-1&&O>=re-N?(re-O)/N:1);E[oe][me+O]+=($[oe][O]??0)*_e}}),E}async function wa(p,g,w,e,z,E){const N=new OfflineAudioContext({numberOfChannels:2,length:Math.max(1,Math.round(w*Ct)),sampleRate:Ct}),A=1/200,W=p.filter(d=>(d.kind==="video"||d.kind==="audio")&&!d.freeze&&!Do(d)&&(d.volume??1)>0),re=d=>(d.kind==="video"||d.kind==="audio")&&!!d.url,ae=new Map;for(const d of g.flatMap(y=>y.audios))!re(d)||ae.has(d.url)||ae.set(d.url,await z(d.url).getPrimaryAudioTrack().then(y=>!!y,()=>!1));const me=d=>re(d)&&!!ae.get(d.url);for(const d of W){if(E?.aborted)throw new DOMException("Export cancelled","AbortError");const y=Math.max(2,Math.ceil(d.duration/A)+1),_=new Float32Array(y);let I=!1;const X=Ur(d.track,e);for(let J=0;J<y;J++){const Ee=d.start+Math.min(d.duration,J*A),ut=g.find(De=>Ee>=De.start-1e-6&&Ee<De.start+De.duration-1e-6),qe=ut?.audios.some(De=>De.id===d.id)?kr(d,Ee-d.start)*X.gain/Pr(ut.audios,me):0;_[J]=qe,qe>0&&(I=!0)}if(!I)continue;const $=await z(d.url).getPrimaryAudioTrack();if(!$)continue;const te=So(d)?Br(d,0,d.duration):null,oe=d.playbackRate||1,O=new yi($),_e=te?te.flatMap(J=>[J.s0,J.s1]):[],Te=te?Math.max(0,Math.min(..._e)-.2):d.inPoint||0,Oe=te?Math.max(..._e)+.2:Te+d.duration*oe,we=[];let Ye=Te;for await(const J of O.samples(Te,Oe))we.length||(Ye=J.timestamp),we.push(J.toAudioBuffer()),J.close();if(!we.length)continue;const ze=we[0].sampleRate,ft=we.reduce((J,Ee)=>J+Ee.length,0);let Fe=[new Float32Array(ft),new Float32Array(ft)],lt=0;for(const J of we){for(let Ee=0;Ee<2;Ee++)Fe[Ee].set(J.getChannelData(Math.min(Ee,J.numberOfChannels-1)),lt);lt+=J.length}te?Fe=Ta(Fe,te,ze,Ye,d.duration):oe!==1&&(Fe=Uo(Fe,oe,ze));const Ke=N.createBuffer(2,Fe[0].length,ze);for(let J=0;J<2;J++)Ke.copyToChannel(Fe[J],J);const ye=N.createBufferSource();ye.buffer=Ke;const Ge=N.createGain();Ge.gain.value=0,Ge.gain.setValueCurveAtTime(_,d.start,Math.max(A,d.duration));const We=N.createChannelSplitter(2),Ae=N.createChannelMerger(2),Le=N.createGain(),rt=N.createGain();Le.gain.value=X.left,rt.gain.value=X.right,ye.connect(Ge),Ge.connect(We),We.connect(Le,0),We.connect(rt,1),Le.connect(Ae,0,0),rt.connect(Ae,0,1),Ae.connect(N.destination),ye.start(d.start,te?0:Math.max(0,Te-Ye)/oe,d.duration)}const xe=await N.startRendering();return ci([xe.getChannelData(0),xe.getChannelData(1)]),xe}export{Pa as canEncodeH264,Ba as canEncodeHevc,ka as canEncodeMp4,ga as exportOnGpu,ro as gpuBitrate,La as gpuExportStage,Na as gpuExportSupported};
197
+ precision highp float;in vec2 uv;uniform sampler2D tex;out vec4 o;void main(){o=texture(tex,uv);}`,Ea=["wipe","blinds","split","iris","diamond","burn"];function Fo(p,g){const w=Math.max(1e-4,p.feather??.05),e=p.progress?Vt(p.progress,g)??0:g,G=(p.angle??0)*Math.PI/180,E=Math.cos(G),N=Math.sin(G),A=Ea.indexOf(p.type??""),Y=p.type==="grid";return{type:"txMask",kind:Y?7:A<0?6:A,e:e*(1+2*w)-w,f:w,inv:!!p.invert,cx:p.cx??.5,cy:p.cy??.5,c:E,s:N,h:.5*(Math.abs(E)+Math.abs(N)),count:p.count??(Y?Sr:8)}}function Ao(p,g,w,e,G=0,E){if(!p)return[];const N=Y=>Vt(p[Y],g)??0,A=[];if(p.zoomBlur&&A.push({type:"txZoom",taps:Rr(),w:N("zoomBlur"),...E?{c:[E.cx,1-E.cy]}:{}}),p.spinBlur){const Y=_r(w,e),re=ae=>Math.max(2,Math.round(ae/2)*2);A.push({type:"txSpin",a:Y.map(ae=>+ae.a.toFixed(6)),sx:Y.map(ae=>re(w*ae.scale)/w),sy:Y.map(ae=>re(e*ae.scale)/e),w:N("spinBlur")})}if(p.dirBlur){const Y=Eo*w/1280,re=Y/(1+Y);A.push({type:"txDir",b:re,reach:Math.min(512,Math.ceil(Math.log(.001)/Math.log(re))),w:N("dirBlur")})}if(p.dirBlurV){const Y=Eo*w/1280,re=Y/(1+Y);A.push({type:"txDir",b:re,reach:Math.min(512,Math.ceil(Math.log(.001)/Math.log(re))),w:N("dirBlurV"),v:!0})}return p.blur&&A.push({type:"txGauss",sigma:Fr*w/1280,w:N("blur")}),p.glitch&&A.push({type:"txGlitch",v:N("glitch"),fr:Math.floor(G*30+.5)}),p.rgbSplit&&A.push({type:"txRgb",px:Math.trunc(N("rgbSplit")*Ar*w/1280+.5)}),p.exposure&&A.push({type:"txExpo",gain:Mr,w:N("exposure")}),p.invert&&A.push({type:"txInv",w:N("invert")}),A}function ba(p,g){const w=new OffscreenCanvas(p,g),e=w.getContext("webgl2",{premultipliedAlpha:!1,preserveDrawingBuffer:!0,antialias:!1});if(!e)throw Error("WebGL2 unavailable");const G=(n,s)=>{const o=e.createShader(n);if(e.shaderSource(o,s),e.compileShader(o),!e.getShaderParameter(o,e.COMPILE_STATUS))throw Error(String(e.getShaderInfoLog(o)));return o},E=(n,s)=>{const o=e.createProgram();if(e.attachShader(o,G(e.VERTEX_SHADER,n)),e.attachShader(o,G(e.FRAGMENT_SHADER,s)),e.bindAttribLocation(o,0,"p"),e.linkProgram(o),!e.getProgramParameter(o,e.LINK_STATUS))throw Error(String(e.getProgramInfoLog(o)));return o},N=E(Bi,Ni),A=E($,Qi),Y=E($,Ji),re=E($,Zi),ae=E($,ea),me=E($,ta),de=E($,oa),d=E($,ra),y=E($,ia),_=E($,Li),C=E($,Ii),L=E($,Ci),O=E($,ha),te=E($,zi),oe=E($,aa),z=E($,na),_e=E($,sa),Te=E($,ca),Oe=E($,la),we=E($,fa),Ye=E($,Xi),ze=E($,Oi),ft=E($,Gi),Fe=E($,qi),lt=E($,$i),We=E($,ji),ye=E($,Hi),Ge=E($,Vi),Ke=E($,Yi),Ae=E($,Wi),Le=E($,Ki),rt=E($,ua),J=E($,ma),Ee=E($,pa),ut=E($,va),qe=E($,da),De=E($,xa),it=e.createBuffer();e.bindBuffer(e.ARRAY_BUFFER,it),e.bufferData(e.ARRAY_BUFFER,new Float32Array([0,0,1,0,0,1,1,1]),e.STATIC_DRAW),e.enableVertexAttribArray(0),e.vertexAttribPointer(0,2,e.FLOAT,!1,0,0);const $e=n=>s=>e.getUniformLocation(n,s),F=$e(N);e.pixelStorei(e.UNPACK_PREMULTIPLY_ALPHA_WEBGL,!1);const pe=()=>{const n=e.createTexture();e.bindTexture(e.TEXTURE_2D,n);for(const[s,o]of[[e.TEXTURE_MIN_FILTER,e.LINEAR],[e.TEXTURE_MAG_FILTER,e.LINEAR],[e.TEXTURE_WRAP_S,e.CLAMP_TO_EDGE],[e.TEXTURE_WRAP_T,e.CLAMP_TO_EDGE]])e.texParameteri(e.TEXTURE_2D,s,o);return n},mt=pe(),wt=pe();let je=null;const at=pe(),pt=e.createTexture(),Ie={l1:"",l3:""};let yt=!1,Xt=!1,ke=null;const Yt={add:1,screen:2,multiply:3,overlay:4,lighten:5,darken:6,difference:7,exclusion:8};let Ce=0;const Rt=pe();let k=[],He=!1,nt=null;const St=n=>{const s=Ve(),o=(n+1)%3,l=(n+2)%3;for(const R of k){let m=n;e.disable(e.BLEND),R.sigma>.05&&(j(_,s[o].fb,[s[n].tex],h=>{e.uniform1i(h("tex"),0),e.uniform2f(h("step"),1/p,0),e.uniform1f(h("sigma"),R.sigma)}),j(_,s[l].fb,[s[o].tex],h=>{e.uniform1i(h("tex"),0),e.uniform2f(h("step"),0,1/g),e.uniform1f(h("sigma"),R.sigma)}),m=l),ue(null),e.enable(e.BLEND),e.blendFuncSeparate(e.SRC_ALPHA,e.ONE_MINUS_SRC_ALPHA,e.ONE,e.ONE_MINUS_SRC_ALPHA);const[t,c,u]=[1,3,5].map(h=>parseInt(R.color.slice(h,h+2),16)/255);j(A,null,[s[m].tex],h=>{e.uniform1i(h("tex"),0),e.uniform2f(h("off"),Math.trunc(R.dx)/p,-Math.trunc(R.dy)/g),e.uniform3f(h("col"),t,c,u),e.uniform1f(h("op"),R.opacity),e.uniform1f(h("times"),R.times),e.uniform2f(h("dil"),R.dilate?+(ei*255).toFixed(3):0,R.dilate?+(1/ti).toFixed(3):0)})}},Qe=n=>{const s=Ve();if(He){ue(nt.fb),e.enable(e.BLEND),e.blendFunc(e.ONE,e.ONE),j(de,nt.fb,[s[n].tex],o=>e.uniform1i(o("tex"),0)),e.blendFuncSeparate(e.SRC_ALPHA,e.ONE_MINUS_SRC_ALPHA,e.ONE,e.ONE_MINUS_SRC_ALPHA);return}if(k.length&&St(n),Ce){Xe(s[n].tex);return}ue(null),e.enable(e.BLEND),e.blendFuncSeparate(e.SRC_ALPHA,e.ONE_MINUS_SRC_ALPHA,e.ONE,e.ONE_MINUS_SRC_ALPHA),j(O,null,[s[n].tex],o=>e.uniform1i(o("tex"),0))},Xe=n=>{ue(null),e.bindTexture(e.TEXTURE_2D,Rt),e.copyTexImage2D(e.TEXTURE_2D,0,e.RGBA8,0,0,p,g,0),e.disable(e.BLEND),j(rt,null,[n,Rt],s=>{e.uniform1i(s("top"),0),e.uniform1i(s("bg"),1),e.uniform1i(s("mode"),Ce)})};let Ue=null;const Ve=()=>Ue??=[Me(),Me(),Me()],Je=new Map,_t=n=>{let s=Je.get(n);if(s)return s;const o=()=>{const l=pe();e.texImage2D(e.TEXTURE_2D,0,e.RGBA8,p*n,g*n,0,e.RGBA,e.UNSIGNED_BYTE,null);const R=e.createFramebuffer();return e.bindFramebuffer(e.FRAMEBUFFER,R),e.framebufferTexture2D(e.FRAMEBUFFER,e.COLOR_ATTACHMENT0,e.TEXTURE_2D,l,0),{tex:l,fb:R}};return s={plane:o(),out:o()},Je.set(n,s),s},Ze=new Map,Ft=new Map,Dt=n=>{let s=Ze.get(n.key);if(s)return s;s=pe();const o=new Uint8Array(256*3);(n.lut??[]).forEach((l,R)=>o.set(l,R*256)),e.pixelStorei(e.UNPACK_ALIGNMENT,1),e.texImage2D(e.TEXTURE_2D,0,e.R8,256,3,0,e.RED,e.UNSIGNED_BYTE,o),e.pixelStorei(e.UNPACK_ALIGNMENT,4);for(const l of[e.TEXTURE_MIN_FILTER,e.TEXTURE_MAG_FILTER])e.texParameteri(e.TEXTURE_2D,l,e.NEAREST);return Ze.set(n.key,s),s},Ot=(n,s)=>{const o=`${n}x${s}`;let l=Ft.get(o);if(l)return l;const R=pe();e.texImage2D(e.TEXTURE_2D,0,e.RGBA8,n,s,0,e.RGBA,e.UNSIGNED_BYTE,null);for(const t of[e.TEXTURE_MIN_FILTER,e.TEXTURE_MAG_FILTER])e.texParameteri(e.TEXTURE_2D,t,e.NEAREST);const m=e.createFramebuffer();return e.bindFramebuffer(e.FRAMEBUFFER,m),e.framebufferTexture2D(e.FRAMEBUFFER,e.COLOR_ATTACHMENT0,e.TEXTURE_2D,R,0),l={tex:R,fb:m},Ft.set(o,l),l},zt=new Map,Wt=(n,s)=>{const o=`${n}x${s}`;let l=zt.get(o);return l||(l=[0,1].map(()=>{const R=pe();e.texImage2D(e.TEXTURE_2D,0,e.RGBA8,n,s,0,e.RGBA,e.UNSIGNED_BYTE,null);const m=e.createFramebuffer();return e.bindFramebuffer(e.FRAMEBUFFER,m),e.framebufferTexture2D(e.FRAMEBUFFER,e.COLOR_ATTACHMENT0,e.TEXTURE_2D,R,0),{tex:R,fb:m}}),zt.set(o,l),l)},Me=()=>{const n=pe();e.texImage2D(e.TEXTURE_2D,0,e.RGBA8,p,g,0,e.RGBA,e.UNSIGNED_BYTE,null);const s=e.createFramebuffer();return e.bindFramebuffer(e.FRAMEBUFFER,s),e.framebufferTexture2D(e.FRAMEBUFFER,e.COLOR_ATTACHMENT0,e.TEXTURE_2D,n,0),{tex:n,fb:s}},ue=n=>{e.bindFramebuffer(e.FRAMEBUFFER,n),e.viewport(0,0,p,g)},j=(n,s,o,l)=>st(n,s,p,g,o,l),st=(n,s,o,l,R,m)=>{e.bindFramebuffer(e.FRAMEBUFFER,s),e.viewport(0,0,o,l),e.useProgram(n);const t=$e(n);R.forEach((c,u)=>{e.activeTexture(e.TEXTURE0+u),e.bindTexture(e.TEXTURE_2D,c)}),m(t),e.drawArrays(e.TRIANGLE_STRIP,0,4),R.length>1&&At(),e.activeTexture(e.TEXTURE0)},At=()=>{e.activeTexture(e.TEXTURE1),e.bindTexture(e.TEXTURE_2D,wt),e.activeTexture(e.TEXTURE2),e.bindTexture(e.TEXTURE_2D,at),e.activeTexture(e.TEXTURE3),e.bindTexture(e.TEXTURE_3D,pt),e.activeTexture(e.TEXTURE0)},dt=(n,s=0)=>{const o=Ve();let l=s;const R=(t,c,u,h)=>{j(_,o[c].fb,[o[t].tex],i=>{e.uniform1i(i("tex"),0),e.uniform2f(i("step"),1/p,0),e.uniform1f(i("sigma"),h)}),j(_,o[u].fb,[o[c].tex],i=>{e.uniform1i(i("tex"),0),e.uniform2f(i("step"),0,1/g),e.uniform1f(i("sigma"),h)})},m=(t,c,u,h)=>j(Fe,o[u].fb,[o[t].tex,o[c].tex],i=>{e.uniform1i(i("a"),0),e.uniform1i(i("b"),1),e.uniform1f(i("w"),h)});for(const t of n){const[c,u,h]=[l,(l+1)%3,(l+2)%3];if(t.type==="blur"){t.sigma>.05&&(R(c,u,h,t.sigma),l=h);continue}if(t.type==="colour"){const i=Dt(t);j(Ge,o[u].fb,[o[c].tex,i],v=>{e.uniform1i(v("tex"),0),e.uniform1i(v("lut"),1),e.uniform1f(v("useM"),t.m?1:0),e.uniform1f(v("useL"),t.lut?1:0),t.m&&e.uniform1fv(v("m"),t.m.flatMap(M=>[M[0],M[1],M[2],M[3]??0]))}),l=u;continue}if(t.type==="txRgb"){t.px>0&&(j(Ee,o[u].fb,[o[c].tex],i=>{e.uniform1i(i("tex"),0),e.uniform1i(i("px"),t.px)}),l=u);continue}if(t.type==="txGlitch"){t.v>1e-4&&(j(qe,o[u].fb,[o[c].tex],i=>{e.uniform1i(i("tex"),0),e.uniform2f(i("size"),p,g),e.uniform2f(i("msize"),Math.max(2,Math.round(p/4)),Math.max(2,Math.round(g/4))),e.uniform1f(i("v"),t.v),e.uniform1f(i("fr"),t.fr)}),l=u);continue}if(t.type==="txInv"){t.w>1e-4&&(j(ut,o[u].fb,[o[c].tex],i=>{e.uniform1i(i("tex"),0),e.uniform1f(i("w"),Math.min(1,t.w))}),l=u);continue}if(t.type==="shift"){j(Ke,o[u].fb,[o[c].tex],i=>{e.uniform1i(i("tex"),0),e.uniform1i(i("px"),t.px)}),l=u;continue}if(t.type==="pixel"){const i=Math.ceil(p/t.block),v=Math.ceil(g/t.block),M=Ot(i,v);e.bindFramebuffer(e.FRAMEBUFFER,M.fb),e.viewport(0,0,i,v),e.useProgram(Ae),e.activeTexture(e.TEXTURE0),e.bindTexture(e.TEXTURE_2D,o[c].tex),e.uniform1i(e.getUniformLocation(Ae,"tex"),0),e.uniform1i(e.getUniformLocation(Ae,"b"),t.block),e.uniform2i(e.getUniformLocation(Ae,"small"),i,v),e.drawArrays(e.TRIANGLE_STRIP,0,4),j(Le,o[u].fb,[M.tex],Q=>{e.uniform1i(Q("small"),0),e.uniform1i(Q("b"),t.block),e.uniform2f(Q("size"),p,g)}),l=u;continue}if(t.type==="txMask"){j(ye,o[u].fb,[o[c].tex],i=>{e.uniform1i(i("tex"),0),e.uniform2f(i("size"),p,g),e.uniform1i(i("kind"),t.kind),e.uniform1f(i("e"),t.e),e.uniform1f(i("f"),t.f),e.uniform1f(i("inv"),t.inv?1:0),e.uniform2f(i("ctr"),t.cx,t.cy),e.uniform3f(i("csh"),t.c,t.s,t.h),e.uniform1f(i("count"),t.count)}),l=u;continue}if(t.type==="txGauss"||t.type==="txDir"||t.type==="txZoom"||t.type==="txSpin"||t.type==="txExpo"){if(!(t.w>1e-4))continue;let i=u;t.type==="txGauss"?(R(c,u,h,t.sigma),i=h):t.type==="txDir"?j(Ye,o[u].fb,[o[c].tex],M=>{e.uniform1i(M("tex"),0),t.v?e.uniform2f(M("step"),0,1/g):e.uniform2f(M("step"),1/p,0),e.uniform1f(M("b"),t.b),e.uniform1i(M("reach"),t.reach)}):t.type==="txZoom"?j(ze,o[u].fb,[o[c].tex],M=>{e.uniform1i(M("tex"),0),e.uniform1fv(M("taps"),t.taps),e.uniform1i(M("n"),t.taps.length),e.uniform2f(M("ctr"),t.c?.[0]??.5,t.c?.[1]??.5)}):t.type==="txSpin"?j(De,o[u].fb,[o[c].tex],M=>{e.uniform1i(M("tex"),0),e.uniform2f(M("size"),p,g),e.uniform1fv(M("a"),t.a),e.uniform1fv(M("sx"),t.sx),e.uniform1fv(M("sy"),t.sy)}):j(ft,o[u].fb,[o[c].tex],M=>{e.uniform1i(M("tex"),0),e.uniform1f(M("gain"),t.gain)});const v=i===h?u:h;m(c,i,v,Math.min(1,t.w)),l=v;continue}if(t.type==="burst"){const{w:i,h:v}=di(p,g),[M,Q]=Wt(i,v),K=ui(mi.burst*t.amount).map(V=>pi(i,v,V));j(C,o[u].fb,[o[c].tex],V=>{e.uniform1i(V("tex"),0),e.uniform1f(V("lo"),t.lo),e.uniform1f(V("k"),t.k)}),st(O,M.fb,i,v,[o[u].tex],V=>e.uniform1i(V("tex"),0)),st(te,Q.fb,i,v,[M.tex],V=>{e.uniform1i(V("tex"),0),e.uniform1i(V("n"),K.length),e.uniform1fv(V("sx"),K.map(be=>be.sw/i)),e.uniform1fv(V("sy"),K.map(be=>be.sh/v)),e.uniform3f(V("gain"),...vi(t.amount))}),j(L,o[h].fb,[o[c].tex,Q.tex],V=>{e.uniform1i(V("a"),0),e.uniform1i(V("b"),1),e.uniform1f(V("amount"),+t.amount.toFixed(4))}),l=h;continue}j(C,o[u].fb,[o[c].tex],i=>{e.uniform1i(i("tex"),0),e.uniform1f(i("lo"),t.lo),e.uniform1f(i("k"),t.k)}),R(u,h,u,t.sigma),j(L,o[h].fb,[o[c].tex,o[u].tex],i=>{e.uniform1i(i("a"),0),e.uniform1i(i("b"),1),e.uniform1f(i("amount"),t.amount)}),l=h}return l};let ct=null,r="",f=[],U="";const x=(n,s)=>{if(U!==`${n}x${s}`){for(const o of f)e.deleteTexture(o.tex),e.deleteFramebuffer(o.fb);f=Array.from({length:4},()=>{const o=pe();e.texImage2D(e.TEXTURE_2D,0,e.RGBA8,n,s,0,e.RGBA,e.UNSIGNED_BYTE,null);const l=e.createFramebuffer();return e.bindFramebuffer(e.FRAMEBUFFER,l),e.framebufferTexture2D(e.FRAMEBUFFER,e.COLOR_ATTACHMENT0,e.TEXTURE_2D,o,0),{tex:o,fb:l}}),U=`${n}x${s}`}return f},T=(n,s,o,l)=>{const R=e.getParameter(e.FRAMEBUFFER_BINDING),m=e.getParameter(e.VIEWPORT),t=e.isEnabled(e.BLEND),c=x(l.ew,l.eh),u=(i,v,M,Q)=>{e.bindFramebuffer(e.FRAMEBUFFER,c[v].fb),e.viewport(0,0,l.ew,l.eh),e.useProgram(i);const K=$e(i);M.forEach((V,be)=>{e.activeTexture(e.TEXTURE0+be),e.bindTexture(e.TEXTURE_2D,c[V].tex)}),Q(K),e.drawArrays(e.TRIANGLE_STRIP,0,4),M.length>1&&At(),e.activeTexture(e.TEXTURE0)};e.disable(e.BLEND),e.bindFramebuffer(e.FRAMEBUFFER,c[0].fb),e.viewport(0,0,l.ew,l.eh),e.clearColor(0,0,0,0),e.clear(e.COLOR_BUFFER_BIT);{const i=kt(n,o);e.bindFramebuffer(e.FRAMEBUFFER,c[0].fb),e.viewport(0,0,l.ew,l.eh),e.disable(e.BLEND),vt(n,[0,0,1,1],s,1,1,!1,i==="win"?null:o,i)}u(Y,1,[0],i=>{e.uniform1i(i("tex"),0),e.uniform1f(i("harden"),l.harden?Qr:0)});const h=(i,v,M,Q)=>{u(re,v,[i],K=>{e.uniform1i(K("tex"),0),e.uniform2i(K("dir"),1,0),e.uniform1f(K("sigma"),Q)}),u(re,M,[v],K=>{e.uniform1i(K("tex"),0),e.uniform2i(K("dir"),0,1),e.uniform1f(K("sigma"),Q)})};h(1,2,3,l.band),u(ae,2,[1,3],i=>{e.uniform1i(i("a"),0),e.uniform1i(i("b"),1);const v=l.arc;e.uniform1f(i("arc"),v?1:0),v&&(e.uniform2f(i("cw"),l.ew/to,l.eh/to),e.uniform2f(i("cen"),v.cen[0],v.cen[1]),e.uniform1f(i("start"),v.start),e.uniform1f(i("cover"),v.cover),e.uniform1f(i("comet"),v.comet?1:0),e.uniform1f(i("feather"),Jr*v.cover))}),h(2,1,3,l.glow),u(me,1,[0,2,3],i=>{e.uniform1i(i("pic"),0),e.uniform1i(i("band"),1),e.uniform1i(i("glow"),2),e.uniform3f(i("col"),...l.col),e.uniform1f(i("k"),l.k),e.uniform1f(i("am"),l.am)}),e.bindFramebuffer(e.FRAMEBUFFER,R),e.viewport(m[0],m[1],m[2],m[3]),t&&e.enable(e.BLEND)};let X=null,P="",ce=null,W=[],Z="";const a=new Map,S=new Map,fe=new Map,ve=new Map,ne=new Map,Re=new Map,se=pe(),B=(n,s)=>{const o=pe();e.texImage2D(e.TEXTURE_2D,0,e.RGBA8,n,s,0,e.RGBA,e.UNSIGNED_BYTE,null);const l=e.createFramebuffer();return e.bindFramebuffer(e.FRAMEBUFFER,l),e.framebufferTexture2D(e.FRAMEBUFFER,e.COLOR_ATTACHMENT0,e.TEXTURE_2D,o,0),{tex:o,fb:l}},Pe=(n,s,o)=>{const l=e.getParameter(e.FRAMEBUFFER_BINDING),R=e.getParameter(e.VIEWPORT),m=e.isEnabled(e.BLEND),t=n.w,c=n.h;if(Z!==`${t}x${c}`){for(const H of W)e.deleteTexture(H.tex),e.deleteFramebuffer(H.fb);W=Array.from({length:7},()=>B(t,c)),Z=`${t}x${c}`}e.disable(e.BLEND),e.bindFramebuffer(e.FRAMEBUFFER,W[0].fb),e.viewport(0,0,t,c),e.clearColor(0,0,0,0),e.clear(e.COLOR_BUFFER_BIT),vt(n,[0,1,1,-1],[0,0,1,1],1,1,!1,s,"base");let u=0;const h=H=>[H[0],H[3],H[6],H[1],H[4],H[7],H[2],H[5],H[8]],i=(H,q,ht,et)=>{e.bindFramebuffer(e.FRAMEBUFFER,W[q].fb),e.viewport(0,0,t,c),e.useProgram(H);const Be=$e(H);ht.forEach((Et,bt)=>{e.activeTexture(e.TEXTURE0+bt),e.bindTexture(Et.d3?e.TEXTURE_3D:e.TEXTURE_2D,Et.t)}),et(Be),e.drawArrays(e.TRIANGLE_STRIP,0,4),At()},v=H=>({t:W[H].tex}),M=(H,q,ht,et)=>{i(_,q,[v(H)],Be=>{e.uniform1i(Be("tex"),0),e.uniform2f(Be("step"),1/t,0),e.uniform1f(Be("sigma"),et)}),i(_,ht,[v(q)],Be=>{e.uniform1i(Be("tex"),0),e.uniform2f(Be("step"),0,1/c),e.uniform1f(Be("sigma"),et)})},Q=o.list,K=Q.map(H=>eo(H)),V=Ir(Q),be=new Set;for(const[H,q]of Q.entries()){const ht=V[H];if(H===ht&&Q.some((b,D)=>D>H&&V[D]===H&&K[D])&&(i(O,2,[v(u)],b=>e.uniform1i(b("tex"),0)),be.add(H)),!K[H])continue;const et=H!==ht&&be.has(ht)?q.branch:void 0,Be=et?2:u;let Et=se,bt=[1,1];if(q.qualifier){const b=Math.max(2,Math.trunc((t+Mt-1)/Mt)),D=Math.max(2,Math.trunc((c+Mt-1)/Mt)),I=`${b}x${D}`;let ie=a.get(I);ie||(ie=B(b,D),a.set(I,ie));const ee=q.qualifier,xe=Math.max(.001,ee.soft??.3),Se=q.window,Tt=-(Se?.rot??0)*Math.PI/180;e.bindFramebuffer(e.FRAMEBUFFER,ie.fb),e.viewport(0,0,b,D),e.useProgram(y),e.activeTexture(e.TEXTURE0),e.bindTexture(e.TEXTURE_2D,W[Be].tex);const ge=$e(y);e.uniform1i(ge("tex"),0),e.uniform2f(ge("big"),t,c),e.uniform2f(ge("small"),b,D),e.uniform4f(ge("q1"),ee.hue,ee.hueWidth,Math.max(1,xe*60),Math.max(.001,xe*.2)),e.uniform4f(ge("q2"),ee.satMin,ee.satMax,ee.lumMin,ee.lumMax),e.uniform1f(ge("useQ"),1),e.uniform1f(ge("useW"),Se?1:0),Se&&(e.uniform4f(ge("w1"),Se.cx,Se.cy,Math.max(1e-4,Se.w/2),Math.max(.001,Se.feather??.2)),e.uniform4f(ge("w2"),Math.cos(Tt),Math.sin(Tt),Math.max(1e-4,Se.h/2),Se.type==="gradient"?2:Se.type==="rect"?1:0)),e.uniform1f(ge("inv"),q.invert?1:0),e.drawArrays(e.TRIANGLE_STRIP,0,4),Et=ie.tex,bt=[b*Mt,D*Mt]}else if(!q.whole&&Cr(q)&&q.window?.type!=="person"){const b=`${o.clip}#${H}`,D=`${t}x${c}@${o.local??0}`,I=go,ie=Math.max(2,Math.min(go*2,Math.round(I*c/t)));let ee=ve.get(b);if(ee||(ee={tex:pe(),at:""},ve.set(b,ee)),ee.at!==D){const xe=bo(q,o.src,o.local??0,c/t,null),Se=new Uint8Array(I*ie);for(let Tt=0;Tt<ie;Tt++)for(let ge=0;ge<I;ge++)Se[Tt*I+ge]=Math.round(xe((ge+.5)/I,(Tt+.5)/ie,0,0,0)*255);e.bindTexture(e.TEXTURE_2D,ee.tex),e.pixelStorei(e.UNPACK_ALIGNMENT,1),e.texImage2D(e.TEXTURE_2D,0,e.R8,I,ie,0,e.RED,e.UNSIGNED_BYTE,Se),e.pixelStorei(e.UNPACK_ALIGNMENT,4),ee.at=D}Et=ee.tex,bt=[t,c]}else if(!q.whole){const b=To(q)?o.src?.depthMap:void 0,D=`${o.clip}#${H}@${t}x${c}${b?`@${b.at}:${b.data.length}:${b.data.slice(0,24)}`:""}`;let I=S.get(D);if(!I){const ie=Xr(q,t,c,To(q)?bo(q,o.src,0,c/t):null);I=pe(),e.pixelStorei(e.UNPACK_ALIGNMENT,1),e.texImage2D(e.TEXTURE_2D,0,e.R8,ie.w4,ie.h4,0,e.RED,e.UNSIGNED_BYTE,ie.px),e.pixelStorei(e.UNPACK_ALIGNMENT,4),S.set(D,I)}Et=I,bt=[t,c]}const Ut=q.adjust??{},no=Or(q),Kt=`${o.clip}#${H}`;let Gt=fe.get(Kt);if(no&&!Gt){const b=new Float32Array(1024);for(let D=0;D<256;D++)["r","g","b"].forEach((I,ie)=>{b[D*4+ie]=+zr(Ut,I,D/255,q.wheels,q.curves).toFixed(6)}),b[D*4+3]=1;Gt=pe(),e.texImage2D(e.TEXTURE_2D,0,e.RGBA32F,256,1,0,e.RGBA,e.FLOAT,b);for(const D of[e.TEXTURE_MIN_FILTER,e.TEXTURE_MAG_FILTER])e.texParameteri(e.TEXTURE_2D,D,e.NEAREST);fe.set(Kt,Gt)}let gt=null;if(Gr(q)){const b=`${Kt}:${JSON.stringify([q.cst,q.look,q.lut,q.mixer])}`;if(gt=ne.get(b)??null,!gt){const D=qr(q,I=>xi(I));if(!D)throw Error(`LUT "${q.lut?.name??""}" chưa tải xong`);gt=e.createTexture(),e.activeTexture(e.TEXTURE4),e.bindTexture(e.TEXTURE_3D,gt),e.pixelStorei(e.UNPACK_ALIGNMENT,1),e.texImage3D(e.TEXTURE_3D,0,e.RGB32F,D.size,D.size,D.size,0,e.RGB,e.FLOAT,D.data),e.pixelStorei(e.UNPACK_ALIGNMENT,4);for(const I of[e.TEXTURE_MIN_FILTER,e.TEXTURE_MAG_FILTER])e.texParameteri(e.TEXTURE_3D,I,e.NEAREST);for(const I of[e.TEXTURE_WRAP_S,e.TEXTURE_WRAP_T,e.TEXTURE_WRAP_R])e.texParameteri(e.TEXTURE_3D,I,e.CLAMP_TO_EDGE);e.activeTexture(e.TEXTURE0),ne.set(b,gt)}}const{sat:No,rot:Lo}=$r(Ut.saturation??1,Ut.hue??0);i(oe,3,[v(Be),{t:Gt??at},{t:gt??pt,d3:!0}],b=>{e.uniform1i(b("tex"),0),e.uniform1i(b("lut"),1),e.uniform1i(b("t3"),2),e.uniform1f(b("useT"),gt?1:0),e.uniform1f(b("useL"),no?1:0),e.uniform1f(b("useS"),(Ut.saturation??1)!==1?1:0),e.uniform1f(b("useR"),(Ut.hue??0)!==0?1:0),e.uniformMatrix3fv(b("sat"),!1,h(No)),e.uniformMatrix3fv(b("rot"),!1,h(Lo))}),e.activeTexture(e.TEXTURE2),e.bindTexture(e.TEXTURE_3D,null),e.activeTexture(e.TEXTURE0),At();let le=3;const tt=(b,D)=>[3,4,5].find(I=>I!==b&&I!==D);if((q.blur??0)>0){const b=tt(le),D=tt(le,b);M(le,b,D,Math.max(.1,+((q.blur??0)*jr*t).toFixed(3))),le=D}const so=Hr({sharpness:q.sharpen??0});if(so){const b=tt(le);i(_e,b,[v(le)],D=>{e.uniform1i(D("tex"),0),e.uniform1fv(D("k"),so),e.uniform1f(D("rdiv"),1/Zr)}),le=b}const he=q.fx?Vr(q.fx,t):null;if(he&&(he.type==="glow"||he.type==="halation")){const b=tt(le),D=tt(le,b);i(C,b,[v(le)],xe=>{e.uniform1i(xe("tex"),0),e.uniform1f(xe("lo"),he.lo),e.uniform1f(xe("k"),he.k)});let I=b;he.tint&&(i(Ge,D,[v(b),{t:at}],xe=>{e.uniform1i(xe("tex"),0),e.uniform1i(xe("lut"),1),e.uniform1f(xe("useM"),1),e.uniform1f(xe("useL"),0),e.uniform1fv(xe("m"),he.tint.flat())}),I=D),M(I,I===b?D:b,I,he.sigma);const ee=6;i(L,ee,[v(le),v(I)],xe=>{e.uniform1i(xe("a"),0),e.uniform1i(xe("b"),1),e.uniform1f(xe("amount"),he.amount)}),i(O,3,[v(ee)],xe=>e.uniform1i(xe("tex"),0)),le=3}else if(he?.type==="grain"){const b=Yr(o.frame??0),D=`${b}:${t}x${c}:${he.amp}`;let I=Re.get(D);if(!I){if(Re.size>8){for(const ee of Re.values())e.deleteTexture(ee);Re.clear()}I=pe(),e.pixelStorei(e.UNPACK_ALIGNMENT,1),e.texImage2D(e.TEXTURE_2D,0,e.R8,t,c,0,e.RED,e.UNSIGNED_BYTE,Wr(b,t,c,he.amp)),e.pixelStorei(e.UNPACK_ALIGNMENT,4),Re.set(D,I)}const ie=tt(le);i(Te,ie,[v(le),{t:I}],ee=>{e.uniform1i(ee("tex"),0),e.uniform1i(ee("grain"),1)}),le=ie}else if(he?.type==="denoise"){const b=tt(le),D=tt(le,b);M(le,b,D,he.sigma),i(Oe,6,[v(le),v(D)],I=>{e.uniform1i(I("tex"),0),e.uniform1i(I("soft"),1),e.uniform1f(I("t"),he.t)}),i(O,3,[v(6)],I=>e.uniform1i(I("tex"),0)),le=3}else if(he?.type==="swirl"){const b=D=>Math.max(2,Math.round(D/2)*2);for(const D of Kr(t,c,he.deg)){const I=tt(le);i(De,I,[v(le)],ie=>{e.uniform1i(ie("tex"),0),e.uniform2f(ie("size"),t,c),e.uniform1fv(ie("a"),D.map(ee=>+ee.a.toFixed(6))),e.uniform1fv(ie("sx"),D.map(ee=>b(t*ee.scale)/t)),e.uniform1fv(ie("sy"),D.map(ee=>b(c*ee.scale)/c))}),le=I}}const Io=et==="parallel"?2:u,Co=et==="parallel"?6:1-u;i(z,Co,[v(Io),v(le),{t:Et}],b=>{e.uniform1i(b("base"),0),e.uniform1i(b("over"),1),e.uniform1i(b("mask"),2),e.uniform2f(b("msz"),bt[0],bt[1]),e.uniform1f(b("full"),q.whole?1:0)}),et==="parallel"&&i(we,1-u,[v(u),v(6),v(2)],b=>{e.uniform1i(b("res"),0),e.uniform1i(b("outp"),1),e.uniform1i(b("inp"),2)}),u=1-u}ce=W[u].tex,e.bindFramebuffer(e.FRAMEBUFFER,l),e.viewport(R[0],R[1],R[2],R[3]),m&&e.enable(e.BLEND)},kt=(n,s)=>X?(P!==X.key&&(Pe(n,s,X),P=X.key),"win"):"pic",xt=(n,s,o,l,R,m,t)=>{if(!ct){const M=kt(n,t);vt(n,s,o,l,R,m,M==="win"?null:t,M);return}const c=je??[0,0,1,1];r!==ct.key&&(T(n,c,t,ct),r=ct.key);const u=(o[0]-c[0])/c[2],h=(o[1]-c[1])/c[3],i=o[2]/c[2],v=o[3]/c[3];vt(n,s,[u,1-h,i,-v],l,R,m,null,"edge")},vt=(n,s,o,l,R,m,t,c)=>{const u=c==="edge"||c==="win",h=c==="pic"||c==="base";if(e.useProgram(N),e.activeTexture(e.TEXTURE0),e.bindTexture(e.TEXTURE_2D,mt),h&&e.texImage2D(e.TEXTURE_2D,0,e.RGBA,e.RGBA,e.UNSIGNED_BYTE,n.source),e.uniform4f(F("dst"),s[0],s[1],s[2],s[3]),e.uniform4f(F("src"),o[0],o[1],o[2],o[3]),e.uniform1f(F("alpha"),l),e.uniform1f(F("fade"),R),e.uniform1f(F("white"),m?1:0),e.uniform1f(F("colour"),t?1:0),e.uniform1i(F("tex"),0),e.uniform1i(F("matte"),1),e.uniform1f(F("useMatte"),je&&(c==="pic"||c==="win")?1:0),ke&&!u?(e.uniform4f(F("key"),ke.u,ke.v,ke.similarity,ke.blend),e.uniform4f(F("keyOpt"),1,ke.blue?1:0,ke.spill,n.bt709?1:0)):e.uniform4f(F("keyOpt"),0,0,0,0),e.uniform1i(F("lut1"),2),e.uniform1i(F("lut3"),3),e.uniform1f(F("useL1"),yt&&!u?1:0),e.uniform1f(F("useL3"),Xt&&!u?1:0),je&&e.uniform4f(F("mrect"),je[0],je[1],je[2],je[3]),e.activeTexture(e.TEXTURE1),e.bindTexture(e.TEXTURE_2D,wt),e.activeTexture(e.TEXTURE2),e.bindTexture(e.TEXTURE_2D,at),e.activeTexture(e.TEXTURE3),e.bindTexture(e.TEXTURE_3D,pt),e.activeTexture(e.TEXTURE0),e.bindTexture(e.TEXTURE_2D,c==="edge"?f[1].tex:c==="win"?ce:mt),t){const i=v=>[v[0],v[3],v[6],v[1],v[4],v[7],v[2],v[5],v[8]];e.uniform1f(F("bright"),t.bright),e.uniform1f(F("contrast"),t.contrast),e.uniformMatrix3fv(F("sat"),!1,i(t.sat)),e.uniformMatrix3fv(F("rot"),!1,i(t.rot))}e.drawArrays(e.TRIANGLE_STRIP,0,4)};return{canvas:w,clear(n=1){ue(null),e.clearColor(0,0,0,n),e.clear(e.COLOR_BUFFER_BIT)},pixels(){ue(null);const n=new Uint8ClampedArray(p*g*4),s=p*4,o=new Uint8ClampedArray(p*g*4);e.readPixels(0,0,p,g,e.RGBA,e.UNSIGNED_BYTE,n);for(let l=0;l<g;l++){const R=(g-1-l)*s,m=l*s;for(let t=0;t<s;t+=4){const c=n[R+t+3];if(o[m+t+3]=c,c){const u=255/c;o[m+t]=n[R+t]*u,o[m+t+1]=n[R+t+1]*u,o[m+t+2]=n[R+t+2]*u}}}return o},draw(n,s,o,l,R,m,t=null,c=[],u=null){if(!c.length&&!Ce&&!k.length&&!He){ue(null),e.enable(e.BLEND),e.blendFuncSeparate(e.SRC_ALPHA,e.ONE_MINUS_SRC_ALPHA,e.ONE,e.ONE_MINUS_SRC_ALPHA),xt(n,s,o,l,R,m,t);return}Ue??=[Me(),Me(),Me()],ue(Ue[0].fb),e.disable(e.BLEND),e.clearColor(0,0,0,0),e.clear(e.COLOR_BUFFER_BIT),xt(n,u??s,o,l,R,m,t);const h=dt(c);if(ue(null),e.enable(e.BLEND),e.blendFuncSeparate(e.SRC_ALPHA,e.ONE_MINUS_SRC_ALPHA,e.ONE,e.ONE_MINUS_SRC_ALPHA),Ce||k.length||He){let i=h;u&&(i=(h+1)%3,ue(Ue[i].fb),e.disable(e.BLEND),e.clearColor(0,0,0,0),e.clear(e.COLOR_BUFFER_BIT),e.useProgram(N),e.activeTexture(e.TEXTURE0),e.bindTexture(e.TEXTURE_2D,Ue[h].tex),e.uniform4f(F("dst"),s[0],s[1],s[2],s[3]),e.uniform4f(F("src"),0,1,1,-1),e.uniform1f(F("alpha"),1),e.uniform1f(F("fade"),1),e.uniform1f(F("white"),0),e.uniform1f(F("colour"),0),e.uniform1f(F("useMatte"),0),e.drawArrays(e.TRIANGLE_STRIP,0,4)),Qe(i);return}if(!u){j(O,null,[Ue[h].tex],i=>e.uniform1i(i("tex"),0));return}e.useProgram(N),e.activeTexture(e.TEXTURE0),e.bindTexture(e.TEXTURE_2D,Ue[h].tex),e.uniform4f(F("dst"),s[0],s[1],s[2],s[3]),e.uniform4f(F("src"),0,1,1,-1),e.uniform1f(F("alpha"),1),e.uniform1f(F("fade"),1),e.uniform1f(F("white"),0),e.uniform1f(F("colour"),0),e.uniform1f(F("useMatte"),0),e.drawArrays(e.TRIANGLE_STRIP,0,4)},warp(n,s,o,l,R,m,t,c,u,h=null,i=null,v=[]){const M=Ve();ue(M[0].fb),e.disable(e.BLEND),e.clearColor(0,0,0,0),e.clear(e.COLOR_BUFFER_BIT),xt(n,s,o,l,R,m,t);const Q=dt(c),K=Ce||k.length||He||v.length?(Q+1)%3:-1;K>=0?(ue(M[K].fb),e.disable(e.BLEND),e.clearColor(0,0,0,0),e.clear(e.COLOR_BUFFER_BIT)):(ue(null),e.enable(e.BLEND),e.blendFuncSeparate(e.SRC_ALPHA,e.ONE_MINUS_SRC_ALPHA,e.ONE,e.ONE_MINUS_SRC_ALPHA)),i&&(e.enable(e.SCISSOR_TEST),e.scissor(i[0],g-i[1]-i[3],i[2],i[3])),j(We,K>=0?M[K].fb:null,[M[Q].tex],V=>{e.uniform1i(V("tex"),0),e.uniform2f(V("size"),p,g),e.uniform1f(V("keepPre"),0),e.uniformMatrix3fv(V("inv"),!1,[u[0],u[3],u[6],u[1],u[4],u[7],u[2],u[5],u[8]]),e.uniform4f(V("rnd"),h?.[0]??0,h?.[1]??0,h?.[2]??0,h?1:0)}),e.disable(e.SCISSOR_TEST),K>=0&&Qe(v.length?dt(v,K):K)},adjust(n,s,o){const l=Ve();if(ue(null),e.bindTexture(e.TEXTURE_2D,Rt),e.copyTexImage2D(e.TEXTURE_2D,0,e.RGBA8,0,0,p,g,0),ue(l[0].fb),e.disable(e.BLEND),e.useProgram(N),e.activeTexture(e.TEXTURE0),e.bindTexture(e.TEXTURE_2D,Rt),e.uniform4f(F("dst"),0,0,1,1),e.uniform4f(F("src"),0,1,1,-1),e.uniform1i(F("tex"),0),e.uniform1f(F("alpha"),1),e.uniform1f(F("fade"),1),e.uniform1f(F("white"),0),e.uniform1f(F("useMatte"),0),e.uniform1f(F("colour"),n?1:0),n){const m=t=>[t[0],t[3],t[6],t[1],t[4],t[7],t[2],t[5],t[8]];e.uniform1f(F("bright"),n.bright),e.uniform1f(F("contrast"),n.contrast),e.uniformMatrix3fv(F("sat"),!1,m(n.sat)),e.uniformMatrix3fv(F("rot"),!1,m(n.rot))}e.drawArrays(e.TRIANGLE_STRIP,0,4);const R=dt(s);ue(null),e.enable(e.BLEND),e.blendFuncSeparate(e.SRC_ALPHA,e.ONE_MINUS_SRC_ALPHA,e.ONE,e.ONE_MINUS_SRC_ALPHA),e.useProgram(N),e.activeTexture(e.TEXTURE0),e.bindTexture(e.TEXTURE_2D,l[R].tex),e.uniform4f(F("dst"),0,0,1,1),e.uniform4f(F("src"),0,1,1,-1),e.uniform1f(F("alpha"),o),e.uniform1f(F("fade"),1),e.uniform1f(F("white"),0),e.uniform1f(F("colour"),0),e.uniform1f(F("useMatte"),0),e.drawArrays(e.TRIANGLE_STRIP,0,4)},grade(n,s){if(yt=!!n,Xt=!!s,n&&Ie.l1!==n.key){const o=new Float32Array(1024);for(let l=0;l<256;l++)o[l*4]=n.r[l],o[l*4+1]=n.g[l],o[l*4+2]=n.b[l],o[l*4+3]=1;e.activeTexture(e.TEXTURE2),e.bindTexture(e.TEXTURE_2D,at),e.texImage2D(e.TEXTURE_2D,0,e.RGBA32F,256,1,0,e.RGBA,e.FLOAT,o);for(const l of[e.TEXTURE_MIN_FILTER,e.TEXTURE_MAG_FILTER])e.texParameteri(e.TEXTURE_2D,l,e.NEAREST);e.activeTexture(e.TEXTURE0),Ie.l1=n.key}if(s&&Ie.l3!==s.key){e.activeTexture(e.TEXTURE3),e.bindTexture(e.TEXTURE_3D,pt),e.pixelStorei(e.UNPACK_ALIGNMENT,1),e.texImage3D(e.TEXTURE_3D,0,e.RGB32F,s.size,s.size,s.size,0,e.RGB,e.FLOAT,s.data),e.pixelStorei(e.UNPACK_ALIGNMENT,4);for(const o of[e.TEXTURE_MIN_FILTER,e.TEXTURE_MAG_FILTER])e.texParameteri(e.TEXTURE_3D,o,e.NEAREST);for(const o of[e.TEXTURE_WRAP_S,e.TEXTURE_WRAP_T,e.TEXTURE_WRAP_R])e.texParameteri(e.TEXTURE_3D,o,e.CLAMP_TO_EDGE);e.activeTexture(e.TEXTURE0),Ie.l3=s.key}},key(n){if(!n){ke=null;return}const[s,o,l]=[1,3,5].map(m=>parseInt(n.color.slice(m,m+2),16)),R=224/255;ke={u:Math.round(-.168736*R*s-.331264*R*o+.5*R*l+128),v:Math.round(.5*R*s-.418688*R*o-.081312*R*l+128),similarity:n.similarity,blend:n.blend,spill:+n.spill.toFixed(3),blue:l>o}},mode(n){Ce=n&&Yt[n]||0},shadow(n){k=n},blurBegin(){nt??=Me(),ue(nt.fb),e.clearColor(0,0,0,0),e.clear(e.COLOR_BUFFER_BIT),He=!0},blurEnd(){He=!1;const n=Ve();e.disable(e.BLEND),j(d,n[0].fb,[nt.tex],s=>e.uniform1i(s("tex"),0)),Qe(0)},windows(n){X=n},edge(n){ct=n},warpBig(n,s,o,l,R,m,t,c,u,h=[]){const i=_t(u),v=p*u,M=g*u;e.bindFramebuffer(e.FRAMEBUFFER,i.plane.fb),e.viewport(0,0,v,M),e.disable(e.BLEND),e.clearColor(0,0,0,0),e.clear(e.COLOR_BUFFER_BIT),xt(n,s,o,l,R,m,t);const Q=It(c.map(([be,H])=>[be*u,H*u]),v,M);e.bindFramebuffer(e.FRAMEBUFFER,i.out.fb),e.viewport(0,0,v,M),e.useProgram(We),e.activeTexture(e.TEXTURE0),e.bindTexture(e.TEXTURE_2D,i.plane.tex);const K=$e(We);if(e.uniform1i(K("tex"),0),e.uniform2f(K("size"),v,M),e.uniform1f(K("keepPre"),1),e.uniform4f(K("rnd"),0,0,0,0),e.uniformMatrix3fv(K("inv"),!1,[Q[0],Q[3],Q[6],Q[1],Q[4],Q[7],Q[2],Q[5],Q[8]]),e.drawArrays(e.TRIANGLE_STRIP,0,4),ue(null),e.enable(e.BLEND),e.blendFuncSeparate(e.SRC_ALPHA,e.ONE_MINUS_SRC_ALPHA,e.ONE,e.ONE_MINUS_SRC_ALPHA),!h.length&&!Ce&&!k.length&&!He){j(J,null,[i.out.tex],be=>{e.uniform1i(be("tex"),0),e.uniform1i(be("ss"),u)});return}const V=Ve();e.disable(e.BLEND),j(J,V[0].fb,[i.out.tex],be=>{e.uniform1i(be("tex"),0),e.uniform1i(be("ss"),u)}),Qe(dt(h,0))},matte(n,s=[0,0,1,1]){je=n?s:null,n&&(e.activeTexture(e.TEXTURE1),e.bindTexture(e.TEXTURE_2D,wt),e.texImage2D(e.TEXTURE_2D,0,e.RGBA,e.RGBA,e.UNSIGNED_BYTE,n),e.activeTexture(e.TEXTURE0))},overlay(n,s){ue(null),e.enable(e.BLEND),e.blendFuncSeparate(e.SRC_ALPHA,e.ONE_MINUS_SRC_ALPHA,e.ONE,e.ONE_MINUS_SRC_ALPHA),s&&(e.activeTexture(e.TEXTURE0),e.bindTexture(e.TEXTURE_2D,mt),e.texImage2D(e.TEXTURE_2D,0,e.RGBA,s.w,s.h,0,e.RGBA,e.UNSIGNED_BYTE,s.data)),j(lt,null,s?[mt]:[],o=>{e.uniform1i(o("tex"),0),e.uniform1f(o("usetex"),s?1:0),e.uniform4f(o("colour"),...n??[0,0,0,0])})},finish(){e.finish()}}}let Ne="";const La=()=>Ne;async function ga(p,{format:g,encode:w=null,tracks:e={},camera:G=null,signal:E,onProgress:N,frames:A,software:Y=!1,liveMotion:re=!1,range:ae,only:me,sink:de}){const d=performance.now(),{width:y,height:_,fps:C}=oo(g);Ne="layers",await Promise.all([...new Set(p.filter(r=>!r.colorBypass).flatMap(r=>qt(r.grade).map(f=>f?.lut?.id)).filter(r=>!!r))].map(r=>li(r))),Xo(co(p.filter(r=>!r.disabled)));const L=p.filter(r=>!r.disabled&&!Mo(r)),O=co(L),te=Oo(L.reduce((r,f)=>Math.max(r,f.start+f.duration),0)),oe=Math.round(te*C);if(!(oe>0)&&!A)throw Error("Empty timeline");const z=zo(G)?G:null,_e=Go(O,e,z?r=>Nr(r,z,y,_):void 0),Te=r=>_e.find(f=>r>=f.start-1e-6&&r<f.start+f.duration-1e-6)??null,Oe=()=>{if(E?.aborted)throw new DOMException("Export cancelled","AbortError")},we=r=>re&&!A&&!!r.motion&&!r._virtual&&!r.warped,Ye=r=>A||me!=="audio"&&(!ae||r.start<ae.to/C+1e-6&&r.start+r.duration>ae.from/C-1e-6),ze=new Pi,ft=[...L.filter(r=>Ht(r)&&!we(r)),...qo(L)].filter(Ye);ft.length&&await(await Pt(async()=>{const{renderTitleFrames:r}=await import("./titleFrames-BI1DnLBn.js");return{renderTitleFrames:r}},__vite__mapDeps([0,1,2,3,4,5,6,7]))).renderTitleFrames(ft,g,ze,E);const Fe=new Map;if(L.some(r=>we(r)&&Ye(r))){const r=await Pt(()=>import("./titleFrames-BI1DnLBn.js"),__vite__mapDeps([0,1,2,3,4,5,6,7]));for(const f of L.filter(U=>we(U)&&Ye(U)))Fe.set(f.id,r.liveMotion(f,L,g))}L.some(r=>r.kind==="model")&&await(await Pt(async()=>{const{render3DFrames:r}=await import("./timeline3dExport-BtYLU1pw.js");return{render3DFrames:r}},__vite__mapDeps([8,1,9,10,11,6,12,7]))).render3DFrames(p.filter(r=>!r.disabled),g,ze,E,G);for(const r of O.filter(f=>f._group&&f.comp)){const f=[],U=Math.max(1,Math.ceil(r.duration*C-1e-6));await ga(ri(ii(r),{W:y,H:_}),{format:g,signal:E,frames:{times:Array.from({length:U},(x,T)=>oi(r,T/C)),push:(x,T)=>{f[x]=T}}}),ze.frames.set(r.id,f)}const lt=performance.now();Oe(),Ne="mattes";const We=L.filter(r=>r.mask||r.person),ye=We.length?await Pt(()=>import("./rotoMatte-C-2o3vv0.js").then(r=>r.r),__vite__mapDeps([13,1,6,14])):null;ye&&await ye.prepareMattes(We);const Ge=ye?document.createElement("canvas"):null;Ne="media";const Ke=new Map,Ae=new Map,Le=new Map,rt=r=>{let f=Ke.get(r);return f||(f=new gi({source:new wi(r,{getRetryDelay:Po}),formats:Ti}),Ke.set(r,f)),f};for(const r of L){if(r.kind==="video"&&!Ae.has(r.url)){const f=await rt(r.url).getPrimaryVideoTrack();f&&Ae.set(r.url,new Ei(f))}if(r.kind==="image"&&!Ht(r)&&!Zt(r)&&!r._group&&!Le.has(r.url)){const f=await createImageBitmap(await Ui(r.url,E),{imageOrientation:"from-image",premultiplyAlpha:"none",colorSpaceConversion:"none"});Le.set(r.url,{source:f,w:f.width,h:f.height,close:()=>f.close()})}}const J=new Map,Ee=async(r,f)=>{const U=Fe.get(r.id);if(U)return{source:await U.frame(Math.round((f-r.start)*C)),w:U.W,h:U.H};const x=ze.frames.get(r.id);if(!x?.length)return null;let T=x.length===1?0:Math.max(0,Math.min(Math.round((f-r.start)*C),Math.ceil(r.duration*C)-1,x.length-1));for(;T>0&&x[T]==="=";)T--;const X=J.get(r.id);if(X&&X.index===T)return X.pic;X?.pic?.close?.();const P=await createImageBitmap(await(await fetch(`data:image/webp;base64,${x[T]}`)).blob(),{premultiplyAlpha:"none",colorSpaceConversion:"none"}),ce={source:P,w:P.width,h:P.height,close:()=>P.close()};return J.set(r.id,{index:T,pic:ce}),ce},ut=L.filter(r=>$o(r)),qe=ut.length?await Pt(()=>import("./captionLayout-DvDPTwO9.js"),__vite__mapDeps([15,1])):null,De=new Map,it=new Map;if(qe){for(const r of new Set(ut.flatMap(f=>[Qt(jo(f.captionStyle).font),Qt(fo(f.captionStyle).font)])))if(await qe.captionFontReady(r.id),!De.has(r.id)){const f=new Uint8Array(await(await fetch(`/fonts/${r.file}`,{signal:E})).arrayBuffer());let U="";for(let x=0;x<f.length;x+=32768)U+=String.fromCharCode(...f.subarray(x,x+32768));De.set(r.id,`@font-face{font-family:'${r.family}';src:url(data:font/${r.file.endsWith(".otf")?"otf":"ttf"};base64,${btoa(U)})}`)}}const $e=new Map,F=async(r,f,U)=>{let x=$e.get(f.start);if(!x||x.owner!==r){const S=fr(r,f.start,f.duration);x={plan:S,starts:lr(S.entries,C),owner:r},$e.clear(),$e.set(f.start,x)}const T=U-Math.round(f.start*C);let X=-1;for(let S=0;S<x.starts.length&&x.starts[S]<=T;S++)X=S;const P=x.plan.entries[X];if(!P||P.blank)return null;const ce=x.plan.social?x.plan.social.style:fo(r.captionStyle),W=x.plan.social?ur(x.plan.social,P.gi,y,_,qe.measureCaption):mr({width:y,height:_,text:P.text,style:ce,measure:qe.measureCaption,second:P.second}),Z=pr(W,ce,x.plan.social?P.scale:1,y,_,P.active,P.motion);let a=it.get(Z);if(!a){const S=Qt(ce.font),fe=URL.createObjectURL(new Blob([Z.replace("<defs>",`<defs><style>${De.get(S.id)??""}</style>`)],{type:"image/svg+xml"}));try{const ve=new Image(y,_);ve.src=fe,await ve.decode();const ne=await createImageBitmap(ve,{premultiplyAlpha:"none"});a={source:ne,w:y,h:_,close:()=>ne.close()}}finally{URL.revokeObjectURL(fe)}if(it.size>64){const[ve,ne]=it.entries().next().value;ne.close?.(),it.delete(ve)}it.set(Z,a)}return a},pe=[0,0,1,1],mt=new Map,wt=["x","y","zoom","rot","sx","sy"],je=(r,f,U,x)=>{const T=`${r.id}@${f.start}`;let X=mt.get(T);if(!X){const ce=Math.max(1,Math.ceil(f.duration/.1-1e-6)),W=Array.from({length:ce+1},(S,fe)=>f.start+f.duration*fe/ce),Z=W.map(S=>Jt(r,S-r.start,y,_)),a=S=>+(+S).toFixed(3);X={ts:W.map(S=>+S.toFixed(5)),v:Object.fromEntries(wt.map(S=>[S,Z.map(fe=>a(fe[S]??(S==="sx"||S==="sy"?1:0)))]))},mt.set(T,X)}const P={...x};for(const ce of wt){const W=X.v[ce];if(W.every(fe=>fe===W[0])){P[ce]=W[0];continue}let Z=X.ts.findIndex((fe,ve)=>ve<X.ts.length-1&&U<X.ts[ve+1]);Z<0&&(Z=X.ts.length-2);const a=+(W[Z+1]-W[Z]).toFixed(3),S=X.ts[Z+1]-X.ts[Z];P[ce]=Math.abs(W[Z+1]-W[Z])<1e-4?W[Z]:W[Z]+a*Math.max(0,Math.min(1,(U-X.ts[Z])/S))}return P},at=new Map,pt=new Map,Ie=(r,f,U,x=r,T="")=>{if(!dr(x))return yo(x,y);const X=`${r.id}${T}@${f.start}`;let P=pt.get(X);P||(P=xr(x,{offset:f.start-r.start,duration:f.duration,fps:C}),pt.set(X,P));const ce=U-Math.round(f.start*C),W=P.find(Z=>ce>=Z.from&&ce<Z.to)??P[P.length-1];return yo({effects:vr(x,W.t)},y)},yt=new Map,Xt=(r,f,U)=>{const x=`${r.id}@${f.start}`;yt.has(x)||yt.set(x,z?Dr(r,z,f.start,f.duration,y,_):null);const T=yt.get(x);return T?Ie(r,f,U,T,":dof"):[]},ke=new Map,Yt=r=>{const f=JSON.stringify(r.grade);let U=ke.get(f);if(!U){const x=P=>Array.from(P,ce=>+ce.toFixed(6)),T=gr(r.grade)?Tr(r.grade):null,X=r.grade.mixer&&wr(r.grade.mixer)?yr(r.grade.mixer):null;U={l1:T?{key:`1${f}`,r:x(T.r),g:x(T.g),b:x(T.b)}:null,l3:X?{key:`3${f}`,size:X.size,data:Float32Array.from(X.data,P=>+P.toFixed(6))}:null},ke.set(f,U)}return U};let Ce=null;const Rt=async(r,f,U)=>{const x=L.find(P=>P.id===r);if(!x||f<x.start||f>=x.start+x.duration)return null;if(Ht(x)){const P=await Ee(x,f);return P&&{source:P.source,w:P.w,h:P.h}}if(x.kind==="image"){const P=Le.get(x.url);return P?{source:P.source,w:P.w,h:P.h}:null}if(x.kind!=="video")return null;const T=await _o(Me,Ae,x,f,C,Math.max(U.start,x.start),U.duration);if(!T)return null;const X=T.toVideoFrame();return{source:X,w:T.displayWidth,h:T.displayHeight,close:()=>X.close()}};Ne="output";const k=ba(y,_),He=io(w,{width:y,height:_,fps:C},ro),nt=w?.codec==="hevc",St=w?.container==="mov",Qe=!A&&!de&&te*He/8>15e7&&!!navigator.storage?.getDirectory;let Xe=null,Ue;if(Qe){const r=await navigator.storage.getDirectory(),f=`gpu-export-${crypto.randomUUID()}.${St?"mov":"mp4"}`,U=await r.getFileHandle(f,{create:!0});Xe={dir:r,handle:U,name:f},Ue=new Ro(await U.createWritable(),{chunked:!0,chunkSize:1<<20})}else Ue=de&&!A?new Ro(de,{chunked:!0,chunkSize:1<<22}):new Ri;const Ve=de&&!A?!1:Qe?"reserve":"in-memory",Je=new _i({format:St?new Fi({fastStart:Ve}):new Ai({fastStart:Ve}),target:Ue}),_t=new Mi(k.canvas,{codec:nt?"hevc":"avc",bitrate:He,keyFrameInterval:2,...nt?{hardwareAcceleration:"prefer-hardware"}:Y?{hardwareAcceleration:"prefer-software"}:{}}),Ze=me==="audio"?0:Math.max(0,Math.min(oe,ae?.from??0)),Ft=me==="audio"?0:Math.max(Ze,Math.min(oe,ae?.to??oe));me!=="audio"&&Je.addVideoTrack(_t,{frameRate:C,...Qe?{maximumPacketCount:Ft-Ze+8}:{}});const Dt=new Si({codec:"aac",bitrate:Uo});me!=="video"&&Je.addAudioTrack(Dt,Qe?{maximumPacketCount:Math.ceil(te*Ct/1024)+16}:{}),A||await Je.start();const Ot=A?new OffscreenCanvas(y,_):null,zt=Ot?.getContext("2d"),Wt=async r=>{zt.putImageData(new ImageData(k.pixels(),y,_),0,0);const f=new Uint8Array(await(await Ot.convertToBlob({type:"image/webp",quality:.9})).arrayBuffer());let U="";for(let x=0;x<f.length;x+=32768)U+=String.fromCharCode(...f.subarray(x,x+32768));A.push(r,btoa(U))},Me=new Map;let ue=0;const j={decode:0,matte:0,titles:0,captions:0,encode:0},st=async(r,f)=>{const U=performance.now();try{return await f}finally{j[r]+=performance.now()-U}},At=(r,f)=>{const U=performance.now();try{return f()}finally{j[r]+=performance.now()-U}};try{for(let f=A?0:Ze,U=A?A.times.length:Ft;f<U;f++){Oe(),Ne="frame";const x=A?A.times[f]:f/C,T=Te(x);k.clear(A?0:1);const X=T&&qe?Ho(L,T.start+1e-5,e):void 0,P=X&&T?Vo(T.visuals,X.captionStyle?.layerTrack):-1,ce=async()=>{const W=X&&T&&await st("captions",F(X,T,f));W&&(k.shadow([]),k.edge(null),k.windows(null),k.matte(null),k.mode(void 0),k.key(null),k.grade(null,null),k.draw(W,pe,pe,1,1,!1,null,[]))};for(const[W,Z]of(T?.visuals??[]).entries()){let a=Z;if(W===P&&await ce(),a.kind==="audio")continue;const S=T?lo(a,T.start,T.start+T.duration):null,fe=S?a._txIn===S?"b":"a":null,ve=S?Yo(S,x):0;e:{if(a.kind==="model"){k.matte(null),k.edge(null),k.windows(null),k.mode(void 0),k.shadow(uo(a,y)),k.key(null),k.grade(null,null);const m=await Ee(a,x);m&&k.draw(m,pe,pe,1,1,!1,null,[]);break e}const ne=x-a.start,Re=Jt(a,ne,y,_),se=(Wo(a)||Ko(a))&&!S&&!(z&&$t(a))&&!a.pin?je(a,T,x,Re):Re;if(!(se.opacity>1e-4))break e;if(Zt(a)){k.adjust(ot(a),Ie(a,T,f),Math.min(1,se.opacity));break e}let B=null,Pe=null;if(Ht(a)||a._group)B=await st("titles",Ee(a,x));else if(a.kind==="image")B=Le.get(a.url)??null;else if(a.kind==="video"){const m=await st("decode",_o(Me,Ae,a,x,C,T.start,T.duration));m&&(Pe=m.toVideoFrame(),B={source:Pe,w:m.displayWidth,h:m.displayHeight,bt709:Pe.colorSpace?.matrix?Pe.colorSpace.matrix==="bt709":m.displayHeight>=720})}if(!B)break e;if(Qo(a)){const m=a.crop||{left:0,right:0,top:0,bottom:0},t=Math.floor(B.w*m.left/2)*2,c=Math.floor(B.h*m.top/2)*2,u=Math.max(2,Math.floor(B.w*(1-m.left-m.right)/2)*2),h=Math.max(2,Math.floor(B.h*(1-m.top-m.bottom)/2)*2),i=a.distort.displace?await Rt(a.distort.displace.map,x,T):null;Ce??=hi();const v=Ce.render({source:B.source,srcW:B.w,srcH:B.h,rect:[t,c,u,h],outW:u,outH:h,distort:a.distort,local:ne,map:i?.source??null,matte:ye&&(a.mask||a.person)?ye.matteCanvas(a,ne,Ge,!1,L):null});i?.close?.(),B={source:v,w:u,h,bt709:B.bt709},a={...a,crop:void 0,mask:void 0,person:void 0}}if(ye&&(a.mask||a.person)){const m=a.crop||{left:0,right:0,top:0,bottom:0},t=Math.max(2,Math.floor(B.w*(1-m.left-m.right)/2)*2),c=Math.max(2,Math.floor(B.h*(1-m.top-m.bottom)/2)*2);k.matte(At("matte",()=>ye.matteCanvas(a,ne,Ge,!1,L)),[m.left,m.top,t/B.w,c/B.h])}else k.matte(null);k.mode(a.blend),k.key(a.key),k.shadow(uo(a,y));{const m=a.colorBypass?[]:qt(a.grade).filter(eo);k.windows(m.length?{key:`${a.id}@${f}`,list:qt(a.grade),clip:a.id,src:a,frame:Math.round((x-a.start)*C),local:Math.round((x-a.start)*C)/C}:null)}if(mo(a)&&po(xo(a),ne)>.001){const m=xo(a),t=ye&&(a.mask||a.person),c=a.crop||{left:0,right:0,top:0,bottom:0},u=t?Math.max(2,Math.floor(t.mw*(1-c.left-c.right)/2)*2):B.w,h=t?Math.max(2,Math.floor(t.mh*(1-c.top-c.bottom)/2)*2):B.h,i=u>=h?jt:Math.max(8,Math.trunc(jt*u/h/8)*8),v=u>=h?Math.max(8,Math.trunc(jt*h/u/8)*8):jt,M=Jo(m),Q=po(m,ne),K=!!m.keys?.length||m.amount<.999;k.edge({key:`${a.id}@${f}`,ew:i,eh:v,band:M.band,glow:M.glow,k:m.glow,col:[1,3,5].map(V=>parseInt(m.color.slice(V,V+2),16)/255),am:K?Math.trunc(255*Q):255,harden:!!t,arc:m.cover>=.999&&!m.comet?null:{cen:t?Zo(a):[.5,.5],start:(m.angle+m.sweep*ne)*Math.PI/180,cover:m.cover,comet:!!m.comet}})}else k.edge(null);{const m=a.grade&&!a.colorBypass?Yt(a):null;k.grade(m?.l1??null,m?.l3??null)}if(a.pin&&!(z&&$t(a))&&T&&vo(a,L,T.start,y,_,z)){const m=vo(a,L,x,y,_,z)??[[0,0],[0,0],[0,0],[0,0]],t=Bt(a,ne),c=er(a,L,y,_,z),u=a.pin.dive,h=c&&!a.pin.scene?[+(c[0]*y).toFixed(3),+(c[1]*_).toFixed(3),u?Math.max(0,Math.min(1,(x-u.at)/u.dur)):0]:null;k.warp(B,Nt([0,0,1,1],y,_),wo(a,B.w,B.h),Math.min(1,se.opacity),t.k,t.white,ot(a),Ie(a,T,f),It(m,y,_),h),Pe?.close();break e}const kt=tr(a,"rot")||or(a),xt=()=>a.motionBlur?fi(x,C).map(m=>({...Jt(a,m-a.start,y,_),rot:se.rot,opacity:se.opacity})):[se];if((kt||Math.abs(se.rot||0)>1e-9)&&!(z&&$t(a))){const m=Bt(a,ne),t=S&&fe?[...Ao(S.spec[fe],ve,y,_,x,S.spec.zoomAt),...fe==="b"&&S.spec.mask?[Fo(S.spec.mask,ve)]:[]]:[];a.motionBlur&&k.blurBegin();for(const c of xt()){const u=ai(a,B.w,B.h,y,_,c,kt);k.warp(B,Nt([0,0,1,1],y,_),wo(a,B.w,B.h),Math.min(1,se.opacity),m.k,m.white,ot(a),[],It(u.quad,y,_),null,u.clip,t)}a.motionBlur&&k.blurEnd(),Pe?.close();break e}if(z&&$t(a)){const m=rr(a,ne,z,x,y,_);if(m){const t=Lt(a,B.w,B.h,y,_,{x:0,y:0,zoom:1}),c=Bt(a,ne),u=Ie(a,T,f);let h=at.get(a.id);h===void 0&&(h=a.effects?.some(v=>!v.off)||a.mask||a.person||mo(a)||!a.colorBypass&&qt(a.grade).some(eo)?1:ir(ar(a,z,y,_),B.w,B.h,y,_),at.set(a.id,h));const i=Xt(a,T,f);h>1&&!u.length?k.warpBig(B,Nt(t.dst,y,_),t.src,Math.min(1,se.opacity),c.k,c.white,ot(a),m.quad,h,i):k.warp(B,Nt(t.dst,y,_),t.src,Math.min(1,se.opacity),c.k,c.white,ot(a),u,It(m.quad,y,_),null,null,i)}Pe?.close();break e}if(a.motionBlur&&!S&&!Ie(a,T,f).length){const m=Bt(a,ne);k.blurBegin();for(const t of xt()){const c=Lt(a,B.w,B.h,y,_,t);k.draw(B,c.dst,c.src,Math.min(1,se.opacity),m.k,m.white,ot(a),[])}k.blurEnd(),Pe?.close();break e}const{dst:vt,src:n}=Lt(a,B.w,B.h,y,_,se),s=Bt(a,ne),o=[...Ie(a,T,f),...S&&fe?Ao(S.spec[fe],ve,y,_,x,S.spec.zoomAt):[],...S&&fe==="b"&&S.spec.mask?[Fo(S.spec.mask,ve)]:[]],l=S&&fe?S.spec[fe]?.rot:null;if(l){const m=Vt(l,ve)??0;k.warp(B,Nt([0,0,1,1],y,_),n,Math.min(1,se.opacity),s.k,s.white,ot(a),[],It(ni(vt,y,_,m),y,_),null,null,o),Pe?.close();break e}if(o.length>0&&!!T&&!a.layout&&!lo(a,T.start,T.start+T.duration)&&nr(a,T.start,T.start+T.duration,y,_)){const m=Lt(a,B.w,B.h,y,_,{x:0,y:0,zoom:1}),t=Lt({},y,_,y,_,se);k.draw(B,t.dst,m.src,Math.min(1,se.opacity),s.k,s.white,ot(a),o,m.dst)}else k.draw(B,vt,n,Math.min(1,se.opacity),s.k,s.white,ot(a),o);Pe?.close()}if(S&&fe==="b"){if(S.spec.light){const Re=Math.max(2,Math.ceil(y/ho)),se=Math.max(2,Math.ceil(_/ho));k.overlay(null,{data:sr(S.spec,ve,Re,se),w:Re,h:se})}const ne=S.spec.flash;if(ne){const Re=Vt(ne.opacity,ve)??0;if(Re>1e-4){const se=parseInt(ne.color.slice(1),16);k.overlay([(se>>16&255)/255,(se>>8&255)/255,(se&255)/255,Math.min(1,Re)],null)}}}}P>=0&&P>=(T?.visuals.length??0)&&await ce();for(const[W,Z]of Me){const a=W.split(`
198
+ `)[0],S=O.find(fe=>fe.id===a);(!S||x>S.start+S.duration+1)&&(Z.current?.close(),Z.peek?.close(),await Z.iterator.return?.(),Me.delete(W))}if(A){await Wt(f);continue}Ne="video encode",await st("encode",_t.add((f-Ze)/C,1/C)),N?.((me==="video"?1:.9)*(f+1-Ze)/Math.max(1,Ft-Ze))}if(A)return{blob:new Blob,ms:{titles:0,video:0,audio:0,total:Math.round(performance.now()-d)}};const r=performance.now();if(me==="video")_t.close(),Ne="finalize",await Je.finalize();else{Ne="audio";const f=new Map(O.map(x=>[x.id,x])),U=await wa(L.map(x=>f.get(x.id)??x),_e,te,e,rt,E);typeof g.loudness=="number"&&si([U.getChannelData(0),U.getChannelData(1)],g.loudness,Ct),Ne="audio encode",await Dt.add(U),ue=performance.now()-r,me!=="audio"&&_t.close(),Dt.close(),Ne="finalize",await Je.finalize()}}catch(r){throw await Je.cancel().catch(()=>{}),Xe&&await Xe.dir.removeEntry(Xe.name).catch(()=>{}),r}finally{for(const r of Me.values())r.current?.close(),r.peek?.close();Ce?.dispose();for(const r of Le.values())r.close?.();for(const r of J.values())r.pic?.close?.();for(const r of Fe.values())r.close();for(const r of it.values())r.close?.();for(const r of Ke.values())r.dispose?.()}N?.(1),Ne="file";const dt=Xe?await Xe.handle.getFile():de?new Blob([]):new Blob([Ue.buffer],{type:St?"video/quicktime":"video/mp4"});Xe&&setTimeout(()=>void Xe.dir.removeEntry(Xe.name).catch(()=>{}),600*1e3);const ct=performance.now()-d;return{blob:dt,ms:{titles:Math.round(lt-d),video:Math.round(ct-(lt-d)-ue),audio:Math.round(ue),total:Math.round(ct),parts:Object.fromEntries(Object.entries(j).map(([r,f])=>[r,Math.round(f)]))}}}function Ta(p,g,w,e,G){const E=[new Float32Array(Math.max(1,Math.round(G*w))),new Float32Array(Math.max(1,Math.round(G*w)))],N=Math.round(Lr*w);return g.forEach((A,Y)=>{if(A.silent)return;const re=Math.round((A.t1-A.t0)*w)+(Y<g.length-1?N:0),ae=Math.abs(A.rate),me=Math.round(A.t0*w),de=Math.max(0,Math.round(((A.rate>0?A.s0:A.s0-ae*re/w)-e)*w)),d=Math.min(p[0].length,Math.round(((A.rate>0?A.s0+ae*re/w:A.s0)-e)*w));if(d-de<2)return;const y=(d-de)/re,_=Math.round(.06*w),C=Math.max(0,de-_),L=Math.min(p[0].length,d+_);let O=p.map(oe=>oe.slice(C,L));A.rate<0&&O.forEach(oe=>oe.reverse());const te=Math.round((A.rate<0?L-d:de-C)/y);O=ko(O,y,w).map(oe=>oe.subarray(te,te+re));for(let oe=0;oe<2;oe++)for(let z=0;z<re&&me+z<E[oe].length;z++){const _e=(Y>0&&z<N?z/N:1)*(Y<g.length-1&&z>=re-N?(re-z)/N:1);E[oe][me+z]+=(O[oe][z]??0)*_e}}),E}async function wa(p,g,w,e,G,E){const N=new OfflineAudioContext({numberOfChannels:2,length:Math.max(1,Math.round(w*Ct)),sampleRate:Ct}),A=1/200,Y=p.filter(d=>(d.kind==="video"||d.kind==="audio")&&!d.freeze&&!Do(d)&&(d.volume??1)>0),re=d=>(d.kind==="video"||d.kind==="audio")&&!!d.url,ae=new Map;for(const d of g.flatMap(y=>y.audios))!re(d)||ae.has(d.url)||ae.set(d.url,await G(d.url).getPrimaryAudioTrack().then(y=>!!y,()=>!1));const me=d=>re(d)&&!!ae.get(d.url);for(const d of Y){if(E?.aborted)throw new DOMException("Export cancelled","AbortError");const y=Math.max(2,Math.ceil(d.duration/A)+1),_=new Float32Array(y);let C=!1;const L=kr(d.track,e);for(let J=0;J<y;J++){const Ee=d.start+Math.min(d.duration,J*A),ut=g.find(De=>Ee>=De.start-1e-6&&Ee<De.start+De.duration-1e-6),qe=ut?.audios.some(De=>De.id===d.id)?Ur(d,Ee-d.start)*L.gain/Pr(ut.audios,me):0;_[J]=qe,qe>0&&(C=!0)}if(!C)continue;const O=await G(d.url).getPrimaryAudioTrack();if(!O)continue;const te=So(d)?Br(d,0,d.duration):null,oe=d.playbackRate||1,z=new yi(O),_e=te?te.flatMap(J=>[J.s0,J.s1]):[],Te=te?Math.max(0,Math.min(..._e)-.2):d.inPoint||0,Oe=te?Math.max(..._e)+.2:Te+d.duration*oe,we=[];let Ye=Te;for await(const J of z.samples(Te,Oe))we.length||(Ye=J.timestamp),we.push(J.toAudioBuffer()),J.close();if(!we.length)continue;const ze=we[0].sampleRate,ft=we.reduce((J,Ee)=>J+Ee.length,0);let Fe=[new Float32Array(ft),new Float32Array(ft)],lt=0;for(const J of we){for(let Ee=0;Ee<2;Ee++)Fe[Ee].set(J.getChannelData(Math.min(Ee,J.numberOfChannels-1)),lt);lt+=J.length}te?Fe=Ta(Fe,te,ze,Ye,d.duration):oe!==1&&(Fe=ko(Fe,oe,ze));const We=N.createBuffer(2,Fe[0].length,ze);for(let J=0;J<2;J++)We.copyToChannel(Fe[J],J);const ye=N.createBufferSource();ye.buffer=We;const Ge=N.createGain();Ge.gain.value=0,Ge.gain.setValueCurveAtTime(_,d.start,Math.max(A,d.duration));const Ke=N.createChannelSplitter(2),Ae=N.createChannelMerger(2),Le=N.createGain(),rt=N.createGain();Le.gain.value=L.left,rt.gain.value=L.right,ye.connect(Ge),Ge.connect(Ke),Ke.connect(Le,0),Ke.connect(rt,1),Le.connect(Ae,0,0),rt.connect(Ae,0,1),Ae.connect(N.destination),ye.start(d.start,te?0:Math.max(0,Te-Ye)/oe,d.duration)}const de=await N.startRendering();return ci([de.getChannelData(0),de.getChannelData(1)]),de}export{Pa as canEncodeH264,Ba as canEncodeHevc,Ua as canEncodeMp4,ga as exportOnGpu,ro as gpuBitrate,La as gpuExportStage,Na as gpuExportSupported};