@hyperframes/core 0.8.16 → 0.8.17
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/compiler/mediaRenderIds.d.ts +0 -1
- package/dist/compiler/mediaRenderIds.d.ts.map +1 -1
- package/dist/compiler/mediaRenderIds.js +6 -18
- package/dist/compiler/mediaRenderIds.js.map +1 -1
- package/dist/generated/runtime-inline.js +1 -1
- package/dist/generated/runtime-inline.js.map +1 -1
- package/dist/hyperframe.runtime.iife.js +1 -1
- package/package.json +4 -4
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"runtime-inline.js","sourceRoot":"","sources":["../../src/generated/runtime-inline.ts"],"names":[],"mappings":"AAAA,gFAAgF;AAChF,MAAM,YAAY,GAAW,
|
|
1
|
+
{"version":3,"file":"runtime-inline.js","sourceRoot":"","sources":["../../src/generated/runtime-inline.ts"],"names":[],"mappings":"AAAA,gFAAgF;AAChF,MAAM,YAAY,GAAW,ikgZAAikgZ,CAAC;AAE/lgZ;;;;GAIG;AACH,MAAM,UAAU,0BAA0B;IACxC,OAAO,YAAY,CAAC;AACtB,CAAC"}
|
|
@@ -365,7 +365,7 @@ ${e.replace(/<\/(script)/gi,"<\\/$1")}
|
|
|
365
365
|
`),wb=["#ifdef GL_FRAGMENT_PRECISION_HIGH","precision highp float;","#else","precision mediump float;","#endif","varying vec2 v_uv;","uniform sampler2D u_source;","uniform vec2 u_resolution;","uniform vec2 u_direction;","uniform float u_radius;","uniform float u_bloomPass;","uniform float u_threshold;","vec4 readSource(vec2 uv){"," vec4 color = texture2D(u_source, clamp(uv, vec2(0.0), vec2(1.0)));"," if (u_bloomPass > 0.5) {"," float luminance = dot(color.rgb, vec3(0.299, 0.587, 0.114));"," if (u_threshold >= 0.0 && luminance <= u_threshold) color.rgb = vec3(0.0);"," return vec4(color.rgb, 1.0);"," }"," color.rgb *= color.a;"," return color;","}","void main(){"," if (u_bloomPass > 0.5) {"," vec2 stepUv = u_direction * max(u_radius, 0.0) / max(u_resolution, vec2(1.0)) * 0.5;"," vec4 bloom = readSource(v_uv) * 0.227027;"," bloom += readSource(v_uv + stepUv) * 0.1945946;"," bloom += readSource(v_uv - stepUv) * 0.1945946;"," bloom += readSource(v_uv + stepUv * 2.0) * 0.1216216;"," bloom += readSource(v_uv - stepUv * 2.0) * 0.1216216;"," bloom += readSource(v_uv + stepUv * 3.0) * 0.054054;"," bloom += readSource(v_uv - stepUv * 3.0) * 0.054054;"," bloom += readSource(v_uv + stepUv * 4.0) * 0.016216;"," bloom += readSource(v_uv - stepUv * 4.0) * 0.016216;"," gl_FragColor = bloom;"," return;"," }"," vec2 stepUv = u_direction * max(u_radius, 0.0) / max(u_resolution, vec2(1.0)) / 12.0;"," vec4 color = readSource(v_uv) * 0.08077993;"," color += readSource(v_uv + stepUv * 1.0) * 0.07918038;"," color += readSource(v_uv - stepUv * 1.0) * 0.07918038;"," color += readSource(v_uv + stepUv * 2.0) * 0.07456928;"," color += readSource(v_uv - stepUv * 2.0) * 0.07456928;"," color += readSource(v_uv + stepUv * 3.0) * 0.06747307;"," color += readSource(v_uv - stepUv * 3.0) * 0.06747307;"," color += readSource(v_uv + stepUv * 4.0) * 0.05865827;"," color += readSource(v_uv - stepUv * 4.0) * 0.05865827;"," color += readSource(v_uv + stepUv * 5.0) * 0.04899551;"," color += readSource(v_uv - stepUv * 5.0) * 0.04899551;"," color += readSource(v_uv + stepUv * 6.0) * 0.03931982;"," color += readSource(v_uv - stepUv * 6.0) * 0.03931982;"," color += readSource(v_uv + stepUv * 7.0) * 0.03031761;"," color += readSource(v_uv - stepUv * 7.0) * 0.03031761;"," color += readSource(v_uv + stepUv * 8.0) * 0.02245983;"," color += readSource(v_uv - stepUv * 8.0) * 0.02245983;"," color += readSource(v_uv + stepUv * 9.0) * 0.01598624;"," color += readSource(v_uv - stepUv * 9.0) * 0.01598624;"," color += readSource(v_uv + stepUv * 10.0) * 0.01093238;"," color += readSource(v_uv - stepUv * 10.0) * 0.01093238;"," color += readSource(v_uv + stepUv * 11.0) * 0.00718308;"," color += readSource(v_uv - stepUv * 11.0) * 0.00718308;"," color += readSource(v_uv + stepUv * 12.0) * 0.00453456;"," color += readSource(v_uv - stepUv * 12.0) * 0.00453456;"," if (color.a > 0.0001) color.rgb /= color.a;"," gl_FragColor = color;","}"].join(`
|
|
366
366
|
`),Cb=["#ifdef GL_FRAGMENT_PRECISION_HIGH","precision highp float;","#else","precision mediump float;","#endif","varying vec2 v_uv;","uniform sampler2D u_source;","uniform sampler2D u_blurSource;","uniform vec2 u_texel;","uniform vec2 u_uvScale;","uniform vec2 u_uvOffset;","uniform float u_blurReady;","uniform float u_blur;","uniform float u_kuwaharaRadius;","vec3 readPrepared(vec2 displayUv){"," vec2 uv = (displayUv - u_uvOffset) / u_uvScale;"," vec3 color = texture2D(u_source, clamp(uv, vec2(0.0), vec2(1.0))).rgb;"," if (u_blurReady > 0.5 && u_blur > 0.0) {"," vec3 blurred = texture2D(u_blurSource, clamp(uv, vec2(0.0), vec2(1.0))).rgb;"," color = mix(color, blurred, clamp(u_blur, 0.0, 1.0));"," }"," return color;","}","void main(){"," float radius = floor(mix(2.0, 16.0, clamp(u_kuwaharaRadius, 0.0, 1.0)) + 0.5);"," vec3 sum = vec3(0.0);"," float sumSquares = 0.0;"," float count = 0.0;"," for (int offset = 0; offset <= 16; offset++) {"," if (float(offset) > radius) continue;"," vec3 color = readPrepared(v_uv + vec2(float(offset), 0.0) * u_texel);"," sum += color;"," sumSquares += dot(color, color) / 3.0;"," count += 1.0;"," }"," gl_FragColor = vec4(sum / count, sumSquares / count);","}"].join(`
|
|
367
367
|
`),_b=["#ifdef GL_FRAGMENT_PRECISION_HIGH","precision highp float;","#else","precision mediump float;","#endif","varying vec2 v_uv;","uniform sampler2D u_kuwaharaMoments;","uniform vec2 u_texel;","uniform float u_kuwaharaRadius;","uniform float u_kuwaharaSharpness;","uniform float u_kuwaharaSaturation;","void main(){"," float radius = floor(mix(2.0, 16.0, clamp(u_kuwaharaRadius, 0.0, 1.0)) + 0.5);"," vec2 origins[4];"," origins[0] = vec2(-radius, -radius);"," origins[1] = vec2(0.0, -radius);"," origins[2] = vec2(-radius, 0.0);"," origins[3] = vec2(0.0, 0.0);"," vec3 means[4];"," float variances[4];"," float minVariance = 1.0;"," for (int quadrant = 0; quadrant < 4; quadrant++) {"," vec4 moment = vec4(0.0);"," float count = 0.0;"," for (int offset = 0; offset <= 16; offset++) {"," if (float(offset) > radius) continue;"," vec2 sampleOffset = origins[quadrant] + vec2(0.0, float(offset));"," moment += texture2D(u_kuwaharaMoments, clamp(v_uv + sampleOffset * u_texel, vec2(0.0), vec2(1.0)));"," count += 1.0;"," }"," moment /= count;"," vec3 mean = moment.rgb;"," float meanSquare = moment.a * 3.0;"," float variance = max(meanSquare - dot(mean, mean), 0.0);"," means[quadrant] = mean;"," variances[quadrant] = variance;"," minVariance = min(minVariance, variance);"," }"," float exponent = 1.0 + clamp(u_kuwaharaSharpness, 0.0, 1.0) * 8.0;"," vec3 result = vec3(0.0);"," float totalWeight = 0.0;"," for (int quadrant = 0; quadrant < 4; quadrant++) {"," float weight = pow((minVariance + 0.0001) / (variances[quadrant] + 0.0001), exponent);"," result += means[quadrant] * weight;"," totalWeight += weight;"," }"," result /= max(totalWeight, 0.0001);"," float luma = dot(result, vec3(0.2126, 0.7152, 0.0722));"," float saturation = clamp(u_kuwaharaSaturation, 0.0, 1.0) * 2.0;"," gl_FragColor = vec4(clamp(mix(vec3(luma), result, saturation), 0.0, 1.0), 1.0);","}"].join(`
|
|
368
|
-
`);function Lt(e){return e instanceof HTMLVideoElement||e instanceof HTMLImageElement}function Sd(e){let t=window.getComputedStyle(e);return t.display!=="none"&&t.visibility!=="hidden"}function Ad(e,t,n){let r=e.createShader(n);return r?(e.shaderSource(r,t),e.compileShader(r),e.getShaderParameter(r,e.COMPILE_STATUS)?r:(L("runtime.colorGrading.compileShader",e.getShaderInfoLog(r)),e.deleteShader(r),null)):null}function xi(e,t=Eb){let n=Ad(e,Ab,e.VERTEX_SHADER),r=Ad(e,t,e.FRAGMENT_SHADER);if(!n||!r)return n&&e.deleteShader(n),r&&e.deleteShader(r),null;let i=e.createProgram();return i?(e.attachShader(i,n),e.attachShader(i,r),e.linkProgram(i),e.deleteShader(n),e.deleteShader(r),e.getProgramParameter(i,e.LINK_STATUS)?i:(L("runtime.colorGrading.linkProgram",e.getProgramInfoLog(i)),e.deleteProgram(i),null)):null}function pi(e,t=e.LINEAR,n=e.UNSIGNED_BYTE){let r=e.createTexture();return r?(e.bindTexture(e.TEXTURE_2D,r),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_S,e.CLAMP_TO_EDGE),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_T,e.CLAMP_TO_EDGE),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MIN_FILTER,t),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MAG_FILTER,t),e.texImage2D(e.TEXTURE_2D,0,e.RGBA,1,1,0,e.RGBA,n,null),r):null}function Tb(e,t){let n=xi(e,wb);return n?{program:n,quad:t,position:e.getAttribLocation(n,"a_pos"),source:e.getUniformLocation(n,"u_source"),resolution:e.getUniformLocation(n,"u_resolution"),direction:e.getUniformLocation(n,"u_direction"),radius:e.getUniformLocation(n,"u_radius"),bloomPass:e.getUniformLocation(n,"u_bloomPass"),threshold:e.getUniformLocation(n,"u_threshold")}:null}function Rb(e,t){let n=xi(e,Cb);return n?{program:n,quad:t,position:e.getAttribLocation(n,"a_pos"),source:e.getUniformLocation(n,"u_source"),blurSource:e.getUniformLocation(n,"u_blurSource"),texel:e.getUniformLocation(n,"u_texel"),uvScale:e.getUniformLocation(n,"u_uvScale"),uvOffset:e.getUniformLocation(n,"u_uvOffset"),blurReady:e.getUniformLocation(n,"u_blurReady"),blur:e.getUniformLocation(n,"u_blur"),radius:e.getUniformLocation(n,"u_kuwaharaRadius")}:null}function kb(e,t){let n=xi(e,_b);return n?{program:n,quad:t,position:e.getAttribLocation(n,"a_pos"),moments:e.getUniformLocation(n,"u_kuwaharaMoments"),texel:e.getUniformLocation(n,"u_texel"),radius:e.getUniformLocation(n,"u_kuwaharaRadius"),sharpness:e.getUniformLocation(n,"u_kuwaharaSharpness"),saturation:e.getUniformLocation(n,"u_kuwaharaSaturation")}:null}function ir(e,t=e.UNSIGNED_BYTE,n=e.LINEAR){let r=pi(e,n,t),i=e.createFramebuffer();if(!r||!i)return r&&e.deleteTexture(r),i&&e.deleteFramebuffer(i),null;e.bindFramebuffer(e.FRAMEBUFFER,i),e.framebufferTexture2D(e.FRAMEBUFFER,e.COLOR_ATTACHMENT0,e.TEXTURE_2D,r,0);let o=e.checkFramebufferStatus(e.FRAMEBUFFER);return e.bindFramebuffer(e.FRAMEBUFFER,null),o!==e.FRAMEBUFFER_COMPLETE?(e.deleteTexture(r),e.deleteFramebuffer(i),null):{texture:r,framebuffer:i,type:t,width:1,height:1}}function gi(e,t,n,r){t.width===n&&t.height===r||(t.width=n,t.height=r,e.bindTexture(e.TEXTURE_2D,t.texture),e.texImage2D(e.TEXTURE_2D,0,e.RGBA,n,r,0,e.RGBA,t.type,null))}function Ia(e,t,n){let r=[];for(let i of n){let o=e.getUniformLocation(t,`u_${i}`);o!==null&&r.push([i,o])}return r}function Ed(e,t,n){t&&e.deleteProgram(t);for(let r of n)r&&e.deleteTexture(r)}function Ga(e){let t=e.getContext("webgl",{alpha:!0,premultipliedAlpha:!1});if(!t)return null;let n=xi(t),r=pi(t),i=pi(t,t.NEAREST),o=pi(t,t.NEAREST);if(!n||!r||!i||!o)return Ed(t,n,[r,i,o]),null;let a=t.createBuffer();return a?(t.bindBuffer(t.ARRAY_BUFFER,a),t.bufferData(t.ARRAY_BUFFER,new Float32Array([-1,-1,1,-1,-1,1,1,1]),t.STATIC_DRAW),{gl:t,program:{program:n,texture:r,lutTexture:i,advancedTexture:o,advancedSignature:null,quad:a,position:t.getAttribLocation(n,"a_pos"),source:t.getUniformLocation(n,"u_source"),blurSource:t.getUniformLocation(n,"u_blurSource"),bloomSource:t.getUniformLocation(n,"u_bloomSource"),kuwaharaSource:t.getUniformLocation(n,"u_kuwaharaSource"),lut:t.getUniformLocation(n,"u_lut"),advanced:t.getUniformLocation(n,"u_advanced"),resolution:t.getUniformLocation(n,"u_resolution"),uvScale:t.getUniformLocation(n,"u_uvScale"),uvOffset:t.getUniformLocation(n,"u_uvOffset"),blurReady:t.getUniformLocation(n,"u_blurReady"),bloomReady:t.getUniformLocation(n,"u_bloomReady"),kuwaharaReady:t.getUniformLocation(n,"u_kuwaharaReady"),lutEnabled:t.getUniformLocation(n,"u_lutEnabled"),lutSize:t.getUniformLocation(n,"u_lutSize"),lutTextureSize:t.getUniformLocation(n,"u_lutTextureSize"),lutDomainMin:t.getUniformLocation(n,"u_lutDomainMin"),lutDomainMax:t.getUniformLocation(n,"u_lutDomainMax"),lutIntensity:t.getUniformLocation(n,"u_lutIntensity"),shadowWheel:t.getUniformLocation(n,"u_shadowWheel"),midtoneWheel:t.getUniformLocation(n,"u_midtoneWheel"),highlightWheel:t.getUniformLocation(n,"u_highlightWheel"),rgbCurvesEnabled:t.getUniformLocation(n,"u_rgbCurvesEnabled"),hueCurvesEnabled:t.getUniformLocation(n,"u_hueCurvesEnabled"),secondaryCount:t.getUniformLocation(n,"u_secondaryCount"),adjustUniforms:Ia(t,n,zr),detailUniforms:Ia(t,n,No),effectUniforms:Ia(t,n,Lo),grainSeed:t.getUniformLocation(n,"u_grainSeed"),effectTime:t.getUniformLocation(n,"u_effectTime"),paletteSize:t.getUniformLocation(n,"u_paletteSize"),palette0:t.getUniformLocation(n,"u_palette0"),palette1:t.getUniformLocation(n,"u_palette1"),palette2:t.getUniformLocation(n,"u_palette2"),palette3:t.getUniformLocation(n,"u_palette3"),palette4:t.getUniformLocation(n,"u_palette4"),palette5:t.getUniformLocation(n,"u_palette5"),intensity:t.getUniformLocation(n,"u_intensity"),compareEnabled:t.getUniformLocation(n,"u_compareEnabled"),comparePosition:t.getUniformLocation(n,"u_comparePosition"),compareSoftness:t.getUniformLocation(n,"u_compareSoftness"),compareLineWidth:t.getUniformLocation(n,"u_compareLineWidth")}}):(Ed(t,n,[r,i,o]),null)}function Mb(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}function Fb(e){if(!Mb(e))return{...rn};let t=(n,r,i,o)=>{let a=typeof n=="number"?n:Number(n);return Math.min(o,Math.max(i,Number.isFinite(a)?a:r))};return{enabled:e.enabled===!0,position:t(e.position,rn.position,0,1),softness:t(e.softness,rn.softness,0,.25),lineWidth:t(e.lineWidth,rn.lineWidth,0,12)}}function Fd(e){try{let t=new URL(e,document.baseURI);return t.protocol==="data:"?{href:t.href}:t.protocol!=="http:"&&t.protocol!=="https:"?{error:"LUT must be project-local or a data URL"}:t.origin!==window.location.origin?{error:"Remote LUT URLs are not supported"}:{href:t.href}}catch{return{error:"Invalid LUT URL"}}}function yi(e){return e instanceof Error?e.message:"LUT failed to load"}function Nb(e){let t=2166136261;for(let n=0;n<e.length;n+=1)t^=e.charCodeAt(n),t=Math.imul(t,16777619);return(t>>>0)%1e4}function Nd(e){let t=e.id||e.currentSrc||e.getAttribute("src")||`${e.tagName}:${Array.prototype.indexOf.call(e.parentNode?.children??[],e)}`;return Nb(t)}function Ba(e){let t=Fd(e);if("error"in t)return{state:"error",message:t.error};let n=it.get(t.href);if(n)return n;let r=fetch(t.href,{credentials:"same-origin"}).then(o=>{if(!o.ok)throw new Error(`Failed to load LUT (${o.status})`);return o.text()}).then(o=>Ul(o,{maxSize:Br})),i={state:"pending",promise:r};for(;it.size>=hb;){let o=it.keys().next().value;if(!o)break;it.delete(o)}return it.set(t.href,i),r.then(o=>{it.get(t.href)===i&&it.set(t.href,{state:"ready",lut:o})},o=>{it.get(t.href)===i&&it.set(t.href,{state:"error",message:yi(o)})}),i}function wd(e,t,n){if(e.lut?.src===t)return e.lut;let r=Eo(n),{gl:i,program:o}=e;try{return Ld(i,o.lutTexture,r),e.lut={src:t,size:n.size,domainMin:n.domainMin,domainMax:n.domainMax,textureWidth:r.width,textureHeight:r.height},e.lutError=null,e.lutLoadingSrc=null,e.lut}catch(a){return e.lut=null,e.lutError=yi(a),e.lutLoadingSrc=null,L("runtime.colorGrading.uploadLut",a),null}}async function Lb(e){let t=Ba(e);if(t.state==="ready")return t.lut;if(t.state==="pending")return t.promise;throw new Error(t.message)}function Ld(e,t,n){e.activeTexture(e.TEXTURE2),e.bindTexture(e.TEXTURE_2D,t),e.pixelStorei(e.UNPACK_FLIP_Y_WEBGL,!1),e.texImage2D(e.TEXTURE_2D,0,e.RGBA,n.width,n.height,0,e.RGBA,e.UNSIGNED_BYTE,n.data)}function Db(e,t,n){let r=Eo(n),{gl:i,program:o}=e;return Ld(i,o.lutTexture,r),{src:t,size:n.size,domainMin:n.domainMin,domainMax:n.domainMax,textureWidth:r.width,textureHeight:r.height}}function Je(e,t){e.deleteTexture(t.texture),e.deleteFramebuffer(t.framebuffer)}function Ua(e){let t=e.effectTargets;t&&(e.gl.deleteProgram(t.blurProgram.program),Je(e.gl,t.scratch),Je(e.gl,t.blur),t.bloom&&Je(e.gl,t.bloom),e.effectTargets=null)}function Wa(e){let t=e.kuwaharaTargets;t&&(e.gl.deleteProgram(t.horizontalProgram.program),e.gl.deleteProgram(t.resolveProgram.program),Je(e.gl,t.moments),Je(e.gl,t.output),e.kuwaharaTargets=null)}function hi(e,t=!1){Ua(e),Wa(e),Ib(e.gl,e.program),t&&e.gl.getExtension("WEBGL_lose_context")?.loseContext()}function Ib(e,t){e.deleteTexture(t.texture),e.deleteTexture(t.lutTexture),e.deleteTexture(t.advancedTexture),e.deleteBuffer(t.quad),e.deleteProgram(t.program)}function Pb(e){let t=Ga(e.canvas);return t?(hi(e),e.gl=t.gl,e.program=t.program,e.lut=null,e.lutLoadingSrc=null,e.lutError=null,e.effectError=null,!0):!1}function Ha(e){if(!e.sourceHidden)return;e.element.removeAttribute(Nn);let t=e.element.style.getPropertyValue("opacity"),n=e.element.style.getPropertyPriority("opacity");t==="0"&&n==="important"&&(e.sourceInlineOpacity===null?e.element.style.removeProperty("opacity"):e.element.style.setProperty("opacity",e.sourceInlineOpacity,e.sourceInlineOpacityPriority)),e.sourceHidden=!1}function Ob(e){if(e.effectTargets)return e.effectTargets;let{gl:t}=e,n=Tb(t,e.program.quad),r=ir(t),i=ir(t);return!n||!r||!i?(n&&t.deleteProgram(n.program),r&&Je(t,r),i&&Je(t,i),e.effectError="Framebuffer effects unavailable",null):(e.effectError=null,e.effectTargets={blurProgram:n,scratch:r,blur:i,bloom:null},e.effectTargets)}function Hb(e,t){return t.bloom||(t.bloom=ir(e.gl),e.effectError=t.bloom?null:"Framebuffer effects unavailable"),t.bloom}function Cd(e){let t=e.effectTargets;t?.bloom&&(Je(e.gl,t.bloom),t.bloom=null)}function Gb(e){if(e.kuwaharaTargets)return e.kuwaharaTargets;let{gl:t}=e,n=t.getExtension("OES_texture_half_float"),r=t.getExtension("EXT_color_buffer_half_float");if(!n||!r)return e.effectError="Kuwahara requires half-float framebuffer support",null;let i=Rb(t,e.program.quad),o=kb(t,e.program.quad),a=ir(t,n.HALF_FLOAT_OES,t.NEAREST),l=ir(t);return!i||!o||!a||!l?(Bb(t,i,o,a,l),e.effectError="Kuwahara framebuffer effects unavailable",null):(e.kuwaharaTargets={horizontalProgram:i,resolveProgram:o,moments:a,output:l},e.kuwaharaTargets)}function Bb(e,t,n,r,i){t&&e.deleteProgram(t.program),n&&e.deleteProgram(n.program),r&&Je(e,r),i&&Je(e,i)}function Dd(e,t,n,r,i){let o=Math.max(1,Math.ceil(r)),a=Math.max(1,Math.ceil(i));return gi(e,t,o,a),gi(e,n,o,a),{width:o,height:a}}function bi(e,t,n,r,i,o,a,l=!1,s=-1){e.bindFramebuffer(e.FRAMEBUFFER,r.framebuffer),e.viewport(0,0,i.width,i.height),e.useProgram(t.program),e.activeTexture(e.TEXTURE0),e.bindTexture(e.TEXTURE_2D,n),e.uniform1i(t.source,0),e.uniform2f(t.resolution,i.width,i.height),e.uniform2f(t.direction,o.x,o.y),e.uniform1f(t.radius,a),e.uniform1f(t.bloomPass,l?1:0),e.uniform1f(t.threshold,s),or(e,t)}function Ub(e,t,n,r,i,o,a){let l=Dd(e,t.scratch,r,i/2,o/2),s=a/2;bi(e,t.blurProgram,n,t.scratch,l,{x:1,y:0},s,!0,.5),bi(e,t.blurProgram,t.scratch.texture,r,l,{x:0,y:1},s,!0)}function Wb(e,t,n,r,i,o,a){let l=n;for(let s=0;s<Math.max(1,Math.floor(a));s++)bi(e,t.blurProgram,l,t.scratch,i,{x:1,y:0},o),bi(e,t.blurProgram,t.scratch.texture,r,i,{x:0,y:1},o),l=r.texture}function or(e,t){e.bindBuffer(e.ARRAY_BUFFER,t.quad),e.enableVertexAttribArray(t.position),e.vertexAttribPointer(t.position,2,e.FLOAT,!1,0,0),e.drawArrays(e.TRIANGLE_STRIP,0,4)}function Vb(e,t,n,r,i,o,a,l){gi(e,t.moments,i.width,i.height),gi(e,t.output,i.width,i.height);let s=t.horizontalProgram;e.bindFramebuffer(e.FRAMEBUFFER,t.moments.framebuffer),e.viewport(0,0,i.width,i.height),e.useProgram(s.program),e.activeTexture(e.TEXTURE0),e.bindTexture(e.TEXTURE_2D,n),e.activeTexture(e.TEXTURE1),e.bindTexture(e.TEXTURE_2D,r),e.uniform1i(s.source,0),e.uniform1i(s.blurSource,1),e.uniform2f(s.texel,1/i.width,1/i.height),e.uniform2f(s.uvScale,o.scaleX,o.scaleY),e.uniform2f(s.uvOffset,o.offsetX,o.offsetY),e.uniform1f(s.blurReady,a?1:0),e.uniform1f(s.blur,l.blur),e.uniform1f(s.radius,l.kuwaharaRadius),or(e,s);let u=t.resolveProgram;e.bindFramebuffer(e.FRAMEBUFFER,t.output.framebuffer),e.useProgram(u.program),e.activeTexture(e.TEXTURE0),e.bindTexture(e.TEXTURE_2D,t.moments.texture),e.uniform1i(u.moments,0),e.uniform2f(u.texel,1/i.width,1/i.height),e.uniform1f(u.radius,l.kuwaharaRadius),e.uniform1f(u.sharpness,l.kuwaharaSharpness),e.uniform1f(u.saturation,l.kuwaharaSaturation),or(e,u)}function zb(e,t,n,r){if(n<=0)return!1;let i=Dd(e.gl,t.scratch,t.blur,r.width,r.height);return Wb(e.gl,t,e.program.texture,t.blur,i,.75+Math.pow(n,1.35)*32,n>.55?3:2),!0}function qb(e,t,n,r,i,o){if(n<=0)return Cd(e),null;o||Cd(e);let a=o?Hb(e,t):t.blur;return a?(Ub(e.gl,t,e.program.texture,a,i.width,i.height,r),a.texture):null}function $b(e,t,n,r){let{program:i}=e,o=t.effects.blur,a=t.effects.bloom;if(o<=0&&a<=0)return e.effectTargets&&r&&Ua(e),{blurReady:!1,bloomReady:!1,blurTexture:i.texture,bloomTexture:i.texture};let l=Ob(e);if(!l)return{blurReady:!1,bloomReady:!1,blurTexture:i.texture,bloomTexture:i.texture};let s=zb(e,l,o,n),u=qb(e,l,a,t.effects.bloomRadius,n,s);return{blurReady:s,bloomReady:u!==null,blurTexture:l.blur.texture,bloomTexture:u??i.texture}}function jb(e,t,n,r,i,o,a){let l=t.effects.kuwahara;if(l<=0&&!o)return e.kuwaharaTargets&&a&&Wa(e),{kuwaharaReady:!1,kuwaharaTexture:e.program.texture};let s=Gb(e);return!s||l<=0?{kuwaharaReady:!1,kuwaharaTexture:s?.output.texture??e.program.texture}:(Vb(e.gl,s,e.program.texture,e.effectTargets?.blur.texture??e.program.texture,n,r,i,t.effects),{kuwaharaReady:!0,kuwaharaTexture:s.output.texture})}function Id(e,t,n,r,i={}){let o=i.releaseIdleTargets??!0;e.effectError=null;let a=$b(e,t,n,o),l=jb(e,t,n,r,a.blurReady,i.preserveKuwahara??!1,o);return{...a,...l}}function Kb(e){let t=e.grading.lut?.src.trim()??"",n=e.grading.lut?.intensity??1;if(!t||n<=0)return e.lut=null,e.lutLoadingSrc=null,e.lutError=null,null;let r=Fd(t);if("error"in r)return e.lut=null,e.lutLoadingSrc=null,e.lutError=r.error,null;if(e.lut?.src===r.href)return e.lut;e.lut=null;let i=Ba(t);return i.state==="ready"?wd(e,r.href,i.lut):i.state==="error"?(e.lutError=i.message,e.lutLoadingSrc=null,null):(e.lutLoadingSrc!==r.href&&(e.lutLoadingSrc=r.href,e.lutError=null,i.promise.then(o=>{e.destroyed||e.grading.lut?.src.trim()!==t||(wd(e,r.href,o),De(e))},o=>{e.destroyed||e.grading.lut?.src.trim()!==t||(e.lut=null,e.lutError=yi(o),e.lutLoadingSrc=null,De(e))})),null)}function nr(e){if(!e)return null;if(typeof e=="string"){let t=e.trim();if(!t)return null;let n=document.getElementById(t.replace(/^#/,""));if(n&&Lt(n))return n;try{let r=document.querySelector(t);return r&&Lt(r)?r:null}catch{return null}}if(e.hfId){let t=document.querySelector(`[data-hf-id="${CSS.escape(e.hfId)}"]`);if(t&&Lt(t))return t}if(e.id){let t=document.getElementById(e.id);if(t&&Lt(t))return t}if(!e.selector)return null;try{let t=Array.from(document.querySelectorAll(e.selector)),n=Math.max(0,Math.floor(Number(e.selectorIndex??0)||0)),r=t[n]??null;return r&&Lt(r)?r:null}catch{return null}}function Pd(e){return e instanceof HTMLVideoElement?e.videoWidth>0&&e.videoHeight>0?{width:e.videoWidth,height:e.videoHeight}:null:e instanceof HTMLImageElement&&e.naturalWidth>0&&e.naturalHeight>0?{width:e.naturalWidth,height:e.naturalHeight}:null}function Od(e){return e instanceof HTMLVideoElement?e.readyState>=HTMLMediaElement.HAVE_CURRENT_DATA&&e.videoWidth>0&&e.videoHeight>0:e instanceof HTMLImageElement?e.complete&&e.naturalWidth>0&&e.naturalHeight>0:!1}function Hd(e){let t=ut(e);return t&&Od(t)?t:null}function _d(e){if(!(e instanceof HTMLVideoElement))return!1;let t=Hd(e);if(!t)return!1;let n=window.getComputedStyle(t);return n.display!=="none"&&n.visibility!=="hidden"}function Yb(e){return e instanceof HTMLImageElement&&e.classList.contains("__render_frame__")}function Xb(e,t){t.parentNode&&t.nextSibling!==e.canvas&&t.parentNode.insertBefore(e.canvas,t.nextSibling)}function Gd(e){if(e instanceof HTMLVideoElement){let t=Hd(e);if(t)return t}return Od(e)?e:null}function Td(e,t){let n=e.toLowerCase();if(n==="center")return .5;if(t==="x"){if(n==="left")return 0;if(n==="right")return 1}else{if(n==="top")return 0;if(n==="bottom")return 1}if(n.endsWith("%")){let r=Number.parseFloat(n);return Number.isFinite(r)?r/100:null}return null}function Jb(e){let t=e.trim().split(/\s+/).filter(Boolean),n=.5,r=.5;for(let i=0;i<t.length;i++){let o=t[i]??"",a=Td(o,"x"),l=Td(o,"y");if(a!==null&&(o==="left"||o==="right"||o.endsWith("%")&&i===0)){n=a;continue}if(l!==null&&(o==="top"||o==="bottom"||o.endsWith("%")&&i>0)){r=l;continue}}return{x:n,y:r}}function Bd(e,t,n,r,i,o){if(e<=0||t<=0||n<=0||r<=0)return{scaleX:1,scaleY:1,offsetX:0,offsetY:0};let a=i||"fill",l=e,s=t;if(a==="contain"||a==="cover"||a==="scale-down"){let f=a==="cover"?Math.max(e/n,t/r):Math.min(e/n,t/r);l=n*f,s=r*f,a==="scale-down"&&l>n&&s>r&&(l=n,s=r)}else a==="none"&&(l=n,s=r);let u=Jb(o||"center"),c=(e-l)*u.x/e,m=(t-s)*u.y/t;return{scaleX:l/e,scaleY:s/t,offsetX:c,offsetY:m}}function Qb(e,t){window.getComputedStyle(t).position==="static"&&(e.touchedParent||(e.touchedParent=t,e.parentInlinePosition=t.style.position||null),t.style.position="relative")}function Rd(e,t){return Math.max(0,Math.round(e>0?e:t))}function Zb(e,t){let{element:n,canvas:r}=e,i=n.parentElement;i&&Qb(e,i);let o=window.getComputedStyle(t);mu(r.style,o),r.style.pointerEvents="none",r.style.position="absolute",r.style.inset="auto",r.style.left=`${n.offsetLeft}px`,r.style.top=`${n.offsetTop}px`,r.style.right="auto",r.style.bottom="auto",r.style.width=`${n.offsetWidth}px`,r.style.height=`${n.offsetHeight}px`,r.style.display="block",r.style.opacity=e.sourceOpacityForCanvas,r.style.visibility=e.sourceVisibleForCanvas?"visible":"hidden";let a=n.getBoundingClientRect(),l=Rd(n.offsetWidth,a.width),s=Rd(n.offsetHeight,a.height);if(l<=0||s<=0)return r.style.display="none",null;let u=Math.max(1,window.devicePixelRatio||1),c=Math.round(l*u),m=Math.round(s*u);return r.width!==c&&(r.width=c),r.height!==m&&(r.height=m),{width:c,height:m}}function nn(e,t,n){e.uniform3f(t,Number.parseInt(n.slice(1,3),16)/255,Number.parseInt(n.slice(3,5),16)/255,Number.parseInt(n.slice(5,7),16)/255)}function Dt(e,t,n,r){e.set(r,(t*Ke+n)*4)}function yt(e,t){return Math.min(1,Math.max(1/255,(e*(127/t)+128)/255))}function Pa(e,t,n){return e.length>=3?Co(e,t,n):new Float32Array(Ke)}function Nt(e,t){return e[t]??0}function ex(e,t,n){let r=zt(t.red),i=zt(t.green),o=zt(t.blue),a=zt(t.master),l=Pa(n.hueVsHue,-180,180),s=Pa(n.hueVsSaturation,-1,1),u=Pa(n.hueVsLuma,-1,1);for(let c=0;c<Ke;c+=1)Dt(e,0,c,[Nt(r,c),Nt(i,c),Nt(o,c),Nt(a,c)]),Dt(e,1,c,[yt(Nt(l,c),180),yt(Nt(s,c),1),yt(Nt(u,c),1),1])}function tx(e,t,n){let r=n*yb;Dt(e,2,r,[t.key.hue.center/360,t.key.hue.range/180,t.key.hue.softness/180,1]),Dt(e,2,r+1,[t.key.saturation.min,t.key.saturation.max,t.key.saturation.softness/.5,0]),Dt(e,2,r+2,[t.key.luma.min,t.key.luma.max,t.key.luma.softness/.5,0]),Dt(e,2,r+3,[yt(t.correction.hueShift,180),yt(t.correction.saturation,1),yt(t.correction.luma,1),yt(t.correction.temperature,1)]),Dt(e,2,r+4,[yt(t.correction.tint,1),.5,.5,1])}function nx(e,t,n){let r=new Float32Array(Ke*sr*4);ex(r,e,t);let i=0;for(let o of n)o.enabled&&(tx(r,o,i),i+=1);return r}var kd=new WeakMap;function rx(e,t,n){let r=kd.get(e);if(r?.hueCurves===t&&r.secondaries===n)return r.signature;let i=JSON.stringify([e,t,n]);return kd.set(e,{hueCurves:t,secondaries:n,signature:i}),i}function ix(e,t,n,r){let{curves:i,hueCurves:o}=n,a=rx(i,o,r);if(t.advancedSignature===a)return;let l=Uint8Array.from(nx(i,o,r),kn);e.activeTexture(e.TEXTURE5),e.bindTexture(e.TEXTURE_2D,t.advancedTexture),e.pixelStorei(e.UNPACK_FLIP_Y_WEBGL,!1),e.texImage2D(e.TEXTURE_2D,0,e.RGBA,Ke,sr,0,e.RGBA,e.UNSIGNED_BYTE,l),t.advancedSignature=a}function Oa(e,t,n){e.uniform3f(t,n.hue/360,n.amount,n.level)}function Ud(e,t,n,r,i,o,a,l,s,u,c,m){e.uniform1i(t.source,0),e.uniform1i(t.blurSource,1),e.uniform1i(t.lut,2),e.uniform1i(t.kuwaharaSource,3),e.uniform1i(t.bloomSource,4),e.uniform1i(t.advanced,5),e.uniform2f(t.resolution,s.width,s.height),e.uniform2f(t.uvScale,u.scaleX,u.scaleY),e.uniform2f(t.uvOffset,u.offsetX,u.offsetY),e.uniform1f(t.blurReady,i?1:0),e.uniform1f(t.bloomReady,o?1:0),e.uniform1f(t.kuwaharaReady,a?1:0),e.uniform1f(t.lutEnabled,r?1:0),e.uniform1f(t.lutSize,r?.size??2),e.uniform2f(t.lutTextureSize,r?.textureWidth??1,r?.textureHeight??1),e.uniform3f(t.lutDomainMin,r?.domainMin[0]??0,r?.domainMin[1]??0,r?.domainMin[2]??0),e.uniform3f(t.lutDomainMax,r?.domainMax[0]??1,r?.domainMax[1]??1,r?.domainMax[2]??1),e.uniform1f(t.lutIntensity,n.lut?.intensity??0);let{curves:f,hueCurves:p,secondaries:b}=n,v=Po(f),x=Oo(p),_=Ho(b)?b.reduce((M,F)=>M+Number(F.enabled),0):0;(v||x||_>0)&&ix(e,t,n,b),Oa(e,t.shadowWheel,n.wheels.shadows),Oa(e,t.midtoneWheel,n.wheels.midtones),Oa(e,t.highlightWheel,n.wheels.highlights),e.uniform1f(t.rgbCurvesEnabled,v?1:0),e.uniform1f(t.hueCurvesEnabled,x?1:0),e.uniform1f(t.secondaryCount,_);for(let[M,F]of t.adjustUniforms)e.uniform1f(F,n.adjust[M]);for(let[M,F]of t.detailUniforms)e.uniform1f(F,n.details[M]);e.uniform1f(t.grainSeed,c),e.uniform1f(t.effectTime,m);for(let[M,F]of t.effectUniforms)e.uniform1f(F,n.effects[M]);let R=n.palette??(n.effects.engraving>0||n.effects.crosshatch>0?bb:La),T=R[R.length-1]??La[1];e.uniform1f(t.paletteSize,R.length),nn(e,t.palette0,R[0]??La[0]),nn(e,t.palette1,R[1]??T),nn(e,t.palette2,R[2]??T),nn(e,t.palette3,R[3]??T),nn(e,t.palette4,R[4]??T),nn(e,t.palette5,R[5]??T),e.uniform1f(t.intensity,n.intensity),e.uniform1f(t.compareEnabled,l.enabled?1:0),e.uniform1f(t.comparePosition,l.position),e.uniform1f(t.compareSoftness,l.softness),e.uniform1f(t.compareLineWidth,l.lineWidth)}function ox(e){if(!e.sourceHidden){let t=e.element.getAttribute(Vr);t!==null?(e.sourceInlineOpacity=t===""?null:t,e.sourceInlineOpacityPriority=""):(e.sourceInlineOpacity=e.element.style.getPropertyValue("opacity")||null,e.sourceInlineOpacityPriority=e.element.style.getPropertyPriority("opacity"))}e.element.setAttribute(Nn,"true"),e.element.style.setProperty("opacity","0","important"),e.sourceHidden=!0}function ot(e){let t=su.find(n=>n.path===e);if(!t)throw new Error(`Missing color-grading animation property: ${e}`);return t}var Wd=ot("intensity"),Vd=ot("lut.intensity"),zd=ot("adjust.exposure"),qd=ot("effects.kuwahara"),$d=[["blur",ot("effects.blur")],["bloom",ot("effects.bloom")],["kuwahara",qd],["pixelate",ot("effects.pixelate")],["ascii",ot("effects.ascii")],["dither",ot("effects.dither")]],jd=[Wd,Vd,zd,...$d.map(([,e])=>e)];function It(e,t){let n=e.style.getPropertyValue(t.name);if(!n)return null;let r=Number(n);return Number.isFinite(r)?Math.min(t.max,Math.max(t.min,r)):null}function rr(e,t){return t!==null&&(du(t)||jd.some(n=>It(e,n)!==null))}function ax(e,t){let n=null;for(let[r,i]of $d){let o=It(e,i);o!==null&&(n??(n={...t.effects}),n[r]=o)}return n}function sx(e){let{element:t,grading:n}=e,r=It(t,Wd),i=It(t,Vd),o=It(t,zd),a=ax(t,n);if(![r,i,o].some(u=>u!==null)&&a===null)return n;let s={...n,adjust:o===null?n.adjust:{...n.adjust,exposure:o},effects:a??n.effects};return r!==null&&(s.intensity=r),n.lut&&i!==null&&(s.lut={...n.lut,intensity:i}),s}function Kd(e,t,n){e.activeTexture(e.TEXTURE0),e.bindTexture(e.TEXTURE_2D,t),e.pixelStorei(e.UNPACK_FLIP_Y_WEBGL,!0),e.texImage2D(e.TEXTURE_2D,0,e.RGBA,e.RGBA,e.UNSIGNED_BYTE,n)}function Yd(e,t,n){let r=[t.texture,n.blurTexture,t.lutTexture,n.kuwaharaTexture,n.bloomTexture,t.advancedTexture];for(let[i,o]of r.entries())e.activeTexture(e.TEXTURE0+i),e.bindTexture(e.TEXTURE_2D,o)}function De(e){if(e.destroyed||e.contextLost)return!1;let t=Gd(e.element);if(!t)return e.hasDrawn||(e.canvas.style.display="none"),!1;let n=Pd(t);if(!n)return!1;let r=t instanceof HTMLElement?t:e.element,i=e.element.style.getPropertyValue("opacity"),o=e.element.style.getPropertyPriority("opacity"),a=e.sourceHidden&&i==="0"&&o==="important",l=e.element.style.getPropertyValue("visibility"),s=Yb(t);s&&Xb(e,t);let u=window.getComputedStyle(s?t:e.element);(s||!a)&&(e.sourceOpacityForCanvas=u.opacity||"1"),e.sourceVisibleForCanvas=(s||l!=="hidden")&&u.visibility!=="hidden";let c=Zb(e,r);if(!c)return!1;let m=window.getComputedStyle(r),f=Bd(c.width,c.height,n.width,n.height,m.objectFit,m.objectPosition),{gl:p,program:b}=e;try{let v=sx(e),x=Kb(e);Kd(p,b.texture,t);let _=It(e.element,qd)!==null,R=Id(e,v,c,f,{preserveKuwahara:_});p.bindFramebuffer(p.FRAMEBUFFER,null),p.viewport(0,0,c.width,c.height),p.useProgram(b.program),Yd(p,b,R);let T=window.__player?.getTime?.(),M=typeof T=="number"&&Number.isFinite(T)?Math.max(0,T):e.element instanceof HTMLVideoElement?Math.max(0,e.element.currentTime):0,F=e.grainSeed+Math.floor(M*60);return Ud(p,b,v,x,R.blurReady,R.bloomReady,R.kuwaharaReady,e.compare,c,f,F,M),or(p,b),ox(e),e.hasDrawn=!0,e.drawError=null,!0}catch(v){return e.drawError=v instanceof Error?v.message:"Shader draw failed",L("runtime.colorGrading.drawEntry",v),!1}}function lx(e,t,n){let r=e.getBoundingClientRect(),i=e.offsetWidth||r.width||t.width,o=e.offsetHeight||r.height||t.height,a=Math.min(320,Math.max(64,Math.round(n??160))),l=i>0&&o>0?i/o:t.width/t.height;return l>=1?{width:a,height:Math.max(1,Math.round(a/l))}:{width:Math.max(1,Math.round(a*l)),height:a}}function ux(){let e=document.createElement("canvas"),t=Ga(e);return t?{canvas:e,...t,lut:null,effectTargets:null,kuwaharaTargets:null,effectError:null}:null}function cx(e,t){let n=t?void 0:window.__player?.getTime?.();return typeof n=="number"&&Number.isFinite(n)?Math.max(0,n):e instanceof HTMLVideoElement?Math.max(0,e.currentTime):0}function dx(e,t,n,r){let i=Gd(t);if(!i)return null;let o=Pd(i);if(!o)return null;let a=lx(t,o,n);e.canvas.width=a.width,e.canvas.height=a.height;let l=i instanceof HTMLElement?i:t,s=window.getComputedStyle(l),u=Bd(a.width,a.height,o.width,o.height,s.objectFit,s.objectPosition);return Kd(e.gl,e.program.texture,i),{dimensions:a,uv:u,effectTime:cx(t,r),grainSeed:Nd(t)+(t instanceof HTMLVideoElement?Math.floor(t.currentTime*60):0)}}async function fx(e,t,n,r,i=!1){let o=dx(e,t,r,i);if(!o)return null;let{dimensions:a,uv:l,grainSeed:s,effectTime:u}=o,c=[];for(let m of n.slice(0,32)){let f=qr(m.grading);if(!f){c.push({id:m.id,dataUrl:null,error:"Invalid grading"});continue}let p=null;try{f.lut&&(e.lut?.src!==f.lut.src&&(e.lut=Db(e,f.lut.src,await Lb(f.lut.src))),p=e.lut),c.push({id:m.id,dataUrl:mx(e,f,p,a,l,s,u)})}catch(b){c.push({id:m.id,dataUrl:null,error:yi(b)})}}return{...a,images:c}}function mx(e,t,n,r,i,o,a){let{canvas:l,gl:s,program:u}=e,c=Id(e,t,r,i,{releaseIdleTargets:!1});return s.bindFramebuffer(s.FRAMEBUFFER,null),s.viewport(0,0,r.width,r.height),s.useProgram(u.program),Yd(s,u,c),n||(e.lut=null),Ud(s,u,t,n,c.blurReady,c.bloomReady,c.kuwaharaReady,rn,r,i,o,a),or(s,u),l.toDataURL("image/png")}function Xe(e,t,n,r){t.addEventListener(n,r),e.cleanup.push(()=>t.removeEventListener(n,r))}function px(e){e.animationFrame!==null&&(window.cancelAnimationFrame(e.animationFrame),e.animationFrame=null),e.videoFrameHandle!==null&&e.element instanceof HTMLVideoElement&&(e.element.cancelVideoFrameCallback?.(e.videoFrameHandle),e.videoFrameHandle=null)}function ar(e){if(e.destroyed||!(e.element instanceof HTMLVideoElement)||e.videoFrameHandle!==null||e.animationFrame!==null)return;let t=e.element,n=t;if(typeof n.requestVideoFrameCallback=="function"){e.videoFrameHandle=n.requestVideoFrameCallback(()=>{e.videoFrameHandle=null,De(e),!e.destroyed&&!t.paused&&!t.ended&&ar(e)});return}e.animationFrame=window.requestAnimationFrame(()=>{e.animationFrame=null,De(e),!e.destroyed&&!t.paused&&!t.ended&&ar(e)})}function hx(e){let t=()=>{De(e)};if(Xe(e,e.element,"load",t),Xe(e,e.element,"loadedmetadata",t),Xe(e,e.element,"loadeddata",t),Xe(e,e.element,"seeked",t),Xe(e,e.element,"timeupdate",t),Xe(e,window,"resize",t),e.element instanceof HTMLVideoElement&&(Xe(e,e.element,"play",()=>ar(e)),Xe(e,e.element,"pause",t)),Xe(e,e.canvas,"webglcontextlost",n=>{n.preventDefault(),e.contextLost=!0,e.drawError="WebGL context lost",e.canvas.style.display="none",Ha(e)}),Xe(e,e.canvas,"webglcontextrestored",()=>{if(e.contextLost=!1,!Pb(e)){e.contextLost=!0,e.drawError="WebGL context restore failed",Ha(e);return}e.drawError=null,De(e)}),typeof ResizeObserver<"u"&&(e.resizeObserver=new ResizeObserver(t),e.resizeObserver.observe(e.element)),typeof MutationObserver<"u"){let n=()=>{let a=e.element.style;return`${a.transform}|${a.translate}|${a.rotate}|${a.scale}|${a.left}|${a.top}|${a.width}|${a.height}`},r=n(),i=!1,o=new MutationObserver(()=>{i||n()!==r&&(i=!0,requestAnimationFrame(()=>{i=!1,r=n(),De(e)}))});o.observe(e.element,{attributes:!0,attributeFilter:["style"]}),e.cleanup.push(()=>o.disconnect())}}function gx(e){if(e.destroyed)return null;e.destroyed=!0,px(e),e.resizeObserver?.disconnect();for(let t of e.cleanup)t();return e.cleanup.length=0,e.canvas.remove(),Ua(e),Wa(e),Ha(e),e.touchedParent&&(e.parentInlinePosition===null?e.touchedParent.style.removeProperty("position"):e.touchedParent.style.position=e.parentInlinePosition),{canvas:e.canvas,gl:e.gl,program:e.program,effectTargets:null,kuwaharaTargets:null,effectError:null}}function Xd(e,t){return e.removeAttribute("style"),t.id?e.id=`${nu}${t.id}`:e.removeAttribute("id"),e.className=pb,e.setAttribute(mb,"true"),e.setAttribute("data-hyperframes-ignore",""),e.setAttribute("data-hyperframes-picker-ignore",""),e.setAttribute("data-hf-ignore",""),e.setAttribute("aria-hidden","true"),e.style.pointerEvents="none",e.style.display="none",t.parentNode?.insertBefore(e,t.nextSibling),e}function bx(e){return Xd(document.createElement("canvas"),e)}function Jd(){let e=new WeakMap,t=new Set,n=[],r=null,i=null,o=Promise.resolve(),a=!1,l=(E,S,A)=>{let C=e.get(E);if(C)return C.grading=S,C.source=A,De(C),E instanceof HTMLVideoElement&&!E.paused&&ar(C),!0;let N=n.pop();if(N)Xd(N.canvas,E);else{let W=bx(E),U=Ga(W);if(!U)return W.remove(),!1;N={canvas:W,gl:U.gl,program:U.program,effectTargets:null,kuwaharaTargets:null,effectError:null}}let I={element:E,...N,grading:S,compare:{...rn},lut:null,lutLoadingSrc:null,lutError:null,drawError:null,effectTargets:null,kuwaharaTargets:null,effectError:null,source:A,animationFrame:null,videoFrameHandle:null,resizeObserver:null,cleanup:[],touchedParent:null,parentInlinePosition:null,sourceHidden:!1,sourceInlineOpacity:null,sourceInlineOpacityPriority:"",sourceOpacityForCanvas:window.getComputedStyle(E).opacity||"1",sourceVisibleForCanvas:window.getComputedStyle(E).visibility!=="hidden",hasDrawn:!1,contextLost:!1,grainSeed:Nd(E),destroyed:!1};return e.set(E,I),t.add(E),hx(I),De(I),E instanceof HTMLVideoElement&&!E.paused&&ar(I),!0},s=(E,S)=>{if(a)return!1;let A=nr(E);if(!A)return!1;let C=e.get(A);if(!C){let N=mi(A);if(!rr(A,N)||!l(A,N,"attribute"))return!1;C=e.get(A)}return C?(C.compare=Fb(S),De(C),!0):!1},u=E=>{let S=e.get(E);if(!S)return;let A=gx(S);A&&(S.contextLost||n.length>=gb?hi(A,!0):n.push(A)),e.delete(E),t.delete(E)},c=()=>{if(a)return 0;let E=new Set;document.querySelectorAll(`video[${Fn}], img[${Fn}]`).forEach(A=>{if(!Lt(A))return;E.add(A);let C=mi(A);rr(A,C)&&(Sd(A)||_d(A))?l(A,C,"attribute"):u(A)});for(let A of t){let C=e.get(A);C&&(!A.isConnected||C.source==="attribute"&&!E.has(A))&&u(A)}return t.size},m=()=>{if(a)return 0;let E=0;for(let S of t){let A=e.get(S);A&&De(A)&&(E+=1)}return E},f=async()=>{let E=new Set;for(let S of t){let A=e.get(S)?.grading.lut;if(!A?.src.trim()||(A.intensity??1)<=0)continue;let C=Ba(A.src);C.state==="pending"&&E.add(C.promise)}return E.size>0&&await Promise.allSettled(E),m(),E.size},p=()=>{if(a)return 0;let E=0;for(let S of t){let A=e.get(S);!A||!jd.some(N=>It(S,N)!==null)||S instanceof HTMLVideoElement&&!S.paused&&!S.ended||De(A)&&(E+=1)}return E},b=(E,S)=>{if(a)return!1;let A=nr(E);if(!A)return!1;let C=qr(S);return rr(A,C)?l(A,C,"live"):(u(A),!0)},v=(E,S)=>{if(!Lt(E))return!1;let A=e.get(E);if(!A){if(!S)return!1;let C=mi(E);return rr(E,C)&&l(E,C,"attribute")}return A.sourceVisibleForCanvas=S,!S&&A.source==="attribute"&&u(E),!0},x=E=>{let S=nr(E);if(!S)return{state:"missing",message:"Media not found"};let A=e.get(S);if(A)return A.effectError?{state:"unavailable",message:A.effectError}:A.drawError?{state:"unavailable",message:A.drawError}:A.lutError?{state:"unavailable",message:`LUT error: ${A.lutError}`}:A.grading.lut&&A.lutLoadingSrc?{state:"pending",message:"Loading LUT"}:A.canvas.style.display==="none"?{state:"pending",message:"Waiting for media frame"}:{state:"active",message:A.lut?"Shader + LUT active":"Shader active"};let C=mi(S);return rr(S,C)?!Sd(S)&&!_d(S)?{state:"pending",message:"Waiting for visible media"}:{state:"unavailable",message:"WebGL unavailable"}:{state:"inactive",message:"No grading applied"}},_=async(E,S,A)=>{let C=async()=>{if(a||S.length===0)return null;let I=nr(E);return!I||(i??(i=ux()),!i)?null:fx(i,I,S,A?.maxDimension,A?.useMediaTime)},N=o.then(C,C);return o=N.then(()=>{},()=>{}),N},R=E=>{let S=nr(E);if(!(S instanceof HTMLVideoElement))return null;if(!S.paused)return()=>{};let A=S.currentTime,C=S.loop,N=S.muted;return S.loop=!0,S.muted=!0,(S.ended||Number.isFinite(S.duration)&&A>=S.duration)&&(S.currentTime=0),S.play().catch(()=>{}),()=>{S.pause(),S.loop=C,S.muted=N,S.currentTime=A}},T=()=>{if(!a){a=!0,r?.disconnect(),r=null;for(let E of t)u(E);for(let E of n)hi(E,!0);n.length=0,i&&(hi(i,!0),i=null)}};document.body&&(r=new MutationObserver(()=>c()),r.observe(document.body,{childList:!0,subtree:!0,attributes:!0,attributeFilter:[Fn]}));let M={refresh:c,redraw:m,redrawAnimated:p,waitForActiveLuts:f,setGrading:b,setCompare:s,setSourceVisibility:v,getStatus:x,renderPreviews:_,startPreviewPlayback:R,destroy:T},F=window;return F.__hf=F.__hf||{},F.__hf.colorGrading=M,c(),M}var vi=class{constructor(t){ge(this,"_baseTime",0);ge(this,"_playStartMs",null);ge(this,"_rate",1);ge(this,"_duration",1/0);ge(this,"_nowMs");ge(this,"_audioSource",null);this._baseTime=t?.initialTime??0,this._rate=t?.rate??1,this._duration=t?.duration??1/0,this._nowMs=t?.nowMs??(()=>performance.now())}now(){if(this._playStartMs===null)return this._baseTime;if(this._audioSource){let r=null;if("currentTimeSeconds"in this._audioSource)r=this._audioSource.currentTimeSeconds;else{let{el:i,compositionStart:o,mediaStart:a}=this._audioSource;!i.paused&&Number.isFinite(i.currentTime)&&(r=(i.currentTime-a)/(i.playbackRate>0?i.playbackRate:1)*this._rate+o)}if(r!==null)return Number.isFinite(this._duration)&&r>=this._duration?this._duration:Math.max(0,r)}let t=(this._nowMs()-this._playStartMs)/1e3,n=this._baseTime+t*this._rate;return Number.isFinite(this._duration)&&n>=this._duration?this._duration:Math.max(0,n)}play(){return this._playStartMs!==null||Number.isFinite(this._duration)&&this._baseTime>=this._duration?!1:(this._playStartMs=this._nowMs(),!0)}pause(){return this._playStartMs===null?!1:(this._baseTime=this.now(),this._playStartMs=null,!0)}seek(t){let n=Number.isFinite(this._duration)?Math.max(0,Math.min(t,this._duration)):Math.max(0,t);this._baseTime=n,this._playStartMs!==null&&(this._playStartMs=this._nowMs())}isPlaying(){return this._playStartMs!==null}setRate(t){let n=Number.isFinite(t)&&t>0?Math.max(.1,Math.min(5,t)):1;this._playStartMs!==null&&(this._baseTime=this.now(),this._playStartMs=this._nowMs()),this._rate=n}getRate(){return this._rate}setDuration(t){this._duration=Number.isFinite(t)&&t>0?t:1/0,this._baseTime>this._duration&&(this._baseTime=this._duration)}getDuration(){return this._duration}attachAudioSource(t){this._audioSource=t}detachAudioSource(){this._audioSource&&this._playStartMs!==null&&(this._baseTime=this.now(),this._playStartMs=this._nowMs()),this._audioSource=null}hasAudioSource(){return this._audioSource!==null}getSource(){if(this._audioSource&&this._playStartMs!==null){if("currentTimeSeconds"in this._audioSource)return"audio";let{el:t}=this._audioSource;if(!t.paused&&Number.isFinite(t.currentTime))return"audio"}return"monotonic"}snapshot(){return{time:this.now(),playing:this.isPlaying(),rate:this._rate,duration:this._duration,source:this.getSource()}}reachedEnd(){return Number.isFinite(this._duration)&&this.now()>=this._duration}};var xx=100,yx=8,vx=4096,Va=e=>e;function Sx(e,t,n){return!(!!e.curve||e.viaX!==void 0&&e.viaY!==void 0)&&t==="linear"&&!n}function Ax(e){let t=Math.ceil(e*xx);return Math.min(vx,Math.max(yx,t))}function Ex(e,t,n,r,i){let{scheduledAt:o,elapsed:a,rate:l}=r,s=i??Va,u=R=>o+(R-a)/l,c=e.points[t],m=e.points[t+1],f=u(m.t);if(f<=o)return null;let p=Math.max(o,u(c.t)),b=f-p;if(b<=0)return null;if(Sx(c,n,i))return{kind:"ramp",time:f,value:s(m.v)};let v=Ax(b),x=_l(e,Math.max(c.t,a),m.t,v,n),_=new Float32Array(v);for(let R=0;R<v;R+=1)_[R]=s(x[R]??0);return{kind:"curve",time:p,duration:b,values:_}}function wx(e,t,n,r){let i=[];for(let a=0;a+1<e.points.length;a+=1){let l=Ex(e,a,t,n,r);l&&i.push(l)}let o=i[0];return o?.kind==="curve"&&o.time<=n.scheduledAt||i.unshift({kind:"set",time:n.scheduledAt,value:(r??Va)(_n(e,n.elapsed,t))}),i}function Cx(e,t){for(let n of t)if(n.kind==="set")e.setValueAtTime(n.value,n.time);else if(n.kind==="ramp")e.linearRampToValueAtTime(n.value,n.time);else try{e.setValueCurveAtTime(n.values,n.time,n.duration)}catch{let r=n.values[n.values.length-1]??0;e.linearRampToValueAtTime(r,n.time+n.duration)}}function lr(e){for(let t of e)t.param.cancelScheduledValues(0)}function on(e,t){for(let n of e)typeof n.param.cancelAndHoldAtTime=="function"?n.param.cancelAndHoldAtTime(t):n.param.cancelScheduledValues(t)}function za(e,t,n,r){if(t.points.length!==0)for(let i of e){if(lr([i]),Cl(t)){let o=(i.map??Va)(t.points[0].v);i.param.setValueAtTime(o,r.scheduledAt);continue}Cx(i.param,wx(t,n,r,i.map))}}function Qd(e,t,n,r,i){let o=new Map(n.filter(l=>l.id).map(l=>[l.id,l.handle])),a=[];for(let l of e.lanes){let s=Cn(l.target);if(!s)continue;let u=s.kind==="preset"?i?.[s.presetId]:s.kind==="fx"?o.get(s.nodeId)?.automation?.[s.param]:void 0;if(!u||u.length===0)continue;let c=co(l.target,t);c&&(za(u,l,c.scale,r),a.push(...u))}return a}function Zd(e){return e.lanes.find(t=>t.target===Ut)??null}var _x=`
|
|
368
|
+
`);function Lt(e){return e instanceof HTMLVideoElement||e instanceof HTMLImageElement}function Sd(e){let t=window.getComputedStyle(e);return t.display!=="none"&&t.visibility!=="hidden"}function Ad(e,t,n){let r=e.createShader(n);return r?(e.shaderSource(r,t),e.compileShader(r),e.getShaderParameter(r,e.COMPILE_STATUS)?r:(L("runtime.colorGrading.compileShader",e.getShaderInfoLog(r)),e.deleteShader(r),null)):null}function xi(e,t=Eb){let n=Ad(e,Ab,e.VERTEX_SHADER),r=Ad(e,t,e.FRAGMENT_SHADER);if(!n||!r)return n&&e.deleteShader(n),r&&e.deleteShader(r),null;let i=e.createProgram();return i?(e.attachShader(i,n),e.attachShader(i,r),e.linkProgram(i),e.deleteShader(n),e.deleteShader(r),e.getProgramParameter(i,e.LINK_STATUS)?i:(L("runtime.colorGrading.linkProgram",e.getProgramInfoLog(i)),e.deleteProgram(i),null)):null}function pi(e,t=e.LINEAR,n=e.UNSIGNED_BYTE){let r=e.createTexture();return r?(e.bindTexture(e.TEXTURE_2D,r),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_S,e.CLAMP_TO_EDGE),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_T,e.CLAMP_TO_EDGE),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MIN_FILTER,t),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MAG_FILTER,t),e.texImage2D(e.TEXTURE_2D,0,e.RGBA,1,1,0,e.RGBA,n,null),r):null}function Tb(e,t){let n=xi(e,wb);return n?{program:n,quad:t,position:e.getAttribLocation(n,"a_pos"),source:e.getUniformLocation(n,"u_source"),resolution:e.getUniformLocation(n,"u_resolution"),direction:e.getUniformLocation(n,"u_direction"),radius:e.getUniformLocation(n,"u_radius"),bloomPass:e.getUniformLocation(n,"u_bloomPass"),threshold:e.getUniformLocation(n,"u_threshold")}:null}function Rb(e,t){let n=xi(e,Cb);return n?{program:n,quad:t,position:e.getAttribLocation(n,"a_pos"),source:e.getUniformLocation(n,"u_source"),blurSource:e.getUniformLocation(n,"u_blurSource"),texel:e.getUniformLocation(n,"u_texel"),uvScale:e.getUniformLocation(n,"u_uvScale"),uvOffset:e.getUniformLocation(n,"u_uvOffset"),blurReady:e.getUniformLocation(n,"u_blurReady"),blur:e.getUniformLocation(n,"u_blur"),radius:e.getUniformLocation(n,"u_kuwaharaRadius")}:null}function kb(e,t){let n=xi(e,_b);return n?{program:n,quad:t,position:e.getAttribLocation(n,"a_pos"),moments:e.getUniformLocation(n,"u_kuwaharaMoments"),texel:e.getUniformLocation(n,"u_texel"),radius:e.getUniformLocation(n,"u_kuwaharaRadius"),sharpness:e.getUniformLocation(n,"u_kuwaharaSharpness"),saturation:e.getUniformLocation(n,"u_kuwaharaSaturation")}:null}function ir(e,t=e.UNSIGNED_BYTE,n=e.LINEAR){let r=pi(e,n,t),i=e.createFramebuffer();if(!r||!i)return r&&e.deleteTexture(r),i&&e.deleteFramebuffer(i),null;e.bindFramebuffer(e.FRAMEBUFFER,i),e.framebufferTexture2D(e.FRAMEBUFFER,e.COLOR_ATTACHMENT0,e.TEXTURE_2D,r,0);let o=e.checkFramebufferStatus(e.FRAMEBUFFER);return e.bindFramebuffer(e.FRAMEBUFFER,null),o!==e.FRAMEBUFFER_COMPLETE?(e.deleteTexture(r),e.deleteFramebuffer(i),null):{texture:r,framebuffer:i,type:t,width:1,height:1}}function gi(e,t,n,r){t.width===n&&t.height===r||(t.width=n,t.height=r,e.bindTexture(e.TEXTURE_2D,t.texture),e.texImage2D(e.TEXTURE_2D,0,e.RGBA,n,r,0,e.RGBA,t.type,null))}function Ia(e,t,n){let r=[];for(let i of n){let o=e.getUniformLocation(t,`u_${i}`);o!==null&&r.push([i,o])}return r}function Ed(e,t,n){t&&e.deleteProgram(t);for(let r of n)r&&e.deleteTexture(r)}function Ga(e){let t=e.getContext("webgl",{alpha:!0,premultipliedAlpha:!1});if(!t)return null;let n=xi(t),r=pi(t),i=pi(t,t.NEAREST),o=pi(t,t.NEAREST);if(!n||!r||!i||!o)return Ed(t,n,[r,i,o]),null;let a=t.createBuffer();return a?(t.bindBuffer(t.ARRAY_BUFFER,a),t.bufferData(t.ARRAY_BUFFER,new Float32Array([-1,-1,1,-1,-1,1,1,1]),t.STATIC_DRAW),{gl:t,program:{program:n,texture:r,lutTexture:i,advancedTexture:o,advancedSignature:null,quad:a,position:t.getAttribLocation(n,"a_pos"),source:t.getUniformLocation(n,"u_source"),blurSource:t.getUniformLocation(n,"u_blurSource"),bloomSource:t.getUniformLocation(n,"u_bloomSource"),kuwaharaSource:t.getUniformLocation(n,"u_kuwaharaSource"),lut:t.getUniformLocation(n,"u_lut"),advanced:t.getUniformLocation(n,"u_advanced"),resolution:t.getUniformLocation(n,"u_resolution"),uvScale:t.getUniformLocation(n,"u_uvScale"),uvOffset:t.getUniformLocation(n,"u_uvOffset"),blurReady:t.getUniformLocation(n,"u_blurReady"),bloomReady:t.getUniformLocation(n,"u_bloomReady"),kuwaharaReady:t.getUniformLocation(n,"u_kuwaharaReady"),lutEnabled:t.getUniformLocation(n,"u_lutEnabled"),lutSize:t.getUniformLocation(n,"u_lutSize"),lutTextureSize:t.getUniformLocation(n,"u_lutTextureSize"),lutDomainMin:t.getUniformLocation(n,"u_lutDomainMin"),lutDomainMax:t.getUniformLocation(n,"u_lutDomainMax"),lutIntensity:t.getUniformLocation(n,"u_lutIntensity"),shadowWheel:t.getUniformLocation(n,"u_shadowWheel"),midtoneWheel:t.getUniformLocation(n,"u_midtoneWheel"),highlightWheel:t.getUniformLocation(n,"u_highlightWheel"),rgbCurvesEnabled:t.getUniformLocation(n,"u_rgbCurvesEnabled"),hueCurvesEnabled:t.getUniformLocation(n,"u_hueCurvesEnabled"),secondaryCount:t.getUniformLocation(n,"u_secondaryCount"),adjustUniforms:Ia(t,n,zr),detailUniforms:Ia(t,n,No),effectUniforms:Ia(t,n,Lo),grainSeed:t.getUniformLocation(n,"u_grainSeed"),effectTime:t.getUniformLocation(n,"u_effectTime"),paletteSize:t.getUniformLocation(n,"u_paletteSize"),palette0:t.getUniformLocation(n,"u_palette0"),palette1:t.getUniformLocation(n,"u_palette1"),palette2:t.getUniformLocation(n,"u_palette2"),palette3:t.getUniformLocation(n,"u_palette3"),palette4:t.getUniformLocation(n,"u_palette4"),palette5:t.getUniformLocation(n,"u_palette5"),intensity:t.getUniformLocation(n,"u_intensity"),compareEnabled:t.getUniformLocation(n,"u_compareEnabled"),comparePosition:t.getUniformLocation(n,"u_comparePosition"),compareSoftness:t.getUniformLocation(n,"u_compareSoftness"),compareLineWidth:t.getUniformLocation(n,"u_compareLineWidth")}}):(Ed(t,n,[r,i,o]),null)}function Mb(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}function Fb(e){if(!Mb(e))return{...rn};let t=(n,r,i,o)=>{let a=typeof n=="number"?n:Number(n);return Math.min(o,Math.max(i,Number.isFinite(a)?a:r))};return{enabled:e.enabled===!0,position:t(e.position,rn.position,0,1),softness:t(e.softness,rn.softness,0,.25),lineWidth:t(e.lineWidth,rn.lineWidth,0,12)}}function Fd(e){try{let t=new URL(e,document.baseURI);return t.protocol==="data:"?{href:t.href}:t.protocol!=="http:"&&t.protocol!=="https:"?{error:"LUT must be project-local or a data URL"}:t.origin!==window.location.origin?{error:"Remote LUT URLs are not supported"}:{href:t.href}}catch{return{error:"Invalid LUT URL"}}}function yi(e){return e instanceof Error?e.message:"LUT failed to load"}function Nb(e){let t=2166136261;for(let n=0;n<e.length;n+=1)t^=e.charCodeAt(n),t=Math.imul(t,16777619);return(t>>>0)%1e4}function Nd(e){let t=e.id||e.currentSrc||e.getAttribute("src")||`${e.tagName}:${Array.prototype.indexOf.call(e.parentNode?.children??[],e)}`;return Nb(t)}function Ba(e){let t=Fd(e);if("error"in t)return{state:"error",message:t.error};let n=it.get(t.href);if(n)return n;let r=fetch(t.href,{credentials:"same-origin"}).then(o=>{if(!o.ok)throw new Error(`Failed to load LUT (${o.status})`);return o.text()}).then(o=>Ul(o,{maxSize:Br})),i={state:"pending",promise:r};for(;it.size>=hb;){let o=it.keys().next().value;if(!o)break;it.delete(o)}return it.set(t.href,i),r.then(o=>{it.get(t.href)===i&&it.set(t.href,{state:"ready",lut:o})},o=>{it.get(t.href)===i&&it.set(t.href,{state:"error",message:yi(o)})}),i}function wd(e,t,n){if(e.lut?.src===t)return e.lut;let r=Eo(n),{gl:i,program:o}=e;try{return Ld(i,o.lutTexture,r),e.lut={src:t,size:n.size,domainMin:n.domainMin,domainMax:n.domainMax,textureWidth:r.width,textureHeight:r.height},e.lutError=null,e.lutLoadingSrc=null,e.lut}catch(a){return e.lut=null,e.lutError=yi(a),e.lutLoadingSrc=null,L("runtime.colorGrading.uploadLut",a),null}}async function Lb(e){let t=Ba(e);if(t.state==="ready")return t.lut;if(t.state==="pending")return t.promise;throw new Error(t.message)}function Ld(e,t,n){e.activeTexture(e.TEXTURE2),e.bindTexture(e.TEXTURE_2D,t),e.pixelStorei(e.UNPACK_FLIP_Y_WEBGL,!1),e.texImage2D(e.TEXTURE_2D,0,e.RGBA,n.width,n.height,0,e.RGBA,e.UNSIGNED_BYTE,n.data)}function Db(e,t,n){let r=Eo(n),{gl:i,program:o}=e;return Ld(i,o.lutTexture,r),{src:t,size:n.size,domainMin:n.domainMin,domainMax:n.domainMax,textureWidth:r.width,textureHeight:r.height}}function Je(e,t){e.deleteTexture(t.texture),e.deleteFramebuffer(t.framebuffer)}function Ua(e){let t=e.effectTargets;t&&(e.gl.deleteProgram(t.blurProgram.program),Je(e.gl,t.scratch),Je(e.gl,t.blur),t.bloom&&Je(e.gl,t.bloom),e.effectTargets=null)}function Wa(e){let t=e.kuwaharaTargets;t&&(e.gl.deleteProgram(t.horizontalProgram.program),e.gl.deleteProgram(t.resolveProgram.program),Je(e.gl,t.moments),Je(e.gl,t.output),e.kuwaharaTargets=null)}function hi(e,t=!1){Ua(e),Wa(e),Ib(e.gl,e.program),t&&e.gl.getExtension("WEBGL_lose_context")?.loseContext()}function Ib(e,t){e.deleteTexture(t.texture),e.deleteTexture(t.lutTexture),e.deleteTexture(t.advancedTexture),e.deleteBuffer(t.quad),e.deleteProgram(t.program)}function Pb(e){let t=Ga(e.canvas);return t?(hi(e),e.gl=t.gl,e.program=t.program,e.lut=null,e.lutLoadingSrc=null,e.lutError=null,e.effectError=null,!0):!1}function Ha(e){if(!e.sourceHidden)return;e.element.removeAttribute(Nn);let t=e.element.style.getPropertyValue("opacity"),n=e.element.style.getPropertyPriority("opacity");t==="0"&&n==="important"&&(e.sourceInlineOpacity===null?e.element.style.removeProperty("opacity"):e.element.style.setProperty("opacity",e.sourceInlineOpacity,e.sourceInlineOpacityPriority)),e.sourceHidden=!1}function Ob(e){if(e.effectTargets)return e.effectTargets;let{gl:t}=e,n=Tb(t,e.program.quad),r=ir(t),i=ir(t);return!n||!r||!i?(n&&t.deleteProgram(n.program),r&&Je(t,r),i&&Je(t,i),e.effectError="Framebuffer effects unavailable",null):(e.effectError=null,e.effectTargets={blurProgram:n,scratch:r,blur:i,bloom:null},e.effectTargets)}function Hb(e,t){return t.bloom||(t.bloom=ir(e.gl),e.effectError=t.bloom?null:"Framebuffer effects unavailable"),t.bloom}function Cd(e){let t=e.effectTargets;t?.bloom&&(Je(e.gl,t.bloom),t.bloom=null)}function Gb(e){if(e.kuwaharaTargets)return e.kuwaharaTargets;let{gl:t}=e,n=t.getExtension("OES_texture_half_float"),r=t.getExtension("EXT_color_buffer_half_float");if(!n||!r)return e.effectError="Kuwahara requires half-float framebuffer support",null;let i=Rb(t,e.program.quad),o=kb(t,e.program.quad),a=ir(t,n.HALF_FLOAT_OES,t.NEAREST),l=ir(t);return!i||!o||!a||!l?(Bb(t,i,o,a,l),e.effectError="Kuwahara framebuffer effects unavailable",null):(e.kuwaharaTargets={horizontalProgram:i,resolveProgram:o,moments:a,output:l},e.kuwaharaTargets)}function Bb(e,t,n,r,i){t&&e.deleteProgram(t.program),n&&e.deleteProgram(n.program),r&&Je(e,r),i&&Je(e,i)}function Dd(e,t,n,r,i){let o=Math.max(1,Math.ceil(r)),a=Math.max(1,Math.ceil(i));return gi(e,t,o,a),gi(e,n,o,a),{width:o,height:a}}function bi(e,t,n,r,i,o,a,l=!1,s=-1){e.bindFramebuffer(e.FRAMEBUFFER,r.framebuffer),e.viewport(0,0,i.width,i.height),e.useProgram(t.program),e.activeTexture(e.TEXTURE0),e.bindTexture(e.TEXTURE_2D,n),e.uniform1i(t.source,0),e.uniform2f(t.resolution,i.width,i.height),e.uniform2f(t.direction,o.x,o.y),e.uniform1f(t.radius,a),e.uniform1f(t.bloomPass,l?1:0),e.uniform1f(t.threshold,s),or(e,t)}function Ub(e,t,n,r,i,o,a){let l=Dd(e,t.scratch,r,i/2,o/2),s=a/2;bi(e,t.blurProgram,n,t.scratch,l,{x:1,y:0},s,!0,.5),bi(e,t.blurProgram,t.scratch.texture,r,l,{x:0,y:1},s,!0)}function Wb(e,t,n,r,i,o,a){let l=n;for(let s=0;s<Math.max(1,Math.floor(a));s++)bi(e,t.blurProgram,l,t.scratch,i,{x:1,y:0},o),bi(e,t.blurProgram,t.scratch.texture,r,i,{x:0,y:1},o),l=r.texture}function or(e,t){e.bindBuffer(e.ARRAY_BUFFER,t.quad),e.enableVertexAttribArray(t.position),e.vertexAttribPointer(t.position,2,e.FLOAT,!1,0,0),e.drawArrays(e.TRIANGLE_STRIP,0,4)}function Vb(e,t,n,r,i,o,a,l){gi(e,t.moments,i.width,i.height),gi(e,t.output,i.width,i.height);let s=t.horizontalProgram;e.bindFramebuffer(e.FRAMEBUFFER,t.moments.framebuffer),e.viewport(0,0,i.width,i.height),e.useProgram(s.program),e.activeTexture(e.TEXTURE0),e.bindTexture(e.TEXTURE_2D,n),e.activeTexture(e.TEXTURE1),e.bindTexture(e.TEXTURE_2D,r),e.uniform1i(s.source,0),e.uniform1i(s.blurSource,1),e.uniform2f(s.texel,1/i.width,1/i.height),e.uniform2f(s.uvScale,o.scaleX,o.scaleY),e.uniform2f(s.uvOffset,o.offsetX,o.offsetY),e.uniform1f(s.blurReady,a?1:0),e.uniform1f(s.blur,l.blur),e.uniform1f(s.radius,l.kuwaharaRadius),or(e,s);let u=t.resolveProgram;e.bindFramebuffer(e.FRAMEBUFFER,t.output.framebuffer),e.useProgram(u.program),e.activeTexture(e.TEXTURE0),e.bindTexture(e.TEXTURE_2D,t.moments.texture),e.uniform1i(u.moments,0),e.uniform2f(u.texel,1/i.width,1/i.height),e.uniform1f(u.radius,l.kuwaharaRadius),e.uniform1f(u.sharpness,l.kuwaharaSharpness),e.uniform1f(u.saturation,l.kuwaharaSaturation),or(e,u)}function zb(e,t,n,r){if(n<=0)return!1;let i=Dd(e.gl,t.scratch,t.blur,r.width,r.height);return Wb(e.gl,t,e.program.texture,t.blur,i,.75+Math.pow(n,1.35)*32,n>.55?3:2),!0}function qb(e,t,n,r,i,o){if(n<=0)return Cd(e),null;o||Cd(e);let a=o?Hb(e,t):t.blur;return a?(Ub(e.gl,t,e.program.texture,a,i.width,i.height,r),a.texture):null}function $b(e,t,n,r){let{program:i}=e,o=t.effects.blur,a=t.effects.bloom;if(o<=0&&a<=0)return e.effectTargets&&r&&Ua(e),{blurReady:!1,bloomReady:!1,blurTexture:i.texture,bloomTexture:i.texture};let l=Ob(e);if(!l)return{blurReady:!1,bloomReady:!1,blurTexture:i.texture,bloomTexture:i.texture};let s=zb(e,l,o,n),u=qb(e,l,a,t.effects.bloomRadius,n,s);return{blurReady:s,bloomReady:u!==null,blurTexture:l.blur.texture,bloomTexture:u??i.texture}}function jb(e,t,n,r,i,o,a){let l=t.effects.kuwahara;if(l<=0&&!o)return e.kuwaharaTargets&&a&&Wa(e),{kuwaharaReady:!1,kuwaharaTexture:e.program.texture};let s=Gb(e);return!s||l<=0?{kuwaharaReady:!1,kuwaharaTexture:s?.output.texture??e.program.texture}:(Vb(e.gl,s,e.program.texture,e.effectTargets?.blur.texture??e.program.texture,n,r,i,t.effects),{kuwaharaReady:!0,kuwaharaTexture:s.output.texture})}function Id(e,t,n,r,i={}){let o=i.releaseIdleTargets??!0;e.effectError=null;let a=$b(e,t,n,o),l=jb(e,t,n,r,a.blurReady,i.preserveKuwahara??!1,o);return{...a,...l}}function Kb(e){let t=e.grading.lut?.src.trim()??"",n=e.grading.lut?.intensity??1;if(!t||n<=0)return e.lut=null,e.lutLoadingSrc=null,e.lutError=null,null;let r=Fd(t);if("error"in r)return e.lut=null,e.lutLoadingSrc=null,e.lutError=r.error,null;if(e.lut?.src===r.href)return e.lut;e.lut=null;let i=Ba(t);return i.state==="ready"?wd(e,r.href,i.lut):i.state==="error"?(e.lutError=i.message,e.lutLoadingSrc=null,null):(e.lutLoadingSrc!==r.href&&(e.lutLoadingSrc=r.href,e.lutError=null,i.promise.then(o=>{e.destroyed||e.grading.lut?.src.trim()!==t||(wd(e,r.href,o),De(e))},o=>{e.destroyed||e.grading.lut?.src.trim()!==t||(e.lut=null,e.lutError=yi(o),e.lutLoadingSrc=null,De(e))})),null)}function nr(e){if(!e)return null;if(typeof e=="string"){let t=e.trim();if(!t)return null;let n=document.getElementById(t.replace(/^#/,""));if(n&&Lt(n))return n;try{let r=document.querySelector(t);return r&&Lt(r)?r:null}catch{return null}}if(e.hfId){let t=document.querySelector(`[data-hf-id="${CSS.escape(e.hfId)}"]`);if(t&&Lt(t))return t}if(e.id){let t=document.getElementById(e.id);if(t&&Lt(t))return t}if(!e.selector)return null;try{let t=Array.from(document.querySelectorAll(e.selector)),n=Math.max(0,Math.floor(Number(e.selectorIndex??0)||0)),r=t[n]??null;return r&&Lt(r)?r:null}catch{return null}}function Pd(e){return e instanceof HTMLVideoElement?e.videoWidth>0&&e.videoHeight>0?{width:e.videoWidth,height:e.videoHeight}:null:e instanceof HTMLImageElement&&e.naturalWidth>0&&e.naturalHeight>0?{width:e.naturalWidth,height:e.naturalHeight}:null}function Od(e){return e instanceof HTMLVideoElement?e.readyState>=HTMLMediaElement.HAVE_CURRENT_DATA&&e.videoWidth>0&&e.videoHeight>0:e instanceof HTMLImageElement?e.complete&&e.naturalWidth>0&&e.naturalHeight>0:!1}function Hd(e){let t=ut(e);return t&&Od(t)?t:null}function _d(e){if(!(e instanceof HTMLVideoElement))return!1;let t=Hd(e);if(!t)return!1;let n=window.getComputedStyle(t);return n.display!=="none"&&n.visibility!=="hidden"}function Yb(e){return e instanceof HTMLImageElement&&e.classList.contains("__render_frame__")}function Xb(e,t){t.parentNode&&t.nextSibling!==e.canvas&&t.parentNode.insertBefore(e.canvas,t.nextSibling)}function Gd(e){if(e instanceof HTMLVideoElement){let t=Hd(e);if(t)return t}return Od(e)?e:null}function Td(e,t){let n=e.toLowerCase();if(n==="center")return .5;if(t==="x"){if(n==="left")return 0;if(n==="right")return 1}else{if(n==="top")return 0;if(n==="bottom")return 1}if(n.endsWith("%")){let r=Number.parseFloat(n);return Number.isFinite(r)?r/100:null}return null}function Jb(e){let t=e.trim().split(/\s+/).filter(Boolean),n=.5,r=.5;for(let i=0;i<t.length;i++){let o=t[i]??"",a=Td(o,"x"),l=Td(o,"y");if(a!==null&&(o==="left"||o==="right"||o.endsWith("%")&&i===0)){n=a;continue}if(l!==null&&(o==="top"||o==="bottom"||o.endsWith("%")&&i>0)){r=l;continue}}return{x:n,y:r}}function Bd(e,t,n,r,i,o){if(e<=0||t<=0||n<=0||r<=0)return{scaleX:1,scaleY:1,offsetX:0,offsetY:0};let a=i||"fill",l=e,s=t;if(a==="contain"||a==="cover"||a==="scale-down"){let f=a==="cover"?Math.max(e/n,t/r):Math.min(e/n,t/r);l=n*f,s=r*f,a==="scale-down"&&l>n&&s>r&&(l=n,s=r)}else a==="none"&&(l=n,s=r);let u=Jb(o||"center"),c=(e-l)*u.x/e,m=(t-s)*u.y/t;return{scaleX:l/e,scaleY:s/t,offsetX:c,offsetY:m}}function Qb(e,t){window.getComputedStyle(t).position==="static"&&(e.touchedParent||(e.touchedParent=t,e.parentInlinePosition=t.style.position||null),t.style.position="relative")}function Rd(e,t){return Math.max(0,Math.round(e>0?e:t))}function Zb(e,t){let{element:n,canvas:r}=e,i=n.parentElement;i&&Qb(e,i);let o=window.getComputedStyle(t);mu(r.style,o),r.style.pointerEvents="none",r.style.position="absolute",r.style.inset="auto",r.style.left=`${n.offsetLeft}px`,r.style.top=`${n.offsetTop}px`,r.style.right="auto",r.style.bottom="auto",r.style.width=`${n.offsetWidth}px`,r.style.height=`${n.offsetHeight}px`,r.style.display="block",r.style.opacity=e.sourceOpacityForCanvas,r.style.visibility=e.sourceVisibleForCanvas?"visible":"hidden";let a=n.getBoundingClientRect(),l=Rd(n.offsetWidth,a.width),s=Rd(n.offsetHeight,a.height);if(l<=0||s<=0)return r.style.display="none",null;let u=Math.max(1,window.devicePixelRatio||1),c=Math.round(l*u),m=Math.round(s*u);return r.width!==c&&(r.width=c),r.height!==m&&(r.height=m),{width:c,height:m}}function nn(e,t,n){e.uniform3f(t,Number.parseInt(n.slice(1,3),16)/255,Number.parseInt(n.slice(3,5),16)/255,Number.parseInt(n.slice(5,7),16)/255)}function Dt(e,t,n,r){e.set(r,(t*Ke+n)*4)}function yt(e,t){return Math.min(1,Math.max(1/255,(e*(127/t)+128)/255))}function Pa(e,t,n){return e.length>=3?Co(e,t,n):new Float32Array(Ke)}function Nt(e,t){return e[t]??0}function ex(e,t,n){let r=zt(t.red),i=zt(t.green),o=zt(t.blue),a=zt(t.master),l=Pa(n.hueVsHue,-180,180),s=Pa(n.hueVsSaturation,-1,1),u=Pa(n.hueVsLuma,-1,1);for(let c=0;c<Ke;c+=1)Dt(e,0,c,[Nt(r,c),Nt(i,c),Nt(o,c),Nt(a,c)]),Dt(e,1,c,[yt(Nt(l,c),180),yt(Nt(s,c),1),yt(Nt(u,c),1),1])}function tx(e,t,n){let r=n*yb;Dt(e,2,r,[t.key.hue.center/360,t.key.hue.range/180,t.key.hue.softness/180,1]),Dt(e,2,r+1,[t.key.saturation.min,t.key.saturation.max,t.key.saturation.softness/.5,0]),Dt(e,2,r+2,[t.key.luma.min,t.key.luma.max,t.key.luma.softness/.5,0]),Dt(e,2,r+3,[yt(t.correction.hueShift,180),yt(t.correction.saturation,1),yt(t.correction.luma,1),yt(t.correction.temperature,1)]),Dt(e,2,r+4,[yt(t.correction.tint,1),.5,.5,1])}function nx(e,t,n){let r=new Float32Array(Ke*sr*4);ex(r,e,t);let i=0;for(let o of n)o.enabled&&(tx(r,o,i),i+=1);return r}var kd=new WeakMap;function rx(e,t,n){let r=kd.get(e);if(r?.hueCurves===t&&r.secondaries===n)return r.signature;let i=JSON.stringify([e,t,n]);return kd.set(e,{hueCurves:t,secondaries:n,signature:i}),i}function ix(e,t,n,r){let{curves:i,hueCurves:o}=n,a=rx(i,o,r);if(t.advancedSignature===a)return;let l=Uint8Array.from(nx(i,o,r),kn);e.activeTexture(e.TEXTURE5),e.bindTexture(e.TEXTURE_2D,t.advancedTexture),e.pixelStorei(e.UNPACK_FLIP_Y_WEBGL,!1),e.texImage2D(e.TEXTURE_2D,0,e.RGBA,Ke,sr,0,e.RGBA,e.UNSIGNED_BYTE,l),t.advancedSignature=a}function Oa(e,t,n){e.uniform3f(t,n.hue/360,n.amount,n.level)}function Ud(e,t,n,r,i,o,a,l,s,u,c,m){e.uniform1i(t.source,0),e.uniform1i(t.blurSource,1),e.uniform1i(t.lut,2),e.uniform1i(t.kuwaharaSource,3),e.uniform1i(t.bloomSource,4),e.uniform1i(t.advanced,5),e.uniform2f(t.resolution,s.width,s.height),e.uniform2f(t.uvScale,u.scaleX,u.scaleY),e.uniform2f(t.uvOffset,u.offsetX,u.offsetY),e.uniform1f(t.blurReady,i?1:0),e.uniform1f(t.bloomReady,o?1:0),e.uniform1f(t.kuwaharaReady,a?1:0),e.uniform1f(t.lutEnabled,r?1:0),e.uniform1f(t.lutSize,r?.size??2),e.uniform2f(t.lutTextureSize,r?.textureWidth??1,r?.textureHeight??1),e.uniform3f(t.lutDomainMin,r?.domainMin[0]??0,r?.domainMin[1]??0,r?.domainMin[2]??0),e.uniform3f(t.lutDomainMax,r?.domainMax[0]??1,r?.domainMax[1]??1,r?.domainMax[2]??1),e.uniform1f(t.lutIntensity,n.lut?.intensity??0);let{curves:f,hueCurves:p,secondaries:b}=n,v=Po(f),x=Oo(p),_=Ho(b)?b.reduce((M,F)=>M+Number(F.enabled),0):0;(v||x||_>0)&&ix(e,t,n,b),Oa(e,t.shadowWheel,n.wheels.shadows),Oa(e,t.midtoneWheel,n.wheels.midtones),Oa(e,t.highlightWheel,n.wheels.highlights),e.uniform1f(t.rgbCurvesEnabled,v?1:0),e.uniform1f(t.hueCurvesEnabled,x?1:0),e.uniform1f(t.secondaryCount,_);for(let[M,F]of t.adjustUniforms)e.uniform1f(F,n.adjust[M]);for(let[M,F]of t.detailUniforms)e.uniform1f(F,n.details[M]);e.uniform1f(t.grainSeed,c),e.uniform1f(t.effectTime,m);for(let[M,F]of t.effectUniforms)e.uniform1f(F,n.effects[M]);let R=n.palette??(n.effects.engraving>0||n.effects.crosshatch>0?bb:La),T=R[R.length-1]??La[1];e.uniform1f(t.paletteSize,R.length),nn(e,t.palette0,R[0]??La[0]),nn(e,t.palette1,R[1]??T),nn(e,t.palette2,R[2]??T),nn(e,t.palette3,R[3]??T),nn(e,t.palette4,R[4]??T),nn(e,t.palette5,R[5]??T),e.uniform1f(t.intensity,n.intensity),e.uniform1f(t.compareEnabled,l.enabled?1:0),e.uniform1f(t.comparePosition,l.position),e.uniform1f(t.compareSoftness,l.softness),e.uniform1f(t.compareLineWidth,l.lineWidth)}function ox(e){if(!e.sourceHidden){let t=e.element.getAttribute(Vr);t!==null?(e.sourceInlineOpacity=t===""?null:t,e.sourceInlineOpacityPriority=""):(e.sourceInlineOpacity=e.element.style.getPropertyValue("opacity")||null,e.sourceInlineOpacityPriority=e.element.style.getPropertyPriority("opacity"))}e.element.setAttribute(Nn,"true"),e.element.style.setProperty("opacity","0","important"),e.sourceHidden=!0}function ot(e){let t=su.find(n=>n.path===e);if(!t)throw new Error(`Missing color-grading animation property: ${e}`);return t}var Wd=ot("intensity"),Vd=ot("lut.intensity"),zd=ot("adjust.exposure"),qd=ot("effects.kuwahara"),$d=[["blur",ot("effects.blur")],["bloom",ot("effects.bloom")],["kuwahara",qd],["pixelate",ot("effects.pixelate")],["ascii",ot("effects.ascii")],["dither",ot("effects.dither")]],jd=[Wd,Vd,zd,...$d.map(([,e])=>e)];function It(e,t){let n=e.style.getPropertyValue(t.name);if(!n)return null;let r=Number(n);return Number.isFinite(r)?Math.min(t.max,Math.max(t.min,r)):null}function rr(e,t){return t!==null&&(du(t)||jd.some(n=>It(e,n)!==null))}function ax(e,t){let n=null;for(let[r,i]of $d){let o=It(e,i);o!==null&&(n??(n={...t.effects}),n[r]=o)}return n}function sx(e){let{element:t,grading:n}=e,r=It(t,Wd),i=It(t,Vd),o=It(t,zd),a=ax(t,n);if(![r,i,o].some(u=>u!==null)&&a===null)return n;let s={...n,adjust:o===null?n.adjust:{...n.adjust,exposure:o},effects:a??n.effects};return r!==null&&(s.intensity=r),n.lut&&i!==null&&(s.lut={...n.lut,intensity:i}),s}function Kd(e,t,n){e.activeTexture(e.TEXTURE0),e.bindTexture(e.TEXTURE_2D,t),e.pixelStorei(e.UNPACK_FLIP_Y_WEBGL,!0),e.texImage2D(e.TEXTURE_2D,0,e.RGBA,e.RGBA,e.UNSIGNED_BYTE,n)}function Yd(e,t,n){let r=[t.texture,n.blurTexture,t.lutTexture,n.kuwaharaTexture,n.bloomTexture,t.advancedTexture];for(let[i,o]of r.entries())e.activeTexture(e.TEXTURE0+i),e.bindTexture(e.TEXTURE_2D,o)}function De(e){if(e.destroyed||e.contextLost)return!1;let t=Gd(e.element);if(!t)return e.hasDrawn||(e.canvas.style.display="none"),!1;let n=Pd(t);if(!n)return!1;let r=t instanceof HTMLElement?t:e.element,i=e.element.style.getPropertyValue("opacity"),o=e.element.style.getPropertyPriority("opacity"),a=e.sourceHidden&&i==="0"&&o==="important",l=e.element.style.getPropertyValue("visibility"),s=Yb(t);s&&Xb(e,t),a&&!s&&(e.sourceInlineOpacity!==null?e.element.style.setProperty("opacity",e.sourceInlineOpacity,e.sourceInlineOpacityPriority||""):e.element.style.removeProperty("opacity"));let u=window.getComputedStyle(s?t:e.element);e.sourceOpacityForCanvas=u.opacity||"1",a&&!s&&e.element.style.setProperty("opacity","0","important"),e.sourceVisibleForCanvas=(s||l!=="hidden")&&u.visibility!=="hidden";let c=Zb(e,r);if(!c)return!1;let m=window.getComputedStyle(r),f=Bd(c.width,c.height,n.width,n.height,m.objectFit,m.objectPosition),{gl:p,program:b}=e;try{let v=sx(e),x=Kb(e);Kd(p,b.texture,t);let _=It(e.element,qd)!==null,R=Id(e,v,c,f,{preserveKuwahara:_});p.bindFramebuffer(p.FRAMEBUFFER,null),p.viewport(0,0,c.width,c.height),p.useProgram(b.program),Yd(p,b,R);let T=window.__player?.getTime?.(),M=typeof T=="number"&&Number.isFinite(T)?Math.max(0,T):e.element instanceof HTMLVideoElement?Math.max(0,e.element.currentTime):0,F=e.grainSeed+Math.floor(M*60);return Ud(p,b,v,x,R.blurReady,R.bloomReady,R.kuwaharaReady,e.compare,c,f,F,M),or(p,b),ox(e),e.hasDrawn=!0,e.drawError=null,!0}catch(v){return e.drawError=v instanceof Error?v.message:"Shader draw failed",L("runtime.colorGrading.drawEntry",v),!1}}function lx(e,t,n){let r=e.getBoundingClientRect(),i=e.offsetWidth||r.width||t.width,o=e.offsetHeight||r.height||t.height,a=Math.min(320,Math.max(64,Math.round(n??160))),l=i>0&&o>0?i/o:t.width/t.height;return l>=1?{width:a,height:Math.max(1,Math.round(a/l))}:{width:Math.max(1,Math.round(a*l)),height:a}}function ux(){let e=document.createElement("canvas"),t=Ga(e);return t?{canvas:e,...t,lut:null,effectTargets:null,kuwaharaTargets:null,effectError:null}:null}function cx(e,t){let n=t?void 0:window.__player?.getTime?.();return typeof n=="number"&&Number.isFinite(n)?Math.max(0,n):e instanceof HTMLVideoElement?Math.max(0,e.currentTime):0}function dx(e,t,n,r){let i=Gd(t);if(!i)return null;let o=Pd(i);if(!o)return null;let a=lx(t,o,n);e.canvas.width=a.width,e.canvas.height=a.height;let l=i instanceof HTMLElement?i:t,s=window.getComputedStyle(l),u=Bd(a.width,a.height,o.width,o.height,s.objectFit,s.objectPosition);return Kd(e.gl,e.program.texture,i),{dimensions:a,uv:u,effectTime:cx(t,r),grainSeed:Nd(t)+(t instanceof HTMLVideoElement?Math.floor(t.currentTime*60):0)}}async function fx(e,t,n,r,i=!1){let o=dx(e,t,r,i);if(!o)return null;let{dimensions:a,uv:l,grainSeed:s,effectTime:u}=o,c=[];for(let m of n.slice(0,32)){let f=qr(m.grading);if(!f){c.push({id:m.id,dataUrl:null,error:"Invalid grading"});continue}let p=null;try{f.lut&&(e.lut?.src!==f.lut.src&&(e.lut=Db(e,f.lut.src,await Lb(f.lut.src))),p=e.lut),c.push({id:m.id,dataUrl:mx(e,f,p,a,l,s,u)})}catch(b){c.push({id:m.id,dataUrl:null,error:yi(b)})}}return{...a,images:c}}function mx(e,t,n,r,i,o,a){let{canvas:l,gl:s,program:u}=e,c=Id(e,t,r,i,{releaseIdleTargets:!1});return s.bindFramebuffer(s.FRAMEBUFFER,null),s.viewport(0,0,r.width,r.height),s.useProgram(u.program),Yd(s,u,c),n||(e.lut=null),Ud(s,u,t,n,c.blurReady,c.bloomReady,c.kuwaharaReady,rn,r,i,o,a),or(s,u),l.toDataURL("image/png")}function Xe(e,t,n,r){t.addEventListener(n,r),e.cleanup.push(()=>t.removeEventListener(n,r))}function px(e){e.animationFrame!==null&&(window.cancelAnimationFrame(e.animationFrame),e.animationFrame=null),e.videoFrameHandle!==null&&e.element instanceof HTMLVideoElement&&(e.element.cancelVideoFrameCallback?.(e.videoFrameHandle),e.videoFrameHandle=null)}function ar(e){if(e.destroyed||!(e.element instanceof HTMLVideoElement)||e.videoFrameHandle!==null||e.animationFrame!==null)return;let t=e.element,n=t;if(typeof n.requestVideoFrameCallback=="function"){e.videoFrameHandle=n.requestVideoFrameCallback(()=>{e.videoFrameHandle=null,De(e),!e.destroyed&&!t.paused&&!t.ended&&ar(e)});return}e.animationFrame=window.requestAnimationFrame(()=>{e.animationFrame=null,De(e),!e.destroyed&&!t.paused&&!t.ended&&ar(e)})}function hx(e){let t=()=>{De(e)};if(Xe(e,e.element,"load",t),Xe(e,e.element,"loadedmetadata",t),Xe(e,e.element,"loadeddata",t),Xe(e,e.element,"seeked",t),Xe(e,e.element,"timeupdate",t),Xe(e,window,"resize",t),e.element instanceof HTMLVideoElement&&(Xe(e,e.element,"play",()=>ar(e)),Xe(e,e.element,"pause",t)),Xe(e,e.canvas,"webglcontextlost",n=>{n.preventDefault(),e.contextLost=!0,e.drawError="WebGL context lost",e.canvas.style.display="none",Ha(e)}),Xe(e,e.canvas,"webglcontextrestored",()=>{if(e.contextLost=!1,!Pb(e)){e.contextLost=!0,e.drawError="WebGL context restore failed",Ha(e);return}e.drawError=null,De(e)}),typeof ResizeObserver<"u"&&(e.resizeObserver=new ResizeObserver(t),e.resizeObserver.observe(e.element)),typeof MutationObserver<"u"){let n=()=>{let a=e.element.style;return`${a.transform}|${a.translate}|${a.rotate}|${a.scale}|${a.left}|${a.top}|${a.width}|${a.height}`},r=n(),i=!1,o=new MutationObserver(()=>{i||n()!==r&&(i=!0,requestAnimationFrame(()=>{i=!1,r=n(),De(e)}))});o.observe(e.element,{attributes:!0,attributeFilter:["style"]}),e.cleanup.push(()=>o.disconnect())}}function gx(e){if(e.destroyed)return null;e.destroyed=!0,px(e),e.resizeObserver?.disconnect();for(let t of e.cleanup)t();return e.cleanup.length=0,e.canvas.remove(),Ua(e),Wa(e),Ha(e),e.touchedParent&&(e.parentInlinePosition===null?e.touchedParent.style.removeProperty("position"):e.touchedParent.style.position=e.parentInlinePosition),{canvas:e.canvas,gl:e.gl,program:e.program,effectTargets:null,kuwaharaTargets:null,effectError:null}}function Xd(e,t){return e.removeAttribute("style"),t.id?e.id=`${nu}${t.id}`:e.removeAttribute("id"),e.className=pb,e.setAttribute(mb,"true"),e.setAttribute("data-hyperframes-ignore",""),e.setAttribute("data-hyperframes-picker-ignore",""),e.setAttribute("data-hf-ignore",""),e.setAttribute("aria-hidden","true"),e.style.pointerEvents="none",e.style.display="none",t.parentNode?.insertBefore(e,t.nextSibling),e}function bx(e){return Xd(document.createElement("canvas"),e)}function Jd(){let e=new WeakMap,t=new Set,n=[],r=null,i=null,o=Promise.resolve(),a=!1,l=(E,S,A)=>{let C=e.get(E);if(C)return C.grading=S,C.source=A,De(C),E instanceof HTMLVideoElement&&!E.paused&&ar(C),!0;let N=n.pop();if(N)Xd(N.canvas,E);else{let W=bx(E),U=Ga(W);if(!U)return W.remove(),!1;N={canvas:W,gl:U.gl,program:U.program,effectTargets:null,kuwaharaTargets:null,effectError:null}}let I={element:E,...N,grading:S,compare:{...rn},lut:null,lutLoadingSrc:null,lutError:null,drawError:null,effectTargets:null,kuwaharaTargets:null,effectError:null,source:A,animationFrame:null,videoFrameHandle:null,resizeObserver:null,cleanup:[],touchedParent:null,parentInlinePosition:null,sourceHidden:!1,sourceInlineOpacity:null,sourceInlineOpacityPriority:"",sourceOpacityForCanvas:window.getComputedStyle(E).opacity||"1",sourceVisibleForCanvas:window.getComputedStyle(E).visibility!=="hidden",hasDrawn:!1,contextLost:!1,grainSeed:Nd(E),destroyed:!1};return e.set(E,I),t.add(E),hx(I),De(I),E instanceof HTMLVideoElement&&!E.paused&&ar(I),!0},s=(E,S)=>{if(a)return!1;let A=nr(E);if(!A)return!1;let C=e.get(A);if(!C){let N=mi(A);if(!rr(A,N)||!l(A,N,"attribute"))return!1;C=e.get(A)}return C?(C.compare=Fb(S),De(C),!0):!1},u=E=>{let S=e.get(E);if(!S)return;let A=gx(S);A&&(S.contextLost||n.length>=gb?hi(A,!0):n.push(A)),e.delete(E),t.delete(E)},c=()=>{if(a)return 0;let E=new Set;document.querySelectorAll(`video[${Fn}], img[${Fn}]`).forEach(A=>{if(!Lt(A))return;E.add(A);let C=mi(A);rr(A,C)&&(Sd(A)||_d(A))?l(A,C,"attribute"):u(A)});for(let A of t){let C=e.get(A);C&&(!A.isConnected||C.source==="attribute"&&!E.has(A))&&u(A)}return t.size},m=()=>{if(a)return 0;let E=0;for(let S of t){let A=e.get(S);A&&De(A)&&(E+=1)}return E},f=async()=>{let E=new Set;for(let S of t){let A=e.get(S)?.grading.lut;if(!A?.src.trim()||(A.intensity??1)<=0)continue;let C=Ba(A.src);C.state==="pending"&&E.add(C.promise)}return E.size>0&&await Promise.allSettled(E),m(),E.size},p=()=>{if(a)return 0;let E=0;for(let S of t){let A=e.get(S);!A||!jd.some(N=>It(S,N)!==null)||S instanceof HTMLVideoElement&&!S.paused&&!S.ended||De(A)&&(E+=1)}return E},b=(E,S)=>{if(a)return!1;let A=nr(E);if(!A)return!1;let C=qr(S);return rr(A,C)?l(A,C,"live"):(u(A),!0)},v=(E,S)=>{if(!Lt(E))return!1;let A=e.get(E);if(!A){if(!S)return!1;let C=mi(E);return rr(E,C)&&l(E,C,"attribute")}return A.sourceVisibleForCanvas=S,!S&&A.source==="attribute"&&u(E),!0},x=E=>{let S=nr(E);if(!S)return{state:"missing",message:"Media not found"};let A=e.get(S);if(A)return A.effectError?{state:"unavailable",message:A.effectError}:A.drawError?{state:"unavailable",message:A.drawError}:A.lutError?{state:"unavailable",message:`LUT error: ${A.lutError}`}:A.grading.lut&&A.lutLoadingSrc?{state:"pending",message:"Loading LUT"}:A.canvas.style.display==="none"?{state:"pending",message:"Waiting for media frame"}:{state:"active",message:A.lut?"Shader + LUT active":"Shader active"};let C=mi(S);return rr(S,C)?!Sd(S)&&!_d(S)?{state:"pending",message:"Waiting for visible media"}:{state:"unavailable",message:"WebGL unavailable"}:{state:"inactive",message:"No grading applied"}},_=async(E,S,A)=>{let C=async()=>{if(a||S.length===0)return null;let I=nr(E);return!I||(i??(i=ux()),!i)?null:fx(i,I,S,A?.maxDimension,A?.useMediaTime)},N=o.then(C,C);return o=N.then(()=>{},()=>{}),N},R=E=>{let S=nr(E);if(!(S instanceof HTMLVideoElement))return null;if(!S.paused)return()=>{};let A=S.currentTime,C=S.loop,N=S.muted;return S.loop=!0,S.muted=!0,(S.ended||Number.isFinite(S.duration)&&A>=S.duration)&&(S.currentTime=0),S.play().catch(()=>{}),()=>{S.pause(),S.loop=C,S.muted=N,S.currentTime=A}},T=()=>{if(!a){a=!0,r?.disconnect(),r=null;for(let E of t)u(E);for(let E of n)hi(E,!0);n.length=0,i&&(hi(i,!0),i=null)}};document.body&&(r=new MutationObserver(()=>c()),r.observe(document.body,{childList:!0,subtree:!0,attributes:!0,attributeFilter:[Fn]}));let M={refresh:c,redraw:m,redrawAnimated:p,waitForActiveLuts:f,setGrading:b,setCompare:s,setSourceVisibility:v,getStatus:x,renderPreviews:_,startPreviewPlayback:R,destroy:T},F=window;return F.__hf=F.__hf||{},F.__hf.colorGrading=M,c(),M}var vi=class{constructor(t){ge(this,"_baseTime",0);ge(this,"_playStartMs",null);ge(this,"_rate",1);ge(this,"_duration",1/0);ge(this,"_nowMs");ge(this,"_audioSource",null);this._baseTime=t?.initialTime??0,this._rate=t?.rate??1,this._duration=t?.duration??1/0,this._nowMs=t?.nowMs??(()=>performance.now())}now(){if(this._playStartMs===null)return this._baseTime;if(this._audioSource){let r=null;if("currentTimeSeconds"in this._audioSource)r=this._audioSource.currentTimeSeconds;else{let{el:i,compositionStart:o,mediaStart:a}=this._audioSource;!i.paused&&Number.isFinite(i.currentTime)&&(r=(i.currentTime-a)/(i.playbackRate>0?i.playbackRate:1)*this._rate+o)}if(r!==null)return Number.isFinite(this._duration)&&r>=this._duration?this._duration:Math.max(0,r)}let t=(this._nowMs()-this._playStartMs)/1e3,n=this._baseTime+t*this._rate;return Number.isFinite(this._duration)&&n>=this._duration?this._duration:Math.max(0,n)}play(){return this._playStartMs!==null||Number.isFinite(this._duration)&&this._baseTime>=this._duration?!1:(this._playStartMs=this._nowMs(),!0)}pause(){return this._playStartMs===null?!1:(this._baseTime=this.now(),this._playStartMs=null,!0)}seek(t){let n=Number.isFinite(this._duration)?Math.max(0,Math.min(t,this._duration)):Math.max(0,t);this._baseTime=n,this._playStartMs!==null&&(this._playStartMs=this._nowMs())}isPlaying(){return this._playStartMs!==null}setRate(t){let n=Number.isFinite(t)&&t>0?Math.max(.1,Math.min(5,t)):1;this._playStartMs!==null&&(this._baseTime=this.now(),this._playStartMs=this._nowMs()),this._rate=n}getRate(){return this._rate}setDuration(t){this._duration=Number.isFinite(t)&&t>0?t:1/0,this._baseTime>this._duration&&(this._baseTime=this._duration)}getDuration(){return this._duration}attachAudioSource(t){this._audioSource=t}detachAudioSource(){this._audioSource&&this._playStartMs!==null&&(this._baseTime=this.now(),this._playStartMs=this._nowMs()),this._audioSource=null}hasAudioSource(){return this._audioSource!==null}getSource(){if(this._audioSource&&this._playStartMs!==null){if("currentTimeSeconds"in this._audioSource)return"audio";let{el:t}=this._audioSource;if(!t.paused&&Number.isFinite(t.currentTime))return"audio"}return"monotonic"}snapshot(){return{time:this.now(),playing:this.isPlaying(),rate:this._rate,duration:this._duration,source:this.getSource()}}reachedEnd(){return Number.isFinite(this._duration)&&this.now()>=this._duration}};var xx=100,yx=8,vx=4096,Va=e=>e;function Sx(e,t,n){return!(!!e.curve||e.viaX!==void 0&&e.viaY!==void 0)&&t==="linear"&&!n}function Ax(e){let t=Math.ceil(e*xx);return Math.min(vx,Math.max(yx,t))}function Ex(e,t,n,r,i){let{scheduledAt:o,elapsed:a,rate:l}=r,s=i??Va,u=R=>o+(R-a)/l,c=e.points[t],m=e.points[t+1],f=u(m.t);if(f<=o)return null;let p=Math.max(o,u(c.t)),b=f-p;if(b<=0)return null;if(Sx(c,n,i))return{kind:"ramp",time:f,value:s(m.v)};let v=Ax(b),x=_l(e,Math.max(c.t,a),m.t,v,n),_=new Float32Array(v);for(let R=0;R<v;R+=1)_[R]=s(x[R]??0);return{kind:"curve",time:p,duration:b,values:_}}function wx(e,t,n,r){let i=[];for(let a=0;a+1<e.points.length;a+=1){let l=Ex(e,a,t,n,r);l&&i.push(l)}let o=i[0];return o?.kind==="curve"&&o.time<=n.scheduledAt||i.unshift({kind:"set",time:n.scheduledAt,value:(r??Va)(_n(e,n.elapsed,t))}),i}function Cx(e,t){for(let n of t)if(n.kind==="set")e.setValueAtTime(n.value,n.time);else if(n.kind==="ramp")e.linearRampToValueAtTime(n.value,n.time);else try{e.setValueCurveAtTime(n.values,n.time,n.duration)}catch{let r=n.values[n.values.length-1]??0;e.linearRampToValueAtTime(r,n.time+n.duration)}}function lr(e){for(let t of e)t.param.cancelScheduledValues(0)}function on(e,t){for(let n of e)typeof n.param.cancelAndHoldAtTime=="function"?n.param.cancelAndHoldAtTime(t):n.param.cancelScheduledValues(t)}function za(e,t,n,r){if(t.points.length!==0)for(let i of e){if(lr([i]),Cl(t)){let o=(i.map??Va)(t.points[0].v);i.param.setValueAtTime(o,r.scheduledAt);continue}Cx(i.param,wx(t,n,r,i.map))}}function Qd(e,t,n,r,i){let o=new Map(n.filter(l=>l.id).map(l=>[l.id,l.handle])),a=[];for(let l of e.lanes){let s=Cn(l.target);if(!s)continue;let u=s.kind==="preset"?i?.[s.presetId]:s.kind==="fx"?o.get(s.nodeId)?.automation?.[s.param]:void 0;if(!u||u.length===0)continue;let c=co(l.target,t);c&&(za(u,l,c.scale,r),a.push(...u))}return a}function Zd(e){return e.lanes.find(t=>t.target===Ut)??null}var _x=`
|
|
369
369
|
const dbToLin = (db) => Math.pow(10, db / 20);
|
|
370
370
|
|
|
371
371
|
/**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hyperframes/core",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.17",
|
|
4
4
|
"description": "",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -278,9 +278,9 @@
|
|
|
278
278
|
"bpm-detective": "^2.0.5",
|
|
279
279
|
"linkedom": "^0.18.12",
|
|
280
280
|
"postcss": "^8.5.8",
|
|
281
|
-
"@hyperframes/
|
|
282
|
-
"@hyperframes/
|
|
283
|
-
"@hyperframes/studio-server": "0.8.
|
|
281
|
+
"@hyperframes/parsers": "0.8.17",
|
|
282
|
+
"@hyperframes/lint": "0.8.17",
|
|
283
|
+
"@hyperframes/studio-server": "0.8.17"
|
|
284
284
|
},
|
|
285
285
|
"devDependencies": {
|
|
286
286
|
"@types/jsdom": "^28.0.0",
|