@razorpay/blade
Version:
The Design System that powers Razorpay
30 lines (26 loc) • 23.1 kB
JavaScript
import _slicedToArray from '@babel/runtime/helpers/slicedToArray';
import _asyncToGenerator from '@babel/runtime/helpers/asyncToGenerator';
import _classCallCheck from '@babel/runtime/helpers/classCallCheck';
import _createClass from '@babel/runtime/helpers/createClass';
import { rzpGlassFragmentShader, rzpGlassVertexShader } from './rzpGlassShader.js';
import { DEFAULT_CONFIG } from './presets.js';
import { loadImage, loadVideo, isSafari, bestGuessBrowserZoom } from './utils.js';
import { createProgram, setupFullscreenQuad, Texture } from './webgl-utils.js';
import { WebGLPerformanceController, LEVEL_RENDER_SETTINGS } from './PerformanceManager.js';
var REF_RESOLUTION={width:3000,height:2000};var DEFAULT_MAX_PIXEL_COUNT=1920*1080*4;var defaultStyle=` rzp-glass {
:where([data-rzp-glass]) {
isolation: isolate;
position: relative;
overflow: hidden;
& canvas {
contain: strict;
display: block;
position: absolute;
z-index: -1;
border-radius: inherit;
pointer-events: none;
}
}
}`;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');}}]);}();
export { RzpGlassMount };
//# sourceMappingURL=RzpGlassMount.js.map