!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).UnicornStudio={})}(this,function(e){"use strict";var t=Object.defineProperty,s=(e,s,i)=>((e,s,i)=>s in e?t(e,s,{enumerable:!0,configurable:!0,writable:!0,value:i}):e[s]=i)(e,"symbol"!=typeof s?s+"":s,i);let i=0;function r(){if(!(i>100)){if(100===i);else{Array.prototype.slice.call(arguments)}i++}}function a(){Array.prototype.slice.call(arguments)}function n(){return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,e=>{let t=16*Math.random()|0;return("x"===e?t:3&t|8).toString(16).toUpperCase()})}function o(e){return!(e&e-1)}let h=class{constructor(e){if(this.type="Scene",e&&"Renderer"===e.type){if(!e.gl)return void a(this.type+": Renderer WebGL context is undefined",e)}else a(this.type+": Renderer not passed as first argument",e);this.renderer=e,this.gl=e.gl,this.initStacks()}initStacks(){this.stacks={pingPong:[],renderTargets:[],opaque:[],transparent:[],renderPasses:[],scenePasses:[]}}resetPlaneStacks(){this.stacks.pingPong=[],this.stacks.renderTargets=[],this.stacks.opaque=[],this.stacks.transparent=[];for(let e=0;e"PingPongPlane"!==t.type&&t.target&&t.uuid!==e.uuid);let s=-1;if(e.target._depth){for(let i=t.length-1;i>=0;i--)if(t[i].target.uuid===e.target.uuid){s=i+1;break}}else s=t.findIndex(t=>t.target.uuid===e.target.uuid);s=Math.max(0,s),t.splice(s,0,e),e.target._depth?(t.sort((e,t)=>e.index-t.index),t.sort((e,t)=>t.renderOrder-e.renderOrder)):(t.sort((e,t)=>t.index-e.index),t.sort((e,t)=>e.renderOrder-t.renderOrder)),t.sort((e,t)=>e.target.index-t.target.index),this.stacks.renderTargets=t}addToRegularPlaneStack(e){const t=this.renderer.planes.filter(t=>"PingPongPlane"!==t.type&&!t.target&&t._transparent===e._transparent&&t.uuid!==e.uuid);let s=-1;for(let i=t.length-1;i>=0;i--)if(t[i]._geometry.definition.id===e._geometry.definition.id){s=i+1;break}return s=Math.max(0,s),t.splice(s,0,e),t.sort((e,t)=>e.index-t.index),t}addPlane(e){if("PingPongPlane"===e.type)this.stacks.pingPong.push(e);else if(e.target)this.addToRenderTargetsStack(e);else if(e._transparent){const t=this.addToRegularPlaneStack(e);t.sort((e,t)=>t.relativeTranslation.z-e.relativeTranslation.z),t.sort((e,t)=>t.renderOrder-e.renderOrder),this.stacks.transparent=t}else{const t=this.addToRegularPlaneStack(e);t.sort((e,t)=>t.renderOrder-e.renderOrder),this.stacks.opaque=t}}removePlane(e){"PingPongPlane"===e.type?this.stacks.pingPong=this.stacks.pingPong.filter(t=>t.uuid!==e.uuid):e.target?this.stacks.renderTargets=this.stacks.renderTargets.filter(t=>t.uuid!==e.uuid):e._transparent?this.stacks.transparent=this.stacks.transparent.filter(t=>t.uuid!==e.uuid):this.stacks.opaque=this.stacks.opaque.filter(t=>t.uuid!==e.uuid)}setPlaneRenderOrder(e){if("ShaderPass"===e.type)this.sortShaderPassStack(e._isScenePass?this.stacks.scenePasses:this.stacks.renderPasses);else if("PingPongPlane"===e.type)return;if(e.target)e.target._depth?(this.stacks.renderTargets.sort((e,t)=>e.index-t.index),this.stacks.renderTargets.sort((e,t)=>t.renderOrder-e.renderOrder)):(this.stacks.renderTargets.sort((e,t)=>t.index-e.index),this.stacks.renderTargets.sort((e,t)=>e.renderOrder-t.renderOrder)),this.stacks.renderTargets.sort((e,t)=>e.target.index-t.target.index);else{const t=e._transparent?this.stacks.transparent:this.stacks.opaque,s=this.stacks.scenePasses.find((e,t)=>e._isScenePass&&!e._depth&&0===t);!this.renderer.depth||s?(t.sort((e,t)=>t.index-e.index),e._transparent&&t.sort((e,t)=>e.relativeTranslation.z-t.relativeTranslation.z),t.sort((e,t)=>e.renderOrder-t.renderOrder)):(t.sort((e,t)=>e.index-t.index),e._transparent&&t.sort((e,t)=>t.relativeTranslation.z-e.relativeTranslation.z),t.sort((e,t)=>t.renderOrder-e.renderOrder))}}addShaderPass(e){e._isScenePass?(this.stacks.scenePasses.push(e),this.sortShaderPassStack(this.stacks.scenePasses)):(this.stacks.renderPasses.push(e),this.sortShaderPassStack(this.stacks.renderPasses))}removeShaderPass(e){this.resetShaderPassStacks()}sortShaderPassStack(e){e.sort((e,t)=>e.index-t.index),e.sort((e,t)=>e.renderOrder-t.renderOrder)}enableShaderPass(){this.stacks.scenePasses.length&&0===this.stacks.renderPasses.length&&this.renderer.planes.length&&(this.renderer.state.scenePassIndex=0,this.renderer.bindFrameBuffer(this.stacks.scenePasses[0].target))}drawRenderPasses(){this.stacks.scenePasses.length&&this.stacks.renderPasses.length&&this.renderer.planes.length&&(this.renderer.state.scenePassIndex=0,this.renderer.bindFrameBuffer(this.stacks.scenePasses[0].target));for(let e=0;et.id===e)}addGeometry(e,t,s){this.geometries.push({id:e,vertices:t,uvs:s})}isSameShader(e,t){return 0===e.localeCompare(t)}getProgramFromShaders(e,t){return this.programs.find(s=>this.isSameShader(s.vsCode,e)&&this.isSameShader(s.fsCode,t))}addProgram(e){this.programs.push(e)}getTextureFromSource(e){const t="string"==typeof e?e:e.src;return this.textures.find(e=>e.source&&e.source.src===t)}addTexture(e){this.getTextureFromSource(e.source)||this.textures.push(e)}removeTexture(e){this.textures=this.textures.filter(t=>t.uuid!==e.uuid)}}class d{constructor(){this.clear()}clear(){this.queue=[]}add(e,t=!1){const s={callback:e,keep:t,timeout:null};return s.timeout=setTimeout(()=>{this.queue.push(s)},0),s}execute(){this.queue.map(e=>{e.callback&&e.callback(),clearTimeout(this.queue.timeout)}),this.queue=this.queue.filter(e=>e.keep)}}class u{constructor({alpha:e,antialias:t,premultipliedAlpha:s,depth:i,failIfMajorPerformanceCaveat:a,preserveDrawingBuffer:n,stencil:o,container:h,pixelRatio:l,renderingScale:d,production:u,onError:c,onSuccess:p,onContextLost:m,onContextRestored:g,onDisposed:f,onSceneChange:_}){this.type="Renderer",this.alpha=e,this.antialias=t,this.premultipliedAlpha=s,this.depth=i,this.failIfMajorPerformanceCaveat=a,this.preserveDrawingBuffer=n,this.stencil=o,this.container=h,this.pixelRatio=l,this._renderingScale=d,this.production=u,this.onError=c,this.onSuccess=p,this.onContextLost=m,this.onContextRestored=g,this.onDisposed=f,this.onSceneChange=_,this.initState(),this.canvas=document.createElement("canvas");const x={alpha:this.alpha,premultipliedAlpha:this.premultipliedAlpha,antialias:this.antialias,depth:this.depth,failIfMajorPerformanceCaveat:this.failIfMajorPerformanceCaveat,preserveDrawingBuffer:this.preserveDrawingBuffer,stencil:this.stencil};if(this.gl=this.canvas.getContext("webgl2",x),this._isWebGL2=!!this.gl,this.gl||(this.gl=this.canvas.getContext("webgl",x)||this.canvas.getContext("experimental-webgl",x)),!this.gl)return this.production||r(this.type+": WebGL context could not be created"),this.state.isActive=!1,void(this.onError&&this.onError());this.onSuccess&&this.onSuccess(),this.initRenderer()}initState(){this.state={isActive:!0,isContextLost:!0,drawingEnabled:!0,forceRender:!1,currentProgramID:null,currentGeometryID:null,forceBufferUpdate:!1,depthTest:null,blending:null,cullFace:null,frameBufferID:null,scenePassIndex:null,activeTexture:null,unpackAlignment:null,flipY:null,premultiplyAlpha:null}}initCallbackQueueManager(){this.nextRender=new d}initRenderer(){this.planes=[],this.renderTargets=[],this.shaderPasses=[],this.state.isContextLost=!1,this.state.maxTextureSize=this.gl.getParameter(this.gl.MAX_TEXTURE_SIZE),this.initCallbackQueueManager(),this.setBlendFunc(),this.setDepthFunc(),this.setDepthTest(!0),this.cache=new l,this.scene=new h(this),this.getExtensions(),this._contextLostHandler=this.contextLost.bind(this),this.canvas.addEventListener("webglcontextlost",this._contextLostHandler,!1),this._contextRestoredHandler=this.contextRestored.bind(this),this.canvas.addEventListener("webglcontextrestored",this._contextRestoredHandler,!1)}getExtensions(){this.extensions=[],this._isWebGL2?(this.extensions.EXT_color_buffer_float=this.gl.getExtension("EXT_color_buffer_float"),this.extensions.OES_texture_float_linear=this.gl.getExtension("OES_texture_float_linear"),this.extensions.EXT_texture_filter_anisotropic=this.gl.getExtension("EXT_texture_filter_anisotropic"),this.extensions.WEBGL_lose_context=this.gl.getExtension("WEBGL_lose_context")):(this.extensions.OES_vertex_array_object=this.gl.getExtension("OES_vertex_array_object"),this.extensions.OES_texture_float=this.gl.getExtension("OES_texture_float"),this.extensions.OES_texture_float_linear=this.gl.getExtension("OES_texture_float_linear"),this.extensions.OES_texture_half_float=this.gl.getExtension("OES_texture_half_float"),this.extensions.OES_texture_half_float_linear=this.gl.getExtension("OES_texture_half_float_linear"),this.extensions.EXT_texture_filter_anisotropic=this.gl.getExtension("EXT_texture_filter_anisotropic"),this.extensions.OES_element_index_uint=this.gl.getExtension("OES_element_index_uint"),this.extensions.OES_standard_derivatives=this.gl.getExtension("OES_standard_derivatives"),this.extensions.EXT_sRGB=this.gl.getExtension("EXT_sRGB"),this.extensions.WEBGL_depth_texture=this.gl.getExtension("WEBGL_depth_texture"),this.extensions.WEBGL_draw_buffers=this.gl.getExtension("WEBGL_draw_buffers"),this.extensions.WEBGL_lose_context=this.gl.getExtension("WEBGL_lose_context"))}contextLost(e){this.state.isContextLost=!0,this.state.isActive&&(e.preventDefault(),this.nextRender.add(()=>this.onContextLost&&this.onContextLost()))}restoreContext(){this.state.isActive&&(this.initState(),this.gl&&this.extensions.WEBGL_lose_context?this.extensions.WEBGL_lose_context.restoreContext():(this.gl||this.production?this.extensions.WEBGL_lose_context||this.production||r(this.type+": Could not restore the context because the restore context extension is not defined"):r(this.type+": Could not restore the context because the context is not defined"),this.onError&&this.onError()))}isContextexFullyRestored(){let e=!0;for(let t=0;t{this.isContextexFullyRestored()&&(e.keep=!1,this.state.isContextLost=!1,this.onContextRestored&&this.onContextRestored(),this.onSceneChange(),this.needRender())},!0)}setPixelRatio(e){this.pixelRatio=e}setSize(){if(!this.gl)return;const e=this.container.getBoundingClientRect();this._boundingRect={width:e.width*this.pixelRatio,height:e.height*this.pixelRatio,top:e.top*this.pixelRatio,left:e.left*this.pixelRatio},this.canvas.style.width=Math.floor(this._boundingRect.width/this.pixelRatio)+"px",this.canvas.style.height=Math.floor(this._boundingRect.height/this.pixelRatio)+"px",this.canvas.width=Math.floor(this._boundingRect.width*this._renderingScale),this.canvas.height=Math.floor(this._boundingRect.height*this._renderingScale),this.gl.viewport(0,0,this.gl.drawingBufferWidth,this.gl.drawingBufferHeight)}resize(){for(let e=0;et.uuid!==e.uuid),this.scene.removePlane(e),e=null,this.gl&&this.clear(),this.onSceneChange())}removeRenderTarget(e){if(!this.gl)return;let t=this.planes.find(t=>"PingPongPlane"!==t.type&&t.target&&t.target.uuid===e.uuid);for(let s=0;st.uuid!==e.uuid);for(let s=0;st.uuid!==e.uuid),this.scene.removeShaderPass(e),e=null,this.gl&&this.clear(),this.onSceneChange())}enableDrawing(){this.state.drawingEnabled=!0}disableDrawing(){this.state.drawingEnabled=!1}needRender(){this.state.forceRender=!0}render(){this.gl&&(this.clear(),this.state.currentGeometryID=null,this.scene.draw())}deletePrograms(){for(let e=0;e0;)this.removePlane(this.planes[0]);for(;this.shaderPasses.length>0;)this.removeShaderPass(this.shaderPasses[0]);for(;this.renderTargets.length>0;)this.removeRenderTarget(this.renderTargets[0]);let e=this.nextRender.add(()=>{0===this.planes.length&&0===this.shaderPasses.length&&0===this.renderTargets.length&&(e.keep=!1,this.deletePrograms(),this.clear(),this.canvas.removeEventListener("webgllost",this._contextLostHandler,!1),this.canvas.removeEventListener("webglrestored",this._contextRestoredHandler,!1),this.gl&&this.extensions.WEBGL_lose_context&&this.extensions.WEBGL_lose_context.loseContext(),this.canvas.width=this.canvas.width,this.gl=null,this.container.removeChild(this.canvas),this.container=null,this.canvas=null,this.onDisposed&&this.onDisposed())},!0)}}class c{constructor({xOffset:e=0,yOffset:t=0,lastXDelta:s=0,lastYDelta:i=0,shouldWatch:r=!0,onScroll:a=()=>{}}={}){this.xOffset=e,this.yOffset=t,this.lastXDelta=s,this.lastYDelta=i,this.shouldWatch=r,this.onScroll=a,this.handler=this.scroll.bind(this,!0),this.shouldWatch&&window.addEventListener("scroll",this.handler,{passive:!0})}scroll(){this.updateScrollValues(window.pageXOffset,window.pageYOffset)}updateScrollValues(e,t){const s=this.xOffset;this.xOffset=e,this.lastXDelta=s-this.xOffset;const i=this.yOffset;this.yOffset=t,this.lastYDelta=i-this.yOffset,this.onScroll&&this.onScroll(this.lastXDelta,this.lastYDelta)}dispose(){this.shouldWatch&&window.removeEventListener("scroll",this.handler,{passive:!0})}}class p{constructor({container:e,alpha:t=!0,premultipliedAlpha:s=!1,antialias:i=!0,depth:a=!0,failIfMajorPerformanceCaveat:n=!0,preserveDrawingBuffer:o=!1,stencil:h=!1,autoResize:l=!0,autoRender:d=!0,watchScroll:u=!0,pixelRatio:c=window.devicePixelRatio||1,renderingScale:p=1,production:m=!1}={}){this.type="Curtains",this._autoResize=l,this._autoRender=d,this._watchScroll=u,this.pixelRatio=c,p=isNaN(p)?1:parseFloat(p),this._renderingScale=Math.max(.25,Math.min(1,p)),this.premultipliedAlpha=s,this.alpha=t,this.antialias=i,this.depth=a,this.failIfMajorPerformanceCaveat=n,this.preserveDrawingBuffer=o,this.stencil=h,this.production=m,this.errors=!1,e?this.setContainer(e):this.production||r(this.type+": no container provided in the initial parameters. Use setContainer() method to set one later and initialize the WebGL context")}setContainer(e){if(e)if("string"==typeof e)if(e=document.getElementById(e))this.container=e;else{let e=document.createElement("div");e.setAttribute("id","curtains-canvas"),document.body.appendChild(e),this.container=e,this.production||r('Curtains: no valid container HTML element or ID provided, created a div with "curtains-canvas" ID instead')}else e instanceof Element&&(this.container=e);else{let e=document.createElement("div");e.setAttribute("id","curtains-canvas"),document.body.appendChild(e),this.container=e,this.production||r('Curtains: no valid container HTML element or ID provided, created a div with "curtains-canvas" ID instead')}this._initCurtains()}_initCurtains(){this.planes=[],this.renderTargets=[],this.shaderPasses=[],this._initRenderer(),this.gl&&(this._initScroll(),this._setSize(),this._addListeners(),this.container.appendChild(this.canvas),this._animationFrameID=null,this._autoRender&&this._animate())}_initRenderer(){this.renderer=new u({alpha:this.alpha,antialias:this.antialias,premultipliedAlpha:this.premultipliedAlpha,depth:this.depth,failIfMajorPerformanceCaveat:this.failIfMajorPerformanceCaveat,preserveDrawingBuffer:this.preserveDrawingBuffer,stencil:this.stencil,container:this.container,pixelRatio:this.pixelRatio,renderingScale:this._renderingScale,production:this.production,onError:()=>this._onRendererError(),onSuccess:()=>this._onRendererSuccess(),onContextLost:()=>this._onRendererContextLost(),onContextRestored:()=>this._onRendererContextRestored(),onDisposed:()=>this._onRendererDisposed(),onSceneChange:()=>this._keepSync()}),this.gl=this.renderer.gl,this.canvas=this.renderer.canvas}restoreContext(){this.renderer.restoreContext()}_animate(){this.render(),this._animationFrameID=window.requestAnimationFrame(this._animate.bind(this))}enableDrawing(){this.renderer.enableDrawing()}disableDrawing(){this.renderer.disableDrawing()}needRender(){this.renderer.needRender()}nextRender(e,t=!1){return this.renderer.nextRender.add(e,t)}clear(){this.renderer&&this.renderer.clear()}clearDepth(){this.renderer&&this.renderer.clearDepth()}clearColor(){this.renderer&&this.renderer.clearColor()}isWebGL2(){return!!this.gl&&this.renderer._isWebGL2}render(){this.renderer.nextRender.execute(),(this.renderer.state.drawingEnabled||this.renderer.state.forceRender)&&(this.renderer.state.forceRender&&(this.renderer.state.forceRender=!1),this._onRenderCallback&&this._onRenderCallback(),this.renderer.render())}_addListeners(){this._resizeHandler=null,this._autoResize&&(this._resizeHandler=this.resize.bind(this,!0),window.addEventListener("resize",this._resizeHandler,!1))}setPixelRatio(e,t){this.pixelRatio=parseFloat(Math.max(e,1))||1,this.renderer.setPixelRatio(e),this.resize(t)}_setSize(){this.renderer.setSize(),this._scrollManager.shouldWatch&&(this._scrollManager.xOffset=window.pageXOffset,this._scrollManager.yOffset=window.pageYOffset)}getBoundingRect(){return this.renderer._boundingRect}resize(e){this.gl&&(this._setSize(),this.renderer.resize(),this.nextRender(()=>{this._onAfterResizeCallback&&e&&this._onAfterResizeCallback()}))}_initScroll(){this._scrollManager=new c({xOffset:window.pageXOffset,yOffset:0,lastXDelta:0,lastYDelta:0,shouldWatch:this._watchScroll,onScroll:(e,t)=>this._updateScroll(e,t)})}_updateScroll(e,t){for(let s=0;s{this._onErrorCallback&&!this.errors&&this._onErrorCallback(),this.errors=!0},0)}onSuccess(e){return e&&(this._onSuccessCallback=e),this}_onRendererSuccess(){setTimeout(()=>{this._onSuccessCallback&&this._onSuccessCallback()},0)}onContextLost(e){return e&&(this._onContextLostCallback=e),this}_onRendererContextLost(){this._onContextLostCallback&&this._onContextLostCallback()}onContextRestored(e){return e&&(this._onContextRestoredCallback=e),this}_onRendererContextRestored(){this._onContextRestoredCallback&&this._onContextRestoredCallback()}onRender(e){return e&&(this._onRenderCallback=e),this}onScroll(e){return e&&(this._onScrollCallback=e),this}dispose(){this.renderer.dispose()}_onRendererDisposed(){this._animationFrameID&&window.cancelAnimationFrame(this._animationFrameID),this._resizeHandler&&window.removeEventListener("resize",this._resizeHandler,!1),this._scrollManager&&this._scrollManager.dispose()}}class m{constructor(e,t,s){if(this.type="Uniforms",e&&"Renderer"===e.type){if(!e.gl)return void a(this.type+": Renderer WebGL context is undefined",e)}else a(this.type+": Renderer not passed as first argument",e);if(this.renderer=e,this.gl=e.gl,this.program=t,this.uniforms={},s)for(const i in s){const e=s[i];this.uniforms[i]={name:e.name,type:e.type,value:e.value.clone&&"function"==typeof e.value.clone?e.value.clone():e.value,update:null}}}handleUniformSetting(e){switch(e.type){case"1i":e.update=this.setUniform1i.bind(this);break;case"1iv":e.update=this.setUniform1iv.bind(this);break;case"1f":e.update=this.setUniform1f.bind(this);break;case"1fv":e.update=this.setUniform1fv.bind(this);break;case"2i":e.update=this.setUniform2i.bind(this);break;case"2iv":e.update=this.setUniform2iv.bind(this);break;case"2f":e.update=this.setUniform2f.bind(this);break;case"2fv":e.update=this.setUniform2fv.bind(this);break;case"3i":e.update=this.setUniform3i.bind(this);break;case"3iv":e.update=this.setUniform3iv.bind(this);break;case"3f":e.update=this.setUniform3f.bind(this);break;case"3fv":e.update=this.setUniform3fv.bind(this);break;case"4i":e.update=this.setUniform4i.bind(this);break;case"4iv":e.update=this.setUniform4iv.bind(this);break;case"4f":e.update=this.setUniform4f.bind(this);break;case"4fv":e.update=this.setUniform4fv.bind(this);break;case"mat2":e.update=this.setUniformMatrix2fv.bind(this);break;case"mat3":e.update=this.setUniformMatrix3fv.bind(this);break;case"mat4":e.update=this.setUniformMatrix4fv.bind(this);break;default:this.renderer.production||r(this.type+": This uniform type is not handled : ",e.type)}}setInternalFormat(e){"Vec2"===e.value.type?(e._internalFormat="Vec2",e.lastValue=e.value.clone()):"Vec3"===e.value.type?(e._internalFormat="Vec3",e.lastValue=e.value.clone()):"Mat4"===e.value.type?(e._internalFormat="Mat4",e.lastValue=e.value.clone()):"Quat"===e.value.type?(e._internalFormat="Quat",e.lastValue=e.value.clone()):Array.isArray(e.value)?(e._internalFormat="array",e.lastValue=Array.from(e.value)):e.value.constructor===Float32Array?(e._internalFormat="mat",e.lastValue=e.value):(e._internalFormat="float",e.lastValue=e.value)}setUniforms(){if(this.uniforms)for(const e in this.uniforms){let t=this.uniforms[e];t.location=this.gl.getUniformLocation(this.program,t.name),t._internalFormat||this.setInternalFormat(t),t.type||("Vec2"===t._internalFormat?t.type="2f":"Vec3"===t._internalFormat?t.type="3f":"Mat4"===t._internalFormat?t.type="mat4":"array"===t._internalFormat?4===t.value.length?(t.type="4f",this.renderer.production||r(this.type+": No uniform type declared for "+t.name+", applied a 4f (array of 4 floats) uniform type")):3===t.value.length?(t.type="3f",this.renderer.production||r(this.type+": No uniform type declared for "+t.name+", applied a 3f (array of 3 floats) uniform type")):2===t.value.length&&(t.type="2f",this.renderer.production||r(this.type+": No uniform type declared for "+t.name+", applied a 2f (array of 2 floats) uniform type")):"mat"===t._internalFormat?16===t.value.length?(t.type="mat4",this.renderer.production||r(this.type+": No uniform type declared for "+t.name+", applied a mat4 (4x4 matrix array) uniform type")):9===t.value.length?(t.type="mat3",this.renderer.production||r(this.type+": No uniform type declared for "+t.name+", applied a mat3 (3x3 matrix array) uniform type")):4===t.value.length&&(t.type="mat2",this.renderer.production||r(this.type+": No uniform type declared for "+t.name+", applied a mat2 (2x2 matrix array) uniform type")):(t.type="1f",this.renderer.production||r(this.type+": No uniform type declared for "+t.name+", applied a 1f (float) uniform type"))),this.handleUniformSetting(t),t.update&&t.update(t)}}updateUniforms(){if(this.uniforms)for(const e in this.uniforms){const t=this.uniforms[e];let s=!1;"Vec2"===t._internalFormat||"Vec3"===t._internalFormat||"Quat"===t._internalFormat?t.value.equals(t.lastValue)||(s=!0,t.lastValue.copy(t.value)):t.value.length?JSON.stringify(t.value)!==JSON.stringify(t.lastValue)&&(s=!0,t.lastValue=Array.from(t.value)):t.value!==t.lastValue&&(s=!0,t.lastValue=t.value),s&&t.update&&t.update(t)}}setUniform1i(e){this.gl.uniform1i(e.location,e.value)}setUniform1iv(e){this.gl.uniform1iv(e.location,e.value)}setUniform1f(e){this.gl.uniform1f(e.location,e.value)}setUniform1fv(e){this.gl.uniform1fv(e.location,e.value)}setUniform2i(e){"Vec2"===e._internalFormat?this.gl.uniform2i(e.location,e.value.x,e.value.y):this.gl.uniform2i(e.location,e.value[0],e.value[1])}setUniform2iv(e){"Vec2"===e._internalFormat?this.gl.uniform2iv(e.location,[e.value.x,e.value.y]):this.gl.uniform2iv(e.location,e.value)}setUniform2f(e){"Vec2"===e._internalFormat?this.gl.uniform2f(e.location,e.value.x,e.value.y):this.gl.uniform2f(e.location,e.value[0],e.value[1])}setUniform2fv(e){"Vec2"===e._internalFormat?this.gl.uniform2fv(e.location,[e.value.x,e.value.y]):this.gl.uniform2fv(e.location,e.value)}setUniform3i(e){"Vec3"===e._internalFormat?this.gl.uniform3i(e.location,e.value.x,e.value.y,e.value.z):this.gl.uniform3i(e.location,e.value[0],e.value[1],e.value[2])}setUniform3iv(e){"Vec3"===e._internalFormat?this.gl.uniform3iv(e.location,[e.value.x,e.value.y,e.value.z]):this.gl.uniform3iv(e.location,e.value)}setUniform3f(e){"Vec3"===e._internalFormat?this.gl.uniform3f(e.location,e.value.x,e.value.y,e.value.z):this.gl.uniform3f(e.location,e.value[0],e.value[1],e.value[2])}setUniform3fv(e){"Vec3"===e._internalFormat?this.gl.uniform3fv(e.location,[e.value.x,e.value.y,e.value.z]):this.gl.uniform3fv(e.location,e.value)}setUniform4i(e){"Quat"===e._internalFormat?this.gl.uniform4i(e.location,e.value.elements[0],e.value.elements[1],e.value.elements[2],e.value[3]):this.gl.uniform4i(e.location,e.value[0],e.value[1],e.value[2],e.value[3])}setUniform4iv(e){"Quat"===e._internalFormat?this.gl.uniform4iv(e.location,[e.value.elements[0],e.value.elements[1],e.value.elements[2],e.value[3]]):this.gl.uniform4iv(e.location,e.value)}setUniform4f(e){"Quat"===e._internalFormat?this.gl.uniform4f(e.location,e.value.elements[0],e.value.elements[1],e.value.elements[2],e.value[3]):this.gl.uniform4f(e.location,e.value[0],e.value[1],e.value[2],e.value[3])}setUniform4fv(e){"Quat"===e._internalFormat?this.gl.uniform4fv(e.location,[e.value.elements[0],e.value.elements[1],e.value.elements[2],e.value[3]]):this.gl.uniform4fv(e.location,e.value)}setUniformMatrix2fv(e){this.gl.uniformMatrix2fv(e.location,!1,e.value)}setUniformMatrix3fv(e){this.gl.uniformMatrix3fv(e.location,!1,e.value)}setUniformMatrix4fv(e){"Mat4"===e._internalFormat?this.gl.uniformMatrix4fv(e.location,!1,e.value.elements):this.gl.uniformMatrix4fv(e.location,!1,e.value)}}const g="\nprecision mediump float;\n".replace(/\n/g,""),f="\nattribute vec3 aVertexPosition;\nattribute vec2 aTextureCoord;\n".replace(/\n/g,""),_="\nvarying vec3 vVertexPosition;\nvarying vec2 vTextureCoord;\n".replace(/\n/g,""),x=(g+f+_+"\nuniform mat4 uMVMatrix;\nuniform mat4 uPMatrix;\n\nvoid main() {\n vTextureCoord = aTextureCoord;\n vVertexPosition = aVertexPosition;\n \n gl_Position = uPMatrix * uMVMatrix * vec4(aVertexPosition, 1.0);\n}\n").replace(/\n/g,""),v=(g+_+"\nvoid main() {\n gl_FragColor = vec4(0.0, 0.0, 0.0, 1.0);\n}\n").replace(/\n/g,""),y=(g+f+_+"\nvoid main() {\n vTextureCoord = aTextureCoord;\n vVertexPosition = aVertexPosition;\n \n gl_Position = vec4(aVertexPosition, 1.0);\n}\n").replace(/\n/g,""),b=(g+_+"\nuniform sampler2D uRenderTexture;\n\nvoid main() {\n gl_FragColor = texture2D(uRenderTexture, vTextureCoord);\n}\n").replace(/\n/g,"");let P=0;class w{constructor(e,{parent:t,vertexShader:s,fragmentShader:i}={}){if(this.type="Program",e&&"Renderer"===e.type){if(!e.gl)return void a(this.type+": Renderer WebGL context is undefined",e)}else a(this.type+": Renderer not passed as first argument",e);this.renderer=e,this.gl=this.renderer.gl,this.parent=t,this.defaultVsCode="Plane"===this.parent.type?x:y,this.defaultFsCode="Plane"===this.parent.type?v:b,s?this.vsCode=s:(this.renderer.production||"Plane"!==this.parent.type||r(this.parent.type+": No vertex shader provided, will use a default one"),this.vsCode=this.defaultVsCode),i?this.fsCode=i:(this.renderer.production||r(this.parent.type+": No fragment shader provided, will use a default one"),this.fsCode=this.defaultFsCode),this.compiled=!0,this.setupProgram()}createShader(e,t){const s=this.gl.createShader(t);if(this.gl.shaderSource(s,e),this.gl.compileShader(s),!this.renderer.production&&!this.gl.getShaderParameter(s,this.gl.COMPILE_STATUS)){const e=t===this.gl.VERTEX_SHADER?"vertex shader":"fragment shader";let i=this.gl.getShaderSource(s).split("\n");for(let t=0;t0&&(e=1/Math.sqrt(e)),this._x*=e,this._y*=e,this}dot(e){return this._x*e.x+this._y*e.y}}class M{constructor(e=0,t=e,s=e){this.type="Vec3",this._x=e,this._y=t,this._z=s}get x(){return this._x}get y(){return this._y}get z(){return this._z}set x(e){const t=e!==this._x;this._x=e,t&&this._onChangeCallback&&this._onChangeCallback()}set y(e){const t=e!==this._y;this._y=e,t&&this._onChangeCallback&&this._onChangeCallback()}set z(e){const t=e!==this._z;this._z=e,t&&this._onChangeCallback&&this._onChangeCallback()}onChange(e){return e&&(this._onChangeCallback=e),this}set(e,t,s){return this._x=e,this._y=t,this._z=s,this}add(e){return this._x+=e.x,this._y+=e.y,this._z+=e.z,this}addScalar(e){return this._x+=e,this._y+=e,this._z+=e,this}sub(e){return this._x-=e.x,this._y-=e.y,this._z-=e.z,this}subScalar(e){return this._x-=e,this._y-=e,this._z-=e,this}multiply(e){return this._x*=e.x,this._y*=e.y,this._z*=e.z,this}multiplyScalar(e){return this._x*=e,this._y*=e,this._z*=e,this}copy(e){return this._x=e.x,this._y=e.y,this._z=e.z,this}clone(){return new M(this._x,this._y,this._z)}sanitizeNaNValuesWith(e){return this._x=isNaN(this._x)?e.x:parseFloat(this._x),this._y=isNaN(this._y)?e.y:parseFloat(this._y),this._z=isNaN(this._z)?e.z:parseFloat(this._z),this}max(e){return this._x=Math.max(this._x,e.x),this._y=Math.max(this._y,e.y),this._z=Math.max(this._z,e.z),this}min(e){return this._x=Math.min(this._x,e.x),this._y=Math.min(this._y,e.y),this._z=Math.min(this._z,e.z),this}equals(e){return this._x===e.x&&this._y===e.y&&this._z===e.z}normalize(){let e=this._x*this._x+this._y*this._y+this._z*this._z;return e>0&&(e=1/Math.sqrt(e)),this._x*=e,this._y*=e,this._z*=e,this}dot(e){return this._x*e.x+this._y*e.y+this._z*e.z}applyMat4(e){const t=this._x,s=this._y,i=this._z,r=e.elements;let a=r[3]*t+r[7]*s+r[11]*i+r[15];return a=a||1,this._x=(r[0]*t+r[4]*s+r[8]*i+r[12])/a,this._y=(r[1]*t+r[5]*s+r[9]*i+r[13])/a,this._z=(r[2]*t+r[6]*s+r[10]*i+r[14])/a,this}applyQuat(e){const t=this._x,s=this._y,i=this._z,r=e.elements[0],a=e.elements[1],n=e.elements[2],o=e.elements[3],h=o*t+a*i-n*s,l=o*s+n*t-r*i,d=o*i+r*s-a*t,u=-r*t-a*s-n*i;return this._x=h*o+u*-r+l*-n-d*-a,this._y=l*o+u*-a+d*-r-h*-n,this._z=d*o+u*-n+h*-a-l*-r,this}project(e){return this.applyMat4(e.viewMatrix).applyMat4(e.projectionMatrix),this}unproject(e){return this.applyMat4(e.projectionMatrix.getInverse()).applyMat4(e.worldMatrix),this}}const E=new S,C=new M,k=new R;class A{constructor(e,{isFBOTexture:t=!1,fromTexture:s=!1,loader:i,sampler:r,floatingPoint:o="none",premultiplyAlpha:h=!1,anisotropy:l=1,generateMipmap:d=null,wrapS:u,wrapT:c,minFilter:p,magFilter:m}={}){if(this.type="Texture",(e=e&&e.renderer||e)&&"Renderer"===e.type){if(!e.gl)return void(e.production||a(this.type+": Unable to create a "+this.type+" because the Renderer WebGL context is not defined"))}else a(this.type+": Renderer not passed as first argument",e);if(this.renderer=e,this.gl=this.renderer.gl,this.uuid=n(),this._globalParameters={unpackAlignment:4,flipY:!t,premultiplyAlpha:!1,shouldPremultiplyAlpha:h,floatingPoint:o,type:this.gl.UNSIGNED_BYTE,internalFormat:this.gl.RGBA,format:this.gl.RGBA},this.parameters={anisotropy:l,generateMipmap:d,wrapS:u||this.gl.CLAMP_TO_EDGE,wrapT:c||this.gl.CLAMP_TO_EDGE,minFilter:p||this.gl.LINEAR,magFilter:m||this.gl.LINEAR,_shouldUpdate:!0},this._initState(),this.sourceType=t?"fbo":"empty",this._useCache=!0,this._samplerName=r,this._sampler={isActive:!1,isTextureBound:!1,texture:this.gl.createTexture()},this._textureMatrix={matrix:new R,isActive:!1},this._size={width:1,height:1},this.scale=new S(1),this.scale.onChange(()=>this.resize()),this.offset=new S,this.offset.onChange(()=>this.resize()),this._loader=i,this._sourceLoaded=!1,this._uploaded=!1,this._willUpdate=!1,this.shouldUpdate=!1,this._forceUpdate=!1,this.userData={},this._canDraw=!1,s)return this._copyOnInit=!0,void(this._copiedFrom=s);this._copyOnInit=!1,this._initTexture()}_initState(){this._state={anisotropy:1,generateMipmap:!1,wrapS:null,wrapT:null,minFilter:null,magFilter:this.gl.LINEAR}}_initTexture(){this.gl.bindTexture(this.gl.TEXTURE_2D,this._sampler.texture),"empty"===this.sourceType&&(this._globalParameters.flipY=!1,this._updateGlobalTexParameters(),this.gl.texImage2D(this.gl.TEXTURE_2D,0,this.gl.RGBA,1,1,0,this.gl.RGBA,this.gl.UNSIGNED_BYTE,new Uint8Array([0,0,0,255])),this._canDraw=!0)}_restoreFromTexture(){this._copyOnInit||this._initTexture(),this._parent&&(this._setTextureUniforms(),this._setSize()),this.copy(this._copiedFrom),this._canDraw=!0}_restoreContext(){if(this._canDraw=!1,this._sampler.texture=this.gl.createTexture(),this._sampler.isActive=!1,this._sampler.isTextureBound=!1,this._textureMatrix.isActive=!1,this._initState(),this._state.generateMipmap=!1,this.parameters._shouldUpdate=!0,this._copiedFrom){const e=this.renderer.nextRender.add(()=>{this._copiedFrom._canDraw&&(this._restoreFromTexture(),e.keep=!1)},!0)}else this._initTexture(),this._parent&&this._setParent(),this.source&&(this.setSource(this.source),"image"===this.sourceType?this.renderer.cache.addTexture(this):this.needUpdate()),this._canDraw=!0}addParent(e){!e||"Plane"!==e.type&&"PingPongPlane"!==e.type&&"ShaderPass"!==e.type&&"RenderTarget"!==e.type?this.renderer.production||r(this.type+": cannot add texture as a child of ",e," because it is not a valid parent"):(this._parent=e,this.index=this._parent.textures.length,this._parent.textures.push(this),this._setParent())}_setParent(){if(this._sampler.name=this._samplerName||"uSampler"+this.index,this._textureMatrix.name=this._samplerName?this._samplerName+"Matrix":"uTextureMatrix"+this.index,this._parent._program){if(!this._parent._program.compiled)return void(this.renderer.production||r(this.type+": Unable to create the texture because the program is not valid"));if(this._setTextureUniforms(),this._copyOnInit){const e=this.renderer.nextRender.add(()=>{this._copiedFrom._canDraw&&this._copiedFrom._uploaded&&(this.copy(this._copiedFrom),e.keep=!1)},!0);return}this.source?this._parent.loader&&this._parent.loader._addSourceToParent(this.source,this.sourceType):this._size={width:this._parent._boundingRect.document.width,height:this._parent._boundingRect.document.height},this._setSize()}else"RenderTarget"===this._parent.type&&(this._size={width:this._parent._size&&this._parent._size.width||this.renderer._boundingRect.width,height:this._parent._size&&this._parent._size.height||this.renderer._boundingRect.height},this._upload(),this._updateTexParameters(),this._canDraw=!0)}hasParent(){return!!this._parent}_setTextureUniforms(){const e=this._parent._program.activeUniforms;for(let t=0;te===this._textureMatrix.name)&&(this._textureMatrix.isActive=!0,this._textureMatrix.location=this.gl.getUniformLocation(this._parent._program.program,this._textureMatrix.name)),this.gl.uniform1i(this._sampler.location,this.index)}}copy(e){e&&"Texture"===e.type?(this._globalParameters=Object.assign({},e._globalParameters),this._state=Object.assign({},e._state),this.parameters.generateMipmap=e.parameters.generateMipmap,this._state.generateMipmap=null,this._size=e._size,!this._sourceLoaded&&e._sourceLoaded&&this._onSourceLoadedCallback&&this._onSourceLoadedCallback(),this._sourceLoaded=e._sourceLoaded,!this._uploaded&&e._uploaded&&this._onSourceUploadedCallback&&this._onSourceUploadedCallback(),this._uploaded=e._uploaded,this.sourceType=e.sourceType,this.source=e.source,this._videoFrameCallbackID=e._videoFrameCallbackID,this._sampler.texture=e._sampler.texture,this._copiedFrom=e,!this._parent||!this._parent._program||this._canDraw&&this._textureMatrix.matrix||(this._setSize(),this._canDraw=!0),this._updateTexParameters(),this.renderer.needRender()):this.renderer.production||r(this.type+": Unable to set the texture from texture:",e)}setSource(e){this._sourceLoaded||this.renderer.nextRender.add(()=>this._onSourceLoadedCallback&&this._onSourceLoadedCallback());const t="IMG"===e.tagName.toUpperCase()?"image":e.tagName.toLowerCase();if("video"!==t&&"canvas"!==t||(this._useCache=!1),this._useCache){const t=this.renderer.cache.getTextureFromSource(e);if(t&&t.uuid!==this.uuid)return this._uploaded||(this.renderer.nextRender.add(()=>this._onSourceUploadedCallback&&this._onSourceUploadedCallback()),this._uploaded=!0),this.copy(t),void this.resize()}if("empty"===this.sourceType||this.sourceType!==t)if("video"===t)this._willUpdate=!1,this.shouldUpdate=!0;else if("canvas"===t)this._willUpdate=!0,this.shouldUpdate=!0;else{if("image"!==t)return void(this.renderer.production||r(this.type+": this HTML tag could not be converted into a texture:",e.tagName));this._willUpdate=!1,this.shouldUpdate=!1}this.source=e,this.sourceType=t,this._size={width:this.source.naturalWidth||this.source.width||this.source.videoWidth,height:this.source.naturalHeight||this.source.height||this.source.videoHeight},this._sourceLoaded=!0,this.gl.bindTexture(this.gl.TEXTURE_2D,this._sampler.texture),this.resize(),this._globalParameters.flipY=!0,this._globalParameters.premultiplyAlpha=this._globalParameters.shouldPremultiplyAlpha,"image"===this.sourceType&&(this.parameters.generateMipmap=this.parameters.generateMipmap||null===this.parameters.generateMipmap,this.parameters._shouldUpdate=this.parameters.generateMipmap,this._state.generateMipmap=!1,this._upload()),this.renderer.needRender()}_updateGlobalTexParameters(){this.renderer.state.unpackAlignment!==this._globalParameters.unpackAlignment&&(this.gl.pixelStorei(this.gl.UNPACK_ALIGNMENT,this._globalParameters.unpackAlignment),this.renderer.state.unpackAlignment=this._globalParameters.unpackAlignment),this.renderer.state.flipY!==this._globalParameters.flipY&&(this.gl.pixelStorei(this.gl.UNPACK_FLIP_Y_WEBGL,this._globalParameters.flipY),this.renderer.state.flipY=this._globalParameters.flipY),this.renderer.state.premultiplyAlpha!==this._globalParameters.premultiplyAlpha&&(this.gl.pixelStorei(this.gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL,this._globalParameters.premultiplyAlpha),this.renderer.state.premultiplyAlpha=this._globalParameters.premultiplyAlpha),"half-float"===this._globalParameters.floatingPoint?this.renderer._isWebGL2&&this.renderer.extensions.EXT_color_buffer_float?(this._globalParameters.internalFormat=this.gl.RGBA16F,this._globalParameters.type=this.gl.HALF_FLOAT):this.renderer.extensions.OES_texture_half_float?this._globalParameters.type=this.renderer.extensions.OES_texture_half_float.HALF_FLOAT_OES:this.renderer.production||r(this.type+": could not use half-float textures because the extension is not available"):"float"===this._globalParameters.floatingPoint&&(this.renderer._isWebGL2&&this.renderer.extensions.EXT_color_buffer_float?(this._globalParameters.internalFormat=this.gl.RGBA16F,this._globalParameters.type=this.gl.FLOAT):this.renderer.extensions.OES_texture_float?this._globalParameters.type=this.renderer.extensions.OES_texture_half_float.FLOAT:this.renderer.production||r(this.type+": could not use float textures because the extension is not available"))}_updateTexParameters(){this.index&&this.renderer.state.activeTexture!==this.index&&this._bindTexture(),this.parameters.wrapS!==this._state.wrapS&&(this.renderer._isWebGL2||o(this._size.width)&&o(this._size.height)||(this.parameters.wrapS=this.gl.CLAMP_TO_EDGE),this.parameters.wrapS!==this.gl.REPEAT&&this.parameters.wrapS!==this.gl.CLAMP_TO_EDGE&&this.parameters.wrapS!==this.gl.MIRRORED_REPEAT&&(this.renderer.production||r(this.type+": Wrong wrapS value",this.parameters.wrapS,"for this texture:",this,"\ngl.CLAMP_TO_EDGE wrapping will be used instead"),this.parameters.wrapS=this.gl.CLAMP_TO_EDGE),this.gl.texParameteri(this.gl.TEXTURE_2D,this.gl.TEXTURE_WRAP_S,this.parameters.wrapS),this._state.wrapS=this.parameters.wrapS),this.parameters.wrapT!==this._state.wrapT&&(this.renderer._isWebGL2||o(this._size.width)&&o(this._size.height)||(this.parameters.wrapT=this.gl.CLAMP_TO_EDGE),this.parameters.wrapT!==this.gl.REPEAT&&this.parameters.wrapT!==this.gl.CLAMP_TO_EDGE&&this.parameters.wrapT!==this.gl.MIRRORED_REPEAT&&(this.renderer.production||r(this.type+": Wrong wrapT value",this.parameters.wrapT,"for this texture:",this,"\ngl.CLAMP_TO_EDGE wrapping will be used instead"),this.parameters.wrapT=this.gl.CLAMP_TO_EDGE),this.gl.texParameteri(this.gl.TEXTURE_2D,this.gl.TEXTURE_WRAP_T,this.parameters.wrapT),this._state.wrapT=this.parameters.wrapT),this.parameters.generateMipmap&&!this._state.generateMipmap&&this.source&&(this.renderer._isWebGL2||o(this._size.width)&&o(this._size.height)?this.gl.generateMipmap(this.gl.TEXTURE_2D):this.parameters.generateMipmap=!1,this._state.generateMipmap=this.parameters.generateMipmap),this.parameters.minFilter!==this._state.minFilter&&(this.renderer._isWebGL2||o(this._size.width)&&o(this._size.height)||(this.parameters.minFilter=this.gl.LINEAR),this.parameters.generateMipmap||null===this.parameters.generateMipmap||(this.parameters.minFilter=this.gl.LINEAR),this.parameters.minFilter!==this.gl.LINEAR&&this.parameters.minFilter!==this.gl.NEAREST&&this.parameters.minFilter!==this.gl.NEAREST_MIPMAP_NEAREST&&this.parameters.minFilter!==this.gl.LINEAR_MIPMAP_NEAREST&&this.parameters.minFilter!==this.gl.NEAREST_MIPMAP_LINEAR&&this.parameters.minFilter!==this.gl.LINEAR_MIPMAP_LINEAR&&(this.renderer.production||r(this.type+": Wrong minFilter value",this.parameters.minFilter,"for this texture:",this,"\ngl.LINEAR filtering will be used instead"),this.parameters.minFilter=this.gl.LINEAR),this.gl.texParameteri(this.gl.TEXTURE_2D,this.gl.TEXTURE_MIN_FILTER,this.parameters.minFilter),this._state.minFilter=this.parameters.minFilter),this.parameters.magFilter!==this._state.magFilter&&(this.renderer._isWebGL2||o(this._size.width)&&o(this._size.height)||(this.parameters.magFilter=this.gl.LINEAR),this.parameters.magFilter!==this.gl.LINEAR&&this.parameters.magFilter!==this.gl.NEAREST&&(this.renderer.production||r(this.type+": Wrong magFilter value",this.parameters.magFilter,"for this texture:",this,"\ngl.LINEAR filtering will be used instead"),this.parameters.magFilter=this.gl.LINEAR),this.gl.texParameteri(this.gl.TEXTURE_2D,this.gl.TEXTURE_MAG_FILTER,this.parameters.magFilter),this._state.magFilter=this.parameters.magFilter);const e=this.renderer.extensions.EXT_texture_filter_anisotropic;if(e&&this.parameters.anisotropy!==this._state.anisotropy){const t=this.gl.getParameter(e.MAX_TEXTURE_MAX_ANISOTROPY_EXT);this.parameters.anisotropy=Math.max(1,Math.min(this.parameters.anisotropy,t)),this.gl.texParameterf(this.gl.TEXTURE_2D,e.TEXTURE_MAX_ANISOTROPY_EXT,this.parameters.anisotropy),this._state.anisotropy=this.parameters.anisotropy}}setWrapS(e){this.parameters.wrapS!==e&&(this.parameters.wrapS=e,this.parameters._shouldUpdate=!0)}setWrapT(e){this.parameters.wrapT!==e&&(this.parameters.wrapT=e,this.parameters._shouldUpdate=!0)}setMinFilter(e){this.parameters.minFilter!==e&&(this.parameters.minFilter=e,this.parameters._shouldUpdate=!0)}setMagFilter(e){this.parameters.magFilter!==e&&(this.parameters.magFilter=e,this.parameters._shouldUpdate=!0)}setAnisotropy(e){e=isNaN(e)?this.parameters.anisotropy:e,this.parameters.anisotropy!==e&&(this.parameters.anisotropy=e,this.parameters._shouldUpdate=!0)}needUpdate(){this._forceUpdate=!0}_videoFrameCallback(){if(this._willUpdate=!0,this.source)this.source.requestVideoFrameCallback(()=>this._videoFrameCallback());else{const e=this.renderer.nextRender.add(()=>{this.source&&(e.keep=!1,this.source.requestVideoFrameCallback(()=>this._videoFrameCallback()))},!0)}}_upload(){this._updateGlobalTexParameters(),this.source?this.gl.texImage2D(this.gl.TEXTURE_2D,0,this._globalParameters.internalFormat,this._globalParameters.format,this._globalParameters.type,this.source):"fbo"===this.sourceType&&this.gl.texImage2D(this.gl.TEXTURE_2D,0,this._globalParameters.internalFormat,this._size.width,this._size.height,0,this._globalParameters.format,this._globalParameters.type,this.source||null),this._uploaded||(this.renderer.nextRender.add(()=>this._onSourceUploadedCallback&&this._onSourceUploadedCallback()),this._uploaded=!0)}_getSizes(){if("fbo"===this.sourceType)return{parentWidth:this._parent._boundingRect.document.width,parentHeight:this._parent._boundingRect.document.height,sourceWidth:this._parent._boundingRect.document.width,sourceHeight:this._parent._boundingRect.document.height,xOffset:0,yOffset:0};const e=this._parent.scale?E.set(this._parent.scale.x,this._parent.scale.y):E.set(1,1),t=this._parent._boundingRect.document.width*e.x,s=this._parent._boundingRect.document.height*e.y,i=this._size.width,r=this._size.height,a=i/r,n=t/s;let o=0,h=0;return n>a?h=Math.min(0,s-t*(1/a)):n=this.source.HAVE_CURRENT_DATA&&!this.source.paused&&(this._willUpdate=!0),(this._forceUpdate||this._willUpdate&&this.shouldUpdate)&&(this._state.generateMipmap=!1,this._upload()),"video"===this.sourceType&&(this._willUpdate=!1),this._forceUpdate=!1),this.parameters._shouldUpdate&&(this._updateTexParameters(),this.parameters._shouldUpdate=!1)}onSourceLoaded(e){return e&&(this._onSourceLoadedCallback=e),this}onSourceUploaded(e){return e&&(this._onSourceUploadedCallback=e),this}_dispose(e=!1){var t;"video"===this.sourceType||"image"===this.sourceType&&!this.renderer.state.isActive?(this._loader&&this._loader._removeSource(this),this.source=null):"canvas"===this.sourceType&&this.source&&(this.source.width=null==(t=this.source)?void 0:t.width,this.source=null),this._parent=null;this.gl&&!this._copiedFrom&&(e||"image"!==this.sourceType||!this.renderer.state.isActive)&&(this._canDraw=!1,this.renderer.cache.removeTexture(this),this.gl.activeTexture(this.gl.TEXTURE0+this.index),this.gl.bindTexture(this.gl.TEXTURE_2D,null),this.gl.deleteTexture(this._sampler.texture))}}class F{constructor(e,t="anonymous"){if(this.type="TextureLoader",(e=e&&e.renderer||e)&&"Renderer"===e.type){if(!e.gl)return void a(this.type+": Renderer WebGL context is undefined",e)}else a(this.type+": Renderer not passed as first argument",e);this.renderer=e,this.gl=this.renderer.gl,this.crossOrigin=t,this.elements=[]}_addElement(e,t,s,i){const r={source:e,texture:t,load:this._sourceLoaded.bind(this,e,t,s),error:this._sourceLoadError.bind(this,e,i)};return this.elements.push(r),r}_sourceLoadError(e,t,s){t&&t(e,s)}_sourceLoaded(e,t,s){t._sourceLoaded||(t._onSourceLoaded(e),this._parent&&(this._increment&&this._increment(),this.renderer.nextRender.add(()=>this._parent._onLoadingCallback&&this._parent._onLoadingCallback(t))),s&&s(t))}_getSourceType(e){let t;return"string"==typeof e?null!==e.match(/\.(jpeg|jpg|jfif|pjpeg|pjp|gif|bmp|png|webp|svg|avif|apng)$/)?t="image":null!==e.match(/\.(webm|mp4|mpg|mpeg|avi|ogg|ogm|ogv|mov|av1)$/)&&(t="video"):"IMG"===e.tagName.toUpperCase()?t="image":"VIDEO"===e.tagName.toUpperCase()?t="video":"CANVAS"===e.tagName.toUpperCase()&&(t="canvas"),t}_createImage(e){if("string"!=typeof e&&e.hasAttribute("crossOrigin"))return e;{const t=new Image;return t.crossOrigin=this.crossOrigin,"string"==typeof e?t.src=e:(t.src=e.src,e.hasAttribute("data-sampler")&&t.setAttribute("data-sampler",e.getAttribute("data-sampler"))),t}}_createVideo(e){if("string"==typeof e||null===e.getAttribute("crossOrigin")){const t=document.createElement("video");return t.crossOrigin=this.crossOrigin,"string"==typeof e?t.src=e:(t.src=e.src,e.hasAttribute("data-sampler")&&t.setAttribute("data-sampler",e.getAttribute("data-sampler"))),t}return e}loadSource(e,t,s,i){switch(this._getSourceType(e)){case"image":this.loadImage(e,t,s,i);break;case"video":this.loadVideo(e,t,s,i);break;case"canvas":this.loadCanvas(e,t,s);break;default:this._sourceLoadError(e,i,"this source could not be converted into a texture: "+e)}}loadSources(e,t,s,i){for(let r=0;r{n.addEventListener("load",h.load,!1),n.addEventListener("error",h.error,!1)}):(n.addEventListener("load",h.load,!1),n.addEventListener("error",h.error,!1)),this._parent&&this._addToParent(o,n,"image")}loadImages(e,t,s,i){for(let r=0;r=r.HAVE_FUTURE_DATA&&s&&this._sourceLoaded(r,n,s),r.load(),this._addToParent&&this._addToParent(n,r,"video"),"requestVideoFrameCallback"in HTMLVideoElement.prototype&&(o.videoFrameCallback=n._videoFrameCallback.bind(n),n._videoFrameCallbackID=r.requestVideoFrameCallback(o.videoFrameCallback))}loadVideos(e,t,s,i){for(let r=0;rt.texture.uuid===e.uuid);t&&("image"===e.sourceType?t.source.removeEventListener("load",t.load,!1):"video"===e.sourceType&&(t.videoFrameCallback&&e._videoFrameCallbackID&&t.source.cancelVideoFrameCallback(e._videoFrameCallbackID),t.source.removeEventListener("canplaythrough",t.load,!1),t.source.pause(),t.source.removeAttribute("src"),t.source.load()),t.source.removeEventListener("error",t.error,!1))}}class D extends F{constructor(e,t,{sourcesLoaded:s=0,sourcesToLoad:i=0,complete:a=!1,onComplete:n=()=>{}}={}){super(e,t.crossOrigin),this.type="PlaneTextureLoader",this._parent=t,"Plane"!==this._parent.type&&"PingPongPlane"!==this._parent.type&&"ShaderPass"!==this._parent.type&&(r(this.type+": Wrong parent type assigned to this loader"),this._parent=null),this.sourcesLoaded=s,this.sourcesToLoad=i,this.complete=a,this.onComplete=n}_setLoaderSize(e){this.sourcesToLoad=e,0===this.sourcesToLoad&&(this.complete=!0,this.renderer.nextRender.add(()=>this.onComplete&&this.onComplete()))}_increment(){this.sourcesLoaded++,this.sourcesLoaded>=this.sourcesToLoad&&!this.complete&&(this.complete=!0,this.renderer.nextRender.add(()=>this.onComplete&&this.onComplete()))}_addSourceToParent(e,t){if("image"===t){const t=this._parent.images;!t.find(t=>t.src===e.src)&&t.push(e)}else if("video"===t){const t=this._parent.videos;!t.find(t=>t.src===e.src)&&t.push(e)}else if("canvas"===t){const t=this._parent.canvases;!t.find(t=>t.isSameNode(e))&&t.push(e)}}_addToParent(e,t,s){this._addSourceToParent(t,s),this._parent&&e.addParent(this._parent)}}class I{constructor(e,t="Mesh",{vertexShaderID:s,fragmentShaderID:i,vertexShader:r,fragmentShader:n,uniforms:o={},widthSegments:h=1,heightSegments:l=1,renderOrder:d=0,depthTest:u=!0,cullFace:c="back",texturesOptions:p={},crossOrigin:m="anonymous"}={}){if(this.type=t,(e=e&&e.renderer||e)&&"Renderer"===e.type||(a(this.type+": Curtains not passed as first argument or Curtains Renderer is missing",e),setTimeout(()=>{this._onErrorCallback&&this._onErrorCallback()},0)),this.renderer=e,this.gl=this.renderer.gl,!this.gl)return this.renderer.production||a(this.type+": Unable to create a "+this.type+" because the Renderer WebGL context is not defined"),void setTimeout(()=>{this._onErrorCallback&&this._onErrorCallback()},0);this._canDraw=!1,this.renderOrder=d,this._depthTest=u,this.cullFace=c,"back"!==this.cullFace&&"front"!==this.cullFace&&"none"!==this.cullFace&&(this.cullFace="back"),this.textures=[],this._texturesOptions=Object.assign({premultiplyAlpha:!1,anisotropy:1,floatingPoint:"none",wrapS:this.gl.CLAMP_TO_EDGE,wrapT:this.gl.CLAMP_TO_EDGE,minFilter:this.gl.LINEAR,magFilter:this.gl.LINEAR},p),this.crossOrigin=m,!r&&s&&document.getElementById(s)&&(r=document.getElementById(s).innerHTML),!n&&i&&document.getElementById(i)&&(n=document.getElementById(i).innerHTML),this._initMesh(),h=parseInt(h),l=parseInt(l),this._geometry=new T(this.renderer,{width:h,height:l}),this._program=new w(this.renderer,{parent:this,vertexShader:r,fragmentShader:n}),this._program.compiled?(this._program.createUniforms(o),this.uniforms=this._program.uniformsManager.uniforms,this._geometry.setProgram(this._program),this.renderer.onSceneChange()):this.renderer.nextRender.add(()=>this._onErrorCallback&&this._onErrorCallback())}_initMesh(){this.uuid=n(),this.loader=new D(this.renderer,this,{sourcesLoaded:0,initSourcesToLoad:0,complete:!1,onComplete:()=>{this._onReadyCallback&&this._onReadyCallback(),this.renderer.needRender()}}),this.images=[],this.videos=[],this.canvases=[],this.userData={},this._canDraw=!0}_restoreContext(){this._canDraw=!1,this._matrices&&(this._matrices=null),this._program=new w(this.renderer,{parent:this,vertexShader:this._program.vsCode,fragmentShader:this._program.fsCode}),this._program.compiled&&(this._geometry.restoreContext(this._program),this._program.createUniforms(this.uniforms),this.uniforms=this._program.uniformsManager.uniforms,this._programRestored())}setRenderTarget(e){e&&"RenderTarget"===e.type?("Plane"===this.type&&this.renderer.scene.removePlane(this),this.target=e,"Plane"===this.type&&this.renderer.scene.addPlane(this)):this.renderer.production||r(this.type+": Could not set the render target because the argument passed is not a RenderTarget class object",e)}setRenderOrder(e=0){(e=isNaN(e)?this.renderOrder:parseInt(e))!==this.renderOrder&&(this.renderOrder=e,this.renderer.scene.setPlaneRenderOrder(this))}createTexture(e={}){const t=new A(this.renderer,Object.assign(e,this._texturesOptions));return t.addParent(this),t}addTexture(e){e&&"Texture"===e.type?e.addParent(this):this.renderer.production||r(this.type+": cannot add ",e," to this "+this.type+" because it is not a valid texture")}loadSources(e,t={},s,i){for(let r=0;r{s&&s(e)},(e,t)=>{this.renderer.production||r(this.type+": this HTML tag could not be converted into a texture:",e.tagName),i&&i(e,t)})}loadImage(e,t={},s,i){this.loader.loadImage(e,Object.assign(t,this._texturesOptions),e=>{s&&s(e)},(e,t)=>{this.renderer.production||r(this.type+": There has been an error:\n",t,"\nwhile loading this image:\n",e),i&&i(e,t)})}loadVideo(e,t={},s,i){this.loader.loadVideo(e,Object.assign(t,this._texturesOptions),e=>{s&&s(e)},(e,t)=>{this.renderer.production||r(this.type+": There has been an error:\n",t,"\nwhile loading this video:\n",e),i&&i(e,t)})}loadCanvas(e,t={},s){this.loader.loadCanvas(e,Object.assign(t,this._texturesOptions),e=>{s&&s(e)})}loadImages(e,t={},s,i){for(let r=0;r{this.renderer.production||r(this.type+": Could not play the video : ",e)})}}}_draw(){this.renderer.setDepthTest(this._depthTest),this.renderer.setFaceCulling(this.cullFace),this._program.updateUniforms(),this._geometry.bindBuffers(),this.renderer.state.forceBufferUpdate=!1;for(let e=0;ethis._onAfterResizeCallback&&this._onAfterResizeCallback())}mouseToPlaneCoords(e){const t=this.scale?this.scale:z.set(1,1),s=O.set((this._boundingRect.document.width-this._boundingRect.document.width*t.x)/2,(this._boundingRect.document.height-this._boundingRect.document.height*t.y)/2),i=this._boundingRect.document.width*t.x/this.renderer.pixelRatio,r=this._boundingRect.document.height*t.y/this.renderer.pixelRatio,a=(this._boundingRect.document.top+s.y)/this.renderer.pixelRatio,n=(this._boundingRect.document.left+s.x)/this.renderer.pixelRatio;return O.set((e.x-n)/i*2-1,1-(e.y-a)/r*2)}onAfterResize(e){return e&&(this._onAfterResizeCallback=e),this}}class U{constructor({fov:e=50,near:t=.1,far:s=150,width:i,height:r,pixelRatio:a=1}={}){this.position=new M,this.projectionMatrix=new R,this.worldMatrix=new R,this.viewMatrix=new R,this._shouldUpdate=!1,this.setSize(),this.setPerspective(e,t,s,i,r,a)}setFov(e){e=isNaN(e)?this.fov:parseFloat(e),(e=Math.max(1,Math.min(e,179)))!==this.fov&&(this.fov=e,this.setPosition(),this._shouldUpdate=!0),this.setCSSPerspective()}setNear(e){e=isNaN(e)?this.near:parseFloat(e),(e=Math.max(e,.01))!==this.near&&(this.near=e,this._shouldUpdate=!0)}setFar(e){e=isNaN(e)?this.far:parseFloat(e),(e=Math.max(e,50))!==this.far&&(this.far=e,this._shouldUpdate=!0)}setPixelRatio(e){e!==this.pixelRatio&&(this._shouldUpdate=!0),this.pixelRatio=e}setSize(e,t){e===this.width&&t===this.height||(this._shouldUpdate=!0),this.width=e,this.height=t}setPerspective(e,t,s,i,r,a){this.setPixelRatio(a),this.setSize(i,r),this.setFov(e),this.setNear(t),this.setFar(s),this._shouldUpdate&&this.updateProjectionMatrix()}setPosition(){this.position.set(0,0,1),this.worldMatrix.setFromArray([1,0,0,0,0,1,0,0,0,0,1,0,this.position.x,this.position.y,this.position.z,1]),this.viewMatrix=this.viewMatrix.copy(this.worldMatrix).getInverse()}setCSSPerspective(){this.CSSPerspective=Math.pow(Math.pow(this.width/(2*this.pixelRatio),2)+Math.pow(this.height/(2*this.pixelRatio),2),.5)/Math.tan(.5*this.fov*Math.PI/180)}getScreenRatiosFromFov(e=0){const t=this.position.z;ethis._applyRotation()),this.quaternion=new V,this.relativeTranslation=new M,this.relativeTranslation.onChange(()=>this._setTranslation()),this._translation=new M,this.scale=new M(1),this.scale.onChange(()=>{this.scale.z=1,this._applyScale()}),this.transformOrigin=new M(.5,.5,0),this.transformOrigin.onChange(()=>{this._setWorldTransformOrigin(),this._updateMVMatrix=!0})}resetPlane(e){this._initTransformValues(),this._setWorldTransformOrigin(),null!==e&&e?(this.htmlElement=e,this.resize()):e||this.renderer.production||r(this.type+": You are trying to reset a plane with a HTML element that does not exist. The old HTML element will be kept instead.")}removeRenderTarget(){this.target&&(this.renderer.scene.removePlane(this),this.target=null,this.renderer.scene.addPlane(this))}_initPositions(){this._initMatrices(),this._setWorldSizes(),this._applyWorldPositions()}_initMatrices(){const e=new R;this._matrices={world:{matrix:e},modelView:{name:"uMVMatrix",matrix:e,location:this.gl.getUniformLocation(this._program.program,"uMVMatrix")},projection:{name:"uPMatrix",matrix:e,location:this.gl.getUniformLocation(this._program.program,"uPMatrix")},modelViewProjection:{matrix:e}}}_setPerspectiveMatrix(){this.camera._shouldUpdate&&(this.renderer.useProgram(this._program),this.gl.uniformMatrix4fv(this._matrices.projection.location,!1,this._matrices.projection.matrix.elements)),this.camera.cancelUpdate()}setPerspective(e,t,s){this.camera.setPerspective(e,t,s,this.renderer._boundingRect.width,this.renderer._boundingRect.height,this.renderer.pixelRatio),this.renderer.state.isContextLost&&this.camera.forceUpdate(),this._matrices.projection.matrix=this.camera.projectionMatrix,this.camera._shouldUpdate&&(this._setWorldSizes(),this._applyWorldPositions(),this._translation.z=this.relativeTranslation.z/this.camera.CSSPerspective),this._updateMVMatrix=this.camera._shouldUpdate}_setMVMatrix(){this._updateMVMatrix&&(this._matrices.world.matrix=this._matrices.world.matrix.composeFromOrigin(this._translation,this.quaternion,this.scale,this._boundingRect.world.transformOrigin),this._matrices.world.matrix.scale({x:this._boundingRect.world.width,y:this._boundingRect.world.height,z:1}),this._matrices.modelView.matrix.copy(this._matrices.world.matrix),this._matrices.modelView.matrix.elements[14]-=this.camera.position.z,this._matrices.modelViewProjection.matrix=this._matrices.projection.matrix.multiply(this._matrices.modelView.matrix),this.alwaysDraw||this._shouldDrawCheck(),this.renderer.useProgram(this._program),this.gl.uniformMatrix4fv(this._matrices.modelView.location,!1,this._matrices.modelView.matrix.elements)),this._updateMVMatrix=!1}_setWorldTransformOrigin(){this._boundingRect.world.transformOrigin=new M((2*this.transformOrigin.x-1)*this._boundingRect.world.width,-(2*this.transformOrigin.y-1)*this._boundingRect.world.height,this.transformOrigin.z)}_documentToWorldSpace(e){return N.set(e.x*this.renderer.pixelRatio/this.renderer._boundingRect.width*this._boundingRect.world.ratios.width,-e.y*this.renderer.pixelRatio/this.renderer._boundingRect.height*this._boundingRect.world.ratios.height,e.z)}_setWorldSizes(){const e=this.camera.getScreenRatiosFromFov();this._boundingRect.world={width:this._boundingRect.document.width/this.renderer._boundingRect.width*e.width/2,height:this._boundingRect.document.height/this.renderer._boundingRect.height*e.height/2,ratios:e},this._setWorldTransformOrigin()}_setWorldPosition(){const e=this._boundingRect.document.width/2+this._boundingRect.document.left,t=this._boundingRect.document.height/2+this._boundingRect.document.top,s=this.renderer._boundingRect.width/2+this.renderer._boundingRect.left,i=this.renderer._boundingRect.height/2+this.renderer._boundingRect.top;this._boundingRect.world.top=(i-t)/this.renderer._boundingRect.height*this._boundingRect.world.ratios.height,this._boundingRect.world.left=(e-s)/this.renderer._boundingRect.width*this._boundingRect.world.ratios.width}setScale(e){e.type&&"Vec2"===e.type?(e.sanitizeNaNValuesWith(this.scale).max(B.set(.001,.001)),e.x===this.scale.x&&e.y===this.scale.y||(this.scale.set(e.x,e.y,1),this._applyScale())):this.renderer.production||r(this.type+": Cannot set scale because the parameter passed is not of Vec2 type:",e)}_applyScale(){for(let e=0;e-1;)i.add(s);return i}_getNearPlaneIntersections(e,t,s){const i=this._matrices.modelViewProjection.matrix;if(1===s.length)0===s[0]?(t[0]=this._getIntersection(t[1],Y.set(.95,1,0).applyMat4(i)),t.push(this._getIntersection(t[3],q.set(-1,-.95,0).applyMat4(i)))):1===s[0]?(t[1]=this._getIntersection(t[0],Y.set(-.95,1,0).applyMat4(i)),t.push(this._getIntersection(t[2],q.set(1,-.95,0).applyMat4(i)))):2===s[0]?(t[2]=this._getIntersection(t[3],Y.set(-.95,-1,0).applyMat4(i)),t.push(this._getIntersection(t[1],q.set(1,.95,0).applyMat4(i)))):3===s[0]&&(t[3]=this._getIntersection(t[2],Y.set(.95,-1,0).applyMat4(i)),t.push(this._getIntersection(t[0],q.set(-1,.95,0).applyMat4(i))));else if(2===s.length)0===s[0]&&1===s[1]?(t[0]=this._getIntersection(t[3],Y.set(-1,-.95,0).applyMat4(i)),t[1]=this._getIntersection(t[2],q.set(1,-.95,0).applyMat4(i))):1===s[0]&&2===s[1]?(t[1]=this._getIntersection(t[0],Y.set(-.95,1,0).applyMat4(i)),t[2]=this._getIntersection(t[3],q.set(-.95,-1,0).applyMat4(i))):2===s[0]&&3===s[1]?(t[2]=this._getIntersection(t[1],Y.set(1,.95,0).applyMat4(i)),t[3]=this._getIntersection(t[0],q.set(-1,.95,0).applyMat4(i))):0===s[0]&&3===s[1]&&(t[0]=this._getIntersection(t[1],Y.set(.95,1,0).applyMat4(i)),t[3]=this._getIntersection(t[2],q.set(.95,-1,0).applyMat4(i)));else if(3===s.length){let r=0;for(let t=0;t1&&s.push(o)}s.length&&(t=this._getNearPlaneIntersections(e,t,s));let i=1/0,r=-1/0,a=1/0,n=-1/0;for(let o=0;or&&(r=e.x),e.yn&&(n=e.y)}return{top:n,right:r,bottom:a,left:i}}_computeWebGLBoundingRect(){const e=this._getWorldCoords();let t={top:1-(e.top+1)/2,right:(e.right+1)/2,bottom:1-(e.bottom+1)/2,left:(e.left+1)/2};t.width=t.right-t.left,t.height=t.bottom-t.top,this._boundingRect.worldToDocument={width:t.width*this.renderer._boundingRect.width,height:t.height*this.renderer._boundingRect.height,top:t.top*this.renderer._boundingRect.height+this.renderer._boundingRect.top,left:t.left*this.renderer._boundingRect.width+this.renderer._boundingRect.left,right:t.left*this.renderer._boundingRect.width+this.renderer._boundingRect.left+t.width*this.renderer._boundingRect.width,bottom:t.top*this.renderer._boundingRect.height+this.renderer._boundingRect.top+t.height*this.renderer._boundingRect.height}}getWebGLBoundingRect(){return this._matrices.modelViewProjection?(this._boundingRect.worldToDocument&&!this.alwaysDraw||this._computeWebGLBoundingRect(),this._boundingRect.worldToDocument):this._boundingRect.document}_getWebGLDrawRect(){return this._computeWebGLBoundingRect(),{top:this._boundingRect.worldToDocument.top-this.drawCheckMargins.top,right:this._boundingRect.worldToDocument.right+this.drawCheckMargins.right,bottom:this._boundingRect.worldToDocument.bottom+this.drawCheckMargins.bottom,left:this._boundingRect.worldToDocument.left-this.drawCheckMargins.left}}_shouldDrawCheck(){const e=this._getWebGLDrawRect();Math.round(e.right)<=this.renderer._boundingRect.left||Math.round(e.left)>=this.renderer._boundingRect.left+this.renderer._boundingRect.width||Math.round(e.bottom)<=this.renderer._boundingRect.top||Math.round(e.top)>=this.renderer._boundingRect.top+this.renderer._boundingRect.height?this._shouldDraw&&(this._shouldDraw=!1,this.renderer.nextRender.add(()=>this._onLeaveViewCallback&&this._onLeaveViewCallback())):(this._shouldDraw||this.renderer.nextRender.add(()=>this._onReEnterViewCallback&&this._onReEnterViewCallback()),this._shouldDraw=!0)}isDrawn(){return this._canDraw&&this.visible&&(this._shouldDraw||this.alwaysDraw)}enableDepthTest(e){this._depthTest=e}_initSources(){let e=0;if(this.autoloadSources){const t=this.htmlElement.getElementsByTagName("img"),s=this.htmlElement.getElementsByTagName("video"),i=this.htmlElement.getElementsByTagName("canvas");t.length&&this.loadImages(t),s.length&&this.loadVideos(s),i.length&&this.loadCanvases(i),e=t.length+s.length+i.length}this.loader._setLoaderSize(e),this._canDraw=!0}_startDrawing(){this._canDraw&&(this._onRenderCallback&&this._onRenderCallback(),this.target?this.renderer.bindFrameBuffer(this.target):null===this.renderer.state.scenePassIndex&&this.renderer.bindFrameBuffer(null),this._setPerspectiveMatrix(),this._setMVMatrix(),(this.alwaysDraw||this._shouldDraw)&&this.visible&&this._draw())}mouseToPlaneCoords(e){if($.setAxisOrder(this.quaternion.axisOrder),$.equals(this.quaternion)&&Z.equals(this.transformOrigin))return super.mouseToPlaneCoords(e);{const t={x:e.x/(this.renderer._boundingRect.width/this.renderer.pixelRatio)*2-1,y:2*(1-e.y/(this.renderer._boundingRect.height/this.renderer.pixelRatio))-1},s=this.camera.position.clone(),i=Q.set(t.x,t.y,-.5);i.unproject(this.camera),i.sub(s).normalize();const r=J.set(0,0,-1);r.applyQuat(this.quaternion).normalize();const a=ee.set(0,0,0),n=r.dot(i);if(Math.abs(n)>=1e-4){const e=this._matrices.world.matrix.getInverse().multiply(this.camera.viewMatrix),t=this._boundingRect.world.transformOrigin.clone().add(this._translation),o=K.set(this._translation.x-t.x,this._translation.y-t.y,this._translation.z-t.z);o.applyQuat(this.quaternion),t.add(o);const h=r.dot(t.clone().sub(s))/n;a.copy(s.add(i.multiplyScalar(h))),a.applyMat4(e)}else a.set(1/0,1/0,1/0);return te.set(a.x,a.y)}}onReEnterView(e){return e&&(this._onReEnterViewCallback=e),this}onLeaveView(e){return e&&(this._onLeaveViewCallback=e),this}}class ie{constructor(e,{shaderPass:t,depth:s=!1,clear:i=!0,maxWidth:r,maxHeight:o,minWidth:h=1024,minHeight:l=1024,texturesOptions:d={}}={}){if(this.type="RenderTarget",(e=e&&e.renderer||e)&&"Renderer"===e.type){if(!e.gl)return void(e.production||a(this.type+": Unable to create a "+this.type+" because the Renderer WebGL context is not defined"))}else a(this.type+": Renderer not passed as first argument",e);this.renderer=e,this.gl=this.renderer.gl,this.index=this.renderer.renderTargets.length,this._shaderPass=t,this._depth=s,this._shouldClear=i,this._maxSize={width:r?Math.min(this.renderer.state.maxTextureSize/4,r):this.renderer.state.maxTextureSize/4,height:o?Math.min(this.renderer.state.maxTextureSize/4,o):this.renderer.state.maxTextureSize/4},this._minSize={width:h*this.renderer.pixelRatio,height:l*this.renderer.pixelRatio},d=Object.assign({sampler:"uRenderTexture",isFBOTexture:!0,premultiplyAlpha:!1,anisotropy:1,generateMipmap:!1,floatingPoint:"none",wrapS:this.gl.CLAMP_TO_EDGE,wrapT:this.gl.CLAMP_TO_EDGE,minFilter:this.gl.LINEAR,magFilter:this.gl.LINEAR},d),this._texturesOptions=d,this.userData={},this.uuid=n(),this.renderer.renderTargets.push(this),this.renderer.onSceneChange(),this._initRenderTarget()}_initRenderTarget(){this._setSize(),this.textures=[],this._createFrameBuffer()}_restoreContext(){this._setSize(),this._createFrameBuffer()}_setSize(){this._shaderPass&&this._shaderPass._isScenePass?this._size={width:this.renderer._boundingRect.width,height:this.renderer._boundingRect.height}:this._size={width:Math.min(this._maxSize.width,Math.max(this._minSize.width,this.renderer._boundingRect.width)),height:Math.min(this._maxSize.height,Math.max(this._minSize.height,this.renderer._boundingRect.height))}}resize(){this._shaderPass&&(this._setSize(),this.textures[0].resize(),this.renderer.bindFrameBuffer(this,!0),this._depth&&this._bindDepthBuffer(),this.renderer.bindFrameBuffer(null))}_bindDepthBuffer(){this._depthBuffer&&(this.gl.bindRenderbuffer(this.gl.RENDERBUFFER,this._depthBuffer),this.gl.renderbufferStorage(this.gl.RENDERBUFFER,this.gl.DEPTH_COMPONENT16,this._size.width,this._size.height),this.gl.framebufferRenderbuffer(this.gl.FRAMEBUFFER,this.gl.DEPTH_ATTACHMENT,this.gl.RENDERBUFFER,this._depthBuffer))}_createFrameBuffer(){if(this._frameBuffer=this.gl.createFramebuffer(),this.renderer.bindFrameBuffer(this,!0),this.textures.length)this.textures[0]._parent=this,this.textures[0]._restoreContext();else{new A(this.renderer,this._texturesOptions).addParent(this)}this.gl.framebufferTexture2D(this.gl.FRAMEBUFFER,this.gl.COLOR_ATTACHMENT0,this.gl.TEXTURE_2D,this.textures[0]._sampler.texture,0),this._depth&&(this._depthBuffer=this.gl.createRenderbuffer(),this._bindDepthBuffer()),this.renderer.bindFrameBuffer(null)}getTexture(){return this.textures[0]}remove(){this._shaderPass?this.renderer.production||r(this.type+": You're trying to remove a RenderTarget attached to a ShaderPass. You should remove that ShaderPass instead:",this._shaderPass):(this._dispose(),this.renderer.removeRenderTarget(this))}_dispose(){this._frameBuffer&&(this.gl.deleteFramebuffer(this._frameBuffer),this._frameBuffer=null),this._depthBuffer&&(this.gl.deleteRenderbuffer(this._depthBuffer),this._depthBuffer=null),this.textures[0]._dispose(),this.textures=[]}}class re extends se{constructor(e,t,{sampler:s="uPingPongTexture",widthSegments:i,heightSegments:r,renderOrder:a,depthTest:n,cullFace:o,uniforms:h,vertexShaderID:l,fragmentShaderID:d,vertexShader:u,fragmentShader:c,texturesOptions:p,crossOrigin:m,alwaysDraw:g,visible:f,transparent:_,drawCheckMargins:x,autoloadSources:v,watchScroll:y,fov:b}={}){if(super(e,t,{widthSegments:i,heightSegments:r,renderOrder:a,depthTest:false,cullFace:o,uniforms:h,vertexShaderID:l,fragmentShaderID:d,vertexShader:u,fragmentShader:c,texturesOptions:p,crossOrigin:m,alwaysDraw:g,visible:f,transparent:_,drawCheckMargins:x,autoloadSources:false,watchScroll:y,fov:b}),!this.gl)return;this.renderer.scene.removePlane(this),this.type="PingPongPlane",this.renderer.scene.addPlane(this),this.readPass=new ie(e,{depth:!1,clear:!1,texturesOptions:p}),this.writePass=new ie(e,{depth:!1,clear:!1,texturesOptions:p}),this.createTexture({sampler:s});let P=0;this.readPass.getTexture().onSourceUploaded(()=>{P++,this._checkIfReady(P)}),this.writePass.getTexture().onSourceUploaded(()=>{P++,this._checkIfReady(P)}),this.setRenderTarget(this.readPass),this._onRenderCallback=()=>{this.readPass&&this.writePass&&this.textures[0]&&this.textures[0]._uploaded&&this.setRenderTarget(this.writePass),this._onPingPongRenderCallback&&this._onPingPongRenderCallback()},this._onAfterRenderCallback=()=>{this.readPass&&this.writePass&&this.textures[0]&&this.textures[0]._uploaded&&this._swapPasses(),this._onPingPongAfterRenderCallback&&this._onPingPongAfterRenderCallback()}}_checkIfReady(e){2===e&&this.renderer.nextRender.add(()=>{this.textures[0].copy(this.target.getTexture())})}_swapPasses(){const e=this.readPass;this.readPass=this.writePass,this.writePass=e,this.textures[0].copy(this.readPass.getTexture())}getTexture(){return this.textures[0]}onRender(e){return e&&(this._onPingPongRenderCallback=e),this}onAfterRender(e){return e&&(this._onPingPongAfterRenderCallback=e),this}remove(){this.target=null,this.renderer.bindFrameBuffer(null),this.writePass&&(this.writePass.remove(),this.writePass=null),this.readPass&&(this.readPass.remove(),this.readPass=null),super.remove()}}let ae,ne,oe,he,le=!1,de=window.innerHeight||document.documentElement.clientHeight,ue=window.innerWidth||document.documentElement.clientWidth,ce=window.scrollY||window.pageYOffset,pe=0,me=0,ge=0;const fe=.001;function _e(e){return window.atob(e)}function xe(){return"id-"+Math.random().toString(36).substring(2,15)+Math.random().toString(36).substring(2,15)}function ve(e,t,s,i,r){if(s.length>1){let a,n=i?2*+i*Math.PI:0,o=t.width/2,h=t.height/2,l=t.width/2,d=t.height/2;if("radial"===r){const t=Math.max(l,d);a=e.createRadialGradient(o,h,t,o,h,0)}const u=Math.cos(n)*l,c=Math.sin(n)*d;if("linear"===r&&(a=e.createLinearGradient(o-u,h-c,o+u,h+c)),"conic"===r){a=e.createConicGradient(-Math.PI+n,o,h);const t=[...s,...s.slice().reverse()];t.forEach((e,s)=>{a.addColorStop(s*(1/(t.length-1)),e)})}else s.forEach((e,t)=>{a.addColorStop(t*(1/(s.length-1)),e)});return a}return s[0]}function ye(e){const t={linear:e=>e,easeInQuad:e=>e*e,easeOutQuad:e=>1-(1-e)*(1-e),easeInOutQuad:e=>e<.5?2*e*e:1-Math.pow(-2*e+2,2)/2,easeInCubic:e=>e*e*e,easeOutCubic:e=>1-Math.pow(1-e,3),easeInOutCubic:e=>e<.5?4*e*e*e:1-Math.pow(-2*e+2,3)/2,easeInQuart:e=>e**4,easeOutQuart:e=>1-Math.pow(1-e,4),easeInOutQuart:e=>e<.5?8*e**4:1-Math.pow(-2*e+2,4)/2,easeInQuint:e=>e**5,easeOutQuint:e=>1-Math.pow(1-e,5),easeInOutQuint:e=>e<.5?16*e**5:1-Math.pow(-2*e+2,5)/2,easeOutElastic:e=>{const t=2*Math.PI/3;return 0===e?0:1===e?1:Math.pow(2,-10*e)*Math.sin((10*e-.75)*t)+1},easeInElastic:e=>{const t=2*Math.PI/3;return 0===e?0:1===e?1:-Math.pow(2,10*e-10)*Math.sin((10*e-10.75)*t)},easeInOutElastic:e=>{const t=2*Math.PI/4.5;return 0===e?0:1===e?1:e<.5?-Math.pow(2,20*e-10)*Math.sin((20*e-11.125)*t)/2:Math.pow(2,-20*e+10)*Math.sin((20*e-11.125)*t)/2+1},easeInSine:e=>1-Math.cos(e*Math.PI/2),easeOutSine:e=>Math.sin(e*Math.PI/2),easeInOutSine:e=>-(Math.cos(Math.PI*e)-1)/2,easeInCirc:e=>1-Math.sqrt(1-e**2),easeOutCirc:e=>Math.sqrt(1-Math.pow(e-1,2)),easeInOutCirc:e=>e<.5?(1-Math.sqrt(1-(2*e)**2))/2:(Math.sqrt(1-Math.pow(-2*e+2,2))+1)/2,easeInExpo:e=>0===e?0:Math.pow(2,10*e-10),easeOutExpo:e=>1===e?1:1-Math.pow(2,-10*e),easeInOutExpo:e=>0===e?0:1===e?1:e<.5?Math.pow(2,20*e-10)/2:(2-Math.pow(2,-20*e+10))/2,easeInBack:e=>{const t=1.70158;return(t+1)*e*e*e-t*e*e},easeOutBack:e=>{const t=1.70158;return 1+(t+1)*Math.pow(e-1,3)+t*Math.pow(e-1,2)},easeInOutBack:e=>{const t=2.5949095;return e<.5?Math.pow(2*e,2)*(7.189819*e-t)/2:(Math.pow(2*e-2,2)*((t+1)*(2*e-2)+t)+2)/2}};if(t[e])return t[e];if("string"==typeof e&&(e.includes("=>")||e.includes("function")||e.includes("x"))){const t=new Function("return "+e)();if(t)return t}return t.linear}function be(e){return e&&"string"==typeof e&&(e=JSON.parse(e)),Object.values(e)}function Pe(e,t,s){for(let i=0;ie.hasOwnProperty(t)&&0!==e[t]),s=e.states&&[...e.states.appear,...e.states.scroll,...e.states.hover].length>0,i=("effect"===e.layerType||e.isModel)&&(e.animating||e.usesPingPong),r="video"===e.type,a=t||s||i||r;return e.local.isDynamicCache=a,a}function Se(e,t){if(e.noTextAsHtml)return;if(!t)return;let s="fixed"===e.widthMode?e.width:e.width*t.offsetWidth,i=e.height,r="fixed"===e.fontSizeMode?e.fontSize:e.fontSize*t.offsetWidth,a="fixed"===e.fontSizeMode?e.lineHeight:e.lineHeight*r,n="fixed"===e.fontSizeMode?e.letterSpacing:e.letterSpacing*r,o="fixed"===e.topMode?e.top:e.top*t.offsetHeight,h="fixed"===e.leftMode?e.left:e.left*t.offsetWidth,l=Le(e.anchorPoint);h-=l.x*s,o-=l.y*i,o+=t.offsetTop,h+=t.offsetLeft;const d=document.querySelector(`[data-us-text="${e.local.id}"]`),u=d||document.createElement("div");u.setAttribute("data-us-text",e.local.id),u.style.cssText=`width:${s}px;top:${o}px;left:${h}px;font-size:${r}px;line-height:${a}px;letter-spacing:${n}px;font-family:${e.fontFamily};font-weight:${e.fontWeight};text-align:${e.textAlign};position:absolute;word-break:break-word;transform:rotateZ(${Math.round(360*e.rotation)}deg);color:transparent;z-index:2;`,u.innerText=e.textContent,d||t.appendChild(u)}function Me(){Qe.filter(e=>!document.body.contains(e.element)).forEach(e=>{e.curtain&&e.curtain.dispose();const t=Qe.indexOf(e);-1!==t&&Qe.splice(t,1)})}function Ee(){cancelAnimationFrame(oe);let e=Qe.filter(e=>!e.destroyed&&e.getDynamicLayers().length>0);const t=s=>{let i=!1;e.forEach(e=>{e.destroyed||(e.isInView&&e.initialized?(e.rendering=!0,s-(e.lastTime||0)>=e.frameDuration&&!e.paused&&(e.renderFrame(),e.lastTime=s),i=!0):e.rendering=!1)}),(!ge||s-ge>64)&&(ce=window.scrollY||window.pageYOffset,me=ce-pe,pe=ce,ge=s,(me>1e3||me<0&&!pe&&!ce)&&Ye()),i?(!function(){let e=performance.now();Qe.forEach(t=>{var s,i,r,a,n,o;if(t.isInView&&(null==(i=null==(s=t.curtain)?void 0:s.planes)?void 0:i.find(e=>e.uniforms.mousePos)))if(we()&&(null==(a=null==(r=t.interactivity)?void 0:r.mouse)?void 0:a.disableMobile)||(null==(o=null==(n=t.interactivity)?void 0:n.mouse)?void 0:o.disabled));else{t.mouse.pos.y=t.mouse.movePos.y,t.mouse.pos.x=t.mouse.movePos.x,t.mouse.lastPos.x=t.mouse.pos.x,t.mouse.lastPos.y=t.mouse.pos.y;let s=t.isFixed?t.bbox.top:t.bbox.top+t.scrollY,i=t.bbox.left;t.mouse.page.x>i&&t.mouse.page.y>s&&t.mouse.page.xthis.transition.duration)return!1;const a=r/this.transition.duration,n=Math.floor(i/t);let o=a;return"reverse"===this.loop&&n%2==1&&(o=1-a),this.progress=this.easeFunction(o),this.lastTick=s,Ce(this.value,e,this.progress)}const r=Math.max(0,Math.min(1,i/this.transition.duration));return this.progress=this.easeFunction(r),0!==this.progress&&(r>=1?(this.complete=!0,this.progress=0,e):(this.lastTick=s,!this.complete&&Ce(this.value,e,this.progress)))}resetState(){this.progress=0,this.complete=!1,this.lastTick=void 0,this.initialized=!1}}class Ie{constructor({prop:e,value:t,range:i,offset:r,momentum:a,uniformData:n,mode:o="scrollIntoView",delta:h=.01,absScrollValue:l=!0,breakpoints:d=[]}){s(this,"id",xe()),this.prop=e,this.progress=0,this.momentum=a,this.range=i,this.offset=r,this.mode=o,this.delta=h,this.absScrollValue=l,this.uniformData=n,this.value=ke(t),this.lastTick=void 0,this.breakpoints=d||[]}updateEffect(e,{top:t,height:s,isFixed:i}){if(void 0===e)return!1;if(i&&(t-=ce),"scrollIntoView"===this.mode){const i=t+ce-de*this.offset,r=i+(de+s)*this.range;let a=(ce-i)/(r-i),n=Math.max(0,Math.min(1,a));return!(void 0!==this.lastTick&&(n=Pe(n,this.lastTick,2*this.momentum),Math.abs(this.lastTick-n)fe;return this.progress=l,!(!t&&!d)&&(!t&&this.transition.forwardsOnly&&(this.progress=0,this.rawProgress=0),this.lastTick=a,this.lastEnterTime=t,!!d&&Ce(e,this.value,this.progress))}resetState(){this.progress=0}}class ze{constructor(e,t,i){var r;s(this,"local",{id:"",projectId:"",lastMousePos:{x:.5,y:.5},createdAt:null}),this.initOptions=i,this.aspectRatio=e.aspectRatio||1,this.layerName=e.layerName||e.id,this.data=e.data||{},this.userDownsample=e.userDownsample||1,this.breakpoints=((r=e.breakpoints||[]).forEach(e=>{var t,s;for(let i in e.props)"Vec2"===(null==(t=e.props[i])?void 0:t.type)?e.props[i]=new S(e.props[i]._x,e.props[i]._y):"Vec3"===(null==(s=e.props[i])?void 0:s.type)?e.props[i]=new M(e.props[i]._x,e.props[i]._y,e.props[i]._z):"object"==typeof e.props[i]&&(e.props[i]=be(e.props[i]))}),r),this.local.sceneId=t,this.local.id=xe(),this.id=e.id,this.compiledFragmentShaders=e.compiledFragmentShaders||[],this.compiledVertexShaders=e.compiledVertexShaders||[],this.states={appear:e.states&&e.states.appear?e.states.appear.map(e=>new De(e)):[],scroll:e.states&&e.states.scroll?e.states.scroll.map(e=>new Ie(e)):[],hover:e.states&&e.states.hover?e.states.hover.map(e=>new Oe(e)):[]}}state(){return Qe.find(e=>e.id===this.local.sceneId)||this.initOptions}getIndex(){return this.state().layers.map(e=>e.local.id).indexOf(this.local.id)}getPixelRatio(){const e=this.state();return e.dpi*e.scale*this.userDownsample}getPlane(){var e,t,s;return null==(s=null==(t=null==(e=this.state())?void 0:e.curtain)?void 0:t.planes)?void 0:s.find(e=>"PingPongPlane"!==e.type&&e.userData.id===this.local.id)}getPlanes(){var e,t,s;return(null==(s=null==(t=null==(e=this.state())?void 0:e.curtain)?void 0:t.planes)?void 0:s.filter(e=>"PingPongPlane"!==e.type&&e.userData.id===this.local.id))||[]}getMaskedItem(){return!!this.mask&&this.state().layers.filter(e=>!e.parentLayer)[this.getIndex()-1]}getChildEffectItems(){if(this.effects&&this.effects.length){const e=this.state();if(!e||!e.layers)return[];const t=e.layers.filter(e=>this.effects.includes(e.parentLayer));return this.effects.map(e=>t.find(t=>t.parentLayer===e)).filter(e=>void 0!==e)}return[]}setBreakpointValues(){const e=ue,t=this.breakpoints.sort((e,t)=>t.min-e.min),s={};if(1===t.length&&"Desktop"===t[0].name)return;if(t.length>=1&&!t.find(e=>"Desktop"===e.name))throw new Error("Malfored breakpoint data, missing Desktop");for(let r=t.length-1;r>=0;r--){const i=t[r];if(null===i.max||e<=i.max)for(let e in i.props)s.hasOwnProperty(e)||(s[e]=i.props[e])}const i=this.breakpoints.find(e=>"Desktop"===e.name);if(i)for(let r in i.props)s.hasOwnProperty(r)||(s[r]=i.props[r]);for(let r in s)if(this.hasOwnProperty(r)){let e=s[r];(null==e?void 0:e.type)?(this[r].x=e._x,this[r].y=e._y,void 0!==e._z&&(this[r].z=e._z)):this[r]=e}this.local.bpProps=s}updateStateEffects(){var e,t,s,i;if(!this.states.appear.some(e=>!e.complete)&&!(null==(e=this.states)?void 0:e.scroll.length)&&!(null==(t=this.states)?void 0:t.hover.length)||this.isModel&&!this.local.modelLoaded)return;this.local.uniformUpdatesPool||(this.local.uniformUpdatesPool={}),this.local.updatedProps?this.local.updatedProps.clear():this.local.updatedProps=new Set,this.local.hasUpdates=!1;const r=this.state();let a=performance.now();this.local.cachedBreakpoint&&this.local.cachedBreakpoint===(null==(s=r.currentBreakpoint)?void 0:s.name)||(this.local.cachedBreakpoint=null==(i=r.currentBreakpoint)?void 0:i.name);const n=e=>!e.breakpoints||0===e.breakpoints.length||e.breakpoints.find(e=>e===this.local.cachedBreakpoint);r.isInView&&(null===this.local.createdAt&&(this.local.createdAt=a),this.states.appear.forEach(e=>{if(!n(e))return;let t=e.startTime||this.local.createdAt;if(!e.initialized){const s=[...this.states.appear.filter(t=>t.prop===e.prop)].sort((e,t)=>(e.transition.delay||0)-(t.transition.delay||0))[0];(null==s?void 0:s.id)===e.id&&(this.local.uniformUpdatesPool[e.prop]=e.value,this.local.hasUpdates=!0,this.local.updatedProps.add(e.prop)),e.initialized=!0,t||(e.startTime=a)}(null==r?void 0:r.pauseTime)&&(t+=Math.abs(null==r?void 0:r.pauseTime));const s=e.updateEffect(this[e.prop],t);!1!==s&&(this.local.uniformUpdatesPool[e.prop]=s,this.local.hasUpdates=!0,this.local.updatedProps.add(e.prop)),this.isElement&&e.complete&&this.local.stateEffectProps&&this.local.stateEffectProps[e.prop]&&delete this.local.stateEffectProps[e.prop]})),this.states.hover.forEach(e=>{if(!n(e))return;const t=e.updateEffect(this[e.prop],r.mouse.enterTime,this);!1!==t&&(this.local.uniformUpdatesPool[e.prop]=t,this.local.hasUpdates=!0,this.local.updatedProps.add(e.prop))}),this.states.scroll.forEach(e=>{var t;if(!n(e))return;const s=r.bbox;if(!s)return;const i=e.updateEffect(this[e.prop],{top:r.isFixed?0:null==(t=r.bbox)?void 0:t.top,height:s.height/2,isFixed:r.isFixed});!1!==i&&(this.local.uniformUpdatesPool[e.prop]=i,this.local.hasUpdates=!0,this.local.updatedProps.add(e.prop))}),this.local.hasUpdates&&(this.getPlanes().forEach(e=>{var t;for(let s of this.local.updatedProps){const i=this.local.uniformUpdatesPool[s];void 0!==i&&((null==(t=e.uniforms[s])?void 0:t.lastValue)!==i&&(e.uniforms[s]&&Ae(i,e.uniforms[s],s),this.updateStateEffectProperty(s,i)))}}),this.isElement&&this.local.stateEffectProps&&Object.keys(this.local.stateEffectProps).length&&this.render())}updateStateEffectProperty(e,t){this.local.stateEffectProps||(this.local.stateEffectProps={}),this.local.stateEffectProps[e]=t}invalidatePerformanceCaches(){this.local.isDynamicCache=void 0,this.local.cachedBreakpoint=void 0,this.local.lastCalculatedMousePos=void 0,this.local.lastCalculatedMouseValues=void 0}dispose(){this.invalidatePerformanceCaches()}}function Le(e){const t={topLeft:{x:0,y:0},topCenter:{x:.5,y:0},topRight:{x:1,y:0},rightCenter:{x:1,y:.5},bottomRight:{x:1,y:1},bottomCenter:{x:.5,y:1},bottomLeft:{x:0,y:1},leftCenter:{x:0,y:.5},center:{x:.5,y:.5}};return t[e]||t.topLeft}let Ue=class extends ze{constructor(e,t){super(e,t),s(this,"isElement",!0),this.anchorPoint=e.anchorPoint||"topLeft",this.opacity=e.opacity??1,this.displace=e.displace||0,this.effects=e.effects||[],this.trackMouse=e.trackMouse||0,this.axisTilt=e.axisTilt||0,this.trackAxes=e.trackAxes||"xy",this.bgDisplace=e.bgDisplace||0,this.dispersion=e.dispersion||0,this.rotation=e.rotation||0,this.mouseMomentum=e.mouseMomentum||0,this.maskAlpha=e.maskAlpha||0,this.maskDepth=e.maskDepth||0,this.maskDepthLayer=e.maskDepthLayer||1,this.maskBackground=e.maskBackground||{},this.mask=e.mask||0,this.blendMode=e.blendMode||"NORMAL",this.width=e.width||0,this.height=e.height||0,this.widthMode=e.widthMode||"fixed",this.heightMode=e.heightMode||"fixed",this.left=e.left||0,this.top=e.top||0,this.leftMode=e.leftMode||"relative",this.topMode=e.topMode||"relative"}unpackage(){return this.effects=be(this.effects),this.maskBackground=new M(this.maskBackground._x,this.maskBackground._y,this.maskBackground._z),this.unpackageType(),this}createLocalCanvas(){const e=this.state(),t=document.createElement("canvas"),s=this.getPixelRatio();t.width=e.canvasWidth*s,t.height=e.canvasHeight*s;const i=t.getContext("2d");i.scale(s,s),this.local.canvas=t,this.local.ctx=i}resize(){var e,t;const s=this.state();if(this.local.canvas){const e=this.getPixelRatio();this.local.canvas.width=s.canvasWidth*e,this.local.canvas.height=s.canvasHeight*e,this.local.ctx.scale(e,e)}(null==(t=null==(e=this.states)?void 0:e.appear)?void 0:t.some(e=>!e.complete))||this.render(),"text"===this.layerType&&Se(this,this.state().element)}dispose(){this.local.canvas&&(this.local.canvas.width=1,this.local.canvas.height=1,this.local.canvas=null),this.local.ctx&&(this.local.ctx=null),super.dispose()}box(){const e=Le(this.anchorPoint),{width:t,height:s}=this.getAbsoluteDimensions(),{left:i,top:r}=this.getAbsolutePosition();return{anchor:{x:i+t*(.5-e.x),y:r+s*(.5-e.y)},center:{x:i+t/2,y:r+s/2},left:i,top:r,width:t,height:s}}getAbsolutePosition(){var e,t,s,i;const r=this.state(),a=r.canvasWidth,n=r.canvasHeight;let o=(null==(t=null==(e=this.local)?void 0:e.stateEffectProps)?void 0:t.left)??this.left,h=(null==(i=null==(s=this.local)?void 0:s.stateEffectProps)?void 0:i.top)??this.top,l="fixed"===this.leftMode?o:o*a,d="fixed"===this.topMode?h:h*n;return l=+l.toFixed(1),d=+d.toFixed(1),{left:l,top:d}}getAbsoluteDimensions(){var e,t,s,i;const r=this.state();let a,n;const o=r.canvasWidth,h=r.canvasHeight;let l=(null==(t=null==(e=this.local)?void 0:e.stateEffectProps)?void 0:t.width)??this.width,d=(null==(i=null==(s=this.local)?void 0:s.stateEffectProps)?void 0:i.height)??this.height;return"auto"!==this.widthMode&&(a="fixed"===this.widthMode?l:l*o,"auto"===this.heightMode&&(n=a/(this.aspectRatio||1),this.height="fixed"===this.widthMode?n:n/h)),"auto"!==this.heightMode&&(n="fixed"===this.heightMode?d:d*h,"auto"===this.widthMode&&(a=n*(this.aspectRatio||1),this.width="fixed"===this.widthMode?a:a/o)),"text"===this.layerType&&(n=this.height),{width:a,height:n}}isHovered(){let{left:e,top:t,width:s,height:i}=this.box();const r=Le(this.anchorPoint);s<0&&(s=Math.abs(s)),i<0&&(t+=i,i=Math.abs(i)),e-=r.x*s,t-=r.y*i;let a=this.state().mouse.movePos;return 2*a.x>=e&&2*a.x<=e+s&&2*a.y>=t&&2*a.y<=t+i}};class Ve extends Ue{constructor(e,t,i){super(e,t),s(this,"layerType","shape"),s(this,"isElement",!0),this.initOptions=i;let r=this.default(e||{});for(let s in r)this[s]=r[s];this.breakpoints.length&&this.setBreakpointValues(),Object.keys(e).length&&this.createLocalCanvas()}default(e){return{borderRadius:e.borderRadius||0,fill:e.fill||["#777777"],fitToCanvas:e.fitToCanvas||!1,gradientAngle:e.gradientAngle||e.gradAngle||0,gradientType:e.gradientType||e.gradType||"linear",numSides:e.numSides||3,type:e.type||"rectangle",stroke:e.stroke||["#000000"],strokeWidth:e.strokeWidth||0}}unpackageType(){return this.fill=be(this.fill),this.stroke=be(this.stroke),this.render(),this}render(){var e,t,s,i;let r=this.local.ctx;const a=this.state();let{left:n,top:o,width:h,height:l}=this.box();const d=Le(this.anchorPoint);let u=(null==(e=this.local.stateEffectProps)?void 0:e.borderRadius)??this.borderRadius,c=(null==(t=this.local.stateEffectProps)?void 0:t.strokeWidth)??this.strokeWidth,p=(null==(s=this.local.stateEffectProps)?void 0:s.gradientAngle)??this.gradientAngle,m=(null==(i=this.local.stateEffectProps)?void 0:i.rotation)??this.rotation,g=n-d.x*h,f=o-d.y*l;if(r.clearRect(0,0,a.canvasWidth,a.canvasHeight),r.beginPath(),this.fitToCanvas)r.rect(0,0,a.canvasWidth,a.canvasHeight),r.fillStyle=ve(r,{width:a.canvasWidth,height:a.canvasHeight},this.fill,p,this.gradientType);else{if(r.save(),r.translate(g+h/2,f+l/2),r.rotate(2*m*Math.PI),r.translate(-h/2,-l/2),"rectangle"===this.type){let e=u*Math.min(Math.abs(h),Math.abs(l))/2;this.drawRoundedRect(r,0,0,h,l,e)}else"circle"===this.type?r.ellipse(h/2,l/2,Math.abs(h)/2,Math.abs(l)/2,0,0,2*Math.PI):"polygon"===this.type&&this.drawPolygon(r,Math.abs(h/2),Math.abs(l/2),this.numSides);r.fillStyle=ve(r,this.box(),this.fill,p,this.gradientType)}r.fill(),c&&(r.strokeStyle=this.stroke[0],r.lineWidth=c,r.stroke()),r.restore()}drawRoundedRect(e,t,s,i,r,a){e.beginPath(),e.moveTo(t+a,s),e.arcTo(t+i,s,t+i,s+r,a),e.arcTo(t+i,s+r,t,s+r,a),e.arcTo(t,s+r,t,s,a),e.arcTo(t,s,t+i,s,a),e.closePath()}drawPolygon(e,t,s,i){e.beginPath();for(let r=0;re.effects&&e.effects.length).find(e=>e.effects.includes(this.parentLayer))}}class We extends Ue{constructor(e,t,i){super(e,t),s(this,"layerType","image"),s(this,"isElement",!0),this.initOptions=i;let r=this.default(e||{});for(let s in r)this[s]=r[s];this.breakpoints.length&&this.setBreakpointValues(),Object.keys(e).length&&(this.createLocalCanvas(),this.loadImage())}default(e){return{fitToCanvas:e.fitToCanvas||!1,src:e.src||""}}unpackage(){return this.effects=be(this.effects),this}loadImage(){const e=new Image;e.crossOrigin="Anonymous",e.addEventListener("load",()=>{const t=this.state();this.local.img=e,this.render=this.renderImage,this.render(),t.renderFrame&&t.renderFrame(),this.local.loaded=!0},!1),e.src=this.src}renderImage(){var e,t;if(!(null==(e=this.local)?void 0:e.ctx))return;let s=this.local.ctx;const i=this.state();s.clearRect(0,0,i.canvasWidth,i.canvasHeight);let{left:r,top:a,width:n,height:o}=this.box(),h=i.canvasWidth,l=i.canvasHeight;if(this.fitToCanvas){let e=this.local.img.width/this.local.img.height;h/l{const t=e.curtain.renderer.gl;this.local.renderTarget&&!this.local.renderTarget._frameBuffer&&this.local.renderTarget._initRenderTarget(),this.local.initialize(t,this),this.local.initialized=!0,this.local.loadModel(this)})}catch(s){}}handleModelLoaded(){if(this.local.modelLoaded=!0,this.local.renderTarget){let e=this.local.renderTarget.getTexture(),t=this.getPlane().textures.find(e=>"uTexture"===e._samplerName);t.copy(e),t.needUpdate()}}renderModel(){var e,t;if(!this.local.rendererLoaded||!this.local.modelLoaded)return;const s=this.state();if(!s||s.destroyed||!s.curtain||!s.curtain.renderer||!s.curtain.renderer.gl)return;const i=s.curtain.renderer.gl;if(0===i.drawingBufferWidth||0===i.drawingBufferHeight)return;if(this.animating){void 0===this.local.time&&(this.local.time=0);let t=(null==(e=this.local.stateEffectProps)?void 0:e.speed)??this.speed??.5;const i=s.fps?60/s.fps:1;this.local.time+=t*i*60}if(this.environmentMapIntensity>0){const e=this.getPlane();if(e&&!(null==(t=this.environmentMapUrl)?void 0:t.trim())){const t=e.textures.find(e=>"uBgTexture"===e._samplerName);t&&t._sampler&&t._canDraw&&(this.local.envTexture={gl:i,webglTexture:t._sampler.texture,width:t._size.width,height:t._size.height})}}else this.local.envTexture=null;if(this.renderNormals){const e=this.getPlane();if(e){const t=e.textures.find(e=>"uBgTexture"===e._samplerName);t&&t._sampler&&t._sampler.texture&&(this.local.backgroundTexture={gl:i,webglTexture:t._sampler.texture,width:t._size.width,height:t._size.height})}}const r=void 0!==this.local.time?this.local.time:performance.now();if(this.local.renderTarget)if(this.local.renderTarget._frameBuffer){const e=this.local.renderTarget._frameBuffer,t=this.local.renderTarget._size.width,s=this.local.renderTarget._size.height;i.bindFramebuffer(i.FRAMEBUFFER,e),i.viewport(0,0,t,s);try{const e=i.getParameter(i.CURRENT_PROGRAM);this.local.draw(i,r,this),e&&i.useProgram(e)}finally{i.bindFramebuffer(i.FRAMEBUFFER,null),i.viewport(0,0,i.drawingBufferWidth,i.drawingBufferHeight)}}else this.local.draw(i,r,this)}resize(){}cleanup(){this.local.dispose&&this.local.dispose(this),this.local.initialize=null,this.local.loadModel=null,this.local.draw=null,this.local.dispose=null,this.local.rendererLoaded=!1,this.local.initialized=!1,this.local.modelLoaded=!1,this.local.renderTarget&&(this.local.renderTarget.remove(),this.local.renderTarget=null)}isAnimating(){return this.visible&&(this.animating||this.trackMouse>0||this.rotationTracking>0)}getProp(e){var t;return(null==(t=this.local.stateEffectProps)?void 0:t[e])??this[e]}dispose(){this.cleanup(),super.dispose()}}class He extends Ue{constructor(e,t,i,r){super(e,t),s(this,"layerType","text"),this.initOptions=r;let a=this.default(e||{});for(let s in a)this[s]=a[s];this.breakpoints.length&&this.setBreakpointValues(),this.isSafari=/^((?!chrome|android).)*safari/i.test(navigator.userAgent),Object.keys(e).length&&this.createLocalCanvas(),this.loadFont()}default(e){return{fill:e.fill||["#ffffff"],fontSize:e.fontSize??24,fontSizeMode:e.fontSizeMode||"fixed",fontCSS:e.fontCSS||null,lineHeight:e.lineHeight??25,letterSpacing:e.letterSpacing||0,fontFamily:e.fontFamily||"arial",fontStyle:e.fontStyle||"normal",fontWeight:e.fontWeight||"normal",textAlign:e.textAlign||"left",textContent:e.textContent||"",gradientAngle:e.gradientAngle||e.gradAngle||0,gradientType:e.gradientType||e.gradType||"linear",noTextAsHtml:e.noTextAsHtml||!1}}unpackage(){return this.fill=be(this.fill),this.effects=be(this.effects),this}loadFont(){var e;const t=this.fontStyle.includes("italic")?"italic":"normal",s=e=>"normal"===e||"400"===e||400===e?"normal":e.toString(),i=isNaN(parseInt(this.fontWeight))?"normal":s(this.fontWeight);if(Array.from(document.fonts).some(e=>e.family===this.fontFamily&&e.style===t&&s(e.weight)===i&&"loaded"===e.status)||!(null==(e=this.fontCSS)?void 0:e.src))return void this.handleFontLoaded();let r=this.fontCSS.src.split(" ").join("%20");const a=new FontFace(this.fontFamily,`url(${r})`,{style:t,weight:i});document.fonts.add(a),a.load().then(()=>{this.handleFontLoaded()}).catch(e=>{this.handleFontLoaded()})}handleFontLoaded(){this.local.loaded=!0,this.render(),this.render();const e=this.state();e.renderFrame&&e.renderFrame(),Se(this,this.state().element)}getAbsoluteFontValues(e){var t,s,i,r,a,n;const o=(null==(s=null==(t=this.local)?void 0:t.stateEffectProps)?void 0:s.fontSize)||this.fontSize,h=(null==(r=null==(i=this.local)?void 0:i.stateEffectProps)?void 0:r.lineHeight)||this.lineHeight,l=(null==(n=null==(a=this.local)?void 0:a.stateEffectProps)?void 0:n.letterSpacing)||this.letterSpacing,d="fixed"===this.fontSizeMode?o:o*e.canvasWidth;return{fontSize:d,lineHeight:"fixed"===this.fontSizeMode?h:h*d,letterSpacing:"fixed"===this.fontSizeMode?l:l*d}}render(){var e,t,s;if(!(null==(e=this.local)?void 0:e.ctx))return;let i=this.local.ctx,{left:r,top:a,width:n}=this.box();const o=Le(this.anchorPoint),h=(null==(s=null==(t=this.local)?void 0:t.stateEffectProps)?void 0:s.rotation)||this.rotation;let l=this.state(),d=this.height,u=r-o.x*n,c=a-o.y*d,p=0,{fontSize:m,lineHeight:g,letterSpacing:f}=this.getAbsoluteFontValues(l),_=this.fontStyle.includes("italic")?"italic":"normal",x=/^\d+$/.test(this.fontStyle)?this.fontStyle:"400";i.clearRect(0,0,l.canvasWidth,l.canvasHeight),i.font=`${_} ${x} ${m}px/${g}px ${this.fontFamily}, -apple-system, BlinkMacSystemFont, Helvetica, Arial`,this.isSafari||(i.textAlign=this.textAlign,i.letterSpacing=f+"px");const v=i.measureText("m").width;n=Math.max(n,v),i.save();let y=u+n/2,b=c+d/2;i.translate(y,b),i.rotate(360*h*Math.PI/180),i.translate(-y,-b),"center"===this.textAlign&&(u+=n/2),"right"===this.textAlign&&(u+=n),i.fillStyle=ve(i,this.box(),this.fill,this.gradientAngle,this.gradientType);const P=(e,t)=>{let s=c+g*t+g/2+m/3;this.isSafari?((e,t,s,i,r,a,n)=>{let o,h=t.split("").reduce((s,i,a)=>s+e.measureText(i).width+(a=0;l--){const s=t[l];o-=e.measureText(s).width,e.fillText(s,o,i),l>0&&(o-=r)}else for(let l=0;lt.split("").reduce((i,r,a)=>(i+=e.measureText(r).width,an||"\n"===r){if(""!==e)w[S]=e.trim(),s!==t.length-1?(w.splice(S+1,0,t.slice(s).join("")),T++):"\n"!==r&&w.push(r);else{let e=r,a=S;for(;e.length>0;){let t="";for(let s=0;s0&&(w.splice(a+1,0,e),a++,T++)}t.slice(s+1).length>0&&(w[a]+=t.slice(s+1).join(""))}break}e=a,s===t.length-1&&(w[S]=e.trim())}}w.forEach((e,t)=>{P(e,p),t{t.pauseTime=e})):(Ee(),Qe.forEach(t=>{t.pauseTime=t.pauseTime-e,t.curtain.planes.forEach(e=>{e.videos.forEach(e=>{e.play()})})}))}function Ge(){de=window.innerHeight||document.documentElement.clientHeight,ue=window.innerWidth||document.documentElement.clientWidth,Qe.filter(e=>e.initialized).forEach(e=>{e.refresh()}),Ye()}function Xe(e,t,s=50){const i=t||e.getBoundingClientRect(),r=i.top>=-s&&i.top<=de+s||i.bottom>=-s&&i.bottom<=de+s||i.top<=0&&i.bottom>=de,a=i.left>=-s&&i.left<=ue+s||i.right>=-s&&i.right<=ue+s||i.left<=0&&i.right>=ue;return r&&a}function Ye(){Qe.filter(e=>e.getDynamicLayers().length).forEach(e=>{let t=e.element.getBoundingClientRect();if(e.scrollY=ce,e.lastBbox){0===Math.abs(t.top-e.lastBbox.top)&&me>0?(e.fixedCounter=(e.fixedCounter||0)+1,e.fixedCounter>3&&(e.isFixed=!0)):e.fixedCounter=0}e.lastBbox=e.bbox,e.bbox=t})}function qe(e){const t=Qe.filter(e=>e.getDynamicLayers().length),s=Qe.filter(e=>e.rendering);t.length&&!s.length&&Ee();const i=performance.now();(!ge||i-ge>64)&&Ye(),t.forEach(e=>{if(Xe(e.element,e.bbox,100)){if(!e.isInView){e.isInView=!0,e.pauseTime=e.pauseTime-i;const t=e.element.offsetWidth>0&&e.element.offsetHeight>0;t&&e.curtain?e.resize():t||requestAnimationFrame(()=>{e.element.offsetWidth>0&&e.element.offsetHeight>0&&e.curtain&&e.resize()}),!e.lazyLoad||e.initialized||e.initializing||e.initializePlanes()}}else e.isInView&&(e.isInView=!1,e.pauseTime=i)})}function $e(e){Qe.filter(e=>e.isInView).forEach(e=>{e.mouse.page.x=99999999999,e.mouse.page.y=99999999999,e.mouse.enterTime=null})}function Ze(e){let t=performance.now();Qe.filter(e=>e.isInView&&e.initialized).forEach(s=>{let i,r,a=s.bbox;Math.abs(me)>1&&t-s.lastBboxTime>64&&(a=s.element.getBoundingClientRect(),s.lastBbox=s.bbox,s.bbox=a,s.lastBboxTime=t),e.targetTouches?(i=e.targetTouches[0].pageX,r=e.targetTouches[0].pageY):(i=e.pageX,r=e.pageY),s.isFixed&&(s.scrollY=0,r=e.targetTouches?e.targetTouches[0].clientY:e.clientY);const n=i-a.left,o=r-(a.top+(s.isFixed?0:ce));s.mouse.page.x=i,s.mouse.page.y=r,s.mouse.movePos.x=.5*n,s.mouse.movePos.y=.5*o,s.mouse.movedInView=!0})}let Qe=[];class Je{constructor(e){s(this,"local",{preloadedTextures:{}}),s(this,"scrollY",0),s(this,"paused",!1),s(this,"destroyed",!1),s(this,"lastBboxTime",0),this.id=e.id,this.breakpoints=[{name:"Desktop",max:1/0,min:992},{name:"Tablet",max:991,min:576},{name:"Mobile",max:575,min:0}],this.projectId=e.projectId,this.canvasWidth=e.width||e.element.offsetWidth||ue,this.canvasHeight=e.height||e.element.offsetHeight||de,this.curtain=void 0,this.curtainRafId=void 0,this.dpi=+e.dpi||Math.min(1.5,window.devicePixelRatio),this.element=e.element,this.fps=e.fps||60,this.name=e.name,this.frameDuration=Math.floor(1e3/(e.fps||60)),this.layers=e.layers,this.lazyLoad=e.lazyLoad,this.initialized=!1,this.lasTick=null,this.lastTime=0,this.rendering=!1,this.bbox={},this.isFixed=e.fixed||"fixed"===window.getComputedStyle(this.element).position,this.interactivity={mouse:{disableMobile:!1,disabled:!1}},this.mouse={downPos:{x:.5,y:.5},movePos:{x:.5,y:.5},lastPos:{x:.5,y:.5},delta:{x:0,y:0},page:{x:99999999999,y:99999999999},dragging:!1,movedInView:!1,enterTime:null,ticks:0,pos:{x:0,y:0}},this.renderingScale=e.renderingScale||1,this.scale=e.scale||1,this.split=!1,this.versionId="",e.width&&e.height&&(this.element.style.width=e.width+"px",this.element.style.height=e.height+"px"),this.bbox=this.element.getBoundingClientRect(),this.lastBbox=this.bbox,this.currentBreakpoint=this.breakpoints.find(e=>ue>=e.min&&ue<=e.max),this.createCurtains(),this.setCanvasScale(),this.curtain&&(this.textureLoader=new F(this.curtain))}preloadTextures(){this.layers.forEach(e=>{var t,s,i,r,a,n,o,h,l;if(e.isElement)e.local.canvas&&this.textureLoader.loadCanvas(e.local.canvas,{sampler:"uTexture",premultiplyAlpha:!0},t=>{t.userData.hasStateEffects=e.states.appear.length>0||e.states.scroll.length>0||e.states.hover.length>0,e.preloadedCanvasTexture=t},e=>{});else if((null==(t=null==e?void 0:e.texture)?void 0:t.src)||(null==(i=null==(s=null==e?void 0:e.data)?void 0:s.texture)?void 0:i.src)){const t=(null==(r=null==e?void 0:e.texture)?void 0:r.src)||(null==(n=null==(a=null==e?void 0:e.data)?void 0:a.texture)?void 0:n.src),s=(null==(o=null==e?void 0:e.texture)?void 0:o.sampler)||(null==(l=null==(h=null==e?void 0:e.data)?void 0:h.texture)?void 0:l.sampler)||"uTexture";this.local.preloadedTextures[t]?this.local.preloadedTextures[t].count++:(this.local.preloadedTextures[t]={count:1,texture:null},this.textureLoader.loadImage(t,{sampler:s,premultipliedAlpha:!1},e=>{this.local.preloadedTextures[t].texture=e}))}})}setCanvasScale(){this.canvasWidth=this.element.offsetWidth,this.canvasHeight=this.element.offsetHeight}destroy(){var e,t;this.destroyed=!0,this.rendering=!1,this.isInView=!1;const s=Qe.findIndex(e=>e.id===this.id);-1!==s&&Qe.splice(s,1),this.layers.filter(e=>e.dispose).forEach(e=>e.dispose()),this.layers=[],(null==(e=this.curtain)?void 0:e.gl)&&(this.curtain.dispose(),this.curtain=null),this.element&&(this.element.removeAttribute("data-us-initialized"),this.element.removeAttribute("data-scene-id"),null==(t=this.element.querySelector("canvas"))||t.remove(),this.element.querySelectorAll("[data-us-text]").forEach(e=>{e.remove()})),Ee(),Qe.length||st()}resize(){this.lastBbox=this.bbox,this.bbox=this.element.getBoundingClientRect(),this.setCanvasScale(),this.layers.filter(e=>e.isElement).forEach(e=>{e.resize()}),this.currentBreakpoint=this.breakpoints.find(e=>ue>=e.min&&ue<=e.max),this.curtain&&(this.curtain.resize(),this.curtain.canvas.style.width=this.canvasWidth+"px",this.curtain.canvas.style.height=this.canvasHeight+"px",this.curtain.planes.forEach(e=>{e.uniforms.resolution&&(e.uniforms.resolution.value.x=this.curtain.canvas.width,e.uniforms.resolution.value.y=this.curtain.canvas.height)}))}refresh(){this.initialized=!1,this.layers.forEach(e=>{var t,s;null==(t=e.states)||t.scroll.forEach(e=>e.resetState()),null==(s=e.states)||s.appear.forEach(t=>{e[t.prop]=t.endValue??e.local.stateEffectProps[t.prop]??e[t.prop]}),e.breakpoints.length&&(e.setBreakpointValues(),e.local.bpProps&&Object.keys(e.local.bpProps).forEach(t=>{e.getPlanes().forEach(s=>{s.uniforms[t]&&Ae(e.local.bpProps[t],s.uniforms[t],t)})})),e.preloadedCanvasTexture&&(e.preloadedCanvasTexture.shouldUpdate=!0)}),requestAnimationFrame(()=>{this.curtain&&(this.curtain.planes.forEach(e=>{e._canDraw=!0}),this.scrollY=ce,this.resize(),this.handlePlaneCreation())})}getDynamicLayers(){return this.layers.filter(e=>Re(e))}createCurtains(){this.curtain=new p({container:this.element,premultipliedAlpha:!0,antialias:!1,autoRender:!1,autoResize:!1,watchScroll:!1,renderingScale:Math.min(Math.max(.25,this.renderingScale),1),production:!1,pixelRatio:this.dpi}),this.curtain.gl&&(this.curtain.onError(e=>{}),this.curtain.onContextLost(()=>{this.curtain.restoreContext()}),this.curtain.onContextRestored(()=>{this.initialized&&(this.layers.forEach(e=>{e.preloadedCanvasTexture&&(e.preloadedCanvasTexture.shouldUpdate=!0)}),requestAnimationFrame(()=>{this.curtain&&(this.curtain.planes.forEach(e=>{e._canDraw=!0}),this.renderFrame())}))}),this.scrollY=ce)}renderFrame(){var e;this.destroyed||(e=this.curtain)&&e.renderer&&e.renderer.nextRender&&"function"==typeof e.renderer.nextRender.execute&&(this.layers.forEach(e=>{e.local.currentFrameMouseValues=null}),this.handleStateEffects(),this.curtain.render())}renderNFrames(e,t){let s=0;const i=()=>{this.renderFrame(),sRe(e)).length;for(;s&&!Re(s)&&!r&&!a;)t++,s=e[t],s&&(i=s.parentLayer?s.getParent():null,r=i&&Re(i),a=i&&i.effects&&i.effects.length&&i.getChildEffectItems().filter(e=>Re(e)).length);return{static:this.getOrderedItems().splice(0,t),dynamic:this.getOrderedItems().splice(t)}}return{static:[],dynamic:[]}}initializePlanes(e){this.initializing=!0,this.handleItemPlanes(()=>{this.handlePlaneCreation(),e&&e(this)})}getPassPlane(e,t){var s;return null==(s=this.curtain)?void 0:s.planes.find(s=>s.userData.id===e.local.id&&s.userData.passIndex===t)}getRenderTargets(){var e;return null==(e=this.curtain)?void 0:e.renderTargets.filter(e=>e.userData.id)}getPlanes(){var e;return null==(e=this.curtain)?void 0:e.planes.filter(e=>"PingPongPlane"!==e.type)}getPlaneParams(e,t){var s,i,r,a,n;let o=(null==(s=e.data)?void 0:s.heightSegments)||(null==(i=e.data)?void 0:i.widthSegments)?500:1;const h={resolution:{name:"uResolution",type:"2f",value:new S(this.canvasWidth,this.canvasHeight)},mousePos:{name:"uMousePos",type:"2f",value:new S(.5)},time:{name:"uTime",type:"1f",value:0},dpi:{name:"uDpi",type:"1f",value:this.dpi*+this.renderingScale}};e.isElement&&(h.sampleBg={name:"uSampleBg",type:"1i",value:1}),e.isModel&&(h.opacity={name:"uOpacity",type:"1f",value:1}),e.usesPingPong&&(h.previousMousePos={name:"uPreviousMousePos",type:"2f",value:new S(.5)});let l=e.compiledFragmentShaders[t]||e.compiledFragmentShaders[0],d=e.compiledVertexShaders[t]||e.compiledVertexShaders[0];if(e.states&&[...e.states.appear,...e.states.scroll,...e.states.hover].forEach(t=>{h[t.prop]||t.uniformData&&(h[t.prop]=t.uniformData,h[t.prop].value=e[t.prop])}),null==(r=e.data)?void 0:r.uniforms)for(let u in e.data.uniforms){let t=e.data.uniforms[u];h[u]=e.data.uniforms[u],"Vec3"===(null==(a=t.value)?void 0:a.type)?h[u].value=new M(t.value._x,t.value._y,t.value._z):"Vec2"===(null==(n=t.value)?void 0:n.type)?h[u].value=new S(t.value._x,t.value._y):"object"==typeof t.value&&(h[u].value=be(t.value))}return{fragmentShader:l,vertexShader:d,widthSegments:o,heightSegments:o,texturesOptions:{floatingPoint:"half-float",premultiplyAlpha:!0},uniforms:h}}createPlane(e,t,s){var i;let r,a;r=e.isElement||e.isModel?this.getPlaneParams(e):this.getPlaneParams(e,s?s.index:null),r.watchScroll=!1;try{if(!this.curtain.container)throw new Error("Can't find scene container");let n=(null==s?void 0:s.downSample)||0===(null==s?void 0:s.index)&&(null==(i=e.data)?void 0:i.downSample),o=this.renderingScale;if(n&&(o="number"==typeof n?n:.5,o*=this.renderingScale),e.userDownsample&&"number"==typeof e.userDownsample&&(o*=e.userDownsample),a=new se(this.curtain,this.curtain.container,r),!a||!a.userData||!a.textures)throw new Error("Plane not properly initialized");return a.textures.length=0,a.userData.id=e.local.id,a.userData.layerType=e.layerType,a.userData.type=e.type,a.userData.downSample=o,a.setRenderOrder(t),a}catch(n){return null}}createPingPongPlane(e,t,s){var i;let r=this.getPlaneParams(e,1+((null==s?void 0:s.length)||0)),a=null==(i=this.curtain)?void 0:i.planes.find(t=>"PingPongPlane"===t.type&&t.userData.id===e.local.id);if(a)a.setRenderOrder(t);else{if(a=new re(this.curtain,this.curtain.container,r),!a)return;a.userData.id=e.local.id,a.userData.pingpong=!0,a.setRenderOrder(t),a.onReady(()=>{this.setInitialEffectPlaneUniforms(a,e,null==e?void 0:e.getParent(),s),a.userData.isReady=!0}).onRender(()=>{this.setEffectPlaneUniforms(a,e)})}if(a)return a}createEffectPlane(e,t,s){const i=this.createPlane(e,t,s);if(!i)return;const r=e.getParent();if(!i||!i.userData||!i.textures)throw new Error("Plane not properly initialized",i);s&&(i.userData.passIndex=s.index,i.userData.length=e.data.passes.length,Object.entries(s).forEach(([e,t])=>{i.uniforms[e]&&(i.uniforms[e].value=t)})),this.setInitialEffectPlaneUniforms(i,e,r,s),i.onReady(()=>{i.userData.isReady=!0}).onRender(()=>this.setEffectPlaneUniforms(i,e))}createElementPlane(e,t){const s=this.createPlane(e,t);s&&s.onReady(()=>{this.setInitialElementPlaneUniforms(s,e),s.userData.isReady=!0}).onRender(()=>this.setElementPlaneUniforms(s,e))}handleMediaTextures(e,t,s){var i;if([t.texture,null==(i=t.data)?void 0:i.texture].filter(e=>null==e?void 0:e.src).forEach(i=>{var r;if(null==(r=t.compiledFragmentShaders[s.passIndex??0])?void 0:r.includes(i.sampler)){const t=this.local.preloadedTextures[i.src];(null==t?void 0:t.texture)?(t.count>1?(Fe(e,i.sampler,t.texture),t.count--):e.addTexture(t.texture),e.userData.textureLoaded=!0):this.textureLoader.loadImage(i.src,{premultipliedAlpha:!1,sampler:i.sampler},t=>{e.addTexture(t),e.userData.textureLoaded=!0})}}),"video"===t.type){const s=t.src.includes(", ")?function(e){const t=e.split(",").map(e=>e.trim()),s=/^((?!chrome|android).)*safari/i.test(navigator.userAgent),i=/iPad|iPhone|iPod/.test(navigator.userAgent);if(s||i){const e=t.find(e=>e.endsWith(".mov")||e.endsWith(".mp4"));if(e)return e}return t.find(e=>e.endsWith(".webm"))||t[0]}(t.src):t.src;e.loadVideo(s,{premultipliedAlpha:!0,sampler:"uVideoTexture"},s=>{e.videos.at(-1).loop=!t.hasOwnProperty("loop")||t.loop,e.videos.at(-1).playbackRate=t.playbackRate||1,e.videos.at(-1).play(),e.userData.textureLoaded=!0})}}handleEffectPlane(e,t,s){var i;const r="passIndex"in s?this.getPassPlane(e,s.passIndex):e.getPlane();if(!r)return!1;let a=this.getRenderTargets()[t-1],n=null==(i=this.curtain)?void 0:i.planes.find(t=>"PingPongPlane"===t.type&&t.userData.id===e.local.id),o=e.compiledFragmentShaders[s.passIndex??0];if(n&&(null==o?void 0:o.includes("uPingPongTexture"))&&Fe(r,"uPingPongTexture",n.getTexture()),a?Fe(r,"uTexture",a.getTexture()):Fe(r,"uTexture"),null==o?void 0:o.includes("uBgTexture")){let e=this.getRenderTargets()[t-(1+s.passIndex)];e&&Fe(r,"uBgTexture",e.getTexture())}this.handleMediaTextures(r,e,s)}handleModelPlane(e,t){var s;const i=e.getPlane();let r=this.getRenderTargets()[t-1];const a=this.layers.filter(e=>!e.parentLayer);let n=a[a.indexOf(e)-1];i.textures.forEach(e=>{}),i.textures=[],(null==(s=e.local.renderTarget)?void 0:s.getTexture)&&e.local.modelLoaded?i.addTexture(e.local.renderTarget.getTexture()):i.createTexture({sampler:"uTexture",premultipliedAlpha:!0,fromTexture:r.getTexture()}),r&&e.renderNormals&&i.createTexture({sampler:"uRefractTexture",premultipliedAlpha:!0,fromTexture:r.getTexture()}),n.local.lastTarget&&i.createTexture({sampler:"uBgTexture",premultipliedAlpha:!0,fromTexture:n.local.lastTarget.getTexture()})}handleElementPlane(e,t){const s=e.getPlane();if(!s)return!1;const i=e.getChildEffectItems(),r=this.layers.filter(e=>!e.parentLayer);let a,n=this.getRenderTargets()[t-1],o=e.maskDepthLayer||1,h=r[r.indexOf(e)-(1+o)];if(e.mask&&h&&(a=h.local.lastTarget),i.length||(s.textures.length=0),n&&i.length?Fe(s,"uTexture",n.getTexture()):s&&s.addTexture(e.preloadedCanvasTexture),n){if(i.length){let e=i.reduce((e,t)=>e+t.getPlanes().length,0);n=this.getRenderTargets()[t-(1+e)]}n&&(Fe(s,"uBgTexture",n.getTexture()),a&&e.mask&&Fe(s,"uPreviousLayerTexture",a.getTexture()))}}handleChildEffectPlane(e,t,s){var i;const r="passIndex"in s?this.getPassPlane(e,s.passIndex):e.getPlane();if(!r)return;const a=e.getParent();let n=this.getRenderTargets()[t-1],o=null==(i=this.curtain)?void 0:i.planes.find(t=>"PingPongPlane"===t.type&&t.userData.id===e.local.id),h=e.compiledFragmentShaders[s.passIndex??0],l=a.effects.filter(e=>{if(this.layers.find(t=>t.parentLayer===e))return this.layers.find(t=>t.parentLayer===e)}),d=l.indexOf(e.parentLayer),u=l[l.length-1]===l[d],c=s.passIndex===s.length;if(n&&(d||s.passIndex>0)?(e.isMask&&(!s.length||u&&c)&&r.addTexture(a.preloadedCanvasTexture),Fe(r,"uTexture",n.getTexture())):e.isMask?(u&&c&&r.addTexture(a.preloadedCanvasTexture),n?Fe(r,"uTexture",n.getTexture()):Fe(r,"uTexture")):(null==h?void 0:h.includes("uTexture"))&&(r.addTexture(a.preloadedCanvasTexture),a.preloadedCanvasTexture.userData.used=!0),o&&(null==h?void 0:h.includes("uPingPongTexture"))&&Fe(r,"uPingPongTexture",o.getTexture()),null==h?void 0:h.includes("uBgTexture"))if(d&&s.length>1){let e=this.getRenderTargets()[t-(1+s.length)];e&&Fe(r,"uBgTexture",e.getTexture())}else a.preloadedCanvasTexture.userData.used?r.loadCanvas(a.local.canvas,{sampler:"uBgTexture",premultiplyAlpha:!0},e=>{e.shouldUpdate=a.preloadedCanvasTexture.shouldUpdate}):(a.preloadedCanvasTexture._samplerName="uBgTexture",r.addTexture(a.preloadedCanvasTexture));"custom"===e.type&&Fe(r,"uCustomTexture",this.getRenderTargets()[t]),this.handleMediaTextures(r,e,s)}createPlanes(){this.getOrderedItems().forEach((e,t)=>{e.getPlanes().length?e.getPlanes().forEach(e=>e.setRenderOrder(t)):e.isElement?this.createElementPlane(e,t):e.isModel?this.createModelPlane(e,t):this.createEffectPlanes(e,t)})}createModelPlane(e,t){const s=this.createPlane(e,t);s&&s.onReady(()=>{s.userData.isReady=!0,s.userData.createdAt=performance.now();let t=e.userDownsample||1,i=this.curtain.canvas.width*t,r=this.curtain.canvas.height*t;e.local.renderTarget||(e.local.renderTarget=new ie(this.curtain,{depth:!0,maxWidth:i,maxHeight:r,texturesOptions:{sampler:"uTexture",premultiplyAlpha:!0}}),e.local.rendererLoaded||e.loadRenderer())}).onRender(()=>{this.setModelPlaneUniforms(s,e),this.curtain.gl&&e.renderModel()})}createEffectPlanes(e,t){const s=e.data;s.passes&&s.passes.length?(this.createEffectPlane(e,t,{index:0,downSample:s.downSample,length:s.passes.length+1}),s.passes.forEach((i,r)=>{this.createEffectPlane(e,t,{index:r+1,length:s.passes.length+1,downSample:i.downSample,[i.prop]:i.value})}),e.usesPingPong&&this.createPingPongPlane(e,t,s.passes)):(this.createEffectPlane(e,t),e.usesPingPong&&this.createPingPongPlane(e,t))}createTextures(){const e=this.getPlanes().sort((e,t)=>e.renderOrder-t.renderOrder),t=e.length;for(let s=0;se.local.id===i.userData.id);s{var s;let i=!1;const r=null==(s=this.curtain)?void 0:s.planes;if(r){for(let e=0;ee.prop===s))||(t.local.bpProps&&s in t.local.bpProps?Ae(t.local.bpProps[s],e.uniforms[s],s):s in t&&Ae(t[s],e.uniforms[s],s));s&&i&&i.index{e.updateStateEffects()})}setInitialElementPlaneUniforms(e,t){var s;e.uniforms.resolution.value.x=this.curtain.canvas.width,e.uniforms.resolution.value.y=this.curtain.canvas.height;for(let i in e.uniforms)t.local.bpProps&&i in t.local.bpProps?e.uniforms[i].value=t.local.bpProps[i]:i in t&&(e.uniforms[i].value=(null==(s=t.local.stateEffectProps)?void 0:s[i])??t[i]);e.uniforms.sampleBg&&(e.renderOrder-t.effects.length===0?e.uniforms.sampleBg.value=0:e.uniforms.sampleBg.value=1)}setElementPlaneUniforms(e,t){if(e.uniforms.mousePos){t.local.currentFrameMouseValues||(t.local.currentFrameMouseValues=this.calculateItemMouseValues(t));const s=t.local.currentFrameMouseValues;if(!s)return;!this.mouse.movedInView||e.uniforms.mousePos.value.x===s.x&&e.uniforms.mousePos.value.y===s.y||(e.uniforms.mousePos.value.x=s.x,e.uniforms.mousePos.value.y=s.y)}}calculateItemMouseValues(e){if(!this.mouse.movedInView)return null;const t=this.bbox.width/2,s=this.bbox.height/2,i=this.getMousePosWithMomentum(e,t,s);return this.local.mouseValuePool||(this.local.mouseValuePool=new S(.5)),this.local.mouseValuePool.x=i.x,this.local.mouseValuePool.y=i.y,this.local.mouseValuePool}getMousePosWithMomentum(e,t,s){let i=this.mouse.pos.x,r=this.mouse.pos.y,a=e.trackAxes||"xy",n="x"===a||"xy"===a,o="y"===a||"xy"===a;const h=e.mouseMomentum||0;let l=i/t,d=1-r/s;if(!h)return{x:n?l:.5,y:o?d:.5};if(!e.local.lastMousePos)return e.local.lastMousePos={x:n?l:.5,y:o?d:.5},e.local.lastMousePos;const u=e.local.lastMousePos.x*t,c=(1-e.local.lastMousePos.y)*s,p=Math.abs(i-u),m=Math.abs(r-c);return p16?(e.uniforms.previousMousePos.value.x=e.uniforms.mousePos.value.x,e.uniforms.previousMousePos.value.y=e.uniforms.mousePos.value.y):(e.uniforms.previousMousePos.value.x=o.x,e.uniforms.previousMousePos.value.y=o.y)),e.uniforms.mousePos&&!o.equals(e.uniforms.mousePos.value)&&(e.uniforms.mousePos.value.x=o.x,e.uniforms.mousePos.value.y=o.y),this.mouse.ticks++)}getOrderedItems(){let e=[];return this.layers.filter(e=>!e.parentLayer).forEach(t=>{t.effects&&t.effects.length&&e.push(...t.getChildEffectItems()),e.push(t)}),e}getTextureParams(e,t,s){var i;const r=e[t];let a=1;r.userData.downSample&&(a="number"==typeof r.userData.downSample?r.userData.downSample:.5);return{maxWidth:this.curtain.canvas.width*a,maxHeight:this.curtain.canvas.height*a,depth:null==(i=null==s?void 0:s.data)?void 0:i.depth}}handlePlaneCreation(){this.initialized=!0,this.initializing=!1,this.rendering||this.renderNFrames(2),this.waitForAssetsAndDisablePlanes(),Ee()}waitForAssetsAndDisablePlanes(){this.layers.some(e=>e.isModel&&!e.local.modelLoaded||"image"===e.layerType||"text"===e.layerType&&!e.local.loaded||Object.values(this.local.preloadedTextures).some(e=>e&&null===e.texture))?setTimeout(()=>this.waitForAssetsAndDisablePlanes(),64):(this.layers.filter(e=>e.preloadedCanvasTexture).forEach(e=>{e.preloadedCanvasTexture.shouldUpdate=e.preloadedCanvasTexture.userData.hasStateEffects||!1}),setTimeout(()=>this.disablePlanes(),16))}disablePlanes(){const e=this.getSplitOrderedItems();e.dynamic.length||e.static.pop();for(const t of e.static)t.getPlanes().forEach(e=>{e._canDraw=!1})}}function Ke(e,t,s){e.addEventListener(t,s,{passive:!0})}function et(e,t,s){e.removeEventListener(t,s)}function tt(){Ke(window,"scroll",qe),we()?Ke(window,"touchmove",Ze):Ke(window,"mousemove",Ze),Ke(window,"routeChange",Me),Ke(document,"mouseleave",$e),he=function(e,t){let s;return function(...i){clearTimeout(s),s=setTimeout(()=>{e.apply(this,i)},t)}}(Ge,16),we()?Ke(window,"orientationchange",he):Ke(window,"resize",he),Ke(document,ne,je),le=!0}function st(){et(window,"mousemove",Ze),et(window,"touchmove",Ze),et(window,"scroll",qe),et(window,"routeChange",Me),et(document,"mouseleave",$e),he&&(et(window,"resize",he),et(window,"orientationchange",he)),et(document,ne,je),le=!1}function it(e){let t=e.projectId?e.projectId.split("?")[0]:null,s=e.projectId?e.projectId.split("?")[1]:null;return new Promise((i,r)=>{(function(e,t,s,i,r){let a;if(s){a=s;const e=document.getElementById(s);if(e)try{let t=JSON.parse(e.innerText);return(null==t?void 0:t.options)&&((null==t?void 0:t.layers)||(null==t?void 0:t.history))?Promise.resolve(t):(i(new Error(`Did not find valid JSON inside ${s}`)),Promise.reject())}catch(n){return i(new Error(`Error parsing JSON from ${s}: ${n.message}`)),Promise.reject()}}else{let s="https://storage.googleapis.com/unicornstudio-production";r||(null==t?void 0:t.includes("production=true"))?(s="https://assets.unicorn.studio",t=`v=${Date.now()}`):(null==t?void 0:t.includes("update="))||(t=`v=${Date.now()}`),a=`${s}/embeds/${e}${t?"?"+t:""}`}return fetch(a).then(e=>e.json()).then(e=>e).catch(e=>{})})(t,s,e.filePath,r,e.production).then(s=>{s&&(s.layers||s.history)&&s.options||r(new Error(`Error fetching data for project id '${e.projectId}'`));const a=s.options||{},n=(o=e.element,("object"==typeof HTMLElement?o instanceof HTMLElement:o&&"object"==typeof o&&null!==o&&1===o.nodeType&&"string"==typeof o.nodeName)?e.element:document.getElementById(e.elementId));var o;if(!n)return void r(new Error(`Couldn't find an element with id '${e.elementId}' on the page.`));const h=xe();n.setAttribute("data-scene-id",h);let l=e.scale||a.scale||1,d=e.dpi||a.dpi||Math.min(1.5,window.devicePixelRatio);const u=function(e,t,s,i){const r=i?{...s,modules:i}:s,a=[];return e.forEach(e=>{switch(e.layerType){case"text":a.push(new He(e,t,null,r).unpackage());break;case"image":a.push(new We(e,t,r).unpackage());break;case"model":a.push(new Ne(e,t,r).unpackage());break;case"shape":a.push(new Ve(e,t,r).unpackage());break;case"effect":a.push(new Be(e,t,r).unpackage())}}),a}(s.layers||s.history,h,function(e,t,s){return{canvasWidth:e.offsetWidth,canvasHeight:e.offsetHeight,scale:t,dpi:s,element:e}}(n,l,d),s.modules),c=new Je({id:h,fps:e.fps||a.fps||60,dpi:d,name:a.name,projectId:t||e.filePath.split(".")[0],renderingScale:l,element:n,lazyLoad:e.lazyLoad,fixed:e.fixed,width:e.width,height:e.height});c.curtain.canvas.innerText=e.altText||"",c.curtain.canvas.setAttribute("aria-label",e.ariaLabel||"Unicorn Studio Scene"),c.curtain.canvas.setAttribute("role","img");let p=a[_e("ZnJlZVBsYW4=")];(p||a[_e("aW5jbHVkZUxvZ28=")])&&function(e,t){const s=document.createElement("a");s.href="https://unicorn.studio?utm_source=public-url",s.style="position: absolute; display: flex; bottom: 30px; left: 0; width: 190px; margin: 0 auto; right: 0rem; padding: 10px; border-radius: 6px; background-color: rgba(255, 255, 255, 1); box-shadow: 0 3px 9px 0 rgba(0, 0, 0, .2); z-index: 99999999; box-sizing: border-box;",s.target="_blank";const i=document.createElement("img");i.src=_e("aHR0cHM6Ly9hc3NldHMudW5pY29ybi5zdHVkaW8vbWVkaWEvbWFkZV9pbl91c19zbWFsbF93ZWIuc3Zn"),i.alt=_e("TWFkZSB3aXRoIHVuaWNvcm4uc3R1ZGlv"),i.style="width: 170px; height: auto;",s.appendChild(i),t.appendChild(s)}(0,n),Qe.push(c),c.layers=u,c.preloadTextures(),c.setInteractiveParams(e,a),c.isInView=c.isFixed||Xe(c.element,c.bbox,50),c.lazyLoad&&!c.isInView||c.initializePlanes(),le||tt(),i(c)}).catch(e=>{r(e)})})}e.addScene=it,e.destroy=function(){Qe.forEach(e=>{e.destroy()}),Qe.length=0,st()},e.init=function(){return function(){try{return!!document.createElement("canvas").getContext("webgl2")}catch(e){return!1}}()?new Promise((e,t)=>{const s=[...document.querySelectorAll("[data-us-project], [data-us-project-src]")],i="undefined"!=typeof window&&window.requestIdleCallback?window.requestIdleCallback:e=>setTimeout(e,0);s.filter(e=>!e.getAttribute("data-us-initialized")).forEach((t,r)=>{t.setAttribute("data-us-initialized",!0),i(()=>{const i=Te(t,"data-us-project"),a=Te(t,"data-us-project-src"),n=Te(t,"data-us-disablemobile"),o=Te(t,"data-us-disablemouse");it({projectId:a?null:i,filePath:a,element:t,dpi:+Te(t,"data-us-dpi"),scale:+Te(t,"data-us-scale"),production:Te(t,"data-us-production"),fps:+Te(t,"data-us-fps"),lazyLoad:Te(t,"data-us-lazyload"),altText:Te(t,"data-us-alttext"),ariaLabel:Te(t,"data-us-arialabel"),fixed:Te(t,"data-us-fixed"),interactivity:n||o?{mouse:{disableMobile:n,disabled:o}}:null}).then(t=>{r===s.length-1&&e(Qe)})})})}):Promise.resolve([])},e.scenes=Qe,e.unbindEvents=st,Object.defineProperty(e,Symbol.toStringTag,{value:"Module"})});