UNPKG

song-viz

Version:
28 lines (24 loc) 17 kB
(function(I,_){typeof exports=="object"&&typeof module<"u"?_(exports,require("react")):typeof define=="function"&&define.amd?define(["exports","react"],_):(I=typeof globalThis<"u"?globalThis:I||self,_(I["song-viz"]={},I.require$$0))})(this,function(I,_){"use strict";const be=(h=>h&&typeof h=="object"&&"default"in h?h:{default:h})(_),Be=h=>{for(var g=0,P=0;P<h.length;P++)g+=Math.pow(h[P],2);return g=g/h.length,g=Math.sqrt(g),g},se=(h,g,P)=>{function S(x,j,u){let f;arguments.length<3&&(u=.5);for(var m=x.slice(),l=0;l<3;l++)m[l]=Math.round(m[l]+u*(j[l]-x[l])),f=`rgb(${m[0]}, ${m[1]}, ${m[2]})`;return f}return((x,j,u)=>{var f=1/(u-1),m=[];const l=x.match(/\d+/g).map(Number),R=j.match(/\d+/g).map(Number);for(var w=0;w<u;w++)m.push(S(l,R,f*w));return m})(h,g,P)};var Te={exports:{}},z={};/** * @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 we;function $e(){if(we)return z;we=1;var h=be.default,g=Symbol.for("react.element"),P=Symbol.for("react.fragment"),S=Object.prototype.hasOwnProperty,F=h.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,x={key:!0,ref:!0,__self:!0,__source:!0};function j(u,f,m){var l,R={},w=null,N=null;m!==void 0&&(w=""+m),f.key!==void 0&&(w=""+f.key),f.ref!==void 0&&(N=f.ref);for(l in f)S.call(f,l)&&!x.hasOwnProperty(l)&&(R[l]=f[l]);if(u&&u.defaultProps)for(l in f=u.defaultProps,f)R[l]===void 0&&(R[l]=f[l]);return{$$typeof:g,type:u,key:w,ref:N,props:R,_owner:F.current}}return z.Fragment=P,z.jsx=j,z.jsxs=j,z}var G={};/** * @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 Se;function ze(){return Se||(Se=1,process.env.NODE_ENV!=="production"&&function(){var h=be.default,g=Symbol.for("react.element"),P=Symbol.for("react.portal"),S=Symbol.for("react.fragment"),F=Symbol.for("react.strict_mode"),x=Symbol.for("react.profiler"),j=Symbol.for("react.provider"),u=Symbol.for("react.context"),f=Symbol.for("react.forward_ref"),m=Symbol.for("react.suspense"),l=Symbol.for("react.suspense_list"),R=Symbol.for("react.memo"),w=Symbol.for("react.lazy"),N=Symbol.for("react.offscreen"),Z=Symbol.iterator,fe="@@iterator";function L(e){if(e===null||typeof e!="object")return null;var r=Z&&e[Z]||e[fe];return typeof r=="function"?r:null}var M=h.__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];le("error",e,t)}}function le(e,r,t){{var n=M.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 H=!1,de=!1,s=!1,ve=!1,y=!1,A;A=Symbol.for("react.module.reference");function Y(e){return!!(typeof e=="string"||typeof e=="function"||e===S||e===x||y||e===F||e===m||e===l||ve||e===N||H||de||s||typeof e=="object"&&e!==null&&(e.$$typeof===w||e.$$typeof===R||e.$$typeof===j||e.$$typeof===u||e.$$typeof===f||e.$$typeof===A||e.getModuleId!==void 0))}function K(e,r,t){var n=e.displayName;if(n)return n;var i=r.displayName||r.name||"";return i!==""?t+"("+i+")":t}function q(e){return e.displayName||"Context"}function k(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 S:return"Fragment";case P:return"Portal";case x:return"Profiler";case F:return"StrictMode";case m:return"Suspense";case l:return"SuspenseList"}if(typeof e=="object")switch(e.$$typeof){case u:var r=e;return q(r)+".Consumer";case j:var t=e;return q(t._context)+".Provider";case f:return K(e,e.render,"ForwardRef");case R:var n=e.displayName||null;return n!==null?n:k(e.type)||"Memo";case w:{var i=e,c=i._payload,o=i._init;try{return k(o(c))}catch{return null}}}return null}var E=Object.assign,O=0,U,Q,ee,re,te,V,Ce;function Pe(){}Pe.__reactDisabledLog=!0;function Je(){{if(O===0){U=console.log,Q=console.info,ee=console.warn,re=console.error,te=console.group,V=console.groupCollapsed,Ce=console.groupEnd;var e={configurable:!0,enumerable:!0,value:Pe,writable:!0};Object.defineProperties(console,{info:e,log:e,warn:e,error:e,group:e,groupCollapsed:e,groupEnd:e})}O++}}function He(){{if(O--,O===0){var e={configurable:!0,enumerable:!0,writable:!0};Object.defineProperties(console,{log:E({},e,{value:U}),info:E({},e,{value:Q}),warn:E({},e,{value:ee}),error:E({},e,{value:re}),group:E({},e,{value:te}),groupCollapsed:E({},e,{value:V}),groupEnd:E({},e,{value:Ce})})}O<0&&d("disabledDepth fell below zero. This is a bug in React. Please file an issue.")}}var he=M.ReactCurrentDispatcher,pe;function ne(e,r,t){{if(pe===void 0)try{throw Error()}catch(i){var n=i.stack.trim().match(/\n( *(at )?)/);pe=n&&n[1]||""}return` `+pe+e}}var ge=!1,ae;{var Ke=typeof WeakMap=="function"?WeakMap:Map;ae=new Ke}function xe(e,r){if(!e||ge)return"";{var t=ae.get(e);if(t!==void 0)return t}var n;ge=!0;var i=Error.prepareStackTrace;Error.prepareStackTrace=void 0;var c;c=he.current,he.current=null,Je();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(D){n=D}Reflect.construct(e,[],o)}else{try{o.call()}catch(D){n=D}e.call(o.prototype)}}else{try{throw Error()}catch(D){n=D}e()}}catch(D){if(D&&n&&typeof D.stack=="string"){for(var a=D.stack.split(` `),b=n.stack.split(` `),v=a.length-1,p=b.length-1;v>=1&&p>=0&&a[v]!==b[p];)p--;for(;v>=1&&p>=0;v--,p--)if(a[v]!==b[p]){if(v!==1||p!==1)do if(v--,p--,p<0||a[v]!==b[p]){var C=` `+a[v].replace(" at new "," at ");return e.displayName&&C.includes("<anonymous>")&&(C=C.replace("<anonymous>",e.displayName)),typeof e=="function"&&ae.set(e,C),C}while(v>=1&&p>=0);break}}}finally{ge=!1,he.current=c,He(),Error.prepareStackTrace=i}var $=e?e.displayName||e.name:"",Ve=$?ne($):"";return typeof e=="function"&&ae.set(e,Ve),Ve}function qe(e,r,t){return xe(e,!1)}function Xe(e){var r=e.prototype;return!!(r&&r.isReactComponent)}function oe(e,r,t){if(e==null)return"";if(typeof e=="function")return xe(e,Xe(e));if(typeof e=="string")return ne(e);switch(e){case m:return ne("Suspense");case l:return ne("SuspenseList")}if(typeof e=="object")switch(e.$$typeof){case f:return qe(e.render);case R:return oe(e.type,r,t);case w:{var n=e,i=n._payload,c=n._init;try{return oe(c(i),r,t)}catch{}}}return""}var ie=Object.prototype.hasOwnProperty,je={},ke=M.ReactDebugCurrentFrame;function ue(e){if(e){var r=e._owner,t=oe(e.type,e._source,r?r.type:null);ke.setExtraStackFrame(t)}else ke.setExtraStackFrame(null)}function Ze(e,r,t,n,i){{var c=Function.call.bind(ie);for(var o in e)if(c(e,o)){var a=void 0;try{if(typeof e[o]!="function"){var b=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 b.name="Invariant Violation",b}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)&&(ue(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),ue(null)),a instanceof Error&&!(a.message in je)&&(je[a.message]=!0,ue(i),d("Failed %s type: %s",t,a.message),ue(null))}}}var Qe=Array.isArray;function ye(e){return Qe(e)}function er(e){{var r=typeof Symbol=="function"&&Symbol.toStringTag,t=r&&e[Symbol.toStringTag]||e.constructor.name||"Object";return t}}function rr(e){try{return Ae(e),!1}catch{return!0}}function Ae(e){return""+e}function De(e){if(rr(e))return d("The provided key is an unsupported type %s. This value must be coerced to a string before before using it here.",er(e)),Ae(e)}var X=M.ReactCurrentOwner,tr={key:!0,ref:!0,__self:!0,__source:!0},Fe,Me,me;me={};function nr(e){if(ie.call(e,"ref")){var r=Object.getOwnPropertyDescriptor(e,"ref").get;if(r&&r.isReactWarning)return!1}return e.ref!==void 0}function ar(e){if(ie.call(e,"key")){var r=Object.getOwnPropertyDescriptor(e,"key").get;if(r&&r.isReactWarning)return!1}return e.key!==void 0}function or(e,r){if(typeof e.ref=="string"&&X.current&&r&&X.current.stateNode!==r){var t=k(X.current.type);me[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',k(X.current.type),e.ref),me[t]=!0)}}function ir(e,r){{var t=function(){Fe||(Fe=!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 ur(e,r){{var t=function(){Me||(Me=!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 sr=function(e,r,t,n,i,c,o){var a={$$typeof:g,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 cr(e,r,t,n,i){{var c,o={},a=null,b=null;t!==void 0&&(De(t),a=""+t),ar(r)&&(De(r.key),a=""+r.key),nr(r)&&(b=r.ref,or(r,i));for(c in r)ie.call(r,c)&&!tr.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||b){var p=typeof e=="function"?e.displayName||e.name||"Unknown":e;a&&ir(o,p),b&&ur(o,p)}return sr(e,a,b,i,n,X.current,o)}}var Ee=M.ReactCurrentOwner,Ie=M.ReactDebugCurrentFrame;function B(e){if(e){var r=e._owner,t=oe(e.type,e._source,r?r.type:null);Ie.setExtraStackFrame(t)}else Ie.setExtraStackFrame(null)}var _e;_e=!1;function Re(e){return typeof e=="object"&&e!==null&&e.$$typeof===g}function We(){{if(Ee.current){var e=k(Ee.current.type);if(e)return` Check the render method of \``+e+"`."}return""}}function fr(e){{if(e!==void 0){var r=e.fileName.replace(/^.*[\\\/]/,""),t=e.lineNumber;return` Check your code at `+r+":"+t+"."}return""}}var Ye={};function lr(e){{var r=We();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 Ne(e,r){{if(!e._store||e._store.validated||e.key!=null)return;e._store.validated=!0;var t=lr(r);if(Ye[t])return;Ye[t]=!0;var n="";e&&e._owner&&e._owner!==Ee.current&&(n=" It was passed a child from "+k(e._owner.type)+"."),B(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),B(null)}}function Le(e,r){{if(typeof e!="object")return;if(ye(e))for(var t=0;t<e.length;t++){var n=e[t];Re(n)&&Ne(n,r)}else if(Re(e))e._store&&(e._store.validated=!0);else if(e){var i=L(e);if(typeof i=="function"&&i!==e.entries)for(var c=i.call(e),o;!(o=c.next()).done;)Re(o.value)&&Ne(o.value,r)}}}function dr(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===f||r.$$typeof===R))t=r.propTypes;else return;if(t){var n=k(r);Ze(t,e.props,"prop",n,e)}else if(r.PropTypes!==void 0&&!_e){_e=!0;var i=k(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 vr(e){{for(var r=Object.keys(e.props),t=0;t<r.length;t++){var n=r[t];if(n!=="children"&&n!=="key"){B(e),d("Invalid prop `%s` supplied to `React.Fragment`. React.Fragment can only have `key` and `children` props.",n),B(null);break}}e.ref!==null&&(B(e),d("Invalid attribute `ref` supplied to `React.Fragment`."),B(null))}}function Ue(e,r,t,n,i,c){{var o=Y(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 b=fr(i);b?a+=b:a+=We();var v;e===null?v="null":ye(e)?v="array":e!==void 0&&e.$$typeof===g?(v="<"+(k(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 p=cr(e,r,t,i,c);if(p==null)return p;if(o){var C=r.children;if(C!==void 0)if(n)if(ye(C)){for(var $=0;$<C.length;$++)Le(C[$],e);Object.freeze&&Object.freeze(C)}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 Le(C,e)}return e===S?vr(p):dr(p),p}}function hr(e,r,t){return Ue(e,r,t,!0)}function pr(e,r,t){return Ue(e,r,t,!1)}var gr=pr,yr=hr;G.Fragment=S,G.jsx=gr,G.jsxs=yr}()),G}(function(h){process.env.NODE_ENV==="production"?h.exports=$e():h.exports=ze()})(Te);const Oe=Te.exports.jsx;var J,T,W,ce;const Ge=Object.freeze(Object.defineProperty({__proto__:null,MeloDisc:({audioRef:h,centerImageSrc:g,rotation:P=!0,bounceMultiplier:S=1,bars:F=200,barWidth:x=4,barHeightMultiplier:j=1,barColor:u,circleProps:f={circleWidth:4,circleColor:"black"},centerColor:m="white",canvasBackground:l="white",baseRadiusValue:R=150,fftSizeValue:w=512,smoothingTimeConstant:N=.8,canvasWidth:Z=1200,canvasHeight:fe=1e3})=>{const[L,M]=_.useState(),[d,le]=_.useState(),[H,de]=_.useState(),[s,ve]=_.useState(),y=_.useRef(null),A=_.useRef(),Y=_.useRef();_.useEffect(()=>{y.current.width=Z,y.current.height=fe,ve(y.current.getContext("2d")),M(h.current),le(new AudioContext)},[]),_.useEffect(()=>{H&&(H.connect(A.current),A.current.connect(d.destination),q())},[H]),_.useEffect(()=>{d&&(de(d.createMediaElementSource(L)),A.current=d.createAnalyser(),A.current.fftSize=w,A.current.smoothingTimeConstant=N,Y.current=new Uint8Array(A.current.frequencyBinCount)),L&&d&&L.addEventListener("play",()=>{d.resume()})},[d]);const K=new Image;g&&(K.src=g),_.useEffect(()=>{u?Object.keys(u).length===2?u.colorOne&&u.colorTwo&&(J=se(u.colorOne,u.colorTwo,256)):Object.keys(u).length===1&&(u.hslColor?W=u.hslColor:u.colorOne?J=se(u.colorOne,u.colorOne,256):u.colorTwo?J=se(u.colorTwo,u.colorTwo,256):W=[2,100,50]):W=[2,100,50]},[u]);const q=()=>{if(requestAnimationFrame(q),A.current.getByteFrequencyData(Y.current),s.fillStyle=l,s.fillRect(0,0,y.current.width,y.current.height),S){const O=Be(Y.current);ce=Math.max(R,R+O*S)}else S||(ce=R);T=ce;const k=()=>{s&&(s.save(),s.beginPath(),s.arc(y.current.width/2,y.current.height/2,T,0,2*Math.PI),f===void 0?(s.strokeStyle="white",s.lineWidth=1):f&&(s.lineWidth=f.circleWidth,s.strokeStyle=f.circleColor),s.stroke(),s.clip(),g===void 0&&(s.fillStyle=m,s.fill(),s.stroke()),g&&(P?(s.setTransform(1,0,0,1,y.current.width/2,y.current.height/2),s.rotate(L.currentTime/1),s.drawImage(K,-T,-T,T*2,T*2),s.setTransform(1,0,0,1,0,0)):s.drawImage(K,y.current.width/2-T,y.current.height/2-T,T*2,T*2)),s.restore())};for(var E=0;E<F;E++){const O=Math.PI*2/F,U=Y.current[E]*j,Q=y.current.width/2+Math.cos(O*E)*T,ee=y.current.height/2+Math.sin(O*E)*T,re=y.current.width/2+Math.cos(O*E)*(T+U),te=y.current.height/2+Math.sin(O*E)*(T+U);let V;J&&(V=J[Y.current[E]]),W&&(V=`hsl(${W[0]*E}, ${W[1]}%, ${W[2]}%)`),s&&(s.strokeStyle=V,s.lineWidth=x,s.beginPath(),s.moveTo(Q,ee),s.lineTo(re,te),s.stroke())}k()};return Oe("div",{children:Oe("canvas",{ref:y})})}},Symbol.toStringTag,{value:"Module"}));I.MeloDisc=Ge,Object.defineProperties(I,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});