1(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[704],{7261:function(t){function e(){this._events=this._events||{},this._maxListeners=this._maxListeners||void 0}function r(t){return"function"==typeof t}function n(t){return"object"==typeof t&&null!==t}t.exports=e,e.EventEmitter=e,e.prototype._events=void 0,e.prototype._maxListeners=void 0,e.defaultMaxListeners=10,e.prototype.setMaxListeners=function(t){if("number"!=typeof t||t<0||isNaN(t))throw TypeError("n must be a positive number");return this._maxListeners=t,this},e.prototype.emit=function(t){var e,i,s,o,c,l;if(this._events||(this._events={}),"error"===t&&(!this._events.error||n(this._events.error)&&!this._events.error.length)){if(e=arguments[1],e instanceof Error)throw e;var u=Error('Uncaught, unspecified "error" event. ('+e+")");throw u.context=e,u}if(void 0===(i=this._events[t]))return!1;if(r(i))switch(arguments.length){case 1:i.call(this);break;case 2:i.call(this,arguments[1]);break;case 3:i.call(this,arguments[1],arguments[2]);break;default:o=Array.prototype.slice.call(arguments,1),i.apply(this,o)}else if(n(i))for(c=0,o=Array.prototype.slice.call(arguments,1),s=(l=i.slice()).length;c<s;c++)l[c].apply(this,o);return!0},e.prototype.addListener=function(t,i){var s;if(!r(i))throw TypeError("listener must be a function");return this._events||(this._events={}),this._events.newListener&&this.emit("newListener",t,r(i.listener)?i.listener:i),this._events[t]?n(this._events[t])?this._events[t].push(i):this._events[t]=[this._events[t],i]:this._events[t]=i,n(this._events[t])&&!this._events[t].warned&&(s=void 0===this._maxListeners?e.defaultMaxListeners:this._maxListeners)&&s>0&&this._events[t].length>s&&(this._events[t].warned=!0,console.error("(node) warning: possible EventEmitter memory leak detected. %d listeners added. Use emitter.setMaxListeners() to increase limit.",this._events[t].length),"function"==typeof console.trace&&console.trace()),this},e.prototype.on=e.prototype.addListener,e.prototype.once=function(t,e){if(!r(e))throw TypeError("listener must be a function");var n=!1;function i(){this.removeListener(t,i),n||(n=!0,e.apply(this,arguments))}return i.listener=e,this.on(t,i),this},e.prototype.removeListener=function(t,e){var i,s,o,c;if(!r(e))throw TypeError("listener must be a function");if(!this._events||!this._events[t])return this;if(o=(i=this._events[t]).length,s=-1,i===e||r(i.listener)&&i.listener===e)delete this._events[t],this._events.removeListener&&this.emit("removeListener",t,e);else if(n(i)){for(c=o;c-- >0;)if(i[c]===e||i[c].listener&&i[c].listener===e){s=c;break}if(s<0)return this;1===i.length?(i.length=0,delete this._events[t]):i.splice(s,1),this._events.removeListener&&this.emit("removeListener",t,e)}return this},e.prototype.removeAllListeners=function(t){var e,n;if(!this._events)return this;if(!this._events.removeListener)return 0==arguments.length?this._events={}:this._events[t]&&delete this._events[t],this;if(0==arguments.length){for(e in this._events)"removeListener"!==e&&this.removeAllListeners(e);return this.removeAllListeners("removeListener"),this._events={},this}if(r(n=this._events[t]))this.removeListener(t,n);else if(n)for(;n.length;)this.removeListener(t,n[n.length-1]);return delete this._events[t],this},e.prototype.listeners=function(t){return this._events&&this._events[t]?r(this._events[t])?[this._events[t]]:this._events[t].slice():[]},e.prototype.listenerCount=function(t){if(this._events){var e=this._events[t];if(r(e))return 1;if(e)return e.length}return 0},e.listenerCount=function(t,e){return t.listenerCount(e)}},5038:function(t){"function"==typeof Object.create?t.exports=function(t,e){e&&(t.super_=e,t.prototype=Object.create(e.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}}))}:t.exports=function(t,e){if(e){t.super_=e;var r=function(){};r.prototype=e.prototype,t.prototype=new r,t.prototype.constructor=t}}},5293:function(t){var e;e=function(){"use strict";function t(t,e,r){if(r||2==arguments.length)for(var n,i=0,s=e.length;i<s;i++)!n&&i in e||(n||(n=Array.prototype.slice.call(e,0,i)),n[i]=e[i]);return t.concat(n||Array.prototype.slice.call(e))}var e,r=Object.freeze({__proto__:null,blackman:function(t){for(var e=new Float32Array(t),r=2*Math.PI/(t-1),n=2*r,i=0;i<t/2;i++)e[i]=.42-.5*Math.cos(i*r)+.08*Math.cos(i*n);for(i=Math.ceil(t/2);i>0;i--)e[t-i]=e[i-1];return e},hamming:function(t){for(var e=new Float32Array(t),r=0;r<t;r++)e[r]=.54-.46*Math.cos(2*Math.PI*(r/t-1));return e},hanning:function(t){for(var e=new Float32Array(t),r=0;r<t;r++)e[r]=.5-.5*Math.cos(2*Math.PI*r/(t-1));return e},sine:function(t){for(var e=Math.PI/(t-1),r=new Float32Array(t),n=0;n<t;n++)r[n]=Math.sin(e*n);return r}}),n={};function i(t){for(;t%2==0&&t>1;)t/=2;return 1===t}function s(t,e){if("rect"!==e){if(""!==e&&e||(e="hanning"),n[e]||(n[e]={}),!n[e][t.length])try{n[e][t.length]=r[e](t.length)}catch(t){throw Error("Invalid windowing function")}t=function(t,e){for(var r=[],n=0;n<Math.min(t.length,e.length);n++)r[n]=t[n]*e[n];return r}(t,n[e][t.length])}return t}function o(t,e,r){for(var n=new Float32Array(t),i=0;i<n.length;i++)n[i]=i*e/r,n[i]=13*Math.atan(n[i]/1315.8)+3.5*Math.atan(Math.pow(n[i]/7518,2));return n}function c(t){return Float32Array.from(t)}function l(t){return 1125*Math.log(1+t/700)}function u(t,e,r){for(var n=new Float32Array(t+2),i=new Float32Array(t+2),s=l(0),o=(l(e/2)-s)/(t+1),c=Array(t+2),u=0;u<n.length;u++)n[u]=u*o,i[u]=700*(Math.exp(n[u]/1125)-1),c[u]=Math.floor((r+1)*i[u]/e);for(var h=Array(t),f=0;f<h.length;f++){for(h[f]=Array(r/2+1).fill(0),u=c[f];u<c[f+1];u++)h[f][u]=(u-c[f])/(c[f+1]-c[f]);for(u=c[f+1];u<c[f+2];u++)h[f][u]=(c[f+2]-u)/(c[f+2]-c[f+1])}return h}function h(t,e){for(var r=0,n=0,i=0;i<e.length;i++)r+=Math.pow(i,t)*Math.abs(e[i]),n+=e[i];return r/n}function f(t){var e=t.ampSpectrum,r=t.barkScale,n=t.numberOfBarkBands;
1if("object"!=typeof e||"object"!=typeof r)throw TypeError();var i=void 0===n?24:n,s=new Float32Array(i),o=0,c=new Int32Array(i+1);c[0]=0;for(var l=r[e.length-1]/i,u=1,h=0;h<e.length;h++)for(;r[h]>l;)c[u++]=h,l=u*r[e.length-1]/i;for(h=0,c[i]=e.length-1;h<i;h++){for(var f=0,p=c[h];p<c[h+1];p++)f+=e[p];s[h]=Math.pow(f,.23)}for(h=0;h<s.length;h++)o+=s[h];return{specific:s,total:o}}function p(t){var e=t.ampSpectrum;if("object"!=typeof e)throw TypeError();for(var r=new Float32Array(e.length),n=0;n<r.length;n++)r[n]=Math.pow(e[n],2);return r}function m(t){var e=t.ampSpectrum,r=t.melFilterBank,n=t.bufferSize;if("object"!=typeof e)throw TypeError("Valid ampSpectrum is required to generate melBands");if("object"!=typeof r)throw TypeError("Valid melFilterBank is required to generate melBands");for(var i=p({ampSpectrum:e}),s=r.length,o=Array(s),c=new Float32Array(s),l=0;l<c.length;l++){o[l]=new Float32Array(n/2),c[l]=0;for(var u=0;u<n/2;u++)o[l][u]=r[l][u]*i[u],c[l]+=o[l][u];c[l]=Math.log(c[l]+1)}return Array.prototype.slice.call(c)}var d=null,v=(e=function(t,e){var r=t.length;return e=e||2,d&&d[r]||function(t){(d=d||{})[t]=Array(t*t);for(var e=Math.PI/t,r=0;r<t;r++)for(var n=0;n<t;n++)d[t][n+r*t]=Math.cos(e*(n+.5)*r)}(r),t.map(function(){return 0}).map(function(n,i){return e*t.reduce(function(t,e,n,s){return t+e*d[r][n+i*r]},0)})}).__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e,y=Object.freeze({__proto__:null,amplitudeSpectrum:function(t){return t.ampSpectrum},buffer:function(t){return t.signal},chroma:function(t){var e=t.ampSpectrum,r=t.chromaFilterBank;if("object"!=typeof e)throw TypeError("Valid ampSpectrum is required to generate chroma");if("object"!=typeof r)throw TypeError("Valid chromaFilterBank is required to generate chroma");var n=r.map(function(t,r){return e.reduce(function(e,r,n){return e+r*t[n]},0)}),i=Math.max.apply(Math,n);return i?n.map(function(t){return t/i}):n},complexSpectrum:function(t){return t.complexSpectrum},energy:function(t){var e=t.signal;if("object"!=typeof e)throw TypeError();for(var r=0,n=0;n<e.length;n++)r+=Math.pow(Math.abs(e[n]),2);return r},loudness:f,melBands:m,mfcc:function(t){var e=t.ampSpectrum,r=t.melFilterBank,n=t.numberOfMFCCCoefficients,i=t.bufferSize,s=Math.min(40,Math.max(1,n||13));if(r.length<s)throw Error("Insufficient filter bank for requested number of coefficients");return v(m({ampSpectrum:e,melFilterBank:r,bufferSize:i})).slice(0,s)},perceptualSharpness:function(t){for(var e=f({ampSpectrum:t.ampSpectrum,barkScale:t.barkScale}),r=e.specific,n=0,i=0;i<r.length;i++)n+=i<15?(i+1)*r[i+1]:.066*Math.exp(.171*(i+1));return .11/e.total*n},perceptualSpread:function(t){for(var e=f({ampSpectrum:t.ampSpectrum,barkScale:t.barkScale}),r=0,n=0;n<e.specific.length;n++)e.specific[n]>r&&(r=e.specific[n]);return Math.pow((e.total-r)/e.total,2)},powerSpectrum:p,rms:function(t){var e=t.signal;if("object"!=typeof e)throw TypeError();for(var r=0,n=0;n<e.length;n++)r+=Math.pow(e[n],2);return r/=e.length,r=Math.sqrt(r)},spectralCentroid:function(t){var e=t.ampSpectrum;if("object"!=typeof e)throw TypeError();return h(1,e)},spectralCrest:function(t){var e=t.ampSpectrum;if("object"!=typeof e)throw TypeError();var r=0,n=-1/0;return e.forEach(function(t){r+=Math.pow(t,2),n=t>n?t:n}),r/=e.length,n/(r=Math.sqrt(r))},spectralFlatness:function(t){var e=t.ampSpectrum;if("object"!=typeof e)throw TypeError();for(var r=0,n=0,i=0;i<e.length;i++)r+=Math.log(e[i]),n+=e[i];return Math.exp(r/e.length)*e.length/n},spectralFlux:function(t){var e=t.signal,r=t.previousSignal,n=t.bufferSize;if("object"!=typeof e||"object"!=typeof r)throw TypeError();for(var i=0,s=-n/2;s<e.length/2-1;s++)i+=((x=Math.abs(e[s])-Math.abs(r[s]))+Math.abs(x))/2;return i},spectralKurtosis:function(t){var e=t.ampSpectrum;if("object"!=typeof e)throw TypeError();var r=h(1,e),n=h(2,e);return(-3*Math.pow(r,4)+6*r*n-4*r*h(3,e)+h(4,e))/Math.pow(Math.sqrt(n-Math.pow(r,2)),4)},spectralRolloff:function(t){var e=t.ampSpectrum,r=t.sampleRate;if("object"!=typeof e)throw TypeError();for(var n=r/(2*(e.length-1)),i=0,s=0;s<e.length;s++)i+=e[s];for(var o=.99*i,c=e.length-1;i>o&&c>=0;)i-=e[c],--c;return(c+1)*n},spectralSkewness:function(t){var e=t.ampSpectrum;if("object"!=typeof e)throw TypeError();var r=h(1,e),n=h(2,e);return(2*Math.pow(r,3)-3*r*n+h(3,e))/Math.pow(Math.sqrt(n-Math.pow(r,2)),3)},spectralSlope:function(t){var e=t.ampSpectrum,r=t.sampleRate,n=t.bufferSize;if("object"!=typeof e)throw TypeError();for(var i=0,s=0,o=new Float32Array(e.length),c=0,l=0,u=0;u<e.length;u++){i+=e[u];var h=u*r/n;o[u]=h,c+=h*h,s+=h,l+=h*e[u]}return(e.length*l-s*i)/(i*(c-Math.pow(s,2)))},spectralSpread:function(t){var e=t.ampSpectrum;if("object"!=typeof e)throw TypeError();return Math.sqrt(h(2,e)-Math.pow(h(1,e),2))},zcr:function(t){var e=t.signal;if("object"!=typeof e)throw TypeError();for(var r=0,n=1;n<e.length;n++)(e[n-1]>=0&&e[n]<0||e[n-1]<0&&e[n]>=0)&&r++;return r}}),g={},b={},_={bitReverseArray:function(t){if(void 0===g[t]){for(var e=(t-1).toString(2).length,r="0".repeat(e),n={},i=0;i<t;i++){var s=i.toString(2);s=[].concat(function(t){if(Array.isArray(t)){for(var e=0,r=Array(t.length);e<t.length;e++)r[e]=t[e];return r}return Array.from(t)}
1(s=r.substr(s.length)+s)).reverse().join(""),n[i]=parseInt(s,2)}g[t]=n}return g[t]},multiply:function(t,e){return{real:t.real*e.real-t.imag*e.imag,imag:t.real*e.imag+t.imag*e.real}},add:function(t,e){return{real:t.real+e.real,imag:t.imag+e.imag}},subtract:function(t,e){return{real:t.real-e.real,imag:t.imag-e.imag}},euler:function(t,e){var r=-2*Math.PI*t/e;return{real:Math.cos(r),imag:Math.sin(r)}},constructComplexArray:function(t){var e={};e.real=void 0===t.real?t.slice():t.real.slice();var r=e.real.length;return void 0===b[r]&&(b[r]=Array.apply(null,Array(r)).map(Number.prototype.valueOf,0)),e.imag=b[r].slice(),e}},w=function(t){var e={};void 0===t.real||void 0===t.imag?e=_.constructComplexArray(t):(e.real=t.real.slice(),e.imag=t.imag.slice());var r=e.real.length,n=Math.log2(r);if(Math.round(n)!=n)throw Error("Input size must be a power of 2.");if(e.real.length!=e.imag.length)throw Error("Real and imaginary components must have the same length.");for(var i=_.bitReverseArray(r),s={real:[],imag:[]},o=0;o<r;o++)s.real[i[o]]=e.real[o],s.imag[i[o]]=e.imag[o];for(var c=0;c<r;c++)e.real[c]=s.real[c],e.imag[c]=s.imag[c];for(var l=1;l<=n;l++)for(var u=Math.pow(2,l),h=0;h<u/2;h++)for(var f=_.euler(h,u),p=0;p<r/u;p++){var m=u*p+h,d=u*p+h+u/2,v={real:e.real[m],imag:e.imag[m]},y={real:e.real[d],imag:e.imag[d]},g=_.multiply(f,y),b=_.subtract(v,g);e.real[d]=b.real,e.imag[d]=b.imag;var w=_.add(g,v);e.real[m]=w.real,e.imag[m]=w.imag}return e},S=function(){function t(t,e){var r=this;if(this._m=e,!t.audioContext)throw this._m.errors.noAC;if(t.bufferSize&&!i(t.bufferSize))throw this._m._errors.notPow2;if(!t.source)throw this._m._errors.noSource;this._m.audioContext=t.audioContext,this._m.bufferSize=t.bufferSize||this._m.bufferSize||256,this._m.hopSize=t.hopSize||this._m.hopSize||this._m.bufferSize,this._m.sampleRate=t.sampleRate||this._m.audioContext.sampleRate||44100,this._m.callback=t.callback,this._m.windowingFunction=t.windowingFunction||"hanning",this._m.featureExtractors=y,this._m.EXTRACTION_STARTED=t.startImmediately||!1,this._m.channel="number"==typeof t.channel?t.channel:0,this._m.inputs=t.inputs||1,this._m.outputs=t.outputs||1,this._m.numberOfMFCCCoefficients=t.numberOfMFCCCoefficients||this._m.numberOfMFCCCoefficients||13,this._m.numberOfBarkBands=t.numberOfBarkBands||this._m.numberOfBarkBands||24,this._m.spn=this._m.audioContext.createScriptProcessor(this._m.bufferSize,this._m.inputs,this._m.outputs),this._m.spn.connect(this._m.audioContext.destination),this._m._featuresToExtract=t.featureExtractors||[],this._m.barkScale=o(this._m.bufferSize,this._m.sampleRate,this._m.bufferSize),this._m.melFilterBank=u(Math.max(this._m.melBands,this._m.numberOfMFCCCoefficients),this._m.sampleRate,this._m.bufferSize),this._m.inputData=null,this._m.previousInputData=null,this._m.frame=null,this._m.previousFrame=null,this.setSource(t.source),this._m.spn.onaudioprocess=function(t){var e;null!==r._m.inputData&&(r._m.previousInputData=r._m.inputData),r._m.inputData=t.inputBuffer.getChannelData(r._m.channel),r._m.previousInputData?((e=new Float32Array(r._m.previousInputData.length+r._m.inputData.length-r._m.hopSize)).set(r._m.previousInputData.slice(r._m.hopSize)),e.set(r._m.inputData,r._m.previousInputData.length-r._m.hopSize)):e=r._m.inputData,(function(t,e,r){if(t.length<e)throw Error("Buffer is too short for frame length");if(r<1)throw Error("Hop length cannot be less that 1");if(e<1)throw Error("Frame length cannot be less that 1");return Array(1+Math.floor((t.length-e)/r)).fill(0).map(function(n,i){return t.slice(i*r,i*r+e)})})(e,r._m.bufferSize,r._m.hopSize).forEach(function(t){r._m.frame=t;var e=r._m.extract(r._m._featuresToExtract,r._m.frame,r._m.previousFrame);"function"==typeof r._m.callback&&r._m.EXTRACTION_STARTED&&r._m.callback(e),r._m.previousFrame=r._m.frame})}}return t.prototype.start=function(t){this._m._featuresToExtract=t||this._m._featuresToExtract,this._m.EXTRACTION_STARTED=!0},t.prototype.stop=function(){this._m.EXTRACTION_STARTED=!1},t.prototype.setSource=function(t){this._m.source&&this._m.source.disconnect(this._m.spn),this._m.source=t,this._m.source.connect(this._m.spn)},t.prototype.setChannel=function(t){t<=this._m.inputs?this._m.channel=t:console.error("Channel ".concat(t," does not exist. Make sure you've provided a value for 'input
1s' that is greater than ").concat(t," when instantiating the MeydaAnalyzer"))},t.prototype.get=function(t){return this._m.inputData?this._m.extract(t||this._m._featuresToExtract,this._m.inputData,this._m.previousInputData):null},t}(),M={audioContext:null,spn:null,bufferSize:512,sampleRate:44100,melBands:26,chromaBands:12,callback:null,windowingFunction:"hanning",featureExtractors:y,EXTRACTION_STARTED:!1,numberOfMFCCCoefficients:13,numberOfBarkBands:24,_featuresToExtract:[],windowing:s,_errors:{notPow2:Error("Meyda: Buffer size must be a power of 2, e.g. 64 or 512"),featureUndef:Error("Meyda: No features defined."),invalidFeatureFmt:Error("Meyda: Invalid feature format"),invalidInput:Error("Meyda: Invalid input."),noAC:Error("Meyda: No AudioContext specified."),noSource:Error("Meyda: No source node specified.")},createMeydaAnalyzer:function(t){return new S(t,Object.assign({},M))},listAvailableFeatureExtractors:function(){return Object.keys(this.featureExtractors)},extract:function(e,r,n){var s=this;if(!r||"object"!=typeof r)throw this._errors.invalidInput;if(!e)throw this._errors.featureUndef;if(!i(r.length))throw this._errors.notPow2;void 0!==this.barkScale&&this.barkScale.length==this.bufferSize||(this.barkScale=o(this.bufferSize,this.sampleRate,this.bufferSize)),void 0!==this.melFilterBank&&this.barkScale.length==this.bufferSize&&this.melFilterBank.length==this.melBands||(this.melFilterBank=u(Math.max(this.melBands,this.numberOfMFCCCoefficients),this.sampleRate,this.bufferSize)),void 0!==this.chromaFilterBank&&this.chromaFilterBank.length==this.chromaBands||(this.chromaFilterBank=function(e,r,n,i,s,o,c){void 0===i&&(i=5),void 0===s&&(s=2),void 0===o&&(o=!0),void 0===c&&(c=440);var l=Math.floor(n/2)+1,u=Array(n).fill(0).map(function(t,i){return e*Math.log2(r*i/n*16/c)});u[0]=u[1]-1.5*e;var h,f,p,m=u.slice(1).map(function(t,e){return Math.max(t-u[e])},1).concat([1]),d=Math.round(e/2),v=Array(e).fill(0).map(function(t,r){return u.map(function(t){return(10*e+d+t-r)%e-d})}),y=v.map(function(t,e){return t.map(function(t,r){return Math.exp(-.5*Math.pow(2*v[e][r]/m[r],2))})});if(f=(h=y)[0].map(function(){return 0}),p=h.reduce(function(t,e){return e.forEach(function(e,r){t[r]+=Math.pow(e,2)}),t},f).map(Math.sqrt),y=h.map(function(t,e){return t.map(function(t,e){return t/(p[e]||1)})}),s){var g=u.map(function(t){return Math.exp(-.5*Math.pow((t/e-i)/s,2))});y=y.map(function(t){return t.map(function(t,e){return t*g[e]})})}return o&&(y=t(t([],y.slice(3),!0),y.slice(0,3),!0)),y.map(function(t){return t.slice(0,l)})}(this.chromaBands,this.sampleRate,this.bufferSize)),"buffer"in r&&void 0===r.buffer?this.signal=c(r):this.signal=r;var l=E(r,this.windowingFunction,this.bufferSize);if(this.signal=l.windowedSignal,this.complexSpectrum=l.complexSpectrum,this.ampSpectrum=l.ampSpectrum,n){var h=E(n,this.windowingFunction,this.bufferSize);this.previousSignal=h.windowedSignal,this.previousComplexSpectrum=h.complexSpectrum,this.previousAmpSpectrum=h.ampSpectrum}var f=function(t){return s.featureExtractors[t]({ampSpectrum:s.ampSpectrum,chromaFilterBank:s.chromaFilterBank,complexSpectrum:s.complexSpectrum,signal:s.signal,bufferSize:s.bufferSize,sampleRate:s.sampleRate,barkScale:s.barkScale,melFilterBank:s.melFilterBank,previousSignal:s.previousSignal,previousAmpSpectrum:s.previousAmpSpectrum,previousComplexSpectrum:s.previousComplexSpectrum,numberOfMFCCCoefficients:s.numberOfMFCCCoefficients,numberOfBarkBands:s.numberOfBarkBands})};if("object"==typeof e)return e.reduce(function(t,e){var r;return Object.assign({},t,((r={})[e]=f(e),r))},{});if("string"==typeof e)return f(e);throw this._errors.invalidFeatureFmt}},E=function(t,e,r){var n={};void 0===t.buffer?n.signal=c(t):n.signal=t,n.windowedSignal=s(n.signal,e),n.complexSpectrum=w(n.windowedSignal),n.ampSpectrum=new Float32Array(r/2);for(var i=0;i<r/2;i++)n.ampSpectrum[i]=Math.sqrt(Math.pow(n.complexSpectrum.real[i],2)+Math.pow(n.complexSpectrum.imag[i],2));return n};return"undefined"!=typeof window&&(window.Meyda=M),M},t.exports=e()},7744:function(t,e,r){var n=r(8070);(function(){var e,r,i,s;"undefined"!=typeof performance&&null!==performance&&performance.now?t.exports=function(){return performance.now()}:null!=n&&n.hrtime?(t.exports=function(){return(e()-s)/1e6},r=n.hrtime,s=(e=function(){var t;return 1e9*(t=r())[0]+t[1]})()-1e9*n.uptime()):Date.now?(t.exports=function(){return Date.now()-i},i=Date.now()):(t.exports=function(){return new Date().getTime()-i},i=new Date().getTime())}).call(this)},2575:function(t,e,r){var n=r(5038),i=r(7261).EventEmitter,s=r(1851),o=r(1463);function c(t){if(!(this instanceof c))return new c(t);this.running=!1,this.last=s(),this._frame=0,this._tick=this.tick.bind(this),t&&this.on("tick",t)}t.exports=c,n(c,i),c.prototype.start=function(){if(!this.running)return this.running=!0,this.last=s(),this._frame=o(this._tick),this},c.prototype.stop=function(){return this.running=!1,0!==this._frame&&o.cancel(this._frame),this._frame=0,this},c.prototype.tick=function(){this._frame=o(this._tick);var t=s(),e=t-this.last;
1this.emit("tick",e),this.last=t}},1463:function(t,e,r){for(var n=r(7744),i="undefined"==typeof window?r.g:window,s=["moz","webkit"],o="AnimationFrame",c=i["request"+o],l=i["cancel"+o]||i["cancelRequest"+o],u=0;!c&&u<s.length;u++)c=i[s[u]+"Request"+o],l=i[s[u]+"Cancel"+o]||i[s[u]+"CancelRequest"+o];if(!c||!l){var h=0,f=0,p=[],m=1e3/60;c=function(t){if(0===p.length){var e=n(),r=Math.max(0,m-(e-h));h=r+e,setTimeout(function(){var t=p.slice(0);p.length=0;for(var e=0;e<t.length;e++)if(!t[e].cancelled)try{t[e].callback(h)}catch(t){setTimeout(function(){throw t},0)}},Math.round(r))}return p.push({handle:++f,callback:t,cancelled:!1}),f},l=function(t){for(var e=0;e<p.length;e++)p[e].handle===t&&(p[e].cancelled=!0)}}t.exports=function(t){return c.call(i,t)},t.exports.cancel=function(){l.apply(i,arguments)},t.exports.polyfill=function(t){t||(t=i),t.requestAnimationFrame=c,t.cancelAnimationFrame=l}},1851:function(t,e,r){t.exports=r.g.performance&&r.g.performance.now?function(){return performance.now()}:Date.now||function(){return+new Date}},8070:function(t){var e,r,n,i=t.exports={};function s(){throw Error("setTimeout has not been defined")}function o(){throw Error("clearTimeout has not been defined")}function c(t){if(e===setTimeout)return setTimeout(t,0);if((e===s||!e)&&setTimeout)return e=setTimeout,setTimeout(t,0);try{return e(t,0)}catch(r){try{return e.call(null,t,0)}catch(r){return e.call(this,t,0)}}}!function(){try{e="function"==typeof setTimeout?setTimeout:s}catch(t){e=s}try{r="function"==typeof clearTimeout?clearTimeout:o}catch(t){r=o}}();var l=[],u=!1,h=-1;function f(){u&&n&&(u=!1,n.length?l=n.concat(l):h=-1,l.length&&p())}function p(){if(!u){var t=c(f);u=!0;for(var e=l.length;e;){for(n=l,l=[];++h<e;)n&&n[h].run();h=-1,e=l.length}n=null,u=!1,function(t){if(r===clearTimeout)return clearTimeout(t);if((r===o||!r)&&clearTimeout)return r=clearTimeout,clearTimeout(t);try{r(t)}catch(e){try{return r.call(null,t)}catch(e){return r.call(this,t)}}}(t)}}function m(t,e){this.fun=t,this.array=e}function d(){}i.nextTick=function(t){var e=Array(arguments.length-1);if(arguments.length>1)for(var r=1;r<arguments.length;r++)e[r-1]=arguments[r];l.push(new m(t,e)),1!==l.length||u||c(p)},m.prototype.run=function(){this.fun.apply(null,this.array)},i.title="browser",i.browser=!0,i.env={},i.argv=[],i.version="",i.versions={},i.on=d,i.addListener=d,i.once=d,i.off=d,i.removeListener=d,i.removeAllListeners=d,i.emit=d,i.prependListener=d,i.prependOnceListener=d,i.listeners=function(t){return[]},i.binding=function(t){throw Error("process.binding is not supported")},i.cwd=function(){return"/"},i.chdir=function(t){throw Error("process.chdir is not supported")},i.umask=function(){return 0}},2704:function(t,e,r){"use strict";r.d(e,{default:function(){return F}});var n=function({regl:t,precision:e,label:r="",width:n,height:i}){this.regl=t,this.precision=e,this.label=r,this.positionBuffer=this.regl.buffer([[-2,0],[0,-2],[2,2]]),this.draw=()=>{},this.init(),this.pingPongIndex=0,this.fbos=[,,].fill().map(()=>this.regl.framebuffer({color:this.regl.texture({mag:"nearest",width:n,height:i,format:"rgba"}),depthStencil:!1}))};n.prototype.resize=function(t,e){this.fbos.forEach(r=>{r.resize(t,e)})},n.prototype.getCurrent=function(){return this.fbos[this.pingPongIndex]},n.prototype.getTexture=function(){var t=this.pingPongIndex?0:1;return this.fbos[t]},n.prototype.init=function(){return this.transformIndex=0,this.fragHeader=` 2 precision ${this.precision} float; 3 4 uniform float time; 5 varying vec2 uv; 6 `,this.fragBody="",this.vert=` 7 precision ${this.precision} float; 8 attribute vec2 position; 9 varying vec2 uv; 10 11 void main () { 12 uv = position; 13 gl_Position = vec4(2.0 * position - 1.0, 0, 1); 14 }`,this.attributes={position:this.positionBuffer},this.uniforms={time:this.regl.prop("time"),resolution:this.regl.prop("resolution")},this.frag=` 15 ${this.fragHeader} 16 17 void main () { 18 vec4 c = vec4(0, 0, 0, 0); 19 vec2 st = uv; 20 ${this.fragBody} 21 gl_FragColor = c; 22 } 23 `,this},n.prototype.render=function(t){let e=t[0];var r=this,n=Object.assign(e.uniforms,{prevBuffer:()=>r.fbos[r.pingPongIndex]});r.draw=r.regl({frag:e.frag,vert:r.vert,attributes:r.attributes,uniforms:n,count:3,framebuffer:()=>(r.pingPongIndex=r.pingPongIndex?0:1,r.fbos[r.pingPongIndex])})},n.prototype.tick=function(t){this.draw(t)};var i=r(2575);class s{constructor({regl:t,width:e,height:r,pb:n,label:i=""}){this.label=i,this.regl=t,this.src=null,this.dynamic=!0,this.width=e,this.height=r,this.tex=this.regl.texture({shape:[1,1]}),this.pb=n}init(t,e){"src"in t&&(this.src=t.src,this.tex=this.regl.texture({data:this.src,...e})),"dynamic"in t&&(this.dynamic=t.dynamic)}initCam(t,e){let r=this;navigator.mediaDevices.enumerateDevices().then(t=>t.filter(t=>"videoinput"===t.kind)).then(e=>{let r={audio:!1,video:!0};return e[t]&&(r.video={deviceId:{exact:e[t].deviceId}}),window.navigator.mediaDevices.getUserMedia(r)}).then(t=>{let e=document.createElement("video");return e.setAttribute("autoplay",""),e.setAttribute("muted",""),e.setAttribute("playsinline",""),e.srcObject=t,new Promise((t,r)=>{e.addEventListener("loadedmetadata",()=>{e.play().then(()=>t({video:e}))})})}).catch(console.log.bind(console)).then(t=>{r.src=t.video,r.dynamic=!0,r.tex=r.regl.texture({data:r.src,...e})}).catch(t=>console.log("could not get camera",t))}initVideo(t="",e){let r=document.createElement("video");r.crossOrigin="anonymous",r.autoplay=!0,r.loop=!0,r.muted=!0,r.addEventListener("loadeddata",()=>{this.src=r,r.play(),this.tex=this.regl.texture({data:this.src,...e}),this.dynamic=!0}),r.src=t}initImage(t="",e){let r=document.createElement("img");r.crossOrigin="anonymous",r.src=t,r.onload=()=>{this.src=r,this.dynamic=!1,this.tex=this.regl.texture({data:this.src,...e})}}initStream(t,e){let r=this;
23t&&this.pb&&(this.pb.initSource(t),this.pb.on("got video",function(n,i){n===t&&(r.src=i,r.dynamic=!0,r.tex=r.regl.texture({data:r.src,...e}))}))}initScreen(t=0,e){let r=this;new Promise(function(t,e){navigator.mediaDevices.getDisplayMedia(void 0).then(e=>{let r=document.createElement("video");r.srcObject=e,r.addEventListener("loadedmetadata",()=>{r.play(),t({video:r})})}).catch(t=>e(t))}).then(function(t){r.src=t.video,r.tex=r.regl.texture({data:r.src,...e}),r.dynamic=!0}).catch(t=>console.log("could not get screen",t))}resize(t,e){this.width=t,this.height=e}clear(){this.src&&this.src.srcObject&&this.src.srcObject.getTracks&&this.src.srcObject.getTracks().forEach(t=>t.stop()),this.src=null,this.tex=this.regl.texture({shape:[1,1]})}tick(t){null!==this.src&&!0===this.dynamic&&(this.src.videoWidth&&this.src.videoWidth!==this.tex.width&&(console.log(this.src.videoWidth,this.src.videoHeight,this.tex.width,this.tex.height),this.tex.resize(this.src.videoWidth,this.src.videoHeight)),this.src.width&&this.src.width!==this.tex.width&&this.tex.resize(this.src.width,this.src.height),this.tex.subimage(this.src))}getTexture(){return this.tex}}let o={};o.buttons=function(t){if("object"==typeof t){if("buttons"in t)return t.buttons;if("which"in t){var e=t.which;if(2===e)return 4;if(3===e)return 2;if(e>0)return 1<<e-1}else if("button"in t){var e=t.button;if(1===e)return 4;if(2===e)return 2;if(e>=0)return 1<<e}}return 0},o.element=function(t){return t.target||t.srcElement||window},o.x=function(t){return"object"==typeof t&&"pageX"in t?t.pageX:0},o.y=function(t){return"object"==typeof t&&"pageY"in t?t.pageY:0};var c=r(5293);class l{constructor({numBins:t=4,cutoff:e=2,smooth:r=.4,max:n=15,scale:i=10,isDrawing:s=!1,parentEl:o=document.body}){this.vol=0,this.scale=i,this.max=n,this.cutoff=e,this.smooth=r,this.setBins(t),this.beat={holdFrames:20,threshold:40,_cutoff:0,decay:.98,_framesSinceBeat:0},this.onBeat=()=>{},this.canvas=document.createElement("canvas"),this.canvas.width=100,this.canvas.height=80,this.canvas.style.width="100px",this.canvas.style.height="80px",this.canvas.style.position="absolute",this.canvas.style.right="0px",this.canvas.style.bottom="0px",o.appendChild(this.canvas),this.isDrawing=s,this.ctx=this.canvas.getContext("2d"),this.ctx.fillStyle="#DFFFFF",this.ctx.strokeStyle="#0ff",this.ctx.lineWidth=.5,window.navigator.mediaDevices&&window.navigator.mediaDevices.getUserMedia({video:!1,audio:!0}).then(t=>{this.stream=t,this.context=new AudioContext;let e=this.context.createMediaStreamSource(t);this.meyda=c.createMeydaAnalyzer({audioContext:this.context,source:e,featureExtractors:["loudness"]})}).catch(t=>console.log("ERROR",t))}detectBeat(t){t>this.beat._cutoff&&t>this.beat.threshold?(this.onBeat(),this.beat._cutoff=1.2*t,this.beat._framesSinceBeat=0):this.beat._framesSinceBeat<=this.beat.holdFrames?this.beat._framesSinceBeat++:(this.beat._cutoff*=this.beat.decay,this.beat._cutoff=Math.max(this.beat._cutoff,this.beat.threshold))}tick(){if(this.meyda){var t=this.meyda.get();if(t&&null!==t){this.vol=t.loudness.total,this.detectBeat(this.vol);let e=(t,e)=>t+e,r=Math.floor(t.loudness.specific.length/this.bins.length);this.prevBins=this.bins.slice(0),this.bins=this.bins.map((n,i)=>t.loudness.specific.slice(i*r,(i+1)*r).reduce(e)).map((t,e)=>t*(1-this.settings[e].smooth)+this.prevBins[e]*this.settings[e].smooth),this.fft=this.bins.map((t,e)=>Math.max(0,(t-this.settings[e].cutoff)/this.settings[e].scale)),this.isDrawing&&this.draw()}}}setCutoff(t){this.cutoff=t,this.settings=this.settings.map(e=>(e.cutoff=t,e))}setSmooth(t){this.smooth=t,this.settings=this.settings.map(e=>(e.smooth=t,e))}setBins(t){this.bins=Array(t).fill(0),this.prevBins=Array(t).fill(0),this.fft=Array(t).fill(0),this.settings=Array(t).fill(0).map(()=>({cutoff:this.cutoff,scale:this.scale,smooth:this.smooth})),this.bins.forEach((t,e)=>{window["a"+e]=(t=1,r=0)=>()=>a.fft[e]*t+r})}setScale(t){this.scale=t,this.settings=this.settings.map(e=>(e.scale=t,e))}setMax(t){this.max=t,console.log("set max is deprecated")}hide(){this.isDrawing=!1,this.canvas.style.display="none"}show(){this.isDrawing=!0,this.canvas.style.display="block"}draw(){this.ctx.clearRect(0,0,this.canvas.width,this.canvas.height);var t=this.canvas.width/this.bins.length,e=this.canvas.height/(2*this.max);this.bins.forEach((r,n)=>{var i=r*e;this.ctx.fillRect(n*t,this.canvas.height-i,t,i);var s=this.canvas.height-e*this.settings[n].cutoff;this.ctx.beginPath(),this.ctx.moveTo(n*t,s),this.ctx.lineTo((n+1)*t,s),this.ctx.stroke();var o=this.canvas.height-e*(this.settings[n].scale+this.settings[n].cutoff);this.ctx.beginPath(),this.ctx.moveTo(n*t,o),this.ctx.lineTo((n+1)*t,o),this.ctx.stroke()})}}class u{constructor(t){this.mediaSource=new MediaSource,this.stream=t,this.output=document.createElement("video"),this.output.autoplay=!0,this.output.loop=!0;let e=this;this.mediaSource.addEventListener("sourceopen",()=>{console.log("MediaSource opened"),e.sourceBuffer=e.mediaSource.addSourceBuffer('video/webm; codecs="vp8"'),console.log("Source buffer: ",sourceBuffer)})}start(){let t={mimeType:"video/webm;codecs=vp9"};this.recordedBlobs=[];try{this.mediaRecorder=new MediaRecorder(this.stream,t)}catch(e){console.log("Unable to create MediaRecorder with options Object: ",e);try{t={mimeType:"video/webm,codecs=vp9"},this.mediaRecorder=new MediaRecorder(this.stream,t)}catch(e){console.log("Unable to create MediaRecorder with options Object: ",e);try{t="video/vp8",this.mediaRecorder=new MediaRecorder(this.stream,t)}catch(t){alert("MediaRecorder is not supported by this browser.\n\nTry Firefox 29 or later, or Chrome 47 or later, with Enable experimental Web Platform features enabled from chrome://flags."),console.error("Exception while creating MediaRecorder:",t);return}}}console.log("Created MediaRecorder",this.mediaRecorder,"with options",t),this.mediaRecorder.onstop=this._handleStop.bind(this),this.mediaRecorder.ondataavailable=this._handleDataAvailable.bind(this),this.mediaRecorder.start(100),console.log("MediaRecorder started",this.mediaRecorder)}stop(){this.mediaRecorder.stop()}_handleStop(){let t=new Blob(this.recordedBlobs,{type:this.mediaRecorder.mimeType}),e=window.URL.createObjectURL(t);this.output.src=e;let r=document.createElement("a");r.style.display="none",r.href=e;let n=new Date;r.download=`hydra-${n.getFullYear()}-${n.getMonth()+1}-${n.getDate()}-${n.getHours()}.${n.getMinutes()}.${n.getSeconds()}.webm`,document.body.appendChild(r),r.click(),setTimeout(()=>{document.body.removeChild(r),window.URL.revokeObjectURL(e)},300)}_handleDataAvailable(t){t.data&&t.data.size>0&&this.recordedBlobs.push(t.data)}}var h={linear:function(t){return t},easeInQuad:function(t){return t*t},easeOutQuad:function(t){return t*(2-t)},easeInOutQuad:function(t){return t<.5?2*t*t:-1+(4-2*t)*t},easeInCubic:function(t){return t*t*t},easeOutCubic:function(t){return--t*t*t+1},easeInOutCubic:function(t){return t<.5?4*t*t*t:(t-1)*(2*t-2)*(2*t-2)+1},easeInQuart:function(t){return t*t*t*t},easeOutQuart:function(t){return 1- --t*t*t*t},easeInOutQuart:function(t){return t<.5?8*t*t*t*t:1-8*--t*t*t*t},easeInQuint:function(t){return t*t*t*t*t},easeOutQuint:function(t){return 1+--t*t*t*t*t},easeInOutQuint:function(t){return t<.5?16*t*t*t*t*t:1+16*--t*t*t*t*t},sin:function(t){return(1+Math.sin(Math.PI*t-Math.PI/2))/2}},f=(t,e,r,n,i)=>(t-e)*(i-n)/(r-e)+n,p={init:()=>{Array.prototype.fast=function(t=1){return this._speed=t,this},Array.prototype.smooth=function(t=1){return this._smooth=t,this},Array.prototype.ease=function(t="linear"){return"function"==typeof t?(this._smooth=1,this._ease=t):h[t]&&(this._smooth=1,this._ease=h[t]),this},Array.prototype.offset=function(t=.5){return this._offset=t%1,this},Array.prototype.fit=function(t=0,e=1){let r=Math.min(...this),n=Math.max(...this);var i=this.map(i=>f(i,r,n,t,e));return i._speed=this._speed,i._smooth=this._smooth,i._ease=this._ease,i}},getValue:(t=[])=>({time:e,bpm:r})=>{let n=t._speed?t._speed:1,i=t._smooth?t._smooth:0,s=e*n*(r/60)+(t._offset||0);if(0===i)return t[Math.floor(s%t.length)],t[Math.floor(s%t.length)];{let e=t._ease?t._ease:h.linear,r=s-i/2,n=t[Math.floor(r%t.length)],o=t[Math.floor((r+1)%t.length)];
23return e(Math.min(r%1/i,1))*(o-n)+n}}},m=t=>{var e="",r=n(e);return{addToContext:(t,i)=>{e+=` 24 var ${t} = ${i} 25 `,r=n(e)},eval:t=>r.eval(t)};function n(t){return globalThis.eval(t),{eval:function(t){globalThis.eval(t)}}}};class d{constructor(t,e,r=[]){this.makeGlobal=e,this.sandbox=m(t),this.parent=t,Object.keys(t).forEach(t=>this.add(t)),this.userProps=r}add(t){this.makeGlobal&&(window[t]=this.parent[t])}set(t,e){this.makeGlobal&&(window[t]=e),this.parent[t]=e}tick(){this.makeGlobal&&this.userProps.forEach(t=>{this.parent[t]=window[t]})}eval(t){this.sandbox.eval(t)}}let v={float:{vec4:{name:"sum",args:[[1,1,1,1]]},vec2:{name:"sum",args:[[1,1]]}}},y=t=>(0>(t=t.toString()).indexOf(".")&&(t+="."),t);function g(t,e){var r=()=>"";return t.forEach(t=>{var n=function(t,e,r){let n=t.transform.inputs,i=t.userArgs,{generators:s}=t.synth,{src:o}=s;return n.map((t,r)=>{let n={value:t.default,type:t.type,isUniform:!1,name:t.name,vecLen:0};if("float"===n.type&&(n.value=y(t.default)),t.type.startsWith("vec"))try{n.vecLen=Number.parseInt(t.type.substr(3))}catch(e){console.log(`Error determining length of vector input type ${t.type} (${t.name})`)}if(i.length>r&&(n.value=i[r],"function"==typeof i[r]?(n.value=(e,n,s)=>{try{let e=i[r](n);if("number"==typeof e)return e;return console.warn("function does not return a number",i[r]),t.default}catch(e){return console.warn("ERROR",e),t.default}},n.isUniform=!0):i[r].constructor===Array&&(n.value=(t,e,n)=>p.getValue(i[r])(e),n.isUniform=!0)),e<0);else{if(n.value&&n.value.transforms){let e=n.value.transforms[n.value.transforms.length-1];if(e.transform.glsl_return_type!==t.type){let r=v[t.type];if(void 0!==r){let t=r[e.transform.glsl_return_type];if(void 0!==t){let{name:e,args:r}=t;n.value=n.value[e](...r)}}}n.isUniform=!1}else if("float"===n.type&&"number"==typeof n.value)n.value=y(n.value);else if(n.type.startsWith("vec")&&"object"==typeof n.value&&Array.isArray(n.value))n.isUniform=!1,n.value=`${n.type}(${n.value.map(y).join(", ")})`;else if("sampler2D"===t.type){var s=n.value;n.value=()=>s.getTexture(),n.isUniform=!0}else if(n.value.getTexture&&"vec4"===t.type){var c=n.value;n.value=o(c),n.isUniform=!1}n.isUniform&&(n.name+=e)}return n})}(t,e.uniforms.length);n.forEach(t=>{t.isUniform&&e.uniforms.push(t)}),!function(t,e){for(var r=0;r<e.length;r++)if(t.name==e[r].name)return!0;return!1}(t,e.glslFunctions)&&e.glslFunctions.push(t);var i=r;if("src"===t.transform.type)r=r=>`${b(r,t.name,n,e)}`;else if("coord"===t.transform.type)r=r=>`${i(`${b(r,t.name,n,e)}`)}`;else if("color"===t.transform.type)r=r=>`${b(`${i(r)}`,t.name,n,e)}`;else if("combine"===t.transform.type){var s=n[0].value&&n[0].value.transforms?t=>`${g(n[0].value.transforms,e)(t)}`:n[0].isUniform?()=>n[0].name:()=>n[0].value;r=r=>`${b(`${i(r)}, ${s(r)}`,t.name,n.slice(1),e)}`}else if("combineCoord"===t.transform.type){var s=n[0].value&&n[0].value.transforms?t=>`${g(n[0].value.transforms,e)(t)}`:n[0].isUniform?()=>n[0].name:()=>n[0].value;r=r=>`${i(`${b(`${r}, ${s(r)}`,t.name,n.slice(1),e)}`)}`}}),r}function b(t,e,r,n){let i=r.map(t=>t.isUniform?t.name:t.value&&t.value.transforms?`${g(t.value.transforms,n)("st")}`:t.value).reduce((t,e)=>`${t}, ${e}`,"");return`${e}(${t}${i})`}var _={_luminance:{type:"util",glsl:`float _luminance(vec3 rgb){ 26 const vec3 W = vec3(0.2125, 0.7154, 0.0721); 27 return dot(rgb, W); 28 }`},_noise:{type:"util",glsl:` 29 // Simplex 3D Noise 30 // by Ian McEwan, Ashima Arts 31 vec4 permute(vec4 x){return mod(((x*34.0)+1.0)*x, 289.0);} 32 vec4 taylorInvSqrt(vec4 r){return 1.79284291400159 - 0.85373472095314 * r;} 33 34 float _noise(vec3 v){ 35 const vec2 C = vec2(1.0/6.0, 1.0/3.0) ; 36 const vec4 D = vec4(0.0, 0.5, 1.0, 2.0); 37 38 // First corner 39 vec3 i = floor(v + dot(v, C.yyy) ); 40 vec3 x0 = v - i + dot(i, C.xxx) ; 41 42 // Other corners 43 vec3 g = step(x0.yzx, x0.xyz); 44 vec3 l = 1.0 - g; 45 vec3 i1 = min( g.xyz, l.zxy ); 46 vec3 i2 = max( g.xyz, l.zxy ); 47 48 // x0 = x0 - 0. + 0.0 * C 49 vec3 x1 = x0 - i1 + 1.0 * C.xxx; 50 vec3 x2 = x0 - i2 + 2.0 * C.xxx; 51 vec3 x3 = x0 - 1. + 3.0 * C.xxx; 52 53 // Permutations 54 i = mod(i, 289.0 ); 55 vec4 p = permute( permute( permute( 56 i.z + vec4(0.0, i1.z, i2.z, 1.0 )) 57 + i.y + vec4(0.0, i1.y, i2.y, 1.0 )) 58 + i.x + vec4(0.0, i1.x, i2.x, 1.0 )); 59 60 // Gradients 61 // ( N*N points uniformly over a square, mapped onto an octahedron.) 62 float n_ = 1.0/7.0; // N=7 63 vec3 ns = n_ * D.wyz - D.xzx; 64 65 vec4 j = p - 49.0 * floor(p * ns.z *ns.z); // mod(p,N*N) 66 67 vec4 x_ = floor(j * ns.z); 68 vec4 y_ = floor(j - 7.0 * x_ ); // mod(j,N) 69 70 vec4 x = x_ *ns.x + ns.yyyy; 71 vec4 y = y_ *ns.x + ns.yyyy; 72 vec4 h = 1.0 - abs(x) - abs(y); 73 74 vec4 b0 = vec4( x.xy, y.xy ); 75 vec4 b1 = vec4( x.zw, y.zw ); 76 77 vec4 s0 = floor(b0)*2.0 + 1.0; 78 vec4 s1 = floor(b1)*2.0 + 1.0; 79 vec4 sh = -step(h, vec4(0.0)); 80 81 vec4 a0 = b0.xzyw + s0.xzyw*sh.xxyy ; 82 vec4 a1 = b1.xzyw + s1.xzyw*sh.zzww ; 83 84 vec3 p0 = vec3(a0.xy,h.x); 85 vec3 p1 = vec3(a0.zw,h.y); 86 vec3 p2 = vec3(a1.xy,h.z); 87 vec3 p3 = vec3(a1.zw,h.w); 88 89 //Normalise gradients 90 vec4 norm = taylorInvSqrt(vec4(dot(p0,p0), dot(p1,p1), dot(p2, p2), dot(p3,p3))); 91 p0 *= norm.x; 92 p1 *= norm.y; 93 p2 *= norm.z; 94 p3 *= norm.w; 95
96 // Mix final noise value 97 vec4 m = max(0.6 - vec4(dot(x0,x0), dot(x1,x1), dot(x2,x2), dot(x3,x3)), 0.0); 98 m = m * m; 99 return 42.0 * dot( m*m, vec4( dot(p0,x0), dot(p1,x1), 100 dot(p2,x2), dot(p3,x3) ) ); 101 } 102 `},_rgbToHsv:{type:"util",glsl:`vec3 _rgbToHsv(vec3 c){ 103 vec4 K = vec4(0.0, -1.0 / 3.0, 2.0 / 3.0, -1.0); 104 vec4 p = mix(vec4(c.bg, K.wz), vec4(c.gb, K.xy), step(c.b, c.g)); 105 vec4 q = mix(vec4(p.xyw, c.r), vec4(c.r, p.yzx), step(p.x, c.r)); 106 107 float d = q.x - min(q.w, q.y); 108 float e = 1.0e-10; 109 return vec3(abs(q.z + (q.w - q.y) / (6.0 * d + e)), d / (q.x + e), q.x); 110 }`},_hsvToRgb:{type:"util",glsl:`vec3 _hsvToRgb(vec3 c){ 111 vec4 K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0); 112 vec3 p = abs(fract(c.xxx + K.xyz) * 6.0 - K.www); 113 return c.z * mix(K.xxx, clamp(p - K.xxx, 0.0, 1.0), c.y); 114 }`}},w=function(t){return this.transforms=[],this.transforms.push(t),this.defaultOutput=t.defaultOutput,this.synth=t.synth,this.type="GlslSource",this.defaultUniforms=t.defaultUniforms,this};w.prototype.addTransform=function(t){this.transforms.push(t)},w.prototype.out=function(t){var e=t||this.defaultOutput,r=this.glsl(e);if(this.synth.currentFunctions=[],e)try{e.render(r)}catch(t){console.log("shader could not compile",t)}},w.prototype.glsl=function(){var t=[],e=[];
114return this.transforms.forEach(t=>{"renderpass"===t.transform.type?console.warn("no support for renderpass"):e.push(t)}),e.length>0&&t.push(this.compile(e)),t},w.prototype.compile=function(t){let e;var r,n,i=(this.synth,n=g(t,r={uniforms:[],glslFunctions:[],fragColor:""})("st"),r.fragColor=n,e={},r.uniforms.forEach(t=>e[t.name]=t),r.uniforms=Object.values(e),r),s={};return i.uniforms.forEach(t=>{s[t.name]=t.value}),{frag:` 115 precision ${this.defaultOutput.precision} float; 116 ${Object.values(i.uniforms).map(t=>{let e=t.type;return"texture"===t.type&&(e="sampler2D"),` 117 uniform ${e} ${t.name};`}).join("")} 118 uniform float time; 119 uniform vec2 resolution; 120 varying vec2 uv; 121 uniform sampler2D prevBuffer; 122 123 ${Object.values(_).map(t=>` 124 ${t.glsl} 125 `).join("")} 126 127 ${i.glslFunctions.map(t=>` 128 ${t.transform.glsl} 129 `).join("")} 130 131 void main () { 132 vec4 c = vec4(1, 0, 0, 1); 133 vec2 st = gl_FragCoord.xy/resolution.xy; 134 gl_FragColor = ${i.fragColor}; 135 } 136 `,uniforms:Object.assign({},this.defaultUniforms,s)}};var S=w,M=()=>[{name:"noise",type:"src",inputs:[{type:"float",name:"scale",default:10},{type:"float",name:"offset",default:.1}],glsl:" return vec4(vec3(_noise(vec3(_st*scale, offset*time))), 1.0);"},{name:"voronoi",type:"src",inputs:[{type:"float",name:"scale",default:5},{type:"float",name:"speed",default:.3},{type:"float",name:"blending",default:.3}],glsl:` vec3 color = vec3(.0); 137 // Scale 138 _st *= scale; 139 // Tile the space 140 vec2 i_st = floor(_st); 141 vec2 f_st = fract(_st); 142 float m_dist = 10.; // minimun distance 143 vec2 m_point; // minimum point 144 for (int j=-1; j<=1; j++ ) { 145 for (int i=-1; i<=1; i++ ) { 146 vec2 neighbor = vec2(float(i),float(j)); 147 vec2 p = i_st + neighbor; 148 vec2 point = fract(sin(vec2(dot(p,vec2(127.1,311.7)),dot(p,vec2(269.5,183.3))))*43758.5453); 149 point = 0.5 + 0.5*sin(time*speed + 6.2831*point); 150 vec2 diff = neighbor + point - f_st; 151 float dist = length(diff); 152 if( dist < m_dist ) { 153 m_dist = dist; 154 m_point = point; 155 } 156 } 157 } 158 // Assign a color using the closest point position 159 color += dot(m_point,vec2(.3,.6)); 160 color *= 1.0 - blending*m_dist; 161 return vec4(color, 1.0);`},{name:"osc",type:"src",inputs:[{type:"float",name:"frequency",default:60},{type:"float",name:"sync",default:.1},{type:"float",name:"offset",default:0}],glsl:` vec2 st = _st; 162 float r = sin((st.x-offset/frequency+time*sync)*frequency)*0.5 + 0.5; 163 float g = sin((st.x+time*sync)*frequency)*0.5 + 0.5; 164 float b = sin((st.x+offset/frequency+time*sync)*frequency)*0.5 + 0.5; 165 return vec4(r, g, b, 1.0);`},{name:"shape",type:"src",inputs:[{type:"float",name:"sides",default:3},{type:"float",name:"radius",default:.3},{type:"float",name:"smoothing",default:.01}],glsl:` vec2 st = _st * 2. - 1.; 166 // Angle and radius from the current pixel 167 float a = atan(st.x,st.y)+3.1416; 168 float r = (2.*3.1416)/sides; 169 float d = cos(floor(.5+a/r)*r-a)*length(st); 170 return vec4(vec3(1.0-smoothstep(radius,radius + smoothing + 0.0000001,d)), 1.0);`},{name:"gradient",type:"src",inputs:[{type:"float",name:"speed",default:0}],glsl:" return vec4(_st, sin(time*speed), 1.0);"},{name:"src",type:"src",inputs:[{type:"sampler2D",name:"tex",default:NaN}],glsl:` // vec2 uv = gl_FragCoord.xy/vec2(1280., 720.); 171 return texture2D(tex, fract(_st));`},{name:"solid",type:"src",inputs:[{type:"float",name:"r",default:0},{type:"float",name:"g",default:0},{type:"float",name:"b",default:0},{type:"float",name:"a",default:1}],glsl:" return vec4(r, g, b, a);"},{name:"rotate",type:"coord",inputs:[{type:"float",name:"angle",default:10},{type:"float",name:"speed",default:0}],glsl:` vec2 xy = _st - vec2(0.5); 172 float ang = angle + speed *time; 173 xy = mat2(cos(ang),-sin(ang), sin(ang),cos(ang))*xy; 174 xy += 0.5; 175 return xy;`},{name:"scale",type:"coord",inputs:[{type:"float",name:"amount",default:1.5},{type:"float",name:"xMult",default:1},{type:"float",name:"yMult",default:1},{type:"float",name:"offsetX",default:.5},{type:"float",name:"offsetY",default:.5}],glsl:` vec2 xy = _st - vec2(offsetX, offsetY); 176 xy*=(1.0/vec2(amount*xMult, amount*yMult)); 177 xy+=vec2(offsetX, offsetY); 178 return xy; 179 `},{name:"pixelate",type:"coord",inputs:[{type:"float",name:"pixelX",default:20},{type:"float",name:"pixelY",default:20}],glsl:` vec2 xy = vec2(pixelX, pixelY); 180 return (floor(_st * xy) + 0.5)/xy;`},{name:"posterize",type:"color",inputs:[{type:"float",name:"bins",default:3},{type:"float",name:"gamma",default:.6}],glsl:` vec4 c2 = pow(_c0, vec4(gamma)); 181 c2 *= vec4(bins); 182 c2 = floor(c2); 183 c2/= vec4(bins); 184 c2 = pow(c2, vec4(1.0/gamma)); 185 return vec4(c2.xyz, _c0.a);`},{name:"shift",type:"color",inputs:[{type:"float",name:"r",default:.5},{type:"float",name:"g",default:0},{type:"float",name:"b",default:0},{type:"float",name:"a",default:0}],glsl:` vec4 c2 = vec4(_c0); 186 c2.r = fract(c2.r + r); 187 c2.g = fract(c2.g + g); 188 c2.b = fract(c2.b + b); 189 c2.a = fract(c2.a + a); 190 return vec4(c2.rgba);`},{name:"repeat",type:"coord",inputs:[{type:"float",name:"repeatX",default:3},{type:"float",name:"repeatY",default:3},{type:"float",name:"offsetX",default:0},{type:"float",name:"offsetY",default:0}],glsl:` vec2 st = _st * vec2(repeatX, repeatY); 191 st.x += step(1., mod(st.y,2.0)) * offsetX; 192 st.y += step(1., mod(st.x,2.0)) * offsetY; 193 return fract(st);`},{name:"modulateRepeat",type:"combineCoord",inputs:[{type:"float",name:"repeatX",default:3},{type:"float",name:"repeatY",default:3},{type:"float",name:"offsetX",default:.5},{type:"float",name:"offsetY",default:.5}],glsl:` vec2 st = _st * vec2(repeatX, repeatY); 194 st.x += step(1., mod(st.y,2.0)) + _c0.r * offsetX; 195 st.y += step(1., mod(st.x,2.0)) + _c0.g * offsetY; 196 return fract(st);`},{name:"repeatX",type:"coord",inputs:[{type:"float",name:"reps",default:3},{type:"float",name:"offset",default:0}],glsl:` vec2 st = _st * vec2(reps, 1.0); 197 // float f = mod(_st.y,2.0); 198 st.y += step(1., mod(st.x,2.0))* offset; 199 return fract(st);`},{name:"modulateRepeatX",type:"combineCoord",inputs:[{type:"float",name:"reps",default:3},{type:"float",name:"offset",default:.5}],glsl:` vec2 st = _st * vec2(reps, 1.0); 200 // float f = mod(_st.y,2.0); 201 st.y += step(1., mod(st.x,2.0)) + _c0.r * offset; 202 return fract(st);`},{name:"repeatY",type:"coord",inputs:[{type:"float",name:"reps",default:3},{type:"float",name:"offset",default:0}],glsl:` vec2 st = _st * vec2(1.0, reps); 203 // float f = mod(_st.y,2.0); 204 st.x += step(1., mod(st.y,2.0))* offset; 205 return fract(st);`},{name:"modulateRepeatY",type:"combineCoord",inputs:[{type:"float",name:"reps",default:3},{type:"float",name:"offset",default:.5}],glsl:` vec2 st = _st * vec2(reps, 1.0); 206 // float f = mod(_st.y,2.0); 207 st.x += step(1., mod(st.y,2.0)) + _c0.r * offset; 208 return fract(st);`},{name:"kaleid",type:"coord",inputs:[{type:"float",name:"nSides",default:4}],glsl:` vec2 st = _st; 209 st -= 0.5; 210 float r = length(st); 211 float a = atan(st.y, st.x); 212 float pi = 2.*3.1416; 213 a = mod(a,pi/nSides); 214 a = abs(a-pi/nSides/2.); 215 return r*vec2(cos(a), sin(a));`},{name:"modulateKaleid",type:"combineCoord",inputs:[{type:"float",name:"nSides",default:4}],glsl:` vec2 st = _st - 0.5; 216 float r = length(st); 217 float a = atan(st.y, st.x); 218 float pi = 2.*3.1416; 219 a = mod(a,pi/nSides); 220 a = abs(a-pi/nSides/2.); 221 return (_c0.r+r)*vec2(cos(a), sin(a));`},{name:"scroll",type:"coord",inputs:[{type:"float",name:"scrollX",default:.5},{type:"float",name:"scrollY",default:.5},{type:"float",name:"speedX",default:0},{type:"float",name:"speedY",default:0}],glsl:` 222 _st.x += scrollX + time*speedX; 223 _st.y += scrollY + time*speedY; 224 return fract(_st);`},{name:"scrollX",type:"coord",inputs:[{type:"float",name:"scrollX",default:.5},{type:"float",name:"speed",default:0}],glsl:` _st.x += scrollX + time*speed; 225 return fract(_st);`},{name:"modulateScrollX",type:"combineCoord",inputs:[{type:"float",name:"scrollX",default:.5},{type:"float",name:"speed",default:0}],glsl:` _st.x += _c0.r*scrollX + time*speed; 226 return fract(_st);`},{name:"scrollY",type:"coord",inputs:[{type:"float",name:"scrollY",default:.5},{type:"float",name:"speed",default:0}],glsl:` _st.y += scrollY + time*speed; 227 return fract(_st);`},{name:"modulateScrollY",type:"combineCoord",inputs:[{type:"float",name:"scrollY",default:.5},{type:"float",name:"speed",default:0}],glsl:` _st.y += _c0.r*scrollY + time*speed; 228 return fract(_st);`}
228,{name:"add",type:"combine",inputs:[{type:"float",name:"amount",default:1}],glsl:" return (_c0+_c1)*amount + _c0*(1.0-amount);"},{name:"sub",type:"combine",inputs:[{type:"float",name:"amount",default:1}],glsl:" return (_c0-_c1)*amount + _c0*(1.0-amount);"},{name:"layer",type:"combine",inputs:[],glsl:" return vec4(mix(_c0.rgb, _c1.rgb, _c1.a), clamp(_c0.a + _c1.a, 0.0, 1.0));"},{name:"blend",type:"combine",inputs:[{type:"float",name:"amount",default:.5}],glsl:" return _c0*(1.0-amount)+_c1*amount;"},{name:"mult",type:"combine",inputs:[{type:"float",name:"amount",default:1}],glsl:" return _c0*(1.0-amount)+(_c0*_c1)*amount;"},{name:"diff",type:"combine",inputs:[],glsl:" return vec4(abs(_c0.rgb-_c1.rgb), max(_c0.a, _c1.a));"},{name:"modulate",type:"combineCoord",inputs:[{type:"float",name:"amount",default:.1}],glsl:` // return fract(st+(_c0.xy-0.5)*amount); 229 return _st + _c0.xy*amount;`},{name:"modulateScale",type:"combineCoord",inputs:[{type:"float",name:"multiple",default:1},{type:"float",name:"offset",default:1}],glsl:` vec2 xy = _st - vec2(0.5); 230 xy*=(1.0/vec2(offset + multiple*_c0.r, offset + multiple*_c0.g)); 231 xy+=vec2(0.5); 232 return xy;`},{name:"modulatePixelate",type:"combineCoord",inputs:[{type:"float",name:"multiple",default:10},{type:"float",name:"offset",default:3}],glsl:` vec2 xy = vec2(offset + _c0.x*multiple, offset + _c0.y*multiple); 233 return (floor(_st * xy) + 0.5)/xy;`},{name:"modulateRotate",type:"combineCoord",inputs:[{type:"float",name:"multiple",default:1},{type:"float",name:"offset",default:0}],glsl:` vec2 xy = _st - vec2(0.5); 234 float angle = offset + _c0.x * multiple; 235 xy = mat2(cos(angle),-sin(angle), sin(angle),cos(angle))*xy; 236 xy += 0.5; 237 return xy;`},{name:"modulateHue",type:"combineCoord",inputs:[{type:"float",name:"amount",default:1}],glsl:" return _st + (vec2(_c0.g - _c0.r, _c0.b - _c0.g) * amount * 1.0/resolution);"},{name:"invert",type:"color",inputs:[{type:"float",name:"amount",default:1}],glsl:" return vec4((1.0-_c0.rgb)*amount + _c0.rgb*(1.0-amount), _c0.a);"},{name:"contrast",type:"color",inputs:[{type:"float",name:"amount",default:1.6}],glsl:` vec4 c = (_c0-vec4(0.5))*vec4(amount) + vec4(0.5); 238 return vec4(c.rgb, _c0.a);`},{name:"brightness",type:"color",inputs:[{type:"float",name:"amount",default:.4}],glsl:" return vec4(_c0.rgb + vec3(amount), _c0.a);"},{name:"mask",type:"combine",inputs:[],glsl:` float a = _luminance(_c1.rgb); 239 return vec4(_c0.rgb*a, a*_c0.a);`},{name:"luma",type:"color",inputs:[{type:"float",name:"threshold",default:.5},{type:"float",name:"tolerance",default:.1}],glsl:` float a = smoothstep(threshold-(tolerance+0.0000001), threshold+(tolerance+0.0000001), _luminance(_c0.rgb)); 240 return vec4(_c0.rgb*a, a);`},{name:"thresh",type:"color",inputs:[{type:"float",name:"threshold",default:.5},{type:"float",name:"tolerance",default:.04}],glsl:" return vec4(vec3(smoothstep(threshold-(tolerance+0.0000001), threshold+(tolerance+0.0000001), _luminance(_c0.rgb))), _c0.a);"},{name:"color",type:"color",inputs:[{type:"float",name:"r",default:1},{type:"float",name:"g",default:1},{type:"float",name:"b",default:1},{type:"float",name:"a",default:1}],glsl:` vec4 c = vec4(r, g, b, a); 241 vec4 pos = step(0.0, c); // detect whether negative 242 // if > 0, return r * _c0 243 // if < 0 return (1.0-r) * _c0 244 return vec4(mix((1.0-_c0)*abs(c), c*_c0, pos));`},{name:"saturate",type:"color",inputs:[{type:"float",name:"amount",default:2}],glsl:` const vec3 W = vec3(0.2125, 0.7154, 0.0721); 245 vec3 intensity = vec3(dot(_c0.rgb, W)); 246 return vec4(mix(intensity, _c0.rgb, amount), _c0.a);`},{name:"hue",type:"color",inputs:[{type:"float",name:"hue",default:.4}],glsl:` vec3 c = _rgbToHsv(_c0.rgb); 247 c.r += hue; 248 // c.r = fract(c.r); 249 return vec4(_hsvToRgb(c), _c0.a);`},{name:"colorama",type:"color",inputs:[{type:"float",name:"amount",default:.005}],glsl:` vec3 c = _rgbToHsv(_c0.rgb); 250 c += vec3(amount); 251 c = _hsvToRgb(c); 252 c = fract(c); 253 return vec4(c, _c0.a);`},{name:"prev",type:"src",inputs:[],glsl:" return texture2D(prevBuffer, fract(_st));"},{name:"sum",type:"color",inputs:[{type:"vec4",name:"scale",default:1}],glsl:` vec4 v = _c0 * s; 254 return v.r + v.g + v.b + v.a; 255 } 256 float sum(vec2 _st, vec4 s) { // vec4 is not a typo, because argument type is not overloaded 257 vec2 v = _st.xy * s.xy; 258 return v.x + v.y;`},{name:"r",type:"color",inputs:[{type:"float",name:"scale",default:1},{type:"float",name:"offset",default:0}],glsl:" return vec4(_c0.r * scale + offset);"},{name:"g",type:"color",inputs:[{type:"float",name:"scale",default:1},{type:"float",name:"offset",default:0}],glsl:" return vec4(_c0.g * scale + offset);"},{name:"b",type:"color",inputs:[{type:"float",name:"scale",default:1},{type:"float",name:"offset",default:0}],glsl:" return vec4(_c0.b * scale + offset);"},{name:"a",type:"color",inputs:[{type:"float",name:"scale",default:1},{type:"float",name:"offset",default:0}],glsl:" return vec4(_c0.a * scale + offset);"}];class E{constructor({defaultUniforms:t,defaultOutput:e,extendTransforms:r=[],changeListener:n=()=>{}}={}){this.defaultOutput=e,this.defaultUniforms=t,this.changeListener=n,this.extendTransforms=r,this.generators={},this.init()}init(){let t=M();return this.glslTransforms={},this.generators=Object.entries(this.generators).reduce((t,[e,r])=>(this.changeListener({type:"remove",synth:this,method:e}),t),{}),this.sourceClass=class extends S{},Array.isArray(this.extendTransforms)?t.concat(this.extendTransforms):"object"==typeof this.extendTransforms&&this.extendTransforms.type&&t.push(this.extendTransforms),t.map(t=>this.setFunction(t))}_addMethod(t,e){let r=this;if(this.glslTransforms[t]=e,"src"===e.type){let n=(...n)=>new this.sourceClass({name:t,transform:e,userArgs:n,defaultOutput:this.defaultOutput,defaultUniforms:this.defaultUniforms,synth:r});return this.generators[t]=n,this.changeListener({type:"add",synth:this,method:t}),n}this.sourceClass.prototype[t]=function(...n){return this.transforms.push({name:t,transform:e,userArgs:n,synth:r}),this}}setFunction(t){var e=function(t){let e=C[t.type];if(e){let r=e.args.map(t=>t).join(", "),n=t.inputs.map(t=>`${t.type} ${t.name}`).join(", "),i=`${r}${n.length>0?", "+n:""}`,s=` 259 ${e.returnType} ${t.name}(${i}) { 260 ${t.glsl} 261 } 262`;
262return("combine"===t.type||"combineCoord"===t.type)&&t.inputs.unshift({name:"color",type:"vec4"}),Object.assign({},t,{glsl:s})}console.warn(`type ${t.type} not recognized`,t)}(t);e&&this._addMethod(t.name,e)}}let C={src:{returnType:"vec4",args:["vec2 _st"]},coord:{returnType:"vec2",args:["vec2 _st"]},color:{returnType:"vec4",args:["vec4 _c0"]},combine:{returnType:"vec4",args:["vec4 _c0","vec4 _c1"]},combineCoord:{returnType:"vec2",args:["vec2 _st","vec4 _c0"]}};var T=r(2902);let k=function(t,e){e||(e=t,t=window);var r=0,n=0,i=0,s={shift:!1,alt:!1,control:!1,meta:!1},c=!1;function l(t){var e=!1;return"altKey"in t&&(e=e||t.altKey!==s.alt,s.alt=!!t.altKey),"shiftKey"in t&&(e=e||t.shiftKey!==s.shift,s.shift=!!t.shiftKey),"ctrlKey"in t&&(e=e||t.ctrlKey!==s.control,s.control=!!t.ctrlKey),"metaKey"in t&&(e=e||t.metaKey!==s.meta,s.meta=!!t.metaKey),e}function u(t,c){var u=o.x(c),h=o.y(c);"buttons"in c&&(t=0|c.buttons),(t!==r||u!==n||h!==i||l(c))&&(r=0|t,n=u||0,i=h||0,e&&e(r,n,i,s))}function h(t){u(0,t)}function f(){(r||n||i||s.shift||s.alt||s.meta||s.control)&&(n=i=0,r=0,s.shift=s.alt=s.control=s.meta=!1,e&&e(0,0,0,s))}function p(t){l(t)&&e&&e(r,n,i,s)}function m(t){0===o.buttons(t)?u(0,t):u(r,t)}function d(t){u(r|o.buttons(t),t)}function v(t){u(r&~o.buttons(t),t)}function y(){c||(c=!0,t.addEventListener("mousemove",m),t.addEventListener("mousedown",d),t.addEventListener("mouseup",v),t.addEventListener("mouseleave",h),t.addEventListener("mouseenter",h),t.addEventListener("mouseout",h),t.addEventListener("mouseover",h),t.addEventListener("blur",f),t.addEventListener("keyup",p),t.addEventListener("keydown",p),t.addEventListener("keypress",p),t!==window&&(window.addEventListener("blur",f),window.addEventListener("keyup",p),window.addEventListener("keydown",p),window.addEventListener("keypress",p)))}y();var g={element:t};return Object.defineProperties(g,{enabled:{get:function(){return c},set:function(e){e?y():c&&(c=!1,t.removeEventListener("mousemove",m),t.removeEventListener("mousedown",d),t.removeEventListener("mouseup",v),t.removeEventListener("mouseleave",h),t.removeEventListener("mouseenter",h),t.removeEventListener("mouseout",h),t.removeEventListener("mouseover",h),t.removeEventListener("blur",f),t.removeEventListener("keyup",p),t.removeEventListener("keydown",p),t.removeEventListener("keypress",p),t!==window&&(window.removeEventListener("blur",f),window.removeEventListener("keyup",p),window.removeEventListener("keydown",p),window.removeEventListener("keypress",p)))},enumerable:!0},buttons:{get:function(){return r},enumerable:!0},x:{get:function(){return n},enumerable:!0},y:{get:function(){return i},enumerable:!0},mods:{get:function(){return s},enumerable:!0}}),g}();class A{constructor({pb:t=null,width:e=1280,height:r=720,numSources:n=4,numOutputs:s=4,makeGlobal:o=!0,autoLoop:c=!0,detectAudio:l=!0,enableStreamCapture:h=!0,canvas:f,precision:m,extendTransforms:v={}}={}){if(p.init(),this.pb=t,this.width=e,this.height=r,this.renderAll=!1,this.detectAudio=l,this._initCanvas(f),this.synth={time:0,bpm:30,width:this.width,height:this.height,fps:void 0,stats:{fps:0},speed:1,mouse:k,render:this._render.bind(this),setResolution:this.setResolution.bind(this),update:t=>{},hush:this.hush.bind(this),tick:this.tick.bind(this)},o&&(window.loadScript=this.loadScript),this.timeSinceLastUpdate=0,this._time=0,m&&["lowp","mediump","highp"].includes(m.toLowerCase()))this.precision=m.toLowerCase();else{let t=(/iPad|iPhone|iPod/.test(navigator.platform)||"MacIntel"===navigator.platform&&navigator.maxTouchPoints>1)&&!window.MSStream;this.precision=t?"highp":"mediump"}if(this.extendTransforms=v,this.saveFrame=!1,this.captureStream=null,this.generator=void 0,this._initRegl(),this._initOutputs(s),this._initSources(n),this._generateGlslTransforms(),this.synth.screencap=()=>{this.saveFrame=!0},h)try{this.captureStream=this.canvas.captureStream(25),this.synth.vidRecorder=new u(this.captureStream)}catch(t){console.warn("[hydra-synth warning]\nnew MediaSource() is not currently supported on iOS."),console.error(t)}l&&this._initAudio(),c&&i(this.tick.bind(this)).start(),this.sandbox=new d(this.synth,o,["speed","update","bpm","fps"])}eval(t){this.sandbox.eval(t)}getScreenImage(t){this.imageCallback=t,this.saveFrame=!0}
262hush(){this.s.forEach(t=>{t.clear()}),this.o.forEach(t=>{this.synth.solid(0,0,0,0).out(t)}),this.synth.render(this.o[0]),this.sandbox.set("update",t=>{})}loadScript(t=""){return new Promise((e,r)=>{var n=document.createElement("script");n.onload=function(){console.log(`loaded script ${t}`),e()},n.onerror=r=>{console.log(`error loading script ${t}`,"log-error"),e()},n.src=t,document.head.appendChild(n)})}setResolution(t,e){this.canvas.width=t,this.canvas.height=e,this.width=t,this.height=e,this.sandbox.set("width",t),this.sandbox.set("height",e),console.log(this.width),this.o.forEach(r=>{r.resize(t,e)}),this.s.forEach(r=>{r.resize(t,e)}),this.regl._refresh(),console.log(this.canvas.width)}canvasToImage(t){let e=document.createElement("a");e.style.display="none";let r=new Date;e.download=`hydra-${r.getFullYear()}-${r.getMonth()+1}-${r.getDate()}-${r.getHours()}.${r.getMinutes()}.${r.getSeconds()}.png`,document.body.appendChild(e);var n=this;this.canvas.toBlob(t=>{n.imageCallback?(n.imageCallback(t),delete n.imageCallback):(e.href=URL.createObjectURL(t),console.log(e.href),e.click())},"image/png"),setTimeout(()=>{document.body.removeChild(e),window.URL.revokeObjectURL(e.href)},300)}_initAudio(){this.synth.a=new l({numBins:4,parentEl:this.canvas.parentNode})}_initCanvas(t){t?(this.canvas=t,this.width=t.width,this.height=t.height):(this.canvas=document.createElement("canvas"),this.canvas.width=this.width,this.canvas.height=this.height,this.canvas.style.width="100%",this.canvas.style.height="100%",this.canvas.style.imageRendering="pixelated",document.body.appendChild(this.canvas))}_initRegl(){this.regl=T({canvas:this.canvas,pixelRatio:1}),this.regl.clear({color:[0,0,0,1]}),this.renderAll=this.regl({frag:` 263 precision ${this.precision} float; 264 varying vec2 uv; 265 uniform sampler2D tex0; 266 uniform sampler2D tex1; 267 uniform sampler2D tex2; 268 uniform sampler2D tex3; 269 270 void main () { 271 vec2 st = vec2(1.0 - uv.x, uv.y); 272 st*= vec2(2); 273 vec2 q = floor(st).xy*(vec2(2.0, 1.0)); 274 int quad = int(q.x) + int(q.y); 275 st.x += step(1., mod(st.y,2.0)); 276 st.y += step(1., mod(st.x,2.0)); 277 st = fract(st); 278 if(quad==0){ 279 gl_FragColor = texture2D(tex0, st); 280 } else if(quad==1){ 281 gl_FragColor = texture2D(tex1, st); 282 } else if (quad==2){ 283 gl_FragColor = texture2D(tex2, st); 284 } else { 285 gl_FragColor = texture2D(tex3, st); 286 } 287 288 } 289 `,vert:` 290 precision ${this.precision} float; 291 attribute vec2 position; 292 varying vec2 uv; 293 294 void main () { 295 uv = position; 296 gl_Position = vec4(1.0 - 2.0 * position, 0, 1); 297 }`,attributes:{position:[[-2,0],[0,-2],[2,2]]},uniforms:{tex0:this.regl.prop("tex0"),tex1:this.regl.prop("tex1"),tex2:this.regl.prop("tex2"),tex3:this.regl.prop("tex3")},count:3,depth:{enable:!1}}),this.renderFbo=this.regl({frag:` 298 precision ${this.precision} float; 299 varying vec2 uv; 300 uniform vec2 resolution; 301 uniform sampler2D tex0; 302 303 void main () { 304 gl_FragColor = texture2D(tex0, vec2(1.0 - uv.x, uv.y)); 305 } 306 `,vert:` 307 precision ${this.precision} float; 308 attribute vec2 position; 309 varying vec2 uv; 310 311 void main () { 312 uv = position; 313 gl_Position = vec4(1.0 - 2.0 * position, 0, 1); 314 }`,attributes:{position:[[-2,0],[0,-2],[2,2]]},uniforms:{tex0:this.regl.prop("tex0"),resolution:this.regl.prop("resolution")},count:3,depth:{enable:!1}})}_initOutputs(t){let e=this;this.o=Array(t).fill().map((t,r)=>{var i=new n({regl:this.regl,width:this.width,height:this.height,precision:this.precision,label:`o${r}`});return i.id=r,e.synth["o"+r]=i,i}),this.output=this.o[0]}_initSources(t){this.s=[];for(var e=0;e<t;e++)this.createSource(e)}createSource(t){let e=new s({regl:this.regl,pb:this.pb,width:this.width,height:this.height,label:`s${t}`});return this.synth["s"+this.s.length]=e,this.s.push(e),e}_generateGlslTransforms(){var t=this;this.generator=new E({defaultOutput:this.o[0],defaultUniforms:this.o[0].uniforms,extendTransforms:this.extendTransforms,changeListener:({type:e,method:r,synth:n})=>{"add"===e&&(t.synth[r]=n.generators[r],t.sandbox&&t.sandbox.add(r))}}),this.synth.setFunction=this.generator.setFunction.bind(this.generator)}_render(t){t?(this.output=t,this.isRenderingAll=!1):this.isRenderingAll=!0}tick(t,e){if(this.sandbox.tick(),!0===this.detectAudio&&this.synth.a.tick(),this.sandbox.set("time",this.synth.time+=.001*t*this.synth.speed),this.timeSinceLastUpdate+=t,!this.synth.fps||this.timeSinceLastUpdate>=1e3/this.synth.fps){if(this.synth.stats.fps=Math.ceil(1e3/this.timeSinceLastUpdate),this.synth.update)try{this.synth.update(this.timeSinceLastUpdate)}catch(t){console.log(t)}for(let t=0;t<this.s.length;t++)this.s[t].tick(this.synth.time);for(let t=0;t<this.o.length;t++)this.o[t].tick({time:this.synth.time,mouse:this.synth.mouse,bpm:this.synth.bpm,resolution:[this.canvas.width,this.canvas.height]});this.isRenderingAll?this.renderAll({tex0:this.o[0].getCurrent(),tex1:this.o[1].getCurrent(),tex2:this.o[2].getCurrent(),tex3:this.o[3].getCurrent(),resolution:[this.canvas.width,this.canvas.height]}):this.renderFbo({tex0:this.output.getCurrent(),resolution:[this.canvas.width,this.canvas.height]}),this.timeSinceLastUpdate=0}!0===this.saveFrame&&(this.canvasToImage(),this.saveFrame=!1)}}var F=A}}]);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.