UNPKG

hydra-element

Version:

A custom element for wrapping the hydra-synth engine

1,201 lines (1,197 loc) 309 kB
var Output = function({ regl: r, precision: n, label: d = "", width: _, height: T }) { this.regl = r, this.precision = n, 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: _, height: T, format: "rgba" }), depthStencil: !1 })); }; Output.prototype.resize = function(r, n) { this.fbos.forEach((d) => { d.resize(r, n); }); }; Output.prototype.getCurrent = function() { return this.fbos[this.pingPongIndex]; }; Output.prototype.getTexture = function() { var r = this.pingPongIndex ? 0 : 1; return this.fbos[r]; }; 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(r) { let n = r[0]; var d = this, _ = Object.assign(n.uniforms, { prevBuffer: () => d.fbos[d.pingPongIndex] }); d.draw = d.regl({ frag: n.frag, vert: d.vert, attributes: d.attributes, uniforms: _, count: 3, framebuffer: () => (d.pingPongIndex = d.pingPongIndex ? 0 : 1, d.fbos[d.pingPongIndex]) }); }; Output.prototype.tick = function(r) { this.draw(r); }; var commonjsGlobal = typeof globalThis < "u" ? globalThis : typeof window < "u" ? window : typeof global < "u" ? global : typeof self < "u" ? self : {}; function getDefaultExportFromCjs(r) { return r && r.__esModule && Object.prototype.hasOwnProperty.call(r, "default") ? r.default : r; } var inherits_browser = { exports: {} }; typeof Object.create == "function" ? inherits_browser.exports = function(n, d) { d && (n.super_ = d, n.prototype = Object.create(d.prototype, { constructor: { value: n, enumerable: !1, writable: !0, configurable: !0 } })); } : inherits_browser.exports = function(n, d) { if (d) { n.super_ = d; var _ = function() { }; _.prototype = d.prototype, n.prototype = new _(), n.prototype.constructor = n; } }; var inherits_browserExports = inherits_browser.exports; function EventEmitter$1() { this._events = this._events || {}, this._maxListeners = this._maxListeners || void 0; } var events = EventEmitter$1; EventEmitter$1.EventEmitter = EventEmitter$1; EventEmitter$1.prototype._events = void 0; EventEmitter$1.prototype._maxListeners = void 0; EventEmitter$1.defaultMaxListeners = 10; EventEmitter$1.prototype.setMaxListeners = function(r) { if (!isNumber(r) || r < 0 || isNaN(r)) throw TypeError("n must be a positive number"); return this._maxListeners = r, this; }; EventEmitter$1.prototype.emit = function(r) { var n, d, _, T, N, le; if (this._events || (this._events = {}), r === "error" && (!this._events.error || isObject(this._events.error) && !this._events.error.length)) { if (n = arguments[1], n instanceof Error) throw n; var fe = new Error('Uncaught, unspecified "error" event. (' + n + ")"); throw fe.context = n, fe; } if (d = this._events[r], isUndefined(d)) return !1; if (isFunction(d)) switch (arguments.length) { case 1: d.call(this); break; case 2: d.call(this, arguments[1]); break; case 3: d.call(this, arguments[1], arguments[2]); break; default: T = Array.prototype.slice.call(arguments, 1), d.apply(this, T); } else if (isObject(d)) for (T = Array.prototype.slice.call(arguments, 1), le = d.slice(), _ = le.length, N = 0; N < _; N++) le[N].apply(this, T); return !0; }; EventEmitter$1.prototype.addListener = function(r, n) { var d; if (!isFunction(n)) throw TypeError("listener must be a function"); return this._events || (this._events = {}), this._events.newListener && this.emit( "newListener", r, isFunction(n.listener) ? n.listener : n ), this._events[r] ? isObject(this._events[r]) ? this._events[r].push(n) : this._events[r] = [this._events[r], n] : this._events[r] = n, isObject(this._events[r]) && !this._events[r].warned && (isUndefined(this._maxListeners) ? d = EventEmitter$1.defaultMaxListeners : d = this._maxListeners, d && d > 0 && this._events[r].length > d && (this._events[r].warned = !0, console.error( "(node) warning: possible EventEmitter memory leak detected. %d listeners added. Use emitter.setMaxListeners() to increase limit.", this._events[r].length ), typeof console.trace == "function" && console.trace())), this; }; EventEmitter$1.prototype.on = EventEmitter$1.prototype.addListener; EventEmitter$1.prototype.once = function(r, n) { if (!isFunction(n)) throw TypeError("listener must be a function"); var d = !1; function _() { this.removeListener(r, _), d || (d = !0, n.apply(this, arguments)); } return _.listener = n, this.on(r, _), this; }; EventEmitter$1.prototype.removeListener = function(r, n) { var d, _, T, N; if (!isFunction(n)) throw TypeError("listener must be a function"); if (!this._events || !this._events[r]) return this; if (d = this._events[r], T = d.length, _ = -1, d === n || isFunction(d.listener) && d.listener === n) delete this._events[r], this._events.removeListener && this.emit("removeListener", r, n); else if (isObject(d)) { for (N = T; N-- > 0; ) if (d[N] === n || d[N].listener && d[N].listener === n) { _ = N; break; } if (_ < 0) return this; d.length === 1 ? (d.length = 0, delete this._events[r]) : d.splice(_, 1), this._events.removeListener && this.emit("removeListener", r, n); } return this; }; EventEmitter$1.prototype.removeAllListeners = function(r) { var n, d; if (!this._events) return this; if (!this._events.removeListener) return arguments.length === 0 ? this._events = {} : this._events[r] && delete this._events[r], this; if (arguments.length === 0) { for (n in this._events) n !== "removeListener" && this.removeAllListeners(n); return this.removeAllListeners("removeListener"), this._events = {}, this; } if (d = this._events[r], isFunction(d)) this.removeListener(r, d); else if (d) for (; d.length; ) this.removeListener(r, d[d.length - 1]); return delete this._events[r], this; }; EventEmitter$1.prototype.listeners = function(r) { var n; return !this._events || !this._events[r] ? n = [] : isFunction(this._events[r]) ? n = [this._events[r]] : n = this._events[r].slice(), n; }; EventEmitter$1.prototype.listenerCount = function(r) { if (this._events) { var n = this._events[r]; if (isFunction(n)) return 1; if (n) return n.length; } return 0; }; EventEmitter$1.listenerCount = function(r, n) { return r.listenerCount(n); }; function isFunction(r) { return typeof r == "function"; } function isNumber(r) { return typeof r == "number"; } function isObject(r) { return typeof r == "object" && r !== null; } function isUndefined(r) { return r === void 0; } var browser = commonjsGlobal.performance && commonjsGlobal.performance.now ? function() { return performance.now(); } : Date.now || function() { return +/* @__PURE__ */ new Date(); }, raf$2 = { exports: {} }, performanceNow = { exports: {} }; (function() { var r, n, d, _, T, N; typeof performance < "u" && performance !== null && performance.now ? performanceNow.exports = function() { return performance.now(); } : typeof process < "u" && process !== null && process.hrtime ? (performanceNow.exports = function() { return (r() - T) / 1e6; }, n = process.hrtime, r = function() { var le; return le = n(), le[0] * 1e9 + le[1]; }, _ = r(), N = process.uptime() * 1e9, T = _ - N) : Date.now ? (performanceNow.exports = function() { return Date.now() - d; }, d = Date.now()) : (performanceNow.exports = function() { return (/* @__PURE__ */ new Date()).getTime() - d; }, d = (/* @__PURE__ */ new Date()).getTime()); }).call(commonjsGlobal); var performanceNowExports = performanceNow.exports, now$1 = performanceNowExports, root = typeof window > "u" ? commonjsGlobal : window, vendors = ["moz", "webkit"], suffix = "AnimationFrame", raf$1 = root["request" + suffix], caf = root["cancel" + suffix] || root["cancelRequest" + suffix]; for (var i = 0; !raf$1 && i < vendors.length; i++) raf$1 = root[vendors[i] + "Request" + suffix], caf = root[vendors[i] + "Cancel" + suffix] || root[vendors[i] + "CancelRequest" + suffix]; if (!raf$1 || !caf) { var last = 0, id = 0, queue = [], frameDuration = 1e3 / 60; raf$1 = function(r) { if (queue.length === 0) { var n = now$1(), d = Math.max(0, frameDuration - (n - last)); last = d + n, setTimeout(function() { var _ = queue.slice(0); queue.length = 0; for (var T = 0; T < _.length; T++) if (!_[T].cancelled) try { _[T].callback(last); } catch (N) { setTimeout(function() { throw N; }, 0); } }, Math.round(d)); } return queue.push({ handle: ++id, callback: r, cancelled: !1 }), id; }, caf = function(r) { for (var n = 0; n < queue.length; n++) queue[n].handle === r && (queue[n].cancelled = !0); }; } raf$2.exports = function(r) { return raf$1.call(root, r); }; raf$2.exports.cancel = function() { caf.apply(root, arguments); }; raf$2.exports.polyfill = function(r) { r || (r = root), r.requestAnimationFrame = raf$1, r.cancelAnimationFrame = caf; }; var rafExports = raf$2.exports, inherits = inherits_browserExports, EventEmitter = events.EventEmitter, now = browser, raf = rafExports, rafLoop = Engine; function Engine(r) { if (!(this instanceof Engine)) return new Engine(r); this.running = !1, this.last = now(), this._frame = 0, this._tick = this.tick.bind(this), r && this.on("tick", r); } inherits(Engine, EventEmitter); Engine.prototype.start = function() { if (!this.running) return this.running = !0, this.last = now(), this._frame = raf(this._tick), this; }; Engine.prototype.stop = function() { return this.running = !1, this._frame !== 0 && raf.cancel(this._frame), this._frame = 0, this; }; Engine.prototype.tick = function() { this._frame = raf(this._tick); var r = now(), n = r - this.last; this.emit("tick", n), this.last = r; }; const loop = /* @__PURE__ */ getDefaultExportFromCjs(rafLoop); function Webcam(r) { return navigator.mediaDevices.enumerateDevices().then((n) => n.filter((d) => d.kind === "videoinput")).then((n) => { let d = { audio: !1, video: !0 }; return n[r] && (d.video = { deviceId: { exact: n[r].deviceId } }), window.navigator.mediaDevices.getUserMedia(d); }).then((n) => { const d = document.createElement("video"); return d.setAttribute("autoplay", ""), d.setAttribute("muted", ""), d.setAttribute("playsinline", ""), d.srcObject = n, new Promise((_, T) => { d.addEventListener("loadedmetadata", () => { d.play().then(() => _({ video: d })); }); }); }).catch(console.log.bind(console)); } function Screen(r) { return new Promise(function(n, d) { navigator.mediaDevices.getDisplayMedia(r).then((_) => { const T = document.createElement("video"); T.srcObject = _, T.addEventListener("loadedmetadata", () => { T.play(), n({ video: T }); }); }).catch((_) => d(_)); }); } class HydraSource { constructor({ regl: n, width: d, height: _, pb: T, label: N = "" }) { this.label = N, this.regl = n, this.src = null, this.dynamic = !0, this.width = d, this.height = _, this.tex = this.regl.texture({ // shape: [width, height] shape: [1, 1] }), this.pb = T; } init(n, d) { "src" in n && (this.src = n.src, this.tex = this.regl.texture({ data: this.src, ...d })), "dynamic" in n && (this.dynamic = n.dynamic); } initCam(n, d) { const _ = this; Webcam(n).then((T) => { _.src = T.video, _.dynamic = !0, _.tex = _.regl.texture({ data: _.src, ...d }); }).catch((T) => console.log("could not get camera", T)); } initVideo(n = "", d) { const _ = document.createElement("video"); _.crossOrigin = "anonymous", _.autoplay = !0, _.loop = !0, _.muted = !0, _.addEventListener("loadeddata", () => { this.src = _, _.play(), this.tex = this.regl.texture({ data: this.src, ...d }), this.dynamic = !0; }), _.src = n; } initImage(n = "", d) { const _ = document.createElement("img"); _.crossOrigin = "anonymous", _.src = n, _.onload = () => { this.src = _, this.dynamic = !1, this.tex = this.regl.texture({ data: this.src, ...d }); }; } initStream(n, d) { let _ = this; n && this.pb && (this.pb.initSource(n), this.pb.on("got video", function(T, N) { T === n && (_.src = N, _.dynamic = !0, _.tex = _.regl.texture({ data: _.src, ...d })); })); } // index only relevant in atom-hydra + desktop apps initScreen(n = 0, d) { const _ = this; Screen().then(function(T) { _.src = T.video, _.tex = _.regl.texture({ data: _.src, ...d }), _.dynamic = !0; }).catch((T) => console.log("could not get screen", T)); } resize(n, d) { this.width = n, this.height = d; } clear() { this.src && this.src.srcObject && this.src.srcObject.getTracks && this.src.srcObject.getTracks().forEach((n) => n.stop()), this.src = null, this.tex = this.regl.texture({ shape: [1, 1] }); } tick(n) { this.src !== null && 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(r) { if (typeof r == "object") { if ("buttons" in r) return r.buttons; if ("which" in r) { var n = r.which; if (n === 2) return 4; if (n === 3) return 2; if (n > 0) return 1 << n - 1; } else if ("button" in r) { var n = r.button; if (n === 1) return 4; if (n === 2) return 2; if (n >= 0) return 1 << n; } } return 0; } mouse.buttons = mouseButtons; function mouseElement(r) { return r.target || r.srcElement || window; } mouse.element = mouseElement; function mouseRelativeX(r) { return typeof r == "object" && "pageX" in r ? r.pageX : 0; } mouse.x = mouseRelativeX; function mouseRelativeY(r) { return typeof r == "object" && "pageY" in r ? r.pageY : 0; } mouse.y = mouseRelativeY; function mouseListen(r, n) { n || (n = r, r = window); var d = 0, _ = 0, T = 0, N = { shift: !1, alt: !1, control: !1, meta: !1 }, le = !1; function fe(Ne) { var Ze = !1; return "altKey" in Ne && (Ze = Ze || Ne.altKey !== N.alt, N.alt = !!Ne.altKey), "shiftKey" in Ne && (Ze = Ze || Ne.shiftKey !== N.shift, N.shift = !!Ne.shiftKey), "ctrlKey" in Ne && (Ze = Ze || Ne.ctrlKey !== N.control, N.control = !!Ne.ctrlKey), "metaKey" in Ne && (Ze = Ze || Ne.metaKey !== N.meta, N.meta = !!Ne.metaKey), Ze; } function Oe(Ne, Ze) { var Ct = mouse.x(Ze), yt = mouse.y(Ze); "buttons" in Ze && (Ne = Ze.buttons | 0), (Ne !== d || Ct !== _ || yt !== T || fe(Ze)) && (d = Ne | 0, _ = Ct || 0, T = yt || 0, n && n(d, _, T, N)); } function pe(Ne) { Oe(0, Ne); } function Ie() { (d || _ || T || N.shift || N.alt || N.meta || N.control) && (_ = T = 0, d = 0, N.shift = N.alt = N.control = N.meta = !1, n && n(0, 0, 0, N)); } function ve(Ne) { fe(Ne) && n && n(d, _, T, N); } function Be(Ne) { mouse.buttons(Ne) === 0 ? Oe(0, Ne) : Oe(d, Ne); } function We(Ne) { Oe(d | mouse.buttons(Ne), Ne); } function je(Ne) { Oe(d & ~mouse.buttons(Ne), Ne); } function Qe() { le || (le = !0, r.addEventListener("mousemove", Be), r.addEventListener("mousedown", We), r.addEventListener("mouseup", je), r.addEventListener("mouseleave", pe), r.addEventListener("mouseenter", pe), r.addEventListener("mouseout", pe), r.addEventListener("mouseover", pe), r.addEventListener("blur", Ie), r.addEventListener("keyup", ve), r.addEventListener("keydown", ve), r.addEventListener("keypress", ve), r !== window && (window.addEventListener("blur", Ie), window.addEventListener("keyup", ve), window.addEventListener("keydown", ve), window.addEventListener("keypress", ve))); } function ut() { le && (le = !1, r.removeEventListener("mousemove", Be), r.removeEventListener("mousedown", We), r.removeEventListener("mouseup", je), r.removeEventListener("mouseleave", pe), r.removeEventListener("mouseenter", pe), r.removeEventListener("mouseout", pe), r.removeEventListener("mouseover", pe), r.removeEventListener("blur", Ie), r.removeEventListener("keyup", ve), r.removeEventListener("keydown", ve), r.removeEventListener("keypress", ve), r !== window && (window.removeEventListener("blur", Ie), window.removeEventListener("keyup", ve), window.removeEventListener("keydown", ve), window.removeEventListener("keypress", ve))); } Qe(); var vt = { element: r }; return Object.defineProperties(vt, { enabled: { get: function() { return le; }, set: function(Ne) { Ne ? Qe() : ut(); }, enumerable: !0 }, buttons: { get: function() { return d; }, enumerable: !0 }, x: { get: function() { return _; }, enumerable: !0 }, y: { get: function() { return T; }, enumerable: !0 }, mods: { get: function() { return N; }, enumerable: !0 } }), vt; } var meyda_min = { exports: {} }, dct_1, hasRequiredDct$1; function requireDct$1() { if (hasRequiredDct$1) return dct_1; hasRequiredDct$1 = 1; var r = null, n = function(_) { r = r || {}, r[_] = new Array(_ * _); for (var T = Math.PI / _, N = 0; N < _; N++) for (var le = 0; le < _; le++) r[_][le + N * _] = Math.cos(T * (le + 0.5) * N); }; function d(_, T) { var N = _.length; T = T || 2, (!r || !r[N]) && n(N); var le = _.map(function() { return 0; }); return le.map(function(fe, Oe) { return T * _.reduce(function(pe, Ie, ve, Be) { return pe + Ie * r[N][ve + Oe * N]; }, 0); }); } return dct_1 = d, dct_1; } var dct, hasRequiredDct; function requireDct() { return hasRequiredDct || (hasRequiredDct = 1, dct = requireDct$1()), dct; } var utils, hasRequiredUtils; function requireUtils() { if (hasRequiredUtils) return utils; hasRequiredUtils = 1; function r(Ie) { if (Array.isArray(Ie)) { for (var ve = 0, Be = Array(Ie.length); ve < Ie.length; ve++) Be[ve] = Ie[ve]; return Be; } else return Array.from(Ie); } var n = {}, d = {}, _ = function(ve) { var Be = {}; Be.real = ve.real === void 0 ? ve.slice() : ve.real.slice(); var We = Be.real.length; return d[We] === void 0 && (d[We] = Array.apply(null, Array(We)).map(Number.prototype.valueOf, 0)), Be.imag = d[We].slice(), Be; }, T = function(ve) { if (n[ve] === void 0) { for (var Be = (ve - 1).toString(2).length, We = "0".repeat(Be), je = {}, Qe = 0; Qe < ve; Qe++) { var ut = Qe.toString(2); ut = We.substr(ut.length) + ut, ut = [].concat(r(ut)).reverse().join(""), je[Qe] = parseInt(ut, 2); } n[ve] = je; } return n[ve]; }, N = function(ve, Be) { return { real: ve.real * Be.real - ve.imag * Be.imag, imag: ve.real * Be.imag + ve.imag * Be.real }; }, le = function(ve, Be) { return { real: ve.real + Be.real, imag: ve.imag + Be.imag }; }, fe = function(ve, Be) { return { real: ve.real - Be.real, imag: ve.imag - Be.imag }; }, Oe = function(ve, Be) { var We = -2 * Math.PI * ve / Be; return { real: Math.cos(We), imag: Math.sin(We) }; }, pe = function(ve) { return ve.imag *= -1, ve; }; return utils = { bitReverseArray: T, multiply: N, add: le, subtract: fe, euler: Oe, conj: pe, constructComplexArray: _ }, utils; } var fft_1, hasRequiredFft; function requireFft() { if (hasRequiredFft) return fft_1; hasRequiredFft = 1; var r = requireUtils(), n = function(T) { var N = {}; T.real === void 0 || T.imag === void 0 ? N = r.constructComplexArray(T) : (N.real = T.real.slice(), N.imag = T.imag.slice()); var le = N.real.length, fe = Math.log2(le); if (Math.round(fe) != fe) throw new Error("Input size must be a power of 2."); if (N.real.length != N.imag.length) throw new Error("Real and imaginary components must have the same length."); for (var Oe = r.bitReverseArray(le), pe = { real: [], imag: [] }, Ie = 0; Ie < le; Ie++) pe.real[Oe[Ie]] = N.real[Ie], pe.imag[Oe[Ie]] = N.imag[Ie]; for (var ve = 0; ve < le; ve++) N.real[ve] = pe.real[ve], N.imag[ve] = pe.imag[ve]; for (var Be = 1; Be <= fe; Be++) for (var We = Math.pow(2, Be), je = 0; je < We / 2; je++) for (var Qe = r.euler(je, We), ut = 0; ut < le / We; ut++) { var vt = We * ut + je, Ne = We * ut + je + We / 2, Ze = { real: N.real[vt], imag: N.imag[vt] }, Ct = { real: N.real[Ne], imag: N.imag[Ne] }, yt = r.multiply(Qe, Ct), I = r.subtract(Ze, yt); N.real[Ne] = I.real, N.imag[Ne] = I.imag; var O = r.add(yt, Ze); N.real[vt] = O.real, N.imag[vt] = O.imag; } return N; }, d = function(T) { if (T.real === void 0 || T.imag === void 0) throw new Error("IFFT only accepts a complex input."); for (var N = T.real.length, le = { real: [], imag: [] }, fe = 0; fe < N; fe++) { var Oe = { real: T.real[fe], imag: T.imag[fe] }, pe = r.conj(Oe); le.real[fe] = pe.real, le.imag[fe] = pe.imag; } var Ie = n(le); return le.real = Ie.real.map(function(ve) { return ve / N; }), le.imag = Ie.imag.map(function(ve) { return ve / N; }), le; }; return fft_1 = { fft: n, ifft: d }, fft_1; } (function(r, n) { (function(d, _) { r.exports = _(requireDct(), requireFft()); })(commonjsGlobal, function(d, _) { function T(I, O, ee) { if (ee || arguments.length === 2) for (var M, oe = 0, xe = O.length; oe < xe; oe++) !M && oe in O || (M || (M = Array.prototype.slice.call(O, 0, oe)), M[oe] = O[oe]); return I.concat(M || Array.prototype.slice.call(O)); } var N = Object.freeze({ __proto__: null, blackman: function(I) { for (var O = new Float32Array(I), ee = 2 * Math.PI / (I - 1), M = 2 * ee, oe = 0; oe < I / 2; oe++) O[oe] = 0.42 - 0.5 * Math.cos(oe * ee) + 0.08 * Math.cos(oe * M); for (oe = Math.ceil(I / 2); oe > 0; oe--) O[I - oe] = O[oe - 1]; return O; }, hamming: function(I) { for (var O = new Float32Array(I), ee = 0; ee < I; ee++) O[ee] = 0.54 - 0.46 * Math.cos(2 * Math.PI * (ee / I - 1)); return O; }, hanning: function(I) { for (var O = new Float32Array(I), ee = 0; ee < I; ee++) O[ee] = 0.5 - 0.5 * Math.cos(2 * Math.PI * ee / (I - 1)); return O; }, sine: function(I) { for (var O = Math.PI / (I - 1), ee = new Float32Array(I), M = 0; M < I; M++) ee[M] = Math.sin(O * M); return ee; } }), le = {}; function fe(I) { for (; I % 2 == 0 && I > 1; ) I /= 2; return I === 1; } function Oe(I, O) { if (O !== "rect") { if (O !== "" && O || (O = "hanning"), le[O] || (le[O] = {}), !le[O][I.length]) try { le[O][I.length] = N[O](I.length); } catch { throw new Error("Invalid windowing function"); } I = function(ee, M) { for (var oe = [], xe = 0; xe < Math.min(ee.length, M.length); xe++) oe[xe] = ee[xe] * M[xe]; return oe; }(I, le[O][I.length]); } return I; } function pe(I, O, ee) { for (var M = new Float32Array(I), oe = 0; oe < M.length; oe++) M[oe] = oe * O / ee, M[oe] = 13 * Math.atan(M[oe] / 1315.8) + 3.5 * Math.atan(Math.pow(M[oe] / 7518, 2)); return M; } function Ie(I) { return Float32Array.from(I); } function ve(I) { return 1125 * Math.log(1 + I / 700); } function Be(I, O, ee) { for (var M, oe = new Float32Array(I + 2), xe = new Float32Array(I + 2), He = O / 2, qe = ve(0), Se = (ve(He) - qe) / (I + 1), Fe = new Array(I + 2), Ve = 0; Ve < oe.length; Ve++) oe[Ve] = Ve * Se, xe[Ve] = (M = oe[Ve], 700 * (Math.exp(M / 1125) - 1)), Fe[Ve] = Math.floor((ee + 1) * xe[Ve] / O); for (var _t = new Array(I), ze = 0; ze < _t.length; ze++) { for (_t[ze] = new Array(ee / 2 + 1).fill(0), Ve = Fe[ze]; Ve < Fe[ze + 1]; Ve++) _t[ze][Ve] = (Ve - Fe[ze]) / (Fe[ze + 1] - Fe[ze]); for (Ve = Fe[ze + 1]; Ve < Fe[ze + 2]; Ve++) _t[ze][Ve] = (Fe[ze + 2] - Ve) / (Fe[ze + 2] - Fe[ze + 1]); } return _t; } function We(I, O, ee, M, oe, xe, He) { M === void 0 && (M = 5), oe === void 0 && (oe = 2), xe === void 0 && (xe = !0), He === void 0 && (He = 440); var qe = Math.floor(ee / 2) + 1, Se = new Array(ee).fill(0).map(function(dt, xt) { return I * function(Lt, kt) { return Math.log2(16 * Lt / kt); }(O * xt / ee, He); }); Se[0] = Se[1] - 1.5 * I; var Fe, Ve, _t, ze = Se.slice(1).map(function(dt, xt) { return Math.max(dt - Se[xt]); }, 1).concat([1]), qt = Math.round(I / 2), Ft = new Array(I).fill(0).map(function(dt, xt) { return Se.map(function(Lt) { return (10 * I + qt + Lt - xt) % I - qt; }); }), Gt = Ft.map(function(dt, xt) { return dt.map(function(Lt, kt) { return Math.exp(-0.5 * Math.pow(2 * Ft[xt][kt] / ze[kt], 2)); }); }); if (Ve = (Fe = Gt)[0].map(function() { return 0; }), _t = Fe.reduce(function(dt, xt) { return xt.forEach(function(Lt, kt) { dt[kt] += Math.pow(Lt, 2); }), dt; }, Ve).map(Math.sqrt), Gt = Fe.map(function(dt, xt) { return dt.map(function(Lt, kt) { return Lt / (_t[kt] || 1); }); }), oe) { var yn = Se.map(function(dt) { return Math.exp(-0.5 * Math.pow((dt / I - M) / oe, 2)); }); Gt = Gt.map(function(dt) { return dt.map(function(xt, Lt) { return xt * yn[Lt]; }); }); } return xe && (Gt = T(T([], Gt.slice(3), !0), Gt.slice(0, 3), !0)), Gt.map(function(dt) { return dt.slice(0, qe); }); } function je(I, O) { for (var ee = 0, M = 0, oe = 0; oe < O.length; oe++) ee += Math.pow(oe, I) * Math.abs(O[oe]), M += O[oe]; return ee / M; } function Qe(I) { var O = I.ampSpectrum, ee = I.barkScale, M = I.numberOfBarkBands, oe = M === void 0 ? 24 : M; if (typeof O != "object" || typeof ee != "object") throw new TypeError(); var xe = oe, He = new Float32Array(xe), qe = 0, Se = O, Fe = new Int32Array(xe + 1); Fe[0] = 0; for (var Ve = ee[Se.length - 1] / xe, _t = 1, ze = 0; ze < Se.length; ze++) for (; ee[ze] > Ve; ) Fe[_t++] = ze, Ve = _t * ee[Se.length - 1] / xe; for (Fe[xe] = Se.length - 1, ze = 0; ze < xe; ze++) { for (var qt = 0, Ft = Fe[ze]; Ft < Fe[ze + 1]; Ft++) qt += Se[Ft]; He[ze] = Math.pow(qt, 0.23); } for (ze = 0; ze < He.length; ze++) qe += He[ze]; return { specific: He, total: qe }; } function ut(I) { var O = I.ampSpectrum; if (typeof O != "object") throw new TypeError(); for (var ee = new Float32Array(O.length), M = 0; M < ee.length; M++) ee[M] = Math.pow(O[M], 2); return ee; } function vt(I) { var O = I.ampSpectrum, ee = I.melFilterBank, M = I.bufferSize; if (typeof O != "object") throw new TypeError("Valid ampSpectrum is required to generate melBands"); if (typeof ee != "object") throw new TypeError("Valid melFilterBank is required to generate melBands"); for (var oe = ut({ ampSpectrum: O }), xe = ee.length, He = Array(xe), qe = new Float32Array(xe), Se = 0; Se < qe.length; Se++) { He[Se] = new Float32Array(M / 2), qe[Se] = 0; for (var Fe = 0; Fe < M / 2; Fe++) He[Se][Fe] = ee[Se][Fe] * oe[Fe], qe[Se] += He[Se][Fe]; qe[Se] = Math.log(qe[Se] + 1); } return Array.prototype.slice.call(qe); } var Ne = Object.freeze({ __proto__: null, amplitudeSpectrum: function(I) { return I.ampSpectrum; }, buffer: function(I) { return I.signal; }, chroma: function(I) { var O = I.ampSpectrum, ee = I.chromaFilterBank; if (typeof O != "object") throw new TypeError("Valid ampSpectrum is required to generate chroma"); if (typeof ee != "object") throw new TypeError("Valid chromaFilterBank is required to generate chroma"); var M = ee.map(function(xe, He) { return O.reduce(function(qe, Se, Fe) { return qe + Se * xe[Fe]; }, 0); }), oe = Math.max.apply(Math, M); return oe ? M.map(function(xe) { return xe / oe; }) : M; }, complexSpectrum: function(I) { return I.complexSpectrum; }, energy: function(I) { var O = I.signal; if (typeof O != "object") throw new TypeError(); for (var ee = 0, M = 0; M < O.length; M++) ee += Math.pow(Math.abs(O[M]), 2); return ee; }, loudness: Qe, melBands: vt, mfcc: function(I) { var O = I.ampSpectrum, ee = I.melFilterBank, M = I.numberOfMFCCCoefficients, oe = I.bufferSize, xe = Math.min(40, Math.max(1, M || 13)); if (ee.length < xe) throw new Error("Insufficient filter bank for requested number of coefficients"); var He = vt({ ampSpectrum: O, melFilterBank: ee, bufferSize: oe }); return d(He).slice(0, xe); }, perceptualSharpness: function(I) { for (var O = Qe({ ampSpectrum: I.ampSpectrum, barkScale: I.barkScale }), ee = O.specific, M = 0, oe = 0; oe < ee.length; oe++) M += oe < 15 ? (oe + 1) * ee[oe + 1] : 0.066 * Math.exp(0.171 * (oe + 1)); return M *= 0.11 / O.total; }, perceptualSpread: function(I) { for (var O = Qe({ ampSpectrum: I.ampSpectrum, barkScale: I.barkScale }), ee = 0, M = 0; M < O.specific.length; M++) O.specific[M] > ee && (ee = O.specific[M]); return Math.pow((O.total - ee) / O.total, 2); }, powerSpectrum: ut, rms: function(I) { var O = I.signal; if (typeof O != "object") throw new TypeError(); for (var ee = 0, M = 0; M < O.length; M++) ee += Math.pow(O[M], 2); return ee /= O.length, ee = Math.sqrt(ee); }, spectralCentroid: function(I) { var O = I.ampSpectrum; if (typeof O != "object") throw new TypeError(); return je(1, O); }, spectralCrest: function(I) { var O = I.ampSpectrum; if (typeof O != "object") throw new TypeError(); var ee = 0, M = -1 / 0; return O.forEach(function(oe) { ee += Math.pow(oe, 2), M = oe > M ? oe : M; }), ee /= O.length, ee = Math.sqrt(ee), M / ee; }, spectralFlatness: function(I) { var O = I.ampSpectrum; if (typeof O != "object") throw new TypeError(); for (var ee = 0, M = 0, oe = 0; oe < O.length; oe++) ee += Math.log(O[oe]), M += O[oe]; return Math.exp(ee / O.length) * O.length / M; }, spectralFlux: function(I) { var O = I.signal, ee = I.previousSignal, M = I.bufferSize; if (typeof O != "object" || typeof ee != "object") throw new TypeError(); for (var oe = 0, xe = -M / 2; xe < O.length / 2 - 1; xe++) x = Math.abs(O[xe]) - Math.abs(ee[xe]), oe += (x + Math.abs(x)) / 2; return oe; }, spectralKurtosis: function(I) { var O = I.ampSpectrum; if (typeof O != "object") throw new TypeError(); var ee = O, M = je(1, ee), oe = je(2, ee), xe = je(3, ee), He = je(4, ee); return (-3 * Math.pow(M, 4) + 6 * M * oe - 4 * M * xe + He) / Math.pow(Math.sqrt(oe - Math.pow(M, 2)), 4); }, spectralRolloff: function(I) { var O = I.ampSpectrum, ee = I.sampleRate; if (typeof O != "object") throw new TypeError(); for (var M = O, oe = ee / (2 * (M.length - 1)), xe = 0, He = 0; He < M.length; He++) xe += M[He]; for (var qe = 0.99 * xe, Se = M.length - 1; xe > qe && Se >= 0; ) xe -= M[Se], --Se; return (Se + 1) * oe; }, spectralSkewness: function(I) { var O = I.ampSpectrum; if (typeof O != "object") throw new TypeError(); var ee = je(1, O), M = je(2, O), oe = je(3, O); return (2 * Math.pow(ee, 3) - 3 * ee * M + oe) / Math.pow(Math.sqrt(M - Math.pow(ee, 2)), 3); }, spectralSlope: function(I) { var O = I.ampSpectrum, ee = I.sampleRate, M = I.bufferSize; if (typeof O != "object") throw new TypeError(); for (var oe = 0, xe = 0, He = new Float32Array(O.length), qe = 0, Se = 0, Fe = 0; Fe < O.length; Fe++) { oe += O[Fe]; var Ve = Fe * ee / M; He[Fe] = Ve, qe += Ve * Ve, xe += Ve, Se += Ve * O[Fe]; } return (O.length * Se - xe * oe) / (oe * (qe - Math.pow(xe, 2))); }, spectralSpread: function(I) { var O = I.ampSpectrum; if (typeof O != "object") throw new TypeError(); return Math.sqrt(je(2, O) - Math.pow(je(1, O), 2)); }, zcr: function(I) { var O = I.signal; if (typeof O != "object") throw new TypeError(); for (var ee = 0, M = 1; M < O.length; M++) (O[M - 1] >= 0 && O[M] < 0 || O[M - 1] < 0 && O[M] >= 0) && ee++; return ee; } }), Ze = function() { function I(O, ee) { var M = this; if (this._m = ee, !O.audioContext) throw this._m.errors.noAC; if (O.bufferSize && !fe(O.bufferSize)) throw this._m._errors.notPow2; if (!O.source) throw this._m._errors.noSource; this._m.audioContext = O.audioContext, this._m.bufferSize = O.bufferSize || this._m.bufferSize || 256, this._m.hopSize = O.hopSize || this._m.hopSize || this._m.bufferSize, this._m.sampleRate = O.sampleRate || this._m.audioContext.sampleRate || 44100, this._m.callback = O.callback, this._m.windowingFunction = O.windowingFunction || "hanning", this._m.featureExtractors = Ne, this._m.EXTRACTION_STARTED = O.startImmediately || !1, this._m.channel = typeof O.channel == "number" ? O.channel : 0, this._m.inputs = O.inputs || 1, this._m.outputs = O.outputs || 1, this._m.numberOfMFCCCoefficients = O.numberOfMFCCCoefficients || this._m.numberOfMFCCCoefficients || 13, this._m.numberOfBarkBands = O.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 = O.featureExtractors || [], this._m.barkScale = pe(this._m.bufferSize, this._m.sampleRate, this._m.bufferSize), this._m.melFilterBank = Be(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(O.source), this._m.spn.onaudioprocess = function(oe) { var xe; M._m.inputData !== null && (M._m.previousInputData = M._m.inputData), M._m.inputData = oe.inputBuffer.getChannelData(M._m.channel), M._m.previousInputData ? ((xe = new Float32Array(M._m.previousInputData.length + M._m.inputData.length - M._m.hopSize)).set(M._m.previousInputData.slice(M._m.hopSize)), xe.set(M._m.inputData, M._m.previousInputData.length - M._m.hopSize)) : xe = M._m.inputData; var He = function(qe, Se, Fe) { if (qe.length < Se) throw new Error("Buffer is too short for frame length"); if (Fe < 1) throw new Error("Hop length cannot be less that 1"); if (Se < 1) throw new Error("Frame length cannot be less that 1"); var Ve = 1 + Math.floor((qe.length - Se) / Fe); return new Array(Ve).fill(0).map(function(_t, ze) { return qe.slice(ze * Fe, ze * Fe + Se); }); }(xe, M._m.bufferSize, M._m.hopSize); He.forEach(function(qe) { M._m.frame = qe; var Se = M._m.extract(M._m._featuresToExtract, M._m.frame, M._m.previousFrame); typeof M._m.callback == "function" && M._m.EXTRACTION_STARTED && M._m.callback(Se), M._m.previousFrame = M._m.frame; }); }; } return I.prototype.start = function(O) { this._m._featuresToExtract = O || this._m._featuresToExtract, this._m.EXTRACTION_STARTED = !0; }, I.prototype.stop = function() { this._m.EXTRACTION_STARTED = !1; }, I.prototype.setSource = function(O) { this._m.source && this._m.source.disconnect(this._m.spn), this._m.source = O, this._m.source.connect(this._m.spn); }, I.prototype.setChannel = function(O) { O <= this._m.inputs ? this._m.channel = O : console.error("Channel ".concat(O, " does not exist. Make sure you've provided a value for 'inputs' that is greater than ").concat(O, " when instantiating the MeydaAnalyzer")); }, I.prototype.get = function(O) { return this._m.inputData ? this._m.extract(O || this._m._featuresToExtract, this._m.inputData, this._m.previousInputData) : null; }, I; }(), Ct = { audioContext: null, spn: null, bufferSize: 512, sampleRate: 44100, melBands: 26, chromaBands: 12, callback: null, windowingFunction: "hanning", featureExtractors: Ne, EXTRACTION_STARTED: !1, numberOfMFCCCoefficients: 13, numberOfBarkBands: 24, _featuresToExtract: [], windowing: Oe, _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(I) { return new Ze(I, Object.assign({}, Ct)); }, listAvailableFeatureExtractors: function() { return Object.keys(this.featureExtractors); }, extract: function(I, O, ee) { var M = this; if (!O) throw this._errors.invalidInput; if (typeof O != "object") throw this._errors.invalidInput; if (!I) throw this._errors.featureUndef; if (!fe(O.length)) throw this._errors.notPow2; this.barkScale !== void 0 && this.barkScale.length == this.bufferSize || (this.barkScale = pe(this.bufferSize, this.sampleRate, this.bufferSize)), this.melFilterBank !== void 0 && this.barkScale.length == this.bufferSize && this.melFilterBank.length == this.melBands || (this.melFilterBank = Be(Math.max(this.melBands, this.numberOfMFCCCoefficients), this.sampleRate, this.bufferSize)), this.chromaFilterBank !== void 0 && this.chromaFilterBank.length == this.chromaBands || (this.chromaFilterBank = We(this.chromaBands, this.sampleRate, this.bufferSize)), "buffer" in O && O.buffer === void 0 ? this.signal = Ie(O) : this.signal = O; var oe = yt(O, this.windowingFunction, this.bufferSize); if (this.signal = oe.windowedSignal, this.complexSpectrum = oe.complexSpectrum, this.ampSpectrum = oe.ampSpectrum, ee) { var xe = yt(ee, this.windowingFunction, this.bufferSize); this.previousSignal = xe.windowedSignal, this.previousComplexSpectrum = xe.complexSpectrum, this.previousAmpSpectrum = xe.ampSpectrum; } var He = function(qe) { return M.featureExtractors[qe]({ ampSpectrum: M.ampSpectrum, chromaFilterBank: M.chromaFilterBank, complexSpectrum: M.complexSpectrum, signal: M.signal, bufferSize: M.bufferSize, sampleRate: M.sampleRate, barkScale: M.barkScale, melFilterBank: M.melFilterBank, previousSignal: M.previousSignal, previousAmpSpectrum: M.previousAmpSpectrum, previousComplexSpectrum: M.previousComplexSpectrum, numberOfMFCCCoefficients: M.numberOfMFCCCoefficients, numberOfBarkBands: M.numberOfBarkBands }); }; if (typeof I == "object") return I.reduce(function(qe, Se) { var Fe; return Object.assign({}, qe, ((Fe = {})[Se] = He(Se), Fe)); }, {}); if (typeof I == "string") return He(I); throw this._errors.invalidFeatureFmt; } }, yt = function(I, O, ee) { var M = {}; I.buffer === void 0 ? M.signal = Ie(I) : M.signal = I, M.windowedSignal = Oe(M.signal, O), M.complexSpectrum = _.fft(M.windowedSignal), M.ampSpectrum = new Float32Array(ee / 2); for (var oe = 0; oe < ee / 2; oe++) M.ampSpectrum[oe] = Math.sqrt(Math.pow(M.complexSpectrum.real[oe], 2) + Math.pow(M.complexSpectrum.imag[oe], 2)); return M; }; return typeof window < "u" && (window.Meyda = Ct), Ct; }); })(meyda_min); var meyda_minExports = meyda_min.exports; const Meyda = /* @__PURE__ */ getDefaultExportFromCjs(meyda_minExports); class Audio { constructor({ numBins: n = 4, cutoff: d = 2, smooth: _ = 0.4, max: T = 15, scale: N = 10, isDrawing: le = !1, parentEl: fe = document.body }) { this.vol = 0, this.scale = N, this.max = T, this.cutoff = d, this.smooth = _, this.setBins(n), 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", fe.appendChild(this.canvas), this.isDrawing = le, 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((Oe) => { this.stream = Oe, this.context = new AudioContext(); let pe = this.context.createMediaStreamSource(Oe); this.meyda = Meyda.createMeydaAnalyzer({ audioContext: this.context, source: pe, featureExtractors: [ "loudness" // 'perceptualSpread', // 'perceptualSharpness', // 'spectralCentroid' ] }); }).catch((Oe) => console.log("ERROR", Oe)); } detectBeat(n) { n > this.beat._cutoff && n > this.beat.threshold ? (this.onBeat(), this.beat._cutoff = n * 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 n = this.meyda.get(); if (n && n !== null) { this.vol = n.loudness.total, this.detectBeat(this.vol); const d = (T, N) => T + N; let _ = Math.floor(n.loudness.specific.length / this.bins.length); this.prevBins = this.bins.slice(0), this.bins = this.bins.map((T, N) => n.loudness.specific.slice(N * _, (N + 1) * _).reduce(d)).map((T, N) => T * (1 - this.settings[N].smooth) + this.prevBins[N] * this.settings[N].smooth), this.fft = this.bins.map((T, N) => ( // Math.max(0, (bin - this.cutoff) / (this.max - this.cutoff)) Math.max(0, (T - this.settings[N].cutoff) / this.settings[N].scale) )), this.isDrawing && this.draw(); } } } setCutoff(n) { this.cutoff = n, this.settings = this.settings.map((d) => (d.cutoff = n, d)); } setSmooth(n) { this.smooth = n, this.settings = this.settings.map((d) => (d.smooth = n, d)); } setBins(n) { this.bins = Array(n).fill(0), this.prevBins = Array(n).fill(0), this.fft = Array(n).fill(0), this.settings = Array(n).fill(0).map(() => ({ cutoff: this.cutoff, scale: this.scale, smooth: this.smooth })), this.bins.forEach((d, _) => { window["a" + _] = (T = 1, N = 0) => () => a.fft[_] * T + N; }); } setScale(n) { this.scale = n, this.settings = this.settings.map((d) => (d.scale = n, d)); } setMax(n) { this.max = n, 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 n = this.canvas.width / this.bins.length, d = this.canvas.height / (this.max * 2); this.bins.forEach((_, T) => { var N = _ * d; this.ctx.fillRect(T * n, this.canvas.height - N, n, N); var le = this.canvas.height - d * this.settings[T].cutoff; this.ctx.beginPath(), this.ctx.moveTo(T * n, le), this.ctx.lineTo((T + 1) * n, le), this.ctx.stroke(); var fe = this.canvas.height - d * (this.settings[T].scale + this.settings[T].cutoff); this.ctx.beginPath(), this.ctx.moveTo(T * n, fe), this.ctx.lineTo((T + 1) * n, fe), this.ctx.stroke(); }); } } class VideoRecorder { constructor(n) { this.mediaSource = new MediaSource(), this.stream = n, 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 n = { mimeType: "video/webm;codecs=vp9" }; this.recordedBlobs = []; try { this.mediaRecorder = new MediaRecorder(this.stream, n); } catch (d) { console.log("Unable to create MediaRecorder with options Object: ", d); try { n = { mimeType: "video/webm,codecs=vp9" }, this.mediaRecorder = new MediaRecorder(this.stream, n); } catch (_) { console.log("Unable to create MediaRecorder with options Object: ", _); try { n = "video/vp8", this.mediaRecorder = new MediaRecorder(this.stream, n); } catch (T) { 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:", T); return; } } } console.log("Created MediaRecorder", this.mediaRecorder, "with options", n), 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 n = new Blob(this.recordedBlobs, { type: this.mediaRecorder.mimeType }), d = window.URL.createObjectURL(n); this.output.src = d; const _ = document.createElement("a"); _.style.display = "none", _.href = d; let T = /* @__PURE__ */ new Date(); _.download = `hydra-${T.getFullYear()}-${T.getMonth() + 1}-${T.getDate()}-${T.getHours()}.${T.getMinutes()}.${T.getSeconds()}.webm`, document.body.appendChild(_), _.click(), setTimeout(() => { document.body.removeChild(_), window.URL.revokeObjectURL(d); }, 300); } _handleDataAvailable(n) { n.data && n.data.size > 0 && this.recordedBlobs.push(n.data); } } const easing = { // no easing, no acceleration linear: function(r) { return r; }, // accelerating from zero velocity easeInQuad: function(r) { return r * r; }, // decelerating to zero velocity easeOutQuad: function(r) { return r * (2 - r); }, // acceleration until halfway, then deceleration easeInOutQuad: function(r) { return r < 0.5 ? 2 * r * r : -1 + (4 - 2 * r) * r; }, // accelerating from zero velocity easeInCubic: function(r) { return r * r * r; }, // decelerating to zero velocity easeOutCubic: function(r) { return --r * r * r + 1; }, // acceleration until halfway, then deceleration easeInOutCubic: function(r) { return r < 0.5 ? 4 * r * r * r : (r - 1) * (2 * r - 2) * (2 * r - 2) + 1; }, // accelerating from zero velocity easeInQuart: function(r) { return r * r * r * r; }, // decelerating to zero velocity easeOutQuart: function(r) { return 1 - --r * r * r * r; }, // acceleration until halfway, then deceleration easeInOutQuart: function(r)