clipoox-render 0.4.6 → 0.4.8

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 (142) hide show
  1. package/package.json +2 -2
  2. package/scripts/render-local.mjs +2656 -1672
  3. package/shared/photocraft/LICENSE.txt +206 -0
  4. package/shared/photocraft/clipoox_photo.js +396 -0
  5. package/shared/photocraft/clipoox_photo_bg.wasm +0 -0
  6. package/web/assets/{FxEmbed-ROS6C_HI.js → FxEmbed-adbxHEBi.js} +1 -1
  7. package/web/assets/ImageStudio-CMxiT1jp.js +3 -0
  8. package/web/assets/ImageStudio-De_DCTrz.css +1 -0
  9. package/web/assets/{MotionEmbed-E2hCysi-.js → MotionEmbed-CDUIyjk0.js} +1 -1
  10. package/web/assets/{PluginStore-CwUSpwPp.js → PluginStore-By_pdOOg.js} +2 -2
  11. package/web/assets/ShotComposer-DcwWZ-eP.css +1 -0
  12. package/web/assets/ShotComposer-XIbJ4nNm.js +287 -0
  13. package/web/assets/{TemplateEmbed-qG1AXdtf.js → TemplateEmbed-a01nKECT.js} +1 -1
  14. package/web/assets/{TimelinePlugins-CB1b6-Cb.js → TimelinePlugins-CqLMVjuh.js} +4 -4
  15. package/web/assets/TimelineShotFx-QmkyCg31.js +2 -0
  16. package/web/assets/{TransitionEmbed-Dym9P7--.js → TransitionEmbed-Cbwlxfl2.js} +1 -1
  17. package/web/assets/{Whiteboard-BdGjJZXW.js → Whiteboard-ChYqIr3v.js} +1 -1
  18. package/web/assets/{aerial-yLD_gDzw.js → aerial-CZeCeacv.js} +2 -2
  19. package/web/assets/{agentTools-B7g6tXTR.js → agentTools-DW2ETnxE.js} +2 -2
  20. package/web/assets/{aiInbetween-6eKDYbYS.js → aiInbetween-De98iM4m.js} +2 -2
  21. package/web/assets/analyzerRun-D5-g-Vxe.js +1 -0
  22. package/web/assets/{analyzerSandbox-N92T6amg.js → analyzerSandbox-E3CdovIk.js} +1 -1
  23. package/web/assets/{api-Dnl2uaKO.js → api-CZoVJ9Fy.js} +87 -87
  24. package/web/assets/auraTrack-ClhHuqlf.js +1 -0
  25. package/web/assets/{breakthrough-DSiuVwEX.js → breakthrough-DTpiUIZd.js} +2 -2
  26. package/web/assets/{cameraPresets-Cfn7qhXK.js → cameraPresets-DD0WmxiI.js} +1 -1
  27. package/web/assets/{cameraTracker-DHdF8Zqx.js → cameraTracker-Df9jWmz6.js} +2 -2
  28. package/web/assets/{captionLayout-cckQ7p-t.js → captionLayout-eiu9QPJu.js} +1 -1
  29. package/web/assets/{clientExport-pkLbOmEF.js → clientExport-BXegTdNc.js} +1 -1
  30. package/web/assets/{clientJobs-CcsLDqFM.js → clientJobs-eB-lNyin.js} +2 -2
  31. package/web/assets/clipoox_photo_bg-BQ0aVNY0.wasm +0 -0
  32. package/web/assets/depthEstimate-CfwX-tXP.js +1 -0
  33. package/web/assets/{directorTools-DMsatulF.js → directorTools-ABbI8m0e.js} +1 -1
  34. package/web/assets/distortFrames-DMnZ8OYh.js +2 -0
  35. package/web/assets/distortGL-DQu0Df2c.js +18 -0
  36. package/web/assets/{domino-DBrinEUu.js → domino-trmDBvfH.js} +1 -1
  37. package/web/assets/{editTools-BNnAvCw-.js → editTools-DEFo9Ahv.js} +1 -1
  38. package/web/assets/{engine-Co-ivzlQ.js → engine-Y-GotDIy.js} +1 -1
  39. package/web/assets/exportGlb-BeLpJKJT.js +2 -0
  40. package/web/assets/{faceTracker-ClR-lS6Y.js → faceTracker-BeSFnLM8.js} +1 -1
  41. package/web/assets/{fightDirector-BlpVAURl.js → fightDirector-Dfz3vu5-.js} +1 -1
  42. package/web/assets/{fightDrama-BK0QidpM.js → fightDrama-CNVn69s0.js} +2 -2
  43. package/web/assets/{focusTool-sVOb2GGS.js → focusTool-Dd2UDkiO.js} +1 -1
  44. package/web/assets/{frameSink-CSRqCnwI.js → frameSink-Rj02YES5.js} +3 -3
  45. package/web/assets/{glTransitionSources.generated-q0H-ZbnZ.js → glTransitionSources.generated-Cs8lVRqs.js} +438 -2
  46. package/web/assets/{gpuCompose-B5bgbHdQ.js → gpuCompose-DkkKH1Ab.js} +1 -1
  47. package/web/assets/gpuExport-DwrXpVGF.js +199 -0
  48. package/web/assets/{handMatte-Dj2taFoC.js → handMatte-B5sUeqKi.js} +1 -1
  49. package/web/assets/{handTracker-c6_rvuwA.js → handTracker-CQV-D7va.js} +2 -2
  50. package/web/assets/i18n-ClNt3LKg.js +3 -0
  51. package/web/assets/{index-Ds_8isyf.js → index-D2u6mD-8.js} +1 -1
  52. package/web/assets/layer-worker-DP0N05Ua.js +5 -0
  53. package/web/assets/library-cb43ZEmy.js +1 -0
  54. package/web/assets/{lottieLayer-Cv8ub9f6.js → lottieLayer-DEw0c3to.js} +4 -4
  55. package/web/assets/main-C_XcvNyC.js +311 -0
  56. package/web/assets/{main-B_MAOvi6.css → main-DlzdW5C4.css} +1 -1
  57. package/web/assets/{mapBake-DtQboFIX.js → mapBake-BUWz0cSx.js} +1 -1
  58. package/web/assets/maskTrack-GYpJyKFw.js +1 -0
  59. package/web/assets/matteFixRun-BCVsuSxf.js +1 -0
  60. package/web/assets/{objectLocate-XuAcemlO.js → objectLocate-CjIlo_u0.js} +1 -1
  61. package/web/assets/{objectSegmenter-D66spD7o.js → objectSegmenter-C4T9qgUL.js} +1 -1
  62. package/web/assets/{objectTrack.worker-BZS6WZ6l.js → objectTrack.worker-BVvsDmR0.js} +1450 -908
  63. package/web/assets/{pathTracer-DykgPkkh.js → pathTracer-DgL1_83l.js} +2 -2
  64. package/web/assets/{pendingMatte-BWBIWajI.js → pendingMatte-DPTe6xoZ.js} +2 -2
  65. package/web/assets/peopleMatte-C1hruEM6.js +1 -0
  66. package/web/assets/{personAi-EhBknW6X.js → personAi-Cjg9KKeH.js} +2 -2
  67. package/web/assets/{personHq-Ca351o06.js → personHq-CBP8v_cw.js} +2 -2
  68. package/web/assets/photo.worker-DK_ulTzR.js +1 -0
  69. package/web/assets/photoRun-lZ2BdSEk.js +2 -0
  70. package/web/assets/photoTools-DmUh69Qk.js +1 -0
  71. package/web/assets/plateCamera-DLqlXhMp.js +1 -0
  72. package/web/assets/{plateCameraMatch-GPZl1fQQ.js → plateCameraMatch-4VUlUMi-.js} +2 -2
  73. package/web/assets/{plateFollow-CJUilsNV.js → plateFollow-D2rjnmZA.js} +2 -2
  74. package/web/assets/plateMatte-0tTG7oeO.js +2 -0
  75. package/web/assets/{pluginAutomation-DAPHWZPN.js → pluginAutomation-ClFdpcCR.js} +1 -1
  76. package/web/assets/popTools-B38V4wub.js +1 -0
  77. package/web/assets/{poseTracker-CzEKvJph.js → poseTracker-qtuytI-L.js} +1 -1
  78. package/web/assets/{productTools-ce-zyZO0.js → productTools-DlC5vWjx.js} +2 -2
  79. package/web/assets/remote-CpkPQOQH.js +989 -0
  80. package/web/assets/{rigTrack-DMyqb0pb.js → rigTrack-BbKqZGs7.js} +1 -1
  81. package/web/assets/{rotoMaskStore-pE1AIt3I.js → rotoMaskStore-BZBJLcCp.js} +1 -1
  82. package/web/assets/{rotoMatte-7b7Ow64f.js → rotoMatte-BI-vjjrv.js} +1 -1
  83. package/web/assets/rotoscope-DuNcCxQy.js +1 -0
  84. package/web/assets/{sceneTrack-DlAH5s74.js → sceneTrack-CO4fTjft.js} +1 -1
  85. package/web/assets/{sceneTrack-CA21MCOP.js → sceneTrack-_n6WKKQv.js} +1 -1
  86. package/web/assets/{sceneTrack.worker-COlhlHRe.js → sceneTrack.worker-f2d-WOzw.js} +1496 -954
  87. package/web/assets/{shot-worker-DL1ZoIym.js → shot-worker-BSmfIXHO.js} +1 -1
  88. package/web/assets/{shotFxAgent-DqngnGFb.js → shotFxAgent-L2GG88W3.js} +1 -1
  89. package/web/assets/{skin-xFScwS3T.js → skin-CirUiqcr.js} +1 -1
  90. package/web/assets/{spark.module-DjaIF6J1.js → spark.module-3Q8DniuL.js} +1 -1
  91. package/web/assets/{spellDuel-BYNtnE8f.js → spellDuel-2CDLbiLQ.js} +2 -2
  92. package/web/assets/{store-CpqHUcA2.js → store-D3Y663py.js} +1 -1
  93. package/web/assets/{surfaceLight-C7YI9SV8.js → surfaceLight--HQj7xhO.js} +1 -1
  94. package/web/assets/{surfacePin-CzpUj1Cw.js → surfacePin-BCmgw-40.js} +2 -2
  95. package/web/assets/{textAnimators-B9vO_hbP.js → textAnimators-C4eMnVRD.js} +1 -1
  96. package/web/assets/{thumb-BTFsBS1u.js → thumb-M9B_goj-.js} +1 -1
  97. package/web/assets/{timeline3d-DrFaMPPB.js → timeline3d-BcW68fQr.js} +2 -2
  98. package/web/assets/{timeline3dExport-Uo0S0CR0.js → timeline3dExport-DgnorHLm.js} +1 -1
  99. package/web/assets/timelineComp-Ciu9JCWJ.js +1 -0
  100. package/web/assets/timelineOps-f1WsVbgS.js +526 -0
  101. package/web/assets/{timelineProps-0v-s69pw.js → timelineProps-CE1R11Hx.js} +1 -1
  102. package/web/assets/{timelineText-DurRhyuh.js → timelineText-Cppd4KB7.js} +1 -1
  103. package/web/assets/{titleArt-CnC0A7x7.js → titleArt-D0YI5xT2.js} +3 -3
  104. package/web/assets/{titleFrameBudget-DsM0V482.js → titleFrameBudget-h4nOQ5u9.js} +1717 -1175
  105. package/web/assets/titleFrames-DnCzi_AI.js +1 -0
  106. package/web/assets/{tool-D1FpErrX.js → tool-tp6gat1J.js} +1 -1
  107. package/web/assets/{tools-DIvrRu-5.js → tools-C07G9KUM.js} +1 -1
  108. package/web/assets/{toonTools-D9MNdRty.js → toonTools-Cazx2CL7.js} +2 -2
  109. package/web/assets/{trackAnchor-XvUuvkWP.js → trackAnchor-DoqFDcJB.js} +1 -1
  110. package/web/assets/{userFonts-Djka6RJX.js → userFonts-BlVEJfDk.js} +1 -1
  111. package/web/assets/{vfxAlpha-B-JzzRI1.js → vfxAlpha-Bp6VgIGN.js} +1 -1
  112. package/web/assets/vfxBackground-BFq44Srn.js +2 -0
  113. package/web/assets/{videoExport-NN-QijHd.js → videoExport-Cz02XKtX.js} +1 -1
  114. package/web/assets/{views-RQBs4zva.js → views-CNF3Afse.js} +1 -1
  115. package/web/assets/{weaponDuel-DKAEYJjO.js → weaponDuel-ChqBQo_b.js} +1 -1
  116. package/web/assets/{windowFrames-DhhJLIs-.js → windowFrames-dBMXwGek.js} +1 -1
  117. package/web/layer-worker.html +3 -3
  118. package/web/shot-worker.html +24 -24
  119. package/web/assets/ShotComposer-DLxWpdYH.js +0 -287
  120. package/web/assets/ShotComposer-deLi4grZ.css +0 -1
  121. package/web/assets/TimelineShotFx-CyHTgJHj.js +0 -2
  122. package/web/assets/analyzerRun-Cr-_79RH.js +0 -1
  123. package/web/assets/auraTrack-C8eAEIWQ.js +0 -1
  124. package/web/assets/depthEstimate-Cav4MmQ1.js +0 -1
  125. package/web/assets/distortFrames-D_v-aSVO.js +0 -2
  126. package/web/assets/distortGL-vhnBRB59.js +0 -12
  127. package/web/assets/exportGlb-D3PrWUvi.js +0 -2
  128. package/web/assets/gpuExport-oA2mUsdm.js +0 -198
  129. package/web/assets/i18n-C9zFX25m.js +0 -3
  130. package/web/assets/layer-worker-ClVZG6ZW.js +0 -5
  131. package/web/assets/library-BK0QVG4O.js +0 -1
  132. package/web/assets/main-CwrkBJ63.js +0 -309
  133. package/web/assets/maskTrack-D4QZfMWc.js +0 -1
  134. package/web/assets/matteFixRun-CytaeRzS.js +0 -1
  135. package/web/assets/plateCamera-BcdXD1uI.js +0 -1
  136. package/web/assets/plateMatte-CoEoVjxZ.js +0 -2
  137. package/web/assets/remote-8XzEAnAJ.js +0 -974
  138. package/web/assets/rotoscope-BUqNTKLd.js +0 -1
  139. package/web/assets/timelineComp-i-zdaoB2.js +0 -1
  140. package/web/assets/timelineOps-DSSaDsU2.js +0 -525
  141. package/web/assets/titleFrames-C8kvflgT.js +0 -1
  142. package/web/assets/vfxBackground-b053ziDK.js +0 -2
@@ -1,198 +0,0 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/titleFrames-C8kvflgT.js","assets/titleFrameBudget-DsM0V482.js","assets/titleArt-CnC0A7x7.js","assets/textAnimators-B9vO_hbP.js","assets/lottieLayer-Cv8ub9f6.js","assets/rigTrack-DMyqb0pb.js","assets/i18n-C9zFX25m.js","assets/index-CKtv7gGE.js","assets/api-Dnl2uaKO.js","assets/frameSink-CSRqCnwI.js","assets/timeline3dExport-Uo0S0CR0.js","assets/timeline3d-DrFaMPPB.js","assets/three.module-Bx43vjkH.js","assets/gltfLoader-U0Eebg7v.js","assets/RoomEnvironment-Dmv_G5ka.js","assets/rotoMatte-7b7Ow64f.js","assets/store-CpqHUcA2.js","assets/captionLayout-cckQ7p-t.js"])))=>i.map(i=>d[i]);
2
- import{b_ as ao,U as Ht,eB as Go,ez as uo,cD as Uo,au as qo,eU as jo,iK as $o,iF as Ho,_ as Nt,i9 as oo,aq as Vo,iL as eo,aR as Yo,aP as mo,hR as Ko,hS as Wo,iM as po,e7 as Qo,eL as xo,ca as to,cc as Zo,fo as Jo,eV as Vt,eT as ei,W as io,er as vo,et as ho,es as go,cL as Yt,ev as ti,eR as oi,dE as Eo,iN as ii,cb as ri,eN as ai,fh as ni,eM as si,hL as ci,eb as Wt,iO as fi,el as bo,ej as li,hJ as ui,iP as mi,iQ as pi,iR as xi,b2 as di,aQ as vi,iS as hi,iT as gi,iU as Ei,bH as bi,aG as ko,iV as Ti,h as Po,iW as wi,iX as yi,d$ as Ri,e0 as _i,ai as Fi,iY as Ai,em as Mi,en as Si,eo as Di,eh as Ui,ep as ki,iZ as Pi,i_ as Bi,f2 as Li,cn as Ni,hV as Ii,i$ as Ci,hP as Xi,eq as To,j0 as Oi,V as zi,X as Gi,a0 as wo,j1 as yo,Y as Ro,an as qi,j2 as ji,e2 as $i,a2 as Hi,a3 as Vi,j3 as Yi,a4 as Ki,e1 as Wi,a5 as Qi,ab as Zi,aa as Ji,a8 as er,a6 as St,j4 as ro,ew as tr,j5 as or,e3 as ir,j6 as rr,j7 as ar}from"./titleFrameBudget-DsM0V482.js";import{h as no,j as nr,G as sr,z as cr,L as fr,e as lr,d as ur,l as mr,c as pr}from"./glTransitionSources.generated-q0H-ZbnZ.js";import{b as xr,e as dr,a as vr}from"./timelineComp-i-zdaoB2.js";import{g as so,l as ot,f as It,p as Ct,s as _o,w as Ot,r as hr,a as Xt,t as gr,n as Er,b as Fo,c as Bo,d as br}from"./gpuCompose-B5bgbHdQ.js";import{t as Tr}from"./motionBlur-uAm030t9.js";import{c as wr}from"./distortGL-vhnBRB59.js";import{c as co,V as yr,a as Rr,I as _r,A as Fr,U as Ar,b as Mr}from"./id3-arvEpAg7.js";import{S as Ao,B as Sr,O as Dr,M as Ur,a as kr,C as Pr,A as Br}from"./output-p-Q7qous.js";import"./api-Dnl2uaKO.js";import"./i18n-C9zFX25m.js";import"./index-CKtv7gGE.js";const Lr=m=>m.kind==="image"&&!!m.title?.text&&!m.url&&!oo(m)&&!Uo(m),Kt=m=>ui(m)||Lr(m),zt=48e3,Lo=192e3,Nr=4,No=(m,g)=>g?.name==="AbortError"||m>=Nr?null:Math.min(2**(m-1),4);async function Ir(m,g){for(let y=1;;y++){let e;try{e=await fetch(m,{signal:g})}catch(q){const h=g?.aborted?null:No(y,q);if(h===null)throw q;await new Promise(L=>setTimeout(L,h*1e3));continue}if(!e.ok)throw Error(`media ${e.status}`);return e.blob()}}const Io=()=>Rr("aac",{numberOfChannels:2,sampleRate:zt,bitrate:Lo}).catch(()=>!1),Xa=async(m,g)=>await co("avc",{width:m,height:g}).catch(()=>!1)&&Io();async function Oa(m){try{const{width:g,height:y,fps:e}=ao(m);return typeof VideoEncoder>"u"||!new OffscreenCanvas(2,2).getContext("webgl2")?!1:(await VideoEncoder.isConfigSupported({codec:"avc1.640034",width:g,height:y,bitrate:no(null,{width:g,height:y,fps:e},so),framerate:e,hardwareAcceleration:"prefer-software"})).supported===!0}catch{return!1}}const za=(m,g)=>co("hevc",{width:m,height:g}).catch(()=>!1);async function Ga(m,g){try{const{width:y,height:e,fps:q}=ao(m),h=g?.codec==="hevc";return typeof VideoEncoder>"u"||typeof AudioEncoder>"u"||typeof OfflineAudioContext>"u"||!new OffscreenCanvas(2,2).getContext("webgl2")||!(await VideoEncoder.isConfigSupported({codec:h?"hvc1.1.6.L153.B0":"avc1.640034",width:y,height:e,bitrate:no(g,{width:y,height:e,fps:q},so),framerate:q,hardwareAcceleration:"prefer-hardware"})).supported?!1:await co(h?"hevc":"avc",{width:y,height:e})&&await Io()}catch{return!1}}class Cr{frames=new Map;async push(g,y,e){let q=this.frames.get(y);q||(q=[],this.frames.set(y,q)),q.push(e)}}async function Mo(m,g,y,e,q,h,L){const M=g.get(y.url);if(!M)return null;if(ko(y)&&!y._still){const C=`${y.id}
3
- remap
4
- ${h}`,N=Math.round((e-h)*q);let X=m.get(C);if(!X){const te=M.samplesAtTimestamps(Ti(y,h-y.start,Math.max(1,Math.round(L*q)),q))[Symbol.asyncIterator]();X={iterator:te,peek:null,current:null,ts0:0,idx:0,next:async()=>{const oe=await te.next();return oe.done?null:oe.value}},m.set(C,X)}for(;(X.idx??0)<=N;){const te=await X.iterator.next();if(X.idx=(X.idx??0)+1,te.done)break;te.value&&te.value!==X.current&&(X.current?.close(),X.current=te.value)}return X.current}const V=!!(y._still||y.freeze),ie=V?1:y.playbackRate||1,se=!V&&Po(y),me=se?wi(y,h,L).start:(y.inPoint||0)+(V?0:(h-y.start)*ie),pe=`${y.id}
5
- ${V?"still":h}`;let x=m.get(pe);if(!x){if(!V)for(const[N,X]of m)N!==pe&&N.startsWith(`${y.id}
6
- `)&&!N.endsWith(`
7
- still`)&&!N.includes(`
8
- remap
9
- `)&&(X.current?.close(),X.peek?.close(),m.delete(N),await X.iterator.return?.());const C=M.samples(Math.max(0,me-.5))[Symbol.asyncIterator]();if(x={iterator:C,peek:null,current:null,ts0:me,next:async()=>{const N=await C.next();return N.done?null:N.value}},x.peek=await x.next(),!V){for(;x.peek&&x.peek.timestamp<me-1e-4;)x.peek.close(),x.peek=await x.next();x.ts0=x.peek?.timestamp??me}if(se){const N=O=>Number(O.toFixed(6)),X=h-y.start,te=yi(y,X,X+L),oe=te.slice(0,-1).map(([O,Ae],we)=>{const[je,ye]=te[we+1];return{xa:N(O),dx:N(je-O),k:je-O>1e-9?N((ye-Ae)/(je-O)):0}}).filter(O=>O.dx>1e-9);x.out=O=>oe.reduce((Ae,we)=>Ae+Math.min(we.dx,Math.max(0,O-we.xa))*we.k,0)}m.set(pe,x)}if(V){const C=Math.round(me*q);for(;x.peek&&Math.round(x.peek.timestamp*q)<=C;)x.current?.close(),x.current=x.peek,x.peek=await x.next();return x.current??x.peek}const R=Math.round((e-h)*q),F=C=>x.out?x.out(C-x.ts0):(C-x.ts0)/ie;for(;x.peek&&Math.round(F(x.peek.timestamp)*q)<=R;)x.current?.close(),x.current=x.peek,x.peek=await x.next();return x.current??x.peek}const Xr=`#version 300 es
10
- in vec2 p;uniform vec4 dst;uniform vec4 src;out vec2 uv;
11
- void main(){uv=src.xy+p*src.zw;vec2 q=dst.xy+p*dst.zw;gl_Position=vec4(q.x*2.-1.,1.-q.y*2.,0,1);}`,Or=`#version 300 es
12
- precision highp float;in vec2 uv;uniform sampler2D tex;uniform float alpha;uniform float fade;uniform float white;
13
- uniform float bright;uniform float contrast;uniform mat3 sat;uniform mat3 rot;uniform float colour;out vec4 o;
14
- uniform sampler2D matte;uniform float useMatte;uniform vec4 mrect;
15
- // chroma key (shared/chromaKey.js, the server's geq on the decoded picture): alpha = clip((d − similarity) / blend), d = |CbCr − key|
16
- // / (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
17
- // key's BT.601 Cb / Cr; then despill (mix 0.5) pulls the green / blue cast back by spill
18
- uniform vec4 key;uniform vec4 keyOpt;
19
- // 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
20
- // mixer, timelineMixer.js mixerLut; ffmpeg lut3d trilinear), each on 8-bit values like the server's lut1d / lut3d
21
- uniform highp sampler2D lut1;uniform highp sampler3D lut3;uniform float useL1;uniform float useL3;
22
- 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));
23
- 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;
24
- 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;
25
- 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);}
26
- void main(){vec4 c=texture(tex,uv);vec3 rgb=c.rgb;
27
- if(keyOpt.x>.5){vec3 q=floor(rgb*255.+.5);float k=224./255.;
28
- 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);
29
- 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);
30
- 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.;
31
- c.a*=floor(a*255.)/255.;
32
- 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);}}}
33
- if(useMatte>.5)c.a*=texture(matte,(uv-mrect.xy)/mrect.zw).r;
34
- if(colour>.5){rgb=clamp(rgb*bright,0.,1.);rgb=clamp((rgb-.5)*contrast+.5,0.,1.);rgb=clamp(sat*rgb,0.,1.);rgb=clamp(rot*rgb,0.,1.);}
35
- if(useL1>.5){ivec3 k=ivec3(floor(rgb*255.+.5));rgb=floor(vec3(texelFetch(lut1,ivec2(k.r,0),0).r,texelFetch(lut1,ivec2(k.g,0),0).g,texelFetch(lut1,ivec2(k.b,0),0).b)*255.+.5)/255.;}
36
- if(useL3>.5)rgb=floor(clamp(tri(floor(rgb*255.+.5)/255.),0.,1.)*255.+.5)/255.;
37
- rgb=white>.5?1.-(1.-rgb)*fade:rgb*fade;o=vec4(rgb,c.a*alpha);}`,G=`#version 300 es
38
- in vec2 p;out vec2 uv;void main(){uv=p;gl_Position=vec4(p*2.-1.,0,1);}`,zr=`#version 300 es
39
- precision highp float;in vec2 uv;uniform sampler2D tex;uniform vec2 step;uniform float sigma;out vec4 o;
40
- void main(){int r=min(int(ceil(sigma*3.)),128);vec4 acc=vec4(0);float wsum=0.;
41
- for(int i=-r;i<=r;i++){float w=exp(-float(i*i)/(2.*sigma*sigma));acc+=texture(tex,uv+step*float(i))*w;wsum+=w;}
42
- o=acc/wsum;}`,Gr=`#version 300 es
43
- precision highp float;in vec2 uv;uniform sampler2D tex;uniform float lo;uniform float k;out vec4 o;
44
- void main(){vec4 c=texture(tex,uv);o=vec4(clamp(lo+c.rgb*k,0.,1.),c.a);}`,qr=`#version 300 es
45
- precision highp float;in vec2 uv;uniform sampler2D a;uniform sampler2D b;uniform float amount;out vec4 o;
46
- void main(){vec4 x=texture(a,uv),y=texture(b,uv);o=mix(x,1.-(1.-x)*(1.-y),amount);}`,jr=`#version 300 es
47
- precision highp float;in vec2 uv;uniform sampler2D tex;uniform vec2 step;uniform float b;uniform int reach;out vec4 o;
48
- void main(){vec4 acc=texture(tex,uv);float ws=1.;float w=1.;
49
- for(int i=1;i<=512;i++){if(i>reach)break;w*=b;acc+=(texture(tex,uv+step*float(i))+texture(tex,uv-step*float(i)))*w;ws+=2.*w;}
50
- o=acc/ws;}`,$r=`#version 300 es
51
- precision highp float;in vec2 uv;uniform sampler2D tex;uniform float taps[16];uniform int n;uniform vec2 ctr;out vec4 o;
52
- void main(){vec4 acc=vec4(0);for(int i=0;i<16;i++){if(i>=n)break;acc+=texture(tex,ctr+(uv-ctr)/taps[i]);}o=acc/float(n);}`,Hr=`#version 300 es
53
- 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;
54
- 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]));}
55
- acc/=float(n);o=vec4(min(acc.rgb*gain,1.),acc.a);}`,Vr=`#version 300 es
56
- precision highp float;in vec2 uv;uniform sampler2D tex;uniform float gain;out vec4 o;
57
- void main(){vec4 c=texture(tex,uv);o=vec4(min(c.rgb*gain,1.),c.a);}`,Yr=`#version 300 es
58
- precision highp float;in vec2 uv;uniform sampler2D a;uniform sampler2D b;uniform float w;out vec4 o;
59
- void main(){o=mix(texture(a,uv),texture(b,uv),w);}`,Kr=`#version 300 es
60
- precision highp float;in vec2 uv;uniform sampler2D tex;uniform vec4 colour;uniform float usetex;out vec4 o;
61
- void main(){o=usetex>.5?texture(tex,vec2(uv.x,1.-uv.y)):colour;}`,Wr=`#version 300 es
62
- precision highp float;uniform sampler2D tex;uniform mat3 inv;uniform vec2 size;uniform vec4 rnd;uniform float keepPre;out vec4 o;
63
- // a pinned screen's rounded corners (shared/cornerPin.js pinRoundGraph): the server's geq mask on the stretched plane BEFORE its
64
- // 2 px inset, at pixel centres, kept at least rnd.z (the portal dive's fade to square corners); rnd.w = on
65
- float corner(ivec2 i){if(rnd.w<.5)return 1.;vec2 k=size/(size-4.),X=(vec2(i)+.5-2.)*k;
66
- 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)));
67
- 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);}
68
- 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);}
69
- 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.;
70
- vec2 f=floor(u),w=u-f;ivec2 i=ivec2(f);
71
- 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);
72
- o=keepPre>.5?c:c.a>0.?vec4(c.rgb/c.a,c.a):vec4(0);}`,Qr=`#version 300 es
73
- precision highp float;in vec2 uv;uniform sampler2D tex;uniform vec2 size;uniform int kind;uniform float e;uniform float f;uniform float inv;
74
- uniform vec2 ctr;uniform vec3 csh;uniform float count;out vec4 o;
75
- 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;
76
- 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)));
77
- 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;}}
78
- else if(kind==3)r=length(vec2(dx,dy))/R;
79
- else if(kind==4)r=(abs(dx)/max(cx,W-cx)+abs(dy)/max(cy,H-cy))/2.;
80
- 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);}
81
- else if(kind==7){float s=W/count,i=floor(X/s),j=floor(Y/s);r=mod(i*i*31.+j*j*17.+i*j*7.+i*13.+j*29.+11.,97.)/97.;}
82
- else{float a=atan(dx,-dy);if(a<0.)a+=6.283185307179586;r=a/6.283185307179586;}
83
- 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
84
- 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;
85
- void main(){vec4 c=texture(tex,uv),v=floor(c*255.+.5);vec3 q=v.rgb;
86
- 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.);}
87
- 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.;
88
- o=vec4(q/255.,c.a);}`,Jr=`#version 300 es
89
- precision highp float;uniform sampler2D tex;uniform int px;out vec4 o;
90
- void main(){ivec2 p=ivec2(gl_FragCoord.xy);int W=textureSize(tex,0).x;vec4 c=texelFetch(tex,p,0);
91
- o=vec4(texelFetch(tex,ivec2(clamp(p.x+px,0,W-1),p.y),0).r,c.g,texelFetch(tex,ivec2(clamp(p.x-px,0,W-1),p.y),0).b,c.a);}`,ea=`#version 300 es
92
- precision highp float;uniform sampler2D tex;uniform int b;uniform ivec2 small;out vec4 o;
93
- void main(){ivec2 s=textureSize(tex,0),k=ivec2(gl_FragCoord.xy);k.y=small.y-1-k.y;vec4 sum=vec4(0);float n=0.;
94
- for(int j=0;j<64;j++){if(j>=b)break;int y=k.y*b+j;if(y>=s.y)break;for(int i=0;i<64;i++){if(i>=b)break;int x=k.x*b+i;if(x>=s.x)break;sum+=texelFetch(tex,ivec2(x,s.y-1-y),0);n+=1.;}}
95
- o=sum/n;}`,ta=`#version 300 es
96
- precision highp float;uniform sampler2D small;uniform int b;uniform vec2 size;out vec4 o;
97
- void main(){ivec2 p=ivec2(gl_FragCoord.xy),ss=textureSize(small,0);int y=int(size.y)-1-p.y;o=texelFetch(small,ivec2(p.x/b,ss.y-1-y/b),0);}`,oa=`#version 300 es
98
- precision highp float;in vec2 uv;uniform sampler2D tex;uniform vec2 off;uniform vec3 col;uniform float op;uniform float times;uniform vec2 dil;out vec4 o;
99
- 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);
100
- 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)));
101
- o=vec4(col,a/255.);}`,ia=`#version 300 es
102
- precision highp float;uniform sampler2D tex;uniform float harden;out vec4 o;
103
- 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);}`,ra=`#version 300 es
104
- precision highp float;uniform sampler2D tex;uniform ivec2 dir;uniform float sigma;out vec4 o;
105
- void main(){ivec2 p=ivec2(gl_FragCoord.xy),n=textureSize(tex,0);int r=min(int(ceil(sigma*3.)),128);float acc=0.,ws=0.;
106
- for(int i=-r;i<=r;i++){float w=exp(-float(i*i)/(2.*sigma*sigma));ivec2 q=p+dir*i;
107
- if(q.x>=0&&q.y>=0&&q.x<n.x&&q.y<n.y)acc+=texelFetch(tex,q,0).r*w;ws+=w;}
108
- o=vec4(floor(acc/ws*255.+.5)/255.,0,0,1);}`,aa=`#version 300 es
109
- precision highp float;uniform sampler2D a;uniform sampler2D b;uniform float arc;uniform vec2 cw;uniform vec2 cen;uniform float start;uniform float cover;uniform float comet;uniform float feather;out vec4 o;
110
- 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);
111
- float band=floor(x*clamp(2.*(1.-y/max(x,1.)),0.,1.));
112
- if(arc>.5){float K=${ro}.,TAU=6.283185307179586;vec2 u=vec2(gl_FragCoord.x,cw.y*K-gl_FragCoord.y)/K;float th=atan(u.x-cw.x*cen.x,cw.y*cen.y-u.y);
113
- float d=mod(mod(th-start,TAU)+TAU,TAU)/TAU,m=d<=cover?1.:0.;if(cover<.999)m*=clamp(min(d,cover-d)/feather,0.,1.);if(comet>.5)m*=d/cover;
114
- band=floor(band*floor(255.*m)/255.);}
115
- o=vec4(band/255.,0,0,1);}`,na=`#version 300 es
116
- precision highp float;uniform sampler2D pic;uniform sampler2D band;uniform sampler2D glow;uniform vec3 col;uniform float k;uniform float am;out vec4 o;
117
- 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);
118
- float rim=clamp(floor(b+g*k),0.,255.);if(am<255.)rim=floor(rim*am/255.);
119
- vec4 P=texelFetch(pic,p,0);float ra=rim/255.,oa=ra+P.a*(1.-ra);
120
- o=vec4(oa>0.?(col*ra+P.rgb*P.a*(1.-ra))/oa:P.rgb,oa);}`,sa=`#version 300 es
121
- 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;}`,ca=`#version 300 es
122
- 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);}`,fa=`#version 300 es
123
- precision highp float;uniform sampler2D tex;uniform vec2 big;uniform vec2 small;uniform vec4 q1;uniform vec4 q2;uniform float useQ;
124
- uniform vec4 w1;uniform vec4 w2;uniform float useW;uniform float inv;out vec4 o;
125
- 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.);}
126
- void main(){vec2 X=floor(gl_FragCoord.xy),c=(X+.5)*big/small;vec3 a=vec3(0);
127
- 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;
128
- vec3 p=floor(a/4.*255.+.5)/255.;float m=1.;
129
- 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.;
130
- 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.);
131
- 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;
132
- m*=mh*rp(ch,q2.x,q2.y,q1.w)*rp(l,q2.z,q2.w,q1.w);}
133
- 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;
134
- if(w2.w>1.5)m*=clamp(.5-y/w1.w,0.,1.);
135
- 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.);}}
136
- if(inv>.5)m=1.-m;o=vec4(floor(255.*m+1e-4)/255.,0,0,1);}`,la=`#version 300 es
137
- precision highp float;uniform sampler2D tex;uniform highp sampler2D lut;uniform highp sampler3D t3;uniform float useT;uniform float useL;
138
- uniform float useS;uniform mat3 sat;uniform float useR;uniform mat3 rot;out vec4 o;
139
- 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));
140
- 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;
141
- 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;
142
- 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);}
143
- void main(){ivec2 P=ivec2(gl_FragCoord.xy);vec4 c=texelFetch(tex,P,0);vec3 g=floor(c.rgb*255.+.5);
144
- if(useT>.5)g=floor(clamp(tri(g/255.),0.,1.)*255.+.5);
145
- 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);}
146
- if(useS>.5)g=floor(clamp(sat*(g/255.),0.,1.)*255.+.5);
147
- if(useR>.5)g=floor(clamp(rot*(g/255.),0.,1.)*255.+.5);
148
- o=vec4(g/255.,c.a);}`,ua=`#version 300 es
149
- precision highp float;uniform sampler2D base;uniform sampler2D over;uniform sampler2D mask;uniform vec2 msz;uniform float full;out vec4 o;
150
- 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;}
151
- 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);
152
- o=vec4((q+floor((m*(G-q)+128.)/256.))/255.,b.a);}`,ma=`#version 300 es
153
- precision highp float;uniform sampler2D tex;uniform float k[9];uniform float rdiv;out vec4 o;
154
- void main(){ivec2 P=ivec2(gl_FragCoord.xy),S=textureSize(tex,0);vec3 s=vec3(0);
155
- 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];}
156
- vec4 c=texelFetch(tex,P,0);o=vec4(clamp(floor(s*rdiv+.5),0.,255.)/255.,c.a);}`,pa=`#version 300 es
157
- precision highp float;uniform sampler2D tex;uniform sampler2D grain;out vec4 o;
158
- 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);}`,xa=`#version 300 es
159
- precision highp float;uniform sampler2D res;uniform sampler2D outp;uniform sampler2D inp;out vec4 o;
160
- 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);
161
- vec3 d=clamp(O-I+128.,0.,255.);o=vec4(clamp(R+d-128.,0.,255.)/255.,r.a);}`,da=`#version 300 es
162
- precision highp float;uniform sampler2D tex;uniform sampler2D soft;uniform float t;out vec4 o;
163
- 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);
164
- 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.);
165
- o=vec4(clamp(B+d-128.,0.,255.)/255.,c.a);}`,va=`#version 300 es
166
- precision highp float;in vec2 uv;uniform sampler2D top;uniform sampler2D bg;uniform int mode;out vec4 o;
167
- 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;
168
- if(mode==1){o=vec4(min(vec3(255.),Bp+floor(S*a/255.+.5))/255.,min(1.,a/255.+ab));return;}
169
- // the backdrop is premultiplied (a comp's own transparent picture, gpuExport frames mode): blended against its straight colour, and
170
- // where it is transparent the layer shows as itself (W3C / After Effects); an opaque backdrop (ab = 1) is the formula as before
171
- vec3 B=ab>0.?(ab<1.?floor(Bp/ab+.5):Bp):vec3(0),X;
172
- if(mode==2)X=255.-floor((255.-B)*(255.-S)/255.);
173
- else if(mode==3)X=floor(B*S/255.);
174
- else if(mode==4)X=mix(255.-2.*floor((255.-B)*(255.-S)/255.),2.*floor(B*S/255.),step(B,vec3(127.5)));
175
- 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.);
176
- 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);}`,ha=`#version 300 es
177
- precision highp float;uniform sampler2D tex;uniform int ss;out vec4 o;
178
- 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);}}
179
- c/=float(ss*ss);o=c.a>0.?vec4(c.rgb/c.a,c.a):vec4(0);}`,ga=`#version 300 es
180
- precision highp float;uniform sampler2D tex;uniform int px;out vec4 o;
181
- 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;
182
- 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);}`,Ea=`#version 300 es
183
- precision highp float;uniform sampler2D tex;uniform vec2 size;uniform vec2 msize;uniform float v;uniform float fr;out vec4 o;
184
- 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.;}
185
- 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.));}
186
- 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;
187
- vec2 a=clamp(f,vec2(0),msize-1.),b=clamp(f+1.,vec2(0),msize-1.);
188
- 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);
189
- o=texelFetch(tex,ivec2(clamp(int(floor(m+.5)),0,int(size.x)-1),int(size.y)-1-int(Y)),0);}`,ba=`#version 300 es
190
- precision highp float;uniform sampler2D tex;uniform vec2 size;uniform float a[8];uniform float sx[8];uniform float sy[8];out vec4 o;
191
- void main(){vec2 p=vec2(gl_FragCoord.x-.5,size.y-gl_FragCoord.y-.5),c=size*.5-.5;vec4 acc=vec4(0);
192
- 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;
193
- 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);}
194
- o=acc/8.;}`,Ta=`#version 300 es
195
- precision highp float;in vec2 uv;uniform sampler2D tex;uniform float w;out vec4 o;
196
- void main(){vec4 c=texture(tex,uv);o=vec4(mix(c.rgb,1.-c.rgb,w),c.a);}`,wa=`#version 300 es
197
- precision highp float;in vec2 uv;uniform sampler2D tex;out vec4 o;void main(){o=texture(tex,uv);}`,ya=["wipe","blinds","split","iris","diamond","burn"];function So(m,g){const y=Math.max(1e-4,m.feather??.05),e=m.progress?Wt(m.progress,g)??0:g,q=(m.angle??0)*Math.PI/180,h=Math.cos(q),L=Math.sin(q),M=ya.indexOf(m.type??""),V=m.type==="grid";return{type:"txMask",kind:V?7:M<0?6:M,e:e*(1+2*y)-y,f:y,inv:!!m.invert,cx:m.cx??.5,cy:m.cy??.5,c:h,s:L,h:.5*(Math.abs(h)+Math.abs(L)),count:m.count??(V?Pi:8)}}function Do(m,g,y,e,q=0,h){if(!m)return[];const L=V=>Wt(m[V],g)??0,M=[];if(m.zoomBlur&&M.push({type:"txZoom",taps:Mi(),w:L("zoomBlur"),...h?{c:[h.cx,1-h.cy]}:{}}),m.spinBlur){const V=Si(y,e),ie=se=>Math.max(2,Math.round(se/2)*2);M.push({type:"txSpin",a:V.map(se=>+se.a.toFixed(6)),sx:V.map(se=>ie(y*se.scale)/y),sy:V.map(se=>ie(e*se.scale)/e),w:L("spinBlur")})}if(m.dirBlur){const V=To*y/1280,ie=V/(1+V);M.push({type:"txDir",b:ie,reach:Math.min(512,Math.ceil(Math.log(.001)/Math.log(ie))),w:L("dirBlur")})}if(m.dirBlurV){const V=To*y/1280,ie=V/(1+V);M.push({type:"txDir",b:ie,reach:Math.min(512,Math.ceil(Math.log(.001)/Math.log(ie))),w:L("dirBlurV"),v:!0})}return m.blur&&M.push({type:"txGauss",sigma:Di*y/1280,w:L("blur")}),m.glitch&&M.push({type:"txGlitch",v:L("glitch"),fr:Math.floor(q*30+.5)}),m.rgbSplit&&M.push({type:"txRgb",px:Math.trunc(L("rgbSplit")*Ui*y/1280+.5)}),m.exposure&&M.push({type:"txExpo",gain:ki,w:L("exposure")}),m.invert&&M.push({type:"txInv",w:L("invert")}),M}function Ra(m,g){const y=new OffscreenCanvas(m,g),e=y.getContext("webgl2",{premultipliedAlpha:!1,preserveDrawingBuffer:!0,antialias:!1});if(!e)throw Error("WebGL2 unavailable");const q=(a,c)=>{const i=e.createShader(a);if(e.shaderSource(i,c),e.compileShader(i),!e.getShaderParameter(i,e.COMPILE_STATUS))throw Error(String(e.getShaderInfoLog(i)));return i},h=(a,c)=>{const i=e.createProgram();if(e.attachShader(i,q(e.VERTEX_SHADER,a)),e.attachShader(i,q(e.FRAGMENT_SHADER,c)),e.bindAttribLocation(i,0,"p"),e.linkProgram(i),!e.getProgramParameter(i,e.LINK_STATUS))throw Error(String(e.getProgramInfoLog(i)));return i},L=h(Xr,Or),M=h(G,oa),V=h(G,ia),ie=h(G,ra),se=h(G,aa),me=h(G,na),pe=h(G,sa),x=h(G,ca),R=h(G,fa),F=h(G,zr),C=h(G,Gr),N=h(G,qr),X=h(G,wa),te=h(G,Hr),oe=h(G,la),O=h(G,ua),Ae=h(G,ma),we=h(G,pa),je=h(G,da),ye=h(G,xa),We=h(G,jr),$e=h(G,$r),nt=h(G,Vr),Me=h(G,Yr),st=h(G,Kr),Qe=h(G,Wr),Re=h(G,Qr),He=h(G,Zr),Ze=h(G,Jr),Se=h(G,ea),Xe=h(G,ta),it=h(G,va),Z=h(G,ha),ge=h(G,ga),ct=h(G,Ta),Ve=h(G,Ea),ke=h(G,ba),rt=e.createBuffer();e.bindBuffer(e.ARRAY_BUFFER,rt),e.bufferData(e.ARRAY_BUFFER,new Float32Array([0,0,1,0,0,1,1,1]),e.STATIC_DRAW),e.enableVertexAttribArray(0),e.vertexAttribPointer(0,2,e.FLOAT,!1,0,0);const Ye=a=>c=>e.getUniformLocation(a,c),A=Ye(L);e.pixelStorei(e.UNPACK_PREMULTIPLY_ALPHA_WEBGL,!1);const ce=()=>{const a=e.createTexture();e.bindTexture(e.TEXTURE_2D,a);for(const[c,i]of[[e.TEXTURE_MIN_FILTER,e.LINEAR],[e.TEXTURE_MAG_FILTER,e.LINEAR],[e.TEXTURE_WRAP_S,e.CLAMP_TO_EDGE],[e.TEXTURE_WRAP_T,e.CLAMP_TO_EDGE]])e.texParameteri(e.TEXTURE_2D,c,i);return a},ft=ce(),Et=ce();let Ke=null;const at=ce(),lt=e.createTexture(),Oe={l1:"",l3:""};let bt=!1,Gt=!1,Pe=null;const Qt={add:1,screen:2,multiply:3,overlay:4,lighten:5,darken:6,difference:7,exclusion:8};let _e=0;const Tt=ce();let U=[],wt=null,yt=null;const Rt=new Map;let Be=!1,be=null;const _t=a=>{const c=Fe(),i=(a+1)%3,o=(a+2)%3;for(const p of U){let b=a;e.disable(e.BLEND),p.sigma>.05&&($(F,c[i].fb,[c[a].tex],w=>{e.uniform1i(w("tex"),0),e.uniform2f(w("step"),1/m,0),e.uniform1f(w("sigma"),p.sigma)}),$(F,c[o].fb,[c[i].tex],w=>{e.uniform1i(w("tex"),0),e.uniform2f(w("step"),0,1/g),e.uniform1f(w("sigma"),p.sigma)}),b=o),le(null),e.enable(e.BLEND),e.blendFuncSeparate(e.SRC_ALPHA,e.ONE_MINUS_SRC_ALPHA,e.ONE,e.ONE_MINUS_SRC_ALPHA);const[t,l,u]=[1,3,5].map(w=>parseInt(p.color.slice(w,w+2),16)/255);$(M,null,[c[b].tex],w=>{e.uniform1i(w("tex"),0),e.uniform2f(w("off"),Math.trunc(p.dx)/m,-Math.trunc(p.dy)/g),e.uniform3f(w("col"),t,l,u),e.uniform1f(w("op"),p.opacity),e.uniform1f(w("times"),p.times),e.uniform2f(w("dil"),p.dilate?+(rr*255).toFixed(3):0,p.dilate?+(1/ar).toFixed(3):0)})}},ut=a=>{const c=Fe();if(Be){le(be.fb),e.enable(e.BLEND),e.blendFunc(e.ONE,e.ONE),$(pe,be.fb,[c[a].tex],i=>e.uniform1i(i("tex"),0)),e.blendFuncSeparate(e.SRC_ALPHA,e.ONE_MINUS_SRC_ALPHA,e.ONE,e.ONE_MINUS_SRC_ALPHA);return}if(U.length&&_t(a),_e){Je(c[a].tex);return}le(null),e.enable(e.BLEND),e.blendFuncSeparate(e.SRC_ALPHA,e.ONE_MINUS_SRC_ALPHA,e.ONE,e.ONE_MINUS_SRC_ALPHA),$(X,null,[c[a].tex],i=>e.uniform1i(i("tex"),0))},Je=a=>{le(null),e.bindTexture(e.TEXTURE_2D,Tt),e.copyTexImage2D(e.TEXTURE_2D,0,e.RGBA8,0,0,m,g,0),e.disable(e.BLEND),$(it,null,[a,Tt],c=>{e.uniform1i(c("top"),0),e.uniform1i(c("bg"),1),e.uniform1i(c("mode"),_e)})};let Le=null;const Fe=()=>Le??=[De(),De(),De()],Ft=new Map,Dt=a=>{let c=Ft.get(a);if(c)return c;const i=()=>{const o=ce();e.texImage2D(e.TEXTURE_2D,0,e.RGBA8,m*a,g*a,0,e.RGBA,e.UNSIGNED_BYTE,null);const p=e.createFramebuffer();return e.bindFramebuffer(e.FRAMEBUFFER,p),e.framebufferTexture2D(e.FRAMEBUFFER,e.COLOR_ATTACHMENT0,e.TEXTURE_2D,o,0),{tex:o,fb:p}};return c={plane:i(),out:i()},Ft.set(a,c),c},Ut=new Map,qt=new Map,Zt=a=>{let c=Ut.get(a.key);if(c)return c;c=ce();const i=new Uint8Array(256*3);(a.lut??[]).forEach((o,p)=>i.set(o,p*256)),e.pixelStorei(e.UNPACK_ALIGNMENT,1),e.texImage2D(e.TEXTURE_2D,0,e.R8,256,3,0,e.RED,e.UNSIGNED_BYTE,i),e.pixelStorei(e.UNPACK_ALIGNMENT,4);for(const o of[e.TEXTURE_MIN_FILTER,e.TEXTURE_MAG_FILTER])e.texParameteri(e.TEXTURE_2D,o,e.NEAREST);return Ut.set(a.key,c),c},mt=(a,c)=>{const i=`${a}x${c}`;let o=qt.get(i);if(o)return o;const p=ce();e.texImage2D(e.TEXTURE_2D,0,e.RGBA8,a,c,0,e.RGBA,e.UNSIGNED_BYTE,null);for(const t of[e.TEXTURE_MIN_FILTER,e.TEXTURE_MAG_FILTER])e.texParameteri(e.TEXTURE_2D,t,e.NEAREST);const b=e.createFramebuffer();return e.bindFramebuffer(e.FRAMEBUFFER,b),e.framebufferTexture2D(e.FRAMEBUFFER,e.COLOR_ATTACHMENT0,e.TEXTURE_2D,p,0),o={tex:p,fb:b},qt.set(i,o),o},At=new Map,kt=(a,c)=>{const i=`${a}x${c}`;let o=At.get(i);return o||(o=[0,1].map(()=>{const p=ce();e.texImage2D(e.TEXTURE_2D,0,e.RGBA8,a,c,0,e.RGBA,e.UNSIGNED_BYTE,null);const b=e.createFramebuffer();return e.bindFramebuffer(e.FRAMEBUFFER,b),e.framebufferTexture2D(e.FRAMEBUFFER,e.COLOR_ATTACHMENT0,e.TEXTURE_2D,p,0),{tex:p,fb:b}}),At.set(i,o),o)},De=()=>{const a=ce();e.texImage2D(e.TEXTURE_2D,0,e.RGBA8,m,g,0,e.RGBA,e.UNSIGNED_BYTE,null);const c=e.createFramebuffer();return e.bindFramebuffer(e.FRAMEBUFFER,c),e.framebufferTexture2D(e.FRAMEBUFFER,e.COLOR_ATTACHMENT0,e.TEXTURE_2D,a,0),{tex:a,fb:c}},le=a=>{e.bindFramebuffer(e.FRAMEBUFFER,a),e.viewport(0,0,m,g)},$=(a,c,i,o)=>Mt(a,c,m,g,i,o),Mt=(a,c,i,o,p,b)=>{e.bindFramebuffer(e.FRAMEBUFFER,c),e.viewport(0,0,i,o),e.useProgram(a);const t=Ye(a);p.forEach((l,u)=>{e.activeTexture(e.TEXTURE0+u),e.bindTexture(e.TEXTURE_2D,l)}),b(t),e.drawArrays(e.TRIANGLE_STRIP,0,4),p.length>1&&r(),e.activeTexture(e.TEXTURE0)},r=()=>{e.activeTexture(e.TEXTURE1),e.bindTexture(e.TEXTURE_2D,Et),e.activeTexture(e.TEXTURE2),e.bindTexture(e.TEXTURE_2D,at),e.activeTexture(e.TEXTURE3),e.bindTexture(e.TEXTURE_3D,lt),e.activeTexture(e.TEXTURE0)},f=(a,c=0)=>{const i=Fe();let o=c;const p=(t,l,u,w)=>{$(F,i[l].fb,[i[t].tex],n=>{e.uniform1i(n("tex"),0),e.uniform2f(n("step"),1/m,0),e.uniform1f(n("sigma"),w)}),$(F,i[u].fb,[i[l].tex],n=>{e.uniform1i(n("tex"),0),e.uniform2f(n("step"),0,1/g),e.uniform1f(n("sigma"),w)})},b=(t,l,u,w)=>$(Me,i[u].fb,[i[t].tex,i[l].tex],n=>{e.uniform1i(n("a"),0),e.uniform1i(n("b"),1),e.uniform1f(n("w"),w)});for(const t of a){const[l,u,w]=[o,(o+1)%3,(o+2)%3];if(t.type==="blur"){t.sigma>.05&&(p(l,u,w,t.sigma),o=w);continue}if(t.type==="colour"){const n=Zt(t);$(He,i[u].fb,[i[l].tex,n],v=>{e.uniform1i(v("tex"),0),e.uniform1i(v("lut"),1),e.uniform1f(v("useM"),t.m?1:0),e.uniform1f(v("useL"),t.lut?1:0),t.m&&e.uniform1fv(v("m"),t.m.flatMap(S=>[S[0],S[1],S[2],S[3]??0]))}),o=u;continue}if(t.type==="txRgb"){t.px>0&&($(ge,i[u].fb,[i[l].tex],n=>{e.uniform1i(n("tex"),0),e.uniform1i(n("px"),t.px)}),o=u);continue}if(t.type==="txGlitch"){t.v>1e-4&&($(Ve,i[u].fb,[i[l].tex],n=>{e.uniform1i(n("tex"),0),e.uniform2f(n("size"),m,g),e.uniform2f(n("msize"),Math.max(2,Math.round(m/4)),Math.max(2,Math.round(g/4))),e.uniform1f(n("v"),t.v),e.uniform1f(n("fr"),t.fr)}),o=u);continue}if(t.type==="txInv"){t.w>1e-4&&($(ct,i[u].fb,[i[l].tex],n=>{e.uniform1i(n("tex"),0),e.uniform1f(n("w"),Math.min(1,t.w))}),o=u);continue}if(t.type==="shift"){$(Ze,i[u].fb,[i[l].tex],n=>{e.uniform1i(n("tex"),0),e.uniform1i(n("px"),t.px)}),o=u;continue}if(t.type==="pixel"){const n=Math.ceil(m/t.block),v=Math.ceil(g/t.block),S=mt(n,v);e.bindFramebuffer(e.FRAMEBUFFER,S.fb),e.viewport(0,0,n,v),e.useProgram(Se),e.activeTexture(e.TEXTURE0),e.bindTexture(e.TEXTURE_2D,i[l].tex),e.uniform1i(e.getUniformLocation(Se,"tex"),0),e.uniform1i(e.getUniformLocation(Se,"b"),t.block),e.uniform2i(e.getUniformLocation(Se,"small"),n,v),e.drawArrays(e.TRIANGLE_STRIP,0,4),$(Xe,i[u].fb,[S.tex],Y=>{e.uniform1i(Y("small"),0),e.uniform1i(Y("b"),t.block),e.uniform2f(Y("size"),m,g)}),o=u;continue}if(t.type==="txMask"){$(Re,i[u].fb,[i[l].tex],n=>{e.uniform1i(n("tex"),0),e.uniform2f(n("size"),m,g),e.uniform1i(n("kind"),t.kind),e.uniform1f(n("e"),t.e),e.uniform1f(n("f"),t.f),e.uniform1f(n("inv"),t.inv?1:0),e.uniform2f(n("ctr"),t.cx,t.cy),e.uniform3f(n("csh"),t.c,t.s,t.h),e.uniform1f(n("count"),t.count)}),o=u;continue}if(t.type==="txGauss"||t.type==="txDir"||t.type==="txZoom"||t.type==="txSpin"||t.type==="txExpo"){if(!(t.w>1e-4))continue;let n=u;t.type==="txGauss"?(p(l,u,w,t.sigma),n=w):t.type==="txDir"?$(We,i[u].fb,[i[l].tex],S=>{e.uniform1i(S("tex"),0),t.v?e.uniform2f(S("step"),0,1/g):e.uniform2f(S("step"),1/m,0),e.uniform1f(S("b"),t.b),e.uniform1i(S("reach"),t.reach)}):t.type==="txZoom"?$($e,i[u].fb,[i[l].tex],S=>{e.uniform1i(S("tex"),0),e.uniform1fv(S("taps"),t.taps),e.uniform1i(S("n"),t.taps.length),e.uniform2f(S("ctr"),t.c?.[0]??.5,t.c?.[1]??.5)}):t.type==="txSpin"?$(ke,i[u].fb,[i[l].tex],S=>{e.uniform1i(S("tex"),0),e.uniform2f(S("size"),m,g),e.uniform1fv(S("a"),t.a),e.uniform1fv(S("sx"),t.sx),e.uniform1fv(S("sy"),t.sy)}):$(nt,i[u].fb,[i[l].tex],S=>{e.uniform1i(S("tex"),0),e.uniform1f(S("gain"),t.gain)});const v=n===w?u:w;b(l,n,v,Math.min(1,t.w)),o=v;continue}if(t.type==="burst"){const{w:n,h:v}=ur(m,g),[S,Y]=kt(n,v),W=cr(fr.burst*t.amount).map(Q=>lr(n,v,Q));$(C,i[u].fb,[i[l].tex],Q=>{e.uniform1i(Q("tex"),0),e.uniform1f(Q("lo"),t.lo),e.uniform1f(Q("k"),t.k)}),Mt(X,S.fb,n,v,[i[u].tex],Q=>e.uniform1i(Q("tex"),0)),Mt(te,Y.fb,n,v,[S.tex],Q=>{e.uniform1i(Q("tex"),0),e.uniform1i(Q("n"),W.length),e.uniform1fv(Q("sx"),W.map(Ee=>Ee.sw/n)),e.uniform1fv(Q("sy"),W.map(Ee=>Ee.sh/v)),e.uniform3f(Q("gain"),...pr(t.amount))}),$(N,i[w].fb,[i[l].tex,Y.tex],Q=>{e.uniform1i(Q("a"),0),e.uniform1i(Q("b"),1),e.uniform1f(Q("amount"),+t.amount.toFixed(4))}),o=w;continue}$(C,i[u].fb,[i[l].tex],n=>{e.uniform1i(n("tex"),0),e.uniform1f(n("lo"),t.lo),e.uniform1f(n("k"),t.k)}),p(u,w,u,t.sigma),$(N,i[w].fb,[i[l].tex,i[u].tex],n=>{e.uniform1i(n("a"),0),e.uniform1i(n("b"),1),e.uniform1f(n("amount"),t.amount)}),o=w}return o};let k=null,d="",E=[],z="";const B=(a,c)=>{if(z!==`${a}x${c}`){for(const i of E)e.deleteTexture(i.tex),e.deleteFramebuffer(i.fb);E=Array.from({length:4},()=>{const i=ce();e.texImage2D(e.TEXTURE_2D,0,e.RGBA8,a,c,0,e.RGBA,e.UNSIGNED_BYTE,null);const o=e.createFramebuffer();return e.bindFramebuffer(e.FRAMEBUFFER,o),e.framebufferTexture2D(e.FRAMEBUFFER,e.COLOR_ATTACHMENT0,e.TEXTURE_2D,i,0),{tex:i,fb:o}}),z=`${a}x${c}`}return E},ue=(a,c,i,o)=>{const p=e.getParameter(e.FRAMEBUFFER_BINDING),b=e.getParameter(e.VIEWPORT),t=e.isEnabled(e.BLEND),l=B(o.ew,o.eh),u=(n,v,S,Y)=>{e.bindFramebuffer(e.FRAMEBUFFER,l[v].fb),e.viewport(0,0,o.ew,o.eh),e.useProgram(n);const W=Ye(n);S.forEach((Q,Ee)=>{e.activeTexture(e.TEXTURE0+Ee),e.bindTexture(e.TEXTURE_2D,l[Q].tex)}),Y(W),e.drawArrays(e.TRIANGLE_STRIP,0,4),S.length>1&&r(),e.activeTexture(e.TEXTURE0)};e.disable(e.BLEND),e.bindFramebuffer(e.FRAMEBUFFER,l[0].fb),e.viewport(0,0,o.ew,o.eh),e.clearColor(0,0,0,0),e.clear(e.COLOR_BUFFER_BIT);{const n=Bt(a,i);e.bindFramebuffer(e.FRAMEBUFFER,l[0].fb),e.viewport(0,0,o.ew,o.eh),e.disable(e.BLEND),qe(a,[0,0,1,1],c,1,1,!1,n==="win"?null:i,n)}u(V,1,[0],n=>{e.uniform1i(n("tex"),0),e.uniform1f(n("harden"),o.harden?tr:0)});const w=(n,v,S,Y)=>{u(ie,v,[n],W=>{e.uniform1i(W("tex"),0),e.uniform2i(W("dir"),1,0),e.uniform1f(W("sigma"),Y)}),u(ie,S,[v],W=>{e.uniform1i(W("tex"),0),e.uniform2i(W("dir"),0,1),e.uniform1f(W("sigma"),Y)})};w(1,2,3,o.band),u(se,2,[1,3],n=>{e.uniform1i(n("a"),0),e.uniform1i(n("b"),1);const v=o.arc;e.uniform1f(n("arc"),v?1:0),v&&(e.uniform2f(n("cw"),o.ew/ro,o.eh/ro),e.uniform2f(n("cen"),v.cen[0],v.cen[1]),e.uniform1f(n("start"),v.start),e.uniform1f(n("cover"),v.cover),e.uniform1f(n("comet"),v.comet?1:0),e.uniform1f(n("feather"),or*v.cover))}),w(2,1,3,o.glow),u(me,1,[0,2,3],n=>{e.uniform1i(n("pic"),0),e.uniform1i(n("band"),1),e.uniform1i(n("glow"),2),e.uniform3f(n("col"),...o.col),e.uniform1f(n("k"),o.k),e.uniform1f(n("am"),o.am)}),e.bindFramebuffer(e.FRAMEBUFFER,p),e.viewport(b[0],b[1],b[2],b[3]),t&&e.enable(e.BLEND)};let K=null,J="",s=null,_=[],re="";const xe=new Map,ze=new Map,de=new Map,Ge=new Map,ae=new Map,P=new Map,Ne=ce(),Pt=(a,c)=>{const i=ce();e.texImage2D(e.TEXTURE_2D,0,e.RGBA8,a,c,0,e.RGBA,e.UNSIGNED_BYTE,null);const o=e.createFramebuffer();return e.bindFramebuffer(e.FRAMEBUFFER,o),e.framebufferTexture2D(e.FRAMEBUFFER,e.COLOR_ATTACHMENT0,e.TEXTURE_2D,i,0),{tex:i,fb:o}},jt=(a,c,i)=>{const o=e.getParameter(e.FRAMEBUFFER_BINDING),p=e.getParameter(e.VIEWPORT),b=e.isEnabled(e.BLEND),t=a.w,l=a.h;if(re!==`${t}x${l}`){for(const H of _)e.deleteTexture(H.tex),e.deleteFramebuffer(H.fb);_=Array.from({length:7},()=>Pt(t,l)),re=`${t}x${l}`}e.disable(e.BLEND),e.bindFramebuffer(e.FRAMEBUFFER,_[0].fb),e.viewport(0,0,t,l),e.clearColor(0,0,0,0),e.clear(e.COLOR_BUFFER_BIT),qe(a,[0,1,1,-1],[0,0,1,1],1,1,!1,c,"base");let u=0;const w=H=>[H[0],H[3],H[6],H[1],H[4],H[7],H[2],H[5],H[8]],n=(H,j,xt,et)=>{e.bindFramebuffer(e.FRAMEBUFFER,_[j].fb),e.viewport(0,0,t,l),e.useProgram(H);const Ie=Ye(H);xt.forEach((dt,vt)=>{e.activeTexture(e.TEXTURE0+vt),e.bindTexture(dt.d3?e.TEXTURE_3D:e.TEXTURE_2D,dt.t)}),et(Ie),e.drawArrays(e.TRIANGLE_STRIP,0,4),r()},v=H=>({t:_[H].tex}),S=(H,j,xt,et)=>{n(F,j,[v(H)],Ie=>{e.uniform1i(Ie("tex"),0),e.uniform2f(Ie("step"),1/t,0),e.uniform1f(Ie("sigma"),et)}),n(F,xt,[v(j)],Ie=>{e.uniform1i(Ie("tex"),0),e.uniform2f(Ie("step"),0,1/l),e.uniform1f(Ie("sigma"),et)})},Y=i.list,W=Y.map(H=>io(H)),Q=zi(Y),Ee=new Set;for(const[H,j]of Y.entries()){const xt=Q[H];if(H===xt&&Y.some((T,D)=>D>H&&Q[D]===H&&W[D])&&(n(X,2,[v(u)],T=>e.uniform1i(T("tex"),0)),Ee.add(H)),!W[H])continue;const et=H!==xt&&Ee.has(xt)?j.branch:void 0,Ie=et?2:u;let dt=Ne,vt=[1,1];if(j.qualifier){const T=Math.max(2,Math.trunc((t+St-1)/St)),D=Math.max(2,Math.trunc((l+St-1)/St)),I=`${T}x${D}`;let ne=xe.get(I);ne||(ne=Pt(T,D),xe.set(I,ne));const ee=j.qualifier,ve=Math.max(.001,ee.soft??.3),Ue=j.window,gt=-(Ue?.rot??0)*Math.PI/180;e.bindFramebuffer(e.FRAMEBUFFER,ne.fb),e.viewport(0,0,T,D),e.useProgram(R),e.activeTexture(e.TEXTURE0),e.bindTexture(e.TEXTURE_2D,_[Ie].tex);const Te=Ye(R);e.uniform1i(Te("tex"),0),e.uniform2f(Te("big"),t,l),e.uniform2f(Te("small"),T,D),e.uniform4f(Te("q1"),ee.hue,ee.hueWidth,Math.max(1,ve*60),Math.max(.001,ve*.2)),e.uniform4f(Te("q2"),ee.satMin,ee.satMax,ee.lumMin,ee.lumMax),e.uniform1f(Te("useQ"),1),e.uniform1f(Te("useW"),Ue?1:0),Ue&&(e.uniform4f(Te("w1"),Ue.cx,Ue.cy,Math.max(1e-4,Ue.w/2),Math.max(.001,Ue.feather??.2)),e.uniform4f(Te("w2"),Math.cos(gt),Math.sin(gt),Math.max(1e-4,Ue.h/2),Ue.type==="gradient"?2:Ue.type==="rect"?1:0)),e.uniform1f(Te("inv"),j.invert?1:0),e.drawArrays(e.TRIANGLE_STRIP,0,4),dt=ne.tex,vt=[T*St,D*St]}else if(!j.whole&&Gi(j)&&j.window?.type!=="person"){const T=`${i.clip}#${H}`,D=`${t}x${l}@${i.local??0}`,I=yo,ne=Math.max(2,Math.min(yo*2,Math.round(I*l/t)));let ee=Ge.get(T);if(ee||(ee={tex:ce(),at:""},Ge.set(T,ee)),ee.at!==D){const ve=wo(j,i.src,i.local??0,l/t,null),Ue=new Uint8Array(I*ne);for(let gt=0;gt<ne;gt++)for(let Te=0;Te<I;Te++)Ue[gt*I+Te]=Math.round(ve((Te+.5)/I,(gt+.5)/ne,0,0,0)*255);e.bindTexture(e.TEXTURE_2D,ee.tex),e.pixelStorei(e.UNPACK_ALIGNMENT,1),e.texImage2D(e.TEXTURE_2D,0,e.R8,I,ne,0,e.RED,e.UNSIGNED_BYTE,Ue),e.pixelStorei(e.UNPACK_ALIGNMENT,4),ee.at=D}dt=ee.tex,vt=[t,l]}else if(!j.whole){const T=Ro(j)?i.src?.depthMap:void 0,D=`${i.clip}#${H}@${t}x${l}${T?`@${T.at}:${T.data.length}:${T.data.slice(0,24)}`:""}`;let I=ze.get(D);if(!I){const ne=qi(j,t,l,Ro(j)?wo(j,i.src,0,l/t):null);I=ce(),e.pixelStorei(e.UNPACK_ALIGNMENT,1),e.texImage2D(e.TEXTURE_2D,0,e.R8,ne.w4,ne.h4,0,e.RED,e.UNSIGNED_BYTE,ne.px),e.pixelStorei(e.UNPACK_ALIGNMENT,4),ze.set(D,I)}dt=I,vt=[t,l]}const Lt=j.adjust??{},fo=ji(j),Jt=`${i.clip}#${H}`;let $t=de.get(Jt);if(fo&&!$t){const T=new Float32Array(1024);for(let D=0;D<256;D++)["r","g","b"].forEach((I,ne)=>{T[D*4+ne]=+$i(Lt,I,D/255,j.wheels,j.curves).toFixed(6)}),T[D*4+3]=1;$t=ce(),e.texImage2D(e.TEXTURE_2D,0,e.RGBA32F,256,1,0,e.RGBA,e.FLOAT,T);for(const D of[e.TEXTURE_MIN_FILTER,e.TEXTURE_MAG_FILTER])e.texParameteri(e.TEXTURE_2D,D,e.NEAREST);de.set(Jt,$t)}let ht=null;if(Hi(j)){const T=`${Jt}:${JSON.stringify([j.cst,j.look,j.lut,j.mixer])}`;if(ht=ae.get(T)??null,!ht){const D=Vi(j,I=>mr(I));if(!D)throw Error(`LUT "${j.lut?.name??""}" chưa tải xong`);ht=e.createTexture(),e.activeTexture(e.TEXTURE4),e.bindTexture(e.TEXTURE_3D,ht),e.pixelStorei(e.UNPACK_ALIGNMENT,1),e.texImage3D(e.TEXTURE_3D,0,e.RGB32F,D.size,D.size,D.size,0,e.RGB,e.FLOAT,D.data),e.pixelStorei(e.UNPACK_ALIGNMENT,4);for(const I of[e.TEXTURE_MIN_FILTER,e.TEXTURE_MAG_FILTER])e.texParameteri(e.TEXTURE_3D,I,e.NEAREST);for(const I of[e.TEXTURE_WRAP_S,e.TEXTURE_WRAP_T,e.TEXTURE_WRAP_R])e.texParameteri(e.TEXTURE_3D,I,e.CLAMP_TO_EDGE);e.activeTexture(e.TEXTURE0),ae.set(T,ht)}}const{sat:Co,rot:Xo}=Yi(Lt.saturation??1,Lt.hue??0);n(oe,3,[v(Ie),{t:$t??at},{t:ht??lt,d3:!0}],T=>{e.uniform1i(T("tex"),0),e.uniform1i(T("lut"),1),e.uniform1i(T("t3"),2),e.uniform1f(T("useT"),ht?1:0),e.uniform1f(T("useL"),fo?1:0),e.uniform1f(T("useS"),(Lt.saturation??1)!==1?1:0),e.uniform1f(T("useR"),(Lt.hue??0)!==0?1:0),e.uniformMatrix3fv(T("sat"),!1,w(Co)),e.uniformMatrix3fv(T("rot"),!1,w(Xo))}),e.activeTexture(e.TEXTURE2),e.bindTexture(e.TEXTURE_3D,null),e.activeTexture(e.TEXTURE0),r();let fe=3;const tt=(T,D)=>[3,4,5].find(I=>I!==T&&I!==D);if((j.blur??0)>0){const T=tt(fe),D=tt(fe,T);S(fe,T,D,Math.max(.1,+((j.blur??0)*Ki*t).toFixed(3))),fe=D}const lo=Wi({sharpness:j.sharpen??0});if(lo){const T=tt(fe);n(Ae,T,[v(fe)],D=>{e.uniform1i(D("tex"),0),e.uniform1fv(D("k"),lo),e.uniform1f(D("rdiv"),1/ir)}),fe=T}const he=j.fx?Qi(j.fx,t):null;if(he&&(he.type==="glow"||he.type==="halation")){const T=tt(fe),D=tt(fe,T);n(C,T,[v(fe)],ve=>{e.uniform1i(ve("tex"),0),e.uniform1f(ve("lo"),he.lo),e.uniform1f(ve("k"),he.k)});let I=T;he.tint&&(n(He,D,[v(T),{t:at}],ve=>{e.uniform1i(ve("tex"),0),e.uniform1i(ve("lut"),1),e.uniform1f(ve("useM"),1),e.uniform1f(ve("useL"),0),e.uniform1fv(ve("m"),he.tint.flat())}),I=D),S(I,I===T?D:T,I,he.sigma);const ee=6;n(N,ee,[v(fe),v(I)],ve=>{e.uniform1i(ve("a"),0),e.uniform1i(ve("b"),1),e.uniform1f(ve("amount"),he.amount)}),n(X,3,[v(ee)],ve=>e.uniform1i(ve("tex"),0)),fe=3}else if(he?.type==="grain"){const T=Zi(i.frame??0),D=`${T}:${t}x${l}:${he.amp}`;let I=P.get(D);if(!I){if(P.size>8){for(const ee of P.values())e.deleteTexture(ee);P.clear()}I=ce(),e.pixelStorei(e.UNPACK_ALIGNMENT,1),e.texImage2D(e.TEXTURE_2D,0,e.R8,t,l,0,e.RED,e.UNSIGNED_BYTE,Ji(T,t,l,he.amp)),e.pixelStorei(e.UNPACK_ALIGNMENT,4),P.set(D,I)}const ne=tt(fe);n(we,ne,[v(fe),{t:I}],ee=>{e.uniform1i(ee("tex"),0),e.uniform1i(ee("grain"),1)}),fe=ne}else if(he?.type==="denoise"){const T=tt(fe),D=tt(fe,T);S(fe,T,D,he.sigma),n(je,6,[v(fe),v(D)],I=>{e.uniform1i(I("tex"),0),e.uniform1i(I("soft"),1),e.uniform1f(I("t"),he.t)}),n(X,3,[v(6)],I=>e.uniform1i(I("tex"),0)),fe=3}else if(he?.type==="swirl"){const T=D=>Math.max(2,Math.round(D/2)*2);for(const D of er(t,l,he.deg)){const I=tt(fe);n(ke,I,[v(fe)],ne=>{e.uniform1i(ne("tex"),0),e.uniform2f(ne("size"),t,l),e.uniform1fv(ne("a"),D.map(ee=>+ee.a.toFixed(6))),e.uniform1fv(ne("sx"),D.map(ee=>T(t*ee.scale)/t)),e.uniform1fv(ne("sy"),D.map(ee=>T(l*ee.scale)/l))}),fe=I}}const Oo=et==="parallel"?2:u,zo=et==="parallel"?6:1-u;n(O,zo,[v(Oo),v(fe),{t:dt}],T=>{e.uniform1i(T("base"),0),e.uniform1i(T("over"),1),e.uniform1i(T("mask"),2),e.uniform2f(T("msz"),vt[0],vt[1]),e.uniform1f(T("full"),j.whole?1:0)}),et==="parallel"&&n(ye,1-u,[v(u),v(6),v(2)],T=>{e.uniform1i(T("res"),0),e.uniform1i(T("outp"),1),e.uniform1i(T("inp"),2)}),u=1-u}s=_[u].tex,e.bindFramebuffer(e.FRAMEBUFFER,o),e.viewport(p[0],p[1],p[2],p[3]),b&&e.enable(e.BLEND)},Bt=(a,c)=>K?(J!==K.key&&(jt(a,c,K),J=K.key),"win"):"pic",pt=(a,c,i,o,p,b,t)=>{if(!k){const S=Bt(a,t);qe(a,c,i,o,p,b,S==="win"?null:t,S);return}const l=Ke??[0,0,1,1];d!==k.key&&(ue(a,l,t,k),d=k.key);const u=(i[0]-l[0])/l[2],w=(i[1]-l[1])/l[3],n=i[2]/l[2],v=i[3]/l[3];qe(a,c,[u,1-w,n,-v],o,p,b,null,"edge")},qe=(a,c,i,o,p,b,t,l)=>{const u=l==="edge"||l==="win",w=l==="pic"||l==="base";if(e.useProgram(L),e.activeTexture(e.TEXTURE0),e.bindTexture(e.TEXTURE_2D,ft),w&&e.texImage2D(e.TEXTURE_2D,0,e.RGBA,e.RGBA,e.UNSIGNED_BYTE,a.source),e.uniform4f(A("dst"),c[0],c[1],c[2],c[3]),e.uniform4f(A("src"),i[0],i[1],i[2],i[3]),e.uniform1f(A("alpha"),o),e.uniform1f(A("fade"),p),e.uniform1f(A("white"),b?1:0),e.uniform1f(A("colour"),t?1:0),e.uniform1i(A("tex"),0),e.uniform1i(A("matte"),1),e.uniform1f(A("useMatte"),Ke&&(l==="pic"||l==="win")?1:0),Pe&&!u?(e.uniform4f(A("key"),Pe.u,Pe.v,Pe.similarity,Pe.blend),e.uniform4f(A("keyOpt"),1,Pe.blue?1:0,Pe.spill,a.bt709?1:0)):e.uniform4f(A("keyOpt"),0,0,0,0),e.uniform1i(A("lut1"),2),e.uniform1i(A("lut3"),3),e.uniform1f(A("useL1"),bt&&!u?1:0),e.uniform1f(A("useL3"),Gt&&!u?1:0),Ke&&e.uniform4f(A("mrect"),Ke[0],Ke[1],Ke[2],Ke[3]),e.activeTexture(e.TEXTURE1),e.bindTexture(e.TEXTURE_2D,Et),e.activeTexture(e.TEXTURE2),e.bindTexture(e.TEXTURE_2D,at),e.activeTexture(e.TEXTURE3),e.bindTexture(e.TEXTURE_3D,lt),e.activeTexture(e.TEXTURE0),e.bindTexture(e.TEXTURE_2D,l==="edge"?E[1].tex:l==="win"?s:ft),t){const n=v=>[v[0],v[3],v[6],v[1],v[4],v[7],v[2],v[5],v[8]];e.uniform1f(A("bright"),t.bright),e.uniform1f(A("contrast"),t.contrast),e.uniformMatrix3fv(A("sat"),!1,n(t.sat)),e.uniformMatrix3fv(A("rot"),!1,n(t.rot))}e.drawArrays(e.TRIANGLE_STRIP,0,4)};return{canvas:y,clear(a=1){le(null),e.clearColor(0,0,0,a),e.clear(e.COLOR_BUFFER_BIT)},pixels(){le(null);const a=new Uint8ClampedArray(m*g*4),c=m*4,i=new Uint8ClampedArray(m*g*4);e.readPixels(0,0,m,g,e.RGBA,e.UNSIGNED_BYTE,a);for(let o=0;o<g;o++){const p=(g-1-o)*c,b=o*c;for(let t=0;t<c;t+=4){const l=a[p+t+3];if(i[b+t+3]=l,l){const u=255/l;i[b+t]=a[p+t]*u,i[b+t+1]=a[p+t+1]*u,i[b+t+2]=a[p+t+2]*u}}}return i},draw(a,c,i,o,p,b,t=null,l=[],u=null){if(!l.length&&!_e&&!U.length&&!Be){le(null),e.enable(e.BLEND),e.blendFuncSeparate(e.SRC_ALPHA,e.ONE_MINUS_SRC_ALPHA,e.ONE,e.ONE_MINUS_SRC_ALPHA),pt(a,c,i,o,p,b,t);return}Le??=[De(),De(),De()],le(Le[0].fb),e.disable(e.BLEND),e.clearColor(0,0,0,0),e.clear(e.COLOR_BUFFER_BIT),pt(a,u??c,i,o,p,b,t);const w=f(l);if(le(null),e.enable(e.BLEND),e.blendFuncSeparate(e.SRC_ALPHA,e.ONE_MINUS_SRC_ALPHA,e.ONE,e.ONE_MINUS_SRC_ALPHA),_e||U.length||Be){let n=w;u&&(n=(w+1)%3,le(Le[n].fb),e.disable(e.BLEND),e.clearColor(0,0,0,0),e.clear(e.COLOR_BUFFER_BIT),e.useProgram(L),e.activeTexture(e.TEXTURE0),e.bindTexture(e.TEXTURE_2D,Le[w].tex),e.uniform4f(A("dst"),c[0],c[1],c[2],c[3]),e.uniform4f(A("src"),0,1,1,-1),e.uniform1f(A("alpha"),1),e.uniform1f(A("fade"),1),e.uniform1f(A("white"),0),e.uniform1f(A("colour"),0),e.uniform1f(A("useMatte"),0),e.drawArrays(e.TRIANGLE_STRIP,0,4)),ut(n);return}if(!u){$(X,null,[Le[w].tex],n=>e.uniform1i(n("tex"),0));return}e.useProgram(L),e.activeTexture(e.TEXTURE0),e.bindTexture(e.TEXTURE_2D,Le[w].tex),e.uniform4f(A("dst"),c[0],c[1],c[2],c[3]),e.uniform4f(A("src"),0,1,1,-1),e.uniform1f(A("alpha"),1),e.uniform1f(A("fade"),1),e.uniform1f(A("white"),0),e.uniform1f(A("colour"),0),e.uniform1f(A("useMatte"),0),e.drawArrays(e.TRIANGLE_STRIP,0,4)},warp(a,c,i,o,p,b,t,l,u,w=null,n=null,v=[]){const S=Fe();le(S[0].fb),e.disable(e.BLEND),e.clearColor(0,0,0,0),e.clear(e.COLOR_BUFFER_BIT),pt(a,c,i,o,p,b,t);const Y=f(l),W=_e||U.length||Be||v.length?(Y+1)%3:-1;W>=0?(le(S[W].fb),e.disable(e.BLEND),e.clearColor(0,0,0,0),e.clear(e.COLOR_BUFFER_BIT)):(le(null),e.enable(e.BLEND),e.blendFuncSeparate(e.SRC_ALPHA,e.ONE_MINUS_SRC_ALPHA,e.ONE,e.ONE_MINUS_SRC_ALPHA)),n&&(e.enable(e.SCISSOR_TEST),e.scissor(n[0],g-n[1]-n[3],n[2],n[3])),$(Qe,W>=0?S[W].fb:null,[S[Y].tex],Q=>{e.uniform1i(Q("tex"),0),e.uniform2f(Q("size"),m,g),e.uniform1f(Q("keepPre"),0),e.uniformMatrix3fv(Q("inv"),!1,[u[0],u[3],u[6],u[1],u[4],u[7],u[2],u[5],u[8]]),e.uniform4f(Q("rnd"),w?.[0]??0,w?.[1]??0,w?.[2]??0,w?1:0)}),e.disable(e.SCISSOR_TEST),W>=0&&ut(v.length?f(v,W):W)},adjust(a,c,i){const o=Fe();if(le(null),e.bindTexture(e.TEXTURE_2D,Tt),e.copyTexImage2D(e.TEXTURE_2D,0,e.RGBA8,0,0,m,g,0),le(o[0].fb),e.disable(e.BLEND),e.useProgram(L),e.activeTexture(e.TEXTURE0),e.bindTexture(e.TEXTURE_2D,Tt),e.uniform4f(A("dst"),0,0,1,1),e.uniform4f(A("src"),0,1,1,-1),e.uniform1i(A("tex"),0),e.uniform1f(A("alpha"),1),e.uniform1f(A("fade"),1),e.uniform1f(A("white"),0),e.uniform1f(A("useMatte"),0),e.uniform1f(A("colour"),a?1:0),a){const b=t=>[t[0],t[3],t[6],t[1],t[4],t[7],t[2],t[5],t[8]];e.uniform1f(A("bright"),a.bright),e.uniform1f(A("contrast"),a.contrast),e.uniformMatrix3fv(A("sat"),!1,b(a.sat)),e.uniformMatrix3fv(A("rot"),!1,b(a.rot))}e.drawArrays(e.TRIANGLE_STRIP,0,4);const p=f(c);le(null),e.enable(e.BLEND),e.blendFuncSeparate(e.SRC_ALPHA,e.ONE_MINUS_SRC_ALPHA,e.ONE,e.ONE_MINUS_SRC_ALPHA),e.useProgram(L),e.activeTexture(e.TEXTURE0),e.bindTexture(e.TEXTURE_2D,o[p].tex),e.uniform4f(A("dst"),0,0,1,1),e.uniform4f(A("src"),0,1,1,-1),e.uniform1f(A("alpha"),i),e.uniform1f(A("fade"),1),e.uniform1f(A("white"),0),e.uniform1f(A("colour"),0),e.uniform1f(A("useMatte"),0),e.drawArrays(e.TRIANGLE_STRIP,0,4)},grade(a,c){if(bt=!!a,Gt=!!c,a&&Oe.l1!==a.key){const i=new Float32Array(1024);for(let o=0;o<256;o++)i[o*4]=a.r[o],i[o*4+1]=a.g[o],i[o*4+2]=a.b[o],i[o*4+3]=1;e.activeTexture(e.TEXTURE2),e.bindTexture(e.TEXTURE_2D,at),e.texImage2D(e.TEXTURE_2D,0,e.RGBA32F,256,1,0,e.RGBA,e.FLOAT,i);for(const o of[e.TEXTURE_MIN_FILTER,e.TEXTURE_MAG_FILTER])e.texParameteri(e.TEXTURE_2D,o,e.NEAREST);e.activeTexture(e.TEXTURE0),Oe.l1=a.key}if(c&&Oe.l3!==c.key){e.activeTexture(e.TEXTURE3),e.bindTexture(e.TEXTURE_3D,lt),e.pixelStorei(e.UNPACK_ALIGNMENT,1),e.texImage3D(e.TEXTURE_3D,0,e.RGB32F,c.size,c.size,c.size,0,e.RGB,e.FLOAT,c.data),e.pixelStorei(e.UNPACK_ALIGNMENT,4);for(const i of[e.TEXTURE_MIN_FILTER,e.TEXTURE_MAG_FILTER])e.texParameteri(e.TEXTURE_3D,i,e.NEAREST);for(const i of[e.TEXTURE_WRAP_S,e.TEXTURE_WRAP_T,e.TEXTURE_WRAP_R])e.texParameteri(e.TEXTURE_3D,i,e.CLAMP_TO_EDGE);e.activeTexture(e.TEXTURE0),Oe.l3=c.key}},key(a){if(!a){Pe=null;return}const[c,i,o]=[1,3,5].map(b=>parseInt(a.color.slice(b,b+2),16)),p=224/255;Pe={u:Math.round(-.168736*p*c-.331264*p*i+.5*p*o+128),v:Math.round(.5*p*c-.418688*p*i-.081312*p*o+128),similarity:a.similarity,blend:a.blend,spill:+a.spill.toFixed(3),blue:o>i}},mode(a){_e=a&&Qt[a]||0},shadow(a){U=a},glBegin(){wt??={base:ce(),a:ce(),b:ce()},le(null),e.bindTexture(e.TEXTURE_2D,wt.base),e.copyTexImage2D(e.TEXTURE_2D,0,e.RGBA8,0,0,m,g,0),e.clearColor(0,0,0,0),e.clear(e.COLOR_BUFFER_BIT)},glEnd(a,c,i){const o=wt;if(le(null),e.bindTexture(e.TEXTURE_2D,a==="a"?o.a:o.b),e.copyTexImage2D(e.TEXTURE_2D,0,e.RGBA8,0,0,m,g,0),e.disable(e.BLEND),$(X,null,[o.base],t=>e.uniform1i(t("tex"),0)),a==="a")return;let p=Rt.get(c);p||(p=h(G,mi(sr[c])),Rt.set(c,p)),yt??=De(),$(p,yt.fb,[o.a,o.b],t=>{e.uniform1i(t("glFrom"),0),e.uniform1i(t("glTo"),1),e.uniform1f(t("progress"),Math.max(0,Math.min(1,i))),e.uniform1f(t("ratio"),m/g),e.uniform1f(t("glPremul"),1)});const b=_e;_e=0,Je(yt.tex),_e=b},blurBegin(){be??=De(),le(be.fb),e.clearColor(0,0,0,0),e.clear(e.COLOR_BUFFER_BIT),Be=!0},blurEnd(){Be=!1;const a=Fe();e.disable(e.BLEND),$(x,a[0].fb,[be.tex],c=>e.uniform1i(c("tex"),0)),ut(0)},windows(a){K=a},edge(a){k=a},warpBig(a,c,i,o,p,b,t,l,u,w=[]){const n=Dt(u),v=m*u,S=g*u;e.bindFramebuffer(e.FRAMEBUFFER,n.plane.fb),e.viewport(0,0,v,S),e.disable(e.BLEND),e.clearColor(0,0,0,0),e.clear(e.COLOR_BUFFER_BIT),pt(a,c,i,o,p,b,t);const Y=Ot(l.map(([Ee,H])=>[Ee*u,H*u]),v,S);e.bindFramebuffer(e.FRAMEBUFFER,n.out.fb),e.viewport(0,0,v,S),e.useProgram(Qe),e.activeTexture(e.TEXTURE0),e.bindTexture(e.TEXTURE_2D,n.plane.tex);const W=Ye(Qe);if(e.uniform1i(W("tex"),0),e.uniform2f(W("size"),v,S),e.uniform1f(W("keepPre"),1),e.uniform4f(W("rnd"),0,0,0,0),e.uniformMatrix3fv(W("inv"),!1,[Y[0],Y[3],Y[6],Y[1],Y[4],Y[7],Y[2],Y[5],Y[8]]),e.drawArrays(e.TRIANGLE_STRIP,0,4),le(null),e.enable(e.BLEND),e.blendFuncSeparate(e.SRC_ALPHA,e.ONE_MINUS_SRC_ALPHA,e.ONE,e.ONE_MINUS_SRC_ALPHA),!w.length&&!_e&&!U.length&&!Be){$(Z,null,[n.out.tex],Ee=>{e.uniform1i(Ee("tex"),0),e.uniform1i(Ee("ss"),u)});return}const Q=Fe();e.disable(e.BLEND),$(Z,Q[0].fb,[n.out.tex],Ee=>{e.uniform1i(Ee("tex"),0),e.uniform1i(Ee("ss"),u)}),ut(f(w,0))},matte(a,c=[0,0,1,1]){Ke=a?c:null,a&&(e.activeTexture(e.TEXTURE1),e.bindTexture(e.TEXTURE_2D,Et),e.texImage2D(e.TEXTURE_2D,0,e.RGBA,e.RGBA,e.UNSIGNED_BYTE,a),e.activeTexture(e.TEXTURE0))},overlay(a,c){le(null),e.enable(e.BLEND),e.blendFuncSeparate(e.SRC_ALPHA,e.ONE_MINUS_SRC_ALPHA,e.ONE,e.ONE_MINUS_SRC_ALPHA),c&&(e.activeTexture(e.TEXTURE0),e.bindTexture(e.TEXTURE_2D,ft),e.texImage2D(e.TEXTURE_2D,0,e.RGBA,c.w,c.h,0,e.RGBA,e.UNSIGNED_BYTE,c.data)),$(st,null,c?[ft]:[],i=>{e.uniform1i(i("tex"),0),e.uniform1f(i("usetex"),c?1:0),e.uniform4f(i("colour"),...a??[0,0,0,0])})},finish(){e.finish()}}}let Ce="";const qa=()=>Ce;async function _a(m,{format:g,encode:y=null,tracks:e={},camera:q=null,signal:h,onProgress:L,frames:M,software:V=!1,liveMotion:ie=!1,range:se,only:me,sink:pe}){const x=performance.now(),{width:R,height:F,fps:C}=ao(g);Ce="layers",await Promise.all([...new Set(m.filter(r=>!r.colorBypass).flatMap(r=>Ht(r.grade).map(f=>f?.lut?.id)).filter(r=>!!r))].map(r=>nr(r))),Go(uo(m.filter(r=>!r.disabled)));const N=m.filter(r=>!r.disabled&&!Uo(r)),X=uo(N),te=qo(N.reduce((r,f)=>Math.max(r,f.start+f.duration),0)),oe=Math.round(te*C);if(!(oe>0)&&!M)throw Error("Empty timeline");const O=jo(q)?q:null,Ae=$o(X,e,O?r=>Xi(r,O,R,F):void 0),we=r=>Ae.find(f=>r>=f.start-1e-6&&r<f.start+f.duration-1e-6)??null,je=()=>{if(h?.aborted)throw new DOMException("Export cancelled","AbortError")},ye=r=>ie&&!M&&!!r.motion&&!r._virtual&&!r.warped,We=r=>M||me!=="audio"&&(!se||r.start<se.to/C+1e-6&&r.start+r.duration>se.from/C-1e-6),$e=new Cr,nt=[...N.filter(r=>Kt(r)&&!ye(r)),...Ho(N)].filter(We);nt.length&&await(await Nt(async()=>{const{renderTitleFrames:r}=await import("./titleFrames-C8kvflgT.js");return{renderTitleFrames:r}},__vite__mapDeps([0,1,2,3,4,5,6,7,8,9]))).renderTitleFrames(nt,g,$e,h);const Me=new Map;if(N.some(r=>ye(r)&&We(r))){const r=await Nt(()=>import("./titleFrames-C8kvflgT.js"),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9]));for(const f of N.filter(k=>ye(k)&&We(k)))Me.set(f.id,r.liveMotion(f,N,g))}N.some(r=>r.kind==="model")&&await(await Nt(async()=>{const{render3DFrames:r}=await import("./timeline3dExport-Uo0S0CR0.js");return{render3DFrames:r}},__vite__mapDeps([10,1,11,12,13,8,6,7,14,9]))).render3DFrames(m.filter(r=>!r.disabled),g,$e,h,q);for(const r of X.filter(f=>f._group&&f.comp)){const f=[],k=Math.max(1,Math.ceil(r.duration*C-1e-6));await _a(dr(vr(r),{W:R,H:F}),{format:g,signal:h,frames:{times:Array.from({length:k},(d,E)=>xr(r,E/C)),push:(d,E)=>{f[d]=E}}}),$e.frames.set(r.id,f)}const st=performance.now();je(),Ce="mattes";const Qe=N.filter(r=>r.mask||r.person),Re=Qe.length?await Nt(()=>import("./rotoMatte-7b7Ow64f.js").then(r=>r.r),__vite__mapDeps([15,1,8,6,7,16])):null;Re&&await Re.prepareMattes(Qe);const He=Re?document.createElement("canvas"):null;Ce="media";const Ze=new Map,Se=new Map,Xe=new Map,it=r=>{let f=Ze.get(r);return f||(f=new _r({source:new Ar(r,{getRetryDelay:No}),formats:Fr}),Ze.set(r,f)),f};for(const r of N){if(r.kind==="video"&&!Se.has(r.url)){const f=await it(r.url).getPrimaryVideoTrack();f&&Se.set(r.url,new yr(f))}if(r.kind==="image"&&!Kt(r)&&!oo(r)&&!r._group&&!Xe.has(r.url)){const f=await createImageBitmap(await Ir(r.url,h),{imageOrientation:"from-image",premultiplyAlpha:"none",colorSpaceConversion:"none"});Xe.set(r.url,{source:f,w:f.width,h:f.height,close:()=>f.close()})}}const Z=new Map,ge=async(r,f)=>{const k=Me.get(r.id);if(k)return{source:await k.frame(Math.round((f-r.start)*C)),w:k.W,h:k.H};const d=$e.frames.get(r.id);if(!d?.length)return null;let E=d.length===1?0:Math.max(0,Math.min(Math.round((f-r.start)*C),Math.ceil(r.duration*C)-1,d.length-1));for(;E>0&&d[E]==="=";)E--;const z=Z.get(r.id);if(z&&z.index===E)return z.pic;z?.pic?.close?.();const B=await createImageBitmap(await(await fetch(`data:image/webp;base64,${d[E]}`)).blob(),{premultiplyAlpha:"none",colorSpaceConversion:"none"}),ue={source:B,w:B.width,h:B.height,close:()=>B.close()};return Z.set(r.id,{index:E,pic:ue}),ue},ct=N.filter(r=>Vo(r)),Ve=ct.length?await Nt(()=>import("./captionLayout-cckQ7p-t.js"),__vite__mapDeps([17,1])):null,ke=new Map,rt=new Map;if(Ve){for(const r of new Set(ct.flatMap(f=>[eo(Yo(f.captionStyle).font),eo(mo(f.captionStyle).font)])))if(await Ve.captionFontReady(r.id),!ke.has(r.id)){const f=new Uint8Array(await(await fetch(`/fonts/${r.file}`,{signal:h})).arrayBuffer());let k="";for(let d=0;d<f.length;d+=32768)k+=String.fromCharCode(...f.subarray(d,d+32768));ke.set(r.id,`@font-face{font-family:'${r.family}';src:url(data:font/${r.file.endsWith(".otf")?"otf":"ttf"};base64,${btoa(k)})}`)}}const Ye=new Map,A=async(r,f,k)=>{let d=Ye.get(f.start);if(!d||d.owner!==r){const _=pi(r,f.start,f.duration);d={plan:_,starts:xi(_.entries,C),owner:r},Ye.clear(),Ye.set(f.start,d)}const E=k-Math.round(f.start*C);let z=-1;for(let _=0;_<d.starts.length&&d.starts[_]<=E;_++)z=_;const B=d.plan.entries[z];if(!B||B.blank)return null;const ue=d.plan.social?d.plan.social.style:mo(r.captionStyle),K=d.plan.social?di(d.plan.social,B.gi,R,F,Ve.measureCaption):vi({width:R,height:F,text:B.text,style:ue,measure:Ve.measureCaption,second:B.second}),J=hi(K,ue,d.plan.social?B.scale:1,R,F,B.active,B.motion);let s=rt.get(J);if(!s){const _=eo(ue.font),re=URL.createObjectURL(new Blob([J.replace("<defs>",`<defs><style>${ke.get(_.id)??""}</style>`)],{type:"image/svg+xml"}));try{const xe=new Image(R,F);xe.src=re,await xe.decode();const ze=await createImageBitmap(xe,{premultiplyAlpha:"none"});s={source:ze,w:R,h:F,close:()=>ze.close()}}finally{URL.revokeObjectURL(re)}if(rt.size>64){const[xe,ze]=rt.entries().next().value;ze.close?.(),rt.delete(xe)}rt.set(J,s)}return s},ce=[0,0,1,1],ft=new Map,Et=["x","y","zoom","rot","sx","sy"],Ke=(r,f,k,d)=>{const E=`${r.id}@${f.start}`;let z=ft.get(E);if(!z){const ue=Math.max(1,Math.ceil(f.duration/.1-1e-6)),K=Array.from({length:ue+1},(_,re)=>f.start+f.duration*re/ue),J=K.map(_=>to(r,_-r.start,R,F)),s=_=>+(+_).toFixed(3);z={ts:K.map(_=>+_.toFixed(5)),v:Object.fromEntries(Et.map(_=>[_,J.map(re=>s(re[_]??(_==="sx"||_==="sy"?1:0)))]))},ft.set(E,z)}const B={...d};for(const ue of Et){const K=z.v[ue];if(K.every(re=>re===K[0])){B[ue]=K[0];continue}let J=z.ts.findIndex((re,xe)=>xe<z.ts.length-1&&k<z.ts[xe+1]);J<0&&(J=z.ts.length-2);const s=+(K[J+1]-K[J]).toFixed(3),_=z.ts[J+1]-z.ts[J];B[ue]=Math.abs(K[J+1]-K[J])<1e-4?K[J]:K[J]+s*Math.max(0,Math.min(1,(k-z.ts[J])/_))}return B},at=new Map,lt=new Map,Oe=(r,f,k,d=r,E="")=>{if(!gi(d))return Fo(d,R);const z=`${r.id}${E}@${f.start}`;let B=lt.get(z);B||(B=Ei(d,{offset:f.start-r.start,duration:f.duration,fps:C}),lt.set(z,B));const ue=k-Math.round(f.start*C),K=B.find(J=>ue>=J.from&&ue<J.to)??B[B.length-1];return Fo({effects:bi(d,K.t)},R)},bt=new Map,Gt=(r,f,k)=>{const d=`${r.id}@${f.start}`;bt.has(d)||bt.set(d,O?Bi(r,O,f.start,f.duration,R,F):null);const E=bt.get(d);return E?Oe(r,f,k,E,":dof"):[]},Pe=new Map,Qt=r=>{const f=JSON.stringify(r.grade);let k=Pe.get(f);if(!k){const d=B=>Array.from(B,ue=>+ue.toFixed(6)),E=Ri(r.grade)?_i(r.grade):null,z=r.grade.mixer&&Fi(r.grade.mixer)?Ai(r.grade.mixer):null;k={l1:E?{key:`1${f}`,r:d(E.r),g:d(E.g),b:d(E.b)}:null,l3:z?{key:`3${f}`,size:z.size,data:Float32Array.from(z.data,B=>+B.toFixed(6))}:null},Pe.set(f,k)}return k};let _e=null;const Tt=async(r,f,k)=>{const d=N.find(B=>B.id===r);if(!d||f<d.start||f>=d.start+d.duration)return null;if(Kt(d)){const B=await ge(d,f);return B&&{source:B.source,w:B.w,h:B.h}}if(d.kind==="image"){const B=Xe.get(d.url);return B?{source:B.source,w:B.w,h:B.h}:null}if(d.kind!=="video")return null;const E=await Mo(mt,Se,d,f,C,Math.max(k.start,d.start),k.duration);if(!E)return null;const z=E.toVideoFrame();return{source:z,w:E.displayWidth,h:E.displayHeight,close:()=>z.close()}};Ce="output";const U=Ra(R,F),wt=no(y,{width:R,height:F,fps:C},so),yt=y?.codec==="hevc",Rt=y?.container==="mov",Be=!M&&!pe&&te*wt/8>15e7&&!!navigator.storage?.getDirectory;let be=null,_t;if(Be){const r=await navigator.storage.getDirectory(),f=`gpu-export-${crypto.randomUUID()}.${Rt?"mov":"mp4"}`,k=await r.getFileHandle(f,{create:!0});be={dir:r,handle:k,name:f},_t=new Ao(await k.createWritable(),{chunked:!0,chunkSize:1<<20})}else _t=pe&&!M?new Ao(pe,{chunked:!0,chunkSize:1<<22}):new Sr;const ut=pe&&!M?!1:Be?"reserve":"in-memory",Je=new Dr({format:Rt?new Ur({fastStart:ut}):new kr({fastStart:ut}),target:_t}),Le=new Pr(U.canvas,{codec:yt?"hevc":"avc",bitrate:wt,keyFrameInterval:2,...yt?{hardwareAcceleration:"prefer-hardware"}:V?{hardwareAcceleration:"prefer-software"}:{}}),Fe=me==="audio"?0:Math.max(0,Math.min(oe,se?.from??0)),Ft=me==="audio"?0:Math.max(Fe,Math.min(oe,se?.to??oe));me!=="audio"&&Je.addVideoTrack(Le,{frameRate:C,...Be?{maximumPacketCount:Ft-Fe+8}:{}});const Dt=new Br({codec:"aac",bitrate:Lo});me!=="video"&&Je.addAudioTrack(Dt,Be?{maximumPacketCount:Math.ceil(te*zt/1024)+16}:{}),M||await Je.start();const Ut=M?new OffscreenCanvas(R,F):null,qt=Ut?.getContext("2d"),Zt=async r=>{qt.putImageData(new ImageData(U.pixels(),R,F),0,0);const f=new Uint8Array(await(await Ut.convertToBlob({type:"image/webp",quality:.9})).arrayBuffer());let k="";for(let d=0;d<f.length;d+=32768)k+=String.fromCharCode(...f.subarray(d,d+32768));M.push(r,btoa(k))},mt=new Map;let At=0;const kt={decode:0,matte:0,titles:0,captions:0,encode:0},De=async(r,f)=>{const k=performance.now();try{return await f}finally{kt[r]+=performance.now()-k}},le=(r,f)=>{const k=performance.now();try{return f()}finally{kt[r]+=performance.now()-k}};try{for(let f=M?0:Fe,k=M?M.times.length:Ft;f<k;f++){je(),Ce="frame";const d=M?M.times[f]:f/C,E=we(d);U.clear(M?0:1);const z=E&&Ve?Ko(N,E.start+1e-5,e):void 0,B=z&&E?Wo(E.visuals,z.captionStyle?.layerTrack):-1,ue=async()=>{const K=z&&E&&await De("captions",A(z,E,f));K&&(U.shadow([]),U.edge(null),U.windows(null),U.matte(null),U.mode(void 0),U.key(null),U.grade(null,null),U.draw(K,ce,ce,1,1,!1,null,[]))};for(const[K,J]of(E?.visuals??[]).entries()){let s=J;if(K===B&&await ue(),s.kind==="audio")continue;const _=E?po(s,E.start,E.start+E.duration):null,re=_?s._txIn===_?"b":"a":null,xe=_?Qo(_,d):0,ze=_&&re?_.spec.gl?.id??null:null;ze&&U.glBegin();e:{if(s.kind==="model"){U.matte(null),U.edge(null),U.windows(null),U.mode(void 0),U.shadow(xo(s,R)),U.key(null),U.grade(null,null);const o=await ge(s,d);o&&U.draw(o,ce,ce,1,1,!1,null,[]);break e}const de=d-s.start,Ge=to(s,de,R,F),ae=(Zo(s)||Jo(s))&&!_&&!(O&&Vt(s))&&!s.pin?Ke(s,E,d,Ge):Ge;if(!(ae.opacity>1e-4))break e;if(oo(s)){U.adjust(ot(s),Oe(s,E,f),Math.min(1,ae.opacity));break e}let P=null,Ne=null;if(Kt(s)||s._group)P=await De("titles",ge(s,d));else if(s.kind==="image")P=Xe.get(s.url)??null;else if(s.kind==="video"){const o=await De("decode",Mo(mt,Se,s,d,C,E.start,E.duration));o&&(Ne=o.toVideoFrame(),P={source:Ne,w:o.displayWidth,h:o.displayHeight,bt709:Ne.colorSpace?.matrix?Ne.colorSpace.matrix==="bt709":o.displayHeight>=720})}if(!P)break e;if(ei(s)){const o=s.crop||{left:0,right:0,top:0,bottom:0},p=Math.floor(P.w*o.left/2)*2,b=Math.floor(P.h*o.top/2)*2,t=Math.max(2,Math.floor(P.w*(1-o.left-o.right)/2)*2),l=Math.max(2,Math.floor(P.h*(1-o.top-o.bottom)/2)*2),u=s.distort.displace?await Tt(s.distort.displace.map,d,E):null;_e??=wr();const w=_e.render({source:P.source,srcW:P.w,srcH:P.h,rect:[p,b,t,l],outW:t,outH:l,distort:s.distort,local:de,map:u?.source??null,matte:Re&&(s.mask||s.person)?Re.matteCanvas(s,de,He,!1,N):null});u?.close?.(),P={source:w,w:t,h:l,bt709:P.bt709},s={...s,crop:void 0,mask:void 0,person:void 0}}if(Re&&(s.mask||s.person)){const o=s.crop||{left:0,right:0,top:0,bottom:0},p=Math.max(2,Math.floor(P.w*(1-o.left-o.right)/2)*2),b=Math.max(2,Math.floor(P.h*(1-o.top-o.bottom)/2)*2);U.matte(le("matte",()=>Re.matteCanvas(s,de,He,!1,N)),[o.left,o.top,p/P.w,b/P.h])}else U.matte(null);U.mode(s.blend),U.key(s.key),U.shadow(xo(s,R));{const o=s.colorBypass?[]:Ht(s.grade).filter(io);U.windows(o.length?{key:`${s.id}@${f}`,list:Ht(s.grade),clip:s.id,src:s,frame:Math.round((d-s.start)*C),local:Math.round((d-s.start)*C)/C}:null)}if(vo(s)&&ho(go(s),de)>.001){const o=go(s),p=Re&&(s.mask||s.person),b=s.crop||{left:0,right:0,top:0,bottom:0},t=p?Math.max(2,Math.floor(p.mw*(1-b.left-b.right)/2)*2):P.w,l=p?Math.max(2,Math.floor(p.mh*(1-b.top-b.bottom)/2)*2):P.h,u=t>=l?Yt:Math.max(8,Math.trunc(Yt*t/l/8)*8),w=t>=l?Math.max(8,Math.trunc(Yt*l/t/8)*8):Yt,n=ti(o),v=ho(o,de),S=!!o.keys?.length||o.amount<.999;U.edge({key:`${s.id}@${f}`,ew:u,eh:w,band:n.band,glow:n.glow,k:o.glow,col:[1,3,5].map(Y=>parseInt(o.color.slice(Y,Y+2),16)/255),am:S?Math.trunc(255*v):255,harden:!!p,arc:o.cover>=.999&&!o.comet?null:{cen:p?oi(s):[.5,.5],start:(o.angle+o.sweep*de)*Math.PI/180,cover:o.cover,comet:!!o.comet}})}else U.edge(null);{const o=s.grade&&!s.colorBypass?Qt(s):null;U.grade(o?.l1??null,o?.l3??null)}if(s.pin&&!(O&&Vt(s))&&E&&Eo(s,N,E.start,R,F,O)){const o=Eo(s,N,d,R,F,O)??[[0,0],[0,0],[0,0],[0,0]],p=It(s,de),b=ii(s,N,R,F,O),t=s.pin.dive,l=b&&!s.pin.scene?[+(b[0]*R).toFixed(3),+(b[1]*F).toFixed(3),t?Math.max(0,Math.min(1,(d-t.at)/t.dur)):0]:null;U.warp(P,Ct([0,0,1,1],R,F),_o(s,P.w,P.h),Math.min(1,ae.opacity),p.k,p.white,ot(s),Oe(s,E,f),Ot(o,R,F),l),Ne?.close();break e}const Pt=ri(s,"rot")||ai(s),jt=()=>s.motionBlur?Tr(d,C).map(o=>({...to(s,o-s.start,R,F),rot:ae.rot,opacity:ae.opacity})):[ae];if((Pt||Math.abs(ae.rot||0)>1e-9)&&!(O&&Vt(s))){const o=It(s,de),p=_&&re?[...Do(_.spec[re],xe,R,F,d,_.spec.zoomAt),...re==="b"&&_.spec.mask?[So(_.spec.mask,xe)]:[]]:[];s.motionBlur&&U.blurBegin();for(const b of jt()){const t=hr(s,P.w,P.h,R,F,b,Pt);U.warp(P,Ct([0,0,1,1],R,F),_o(s,P.w,P.h),Math.min(1,ae.opacity),o.k,o.white,ot(s),[],Ot(t.quad,R,F),null,t.clip,p)}s.motionBlur&&U.blurEnd(),Ne?.close();break e}if(O&&Vt(s)){const o=ni(s,de,O,d,R,F);if(o){const p=Xt(s,P.w,P.h,R,F,{x:0,y:0,zoom:1}),b=It(s,de),t=Oe(s,E,f);let l=at.get(s.id);l===void 0&&(l=s.effects?.some(w=>!w.off)||s.mask||s.person||vo(s)||!s.colorBypass&&Ht(s.grade).some(io)?1:si(ci(s,O,R,F),P.w,P.h,R,F),at.set(s.id,l));const u=Gt(s,E,f);l>1&&!t.length?U.warpBig(P,Ct(p.dst,R,F),p.src,Math.min(1,ae.opacity),b.k,b.white,ot(s),o.quad,l,u):U.warp(P,Ct(p.dst,R,F),p.src,Math.min(1,ae.opacity),b.k,b.white,ot(s),t,Ot(o.quad,R,F),null,null,u)}Ne?.close();break e}if(s.motionBlur&&!_&&!Oe(s,E,f).length){const o=It(s,de);U.blurBegin();for(const p of jt()){const b=Xt(s,P.w,P.h,R,F,p);U.draw(P,b.dst,b.src,Math.min(1,ae.opacity),o.k,o.white,ot(s),[])}U.blurEnd(),Ne?.close();break e}const{dst:Bt,src:pt}=Xt(s,P.w,P.h,R,F,ae),qe=It(s,de),a=[...Oe(s,E,f),..._&&re?Do(_.spec[re],xe,R,F,d,_.spec.zoomAt):[],..._&&re==="b"&&_.spec.mask?[So(_.spec.mask,xe)]:[]],c=_&&re?_.spec[re]?.rot:null;if(c){const o=Wt(c,xe)??0;U.warp(P,Ct([0,0,1,1],R,F),pt,Math.min(1,ae.opacity),qe.k,qe.white,ot(s),[],Ot(gr(Bt,R,F,o),R,F),null,null,a),Ne?.close();break e}if(a.length>0&&!!E&&!s.layout&&!po(s,E.start,E.start+E.duration)&&fi(s,E.start,E.start+E.duration,R,F)){const o=Xt(s,P.w,P.h,R,F,{x:0,y:0,zoom:1}),p=Xt({},R,F,R,F,ae);U.draw(P,p.dst,o.src,Math.min(1,ae.opacity),qe.k,qe.white,ot(s),a,o.dst)}else U.draw(P,Bt,pt,Math.min(1,ae.opacity),qe.k,qe.white,ot(s),a);Ne?.close()}if(ze&&U.glEnd(re,ze,xe),_&&re==="b"){if(_.spec.light){const Ge=Math.max(2,Math.ceil(R/bo)),ae=Math.max(2,Math.ceil(F/bo));U.overlay(null,{data:li(_.spec,xe,Ge,ae),w:Ge,h:ae})}const de=_.spec.flash;if(de){const Ge=Wt(de.opacity,xe)??0;if(Ge>1e-4){const ae=parseInt(de.color.slice(1),16);U.overlay([(ae>>16&255)/255,(ae>>8&255)/255,(ae&255)/255,Math.min(1,Ge)],null)}}}}B>=0&&B>=(E?.visuals.length??0)&&await ue();for(const[K,J]of mt){const s=K.split(`
198
- `)[0],_=X.find(re=>re.id===s);(!_||d>_.start+_.duration+1)&&(J.current?.close(),J.peek?.close(),await J.iterator.return?.(),mt.delete(K))}if(M){await Zt(f);continue}Ce="video encode",await De("encode",Le.add((f-Fe)/C,1/C)),L?.((me==="video"?1:.9)*(f+1-Fe)/Math.max(1,Ft-Fe))}if(M)return{blob:new Blob,ms:{titles:0,video:0,audio:0,total:Math.round(performance.now()-x)}};const r=performance.now();if(me==="video")Le.close(),Ce="finalize",await Je.finalize();else{Ce="audio";const f=new Map(X.map(d=>[d.id,d])),k=await Aa(N.map(d=>f.get(d.id)??d),Ae,te,e,it,h);typeof g.loudness=="number"&&Er([k.getChannelData(0),k.getChannelData(1)],g.loudness,zt),Ce="audio encode",await Dt.add(k),At=performance.now()-r,me!=="audio"&&Le.close(),Dt.close(),Ce="finalize",await Je.finalize()}}catch(r){throw await Je.cancel().catch(()=>{}),be&&await be.dir.removeEntry(be.name).catch(()=>{}),r}finally{for(const r of mt.values())r.current?.close(),r.peek?.close();_e?.dispose();for(const r of Xe.values())r.close?.();for(const r of Z.values())r.pic?.close?.();for(const r of Me.values())r.close();for(const r of rt.values())r.close?.();for(const r of Ze.values())r.dispose?.()}L?.(1),Ce="file";const $=be?await be.handle.getFile():pe?new Blob([]):new Blob([_t.buffer],{type:Rt?"video/quicktime":"video/mp4"});be&&setTimeout(()=>void be.dir.removeEntry(be.name).catch(()=>{}),600*1e3);const Mt=performance.now()-x;return{blob:$,ms:{titles:Math.round(st-x),video:Math.round(Mt-(st-x)-At),audio:Math.round(At),total:Math.round(Mt),parts:Object.fromEntries(Object.entries(kt).map(([r,f])=>[r,Math.round(f)]))}}}function Fa(m,g,y,e,q){const h=[new Float32Array(Math.max(1,Math.round(q*y))),new Float32Array(Math.max(1,Math.round(q*y)))],L=Math.round(Oi*y);return g.forEach((M,V)=>{if(M.silent)return;const ie=Math.round((M.t1-M.t0)*y)+(V<g.length-1?L:0),se=Math.abs(M.rate),me=Math.round(M.t0*y),pe=Math.max(0,Math.round(((M.rate>0?M.s0:M.s0-se*ie/y)-e)*y)),x=Math.min(m[0].length,Math.round(((M.rate>0?M.s0+se*ie/y:M.s0)-e)*y));if(x-pe<2)return;const R=(x-pe)/ie,F=Math.round(.06*y),C=Math.max(0,pe-F),N=Math.min(m[0].length,x+F);let X=m.map(oe=>oe.slice(C,N));M.rate<0&&X.forEach(oe=>oe.reverse());const te=Math.round((M.rate<0?N-x:pe-C)/R);X=Bo(X,R,y).map(oe=>oe.subarray(te,te+ie));for(let oe=0;oe<2;oe++)for(let O=0;O<ie&&me+O<h[oe].length;O++){const Ae=(V>0&&O<L?O/L:1)*(V<g.length-1&&O>=ie-L?(ie-O)/L:1);h[oe][me+O]+=(X[oe][O]??0)*Ae}}),h}async function Aa(m,g,y,e,q,h){const L=new OfflineAudioContext({numberOfChannels:2,length:Math.max(1,Math.round(y*zt)),sampleRate:zt}),M=1/200,V=m.filter(x=>(x.kind==="video"||x.kind==="audio")&&!x.freeze&&!Po(x)&&(x.volume??1)>0),ie=x=>(x.kind==="video"||x.kind==="audio")&&!!x.url,se=new Map;for(const x of g.flatMap(R=>R.audios))!ie(x)||se.has(x.url)||se.set(x.url,await q(x.url).getPrimaryAudioTrack().then(R=>!!R,()=>!1));const me=x=>ie(x)&&!!se.get(x.url);for(const x of V){if(h?.aborted)throw new DOMException("Export cancelled","AbortError");const R=Math.max(2,Math.ceil(x.duration/M)+1),F=new Float32Array(R);let C=!1;const N=Li(x.track,e);for(let Z=0;Z<R;Z++){const ge=x.start+Math.min(x.duration,Z*M),ct=g.find(ke=>ge>=ke.start-1e-6&&ge<ke.start+ke.duration-1e-6),Ve=ct?.audios.some(ke=>ke.id===x.id)?Ni(x,ge-x.start)*N.gain/Ii(ct.audios,me):0;F[Z]=Ve,Ve>0&&(C=!0)}if(!C)continue;const X=await q(x.url).getPrimaryAudioTrack();if(!X)continue;const te=ko(x)?Ci(x,0,x.duration):null,oe=x.playbackRate||1,O=new Mr(X),Ae=te?te.flatMap(Z=>[Z.s0,Z.s1]):[],we=te?Math.max(0,Math.min(...Ae)-.2):x.inPoint||0,je=te?Math.max(...Ae)+.2:we+x.duration*oe,ye=[];let We=we;for await(const Z of O.samples(we,je))ye.length||(We=Z.timestamp),ye.push(Z.toAudioBuffer()),Z.close();if(!ye.length)continue;const $e=ye[0].sampleRate,nt=ye.reduce((Z,ge)=>Z+ge.length,0);let Me=[new Float32Array(nt),new Float32Array(nt)],st=0;for(const Z of ye){for(let ge=0;ge<2;ge++)Me[ge].set(Z.getChannelData(Math.min(ge,Z.numberOfChannels-1)),st);st+=Z.length}te?Me=Fa(Me,te,$e,We,x.duration):oe!==1&&(Me=Bo(Me,oe,$e));const Qe=L.createBuffer(2,Me[0].length,$e);for(let Z=0;Z<2;Z++)Qe.copyToChannel(Me[Z],Z);const Re=L.createBufferSource();Re.buffer=Qe;const He=L.createGain();He.gain.value=0,He.gain.setValueCurveAtTime(F,x.start,Math.max(M,x.duration));const Ze=L.createChannelSplitter(2),Se=L.createChannelMerger(2),Xe=L.createGain(),it=L.createGain();Xe.gain.value=N.left,it.gain.value=N.right,Re.connect(He),He.connect(Ze),Ze.connect(Xe,0),Ze.connect(it,1),Xe.connect(Se,0,0),it.connect(Se,0,1),Se.connect(L.destination),Re.start(x.start,te?0:Math.max(0,we-We)/oe,x.duration)}const pe=await L.startRendering();return br([pe.getChannelData(0),pe.getChannelData(1)]),pe}export{Oa as canEncodeH264,za as canEncodeHevc,Xa as canEncodeMp4,_a as exportOnGpu,so as gpuBitrate,qa as gpuExportStage,Ga as gpuExportSupported};