clipoox-render 0.1.0 → 0.3.0

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 (155) hide show
  1. package/dist/server-text/titleRaster.js +1394 -0
  2. package/package.json +5 -3
  3. package/scripts/render-local.mjs +1617 -1481
  4. package/shared/transitionStarterPack.json +261 -0
  5. package/web/assets/FxEmbed-D7k1ThAF.js +1 -0
  6. package/web/assets/{GLTFLoader-Dy6SrZg8.js → GLTFLoader-BHWu1lKg.js} +1 -1
  7. package/web/assets/MotionEmbed-DFni5IAh.js +1 -0
  8. package/web/assets/PluginStore-BrupM_8E.js +3 -0
  9. package/web/assets/{ShotComposer-AHScyNYv.js → ShotComposer-BLztjSKy.js} +4 -4
  10. package/web/assets/TemplateEmbed-BbAimhLj.js +2 -0
  11. package/web/assets/TimelinePlugins-BI1bE9pX.js +5 -0
  12. package/web/assets/TimelinePlugins-DYarX9RK.css +1 -0
  13. package/web/assets/TimelineShotFx-CQN3WIfN.js +2 -0
  14. package/web/assets/TransitionEmbed-CmoIrHVr.js +1 -0
  15. package/web/assets/{Whiteboard-C9Mwa3nF.js → Whiteboard-DMk0unYK.js} +3 -3
  16. package/web/assets/aerial-DT_gUtSh.js +2 -0
  17. package/web/assets/agentTools-qOww5RUs.js +2 -0
  18. package/web/assets/analyzerRun-B2FLUp4G.js +1 -0
  19. package/web/assets/{analyzerSandbox-DQGHjUCa.js → analyzerSandbox-CJVsEhrg.js} +2 -2
  20. package/web/assets/{api-C5pOWyBM.js → api-QBI5GJTZ.js} +148 -148
  21. package/web/assets/auraTrack-CEs_Q9EP.js +1 -0
  22. package/web/assets/breakthrough-DvkxvNK9.js +2 -0
  23. package/web/assets/{cameraPresets-CeStHDvF.js → cameraPresets-4pFeF2YG.js} +1 -1
  24. package/web/assets/{captionLayout-BAdmqwdS.js → captionLayout-C67EMVI1.js} +1 -1
  25. package/web/assets/clientExport-C4VgAJtO.js +1 -0
  26. package/web/assets/{depthEstimate-1OjTo_pb.js → depthEstimate-mnXDZMW-.js} +1 -1
  27. package/web/assets/directorTools-BOHZjcww.js +1 -0
  28. package/web/assets/{distortFrames-D39fkQ_H.js → distortFrames-Csuj2jHE.js} +2 -2
  29. package/web/assets/{distortGL-5uNfls9s.js → distortGL-BaXfN0IK.js} +2 -2
  30. package/web/assets/editTools-m0VGPmfF.js +1 -0
  31. package/web/assets/{exportEncode-pFxeatJt.js → exportEncode-D9OT7_5k.js} +1 -1
  32. package/web/assets/exportGlb-CLfTnbMG.js +2 -0
  33. package/web/assets/faceTracker-W0iZSiMe.js +1 -0
  34. package/web/assets/fightDirector-CECPf2iH.js +1 -0
  35. package/web/assets/fightDrama-CqNoa5XI.js +2 -0
  36. package/web/assets/{frameSink-CB1EghW0.js → frameSink-BGRj7wqY.js} +3 -3
  37. package/web/assets/{gpuCompose-EfzSAeMh.js → gpuCompose-CIEoLFem.js} +1 -1
  38. package/web/assets/gpuExport-uyOAyrhm.js +190 -0
  39. package/web/assets/handMatte-mHxZwLZD.js +1 -0
  40. package/web/assets/handTracker-dTVeSUzt.js +2 -0
  41. package/web/assets/{index-BGZJld3s.js → index-D7M5t2re.js} +1 -1
  42. package/web/assets/layer-worker-Cp0pjurp.js +5 -0
  43. package/web/assets/library-Dsz_MLyd.js +1 -0
  44. package/web/assets/{lottieLayer-BhLbZOpr.js → lottieLayer-CDCGeJyv.js} +5 -5
  45. package/web/assets/{lottie_light_canvas-D9fsNLID.js → lottie_light_canvas-BblLU4nU.js} +1 -1
  46. package/web/assets/main-BQ8IY0WV.css +1 -0
  47. package/web/assets/{main-BNZrzSIG.js → main-CVRIuDW2.js} +76 -76
  48. package/web/assets/{mapBake-BAG6i5fI.js → mapBake-CNMOKXA7.js} +1 -1
  49. package/web/assets/maskTrack-Dtv6Jr06.js +1 -0
  50. package/web/assets/matteFixRun-BLDH2AjH.js +1 -0
  51. package/web/assets/motionBlur-uAm030t9.js +1 -0
  52. package/web/assets/{objectLocate-Dhktxe5z.js → objectLocate-Cy3IFBSF.js} +1 -1
  53. package/web/assets/{objectTrack.worker-ENzKeSiV.js → objectTrack.worker-BlZkgpOX.js} +483 -352
  54. package/web/assets/pendingMatte-C2AWApuv.js +2 -0
  55. package/web/assets/personAi-DPUnoymj.js +2 -0
  56. package/web/assets/plateCamera-C96L5GKm.js +1 -0
  57. package/web/assets/plateCameraMatch-Chk-ZjDi.js +2 -0
  58. package/web/assets/plateFollow-B9_QTgvo.js +2 -0
  59. package/web/assets/plateMatte-BiqyI_8x.js +2 -0
  60. package/web/assets/{pluginAutomation-DdZOnpoV.js → pluginAutomation-5DYldFrb.js} +1 -1
  61. package/web/assets/poseTracker-PuI8vWpR.js +1 -0
  62. package/web/assets/productTools-B1h5cgyt.js +2 -0
  63. package/web/assets/remote-BJdzzFZg.js +1241 -0
  64. package/web/assets/rigTrack-CUt4O67J.js +1 -0
  65. package/web/assets/{rotoMaskStore-DrRawyH9.js → rotoMaskStore-DIi45swK.js} +1 -1
  66. package/web/assets/{rotoMatte-2EcyuvBX.js → rotoMatte-013RKqHu.js} +1 -1
  67. package/web/assets/rotoscope-d_TUxa-J.js +1 -0
  68. package/web/assets/{sceneTrack.worker-CEvCN5OB.js → sceneTrack.worker-CT4uoTKn.js} +475 -344
  69. package/web/assets/shot-worker-B1iZT6F5.js +1 -0
  70. package/web/assets/{shotFxAgent-CETPcjzU.js → shotFxAgent-BDfe73TP.js} +2 -2
  71. package/web/assets/{skin-BQG1Iz6Q.js → skin-GDY3QPkV.js} +1 -1
  72. package/web/assets/{spark.module-CMSPLU2n.js → spark.module-DdwuJ_hb.js} +10 -10
  73. package/web/assets/spellDuel-DjNN00bv.js +2 -0
  74. package/web/assets/{store-Dxq3MZF3.js → store-2zneEhhu.js} +1 -1
  75. package/web/assets/{surfaceLight-B_OSTxcx.js → surfaceLight-B_SYg_f8.js} +1 -1
  76. package/web/assets/surfacePin-zDPmq-hH.js +2 -0
  77. package/web/assets/textAnimators-Bdt5LWXk.js +1 -0
  78. package/web/assets/{thumb-xLFX6lDN.js → thumb-byAKvhQP.js} +1 -1
  79. package/web/assets/timeline3d-YIIk_Kn2.js +2 -0
  80. package/web/assets/timeline3dExport-CEH1RjNf.js +1 -0
  81. package/web/assets/timelineComp-B73i_8vD.js +1 -0
  82. package/web/assets/timelineProps-B2pnudeT.js +1 -0
  83. package/web/assets/timelineText-BcL4Pw3C.js +1 -0
  84. package/web/assets/{titleArt-CAOxtyHl.js → titleArt-hb_T45WJ.js} +5 -5
  85. package/web/assets/{titleFrameBudget-BjW--v_T.js → titleFrameBudget-Cml-MO53.js} +970 -839
  86. package/web/assets/titleFrames-Dw0PEBdV.js +1 -0
  87. package/web/assets/{tool-DEWWeyCz.js → tool-Bt9bclIf.js} +1 -1
  88. package/web/assets/tools-BXeJbgZJ.js +1 -0
  89. package/web/assets/toonTools-u7Y9fdEZ.js +2 -0
  90. package/web/assets/trackAnchor-9MnVHe4S.js +1 -0
  91. package/web/assets/userFonts-BHduCNtc.js +1 -0
  92. package/web/assets/{vfxAlpha-vbbI-03F.js → vfxAlpha-DpV4rbI-.js} +2 -2
  93. package/web/assets/vfxBackground-Ddviync5.js +2 -0
  94. package/web/assets/videoExport-z5WjM0hw.js +1 -0
  95. package/web/assets/views-CsrYzCSR.js +1 -0
  96. package/web/assets/weaponDuel-CLLgv5A4.js +1 -0
  97. package/web/assets/{windowFrames-DydW5Al5.js → windowFrames-BQEWQkEs.js} +1 -1
  98. package/web/layer-worker.html +3 -3
  99. package/web/assets/FxEmbed-B5TQxKxk.js +0 -1
  100. package/web/assets/MotionEmbed-Catb_GgA.js +0 -1
  101. package/web/assets/PluginStore-8TjQawtB.js +0 -3
  102. package/web/assets/TemplateEmbed-Cao8Z5fY.js +0 -2
  103. package/web/assets/TimelinePlugins-B5WmAawO.css +0 -1
  104. package/web/assets/TimelinePlugins-CkP5P9b_.js +0 -5
  105. package/web/assets/TimelineShotFx-DvmPZQXM.js +0 -2
  106. package/web/assets/TransitionEmbed-o4UxJ35e.js +0 -1
  107. package/web/assets/aerial-BPRLPci2.js +0 -2
  108. package/web/assets/agentTools-CSnN-LvS.js +0 -2
  109. package/web/assets/analyzerRun-5zJsmMS1.js +0 -1
  110. package/web/assets/auraTrack-pF-WhpH3.js +0 -1
  111. package/web/assets/breakthrough-DQN1i-Pw.js +0 -2
  112. package/web/assets/clientExport-Ca9a3Jiy.js +0 -1
  113. package/web/assets/desktop-BWhFnYwd.js +0 -1
  114. package/web/assets/directorTools-CvmghG_6.js +0 -1
  115. package/web/assets/editTools-CUoVvupD.js +0 -1
  116. package/web/assets/exportGlb-MK05aKqH.js +0 -2
  117. package/web/assets/faceTracker-_rQOgBvX.js +0 -1
  118. package/web/assets/fightDirector-Dt60kfbV.js +0 -1
  119. package/web/assets/fightDrama-py4jxSdn.js +0 -2
  120. package/web/assets/gpuExport-Cnv2NfEb.js +0 -189
  121. package/web/assets/handMatte-DZCsuqD2.js +0 -1
  122. package/web/assets/handTracker-Btr9L-Hu.js +0 -2
  123. package/web/assets/layer-worker-Rbo-YZv-.js +0 -5
  124. package/web/assets/library-CdukL2BW.js +0 -1
  125. package/web/assets/main-By_IEoB_.css +0 -1
  126. package/web/assets/maskTrack-AZwAVz1c.js +0 -1
  127. package/web/assets/matteFixRun-wTHGiGGf.js +0 -1
  128. package/web/assets/pendingMatte-iKz2-XBZ.js +0 -2
  129. package/web/assets/personAi-BEVyjCii.js +0 -2
  130. package/web/assets/plateCamera-D_J3-X06.js +0 -1
  131. package/web/assets/plateCameraMatch-C0peOvBn.js +0 -2
  132. package/web/assets/plateFollow-BbJMVxfg.js +0 -2
  133. package/web/assets/plateMatte-u5wKpsUN.js +0 -2
  134. package/web/assets/poseTracker--VJYw-hX.js +0 -1
  135. package/web/assets/productTools-DbhbyJxx.js +0 -2
  136. package/web/assets/remote-DXG553d8.js +0 -1220
  137. package/web/assets/rigTrack-CW9_kg5j.js +0 -1
  138. package/web/assets/rotoscope-_CYT-9ry.js +0 -1
  139. package/web/assets/shot-worker-BxIzQRZh.js +0 -1
  140. package/web/assets/spellDuel-eZvRwaxi.js +0 -2
  141. package/web/assets/surfacePin-CfLBhSrm.js +0 -2
  142. package/web/assets/timeline3d-DqXTKdEK.js +0 -2
  143. package/web/assets/timeline3dExport-MWomW4fF.js +0 -1
  144. package/web/assets/timelineProps-KL6XCR4Q.js +0 -1
  145. package/web/assets/timelineText-DEK2BRyU.js +0 -1
  146. package/web/assets/titleFrames-WfiLHzjf.js +0 -1
  147. package/web/assets/tools-CBfIZX8_.js +0 -1
  148. package/web/assets/toonTools-D7jucq3t.js +0 -2
  149. package/web/assets/trackAnchor-DFqKIb8a.js +0 -1
  150. package/web/assets/userFonts-txN4I-eo.js +0 -1
  151. package/web/assets/vfxBackground-C1dHlJN6.js +0 -2
  152. package/web/assets/vfxTrack-BmxWjlDi.js +0 -1
  153. package/web/assets/videoExport-DiNI9GY1.js +0 -1
  154. package/web/assets/views-sH39zgjD.js +0 -1
  155. package/web/assets/weaponDuel-CEvRDeuE.js +0 -1
@@ -1,189 +0,0 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/titleFrames-WfiLHzjf.js","assets/titleFrameBudget-BjW--v_T.js","assets/titleArt-CAOxtyHl.js","assets/rigTrack-CW9_kg5j.js","assets/lottieLayer-BhLbZOpr.js","assets/api-C5pOWyBM.js","assets/frameSink-CB1EghW0.js","assets/timeline3dExport-MWomW4fF.js","assets/timeline3d-DqXTKdEK.js","assets/three.module-Bx43vjkH.js","assets/GLTFLoader-Dy6SrZg8.js","assets/RoomEnvironment-Dmv_G5ka.js","assets/rotoMatte-2EcyuvBX.js","assets/store-Dxq3MZF3.js","assets/captionLayout-BAdmqwdS.js"])))=>i.map(i=>d[i]);
2
- import{b$ as wo,U as qt,eQ as Lo,eO as io,cK as Io,au as Co,f7 as Xo,lj as Oo,hR as $t,iM as zo,_ as jt,ii as ro,aq as Go,lk as Qt,aR as qo,aP as ao,hZ as $o,h_ as jo,ll as no,en as Ho,e_ as so,cb as Zt,cd as Vo,fD as Yo,f8 as Ht,f6 as Ko,W as Jt,eG as co,eI as lo,eH as fo,cS as Vt,eK as Wo,dU as uo,lm as Qo,cc as Zo,f0 as Jo,fw as ei,e$ as ti,hT as oi,er as Yt,jV as ii,eA as mo,ez as ri,ln as ai,lo as ni,b2 as si,aQ as ci,lp as li,lq as fi,lr as ui,bF as mi,aG as Ro,ls as pi,h as _o,lt as xi,lu as di,ef as vi,eg as hi,ai as bi,lv as gi,eB as Ei,eC as Ti,eD as yi,ex as wi,eE as Ri,lw as _i,fh as Fi,co as Ai,i1 as Mi,lx as Si,hX as Di,eF as po,ly as ki,V as Ui,X as Pi,a0 as xo,lz as vo,Y as ho,an as Bi,lA as Ni,ei as Li,a2 as Ii,a3 as Ci,lB as Xi,a4 as Oi,eh as zi,a5 as Gi,ab as qi,aa as $i,a8 as ji,a6 as _t,eL as Hi,ej as Vi,lC as Yi,lD as Ki}from"./titleFrameBudget-BjW--v_T.js";import{bi as Wi,bg as Qi,bh as Zi,bk as Ji}from"./remote-DXG553d8.js";import{l as ct,f as Pt,p as Bt,s as bo,w as Lt,r as er,a as Nt,t as tr,n as or,g as Fo,b as go,c as Ao,d as ir}from"./gpuCompose-EfzSAeMh.js";import{f as rr,h as Mo,z as ar,L as nr,d as sr,c as cr,l as lr,b as fr}from"./exportEncode-pFxeatJt.js";import{c as ur}from"./distortGL-5uNfls9s.js";import{c as eo,V as mr,a as pr,I as xr,A as dr,U as vr,b as hr}from"./id3-BCR9Bqgo.js";import{S as br,B as gr,O as Er,M as Tr,a as yr,C as wr,A as Rr}from"./output-BwZzMbp-.js";import"./api-C5pOWyBM.js";import"./three.module-Bx43vjkH.js";import"./GLTFLoader-Dy6SrZg8.js";import"./store-Dxq3MZF3.js";import"./rotoMaskStore-DrRawyH9.js";import"./rigTrack-CW9_kg5j.js";const It=48e3,So=192e3,_r=4,Do=(d,y)=>y?.name==="AbortError"||d>=_r?null:Math.min(2**(d-1),4);async function Fr(d,y){for(let w=1;;w++){let e;try{e=await fetch(d,{signal:y})}catch(O){const v=y?.aborted?null:Do(w,O);if(v===null)throw O;await new Promise(B=>setTimeout(B,v*1e3));continue}if(!e.ok)throw Error(`media ${e.status}`);return e.blob()}}const ko=()=>pr("aac",{numberOfChannels:2,sampleRate:It,bitrate:So}).catch(()=>!1),Da=async(d,y)=>await eo("avc",{width:d,height:y}).catch(()=>!1)&&ko(),ka=(d,y)=>eo("hevc",{width:d,height:y}).catch(()=>!1);async function Ua(d,y){try{const{width:w,height:e,fps:O}=wo(d),v=y?.codec==="hevc";return typeof VideoEncoder>"u"||typeof AudioEncoder>"u"||typeof OfflineAudioContext>"u"||!new OffscreenCanvas(2,2).getContext("webgl2")||!(await VideoEncoder.isConfigSupported({codec:v?"hvc1.1.6.L153.B0":"avc1.640034",width:w,height:e,bitrate:Mo(y,{width:w,height:e,fps:O},Fo),framerate:O,hardwareAcceleration:"prefer-hardware"})).supported?!1:await eo(v?"hevc":"avc",{width:w,height:e})&&await ko()}catch{return!1}}class Ar{frames=new Map;async push(y,w,e){let O=this.frames.get(w);O||(O=[],this.frames.set(w,O)),O.push(e)}}async function Eo(d,y,w,e,O,v,B){const D=y.get(w.url);if(!D)return null;if(Ro(w)&&!w._still){const ce=`${w.id}
3
- remap
4
- ${v}`,H=Math.round((e-v)*O);let Y=d.get(ce);if(!Y){const le=D.samplesAtTimestamps(pi(w,v-w.start,Math.max(1,Math.round(B*O)),O))[Symbol.asyncIterator]();Y={iterator:le,peek:null,current:null,ts0:0,idx:0,next:async()=>{const ae=await le.next();return ae.done?null:ae.value}},d.set(ce,Y)}for(;(Y.idx??0)<=H;){const le=await Y.iterator.next();if(Y.idx=(Y.idx??0)+1,le.done)break;le.value&&le.value!==Y.current&&(Y.current?.close(),Y.current=le.value)}return Y.current}const oe=!!(w._still||w.freeze),K=oe?1:w.playbackRate||1,h=!oe&&_o(w),_=h?xi(w,v,B).start:(w.inPoint||0)+(oe?0:(v-w.start)*K),j=`${w.id}
5
- ${oe?"still":v}`;let l=d.get(j);if(!l){const ce=D.samples(Math.max(0,_-.5))[Symbol.asyncIterator]();if(l={iterator:ce,peek:null,current:null,ts0:_,next:async()=>{const H=await ce.next();return H.done?null:H.value}},l.peek=await l.next(),!oe){for(;l.peek&&l.peek.timestamp<_-1e-4;)l.peek.close(),l.peek=await l.next();l.ts0=l.peek?.timestamp??_}if(h){const H=Z=>Number(Z.toFixed(6)),Y=v-w.start,le=di(w,Y,Y+B),ae=le.slice(0,-1).map(([Z,Se],Fe)=>{const[qe,Ee]=le[Fe+1];return{xa:H(Z),dx:H(qe-Z),k:qe-Z>1e-9?H((Ee-Se)/(qe-Z)):0}}).filter(Z=>Z.dx>1e-9);l.out=Z=>ae.reduce((Se,Fe)=>Se+Math.min(Fe.dx,Math.max(0,Z-Fe.xa))*Fe.k,0)}d.set(j,l)}if(oe){const ce=Math.round(_*O);for(;l.peek&&Math.round(l.peek.timestamp*O)<=ce;)l.current?.close(),l.current=l.peek,l.peek=await l.next();return l.current??l.peek}const be=Math.round((e-v)*O),ge=ce=>l.out?l.out(ce-l.ts0):(ce-l.ts0)/K;for(;l.peek&&Math.round(ge(l.peek.timestamp)*O)<=be;)l.current?.close(),l.current=l.peek,l.peek=await l.next();return l.current??l.peek}const Mr=`#version 300 es
6
- in vec2 p;uniform vec4 dst;uniform vec4 src;out vec2 uv;
7
- 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);}`,Sr=`#version 300 es
8
- precision highp float;in vec2 uv;uniform sampler2D tex;uniform float alpha;uniform float fade;uniform float white;
9
- uniform float bright;uniform float contrast;uniform mat3 sat;uniform mat3 rot;uniform float colour;out vec4 o;
10
- uniform sampler2D matte;uniform float useMatte;uniform vec4 mrect;
11
- // chroma key (shared/chromaKey.js, the server's geq on the decoded picture): alpha = clip((d − similarity) / blend), d = |CbCr − key|
12
- // / (255√2) with the picture's own Cb / Cr (8-bit studio range, back from RGB with its matrix: kmat 1 = BT.709, 0 = BT.601) and the
13
- // key's BT.601 Cb / Cr; then despill (mix 0.5) pulls the green / blue cast back by spill
14
- uniform vec4 key;uniform vec4 keyOpt;
15
- // the grade's 1D LUT (shared/timelineGrade.js gradeLut, 256 entries: an 8-bit input lands on an entry) and its 3D table (the colour
16
- // mixer, timelineMixer.js mixerLut; ffmpeg lut3d trilinear), each on 8-bit values like the server's lut1d / lut3d
17
- uniform highp sampler2D lut1;uniform highp sampler3D lut3;uniform float useL1;uniform float useL3;
18
- vec3 tri(vec3 q){int n=textureSize(lut3,0).x;vec3 p=q*float(n-1),f=floor(p),w=p-f;ivec3 i=ivec3(f),j=min(i+1,ivec3(n-1));
19
- vec3 c000=texelFetch(lut3,i,0).rgb,c100=texelFetch(lut3,ivec3(j.x,i.y,i.z),0).rgb,c010=texelFetch(lut3,ivec3(i.x,j.y,i.z),0).rgb,c110=texelFetch(lut3,ivec3(j.x,j.y,i.z),0).rgb;
20
- vec3 c001=texelFetch(lut3,ivec3(i.x,i.y,j.z),0).rgb,c101=texelFetch(lut3,ivec3(j.x,i.y,j.z),0).rgb,c011=texelFetch(lut3,ivec3(i.x,j.y,j.z),0).rgb,c111=texelFetch(lut3,j,0).rgb;
21
- return mix(mix(mix(c000,c100,w.x),mix(c010,c110,w.x),w.y),mix(mix(c001,c101,w.x),mix(c011,c111,w.x),w.y),w.z);}
22
- void main(){vec4 c=texture(tex,uv);vec3 rgb=c.rgb;
23
- if(keyOpt.x>.5){vec3 q=floor(rgb*255.+.5);float k=224./255.;
24
- float u=keyOpt.w>.5?floor((-.114572*q.r-.385428*q.g+.5*q.b)*k+128.5):floor((-.168736*q.r-.331264*q.g+.5*q.b)*k+128.5);
25
- float v=keyOpt.w>.5?floor((.5*q.r-.454153*q.g-.045847*q.b)*k+128.5):floor((.5*q.r-.418688*q.g-.081312*q.b)*k+128.5);
26
- float d=length(vec2(u-key.x,v-key.y))/360.62445840513925,a=key.w>1e-4?clamp((d-key.z)/key.w,0.,1.):step(key.z,d)-step(d,key.z)*0.;
27
- c.a*=floor(a*255.)/255.;
28
- if(keyOpt.z>0.){if(keyOpt.y>.5){float m=max(0.,rgb.b-(rgb.r*.5+rgb.g*.5));rgb.b=max(0.,rgb.b-m*keyOpt.z);}else{float m=max(0.,rgb.g-(rgb.r*.5+rgb.b*.5));rgb.g=max(0.,rgb.g-m*keyOpt.z);}}}
29
- if(useMatte>.5)c.a*=texture(matte,(uv-mrect.xy)/mrect.zw).r;
30
- if(colour>.5){rgb=clamp(rgb*bright,0.,1.);rgb=clamp((rgb-.5)*contrast+.5,0.,1.);rgb=clamp(sat*rgb,0.,1.);rgb=clamp(rot*rgb,0.,1.);}
31
- if(useL1>.5){ivec3 k=ivec3(floor(rgb*255.+.5));rgb=floor(vec3(texelFetch(lut1,ivec2(k.r,0),0).r,texelFetch(lut1,ivec2(k.g,0),0).g,texelFetch(lut1,ivec2(k.b,0),0).b)*255.+.5)/255.;}
32
- if(useL3>.5)rgb=floor(clamp(tri(floor(rgb*255.+.5)/255.),0.,1.)*255.+.5)/255.;
33
- rgb=white>.5?1.-(1.-rgb)*fade:rgb*fade;o=vec4(rgb,c.a*alpha);}`,G=`#version 300 es
34
- in vec2 p;out vec2 uv;void main(){uv=p;gl_Position=vec4(p*2.-1.,0,1);}`,Dr=`#version 300 es
35
- precision highp float;in vec2 uv;uniform sampler2D tex;uniform vec2 step;uniform float sigma;out vec4 o;
36
- void main(){int r=int(ceil(sigma*3.));vec4 acc=vec4(0);float wsum=0.;
37
- for(int i=-128;i<=128;i++){if(i<-r||i>r)continue;float w=exp(-float(i*i)/(2.*sigma*sigma));acc+=texture(tex,uv+step*float(i))*w;wsum+=w;}
38
- o=acc/wsum;}`,kr=`#version 300 es
39
- precision highp float;in vec2 uv;uniform sampler2D tex;uniform float lo;uniform float k;out vec4 o;
40
- void main(){vec4 c=texture(tex,uv);o=vec4(clamp(lo+c.rgb*k,0.,1.),c.a);}`,Ur=`#version 300 es
41
- precision highp float;in vec2 uv;uniform sampler2D a;uniform sampler2D b;uniform float amount;out vec4 o;
42
- void main(){vec4 x=texture(a,uv),y=texture(b,uv);o=mix(x,1.-(1.-x)*(1.-y),amount);}`,Pr=`#version 300 es
43
- precision highp float;in vec2 uv;uniform sampler2D tex;uniform vec2 step;uniform float b;uniform int reach;out vec4 o;
44
- void main(){vec4 acc=texture(tex,uv);float ws=1.;float w=1.;
45
- 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;}
46
- o=acc/ws;}`,Br=`#version 300 es
47
- precision highp float;in vec2 uv;uniform sampler2D tex;uniform float taps[16];uniform int n;uniform vec2 ctr;out vec4 o;
48
- 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);}`,Nr=`#version 300 es
49
- 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;
50
- void main(){vec4 acc=vec4(0);for(int i=0;i<8;i++){if(i>=n)break;acc+=texture(tex,vec2(.5)+(uv-vec2(.5))/vec2(sx[i],sy[i]));}
51
- acc/=float(n);o=vec4(min(acc.rgb*gain,1.),acc.a);}`,Lr=`#version 300 es
52
- precision highp float;in vec2 uv;uniform sampler2D tex;uniform float gain;out vec4 o;
53
- void main(){vec4 c=texture(tex,uv);o=vec4(min(c.rgb*gain,1.),c.a);}`,Ir=`#version 300 es
54
- precision highp float;in vec2 uv;uniform sampler2D a;uniform sampler2D b;uniform float w;out vec4 o;
55
- void main(){o=mix(texture(a,uv),texture(b,uv),w);}`,Cr=`#version 300 es
56
- precision highp float;in vec2 uv;uniform sampler2D tex;uniform vec4 colour;uniform float usetex;out vec4 o;
57
- void main(){o=usetex>.5?texture(tex,vec2(uv.x,1.-uv.y)):colour;}`,Xr=`#version 300 es
58
- precision highp float;uniform sampler2D tex;uniform mat3 inv;uniform vec2 size;uniform vec4 rnd;uniform float keepPre;out vec4 o;
59
- // a pinned screen's rounded corners (shared/cornerPin.js pinRoundGraph): the server's geq mask on the stretched plane BEFORE its
60
- // 2 px inset, at pixel centres, kept at least rnd.z (the portal dive's fade to square corners); rnd.w = on
61
- float corner(ivec2 i){if(rnd.w<.5)return 1.;vec2 k=size/(size-4.),X=(vec2(i)+.5-2.)*k;
62
- float dx=max(0.,max(rnd.x-X.x,X.x-(size.x-rnd.x))),dy=max(0.,max(rnd.y-X.y,X.y-(size.y-rnd.y)));
63
- float m=clamp((1.-sqrt(pow(dx/rnd.x,2.)+pow(dy/rnd.y,2.)))*min(rnd.x,rnd.y)+.5,0.,1.);return max(floor(m*255.)/255.,rnd.z);}
64
- vec4 px(ivec2 i){ivec2 s=ivec2(size);i=clamp(i,ivec2(0),s-1);vec4 c=texelFetch(tex,ivec2(i.x,s.y-1-i.y),0);float a=c.a*corner(i);return vec4(c.rgb*a,a);}
65
- void main(){vec2 d=vec2(gl_FragCoord.x-.5,size.y-gl_FragCoord.y-.5);vec3 q=inv*vec3(d,1.);vec2 u=floor(q.xy/q.z*256.+.5)/256.;
66
- vec2 f=floor(u),w=u-f;ivec2 i=ivec2(f);
67
- vec4 c=mix(mix(px(i),px(i+ivec2(1,0)),w.x),mix(px(i+ivec2(0,1)),px(i+ivec2(1,1)),w.x),w.y);
68
- o=keepPre>.5?c:c.a>0.?vec4(c.rgb/c.a,c.a):vec4(0);}`,Or=`#version 300 es
69
- precision highp float;in vec2 uv;uniform sampler2D tex;uniform vec2 size;uniform int kind;uniform float e;uniform float f;uniform float inv;
70
- uniform vec2 ctr;uniform vec3 csh;uniform float count;out vec4 o;
71
- void main(){vec4 c=texture(tex,uv);float X=gl_FragCoord.x-.5,Y=size.y-gl_FragCoord.y-.5,W=size.x,H=size.y,r;
72
- float cx=ctr.x*W,cy=ctr.y*H,dx=X-cx,dy=Y-cy,R=length(vec2(max(cx,W-cx),max(cy,H-cy)));
73
- if(kind<=2){float lin=(X/W-.5)*csh.x+(Y/H-.5)*csh.y,h=csh.z;if(kind==2)r=abs(lin)/h;else{float u=(lin+h)/(2.*h);r=kind==1?mod(u*count,1.):u;}}
74
- else if(kind==3)r=length(vec2(dx,dy))/R;
75
- else if(kind==4)r=(abs(dx)/max(cx,W-cx)+abs(dy)/max(cy,H-cy))/2.;
76
- else if(kind==5){float u=X/W,v=Y/H,A=W/H;r=.1+.78*length(vec2(dx,dy))/R+.12*((sin(u*A*5.3+1.7)*sin(v*4.9+.4)+.55*sin(u*A*11.3-v*9.7+2.3)+.3*sin(u*A*19.1+v*17.3+.7))/1.85);}
77
- else{float a=atan(dx,-dy);if(a<0.)a+=6.283185307179586;r=a/6.283185307179586;}
78
- float m=clamp((e-r)/f,0.,1.);if(inv>.5)m=1.-m;m=floor(m*255.+.5)/255.;o=vec4(c.rgb,c.a*m);}`,zr=`#version 300 es
79
- precision highp float;in vec2 uv;uniform sampler2D tex;uniform highp sampler2D lut;uniform float m[12];uniform float useM;uniform float useL;out vec4 o;
80
- void main(){vec4 c=texture(tex,uv),v=floor(c*255.+.5);vec3 q=v.rgb;
81
- if(useM>.5){vec3 r;for(int i=0;i<3;i++)r[i]=floor(v.r*m[i*4]+.5)+floor(v.g*m[i*4+1]+.5)+floor(v.b*m[i*4+2]+.5)+floor(v.a*m[i*4+3]+.5);q=clamp(r,0.,255.);}
82
- if(useL>.5)q=vec3(texelFetch(lut,ivec2(int(q.r),0),0).r,texelFetch(lut,ivec2(int(q.g),1),0).r,texelFetch(lut,ivec2(int(q.b),2),0).r)*255.;
83
- o=vec4(q/255.,c.a);}`,Gr=`#version 300 es
84
- precision highp float;uniform sampler2D tex;uniform int px;out vec4 o;
85
- void main(){ivec2 p=ivec2(gl_FragCoord.xy);int W=textureSize(tex,0).x;vec4 c=texelFetch(tex,p,0);
86
- o=vec4(texelFetch(tex,ivec2(clamp(p.x+px,0,W-1),p.y),0).r,c.g,texelFetch(tex,ivec2(clamp(p.x-px,0,W-1),p.y),0).b,c.a);}`,qr=`#version 300 es
87
- precision highp float;uniform sampler2D tex;uniform int b;uniform ivec2 small;out vec4 o;
88
- void main(){ivec2 s=textureSize(tex,0),k=ivec2(gl_FragCoord.xy);k.y=small.y-1-k.y;vec4 sum=vec4(0);float n=0.;
89
- for(int j=0;j<64;j++){if(j>=b)break;int y=k.y*b+j;if(y>=s.y)break;for(int i=0;i<64;i++){if(i>=b)break;int x=k.x*b+i;if(x>=s.x)break;sum+=texelFetch(tex,ivec2(x,s.y-1-y),0);n+=1.;}}
90
- o=sum/n;}`,$r=`#version 300 es
91
- precision highp float;uniform sampler2D small;uniform int b;uniform vec2 size;out vec4 o;
92
- void main(){ivec2 p=ivec2(gl_FragCoord.xy),ss=textureSize(small,0);int y=int(size.y)-1-p.y;o=texelFetch(small,ivec2(p.x/b,ss.y-1-y/b),0);}`,jr=`#version 300 es
93
- precision highp float;in vec2 uv;uniform sampler2D tex;uniform vec2 off;uniform vec3 col;uniform float op;uniform float times;uniform vec2 dil;out vec4 o;
94
- void main(){vec2 p=uv-off;float v=0.;if(p.x>=0.&&p.x<=1.&&p.y>=0.&&p.y<=1.)v=floor(texture(tex,p).a*255.+.5);
95
- float a=dil.y>0.?clamp(floor((v-dil.x)*dil.y),0.,255.):times<1.5?floor(v*op):floor(255.*(1.-pow(1.-v/255.*op,times)));
96
- o=vec4(col,a/255.);}`,Hr=`#version 300 es
97
- precision highp float;uniform sampler2D tex;uniform float harden;out vec4 o;
98
- void main(){float a=floor(texelFetch(tex,ivec2(gl_FragCoord.xy),0).a*255.+.5);if(harden>0.)a=clamp((a-128.)*harden+128.,0.,255.);o=vec4(a/255.,0,0,1);}`,Vr=`#version 300 es
99
- precision highp float;uniform sampler2D tex;uniform ivec2 dir;uniform float sigma;out vec4 o;
100
- void main(){ivec2 p=ivec2(gl_FragCoord.xy),n=textureSize(tex,0);int r=int(ceil(sigma*3.));float acc=0.,ws=0.;
101
- for(int i=-128;i<=128;i++){if(i<-r||i>r)continue;float w=exp(-float(i*i)/(2.*sigma*sigma));ivec2 q=p+dir*i;
102
- if(q.x>=0&&q.y>=0&&q.x<n.x&&q.y<n.y)acc+=texelFetch(tex,q,0).r*w;ws+=w;}
103
- o=vec4(floor(acc/ws*255.+.5)/255.,0,0,1);}`,Yr=`#version 300 es
104
- precision highp float;uniform sampler2D a;uniform sampler2D b;out vec4 o;
105
- void main(){ivec2 p=ivec2(gl_FragCoord.xy);float x=floor(texelFetch(a,p,0).r*255.+.5),y=floor(texelFetch(b,p,0).r*255.+.5);
106
- o=vec4(floor(x*clamp(2.*(1.-y/max(x,1.)),0.,1.))/255.,0,0,1);}`,Kr=`#version 300 es
107
- precision highp float;uniform sampler2D pic;uniform sampler2D band;uniform sampler2D glow;uniform vec3 col;uniform float k;uniform float am;out vec4 o;
108
- void main(){ivec2 p=ivec2(gl_FragCoord.xy);float b=floor(texelFetch(band,p,0).r*255.+.5),g=floor(texelFetch(glow,p,0).r*255.+.5);
109
- float rim=clamp(floor(b+g*k),0.,255.);if(am<255.)rim=floor(rim*am/255.);
110
- vec4 P=texelFetch(pic,p,0);float ra=rim/255.,oa=ra+P.a*(1.-ra);
111
- o=vec4(oa>0.?(col*ra+P.rgb*P.a*(1.-ra))/oa:P.rgb,oa);}`,Wr=`#version 300 es
112
- precision highp float;in vec2 uv;uniform sampler2D tex;out vec4 o;void main(){vec4 c=texture(tex,uv);o=vec4(c.rgb*c.a,c.a)*.25;}`,Qr=`#version 300 es
113
- precision highp float;in vec2 uv;uniform sampler2D tex;out vec4 o;void main(){vec4 c=texture(tex,uv);o=c.a>0.?vec4(min(c.rgb/c.a,1.),c.a):vec4(0);}`,Zr=`#version 300 es
114
- precision highp float;uniform sampler2D tex;uniform vec2 big;uniform vec2 small;uniform vec4 q1;uniform vec4 q2;uniform float useQ;
115
- uniform vec4 w1;uniform vec4 w2;uniform float useW;uniform float inv;out vec4 o;
116
- float rp(float v,float lo,float hi,float ss){return clamp((v-lo)/ss+1.,0.,1.)*clamp((hi-v)/ss+1.,0.,1.);}
117
- void main(){vec2 X=floor(gl_FragCoord.xy),c=(X+.5)*big/small;vec3 a=vec3(0);
118
- for(int j=0;j<2;j++)for(int i=0;i<2;i++)a+=texture(tex,(c+vec2(float(i)*2.-1.,float(j)*2.-1.))/big).rgb;
119
- vec3 p=floor(a/4.*255.+.5)/255.;float m=1.;
120
- if(useQ>.5){float h=atan(sqrt(3.)*(p.g-p.b),2.*p.r-p.g-p.b)*180./3.14159265358979;if(h<0.)h+=360.;
121
- float d=abs(h-q1.x);if(d>180.)d=360.-d;float mh=q1.y>=360.?1.:clamp((q1.y/2.+q1.z-d)/q1.z,0.,1.);
122
- float ch=max(max(p.r,p.g),p.b)-min(min(p.r,p.g),p.b),l=.2126*p.r+.7152*p.g+.0722*p.b;
123
- m*=mh*rp(ch,q2.x,q2.y,q1.w)*rp(l,q2.z,q2.w,q1.w);}
124
- if(useW>.5){float dx=X.x/small.x-w1.x,dy=X.y/small.y-w1.y,x=dx*w2.x-dy*w2.y,y=dx*w2.y+dy*w2.x;
125
- if(w2.w>1.5)m*=clamp(.5-y/w1.w,0.,1.);
126
- else{float nx=abs(x)/w1.z,ny=abs(y)/w2.z,dist=w2.w>.5?max(nx,ny):length(vec2(nx,ny));m*=clamp((1.+w1.w/2.-dist)/w1.w,0.,1.);}}
127
- if(inv>.5)m=1.-m;o=vec4(floor(255.*m+1e-4)/255.,0,0,1);}`,Jr=`#version 300 es
128
- precision highp float;uniform sampler2D tex;uniform highp sampler2D lut;uniform highp sampler3D t3;uniform float useT;uniform float useL;
129
- uniform float useS;uniform mat3 sat;uniform float useR;uniform mat3 rot;out vec4 o;
130
- vec3 tri(vec3 q){int n=textureSize(t3,0).x;vec3 p=q*float(n-1),f=floor(p),w=p-f;ivec3 i=ivec3(f),j=min(i+1,ivec3(n-1));
131
- vec3 c000=texelFetch(t3,i,0).rgb,c100=texelFetch(t3,ivec3(j.x,i.y,i.z),0).rgb,c010=texelFetch(t3,ivec3(i.x,j.y,i.z),0).rgb,c110=texelFetch(t3,ivec3(j.x,j.y,i.z),0).rgb;
132
- vec3 c001=texelFetch(t3,ivec3(i.x,i.y,j.z),0).rgb,c101=texelFetch(t3,ivec3(j.x,i.y,j.z),0).rgb,c011=texelFetch(t3,ivec3(i.x,j.y,j.z),0).rgb,c111=texelFetch(t3,j,0).rgb;
133
- return mix(mix(mix(c000,c100,w.x),mix(c010,c110,w.x),w.y),mix(mix(c001,c101,w.x),mix(c011,c111,w.x),w.y),w.z);}
134
- void main(){ivec2 P=ivec2(gl_FragCoord.xy);vec4 c=texelFetch(tex,P,0);vec3 g=floor(c.rgb*255.+.5);
135
- if(useT>.5)g=floor(clamp(tri(g/255.),0.,1.)*255.+.5);
136
- if(useL>.5){ivec3 k=ivec3(g);g=floor(vec3(texelFetch(lut,ivec2(k.r,0),0).r,texelFetch(lut,ivec2(k.g,0),0).g,texelFetch(lut,ivec2(k.b,0),0).b)*255.+.5);}
137
- if(useS>.5)g=floor(clamp(sat*(g/255.),0.,1.)*255.+.5);
138
- if(useR>.5)g=floor(clamp(rot*(g/255.),0.,1.)*255.+.5);
139
- o=vec4(g/255.,c.a);}`,ea=`#version 300 es
140
- precision highp float;uniform sampler2D base;uniform sampler2D over;uniform sampler2D mask;uniform vec2 msz;uniform float full;out vec4 o;
141
- void main(){ivec2 P=ivec2(gl_FragCoord.xy);vec4 b=texelFetch(base,P,0),g=texelFetch(over,P,0);if(full>.5){o=g;return;}
142
- vec3 q=floor(b.rgb*255.+.5),G=floor(g.rgb*255.+.5);float m=floor(texture(mask,gl_FragCoord.xy/msz).r*255.+.5);
143
- o=vec4((q+floor((m*(G-q)+128.)/256.))/255.,b.a);}`,ta=`#version 300 es
144
- precision highp float;uniform sampler2D tex;uniform float k[9];uniform float rdiv;out vec4 o;
145
- void main(){ivec2 P=ivec2(gl_FragCoord.xy),S=textureSize(tex,0);vec3 s=vec3(0);
146
- for(int j=0;j<3;j++)for(int i=0;i<3;i++){int x=abs(P.x+i-1),y=abs(P.y+j-1);x=x>=S.x?2*S.x-1-x:x;y=y>=S.y?2*S.y-1-y:y;s+=floor(texelFetch(tex,ivec2(x,y),0).rgb*255.+.5)*k[j*3+i];}
147
- vec4 c=texelFetch(tex,P,0);o=vec4(clamp(floor(s*rdiv+.5),0.,255.)/255.,c.a);}`,oa=`#version 300 es
148
- precision highp float;uniform sampler2D tex;uniform sampler2D grain;out vec4 o;
149
- void main(){ivec2 P=ivec2(gl_FragCoord.xy);vec4 c=texelFetch(tex,P,0);float n=floor(texelFetch(grain,P,0).r*255.+.5)-128.;o=vec4(clamp(floor(c.rgb*255.+.5)+n,0.,255.)/255.,c.a);}`,ia=`#version 300 es
150
- precision highp float;uniform sampler2D res;uniform sampler2D outp;uniform sampler2D inp;out vec4 o;
151
- void main(){ivec2 P=ivec2(gl_FragCoord.xy);vec4 r=texelFetch(res,P,0);vec3 R=floor(r.rgb*255.+.5),O=floor(texelFetch(outp,P,0).rgb*255.+.5),I=floor(texelFetch(inp,P,0).rgb*255.+.5);
152
- vec3 d=clamp(O-I+128.,0.,255.);o=vec4(clamp(R+d-128.,0.,255.)/255.,r.a);}`,ra=`#version 300 es
153
- precision highp float;uniform sampler2D tex;uniform sampler2D soft;uniform float t;out vec4 o;
154
- void main(){ivec2 P=ivec2(gl_FragCoord.xy);vec4 c=texelFetch(tex,P,0);vec3 V=floor(c.rgb*255.+.5),B=floor(texelFetch(soft,P,0).rgb*255.+.5);
155
- vec3 x=clamp(V-B+128.,0.,255.)-128.,g=clamp((abs(x)-t)/t,0.,1.),d=clamp(floor(128.+x*g*g*(3.-2.*g)+.5),0.,255.);
156
- o=vec4(clamp(B+d-128.,0.,255.)/255.,c.a);}`,aa=`#version 300 es
157
- precision highp float;in vec2 uv;uniform sampler2D top;uniform sampler2D bg;uniform int mode;out vec4 o;
158
- void main(){vec4 s=texture(top,uv),b=texture(bg,uv);vec3 Bp=floor(b.rgb*255.+.5),S=floor(s.rgb*255.+.5);float a=floor(s.a*255.+.5),ab=b.a;
159
- if(mode==1){o=vec4(min(vec3(255.),Bp+floor(S*a/255.+.5))/255.,min(1.,a/255.+ab));return;}
160
- // the backdrop is premultiplied (a comp's own transparent picture, gpuExport frames mode): blended against its straight colour, and
161
- // where it is transparent the layer shows as itself (W3C / After Effects); an opaque backdrop (ab = 1) is the formula as before
162
- vec3 B=ab>0.?(ab<1.?floor(Bp/ab+.5):Bp):vec3(0),X;
163
- if(mode==2)X=255.-floor((255.-B)*(255.-S)/255.);
164
- else if(mode==3)X=floor(B*S/255.);
165
- else if(mode==4)X=mix(255.-2.*floor((255.-B)*(255.-S)/255.),2.*floor(B*S/255.),step(B,vec3(127.5)));
166
- else if(mode==5)X=max(B,S);else if(mode==6)X=min(B,S);else if(mode==7)X=abs(B-S);else X=B+S-2.*floor(B*S/255.);
167
- X=clamp(X,0.,255.);if(ab<1.)X=mix(S,X,ab);o=vec4(floor((X*a+Bp*(255.-a))/255.+.5)/255.,ab<1.?a/255.+ab*(1.-a/255.):b.a);}`,na=`#version 300 es
168
- precision highp float;uniform sampler2D tex;uniform int ss;out vec4 o;
169
- void main(){ivec2 p=ivec2(gl_FragCoord.xy)*ss;vec4 c=vec4(0);for(int j=0;j<4;j++){if(j>=ss)break;for(int i=0;i<4;i++){if(i>=ss)break;c+=texelFetch(tex,p+ivec2(i,j),0);}}
170
- c/=float(ss*ss);o=c.a>0.?vec4(c.rgb/c.a,c.a):vec4(0);}`,sa=`#version 300 es
171
- precision highp float;uniform sampler2D tex;uniform int px;out vec4 o;
172
- void main(){ivec2 p=ivec2(gl_FragCoord.xy);int W=textureSize(tex,0).x;vec4 c=texelFetch(tex,p,0);int xr=p.x-px,xb=p.x+px;
173
- o=vec4(xr>=0&&xr<W?texelFetch(tex,ivec2(xr,p.y),0).r:0.,c.g,xb>=0&&xb<W?texelFetch(tex,ivec2(xb,p.y),0).b:0.,c.a);}`,ca=`#version 300 es
174
- precision highp float;uniform sampler2D tex;uniform vec2 size;uniform vec2 msize;uniform float v;uniform float fr;out vec4 o;
175
- float sh(float Y){float band=floor(Y*24./size.y),k=mod(band*73.+fr*151.+17.,97.)/97.;return k>1.-v*.6?(k-.5)*2.*v*.15:0.;}
176
- float mx(vec2 s){float X=(s.x+.5)*size.x/msize.x-.5,Y=(s.y+.5)*size.y/msize.y-.5;return floor(clamp(X-size.x*sh(Y),0.,size.x-1.));}
177
- void main(){float X=gl_FragCoord.x-.5,Y=size.y-gl_FragCoord.y-.5;vec2 p=vec2((X+.5)*msize.x/size.x-.5,(Y+.5)*msize.y/size.y-.5),f=floor(p),w=p-f;
178
- vec2 a=clamp(f,vec2(0),msize-1.),b=clamp(f+1.,vec2(0),msize-1.);
179
- float m=mix(mix(mx(a),mx(vec2(b.x,a.y)),w.x),mix(mx(vec2(a.x,b.y)),mx(b),w.x),w.y);
180
- o=texelFetch(tex,ivec2(clamp(int(floor(m+.5)),0,int(size.x)-1),int(size.y)-1-int(Y)),0);}`,la=`#version 300 es
181
- precision highp float;uniform sampler2D tex;uniform vec2 size;uniform float a[8];uniform float sx[8];uniform float sy[8];out vec4 o;
182
- void main(){vec2 p=vec2(gl_FragCoord.x-.5,size.y-gl_FragCoord.y-.5),c=size*.5-.5;vec4 acc=vec4(0);
183
- for(int k=0;k<8;k++){vec2 d=p-c;float cs=cos(a[k]),sn=sin(a[k]);vec2 q=vec2(d.x*cs+d.y*sn,-d.x*sn+d.y*cs);vec2 s=q/vec2(sx[k],sy[k])+c;
184
- vec2 uv=vec2((s.x+.5)/size.x,1.-(s.y+.5)/size.y);acc+=(uv.x<0.||uv.x>1.||uv.y<0.||uv.y>1.)?vec4(0):texture(tex,uv);}
185
- o=acc/8.;}`,fa=`#version 300 es
186
- precision highp float;in vec2 uv;uniform sampler2D tex;uniform float w;out vec4 o;
187
- void main(){vec4 c=texture(tex,uv);o=vec4(mix(c.rgb,1.-c.rgb,w),c.a);}`,ua=`#version 300 es
188
- precision highp float;in vec2 uv;uniform sampler2D tex;out vec4 o;void main(){o=texture(tex,uv);}`,ma=["wipe","blinds","split","iris","diamond","burn"];function To(d,y){const w=Math.max(1e-4,d.feather??.05),e=d.progress?Yt(d.progress,y)??0:y,O=(d.angle??0)*Math.PI/180,v=Math.cos(O),B=Math.sin(O),D=ma.indexOf(d.type??"");return{type:"txMask",kind:D<0?6:D,e:e*(1+2*w)-w,f:w,inv:!!d.invert,cx:d.cx??.5,cy:d.cy??.5,c:v,s:B,h:.5*(Math.abs(v)+Math.abs(B)),count:d.count??8}}function yo(d,y,w,e,O=0,v){if(!d)return[];const B=oe=>Yt(d[oe],y)??0,D=[];if(d.zoomBlur&&D.push({type:"txZoom",taps:Ei(),w:B("zoomBlur"),...v?{c:[v.cx,1-v.cy]}:{}}),d.spinBlur){const oe=Ti(w,e),K=h=>Math.max(2,Math.round(h/2)*2);D.push({type:"txSpin",a:oe.map(h=>+h.a.toFixed(6)),sx:oe.map(h=>K(w*h.scale)/w),sy:oe.map(h=>K(e*h.scale)/e),w:B("spinBlur")})}if(d.dirBlur){const oe=po*w/1280,K=oe/(1+oe);D.push({type:"txDir",b:K,reach:Math.min(512,Math.ceil(Math.log(.001)/Math.log(K))),w:B("dirBlur")})}if(d.dirBlurV){const oe=po*w/1280,K=oe/(1+oe);D.push({type:"txDir",b:K,reach:Math.min(512,Math.ceil(Math.log(.001)/Math.log(K))),w:B("dirBlurV"),v:!0})}return d.blur&&D.push({type:"txGauss",sigma:yi*w/1280,w:B("blur")}),d.glitch&&D.push({type:"txGlitch",v:B("glitch"),fr:Math.floor(O*30+.5)}),d.rgbSplit&&D.push({type:"txRgb",px:Math.trunc(B("rgbSplit")*wi*w/1280+.5)}),d.exposure&&D.push({type:"txExpo",gain:Ri,w:B("exposure")}),d.invert&&D.push({type:"txInv",w:B("invert")}),D}function pa(d,y){const w=new OffscreenCanvas(d,y),e=w.getContext("webgl2",{premultipliedAlpha:!1,preserveDrawingBuffer:!0,antialias:!1});if(!e)throw Error("WebGL2 unavailable");const O=(r,s)=>{const t=e.createShader(r);if(e.shaderSource(t,s),e.compileShader(t),!e.getShaderParameter(t,e.COMPILE_STATUS))throw Error(String(e.getShaderInfoLog(t)));return t},v=(r,s)=>{const t=e.createProgram();if(e.attachShader(t,O(e.VERTEX_SHADER,r)),e.attachShader(t,O(e.FRAGMENT_SHADER,s)),e.bindAttribLocation(t,0,"p"),e.linkProgram(t),!e.getProgramParameter(t,e.LINK_STATUS))throw Error(String(e.getProgramInfoLog(t)));return t},B=v(Mr,Sr),D=v(G,jr),oe=v(G,Hr),K=v(G,Vr),h=v(G,Yr),_=v(G,Kr),j=v(G,Wr),l=v(G,Qr),be=v(G,Zr),ge=v(G,Dr),ce=v(G,kr),H=v(G,Ur),Y=v(G,ua),le=v(G,Nr),ae=v(G,Jr),Z=v(G,ea),Se=v(G,ta),Fe=v(G,oa),qe=v(G,ra),Ee=v(G,ia),lt=v(G,Pr),Qe=v(G,Br),Ze=v(G,Lr),Ae=v(G,Ir),ft=v(G,Cr),$e=v(G,Xr),Je=v(G,Or),je=v(G,zr),Xe=v(G,Gr),Ne=v(G,qr),Le=v(G,$r),et=v(G,aa),ie=v(G,na),ye=v(G,sa),ut=v(G,fa),mt=v(G,ca),He=v(G,la),Ct=e.createBuffer();e.bindBuffer(e.ARRAY_BUFFER,Ct),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 tt=r=>s=>e.getUniformLocation(r,s),T=tt(B);e.pixelStorei(e.UNPACK_PREMULTIPLY_ALPHA_WEBGL,!1);const ve=()=>{const r=e.createTexture();e.bindTexture(e.TEXTURE_2D,r);for(const[s,t]of[[e.TEXTURE_MIN_FILTER,e.LINEAR],[e.TEXTURE_MAG_FILTER,e.LINEAR],[e.TEXTURE_WRAP_S,e.CLAMP_TO_EDGE],[e.TEXTURE_WRAP_T,e.CLAMP_TO_EDGE]])e.texParameteri(e.TEXTURE_2D,s,t);return r},Et=ve(),Tt=ve();let Ve=null;const ot=ve(),yt=e.createTexture(),U={l1:"",l3:""};let Ft=!1,At=!1,De=null;const pt={add:1,screen:2,multiply:3,overlay:4,lighten:5,darken:6,difference:7,exclusion:8};let we=0;const it=ve();let ke=[],Oe=!1,rt=null;const Xt=r=>{const s=ze(),t=(r+1)%3,c=(r+2)%3;for(const E of ke){let L=r;e.disable(e.BLEND),E.sigma>.05&&(S(ge,s[t].fb,[s[r].tex],R=>{e.uniform1i(R("tex"),0),e.uniform2f(R("step"),1/d,0),e.uniform1f(R("sigma"),E.sigma)}),S(ge,s[c].fb,[s[t].tex],R=>{e.uniform1i(R("tex"),0),e.uniform2f(R("step"),0,1/y),e.uniform1f(R("sigma"),E.sigma)}),L=c),I(null),e.enable(e.BLEND),e.blendFuncSeparate(e.SRC_ALPHA,e.ONE_MINUS_SRC_ALPHA,e.ONE,e.ONE_MINUS_SRC_ALPHA);const[o,f,u]=[1,3,5].map(R=>parseInt(E.color.slice(R,R+2),16)/255);S(D,null,[s[L].tex],R=>{e.uniform1i(R("tex"),0),e.uniform2f(R("off"),Math.trunc(E.dx)/d,-Math.trunc(E.dy)/y),e.uniform3f(R("col"),o,f,u),e.uniform1f(R("op"),E.opacity),e.uniform1f(R("times"),E.times),e.uniform2f(R("dil"),E.dilate?+(Yi*255).toFixed(3):0,E.dilate?+(1/Ki).toFixed(3):0)})}},wt=r=>{const s=ze();if(Oe){I(rt.fb),e.enable(e.BLEND),e.blendFunc(e.ONE,e.ONE),S(j,rt.fb,[s[r].tex],t=>e.uniform1i(t("tex"),0)),e.blendFuncSeparate(e.SRC_ALPHA,e.ONE_MINUS_SRC_ALPHA,e.ONE,e.ONE_MINUS_SRC_ALPHA);return}if(ke.length&&Xt(r),we){Kt(s[r].tex);return}I(null),e.enable(e.BLEND),e.blendFuncSeparate(e.SRC_ALPHA,e.ONE_MINUS_SRC_ALPHA,e.ONE,e.ONE_MINUS_SRC_ALPHA),S(Y,null,[s[r].tex],t=>e.uniform1i(t("tex"),0))},Kt=r=>{I(null),e.bindTexture(e.TEXTURE_2D,it),e.copyTexImage2D(e.TEXTURE_2D,0,e.RGBA8,0,0,d,y,0),e.disable(e.BLEND),S(et,null,[r,it],s=>{e.uniform1i(s("top"),0),e.uniform1i(s("bg"),1),e.uniform1i(s("mode"),we)})};let Ue=null;const ze=()=>Ue??=[p(),p(),p()],Ot=new Map,zt=r=>{let s=Ot.get(r);if(s)return s;const t=()=>{const c=ve();e.texImage2D(e.TEXTURE_2D,0,e.RGBA8,d*r,y*r,0,e.RGBA,e.UNSIGNED_BYTE,null);const E=e.createFramebuffer();return e.bindFramebuffer(e.FRAMEBUFFER,E),e.framebufferTexture2D(e.FRAMEBUFFER,e.COLOR_ATTACHMENT0,e.TEXTURE_2D,c,0),{tex:c,fb:E}};return s={plane:t(),out:t()},Ot.set(r,s),s},n=new Map,x=new Map,C=r=>{let s=n.get(r.key);if(s)return s;s=ve();const t=new Uint8Array(256*3);(r.lut??[]).forEach((c,E)=>t.set(c,E*256)),e.pixelStorei(e.UNPACK_ALIGNMENT,1),e.texImage2D(e.TEXTURE_2D,0,e.R8,256,3,0,e.RED,e.UNSIGNED_BYTE,t),e.pixelStorei(e.UNPACK_ALIGNMENT,4);for(const c of[e.TEXTURE_MIN_FILTER,e.TEXTURE_MAG_FILTER])e.texParameteri(e.TEXTURE_2D,c,e.NEAREST);return n.set(r.key,s),s},m=(r,s)=>{const t=`${r}x${s}`;let c=x.get(t);if(c)return c;const E=ve();e.texImage2D(e.TEXTURE_2D,0,e.RGBA8,r,s,0,e.RGBA,e.UNSIGNED_BYTE,null);for(const o of[e.TEXTURE_MIN_FILTER,e.TEXTURE_MAG_FILTER])e.texParameteri(e.TEXTURE_2D,o,e.NEAREST);const L=e.createFramebuffer();return e.bindFramebuffer(e.FRAMEBUFFER,L),e.framebufferTexture2D(e.FRAMEBUFFER,e.COLOR_ATTACHMENT0,e.TEXTURE_2D,E,0),c={tex:E,fb:L},x.set(t,c),c},V=new Map,k=(r,s)=>{const t=`${r}x${s}`;let c=V.get(t);return c||(c=[0,1].map(()=>{const E=ve();e.texImage2D(e.TEXTURE_2D,0,e.RGBA8,r,s,0,e.RGBA,e.UNSIGNED_BYTE,null);const L=e.createFramebuffer();return e.bindFramebuffer(e.FRAMEBUFFER,L),e.framebufferTexture2D(e.FRAMEBUFFER,e.COLOR_ATTACHMENT0,e.TEXTURE_2D,E,0),{tex:E,fb:L}}),V.set(t,c),c)},p=()=>{const r=ve();e.texImage2D(e.TEXTURE_2D,0,e.RGBA8,d,y,0,e.RGBA,e.UNSIGNED_BYTE,null);const s=e.createFramebuffer();return e.bindFramebuffer(e.FRAMEBUFFER,s),e.framebufferTexture2D(e.FRAMEBUFFER,e.COLOR_ATTACHMENT0,e.TEXTURE_2D,r,0),{tex:r,fb:s}},I=r=>{e.bindFramebuffer(e.FRAMEBUFFER,r),e.viewport(0,0,d,y)},S=(r,s,t,c)=>re(r,s,d,y,t,c),re=(r,s,t,c,E,L)=>{e.bindFramebuffer(e.FRAMEBUFFER,s),e.viewport(0,0,t,c),e.useProgram(r);const o=tt(r);E.forEach((f,u)=>{e.activeTexture(e.TEXTURE0+u),e.bindTexture(e.TEXTURE_2D,f)}),L(o),e.drawArrays(e.TRIANGLE_STRIP,0,4),E.length>1&&me(),e.activeTexture(e.TEXTURE0)},me=()=>{e.activeTexture(e.TEXTURE1),e.bindTexture(e.TEXTURE_2D,Tt),e.activeTexture(e.TEXTURE2),e.bindTexture(e.TEXTURE_2D,ot),e.activeTexture(e.TEXTURE3),e.bindTexture(e.TEXTURE_3D,yt),e.activeTexture(e.TEXTURE0)},q=(r,s=0)=>{const t=ze();let c=s;const E=(o,f,u,R)=>{S(ge,t[f].fb,[t[o].tex],a=>{e.uniform1i(a("tex"),0),e.uniform2f(a("step"),1/d,0),e.uniform1f(a("sigma"),R)}),S(ge,t[u].fb,[t[f].tex],a=>{e.uniform1i(a("tex"),0),e.uniform2f(a("step"),0,1/y),e.uniform1f(a("sigma"),R)})},L=(o,f,u,R)=>S(Ae,t[u].fb,[t[o].tex,t[f].tex],a=>{e.uniform1i(a("a"),0),e.uniform1i(a("b"),1),e.uniform1f(a("w"),R)});for(const o of r){const[f,u,R]=[c,(c+1)%3,(c+2)%3];if(o.type==="blur"){o.sigma>.05&&(E(f,u,R,o.sigma),c=R);continue}if(o.type==="colour"){const a=C(o);S(je,t[u].fb,[t[f].tex,a],g=>{e.uniform1i(g("tex"),0),e.uniform1i(g("lut"),1),e.uniform1f(g("useM"),o.m?1:0),e.uniform1f(g("useL"),o.lut?1:0),o.m&&e.uniform1fv(g("m"),o.m.flatMap(M=>[M[0],M[1],M[2],M[3]??0]))}),c=u;continue}if(o.type==="txRgb"){o.px>0&&(S(ye,t[u].fb,[t[f].tex],a=>{e.uniform1i(a("tex"),0),e.uniform1i(a("px"),o.px)}),c=u);continue}if(o.type==="txGlitch"){o.v>1e-4&&(S(mt,t[u].fb,[t[f].tex],a=>{e.uniform1i(a("tex"),0),e.uniform2f(a("size"),d,y),e.uniform2f(a("msize"),Math.max(2,Math.round(d/4)),Math.max(2,Math.round(y/4))),e.uniform1f(a("v"),o.v),e.uniform1f(a("fr"),o.fr)}),c=u);continue}if(o.type==="txInv"){o.w>1e-4&&(S(ut,t[u].fb,[t[f].tex],a=>{e.uniform1i(a("tex"),0),e.uniform1f(a("w"),Math.min(1,o.w))}),c=u);continue}if(o.type==="shift"){S(Xe,t[u].fb,[t[f].tex],a=>{e.uniform1i(a("tex"),0),e.uniform1i(a("px"),o.px)}),c=u;continue}if(o.type==="pixel"){const a=Math.ceil(d/o.block),g=Math.ceil(y/o.block),M=m(a,g);e.bindFramebuffer(e.FRAMEBUFFER,M.fb),e.viewport(0,0,a,g),e.useProgram(Ne),e.activeTexture(e.TEXTURE0),e.bindTexture(e.TEXTURE_2D,t[f].tex),e.uniform1i(e.getUniformLocation(Ne,"tex"),0),e.uniform1i(e.getUniformLocation(Ne,"b"),o.block),e.uniform2i(e.getUniformLocation(Ne,"small"),a,g),e.drawArrays(e.TRIANGLE_STRIP,0,4),S(Le,t[u].fb,[M.tex],ee=>{e.uniform1i(ee("small"),0),e.uniform1i(ee("b"),o.block),e.uniform2f(ee("size"),d,y)}),c=u;continue}if(o.type==="txMask"){S(Je,t[u].fb,[t[f].tex],a=>{e.uniform1i(a("tex"),0),e.uniform2f(a("size"),d,y),e.uniform1i(a("kind"),o.kind),e.uniform1f(a("e"),o.e),e.uniform1f(a("f"),o.f),e.uniform1f(a("inv"),o.inv?1:0),e.uniform2f(a("ctr"),o.cx,o.cy),e.uniform3f(a("csh"),o.c,o.s,o.h),e.uniform1f(a("count"),o.count)}),c=u;continue}if(o.type==="txGauss"||o.type==="txDir"||o.type==="txZoom"||o.type==="txSpin"||o.type==="txExpo"){if(!(o.w>1e-4))continue;let a=u;o.type==="txGauss"?(E(f,u,R,o.sigma),a=R):o.type==="txDir"?S(lt,t[u].fb,[t[f].tex],M=>{e.uniform1i(M("tex"),0),o.v?e.uniform2f(M("step"),0,1/y):e.uniform2f(M("step"),1/d,0),e.uniform1f(M("b"),o.b),e.uniform1i(M("reach"),o.reach)}):o.type==="txZoom"?S(Qe,t[u].fb,[t[f].tex],M=>{e.uniform1i(M("tex"),0),e.uniform1fv(M("taps"),o.taps),e.uniform1i(M("n"),o.taps.length),e.uniform2f(M("ctr"),o.c?.[0]??.5,o.c?.[1]??.5)}):o.type==="txSpin"?S(He,t[u].fb,[t[f].tex],M=>{e.uniform1i(M("tex"),0),e.uniform2f(M("size"),d,y),e.uniform1fv(M("a"),o.a),e.uniform1fv(M("sx"),o.sx),e.uniform1fv(M("sy"),o.sy)}):S(Ze,t[u].fb,[t[f].tex],M=>{e.uniform1i(M("tex"),0),e.uniform1f(M("gain"),o.gain)});const g=a===R?u:R;L(f,a,g,Math.min(1,o.w)),c=g;continue}if(o.type==="burst"){const{w:a,h:g}=cr(d,y),[M,ee]=k(a,g),W=ar(nr.burst*o.amount).map(Q=>sr(a,g,Q));S(ce,t[u].fb,[t[f].tex],Q=>{e.uniform1i(Q("tex"),0),e.uniform1f(Q("lo"),o.lo),e.uniform1f(Q("k"),o.k)}),re(Y,M.fb,a,g,[t[u].tex],Q=>e.uniform1i(Q("tex"),0)),re(le,ee.fb,a,g,[M.tex],Q=>{e.uniform1i(Q("tex"),0),e.uniform1i(Q("n"),W.length),e.uniform1fv(Q("sx"),W.map(_e=>_e.sw/a)),e.uniform1fv(Q("sy"),W.map(_e=>_e.sh/g)),e.uniform3f(Q("gain"),...fr(o.amount))}),S(H,t[R].fb,[t[f].tex,ee.tex],Q=>{e.uniform1i(Q("a"),0),e.uniform1i(Q("b"),1),e.uniform1f(Q("amount"),+o.amount.toFixed(4))}),c=R;continue}S(ce,t[u].fb,[t[f].tex],a=>{e.uniform1i(a("tex"),0),e.uniform1f(a("lo"),o.lo),e.uniform1f(a("k"),o.k)}),E(u,R,u,o.sigma),S(H,t[R].fb,[t[f].tex,t[u].tex],a=>{e.uniform1i(a("a"),0),e.uniform1i(a("b"),1),e.uniform1f(a("amount"),o.amount)}),c=R}return c};let i=null,X="",pe=[],Ye="";const Te=(r,s)=>{if(Ye!==`${r}x${s}`){for(const t of pe)e.deleteTexture(t.tex),e.deleteFramebuffer(t.fb);pe=Array.from({length:4},()=>{const t=ve();e.texImage2D(e.TEXTURE_2D,0,e.RGBA8,r,s,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,t,0),{tex:t,fb:c}}),Ye=`${r}x${s}`}return pe},Ke=(r,s,t,c)=>{const E=e.getParameter(e.FRAMEBUFFER_BINDING),L=e.getParameter(e.VIEWPORT),o=e.isEnabled(e.BLEND),f=Te(c.ew,c.eh),u=(a,g,M,ee)=>{e.bindFramebuffer(e.FRAMEBUFFER,f[g].fb),e.viewport(0,0,c.ew,c.eh),e.useProgram(a);const W=tt(a);M.forEach((Q,_e)=>{e.activeTexture(e.TEXTURE0+_e),e.bindTexture(e.TEXTURE_2D,f[Q].tex)}),ee(W),e.drawArrays(e.TRIANGLE_STRIP,0,4),M.length>1&&me(),e.activeTexture(e.TEXTURE0)};e.disable(e.BLEND),e.bindFramebuffer(e.FRAMEBUFFER,f[0].fb),e.viewport(0,0,c.ew,c.eh),e.clearColor(0,0,0,0),e.clear(e.COLOR_BUFFER_BIT);{const a=xe(r,t);e.bindFramebuffer(e.FRAMEBUFFER,f[0].fb),e.viewport(0,0,c.ew,c.eh),e.disable(e.BLEND),Ie(r,[0,0,1,1],s,1,1,!1,a==="win"?null:t,a)}u(oe,1,[0],a=>{e.uniform1i(a("tex"),0),e.uniform1f(a("harden"),c.harden?Hi:0)});const R=(a,g,M,ee)=>{u(K,g,[a],W=>{e.uniform1i(W("tex"),0),e.uniform2i(W("dir"),1,0),e.uniform1f(W("sigma"),ee)}),u(K,M,[g],W=>{e.uniform1i(W("tex"),0),e.uniform2i(W("dir"),0,1),e.uniform1f(W("sigma"),ee)})};R(1,2,3,c.band),u(h,2,[1,3],a=>{e.uniform1i(a("a"),0),e.uniform1i(a("b"),1)}),R(2,1,3,c.glow),u(_,1,[0,2,3],a=>{e.uniform1i(a("pic"),0),e.uniform1i(a("band"),1),e.uniform1i(a("glow"),2),e.uniform3f(a("col"),...c.col),e.uniform1f(a("k"),c.k),e.uniform1f(a("am"),c.am)}),e.bindFramebuffer(e.FRAMEBUFFER,E),e.viewport(L[0],L[1],L[2],L[3]),o&&e.enable(e.BLEND)};let J=null,P="",Pe=null,We=[],Mt="";const St=new Map,Dt=new Map,at=new Map,xt=new Map,kt=new Map,Rt=new Map,F=ve(),ne=(r,s)=>{const t=ve();e.texImage2D(e.TEXTURE_2D,0,e.RGBA8,r,s,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,t,0),{tex:t,fb:c}},fe=(r,s,t)=>{const c=e.getParameter(e.FRAMEBUFFER_BINDING),E=e.getParameter(e.VIEWPORT),L=e.isEnabled(e.BLEND),o=r.w,f=r.h;if(Mt!==`${o}x${f}`){for(const $ of We)e.deleteTexture($.tex),e.deleteFramebuffer($.fb);We=Array.from({length:7},()=>ne(o,f)),Mt=`${o}x${f}`}e.disable(e.BLEND),e.bindFramebuffer(e.FRAMEBUFFER,We[0].fb),e.viewport(0,0,o,f),e.clearColor(0,0,0,0),e.clear(e.COLOR_BUFFER_BIT),Ie(r,[0,1,1,-1],[0,0,1,1],1,1,!1,s,"base");let u=0;const R=$=>[$[0],$[3],$[6],$[1],$[4],$[7],$[2],$[5],$[8]],a=($,z,dt,nt)=>{e.bindFramebuffer(e.FRAMEBUFFER,We[z].fb),e.viewport(0,0,o,f),e.useProgram($);const Ce=tt($);dt.forEach((vt,ht)=>{e.activeTexture(e.TEXTURE0+ht),e.bindTexture(vt.d3?e.TEXTURE_3D:e.TEXTURE_2D,vt.t)}),nt(Ce),e.drawArrays(e.TRIANGLE_STRIP,0,4),me()},g=$=>({t:We[$].tex}),M=($,z,dt,nt)=>{a(ge,z,[g($)],Ce=>{e.uniform1i(Ce("tex"),0),e.uniform2f(Ce("step"),1/o,0),e.uniform1f(Ce("sigma"),nt)}),a(ge,dt,[g(z)],Ce=>{e.uniform1i(Ce("tex"),0),e.uniform2f(Ce("step"),0,1/f),e.uniform1f(Ce("sigma"),nt)})},ee=t.list,W=ee.map($=>Jt($)),Q=Ui(ee),_e=new Set;for(const[$,z]of ee.entries()){const dt=Q[$];if($===dt&&ee.some((b,A)=>A>$&&Q[A]===$&&W[A])&&(a(Y,2,[g(u)],b=>e.uniform1i(b("tex"),0)),_e.add($)),!W[$])continue;const nt=$!==dt&&_e.has(dt)?z.branch:void 0,Ce=nt?2:u;let vt=F,ht=[1,1];if(z.qualifier){const b=Math.max(2,Math.trunc((o+_t-1)/_t)),A=Math.max(2,Math.trunc((f+_t-1)/_t)),N=`${b}x${A}`;let se=St.get(N);se||(se=ne(b,A),St.set(N,se));const te=z.qualifier,he=Math.max(.001,te.soft??.3),Be=z.window,gt=-(Be?.rot??0)*Math.PI/180;e.bindFramebuffer(e.FRAMEBUFFER,se.fb),e.viewport(0,0,b,A),e.useProgram(be),e.activeTexture(e.TEXTURE0),e.bindTexture(e.TEXTURE_2D,We[Ce].tex);const Me=tt(be);e.uniform1i(Me("tex"),0),e.uniform2f(Me("big"),o,f),e.uniform2f(Me("small"),b,A),e.uniform4f(Me("q1"),te.hue,te.hueWidth,Math.max(1,he*60),Math.max(.001,he*.2)),e.uniform4f(Me("q2"),te.satMin,te.satMax,te.lumMin,te.lumMax),e.uniform1f(Me("useQ"),1),e.uniform1f(Me("useW"),Be?1:0),Be&&(e.uniform4f(Me("w1"),Be.cx,Be.cy,Math.max(1e-4,Be.w/2),Math.max(.001,Be.feather??.2)),e.uniform4f(Me("w2"),Math.cos(gt),Math.sin(gt),Math.max(1e-4,Be.h/2),Be.type==="gradient"?2:Be.type==="rect"?1:0)),e.uniform1f(Me("inv"),z.invert?1:0),e.drawArrays(e.TRIANGLE_STRIP,0,4),vt=se.tex,ht=[b*_t,A*_t]}else if(!z.whole&&Pi(z)&&z.window?.type!=="person"){const b=`${t.clip}#${$}`,A=`${o}x${f}@${t.local??0}`,N=vo,se=Math.max(2,Math.min(vo*2,Math.round(N*f/o)));let te=xt.get(b);if(te||(te={tex:ve(),at:""},xt.set(b,te)),te.at!==A){const he=xo(z,t.src,t.local??0,f/o,null),Be=new Uint8Array(N*se);for(let gt=0;gt<se;gt++)for(let Me=0;Me<N;Me++)Be[gt*N+Me]=Math.round(he((Me+.5)/N,(gt+.5)/se,0,0,0)*255);e.bindTexture(e.TEXTURE_2D,te.tex),e.pixelStorei(e.UNPACK_ALIGNMENT,1),e.texImage2D(e.TEXTURE_2D,0,e.R8,N,se,0,e.RED,e.UNSIGNED_BYTE,Be),e.pixelStorei(e.UNPACK_ALIGNMENT,4),te.at=A}vt=te.tex,ht=[o,f]}else if(!z.whole){const b=ho(z)?t.src?.depthMap:void 0,A=`${t.clip}#${$}@${o}x${f}${b?`@${b.at}:${b.data.length}:${b.data.slice(0,24)}`:""}`;let N=Dt.get(A);if(!N){const se=Bi(z,o,f,ho(z)?xo(z,t.src,0,f/o):null);N=ve(),e.pixelStorei(e.UNPACK_ALIGNMENT,1),e.texImage2D(e.TEXTURE_2D,0,e.R8,se.w4,se.h4,0,e.RED,e.UNSIGNED_BYTE,se.px),e.pixelStorei(e.UNPACK_ALIGNMENT,4),Dt.set(A,N)}vt=N,ht=[o,f]}const Ut=z.adjust??{},to=Ni(z),Wt=`${t.clip}#${$}`;let Gt=at.get(Wt);if(to&&!Gt){const b=new Float32Array(1024);for(let A=0;A<256;A++)["r","g","b"].forEach((N,se)=>{b[A*4+se]=+Li(Ut,N,A/255,z.wheels,z.curves).toFixed(6)}),b[A*4+3]=1;Gt=ve(),e.texImage2D(e.TEXTURE_2D,0,e.RGBA32F,256,1,0,e.RGBA,e.FLOAT,b);for(const A of[e.TEXTURE_MIN_FILTER,e.TEXTURE_MAG_FILTER])e.texParameteri(e.TEXTURE_2D,A,e.NEAREST);at.set(Wt,Gt)}let bt=null;if(Ii(z)){const b=`${Wt}:${JSON.stringify([z.cst,z.look,z.lut,z.mixer])}`;if(bt=kt.get(b)??null,!bt){const A=Ci(z,N=>lr(N));if(!A)throw Error(`LUT "${z.lut?.name??""}" chưa tải xong`);bt=e.createTexture(),e.activeTexture(e.TEXTURE4),e.bindTexture(e.TEXTURE_3D,bt),e.pixelStorei(e.UNPACK_ALIGNMENT,1),e.texImage3D(e.TEXTURE_3D,0,e.RGB32F,A.size,A.size,A.size,0,e.RGB,e.FLOAT,A.data),e.pixelStorei(e.UNPACK_ALIGNMENT,4);for(const N of[e.TEXTURE_MIN_FILTER,e.TEXTURE_MAG_FILTER])e.texParameteri(e.TEXTURE_3D,N,e.NEAREST);for(const N of[e.TEXTURE_WRAP_S,e.TEXTURE_WRAP_T,e.TEXTURE_WRAP_R])e.texParameteri(e.TEXTURE_3D,N,e.CLAMP_TO_EDGE);e.activeTexture(e.TEXTURE0),kt.set(b,bt)}}const{sat:Uo,rot:Po}=Xi(Ut.saturation??1,Ut.hue??0);a(ae,3,[g(Ce),{t:Gt??ot},{t:bt??yt,d3:!0}],b=>{e.uniform1i(b("tex"),0),e.uniform1i(b("lut"),1),e.uniform1i(b("t3"),2),e.uniform1f(b("useT"),bt?1:0),e.uniform1f(b("useL"),to?1:0),e.uniform1f(b("useS"),(Ut.saturation??1)!==1?1:0),e.uniform1f(b("useR"),(Ut.hue??0)!==0?1:0),e.uniformMatrix3fv(b("sat"),!1,R(Uo)),e.uniformMatrix3fv(b("rot"),!1,R(Po))}),e.activeTexture(e.TEXTURE2),e.bindTexture(e.TEXTURE_3D,null),e.activeTexture(e.TEXTURE0),me();let ue=3;const st=(b,A)=>[3,4,5].find(N=>N!==b&&N!==A);if((z.blur??0)>0){const b=st(ue),A=st(ue,b);M(ue,b,A,Math.max(.1,+((z.blur??0)*Oi*o).toFixed(3))),ue=A}const oo=zi({sharpness:z.sharpen??0});if(oo){const b=st(ue);a(Se,b,[g(ue)],A=>{e.uniform1i(A("tex"),0),e.uniform1fv(A("k"),oo),e.uniform1f(A("rdiv"),1/Vi)}),ue=b}const Re=z.fx?Gi(z.fx,o):null;if(Re&&(Re.type==="glow"||Re.type==="halation")){const b=st(ue),A=st(ue,b);a(ce,b,[g(ue)],he=>{e.uniform1i(he("tex"),0),e.uniform1f(he("lo"),Re.lo),e.uniform1f(he("k"),Re.k)});let N=b;Re.tint&&(a(je,A,[g(b),{t:ot}],he=>{e.uniform1i(he("tex"),0),e.uniform1i(he("lut"),1),e.uniform1f(he("useM"),1),e.uniform1f(he("useL"),0),e.uniform1fv(he("m"),Re.tint.flat())}),N=A),M(N,N===b?A:b,N,Re.sigma);const te=6;a(H,te,[g(ue),g(N)],he=>{e.uniform1i(he("a"),0),e.uniform1i(he("b"),1),e.uniform1f(he("amount"),Re.amount)}),a(Y,3,[g(te)],he=>e.uniform1i(he("tex"),0)),ue=3}else if(Re?.type==="grain"){const b=qi(t.frame??0),A=`${b}:${o}x${f}:${Re.amp}`;let N=Rt.get(A);if(!N){if(Rt.size>8){for(const te of Rt.values())e.deleteTexture(te);Rt.clear()}N=ve(),e.pixelStorei(e.UNPACK_ALIGNMENT,1),e.texImage2D(e.TEXTURE_2D,0,e.R8,o,f,0,e.RED,e.UNSIGNED_BYTE,$i(b,o,f,Re.amp)),e.pixelStorei(e.UNPACK_ALIGNMENT,4),Rt.set(A,N)}const se=st(ue);a(Fe,se,[g(ue),{t:N}],te=>{e.uniform1i(te("tex"),0),e.uniform1i(te("grain"),1)}),ue=se}else if(Re?.type==="denoise"){const b=st(ue),A=st(ue,b);M(ue,b,A,Re.sigma),a(qe,6,[g(ue),g(A)],N=>{e.uniform1i(N("tex"),0),e.uniform1i(N("soft"),1),e.uniform1f(N("t"),Re.t)}),a(Y,3,[g(6)],N=>e.uniform1i(N("tex"),0)),ue=3}else if(Re?.type==="swirl"){const b=A=>Math.max(2,Math.round(A/2)*2);for(const A of ji(o,f,Re.deg)){const N=st(ue);a(He,N,[g(ue)],se=>{e.uniform1i(se("tex"),0),e.uniform2f(se("size"),o,f),e.uniform1fv(se("a"),A.map(te=>+te.a.toFixed(6))),e.uniform1fv(se("sx"),A.map(te=>b(o*te.scale)/o)),e.uniform1fv(se("sy"),A.map(te=>b(f*te.scale)/f))}),ue=N}}const Bo=nt==="parallel"?2:u,No=nt==="parallel"?6:1-u;a(Z,No,[g(Bo),g(ue),{t:vt}],b=>{e.uniform1i(b("base"),0),e.uniform1i(b("over"),1),e.uniform1i(b("mask"),2),e.uniform2f(b("msz"),ht[0],ht[1]),e.uniform1f(b("full"),z.whole?1:0)}),nt==="parallel"&&a(Ee,1-u,[g(u),g(6),g(2)],b=>{e.uniform1i(b("res"),0),e.uniform1i(b("outp"),1),e.uniform1i(b("inp"),2)}),u=1-u}Pe=We[u].tex,e.bindFramebuffer(e.FRAMEBUFFER,c),e.viewport(E[0],E[1],E[2],E[3]),L&&e.enable(e.BLEND)},xe=(r,s)=>J?(P!==J.key&&(fe(r,s,J),P=J.key),"win"):"pic",de=(r,s,t,c,E,L,o)=>{if(!i){const M=xe(r,o);Ie(r,s,t,c,E,L,M==="win"?null:o,M);return}const f=Ve??[0,0,1,1];X!==i.key&&(Ke(r,f,o,i),X=i.key);const u=(t[0]-f[0])/f[2],R=(t[1]-f[1])/f[3],a=t[2]/f[2],g=t[3]/f[3];Ie(r,s,[u,1-R,a,-g],c,E,L,null,"edge")},Ie=(r,s,t,c,E,L,o,f)=>{const u=f==="edge"||f==="win",R=f==="pic"||f==="base";if(e.useProgram(B),e.activeTexture(e.TEXTURE0),e.bindTexture(e.TEXTURE_2D,Et),R&&e.texImage2D(e.TEXTURE_2D,0,e.RGBA,e.RGBA,e.UNSIGNED_BYTE,r.source),e.uniform4f(T("dst"),s[0],s[1],s[2],s[3]),e.uniform4f(T("src"),t[0],t[1],t[2],t[3]),e.uniform1f(T("alpha"),c),e.uniform1f(T("fade"),E),e.uniform1f(T("white"),L?1:0),e.uniform1f(T("colour"),o?1:0),e.uniform1i(T("tex"),0),e.uniform1i(T("matte"),1),e.uniform1f(T("useMatte"),Ve&&(f==="pic"||f==="win")?1:0),De&&!u?(e.uniform4f(T("key"),De.u,De.v,De.similarity,De.blend),e.uniform4f(T("keyOpt"),1,De.blue?1:0,De.spill,r.bt709?1:0)):e.uniform4f(T("keyOpt"),0,0,0,0),e.uniform1i(T("lut1"),2),e.uniform1i(T("lut3"),3),e.uniform1f(T("useL1"),Ft&&!u?1:0),e.uniform1f(T("useL3"),At&&!u?1:0),Ve&&e.uniform4f(T("mrect"),Ve[0],Ve[1],Ve[2],Ve[3]),e.activeTexture(e.TEXTURE1),e.bindTexture(e.TEXTURE_2D,Tt),e.activeTexture(e.TEXTURE2),e.bindTexture(e.TEXTURE_2D,ot),e.activeTexture(e.TEXTURE3),e.bindTexture(e.TEXTURE_3D,yt),e.activeTexture(e.TEXTURE0),e.bindTexture(e.TEXTURE_2D,f==="edge"?pe[1].tex:f==="win"?Pe:Et),o){const a=g=>[g[0],g[3],g[6],g[1],g[4],g[7],g[2],g[5],g[8]];e.uniform1f(T("bright"),o.bright),e.uniform1f(T("contrast"),o.contrast),e.uniformMatrix3fv(T("sat"),!1,a(o.sat)),e.uniformMatrix3fv(T("rot"),!1,a(o.rot))}e.drawArrays(e.TRIANGLE_STRIP,0,4)};return{canvas:w,clear(r=1){I(null),e.clearColor(0,0,0,r),e.clear(e.COLOR_BUFFER_BIT)},pixels(){I(null);const r=new Uint8ClampedArray(d*y*4),s=d*4,t=new Uint8ClampedArray(d*y*4);e.readPixels(0,0,d,y,e.RGBA,e.UNSIGNED_BYTE,r);for(let c=0;c<y;c++){const E=(y-1-c)*s,L=c*s;for(let o=0;o<s;o+=4){const f=r[E+o+3];if(t[L+o+3]=f,f){const u=255/f;t[L+o]=r[E+o]*u,t[L+o+1]=r[E+o+1]*u,t[L+o+2]=r[E+o+2]*u}}}return t},draw(r,s,t,c,E,L,o=null,f=[],u=null){if(!f.length&&!we&&!ke.length&&!Oe){I(null),e.enable(e.BLEND),e.blendFuncSeparate(e.SRC_ALPHA,e.ONE_MINUS_SRC_ALPHA,e.ONE,e.ONE_MINUS_SRC_ALPHA),de(r,s,t,c,E,L,o);return}Ue??=[p(),p(),p()],I(Ue[0].fb),e.disable(e.BLEND),e.clearColor(0,0,0,0),e.clear(e.COLOR_BUFFER_BIT),de(r,u??s,t,c,E,L,o);const R=q(f);if(I(null),e.enable(e.BLEND),e.blendFuncSeparate(e.SRC_ALPHA,e.ONE_MINUS_SRC_ALPHA,e.ONE,e.ONE_MINUS_SRC_ALPHA),we||ke.length||Oe){let a=R;u&&(a=(R+1)%3,I(Ue[a].fb),e.disable(e.BLEND),e.clearColor(0,0,0,0),e.clear(e.COLOR_BUFFER_BIT),e.useProgram(B),e.activeTexture(e.TEXTURE0),e.bindTexture(e.TEXTURE_2D,Ue[R].tex),e.uniform4f(T("dst"),s[0],s[1],s[2],s[3]),e.uniform4f(T("src"),0,1,1,-1),e.uniform1f(T("alpha"),1),e.uniform1f(T("fade"),1),e.uniform1f(T("white"),0),e.uniform1f(T("colour"),0),e.uniform1f(T("useMatte"),0),e.drawArrays(e.TRIANGLE_STRIP,0,4)),wt(a);return}if(!u){S(Y,null,[Ue[R].tex],a=>e.uniform1i(a("tex"),0));return}e.useProgram(B),e.activeTexture(e.TEXTURE0),e.bindTexture(e.TEXTURE_2D,Ue[R].tex),e.uniform4f(T("dst"),s[0],s[1],s[2],s[3]),e.uniform4f(T("src"),0,1,1,-1),e.uniform1f(T("alpha"),1),e.uniform1f(T("fade"),1),e.uniform1f(T("white"),0),e.uniform1f(T("colour"),0),e.uniform1f(T("useMatte"),0),e.drawArrays(e.TRIANGLE_STRIP,0,4)},warp(r,s,t,c,E,L,o,f,u,R=null,a=null,g=[]){const M=ze();I(M[0].fb),e.disable(e.BLEND),e.clearColor(0,0,0,0),e.clear(e.COLOR_BUFFER_BIT),de(r,s,t,c,E,L,o);const ee=q(f),W=we||ke.length||Oe||g.length?(ee+1)%3:-1;W>=0?(I(M[W].fb),e.disable(e.BLEND),e.clearColor(0,0,0,0),e.clear(e.COLOR_BUFFER_BIT)):(I(null),e.enable(e.BLEND),e.blendFuncSeparate(e.SRC_ALPHA,e.ONE_MINUS_SRC_ALPHA,e.ONE,e.ONE_MINUS_SRC_ALPHA)),a&&(e.enable(e.SCISSOR_TEST),e.scissor(a[0],y-a[1]-a[3],a[2],a[3])),S($e,W>=0?M[W].fb:null,[M[ee].tex],Q=>{e.uniform1i(Q("tex"),0),e.uniform2f(Q("size"),d,y),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"),R?.[0]??0,R?.[1]??0,R?.[2]??0,R?1:0)}),e.disable(e.SCISSOR_TEST),W>=0&&wt(g.length?q(g,W):W)},adjust(r,s,t){const c=ze();if(I(null),e.bindTexture(e.TEXTURE_2D,it),e.copyTexImage2D(e.TEXTURE_2D,0,e.RGBA8,0,0,d,y,0),I(c[0].fb),e.disable(e.BLEND),e.useProgram(B),e.activeTexture(e.TEXTURE0),e.bindTexture(e.TEXTURE_2D,it),e.uniform4f(T("dst"),0,0,1,1),e.uniform4f(T("src"),0,1,1,-1),e.uniform1i(T("tex"),0),e.uniform1f(T("alpha"),1),e.uniform1f(T("fade"),1),e.uniform1f(T("white"),0),e.uniform1f(T("useMatte"),0),e.uniform1f(T("colour"),r?1:0),r){const L=o=>[o[0],o[3],o[6],o[1],o[4],o[7],o[2],o[5],o[8]];e.uniform1f(T("bright"),r.bright),e.uniform1f(T("contrast"),r.contrast),e.uniformMatrix3fv(T("sat"),!1,L(r.sat)),e.uniformMatrix3fv(T("rot"),!1,L(r.rot))}e.drawArrays(e.TRIANGLE_STRIP,0,4);const E=q(s);I(null),e.enable(e.BLEND),e.blendFuncSeparate(e.SRC_ALPHA,e.ONE_MINUS_SRC_ALPHA,e.ONE,e.ONE_MINUS_SRC_ALPHA),e.useProgram(B),e.activeTexture(e.TEXTURE0),e.bindTexture(e.TEXTURE_2D,c[E].tex),e.uniform4f(T("dst"),0,0,1,1),e.uniform4f(T("src"),0,1,1,-1),e.uniform1f(T("alpha"),t),e.uniform1f(T("fade"),1),e.uniform1f(T("white"),0),e.uniform1f(T("colour"),0),e.uniform1f(T("useMatte"),0),e.drawArrays(e.TRIANGLE_STRIP,0,4)},grade(r,s){if(Ft=!!r,At=!!s,r&&U.l1!==r.key){const t=new Float32Array(1024);for(let c=0;c<256;c++)t[c*4]=r.r[c],t[c*4+1]=r.g[c],t[c*4+2]=r.b[c],t[c*4+3]=1;e.activeTexture(e.TEXTURE2),e.bindTexture(e.TEXTURE_2D,ot),e.texImage2D(e.TEXTURE_2D,0,e.RGBA32F,256,1,0,e.RGBA,e.FLOAT,t);for(const c of[e.TEXTURE_MIN_FILTER,e.TEXTURE_MAG_FILTER])e.texParameteri(e.TEXTURE_2D,c,e.NEAREST);e.activeTexture(e.TEXTURE0),U.l1=r.key}if(s&&U.l3!==s.key){e.activeTexture(e.TEXTURE3),e.bindTexture(e.TEXTURE_3D,yt),e.pixelStorei(e.UNPACK_ALIGNMENT,1),e.texImage3D(e.TEXTURE_3D,0,e.RGB32F,s.size,s.size,s.size,0,e.RGB,e.FLOAT,s.data),e.pixelStorei(e.UNPACK_ALIGNMENT,4);for(const t of[e.TEXTURE_MIN_FILTER,e.TEXTURE_MAG_FILTER])e.texParameteri(e.TEXTURE_3D,t,e.NEAREST);for(const t of[e.TEXTURE_WRAP_S,e.TEXTURE_WRAP_T,e.TEXTURE_WRAP_R])e.texParameteri(e.TEXTURE_3D,t,e.CLAMP_TO_EDGE);e.activeTexture(e.TEXTURE0),U.l3=s.key}},key(r){if(!r){De=null;return}const[s,t,c]=[1,3,5].map(L=>parseInt(r.color.slice(L,L+2),16)),E=224/255;De={u:Math.round(-.168736*E*s-.331264*E*t+.5*E*c+128),v:Math.round(.5*E*s-.418688*E*t-.081312*E*c+128),similarity:r.similarity,blend:r.blend,spill:+r.spill.toFixed(3),blue:c>t}},mode(r){we=r&&pt[r]||0},shadow(r){ke=r},blurBegin(){rt??=p(),I(rt.fb),e.clearColor(0,0,0,0),e.clear(e.COLOR_BUFFER_BIT),Oe=!0},blurEnd(){Oe=!1;const r=ze();e.disable(e.BLEND),S(l,r[0].fb,[rt.tex],s=>e.uniform1i(s("tex"),0)),wt(0)},windows(r){J=r},edge(r){i=r},warpBig(r,s,t,c,E,L,o,f,u,R=[]){const a=zt(u),g=d*u,M=y*u;e.bindFramebuffer(e.FRAMEBUFFER,a.plane.fb),e.viewport(0,0,g,M),e.disable(e.BLEND),e.clearColor(0,0,0,0),e.clear(e.COLOR_BUFFER_BIT),de(r,s,t,c,E,L,o);const ee=Lt(f.map(([_e,$])=>[_e*u,$*u]),g,M);e.bindFramebuffer(e.FRAMEBUFFER,a.out.fb),e.viewport(0,0,g,M),e.useProgram($e),e.activeTexture(e.TEXTURE0),e.bindTexture(e.TEXTURE_2D,a.plane.tex);const W=tt($e);if(e.uniform1i(W("tex"),0),e.uniform2f(W("size"),g,M),e.uniform1f(W("keepPre"),1),e.uniform4f(W("rnd"),0,0,0,0),e.uniformMatrix3fv(W("inv"),!1,[ee[0],ee[3],ee[6],ee[1],ee[4],ee[7],ee[2],ee[5],ee[8]]),e.drawArrays(e.TRIANGLE_STRIP,0,4),I(null),e.enable(e.BLEND),e.blendFuncSeparate(e.SRC_ALPHA,e.ONE_MINUS_SRC_ALPHA,e.ONE,e.ONE_MINUS_SRC_ALPHA),!R.length&&!we&&!ke.length&&!Oe){S(ie,null,[a.out.tex],_e=>{e.uniform1i(_e("tex"),0),e.uniform1i(_e("ss"),u)});return}const Q=ze();e.disable(e.BLEND),S(ie,Q[0].fb,[a.out.tex],_e=>{e.uniform1i(_e("tex"),0),e.uniform1i(_e("ss"),u)}),wt(q(R,0))},matte(r,s=[0,0,1,1]){Ve=r?s:null,r&&(e.activeTexture(e.TEXTURE1),e.bindTexture(e.TEXTURE_2D,Tt),e.texImage2D(e.TEXTURE_2D,0,e.RGBA,e.RGBA,e.UNSIGNED_BYTE,r),e.activeTexture(e.TEXTURE0))},overlay(r,s){I(null),e.enable(e.BLEND),e.blendFuncSeparate(e.SRC_ALPHA,e.ONE_MINUS_SRC_ALPHA,e.ONE,e.ONE_MINUS_SRC_ALPHA),s&&(e.activeTexture(e.TEXTURE0),e.bindTexture(e.TEXTURE_2D,Et),e.texImage2D(e.TEXTURE_2D,0,e.RGBA,s.w,s.h,0,e.RGBA,e.UNSIGNED_BYTE,s.data)),S(ft,null,s?[Et]:[],t=>{e.uniform1i(t("tex"),0),e.uniform1f(t("usetex"),s?1:0),e.uniform4f(t("colour"),...r??[0,0,0,0])})},finish(){e.finish()}}}let Ge="";const Pa=()=>Ge;async function xa(d,{format:y,encode:w=null,tracks:e={},camera:O=null,signal:v,onProgress:B,frames:D,software:oe=!1}){const K=performance.now(),{width:h,height:_,fps:j}=wo(y);Ge="layers",await Promise.all([...new Set(d.filter(n=>!n.colorBypass).flatMap(n=>qt(n.grade).map(x=>x?.lut?.id)).filter(n=>!!n))].map(n=>rr(n))),Lo(io(d.filter(n=>!n.disabled)));const l=d.filter(n=>!n.disabled&&!Io(n)),be=io(l),ge=Co(l.reduce((n,x)=>Math.max(n,x.start+x.duration),0)),ce=Math.round(ge*j);if(!(ce>0)&&!D)throw Error("Empty timeline");const H=Xo(O)?O:null,Y=Oo(be,e,H?n=>Di(n,H,h,_):void 0),le=n=>Y.find(x=>n>=x.start-1e-6&&n<x.start+x.duration-1e-6)??null,ae=()=>{if(v?.aborted)throw new DOMException("Export cancelled","AbortError")},Z=new Ar,Se=[...l.filter(n=>$t(n)),...zo(l)];Se.length&&await(await jt(async()=>{const{renderTitleFrames:n}=await import("./titleFrames-WfiLHzjf.js");return{renderTitleFrames:n}},__vite__mapDeps([0,1,2,3,4,5,6]))).renderTitleFrames(Se,y,Z,v),l.some(n=>n.kind==="model")&&await(await jt(async()=>{const{render3DFrames:n}=await import("./timeline3dExport-MWomW4fF.js");return{render3DFrames:n}},__vite__mapDeps([7,1,8,9,10,5,11,6]))).render3DFrames(d.filter(n=>!n.disabled),y,Z,v,O);for(const n of be.filter(x=>x._group&&x.comp)){const x=[],C=Math.max(1,Math.ceil(n.duration*j-1e-6));await xa(Qi(Zi(n),{W:h,H:_}),{format:y,signal:v,frames:{times:Array.from({length:C},(m,V)=>Wi(n,V/j)),push:(m,V)=>{x[m]=V}}}),Z.frames.set(n.id,x)}const Fe=performance.now();ae(),Ge="mattes";const qe=l.filter(n=>n.mask||n.person),Ee=qe.length?await jt(()=>import("./rotoMatte-2EcyuvBX.js").then(n=>n.r),__vite__mapDeps([12,1,5,13])):null;Ee&&await Ee.prepareMattes(qe);const lt=Ee?document.createElement("canvas"):null;Ge="media";const Qe=new Map,Ze=new Map,Ae=new Map,ft=n=>{let x=Qe.get(n);return x||(x=new xr({source:new vr(n,{getRetryDelay:Do}),formats:dr}),Qe.set(n,x)),x};for(const n of l){if(n.kind==="video"&&!Ze.has(n.url)){const x=await ft(n.url).getPrimaryVideoTrack();x&&Ze.set(n.url,new mr(x))}if(n.kind==="image"&&!$t(n)&&!ro(n)&&!n._group&&!Ae.has(n.url)){const x=await createImageBitmap(await Fr(n.url,v),{imageOrientation:"from-image",premultiplyAlpha:"none",colorSpaceConversion:"none"});Ae.set(n.url,{source:x,w:x.width,h:x.height,close:()=>x.close()})}}const $e=new Map,Je=async(n,x)=>{const C=Z.frames.get(n.id);if(!C?.length)return null;let m=C.length===1?0:Math.max(0,Math.min(Math.round((x-n.start)*j),Math.ceil(n.duration*j)-1,C.length-1));for(;m>0&&C[m]==="=";)m--;const V=$e.get(n.id);if(V&&V.index===m)return V.pic;V?.pic?.close?.();const k=await createImageBitmap(await(await fetch(`data:image/webp;base64,${C[m]}`)).blob(),{premultiplyAlpha:"none",colorSpaceConversion:"none"}),p={source:k,w:k.width,h:k.height,close:()=>k.close()};return $e.set(n.id,{index:m,pic:p}),p},je=l.filter(n=>Go(n)),Xe=je.length?await jt(()=>import("./captionLayout-BAdmqwdS.js"),__vite__mapDeps([14,1])):null,Ne=new Map,Le=new Map;if(Xe){for(const n of new Set(je.flatMap(x=>[Qt(qo(x.captionStyle).font),Qt(ao(x.captionStyle).font)])))if(await Xe.captionFontReady(n.id),!Ne.has(n.id)){const x=new Uint8Array(await(await fetch(`/fonts/${n.file}`,{signal:v})).arrayBuffer());let C="";for(let m=0;m<x.length;m+=32768)C+=String.fromCharCode(...x.subarray(m,m+32768));Ne.set(n.id,`@font-face{font-family:'${n.family}';src:url(data:font/${n.file.endsWith(".otf")?"otf":"ttf"};base64,${btoa(C)})}`)}}const et=new Map,ie=async(n,x,C)=>{let m=et.get(x.start);if(!m||m.owner!==n){const q=ai(n,x.start,x.duration);m={plan:q,starts:ni(q.entries,j),owner:n},et.clear(),et.set(x.start,m)}const V=C-Math.round(x.start*j);let k=-1;for(let q=0;q<m.starts.length&&m.starts[q]<=V;q++)k=q;const p=m.plan.entries[k];if(!p||p.blank)return null;const I=m.plan.social?m.plan.social.style:ao(n.captionStyle),S=m.plan.social?si(m.plan.social,p.gi,h,_,Xe.measureCaption):ci({width:h,height:_,text:p.text,style:I,measure:Xe.measureCaption,second:p.second}),re=li(S,I,m.plan.social?p.scale:1,h,_,p.active,p.motion);let me=Le.get(re);if(!me){const q=Qt(I.font),i=URL.createObjectURL(new Blob([re.replace("<defs>",`<defs><style>${Ne.get(q.id)??""}</style>`)],{type:"image/svg+xml"}));try{const X=new Image(h,_);X.src=i,await X.decode();const pe=await createImageBitmap(X,{premultiplyAlpha:"none"});me={source:pe,w:h,h:_,close:()=>pe.close()}}finally{URL.revokeObjectURL(i)}if(Le.size>64){const[X,pe]=Le.entries().next().value;pe.close?.(),Le.delete(X)}Le.set(re,me)}return me},ye=[0,0,1,1],ut=new Map,mt=["x","y","zoom","rot","sx","sy"],He=(n,x,C,m)=>{const V=`${n.id}@${x.start}`;let k=ut.get(V);if(!k){const I=Math.max(1,Math.ceil(x.duration/.1-1e-6)),S=Array.from({length:I+1},(q,i)=>x.start+x.duration*i/I),re=S.map(q=>Zt(n,q-n.start,h,_)),me=q=>+(+q).toFixed(3);k={ts:S.map(q=>+q.toFixed(5)),v:Object.fromEntries(mt.map(q=>[q,re.map(i=>me(i[q]??(q==="sx"||q==="sy"?1:0)))]))},ut.set(V,k)}const p={...m};for(const I of mt){const S=k.v[I];if(S.every(i=>i===S[0])){p[I]=S[0];continue}let re=k.ts.findIndex((i,X)=>X<k.ts.length-1&&C<k.ts[X+1]);re<0&&(re=k.ts.length-2);const me=+(S[re+1]-S[re]).toFixed(3),q=k.ts[re+1]-k.ts[re];p[I]=Math.abs(S[re+1]-S[re])<1e-4?S[re]:S[re]+me*Math.max(0,Math.min(1,(C-k.ts[re])/q))}return p},Ct=new Map,tt=new Map,T=(n,x,C,m=n,V="")=>{if(!fi(m))return go(m,h);const k=`${n.id}${V}@${x.start}`;let p=tt.get(k);p||(p=ui(m,{offset:x.start-n.start,duration:x.duration,fps:j}),tt.set(k,p));const I=C-Math.round(x.start*j),S=p.find(re=>I>=re.from&&I<re.to)??p[p.length-1];return go({effects:mi(m,S.t)},h)},ve=new Map,Et=(n,x,C)=>{const m=`${n.id}@${x.start}`;ve.has(m)||ve.set(m,H?_i(n,H,x.start,x.duration,h,_):null);const V=ve.get(m);return V?T(n,x,C,V,":dof"):[]},Tt=new Map,Ve=n=>{const x=JSON.stringify(n.grade);let C=Tt.get(x);if(!C){const m=p=>Array.from(p,I=>+I.toFixed(6)),V=vi(n.grade)?hi(n.grade):null,k=n.grade.mixer&&bi(n.grade.mixer)?gi(n.grade.mixer):null;C={l1:V?{key:`1${x}`,r:m(V.r),g:m(V.g),b:m(V.b)}:null,l3:k?{key:`3${x}`,size:k.size,data:Float32Array.from(k.data,p=>+p.toFixed(6))}:null},Tt.set(x,C)}return C};let ot=null;const yt=async(n,x,C)=>{const m=l.find(p=>p.id===n);if(!m||x<m.start||x>=m.start+m.duration)return null;if($t(m)){const p=await Je(m,x);return p&&{source:p.source,w:p.w,h:p.h}}if(m.kind==="image"){const p=Ae.get(m.url);return p?{source:p.source,w:p.w,h:p.h}:null}if(m.kind!=="video")return null;const V=await Eo(Ue,Ze,m,x,j,Math.max(C.start,m.start),C.duration);if(!V)return null;const k=V.toVideoFrame();return{source:k,w:V.displayWidth,h:V.displayHeight,close:()=>k.close()}};Ge="output";const U=pa(h,_),Ft=Mo(w,{width:h,height:_,fps:j},Fo),At=w?.codec==="hevc",De=w?.container==="mov",pt=!D&&ge*Ft/8>15e7&&!!navigator.storage?.getDirectory;let we=null,it;if(pt){const n=await navigator.storage.getDirectory(),x=`gpu-export-${crypto.randomUUID()}.${De?"mov":"mp4"}`,C=await n.getFileHandle(x,{create:!0});we={dir:n,handle:C,name:x},it=new br(await C.createWritable(),{chunked:!0,chunkSize:1<<20})}else it=new gr;const ke=new Er({format:De?new Tr({fastStart:pt?"reserve":"in-memory"}):new yr({fastStart:pt?"reserve":"in-memory"}),target:it}),Oe=new wr(U.canvas,{codec:At?"hevc":"avc",bitrate:Ft,keyFrameInterval:2,...At?{hardwareAcceleration:"prefer-hardware"}:oe?{hardwareAcceleration:"prefer-software"}:{}});ke.addVideoTrack(Oe,{frameRate:j,...pt?{maximumPacketCount:ce+8}:{}});const rt=new Rr({codec:"aac",bitrate:So});ke.addAudioTrack(rt,pt?{maximumPacketCount:Math.ceil(ge*It/1024)+16}:{}),D||await ke.start();const Xt=D?new OffscreenCanvas(h,_):null,wt=Xt?.getContext("2d"),Kt=async n=>{wt.putImageData(new ImageData(U.pixels(),h,_),0,0);const x=new Uint8Array(await(await Xt.convertToBlob({type:"image/webp",quality:.9})).arrayBuffer());let C="";for(let m=0;m<x.length;m+=32768)C+=String.fromCharCode(...x.subarray(m,m+32768));D.push(n,btoa(C))},Ue=new Map;let ze=0;try{for(let m=0,V=D?D.times.length:ce;m<V;m++){ae(),Ge="frame";const k=D?D.times[m]:m/j,p=le(k);U.clear(D?0:1);const I=p&&Xe?$o(l,p.start+1e-5,e):void 0,S=I&&p?jo(p.visuals,I.captionStyle?.layerTrack):-1,re=async()=>{const me=I&&p&&await ie(I,p,m);me&&(U.shadow([]),U.edge(null),U.windows(null),U.matte(null),U.mode(void 0),U.key(null),U.grade(null,null),U.draw(me,ye,ye,1,1,!1,null,[]))};for(const[me,q]of(p?.visuals??[]).entries()){let i=q;if(me===S&&await re(),i.kind==="audio")continue;const X=p?no(i,p.start,p.start+p.duration):null,pe=X?i._txIn===X?"b":"a":null,Ye=X?Ho(X,k):0;e:{if(i.kind==="model"){U.matte(null),U.edge(null),U.windows(null),U.mode(void 0),U.shadow(so(i,h)),U.key(null),U.grade(null,null);const F=await Je(i,k);F&&U.draw(F,ye,ye,1,1,!1,null,[]);break e}const Te=k-i.start,Ke=Zt(i,Te,h,_),J=(Vo(i)||Yo(i))&&!X&&!(H&&Ht(i))&&!i.pin?He(i,p,k,Ke):Ke;if(!(J.opacity>1e-4))break e;if(ro(i)){U.adjust(ct(i),T(i,p,m),Math.min(1,J.opacity));break e}let P=null,Pe=null;if($t(i)||i._group)P=await Je(i,k);else if(i.kind==="image")P=Ae.get(i.url)??null;else if(i.kind==="video"){const F=await Eo(Ue,Ze,i,k,j,p.start,p.duration);F&&(Pe=F.toVideoFrame(),P={source:Pe,w:F.displayWidth,h:F.displayHeight,bt709:Pe.colorSpace?.matrix?Pe.colorSpace.matrix==="bt709":F.displayHeight>=720})}if(!P)break e;if(Ko(i)){const F=i.crop||{left:0,right:0,top:0,bottom:0},ne=Math.floor(P.w*F.left/2)*2,fe=Math.floor(P.h*F.top/2)*2,xe=Math.max(2,Math.floor(P.w*(1-F.left-F.right)/2)*2),de=Math.max(2,Math.floor(P.h*(1-F.top-F.bottom)/2)*2),Ie=i.distort.displace?await yt(i.distort.displace.map,k,p):null;ot??=ur();const r=ot.render({source:P.source,srcW:P.w,srcH:P.h,rect:[ne,fe,xe,de],outW:xe,outH:de,distort:i.distort,local:Te,map:Ie?.source??null,matte:Ee&&(i.mask||i.person)?Ee.matteCanvas(i,Te,lt,!1,l):null});Ie?.close?.(),P={source:r,w:xe,h:de,bt709:P.bt709},i={...i,crop:void 0,mask:void 0,person:void 0}}if(Ee&&(i.mask||i.person)){const F=i.crop||{left:0,right:0,top:0,bottom:0},ne=Math.max(2,Math.floor(P.w*(1-F.left-F.right)/2)*2),fe=Math.max(2,Math.floor(P.h*(1-F.top-F.bottom)/2)*2);U.matte(Ee.matteCanvas(i,Te,lt,!1,l),[F.left,F.top,ne/P.w,fe/P.h])}else U.matte(null);U.mode(i.blend),U.key(i.key),U.shadow(so(i,h));{const F=i.colorBypass?[]:qt(i.grade).filter(Jt);U.windows(F.length?{key:`${i.id}@${m}`,list:qt(i.grade),clip:i.id,src:i,frame:Math.round((k-i.start)*j),local:Math.round((k-i.start)*j)/j}:null)}if(co(i)&&lo(fo(i),Te)>.001){const F=fo(i),ne=Ee&&(i.mask||i.person),fe=i.crop||{left:0,right:0,top:0,bottom:0},xe=ne?Math.max(2,Math.floor(ne.mw*(1-fe.left-fe.right)/2)*2):P.w,de=ne?Math.max(2,Math.floor(ne.mh*(1-fe.top-fe.bottom)/2)*2):P.h,Ie=xe>=de?Vt:Math.max(8,Math.trunc(Vt*xe/de/8)*8),r=xe>=de?Math.max(8,Math.trunc(Vt*de/xe/8)*8):Vt,s=Wo(F),t=lo(F,Te),c=!!F.keys?.length||F.amount<.999;U.edge({key:`${i.id}@${m}`,ew:Ie,eh:r,band:s.band,glow:s.glow,k:F.glow,col:[1,3,5].map(E=>parseInt(F.color.slice(E,E+2),16)/255),am:c?Math.trunc(255*t):255,harden:!!ne})}else U.edge(null);{const F=i.grade&&!i.colorBypass?Ve(i):null;U.grade(F?.l1??null,F?.l3??null)}if(i.pin&&!(H&&Ht(i))&&p&&uo(i,l,p.start,h,_,H)){const F=uo(i,l,k,h,_,H)??[[0,0],[0,0],[0,0],[0,0]],ne=Pt(i,Te),fe=Qo(i,l,h,_,H),xe=i.pin.dive,de=fe&&!i.pin.scene?[+(fe[0]*h).toFixed(3),+(fe[1]*_).toFixed(3),xe?Math.max(0,Math.min(1,(k-xe.at)/xe.dur)):0]:null;U.warp(P,Bt([0,0,1,1],h,_),bo(i,P.w,P.h),Math.min(1,J.opacity),ne.k,ne.white,ct(i),T(i,p,m),Lt(F,h,_),de),Pe?.close();break e}const We=Zo(i,"rot")||Jo(i),Mt=()=>i.motionBlur?Ji(k,j).map(F=>({...Zt(i,F-i.start,h,_),rot:J.rot,opacity:J.opacity})):[J];if((We||Math.abs(J.rot||0)>1e-9)&&!(H&&Ht(i))){const F=Pt(i,Te),ne=X&&pe?[...yo(X.spec[pe],Ye,h,_,k,X.spec.zoomAt),...pe==="b"&&X.spec.mask?[To(X.spec.mask,Ye)]:[]]:[];i.motionBlur&&U.blurBegin();for(const fe of Mt()){const xe=er(i,P.w,P.h,h,_,fe,We);U.warp(P,Bt([0,0,1,1],h,_),bo(i,P.w,P.h),Math.min(1,J.opacity),F.k,F.white,ct(i),[],Lt(xe.quad,h,_),null,xe.clip,ne)}i.motionBlur&&U.blurEnd(),Pe?.close();break e}if(H&&Ht(i)){const F=ei(i,Te,H,k,h,_);if(F){const ne=Nt(i,P.w,P.h,h,_,{x:0,y:0,zoom:1}),fe=Pt(i,Te),xe=T(i,p,m);let de=Ct.get(i.id);de===void 0&&(de=i.effects?.some(r=>!r.off)||i.mask||i.person||co(i)||!i.colorBypass&&qt(i.grade).some(Jt)?1:ti(oi(i,H,h,_),P.w,P.h,h,_),Ct.set(i.id,de));const Ie=Et(i,p,m);de>1&&!xe.length?U.warpBig(P,Bt(ne.dst,h,_),ne.src,Math.min(1,J.opacity),fe.k,fe.white,ct(i),F.quad,de,Ie):U.warp(P,Bt(ne.dst,h,_),ne.src,Math.min(1,J.opacity),fe.k,fe.white,ct(i),xe,Lt(F.quad,h,_),null,null,Ie)}Pe?.close();break e}if(i.motionBlur&&!X&&!T(i,p,m).length){const F=Pt(i,Te);U.blurBegin();for(const ne of Mt()){const fe=Nt(i,P.w,P.h,h,_,ne);U.draw(P,fe.dst,fe.src,Math.min(1,J.opacity),F.k,F.white,ct(i),[])}U.blurEnd(),Pe?.close();break e}const{dst:St,src:Dt}=Nt(i,P.w,P.h,h,_,J),at=Pt(i,Te),xt=[...T(i,p,m),...X&&pe?yo(X.spec[pe],Ye,h,_,k,X.spec.zoomAt):[],...X&&pe==="b"&&X.spec.mask?[To(X.spec.mask,Ye)]:[]],kt=X&&pe?X.spec[pe]?.rot:null;if(kt){const F=Yt(kt,Ye)??0;U.warp(P,Bt([0,0,1,1],h,_),Dt,Math.min(1,J.opacity),at.k,at.white,ct(i),[],Lt(tr(St,h,_,F),h,_),null,null,xt),Pe?.close();break e}if(xt.length>0&&!!p&&!i.layout&&!no(i,p.start,p.start+p.duration)&&ii(i,p.start,p.start+p.duration,h,_)){const F=Nt(i,P.w,P.h,h,_,{x:0,y:0,zoom:1}),ne=Nt({},h,_,h,_,J);U.draw(P,ne.dst,F.src,Math.min(1,J.opacity),at.k,at.white,ct(i),xt,F.dst)}else U.draw(P,St,Dt,Math.min(1,J.opacity),at.k,at.white,ct(i),xt);Pe?.close()}if(X&&pe==="b"){if(X.spec.light){const Ke=Math.max(2,Math.ceil(h/mo)),J=Math.max(2,Math.ceil(_/mo));U.overlay(null,{data:ri(X.spec,Ye,Ke,J),w:Ke,h:J})}const Te=X.spec.flash;if(Te){const Ke=Yt(Te.opacity,Ye)??0;if(Ke>1e-4){const J=parseInt(Te.color.slice(1),16);U.overlay([(J>>16&255)/255,(J>>8&255)/255,(J&255)/255,Math.min(1,Ke)],null)}}}}S>=0&&S>=(p?.visuals.length??0)&&await re();for(const[me,q]of Ue){const i=me.split(`
189
- `)[0],X=be.find(pe=>pe.id===i);(!X||k>X.start+X.duration+1)&&(q.current?.close(),q.peek?.close(),await q.iterator.return?.(),Ue.delete(me))}if(D){await Kt(m);continue}Ge="video encode",await Oe.add(k,1/j),B?.(.9*(m+1)/ce)}if(D)return{blob:new Blob,ms:{titles:0,video:0,audio:0,total:Math.round(performance.now()-K)}};const n=performance.now();Ge="audio";const x=new Map(be.map(m=>[m.id,m])),C=await va(l.map(m=>x.get(m.id)??m),Y,ge,e,ft,v);typeof y.loudness=="number"&&or([C.getChannelData(0),C.getChannelData(1)],y.loudness,It),Ge="audio encode",await rt.add(C),ze=performance.now()-n,Oe.close(),rt.close(),Ge="finalize",await ke.finalize()}catch(n){throw await ke.cancel().catch(()=>{}),we&&await we.dir.removeEntry(we.name).catch(()=>{}),n}finally{for(const n of Ue.values())n.current?.close(),n.peek?.close();ot?.dispose();for(const n of Ae.values())n.close?.();for(const n of $e.values())n.pic?.close?.();for(const n of Le.values())n.close?.();for(const n of Qe.values())n.dispose?.()}B?.(1),Ge="file";const Ot=we?await we.handle.getFile():new Blob([it.buffer],{type:De?"video/quicktime":"video/mp4"});we&&setTimeout(()=>void we.dir.removeEntry(we.name).catch(()=>{}),600*1e3);const zt=performance.now()-K;return{blob:Ot,ms:{titles:Math.round(Fe-K),video:Math.round(zt-(Fe-K)-ze),audio:Math.round(ze),total:Math.round(zt)}}}function da(d,y,w,e,O){const v=[new Float32Array(Math.max(1,Math.round(O*w))),new Float32Array(Math.max(1,Math.round(O*w)))],B=Math.round(ki*w);return y.forEach((D,oe)=>{if(D.silent)return;const K=Math.round((D.t1-D.t0)*w)+(oe<y.length-1?B:0),h=Math.abs(D.rate),_=Math.round(D.t0*w),j=Math.max(0,Math.round(((D.rate>0?D.s0:D.s0-h*K/w)-e)*w)),l=Math.min(d[0].length,Math.round(((D.rate>0?D.s0+h*K/w:D.s0)-e)*w));if(l-j<2)return;const be=(l-j)/K,ge=Math.round(.06*w),ce=Math.max(0,j-ge),H=Math.min(d[0].length,l+ge);let Y=d.map(ae=>ae.slice(ce,H));D.rate<0&&Y.forEach(ae=>ae.reverse());const le=Math.round((D.rate<0?H-l:j-ce)/be);Y=Ao(Y,be,w).map(ae=>ae.subarray(le,le+K));for(let ae=0;ae<2;ae++)for(let Z=0;Z<K&&_+Z<v[ae].length;Z++){const Se=(oe>0&&Z<B?Z/B:1)*(oe<y.length-1&&Z>=K-B?(K-Z)/B:1);v[ae][_+Z]+=(Y[ae][Z]??0)*Se}}),v}async function va(d,y,w,e,O,v){const B=new OfflineAudioContext({numberOfChannels:2,length:Math.max(1,Math.round(w*It)),sampleRate:It}),D=1/200,oe=d.filter(l=>(l.kind==="video"||l.kind==="audio")&&!l.freeze&&!_o(l)&&(l.volume??1)>0),K=l=>(l.kind==="video"||l.kind==="audio")&&!!l.url,h=new Map;for(const l of y.flatMap(be=>be.audios))!K(l)||h.has(l.url)||h.set(l.url,await O(l.url).getPrimaryAudioTrack().then(be=>!!be,()=>!1));const _=l=>K(l)&&!!h.get(l.url);for(const l of oe){if(v?.aborted)throw new DOMException("Export cancelled","AbortError");const be=Math.max(2,Math.ceil(l.duration/D)+1),ge=new Float32Array(be);let ce=!1;const H=Fi(l.track,e);for(let ie=0;ie<be;ie++){const ye=l.start+Math.min(l.duration,ie*D),ut=y.find(He=>ye>=He.start-1e-6&&ye<He.start+He.duration-1e-6),mt=ut?.audios.some(He=>He.id===l.id)?Ai(l,ye-l.start)*H.gain/Mi(ut.audios,_):0;ge[ie]=mt,mt>0&&(ce=!0)}if(!ce)continue;const Y=await O(l.url).getPrimaryAudioTrack();if(!Y)continue;const le=Ro(l)?Si(l,0,l.duration):null,ae=l.playbackRate||1,Z=new hr(Y),Se=le?le.flatMap(ie=>[ie.s0,ie.s1]):[],Fe=le?Math.max(0,Math.min(...Se)-.2):l.inPoint||0,qe=le?Math.max(...Se)+.2:Fe+l.duration*ae,Ee=[];let lt=Fe;for await(const ie of Z.samples(Fe,qe))Ee.length||(lt=ie.timestamp),Ee.push(ie.toAudioBuffer()),ie.close();if(!Ee.length)continue;const Qe=Ee[0].sampleRate,Ze=Ee.reduce((ie,ye)=>ie+ye.length,0);let Ae=[new Float32Array(Ze),new Float32Array(Ze)],ft=0;for(const ie of Ee){for(let ye=0;ye<2;ye++)Ae[ye].set(ie.getChannelData(Math.min(ye,ie.numberOfChannels-1)),ft);ft+=ie.length}le?Ae=da(Ae,le,Qe,lt,l.duration):ae!==1&&(Ae=Ao(Ae,ae,Qe));const $e=B.createBuffer(2,Ae[0].length,Qe);for(let ie=0;ie<2;ie++)$e.copyToChannel(Ae[ie],ie);const Je=B.createBufferSource();Je.buffer=$e;const je=B.createGain();je.gain.value=0,je.gain.setValueCurveAtTime(ge,l.start,Math.max(D,l.duration));const Xe=B.createChannelSplitter(2),Ne=B.createChannelMerger(2),Le=B.createGain(),et=B.createGain();Le.gain.value=H.left,et.gain.value=H.right,Je.connect(je),je.connect(Xe),Xe.connect(Le,0),Xe.connect(et,1),Le.connect(Ne,0,0),et.connect(Ne,0,1),Ne.connect(B.destination),Je.start(l.start,le?0:Math.max(0,Fe-lt)/ae,l.duration)}const j=await B.startRendering();return ir([j.getChannelData(0),j.getChannelData(1)]),j}export{ka as canEncodeHevc,Da as canEncodeMp4,xa as exportOnGpu,Fo as gpuBitrate,Pa as gpuExportStage,Ua as gpuExportSupported};
@@ -1 +0,0 @@
1
- import{a8 as kt,a9 as Ft}from"./main-BNZrzSIG.js";import{iX as K,iY as jt}from"./remote-DXG553d8.js";import"./titleFrameBudget-BjW--v_T.js";import"./api-C5pOWyBM.js";import"./store-Dxq3MZF3.js";import"./three.module-Bx43vjkH.js";import"./spark.module-CMSPLU2n.js";import"./GLTFLoader-Dy6SrZg8.js";import"./rotoMaskStore-DrRawyH9.js";import"./rigTrack-CW9_kg5j.js";import"./userFonts-txN4I-eo.js";import"./lottieLayer-BhLbZOpr.js";import"./desktop-BWhFnYwd.js";import"./timeline3d-DqXTKdEK.js";import"./RoomEnvironment-Dmv_G5ka.js";import"./exportEncode-pFxeatJt.js";import"./captionLayout-BAdmqwdS.js";import"./timelineText-DEK2BRyU.js";import"./titleArt-CAOxtyHl.js";import"./rotoMatte-2EcyuvBX.js";import"./distortGL-5uNfls9s.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 Q(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)),M=Math.max(0,Math.floor(Math.min(t[1],n[1])-g)),p=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=M;m<=p;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 M of t)M[1]<y&&(y=M[1]),M[1]>a&&(a=M[1]);y=Math.max(0,Math.floor(y)),a=Math.min(g-1,Math.ceil(a));const e=[];for(let M=y;M<=a;M++){const p=M+.5;e.length=0;for(let i=0,f=d-1;i<d;f=i++){const c=t[f],m=t[i];(c[1]<=p&&m[1]>p||m[1]<=p&&c[1]>p)&&e.push([c[0]+(p-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=M*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 M=0;for(let p=0;p<t;p++)M+=y[e*t+p],a[(e+1)*A+p+1]=a[e*A+p+1]+M}return a});return(y,a,e)=>{const M=d[y],p=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 M[f*A+U]-M[i*A+U]-M[f*A+p]+M[i*A+p]}}function Jt(l,t,n,g,A={}){const{learned:d=null,...y}=A,a={...dt,...y},e=t*n,M=new Uint8Array(e),p=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(M,m(K(r.lm,t,n,{edge:r.edge?r.edge.map(x=>Math.min(0,x)):null,scale:a.core})),t,n),W(i,m(K(r.lm,t,n,{edge:r.edge})),t,n),W(p,m(K(r.lm,t,n,{edge:r.edge,grow:a.band})),t,n),W(U,m(K(r.lm,t,n,{edge:r.edge,grow:a.ring})),t,n);const h=K(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)Q(r,s[P],s[L],.45*F,t,n),Q(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 J=[s[0][0]+k[0]*Math.max(t,n)*1.5,s[0][1]+k[1]*Math.max(t,n)*1.5];Q(r,s[0],J,1.6*F,t,n),Q(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)Q(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],J=u*4,P=[l[J],l[J+1],l[J+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)},Z=d,G=new Uint8Array(e),[O,v]=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]?v:Ut;if(Z[u]<s)continue;const k=Math.max(0,Math.min(1,(Z[u]-s)/(F-s)))*Y(u);G[u]=Math.round(255*k*k*(3-2*k))}return Mt(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(M[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]&&!p[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))),X=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(!p[x]&&!(d&&U[x]&&!f[x]&&d[x]>.3))continue;if(nt[x]=1,M[x]){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[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]],v=O[0]*O[0]+O[1]*O[1]+O[2]*O[2];C=Math.min(C,Math.sqrt(v)),!(v<1)&&(q=Math.max(q,((T[0]-S[0])*O[0]+(T[1]-S[1])*O[1]+(T[2]-S[2])*O[2])/v))}const E=d&&!f[x]?d[x]:null;if(C<a.sep){X[x]=E??i[x]/255;continue}const Y=Math.max(0,Math.min(1,(q-a.lo)/(a.hi-a.lo))),Z=Y*Y*(3-2*Y);X[x]=E===null?Z:E*Z}const xt=kt(X,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(M[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 Mt(ot,t,n,{snapped:i,band:nt,core:M,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 pt(l,t,n,g,A,d,y){const a=2*d+1,e=new Uint8Array(n+a),M=new Uint8Array(n+a),p=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]=p(f);for(let m=f+1;m<c;m++)e[m]=i(e[m-1],p(m));M[c-1]=p(c-1);for(let m=c-2;m>=f;m--)M[m]=i(M[m+1],p(m))}for(let f=0;f<n;f++)t[g+f*A]=i(M[f],e[f+2*d]??e[U-1])}function V(l,t,n,g,A){const d=new Uint8Array(l.length),y=new Uint8Array(l.length);for(let a=0;a<n;a++)pt(l,d,t,a*t,1,g,A);for(let a=0;a<t;a++)pt(d,y,n,a,t,g,A);return y}function Mt(l,t,n,{snapped:g,band:A,core:d,arm:y,r:a,rArm:e,small:M}){const p=t*n,U=new Uint8Array(p);for(let o=0;o<p;o++)U[o]=l[o]>=128?255:0;const i=V(V(U,t,n,a,!0),t,n,a,!1),f=V(V(U,t,n,e,!0),t,n,e,!1);for(let o=0;o<p;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,M,y);const c=new Uint8Array(p),m=[];for(let o=0;o<p;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<p-t&&m.push(o+t)}for(let o=0;o<p;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 M=(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)}};M(-1);for(let i=0,f=1;i<y;i++){if(a[i]||l[i]>=128)continue;const c=[];e.push(i),M(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 p=new Uint8Array(y);for(let i=0;i<y;i++)p[i]=a[i]===-1||a[i]>0&&l[i]<128?255:0;const U=V(p,t,n,2,!0);for(let i=0;i<y;i++)l[i]&&l[i]<255&&!U[i]&&(l[i]=255);return l}function Kt(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,Q as fillCapsule,W as fillPolygon,Jt as handMatteFrame,Kt as handMatteSize};
@@ -1,2 +0,0 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/main-BNZrzSIG.js","assets/titleFrameBudget-BjW--v_T.js","assets/remote-DXG553d8.js","assets/api-C5pOWyBM.js","assets/three.module-Bx43vjkH.js","assets/GLTFLoader-Dy6SrZg8.js","assets/store-Dxq3MZF3.js","assets/rotoMaskStore-DrRawyH9.js","assets/rigTrack-CW9_kg5j.js","assets/spark.module-CMSPLU2n.js","assets/userFonts-txN4I-eo.js","assets/lottieLayer-BhLbZOpr.js","assets/desktop-BWhFnYwd.js","assets/timeline3d-DqXTKdEK.js","assets/RoomEnvironment-Dmv_G5ka.js","assets/exportEncode-pFxeatJt.js","assets/captionLayout-BAdmqwdS.js","assets/timelineText-DEK2BRyU.js","assets/titleArt-CAOxtyHl.js","assets/rotoMatte-2EcyuvBX.js","assets/distortGL-5uNfls9s.js","assets/main-By_IEoB_.css","assets/handMatte-DZCsuqD2.js","assets/matteFixRun-wTHGiGGf.js"])))=>i.map(i=>d[i]);
2
- import{b$ as X,_ as N,a7 as Z,bY as tt}from"./titleFrameBudget-BjW--v_T.js";import{u as W}from"./store-Dxq3MZF3.js";import{t as j}from"./api-C5pOWyBM.js";import{a4 as et,a5 as at,a6 as nt,a3 as Y,a7 as ot}from"./main-BNZrzSIG.js";import{iP as it,iQ as rt,iR as J,iS as st,iT as ct,iU as K,iJ as lt,be as z,iK as dt,iV as mt,iW as ut}from"./remote-DXG553d8.js";import{handMatteSize as ht,handMatteFrame as ft}from"./handMatte-DZCsuqD2.js";import"./three.module-Bx43vjkH.js";import"./spark.module-CMSPLU2n.js";import"./GLTFLoader-Dy6SrZg8.js";import"./rotoMaskStore-DrRawyH9.js";import"./rigTrack-CW9_kg5j.js";import"./userFonts-txN4I-eo.js";import"./lottieLayer-BhLbZOpr.js";import"./desktop-BWhFnYwd.js";import"./timeline3d-DqXTKdEK.js";import"./RoomEnvironment-Dmv_G5ka.js";import"./exportEncode-pFxeatJt.js";import"./captionLayout-BAdmqwdS.js";import"./timelineText-DEK2BRyU.js";import"./titleArt-CAOxtyHl.js";import"./rotoMatte-2EcyuvBX.js";import"./distortGL-5uNfls9s.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@${Y}/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:R}=await yt(),u=Object.assign(document.createElement("video"),{muted:!0,playsInline:!0,preload:"auto",crossOrigin:"anonymous"});u.src=w;try{await new Promise((r,h)=>{u.onloadeddata=()=>r(),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)),i=Object.assign(document.createElement("canvas"),{width:_,height:o}),y=i.getContext("2d",{willReadFrequently:!0}),E=z(d,a),T=[];let n=[null,null];for(let r=0;r<v;r++){if(c?.aborted)throw new DOMException("Đã huỷ","AbortError");const h=Math.max(0,Math.min(u.duration-1/60,E+r/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(i,(r+1)*1e3/m).filter(t=>Array.isArray(t.lm)&&t.lm.length>=21).slice(0,2),k=[null,null],C=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&&C(S[0])===C(S[1])){const t=S[0],e=S[1],l=M(t,0)+M(e,1)<=M(t,1)+M(e,0),[F,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:F.lm.map(I=>[I[0],I[1]]),score:F.score},k[1]={lm:A.lm.map(I=>[I[0],I[1]]),score:A.score}}else for(const t of S){let e=C(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,F)=>{const A=(Math.max(0,Math.min(o-1,F))*_+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 F=mt(l.lm,_,o,e);F&&(l.edge=F)}}T.push(k),n=[k[0]??n[0],k[1]??n[1]],s?.(r+1,v)}return ut({mw:x,mh:H,fps:m,s0:E,frames:T})}finally{u.removeAttribute("src"),u.load(),R()}}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:R}=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@${Y}/wasm`),x=await R.createFromOptions(u,{baseOptions:{modelAssetPath:ot,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 R=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[R+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("./main-BNZrzSIG.js").then(i=>i.aF);return{objectProbability:o}},__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21])),m=new Float32Array(c*s),v=512;G??=Object.assign(document.createElement("canvas"),{width:v,height:v});const p=G.getContext("2d",{willReadFrequently:!0}),R=async(o,i,y,E,T)=>{p.fillStyle="#000",p.fillRect(0,0,v,v),p.drawImage(d,o,i,y,E,0,0,v,v);const n=await b(G,T.map(h=>({x:(h.x-o)/y,y:(h.y-i)/E})).filter(h=>h.x>0&&h.x<1&&h.y>0&&h.y<1)),r=new Float32Array(c*s);for(let h=0;h<s;h++){const S=((h+.5)/s*a-i)/E;if(S<0||S>=1)continue;const k=Math.floor(S*n.height)*n.width;for(let C=0;C<c;C++){const M=((C+.5)/c*w-o)/y;M<0||M>=1||(r[h*c+C]=n.data[k+Math.floor(M*n.width)])}}return r},{fillCapsule:u,fillPolygon:x}=await N(async()=>{const{fillCapsule:o,fillPolygon:i}=await import("./handMatte-DZCsuqD2.js");return{fillCapsule:o,fillPolygon:i}},__vite__mapDeps([22,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21])),H=[],_=await xt(d,c,s);for(const{lm:o}of f){const i=o.map(t=>t[0]*w),y=o.map(t=>t[1]*a),E=Math.hypot(i[0]-i[9],y[0]-y[9])||1,T=kt.map(t=>({x:i[t],y:y[t]}));T.push({x:i[0]+(i[0]-i[9])*.6,y:y[0]+(y[0]-y[9])*.6});const r=await R(...((t,e,l,F=1)=>{const A=Math.min(...t)-l,I=Math.max(...t)+l,O=Math.min(...e)-l,g=Math.max(...e)+l,P=Math.max(I-A,g-O),D=Math.min(w,Math.max(I-A,P/F)),V=Math.min(a,Math.max(g-O,P/F)),L=Math.min(D,V*F),U=Math.min(V,D*F);return[Math.max(0,Math.min(w-L,(A+I)/2-L/2)),Math.max(0,Math.min(a-U,(O+g)/2-U/2)),L,U]})([...i,i[0]+(i[0]-i[9])*3],[...y,y[0]+(y[0]-y[9])*3],.6*E),T);let h=(i[0]-i[9])/E,S=(y[0]-y[9])/E;{const t=i[0]/w*c,e=y[0]/a*s,l=E/w*c;let F=0,A=0,I=0;for(let O=0;O<s;O++)for(let g=0;g<c;g++){if(r[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||(F+=g,A+=O,I++)}if(I>20){const O=F/I-t,g=A/I-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),C=i.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,C[t],C[e],.35*M,c,s);x(k,[0,1,5,9,13,17].map(t=>C[t]),c,s);for(let t=0;t<c*s;t++){const e=k[t]?Math.max(r[t],_[t]*.5):_[t];e>m[t]&&(m[t]=e)}}return{map:m,armDirs:H}}async function Q({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=lt(d.hands),R=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:i}=ht(H,_),y=Object.assign(document.createElement("canvas"),{width:o,height:i}),E=y.getContext("2d",{willReadFrequently:!0}),T=z(d,a),n=Math.max(1,Math.min(K.maxFrames,Math.round(f*R*u)+1)),r=z(d,c),h=et({mw:H,mh:_,w:o,h:i,fps:u,s0:T},32),S=at(t=>h.push(t)),k=s?await Z(s):null,C=nt(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>r+1e-6){S.push(new Uint8Array(o*i)),v?.(t+1,n);continue}const l=await C(Math.max(0,Math.min(x.duration-1/60,e)));E.drawImage(l,0,0,o,i);const F=Math.max(0,Math.min(p.n-1,Math.round((e-p.s0)*u))),A=[0,1].map(g=>{const P=dt(p,e,g);return P?{lm:P,edge:p.frames[F][g]?.edge??null}:null}).filter(Boolean);let I=null;if(M&&A.length)try{const g=await bt(l,H,_,A,o,i);I=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?ft(E.getImageData(0,0,o,i).data,o,i,A,{learned:I}):new Uint8Array(o*i);if(k&&s){const g=tt(k,s,e),P=s.w,D=s.h,V=new Uint8Array(o*i);for(let L=0;L<i;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/i))*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(ct(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 Gt(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}=X(c.timelineFormat);if(a.mode==="attach"){const n=c.clips.find(r=>r.id===d.id)??d;return it(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,r=c.clips.find(e=>e.id===f.id)??f,h=n.mask,S=rt(n,r,{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),C=document.querySelector(`video[data-clip-media="${r.id}"]`)?.currentSrc||r.url;let M=null;if(k)try{M=await Q({clip:r,url:C,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:J({...k,hands:r.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(r=>r.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,R=m.clips.find(n=>n.id===f.id)??f;if(!v)throw Error(j("Không còn tường HUD"));const u=st({wall:v,layer:p,src:R,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="${R.id}"]`)?.currentSrc||R.url,_=(a.matte?m.clips.find(n=>n.id===a.matte)?.person:null)??x?.person??null;let o=null;if(x)try{o=await Q({clip:R,url:H,from:a.from??0,duration:a.duration??d.duration,until:u.cutoutUntil,refine:_})}catch(n){console.warn("hand matte",n)}const i=x?.matteFix?.fixes??[],y=o;if(o&&i.length)try{const{fixedMatte:n}=await N(async()=>{const{fixedMatte:r}=await import("./matteFixRun-wTHGiGGf.js");return{fixedMatte:r}},__vite__mapDeps([23,6,1,3,0,2,4,5,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22]));o=await n(o,i,R.hands)}catch(n){console.warn("hand touch-ups",n)}const E=o?void 0:J(R,{until:u.cutoutUntil}),T=n=>{const r=n.mask?.masks?.find(h=>h.id==="wall");return!r||!n.mask?n:o?{...n,person:o,mask:{...n.mask,masks:[{...r,mode:"add"}]}}:E?{...n,mask:{...E,masks:[...E.masks,{...r,mode:"intersect"}]}}:n};return W.setState(n=>({clips:n.clips.map(r=>r.id===v.id?{...r,motion:u.wall}:r.id===a.cutout?o?{...r,person:o,mask:void 0,...i.length?{matteFix:{auto:y,fixes:i}}:{}}:E?{...r,mask:E}:r:r.id===a.shadow?T(r):r)})),{motion:u.grab}}export{pt as HAND_MODEL_URL,Q as buildHandMatte,bt as learnedHands,Gt as runHandTrack,Mt as trackHands};
@@ -1,5 +0,0 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/rotoMaskStore-DrRawyH9.js","assets/titleFrameBudget-BjW--v_T.js","assets/api-C5pOWyBM.js","assets/timeline3dExport-MWomW4fF.js","assets/timeline3d-DqXTKdEK.js","assets/three.module-Bx43vjkH.js","assets/GLTFLoader-Dy6SrZg8.js","assets/RoomEnvironment-Dmv_G5ka.js","assets/frameSink-CB1EghW0.js","assets/titleFrames-WfiLHzjf.js","assets/titleArt-CAOxtyHl.js","assets/rigTrack-CW9_kg5j.js","assets/lottieLayer-BhLbZOpr.js","assets/rotoMatte-2EcyuvBX.js","assets/store-Dxq3MZF3.js","assets/windowFrames-DydW5Al5.js"])))=>i.map(i=>d[i]);
2
- import{_ as d,b$ as E,iM as v}from"./titleFrameBudget-BjW--v_T.js";import{FrameSink as g,SKIPPED_FRAME as D}from"./frameSink-CB1EghW0.js";class M extends g{want;next=new Map;last=new Map;out={};constructor(r){super({put:async()=>{throw Error("a pick sink keeps its frames")}}),this.want=new Map;for(const[o,t]of Object.entries(r))for(const[s,n]of Object.entries(t||{}))this.want.set(`${o}
3
- ${s}`,new Set(n));this.wants=(o,t,s)=>{const n=this.want.get(`${o}
4
- ${t}`);return!!n&&(s===void 0||n.has(s))}}async push(r,o,t){const s=`${r}
5
- ${o}`,n=this.next.get(s)??0;if(this.next.set(s,n+1),t===D)return;const a=t==="="?this.last.get(s):t;a!==void 0&&(this.last.set(s,a),this.want.get(s)?.has(n)&&(((this.out[r]??={})[o]??={})[n]=a))}picked(){return this.out}}const l=(i,r)=>Object.keys(i[r]||{}).length>0,O={async frames({clips:i,format:r,camera:o=null,want:t}){const{unpackMasks:s}=await d(async()=>{const{unpackMasks:e}=await import("./rotoMaskStore-DrRawyH9.js").then(c=>c.X);return{unpackMasks:e}},__vite__mapDeps([0,1,2])),n=await s(i);i=n.clips;const a=new M(t),h={},F=E(r).fps,f=a.wants,_=async(e,c,m)=>{for(const k of c){a.wants=(w,p,y)=>w===e&&p===k&&f(w,p,y);try{await m()}catch(w){h[k]=String(w?.message||w).slice(0,200)}finally{a.wants=f}}},u=e=>Object.keys(t[e]||{});if(l(t,"modelFrames")){const{render3DFrames:e}=await d(async()=>{const{render3DFrames:c}=await import("./timeline3dExport-MWomW4fF.js");return{render3DFrames:c}},__vite__mapDeps([3,1,4,5,6,2,7,8]));await _("modelFrames",u("modelFrames"),()=>e(i,r,a,void 0,o))}if(l(t,"titleFrames")){const{renderTitleFrames:e}=await d(async()=>{const{renderTitleFrames:m}=await import("./titleFrames-WfiLHzjf.js");return{renderTitleFrames:m}},__vite__mapDeps([9,1,10,11,12,2,8])),c=[...i,...v(i)];await _("titleFrames",u("titleFrames"),()=>e(c,r,a,void 0,o))}if(l(t,"matteFrames")){const e=await d(()=>import("./rotoMatte-2EcyuvBX.js").then(m=>m.r),__vite__mapDeps([13,1,2,14])),c=[...i,...e.maskedCopies(i)];await _("matteFrames",u("matteFrames"),()=>e.renderMatteFrames(c,F,a))}if(l(t,"windowFrames")){const e=await d(()=>import("./windowFrames-DydW5Al5.js"),__vite__mapDeps([15,1,13,2,14]));await _("windowFrames",u("windowFrames"),()=>e.renderWindowFrames(i,F,a))}return{frames:a.picked(),failed:h,missingMasks:n.missing}}};window.__layerWorker=O;
@@ -1 +0,0 @@
1
- import{gJ as l}from"./remote-DXG553d8.js";import{ik as h,hE as j,il as k,im as E}from"./remote-DXG553d8.js";import{e as f}from"./skin-BQG1Iz6Q.js";import"./api-C5pOWyBM.js";import"./titleFrameBudget-BjW--v_T.js";import"./three.module-Bx43vjkH.js";import"./GLTFLoader-Dy6SrZg8.js";import"./store-Dxq3MZF3.js";import"./rotoMaskStore-DrRawyH9.js";import"./rigTrack-CW9_kg5j.js";async function D(o,s,a,m=2e4){let i;for(const t=Date.now()+m;!i&&Date.now()<t;){const e=o.getStage().items.find(r=>r.id===s);if(!e||e.rig!==a)return!1;i=o.engine()?.objects?.children.find(r=>r.userData.id===s)?.children[0],i||await new Promise(r=>setTimeout(r,150))}if(!i)return!1;const p=l(a,{positions:f(i).positions});let n=!1;return o.setStage(t=>({...t,items:t.items.map(e=>e.id===s&&e.rig===a?(n=!0,{...e,rig:p}):e)})),n}export{D as fitLibraryFingers,h as libraryModelFields,j as libraryModelItem,k as libraryRig,E as wantsFingers};