@razorpay/blade 12.94.0 → 12.95.1
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/build/lib/native/components/Spark/RazorSenseGradient/shader.js +10 -3
- package/build/lib/native/components/Spark/RazorSenseGradient/shader.js.map +1 -1
- package/build/lib/native/components/Spark/RzpGlass/RzpGlass.js +5 -4
- package/build/lib/native/components/Spark/RzpGlass/RzpGlass.js.map +1 -1
- package/build/lib/native/components/Spark/RzpGlass/RzpGlassMount.js +2 -1
- package/build/lib/native/components/Spark/RzpGlass/RzpGlassMount.js.map +1 -1
- package/build/lib/native/components/Spark/RzpGlass/presets.js +2 -2
- package/build/lib/native/components/Spark/RzpGlass/presets.js.map +1 -1
- package/build/lib/native/components/Spark/RzpGlass/rzpGlassShader.js +8 -5
- package/build/lib/native/components/Spark/RzpGlass/rzpGlassShader.js.map +1 -1
- package/build/lib/native/components/Spark/RzpGlass/utils.js +7 -2
- package/build/lib/native/components/Spark/RzpGlass/utils.js.map +1 -1
- package/build/lib/native/components/index.js +1 -0
- package/build/lib/native/components/index.js.map +1 -1
- package/build/lib/web/development/_virtual/cloneDeep.js +1 -1
- package/build/lib/web/development/_virtual/cloneDeep3.js +1 -1
- package/build/lib/web/development/_virtual/flatten.js +1 -1
- package/build/lib/web/development/_virtual/flatten3.js +1 -1
- package/build/lib/web/development/components/Spark/RazorSenseGradient/shader.js +1 -1
- package/build/lib/web/development/components/Spark/RazorSenseGradient/shader.js.map +1 -1
- package/build/lib/web/development/components/Spark/RzpGlass/RzpGlass.js +41 -110
- package/build/lib/web/development/components/Spark/RzpGlass/RzpGlass.js.map +1 -1
- package/build/lib/web/development/components/Spark/RzpGlass/RzpGlassMount.js +8 -6
- package/build/lib/web/development/components/Spark/RzpGlass/RzpGlassMount.js.map +1 -1
- package/build/lib/web/development/components/Spark/RzpGlass/index.js +4 -0
- package/build/lib/web/development/components/Spark/RzpGlass/index.js.map +1 -1
- package/build/lib/web/development/components/Spark/RzpGlass/presets.js +85 -79
- package/build/lib/web/development/components/Spark/RzpGlass/presets.js.map +1 -1
- package/build/lib/web/development/components/Spark/RzpGlass/rzpGlassShader.js +1 -1
- package/build/lib/web/development/components/Spark/RzpGlass/rzpGlassShader.js.map +1 -1
- package/build/lib/web/development/components/Spark/RzpGlass/utils.js +147 -2
- package/build/lib/web/development/components/Spark/RzpGlass/utils.js.map +1 -1
- package/build/lib/web/development/components/TopNav/TabNav/TabNavItem.web.js +3 -2
- package/build/lib/web/development/components/TopNav/TabNav/TabNavItem.web.js.map +1 -1
- package/build/lib/web/development/components/index.js +1 -0
- package/build/lib/web/development/components/index.js.map +1 -1
- package/build/lib/web/development/node_modules/es-toolkit/dist/array/flatten.js +1 -1
- package/build/lib/web/development/node_modules/es-toolkit/dist/compat/array/flatten.js +1 -1
- package/build/lib/web/development/node_modules/es-toolkit/dist/compat/array/sortBy.js +2 -2
- package/build/lib/web/development/node_modules/es-toolkit/dist/compat/object/cloneDeep.js +1 -1
- package/build/lib/web/development/node_modules/es-toolkit/dist/compat/object/omit.js +2 -2
- package/build/lib/web/development/node_modules/es-toolkit/dist/compat/predicate/matches.js +2 -2
- package/build/lib/web/development/node_modules/es-toolkit/dist/compat/predicate/matchesProperty.js +2 -2
- package/build/lib/web/development/node_modules/es-toolkit/dist/object/cloneDeep.js +1 -1
- package/build/lib/web/production/_virtual/cloneDeep.js +1 -1
- package/build/lib/web/production/_virtual/cloneDeep3.js +1 -1
- package/build/lib/web/production/components/Spark/RazorSenseGradient/shader.js +1 -1
- package/build/lib/web/production/components/Spark/RazorSenseGradient/shader.js.map +1 -1
- package/build/lib/web/production/components/Spark/RzpGlass/RzpGlass.js +41 -110
- package/build/lib/web/production/components/Spark/RzpGlass/RzpGlass.js.map +1 -1
- package/build/lib/web/production/components/Spark/RzpGlass/RzpGlassMount.js +8 -6
- package/build/lib/web/production/components/Spark/RzpGlass/RzpGlassMount.js.map +1 -1
- package/build/lib/web/production/components/Spark/RzpGlass/index.js +4 -0
- package/build/lib/web/production/components/Spark/RzpGlass/index.js.map +1 -1
- package/build/lib/web/production/components/Spark/RzpGlass/presets.js +85 -79
- package/build/lib/web/production/components/Spark/RzpGlass/presets.js.map +1 -1
- package/build/lib/web/production/components/Spark/RzpGlass/rzpGlassShader.js +1 -1
- package/build/lib/web/production/components/Spark/RzpGlass/rzpGlassShader.js.map +1 -1
- package/build/lib/web/production/components/Spark/RzpGlass/utils.js +147 -2
- package/build/lib/web/production/components/Spark/RzpGlass/utils.js.map +1 -1
- package/build/lib/web/production/components/TopNav/TabNav/TabNavItem.web.js +3 -2
- package/build/lib/web/production/components/TopNav/TabNav/TabNavItem.web.js.map +1 -1
- package/build/lib/web/production/components/index.js +1 -0
- package/build/lib/web/production/components/index.js.map +1 -1
- package/build/lib/web/production/node_modules/es-toolkit/dist/compat/object/cloneDeep.js +1 -1
- package/build/lib/web/production/node_modules/es-toolkit/dist/compat/predicate/matches.js +2 -2
- package/build/lib/web/production/node_modules/es-toolkit/dist/compat/predicate/matchesProperty.js +2 -2
- package/build/lib/web/production/node_modules/es-toolkit/dist/object/cloneDeep.js +1 -1
- package/build/types/components/index.d.ts +43 -3
- package/build/types/components/index.native.d.ts +42 -3
- package/package.json +1 -1
|
@@ -30,6 +30,10 @@ float vnoise(vec2 p) {
|
|
|
30
30
|
}
|
|
31
31
|
|
|
32
32
|
void main() {
|
|
33
|
+
// Envelope controls: how the gradient fades from center outward
|
|
34
|
+
const float FADE_OUTER_EDGE = 1.4; // distance where gradient fully fades to black
|
|
35
|
+
const float FADE_INNER_EDGE = 0.4; // distance where gradient is at full opacity
|
|
36
|
+
|
|
33
37
|
vec2 uv = vUv - uOrigin;
|
|
34
38
|
float angle = atan(uv.y, uv.x);
|
|
35
39
|
float r = length(uv);
|
|
@@ -57,9 +61,12 @@ void main() {
|
|
|
57
61
|
float phase = w * 0.5 + 0.5;
|
|
58
62
|
vec3 color = gradientColor(phase);
|
|
59
63
|
|
|
60
|
-
float envelope
|
|
61
|
-
|
|
62
|
-
|
|
64
|
+
float envelope = smoothstep(FADE_OUTER_EDGE, FADE_INNER_EDGE, r);
|
|
65
|
+
color = color * envelope;
|
|
66
|
+
|
|
67
|
+
// Film grain effect
|
|
68
|
+
float grain = hash(vUv * 500.0 + fract(uTime * 0.5)) * 2.0 - 1.0;
|
|
69
|
+
color += grain * 0.0002;
|
|
63
70
|
|
|
64
71
|
gl_FragColor = vec4(color, 1.0);
|
|
65
72
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"shader.js","sources":["../../../../../../src/components/Spark/RazorSenseGradient/shader.ts"],"sourcesContent":["export const FLUID_GRADIENT_LOOP = 12.0;\n\n// vec3 c0 = vec3(0.55, 0.95, 0.75);\n// vec3 c1 = vec3(0.35, 0.90, 0.65);\n// vec3 c2 = vec3(0.20, 0.88, 0.70);\n// vec3 c3 = vec3(0.08, 0.82, 0.48);\n// vec3 c4 = vec3(0.04, 0.68, 0.30);\n\n// vec3 c0 = vec3(0.72, 0.92, 1.00); // light sky blue\n// vec3 c1 = vec3(0.38, 0.72, 0.98); // cornflower blue\n// vec3 c2 = vec3(0.16, 0.50, 0.92); // medium blue\n// vec3 c3 = vec3(0.08, 0.30, 0.78); // deep royal blue\n// vec3 c4 = vec3(0.10, 0.28, 0.72); // deep blue (not black)\n\nexport const fragmentShader = /* glsl */ `\nprecision mediump float;\n\nuniform float uTime; // pre-wrapped: mod(raw, LOOP)\nuniform vec2 iResolution;\nuniform vec2 uOrigin; // gradient origin in UV space (0,0)=top-left (1,1)=bottom-right\nvarying vec2 vUv;\n\n// Cubic smoothstep inside each segment — no kink at stop boundaries\nvec3 gradientColor(float t) {\n t = clamp(t, 0.0, 1.0);\n vec3 c0 = vec3(0.682, 0.957, 0.831); // 174, 244, 212\n vec3 c1 = vec3(0.310, 0.882, 0.620); // 79, 225, 158\n vec3 c2 = vec3(0.306, 0.973, 0.910); // 78, 248, 232\n vec3 c3 = vec3(0.004, 0.753, 0.443); // 1, 192, 113\n vec3 c4 = vec3(0.004, 0.753, 0.443); // 1, 192, 113\n float s;\n if (t < 0.25) { s = smoothstep(0.0,1.0, t/0.25); return mix(c0,c1,s); }\n if (t < 0.55) { s = smoothstep(0.0,1.0,(t-0.25)/0.30); return mix(c1,c2,s); }\n if (t < 0.80) { s = smoothstep(0.0,1.0,(t-0.55)/0.25); return mix(c2,c3,s); }\n s = smoothstep(0.0,1.0,(t-0.80)/0.20); return mix(c3,c4,s);\n}\n\n// Value noise\nfloat hash(vec2 p) { return fract(sin(dot(p,vec2(127.1,311.7)))*43758.5453); }\nfloat vnoise(vec2 p) {\n vec2 i = floor(p), f = fract(p);\n vec2 u = f*f*(3.0-2.0*f);\n return mix(mix(hash(i),hash(i+vec2(1,0)),u.x), mix(hash(i+vec2(0,1)),hash(i+vec2(1,1)),u.x),u.y);\n}\n\nvoid main() {\n vec2 uv = vUv - uOrigin;\n float angle = atan(uv.y, uv.x);\n float r = length(uv);\n\n // Warp: traces a circle in noise space → exactly periodic in LOOP seconds.\n // speed = 2π * n / LOOP (n integer → 1 full orbit per loop)\n float ws = 6.2832 / 12.0; // 2π/LOOP — 1 orbit in LOOP s\n float ws2 = ws * 2.0; // 2 orbits in LOOP s\n float warp =\n vnoise(vec2(cos(angle)*1.4 + sin(uTime*ws )*2.0, sin(angle)*1.4 + cos(uTime*ws )*2.0)) * 0.50 +\n vnoise(vec2(cos(angle)*2.6 + sin(uTime*ws2)*1.2, sin(angle)*2.6 + cos(uTime*ws2)*1.2)) * 0.25;\n float organicR = r + (warp - 0.45) * 0.04;\n\n // Three wave sines — speeds are 2π*n/LOOP (n=3,2,1) → integer cycles in LOOP s.\n // Spatial frequencies are irrational ratios so they never phase-lock into\n // distinct bands; the result is one broad, shifting swell.\n float s1 = 6.2832 * 3.0 / 12.0; // 3 cycles in LOOP s\n float s2 = 6.2832 * 2.0 / 12.0; // 2 cycles\n float s3 = 6.2832 * 1.0 / 12.0; // 1 cycle\n float w =\n sin(organicR * 4.80 - uTime * s1) * 0.55 +\n sin(organicR * 2.55 - uTime * s2) * 0.30 +\n sin(organicR * 1.45 - uTime * s3) * 0.15;\n\n float phase = w * 0.5 + 0.5;\n vec3 color = gradientColor(phase);\n\n float envelope
|
|
1
|
+
{"version":3,"file":"shader.js","sources":["../../../../../../src/components/Spark/RazorSenseGradient/shader.ts"],"sourcesContent":["export const FLUID_GRADIENT_LOOP = 12.0;\n\n// vec3 c0 = vec3(0.55, 0.95, 0.75);\n// vec3 c1 = vec3(0.35, 0.90, 0.65);\n// vec3 c2 = vec3(0.20, 0.88, 0.70);\n// vec3 c3 = vec3(0.08, 0.82, 0.48);\n// vec3 c4 = vec3(0.04, 0.68, 0.30);\n\n// vec3 c0 = vec3(0.72, 0.92, 1.00); // light sky blue\n// vec3 c1 = vec3(0.38, 0.72, 0.98); // cornflower blue\n// vec3 c2 = vec3(0.16, 0.50, 0.92); // medium blue\n// vec3 c3 = vec3(0.08, 0.30, 0.78); // deep royal blue\n// vec3 c4 = vec3(0.10, 0.28, 0.72); // deep blue (not black)\n\nexport const fragmentShader = /* glsl */ `\nprecision mediump float;\n\nuniform float uTime; // pre-wrapped: mod(raw, LOOP)\nuniform vec2 iResolution;\nuniform vec2 uOrigin; // gradient origin in UV space (0,0)=top-left (1,1)=bottom-right\nvarying vec2 vUv;\n\n// Cubic smoothstep inside each segment — no kink at stop boundaries\nvec3 gradientColor(float t) {\n t = clamp(t, 0.0, 1.0);\n vec3 c0 = vec3(0.682, 0.957, 0.831); // 174, 244, 212\n vec3 c1 = vec3(0.310, 0.882, 0.620); // 79, 225, 158\n vec3 c2 = vec3(0.306, 0.973, 0.910); // 78, 248, 232\n vec3 c3 = vec3(0.004, 0.753, 0.443); // 1, 192, 113\n vec3 c4 = vec3(0.004, 0.753, 0.443); // 1, 192, 113\n float s;\n if (t < 0.25) { s = smoothstep(0.0,1.0, t/0.25); return mix(c0,c1,s); }\n if (t < 0.55) { s = smoothstep(0.0,1.0,(t-0.25)/0.30); return mix(c1,c2,s); }\n if (t < 0.80) { s = smoothstep(0.0,1.0,(t-0.55)/0.25); return mix(c2,c3,s); }\n s = smoothstep(0.0,1.0,(t-0.80)/0.20); return mix(c3,c4,s);\n}\n\n// Value noise\nfloat hash(vec2 p) { return fract(sin(dot(p,vec2(127.1,311.7)))*43758.5453); }\nfloat vnoise(vec2 p) {\n vec2 i = floor(p), f = fract(p);\n vec2 u = f*f*(3.0-2.0*f);\n return mix(mix(hash(i),hash(i+vec2(1,0)),u.x), mix(hash(i+vec2(0,1)),hash(i+vec2(1,1)),u.x),u.y);\n}\n\nvoid main() {\n // Envelope controls: how the gradient fades from center outward\n const float FADE_OUTER_EDGE = 1.4; // distance where gradient fully fades to black\n const float FADE_INNER_EDGE = 0.4; // distance where gradient is at full opacity\n\n vec2 uv = vUv - uOrigin;\n float angle = atan(uv.y, uv.x);\n float r = length(uv);\n\n // Warp: traces a circle in noise space → exactly periodic in LOOP seconds.\n // speed = 2π * n / LOOP (n integer → 1 full orbit per loop)\n float ws = 6.2832 / 12.0; // 2π/LOOP — 1 orbit in LOOP s\n float ws2 = ws * 2.0; // 2 orbits in LOOP s\n float warp =\n vnoise(vec2(cos(angle)*1.4 + sin(uTime*ws )*2.0, sin(angle)*1.4 + cos(uTime*ws )*2.0)) * 0.50 +\n vnoise(vec2(cos(angle)*2.6 + sin(uTime*ws2)*1.2, sin(angle)*2.6 + cos(uTime*ws2)*1.2)) * 0.25;\n float organicR = r + (warp - 0.45) * 0.04;\n\n // Three wave sines — speeds are 2π*n/LOOP (n=3,2,1) → integer cycles in LOOP s.\n // Spatial frequencies are irrational ratios so they never phase-lock into\n // distinct bands; the result is one broad, shifting swell.\n float s1 = 6.2832 * 3.0 / 12.0; // 3 cycles in LOOP s\n float s2 = 6.2832 * 2.0 / 12.0; // 2 cycles\n float s3 = 6.2832 * 1.0 / 12.0; // 1 cycle\n float w =\n sin(organicR * 4.80 - uTime * s1) * 0.55 +\n sin(organicR * 2.55 - uTime * s2) * 0.30 +\n sin(organicR * 1.45 - uTime * s3) * 0.15;\n\n float phase = w * 0.5 + 0.5;\n vec3 color = gradientColor(phase);\n\n float envelope = smoothstep(FADE_OUTER_EDGE, FADE_INNER_EDGE, r);\n color = color * envelope;\n\n // Film grain effect\n float grain = hash(vUv * 500.0 + fract(uTime * 0.5)) * 2.0 - 1.0;\n color += grain * 0.0002;\n\n gl_FragColor = vec4(color, 1.0);\n}\n`;\n"],"names":["FLUID_GRADIENT_LOOP","fragmentShader"],"mappings":"AAAa,IAAAA,mBAAmB,CAAG,KActB,IAAAC,cAAc,CAAc,CAAA;AACzC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;;"}
|
|
@@ -2,12 +2,13 @@ import _toConsumableArray from '@babel/runtime/helpers/toConsumableArray';
|
|
|
2
2
|
import _asyncToGenerator from '@babel/runtime/helpers/asyncToGenerator';
|
|
3
3
|
import _slicedToArray from '@babel/runtime/helpers/slicedToArray';
|
|
4
4
|
import _objectWithoutProperties from '@babel/runtime/helpers/objectWithoutProperties';
|
|
5
|
-
import { forwardRef, useState, useRef, useEffect
|
|
5
|
+
import { forwardRef, useState, useRef, useEffect } from 'react';
|
|
6
6
|
import { RzpGlassMount } from './RzpGlassMount.js';
|
|
7
|
-
import {
|
|
7
|
+
import { getPresetAssets, resolveConfig, DEFAULT_CDN_PATH, getDefaultAssets } from './utils.js';
|
|
8
|
+
import { useMergeRefs } from '../../../utils/useMergeRefs.js';
|
|
8
9
|
import { jsx } from 'react/jsx-runtime';
|
|
9
10
|
|
|
10
|
-
var _excluded=["width","height","className","style","onLoad","onError","
|
|
11
|
+
var _excluded=["width","height","className","style","onLoad","onError","assetsPath","gradientMapCanvas","gradientMapSrc","gradientMap2Src","imageSrc"];var FADE_IN_MS=200;var RzpGlass=forwardRef(function RzpGlass(props,forwardedRef){var _presetAssets$videoSr,_ref,_ref2,_presetAssets$centerG,_configProps$edgeFeat;var _props$width=props.width,width=_props$width===void 0?'100%':_props$width,_props$height=props.height,height=_props$height===void 0?'100%':_props$height,className=props.className,style=props.style,onLoad=props.onLoad,onError=props.onError,assetsPathProp=props.assetsPath,gradientMapCanvas=props.gradientMapCanvas,gradientMapSrcProp=props.gradientMapSrc,gradientMap2SrcProp=props.gradientMap2Src,imageSrcProp=props.imageSrc,configProps=_objectWithoutProperties(props,_excluded);var assetsPath=assetsPathProp!=null?assetsPathProp:DEFAULT_CDN_PATH;var defaultAssets=getDefaultAssets(assetsPath);var presetAssets=getPresetAssets(props.preset,assetsPath);var imageSrc=imageSrcProp!=null?imageSrcProp:presetAssets.imageSrc;var videoSrc=imageSrc?undefined:(_presetAssets$videoSr=presetAssets.videoSrc)!=null?_presetAssets$videoSr:defaultAssets.videoSrc;var gradientMapSrc=(_ref=gradientMapSrcProp!=null?gradientMapSrcProp:presetAssets.gradientMapSrc)!=null?_ref:defaultAssets.gradientMapSrc;var gradientMap2Src=(_ref2=gradientMap2SrcProp!=null?gradientMap2SrcProp:presetAssets.gradientMap2Src)!=null?_ref2:defaultAssets.gradientMap2Src;var centerGradientMapSrc=(_presetAssets$centerG=presetAssets.centerGradientMapSrc)!=null?_presetAssets$centerG:defaultAssets.centerGradientMapSrc;var _useState=useState(false),_useState2=_slicedToArray(_useState,2),isInitialized=_useState2[0],setIsInitialized=_useState2[1];var _useState3=useState(null),_useState4=_slicedToArray(_useState3,2),error=_useState4[0],setError=_useState4[1];var divRef=useRef(null);var mountRef=useRef(null);useEffect(function(){var init=function(){var _ref3=_asyncToGenerator(function*(){if(!divRef.current||mountRef.current)return;try{var _config$paused;var config=resolveConfig(props,assetsPath);mountRef.current=new RzpGlassMount(divRef.current,{videoSrc:videoSrc,imageSrc:imageSrc,gradientMapSrc:gradientMapSrc,gradientMap2Src:gradientMap2Src,centerGradientMapSrc:centerGradientMapSrc},config);yield mountRef.current.loadAssets();var userWantsPaused=(_config$paused=config.paused)!=null?_config$paused:false;if(!userWantsPaused){mountRef.current.pause();}setIsInitialized(true);setTimeout(function(){if(!mountRef.current)return;if(!userWantsPaused){mountRef.current.play();}onLoad==null?void 0:onLoad();},FADE_IN_MS);}catch(err){var _error=err instanceof Error?err:new Error(String(err));setError(_error);onError==null?void 0:onError(_error);}});return function init(){return _ref3.apply(this,arguments);};}();void init();return function(){var _mountRef$current;(_mountRef$current=mountRef.current)==null?void 0:_mountRef$current.dispose();mountRef.current=null;setIsInitialized(false);};},[assetsPath,videoSrc,imageSrc,gradientMapSrc,gradientMap2Src,centerGradientMapSrc,configProps.preset]);useEffect(function(){if(isInitialized&&mountRef.current){var config=resolveConfig(props,assetsPath);mountRef.current.setUniforms(config);}},[isInitialized,configProps.preset,configProps.inputMin,configProps.inputMax,configProps.modifyGamma,configProps.posterizeLevels,configProps.cycleRepetitions,configProps.phaseShift,configProps.cycleSpeed,configProps.wrapMode,configProps.reverse,configProps.blendWithOriginal,configProps.numSegments,configProps.slitAngle,configProps.displacementX,configProps.displacementY,configProps.enableCenterElement,configProps.centerAnimDuration,configProps.ccBlackPoint,configProps.ccWhitePoint,configProps.ccMidtoneGamma,configProps.ccGamma,configProps.ccContrast,configProps.zoom,configProps.panX,configProps.panY].concat(_toConsumableArray((_configProps$edgeFeat=configProps.edgeFeather)!=null?_configProps$edgeFeat:[0,0,0,0]),[configProps.enableDisplacement,configProps.enableColorama,configProps.enableBloom,configProps.enableLightSweep,configProps.lightIntensity,configProps.lightStartFrame,configProps.paused,configProps.startTime,configProps.endTime,configProps.animateLightIndependently,configProps.animateCycleReps,configProps.cycleRepetitionsStart,configProps.cycleRepetitionsEnd,configProps.cycleRepetitionsStartFrame,configProps.cycleRepetitionsDuration,configProps.gradientMapBlend,configProps.gradientMapBlendDuration]));useEffect(function(){if(isInitialized&&mountRef.current&&gradientMapCanvas){mountRef.current.updateGradientMapTexture(gradientMapCanvas);}},[isInitialized,gradientMapCanvas]);var mergedRef=useMergeRefs(forwardedRef,divRef);var widthStyle=typeof width==='number'?`${width}px`:width;var heightStyle=typeof height==='number'?`${height}px`:height;if(error){return jsx("div",{ref:mergedRef,className:className,style:Object.assign({width:widthStyle,height:heightStyle},style)});}return jsx("div",{ref:mergedRef,className:className,style:Object.assign({width:widthStyle,height:heightStyle,position:'relative',overflow:'hidden',backgroundColor:'transparent',transition:`${FADE_IN_MS}ms opacity`},isInitialized?{opacity:1}:{opacity:0},style)});});
|
|
11
12
|
|
|
12
|
-
export { RzpGlass
|
|
13
|
+
export { RzpGlass };
|
|
13
14
|
//# sourceMappingURL=RzpGlass.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RzpGlass.js","sources":["../../../../../../src/components/Spark/RzpGlass/RzpGlass.tsx"],"sourcesContent":["/* eslint-disable @typescript-eslint/explicit-function-return-type */\n/* eslint-disable @typescript-eslint/no-unsafe-argument */\n/* eslint-disable @typescript-eslint/no-unsafe-assignment */\n/* eslint-disable react/react-in-jsx-scope */\n/* eslint-disable react-hooks/exhaustive-deps */\n/* eslint-disable @typescript-eslint/no-implicit-any-catch */\n/* eslint-disable @typescript-eslint/no-shadow */\n/**\n * RzpGlass React Component\n *\n * A React wrapper for the RzpGlassMount WebGL shader effect.\n * Manages the component lifecycle with useEffect hooks.\n *\n * @example\n * ```tsx\n * // Uses default assets and config\n * <RzpGlass width=\"400px\" height=\"300px\" />\n *\n * // With custom assets\n * <RzpGlass\n * videoSrc=\"/custom_video.mp4\"\n * gradientMapSrc=\"/custom-gradient.jpg\"\n * enableBloom={true}\n * />\n * ```\n */\n\nimport { forwardRef, useEffect, useRef, useState, useCallback } from 'react';\nimport { RzpGlassMount } from './RzpGlassMount';\nimport type {\n RzpGlassProps,\n RzpGlassConfig,\n RzpGlassAssets,\n RzpGlassPresetDefinition,\n} from './types';\nimport { PRESETS } from './presets';\nimport type { RzpGlassPreset } from './presets';\n\nconst DEFAULT_CDN_PATH =\n 'https://cdn.jsdelivr.net/gh/razorpay/blade@feat/expose-assets-folder/packages/blade/assets/spark';\n\nconst getDefaultAssets = (cdnPath: string): Required<RzpGlassAssets> => ({\n videoSrc: `${cdnPath}/spark-base-video.mp4`,\n imageSrc: `${cdnPath}/bottom-frame.jpg`,\n gradientMapSrc: `${cdnPath}/colorama-gradient-map-green.jpg`,\n gradientMap2Src: `${cdnPath}/colorama-gradient-map-blue.jpg`,\n centerGradientMapSrc: `${cdnPath}/colorama-center-gradient-map.jpg`,\n});\n\n/**\n * Hook to merge multiple refs into one\n */\nfunction useMergeRefs<T>(refs: (React.Ref<T> | undefined)[]): React.RefCallback<T> {\n return useCallback(\n (value: T) => {\n refs.forEach((ref) => {\n if (typeof ref === 'function') {\n ref(value);\n } else if (ref != null) {\n (ref as React.MutableRefObject<T | null>).current = value;\n }\n });\n },\n [refs],\n );\n}\n\n/**\n * Extract config from props (exclude non-config props).\n * Strips undefined values so they don't clobber preset defaults.\n */\nfunction extractConfig(props: RzpGlassProps): Partial<RzpGlassConfig> {\n const {\n width: _width,\n height: _height,\n className: _className,\n style: _style,\n onLoad: _onLoad,\n onError: _onError,\n preset: _preset,\n cdnPath: _cdnPath,\n gradientMapSrc: _gradientMapSrc,\n gradientMap2Src: _gradientMap2Src,\n gradientMapCanvas: _gradientMapCanvas,\n imageSrc: _imageSrc,\n ...config\n } = props;\n\n // Drop keys with undefined values so preset config isn't overridden by unset props\n return Object.fromEntries(\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition\n Object.entries(config).filter(([, v]) => v !== undefined),\n ) as Partial<RzpGlassConfig>;\n}\n\nconst ASSET_KEYS = new Set<string>([\n 'videoSrc',\n 'imageSrc',\n 'gradientMapSrc',\n 'gradientMap2Src',\n 'centerGradientMapSrc',\n]);\n\n/* eslint-disable @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-return */\nfunction getPresetDefinition(preset: RzpGlassPreset | undefined): RzpGlassPresetDefinition {\n if (preset && preset in PRESETS) return { ...PRESETS[preset] };\n return {};\n}\n\nfunction getPresetConfig(preset: RzpGlassPreset | undefined): Partial<RzpGlassConfig> {\n const def = getPresetDefinition(preset) as Record<string, unknown>;\n return Object.fromEntries(\n Object.entries(def).filter(([k]) => !ASSET_KEYS.has(k)),\n ) as Partial<RzpGlassConfig>;\n}\n\nfunction getPresetAssets(preset: RzpGlassPreset | undefined): Partial<RzpGlassAssets> {\n const def = getPresetDefinition(preset) as Record<string, unknown>;\n return Object.fromEntries(\n Object.entries(def).filter(([k]) => ASSET_KEYS.has(k)),\n ) as Partial<RzpGlassAssets>;\n}\n\n/**\n * Merge preset config with user-provided config.\n * Preset values are used as base; any explicit prop overrides them.\n */\nfunction resolveConfig(props: RzpGlassProps): Partial<RzpGlassConfig> {\n return {\n ...getPresetConfig(props.preset),\n ...extractConfig(props),\n };\n}\n\nexport const RzpGlass = forwardRef<HTMLDivElement, RzpGlassProps>(function RzpGlass(\n props,\n forwardedRef,\n) {\n const {\n width = '100%',\n height = '100%',\n className,\n style,\n onLoad,\n onError,\n cdnPath: cdnPathProp,\n gradientMapCanvas,\n gradientMapSrc: gradientMapSrcProp,\n gradientMap2Src: gradientMap2SrcProp,\n imageSrc: imageSrcProp,\n ...configProps\n } = props;\n\n // Get default assets based on cdnPath\n const cdnPath: string = cdnPathProp ?? DEFAULT_CDN_PATH;\n const defaultAssets = getDefaultAssets(cdnPath);\n\n // Resolve assets: prop overrides preset, preset overrides default\n const presetAssets = getPresetAssets(props.preset);\n const imageSrc = imageSrcProp ?? presetAssets.imageSrc;\n const videoSrc = imageSrc ? undefined : presetAssets.videoSrc ?? defaultAssets.videoSrc;\n const gradientMapSrc =\n gradientMapSrcProp ?? presetAssets.gradientMapSrc ?? defaultAssets.gradientMapSrc;\n const gradientMap2Src =\n gradientMap2SrcProp ?? presetAssets.gradientMap2Src ?? defaultAssets.gradientMap2Src;\n const centerGradientMapSrc =\n presetAssets.centerGradientMapSrc ?? defaultAssets.centerGradientMapSrc;\n\n const [isInitialized, setIsInitialized] = useState(false);\n const [error, setError] = useState<Error | null>(null);\n const divRef = useRef<HTMLDivElement>(null);\n const mountRef = useRef<RzpGlassMount | null>(null);\n\n // Initialize on mount\n useEffect(() => {\n const init = async () => {\n if (!divRef.current || mountRef.current) return;\n\n try {\n const config = resolveConfig(props);\n\n mountRef.current = new RzpGlassMount(\n divRef.current,\n {\n videoSrc,\n imageSrc,\n gradientMapSrc,\n gradientMap2Src,\n centerGradientMapSrc,\n },\n config,\n );\n\n await mountRef.current.loadAssets();\n setIsInitialized(true);\n onLoad?.();\n } catch (err) {\n const error = err instanceof Error ? err : new Error(String(err));\n setError(error);\n onError?.(error);\n }\n };\n\n void init();\n\n return () => {\n mountRef.current?.dispose();\n mountRef.current = null;\n setIsInitialized(false);\n };\n }, [\n cdnPath,\n videoSrc,\n imageSrc,\n gradientMapSrc,\n gradientMap2Src,\n centerGradientMapSrc,\n configProps.preset,\n ]);\n\n // Update uniforms when config props change\n useEffect(() => {\n if (isInitialized && mountRef.current) {\n const config = resolveConfig(props);\n mountRef.current.setUniforms(config);\n }\n }, [\n isInitialized,\n configProps.preset,\n // Colorama\n configProps.inputMin,\n configProps.inputMax,\n configProps.modifyGamma,\n configProps.posterizeLevels,\n configProps.cycleRepetitions,\n configProps.phaseShift,\n configProps.cycleSpeed,\n configProps.wrapMode,\n configProps.reverse,\n configProps.blendWithOriginal,\n // Displacement\n configProps.numSegments,\n configProps.slitAngle,\n configProps.displacementX,\n configProps.displacementY,\n // Center element\n configProps.enableCenterElement,\n configProps.centerAnimDuration,\n // Color correction\n configProps.ccBlackPoint,\n configProps.ccWhitePoint,\n configProps.ccMidtoneGamma,\n configProps.ccGamma,\n configProps.ccContrast,\n // Zoom & Pan\n configProps.zoom,\n configProps.panX,\n configProps.panY,\n // eslint-disable-next-line react-hooks/exhaustive-deps\n ...(configProps.edgeFeather ?? [0, 0, 0, 0]),\n // Effect toggles\n configProps.enableDisplacement,\n configProps.enableColorama,\n configProps.enableBloom,\n configProps.enableLightSweep,\n // Light\n configProps.lightIntensity,\n configProps.lightStartFrame,\n // Playback\n configProps.paused,\n configProps.startTime,\n configProps.endTime,\n configProps.animateLightIndependently,\n // Cycle animation\n configProps.animateCycleReps,\n configProps.cycleRepetitionsStart,\n configProps.cycleRepetitionsEnd,\n configProps.cycleRepetitionsStartFrame,\n configProps.cycleRepetitionsDuration,\n // Gradient map blend\n configProps.gradientMapBlend,\n configProps.gradientMapBlendDuration,\n ]);\n\n // Update gradient map texture when a canvas is provided\n useEffect(() => {\n if (isInitialized && mountRef.current && gradientMapCanvas) {\n mountRef.current.updateGradientMapTexture(gradientMapCanvas);\n }\n }, [isInitialized, gradientMapCanvas]);\n\n const mergedRef = useMergeRefs([divRef, forwardedRef]);\n\n // Convert width/height to string if number\n const widthStyle = typeof width === 'number' ? `${width}px` : width;\n const heightStyle = typeof height === 'number' ? `${height}px` : height;\n\n if (error) {\n return (\n <div\n ref={mergedRef}\n className={className}\n style={{\n width: widthStyle,\n height: heightStyle,\n ...style,\n }}\n />\n );\n }\n\n return (\n <div\n ref={mergedRef}\n className={className}\n style={{\n width: widthStyle,\n height: heightStyle,\n position: 'relative',\n overflow: 'hidden',\n backgroundColor: 'transparent',\n transition: '2s opacity',\n ...(isInitialized ? { opacity: 1 } : { opacity: 0 }),\n ...style,\n }}\n />\n );\n});\n\nexport default RzpGlass;\n"],"names":["DEFAULT_CDN_PATH","getDefaultAssets","cdnPath","videoSrc","imageSrc","gradientMapSrc","gradientMap2Src","centerGradientMapSrc","useMergeRefs","refs","useCallback","value","forEach","ref","current","extractConfig","props","width","height","className","style","onLoad","onError","preset","gradientMapCanvas","config","_objectWithoutProperties","_excluded","Object","fromEntries","entries","filter","_ref","_ref2","_slicedToArray","v","undefined","ASSET_KEYS","Set","getPresetDefinition","PRESETS","assign","getPresetConfig","def","_ref3","_ref4","k","has","getPresetAssets","_ref5","_ref6","resolveConfig","RzpGlass","forwardRef","forwardedRef","_presetAssets$videoSr","_ref7","_ref8","_presetAssets$centerG","_configProps$edgeFeat","_props$width","_props$height","cdnPathProp","gradientMapSrcProp","gradientMap2SrcProp","imageSrcProp","configProps","_excluded2","defaultAssets","presetAssets","_useState","useState","_useState2","isInitialized","setIsInitialized","_useState3","_useState4","error","setError","divRef","useRef","mountRef","useEffect","init","_ref9","_asyncToGenerator","RzpGlassMount","loadAssets","err","Error","String","apply","arguments","_mountRef$current","dispose","setUniforms","inputMin","inputMax","modifyGamma","posterizeLevels","cycleRepetitions","phaseShift","cycleSpeed","wrapMode","reverse","blendWithOriginal","numSegments","slitAngle","displacementX","displacementY","enableCenterElement","centerAnimDuration","ccBlackPoint","ccWhitePoint","ccMidtoneGamma","ccGamma","ccContrast","zoom","panX","panY","concat","_toConsumableArray","edgeFeather","enableDisplacement","enableColorama","enableBloom","enableLightSweep","lightIntensity","lightStartFrame","paused","startTime","endTime","animateLightIndependently","animateCycleReps","cycleRepetitionsStart","cycleRepetitionsEnd","cycleRepetitionsStartFrame","cycleRepetitionsDuration","gradientMapBlend","gradientMapBlendDuration","updateGradientMapTexture","mergedRef","widthStyle","heightStyle","_jsx","position","overflow","backgroundColor","transition","opacity"],"mappings":";;;;;;;;;AA2BA,IAAA,SAAA,CAAA,CAAA,OAAA,CAAA,QAAA,CAAA,WAAA,CAAA,OAAA,CAAA,QAAA,CAAA,SAAA,CAAA,QAAA,CAAA,SAAA,CAAA,gBAAA,CAAA,iBAAA,CAAA,mBAAA,CAAA,UAAA,CAAA,CAAA,UAAA,CAAA,CAAA,OAAA,CAAA,QAAA,CAAA,WAAA,CAAA,OAAA,CAAA,QAAA,CAAA,SAAA,CAAA,SAAA,CAAA,mBAAA,CAAA,gBAAA,CA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,EACHxB,KAAK,CAAE6H,UAAU,CACjB5H,MAAM,CAAE6H,WAAW,CAChB3H,CAAAA,KAAK,CACR,CACH,CAAC,CAEN,CAEA,OACE4H,GAAA,CAAA,KAAA,CAAA,CACEnI,GAAG,CAAEgI,SAAU,CACf1H,SAAS,CAAEA,SAAU,CACrBC,KAAK,CAAAQ,MAAA,CAAAa,MAAA,CACHxB,CAAAA,KAAK,CAAE6H,UAAU,CACjB5H,MAAM,CAAE6H,WAAW,CACnBE,QAAQ,CAAE,UAAU,CACpBC,QAAQ,CAAE,QAAQ,CAClBC,eAAe,CAAE,aAAa,CAC9BC,UAAU,CAAE,YAAY,CACpB3E,CAAAA,aAAa,CAAG,CAAE4E,OAAO,CAAE,CAAE,CAAC,CAAG,CAAEA,OAAO,CAAE,CAAE,CAAC,CAChDjI,KAAK,CACR,CACH,CAAC,CAEN,CAAC;;;;"}
|
|
1
|
+
{"version":3,"file":"RzpGlass.js","sources":["../../../../../../src/components/Spark/RzpGlass/RzpGlass.tsx"],"sourcesContent":["/* eslint-disable @typescript-eslint/explicit-function-return-type */\n/* eslint-disable @typescript-eslint/no-unsafe-argument */\n/* eslint-disable @typescript-eslint/no-unsafe-assignment */\n/* eslint-disable react/react-in-jsx-scope */\n/* eslint-disable react-hooks/exhaustive-deps */\n/* eslint-disable @typescript-eslint/no-implicit-any-catch */\n/* eslint-disable @typescript-eslint/no-shadow */\nimport { forwardRef, useEffect, useRef, useState } from 'react';\nimport { RzpGlassMount } from './RzpGlassMount';\nimport type { RzpGlassProps } from './types';\nimport { DEFAULT_CDN_PATH, getDefaultAssets, getPresetAssets, resolveConfig } from './utils';\nimport { useMergeRefs } from '~utils/useMergeRefs';\n\n// Duration of the component's built-in fade-in transition.\n// The video is kept paused during this window so one-shot animations\n// (e.g. circleSlideUp) don't \"waste\" frames while the canvas is invisible.\nconst FADE_IN_MS = 200;\n\nconst RzpGlass = forwardRef<HTMLDivElement, RzpGlassProps>(function RzpGlass(props, forwardedRef) {\n const {\n width = '100%',\n height = '100%',\n className,\n style,\n onLoad,\n onError,\n assetsPath: assetsPathProp,\n gradientMapCanvas,\n gradientMapSrc: gradientMapSrcProp,\n gradientMap2Src: gradientMap2SrcProp,\n imageSrc: imageSrcProp,\n ...configProps\n } = props;\n\n // Get default assets based on assetsPath\n const assetsPath: string = assetsPathProp ?? DEFAULT_CDN_PATH;\n const defaultAssets = getDefaultAssets(assetsPath);\n\n // Resolve assets: prop overrides preset, preset overrides default\n const presetAssets = getPresetAssets(props.preset, assetsPath);\n const imageSrc = imageSrcProp ?? presetAssets.imageSrc;\n const videoSrc = imageSrc ? undefined : presetAssets.videoSrc ?? defaultAssets.videoSrc;\n const gradientMapSrc =\n gradientMapSrcProp ?? presetAssets.gradientMapSrc ?? defaultAssets.gradientMapSrc;\n const gradientMap2Src =\n gradientMap2SrcProp ?? presetAssets.gradientMap2Src ?? defaultAssets.gradientMap2Src;\n const centerGradientMapSrc =\n presetAssets.centerGradientMapSrc ?? defaultAssets.centerGradientMapSrc;\n\n const [isInitialized, setIsInitialized] = useState(false);\n const [error, setError] = useState<Error | null>(null);\n const divRef = useRef<HTMLDivElement>(null);\n const mountRef = useRef<RzpGlassMount | null>(null);\n\n // Initialize on mount\n useEffect(() => {\n const init = async () => {\n if (!divRef.current || mountRef.current) return;\n\n try {\n const config = resolveConfig(props, assetsPath);\n\n mountRef.current = new RzpGlassMount(\n divRef.current,\n {\n videoSrc,\n imageSrc,\n gradientMapSrc,\n gradientMap2Src,\n centerGradientMapSrc,\n },\n config,\n );\n\n await mountRef.current.loadAssets();\n\n // Pause the video during the CSS fade-in so one-shot animations\n // don't burn frames while the component is still transparent.\n // Only do this when the consumer hasn't explicitly set paused: true.\n const userWantsPaused = config.paused ?? false;\n if (!userWantsPaused) {\n mountRef.current.pause();\n }\n\n setIsInitialized(true); // kicks off the CSS opacity 0 → 1 transition\n\n // After the fade-in completes, resume video and notify the consumer.\n setTimeout(() => {\n if (!mountRef.current) return;\n if (!userWantsPaused) {\n mountRef.current.play();\n }\n onLoad?.();\n }, FADE_IN_MS);\n } catch (err) {\n const error = err instanceof Error ? err : new Error(String(err));\n setError(error);\n onError?.(error);\n }\n };\n\n void init();\n\n return () => {\n mountRef.current?.dispose();\n mountRef.current = null;\n setIsInitialized(false);\n };\n }, [assetsPath, videoSrc, imageSrc, gradientMapSrc, gradientMap2Src, centerGradientMapSrc, configProps.preset]);\n\n // Update uniforms when config props change\n useEffect(() => {\n if (isInitialized && mountRef.current) {\n const config = resolveConfig(props, assetsPath);\n mountRef.current.setUniforms(config);\n }\n }, [\n isInitialized,\n configProps.preset,\n // Colorama\n configProps.inputMin,\n configProps.inputMax,\n configProps.modifyGamma,\n configProps.posterizeLevels,\n configProps.cycleRepetitions,\n configProps.phaseShift,\n configProps.cycleSpeed,\n configProps.wrapMode,\n configProps.reverse,\n configProps.blendWithOriginal,\n // Displacement\n configProps.numSegments,\n configProps.slitAngle,\n configProps.displacementX,\n configProps.displacementY,\n // Center element\n configProps.enableCenterElement,\n configProps.centerAnimDuration,\n // Color correction\n configProps.ccBlackPoint,\n configProps.ccWhitePoint,\n configProps.ccMidtoneGamma,\n configProps.ccGamma,\n configProps.ccContrast,\n // Zoom & Pan\n configProps.zoom,\n configProps.panX,\n configProps.panY,\n // eslint-disable-next-line react-hooks/exhaustive-deps\n ...(configProps.edgeFeather ?? [0, 0, 0, 0]),\n // Effect toggles\n configProps.enableDisplacement,\n configProps.enableColorama,\n configProps.enableBloom,\n configProps.enableLightSweep,\n // Light\n configProps.lightIntensity,\n configProps.lightStartFrame,\n // Playback\n configProps.paused,\n configProps.startTime,\n configProps.endTime,\n configProps.animateLightIndependently,\n // Cycle animation\n configProps.animateCycleReps,\n configProps.cycleRepetitionsStart,\n configProps.cycleRepetitionsEnd,\n configProps.cycleRepetitionsStartFrame,\n configProps.cycleRepetitionsDuration,\n // Gradient map blend\n configProps.gradientMapBlend,\n configProps.gradientMapBlendDuration,\n ]);\n\n // Update gradient map texture when a canvas is provided\n useEffect(() => {\n if (isInitialized && mountRef.current && gradientMapCanvas) {\n mountRef.current.updateGradientMapTexture(gradientMapCanvas);\n }\n }, [isInitialized, gradientMapCanvas]);\n\n const mergedRef = useMergeRefs(forwardedRef, divRef);\n\n // Convert width/height to string if number\n const widthStyle = typeof width === 'number' ? `${width}px` : width;\n const heightStyle = typeof height === 'number' ? `${height}px` : height;\n\n if (error) {\n return (\n <div\n ref={mergedRef}\n className={className}\n style={{\n width: widthStyle,\n height: heightStyle,\n ...style,\n }}\n />\n );\n }\n\n return (\n <div\n ref={mergedRef}\n className={className}\n style={{\n width: widthStyle,\n height: heightStyle,\n position: 'relative',\n overflow: 'hidden',\n backgroundColor: 'transparent',\n transition: `${FADE_IN_MS}ms opacity`,\n ...(isInitialized ? { opacity: 1 } : { opacity: 0 }),\n ...style,\n }}\n />\n );\n});\n\nexport { RzpGlass };\n"],"names":["FADE_IN_MS","RzpGlass","forwardRef","props","forwardedRef","_presetAssets$videoSr","_ref","_ref2","_presetAssets$centerG","_configProps$edgeFeat","_props$width","width","_props$height","height","className","style","onLoad","onError","assetsPathProp","assetsPath","gradientMapCanvas","gradientMapSrcProp","gradientMapSrc","gradientMap2SrcProp","gradientMap2Src","imageSrcProp","imageSrc","configProps","_objectWithoutProperties","_excluded","DEFAULT_CDN_PATH","defaultAssets","getDefaultAssets","presetAssets","getPresetAssets","preset","videoSrc","undefined","centerGradientMapSrc","_useState","useState","_useState2","_slicedToArray","isInitialized","setIsInitialized","_useState3","_useState4","error","setError","divRef","useRef","mountRef","useEffect","init","_ref3","_asyncToGenerator","current","_config$paused","config","resolveConfig","RzpGlassMount","loadAssets","userWantsPaused","paused","pause","setTimeout","play","err","Error","String","apply","arguments","_mountRef$current","dispose","setUniforms","inputMin","inputMax","modifyGamma","posterizeLevels","cycleRepetitions","phaseShift","cycleSpeed","wrapMode","reverse","blendWithOriginal","numSegments","slitAngle","displacementX","displacementY","enableCenterElement","centerAnimDuration","ccBlackPoint","ccWhitePoint","ccMidtoneGamma","ccGamma","ccContrast","zoom","panX","panY","concat","_toConsumableArray","edgeFeather","enableDisplacement","enableColorama","enableBloom","enableLightSweep","lightIntensity","lightStartFrame","startTime","endTime","animateLightIndependently","animateCycleReps","cycleRepetitionsStart","cycleRepetitionsEnd","cycleRepetitionsStartFrame","cycleRepetitionsDuration","gradientMapBlend","gradientMapBlendDuration","updateGradientMapTexture","mergedRef","useMergeRefs","widthStyle","heightStyle","_jsx","ref","Object","assign","position","overflow","backgroundColor","transition","opacity"],"mappings":";;;;;;;;;;uJAgBA,IAAMA,UAAU,CAAG,GAAG,CAEhB,IAAAC,QAAQ,CAAGC,UAAU,CAAgC,SAASD,QAAQA,CAACE,KAAK,CAAEC,YAAY,CAAE,CAAA,IAAAC,qBAAA,CAAAC,IAAA,CAAAC,KAAA,CAAAC,qBAAA,CAAAC,qBAAA,CAChG,IAAAC,YAAA,CAaIP,KAAK,CAZPQ,KAAK,CAALA,KAAK,CAAAD,YAAA,GAAA,KAAA,CAAA,CAAG,MAAM,CAAAA,YAAA,CAAAE,aAAA,CAYZT,KAAK,CAXPU,MAAM,CAANA,MAAM,CAAAD,aAAA,GAAA,KAAA,CAAA,CAAG,MAAM,CAAAA,aAAA,CACfE,SAAS,CAUPX,KAAK,CAVPW,SAAS,CACTC,KAAK,CASHZ,KAAK,CATPY,KAAK,CACLC,MAAM,CAQJb,KAAK,CARPa,MAAM,CACNC,OAAO,CAOLd,KAAK,CAPPc,OAAO,CACKC,cAAc,CAMxBf,KAAK,CANPgB,UAAU,CACVC,iBAAiB,CAKfjB,KAAK,CALPiB,iBAAiB,CACDC,kBAAkB,CAIhClB,KAAK,CAJPmB,cAAc,CACGC,mBAAmB,CAGlCpB,KAAK,CAHPqB,eAAe,CACLC,YAAY,CAEpBtB,KAAK,CAFPuB,QAAQ,CACLC,WAAW,CAAAC,wBAAA,CACZzB,KAAK,CAAA0B,SAAA,CAGT,CAAA,IAAMV,UAAkB,CAAGD,cAAc,EAAdA,IAAAA,CAAAA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C,CAEN,CAAC;;;;"}
|
|
@@ -20,9 +20,10 @@ var REF_RESOLUTION={width:3000,height:2000};var DEFAULT_MAX_PIXEL_COUNT=1920*108
|
|
|
20
20
|
position: absolute;
|
|
21
21
|
z-index: -1;
|
|
22
22
|
border-radius: inherit;
|
|
23
|
+
pointer-events: none;
|
|
23
24
|
}
|
|
24
25
|
}
|
|
25
|
-
}`;var CONFIG_TO_UNIFORM={enableDisplacement:'uEnableDisplacement',enableColorama:'uEnableColorama',enableBloom:'uEnableBloom',enableLightSweep:'uEnableLightSweep',inputMin:'uInputMin',inputMax:'uInputMax',modifyGamma:'uModifyGamma',posterizeLevels:'uPosterizeLevels',cycleRepetitions:'uCycleRepetitions',phaseShift:'uPhaseShift',cycleSpeed:'uCycleSpeed',wrapMode:'uWrapMode',reverse:'uReverse',blendWithOriginal:'uBlendWithOriginal',lightIntensity:'uLightIntensity',lightStartFrame:'uLightStartFrame',numSegments:'uNumSegments',slitAngle:'uSlitAngle',displacementX:'uDisplacementX',displacementY:'uDisplacementY',enableCenterElement:'uEnableCenterElement',centerAnimDuration:'uCenterAnimDuration',ccBlackPoint:'uCCBlackPoint',ccWhitePoint:'uCCWhitePoint',ccMidtoneGamma:'uCCMidtoneGamma',ccGamma:'uCCGamma',ccContrast:'uCCContrast',zoom:'uZoom',edgeFeather:'uEdgeFeather'};var RzpGlassMount=function(){function RzpGlassMount(parentElement,assets){var _this=this,_visualViewport2;var config=arguments.length>2&&arguments[2]!==undefined?arguments[2]:{};var frame=arguments.length>3&&arguments[3]!==undefined?arguments[3]:0;var _minPixelRatio=arguments.length>4&&arguments[4]!==undefined?arguments[4]:1;var _maxPixelCount=arguments.length>5&&arguments[5]!==undefined?arguments[5]:DEFAULT_MAX_PIXEL_COUNT;_classCallCheck(this,RzpGlassMount);this.program=null;this.uniformLocations={};this.uniformCache={};this.videoTexture=null;this.gradientMapTexture=null;this.gradientMap2Texture=null;this.centerGradientMapTexture=null;this.currentGradientMapBlend=0;this.video=null;this.videoFrameCallbackId=null;this.rafId=null;this.lastRenderTime=0;this.currentFrame=0;this.independentLightTime=0;this.lastVideoTime=0;this.hasBeenDisposed=false;this.isInitialized=false;this.resolutionChanged=true;this.visibleUvBounds=[0,0,1,1];this.resizeObserver=null;this.renderScale=1;this.parentWidth=0;this.parentHeight=0;this.parentDevicePixelWidth=0;this.parentDevicePixelHeight=0;this.devicePixelsSupported=false;this.isSafariBrowser=isSafari();this.performanceController=null;this.handleVisualViewportChange=function(){var _this$resizeObserver;(_this$resizeObserver=_this.resizeObserver)==null?void 0:_this$resizeObserver.disconnect();_this.setupResizeObserver();};this.handleResize=function(){var _visualViewport$scale,_visualViewport;var containerWidth=_this.parentWidth||_this.parentElement.clientWidth;var containerHeight=_this.parentHeight||_this.parentElement.clientHeight;var containerAspect=containerWidth/containerHeight;var canvasWidth;var canvasHeight;var targetAspectRatio=_this.config.aspectRatio;if(containerAspect>targetAspectRatio){canvasWidth=containerWidth;canvasHeight=containerWidth/targetAspectRatio;}else {canvasHeight=containerHeight;canvasWidth=containerHeight*targetAspectRatio;}var offsetX=(containerWidth-canvasWidth)/2;var offsetY=(containerHeight-canvasHeight)/2;var visibleMinX=-offsetX/canvasWidth;var visibleMaxX=(containerWidth-offsetX)/canvasWidth;var visibleMinY=-offsetY/canvasHeight;var visibleMaxY=(containerHeight-offsetY)/canvasHeight;_this.visibleUvBounds=[visibleMinX,visibleMinY,visibleMaxX,visibleMaxY];_this.canvasElement.style.width=`${canvasWidth}px`;_this.canvasElement.style.height=`${canvasHeight}px`;_this.canvasElement.style.left=`${offsetX}px`;_this.canvasElement.style.top=`${offsetY}px`;var targetPixelWidth=0;var targetPixelHeight=0;var dpr=Math.max(1,window.devicePixelRatio);var pinchZoom=(_visualViewport$scale=(_visualViewport=visualViewport)==null?void 0:_visualViewport.scale)!=null?_visualViewport$scale:1;if(_this.devicePixelsSupported){var canvasToParentRatioX=canvasWidth/containerWidth;var canvasToParentRatioY=canvasHeight/containerHeight;var scaleToMeetMinPixelRatio=Math.max(1,_this.minPixelRatio/dpr);targetPixelWidth=_this.parentDevicePixelWidth*canvasToParentRatioX*scaleToMeetMinPixelRatio*pinchZoom;targetPixelHeight=_this.parentDevicePixelHeight*canvasToParentRatioY*scaleToMeetMinPixelRatio*pinchZoom;}else {var targetRenderScale=Math.max(dpr,_this.minPixelRatio)*pinchZoom;if(_this.isSafariBrowser){var zoomLevel=bestGuessBrowserZoom();targetRenderScale*=Math.max(1,zoomLevel);}targetPixelWidth=Math.round(canvasWidth)*targetRenderScale;targetPixelHeight=Math.round(canvasHeight)*targetRenderScale;}var maxPixelCountHeadroom=Math.sqrt(_this.maxPixelCount)/Math.sqrt(targetPixelWidth*targetPixelHeight);var scaleToMeetMaxPixelCount=Math.min(1,maxPixelCountHeadroom);var newWidth=Math.round(targetPixelWidth*scaleToMeetMaxPixelCount);var newHeight=Math.round(targetPixelHeight*scaleToMeetMaxPixelCount);var newRenderScale=newWidth/Math.round(canvasWidth);if(_this.canvasElement.width!==newWidth||_this.canvasElement.height!==newHeight||_this.renderScale!==newRenderScale){_this.renderScale=newRenderScale;_this.canvasElement.width=newWidth;_this.canvasElement.height=newHeight;_this.resolutionChanged=true;_this.gl.viewport(0,0,newWidth,newHeight);if(_this.rafId===null){_this.render(performance.now());}}};this.handleDocumentVisibilityChange=function(){if(document.hidden){var _this$video;_this.stopRenderLoop();(_this$video=_this.video)==null?void 0:_this$video.pause();}else {_this.startRenderLoop();if(!_this.config.paused){var _this$video2;(_this$video2=_this.video)==null?void 0:_this$video2.play().catch(function(){});}}};this.render=function(currentTime){if(_this.hasBeenDisposed)return;_this.rafId=requestAnimationFrame(_this.render);if(_this.program===null){console.warn('Tried to render before program was initialized');return;}var gl=_this.gl;var video=_this.video;var currentTimeSeconds=currentTime*0.001;var deltaTime=currentTimeSeconds-_this.lastRenderTime;_this.lastRenderTime=currentTimeSeconds;_this.currentFrame++;var usingStaticImage=!video&&_this.videoTexture!==null;if(!usingStaticImage){if(!video||video.readyState<video.HAVE_CURRENT_DATA){return;}if(!('requestVideoFrameCallback'in video)&&_this.videoTexture){_this.videoTexture.update(video);}if(!_this.config.paused){if(video.currentTime<_this.config.startTime||video.currentTime>=_this.config.endTime){video.currentTime=_this.config.startTime;}}}gl.clear(gl.COLOR_BUFFER_BIT);var videoAnimTime=usingStaticImage?currentTimeSeconds:video.currentTime-_this.config.startTime;if(_this.config.animateLightIndependently||usingStaticImage){_this.independentLightTime+=deltaTime;}else {var videoTimeDelta=videoAnimTime-_this.lastVideoTime;var isVideoJump=Math.abs(videoTimeDelta)>0.1||videoTimeDelta<-0.01;if(isVideoJump){_this.independentLightTime=videoAnimTime;}else {_this.independentLightTime+=deltaTime;}}_this.lastVideoTime=videoAnimTime;gl.useProgram(_this.program);gl.uniform1f(_this.uniformLocations.uTime,currentTimeSeconds);var frameCount=_this.config.animateLightIndependently?_this.independentLightTime*30:videoAnimTime*30;gl.uniform1f(_this.uniformLocations.uFrameCount,frameCount);gl.uniform1f(_this.uniformLocations.uCenterAnimTime,_this.independentLightTime);if(_this.resolutionChanged){gl.uniform2f(_this.uniformLocations.iResolution,_this.canvasElement.width,_this.canvasElement.height);gl.uniform1f(_this.uniformLocations.uDpr,_this.renderScale);gl.uniform4f(_this.uniformLocations.uVisibleUvBounds,_this.visibleUvBounds[0],_this.visibleUvBounds[1],_this.visibleUvBounds[2],_this.visibleUvBounds[3]);_this.resolutionChanged=false;}if(_this.config.animateCycleReps&&_this.currentFrame>_this.config.cycleRepetitionsStartFrame){var elapsed=_this.currentFrame-_this.config.cycleRepetitionsStartFrame;var cycleProgress=elapsed%(_this.config.cycleRepetitionsDuration*2)/_this.config.cycleRepetitionsDuration;var pingPong=cycleProgress<=1?cycleProgress:2-cycleProgress;var eased=pingPong*pingPong*(3-2*pingPong);var delta=_this.config.cycleRepetitionsEnd-_this.config.cycleRepetitionsStart;gl.uniform1f(_this.uniformLocations.uCycleRepetitions,_this.config.cycleRepetitionsStart+eased*delta);}else {gl.uniform1f(_this.uniformLocations.uCycleRepetitions,_this.config.cycleRepetitions);}var targetBlend=_this.config.gradientMapBlend;if(_this.currentGradientMapBlend!==targetBlend){var speed=1.0/_this.config.gradientMapBlendDuration;var diff=targetBlend-_this.currentGradientMapBlend;var step=Math.sign(diff)*Math.min(Math.abs(diff),speed*deltaTime);_this.currentGradientMapBlend+=step;gl.uniform1f(_this.uniformLocations.uGradientMapBlend,_this.currentGradientMapBlend);}gl.drawArrays(gl.TRIANGLES,0,6);};this.handlePerformanceLevelChange=function(level){if(level===0){_this.stopRenderLoop();_this.canvasElement.style.display='none';return;}var _LEVEL_RENDER_SETTING=LEVEL_RENDER_SETTINGS[level],maxPixelCount=_LEVEL_RENDER_SETTING.maxPixelCount,minPixelRatio=_LEVEL_RENDER_SETTING.minPixelRatio;_this.maxPixelCount=maxPixelCount;_this.minPixelRatio=minPixelRatio;if(_this.canvasElement.style.display==='none'){_this.canvasElement.style.display='';}if(_this.isInitialized){_this.startRenderLoop();}_this.handleResize();};this.parentElement=parentElement;this.assets=assets;this.config=Object.assign({},DEFAULT_CONFIG,config);this.currentFrame=frame;this.minPixelRatio=_minPixelRatio;this.maxPixelCount=_maxPixelCount;if(!document.querySelector('style[data-rzp-glass-style]')){var styleElement=document.createElement('style');styleElement.innerHTML=defaultStyle;styleElement.setAttribute('data-rzp-glass-style','');document.head.prepend(styleElement);}this.canvasElement=document.createElement('canvas');this.parentElement.prepend(this.canvasElement);this.parentElement.setAttribute('data-rzp-glass','');var _gl=this.canvasElement.getContext('webgl',{antialias:false,premultipliedAlpha:false,depth:false,alpha:true,powerPreference:'high-performance'});this.gl=_gl;this.performanceController=new WebGLPerformanceController({gl:this.gl,onLevelChange:this.handlePerformanceLevelChange});this.stopIfPotato();_gl.pixelStorei(_gl.UNPACK_FLIP_Y_WEBGL,true);_gl.disable(_gl.DEPTH_TEST);_gl.disable(_gl.CULL_FACE);_gl.clearColor(0,0,0,0);this.initProgram();this.setupPositionAttribute();this.setupUniformLocations();this.setupResizeObserver();(_visualViewport2=visualViewport)==null?void 0:_visualViewport2.addEventListener('resize',this.handleVisualViewportChange);document.addEventListener('visibilitychange',this.handleDocumentVisibilityChange);}return _createClass(RzpGlassMount,[{key:"stopIfPotato",value:function stopIfPotato(){var _this$performanceCont;if(!((_this$performanceCont=this.performanceController)!=null&&_this$performanceCont.isPotato())){return;}this.stopRenderLoop();throw new Error('RzpGlass: WebGL is not supported in this browser');}},{key:"loadAssets",value:(function(){var _loadAssets=_asyncToGenerator(function*(){this.stopIfPotato();try{var _this$assets$gradient;var useStaticImage=Boolean(this.assets.imageSrc);var gradientMap2Src=(_this$assets$gradient=this.assets.gradientMap2Src)!=null?_this$assets$gradient:this.assets.gradientMapSrc;var _yield$Promise$all=yield Promise.all([useStaticImage?loadImage(this.assets.imageSrc):loadVideo(this.assets.videoSrc),loadImage(this.assets.gradientMapSrc),loadImage(gradientMap2Src),loadImage(this.assets.centerGradientMapSrc)]),_yield$Promise$all2=_slicedToArray(_yield$Promise$all,4),baseAsset=_yield$Promise$all2[0],gradientMap=_yield$Promise$all2[1],gradientMap2=_yield$Promise$all2[2],centerGradientMap=_yield$Promise$all2[3];if(useStaticImage){this.setupImageTexture('uVideoTexture',baseAsset,0);}else {this.video=baseAsset;this.setupVideoTexture();this.video.currentTime=this.config.startTime;this.video.playbackRate=this.config.playbackRate;if(!this.config.paused){yield this.video.play().catch(function(e){console.warn('Video autoplay failed:',e);});}}this.setupImageTexture('uGradientMap',gradientMap,1);this.setupImageTexture('uCenterGradientMap',centerGradientMap,2);this.setupImageTexture('uGradientMap2',gradientMap2,3);this.setAllUniforms();this.isInitialized=true;this.handleResize();this.startRenderLoop();}catch(error){console.error('RzpGlass: Failed to load assets',error);throw error;}});function loadAssets(){return _loadAssets.apply(this,arguments);}return loadAssets;}())},{key:"initProgram",value:function initProgram(){var program=createProgram(this.gl,rzpGlassVertexShader,rzpGlassFragmentShader);if(!program){throw new Error('RzpGlass: Failed to create WebGL program');}this.program=program;}},{key:"setupPositionAttribute",value:function setupPositionAttribute(){var buffers=setupFullscreenQuad(this.gl,this.program);if(!buffers){throw new Error('RzpGlass: Failed to setup fullscreen quad');}}},{key:"setupUniformLocations",value:function setupUniformLocations(){var gl=this.gl;var program=this.program;var uniformNames=['uTime','iResolution','uDpr','uVideoTexture','uGradientMap','uGradientMap2','uGradientMapBlend','uCenterGradientMap','uEnableDisplacement','uEnableColorama','uEnableBloom','uEnableLightSweep','uInputMin','uInputMax','uModifyGamma','uPosterizeLevels','uCycleRepetitions','uPhaseShift','uCycleSpeed','uWrapMode','uReverse','uBlendWithOriginal','uLightIntensity','uFrameCount','uLightStartFrame','uNumSegments','uSlitAngle','uDisplacementX','uDisplacementY','uEnableCenterElement','uCenterAnimDuration','uCenterAnimTime','uCCBlackPoint','uCCWhitePoint','uCCMidtoneGamma','uCCGamma','uCCContrast','uZoom','uPan','uEdgeFeather','uRefResolution','uVisibleUvBounds','uBackgroundColor','uEnableRippleWave','uRippleSpeed','uRippleBlend','uRippleAngularPower','uRippleRadialFalloff','uRippleWaitTime'];for(var name of uniformNames){this.uniformLocations[name]=gl.getUniformLocation(program,name);}}},{key:"setupVideoTexture",value:function setupVideoTexture(){var _this2=this;this.videoTexture=new Texture(this.gl,{textureUnit:0});if(this.video&&'requestVideoFrameCallback'in this.video){var _updateVideoFrame=function updateVideoFrame(){if(_this2.hasBeenDisposed||!_this2.video||!_this2.videoTexture)return;_this2.videoTexture.update(_this2.video);_this2.videoFrameCallbackId=_this2.video.requestVideoFrameCallback(_updateVideoFrame);};this.videoFrameCallbackId=this.video.requestVideoFrameCallback(_updateVideoFrame);}}},{key:"setupImageTexture",value:function setupImageTexture(uniformName,image,textureUnit){var texture=new Texture(this.gl,{textureUnit:textureUnit});texture.image(image);if(uniformName==='uVideoTexture'){this.videoTexture=texture;}else if(uniformName==='uGradientMap'){this.gradientMapTexture=texture;}else if(uniformName==='uGradientMap2'){this.gradientMap2Texture=texture;}else if(uniformName==='uCenterGradientMap'){this.centerGradientMapTexture=texture;}}},{key:"updateGradientMapTexture",value:function updateGradientMapTexture(source){if(!this.isInitialized||!this.gradientMapTexture)return;this.gradientMapTexture.image(source);}},{key:"setupResizeObserver",value:function setupResizeObserver(){var _this3=this;this.resizeObserver=new ResizeObserver(function(_ref){var _ref2=_slicedToArray(_ref,1),entry=_ref2[0];if(entry!=null&&entry.borderBoxSize[0]){var _entry$devicePixelCon;var physicalPixelSize=(_entry$devicePixelCon=entry.devicePixelContentBoxSize)==null?void 0:_entry$devicePixelCon[0];if(physicalPixelSize!==undefined){_this3.devicePixelsSupported=true;_this3.parentDevicePixelWidth=physicalPixelSize.inlineSize;_this3.parentDevicePixelHeight=physicalPixelSize.blockSize;}_this3.parentWidth=entry.borderBoxSize[0].inlineSize;_this3.parentHeight=entry.borderBoxSize[0].blockSize;}_this3.handleResize();});this.resizeObserver.observe(this.parentElement);}},{key:"setAllUniforms",value:function setAllUniforms(){var gl=this.gl;gl.useProgram(this.program);gl.uniform1i(this.uniformLocations.uVideoTexture,0);gl.uniform1i(this.uniformLocations.uGradientMap,1);gl.uniform1i(this.uniformLocations.uCenterGradientMap,2);gl.uniform1i(this.uniformLocations.uGradientMap2,3);gl.uniform1f(this.uniformLocations.uGradientMapBlend,this.currentGradientMapBlend);this.setUniformValues(this.config);gl.uniform2f(this.uniformLocations.uPan,this.config.panX,this.config.panY);gl.uniform2f(this.uniformLocations.uRefResolution,REF_RESOLUTION.width,REF_RESOLUTION.height);if(this.config.backgroundColor){var _this$config$backgrou=_slicedToArray(this.config.backgroundColor,3),r=_this$config$backgrou[0],g=_this$config$backgrou[1],b=_this$config$backgrou[2];gl.uniform3f(this.uniformLocations.uBackgroundColor,r,g,b);gl.clearColor(r,g,b,1.0);}else {gl.uniform3f(this.uniformLocations.uBackgroundColor,-1.0,-1.0,-1.0);gl.clearColor(0,0,0,0);}gl.uniform4f(this.uniformLocations.uVisibleUvBounds,this.visibleUvBounds[0],this.visibleUvBounds[1],this.visibleUvBounds[2],this.visibleUvBounds[3]);}},{key:"areUniformValuesEqual",value:function areUniformValuesEqual(a,b){var _this4=this;if(a===b)return true;if(Array.isArray(a)&&Array.isArray(b)&&a.length===b.length){return a.every(function(val,i){return _this4.areUniformValuesEqual(val,b[i]);});}return false;}},{key:"setUniformValues",value:function setUniformValues(config){var _this5=this;var gl=this.gl;gl.useProgram(this.program);Object.entries(config).forEach(function(_ref3){var _ref4=_slicedToArray(_ref3,2),key=_ref4[0],value=_ref4[1];if(value===undefined)return;if(_this5.areUniformValuesEqual(_this5.uniformCache[key],value))return;_this5.uniformCache[key]=value;var uniformName=CONFIG_TO_UNIFORM[key];if(!uniformName)return;var location=_this5.uniformLocations[uniformName];if(!location)return;if(typeof value==='boolean'){gl.uniform1f(location,value?1:0);}else if(typeof value==='number'){gl.uniform1f(location,value);}else if(Array.isArray(value)){var flatArray=value.flat();switch(flatArray.length){case 2:gl.uniform2fv(location,flatArray);break;case 3:gl.uniform3fv(location,flatArray);break;case 4:gl.uniform4fv(location,flatArray);break;}}});if(config.panX!==undefined||config.panY!==undefined){var panCacheKey='pan';var panValue=[this.config.panX,this.config.panY];if(!this.areUniformValuesEqual(this.uniformCache[panCacheKey],panValue)){this.uniformCache[panCacheKey]=panValue;gl.uniform2f(this.uniformLocations.uPan,panValue[0],panValue[1]);}}if(config.backgroundColor!==undefined){var bgCacheKey='backgroundColor';if(!this.areUniformValuesEqual(this.uniformCache[bgCacheKey],config.backgroundColor)){this.uniformCache[bgCacheKey]=config.backgroundColor;if(config.backgroundColor){var _config$backgroundCol=_slicedToArray(config.backgroundColor,3),r=_config$backgroundCol[0],g=_config$backgroundCol[1],b=_config$backgroundCol[2];gl.uniform3f(this.uniformLocations.uBackgroundColor,r,g,b);gl.clearColor(r,g,b,1.0);}else {gl.uniform3f(this.uniformLocations.uBackgroundColor,-1.0,-1.0,-1.0);gl.clearColor(0,0,0,0);}}}}},{key:"setUniforms",value:function setUniforms(newConfig){this.config=Object.assign({},this.config,newConfig);if(!this.isInitialized)return;this.setUniformValues(newConfig);if(newConfig.paused!==undefined){if(newConfig.paused){var _this$video3;(_this$video3=this.video)==null?void 0:_this$video3.pause();}else {var _this$video4;(_this$video4=this.video)==null?void 0:_this$video4.play().catch(function(){});}}if(newConfig.playbackRate!==undefined&&this.video){this.video.playbackRate=newConfig.playbackRate;}if(newConfig.aspectRatio!==undefined){this.handleResize();}}},{key:"startRenderLoop",value:function startRenderLoop(){if(this.rafId!==null)return;this.lastRenderTime=performance.now()*0.001;this.rafId=requestAnimationFrame(this.render);}},{key:"stopRenderLoop",value:function stopRenderLoop(){if(this.rafId!==null){cancelAnimationFrame(this.rafId);this.rafId=null;}}},{key:"getCurrentFrame",value:function getCurrentFrame(){return this.currentFrame;}},{key:"setFrame",value:function setFrame(newFrame){this.currentFrame=newFrame;}},{key:"setMaxPixelCount",value:function setMaxPixelCount(){var newMaxPixelCount=arguments.length>0&&arguments[0]!==undefined?arguments[0]:DEFAULT_MAX_PIXEL_COUNT;this.maxPixelCount=newMaxPixelCount;this.handleResize();}},{key:"setMinPixelRatio",value:function setMinPixelRatio(){var newMinPixelRatio=arguments.length>0&&arguments[0]!==undefined?arguments[0]:2;this.minPixelRatio=newMinPixelRatio;this.handleResize();}},{key:"play",value:function play(){var _this$video5;this.config.paused=false;(_this$video5=this.video)==null?void 0:_this$video5.play().catch(function(){});}},{key:"pause",value:function pause(){var _this$video6;this.config.paused=true;(_this$video6=this.video)==null?void 0:_this$video6.pause();}},{key:"setTime",value:function setTime(time){if(this.video){this.video.currentTime=time;}}},{key:"dispose",value:function dispose(){var _this$performanceCont2,_visualViewport3;this.hasBeenDisposed=true;if(this.rafId!==null){cancelAnimationFrame(this.rafId);this.rafId=null;}if(this.videoFrameCallbackId!==null&&this.video&&'cancelVideoFrameCallback'in this.video){this.video.cancelVideoFrameCallback(this.videoFrameCallbackId);}if(this.video){this.video.pause();this.video.src='';this.video.load();this.video=null;}if(this.gl&&this.program){var _this$videoTexture,_this$gradientMapText,_this$gradientMap2Tex,_this$centerGradientM;(_this$videoTexture=this.videoTexture)==null?void 0:_this$videoTexture.destroy();(_this$gradientMapText=this.gradientMapTexture)==null?void 0:_this$gradientMapText.destroy();(_this$gradientMap2Tex=this.gradientMap2Texture)==null?void 0:_this$gradientMap2Tex.destroy();(_this$centerGradientM=this.centerGradientMapTexture)==null?void 0:_this$centerGradientM.destroy();this.gl.deleteProgram(this.program);this.program=null;this.gl.bindBuffer(this.gl.ARRAY_BUFFER,null);this.gl.bindBuffer(this.gl.ELEMENT_ARRAY_BUFFER,null);this.gl.bindRenderbuffer(this.gl.RENDERBUFFER,null);this.gl.bindFramebuffer(this.gl.FRAMEBUFFER,null);this.gl.getError();}(_this$performanceCont2=this.performanceController)==null?void 0:_this$performanceCont2.dispose();this.performanceController=null;if(this.resizeObserver){this.resizeObserver.disconnect();this.resizeObserver=null;}(_visualViewport3=visualViewport)==null?void 0:_visualViewport3.removeEventListener('resize',this.handleVisualViewportChange);document.removeEventListener('visibilitychange',this.handleDocumentVisibilityChange);this.uniformLocations={};this.uniformCache={};this.canvasElement.remove();this.parentElement.removeAttribute('data-rzp-glass');}}]);}();
|
|
26
|
+
}`;var CONFIG_TO_UNIFORM={enableDisplacement:'uEnableDisplacement',enableColorama:'uEnableColorama',enableBloom:'uEnableBloom',enableLightSweep:'uEnableLightSweep',inputMin:'uInputMin',inputMax:'uInputMax',modifyGamma:'uModifyGamma',posterizeLevels:'uPosterizeLevels',cycleRepetitions:'uCycleRepetitions',phaseShift:'uPhaseShift',cycleSpeed:'uCycleSpeed',wrapMode:'uWrapMode',reverse:'uReverse',blendWithOriginal:'uBlendWithOriginal',lightIntensity:'uLightIntensity',lightStartFrame:'uLightStartFrame',numSegments:'uNumSegments',slitAngle:'uSlitAngle',displacementX:'uDisplacementX',displacementY:'uDisplacementY',enableCenterElement:'uEnableCenterElement',centerAnimDuration:'uCenterAnimDuration',ccBlackPoint:'uCCBlackPoint',ccWhitePoint:'uCCWhitePoint',ccMidtoneGamma:'uCCMidtoneGamma',ccGamma:'uCCGamma',ccContrast:'uCCContrast',zoom:'uZoom',edgeFeather:'uEdgeFeather'};var RzpGlassMount=function(){function RzpGlassMount(parentElement,assets){var _this=this,_visualViewport2;var config=arguments.length>2&&arguments[2]!==undefined?arguments[2]:{};var frame=arguments.length>3&&arguments[3]!==undefined?arguments[3]:0;var _minPixelRatio=arguments.length>4&&arguments[4]!==undefined?arguments[4]:1;var _maxPixelCount=arguments.length>5&&arguments[5]!==undefined?arguments[5]:DEFAULT_MAX_PIXEL_COUNT;_classCallCheck(this,RzpGlassMount);this.program=null;this.uniformLocations={};this.uniformCache={};this.videoTexture=null;this.gradientMapTexture=null;this.gradientMap2Texture=null;this.centerGradientMapTexture=null;this.currentGradientMapBlend=0;this.video=null;this.videoFrameCallbackId=null;this.rafId=null;this.lastRenderTime=0;this.currentFrame=0;this.independentLightTime=0;this.lastVideoTime=0;this.hasBeenDisposed=false;this.isInitialized=false;this.resolutionChanged=true;this.visibleUvBounds=[0,0,1,1];this.resizeObserver=null;this.renderScale=1;this.parentWidth=0;this.parentHeight=0;this.parentDevicePixelWidth=0;this.parentDevicePixelHeight=0;this.devicePixelsSupported=false;this.isSafariBrowser=isSafari();this.performanceController=null;this.handleVisualViewportChange=function(){var _this$resizeObserver;(_this$resizeObserver=_this.resizeObserver)==null?void 0:_this$resizeObserver.disconnect();_this.setupResizeObserver();};this.handleResize=function(){var _visualViewport$scale,_visualViewport;var containerWidth=_this.parentWidth||_this.parentElement.clientWidth;var containerHeight=_this.parentHeight||_this.parentElement.clientHeight;var containerAspect=containerWidth/containerHeight;var canvasWidth;var canvasHeight;var targetAspectRatio=_this.config.aspectRatio;if(containerAspect>targetAspectRatio){canvasWidth=containerWidth;canvasHeight=containerWidth/targetAspectRatio;}else {canvasHeight=containerHeight;canvasWidth=containerHeight*targetAspectRatio;}var offsetX=(containerWidth-canvasWidth)/2;var offsetY=(containerHeight-canvasHeight)/2;var visibleMinX=-offsetX/canvasWidth;var visibleMaxX=(containerWidth-offsetX)/canvasWidth;var visibleMinY=-offsetY/canvasHeight;var visibleMaxY=(containerHeight-offsetY)/canvasHeight;_this.visibleUvBounds=[visibleMinX,visibleMinY,visibleMaxX,visibleMaxY];_this.canvasElement.style.width=`${canvasWidth}px`;_this.canvasElement.style.height=`${canvasHeight}px`;_this.canvasElement.style.left=`${offsetX}px`;_this.canvasElement.style.top=`${offsetY}px`;var targetPixelWidth=0;var targetPixelHeight=0;var dpr=Math.max(1,window.devicePixelRatio);var pinchZoom=(_visualViewport$scale=(_visualViewport=visualViewport)==null?void 0:_visualViewport.scale)!=null?_visualViewport$scale:1;if(_this.devicePixelsSupported){var canvasToParentRatioX=canvasWidth/containerWidth;var canvasToParentRatioY=canvasHeight/containerHeight;var scaleToMeetMinPixelRatio=Math.max(1,_this.minPixelRatio/dpr);targetPixelWidth=_this.parentDevicePixelWidth*canvasToParentRatioX*scaleToMeetMinPixelRatio*pinchZoom;targetPixelHeight=_this.parentDevicePixelHeight*canvasToParentRatioY*scaleToMeetMinPixelRatio*pinchZoom;}else {var targetRenderScale=Math.max(dpr,_this.minPixelRatio)*pinchZoom;if(_this.isSafariBrowser){var zoomLevel=bestGuessBrowserZoom();targetRenderScale*=Math.max(1,zoomLevel);}targetPixelWidth=Math.round(canvasWidth)*targetRenderScale;targetPixelHeight=Math.round(canvasHeight)*targetRenderScale;}var maxPixelCountHeadroom=Math.sqrt(_this.maxPixelCount)/Math.sqrt(targetPixelWidth*targetPixelHeight);var scaleToMeetMaxPixelCount=Math.min(1,maxPixelCountHeadroom);var newWidth=Math.round(targetPixelWidth*scaleToMeetMaxPixelCount);var newHeight=Math.round(targetPixelHeight*scaleToMeetMaxPixelCount);var newRenderScale=newWidth/Math.round(canvasWidth);if(_this.canvasElement.width!==newWidth||_this.canvasElement.height!==newHeight||_this.renderScale!==newRenderScale){_this.renderScale=newRenderScale;_this.canvasElement.width=newWidth;_this.canvasElement.height=newHeight;_this.resolutionChanged=true;_this.gl.viewport(0,0,newWidth,newHeight);if(_this.rafId===null){_this.render(performance.now());}}};this.handleDocumentVisibilityChange=function(){if(document.hidden){var _this$video;_this.stopRenderLoop();(_this$video=_this.video)==null?void 0:_this$video.pause();}else {_this.startRenderLoop();if(!_this.config.paused){var _this$video2;(_this$video2=_this.video)==null?void 0:_this$video2.play().catch(function(){});}}};this.render=function(currentTime){if(_this.hasBeenDisposed)return;_this.rafId=requestAnimationFrame(_this.render);if(_this.program===null){console.warn('Tried to render before program was initialized');return;}var gl=_this.gl;var video=_this.video;var currentTimeSeconds=currentTime*0.001;var deltaTime=currentTimeSeconds-_this.lastRenderTime;_this.lastRenderTime=currentTimeSeconds;_this.currentFrame++;var usingStaticImage=!video&&_this.videoTexture!==null;if(!usingStaticImage){if(!video||video.readyState<video.HAVE_CURRENT_DATA){return;}if(!('requestVideoFrameCallback'in video)&&_this.videoTexture){_this.videoTexture.update(video);}if(!_this.config.paused){if(video.currentTime<_this.config.startTime||video.currentTime>=_this.config.endTime){video.currentTime=_this.config.startTime;}}}gl.clear(gl.COLOR_BUFFER_BIT);var videoAnimTime=usingStaticImage?currentTimeSeconds:video.currentTime-_this.config.startTime;if(_this.config.animateLightIndependently||usingStaticImage){_this.independentLightTime+=deltaTime;}else {var videoTimeDelta=videoAnimTime-_this.lastVideoTime;var isVideoJump=Math.abs(videoTimeDelta)>0.1||videoTimeDelta<-0.01;if(isVideoJump){_this.independentLightTime=videoAnimTime;}else {_this.independentLightTime+=deltaTime;}}_this.lastVideoTime=videoAnimTime;gl.useProgram(_this.program);gl.uniform1f(_this.uniformLocations.uTime,currentTimeSeconds);var frameCount=_this.config.animateLightIndependently?_this.independentLightTime*30:videoAnimTime*30;gl.uniform1f(_this.uniformLocations.uFrameCount,frameCount);gl.uniform1f(_this.uniformLocations.uCenterAnimTime,_this.independentLightTime);if(_this.resolutionChanged){gl.uniform2f(_this.uniformLocations.iResolution,_this.canvasElement.width,_this.canvasElement.height);gl.uniform1f(_this.uniformLocations.uDpr,_this.renderScale);gl.uniform4f(_this.uniformLocations.uVisibleUvBounds,_this.visibleUvBounds[0],_this.visibleUvBounds[1],_this.visibleUvBounds[2],_this.visibleUvBounds[3]);_this.resolutionChanged=false;}if(_this.config.animateCycleReps&&_this.currentFrame>_this.config.cycleRepetitionsStartFrame){var elapsed=_this.currentFrame-_this.config.cycleRepetitionsStartFrame;var cycleProgress=elapsed%(_this.config.cycleRepetitionsDuration*2)/_this.config.cycleRepetitionsDuration;var pingPong=cycleProgress<=1?cycleProgress:2-cycleProgress;var eased=pingPong*pingPong*(3-2*pingPong);var delta=_this.config.cycleRepetitionsEnd-_this.config.cycleRepetitionsStart;gl.uniform1f(_this.uniformLocations.uCycleRepetitions,_this.config.cycleRepetitionsStart+eased*delta);}else {gl.uniform1f(_this.uniformLocations.uCycleRepetitions,_this.config.cycleRepetitions);}var targetBlend=_this.config.gradientMapBlend;if(_this.currentGradientMapBlend!==targetBlend){var speed=1.0/_this.config.gradientMapBlendDuration;var diff=targetBlend-_this.currentGradientMapBlend;var step=Math.sign(diff)*Math.min(Math.abs(diff),speed*deltaTime);_this.currentGradientMapBlend+=step;gl.uniform1f(_this.uniformLocations.uGradientMapBlend,_this.currentGradientMapBlend);}gl.drawArrays(gl.TRIANGLES,0,6);};this.handlePerformanceLevelChange=function(level){if(level===0){_this.stopRenderLoop();_this.canvasElement.style.display='none';return;}var _LEVEL_RENDER_SETTING=LEVEL_RENDER_SETTINGS[level],maxPixelCount=_LEVEL_RENDER_SETTING.maxPixelCount,minPixelRatio=_LEVEL_RENDER_SETTING.minPixelRatio;_this.maxPixelCount=maxPixelCount;_this.minPixelRatio=minPixelRatio;if(_this.canvasElement.style.display==='none'){_this.canvasElement.style.display='';}if(_this.isInitialized){_this.startRenderLoop();}_this.handleResize();};this.parentElement=parentElement;this.assets=assets;this.config=Object.assign({},DEFAULT_CONFIG,config);this.currentFrame=frame;this.minPixelRatio=_minPixelRatio;this.maxPixelCount=_maxPixelCount;if(!document.querySelector('style[data-rzp-glass-style]')){var styleElement=document.createElement('style');styleElement.innerHTML=defaultStyle;styleElement.setAttribute('data-rzp-glass-style','');document.head.prepend(styleElement);}this.canvasElement=document.createElement('canvas');this.parentElement.prepend(this.canvasElement);this.parentElement.setAttribute('data-rzp-glass','');var _gl=this.canvasElement.getContext('webgl',{antialias:false,premultipliedAlpha:false,depth:false,alpha:true,powerPreference:'high-performance'});this.gl=_gl;_gl.pixelStorei(_gl.UNPACK_FLIP_Y_WEBGL,true);_gl.disable(_gl.DEPTH_TEST);_gl.disable(_gl.CULL_FACE);_gl.clearColor(0,0,0,0);this.initProgram();this.performanceController=new WebGLPerformanceController({gl:this.gl,onLevelChange:this.handlePerformanceLevelChange});this.stopIfPotato();this.setupPositionAttribute();this.setupUniformLocations();this.setupResizeObserver();(_visualViewport2=visualViewport)==null?void 0:_visualViewport2.addEventListener('resize',this.handleVisualViewportChange);document.addEventListener('visibilitychange',this.handleDocumentVisibilityChange);}return _createClass(RzpGlassMount,[{key:"stopIfPotato",value:function stopIfPotato(){var _this$performanceCont;if(!((_this$performanceCont=this.performanceController)!=null&&_this$performanceCont.isPotato())){return;}this.stopRenderLoop();throw new Error('RzpGlass: WebGL is not supported in this browser');}},{key:"loadAssets",value:(function(){var _loadAssets=_asyncToGenerator(function*(){this.stopIfPotato();try{var _this$assets$gradient;var useStaticImage=Boolean(this.assets.imageSrc);var gradientMap2Src=(_this$assets$gradient=this.assets.gradientMap2Src)!=null?_this$assets$gradient:this.assets.gradientMapSrc;var _yield$Promise$all=yield Promise.all([useStaticImage?loadImage(this.assets.imageSrc):loadVideo(this.assets.videoSrc),loadImage(this.assets.gradientMapSrc),loadImage(gradientMap2Src),loadImage(this.assets.centerGradientMapSrc)]),_yield$Promise$all2=_slicedToArray(_yield$Promise$all,4),baseAsset=_yield$Promise$all2[0],gradientMap=_yield$Promise$all2[1],gradientMap2=_yield$Promise$all2[2],centerGradientMap=_yield$Promise$all2[3];if(useStaticImage){this.setupImageTexture('uVideoTexture',baseAsset,0);}else {this.video=baseAsset;this.setupVideoTexture();this.video.currentTime=this.config.startTime;this.video.playbackRate=this.config.playbackRate;if(!this.config.paused){yield this.video.play().catch(function(e){console.warn('Video autoplay failed:',e);});}}this.setupImageTexture('uGradientMap',gradientMap,1);this.setupImageTexture('uCenterGradientMap',centerGradientMap,2);this.setupImageTexture('uGradientMap2',gradientMap2,3);this.setAllUniforms();this.isInitialized=true;this.handleResize();this.startRenderLoop();}catch(error){console.error('RzpGlass: Failed to load assets',error);throw error;}});function loadAssets(){return _loadAssets.apply(this,arguments);}return loadAssets;}())},{key:"initProgram",value:function initProgram(){var program=createProgram(this.gl,rzpGlassVertexShader,rzpGlassFragmentShader);if(!program){throw new Error('RzpGlass: Failed to create WebGL program');}this.program=program;}},{key:"setupPositionAttribute",value:function setupPositionAttribute(){var buffers=setupFullscreenQuad(this.gl,this.program);if(!buffers){throw new Error('RzpGlass: Failed to setup fullscreen quad');}}},{key:"setupUniformLocations",value:function setupUniformLocations(){var gl=this.gl;var program=this.program;var uniformNames=['uTime','iResolution','uDpr','uVideoTexture','uGradientMap','uGradientMap2','uGradientMapBlend','uCenterGradientMap','uEnableDisplacement','uEnableColorama','uEnableBloom','uEnableLightSweep','uInputMin','uInputMax','uModifyGamma','uPosterizeLevels','uCycleRepetitions','uPhaseShift','uCycleSpeed','uWrapMode','uReverse','uBlendWithOriginal','uLightIntensity','uFrameCount','uLightStartFrame','uNumSegments','uSlitAngle','uDisplacementX','uDisplacementY','uEnableCenterElement','uCenterAnimDuration','uCenterAnimTime','uCCBlackPoint','uCCWhitePoint','uCCMidtoneGamma','uCCGamma','uCCContrast','uZoom','uPan','uEdgeFeather','uRefResolution','uVisibleUvBounds','uBackgroundColor','uEnableRippleWave','uRippleSpeed','uRippleBlend','uRippleAngularPower','uRippleRadialFalloff','uRippleWaitTime'];for(var name of uniformNames){this.uniformLocations[name]=gl.getUniformLocation(program,name);}}},{key:"setupVideoTexture",value:function setupVideoTexture(){var _this2=this;this.videoTexture=new Texture(this.gl,{textureUnit:0});if(this.video&&'requestVideoFrameCallback'in this.video){var _updateVideoFrame=function updateVideoFrame(){if(_this2.hasBeenDisposed||!_this2.video||!_this2.videoTexture)return;_this2.videoTexture.update(_this2.video);_this2.videoFrameCallbackId=_this2.video.requestVideoFrameCallback(_updateVideoFrame);};this.videoFrameCallbackId=this.video.requestVideoFrameCallback(_updateVideoFrame);}}},{key:"setupImageTexture",value:function setupImageTexture(uniformName,image,textureUnit){var texture=new Texture(this.gl,{textureUnit:textureUnit});texture.image(image);if(uniformName==='uVideoTexture'){this.videoTexture=texture;}else if(uniformName==='uGradientMap'){this.gradientMapTexture=texture;}else if(uniformName==='uGradientMap2'){this.gradientMap2Texture=texture;}else if(uniformName==='uCenterGradientMap'){this.centerGradientMapTexture=texture;}}},{key:"updateGradientMapTexture",value:function updateGradientMapTexture(source){if(!this.isInitialized||!this.gradientMapTexture)return;this.gradientMapTexture.image(source);}},{key:"setupResizeObserver",value:function setupResizeObserver(){var _this3=this;this.resizeObserver=new ResizeObserver(function(_ref){var _ref2=_slicedToArray(_ref,1),entry=_ref2[0];if(entry!=null&&entry.borderBoxSize[0]){var _entry$devicePixelCon;var physicalPixelSize=(_entry$devicePixelCon=entry.devicePixelContentBoxSize)==null?void 0:_entry$devicePixelCon[0];if(physicalPixelSize!==undefined){_this3.devicePixelsSupported=true;_this3.parentDevicePixelWidth=physicalPixelSize.inlineSize;_this3.parentDevicePixelHeight=physicalPixelSize.blockSize;}_this3.parentWidth=entry.borderBoxSize[0].inlineSize;_this3.parentHeight=entry.borderBoxSize[0].blockSize;}_this3.handleResize();});this.resizeObserver.observe(this.parentElement);}},{key:"setAllUniforms",value:function setAllUniforms(){var gl=this.gl;gl.useProgram(this.program);gl.uniform1i(this.uniformLocations.uVideoTexture,0);gl.uniform1i(this.uniformLocations.uGradientMap,1);gl.uniform1i(this.uniformLocations.uCenterGradientMap,2);gl.uniform1i(this.uniformLocations.uGradientMap2,3);gl.uniform1f(this.uniformLocations.uGradientMapBlend,this.currentGradientMapBlend);this.setUniformValues(this.config);gl.uniform2f(this.uniformLocations.uPan,this.config.panX,this.config.panY);gl.uniform2f(this.uniformLocations.uRefResolution,REF_RESOLUTION.width,REF_RESOLUTION.height);if(this.config.backgroundColor){var _this$config$backgrou=_slicedToArray(this.config.backgroundColor,3),r=_this$config$backgrou[0],g=_this$config$backgrou[1],b=_this$config$backgrou[2];gl.uniform3f(this.uniformLocations.uBackgroundColor,r,g,b);gl.clearColor(r,g,b,1.0);}else {gl.uniform3f(this.uniformLocations.uBackgroundColor,-1.0,-1.0,-1.0);gl.clearColor(0,0,0,0);}gl.uniform4f(this.uniformLocations.uVisibleUvBounds,this.visibleUvBounds[0],this.visibleUvBounds[1],this.visibleUvBounds[2],this.visibleUvBounds[3]);}},{key:"areUniformValuesEqual",value:function areUniformValuesEqual(a,b){var _this4=this;if(a===b)return true;if(Array.isArray(a)&&Array.isArray(b)&&a.length===b.length){return a.every(function(val,i){return _this4.areUniformValuesEqual(val,b[i]);});}return false;}},{key:"setUniformValues",value:function setUniformValues(config){var _this5=this;var gl=this.gl;gl.useProgram(this.program);Object.entries(config).forEach(function(_ref3){var _ref4=_slicedToArray(_ref3,2),key=_ref4[0],value=_ref4[1];if(value===undefined)return;if(_this5.areUniformValuesEqual(_this5.uniformCache[key],value))return;_this5.uniformCache[key]=value;var uniformName=CONFIG_TO_UNIFORM[key];if(!uniformName)return;var location=_this5.uniformLocations[uniformName];if(!location)return;if(typeof value==='boolean'){gl.uniform1f(location,value?1:0);}else if(typeof value==='number'){gl.uniform1f(location,value);}else if(Array.isArray(value)){var flatArray=value.flat();switch(flatArray.length){case 2:gl.uniform2fv(location,flatArray);break;case 3:gl.uniform3fv(location,flatArray);break;case 4:gl.uniform4fv(location,flatArray);break;}}});if(config.panX!==undefined||config.panY!==undefined){var panCacheKey='pan';var panValue=[this.config.panX,this.config.panY];if(!this.areUniformValuesEqual(this.uniformCache[panCacheKey],panValue)){this.uniformCache[panCacheKey]=panValue;gl.uniform2f(this.uniformLocations.uPan,panValue[0],panValue[1]);}}if(config.backgroundColor!==undefined){var bgCacheKey='backgroundColor';if(!this.areUniformValuesEqual(this.uniformCache[bgCacheKey],config.backgroundColor)){this.uniformCache[bgCacheKey]=config.backgroundColor;if(config.backgroundColor){var _config$backgroundCol=_slicedToArray(config.backgroundColor,3),r=_config$backgroundCol[0],g=_config$backgroundCol[1],b=_config$backgroundCol[2];gl.uniform3f(this.uniformLocations.uBackgroundColor,r,g,b);gl.clearColor(r,g,b,1.0);}else {gl.uniform3f(this.uniformLocations.uBackgroundColor,-1.0,-1.0,-1.0);gl.clearColor(0,0,0,0);}}}}},{key:"setUniforms",value:function setUniforms(newConfig){this.config=Object.assign({},this.config,newConfig);if(!this.isInitialized)return;this.setUniformValues(newConfig);if(newConfig.paused!==undefined){if(newConfig.paused){var _this$video3;(_this$video3=this.video)==null?void 0:_this$video3.pause();}else {var _this$video4;(_this$video4=this.video)==null?void 0:_this$video4.play().catch(function(){});}}if(newConfig.playbackRate!==undefined&&this.video){this.video.playbackRate=newConfig.playbackRate;}if(newConfig.aspectRatio!==undefined){this.handleResize();}}},{key:"startRenderLoop",value:function startRenderLoop(){if(this.rafId!==null)return;this.lastRenderTime=performance.now()*0.001;this.rafId=requestAnimationFrame(this.render);}},{key:"stopRenderLoop",value:function stopRenderLoop(){if(this.rafId!==null){cancelAnimationFrame(this.rafId);this.rafId=null;}}},{key:"getCurrentFrame",value:function getCurrentFrame(){return this.currentFrame;}},{key:"setFrame",value:function setFrame(newFrame){this.currentFrame=newFrame;}},{key:"setMaxPixelCount",value:function setMaxPixelCount(){var newMaxPixelCount=arguments.length>0&&arguments[0]!==undefined?arguments[0]:DEFAULT_MAX_PIXEL_COUNT;this.maxPixelCount=newMaxPixelCount;this.handleResize();}},{key:"setMinPixelRatio",value:function setMinPixelRatio(){var newMinPixelRatio=arguments.length>0&&arguments[0]!==undefined?arguments[0]:2;this.minPixelRatio=newMinPixelRatio;this.handleResize();}},{key:"play",value:function play(){var _this$video5;this.config.paused=false;(_this$video5=this.video)==null?void 0:_this$video5.play().catch(function(){});}},{key:"pause",value:function pause(){var _this$video6;this.config.paused=true;(_this$video6=this.video)==null?void 0:_this$video6.pause();}},{key:"setTime",value:function setTime(time){if(this.video){this.video.currentTime=time;}}},{key:"dispose",value:function dispose(){var _this$performanceCont2,_visualViewport3;this.hasBeenDisposed=true;if(this.rafId!==null){cancelAnimationFrame(this.rafId);this.rafId=null;}if(this.videoFrameCallbackId!==null&&this.video&&'cancelVideoFrameCallback'in this.video){this.video.cancelVideoFrameCallback(this.videoFrameCallbackId);}if(this.video){this.video.pause();this.video.src='';this.video.load();this.video=null;}if(this.gl&&this.program){var _this$videoTexture,_this$gradientMapText,_this$gradientMap2Tex,_this$centerGradientM;(_this$videoTexture=this.videoTexture)==null?void 0:_this$videoTexture.destroy();(_this$gradientMapText=this.gradientMapTexture)==null?void 0:_this$gradientMapText.destroy();(_this$gradientMap2Tex=this.gradientMap2Texture)==null?void 0:_this$gradientMap2Tex.destroy();(_this$centerGradientM=this.centerGradientMapTexture)==null?void 0:_this$centerGradientM.destroy();this.gl.deleteProgram(this.program);this.program=null;this.gl.bindBuffer(this.gl.ARRAY_BUFFER,null);this.gl.bindBuffer(this.gl.ELEMENT_ARRAY_BUFFER,null);this.gl.bindRenderbuffer(this.gl.RENDERBUFFER,null);this.gl.bindFramebuffer(this.gl.FRAMEBUFFER,null);this.gl.getError();}(_this$performanceCont2=this.performanceController)==null?void 0:_this$performanceCont2.dispose();this.performanceController=null;if(this.resizeObserver){this.resizeObserver.disconnect();this.resizeObserver=null;}(_visualViewport3=visualViewport)==null?void 0:_visualViewport3.removeEventListener('resize',this.handleVisualViewportChange);document.removeEventListener('visibilitychange',this.handleDocumentVisibilityChange);this.uniformLocations={};this.uniformCache={};this.canvasElement.remove();this.parentElement.removeAttribute('data-rzp-glass');}}]);}();
|
|
26
27
|
|
|
27
28
|
export { RzpGlassMount };
|
|
28
29
|
//# sourceMappingURL=RzpGlassMount.js.map
|