"use strict";var V=Object.defineProperty;var k=(v,r,s)=>r in v?V(v,r,{enumerable:!0,configurable:!0,writable:!0,value:s}):v[r]=s;var O=(v,r,s)=>(k(v,typeof r!="symbol"?r+"":r,s),s);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});class S{constructor(r=[0,0,0]){O(this,"elements");this.elements=new Float32Array(r.slice(0,3))}normalize(){const r=this.elements,[s,e,n]=r,t=Math.sqrt(s*s+e*e+n*n);if(t){if(t===1)return this}else return r[0]=0,r[1]=0,r[2]=0,this;const l=1/t;return r[0]=s*l,r[1]=e*l,r[2]=n*l,this}}class j{constructor(r=[0,0,0,0]){O(this,"elements");this.elements=new Float32Array(r.slice(0,4))}}class A{constructor(r){let s,e,n;if(r&&typeof r=="object"&&r.hasOwnProperty("elements")){for(e=r.elements,n=new Float32Array(16),s=0;s<16;++s)n[s]=e[s];this.elements=n}else this.elements=new Float32Array([1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1])}setIdentity(){let r=this.elements;return r[0]=1,r[4]=0,r[8]=0,r[12]=0,r[1]=0,r[5]=1,r[9]=0,r[13]=0,r[2]=0,r[6]=0,r[10]=1,r[14]=0,r[3]=0,r[7]=0,r[11]=0,r[15]=1,this}set(r){let s,e,n;if(e=r.elements,n=this.elements,e!==n){for(s=0;s<16;++s)n[s]=e[s];return this}}concat(r){let s,e,n,t,l,i,h,o;if(e=this.elements,n=this.elements,t=r.elements,e===t)for(t=new Float32Array(16),s=0;s<16;++s)t[s]=e[s];for(s=0;s<4;s++)l=n[s],i=n[s+4],h=n[s+8],o=n[s+12],e[s]=l*t[0]+i*t[1]+h*t[2]+o*t[3],e[s+4]=l*t[4]+i*t[5]+h*t[6]+o*t[7],e[s+8]=l*t[8]+i*t[9]+h*t[10]+o*t[11],e[s+12]=l*t[12]+i*t[13]+h*t[14]+o*t[15];return this}multiply(...r){this.concat(...r)}multiplyVector3(r){let s=this.elements,e=r.elements,n=new S,t=n.elements;return t[0]=e[0]*s[0]+e[1]*s[4]+e[2]*s[8]+s[12],t[1]=e[0]*s[1]+e[1]*s[5]+e[2]*s[9]+s[13],t[2]=e[0]*s[2]+e[1]*s[6]+e[2]*s[10]+s[14],n}multiplyVector4(r){let s=this.elements,e=r.elements,n=new j,t=n.elements;return t[0]=e[0]*s[0]+e[1]*s[4]+e[2]*s[8]+e[3]*s[12],t[1]=e[0]*s[1]+e[1]*s[5]+e[2]*s[9]+e[3]*s[13],t[2]=e[0]*s[2]+e[1]*s[6]+e[2]*s[10]+e[3]*s[14],t[3]=e[0]*s[3]+e[1]*s[7]+e[2]*s[11]+e[3]*s[15],n}transpose(){let r,s;return r=this.elements,s=r[1],r[1]=r[4],r[4]=s,s=r[2],r[2]=r[8],r[8]=s,s=r[3],r[3]=r[12],r[12]=s,s=r[6],r[6]=r[9],r[9]=s,s=r[7],r[7]=r[13],r[13]=s,s=r[11],r[11]=r[14],r[14]=s,this}setInverseOf(r){let s,e,n,t,l;if(e=r.elements,n=this.elements,t=new Float32Array(16),t[0]=e[5]*e[10]*e[15]-e[5]*e[11]*e[14]-e[9]*e[6]*e[15]+e[9]*e[7]*e[14]+e[13]*e[6]*e[11]-e[13]*e[7]*e[10],t[4]=-e[4]*e[10]*e[15]+e[4]*e[11]*e[14]+e[8]*e[6]*e[15]-e[8]*e[7]*e[14]-e[12]*e[6]*e[11]+e[12]*e[7]*e[10],t[8]=e[4]*e[9]*e[15]-e[4]*e[11]*e[13]-e[8]*e[5]*e[15]+e[8]*e[7]*e[13]+e[12]*e[5]*e[11]-e[12]*e[7]*e[9],t[12]=-e[4]*e[9]*e[14]+e[4]*e[10]*e[13]+e[8]*e[5]*e[14]-e[8]*e[6]*e[13]-e[12]*e[5]*e[10]+e[12]*e[6]*e[9],t[1]=-e[1]*e[10]*e[15]+e[1]*e[11]*e[14]+e[9]*e[2]*e[15]-e[9]*e[3]*e[14]-e[13]*e[2]*e[11]+e[13]*e[3]*e[10],t[5]=e[0]*e[10]*e[15]-e[0]*e[11]*e[14]-e[8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[2]*t[8]+e[3]*t[12],l===0)return this;for(l=1/l,s=0;s<16;s++)n[s]=t[s]*l;return this}invert(){return this.setInverseOf(this)}setOrtho(r,s,e,n,t,l){let i,h,o,u;if(r===s||e===n||t===l)throw"null frustum";return h=1/(s-r),o=1/(n-e),u=1/(l-t),i=this.elements,i[0]=2*h,i[1]=0,i[2]=0,i[3]=0,i[4]=0,i[5]=2*o,i[6]=0,i[7]=0,i[8]=0,i[9]=0,i[10]=-2*u,i[11]=0,i[12]=-(s+r)*h,i[13]=-(n+e)*o,i[14]=-(l+t)*u,i[15]=1,this}ortho(r,s,e,n,t,l){return this.concat(new A().setOrtho(r,s,e,n,t,l))}setFrustum(r,s,e,n,t,l){let i,h,o,u;if(r===s||n===e||t===l)throw"null frustum";if(t<=0)throw"near <= 0";if(l<=0)throw"far <= 0";return h=1/(s-r),o=1/(n-e),u=1/(l-t),i=this.elements,i[0]=2*t*h,i[1]=0,i[2]=0,i[3]=0,i[4]=0,i[5]=2*t*o,i[6]=0,i[7]=0,i[8]=(s+r)*h,i[9]=(n+e)*o,i[10]=-(l+t)*u,i[11]=-1,i[12]=0,i[13]=0,i[14]=-2*t*l*u,i[15]=0,this}frustum(r,s,e,n,t,l){return this.concat(new A().setFrustum(r,s,e,n,t,l))}setPerspective(r,s,e,n){let t,l,i,h;if(e===n||s===0)throw"null frustum";if(e<=0)throw"near <= 0";if(n<=0)throw"far <= 0";if(r=Math.PI*r/180/2,i=Math.sin(r),i===0)throw"null frustum";return l=1/(n-e),h=Math.cos(r)/i,t=this.elements,t[0]=h/s,t[1]=0,t[2]=0,t[3]=0,t[4]=0,t[5]=h,t[6]=0,t[7]=0,t[8]=0,t[9]=0,t[10]=-(n+e)*l,t[11]=-1,t[12]=0,t[13]=0,t[14]=-2*e*n*l,t[15]=0,this}perspective(r,s,e,n){return this.concat(new A().setPerspective(r,s,e,n))}setScale(r,s,e){let n=this.elements;return n[0]=r,n[4]=0,n[8]=0,n[12]=0,n[1]=0,n[5]=s,n[9]=0,n[13]=0,n[2]=0,n[6]=0,n[10]=e,n[14]=0,n[3]=0,n[7]=0,n[11]=0,n[15]=1,this}scale(r,s,e){let n=this.elements;return n[0]*=r,n[4]*=s,n[8]*=e,n[1]*=r,n[5]*=s,n[9]*=e,n[2]*=r,n[6]*=s,n[10]*=e,n[3]*=r,n[7]*=s,n[11]*=e,this}setTranslate(r,s,e){let n=this.elements;return n[0]=1,n[4]=0,n[8]=0,n[12]=r,n[1]=0,n[5]=1,n[9]=0,n[13]=s,n[2]=0,n[6]=0,n[10]=1,n[14]=e,n[3]=0,n[7]=0,n[11]=0,n[15]=1,this}translate(r,s,e){let n=this.elements;return n[12]+=n[0]*r+n[4]*s+n[8]*e,n[13]+=n[1]*r+n[5]*s+n[9]*e,n[14]+=n[2]*r+n[6]*s+n[10]*e,n[15]+=n[3]*r+n[7]*s+n[11]*e,this}setRotate(r,s,e,n){let t,l,i,h,o,u,c,m,w,a,f,d;return r=Math.PI*r/180,t=this.elements,l=Math.sin(r),i=Math.cos(r),s!==0&&e===0&&n===0?(s<0&&(l=-l),t[0]=1,t[4]=0,t[8]=0,t[12]=0,t[1]=0,t[5]=i,t[9]=-l,t[13]=0,t[2]=0,t[6]=l,t[10]=i,t[14]=0,t[3]=0,t[7]=0,t[11]=0,t[15]=1):s===0&&e!==0&&n===0?(e<0&&(l=-l),t[0]=i,t[4]=0,t[8]=l,t[12]=0,t[1]=0,t[5]=1,t[9]=0,t[13]=0,t[2]=-l,t[6]=0,t[10]=i,t[14]=0,t[3]=0,t[7]=0,t[11]=0,t[15]=1):s===0&&e===0&&n!==0?(n<0&&(l=-l),t[0]=i,t[4]=-l,t[8]=0,t[12]=0,t[1]=l,t[5]=i,t[9]=0,t[13]=0,t[2]=0,t[6]=0,t[10]=1,t[14]=0,t[3]=0,t[7]=0,t[11]=0,t[15]=1):(h=Math.sqrt(s*s+e*e+n*n),h!==1&&(o=1/h,s*=o,e*=o,n*=o),u=1-i,c=s*e,m=e*n,w=n*s,a=s*l,f=e*l,d=n*l,t[0]=s*s*u+i,t[1]=c*u+d,t[2]=w*u-f,t[3]=0,t[4]=c*u-d,t[5]=e*e*u+i,t[6]=m*u+a,t[7]=0,t[8]=w*u+f,t[9]=m*u-a,t[10]=n*n*u+i,t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1),this}rotate(r,s,e,n){return this.concat(new A().setRotate(r,s,e,n))}setLookAt(r,s,e,n,t,l,i,h,o){let u,c,m,w,a,f,d,F,M,P,I,q;return c=n-r,m=t-s,w=l-e,a=1/Math.sqrt(c*c+m*m+w*w),c*=a,m*=a,w*=a,f=m*o-w*h,d=w*i-c*o,F=c*h-m*i,M=1/Math.sqrt(f*f+d*d+F*F),f*=M,d*=M,F*=M,P=d*w-F*m,I=F*c-f*w,q=f*m-d*c,u=this.elements,u[0]=f,u[1]=P,u[2]=-c,u[3]=0,u[4]=d,u[5]=I,u[6]=-m,u[7]=0,u[8]=F,u[9]=q,u[10]=-w,u[11]=0,u[12]=0,u[13]=0,u[14]=0,u[15]=1,this.translate(-r,-s,-e)}lookAt(r,s,e,n,t,l,i,h,o){return this.concat(new A().setLookAt(r,s,e,n,t,l,i,h,o))}dropShadow(r,s){const e=new A;let n=e.elements,t=r[0]*s[0]+r[1]*s[1]+r[2]*s[2]+r[3]*s[3];return n[0]=t-s[0]*r[0],n[1]=-s[1]*r[0],n[2]=-s[2]*r[0],n[3]=-s[3]*r[0],n[4]=-s[0]*r[1],n[5]=t-s[1]*r[1],n[6]=-s[2]*r[1],n[7]=-s[3]*r[1],n[8]=-s[0]*r[2],n[9]=-s[1]*r[2],n[10]=t-s[2]*r[2],n[11]=-s[3]*r[2],n[12]=-s[0]*r[3],n[13]=-s[1]*r[3],n[14]=-s[2]*r[3],n[15]=t-s[3]*r[3],this.concat(e)}dropShadowDirectionally(r,s,e,n,t,l,i,h,o){let u=n*r+t*s+l*e;return this.dropShadow([r,s,e,-u],[i,h,o,0])}}exports.Matrix4=A;