audio-vis/out/js/scripts.min.js

1 line
37 KiB
JavaScript
Raw Permalink Normal View History

2020-08-08 21:58:15 +02:00
class VTUtils{static random(e,t){let a=Math.random();if(void 0===e)return a;if(void 0===t)return e instanceof Array?e[Math.floor(a*e.length)]:a*e;if(e>t){let a=e;e=t,t=a}return a*(t-e)+e}static randomInt(e,t){return Math.floor(VTUtils.random(e,t))}static normalize(e,t,a){return(e-a)/(t-a)}static distance(e,t,a,i){let s=e-a,n=t-i;return Math.sqrt(s*s+n*n)}static map(e,t,a,i,s,n){let r=(e-t)/(a-t)*(s-i)+i;return n?i<s?this.constrain(r,i,s):this.constrain(r,s,i):r}static constrain(e,t,a){return Math.max(Math.min(e,a),t)}static hsvToRgb(e,t,a){let i,s,n,r=Math.floor(6*e),l=6*e-r,o=a*(1-t),d=a*(1-l*t),c=a*(1-(1-l)*t);switch(r%6){case 0:i=a,s=c,n=o;break;case 1:i=d,s=a,n=o;break;case 2:i=o,s=a,n=c;break;case 3:i=o,s=d,n=a;break;case 4:i=c,s=o,n=a;break;case 5:i=a,s=o,n=d}return{r:i,g:s,b:n}}static peakRGB(e){return{r:e,g:1-e,b:0}}}class VTVector{constructor(e,t,a){this.x=e||0,this.y=t||0,this.z=a||0}static createRandom(e,t,a){return e=e||1,t=t||1,a=a||0,new VTVector(VTUtils.random(-e,e),VTUtils.random(-t,t),VTUtils.random(-a,a))}mult(e){this.x*=e,this.y*=e,this.z*=e}set(e){this.x=e.x,this.y=e.y,this.z=e.z}add(e){this.x=this.x+e.x,this.y=this.y+e.y,this.z=this.z+e.z}addXYZ(e,t,a){this.x+=e,this.y+=t,this.z+=a}setXYZ(e,t,a){this.x=e||0,this.y=t||0,this.z=a||0}clone(){return new VTVector(this.x,this.y,this.z)}}function $(e,t){return(t=t||document).querySelector(e)}function $$(e,t){return(t=t||document).querySelectorAll(e)}function b64toBlob(e,t){const a=atob(e),i=new Array(a.length);for(let e=0;e<a.length;e++)i[e]=a.charCodeAt(e);const s=new Uint8Array(i);return new Blob([s],{type:t})}function create(e,t){let a=document.createElement(e);return t&&(a.innerHTML=t),a}function append(e,t){for(let a of t)e.appendChild(a)}function hexToRgb(e){e=e.replace("#","");let t=parseInt(e,16);return[(t>>16&255)/255,(t>>8&255)/255,(255&t)/255]}Node.prototype.addDelegatedEventListener=function(e,t,a){this.addEventListener(e,e=>{let i=e.target;if(i.matches(t))a(e,i);else{let s=i.closest(t);if(s)try{a(e,s)}catch(e){NotificationHandler.createNotification("FATAL ERROR WITHIN HANDLER!","error",1e3)}}})},Node.prototype.hasClass=function(e){let t=e.split(","),a=null;for(let e of t){if(!1===a)break;a=this.classList.contains(e.trim())}return!0===a},Node.prototype.addClass=function(e){let t=e.split(",");for(let e of t)this.classList.add(e.trim());return this},Node.prototype.removeClass=function(e){let t=e.split(",");for(let e of t)this.classList.remove(e.trim());return this},Node.prototype.toggleClass=function(e,t){let a=e.split(",");for(let e of a)this.classList.toggle(e.trim(),t)},Node.prototype.switchClass=function(e,t,a){let i=this.classList;a?(i.remove(e),i.add(t)):(i.remove(t),i.add(e))},Node.prototype.toggleCheck=function(e,t){let a=this.classList,i=e.split(",");for(let e of i){let i=e.trim();t?a.add(i):a.remove(i)}},String.prototype.firstUpper=function(){return this.charAt(0).toUpperCase()+this.slice(1)},File.prototype.toBase64=function(e){const t=new FileReader;t.onloadend=e,t.readAsDataURL(this)};class TDUtils{static lastMatrix={m:null};static multiply(e,t){let a=t[0],i=t[1],s=t[2],n=t[3],r=t[4],l=t[5],o=t[6],d=t[7],c=t[8],h=t[9],u=t[10],p=t[11],g=t[12],f=t[13],m=t[14],y=t[15],v=e[0],w=e[1],C=e[2],T=e[3],x=e[4],H=e[5],b=e[6],S=e[7],U=e[8],A=e[9],E=e[10],L=e[11],D=e[12],k=e[13],F=e[14],M=e[15];return[a*v+i*x+s*U+n*D,a*w+i*H+s*A+n*k,a*C+i*b+s*E+n*F,a*T+i*S+s*L+n*M,r*v+l*x+o*U+d*D,r*w+l*H+o*A+d*k,r*C+l*b+o*E+d*F,r*T+l*S+o*L+d*M,c*v+h*x+u*U+p*D,c*w+h*H+u*A+p*k,c*C+h*b+u*E+p*F,c*T+h*S+u*L+p*M,g*v+f*x+m*U+y*D,g*w+f*H+m*A+y*k,g*C+f*b+m*E+y*F,g*T+f*S+m*L+y*M]}static translate(e,t,a,i,s){s=s||new Float32Array(16);let n=e[0],r=e[1],l=e[2],o=e[3],d=e[4],c=e[5],h=e[6],u=e[7],p=e[8],g=e[9],f=e[10],m=e[11],y=e[12],v=e[13],w=e[14],C=e[15];return s[0]=n,s[1]=r,s[2]=l,s[3]=o,s[4]=d,s[5]=c,s[6]=h,s[7]=u,s[8]=p,s[9]=g,s[10]=f,s[11]=m,s[12]=n*t+d*a+p*i+y,s[13]=r*t+c*a+g*i+v,s[14]=l*t+h*a+f*i+w,s[15]=o*t+u*a+m*i+C,s}static xRotation(e){e=TDUtils.degToRad(e);let t=Math.cos(e),a=Math.sin(e);return[1,0,0,0,0,t,a,0,0,-a,t,0,0,0,0,1]}static yRotation(e){e=TDUtils.degToRad