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