gl-draw 0.9.47 → 0.9.48

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.
@@ -102,6 +102,7 @@ export default class Pencil {
102
102
  scene: {
103
103
  background: null;
104
104
  om: boolean;
105
+ addCamera: boolean;
105
106
  };
106
107
  camera: {
107
108
  fov: number;
@@ -2,10 +2,12 @@ import * as THREE from 'three';
2
2
  export interface SceneParams {
3
3
  background: THREE.Scene['background'];
4
4
  om: boolean;
5
+ addCamera?: boolean;
5
6
  }
6
7
  export declare const defaultSceneParams: {
7
8
  background: null;
8
9
  om: boolean;
10
+ addCamera: boolean;
9
11
  };
10
12
  interface Options {
11
13
  camera: THREE.Camera;
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- "use strict";var Nt=Object.defineProperty,qt=Object.defineProperties;var Xt=Object.getOwnPropertyDescriptors;var it=Object.getOwnPropertySymbols;var Ct=Object.prototype.hasOwnProperty,Ot=Object.prototype.propertyIsEnumerable;var yt=(d,t,e)=>t in d?Nt(d,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):d[t]=e,I=(d,t)=>{for(var e in t||(t={}))Ct.call(t,e)&&yt(d,e,t[e]);if(it)for(var e of it(t))Ot.call(t,e)&&yt(d,e,t[e]);return d},ot=(d,t)=>qt(d,Xt(t));var Tt=(d,t)=>{var e={};for(var s in d)Ct.call(d,s)&&t.indexOf(s)<0&&(e[s]=d[s]);if(d!=null&&it)for(var s of it(d))t.indexOf(s)<0&&Ot.call(d,s)&&(e[s]=d[s]);return e};Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const tt=require("three"),Kt=require("@tweenjs/tween.js"),Ft=require("./events.js"),jt=require("deepmerge"),Gt=require("three/examples/jsm/libs/stats.module"),Qt=require("lil-gui"),Wt=require("./colorCorrection.js"),Jt=require("./disposeMesh.js");require("idb-keyval");require("esus-lite");require("d3-geo");const vt=require("./MeshLineMaterial.js"),$t=require("three/examples/jsm/helpers/RectAreaLightHelper"),te=require("three/examples/jsm/controls/TransformControls"),ee=require("three/examples/jsm/renderers/CSS3DRenderer"),se=require("three/examples/jsm/renderers/CSS2DRenderer"),b=require("postprocessing"),ie=require("./isPlainObject.js"),oe=require("./BaseObject.js");function It(d){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(d){for(const e in d)if(e!=="default"){const s=Object.getOwnPropertyDescriptor(d,e);Object.defineProperty(t,e,s.get?s:{enumerable:!0,get:()=>d[e]})}}return t.default=d,Object.freeze(t)}const x=It(tt),Pt=It(Kt),A={LEFT:1,RIGHT:2,MIDDLE:4},n=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}),N={NONE:0,IN:1,OUT:-1};function V(d){return d.isPerspectiveCamera}function B(d){return d.isOrthographicCamera}const q=Math.PI*2,xt=Math.PI/2,Ht=1e-5,j=Math.PI/180;function F(d,t,e){return Math.max(t,Math.min(e,d))}function U(d,t=Ht){return Math.abs(d)<t}function w(d,t,e=Ht){return U(d-t,e)}function Dt(d,t){return Math.round(d/t)*t}function G(d){return isFinite(d)?d:d<0?-Number.MAX_VALUE:Number.MAX_VALUE}function Q(d){return Math.abs(d)<Number.MAX_VALUE?d:d*(1/0)}function rt(d,t,e,s,i=1/0,o){s=Math.max(1e-4,s);const r=2/s,a=r*o,h=1/(1+a+.48*a*a+.235*a*a*a);let c=d-t;const p=t,m=i*s;c=F(c,-m,m),t=d-c;const E=(e.value+r*c)*o;e.value=(e.value-r*E)*h;let u=t+(c+E)*h;return p-d>0==u>p&&(u=p,e.value=(u-p)/o),u}function wt(d,t,e,s,i=1/0,o,r){s=Math.max(1e-4,s);const a=2/s,h=a*o,c=1/(1+h+.48*h*h+.235*h*h*h);let p=t.x,m=t.y,E=t.z,u=d.x-p,D=d.y-m,g=d.z-E;const S=p,l=m,_=E,y=i*s,f=y*y,v=u*u+D*D+g*g;if(v>f){const mt=Math.sqrt(v);u=u/mt*y,D=D/mt*y,g=g/mt*y}p=d.x-u,m=d.y-D,E=d.z-g;const O=(e.x+a*u)*o,L=(e.y+a*D)*o,R=(e.z+a*g)*o;e.x=(e.x-a*O)*c,e.y=(e.y-a*L)*c,e.z=(e.z-a*R)*c,r.x=p+(u+O)*c,r.y=m+(D+L)*c,r.z=E+(g+R)*c;const et=S-d.x,st=l-d.y,Bt=_-d.z,Vt=r.x-S,Yt=r.y-l,Zt=r.z-_;return et*Vt+st*Yt+Bt*Zt>0&&(r.x=S,r.y=l,r.z=_,e.x=(r.x-S)/o,e.y=(r.y-l)/o,e.z=(r.z-_)/o),r}function _t(d,t){t.set(0,0),d.forEach(e=>{t.x+=e.clientX,t.y+=e.clientY}),t.x/=d.length,t.y/=d.length}function pt(d,t){return B(d)?(console.warn(`${t} is not supported in OrthographicCamera`),!0):!1}class re{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 i=this._listeners[t];if(i!==void 0){const o=i.indexOf(e);o!==-1&&i.splice(o,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 i=s.slice(0);for(let o=0,r=i.length;o<r;o++)i[o].call(this,t)}}}const nt=1/8,ne=/Mac/.test(navigator.platform);let C,St,at,ut,M,T,P,X,W,H,k,Y,Ut,Lt,z,J,K,At,ft,Rt,gt,Et,ht;class Z extends re{static install(t){C=t.THREE,St=Object.freeze(new C.Vector3(0,0,0)),at=Object.freeze(new C.Vector3(0,1,0)),ut=Object.freeze(new C.Vector3(0,0,1)),M=new C.Vector2,T=new C.Vector3,P=new C.Vector3,X=new C.Vector3,W=new C.Vector3,H=new C.Vector3,k=new C.Vector3,Y=new C.Vector3,Ut=new C.Vector3,Lt=new C.Vector3,z=new C.Spherical,J=new C.Spherical,K=new C.Box3,At=new C.Box3,ft=new C.Sphere,Rt=new C.Quaternion,gt=new C.Quaternion,Et=new C.Matrix4,ht=new C.Raycaster}static get ACTION(){return n}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=n.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=N.NONE,this._thetaVelocity={value:0},this._phiVelocity={value:0},this._radiusVelocity={value:0},this._targetVelocity=new C.Vector3,this._focalOffsetVelocity=new C.Vector3,this._zoomVelocity={value:0},this._truckInternal=(l,_,y)=>{let f,v;if(V(this._camera)){const O=T.copy(this._camera.position).sub(this._target),L=this._camera.getEffectiveFOV()*j,R=O.length()*Math.tan(L*.5);f=this.truckSpeed*l*R/this._elementRect.height,v=this.truckSpeed*_*R/this._elementRect.height}else if(B(this._camera)){const O=this._camera;f=l*(O.right-O.left)/O.zoom/this._elementRect.width,v=_*(O.top-O.bottom)/O.zoom/this._elementRect.height}else return;this.verticalDragToForward?(y?this.setFocalOffset(this._focalOffsetEnd.x+f,this._focalOffsetEnd.y,this._focalOffsetEnd.z,!0):this.truck(f,0,!0),this.forward(-v,!0)):y?this.setFocalOffset(this._focalOffsetEnd.x+f,this._focalOffsetEnd.y+v,this._focalOffsetEnd.z,!0):this.truck(f,v,!0)},this._rotateInternal=(l,_)=>{const y=q*this.azimuthRotateSpeed*l/this._elementRect.height,f=q*this.polarRotateSpeed*_/this._elementRect.height;this.rotate(y,f,!0)},this._dollyInternal=(l,_,y)=>{const f=Math.pow(.95,-l*this.dollySpeed),v=this._sphericalEnd.radius,O=this._sphericalEnd.radius*f,L=F(O,this.minDistance,this.maxDistance),R=L-O;this.infinityDolly&&this.dollyToCursor?this._dollyToNoClamp(O,!0):this.infinityDolly&&!this.dollyToCursor?(this.dollyInFixed(R,!0),this._dollyToNoClamp(L,!0)):this._dollyToNoClamp(L,!0),this.dollyToCursor&&(this._changedDolly+=(this.infinityDolly?O:L)-v,this._dollyControlCoord.set(_,y)),this._lastDollyDirection=Math.sign(-l)},this._zoomInternal=(l,_,y)=>{const f=Math.pow(.95,l*this.dollySpeed),v=this._zoom,O=this._zoom*f;this.zoomTo(O,!0),this.dollyToCursor&&(this._changedZoom+=O-v,this._dollyControlCoord.set(_,y))},typeof C=="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 C.Quaternion().setFromUnitVectors(this._camera.up,at),this._yAxisUpSpaceInverse=this._yAxisUpSpace.clone().invert(),this._state=n.NONE,this._target=new C.Vector3,this._targetEnd=this._target.clone(),this._focalOffset=new C.Vector3,this._focalOffsetEnd=this._focalOffset.clone(),this._spherical=new C.Spherical().setFromVector3(T.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 C.Vector3,new C.Vector3,new C.Vector3,new C.Vector3],this._updateNearPlaneCorners(),this._boundary=new C.Box3(new C.Vector3(-1/0,-1/0,-1/0),new C.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 C.Vector2,this.mouseButtons={left:n.ROTATE,middle:n.DOLLY,right:n.TRUCK,wheel:V(this._camera)?n.DOLLY:B(this._camera)?n.ZOOM:n.NONE},this.touches={one:n.TOUCH_ROTATE,two:V(this._camera)?n.TOUCH_DOLLY_TRUCK:B(this._camera)?n.TOUCH_ZOOM_TRUCK:n.NONE,three:n.TOUCH_TRUCK};const s=new C.Vector2,i=new C.Vector2,o=new C.Vector2,r=l=>{if(!this._enabled||!this._domElement)return;if(this._interactiveArea.left!==0||this._interactiveArea.top!==0||this._interactiveArea.width!==1||this._interactiveArea.height!==1){const f=this._domElement.getBoundingClientRect(),v=(l.clientX-f.left)/(f.right-f.left),O=(l.clientY-f.top)/(f.bottom-f.top);if(v<this._interactiveArea.left||v>this._interactiveArea.right||O<this._interactiveArea.top||O>this._interactiveArea.bottom)return}const _=l.pointerType!=="mouse"?null:(l.buttons&A.LEFT)===A.LEFT?A.LEFT:(l.buttons&A.MIDDLE)===A.MIDDLE?A.MIDDLE:(l.buttons&A.RIGHT)===A.RIGHT?A.RIGHT:null;if(_!==null){const f=this._findPointerByMouseButton(_);f&&this._disposePointer(f)}if((l.buttons&A.LEFT)===A.LEFT&&this._lockedPointer)return;const y={pointerId:l.pointerId,clientX:l.clientX,clientY:l.clientY,deltaX:0,deltaY:0,mouseButton:_};this._activePointers.push(y),this._domElement.ownerDocument.removeEventListener("pointermove",a,{passive:!1}),this._domElement.ownerDocument.removeEventListener("pointerup",h),this._domElement.ownerDocument.addEventListener("pointermove",a,{passive:!1}),this._domElement.ownerDocument.addEventListener("pointerup",h),this._isDragging=!0,E(l)},a=l=>{l.cancelable&&l.preventDefault();const _=l.pointerId,y=this._lockedPointer||this._findPointerById(_);if(y){if(y.clientX=l.clientX,y.clientY=l.clientY,y.deltaX=l.movementX,y.deltaY=l.movementY,this._state=0,l.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&&(l.buttons&A.LEFT)===A.LEFT)&&(this._state=this._state|this.mouseButtons.left),this._isDragging&&(l.buttons&A.MIDDLE)===A.MIDDLE&&(this._state=this._state|this.mouseButtons.middle),this._isDragging&&(l.buttons&A.RIGHT)===A.RIGHT&&(this._state=this._state|this.mouseButtons.right);u()}},h=l=>{const _=this._findPointerById(l.pointerId);if(!(_&&_===this._lockedPointer)){if(_&&this._disposePointer(_),l.pointerType==="touch")switch(this._activePointers.length){case 0:this._state=n.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=n.NONE;D()}};let c=-1;const p=l=>{if(!this._domElement||!this._enabled||this.mouseButtons.wheel===n.NONE)return;if(this._interactiveArea.left!==0||this._interactiveArea.top!==0||this._interactiveArea.width!==1||this._interactiveArea.height!==1){const O=this._domElement.getBoundingClientRect(),L=(l.clientX-O.left)/(O.right-O.left),R=(l.clientY-O.top)/(O.bottom-O.top);if(L<this._interactiveArea.left||L>this._interactiveArea.right||R<this._interactiveArea.top||R>this._interactiveArea.bottom)return}if(l.preventDefault(),this.dollyToCursor||this.mouseButtons.wheel===n.ROTATE||this.mouseButtons.wheel===n.TRUCK){const O=performance.now();c-O<1e3&&this._getClientRect(this._elementRect),c=O}const _=ne?-1:-3,y=l.deltaMode===1?l.deltaY/_:l.deltaY/(_*10),f=this.dollyToCursor?(l.clientX-this._elementRect.x)/this._elementRect.width*2-1:0,v=this.dollyToCursor?(l.clientY-this._elementRect.y)/this._elementRect.height*-2+1:0;switch(this.mouseButtons.wheel){case n.ROTATE:{this._rotateInternal(l.deltaX,l.deltaY),this._isUserControllingRotate=!0;break}case n.TRUCK:{this._truckInternal(l.deltaX,l.deltaY,!1),this._isUserControllingTruck=!0;break}case n.OFFSET:{this._truckInternal(l.deltaX,l.deltaY,!0),this._isUserControllingOffset=!0;break}case n.DOLLY:{this._dollyInternal(-y,f,v),this._isUserControllingDolly=!0;break}case n.ZOOM:{this._zoomInternal(-y,f,v),this._isUserControllingZoom=!0;break}}this.dispatchEvent({type:"control"})},m=l=>{if(!(!this._domElement||!this._enabled)){if(this.mouseButtons.right===Z.ACTION.NONE){const _=l instanceof PointerEvent?l.pointerId:0,y=this._findPointerById(_);y&&this._disposePointer(y),this._domElement.ownerDocument.removeEventListener("pointermove",a,{passive:!1}),this._domElement.ownerDocument.removeEventListener("pointerup",h);return}l.preventDefault()}},E=l=>{if(!this._enabled)return;if(_t(this._activePointers,M),this._getClientRect(this._elementRect),s.copy(M),i.copy(M),this._activePointers.length>=2){const y=M.x-this._activePointers[1].clientX,f=M.y-this._activePointers[1].clientY,v=Math.sqrt(y*y+f*f);o.set(0,v);const O=(this._activePointers[0].clientX+this._activePointers[1].clientX)*.5,L=(this._activePointers[0].clientY+this._activePointers[1].clientY)*.5;i.set(O,L)}if(this._state=0,!l)this._lockedPointer&&(this._state=this._state|this.mouseButtons.left);else if("pointerType"in l&&l.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&&(l.buttons&A.LEFT)===A.LEFT&&(this._state=this._state|this.mouseButtons.left),(l.buttons&A.MIDDLE)===A.MIDDLE&&(this._state=this._state|this.mouseButtons.middle),(l.buttons&A.RIGHT)===A.RIGHT&&(this._state=this._state|this.mouseButtons.right);((this._state&n.ROTATE)===n.ROTATE||(this._state&n.TOUCH_ROTATE)===n.TOUCH_ROTATE||(this._state&n.TOUCH_DOLLY_ROTATE)===n.TOUCH_DOLLY_ROTATE||(this._state&n.TOUCH_ZOOM_ROTATE)===n.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&n.TRUCK)===n.TRUCK||(this._state&n.TOUCH_TRUCK)===n.TOUCH_TRUCK||(this._state&n.TOUCH_DOLLY_TRUCK)===n.TOUCH_DOLLY_TRUCK||(this._state&n.TOUCH_ZOOM_TRUCK)===n.TOUCH_ZOOM_TRUCK)&&(this._targetEnd.copy(this._target),this._targetVelocity.set(0,0,0)),((this._state&n.DOLLY)===n.DOLLY||(this._state&n.TOUCH_DOLLY)===n.TOUCH_DOLLY||(this._state&n.TOUCH_DOLLY_TRUCK)===n.TOUCH_DOLLY_TRUCK||(this._state&n.TOUCH_DOLLY_OFFSET)===n.TOUCH_DOLLY_OFFSET||(this._state&n.TOUCH_DOLLY_ROTATE)===n.TOUCH_DOLLY_ROTATE)&&(this._sphericalEnd.radius=this._spherical.radius,this._radiusVelocity.value=0),((this._state&n.ZOOM)===n.ZOOM||(this._state&n.TOUCH_ZOOM)===n.TOUCH_ZOOM||(this._state&n.TOUCH_ZOOM_TRUCK)===n.TOUCH_ZOOM_TRUCK||(this._state&n.TOUCH_ZOOM_OFFSET)===n.TOUCH_ZOOM_OFFSET||(this._state&n.TOUCH_ZOOM_ROTATE)===n.TOUCH_ZOOM_ROTATE)&&(this._zoomEnd=this._zoom,this._zoomVelocity.value=0),((this._state&n.OFFSET)===n.OFFSET||(this._state&n.TOUCH_OFFSET)===n.TOUCH_OFFSET||(this._state&n.TOUCH_DOLLY_OFFSET)===n.TOUCH_DOLLY_OFFSET||(this._state&n.TOUCH_ZOOM_OFFSET)===n.TOUCH_ZOOM_OFFSET)&&(this._focalOffsetEnd.copy(this._focalOffset),this._focalOffsetVelocity.set(0,0,0)),this.dispatchEvent({type:"controlstart"})},u=()=>{if(!this._enabled||!this._dragNeedsUpdate)return;this._dragNeedsUpdate=!1,_t(this._activePointers,M);const _=this._domElement&&this._domElement.ownerDocument.pointerLockElement===this._domElement?this._lockedPointer||this._activePointers[0]:null,y=_?-_.deltaX:i.x-M.x,f=_?-_.deltaY:i.y-M.y;if(i.copy(M),((this._state&n.ROTATE)===n.ROTATE||(this._state&n.TOUCH_ROTATE)===n.TOUCH_ROTATE||(this._state&n.TOUCH_DOLLY_ROTATE)===n.TOUCH_DOLLY_ROTATE||(this._state&n.TOUCH_ZOOM_ROTATE)===n.TOUCH_ZOOM_ROTATE)&&(this._rotateInternal(y,f),this._isUserControllingRotate=!0),(this._state&n.DOLLY)===n.DOLLY||(this._state&n.ZOOM)===n.ZOOM){const v=this.dollyToCursor?(s.x-this._elementRect.x)/this._elementRect.width*2-1:0,O=this.dollyToCursor?(s.y-this._elementRect.y)/this._elementRect.height*-2+1:0,L=this.dollyDragInverted?-1:1;(this._state&n.DOLLY)===n.DOLLY?(this._dollyInternal(L*f*nt,v,O),this._isUserControllingDolly=!0):(this._zoomInternal(L*f*nt,v,O),this._isUserControllingZoom=!0)}if((this._state&n.TOUCH_DOLLY)===n.TOUCH_DOLLY||(this._state&n.TOUCH_ZOOM)===n.TOUCH_ZOOM||(this._state&n.TOUCH_DOLLY_TRUCK)===n.TOUCH_DOLLY_TRUCK||(this._state&n.TOUCH_ZOOM_TRUCK)===n.TOUCH_ZOOM_TRUCK||(this._state&n.TOUCH_DOLLY_OFFSET)===n.TOUCH_DOLLY_OFFSET||(this._state&n.TOUCH_ZOOM_OFFSET)===n.TOUCH_ZOOM_OFFSET||(this._state&n.TOUCH_DOLLY_ROTATE)===n.TOUCH_DOLLY_ROTATE||(this._state&n.TOUCH_ZOOM_ROTATE)===n.TOUCH_ZOOM_ROTATE){const v=M.x-this._activePointers[1].clientX,O=M.y-this._activePointers[1].clientY,L=Math.sqrt(v*v+O*O),R=o.y-L;o.set(0,L);const et=this.dollyToCursor?(i.x-this._elementRect.x)/this._elementRect.width*2-1:0,st=this.dollyToCursor?(i.y-this._elementRect.y)/this._elementRect.height*-2+1:0;(this._state&n.TOUCH_DOLLY)===n.TOUCH_DOLLY||(this._state&n.TOUCH_DOLLY_ROTATE)===n.TOUCH_DOLLY_ROTATE||(this._state&n.TOUCH_DOLLY_TRUCK)===n.TOUCH_DOLLY_TRUCK||(this._state&n.TOUCH_DOLLY_OFFSET)===n.TOUCH_DOLLY_OFFSET?(this._dollyInternal(R*nt,et,st),this._isUserControllingDolly=!0):(this._zoomInternal(R*nt,et,st),this._isUserControllingZoom=!0)}((this._state&n.TRUCK)===n.TRUCK||(this._state&n.TOUCH_TRUCK)===n.TOUCH_TRUCK||(this._state&n.TOUCH_DOLLY_TRUCK)===n.TOUCH_DOLLY_TRUCK||(this._state&n.TOUCH_ZOOM_TRUCK)===n.TOUCH_ZOOM_TRUCK)&&(this._truckInternal(y,f,!1),this._isUserControllingTruck=!0),((this._state&n.OFFSET)===n.OFFSET||(this._state&n.TOUCH_OFFSET)===n.TOUCH_OFFSET||(this._state&n.TOUCH_DOLLY_OFFSET)===n.TOUCH_DOLLY_OFFSET||(this._state&n.TOUCH_ZOOM_OFFSET)===n.TOUCH_ZOOM_OFFSET)&&(this._truckInternal(y,f,!0),this._isUserControllingOffset=!0),this.dispatchEvent({type:"control"})},D=()=>{_t(this._activePointers,M),i.copy(M),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",h),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",h),this._domElement.requestPointerLock(),this._domElement.ownerDocument.addEventListener("pointerlockchange",g),this._domElement.ownerDocument.addEventListener("pointerlockerror",S),this._domElement.ownerDocument.addEventListener("pointermove",a,{passive:!1}),this._domElement.ownerDocument.addEventListener("pointerup",h),E())},this.unlockPointer=()=>{var l,_,y;this._lockedPointer!==null&&(this._disposePointer(this._lockedPointer),this._lockedPointer=null),(l=this._domElement)===null||l===void 0||l.ownerDocument.exitPointerLock(),(_=this._domElement)===null||_===void 0||_.ownerDocument.removeEventListener("pointerlockchange",g),(y=this._domElement)===null||y===void 0||y.ownerDocument.removeEventListener("pointerlockerror",S),this.cancel()};const g=()=>{this._domElement&&this._domElement.ownerDocument.pointerLockElement===this._domElement||this.unlockPointer()},S=()=>{this.unlockPointer()};this._addAllEventListeners=l=>{this._domElement=l,this._domElement.style.touchAction="none",this._domElement.style.userSelect="none",this._domElement.style.webkitUserSelect="none",this._domElement.addEventListener("pointerdown",r),this._domElement.addEventListener("pointercancel",h),this._domElement.addEventListener("wheel",p,{passive:!1}),this._domElement.addEventListener("contextmenu",m)},this._removeAllEventListeners=()=>{this._domElement&&(this._domElement.style.touchAction="",this._domElement.style.userSelect="",this._domElement.style.webkitUserSelect="",this._domElement.removeEventListener("pointerdown",r),this._domElement.removeEventListener("pointercancel",h),this._domElement.removeEventListener("wheel",p,{passive:!1}),this._domElement.removeEventListener("contextmenu",m),this._domElement.ownerDocument.removeEventListener("pointermove",a,{passive:!1}),this._domElement.ownerDocument.removeEventListener("pointerup",h),this._domElement.ownerDocument.removeEventListener("pointerlockchange",g),this._domElement.ownerDocument.removeEventListener("pointerlockerror",S))},this.cancel=()=>{this._state!==n.NONE&&(this._state=n.NONE,this._activePointers.length=0,D())},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 i=F(t,this.minAzimuthAngle,this.maxAzimuthAngle),o=F(e,this.minPolarAngle,this.maxPolarAngle);this._sphericalEnd.theta=i,this._sphericalEnd.phi=o,this._sphericalEnd.makeSafe(),this._needsUpdate=!0,s||(this._spherical.theta=this._sphericalEnd.theta,this._spherical.phi=this._sphericalEnd.phi);const r=!s||w(this._spherical.theta,this._sphericalEnd.theta,this.restThreshold)&&w(this._spherical.phi,this._sphericalEnd.phi,this.restThreshold);return this._createOnRestPromise(r)}dolly(t,e=!1){return this.dollyTo(this._sphericalEnd.radius-t,e)}dollyTo(t,e=!1){return this._isUserControllingDolly=!1,this._lastDollyDirection=N.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 r=this._collisionTest(),a=w(r,this._spherical.radius);if(!(s>t)&&a)return Promise.resolve();this._sphericalEnd.radius=Math.min(t,r)}else this._sphericalEnd.radius=t;this._needsUpdate=!0,e||(this._spherical.radius=this._sphericalEnd.radius);const o=!e||w(this._spherical.radius,this._sphericalEnd.radius,this.restThreshold);return this._createOnRestPromise(o)}dollyInFixed(t,e=!1){this._targetEnd.add(this._getCameraDirection(W).multiplyScalar(t)),e||this._target.copy(this._targetEnd);const s=!e||w(this._target.x,this._targetEnd.x,this.restThreshold)&&w(this._target.y,this._targetEnd.y,this.restThreshold)&&w(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||w(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),k.setFromMatrixColumn(this._camera.matrix,1),H.multiplyScalar(t),k.multiplyScalar(-e);const i=T.copy(H).add(k),o=P.copy(this._targetEnd).add(i);return this.moveTo(o.x,o.y,o.z,s)}forward(t,e=!1){T.setFromMatrixColumn(this._camera.matrix,0),T.crossVectors(this._camera.up,T),T.multiplyScalar(t);const s=P.copy(this._targetEnd).add(T);return this.moveTo(s.x,s.y,s.z,e)}elevate(t,e=!1){return T.copy(this._camera.up).multiplyScalar(t),this.moveTo(this._targetEnd.x+T.x,this._targetEnd.y+T.y,this._targetEnd.z+T.z,e)}moveTo(t,e,s,i=!1){this._isUserControllingTruck=!1;const o=T.set(t,e,s).sub(this._targetEnd);this._encloseToBoundary(this._targetEnd,o,this.boundaryFriction),this._needsUpdate=!0,i||this._target.copy(this._targetEnd);const r=!i||w(this._target.x,this._targetEnd.x,this.restThreshold)&&w(this._target.y,this._targetEnd.y,this.restThreshold)&&w(this._target.z,this._targetEnd.z,this.restThreshold);return this._createOnRestPromise(r)}lookInDirectionOf(t,e,s,i=!1){const a=T.set(t,e,s).sub(this._targetEnd).normalize().multiplyScalar(-this._sphericalEnd.radius).add(this._targetEnd);return this.setPosition(a.x,a.y,a.z,i)}fitToBox(t,e,{cover:s=!1,paddingLeft:i=0,paddingRight:o=0,paddingBottom:r=0,paddingTop:a=0}={}){const h=[],c=t.isBox3?K.copy(t):K.setFromObject(t);c.isEmpty()&&(console.warn("camera-controls: fitTo() cannot be used with an empty box. Aborting"),Promise.resolve());const p=Dt(this._sphericalEnd.theta,xt),m=Dt(this._sphericalEnd.phi,xt);h.push(this.rotateTo(p,m,e));const E=T.setFromSpherical(this._sphericalEnd).normalize(),u=Rt.setFromUnitVectors(E,ut),D=w(Math.abs(E.y),1);D&&u.multiply(gt.setFromAxisAngle(at,p)),u.multiply(this._yAxisUpSpaceInverse);const g=At.makeEmpty();P.copy(c.min).applyQuaternion(u),g.expandByPoint(P),P.copy(c.min).setX(c.max.x).applyQuaternion(u),g.expandByPoint(P),P.copy(c.min).setY(c.max.y).applyQuaternion(u),g.expandByPoint(P),P.copy(c.max).setZ(c.min.z).applyQuaternion(u),g.expandByPoint(P),P.copy(c.min).setZ(c.max.z).applyQuaternion(u),g.expandByPoint(P),P.copy(c.max).setY(c.min.y).applyQuaternion(u),g.expandByPoint(P),P.copy(c.max).setX(c.min.x).applyQuaternion(u),g.expandByPoint(P),P.copy(c.max).applyQuaternion(u),g.expandByPoint(P),g.min.x-=i,g.min.y-=r,g.max.x+=o,g.max.y+=a,u.setFromUnitVectors(ut,E),D&&u.premultiply(gt.invert()),u.premultiply(this._yAxisUpSpace);const S=g.getSize(T),l=g.getCenter(P).applyQuaternion(u);if(V(this._camera)){const _=this.getDistanceToFitBox(S.x,S.y,S.z,s);h.push(this.moveTo(l.x,l.y,l.z,e)),h.push(this.dollyTo(_,e)),h.push(this.setFocalOffset(0,0,0,e))}else if(B(this._camera)){const _=this._camera,y=_.right-_.left,f=_.top-_.bottom,v=s?Math.max(y/S.x,f/S.y):Math.min(y/S.x,f/S.y);h.push(this.moveTo(l.x,l.y,l.z,e)),h.push(this.zoomTo(v,e)),h.push(this.setFocalOffset(0,0,0,e))}return Promise.all(h)}fitToSphere(t,e){const s=[],o="isObject3D"in t?Z.createBoundingSphere(t,ft):ft.copy(t);if(s.push(this.moveTo(o.center.x,o.center.y,o.center.z,e)),V(this._camera)){const r=this.getDistanceToFitSphere(o.radius);s.push(this.dollyTo(r,e))}else if(B(this._camera)){const r=this._camera.right-this._camera.left,a=this._camera.top-this._camera.bottom,h=2*o.radius,c=Math.min(r/h,a/h);s.push(this.zoomTo(c,e))}return s.push(this.setFocalOffset(0,0,0,e)),Promise.all(s)}setLookAt(t,e,s,i,o,r,a=!1){this._isUserControllingRotate=!1,this._isUserControllingDolly=!1,this._isUserControllingTruck=!1,this._lastDollyDirection=N.NONE,this._changedDolly=0;const h=P.set(i,o,r),c=T.set(t,e,s);this._targetEnd.copy(h),this._sphericalEnd.setFromVector3(c.sub(h).applyQuaternion(this._yAxisUpSpace)),this.normalizeRotations(),this._needsUpdate=!0,a||(this._target.copy(this._targetEnd),this._spherical.copy(this._sphericalEnd));const p=!a||w(this._target.x,this._targetEnd.x,this.restThreshold)&&w(this._target.y,this._targetEnd.y,this.restThreshold)&&w(this._target.z,this._targetEnd.z,this.restThreshold)&&w(this._spherical.theta,this._sphericalEnd.theta,this.restThreshold)&&w(this._spherical.phi,this._sphericalEnd.phi,this.restThreshold)&&w(this._spherical.radius,this._sphericalEnd.radius,this.restThreshold);return this._createOnRestPromise(p)}lerpLookAt(t,e,s,i,o,r,a,h,c,p,m,E,u,D=!1){this._isUserControllingRotate=!1,this._isUserControllingDolly=!1,this._isUserControllingTruck=!1,this._lastDollyDirection=N.NONE,this._changedDolly=0;const g=T.set(i,o,r),S=P.set(t,e,s);z.setFromVector3(S.sub(g).applyQuaternion(this._yAxisUpSpace));const l=X.set(p,m,E),_=P.set(a,h,c);J.setFromVector3(_.sub(l).applyQuaternion(this._yAxisUpSpace)),this._targetEnd.copy(g.lerp(l,u));const y=J.theta-z.theta,f=J.phi-z.phi,v=J.radius-z.radius;this._sphericalEnd.set(z.radius+v*u,z.phi+f*u,z.theta+y*u),this.normalizeRotations(),this._needsUpdate=!0,D||(this._target.copy(this._targetEnd),this._spherical.copy(this._sphericalEnd));const O=!D||w(this._target.x,this._targetEnd.x,this.restThreshold)&&w(this._target.y,this._targetEnd.y,this.restThreshold)&&w(this._target.z,this._targetEnd.z,this.restThreshold)&&w(this._spherical.theta,this._sphericalEnd.theta,this.restThreshold)&&w(this._spherical.phi,this._sphericalEnd.phi,this.restThreshold)&&w(this._spherical.radius,this._sphericalEnd.radius,this.restThreshold);return this._createOnRestPromise(O)}setPosition(t,e,s,i=!1){return this.setLookAt(t,e,s,this._targetEnd.x,this._targetEnd.y,this._targetEnd.z,i)}setTarget(t,e,s,i=!1){const o=this.getPosition(T),r=this.setLookAt(o.x,o.y,o.z,t,e,s,i);return this._sphericalEnd.phi=F(this._sphericalEnd.phi,this.minPolarAngle,this.maxPolarAngle),r}setFocalOffset(t,e,s,i=!1){this._isUserControllingOffset=!1,this._focalOffsetEnd.set(t,e,s),this._needsUpdate=!0,i||this._focalOffset.copy(this._focalOffsetEnd);const o=!i||w(this._focalOffset.x,this._focalOffsetEnd.x,this.restThreshold)&&w(this._focalOffset.y,this._focalOffsetEnd.y,this.restThreshold)&&w(this._focalOffset.z,this._focalOffsetEnd.z,this.restThreshold);return this._createOnRestPromise(o)}setOrbitPoint(t,e,s){this._camera.updateMatrixWorld(),H.setFromMatrixColumn(this._camera.matrixWorldInverse,0),k.setFromMatrixColumn(this._camera.matrixWorldInverse,1),Y.setFromMatrixColumn(this._camera.matrixWorldInverse,2);const i=T.set(t,e,s),o=i.distanceTo(this._camera.position),r=i.sub(this._camera.position);H.multiplyScalar(r.x),k.multiplyScalar(r.y),Y.multiplyScalar(r.z),T.copy(H).add(k).add(Y),T.z=T.z+o,this.dollyTo(o,!1),this.setFocalOffset(-T.x,T.y,-T.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,i){if(t===null){this._viewport=null;return}this._viewport=this._viewport||new C.Vector4,typeof t=="number"?this._viewport.set(t,e,s,i):this._viewport.copy(t)}getDistanceToFitBox(t,e,s,i=!1){if(pt(this._camera,"getDistanceToFitBox"))return this._spherical.radius;const o=t/e,r=this._camera.getEffectiveFOV()*j,a=this._camera.aspect;return((i?o>a:o<a)?e:t/a)*.5/Math.tan(r*.5)+s*.5}getDistanceToFitSphere(t){if(pt(this._camera,"getDistanceToFitSphere"))return this._spherical.radius;const e=this._camera.getEffectiveFOV()*j,s=Math.atan(Math.tan(e*.5)*this._camera.aspect)*2,i=1<this._camera.aspect?e:s;return t/Math.sin(i*.5)}getTarget(t,e=!0){return(t&&t.isVector3?t:new C.Vector3).copy(e?this._targetEnd:this._target)}getPosition(t,e=!0){return(t&&t.isVector3?t:new C.Vector3).setFromSpherical(e?this._sphericalEnd:this._spherical).applyQuaternion(this._yAxisUpSpaceInverse).add(e?this._targetEnd:this._target)}getSpherical(t,e=!0){return(t||new C.Spherical).copy(e?this._sphericalEnd:this._spherical)}getFocalOffset(t,e=!0){return(t&&t.isVector3?t:new C.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(!w(this._camera.up.x,this._cameraUp0.x)||!w(this._camera.up.y,this._cameraUp0.y)||!w(this._camera.up.z,this._cameraUp0.z)){this._camera.up.copy(this._cameraUp0);const s=this.getPosition(T);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,at),this._yAxisUpSpaceInverse.copy(this._yAxisUpSpace).invert()}applyCameraUp(){const t=T.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(T);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,i=this._sphericalEnd.radius-this._spherical.radius,o=Ut.subVectors(this._targetEnd,this._target),r=Lt.subVectors(this._focalOffsetEnd,this._focalOffset),a=this._zoomEnd-this._zoom;if(U(e))this._thetaVelocity.value=0,this._spherical.theta=this._sphericalEnd.theta;else{const m=this._isUserControllingRotate?this.draggingSmoothTime:this.smoothTime;this._spherical.theta=rt(this._spherical.theta,this._sphericalEnd.theta,this._thetaVelocity,m,1/0,t),this._needsUpdate=!0}if(U(s))this._phiVelocity.value=0,this._spherical.phi=this._sphericalEnd.phi;else{const m=this._isUserControllingRotate?this.draggingSmoothTime:this.smoothTime;this._spherical.phi=rt(this._spherical.phi,this._sphericalEnd.phi,this._phiVelocity,m,1/0,t),this._needsUpdate=!0}if(U(i))this._radiusVelocity.value=0,this._spherical.radius=this._sphericalEnd.radius;else{const m=this._isUserControllingDolly?this.draggingSmoothTime:this.smoothTime;this._spherical.radius=rt(this._spherical.radius,this._sphericalEnd.radius,this._radiusVelocity,m,this.maxSpeed,t),this._needsUpdate=!0}if(U(o.x)&&U(o.y)&&U(o.z))this._targetVelocity.set(0,0,0),this._target.copy(this._targetEnd);else{const m=this._isUserControllingTruck?this.draggingSmoothTime:this.smoothTime;wt(this._target,this._targetEnd,this._targetVelocity,m,this.maxSpeed,t,this._target),this._needsUpdate=!0}if(U(r.x)&&U(r.y)&&U(r.z))this._focalOffsetVelocity.set(0,0,0),this._focalOffset.copy(this._focalOffsetEnd);else{const m=this._isUserControllingOffset?this.draggingSmoothTime:this.smoothTime;wt(this._focalOffset,this._focalOffsetEnd,this._focalOffsetVelocity,m,this.maxSpeed,t,this._focalOffset),this._needsUpdate=!0}if(U(a))this._zoomVelocity.value=0,this._zoom=this._zoomEnd;else{const m=this._isUserControllingZoom?this.draggingSmoothTime:this.smoothTime;this._zoom=rt(this._zoom,this._zoomEnd,this._zoomVelocity,m,1/0,t)}if(this.dollyToCursor){if(V(this._camera)&&this._changedDolly!==0){const m=this._spherical.radius-this._lastDistance,E=this._camera,u=this._getCameraDirection(W),D=T.copy(u).cross(E.up).normalize();D.lengthSq()===0&&(D.x=1);const g=P.crossVectors(D,u),S=this._sphericalEnd.radius*Math.tan(E.getEffectiveFOV()*j*.5),_=(this._sphericalEnd.radius-m-this._sphericalEnd.radius)/this._sphericalEnd.radius,y=X.copy(this._targetEnd).add(D.multiplyScalar(this._dollyControlCoord.x*S*E.aspect)).add(g.multiplyScalar(this._dollyControlCoord.y*S)),f=T.copy(this._targetEnd).lerp(y,_),v=this._lastDollyDirection===N.IN&&this._spherical.radius<=this.minDistance,O=this._lastDollyDirection===N.OUT&&this.maxDistance<=this._spherical.radius;if(this.infinityDolly&&(v||O)){this._sphericalEnd.radius-=m,this._spherical.radius-=m;const R=P.copy(u).multiplyScalar(-m);f.add(R)}this._boundary.clampPoint(f,f);const L=P.subVectors(f,this._targetEnd);this._targetEnd.copy(f),this._target.add(L),this._changedDolly-=m,U(this._changedDolly)&&(this._changedDolly=0)}else if(B(this._camera)&&this._changedZoom!==0){const m=this._zoom-this._lastZoom,E=this._camera,u=T.set(this._dollyControlCoord.x,this._dollyControlCoord.y,(E.near+E.far)/(E.near-E.far)).unproject(E),D=P.set(0,0,-1).applyQuaternion(E.quaternion),g=X.copy(u).add(D.multiplyScalar(-u.dot(E.up))),l=-(this._zoom-m-this._zoom)/this._zoom,_=this._getCameraDirection(W),y=this._targetEnd.dot(_),f=T.copy(this._targetEnd).lerp(g,l),v=f.dot(_),O=_.multiplyScalar(v-y);f.sub(O),this._boundary.clampPoint(f,f);const L=P.subVectors(f,this._targetEnd);this._targetEnd.copy(f),this._target.add(L),this._changedZoom-=m,U(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 h=this._collisionTest();this._spherical.radius=Math.min(this._spherical.radius,h),this._spherical.makeSafe(),this._camera.position.setFromSpherical(this._spherical).applyQuaternion(this._yAxisUpSpaceInverse).add(this._target),this._camera.lookAt(this._target),(!U(this._focalOffset.x)||!U(this._focalOffset.y)||!U(this._focalOffset.z))&&(this._camera.updateMatrixWorld(),H.setFromMatrixColumn(this._camera.matrix,0),k.setFromMatrixColumn(this._camera.matrix,1),Y.setFromMatrixColumn(this._camera.matrix,2),H.multiplyScalar(this._focalOffset.x),k.multiplyScalar(-this._focalOffset.y),Y.multiplyScalar(this._focalOffset.z),T.copy(H).add(k).add(Y),this._camera.position.add(T)),this._boundaryEnclosesCamera&&this._encloseToBoundary(this._camera.position.copy(this._target),T.setFromSpherical(this._spherical).applyQuaternion(this._yAxisUpSpaceInverse),1);const p=this._needsUpdate;return p&&!this._updatedLastTime?(this._hasRested=!1,this.dispatchEvent({type:"wake"}),this.dispatchEvent({type:"update"})):p?(this.dispatchEvent({type:"update"}),U(e,this.restThreshold)&&U(s,this.restThreshold)&&U(i,this.restThreshold)&&U(o.x,this.restThreshold)&&U(o.y,this.restThreshold)&&U(o.z,this.restThreshold)&&U(r.x,this.restThreshold)&&U(r.y,this.restThreshold)&&U(r.z,this.restThreshold)&&U(a,this.restThreshold)&&!this._hasRested&&(this._hasRested=!0,this.dispatchEvent({type:"rest"}))):!p&&this._updatedLastTime&&this.dispatchEvent({type:"sleep"}),this._lastDistance=this._spherical.radius,this._lastZoom=this._zoom,this._updatedLastTime=p,this._needsUpdate=!1,p}toJSON(){return JSON.stringify({enabled:this._enabled,minDistance:this.minDistance,maxDistance:G(this.maxDistance),minZoom:this.minZoom,maxZoom:G(this.maxZoom),minPolarAngle:this.minPolarAngle,maxPolarAngle:G(this.maxPolarAngle),minAzimuthAngle:G(this.minAzimuthAngle),maxAzimuthAngle:G(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:T.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=Q(s.maxDistance),this.minZoom=s.minZoom,this.maxZoom=Q(s.maxZoom),this.minPolarAngle=s.minPolarAngle,this.maxPolarAngle=Q(s.maxPolarAngle),this.minAzimuthAngle=Q(s.minAzimuthAngle),this.maxAzimuthAngle=Q(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),z.setFromVector3(T.fromArray(s.position).sub(this._targetEnd).applyQuaternion(this._yAxisUpSpace)),this.rotateTo(z.theta,z.phi,e),this.dollyTo(z.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 i=e.lengthSq();if(i===0)return t;const o=P.copy(e).add(t),a=this._boundary.clampPoint(o,X).sub(o),h=a.lengthSq();if(h===0)return t.add(e);if(h===i)return t;if(s===0)return t.add(e).add(a);{const c=1+s*h/e.dot(a);return t.add(P.copy(e).multiplyScalar(c)).add(a.multiplyScalar(1-s))}}_updateNearPlaneCorners(){if(V(this._camera)){const t=this._camera,e=t.near,s=t.getEffectiveFOV()*j,i=Math.tan(s*.5)*e,o=i*t.aspect;this._nearPlaneCorners[0].set(-o,-i,0),this._nearPlaneCorners[1].set(o,-i,0),this._nearPlaneCorners[2].set(o,i,0),this._nearPlaneCorners[3].set(-o,i,0)}else if(B(this._camera)){const t=this._camera,e=1/t.zoom,s=t.left*e,i=t.right*e,o=t.top*e,r=t.bottom*e;this._nearPlaneCorners[0].set(s,o,0),this._nearPlaneCorners[1].set(i,o,0),this._nearPlaneCorners[2].set(i,r,0),this._nearPlaneCorners[3].set(s,r,0)}}_collisionTest(){let t=1/0;if(!(this.colliderMeshes.length>=1)||pt(this._camera,"_collisionTest"))return t;const s=this._getTargetDirection(W);Et.lookAt(St,s,this._camera.up);for(let i=0;i<4;i++){const o=P.copy(this._nearPlaneCorners[i]);o.applyMatrix4(Et);const r=X.addVectors(this._target,o);ht.set(r,s),ht.far=this._spherical.radius+1;const a=ht.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 C.Sphere){const s=e,i=s.center;K.makeEmpty(),t.traverseVisible(r=>{r.isMesh&&K.expandByObject(r)}),K.getCenter(i);let o=0;return t.traverseVisible(r=>{if(!r.isMesh)return;const a=r,h=a.geometry.clone();h.applyMatrix4(a.matrixWorld);const p=h.attributes.position;for(let m=0,E=p.count;m<E;m++)T.fromBufferAttribute(p,m),o=Math.max(o,i.distanceToSquared(T))}),s.radius=Math.sqrt(o),s}}const ae={antialias:!1,devicePixelRatio:window.devicePixelRatio,powerPreference:"high-performance",toneMappingExposure:1,alpha:!1,outputColorSpace:Wt.ColorSpace.sRGB,logarithmicDepthBuffer:!1,preserveDrawingBuffer:!1,stencil:!1,depth:!1,physicallyCorrectLights:!1};class he{constructor(t){this.options=t;const{width:e,height:s,rendererParams:i}=t,{canvas:o,context:r,alpha:a,devicePixelRatio:h,antialias:c,powerPreference:p,toneMappingExposure:m,outputColorSpace:E,logarithmicDepthBuffer:u,preserveDrawingBuffer:D,stencil:g,depth:S,physicallyCorrectLights:l}=i,_=new x.WebGLRenderer({canvas:o,context:r,alpha:a,antialias:c,powerPreference:p,logarithmicDepthBuffer:u,preserveDrawingBuffer:D,stencil:g,depth:S});_.setSize(e,s),_.setPixelRatio(h),_.toneMappingExposure=m,_.outputColorSpace=E,+x.REVISION<155&&(_.useLegacyLights=l),this.renderer=_}setSize(t,e){this.renderer.setSize(t,e)}render(t){const{scene:e,camera:s}=this.options;this.renderer.render(e,t||s)}dispose(){var t,e;this.setSize(1,1),(t=this.renderer)==null||t.clear(),(e=this.renderer)==null||e.dispose()}}class lt{constructor(t){this.guiParams={},t&&(this.guiParams=t)}showGui(t){t&&Object.keys(this.guiParams).forEach(e=>{const s=t.addFolder(e),i=this.guiParams[e];Object.keys(i).forEach(o=>{const{min:r,max:a,step:h,name:c,paramMap:p,items:m,value:E,target:u}=i[o],D=o.toLowerCase().indexOf("color")>-1;let g;const S=typeof E=="undefined"&&u,l=S?u():i[o],_=S?o:"value";m?g=s.add(l,_,m):D?g=s.addColor(l,_):g=s.add(l,_),g=g.name(c||o),typeof r!="undefined"&&(g=g.min(r)),typeof a!="undefined"&&(g=g.max(a)),typeof h!="undefined"&&(g=g.step(h)),g=g.onChange(()=>{this.setTargetValue(e,o,l[_],p)}),S&&g.listen()})})}setTargetValue(t,e,s,i){const{onChange:o,target:r,value:a}=this.guiParams[t][e],h=e.toLowerCase().indexOf("color")>-1;if(r&&!(typeof a=="undefined"&&r)){let p=r();Array.isArray(p)||(p=[p]),p.forEach(m=>{if(m)if(h)try{m[i||e].set(s)}catch(E){e!=="color"&&!i&&console.warn(`${e} is not a color,set paramMap`)}else m[i||e]=s})}o&&o(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={fov:45,near:1,far:1e3,up:new x.Vector3(0,1,0)};class ce{constructor(t){this.customCamera=!1,this.options=t;const{width:e,height:s,cameraParams:i}=t;if(i instanceof x.Camera)this.camera=i,this.customCamera=!0;else{const{fov:o,far:r,near:a,up:h}=i,c=new x.PerspectiveCamera(o,e/s,a,r);c.position.set(0,0,400),c.lookAt(0,0,0),c.up=h,this.camera=c}}setSize(t,e){this.camera instanceof x.PerspectiveCamera&&(this.camera.aspect=t/e),this.camera.updateProjectionMatrix(),this.camera2&&(this.camera2.aspect=t/e,this.camera2.updateProjectionMatrix())}addCamera2(){const t=new x.PerspectiveCamera(this.camera.fov,this.camera.aspect,this.camera.near,this.camera.far);return t.position.copy(this.camera.position),this.camera2=t,t}setGui(t){const e=new lt({camera:ot(I({},this.options.cameraControls?{}:{x:{min:-1e4,max:1e4,step:1,target:()=>this.camera.position},y:{min:-1e4,max:1e4,step:1,target:()=>this.camera.position},z:{min:-1e4,max:1e4,step:1,target:()=>this.camera.position}}),{near:{min:0,max:1e3,step:1,target:()=>this.camera,onChange:s=>{this.camera.updateProjectionMatrix()}},far:{min:0,max:2e4,step:1,target:()=>this.camera,onChange:s=>{this.camera.updateProjectionMatrix()}}})});this.camera instanceof x.PerspectiveCamera&&(e.guiParams.camera.fov={min:0,max:90,step:1,target:()=>this.camera,onChange:s=>{this.camera.updateProjectionMatrix()}}),e.showGui(t)}}const de={background:null,om:!0};class me{constructor(t){this.overrideMaterial=!1,this.options=t;const{camera:e,sceneParams:s}=t,{background:i,om:o}=s,r=o?new x.Scene:new Proxy(new x.Scene,{set:(a,h,c)=>Reflect.set(a,h,c),get:(a,h)=>{if(h==="overrideMaterial"){const c=Reflect.get(a,h);return this.overrideMaterial=!!c,vt.meshLineMaterialArr.forEach(p=>{this.overrideMaterial?p.useDepth=1:p.useDepth=0}),null}return Reflect.get(a,h)}});i&&(r.background=i),r.add(e),this.scene=r}dispose(){var t;(t=this.scene)==null||t.traverse(e=>{Jt.disposeMesh(e)}),vt.meshLineMaterialArr.length=0}}class _e{constructor(t){this.helpers={},this.options=t}add(t){const e=t.uuid,{scene:s}=this.options;let i=this.helpers[e];if(i===void 0){if(t.isScene)i=new x.AxesHelper(100);else if(t.isCamera)i=new x.CameraHelper(t);else if(t.isPointLight)i=new x.PointLightHelper(t,1);else if(t.isDirectionalLight)i=new x.DirectionalLightHelper(t,1);else if(t.isSpotLight)i=new x.SpotLightHelper(t);else if(t.isHemisphereLight)i=new x.HemisphereLightHelper(t,10);else if(t.isRectAreaLight)i=new $t.RectAreaLightHelper(t);else{const o=new x.Box3;if(o.setFromObject(t,!0),o.isEmpty()===!1){i=new x.Box3Helper(o);const r=i.material;r.userData.object=t,r.depthTest=!1,r.transparent=!0}else return}s.add(i),this.helpers[e]=i}}remove(t){const e=t.uuid,{scene:s}=this.options;if(this.helpers[e]!==void 0){const i=this.helpers[e];s.remove(i),delete this.helpers[e],i instanceof x.Box3Helper&&i.dispose()}}removeAll(){Object.keys(this.helpers).forEach(t=>{this.remove({uuid:t})}),this.helpers={}}removeAllExcludeScene(){Object.keys(this.helpers).forEach(t=>{this.helpers[t]instanceof x.AxesHelper||this.remove({uuid:t})})}update(){Object.values(this.helpers).forEach(t=>{if(t.update&&t.update(),t instanceof x.Box3Helper){const e=t.material,{object:s}=e.userData;s&&t.box.setFromObject(s,!0)}})}dispose(){this.helpers={}}}class pe{constructor(t){this.autoRotateSpeed=0,this.options=t;const{camera:e,controlsParams:s,customControl:i}=t,{domElement:o}=s;if(i){const r=new i(e,o);r.enableDamping=!0,r.dampingFactor=.063,r.autoRotate=!1,r.autoRotateSpeed=-60,r.enableZoom=!0,r.zoomSpeed=.2,this.controls=r}else Z.install({THREE:x}),this.cameraControls=new Z(e,o)}addCameraControls2(t){const{controlsParams:e}=this.options,{domElement:s}=e;this.cameraControls2=new Z(t,s),this.cameraControls2.addEventListener("update",()=>{this.cameraControls.enabled=!1}),this.cameraControls2.addEventListener("sleep",()=>{this.cameraControls.enabled=!0})}enable(){this.controls?this.controls.enabled=!0:this.cameraControls&&(this.cameraControls.enabled=!0,this.cameraControls2&&(this.cameraControls2.enabled=!0))}disable(){this.controls?this.controls.enabled=!1:this.cameraControls&&(this.cameraControls.enabled=!1,this.cameraControls2&&(this.cameraControls2.enabled=!1))}update(t){var e,s,i;(e=this.controls)==null||e.update(),(s=this.cameraControls)==null||s.update(t),(i=this.cameraControls2)==null||i.update(t),this.autoRotateSpeed&&this.cameraControls&&(this.cameraControls.azimuthAngle+=this.autoRotateSpeed*t*x.MathUtils.DEG2RAD)}dispose(){var t,e,s;(t=this.controls)==null||t.dispose(),(e=this.cameraControls)==null||e.dispose(),(s=this.cameraControls2)==null||s.dispose()}}class ue{constructor(t){this.event=new Ft.eventsExports.EventEmitter;const{renderer:e,scene:s,camera:i}=t,o=new te.TransformControls(i,e.domElement);s.add(o),this.controls=o,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 i=this.controls;i.addEventListener("change",()=>{const o=i.object;o!==void 0&&this.event.emit("change",o)}),i.addEventListener("mouseDown",()=>{const o=i.object;t=o.position.clone(),e=o.rotation.clone(),s=o.scale.clone(),this.event.emit("mouseDown",o)}),i.addEventListener("mouseUp",()=>{const o=i.object;if(o!==void 0)switch(i.getMode()){case"translate":t.equals(o.position)||this.event.emit("translate",o,o.position,t);break;case"rotate":e.equals(o.rotation)||this.event.emit("rotate",o,o.rotation,e);break;case"scale":s.equals(o.scale)||this.event.emit("scale",o,o.scale,s);break}this.event.emit("mouseUp")})}dispose(){var t;this.event.removeAllListeners(),(t=this.controls)==null||t.dispose()}}const bt={zIndex:"auto"};class fe{constructor(t){this.container=t}addRenderer(t,e){const s=e.container||this.container,i=s.offsetWidth,o=s.offsetHeight,r=t==="css2d"?new se.CSS2DRenderer:new ee.CSS3DRenderer;r.domElement.style.position="absolute",r.domElement.style.top="0",r.domElement.style.pointerEvents="none",r.domElement.style.zIndex=e.zIndex,r.setSize(i,o),s.appendChild(r.domElement),t==="css2d"?this.css2Drenderer=r:t==="css3d"&&(this.css3Drenderer=r)}setSize(t,e){var s,i;(s=this.css2Drenderer)==null||s.setSize(t,e),(i=this.css3Drenderer)==null||i.setSize(t,e)}render(t,e){var s,i;(s=this.css2Drenderer)==null||s.render(t,e),(i=this.css3Drenderer)==null||i.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}}const Mt=["encodings_fragment","colorspace_fragment"];class ge extends tt.ShaderMaterial{constructor(){super({uniforms:{inputBuffer:new tt.Uniform(null),ratio:new tt.Uniform(1)},fragmentShader:`
1
+ "use strict";var Nt=Object.defineProperty,qt=Object.defineProperties;var Xt=Object.getOwnPropertyDescriptors;var it=Object.getOwnPropertySymbols;var Ct=Object.prototype.hasOwnProperty,Ot=Object.prototype.propertyIsEnumerable;var yt=(d,t,e)=>t in d?Nt(d,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):d[t]=e,I=(d,t)=>{for(var e in t||(t={}))Ct.call(t,e)&&yt(d,e,t[e]);if(it)for(var e of it(t))Ot.call(t,e)&&yt(d,e,t[e]);return d},ot=(d,t)=>qt(d,Xt(t));var Tt=(d,t)=>{var e={};for(var s in d)Ct.call(d,s)&&t.indexOf(s)<0&&(e[s]=d[s]);if(d!=null&&it)for(var s of it(d))t.indexOf(s)<0&&Ot.call(d,s)&&(e[s]=d[s]);return e};Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const tt=require("three"),Kt=require("@tweenjs/tween.js"),Ft=require("./events.js"),jt=require("deepmerge"),Gt=require("three/examples/jsm/libs/stats.module"),Qt=require("lil-gui"),Wt=require("./colorCorrection.js"),Jt=require("./disposeMesh.js");require("idb-keyval");require("esus-lite");require("d3-geo");const vt=require("./MeshLineMaterial.js"),$t=require("three/examples/jsm/helpers/RectAreaLightHelper"),te=require("three/examples/jsm/controls/TransformControls"),ee=require("three/examples/jsm/renderers/CSS3DRenderer"),se=require("three/examples/jsm/renderers/CSS2DRenderer"),b=require("postprocessing"),ie=require("./isPlainObject.js"),oe=require("./BaseObject.js");function It(d){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(d){for(const e in d)if(e!=="default"){const s=Object.getOwnPropertyDescriptor(d,e);Object.defineProperty(t,e,s.get?s:{enumerable:!0,get:()=>d[e]})}}return t.default=d,Object.freeze(t)}const x=It(tt),Pt=It(Kt),A={LEFT:1,RIGHT:2,MIDDLE:4},n=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}),N={NONE:0,IN:1,OUT:-1};function V(d){return d.isPerspectiveCamera}function B(d){return d.isOrthographicCamera}const q=Math.PI*2,xt=Math.PI/2,Ht=1e-5,j=Math.PI/180;function F(d,t,e){return Math.max(t,Math.min(e,d))}function U(d,t=Ht){return Math.abs(d)<t}function w(d,t,e=Ht){return U(d-t,e)}function Dt(d,t){return Math.round(d/t)*t}function G(d){return isFinite(d)?d:d<0?-Number.MAX_VALUE:Number.MAX_VALUE}function Q(d){return Math.abs(d)<Number.MAX_VALUE?d:d*(1/0)}function rt(d,t,e,s,i=1/0,o){s=Math.max(1e-4,s);const r=2/s,a=r*o,h=1/(1+a+.48*a*a+.235*a*a*a);let c=d-t;const p=t,m=i*s;c=F(c,-m,m),t=d-c;const E=(e.value+r*c)*o;e.value=(e.value-r*E)*h;let u=t+(c+E)*h;return p-d>0==u>p&&(u=p,e.value=(u-p)/o),u}function wt(d,t,e,s,i=1/0,o,r){s=Math.max(1e-4,s);const a=2/s,h=a*o,c=1/(1+h+.48*h*h+.235*h*h*h);let p=t.x,m=t.y,E=t.z,u=d.x-p,D=d.y-m,g=d.z-E;const S=p,l=m,_=E,y=i*s,f=y*y,v=u*u+D*D+g*g;if(v>f){const mt=Math.sqrt(v);u=u/mt*y,D=D/mt*y,g=g/mt*y}p=d.x-u,m=d.y-D,E=d.z-g;const O=(e.x+a*u)*o,L=(e.y+a*D)*o,R=(e.z+a*g)*o;e.x=(e.x-a*O)*c,e.y=(e.y-a*L)*c,e.z=(e.z-a*R)*c,r.x=p+(u+O)*c,r.y=m+(D+L)*c,r.z=E+(g+R)*c;const et=S-d.x,st=l-d.y,Bt=_-d.z,Vt=r.x-S,Yt=r.y-l,Zt=r.z-_;return et*Vt+st*Yt+Bt*Zt>0&&(r.x=S,r.y=l,r.z=_,e.x=(r.x-S)/o,e.y=(r.y-l)/o,e.z=(r.z-_)/o),r}function _t(d,t){t.set(0,0),d.forEach(e=>{t.x+=e.clientX,t.y+=e.clientY}),t.x/=d.length,t.y/=d.length}function pt(d,t){return B(d)?(console.warn(`${t} is not supported in OrthographicCamera`),!0):!1}class re{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 i=this._listeners[t];if(i!==void 0){const o=i.indexOf(e);o!==-1&&i.splice(o,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 i=s.slice(0);for(let o=0,r=i.length;o<r;o++)i[o].call(this,t)}}}const nt=1/8,ne=/Mac/.test(navigator.platform);let C,St,at,ut,M,T,P,X,W,H,k,Y,Ut,Lt,z,J,K,At,ft,Rt,gt,Et,ht;class Z extends re{static install(t){C=t.THREE,St=Object.freeze(new C.Vector3(0,0,0)),at=Object.freeze(new C.Vector3(0,1,0)),ut=Object.freeze(new C.Vector3(0,0,1)),M=new C.Vector2,T=new C.Vector3,P=new C.Vector3,X=new C.Vector3,W=new C.Vector3,H=new C.Vector3,k=new C.Vector3,Y=new C.Vector3,Ut=new C.Vector3,Lt=new C.Vector3,z=new C.Spherical,J=new C.Spherical,K=new C.Box3,At=new C.Box3,ft=new C.Sphere,Rt=new C.Quaternion,gt=new C.Quaternion,Et=new C.Matrix4,ht=new C.Raycaster}static get ACTION(){return n}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=n.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=N.NONE,this._thetaVelocity={value:0},this._phiVelocity={value:0},this._radiusVelocity={value:0},this._targetVelocity=new C.Vector3,this._focalOffsetVelocity=new C.Vector3,this._zoomVelocity={value:0},this._truckInternal=(l,_,y)=>{let f,v;if(V(this._camera)){const O=T.copy(this._camera.position).sub(this._target),L=this._camera.getEffectiveFOV()*j,R=O.length()*Math.tan(L*.5);f=this.truckSpeed*l*R/this._elementRect.height,v=this.truckSpeed*_*R/this._elementRect.height}else if(B(this._camera)){const O=this._camera;f=l*(O.right-O.left)/O.zoom/this._elementRect.width,v=_*(O.top-O.bottom)/O.zoom/this._elementRect.height}else return;this.verticalDragToForward?(y?this.setFocalOffset(this._focalOffsetEnd.x+f,this._focalOffsetEnd.y,this._focalOffsetEnd.z,!0):this.truck(f,0,!0),this.forward(-v,!0)):y?this.setFocalOffset(this._focalOffsetEnd.x+f,this._focalOffsetEnd.y+v,this._focalOffsetEnd.z,!0):this.truck(f,v,!0)},this._rotateInternal=(l,_)=>{const y=q*this.azimuthRotateSpeed*l/this._elementRect.height,f=q*this.polarRotateSpeed*_/this._elementRect.height;this.rotate(y,f,!0)},this._dollyInternal=(l,_,y)=>{const f=Math.pow(.95,-l*this.dollySpeed),v=this._sphericalEnd.radius,O=this._sphericalEnd.radius*f,L=F(O,this.minDistance,this.maxDistance),R=L-O;this.infinityDolly&&this.dollyToCursor?this._dollyToNoClamp(O,!0):this.infinityDolly&&!this.dollyToCursor?(this.dollyInFixed(R,!0),this._dollyToNoClamp(L,!0)):this._dollyToNoClamp(L,!0),this.dollyToCursor&&(this._changedDolly+=(this.infinityDolly?O:L)-v,this._dollyControlCoord.set(_,y)),this._lastDollyDirection=Math.sign(-l)},this._zoomInternal=(l,_,y)=>{const f=Math.pow(.95,l*this.dollySpeed),v=this._zoom,O=this._zoom*f;this.zoomTo(O,!0),this.dollyToCursor&&(this._changedZoom+=O-v,this._dollyControlCoord.set(_,y))},typeof C=="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 C.Quaternion().setFromUnitVectors(this._camera.up,at),this._yAxisUpSpaceInverse=this._yAxisUpSpace.clone().invert(),this._state=n.NONE,this._target=new C.Vector3,this._targetEnd=this._target.clone(),this._focalOffset=new C.Vector3,this._focalOffsetEnd=this._focalOffset.clone(),this._spherical=new C.Spherical().setFromVector3(T.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 C.Vector3,new C.Vector3,new C.Vector3,new C.Vector3],this._updateNearPlaneCorners(),this._boundary=new C.Box3(new C.Vector3(-1/0,-1/0,-1/0),new C.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 C.Vector2,this.mouseButtons={left:n.ROTATE,middle:n.DOLLY,right:n.TRUCK,wheel:V(this._camera)?n.DOLLY:B(this._camera)?n.ZOOM:n.NONE},this.touches={one:n.TOUCH_ROTATE,two:V(this._camera)?n.TOUCH_DOLLY_TRUCK:B(this._camera)?n.TOUCH_ZOOM_TRUCK:n.NONE,three:n.TOUCH_TRUCK};const s=new C.Vector2,i=new C.Vector2,o=new C.Vector2,r=l=>{if(!this._enabled||!this._domElement)return;if(this._interactiveArea.left!==0||this._interactiveArea.top!==0||this._interactiveArea.width!==1||this._interactiveArea.height!==1){const f=this._domElement.getBoundingClientRect(),v=(l.clientX-f.left)/(f.right-f.left),O=(l.clientY-f.top)/(f.bottom-f.top);if(v<this._interactiveArea.left||v>this._interactiveArea.right||O<this._interactiveArea.top||O>this._interactiveArea.bottom)return}const _=l.pointerType!=="mouse"?null:(l.buttons&A.LEFT)===A.LEFT?A.LEFT:(l.buttons&A.MIDDLE)===A.MIDDLE?A.MIDDLE:(l.buttons&A.RIGHT)===A.RIGHT?A.RIGHT:null;if(_!==null){const f=this._findPointerByMouseButton(_);f&&this._disposePointer(f)}if((l.buttons&A.LEFT)===A.LEFT&&this._lockedPointer)return;const y={pointerId:l.pointerId,clientX:l.clientX,clientY:l.clientY,deltaX:0,deltaY:0,mouseButton:_};this._activePointers.push(y),this._domElement.ownerDocument.removeEventListener("pointermove",a,{passive:!1}),this._domElement.ownerDocument.removeEventListener("pointerup",h),this._domElement.ownerDocument.addEventListener("pointermove",a,{passive:!1}),this._domElement.ownerDocument.addEventListener("pointerup",h),this._isDragging=!0,E(l)},a=l=>{l.cancelable&&l.preventDefault();const _=l.pointerId,y=this._lockedPointer||this._findPointerById(_);if(y){if(y.clientX=l.clientX,y.clientY=l.clientY,y.deltaX=l.movementX,y.deltaY=l.movementY,this._state=0,l.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&&(l.buttons&A.LEFT)===A.LEFT)&&(this._state=this._state|this.mouseButtons.left),this._isDragging&&(l.buttons&A.MIDDLE)===A.MIDDLE&&(this._state=this._state|this.mouseButtons.middle),this._isDragging&&(l.buttons&A.RIGHT)===A.RIGHT&&(this._state=this._state|this.mouseButtons.right);u()}},h=l=>{const _=this._findPointerById(l.pointerId);if(!(_&&_===this._lockedPointer)){if(_&&this._disposePointer(_),l.pointerType==="touch")switch(this._activePointers.length){case 0:this._state=n.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=n.NONE;D()}};let c=-1;const p=l=>{if(!this._domElement||!this._enabled||this.mouseButtons.wheel===n.NONE)return;if(this._interactiveArea.left!==0||this._interactiveArea.top!==0||this._interactiveArea.width!==1||this._interactiveArea.height!==1){const O=this._domElement.getBoundingClientRect(),L=(l.clientX-O.left)/(O.right-O.left),R=(l.clientY-O.top)/(O.bottom-O.top);if(L<this._interactiveArea.left||L>this._interactiveArea.right||R<this._interactiveArea.top||R>this._interactiveArea.bottom)return}if(l.preventDefault(),this.dollyToCursor||this.mouseButtons.wheel===n.ROTATE||this.mouseButtons.wheel===n.TRUCK){const O=performance.now();c-O<1e3&&this._getClientRect(this._elementRect),c=O}const _=ne?-1:-3,y=l.deltaMode===1?l.deltaY/_:l.deltaY/(_*10),f=this.dollyToCursor?(l.clientX-this._elementRect.x)/this._elementRect.width*2-1:0,v=this.dollyToCursor?(l.clientY-this._elementRect.y)/this._elementRect.height*-2+1:0;switch(this.mouseButtons.wheel){case n.ROTATE:{this._rotateInternal(l.deltaX,l.deltaY),this._isUserControllingRotate=!0;break}case n.TRUCK:{this._truckInternal(l.deltaX,l.deltaY,!1),this._isUserControllingTruck=!0;break}case n.OFFSET:{this._truckInternal(l.deltaX,l.deltaY,!0),this._isUserControllingOffset=!0;break}case n.DOLLY:{this._dollyInternal(-y,f,v),this._isUserControllingDolly=!0;break}case n.ZOOM:{this._zoomInternal(-y,f,v),this._isUserControllingZoom=!0;break}}this.dispatchEvent({type:"control"})},m=l=>{if(!(!this._domElement||!this._enabled)){if(this.mouseButtons.right===Z.ACTION.NONE){const _=l instanceof PointerEvent?l.pointerId:0,y=this._findPointerById(_);y&&this._disposePointer(y),this._domElement.ownerDocument.removeEventListener("pointermove",a,{passive:!1}),this._domElement.ownerDocument.removeEventListener("pointerup",h);return}l.preventDefault()}},E=l=>{if(!this._enabled)return;if(_t(this._activePointers,M),this._getClientRect(this._elementRect),s.copy(M),i.copy(M),this._activePointers.length>=2){const y=M.x-this._activePointers[1].clientX,f=M.y-this._activePointers[1].clientY,v=Math.sqrt(y*y+f*f);o.set(0,v);const O=(this._activePointers[0].clientX+this._activePointers[1].clientX)*.5,L=(this._activePointers[0].clientY+this._activePointers[1].clientY)*.5;i.set(O,L)}if(this._state=0,!l)this._lockedPointer&&(this._state=this._state|this.mouseButtons.left);else if("pointerType"in l&&l.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&&(l.buttons&A.LEFT)===A.LEFT&&(this._state=this._state|this.mouseButtons.left),(l.buttons&A.MIDDLE)===A.MIDDLE&&(this._state=this._state|this.mouseButtons.middle),(l.buttons&A.RIGHT)===A.RIGHT&&(this._state=this._state|this.mouseButtons.right);((this._state&n.ROTATE)===n.ROTATE||(this._state&n.TOUCH_ROTATE)===n.TOUCH_ROTATE||(this._state&n.TOUCH_DOLLY_ROTATE)===n.TOUCH_DOLLY_ROTATE||(this._state&n.TOUCH_ZOOM_ROTATE)===n.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&n.TRUCK)===n.TRUCK||(this._state&n.TOUCH_TRUCK)===n.TOUCH_TRUCK||(this._state&n.TOUCH_DOLLY_TRUCK)===n.TOUCH_DOLLY_TRUCK||(this._state&n.TOUCH_ZOOM_TRUCK)===n.TOUCH_ZOOM_TRUCK)&&(this._targetEnd.copy(this._target),this._targetVelocity.set(0,0,0)),((this._state&n.DOLLY)===n.DOLLY||(this._state&n.TOUCH_DOLLY)===n.TOUCH_DOLLY||(this._state&n.TOUCH_DOLLY_TRUCK)===n.TOUCH_DOLLY_TRUCK||(this._state&n.TOUCH_DOLLY_OFFSET)===n.TOUCH_DOLLY_OFFSET||(this._state&n.TOUCH_DOLLY_ROTATE)===n.TOUCH_DOLLY_ROTATE)&&(this._sphericalEnd.radius=this._spherical.radius,this._radiusVelocity.value=0),((this._state&n.ZOOM)===n.ZOOM||(this._state&n.TOUCH_ZOOM)===n.TOUCH_ZOOM||(this._state&n.TOUCH_ZOOM_TRUCK)===n.TOUCH_ZOOM_TRUCK||(this._state&n.TOUCH_ZOOM_OFFSET)===n.TOUCH_ZOOM_OFFSET||(this._state&n.TOUCH_ZOOM_ROTATE)===n.TOUCH_ZOOM_ROTATE)&&(this._zoomEnd=this._zoom,this._zoomVelocity.value=0),((this._state&n.OFFSET)===n.OFFSET||(this._state&n.TOUCH_OFFSET)===n.TOUCH_OFFSET||(this._state&n.TOUCH_DOLLY_OFFSET)===n.TOUCH_DOLLY_OFFSET||(this._state&n.TOUCH_ZOOM_OFFSET)===n.TOUCH_ZOOM_OFFSET)&&(this._focalOffsetEnd.copy(this._focalOffset),this._focalOffsetVelocity.set(0,0,0)),this.dispatchEvent({type:"controlstart"})},u=()=>{if(!this._enabled||!this._dragNeedsUpdate)return;this._dragNeedsUpdate=!1,_t(this._activePointers,M);const _=this._domElement&&this._domElement.ownerDocument.pointerLockElement===this._domElement?this._lockedPointer||this._activePointers[0]:null,y=_?-_.deltaX:i.x-M.x,f=_?-_.deltaY:i.y-M.y;if(i.copy(M),((this._state&n.ROTATE)===n.ROTATE||(this._state&n.TOUCH_ROTATE)===n.TOUCH_ROTATE||(this._state&n.TOUCH_DOLLY_ROTATE)===n.TOUCH_DOLLY_ROTATE||(this._state&n.TOUCH_ZOOM_ROTATE)===n.TOUCH_ZOOM_ROTATE)&&(this._rotateInternal(y,f),this._isUserControllingRotate=!0),(this._state&n.DOLLY)===n.DOLLY||(this._state&n.ZOOM)===n.ZOOM){const v=this.dollyToCursor?(s.x-this._elementRect.x)/this._elementRect.width*2-1:0,O=this.dollyToCursor?(s.y-this._elementRect.y)/this._elementRect.height*-2+1:0,L=this.dollyDragInverted?-1:1;(this._state&n.DOLLY)===n.DOLLY?(this._dollyInternal(L*f*nt,v,O),this._isUserControllingDolly=!0):(this._zoomInternal(L*f*nt,v,O),this._isUserControllingZoom=!0)}if((this._state&n.TOUCH_DOLLY)===n.TOUCH_DOLLY||(this._state&n.TOUCH_ZOOM)===n.TOUCH_ZOOM||(this._state&n.TOUCH_DOLLY_TRUCK)===n.TOUCH_DOLLY_TRUCK||(this._state&n.TOUCH_ZOOM_TRUCK)===n.TOUCH_ZOOM_TRUCK||(this._state&n.TOUCH_DOLLY_OFFSET)===n.TOUCH_DOLLY_OFFSET||(this._state&n.TOUCH_ZOOM_OFFSET)===n.TOUCH_ZOOM_OFFSET||(this._state&n.TOUCH_DOLLY_ROTATE)===n.TOUCH_DOLLY_ROTATE||(this._state&n.TOUCH_ZOOM_ROTATE)===n.TOUCH_ZOOM_ROTATE){const v=M.x-this._activePointers[1].clientX,O=M.y-this._activePointers[1].clientY,L=Math.sqrt(v*v+O*O),R=o.y-L;o.set(0,L);const et=this.dollyToCursor?(i.x-this._elementRect.x)/this._elementRect.width*2-1:0,st=this.dollyToCursor?(i.y-this._elementRect.y)/this._elementRect.height*-2+1:0;(this._state&n.TOUCH_DOLLY)===n.TOUCH_DOLLY||(this._state&n.TOUCH_DOLLY_ROTATE)===n.TOUCH_DOLLY_ROTATE||(this._state&n.TOUCH_DOLLY_TRUCK)===n.TOUCH_DOLLY_TRUCK||(this._state&n.TOUCH_DOLLY_OFFSET)===n.TOUCH_DOLLY_OFFSET?(this._dollyInternal(R*nt,et,st),this._isUserControllingDolly=!0):(this._zoomInternal(R*nt,et,st),this._isUserControllingZoom=!0)}((this._state&n.TRUCK)===n.TRUCK||(this._state&n.TOUCH_TRUCK)===n.TOUCH_TRUCK||(this._state&n.TOUCH_DOLLY_TRUCK)===n.TOUCH_DOLLY_TRUCK||(this._state&n.TOUCH_ZOOM_TRUCK)===n.TOUCH_ZOOM_TRUCK)&&(this._truckInternal(y,f,!1),this._isUserControllingTruck=!0),((this._state&n.OFFSET)===n.OFFSET||(this._state&n.TOUCH_OFFSET)===n.TOUCH_OFFSET||(this._state&n.TOUCH_DOLLY_OFFSET)===n.TOUCH_DOLLY_OFFSET||(this._state&n.TOUCH_ZOOM_OFFSET)===n.TOUCH_ZOOM_OFFSET)&&(this._truckInternal(y,f,!0),this._isUserControllingOffset=!0),this.dispatchEvent({type:"control"})},D=()=>{_t(this._activePointers,M),i.copy(M),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",h),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",h),this._domElement.requestPointerLock(),this._domElement.ownerDocument.addEventListener("pointerlockchange",g),this._domElement.ownerDocument.addEventListener("pointerlockerror",S),this._domElement.ownerDocument.addEventListener("pointermove",a,{passive:!1}),this._domElement.ownerDocument.addEventListener("pointerup",h),E())},this.unlockPointer=()=>{var l,_,y;this._lockedPointer!==null&&(this._disposePointer(this._lockedPointer),this._lockedPointer=null),(l=this._domElement)===null||l===void 0||l.ownerDocument.exitPointerLock(),(_=this._domElement)===null||_===void 0||_.ownerDocument.removeEventListener("pointerlockchange",g),(y=this._domElement)===null||y===void 0||y.ownerDocument.removeEventListener("pointerlockerror",S),this.cancel()};const g=()=>{this._domElement&&this._domElement.ownerDocument.pointerLockElement===this._domElement||this.unlockPointer()},S=()=>{this.unlockPointer()};this._addAllEventListeners=l=>{this._domElement=l,this._domElement.style.touchAction="none",this._domElement.style.userSelect="none",this._domElement.style.webkitUserSelect="none",this._domElement.addEventListener("pointerdown",r),this._domElement.addEventListener("pointercancel",h),this._domElement.addEventListener("wheel",p,{passive:!1}),this._domElement.addEventListener("contextmenu",m)},this._removeAllEventListeners=()=>{this._domElement&&(this._domElement.style.touchAction="",this._domElement.style.userSelect="",this._domElement.style.webkitUserSelect="",this._domElement.removeEventListener("pointerdown",r),this._domElement.removeEventListener("pointercancel",h),this._domElement.removeEventListener("wheel",p,{passive:!1}),this._domElement.removeEventListener("contextmenu",m),this._domElement.ownerDocument.removeEventListener("pointermove",a,{passive:!1}),this._domElement.ownerDocument.removeEventListener("pointerup",h),this._domElement.ownerDocument.removeEventListener("pointerlockchange",g),this._domElement.ownerDocument.removeEventListener("pointerlockerror",S))},this.cancel=()=>{this._state!==n.NONE&&(this._state=n.NONE,this._activePointers.length=0,D())},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 i=F(t,this.minAzimuthAngle,this.maxAzimuthAngle),o=F(e,this.minPolarAngle,this.maxPolarAngle);this._sphericalEnd.theta=i,this._sphericalEnd.phi=o,this._sphericalEnd.makeSafe(),this._needsUpdate=!0,s||(this._spherical.theta=this._sphericalEnd.theta,this._spherical.phi=this._sphericalEnd.phi);const r=!s||w(this._spherical.theta,this._sphericalEnd.theta,this.restThreshold)&&w(this._spherical.phi,this._sphericalEnd.phi,this.restThreshold);return this._createOnRestPromise(r)}dolly(t,e=!1){return this.dollyTo(this._sphericalEnd.radius-t,e)}dollyTo(t,e=!1){return this._isUserControllingDolly=!1,this._lastDollyDirection=N.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 r=this._collisionTest(),a=w(r,this._spherical.radius);if(!(s>t)&&a)return Promise.resolve();this._sphericalEnd.radius=Math.min(t,r)}else this._sphericalEnd.radius=t;this._needsUpdate=!0,e||(this._spherical.radius=this._sphericalEnd.radius);const o=!e||w(this._spherical.radius,this._sphericalEnd.radius,this.restThreshold);return this._createOnRestPromise(o)}dollyInFixed(t,e=!1){this._targetEnd.add(this._getCameraDirection(W).multiplyScalar(t)),e||this._target.copy(this._targetEnd);const s=!e||w(this._target.x,this._targetEnd.x,this.restThreshold)&&w(this._target.y,this._targetEnd.y,this.restThreshold)&&w(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||w(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),k.setFromMatrixColumn(this._camera.matrix,1),H.multiplyScalar(t),k.multiplyScalar(-e);const i=T.copy(H).add(k),o=P.copy(this._targetEnd).add(i);return this.moveTo(o.x,o.y,o.z,s)}forward(t,e=!1){T.setFromMatrixColumn(this._camera.matrix,0),T.crossVectors(this._camera.up,T),T.multiplyScalar(t);const s=P.copy(this._targetEnd).add(T);return this.moveTo(s.x,s.y,s.z,e)}elevate(t,e=!1){return T.copy(this._camera.up).multiplyScalar(t),this.moveTo(this._targetEnd.x+T.x,this._targetEnd.y+T.y,this._targetEnd.z+T.z,e)}moveTo(t,e,s,i=!1){this._isUserControllingTruck=!1;const o=T.set(t,e,s).sub(this._targetEnd);this._encloseToBoundary(this._targetEnd,o,this.boundaryFriction),this._needsUpdate=!0,i||this._target.copy(this._targetEnd);const r=!i||w(this._target.x,this._targetEnd.x,this.restThreshold)&&w(this._target.y,this._targetEnd.y,this.restThreshold)&&w(this._target.z,this._targetEnd.z,this.restThreshold);return this._createOnRestPromise(r)}lookInDirectionOf(t,e,s,i=!1){const a=T.set(t,e,s).sub(this._targetEnd).normalize().multiplyScalar(-this._sphericalEnd.radius).add(this._targetEnd);return this.setPosition(a.x,a.y,a.z,i)}fitToBox(t,e,{cover:s=!1,paddingLeft:i=0,paddingRight:o=0,paddingBottom:r=0,paddingTop:a=0}={}){const h=[],c=t.isBox3?K.copy(t):K.setFromObject(t);c.isEmpty()&&(console.warn("camera-controls: fitTo() cannot be used with an empty box. Aborting"),Promise.resolve());const p=Dt(this._sphericalEnd.theta,xt),m=Dt(this._sphericalEnd.phi,xt);h.push(this.rotateTo(p,m,e));const E=T.setFromSpherical(this._sphericalEnd).normalize(),u=Rt.setFromUnitVectors(E,ut),D=w(Math.abs(E.y),1);D&&u.multiply(gt.setFromAxisAngle(at,p)),u.multiply(this._yAxisUpSpaceInverse);const g=At.makeEmpty();P.copy(c.min).applyQuaternion(u),g.expandByPoint(P),P.copy(c.min).setX(c.max.x).applyQuaternion(u),g.expandByPoint(P),P.copy(c.min).setY(c.max.y).applyQuaternion(u),g.expandByPoint(P),P.copy(c.max).setZ(c.min.z).applyQuaternion(u),g.expandByPoint(P),P.copy(c.min).setZ(c.max.z).applyQuaternion(u),g.expandByPoint(P),P.copy(c.max).setY(c.min.y).applyQuaternion(u),g.expandByPoint(P),P.copy(c.max).setX(c.min.x).applyQuaternion(u),g.expandByPoint(P),P.copy(c.max).applyQuaternion(u),g.expandByPoint(P),g.min.x-=i,g.min.y-=r,g.max.x+=o,g.max.y+=a,u.setFromUnitVectors(ut,E),D&&u.premultiply(gt.invert()),u.premultiply(this._yAxisUpSpace);const S=g.getSize(T),l=g.getCenter(P).applyQuaternion(u);if(V(this._camera)){const _=this.getDistanceToFitBox(S.x,S.y,S.z,s);h.push(this.moveTo(l.x,l.y,l.z,e)),h.push(this.dollyTo(_,e)),h.push(this.setFocalOffset(0,0,0,e))}else if(B(this._camera)){const _=this._camera,y=_.right-_.left,f=_.top-_.bottom,v=s?Math.max(y/S.x,f/S.y):Math.min(y/S.x,f/S.y);h.push(this.moveTo(l.x,l.y,l.z,e)),h.push(this.zoomTo(v,e)),h.push(this.setFocalOffset(0,0,0,e))}return Promise.all(h)}fitToSphere(t,e){const s=[],o="isObject3D"in t?Z.createBoundingSphere(t,ft):ft.copy(t);if(s.push(this.moveTo(o.center.x,o.center.y,o.center.z,e)),V(this._camera)){const r=this.getDistanceToFitSphere(o.radius);s.push(this.dollyTo(r,e))}else if(B(this._camera)){const r=this._camera.right-this._camera.left,a=this._camera.top-this._camera.bottom,h=2*o.radius,c=Math.min(r/h,a/h);s.push(this.zoomTo(c,e))}return s.push(this.setFocalOffset(0,0,0,e)),Promise.all(s)}setLookAt(t,e,s,i,o,r,a=!1){this._isUserControllingRotate=!1,this._isUserControllingDolly=!1,this._isUserControllingTruck=!1,this._lastDollyDirection=N.NONE,this._changedDolly=0;const h=P.set(i,o,r),c=T.set(t,e,s);this._targetEnd.copy(h),this._sphericalEnd.setFromVector3(c.sub(h).applyQuaternion(this._yAxisUpSpace)),this.normalizeRotations(),this._needsUpdate=!0,a||(this._target.copy(this._targetEnd),this._spherical.copy(this._sphericalEnd));const p=!a||w(this._target.x,this._targetEnd.x,this.restThreshold)&&w(this._target.y,this._targetEnd.y,this.restThreshold)&&w(this._target.z,this._targetEnd.z,this.restThreshold)&&w(this._spherical.theta,this._sphericalEnd.theta,this.restThreshold)&&w(this._spherical.phi,this._sphericalEnd.phi,this.restThreshold)&&w(this._spherical.radius,this._sphericalEnd.radius,this.restThreshold);return this._createOnRestPromise(p)}lerpLookAt(t,e,s,i,o,r,a,h,c,p,m,E,u,D=!1){this._isUserControllingRotate=!1,this._isUserControllingDolly=!1,this._isUserControllingTruck=!1,this._lastDollyDirection=N.NONE,this._changedDolly=0;const g=T.set(i,o,r),S=P.set(t,e,s);z.setFromVector3(S.sub(g).applyQuaternion(this._yAxisUpSpace));const l=X.set(p,m,E),_=P.set(a,h,c);J.setFromVector3(_.sub(l).applyQuaternion(this._yAxisUpSpace)),this._targetEnd.copy(g.lerp(l,u));const y=J.theta-z.theta,f=J.phi-z.phi,v=J.radius-z.radius;this._sphericalEnd.set(z.radius+v*u,z.phi+f*u,z.theta+y*u),this.normalizeRotations(),this._needsUpdate=!0,D||(this._target.copy(this._targetEnd),this._spherical.copy(this._sphericalEnd));const O=!D||w(this._target.x,this._targetEnd.x,this.restThreshold)&&w(this._target.y,this._targetEnd.y,this.restThreshold)&&w(this._target.z,this._targetEnd.z,this.restThreshold)&&w(this._spherical.theta,this._sphericalEnd.theta,this.restThreshold)&&w(this._spherical.phi,this._sphericalEnd.phi,this.restThreshold)&&w(this._spherical.radius,this._sphericalEnd.radius,this.restThreshold);return this._createOnRestPromise(O)}setPosition(t,e,s,i=!1){return this.setLookAt(t,e,s,this._targetEnd.x,this._targetEnd.y,this._targetEnd.z,i)}setTarget(t,e,s,i=!1){const o=this.getPosition(T),r=this.setLookAt(o.x,o.y,o.z,t,e,s,i);return this._sphericalEnd.phi=F(this._sphericalEnd.phi,this.minPolarAngle,this.maxPolarAngle),r}setFocalOffset(t,e,s,i=!1){this._isUserControllingOffset=!1,this._focalOffsetEnd.set(t,e,s),this._needsUpdate=!0,i||this._focalOffset.copy(this._focalOffsetEnd);const o=!i||w(this._focalOffset.x,this._focalOffsetEnd.x,this.restThreshold)&&w(this._focalOffset.y,this._focalOffsetEnd.y,this.restThreshold)&&w(this._focalOffset.z,this._focalOffsetEnd.z,this.restThreshold);return this._createOnRestPromise(o)}setOrbitPoint(t,e,s){this._camera.updateMatrixWorld(),H.setFromMatrixColumn(this._camera.matrixWorldInverse,0),k.setFromMatrixColumn(this._camera.matrixWorldInverse,1),Y.setFromMatrixColumn(this._camera.matrixWorldInverse,2);const i=T.set(t,e,s),o=i.distanceTo(this._camera.position),r=i.sub(this._camera.position);H.multiplyScalar(r.x),k.multiplyScalar(r.y),Y.multiplyScalar(r.z),T.copy(H).add(k).add(Y),T.z=T.z+o,this.dollyTo(o,!1),this.setFocalOffset(-T.x,T.y,-T.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,i){if(t===null){this._viewport=null;return}this._viewport=this._viewport||new C.Vector4,typeof t=="number"?this._viewport.set(t,e,s,i):this._viewport.copy(t)}getDistanceToFitBox(t,e,s,i=!1){if(pt(this._camera,"getDistanceToFitBox"))return this._spherical.radius;const o=t/e,r=this._camera.getEffectiveFOV()*j,a=this._camera.aspect;return((i?o>a:o<a)?e:t/a)*.5/Math.tan(r*.5)+s*.5}getDistanceToFitSphere(t){if(pt(this._camera,"getDistanceToFitSphere"))return this._spherical.radius;const e=this._camera.getEffectiveFOV()*j,s=Math.atan(Math.tan(e*.5)*this._camera.aspect)*2,i=1<this._camera.aspect?e:s;return t/Math.sin(i*.5)}getTarget(t,e=!0){return(t&&t.isVector3?t:new C.Vector3).copy(e?this._targetEnd:this._target)}getPosition(t,e=!0){return(t&&t.isVector3?t:new C.Vector3).setFromSpherical(e?this._sphericalEnd:this._spherical).applyQuaternion(this._yAxisUpSpaceInverse).add(e?this._targetEnd:this._target)}getSpherical(t,e=!0){return(t||new C.Spherical).copy(e?this._sphericalEnd:this._spherical)}getFocalOffset(t,e=!0){return(t&&t.isVector3?t:new C.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(!w(this._camera.up.x,this._cameraUp0.x)||!w(this._camera.up.y,this._cameraUp0.y)||!w(this._camera.up.z,this._cameraUp0.z)){this._camera.up.copy(this._cameraUp0);const s=this.getPosition(T);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,at),this._yAxisUpSpaceInverse.copy(this._yAxisUpSpace).invert()}applyCameraUp(){const t=T.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(T);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,i=this._sphericalEnd.radius-this._spherical.radius,o=Ut.subVectors(this._targetEnd,this._target),r=Lt.subVectors(this._focalOffsetEnd,this._focalOffset),a=this._zoomEnd-this._zoom;if(U(e))this._thetaVelocity.value=0,this._spherical.theta=this._sphericalEnd.theta;else{const m=this._isUserControllingRotate?this.draggingSmoothTime:this.smoothTime;this._spherical.theta=rt(this._spherical.theta,this._sphericalEnd.theta,this._thetaVelocity,m,1/0,t),this._needsUpdate=!0}if(U(s))this._phiVelocity.value=0,this._spherical.phi=this._sphericalEnd.phi;else{const m=this._isUserControllingRotate?this.draggingSmoothTime:this.smoothTime;this._spherical.phi=rt(this._spherical.phi,this._sphericalEnd.phi,this._phiVelocity,m,1/0,t),this._needsUpdate=!0}if(U(i))this._radiusVelocity.value=0,this._spherical.radius=this._sphericalEnd.radius;else{const m=this._isUserControllingDolly?this.draggingSmoothTime:this.smoothTime;this._spherical.radius=rt(this._spherical.radius,this._sphericalEnd.radius,this._radiusVelocity,m,this.maxSpeed,t),this._needsUpdate=!0}if(U(o.x)&&U(o.y)&&U(o.z))this._targetVelocity.set(0,0,0),this._target.copy(this._targetEnd);else{const m=this._isUserControllingTruck?this.draggingSmoothTime:this.smoothTime;wt(this._target,this._targetEnd,this._targetVelocity,m,this.maxSpeed,t,this._target),this._needsUpdate=!0}if(U(r.x)&&U(r.y)&&U(r.z))this._focalOffsetVelocity.set(0,0,0),this._focalOffset.copy(this._focalOffsetEnd);else{const m=this._isUserControllingOffset?this.draggingSmoothTime:this.smoothTime;wt(this._focalOffset,this._focalOffsetEnd,this._focalOffsetVelocity,m,this.maxSpeed,t,this._focalOffset),this._needsUpdate=!0}if(U(a))this._zoomVelocity.value=0,this._zoom=this._zoomEnd;else{const m=this._isUserControllingZoom?this.draggingSmoothTime:this.smoothTime;this._zoom=rt(this._zoom,this._zoomEnd,this._zoomVelocity,m,1/0,t)}if(this.dollyToCursor){if(V(this._camera)&&this._changedDolly!==0){const m=this._spherical.radius-this._lastDistance,E=this._camera,u=this._getCameraDirection(W),D=T.copy(u).cross(E.up).normalize();D.lengthSq()===0&&(D.x=1);const g=P.crossVectors(D,u),S=this._sphericalEnd.radius*Math.tan(E.getEffectiveFOV()*j*.5),_=(this._sphericalEnd.radius-m-this._sphericalEnd.radius)/this._sphericalEnd.radius,y=X.copy(this._targetEnd).add(D.multiplyScalar(this._dollyControlCoord.x*S*E.aspect)).add(g.multiplyScalar(this._dollyControlCoord.y*S)),f=T.copy(this._targetEnd).lerp(y,_),v=this._lastDollyDirection===N.IN&&this._spherical.radius<=this.minDistance,O=this._lastDollyDirection===N.OUT&&this.maxDistance<=this._spherical.radius;if(this.infinityDolly&&(v||O)){this._sphericalEnd.radius-=m,this._spherical.radius-=m;const R=P.copy(u).multiplyScalar(-m);f.add(R)}this._boundary.clampPoint(f,f);const L=P.subVectors(f,this._targetEnd);this._targetEnd.copy(f),this._target.add(L),this._changedDolly-=m,U(this._changedDolly)&&(this._changedDolly=0)}else if(B(this._camera)&&this._changedZoom!==0){const m=this._zoom-this._lastZoom,E=this._camera,u=T.set(this._dollyControlCoord.x,this._dollyControlCoord.y,(E.near+E.far)/(E.near-E.far)).unproject(E),D=P.set(0,0,-1).applyQuaternion(E.quaternion),g=X.copy(u).add(D.multiplyScalar(-u.dot(E.up))),l=-(this._zoom-m-this._zoom)/this._zoom,_=this._getCameraDirection(W),y=this._targetEnd.dot(_),f=T.copy(this._targetEnd).lerp(g,l),v=f.dot(_),O=_.multiplyScalar(v-y);f.sub(O),this._boundary.clampPoint(f,f);const L=P.subVectors(f,this._targetEnd);this._targetEnd.copy(f),this._target.add(L),this._changedZoom-=m,U(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 h=this._collisionTest();this._spherical.radius=Math.min(this._spherical.radius,h),this._spherical.makeSafe(),this._camera.position.setFromSpherical(this._spherical).applyQuaternion(this._yAxisUpSpaceInverse).add(this._target),this._camera.lookAt(this._target),(!U(this._focalOffset.x)||!U(this._focalOffset.y)||!U(this._focalOffset.z))&&(this._camera.updateMatrixWorld(),H.setFromMatrixColumn(this._camera.matrix,0),k.setFromMatrixColumn(this._camera.matrix,1),Y.setFromMatrixColumn(this._camera.matrix,2),H.multiplyScalar(this._focalOffset.x),k.multiplyScalar(-this._focalOffset.y),Y.multiplyScalar(this._focalOffset.z),T.copy(H).add(k).add(Y),this._camera.position.add(T)),this._boundaryEnclosesCamera&&this._encloseToBoundary(this._camera.position.copy(this._target),T.setFromSpherical(this._spherical).applyQuaternion(this._yAxisUpSpaceInverse),1);const p=this._needsUpdate;return p&&!this._updatedLastTime?(this._hasRested=!1,this.dispatchEvent({type:"wake"}),this.dispatchEvent({type:"update"})):p?(this.dispatchEvent({type:"update"}),U(e,this.restThreshold)&&U(s,this.restThreshold)&&U(i,this.restThreshold)&&U(o.x,this.restThreshold)&&U(o.y,this.restThreshold)&&U(o.z,this.restThreshold)&&U(r.x,this.restThreshold)&&U(r.y,this.restThreshold)&&U(r.z,this.restThreshold)&&U(a,this.restThreshold)&&!this._hasRested&&(this._hasRested=!0,this.dispatchEvent({type:"rest"}))):!p&&this._updatedLastTime&&this.dispatchEvent({type:"sleep"}),this._lastDistance=this._spherical.radius,this._lastZoom=this._zoom,this._updatedLastTime=p,this._needsUpdate=!1,p}toJSON(){return JSON.stringify({enabled:this._enabled,minDistance:this.minDistance,maxDistance:G(this.maxDistance),minZoom:this.minZoom,maxZoom:G(this.maxZoom),minPolarAngle:this.minPolarAngle,maxPolarAngle:G(this.maxPolarAngle),minAzimuthAngle:G(this.minAzimuthAngle),maxAzimuthAngle:G(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:T.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=Q(s.maxDistance),this.minZoom=s.minZoom,this.maxZoom=Q(s.maxZoom),this.minPolarAngle=s.minPolarAngle,this.maxPolarAngle=Q(s.maxPolarAngle),this.minAzimuthAngle=Q(s.minAzimuthAngle),this.maxAzimuthAngle=Q(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),z.setFromVector3(T.fromArray(s.position).sub(this._targetEnd).applyQuaternion(this._yAxisUpSpace)),this.rotateTo(z.theta,z.phi,e),this.dollyTo(z.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 i=e.lengthSq();if(i===0)return t;const o=P.copy(e).add(t),a=this._boundary.clampPoint(o,X).sub(o),h=a.lengthSq();if(h===0)return t.add(e);if(h===i)return t;if(s===0)return t.add(e).add(a);{const c=1+s*h/e.dot(a);return t.add(P.copy(e).multiplyScalar(c)).add(a.multiplyScalar(1-s))}}_updateNearPlaneCorners(){if(V(this._camera)){const t=this._camera,e=t.near,s=t.getEffectiveFOV()*j,i=Math.tan(s*.5)*e,o=i*t.aspect;this._nearPlaneCorners[0].set(-o,-i,0),this._nearPlaneCorners[1].set(o,-i,0),this._nearPlaneCorners[2].set(o,i,0),this._nearPlaneCorners[3].set(-o,i,0)}else if(B(this._camera)){const t=this._camera,e=1/t.zoom,s=t.left*e,i=t.right*e,o=t.top*e,r=t.bottom*e;this._nearPlaneCorners[0].set(s,o,0),this._nearPlaneCorners[1].set(i,o,0),this._nearPlaneCorners[2].set(i,r,0),this._nearPlaneCorners[3].set(s,r,0)}}_collisionTest(){let t=1/0;if(!(this.colliderMeshes.length>=1)||pt(this._camera,"_collisionTest"))return t;const s=this._getTargetDirection(W);Et.lookAt(St,s,this._camera.up);for(let i=0;i<4;i++){const o=P.copy(this._nearPlaneCorners[i]);o.applyMatrix4(Et);const r=X.addVectors(this._target,o);ht.set(r,s),ht.far=this._spherical.radius+1;const a=ht.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 C.Sphere){const s=e,i=s.center;K.makeEmpty(),t.traverseVisible(r=>{r.isMesh&&K.expandByObject(r)}),K.getCenter(i);let o=0;return t.traverseVisible(r=>{if(!r.isMesh)return;const a=r,h=a.geometry.clone();h.applyMatrix4(a.matrixWorld);const p=h.attributes.position;for(let m=0,E=p.count;m<E;m++)T.fromBufferAttribute(p,m),o=Math.max(o,i.distanceToSquared(T))}),s.radius=Math.sqrt(o),s}}const ae={antialias:!1,devicePixelRatio:window.devicePixelRatio,powerPreference:"high-performance",toneMappingExposure:1,alpha:!1,outputColorSpace:Wt.ColorSpace.sRGB,logarithmicDepthBuffer:!1,preserveDrawingBuffer:!1,stencil:!1,depth:!1,physicallyCorrectLights:!1};class he{constructor(t){this.options=t;const{width:e,height:s,rendererParams:i}=t,{canvas:o,context:r,alpha:a,devicePixelRatio:h,antialias:c,powerPreference:p,toneMappingExposure:m,outputColorSpace:E,logarithmicDepthBuffer:u,preserveDrawingBuffer:D,stencil:g,depth:S,physicallyCorrectLights:l}=i,_=new x.WebGLRenderer({canvas:o,context:r,alpha:a,antialias:c,powerPreference:p,logarithmicDepthBuffer:u,preserveDrawingBuffer:D,stencil:g,depth:S});_.setSize(e,s),_.setPixelRatio(h),_.toneMappingExposure=m,_.outputColorSpace=E,+x.REVISION<155&&(_.useLegacyLights=l),this.renderer=_}setSize(t,e){this.renderer.setSize(t,e)}render(t){const{scene:e,camera:s}=this.options;this.renderer.render(e,t||s)}dispose(){var t,e;this.setSize(1,1),(t=this.renderer)==null||t.clear(),(e=this.renderer)==null||e.dispose()}}class lt{constructor(t){this.guiParams={},t&&(this.guiParams=t)}showGui(t){t&&Object.keys(this.guiParams).forEach(e=>{const s=t.addFolder(e),i=this.guiParams[e];Object.keys(i).forEach(o=>{const{min:r,max:a,step:h,name:c,paramMap:p,items:m,value:E,target:u}=i[o],D=o.toLowerCase().indexOf("color")>-1;let g;const S=typeof E=="undefined"&&u,l=S?u():i[o],_=S?o:"value";m?g=s.add(l,_,m):D?g=s.addColor(l,_):g=s.add(l,_),g=g.name(c||o),typeof r!="undefined"&&(g=g.min(r)),typeof a!="undefined"&&(g=g.max(a)),typeof h!="undefined"&&(g=g.step(h)),g=g.onChange(()=>{this.setTargetValue(e,o,l[_],p)}),S&&g.listen()})})}setTargetValue(t,e,s,i){const{onChange:o,target:r,value:a}=this.guiParams[t][e],h=e.toLowerCase().indexOf("color")>-1;if(r&&!(typeof a=="undefined"&&r)){let p=r();Array.isArray(p)||(p=[p]),p.forEach(m=>{if(m)if(h)try{m[i||e].set(s)}catch(E){e!=="color"&&!i&&console.warn(`${e} is not a color,set paramMap`)}else m[i||e]=s})}o&&o(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={fov:45,near:1,far:1e3,up:new x.Vector3(0,1,0)};class ce{constructor(t){this.customCamera=!1,this.options=t;const{width:e,height:s,cameraParams:i}=t;if(i instanceof x.Camera)this.camera=i,this.customCamera=!0;else{const{fov:o,far:r,near:a,up:h}=i,c=new x.PerspectiveCamera(o,e/s,a,r);c.position.set(0,0,400),c.lookAt(0,0,0),c.up=h,this.camera=c}}setSize(t,e){this.camera instanceof x.PerspectiveCamera&&(this.camera.aspect=t/e),this.camera.updateProjectionMatrix(),this.camera2&&(this.camera2.aspect=t/e,this.camera2.updateProjectionMatrix())}addCamera2(){const t=new x.PerspectiveCamera(this.camera.fov,this.camera.aspect,this.camera.near,this.camera.far);return t.position.copy(this.camera.position),this.camera2=t,t}setGui(t){const e=new lt({camera:ot(I({},this.options.cameraControls?{}:{x:{min:-1e4,max:1e4,step:1,target:()=>this.camera.position},y:{min:-1e4,max:1e4,step:1,target:()=>this.camera.position},z:{min:-1e4,max:1e4,step:1,target:()=>this.camera.position}}),{near:{min:0,max:1e3,step:1,target:()=>this.camera,onChange:s=>{this.camera.updateProjectionMatrix()}},far:{min:0,max:2e4,step:1,target:()=>this.camera,onChange:s=>{this.camera.updateProjectionMatrix()}}})});this.camera instanceof x.PerspectiveCamera&&(e.guiParams.camera.fov={min:0,max:90,step:1,target:()=>this.camera,onChange:s=>{this.camera.updateProjectionMatrix()}}),e.showGui(t)}}const de={background:null,om:!0,addCamera:!0};class me{constructor(t){this.overrideMaterial=!1,this.options=t;const{camera:e,sceneParams:s}=t,{background:i,om:o,addCamera:r}=s,a=o?new x.Scene:new Proxy(new x.Scene,{set:(h,c,p)=>Reflect.set(h,c,p),get:(h,c)=>{if(c==="overrideMaterial"){const p=Reflect.get(h,c);return this.overrideMaterial=!!p,vt.meshLineMaterialArr.forEach(m=>{this.overrideMaterial?m.useDepth=1:m.useDepth=0}),null}return Reflect.get(h,c)}});i&&(a.background=i),r&&a.add(e),this.scene=a}dispose(){var t;(t=this.scene)==null||t.traverse(e=>{Jt.disposeMesh(e)}),vt.meshLineMaterialArr.length=0}}class _e{constructor(t){this.helpers={},this.options=t}add(t){const e=t.uuid,{scene:s}=this.options;let i=this.helpers[e];if(i===void 0){if(t.isScene)i=new x.AxesHelper(100);else if(t.isCamera)i=new x.CameraHelper(t);else if(t.isPointLight)i=new x.PointLightHelper(t,1);else if(t.isDirectionalLight)i=new x.DirectionalLightHelper(t,1);else if(t.isSpotLight)i=new x.SpotLightHelper(t);else if(t.isHemisphereLight)i=new x.HemisphereLightHelper(t,10);else if(t.isRectAreaLight)i=new $t.RectAreaLightHelper(t);else{const o=new x.Box3;if(o.setFromObject(t,!0),o.isEmpty()===!1){i=new x.Box3Helper(o);const r=i.material;r.userData.object=t,r.depthTest=!1,r.transparent=!0}else return}s.add(i),this.helpers[e]=i}}remove(t){const e=t.uuid,{scene:s}=this.options;if(this.helpers[e]!==void 0){const i=this.helpers[e];s.remove(i),delete this.helpers[e],i instanceof x.Box3Helper&&i.dispose()}}removeAll(){Object.keys(this.helpers).forEach(t=>{this.remove({uuid:t})}),this.helpers={}}removeAllExcludeScene(){Object.keys(this.helpers).forEach(t=>{this.helpers[t]instanceof x.AxesHelper||this.remove({uuid:t})})}update(){Object.values(this.helpers).forEach(t=>{if(t.update&&t.update(),t instanceof x.Box3Helper){const e=t.material,{object:s}=e.userData;s&&t.box.setFromObject(s,!0)}})}dispose(){this.helpers={}}}class pe{constructor(t){this.autoRotateSpeed=0,this.options=t;const{camera:e,controlsParams:s,customControl:i}=t,{domElement:o}=s;if(i){const r=new i(e,o);r.enableDamping=!0,r.dampingFactor=.063,r.autoRotate=!1,r.autoRotateSpeed=-60,r.enableZoom=!0,r.zoomSpeed=.2,this.controls=r}else Z.install({THREE:x}),this.cameraControls=new Z(e,o)}addCameraControls2(t){const{controlsParams:e}=this.options,{domElement:s}=e;this.cameraControls2=new Z(t,s),this.cameraControls2.addEventListener("update",()=>{this.cameraControls.enabled=!1}),this.cameraControls2.addEventListener("sleep",()=>{this.cameraControls.enabled=!0})}enable(){this.controls?this.controls.enabled=!0:this.cameraControls&&(this.cameraControls.enabled=!0,this.cameraControls2&&(this.cameraControls2.enabled=!0))}disable(){this.controls?this.controls.enabled=!1:this.cameraControls&&(this.cameraControls.enabled=!1,this.cameraControls2&&(this.cameraControls2.enabled=!1))}update(t){var e,s,i;(e=this.controls)==null||e.update(),(s=this.cameraControls)==null||s.update(t),(i=this.cameraControls2)==null||i.update(t),this.autoRotateSpeed&&this.cameraControls&&(this.cameraControls.azimuthAngle+=this.autoRotateSpeed*t*x.MathUtils.DEG2RAD)}dispose(){var t,e,s;(t=this.controls)==null||t.dispose(),(e=this.cameraControls)==null||e.dispose(),(s=this.cameraControls2)==null||s.dispose()}}class ue{constructor(t){this.event=new Ft.eventsExports.EventEmitter;const{renderer:e,scene:s,camera:i}=t,o=new te.TransformControls(i,e.domElement);s.add(o),this.controls=o,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 i=this.controls;i.addEventListener("change",()=>{const o=i.object;o!==void 0&&this.event.emit("change",o)}),i.addEventListener("mouseDown",()=>{const o=i.object;t=o.position.clone(),e=o.rotation.clone(),s=o.scale.clone(),this.event.emit("mouseDown",o)}),i.addEventListener("mouseUp",()=>{const o=i.object;if(o!==void 0)switch(i.getMode()){case"translate":t.equals(o.position)||this.event.emit("translate",o,o.position,t);break;case"rotate":e.equals(o.rotation)||this.event.emit("rotate",o,o.rotation,e);break;case"scale":s.equals(o.scale)||this.event.emit("scale",o,o.scale,s);break}this.event.emit("mouseUp")})}dispose(){var t;this.event.removeAllListeners(),(t=this.controls)==null||t.dispose()}}const bt={zIndex:"auto"};class fe{constructor(t){this.container=t}addRenderer(t,e){const s=e.container||this.container,i=s.offsetWidth,o=s.offsetHeight,r=t==="css2d"?new se.CSS2DRenderer:new ee.CSS3DRenderer;r.domElement.style.position="absolute",r.domElement.style.top="0",r.domElement.style.pointerEvents="none",r.domElement.style.zIndex=e.zIndex,r.setSize(i,o),s.appendChild(r.domElement),t==="css2d"?this.css2Drenderer=r:t==="css3d"&&(this.css3Drenderer=r)}setSize(t,e){var s,i;(s=this.css2Drenderer)==null||s.setSize(t,e),(i=this.css3Drenderer)==null||i.setSize(t,e)}render(t,e){var s,i;(s=this.css2Drenderer)==null||s.render(t,e),(i=this.css3Drenderer)==null||i.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}}const Mt=["encodings_fragment","colorspace_fragment"];class ge extends tt.ShaderMaterial{constructor(){super({uniforms:{inputBuffer:new tt.Uniform(null),ratio:new tt.Uniform(1)},fragmentShader:`
2
2
  uniform sampler2D inputBuffer;
3
3
  uniform float ratio;
4
4
  varying vec2 vUv;
@@ -1915,24 +1915,25 @@ class Ee {
1915
1915
  }
1916
1916
  const ye = {
1917
1917
  background: null,
1918
- om: !0
1918
+ om: !0,
1919
+ addCamera: !0
1919
1920
  };
1920
1921
  class Ce {
1921
1922
  constructor(t) {
1922
1923
  this.overrideMaterial = !1, this.options = t;
1923
- const { camera: e, sceneParams: s } = t, { background: i, om: o } = s, r = o ? new P.Scene() : new Proxy(new P.Scene(), {
1924
- set: (a, h, c) => Reflect.set(a, h, c),
1925
- get: (a, h) => {
1926
- if (h === "overrideMaterial") {
1927
- const c = Reflect.get(a, h);
1928
- return this.overrideMaterial = !!c, xt.forEach((p) => {
1929
- this.overrideMaterial ? p.useDepth = 1 : p.useDepth = 0;
1924
+ const { camera: e, sceneParams: s } = t, { background: i, om: o, addCamera: r } = s, a = o ? new P.Scene() : new Proxy(new P.Scene(), {
1925
+ set: (h, c, p) => Reflect.set(h, c, p),
1926
+ get: (h, c) => {
1927
+ if (c === "overrideMaterial") {
1928
+ const p = Reflect.get(h, c);
1929
+ return this.overrideMaterial = !!p, xt.forEach((m) => {
1930
+ this.overrideMaterial ? m.useDepth = 1 : m.useDepth = 0;
1930
1931
  }), null;
1931
1932
  }
1932
- return Reflect.get(a, h);
1933
+ return Reflect.get(h, c);
1933
1934
  }
1934
1935
  });
1935
- i && (r.background = i), r.add(e), this.scene = r;
1936
+ i && (a.background = i), r && a.add(e), this.scene = a;
1936
1937
  }
1937
1938
  dispose() {
1938
1939
  var t;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gl-draw",
3
- "version": "0.9.47",
3
+ "version": "0.9.48",
4
4
  "author": "gitplus <hstits@gmail.com>",
5
5
  "scripts": {
6
6
  "start": "bundler-dev",
@@ -9,26 +9,32 @@
9
9
  },
10
10
  "main": "dist/index.js",
11
11
  "module": "dist/index.module.js",
12
+ "types": "dist/index.d.ts",
12
13
  "exports": {
13
14
  ".": {
14
15
  "import": "./dist/index.module.js",
15
- "require": "./dist/index.js"
16
+ "require": "./dist/index.js",
17
+ "types": "./dist/index.d.ts"
16
18
  },
17
19
  "./dist/objects": {
18
20
  "import": "./dist/objects/index.module.js",
19
- "require": "./dist/objects/index.js"
21
+ "require": "./dist/objects/index.js",
22
+ "types": "./dist/objects/index.d.ts"
20
23
  },
21
24
  "./dist/plugins": {
22
25
  "import": "./dist/plugins/index.module.js",
23
- "require": "./dist/plugins/index.js"
26
+ "require": "./dist/plugins/index.js",
27
+ "types": "./dist/plugins/index.d.ts"
24
28
  },
25
29
  "./dist/effect": {
26
30
  "import": "./dist/effect/index.module.js",
27
- "require": "./dist/effect/index.js"
31
+ "require": "./dist/effect/index.js",
32
+ "types": "./dist/effect/index.d.ts"
28
33
  },
29
34
  "./dist/utils": {
30
35
  "import": "./dist/utils/index.module.js",
31
- "require": "./dist/utils/index.js"
36
+ "require": "./dist/utils/index.js",
37
+ "types": "./dist/utils/index.d.ts"
32
38
  },
33
39
  "./dist/": "./dist/"
34
40
  },