shopar-plugin
Version:
Plugin for the Web that seamlessly integrates into your webpage to create embedded virtual try-on and 3D preview capabilities.
6 lines • 879 kB
JavaScript
const e=["AR","3D"];class t extends Error{constructor(e){super(e),this.name="PluginError"}}class n extends t{constructor(e){super(e),this.name="ValidationError"}}class i extends t{constructor(e,t){super(e),this.name="ApiError",this.status=t}}class r extends t{constructor(e){super(e),this.name="SanitizationError"}}class a extends t{constructor(e){super((null==e?void 0:e.trim())||"3D failed to launch."),this.name="Launch3DError"}}class o extends t{constructor(e){super((null==e?void 0:e.trim())||"AR failed to launch."),this.name="LaunchARError"}}class s extends o{constructor(e){super((null==e?void 0:e.trim())||"Camera permission denied."),this.name="CameraPermissionDeniedError"}}class l extends o{constructor(e){super((null==e?void 0:e.trim())||"QR failed."),this.name="QRError"}}function c(e,t,n,i){return new(n||(n=Promise))(function(r,a){function o(e){try{l(i.next(e))}catch(e){a(e)}}function s(e){try{l(i.throw(e))}catch(e){a(e)}}function l(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(o,s)}l((i=i.apply(e,t||[])).next())})}function h(e){return null!=e&&"object"==typeof e&&"name"in e&&"string"==typeof e.name?e.name:"Unknown"}function A(e){return null!=e&&"object"==typeof e&&"message"in e&&"string"==typeof e.message?e.message:"Unknown error."}"function"==typeof SuppressedError&&SuppressedError;function u(e){if(null!=e&&"object"==typeof e&&"stack"in e&&"string"==typeof e.stack)return e.stack.length>1e3?e.stack.slice(0,1e3):e.stack}function d(e,n){return()=>c(this,void 0,void 0,function*(){try{return yield n()}catch(n){if(n instanceof t)throw n;throw new t(`${e} failed: ${A(n)}`)}})}const p=[Uint8Array,Uint32Array].length-2,f=["addEventListener","alert","atob","blur","btoa","cancelAnimationFrame","localStorage","location","locationbar","hash","hasOwnProperty","host","hostname","href","requestAnimationFrame"],g=[2,12,7,1],m=window[f[g[g[p]]]][f[g[g[g.length-1]]]];function v(){const e=(new TextEncoder).encode(m),t=f.map(e=>e.length);for(let n=0;n<e.length;n++)e[n]^=t[n%t.length];return window[f[t[2]]](String.fromCodePoint(...e))}m.charCodeAt(p);function E(e){return e*(180/Math.PI)}function b(e){return Math.round(100*e)/100}const C=["Glasses","Shoes","Watches","Bracelets","Scarves","Hats","Necklaces"],_=["Shoes"];const I="1.2.0";let x=`https://cdn.jsdelivr.net/npm/shopar-plugin@${I}/dist`;const y=e=>{null!=e&&(x=e.endsWith("/")?e.substring(0,e.length-1):e)},M=()=>x;function w(e,t){return c(this,void 0,void 0,function*(){if("function"!=typeof importScripts){if("function"==typeof window.define&&window.define.amd&&"function"==typeof window.require)return new Promise(n=>{window.require([e],e=>{window[t]=e,n()},()=>{n()})});{const t=document.createElement("script");return t.setAttribute("src",e),t.setAttribute("crossorigin","anonymous"),new Promise(e=>{t.addEventListener("load",()=>e(),!1),t.addEventListener("error",()=>e(),!1),document.body.appendChild(t)})}}importScripts(e.toString())})}let S;function B(e,t){let n=!0;return{qrPaused:()=>n,qrDraw:(i,r)=>c(this,void 0,void 0,function*(){!function(){c(this,void 0,void 0,function*(){null==S&&(S=w(`${M()}/shopar-qr.js`,"ShopAR__QR"))})}(),yield S;const a=`https://ar.shopar.ai/${I.includes("alpha")?"qr-alpha":"qr"}/?${new URLSearchParams({a:i,s:r,h:location.href})}`,o=yield window.ShopAR__QR.toDataURL(a),s=new Promise((e,n)=>{t.onload=e,t.onerror=n});t.src=o,yield s,n=!1,e.style.display=""}),qrPause:()=>c(this,void 0,void 0,function*(){n=!0,e.style.display="none"})}}const T={"loading.ar":"Loading Try On...","prompt.ar.shoes":void 0,"prompt.ar.glasses":void 0,"prompt.ar.watches":void 0,"prompt.ar.bracelets":void 0,"prompt.ar.scarves":void 0,"prompt.ar.hats":void 0,"prompt.ar.necklaces":void 0},R=Object.keys(T);const D="--shopar";function Q(e){return`var(${e.var}, ${e.default})`}const L={padding:{var:`${D}-btn-padding`,default:"0.5rem 0.75rem"},gap:{var:`${D}-btn-gap`,default:"0.25rem"},border:{var:`${D}-btn-border`,default:"1px solid #dddddd"},borderRadius:{var:`${D}-btn-border-radius`,default:"calc(infinity * 1px)"},bg:{var:`${D}-btn-bg`,default:"#ffffff"},hoverBg:{var:`${D}-btn-hover-bg`,default:"#f5f5f5"}};function U(e,t,n){const i=document.createElement("button");i.type="button",i.appendChild(n);{const t=document.createElement("span");t.textContent=e,i.appendChild(t)}i.ariaLabel=t;const r=i.style;r.display="none",r.pointerEvents="auto",r.padding=Q(L.padding),r.justifyContent="center",r.alignItems="center",r.gap=Q(L.gap),r.backgroundColor=Q(L.bg),r.border=Q(L.border),r.borderRadius=Q(L.borderRadius),r.cursor="pointer";const a=Q(L.bg),o=Q(L.hoverBg);return i.addEventListener("mouseenter",()=>{r.backgroundColor=o}),i.addEventListener("mouseleave",()=>{r.backgroundColor=a}),i}const P={paddingBottom:{var:`${D}-btn-container-padding-bottom`,default:"2rem"},gap:{var:`${D}-btn-container-gap`,default:"0.5rem"}};const F={bg:{var:`${D}-ar-prompt-bg`,default:"#1e293bb2"},gap:{var:`${D}-ar-prompt-gap`,default:"1rem"},textColor:{var:`${D}-ar-prompt-text-color`,default:"white"},imgMaxWidth:{var:`${D}-ar-prompt-img-max-width`,default:"80%"},imgMaxHeight:{var:`${D}-ar-prompt-img-max-height`,default:"50%"}};const N={containerDisplay:{var:`${D}-ar-loading-container-display`,default:"flex"},containerBg:{var:`${D}-ar-loading-container-bg`,default:"#ffffff"},containerGap:{var:`${D}-ar-loading-container-gap`,default:"1rem"},barWidth:{var:`${D}-ar-loading-bar-width`,default:"80%"},barHeight:{var:`${D}-ar-loading-bar-height`,default:"0.5rem"},barRadius:{var:`${D}-ar-loading-bar-radius`,default:"calc(infinity * 1px)"},barFg:{var:`${D}-ar-loading-bar-fg`,default:"linear-gradient(90deg, #773cd8, #5fb9ec)"},barBg:{var:`${D}-ar-loading-bar-bg`,default:"#e5e7eb"}};const O={bg:{var:`${D}-qr-bg`,default:"#ffffff"}};function k(e,t,n,i){return new(n||(n=Promise))(function(r,a){function o(e){try{l(i.next(e))}catch(e){a(e)}}function s(e){try{l(i.throw(e))}catch(e){a(e)}}function l(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(o,s)}l((i=i.apply(e,t||[])).next())})}function G(e,t,n,i){if("a"===n&&!i)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof t?e!==t||!i:!t.has(e))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===n?i:"a"===n?i.call(e):i?i.value:t.get(e)}function H(e,t,n,i,r){if("function"==typeof t||!t.has(e))throw new TypeError("Cannot write private member to an object whose class did not declare it");return t.set(e,n),n}"function"==typeof SuppressedError&&SuppressedError;const z=.1,V="function"==typeof Float32Array;function W(e,t){return 1-3*t+3*e}function q(e,t){return 3*t-6*e}function j(e){return 3*e}function Y(e,t,n){return((W(t,n)*e+q(t,n))*e+j(t))*e}function X(e,t,n){return 3*W(t,n)*e*e+2*q(t,n)*e+j(t)}function K(e){return e}function J(e){if("hold"===e.type)return()=>0;if("bezier"===e.type){const t=function(e,t,n,i){if(!(0<=e&&e<=1&&0<=n&&n<=1))throw new Error("bezier x values must be in [0, 1] range");if(e===t&&n===i)return K;const r=V?new Float32Array(11):new Array(11);for(let t=0;t<11;++t)r[t]=Y(t*z,e,n);function a(t){let i=0,a=1;for(;10!==a&&r[a]<=t;++a)i+=z;--a;const o=i+(t-r[a])/(r[a+1]-r[a])*z,s=X(o,e,n);return s>=.001?function(e,t,n,i){for(let r=0;r<4;++r){const r=X(t,n,i);if(0===r)return t;t-=(Y(t,n,i)-e)/r}return t}(t,o,e,n):0===s?o:function(e,t,n,i,r){let a,o,s=0;do{o=t+(n-t)/2,a=Y(o,i,r)-e,a>0?n=o:t=o}while(Math.abs(a)>1e-7&&++s<10);return o}(t,i,i+z,e,n)}return function(e){return 0===e||1===e?e:Y(a(e),t,i)}}(e.x1,e.y1,e.x2,e.y2);return e=>t(e)}throw new Error(`Unknown interpolation: ${e}`)}function Z(e){if(e.length<2)throw new Error("Expected at least two key frames.");const t=e[e.length-1].time,n=[...e].sort((e,t)=>e.time-t.time).map(({time:e,value:t,interpolation:n})=>({time:e,value:t,interpolate:J(n)}));let i=0,r=n[0].value;const a=()=>{for(i<0&&(i=0);i>=t;)i-=t;for(let e=0;e<n.length-1;e++){const t=n[e],a=n[e+1];if(i>=t.time&&i<a.time){const e=t.interpolate((i-t.time)/(a.time-t.time));r=t.value+e*(a.value-t.value)}}};return{reset:()=>{i=0,a()},update:e=>{i+=e,a()},seek:e=>{i=e,a()},get:()=>r}}const $="time",ee="interpolation",te="pitch",ne=[$,"yaw",te,"fov",ee],ie=Math.PI/180,re="ease-in-out",ae="cubic-bezier(";function oe(e){if("string"==typeof e)return function(e){const[t,...n]=function(e){return e.split(/\r?\n/).map(e=>function(e){const t=e.indexOf("#");return(-1!==t?e.substring(0,t):e).trim()}(e)).filter(e=>""!==e)}(e);if(null==t)throw new Error("Header missing.");const i=function(e){const t=[];for(let n=0;n<e.length;n++){const i=e[n];if(!ne.includes(i))throw new Error(`Invalid token in header: '${i}'.`);if(t.includes(i))throw new Error(`Duplicate token in header: '${i}'.`);t.push(i)}if(!t.includes($))throw new Error(`Missing required token: '${$}'.`);return t}(t.split(/\s+/)),r={};if(n.length<2)throw new Error("Expected at least two key frames.");for(const e of n){const{theta:t,phi:n,fov:a}=se(i,e);null!=t&&(null==r.theta&&(r.theta=[]),r.theta.push(t)),null!=n&&(null==r.phi&&(r.phi=[]),r.phi.push(n)),null!=a&&(null==r.fov&&(r.fov=[]),r.fov.push(a))}if(0===Object.values(r).length)throw new Error("At least one parameter should be animated.");return r}(e);if(Array.isArray(e))return function(e){var t;const n={};if(e.length<2)throw new Error("Expected at least two key frames.");for(const i of e){const{time:e,pitch:r,yaw:a,fov:o}=i;if(null==e)throw new Error("Time missing.");const s=ce(null!==(t=i.interpolation)&&void 0!==t?t:re);null!=a&&(null==n.theta&&(n.theta=[]),n.theta.push({time:e,value:a*ie,interpolation:s})),null!=r&&(null==n.phi&&(n.phi=[]),n.phi.push({time:e,value:r*ie,interpolation:s})),null!=o&&(null==n.fov&&(n.fov=[]),n.fov.push({time:e,value:o*ie,interpolation:s}))}if(0===Object.values(n).length)throw new Error("At least one parameter should be animated.");if(Object.values(n).every(t=>t.length!==e.length))throw new Error("All parameters should have the same key frame count.");return n}(e);throw new Error("Expected string or key frame config array.")}function se(e,t){const n=t.match(/[^()\s]+(\(.*?\))?/g);if(null==n||n.length<e.length)throw new Error(`Missing data for fields: '${e.filter(e=>!(null==n?void 0:n.includes(e))).join(", ")}'.`);if(n.length>e.length)throw new Error(`Excess data: '${n.filter(t=>!e.includes(t)).join(", ")}'.`);const i=e.indexOf($),r=function(e){return e.endsWith("ms")?Ae(e.substring(0,e.length-2)):e.endsWith("s")?1e3*Ae(e.substring(0,e.length-1)):Ae(e)}(n[i]),a=e.indexOf(ee),o=ce(-1===a?re:n[a]),s={};for(let t=0;t<n.length;t++){if(t===i||t===a)continue;const l=e[t],c=n[t];switch(l){case"yaw":s.theta={time:r,value:le(c),interpolation:o};break;case te:s.phi={time:r,value:le(c),interpolation:o};break;case"fov":s.fov={time:r,value:le(c),interpolation:o};break;default:throw new Error(`Unhandled value for header '${l}'.`)}}return s}function le(e){return e.endsWith("deg")?Ae(e.substring(0,e.length-3))*ie:e.endsWith("rad")?Ae(e.substring(0,e.length-3)):Ae(e)*ie}function ce(e){if("hold"===e)return{type:"hold"};if("linear"===e)return he(0,0,1,1);if("sine"===e)return he(.37,0,.63,1);if("sine-in"===e)return he(.12,0,.39,0);if("sine-out"===e)return he(.61,1,.88,1);if("ease"===e)return he(.25,.1,.25,1);if("ease-in"===e)return he(.42,0,1,1);if("ease-out"===e)return he(0,0,.58,1);if("ease-in-out"===e)return he(.42,0,.58,1);if(e.startsWith(ae)&&e.endsWith(")")){const t=e.substring(13,e.length-1).split(/\s*,\s*/);if(4!==t.length)throw new Error(`Expected 4 parameters for the Bezier curve, but got '${t}'.`);return{type:"bezier",x1:Ae(t[0]),y1:Ae(t[1]),x2:Ae(t[2]),y2:Ae(t[3])}}throw new Error(`Expected an interpolation token, but found: ${e}`)}function he(e,t,n,i){return{type:"bezier",x1:e,y1:t,x2:n,y2:i}}function Ae(e){const t=Number.parseFloat(e);if(Number.isNaN(t))throw new Error(`Expected a numeric value, but got: ${e}`);return t}
/**
* @license
* Copyright 2010-2024 Three.js Authors
* SPDX-License-Identifier: MIT
*/const ue="166dev",de=0,pe=1,fe=2,ge=100,me=101,ve=102,Ee=200,be=201,Ce=202,_e=203,Ie=204,xe=205,ye=206,Me=207,we=208,Se=209,Be=210,Te=211,Re=212,De=213,Qe=214,Le="attached",Ue=301,Pe=302,Fe=303,Ne=306,Oe=1e3,ke=1001,Ge=1002,He=1003,ze=1004,Ve=1005,We=1006,qe=1007,je=1008,Ye=1009,Xe=1012,Ke=1014,Je=1015,Ze=1016,$e=1020,et=1023,tt=1026,nt=1027,it=1028,rt=1030,at=33776,ot=33777,st=33778,lt=33779,ct=35840,ht=35842,At=36196,ut=37492,dt=37496,pt=37808,ft=37812,gt=36492,mt=2300,vt=2301,Et=2302,bt="",Ct="srgb",_t="srgb-linear",It="display-p3",xt="display-p3-linear",yt="linear",Mt="srgb",wt="rec709",St="p3",Bt=7680,Tt=512,Rt=513,Dt=514,Qt=515,Lt=516,Ut=517,Pt=518,Ft=519,Nt=35044,Ot="300 es",kt=2e3,Gt=2001;class Ht{addEventListener(e,t){void 0===this._listeners&&(this._listeners={});const n=this._listeners;void 0===n[e]&&(n[e]=[]),-1===n[e].indexOf(t)&&n[e].push(t)}hasEventListener(e,t){if(void 0===this._listeners)return!1;const n=this._listeners;return void 0!==n[e]&&-1!==n[e].indexOf(t)}removeEventListener(e,t){if(void 0===this._listeners)return;const n=this._listeners[e];if(void 0!==n){const e=n.indexOf(t);-1!==e&&n.splice(e,1)}}dispatchEvent(e){if(void 0===this._listeners)return;const t=this._listeners[e.type];if(void 0!==t){e.target=this;const n=t.slice(0);for(let t=0,i=n.length;t<i;t++)n[t].call(this,e);e.target=null}}}const zt=["00","01","02","03","04","05","06","07","08","09","0a","0b","0c","0d","0e","0f","10","11","12","13","14","15","16","17","18","19","1a","1b","1c","1d","1e","1f","20","21","22","23","24","25","26","27","28","29","2a","2b","2c","2d","2e","2f","30","31","32","33","34","35","36","37","38","39","3a","3b","3c","3d","3e","3f","40","41","42","43","44","45","46","47","48","49","4a","4b","4c","4d","4e","4f","50","51","52","53","54","55","56","57","58","59","5a","5b","5c","5d","5e","5f","60","61","62","63","64","65","66","67","68","69","6a","6b","6c","6d","6e","6f","70","71","72","73","74","75","76","77","78","79","7a","7b","7c","7d","7e","7f","80","81","82","83","84","85","86","87","88","89","8a","8b","8c","8d","8e","8f","90","91","92","93","94","95","96","97","98","99","9a","9b","9c","9d","9e","9f","a0","a1","a2","a3","a4","a5","a6","a7","a8","a9","aa","ab","ac","ad","ae","af","b0","b1","b2","b3","b4","b5","b6","b7","b8","b9","ba","bb","bc","bd","be","bf","c0","c1","c2","c3","c4","c5","c6","c7","c8","c9","ca","cb","cc","cd","ce","cf","d0","d1","d2","d3","d4","d5","d6","d7","d8","d9","da","db","dc","dd","de","df","e0","e1","e2","e3","e4","e5","e6","e7","e8","e9","ea","eb","ec","ed","ee","ef","f0","f1","f2","f3","f4","f5","f6","f7","f8","f9","fa","fb","fc","fd","fe","ff"];const Vt=Math.PI/180,Wt=180/Math.PI;function qt(){const e=4294967295*Math.random()|0,t=4294967295*Math.random()|0,n=4294967295*Math.random()|0,i=4294967295*Math.random()|0;return(zt[255&e]+zt[e>>8&255]+zt[e>>16&255]+zt[e>>24&255]+"-"+zt[255&t]+zt[t>>8&255]+"-"+zt[t>>16&15|64]+zt[t>>24&255]+"-"+zt[63&n|128]+zt[n>>8&255]+"-"+zt[n>>16&255]+zt[n>>24&255]+zt[255&i]+zt[i>>8&255]+zt[i>>16&255]+zt[i>>24&255]).toLowerCase()}function jt(e,t,n){return Math.max(t,Math.min(n,e))}function Yt(e,t){return(e%t+t)%t}function Xt(e,t,n){return(1-n)*e+n*t}function Kt(e,t){switch(t.constructor){case Float32Array:return e;case Uint32Array:return e/4294967295;case Uint16Array:return e/65535;case Uint8Array:return e/255;case Int32Array:return Math.max(e/2147483647,-1);case Int16Array:return Math.max(e/32767,-1);case Int8Array:return Math.max(e/127,-1);default:throw new Error("Invalid component type.")}}function Jt(e,t){switch(t.constructor){case Float32Array:return e;case Uint32Array:return Math.round(4294967295*e);case Uint16Array:return Math.round(65535*e);case Uint8Array:return Math.round(255*e);case Int32Array:return Math.round(2147483647*e);case Int16Array:return Math.round(32767*e);case Int8Array:return Math.round(127*e);default:throw new Error("Invalid component type.")}}const Zt=Vt,$t=Wt,en=function(e){return e*Wt};class tn{constructor(e=0,t=0){tn.prototype.isVector2=!0,this.x=e,this.y=t}get width(){return this.x}set width(e){this.x=e}get height(){return this.y}set height(e){this.y=e}set(e,t){return this.x=e,this.y=t,this}setScalar(e){return this.x=e,this.y=e,this}setX(e){return this.x=e,this}setY(e){return this.y=e,this}setComponent(e,t){switch(e){case 0:this.x=t;break;case 1:this.y=t;break;default:throw new Error("index is out of range: "+e)}return this}getComponent(e){switch(e){case 0:return this.x;case 1:return this.y;default:throw new Error("index is out of range: "+e)}}clone(){return new this.constructor(this.x,this.y)}copy(e){return this.x=e.x,this.y=e.y,this}add(e){return this.x+=e.x,this.y+=e.y,this}addScalar(e){return this.x+=e,this.y+=e,this}addVectors(e,t){return this.x=e.x+t.x,this.y=e.y+t.y,this}addScaledVector(e,t){return this.x+=e.x*t,this.y+=e.y*t,this}sub(e){return this.x-=e.x,this.y-=e.y,this}subScalar(e){return this.x-=e,this.y-=e,this}subVectors(e,t){return this.x=e.x-t.x,this.y=e.y-t.y,this}multiply(e){return this.x*=e.x,this.y*=e.y,this}multiplyScalar(e){return this.x*=e,this.y*=e,this}divide(e){return this.x/=e.x,this.y/=e.y,this}divideScalar(e){return this.multiplyScalar(1/e)}applyMatrix3(e){const t=this.x,n=this.y,i=e.elements;return this.x=i[0]*t+i[3]*n+i[6],this.y=i[1]*t+i[4]*n+i[7],this}min(e){return this.x=Math.min(this.x,e.x),this.y=Math.min(this.y,e.y),this}max(e){return this.x=Math.max(this.x,e.x),this.y=Math.max(this.y,e.y),this}clamp(e,t){return this.x=Math.max(e.x,Math.min(t.x,this.x)),this.y=Math.max(e.y,Math.min(t.y,this.y)),this}clampScalar(e,t){return this.x=Math.max(e,Math.min(t,this.x)),this.y=Math.max(e,Math.min(t,this.y)),this}clampLength(e,t){const n=this.length();return this.divideScalar(n||1).multiplyScalar(Math.max(e,Math.min(t,n)))}floor(){return this.x=Math.floor(this.x),this.y=Math.floor(this.y),this}ceil(){return this.x=Math.ceil(this.x),this.y=Math.ceil(this.y),this}round(){return this.x=Math.round(this.x),this.y=Math.round(this.y),this}roundToZero(){return this.x=Math.trunc(this.x),this.y=Math.trunc(this.y),this}negate(){return this.x=-this.x,this.y=-this.y,this}dot(e){return this.x*e.x+this.y*e.y}cross(e){return this.x*e.y-this.y*e.x}lengthSq(){return this.x*this.x+this.y*this.y}length(){return Math.sqrt(this.x*this.x+this.y*this.y)}manhattanLength(){return Math.abs(this.x)+Math.abs(this.y)}normalize(){return this.divideScalar(this.length()||1)}angle(){return Math.atan2(-this.y,-this.x)+Math.PI}angleTo(e){const t=Math.sqrt(this.lengthSq()*e.lengthSq());if(0===t)return Math.PI/2;const n=this.dot(e)/t;return Math.acos(jt(n,-1,1))}distanceTo(e){return Math.sqrt(this.distanceToSquared(e))}distanceToSquared(e){const t=this.x-e.x,n=this.y-e.y;return t*t+n*n}manhattanDistanceTo(e){return Math.abs(this.x-e.x)+Math.abs(this.y-e.y)}setLength(e){return this.normalize().multiplyScalar(e)}lerp(e,t){return this.x+=(e.x-this.x)*t,this.y+=(e.y-this.y)*t,this}lerpVectors(e,t,n){return this.x=e.x+(t.x-e.x)*n,this.y=e.y+(t.y-e.y)*n,this}equals(e){return e.x===this.x&&e.y===this.y}fromArray(e,t=0){return this.x=e[t],this.y=e[t+1],this}toArray(e=[],t=0){return e[t]=this.x,e[t+1]=this.y,e}fromBufferAttribute(e,t){return this.x=e.getX(t),this.y=e.getY(t),this}rotateAround(e,t){const n=Math.cos(t),i=Math.sin(t),r=this.x-e.x,a=this.y-e.y;return this.x=r*n-a*i+e.x,this.y=r*i+a*n+e.y,this}random(){return this.x=Math.random(),this.y=Math.random(),this}*[Symbol.iterator](){yield this.x,yield this.y}}class nn{constructor(e,t,n,i,r,a,o,s,l){nn.prototype.isMatrix3=!0,this.elements=[1,0,0,0,1,0,0,0,1],void 0!==e&&this.set(e,t,n,i,r,a,o,s,l)}set(e,t,n,i,r,a,o,s,l){const c=this.elements;return c[0]=e,c[1]=i,c[2]=o,c[3]=t,c[4]=r,c[5]=s,c[6]=n,c[7]=a,c[8]=l,this}identity(){return this.set(1,0,0,0,1,0,0,0,1),this}copy(e){const t=this.elements,n=e.elements;return t[0]=n[0],t[1]=n[1],t[2]=n[2],t[3]=n[3],t[4]=n[4],t[5]=n[5],t[6]=n[6],t[7]=n[7],t[8]=n[8],this}extractBasis(e,t,n){return e.setFromMatrix3Column(this,0),t.setFromMatrix3Column(this,1),n.setFromMatrix3Column(this,2),this}setFromMatrix4(e){const t=e.elements;return this.set(t[0],t[4],t[8],t[1],t[5],t[9],t[2],t[6],t[10]),this}multiply(e){return this.multiplyMatrices(this,e)}premultiply(e){return this.multiplyMatrices(e,this)}multiplyMatrices(e,t){const n=e.elements,i=t.elements,r=this.elements,a=n[0],o=n[3],s=n[6],l=n[1],c=n[4],h=n[7],A=n[2],u=n[5],d=n[8],p=i[0],f=i[3],g=i[6],m=i[1],v=i[4],E=i[7],b=i[2],C=i[5],_=i[8];return r[0]=a*p+o*m+s*b,r[3]=a*f+o*v+s*C,r[6]=a*g+o*E+s*_,r[1]=l*p+c*m+h*b,r[4]=l*f+c*v+h*C,r[7]=l*g+c*E+h*_,r[2]=A*p+u*m+d*b,r[5]=A*f+u*v+d*C,r[8]=A*g+u*E+d*_,this}multiplyScalar(e){const t=this.elements;return t[0]*=e,t[3]*=e,t[6]*=e,t[1]*=e,t[4]*=e,t[7]*=e,t[2]*=e,t[5]*=e,t[8]*=e,this}determinant(){const e=this.elements,t=e[0],n=e[1],i=e[2],r=e[3],a=e[4],o=e[5],s=e[6],l=e[7],c=e[8];return t*a*c-t*o*l-n*r*c+n*o*s+i*r*l-i*a*s}invert(){const e=this.elements,t=e[0],n=e[1],i=e[2],r=e[3],a=e[4],o=e[5],s=e[6],l=e[7],c=e[8],h=c*a-o*l,A=o*s-c*r,u=l*r-a*s,d=t*h+n*A+i*u;if(0===d)return this.set(0,0,0,0,0,0,0,0,0);const p=1/d;return e[0]=h*p,e[1]=(i*l-c*n)*p,e[2]=(o*n-i*a)*p,e[3]=A*p,e[4]=(c*t-i*s)*p,e[5]=(i*r-o*t)*p,e[6]=u*p,e[7]=(n*s-l*t)*p,e[8]=(a*t-n*r)*p,this}transpose(){let e;const t=this.elements;return e=t[1],t[1]=t[3],t[3]=e,e=t[2],t[2]=t[6],t[6]=e,e=t[5],t[5]=t[7],t[7]=e,this}getNormalMatrix(e){return this.setFromMatrix4(e).invert().transpose()}transposeIntoArray(e){const t=this.elements;return e[0]=t[0],e[1]=t[3],e[2]=t[6],e[3]=t[1],e[4]=t[4],e[5]=t[7],e[6]=t[2],e[7]=t[5],e[8]=t[8],this}setUvTransform(e,t,n,i,r,a,o){const s=Math.cos(r),l=Math.sin(r);return this.set(n*s,n*l,-n*(s*a+l*o)+a+e,-i*l,i*s,-i*(-l*a+s*o)+o+t,0,0,1),this}scale(e,t){return this.premultiply(rn.makeScale(e,t)),this}rotate(e){return this.premultiply(rn.makeRotation(-e)),this}translate(e,t){return this.premultiply(rn.makeTranslation(e,t)),this}makeTranslation(e,t){return e.isVector2?this.set(1,0,e.x,0,1,e.y,0,0,1):this.set(1,0,e,0,1,t,0,0,1),this}makeRotation(e){const t=Math.cos(e),n=Math.sin(e);return this.set(t,-n,0,n,t,0,0,0,1),this}makeScale(e,t){return this.set(e,0,0,0,t,0,0,0,1),this}equals(e){const t=this.elements,n=e.elements;for(let e=0;e<9;e++)if(t[e]!==n[e])return!1;return!0}fromArray(e,t=0){for(let n=0;n<9;n++)this.elements[n]=e[n+t];return this}toArray(e=[],t=0){const n=this.elements;return e[t]=n[0],e[t+1]=n[1],e[t+2]=n[2],e[t+3]=n[3],e[t+4]=n[4],e[t+5]=n[5],e[t+6]=n[6],e[t+7]=n[7],e[t+8]=n[8],e}clone(){return(new this.constructor).fromArray(this.elements)}}const rn=new nn;function an(e){for(let t=e.length-1;t>=0;--t)if(e[t]>=65535)return!0;return!1}function on(e){return document.createElementNS("http://www.w3.org/1999/xhtml",e)}function sn(){const e=on("canvas");return e.style.display="block",e}const ln={};function cn(e){e in ln||(ln[e]=!0,console.warn(e))}const hn=(new nn).set(.8224621,.177538,0,.0331941,.9668058,0,.0170827,.0723974,.9105199),An=(new nn).set(1.2249401,-.2249404,0,-.0420569,1.0420571,0,-.0196376,-.0786361,1.0982735),un={[_t]:{transfer:yt,primaries:wt,toReference:e=>e,fromReference:e=>e},[Ct]:{transfer:Mt,primaries:wt,toReference:e=>e.convertSRGBToLinear(),fromReference:e=>e.convertLinearToSRGB()},[xt]:{transfer:yt,primaries:St,toReference:e=>e.applyMatrix3(An),fromReference:e=>e.applyMatrix3(hn)},[It]:{transfer:Mt,primaries:St,toReference:e=>e.convertSRGBToLinear().applyMatrix3(An),fromReference:e=>e.applyMatrix3(hn).convertLinearToSRGB()}},dn=new Set([_t,xt]),pn={enabled:!0,_workingColorSpace:_t,get workingColorSpace(){return this._workingColorSpace},set workingColorSpace(e){if(!dn.has(e))throw new Error(`Unsupported working color space, "${e}".`);this._workingColorSpace=e},convert:function(e,t,n){if(!1===this.enabled||t===n||!t||!n)return e;const i=un[t].toReference;return(0,un[n].fromReference)(i(e))},fromWorkingColorSpace:function(e,t){return this.convert(e,this._workingColorSpace,t)},toWorkingColorSpace:function(e,t){return this.convert(e,t,this._workingColorSpace)},getPrimaries:function(e){return un[e].primaries},getTransfer:function(e){return e===bt?yt:un[e].transfer}};function fn(e){return e<.04045?.0773993808*e:Math.pow(.9478672986*e+.0521327014,2.4)}function gn(e){return e<.0031308?12.92*e:1.055*Math.pow(e,.41666)-.055}let mn;class vn{static getDataURL(e){if(/^data:/i.test(e.src))return e.src;if("undefined"==typeof HTMLCanvasElement)return e.src;let t;if(e instanceof HTMLCanvasElement)t=e;else{void 0===mn&&(mn=on("canvas")),mn.width=e.width,mn.height=e.height;const n=mn.getContext("2d");e instanceof ImageData?n.putImageData(e,0,0):n.drawImage(e,0,0,e.width,e.height),t=mn}return t.width>2048||t.height>2048?(console.warn("THREE.ImageUtils.getDataURL: Image converted to jpg for performance reasons",e),t.toDataURL("image/jpeg",.6)):t.toDataURL("image/png")}static sRGBToLinear(e){if("undefined"!=typeof HTMLImageElement&&e instanceof HTMLImageElement||"undefined"!=typeof HTMLCanvasElement&&e instanceof HTMLCanvasElement||"undefined"!=typeof ImageBitmap&&e instanceof ImageBitmap){const t=on("canvas");t.width=e.width,t.height=e.height;const n=t.getContext("2d");n.drawImage(e,0,0,e.width,e.height);const i=n.getImageData(0,0,e.width,e.height),r=i.data;for(let e=0;e<r.length;e++)r[e]=255*fn(r[e]/255);return n.putImageData(i,0,0),t}if(e.data){const t=e.data.slice(0);for(let e=0;e<t.length;e++)t instanceof Uint8Array||t instanceof Uint8ClampedArray?t[e]=Math.floor(255*fn(t[e]/255)):t[e]=fn(t[e]);return{data:t,width:e.width,height:e.height}}return console.warn("THREE.ImageUtils.sRGBToLinear(): Unsupported image type. No color space conversion applied."),e}}let En=0;class bn{constructor(e=null){this.isSource=!0,Object.defineProperty(this,"id",{value:En++}),this.uuid=qt(),this.data=e,this.dataReady=!0,this.version=0}set needsUpdate(e){!0===e&&this.version++}toJSON(e){const t=void 0===e||"string"==typeof e;if(!t&&void 0!==e.images[this.uuid])return e.images[this.uuid];const n={uuid:this.uuid,url:""},i=this.data;if(null!==i){let e;if(Array.isArray(i)){e=[];for(let t=0,n=i.length;t<n;t++)i[t].isDataTexture?e.push(Cn(i[t].image)):e.push(Cn(i[t]))}else e=Cn(i);n.url=e}return t||(e.images[this.uuid]=n),n}}function Cn(e){return"undefined"!=typeof HTMLImageElement&&e instanceof HTMLImageElement||"undefined"!=typeof HTMLCanvasElement&&e instanceof HTMLCanvasElement||"undefined"!=typeof ImageBitmap&&e instanceof ImageBitmap?vn.getDataURL(e):e.data?{data:Array.from(e.data),width:e.width,height:e.height,type:e.data.constructor.name}:(console.warn("THREE.Texture: Unable to serialize Texture."),{})}let _n=0;class In extends Ht{constructor(e=In.DEFAULT_IMAGE,t=In.DEFAULT_MAPPING,n=ke,i=ke,r=We,a=1008,o=1023,s=1009,l=In.DEFAULT_ANISOTROPY,c=""){super(),this.isTexture=!0,Object.defineProperty(this,"id",{value:_n++}),this.uuid=qt(),this.name="",this.source=new bn(e),this.mipmaps=[],this.mapping=t,this.channel=0,this.wrapS=n,this.wrapT=i,this.magFilter=r,this.minFilter=a,this.anisotropy=l,this.format=o,this.internalFormat=null,this.type=s,this.offset=new tn(0,0),this.repeat=new tn(1,1),this.center=new tn(0,0),this.rotation=0,this.matrixAutoUpdate=!0,this.matrix=new nn,this.generateMipmaps=!0,this.premultiplyAlpha=!1,this.flipY=!0,this.unpackAlignment=4,this.colorSpace=c,this.userData={},this.version=0,this.onUpdate=null,this.isRenderTargetTexture=!1,this.pmremVersion=0}get image(){return this.source.data}set image(e=null){this.source.data=e}updateMatrix(){this.matrix.setUvTransform(this.offset.x,this.offset.y,this.repeat.x,this.repeat.y,this.rotation,this.center.x,this.center.y)}clone(){return(new this.constructor).copy(this)}copy(e){return this.name=e.name,this.source=e.source,this.mipmaps=e.mipmaps.slice(0),this.mapping=e.mapping,this.channel=e.channel,this.wrapS=e.wrapS,this.wrapT=e.wrapT,this.magFilter=e.magFilter,this.minFilter=e.minFilter,this.anisotropy=e.anisotropy,this.format=e.format,this.internalFormat=e.internalFormat,this.type=e.type,this.offset.copy(e.offset),this.repeat.copy(e.repeat),this.center.copy(e.center),this.rotation=e.rotation,this.matrixAutoUpdate=e.matrixAutoUpdate,this.matrix.copy(e.matrix),this.generateMipmaps=e.generateMipmaps,this.premultiplyAlpha=e.premultiplyAlpha,this.flipY=e.flipY,this.unpackAlignment=e.unpackAlignment,this.colorSpace=e.colorSpace,this.userData=JSON.parse(JSON.stringify(e.userData)),this.needsUpdate=!0,this}toJSON(e){const t=void 0===e||"string"==typeof e;if(!t&&void 0!==e.textures[this.uuid])return e.textures[this.uuid];const n={metadata:{version:4.6,type:"Texture",generator:"Texture.toJSON"},uuid:this.uuid,name:this.name,image:this.source.toJSON(e).uuid,mapping:this.mapping,channel:this.channel,repeat:[this.repeat.x,this.repeat.y],offset:[this.offset.x,this.offset.y],center:[this.center.x,this.center.y],rotation:this.rotation,wrap:[this.wrapS,this.wrapT],format:this.format,internalFormat:this.internalFormat,type:this.type,colorSpace:this.colorSpace,minFilter:this.minFilter,magFilter:this.magFilter,anisotropy:this.anisotropy,flipY:this.flipY,generateMipmaps:this.generateMipmaps,premultiplyAlpha:this.premultiplyAlpha,unpackAlignment:this.unpackAlignment};return Object.keys(this.userData).length>0&&(n.userData=this.userData),t||(e.textures[this.uuid]=n),n}dispose(){this.dispatchEvent({type:"dispose"})}transformUv(e){if(300!==this.mapping)return e;if(e.applyMatrix3(this.matrix),e.x<0||e.x>1)switch(this.wrapS){case Oe:e.x=e.x-Math.floor(e.x);break;case ke:e.x=e.x<0?0:1;break;case Ge:1===Math.abs(Math.floor(e.x)%2)?e.x=Math.ceil(e.x)-e.x:e.x=e.x-Math.floor(e.x)}if(e.y<0||e.y>1)switch(this.wrapT){case Oe:e.y=e.y-Math.floor(e.y);break;case ke:e.y=e.y<0?0:1;break;case Ge:1===Math.abs(Math.floor(e.y)%2)?e.y=Math.ceil(e.y)-e.y:e.y=e.y-Math.floor(e.y)}return this.flipY&&(e.y=1-e.y),e}set needsUpdate(e){!0===e&&(this.version++,this.source.needsUpdate=!0)}set needsPMREMUpdate(e){!0===e&&this.pmremVersion++}}In.DEFAULT_IMAGE=null,In.DEFAULT_MAPPING=300,In.DEFAULT_ANISOTROPY=1;class xn{constructor(e=0,t=0,n=0,i=1){xn.prototype.isVector4=!0,this.x=e,this.y=t,this.z=n,this.w=i}get width(){return this.z}set width(e){this.z=e}get height(){return this.w}set height(e){this.w=e}set(e,t,n,i){return this.x=e,this.y=t,this.z=n,this.w=i,this}setScalar(e){return this.x=e,this.y=e,this.z=e,this.w=e,this}setX(e){return this.x=e,this}setY(e){return this.y=e,this}setZ(e){return this.z=e,this}setW(e){return this.w=e,this}setComponent(e,t){switch(e){case 0:this.x=t;break;case 1:this.y=t;break;case 2:this.z=t;break;case 3:this.w=t;break;default:throw new Error("index is out of range: "+e)}return this}getComponent(e){switch(e){case 0:return this.x;case 1:return this.y;case 2:return this.z;case 3:return this.w;default:throw new Error("index is out of range: "+e)}}clone(){return new this.constructor(this.x,this.y,this.z,this.w)}copy(e){return this.x=e.x,this.y=e.y,this.z=e.z,this.w=void 0!==e.w?e.w:1,this}add(e){return this.x+=e.x,this.y+=e.y,this.z+=e.z,this.w+=e.w,this}addScalar(e){return this.x+=e,this.y+=e,this.z+=e,this.w+=e,this}addVectors(e,t){return this.x=e.x+t.x,this.y=e.y+t.y,this.z=e.z+t.z,this.w=e.w+t.w,this}addScaledVector(e,t){return this.x+=e.x*t,this.y+=e.y*t,this.z+=e.z*t,this.w+=e.w*t,this}sub(e){return this.x-=e.x,this.y-=e.y,this.z-=e.z,this.w-=e.w,this}subScalar(e){return this.x-=e,this.y-=e,this.z-=e,this.w-=e,this}subVectors(e,t){return this.x=e.x-t.x,this.y=e.y-t.y,this.z=e.z-t.z,this.w=e.w-t.w,this}multiply(e){return this.x*=e.x,this.y*=e.y,this.z*=e.z,this.w*=e.w,this}multiplyScalar(e){return this.x*=e,this.y*=e,this.z*=e,this.w*=e,this}applyMatrix4(e){const t=this.x,n=this.y,i=this.z,r=this.w,a=e.elements;return this.x=a[0]*t+a[4]*n+a[8]*i+a[12]*r,this.y=a[1]*t+a[5]*n+a[9]*i+a[13]*r,this.z=a[2]*t+a[6]*n+a[10]*i+a[14]*r,this.w=a[3]*t+a[7]*n+a[11]*i+a[15]*r,this}divideScalar(e){return this.multiplyScalar(1/e)}setAxisAngleFromQuaternion(e){this.w=2*Math.acos(e.w);const t=Math.sqrt(1-e.w*e.w);return t<1e-4?(this.x=1,this.y=0,this.z=0):(this.x=e.x/t,this.y=e.y/t,this.z=e.z/t),this}setAxisAngleFromRotationMatrix(e){let t,n,i,r;const a=.01,o=.1,s=e.elements,l=s[0],c=s[4],h=s[8],A=s[1],u=s[5],d=s[9],p=s[2],f=s[6],g=s[10];if(Math.abs(c-A)<a&&Math.abs(h-p)<a&&Math.abs(d-f)<a){if(Math.abs(c+A)<o&&Math.abs(h+p)<o&&Math.abs(d+f)<o&&Math.abs(l+u+g-3)<o)return this.set(1,0,0,0),this;t=Math.PI;const e=(l+1)/2,s=(u+1)/2,m=(g+1)/2,v=(c+A)/4,E=(h+p)/4,b=(d+f)/4;return e>s&&e>m?e<a?(n=0,i=.707106781,r=.707106781):(n=Math.sqrt(e),i=v/n,r=E/n):s>m?s<a?(n=.707106781,i=0,r=.707106781):(i=Math.sqrt(s),n=v/i,r=b/i):m<a?(n=.707106781,i=.707106781,r=0):(r=Math.sqrt(m),n=E/r,i=b/r),this.set(n,i,r,t),this}let m=Math.sqrt((f-d)*(f-d)+(h-p)*(h-p)+(A-c)*(A-c));return Math.abs(m)<.001&&(m=1),this.x=(f-d)/m,this.y=(h-p)/m,this.z=(A-c)/m,this.w=Math.acos((l+u+g-1)/2),this}setFromMatrixPosition(e){const t=e.elements;return this.x=t[12],this.y=t[13],this.z=t[14],this.w=t[15],this}min(e){return this.x=Math.min(this.x,e.x),this.y=Math.min(this.y,e.y),this.z=Math.min(this.z,e.z),this.w=Math.min(this.w,e.w),this}max(e){return this.x=Math.max(this.x,e.x),this.y=Math.max(this.y,e.y),this.z=Math.max(this.z,e.z),this.w=Math.max(this.w,e.w),this}clamp(e,t){return this.x=Math.max(e.x,Math.min(t.x,this.x)),this.y=Math.max(e.y,Math.min(t.y,this.y)),this.z=Math.max(e.z,Math.min(t.z,this.z)),this.w=Math.max(e.w,Math.min(t.w,this.w)),this}clampScalar(e,t){return this.x=Math.max(e,Math.min(t,this.x)),this.y=Math.max(e,Math.min(t,this.y)),this.z=Math.max(e,Math.min(t,this.z)),this.w=Math.max(e,Math.min(t,this.w)),this}clampLength(e,t){const n=this.length();return this.divideScalar(n||1).multiplyScalar(Math.max(e,Math.min(t,n)))}floor(){return this.x=Math.floor(this.x),this.y=Math.floor(this.y),this.z=Math.floor(this.z),this.w=Math.floor(this.w),this}ceil(){return this.x=Math.ceil(this.x),this.y=Math.ceil(this.y),this.z=Math.ceil(this.z),this.w=Math.ceil(this.w),this}round(){return this.x=Math.round(this.x),this.y=Math.round(this.y),this.z=Math.round(this.z),this.w=Math.round(this.w),this}roundToZero(){return this.x=Math.trunc(this.x),this.y=Math.trunc(this.y),this.z=Math.trunc(this.z),this.w=Math.trunc(this.w),this}negate(){return this.x=-this.x,this.y=-this.y,this.z=-this.z,this.w=-this.w,this}dot(e){return this.x*e.x+this.y*e.y+this.z*e.z+this.w*e.w}lengthSq(){return this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w}length(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w)}manhattanLength(){return Math.abs(this.x)+Math.abs(this.y)+Math.abs(this.z)+Math.abs(this.w)}normalize(){return this.divideScalar(this.length()||1)}setLength(e){return this.normalize().multiplyScalar(e)}lerp(e,t){return this.x+=(e.x-this.x)*t,this.y+=(e.y-this.y)*t,this.z+=(e.z-this.z)*t,this.w+=(e.w-this.w)*t,this}lerpVectors(e,t,n){return this.x=e.x+(t.x-e.x)*n,this.y=e.y+(t.y-e.y)*n,this.z=e.z+(t.z-e.z)*n,this.w=e.w+(t.w-e.w)*n,this}equals(e){return e.x===this.x&&e.y===this.y&&e.z===this.z&&e.w===this.w}fromArray(e,t=0){return this.x=e[t],this.y=e[t+1],this.z=e[t+2],this.w=e[t+3],this}toArray(e=[],t=0){return e[t]=this.x,e[t+1]=this.y,e[t+2]=this.z,e[t+3]=this.w,e}fromBufferAttribute(e,t){return this.x=e.getX(t),this.y=e.getY(t),this.z=e.getZ(t),this.w=e.getW(t),this}random(){return this.x=Math.random(),this.y=Math.random(),this.z=Math.random(),this.w=Math.random(),this}*[Symbol.iterator](){yield this.x,yield this.y,yield this.z,yield this.w}}class yn extends Ht{constructor(e=1,t=1,n={}){super(),this.isRenderTarget=!0,this.width=e,this.height=t,this.depth=1,this.scissor=new xn(0,0,e,t),this.scissorTest=!1,this.viewport=new xn(0,0,e,t);const i={width:e,height:t,depth:1};n=Object.assign({generateMipmaps:!1,internalFormat:null,minFilter:We,depthBuffer:!0,stencilBuffer:!1,resolveDepthBuffer:!0,resolveStencilBuffer:!0,depthTexture:null,samples:0,count:1},n);const r=new In(i,n.mapping,n.wrapS,n.wrapT,n.magFilter,n.minFilter,n.format,n.type,n.anisotropy,n.colorSpace);r.flipY=!1,r.generateMipmaps=n.generateMipmaps,r.internalFormat=n.internalFormat,this.textures=[];const a=n.count;for(let e=0;e<a;e++)this.textures[e]=r.clone(),this.textures[e].isRenderTargetTexture=!0;this.depthBuffer=n.depthBuffer,this.stencilBuffer=n.stencilBuffer,this.resolveDepthBuffer=n.resolveDepthBuffer,this.resolveStencilBuffer=n.resolveStencilBuffer,this.depthTexture=n.depthTexture,this.samples=n.samples}get texture(){return this.textures[0]}set texture(e){this.textures[0]=e}setSize(e,t,n=1){if(this.width!==e||this.height!==t||this.depth!==n){this.width=e,this.height=t,this.depth=n;for(let i=0,r=this.textures.length;i<r;i++)this.textures[i].image.width=e,this.textures[i].image.height=t,this.textures[i].image.depth=n;this.dispose()}this.viewport.set(0,0,e,t),this.scissor.set(0,0,e,t)}clone(){return(new this.constructor).copy(this)}copy(e){this.width=e.width,this.height=e.height,this.depth=e.depth,this.scissor.copy(e.scissor),this.scissorTest=e.scissorTest,this.viewport.copy(e.viewport),this.textures.length=0;for(let t=0,n=e.textures.length;t<n;t++)this.textures[t]=e.textures[t].clone(),this.textures[t].isRenderTargetTexture=!0;const t=Object.assign({},e.texture.image);return this.texture.source=new bn(t),this.depthBuffer=e.depthBuffer,this.stencilBuffer=e.stencilBuffer,this.resolveDepthBuffer=e.resolveDepthBuffer,this.resolveStencilBuffer=e.resolveStencilBuffer,null!==e.depthTexture&&(this.depthTexture=e.depthTexture.clone()),this.samples=e.samples,this}dispose(){this.dispatchEvent({type:"dispose"})}}class Mn extends yn{constructor(e=1,t=1,n={}){super(e,t,n),this.isWebGLRenderTarget=!0}}class wn extends In{constructor(e=null,t=1,n=1,i=1){super(null),this.isDataArrayTexture=!0,this.image={data:e,width:t,height:n,depth:i},this.magFilter=He,this.minFilter=He,this.wrapR=ke,this.generateMipmaps=!1,this.flipY=!1,this.unpackAlignment=1,this.layerUpdates=new Set}addLayerUpdate(e){this.layerUpdates.add(e)}clearLayerUpdates(){this.layerUpdates.clear()}}class Sn extends In{constructor(e=null,t=1,n=1,i=1){super(null),this.isData3DTexture=!0,this.image={data:e,width:t,height:n,depth:i},this.magFilter=He,this.minFilter=He,this.wrapR=ke,this.generateMipmaps=!1,this.flipY=!1,this.unpackAlignment=1}}class Bn{constructor(e=0,t=0,n=0,i=1){this.isQuaternion=!0,this._x=e,this._y=t,this._z=n,this._w=i}static slerpFlat(e,t,n,i,r,a,o){let s=n[i+0],l=n[i+1],c=n[i+2],h=n[i+3];const A=r[a+0],u=r[a+1],d=r[a+2],p=r[a+3];if(0===o)return e[t+0]=s,e[t+1]=l,e[t+2]=c,void(e[t+3]=h);if(1===o)return e[t+0]=A,e[t+1]=u,e[t+2]=d,void(e[t+3]=p);if(h!==p||s!==A||l!==u||c!==d){let e=1-o;const t=s*A+l*u+c*d+h*p,n=t>=0?1:-1,i=1-t*t;if(i>Number.EPSILON){const r=Math.sqrt(i),a=Math.atan2(r,t*n);e=Math.sin(e*a)/r,o=Math.sin(o*a)/r}const r=o*n;if(s=s*e+A*r,l=l*e+u*r,c=c*e+d*r,h=h*e+p*r,e===1-o){const e=1/Math.sqrt(s*s+l*l+c*c+h*h);s*=e,l*=e,c*=e,h*=e}}e[t]=s,e[t+1]=l,e[t+2]=c,e[t+3]=h}static multiplyQuaternionsFlat(e,t,n,i,r,a){const o=n[i],s=n[i+1],l=n[i+2],c=n[i+3],h=r[a],A=r[a+1],u=r[a+2],d=r[a+3];return e[t]=o*d+c*h+s*u-l*A,e[t+1]=s*d+c*A+l*h-o*u,e[t+2]=l*d+c*u+o*A-s*h,e[t+3]=c*d-o*h-s*A-l*u,e}get x(){return this._x}set x(e){this._x=e,this._onChangeCallback()}get y(){return this._y}set y(e){this._y=e,this._onChangeCallback()}get z(){return this._z}set z(e){this._z=e,this._onChangeCallback()}get w(){return this._w}set w(e){this._w=e,this._onChangeCallback()}set(e,t,n,i){return this._x=e,this._y=t,this._z=n,this._w=i,this._onChangeCallback(),this}clone(){return new this.constructor(this._x,this._y,this._z,this._w)}copy(e){return this._x=e.x,this._y=e.y,this._z=e.z,this._w=e.w,this._onChangeCallback(),this}setFromEuler(e,t=!0){const n=e._x,i=e._y,r=e._z,a=e._order,o=Math.cos,s=Math.sin,l=o(n/2),c=o(i/2),h=o(r/2),A=s(n/2),u=s(i/2),d=s(r/2);switch(a){case"XYZ":this._x=A*c*h+l*u*d,this._y=l*u*h-A*c*d,this._z=l*c*d+A*u*h,this._w=l*c*h-A*u*d;break;case"YXZ":this._x=A*c*h+l*u*d,this._y=l*u*h-A*c*d,this._z=l*c*d-A*u*h,this._w=l*c*h+A*u*d;break;case"ZXY":this._x=A*c*h-l*u*d,this._y=l*u*h+A*c*d,this._z=l*c*d+A*u*h,this._w=l*c*h-A*u*d;break;case"ZYX":this._x=A*c*h-l*u*d,this._y=l*u*h+A*c*d,this._z=l*c*d-A*u*h,this._w=l*c*h+A*u*d;break;case"YZX":this._x=A*c*h+l*u*d,this._y=l*u*h+A*c*d,this._z=l*c*d-A*u*h,this._w=l*c*h-A*u*d;break;case"XZY":this._x=A*c*h-l*u*d,this._y=l*u*h-A*c*d,this._z=l*c*d+A*u*h,this._w=l*c*h+A*u*d;break;default:console.warn("THREE.Quaternion: .setFromEuler() encountered an unknown order: "+a)}return!0===t&&this._onChangeCallback(),this}setFromAxisAngle(e,t){const n=t/2,i=Math.sin(n);return this._x=e.x*i,this._y=e.y*i,this._z=e.z*i,this._w=Math.cos(n),this._onChangeCallback(),this}setFromRotationMatrix(e){const t=e.elements,n=t[0],i=t[4],r=t[8],a=t[1],o=t[5],s=t[9],l=t[2],c=t[6],h=t[10],A=n+o+h;if(A>0){const e=.5/Math.sqrt(A+1);this._w=.25/e,this._x=(c-s)*e,this._y=(r-l)*e,this._z=(a-i)*e}else if(n>o&&n>h){const e=2*Math.sqrt(1+n-o-h);this._w=(c-s)/e,this._x=.25*e,this._y=(i+a)/e,this._z=(r+l)/e}else if(o>h){const e=2*Math.sqrt(1+o-n-h);this._w=(r-l)/e,this._x=(i+a)/e,this._y=.25*e,this._z=(s+c)/e}else{const e=2*Math.sqrt(1+h-n-o);this._w=(a-i)/e,this._x=(r+l)/e,this._y=(s+c)/e,this._z=.25*e}return this._onChangeCallback(),this}setFromUnitVectors(e,t){let n=e.dot(t)+1;return n<Number.EPSILON?(n=0,Math.abs(e.x)>Math.abs(e.z)?(this._x=-e.y,this._y=e.x,this._z=0,this._w=n):(this._x=0,this._y=-e.z,this._z=e.y,this._w=n)):(this._x=e.y*t.z-e.z*t.y,this._y=e.z*t.x-e.x*t.z,this._z=e.x*t.y-e.y*t.x,this._w=n),this.normalize()}angleTo(e){return 2*Math.acos(Math.abs(jt(this.dot(e),-1,1)))}rotateTowards(e,t){const n=this.angleTo(e);if(0===n)return this;const i=Math.min(1,t/n);return this.slerp(e,i),this}identity(){return this.set(0,0,0,1)}invert(){return this.conjugate()}conjugate(){return this._x*=-1,this._y*=-1,this._z*=-1,this._onChangeCallback(),this}dot(e){return this._x*e._x+this._y*e._y+this._z*e._z+this._w*e._w}lengthSq(){return this._x*this._x+this._y*this._y+this._z*this._z+this._w*this._w}length(){return Math.sqrt(this._x*this._x+this._y*this._y+this._z*this._z+this._w*this._w)}normalize(){let e=this.length();return 0===e?(this._x=0,this._y=0,this._z=0,this._w=1):(e=1/e,this._x=this._x*e,this._y=this._y*e,this._z=this._z*e,this._w=this._w*e),this._onChangeCallback(),this}multiply(e){return this.multiplyQuaternions(this,e)}premultiply(e){return this.multiplyQuaternions(e,this)}multiplyQuaternions(e,t){const n=e._x,i=e._y,r=e._z,a=e._w,o=t._x,s=t._y,l=t._z,c=t._w;return this._x=n*c+a*o+i*l-r*s,this._y=i*c+a*s+r*o-n*l,this._z=r*c+a*l+n*s-i*o,this._w=a*c-n*o-i*s-r*l,this._onChangeCallback(),this}slerp(e,t){if(0===t)return this;if(1===t)return this.copy(e);const n=this._x,i=this._y,r=this._z,a=this._w;let o=a*e._w+n*e._x+i*e._y+r*e._z;if(o<0?(this._w=-e._w,this._x=-e._x,this._y=-e._y,this._z=-e._z,o=-o):this.copy(e),o>=1)return this._w=a,this._x=n,this._y=i,this._z=r,this;const s=1-o*o;if(s<=Number.EPSILON){const e=1-t;return this._w=e*a+t*this._w,this._x=e*n+t*this._x,this._y=e*i+t*this._y,this._z=e*r+t*this._z,this.normalize(),this}const l=Math.sqrt(s),c=Math.atan2(l,o),h=Math.sin((1-t)*c)/l,A=Math.sin(t*c)/l;return this._w=a*h+this._w*A,this._x=n*h+this._x*A,this._y=i*h+this._y*A,this._z=r*h+this._z*A,this._onChangeCallback(),this}slerpQuaternions(e,t,n){return this.copy(e).slerp(t,n)}random(){const e=2*Math.PI*Math.random(),t=2*Math.PI*Math.random(),n=Math.random(),i=Math.sqrt(1-n),r=Math.sqrt(n);return this.set(i*Math.sin(e),i*Math.cos(e),r*Math.sin(t),r*Math.cos(t))}equals(e){return e._x===this._x&&e._y===this._y&&e._z===this._z&&e._w===this._w}fromArray(e,t=0){return this._x=e[t],this._y=e[t+1],this._z=e[t+2],this._w=e[t+3],this._onChangeCallback(),this}toArray(e=[],t=0){return e[t]=this._x,e[t+1]=this._y,e[t+2]=this._z,e[t+3]=this._w,e}fromBufferAttribute(e,t){return this._x=e.getX(t),this._y=e.getY(t),this._z=e.getZ(t),this._w=e.getW(t),this._onChangeCallback(),this}toJSON(){return this.toArray()}_onChange(e){return this._onChangeCallback=e,this}_onChangeCallback(){}*[Symbol.iterator](){yield this._x,yield this._y,yield this._z,yield this._w}}class Tn{constructor(e=0,t=0,n=0){Tn.prototype.isVector3=!0,this.x=e,this.y=t,this.z=n}set(e,t,n){return void 0===n&&(n=this.z),this.x=e,this.y=t,this.z=n,this}setScalar(e){return this.x=e,this.y=e,this.z=e,this}setX(e){return this.x=e,this}setY(e){return this.y=e,this}setZ(e){return this.z=e,this}setComponent(e,t){switch(e){case 0:this.x=t;break;case 1:this.y=t;break;case 2:this.z=t;break;default:throw new Error("index is out of range: "+e)}return this}getComponent(e){switch(e){case 0:return this.x;case 1:return this.y;case 2:return this.z;default:throw new Error("index is out of range: "+e)}}clone(){return new this.constructor(this.x,this.y,this.z)}copy(e){return this.x=e.x,this.y=e.y,this.z=e.z,this}add(e){return this.x+=e.x,this.y+=e.y,this.z+=e.z,this}addScalar(e){return this.x+=e,this.y+=e,this.z+=e,this}addVectors(e,t){return this.x=e.x+t.x,this.y=e.y+t.y,this.z=e.z+t.z,this}addScaledVector(e,t){return this.x+=e.x*t,this.y+=e.y*t,this.z+=e.z*t,this}sub(e){return this.x-=e.x,this.y-=e.y,this.z-=e.z,this}subScalar(e){return this.x-=e,this.y-=e,this.z-=e,this}subVectors(e,t){return this.x=e.x-t.x,this.y=e.y-t.y,this.z=e.z-t.z,this}multiply(e){return this.x*=e.x,this.y*=e.y,this.z*=e.z,this}multiplyScalar(e){return this.x*=e,this.y*=e,this.z*=e,this}multiplyVectors(e,t){return this.x=e.x*t.x,this.y=e.y*t.y,this.z=e.z*t.z,this}applyEuler(e){return this.applyQuaternion(Dn.setFromEuler(e))}applyAxisAngle(e,t){return this.applyQuaternion(Dn.setFromAxisAngle(e,t))}applyMatrix3(e){const t=this.x,n=this.y,i=this.z,r=e.elements;return this.x=r[0]*t+r[3]*n+r[6]*i,this.y=r[1]*t+r[4]*n+r[7]*i,this.z=r[2]*t+r[5]*n+r[8]*i,this}applyNormalMatrix(e){return this.applyMatrix3(e).normalize()}applyMatrix4(e){const t=this.x,n=this.y,i=this.z,r=e.elements,a=1/(r[3]*t+r[7]*n+r[11]*i+r[15]);return this.x=(r[0]*t+r[4]*n+r[8]*i+r[12])*a,this.y=(r[1]*t+r[5]*n+r[9]*i+r[13])*a,this.z=(r[2]*t+r[6]*n+r[10]*i+r[14])*a,this}applyQuaternion(e){const t=this.x,n=this.y,i=this.z,r=e.x,a=e.y,o=e.z,s=e.w,l=2*(a*i-o*n),c=2*(o*t-r*i),h=2*(r*n-a*t);return this.x=t+s*l+a*h-o*c,this.y=n+s*c+o*l-r*h,this.z=i+s*h+r*c-a*l,this}project(e){return this.applyMatrix4(e.matrixWorldInverse).applyMatrix4(e.projectionMatrix)}unproject(e){return this.applyMatrix4(e.projectionMatrixInverse).applyMatrix4(e.matrixWorld)}transformDirection(e){const t=this.x,n=this.y,i=this.z,r=e.elements;return this.x=r[0]*t+r[4]*n+r[8]*i,this.y=r[1]*t+r[5]*n+r[9]*i,this.z=r[2]*t+r[6]*n+r[10]*i,this.normalize()}divide(e){return this.x/=e.x,this.y/=e.y,this.z/=e.z,this}divideScalar(e){return this.multiplyScalar(1/e)}min(e){return this.x=Math.min(this.x,e.x),this.y=Math.min(this.y,e.y),this.z=Math.min(this.z,e.z),this}max(e){return this.x=Math.max(this.x,e.x),this.y=Math.max(this.y,e.y),this.z=Math.max(this.z,e.z),this}clamp(e,t){return this.x=Math.max(e.x,Math.min(t.x,this.x)),this.y=Math.max(e.y,Math.min(t.y,this.y)),this.z=Math.max(e.z,Math.min(t.z,this.z)),this}clampScalar(e,t){return this.x=Math.max(e,Math.min(t,this.x)),this.y=Math.max(e,Math.min(t,this.y)),this.z=Math.max(e,Math.min(t,this.z)),this}clampLength(e,t){const n=this.length();return this.divideScalar(n||1).multiplyScalar(Math.max(e,Math.min(t,n)))}floor(){return this.x=Math.floor(this.x),this.y=Math.floor(this.y),this.z=Math.floor(this.z),this}ceil(){return this.x=Math.ceil(this.x),this.y=Math.ceil(this.y),this.z=Math.ceil(this.z),this}round(){return this.x=Math.round(this.x),this.y=Math.round(this.y),this.z=Math.round(this.z),this}roundToZero(){return this.x=Math.trunc(this.x),this.y=Math.trunc(this.y),this.z=Math.trunc(this.z),this}negate(){return this.x=-this.x,this.y=-this.y,this.z=-this.z,this}dot(e){return this.x*e.x+this.y*e.y+this.z*e.z}lengthSq(){return this.x*this.x+this.y*this.y+this.z*this.z}length(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z)}manhattanLength(){return Math.abs(this.x)+Math.abs(this.y)+Math.abs(this.z)}normalize(){return this.divideScalar(this.length()||1)}setLength(e){return this.normalize().multiplyScalar(e)}lerp(e,t){return this.x+=(e.x-this.x)*t,this.y+=(e.y-this.y)*t,this.z+=(e.z-this.z)*t,this}lerpVectors(e,t,n){return this.x=e.x+(t.x-e.x)*n,this.y=e.y+(t.y-e.y)*n,this.z=e.z+(t.z-e.z)*n,this}cross(e){return this.crossVectors(this,e)}crossVectors(e,t){const n=e.x,i=e.y,r=e.z,a=t.x,o=t.y,s=t.z;return this.x=i*s-r*o,this.y=r*a-n*s,this.z=n*o-i*a,this}projectOnVector(e){const t=e.lengthSq();if(0===t)return this.set(0,0,0);const n=e.dot(this)/t;return this.copy(e).multiplyScalar(n)}projectOnPlane(e){return Rn.copy(this).projectOnVector(e),this.sub(Rn)}reflect(e){return this.sub(Rn.copy(e).multiplyScalar(2*this.dot(e)))}angleTo(e){const t=Math.sqrt(this.lengthSq()*e.lengthSq());if(0===t)return Math.PI/2;const n=this.dot(e)/t;return Math.acos(jt(n,-1,1))}distanceTo(e){return Math.sqrt(this.distanceToSquared(e))}distanceToSquared(e){const t=this.x-e.x,n=this.y-e.y,i=this.z-e.z;return t*t+n*n+i*i}manhattanDistanceTo(e){return Math.abs(this.x-e.x)+Math.abs(this.y-e.y)+Math.abs(this.z-e.z)}setFromSpherical(e){return this.setFromSphericalCoords(e.radius,e.phi,e.theta)}setFromSphericalCoords(e,t,n){const i=Math.sin(t)*e;return this.x=i*Math.sin(n),this.y=Math.cos(t)*e,this.z=i*Math.cos(n),this}setFromCylindrical(e){return this.setFromCylindricalCoords(e.radius,e.theta,e.y)}setFromCylindricalCoords(e,t,n){return this.x=e*Math.sin(t),this.y=n,this.z=e*Math.cos(t),this}setFromMatrixPosition(e){const t=e.elements;return this.x=t[12],this.y=t[13],this.z=t[14],this}setFromMatrixScale(e){const t=this.setFromMatrixColumn(e,0).length(),n=this.setFromMatrixColumn(e,1).length(),i=this.setFromMatrixColumn(e,2).length();return this.x=t,this.y=n,this.z=i,this}setFromMatrixColumn(e,t){return this.fromArray(e.elements,4*t)}setFromMatrix3Column(e,t){return this.fromArray(e.elements,3*t)}setFromEuler(e){return this.x=e._x,this.y=e._y,this.z=e._z,this}setFromColor(e){return this.x=e.r,this.y=e.g,this.z=e.b,this}equals(e){return e.x===this.x&&e.y===this.y&&e.z===this.z}fromArray(e,t=0){return this.x=e[t],this.y=e[t+1],this.z=e[t+2],this}toArray(e=[],t=0){return e[t]=this.x,e[t+1]=this.y,e[t+2]=t