UNPKG

song-viz

Version:
719 lines (715 loc) 24.5 kB
import Ue, { useState as ie, useRef as Re, useEffect as ue } from "react"; const pr = (_) => { for (var p = 0, C = 0; C < _.length; C++) p += Math.pow(_[C], 2); return p = p / _.length, p = Math.sqrt(p), p; }, _e = (_, p, C) => { function w(P, x, u) { let l; arguments.length < 3 && (u = 0.5); for (var m = P.slice(), f = 0; f < 3; f++) m[f] = Math.round(m[f] + u * (x[f] - P[f])), l = `rgb(${m[0]}, ${m[1]}, ${m[2]})`; return l; } return ((P, x, u) => { var l = 1 / (u - 1), m = []; const f = P.match(/\d+/g).map(Number), E = x.match(/\d+/g).map(Number); for (var T = 0; T < u; T++) m.push( w( f, E, l * T ) ); return m; })(_, p, C); }; var Ve = { exports: {} }, G = {}; /** * @license React * react-jsx-runtime.production.min.js * * Copyright (c) Facebook, Inc. and its affiliates. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. */ var Ye; function gr() { if (Ye) return G; Ye = 1; var _ = Ue, p = Symbol.for("react.element"), C = Symbol.for("react.fragment"), w = Object.prototype.hasOwnProperty, D = _.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner, P = { key: !0, ref: !0, __self: !0, __source: !0 }; function x(u, l, m) { var f, E = {}, T = null, $ = null; m !== void 0 && (T = "" + m), l.key !== void 0 && (T = "" + l.key), l.ref !== void 0 && ($ = l.ref); for (f in l) w.call(l, f) && !P.hasOwnProperty(f) && (E[f] = l[f]); if (u && u.defaultProps) for (f in l = u.defaultProps, l) E[f] === void 0 && (E[f] = l[f]); return { $$typeof: p, type: u, key: T, ref: $, props: E, _owner: D.current }; } return G.Fragment = C, G.jsx = x, G.jsxs = x, G; } var J = {}; /** * @license React * react-jsx-runtime.development.js * * Copyright (c) Facebook, Inc. and its affiliates. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. */ var Ne; function mr() { return Ne || (Ne = 1, process.env.NODE_ENV !== "production" && function() { var _ = Ue, p = Symbol.for("react.element"), C = Symbol.for("react.portal"), w = Symbol.for("react.fragment"), D = Symbol.for("react.strict_mode"), P = Symbol.for("react.profiler"), x = Symbol.for("react.provider"), u = Symbol.for("react.context"), l = Symbol.for("react.forward_ref"), m = Symbol.for("react.suspense"), f = Symbol.for("react.suspense_list"), E = Symbol.for("react.memo"), T = Symbol.for("react.lazy"), $ = Symbol.for("react.offscreen"), K = Symbol.iterator, se = "@@iterator"; function W(e) { if (e === null || typeof e != "object") return null; var r = K && e[K] || e[se]; return typeof r == "function" ? r : null; } var F = _.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED; function d(e) { { for (var r = arguments.length, t = new Array(r > 1 ? r - 1 : 0), n = 1; n < r; n++) t[n - 1] = arguments[n]; ce("error", e, t); } } function ce(e, r, t) { { var n = F.ReactDebugCurrentFrame, i = n.getStackAddendum(); i !== "" && (r += "%s", t = t.concat([i])); var c = t.map(function(o) { return String(o); }); c.unshift("Warning: " + r), Function.prototype.apply.call(console[e], console, c); } } var V = !1, le = !1, s = !1, fe = !1, g = !1, k; k = Symbol.for("react.module.reference"); function I(e) { return !!(typeof e == "string" || typeof e == "function" || e === w || e === P || g || e === D || e === m || e === f || fe || e === $ || V || le || s || typeof e == "object" && e !== null && (e.$$typeof === T || e.$$typeof === E || e.$$typeof === x || e.$$typeof === u || e.$$typeof === l || e.$$typeof === k || e.getModuleId !== void 0)); } function q(e, r, t) { var n = e.displayName; if (n) return n; var i = r.displayName || r.name || ""; return i !== "" ? t + "(" + i + ")" : t; } function B(e) { return e.displayName || "Context"; } function j(e) { if (e == null) return null; if (typeof e.tag == "number" && d("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."), typeof e == "function") return e.displayName || e.name || null; if (typeof e == "string") return e; switch (e) { case w: return "Fragment"; case C: return "Portal"; case P: return "Profiler"; case D: return "StrictMode"; case m: return "Suspense"; case f: return "SuspenseList"; } if (typeof e == "object") switch (e.$$typeof) { case u: var r = e; return B(r) + ".Consumer"; case x: var t = e; return B(t._context) + ".Provider"; case l: return q(e, e.render, "ForwardRef"); case E: var n = e.displayName || null; return n !== null ? n : j(e.type) || "Memo"; case T: { var i = e, c = i._payload, o = i._init; try { return j(o(c)); } catch { return null; } } } return null; } var y = Object.assign, O = 0, Y, X, Z, Q, ee, N, Te; function we() { } we.__reactDisabledLog = !0; function qe() { { if (O === 0) { Y = console.log, X = console.info, Z = console.warn, Q = console.error, ee = console.group, N = console.groupCollapsed, Te = console.groupEnd; var e = { configurable: !0, enumerable: !0, value: we, writable: !0 }; Object.defineProperties(console, { info: e, log: e, warn: e, error: e, group: e, groupCollapsed: e, groupEnd: e }); } O++; } } function Be() { { if (O--, O === 0) { var e = { configurable: !0, enumerable: !0, writable: !0 }; Object.defineProperties(console, { log: y({}, e, { value: Y }), info: y({}, e, { value: X }), warn: y({}, e, { value: Z }), error: y({}, e, { value: Q }), group: y({}, e, { value: ee }), groupCollapsed: y({}, e, { value: N }), groupEnd: y({}, e, { value: Te }) }); } O < 0 && d("disabledDepth fell below zero. This is a bug in React. Please file an issue."); } } var de = F.ReactCurrentDispatcher, ve; function re(e, r, t) { { if (ve === void 0) try { throw Error(); } catch (i) { var n = i.stack.trim().match(/\n( *(at )?)/); ve = n && n[1] || ""; } return ` ` + ve + e; } } var he = !1, te; { var ze = typeof WeakMap == "function" ? WeakMap : Map; te = new ze(); } function Oe(e, r) { if (!e || he) return ""; { var t = te.get(e); if (t !== void 0) return t; } var n; he = !0; var i = Error.prepareStackTrace; Error.prepareStackTrace = void 0; var c; c = de.current, de.current = null, qe(); try { if (r) { var o = function() { throw Error(); }; if (Object.defineProperty(o.prototype, "props", { set: function() { throw Error(); } }), typeof Reflect == "object" && Reflect.construct) { try { Reflect.construct(o, []); } catch (A) { n = A; } Reflect.construct(e, [], o); } else { try { o.call(); } catch (A) { n = A; } e.call(o.prototype); } } else { try { throw Error(); } catch (A) { n = A; } e(); } } catch (A) { if (A && n && typeof A.stack == "string") { for (var a = A.stack.split(` `), R = n.stack.split(` `), v = a.length - 1, h = R.length - 1; v >= 1 && h >= 0 && a[v] !== R[h]; ) h--; for (; v >= 1 && h >= 0; v--, h--) if (a[v] !== R[h]) { if (v !== 1 || h !== 1) do if (v--, h--, h < 0 || a[v] !== R[h]) { var S = ` ` + a[v].replace(" at new ", " at "); return e.displayName && S.includes("<anonymous>") && (S = S.replace("<anonymous>", e.displayName)), typeof e == "function" && te.set(e, S), S; } while (v >= 1 && h >= 0); break; } } } finally { he = !1, de.current = c, Be(), Error.prepareStackTrace = i; } var U = e ? e.displayName || e.name : "", We = U ? re(U) : ""; return typeof e == "function" && te.set(e, We), We; } function Ge(e, r, t) { return Oe(e, !1); } function Je(e) { var r = e.prototype; return !!(r && r.isReactComponent); } function ne(e, r, t) { if (e == null) return ""; if (typeof e == "function") return Oe(e, Je(e)); if (typeof e == "string") return re(e); switch (e) { case m: return re("Suspense"); case f: return re("SuspenseList"); } if (typeof e == "object") switch (e.$$typeof) { case l: return Ge(e.render); case E: return ne(e.type, r, t); case T: { var n = e, i = n._payload, c = n._init; try { return ne(c(i), r, t); } catch { } } } return ""; } var ae = Object.prototype.hasOwnProperty, Se = {}, Ce = F.ReactDebugCurrentFrame; function oe(e) { if (e) { var r = e._owner, t = ne(e.type, e._source, r ? r.type : null); Ce.setExtraStackFrame(t); } else Ce.setExtraStackFrame(null); } function He(e, r, t, n, i) { { var c = Function.call.bind(ae); for (var o in e) if (c(e, o)) { var a = void 0; try { if (typeof e[o] != "function") { var R = Error((n || "React class") + ": " + t + " type `" + o + "` is invalid; it must be a function, usually from the `prop-types` package, but received `" + typeof e[o] + "`.This often happens because of typos such as `PropTypes.function` instead of `PropTypes.func`."); throw R.name = "Invariant Violation", R; } a = e[o](r, o, n, t, null, "SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED"); } catch (v) { a = v; } a && !(a instanceof Error) && (oe(i), d("%s: type specification of %s `%s` is invalid; the type checker function must return `null` or an `Error` but returned a %s. You may have forgotten to pass an argument to the type checker creator (arrayOf, instanceOf, objectOf, oneOf, oneOfType, and shape all require an argument).", n || "React class", t, o, typeof a), oe(null)), a instanceof Error && !(a.message in Se) && (Se[a.message] = !0, oe(i), d("Failed %s type: %s", t, a.message), oe(null)); } } } var Ke = Array.isArray; function pe(e) { return Ke(e); } function Xe(e) { { var r = typeof Symbol == "function" && Symbol.toStringTag, t = r && e[Symbol.toStringTag] || e.constructor.name || "Object"; return t; } } function Ze(e) { try { return Pe(e), !1; } catch { return !0; } } function Pe(e) { return "" + e; } function xe(e) { if (Ze(e)) return d("The provided key is an unsupported type %s. This value must be coerced to a string before before using it here.", Xe(e)), Pe(e); } var z = F.ReactCurrentOwner, Qe = { key: !0, ref: !0, __self: !0, __source: !0 }, je, ke, ge; ge = {}; function er(e) { if (ae.call(e, "ref")) { var r = Object.getOwnPropertyDescriptor(e, "ref").get; if (r && r.isReactWarning) return !1; } return e.ref !== void 0; } function rr(e) { if (ae.call(e, "key")) { var r = Object.getOwnPropertyDescriptor(e, "key").get; if (r && r.isReactWarning) return !1; } return e.key !== void 0; } function tr(e, r) { if (typeof e.ref == "string" && z.current && r && z.current.stateNode !== r) { var t = j(z.current.type); ge[t] || (d('Component "%s" contains the string ref "%s". Support for string refs will be removed in a future major release. This case cannot be automatically converted to an arrow function. We ask you to manually fix this case by using useRef() or createRef() instead. Learn more about using refs safely here: https://reactjs.org/link/strict-mode-string-ref', j(z.current.type), e.ref), ge[t] = !0); } } function nr(e, r) { { var t = function() { je || (je = !0, d("%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://reactjs.org/link/special-props)", r)); }; t.isReactWarning = !0, Object.defineProperty(e, "key", { get: t, configurable: !0 }); } } function ar(e, r) { { var t = function() { ke || (ke = !0, d("%s: `ref` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://reactjs.org/link/special-props)", r)); }; t.isReactWarning = !0, Object.defineProperty(e, "ref", { get: t, configurable: !0 }); } } var or = function(e, r, t, n, i, c, o) { var a = { $$typeof: p, type: e, key: r, ref: t, props: o, _owner: c }; return a._store = {}, Object.defineProperty(a._store, "validated", { configurable: !1, enumerable: !1, writable: !0, value: !1 }), Object.defineProperty(a, "_self", { configurable: !1, enumerable: !1, writable: !1, value: n }), Object.defineProperty(a, "_source", { configurable: !1, enumerable: !1, writable: !1, value: i }), Object.freeze && (Object.freeze(a.props), Object.freeze(a)), a; }; function ir(e, r, t, n, i) { { var c, o = {}, a = null, R = null; t !== void 0 && (xe(t), a = "" + t), rr(r) && (xe(r.key), a = "" + r.key), er(r) && (R = r.ref, tr(r, i)); for (c in r) ae.call(r, c) && !Qe.hasOwnProperty(c) && (o[c] = r[c]); if (e && e.defaultProps) { var v = e.defaultProps; for (c in v) o[c] === void 0 && (o[c] = v[c]); } if (a || R) { var h = typeof e == "function" ? e.displayName || e.name || "Unknown" : e; a && nr(o, h), R && ar(o, h); } return or(e, a, R, i, n, z.current, o); } } var me = F.ReactCurrentOwner, Ae = F.ReactDebugCurrentFrame; function L(e) { if (e) { var r = e._owner, t = ne(e.type, e._source, r ? r.type : null); Ae.setExtraStackFrame(t); } else Ae.setExtraStackFrame(null); } var ye; ye = !1; function Ee(e) { return typeof e == "object" && e !== null && e.$$typeof === p; } function De() { { if (me.current) { var e = j(me.current.type); if (e) return ` Check the render method of \`` + e + "`."; } return ""; } } function ur(e) { { if (e !== void 0) { var r = e.fileName.replace(/^.*[\\\/]/, ""), t = e.lineNumber; return ` Check your code at ` + r + ":" + t + "."; } return ""; } } var Fe = {}; function sr(e) { { var r = De(); if (!r) { var t = typeof e == "string" ? e : e.displayName || e.name; t && (r = ` Check the top-level render call using <` + t + ">."); } return r; } } function Ie(e, r) { { if (!e._store || e._store.validated || e.key != null) return; e._store.validated = !0; var t = sr(r); if (Fe[t]) return; Fe[t] = !0; var n = ""; e && e._owner && e._owner !== me.current && (n = " It was passed a child from " + j(e._owner.type) + "."), L(e), d('Each child in a list should have a unique "key" prop.%s%s See https://reactjs.org/link/warning-keys for more information.', t, n), L(null); } } function Me(e, r) { { if (typeof e != "object") return; if (pe(e)) for (var t = 0; t < e.length; t++) { var n = e[t]; Ee(n) && Ie(n, r); } else if (Ee(e)) e._store && (e._store.validated = !0); else if (e) { var i = W(e); if (typeof i == "function" && i !== e.entries) for (var c = i.call(e), o; !(o = c.next()).done; ) Ee(o.value) && Ie(o.value, r); } } } function cr(e) { { var r = e.type; if (r == null || typeof r == "string") return; var t; if (typeof r == "function") t = r.propTypes; else if (typeof r == "object" && (r.$$typeof === l || r.$$typeof === E)) t = r.propTypes; else return; if (t) { var n = j(r); He(t, e.props, "prop", n, e); } else if (r.PropTypes !== void 0 && !ye) { ye = !0; var i = j(r); d("Component %s declared `PropTypes` instead of `propTypes`. Did you misspell the property assignment?", i || "Unknown"); } typeof r.getDefaultProps == "function" && !r.getDefaultProps.isReactClassApproved && d("getDefaultProps is only used on classic React.createClass definitions. Use a static property named `defaultProps` instead."); } } function lr(e) { { for (var r = Object.keys(e.props), t = 0; t < r.length; t++) { var n = r[t]; if (n !== "children" && n !== "key") { L(e), d("Invalid prop `%s` supplied to `React.Fragment`. React.Fragment can only have `key` and `children` props.", n), L(null); break; } } e.ref !== null && (L(e), d("Invalid attribute `ref` supplied to `React.Fragment`."), L(null)); } } function $e(e, r, t, n, i, c) { { var o = I(e); if (!o) { var a = ""; (e === void 0 || typeof e == "object" && e !== null && Object.keys(e).length === 0) && (a += " You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports."); var R = ur(i); R ? a += R : a += De(); var v; e === null ? v = "null" : pe(e) ? v = "array" : e !== void 0 && e.$$typeof === p ? (v = "<" + (j(e.type) || "Unknown") + " />", a = " Did you accidentally export a JSX literal instead of a component?") : v = typeof e, d("React.jsx: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: %s.%s", v, a); } var h = ir(e, r, t, i, c); if (h == null) return h; if (o) { var S = r.children; if (S !== void 0) if (n) if (pe(S)) { for (var U = 0; U < S.length; U++) Me(S[U], e); Object.freeze && Object.freeze(S); } else d("React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead."); else Me(S, e); } return e === w ? lr(h) : cr(h), h; } } function fr(e, r, t) { return $e(e, r, t, !0); } function dr(e, r, t) { return $e(e, r, t, !1); } var vr = dr, hr = fr; J.Fragment = w, J.jsx = vr, J.jsxs = hr; }()), J; } (function(_) { process.env.NODE_ENV === "production" ? _.exports = gr() : _.exports = mr(); })(Ve); const Le = Ve.exports.jsx; var H, b, M, be; const yr = ({ audioRef: _, centerImageSrc: p, rotation: C = !0, bounceMultiplier: w = 1, bars: D = 200, barWidth: P = 4, barHeightMultiplier: x = 1, barColor: u, circleProps: l = { circleWidth: 4, circleColor: "black" }, centerColor: m = "white", canvasBackground: f = "white", baseRadiusValue: E = 150, fftSizeValue: T = 512, smoothingTimeConstant: $ = 0.8, canvasWidth: K = 1200, canvasHeight: se = 1e3 }) => { const [W, F] = ie(), [d, ce] = ie(), [V, le] = ie(), [s, fe] = ie(), g = Re(null), k = Re(), I = Re(); ue(() => { g.current.width = K, g.current.height = se, fe(g.current.getContext("2d")), F(_.current), ce(new AudioContext()); }, []), ue(() => { V && (V.connect(k.current), k.current.connect(d.destination), B()); }, [V]), ue(() => { d && (le(d.createMediaElementSource(W)), k.current = d.createAnalyser(), k.current.fftSize = T, k.current.smoothingTimeConstant = $, I.current = new Uint8Array(k.current.frequencyBinCount)), W && d && W.addEventListener("play", () => { d.resume(); }); }, [d]); const q = new Image(); p && (q.src = p), ue(() => { u ? Object.keys(u).length === 2 ? u.colorOne && u.colorTwo && (H = _e(u.colorOne, u.colorTwo, 256)) : Object.keys(u).length === 1 && (u.hslColor ? M = u.hslColor : u.colorOne ? H = _e(u.colorOne, u.colorOne, 256) : u.colorTwo ? H = _e(u.colorTwo, u.colorTwo, 256) : M = [2, 100, 50]) : M = [2, 100, 50]; }, [u]); const B = () => { if (requestAnimationFrame(B), k.current.getByteFrequencyData(I.current), s.fillStyle = f, s.fillRect(0, 0, g.current.width, g.current.height), w) { const O = pr(I.current); be = Math.max(E, E + O * w); } else w || (be = E); b = be; const j = () => { s && (s.save(), s.beginPath(), s.arc(g.current.width / 2, g.current.height / 2, b, 0, 2 * Math.PI), l === void 0 ? (s.strokeStyle = "white", s.lineWidth = 1) : l && (s.lineWidth = l.circleWidth, s.strokeStyle = l.circleColor), s.stroke(), s.clip(), p === void 0 && (s.fillStyle = m, s.fill(), s.stroke()), p && (C ? (s.setTransform(1, 0, 0, 1, g.current.width / 2, g.current.height / 2), s.rotate(W.currentTime / 1), s.drawImage(q, -b, -b, b * 2, b * 2), s.setTransform(1, 0, 0, 1, 0, 0)) : s.drawImage( q, g.current.width / 2 - b, g.current.height / 2 - b, b * 2, b * 2 )), s.restore()); }; for (var y = 0; y < D; y++) { const O = Math.PI * 2 / D, Y = I.current[y] * x, X = g.current.width / 2 + Math.cos(O * y) * b, Z = g.current.height / 2 + Math.sin(O * y) * b, Q = g.current.width / 2 + Math.cos(O * y) * (b + Y), ee = g.current.height / 2 + Math.sin(O * y) * (b + Y); let N; H && (N = H[I.current[y]]), M && (N = `hsl(${M[0] * y}, ${M[1]}%, ${M[2]}%)`), s && (s.strokeStyle = N, s.lineWidth = P, s.beginPath(), s.moveTo(X, Z), s.lineTo(Q, ee), s.stroke()); } j(); }; return /* @__PURE__ */ Le("div", { children: /* @__PURE__ */ Le("canvas", { ref: g }) }); }, Rr = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({ __proto__: null, MeloDisc: yr }, Symbol.toStringTag, { value: "Module" })); export { Rr as MeloDisc };