gl-draw 0.12.13 → 0.12.14

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- "use strict";var Gt=Object.defineProperty,Xt=Object.defineProperties;var Kt=Object.getOwnPropertyDescriptors;var Ot=Object.getOwnPropertySymbols;var jt=Object.prototype.hasOwnProperty,Qt=Object.prototype.propertyIsEnumerable;var Tt=(f,t,e)=>t in f?Gt(f,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):f[t]=e,V=(f,t)=>{for(var e in t||(t={}))jt.call(t,e)&&Tt(f,e,t[e]);if(Ot)for(var e of Ot(t))Qt.call(t,e)&&Tt(f,e,t[e]);return f},ot=(f,t)=>Xt(f,Kt(t));Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const z=require("three"),$t=require("@tweenjs/tween.js"),st=require("./events.js"),Jt=require("deepmerge"),te=require("stats-gl"),ee=require("lil-gui"),se=require("./colorCorrection.js"),ie=require("./parseVector.js");require("idb-keyval");require("esus-lite");require("d3-geo");require("d3-geo-projection");const re=require("three/examples/jsm/helpers/RectAreaLightHelper"),oe=require("three/examples/jsm/helpers/ViewHelper"),ne=require("three/examples/jsm/controls/TransformControls"),vt=require("three/examples/jsm/postprocessing/EffectComposer"),ae=require("three/examples/jsm/postprocessing/RenderPass"),he=require("three/examples/jsm/postprocessing/SSAOPass"),le=require("three/examples/jsm/postprocessing/Pass"),ce=require("three/examples/jsm/postprocessing/OutputPass"),de=require("three/examples/jsm/postprocessing/ShaderPass"),me=require("three/examples/jsm/postprocessing/UnrealBloomPass");require("three/examples/jsm/renderers/CSS2DRenderer");require("three/examples/jsm/renderers/CSS3DRenderer");require("three/examples/jsm/lights/RectAreaLightUniformsLib");require("three/examples/jsm/lines/LineSegments2");const Vt=require("./index2.js");require("three/examples/jsm/lines/LineSegmentsGeometry");require("three/examples/jsm/lines/LineMaterial");require("three-bvh-csg");const pe=require("./isPlainObject.js"),_e=require("./BaseObject.js");function Bt(f){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(f){for(const e in f)if(e!=="default"){const s=Object.getOwnPropertyDescriptor(f,e);Object.defineProperty(t,e,s.get?s:{enumerable:!0,get:()=>f[e]})}}return t.default=f,Object.freeze(t)}const w=Bt(z),xt=Bt($t),U={LEFT:1,RIGHT:2,MIDDLE:4},h=Object.freeze({NONE:0,ROTATE:1,TRUCK:2,OFFSET:4,DOLLY:8,ZOOM:16,TOUCH_ROTATE:32,TOUCH_TRUCK:64,TOUCH_OFFSET:128,TOUCH_DOLLY:256,TOUCH_ZOOM:512,TOUCH_DOLLY_TRUCK:1024,TOUCH_DOLLY_OFFSET:2048,TOUCH_DOLLY_ROTATE:4096,TOUCH_ZOOM_TRUCK:8192,TOUCH_ZOOM_OFFSET:16384,TOUCH_ZOOM_ROTATE:32768}),Z={NONE:0,IN:1,OUT:-1};function N(f){return f.isPerspectiveCamera}function B(f){return f.isOrthographicCamera}const q=Math.PI*2,wt=Math.PI/2,Nt=1e-5,Q=Math.PI/180;function F(f,t,e){return Math.max(t,Math.min(e,f))}function b(f,t=Nt){return Math.abs(f)<t}function A(f,t,e=Nt){return b(f-t,e)}function St(f,t){return Math.round(f/t)*t}function $(f){return isFinite(f)?f:f<0?-Number.MAX_VALUE:Number.MAX_VALUE}function J(f){return Math.abs(f)<Number.MAX_VALUE?f:f*(1/0)}function nt(f,t,e,s,r=1/0,i){s=Math.max(1e-4,s);const n=2/s,a=n*i,l=1/(1+a+.48*a*a+.235*a*a*a);let d=f-t;const g=t,c=r*s;d=F(d,-c,c),t=f-d;const E=(e.value+n*d)*i;e.value=(e.value-n*E)*l;let y=t+(d+E)*l;return g-f>0==y>g&&(y=g,e.value=(y-g)/i),y}function Pt(f,t,e,s,r=1/0,i,n){s=Math.max(1e-4,s);const a=2/s,l=a*i,d=1/(1+l+.48*l*l+.235*l*l*l);let g=t.x,c=t.y,E=t.z,y=f.x-g,u=f.y-c,p=f.z-E;const _=g,o=c,m=E,O=r*s,C=O*O,x=y*y+u*u+p*p;if(x>C){const mt=Math.sqrt(x);y=y/mt*O,u=u/mt*O,p=p/mt*O}g=f.x-y,c=f.y-u,E=f.z-p;const T=(e.x+a*y)*i,D=(e.y+a*u)*i,R=(e.z+a*p)*i;e.x=(e.x-a*T)*d,e.y=(e.y-a*D)*d,e.z=(e.z-a*R)*d,n.x=g+(y+T)*d,n.y=c+(u+D)*d,n.z=E+(p+R)*d;const it=_-f.x,rt=o-f.y,Yt=m-f.z,Zt=n.x-_,qt=n.y-o,Wt=n.z-m;return it*Zt+rt*qt+Yt*Wt>0&&(n.x=_,n.y=o,n.z=m,e.x=(n.x-_)/i,e.y=(n.y-o)/i,e.z=(n.z-m)/i),n}function pt(f,t){t.set(0,0),f.forEach(e=>{t.x+=e.clientX,t.y+=e.clientY}),t.x/=f.length,t.y/=f.length}function _t(f,t){return B(f)?(console.warn(`${t} is not supported in OrthographicCamera`),!0):!1}class ue{constructor(){this._listeners={}}addEventListener(t,e){const s=this._listeners;s[t]===void 0&&(s[t]=[]),s[t].indexOf(e)===-1&&s[t].push(e)}hasEventListener(t,e){const s=this._listeners;return s[t]!==void 0&&s[t].indexOf(e)!==-1}removeEventListener(t,e){const r=this._listeners[t];if(r!==void 0){const i=r.indexOf(e);i!==-1&&r.splice(i,1)}}removeAllEventListeners(t){if(!t){this._listeners={};return}Array.isArray(this._listeners[t])&&(this._listeners[t].length=0)}dispatchEvent(t){const s=this._listeners[t.type];if(s!==void 0){t.target=this;const r=s.slice(0);for(let i=0,n=r.length;i<n;i++)r[i].call(this,t)}}}const at=1/8,fe=/Mac/.test(navigator.platform);let v,At,ht,ut,L,S,P,W,tt,H,I,Y,Dt,bt,M,et,G,Ut,ft,Rt,gt,Ct,lt;class j extends ue{static install(t){v=t.THREE,At=Object.freeze(new v.Vector3(0,0,0)),ht=Object.freeze(new v.Vector3(0,1,0)),ut=Object.freeze(new v.Vector3(0,0,1)),L=new v.Vector2,S=new v.Vector3,P=new v.Vector3,W=new v.Vector3,tt=new v.Vector3,H=new v.Vector3,I=new v.Vector3,Y=new v.Vector3,Dt=new v.Vector3,bt=new v.Vector3,M=new v.Spherical,et=new v.Spherical,G=new v.Box3,Ut=new v.Box3,ft=new v.Sphere,Rt=new v.Quaternion,gt=new v.Quaternion,Ct=new v.Matrix4,lt=new v.Raycaster}static get ACTION(){return h}constructor(t,e){super(),this.minPolarAngle=0,this.maxPolarAngle=Math.PI,this.minAzimuthAngle=-1/0,this.maxAzimuthAngle=1/0,this.minDistance=Number.EPSILON,this.maxDistance=1/0,this.infinityDolly=!1,this.minZoom=.01,this.maxZoom=1/0,this.smoothTime=.25,this.draggingSmoothTime=.125,this.maxSpeed=1/0,this.azimuthRotateSpeed=1,this.polarRotateSpeed=1,this.dollySpeed=1,this.dollyDragInverted=!1,this.truckSpeed=2,this.dollyToCursor=!1,this.dragToOffset=!1,this.verticalDragToForward=!1,this.boundaryFriction=0,this.restThreshold=.01,this.colliderMeshes=[],this.cancel=()=>{},this._enabled=!0,this._state=h.NONE,this._viewport=null,this._changedDolly=0,this._changedZoom=0,this._hasRested=!0,this._boundaryEnclosesCamera=!1,this._needsUpdate=!0,this._updatedLastTime=!1,this._elementRect=new DOMRect,this._isDragging=!1,this._dragNeedsUpdate=!0,this._activePointers=[],this._lockedPointer=null,this._interactiveArea=new DOMRect(0,0,1,1),this._isUserControllingRotate=!1,this._isUserControllingDolly=!1,this._isUserControllingTruck=!1,this._isUserControllingOffset=!1,this._isUserControllingZoom=!1,this._lastDollyDirection=Z.NONE,this._thetaVelocity={value:0},this._phiVelocity={value:0},this._radiusVelocity={value:0},this._targetVelocity=new v.Vector3,this._focalOffsetVelocity=new v.Vector3,this._zoomVelocity={value:0},this._truckInternal=(o,m,O)=>{let C,x;if(N(this._camera)){const T=S.copy(this._camera.position).sub(this._target),D=this._camera.getEffectiveFOV()*Q,R=T.length()*Math.tan(D*.5);C=this.truckSpeed*o*R/this._elementRect.height,x=this.truckSpeed*m*R/this._elementRect.height}else if(B(this._camera)){const T=this._camera;C=o*(T.right-T.left)/T.zoom/this._elementRect.width,x=m*(T.top-T.bottom)/T.zoom/this._elementRect.height}else return;this.verticalDragToForward?(O?this.setFocalOffset(this._focalOffsetEnd.x+C,this._focalOffsetEnd.y,this._focalOffsetEnd.z,!0):this.truck(C,0,!0),this.forward(-x,!0)):O?this.setFocalOffset(this._focalOffsetEnd.x+C,this._focalOffsetEnd.y+x,this._focalOffsetEnd.z,!0):this.truck(C,x,!0)},this._rotateInternal=(o,m)=>{const O=q*this.azimuthRotateSpeed*o/this._elementRect.height,C=q*this.polarRotateSpeed*m/this._elementRect.height;this.rotate(O,C,!0)},this._dollyInternal=(o,m,O)=>{const C=Math.pow(.95,-o*this.dollySpeed),x=this._sphericalEnd.radius,T=this._sphericalEnd.radius*C,D=F(T,this.minDistance,this.maxDistance),R=D-T;this.infinityDolly&&this.dollyToCursor?this._dollyToNoClamp(T,!0):this.infinityDolly&&!this.dollyToCursor?(this.dollyInFixed(R,!0),this._dollyToNoClamp(D,!0)):this._dollyToNoClamp(D,!0),this.dollyToCursor&&(this._changedDolly+=(this.infinityDolly?T:D)-x,this._dollyControlCoord.set(m,O)),this._lastDollyDirection=Math.sign(-o)},this._zoomInternal=(o,m,O)=>{const C=Math.pow(.95,o*this.dollySpeed),x=this._zoom,T=this._zoom*C;this.zoomTo(T,!0),this.dollyToCursor&&(this._changedZoom+=T-x,this._dollyControlCoord.set(m,O))},typeof v=="undefined"&&console.error("camera-controls: `THREE` is undefined. You must first run `CameraControls.install( { THREE: THREE } )`. Check the docs for further information."),this._camera=t,this._yAxisUpSpace=new v.Quaternion().setFromUnitVectors(this._camera.up,ht),this._yAxisUpSpaceInverse=this._yAxisUpSpace.clone().invert(),this._state=h.NONE,this._target=new v.Vector3,this._targetEnd=this._target.clone(),this._focalOffset=new v.Vector3,this._focalOffsetEnd=this._focalOffset.clone(),this._spherical=new v.Spherical().setFromVector3(S.copy(this._camera.position).applyQuaternion(this._yAxisUpSpace)),this._sphericalEnd=this._spherical.clone(),this._lastDistance=this._spherical.radius,this._zoom=this._camera.zoom,this._zoomEnd=this._zoom,this._lastZoom=this._zoom,this._nearPlaneCorners=[new v.Vector3,new v.Vector3,new v.Vector3,new v.Vector3],this._updateNearPlaneCorners(),this._boundary=new v.Box3(new v.Vector3(-1/0,-1/0,-1/0),new v.Vector3(1/0,1/0,1/0)),this._cameraUp0=this._camera.up.clone(),this._target0=this._target.clone(),this._position0=this._camera.position.clone(),this._zoom0=this._zoom,this._focalOffset0=this._focalOffset.clone(),this._dollyControlCoord=new v.Vector2,this.mouseButtons={left:h.ROTATE,middle:h.DOLLY,right:h.TRUCK,wheel:N(this._camera)?h.DOLLY:B(this._camera)?h.ZOOM:h.NONE},this.touches={one:h.TOUCH_ROTATE,two:N(this._camera)?h.TOUCH_DOLLY_TRUCK:B(this._camera)?h.TOUCH_ZOOM_TRUCK:h.NONE,three:h.TOUCH_TRUCK};const s=new v.Vector2,r=new v.Vector2,i=new v.Vector2,n=o=>{if(!this._enabled||!this._domElement)return;if(this._interactiveArea.left!==0||this._interactiveArea.top!==0||this._interactiveArea.width!==1||this._interactiveArea.height!==1){const C=this._domElement.getBoundingClientRect(),x=(o.clientX-C.left)/(C.right-C.left),T=(o.clientY-C.top)/(C.bottom-C.top);if(x<this._interactiveArea.left||x>this._interactiveArea.right||T<this._interactiveArea.top||T>this._interactiveArea.bottom)return}const m=o.pointerType!=="mouse"?null:(o.buttons&U.LEFT)===U.LEFT?U.LEFT:(o.buttons&U.MIDDLE)===U.MIDDLE?U.MIDDLE:(o.buttons&U.RIGHT)===U.RIGHT?U.RIGHT:null;if(m!==null){const C=this._findPointerByMouseButton(m);C&&this._disposePointer(C)}if((o.buttons&U.LEFT)===U.LEFT&&this._lockedPointer)return;const O={pointerId:o.pointerId,clientX:o.clientX,clientY:o.clientY,deltaX:0,deltaY:0,mouseButton:m};this._activePointers.push(O),this._domElement.ownerDocument.removeEventListener("pointermove",a,{passive:!1}),this._domElement.ownerDocument.removeEventListener("pointerup",l),this._domElement.ownerDocument.addEventListener("pointermove",a,{passive:!1}),this._domElement.ownerDocument.addEventListener("pointerup",l),this._isDragging=!0,E(o)},a=o=>{o.cancelable&&o.preventDefault();const m=o.pointerId,O=this._lockedPointer||this._findPointerById(m);if(O){if(O.clientX=o.clientX,O.clientY=o.clientY,O.deltaX=o.movementX,O.deltaY=o.movementY,this._state=0,o.pointerType==="touch")switch(this._activePointers.length){case 1:this._state=this.touches.one;break;case 2:this._state=this.touches.two;break;case 3:this._state=this.touches.three;break}else(!this._isDragging&&this._lockedPointer||this._isDragging&&(o.buttons&U.LEFT)===U.LEFT)&&(this._state=this._state|this.mouseButtons.left),this._isDragging&&(o.buttons&U.MIDDLE)===U.MIDDLE&&(this._state=this._state|this.mouseButtons.middle),this._isDragging&&(o.buttons&U.RIGHT)===U.RIGHT&&(this._state=this._state|this.mouseButtons.right);y()}},l=o=>{const m=this._findPointerById(o.pointerId);if(!(m&&m===this._lockedPointer)){if(m&&this._disposePointer(m),o.pointerType==="touch")switch(this._activePointers.length){case 0:this._state=h.NONE;break;case 1:this._state=this.touches.one;break;case 2:this._state=this.touches.two;break;case 3:this._state=this.touches.three;break}else this._state=h.NONE;u()}};let d=-1;const g=o=>{if(!this._domElement||!this._enabled||this.mouseButtons.wheel===h.NONE)return;if(this._interactiveArea.left!==0||this._interactiveArea.top!==0||this._interactiveArea.width!==1||this._interactiveArea.height!==1){const T=this._domElement.getBoundingClientRect(),D=(o.clientX-T.left)/(T.right-T.left),R=(o.clientY-T.top)/(T.bottom-T.top);if(D<this._interactiveArea.left||D>this._interactiveArea.right||R<this._interactiveArea.top||R>this._interactiveArea.bottom)return}if(o.preventDefault(),this.dollyToCursor||this.mouseButtons.wheel===h.ROTATE||this.mouseButtons.wheel===h.TRUCK){const T=performance.now();d-T<1e3&&this._getClientRect(this._elementRect),d=T}const m=fe?-1:-3,O=o.deltaMode===1?o.deltaY/m:o.deltaY/(m*10),C=this.dollyToCursor?(o.clientX-this._elementRect.x)/this._elementRect.width*2-1:0,x=this.dollyToCursor?(o.clientY-this._elementRect.y)/this._elementRect.height*-2+1:0;switch(this.mouseButtons.wheel){case h.ROTATE:{this._rotateInternal(o.deltaX,o.deltaY),this._isUserControllingRotate=!0;break}case h.TRUCK:{this._truckInternal(o.deltaX,o.deltaY,!1),this._isUserControllingTruck=!0;break}case h.OFFSET:{this._truckInternal(o.deltaX,o.deltaY,!0),this._isUserControllingOffset=!0;break}case h.DOLLY:{this._dollyInternal(-O,C,x),this._isUserControllingDolly=!0;break}case h.ZOOM:{this._zoomInternal(-O,C,x),this._isUserControllingZoom=!0;break}}this.dispatchEvent({type:"control"})},c=o=>{if(!(!this._domElement||!this._enabled)){if(this.mouseButtons.right===j.ACTION.NONE){const m=o instanceof PointerEvent?o.pointerId:0,O=this._findPointerById(m);O&&this._disposePointer(O),this._domElement.ownerDocument.removeEventListener("pointermove",a,{passive:!1}),this._domElement.ownerDocument.removeEventListener("pointerup",l);return}o.preventDefault()}},E=o=>{if(!this._enabled)return;if(pt(this._activePointers,L),this._getClientRect(this._elementRect),s.copy(L),r.copy(L),this._activePointers.length>=2){const O=L.x-this._activePointers[1].clientX,C=L.y-this._activePointers[1].clientY,x=Math.sqrt(O*O+C*C);i.set(0,x);const T=(this._activePointers[0].clientX+this._activePointers[1].clientX)*.5,D=(this._activePointers[0].clientY+this._activePointers[1].clientY)*.5;r.set(T,D)}if(this._state=0,!o)this._lockedPointer&&(this._state=this._state|this.mouseButtons.left);else if("pointerType"in o&&o.pointerType==="touch")switch(this._activePointers.length){case 1:this._state=this.touches.one;break;case 2:this._state=this.touches.two;break;case 3:this._state=this.touches.three;break}else!this._lockedPointer&&(o.buttons&U.LEFT)===U.LEFT&&(this._state=this._state|this.mouseButtons.left),(o.buttons&U.MIDDLE)===U.MIDDLE&&(this._state=this._state|this.mouseButtons.middle),(o.buttons&U.RIGHT)===U.RIGHT&&(this._state=this._state|this.mouseButtons.right);((this._state&h.ROTATE)===h.ROTATE||(this._state&h.TOUCH_ROTATE)===h.TOUCH_ROTATE||(this._state&h.TOUCH_DOLLY_ROTATE)===h.TOUCH_DOLLY_ROTATE||(this._state&h.TOUCH_ZOOM_ROTATE)===h.TOUCH_ZOOM_ROTATE)&&(this._sphericalEnd.theta=this._spherical.theta,this._sphericalEnd.phi=this._spherical.phi,this._thetaVelocity.value=0,this._phiVelocity.value=0),((this._state&h.TRUCK)===h.TRUCK||(this._state&h.TOUCH_TRUCK)===h.TOUCH_TRUCK||(this._state&h.TOUCH_DOLLY_TRUCK)===h.TOUCH_DOLLY_TRUCK||(this._state&h.TOUCH_ZOOM_TRUCK)===h.TOUCH_ZOOM_TRUCK)&&(this._targetEnd.copy(this._target),this._targetVelocity.set(0,0,0)),((this._state&h.DOLLY)===h.DOLLY||(this._state&h.TOUCH_DOLLY)===h.TOUCH_DOLLY||(this._state&h.TOUCH_DOLLY_TRUCK)===h.TOUCH_DOLLY_TRUCK||(this._state&h.TOUCH_DOLLY_OFFSET)===h.TOUCH_DOLLY_OFFSET||(this._state&h.TOUCH_DOLLY_ROTATE)===h.TOUCH_DOLLY_ROTATE)&&(this._sphericalEnd.radius=this._spherical.radius,this._radiusVelocity.value=0),((this._state&h.ZOOM)===h.ZOOM||(this._state&h.TOUCH_ZOOM)===h.TOUCH_ZOOM||(this._state&h.TOUCH_ZOOM_TRUCK)===h.TOUCH_ZOOM_TRUCK||(this._state&h.TOUCH_ZOOM_OFFSET)===h.TOUCH_ZOOM_OFFSET||(this._state&h.TOUCH_ZOOM_ROTATE)===h.TOUCH_ZOOM_ROTATE)&&(this._zoomEnd=this._zoom,this._zoomVelocity.value=0),((this._state&h.OFFSET)===h.OFFSET||(this._state&h.TOUCH_OFFSET)===h.TOUCH_OFFSET||(this._state&h.TOUCH_DOLLY_OFFSET)===h.TOUCH_DOLLY_OFFSET||(this._state&h.TOUCH_ZOOM_OFFSET)===h.TOUCH_ZOOM_OFFSET)&&(this._focalOffsetEnd.copy(this._focalOffset),this._focalOffsetVelocity.set(0,0,0)),this.dispatchEvent({type:"controlstart"})},y=()=>{if(!this._enabled||!this._dragNeedsUpdate)return;this._dragNeedsUpdate=!1,pt(this._activePointers,L);const m=this._domElement&&this._domElement.ownerDocument.pointerLockElement===this._domElement?this._lockedPointer||this._activePointers[0]:null,O=m?-m.deltaX:r.x-L.x,C=m?-m.deltaY:r.y-L.y;if(r.copy(L),((this._state&h.ROTATE)===h.ROTATE||(this._state&h.TOUCH_ROTATE)===h.TOUCH_ROTATE||(this._state&h.TOUCH_DOLLY_ROTATE)===h.TOUCH_DOLLY_ROTATE||(this._state&h.TOUCH_ZOOM_ROTATE)===h.TOUCH_ZOOM_ROTATE)&&(this._rotateInternal(O,C),this._isUserControllingRotate=!0),(this._state&h.DOLLY)===h.DOLLY||(this._state&h.ZOOM)===h.ZOOM){const x=this.dollyToCursor?(s.x-this._elementRect.x)/this._elementRect.width*2-1:0,T=this.dollyToCursor?(s.y-this._elementRect.y)/this._elementRect.height*-2+1:0,D=this.dollyDragInverted?-1:1;(this._state&h.DOLLY)===h.DOLLY?(this._dollyInternal(D*C*at,x,T),this._isUserControllingDolly=!0):(this._zoomInternal(D*C*at,x,T),this._isUserControllingZoom=!0)}if((this._state&h.TOUCH_DOLLY)===h.TOUCH_DOLLY||(this._state&h.TOUCH_ZOOM)===h.TOUCH_ZOOM||(this._state&h.TOUCH_DOLLY_TRUCK)===h.TOUCH_DOLLY_TRUCK||(this._state&h.TOUCH_ZOOM_TRUCK)===h.TOUCH_ZOOM_TRUCK||(this._state&h.TOUCH_DOLLY_OFFSET)===h.TOUCH_DOLLY_OFFSET||(this._state&h.TOUCH_ZOOM_OFFSET)===h.TOUCH_ZOOM_OFFSET||(this._state&h.TOUCH_DOLLY_ROTATE)===h.TOUCH_DOLLY_ROTATE||(this._state&h.TOUCH_ZOOM_ROTATE)===h.TOUCH_ZOOM_ROTATE){const x=L.x-this._activePointers[1].clientX,T=L.y-this._activePointers[1].clientY,D=Math.sqrt(x*x+T*T),R=i.y-D;i.set(0,D);const it=this.dollyToCursor?(r.x-this._elementRect.x)/this._elementRect.width*2-1:0,rt=this.dollyToCursor?(r.y-this._elementRect.y)/this._elementRect.height*-2+1:0;(this._state&h.TOUCH_DOLLY)===h.TOUCH_DOLLY||(this._state&h.TOUCH_DOLLY_ROTATE)===h.TOUCH_DOLLY_ROTATE||(this._state&h.TOUCH_DOLLY_TRUCK)===h.TOUCH_DOLLY_TRUCK||(this._state&h.TOUCH_DOLLY_OFFSET)===h.TOUCH_DOLLY_OFFSET?(this._dollyInternal(R*at,it,rt),this._isUserControllingDolly=!0):(this._zoomInternal(R*at,it,rt),this._isUserControllingZoom=!0)}((this._state&h.TRUCK)===h.TRUCK||(this._state&h.TOUCH_TRUCK)===h.TOUCH_TRUCK||(this._state&h.TOUCH_DOLLY_TRUCK)===h.TOUCH_DOLLY_TRUCK||(this._state&h.TOUCH_ZOOM_TRUCK)===h.TOUCH_ZOOM_TRUCK)&&(this._truckInternal(O,C,!1),this._isUserControllingTruck=!0),((this._state&h.OFFSET)===h.OFFSET||(this._state&h.TOUCH_OFFSET)===h.TOUCH_OFFSET||(this._state&h.TOUCH_DOLLY_OFFSET)===h.TOUCH_DOLLY_OFFSET||(this._state&h.TOUCH_ZOOM_OFFSET)===h.TOUCH_ZOOM_OFFSET)&&(this._truckInternal(O,C,!0),this._isUserControllingOffset=!0),this.dispatchEvent({type:"control"})},u=()=>{pt(this._activePointers,L),r.copy(L),this._dragNeedsUpdate=!1,(this._activePointers.length===0||this._activePointers.length===1&&this._activePointers[0]===this._lockedPointer)&&(this._isDragging=!1),this._activePointers.length===0&&this._domElement&&(this._domElement.ownerDocument.removeEventListener("pointermove",a,{passive:!1}),this._domElement.ownerDocument.removeEventListener("pointerup",l),this.dispatchEvent({type:"controlend"}))};this.lockPointer=()=>{!this._enabled||!this._domElement||(this.cancel(),this._lockedPointer={pointerId:-1,clientX:0,clientY:0,deltaX:0,deltaY:0,mouseButton:null},this._activePointers.push(this._lockedPointer),this._domElement.ownerDocument.removeEventListener("pointermove",a,{passive:!1}),this._domElement.ownerDocument.removeEventListener("pointerup",l),this._domElement.requestPointerLock(),this._domElement.ownerDocument.addEventListener("pointerlockchange",p),this._domElement.ownerDocument.addEventListener("pointerlockerror",_),this._domElement.ownerDocument.addEventListener("pointermove",a,{passive:!1}),this._domElement.ownerDocument.addEventListener("pointerup",l),E())},this.unlockPointer=()=>{var o,m,O;this._lockedPointer!==null&&(this._disposePointer(this._lockedPointer),this._lockedPointer=null),(o=this._domElement)===null||o===void 0||o.ownerDocument.exitPointerLock(),(m=this._domElement)===null||m===void 0||m.ownerDocument.removeEventListener("pointerlockchange",p),(O=this._domElement)===null||O===void 0||O.ownerDocument.removeEventListener("pointerlockerror",_),this.cancel()};const p=()=>{this._domElement&&this._domElement.ownerDocument.pointerLockElement===this._domElement||this.unlockPointer()},_=()=>{this.unlockPointer()};this._addAllEventListeners=o=>{this._domElement=o,this._domElement.style.touchAction="none",this._domElement.style.userSelect="none",this._domElement.style.webkitUserSelect="none",this._domElement.addEventListener("pointerdown",n),this._domElement.addEventListener("pointercancel",l),this._domElement.addEventListener("wheel",g,{passive:!1}),this._domElement.addEventListener("contextmenu",c)},this._removeAllEventListeners=()=>{this._domElement&&(this._domElement.style.touchAction="",this._domElement.style.userSelect="",this._domElement.style.webkitUserSelect="",this._domElement.removeEventListener("pointerdown",n),this._domElement.removeEventListener("pointercancel",l),this._domElement.removeEventListener("wheel",g,{passive:!1}),this._domElement.removeEventListener("contextmenu",c),this._domElement.ownerDocument.removeEventListener("pointermove",a,{passive:!1}),this._domElement.ownerDocument.removeEventListener("pointerup",l),this._domElement.ownerDocument.removeEventListener("pointerlockchange",p),this._domElement.ownerDocument.removeEventListener("pointerlockerror",_))},this.cancel=()=>{this._state!==h.NONE&&(this._state=h.NONE,this._activePointers.length=0,u())},e&&this.connect(e),this.update(0)}get camera(){return this._camera}set camera(t){this._camera=t,this.updateCameraUp(),this._camera.updateProjectionMatrix(),this._updateNearPlaneCorners(),this._needsUpdate=!0}get enabled(){return this._enabled}set enabled(t){this._enabled=t,this._domElement&&(t?(this._domElement.style.touchAction="none",this._domElement.style.userSelect="none",this._domElement.style.webkitUserSelect="none"):(this.cancel(),this._domElement.style.touchAction="",this._domElement.style.userSelect="",this._domElement.style.webkitUserSelect=""))}get active(){return!this._hasRested}get currentAction(){return this._state}get distance(){return this._spherical.radius}set distance(t){this._spherical.radius===t&&this._sphericalEnd.radius===t||(this._spherical.radius=t,this._sphericalEnd.radius=t,this._needsUpdate=!0)}get azimuthAngle(){return this._spherical.theta}set azimuthAngle(t){this._spherical.theta===t&&this._sphericalEnd.theta===t||(this._spherical.theta=t,this._sphericalEnd.theta=t,this._needsUpdate=!0)}get polarAngle(){return this._spherical.phi}set polarAngle(t){this._spherical.phi===t&&this._sphericalEnd.phi===t||(this._spherical.phi=t,this._sphericalEnd.phi=t,this._needsUpdate=!0)}get boundaryEnclosesCamera(){return this._boundaryEnclosesCamera}set boundaryEnclosesCamera(t){this._boundaryEnclosesCamera=t,this._needsUpdate=!0}set interactiveArea(t){this._interactiveArea.width=F(t.width,0,1),this._interactiveArea.height=F(t.height,0,1),this._interactiveArea.x=F(t.x,0,1-this._interactiveArea.width),this._interactiveArea.y=F(t.y,0,1-this._interactiveArea.height)}addEventListener(t,e){super.addEventListener(t,e)}removeEventListener(t,e){super.removeEventListener(t,e)}rotate(t,e,s=!1){return this.rotateTo(this._sphericalEnd.theta+t,this._sphericalEnd.phi+e,s)}rotateAzimuthTo(t,e=!1){return this.rotateTo(t,this._sphericalEnd.phi,e)}rotatePolarTo(t,e=!1){return this.rotateTo(this._sphericalEnd.theta,t,e)}rotateTo(t,e,s=!1){this._isUserControllingRotate=!1;const r=F(t,this.minAzimuthAngle,this.maxAzimuthAngle),i=F(e,this.minPolarAngle,this.maxPolarAngle);this._sphericalEnd.theta=r,this._sphericalEnd.phi=i,this._sphericalEnd.makeSafe(),this._needsUpdate=!0,s||(this._spherical.theta=this._sphericalEnd.theta,this._spherical.phi=this._sphericalEnd.phi);const n=!s||A(this._spherical.theta,this._sphericalEnd.theta,this.restThreshold)&&A(this._spherical.phi,this._sphericalEnd.phi,this.restThreshold);return this._createOnRestPromise(n)}dolly(t,e=!1){return this.dollyTo(this._sphericalEnd.radius-t,e)}dollyTo(t,e=!1){return this._isUserControllingDolly=!1,this._lastDollyDirection=Z.NONE,this._changedDolly=0,this._dollyToNoClamp(F(t,this.minDistance,this.maxDistance),e)}_dollyToNoClamp(t,e=!1){const s=this._sphericalEnd.radius;if(this.colliderMeshes.length>=1){const n=this._collisionTest(),a=A(n,this._spherical.radius);if(!(s>t)&&a)return Promise.resolve();this._sphericalEnd.radius=Math.min(t,n)}else this._sphericalEnd.radius=t;this._needsUpdate=!0,e||(this._spherical.radius=this._sphericalEnd.radius);const i=!e||A(this._spherical.radius,this._sphericalEnd.radius,this.restThreshold);return this._createOnRestPromise(i)}dollyInFixed(t,e=!1){this._targetEnd.add(this._getCameraDirection(tt).multiplyScalar(t)),e||this._target.copy(this._targetEnd);const s=!e||A(this._target.x,this._targetEnd.x,this.restThreshold)&&A(this._target.y,this._targetEnd.y,this.restThreshold)&&A(this._target.z,this._targetEnd.z,this.restThreshold);return this._createOnRestPromise(s)}zoom(t,e=!1){return this.zoomTo(this._zoomEnd+t,e)}zoomTo(t,e=!1){this._isUserControllingZoom=!1,this._zoomEnd=F(t,this.minZoom,this.maxZoom),this._needsUpdate=!0,e||(this._zoom=this._zoomEnd);const s=!e||A(this._zoom,this._zoomEnd,this.restThreshold);return this._changedZoom=0,this._createOnRestPromise(s)}pan(t,e,s=!1){return console.warn("`pan` has been renamed to `truck`"),this.truck(t,e,s)}truck(t,e,s=!1){this._camera.updateMatrix(),H.setFromMatrixColumn(this._camera.matrix,0),I.setFromMatrixColumn(this._camera.matrix,1),H.multiplyScalar(t),I.multiplyScalar(-e);const r=S.copy(H).add(I),i=P.copy(this._targetEnd).add(r);return this.moveTo(i.x,i.y,i.z,s)}forward(t,e=!1){S.setFromMatrixColumn(this._camera.matrix,0),S.crossVectors(this._camera.up,S),S.multiplyScalar(t);const s=P.copy(this._targetEnd).add(S);return this.moveTo(s.x,s.y,s.z,e)}elevate(t,e=!1){return S.copy(this._camera.up).multiplyScalar(t),this.moveTo(this._targetEnd.x+S.x,this._targetEnd.y+S.y,this._targetEnd.z+S.z,e)}moveTo(t,e,s,r=!1){this._isUserControllingTruck=!1;const i=S.set(t,e,s).sub(this._targetEnd);this._encloseToBoundary(this._targetEnd,i,this.boundaryFriction),this._needsUpdate=!0,r||this._target.copy(this._targetEnd);const n=!r||A(this._target.x,this._targetEnd.x,this.restThreshold)&&A(this._target.y,this._targetEnd.y,this.restThreshold)&&A(this._target.z,this._targetEnd.z,this.restThreshold);return this._createOnRestPromise(n)}lookInDirectionOf(t,e,s,r=!1){const a=S.set(t,e,s).sub(this._targetEnd).normalize().multiplyScalar(-this._sphericalEnd.radius).add(this._targetEnd);return this.setPosition(a.x,a.y,a.z,r)}fitToBox(t,e,{cover:s=!1,paddingLeft:r=0,paddingRight:i=0,paddingBottom:n=0,paddingTop:a=0}={}){const l=[],d=t.isBox3?G.copy(t):G.setFromObject(t);d.isEmpty()&&(console.warn("camera-controls: fitTo() cannot be used with an empty box. Aborting"),Promise.resolve());const g=St(this._sphericalEnd.theta,wt),c=St(this._sphericalEnd.phi,wt);l.push(this.rotateTo(g,c,e));const E=S.setFromSpherical(this._sphericalEnd).normalize(),y=Rt.setFromUnitVectors(E,ut),u=A(Math.abs(E.y),1);u&&y.multiply(gt.setFromAxisAngle(ht,g)),y.multiply(this._yAxisUpSpaceInverse);const p=Ut.makeEmpty();P.copy(d.min).applyQuaternion(y),p.expandByPoint(P),P.copy(d.min).setX(d.max.x).applyQuaternion(y),p.expandByPoint(P),P.copy(d.min).setY(d.max.y).applyQuaternion(y),p.expandByPoint(P),P.copy(d.max).setZ(d.min.z).applyQuaternion(y),p.expandByPoint(P),P.copy(d.min).setZ(d.max.z).applyQuaternion(y),p.expandByPoint(P),P.copy(d.max).setY(d.min.y).applyQuaternion(y),p.expandByPoint(P),P.copy(d.max).setX(d.min.x).applyQuaternion(y),p.expandByPoint(P),P.copy(d.max).applyQuaternion(y),p.expandByPoint(P),p.min.x-=r,p.min.y-=n,p.max.x+=i,p.max.y+=a,y.setFromUnitVectors(ut,E),u&&y.premultiply(gt.invert()),y.premultiply(this._yAxisUpSpace);const _=p.getSize(S),o=p.getCenter(P).applyQuaternion(y);if(N(this._camera)){const m=this.getDistanceToFitBox(_.x,_.y,_.z,s);l.push(this.moveTo(o.x,o.y,o.z,e)),l.push(this.dollyTo(m,e)),l.push(this.setFocalOffset(0,0,0,e))}else if(B(this._camera)){const m=this._camera,O=m.right-m.left,C=m.top-m.bottom,x=s?Math.max(O/_.x,C/_.y):Math.min(O/_.x,C/_.y);l.push(this.moveTo(o.x,o.y,o.z,e)),l.push(this.zoomTo(x,e)),l.push(this.setFocalOffset(0,0,0,e))}return Promise.all(l)}fitToSphere(t,e){const s=[],i="isObject3D"in t?j.createBoundingSphere(t,ft):ft.copy(t);if(s.push(this.moveTo(i.center.x,i.center.y,i.center.z,e)),N(this._camera)){const n=this.getDistanceToFitSphere(i.radius);s.push(this.dollyTo(n,e))}else if(B(this._camera)){const n=this._camera.right-this._camera.left,a=this._camera.top-this._camera.bottom,l=2*i.radius,d=Math.min(n/l,a/l);s.push(this.zoomTo(d,e))}return s.push(this.setFocalOffset(0,0,0,e)),Promise.all(s)}setLookAt(t,e,s,r,i,n,a=!1){this._isUserControllingRotate=!1,this._isUserControllingDolly=!1,this._isUserControllingTruck=!1,this._lastDollyDirection=Z.NONE,this._changedDolly=0;const l=P.set(r,i,n),d=S.set(t,e,s);this._targetEnd.copy(l),this._sphericalEnd.setFromVector3(d.sub(l).applyQuaternion(this._yAxisUpSpace)),this.normalizeRotations(),this._needsUpdate=!0,a||(this._target.copy(this._targetEnd),this._spherical.copy(this._sphericalEnd));const g=!a||A(this._target.x,this._targetEnd.x,this.restThreshold)&&A(this._target.y,this._targetEnd.y,this.restThreshold)&&A(this._target.z,this._targetEnd.z,this.restThreshold)&&A(this._spherical.theta,this._sphericalEnd.theta,this.restThreshold)&&A(this._spherical.phi,this._sphericalEnd.phi,this.restThreshold)&&A(this._spherical.radius,this._sphericalEnd.radius,this.restThreshold);return this._createOnRestPromise(g)}lerpLookAt(t,e,s,r,i,n,a,l,d,g,c,E,y,u=!1){this._isUserControllingRotate=!1,this._isUserControllingDolly=!1,this._isUserControllingTruck=!1,this._lastDollyDirection=Z.NONE,this._changedDolly=0;const p=S.set(r,i,n),_=P.set(t,e,s);M.setFromVector3(_.sub(p).applyQuaternion(this._yAxisUpSpace));const o=W.set(g,c,E),m=P.set(a,l,d);et.setFromVector3(m.sub(o).applyQuaternion(this._yAxisUpSpace)),this._targetEnd.copy(p.lerp(o,y));const O=et.theta-M.theta,C=et.phi-M.phi,x=et.radius-M.radius;this._sphericalEnd.set(M.radius+x*y,M.phi+C*y,M.theta+O*y),this.normalizeRotations(),this._needsUpdate=!0,u||(this._target.copy(this._targetEnd),this._spherical.copy(this._sphericalEnd));const T=!u||A(this._target.x,this._targetEnd.x,this.restThreshold)&&A(this._target.y,this._targetEnd.y,this.restThreshold)&&A(this._target.z,this._targetEnd.z,this.restThreshold)&&A(this._spherical.theta,this._sphericalEnd.theta,this.restThreshold)&&A(this._spherical.phi,this._sphericalEnd.phi,this.restThreshold)&&A(this._spherical.radius,this._sphericalEnd.radius,this.restThreshold);return this._createOnRestPromise(T)}setPosition(t,e,s,r=!1){return this.setLookAt(t,e,s,this._targetEnd.x,this._targetEnd.y,this._targetEnd.z,r)}setTarget(t,e,s,r=!1){const i=this.getPosition(S),n=this.setLookAt(i.x,i.y,i.z,t,e,s,r);return this._sphericalEnd.phi=F(this._sphericalEnd.phi,this.minPolarAngle,this.maxPolarAngle),n}setFocalOffset(t,e,s,r=!1){this._isUserControllingOffset=!1,this._focalOffsetEnd.set(t,e,s),this._needsUpdate=!0,r||this._focalOffset.copy(this._focalOffsetEnd);const i=!r||A(this._focalOffset.x,this._focalOffsetEnd.x,this.restThreshold)&&A(this._focalOffset.y,this._focalOffsetEnd.y,this.restThreshold)&&A(this._focalOffset.z,this._focalOffsetEnd.z,this.restThreshold);return this._createOnRestPromise(i)}setOrbitPoint(t,e,s){this._camera.updateMatrixWorld(),H.setFromMatrixColumn(this._camera.matrixWorldInverse,0),I.setFromMatrixColumn(this._camera.matrixWorldInverse,1),Y.setFromMatrixColumn(this._camera.matrixWorldInverse,2);const r=S.set(t,e,s),i=r.distanceTo(this._camera.position),n=r.sub(this._camera.position);H.multiplyScalar(n.x),I.multiplyScalar(n.y),Y.multiplyScalar(n.z),S.copy(H).add(I).add(Y),S.z=S.z+i,this.dollyTo(i,!1),this.setFocalOffset(-S.x,S.y,-S.z,!1),this.moveTo(t,e,s,!1)}setBoundary(t){if(!t){this._boundary.min.set(-1/0,-1/0,-1/0),this._boundary.max.set(1/0,1/0,1/0),this._needsUpdate=!0;return}this._boundary.copy(t),this._boundary.clampPoint(this._targetEnd,this._targetEnd),this._needsUpdate=!0}setViewport(t,e,s,r){if(t===null){this._viewport=null;return}this._viewport=this._viewport||new v.Vector4,typeof t=="number"?this._viewport.set(t,e,s,r):this._viewport.copy(t)}getDistanceToFitBox(t,e,s,r=!1){if(_t(this._camera,"getDistanceToFitBox"))return this._spherical.radius;const i=t/e,n=this._camera.getEffectiveFOV()*Q,a=this._camera.aspect;return((r?i>a:i<a)?e:t/a)*.5/Math.tan(n*.5)+s*.5}getDistanceToFitSphere(t){if(_t(this._camera,"getDistanceToFitSphere"))return this._spherical.radius;const e=this._camera.getEffectiveFOV()*Q,s=Math.atan(Math.tan(e*.5)*this._camera.aspect)*2,r=1<this._camera.aspect?e:s;return t/Math.sin(r*.5)}getTarget(t,e=!0){return(t&&t.isVector3?t:new v.Vector3).copy(e?this._targetEnd:this._target)}getPosition(t,e=!0){return(t&&t.isVector3?t:new v.Vector3).setFromSpherical(e?this._sphericalEnd:this._spherical).applyQuaternion(this._yAxisUpSpaceInverse).add(e?this._targetEnd:this._target)}getSpherical(t,e=!0){return(t||new v.Spherical).copy(e?this._sphericalEnd:this._spherical)}getFocalOffset(t,e=!0){return(t&&t.isVector3?t:new v.Vector3).copy(e?this._focalOffsetEnd:this._focalOffset)}normalizeRotations(){this._sphericalEnd.theta=this._sphericalEnd.theta%q,this._sphericalEnd.theta<0&&(this._sphericalEnd.theta+=q),this._spherical.theta+=q*Math.round((this._sphericalEnd.theta-this._spherical.theta)/q)}reset(t=!1){if(!A(this._camera.up.x,this._cameraUp0.x)||!A(this._camera.up.y,this._cameraUp0.y)||!A(this._camera.up.z,this._cameraUp0.z)){this._camera.up.copy(this._cameraUp0);const s=this.getPosition(S);this.updateCameraUp(),this.setPosition(s.x,s.y,s.z)}const e=[this.setLookAt(this._position0.x,this._position0.y,this._position0.z,this._target0.x,this._target0.y,this._target0.z,t),this.setFocalOffset(this._focalOffset0.x,this._focalOffset0.y,this._focalOffset0.z,t),this.zoomTo(this._zoom0,t)];return Promise.all(e)}saveState(){this._cameraUp0.copy(this._camera.up),this.getTarget(this._target0),this.getPosition(this._position0),this._zoom0=this._zoom,this._focalOffset0.copy(this._focalOffset)}updateCameraUp(){this._yAxisUpSpace.setFromUnitVectors(this._camera.up,ht),this._yAxisUpSpaceInverse.copy(this._yAxisUpSpace).invert()}applyCameraUp(){const t=S.subVectors(this._target,this._camera.position).normalize(),e=P.crossVectors(t,this._camera.up);this._camera.up.crossVectors(e,t).normalize(),this._camera.updateMatrixWorld();const s=this.getPosition(S);this.updateCameraUp(),this.setPosition(s.x,s.y,s.z)}update(t){const e=this._sphericalEnd.theta-this._spherical.theta,s=this._sphericalEnd.phi-this._spherical.phi,r=this._sphericalEnd.radius-this._spherical.radius,i=Dt.subVectors(this._targetEnd,this._target),n=bt.subVectors(this._focalOffsetEnd,this._focalOffset),a=this._zoomEnd-this._zoom;if(b(e))this._thetaVelocity.value=0,this._spherical.theta=this._sphericalEnd.theta;else{const c=this._isUserControllingRotate?this.draggingSmoothTime:this.smoothTime;this._spherical.theta=nt(this._spherical.theta,this._sphericalEnd.theta,this._thetaVelocity,c,1/0,t),this._needsUpdate=!0}if(b(s))this._phiVelocity.value=0,this._spherical.phi=this._sphericalEnd.phi;else{const c=this._isUserControllingRotate?this.draggingSmoothTime:this.smoothTime;this._spherical.phi=nt(this._spherical.phi,this._sphericalEnd.phi,this._phiVelocity,c,1/0,t),this._needsUpdate=!0}if(b(r))this._radiusVelocity.value=0,this._spherical.radius=this._sphericalEnd.radius;else{const c=this._isUserControllingDolly?this.draggingSmoothTime:this.smoothTime;this._spherical.radius=nt(this._spherical.radius,this._sphericalEnd.radius,this._radiusVelocity,c,this.maxSpeed,t),this._needsUpdate=!0}if(b(i.x)&&b(i.y)&&b(i.z))this._targetVelocity.set(0,0,0),this._target.copy(this._targetEnd);else{const c=this._isUserControllingTruck?this.draggingSmoothTime:this.smoothTime;Pt(this._target,this._targetEnd,this._targetVelocity,c,this.maxSpeed,t,this._target),this._needsUpdate=!0}if(b(n.x)&&b(n.y)&&b(n.z))this._focalOffsetVelocity.set(0,0,0),this._focalOffset.copy(this._focalOffsetEnd);else{const c=this._isUserControllingOffset?this.draggingSmoothTime:this.smoothTime;Pt(this._focalOffset,this._focalOffsetEnd,this._focalOffsetVelocity,c,this.maxSpeed,t,this._focalOffset),this._needsUpdate=!0}if(b(a))this._zoomVelocity.value=0,this._zoom=this._zoomEnd;else{const c=this._isUserControllingZoom?this.draggingSmoothTime:this.smoothTime;this._zoom=nt(this._zoom,this._zoomEnd,this._zoomVelocity,c,1/0,t)}if(this.dollyToCursor){if(N(this._camera)&&this._changedDolly!==0){const c=this._spherical.radius-this._lastDistance,E=this._camera,y=this._getCameraDirection(tt),u=S.copy(y).cross(E.up).normalize();u.lengthSq()===0&&(u.x=1);const p=P.crossVectors(u,y),_=this._sphericalEnd.radius*Math.tan(E.getEffectiveFOV()*Q*.5),m=(this._sphericalEnd.radius-c-this._sphericalEnd.radius)/this._sphericalEnd.radius,O=W.copy(this._targetEnd).add(u.multiplyScalar(this._dollyControlCoord.x*_*E.aspect)).add(p.multiplyScalar(this._dollyControlCoord.y*_)),C=S.copy(this._targetEnd).lerp(O,m),x=this._lastDollyDirection===Z.IN&&this._spherical.radius<=this.minDistance,T=this._lastDollyDirection===Z.OUT&&this.maxDistance<=this._spherical.radius;if(this.infinityDolly&&(x||T)){this._sphericalEnd.radius-=c,this._spherical.radius-=c;const R=P.copy(y).multiplyScalar(-c);C.add(R)}this._boundary.clampPoint(C,C);const D=P.subVectors(C,this._targetEnd);this._targetEnd.copy(C),this._target.add(D),this._changedDolly-=c,b(this._changedDolly)&&(this._changedDolly=0)}else if(B(this._camera)&&this._changedZoom!==0){const c=this._zoom-this._lastZoom,E=this._camera,y=S.set(this._dollyControlCoord.x,this._dollyControlCoord.y,(E.near+E.far)/(E.near-E.far)).unproject(E),u=P.set(0,0,-1).applyQuaternion(E.quaternion),p=W.copy(y).add(u.multiplyScalar(-y.dot(E.up))),o=-(this._zoom-c-this._zoom)/this._zoom,m=this._getCameraDirection(tt),O=this._targetEnd.dot(m),C=S.copy(this._targetEnd).lerp(p,o),x=C.dot(m),T=m.multiplyScalar(x-O);C.sub(T),this._boundary.clampPoint(C,C);const D=P.subVectors(C,this._targetEnd);this._targetEnd.copy(C),this._target.add(D),this._changedZoom-=c,b(this._changedZoom)&&(this._changedZoom=0)}}this._camera.zoom!==this._zoom&&(this._camera.zoom=this._zoom,this._camera.updateProjectionMatrix(),this._updateNearPlaneCorners(),this._needsUpdate=!0),this._dragNeedsUpdate=!0;const l=this._collisionTest();this._spherical.radius=Math.min(this._spherical.radius,l),this._spherical.makeSafe(),this._camera.position.setFromSpherical(this._spherical).applyQuaternion(this._yAxisUpSpaceInverse).add(this._target),this._camera.lookAt(this._target),(!b(this._focalOffset.x)||!b(this._focalOffset.y)||!b(this._focalOffset.z))&&(this._camera.updateMatrixWorld(),H.setFromMatrixColumn(this._camera.matrix,0),I.setFromMatrixColumn(this._camera.matrix,1),Y.setFromMatrixColumn(this._camera.matrix,2),H.multiplyScalar(this._focalOffset.x),I.multiplyScalar(-this._focalOffset.y),Y.multiplyScalar(this._focalOffset.z),S.copy(H).add(I).add(Y),this._camera.position.add(S)),this._boundaryEnclosesCamera&&this._encloseToBoundary(this._camera.position.copy(this._target),S.setFromSpherical(this._spherical).applyQuaternion(this._yAxisUpSpaceInverse),1);const g=this._needsUpdate;return g&&!this._updatedLastTime?(this._hasRested=!1,this.dispatchEvent({type:"wake"}),this.dispatchEvent({type:"update"})):g?(this.dispatchEvent({type:"update"}),b(e,this.restThreshold)&&b(s,this.restThreshold)&&b(r,this.restThreshold)&&b(i.x,this.restThreshold)&&b(i.y,this.restThreshold)&&b(i.z,this.restThreshold)&&b(n.x,this.restThreshold)&&b(n.y,this.restThreshold)&&b(n.z,this.restThreshold)&&b(a,this.restThreshold)&&!this._hasRested&&(this._hasRested=!0,this.dispatchEvent({type:"rest"}))):!g&&this._updatedLastTime&&(this._hasRested||(this._hasRested=!0,this.dispatchEvent({type:"rest"})),this.dispatchEvent({type:"sleep"})),this._lastDistance=this._spherical.radius,this._lastZoom=this._zoom,this._updatedLastTime=g,this._needsUpdate=!1,g}toJSON(){return JSON.stringify({enabled:this._enabled,minDistance:this.minDistance,maxDistance:$(this.maxDistance),minZoom:this.minZoom,maxZoom:$(this.maxZoom),minPolarAngle:this.minPolarAngle,maxPolarAngle:$(this.maxPolarAngle),minAzimuthAngle:$(this.minAzimuthAngle),maxAzimuthAngle:$(this.maxAzimuthAngle),smoothTime:this.smoothTime,draggingSmoothTime:this.draggingSmoothTime,dollySpeed:this.dollySpeed,truckSpeed:this.truckSpeed,dollyToCursor:this.dollyToCursor,verticalDragToForward:this.verticalDragToForward,target:this._targetEnd.toArray(),position:S.setFromSpherical(this._sphericalEnd).add(this._targetEnd).toArray(),zoom:this._zoomEnd,focalOffset:this._focalOffsetEnd.toArray(),target0:this._target0.toArray(),position0:this._position0.toArray(),zoom0:this._zoom0,focalOffset0:this._focalOffset0.toArray()})}fromJSON(t,e=!1){const s=JSON.parse(t);this.enabled=s.enabled,this.minDistance=s.minDistance,this.maxDistance=J(s.maxDistance),this.minZoom=s.minZoom,this.maxZoom=J(s.maxZoom),this.minPolarAngle=s.minPolarAngle,this.maxPolarAngle=J(s.maxPolarAngle),this.minAzimuthAngle=J(s.minAzimuthAngle),this.maxAzimuthAngle=J(s.maxAzimuthAngle),this.smoothTime=s.smoothTime,this.draggingSmoothTime=s.draggingSmoothTime,this.dollySpeed=s.dollySpeed,this.truckSpeed=s.truckSpeed,this.dollyToCursor=s.dollyToCursor,this.verticalDragToForward=s.verticalDragToForward,this._target0.fromArray(s.target0),this._position0.fromArray(s.position0),this._zoom0=s.zoom0,this._focalOffset0.fromArray(s.focalOffset0),this.moveTo(s.target[0],s.target[1],s.target[2],e),M.setFromVector3(S.fromArray(s.position).sub(this._targetEnd).applyQuaternion(this._yAxisUpSpace)),this.rotateTo(M.theta,M.phi,e),this.dollyTo(M.radius,e),this.zoomTo(s.zoom,e),this.setFocalOffset(s.focalOffset[0],s.focalOffset[1],s.focalOffset[2],e),this._needsUpdate=!0}connect(t){if(this._domElement){console.warn("camera-controls is already connected.");return}this._addAllEventListeners(t),this._getClientRect(this._elementRect)}disconnect(){this.cancel(),this._removeAllEventListeners(),this._domElement&&(this._domElement=void 0)}dispose(){this.removeAllEventListeners(),this.disconnect()}_getTargetDirection(t){return t.setFromSpherical(this._spherical).divideScalar(this._spherical.radius).applyQuaternion(this._yAxisUpSpaceInverse)}_getCameraDirection(t){return this._getTargetDirection(t).negate()}_findPointerById(t){return this._activePointers.find(e=>e.pointerId===t)}_findPointerByMouseButton(t){return this._activePointers.find(e=>e.mouseButton===t)}_disposePointer(t){this._activePointers.splice(this._activePointers.indexOf(t),1)}_encloseToBoundary(t,e,s){const r=e.lengthSq();if(r===0)return t;const i=P.copy(e).add(t),a=this._boundary.clampPoint(i,W).sub(i),l=a.lengthSq();if(l===0)return t.add(e);if(l===r)return t;if(s===0)return t.add(e).add(a);{const d=1+s*l/e.dot(a);return t.add(P.copy(e).multiplyScalar(d)).add(a.multiplyScalar(1-s))}}_updateNearPlaneCorners(){if(N(this._camera)){const t=this._camera,e=t.near,s=t.getEffectiveFOV()*Q,r=Math.tan(s*.5)*e,i=r*t.aspect;this._nearPlaneCorners[0].set(-i,-r,0),this._nearPlaneCorners[1].set(i,-r,0),this._nearPlaneCorners[2].set(i,r,0),this._nearPlaneCorners[3].set(-i,r,0)}else if(B(this._camera)){const t=this._camera,e=1/t.zoom,s=t.left*e,r=t.right*e,i=t.top*e,n=t.bottom*e;this._nearPlaneCorners[0].set(s,i,0),this._nearPlaneCorners[1].set(r,i,0),this._nearPlaneCorners[2].set(r,n,0),this._nearPlaneCorners[3].set(s,n,0)}}_collisionTest(){let t=1/0;if(!(this.colliderMeshes.length>=1)||_t(this._camera,"_collisionTest"))return t;const s=this._getTargetDirection(tt);Ct.lookAt(At,s,this._camera.up);for(let r=0;r<4;r++){const i=P.copy(this._nearPlaneCorners[r]);i.applyMatrix4(Ct);const n=W.addVectors(this._target,i);lt.set(n,s),lt.far=this._spherical.radius+1;const a=lt.intersectObjects(this.colliderMeshes);a.length!==0&&a[0].distance<t&&(t=a[0].distance)}return t}_getClientRect(t){if(!this._domElement)return;const e=this._domElement.getBoundingClientRect();return t.x=e.left,t.y=e.top,this._viewport?(t.x+=this._viewport.x,t.y+=e.height-this._viewport.w-this._viewport.y,t.width=this._viewport.z,t.height=this._viewport.w):(t.width=e.width,t.height=e.height),t}_createOnRestPromise(t){return t?Promise.resolve():(this._hasRested=!1,this.dispatchEvent({type:"transitionstart"}),new Promise(e=>{const s=()=>{this.removeEventListener("rest",s),e()};this.addEventListener("rest",s)}))}_addAllEventListeners(t){}_removeAllEventListeners(){}get dampingFactor(){return console.warn(".dampingFactor has been deprecated. use smoothTime (in seconds) instead."),0}set dampingFactor(t){console.warn(".dampingFactor has been deprecated. use smoothTime (in seconds) instead.")}get draggingDampingFactor(){return console.warn(".draggingDampingFactor has been deprecated. use draggingSmoothTime (in seconds) instead."),0}set draggingDampingFactor(t){console.warn(".draggingDampingFactor has been deprecated. use draggingSmoothTime (in seconds) instead.")}static createBoundingSphere(t,e=new v.Sphere){const s=e,r=s.center;G.makeEmpty(),t.traverseVisible(n=>{n.isMesh&&G.expandByObject(n)}),G.getCenter(r);let i=0;return t.traverseVisible(n=>{if(!n.isMesh)return;const a=n,l=a.geometry.clone();l.applyMatrix4(a.matrixWorld);const g=l.attributes.position;for(let c=0,E=g.count;c<E;c++)S.fromBufferAttribute(g,c),i=Math.max(i,r.distanceToSquared(S))}),s.radius=Math.sqrt(i),s}}const ge={antialias:!1,devicePixelRatio:window.devicePixelRatio,powerPreference:"high-performance",toneMappingExposure:1,alpha:!1,outputColorSpace:se.ColorSpace.sRGB,logarithmicDepthBuffer:!1,preserveDrawingBuffer:!1,stencil:!1,depth:!1,physicallyCorrectLights:!1};class Ce{constructor(t){this.options=t;const{width:e,height:s,rendererParams:r}=t,{canvas:i,context:n,alpha:a,devicePixelRatio:l,antialias:d,powerPreference:g,toneMappingExposure:c,outputColorSpace:E,logarithmicDepthBuffer:y,preserveDrawingBuffer:u,stencil:p,depth:_,physicallyCorrectLights:o}=r,m=new w.WebGLRenderer({canvas:i,context:n,alpha:a,antialias:d,powerPreference:g,logarithmicDepthBuffer:y,preserveDrawingBuffer:u,stencil:p,depth:_});m.setSize(e,s),m.setPixelRatio(l),m.toneMappingExposure=c,m.outputColorSpace=E,+w.REVISION<155&&(m.useLegacyLights=o),this.renderer=m}setSize(t,e){this.renderer.setSize(t,e)}setPixelRatio(t){this.renderer.setPixelRatio(t)}render(){const{sceneController:t,cameraController:e}=this.options;this.renderer.render(t.scene,e.camera)}setViewport(t){var g,c;const{cameraController:e}=this.options,{x:s,y:r,width:i,height:n}=t,a=(g=t.scissor)!=null?g:!1,l=(c=t.scissorTest)!=null?c:!1,d=i/n;e.camera.aspect!==d&&(e.camera.aspect=d,e.camera.updateProjectionMatrix()),this.renderer.setViewport(s,r,i,n),a&&(this.renderer.setScissor(s,r,i,n),this.renderer.setScissorTest(l))}setViewPadding(t=0,e=0,s=0,r=0){const{width:i,height:n}=this.renderer.getSize(new w.Vector2),a={x:r,y:s,width:i-r-e,height:n-t-s};this.setViewport(a)}dispose(){var t,e;this.setSize(1,1),(t=this.renderer)==null||t.clear(),(e=this.renderer)==null||e.dispose()}}const ye={antialias:!0,devicePixelRatio:window.devicePixelRatio};class Ee{constructor(t){this.options=t;const{width:e,height:s,rendererParams:r,renderer:i}=t,{devicePixelRatio:n,antialias:a}=r,l=new i({antialias:a});l.setSize(e,s),l.setPixelRatio(n),this.renderer=l}setSize(t,e){this.renderer.setSize(t,e)}render(){const{sceneController:t,cameraController:e}=this.options;this.renderer.render(t.scene,e.camera)}dispose(){var t,e;this.setSize(1,1),(t=this.renderer)==null||t.clear(),(e=this.renderer)==null||e.dispose()}}const Oe={fov:45,near:1,far:1e3,up:new w.Vector3(0,1,0)};class Te{constructor(t){this.event=new st.eventsExports.EventEmitter,this.cameraArr=[],this.cameraActiveIndex=0,this.customCamera=!1,this.options=t;const{cameraParams:e,width:s,height:r}=t;if(e instanceof w.Camera)this.cameraArr.push(e),this.customCamera=!0;else{const i=this.addPerspectiveCamera(ot(V({},e),{aspect:s/r}));i.position.set(0,0,400),i.lookAt(0,0,0)}}get camera(){return this.cameraArr[this.cameraActiveIndex]}addPerspectiveCamera(t){const{fov:e,far:s,near:r,up:i,aspect:n}=t,a=new w.PerspectiveCamera(e,n,r,s);return a.up=i,this.cameraArr.push(a),a}setCameraActive(t){this.cameraActiveIndex=t,this.event.emit("cameraChange",this.camera)}setSize(t,e){this.options.width=t,this.options.height=e,this.cameraArr.forEach(s=>{s instanceof w.PerspectiveCamera&&(s.aspect=t/e),s.updateProjectionMatrix()})}cloneCamera(){const t=this.addPerspectiveCamera({fov:this.camera.fov,aspect:this.camera.aspect,near:this.camera.near,far:this.camera.far,up:this.camera.up});return t.position.copy(this.camera.position),t}sync(t){if(t.type==="PerspectiveCamera"){const e=t;(!this.camera.matrixWorld.equals(e.matrixWorld)||this.camera.far!==e.far||this.camera.near!==e.near||this.camera.fov!==e.fov||this.camera.aspect!==e.aspect)&&this.camera.copy(e)}else{const e=t,s=e.viewMatrix,r=e.inverseViewMatrix,i=new w.Matrix4(r[0],r[4],r[8],r[12],r[1],r[5],r[9],r[13],r[2],r[6],r[10],r[14],r[3],r[7],r[11],r[15]),n=new w.Matrix4(s[0],s[4],s[8],s[12],s[1],s[5],s[9],s[13],s[2],s[6],s[10],s[14],s[3],s[7],s[11],s[15]),{width:a,height:l}=this.options,d=a/l;(this.camera.fov!==e.fov||this.camera.aspect!==d||!this.camera.matrixWorld.equals(i)||!this.camera.matrixWorldInverse.equals(n))&&(this.camera.fov=e.fov,this.camera.updateProjectionMatrix(),this.camera.matrixAutoUpdate=!1,this.camera.matrixWorld.copy(i),this.camera.matrixWorldInverse.copy(n),this.camera.aspect=d,this.camera.updateProjectionMatrix())}}}const ve={background:null,addCamera:!0};class xe{constructor(t){this.event=new st.eventsExports.EventEmitter,this.sceneArr=[],this.sceneActiveIndex=0,this.overrideMaterial=!1,this.options=t;const{cameraController:e,sceneParams:s}=t,{addCamera:r}=s;this.addScene(),r&&this.scene.add(e.camera)}get scene(){return this.sceneArr[this.sceneActiveIndex]}addScene(){const{sceneParams:t}=this.options,{background:e}=t,s=new w.Scene;return e&&(s.background=e),this.sceneArr.push(s),s}setSceneActive(t){this.sceneActiveIndex=t,this.event.emit("sceneChange",this.scene)}dispose(){this.sceneArr.forEach(t=>{t.traverse(e=>{ie.disposeMesh(e)})})}}class we{constructor(t){this.helpers={},this.options=t}add(t){const e=t.uuid,{sceneController:s}=this.options;let r=this.helpers[e];if(r===void 0){if(t.isScene)r=new w.AxesHelper(100);else if(t.isCamera)r=new w.CameraHelper(t);else if(t.isPointLight)r=new w.PointLightHelper(t,1);else if(t.isDirectionalLight)r=new w.DirectionalLightHelper(t,1);else if(t.isSpotLight)r=new w.SpotLightHelper(t);else if(t.isHemisphereLight)r=new w.HemisphereLightHelper(t,10);else if(t.isRectAreaLight)r=new re.RectAreaLightHelper(t);else{const i=new w.Box3;if(i.setFromObject(t,!0),i.isEmpty()===!1){r=new w.Box3Helper(i);const n=r.material;n.userData.object=t,n.depthTest=!1,n.transparent=!0}else return}s.scene.add(r),this.helpers[e]=r}}addViewHelper(){const{cameraController:t,container:e}=this.options,s=new oe.ViewHelper(t.camera,e);e.addEventListener("pointerdown",r=>{r.preventDefault(),s.handleClick(r)}),this.viewHelper=s}remove(t){var r;const e=t.uuid,{sceneController:s}=this.options;if(this.helpers[e]!==void 0){const i=this.helpers[e];s.scene.remove(i),delete this.helpers[e],(r=i.dispose)==null||r.call(i)}}removeAll(){Object.keys(this.helpers).forEach(t=>{this.remove({uuid:t})}),this.helpers={}}removeAllExcludeScene(){Object.keys(this.helpers).forEach(t=>{this.helpers[t]instanceof w.AxesHelper||this.remove({uuid:t})})}update(t,e,s){var i,n;const{cameraController:r}=this.options;Object.values(this.helpers).forEach(a=>{if(a.update&&a.update(),a instanceof w.Box3Helper){const l=a.material,{object:d}=l.userData;d&&a.box.setFromObject(d,!0)}}),((i=this.viewHelper)==null?void 0:i.animating)===!0&&(this.viewHelper.update(t),(n=e.cameraControls)==null||n.setPosition(...r.camera.position.toArray()),this.viewHelper.center.copy(s))}renderViewHelper(t){if(!this.viewHelper)return;const e=t.autoClear;t.autoClear=!1,this.viewHelper.render(t),t.autoClear=e}dispose(){var t;this.helpers={},(t=this.viewHelper)==null||t.dispose()}}class Se{constructor(t){this.event=new st.eventsExports.EventEmitter,this.cameraControlsArr=[],this.cameraControlsActiveIndex=0,this.autoRotateSpeed=0,this.options=t;const{camera:e,controlsParams:s,customControls:r}=t,{domElement:i}=s;if(r){const n=new r(e,i);n.enableDamping=!0,n.dampingFactor=.063,n.autoRotate=!1,n.autoRotateSpeed=-60,n.enableZoom=!0,n.zoomSpeed=.2,this.customControls=n}else j.install({THREE:w}),this.addCameraControls(e)}get cameraControls(){return this.cameraControlsArr[this.cameraControlsActiveIndex]}addCameraControls(t,e){const{controlsParams:s}=this.options,{domElement:r}=s,i=new j(t,r);return e&&(i.interactiveArea=e),i.addEventListener("update",()=>{this.cameraControlsArr.length>1&&this.cameraControlsArr.forEach(n=>{n!==i&&(n.enabled=!1)})}),i.addEventListener("sleep",()=>{this.cameraControlsArr.length>1&&this.cameraControlsArr.forEach(n=>{n!==i&&(n.enabled=!0)})}),this.cameraControlsArr.push(i),i}setCameraControlsActive(t){this.cameraControlsActiveIndex=t}enable(){this.customControls?this.customControls.enabled=!0:this.cameraControls&&this.cameraControlsArr.forEach(t=>{t.enabled=!0})}disable(){this.customControls?this.customControls.enabled=!1:this.cameraControls&&this.cameraControlsArr.forEach(t=>{t.enabled=!1})}update(t){var e;(e=this.customControls)==null||e.update(),this.cameraControlsArr.forEach(s=>{s.update(t)}),this.autoRotateSpeed&&this.cameraControls&&(this.cameraControls.azimuthAngle+=this.autoRotateSpeed*t*w.MathUtils.DEG2RAD)}dispose(){var t;(t=this.customControls)==null||t.dispose(),this.cameraControlsArr.forEach(e=>{e.dispose()})}}class Pe{constructor(t){this.event=new st.eventsExports.EventEmitter;const{renderer:e,scene:s,camera:r}=t,i=new ne.TransformControls(r,e.domElement);if(i.getHelper){const n=i.getHelper();if(s.add(n),+w.REVISION<170){const a=i._root;a.dispose=()=>{a.traverse(l=>{l.geometry&&l.geometry.dispose(),l.material&&l.material.dispose()})},i.dispose=()=>{i.disconnect(),a.dispose()}}}else i instanceof w.Object3D&&s.add(i);this.controls=i,this.addEvent()}get detach(){return this.controls.detach.bind(this.controls)}get attach(){return this.controls.attach.bind(this.controls)}addEvent(){let t=null,e=null,s=null;const r=this.controls;r.addEventListener("change",()=>{const i=r.object;i!==void 0&&this.event.emit("change",i)}),r.addEventListener("mouseDown",()=>{const i=r.object;t=i.position.clone(),e=i.rotation.clone(),s=i.scale.clone(),this.event.emit("mouseDown",i)}),r.addEventListener("mouseUp",()=>{const i=r.object;if(i!==void 0)switch(r.getMode()){case"translate":t.equals(i.position)||this.event.emit("translate",i,i.position,t);break;case"rotate":e.equals(i.rotation)||this.event.emit("rotate",i,i.rotation,e);break;case"scale":s.equals(i.scale)||this.event.emit("scale",i,i.scale,s);break}this.event.emit("mouseUp")})}dispose(){var t;this.event.removeAllListeners(),(t=this.controls)==null||t.dispose()}}const Lt=new z.Vector3,Ae=new z.Quaternion,zt=new z.Vector3,k=new z.Matrix4,De=new z.Matrix4;class be{constructor(t={}){const e=this;let s,r,i,n;const a={camera:{style:""},objects:new WeakMap},l=t.element!==void 0?t.element:document.createElement("div");l.style.overflow="hidden",this.domElement=l;const d=document.createElement("div");d.style.transformOrigin="0 0",d.style.pointerEvents="none",l.appendChild(d);const g=document.createElement("div");g.style.transformStyle="preserve-3d",d.appendChild(g),this.getSize=function(){return{width:s,height:r}},this.render=function(_,o){const m=o.projectionMatrix.elements[5]*n;o.view&&o.view.enabled?(d.style.transform=`translate( ${-o.view.offsetX*(s/o.view.width)}px, ${-o.view.offsetY*(r/o.view.height)}px )`,d.style.transform+=`scale( ${o.view.fullWidth/o.view.width}, ${o.view.fullHeight/o.view.height} )`):d.style.transform="",_.matrixWorldAutoUpdate===!0&&_.updateMatrixWorld(),o.parent===null&&o.matrixWorldAutoUpdate===!0&&o.updateMatrixWorld();let O,C;o.isOrthographicCamera&&(O=-(o.right+o.left)/2,C=(o.top+o.bottom)/2);const x=o.view&&o.view.enabled?o.view.height/o.view.fullHeight:1,T=o.isOrthographicCamera?`scale( ${x} )scale(`+m+")translate("+c(O)+"px,"+c(C)+"px)"+E(o.matrixWorldInverse):`scale( ${x} )translateZ(`+m+"px)"+E(o.matrixWorldInverse),R=(o.isPerspectiveCamera?"perspective("+m+"px) ":"")+T+"translate("+i+"px,"+n+"px)";a.camera.style!==R&&(g.style.transform=R,a.camera.style=R),p(_,_,o)},this.setSize=function(_,o){s=_,r=o,i=s/2,n=r/2,l.style.width=_+"px",l.style.height=o+"px",d.style.width=_+"px",d.style.height=o+"px",g.style.width=_+"px",g.style.height=o+"px"};function c(_){return Math.abs(_)<1e-10?0:_}function E(_){const o=_.elements;return"matrix3d("+c(o[0])+","+c(-o[1])+","+c(o[2])+","+c(o[3])+","+c(o[4])+","+c(-o[5])+","+c(o[6])+","+c(o[7])+","+c(o[8])+","+c(-o[9])+","+c(o[10])+","+c(o[11])+","+c(o[12])+","+c(-o[13])+","+c(o[14])+","+c(o[15])+")"}function y(_){const o=_.elements;return"translate(-50%,-50%)"+("matrix3d("+c(o[0])+","+c(o[1])+","+c(o[2])+","+c(o[3])+","+c(-o[4])+","+c(-o[5])+","+c(-o[6])+","+c(-o[7])+","+c(o[8])+","+c(o[9])+","+c(o[10])+","+c(o[11])+","+c(o[12])+","+c(o[13])+","+c(o[14])+","+c(o[15])+")")}function u(_){_.isCSS3DObject&&(_.element.style.display="none");for(let o=0,m=_.children.length;o<m;o++)u(_.children[o])}function p(_,o,m,O){if(_.visible===!1){u(_);return}if(_.isCSS3DObject){const C=_.layers.test(m.layers)===!0,x=_.element;if(x.style.display=C===!0?"":"none",C===!0){_.onBeforeRender(e,o,m);let T;_.isCSS3DSprite?(k.copy(m.matrixWorldInverse),k.transpose(),_.rotation2D!==0&&k.multiply(De.makeRotationZ(_.rotation2D)),_.matrixWorld.decompose(Lt,Ae,zt),k.setPosition(Lt),k.scale(zt),k.elements[3]=0,k.elements[7]=0,k.elements[11]=0,k.elements[15]=1,T=y(k)):T=y(_.matrixWorld);const D=a.objects.get(_);if(D===void 0||D.style!==T){x.style.transform=T;const R={style:T};a.objects.set(_,R)}x.parentNode!==g&&g.appendChild(x),_.onAfterRender(e,o,m)}}for(let C=0,x=_.children.length;C<x;C++)p(_.children[C],o,m)}}}const X=new z.Vector3,Mt=new z.Matrix4,Ft=new z.Matrix4,Ht=new z.Vector3,It=new z.Vector3;class Ue{constructor(t={}){const e=this;let s,r,i,n;const a={objects:new WeakMap},l=t.element!==void 0?t.element:document.createElement("div");l.style.overflow="hidden",this.domElement=l,this.getSize=function(){return{width:s,height:r}},this.render=function(u,p){u.matrixWorldAutoUpdate===!0&&u.updateMatrixWorld(),p.parent===null&&p.matrixWorldAutoUpdate===!0&&p.updateMatrixWorld(),Mt.copy(p.matrixWorldInverse),Ft.multiplyMatrices(p.projectionMatrix,Mt),g(u,u,p),y(u)},this.setSize=function(u,p){s=u,r=p,i=s/2,n=r/2,l.style.width=u+"px",l.style.height=p+"px"};function d(u){u.isCSS2DObject&&(u.element.style.display="none");for(let p=0,_=u.children.length;p<_;p++)d(u.children[p])}function g(u,p,_){if(u.visible===!1){d(u);return}if(u.isCSS2DObject){X.setFromMatrixPosition(u.matrixWorld),X.applyMatrix4(Ft);const o=X.z>=-1&&X.z<=1&&u.layers.test(_.layers)===!0,m=u.element;m.style.display=o===!0?"":"none",o===!0&&(u.onBeforeRender(e,p,_),m.style.transform="translate("+-100*u.center.x+"%,"+-100*u.center.y+"%)translate("+(X.x*i+i)+"px,"+(-X.y*n+n)+"px)",m.parentNode!==l&&l.appendChild(m),u.onAfterRender(e,p,_));const O={distanceToCameraSquared:c(_,u)};a.objects.set(u,O)}for(let o=0,m=u.children.length;o<m;o++)g(u.children[o],p,_)}function c(u,p){return Ht.setFromMatrixPosition(u.matrixWorld),It.setFromMatrixPosition(p.matrixWorld),Ht.distanceToSquared(It)}function E(u){const p=[];return u.traverseVisible(function(_){_.isCSS2DObject&&p.push(_)}),p}function y(u){const p=E(u).sort(function(o,m){if(o.renderOrder!==m.renderOrder)return m.renderOrder-o.renderOrder;const O=a.objects.get(o).distanceToCameraSquared,C=a.objects.get(m).distanceToCameraSquared;return O-C}),_=p.length;for(let o=0,m=p.length;o<m;o++)p[o].element.style.zIndex=_-o}}}const kt={zIndex:"auto"};class Re{constructor(t){this.container=t}addRenderer(t,e){const s=e.container||this.container,r=s.offsetWidth,i=s.offsetHeight,n=t==="css2d"?new Ue:new be;n.domElement.style.position="absolute",n.domElement.style.top="0",n.domElement.style.pointerEvents="none",n.domElement.style.zIndex=e.zIndex,n.setSize(r,i),s.appendChild(n.domElement),t==="css2d"?this.css2Drenderer=n:t==="css3d"&&(this.css3Drenderer=n)}setSize(t,e){var s,r;(s=this.css2Drenderer)==null||s.setSize(t,e),(r=this.css3Drenderer)==null||r.setSize(t,e)}render(t,e){var s,r;(s=this.css2Drenderer)==null||s.render(t,e),(r=this.css3Drenderer)==null||r.render(t,e)}dispose(){var t,e;(t=this.css2Drenderer)==null||t.domElement.remove(),(e=this.css3Drenderer)==null||e.domElement.remove(),this.css2Drenderer=void 0,this.css3Drenderer=void 0}}class Et{constructor(t){this.guiParams={},t&&(this.guiParams=t)}showGui(t){t&&Object.keys(this.guiParams).forEach(e=>{const s=t.addFolder(e),r=this.guiParams[e];Object.keys(r).forEach(i=>{const{min:n,max:a,step:l,name:d,paramMap:g,items:c,value:E,target:y}=r[i],u=i.toLowerCase().indexOf("color")>-1;let p;const _=typeof E=="undefined"&&y,o=_?y():r[i],m=_?i:"value";c?p=s.add(o,m,c):u?p=s.addColor(o,m):p=s.add(o,m),p=p.name(d||i),typeof n!="undefined"&&(p=p.min(n)),typeof a!="undefined"&&(p=p.max(a)),typeof l!="undefined"&&(p=p.step(l)),p=p.onChange(()=>{this.setTargetValue(e,i,o[m],g)}),_&&p.listen()})})}setTargetValue(t,e,s,r){const{onChange:i,target:n,value:a}=this.guiParams[t][e],l=e.toLowerCase().indexOf("color")>-1;if(n&&!(typeof a=="undefined"&&n)){let g=n();Array.isArray(g)||(g=[g]),g.forEach(c=>{if(c)if(l)try{c[r||e].set(s)}catch(E){e!=="color"&&!r&&console.warn(`${e} is not a color,set paramMap`)}else c[r||e]=s})}i&&i(s)}setTargetValueByParams(){Object.keys(this.guiParams).forEach(t=>{Object.keys(this.guiParams[t]).forEach(e=>{const s=this.guiParams[t][e];typeof s.value!="undefined"&&this.setTargetValue(t,e,s.value,s.paramMap)})})}}const Le={name:"OutputShader",uniforms:{tDiffuse:{value:null},toneMappingExposure:{value:1},premultiplieAlpha:{value:0}},vertexShader:`
1
+ "use strict";var Gt=Object.defineProperty,Xt=Object.defineProperties;var Kt=Object.getOwnPropertyDescriptors;var Ot=Object.getOwnPropertySymbols;var jt=Object.prototype.hasOwnProperty,Qt=Object.prototype.propertyIsEnumerable;var Tt=(f,t,e)=>t in f?Gt(f,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):f[t]=e,V=(f,t)=>{for(var e in t||(t={}))jt.call(t,e)&&Tt(f,e,t[e]);if(Ot)for(var e of Ot(t))Qt.call(t,e)&&Tt(f,e,t[e]);return f},ot=(f,t)=>Xt(f,Kt(t));Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const z=require("three"),$t=require("@tweenjs/tween.js"),st=require("./events.js"),Jt=require("deepmerge"),te=require("stats-gl"),ee=require("lil-gui"),se=require("./colorCorrection.js"),ie=require("./parseVector.js");require("idb-keyval");require("esus-lite");require("d3-geo");require("d3-geo-projection");const re=require("three/examples/jsm/helpers/RectAreaLightHelper"),oe=require("three/examples/jsm/helpers/ViewHelper"),ne=require("three/examples/jsm/controls/TransformControls"),vt=require("three/examples/jsm/postprocessing/EffectComposer"),ae=require("three/examples/jsm/postprocessing/RenderPass"),he=require("three/examples/jsm/postprocessing/SSAOPass"),le=require("three/examples/jsm/postprocessing/Pass"),ce=require("three/examples/jsm/postprocessing/OutputPass"),de=require("three/examples/jsm/postprocessing/ShaderPass"),me=require("three/examples/jsm/postprocessing/UnrealBloomPass");require("three/examples/jsm/renderers/CSS2DRenderer");require("three/examples/jsm/renderers/CSS3DRenderer");require("three/examples/jsm/lights/RectAreaLightUniformsLib");require("three/examples/jsm/lines/LineSegments2");const Vt=require("./index2.js");require("three/examples/jsm/lines/LineSegmentsGeometry");require("three/examples/jsm/lines/LineMaterial");require("three-bvh-csg");const pe=require("./isPlainObject.js"),_e=require("./BaseObject.js");function Bt(f){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(f){for(const e in f)if(e!=="default"){const s=Object.getOwnPropertyDescriptor(f,e);Object.defineProperty(t,e,s.get?s:{enumerable:!0,get:()=>f[e]})}}return t.default=f,Object.freeze(t)}const w=Bt(z),xt=Bt($t),U={LEFT:1,RIGHT:2,MIDDLE:4},h=Object.freeze({NONE:0,ROTATE:1,TRUCK:2,OFFSET:4,DOLLY:8,ZOOM:16,TOUCH_ROTATE:32,TOUCH_TRUCK:64,TOUCH_OFFSET:128,TOUCH_DOLLY:256,TOUCH_ZOOM:512,TOUCH_DOLLY_TRUCK:1024,TOUCH_DOLLY_OFFSET:2048,TOUCH_DOLLY_ROTATE:4096,TOUCH_ZOOM_TRUCK:8192,TOUCH_ZOOM_OFFSET:16384,TOUCH_ZOOM_ROTATE:32768}),Z={NONE:0,IN:1,OUT:-1};function N(f){return f.isPerspectiveCamera}function B(f){return f.isOrthographicCamera}const q=Math.PI*2,wt=Math.PI/2,Nt=1e-5,Q=Math.PI/180;function F(f,t,e){return Math.max(t,Math.min(e,f))}function b(f,t=Nt){return Math.abs(f)<t}function A(f,t,e=Nt){return b(f-t,e)}function St(f,t){return Math.round(f/t)*t}function $(f){return isFinite(f)?f:f<0?-Number.MAX_VALUE:Number.MAX_VALUE}function J(f){return Math.abs(f)<Number.MAX_VALUE?f:f*(1/0)}function nt(f,t,e,s,r=1/0,i){s=Math.max(1e-4,s);const n=2/s,a=n*i,l=1/(1+a+.48*a*a+.235*a*a*a);let d=f-t;const g=t,c=r*s;d=F(d,-c,c),t=f-d;const E=(e.value+n*d)*i;e.value=(e.value-n*E)*l;let y=t+(d+E)*l;return g-f>0==y>g&&(y=g,e.value=(y-g)/i),y}function Pt(f,t,e,s,r=1/0,i,n){s=Math.max(1e-4,s);const a=2/s,l=a*i,d=1/(1+l+.48*l*l+.235*l*l*l);let g=t.x,c=t.y,E=t.z,y=f.x-g,u=f.y-c,p=f.z-E;const _=g,o=c,m=E,O=r*s,C=O*O,x=y*y+u*u+p*p;if(x>C){const mt=Math.sqrt(x);y=y/mt*O,u=u/mt*O,p=p/mt*O}g=f.x-y,c=f.y-u,E=f.z-p;const T=(e.x+a*y)*i,D=(e.y+a*u)*i,R=(e.z+a*p)*i;e.x=(e.x-a*T)*d,e.y=(e.y-a*D)*d,e.z=(e.z-a*R)*d,n.x=g+(y+T)*d,n.y=c+(u+D)*d,n.z=E+(p+R)*d;const it=_-f.x,rt=o-f.y,Yt=m-f.z,Zt=n.x-_,qt=n.y-o,Wt=n.z-m;return it*Zt+rt*qt+Yt*Wt>0&&(n.x=_,n.y=o,n.z=m,e.x=(n.x-_)/i,e.y=(n.y-o)/i,e.z=(n.z-m)/i),n}function pt(f,t){t.set(0,0),f.forEach(e=>{t.x+=e.clientX,t.y+=e.clientY}),t.x/=f.length,t.y/=f.length}function _t(f,t){return B(f)?(console.warn(`${t} is not supported in OrthographicCamera`),!0):!1}class ue{constructor(){this._listeners={}}addEventListener(t,e){const s=this._listeners;s[t]===void 0&&(s[t]=[]),s[t].indexOf(e)===-1&&s[t].push(e)}hasEventListener(t,e){const s=this._listeners;return s[t]!==void 0&&s[t].indexOf(e)!==-1}removeEventListener(t,e){const r=this._listeners[t];if(r!==void 0){const i=r.indexOf(e);i!==-1&&r.splice(i,1)}}removeAllEventListeners(t){if(!t){this._listeners={};return}Array.isArray(this._listeners[t])&&(this._listeners[t].length=0)}dispatchEvent(t){const s=this._listeners[t.type];if(s!==void 0){t.target=this;const r=s.slice(0);for(let i=0,n=r.length;i<n;i++)r[i].call(this,t)}}}const at=1/8,fe=/Mac/.test(navigator.platform);let v,At,ht,ut,L,S,P,W,tt,H,I,Y,Dt,bt,M,et,G,Ut,ft,Rt,gt,Ct,lt;class j extends ue{static install(t){v=t.THREE,At=Object.freeze(new v.Vector3(0,0,0)),ht=Object.freeze(new v.Vector3(0,1,0)),ut=Object.freeze(new v.Vector3(0,0,1)),L=new v.Vector2,S=new v.Vector3,P=new v.Vector3,W=new v.Vector3,tt=new v.Vector3,H=new v.Vector3,I=new v.Vector3,Y=new v.Vector3,Dt=new v.Vector3,bt=new v.Vector3,M=new v.Spherical,et=new v.Spherical,G=new v.Box3,Ut=new v.Box3,ft=new v.Sphere,Rt=new v.Quaternion,gt=new v.Quaternion,Ct=new v.Matrix4,lt=new v.Raycaster}static get ACTION(){return h}constructor(t,e){super(),this.minPolarAngle=0,this.maxPolarAngle=Math.PI,this.minAzimuthAngle=-1/0,this.maxAzimuthAngle=1/0,this.minDistance=Number.EPSILON,this.maxDistance=1/0,this.infinityDolly=!1,this.minZoom=.01,this.maxZoom=1/0,this.smoothTime=.25,this.draggingSmoothTime=.125,this.maxSpeed=1/0,this.azimuthRotateSpeed=1,this.polarRotateSpeed=1,this.dollySpeed=1,this.dollyDragInverted=!1,this.truckSpeed=2,this.dollyToCursor=!1,this.dragToOffset=!1,this.verticalDragToForward=!1,this.boundaryFriction=0,this.restThreshold=.01,this.colliderMeshes=[],this.cancel=()=>{},this._enabled=!0,this._state=h.NONE,this._viewport=null,this._changedDolly=0,this._changedZoom=0,this._hasRested=!0,this._boundaryEnclosesCamera=!1,this._needsUpdate=!0,this._updatedLastTime=!1,this._elementRect=new DOMRect,this._isDragging=!1,this._dragNeedsUpdate=!0,this._activePointers=[],this._lockedPointer=null,this._interactiveArea=new DOMRect(0,0,1,1),this._isUserControllingRotate=!1,this._isUserControllingDolly=!1,this._isUserControllingTruck=!1,this._isUserControllingOffset=!1,this._isUserControllingZoom=!1,this._lastDollyDirection=Z.NONE,this._thetaVelocity={value:0},this._phiVelocity={value:0},this._radiusVelocity={value:0},this._targetVelocity=new v.Vector3,this._focalOffsetVelocity=new v.Vector3,this._zoomVelocity={value:0},this._truckInternal=(o,m,O)=>{let C,x;if(N(this._camera)){const T=S.copy(this._camera.position).sub(this._target),D=this._camera.getEffectiveFOV()*Q,R=T.length()*Math.tan(D*.5);C=this.truckSpeed*o*R/this._elementRect.height,x=this.truckSpeed*m*R/this._elementRect.height}else if(B(this._camera)){const T=this._camera;C=o*(T.right-T.left)/T.zoom/this._elementRect.width,x=m*(T.top-T.bottom)/T.zoom/this._elementRect.height}else return;this.verticalDragToForward?(O?this.setFocalOffset(this._focalOffsetEnd.x+C,this._focalOffsetEnd.y,this._focalOffsetEnd.z,!0):this.truck(C,0,!0),this.forward(-x,!0)):O?this.setFocalOffset(this._focalOffsetEnd.x+C,this._focalOffsetEnd.y+x,this._focalOffsetEnd.z,!0):this.truck(C,x,!0)},this._rotateInternal=(o,m)=>{const O=q*this.azimuthRotateSpeed*o/this._elementRect.height,C=q*this.polarRotateSpeed*m/this._elementRect.height;this.rotate(O,C,!0)},this._dollyInternal=(o,m,O)=>{const C=Math.pow(.95,-o*this.dollySpeed),x=this._sphericalEnd.radius,T=this._sphericalEnd.radius*C,D=F(T,this.minDistance,this.maxDistance),R=D-T;this.infinityDolly&&this.dollyToCursor?this._dollyToNoClamp(T,!0):this.infinityDolly&&!this.dollyToCursor?(this.dollyInFixed(R,!0),this._dollyToNoClamp(D,!0)):this._dollyToNoClamp(D,!0),this.dollyToCursor&&(this._changedDolly+=(this.infinityDolly?T:D)-x,this._dollyControlCoord.set(m,O)),this._lastDollyDirection=Math.sign(-o)},this._zoomInternal=(o,m,O)=>{const C=Math.pow(.95,o*this.dollySpeed),x=this._zoom,T=this._zoom*C;this.zoomTo(T,!0),this.dollyToCursor&&(this._changedZoom+=T-x,this._dollyControlCoord.set(m,O))},typeof v=="undefined"&&console.error("camera-controls: `THREE` is undefined. You must first run `CameraControls.install( { THREE: THREE } )`. Check the docs for further information."),this._camera=t,this._yAxisUpSpace=new v.Quaternion().setFromUnitVectors(this._camera.up,ht),this._yAxisUpSpaceInverse=this._yAxisUpSpace.clone().invert(),this._state=h.NONE,this._target=new v.Vector3,this._targetEnd=this._target.clone(),this._focalOffset=new v.Vector3,this._focalOffsetEnd=this._focalOffset.clone(),this._spherical=new v.Spherical().setFromVector3(S.copy(this._camera.position).applyQuaternion(this._yAxisUpSpace)),this._sphericalEnd=this._spherical.clone(),this._lastDistance=this._spherical.radius,this._zoom=this._camera.zoom,this._zoomEnd=this._zoom,this._lastZoom=this._zoom,this._nearPlaneCorners=[new v.Vector3,new v.Vector3,new v.Vector3,new v.Vector3],this._updateNearPlaneCorners(),this._boundary=new v.Box3(new v.Vector3(-1/0,-1/0,-1/0),new v.Vector3(1/0,1/0,1/0)),this._cameraUp0=this._camera.up.clone(),this._target0=this._target.clone(),this._position0=this._camera.position.clone(),this._zoom0=this._zoom,this._focalOffset0=this._focalOffset.clone(),this._dollyControlCoord=new v.Vector2,this.mouseButtons={left:h.ROTATE,middle:h.DOLLY,right:h.TRUCK,wheel:N(this._camera)?h.DOLLY:B(this._camera)?h.ZOOM:h.NONE},this.touches={one:h.TOUCH_ROTATE,two:N(this._camera)?h.TOUCH_DOLLY_TRUCK:B(this._camera)?h.TOUCH_ZOOM_TRUCK:h.NONE,three:h.TOUCH_TRUCK};const s=new v.Vector2,r=new v.Vector2,i=new v.Vector2,n=o=>{if(!this._enabled||!this._domElement)return;if(this._interactiveArea.left!==0||this._interactiveArea.top!==0||this._interactiveArea.width!==1||this._interactiveArea.height!==1){const C=this._domElement.getBoundingClientRect(),x=(o.clientX-C.left)/(C.right-C.left),T=(o.clientY-C.top)/(C.bottom-C.top);if(x<this._interactiveArea.left||x>this._interactiveArea.right||T<this._interactiveArea.top||T>this._interactiveArea.bottom)return}const m=o.pointerType!=="mouse"?null:(o.buttons&U.LEFT)===U.LEFT?U.LEFT:(o.buttons&U.MIDDLE)===U.MIDDLE?U.MIDDLE:(o.buttons&U.RIGHT)===U.RIGHT?U.RIGHT:null;if(m!==null){const C=this._findPointerByMouseButton(m);C&&this._disposePointer(C)}if((o.buttons&U.LEFT)===U.LEFT&&this._lockedPointer)return;const O={pointerId:o.pointerId,clientX:o.clientX,clientY:o.clientY,deltaX:0,deltaY:0,mouseButton:m};this._activePointers.push(O),this._domElement.ownerDocument.removeEventListener("pointermove",a,{passive:!1}),this._domElement.ownerDocument.removeEventListener("pointerup",l),this._domElement.ownerDocument.addEventListener("pointermove",a,{passive:!1}),this._domElement.ownerDocument.addEventListener("pointerup",l),this._isDragging=!0,E(o)},a=o=>{o.cancelable&&o.preventDefault();const m=o.pointerId,O=this._lockedPointer||this._findPointerById(m);if(O){if(O.clientX=o.clientX,O.clientY=o.clientY,O.deltaX=o.movementX,O.deltaY=o.movementY,this._state=0,o.pointerType==="touch")switch(this._activePointers.length){case 1:this._state=this.touches.one;break;case 2:this._state=this.touches.two;break;case 3:this._state=this.touches.three;break}else(!this._isDragging&&this._lockedPointer||this._isDragging&&(o.buttons&U.LEFT)===U.LEFT)&&(this._state=this._state|this.mouseButtons.left),this._isDragging&&(o.buttons&U.MIDDLE)===U.MIDDLE&&(this._state=this._state|this.mouseButtons.middle),this._isDragging&&(o.buttons&U.RIGHT)===U.RIGHT&&(this._state=this._state|this.mouseButtons.right);y()}},l=o=>{const m=this._findPointerById(o.pointerId);if(!(m&&m===this._lockedPointer)){if(m&&this._disposePointer(m),o.pointerType==="touch")switch(this._activePointers.length){case 0:this._state=h.NONE;break;case 1:this._state=this.touches.one;break;case 2:this._state=this.touches.two;break;case 3:this._state=this.touches.three;break}else this._state=h.NONE;u()}};let d=-1;const g=o=>{if(!this._domElement||!this._enabled||this.mouseButtons.wheel===h.NONE)return;if(this._interactiveArea.left!==0||this._interactiveArea.top!==0||this._interactiveArea.width!==1||this._interactiveArea.height!==1){const T=this._domElement.getBoundingClientRect(),D=(o.clientX-T.left)/(T.right-T.left),R=(o.clientY-T.top)/(T.bottom-T.top);if(D<this._interactiveArea.left||D>this._interactiveArea.right||R<this._interactiveArea.top||R>this._interactiveArea.bottom)return}if(o.preventDefault(),this.dollyToCursor||this.mouseButtons.wheel===h.ROTATE||this.mouseButtons.wheel===h.TRUCK){const T=performance.now();d-T<1e3&&this._getClientRect(this._elementRect),d=T}const m=fe?-1:-3,O=o.deltaMode===1?o.deltaY/m:o.deltaY/(m*10),C=this.dollyToCursor?(o.clientX-this._elementRect.x)/this._elementRect.width*2-1:0,x=this.dollyToCursor?(o.clientY-this._elementRect.y)/this._elementRect.height*-2+1:0;switch(this.mouseButtons.wheel){case h.ROTATE:{this._rotateInternal(o.deltaX,o.deltaY),this._isUserControllingRotate=!0;break}case h.TRUCK:{this._truckInternal(o.deltaX,o.deltaY,!1),this._isUserControllingTruck=!0;break}case h.OFFSET:{this._truckInternal(o.deltaX,o.deltaY,!0),this._isUserControllingOffset=!0;break}case h.DOLLY:{this._dollyInternal(-O,C,x),this._isUserControllingDolly=!0;break}case h.ZOOM:{this._zoomInternal(-O,C,x),this._isUserControllingZoom=!0;break}}this.dispatchEvent({type:"control"})},c=o=>{if(!(!this._domElement||!this._enabled)){if(this.mouseButtons.right===j.ACTION.NONE){const m=o instanceof PointerEvent?o.pointerId:0,O=this._findPointerById(m);O&&this._disposePointer(O),this._domElement.ownerDocument.removeEventListener("pointermove",a,{passive:!1}),this._domElement.ownerDocument.removeEventListener("pointerup",l);return}o.preventDefault()}},E=o=>{if(!this._enabled)return;if(pt(this._activePointers,L),this._getClientRect(this._elementRect),s.copy(L),r.copy(L),this._activePointers.length>=2){const O=L.x-this._activePointers[1].clientX,C=L.y-this._activePointers[1].clientY,x=Math.sqrt(O*O+C*C);i.set(0,x);const T=(this._activePointers[0].clientX+this._activePointers[1].clientX)*.5,D=(this._activePointers[0].clientY+this._activePointers[1].clientY)*.5;r.set(T,D)}if(this._state=0,!o)this._lockedPointer&&(this._state=this._state|this.mouseButtons.left);else if("pointerType"in o&&o.pointerType==="touch")switch(this._activePointers.length){case 1:this._state=this.touches.one;break;case 2:this._state=this.touches.two;break;case 3:this._state=this.touches.three;break}else!this._lockedPointer&&(o.buttons&U.LEFT)===U.LEFT&&(this._state=this._state|this.mouseButtons.left),(o.buttons&U.MIDDLE)===U.MIDDLE&&(this._state=this._state|this.mouseButtons.middle),(o.buttons&U.RIGHT)===U.RIGHT&&(this._state=this._state|this.mouseButtons.right);((this._state&h.ROTATE)===h.ROTATE||(this._state&h.TOUCH_ROTATE)===h.TOUCH_ROTATE||(this._state&h.TOUCH_DOLLY_ROTATE)===h.TOUCH_DOLLY_ROTATE||(this._state&h.TOUCH_ZOOM_ROTATE)===h.TOUCH_ZOOM_ROTATE)&&(this._sphericalEnd.theta=this._spherical.theta,this._sphericalEnd.phi=this._spherical.phi,this._thetaVelocity.value=0,this._phiVelocity.value=0),((this._state&h.TRUCK)===h.TRUCK||(this._state&h.TOUCH_TRUCK)===h.TOUCH_TRUCK||(this._state&h.TOUCH_DOLLY_TRUCK)===h.TOUCH_DOLLY_TRUCK||(this._state&h.TOUCH_ZOOM_TRUCK)===h.TOUCH_ZOOM_TRUCK)&&(this._targetEnd.copy(this._target),this._targetVelocity.set(0,0,0)),((this._state&h.DOLLY)===h.DOLLY||(this._state&h.TOUCH_DOLLY)===h.TOUCH_DOLLY||(this._state&h.TOUCH_DOLLY_TRUCK)===h.TOUCH_DOLLY_TRUCK||(this._state&h.TOUCH_DOLLY_OFFSET)===h.TOUCH_DOLLY_OFFSET||(this._state&h.TOUCH_DOLLY_ROTATE)===h.TOUCH_DOLLY_ROTATE)&&(this._sphericalEnd.radius=this._spherical.radius,this._radiusVelocity.value=0),((this._state&h.ZOOM)===h.ZOOM||(this._state&h.TOUCH_ZOOM)===h.TOUCH_ZOOM||(this._state&h.TOUCH_ZOOM_TRUCK)===h.TOUCH_ZOOM_TRUCK||(this._state&h.TOUCH_ZOOM_OFFSET)===h.TOUCH_ZOOM_OFFSET||(this._state&h.TOUCH_ZOOM_ROTATE)===h.TOUCH_ZOOM_ROTATE)&&(this._zoomEnd=this._zoom,this._zoomVelocity.value=0),((this._state&h.OFFSET)===h.OFFSET||(this._state&h.TOUCH_OFFSET)===h.TOUCH_OFFSET||(this._state&h.TOUCH_DOLLY_OFFSET)===h.TOUCH_DOLLY_OFFSET||(this._state&h.TOUCH_ZOOM_OFFSET)===h.TOUCH_ZOOM_OFFSET)&&(this._focalOffsetEnd.copy(this._focalOffset),this._focalOffsetVelocity.set(0,0,0)),this.dispatchEvent({type:"controlstart"})},y=()=>{if(!this._enabled||!this._dragNeedsUpdate)return;this._dragNeedsUpdate=!1,pt(this._activePointers,L);const m=this._domElement&&this._domElement.ownerDocument.pointerLockElement===this._domElement?this._lockedPointer||this._activePointers[0]:null,O=m?-m.deltaX:r.x-L.x,C=m?-m.deltaY:r.y-L.y;if(r.copy(L),((this._state&h.ROTATE)===h.ROTATE||(this._state&h.TOUCH_ROTATE)===h.TOUCH_ROTATE||(this._state&h.TOUCH_DOLLY_ROTATE)===h.TOUCH_DOLLY_ROTATE||(this._state&h.TOUCH_ZOOM_ROTATE)===h.TOUCH_ZOOM_ROTATE)&&(this._rotateInternal(O,C),this._isUserControllingRotate=!0),(this._state&h.DOLLY)===h.DOLLY||(this._state&h.ZOOM)===h.ZOOM){const x=this.dollyToCursor?(s.x-this._elementRect.x)/this._elementRect.width*2-1:0,T=this.dollyToCursor?(s.y-this._elementRect.y)/this._elementRect.height*-2+1:0,D=this.dollyDragInverted?-1:1;(this._state&h.DOLLY)===h.DOLLY?(this._dollyInternal(D*C*at,x,T),this._isUserControllingDolly=!0):(this._zoomInternal(D*C*at,x,T),this._isUserControllingZoom=!0)}if((this._state&h.TOUCH_DOLLY)===h.TOUCH_DOLLY||(this._state&h.TOUCH_ZOOM)===h.TOUCH_ZOOM||(this._state&h.TOUCH_DOLLY_TRUCK)===h.TOUCH_DOLLY_TRUCK||(this._state&h.TOUCH_ZOOM_TRUCK)===h.TOUCH_ZOOM_TRUCK||(this._state&h.TOUCH_DOLLY_OFFSET)===h.TOUCH_DOLLY_OFFSET||(this._state&h.TOUCH_ZOOM_OFFSET)===h.TOUCH_ZOOM_OFFSET||(this._state&h.TOUCH_DOLLY_ROTATE)===h.TOUCH_DOLLY_ROTATE||(this._state&h.TOUCH_ZOOM_ROTATE)===h.TOUCH_ZOOM_ROTATE){const x=L.x-this._activePointers[1].clientX,T=L.y-this._activePointers[1].clientY,D=Math.sqrt(x*x+T*T),R=i.y-D;i.set(0,D);const it=this.dollyToCursor?(r.x-this._elementRect.x)/this._elementRect.width*2-1:0,rt=this.dollyToCursor?(r.y-this._elementRect.y)/this._elementRect.height*-2+1:0;(this._state&h.TOUCH_DOLLY)===h.TOUCH_DOLLY||(this._state&h.TOUCH_DOLLY_ROTATE)===h.TOUCH_DOLLY_ROTATE||(this._state&h.TOUCH_DOLLY_TRUCK)===h.TOUCH_DOLLY_TRUCK||(this._state&h.TOUCH_DOLLY_OFFSET)===h.TOUCH_DOLLY_OFFSET?(this._dollyInternal(R*at,it,rt),this._isUserControllingDolly=!0):(this._zoomInternal(R*at,it,rt),this._isUserControllingZoom=!0)}((this._state&h.TRUCK)===h.TRUCK||(this._state&h.TOUCH_TRUCK)===h.TOUCH_TRUCK||(this._state&h.TOUCH_DOLLY_TRUCK)===h.TOUCH_DOLLY_TRUCK||(this._state&h.TOUCH_ZOOM_TRUCK)===h.TOUCH_ZOOM_TRUCK)&&(this._truckInternal(O,C,!1),this._isUserControllingTruck=!0),((this._state&h.OFFSET)===h.OFFSET||(this._state&h.TOUCH_OFFSET)===h.TOUCH_OFFSET||(this._state&h.TOUCH_DOLLY_OFFSET)===h.TOUCH_DOLLY_OFFSET||(this._state&h.TOUCH_ZOOM_OFFSET)===h.TOUCH_ZOOM_OFFSET)&&(this._truckInternal(O,C,!0),this._isUserControllingOffset=!0),this.dispatchEvent({type:"control"})},u=()=>{pt(this._activePointers,L),r.copy(L),this._dragNeedsUpdate=!1,(this._activePointers.length===0||this._activePointers.length===1&&this._activePointers[0]===this._lockedPointer)&&(this._isDragging=!1),this._activePointers.length===0&&this._domElement&&(this._domElement.ownerDocument.removeEventListener("pointermove",a,{passive:!1}),this._domElement.ownerDocument.removeEventListener("pointerup",l),this.dispatchEvent({type:"controlend"}))};this.lockPointer=()=>{!this._enabled||!this._domElement||(this.cancel(),this._lockedPointer={pointerId:-1,clientX:0,clientY:0,deltaX:0,deltaY:0,mouseButton:null},this._activePointers.push(this._lockedPointer),this._domElement.ownerDocument.removeEventListener("pointermove",a,{passive:!1}),this._domElement.ownerDocument.removeEventListener("pointerup",l),this._domElement.requestPointerLock(),this._domElement.ownerDocument.addEventListener("pointerlockchange",p),this._domElement.ownerDocument.addEventListener("pointerlockerror",_),this._domElement.ownerDocument.addEventListener("pointermove",a,{passive:!1}),this._domElement.ownerDocument.addEventListener("pointerup",l),E())},this.unlockPointer=()=>{var o,m,O;this._lockedPointer!==null&&(this._disposePointer(this._lockedPointer),this._lockedPointer=null),(o=this._domElement)===null||o===void 0||o.ownerDocument.exitPointerLock(),(m=this._domElement)===null||m===void 0||m.ownerDocument.removeEventListener("pointerlockchange",p),(O=this._domElement)===null||O===void 0||O.ownerDocument.removeEventListener("pointerlockerror",_),this.cancel()};const p=()=>{this._domElement&&this._domElement.ownerDocument.pointerLockElement===this._domElement||this.unlockPointer()},_=()=>{this.unlockPointer()};this._addAllEventListeners=o=>{this._domElement=o,this._domElement.style.touchAction="none",this._domElement.style.userSelect="none",this._domElement.style.webkitUserSelect="none",this._domElement.addEventListener("pointerdown",n),this._domElement.addEventListener("pointercancel",l),this._domElement.addEventListener("wheel",g,{passive:!1}),this._domElement.addEventListener("contextmenu",c)},this._removeAllEventListeners=()=>{this._domElement&&(this._domElement.style.touchAction="",this._domElement.style.userSelect="",this._domElement.style.webkitUserSelect="",this._domElement.removeEventListener("pointerdown",n),this._domElement.removeEventListener("pointercancel",l),this._domElement.removeEventListener("wheel",g,{passive:!1}),this._domElement.removeEventListener("contextmenu",c),this._domElement.ownerDocument.removeEventListener("pointermove",a,{passive:!1}),this._domElement.ownerDocument.removeEventListener("pointerup",l),this._domElement.ownerDocument.removeEventListener("pointerlockchange",p),this._domElement.ownerDocument.removeEventListener("pointerlockerror",_))},this.cancel=()=>{this._state!==h.NONE&&(this._state=h.NONE,this._activePointers.length=0,u())},e&&this.connect(e),this.update(0)}get camera(){return this._camera}set camera(t){this._camera=t,this.updateCameraUp(),this._camera.updateProjectionMatrix(),this._updateNearPlaneCorners(),this._needsUpdate=!0}get enabled(){return this._enabled}set enabled(t){this._enabled=t,this._domElement&&(t?(this._domElement.style.touchAction="none",this._domElement.style.userSelect="none",this._domElement.style.webkitUserSelect="none"):(this.cancel(),this._domElement.style.touchAction="",this._domElement.style.userSelect="",this._domElement.style.webkitUserSelect=""))}get active(){return!this._hasRested}get currentAction(){return this._state}get distance(){return this._spherical.radius}set distance(t){this._spherical.radius===t&&this._sphericalEnd.radius===t||(this._spherical.radius=t,this._sphericalEnd.radius=t,this._needsUpdate=!0)}get azimuthAngle(){return this._spherical.theta}set azimuthAngle(t){this._spherical.theta===t&&this._sphericalEnd.theta===t||(this._spherical.theta=t,this._sphericalEnd.theta=t,this._needsUpdate=!0)}get polarAngle(){return this._spherical.phi}set polarAngle(t){this._spherical.phi===t&&this._sphericalEnd.phi===t||(this._spherical.phi=t,this._sphericalEnd.phi=t,this._needsUpdate=!0)}get boundaryEnclosesCamera(){return this._boundaryEnclosesCamera}set boundaryEnclosesCamera(t){this._boundaryEnclosesCamera=t,this._needsUpdate=!0}set interactiveArea(t){this._interactiveArea.width=F(t.width,0,1),this._interactiveArea.height=F(t.height,0,1),this._interactiveArea.x=F(t.x,0,1-this._interactiveArea.width),this._interactiveArea.y=F(t.y,0,1-this._interactiveArea.height)}addEventListener(t,e){super.addEventListener(t,e)}removeEventListener(t,e){super.removeEventListener(t,e)}rotate(t,e,s=!1){return this.rotateTo(this._sphericalEnd.theta+t,this._sphericalEnd.phi+e,s)}rotateAzimuthTo(t,e=!1){return this.rotateTo(t,this._sphericalEnd.phi,e)}rotatePolarTo(t,e=!1){return this.rotateTo(this._sphericalEnd.theta,t,e)}rotateTo(t,e,s=!1){this._isUserControllingRotate=!1;const r=F(t,this.minAzimuthAngle,this.maxAzimuthAngle),i=F(e,this.minPolarAngle,this.maxPolarAngle);this._sphericalEnd.theta=r,this._sphericalEnd.phi=i,this._sphericalEnd.makeSafe(),this._needsUpdate=!0,s||(this._spherical.theta=this._sphericalEnd.theta,this._spherical.phi=this._sphericalEnd.phi);const n=!s||A(this._spherical.theta,this._sphericalEnd.theta,this.restThreshold)&&A(this._spherical.phi,this._sphericalEnd.phi,this.restThreshold);return this._createOnRestPromise(n)}dolly(t,e=!1){return this.dollyTo(this._sphericalEnd.radius-t,e)}dollyTo(t,e=!1){return this._isUserControllingDolly=!1,this._lastDollyDirection=Z.NONE,this._changedDolly=0,this._dollyToNoClamp(F(t,this.minDistance,this.maxDistance),e)}_dollyToNoClamp(t,e=!1){const s=this._sphericalEnd.radius;if(this.colliderMeshes.length>=1){const n=this._collisionTest(),a=A(n,this._spherical.radius);if(!(s>t)&&a)return Promise.resolve();this._sphericalEnd.radius=Math.min(t,n)}else this._sphericalEnd.radius=t;this._needsUpdate=!0,e||(this._spherical.radius=this._sphericalEnd.radius);const i=!e||A(this._spherical.radius,this._sphericalEnd.radius,this.restThreshold);return this._createOnRestPromise(i)}dollyInFixed(t,e=!1){this._targetEnd.add(this._getCameraDirection(tt).multiplyScalar(t)),e||this._target.copy(this._targetEnd);const s=!e||A(this._target.x,this._targetEnd.x,this.restThreshold)&&A(this._target.y,this._targetEnd.y,this.restThreshold)&&A(this._target.z,this._targetEnd.z,this.restThreshold);return this._createOnRestPromise(s)}zoom(t,e=!1){return this.zoomTo(this._zoomEnd+t,e)}zoomTo(t,e=!1){this._isUserControllingZoom=!1,this._zoomEnd=F(t,this.minZoom,this.maxZoom),this._needsUpdate=!0,e||(this._zoom=this._zoomEnd);const s=!e||A(this._zoom,this._zoomEnd,this.restThreshold);return this._changedZoom=0,this._createOnRestPromise(s)}pan(t,e,s=!1){return console.warn("`pan` has been renamed to `truck`"),this.truck(t,e,s)}truck(t,e,s=!1){this._camera.updateMatrix(),H.setFromMatrixColumn(this._camera.matrix,0),I.setFromMatrixColumn(this._camera.matrix,1),H.multiplyScalar(t),I.multiplyScalar(-e);const r=S.copy(H).add(I),i=P.copy(this._targetEnd).add(r);return this.moveTo(i.x,i.y,i.z,s)}forward(t,e=!1){S.setFromMatrixColumn(this._camera.matrix,0),S.crossVectors(this._camera.up,S),S.multiplyScalar(t);const s=P.copy(this._targetEnd).add(S);return this.moveTo(s.x,s.y,s.z,e)}elevate(t,e=!1){return S.copy(this._camera.up).multiplyScalar(t),this.moveTo(this._targetEnd.x+S.x,this._targetEnd.y+S.y,this._targetEnd.z+S.z,e)}moveTo(t,e,s,r=!1){this._isUserControllingTruck=!1;const i=S.set(t,e,s).sub(this._targetEnd);this._encloseToBoundary(this._targetEnd,i,this.boundaryFriction),this._needsUpdate=!0,r||this._target.copy(this._targetEnd);const n=!r||A(this._target.x,this._targetEnd.x,this.restThreshold)&&A(this._target.y,this._targetEnd.y,this.restThreshold)&&A(this._target.z,this._targetEnd.z,this.restThreshold);return this._createOnRestPromise(n)}lookInDirectionOf(t,e,s,r=!1){const a=S.set(t,e,s).sub(this._targetEnd).normalize().multiplyScalar(-this._sphericalEnd.radius).add(this._targetEnd);return this.setPosition(a.x,a.y,a.z,r)}fitToBox(t,e,{cover:s=!1,paddingLeft:r=0,paddingRight:i=0,paddingBottom:n=0,paddingTop:a=0}={}){const l=[],d=t.isBox3?G.copy(t):G.setFromObject(t);d.isEmpty()&&(console.warn("camera-controls: fitTo() cannot be used with an empty box. Aborting"),Promise.resolve());const g=St(this._sphericalEnd.theta,wt),c=St(this._sphericalEnd.phi,wt);l.push(this.rotateTo(g,c,e));const E=S.setFromSpherical(this._sphericalEnd).normalize(),y=Rt.setFromUnitVectors(E,ut),u=A(Math.abs(E.y),1);u&&y.multiply(gt.setFromAxisAngle(ht,g)),y.multiply(this._yAxisUpSpaceInverse);const p=Ut.makeEmpty();P.copy(d.min).applyQuaternion(y),p.expandByPoint(P),P.copy(d.min).setX(d.max.x).applyQuaternion(y),p.expandByPoint(P),P.copy(d.min).setY(d.max.y).applyQuaternion(y),p.expandByPoint(P),P.copy(d.max).setZ(d.min.z).applyQuaternion(y),p.expandByPoint(P),P.copy(d.min).setZ(d.max.z).applyQuaternion(y),p.expandByPoint(P),P.copy(d.max).setY(d.min.y).applyQuaternion(y),p.expandByPoint(P),P.copy(d.max).setX(d.min.x).applyQuaternion(y),p.expandByPoint(P),P.copy(d.max).applyQuaternion(y),p.expandByPoint(P),p.min.x-=r,p.min.y-=n,p.max.x+=i,p.max.y+=a,y.setFromUnitVectors(ut,E),u&&y.premultiply(gt.invert()),y.premultiply(this._yAxisUpSpace);const _=p.getSize(S),o=p.getCenter(P).applyQuaternion(y);if(N(this._camera)){const m=this.getDistanceToFitBox(_.x,_.y,_.z,s);l.push(this.moveTo(o.x,o.y,o.z,e)),l.push(this.dollyTo(m,e)),l.push(this.setFocalOffset(0,0,0,e))}else if(B(this._camera)){const m=this._camera,O=m.right-m.left,C=m.top-m.bottom,x=s?Math.max(O/_.x,C/_.y):Math.min(O/_.x,C/_.y);l.push(this.moveTo(o.x,o.y,o.z,e)),l.push(this.zoomTo(x,e)),l.push(this.setFocalOffset(0,0,0,e))}return Promise.all(l)}fitToSphere(t,e){const s=[],i="isObject3D"in t?j.createBoundingSphere(t,ft):ft.copy(t);if(s.push(this.moveTo(i.center.x,i.center.y,i.center.z,e)),N(this._camera)){const n=this.getDistanceToFitSphere(i.radius);s.push(this.dollyTo(n,e))}else if(B(this._camera)){const n=this._camera.right-this._camera.left,a=this._camera.top-this._camera.bottom,l=2*i.radius,d=Math.min(n/l,a/l);s.push(this.zoomTo(d,e))}return s.push(this.setFocalOffset(0,0,0,e)),Promise.all(s)}setLookAt(t,e,s,r,i,n,a=!1){this._isUserControllingRotate=!1,this._isUserControllingDolly=!1,this._isUserControllingTruck=!1,this._lastDollyDirection=Z.NONE,this._changedDolly=0;const l=P.set(r,i,n),d=S.set(t,e,s);this._targetEnd.copy(l),this._sphericalEnd.setFromVector3(d.sub(l).applyQuaternion(this._yAxisUpSpace)),this.normalizeRotations(),this._needsUpdate=!0,a||(this._target.copy(this._targetEnd),this._spherical.copy(this._sphericalEnd));const g=!a||A(this._target.x,this._targetEnd.x,this.restThreshold)&&A(this._target.y,this._targetEnd.y,this.restThreshold)&&A(this._target.z,this._targetEnd.z,this.restThreshold)&&A(this._spherical.theta,this._sphericalEnd.theta,this.restThreshold)&&A(this._spherical.phi,this._sphericalEnd.phi,this.restThreshold)&&A(this._spherical.radius,this._sphericalEnd.radius,this.restThreshold);return this._createOnRestPromise(g)}lerpLookAt(t,e,s,r,i,n,a,l,d,g,c,E,y,u=!1){this._isUserControllingRotate=!1,this._isUserControllingDolly=!1,this._isUserControllingTruck=!1,this._lastDollyDirection=Z.NONE,this._changedDolly=0;const p=S.set(r,i,n),_=P.set(t,e,s);M.setFromVector3(_.sub(p).applyQuaternion(this._yAxisUpSpace));const o=W.set(g,c,E),m=P.set(a,l,d);et.setFromVector3(m.sub(o).applyQuaternion(this._yAxisUpSpace)),this._targetEnd.copy(p.lerp(o,y));const O=et.theta-M.theta,C=et.phi-M.phi,x=et.radius-M.radius;this._sphericalEnd.set(M.radius+x*y,M.phi+C*y,M.theta+O*y),this.normalizeRotations(),this._needsUpdate=!0,u||(this._target.copy(this._targetEnd),this._spherical.copy(this._sphericalEnd));const T=!u||A(this._target.x,this._targetEnd.x,this.restThreshold)&&A(this._target.y,this._targetEnd.y,this.restThreshold)&&A(this._target.z,this._targetEnd.z,this.restThreshold)&&A(this._spherical.theta,this._sphericalEnd.theta,this.restThreshold)&&A(this._spherical.phi,this._sphericalEnd.phi,this.restThreshold)&&A(this._spherical.radius,this._sphericalEnd.radius,this.restThreshold);return this._createOnRestPromise(T)}setPosition(t,e,s,r=!1){return this.setLookAt(t,e,s,this._targetEnd.x,this._targetEnd.y,this._targetEnd.z,r)}setTarget(t,e,s,r=!1){const i=this.getPosition(S),n=this.setLookAt(i.x,i.y,i.z,t,e,s,r);return this._sphericalEnd.phi=F(this._sphericalEnd.phi,this.minPolarAngle,this.maxPolarAngle),n}setFocalOffset(t,e,s,r=!1){this._isUserControllingOffset=!1,this._focalOffsetEnd.set(t,e,s),this._needsUpdate=!0,r||this._focalOffset.copy(this._focalOffsetEnd);const i=!r||A(this._focalOffset.x,this._focalOffsetEnd.x,this.restThreshold)&&A(this._focalOffset.y,this._focalOffsetEnd.y,this.restThreshold)&&A(this._focalOffset.z,this._focalOffsetEnd.z,this.restThreshold);return this._createOnRestPromise(i)}setOrbitPoint(t,e,s){this._camera.updateMatrixWorld(),H.setFromMatrixColumn(this._camera.matrixWorldInverse,0),I.setFromMatrixColumn(this._camera.matrixWorldInverse,1),Y.setFromMatrixColumn(this._camera.matrixWorldInverse,2);const r=S.set(t,e,s),i=r.distanceTo(this._camera.position),n=r.sub(this._camera.position);H.multiplyScalar(n.x),I.multiplyScalar(n.y),Y.multiplyScalar(n.z),S.copy(H).add(I).add(Y),S.z=S.z+i,this.dollyTo(i,!1),this.setFocalOffset(-S.x,S.y,-S.z,!1),this.moveTo(t,e,s,!1)}setBoundary(t){if(!t){this._boundary.min.set(-1/0,-1/0,-1/0),this._boundary.max.set(1/0,1/0,1/0),this._needsUpdate=!0;return}this._boundary.copy(t),this._boundary.clampPoint(this._targetEnd,this._targetEnd),this._needsUpdate=!0}setViewport(t,e,s,r){if(t===null){this._viewport=null;return}this._viewport=this._viewport||new v.Vector4,typeof t=="number"?this._viewport.set(t,e,s,r):this._viewport.copy(t)}getDistanceToFitBox(t,e,s,r=!1){if(_t(this._camera,"getDistanceToFitBox"))return this._spherical.radius;const i=t/e,n=this._camera.getEffectiveFOV()*Q,a=this._camera.aspect;return((r?i>a:i<a)?e:t/a)*.5/Math.tan(n*.5)+s*.5}getDistanceToFitSphere(t){if(_t(this._camera,"getDistanceToFitSphere"))return this._spherical.radius;const e=this._camera.getEffectiveFOV()*Q,s=Math.atan(Math.tan(e*.5)*this._camera.aspect)*2,r=1<this._camera.aspect?e:s;return t/Math.sin(r*.5)}getTarget(t,e=!0){return(t&&t.isVector3?t:new v.Vector3).copy(e?this._targetEnd:this._target)}getPosition(t,e=!0){return(t&&t.isVector3?t:new v.Vector3).setFromSpherical(e?this._sphericalEnd:this._spherical).applyQuaternion(this._yAxisUpSpaceInverse).add(e?this._targetEnd:this._target)}getSpherical(t,e=!0){return(t||new v.Spherical).copy(e?this._sphericalEnd:this._spherical)}getFocalOffset(t,e=!0){return(t&&t.isVector3?t:new v.Vector3).copy(e?this._focalOffsetEnd:this._focalOffset)}normalizeRotations(){this._sphericalEnd.theta=this._sphericalEnd.theta%q,this._sphericalEnd.theta<0&&(this._sphericalEnd.theta+=q),this._spherical.theta+=q*Math.round((this._sphericalEnd.theta-this._spherical.theta)/q)}reset(t=!1){if(!A(this._camera.up.x,this._cameraUp0.x)||!A(this._camera.up.y,this._cameraUp0.y)||!A(this._camera.up.z,this._cameraUp0.z)){this._camera.up.copy(this._cameraUp0);const s=this.getPosition(S);this.updateCameraUp(),this.setPosition(s.x,s.y,s.z)}const e=[this.setLookAt(this._position0.x,this._position0.y,this._position0.z,this._target0.x,this._target0.y,this._target0.z,t),this.setFocalOffset(this._focalOffset0.x,this._focalOffset0.y,this._focalOffset0.z,t),this.zoomTo(this._zoom0,t)];return Promise.all(e)}saveState(){this._cameraUp0.copy(this._camera.up),this.getTarget(this._target0),this.getPosition(this._position0),this._zoom0=this._zoom,this._focalOffset0.copy(this._focalOffset)}updateCameraUp(){this._yAxisUpSpace.setFromUnitVectors(this._camera.up,ht),this._yAxisUpSpaceInverse.copy(this._yAxisUpSpace).invert()}applyCameraUp(){const t=S.subVectors(this._target,this._camera.position).normalize(),e=P.crossVectors(t,this._camera.up);this._camera.up.crossVectors(e,t).normalize(),this._camera.updateMatrixWorld();const s=this.getPosition(S);this.updateCameraUp(),this.setPosition(s.x,s.y,s.z)}update(t){const e=this._sphericalEnd.theta-this._spherical.theta,s=this._sphericalEnd.phi-this._spherical.phi,r=this._sphericalEnd.radius-this._spherical.radius,i=Dt.subVectors(this._targetEnd,this._target),n=bt.subVectors(this._focalOffsetEnd,this._focalOffset),a=this._zoomEnd-this._zoom;if(b(e))this._thetaVelocity.value=0,this._spherical.theta=this._sphericalEnd.theta;else{const c=this._isUserControllingRotate?this.draggingSmoothTime:this.smoothTime;this._spherical.theta=nt(this._spherical.theta,this._sphericalEnd.theta,this._thetaVelocity,c,1/0,t),this._needsUpdate=!0}if(b(s))this._phiVelocity.value=0,this._spherical.phi=this._sphericalEnd.phi;else{const c=this._isUserControllingRotate?this.draggingSmoothTime:this.smoothTime;this._spherical.phi=nt(this._spherical.phi,this._sphericalEnd.phi,this._phiVelocity,c,1/0,t),this._needsUpdate=!0}if(b(r))this._radiusVelocity.value=0,this._spherical.radius=this._sphericalEnd.radius;else{const c=this._isUserControllingDolly?this.draggingSmoothTime:this.smoothTime;this._spherical.radius=nt(this._spherical.radius,this._sphericalEnd.radius,this._radiusVelocity,c,this.maxSpeed,t),this._needsUpdate=!0}if(b(i.x)&&b(i.y)&&b(i.z))this._targetVelocity.set(0,0,0),this._target.copy(this._targetEnd);else{const c=this._isUserControllingTruck?this.draggingSmoothTime:this.smoothTime;Pt(this._target,this._targetEnd,this._targetVelocity,c,this.maxSpeed,t,this._target),this._needsUpdate=!0}if(b(n.x)&&b(n.y)&&b(n.z))this._focalOffsetVelocity.set(0,0,0),this._focalOffset.copy(this._focalOffsetEnd);else{const c=this._isUserControllingOffset?this.draggingSmoothTime:this.smoothTime;Pt(this._focalOffset,this._focalOffsetEnd,this._focalOffsetVelocity,c,this.maxSpeed,t,this._focalOffset),this._needsUpdate=!0}if(b(a))this._zoomVelocity.value=0,this._zoom=this._zoomEnd;else{const c=this._isUserControllingZoom?this.draggingSmoothTime:this.smoothTime;this._zoom=nt(this._zoom,this._zoomEnd,this._zoomVelocity,c,1/0,t)}if(this.dollyToCursor){if(N(this._camera)&&this._changedDolly!==0){const c=this._spherical.radius-this._lastDistance,E=this._camera,y=this._getCameraDirection(tt),u=S.copy(y).cross(E.up).normalize();u.lengthSq()===0&&(u.x=1);const p=P.crossVectors(u,y),_=this._sphericalEnd.radius*Math.tan(E.getEffectiveFOV()*Q*.5),m=(this._sphericalEnd.radius-c-this._sphericalEnd.radius)/this._sphericalEnd.radius,O=W.copy(this._targetEnd).add(u.multiplyScalar(this._dollyControlCoord.x*_*E.aspect)).add(p.multiplyScalar(this._dollyControlCoord.y*_)),C=S.copy(this._targetEnd).lerp(O,m),x=this._lastDollyDirection===Z.IN&&this._spherical.radius<=this.minDistance,T=this._lastDollyDirection===Z.OUT&&this.maxDistance<=this._spherical.radius;if(this.infinityDolly&&(x||T)){this._sphericalEnd.radius-=c,this._spherical.radius-=c;const R=P.copy(y).multiplyScalar(-c);C.add(R)}this._boundary.clampPoint(C,C);const D=P.subVectors(C,this._targetEnd);this._targetEnd.copy(C),this._target.add(D),this._changedDolly-=c,b(this._changedDolly)&&(this._changedDolly=0)}else if(B(this._camera)&&this._changedZoom!==0){const c=this._zoom-this._lastZoom,E=this._camera,y=S.set(this._dollyControlCoord.x,this._dollyControlCoord.y,(E.near+E.far)/(E.near-E.far)).unproject(E),u=P.set(0,0,-1).applyQuaternion(E.quaternion),p=W.copy(y).add(u.multiplyScalar(-y.dot(E.up))),o=-(this._zoom-c-this._zoom)/this._zoom,m=this._getCameraDirection(tt),O=this._targetEnd.dot(m),C=S.copy(this._targetEnd).lerp(p,o),x=C.dot(m),T=m.multiplyScalar(x-O);C.sub(T),this._boundary.clampPoint(C,C);const D=P.subVectors(C,this._targetEnd);this._targetEnd.copy(C),this._target.add(D),this._changedZoom-=c,b(this._changedZoom)&&(this._changedZoom=0)}}this._camera.zoom!==this._zoom&&(this._camera.zoom=this._zoom,this._camera.updateProjectionMatrix(),this._updateNearPlaneCorners(),this._needsUpdate=!0),this._dragNeedsUpdate=!0;const l=this._collisionTest();this._spherical.radius=Math.min(this._spherical.radius,l),this._spherical.makeSafe(),this._camera.position.setFromSpherical(this._spherical).applyQuaternion(this._yAxisUpSpaceInverse).add(this._target),this._camera.lookAt(this._target),(!b(this._focalOffset.x)||!b(this._focalOffset.y)||!b(this._focalOffset.z))&&(this._camera.updateMatrixWorld(),H.setFromMatrixColumn(this._camera.matrix,0),I.setFromMatrixColumn(this._camera.matrix,1),Y.setFromMatrixColumn(this._camera.matrix,2),H.multiplyScalar(this._focalOffset.x),I.multiplyScalar(-this._focalOffset.y),Y.multiplyScalar(this._focalOffset.z),S.copy(H).add(I).add(Y),this._camera.position.add(S)),this._boundaryEnclosesCamera&&this._encloseToBoundary(this._camera.position.copy(this._target),S.setFromSpherical(this._spherical).applyQuaternion(this._yAxisUpSpaceInverse),1);const g=this._needsUpdate;return g&&!this._updatedLastTime?(this._hasRested=!1,this.dispatchEvent({type:"wake"}),this.dispatchEvent({type:"update"})):g?(this.dispatchEvent({type:"update"}),b(e,this.restThreshold)&&b(s,this.restThreshold)&&b(r,this.restThreshold)&&b(i.x,this.restThreshold)&&b(i.y,this.restThreshold)&&b(i.z,this.restThreshold)&&b(n.x,this.restThreshold)&&b(n.y,this.restThreshold)&&b(n.z,this.restThreshold)&&b(a,this.restThreshold)&&!this._hasRested&&(this._hasRested=!0,this.dispatchEvent({type:"rest"}))):!g&&this._updatedLastTime&&(this._hasRested||(this._hasRested=!0,this.dispatchEvent({type:"rest"})),this.dispatchEvent({type:"sleep"})),this._lastDistance=this._spherical.radius,this._lastZoom=this._zoom,this._updatedLastTime=g,this._needsUpdate=!1,g}toJSON(){return JSON.stringify({enabled:this._enabled,minDistance:this.minDistance,maxDistance:$(this.maxDistance),minZoom:this.minZoom,maxZoom:$(this.maxZoom),minPolarAngle:this.minPolarAngle,maxPolarAngle:$(this.maxPolarAngle),minAzimuthAngle:$(this.minAzimuthAngle),maxAzimuthAngle:$(this.maxAzimuthAngle),smoothTime:this.smoothTime,draggingSmoothTime:this.draggingSmoothTime,dollySpeed:this.dollySpeed,truckSpeed:this.truckSpeed,dollyToCursor:this.dollyToCursor,verticalDragToForward:this.verticalDragToForward,target:this._targetEnd.toArray(),position:S.setFromSpherical(this._sphericalEnd).add(this._targetEnd).toArray(),zoom:this._zoomEnd,focalOffset:this._focalOffsetEnd.toArray(),target0:this._target0.toArray(),position0:this._position0.toArray(),zoom0:this._zoom0,focalOffset0:this._focalOffset0.toArray()})}fromJSON(t,e=!1){const s=JSON.parse(t);this.enabled=s.enabled,this.minDistance=s.minDistance,this.maxDistance=J(s.maxDistance),this.minZoom=s.minZoom,this.maxZoom=J(s.maxZoom),this.minPolarAngle=s.minPolarAngle,this.maxPolarAngle=J(s.maxPolarAngle),this.minAzimuthAngle=J(s.minAzimuthAngle),this.maxAzimuthAngle=J(s.maxAzimuthAngle),this.smoothTime=s.smoothTime,this.draggingSmoothTime=s.draggingSmoothTime,this.dollySpeed=s.dollySpeed,this.truckSpeed=s.truckSpeed,this.dollyToCursor=s.dollyToCursor,this.verticalDragToForward=s.verticalDragToForward,this._target0.fromArray(s.target0),this._position0.fromArray(s.position0),this._zoom0=s.zoom0,this._focalOffset0.fromArray(s.focalOffset0),this.moveTo(s.target[0],s.target[1],s.target[2],e),M.setFromVector3(S.fromArray(s.position).sub(this._targetEnd).applyQuaternion(this._yAxisUpSpace)),this.rotateTo(M.theta,M.phi,e),this.dollyTo(M.radius,e),this.zoomTo(s.zoom,e),this.setFocalOffset(s.focalOffset[0],s.focalOffset[1],s.focalOffset[2],e),this._needsUpdate=!0}connect(t){if(this._domElement){console.warn("camera-controls is already connected.");return}this._addAllEventListeners(t),this._getClientRect(this._elementRect)}disconnect(){this.cancel(),this._removeAllEventListeners(),this._domElement&&(this._domElement=void 0)}dispose(){this.removeAllEventListeners(),this.disconnect()}_getTargetDirection(t){return t.setFromSpherical(this._spherical).divideScalar(this._spherical.radius).applyQuaternion(this._yAxisUpSpaceInverse)}_getCameraDirection(t){return this._getTargetDirection(t).negate()}_findPointerById(t){return this._activePointers.find(e=>e.pointerId===t)}_findPointerByMouseButton(t){return this._activePointers.find(e=>e.mouseButton===t)}_disposePointer(t){this._activePointers.splice(this._activePointers.indexOf(t),1)}_encloseToBoundary(t,e,s){const r=e.lengthSq();if(r===0)return t;const i=P.copy(e).add(t),a=this._boundary.clampPoint(i,W).sub(i),l=a.lengthSq();if(l===0)return t.add(e);if(l===r)return t;if(s===0)return t.add(e).add(a);{const d=1+s*l/e.dot(a);return t.add(P.copy(e).multiplyScalar(d)).add(a.multiplyScalar(1-s))}}_updateNearPlaneCorners(){if(N(this._camera)){const t=this._camera,e=t.near,s=t.getEffectiveFOV()*Q,r=Math.tan(s*.5)*e,i=r*t.aspect;this._nearPlaneCorners[0].set(-i,-r,0),this._nearPlaneCorners[1].set(i,-r,0),this._nearPlaneCorners[2].set(i,r,0),this._nearPlaneCorners[3].set(-i,r,0)}else if(B(this._camera)){const t=this._camera,e=1/t.zoom,s=t.left*e,r=t.right*e,i=t.top*e,n=t.bottom*e;this._nearPlaneCorners[0].set(s,i,0),this._nearPlaneCorners[1].set(r,i,0),this._nearPlaneCorners[2].set(r,n,0),this._nearPlaneCorners[3].set(s,n,0)}}_collisionTest(){let t=1/0;if(!(this.colliderMeshes.length>=1)||_t(this._camera,"_collisionTest"))return t;const s=this._getTargetDirection(tt);Ct.lookAt(At,s,this._camera.up);for(let r=0;r<4;r++){const i=P.copy(this._nearPlaneCorners[r]);i.applyMatrix4(Ct);const n=W.addVectors(this._target,i);lt.set(n,s),lt.far=this._spherical.radius+1;const a=lt.intersectObjects(this.colliderMeshes);a.length!==0&&a[0].distance<t&&(t=a[0].distance)}return t}_getClientRect(t){if(!this._domElement)return;const e=this._domElement.getBoundingClientRect();return t.x=e.left,t.y=e.top,this._viewport?(t.x+=this._viewport.x,t.y+=e.height-this._viewport.w-this._viewport.y,t.width=this._viewport.z,t.height=this._viewport.w):(t.width=e.width,t.height=e.height),t}_createOnRestPromise(t){return t?Promise.resolve():(this._hasRested=!1,this.dispatchEvent({type:"transitionstart"}),new Promise(e=>{const s=()=>{this.removeEventListener("rest",s),e()};this.addEventListener("rest",s)}))}_addAllEventListeners(t){}_removeAllEventListeners(){}get dampingFactor(){return console.warn(".dampingFactor has been deprecated. use smoothTime (in seconds) instead."),0}set dampingFactor(t){console.warn(".dampingFactor has been deprecated. use smoothTime (in seconds) instead.")}get draggingDampingFactor(){return console.warn(".draggingDampingFactor has been deprecated. use draggingSmoothTime (in seconds) instead."),0}set draggingDampingFactor(t){console.warn(".draggingDampingFactor has been deprecated. use draggingSmoothTime (in seconds) instead.")}static createBoundingSphere(t,e=new v.Sphere){const s=e,r=s.center;G.makeEmpty(),t.traverseVisible(n=>{n.isMesh&&G.expandByObject(n)}),G.getCenter(r);let i=0;return t.traverseVisible(n=>{if(!n.isMesh)return;const a=n,l=a.geometry.clone();l.applyMatrix4(a.matrixWorld);const g=l.attributes.position;for(let c=0,E=g.count;c<E;c++)S.fromBufferAttribute(g,c),i=Math.max(i,r.distanceToSquared(S))}),s.radius=Math.sqrt(i),s}}const ge={antialias:!1,devicePixelRatio:window.devicePixelRatio,powerPreference:"high-performance",toneMappingExposure:1,alpha:!1,outputColorSpace:se.ColorSpace.sRGB,logarithmicDepthBuffer:!1,preserveDrawingBuffer:!1,stencil:!1,depth:!1,physicallyCorrectLights:!1};class Ce{constructor(t){this.options=t;const{width:e,height:s,rendererParams:r}=t,{canvas:i,context:n,alpha:a,devicePixelRatio:l,antialias:d,powerPreference:g,toneMappingExposure:c,outputColorSpace:E,logarithmicDepthBuffer:y,preserveDrawingBuffer:u,stencil:p,depth:_,physicallyCorrectLights:o}=r,m=new w.WebGLRenderer({canvas:i,context:n,alpha:a,antialias:d,powerPreference:g,logarithmicDepthBuffer:y,preserveDrawingBuffer:u,stencil:p,depth:_});m.setSize(e,s),m.setPixelRatio(l),m.toneMappingExposure=c,m.outputColorSpace=E,+w.REVISION<155&&(m.useLegacyLights=o),this.renderer=m}setSize(t,e){this.renderer.setSize(t,e)}setPixelRatio(t){this.renderer.setPixelRatio(t)}render(){const{sceneController:t,cameraController:e}=this.options;this.renderer.render(t.scene,e.camera)}setViewport(t){var g,c;const{cameraController:e}=this.options,{x:s,y:r,width:i,height:n}=t,a=(g=t.scissor)!=null?g:!1,l=(c=t.scissorTest)!=null?c:!1,d=i/n;e.camera.aspect!==d&&(e.camera.aspect=d,e.camera.updateProjectionMatrix()),this.renderer.setViewport(s,r,i,n),a&&(this.renderer.setScissor(s,r,i,n),this.renderer.setScissorTest(l))}setViewPadding(t=0,e=0,s=0,r=0){const{width:i,height:n}=this.renderer.getSize(new w.Vector2),a={x:r,y:s,width:i-r-e,height:n-t-s};this.setViewport(a)}dispose(){var t,e;this.setSize(1,1),(t=this.renderer)==null||t.clear(),(e=this.renderer)==null||e.dispose()}}const ye={antialias:!0,devicePixelRatio:window.devicePixelRatio};class Ee{constructor(t){this.options=t;const{width:e,height:s,rendererParams:r,renderer:i}=t,{devicePixelRatio:n,antialias:a}=r,l=new i({antialias:a});l.setSize(e,s),l.setPixelRatio(n),this.renderer=l}setSize(t,e){this.renderer.setSize(t,e)}render(){const{sceneController:t,cameraController:e}=this.options;this.renderer.render(t.scene,e.camera)}dispose(){var t,e;this.setSize(1,1),(t=this.renderer)==null||t.clear(),(e=this.renderer)==null||e.dispose()}}const Oe={fov:45,near:1,far:1e3,up:new w.Vector3(0,1,0)};class Te{constructor(t){this.event=new st.eventsExports.EventEmitter,this.cameraArr=[],this.cameraActiveIndex=0,this.customCamera=!1,this.options=t;const{cameraParams:e,width:s,height:r}=t;if(e instanceof w.Camera)this.cameraArr.push(e),this.customCamera=!0;else{const i=this.addPerspectiveCamera(ot(V({},e),{aspect:s/r}));i.position.set(0,0,400),i.lookAt(0,0,0)}}get camera(){return this.cameraArr[this.cameraActiveIndex]}addPerspectiveCamera(t){const{fov:e,far:s,near:r,up:i,aspect:n}=t,a=new w.PerspectiveCamera(e,n,r,s);return a.up=i,this.cameraArr.push(a),a}setCameraActive(t){this.cameraActiveIndex=t,this.event.emit("cameraChange",this.camera)}setSize(t,e){this.options.width=t,this.options.height=e,this.cameraArr.forEach(s=>{s instanceof w.PerspectiveCamera&&(s.aspect=t/e),s.updateProjectionMatrix()})}cloneCamera(){const t=this.addPerspectiveCamera({fov:this.camera.fov,aspect:this.camera.aspect,near:this.camera.near,far:this.camera.far,up:this.camera.up});return t.position.copy(this.camera.position),t}sync(t){if(t.type==="PerspectiveCamera"){const e=t;(!this.camera.matrixWorld.equals(e.matrixWorld)||this.camera.far!==e.far||this.camera.near!==e.near||this.camera.fov!==e.fov||this.camera.aspect!==e.aspect)&&this.camera.copy(e)}else{const e=t,s=e.viewMatrix,r=e.inverseViewMatrix,i=new w.Matrix4(r[0],r[4],r[8],r[12],r[1],r[5],r[9],r[13],r[2],r[6],r[10],r[14],r[3],r[7],r[11],r[15]),n=new w.Matrix4(s[0],s[4],s[8],s[12],s[1],s[5],s[9],s[13],s[2],s[6],s[10],s[14],s[3],s[7],s[11],s[15]),{width:a,height:l}=this.options,d=a/l;(this.camera.fov!==e.fov||this.camera.aspect!==d||!this.camera.matrixWorld.equals(i)||!this.camera.matrixWorldInverse.equals(n))&&(this.camera.fov=e.fov,this.camera.updateProjectionMatrix(),this.camera.matrixAutoUpdate=!1,this.camera.matrixWorld.copy(i),this.camera.matrixWorldInverse.copy(n),this.camera.aspect=d,this.camera.updateProjectionMatrix())}}}const ve={background:null,addCamera:!0};class xe{constructor(t){this.event=new st.eventsExports.EventEmitter,this.sceneArr=[],this.sceneActiveIndex=0,this.overrideMaterial=!1,this.options=t;const{cameraController:e,sceneParams:s}=t,{addCamera:r}=s;this.addScene(),r&&this.scene.add(e.camera)}get scene(){return this.sceneArr[this.sceneActiveIndex]}addScene(){const{sceneParams:t}=this.options,{background:e}=t,s=new w.Scene;return e&&(s.background=e),this.sceneArr.push(s),s}setSceneActive(t){this.sceneActiveIndex=t,this.event.emit("sceneChange",this.scene)}dispose(){this.sceneArr.forEach(t=>{t.traverse(e=>{ie.disposeMesh(e)})})}}class we{constructor(t){this.helpers={},this.options=t}add(t){const e=t.uuid,{sceneController:s}=this.options;let r=this.helpers[e];if(r===void 0){if(t.isScene)r=new w.AxesHelper(100);else if(t.isCamera)r=new w.CameraHelper(t);else if(t.isPointLight)r=new w.PointLightHelper(t,1);else if(t.isDirectionalLight)r=new w.DirectionalLightHelper(t,1);else if(t.isSpotLight)r=new w.SpotLightHelper(t);else if(t.isHemisphereLight)r=new w.HemisphereLightHelper(t,10);else if(t.isRectAreaLight)r=new re.RectAreaLightHelper(t);else{const i=new w.Box3;if(i.setFromObject(t,!0),i.isEmpty()===!1){r=new w.Box3Helper(i);const n=r.material;n.userData.object=t,n.depthTest=!1,n.transparent=!0}else return}s.scene.add(r),this.helpers[e]=r}}addViewHelper(){const{cameraController:t,container:e}=this.options,s=new oe.ViewHelper(t.camera,e);e.addEventListener("pointerdown",r=>{r.preventDefault(),s.handleClick(r)}),this.viewHelper=s}remove(t){var r;const e=t.uuid,{sceneController:s}=this.options;if(this.helpers[e]!==void 0){const i=this.helpers[e];s.scene.remove(i),delete this.helpers[e],(r=i.dispose)==null||r.call(i)}}removeAll(){Object.keys(this.helpers).forEach(t=>{this.remove({uuid:t})}),this.helpers={}}removeAllExcludeScene(){Object.keys(this.helpers).forEach(t=>{this.helpers[t]instanceof w.AxesHelper||this.remove({uuid:t})})}update(t,e,s){var i,n;const{cameraController:r}=this.options;Object.values(this.helpers).forEach(a=>{if(a.update&&a.update(),a instanceof w.Box3Helper){const l=a.material,{object:d}=l.userData;d&&a.box.setFromObject(d,!0)}}),((i=this.viewHelper)==null?void 0:i.animating)===!0&&(this.viewHelper.update(t),(n=e.cameraControls)==null||n.setPosition(...r.camera.position.toArray()),this.viewHelper.center.copy(s))}renderViewHelper(t){if(!this.viewHelper)return;const e=t.autoClear;t.autoClear=!1,this.viewHelper.render(t),t.autoClear=e}dispose(){var t;this.helpers={},(t=this.viewHelper)==null||t.dispose()}}class Se{constructor(t){this.event=new st.eventsExports.EventEmitter,this.cameraControlsArr=[],this.cameraControlsActiveIndex=0,this.autoRotateSpeed=0,this.options=t;const{camera:e,controlsParams:s,customControls:r}=t,{domElement:i}=s;if(r){const n=new r(e,i);n.enableDamping=!0,n.dampingFactor=.063,n.autoRotate=!1,n.autoRotateSpeed=-60,n.enableZoom=!0,n.zoomSpeed=.2,this.customControls=n}else j.install({THREE:w}),this.addCameraControls(e)}get cameraControls(){return this.cameraControlsArr[this.cameraControlsActiveIndex]}addCameraControls(t,e){const{controlsParams:s}=this.options,{domElement:r}=s,i=new j(t,r);return e&&(i.interactiveArea=e,i.addEventListener("update",()=>{this.cameraControlsArr.forEach(n=>{n!==i&&(n.enabled=!1)})}),i.addEventListener("sleep",()=>{this.cameraControlsArr.forEach(n=>{n!==i&&(n.enabled=!0)})})),this.cameraControlsArr.push(i),i}setCameraControlsActive(t){this.cameraControlsActiveIndex=t}enable(){this.customControls?this.customControls.enabled=!0:this.cameraControls&&this.cameraControlsArr.forEach(t=>{t.enabled=!0})}disable(){this.customControls?this.customControls.enabled=!1:this.cameraControls&&this.cameraControlsArr.forEach(t=>{t.enabled=!1})}update(t){var e;(e=this.customControls)==null||e.update(),this.cameraControlsArr.forEach(s=>{s.update(t)}),this.autoRotateSpeed&&this.cameraControls&&(this.cameraControls.azimuthAngle+=this.autoRotateSpeed*t*w.MathUtils.DEG2RAD)}dispose(){var t;(t=this.customControls)==null||t.dispose(),this.cameraControlsArr.forEach(e=>{e.dispose()})}}class Pe{constructor(t){this.event=new st.eventsExports.EventEmitter;const{renderer:e,scene:s,camera:r}=t,i=new ne.TransformControls(r,e.domElement);if(i.getHelper){const n=i.getHelper();if(s.add(n),+w.REVISION<170){const a=i._root;a.dispose=()=>{a.traverse(l=>{l.geometry&&l.geometry.dispose(),l.material&&l.material.dispose()})},i.dispose=()=>{i.disconnect(),a.dispose()}}}else i instanceof w.Object3D&&s.add(i);this.controls=i,this.addEvent()}get detach(){return this.controls.detach.bind(this.controls)}get attach(){return this.controls.attach.bind(this.controls)}addEvent(){let t=null,e=null,s=null;const r=this.controls;r.addEventListener("change",()=>{const i=r.object;i!==void 0&&this.event.emit("change",i)}),r.addEventListener("mouseDown",()=>{const i=r.object;t=i.position.clone(),e=i.rotation.clone(),s=i.scale.clone(),this.event.emit("mouseDown",i)}),r.addEventListener("mouseUp",()=>{const i=r.object;if(i!==void 0)switch(r.getMode()){case"translate":t.equals(i.position)||this.event.emit("translate",i,i.position,t);break;case"rotate":e.equals(i.rotation)||this.event.emit("rotate",i,i.rotation,e);break;case"scale":s.equals(i.scale)||this.event.emit("scale",i,i.scale,s);break}this.event.emit("mouseUp")})}dispose(){var t;this.event.removeAllListeners(),(t=this.controls)==null||t.dispose()}}const Lt=new z.Vector3,Ae=new z.Quaternion,zt=new z.Vector3,k=new z.Matrix4,De=new z.Matrix4;class be{constructor(t={}){const e=this;let s,r,i,n;const a={camera:{style:""},objects:new WeakMap},l=t.element!==void 0?t.element:document.createElement("div");l.style.overflow="hidden",this.domElement=l;const d=document.createElement("div");d.style.transformOrigin="0 0",d.style.pointerEvents="none",l.appendChild(d);const g=document.createElement("div");g.style.transformStyle="preserve-3d",d.appendChild(g),this.getSize=function(){return{width:s,height:r}},this.render=function(_,o){const m=o.projectionMatrix.elements[5]*n;o.view&&o.view.enabled?(d.style.transform=`translate( ${-o.view.offsetX*(s/o.view.width)}px, ${-o.view.offsetY*(r/o.view.height)}px )`,d.style.transform+=`scale( ${o.view.fullWidth/o.view.width}, ${o.view.fullHeight/o.view.height} )`):d.style.transform="",_.matrixWorldAutoUpdate===!0&&_.updateMatrixWorld(),o.parent===null&&o.matrixWorldAutoUpdate===!0&&o.updateMatrixWorld();let O,C;o.isOrthographicCamera&&(O=-(o.right+o.left)/2,C=(o.top+o.bottom)/2);const x=o.view&&o.view.enabled?o.view.height/o.view.fullHeight:1,T=o.isOrthographicCamera?`scale( ${x} )scale(`+m+")translate("+c(O)+"px,"+c(C)+"px)"+E(o.matrixWorldInverse):`scale( ${x} )translateZ(`+m+"px)"+E(o.matrixWorldInverse),R=(o.isPerspectiveCamera?"perspective("+m+"px) ":"")+T+"translate("+i+"px,"+n+"px)";a.camera.style!==R&&(g.style.transform=R,a.camera.style=R),p(_,_,o)},this.setSize=function(_,o){s=_,r=o,i=s/2,n=r/2,l.style.width=_+"px",l.style.height=o+"px",d.style.width=_+"px",d.style.height=o+"px",g.style.width=_+"px",g.style.height=o+"px"};function c(_){return Math.abs(_)<1e-10?0:_}function E(_){const o=_.elements;return"matrix3d("+c(o[0])+","+c(-o[1])+","+c(o[2])+","+c(o[3])+","+c(o[4])+","+c(-o[5])+","+c(o[6])+","+c(o[7])+","+c(o[8])+","+c(-o[9])+","+c(o[10])+","+c(o[11])+","+c(o[12])+","+c(-o[13])+","+c(o[14])+","+c(o[15])+")"}function y(_){const o=_.elements;return"translate(-50%,-50%)"+("matrix3d("+c(o[0])+","+c(o[1])+","+c(o[2])+","+c(o[3])+","+c(-o[4])+","+c(-o[5])+","+c(-o[6])+","+c(-o[7])+","+c(o[8])+","+c(o[9])+","+c(o[10])+","+c(o[11])+","+c(o[12])+","+c(o[13])+","+c(o[14])+","+c(o[15])+")")}function u(_){_.isCSS3DObject&&(_.element.style.display="none");for(let o=0,m=_.children.length;o<m;o++)u(_.children[o])}function p(_,o,m,O){if(_.visible===!1){u(_);return}if(_.isCSS3DObject){const C=_.layers.test(m.layers)===!0,x=_.element;if(x.style.display=C===!0?"":"none",C===!0){_.onBeforeRender(e,o,m);let T;_.isCSS3DSprite?(k.copy(m.matrixWorldInverse),k.transpose(),_.rotation2D!==0&&k.multiply(De.makeRotationZ(_.rotation2D)),_.matrixWorld.decompose(Lt,Ae,zt),k.setPosition(Lt),k.scale(zt),k.elements[3]=0,k.elements[7]=0,k.elements[11]=0,k.elements[15]=1,T=y(k)):T=y(_.matrixWorld);const D=a.objects.get(_);if(D===void 0||D.style!==T){x.style.transform=T;const R={style:T};a.objects.set(_,R)}x.parentNode!==g&&g.appendChild(x),_.onAfterRender(e,o,m)}}for(let C=0,x=_.children.length;C<x;C++)p(_.children[C],o,m)}}}const X=new z.Vector3,Mt=new z.Matrix4,Ft=new z.Matrix4,Ht=new z.Vector3,It=new z.Vector3;class Ue{constructor(t={}){const e=this;let s,r,i,n;const a={objects:new WeakMap},l=t.element!==void 0?t.element:document.createElement("div");l.style.overflow="hidden",this.domElement=l,this.getSize=function(){return{width:s,height:r}},this.render=function(u,p){u.matrixWorldAutoUpdate===!0&&u.updateMatrixWorld(),p.parent===null&&p.matrixWorldAutoUpdate===!0&&p.updateMatrixWorld(),Mt.copy(p.matrixWorldInverse),Ft.multiplyMatrices(p.projectionMatrix,Mt),g(u,u,p),y(u)},this.setSize=function(u,p){s=u,r=p,i=s/2,n=r/2,l.style.width=u+"px",l.style.height=p+"px"};function d(u){u.isCSS2DObject&&(u.element.style.display="none");for(let p=0,_=u.children.length;p<_;p++)d(u.children[p])}function g(u,p,_){if(u.visible===!1){d(u);return}if(u.isCSS2DObject){X.setFromMatrixPosition(u.matrixWorld),X.applyMatrix4(Ft);const o=X.z>=-1&&X.z<=1&&u.layers.test(_.layers)===!0,m=u.element;m.style.display=o===!0?"":"none",o===!0&&(u.onBeforeRender(e,p,_),m.style.transform="translate("+-100*u.center.x+"%,"+-100*u.center.y+"%)translate("+(X.x*i+i)+"px,"+(-X.y*n+n)+"px)",m.parentNode!==l&&l.appendChild(m),u.onAfterRender(e,p,_));const O={distanceToCameraSquared:c(_,u)};a.objects.set(u,O)}for(let o=0,m=u.children.length;o<m;o++)g(u.children[o],p,_)}function c(u,p){return Ht.setFromMatrixPosition(u.matrixWorld),It.setFromMatrixPosition(p.matrixWorld),Ht.distanceToSquared(It)}function E(u){const p=[];return u.traverseVisible(function(_){_.isCSS2DObject&&p.push(_)}),p}function y(u){const p=E(u).sort(function(o,m){if(o.renderOrder!==m.renderOrder)return m.renderOrder-o.renderOrder;const O=a.objects.get(o).distanceToCameraSquared,C=a.objects.get(m).distanceToCameraSquared;return O-C}),_=p.length;for(let o=0,m=p.length;o<m;o++)p[o].element.style.zIndex=_-o}}}const kt={zIndex:"auto"};class Re{constructor(t){this.container=t}addRenderer(t,e){const s=e.container||this.container,r=s.offsetWidth,i=s.offsetHeight,n=t==="css2d"?new Ue:new be;n.domElement.style.position="absolute",n.domElement.style.top="0",n.domElement.style.pointerEvents="none",n.domElement.style.zIndex=e.zIndex,n.setSize(r,i),s.appendChild(n.domElement),t==="css2d"?this.css2Drenderer=n:t==="css3d"&&(this.css3Drenderer=n)}setSize(t,e){var s,r;(s=this.css2Drenderer)==null||s.setSize(t,e),(r=this.css3Drenderer)==null||r.setSize(t,e)}render(t,e){var s,r;(s=this.css2Drenderer)==null||s.render(t,e),(r=this.css3Drenderer)==null||r.render(t,e)}dispose(){var t,e;(t=this.css2Drenderer)==null||t.domElement.remove(),(e=this.css3Drenderer)==null||e.domElement.remove(),this.css2Drenderer=void 0,this.css3Drenderer=void 0}}class Et{constructor(t){this.guiParams={},t&&(this.guiParams=t)}showGui(t){t&&Object.keys(this.guiParams).forEach(e=>{const s=t.addFolder(e),r=this.guiParams[e];Object.keys(r).forEach(i=>{const{min:n,max:a,step:l,name:d,paramMap:g,items:c,value:E,target:y}=r[i],u=i.toLowerCase().indexOf("color")>-1;let p;const _=typeof E=="undefined"&&y,o=_?y():r[i],m=_?i:"value";c?p=s.add(o,m,c):u?p=s.addColor(o,m):p=s.add(o,m),p=p.name(d||i),typeof n!="undefined"&&(p=p.min(n)),typeof a!="undefined"&&(p=p.max(a)),typeof l!="undefined"&&(p=p.step(l)),p=p.onChange(()=>{this.setTargetValue(e,i,o[m],g)}),_&&p.listen()})})}setTargetValue(t,e,s,r){const{onChange:i,target:n,value:a}=this.guiParams[t][e],l=e.toLowerCase().indexOf("color")>-1;if(n&&!(typeof a=="undefined"&&n)){let g=n();Array.isArray(g)||(g=[g]),g.forEach(c=>{if(c)if(l)try{c[r||e].set(s)}catch(E){e!=="color"&&!r&&console.warn(`${e} is not a color,set paramMap`)}else c[r||e]=s})}i&&i(s)}setTargetValueByParams(){Object.keys(this.guiParams).forEach(t=>{Object.keys(this.guiParams[t]).forEach(e=>{const s=this.guiParams[t][e];typeof s.value!="undefined"&&this.setTargetValue(t,e,s.value,s.paramMap)})})}}const Le={name:"OutputShader",uniforms:{tDiffuse:{value:null},toneMappingExposure:{value:1},premultiplieAlpha:{value:0}},vertexShader:`
2
2
  precision highp float;
3
3
 
4
4
  uniform mat4 modelViewMatrix;
@@ -2030,15 +2030,15 @@ class Pe {
2030
2030
  }
2031
2031
  addCameraControls(t, e) {
2032
2032
  const { controlsParams: s } = this.options, { domElement: r } = s, i = new q(t, r);
2033
- return e && (i.interactiveArea = e), i.addEventListener("update", () => {
2034
- this.cameraControlsArr.length > 1 && this.cameraControlsArr.forEach((n) => {
2033
+ return e && (i.interactiveArea = e, i.addEventListener("update", () => {
2034
+ this.cameraControlsArr.forEach((n) => {
2035
2035
  n !== i && (n.enabled = !1);
2036
2036
  });
2037
2037
  }), i.addEventListener("sleep", () => {
2038
- this.cameraControlsArr.length > 1 && this.cameraControlsArr.forEach((n) => {
2038
+ this.cameraControlsArr.forEach((n) => {
2039
2039
  n !== i && (n.enabled = !0);
2040
2040
  });
2041
- }), this.cameraControlsArr.push(i), i;
2041
+ })), this.cameraControlsArr.push(i), i;
2042
2042
  }
2043
2043
  setCameraControlsActive(t) {
2044
2044
  this.cameraControlsActiveIndex = t;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gl-draw",
3
- "version": "0.12.13",
3
+ "version": "0.12.14",
4
4
  "author": "gitplus <hstits@gmail.com>",
5
5
  "scripts": {
6
6
  "start": "bundler-dev",