UNPKG

hydra-element

Version:

A custom element for wrapping the hydra-synth engine

1,071 lines (1,067 loc) 322 kB
var Output = function({ regl: c, precision: i, label: d = "", width: b, height: w }) { this.regl = c, this.precision = i, this.label = d, this.positionBuffer = this.regl.buffer([ [-2, 0], [0, -2], [2, 2] ]), this.draw = () => { }, this.init(), this.pingPongIndex = 0, this.fbos = Array(2).fill().map(() => this.regl.framebuffer({ color: this.regl.texture({ mag: "nearest", width: b, height: w, format: "rgba" }), depthStencil: !1 })); }; Output.prototype.resize = function(c, i) { this.fbos.forEach((d) => { d.resize(c, i); }); }; Output.prototype.getCurrent = function() { return this.fbos[this.pingPongIndex]; }; Output.prototype.getTexture = function() { var c = this.pingPongIndex ? 0 : 1; return this.fbos[c]; }; Output.prototype.init = function() { return this.transformIndex = 0, this.fragHeader = ` precision ${this.precision} float; uniform float time; varying vec2 uv; `, this.fragBody = "", this.vert = ` precision ${this.precision} float; attribute vec2 position; varying vec2 uv; void main () { uv = position; gl_Position = vec4(2.0 * position - 1.0, 0, 1); }`, this.attributes = { position: this.positionBuffer }, this.uniforms = { time: this.regl.prop("time"), resolution: this.regl.prop("resolution") }, this.frag = ` ${this.fragHeader} void main () { vec4 c = vec4(0, 0, 0, 0); vec2 st = uv; ${this.fragBody} gl_FragColor = c; } `, this; }; Output.prototype.render = function(c) { let i = c[0]; var d = this, b = Object.assign(i.uniforms, { prevBuffer: () => d.fbos[d.pingPongIndex] }); d.draw = d.regl({ frag: i.frag, vert: d.vert, attributes: d.attributes, uniforms: b, count: 3, framebuffer: () => (d.pingPongIndex = d.pingPongIndex ? 0 : 1, d.fbos[d.pingPongIndex]) }); }; Output.prototype.tick = function(c) { this.draw(c); }; var commonjsGlobal = typeof globalThis < "u" ? globalThis : typeof window < "u" ? window : typeof global < "u" ? global : typeof self < "u" ? self : {}; function getDefaultExportFromCjs(c) { return c && c.__esModule && Object.prototype.hasOwnProperty.call(c, "default") ? c.default : c; } var inherits_browser = { exports: {} }, hasRequiredInherits_browser; function requireInherits_browser() { return hasRequiredInherits_browser || (hasRequiredInherits_browser = 1, typeof Object.create == "function" ? inherits_browser.exports = function(i, d) { d && (i.super_ = d, i.prototype = Object.create(d.prototype, { constructor: { value: i, enumerable: !1, writable: !0, configurable: !0 } })); } : inherits_browser.exports = function(i, d) { if (d) { i.super_ = d; var b = function() { }; b.prototype = d.prototype, i.prototype = new b(), i.prototype.constructor = i; } }), inherits_browser.exports; } var events, hasRequiredEvents; function requireEvents() { if (hasRequiredEvents) return events; hasRequiredEvents = 1; function c() { this._events = this._events || {}, this._maxListeners = this._maxListeners || void 0; } events = c, c.EventEmitter = c, c.prototype._events = void 0, c.prototype._maxListeners = void 0, c.defaultMaxListeners = 10, c.prototype.setMaxListeners = function(L) { if (!d(L) || L < 0 || isNaN(L)) throw TypeError("n must be a positive number"); return this._maxListeners = L, this; }, c.prototype.emit = function(L) { var ne, U, pe, he, Ve, Pe; if (this._events || (this._events = {}), L === "error" && (!this._events.error || b(this._events.error) && !this._events.error.length)) { if (ne = arguments[1], ne instanceof Error) throw ne; var Xe = new Error('Uncaught, unspecified "error" event. (' + ne + ")"); throw Xe.context = ne, Xe; } if (U = this._events[L], w(U)) return !1; if (i(U)) switch (arguments.length) { // fast cases case 1: U.call(this); break; case 2: U.call(this, arguments[1]); break; case 3: U.call(this, arguments[1], arguments[2]); break; // slower default: he = Array.prototype.slice.call(arguments, 1), U.apply(this, he); } else if (b(U)) for (he = Array.prototype.slice.call(arguments, 1), Pe = U.slice(), pe = Pe.length, Ve = 0; Ve < pe; Ve++) Pe[Ve].apply(this, he); return !0; }, c.prototype.addListener = function(L, ne) { var U; if (!i(ne)) throw TypeError("listener must be a function"); return this._events || (this._events = {}), this._events.newListener && this.emit( "newListener", L, i(ne.listener) ? ne.listener : ne ), this._events[L] ? b(this._events[L]) ? this._events[L].push(ne) : this._events[L] = [this._events[L], ne] : this._events[L] = ne, b(this._events[L]) && !this._events[L].warned && (w(this._maxListeners) ? U = c.defaultMaxListeners : U = this._maxListeners, U && U > 0 && this._events[L].length > U && (this._events[L].warned = !0, console.error( "(node) warning: possible EventEmitter memory leak detected. %d listeners added. Use emitter.setMaxListeners() to increase limit.", this._events[L].length ), typeof console.trace == "function" && console.trace())), this; }, c.prototype.on = c.prototype.addListener, c.prototype.once = function(L, ne) { if (!i(ne)) throw TypeError("listener must be a function"); var U = !1; function pe() { this.removeListener(L, pe), U || (U = !0, ne.apply(this, arguments)); } return pe.listener = ne, this.on(L, pe), this; }, c.prototype.removeListener = function(L, ne) { var U, pe, he, Ve; if (!i(ne)) throw TypeError("listener must be a function"); if (!this._events || !this._events[L]) return this; if (U = this._events[L], he = U.length, pe = -1, U === ne || i(U.listener) && U.listener === ne) delete this._events[L], this._events.removeListener && this.emit("removeListener", L, ne); else if (b(U)) { for (Ve = he; Ve-- > 0; ) if (U[Ve] === ne || U[Ve].listener && U[Ve].listener === ne) { pe = Ve; break; } if (pe < 0) return this; U.length === 1 ? (U.length = 0, delete this._events[L]) : U.splice(pe, 1), this._events.removeListener && this.emit("removeListener", L, ne); } return this; }, c.prototype.removeAllListeners = function(L) { var ne, U; if (!this._events) return this; if (!this._events.removeListener) return arguments.length === 0 ? this._events = {} : this._events[L] && delete this._events[L], this; if (arguments.length === 0) { for (ne in this._events) ne !== "removeListener" && this.removeAllListeners(ne); return this.removeAllListeners("removeListener"), this._events = {}, this; } if (U = this._events[L], i(U)) this.removeListener(L, U); else if (U) for (; U.length; ) this.removeListener(L, U[U.length - 1]); return delete this._events[L], this; }, c.prototype.listeners = function(L) { var ne; return !this._events || !this._events[L] ? ne = [] : i(this._events[L]) ? ne = [this._events[L]] : ne = this._events[L].slice(), ne; }, c.prototype.listenerCount = function(L) { if (this._events) { var ne = this._events[L]; if (i(ne)) return 1; if (ne) return ne.length; } return 0; }, c.listenerCount = function(L, ne) { return L.listenerCount(ne); }; function i(L) { return typeof L == "function"; } function d(L) { return typeof L == "number"; } function b(L) { return typeof L == "object" && L !== null; } function w(L) { return L === void 0; } return events; } var browser, hasRequiredBrowser; function requireBrowser() { return hasRequiredBrowser || (hasRequiredBrowser = 1, browser = commonjsGlobal.performance && commonjsGlobal.performance.now ? function() { return performance.now(); } : Date.now || function() { return +/* @__PURE__ */ new Date(); }), browser; } var raf = { exports: {} }, performanceNow$1 = { exports: {} }, performanceNow = performanceNow$1.exports, hasRequiredPerformanceNow; function requirePerformanceNow() { return hasRequiredPerformanceNow || (hasRequiredPerformanceNow = 1, (function() { var c, i, d, b, w, L; typeof performance < "u" && performance !== null && performance.now ? performanceNow$1.exports = function() { return performance.now(); } : typeof process < "u" && process !== null && process.hrtime ? (performanceNow$1.exports = function() { return (c() - w) / 1e6; }, i = process.hrtime, c = function() { var ne; return ne = i(), ne[0] * 1e9 + ne[1]; }, b = c(), L = process.uptime() * 1e9, w = b - L) : Date.now ? (performanceNow$1.exports = function() { return Date.now() - d; }, d = Date.now()) : (performanceNow$1.exports = function() { return (/* @__PURE__ */ new Date()).getTime() - d; }, d = (/* @__PURE__ */ new Date()).getTime()); }).call(performanceNow)), performanceNow$1.exports; } var hasRequiredRaf; function requireRaf() { if (hasRequiredRaf) return raf.exports; hasRequiredRaf = 1; for (var c = requirePerformanceNow(), i = typeof window > "u" ? commonjsGlobal : window, d = ["moz", "webkit"], b = "AnimationFrame", w = i["request" + b], L = i["cancel" + b] || i["cancelRequest" + b], ne = 0; !w && ne < d.length; ne++) w = i[d[ne] + "Request" + b], L = i[d[ne] + "Cancel" + b] || i[d[ne] + "CancelRequest" + b]; if (!w || !L) { var U = 0, pe = 0, he = [], Ve = 1e3 / 60; w = function(Pe) { if (he.length === 0) { var Xe = c(), ut = Math.max(0, Ve - (Xe - U)); U = ut + Xe, setTimeout(function() { var qe = he.slice(0); he.length = 0; for (var st = 0; st < qe.length; st++) if (!qe[st].cancelled) try { qe[st].callback(U); } catch (Pt) { setTimeout(function() { throw Pt; }, 0); } }, Math.round(ut)); } return he.push({ handle: ++pe, callback: Pe, cancelled: !1 }), pe; }, L = function(Pe) { for (var Xe = 0; Xe < he.length; Xe++) he[Xe].handle === Pe && (he[Xe].cancelled = !0); }; } return raf.exports = function(Pe) { return w.call(i, Pe); }, raf.exports.cancel = function() { L.apply(i, arguments); }, raf.exports.polyfill = function(Pe) { Pe || (Pe = i), Pe.requestAnimationFrame = w, Pe.cancelAnimationFrame = L; }, raf.exports; } var rafLoop, hasRequiredRafLoop; function requireRafLoop() { if (hasRequiredRafLoop) return rafLoop; hasRequiredRafLoop = 1; var c = requireInherits_browser(), i = requireEvents().EventEmitter, d = requireBrowser(), b = requireRaf(); rafLoop = w; function w(L) { if (!(this instanceof w)) return new w(L); this.running = !1, this.last = d(), this._frame = 0, this._tick = this.tick.bind(this), L && this.on("tick", L); } return c(w, i), w.prototype.start = function() { if (!this.running) return this.running = !0, this.last = d(), this._frame = b(this._tick), this; }, w.prototype.stop = function() { return this.running = !1, this._frame !== 0 && b.cancel(this._frame), this._frame = 0, this; }, w.prototype.tick = function() { this._frame = b(this._tick); var L = d(), ne = L - this.last; this.emit("tick", ne), this.last = L; }, rafLoop; } var rafLoopExports = requireRafLoop(); const loop = /* @__PURE__ */ getDefaultExportFromCjs(rafLoopExports); function Webcam(c) { return navigator.mediaDevices.enumerateDevices().then((i) => i.filter((d) => d.kind === "videoinput")).then((i) => { let d = { audio: !1, video: !0 }; return i[c] && (d.video = { deviceId: { exact: i[c].deviceId } }), window.navigator.mediaDevices.getUserMedia(d); }).then((i) => { const d = document.createElement("video"); return d.setAttribute("autoplay", ""), d.setAttribute("muted", ""), d.setAttribute("playsinline", ""), d.srcObject = i, new Promise((b, w) => { d.addEventListener("loadedmetadata", () => { d.play().then(() => b({ video: d })); }); }); }).catch(console.log.bind(console)); } function Screen(c) { return new Promise(function(i, d) { navigator.mediaDevices.getDisplayMedia(c).then((b) => { const w = document.createElement("video"); w.srcObject = b, w.addEventListener("loadedmetadata", () => { w.play(), i({ video: w }); }); }).catch((b) => d(b)); }); } class HydraSource { constructor({ regl: i, width: d, height: b, pb: w, label: L = "" }) { this.label = L, this.regl = i, this.src = null, this.dynamic = !0, this.width = d, this.height = b, this.tex = this.regl.texture({ // shape: [width, height] shape: [1, 1] }), this.pb = w; } init(i, d) { "src" in i && (this.src = i.src, this.tex = this.regl.texture({ data: this.src, ...d })), "dynamic" in i && (this.dynamic = i.dynamic); } initCam(i, d) { const b = this; Webcam(i).then((w) => { b.src = w.video, b.dynamic = !0, b.tex = b.regl.texture({ data: b.src, ...d }); }).catch((w) => console.log("could not get camera", w)); } initVideo(i = "", d) { const b = document.createElement("video"); b.crossOrigin = "anonymous", b.autoplay = !0, b.loop = !0, b.muted = !0, b.addEventListener("loadeddata", () => { this.src = b, b.play(), this.tex = this.regl.texture({ data: this.src, ...d }), this.dynamic = !0; }), b.src = i; } initImage(i = "", d) { const b = document.createElement("img"); b.crossOrigin = "anonymous", b.src = i, b.onload = () => { this.src = b, this.dynamic = !1, this.tex = this.regl.texture({ data: this.src, ...d }); }; } initStream(i, d) { let b = this; i && this.pb && (this.pb.initSource(i), this.pb.on("got video", function(w, L) { w === i && (b.src = L, b.dynamic = !0, b.tex = b.regl.texture({ data: b.src, ...d })); })); } // index only relevant in atom-hydra + desktop apps initScreen(i = 0, d) { const b = this; Screen().then(function(w) { b.src = w.video, b.tex = b.regl.texture({ data: b.src, ...d }), b.dynamic = !0; }).catch((w) => console.log("could not get screen", w)); } // cache for the canvases, so we don't create them every time canvases = {}; // Creates a canvas and returns the 2d context initCanvas(i = 1e3, d = 1e3) { if (this.canvases[this.label] == null) { const ne = document.createElement("canvas").getContext("2d"); ne != null && (this.canvases[this.label] = ne); } const b = this.canvases[this.label], w = b.canvas; return w.width !== i && w.height !== d ? (w.width = i, w.height = d) : b.clearRect(0, 0, i, d), this.init({ src: w }), this.dynamic = !0, b; } resize(i, d) { this.width = i, this.height = d; } clear() { this.src && this.src.srcObject && this.src.srcObject.getTracks && this.src.srcObject.getTracks().forEach((i) => i.stop()), this.src = null, this.tex = this.regl.texture({ shape: [1, 1] }); } tick(i) { this.src && this.dynamic === !0 && (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; } } const mouse = {}; function mouseButtons(c) { if (typeof c == "object") { if ("buttons" in c) return c.buttons; if ("which" in c) { var i = c.which; if (i === 2) return 4; if (i === 3) return 2; if (i > 0) return 1 << i - 1; } else if ("button" in c) { var i = c.button; if (i === 1) return 4; if (i === 2) return 2; if (i >= 0) return 1 << i; } } return 0; } mouse.buttons = mouseButtons; function mouseElement(c) { return c.target || c.srcElement || window; } mouse.element = mouseElement; function mouseRelativeX(c) { return typeof c == "object" && "pageX" in c ? c.pageX : 0; } mouse.x = mouseRelativeX; function mouseRelativeY(c) { return typeof c == "object" && "pageY" in c ? c.pageY : 0; } mouse.y = mouseRelativeY; function mouseListen(c, i) { i || (i = c, c = window); var d = 0, b = 0, w = 0, L = { shift: !1, alt: !1, control: !1, meta: !1 }, ne = !1; function U(Ue) { var rt = !1; return "altKey" in Ue && (rt = rt || Ue.altKey !== L.alt, L.alt = !!Ue.altKey), "shiftKey" in Ue && (rt = rt || Ue.shiftKey !== L.shift, L.shift = !!Ue.shiftKey), "ctrlKey" in Ue && (rt = rt || Ue.ctrlKey !== L.control, L.control = !!Ue.ctrlKey), "metaKey" in Ue && (rt = rt || Ue.metaKey !== L.meta, L.meta = !!Ue.metaKey), rt; } function pe(Ue, rt) { var qt = mouse.x(rt), gt = mouse.y(rt); "buttons" in rt && (Ue = rt.buttons | 0), (Ue !== d || qt !== b || gt !== w || U(rt)) && (d = Ue | 0, b = qt || 0, w = gt || 0, i && i(d, b, w, L)); } function he(Ue) { pe(0, Ue); } function Ve() { (d || b || w || L.shift || L.alt || L.meta || L.control) && (b = w = 0, d = 0, L.shift = L.alt = L.control = L.meta = !1, i && i(0, 0, 0, L)); } function Pe(Ue) { U(Ue) && i && i(d, b, w, L); } function Xe(Ue) { mouse.buttons(Ue) === 0 ? pe(0, Ue) : pe(d, Ue); } function ut(Ue) { pe(d | mouse.buttons(Ue), Ue); } function qe(Ue) { pe(d & ~mouse.buttons(Ue), Ue); } function st() { ne || (ne = !0, c.addEventListener("mousemove", Xe), c.addEventListener("mousedown", ut), c.addEventListener("mouseup", qe), c.addEventListener("mouseleave", he), c.addEventListener("mouseenter", he), c.addEventListener("mouseout", he), c.addEventListener("mouseover", he), c.addEventListener("blur", Ve), c.addEventListener("keyup", Pe), c.addEventListener("keydown", Pe), c.addEventListener("keypress", Pe), c !== window && (window.addEventListener("blur", Ve), window.addEventListener("keyup", Pe), window.addEventListener("keydown", Pe), window.addEventListener("keypress", Pe))); } function Pt() { ne && (ne = !1, c.removeEventListener("mousemove", Xe), c.removeEventListener("mousedown", ut), c.removeEventListener("mouseup", qe), c.removeEventListener("mouseleave", he), c.removeEventListener("mouseenter", he), c.removeEventListener("mouseout", he), c.removeEventListener("mouseover", he), c.removeEventListener("blur", Ve), c.removeEventListener("keyup", Pe), c.removeEventListener("keydown", Pe), c.removeEventListener("keypress", Pe), c !== window && (window.removeEventListener("blur", Ve), window.removeEventListener("keyup", Pe), window.removeEventListener("keydown", Pe), window.removeEventListener("keypress", Pe))); } st(); var pt = { element: c }; return Object.defineProperties(pt, { enabled: { get: function() { return ne; }, set: function(Ue) { Ue ? st() : Pt(); }, enumerable: !0 }, buttons: { get: function() { return d; }, enumerable: !0 }, x: { get: function() { return b; }, enumerable: !0 }, y: { get: function() { return w; }, enumerable: !0 }, mods: { get: function() { return L; }, enumerable: !0 } }), pt; } var meyda_min$1 = { exports: {} }, meyda_min = meyda_min$1.exports, hasRequiredMeyda_min; function requireMeyda_min() { return hasRequiredMeyda_min || (hasRequiredMeyda_min = 1, (function(c, i) { (function(d, b) { c.exports = b(); })(meyda_min, (function() { function d(R, y, j) { for (var C, ee = 0, me = y.length; ee < me; ee++) !C && ee in y || (C || (C = Array.prototype.slice.call(y, 0, ee)), C[ee] = y[ee]); return R.concat(C || Array.prototype.slice.call(y)); } var b = Object.freeze({ __proto__: null, blackman: function(R) { for (var y = new Float32Array(R), j = 2 * Math.PI / (R - 1), C = 2 * j, ee = 0; ee < R / 2; ee++) y[ee] = 0.42 - 0.5 * Math.cos(ee * j) + 0.08 * Math.cos(ee * C); for (ee = Math.ceil(R / 2); ee > 0; ee--) y[R - ee] = y[ee - 1]; return y; }, hamming: function(R) { for (var y = new Float32Array(R), j = 0; j < R; j++) y[j] = 0.54 - 0.46 * Math.cos(2 * Math.PI * (j / R - 1)); return y; }, hanning: function(R) { for (var y = new Float32Array(R), j = 0; j < R; j++) y[j] = 0.5 - 0.5 * Math.cos(2 * Math.PI * j / (R - 1)); return y; }, sine: function(R) { for (var y = Math.PI / (R - 1), j = new Float32Array(R), C = 0; C < R; C++) j[C] = Math.sin(y * C); return j; } }), w = {}; function L(R) { for (; R % 2 == 0 && R > 1; ) R /= 2; return R === 1; } function ne(R, y) { if (y !== "rect") { if (y !== "" && y || (y = "hanning"), w[y] || (w[y] = {}), !w[y][R.length]) try { w[y][R.length] = b[y](R.length); } catch { throw new Error("Invalid windowing function"); } R = (function(j, C) { for (var ee = [], me = 0; me < Math.min(j.length, C.length); me++) ee[me] = j[me] * C[me]; return ee; })(R, w[y][R.length]); } return R; } function U(R, y, j) { for (var C = new Float32Array(R), ee = 0; ee < C.length; ee++) C[ee] = ee * y / j, C[ee] = 13 * Math.atan(C[ee] / 1315.8) + 3.5 * Math.atan(Math.pow(C[ee] / 7518, 2)); return C; } function pe(R) { return Float32Array.from(R); } function he(R) { return 1125 * Math.log(1 + R / 700); } function Ve(R, y, j) { for (var C, ee = new Float32Array(R + 2), me = new Float32Array(R + 2), Ce = y / 2, Ne = he(0), we = (he(Ce) - Ne) / (R + 1), Ee = new Array(R + 2), ke = 0; ke < ee.length; ke++) ee[ke] = ke * we, me[ke] = (C = ee[ke], 700 * (Math.exp(C / 1125) - 1)), Ee[ke] = Math.floor((j + 1) * me[ke] / y); for (var vt = new Array(R), Ie = 0; Ie < vt.length; Ie++) { for (vt[Ie] = new Array(j / 2 + 1).fill(0), ke = Ee[Ie]; ke < Ee[Ie + 1]; ke++) vt[Ie][ke] = (ke - Ee[Ie]) / (Ee[Ie + 1] - Ee[Ie]); for (ke = Ee[Ie + 1]; ke < Ee[Ie + 2]; ke++) vt[Ie][ke] = (Ee[Ie + 2] - ke) / (Ee[Ie + 2] - Ee[Ie + 1]); } return vt; } function Pe(R, y, j, C, ee, me, Ce) { C === void 0 && (C = 5), ee === void 0 && (ee = 2), me === void 0 && (me = !0), Ce === void 0 && (Ce = 440); var Ne = Math.floor(j / 2) + 1, we = new Array(j).fill(0).map((function(nt, mt) { return R * (function(yt, Ft) { return Math.log2(16 * yt / Ft); })(y * mt / j, Ce); })); we[0] = we[1] - 1.5 * R; var Ee, ke, vt, Ie = we.slice(1).map((function(nt, mt) { return Math.max(nt - we[mt]); }), 1).concat([1]), Rt = Math.round(R / 2), At = new Array(R).fill(0).map((function(nt, mt) { return we.map((function(yt) { return (10 * R + Rt + yt - mt) % R - Rt; })); })), wt = At.map((function(nt, mt) { return nt.map((function(yt, Ft) { return Math.exp(-0.5 * Math.pow(2 * At[mt][Ft] / Ie[Ft], 2)); })); })); if (ke = (Ee = wt)[0].map((function() { return 0; })), vt = Ee.reduce((function(nt, mt) { return mt.forEach((function(yt, Ft) { nt[Ft] += Math.pow(yt, 2); })), nt; }), ke).map(Math.sqrt), wt = Ee.map((function(nt, mt) { return nt.map((function(yt, Ft) { return yt / (vt[Ft] || 1); })); })), ee) { var Tr = we.map((function(nt) { return Math.exp(-0.5 * Math.pow((nt / R - C) / ee, 2)); })); wt = wt.map((function(nt) { return nt.map((function(mt, yt) { return mt * Tr[yt]; })); })); } return me && (wt = d(d([], wt.slice(3), !0), wt.slice(0, 3))), wt.map((function(nt) { return nt.slice(0, Ne); })); } function Xe(R, y) { for (var j = 0, C = 0, ee = 0; ee < y.length; ee++) j += Math.pow(ee, R) * Math.abs(y[ee]), C += y[ee]; return j / C; } function ut(R) { var y = R.ampSpectrum, j = R.barkScale, C = R.numberOfBarkBands, ee = C === void 0 ? 24 : C; if (typeof y != "object" || typeof j != "object") throw new TypeError(); var me = ee, Ce = new Float32Array(me), Ne = 0, we = y, Ee = new Int32Array(me + 1); Ee[0] = 0; for (var ke = j[we.length - 1] / me, vt = 1, Ie = 0; Ie < we.length; Ie++) for (; j[Ie] > ke; ) Ee[vt++] = Ie, ke = vt * j[we.length - 1] / me; for (Ee[me] = we.length - 1, Ie = 0; Ie < me; Ie++) { for (var Rt = 0, At = Ee[Ie]; At < Ee[Ie + 1]; At++) Rt += we[At]; Ce[Ie] = Math.pow(Rt, 0.23); } for (Ie = 0; Ie < Ce.length; Ie++) Ne += Ce[Ie]; return { specific: Ce, total: Ne }; } function qe(R) { var y = R.ampSpectrum; if (typeof y != "object") throw new TypeError(); for (var j = new Float32Array(y.length), C = 0; C < j.length; C++) j[C] = Math.pow(y[C], 2); return j; } function st(R) { var y = R.ampSpectrum, j = R.melFilterBank, C = R.bufferSize; if (typeof y != "object") throw new TypeError("Valid ampSpectrum is required to generate melBands"); if (typeof j != "object") throw new TypeError("Valid melFilterBank is required to generate melBands"); for (var ee = qe({ ampSpectrum: y }), me = j.length, Ce = Array(me), Ne = new Float32Array(me), we = 0; we < Ne.length; we++) { Ce[we] = new Float32Array(C / 2), Ne[we] = 0; for (var Ee = 0; Ee < C / 2; Ee++) Ce[we][Ee] = j[we][Ee] * ee[Ee], Ne[we] += Ce[we][Ee]; Ne[we] = Math.log(Ne[we] + 1); } return Array.prototype.slice.call(Ne); } function Pt(R) { return R && R.__esModule && Object.prototype.hasOwnProperty.call(R, "default") ? R.default : R; } var pt = null, Ue = Pt((function(R, y) { var j = R.length; return y = y || 2, pt && pt[j] || (function(C) { (pt = pt || {})[C] = new Array(C * C); for (var ee = Math.PI / C, me = 0; me < C; me++) for (var Ce = 0; Ce < C; Ce++) pt[C][Ce + me * C] = Math.cos(ee * (Ce + 0.5) * me); })(j), R.map((function() { return 0; })).map((function(C, ee) { return y * R.reduce((function(me, Ce, Ne, we) { return me + Ce * pt[j][Ne + ee * j]; }), 0); })); })), rt = Object.freeze({ __proto__: null, amplitudeSpectrum: function(R) { return R.ampSpectrum; }, buffer: function(R) { return R.signal; }, chroma: function(R) { var y = R.ampSpectrum, j = R.chromaFilterBank; if (typeof y != "object") throw new TypeError("Valid ampSpectrum is required to generate chroma"); if (typeof j != "object") throw new TypeError("Valid chromaFilterBank is required to generate chroma"); var C = j.map((function(me, Ce) { return y.reduce((function(Ne, we, Ee) { return Ne + we * me[Ee]; }), 0); })), ee = Math.max.apply(Math, C); return ee ? C.map((function(me) { return me / ee; })) : C; }, complexSpectrum: function(R) { return R.complexSpectrum; }, energy: function(R) { var y = R.signal; if (typeof y != "object") throw new TypeError(); for (var j = 0, C = 0; C < y.length; C++) j += Math.pow(Math.abs(y[C]), 2); return j; }, loudness: ut, melBands: st, mfcc: function(R) { var y = R.ampSpectrum, j = R.melFilterBank, C = R.numberOfMFCCCoefficients, ee = R.bufferSize, me = Math.min(40, Math.max(1, C || 13)); if (j.length < me) throw new Error("Insufficient filter bank for requested number of coefficients"); var Ce = st({ ampSpectrum: y, melFilterBank: j, bufferSize: ee }); return Ue(Ce).slice(0, me); }, perceptualSharpness: function(R) { for (var y = ut({ ampSpectrum: R.ampSpectrum, barkScale: R.barkScale }), j = y.specific, C = 0, ee = 0; ee < j.length; ee++) C += ee < 15 ? (ee + 1) * j[ee + 1] : 0.066 * Math.exp(0.171 * (ee + 1)); return C *= 0.11 / y.total; }, perceptualSpread: function(R) { for (var y = ut({ ampSpectrum: R.ampSpectrum, barkScale: R.barkScale }), j = 0, C = 0; C < y.specific.length; C++) y.specific[C] > j && (j = y.specific[C]); return Math.pow((y.total - j) / y.total, 2); }, powerSpectrum: qe, rms: function(R) { var y = R.signal; if (typeof y != "object") throw new TypeError(); for (var j = 0, C = 0; C < y.length; C++) j += Math.pow(y[C], 2); return j /= y.length, j = Math.sqrt(j); }, spectralCentroid: function(R) { var y = R.ampSpectrum; if (typeof y != "object") throw new TypeError(); return Xe(1, y); }, spectralCrest: function(R) { var y = R.ampSpectrum; if (typeof y != "object") throw new TypeError(); var j = 0, C = -1 / 0; return y.forEach((function(ee) { j += Math.pow(ee, 2), C = ee > C ? ee : C; })), j /= y.length, j = Math.sqrt(j), C / j; }, spectralFlatness: function(R) { var y = R.ampSpectrum; if (typeof y != "object") throw new TypeError(); for (var j = 0, C = 0, ee = 0; ee < y.length; ee++) j += Math.log(y[ee]), C += y[ee]; return Math.exp(j / y.length) * y.length / C; }, spectralFlux: function(R) { var y = R.signal, j = R.previousSignal, C = R.bufferSize; if (typeof y != "object" || typeof j != "object") throw new TypeError(); for (var ee = 0, me = -C / 2; me < y.length / 2 - 1; me++) x = Math.abs(y[me]) - Math.abs(j[me]), ee += (x + Math.abs(x)) / 2; return ee; }, spectralKurtosis: function(R) { var y = R.ampSpectrum; if (typeof y != "object") throw new TypeError(); var j = y, C = Xe(1, j), ee = Xe(2, j), me = Xe(3, j), Ce = Xe(4, j); return (-3 * Math.pow(C, 4) + 6 * C * ee - 4 * C * me + Ce) / Math.pow(Math.sqrt(ee - Math.pow(C, 2)), 4); }, spectralRolloff: function(R) { var y = R.ampSpectrum, j = R.sampleRate; if (typeof y != "object") throw new TypeError(); for (var C = y, ee = j / (2 * (C.length - 1)), me = 0, Ce = 0; Ce < C.length; Ce++) me += C[Ce]; for (var Ne = 0.99 * me, we = C.length - 1; me > Ne && we >= 0; ) me -= C[we], --we; return (we + 1) * ee; }, spectralSkewness: function(R) { var y = R.ampSpectrum; if (typeof y != "object") throw new TypeError(); var j = Xe(1, y), C = Xe(2, y), ee = Xe(3, y); return (2 * Math.pow(j, 3) - 3 * j * C + ee) / Math.pow(Math.sqrt(C - Math.pow(j, 2)), 3); }, spectralSlope: function(R) { var y = R.ampSpectrum, j = R.sampleRate, C = R.bufferSize; if (typeof y != "object") throw new TypeError(); for (var ee = 0, me = 0, Ce = new Float32Array(y.length), Ne = 0, we = 0, Ee = 0; Ee < y.length; Ee++) { ee += y[Ee]; var ke = Ee * j / C; Ce[Ee] = ke, Ne += ke * ke, me += ke, we += ke * y[Ee]; } return (y.length * we - me * ee) / (ee * (Ne - Math.pow(me, 2))); }, spectralSpread: function(R) { var y = R.ampSpectrum; if (typeof y != "object") throw new TypeError(); return Math.sqrt(Xe(2, y) - Math.pow(Xe(1, y), 2)); }, zcr: function(R) { var y = R.signal; if (typeof y != "object") throw new TypeError(); for (var j = 0, C = 1; C < y.length; C++) (y[C - 1] >= 0 && y[C] < 0 || y[C - 1] < 0 && y[C] >= 0) && j++; return j; } }); function qt(R) { if (Array.isArray(R)) { for (var y = 0, j = Array(R.length); y < R.length; y++) j[y] = R[y]; return j; } return Array.from(R); } var gt = {}, or = {}, Mt = { bitReverseArray: function(R) { if (gt[R] === void 0) { for (var y = (R - 1).toString(2).length, j = "0".repeat(y), C = {}, ee = 0; ee < R; ee++) { var me = ee.toString(2); me = j.substr(me.length) + me, me = [].concat(qt(me)).reverse().join(""), C[ee] = parseInt(me, 2); } gt[R] = C; } return gt[R]; }, multiply: function(R, y) { return { real: R.real * y.real - R.imag * y.imag, imag: R.real * y.imag + R.imag * y.real }; }, add: function(R, y) { return { real: R.real + y.real, imag: R.imag + y.imag }; }, subtract: function(R, y) { return { real: R.real - y.real, imag: R.imag - y.imag }; }, euler: function(R, y) { var j = -2 * Math.PI * R / y; return { real: Math.cos(j), imag: Math.sin(j) }; }, conj: function(R) { return R.imag *= -1, R; }, constructComplexArray: function(R) { var y = {}; y.real = R.real === void 0 ? R.slice() : R.real.slice(); var j = y.real.length; return or[j] === void 0 && (or[j] = Array.apply(null, Array(j)).map(Number.prototype.valueOf, 0)), y.imag = or[j].slice(), y; } }, xn = function(R) { var y = {}; R.real === void 0 || R.imag === void 0 ? y = Mt.constructComplexArray(R) : (y.real = R.real.slice(), y.imag = R.imag.slice()); var j = y.real.length, C = Math.log2(j); if (Math.round(C) != C) throw new Error("Input size must be a power of 2."); if (y.real.length != y.imag.length) throw new Error("Real and imaginary components must have the same length."); for (var ee = Mt.bitReverseArray(j), me = { real: [], imag: [] }, Ce = 0; Ce < j; Ce++) me.real[ee[Ce]] = y.real[Ce], me.imag[ee[Ce]] = y.imag[Ce]; for (var Ne = 0; Ne < j; Ne++) y.real[Ne] = me.real[Ne], y.imag[Ne] = me.imag[Ne]; for (var we = 1; we <= C; we++) for (var Ee = Math.pow(2, we), ke = 0; ke < Ee / 2; ke++) for (var vt = Mt.euler(ke, Ee), Ie = 0; Ie < j / Ee; Ie++) { var Rt = Ee * Ie + ke, At = Ee * Ie + ke + Ee / 2, wt = { real: y.real[Rt], imag: y.imag[Rt] }, Tr = { real: y.real[At], imag: y.imag[At] }, nt = Mt.multiply(vt, Tr), mt = Mt.subtract(wt, nt); y.real[At] = mt.real, y.imag[At] = mt.imag; var yt = Mt.add(nt, wt); y.real[Rt] = yt.real, y.imag[Rt] = yt.imag; } return y; }, En = xn, An = (function() { function R(y, j) { var C = this; if (this._m = j, !y.audioContext) throw this._m.errors.noAC; if (y.bufferSize && !L(y.bufferSize)) throw this._m._errors.notPow2; if (!y.source) throw this._m._errors.noSource; this._m.audioContext = y.audioContext, this._m.bufferSize = y.bufferSize || this._m.bufferSize || 256, this._m.hopSize = y.hopSize || this._m.hopSize || this._m.bufferSize, this._m.sampleRate = y.sampleRate || this._m.audioContext.sampleRate || 44100, this._m.callback = y.callback, this._m.windowingFunction = y.windowingFunction || "hanning", this._m.featureExtractors = rt, this._m.EXTRACTION_STARTED = y.startImmediately || !1, this._m.channel = typeof y.channel == "number" ? y.channel : 0, this._m.inputs = y.inputs || 1, this._m.outputs = y.outputs || 1, this._m.numberOfMFCCCoefficients = y.numberOfMFCCCoefficients || this._m.numberOfMFCCCoefficients || 13, this._m.numberOfBarkBands = y.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 = y.featureExtractors || [], this._m.barkScale = U(this._m.bufferSize, this._m.sampleRate, this._m.bufferSize), this._m.melFilterBank = Ve(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(y.source), this._m.spn.onaudioprocess = function(ee) { var me; C._m.inputData !== null && (C._m.previousInputData = C._m.inputData), C._m.inputData = ee.inputBuffer.getChannelData(C._m.channel), C._m.previousInputData ? ((me = new Float32Array(C._m.previousInputData.length + C._m.inputData.length - C._m.hopSize)).set(C._m.previousInputData.slice(C._m.hopSize)), me.set(C._m.inputData, C._m.previousInputData.length - C._m.hopSize)) : me = C._m.inputData; var Ce = (function(Ne, we, Ee) { if (Ne.length < we) throw new Error("Buffer is too short for frame length"); if (Ee < 1) throw new Error("Hop length cannot be less that 1"); if (we < 1) throw new Error("Frame length cannot be less that 1"); var ke = 1 + Math.floor((Ne.length - we) / Ee); return new Array(ke).fill(0).map((function(vt, Ie) { return Ne.slice(Ie * Ee, Ie * Ee + we); })); })(me, C._m.bufferSize, C._m.hopSize); Ce.forEach((function(Ne) { C._m.frame = Ne; var we = C._m.extract(C._m._featuresToExtract, C._m.frame, C._m.previousFrame); typeof C._m.callback == "function" && C._m.EXTRACTION_STARTED && C._m.callback(we), C._m.previousFrame = C._m.frame; })); }; } return R.prototype.start = function(y) { this._m._featuresToExtract = y || this._m._featuresToExtract, this._m.EXTRACTION_STARTED = !0; }, R.prototype.stop = function() { this._m.EXTRACTION_STARTED = !1; }, R.prototype.setSource = function(y) { this._m.source && this._m.source.disconnect(this._m.spn), this._m.source = y, this._m.source.connect(this._m.spn); }, R.prototype.setChannel = function(y) { y <= this._m.inputs ? this._m.channel = y : console.error("Channel ".concat(y, " does not exist. Make sure you've provided a value for 'inputs' that is greater than ").concat(y, " when instantiating the MeydaAnalyzer")); }, R.prototype.get = function(y) { return this._m.inputData ? this._m.extract(y || this._m._featuresToExtract, this._m.inputData, this._m.previousInputData) : null; }, R; })(), Ar = { audioContext: null, spn: null, bufferSize: 512, sampleRate: 44100, melBands: 26, chromaBands: 12, callback: null, windowingFunction: "hanning", featureExtractors: rt, EXTRACTION_STARTED: !1, numberOfMFCCCoefficients: 13, numberOfBarkBands: 24, _featuresToExtract: [], windowing: ne, _errors: { notPow2: new Error("Meyda: Buffer size must be a power of 2, e.g. 64 or 512"), featureUndef: new Error("Meyda: No features defined."), invalidFeatureFmt: new Error("Meyda: Invalid feature format"), invalidInput: new Error("Meyda: Invalid input."), noAC: new Error("Meyda: No AudioContext specified."), noSource: new Error("Meyda: No source node specified.") }, createMeydaAnalyzer: function(R) { return new An(R, Object.assign({}, Ar)); }, listAvailableFeatureExtractors: function() { return Object.keys(this.featureExtractors); }, extract: function(R, y, j) { var C = this; if (!y) throw this._errors.invalidInput; if (typeof y != "object") throw this._errors.invalidInput; if (!R) throw this._errors.featureUndef; if (!L(y.length)) throw this._errors.notPow2; this.barkScale !== void 0 && this.barkScale.length == this.bufferSize || (this.barkScale = U(this.bufferSize, this.sampleRate, this.bufferSize)), this.melFilterBank !== void 0 && this.barkScale.length == this.bufferSize && this.melFilterBank.length == this.melBands || (this.melFilterBank = Ve(Math.max(this.melBands, this.numberOfMFCCCoefficients), this.sampleRate, this.bufferSize)), this.chromaFilterBank !== void 0 && this.chromaFilterBank.length == this.chromaBands || (this.chromaFilterBank = Pe(this.chromaBands, this.sampleRate, this.bufferSize)), "buffer" in y && y.buffer === void 0 ? this.signal = pe(y) : this.signal = y; var ee = wr(y, this.windowingFunction, this.bufferSize); if (this.signal = ee.windowedSignal, this.complexSpectrum = ee.complexSpectrum, this.ampSpectrum = ee.ampSpectrum, j) { var me = wr(j, this.windowingFunction, this.bufferSize); this.previousSignal = me.windowedSignal, this.previousComplexSpectrum = me.complexSpectrum, this.previousAmpSpectrum = me.ampSpectrum; } var Ce = function(Ne) { return C.featureExtractors[Ne]({ ampSpectrum: C.ampSpectrum, chromaFilterBank: C.chromaFilterBank, complexSpectrum: C.complexSpectrum, signal: C.signal, bufferSize: C.bufferSize, sampleRate: C.sampleRate, barkScale: C.barkScale, melFilterBank: C.melFilterBank, previousSignal: C.previousSignal, previousAmpSpectrum: C.previousAmpSpectrum, previousComplexSpectrum: C.previousComplexSpectrum, numberOfMFCCCoefficients: C.numberOfMFCCCoefficients, numberOfBarkBands: C.numberOfBarkBands }); }; if (typeof R == "object") return R.reduce((function(Ne, we) { var Ee; return Object.assign({}, Ne, ((Ee = {})[we] = Ce(we), Ee)); }), {}); if (typeof R == "string") return Ce(R); throw this._errors.invalidFeatureFmt; } }, wr = function(R, y, j) { var C = {}; R.buffer === void 0 ? C.signal = pe(R) : C.signal = R, C.windowedSignal = ne(C.signal, y), C.complexSpectrum = En(C.windowedSignal), C.ampSpectrum = new Float32Array(j / 2); for (var ee = 0; ee < j / 2; ee++) C.ampSpectrum[ee] = Math.sqrt(Math.pow(C.complexSpectrum.real[ee], 2) + Math.pow(C.complexSpectrum.imag[ee], 2)); return C; }; return typeof window < "u" && (window.Meyda = Ar), Ar; })); })(meyda_min$1)), meyda_min$1.exports; } var meyda_minExports = requireMeyda_min(); const Meyda = /* @__PURE__ */ getDefaultExportFromCjs(meyda_minExports); class Audio { constructor({ numBins: i = 4, cutoff: d = 2, smooth: b = 0.4, max: w = 15, scale: L = 10, isDrawing: ne = !1, parentEl: U = document.body }) { this.vol = 0, this.scale = L, this.max = w, this.cutoff = d, this.smooth = b, this.setBins(i), this.beat = { holdFrames: 20, threshold: 40, _cutoff: 0, // adaptive based on sound state decay: 0.98, _framesSinceBeat: 0 // keeps track of frames }, 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", U.appendChild(this.canvas), this.isDrawing = ne, this.ctx = this.canvas.getContext("2d"), this.ctx.fillStyle = "#DFFFFF", this.ctx.strokeStyle = "#0ff", this.ctx.lineWidth = 0.5, window.navigator.mediaDevices && window.navigator.mediaDevices.getUserMedia({ video: !1, audio: !0 }).then((pe) => { this.stream = pe, this.context = new AudioContext(); let he = this.context.createMediaStreamSource(pe); this.meyda = Meyda.createMeydaAnalyzer({ audioContext: this.context, source: he, featureExtractors: [ "loudness" // 'perceptualSpread', // 'perceptualSharpness', // 'spectralCentroid' ] }); }).catch((pe) => console.log("ERROR", pe)); } detectBeat(i) { i > this.beat._cutoff && i > this.beat.threshold ? (this.onBeat(), this.beat._cutoff = i * 1.2, 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 i = this.meyda.get(); if (i && i !== null) { this.vol = i.loudness.total, this.detectBeat(this.vol); const d = (w, L) => w + L; let b = Math.floor(i.loudness.specific.length / this.bins.length); this.prevBins = this.bins.slice(0), this.bins = this.bins.map((w, L) => i.loudness.specific.slice(L * b, (L + 1) * b).reduce(d)).map((w, L) => w * (1 - this.settings[L].smooth) + this.prevBins[L] * this.settings[L].smooth), this.fft = this.bins.map((w, L) => ( // Math.max(0, (bin - this.cutoff) / (this.max - this.cutoff)) Math.max(0, (w - this.settings[L].cutoff) / this.settings[L].scale) )), this.isDrawing && this.draw(); } } } setCutoff(i) { this.cutoff = i, this.settings = this.settings.map((d) => (d.cutoff = i, d)); } setSmooth(i) { this.smooth = i, this.settings = this.settings.map((d) => (d.smooth = i, d)); } setBins(i) { this.bins = Array(i).fill(0), this.prevBins = Array(i).fill(0), this.fft = Array(i).fill(0), this.settings = Array(i).fill(0).map(() => ({ cutoff: this.cutoff, scale: this.scale, smooth: this.smooth })), this.bins.forEach((d, b) => { window["a" + b] = (w = 1, L = 0) => () => a.fft[b] * w + L; }); } setScale(i) { this.scale = i, this.settings = this.settings.map((d) => (d.scale = i, d)); } setMax(i) { this.max = i, 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 i = this.canvas.width / this.bins.length, d = this.canvas.height / (this.max * 2); this.bins.forEach((b, w) => { var L = b * d; this.ctx.fillRect(w * i, this.canvas.height - L, i, L); var ne = this.canvas.height - d * this.settings[w].cutoff; this.ctx.beginPath(), this.ctx.moveTo(w * i, ne), this.ctx.lineTo((w + 1) * i, ne), this.ctx.stroke(); var U = this.canvas.height - d * (this.settings[w].scale + this.settings[w].cutoff); this.ctx.beginPath(), this.ctx.moveTo(w * i, U), this.ctx.lineTo((w + 1) * i, U), this.ctx.stroke(); }); } } class VideoRecorder { constructor(i) { this.mediaSource = new MediaSource(), this.stream = i, this.output = document.createElement("video"), this.output.autoplay = !0, this.output.loop = !0; let d = this; this.mediaSource.addEventListener("sourceopen", () => { console.log("MediaSource opened"), d.sourceBuffer = d.mediaSource.addSourceBuffer('video/webm; codecs="vp8"'), console.log("Source buffer: ", sourceBuffer); }); } start() { let i = { mimeType: "video/webm;codecs=vp9" }; this.recordedBlobs = []; try { this.mediaRecorder = new MediaRecorder(this.stream, i); } catch (d) { console.log("Unable to create MediaRecorder with options Object: ", d); try { i = { mimeType: "video/webm,codecs=vp9" }, this.mediaRecorder = new MediaRecorder(this.stream, i); } catch (b) { console.log("Unable to create MediaRecorder with options Object: ", b); try { i = "video/vp8", this.mediaRecorder = new MediaRecorder(this.stream, i); } catch (w) { alert(`MediaRecorder is not supported by this browser. Try 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:", w); return; } } } console.log("Created MediaRecorder", this.mediaRecorder, "with options", i), 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() { const i = new Blob(this.recordedBlobs, { type: this.mediaRecorder.mimeType }), d = window.URL.createObjectURL(i); this.output.src = d; const b = document.createElement("a"); b.style.display = "none", b.href = d; let w = /* @__PURE__ */ new Date(); b.download = `hydra-${w.getFullYear()}-${w.getMonth() + 1}-${w.getDate()}-${w.getHours()}.${w.getMinutes()}.${w.getSeconds()}.webm`, document.body.appendChild(b), b.click(), setTimeout(() => { document.body.removeChild(b), window.URL.revokeObjectURL(d); }, 300); } _handleDataAvailable(i) { i.data && i.data.size > 0 && this.recordedBlobs.push(i.data); } } const easing = { // no easing, no acceleration linear: function(c) { return c; }, // accelerating from zero velocity easeInQuad: function(c) { return c * c; }, // decelerating to zero velocity easeOutQuad: function(c) { return c * (2 - c); }, // acceleration until halfway, then deceleration easeInOutQuad: function(c) { return c < 0.5 ? 2 * c * c : -1 + (4 - 2 * c) * c; }, // accelerating from zero velocity easeInCubic: function(c) { return c * c * c; }, // decelerating to zero velocity easeOutCubic: function(c) { return --c * c * c + 1; }, // acceleration until halfway, then deceleration easeInOutCubic: function(c) { return c < 0.5 ? 4 * c * c * c : (c - 1) * (2 * c - 2) * (2 * c - 2) + 1; }, // accelerating from zero velocity easeInQuart: function(c) { return c * c * c * c; }, // decelerating to