@zenvor/view360 4.0.0-beta.7-fork.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +19 -0
- package/README.md +88 -0
- package/css/base.css +19 -0
- package/css/base.min.css +1 -0
- package/css/control-bar.css +329 -0
- package/css/control-bar.min.css +1 -0
- package/css/helper.css +51 -0
- package/css/helper.min.css +1 -0
- package/css/hotspot.css +21 -0
- package/css/hotspot.min.css +1 -0
- package/css/loading-spinner.css +37 -0
- package/css/loading-spinner.min.css +1 -0
- package/css/variable.css +1 -0
- package/css/variable.min.css +0 -0
- package/css/view360.css +468 -0
- package/css/view360.min.css +1 -0
- package/css/vr.css +8 -0
- package/css/vr.min.css +1 -0
- package/declaration/View360.d.ts +150 -0
- package/declaration/cfc/const.d.ts +1 -0
- package/declaration/cfc/index.d.ts +4 -0
- package/declaration/cfc/utils.d.ts +1 -0
- package/declaration/cfc/withMethods.d.ts +2 -0
- package/declaration/const/browser.d.ts +71 -0
- package/declaration/const/error.d.ts +47 -0
- package/declaration/const/external.d.ts +33 -0
- package/declaration/const/internal.d.ts +34 -0
- package/declaration/control/CameraControl.d.ts +10 -0
- package/declaration/control/GyroControl.d.ts +30 -0
- package/declaration/control/PanoControl.d.ts +58 -0
- package/declaration/control/RotateControl.d.ts +75 -0
- package/declaration/control/ZoomControl.d.ts +45 -0
- package/declaration/control/index.d.ts +7 -0
- package/declaration/control/input/GyroInput.d.ts +46 -0
- package/declaration/control/input/KeyboardInput.d.ts +21 -0
- package/declaration/control/input/MouseInput.d.ts +16 -0
- package/declaration/control/input/PinchInput.d.ts +14 -0
- package/declaration/control/input/PointerInput.d.ts +18 -0
- package/declaration/control/input/TouchInput.d.ts +21 -0
- package/declaration/control/input/WheelInput.d.ts +16 -0
- package/declaration/core/AutoResizer.d.ts +13 -0
- package/declaration/core/Autoplay.d.ts +54 -0
- package/declaration/core/Camera.d.ts +88 -0
- package/declaration/core/CameraAnimation.d.ts +25 -0
- package/declaration/core/CameraPath.d.ts +55 -0
- package/declaration/core/CubeTexturePainter.d.ts +16 -0
- package/declaration/core/FrameAnimator.d.ts +13 -0
- package/declaration/core/Motion.d.ts +39 -0
- package/declaration/core/Object3D.d.ts +21 -0
- package/declaration/core/ShaderProgram.d.ts +10 -0
- package/declaration/core/TextureLoader.d.ts +26 -0
- package/declaration/core/TriangleMesh.d.ts +20 -0
- package/declaration/core/VertexArrayObject.d.ts +14 -0
- package/declaration/core/VertexData.d.ts +8 -0
- package/declaration/core/View360Error.d.ts +5 -0
- package/declaration/core/WebGLContext.d.ts +74 -0
- package/declaration/core/WebGLRenderer.d.ts +26 -0
- package/declaration/core/XRManager.d.ts +33 -0
- package/declaration/core/index.d.ts +12 -0
- package/declaration/geometry/CubeGeometry.d.ts +9 -0
- package/declaration/geometry/CylinderGeometry.d.ts +5 -0
- package/declaration/geometry/Geometry.d.ts +8 -0
- package/declaration/geometry/PlaneGeometry.d.ts +5 -0
- package/declaration/geometry/SphereGeometry.d.ts +5 -0
- package/declaration/hotspot/Hotspot.d.ts +7 -0
- package/declaration/hotspot/HotspotRenderer.d.ts +17 -0
- package/declaration/hotspot/index.d.ts +4 -0
- package/declaration/index.cjs.d.ts +3 -0
- package/declaration/index.d.ts +11 -0
- package/declaration/index.umd.d.ts +2 -0
- package/declaration/plugin/ControlBar/AutoHide.d.ts +42 -0
- package/declaration/plugin/ControlBar/ControlBar.d.ts +113 -0
- package/declaration/plugin/ControlBar/ControlBarItem.d.ts +15 -0
- package/declaration/plugin/ControlBar/FullscreenButton.d.ts +19 -0
- package/declaration/plugin/ControlBar/GyroButton.d.ts +14 -0
- package/declaration/plugin/ControlBar/PieView.d.ts +26 -0
- package/declaration/plugin/ControlBar/PlayButton.d.ts +16 -0
- package/declaration/plugin/ControlBar/ProgressBar.d.ts +23 -0
- package/declaration/plugin/ControlBar/RangeControl.d.ts +27 -0
- package/declaration/plugin/ControlBar/VRButton.d.ts +12 -0
- package/declaration/plugin/ControlBar/VideoControl.d.ts +11 -0
- package/declaration/plugin/ControlBar/VideoTime.d.ts +17 -0
- package/declaration/plugin/ControlBar/VolumeControl.d.ts +23 -0
- package/declaration/plugin/ControlBar/const.d.ts +41 -0
- package/declaration/plugin/ControlBar/index.d.ts +11 -0
- package/declaration/plugin/LoadingSpinner/LoadingSpinner.d.ts +22 -0
- package/declaration/plugin/View360Plugin.d.ts +6 -0
- package/declaration/plugin/index.d.ts +5 -0
- package/declaration/projection/CorrectionPass.d.ts +26 -0
- package/declaration/projection/CubemapProjection.d.ts +19 -0
- package/declaration/projection/CubestripProjection.d.ts +18 -0
- package/declaration/projection/CylindricalProjection.d.ts +22 -0
- package/declaration/projection/EquiangularProjection.d.ts +13 -0
- package/declaration/projection/EquirectProjection.d.ts +15 -0
- package/declaration/projection/LittlePlanetProjection.d.ts +21 -0
- package/declaration/projection/Projection.d.ts +19 -0
- package/declaration/projection/StereoEquiProjection.d.ts +25 -0
- package/declaration/projection/WideAngleCorrectionProjection.d.ts +27 -0
- package/declaration/projection/WideAngleRealtimeProjection.d.ts +50 -0
- package/declaration/projection/index.d.ts +12 -0
- package/declaration/texture/Texture.d.ts +18 -0
- package/declaration/texture/Texture2D.d.ts +11 -0
- package/declaration/texture/TextureCube.d.ts +12 -0
- package/declaration/texture/TextureRenderTarget.d.ts +8 -0
- package/declaration/texture/TextureVideo.d.ts +11 -0
- package/declaration/type/events.d.ts +74 -0
- package/declaration/type/external.d.ts +13 -0
- package/declaration/type/internal.d.ts +47 -0
- package/declaration/type/utils.d.ts +11 -0
- package/declaration/uniform/Uniform.d.ts +7 -0
- package/declaration/uniform/UniformBoolean.d.ts +7 -0
- package/declaration/uniform/UniformCanvasCube.d.ts +12 -0
- package/declaration/uniform/UniformFloat.d.ts +7 -0
- package/declaration/uniform/UniformInt.d.ts +7 -0
- package/declaration/uniform/UniformMatrix.d.ts +8 -0
- package/declaration/uniform/UniformTexture2D.d.ts +11 -0
- package/declaration/uniform/UniformTextureCube.d.ts +12 -0
- package/declaration/uniform/UniformTextureRenderTarget.d.ts +11 -0
- package/declaration/uniform/UniformVec2.d.ts +7 -0
- package/declaration/uniform/UniformVec3.d.ts +7 -0
- package/declaration/uniform/UniformVector4Array.d.ts +7 -0
- package/declaration/utils.d.ts +25 -0
- package/dist/view360.cjs.js +9392 -0
- package/dist/view360.cjs.js.map +1 -0
- package/dist/view360.esm.js +9274 -0
- package/dist/view360.esm.js.map +1 -0
- package/dist/view360.js +9350 -0
- package/dist/view360.js.map +1 -0
- package/dist/view360.min.js +2 -0
- package/dist/view360.min.js.map +1 -0
- package/dist/view360.pkgd.js +48537 -0
- package/dist/view360.pkgd.js.map +1 -0
- package/dist/view360.pkgd.min.js +16 -0
- package/dist/view360.pkgd.min.js.map +1 -0
- package/package.json +110 -0
- package/sass/base.sass +17 -0
- package/sass/control-bar.sass +284 -0
- package/sass/helper.sass +51 -0
- package/sass/hotspot.sass +20 -0
- package/sass/loading-spinner.sass +34 -0
- package/sass/variable.sass +2 -0
- package/sass/view360.sass +6 -0
- package/sass/vr.sass +10 -0
- package/src/View360.ts +1220 -0
- package/src/cfc/const.ts +15 -0
- package/src/cfc/index.ts +8 -0
- package/src/cfc/utils.ts +12 -0
- package/src/cfc/withMethods.ts +40 -0
- package/src/const/browser.ts +109 -0
- package/src/const/error.ts +83 -0
- package/src/const/external.ts +77 -0
- package/src/const/internal.ts +53 -0
- package/src/control/CameraControl.ts +53 -0
- package/src/control/GyroControl.ts +225 -0
- package/src/control/PanoControl.ts +434 -0
- package/src/control/RotateControl.ts +411 -0
- package/src/control/ZoomControl.ts +254 -0
- package/src/control/index.ts +24 -0
- package/src/control/input/GyroInput.ts +315 -0
- package/src/control/input/KeyboardInput.ts +151 -0
- package/src/control/input/MouseInput.ts +102 -0
- package/src/control/input/PinchInput.ts +101 -0
- package/src/control/input/PointerInput.ts +118 -0
- package/src/control/input/TouchInput.ts +138 -0
- package/src/control/input/WheelInput.ts +89 -0
- package/src/core/AutoResizer.ts +92 -0
- package/src/core/Autoplay.ts +326 -0
- package/src/core/Camera.ts +616 -0
- package/src/core/CameraAnimation.ts +110 -0
- package/src/core/CameraPath.ts +454 -0
- package/src/core/CubeTexturePainter.ts +95 -0
- package/src/core/FrameAnimator.ts +69 -0
- package/src/core/Motion.ts +205 -0
- package/src/core/Object3D.ts +81 -0
- package/src/core/ShaderProgram.ts +21 -0
- package/src/core/TextureLoader.ts +303 -0
- package/src/core/TriangleMesh.ts +54 -0
- package/src/core/VertexArrayObject.ts +29 -0
- package/src/core/VertexData.ts +23 -0
- package/src/core/View360Error.ts +35 -0
- package/src/core/WebGLContext.ts +558 -0
- package/src/core/WebGLRenderer.ts +205 -0
- package/src/core/XRManager.ts +193 -0
- package/src/core/index.ts +35 -0
- package/src/geometry/CubeGeometry.ts +121 -0
- package/src/geometry/CylinderGeometry.ts +49 -0
- package/src/geometry/Geometry.ts +23 -0
- package/src/geometry/PlaneGeometry.ts +36 -0
- package/src/geometry/SphereGeometry.ts +55 -0
- package/src/hotspot/Hotspot.ts +32 -0
- package/src/hotspot/HotspotRenderer.ts +155 -0
- package/src/hotspot/index.ts +11 -0
- package/src/index.cjs.ts +13 -0
- package/src/index.ts +21 -0
- package/src/index.umd.ts +10 -0
- package/src/plugin/ControlBar/AutoHide.ts +246 -0
- package/src/plugin/ControlBar/ControlBar.ts +564 -0
- package/src/plugin/ControlBar/ControlBarItem.ts +84 -0
- package/src/plugin/ControlBar/FullscreenButton.ts +145 -0
- package/src/plugin/ControlBar/GyroButton.ts +124 -0
- package/src/plugin/ControlBar/PieView.ts +195 -0
- package/src/plugin/ControlBar/PlayButton.ts +130 -0
- package/src/plugin/ControlBar/ProgressBar.ts +175 -0
- package/src/plugin/ControlBar/RangeControl.ts +165 -0
- package/src/plugin/ControlBar/VRButton.ts +78 -0
- package/src/plugin/ControlBar/VideoControl.ts +79 -0
- package/src/plugin/ControlBar/VideoTime.ts +120 -0
- package/src/plugin/ControlBar/VolumeControl.ts +220 -0
- package/src/plugin/ControlBar/const.ts +72 -0
- package/src/plugin/ControlBar/index.ts +31 -0
- package/src/plugin/LoadingSpinner/LoadingSpinner.ts +116 -0
- package/src/plugin/View360Plugin.ts +30 -0
- package/src/plugin/index.ts +16 -0
- package/src/projection/CorrectionPass.ts +161 -0
- package/src/projection/CubemapProjection.ts +92 -0
- package/src/projection/CubestripProjection.ts +85 -0
- package/src/projection/CylindricalProjection.ts +123 -0
- package/src/projection/EquiangularProjection.ts +52 -0
- package/src/projection/EquirectProjection.ts +56 -0
- package/src/projection/LittlePlanetProjection.ts +82 -0
- package/src/projection/Projection.ts +103 -0
- package/src/projection/StereoEquiProjection.ts +104 -0
- package/src/projection/WideAngleCorrectionProjection.ts +307 -0
- package/src/projection/WideAngleRealtimeProjection.ts +653 -0
- package/src/projection/index.ts +36 -0
- package/src/shader/common.frag +7 -0
- package/src/shader/common.vert +12 -0
- package/src/shader/correction.frag +110 -0
- package/src/shader/cube.frag +8 -0
- package/src/shader/cube.vert +12 -0
- package/src/shader/eac.frag +40 -0
- package/src/shader/fullscreen.vert +7 -0
- package/src/shader/little-planet.frag +47 -0
- package/src/shader/little-planet.vert +12 -0
- package/src/shader/stereoequi.vert +15 -0
- package/src/shader/wideangle_realtime.frag +109 -0
- package/src/shader/wideangle_realtime.vert +17 -0
- package/src/shim.d.ts +9 -0
- package/src/texture/Texture.ts +47 -0
- package/src/texture/Texture2D.ts +34 -0
- package/src/texture/TextureCube.ts +36 -0
- package/src/texture/TextureRenderTarget.ts +33 -0
- package/src/texture/TextureVideo.ts +56 -0
- package/src/type/events.ts +389 -0
- package/src/type/external.ts +78 -0
- package/src/type/internal.ts +54 -0
- package/src/type/utils.ts +27 -0
- package/src/types/hls.d.ts +78 -0
- package/src/uniform/Uniform.ts +20 -0
- package/src/uniform/UniformBoolean.ts +23 -0
- package/src/uniform/UniformCanvasCube.ts +44 -0
- package/src/uniform/UniformFloat.ts +23 -0
- package/src/uniform/UniformInt.ts +25 -0
- package/src/uniform/UniformMatrix.ts +24 -0
- package/src/uniform/UniformTexture2D.ts +46 -0
- package/src/uniform/UniformTextureCube.ts +51 -0
- package/src/uniform/UniformTextureRenderTarget.ts +55 -0
- package/src/uniform/UniformVec2.ts +25 -0
- package/src/uniform/UniformVec3.ts +25 -0
- package/src/uniform/UniformVector4Array.ts +23 -0
- package/src/utils.ts +217 -0
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e(require("@egjs/component"),require("gl-matrix"),require("@egjs/imready"),require("hls.js")):"function"==typeof define&&define.amd?define(["@egjs/component","gl-matrix","@egjs/imready","hls.js"],e):(t="undefined"!=typeof globalThis?globalThis:t||self).View360=e(t.Component,t.glMatrix,t.eg.ImReady,t.Hls)}(this,(function(t,e,i,s){"use strict";function r(t){return t&&t.__esModule?t:{default:t}}var o=r(t),n=r(i),a=r(s);function h(t,e,i,s){return new(i||(i=Promise))((function(r,o){function n(t){try{h(s.next(t))}catch(t){o(t)}}function a(t){try{h(s.throw(t))}catch(t){o(t)}}function h(t){var e;t.done?r(t.value):(e=t.value,e instanceof i?e:new i((function(t){t(e)}))).then(n,a)}h((s=s.apply(t,e||[])).next())}))}class l extends Error{constructor(t,e){super(t),Object.setPrototypeOf(this,l.prototype),this.name="View360Error",this.code=e}}const u={WRONG_TYPE:0,WRONG_OPTION:1,ELEMENT_NOT_FOUND:2,CANVAS_NOT_FOUND:3,WEBGL_NOT_SUPPORTED:4,FAILED_CREATE_CONTEXT_2D:5,PROVIDE_PROJECTION_FIRST:6,FAILED_LINKING_PROGRAM:7,INSUFFICIENT_ARGS:8};var c=u,_={WRONG_TYPE:(t,e)=>`${typeof t} is not a ${e.map((t=>`"${t}"`)).join(" or ")}.`,WRONG_OPTION:(t,e)=>`Bad option: given "${t}" for option "${e}".`,ELEMENT_NOT_FOUND:t=>`Element with selector "${t}" not found.`,CANVAS_NOT_FOUND:"The canvas element was not found inside the given root element.",WEBGL_NOT_SUPPORTED:"WebGL is not supported on this browser.",FAILED_CREATE_CONTEXT_2D:"Failed to create canvas 2D context",PROVIDE_PROJECTION_FIRST:'"projection" should be provided before initialization.',FAILED_LINKING_PROGRAM:(t,e)=>`Failed linking WebGL program - "${t}\nShader compile Log: ${e}`,INSUFFICIENT_ARGS:(t,e)=>`Insufficient arguments: given "${t}" for "${e}".`};const d="mousedown",m="mousemove",g="mouseup",p="touchstart",v="touchmove",f="touchend",E="wheel",T="resize",b="contextmenu",R="mouseenter",y="mouseleave",x="keydown",w="keyup",C="click",L="webglcontextcreationerror",I="webglcontextlost",A="webglcontextrestored",O="deviceorientation",P="devicemotion",S="orientationchange",F="play",M="pause",N="loadeddata",U="volumechange",D="timeupdate",B="durationchange",V="canplaythrough",z="transitionend",G="end",H="div",Y="button";var W;!function(t){t[t.LEFT=0]="LEFT",t[t.MIDDLE=1]="MIDDLE",t[t.RIGHT=2]="RIGHT"}(W||(W={}));const k="grab",X="grabbing",j="",q=["LEFT","UP","RIGHT","DOWN"];var K;!function(t){t[t.LEFT=37]="LEFT",t[t.UP=38]="UP",t[t.RIGHT=39]="RIGHT",t[t.DOWN=40]="DOWN"}(K||(K={}));const Z={LEFT:"ArrowLeft",UP:"ArrowUp",RIGHT:"ArrowRight",DOWN:"ArrowDown"},$=["requestFullscreen","webkitRequestFullscreen","webkitRequestFullScreen","webkitCancelFullScreen","mozRequestFullScreen","msRequestFullscreen"],Q=["fullscreenElement","webkitFullscreenElement","webkitCurrentFullScreenElement","mozFullScreenElement","msFullscreenElement"],J=["exitFullscreen","webkitExitFullscreen","webkitCancelFullScreen","mozCancelFullScreen","msExitFullscreen"],tt=["fullscreenchange","webkitfullscreenchange","mozfullscreenchange","MSFullscreenChange"],et={CONTAINER:"view360-container",CANVAS:"view360-canvas",CTX_LOST:"view360-ctx-lost",IN_VR:"view360-vr-presenting",HOTSPOT_CONTAINER:"view360-hotspots",HOTSPOT:"view360-hotspot",HOTSPOT_VISIBLE:"view360-hotspot-visible",HOTSPOT_FLIP_X:"view360-hotspot-flip-x",HOTSPOT_FLIP_Y:"view360-hotspot-flip-y"},it={READY:"ready",LOAD_START:"loadStart",LOAD:"load",PROJECTION_CHANGE:"projectionChange",RESIZE:"resize",BEFORE_RENDER:"beforeRender",RENDER:"render",INPUT_START:"inputStart",INPUT_END:"inputEnd",VIEW_CHANGE:"viewChange",STATIC_CLICK:"staticClick",VR_START:"vrStart",VR_END:"vrEnd"},st={LINEAR:t=>t,SINE_WAVE:t=>Math.sin(t*Math.PI*2),EASE_OUT_CUBIC:t=>1-Math.pow(1-t,3),EASE_OUT_BOUNCE:t=>{const e=7.5625,i=2.75;return t<1/i?e*t*t:t<2/i?e*(t-=1.5/i)*t+.75:t<2.5/i?e*(t-=2.25/i)*t+.9375:e*(t-=2.625/i)*t+.984375}},rt="animationEnd",ot="update",nt="inputStart",at="change",ht="inputEnd",lt="enable",ut="disable",ct="staticClick",_t=Math.PI/180,dt=180/Math.PI,mt=st.EASE_OUT_CUBIC,gt=300,pt={min:-1/0,max:1/0},vt={min:-90,max:90},ft={min:.6,max:10};var Et;!function(t){t[t.ZERO=0]="ZERO",t[t.CW_90=1]="CW_90",t[t.CCW_90=2]="CCW_90",t[t.CW_180=3]="CW_180"}(Et||(Et={}));const Tt="view360videotimechange",bt="http://www.w3.org/2000/svg",Rt="immersive-vr",yt="local",xt=2220446049250313e-31,wt=t=>"string"==typeof t,Ct=(t,e=H)=>{const i=document.createElement(e);return i.classList.add(t),i},Lt=(t,e)=>{let i=null;if(wt(t)){const s=(e||document).querySelector(t);if(!s)return null;i=s}else(s=t)&&s.nodeType===Node.ELEMENT_NODE&&(i=t);var s;return i},It=(t,e,i)=>Math.max(Math.min(t,i),e),At=(t,e,i)=>t*(1-i)+e*i,Ot=(t,e,i)=>{const s=Math.abs(i-e);if(t<e){t=i-(e-t)%s}else if(t>i){t=e+(t-i)%s}return t},Pt=(t,e)=>{for(let i=0;i<t.length;i++)if(e(t[i]))return i;return-1},St=t=>"object"==typeof t?t:{},Ft=(t,e)=>2*Math.atan(Math.tan(.5*t)/e),Mt=(t,e,i="RLUDFB")=>i.split("").map((t=>e.indexOf(t))).map((e=>t[e])),Nt=()=>{if(!document)return!1;for(const t of Q)if(document[t])return!0;return!1},Ut=()=>{const t=window.location.hostname;return("https:"===window.location.protocol||"localhost"===t||"127.0.0.1"===t||"[::1]"===t)&&!!DeviceMotionEvent&&"requestPermission"in DeviceMotionEvent},Dt=(t,e)=>Math.tan(_t*t*.5)/Math.tan(_t*e*.5),Bt=(t,i,s,r)=>{e.quat.identity(t);const o=It(s,-89.99,89.99);return e.quat.rotateY(t,t,i*_t),e.quat.rotateX(t,t,o*_t),e.quat.rotateZ(t,t,r*_t),t},Vt=t=>{const i=t[0],s=t[1],r=t[2],o=t[3],n=i*i+s*s+r*r+o*o,a=i*o-s*r;let h,l;if(a>.499995*n)h=Math.PI/2,l=2*Math.atan2(s,i);else if(a<-.499995*n)h=-Math.PI/2,l=-2*Math.atan2(s,i);else{const i=e.vec3.fromValues(0,0,1),s=e.vec3.fromValues(0,1,0);e.vec3.transformQuat(i,i,t),e.vec3.transformQuat(s,s,t);const r=Math.sqrt(i[0]*i[0]+i[2]*i[2]);h=Math.atan2(-i[1],r),l=Math.atan2(i[0],i[2])}return{pitch:It(h*dt,-90,90),yaw:Ot(l*dt,0,360)}};class zt{get val(){return this._val}get start(){return this._start}get end(){return this._end}get progress(){return this._progress}get activated(){return this._activated}get duration(){return this._duration}set duration(t){this._duration=t}get loop(){return this._loop}set loop(t){this._loop=t}get range(){return this._range}get easing(){return this._easing}set easing(t){this._easing=t}constructor({duration:t=300,loop:e=!1,range:i={min:0,max:1},easing:s=mt}={}){this._duration=t,this._loop=e,this._range=i,this._easing=s,this._activated=!1,this.reset(0)}update(t){if(!this._activated)return this._val=this._end,0;const e=this._start,i=this._end,s=this._duration,r=this._val,o=this._loop,n=this._progress+t/s;this._progress=o?Ot(n,0,1):It(n,0,1);const a=this._easing(this._progress);return this._val=At(e,i,a),!o&&this._progress>=1&&(this._activated=!1),this._val-r}reset(t){const e=this._range,i=It(t,e.min,e.max);this._start=i,this._end=i,this._val=i,this._progress=0,this._activated=!1}add(t){const e=this._range;this._start=It(this._start+t,e.min,e.max),this._end=It(this._end+t,e.min,e.max),this._val=It(this._val+t,e.min,e.max)}setNewEndByDelta(t){const e=this._range;this._start=this._val,this._end=It(this._end+t,e.min,e.max),this._progress=0,this._activated=!0}setRange(t,e){this._start=It(this._start,t,e),this._end=It(this._end,t,e),this._range={min:t,max:e}}}class Gt{get duration(){return this._motion.duration}set duration(t){this._motion.duration=t}get easing(){return this._motion.easing}set easing(t){this._motion.easing=t}constructor(t,e,i,{duration:s=300,easing:r=mt}={}){this._camera=t,this._motion=new zt({duration:s,easing:r,range:{min:0,max:1}}),this._from=e,this._to=i,this._finishPromise=new Promise((t=>{this._finish=t})),this._motion.setNewEndByDelta(1)}getFinishPromise(){return this._finishPromise}update(t){const i=this._camera,s=this._from,r=this._to,o=this._motion;o.update(t);const n=o.val,a=e.quat.create(),h=At(s.zoom,r.zoom,n);e.quat.slerp(a,s.rotation,r.rotation,n),i.rotate(a,h),n>=1&&this._finish()}}class Ht extends o.default{get aspect(){return this._aspect}get changed(){return this._changed}get yawRange(){return this._initialYawRange}set yawRange(t){this._initialYawRange=t}get pitchRange(){return this._initialPitchRange}set pitchRange(t){this._initialPitchRange=t}get zoomRange(){return this._initialZoomRange}set zoomRange(t){this._initialZoomRange=t}constructor({initialYaw:t,initialPitch:i,initialZoom:s,yawRange:r,pitchRange:o,zoomRange:n,fov:a}){super(),this.yaw=t,this.pitch=i,this.zoom=s,this.rollOffset=0,this.initialYaw=t,this.initialPitch=i,this.initialZoom=s,this.position=e.vec3.create(),this.animation=null,this._up=e.vec3.fromValues(0,1,0),this._aspect=1,this._initialYawRange=r,this._initialPitchRange=o,this._initialZoomRange=n,this._yawRange=r,this._pitchRange=o,this._zoomRange=n,this.quaternion=e.quat.create(),this._updateQuaternion(),this.viewMatrix=e.mat4.create(),this.projectionMatrix=e.mat4.create(),this.fov=a,this._maxRenderHeight=-1}destroy(){this.off()}resize(t,e){const i=this._aspect;this._aspect=t/e,this._aspect!==i&&this.updateMatrix()}lookAt({yaw:t=this.yaw,pitch:i=this.pitch,zoom:s=this.zoom}){const r=e.quat.clone(this.quaternion),o=this.zoom;this.yaw=Ot(t,0,360),this.pitch=It(i,-90,90),this.zoom=s,this._updateQuaternion();const n=Math.abs(s-o);(!e.quat.equals(this.quaternion,r)||n>=10*xt)&&this.updateMatrix()}rotate(t,i=this.zoom){const s=e.quat.normalize(e.quat.create(),t),r=e.quat.equals(this.quaternion,s);e.quat.copy(this.quaternion,s);const o=this.zoom,{yaw:n,pitch:a}=Vt(s);this.yaw=n,this.pitch=a,this.zoom=i;const h=Math.abs(i-o);(!r||h>=10*xt)&&this.updateMatrix()}animateTo({yaw:t=this.yaw,pitch:i=this.pitch,zoom:s=this.zoom,duration:r=0,easing:o=mt}={}){return h(this,void 0,void 0,(function*(){if(this.yaw===t&&this.pitch===i&&this.zoom===s)return;const n={rotation:e.quat.clone(this.quaternion),zoom:this.zoom},a={rotation:Bt(e.quat.create(),t,i,this.rollOffset),zoom:s},h=new Gt(this,n,a,{duration:r,easing:o}),l=h.getFinishPromise();return this.animation=h,l.then((()=>{this.animation=null,this.trigger(rt,{animation:h})})),l}))}restrictYawRange(t,e){this._yawRange={min:t,max:e}}restrictPitchRange(t,e){this._pitchRange={min:t,max:e}}restrictZoomRange(t,e){this._zoomRange={min:t,max:e}}restrictRenderHeight(t){this._maxRenderHeight=t}resetRange(){this._yawRange=this._initialYawRange,this._pitchRange=this._initialPitchRange,this._zoomRange=this._initialZoomRange,this._maxRenderHeight=-1}getYawRange(t){const e=this._yawRange,i=this._maxRenderHeight;if(!e)return pt;const s=.5*this.getHorizontalFov(t);let r=e.min,o=e.max;if(i>0){const t=Ft(s*_t,this._aspect),n=.5*i,a=Math.tan(t),h=Math.sqrt((1+n*n)/(1+a*a)),l=Math.atan(Math.tan(s*_t)*h)*dt;r=e.min+l,o=e.max-l}return r>o&&(r=0,o=0),{min:r,max:o}}getPitchRange(t){const e=this._pitchRange,i=this._maxRenderHeight;if(!e)return vt;let s=e.min,r=e.max;if(i>0){const i=.5*this.getVerticalFov(t);s=e.min+i,r=e.max-i}return s>r&&(s=0,r=0),{min:Math.max(s,-90),max:Math.min(r,90)}}getZoomRange(){var t;const e=null!==(t=this._zoomRange)&&void 0!==t?t:ft,i=this.getHorizontalFov(e.max),s=this.getHorizontalFov(e.min),r=this.getHorizontalFov(this.zoom);return{min:Math.max(i,1),max:Math.min(s,180),current:r}}getHorizontalFov(t=this.zoom){return this._getZoomedHorizontalFov(t)*dt}getVerticalFov(t=this.zoom){const e=this._aspect,i=this._getZoomedHorizontalFov(t);return Ft(i,e)*dt}fovToZoom(t){const e=this.fov;return Math.tan(_t*e*.5)/Math.tan(_t*t*.5)}updateMatrix(){const t=this._up,i=this._aspect,s=this.viewMatrix,r=this.projectionMatrix,o=this.position,n=this.quaternion,a=e.vec3.create(),h=e.vec3.fromValues(0,0,-1);e.vec3.transformQuat(h,h,n),e.vec3.transformQuat(a,t,n);const l=this._getZoomedHorizontalFov(),u=Ft(l,i);e.mat4.lookAt(s,o,h,a),e.mat4.perspective(r,u,i,.1,100),this._changed=!0}onFrameRender(){this._changed=!1}_updateQuaternion(){Bt(this.quaternion,this.yaw,this.pitch,this.rollOffset)}_getZoomedHorizontalFov(t=this.zoom){return 2*Math.atan(Math.tan(_t*this.fov*.5)/t)}}class Yt extends o.default{constructor(){super(),this._onMouseDown=t=>{const e=this._el;e&&t.button===W.LEFT&&(t.preventDefault(),e.focus?e.focus():window.focus(),this._prevPos[0]=t.clientX,this._prevPos[1]=t.clientY,window.addEventListener(m,this._onMouseMove,!1),window.addEventListener(g,this._onMouseUp,!1),this.trigger(nt,{srcEvent:t,isTouch:!1,isKeyboard:!1}))},this._onMouseMove=t=>{t.preventDefault();const e=t.clientX,i=t.clientY,s=this._prevPos,r=e-s[0],o=i-s[1];this.trigger(at,{delta:{x:r,y:o},isTouch:!1,isKeyboard:!1}),s[0]=e,s[1]=i},this._onMouseUp=()=>{this._prevPos[0]=0,this._prevPos[1]=0,window.removeEventListener(m,this._onMouseMove,!1),window.removeEventListener(g,this._onMouseUp,!1),this.trigger(ht,{isTouch:!1,isKeyboard:!1,scrolling:!1})},this._el=null,this._prevPos=[0,0]}enable(t){this._el||(t.addEventListener(d,this._onMouseDown),this._el=t)}disable(){const t=this._el;t&&(t.removeEventListener(d,this._onMouseDown),window.removeEventListener(m,this._onMouseMove,!1),window.removeEventListener(g,this._onMouseUp,!1),this._el=null)}}class Wt extends o.default{get scrollable(){return this._scrollable}set scrollable(t){this._scrollable=t}constructor(){super(),this._onTouchStart=t=>{if(t.touches.length>1||this._scrolling)return;const e=t.touches[0];this._isFirstTouch=!0,this._prevPos[0]=e.clientX,this._prevPos[1]=e.clientY,this.trigger(nt,{srcEvent:t,isTouch:!0,isKeyboard:!1})},this._onTouchMove=t=>{if(t.touches.length>1||this._scrolling)return;const e=t.touches[0],i=this._scrollable,s=this._prevPos,r=e.clientX,o=e.clientY,n=r-s[0],a=o-s[1];if(this._isFirstTouch){if(i&&!Nt()&&Math.abs(a)>Math.abs(n))return void(this._scrolling=!0);this._isFirstTouch=!1}!1!==t.cancelable&&t.preventDefault(),this.trigger(at,{delta:{x:n,y:a},isTouch:!0,isKeyboard:!1}),s[0]=r,s[1]=o},this._onTouchEnd=t=>{if(0!==t.touches.length)return;const e=t.touches[0],i=this._prevPos;e?(i[0]=e.clientX,i[1]=e.clientY):(i[0]=0,i[1]=0,this.trigger(ht,{isTouch:!0,isKeyboard:!1,scrolling:this._scrolling})),!1!==t.cancelable&&t.preventDefault(),this._scrolling=!1},this._el=null,this._prevPos=[0,0],this._isFirstTouch=!1,this._scrolling=!1,this._scrollable=!1}enable(t){this._el||(t.addEventListener(p,this._onTouchStart,{passive:!1}),t.addEventListener(v,this._onTouchMove,{passive:!1}),t.addEventListener(f,this._onTouchEnd),this._el=t)}disable(){const t=this._el;t&&(t.removeEventListener(p,this._onTouchStart),t.removeEventListener(v,this._onTouchMove),t.removeEventListener(f,this._onTouchEnd),this._el=null)}}class kt extends o.default{get active(){const t=this._pressed;return t.LEFT||t.UP||t.RIGHT||t.DOWN}constructor(){super(),this._onKeyDown=t=>{if(t.location!==KeyboardEvent.DOM_KEY_LOCATION_STANDARD)return;this._updateKeyPress(t,!0);const e=this._getPressedKeyCount();e<=0||(t.preventDefault(),1!==e||t.repeat||this.trigger(nt,{srcEvent:t,isTouch:!1,isKeyboard:!0}))},this._onKeyUp=t=>{if(t.location!==KeyboardEvent.DOM_KEY_LOCATION_STANDARD)return;this._updateKeyPress(t,!1);this._getPressedKeyCount()>0||this.trigger(ht,{isTouch:!1,isKeyboard:!0,scrolling:!1})},this._el=null,this._clearPressedKeys()}enable(t){this._el||(t.addEventListener(x,this._onKeyDown),t.addEventListener(w,this._onKeyUp),this._el=t,this._clearPressedKeys())}disable(){const t=this._el;t&&(t.removeEventListener(x,this._onKeyDown),t.removeEventListener(w,this._onKeyUp),this._el=null,this._clearPressedKeys())}update(){const t=this._getDeltaByPressedKeys();0===t.x&&0===t.y||this.trigger(at,{delta:t,isTouch:!1,isKeyboard:!0})}_clearPressedKeys(){this._pressed=q.reduce(((t,e)=>Object.assign(Object.assign({},t),{[e]:!1})),{})}_updateKeyPress(t,e){const i=this._pressed,s=null!=t.keyCode?K[t.keyCode]:Z[t.key];s&&(i[s]=e)}_getPressedKeyCount(){return q.filter((t=>this._pressed[t])).length}_getDeltaByPressedKeys(){const t=this._pressed;let e=0,i=0;return t.LEFT&&(e+=1),t.RIGHT&&(e-=1),t.UP&&(i+=1),t.DOWN&&(i-=1),{x:e,y:i}}}class Xt extends o.default{get enabled(){return this._enabled}get enableBlocked(){return this._enableBlocked}get animating(){return this._keyboardInput.active||this._xMotion.activated||this._yMotion.activated}get yaw(){return this._xMotion}get pitch(){return this._yMotion}get scrollable(){return this._touchInput.scrollable}set scrollable(t){this._touchInput.scrollable=t}get pointerScale(){return this._pointerScale}set pointerScale(t){this._pointerScale=t}get keyboardScale(){return this._keyboardScale}set keyboardScale(t){this._keyboardScale=t}get duration(){return this._duration}set duration(t){this._duration=t,this._xMotion.duration=t,this._yMotion.duration=t}get easing(){return this._easing}set easing(t){this._easing=t,this._xMotion.easing=t,this._yMotion.easing=t}get disablePitch(){return this._disablePitch}set disablePitch(t){this._disablePitch=t}get disableYaw(){return this._disableYaw}set disableYaw(t){this._disableYaw=t}get disableKeyboard(){return this._disableKeyboard}set disableKeyboard(t){this._disableKeyboard=t}constructor(t,e,{duration:i=300,easing:s=mt,pointerScale:r=[1,1],keyboardScale:o=[1,1],disablePitch:n=!1,disableYaw:a=!1,disableKeyboard:h=!1}={}){super(),this._onInputStart=t=>{this._changedWhileDragging=!1,this.trigger(nt,Object.assign(Object.assign({},t),{inputType:"rotate"}))},this._onChange=t=>{const e=t.delta,i=1/this._zoomScale,s=this._screenScale,r=this._keyboardScale,o=this._pointerScale;let n;n=t.isKeyboard?[r[0]*i,r[1]*i]:[o[0]*s[0]*i,o[1]*s[1]*i];const a=e.x*n[0],h=e.y*n[1];this._xMotion.setNewEndByDelta(a),this._yMotion.setNewEndByDelta(h),this._changedWhileDragging=!0},this._onInputEnd=t=>{this.trigger(ht,Object.assign(Object.assign({},t),{inputType:"rotate"})),this._changedWhileDragging||t.isKeyboard||t.scrolling||this.trigger(ct,{isTouch:t.isTouch}),this._changedWhileDragging=!1},this._controlEl=t,this._pointerScale=r,this._keyboardScale=o,this._duration=i,this._easing=s,this._disablePitch=n,this._disableYaw=a,this._disableKeyboard=h,this._enableBlocked=e,this._mouseInput=new Yt,this._touchInput=new Wt,this._keyboardInput=new kt,this._xMotion=new zt({duration:i,range:pt,easing:s}),this._yMotion=new zt({duration:i,range:vt,easing:s}),this._screenScale=[1,1],this._zoomScale=1,this._enabled=!1,this._changedWhileDragging=!1,this._bindInputs()}destroy(){this.disable(),this._mouseInput.off(),this._touchInput.off(),this._keyboardInput.off(),this.off(),this._changedWhileDragging=!1}update(t){if(!this._enabled)return;const e=this._xMotion,i=this._yMotion,s=this._keyboardInput;this._disableKeyboard||s.update(),this._disablePitch||i.update(t),this._disableYaw||e.update(t)}updateByCameraPath(t){this._xMotion.update(t),this._yMotion.update(t)}updateRange(t,e){const i=t.getYawRange(e),s=t.getPitchRange(e);this._xMotion.setRange(i.min,i.max),this._yMotion.setRange(s.min,s.max)}setZoomScale(t){this._zoomScale=t}resize(t,e,i,s){const r=Ft(t*_t,e)*dt;this._screenScale[0]=t/i,this._screenScale[1]=r/s}enable(){if(this._enabled)return;const t=this._controlEl;this._mouseInput.enable(t),this._touchInput.enable(t),this._keyboardInput.enable(t),this._enabled=!0,this._enableBlocked=!1,this.trigger(lt,{control:this,updateCursor:!0})}disable(){this._enabled&&(this._mouseInput.disable(),this._touchInput.disable(),this._keyboardInput.disable(),this._enabled=!1,this.trigger(ut,{updateCursor:!0}))}sync(t){this.updateRange(t,t.zoom),this._xMotion.reset(t.yaw),this._yMotion.reset(t.pitch)}_bindInputs(){const t=this._mouseInput,e=this._touchInput,i=this._keyboardInput;t.on(nt,this._onInputStart),t.on(at,this._onChange),t.on(ht,this._onInputEnd),e.on(nt,this._onInputStart),e.on(at,this._onChange),e.on(ht,this._onInputEnd),i.on(nt,this._onInputStart),i.on(at,this._onChange),i.on(ht,this._onInputEnd)}}class jt extends o.default{get scrollable(){return this._scrollable}set scrollable(t){this._scrollable=t}constructor(){super(),this._onWheel=t=>{const e=this._scrollable;if(0===t.deltaY||e)return;t.preventDefault(),t.stopPropagation(),this._inputTimer<0?this.trigger(nt,{srcEvent:t,isTouch:!1,isKeyboard:!1}):this._clearTimer();const i=this._baseScale*t.deltaY;this.trigger(at,{delta:i,isTouch:!1,isKeyboard:!1}),this._inputTimer=window.setTimeout((()=>{this.trigger(ht,{isTouch:!1,isKeyboard:!1,scrolling:!1}),this._inputTimer=-1}),gt)},this._el=null,this._baseScale=.04,this._scrollable=!1,this._inputTimer=-1}enable(t){this._el||(t.addEventListener(E,this._onWheel,{passive:!1,capture:!1}),this._el=t,this._clearTimer())}disable(){const t=this._el;t&&(t.removeEventListener(E,this._onWheel,!1),this._el=null,this._clearTimer())}_clearTimer(){window.clearTimeout(this._inputTimer),this._inputTimer=-1}}class qt extends o.default{constructor(){super(),this._onTouchMove=t=>{const e=t.touches;if(2!==e.length)return;if(!t.cancelable)return;t.preventDefault(),t.stopPropagation();const i=this._prevDistance,s=[e[0].pageX-e[1].pageX,e[0].pageY-e[1].pageY],r=Math.sqrt(s[0]*s[0]+s[1]*s[1])*this._baseScale,o=this._isFirstTouch?0:r-i;this._isFirstTouch&&this.trigger(nt,{srcEvent:t,isTouch:!0,isKeyboard:!1}),this._prevDistance=r,this._isFirstTouch=!1,this.trigger(at,{delta:o,isTouch:!0,isKeyboard:!1})},this._onTouchEnd=t=>{0===t.touches.length&&(this._isFirstTouch||this.trigger(ht,{isTouch:!0,isKeyboard:!1,scrolling:!1}),this._prevDistance=-1,this._isFirstTouch=!0)},this._el=null,this._baseScale=-.2,this._prevDistance=-1,this._isFirstTouch=!0}enable(t){this._el||(t.addEventListener(v,this._onTouchMove,{passive:!1,capture:!1}),t.addEventListener(f,this._onTouchEnd),this._el=t,this._prevDistance=-1,this._isFirstTouch=!0)}disable(){const t=this._el;t&&(t.removeEventListener(v,this._onTouchMove,!1),t.removeEventListener(f,this._onTouchEnd),this._el=null)}}class Kt extends o.default{constructor(t,e,{scale:i=1,duration:s=300,easing:r=mt}={}){super(),this._onInputStart=t=>{this.trigger(nt,Object.assign(Object.assign({},t),{inputType:"zoom"}))},this._onChange=({delta:t})=>{const e=t*this._scale;this._motion.setNewEndByDelta(e)},this._onInputEnd=t=>{this.trigger(ht,Object.assign(Object.assign({},t),{inputType:"zoom"}))},this._scale=i,this._controlEl=t,this._enableBlocked=e,this._wheelInput=new jt,this._pinchInput=new qt,this._motion=new zt({duration:s,easing:r,range:pt}),this._enabled=!1,this._bindInputs()}get enabled(){return this._enabled}get enableBlocked(){return this._enableBlocked}get animating(){return this._motion.activated}get zoom(){return this._motion.val}get end(){return this._motion.end}get scrollable(){return this._wheelInput.scrollable}set scrollable(t){this._wheelInput.scrollable=t}get range(){return this._motion.range}setNewEndByDelta(t){this._motion.setNewEndByDelta(t)}reset(t){this._motion.reset(t)}get scale(){return this._scale}set scale(t){this._scale=t}get duration(){return this._motion.duration}get easing(){return this._motion.easing}destroy(){this.disable(),this._wheelInput.off(),this._pinchInput.off(),this.off()}update(t){if(!this._enabled)return;this._motion.update(t)}updateByCameraPath(t){this._motion.update(t)}enable(){if(this._enabled)return;const t=this._controlEl;this._wheelInput.enable(t),this._pinchInput.enable(t),this._enabled=!0,this._enableBlocked=!1,this.trigger(lt,{control:this,updateCursor:!1})}disable(){this._enabled&&(this._wheelInput.disable(),this._pinchInput.disable(),this._enabled=!1,this.trigger(ut,{updateCursor:!1}))}sync(t){const e=this._motion,i=t.getZoomRange();e.setRange(i.min,i.max),e.reset(i.current)}_bindInputs(){const t=this._wheelInput,e=this._pinchInput;t.on(nt,this._onInputStart),t.on(at,this._onChange),t.on(ht,this._onInputEnd),e.on(nt,this._onInputStart),e.on(at,this._onChange),e.on(ht,this._onInputEnd)}}const Zt={PITCH_DELTA:1,YAW_DELTA_BY_ROLL:2,YAW_DELTA_BY_YAW:3};Zt[Zt.PITCH_DELTA]={targetAxis:[0,1,0],meshPoint:[0,0,1]},Zt[Zt.YAW_DELTA_BY_ROLL]={targetAxis:[0,1,0],meshPoint:[1,0,0]},Zt[Zt.YAW_DELTA_BY_YAW]={targetAxis:[1,0,0],meshPoint:[0,0,1]};class $t extends o.default{get enabled(){return this._enabled}get orientationUpdated(){return this._orientationUpdated}get ignoreRoll(){return this._ignoreRoll}set ignoreRoll(t){this._ignoreRoll=t}constructor(){super(),this._onDeviceOrientation=t=>{const e=this._orientation,{alpha:i,beta:s,gamma:r}=t;null!=i&&null!=s&&null!=r&&(e.alpha=i,e.beta=s,e.gamma=r,this._orientationUpdated=!0,this._needsCalibrate&&(this._needsCalibrate=!1,this._calibrateSensor()))},this._updateScreenOrientation=()=>{window.screen&&window.screen.orientation&&void 0!==window.screen.orientation.angle?this._screenOrientation=screen.orientation.angle:void 0!==window.orientation?this._screenOrientation=window.orientation>=0?window.orientation:360+window.orientation:this._screenOrientation=0},this.quaternion=e.quat.create(),this._orientation={alpha:0,beta:90,gamma:0},this._yawOrigin=0,this._yawOffset=0,this._orientationUpdated=!1,this._screenOrientation=0,this._needsCalibrate=!0,this._enabled=!1}enable(){this._enabled||(window.addEventListener(O,this._onDeviceOrientation),window.addEventListener(S,this._updateScreenOrientation),this._updateScreenOrientation(),this._orientationUpdated=!1,this._needsCalibrate=!0,this._enabled=!0)}disable(){this._enabled&&(window.removeEventListener(O,this._onDeviceOrientation),window.removeEventListener(S,this._updateScreenOrientation),this._enabled=!1)}update(){this._updateRotation(),this._orientationUpdated=!1}collectDelta(){if(!this._orientationUpdated)return{pitch:0,yaw:0};const t=e.quat.clone(this.quaternion);return this._updateRotation(),this._orientationUpdated=!1,this._toEulerDelta(t,this.quaternion)}setInitialRotation(t){this._yawOrigin=t}_calibrateSensor(){const t=this._yawOrigin,e=this.quaternion;this._yawOffset=0,this._updateRotation();const{yaw:i}=Vt(e);this._yawOffset=i-t,this._updateRotation(),this._needsCalibrate=!1}_updateRotation(){const t=this.quaternion,{alpha:i,beta:s,gamma:r}=this._orientation;e.quat.identity(t),e.quat.rotateY(t,t,(i-this._yawOffset)*_t),e.quat.rotateX(t,t,s*_t),e.quat.rotateZ(t,t,-r*_t);const o=e.quat.create(),n=.5*-this._screenOrientation*_t,a=e.quat.fromValues(-Math.sqrt(.5),0,0,Math.sqrt(.5));e.quat.set(o,0,Math.sin(n),0,Math.cos(n)),e.quat.multiply(t,t,o),e.quat.multiply(t,t,a),e.quat.normalize(t,t)}_toEulerDelta(t,e){return{yaw:this._getDeltaYaw(t,e),pitch:this._getDeltaPitch(t,e)}}_getDeltaYaw(t,e){const i=this._getRotationDelta(t,e,Zt.YAW_DELTA_BY_YAW);return this._getRotationDelta(t,e,Zt.YAW_DELTA_BY_ROLL)*Math.sin(this._extractPitchFromQuat(e))+i}_getDeltaPitch(t,e){return this._getRotationDelta(t,e,Zt.PITCH_DELTA)}_getRotationDelta(t,i,s){const r=e.vec3.fromValues(Zt[s].targetAxis[0],Zt[s].targetAxis[1],Zt[s].targetAxis[2]),o=Zt[s].meshPoint,n=e.quat.clone(t),a=e.quat.clone(i);e.quat.normalize(n,n),e.quat.normalize(a,a);let h=e.vec3.fromValues(0,0,1),l=e.vec3.fromValues(0,0,1);e.vec3.transformQuat(h,h,n),e.vec3.transformQuat(l,l,a),e.vec3.transformQuat(r,r,a);const u=e.vec3.dot(r,e.vec3.cross(e.vec3.create(),h,l))>0?1:-1,c=e.vec3.fromValues(o[0],o[1],o[2]);let _;_=s!==Zt.YAW_DELTA_BY_YAW?e.vec3.fromValues(0,u,0):e.vec3.fromValues(u,0,0),e.vec3.transformQuat(c,c,a),e.vec3.transformQuat(_,_,a);const d=c,m=_,g=e.vec3.create();e.vec3.cross(g,d,m),e.vec3.normalize(g,g);const p=g[0],v=g[1],f=g[2];l=e.vec3.fromValues(o[0],o[1],o[2]),e.vec3.transformQuat(l,l,a),h=e.vec3.fromValues(o[0],o[1],o[2]),e.vec3.transformQuat(h,h,n);let E=Math.abs(h[0]*p+h[1]*v+h[2]*f);const T=e.vec3.create();e.vec3.subtract(T,h,e.vec3.scale(e.vec3.create(),g,E));let b=(T[0]*l[0]+T[1]*l[1]+T[2]*l[2])/(e.vec3.length(T)*e.vec3.length(l));b>1&&(b=1);const R=Math.acos(b),y=e.vec3.cross(e.vec3.create(),l,T);let x;E=p*y[0]+v*y[1]+f*y[2],x=s!==Zt.YAW_DELTA_BY_YAW?E>0?1:-1:E<0?1:-1;return R*x*u*dt}_extractPitchFromQuat(t){const i=e.vec3.fromValues(0,0,1);return e.vec3.transformQuat(i,i,t),-1*Math.atan2(i[1],Math.sqrt(Math.pow(i[0],2)+Math.pow(i[2],2)))}}class Qt extends o.default{get enabled(){return this._input.enabled}get enableBlocked(){return this._enableBlocked}get animating(){return this._input.enabled&&this._input.orientationUpdated}get ignoreRoll(){return this._ignoreRoll}set ignoreRoll(t){this._ignoreRoll=t}static isAvailable(){return h(this,void 0,void 0,(function*(){if(!DeviceMotionEvent)return!1;let t;return Promise.race([new Promise((e=>{t=t=>{e(t.rotationRate&&null!=t.rotationRate.alpha)},window.addEventListener(P,t)})),new Promise((t=>{setTimeout((()=>t(!1)),1e3)}))]).then((e=>(window.removeEventListener(P,t),e)))}))}static requestSensorPermission(){return h(this,void 0,void 0,(function*(){return!Ut()||DeviceMotionEvent.requestPermission().then((t=>"granted"===t)).catch((()=>!1))}))}constructor(t,{ignoreRoll:e=!0}={}){super(),this._enableBlocked=t,this._ignoreRoll=e,this._input=new $t}destroy(){this.disable(),this._input.off(),this.off()}update(t,e,i,s){this._ignoreRoll?this._updateYawPitch(t,e,i,s):this._updateQuaternion(t,s)}enable(){this._input.enabled||(this._input.enable(),this._enableBlocked=!1,this.trigger(lt,{control:this,updateCursor:!1}))}disable(){this._input.enabled&&(this._input.disable(),this.trigger(ut,{updateCursor:!1}))}sync(){}_updateYawPitch(t,e,i,s){const r=this._input;if(!r.enabled)return;const{yaw:o,pitch:n}=r.collectDelta();e.add(o),i.add(n),t.lookAt({yaw:e.val,pitch:i.val,zoom:s})}_updateQuaternion(t,e){const i=this._input;i.enabled&&(i.update(),t.rotate(i.quaternion,e))}}class Jt{get useGrabCursor(){return this._useGrabCursor}set useGrabCursor(t){t!==this._useGrabCursor&&(this._useGrabCursor=t,t&&this._enabled?this._setCursor(k):t||this._setCursor(j))}get disableContextMenu(){return this._disableContextMenu}set disableContextMenu(t){t!==this._disableContextMenu&&(this._disableContextMenu=t,t&&this._enabled?this._blockContextMenu():t||this._restoreContextMenu())}get scrollable(){return this._rotateControl.scrollable}set scrollable(t){this._rotateControl.scrollable=t}get wheelScrollable(){return this._zoomControl.scrollable}set wheelScrollable(t){this._zoomControl.scrollable=t}get ignoreZoomScale(){return this._ignoreZoomScale}set ignoreZoomScale(t){this._ignoreZoomScale=t}get enabled(){return this._enabled}get rotate(){return this._rotateControl}get zoom(){return this._zoomControl}get gyro(){return this._gyroControl}get animating(){return this._rotateControl.animating||this._zoomControl.animating||this._gyroControl.animating}constructor(t,e,{useGrabCursor:i,scrollable:s,wheelScrollable:r,disableContextMenu:o,rotate:n,zoom:a,gyro:h}){this._preventContextMenu=t=>{t.preventDefault()},this._onInputStart=t=>{this._useGrabCursor&&!t.isKeyboard&&this._setCursor(X)},this._onInputEnd=t=>{this._useGrabCursor&&!t.isKeyboard&&this._setCursor(k)},this._onEnable=({control:t,updateCursor:e})=>{e&&this._useGrabCursor&&this._setCursor(k),t.sync(this._camera)},this._onDisable=({updateCursor:t})=>{t&&this._setCursor(j)},this._onCameraAnimationEnd=({animation:t})=>{t.getFinishPromise().then((()=>{this.sync()}))},this._useGrabCursor=i,this._disableContextMenu=o,this._camera=e,this._controlEl=t,this._ignoreZoomScale=!1,this._enabled=!1,this._rotateControl=new Xt(t,!n,St(n)),this._zoomControl=new Kt(t,!a,St(a)),this._gyroControl=new Qt(!h,St(h)),this._rotateControl.scrollable=s,this._zoomControl.scrollable=r,this._bindEvents()}destroy(){this.disable(),this._rotateControl.destroy(),this._zoomControl.destroy(),this._setCursor(j)}resize(t,e){const i=this._camera;this._rotateControl.resize(i.fov,i.aspect,t,e)}enable(){return h(this,void 0,void 0,(function*(){this._enabled||(this._rotateControl.enableBlocked||this._rotateControl.enable(),this._zoomControl.enableBlocked||this._zoomControl.enable(),this._gyroControl.enableBlocked||(yield Qt.isAvailable())&&this._gyroControl.enable(),this.sync(),this._disableContextMenu&&this._blockContextMenu(),this._enabled=!0)}))}disable(){this._enabled&&(this._rotateControl.disable(),this._zoomControl.disable(),this._gyroControl.disable(),this._restoreContextMenu(),this._enabled=!1)}update(t){const e=this._camera,i=this._rotateControl,s=this._zoomControl,r=this._gyroControl;s.update(t);const o=Dt(e.fov,s.zoom),n=this._ignoreZoomScale?1:Math.max(o,1);i.setZoomScale(n),i.updateRange(e,o),i.update(t);const a=i.yaw,h=i.pitch;r.enabled?r.update(e,a,h,o):e.lookAt({yaw:a.val,pitch:h.val,zoom:o})}updateByCameraPath(t){const e=this._camera,i=this._rotateControl,s=this._zoomControl,r=this._gyroControl;s.updateByCameraPath(t);const o=Dt(e.fov,s.zoom),n=this._ignoreZoomScale?1:Math.max(o,1);i.setZoomScale(n),i.updateRange(e,o),i.updateByCameraPath(t);const a=i.yaw,h=i.pitch;r.enabled?r.update(e,a,h,o):e.lookAt({yaw:a.val,pitch:h.val,zoom:o})}sync(){const t=this._camera;this._zoomControl.sync(t),this._rotateControl.sync(t)}_blockContextMenu(){this._controlEl.addEventListener(b,this._preventContextMenu)}_restoreContextMenu(){this._controlEl.removeEventListener(b,this._preventContextMenu)}_setCursor(t){if(!this._useGrabCursor&&t!==j)return;this._controlEl.style.cursor=t}_bindEvents(){const t=this._rotateControl,e=this._zoomControl;t.on(nt,this._onInputStart),t.on(ht,this._onInputEnd),t.on(lt,this._onEnable),t.on(ut,this._onDisable),e.on(lt,this._onEnable),e.on(ut,this._onDisable),this._camera.on(rt,this._onCameraAnimationEnd)}}class te{constructor({width:t,height:e,flipY:i}){this.width=t,this.height=e,this.flipY=i,this.wrapS=WebGLRenderingContext.CLAMP_TO_EDGE,this.wrapT=WebGLRenderingContext.CLAMP_TO_EDGE}destroy(){}isVideo(){return!1}isCube(){return!1}}class ee extends te{constructor({source:t,width:e,height:i,flipY:s}){super({width:e,height:i,flipY:s}),this.source=t}}class ie extends ee{constructor(){super(...arguments),this.hls=null}destroy(){const t=this.source;this.hls&&(this.hls.destroy(),this.hls=null),t.pause(),t.removeAttribute("src"),t.load()}isVideo(){return!0}isPaused(){const t=this.source;return t.paused||t.ended||t.readyState<=2}hasAudio(){const t=this.source;return t.audioTracks?t.audioTracks.length>0:null!=t.webkitAudioDecodedByteCount?t.webkitAudioDecodedByteCount>0:null==t.mozHasAudio||t.mozHasAudio}}class se extends te{constructor({sources:t,width:e,height:i,flipY:s}){super({width:e,height:i,flipY:s}),this.sources=t}isCube(){return!0}}class re{constructor(t=!1){this.pendingHls=null,this._loadChecker=new n.default,this._debug=t}load(t,e){return h(this,void 0,void 0,(function*(){if(e)return this.loadVideo(t,St(e));if(Array.isArray(t)&&t.length>1)return this.loadCubeImage(t);{const e=Array.isArray(t)?t[0]:t;return this.loadImage(e)}}))}loadImage(t){return h(this,void 0,void 0,(function*(){const e=this._toImageArray(t);return this._load(e,(t=>{const i=e[0];t(new ee({source:i,width:i.naturalWidth,height:i.naturalHeight,flipY:!0}))}))}))}loadCubeImage(t){return h(this,void 0,void 0,(function*(){const e=this._toImageArray(t);return this._load(e,(t=>{t(new se({sources:e,width:e[0].naturalWidth,height:e[0].naturalHeight,flipY:!1}))}))}))}loadVideo(t,e){return h(this,void 0,void 0,(function*(){const i=Object.assign({autoplay:!0,muted:!0,loop:!1,volume:1},e),s=i.hlsConfig,r=!!(null==s?void 0:s.enabled),o=!!(null==s?void 0:s.force),n=r?this._getHlsSource(t):null,h=r&&(o||this._isM3u8Source(n)),l=h&&a.default&&"function"==typeof a.default.isSupported?a.default:null,u=!!l&&"function"==typeof l.isSupported,c=h&&u&&l.isSupported(),_=t instanceof HTMLVideoElement,d=this._toVideoElement(t,i,c);this._attachVideoDebugListeners(d);let m=null;return h&&(n?c&&l?(m=new l(null==s?void 0:s.config),this.pendingHls=m,m.loadSource(n),m.attachMedia(d)):!u&&this._debug?console.info("[View360][TextureLoader] HLS enabled but hls.js is unavailable."):d.canPlayType("application/vnd.apple.mpegurl")?d.src=n:this._debug&&console.info("[View360][TextureLoader] HLS source provided but not supported by this browser."):this._debug&&console.info("[View360][TextureLoader] HLS enabled but no source URL provided.")),this._load([d],(t=>{const{autoplay:e,muted:s}=i;if(_||(this._logVideoState(d,"ready-before-reset"),d.currentTime=0,this._logVideoState(d,"ready-after-reset")),e&&s){const t=d.play();t&&"function"==typeof t.catch&&t.catch((t=>{this._debug&&(console.info("[View360][TextureLoader] autoplay rejected:",t),this._logVideoState(d,"autoplay-rejected"))}))}const r=new ie({source:d,width:d.videoWidth,height:d.videoHeight,flipY:!0});r.hls=m,t(r)}))}))}_load(t,e){const i=this._loadChecker;return new Promise(((s,r)=>{i.once("ready",(t=>{t.errorCount>0||e(s)})),i.once("error",r),i.check(t)}))}_toImageArray(t){return(Array.isArray(t)?t:[t]).map((t=>{if(wt(t)){const e=new Image;return e.crossOrigin="anonymous",e.src=t,e}return t}))}_toVideoElement(t,{muted:e,loop:i,volume:s},r=!1){if(t instanceof HTMLVideoElement)return t;const o=document.createElement("video");if(o.crossOrigin="anonymous",o.playsInline=!0,o.setAttribute("webkit-playsinline",""),o.muted=e,o.volume=s,o.loop=i,r||(Array.isArray(t)?t.forEach((t=>this._appendSourceElement(o,t))):this._appendSourceElement(o,t)),!r){o.querySelectorAll("source").length>0&&o.readyState<1&&o.load()}return o}_attachVideoDebugListeners(t){if(!this._debug)return;["loadedmetadata","seeking","seeked","timeupdate","play","pause"].forEach((e=>{const i=()=>{this._logVideoState(t,`event:${e}`),t.removeEventListener(e,i)};t.addEventListener(e,i)}))}_logVideoState(t,e){if(!this._debug)return;let i=null,s=null;t.seekable&&t.seekable.length>0&&(i=t.seekable.start(0),s=t.seekable.end(0)),console.info("[View360][TextureLoader]",e,{currentTime:t.currentTime,duration:t.duration,readyState:t.readyState,paused:t.paused,ended:t.ended,seekableStart:i,seekableEnd:s,currentSrc:t.currentSrc||t.src})}_getHlsSource(t){if(wt(t))return t;if(Array.isArray(t)){for(const e of t){if(wt(e))return e;if(e instanceof HTMLSourceElement)return e.src}return null}if(t instanceof HTMLSourceElement)return t.src;if(t instanceof HTMLVideoElement){const e=t.querySelector("source");return t.currentSrc||t.src||(e?e.src:null)}return null}_isM3u8Source(t){return!!t&&/\.m3u8($|[?#])/i.test(t)}_appendSourceElement(t,e){if(e instanceof HTMLSourceElement)return e;const i=document.createElement("source");i.src=e,t.appendChild(i)}}class oe{constructor(t,e=window){this.maxDeltaTime=t,this._context=e,this._rafId=-1,this._rafTimer=-1,this._lastUpdateTime=-1}start(t){const e=this._context;if(!e||!t)return;if(this._rafId>=0||this._rafTimer>=0)return;const i=(s,r)=>{const o=Date.now(),n=Math.min(o-this._lastUpdateTime,1e3*this.maxDeltaTime);t(n,r),this._lastUpdateTime=o,this._rafId=e.requestAnimationFrame(i)};this._lastUpdateTime=Date.now(),this._rafId=e.requestAnimationFrame(i)}stop(){this._rafId>=0&&this._context.cancelAnimationFrame(this._rafId),this._rafTimer>=0&&clearTimeout(this._rafTimer),this._rafId=-1,this._rafTimer=-1}changeContext(t){this.stop(),this._context=t}}class ne{get useResizeObserver(){return this._useResizeObserver}get enabled(){return this._enabled}constructor(t,e){this._skipFirstResize=(()=>{let t=!0;return()=>{t?t=!1:this._onResize()}})(),this._useResizeObserver=t,this._enabled=!1,this._resizeObserver=null,this._onResize=e}enable(t){if(this._enabled&&this.disable(),this._useResizeObserver&&window.ResizeObserver){const e=t.getBoundingClientRect(),i=0!==e.width||0!==e.height,s=new ResizeObserver(i?this._skipFirstResize:this._onResize);s.observe(t),this._resizeObserver=s}else window.addEventListener(T,this._onResize);return this._enabled=!0,this}disable(){if(!this._enabled)return this;const t=this._resizeObserver;return t?(t.disconnect(),this._resizeObserver=null):window.removeEventListener(T,this._onResize),this._enabled=!1,this}}class ae{get enabled(){return this._enabled}get enableBlocked(){return this._enableBlocked}get playing(){return this._enabled&&!this._interrupted}get delay(){return this._delay}set delay(t){this._delay=t}get delayOnMouseLeave(){return this._delayOnMouseLeave}set delayOnMouseLeave(t){this._delayOnMouseLeave=t}get speed(){return this._speed}set speed(t){this._speed=t}get pauseOnHover(){return this._pauseOnHover}set pauseOnHover(t){this._pauseOnHover=t}get canInterrupt(){return this._canInterrupt}set canInterrupt(t){this._canInterrupt=t}get disableOnInterrupt(){return this._disableOnInterrupt}set disableOnInterrupt(t){this._disableOnInterrupt=t}constructor(t,e,i){this._onInputStart=()=>{this._canInterrupt&&(this._interrupted=!0,this._clearTimeout())},this._onInputEnd=()=>{this._setUninterruptedAfterDelay(this._delay)},this._onGyroEnable=()=>{this.disable()},this._onMouseEnter=()=>{this._pauseOnHover&&(this._interrupted=!0,this._hovering=!0)},this._onMouseLeave=()=>{this._pauseOnHover&&(this._hovering=!1,this._setUninterruptedAfterDelay(this._delayOnMouseLeave))},this._camera=t.camera,this._control=t.control,this._element=e,this._enabled=!1,this._interrupted=!1,this._interruptionTimer=-1,this._hovering=!1;const{delay:s=2e3,delayOnMouseLeave:r=0,speed:o=1,pauseOnHover:n=!1,canInterrupt:a=!0,disableOnInterrupt:h=!1}=St(i);this._enableBlocked=!i,this._delay=s,this._delayOnMouseLeave=r,this._speed=o,this._pauseOnHover=n,this._canInterrupt=a,this._disableOnInterrupt=h}destroy(){this.disable()}update(t){if(!this._enabled)return;if(this._interrupted)return void(this._disableOnInterrupt&&this.disable());const e=this._camera,i=-this._speed*t/100;e.yaw=Ot(e.yaw+i,0,360)}enable(){const t=this._control,e=this._element;this._enabled||t.gyro.enabled||(t.rotate.on(nt,this._onInputStart),t.rotate.on(ht,this._onInputEnd),t.zoom.on(nt,this._onInputStart),t.zoom.on(ht,this._onInputEnd),t.gyro.on(lt,this._onGyroEnable),e.addEventListener(R,this._onMouseEnter,!1),e.addEventListener(y,this._onMouseLeave,!1),this._enabled=!0,this._enableBlocked=!1)}enableAfterDelay(){this.enable(),this._interrupted=!0,this._setUninterruptedAfterDelay(this._delay)}disable(){if(!this._enabled)return;const t=this._control,e=this._element;t.rotate.off(nt,this._onInputStart),t.rotate.off(ht,this._onInputEnd),t.zoom.off(nt,this._onInputStart),t.zoom.off(ht,this._onInputEnd),t.gyro.off(lt,this._onGyroEnable),e.removeEventListener(R,this._onMouseEnter,!1),e.removeEventListener(y,this._onMouseLeave,!1),this._enabled=!1,this._interrupted=!1,this._hovering=!1,this._clearTimeout()}_setUninterruptedAfterDelay(t){this._hovering||(this._clearTimeout(),t>0?this._interruptionTimer=window.setTimeout((()=>{this._interrupted=!1,this._interruptionTimer=-1}),t):(this._interrupted=!1,this._interruptionTimer=-1))}_clearTimeout(){this._interruptionTimer>=0&&(window.clearTimeout(this._interruptionTimer),this._interruptionTimer=-1)}}const he=(t,e,i)=>t+(e-t)*i;class le{get enabled(){return this._enabled}get fps(){return this._fps}set fps(t){t>0&&(this._fps=t)}get canInterrupt(){return this._canInterrupt}set canInterrupt(t){this._canInterrupt=t}get disableOnInterrupt(){return this._disableOnInterrupt}set disableOnInterrupt(t){this._disableOnInterrupt=t}get smoothing(){return this._smoothing}set smoothing(t){Number.isFinite(t)&&(this._smoothing=Math.max(0,Math.min(1,t)))}get hasFrames(){return this._frameCount>0}constructor(t,e={}){this._onVideoFrame=(t,e)=>{if(this._lastMediaTime=e.mediaTime,!this._enabled||!this._video)return void(this._videoFrameCallbackId=-1);const i=this._video;"function"==typeof i.requestVideoFrameCallback?this._videoFrameCallbackId=i.requestVideoFrameCallback(this._onVideoFrame):this._videoFrameCallbackId=-1},this._onInputStart=()=>{this._canInterrupt&&this._disableOnInterrupt&&this.disable()};const{fps:i=30,canInterrupt:s=!0,disableOnInterrupt:r=!0,smoothing:o=0}=e;this._fps=i,this._canInterrupt=s,this._disableOnInterrupt=r,this.smoothing=o,this._frames=null,this._frameCount=0,this._lastFrameIndex=-1,this._enabled=!1,this._timeOffset=0,this._control=t.control,this._video=null,this._videoFrameCallbackId=-1,this._lastMediaTime=-1}setFrames(t,e=this._fps){const i=this._lastFrameIndex;if(t instanceof Float32Array)this._frames=t,this._frameCount=Math.floor(t.length/3);else{const e=t.length,i=new Float32Array(3*e);for(let s=0;s<e;s++){const e=3*s,r=t[s];i[e]=r.yaw,i[e+1]=r.pitch,i[e+2]=r.zoom}this._frames=i,this._frameCount=e}e>0&&(this._fps=e);const s=this._frameCount;(i<0||i>=s)&&(this._lastFrameIndex=-1)}setTimeOffset(t){Number.isFinite(t)&&(this._timeOffset=t,this._lastFrameIndex=-1)}resetTimeOffset(){this._timeOffset=0,this._lastFrameIndex=-1}clear(){this._frames=null,this._frameCount=0,this._lastFrameIndex=-1}enable(){this._enabled||(this._canInterrupt&&(this._control.rotate.on(nt,this._onInputStart),this._control.zoom.on(nt,this._onInputStart)),this._control.sync(),this._enabled=!0,this._lastFrameIndex=-1)}disable(){this._enabled&&(this._control.rotate.off(nt,this._onInputStart),this._control.zoom.off(nt,this._onInputStart),this._stopVideoFrameCallback(),this._enabled=!1)}updateByTime(t,e){if(!this._enabled||!this._frames||this._frameCount<=0)return!1;if(!Number.isFinite(t)||this._fps<=0)return!1;const i=this._frameCount-1,s=Math.max(0,t-this._timeOffset)*this._fps,r=((t,e)=>t<0?0:t>e?e:t)(Math.floor(s),i);let o=!1;const n=this._lastFrameIndex,a=Math.max(2*this._fps,30);(n<0||Math.abs(s-n)>a)&&(o=!0);const h=r<i?r+1:r,l=h===r?0:Math.max(0,Math.min(1,s-r)),u=3*r,c=3*h,_=this._frames[u],d=this._frames[u+1],m=this._frames[u+2],g=l>0?((t,e,i)=>{let s=e-t;return s>180&&(s-=360),s<-180&&(s+=360),t+s*i})(_,this._frames[c],l):_,p=l>0?he(d,this._frames[c+1],l):d,v=l>0?he(m,this._frames[c+2],l):m;return this._applyTarget(r,g,p,v,e,o)}updateFromVideo(t,e){if(!this._enabled||!this._frames||this._frameCount<=0)return!1;this._ensureVideoFrameCallback(t);const i=this._getVideoTime(t);return this.updateByTime(i,e)}destroy(){this.disable(),this.clear()}_getVideoTime(t){const e=t.currentTime;if(t.paused||t.ended||this._lastMediaTime<0)return e;return Math.abs(e-this._lastMediaTime)<=1/this._fps*2||e<this._lastMediaTime?this._lastMediaTime:e}_ensureVideoFrameCallback(t){if(!(t=>"function"==typeof t.requestVideoFrameCallback)(t))return;if(this._video&&this._video!==t&&this._stopVideoFrameCallback(),this._video=t,this._videoFrameCallbackId>=0)return;const e=t.requestVideoFrameCallback;this._videoFrameCallbackId=e.call(t,this._onVideoFrame)}_stopVideoFrameCallback(){const t=this._video;t&&this._videoFrameCallbackId>=0&&"function"==typeof t.cancelVideoFrameCallback&&t.cancelVideoFrameCallback(this._videoFrameCallbackId),this._videoFrameCallbackId=-1,this._lastMediaTime=-1,this._video=null}_applyTarget(t,e,i,s,r,o){const n=t!==this._lastFrameIndex,a=this._control.rotate,h=this._control.zoom,l=a.yaw,u=a.pitch,c=r.getHorizontalFov(s),_=this._smoothing;if(o){const s=l.val,r=e-s;return console.warn(`%c[CameraPath] forceInstant! frame=${t} prevFrame=${this._lastFrameIndex} | yaw: ${s.toFixed(2)}→${e.toFixed(2)} (jump=${r.toFixed(2)}) | pitch: ${u.val.toFixed(2)}→${i.toFixed(2)}`,"color: #ff9800"),l.reset(e),u.reset(i),h.reset(c),this._lastFrameIndex=t,!0}let d=e-l.end;const m=l.range;Number.isFinite(m.min)||Number.isFinite(m.max)||(d>180&&(d-=360),d<-180&&(d+=360));const g=i-u.end,p=c-h.end,v=1e-4,f=Math.abs(d)>v||Math.abs(g)>v||Math.abs(p)>v;if(!n&&!f)return!1;const E=_>0?_:1;return Math.abs(d)>v&&l.setNewEndByDelta(d*E),Math.abs(g)>v&&u.setNewEndByDelta(g*E),Math.abs(p)>v&&h.setNewEndByDelta(p*E),this._lastFrameIndex=t,!0}}class ue extends o.default{constructor(t,e={}){super(),this.destroy=()=>{this.exit(),this.off()},this._onSessionEnd=()=>{this.exit(),this.trigger(it.VR_END)},this._xrSession=null,this._xrRefSpace=null,this._ctx=t,this._options=e}isAvailable(){return h(this,void 0,void 0,(function*(){const t=window.navigator.xr;return!!t&&t.isSessionSupported(Rt).then((t=>t)).catch((()=>!1))}))}enter(){return h(this,void 0,void 0,(function*(){const t=this._ctx,e=window.navigator.xr;if(!e)return;yield Qt.requestSensorPermission();const i=Object.assign({requiredFeatures:[yt]},this._options);yield t.makeXRCompatible();const s=yield e.requestSession(Rt,i);t.bindXRLayer(s);const r=yield s.requestReferenceSpace(yt);this._setSession(s,r),this.trigger(it.VR_START,{session:s})}))}exit(){const t=this._xrSession;t&&t.end().catch((()=>{})),this._xrSession=null,this._xrRefSpace=null}canRender(t){const e=this._xrRefSpace;if(!e)return!1;return!!t.getViewerPose(e)}getEyeParams(t){const e=t.session,i=t.getViewerPose(this._xrRefSpace);if(!i)return null;const s=e.renderState.baseLayer;return s?i.views.map((t=>({viewport:s.getViewport(t),vMatrix:t.transform.inverse.matrix,pMatrix:t.projectionMatrix}))):null}_setSession(t,e){this._xrSession=t,this._xrRefSpace=e,t.addEventListener(G,this._onSessionEnd)}}class ce{constructor(t,e){this.element=t,this.position=e}}class _e{constructor(t,e,{zoom:i=!1}){this._containerEl=Lt(`.${et.HOTSPOT_CONTAINER}`,t),this._renderer=e,this._hotspots=[],this._zoom=i}refresh(){const t=this._containerEl;if(!t)return;const e=[].slice.apply(t.querySelectorAll(`.${et.HOTSPOT}`));this._hotspots=e.map((t=>this._parseHotspot(t)))}render(t){const i=this._hotspots,s=.5*this._renderer.width,r=.5*this._renderer.height,o=t.zoom,n="translate(-50%, -50%)",a=this._zoom?`scale(${o})`:"";i.forEach((i=>{const o=i.position,h=e.vec3.create();if(e.vec3.copy(h,o),e.vec3.transformMat4(h,h,t.viewMatrix),e.vec3.transformMat4(h,h,t.projectionMatrix),h[2]>1||h[2]<0)return void i.element.classList.remove(et.HOTSPOT_VISIBLE);const l=e.vec2.fromValues(h[0]*s+s,-h[1]*r+r);i.element.classList.add(et.HOTSPOT_VISIBLE),i.element.style.transform=[n,`translate(${l[0]}px, ${l[1]}px)`,a].join(" ")}))}_parseHotspot(t){const i=t.dataset.yaw,s=t.dataset.pitch,r=t.dataset.position;if(i||s){const e=i?parseFloat(i):0,r=s?parseFloat(s):0,o=this._yawPitchToVec3(e,r);return new ce(t,o)}if(r){const i=r.split(" ").map((t=>parseFloat(t)));if(i.length<3)throw new l(_.INSUFFICIENT_ARGS(r,'hotspot attribute "data-position"'),c.INSUFFICIENT_ARGS);return new ce(t,e.vec3.fromValues(i[0],i[1],i[2]))}{const i=e.vec3.fromValues(0,0,-1);return new ce(t,i)}}_yawPitchToVec3(t,i){const s=t*_t,r=i*_t,o=e.vec3.create();return o[1]=Math.sin(r),o[2]=Math.cos(r),o[0]=o[2]*Math.sin(-s),o[2]=-o[2]*Math.cos(-s),o}}class de{get count(){return this.geometry.indicies.count}constructor(t,e,i){this.obj=t,this.geometry=e,this.buffers=i}}class me{get canvas(){return this._canvas}get gl(){return this._gl}get maxTextureSize(){return this._maxTextureSize}get isWebGL2(){return this._isWebGL2}get supportVAO(){return this._isWebGL2||!!this._extensions.vao}get lost(){return this._contextLost}get debug(){return this._debug}constructor(t,e){this._onContextLost=()=>{this._canvas.classList.add(et.CTX_LOST),this._contextLost=!0},this._onContextRestore=()=>{this._canvas.classList.remove(et.CTX_LOST),this._contextLost=!1},this._canvas=t,this._contextLost=!1,this._debug=e,this._extensions={vao:null,loseContext:null}}init(){const t=this._canvas,{gl:e,isWebGL2:i}=this._getContext(t);this._gl=e,this._maxTextureSize=e.getParameter(e.MAX_TEXTURE_SIZE),this._isWebGL2=i,this._isWebGL2||(this._extensions.vao=e.getExtension("OES_vertex_array_object")),this._extensions.loseContext=e.getExtension("WEBGL_lose_context"),t.addEventListener(I,this._onContextLost),t.addEventListener(A,this._onContextRestore)}destroy(){const t=this._gl,e=this._canvas;t&&(t.bindBuffer(t.ARRAY_BUFFER,null),t.bindBuffer(t.ELEMENT_ARRAY_BUFFER,null)),e.removeEventListener(I,this._onContextLost),e.removeEventListener(A,this._onContextRestore)}forceLoseContext(){const t=this._extensions.loseContext;t&&t.loseContext()}forceRestoreContext(){const t=this._extensions.loseContext;t&&t.restoreContext()}clear(){const t=this._gl;t.clear(t.COLOR_BUFFER_BIT)}resize(){const t=this._gl;t.viewport(0,0,t.drawingBufferWidth,t.drawingBufferHeight)}viewport(t,e,i,s){this._gl.viewport(t,e,i,s)}createVAO(t,e){const i=this._createNativeVAO(),s=new de(i,t,{indicies:this._createBuffer(),position:this._createBuffer(),uv:this._createBuffer()});return i&&(this._bindNativeVAO(i),this._supplyGeometryData(s,e),this._bindNativeVAO(null),this._unbindBuffers()),s}draw(t,e){const i=this._gl;t.obj?this._bindNativeVAO(t.obj):this._supplyGeometryData(t,e),i.drawElements(i.TRIANGLES,t.count,i.UNSIGNED_SHORT,0),t.obj?this._bindNativeVAO(null):this._unbindBuffers()}releaseVAO(t){t.obj&&this._deleteNativeVAO(t.obj),this._deleteBuffer(t.buffers.indicies),this._deleteBuffer(t.buffers.position),this._deleteBuffer(t.buffers.uv)}getUniformLocations(t,e){const i=this._gl,s=Object.keys(e).reduce(((e,s)=>(e[s]=i.getUniformLocation(t,s),e)),{});return Object.assign(Object.assign({},this._getCommonUniformLocations(t)),s)}updateCommonUniforms(t,i,s){const r=this._gl,o=s.uniformLocations,n=t.matrix,a=e.mat4.create();e.mat4.multiply(a,i.viewMatrix,n),r.uniformMatrix4fv(o.uMVMatrix,!1,a),r.uniformMatrix4fv(o.uPMatrix,!1,i.projectionMatrix)}updateVRUniforms(t,e,i,s){const r=this._gl,o=t.uniformLocations;r.uniformMatrix4fv(o.uMVMatrix,!1,e),r.uniformMatrix4fv(o.uPMatrix,!1,i),o.uEye&&r.uniform1f(o.uEye,s)}updateUniforms(t){const e=this._gl,i=t.uniforms,s=t.uniformLocations;for(const t in i){const r=i[t],o=s[t];r&&(r.needsUpdate&&r.update(e,o,this._isWebGL2))}}releaseShaderResources(t){const e=this._gl,i=t.uniforms;for(const t in i){const s=i[t];s&&(s.needsUpdate&&s.destroy(e))}e.deleteProgram(t.program)}useProgram(t){this._gl.useProgram(t.program)}createProgram(t,e){const i=this._gl,s=i.createProgram(),r=this._compileShader(i.VERTEX_SHADER,t),o=this._compileShader(i.FRAGMENT_SHADER,e);if(i.attachShader(s,r),i.attachShader(s,o),i.bindAttribLocation(s,0,"position"),i.bindAttribLocation(s,1,"uv"),i.linkProgram(s),this._debug&&!i.getProgramParameter(s,i.LINK_STATUS)){let t=null;throw i.getShaderParameter(r,i.COMPILE_STATUS)?i.getShaderParameter(o,i.COMPILE_STATUS)||(t=i.getShaderInfoLog(o)):t=i.getShaderInfoLog(r),new l(_.FAILED_LINKING_PROGRAM(i.getProgramInfoLog(s),t),c.FAILED_LINKING_PROGRAM)}return i.deleteShader(r),i.deleteShader(o),s}createWebGLTexture(t){const e=this._gl,i=e.createTexture();if(e.bindTexture(e.TEXTURE_2D,i),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MIN_FILTER,e.LINEAR),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MAG_FILTER,e.LINEAR),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_S,t.wrapS),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_T,t.wrapT),!t.isVideo()&&this._isWebGL2){const i=e;i.texStorage2D(i.TEXTURE_2D,1,i.RGBA8,t.width,t.height)}return i}createWebGLCubeTexture(t,e){const i=this._gl,s=i.createTexture();if(i.bindTexture(i.TEXTURE_CUBE_MAP,s),i.texParameteri(i.TEXTURE_CUBE_MAP,i.TEXTURE_MIN_FILTER,i.LINEAR),i.texParameteri(i.TEXTURE_CUBE_MAP,i.TEXTURE_MAG_FILTER,i.LINEAR),i.texParameteri(i.TEXTURE_CUBE_MAP,i.TEXTURE_WRAP_S,t.wrapS),i.texParameteri(i.TEXTURE_CUBE_MAP,i.TEXTURE_WRAP_T,t.wrapT),this._isWebGL2){const t=i;t.texStorage2D(t.TEXTURE_CUBE_MAP,1,t.RGBA8,e,e)}return s}makeXRCompatible(){return h(this,void 0,void 0,(function*(){const t=this._gl,e=t.getContextAttributes();e&&!0!==e.xrCompatible&&(yield t.makeXRCompatible())}))}bindXRLayer(t){const e=this._gl,i=new XRWebGLLayer(t,e);t.updateRenderState({baseLayer:i})}bindXRFrame(t){const e=this._gl,i=t.session.renderState.baseLayer;e.bindFramebuffer(e.FRAMEBUFFER,i.framebuffer)}useDefaultFrameBuffer(){const t=this._gl;t.bindFramebuffer(t.FRAMEBUFFER,null)}createFramebuffer(t,e){const i=this._gl,s=i.createFramebuffer(),r=i.createTexture();if(!s||!r)throw new l("无法创建 Framebuffer",c.FAILED_LINKING_PROGRAM);i.bindTexture(i.TEXTURE_2D,r),i.texImage2D(i.TEXTURE_2D,0,i.RGBA,t,e,0,i.RGBA,i.UNSIGNED_BYTE,null),i.texParameteri(i.TEXTURE_2D,i.TEXTURE_MIN_FILTER,i.LINEAR),i.texParameteri(i.TEXTURE_2D,i.TEXTURE_MAG_FILTER,i.LINEAR),i.texParameteri(i.TEXTURE_2D,i.TEXTURE_WRAP_S,i.CLAMP_TO_EDGE),i.texParameteri(i.TEXTURE_2D,i.TEXTURE_WRAP_T,i.CLAMP_TO_EDGE),i.bindFramebuffer(i.FRAMEBUFFER,s),i.framebufferTexture2D(i.FRAMEBUFFER,i.COLOR_ATTACHMENT0,i.TEXTURE_2D,r,0);const o=i.checkFramebufferStatus(i.FRAMEBUFFER);if(o!==i.FRAMEBUFFER_COMPLETE)throw new l("Framebuffer 不完整: "+o,c.FAILED_LINKING_PROGRAM);return i.bindFramebuffer(i.FRAMEBUFFER,null),i.bindTexture(i.TEXTURE_2D,null),{framebuffer:s,texture:r}}bindFramebuffer(t){this._gl.bindFramebuffer(this._gl.FRAMEBUFFER,t)}deleteFramebuffer(t){const e=this._gl;e.deleteFramebuffer(t.framebuffer),e.deleteTexture(t.texture)}_createBuffer(){return this._gl.createBuffer()}_deleteBuffer(t){return this._gl.deleteBuffer(t)}_createNativeVAO(){const t=this._gl;if(this._isWebGL2)return t.createVertexArray();{const t=this._extensions.vao;return(null==t?void 0:t.createVertexArrayOES())||null}}_bindNativeVAO(t){const e=this._gl;if(this._isWebGL2)e.bindVertexArray(t);else{const e=this._extensions.vao;null==e||e.bindVertexArrayOES(t)}}_deleteNativeVAO(t){const e=this._gl;if(this._isWebGL2)e.deleteVertexArray(t);else{const e=this._extensions.vao;null==e||e.deleteVertexArrayOES(t)}}_supplyGeometryData(t,e){const i=t.geometry;this._supplyIndiciesData(i.indicies,t.buffers.indicies),this._supplyAttributeData(i.vertices,e.program,"position",t.buffers.position),this._supplyAttributeData(i.uvs,e.program,"uv",t.buffers.uv)}_unbindBuffers(){const t=this._gl;t.bindBuffer(t.ELEMENT_ARRAY_BUFFER,null),t.bindBuffer(t.ARRAY_BUFFER,null)}_supplyIndiciesData(t,e){const i=this._gl;i.bindBuffer(i.ELEMENT_ARRAY_BUFFER,e),i.bufferData(i.ELEMENT_ARRAY_BUFFER,t.data,i.STATIC_DRAW)}_supplyAttributeData(t,e,i,s){const r=this._gl,o=r.getAttribLocation(e,i);o<0||(r.bindBuffer(r.ARRAY_BUFFER,s),r.bufferData(r.ARRAY_BUFFER,t.data,r.STATIC_DRAW),r.vertexAttribPointer(o,t.itemSize,r.FLOAT,!1,0,0),r.enableVertexAttribArray(o))}_compileShader(t,e){const i=this._gl,s=i.createShader(t);return i.shaderSource(s,e),i.compileShader(s),s}_getCommonUniformLocations(t){const e=this._gl;return{uMVMatrix:e.getUniformLocation(t,"uMVMatrix"),uPMatrix:e.getUniformLocation(t,"uPMatrix")}}_getContext(t){const e=["webgl2","webgl","experimental-webgl","webkit-3d","moz-webgl"];let i=null,s=!1;const r={preserveDrawingBuffer:!1,antialias:!1},o=t=>t.statusMessage;t.addEventListener(L,o);for(const o of e){try{i=t.getContext(o,r),s="webgl2"===o}catch(t){}if(i)break}if(t.removeEventListener(L,o),!i)throw new l(_.WEBGL_NOT_SUPPORTED,c.WEBGL_NOT_SUPPORTED);return{gl:i,isWebGL2:s}}}class ge{get canvas(){return this._canvas}get width(){return this._elementSize.x}get height(){return this._elementSize.y}get pixelRatio(){return this._pixelRatio}get renderWidth(){return this._renderSize.width}get renderHeight(){return this._renderSize.height}get aspect(){return this._elementSize.x/this._elementSize.y}constructor(t,e){this._canvas=t,this._elementSize={x:0,y:0},this._pixelRatio=1,this._renderSize={width:null,height:null},this.ctx=new me(t,e)}destroy(){const t=this._canvas;this.ctx.destroy(),t.width=1,t.height=1}resize(){const t=this._canvas,e=this._elementSize,i=window.devicePixelRatio;e.x=t.clientWidth,e.y=t.clientHeight;const s=e.x||1,r=e.y||1,o=this._renderSize.width,n=this._renderSize.height;let a,h;null!=o&&null!=n?(a=o,h=n):null!=o?(a=o,h=Math.max(1,Math.round(a*r/s))):null!=n?(h=n,a=Math.max(1,Math.round(h*s/r))):(a=Math.max(1,Math.round(s*i)),h=Math.max(1,Math.round(r*i))),t.width=a,t.height=h,this._pixelRatio=a/s,this.ctx.resize()}setRenderSize(t,e){const i=null!=t&&t>0?Math.round(t):null,s=null!=e&&e>0?Math.round(e):null;this._renderSize={width:i,height:s}}render(t,e){const i=this.ctx;i.lost||(i.clear(),i.useProgram(t.program),i.updateCommonUniforms(t,e,t.program),t.update({camera:e}),i.updateUniforms(t.program),i.draw(t.vao,t.program))}renderVR(t,i,s){const r=this.ctx,o=i.getEyeParams(s);o&&t&&(r.bindXRFrame(s),r.useProgram(t.program),r.updateUniforms(t.program),o.forEach(((i,s)=>{const o=i.viewport,n=e.mat4.multiply(e.mat4.create(),i.vMatrix,t.matrix);r.viewport(o.x,o.y,o.width,o.height),r.updateVRUniforms(t.program,n,i.pMatrix,s),r.draw(t.vao,t.program)})))}}class pe extends o.default{get rootEl(){return this._rootEl}get renderer(){return this._renderer}get renderWidth(){return this._renderWidth}set renderWidth(t){this._renderWidth=null!=t&&t>0?t:null,this._renderer.setRenderSize(this._renderWidth,this._renderHeight),this.resize()}get renderHeight(){return this._renderHeight}set renderHeight(t){this._renderHeight=null!=t&&t>0?t:null,this._renderer.setRenderSize(this._renderWidth,this._renderHeight),this.resize()}get camera(){return this._camera}get control(){return this._control}get cameraPath(){return this._cameraPath}get hls(){var t;if(this._earlyHls)return this._earlyHls;const e=null===(t=this._mesh)||void 0===t?void 0:t.getTexture();return e&&e.isVideo()&&e.hls||null}get vr(){return this._vr}get hotspot(){return this._hotspot}get plugins(){return this._plugins}get projection(){return this._projection}set projection(t){this._initialized&&t?this.load(t):this._projection=t}get mesh(){return this._mesh}get initialized(){return this._initialized}get autoplay(){return this._autoplay}get autoInit(){return this._autoInit}get autoResize(){return this._autoResize}get canvasSelector(){return this._canvasSelector}get useResizeObserver(){return this._useResizeObserver}get tabIndex(){return this._tabIndex}set tabIndex(t){const e=this._renderer.canvas;this._tabIndex=t,null!=t?e.tabIndex=t:e.removeAttribute("tabindex")}get maxDeltaTime(){return this._animator.maxDeltaTime}set maxDeltaTime(t){this._animator.maxDeltaTime=t}get debug(){return this._debug}set debug(t){this._debug=t}get initialYaw(){return this._camera.initialYaw}set initialYaw(t){this._camera.initialYaw=t}get initialPitch(){return this._camera.initialPitch}set initialPitch(t){this._camera.initialPitch=t}get initialZoom(){return this._camera.initialZoom}set initialZoom(t){this._camera.initialZoom=t}get yawRange(){return this._camera.yawRange}set yawRange(t){this._camera.yawRange=t,this._projection&&this._projection.updateCamera(this._camera)}get pitchRange(){return this._camera.pitchRange}set pitchRange(t){this._camera.pitchRange=t,this._projection&&this._projection.updateCamera(this._camera)}get zoomRange(){return this._camera.zoomRange}set zoomRange(t){this._camera.zoomRange=t,this._projection&&this._projection.updateCamera(this._camera)}get fov(){return this._camera.fov}set fov(t){const e=this._camera,i=this._control;e.fov=t,e.updateMatrix(),i.sync()}get rotate(){return this._control.rotate}get zoom(){return this._control.zoom}get gyro(){return this._control.gyro}get useGrabCursor(){return this._control.useGrabCursor}set useGrabCursor(t){this._control.useGrabCursor=t}get disableContextMenu(){return this._control.disableContextMenu}set disableContextMenu(t){this._control.disableContextMenu=t}get scrollable(){return this._control.scrollable}set scrollable(t){this._control.scrollable=t}get wheelScrollable(){return this._control.wheelScrollable}set wheelScrollable(t){this._control.wheelScrollable=t}constructor(t,{projection:e=null,initialYaw:i=0,initialPitch:s=0,initialZoom:r=1,yawRange:o=null,pitchRange:n=null,zoomRange:a=null,fov:h=90,useGrabCursor:u=!0,disableContextMenu:d=!1,rotate:m=!0,zoom:g=!0,gyro:p=!1,scrollable:v=!0,wheelScrollable:f=!1,autoplay:E=!1,hotspot:T={},autoInit:b=!0,autoResize:R=!0,renderWidth:y=null,renderHeight:x=null,canvasSelector:w="canvas",useResizeObserver:C=!0,on:L={},plugins:I=[],maxDeltaTime:A=1/30,tabIndex:O=0,debug:P=!1}={}){super(),this._earlyHls=null,this.renderFrame=t=>{const e=this._camera,i=this._renderer,s=this._control,r=this._hotspot,o=this._autoplay,n=this._cameraPath,a=this._mesh;if(!a)return;const h=a.getTexture(),l=h&&h.isVideo()?h.source:null,u=n.enabled&&n.hasFrames&&!!l;if(this._emit(it.BEFORE_RENDER),o.playing&&!u&&(o.update(t),s.sync()),u){l.paused||l.ended?this._cameraPathPaused||(s.sync(),this._cameraPathPaused=!0):(this._cameraPathPaused=!1,n.updateFromVideo(l,e)),s.updateByCameraPath(t)}else e.animation?(this._cameraPathPaused=!1,e.animation.update(t)):(this._cameraPathPaused=!1,s.update(t));i.render(a,e),r.render(e),e.changed&&this._emit(it.VIEW_CHANGE,{yaw:e.yaw,pitch:e.pitch,zoom:e.zoom,quaternion:[e.quaternion[0],e.quaternion[1],e.quaternion[2],e.quaternion[3]]}),e.onFrameRender(),this._emit(it.RENDER)},this._renderFrameOnDemand=t=>{const e=this._camera,i=this._control,s=this._autoplay,r=this._mesh,o=null==r?void 0:r.getTexture();if(!this._initialized||!o)return;const n=o.isVideo(),a=n&&o.isPaused();(e.animation||i.animating||s.playing||n&&!a)&&this.renderFrame(t)},this._renderVRFrame=(t,e)=>{const i=this._vr,s=this._mesh,r=this._renderer;s&&(this._emit(it.BEFORE_RENDER),r.renderVR(s,i,e),this._emit(it.RENDER))},this._onVideoTimeUpdate=t=>{const e=t.currentTarget;if(!e)return;if(!e.paused&&!e.ended)return;const i=this._cameraPath;if(!i.enabled||!i.hasFrames)return;const s=this._mesh,r=null==s?void 0:s.getTexture();r&&r.isVideo()&&r.source===e&&this.renderFrame(0)},this._rootEl=((t,e)=>{const i=Lt(t,e);if(!i)throw wt(t)?new l(_.ELEMENT_NOT_FOUND(t),c.ELEMENT_NOT_FOUND):new l(_.WRONG_TYPE(t,["HTMLElement","string"]),c.WRONG_TYPE);return i})(t),this._plugins=I,this._initialized=!1,this._autoInit=b,this._autoResize=R,this._renderWidth=null!=y&&y>0?y:null,this._renderHeight=null!=x&&x>0?x:null,this._canvasSelector=w,this._useResizeObserver=C,this._tabIndex=O,this._debug=P;const S=((t,e)=>{const i=t.querySelector(e);if(!i)throw new l(_.CANVAS_NOT_FOUND,c.CANVAS_NOT_FOUND);return i})(this._rootEl,w);this._renderer=new ge(S,P),this._renderer.setRenderSize(this._renderWidth,this._renderHeight),this._camera=new Ht({initialYaw:i,initialPitch:s,initialZoom:r,fov:h,yawRange:o,pitchRange:n,zoomRange:a}),this._control=new Jt(S,this._camera,{useGrabCursor:u,scrollable:v,wheelScrollable:f,disableContextMenu:d,rotate:m,zoom:g,gyro:p}),this._animator=new oe(A),this._autoplay=new ae(this,S,E),this._cameraPath=new le(this),this._cameraPathPaused=!1,this._projection=e,this._mesh=null,this._autoResizer=new ne(C,(()=>this.resize())),this._vr=new ue(this._renderer.ctx),this._hotspot=new _e(this._rootEl,this._renderer,T),this._videoEventTarget=null,this._addEventHandlers(L),e&&b&&this.init()}destroy(){this._camera.destroy(),this._animator.stop(),this._renderer.destroy(),this._control.destroy(),this._cameraPath.destroy(),this._autoResizer.disable(),this._unbindVideoEvents(),this._mesh&&(this._mesh.destroy(this._renderer.ctx),this._mesh=null),this._plugins.forEach((t=>t.destroy(this))),this._earlyHls=null,this._initialized=!1}init(){return h(this,void 0,void 0,(function*(){if(!this._projection)throw new l(_.PROVIDE_PROJECTION_FIRST,c.PROVIDE_PROJECTION_FIRST);const t=this._renderer,e=this._camera,i=this._control,s=this._animator,r=this._hotspot,o=this._projection,n=t.canvas;this._bindComponentEvents(),t.ctx.init(),this._resizeComponents(),e.updateMatrix(),this._autoResize&&this._autoResizer.enable(n),this._autoplay.enableBlocked||this._autoplay.enable(),this._plugins.forEach((t=>{t.init(this)}));const a=yield this._loadTexture(o);this._applyProjection(o,a),r.refresh(),s.start(this._renderFrameOnDemand),yield i.enable(),null==this._tabIndex||n.hasAttribute("tabIndex")||(n.tabIndex=this._tabIndex),this._initialized=!0,this.renderFrame(0),this._emit(it.READY)}))}load(t){return h(this,void 0,void 0,(function*(){if(!t)return!1;if(this._initialized){const e=yield this._loadTexture(t);this._applyProjection(t,e),this.renderFrame(0)}else this._projection=t,this.init();return!0}))}resize(){if(!this._initialized)return;this._resizeComponents(),this.renderFrame(0);const{width:t,height:e}=this._renderer;this._emit(it.RESIZE,{width:t,height:e})}addPlugins(...t){this._initialized&&t.forEach((t=>{t.init(this)})),this._plugins.push(...t)}removePlugins(...t){t.forEach((t=>{const e=this._plugins.indexOf(t);e<0||(t.destroy(this),this._plugins.splice(e,1))}))}_emit(t,...e){const i=e?e[0]:{};this.trigger(t,Object.assign({type:t,target:this},i))}_applyProjection(t,e){const i=this._camera,s=this._control,r=this._renderer,o=this._mesh;this._unbindVideoEvents(),o&&o.destroy(r.ctx);const n=t.createMesh(r.ctx,e);t.updateCamera(i),t.updateControl(s),this._mesh=n,e.isVideo()&&this._bindVideoEvents(e.source),this._emit(it.PROJECTION_CHANGE,{projection:t})}_loadTexture(t){return h(this,void 0,void 0,(function*(){const e=new re(this._debug),{src:i,video:s}=t;this._emit(it.LOAD_START,{src:i,video:s});const r=e.load(i,s);let o;this._earlyHls=e.pendingHls;try{o=yield r}catch(t){throw this._earlyHls=null,t}return this._emit(it.LOAD,{src:i,video:s}),o}))}_resizeComponents(){const t=this._renderer,e=this._camera,i=this._control;t.resize(),e.resize(t.width,t.height),i.resize(t.width,t.height)}_addEventHandlers(t){Object.keys(t).forEach((e=>{this.on(e,t[e])}))}_bindComponentEvents(){const t=this._rootEl,e=this._control,i=this._animator,s=this._renderer,r=this._vr;[ct,nt,ht].forEach((t=>{e.rotate.on(t,(e=>{this._emit(t,e)})),e.zoom.on(t,(e=>{this._emit(t,e)}))})),r.on(it.VR_START,(e=>{t.classList.add(et.IN_VR),i.changeContext(e.session),i.start(this._renderVRFrame),this._emit(it.VR_START)})),r.on(it.VR_END,(()=>{t.classList.remove(et.IN_VR),s.ctx.useDefaultFrameBuffer(),i.changeContext(window),i.start(this._renderFrameOnDemand),this.resize(),this._emit(it.VR_END)}))}_bindVideoEvents(t){this._videoEventTarget!==t&&(this._unbindVideoEvents(),this._videoEventTarget=t,t.addEventListener("seeked",this._onVideoTimeUpdate),t.addEventListener("timeupdate",this._onVideoTimeUpdate),t.addEventListener(Tt,this._onVideoTimeUpdate))}_unbindVideoEvents(){this._videoEventTarget&&(this._videoEventTarget.removeEventListener("seeked",this._onVideoTimeUpdate),this._videoEventTarget.removeEventListener("timeupdate",this._onVideoTimeUpdate),this._videoEventTarget.removeEventListener(Tt,this._onVideoTimeUpdate),this._videoEventTarget=null)}}pe.VERSION="4.0.0-beta.7-fork.1";class ve extends o.default{constructor(){super(),this.matrix=e.mat4.create(),this.rotation=e.quat.create(),this.position=e.vec3.fromValues(0,0,0),this.scale=e.vec3.fromValues(1,1,1)}updateMatrix(){e.mat4.fromRotationTranslationScale(this.matrix,this.rotation,this.position,this.scale)}update(t){this.trigger(ot,t)}}class fe{constructor({className:t={}}={}){this._startLoading=({target:t})=>{t.rootEl.appendChild(this._container),t.initialized?t.once(it.LOAD,this._detachElements):t.once(it.READY,this._detachElements)},this._detachElements=({target:t})=>{const e=this._container;e&&e.parentElement===t.rootEl&&t.rootEl.removeChild(e)},this.className=t,this._container=this._createElements()}init(t){t.on(it.LOAD_START,this._startLoading)}destroy(t){t.off(it.LOAD_START,this._startLoading),this._detachElements({target:t})}_createElements(){const t=Object.assign(Object.assign({},this.className),fe.DEFAULT_CLASS),e=Ct(t.CONTAINER),i=Ct(t.RING);return e.appendChild(i),e}}fe.DEFAULT_CLASS={CONTAINER:"view360-spinner",RING:"view360-spinner-ring"};class Ee{constructor(t){this.position=t.position,this.order=t.order}}const Te={CONTROLS_ROOT:"view360-controls",CONTROLS_BG:"view360-controls-background",CONTROLS_MAIN:"view360-controls-main",CONTROLS_TOP:"view360-controls-top",CONTROLS_BOTTOM:"view360-controls-bottom",CONTROLS_MID:"view360-controls-mid",CONTROLS_LEFT:"view360-controls-left",CONTROLS_RIGHT:"view360-controls-right",CONTROLS_FLOAT_LEFT:"view360-controls-float-left",CONTROLS_FLOAT_RIGHT:"view360-controls-float-right",CONTROLS_BUTTON:"view360-controls-button",PROGRESS_ROOT:"view360-controls-progress",VOLUME_ROOT:"view360-controls-volume",RANGE_ROOT:"view360-range",RANGE_TRACK:"view360-range-track",RANGE_THUMB:"view360-range-thumb",RANGE_FILLER:"view360-range-filler",PLAY_BUTTON:"view360-controls-play",PAUSE_BUTTON:"view360-controls-pause",UNMUTED_BUTTON:"view360-controls-unmuted",MUTED_BUTTON:"view360-controls-muted",FULLSCREEN_BUTTON:"view360-controls-fullscreen",FULLSCREEN_EXIT_BUTTON:"view360-controls-fullscreen-exit",VR_BUTTON:"view360-controls-vr",GYRO_ENABLED:"view360-controls-gyro-enabled",GYRO_DISABLED:"view360-controls-gyro-disabled",VIDEO_TIME_DISPLAY:"view360-controls-time",PIEVIEW_ROOT:"view360-controls-pie",FIXED:"view360-controls-fixed",UNAVAILABLE:"view360-controls-unavailable",HIDDEN:"view360-controls-hidden"},be={TOP_LEFT:"top-left",TOP_RIGHT:"top-right",MAIN_TOP:"main-top",MAIN_BOTTOM:"main-bottom",MAIN_LEFT:"main-left",MAIN_RIGHT:"main-right"};class Re extends o.default{constructor(){super(),this._onHold=({srcEvent:t,isTouch:e})=>{var i;const s=this._bbox;if(!s)return;const r=e?t.touches[0].pageX:t.pageX,o=s.x+(null!==(i=window.scrollX)&&void 0!==i?i:window.pageXOffset),n=It(r,o,o+s.width),a=(n-o)/s.width;this._motion.reset(n),this.thumbEl.classList.add(this._fixedClass),this.trigger(nt,a)},this._onChange=({delta:t})=>{var e;const i=this._motion,s=this._bbox;if(!s)return;i.setNewEndByDelta(t.x),i.update(1);const r=s.x+(null!==(e=window.scrollX)&&void 0!==e?e:window.pageXOffset),o=(It(i.val,r,r+s.width)-r)/s.width;this.trigger(at,o)},this._onRelease=()=>{this._bbox&&(this.thumbEl.classList.remove(this._fixedClass),this.trigger(ht))};const t=document.createElement(H),e=document.createElement(H),i=document.createElement(H),s=document.createElement(H);t.draggable=!1,e.appendChild(s),e.appendChild(i),t.appendChild(e),this.rootEl=t,this.trackEl=e,this.thumbEl=i,this.fillerEl=s,this._mouseInput=new Yt,this._touchInput=new Wt,this._motion=new zt({duration:1,range:pt,easing:t=>t}),this._bbox={x:0,y:0,width:0,height:0,left:0,right:0,bottom:0,top:0},this._fixedClass=Te.FIXED}init(t){const e=this._mouseInput,i=this._touchInput;this.rootEl.classList.add(t.RANGE_ROOT),this.trackEl.classList.add(t.RANGE_TRACK),this.thumbEl.classList.add(t.RANGE_THUMB),this.fillerEl.classList.add(t.RANGE_FILLER),this._fixedClass=t.FIXED,e.on(nt,this._onHold),i.on(nt,this._onHold),e.on(ht,this._onRelease),i.on(ht,this._onRelease),e.on(at,this._onChange),i.on(at,this._onChange),e.enable(this.rootEl),i.enable(this.rootEl),this.resize()}destroy(){const t=this._mouseInput,e=this._touchInput;this.rootEl.className="",this.trackEl.className="",this.thumbEl.className="",this.fillerEl.className="",t.off(),e.off(),t.disable(),e.disable()}resize(){this._bbox=this.trackEl.getBoundingClientRect()}updateStyle(t){const e=this._bbox.width,i=It(t,0,1);this.fillerEl.style.width=100*i+"%",this.thumbEl.style.transform=`translateX(${i*e}px)`}}class ye extends Ee{get element(){return this._rangeControl.rootEl}constructor({position:t=be.MAIN_TOP,order:e=9999}={}){super({position:t,order:e}),this._onResize=()=>{this._rangeControl.resize()},this._onTimeUpdate=()=>{const t=this._video;t&&(this._currentTime=t.source.currentTime,this._rangeControl.updateStyle(this._currentTime/this._duration))},this._onDurationChange=()=>{const t=this._video;t&&(this._duration=t.source.duration,this._rangeControl.updateStyle(this._currentTime/this._duration))},this._onHold=t=>{const e=this._video,i=this._controlBar;if(!e||!i)return;const s=e.isPaused();e.source.pause();const r=e.source.duration*t;e.source.currentTime=r,e.source.dispatchEvent(new CustomEvent(Tt,{detail:{time:r}})),i.rootEl.classList.add(i.className.FIXED),this._wasPaused=!this._playPromise&&s},this._onControl=t=>{const e=this._video;if(!e)return;const i=e.source.duration*t;e.source.currentTime=i,e.source.dispatchEvent(new CustomEvent(Tt,{detail:{time:i}}))},this._onRelease=()=>{const t=this._video,e=this._controlBar;t&&e&&(this._wasPaused||this._playPromise||(this._playPromise=t.source.play().catch((()=>{})),this._playPromise.then((()=>{this._playPromise=null})),e.rootEl.classList.remove(e.className.FIXED))),this._wasPaused=!1},this.position=t,this.order=e,this._controlBar=null,this._rangeControl=new Re,this._video=null,this._wasPaused=!1,this._currentTime=0,this._duration=0,this._playPromise=null}init(t,e){var i;const s=null===(i=t.mesh)||void 0===i?void 0:i.getTexture(),r=this.element,o=this._rangeControl,n=e.className.UNAVAILABLE;s&&s.isVideo()?(r.classList.remove(n),r.classList.add(e.className.PROGRESS_ROOT),t.on(it.RESIZE,this._onResize),s.source.addEventListener(D,this._onTimeUpdate),s.source.addEventListener(B,this._onDurationChange),s.source.addEventListener(Tt,this._onTimeUpdate),o.init(e.className),o.on(nt,this._onHold),o.on(at,this._onControl),o.on(ht,this._onRelease),this._video=s,this._currentTime=s.source.currentTime,this._duration=s.source.duration,this._controlBar=e,o.updateStyle(this._currentTime/this._duration)):r.classList.add(n)}destroy(t){const e=this._video;t.off(it.RESIZE,this._onResize),e&&(e.source.removeEventListener(D,this._onTimeUpdate),e.source.removeEventListener(B,this._onDurationChange),e.source.removeEventListener(Tt,this._onTimeUpdate)),this._rangeControl.destroy(),this._video=null,this._playPromise=null}}class xe extends Ee{constructor({position:t=be.MAIN_LEFT,order:e=9999}={}){super({position:t,order:e}),this._onClick=()=>{const t=this._video;t&&(this._paused?t.source.play():t.source.pause())},this._onPlay=()=>{if(!this._controlBar)return;const t=this.element,e=this._controlBar.className;t.classList.add(e.PAUSE_BUTTON),t.classList.remove(e.PLAY_BUTTON),t.title="Pause Video",this._paused=!1},this._onPause=()=>{if(!this._controlBar)return;const t=this.element,e=this._controlBar.className;t.classList.add(e.PLAY_BUTTON),t.classList.remove(e.PAUSE_BUTTON),t.title="Play Video",this._paused=!0},this.element=document.createElement(Y),this._video=null,this._paused=!0,this._controlBar=null}init(t,e){var i;const s=this.element,r=null===(i=t.mesh)||void 0===i?void 0:i.getTexture(),o=e.className,n=o.UNAVAILABLE;if(!r||!r.isVideo())return void s.classList.add(n);s.classList.add(o.CONTROLS_BUTTON),s.classList.remove(n);const a=r.isPaused();this._video=r,this._paused=a,this._controlBar=e,a?this._onPause():this._onPlay(),s.addEventListener(C,this._onClick),r.source.addEventListener(F,this._onPlay),r.source.addEventListener(M,this._onPause)}destroy(){const t=this._video,e=this.element;t&&(e.className="",e.removeEventListener(C,this._onClick),t.source.removeEventListener(F,this._onPlay),t.source.removeEventListener(M,this._onPause),this._video=null,this._paused=!0,this._controlBar=null)}}class we extends Ee{get element(){return this._rootEl}constructor({position:t=be.MAIN_RIGHT,order:e=9999}={}){super({position:t,order:e}),this._onResize=()=>{this._rangeControl.resize(),this._updateDisplay()},this._onClick=()=>{const t=this._video;t&&!this._rootEl.disabled&&(t.source.muted=!t.source.muted)},this._onVolumeChange=()=>{const t=this._buttonEl,e=this._video,i=this._controlBar;if(!e||!i)return;const s=i.className;e.source.muted||0===e.source.volume?(t.classList.add(s.MUTED_BUTTON),t.classList.remove(s.UNMUTED_BUTTON)):(t.classList.add(s.UNMUTED_BUTTON),t.classList.remove(s.MUTED_BUTTON)),this._updateDisplay()},this._onHold=t=>{const e=this._video,i=this._controlBar;if(!e||!i)return;const s=i.className;e.source.volume=t,this._rootEl.classList.add(s.FIXED),i.containerEl.classList.add(s.FIXED),this._updateDisplay()},this._onChange=t=>{const e=this._video;e&&(e.source.volume=t,e.source.muted=!(t>0),this._updateDisplay())},this._onRelease=()=>{const t=this._controlBar;if(!t)return;const e=t.className;this._rootEl.classList.remove(e.FIXED),t.containerEl.classList.remove(e.FIXED)},this._updateDisplay=()=>{const t=this._video,e=this._rootEl;if(!t)return;if(!t.hasAudio())return void(e.disabled=!0);e.disabled=!1;const i=t.source.muted?0:t.source.volume;this._rangeControl.updateStyle(i)},this._controlBar=null,this._rangeControl=new Re,this._createElements(),this._video=null}init(t,e){var i;const s=null===(i=t.mesh)||void 0===i?void 0:i.getTexture(),r=this._rootEl,o=this._buttonEl,n=this._rangeControl,a=e.className,h=a.UNAVAILABLE;s&&s.isVideo()?(r.classList.remove(h),r.classList.add(a.CONTROLS_BUTTON),r.classList.add(a.VOLUME_ROOT),o.classList.add(a.CONTROLS_BUTTON),s.source.muted?o.classList.add(a.MUTED_BUTTON):o.classList.add(a.UNMUTED_BUTTON),t.on(it.RESIZE,this._onResize),r.addEventListener(z,this._onResize),o.addEventListener(C,this._onClick),s.source.addEventListener(U,this._onVolumeChange),s.source.addEventListener(N,this._updateDisplay),s.source.addEventListener(V,this._updateDisplay),n.init(a),n.on(nt,this._onHold),n.on(at,this._onChange),n.on(ht,this._onRelease),this._controlBar=e,this._video=s,this._updateDisplay()):r.classList.add(h)}destroy(t){const e=this._video,i=this._buttonEl,s=this._rootEl;s.className="",i.className="",t.off(it.RESIZE,this._onResize),s.removeEventListener(z,this._onResize),i.removeEventListener(C,this._onClick),e&&(e.source.removeEventListener(U,this._onVolumeChange),e.source.removeEventListener(N,this._updateDisplay),e.source.removeEventListener(V,this._updateDisplay)),this._controlBar=null,this._rangeControl.destroy(),this._video=null}_createElements(){const t=document.createElement(Y),e=document.createElement(H);t.appendChild(this._rangeControl.rootEl),t.appendChild(e),t.title="Toggle Mute",this._rootEl=t,this._buttonEl=e}}class Ce extends Ee{constructor({position:t=be.MAIN_RIGHT,order:e=9999}={}){super({position:t,order:e}),this._onClick=()=>{const t=this._targetEl;t&&(Nt()?this._exitFullscreen():this._requestFullscreen(t))},this._onFullscreenChange=()=>{const t=this.element,e=this._controlBar;if(!e)return;const i=e.className;Nt()?(t.classList.add(i.FULLSCREEN_EXIT_BUTTON),t.classList.remove(i.FULLSCREEN_BUTTON)):(t.classList.add(i.FULLSCREEN_BUTTON),t.classList.remove(i.FULLSCREEN_EXIT_BUTTON))},this.element=document.createElement(Y),this.element.title="Toggle Fullscreen",this._controlBar=null,this._targetEl=null}init(t,e){const i=this.element,s=e.className;this._fullscreenAvailable()?(i.classList.add(s.CONTROLS_BUTTON),i.classList.remove(s.UNAVAILABLE),i.addEventListener(C,this._onClick),this._addFullscreenHandlers(),Nt()?i.classList.add(s.FULLSCREEN_EXIT_BUTTON):i.classList.add(s.FULLSCREEN_BUTTON),this._controlBar=e,this._targetEl=t.rootEl):i.classList.add(s.UNAVAILABLE)}destroy(){const t=this.element;t.className="",t.removeEventListener(C,this._onClick),this._removeFullscreenHandlers(),this._controlBar=null,this._targetEl=null}_fullscreenAvailable(){return $.some((t=>!!document[t]))}_requestFullscreen(t){for(const e of $){const i=t[e];if(i)return void i.call(t)}}_exitFullscreen(){for(const t of J){const e=document[t];if(e)return void e.call(document)}}_addFullscreenHandlers(){tt.forEach((t=>{document.addEventListener(t,this._onFullscreenChange)}))}_removeFullscreenHandlers(){tt.forEach((t=>{document.removeEventListener(t,this._onFullscreenChange)}))}}class Le extends Ee{constructor({position:t=be.MAIN_LEFT,order:e=9999}={}){super({position:t,order:e}),this._onTimeUpdate=()=>{const t=this._video;t&&(this._currentTime=t.source.currentTime,this._updateDisplay())},this._onDurationChange=()=>{const t=this._video;t&&(this._duration=t.source.duration,this._updateDisplay())},this._onCustomTimeChange=t=>{this._currentTime=t.detail.time,this._updateDisplay()},this.element=document.createElement(H),this._video=null,this._currentTime=0,this._duration=0}init(t,e){var i;const s=null===(i=t.mesh)||void 0===i?void 0:i.getTexture(),r=this.element,o=e.className;s&&s.isVideo()?(r.classList.add(o.VIDEO_TIME_DISPLAY),r.classList.remove(o.UNAVAILABLE),s.source.addEventListener(D,this._onTimeUpdate),s.source.addEventListener(B,this._onDurationChange),s.source.addEventListener(Tt,this._onCustomTimeChange),this._video=s,this._currentTime=s.source.currentTime,this._duration=s.source.duration,this._updateDisplay()):r.classList.add(o.UNAVAILABLE)}destroy(){const t=this._video;t&&(this.element.className="",t.source.removeEventListener(D,this._onTimeUpdate),t.source.removeEventListener(B,this._onDurationChange),t.source.removeEventListener(Tt,this._onCustomTimeChange),this._video=null)}_updateDisplay(){const t=this._currentTime,e=Math.floor(t/60),i=Math.floor(t-60*e),s=i<10?`0${i}`:i,r=this._duration,o=Math.floor(r/60),n=Math.floor(r-60*o),a=n<10?`0${n}`:n;this.element.innerText=`${e}:${s} / ${o}:${a}`}}class Ie extends Ee{constructor({resetCamera:t=!0,position:e=be.TOP_RIGHT,order:i=9999}={}){super({position:e,order:i}),this._onClick=()=>{const t=this._viewer,e=this.resetCamera;if(!t||!e)return;const{yaw:i=t.initialYaw,pitch:s=t.initialPitch,zoom:r=t.initialZoom,duration:o=500}=St(e);t.camera.animateTo({yaw:i,pitch:s,zoom:r,duration:o})},this._updatePie=({target:t})=>{const e=this._piePathEl,i=this._rangeCircleEl,s=t.camera,r=s.getHorizontalFov(),o=s.getYawRange(s.zoom),n=.5*r,a=24*Math.PI,h=a*r/360,l=a*(s.yaw+n+90)/360;if(e.setAttribute("stroke-dasharray",`${h} ${a-h}`),e.setAttribute("stroke-dashoffset",`${l}`),isFinite(o.min)&&isFinite(o.max)){const t=45*Math.PI,e=(Ot(o.min,-180,180)-n)/360,s=(Ot(o.max,-180,180)+n)/360,r=t*Math.abs(s-e),a=-t*(e-.25);i.setAttribute("stroke-dasharray",`${r} ${t-r}`),i.setAttribute("stroke-dashoffset",`${a}`)}else i.setAttribute("stroke-dasharray",""),i.setAttribute("stroke-dashoffset","")},this.element=document.createElement(H),this.element.title="Reset view",this.resetCamera=t,this._createPieElements(),this._viewer=null}init(t,e){const i=this.element;t.initialized?this._updatePie({target:t}):t.once(it.READY,this._updatePie);const s=e.className.PIEVIEW_ROOT;i.classList.add(s),this.resetCamera&&i.addEventListener(C,this._onClick),t.on(it.VIEW_CHANGE,this._updatePie),this._viewer=t}destroy(t){const e=this.element;e.removeEventListener(C,this._onClick),e.className="",t.off(it.READY,this._updatePie),t.off(it.VIEW_CHANGE,this._updatePie),this._viewer=null}_createPieElements(){const t=this.element,e=document.createElementNS(bt,"svg");e.setAttribute("viewBox","0 0 48 48"),e.setAttribute("width","100%"),e.setAttribute("height","100%");const i=document.createElementNS(bt,"circle");i.setAttribute("stroke","currentColor"),i.setAttribute("fill","transparent"),i.setAttribute("cx","24"),i.setAttribute("cy","24"),i.setAttribute("r","12"),i.setAttribute("stroke-width","24"),e.appendChild(i);const s=document.createElementNS(bt,"circle");s.setAttribute("stroke","currentColor"),s.setAttribute("fill","transparent"),s.setAttribute("cx","24"),s.setAttribute("cy","24"),s.setAttribute("r","22.5"),s.setAttribute("stroke-width","3"),e.appendChild(s),t.appendChild(e),this._piePathEl=i,this._rangeCircleEl=s}}class Ae extends Ee{constructor({position:t=be.MAIN_RIGHT,order:e=9999}={}){super({position:t,order:e}),this._onClick=()=>{const t=this._viewer;t&&t.vr.enter()},this.element=document.createElement(Y),this.element.title="Enter VR",this._viewer=null}init(t,e){const i=this.element,s=e.className;i.classList.add(s.UNAVAILABLE),i.classList.add(s.VR_BUTTON),i.classList.add(s.CONTROLS_BUTTON),t.vr.isAvailable().then((t=>{t&&i.classList.remove(s.UNAVAILABLE)})),i.addEventListener(C,this._onClick),this._viewer=t}destroy(){const t=this.element;t.className="",t.removeEventListener(C,this._onClick),this._viewer=null}}class Oe extends Ee{constructor({position:t=be.MAIN_RIGHT,order:e=9999}={}){super({position:t,order:e}),this._onClick=()=>{const t=this._viewer,e=this._controlBar;if(!t||!e)return;const i=t.control.gyro;i.enabled?i.disable():Qt.requestSensorPermission().then((t=>{t?i.enable():this.element.classList.add(e.className.UNAVAILABLE)}))},this._updateStyle=()=>{const t=this.element,e=this._viewer,i=this._controlBar;if(!e||!i)return;const s=e.control.gyro,r=i.className;s.enabled?(t.classList.add(r.GYRO_ENABLED),t.classList.remove(r.GYRO_DISABLED)):(t.classList.add(r.GYRO_DISABLED),t.classList.remove(r.GYRO_ENABLED))},this.element=document.createElement(H),this.element.title="Toggle gyroscope control"}init(t,e){const i=this.element,s=e.className;i.addEventListener(C,this._onClick),i.classList.add(s.CONTROLS_BUTTON),i.classList.add(s.UNAVAILABLE);const r=()=>{i.classList.remove(s.UNAVAILABLE),t.control.gyro.on(lt,this._updateStyle),t.control.gyro.on(ut,this._updateStyle)};Ut()?r():Qt.isAvailable().then((t=>{t&&r()})),this._controlBar=e,this._viewer=t,this._updateStyle()}destroy(t){const e=this.element;t.control.gyro.off(lt,this._updateStyle),t.control.gyro.off(ut,this._updateStyle),e.removeEventListener(C,this._onClick),e.className="",this._controlBar=null,this._viewer=null}}class Pe{get enabled(){return!!this._targetEl}get hidden(){return this._controlBar.containerEl.classList.contains(this._hiddenClass)}get _hiddenClass(){return this._controlBar.className.HIDDEN}get _fixedClass(){return this._controlBar.className.FIXED}constructor(t,{initialDelay:e=3e3,delay:i=0,idleDelay:s=3e3}){this._onMouseEnter=()=>{this._isCursorInside=!0,this.show()},this._onMouseLeave=()=>{this._isCursorInside=!1,this._hideAfterDelay()},this._onMouseMove=()=>{this._isFullscreen&&this.showTemporaliy()},this._onHold=t=>{this._isGrabbing=!0,"mouse"===t.pointerType&&(this._isCursorInside=!0),window.addEventListener(g,this._onRelease),this.show()},this._onRelease=()=>{this._isGrabbing=!1,window.removeEventListener(g,this._onRelease),this._hideAfterDelay()},this._onVideoPlay=()=>{this._targetEl&&this._controlBar.containerEl.classList.remove(this._fixedClass)},this._onVideoPause=()=>{this._targetEl&&this._controlBar.containerEl.classList.add(this._fixedClass)},this._onFullscreenChange=()=>{this._isFullscreen=Nt(),this._isFullscreen&&this._hideAfterDelay()},this._controlBar=t,this._initialDelay=e,this._delay=i,this._idleDelay=s,this._timer=-1,this._isCursorInside=!1,this._isGrabbing=!1,this._isFullscreen=!1,this._video=null,this._targetEl=null}enable(t){var e;this._targetEl&&this.disable(t);const i=this._initialDelay,s=t.rootEl;this._targetEl=t.rootEl,this._timer=window.setTimeout((()=>{this.hide()}),i),s.addEventListener(d,this._onHold),s.addEventListener(R,this._onMouseEnter),s.addEventListener(m,this._onMouseMove),s.addEventListener(y,this._onMouseLeave),this._addFullscreenHandlers();const r=null===(e=t.mesh)||void 0===e?void 0:e.getTexture();r&&r.isVideo()&&(r.isPaused()&&this._controlBar.containerEl.classList.add(this._fixedClass),r.source.addEventListener(F,this._onVideoPlay),r.source.addEventListener(M,this._onVideoPause),this._video=r)}disable(t){if(!this._targetEl)return;const e=this._controlBar,i=t.rootEl,s=this._video;i.removeEventListener(d,this._onHold),window.removeEventListener(g,this._onRelease),i.removeEventListener(R,this._onMouseEnter),i.removeEventListener(m,this._onMouseMove),i.removeEventListener(y,this._onMouseLeave),this._removeFullscreenHandlers(),window.clearTimeout(this._timer),e.containerEl.classList.remove(this._fixedClass),s&&(s.source.removeEventListener(F,this._onVideoPlay),s.source.removeEventListener(M,this._onVideoPause)),this._isCursorInside=!1,this._isGrabbing=!1,this._video=null,this._targetEl=null}show(){this._clearHideTimer(),this._controlBar.containerEl.classList.remove(this._hiddenClass)}showTemporaliy(){this.show(),this._hideAfterDelay(this._idleDelay)}hide(){this._clearHideTimer(),this._controlBar.containerEl.classList.add(this._hiddenClass)}_clearHideTimer(){this._timer&&(window.clearTimeout(this._timer),this._timer=-1)}_hideAfterDelay(t=this._delay){this._isGrabbing||!this._isFullscreen&&this._isCursorInside||(this._clearHideTimer(),t<=0?this.hide():this._timer=window.setTimeout((()=>{this.hide()}),t))}_addFullscreenHandlers(){tt.forEach((t=>{document.addEventListener(t,this._onFullscreenChange)}))}_removeFullscreenHandlers(){tt.forEach((t=>{document.removeEventListener(t,this._onFullscreenChange)}))}}class Se{constructor(){this._onKeyDown=t=>{const e=this._video;if(!e)return;t.preventDefault(),t.stopPropagation();const i=e.source,s=null!=t.keyCode?K[t.keyCode]:Z[t.key];switch(s){case"LEFT":case"RIGHT":return this._changeVideoTime(i,"RIGHT"===s);case"UP":case"DOWN":return this._changeVideoVolume(i,"UP"===s)}(32===t.keyCode||" "===t.key)&&this._toggleVideo(e)}}enable(t,e){this._video=e,t.addEventListener(x,this._onKeyDown,!0)}disable(t){this._video=null,t.removeEventListener(x,this._onKeyDown,!0)}_changeVideoTime(t,e){const i=e?5:-5;t.currentTime+=i,t.dispatchEvent(new CustomEvent(Tt,{detail:{time:t.currentTime}}))}_changeVideoVolume(t,e){const i=e?.1:-.1;t.muted?t.volume=It(i,0,1):t.volume=It(t.volume+i,0,1),t.volume>0?t.muted=!1:t.muted=!0}_toggleVideo(t){t.isPaused()?t.source.play():t.source.pause()}}class Fe{get rootEl(){return this._rootEl}get containerEl(){return this._containerEl}get backgroundEl(){return this._bgEl}get items(){return this._items}get customItems(){return this._customItems}constructor({autoHide:t,showBackground:e,clickToPlay:i=!0,keyboardControls:s=!0,progressBar:r=!0,playButton:o=!0,volumeButton:n=!0,fullscreenButton:a=!0,videoTime:h=!0,pieView:l=!0,vrButton:u=!0,gyroButton:c=!0,className:_={},customItems:d=[]}={}){var m;this._onStaticClick=({target:t,isTouch:e})=>{var i;const s=this._autoHider;if(e){if(!s.enabled)return;s.hidden?s.showTemporaliy():s.hide()}else{if(!this.clickToPlay)return;const e=null===(i=t.mesh)||void 0===i?void 0:i.getTexture();if(!e||!e.isVideo())return;e.isPaused()?e.source.play():e.source.pause()}},this._onNewSrcLoad=({target:t})=>{const e=this._items;this._updateBackground(t),this._updateAutoHide(t),this._updateKeyboardHandler(t),Object.keys(e).forEach((i=>{e[i].forEach((e=>{e.destroy(t,this),e.init(t,this)}))}))},this.autoHide=t,this.showBackground=e,this.clickToPlay=i,this.keyboardControls=s,this.progressBar=r,this.playButton=o,this.volumeButton=n,this.fullscreenButton=a,this.videoTime=h,this.pieView=l,this.vrButton=u,this.gyroButton=c,this.className=Object.assign(Object.assign({},Fe.DEFAULT_CLASS),_);const g=null!==(m=_.CONTROLS_ROOT)&&void 0!==m?m:Fe.DEFAULT_CLASS.CONTROLS_ROOT;this._rootEl=Ct(g),this._createPositionWrappers(),this._items=Object.keys(Fe.POSITION).reduce(((t,e)=>(t[Fe.POSITION[e]]=[],t)),{}),this._customItems=d,this._autoHider=new Pe(this,St(t)),this._videoControl=new Se,d.forEach((t=>{this._items[t.position].push(t)}))}init(t){const e=t.rootEl,i=this._rootEl,s=this._createDefaultItems();this._updateBackground(t),this._updateAutoHide(t),this._updateKeyboardHandler(t),e.appendChild(i),this._addItem(t,s),this._addItem(t,this._customItems),t.on(it.PROJECTION_CHANGE,this._onNewSrcLoad),t.on(it.STATIC_CLICK,this._onStaticClick)}destroy(t){const e=t.rootEl,i=this._rootEl,s=this._items;i.parentElement===e&&e.removeChild(i),Object.keys(s).forEach((e=>{s[e].forEach((e=>{e.destroy(t,this)})),s[e]=[]})),this._clearItemElements(),this._autoHider.disable(t),this._videoControl.disable(e),t.off(it.PROJECTION_CHANGE,this._onNewSrcLoad),t.off(it.STATIC_CLICK,this._onStaticClick)}_addItem(t,e){for(const i of e){const e=this._items[i.position],s=this._wrapperEl[i.position],r=Pt(e,(t=>t.order>i.order));if(r>=0){const t=e[r].element;e.splice(r,0,i),s.insertBefore(i.element,t)}else e.push(i),s.appendChild(i.element);i.init(t,this)}}_createPositionWrappers(){const t=Object.assign(Object.assign({},Fe.DEFAULT_CLASS),this.className),e=this._rootEl,i=Ct(t.CONTROLS_BG),s=Ct(t.CONTROLS_FLOAT_LEFT),r=Ct(t.CONTROLS_FLOAT_RIGHT);e.appendChild(s),e.appendChild(r);const o=Ct(t.CONTROLS_MAIN),n=Ct(t.CONTROLS_TOP),a=Ct(t.CONTROLS_BOTTOM),h=Ct(t.CONTROLS_MID),l=Ct(t.CONTROLS_LEFT),u=Ct(t.CONTROLS_RIGHT);h.appendChild(l),h.appendChild(u),o.appendChild(i),o.appendChild(n),o.appendChild(h),o.appendChild(a),e.appendChild(o),this._bgEl=i,this._containerEl=o,this._wrapperEl={[Fe.POSITION.MAIN_TOP]:n,[Fe.POSITION.MAIN_LEFT]:l,[Fe.POSITION.MAIN_RIGHT]:u,[Fe.POSITION.MAIN_BOTTOM]:a,[Fe.POSITION.TOP_LEFT]:s,[Fe.POSITION.TOP_RIGHT]:r}}_clearItemElements(){Object.keys(Fe.POSITION).map((t=>Fe.POSITION[t])).map((t=>this._wrapperEl[t])).forEach((t=>{for(;t.firstChild;)t.removeChild(t.firstChild)}))}_updateAutoHide(t){var e;const i=this.autoHide,s=this._autoHider;if(null!=i)i?s.enable(t):s.disable(t);else{const i=null===(e=t.mesh)||void 0===e?void 0:e.getTexture();i&&i.isVideo()?s.enable(t):s.disable(t)}}_updateBackground(t){var e,i;const s=this._bgEl,r=this.showBackground,o=null!==(e=this.className.HIDDEN)&&void 0!==e?e:Fe.DEFAULT_CLASS.HIDDEN;if(null!=r)r?s.classList.remove(o):s.classList.add(o);else{const e=null===(i=t.mesh)||void 0===i?void 0:i.getTexture();e&&e.isVideo()?s.classList.remove(o):s.classList.add(o)}}_updateKeyboardHandler(t){var e;const i=t.rootEl,s=this._videoControl,r=null===(e=t.mesh)||void 0===e?void 0:e.getTexture();this.keyboardControls&&r&&r.isVideo()?s.enable(i,r):s.disable(i)}_createDefaultItems(){const t=[];return this.progressBar&&t.push(new ye(St(this.progressBar))),this.playButton&&t.push(new xe(St(this.playButton))),this.volumeButton&&t.push(new we(St(this.volumeButton))),this.gyroButton&&t.push(new Oe(St(this.gyroButton))),this.vrButton&&t.push(new Ae(St(this.vrButton))),this.fullscreenButton&&t.push(new Ce(St(this.fullscreenButton))),this.videoTime&&t.push(new Le(St(this.videoTime))),this.pieView&&t.push(new Ie(St(this.pieView))),t}}Fe.DEFAULT_CLASS=Te,Fe.POSITION=be;class Me{constructor({src:t,video:e=!1}){this.src=t,this.video=e}updateCamera(t){t.resetRange()}updateControl(t){t.ignoreZoomScale=!1}}class Ne{constructor(){this.needsUpdate=!0}destroy(t){}}class Ue extends Ne{constructor(t,e,i){super(),this.texture=e,this._webglTexture=t.createWebGLCubeTexture(e,e.width),this._cubemapOrder=i}destroy(t){this.texture.destroy(),t.deleteTexture(this._webglTexture)}update(t,e,i){const s=this.texture;t.pixelStorei(t.UNPACK_FLIP_Y_WEBGL,s.flipY),t.uniform1i(e,0),t.activeTexture(t.TEXTURE0),t.bindTexture(t.TEXTURE_CUBE_MAP,this._webglTexture);Mt(s.sources,this._cubemapOrder).forEach(((e,s)=>{i?t.texSubImage2D(t.TEXTURE_CUBE_MAP_POSITIVE_X+s,0,0,0,t.RGBA,t.UNSIGNED_BYTE,e):t.texImage2D(t.TEXTURE_CUBE_MAP_POSITIVE_X+s,0,t.RGBA,t.RGBA,t.UNSIGNED_BYTE,e)})),s.isVideo()||(this.needsUpdate=!1)}}class De{get size(){return this._size}constructor(t,e){var i;this.texture=t,this._renderingOrder=Mt(!(i=6)||i<=0?[]:Array.apply(0,Array(i)).map(((t,e)=>e)),e);const s=document.createElement("canvas");this._calcRenderingSize(),s.width=this._size,s.height=this._size,this._canvas=s,this._ctx=s.getContext("2d")}destroy(){const t=this._canvas;t.width=1,t.height=1,this._canvas=null}draw(t,e){const i=this._size,s=this.texture;let r=0;for(let o=0;o<this._row;o++)for(let n=0;n<this._column;n++){const a=i*n,h=i*o,l=this._renderingOrder[r];this._ctx.drawImage(s.source,a,h,i,i,0,0,i,i),e?t.texSubImage2D(t.TEXTURE_CUBE_MAP_POSITIVE_X+l,0,0,0,t.RGBA,t.UNSIGNED_BYTE,this._canvas):t.texImage2D(t.TEXTURE_CUBE_MAP_POSITIVE_X+l,0,t.RGBA,t.RGBA,t.UNSIGNED_BYTE,this._canvas),r++}}_calcRenderingSize(){const{width:t,height:e}=this.texture,i=t/e;i===1/6?(this._size=t,this._row=6,this._column=1):6===i?(this._size=e,this._row=1,this._column=6):i===2/3?(this._size=.5*t,this._row=3,this._column=2):(this._size=t/3,this._row=2,this._column=3)}}class Be extends Ne{get texture(){return this._painter.texture}constructor(t,e,i){super(),this._painter=new De(e,i),this._webglTexture=t.createWebGLCubeTexture(e,this._painter.size)}destroy(t){t.deleteTexture(this._webglTexture),this._painter.destroy()}update(t,e,i){const s=this.texture;t.pixelStorei(t.UNPACK_FLIP_Y_WEBGL,!1),t.uniform1i(e,0),t.activeTexture(t.TEXTURE0),t.bindTexture(t.TEXTURE_CUBE_MAP,this._webglTexture),this._painter.draw(t,i),s.isVideo()||(this.needsUpdate=!1)}}class Ve extends ve{constructor(t,e){super(),this.vao=t,this.program=e}destroy(t){t.releaseVAO(this.vao),t.releaseShaderResources(this.program)}getTexture(){const t=this.program.uniforms.uTexture;return t.sourceTexture||t.texture}}class ze{constructor(t,e,i,s){this.program=t.createProgram(e,i),this.uniforms=s,this.uniformLocations=t.getUniformLocations(this.program,s)}}class Ge{constructor(t,e){this.data=t,this.itemSize=e,this.count=t.length/e}}class He{constructor(t,e,i){this.vertices=new Ge(new Float32Array(t),3),this.indicies=new Ge(new Uint16Array(e),1),this.uvs=new Ge(new Float32Array(i),2)}}class Ye extends He{constructor({order:t,rotateUV:e}){const i=1/3,s=[];for(let t=1;t>=0;t--)for(let e=0;e<3;e++){const r=[e*i,.5*t,(e+1)*i,.5*t,(e+1)*i,.5*(t+1),e*i,.5*(t+1)];s.push(r)}e&&e.forEach(((t,e)=>{if(t===Et.ZERO)return;const i=s[e];let r;r=t===Et.CW_90?[1,2,3,0]:t===Et.CCW_90?[3,0,1,2]:[2,3,0,1];const o=Array(i.length);for(let t=0;t<i.length/2;t++)o[2*t+0]=i[2*r[t]+0],o[2*t+1]=i[2*r[t]+1];s[e]=o}));super([1,-1,1,-1,-1,1,-1,1,1,1,1,1,-1,-1,-1,1,-1,-1,1,1,-1,-1,1,-1,-1,1,-1,1,1,-1,1,1,1,-1,1,1,-1,-1,1,1,-1,1,1,-1,-1,-1,-1,-1,1,-1,-1,1,-1,1,1,1,1,1,1,-1,-1,-1,1,-1,-1,-1,-1,1,-1,-1,1,1],[0,1,2,0,2,3,4,5,6,4,6,7,8,9,10,8,10,11,12,13,14,12,14,15,16,17,18,16,18,19,20,21,22,20,22,23],Mt(s,t,"BFUDRL").reduce(((t,e)=>t.concat(e)),[]))}}class We extends Ne{constructor(t,e){super(),this.texture=e,this._webglTexture=t.createWebGLTexture(e)}destroy(t){this.texture.destroy(),t.deleteTexture(this._webglTexture)}update(t,e,i){const s=this.texture,r=s.isVideo();t.pixelStorei(t.UNPACK_FLIP_Y_WEBGL,s.flipY),t.uniform1i(e,0),t.activeTexture(t.TEXTURE0),t.bindTexture(t.TEXTURE_2D,this._webglTexture),!r&&i?t.texSubImage2D(t.TEXTURE_2D,0,0,0,t.RGBA,t.UNSIGNED_BYTE,s.source):t.texImage2D(t.TEXTURE_2D,0,t.RGBA,t.RGBA,t.UNSIGNED_BYTE,s.source),r||(this.needsUpdate=!1)}}var ke="#define GLSLIFY 1\nattribute vec3 position;attribute vec2 uv;uniform mat4 uMVMatrix;uniform mat4 uPMatrix;varying highp vec2 vUV;void main(){vUV=uv;gl_Position=uPMatrix*uMVMatrix*vec4(position,1.0);}",Xe="#define GLSLIFY 1\nuniform sampler2D uTexture;varying highp vec2 vUV;void main(){gl_FragColor=texture2D(uTexture,vUV.st);}";class je extends He{constructor(t){const e=[],i=[],s=[],r=[-.5,.5],o=1/60,n=t*o;for(let a=0;a<2;a++){const h=r[a];for(let r=0;r<=60;r++){const l=r*n+Math.PI-.5*t,u=Math.cos(l),c=Math.sin(l),_=r*o,d=a;if(s.push(_,d),e.push(u,h,c),0===a&&r<60){const t=r,e=t+60+1;i.push(t,e,t+1,e,e+1,t+1)}}}super(e,i,s)}}class qe extends He{constructor(){const t=60,e=-.5*Math.PI,i=[],s=[],r=[];let o,n;for(o=0;o<=60;o++){const a=(o/60-.5)*Math.PI,h=Math.sin(a),l=Math.cos(a);for(n=0;n<=t;n++){const a=2*(n/t-.5)*Math.PI+e,u=Math.sin(a),c=Math.cos(a)*l,_=h,d=u*l,m=n/t,g=o/60;if(i.push(m,g),s.push(c,_,d),n!==t&&60!==o){const e=61*o+n,i=e+t+1;r.push(e,e+1,i,i,e+1,i+1)}}}super(s,r,i)}}class Ke extends Ne{constructor(t){super(),this.val=t}update(t,e){t.uniform1f(e,this.val),this.needsUpdate=!1}}class Ze extends He{constructor(t=2,e=2,i=-1){const s=.5*t,r=.5*e;super([-s,-r,i,s,-r,i,-s,r,i,s,r,i],[0,1,2,2,1,3],[0,0,1,0,0,1,1,1])}}class $e extends Ne{constructor(t){super(),this.val=t}update(t,e){t.uniform4fv(e,this.val.reduce(((t,e)=>[...t,...e]),[])),this.needsUpdate=!1}}class Qe extends Me{constructor(t){super(t),this._mode=t.mode}createMesh(t,e){let i,s;if(this._mode===Qe.MODE.LEFT_RIGHT)i=[.5,1,0,0],s=[.5,1,.5,0];else i=[1,.5,0,0],s=[1,.5,0,.5];const r={uTexture:new We(t,e),uEye:new Ke(0),uTexScaleOffset:new $e([i,s])},o=new qe,n=new ze(t,"#define GLSLIFY 1\nattribute vec3 position;attribute vec2 uv;uniform mat4 uMVMatrix;uniform mat4 uPMatrix;uniform vec4 uTexScaleOffset[2];uniform float uEye;varying highp vec2 vUV;void main(){vec4 scaleOffset=uTexScaleOffset[int(uEye)];vUV=uv.xy*scaleOffset.xy+scaleOffset.zw;gl_Position=uPMatrix*uMVMatrix*vec4(position,1.0);}",Xe,r),a=t.createVAO(o,n);return new Ve(a,n)}}Qe.MODE={LEFT_RIGHT:"left_right",TOP_BOTTOM:"top_bottom"};class Je extends te{constructor(t,e,i){super({width:e,height:i,flipY:!1}),this.glTexture=t}isVideo(){return!1}destroy(){}}class ti{get outputTexture(){return this._outputTexture}constructor(t,e,i){this._ctx=t,this._outputWidth=e,this._outputHeight=i;const s=t.gl;this._fbo=t.createFramebuffer(e,i),this._outputTexture=new Je(this._fbo.texture,e,i),this._program=t.createProgram("#define GLSLIFY 1\nattribute vec2 aPosition;varying vec2 vUV;void main(){vUV=aPosition*0.5+0.5;gl_Position=vec4(aPosition,0.0,1.0);}","precision highp float;\n#define GLSLIFY 1\nvarying vec2 vUV;uniform sampler2D uTexture;uniform int uMode;uniform vec3 uRotYPR;uniform float uHFov;uniform float uVFov;uniform float uFisheyeFov;uniform vec2 uImgSize;const float PI=3.14159265359;mat3 buildRotation(float yaw,float pitch,float roll){float cy=cos(yaw),sy=sin(yaw);float cp=cos(pitch),sp=sin(pitch);float cr=cos(roll),sr=sin(roll);mat3 Ry=mat3(cy,0.0,sy,0.0,1.0,0.0,-sy,0.0,cy);mat3 Rx=mat3(1.0,0.0,0.0,0.0,cp,-sp,0.0,sp,cp);mat3 Rz=mat3(cr,-sr,0.0,sr,cr,0.0,0.0,0.0,1.0);return Rz*(Rx*Ry);}mat3 myTranspose(mat3 m){return mat3(m[0][0],m[1][0],m[2][0],m[0][1],m[1][1],m[2][1],m[0][2],m[1][2],m[2][2]);}vec3 dirToErpCoord(vec3 dir){float lon=atan(dir.x,dir.z);float lat=asin(clamp(dir.y,-1.0,1.0));float halfLon=uHFov*0.5;float halfLat=uVFov*0.5;if(abs(lon)>halfLon||abs(lat)>halfLat){return vec3(0.0,0.0,-1.0);}float u=(lon/uHFov+0.5)*(uImgSize.x-1.0);float v=(0.5-lat/uVFov)*(uImgSize.y-1.0);if(u<0.0||u>=uImgSize.x||v<0.0||v>=uImgSize.y){return vec3(0.0,0.0,-1.0);}return vec3(u,v,1.0);}vec3 dirToFisheyeCoord(vec3 dir){float len=length(dir);float theta=acos(clamp(dir.z/len,-1.0,1.0));if(dir.z<=0.0)return vec3(0.0,0.0,-1.0);float maxTheta=uFisheyeFov*0.5;if(theta>maxTheta)return vec3(0.0,0.0,-1.0);float fisheyeRadius=min(uImgSize.x,uImgSize.y)*0.5;float fisheyeFocalLen=fisheyeRadius/maxTheta;float r=fisheyeFocalLen*theta;float imgAngle=atan(dir.x,-dir.y);float ix=uImgSize.x*0.5+r*sin(imgAngle);float iy=uImgSize.y*0.5+r*cos(imgAngle);if(ix<0.0||ix>=uImgSize.x||iy<0.0||iy>=uImgSize.y){return vec3(0.0,0.0,-1.0);}return vec3(ix,iy,1.0);}void main(){mat3 R=buildRotation(uRotYPR.x,uRotYPR.y,uRotYPR.z);mat3 Rinv=myTranspose(R);float phi=(vUV.x-0.5)*2.0*PI;float lat=(vUV.y-0.5)*PI;float cosLat=cos(lat);vec3 worldDir=vec3(cosLat*sin(phi),sin(lat),cosLat*cos(phi));vec3 imgDir=Rinv*worldDir;vec3 imgCoord;if(uMode==0){imgCoord=dirToErpCoord(imgDir);}else{imgCoord=dirToFisheyeCoord(imgDir);}if(imgCoord.z>0.0){vec2 uv=vec2(imgCoord.x/uImgSize.x,imgCoord.y/uImgSize.y);gl_FragColor=texture2D(uTexture,uv);}else{gl_FragColor=vec4(0.0,0.0,0.0,1.0);}}"),this._uniformLocations={uTexture:s.getUniformLocation(this._program,"uTexture"),uMode:s.getUniformLocation(this._program,"uMode"),uRotYPR:s.getUniformLocation(this._program,"uRotYPR"),uHFov:s.getUniformLocation(this._program,"uHFov"),uVFov:s.getUniformLocation(this._program,"uVFov"),uFisheyeFov:s.getUniformLocation(this._program,"uFisheyeFov"),uImgSize:s.getUniformLocation(this._program,"uImgSize")};const r=s.createBuffer();if(!r)throw new Error("无法创建顶点缓冲区");this._quadBuffer=r,s.bindBuffer(s.ARRAY_BUFFER,this._quadBuffer),s.bufferData(s.ARRAY_BUFFER,new Float32Array([-1,-1,1,-1,-1,1,1,1]),s.STATIC_DRAW),s.bindBuffer(s.ARRAY_BUFFER,null)}render(t,e,i,s){const r=this._ctx.gl,o=this._uniformLocations,n=r.getParameter(r.FRAMEBUFFER_BINDING),a=r.getParameter(r.VIEWPORT),h=r.getParameter(r.CURRENT_PROGRAM),l=r.getParameter(r.COLOR_CLEAR_VALUE),u=r.getParameter(r.ACTIVE_TEXTURE),c=r.getParameter(r.TEXTURE_BINDING_2D),_=r.getParameter(r.ARRAY_BUFFER_BINDING),d=r,m=d.bindVertexArray?null:r.getExtension("OES_vertex_array_object"),g=d.bindVertexArray?r.getParameter(r.VERTEX_ARRAY_BINDING):m?r.getParameter(m.VERTEX_ARRAY_BINDING_OES):null;d.bindVertexArray?r.bindVertexArray(null):m&&m.bindVertexArrayOES(null),this._ctx.bindFramebuffer(this._fbo.framebuffer),r.viewport(0,0,this._outputWidth,this._outputHeight),r.clearColor(0,0,0,1),r.clear(r.COLOR_BUFFER_BIT),r.useProgram(this._program);const p=t=>t*Math.PI/180;r.uniform1i(o.uMode,"fisheye"===s.mode?1:0),r.uniform3f(o.uRotYPR,p(-s.yaw),p(-s.pitch),p(s.roll)),r.uniform1f(o.uHFov,p(s.hfov)),r.uniform1f(o.uVFov,p(s.vfov)),r.uniform1f(o.uFisheyeFov,p(s.fisheyeFov)),r.uniform2f(o.uImgSize,e,i),r.activeTexture(r.TEXTURE0),r.bindTexture(r.TEXTURE_2D,t),r.uniform1i(o.uTexture,0),r.bindBuffer(r.ARRAY_BUFFER,this._quadBuffer);const v=r.getAttribLocation(this._program,"aPosition");r.enableVertexAttribArray(v),r.vertexAttribPointer(v,2,r.FLOAT,!1,0,0),r.drawArrays(r.TRIANGLE_STRIP,0,4),r.disableVertexAttribArray(v),r.useProgram(h),r.activeTexture(u),r.bindTexture(r.TEXTURE_2D,c),r.bindBuffer(r.ARRAY_BUFFER,_),d.bindVertexArray?r.bindVertexArray(g):m&&m.bindVertexArrayOES(g),r.bindFramebuffer(r.FRAMEBUFFER,n),r.viewport(a[0],a[1],a[2],a[3]),r.clearColor(l[0],l[1],l[2],l[3])}destroy(){const t=this._ctx.gl;t.deleteBuffer(this._quadBuffer),t.deleteProgram(this._program),this._ctx.deleteFramebuffer(this._fbo)}}class ei extends Ne{constructor(t,e){super(),this.texture=t,this._onDestroy=null!=e?e:null,this._keepNeedsUpdateForDestroy=!!this._onDestroy,this.needsUpdate=!0}destroy(t){this._onDestroy&&(this._onDestroy(),this._onDestroy=null)}update(t,e,i){t.pixelStorei(t.UNPACK_FLIP_Y_WEBGL,!1),t.uniform1i(e,0),t.activeTexture(t.TEXTURE0),t.bindTexture(t.TEXTURE_2D,this.texture.glTexture),this._keepNeedsUpdateForDestroy||(this.needsUpdate=!1)}}class ii extends Ne{constructor(t){super(),this.val=t}update(t,e){t.uniform1i(e,this.val),this.needsUpdate=!1}}class si extends Ne{constructor(t,e){super(),this.val=[t,e]}update(t,e){t.uniform2f(e,this.val[0],this.val[1]),this.needsUpdate=!1}}class ri extends Ne{constructor(t,e,i){super(),this.val=[t,e,i]}update(t,e){t.uniform3f(e,this.val[0],this.val[1],this.val[2]),this.needsUpdate=!1}}const oi=t=>t*Math.PI/180;class ni extends Ne{constructor(t,e,i,s,r){super(),this._imgSizeUniform=null,this._initialized=!1,this._scaleCanvas=null,this._scaleCtx=null,this._textureAllocated=!1,this._allocatedWidth=0,this._allocatedHeight=0,this._isImmutableTexture=!1,this.texture=t,this._webglTexture=e,this._targetWidth=i||0,this._targetHeight=s||0,this._isImmutableTexture=r||!1,this._targetWidth>0&&this._targetHeight>0&&this._initScaleCanvas()}setImgSizeUniform(t){this._imgSizeUniform=t}destroy(t){this.texture.destroy(),this._scaleCanvas=null,this._scaleCtx=null,t.deleteTexture(this._webglTexture)}update(t,e,i){const s=this.texture,r=s.isVideo();if(t.pixelStorei(t.UNPACK_FLIP_Y_WEBGL,0),t.uniform1i(e,0),t.activeTexture(t.TEXTURE0),t.bindTexture(t.TEXTURE_2D,this._webglTexture),r){const e=s.source;if(e.readyState<2||e.videoWidth<=0||e.videoHeight<=0)return void this._uploadPlaceholder(t);const i=this._targetWidth>0?this._targetWidth:e.videoWidth,r=this._targetHeight>0?this._targetHeight:e.videoHeight;if(this._imgSizeUniform){const t=this._imgSizeUniform.val;t[0]===i&&t[1]===r||(this._imgSizeUniform.val=[i,r],this._imgSizeUniform.needsUpdate=!0)}}let o,n,a=s.source;if(r&&this._scaleCanvas&&this._scaleCtx){const t=s.source;this._scaleCtx.drawImage(t,0,0,this._targetWidth,this._targetHeight),a=this._scaleCanvas}if(this._targetWidth>0&&this._targetHeight>0)o=this._targetWidth,n=this._targetHeight;else if(r){const t=s.source;o=t.videoWidth,n=t.videoHeight}else o=a.width||0,n=a.height||0;this._textureAllocated&&this._allocatedWidth===o&&this._allocatedHeight===n&&o>0&&n>0?t.texSubImage2D(t.TEXTURE_2D,0,0,0,t.RGBA,t.UNSIGNED_BYTE,a):(this._isImmutableTexture?t.texSubImage2D(t.TEXTURE_2D,0,0,0,t.RGBA,t.UNSIGNED_BYTE,a):t.texImage2D(t.TEXTURE_2D,0,t.RGBA,t.RGBA,t.UNSIGNED_BYTE,a),this._textureAllocated=!0,this._allocatedWidth=o,this._allocatedHeight=n),this._initialized=!0,r||(this.needsUpdate=!1)}getEffectiveTargetWidth(){return this._targetWidth}getEffectiveTargetHeight(){return this._targetHeight}_initScaleCanvas(){try{if(this._scaleCanvas=new OffscreenCanvas(this._targetWidth,this._targetHeight),this._scaleCtx=this._scaleCanvas.getContext("2d"),!this._scaleCtx)throw new Error("OffscreenCanvas getContext('2d') returned null")}catch(t){"undefined"!=typeof document?(this._scaleCanvas=document.createElement("canvas"),this._scaleCanvas.width=this._targetWidth,this._scaleCanvas.height=this._targetHeight,this._scaleCtx=this._scaleCanvas.getContext("2d"),this._scaleCtx||(console.warn("[WideAngleRealtimeProjection] Canvas getContext('2d') returned null. Input scaling disabled."),this._scaleCanvas=null,this._targetWidth=0,this._targetHeight=0)):(console.warn("[WideAngleRealtimeProjection] OffscreenCanvas not available and document is undefined (Worker/SSR). Input scaling disabled."),this._scaleCanvas=null,this._scaleCtx=null,this._targetWidth=0,this._targetHeight=0)}}_uploadPlaceholder(t){if(this._initialized)return;const e=new Uint8Array([0,0,0,255]);if(t.texImage2D(t.TEXTURE_2D,0,t.RGBA,1,1,0,t.RGBA,t.UNSIGNED_BYTE,e),this._imgSizeUniform){const t=this._imgSizeUniform.val;(t[0]<=0||t[1]<=0)&&(this._imgSizeUniform.val=[1,1],this._imgSizeUniform.needsUpdate=!0)}this._initialized=!0}}var ai={__proto__:null,default:pe,Autoplay:ae,AutoResizer:ne,Camera:Ht,CameraAnimation:Gt,CameraPath:le,Motion:zt,Object3D:ve,View360Error:l,WebGLRenderer:ge,XRManager:ue,PanoControl:Jt,RotateControl:Xt,ZoomControl:Kt,GyroControl:Qt,ControlBar:Fe,ControlBarItem:Ee,FullscreenButton:Ce,PieView:Ie,PlayButton:xe,ProgressBar:ye,VideoTime:Le,VolumeControl:we,LoadingSpinner:fe,Projection:Me,CubemapProjection:class extends Me{constructor(t){super(t);const{cubemapOrder:e="RLUDFB",cubemapFlipX:i=!1}=t;this._cubemapOrder=e,this._cubemapFlipX=i}createMesh(t,e){const i=this._cubemapOrder,s=this._cubemapFlipX,r={uTexture:e.isCube()?new Ue(t,e,i):new Be(t,e,i)},o=new Ye({order:i}),n=new ze(t,"#define GLSLIFY 1\nattribute vec3 position;attribute vec2 uv;uniform mat4 uMVMatrix;uniform mat4 uPMatrix;varying highp vec3 vPos;void main(){vPos=position;gl_Position=uPMatrix*uMVMatrix*vec4(position,1.0);}","#define GLSLIFY 1\nuniform samplerCube uTexture;varying highp vec3 vPos;void main(){gl_FragColor=textureCube(uTexture,vec3(vPos.x,vPos.y,-vPos.z));}",r),a=t.createVAO(o,n),h=new Ve(a,n);return s&&(h.scale[0]=-1),h.updateMatrix(),h}},CubestripProjection:class extends Me{constructor(t){super(t);const{cubemapOrder:e="RLUDFB",cubemapFlipX:i=!1}=t;this._cubemapOrder=e,this._cubemapFlipX=i}createMesh(t,e){const i=this._cubemapOrder,s=this._cubemapFlipX,r={uTexture:new We(t,e)},o=new Ye({order:i}),n=new ze(t,ke,Xe,r),a=t.createVAO(o,n),h=new Ve(a,n);return s&&(h.scale[0]=-1),h.updateMatrix(),h}},CylindricalProjection:class extends Me{constructor(t){super(t);const{partial:e=!1}=t;this._partial=e,this._aspect=1,this._halfHeight=0,this._mesh=null}createMesh(t,i){if(this._mesh)return this._mesh;const s=this._partial,{width:r,height:o}=i,n=r/o,a=180/n,h=s?1:2*Math.tan(a*_t),l=s?n:2*Math.PI,u=new je(l),c=new ze(t,ke,Xe,{uTexture:new We(t,i)}),_=t.createVAO(u,c),d=new Ve(_,c);return d.scale[1]=h,e.quat.identity(d.rotation),e.quat.rotateY(d.rotation,d.rotation,-Math.PI/2),d.updateMatrix(),this._aspect=n,this._halfHeight=.5*h,this._mesh=d,d}updateCamera(t){super.updateCamera(t);const e=this._mesh,i=this._aspect,s=this._halfHeight;if(!e)return;if(this._partial){const e=.5*i*dt;t.restrictYawRange(-e,e)}const r=Math.atan2(s,1)*dt,o=Math.tan(t.fov*_t*.5)/(s*t.aspect);t.restrictPitchRange(-r,r),t.restrictZoomRange(o,1/0),t.restrictRenderHeight(2*s)}},EquiangularProjection:class extends Me{createMesh(t,e){const i={uTexture:new We(t,e)},s=new Ye({order:"LFRDBU",rotateUV:[Et.ZERO,Et.ZERO,Et.ZERO,Et.CW_90,Et.CCW_90,Et.CW_90]}),r=new ze(t,ke,"#define PI 3.14159265359\nprecision mediump float;\n#define GLSLIFY 1\nuniform sampler2D uTexture;varying highp vec2 vUV;const vec2 OPERATE_COORDS_RANGE=vec2(-1.0,1.0);const vec2 TEXTURE_COORDS_RANGE=vec2(0.0,1.0);const float ONE_THIRD=1.0/3.0;const float EAC_CONST=2.0/PI;float scale(vec2 domainRange,vec2 targetRange,float val){float unit=1.0/(domainRange[1]-domainRange[0]);return targetRange[0]+(targetRange[1]-targetRange[0])*(val-domainRange[0])*unit;}void main(void){float transformedCoordX;float transformedCoordY;float texRangeXStart=floor(vUV.s*3.)*ONE_THIRD;float texRangeYStart=floor(vUV.t*2.)*0.5;vec2 orgTextureRangeX=vec2(texRangeXStart,texRangeXStart+ONE_THIRD);vec2 orgTextureRangeY=vec2(texRangeYStart,texRangeYStart+0.5);float px=scale(orgTextureRangeX,OPERATE_COORDS_RANGE,vUV.s);float py=scale(orgTextureRangeY,OPERATE_COORDS_RANGE,vUV.t);float qu=EAC_CONST*atan(px)+0.5;float qv=EAC_CONST*atan(py)+0.5;transformedCoordX=scale(TEXTURE_COORDS_RANGE,orgTextureRangeX,qu);transformedCoordY=scale(TEXTURE_COORDS_RANGE,orgTextureRangeY,qv);gl_FragColor=texture2D(uTexture,vec2(transformedCoordX,transformedCoordY));}",i),o=t.createVAO(s,r);return new Ve(o,r)}},EquirectProjection:class extends Me{constructor(t){super(t)}createMesh(t,e){const i={uTexture:new We(t,e)},s=new qe,r=new ze(t,ke,Xe,i),o=t.createVAO(s,r);return new Ve(o,r)}},LittlePlanetProjection:class extends Me{constructor(t){super(t)}createMesh(t,e){e.wrapS=WebGLRenderingContext.REPEAT,e.wrapT=WebGLRenderingContext.REPEAT;const i={uTexture:new We(t,e),uYaw:new Ke(0),uPitch:new Ke(.5),uZoom:new Ke(1)},s=new Ze,r=new ze(t,"#define GLSLIFY 1\nattribute vec3 position;attribute vec2 uv;uniform mat4 uMVMatrix;uniform mat4 uPMatrix;varying highp vec2 vUV;void main(){vUV=uv;gl_Position=vec4(position,1.0);}","precision mediump float;\n#define GLSLIFY 1\nuniform sampler2D uTexture;uniform float uYaw;uniform float uPitch;uniform float uZoom;varying highp vec2 vUV;const float PI=3.1415926536;const float PI_2=PI*0.5;vec2 toStereographicUV(in vec2 uv,in vec2 center){float R=1.*uZoom;vec2 texLatLon=(uv*2.-1.)*vec2(PI,PI_2);vec2 central=(center*2.-1.)*vec2(PI,PI_2)+vec2(PI,0);float x=texLatLon.x;float y=texLatLon.y;float rou=sqrt(x*x+y*y);float c=2.0*atan(rou,R*0.5);float sin_c=sin(c);float cos_c=cos(c);float sin_cy=sin(central.y);float cos_cy=cos(central.y);float lat=asin(cos_c*sin_cy+(y*sin_c*cos_cy)/rou);float lon=central.x+atan(x*sin_c,rou*cos_cy*cos_c-y*sin_cy*sin_c);float u=(lon/PI+1.0)*0.5;float v=(lat/PI_2+1.0)*0.5;return vec2(u,v);}void main(){vec2 central=vec2(uYaw,uPitch);vec2 uv=toStereographicUV(vUV,central);gl_FragColor=texture2D(uTexture,uv);}",i),o=t.createVAO(s,r),n=new Ve(o,r);return n.on(ot,(({camera:t})=>{const e=n.program.uniforms;e.uYaw.val=t.yaw/360,e.uPitch.val=t.pitch/180+.5,e.uZoom.val=t.zoom,e.uYaw.needsUpdate=!0,e.uPitch.needsUpdate=!0,e.uZoom.needsUpdate=!0})),n}updateControl(t){t.ignoreZoomScale=!0}},StereoEquiProjection:Qe,WideAngleCorrectionProjection:class extends Me{constructor(t){var e,i,s,r,o,n,a,h,l,u;super(t),this._correctionPass=null,this._correctionParams={mode:null!==(e=t.mode)&&void 0!==e?e:"erp",yaw:null!==(i=t.yaw)&&void 0!==i?i:0,pitch:null!==(s=t.pitch)&&void 0!==s?s:0,roll:null!==(r=t.roll)&&void 0!==r?r:0,hfov:null!==(o=t.hfov)&&void 0!==o?o:180,vfov:null!==(n=t.vfov)&&void 0!==n?n:90,fisheyeFov:null!==(a=t.fisheyeFov)&&void 0!==a?a:180},this._outputWidth=null!==(h=t.outputWidth)&&void 0!==h?h:4096,this._outputHeight=null!==(l=t.outputHeight)&&void 0!==l?l:2048,this._flatProjection=null!==(u=t.flatProjection)&&void 0!==u&&u}createMesh(t,e){if(e.isCube())throw new Error("WideAngleCorrectionProjection 仅支持单张 2D 图像,不支持 Cubemap 纹理");const i=t.maxTextureSize;if(e.width>i||e.height>i)throw new Error("输入纹理尺寸 ("+e.width+"x"+e.height+") 超过 GPU 最大纹理尺寸限制 ("+i+"x"+i+")。请使用更小的图片或在支持更大纹理的设备上运行。");if(this._outputWidth>i||this._outputHeight>i)throw new Error("输出纹理尺寸 ("+this._outputWidth+"x"+this._outputHeight+") 超过 GPU 最大纹理尺寸限制 ("+i+"x"+i+")。请降低 outputWidth/outputHeight 参数值。");const s=t.gl;console.info("WideAngleCorrectionProjection 输出纹理尺寸:",this._outputWidth,"x",this._outputHeight,"输入纹理尺寸:",e.width,"x",e.height,"GPU 最大纹理尺寸:",t.maxTextureSize);const r=this._outputWidth/this._outputHeight;if(e.isVideo()){const i=new ti(t,this._outputWidth,this._outputHeight);this._correctionPass=i;const o={uTexture:this._createVideoUniform(e,s)},n=this._flatProjection?new Ze(r,1,-1):new qe,a=new ze(t,ke,Xe,o),h=t.createVAO(n,a);return new Ve(h,a)}const o=new ti(t,this._outputWidth,this._outputHeight);this._correctionPass=o;const n=e,a=e.width,h=e.height,l=s.createTexture();if(!l)throw new Error("无法创建输入纹理");s.bindTexture(s.TEXTURE_2D,l),s.pixelStorei(s.UNPACK_FLIP_Y_WEBGL,0),s.texParameteri(s.TEXTURE_2D,s.TEXTURE_MIN_FILTER,s.LINEAR),s.texParameteri(s.TEXTURE_2D,s.TEXTURE_MAG_FILTER,s.LINEAR),s.texParameteri(s.TEXTURE_2D,s.TEXTURE_WRAP_S,s.CLAMP_TO_EDGE),s.texParameteri(s.TEXTURE_2D,s.TEXTURE_WRAP_T,s.CLAMP_TO_EDGE),s.texImage2D(s.TEXTURE_2D,0,s.RGBA,s.RGBA,s.UNSIGNED_BYTE,n.source),o.render(l,a,h,this._correctionParams),s.deleteTexture(l);const u={uTexture:new ei(o.outputTexture,(()=>{o.destroy(),this._correctionPass===o&&(this._correctionPass=null)}))},c=this._flatProjection?new Ze(r,1,-1):new qe,_=new ze(t,ke,Xe,u),d=t.createVAO(c,_);return new Ve(d,_)}_createVideoUniform(t,e){const i=this._correctionPass;if(!i)throw new Error("矫正 Pass 未初始化");return new class extends ei{constructor(t,i,s,r){super(t.outputTexture,r),this.sourceTexture=i,this._correctionPass=t,this._params=s,this._initialized=!1;const o=e.createTexture();if(!o)throw new Error("无法创建输入纹理");this._inputTexture=o,e.bindTexture(e.TEXTURE_2D,this._inputTexture),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MIN_FILTER,e.LINEAR),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MAG_FILTER,e.LINEAR),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_S,e.CLAMP_TO_EDGE),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_T,e.CLAMP_TO_EDGE),e.bindTexture(e.TEXTURE_2D,null)}destroy(t){this.sourceTexture.destroy(),t.deleteTexture(this._inputTexture),super.destroy(t)}update(t,e,i){const s=this.sourceTexture,r=s.isVideo(),o=t.getParameter(t.UNPACK_FLIP_Y_WEBGL);if(!r||!s.isPaused()||!this._initialized){if(r){const r=s.source;if(r.readyState<2||0===r.videoWidth||0===r.videoHeight)return super.update(t,e,i),void t.pixelStorei(t.UNPACK_FLIP_Y_WEBGL,o)}t.pixelStorei(t.UNPACK_FLIP_Y_WEBGL,0),t.activeTexture(t.TEXTURE0),t.bindTexture(t.TEXTURE_2D,this._inputTexture),!r&&i?t.texSubImage2D(t.TEXTURE_2D,0,0,0,t.RGBA,t.UNSIGNED_BYTE,s.source):t.texImage2D(t.TEXTURE_2D,0,t.RGBA,t.RGBA,t.UNSIGNED_BYTE,s.source);const n=s.source,a=r&&n.videoWidth||s.width,h=r&&n.videoHeight||s.height;this._correctionPass.render(this._inputTexture,a,h,this._params),this._initialized=!0}super.update(t,e,i),t.pixelStorei(t.UNPACK_FLIP_Y_WEBGL,o)}}(i,t,this._correctionParams,(()=>{i.destroy(),this._correctionPass===i&&(this._correctionPass=null)}))}},WideAngleRealtimeProjection:class extends Me{constructor(t){var e,i,s,r,o,n,a,h,l,u,c,_,d,m,g,p,v;super(t),this._uniforms={};const f=t.correction||{};this._mode=null!==(i=null!==(e=f.mode)&&void 0!==e?e:t.mode)&&void 0!==i?i:"erp",this._flatProjection=null!==(s=t.flatProjection)&&void 0!==s&&s,this._yaw=null!==(o=null!==(r=f.yaw)&&void 0!==r?r:t.yaw)&&void 0!==o?o:0,this._pitch=null!==(a=null!==(n=f.pitch)&&void 0!==n?n:t.pitch)&&void 0!==a?a:0,this._roll=null!==(l=null!==(h=f.roll)&&void 0!==h?h:t.roll)&&void 0!==l?l:0,this._hfov=null!==(c=null!==(u=f.hfov)&&void 0!==u?u:t.hfov)&&void 0!==c?c:180,this._vfov=null!==(d=null!==(_=f.vfov)&&void 0!==_?_:t.vfov)&&void 0!==d?d:90,this._fisheyeFov=null!==(g=null!==(m=f.fisheyeFov)&&void 0!==m?m:t.fisheyeFov)&&void 0!==g?g:180,this._inputWidth=null!==(p=t.inputWidth)&&void 0!==p?p:0,this._inputHeight=null!==(v=t.inputHeight)&&void 0!==v?v:0}get mode(){return this._mode}set mode(t){this._mode=t,this._uniforms.uMode&&(this._uniforms.uMode.val="fisheye"===t?1:0,this._uniforms.uMode.needsUpdate=!0)}get yaw(){return this._yaw}set yaw(t){this._yaw=t,this._updateRotation()}get pitch(){return this._pitch}set pitch(t){this._pitch=t,this._updateRotation()}get roll(){return this._roll}set roll(t){this._roll=t,this._updateRotation()}get hfov(){return this._hfov}set hfov(t){this._hfov=t,this._uniforms.uHFov&&(this._uniforms.uHFov.val=oi(t),this._uniforms.uHFov.needsUpdate=!0)}get vfov(){return this._vfov}set vfov(t){this._vfov=t,this._uniforms.uVFov&&(this._uniforms.uVFov.val=oi(t),this._uniforms.uVFov.needsUpdate=!0)}get fisheyeFov(){return this._fisheyeFov}set fisheyeFov(t){this._fisheyeFov=t,this._uniforms.uFisheyeFov&&(this._uniforms.uFisheyeFov.val=oi(t),this._uniforms.uFisheyeFov.needsUpdate=!0)}createMesh(t,e){if(e.isCube())throw new Error("WideAngleRealtimeProjection 仅支持单张 2D 图像,不支持 Cubemap 纹理");const i=e,s=t.maxTextureSize;if(e.width>s||e.height>s)throw new Error("输入纹理尺寸 ("+e.width+"x"+e.height+") 超过 GPU 最大纹理尺寸限制 ("+s+"x"+s+")。请使用更小的图片或在支持更大纹理的设备上运行。");const r=this._inputWidth>0&&this._inputHeight>0;if(t.debug){const i=r?this._inputWidth:e.width,s=r?this._inputHeight:e.height;console.info("WideAngleRealtimeProjection 实时矫正模式","输入纹理尺寸:",i,"x",s,r?"(已缩放,原始: "+e.width+" x "+e.height+")":"","GPU 最大纹理尺寸:",t.maxTextureSize)}const o=t.createWebGLTexture(i),n=t.isWebGL2&&!i.isVideo(),a=new ni(i,o,r?this._inputWidth:void 0,r?this._inputHeight:void 0,n),h=new ii("fisheye"===this._mode?1:0),l=new ri(oi(-this._yaw),oi(-this._pitch),oi(this._roll)),u=new Ke(oi(this._hfov)),c=new Ke(oi(this._vfov)),_=new Ke(oi(this._fisheyeFov)),d=a.getEffectiveTargetWidth(),m=a.getEffectiveTargetHeight(),g=d>0&&m>0,p=g?d:e.width,v=g?m:e.height,f=new si(p,v);t.debug&&console.info("[WideAngleRealtimeProjection] Uniforms:",{mode:this._mode,yaw:this._yaw,yawRad:oi(-this._yaw),pitch:this._pitch,pitchRad:oi(-this._pitch),roll:this._roll,rollRad:oi(this._roll),hfov:this._hfov,hfovRad:oi(this._hfov),vfov:this._vfov,vfovRad:oi(this._vfov),fisheyeFov:this._fisheyeFov,fisheyeFovRad:oi(this._fisheyeFov),imgSize:[p,v],inputScale:this._inputWidth>0?`${this._inputWidth}x${this._inputHeight}`:"none"}),a.setImgSizeUniform(f),this._uniforms={uTexture:a,uMode:h,uRotYPR:l,uHFov:u,uVFov:c,uFisheyeFov:_,uImgSize:f};const E={uTexture:a,uMode:h,uRotYPR:l,uHFov:u,uVFov:c,uFisheyeFov:_,uImgSize:f},T=this._flatProjection?new Ze(2,1,-1):new qe,b=new ze(t,"#define GLSLIFY 1\nattribute vec3 position;attribute vec2 uv;uniform mat4 uMVMatrix;uniform mat4 uPMatrix;varying highp vec2 vUV;void main(){vUV=uv;gl_Position=uPMatrix*uMVMatrix*vec4(position,1.0);}","precision highp float;\n#define GLSLIFY 1\nvarying vec2 vUV;uniform sampler2D uTexture;uniform int uMode;uniform vec3 uRotYPR;uniform float uHFov;uniform float uVFov;uniform float uFisheyeFov;uniform vec2 uImgSize;const float PI=3.14159265359;mat3 buildRotation(float yaw,float pitch,float roll){float cy=cos(yaw),sy=sin(yaw);float cp=cos(pitch),sp=sin(pitch);float cr=cos(roll),sr=sin(roll);mat3 Ry=mat3(cy,0.0,sy,0.0,1.0,0.0,-sy,0.0,cy);mat3 Rx=mat3(1.0,0.0,0.0,0.0,cp,-sp,0.0,sp,cp);mat3 Rz=mat3(cr,-sr,0.0,sr,cr,0.0,0.0,0.0,1.0);return Rz*(Rx*Ry);}mat3 myTranspose(mat3 m){return mat3(m[0][0],m[1][0],m[2][0],m[0][1],m[1][1],m[2][1],m[0][2],m[1][2],m[2][2]);}vec3 dirToErpCoord(vec3 dir){float lon=atan(dir.x,dir.z);float lat=asin(clamp(dir.y,-1.0,1.0));float halfLon=uHFov*0.5;float halfLat=uVFov*0.5;if(abs(lon)>halfLon||abs(lat)>halfLat){return vec3(0.0,0.0,-1.0);}float u=(lon/uHFov+0.5)*(uImgSize.x-1.0);float v=(0.5-lat/uVFov)*(uImgSize.y-1.0);if(u<0.0||u>=uImgSize.x||v<0.0||v>=uImgSize.y){return vec3(0.0,0.0,-1.0);}return vec3(u,v,1.0);}vec3 dirToFisheyeCoord(vec3 dir){float len=length(dir);float theta=acos(clamp(dir.z/len,-1.0,1.0));if(dir.z<=0.0)return vec3(0.0,0.0,-1.0);float maxTheta=uFisheyeFov*0.5;if(theta>maxTheta)return vec3(0.0,0.0,-1.0);float fisheyeRadius=min(uImgSize.x,uImgSize.y)*0.5;float fisheyeFocalLen=fisheyeRadius/maxTheta;float r=fisheyeFocalLen*theta;float imgAngle=atan(dir.x,-dir.y);float ix=uImgSize.x*0.5+r*sin(imgAngle);float iy=uImgSize.y*0.5+r*cos(imgAngle);if(ix<0.0||ix>=uImgSize.x||iy<0.0||iy>=uImgSize.y){return vec3(0.0,0.0,-1.0);}return vec3(ix,iy,1.0);}void main(){if(uImgSize.x<=0.0||uImgSize.y<=0.0){gl_FragColor=vec4(0.0,0.0,0.0,1.0);return;}mat3 R=buildRotation(uRotYPR.x,uRotYPR.y,uRotYPR.z);mat3 Rinv=myTranspose(R);float phi=(vUV.x-0.5)*2.0*PI;float lat=(vUV.y-0.5)*PI;float cosLat=cos(lat);vec3 worldDir=vec3(cosLat*sin(phi),sin(lat),cosLat*cos(phi));vec3 imgDir=Rinv*worldDir;vec3 imgCoord;if(uMode==0){imgCoord=dirToErpCoord(imgDir);}else{imgCoord=dirToFisheyeCoord(imgDir);}if(imgCoord.z>0.0){vec2 uv=vec2(imgCoord.x/uImgSize.x,imgCoord.y/uImgSize.y);gl_FragColor=texture2D(uTexture,uv);}else{gl_FragColor=vec4(0.0,0.0,0.0,1.0);}}",E),R=t.createVAO(T,b);return new Ve(R,b)}_updateRotation(){this._uniforms.uRotYPR&&(this._uniforms.uRotYPR.val=[oi(-this._yaw),oi(-this._pitch),oi(this._roll)],this._uniforms.uRotYPR.needsUpdate=!0)}},Hotspot:ce,HotspotRenderer:_e,ERROR_CODES:u,DEFAULT_CLASS:et,EVENTS:it,EASING:st,getValidProps:t=>Object.keys(t).reduce(((e,i)=>(null!=t[i]&&(e[i]=t[i]),e)),{}),VIEW360_METHODS:["destroy","init","load","resize","addPlugins","removePlugins","renderFrame","on","hasOn","once","off","trigger"],withMethods:(t,e)=>{[o.default.prototype,pe.prototype].forEach((i=>{Object.getOwnPropertyNames(i).filter((t=>"_"!==t.charAt(0)&&"constructor"!==t)).forEach((s=>{const r=Object.getOwnPropertyDescriptor(i,s);if(r.value)Object.defineProperty(t,s,{value:function(...t){return r.value.call(this[e],...t)}});else{const i={};r.get&&(i.get=function(){var t;return this[e]&&(null===(t=r.get)||void 0===t?void 0:t.call(this[e]))}),r.set&&(i.set=function(...t){var i;return null===(i=r.set)||void 0===i?void 0:i.call(this[e],...t)}),Object.defineProperty(t,s,i)}}))}))}};return((t,...e)=>{e.forEach((e=>{Object.keys(e).forEach((i=>{const s=e[i];Array.isArray(t[i])&&Array.isArray(s)?t[i]=[...t[i],...s]:t[i]=s}))}))})(pe,ai),pe}));
|
|
2
|
+
//# sourceMappingURL=view360.min.js.map
|