clipoox-render 0.4.5 → 0.4.7

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 (115) hide show
  1. package/package.json +1 -1
  2. package/scripts/render-local.mjs +1361 -990
  3. package/web/assets/{FxEmbed-DbfuM8Yo.js → FxEmbed-B-D-tbgP.js} +1 -1
  4. package/web/assets/{MotionEmbed-CBQ-8Tzh.js → MotionEmbed-eB-zRpv9.js} +1 -1
  5. package/web/assets/{PluginStore-OOEx0lP5.js → PluginStore-D6UvvVXA.js} +1 -1
  6. package/web/assets/{ShotComposer-Cng515xa.js → ShotComposer-CoxtWL6A.js} +8 -8
  7. package/web/assets/{TemplateEmbed-hjwM2b0o.js → TemplateEmbed-DZNaQAJ-.js} +1 -1
  8. package/web/assets/{TimelinePlugins-D-NakABP.js → TimelinePlugins-zhB9Uqav.js} +3 -3
  9. package/web/assets/{TimelineShotFx-D3kGhHN3.js → TimelineShotFx-muTN__gf.js} +2 -2
  10. package/web/assets/{TransitionEmbed-DR26yI3a.js → TransitionEmbed-r_B0toRr.js} +1 -1
  11. package/web/assets/{Whiteboard-BhxY0D0Z.js → Whiteboard-f6owS-ne.js} +1 -1
  12. package/web/assets/{aerial-BisYSXzG.js → aerial-DIj143Yz.js} +2 -2
  13. package/web/assets/{agentTools-CPFQeiDP.js → agentTools-CoNs1wCQ.js} +2 -2
  14. package/web/assets/{aiInbetween-AOOM1e6p.js → aiInbetween-ZFNHEXdI.js} +2 -2
  15. package/web/assets/{analyzerRun-Dtp2o7gT.js → analyzerRun-BswbLsRF.js} +1 -1
  16. package/web/assets/{analyzerSandbox-BG_3Cea1.js → analyzerSandbox-C2rd6s8U.js} +1 -1
  17. package/web/assets/{api-BFN7blbw.js → api-DJC95K48.js} +3 -3
  18. package/web/assets/auraTrack-C9diszRB.js +1 -0
  19. package/web/assets/{breakthrough-0qFpZW-V.js → breakthrough-DiHiElqL.js} +2 -2
  20. package/web/assets/{cameraPresets-eK3mP7qb.js → cameraPresets-DfKERP1j.js} +1 -1
  21. package/web/assets/{cameraTracker-BAQHuTV-.js → cameraTracker-DFjnZ7tw.js} +5 -5
  22. package/web/assets/{captionLayout-CWPcbid-.js → captionLayout-CAuhUiW9.js} +1 -1
  23. package/web/assets/{clientExport-DvpTTndR.js → clientExport-DyqpYM6h.js} +1 -1
  24. package/web/assets/{clientJobs-CIrYTMpn.js → clientJobs-BqkjV5Ld.js} +2 -2
  25. package/web/assets/{depthEstimate-B7D7cGCl.js → depthEstimate-HrGq0Ffx.js} +1 -1
  26. package/web/assets/{directorTools-CJD4Huqk.js → directorTools-CLn4xt6m.js} +1 -1
  27. package/web/assets/{distortFrames-BLt1icUb.js → distortFrames-D-DK2HlN.js} +2 -2
  28. package/web/assets/{distortGL-BA5molk-.js → distortGL-waTJhiOf.js} +1 -1
  29. package/web/assets/domino-BDKBYrNQ.js +1 -0
  30. package/web/assets/{editTools-NKLsWZD1.js → editTools-BqKU-ucA.js} +1 -1
  31. package/web/assets/{engine-DioUF2mX.js → engine-B2YPWQZ2.js} +1 -1
  32. package/web/assets/{exportGlb-BOdI9cVS.js → exportGlb-Cm07JQXt.js} +1 -1
  33. package/web/assets/{faceTracker-D7CbF-qX.js → faceTracker-DsmLlUZ1.js} +1 -1
  34. package/web/assets/fightDirector-BIVLGhAP.js +1 -0
  35. package/web/assets/{fightDrama-DIPcRKnc.js → fightDrama-B_jDQ-cW.js} +2 -2
  36. package/web/assets/{focusTool-vfabPqQ5.js → focusTool-mWs2Eikj.js} +1 -1
  37. package/web/assets/{frameSink-DYs2gTzq.js → frameSink-DWkHUnvV.js} +3 -3
  38. package/web/assets/{glTransitionSources.generated-DM5sRMX2.js → glTransitionSources.generated-BJuEUz3E.js} +2 -2
  39. package/web/assets/{gpuCompose-DbnZuelB.js → gpuCompose-Fi0sIUI9.js} +1 -1
  40. package/web/assets/{gpuExport-CQ7ZhpsX.js → gpuExport-Dlf6YjLs.js} +7 -7
  41. package/web/assets/{handMatte-DIbMuqCu.js → handMatte-CvFkZKTL.js} +1 -1
  42. package/web/assets/handTracker-CF1hqh09.js +2 -0
  43. package/web/assets/i18n-C9zFX25m.js +3 -0
  44. package/web/assets/{index-BfrDwjDI.js → index-EegUntr6.js} +1 -1
  45. package/web/assets/{layer-worker-DK67WH1a.js → layer-worker-Drj-NLVj.js} +3 -3
  46. package/web/assets/library-BhH-xsMR.js +1 -0
  47. package/web/assets/{lottieLayer-C2YbiXhK.js → lottieLayer-Dp_vGTy8.js} +1 -1
  48. package/web/assets/{main-B27kf5aL.css → main-B_MAOvi6.css} +1 -1
  49. package/web/assets/{main-BKatDoGw.js → main-DAk1Tv1E.js} +104 -104
  50. package/web/assets/{mapBake-C-G7WpFM.js → mapBake-CEmw-e9Y.js} +1 -1
  51. package/web/assets/{maskTrack-LMrwm5ub.js → maskTrack-CADMBJDf.js} +1 -1
  52. package/web/assets/{matteFixRun-B38CbeEt.js → matteFixRun-BHD3Qnta.js} +1 -1
  53. package/web/assets/{objectLocate-CKi3OTnL.js → objectLocate-DWsEG8eK.js} +1 -1
  54. package/web/assets/{objectSegmenter-CziPuM61.js → objectSegmenter-oGv8YQbI.js} +1 -1
  55. package/web/assets/{objectTrack.worker-b7DJ-ub6.js → objectTrack.worker-B6RVfsq4.js} +925 -554
  56. package/web/assets/{pathTracer-bqau16sX.js → pathTracer-DxqKEvC7.js} +2 -2
  57. package/web/assets/{pendingMatte-CQb7jPg1.js → pendingMatte-Taa0BlLI.js} +2 -2
  58. package/web/assets/{personAi-CQntGDqK.js → personAi-BebqXrqD.js} +2 -2
  59. package/web/assets/{personHq-B1c0QVJT.js → personHq-Cyq9HWnW.js} +2 -2
  60. package/web/assets/{plateCamera-D7iLiNBy.js → plateCamera-D1A1iEpf.js} +1 -1
  61. package/web/assets/{plateCameraMatch-BM88dx-a.js → plateCameraMatch-1_DuZ0LV.js} +2 -2
  62. package/web/assets/{plateFollow-4iGUDTu1.js → plateFollow-Ztxwpq5v.js} +2 -2
  63. package/web/assets/{plateMatte-zTyuHHqh.js → plateMatte-CWT1ymGj.js} +2 -2
  64. package/web/assets/{pluginAutomation-DSg-sYLF.js → pluginAutomation-D73Az7HS.js} +1 -1
  65. package/web/assets/{poseTracker-DZl8l2qS.js → poseTracker-b1h08oRY.js} +1 -1
  66. package/web/assets/{productTools-B-jh8ukh.js → productTools-CoJ_Fnfc.js} +2 -2
  67. package/web/assets/remote-kxNNhmis.js +974 -0
  68. package/web/assets/{rigTrack-XaMj1yaH.js → rigTrack-B9r9wrdV.js} +1 -1
  69. package/web/assets/{rotoMaskStore-DdpmT9C3.js → rotoMaskStore-RmW40Pcn.js} +1 -1
  70. package/web/assets/{rotoMatte-i-cJTYmK.js → rotoMatte-DisQplSv.js} +1 -1
  71. package/web/assets/{rotoscope-DqRSWmHR.js → rotoscope-Z8bn-jRs.js} +1 -1
  72. package/web/assets/{sceneTrack-DIPzBmMK.js → sceneTrack-BKknn180.js} +1 -1
  73. package/web/assets/{sceneTrack-Bbov7zET.js → sceneTrack-DyVxpl7i.js} +1 -1
  74. package/web/assets/{sceneTrack.worker-Bav9h0pv.js → sceneTrack.worker-DKVLLgf9.js} +925 -554
  75. package/web/assets/{shot-worker-m-q77W9f.js → shot-worker-DM5PUQ6g.js} +1 -1
  76. package/web/assets/{shotFxAgent-DIMS7BGA.js → shotFxAgent-CsW0MAiG.js} +1 -1
  77. package/web/assets/{skin-DrUzJE1u.js → skin-CXvqtCZI.js} +1 -1
  78. package/web/assets/{spark.module-Y1SEI8Xz.js → spark.module-B341moK0.js} +1 -1
  79. package/web/assets/{spellDuel-DNnyQDVr.js → spellDuel-KCMEFHLA.js} +2 -2
  80. package/web/assets/{store-GFMJzaWS.js → store-xR02oY0m.js} +1 -1
  81. package/web/assets/{surfaceLight-C--moyc9.js → surfaceLight-DBfJxggM.js} +1 -1
  82. package/web/assets/{surfacePin-B4-1UqXD.js → surfacePin-i-X1Dz68.js} +2 -2
  83. package/web/assets/{textAnimators-BVXTl8bU.js → textAnimators-CeMuG34D.js} +1 -1
  84. package/web/assets/{thumb-CTfDJgLp.js → thumb-DzNl15MN.js} +1 -1
  85. package/web/assets/{timeline3d-Dn7PqmEe.js → timeline3d-D0Ws4lcp.js} +2 -2
  86. package/web/assets/{timeline3dExport-DCOr6ARB.js → timeline3dExport-BO--SpAn.js} +1 -1
  87. package/web/assets/{timelineComp-Dx_kED5V.js → timelineComp-D8PHGHgQ.js} +1 -1
  88. package/web/assets/timelineOps-CEGk2t4h.js +525 -0
  89. package/web/assets/{timelineProps-eYgO6gs5.js → timelineProps-Cm_Irino.js} +1 -1
  90. package/web/assets/{timelineText-RKyRP988.js → timelineText-DjPW2-dd.js} +1 -1
  91. package/web/assets/{titleArt-CUtA0C3I.js → titleArt-BSu80bfN.js} +3 -3
  92. package/web/assets/{titleFrameBudget-X7HLSDre.js → titleFrameBudget-BW-N1-cw.js} +1195 -824
  93. package/web/assets/{titleFrames-aMG7HdVe.js → titleFrames-BHFaInux.js} +1 -1
  94. package/web/assets/{tool-DpFjybaq.js → tool-Bboi3NDg.js} +1 -1
  95. package/web/assets/{tools-CeOU0p13.js → tools-kgYkohv8.js} +1 -1
  96. package/web/assets/toonTools-Bxz_HSqT.js +2 -0
  97. package/web/assets/{trackAnchor-hAOtEhKO.js → trackAnchor-DK9cEMCf.js} +1 -1
  98. package/web/assets/{userFonts-1kuRjWOo.js → userFonts-DSkZHfmh.js} +1 -1
  99. package/web/assets/{vfxAlpha-DxS5-QwY.js → vfxAlpha-B0rNpKZN.js} +1 -1
  100. package/web/assets/vfxBackground-CBTDl1xA.js +2 -0
  101. package/web/assets/{videoExport-Cg4B2Nyh.js → videoExport-Cu0vw-dL.js} +1 -1
  102. package/web/assets/{views-CUXyRb9x.js → views-CmulxRJP.js} +1 -1
  103. package/web/assets/{weaponDuel-nFECu9nk.js → weaponDuel-DuuMMfzY.js} +1 -1
  104. package/web/assets/{windowFrames-1wAkkWnv.js → windowFrames-BP2oDn-n.js} +1 -1
  105. package/web/layer-worker.html +3 -3
  106. package/web/shot-worker.html +23 -23
  107. package/web/assets/auraTrack-D_gxHNVe.js +0 -1
  108. package/web/assets/fightDirector-CYP8jxo8.js +0 -1
  109. package/web/assets/handTracker-DY_g5Xmg.js +0 -2
  110. package/web/assets/i18n-BJppIrtF.js +0 -3
  111. package/web/assets/library-B6KsZUKq.js +0 -1
  112. package/web/assets/remote-DJd9xWjn.js +0 -963
  113. package/web/assets/timelineOps-afzSo188.js +0 -525
  114. package/web/assets/toonTools-DLmo37Z_.js +0 -2
  115. package/web/assets/vfxBackground-CYpaQaTa.js +0 -2
@@ -1,12 +1,12 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/titleFrames-aMG7HdVe.js","assets/titleFrameBudget-X7HLSDre.js","assets/titleArt-CUtA0C3I.js","assets/textAnimators-BVXTl8bU.js","assets/lottieLayer-C2YbiXhK.js","assets/rigTrack-XaMj1yaH.js","assets/i18n-BJppIrtF.js","assets/index-CKtv7gGE.js","assets/api-BFN7blbw.js","assets/frameSink-DYs2gTzq.js","assets/timeline3dExport-DCOr6ARB.js","assets/timeline3d-Dn7PqmEe.js","assets/three.module-Bx43vjkH.js","assets/gltfLoader-U0Eebg7v.js","assets/RoomEnvironment-Dmv_G5ka.js","assets/rotoMatte-i-cJTYmK.js","assets/store-GFMJzaWS.js","assets/captionLayout-CWPcbid-.js"])))=>i.map(i=>d[i]);
2
- import{b_ as ao,U as Ht,eB as Go,ez as uo,cD as Uo,au as qo,eU as $o,iK as jo,iF as Ho,_ as Nt,i9 as oo,aq as Vo,iL as eo,aR as Yo,aP as mo,hR as Ko,hS as Wo,iM as po,e7 as Qo,eL as xo,ca as to,cc as Zo,fo as Jo,eV as Vt,eT as ei,W as io,er as vo,et as ho,es as go,cL as Yt,ev as ti,eR as oi,dE as Eo,iN as ii,cb as ri,eN as ai,fh as ni,eM as si,hL as ci,eb as Wt,iO as fi,el as bo,ej as li,hJ as ui,iP as mi,iQ as pi,iR as xi,b2 as di,aQ as vi,iS as hi,iT as gi,iU as Ei,bH as bi,aG as ko,iV as Ti,h as Po,iW as wi,iX as yi,d$ as Ri,e0 as _i,ai as Fi,iY as Ai,em as Mi,en as Si,eo as Di,eh as Ui,ep as ki,iZ as Pi,i_ as Bi,f2 as Li,cn as Ni,hV as Ii,i$ as Ci,hP as Xi,eq as To,j0 as Oi,V as zi,X as Gi,a0 as wo,j1 as yo,Y as Ro,an as qi,j2 as $i,e2 as ji,a2 as Hi,a3 as Vi,j3 as Yi,a4 as Ki,e1 as Wi,a5 as Qi,ab as Zi,aa as Ji,a8 as er,a6 as St,j4 as ro,ew as tr,j5 as or,e3 as ir,j6 as rr,j7 as ar}from"./titleFrameBudget-X7HLSDre.js";import{f as no,h as nr,G as sr,z as cr,L as fr,d as lr,c as ur,l as mr,b as pr}from"./glTransitionSources.generated-DM5sRMX2.js";import{b as xr,e as dr,a as vr}from"./timelineComp-Dx_kED5V.js";import{g as so,l as ot,f as It,p as Ct,s as _o,w as Ot,r as hr,a as Xt,t as gr,n as Er,b as Fo,c as Bo,d as br}from"./gpuCompose-DbnZuelB.js";import{t as Tr}from"./motionBlur-uAm030t9.js";import{c as wr}from"./distortGL-BA5molk-.js";import{c as co,V as yr,a as Rr,I as _r,A as Fr,U as Ar,b as Mr}from"./id3-arvEpAg7.js";import{S as Ao,B as Sr,O as Dr,M as Ur,a as kr,C as Pr,A as Br}from"./output-p-Q7qous.js";import"./api-BFN7blbw.js";import"./i18n-BJppIrtF.js";import"./index-CKtv7gGE.js";const Lr=m=>m.kind==="image"&&!!m.title?.text&&!m.url&&!oo(m)&&!Uo(m),Kt=m=>ui(m)||Lr(m),zt=48e3,Lo=192e3,Nr=4,No=(m,g)=>g?.name==="AbortError"||m>=Nr?null:Math.min(2**(m-1),4);async function Ir(m,g){for(let y=1;;y++){let e;try{e=await fetch(m,{signal:g})}catch(q){const h=g?.aborted?null:No(y,q);if(h===null)throw q;await new Promise(L=>setTimeout(L,h*1e3));continue}if(!e.ok)throw Error(`media ${e.status}`);return e.blob()}}const Io=()=>Rr("aac",{numberOfChannels:2,sampleRate:zt,bitrate:Lo}).catch(()=>!1),Xa=async(m,g)=>await co("avc",{width:m,height:g}).catch(()=>!1)&&Io();async function Oa(m){try{const{width:g,height:y,fps:e}=ao(m);return typeof VideoEncoder>"u"||!new OffscreenCanvas(2,2).getContext("webgl2")?!1:(await VideoEncoder.isConfigSupported({codec:"avc1.640034",width:g,height:y,bitrate:no(null,{width:g,height:y,fps:e},so),framerate:e,hardwareAcceleration:"prefer-software"})).supported===!0}catch{return!1}}const za=(m,g)=>co("hevc",{width:m,height:g}).catch(()=>!1);async function Ga(m,g){try{const{width:y,height:e,fps:q}=ao(m),h=g?.codec==="hevc";return typeof VideoEncoder>"u"||typeof AudioEncoder>"u"||typeof OfflineAudioContext>"u"||!new OffscreenCanvas(2,2).getContext("webgl2")||!(await VideoEncoder.isConfigSupported({codec:h?"hvc1.1.6.L153.B0":"avc1.640034",width:y,height:e,bitrate:no(g,{width:y,height:e,fps:q},so),framerate:q,hardwareAcceleration:"prefer-hardware"})).supported?!1:await co(h?"hevc":"avc",{width:y,height:e})&&await Io()}catch{return!1}}class Cr{frames=new Map;async push(g,y,e){let q=this.frames.get(y);q||(q=[],this.frames.set(y,q)),q.push(e)}}async function Mo(m,g,y,e,q,h,L){const M=g.get(y.url);if(!M)return null;if(ko(y)&&!y._still){const C=`${y.id}
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/titleFrames-BHFaInux.js","assets/titleFrameBudget-BW-N1-cw.js","assets/titleArt-BSu80bfN.js","assets/textAnimators-CeMuG34D.js","assets/lottieLayer-Dp_vGTy8.js","assets/rigTrack-B9r9wrdV.js","assets/i18n-C9zFX25m.js","assets/index-CKtv7gGE.js","assets/api-DJC95K48.js","assets/frameSink-DWkHUnvV.js","assets/timeline3dExport-BO--SpAn.js","assets/timeline3d-D0Ws4lcp.js","assets/three.module-Bx43vjkH.js","assets/gltfLoader-U0Eebg7v.js","assets/RoomEnvironment-Dmv_G5ka.js","assets/rotoMatte-DisQplSv.js","assets/store-xR02oY0m.js","assets/captionLayout-CAuhUiW9.js"])))=>i.map(i=>d[i]);
2
+ import{b_ as ao,U as Ht,eB as Go,ez as uo,cD as Uo,au as qo,eU as jo,iK as $o,iF as Ho,_ as Nt,i9 as oo,aq as Vo,iL as eo,aR as Yo,aP as mo,hR as Ko,hS as Wo,iM as po,e7 as Qo,eL as xo,ca as to,cc as Zo,fo as Jo,eV as Vt,eT as ei,W as io,er as vo,et as ho,es as go,cL as Yt,ev as ti,eR as oi,dE as Eo,iN as ii,cb as ri,eN as ai,fh as ni,eM as si,hL as ci,eb as Wt,iO as fi,el as bo,ej as li,hJ as ui,iP as mi,iQ as pi,iR as xi,b2 as di,aQ as vi,iS as hi,iT as gi,iU as Ei,bH as bi,aG as ko,iV as Ti,h as Po,iW as wi,iX as yi,d$ as Ri,e0 as _i,ai as Fi,iY as Ai,em as Mi,en as Si,eo as Di,eh as Ui,ep as ki,iZ as Pi,i_ as Bi,f2 as Li,cn as Ni,hV as Ii,i$ as Ci,hP as Xi,eq as To,j0 as Oi,V as zi,X as Gi,a0 as wo,j1 as yo,Y as Ro,an as qi,j2 as ji,e2 as $i,a2 as Hi,a3 as Vi,j3 as Yi,a4 as Ki,e1 as Wi,a5 as Qi,ab as Zi,aa as Ji,a8 as er,a6 as St,j4 as ro,ew as tr,j5 as or,e3 as ir,j6 as rr,j7 as ar}from"./titleFrameBudget-BW-N1-cw.js";import{h as no,j as nr,G as sr,z as cr,L as fr,e as lr,d as ur,l as mr,c as pr}from"./glTransitionSources.generated-BJuEUz3E.js";import{b as xr,e as dr,a as vr}from"./timelineComp-D8PHGHgQ.js";import{g as so,l as ot,f as It,p as Ct,s as _o,w as Ot,r as hr,a as Xt,t as gr,n as Er,b as Fo,c as Bo,d as br}from"./gpuCompose-Fi0sIUI9.js";import{t as Tr}from"./motionBlur-uAm030t9.js";import{c as wr}from"./distortGL-waTJhiOf.js";import{c as co,V as yr,a as Rr,I as _r,A as Fr,U as Ar,b as Mr}from"./id3-arvEpAg7.js";import{S as Ao,B as Sr,O as Dr,M as Ur,a as kr,C as Pr,A as Br}from"./output-p-Q7qous.js";import"./api-DJC95K48.js";import"./i18n-C9zFX25m.js";import"./index-CKtv7gGE.js";const Lr=m=>m.kind==="image"&&!!m.title?.text&&!m.url&&!oo(m)&&!Uo(m),Kt=m=>ui(m)||Lr(m),zt=48e3,Lo=192e3,Nr=4,No=(m,g)=>g?.name==="AbortError"||m>=Nr?null:Math.min(2**(m-1),4);async function Ir(m,g){for(let y=1;;y++){let e;try{e=await fetch(m,{signal:g})}catch(q){const h=g?.aborted?null:No(y,q);if(h===null)throw q;await new Promise(L=>setTimeout(L,h*1e3));continue}if(!e.ok)throw Error(`media ${e.status}`);return e.blob()}}const Io=()=>Rr("aac",{numberOfChannels:2,sampleRate:zt,bitrate:Lo}).catch(()=>!1),Xa=async(m,g)=>await co("avc",{width:m,height:g}).catch(()=>!1)&&Io();async function Oa(m){try{const{width:g,height:y,fps:e}=ao(m);return typeof VideoEncoder>"u"||!new OffscreenCanvas(2,2).getContext("webgl2")?!1:(await VideoEncoder.isConfigSupported({codec:"avc1.640034",width:g,height:y,bitrate:no(null,{width:g,height:y,fps:e},so),framerate:e,hardwareAcceleration:"prefer-software"})).supported===!0}catch{return!1}}const za=(m,g)=>co("hevc",{width:m,height:g}).catch(()=>!1);async function Ga(m,g){try{const{width:y,height:e,fps:q}=ao(m),h=g?.codec==="hevc";return typeof VideoEncoder>"u"||typeof AudioEncoder>"u"||typeof OfflineAudioContext>"u"||!new OffscreenCanvas(2,2).getContext("webgl2")||!(await VideoEncoder.isConfigSupported({codec:h?"hvc1.1.6.L153.B0":"avc1.640034",width:y,height:e,bitrate:no(g,{width:y,height:e,fps:q},so),framerate:q,hardwareAcceleration:"prefer-hardware"})).supported?!1:await co(h?"hevc":"avc",{width:y,height:e})&&await Io()}catch{return!1}}class Cr{frames=new Map;async push(g,y,e){let q=this.frames.get(y);q||(q=[],this.frames.set(y,q)),q.push(e)}}async function Mo(m,g,y,e,q,h,L){const M=g.get(y.url);if(!M)return null;if(ko(y)&&!y._still){const C=`${y.id}
3
3
  remap
4
4
  ${h}`,N=Math.round((e-h)*q);let X=m.get(C);if(!X){const te=M.samplesAtTimestamps(Ti(y,h-y.start,Math.max(1,Math.round(L*q)),q))[Symbol.asyncIterator]();X={iterator:te,peek:null,current:null,ts0:0,idx:0,next:async()=>{const oe=await te.next();return oe.done?null:oe.value}},m.set(C,X)}for(;(X.idx??0)<=N;){const te=await X.iterator.next();if(X.idx=(X.idx??0)+1,te.done)break;te.value&&te.value!==X.current&&(X.current?.close(),X.current=te.value)}return X.current}const V=!!(y._still||y.freeze),ie=V?1:y.playbackRate||1,se=!V&&Po(y),me=se?wi(y,h,L).start:(y.inPoint||0)+(V?0:(h-y.start)*ie),pe=`${y.id}
5
5
  ${V?"still":h}`;let x=m.get(pe);if(!x){if(!V)for(const[N,X]of m)N!==pe&&N.startsWith(`${y.id}
6
6
  `)&&!N.endsWith(`
7
7
  still`)&&!N.includes(`
8
8
  remap
9
- `)&&(X.current?.close(),X.peek?.close(),m.delete(N),await X.iterator.return?.());const C=M.samples(Math.max(0,me-.5))[Symbol.asyncIterator]();if(x={iterator:C,peek:null,current:null,ts0:me,next:async()=>{const N=await C.next();return N.done?null:N.value}},x.peek=await x.next(),!V){for(;x.peek&&x.peek.timestamp<me-1e-4;)x.peek.close(),x.peek=await x.next();x.ts0=x.peek?.timestamp??me}if(se){const N=O=>Number(O.toFixed(6)),X=h-y.start,te=yi(y,X,X+L),oe=te.slice(0,-1).map(([O,Ae],we)=>{const[$e,ye]=te[we+1];return{xa:N(O),dx:N($e-O),k:$e-O>1e-9?N((ye-Ae)/($e-O)):0}}).filter(O=>O.dx>1e-9);x.out=O=>oe.reduce((Ae,we)=>Ae+Math.min(we.dx,Math.max(0,O-we.xa))*we.k,0)}m.set(pe,x)}if(V){const C=Math.round(me*q);for(;x.peek&&Math.round(x.peek.timestamp*q)<=C;)x.current?.close(),x.current=x.peek,x.peek=await x.next();return x.current??x.peek}const R=Math.round((e-h)*q),F=C=>x.out?x.out(C-x.ts0):(C-x.ts0)/ie;for(;x.peek&&Math.round(F(x.peek.timestamp)*q)<=R;)x.current?.close(),x.current=x.peek,x.peek=await x.next();return x.current??x.peek}const Xr=`#version 300 es
9
+ `)&&(X.current?.close(),X.peek?.close(),m.delete(N),await X.iterator.return?.());const C=M.samples(Math.max(0,me-.5))[Symbol.asyncIterator]();if(x={iterator:C,peek:null,current:null,ts0:me,next:async()=>{const N=await C.next();return N.done?null:N.value}},x.peek=await x.next(),!V){for(;x.peek&&x.peek.timestamp<me-1e-4;)x.peek.close(),x.peek=await x.next();x.ts0=x.peek?.timestamp??me}if(se){const N=O=>Number(O.toFixed(6)),X=h-y.start,te=yi(y,X,X+L),oe=te.slice(0,-1).map(([O,Ae],we)=>{const[je,ye]=te[we+1];return{xa:N(O),dx:N(je-O),k:je-O>1e-9?N((ye-Ae)/(je-O)):0}}).filter(O=>O.dx>1e-9);x.out=O=>oe.reduce((Ae,we)=>Ae+Math.min(we.dx,Math.max(0,O-we.xa))*we.k,0)}m.set(pe,x)}if(V){const C=Math.round(me*q);for(;x.peek&&Math.round(x.peek.timestamp*q)<=C;)x.current?.close(),x.current=x.peek,x.peek=await x.next();return x.current??x.peek}const R=Math.round((e-h)*q),F=C=>x.out?x.out(C-x.ts0):(C-x.ts0)/ie;for(;x.peek&&Math.round(F(x.peek.timestamp)*q)<=R;)x.current?.close(),x.current=x.peek,x.peek=await x.next();return x.current??x.peek}const Xr=`#version 300 es
10
10
  in vec2 p;uniform vec4 dst;uniform vec4 src;out vec2 uv;
11
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);}`,Or=`#version 300 es
12
12
  precision highp float;in vec2 uv;uniform sampler2D tex;uniform float alpha;uniform float fade;uniform float white;
@@ -43,11 +43,11 @@ void main(){int r=min(int(ceil(sigma*3.)),128);vec4 acc=vec4(0);float wsum=0.;
43
43
  precision highp float;in vec2 uv;uniform sampler2D tex;uniform float lo;uniform float k;out vec4 o;
44
44
  void main(){vec4 c=texture(tex,uv);o=vec4(clamp(lo+c.rgb*k,0.,1.),c.a);}`,qr=`#version 300 es
45
45
  precision highp float;in vec2 uv;uniform sampler2D a;uniform sampler2D b;uniform float amount;out vec4 o;
46
- void main(){vec4 x=texture(a,uv),y=texture(b,uv);o=mix(x,1.-(1.-x)*(1.-y),amount);}`,$r=`#version 300 es
46
+ void main(){vec4 x=texture(a,uv),y=texture(b,uv);o=mix(x,1.-(1.-x)*(1.-y),amount);}`,jr=`#version 300 es
47
47
  precision highp float;in vec2 uv;uniform sampler2D tex;uniform vec2 step;uniform float b;uniform int reach;out vec4 o;
48
48
  void main(){vec4 acc=texture(tex,uv);float ws=1.;float w=1.;
49
49
  for(int i=1;i<=512;i++){if(i>reach)break;w*=b;acc+=(texture(tex,uv+step*float(i))+texture(tex,uv-step*float(i)))*w;ws+=2.*w;}
50
- o=acc/ws;}`,jr=`#version 300 es
50
+ o=acc/ws;}`,$r=`#version 300 es
51
51
  precision highp float;in vec2 uv;uniform sampler2D tex;uniform float taps[16];uniform int n;uniform vec2 ctr;out vec4 o;
52
52
  void main(){vec4 acc=vec4(0);for(int i=0;i<16;i++){if(i>=n)break;acc+=texture(tex,ctr+(uv-ctr)/taps[i]);}o=acc/float(n);}`,Hr=`#version 300 es
53
53
  precision highp float;in vec2 uv;uniform sampler2D tex;uniform float sx[8];uniform float sy[8];uniform int n;uniform vec3 gain;out vec4 o;
@@ -194,5 +194,5 @@ void main(){vec2 p=vec2(gl_FragCoord.x-.5,size.y-gl_FragCoord.y-.5),c=size*.5-.5
194
194
  o=acc/8.;}`,Ta=`#version 300 es
195
195
  precision highp float;in vec2 uv;uniform sampler2D tex;uniform float w;out vec4 o;
196
196
  void main(){vec4 c=texture(tex,uv);o=vec4(mix(c.rgb,1.-c.rgb,w),c.a);}`,wa=`#version 300 es
197
- precision highp float;in vec2 uv;uniform sampler2D tex;out vec4 o;void main(){o=texture(tex,uv);}`,ya=["wipe","blinds","split","iris","diamond","burn"];function So(m,g){const y=Math.max(1e-4,m.feather??.05),e=m.progress?Wt(m.progress,g)??0:g,q=(m.angle??0)*Math.PI/180,h=Math.cos(q),L=Math.sin(q),M=ya.indexOf(m.type??""),V=m.type==="grid";return{type:"txMask",kind:V?7:M<0?6:M,e:e*(1+2*y)-y,f:y,inv:!!m.invert,cx:m.cx??.5,cy:m.cy??.5,c:h,s:L,h:.5*(Math.abs(h)+Math.abs(L)),count:m.count??(V?Pi:8)}}function Do(m,g,y,e,q=0,h){if(!m)return[];const L=V=>Wt(m[V],g)??0,M=[];if(m.zoomBlur&&M.push({type:"txZoom",taps:Mi(),w:L("zoomBlur"),...h?{c:[h.cx,1-h.cy]}:{}}),m.spinBlur){const V=Si(y,e),ie=se=>Math.max(2,Math.round(se/2)*2);M.push({type:"txSpin",a:V.map(se=>+se.a.toFixed(6)),sx:V.map(se=>ie(y*se.scale)/y),sy:V.map(se=>ie(e*se.scale)/e),w:L("spinBlur")})}if(m.dirBlur){const V=To*y/1280,ie=V/(1+V);M.push({type:"txDir",b:ie,reach:Math.min(512,Math.ceil(Math.log(.001)/Math.log(ie))),w:L("dirBlur")})}if(m.dirBlurV){const V=To*y/1280,ie=V/(1+V);M.push({type:"txDir",b:ie,reach:Math.min(512,Math.ceil(Math.log(.001)/Math.log(ie))),w:L("dirBlurV"),v:!0})}return m.blur&&M.push({type:"txGauss",sigma:Di*y/1280,w:L("blur")}),m.glitch&&M.push({type:"txGlitch",v:L("glitch"),fr:Math.floor(q*30+.5)}),m.rgbSplit&&M.push({type:"txRgb",px:Math.trunc(L("rgbSplit")*Ui*y/1280+.5)}),m.exposure&&M.push({type:"txExpo",gain:ki,w:L("exposure")}),m.invert&&M.push({type:"txInv",w:L("invert")}),M}function Ra(m,g){const y=new OffscreenCanvas(m,g),e=y.getContext("webgl2",{premultipliedAlpha:!1,preserveDrawingBuffer:!0,antialias:!1});if(!e)throw Error("WebGL2 unavailable");const q=(a,c)=>{const i=e.createShader(a);if(e.shaderSource(i,c),e.compileShader(i),!e.getShaderParameter(i,e.COMPILE_STATUS))throw Error(String(e.getShaderInfoLog(i)));return i},h=(a,c)=>{const i=e.createProgram();if(e.attachShader(i,q(e.VERTEX_SHADER,a)),e.attachShader(i,q(e.FRAGMENT_SHADER,c)),e.bindAttribLocation(i,0,"p"),e.linkProgram(i),!e.getProgramParameter(i,e.LINK_STATUS))throw Error(String(e.getProgramInfoLog(i)));return i},L=h(Xr,Or),M=h(G,oa),V=h(G,ia),ie=h(G,ra),se=h(G,aa),me=h(G,na),pe=h(G,sa),x=h(G,ca),R=h(G,fa),F=h(G,zr),C=h(G,Gr),N=h(G,qr),X=h(G,wa),te=h(G,Hr),oe=h(G,la),O=h(G,ua),Ae=h(G,ma),we=h(G,pa),$e=h(G,da),ye=h(G,xa),We=h(G,$r),je=h(G,jr),nt=h(G,Vr),Me=h(G,Yr),st=h(G,Kr),Qe=h(G,Wr),Re=h(G,Qr),He=h(G,Zr),Ze=h(G,Jr),Se=h(G,ea),Xe=h(G,ta),it=h(G,va),Z=h(G,ha),ge=h(G,ga),ct=h(G,Ta),Ve=h(G,Ea),ke=h(G,ba),rt=e.createBuffer();e.bindBuffer(e.ARRAY_BUFFER,rt),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 Ye=a=>c=>e.getUniformLocation(a,c),A=Ye(L);e.pixelStorei(e.UNPACK_PREMULTIPLY_ALPHA_WEBGL,!1);const ce=()=>{const a=e.createTexture();e.bindTexture(e.TEXTURE_2D,a);for(const[c,i]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,c,i);return a},ft=ce(),Et=ce();let Ke=null;const at=ce(),lt=e.createTexture(),Oe={l1:"",l3:""};let bt=!1,Gt=!1,Pe=null;const Qt={add:1,screen:2,multiply:3,overlay:4,lighten:5,darken:6,difference:7,exclusion:8};let _e=0;const Tt=ce();let U=[],wt=null,yt=null;const Rt=new Map;let Be=!1,be=null;const _t=a=>{const c=Fe(),i=(a+1)%3,o=(a+2)%3;for(const p of U){let b=a;e.disable(e.BLEND),p.sigma>.05&&(j(F,c[i].fb,[c[a].tex],w=>{e.uniform1i(w("tex"),0),e.uniform2f(w("step"),1/m,0),e.uniform1f(w("sigma"),p.sigma)}),j(F,c[o].fb,[c[i].tex],w=>{e.uniform1i(w("tex"),0),e.uniform2f(w("step"),0,1/g),e.uniform1f(w("sigma"),p.sigma)}),b=o),le(null),e.enable(e.BLEND),e.blendFuncSeparate(e.SRC_ALPHA,e.ONE_MINUS_SRC_ALPHA,e.ONE,e.ONE_MINUS_SRC_ALPHA);const[t,l,u]=[1,3,5].map(w=>parseInt(p.color.slice(w,w+2),16)/255);j(M,null,[c[b].tex],w=>{e.uniform1i(w("tex"),0),e.uniform2f(w("off"),Math.trunc(p.dx)/m,-Math.trunc(p.dy)/g),e.uniform3f(w("col"),t,l,u),e.uniform1f(w("op"),p.opacity),e.uniform1f(w("times"),p.times),e.uniform2f(w("dil"),p.dilate?+(rr*255).toFixed(3):0,p.dilate?+(1/ar).toFixed(3):0)})}},ut=a=>{const c=Fe();if(Be){le(be.fb),e.enable(e.BLEND),e.blendFunc(e.ONE,e.ONE),j(pe,be.fb,[c[a].tex],i=>e.uniform1i(i("tex"),0)),e.blendFuncSeparate(e.SRC_ALPHA,e.ONE_MINUS_SRC_ALPHA,e.ONE,e.ONE_MINUS_SRC_ALPHA);return}if(U.length&&_t(a),_e){Je(c[a].tex);return}le(null),e.enable(e.BLEND),e.blendFuncSeparate(e.SRC_ALPHA,e.ONE_MINUS_SRC_ALPHA,e.ONE,e.ONE_MINUS_SRC_ALPHA),j(X,null,[c[a].tex],i=>e.uniform1i(i("tex"),0))},Je=a=>{le(null),e.bindTexture(e.TEXTURE_2D,Tt),e.copyTexImage2D(e.TEXTURE_2D,0,e.RGBA8,0,0,m,g,0),e.disable(e.BLEND),j(it,null,[a,Tt],c=>{e.uniform1i(c("top"),0),e.uniform1i(c("bg"),1),e.uniform1i(c("mode"),_e)})};let Le=null;const Fe=()=>Le??=[De(),De(),De()],Ft=new Map,Dt=a=>{let c=Ft.get(a);if(c)return c;const i=()=>{const o=ce();e.texImage2D(e.TEXTURE_2D,0,e.RGBA8,m*a,g*a,0,e.RGBA,e.UNSIGNED_BYTE,null);const p=e.createFramebuffer();return e.bindFramebuffer(e.FRAMEBUFFER,p),e.framebufferTexture2D(e.FRAMEBUFFER,e.COLOR_ATTACHMENT0,e.TEXTURE_2D,o,0),{tex:o,fb:p}};return c={plane:i(),out:i()},Ft.set(a,c),c},Ut=new Map,qt=new Map,Zt=a=>{let c=Ut.get(a.key);if(c)return c;c=ce();const i=new Uint8Array(256*3);(a.lut??[]).forEach((o,p)=>i.set(o,p*256)),e.pixelStorei(e.UNPACK_ALIGNMENT,1),e.texImage2D(e.TEXTURE_2D,0,e.R8,256,3,0,e.RED,e.UNSIGNED_BYTE,i),e.pixelStorei(e.UNPACK_ALIGNMENT,4);for(const o of[e.TEXTURE_MIN_FILTER,e.TEXTURE_MAG_FILTER])e.texParameteri(e.TEXTURE_2D,o,e.NEAREST);return Ut.set(a.key,c),c},mt=(a,c)=>{const i=`${a}x${c}`;let o=qt.get(i);if(o)return o;const p=ce();e.texImage2D(e.TEXTURE_2D,0,e.RGBA8,a,c,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 b=e.createFramebuffer();return e.bindFramebuffer(e.FRAMEBUFFER,b),e.framebufferTexture2D(e.FRAMEBUFFER,e.COLOR_ATTACHMENT0,e.TEXTURE_2D,p,0),o={tex:p,fb:b},qt.set(i,o),o},At=new Map,kt=(a,c)=>{const i=`${a}x${c}`;let o=At.get(i);return o||(o=[0,1].map(()=>{const p=ce();e.texImage2D(e.TEXTURE_2D,0,e.RGBA8,a,c,0,e.RGBA,e.UNSIGNED_BYTE,null);const b=e.createFramebuffer();return e.bindFramebuffer(e.FRAMEBUFFER,b),e.framebufferTexture2D(e.FRAMEBUFFER,e.COLOR_ATTACHMENT0,e.TEXTURE_2D,p,0),{tex:p,fb:b}}),At.set(i,o),o)},De=()=>{const a=ce();e.texImage2D(e.TEXTURE_2D,0,e.RGBA8,m,g,0,e.RGBA,e.UNSIGNED_BYTE,null);const c=e.createFramebuffer();return e.bindFramebuffer(e.FRAMEBUFFER,c),e.framebufferTexture2D(e.FRAMEBUFFER,e.COLOR_ATTACHMENT0,e.TEXTURE_2D,a,0),{tex:a,fb:c}},le=a=>{e.bindFramebuffer(e.FRAMEBUFFER,a),e.viewport(0,0,m,g)},j=(a,c,i,o)=>Mt(a,c,m,g,i,o),Mt=(a,c,i,o,p,b)=>{e.bindFramebuffer(e.FRAMEBUFFER,c),e.viewport(0,0,i,o),e.useProgram(a);const t=Ye(a);p.forEach((l,u)=>{e.activeTexture(e.TEXTURE0+u),e.bindTexture(e.TEXTURE_2D,l)}),b(t),e.drawArrays(e.TRIANGLE_STRIP,0,4),p.length>1&&r(),e.activeTexture(e.TEXTURE0)},r=()=>{e.activeTexture(e.TEXTURE1),e.bindTexture(e.TEXTURE_2D,Et),e.activeTexture(e.TEXTURE2),e.bindTexture(e.TEXTURE_2D,at),e.activeTexture(e.TEXTURE3),e.bindTexture(e.TEXTURE_3D,lt),e.activeTexture(e.TEXTURE0)},f=(a,c=0)=>{const i=Fe();let o=c;const p=(t,l,u,w)=>{j(F,i[l].fb,[i[t].tex],n=>{e.uniform1i(n("tex"),0),e.uniform2f(n("step"),1/m,0),e.uniform1f(n("sigma"),w)}),j(F,i[u].fb,[i[l].tex],n=>{e.uniform1i(n("tex"),0),e.uniform2f(n("step"),0,1/g),e.uniform1f(n("sigma"),w)})},b=(t,l,u,w)=>j(Me,i[u].fb,[i[t].tex,i[l].tex],n=>{e.uniform1i(n("a"),0),e.uniform1i(n("b"),1),e.uniform1f(n("w"),w)});for(const t of a){const[l,u,w]=[o,(o+1)%3,(o+2)%3];if(t.type==="blur"){t.sigma>.05&&(p(l,u,w,t.sigma),o=w);continue}if(t.type==="colour"){const n=Zt(t);j(He,i[u].fb,[i[l].tex,n],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(S=>[S[0],S[1],S[2],S[3]??0]))}),o=u;continue}if(t.type==="txRgb"){t.px>0&&(j(ge,i[u].fb,[i[l].tex],n=>{e.uniform1i(n("tex"),0),e.uniform1i(n("px"),t.px)}),o=u);continue}if(t.type==="txGlitch"){t.v>1e-4&&(j(Ve,i[u].fb,[i[l].tex],n=>{e.uniform1i(n("tex"),0),e.uniform2f(n("size"),m,g),e.uniform2f(n("msize"),Math.max(2,Math.round(m/4)),Math.max(2,Math.round(g/4))),e.uniform1f(n("v"),t.v),e.uniform1f(n("fr"),t.fr)}),o=u);continue}if(t.type==="txInv"){t.w>1e-4&&(j(ct,i[u].fb,[i[l].tex],n=>{e.uniform1i(n("tex"),0),e.uniform1f(n("w"),Math.min(1,t.w))}),o=u);continue}if(t.type==="shift"){j(Ze,i[u].fb,[i[l].tex],n=>{e.uniform1i(n("tex"),0),e.uniform1i(n("px"),t.px)}),o=u;continue}if(t.type==="pixel"){const n=Math.ceil(m/t.block),v=Math.ceil(g/t.block),S=mt(n,v);e.bindFramebuffer(e.FRAMEBUFFER,S.fb),e.viewport(0,0,n,v),e.useProgram(Se),e.activeTexture(e.TEXTURE0),e.bindTexture(e.TEXTURE_2D,i[l].tex),e.uniform1i(e.getUniformLocation(Se,"tex"),0),e.uniform1i(e.getUniformLocation(Se,"b"),t.block),e.uniform2i(e.getUniformLocation(Se,"small"),n,v),e.drawArrays(e.TRIANGLE_STRIP,0,4),j(Xe,i[u].fb,[S.tex],Y=>{e.uniform1i(Y("small"),0),e.uniform1i(Y("b"),t.block),e.uniform2f(Y("size"),m,g)}),o=u;continue}if(t.type==="txMask"){j(Re,i[u].fb,[i[l].tex],n=>{e.uniform1i(n("tex"),0),e.uniform2f(n("size"),m,g),e.uniform1i(n("kind"),t.kind),e.uniform1f(n("e"),t.e),e.uniform1f(n("f"),t.f),e.uniform1f(n("inv"),t.inv?1:0),e.uniform2f(n("ctr"),t.cx,t.cy),e.uniform3f(n("csh"),t.c,t.s,t.h),e.uniform1f(n("count"),t.count)}),o=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 n=u;t.type==="txGauss"?(p(l,u,w,t.sigma),n=w):t.type==="txDir"?j(We,i[u].fb,[i[l].tex],S=>{e.uniform1i(S("tex"),0),t.v?e.uniform2f(S("step"),0,1/g):e.uniform2f(S("step"),1/m,0),e.uniform1f(S("b"),t.b),e.uniform1i(S("reach"),t.reach)}):t.type==="txZoom"?j(je,i[u].fb,[i[l].tex],S=>{e.uniform1i(S("tex"),0),e.uniform1fv(S("taps"),t.taps),e.uniform1i(S("n"),t.taps.length),e.uniform2f(S("ctr"),t.c?.[0]??.5,t.c?.[1]??.5)}):t.type==="txSpin"?j(ke,i[u].fb,[i[l].tex],S=>{e.uniform1i(S("tex"),0),e.uniform2f(S("size"),m,g),e.uniform1fv(S("a"),t.a),e.uniform1fv(S("sx"),t.sx),e.uniform1fv(S("sy"),t.sy)}):j(nt,i[u].fb,[i[l].tex],S=>{e.uniform1i(S("tex"),0),e.uniform1f(S("gain"),t.gain)});const v=n===w?u:w;b(l,n,v,Math.min(1,t.w)),o=v;continue}if(t.type==="burst"){const{w:n,h:v}=ur(m,g),[S,Y]=kt(n,v),W=cr(fr.burst*t.amount).map(Q=>lr(n,v,Q));j(C,i[u].fb,[i[l].tex],Q=>{e.uniform1i(Q("tex"),0),e.uniform1f(Q("lo"),t.lo),e.uniform1f(Q("k"),t.k)}),Mt(X,S.fb,n,v,[i[u].tex],Q=>e.uniform1i(Q("tex"),0)),Mt(te,Y.fb,n,v,[S.tex],Q=>{e.uniform1i(Q("tex"),0),e.uniform1i(Q("n"),W.length),e.uniform1fv(Q("sx"),W.map(Ee=>Ee.sw/n)),e.uniform1fv(Q("sy"),W.map(Ee=>Ee.sh/v)),e.uniform3f(Q("gain"),...pr(t.amount))}),j(N,i[w].fb,[i[l].tex,Y.tex],Q=>{e.uniform1i(Q("a"),0),e.uniform1i(Q("b"),1),e.uniform1f(Q("amount"),+t.amount.toFixed(4))}),o=w;continue}j(C,i[u].fb,[i[l].tex],n=>{e.uniform1i(n("tex"),0),e.uniform1f(n("lo"),t.lo),e.uniform1f(n("k"),t.k)}),p(u,w,u,t.sigma),j(N,i[w].fb,[i[l].tex,i[u].tex],n=>{e.uniform1i(n("a"),0),e.uniform1i(n("b"),1),e.uniform1f(n("amount"),t.amount)}),o=w}return o};let k=null,d="",E=[],z="";const B=(a,c)=>{if(z!==`${a}x${c}`){for(const i of E)e.deleteTexture(i.tex),e.deleteFramebuffer(i.fb);E=Array.from({length:4},()=>{const i=ce();e.texImage2D(e.TEXTURE_2D,0,e.RGBA8,a,c,0,e.RGBA,e.UNSIGNED_BYTE,null);const o=e.createFramebuffer();return e.bindFramebuffer(e.FRAMEBUFFER,o),e.framebufferTexture2D(e.FRAMEBUFFER,e.COLOR_ATTACHMENT0,e.TEXTURE_2D,i,0),{tex:i,fb:o}}),z=`${a}x${c}`}return E},ue=(a,c,i,o)=>{const p=e.getParameter(e.FRAMEBUFFER_BINDING),b=e.getParameter(e.VIEWPORT),t=e.isEnabled(e.BLEND),l=B(o.ew,o.eh),u=(n,v,S,Y)=>{e.bindFramebuffer(e.FRAMEBUFFER,l[v].fb),e.viewport(0,0,o.ew,o.eh),e.useProgram(n);const W=Ye(n);S.forEach((Q,Ee)=>{e.activeTexture(e.TEXTURE0+Ee),e.bindTexture(e.TEXTURE_2D,l[Q].tex)}),Y(W),e.drawArrays(e.TRIANGLE_STRIP,0,4),S.length>1&&r(),e.activeTexture(e.TEXTURE0)};e.disable(e.BLEND),e.bindFramebuffer(e.FRAMEBUFFER,l[0].fb),e.viewport(0,0,o.ew,o.eh),e.clearColor(0,0,0,0),e.clear(e.COLOR_BUFFER_BIT);{const n=Bt(a,i);e.bindFramebuffer(e.FRAMEBUFFER,l[0].fb),e.viewport(0,0,o.ew,o.eh),e.disable(e.BLEND),qe(a,[0,0,1,1],c,1,1,!1,n==="win"?null:i,n)}u(V,1,[0],n=>{e.uniform1i(n("tex"),0),e.uniform1f(n("harden"),o.harden?tr:0)});const w=(n,v,S,Y)=>{u(ie,v,[n],W=>{e.uniform1i(W("tex"),0),e.uniform2i(W("dir"),1,0),e.uniform1f(W("sigma"),Y)}),u(ie,S,[v],W=>{e.uniform1i(W("tex"),0),e.uniform2i(W("dir"),0,1),e.uniform1f(W("sigma"),Y)})};w(1,2,3,o.band),u(se,2,[1,3],n=>{e.uniform1i(n("a"),0),e.uniform1i(n("b"),1);const v=o.arc;e.uniform1f(n("arc"),v?1:0),v&&(e.uniform2f(n("cw"),o.ew/ro,o.eh/ro),e.uniform2f(n("cen"),v.cen[0],v.cen[1]),e.uniform1f(n("start"),v.start),e.uniform1f(n("cover"),v.cover),e.uniform1f(n("comet"),v.comet?1:0),e.uniform1f(n("feather"),or*v.cover))}),w(2,1,3,o.glow),u(me,1,[0,2,3],n=>{e.uniform1i(n("pic"),0),e.uniform1i(n("band"),1),e.uniform1i(n("glow"),2),e.uniform3f(n("col"),...o.col),e.uniform1f(n("k"),o.k),e.uniform1f(n("am"),o.am)}),e.bindFramebuffer(e.FRAMEBUFFER,p),e.viewport(b[0],b[1],b[2],b[3]),t&&e.enable(e.BLEND)};let K=null,J="",s=null,_=[],re="";const xe=new Map,ze=new Map,de=new Map,Ge=new Map,ae=new Map,P=new Map,Ne=ce(),Pt=(a,c)=>{const i=ce();e.texImage2D(e.TEXTURE_2D,0,e.RGBA8,a,c,0,e.RGBA,e.UNSIGNED_BYTE,null);const o=e.createFramebuffer();return e.bindFramebuffer(e.FRAMEBUFFER,o),e.framebufferTexture2D(e.FRAMEBUFFER,e.COLOR_ATTACHMENT0,e.TEXTURE_2D,i,0),{tex:i,fb:o}},$t=(a,c,i)=>{const o=e.getParameter(e.FRAMEBUFFER_BINDING),p=e.getParameter(e.VIEWPORT),b=e.isEnabled(e.BLEND),t=a.w,l=a.h;if(re!==`${t}x${l}`){for(const H of _)e.deleteTexture(H.tex),e.deleteFramebuffer(H.fb);_=Array.from({length:7},()=>Pt(t,l)),re=`${t}x${l}`}e.disable(e.BLEND),e.bindFramebuffer(e.FRAMEBUFFER,_[0].fb),e.viewport(0,0,t,l),e.clearColor(0,0,0,0),e.clear(e.COLOR_BUFFER_BIT),qe(a,[0,1,1,-1],[0,0,1,1],1,1,!1,c,"base");let u=0;const w=H=>[H[0],H[3],H[6],H[1],H[4],H[7],H[2],H[5],H[8]],n=(H,$,xt,et)=>{e.bindFramebuffer(e.FRAMEBUFFER,_[$].fb),e.viewport(0,0,t,l),e.useProgram(H);const Ie=Ye(H);xt.forEach((dt,vt)=>{e.activeTexture(e.TEXTURE0+vt),e.bindTexture(dt.d3?e.TEXTURE_3D:e.TEXTURE_2D,dt.t)}),et(Ie),e.drawArrays(e.TRIANGLE_STRIP,0,4),r()},v=H=>({t:_[H].tex}),S=(H,$,xt,et)=>{n(F,$,[v(H)],Ie=>{e.uniform1i(Ie("tex"),0),e.uniform2f(Ie("step"),1/t,0),e.uniform1f(Ie("sigma"),et)}),n(F,xt,[v($)],Ie=>{e.uniform1i(Ie("tex"),0),e.uniform2f(Ie("step"),0,1/l),e.uniform1f(Ie("sigma"),et)})},Y=i.list,W=Y.map(H=>io(H)),Q=zi(Y),Ee=new Set;for(const[H,$]of Y.entries()){const xt=Q[H];if(H===xt&&Y.some((T,D)=>D>H&&Q[D]===H&&W[D])&&(n(X,2,[v(u)],T=>e.uniform1i(T("tex"),0)),Ee.add(H)),!W[H])continue;const et=H!==xt&&Ee.has(xt)?$.branch:void 0,Ie=et?2:u;let dt=Ne,vt=[1,1];if($.qualifier){const T=Math.max(2,Math.trunc((t+St-1)/St)),D=Math.max(2,Math.trunc((l+St-1)/St)),I=`${T}x${D}`;let ne=xe.get(I);ne||(ne=Pt(T,D),xe.set(I,ne));const ee=$.qualifier,ve=Math.max(.001,ee.soft??.3),Ue=$.window,gt=-(Ue?.rot??0)*Math.PI/180;e.bindFramebuffer(e.FRAMEBUFFER,ne.fb),e.viewport(0,0,T,D),e.useProgram(R),e.activeTexture(e.TEXTURE0),e.bindTexture(e.TEXTURE_2D,_[Ie].tex);const Te=Ye(R);e.uniform1i(Te("tex"),0),e.uniform2f(Te("big"),t,l),e.uniform2f(Te("small"),T,D),e.uniform4f(Te("q1"),ee.hue,ee.hueWidth,Math.max(1,ve*60),Math.max(.001,ve*.2)),e.uniform4f(Te("q2"),ee.satMin,ee.satMax,ee.lumMin,ee.lumMax),e.uniform1f(Te("useQ"),1),e.uniform1f(Te("useW"),Ue?1:0),Ue&&(e.uniform4f(Te("w1"),Ue.cx,Ue.cy,Math.max(1e-4,Ue.w/2),Math.max(.001,Ue.feather??.2)),e.uniform4f(Te("w2"),Math.cos(gt),Math.sin(gt),Math.max(1e-4,Ue.h/2),Ue.type==="gradient"?2:Ue.type==="rect"?1:0)),e.uniform1f(Te("inv"),$.invert?1:0),e.drawArrays(e.TRIANGLE_STRIP,0,4),dt=ne.tex,vt=[T*St,D*St]}else if(!$.whole&&Gi($)&&$.window?.type!=="person"){const T=`${i.clip}#${H}`,D=`${t}x${l}@${i.local??0}`,I=yo,ne=Math.max(2,Math.min(yo*2,Math.round(I*l/t)));let ee=Ge.get(T);if(ee||(ee={tex:ce(),at:""},Ge.set(T,ee)),ee.at!==D){const ve=wo($,i.src,i.local??0,l/t,null),Ue=new Uint8Array(I*ne);for(let gt=0;gt<ne;gt++)for(let Te=0;Te<I;Te++)Ue[gt*I+Te]=Math.round(ve((Te+.5)/I,(gt+.5)/ne,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,ne,0,e.RED,e.UNSIGNED_BYTE,Ue),e.pixelStorei(e.UNPACK_ALIGNMENT,4),ee.at=D}dt=ee.tex,vt=[t,l]}else if(!$.whole){const T=Ro($)?i.src?.depthMap:void 0,D=`${i.clip}#${H}@${t}x${l}${T?`@${T.at}:${T.data.length}:${T.data.slice(0,24)}`:""}`;let I=ze.get(D);if(!I){const ne=qi($,t,l,Ro($)?wo($,i.src,0,l/t):null);I=ce(),e.pixelStorei(e.UNPACK_ALIGNMENT,1),e.texImage2D(e.TEXTURE_2D,0,e.R8,ne.w4,ne.h4,0,e.RED,e.UNSIGNED_BYTE,ne.px),e.pixelStorei(e.UNPACK_ALIGNMENT,4),ze.set(D,I)}dt=I,vt=[t,l]}const Lt=$.adjust??{},fo=$i($),Jt=`${i.clip}#${H}`;let jt=de.get(Jt);if(fo&&!jt){const T=new Float32Array(1024);for(let D=0;D<256;D++)["r","g","b"].forEach((I,ne)=>{T[D*4+ne]=+ji(Lt,I,D/255,$.wheels,$.curves).toFixed(6)}),T[D*4+3]=1;jt=ce(),e.texImage2D(e.TEXTURE_2D,0,e.RGBA32F,256,1,0,e.RGBA,e.FLOAT,T);for(const D of[e.TEXTURE_MIN_FILTER,e.TEXTURE_MAG_FILTER])e.texParameteri(e.TEXTURE_2D,D,e.NEAREST);de.set(Jt,jt)}let ht=null;if(Hi($)){const T=`${Jt}:${JSON.stringify([$.cst,$.look,$.lut,$.mixer])}`;if(ht=ae.get(T)??null,!ht){const D=Vi($,I=>mr(I));if(!D)throw Error(`LUT "${$.lut?.name??""}" chưa tải xong`);ht=e.createTexture(),e.activeTexture(e.TEXTURE4),e.bindTexture(e.TEXTURE_3D,ht),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),ae.set(T,ht)}}const{sat:Co,rot:Xo}=Yi(Lt.saturation??1,Lt.hue??0);n(oe,3,[v(Ie),{t:jt??at},{t:ht??lt,d3:!0}],T=>{e.uniform1i(T("tex"),0),e.uniform1i(T("lut"),1),e.uniform1i(T("t3"),2),e.uniform1f(T("useT"),ht?1:0),e.uniform1f(T("useL"),fo?1:0),e.uniform1f(T("useS"),(Lt.saturation??1)!==1?1:0),e.uniform1f(T("useR"),(Lt.hue??0)!==0?1:0),e.uniformMatrix3fv(T("sat"),!1,w(Co)),e.uniformMatrix3fv(T("rot"),!1,w(Xo))}),e.activeTexture(e.TEXTURE2),e.bindTexture(e.TEXTURE_3D,null),e.activeTexture(e.TEXTURE0),r();let fe=3;const tt=(T,D)=>[3,4,5].find(I=>I!==T&&I!==D);if(($.blur??0)>0){const T=tt(fe),D=tt(fe,T);S(fe,T,D,Math.max(.1,+(($.blur??0)*Ki*t).toFixed(3))),fe=D}const lo=Wi({sharpness:$.sharpen??0});if(lo){const T=tt(fe);n(Ae,T,[v(fe)],D=>{e.uniform1i(D("tex"),0),e.uniform1fv(D("k"),lo),e.uniform1f(D("rdiv"),1/ir)}),fe=T}const he=$.fx?Qi($.fx,t):null;if(he&&(he.type==="glow"||he.type==="halation")){const T=tt(fe),D=tt(fe,T);n(C,T,[v(fe)],ve=>{e.uniform1i(ve("tex"),0),e.uniform1f(ve("lo"),he.lo),e.uniform1f(ve("k"),he.k)});let I=T;he.tint&&(n(He,D,[v(T),{t:at}],ve=>{e.uniform1i(ve("tex"),0),e.uniform1i(ve("lut"),1),e.uniform1f(ve("useM"),1),e.uniform1f(ve("useL"),0),e.uniform1fv(ve("m"),he.tint.flat())}),I=D),S(I,I===T?D:T,I,he.sigma);const ee=6;n(N,ee,[v(fe),v(I)],ve=>{e.uniform1i(ve("a"),0),e.uniform1i(ve("b"),1),e.uniform1f(ve("amount"),he.amount)}),n(X,3,[v(ee)],ve=>e.uniform1i(ve("tex"),0)),fe=3}else if(he?.type==="grain"){const T=Zi(i.frame??0),D=`${T}:${t}x${l}:${he.amp}`;let I=P.get(D);if(!I){if(P.size>8){for(const ee of P.values())e.deleteTexture(ee);P.clear()}I=ce(),e.pixelStorei(e.UNPACK_ALIGNMENT,1),e.texImage2D(e.TEXTURE_2D,0,e.R8,t,l,0,e.RED,e.UNSIGNED_BYTE,Ji(T,t,l,he.amp)),e.pixelStorei(e.UNPACK_ALIGNMENT,4),P.set(D,I)}const ne=tt(fe);n(we,ne,[v(fe),{t:I}],ee=>{e.uniform1i(ee("tex"),0),e.uniform1i(ee("grain"),1)}),fe=ne}else if(he?.type==="denoise"){const T=tt(fe),D=tt(fe,T);S(fe,T,D,he.sigma),n($e,6,[v(fe),v(D)],I=>{e.uniform1i(I("tex"),0),e.uniform1i(I("soft"),1),e.uniform1f(I("t"),he.t)}),n(X,3,[v(6)],I=>e.uniform1i(I("tex"),0)),fe=3}else if(he?.type==="swirl"){const T=D=>Math.max(2,Math.round(D/2)*2);for(const D of er(t,l,he.deg)){const I=tt(fe);n(ke,I,[v(fe)],ne=>{e.uniform1i(ne("tex"),0),e.uniform2f(ne("size"),t,l),e.uniform1fv(ne("a"),D.map(ee=>+ee.a.toFixed(6))),e.uniform1fv(ne("sx"),D.map(ee=>T(t*ee.scale)/t)),e.uniform1fv(ne("sy"),D.map(ee=>T(l*ee.scale)/l))}),fe=I}}const Oo=et==="parallel"?2:u,zo=et==="parallel"?6:1-u;n(O,zo,[v(Oo),v(fe),{t:dt}],T=>{e.uniform1i(T("base"),0),e.uniform1i(T("over"),1),e.uniform1i(T("mask"),2),e.uniform2f(T("msz"),vt[0],vt[1]),e.uniform1f(T("full"),$.whole?1:0)}),et==="parallel"&&n(ye,1-u,[v(u),v(6),v(2)],T=>{e.uniform1i(T("res"),0),e.uniform1i(T("outp"),1),e.uniform1i(T("inp"),2)}),u=1-u}s=_[u].tex,e.bindFramebuffer(e.FRAMEBUFFER,o),e.viewport(p[0],p[1],p[2],p[3]),b&&e.enable(e.BLEND)},Bt=(a,c)=>K?(J!==K.key&&($t(a,c,K),J=K.key),"win"):"pic",pt=(a,c,i,o,p,b,t)=>{if(!k){const S=Bt(a,t);qe(a,c,i,o,p,b,S==="win"?null:t,S);return}const l=Ke??[0,0,1,1];d!==k.key&&(ue(a,l,t,k),d=k.key);const u=(i[0]-l[0])/l[2],w=(i[1]-l[1])/l[3],n=i[2]/l[2],v=i[3]/l[3];qe(a,c,[u,1-w,n,-v],o,p,b,null,"edge")},qe=(a,c,i,o,p,b,t,l)=>{const u=l==="edge"||l==="win",w=l==="pic"||l==="base";if(e.useProgram(L),e.activeTexture(e.TEXTURE0),e.bindTexture(e.TEXTURE_2D,ft),w&&e.texImage2D(e.TEXTURE_2D,0,e.RGBA,e.RGBA,e.UNSIGNED_BYTE,a.source),e.uniform4f(A("dst"),c[0],c[1],c[2],c[3]),e.uniform4f(A("src"),i[0],i[1],i[2],i[3]),e.uniform1f(A("alpha"),o),e.uniform1f(A("fade"),p),e.uniform1f(A("white"),b?1:0),e.uniform1f(A("colour"),t?1:0),e.uniform1i(A("tex"),0),e.uniform1i(A("matte"),1),e.uniform1f(A("useMatte"),Ke&&(l==="pic"||l==="win")?1:0),Pe&&!u?(e.uniform4f(A("key"),Pe.u,Pe.v,Pe.similarity,Pe.blend),e.uniform4f(A("keyOpt"),1,Pe.blue?1:0,Pe.spill,a.bt709?1:0)):e.uniform4f(A("keyOpt"),0,0,0,0),e.uniform1i(A("lut1"),2),e.uniform1i(A("lut3"),3),e.uniform1f(A("useL1"),bt&&!u?1:0),e.uniform1f(A("useL3"),Gt&&!u?1:0),Ke&&e.uniform4f(A("mrect"),Ke[0],Ke[1],Ke[2],Ke[3]),e.activeTexture(e.TEXTURE1),e.bindTexture(e.TEXTURE_2D,Et),e.activeTexture(e.TEXTURE2),e.bindTexture(e.TEXTURE_2D,at),e.activeTexture(e.TEXTURE3),e.bindTexture(e.TEXTURE_3D,lt),e.activeTexture(e.TEXTURE0),e.bindTexture(e.TEXTURE_2D,l==="edge"?E[1].tex:l==="win"?s:ft),t){const n=v=>[v[0],v[3],v[6],v[1],v[4],v[7],v[2],v[5],v[8]];e.uniform1f(A("bright"),t.bright),e.uniform1f(A("contrast"),t.contrast),e.uniformMatrix3fv(A("sat"),!1,n(t.sat)),e.uniformMatrix3fv(A("rot"),!1,n(t.rot))}e.drawArrays(e.TRIANGLE_STRIP,0,4)};return{canvas:y,clear(a=1){le(null),e.clearColor(0,0,0,a),e.clear(e.COLOR_BUFFER_BIT)},pixels(){le(null);const a=new Uint8ClampedArray(m*g*4),c=m*4,i=new Uint8ClampedArray(m*g*4);e.readPixels(0,0,m,g,e.RGBA,e.UNSIGNED_BYTE,a);for(let o=0;o<g;o++){const p=(g-1-o)*c,b=o*c;for(let t=0;t<c;t+=4){const l=a[p+t+3];if(i[b+t+3]=l,l){const u=255/l;i[b+t]=a[p+t]*u,i[b+t+1]=a[p+t+1]*u,i[b+t+2]=a[p+t+2]*u}}}return i},draw(a,c,i,o,p,b,t=null,l=[],u=null){if(!l.length&&!_e&&!U.length&&!Be){le(null),e.enable(e.BLEND),e.blendFuncSeparate(e.SRC_ALPHA,e.ONE_MINUS_SRC_ALPHA,e.ONE,e.ONE_MINUS_SRC_ALPHA),pt(a,c,i,o,p,b,t);return}Le??=[De(),De(),De()],le(Le[0].fb),e.disable(e.BLEND),e.clearColor(0,0,0,0),e.clear(e.COLOR_BUFFER_BIT),pt(a,u??c,i,o,p,b,t);const w=f(l);if(le(null),e.enable(e.BLEND),e.blendFuncSeparate(e.SRC_ALPHA,e.ONE_MINUS_SRC_ALPHA,e.ONE,e.ONE_MINUS_SRC_ALPHA),_e||U.length||Be){let n=w;u&&(n=(w+1)%3,le(Le[n].fb),e.disable(e.BLEND),e.clearColor(0,0,0,0),e.clear(e.COLOR_BUFFER_BIT),e.useProgram(L),e.activeTexture(e.TEXTURE0),e.bindTexture(e.TEXTURE_2D,Le[w].tex),e.uniform4f(A("dst"),c[0],c[1],c[2],c[3]),e.uniform4f(A("src"),0,1,1,-1),e.uniform1f(A("alpha"),1),e.uniform1f(A("fade"),1),e.uniform1f(A("white"),0),e.uniform1f(A("colour"),0),e.uniform1f(A("useMatte"),0),e.drawArrays(e.TRIANGLE_STRIP,0,4)),ut(n);return}if(!u){j(X,null,[Le[w].tex],n=>e.uniform1i(n("tex"),0));return}e.useProgram(L),e.activeTexture(e.TEXTURE0),e.bindTexture(e.TEXTURE_2D,Le[w].tex),e.uniform4f(A("dst"),c[0],c[1],c[2],c[3]),e.uniform4f(A("src"),0,1,1,-1),e.uniform1f(A("alpha"),1),e.uniform1f(A("fade"),1),e.uniform1f(A("white"),0),e.uniform1f(A("colour"),0),e.uniform1f(A("useMatte"),0),e.drawArrays(e.TRIANGLE_STRIP,0,4)},warp(a,c,i,o,p,b,t,l,u,w=null,n=null,v=[]){const S=Fe();le(S[0].fb),e.disable(e.BLEND),e.clearColor(0,0,0,0),e.clear(e.COLOR_BUFFER_BIT),pt(a,c,i,o,p,b,t);const Y=f(l),W=_e||U.length||Be||v.length?(Y+1)%3:-1;W>=0?(le(S[W].fb),e.disable(e.BLEND),e.clearColor(0,0,0,0),e.clear(e.COLOR_BUFFER_BIT)):(le(null),e.enable(e.BLEND),e.blendFuncSeparate(e.SRC_ALPHA,e.ONE_MINUS_SRC_ALPHA,e.ONE,e.ONE_MINUS_SRC_ALPHA)),n&&(e.enable(e.SCISSOR_TEST),e.scissor(n[0],g-n[1]-n[3],n[2],n[3])),j(Qe,W>=0?S[W].fb:null,[S[Y].tex],Q=>{e.uniform1i(Q("tex"),0),e.uniform2f(Q("size"),m,g),e.uniform1f(Q("keepPre"),0),e.uniformMatrix3fv(Q("inv"),!1,[u[0],u[3],u[6],u[1],u[4],u[7],u[2],u[5],u[8]]),e.uniform4f(Q("rnd"),w?.[0]??0,w?.[1]??0,w?.[2]??0,w?1:0)}),e.disable(e.SCISSOR_TEST),W>=0&&ut(v.length?f(v,W):W)},adjust(a,c,i){const o=Fe();if(le(null),e.bindTexture(e.TEXTURE_2D,Tt),e.copyTexImage2D(e.TEXTURE_2D,0,e.RGBA8,0,0,m,g,0),le(o[0].fb),e.disable(e.BLEND),e.useProgram(L),e.activeTexture(e.TEXTURE0),e.bindTexture(e.TEXTURE_2D,Tt),e.uniform4f(A("dst"),0,0,1,1),e.uniform4f(A("src"),0,1,1,-1),e.uniform1i(A("tex"),0),e.uniform1f(A("alpha"),1),e.uniform1f(A("fade"),1),e.uniform1f(A("white"),0),e.uniform1f(A("useMatte"),0),e.uniform1f(A("colour"),a?1:0),a){const b=t=>[t[0],t[3],t[6],t[1],t[4],t[7],t[2],t[5],t[8]];e.uniform1f(A("bright"),a.bright),e.uniform1f(A("contrast"),a.contrast),e.uniformMatrix3fv(A("sat"),!1,b(a.sat)),e.uniformMatrix3fv(A("rot"),!1,b(a.rot))}e.drawArrays(e.TRIANGLE_STRIP,0,4);const p=f(c);le(null),e.enable(e.BLEND),e.blendFuncSeparate(e.SRC_ALPHA,e.ONE_MINUS_SRC_ALPHA,e.ONE,e.ONE_MINUS_SRC_ALPHA),e.useProgram(L),e.activeTexture(e.TEXTURE0),e.bindTexture(e.TEXTURE_2D,o[p].tex),e.uniform4f(A("dst"),0,0,1,1),e.uniform4f(A("src"),0,1,1,-1),e.uniform1f(A("alpha"),i),e.uniform1f(A("fade"),1),e.uniform1f(A("white"),0),e.uniform1f(A("colour"),0),e.uniform1f(A("useMatte"),0),e.drawArrays(e.TRIANGLE_STRIP,0,4)},grade(a,c){if(bt=!!a,Gt=!!c,a&&Oe.l1!==a.key){const i=new Float32Array(1024);for(let o=0;o<256;o++)i[o*4]=a.r[o],i[o*4+1]=a.g[o],i[o*4+2]=a.b[o],i[o*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,i);for(const o of[e.TEXTURE_MIN_FILTER,e.TEXTURE_MAG_FILTER])e.texParameteri(e.TEXTURE_2D,o,e.NEAREST);e.activeTexture(e.TEXTURE0),Oe.l1=a.key}if(c&&Oe.l3!==c.key){e.activeTexture(e.TEXTURE3),e.bindTexture(e.TEXTURE_3D,lt),e.pixelStorei(e.UNPACK_ALIGNMENT,1),e.texImage3D(e.TEXTURE_3D,0,e.RGB32F,c.size,c.size,c.size,0,e.RGB,e.FLOAT,c.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),Oe.l3=c.key}},key(a){if(!a){Pe=null;return}const[c,i,o]=[1,3,5].map(b=>parseInt(a.color.slice(b,b+2),16)),p=224/255;Pe={u:Math.round(-.168736*p*c-.331264*p*i+.5*p*o+128),v:Math.round(.5*p*c-.418688*p*i-.081312*p*o+128),similarity:a.similarity,blend:a.blend,spill:+a.spill.toFixed(3),blue:o>i}},mode(a){_e=a&&Qt[a]||0},shadow(a){U=a},glBegin(){wt??={base:ce(),a:ce(),b:ce()},le(null),e.bindTexture(e.TEXTURE_2D,wt.base),e.copyTexImage2D(e.TEXTURE_2D,0,e.RGBA8,0,0,m,g,0),e.clearColor(0,0,0,0),e.clear(e.COLOR_BUFFER_BIT)},glEnd(a,c,i){const o=wt;if(le(null),e.bindTexture(e.TEXTURE_2D,a==="a"?o.a:o.b),e.copyTexImage2D(e.TEXTURE_2D,0,e.RGBA8,0,0,m,g,0),e.disable(e.BLEND),j(X,null,[o.base],t=>e.uniform1i(t("tex"),0)),a==="a")return;let p=Rt.get(c);p||(p=h(G,mi(sr[c])),Rt.set(c,p)),yt??=De(),j(p,yt.fb,[o.a,o.b],t=>{e.uniform1i(t("glFrom"),0),e.uniform1i(t("glTo"),1),e.uniform1f(t("progress"),Math.max(0,Math.min(1,i))),e.uniform1f(t("ratio"),m/g),e.uniform1f(t("glPremul"),1)});const b=_e;_e=0,Je(yt.tex),_e=b},blurBegin(){be??=De(),le(be.fb),e.clearColor(0,0,0,0),e.clear(e.COLOR_BUFFER_BIT),Be=!0},blurEnd(){Be=!1;const a=Fe();e.disable(e.BLEND),j(x,a[0].fb,[be.tex],c=>e.uniform1i(c("tex"),0)),ut(0)},windows(a){K=a},edge(a){k=a},warpBig(a,c,i,o,p,b,t,l,u,w=[]){const n=Dt(u),v=m*u,S=g*u;e.bindFramebuffer(e.FRAMEBUFFER,n.plane.fb),e.viewport(0,0,v,S),e.disable(e.BLEND),e.clearColor(0,0,0,0),e.clear(e.COLOR_BUFFER_BIT),pt(a,c,i,o,p,b,t);const Y=Ot(l.map(([Ee,H])=>[Ee*u,H*u]),v,S);e.bindFramebuffer(e.FRAMEBUFFER,n.out.fb),e.viewport(0,0,v,S),e.useProgram(Qe),e.activeTexture(e.TEXTURE0),e.bindTexture(e.TEXTURE_2D,n.plane.tex);const W=Ye(Qe);if(e.uniform1i(W("tex"),0),e.uniform2f(W("size"),v,S),e.uniform1f(W("keepPre"),1),e.uniform4f(W("rnd"),0,0,0,0),e.uniformMatrix3fv(W("inv"),!1,[Y[0],Y[3],Y[6],Y[1],Y[4],Y[7],Y[2],Y[5],Y[8]]),e.drawArrays(e.TRIANGLE_STRIP,0,4),le(null),e.enable(e.BLEND),e.blendFuncSeparate(e.SRC_ALPHA,e.ONE_MINUS_SRC_ALPHA,e.ONE,e.ONE_MINUS_SRC_ALPHA),!w.length&&!_e&&!U.length&&!Be){j(Z,null,[n.out.tex],Ee=>{e.uniform1i(Ee("tex"),0),e.uniform1i(Ee("ss"),u)});return}const Q=Fe();e.disable(e.BLEND),j(Z,Q[0].fb,[n.out.tex],Ee=>{e.uniform1i(Ee("tex"),0),e.uniform1i(Ee("ss"),u)}),ut(f(w,0))},matte(a,c=[0,0,1,1]){Ke=a?c:null,a&&(e.activeTexture(e.TEXTURE1),e.bindTexture(e.TEXTURE_2D,Et),e.texImage2D(e.TEXTURE_2D,0,e.RGBA,e.RGBA,e.UNSIGNED_BYTE,a),e.activeTexture(e.TEXTURE0))},overlay(a,c){le(null),e.enable(e.BLEND),e.blendFuncSeparate(e.SRC_ALPHA,e.ONE_MINUS_SRC_ALPHA,e.ONE,e.ONE_MINUS_SRC_ALPHA),c&&(e.activeTexture(e.TEXTURE0),e.bindTexture(e.TEXTURE_2D,ft),e.texImage2D(e.TEXTURE_2D,0,e.RGBA,c.w,c.h,0,e.RGBA,e.UNSIGNED_BYTE,c.data)),j(st,null,c?[ft]:[],i=>{e.uniform1i(i("tex"),0),e.uniform1f(i("usetex"),c?1:0),e.uniform4f(i("colour"),...a??[0,0,0,0])})},finish(){e.finish()}}}let Ce="";const qa=()=>Ce;async function _a(m,{format:g,encode:y=null,tracks:e={},camera:q=null,signal:h,onProgress:L,frames:M,software:V=!1,liveMotion:ie=!1,range:se,only:me,sink:pe}){const x=performance.now(),{width:R,height:F,fps:C}=ao(g);Ce="layers",await Promise.all([...new Set(m.filter(r=>!r.colorBypass).flatMap(r=>Ht(r.grade).map(f=>f?.lut?.id)).filter(r=>!!r))].map(r=>nr(r))),Go(uo(m.filter(r=>!r.disabled)));const N=m.filter(r=>!r.disabled&&!Uo(r)),X=uo(N),te=qo(N.reduce((r,f)=>Math.max(r,f.start+f.duration),0)),oe=Math.round(te*C);if(!(oe>0)&&!M)throw Error("Empty timeline");const O=$o(q)?q:null,Ae=jo(X,e,O?r=>Xi(r,O,R,F):void 0),we=r=>Ae.find(f=>r>=f.start-1e-6&&r<f.start+f.duration-1e-6)??null,$e=()=>{if(h?.aborted)throw new DOMException("Export cancelled","AbortError")},ye=r=>ie&&!M&&!!r.motion&&!r._virtual&&!r.warped,We=r=>M||me!=="audio"&&(!se||r.start<se.to/C+1e-6&&r.start+r.duration>se.from/C-1e-6),je=new Cr,nt=[...N.filter(r=>Kt(r)&&!ye(r)),...Ho(N)].filter(We);nt.length&&await(await Nt(async()=>{const{renderTitleFrames:r}=await import("./titleFrames-aMG7HdVe.js");return{renderTitleFrames:r}},__vite__mapDeps([0,1,2,3,4,5,6,7,8,9]))).renderTitleFrames(nt,g,je,h);const Me=new Map;if(N.some(r=>ye(r)&&We(r))){const r=await Nt(()=>import("./titleFrames-aMG7HdVe.js"),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9]));for(const f of N.filter(k=>ye(k)&&We(k)))Me.set(f.id,r.liveMotion(f,N,g))}N.some(r=>r.kind==="model")&&await(await Nt(async()=>{const{render3DFrames:r}=await import("./timeline3dExport-DCOr6ARB.js");return{render3DFrames:r}},__vite__mapDeps([10,1,11,12,13,8,6,7,14,9]))).render3DFrames(m.filter(r=>!r.disabled),g,je,h,q);for(const r of X.filter(f=>f._group&&f.comp)){const f=[],k=Math.max(1,Math.ceil(r.duration*C-1e-6));await _a(dr(vr(r),{W:R,H:F}),{format:g,signal:h,frames:{times:Array.from({length:k},(d,E)=>xr(r,E/C)),push:(d,E)=>{f[d]=E}}}),je.frames.set(r.id,f)}const st=performance.now();$e(),Ce="mattes";const Qe=N.filter(r=>r.mask||r.person),Re=Qe.length?await Nt(()=>import("./rotoMatte-i-cJTYmK.js").then(r=>r.r),__vite__mapDeps([15,1,8,6,7,16])):null;Re&&await Re.prepareMattes(Qe);const He=Re?document.createElement("canvas"):null;Ce="media";const Ze=new Map,Se=new Map,Xe=new Map,it=r=>{let f=Ze.get(r);return f||(f=new _r({source:new Ar(r,{getRetryDelay:No}),formats:Fr}),Ze.set(r,f)),f};for(const r of N){if(r.kind==="video"&&!Se.has(r.url)){const f=await it(r.url).getPrimaryVideoTrack();f&&Se.set(r.url,new yr(f))}if(r.kind==="image"&&!Kt(r)&&!oo(r)&&!r._group&&!Xe.has(r.url)){const f=await createImageBitmap(await Ir(r.url,h),{imageOrientation:"from-image",premultiplyAlpha:"none",colorSpaceConversion:"none"});Xe.set(r.url,{source:f,w:f.width,h:f.height,close:()=>f.close()})}}const Z=new Map,ge=async(r,f)=>{const k=Me.get(r.id);if(k)return{source:await k.frame(Math.round((f-r.start)*C)),w:k.W,h:k.H};const d=je.frames.get(r.id);if(!d?.length)return null;let E=d.length===1?0:Math.max(0,Math.min(Math.round((f-r.start)*C),Math.ceil(r.duration*C)-1,d.length-1));for(;E>0&&d[E]==="=";)E--;const z=Z.get(r.id);if(z&&z.index===E)return z.pic;z?.pic?.close?.();const B=await createImageBitmap(await(await fetch(`data:image/webp;base64,${d[E]}`)).blob(),{premultiplyAlpha:"none",colorSpaceConversion:"none"}),ue={source:B,w:B.width,h:B.height,close:()=>B.close()};return Z.set(r.id,{index:E,pic:ue}),ue},ct=N.filter(r=>Vo(r)),Ve=ct.length?await Nt(()=>import("./captionLayout-CWPcbid-.js"),__vite__mapDeps([17,1])):null,ke=new Map,rt=new Map;if(Ve){for(const r of new Set(ct.flatMap(f=>[eo(Yo(f.captionStyle).font),eo(mo(f.captionStyle).font)])))if(await Ve.captionFontReady(r.id),!ke.has(r.id)){const f=new Uint8Array(await(await fetch(`/fonts/${r.file}`,{signal:h})).arrayBuffer());let k="";for(let d=0;d<f.length;d+=32768)k+=String.fromCharCode(...f.subarray(d,d+32768));ke.set(r.id,`@font-face{font-family:'${r.family}';src:url(data:font/${r.file.endsWith(".otf")?"otf":"ttf"};base64,${btoa(k)})}`)}}const Ye=new Map,A=async(r,f,k)=>{let d=Ye.get(f.start);if(!d||d.owner!==r){const _=pi(r,f.start,f.duration);d={plan:_,starts:xi(_.entries,C),owner:r},Ye.clear(),Ye.set(f.start,d)}const E=k-Math.round(f.start*C);let z=-1;for(let _=0;_<d.starts.length&&d.starts[_]<=E;_++)z=_;const B=d.plan.entries[z];if(!B||B.blank)return null;const ue=d.plan.social?d.plan.social.style:mo(r.captionStyle),K=d.plan.social?di(d.plan.social,B.gi,R,F,Ve.measureCaption):vi({width:R,height:F,text:B.text,style:ue,measure:Ve.measureCaption,second:B.second}),J=hi(K,ue,d.plan.social?B.scale:1,R,F,B.active,B.motion);let s=rt.get(J);if(!s){const _=eo(ue.font),re=URL.createObjectURL(new Blob([J.replace("<defs>",`<defs><style>${ke.get(_.id)??""}</style>`)],{type:"image/svg+xml"}));try{const xe=new Image(R,F);xe.src=re,await xe.decode();const ze=await createImageBitmap(xe,{premultiplyAlpha:"none"});s={source:ze,w:R,h:F,close:()=>ze.close()}}finally{URL.revokeObjectURL(re)}if(rt.size>64){const[xe,ze]=rt.entries().next().value;ze.close?.(),rt.delete(xe)}rt.set(J,s)}return s},ce=[0,0,1,1],ft=new Map,Et=["x","y","zoom","rot","sx","sy"],Ke=(r,f,k,d)=>{const E=`${r.id}@${f.start}`;let z=ft.get(E);if(!z){const ue=Math.max(1,Math.ceil(f.duration/.1-1e-6)),K=Array.from({length:ue+1},(_,re)=>f.start+f.duration*re/ue),J=K.map(_=>to(r,_-r.start,R,F)),s=_=>+(+_).toFixed(3);z={ts:K.map(_=>+_.toFixed(5)),v:Object.fromEntries(Et.map(_=>[_,J.map(re=>s(re[_]??(_==="sx"||_==="sy"?1:0)))]))},ft.set(E,z)}const B={...d};for(const ue of Et){const K=z.v[ue];if(K.every(re=>re===K[0])){B[ue]=K[0];continue}let J=z.ts.findIndex((re,xe)=>xe<z.ts.length-1&&k<z.ts[xe+1]);J<0&&(J=z.ts.length-2);const s=+(K[J+1]-K[J]).toFixed(3),_=z.ts[J+1]-z.ts[J];B[ue]=Math.abs(K[J+1]-K[J])<1e-4?K[J]:K[J]+s*Math.max(0,Math.min(1,(k-z.ts[J])/_))}return B},at=new Map,lt=new Map,Oe=(r,f,k,d=r,E="")=>{if(!gi(d))return Fo(d,R);const z=`${r.id}${E}@${f.start}`;let B=lt.get(z);B||(B=Ei(d,{offset:f.start-r.start,duration:f.duration,fps:C}),lt.set(z,B));const ue=k-Math.round(f.start*C),K=B.find(J=>ue>=J.from&&ue<J.to)??B[B.length-1];return Fo({effects:bi(d,K.t)},R)},bt=new Map,Gt=(r,f,k)=>{const d=`${r.id}@${f.start}`;bt.has(d)||bt.set(d,O?Bi(r,O,f.start,f.duration,R,F):null);const E=bt.get(d);return E?Oe(r,f,k,E,":dof"):[]},Pe=new Map,Qt=r=>{const f=JSON.stringify(r.grade);let k=Pe.get(f);if(!k){const d=B=>Array.from(B,ue=>+ue.toFixed(6)),E=Ri(r.grade)?_i(r.grade):null,z=r.grade.mixer&&Fi(r.grade.mixer)?Ai(r.grade.mixer):null;k={l1:E?{key:`1${f}`,r:d(E.r),g:d(E.g),b:d(E.b)}:null,l3:z?{key:`3${f}`,size:z.size,data:Float32Array.from(z.data,B=>+B.toFixed(6))}:null},Pe.set(f,k)}return k};let _e=null;const Tt=async(r,f,k)=>{const d=N.find(B=>B.id===r);if(!d||f<d.start||f>=d.start+d.duration)return null;if(Kt(d)){const B=await ge(d,f);return B&&{source:B.source,w:B.w,h:B.h}}if(d.kind==="image"){const B=Xe.get(d.url);return B?{source:B.source,w:B.w,h:B.h}:null}if(d.kind!=="video")return null;const E=await Mo(mt,Se,d,f,C,Math.max(k.start,d.start),k.duration);if(!E)return null;const z=E.toVideoFrame();return{source:z,w:E.displayWidth,h:E.displayHeight,close:()=>z.close()}};Ce="output";const U=Ra(R,F),wt=no(y,{width:R,height:F,fps:C},so),yt=y?.codec==="hevc",Rt=y?.container==="mov",Be=!M&&!pe&&te*wt/8>15e7&&!!navigator.storage?.getDirectory;let be=null,_t;if(Be){const r=await navigator.storage.getDirectory(),f=`gpu-export-${crypto.randomUUID()}.${Rt?"mov":"mp4"}`,k=await r.getFileHandle(f,{create:!0});be={dir:r,handle:k,name:f},_t=new Ao(await k.createWritable(),{chunked:!0,chunkSize:1<<20})}else _t=pe&&!M?new Ao(pe,{chunked:!0,chunkSize:1<<22}):new Sr;const ut=pe&&!M?!1:Be?"reserve":"in-memory",Je=new Dr({format:Rt?new Ur({fastStart:ut}):new kr({fastStart:ut}),target:_t}),Le=new Pr(U.canvas,{codec:yt?"hevc":"avc",bitrate:wt,keyFrameInterval:2,...yt?{hardwareAcceleration:"prefer-hardware"}:V?{hardwareAcceleration:"prefer-software"}:{}}),Fe=me==="audio"?0:Math.max(0,Math.min(oe,se?.from??0)),Ft=me==="audio"?0:Math.max(Fe,Math.min(oe,se?.to??oe));me!=="audio"&&Je.addVideoTrack(Le,{frameRate:C,...Be?{maximumPacketCount:Ft-Fe+8}:{}});const Dt=new Br({codec:"aac",bitrate:Lo});me!=="video"&&Je.addAudioTrack(Dt,Be?{maximumPacketCount:Math.ceil(te*zt/1024)+16}:{}),M||await Je.start();const Ut=M?new OffscreenCanvas(R,F):null,qt=Ut?.getContext("2d"),Zt=async r=>{qt.putImageData(new ImageData(U.pixels(),R,F),0,0);const f=new Uint8Array(await(await Ut.convertToBlob({type:"image/webp",quality:.9})).arrayBuffer());let k="";for(let d=0;d<f.length;d+=32768)k+=String.fromCharCode(...f.subarray(d,d+32768));M.push(r,btoa(k))},mt=new Map;let At=0;const kt={decode:0,matte:0,titles:0,captions:0,encode:0},De=async(r,f)=>{const k=performance.now();try{return await f}finally{kt[r]+=performance.now()-k}},le=(r,f)=>{const k=performance.now();try{return f()}finally{kt[r]+=performance.now()-k}};try{for(let f=M?0:Fe,k=M?M.times.length:Ft;f<k;f++){$e(),Ce="frame";const d=M?M.times[f]:f/C,E=we(d);U.clear(M?0:1);const z=E&&Ve?Ko(N,E.start+1e-5,e):void 0,B=z&&E?Wo(E.visuals,z.captionStyle?.layerTrack):-1,ue=async()=>{const K=z&&E&&await De("captions",A(z,E,f));K&&(U.shadow([]),U.edge(null),U.windows(null),U.matte(null),U.mode(void 0),U.key(null),U.grade(null,null),U.draw(K,ce,ce,1,1,!1,null,[]))};for(const[K,J]of(E?.visuals??[]).entries()){let s=J;if(K===B&&await ue(),s.kind==="audio")continue;const _=E?po(s,E.start,E.start+E.duration):null,re=_?s._txIn===_?"b":"a":null,xe=_?Qo(_,d):0,ze=_&&re?_.spec.gl?.id??null:null;ze&&U.glBegin();e:{if(s.kind==="model"){U.matte(null),U.edge(null),U.windows(null),U.mode(void 0),U.shadow(xo(s,R)),U.key(null),U.grade(null,null);const o=await ge(s,d);o&&U.draw(o,ce,ce,1,1,!1,null,[]);break e}const de=d-s.start,Ge=to(s,de,R,F),ae=(Zo(s)||Jo(s))&&!_&&!(O&&Vt(s))&&!s.pin?Ke(s,E,d,Ge):Ge;if(!(ae.opacity>1e-4))break e;if(oo(s)){U.adjust(ot(s),Oe(s,E,f),Math.min(1,ae.opacity));break e}let P=null,Ne=null;if(Kt(s)||s._group)P=await De("titles",ge(s,d));else if(s.kind==="image")P=Xe.get(s.url)??null;else if(s.kind==="video"){const o=await De("decode",Mo(mt,Se,s,d,C,E.start,E.duration));o&&(Ne=o.toVideoFrame(),P={source:Ne,w:o.displayWidth,h:o.displayHeight,bt709:Ne.colorSpace?.matrix?Ne.colorSpace.matrix==="bt709":o.displayHeight>=720})}if(!P)break e;if(ei(s)){const o=s.crop||{left:0,right:0,top:0,bottom:0},p=Math.floor(P.w*o.left/2)*2,b=Math.floor(P.h*o.top/2)*2,t=Math.max(2,Math.floor(P.w*(1-o.left-o.right)/2)*2),l=Math.max(2,Math.floor(P.h*(1-o.top-o.bottom)/2)*2),u=s.distort.displace?await Tt(s.distort.displace.map,d,E):null;_e??=wr();const w=_e.render({source:P.source,srcW:P.w,srcH:P.h,rect:[p,b,t,l],outW:t,outH:l,distort:s.distort,local:de,map:u?.source??null,matte:Re&&(s.mask||s.person)?Re.matteCanvas(s,de,He,!1,N):null});u?.close?.(),P={source:w,w:t,h:l,bt709:P.bt709},s={...s,crop:void 0,mask:void 0,person:void 0}}if(Re&&(s.mask||s.person)){const o=s.crop||{left:0,right:0,top:0,bottom:0},p=Math.max(2,Math.floor(P.w*(1-o.left-o.right)/2)*2),b=Math.max(2,Math.floor(P.h*(1-o.top-o.bottom)/2)*2);U.matte(le("matte",()=>Re.matteCanvas(s,de,He,!1,N)),[o.left,o.top,p/P.w,b/P.h])}else U.matte(null);U.mode(s.blend),U.key(s.key),U.shadow(xo(s,R));{const o=s.colorBypass?[]:Ht(s.grade).filter(io);U.windows(o.length?{key:`${s.id}@${f}`,list:Ht(s.grade),clip:s.id,src:s,frame:Math.round((d-s.start)*C),local:Math.round((d-s.start)*C)/C}:null)}if(vo(s)&&ho(go(s),de)>.001){const o=go(s),p=Re&&(s.mask||s.person),b=s.crop||{left:0,right:0,top:0,bottom:0},t=p?Math.max(2,Math.floor(p.mw*(1-b.left-b.right)/2)*2):P.w,l=p?Math.max(2,Math.floor(p.mh*(1-b.top-b.bottom)/2)*2):P.h,u=t>=l?Yt:Math.max(8,Math.trunc(Yt*t/l/8)*8),w=t>=l?Math.max(8,Math.trunc(Yt*l/t/8)*8):Yt,n=ti(o),v=ho(o,de),S=!!o.keys?.length||o.amount<.999;U.edge({key:`${s.id}@${f}`,ew:u,eh:w,band:n.band,glow:n.glow,k:o.glow,col:[1,3,5].map(Y=>parseInt(o.color.slice(Y,Y+2),16)/255),am:S?Math.trunc(255*v):255,harden:!!p,arc:o.cover>=.999&&!o.comet?null:{cen:p?oi(s):[.5,.5],start:(o.angle+o.sweep*de)*Math.PI/180,cover:o.cover,comet:!!o.comet}})}else U.edge(null);{const o=s.grade&&!s.colorBypass?Qt(s):null;U.grade(o?.l1??null,o?.l3??null)}if(s.pin&&!(O&&Vt(s))&&E&&Eo(s,N,E.start,R,F,O)){const o=Eo(s,N,d,R,F,O)??[[0,0],[0,0],[0,0],[0,0]],p=It(s,de),b=ii(s,N,R,F,O),t=s.pin.dive,l=b&&!s.pin.scene?[+(b[0]*R).toFixed(3),+(b[1]*F).toFixed(3),t?Math.max(0,Math.min(1,(d-t.at)/t.dur)):0]:null;U.warp(P,Ct([0,0,1,1],R,F),_o(s,P.w,P.h),Math.min(1,ae.opacity),p.k,p.white,ot(s),Oe(s,E,f),Ot(o,R,F),l),Ne?.close();break e}const Pt=ri(s,"rot")||ai(s),$t=()=>s.motionBlur?Tr(d,C).map(o=>({...to(s,o-s.start,R,F),rot:ae.rot,opacity:ae.opacity})):[ae];if((Pt||Math.abs(ae.rot||0)>1e-9)&&!(O&&Vt(s))){const o=It(s,de),p=_&&re?[...Do(_.spec[re],xe,R,F,d,_.spec.zoomAt),...re==="b"&&_.spec.mask?[So(_.spec.mask,xe)]:[]]:[];s.motionBlur&&U.blurBegin();for(const b of $t()){const t=hr(s,P.w,P.h,R,F,b,Pt);U.warp(P,Ct([0,0,1,1],R,F),_o(s,P.w,P.h),Math.min(1,ae.opacity),o.k,o.white,ot(s),[],Ot(t.quad,R,F),null,t.clip,p)}s.motionBlur&&U.blurEnd(),Ne?.close();break e}if(O&&Vt(s)){const o=ni(s,de,O,d,R,F);if(o){const p=Xt(s,P.w,P.h,R,F,{x:0,y:0,zoom:1}),b=It(s,de),t=Oe(s,E,f);let l=at.get(s.id);l===void 0&&(l=s.effects?.some(w=>!w.off)||s.mask||s.person||vo(s)||!s.colorBypass&&Ht(s.grade).some(io)?1:si(ci(s,O,R,F),P.w,P.h,R,F),at.set(s.id,l));const u=Gt(s,E,f);l>1&&!t.length?U.warpBig(P,Ct(p.dst,R,F),p.src,Math.min(1,ae.opacity),b.k,b.white,ot(s),o.quad,l,u):U.warp(P,Ct(p.dst,R,F),p.src,Math.min(1,ae.opacity),b.k,b.white,ot(s),t,Ot(o.quad,R,F),null,null,u)}Ne?.close();break e}if(s.motionBlur&&!_&&!Oe(s,E,f).length){const o=It(s,de);U.blurBegin();for(const p of $t()){const b=Xt(s,P.w,P.h,R,F,p);U.draw(P,b.dst,b.src,Math.min(1,ae.opacity),o.k,o.white,ot(s),[])}U.blurEnd(),Ne?.close();break e}const{dst:Bt,src:pt}=Xt(s,P.w,P.h,R,F,ae),qe=It(s,de),a=[...Oe(s,E,f),..._&&re?Do(_.spec[re],xe,R,F,d,_.spec.zoomAt):[],..._&&re==="b"&&_.spec.mask?[So(_.spec.mask,xe)]:[]],c=_&&re?_.spec[re]?.rot:null;if(c){const o=Wt(c,xe)??0;U.warp(P,Ct([0,0,1,1],R,F),pt,Math.min(1,ae.opacity),qe.k,qe.white,ot(s),[],Ot(gr(Bt,R,F,o),R,F),null,null,a),Ne?.close();break e}if(a.length>0&&!!E&&!s.layout&&!po(s,E.start,E.start+E.duration)&&fi(s,E.start,E.start+E.duration,R,F)){const o=Xt(s,P.w,P.h,R,F,{x:0,y:0,zoom:1}),p=Xt({},R,F,R,F,ae);U.draw(P,p.dst,o.src,Math.min(1,ae.opacity),qe.k,qe.white,ot(s),a,o.dst)}else U.draw(P,Bt,pt,Math.min(1,ae.opacity),qe.k,qe.white,ot(s),a);Ne?.close()}if(ze&&U.glEnd(re,ze,xe),_&&re==="b"){if(_.spec.light){const Ge=Math.max(2,Math.ceil(R/bo)),ae=Math.max(2,Math.ceil(F/bo));U.overlay(null,{data:li(_.spec,xe,Ge,ae),w:Ge,h:ae})}const de=_.spec.flash;if(de){const Ge=Wt(de.opacity,xe)??0;if(Ge>1e-4){const ae=parseInt(de.color.slice(1),16);U.overlay([(ae>>16&255)/255,(ae>>8&255)/255,(ae&255)/255,Math.min(1,Ge)],null)}}}}B>=0&&B>=(E?.visuals.length??0)&&await ue();for(const[K,J]of mt){const s=K.split(`
198
- `)[0],_=X.find(re=>re.id===s);(!_||d>_.start+_.duration+1)&&(J.current?.close(),J.peek?.close(),await J.iterator.return?.(),mt.delete(K))}if(M){await Zt(f);continue}Ce="video encode",await De("encode",Le.add((f-Fe)/C,1/C)),L?.((me==="video"?1:.9)*(f+1-Fe)/Math.max(1,Ft-Fe))}if(M)return{blob:new Blob,ms:{titles:0,video:0,audio:0,total:Math.round(performance.now()-x)}};const r=performance.now();if(me==="video")Le.close(),Ce="finalize",await Je.finalize();else{Ce="audio";const f=new Map(X.map(d=>[d.id,d])),k=await Aa(N.map(d=>f.get(d.id)??d),Ae,te,e,it,h);typeof g.loudness=="number"&&Er([k.getChannelData(0),k.getChannelData(1)],g.loudness,zt),Ce="audio encode",await Dt.add(k),At=performance.now()-r,me!=="audio"&&Le.close(),Dt.close(),Ce="finalize",await Je.finalize()}}catch(r){throw await Je.cancel().catch(()=>{}),be&&await be.dir.removeEntry(be.name).catch(()=>{}),r}finally{for(const r of mt.values())r.current?.close(),r.peek?.close();_e?.dispose();for(const r of Xe.values())r.close?.();for(const r of Z.values())r.pic?.close?.();for(const r of Me.values())r.close();for(const r of rt.values())r.close?.();for(const r of Ze.values())r.dispose?.()}L?.(1),Ce="file";const j=be?await be.handle.getFile():pe?new Blob([]):new Blob([_t.buffer],{type:Rt?"video/quicktime":"video/mp4"});be&&setTimeout(()=>void be.dir.removeEntry(be.name).catch(()=>{}),600*1e3);const Mt=performance.now()-x;return{blob:j,ms:{titles:Math.round(st-x),video:Math.round(Mt-(st-x)-At),audio:Math.round(At),total:Math.round(Mt),parts:Object.fromEntries(Object.entries(kt).map(([r,f])=>[r,Math.round(f)]))}}}function Fa(m,g,y,e,q){const h=[new Float32Array(Math.max(1,Math.round(q*y))),new Float32Array(Math.max(1,Math.round(q*y)))],L=Math.round(Oi*y);return g.forEach((M,V)=>{if(M.silent)return;const ie=Math.round((M.t1-M.t0)*y)+(V<g.length-1?L:0),se=Math.abs(M.rate),me=Math.round(M.t0*y),pe=Math.max(0,Math.round(((M.rate>0?M.s0:M.s0-se*ie/y)-e)*y)),x=Math.min(m[0].length,Math.round(((M.rate>0?M.s0+se*ie/y:M.s0)-e)*y));if(x-pe<2)return;const R=(x-pe)/ie,F=Math.round(.06*y),C=Math.max(0,pe-F),N=Math.min(m[0].length,x+F);let X=m.map(oe=>oe.slice(C,N));M.rate<0&&X.forEach(oe=>oe.reverse());const te=Math.round((M.rate<0?N-x:pe-C)/R);X=Bo(X,R,y).map(oe=>oe.subarray(te,te+ie));for(let oe=0;oe<2;oe++)for(let O=0;O<ie&&me+O<h[oe].length;O++){const Ae=(V>0&&O<L?O/L:1)*(V<g.length-1&&O>=ie-L?(ie-O)/L:1);h[oe][me+O]+=(X[oe][O]??0)*Ae}}),h}async function Aa(m,g,y,e,q,h){const L=new OfflineAudioContext({numberOfChannels:2,length:Math.max(1,Math.round(y*zt)),sampleRate:zt}),M=1/200,V=m.filter(x=>(x.kind==="video"||x.kind==="audio")&&!x.freeze&&!Po(x)&&(x.volume??1)>0),ie=x=>(x.kind==="video"||x.kind==="audio")&&!!x.url,se=new Map;for(const x of g.flatMap(R=>R.audios))!ie(x)||se.has(x.url)||se.set(x.url,await q(x.url).getPrimaryAudioTrack().then(R=>!!R,()=>!1));const me=x=>ie(x)&&!!se.get(x.url);for(const x of V){if(h?.aborted)throw new DOMException("Export cancelled","AbortError");const R=Math.max(2,Math.ceil(x.duration/M)+1),F=new Float32Array(R);let C=!1;const N=Li(x.track,e);for(let Z=0;Z<R;Z++){const ge=x.start+Math.min(x.duration,Z*M),ct=g.find(ke=>ge>=ke.start-1e-6&&ge<ke.start+ke.duration-1e-6),Ve=ct?.audios.some(ke=>ke.id===x.id)?Ni(x,ge-x.start)*N.gain/Ii(ct.audios,me):0;F[Z]=Ve,Ve>0&&(C=!0)}if(!C)continue;const X=await q(x.url).getPrimaryAudioTrack();if(!X)continue;const te=ko(x)?Ci(x,0,x.duration):null,oe=x.playbackRate||1,O=new Mr(X),Ae=te?te.flatMap(Z=>[Z.s0,Z.s1]):[],we=te?Math.max(0,Math.min(...Ae)-.2):x.inPoint||0,$e=te?Math.max(...Ae)+.2:we+x.duration*oe,ye=[];let We=we;for await(const Z of O.samples(we,$e))ye.length||(We=Z.timestamp),ye.push(Z.toAudioBuffer()),Z.close();if(!ye.length)continue;const je=ye[0].sampleRate,nt=ye.reduce((Z,ge)=>Z+ge.length,0);let Me=[new Float32Array(nt),new Float32Array(nt)],st=0;for(const Z of ye){for(let ge=0;ge<2;ge++)Me[ge].set(Z.getChannelData(Math.min(ge,Z.numberOfChannels-1)),st);st+=Z.length}te?Me=Fa(Me,te,je,We,x.duration):oe!==1&&(Me=Bo(Me,oe,je));const Qe=L.createBuffer(2,Me[0].length,je);for(let Z=0;Z<2;Z++)Qe.copyToChannel(Me[Z],Z);const Re=L.createBufferSource();Re.buffer=Qe;const He=L.createGain();He.gain.value=0,He.gain.setValueCurveAtTime(F,x.start,Math.max(M,x.duration));const Ze=L.createChannelSplitter(2),Se=L.createChannelMerger(2),Xe=L.createGain(),it=L.createGain();Xe.gain.value=N.left,it.gain.value=N.right,Re.connect(He),He.connect(Ze),Ze.connect(Xe,0),Ze.connect(it,1),Xe.connect(Se,0,0),it.connect(Se,0,1),Se.connect(L.destination),Re.start(x.start,te?0:Math.max(0,we-We)/oe,x.duration)}const pe=await L.startRendering();return br([pe.getChannelData(0),pe.getChannelData(1)]),pe}export{Oa as canEncodeH264,za as canEncodeHevc,Xa as canEncodeMp4,_a as exportOnGpu,so as gpuBitrate,qa as gpuExportStage,Ga as gpuExportSupported};
197
+ precision highp float;in vec2 uv;uniform sampler2D tex;out vec4 o;void main(){o=texture(tex,uv);}`,ya=["wipe","blinds","split","iris","diamond","burn"];function So(m,g){const y=Math.max(1e-4,m.feather??.05),e=m.progress?Wt(m.progress,g)??0:g,q=(m.angle??0)*Math.PI/180,h=Math.cos(q),L=Math.sin(q),M=ya.indexOf(m.type??""),V=m.type==="grid";return{type:"txMask",kind:V?7:M<0?6:M,e:e*(1+2*y)-y,f:y,inv:!!m.invert,cx:m.cx??.5,cy:m.cy??.5,c:h,s:L,h:.5*(Math.abs(h)+Math.abs(L)),count:m.count??(V?Pi:8)}}function Do(m,g,y,e,q=0,h){if(!m)return[];const L=V=>Wt(m[V],g)??0,M=[];if(m.zoomBlur&&M.push({type:"txZoom",taps:Mi(),w:L("zoomBlur"),...h?{c:[h.cx,1-h.cy]}:{}}),m.spinBlur){const V=Si(y,e),ie=se=>Math.max(2,Math.round(se/2)*2);M.push({type:"txSpin",a:V.map(se=>+se.a.toFixed(6)),sx:V.map(se=>ie(y*se.scale)/y),sy:V.map(se=>ie(e*se.scale)/e),w:L("spinBlur")})}if(m.dirBlur){const V=To*y/1280,ie=V/(1+V);M.push({type:"txDir",b:ie,reach:Math.min(512,Math.ceil(Math.log(.001)/Math.log(ie))),w:L("dirBlur")})}if(m.dirBlurV){const V=To*y/1280,ie=V/(1+V);M.push({type:"txDir",b:ie,reach:Math.min(512,Math.ceil(Math.log(.001)/Math.log(ie))),w:L("dirBlurV"),v:!0})}return m.blur&&M.push({type:"txGauss",sigma:Di*y/1280,w:L("blur")}),m.glitch&&M.push({type:"txGlitch",v:L("glitch"),fr:Math.floor(q*30+.5)}),m.rgbSplit&&M.push({type:"txRgb",px:Math.trunc(L("rgbSplit")*Ui*y/1280+.5)}),m.exposure&&M.push({type:"txExpo",gain:ki,w:L("exposure")}),m.invert&&M.push({type:"txInv",w:L("invert")}),M}function Ra(m,g){const y=new OffscreenCanvas(m,g),e=y.getContext("webgl2",{premultipliedAlpha:!1,preserveDrawingBuffer:!0,antialias:!1});if(!e)throw Error("WebGL2 unavailable");const q=(a,c)=>{const i=e.createShader(a);if(e.shaderSource(i,c),e.compileShader(i),!e.getShaderParameter(i,e.COMPILE_STATUS))throw Error(String(e.getShaderInfoLog(i)));return i},h=(a,c)=>{const i=e.createProgram();if(e.attachShader(i,q(e.VERTEX_SHADER,a)),e.attachShader(i,q(e.FRAGMENT_SHADER,c)),e.bindAttribLocation(i,0,"p"),e.linkProgram(i),!e.getProgramParameter(i,e.LINK_STATUS))throw Error(String(e.getProgramInfoLog(i)));return i},L=h(Xr,Or),M=h(G,oa),V=h(G,ia),ie=h(G,ra),se=h(G,aa),me=h(G,na),pe=h(G,sa),x=h(G,ca),R=h(G,fa),F=h(G,zr),C=h(G,Gr),N=h(G,qr),X=h(G,wa),te=h(G,Hr),oe=h(G,la),O=h(G,ua),Ae=h(G,ma),we=h(G,pa),je=h(G,da),ye=h(G,xa),We=h(G,jr),$e=h(G,$r),nt=h(G,Vr),Me=h(G,Yr),st=h(G,Kr),Qe=h(G,Wr),Re=h(G,Qr),He=h(G,Zr),Ze=h(G,Jr),Se=h(G,ea),Xe=h(G,ta),it=h(G,va),Z=h(G,ha),ge=h(G,ga),ct=h(G,Ta),Ve=h(G,Ea),ke=h(G,ba),rt=e.createBuffer();e.bindBuffer(e.ARRAY_BUFFER,rt),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 Ye=a=>c=>e.getUniformLocation(a,c),A=Ye(L);e.pixelStorei(e.UNPACK_PREMULTIPLY_ALPHA_WEBGL,!1);const ce=()=>{const a=e.createTexture();e.bindTexture(e.TEXTURE_2D,a);for(const[c,i]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,c,i);return a},ft=ce(),Et=ce();let Ke=null;const at=ce(),lt=e.createTexture(),Oe={l1:"",l3:""};let bt=!1,Gt=!1,Pe=null;const Qt={add:1,screen:2,multiply:3,overlay:4,lighten:5,darken:6,difference:7,exclusion:8};let _e=0;const Tt=ce();let U=[],wt=null,yt=null;const Rt=new Map;let Be=!1,be=null;const _t=a=>{const c=Fe(),i=(a+1)%3,o=(a+2)%3;for(const p of U){let b=a;e.disable(e.BLEND),p.sigma>.05&&($(F,c[i].fb,[c[a].tex],w=>{e.uniform1i(w("tex"),0),e.uniform2f(w("step"),1/m,0),e.uniform1f(w("sigma"),p.sigma)}),$(F,c[o].fb,[c[i].tex],w=>{e.uniform1i(w("tex"),0),e.uniform2f(w("step"),0,1/g),e.uniform1f(w("sigma"),p.sigma)}),b=o),le(null),e.enable(e.BLEND),e.blendFuncSeparate(e.SRC_ALPHA,e.ONE_MINUS_SRC_ALPHA,e.ONE,e.ONE_MINUS_SRC_ALPHA);const[t,l,u]=[1,3,5].map(w=>parseInt(p.color.slice(w,w+2),16)/255);$(M,null,[c[b].tex],w=>{e.uniform1i(w("tex"),0),e.uniform2f(w("off"),Math.trunc(p.dx)/m,-Math.trunc(p.dy)/g),e.uniform3f(w("col"),t,l,u),e.uniform1f(w("op"),p.opacity),e.uniform1f(w("times"),p.times),e.uniform2f(w("dil"),p.dilate?+(rr*255).toFixed(3):0,p.dilate?+(1/ar).toFixed(3):0)})}},ut=a=>{const c=Fe();if(Be){le(be.fb),e.enable(e.BLEND),e.blendFunc(e.ONE,e.ONE),$(pe,be.fb,[c[a].tex],i=>e.uniform1i(i("tex"),0)),e.blendFuncSeparate(e.SRC_ALPHA,e.ONE_MINUS_SRC_ALPHA,e.ONE,e.ONE_MINUS_SRC_ALPHA);return}if(U.length&&_t(a),_e){Je(c[a].tex);return}le(null),e.enable(e.BLEND),e.blendFuncSeparate(e.SRC_ALPHA,e.ONE_MINUS_SRC_ALPHA,e.ONE,e.ONE_MINUS_SRC_ALPHA),$(X,null,[c[a].tex],i=>e.uniform1i(i("tex"),0))},Je=a=>{le(null),e.bindTexture(e.TEXTURE_2D,Tt),e.copyTexImage2D(e.TEXTURE_2D,0,e.RGBA8,0,0,m,g,0),e.disable(e.BLEND),$(it,null,[a,Tt],c=>{e.uniform1i(c("top"),0),e.uniform1i(c("bg"),1),e.uniform1i(c("mode"),_e)})};let Le=null;const Fe=()=>Le??=[De(),De(),De()],Ft=new Map,Dt=a=>{let c=Ft.get(a);if(c)return c;const i=()=>{const o=ce();e.texImage2D(e.TEXTURE_2D,0,e.RGBA8,m*a,g*a,0,e.RGBA,e.UNSIGNED_BYTE,null);const p=e.createFramebuffer();return e.bindFramebuffer(e.FRAMEBUFFER,p),e.framebufferTexture2D(e.FRAMEBUFFER,e.COLOR_ATTACHMENT0,e.TEXTURE_2D,o,0),{tex:o,fb:p}};return c={plane:i(),out:i()},Ft.set(a,c),c},Ut=new Map,qt=new Map,Zt=a=>{let c=Ut.get(a.key);if(c)return c;c=ce();const i=new Uint8Array(256*3);(a.lut??[]).forEach((o,p)=>i.set(o,p*256)),e.pixelStorei(e.UNPACK_ALIGNMENT,1),e.texImage2D(e.TEXTURE_2D,0,e.R8,256,3,0,e.RED,e.UNSIGNED_BYTE,i),e.pixelStorei(e.UNPACK_ALIGNMENT,4);for(const o of[e.TEXTURE_MIN_FILTER,e.TEXTURE_MAG_FILTER])e.texParameteri(e.TEXTURE_2D,o,e.NEAREST);return Ut.set(a.key,c),c},mt=(a,c)=>{const i=`${a}x${c}`;let o=qt.get(i);if(o)return o;const p=ce();e.texImage2D(e.TEXTURE_2D,0,e.RGBA8,a,c,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 b=e.createFramebuffer();return e.bindFramebuffer(e.FRAMEBUFFER,b),e.framebufferTexture2D(e.FRAMEBUFFER,e.COLOR_ATTACHMENT0,e.TEXTURE_2D,p,0),o={tex:p,fb:b},qt.set(i,o),o},At=new Map,kt=(a,c)=>{const i=`${a}x${c}`;let o=At.get(i);return o||(o=[0,1].map(()=>{const p=ce();e.texImage2D(e.TEXTURE_2D,0,e.RGBA8,a,c,0,e.RGBA,e.UNSIGNED_BYTE,null);const b=e.createFramebuffer();return e.bindFramebuffer(e.FRAMEBUFFER,b),e.framebufferTexture2D(e.FRAMEBUFFER,e.COLOR_ATTACHMENT0,e.TEXTURE_2D,p,0),{tex:p,fb:b}}),At.set(i,o),o)},De=()=>{const a=ce();e.texImage2D(e.TEXTURE_2D,0,e.RGBA8,m,g,0,e.RGBA,e.UNSIGNED_BYTE,null);const c=e.createFramebuffer();return e.bindFramebuffer(e.FRAMEBUFFER,c),e.framebufferTexture2D(e.FRAMEBUFFER,e.COLOR_ATTACHMENT0,e.TEXTURE_2D,a,0),{tex:a,fb:c}},le=a=>{e.bindFramebuffer(e.FRAMEBUFFER,a),e.viewport(0,0,m,g)},$=(a,c,i,o)=>Mt(a,c,m,g,i,o),Mt=(a,c,i,o,p,b)=>{e.bindFramebuffer(e.FRAMEBUFFER,c),e.viewport(0,0,i,o),e.useProgram(a);const t=Ye(a);p.forEach((l,u)=>{e.activeTexture(e.TEXTURE0+u),e.bindTexture(e.TEXTURE_2D,l)}),b(t),e.drawArrays(e.TRIANGLE_STRIP,0,4),p.length>1&&r(),e.activeTexture(e.TEXTURE0)},r=()=>{e.activeTexture(e.TEXTURE1),e.bindTexture(e.TEXTURE_2D,Et),e.activeTexture(e.TEXTURE2),e.bindTexture(e.TEXTURE_2D,at),e.activeTexture(e.TEXTURE3),e.bindTexture(e.TEXTURE_3D,lt),e.activeTexture(e.TEXTURE0)},f=(a,c=0)=>{const i=Fe();let o=c;const p=(t,l,u,w)=>{$(F,i[l].fb,[i[t].tex],n=>{e.uniform1i(n("tex"),0),e.uniform2f(n("step"),1/m,0),e.uniform1f(n("sigma"),w)}),$(F,i[u].fb,[i[l].tex],n=>{e.uniform1i(n("tex"),0),e.uniform2f(n("step"),0,1/g),e.uniform1f(n("sigma"),w)})},b=(t,l,u,w)=>$(Me,i[u].fb,[i[t].tex,i[l].tex],n=>{e.uniform1i(n("a"),0),e.uniform1i(n("b"),1),e.uniform1f(n("w"),w)});for(const t of a){const[l,u,w]=[o,(o+1)%3,(o+2)%3];if(t.type==="blur"){t.sigma>.05&&(p(l,u,w,t.sigma),o=w);continue}if(t.type==="colour"){const n=Zt(t);$(He,i[u].fb,[i[l].tex,n],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(S=>[S[0],S[1],S[2],S[3]??0]))}),o=u;continue}if(t.type==="txRgb"){t.px>0&&($(ge,i[u].fb,[i[l].tex],n=>{e.uniform1i(n("tex"),0),e.uniform1i(n("px"),t.px)}),o=u);continue}if(t.type==="txGlitch"){t.v>1e-4&&($(Ve,i[u].fb,[i[l].tex],n=>{e.uniform1i(n("tex"),0),e.uniform2f(n("size"),m,g),e.uniform2f(n("msize"),Math.max(2,Math.round(m/4)),Math.max(2,Math.round(g/4))),e.uniform1f(n("v"),t.v),e.uniform1f(n("fr"),t.fr)}),o=u);continue}if(t.type==="txInv"){t.w>1e-4&&($(ct,i[u].fb,[i[l].tex],n=>{e.uniform1i(n("tex"),0),e.uniform1f(n("w"),Math.min(1,t.w))}),o=u);continue}if(t.type==="shift"){$(Ze,i[u].fb,[i[l].tex],n=>{e.uniform1i(n("tex"),0),e.uniform1i(n("px"),t.px)}),o=u;continue}if(t.type==="pixel"){const n=Math.ceil(m/t.block),v=Math.ceil(g/t.block),S=mt(n,v);e.bindFramebuffer(e.FRAMEBUFFER,S.fb),e.viewport(0,0,n,v),e.useProgram(Se),e.activeTexture(e.TEXTURE0),e.bindTexture(e.TEXTURE_2D,i[l].tex),e.uniform1i(e.getUniformLocation(Se,"tex"),0),e.uniform1i(e.getUniformLocation(Se,"b"),t.block),e.uniform2i(e.getUniformLocation(Se,"small"),n,v),e.drawArrays(e.TRIANGLE_STRIP,0,4),$(Xe,i[u].fb,[S.tex],Y=>{e.uniform1i(Y("small"),0),e.uniform1i(Y("b"),t.block),e.uniform2f(Y("size"),m,g)}),o=u;continue}if(t.type==="txMask"){$(Re,i[u].fb,[i[l].tex],n=>{e.uniform1i(n("tex"),0),e.uniform2f(n("size"),m,g),e.uniform1i(n("kind"),t.kind),e.uniform1f(n("e"),t.e),e.uniform1f(n("f"),t.f),e.uniform1f(n("inv"),t.inv?1:0),e.uniform2f(n("ctr"),t.cx,t.cy),e.uniform3f(n("csh"),t.c,t.s,t.h),e.uniform1f(n("count"),t.count)}),o=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 n=u;t.type==="txGauss"?(p(l,u,w,t.sigma),n=w):t.type==="txDir"?$(We,i[u].fb,[i[l].tex],S=>{e.uniform1i(S("tex"),0),t.v?e.uniform2f(S("step"),0,1/g):e.uniform2f(S("step"),1/m,0),e.uniform1f(S("b"),t.b),e.uniform1i(S("reach"),t.reach)}):t.type==="txZoom"?$($e,i[u].fb,[i[l].tex],S=>{e.uniform1i(S("tex"),0),e.uniform1fv(S("taps"),t.taps),e.uniform1i(S("n"),t.taps.length),e.uniform2f(S("ctr"),t.c?.[0]??.5,t.c?.[1]??.5)}):t.type==="txSpin"?$(ke,i[u].fb,[i[l].tex],S=>{e.uniform1i(S("tex"),0),e.uniform2f(S("size"),m,g),e.uniform1fv(S("a"),t.a),e.uniform1fv(S("sx"),t.sx),e.uniform1fv(S("sy"),t.sy)}):$(nt,i[u].fb,[i[l].tex],S=>{e.uniform1i(S("tex"),0),e.uniform1f(S("gain"),t.gain)});const v=n===w?u:w;b(l,n,v,Math.min(1,t.w)),o=v;continue}if(t.type==="burst"){const{w:n,h:v}=ur(m,g),[S,Y]=kt(n,v),W=cr(fr.burst*t.amount).map(Q=>lr(n,v,Q));$(C,i[u].fb,[i[l].tex],Q=>{e.uniform1i(Q("tex"),0),e.uniform1f(Q("lo"),t.lo),e.uniform1f(Q("k"),t.k)}),Mt(X,S.fb,n,v,[i[u].tex],Q=>e.uniform1i(Q("tex"),0)),Mt(te,Y.fb,n,v,[S.tex],Q=>{e.uniform1i(Q("tex"),0),e.uniform1i(Q("n"),W.length),e.uniform1fv(Q("sx"),W.map(Ee=>Ee.sw/n)),e.uniform1fv(Q("sy"),W.map(Ee=>Ee.sh/v)),e.uniform3f(Q("gain"),...pr(t.amount))}),$(N,i[w].fb,[i[l].tex,Y.tex],Q=>{e.uniform1i(Q("a"),0),e.uniform1i(Q("b"),1),e.uniform1f(Q("amount"),+t.amount.toFixed(4))}),o=w;continue}$(C,i[u].fb,[i[l].tex],n=>{e.uniform1i(n("tex"),0),e.uniform1f(n("lo"),t.lo),e.uniform1f(n("k"),t.k)}),p(u,w,u,t.sigma),$(N,i[w].fb,[i[l].tex,i[u].tex],n=>{e.uniform1i(n("a"),0),e.uniform1i(n("b"),1),e.uniform1f(n("amount"),t.amount)}),o=w}return o};let k=null,d="",E=[],z="";const B=(a,c)=>{if(z!==`${a}x${c}`){for(const i of E)e.deleteTexture(i.tex),e.deleteFramebuffer(i.fb);E=Array.from({length:4},()=>{const i=ce();e.texImage2D(e.TEXTURE_2D,0,e.RGBA8,a,c,0,e.RGBA,e.UNSIGNED_BYTE,null);const o=e.createFramebuffer();return e.bindFramebuffer(e.FRAMEBUFFER,o),e.framebufferTexture2D(e.FRAMEBUFFER,e.COLOR_ATTACHMENT0,e.TEXTURE_2D,i,0),{tex:i,fb:o}}),z=`${a}x${c}`}return E},ue=(a,c,i,o)=>{const p=e.getParameter(e.FRAMEBUFFER_BINDING),b=e.getParameter(e.VIEWPORT),t=e.isEnabled(e.BLEND),l=B(o.ew,o.eh),u=(n,v,S,Y)=>{e.bindFramebuffer(e.FRAMEBUFFER,l[v].fb),e.viewport(0,0,o.ew,o.eh),e.useProgram(n);const W=Ye(n);S.forEach((Q,Ee)=>{e.activeTexture(e.TEXTURE0+Ee),e.bindTexture(e.TEXTURE_2D,l[Q].tex)}),Y(W),e.drawArrays(e.TRIANGLE_STRIP,0,4),S.length>1&&r(),e.activeTexture(e.TEXTURE0)};e.disable(e.BLEND),e.bindFramebuffer(e.FRAMEBUFFER,l[0].fb),e.viewport(0,0,o.ew,o.eh),e.clearColor(0,0,0,0),e.clear(e.COLOR_BUFFER_BIT);{const n=Bt(a,i);e.bindFramebuffer(e.FRAMEBUFFER,l[0].fb),e.viewport(0,0,o.ew,o.eh),e.disable(e.BLEND),qe(a,[0,0,1,1],c,1,1,!1,n==="win"?null:i,n)}u(V,1,[0],n=>{e.uniform1i(n("tex"),0),e.uniform1f(n("harden"),o.harden?tr:0)});const w=(n,v,S,Y)=>{u(ie,v,[n],W=>{e.uniform1i(W("tex"),0),e.uniform2i(W("dir"),1,0),e.uniform1f(W("sigma"),Y)}),u(ie,S,[v],W=>{e.uniform1i(W("tex"),0),e.uniform2i(W("dir"),0,1),e.uniform1f(W("sigma"),Y)})};w(1,2,3,o.band),u(se,2,[1,3],n=>{e.uniform1i(n("a"),0),e.uniform1i(n("b"),1);const v=o.arc;e.uniform1f(n("arc"),v?1:0),v&&(e.uniform2f(n("cw"),o.ew/ro,o.eh/ro),e.uniform2f(n("cen"),v.cen[0],v.cen[1]),e.uniform1f(n("start"),v.start),e.uniform1f(n("cover"),v.cover),e.uniform1f(n("comet"),v.comet?1:0),e.uniform1f(n("feather"),or*v.cover))}),w(2,1,3,o.glow),u(me,1,[0,2,3],n=>{e.uniform1i(n("pic"),0),e.uniform1i(n("band"),1),e.uniform1i(n("glow"),2),e.uniform3f(n("col"),...o.col),e.uniform1f(n("k"),o.k),e.uniform1f(n("am"),o.am)}),e.bindFramebuffer(e.FRAMEBUFFER,p),e.viewport(b[0],b[1],b[2],b[3]),t&&e.enable(e.BLEND)};let K=null,J="",s=null,_=[],re="";const xe=new Map,ze=new Map,de=new Map,Ge=new Map,ae=new Map,P=new Map,Ne=ce(),Pt=(a,c)=>{const i=ce();e.texImage2D(e.TEXTURE_2D,0,e.RGBA8,a,c,0,e.RGBA,e.UNSIGNED_BYTE,null);const o=e.createFramebuffer();return e.bindFramebuffer(e.FRAMEBUFFER,o),e.framebufferTexture2D(e.FRAMEBUFFER,e.COLOR_ATTACHMENT0,e.TEXTURE_2D,i,0),{tex:i,fb:o}},jt=(a,c,i)=>{const o=e.getParameter(e.FRAMEBUFFER_BINDING),p=e.getParameter(e.VIEWPORT),b=e.isEnabled(e.BLEND),t=a.w,l=a.h;if(re!==`${t}x${l}`){for(const H of _)e.deleteTexture(H.tex),e.deleteFramebuffer(H.fb);_=Array.from({length:7},()=>Pt(t,l)),re=`${t}x${l}`}e.disable(e.BLEND),e.bindFramebuffer(e.FRAMEBUFFER,_[0].fb),e.viewport(0,0,t,l),e.clearColor(0,0,0,0),e.clear(e.COLOR_BUFFER_BIT),qe(a,[0,1,1,-1],[0,0,1,1],1,1,!1,c,"base");let u=0;const w=H=>[H[0],H[3],H[6],H[1],H[4],H[7],H[2],H[5],H[8]],n=(H,j,xt,et)=>{e.bindFramebuffer(e.FRAMEBUFFER,_[j].fb),e.viewport(0,0,t,l),e.useProgram(H);const Ie=Ye(H);xt.forEach((dt,vt)=>{e.activeTexture(e.TEXTURE0+vt),e.bindTexture(dt.d3?e.TEXTURE_3D:e.TEXTURE_2D,dt.t)}),et(Ie),e.drawArrays(e.TRIANGLE_STRIP,0,4),r()},v=H=>({t:_[H].tex}),S=(H,j,xt,et)=>{n(F,j,[v(H)],Ie=>{e.uniform1i(Ie("tex"),0),e.uniform2f(Ie("step"),1/t,0),e.uniform1f(Ie("sigma"),et)}),n(F,xt,[v(j)],Ie=>{e.uniform1i(Ie("tex"),0),e.uniform2f(Ie("step"),0,1/l),e.uniform1f(Ie("sigma"),et)})},Y=i.list,W=Y.map(H=>io(H)),Q=zi(Y),Ee=new Set;for(const[H,j]of Y.entries()){const xt=Q[H];if(H===xt&&Y.some((T,D)=>D>H&&Q[D]===H&&W[D])&&(n(X,2,[v(u)],T=>e.uniform1i(T("tex"),0)),Ee.add(H)),!W[H])continue;const et=H!==xt&&Ee.has(xt)?j.branch:void 0,Ie=et?2:u;let dt=Ne,vt=[1,1];if(j.qualifier){const T=Math.max(2,Math.trunc((t+St-1)/St)),D=Math.max(2,Math.trunc((l+St-1)/St)),I=`${T}x${D}`;let ne=xe.get(I);ne||(ne=Pt(T,D),xe.set(I,ne));const ee=j.qualifier,ve=Math.max(.001,ee.soft??.3),Ue=j.window,gt=-(Ue?.rot??0)*Math.PI/180;e.bindFramebuffer(e.FRAMEBUFFER,ne.fb),e.viewport(0,0,T,D),e.useProgram(R),e.activeTexture(e.TEXTURE0),e.bindTexture(e.TEXTURE_2D,_[Ie].tex);const Te=Ye(R);e.uniform1i(Te("tex"),0),e.uniform2f(Te("big"),t,l),e.uniform2f(Te("small"),T,D),e.uniform4f(Te("q1"),ee.hue,ee.hueWidth,Math.max(1,ve*60),Math.max(.001,ve*.2)),e.uniform4f(Te("q2"),ee.satMin,ee.satMax,ee.lumMin,ee.lumMax),e.uniform1f(Te("useQ"),1),e.uniform1f(Te("useW"),Ue?1:0),Ue&&(e.uniform4f(Te("w1"),Ue.cx,Ue.cy,Math.max(1e-4,Ue.w/2),Math.max(.001,Ue.feather??.2)),e.uniform4f(Te("w2"),Math.cos(gt),Math.sin(gt),Math.max(1e-4,Ue.h/2),Ue.type==="gradient"?2:Ue.type==="rect"?1:0)),e.uniform1f(Te("inv"),j.invert?1:0),e.drawArrays(e.TRIANGLE_STRIP,0,4),dt=ne.tex,vt=[T*St,D*St]}else if(!j.whole&&Gi(j)&&j.window?.type!=="person"){const T=`${i.clip}#${H}`,D=`${t}x${l}@${i.local??0}`,I=yo,ne=Math.max(2,Math.min(yo*2,Math.round(I*l/t)));let ee=Ge.get(T);if(ee||(ee={tex:ce(),at:""},Ge.set(T,ee)),ee.at!==D){const ve=wo(j,i.src,i.local??0,l/t,null),Ue=new Uint8Array(I*ne);for(let gt=0;gt<ne;gt++)for(let Te=0;Te<I;Te++)Ue[gt*I+Te]=Math.round(ve((Te+.5)/I,(gt+.5)/ne,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,ne,0,e.RED,e.UNSIGNED_BYTE,Ue),e.pixelStorei(e.UNPACK_ALIGNMENT,4),ee.at=D}dt=ee.tex,vt=[t,l]}else if(!j.whole){const T=Ro(j)?i.src?.depthMap:void 0,D=`${i.clip}#${H}@${t}x${l}${T?`@${T.at}:${T.data.length}:${T.data.slice(0,24)}`:""}`;let I=ze.get(D);if(!I){const ne=qi(j,t,l,Ro(j)?wo(j,i.src,0,l/t):null);I=ce(),e.pixelStorei(e.UNPACK_ALIGNMENT,1),e.texImage2D(e.TEXTURE_2D,0,e.R8,ne.w4,ne.h4,0,e.RED,e.UNSIGNED_BYTE,ne.px),e.pixelStorei(e.UNPACK_ALIGNMENT,4),ze.set(D,I)}dt=I,vt=[t,l]}const Lt=j.adjust??{},fo=ji(j),Jt=`${i.clip}#${H}`;let $t=de.get(Jt);if(fo&&!$t){const T=new Float32Array(1024);for(let D=0;D<256;D++)["r","g","b"].forEach((I,ne)=>{T[D*4+ne]=+$i(Lt,I,D/255,j.wheels,j.curves).toFixed(6)}),T[D*4+3]=1;$t=ce(),e.texImage2D(e.TEXTURE_2D,0,e.RGBA32F,256,1,0,e.RGBA,e.FLOAT,T);for(const D of[e.TEXTURE_MIN_FILTER,e.TEXTURE_MAG_FILTER])e.texParameteri(e.TEXTURE_2D,D,e.NEAREST);de.set(Jt,$t)}let ht=null;if(Hi(j)){const T=`${Jt}:${JSON.stringify([j.cst,j.look,j.lut,j.mixer])}`;if(ht=ae.get(T)??null,!ht){const D=Vi(j,I=>mr(I));if(!D)throw Error(`LUT "${j.lut?.name??""}" chưa tải xong`);ht=e.createTexture(),e.activeTexture(e.TEXTURE4),e.bindTexture(e.TEXTURE_3D,ht),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),ae.set(T,ht)}}const{sat:Co,rot:Xo}=Yi(Lt.saturation??1,Lt.hue??0);n(oe,3,[v(Ie),{t:$t??at},{t:ht??lt,d3:!0}],T=>{e.uniform1i(T("tex"),0),e.uniform1i(T("lut"),1),e.uniform1i(T("t3"),2),e.uniform1f(T("useT"),ht?1:0),e.uniform1f(T("useL"),fo?1:0),e.uniform1f(T("useS"),(Lt.saturation??1)!==1?1:0),e.uniform1f(T("useR"),(Lt.hue??0)!==0?1:0),e.uniformMatrix3fv(T("sat"),!1,w(Co)),e.uniformMatrix3fv(T("rot"),!1,w(Xo))}),e.activeTexture(e.TEXTURE2),e.bindTexture(e.TEXTURE_3D,null),e.activeTexture(e.TEXTURE0),r();let fe=3;const tt=(T,D)=>[3,4,5].find(I=>I!==T&&I!==D);if((j.blur??0)>0){const T=tt(fe),D=tt(fe,T);S(fe,T,D,Math.max(.1,+((j.blur??0)*Ki*t).toFixed(3))),fe=D}const lo=Wi({sharpness:j.sharpen??0});if(lo){const T=tt(fe);n(Ae,T,[v(fe)],D=>{e.uniform1i(D("tex"),0),e.uniform1fv(D("k"),lo),e.uniform1f(D("rdiv"),1/ir)}),fe=T}const he=j.fx?Qi(j.fx,t):null;if(he&&(he.type==="glow"||he.type==="halation")){const T=tt(fe),D=tt(fe,T);n(C,T,[v(fe)],ve=>{e.uniform1i(ve("tex"),0),e.uniform1f(ve("lo"),he.lo),e.uniform1f(ve("k"),he.k)});let I=T;he.tint&&(n(He,D,[v(T),{t:at}],ve=>{e.uniform1i(ve("tex"),0),e.uniform1i(ve("lut"),1),e.uniform1f(ve("useM"),1),e.uniform1f(ve("useL"),0),e.uniform1fv(ve("m"),he.tint.flat())}),I=D),S(I,I===T?D:T,I,he.sigma);const ee=6;n(N,ee,[v(fe),v(I)],ve=>{e.uniform1i(ve("a"),0),e.uniform1i(ve("b"),1),e.uniform1f(ve("amount"),he.amount)}),n(X,3,[v(ee)],ve=>e.uniform1i(ve("tex"),0)),fe=3}else if(he?.type==="grain"){const T=Zi(i.frame??0),D=`${T}:${t}x${l}:${he.amp}`;let I=P.get(D);if(!I){if(P.size>8){for(const ee of P.values())e.deleteTexture(ee);P.clear()}I=ce(),e.pixelStorei(e.UNPACK_ALIGNMENT,1),e.texImage2D(e.TEXTURE_2D,0,e.R8,t,l,0,e.RED,e.UNSIGNED_BYTE,Ji(T,t,l,he.amp)),e.pixelStorei(e.UNPACK_ALIGNMENT,4),P.set(D,I)}const ne=tt(fe);n(we,ne,[v(fe),{t:I}],ee=>{e.uniform1i(ee("tex"),0),e.uniform1i(ee("grain"),1)}),fe=ne}else if(he?.type==="denoise"){const T=tt(fe),D=tt(fe,T);S(fe,T,D,he.sigma),n(je,6,[v(fe),v(D)],I=>{e.uniform1i(I("tex"),0),e.uniform1i(I("soft"),1),e.uniform1f(I("t"),he.t)}),n(X,3,[v(6)],I=>e.uniform1i(I("tex"),0)),fe=3}else if(he?.type==="swirl"){const T=D=>Math.max(2,Math.round(D/2)*2);for(const D of er(t,l,he.deg)){const I=tt(fe);n(ke,I,[v(fe)],ne=>{e.uniform1i(ne("tex"),0),e.uniform2f(ne("size"),t,l),e.uniform1fv(ne("a"),D.map(ee=>+ee.a.toFixed(6))),e.uniform1fv(ne("sx"),D.map(ee=>T(t*ee.scale)/t)),e.uniform1fv(ne("sy"),D.map(ee=>T(l*ee.scale)/l))}),fe=I}}const Oo=et==="parallel"?2:u,zo=et==="parallel"?6:1-u;n(O,zo,[v(Oo),v(fe),{t:dt}],T=>{e.uniform1i(T("base"),0),e.uniform1i(T("over"),1),e.uniform1i(T("mask"),2),e.uniform2f(T("msz"),vt[0],vt[1]),e.uniform1f(T("full"),j.whole?1:0)}),et==="parallel"&&n(ye,1-u,[v(u),v(6),v(2)],T=>{e.uniform1i(T("res"),0),e.uniform1i(T("outp"),1),e.uniform1i(T("inp"),2)}),u=1-u}s=_[u].tex,e.bindFramebuffer(e.FRAMEBUFFER,o),e.viewport(p[0],p[1],p[2],p[3]),b&&e.enable(e.BLEND)},Bt=(a,c)=>K?(J!==K.key&&(jt(a,c,K),J=K.key),"win"):"pic",pt=(a,c,i,o,p,b,t)=>{if(!k){const S=Bt(a,t);qe(a,c,i,o,p,b,S==="win"?null:t,S);return}const l=Ke??[0,0,1,1];d!==k.key&&(ue(a,l,t,k),d=k.key);const u=(i[0]-l[0])/l[2],w=(i[1]-l[1])/l[3],n=i[2]/l[2],v=i[3]/l[3];qe(a,c,[u,1-w,n,-v],o,p,b,null,"edge")},qe=(a,c,i,o,p,b,t,l)=>{const u=l==="edge"||l==="win",w=l==="pic"||l==="base";if(e.useProgram(L),e.activeTexture(e.TEXTURE0),e.bindTexture(e.TEXTURE_2D,ft),w&&e.texImage2D(e.TEXTURE_2D,0,e.RGBA,e.RGBA,e.UNSIGNED_BYTE,a.source),e.uniform4f(A("dst"),c[0],c[1],c[2],c[3]),e.uniform4f(A("src"),i[0],i[1],i[2],i[3]),e.uniform1f(A("alpha"),o),e.uniform1f(A("fade"),p),e.uniform1f(A("white"),b?1:0),e.uniform1f(A("colour"),t?1:0),e.uniform1i(A("tex"),0),e.uniform1i(A("matte"),1),e.uniform1f(A("useMatte"),Ke&&(l==="pic"||l==="win")?1:0),Pe&&!u?(e.uniform4f(A("key"),Pe.u,Pe.v,Pe.similarity,Pe.blend),e.uniform4f(A("keyOpt"),1,Pe.blue?1:0,Pe.spill,a.bt709?1:0)):e.uniform4f(A("keyOpt"),0,0,0,0),e.uniform1i(A("lut1"),2),e.uniform1i(A("lut3"),3),e.uniform1f(A("useL1"),bt&&!u?1:0),e.uniform1f(A("useL3"),Gt&&!u?1:0),Ke&&e.uniform4f(A("mrect"),Ke[0],Ke[1],Ke[2],Ke[3]),e.activeTexture(e.TEXTURE1),e.bindTexture(e.TEXTURE_2D,Et),e.activeTexture(e.TEXTURE2),e.bindTexture(e.TEXTURE_2D,at),e.activeTexture(e.TEXTURE3),e.bindTexture(e.TEXTURE_3D,lt),e.activeTexture(e.TEXTURE0),e.bindTexture(e.TEXTURE_2D,l==="edge"?E[1].tex:l==="win"?s:ft),t){const n=v=>[v[0],v[3],v[6],v[1],v[4],v[7],v[2],v[5],v[8]];e.uniform1f(A("bright"),t.bright),e.uniform1f(A("contrast"),t.contrast),e.uniformMatrix3fv(A("sat"),!1,n(t.sat)),e.uniformMatrix3fv(A("rot"),!1,n(t.rot))}e.drawArrays(e.TRIANGLE_STRIP,0,4)};return{canvas:y,clear(a=1){le(null),e.clearColor(0,0,0,a),e.clear(e.COLOR_BUFFER_BIT)},pixels(){le(null);const a=new Uint8ClampedArray(m*g*4),c=m*4,i=new Uint8ClampedArray(m*g*4);e.readPixels(0,0,m,g,e.RGBA,e.UNSIGNED_BYTE,a);for(let o=0;o<g;o++){const p=(g-1-o)*c,b=o*c;for(let t=0;t<c;t+=4){const l=a[p+t+3];if(i[b+t+3]=l,l){const u=255/l;i[b+t]=a[p+t]*u,i[b+t+1]=a[p+t+1]*u,i[b+t+2]=a[p+t+2]*u}}}return i},draw(a,c,i,o,p,b,t=null,l=[],u=null){if(!l.length&&!_e&&!U.length&&!Be){le(null),e.enable(e.BLEND),e.blendFuncSeparate(e.SRC_ALPHA,e.ONE_MINUS_SRC_ALPHA,e.ONE,e.ONE_MINUS_SRC_ALPHA),pt(a,c,i,o,p,b,t);return}Le??=[De(),De(),De()],le(Le[0].fb),e.disable(e.BLEND),e.clearColor(0,0,0,0),e.clear(e.COLOR_BUFFER_BIT),pt(a,u??c,i,o,p,b,t);const w=f(l);if(le(null),e.enable(e.BLEND),e.blendFuncSeparate(e.SRC_ALPHA,e.ONE_MINUS_SRC_ALPHA,e.ONE,e.ONE_MINUS_SRC_ALPHA),_e||U.length||Be){let n=w;u&&(n=(w+1)%3,le(Le[n].fb),e.disable(e.BLEND),e.clearColor(0,0,0,0),e.clear(e.COLOR_BUFFER_BIT),e.useProgram(L),e.activeTexture(e.TEXTURE0),e.bindTexture(e.TEXTURE_2D,Le[w].tex),e.uniform4f(A("dst"),c[0],c[1],c[2],c[3]),e.uniform4f(A("src"),0,1,1,-1),e.uniform1f(A("alpha"),1),e.uniform1f(A("fade"),1),e.uniform1f(A("white"),0),e.uniform1f(A("colour"),0),e.uniform1f(A("useMatte"),0),e.drawArrays(e.TRIANGLE_STRIP,0,4)),ut(n);return}if(!u){$(X,null,[Le[w].tex],n=>e.uniform1i(n("tex"),0));return}e.useProgram(L),e.activeTexture(e.TEXTURE0),e.bindTexture(e.TEXTURE_2D,Le[w].tex),e.uniform4f(A("dst"),c[0],c[1],c[2],c[3]),e.uniform4f(A("src"),0,1,1,-1),e.uniform1f(A("alpha"),1),e.uniform1f(A("fade"),1),e.uniform1f(A("white"),0),e.uniform1f(A("colour"),0),e.uniform1f(A("useMatte"),0),e.drawArrays(e.TRIANGLE_STRIP,0,4)},warp(a,c,i,o,p,b,t,l,u,w=null,n=null,v=[]){const S=Fe();le(S[0].fb),e.disable(e.BLEND),e.clearColor(0,0,0,0),e.clear(e.COLOR_BUFFER_BIT),pt(a,c,i,o,p,b,t);const Y=f(l),W=_e||U.length||Be||v.length?(Y+1)%3:-1;W>=0?(le(S[W].fb),e.disable(e.BLEND),e.clearColor(0,0,0,0),e.clear(e.COLOR_BUFFER_BIT)):(le(null),e.enable(e.BLEND),e.blendFuncSeparate(e.SRC_ALPHA,e.ONE_MINUS_SRC_ALPHA,e.ONE,e.ONE_MINUS_SRC_ALPHA)),n&&(e.enable(e.SCISSOR_TEST),e.scissor(n[0],g-n[1]-n[3],n[2],n[3])),$(Qe,W>=0?S[W].fb:null,[S[Y].tex],Q=>{e.uniform1i(Q("tex"),0),e.uniform2f(Q("size"),m,g),e.uniform1f(Q("keepPre"),0),e.uniformMatrix3fv(Q("inv"),!1,[u[0],u[3],u[6],u[1],u[4],u[7],u[2],u[5],u[8]]),e.uniform4f(Q("rnd"),w?.[0]??0,w?.[1]??0,w?.[2]??0,w?1:0)}),e.disable(e.SCISSOR_TEST),W>=0&&ut(v.length?f(v,W):W)},adjust(a,c,i){const o=Fe();if(le(null),e.bindTexture(e.TEXTURE_2D,Tt),e.copyTexImage2D(e.TEXTURE_2D,0,e.RGBA8,0,0,m,g,0),le(o[0].fb),e.disable(e.BLEND),e.useProgram(L),e.activeTexture(e.TEXTURE0),e.bindTexture(e.TEXTURE_2D,Tt),e.uniform4f(A("dst"),0,0,1,1),e.uniform4f(A("src"),0,1,1,-1),e.uniform1i(A("tex"),0),e.uniform1f(A("alpha"),1),e.uniform1f(A("fade"),1),e.uniform1f(A("white"),0),e.uniform1f(A("useMatte"),0),e.uniform1f(A("colour"),a?1:0),a){const b=t=>[t[0],t[3],t[6],t[1],t[4],t[7],t[2],t[5],t[8]];e.uniform1f(A("bright"),a.bright),e.uniform1f(A("contrast"),a.contrast),e.uniformMatrix3fv(A("sat"),!1,b(a.sat)),e.uniformMatrix3fv(A("rot"),!1,b(a.rot))}e.drawArrays(e.TRIANGLE_STRIP,0,4);const p=f(c);le(null),e.enable(e.BLEND),e.blendFuncSeparate(e.SRC_ALPHA,e.ONE_MINUS_SRC_ALPHA,e.ONE,e.ONE_MINUS_SRC_ALPHA),e.useProgram(L),e.activeTexture(e.TEXTURE0),e.bindTexture(e.TEXTURE_2D,o[p].tex),e.uniform4f(A("dst"),0,0,1,1),e.uniform4f(A("src"),0,1,1,-1),e.uniform1f(A("alpha"),i),e.uniform1f(A("fade"),1),e.uniform1f(A("white"),0),e.uniform1f(A("colour"),0),e.uniform1f(A("useMatte"),0),e.drawArrays(e.TRIANGLE_STRIP,0,4)},grade(a,c){if(bt=!!a,Gt=!!c,a&&Oe.l1!==a.key){const i=new Float32Array(1024);for(let o=0;o<256;o++)i[o*4]=a.r[o],i[o*4+1]=a.g[o],i[o*4+2]=a.b[o],i[o*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,i);for(const o of[e.TEXTURE_MIN_FILTER,e.TEXTURE_MAG_FILTER])e.texParameteri(e.TEXTURE_2D,o,e.NEAREST);e.activeTexture(e.TEXTURE0),Oe.l1=a.key}if(c&&Oe.l3!==c.key){e.activeTexture(e.TEXTURE3),e.bindTexture(e.TEXTURE_3D,lt),e.pixelStorei(e.UNPACK_ALIGNMENT,1),e.texImage3D(e.TEXTURE_3D,0,e.RGB32F,c.size,c.size,c.size,0,e.RGB,e.FLOAT,c.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),Oe.l3=c.key}},key(a){if(!a){Pe=null;return}const[c,i,o]=[1,3,5].map(b=>parseInt(a.color.slice(b,b+2),16)),p=224/255;Pe={u:Math.round(-.168736*p*c-.331264*p*i+.5*p*o+128),v:Math.round(.5*p*c-.418688*p*i-.081312*p*o+128),similarity:a.similarity,blend:a.blend,spill:+a.spill.toFixed(3),blue:o>i}},mode(a){_e=a&&Qt[a]||0},shadow(a){U=a},glBegin(){wt??={base:ce(),a:ce(),b:ce()},le(null),e.bindTexture(e.TEXTURE_2D,wt.base),e.copyTexImage2D(e.TEXTURE_2D,0,e.RGBA8,0,0,m,g,0),e.clearColor(0,0,0,0),e.clear(e.COLOR_BUFFER_BIT)},glEnd(a,c,i){const o=wt;if(le(null),e.bindTexture(e.TEXTURE_2D,a==="a"?o.a:o.b),e.copyTexImage2D(e.TEXTURE_2D,0,e.RGBA8,0,0,m,g,0),e.disable(e.BLEND),$(X,null,[o.base],t=>e.uniform1i(t("tex"),0)),a==="a")return;let p=Rt.get(c);p||(p=h(G,mi(sr[c])),Rt.set(c,p)),yt??=De(),$(p,yt.fb,[o.a,o.b],t=>{e.uniform1i(t("glFrom"),0),e.uniform1i(t("glTo"),1),e.uniform1f(t("progress"),Math.max(0,Math.min(1,i))),e.uniform1f(t("ratio"),m/g),e.uniform1f(t("glPremul"),1)});const b=_e;_e=0,Je(yt.tex),_e=b},blurBegin(){be??=De(),le(be.fb),e.clearColor(0,0,0,0),e.clear(e.COLOR_BUFFER_BIT),Be=!0},blurEnd(){Be=!1;const a=Fe();e.disable(e.BLEND),$(x,a[0].fb,[be.tex],c=>e.uniform1i(c("tex"),0)),ut(0)},windows(a){K=a},edge(a){k=a},warpBig(a,c,i,o,p,b,t,l,u,w=[]){const n=Dt(u),v=m*u,S=g*u;e.bindFramebuffer(e.FRAMEBUFFER,n.plane.fb),e.viewport(0,0,v,S),e.disable(e.BLEND),e.clearColor(0,0,0,0),e.clear(e.COLOR_BUFFER_BIT),pt(a,c,i,o,p,b,t);const Y=Ot(l.map(([Ee,H])=>[Ee*u,H*u]),v,S);e.bindFramebuffer(e.FRAMEBUFFER,n.out.fb),e.viewport(0,0,v,S),e.useProgram(Qe),e.activeTexture(e.TEXTURE0),e.bindTexture(e.TEXTURE_2D,n.plane.tex);const W=Ye(Qe);if(e.uniform1i(W("tex"),0),e.uniform2f(W("size"),v,S),e.uniform1f(W("keepPre"),1),e.uniform4f(W("rnd"),0,0,0,0),e.uniformMatrix3fv(W("inv"),!1,[Y[0],Y[3],Y[6],Y[1],Y[4],Y[7],Y[2],Y[5],Y[8]]),e.drawArrays(e.TRIANGLE_STRIP,0,4),le(null),e.enable(e.BLEND),e.blendFuncSeparate(e.SRC_ALPHA,e.ONE_MINUS_SRC_ALPHA,e.ONE,e.ONE_MINUS_SRC_ALPHA),!w.length&&!_e&&!U.length&&!Be){$(Z,null,[n.out.tex],Ee=>{e.uniform1i(Ee("tex"),0),e.uniform1i(Ee("ss"),u)});return}const Q=Fe();e.disable(e.BLEND),$(Z,Q[0].fb,[n.out.tex],Ee=>{e.uniform1i(Ee("tex"),0),e.uniform1i(Ee("ss"),u)}),ut(f(w,0))},matte(a,c=[0,0,1,1]){Ke=a?c:null,a&&(e.activeTexture(e.TEXTURE1),e.bindTexture(e.TEXTURE_2D,Et),e.texImage2D(e.TEXTURE_2D,0,e.RGBA,e.RGBA,e.UNSIGNED_BYTE,a),e.activeTexture(e.TEXTURE0))},overlay(a,c){le(null),e.enable(e.BLEND),e.blendFuncSeparate(e.SRC_ALPHA,e.ONE_MINUS_SRC_ALPHA,e.ONE,e.ONE_MINUS_SRC_ALPHA),c&&(e.activeTexture(e.TEXTURE0),e.bindTexture(e.TEXTURE_2D,ft),e.texImage2D(e.TEXTURE_2D,0,e.RGBA,c.w,c.h,0,e.RGBA,e.UNSIGNED_BYTE,c.data)),$(st,null,c?[ft]:[],i=>{e.uniform1i(i("tex"),0),e.uniform1f(i("usetex"),c?1:0),e.uniform4f(i("colour"),...a??[0,0,0,0])})},finish(){e.finish()}}}let Ce="";const qa=()=>Ce;async function _a(m,{format:g,encode:y=null,tracks:e={},camera:q=null,signal:h,onProgress:L,frames:M,software:V=!1,liveMotion:ie=!1,range:se,only:me,sink:pe}){const x=performance.now(),{width:R,height:F,fps:C}=ao(g);Ce="layers",await Promise.all([...new Set(m.filter(r=>!r.colorBypass).flatMap(r=>Ht(r.grade).map(f=>f?.lut?.id)).filter(r=>!!r))].map(r=>nr(r))),Go(uo(m.filter(r=>!r.disabled)));const N=m.filter(r=>!r.disabled&&!Uo(r)),X=uo(N),te=qo(N.reduce((r,f)=>Math.max(r,f.start+f.duration),0)),oe=Math.round(te*C);if(!(oe>0)&&!M)throw Error("Empty timeline");const O=jo(q)?q:null,Ae=$o(X,e,O?r=>Xi(r,O,R,F):void 0),we=r=>Ae.find(f=>r>=f.start-1e-6&&r<f.start+f.duration-1e-6)??null,je=()=>{if(h?.aborted)throw new DOMException("Export cancelled","AbortError")},ye=r=>ie&&!M&&!!r.motion&&!r._virtual&&!r.warped,We=r=>M||me!=="audio"&&(!se||r.start<se.to/C+1e-6&&r.start+r.duration>se.from/C-1e-6),$e=new Cr,nt=[...N.filter(r=>Kt(r)&&!ye(r)),...Ho(N)].filter(We);nt.length&&await(await Nt(async()=>{const{renderTitleFrames:r}=await import("./titleFrames-BHFaInux.js");return{renderTitleFrames:r}},__vite__mapDeps([0,1,2,3,4,5,6,7,8,9]))).renderTitleFrames(nt,g,$e,h);const Me=new Map;if(N.some(r=>ye(r)&&We(r))){const r=await Nt(()=>import("./titleFrames-BHFaInux.js"),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9]));for(const f of N.filter(k=>ye(k)&&We(k)))Me.set(f.id,r.liveMotion(f,N,g))}N.some(r=>r.kind==="model")&&await(await Nt(async()=>{const{render3DFrames:r}=await import("./timeline3dExport-BO--SpAn.js");return{render3DFrames:r}},__vite__mapDeps([10,1,11,12,13,8,6,7,14,9]))).render3DFrames(m.filter(r=>!r.disabled),g,$e,h,q);for(const r of X.filter(f=>f._group&&f.comp)){const f=[],k=Math.max(1,Math.ceil(r.duration*C-1e-6));await _a(dr(vr(r),{W:R,H:F}),{format:g,signal:h,frames:{times:Array.from({length:k},(d,E)=>xr(r,E/C)),push:(d,E)=>{f[d]=E}}}),$e.frames.set(r.id,f)}const st=performance.now();je(),Ce="mattes";const Qe=N.filter(r=>r.mask||r.person),Re=Qe.length?await Nt(()=>import("./rotoMatte-DisQplSv.js").then(r=>r.r),__vite__mapDeps([15,1,8,6,7,16])):null;Re&&await Re.prepareMattes(Qe);const He=Re?document.createElement("canvas"):null;Ce="media";const Ze=new Map,Se=new Map,Xe=new Map,it=r=>{let f=Ze.get(r);return f||(f=new _r({source:new Ar(r,{getRetryDelay:No}),formats:Fr}),Ze.set(r,f)),f};for(const r of N){if(r.kind==="video"&&!Se.has(r.url)){const f=await it(r.url).getPrimaryVideoTrack();f&&Se.set(r.url,new yr(f))}if(r.kind==="image"&&!Kt(r)&&!oo(r)&&!r._group&&!Xe.has(r.url)){const f=await createImageBitmap(await Ir(r.url,h),{imageOrientation:"from-image",premultiplyAlpha:"none",colorSpaceConversion:"none"});Xe.set(r.url,{source:f,w:f.width,h:f.height,close:()=>f.close()})}}const Z=new Map,ge=async(r,f)=>{const k=Me.get(r.id);if(k)return{source:await k.frame(Math.round((f-r.start)*C)),w:k.W,h:k.H};const d=$e.frames.get(r.id);if(!d?.length)return null;let E=d.length===1?0:Math.max(0,Math.min(Math.round((f-r.start)*C),Math.ceil(r.duration*C)-1,d.length-1));for(;E>0&&d[E]==="=";)E--;const z=Z.get(r.id);if(z&&z.index===E)return z.pic;z?.pic?.close?.();const B=await createImageBitmap(await(await fetch(`data:image/webp;base64,${d[E]}`)).blob(),{premultiplyAlpha:"none",colorSpaceConversion:"none"}),ue={source:B,w:B.width,h:B.height,close:()=>B.close()};return Z.set(r.id,{index:E,pic:ue}),ue},ct=N.filter(r=>Vo(r)),Ve=ct.length?await Nt(()=>import("./captionLayout-CAuhUiW9.js"),__vite__mapDeps([17,1])):null,ke=new Map,rt=new Map;if(Ve){for(const r of new Set(ct.flatMap(f=>[eo(Yo(f.captionStyle).font),eo(mo(f.captionStyle).font)])))if(await Ve.captionFontReady(r.id),!ke.has(r.id)){const f=new Uint8Array(await(await fetch(`/fonts/${r.file}`,{signal:h})).arrayBuffer());let k="";for(let d=0;d<f.length;d+=32768)k+=String.fromCharCode(...f.subarray(d,d+32768));ke.set(r.id,`@font-face{font-family:'${r.family}';src:url(data:font/${r.file.endsWith(".otf")?"otf":"ttf"};base64,${btoa(k)})}`)}}const Ye=new Map,A=async(r,f,k)=>{let d=Ye.get(f.start);if(!d||d.owner!==r){const _=pi(r,f.start,f.duration);d={plan:_,starts:xi(_.entries,C),owner:r},Ye.clear(),Ye.set(f.start,d)}const E=k-Math.round(f.start*C);let z=-1;for(let _=0;_<d.starts.length&&d.starts[_]<=E;_++)z=_;const B=d.plan.entries[z];if(!B||B.blank)return null;const ue=d.plan.social?d.plan.social.style:mo(r.captionStyle),K=d.plan.social?di(d.plan.social,B.gi,R,F,Ve.measureCaption):vi({width:R,height:F,text:B.text,style:ue,measure:Ve.measureCaption,second:B.second}),J=hi(K,ue,d.plan.social?B.scale:1,R,F,B.active,B.motion);let s=rt.get(J);if(!s){const _=eo(ue.font),re=URL.createObjectURL(new Blob([J.replace("<defs>",`<defs><style>${ke.get(_.id)??""}</style>`)],{type:"image/svg+xml"}));try{const xe=new Image(R,F);xe.src=re,await xe.decode();const ze=await createImageBitmap(xe,{premultiplyAlpha:"none"});s={source:ze,w:R,h:F,close:()=>ze.close()}}finally{URL.revokeObjectURL(re)}if(rt.size>64){const[xe,ze]=rt.entries().next().value;ze.close?.(),rt.delete(xe)}rt.set(J,s)}return s},ce=[0,0,1,1],ft=new Map,Et=["x","y","zoom","rot","sx","sy"],Ke=(r,f,k,d)=>{const E=`${r.id}@${f.start}`;let z=ft.get(E);if(!z){const ue=Math.max(1,Math.ceil(f.duration/.1-1e-6)),K=Array.from({length:ue+1},(_,re)=>f.start+f.duration*re/ue),J=K.map(_=>to(r,_-r.start,R,F)),s=_=>+(+_).toFixed(3);z={ts:K.map(_=>+_.toFixed(5)),v:Object.fromEntries(Et.map(_=>[_,J.map(re=>s(re[_]??(_==="sx"||_==="sy"?1:0)))]))},ft.set(E,z)}const B={...d};for(const ue of Et){const K=z.v[ue];if(K.every(re=>re===K[0])){B[ue]=K[0];continue}let J=z.ts.findIndex((re,xe)=>xe<z.ts.length-1&&k<z.ts[xe+1]);J<0&&(J=z.ts.length-2);const s=+(K[J+1]-K[J]).toFixed(3),_=z.ts[J+1]-z.ts[J];B[ue]=Math.abs(K[J+1]-K[J])<1e-4?K[J]:K[J]+s*Math.max(0,Math.min(1,(k-z.ts[J])/_))}return B},at=new Map,lt=new Map,Oe=(r,f,k,d=r,E="")=>{if(!gi(d))return Fo(d,R);const z=`${r.id}${E}@${f.start}`;let B=lt.get(z);B||(B=Ei(d,{offset:f.start-r.start,duration:f.duration,fps:C}),lt.set(z,B));const ue=k-Math.round(f.start*C),K=B.find(J=>ue>=J.from&&ue<J.to)??B[B.length-1];return Fo({effects:bi(d,K.t)},R)},bt=new Map,Gt=(r,f,k)=>{const d=`${r.id}@${f.start}`;bt.has(d)||bt.set(d,O?Bi(r,O,f.start,f.duration,R,F):null);const E=bt.get(d);return E?Oe(r,f,k,E,":dof"):[]},Pe=new Map,Qt=r=>{const f=JSON.stringify(r.grade);let k=Pe.get(f);if(!k){const d=B=>Array.from(B,ue=>+ue.toFixed(6)),E=Ri(r.grade)?_i(r.grade):null,z=r.grade.mixer&&Fi(r.grade.mixer)?Ai(r.grade.mixer):null;k={l1:E?{key:`1${f}`,r:d(E.r),g:d(E.g),b:d(E.b)}:null,l3:z?{key:`3${f}`,size:z.size,data:Float32Array.from(z.data,B=>+B.toFixed(6))}:null},Pe.set(f,k)}return k};let _e=null;const Tt=async(r,f,k)=>{const d=N.find(B=>B.id===r);if(!d||f<d.start||f>=d.start+d.duration)return null;if(Kt(d)){const B=await ge(d,f);return B&&{source:B.source,w:B.w,h:B.h}}if(d.kind==="image"){const B=Xe.get(d.url);return B?{source:B.source,w:B.w,h:B.h}:null}if(d.kind!=="video")return null;const E=await Mo(mt,Se,d,f,C,Math.max(k.start,d.start),k.duration);if(!E)return null;const z=E.toVideoFrame();return{source:z,w:E.displayWidth,h:E.displayHeight,close:()=>z.close()}};Ce="output";const U=Ra(R,F),wt=no(y,{width:R,height:F,fps:C},so),yt=y?.codec==="hevc",Rt=y?.container==="mov",Be=!M&&!pe&&te*wt/8>15e7&&!!navigator.storage?.getDirectory;let be=null,_t;if(Be){const r=await navigator.storage.getDirectory(),f=`gpu-export-${crypto.randomUUID()}.${Rt?"mov":"mp4"}`,k=await r.getFileHandle(f,{create:!0});be={dir:r,handle:k,name:f},_t=new Ao(await k.createWritable(),{chunked:!0,chunkSize:1<<20})}else _t=pe&&!M?new Ao(pe,{chunked:!0,chunkSize:1<<22}):new Sr;const ut=pe&&!M?!1:Be?"reserve":"in-memory",Je=new Dr({format:Rt?new Ur({fastStart:ut}):new kr({fastStart:ut}),target:_t}),Le=new Pr(U.canvas,{codec:yt?"hevc":"avc",bitrate:wt,keyFrameInterval:2,...yt?{hardwareAcceleration:"prefer-hardware"}:V?{hardwareAcceleration:"prefer-software"}:{}}),Fe=me==="audio"?0:Math.max(0,Math.min(oe,se?.from??0)),Ft=me==="audio"?0:Math.max(Fe,Math.min(oe,se?.to??oe));me!=="audio"&&Je.addVideoTrack(Le,{frameRate:C,...Be?{maximumPacketCount:Ft-Fe+8}:{}});const Dt=new Br({codec:"aac",bitrate:Lo});me!=="video"&&Je.addAudioTrack(Dt,Be?{maximumPacketCount:Math.ceil(te*zt/1024)+16}:{}),M||await Je.start();const Ut=M?new OffscreenCanvas(R,F):null,qt=Ut?.getContext("2d"),Zt=async r=>{qt.putImageData(new ImageData(U.pixels(),R,F),0,0);const f=new Uint8Array(await(await Ut.convertToBlob({type:"image/webp",quality:.9})).arrayBuffer());let k="";for(let d=0;d<f.length;d+=32768)k+=String.fromCharCode(...f.subarray(d,d+32768));M.push(r,btoa(k))},mt=new Map;let At=0;const kt={decode:0,matte:0,titles:0,captions:0,encode:0},De=async(r,f)=>{const k=performance.now();try{return await f}finally{kt[r]+=performance.now()-k}},le=(r,f)=>{const k=performance.now();try{return f()}finally{kt[r]+=performance.now()-k}};try{for(let f=M?0:Fe,k=M?M.times.length:Ft;f<k;f++){je(),Ce="frame";const d=M?M.times[f]:f/C,E=we(d);U.clear(M?0:1);const z=E&&Ve?Ko(N,E.start+1e-5,e):void 0,B=z&&E?Wo(E.visuals,z.captionStyle?.layerTrack):-1,ue=async()=>{const K=z&&E&&await De("captions",A(z,E,f));K&&(U.shadow([]),U.edge(null),U.windows(null),U.matte(null),U.mode(void 0),U.key(null),U.grade(null,null),U.draw(K,ce,ce,1,1,!1,null,[]))};for(const[K,J]of(E?.visuals??[]).entries()){let s=J;if(K===B&&await ue(),s.kind==="audio")continue;const _=E?po(s,E.start,E.start+E.duration):null,re=_?s._txIn===_?"b":"a":null,xe=_?Qo(_,d):0,ze=_&&re?_.spec.gl?.id??null:null;ze&&U.glBegin();e:{if(s.kind==="model"){U.matte(null),U.edge(null),U.windows(null),U.mode(void 0),U.shadow(xo(s,R)),U.key(null),U.grade(null,null);const o=await ge(s,d);o&&U.draw(o,ce,ce,1,1,!1,null,[]);break e}const de=d-s.start,Ge=to(s,de,R,F),ae=(Zo(s)||Jo(s))&&!_&&!(O&&Vt(s))&&!s.pin?Ke(s,E,d,Ge):Ge;if(!(ae.opacity>1e-4))break e;if(oo(s)){U.adjust(ot(s),Oe(s,E,f),Math.min(1,ae.opacity));break e}let P=null,Ne=null;if(Kt(s)||s._group)P=await De("titles",ge(s,d));else if(s.kind==="image")P=Xe.get(s.url)??null;else if(s.kind==="video"){const o=await De("decode",Mo(mt,Se,s,d,C,E.start,E.duration));o&&(Ne=o.toVideoFrame(),P={source:Ne,w:o.displayWidth,h:o.displayHeight,bt709:Ne.colorSpace?.matrix?Ne.colorSpace.matrix==="bt709":o.displayHeight>=720})}if(!P)break e;if(ei(s)){const o=s.crop||{left:0,right:0,top:0,bottom:0},p=Math.floor(P.w*o.left/2)*2,b=Math.floor(P.h*o.top/2)*2,t=Math.max(2,Math.floor(P.w*(1-o.left-o.right)/2)*2),l=Math.max(2,Math.floor(P.h*(1-o.top-o.bottom)/2)*2),u=s.distort.displace?await Tt(s.distort.displace.map,d,E):null;_e??=wr();const w=_e.render({source:P.source,srcW:P.w,srcH:P.h,rect:[p,b,t,l],outW:t,outH:l,distort:s.distort,local:de,map:u?.source??null,matte:Re&&(s.mask||s.person)?Re.matteCanvas(s,de,He,!1,N):null});u?.close?.(),P={source:w,w:t,h:l,bt709:P.bt709},s={...s,crop:void 0,mask:void 0,person:void 0}}if(Re&&(s.mask||s.person)){const o=s.crop||{left:0,right:0,top:0,bottom:0},p=Math.max(2,Math.floor(P.w*(1-o.left-o.right)/2)*2),b=Math.max(2,Math.floor(P.h*(1-o.top-o.bottom)/2)*2);U.matte(le("matte",()=>Re.matteCanvas(s,de,He,!1,N)),[o.left,o.top,p/P.w,b/P.h])}else U.matte(null);U.mode(s.blend),U.key(s.key),U.shadow(xo(s,R));{const o=s.colorBypass?[]:Ht(s.grade).filter(io);U.windows(o.length?{key:`${s.id}@${f}`,list:Ht(s.grade),clip:s.id,src:s,frame:Math.round((d-s.start)*C),local:Math.round((d-s.start)*C)/C}:null)}if(vo(s)&&ho(go(s),de)>.001){const o=go(s),p=Re&&(s.mask||s.person),b=s.crop||{left:0,right:0,top:0,bottom:0},t=p?Math.max(2,Math.floor(p.mw*(1-b.left-b.right)/2)*2):P.w,l=p?Math.max(2,Math.floor(p.mh*(1-b.top-b.bottom)/2)*2):P.h,u=t>=l?Yt:Math.max(8,Math.trunc(Yt*t/l/8)*8),w=t>=l?Math.max(8,Math.trunc(Yt*l/t/8)*8):Yt,n=ti(o),v=ho(o,de),S=!!o.keys?.length||o.amount<.999;U.edge({key:`${s.id}@${f}`,ew:u,eh:w,band:n.band,glow:n.glow,k:o.glow,col:[1,3,5].map(Y=>parseInt(o.color.slice(Y,Y+2),16)/255),am:S?Math.trunc(255*v):255,harden:!!p,arc:o.cover>=.999&&!o.comet?null:{cen:p?oi(s):[.5,.5],start:(o.angle+o.sweep*de)*Math.PI/180,cover:o.cover,comet:!!o.comet}})}else U.edge(null);{const o=s.grade&&!s.colorBypass?Qt(s):null;U.grade(o?.l1??null,o?.l3??null)}if(s.pin&&!(O&&Vt(s))&&E&&Eo(s,N,E.start,R,F,O)){const o=Eo(s,N,d,R,F,O)??[[0,0],[0,0],[0,0],[0,0]],p=It(s,de),b=ii(s,N,R,F,O),t=s.pin.dive,l=b&&!s.pin.scene?[+(b[0]*R).toFixed(3),+(b[1]*F).toFixed(3),t?Math.max(0,Math.min(1,(d-t.at)/t.dur)):0]:null;U.warp(P,Ct([0,0,1,1],R,F),_o(s,P.w,P.h),Math.min(1,ae.opacity),p.k,p.white,ot(s),Oe(s,E,f),Ot(o,R,F),l),Ne?.close();break e}const Pt=ri(s,"rot")||ai(s),jt=()=>s.motionBlur?Tr(d,C).map(o=>({...to(s,o-s.start,R,F),rot:ae.rot,opacity:ae.opacity})):[ae];if((Pt||Math.abs(ae.rot||0)>1e-9)&&!(O&&Vt(s))){const o=It(s,de),p=_&&re?[...Do(_.spec[re],xe,R,F,d,_.spec.zoomAt),...re==="b"&&_.spec.mask?[So(_.spec.mask,xe)]:[]]:[];s.motionBlur&&U.blurBegin();for(const b of jt()){const t=hr(s,P.w,P.h,R,F,b,Pt);U.warp(P,Ct([0,0,1,1],R,F),_o(s,P.w,P.h),Math.min(1,ae.opacity),o.k,o.white,ot(s),[],Ot(t.quad,R,F),null,t.clip,p)}s.motionBlur&&U.blurEnd(),Ne?.close();break e}if(O&&Vt(s)){const o=ni(s,de,O,d,R,F);if(o){const p=Xt(s,P.w,P.h,R,F,{x:0,y:0,zoom:1}),b=It(s,de),t=Oe(s,E,f);let l=at.get(s.id);l===void 0&&(l=s.effects?.some(w=>!w.off)||s.mask||s.person||vo(s)||!s.colorBypass&&Ht(s.grade).some(io)?1:si(ci(s,O,R,F),P.w,P.h,R,F),at.set(s.id,l));const u=Gt(s,E,f);l>1&&!t.length?U.warpBig(P,Ct(p.dst,R,F),p.src,Math.min(1,ae.opacity),b.k,b.white,ot(s),o.quad,l,u):U.warp(P,Ct(p.dst,R,F),p.src,Math.min(1,ae.opacity),b.k,b.white,ot(s),t,Ot(o.quad,R,F),null,null,u)}Ne?.close();break e}if(s.motionBlur&&!_&&!Oe(s,E,f).length){const o=It(s,de);U.blurBegin();for(const p of jt()){const b=Xt(s,P.w,P.h,R,F,p);U.draw(P,b.dst,b.src,Math.min(1,ae.opacity),o.k,o.white,ot(s),[])}U.blurEnd(),Ne?.close();break e}const{dst:Bt,src:pt}=Xt(s,P.w,P.h,R,F,ae),qe=It(s,de),a=[...Oe(s,E,f),..._&&re?Do(_.spec[re],xe,R,F,d,_.spec.zoomAt):[],..._&&re==="b"&&_.spec.mask?[So(_.spec.mask,xe)]:[]],c=_&&re?_.spec[re]?.rot:null;if(c){const o=Wt(c,xe)??0;U.warp(P,Ct([0,0,1,1],R,F),pt,Math.min(1,ae.opacity),qe.k,qe.white,ot(s),[],Ot(gr(Bt,R,F,o),R,F),null,null,a),Ne?.close();break e}if(a.length>0&&!!E&&!s.layout&&!po(s,E.start,E.start+E.duration)&&fi(s,E.start,E.start+E.duration,R,F)){const o=Xt(s,P.w,P.h,R,F,{x:0,y:0,zoom:1}),p=Xt({},R,F,R,F,ae);U.draw(P,p.dst,o.src,Math.min(1,ae.opacity),qe.k,qe.white,ot(s),a,o.dst)}else U.draw(P,Bt,pt,Math.min(1,ae.opacity),qe.k,qe.white,ot(s),a);Ne?.close()}if(ze&&U.glEnd(re,ze,xe),_&&re==="b"){if(_.spec.light){const Ge=Math.max(2,Math.ceil(R/bo)),ae=Math.max(2,Math.ceil(F/bo));U.overlay(null,{data:li(_.spec,xe,Ge,ae),w:Ge,h:ae})}const de=_.spec.flash;if(de){const Ge=Wt(de.opacity,xe)??0;if(Ge>1e-4){const ae=parseInt(de.color.slice(1),16);U.overlay([(ae>>16&255)/255,(ae>>8&255)/255,(ae&255)/255,Math.min(1,Ge)],null)}}}}B>=0&&B>=(E?.visuals.length??0)&&await ue();for(const[K,J]of mt){const s=K.split(`
198
+ `)[0],_=X.find(re=>re.id===s);(!_||d>_.start+_.duration+1)&&(J.current?.close(),J.peek?.close(),await J.iterator.return?.(),mt.delete(K))}if(M){await Zt(f);continue}Ce="video encode",await De("encode",Le.add((f-Fe)/C,1/C)),L?.((me==="video"?1:.9)*(f+1-Fe)/Math.max(1,Ft-Fe))}if(M)return{blob:new Blob,ms:{titles:0,video:0,audio:0,total:Math.round(performance.now()-x)}};const r=performance.now();if(me==="video")Le.close(),Ce="finalize",await Je.finalize();else{Ce="audio";const f=new Map(X.map(d=>[d.id,d])),k=await Aa(N.map(d=>f.get(d.id)??d),Ae,te,e,it,h);typeof g.loudness=="number"&&Er([k.getChannelData(0),k.getChannelData(1)],g.loudness,zt),Ce="audio encode",await Dt.add(k),At=performance.now()-r,me!=="audio"&&Le.close(),Dt.close(),Ce="finalize",await Je.finalize()}}catch(r){throw await Je.cancel().catch(()=>{}),be&&await be.dir.removeEntry(be.name).catch(()=>{}),r}finally{for(const r of mt.values())r.current?.close(),r.peek?.close();_e?.dispose();for(const r of Xe.values())r.close?.();for(const r of Z.values())r.pic?.close?.();for(const r of Me.values())r.close();for(const r of rt.values())r.close?.();for(const r of Ze.values())r.dispose?.()}L?.(1),Ce="file";const $=be?await be.handle.getFile():pe?new Blob([]):new Blob([_t.buffer],{type:Rt?"video/quicktime":"video/mp4"});be&&setTimeout(()=>void be.dir.removeEntry(be.name).catch(()=>{}),600*1e3);const Mt=performance.now()-x;return{blob:$,ms:{titles:Math.round(st-x),video:Math.round(Mt-(st-x)-At),audio:Math.round(At),total:Math.round(Mt),parts:Object.fromEntries(Object.entries(kt).map(([r,f])=>[r,Math.round(f)]))}}}function Fa(m,g,y,e,q){const h=[new Float32Array(Math.max(1,Math.round(q*y))),new Float32Array(Math.max(1,Math.round(q*y)))],L=Math.round(Oi*y);return g.forEach((M,V)=>{if(M.silent)return;const ie=Math.round((M.t1-M.t0)*y)+(V<g.length-1?L:0),se=Math.abs(M.rate),me=Math.round(M.t0*y),pe=Math.max(0,Math.round(((M.rate>0?M.s0:M.s0-se*ie/y)-e)*y)),x=Math.min(m[0].length,Math.round(((M.rate>0?M.s0+se*ie/y:M.s0)-e)*y));if(x-pe<2)return;const R=(x-pe)/ie,F=Math.round(.06*y),C=Math.max(0,pe-F),N=Math.min(m[0].length,x+F);let X=m.map(oe=>oe.slice(C,N));M.rate<0&&X.forEach(oe=>oe.reverse());const te=Math.round((M.rate<0?N-x:pe-C)/R);X=Bo(X,R,y).map(oe=>oe.subarray(te,te+ie));for(let oe=0;oe<2;oe++)for(let O=0;O<ie&&me+O<h[oe].length;O++){const Ae=(V>0&&O<L?O/L:1)*(V<g.length-1&&O>=ie-L?(ie-O)/L:1);h[oe][me+O]+=(X[oe][O]??0)*Ae}}),h}async function Aa(m,g,y,e,q,h){const L=new OfflineAudioContext({numberOfChannels:2,length:Math.max(1,Math.round(y*zt)),sampleRate:zt}),M=1/200,V=m.filter(x=>(x.kind==="video"||x.kind==="audio")&&!x.freeze&&!Po(x)&&(x.volume??1)>0),ie=x=>(x.kind==="video"||x.kind==="audio")&&!!x.url,se=new Map;for(const x of g.flatMap(R=>R.audios))!ie(x)||se.has(x.url)||se.set(x.url,await q(x.url).getPrimaryAudioTrack().then(R=>!!R,()=>!1));const me=x=>ie(x)&&!!se.get(x.url);for(const x of V){if(h?.aborted)throw new DOMException("Export cancelled","AbortError");const R=Math.max(2,Math.ceil(x.duration/M)+1),F=new Float32Array(R);let C=!1;const N=Li(x.track,e);for(let Z=0;Z<R;Z++){const ge=x.start+Math.min(x.duration,Z*M),ct=g.find(ke=>ge>=ke.start-1e-6&&ge<ke.start+ke.duration-1e-6),Ve=ct?.audios.some(ke=>ke.id===x.id)?Ni(x,ge-x.start)*N.gain/Ii(ct.audios,me):0;F[Z]=Ve,Ve>0&&(C=!0)}if(!C)continue;const X=await q(x.url).getPrimaryAudioTrack();if(!X)continue;const te=ko(x)?Ci(x,0,x.duration):null,oe=x.playbackRate||1,O=new Mr(X),Ae=te?te.flatMap(Z=>[Z.s0,Z.s1]):[],we=te?Math.max(0,Math.min(...Ae)-.2):x.inPoint||0,je=te?Math.max(...Ae)+.2:we+x.duration*oe,ye=[];let We=we;for await(const Z of O.samples(we,je))ye.length||(We=Z.timestamp),ye.push(Z.toAudioBuffer()),Z.close();if(!ye.length)continue;const $e=ye[0].sampleRate,nt=ye.reduce((Z,ge)=>Z+ge.length,0);let Me=[new Float32Array(nt),new Float32Array(nt)],st=0;for(const Z of ye){for(let ge=0;ge<2;ge++)Me[ge].set(Z.getChannelData(Math.min(ge,Z.numberOfChannels-1)),st);st+=Z.length}te?Me=Fa(Me,te,$e,We,x.duration):oe!==1&&(Me=Bo(Me,oe,$e));const Qe=L.createBuffer(2,Me[0].length,$e);for(let Z=0;Z<2;Z++)Qe.copyToChannel(Me[Z],Z);const Re=L.createBufferSource();Re.buffer=Qe;const He=L.createGain();He.gain.value=0,He.gain.setValueCurveAtTime(F,x.start,Math.max(M,x.duration));const Ze=L.createChannelSplitter(2),Se=L.createChannelMerger(2),Xe=L.createGain(),it=L.createGain();Xe.gain.value=N.left,it.gain.value=N.right,Re.connect(He),He.connect(Ze),Ze.connect(Xe,0),Ze.connect(it,1),Xe.connect(Se,0,0),it.connect(Se,0,1),Se.connect(L.destination),Re.start(x.start,te?0:Math.max(0,we-We)/oe,x.duration)}const pe=await L.startRendering();return br([pe.getChannelData(0),pe.getChannelData(1)]),pe}export{Oa as canEncodeH264,za as canEncodeHevc,Xa as canEncodeMp4,_a as exportOnGpu,so as gpuBitrate,qa as gpuExportStage,Ga as gpuExportSupported};
@@ -1 +1 @@
1
- import{g as kt,l as Ft}from"./matteQuality-9X-jgJrH.js";import{cR as V,cS as jt}from"./timelineOps-afzSo188.js";import"./titleFrameBudget-X7HLSDre.js";import"./sceneTrack-Bbov7zET.js";import"./cameraTracker-BAQHuTV-.js";import"./textAnimators-BVXTl8bU.js";import"./timelineComp-Dx_kED5V.js";import"./api-BFN7blbw.js";import"./i18n-BJppIrtF.js";import"./index-CKtv7gGE.js";import"./store-GFMJzaWS.js";import"./rigTrack-XaMj1yaH.js";import"./clientJobs-CuuUyhEy.js";const dt=Object.freeze({core:.5,band:.16,ring:.55,sep:22,lo:.1,hi:.78,guideR:2,guideEps:.002,maxW:512,choke:[.5,.66],close:.08,closeArm:.22,chokeAI:[.45,.62],chokeArm:[.22,.4]}),ut=[[0,1],[1,2],[2,3],[3,4],[0,5],[5,6],[6,7],[7,8],[5,9],[9,10],[10,11],[11,12],[9,13],[13,14],[14,15],[15,16],[13,17],[0,17],[17,18],[18,19],[19,20]],at=[0,1,5,9,13,17];function X(l,t,n,g,A,d,y=255){const a=Math.max(0,Math.floor(Math.min(t[0],n[0])-g)),e=Math.min(A-1,Math.ceil(Math.max(t[0],n[0])+g)),p=Math.max(0,Math.floor(Math.min(t[1],n[1])-g)),M=Math.min(d-1,Math.ceil(Math.max(t[1],n[1])+g)),U=n[0]-t[0],i=n[1]-t[1],f=U*U+i*i||1,c=g*g;for(let m=p;m<=M;m++)for(let o=a;o<=e;o++){const N=o+.5-t[0],z=m+.5-t[1],$=Math.max(0,Math.min(1,(N*U+z*i)/f)),H=N-$*U,B=z-$*i;H*H+B*B<=c&&l[m*A+o]<y&&(l[m*A+o]=y)}return l}function W(l,t,n,g,A=255){const d=t.length;if(d<3)return l;let y=1/0,a=-1/0;for(const p of t)p[1]<y&&(y=p[1]),p[1]>a&&(a=p[1]);y=Math.max(0,Math.floor(y)),a=Math.min(g-1,Math.ceil(a));const e=[];for(let p=y;p<=a;p++){const M=p+.5;e.length=0;for(let i=0,f=d-1;i<d;f=i++){const c=t[f],m=t[i];(c[1]<=M&&m[1]>M||m[1]<=M&&c[1]>M)&&e.push([c[0]+(M-c[1])/(m[1]-c[1])*(m[0]-c[0]),m[1]>c[1]?1:-1])}if(e.length<2)continue;e.sort((i,f)=>i[0]-f[0]);let U=0;for(let i=0;i<e.length-1;i++){if(U+=e[i][1],!U)continue;const f=Math.max(0,Math.ceil(e[i][0]-.5)),c=Math.min(n-1,Math.floor(e[i+1][0]-.5)),m=p*n;for(let o=f;o<=c;o++)l[m+o]<A&&(l[m+o]=A)}}return l}function ht(l,t,n,g){const A=t+1,d=l.map(y=>{const a=new Float64Array(A*(n+1));for(let e=0;e<n;e++){let p=0;for(let M=0;M<t;M++)p+=y[e*t+M],a[(e+1)*A+M+1]=a[e*A+M+1]+p}return a});return(y,a,e)=>{const p=d[y],M=Math.max(0,a-g),U=Math.min(t,a+g+1),i=Math.max(0,e-g),f=Math.min(n,e+g+1);return p[f*A+U]-p[i*A+U]-p[f*A+M]+p[i*A+M]}}function Ct(l,t,n,g,A={}){const{learned:d=null,...y}=A,a={...dt,...y},e=t*n,p=new Uint8Array(e),M=new Uint8Array(e),U=new Uint8Array(e),i=new Uint8Array(e),f=new Uint8Array(e),c=(g||[]).filter(r=>r?.lm?.length>=21);if(!c.length)return new Uint8Array(e);const m=r=>r.map(([h,x])=>[h*t,x*n]);let o=0;for(const r of c){o=Math.max(o,Math.hypot((r.lm[0][0]-r.lm[9][0])*t,(r.lm[0][1]-r.lm[9][1])*n)),W(p,m(V(r.lm,t,n,{edge:r.edge?r.edge.map(x=>Math.min(0,x)):null,scale:a.core})),t,n),W(i,m(V(r.lm,t,n,{edge:r.edge})),t,n),W(M,m(V(r.lm,t,n,{edge:r.edge,grow:a.band})),t,n),W(U,m(V(r.lm,t,n,{edge:r.edge,grow:a.ring})),t,n);const h=V(r.lm,t,n,{edge:r.edge,grow:a.band});W(f,m(jt.map(x=>h[x])),t,n)}if(d){const r=new Uint8Array(e),h=new Uint8Array(e);for(const u of c){const s=u.lm.map(([P,L])=>[P*t,L*n]),F=Math.hypot(s[0][0]-s[9][0],s[0][1]-s[9][1]),k=Array.isArray(u.armDir)?u.armDir:[(s[0][0]-s[9][0])/(F||1),(s[0][1]-s[9][1])/(F||1)],j=[s[0][0]+k[0]*4*F,s[0][1]+k[1]*4*F];for(const[P,L]of ut)X(r,s[P],s[L],.45*F,t,n),X(h,s[P],s[L],.08*F,t,n);W(r,at.map(P=>s[P]),t,n),W(h,at.map(P=>s[P]),t,n);const Q=[s[0][0]+k[0]*Math.max(t,n)*1.5,s[0][1]+k[1]*Math.max(t,n)*1.5];X(r,s[0],Q,1.6*F,t,n),X(h,s[0],j,.12*F,t,n)}const x=new Uint8Array(e);for(const u of c){const s=u.lm.map(([k,j])=>[k*t,j*n]),F=Math.hypot(s[0][0]-s[9][0],s[0][1]-s[9][1]);for(const[k,j]of ut)X(x,s[k],s[j],.45*F,t,n);W(x,at.map(k=>s[k]),t,n)}const I=[];for(let u=0;u<e;u+=2)if(h[u]&&x[u]&&d[u]>.6){const s=u*4;I.push([l[s],l[s+1],l[s+2]])}I.sort((u,s)=>u[0]+u[1]+u[2]-s[0]-s[1]-s[2]);const S=I.length>=30?[0,1,2].map(u=>{const s=I.slice(Math.floor(I.length*u/3),Math.floor(I.length*(u+1)/3));return[0,1,2].map(F=>s.reduce((k,j)=>k+j[F],0)/s.length)}):null,D=new Float32Array(e),T=new Float32Array(e),q=new Float32Array(e),C=new Float32Array(e);for(let u=0;u<e;u++)if(d[u]<.1){const s=u*4;D[u]=1,T[u]=l[s],q[u]=l[s+1],C[u]=l[s+2]}const E=S?ht([D,T,q,C],t,n,Math.max(4,Math.round(o*.6))):null,v=u=>{if(!S||!x[u])return 1;const s=u%t,F=u/t|0,k=E(0,s,F);if(k<4)return 1;const j=[E(1,s,F)/k,E(2,s,F)/k,E(3,s,F)/k],Q=u*4,P=[l[Q],l[Q+1],l[Q+2]];let L=0,et=1/0;for(const it of S){const O=[it[0]-j[0],it[1]-j[1],it[2]-j[2]],lt=O[0]*O[0]+O[1]*O[1]+O[2]*O[2];et=Math.min(et,Math.sqrt(lt)),lt>=1&&(L=Math.max(L,((P[0]-j[0])*O[0]+(P[1]-j[1])*O[1]+(P[2]-j[2])*O[2])/lt))}if(et<a.sep)return 1;const rt=Math.max(0,Math.min(1,(L-.12)/.2));return rt*rt*(3-2*rt)},J=d,G=new Uint8Array(e),[R,K]=a.chokeAI,[gt,Ut]=a.chokeArm;for(let u=0;u<e;u++){if(!r[u])continue;const s=x[u]?R:gt,F=x[u]?K:Ut;if(J[u]<s)continue;const k=Math.max(0,Math.min(1,(J[u]-s)/(F-s)))*v(u);G[u]=Math.round(255*k*k*(3-2*k))}return pt(G,t,n,{snapped:h,band:r,core:h,arm:f,r:1,rArm:Math.max(2,Math.round(o*a.closeArm)),small:Math.round(.03*o*o)})}const N=[];for(let r=0;r<e;r+=3)if(p[r]){const h=r*4;N.push([l[h],l[h+1],l[h+2]])}if(N.length<12)return i;N.sort((r,h)=>r[0]+r[1]+r[2]-h[0]-h[1]-h[2]);const z=r=>{const h=N.slice(Math.floor(N.length*r/3),Math.floor(N.length*(r+1)/3));return[0,1,2].map(x=>h.reduce((I,S)=>I+S[x],0)/h.length)},$=[z(0),z(1),z(2)],H=new Float32Array(e),B=new Float32Array(e),w=new Float32Array(e),tt=new Float32Array(e);let st=0,ct=0,ft=0,_=0;for(let r=0;r<e;r++)if(U[r]&&!M[r]){const h=r*4;H[r]=1,B[r]=l[h],w[r]=l[h+1],tt[r]=l[h+2],st+=B[r],ct+=w[r],ft+=tt[r],_++}const yt=_?[st/_,ct/_,ft/_]:null,b=ht([H,B,w,tt],t,n,Math.max(3,Math.round(o*.45))),Z=new Float32Array(e),nt=new Uint8Array(e);for(let r=0;r<n;r++)for(let h=0;h<t;h++){const x=r*t+h;if(!M[x]&&!(d&&U[x]&&!f[x]&&d[x]>.3))continue;if(nt[x]=1,p[x]){Z[x]=1;continue}const I=b(0,h,r),S=I>2?[b(1,h,r)/I,b(2,h,r)/I,b(3,h,r)/I]:yt;if(!S){Z[x]=i[x]/255;continue}const D=x*4,T=[l[D],l[D+1],l[D+2]];let q=0,C=1/0;for(const G of $){const R=[G[0]-S[0],G[1]-S[1],G[2]-S[2]],K=R[0]*R[0]+R[1]*R[1]+R[2]*R[2];C=Math.min(C,Math.sqrt(K)),!(K<1)&&(q=Math.max(q,((T[0]-S[0])*R[0]+(T[1]-S[1])*R[1]+(T[2]-S[2])*R[2])/K))}const E=d&&!f[x]?d[x]:null;if(C<a.sep){Z[x]=E??i[x]/255;continue}const v=Math.max(0,Math.min(1,(q-a.lo)/(a.hi-a.lo))),J=v*v*(3-2*v);Z[x]=E===null?J:E*J}const xt=kt(Z,Ft(l,t,n),t,n,{r:a.guideR,eps:a.guideEps}),ot=new Uint8Array(e),[mt,At]=a.choke;for(let r=0;r<e;r++){if(!nt[r])continue;if(p[r]){ot[r]=255;continue}const h=Math.max(0,Math.min(1,(xt[r]-mt)/(At-mt)));ot[r]=Math.round(255*h*h*(3-2*h))}return pt(ot,t,n,{snapped:i,band:nt,core:p,arm:f,r:Math.max(1,Math.round(o*a.close)),rArm:Math.max(2,Math.round(o*a.closeArm)),small:Math.round(.12*o*o)})}function Mt(l,t,n,g,A,d,y){const a=2*d+1,e=new Uint8Array(n+a),p=new Uint8Array(n+a),M=f=>{const c=Math.max(0,Math.min(n-1,f-d));return l[g+c*A]},U=n+2*d,i=y?(f,c)=>f>c?f:c:(f,c)=>f<c?f:c;for(let f=0;f<U;f+=a){const c=Math.min(U,f+a);e[f]=M(f);for(let m=f+1;m<c;m++)e[m]=i(e[m-1],M(m));p[c-1]=M(c-1);for(let m=c-2;m>=f;m--)p[m]=i(p[m+1],M(m))}for(let f=0;f<n;f++)t[g+f*A]=i(p[f],e[f+2*d]??e[U-1])}function Y(l,t,n,g,A){const d=new Uint8Array(l.length),y=new Uint8Array(l.length);for(let a=0;a<n;a++)Mt(l,d,t,a*t,1,g,A);for(let a=0;a<t;a++)Mt(d,y,n,a,t,g,A);return y}function pt(l,t,n,{snapped:g,band:A,core:d,arm:y,r:a,rArm:e,small:p}){const M=t*n,U=new Uint8Array(M);for(let o=0;o<M;o++)U[o]=l[o]>=128?255:0;const i=Y(Y(U,t,n,a,!0),t,n,a,!1),f=Y(Y(U,t,n,e,!0),t,n,e,!1);for(let o=0;o<M;o++)!U[o]&&A[o]&&(y[o]&&(i[o]||f[o])||!y[o]&&i[o]&&d[o])&&(l[o]=255);It(l,t,n,d,p,y);const c=new Uint8Array(M),m=[];for(let o=0;o<M;o++)d[o]&&l[o]>=64&&m.push(o);for(;m.length;){const o=m.pop();if(c[o]||l[o]<64)continue;c[o]=1;const N=o%t;N>0&&m.push(o-1),N<t-1&&m.push(o+1),o>=t&&m.push(o-t),o<M-t&&m.push(o+t)}for(let o=0;o<M;o++)c[o]||(l[o]=l[o]>=64?0:l[o]);return l}function It(l,t,n,g,A=0,d=null){const y=t*n,a=new Int32Array(y),e=[];for(let i=0;i<t;i++)e.push(i,(n-1)*t+i);for(let i=0;i<n;i++)e.push(i*t,i*t+t-1);const p=(i,f)=>{for(;e.length;){const c=e.pop();if(a[c]||l[c]>=128)continue;a[c]=i,f?.push(c);const m=c%t;m>0&&e.push(c-1),m<t-1&&e.push(c+1),c>=t&&e.push(c-t),c<y-t&&e.push(c+t)}};p(-1);for(let i=0,f=1;i<y;i++){if(a[i]||l[i]>=128)continue;const c=[];e.push(i),p(f++,c);const m=c.length<A&&(!d||c.every(o=>d[o]));for(const o of c)(m||g[o])&&(l[o]=255)}const M=new Uint8Array(y);for(let i=0;i<y;i++)M[i]=a[i]===-1||a[i]>0&&l[i]<128?255:0;const U=Y(M,t,n,2,!0);for(let i=0;i<y;i++)l[i]&&l[i]<255&&!U[i]&&(l[i]=255);return l}function Gt(l,t,n=dt.maxW){const g=Math.min(n,l),A=Math.max(2,Math.round(g*t/l/2)*2);return{w:Math.round(g/2)*2,h:A}}export{dt as HAND_MATTE,X as fillCapsule,W as fillPolygon,Ct as handMatteFrame,Gt as handMatteSize};
1
+ import{g as kt,l as Ft}from"./matteQuality-9X-jgJrH.js";import{cY as Q,cZ as jt}from"./timelineOps-CEGk2t4h.js";import"./titleFrameBudget-BW-N1-cw.js";import"./sceneTrack-DyVxpl7i.js";import"./cameraTracker-DFjnZ7tw.js";import"./textAnimators-CeMuG34D.js";import"./timelineComp-D8PHGHgQ.js";import"./api-DJC95K48.js";import"./i18n-C9zFX25m.js";import"./index-CKtv7gGE.js";import"./store-xR02oY0m.js";import"./rigTrack-B9r9wrdV.js";import"./clientJobs-CuuUyhEy.js";const dt=Object.freeze({core:.5,band:.16,ring:.55,sep:22,lo:.1,hi:.78,guideR:2,guideEps:.002,maxW:512,choke:[.5,.66],close:.08,closeArm:.22,chokeAI:[.45,.62],chokeArm:[.22,.4]}),ut=[[0,1],[1,2],[2,3],[3,4],[0,5],[5,6],[6,7],[7,8],[5,9],[9,10],[10,11],[11,12],[9,13],[13,14],[14,15],[15,16],[13,17],[0,17],[17,18],[18,19],[19,20]],at=[0,1,5,9,13,17];function V(l,t,n,g,A,d,y=255){const a=Math.max(0,Math.floor(Math.min(t[0],n[0])-g)),e=Math.min(A-1,Math.ceil(Math.max(t[0],n[0])+g)),p=Math.max(0,Math.floor(Math.min(t[1],n[1])-g)),M=Math.min(d-1,Math.ceil(Math.max(t[1],n[1])+g)),U=n[0]-t[0],i=n[1]-t[1],f=U*U+i*i||1,c=g*g;for(let m=p;m<=M;m++)for(let o=a;o<=e;o++){const N=o+.5-t[0],z=m+.5-t[1],$=Math.max(0,Math.min(1,(N*U+z*i)/f)),H=N-$*U,B=z-$*i;H*H+B*B<=c&&l[m*A+o]<y&&(l[m*A+o]=y)}return l}function W(l,t,n,g,A=255){const d=t.length;if(d<3)return l;let y=1/0,a=-1/0;for(const p of t)p[1]<y&&(y=p[1]),p[1]>a&&(a=p[1]);y=Math.max(0,Math.floor(y)),a=Math.min(g-1,Math.ceil(a));const e=[];for(let p=y;p<=a;p++){const M=p+.5;e.length=0;for(let i=0,f=d-1;i<d;f=i++){const c=t[f],m=t[i];(c[1]<=M&&m[1]>M||m[1]<=M&&c[1]>M)&&e.push([c[0]+(M-c[1])/(m[1]-c[1])*(m[0]-c[0]),m[1]>c[1]?1:-1])}if(e.length<2)continue;e.sort((i,f)=>i[0]-f[0]);let U=0;for(let i=0;i<e.length-1;i++){if(U+=e[i][1],!U)continue;const f=Math.max(0,Math.ceil(e[i][0]-.5)),c=Math.min(n-1,Math.floor(e[i+1][0]-.5)),m=p*n;for(let o=f;o<=c;o++)l[m+o]<A&&(l[m+o]=A)}}return l}function ht(l,t,n,g){const A=t+1,d=l.map(y=>{const a=new Float64Array(A*(n+1));for(let e=0;e<n;e++){let p=0;for(let M=0;M<t;M++)p+=y[e*t+M],a[(e+1)*A+M+1]=a[e*A+M+1]+p}return a});return(y,a,e)=>{const p=d[y],M=Math.max(0,a-g),U=Math.min(t,a+g+1),i=Math.max(0,e-g),f=Math.min(n,e+g+1);return p[f*A+U]-p[i*A+U]-p[f*A+M]+p[i*A+M]}}function Ct(l,t,n,g,A={}){const{learned:d=null,...y}=A,a={...dt,...y},e=t*n,p=new Uint8Array(e),M=new Uint8Array(e),U=new Uint8Array(e),i=new Uint8Array(e),f=new Uint8Array(e),c=(g||[]).filter(r=>r?.lm?.length>=21);if(!c.length)return new Uint8Array(e);const m=r=>r.map(([h,x])=>[h*t,x*n]);let o=0;for(const r of c){o=Math.max(o,Math.hypot((r.lm[0][0]-r.lm[9][0])*t,(r.lm[0][1]-r.lm[9][1])*n)),W(p,m(Q(r.lm,t,n,{edge:r.edge?r.edge.map(x=>Math.min(0,x)):null,scale:a.core})),t,n),W(i,m(Q(r.lm,t,n,{edge:r.edge})),t,n),W(M,m(Q(r.lm,t,n,{edge:r.edge,grow:a.band})),t,n),W(U,m(Q(r.lm,t,n,{edge:r.edge,grow:a.ring})),t,n);const h=Q(r.lm,t,n,{edge:r.edge,grow:a.band});W(f,m(jt.map(x=>h[x])),t,n)}if(d){const r=new Uint8Array(e),h=new Uint8Array(e);for(const u of c){const s=u.lm.map(([P,L])=>[P*t,L*n]),F=Math.hypot(s[0][0]-s[9][0],s[0][1]-s[9][1]),k=Array.isArray(u.armDir)?u.armDir:[(s[0][0]-s[9][0])/(F||1),(s[0][1]-s[9][1])/(F||1)],j=[s[0][0]+k[0]*4*F,s[0][1]+k[1]*4*F];for(const[P,L]of ut)V(r,s[P],s[L],.45*F,t,n),V(h,s[P],s[L],.08*F,t,n);W(r,at.map(P=>s[P]),t,n),W(h,at.map(P=>s[P]),t,n);const K=[s[0][0]+k[0]*Math.max(t,n)*1.5,s[0][1]+k[1]*Math.max(t,n)*1.5];V(r,s[0],K,1.6*F,t,n),V(h,s[0],j,.12*F,t,n)}const x=new Uint8Array(e);for(const u of c){const s=u.lm.map(([k,j])=>[k*t,j*n]),F=Math.hypot(s[0][0]-s[9][0],s[0][1]-s[9][1]);for(const[k,j]of ut)V(x,s[k],s[j],.45*F,t,n);W(x,at.map(k=>s[k]),t,n)}const I=[];for(let u=0;u<e;u+=2)if(h[u]&&x[u]&&d[u]>.6){const s=u*4;I.push([l[s],l[s+1],l[s+2]])}I.sort((u,s)=>u[0]+u[1]+u[2]-s[0]-s[1]-s[2]);const S=I.length>=30?[0,1,2].map(u=>{const s=I.slice(Math.floor(I.length*u/3),Math.floor(I.length*(u+1)/3));return[0,1,2].map(F=>s.reduce((k,j)=>k+j[F],0)/s.length)}):null,D=new Float32Array(e),T=new Float32Array(e),q=new Float32Array(e),C=new Float32Array(e);for(let u=0;u<e;u++)if(d[u]<.1){const s=u*4;D[u]=1,T[u]=l[s],q[u]=l[s+1],C[u]=l[s+2]}const E=S?ht([D,T,q,C],t,n,Math.max(4,Math.round(o*.6))):null,Y=u=>{if(!S||!x[u])return 1;const s=u%t,F=u/t|0,k=E(0,s,F);if(k<4)return 1;const j=[E(1,s,F)/k,E(2,s,F)/k,E(3,s,F)/k],K=u*4,P=[l[K],l[K+1],l[K+2]];let L=0,et=1/0;for(const it of S){const R=[it[0]-j[0],it[1]-j[1],it[2]-j[2]],lt=R[0]*R[0]+R[1]*R[1]+R[2]*R[2];et=Math.min(et,Math.sqrt(lt)),lt>=1&&(L=Math.max(L,((P[0]-j[0])*R[0]+(P[1]-j[1])*R[1]+(P[2]-j[2])*R[2])/lt))}if(et<a.sep)return 1;const rt=Math.max(0,Math.min(1,(L-.12)/.2));return rt*rt*(3-2*rt)},v=d,G=new Uint8Array(e),[O,J]=a.chokeAI,[gt,Ut]=a.chokeArm;for(let u=0;u<e;u++){if(!r[u])continue;const s=x[u]?O:gt,F=x[u]?J:Ut;if(v[u]<s)continue;const k=Math.max(0,Math.min(1,(v[u]-s)/(F-s)))*Y(u);G[u]=Math.round(255*k*k*(3-2*k))}return pt(G,t,n,{snapped:h,band:r,core:h,arm:f,r:1,rArm:Math.max(2,Math.round(o*a.closeArm)),small:Math.round(.03*o*o)})}const N=[];for(let r=0;r<e;r+=3)if(p[r]){const h=r*4;N.push([l[h],l[h+1],l[h+2]])}if(N.length<12)return i;N.sort((r,h)=>r[0]+r[1]+r[2]-h[0]-h[1]-h[2]);const z=r=>{const h=N.slice(Math.floor(N.length*r/3),Math.floor(N.length*(r+1)/3));return[0,1,2].map(x=>h.reduce((I,S)=>I+S[x],0)/h.length)},$=[z(0),z(1),z(2)],H=new Float32Array(e),B=new Float32Array(e),w=new Float32Array(e),tt=new Float32Array(e);let st=0,ct=0,ft=0,Z=0;for(let r=0;r<e;r++)if(U[r]&&!M[r]){const h=r*4;H[r]=1,B[r]=l[h],w[r]=l[h+1],tt[r]=l[h+2],st+=B[r],ct+=w[r],ft+=tt[r],Z++}const yt=Z?[st/Z,ct/Z,ft/Z]:null,b=ht([H,B,w,tt],t,n,Math.max(3,Math.round(o*.45))),_=new Float32Array(e),nt=new Uint8Array(e);for(let r=0;r<n;r++)for(let h=0;h<t;h++){const x=r*t+h;if(!M[x]&&!(d&&U[x]&&!f[x]&&d[x]>.3))continue;if(nt[x]=1,p[x]){_[x]=1;continue}const I=b(0,h,r),S=I>2?[b(1,h,r)/I,b(2,h,r)/I,b(3,h,r)/I]:yt;if(!S){_[x]=i[x]/255;continue}const D=x*4,T=[l[D],l[D+1],l[D+2]];let q=0,C=1/0;for(const G of $){const O=[G[0]-S[0],G[1]-S[1],G[2]-S[2]],J=O[0]*O[0]+O[1]*O[1]+O[2]*O[2];C=Math.min(C,Math.sqrt(J)),!(J<1)&&(q=Math.max(q,((T[0]-S[0])*O[0]+(T[1]-S[1])*O[1]+(T[2]-S[2])*O[2])/J))}const E=d&&!f[x]?d[x]:null;if(C<a.sep){_[x]=E??i[x]/255;continue}const Y=Math.max(0,Math.min(1,(q-a.lo)/(a.hi-a.lo))),v=Y*Y*(3-2*Y);_[x]=E===null?v:E*v}const xt=kt(_,Ft(l,t,n),t,n,{r:a.guideR,eps:a.guideEps}),ot=new Uint8Array(e),[mt,At]=a.choke;for(let r=0;r<e;r++){if(!nt[r])continue;if(p[r]){ot[r]=255;continue}const h=Math.max(0,Math.min(1,(xt[r]-mt)/(At-mt)));ot[r]=Math.round(255*h*h*(3-2*h))}return pt(ot,t,n,{snapped:i,band:nt,core:p,arm:f,r:Math.max(1,Math.round(o*a.close)),rArm:Math.max(2,Math.round(o*a.closeArm)),small:Math.round(.12*o*o)})}function Mt(l,t,n,g,A,d,y){const a=2*d+1,e=new Uint8Array(n+a),p=new Uint8Array(n+a),M=f=>{const c=Math.max(0,Math.min(n-1,f-d));return l[g+c*A]},U=n+2*d,i=y?(f,c)=>f>c?f:c:(f,c)=>f<c?f:c;for(let f=0;f<U;f+=a){const c=Math.min(U,f+a);e[f]=M(f);for(let m=f+1;m<c;m++)e[m]=i(e[m-1],M(m));p[c-1]=M(c-1);for(let m=c-2;m>=f;m--)p[m]=i(p[m+1],M(m))}for(let f=0;f<n;f++)t[g+f*A]=i(p[f],e[f+2*d]??e[U-1])}function X(l,t,n,g,A){const d=new Uint8Array(l.length),y=new Uint8Array(l.length);for(let a=0;a<n;a++)Mt(l,d,t,a*t,1,g,A);for(let a=0;a<t;a++)Mt(d,y,n,a,t,g,A);return y}function pt(l,t,n,{snapped:g,band:A,core:d,arm:y,r:a,rArm:e,small:p}){const M=t*n,U=new Uint8Array(M);for(let o=0;o<M;o++)U[o]=l[o]>=128?255:0;const i=X(X(U,t,n,a,!0),t,n,a,!1),f=X(X(U,t,n,e,!0),t,n,e,!1);for(let o=0;o<M;o++)!U[o]&&A[o]&&(y[o]&&(i[o]||f[o])||!y[o]&&i[o]&&d[o])&&(l[o]=255);It(l,t,n,d,p,y);const c=new Uint8Array(M),m=[];for(let o=0;o<M;o++)d[o]&&l[o]>=64&&m.push(o);for(;m.length;){const o=m.pop();if(c[o]||l[o]<64)continue;c[o]=1;const N=o%t;N>0&&m.push(o-1),N<t-1&&m.push(o+1),o>=t&&m.push(o-t),o<M-t&&m.push(o+t)}for(let o=0;o<M;o++)c[o]||(l[o]=l[o]>=64?0:l[o]);return l}function It(l,t,n,g,A=0,d=null){const y=t*n,a=new Int32Array(y),e=[];for(let i=0;i<t;i++)e.push(i,(n-1)*t+i);for(let i=0;i<n;i++)e.push(i*t,i*t+t-1);const p=(i,f)=>{for(;e.length;){const c=e.pop();if(a[c]||l[c]>=128)continue;a[c]=i,f?.push(c);const m=c%t;m>0&&e.push(c-1),m<t-1&&e.push(c+1),c>=t&&e.push(c-t),c<y-t&&e.push(c+t)}};p(-1);for(let i=0,f=1;i<y;i++){if(a[i]||l[i]>=128)continue;const c=[];e.push(i),p(f++,c);const m=c.length<A&&(!d||c.every(o=>d[o]));for(const o of c)(m||g[o])&&(l[o]=255)}const M=new Uint8Array(y);for(let i=0;i<y;i++)M[i]=a[i]===-1||a[i]>0&&l[i]<128?255:0;const U=X(M,t,n,2,!0);for(let i=0;i<y;i++)l[i]&&l[i]<255&&!U[i]&&(l[i]=255);return l}function Gt(l,t,n=dt.maxW){const g=Math.min(n,l),A=Math.max(2,Math.round(g*t/l/2)*2);return{w:Math.round(g/2)*2,h:A}}export{dt as HAND_MATTE,V as fillCapsule,W as fillPolygon,Ct as handMatteFrame,Gt as handMatteSize};
@@ -0,0 +1,2 @@
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/objectSegmenter-oGv8YQbI.js","assets/titleFrameBudget-BW-N1-cw.js","assets/personHq-Cyq9HWnW.js","assets/matteQuality-9X-jgJrH.js","assets/api-DJC95K48.js","assets/i18n-C9zFX25m.js","assets/index-CKtv7gGE.js","assets/cutoutClean-CLYYAuXg.js","assets/handMatte-CvFkZKTL.js","assets/timelineOps-CEGk2t4h.js","assets/sceneTrack-DyVxpl7i.js","assets/cameraTracker-DFjnZ7tw.js","assets/textAnimators-CeMuG34D.js","assets/timelineComp-D8PHGHgQ.js","assets/store-xR02oY0m.js","assets/rigTrack-B9r9wrdV.js","assets/clientJobs-CuuUyhEy.js","assets/matteFixRun-BHD3Qnta.js","assets/main-DAk1Tv1E.js","assets/remote-kxNNhmis.js","assets/three.module-Bx43vjkH.js","assets/gltfLoader-U0Eebg7v.js","assets/rotoMaskStore-RmW40Pcn.js","assets/spark.module-B341moK0.js","assets/userFonts-DSkZHfmh.js","assets/lottieLayer-Dp_vGTy8.js","assets/timeline3d-D0Ws4lcp.js","assets/RoomEnvironment-Dmv_G5ka.js","assets/glTransitionSources.generated-BJuEUz3E.js","assets/clientJobs-BqkjV5Ld.js","assets/captionLayout-CAuhUiW9.js","assets/timelineText-DjPW2-dd.js","assets/titleArt-BSu80bfN.js","assets/sceneTrack-BKknn180.js","assets/rotoMatte-DisQplSv.js","assets/distortGL-waTJhiOf.js","assets/motionBlur-uAm030t9.js","assets/main-B_MAOvi6.css"])))=>i.map(i=>d[i]);
2
+ import{b_ as Y,_ as N,a7 as Z,da as tt}from"./titleFrameBudget-BW-N1-cw.js";import{u as W}from"./store-xR02oY0m.js";import{t as j}from"./i18n-C9zFX25m.js";import{m as et,g as at,S as J,M as nt}from"./personHq-Cyq9HWnW.js";import{cO as ot,cP as it,cQ as Q,cR as rt,cS as st,cT as K,cU as ct,ay as z,cV as lt,cW as dt,cX as mt}from"./timelineOps-CEGk2t4h.js";import{handMatteSize as ut,handMatteFrame as ht}from"./handMatte-CvFkZKTL.js";import{t as ft}from"./matteQuality-9X-jgJrH.js";import"./index-CKtv7gGE.js";import"./api-DJC95K48.js";import"./sceneTrack-DyVxpl7i.js";import"./cameraTracker-DFjnZ7tw.js";import"./textAnimators-CeMuG34D.js";import"./timelineComp-D8PHGHgQ.js";import"./rigTrack-B9r9wrdV.js";import"./clientJobs-CuuUyhEy.js";const pt="https://storage.googleapis.com/mediapipe-models/hand_landmarker/hand_landmarker/float16/1/hand_landmarker.task",wt=`https://cdn.jsdelivr.net/npm/@mediapipe/tasks-vision@${J}/wasm`,gt=640;let $=null;async function yt(){if(typeof window<"u"&&window.__handTrackerStub)return{detect:window.__handTrackerStub,close:()=>{}};const{FilesetResolver:d,HandLandmarker:w}=await N(async()=>{const{FilesetResolver:c,HandLandmarker:s}=await import("./vision_bundle-9zIsgJJP.js");return{FilesetResolver:c,HandLandmarker:s}},[]);$??=d.forVisionTasks(wt).catch(c=>{throw $=null,c});const a=await w.createFromOptions(await $,{baseOptions:{modelAssetPath:pt,delegate:"CPU"},runningMode:"VIDEO",numHands:2,minHandDetectionConfidence:.5,minHandPresenceConfidence:.5,minTrackingConfidence:.5});let f=0;return{detect:(c,s)=>{f=Math.max(f+1,Math.round(s));const b=a.detectForVideo(c,f);return(b.landmarks??[]).map((m,v)=>({lm:m.map(p=>[p.x,p.y]),label:b.handedness?.[v]?.[0]?.categoryName??"",score:b.handedness?.[v]?.[0]?.score??1}))},close:()=>a.close()}}async function Mt({clip:d,url:w,from:a,duration:f,signal:c,onProgress:s}){const b=f*(d.playbackRate||1),m=b*30<=K.maxFrames?30:15,v=Math.max(2,Math.min(K.maxFrames,Math.round(b*m)+1)),{detect:p,close:C}=await yt(),u=Object.assign(document.createElement("video"),{muted:!0,playsInline:!0,preload:"auto",crossOrigin:"anonymous"});u.src=w;try{await new Promise((i,h)=>{u.onloadeddata=()=>i(),u.onerror=()=>h(Error(j("Không đọc được video để bám tay (CORS / định dạng)")))});const x=u.videoWidth||1280,H=u.videoHeight||720,_=Math.min(gt,x),o=Math.max(2,Math.round(_*H/x)),r=Object.assign(document.createElement("canvas"),{width:_,height:o}),y=r.getContext("2d",{willReadFrequently:!0}),E=z(d,a),T=[];let n=[null,null];for(let i=0;i<v;i++){if(c?.aborted)throw new DOMException("Đã huỷ","AbortError");const h=Math.max(0,Math.min(u.duration-1/60,E+i/m));Math.abs(u.currentTime-h)>1e-4&&await new Promise((t,e)=>{const l=window.setTimeout(()=>e(Error(j("Seek video quá lâu"))),8e3);u.onseeked=()=>{window.clearTimeout(l),t()},u.currentTime=h}),y.drawImage(u,0,0,_,o);const S=p(r,(i+1)*1e3/m).filter(t=>Array.isArray(t.lm)&&t.lm.length>=21).slice(0,2),k=[null,null],F=t=>t.label==="Left"?0:t.label==="Right"?1:-1,M=(t,e)=>{const l=n[e];return l?Math.hypot(l.lm[0][0]-t.lm[0][0],l.lm[0][1]-t.lm[0][1]):1/0};if(S.length===2&&F(S[0])===F(S[1])){const t=S[0],e=S[1],l=M(t,0)+M(e,1)<=M(t,1)+M(e,0),[I,A]=Number.isFinite(M(t,0)+M(e,1))||Number.isFinite(M(t,1)+M(e,0))?l?[t,e]:[e,t]:t.lm[0][0]>e.lm[0][0]?[t,e]:[e,t];k[0]={lm:I.lm.map(R=>[R[0],R[1]]),score:I.score},k[1]={lm:A.lm.map(R=>[R[0],R[1]]),score:A.score}}else for(const t of S){let e=F(t);if(e<0&&(e=t.lm[0][0]>.5?0:1),S.length===1){const l=1-e;M(t,l)<.08&&M(t,e)>.15&&(e=l)}k[e]||(k[e]={lm:t.lm.map(l=>[l[0],l[1]]),score:t.score})}if(k.some(Boolean)){const t=y.getImageData(0,0,_,o).data,e=(l,I)=>{const A=(Math.max(0,Math.min(o-1,I))*_+Math.max(0,Math.min(_-1,l)))*4;return[t[A],t[A+1],t[A+2]]};for(const l of k)if(l){const I=dt(l.lm,_,o,e);I&&(l.edge=I)}}T.push(k),n=[k[0]??n[0],k[1]??n[1]],s?.(i+1,v)}return mt({mw:x,mh:H,fps:m,s0:E,frames:T})}finally{u.removeAttribute("src"),u.load(),C()}}let B=null,q=null;async function xt(d,w,a){const f=typeof window<"u"?window.__bodySkinStub:void 0;B??=f?Promise.resolve(f):(async()=>{const{FilesetResolver:p,ImageSegmenter:C}=await N(async()=>{const{FilesetResolver:H,ImageSegmenter:_}=await import("./vision_bundle-9zIsgJJP.js");return{FilesetResolver:H,ImageSegmenter:_}},[]),u=await p.forVisionTasks(`https://cdn.jsdelivr.net/npm/@mediapipe/tasks-vision@${J}/wasm`),x=await C.createFromOptions(u,{baseOptions:{modelAssetPath:nt,delegate:"CPU"},runningMode:"IMAGE",outputConfidenceMasks:!0,outputCategoryMask:!1});return H=>{const _=x.segment(H);try{const o=_.confidenceMasks?.[2];if(!o)throw Error("no skin mask");return{data:o.getAsFloat32Array().slice(),width:o.width,height:o.height}}finally{_.close()}}})().catch(p=>{throw B=null,p});const c=await B;q??=document.createElement("canvas");const s=960,b=Math.max(2,Math.round(960*d.height/d.width));(q.width!==s||q.height!==b)&&Object.assign(q,{width:s,height:b}),q.getContext("2d").drawImage(d,0,0,s,b);const m=c(q),v=new Float32Array(w*a);for(let p=0;p<a;p++){const C=Math.min(m.height-1,Math.floor((p+.5)/a*m.height))*m.width;for(let u=0;u<w;u++){const x=m.data[C+Math.min(m.width-1,Math.floor((u+.5)/w*m.width))];v[p*w+u]=Math.max(0,Math.min(1,(x-.25)/.4))}}return v}const kt=[0,1,2,3,5,6,7,9,10,11,13,14,15,17,18,19];let G=null;async function bt(d,w,a,f,c,s){const{objectProbability:b}=await N(async()=>{const{objectProbability:o}=await import("./objectSegmenter-oGv8YQbI.js");return{objectProbability:o}},__vite__mapDeps([0,1,2,3,4,5,6,7])),m=new Float32Array(c*s),v=512;G??=Object.assign(document.createElement("canvas"),{width:v,height:v});const p=G.getContext("2d",{willReadFrequently:!0}),C=async(o,r,y,E,T)=>{p.fillStyle="#000",p.fillRect(0,0,v,v),p.drawImage(d,o,r,y,E,0,0,v,v);const n=await b(G,T.map(h=>({x:(h.x-o)/y,y:(h.y-r)/E})).filter(h=>h.x>0&&h.x<1&&h.y>0&&h.y<1)),i=new Float32Array(c*s);for(let h=0;h<s;h++){const S=((h+.5)/s*a-r)/E;if(S<0||S>=1)continue;const k=Math.floor(S*n.height)*n.width;for(let F=0;F<c;F++){const M=((F+.5)/c*w-o)/y;M<0||M>=1||(i[h*c+F]=n.data[k+Math.floor(M*n.width)])}}return i},{fillCapsule:u,fillPolygon:x}=await N(async()=>{const{fillCapsule:o,fillPolygon:r}=await import("./handMatte-CvFkZKTL.js");return{fillCapsule:o,fillPolygon:r}},__vite__mapDeps([8,3,9,1,10,11,12,13,4,5,6,14,15,16])),H=[],_=await xt(d,c,s);for(const{lm:o}of f){const r=o.map(t=>t[0]*w),y=o.map(t=>t[1]*a),E=Math.hypot(r[0]-r[9],y[0]-y[9])||1,T=kt.map(t=>({x:r[t],y:y[t]}));T.push({x:r[0]+(r[0]-r[9])*.6,y:y[0]+(y[0]-y[9])*.6});const i=await C(...((t,e,l,I=1)=>{const A=Math.min(...t)-l,R=Math.max(...t)+l,O=Math.min(...e)-l,g=Math.max(...e)+l,P=Math.max(R-A,g-O),D=Math.min(w,Math.max(R-A,P/I)),V=Math.min(a,Math.max(g-O,P/I)),L=Math.min(D,V*I),U=Math.min(V,D*I);return[Math.max(0,Math.min(w-L,(A+R)/2-L/2)),Math.max(0,Math.min(a-U,(O+g)/2-U/2)),L,U]})([...r,r[0]+(r[0]-r[9])*3],[...y,y[0]+(y[0]-y[9])*3],.6*E),T);let h=(r[0]-r[9])/E,S=(y[0]-y[9])/E;{const t=r[0]/w*c,e=y[0]/a*s,l=E/w*c;let I=0,A=0,R=0;for(let O=0;O<s;O++)for(let g=0;g<c;g++){if(i[O*c+g]<.5)continue;const P=Math.hypot(g-t,O-e);if(P<1.2*l||P>3*l)continue;const D=g-t,V=O-e;D*h+V*S<-.2*P||(I+=g,A+=O,R++)}if(R>20){const O=I/R-t,g=A/R-e,P=Math.hypot(O,g)||1;(O*h+g*S)/P>Math.cos(75*Math.PI/180)&&(h=O/P,S=g/P)}}H.push([h,S]);const k=new Uint8Array(c*s),F=r.map((t,e)=>[t/w*c,y[e]/a*s]),M=E/w*c;for(const[t,e]of[[1,2],[2,3],[3,4],[5,6],[6,7],[7,8],[9,10],[10,11],[11,12],[13,14],[14,15],[15,16],[17,18],[18,19],[19,20],[0,1],[0,5],[0,17]])u(k,F[t],F[e],.35*M,c,s);x(k,[0,1,5,9,13,17].map(t=>F[t]),c,s);for(let t=0;t<c*s;t++){const e=k[t]?Math.max(i[t],_[t]*.5):_[t];e>m[t]&&(m[t]=e)}}return{map:m,armDirs:H}}async function X({clip:d,url:w,from:a,duration:f,until:c=1/0,refine:s=null,store:b=!0,signal:m,onProgress:v}){if(!d.hands)throw Error(j("Không tìm thấy clip video có tay"));const p=ct(d.hands),C=d.playbackRate||1,u=p.fps,x=Object.assign(document.createElement("video"),{muted:!0,playsInline:!0,preload:"auto",crossOrigin:"anonymous"});x.src=w;try{await new Promise((t,e)=>{x.onloadeddata=()=>t(),x.onerror=()=>e(Error(j("Không đọc được video để bám tay (CORS / định dạng)")))});const H=x.videoWidth||p.mw,_=x.videoHeight||p.mh,{w:o,h:r}=ut(H,_),y=Object.assign(document.createElement("canvas"),{width:o,height:r}),E=y.getContext("2d",{willReadFrequently:!0}),T=z(d,a),n=Math.max(1,Math.min(K.maxFrames,Math.round(f*C*u)+1)),i=z(d,c),h=et({mw:H,mh:_,w:o,h:r,fps:u,s0:T},32),S=ft(t=>h.push(t)),k=s?await Z(s):null,F=at(x);let M=!0;for(let t=0;t<n;t++){if(m?.aborted)throw new DOMException("Đã huỷ","AbortError");const e=T+t/u;if(e>i+1e-6){S.push(new Uint8Array(o*r)),v?.(t+1,n);continue}const l=await F(Math.max(0,Math.min(x.duration-1/60,e)));E.drawImage(l,0,0,o,r);const I=Math.max(0,Math.min(p.n-1,Math.round((e-p.s0)*u))),A=[0,1].map(g=>{const P=lt(p,e,g);return P?{lm:P,edge:p.frames[I][g]?.edge??null}:null}).filter(Boolean);let R=null;if(M&&A.length)try{const g=await bt(l,H,_,A,o,r);R=g.map,g.armDirs.forEach((P,D)=>{A[D].armDir=P})}catch(g){M=!1,console.warn("hand cut-out model",g)}let O=A.length?ht(E.getImageData(0,0,o,r).data,o,r,A,{learned:R}):new Uint8Array(o*r);if(k&&s){const g=tt(k,s,e),P=s.w,D=s.h,V=new Uint8Array(o*r);for(let L=0;L<r;L++)for(let U=0;U<o;U++)V[L*o+U]=Math.round(O[L*o+U]*g[Math.min(D-1,Math.floor(L*D/r))*P+Math.min(P-1,Math.floor(U*P/o))]/255);O=V}S.push(O),v?.(t+1,n),t%4===3&&await new Promise(g=>setTimeout(g,0))}return S.finish(),await h.finish({feather:0,grow:0},{store:b})}finally{x.removeAttribute("src"),x.load()}}async function vt(d,w,a){const f=W.getState().clips.find(b=>b.id===d);if(!f||f.kind!=="video")throw Error(j("Không tìm thấy clip video có tay"));if(st(f,w,a))return f;const c=document.querySelector(`video[data-clip-media="${f.id}"]`)?.currentSrc||f.url,s=await Mt({clip:f,url:c,from:w,duration:Math.min(a,K.maxFrames/15/(f.playbackRate||1))});if(!s.data||!/[^A]/.test(s.data.replace(/=+$/,"")))throw Error(j("Không thấy bàn tay nào trong đoạn này"));return W.setState(b=>({clips:b.clips.map(m=>m.id===f.id?{...m,hands:s}:m)})),{...f,hands:s}}const St=d=>new Promise(w=>setTimeout(w,d));async function Wt(d,w){const a=w.params??{},f=await vt(String(a.source),a.from??0,a.duration??d.duration),c=W.getState(),{width:s,height:b}=Y(c.timelineFormat);if(a.mode==="attach"){const n=c.clips.find(i=>i.id===d.id)??d;return ot(n,f,{point:a.point,side:a.side,scale:!!a.scale,offset:a.offset??null,W:s,H:b})}if(a.mode==="wipe"){const n=c.clips.find(e=>e.id===d.id)??d,i=c.clips.find(e=>e.id===f.id)??f,h=n.mask,S=it(n,i,{point:a.point,side:a.side,dir:a.dir,feather:a.feather,W:s,H:b,mw:h?.mw,mh:h?.mh}),k=c.clips.find(e=>e.id===a.cutout),F=document.querySelector(`video[data-clip-media="${i.id}"]`)?.currentSrc||i.url;let M=null;if(k)try{M=await X({clip:i,url:F,from:a.from??0,duration:a.duration??d.duration,refine:k.person??null})}catch(e){console.warn("hand matte",e)}const t=M||!k?void 0:Q({...k,hands:i.hands});return W.setState(e=>({clips:e.clips.map(l=>l.id===a.cutout?M?{...l,person:M,mask:void 0}:t?{...l,mask:t}:l:l)})),S.patch}for(let n=0;n<360&&W.getState().clips.find(i=>i.id===a.wall)?.pendingPin;n++)await St(500);const m=W.getState(),v=m.clips.find(n=>n.id===a.wall),p=m.clips.find(n=>n.id===d.id)??d,C=m.clips.find(n=>n.id===f.id)??f;if(!v)throw Error(j("Không còn tường HUD"));const u=rt({wall:v,layer:p,src:C,clips:m.clips,cam:m.timelineCamera,W:s,H:b,events:a.events??null,grab:a.grab??"auto",side:a.side,fly:a.fly}),x=m.clips.find(n=>n.id===a.cutout),H=document.querySelector(`video[data-clip-media="${C.id}"]`)?.currentSrc||C.url,_=(a.matte?m.clips.find(n=>n.id===a.matte)?.person:null)??x?.person??null;let o=null;if(x)try{o=await X({clip:C,url:H,from:a.from??0,duration:a.duration??d.duration,until:u.cutoutUntil,refine:_})}catch(n){console.warn("hand matte",n)}const r=x?.matteFix?.fixes??[],y=o;if(o&&r.length)try{const{fixedMatte:n}=await N(async()=>{const{fixedMatte:i}=await import("./matteFixRun-BHD3Qnta.js");return{fixedMatte:i}},__vite__mapDeps([17,14,1,6,5,2,3,4,9,10,11,12,13,15,16,8,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,0,7,35,36,37]));o=await n(o,r,C.hands)}catch(n){console.warn("hand touch-ups",n)}const E=o?void 0:Q(C,{until:u.cutoutUntil}),T=n=>{const i=n.mask?.masks?.find(h=>h.id==="wall");return!i||!n.mask?n:o?{...n,person:o,mask:{...n.mask,masks:[{...i,mode:"add"}]}}:E?{...n,mask:{...E,masks:[...E.masks,{...i,mode:"intersect"}]}}:n};return W.setState(n=>({clips:n.clips.map(i=>i.id===v.id?{...i,motion:u.wall}:i.id===a.cutout?o?{...i,person:o,mask:void 0,...r.length?{matteFix:{auto:y,fixes:r}}:{}}:E?{...i,mask:E}:i:i.id===a.shadow?T(i):i)})),{motion:u.grab}}export{pt as HAND_MODEL_URL,X as buildHandMatte,bt as learnedHands,Wt as runHandTrack,Mt as trackHands};