@rs1/media-player
Version:
A smart media player for React, for audio and video content.
10 lines • 129 kB
JavaScript
Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react"),t=require("transition-hook");function r(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var o=r(e);function a(){return(a=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var o in r)Object.prototype.hasOwnProperty.call(r,o)&&(e[o]=r[o])}return e}).apply(this,arguments)}function n(e){var t,r,o="";if("string"==typeof e||"number"==typeof e)o+=e;else if("object"==typeof e)if(Array.isArray(e))for(t=0;t<e.length;t++)e[t]&&(r=n(e[t]))&&(o&&(o+=" "),o+=r);else for(t in e)e[t]&&(o&&(o+=" "),o+=t);return o}function l(){for(var e,t,r=0,o="";r<arguments.length;)(e=arguments[r++])&&(t=n(e))&&(o&&(o+=" "),o+=t);return o}function i(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:250,r=!1;return function(){if(!r)return r=!0,setTimeout((()=>{r=!1}),t),e(...arguments)}}function s(t,r){let o,a;"number"==typeof t?(o=!1,a=t):void 0===t?(o=!1,a=300):(o=t,a=null!=r?r:300);const n=e.useRef(void 0),[l,i]=e.useState(o);return[l,e.useCallback(function(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:250,r=void 0;return function(){for(var o=arguments.length,a=new Array(o),n=0;n<o;n++)a[n]=arguments[n];clearTimeout(r),r=setTimeout((()=>{e(...a)}),t)}}((e=>{i(null!=e?e:!o),clearTimeout(n.current),n.current=setTimeout((()=>{i(o),n.current=void 0}),a)}),a),[a,o])]}function c(t,r,o,a){const n="number"!=typeof t&&"boolean"!=typeof t&&t?t:void 0,l="number"!=typeof r&&"boolean"!=typeof r&&r?r:void 0,i="boolean"==typeof t?t:"boolean"==typeof r?r:"boolean"==typeof o&&o,s="number"==typeof t?t:"number"==typeof r?r:"number"==typeof o?o:"number"==typeof a?a:3e3,[c,u]=e.useState(!1),[d,m]=e.useState(i);return e.useEffect((()=>{var e;if(d)return;const t=()=>{u(!0)},r=()=>u(!1),o=()=>m(!0),a=null!=n?n:null===(e=window)||void 0===e?void 0:e.document;return a.addEventListener("mousemove",o),a.addEventListener("mousedown",o),a.addEventListener("click",o),a.addEventListener("touchend",o),a.addEventListener("keydown",o),l&&(l.addEventListener("mouseenter",t),l.addEventListener("mouseleave",r)),()=>{a.removeEventListener("mousemove",o),a.removeEventListener("mousedown",o),a.removeEventListener("click",o),a.removeEventListener("touchend",o),a.removeEventListener("keydown",o),l&&(l.removeEventListener("mouseenter",t),l.removeEventListener("mouseleave",r))}}),[d,n,l]),e.useEffect((()=>{d&&setTimeout((()=>m(!1)),s)}),[d,s]),d||c}function u(t){let{onDoubleTap:r,onSingleTap:o,delay:a=300}=t;const n=e.useRef(null),l=e.useRef(0),i=e.useCallback((()=>{l.current+=1,2===l.current?(n.current&&clearTimeout(n.current),n.current=null,l.current=0,r()):1===l.current&&(n.current&&clearTimeout(n.current),n.current=setTimeout((()=>{n.current=null,l.current=0,null==o||o()}),a))}),[r,o,a]);return e.useEffect((()=>()=>{n.current&&(clearTimeout(n.current),n.current=null)}),[]),i}function d(e,t,r){return Math.min(Math.max(e,t),r)}function m(e){const t=[...e];for(let e=t.length-1;e>0;e--){const r=Math.floor(Math.random()*(e+1));[t[e],t[r]]=[t[r],t[e]]}return t}const p={BTT:{axis:"Y",scroll:"Top",start:"top",end:"height",reverse:!1},TTB:{axis:"Y",scroll:"Top",start:"bottom",end:"height",reverse:!0},RTL:{axis:"X",scroll:"Left",start:"right",end:"width",reverse:!1},LTR:{axis:"X",scroll:"Left",start:"left",end:"width",reverse:!0}};function f(e,t){var r,o,a,n,l;const i=e.target.getBoundingClientRect(),{axis:s,scroll:c,start:u,end:m,reverse:f}=p[t],{[u]:v,[m]:w}=i;return d(0,(f?1:-1)*(("X"===s?e.x:e.y)-v+(null!==(r=null===(o=window)||void 0===o?void 0:o[`page${s}Offset`])&&void 0!==r?r:((null===(a=document)||void 0===a?void 0:a.documentElement)||(null===(n=document)||void 0===n?void 0:n.body.parentNode)||(null===(l=document)||void 0===l?void 0:l.body)||{})["scroll"+c])),w)/w}function v(){for(var t=arguments.length,r=new Array(t),o=0;o<t;o++)r[o]=arguments[o];const[a=0,n={}]=r,{direction:l="LTR",onChange:s}=n,c=e.useRef(null),[u,m]=e.useState(a),[p,v]=e.useState(!1);e.useEffect((()=>{m(a)}),[a]);const w=e.useCallback((e=>{if(!c.current)return;const t=d(f({target:c.current,...e},l),0,.99);m(t),s&&s(t)}),[l,s]),g=e.useCallback((e=>{const t="touchstart"===e.type?e.touches[0]:e;c.current=e.currentTarget,v(!0);const r=e=>{const t="touchmove"===e.type?e.touches[0]:e;w({x:t.pageX,y:t.pageY})},o=()=>{c.current=null,v(!1),document.removeEventListener("mousemove",r),document.removeEventListener("touchmove",r)};document.addEventListener("mousemove",i(r,25)),document.addEventListener("touchmove",i(r,25)),document.addEventListener("mouseup",o,{once:!0}),document.addEventListener("touchend",o,{once:!0}),w({x:t.pageX,y:t.pageY})}),[w]);return{value:u,props:{onMouseDown:g,onTouchStart:g},isSliding:p}}const w={xs:0,sm:576,md:768,lg:992,xl:1200},g=e=>Object.entries(e).filter((e=>{let[,t]=e;return"number"==typeof t})).sort(((e,t)=>{let[,r]=e,[,o]=t;return o-r}));function y(e,t,r){const[a,n]=o.default.useState((()=>{const o="object"!=typeof e||Array.isArray(e)?"object"!=typeof t||Array.isArray(t)?void 0:t:e,a=Array.isArray(e)?e:Array.isArray(t)?t:r,n="string"==typeof e&&e in w?e:void 0;return{default:n,breakpoint:n,breakpoints:g(o||w),needed:a}}));return o.default.useEffect((()=>{const r="object"!=typeof e||Array.isArray(e)?"object"!=typeof t||Array.isArray(t)?void 0:t:e;n((e=>({...e,breakpoints:g(r||w)})))}),[JSON.stringify(e),JSON.stringify(t)]),o.default.useEffect((()=>{const o=Array.isArray(e)?e:Array.isArray(t)?t:r;n((e=>({...e,needed:o})))}),[JSON.stringify(e),JSON.stringify(t),JSON.stringify(r)]),o.default.useEffect((()=>{const e=()=>{var e;const t=null===(e=window)||void 0===e?void 0:e.innerWidth;let r=void 0;for(const[e,o]of a.breakpoints)if((!a.needed||a.needed.some((t=>t===e)))&&t>o){r=e;break}n((e=>{var t;return{...e,breakpoint:null!==(t=r)&&void 0!==t?t:e.default}}))};var t;(void 0===a.needed||a.needed.some((e=>a.breakpoints.some((t=>{let[r]=t;return r===e})))))&&(null===(t=window)||void 0===t||t.addEventListener("resize",e),e());return()=>{var t;null===(t=window)||void 0===t||t.removeEventListener("resize",e)}}),[a.breakpoints,a.needed]),a.breakpoint}function h(){var e;const t=null===(e=window)||void 0===e?void 0:e.document,r=t&&"fullscreenEnabled"in t?"mdn":t&&"webkitFullscreenEnabled"in t?"webkit":t&&"webkitIsFullScreen"in t?"webkit-old":t&&"mozFullScreenEnabled"in t?"firefox":t&&"msFullscreenEnabled"in t?"explorer":"mdn",o=(()=>{if(!t)return!1;switch(r){case"mdn":return t.fullscreenEnabled;case"webkit":return t.webkitFullscreenEnabled;case"webkit-old":return t.webkitIsFullScreen;case"firefox":return t.mozFullScreenEnabled;case"explorer":return t.msFullscreenEnabled;default:return!1}})(),a=(()=>{switch(r){case"webkit":case"webkit-old":return"webkitfullscreenchange";case"firefox":return"mozfullscreenchange";case"explorer":return"MSFullscreenChange";case"mdn":default:return"fullscreenchange"}})(),n=(()=>{switch(r){case"webkit":case"webkit-old":return"webkitfullscreenerror";case"firefox":return"mozfullscreenerror";case"explorer":return"MSFullscreenError";case"mdn":default:return"fullscreenerror"}})();return{document:t,currentAPI:r,isFullscreenEnabled:o,onFullscreenEvent:a,onFullscreenErrorEvent:n}}function b(){let e=null;const{document:t,currentAPI:r}=h();return t?("mdn"===r?e=t.fullscreenElement:"webkit"===r?e=t.webkitFullscreenElement:"webkit-old"===r?e=t.webkitFullScreenElement:"firefox"===r?e=t.mozFullScreenElement:"explorer"===r&&(e=t.msFullscreenElement),e):e}async function k(e,t){if(!e)return;const{currentAPI:r,isFullscreenEnabled:o}=h(),a=/iPad|iPhone|iPod/.test(navigator.userAgent);if(t&&!o&&a&&"VIDEO"===t.tagName){const e=t;return null==e?void 0:e["webkitEnterFullscreen"in e?"webkitEnterFullscreen":"enterFullscreen"]()}const n=e;return"mdn"===r?n.requestFullscreen():"webkit"===r?n.webkitRequestFullscreen():"webkit-old"===r?n.webkitRequestFullScreen():"firefox"===r?n.mozRequestFullScreen():"explorer"===r?n.msRequestFullscreen():void 0}async function x(){const{document:e,currentAPI:t}=h();if(e)return"mdn"===t?e.exitFullscreen():"webkit"===t?e.webkitExitFullscreen():"webkit-old"===t?e.webkitCancelFullScreen():"firefox"===t?e.mozCancelFullScreen():"explorer"===t?e.msExitFullscreen():void 0}async function C(e,t){if(e)return b()?x():k(e,t)}function E(){const[t,r]=e.useState(!1),o=e.useRef({request:k,exit:x,toggle:C,element:null,enabled:!1});return e.useEffect((()=>{var e,t;const{isFullscreenEnabled:a,onFullscreenEvent:n,onFullscreenErrorEvent:l}=h();o.current.enabled=a;const i=()=>{const e=b();o.current.element=e,r(null!==e)};return null===(e=document)||void 0===e||e.addEventListener(n,i),null===(t=document)||void 0===t||t.addEventListener(l,i),()=>{var e,t;null===(e=document)||void 0===e||e.removeEventListener(n,i),null===(t=document)||void 0===t||t.removeEventListener(l,i)}}),[]),[t,o.current]}function P(){let e=!1;return window&&document&&(e=!!document.pictureInPictureEnabled),{isPiPEnabled:e}}function S(){var e,t;return null!==(e=null===(t=document)||void 0===t?void 0:t.pictureInPictureElement)&&void 0!==e?e:null}async function L(e){e&&e.requestPictureInPicture()}async function M(){S()&&document.exitPictureInPicture()}async function T(e){e&&(S()?await M():await L(e))}function N(){const[t,r]=e.useState(!1),o=e.useRef({request:L,exit:M,toggle:T,element:null,enabled:!1});return e.useEffect((()=>{const{isPiPEnabled:e}=P();o.current.enabled=e;const t=()=>{const e=S();o.current.element=e,r(null!==e)};return document.addEventListener("enterpictureinpicture",t),document.addEventListener("leavepictureinpicture",t),()=>{document.removeEventListener("enterpictureinpicture",t),document.removeEventListener("leavepictureinpicture",t)}}),[]),[t,o.current]}function A(e){const[t,r]=o.default.useState(!1),[a,n]=o.default.useState(!1);return o.default.useEffect((()=>{const t=()=>{r(!!e&&e.webkitCurrentPlaybackTargetIsWireless)};if(!window.WebKitPlaybackTargetAvailabilityEvent)return void n(!1);const o=e=>{n("available"===e.availability)};return null==e||e.addEventListener("webkitcurrentplaybacktargetiswirelesschanged",t),null==e||e.addEventListener("webkitplaybacktargetavailabilitychanged",o),()=>{null==e||e.removeEventListener("webkitcurrentplaybacktargetiswirelesschanged",t),null==e||e.removeEventListener("webkitplaybacktargetavailabilitychanged",o)}}),[e]),{isActive:t,isAvailable:a,airPlayAPI:{showPicker:()=>async function(e){e&&e.webkitShowPlaybackTargetPicker()}(e)}}}function j(t){const[r,o]=e.useState("disconnected"),[a,n]=e.useState(!1),l=e.useRef(null),i=e.useCallback((function(){o(this.state)}),[]),s=e.useCallback((()=>{a&&t&&t.remote&&(t.remote.prompt().then((()=>{i.call(t.remote)})).catch((()=>{i.call(t.remote),n(!1)})),o("connecting"))}),[t,a]);return e.useEffect((()=>{if(t&&t.remote)return l.current&&t.remote.cancelWatchAvailability(l.current),t.remote.watchAvailability((e=>{n(!!e)})).then((e=>{l.current=e})).catch((()=>{n(!1)})),t.remote.onconnecting=i,t.remote.onconnect=i,t.remote.ondisconnect=i,()=>{l.current&&t.remote.cancelWatchAvailability(l.current),t.remote.onconnecting=null,t.remote.onconnect=null,t.remote.ondisconnect=null}}),[t]),{state:r,isAvailable:a,requestRemotePlayback:s}}function z(){const t=e.useRef(null);return{initStream:e.useCallback((()=>{t.current||(t.current=function(){if("undefined"==typeof window)return null;const e=window.AudioContext||window.webkitAudioContext||!1;if(!e)return null;const t=new e,r=2*t.sampleRate,o=t.createBuffer(1,r,t.sampleRate),a=o.getChannelData(0);for(let e=0;e<r;e++)a[e]=0;const n=t.createBufferSource();n.buffer=o,n.loop=!0;const l=t.createMediaStreamDestination();n.connect(l);const i=document.createElement("audio");return i.style.display="none",document.body.appendChild(i),i.srcObject=l.stream,i}())}),[]),playStream:e.useCallback((()=>{t.current&&t.current.play()}),[]),stream:t.current}}const R={volume:["mute"],playback:["previous","backward10","playpause","forward10","next"],playlist:["playlist","shuffle","repeat"],metadata:["metadata"],time:["time","seekbar","remaining"],screen:["airplay","pictureinpicture","fullscreen"],state:["loading","stalled","error"]},Z={extended:[[["playlist","shuffle","error"],R.playback,["stalled","repeat"]],R.time,[["mute","airplay"],"metadata",["pictureinpicture","fullscreen"]]],compact:[[R.volume,R.playback,R.screen],[R.time]],mini:[[R.metadata],["error",R.playback,"stalled"],[R.time],["mute","playlist","shuffle","repeat","airplay","pictureinpicture","fullscreen"]]},I={aspectRatio:"stretch",playerMode:"auto",playerBackground:"flat",breakpoints:w,autoHideControls:3e3,controls:{xs:Z.mini,md:Z.extended},controlsMetadataSeparator:" — ",autoPlay:!1,loop:!1,muted:!1,canControlWithKeyboard:!0,canShuffle:!0,canLoop:!0,canPause:!0,canSeek:!0,canMute:!0,canChangeVolume:!0,canChangePlaybackRate:!0,canFullscreen:!0,canPictureInPicture:!0,canAirPlay:!0,canRemotePlay:!0,canTapToPause:!0,canDoubleTapToSeek:!0},F={default:I};function $(e){return{...I,..."string"==typeof e&&Object.prototype.hasOwnProperty.call(F,e)?F[e]:"object"==typeof e?e:{}}}const D=e.createContext(F.base);function O(t){const{config:r={},children:a}=t,n=function(t){const[r,o]=e.useState($(t));return e.useEffect((()=>{o($(t))}),[JSON.stringify(t)]),r}(r);return o.default.createElement(D.Provider,{value:n},a)}function B(t){const r=e.useRef(null),o=e.useRef(null),{onPlaybackChange:a,onTrackChange:n,keepAlive:l=!1}=t,i=z(),s=e.useCallback((e=>{e?(r.current=e,o.current={current:e,isPlaying:null!=o&&o.current?o.current.isPlaying:!e.paused,isSeeking:!1,getTime:()=>!e||isNaN(e.currentTime)?0:e.currentTime,getDuration:()=>!e||isNaN(e.duration)?0:e.duration,getProgress:()=>!e||isNaN(e.duration)||isNaN(e.currentTime)?0:e.currentTime/e.duration,getBuffered:()=>e&&e.buffered.length&&!isNaN(e.duration)?e.buffered.end(e.buffered.length-1)/e.duration:0,getMuted:()=>!!e&&(e.muted||0===e.volume),getVolume:()=>e?e.muted?0:isNaN(e.volume)?1:e.volume:1,getPlaybackRate:()=>!e||isNaN(e.playbackRate)?1:e.playbackRate,setTime:async t=>{var r,a;if(!e)return;if(o.current){const r=isNaN(e.currentTime)?0:e.currentTime;o.current.isSeeking=t>r?"forward":"backward"}e.dispatchEvent(new Event("seeking"));const n=null!==(r=null===(a=o.current)||void 0===a?void 0:a.getDuration())&&void 0!==r?r:0;e.currentTime=d(t,0,n),e.dispatchEvent(new Event("seeked"))},setProgress:async t=>{if(!e)return;const r=isNaN(e.duration)?0:e.duration;if(o.current){const a=isNaN(e.currentTime)?0:e.currentTime;o.current.isSeeking=t*r>a?"forward":"backward"}e.dispatchEvent(new Event("seeking")),e.currentTime=d(t*r,0,r),e.dispatchEvent(new Event("seeked"))},setMuted:async t=>{e&&(e.muted="function"==typeof t?t(e.muted):t)},setVolume:async t=>{if(!e)return;const r="function"==typeof t?t(e.volume):t;e.volume=d(r,0,1),e.muted=!1},setPlaybackRate:async t=>{if(!e)return;const r="function"==typeof t?t(e.playbackRate):t;e.playbackRate=d(parseFloat(""+r),.25,2)},play:async()=>{l&&(i.stream||await i.initStream(),i.playStream()),e&&await e.play(),o.current&&(o.current.isPlaying=!0),a&&a(!0)},pause:async()=>{e&&await e.pause(),o.current&&(o.current.isPlaying=!1),a&&a(!1)},wait:async()=>{e&&await e.pause()},skip:async t=>{var r,a,n,l,i;if(!e)return;const s=(null!==(r=null===(a=o.current)||void 0===a?void 0:a.getTime())&&void 0!==r?r:0)+t,c=null!==(n=null===(l=o.current)||void 0===l?void 0:l.getDuration())&&void 0!==n?n:0;var u;if(null===(i=o.current)||void 0===i||i.setTime(s),s<=.1)await(null===(u=o.current)||void 0===u?void 0:u.previous());else if(s>c-.1){var d;await(null===(d=o.current)||void 0===d?void 0:d.next())}},previous:async()=>{var t,r;if(!e)return;var a,l;if((null!==(t=null===(r=o.current)||void 0===r?void 0:r.getTime())&&void 0!==t?t:0)>10||!n)return await(null===(a=o.current)||void 0===a?void 0:a.setTime(0)),void await(null===(l=o.current)||void 0===l?void 0:l.play());n(-1)},next:async()=>{if(e)if(n)n(1);else{var t,r,a,l;const e=null!==(t=null===(r=o.current)||void 0===r?void 0:r.getDuration())&&void 0!==t?t:0;var i,s,c,u;e-(null!==(a=null===(l=o.current)||void 0===l?void 0:l.getTime())&&void 0!==a?a:0)>10?(await(null===(i=o.current)||void 0===i?void 0:i.setTime(e)),await(null===(s=o.current)||void 0===s?void 0:s.pause())):(await(null===(c=o.current)||void 0===c?void 0:c.setTime(0)),await(null===(u=o.current)||void 0===u?void 0:u.play()))}},seekTo:async e=>{var t;await(null===(t=o.current)||void 0===t?void 0:t.setTime(e))}}):(r.current=null,o.current=null)}),[a,n,l]);return[null==o?void 0:o.current,s,r]}var V;const Y="undefined"!=typeof window?(null===(V=navigator.userAgentData)||void 0===V?void 0:V.platform)||navigator.platform:"",q="undefined"!=typeof window&&/^((?!chrome|android).)*safari/i.test(navigator.userAgent),X="undefined"!=typeof window&&(/^(iPhone|iP[oa]d)(\sSimulator)?$/i.test(Y)||navigator.userAgent.includes("Mac")&&"ontouchend"in document);function K(e){var t;if(!e||"string"!=typeof e)return null;const r=null===(t=e.split("?")[0].split(".").pop())||void 0===t?void 0:t.toLowerCase();if(!r)return null;switch(r){case"mp4":return"video/mp4";case"webm":return"video/webm";case"ogg":return"video/ogg";case"m4v":return"video/x-m4v";case"mov":return"video/quicktime";case"wmv":return"video/x-ms-wmv";case"avi":return"video/x-msvideo";case"flv":return"video/x-flv";case"mpg":case"mpeg":return"video/mpeg";case"3gp":return"video/3gpp";case"3g2":return"video/3gpp2";case"ts":return"video/mp2t";case"m3u8":return"application/x-mpegURL";case"m3u":return"audio/x-mpegurl";case"f4v":return"video/x-f4v";case"f4p":return"video/x-f4p";case"f4a":return"video/x-f4a";case"f4b":return"video/x-f4b";case"mp3":return"audio/mpeg";case"wav":return"audio/wav";case"aac":return"audio/aac";case"flac":return"audio/flac";case"m4a":return"audio/x-m4a";case"jpg":case"jpeg":return"image/jpeg";case"png":return"image/png";case"gif":return"image/gif";case"svg":return"image/svg+xml";case"webp":return"image/webp";case"bmp":return"image/bmp";case"ico":return"image/vnd.microsoft.icon";case"tiff":case"tif":return"image/tiff";case"avif":return"image/avif";default:return null}}function W(e){var t;const r={title:null==e?void 0:e.title,artist:null==e?void 0:e.artist,album:null==e?void 0:e.album,artwork:null!=e&&e.artwork?[{src:e.artwork,type:null!==(t=K(e.artwork))&&void 0!==t?t:void 0}]:[]};"undefined"!=typeof window&&(navigator.mediaSession.metadata=new window.MediaMetadata(r))}function H(e){navigator.mediaSession.playbackState=null!=e&&e.isPlaying?"playing":"paused"}function U(e){var t;const r=(null==e?void 0:e.getDuration())||0,o=(null==e?void 0:e.getTime())||0,a=null!==(t=null==e?void 0:e.getPlaybackRate())&&void 0!==t?t:1;navigator.mediaSession.setPositionState({duration:r,position:o,playbackRate:a})}function J(e,t){var r;r={play:()=>null==e?void 0:e.play(),pause:null!=t&&t.canPause?()=>null==e?void 0:e.pause():null,stop:()=>null==e?void 0:e.pause(),seekto:null!=t&&t.canSeek?t=>{let{seekTime:r=0}=t;return null==e?void 0:e.seekTo(r)}:null,seekbackward:null!=t&&t.canSeek?(X||q)&&null!=t&&t.forPlaylist?null:t=>{let{seekOffset:r}=t;return null==e?void 0:e.skip(r||-10)}:null,seekforward:null!=t&&t.canSeek?(X||q)&&null!=t&&t.forPlaylist?null:t=>{let{seekOffset:r}=t;return null==e?void 0:e.skip(r||10)}:null,nexttrack:()=>null==e?void 0:e.next(),previoustrack:()=>null==e?void 0:e.previous()},Object.entries(r).forEach((e=>{let[t,r]=e;navigator.mediaSession.setActionHandler(t,r)}))}function G(e){return`${e<10?"0":""}${e}`}function _(e){let t=arguments.length>1&&void 0!==arguments[1]&&arguments[1];const r=e<0?"-":"",o=Math[t?"ceil":"floor"](Math.abs(e)),a=Math.floor(o/3600),n=Math.floor(o%3600/60),l=o%60;return`${r}${a>0?`${a}:${G(n)}`:n}:${G(l)}`}const Q=e.createContext(null);function ee(e,t,r){var o,a,n,l,i;const s=Array.isArray(e.src)?e.src:[e.src],c=s.reduce(((e,t,r)=>(e[r]||e.push(K(t)||""),e)),e.mimeType?Array.isArray(e.mimeType)?e.mimeType:[e.mimeType]:[]),u=(null!==(o=e.type)&&void 0!==o?o:s.length)?function(e){var t;if(!e||"string"!=typeof e)return"video";const r=null===(t=e.split("?")[0].split(".").pop())||void 0===t?void 0:t.toLowerCase();if(!r)return"video";switch(r){case"mp4":case"webm":case"ogg":case"m4v":case"mov":case"wmv":case"avi":case"flv":case"mpg":case"mpeg":case"3gp":case"3g2":case"ts":case"m3u8":case"f4v":case"f4p":case"f4a":case"f4b":return"video";case"m3u":case"mp3":case"wav":case"aac":case"flac":case"m4a":return"audio";default:return"video"}}(s[0]):"video",d=e.cover||t.cover,m=e.thumbnail||t.thumbnail,p=e.artwork||t.artwork,f=null!==(a=null!==(n=e.album)&&void 0!==n?n:t.title)&&void 0!==a?a:t.album,v=null!==(l=e.artist)&&void 0!==l?l:t.artist,w=e.title||`${f||(g=u,"string"!=typeof g?"":g.charAt(0).toUpperCase()+g.slice(1).toLowerCase())} ${G(r+1)}`;var g;let y=void 0!==e.id?""+e.id:void 0;if(void 0===y){const e=[...s];e.sort(),y=e.join("-")}const h="string"!=typeof e.crossOrigin?!0===e.crossOrigin?"anonymous":void 0:"use-credentials"===e.crossOrigin?"use-credentials":"anonymous",b=e.prefix||t.prefix||"",k=e.suffix||t.suffix||"",x=""+(null!==(i=e.position)&&void 0!==i?i:r+1);return{...e,id:y,type:u,title:w,artist:v||"",album:f||"",cover:d||p||m,artwork:p||d||m,thumbnail:m||p||d,index:r,src:s,mimeType:c,crossOrigin:h,prefix:b,suffix:k,position:x}}function te(e,t){var r,o;const a=void 0!==e.id?""+e.id:"playlist-"+t,n=e.cover,l=e.thumbnail,i=e.artwork,s={...e,id:a,cover:n||i||l,artwork:i||n||l,thumbnail:l||i||n};return{...s,tracks:null!==(r=null===(o=e.tracks)||void 0===o?void 0:o.map(((e,t)=>ee(e,s,t))))&&void 0!==r?r:[]}}function re(t){const{children:r,playlist:a,track:n}=t,l=e.useContext(D),[i,s]=e.useState((()=>{if(n&&!a){const e=[te({id:"playlist-0",tracks:[n]},0)];return{playlistCollection:e,queue:e[0].tracks,mode:l.loop?"repeat-one":"repeat",shuffle:!1,activeTrack:0,activePlaylist:0}}const e=(a?Array.isArray(a)?a:[a]:[]).map(te);let t=-1,r=-1;if(n){const o=ee(n,{},0);t=e.findIndex((e=>e.tracks.some((e=>e.id===o.id)))),-1!==t&&(r=e[t].tracks.findIndex((e=>e.id===o.id)))}const o=e[-1!==t?t:0].tracks;return{playlistCollection:e,queue:o,mode:l.loop?"repeat-one":"repeat",shuffle:!1,activePlaylist:e.length?d(t,0,e.length-1):null,activeTrack:o.length?d(r,0,o.length-1):null}})),c=e.useCallback((()=>{s((e=>({...e,mode:"repeat-one"})))}),[]),u=e.useCallback((()=>{s((e=>({...e,mode:"repeat"})))}),[]),p=e.useCallback((()=>{s((e=>{const t=null!==e.activePlaylist?m(e.playlistCollection[e.activePlaylist].tracks):[],r=t.length&&null!==e.activeTrack?e.queue[e.activeTrack]:null,o=r?t.findIndex((e=>e.id===r.id)):null;return{...e,queue:t,activeTrack:o,shuffle:!0}}))}),[]),f=e.useCallback((()=>{s((e=>{const t=null!==e.activeTrack?e.queue[e.activeTrack]:null,r=t&&null!==e.activePlaylist?e.playlistCollection[e.activePlaylist].tracks.findIndex((e=>e.id===t.id)):null;return{...e,queue:null!==e.activePlaylist?e.playlistCollection[e.activePlaylist].tracks:[],activeTrack:null!==r&&-1!==r?r:null,shuffle:!1}}))}),[]),v=e.useCallback((e=>{s((t=>{const r="function"==typeof e?e(t.playlistCollection):e,o=(Array.isArray(r)?r:[r]).map(te),a=null!==t.activePlaylist?t.playlistCollection[t.activePlaylist]:null,n=null!==t.activeTrack?t.queue[t.activeTrack]:null;let l=a?o.findIndex((e=>e.id===a.id)):null;l=-1===l?null:l;const i=null===l?[]:t.shuffle?m(o[l].tracks):o[l].tracks;let s=n&&l?i.findIndex((e=>e.id===n.id)):null;return s=-1===s?null:s,{...t,playlistCollection:o,queue:i,activePlaylist:l,activeTrack:s}}))}),[s]),w=e.useCallback((function(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0;s((r=>{const o=null===r.activeTrack?null:r.queue[r.activeTrack],a=null===r.activePlaylist?null:r.playlistCollection[r.activePlaylist],n="function"==typeof e?e(a,o):e,l="function"==typeof t?t(a,o):t;if(n===r.activePlaylist)return r;let i=null;if("number"==typeof n)i=d(n,0,r.playlistCollection.length-1);else if("string"==typeof n){const e=r.playlistCollection.findIndex((e=>e.id===n));-1!==e&&(i=e)}else if(null!==n){const e=te(n,r.playlistCollection.length),t=r.playlistCollection.findIndex((t=>t.id===e.id));i=-1!==t?t:r.playlistCollection.length}if(null===i)return{...r,queue:[],activePlaylist:null,activeTrack:null};const s=i<r.playlistCollection.length?r.playlistCollection:[...r.playlistCollection,te(n,i)],c=s[i].tracks,u=r.shuffle?m(c):c,p=null===l?0:u.findIndex((e=>e.id===("number"==typeof e?c[d(e,0,c.length)].id:"string"==typeof e?e:e.id)));return{...r,playlistCollection:s,queue:u,activePlaylist:i,activeTrack:p}}))}),[]),g=e.useCallback((e=>s((t=>{const r="function"==typeof e?e(null===t.activeTrack?null:t.queue[t.activeTrack]):e;if(null===r)return{...t,activeTrack:null};if("number"==typeof r){const e=null===t.activePlaylist?null:t.playlistCollection[t.activePlaylist].tracks[d(r,0,t.queue.length-1)];if(!e)return{...t,activeTrack:null};const o=t.queue.findIndex((t=>t.id===e.id));return{...t,activeTrack:o<0?null:o}}if("string"==typeof r){let e,o,a;if(null===t.activePlaylist?null:t.playlistCollection[t.activePlaylist].tracks.find((e=>e.id===r)))e=t.activePlaylist,a=t.queue,o=t.queue.findIndex((e=>e.id===r));else{const n=t.playlistCollection.findIndex((e=>e.tracks.find((e=>e.id===r))));if(-1===n)return{...t,activeTrack:null};e=n,a=t.playlistCollection[n].tracks,t.shuffle&&(a=m(a)),o=a.findIndex((e=>e.id===r))}return{...t,queue:a,activePlaylist:e,activeTrack:o<0?null:o}}const o=ee(r,{},t.queue.length),a=t.queue.findIndex((e=>e.id===o.id));if(-1===a){const e=t.playlistCollection.findIndex((e=>e.tracks.find((e=>e.id===o.id))));if(e>=0){const r=e;let a=t.playlistCollection[e].tracks;t.shuffle&&(a=m(a));const n=a.findIndex((e=>e.id===o.id));return{...t,queue:a,activePlaylist:r,activeTrack:n<0?null:n}}const a=[...t.playlistCollection];if(null===t.activePlaylist)return{...t,activeTrack:null};const n=t.playlistCollection[t.activePlaylist];n.tracks=[...n.tracks,ee(r,n,n.tracks.length)];const l=t.shuffle?m(n.tracks):n.tracks,i=l.findIndex((e=>e.id===o.id));return a[t.activePlaylist]=n,{...t,playlistCollection:a,queue:l,activeTrack:i<0?null:i}}return{...t,activeTrack:a}}))),[]),y=e.useCallback((e=>{s((t=>{const r=null===t.activeTrack?0:t.activeTrack;return{...t,activeTrack:(r+e)%t.queue.length}}))}),[]),h=e.useCallback((()=>y(-1)),[y]),b=e.useCallback((()=>y(1)),[y]),k=e.useMemo((()=>({track:[null===i.activeTrack?null:i.queue[i.activeTrack],g],playlist:[null===i.activePlaylist?null:i.playlistCollection[i.activePlaylist],w],collection:[i.playlistCollection,v],state:{mode:i.mode,shuffle:i.shuffle,queue:i.queue},controls:{shuffle:p,unshuffle:f,toggleShuffle:i.shuffle?f:p,loop:c,unloop:u,toggleLoop:"repeat-one"===i.mode?u:c,setTrack:g,skipTrackBy:y,previousTrack:h,nextTrack:b}})),[p,f,c,u,g,w,v,y,h,b,JSON.stringify(i.queue),JSON.stringify(i.playlistCollection),i.activeTrack,i.activePlaylist,i.mode,i.shuffle]);return o.default.createElement(Q.Provider,{value:k},r)}function oe(t){const[r,o]=e.useState(t);return[r,e.useCallback((e=>{o((t=>{const r="function"==typeof e?e(t):e,o=Object.keys(r).filter((e=>Object.keys(t).includes(e))).reduce(((e,t)=>(e[t]=r[t],e)),{}),a={...t,...o};return JSON.stringify(a)===JSON.stringify(t)?t:a}))}),[])]}const ae={wasPlaying:!1,isPlaying:!1,isWaiting:!1,isSeeking:!1,isStalled:!1,isLoaded:!1,isMuted:!1,isFullscreen:!1,isPictureInPicture:!1,isImmersive:!1,isAirPlay:!1,hasError:!1,hasLoadedData:!1,hasLoadedMetadata:!1,volume:1,playbackRate:1,intrinsicSize:[0,0]},ne=e.createContext(ae),le=e.createContext((()=>{}));function ie(t){const{children:r}=t,a=e.useContext(D),[n,l]=oe((()=>{var e,t,r;return{...ae,isMuted:null!==(e=null==a?void 0:a.muted)&&void 0!==e?e:ae.isMuted,wasPlaying:null!==(t=null==a?void 0:a.autoPlay)&&void 0!==t?t:ae.wasPlaying,isPlaying:null!==(r=null==a?void 0:a.autoPlay)&&void 0!==r?r:ae.isPlaying}}));e.useEffect((()=>{l({isMuted:null==a?void 0:a.muted,wasPlaying:null==a?void 0:a.autoPlay,isPlaying:null==a?void 0:a.autoPlay})}),[null==a?void 0:a.muted,null==a?void 0:a.autoPlay]);const[i]=E();e.useEffect((()=>{l((e=>({...e,isFullscreen:!!i})))}),[i]);const[s]=N();return e.useEffect((()=>{l((e=>({...e,isPictureInPicture:!!s})))}),[s]),o.default.createElement(le.Provider,{value:l},o.default.createElement(ne.Provider,{value:n},r))}const se={time:0,duration:0,progress:0,buffered:0},ce=e.createContext(se),ue=e.createContext((()=>{}));function de(e){const{children:t}=e,[r,a]=oe(se);return o.default.createElement(ue.Provider,{value:a},o.default.createElement(ce.Provider,{value:r},t))}const me=e.createContext(null);function pe(t){var r,a,n,l;const{children:i}=t,s=null!==(r=e.useContext(le))&&void 0!==r?r:()=>{},c=null!==(a=e.useContext(ne))&&void 0!==a?a:{},u=null!==(n=e.useContext(ue))&&void 0!==n?n:()=>{},d=e.useContext(D),{track:[m=null]=[],controls:p={},state:{queue:f=[],mode:v="repeat-all"}={}}=null!==(l=e.useContext(Q))&&void 0!==l?l:{},w=f.length>1,g=e.useCallback((e=>{s({isPlaying:e})}),[]),y=e.useCallback((e=>{var t;return null===(t=p.skipTrackBy)||void 0===t?void 0:t.call(p,e)}),[p.skipTrackBy]),[h,b]=B({onPlaybackChange:g,onTrackChange:w?y:void 0}),k=e.useMemo((()=>{const e=m||{};return{...e.title?{title:e.title}:{},...e.artist?{artist:e.artist}:{},...e.album?{album:e.album}:{},...e.artwork?{artwork:e.artwork}:{}}}),[JSON.stringify(m)]),x=e.useMemo((()=>((e,t)=>({setMetadata(e){try{W(e)}catch(e){console.error(e)}},refreshPlaybackState(){try{H(e)}catch(e){console.error(e)}},refreshPosition(){try{U(e)}catch(e){console.error(e)}},refreshPlaybackActions(){try{J(e,t)}catch(e){console.error(e)}}}))(h,{forPlaylist:w,canSeek:null==d?void 0:d.canSeek,canPause:null==d?void 0:d.canPause})),[h,w,null==d?void 0:d.canSeek,null==d?void 0:d.canPause]),C=e.useMemo((()=>({onPlay:()=>{x.setMetadata(k),x.refreshPlaybackState(),x.refreshPosition(),x.refreshPlaybackActions(),s({isWaiting:!1,isSeeking:!1,isLoaded:!0,isStalled:!1,isPlaying:!0,wasPlaying:!0})},onPlaying:()=>{x.setMetadata(k),x.refreshPlaybackState(),s({isWaiting:!1,isSeeking:!1,isLoaded:!0,isStalled:!1,isPlaying:!0,wasPlaying:!0})},onPause:()=>{x.refreshPlaybackState(),s({isPlaying:!1,wasPlaying:!1})},onEnded:()=>{x.refreshPlaybackState(),s({isPlaying:!1,wasPlaying:!0}),"repeat-one"===v?null==h||h.seekTo(0):null==h||h.next()},onSeeking:()=>{s({isSeeking:(null==h?void 0:h.isSeeking)||!1})},onSeeked:()=>{x.refreshPosition();const e=(null==h?void 0:h.getTime())||0;s({isSeeking:!1}),u({time:e,progress:(null==h?void 0:h.getProgress())||0})},onStalled:()=>{s({isStalled:!0})},onWaiting:()=>{s({isWaiting:!0,isStalled:!0})},onCanPlay:()=>{s({isWaiting:!1,isSeeking:!1,isLoaded:!0,isStalled:!1}),c.wasPlaying&&(null==h||h.play())},onCanPlayThrough:()=>{s({isWaiting:!1,isSeeking:!1,isLoaded:!0,isStalled:!1})},onLoadStart:()=>{s({isLoaded:!1})},onLoadedData:()=>{s({isLoaded:!0,hasLoadedData:!0})},onLoadedMetadata:()=>{var e;x.refreshPlaybackActions();let t=[512,512];if("VIDEO"===(null==h||null===(e=h.current)||void 0===e?void 0:e.tagName)){const{videoWidth:e,videoHeight:r}=h.current;t=[e,r]}s({isLoaded:!0,hasLoadedMetadata:!0,intrinsicSize:t}),c.wasPlaying&&(null==h||h.play())},onError:()=>{s({hasError:"An error occurred while loading the media"})},onAbort:()=>{s({isWaiting:!1,isSeeking:!1,isLoaded:!0,hasError:!1,isStalled:!1})},onEmptied:()=>{s({isWaiting:!1,isSeeking:!1,isLoaded:!0,hasError:!1,isStalled:!1})},onTimeUpdate:()=>{x.refreshPosition(),x.setMetadata(k);const e=(null==h?void 0:h.getTime())||0;u({time:e,progress:(null==h?void 0:h.getProgress())||0}),s((t=>e>0&&t.hasError?{hasError:!1}:t));const t=(null==h?void 0:h.getDuration())||0;t>0&&e>=t-.5&&("repeat-one"===v?null==h||h.seekTo(0):null==h||h.next())},onDurationChange:()=>{var e;const t=null==h||null===(e=h.current)||void 0===e?void 0:e.duration;void 0===t||isNaN(t)||t===1/0?s({hasError:"An error occurred while loading the media"}):(x.refreshPosition(),u({duration:(null==h?void 0:h.getDuration())||0,progress:(null==h?void 0:h.getProgress())||0,buffered:(null==h?void 0:h.getBuffered())||0}))},onProgress:()=>{u({buffered:(null==h?void 0:h.getBuffered())||0}),s({isStalled:!1})},onVolumeChange:()=>{var e,t;s({volume:null!==(e=null==h?void 0:h.getVolume())&&void 0!==e?e:1,isMuted:null!==(t=null==h?void 0:h.getMuted())&&void 0!==t&&t})},onRateChange:()=>{var e;x.refreshPosition(),s({playbackRate:null!==(e=null==h?void 0:h.getPlaybackRate())&&void 0!==e?e:1})},poster:null==m?void 0:m.thumbnail,preload:"metadata",playsInline:!0,autoPlay:c.wasPlaying,muted:null==d?void 0:d.muted,"x-webkit-airplay":!1===(null==d?void 0:d.canAirPlay)?"deny":void 0,"x-webkit-wirelessvideoplaybackdisabled":!1===(null==d?void 0:d.canRemotePlay)||void 0,disableRemotePlayback:!1===(null==d?void 0:d.canRemotePlay)||void 0,disablePictureInPicture:!1===(null==d?void 0:d.canPictureInPicture)||void 0,crossOrigin:null==m?void 0:m.crossOrigin})),[h,x,null==d?void 0:d.muted,null==d?void 0:d.canAirPlay,null==d?void 0:d.canPictureInPicture,JSON.stringify(m),c.wasPlaying,v]);e.useEffect((()=>{var e;null==h||null===(e=h.current)||void 0===e||e.load()}),[JSON.stringify(m)]);const P=e.useRef(null),S=e.useCallback((e=>{P.current=e}),[]),L=function(t,r){const[,o]=E(),[,a]=N();return e.useMemo((()=>({play:()=>null==t?void 0:t.play(),pause:()=>null==t?void 0:t.pause(),togglePlay:()=>null!=t&&t.isPlaying?t.pause():null==t?void 0:t.play(),seek:e=>null==t?void 0:t.seekTo(e),skip:e=>null==t?void 0:t.skip(e),next:()=>null==t?void 0:t.next(),previous:()=>null==t?void 0:t.previous(),enterFullscreen:()=>{var e,a;return null==o?void 0:o.request(null!==(e=r||(null==t?void 0:t.current))&&void 0!==e?e:null,null!==(a=null==t?void 0:t.current)&&void 0!==a?a:null)},exitFullscreen:()=>null==o?void 0:o.exit(),toggleFullscreen:()=>{var e,a;return null==o?void 0:o.toggle(null!==(e=r||(null==t?void 0:t.current))&&void 0!==e?e:null,null!==(a=null==t?void 0:t.current)&&void 0!==a?a:null)},enterPiP:()=>{var e;a&&"VIDEO"===(null==t||null===(e=t.current)||void 0===e?void 0:e.tagName)&&a.request(t.current)},exitPiP:()=>null==a?void 0:a.exit(),togglePiP:()=>{var e;a&&"VIDEO"===(null==t||null===(e=t.current)||void 0===e?void 0:e.tagName)&&a.toggle(t.current)},mute:()=>null==t?void 0:t.setMuted(!0),unmute:()=>null==t?void 0:t.setMuted(!1),toggleMute:()=>null==t?void 0:t.setMuted((e=>!e)),setProgress:e=>{var r;const o="function"==typeof e?e(null!==(r=null==t?void 0:t.getProgress())&&void 0!==r?r:0):e;null==t||t.setProgress(o)},setVolume:e=>{var r;const o="function"==typeof e?e(null!==(r=null==t?void 0:t.getVolume())&&void 0!==r?r:1):e;null==t||t.setVolume(o)},setPlaybackRate:e=>{var r;const o="function"==typeof e?e(null!==(r=null==t?void 0:t.getPlaybackRate())&&void 0!==r?r:1):e;null==t||t.setPlaybackRate(o)}})),[t,r,o])}(h,P.current),M=e.useMemo((()=>({node:h,container:null==P?void 0:P.current,setRef:b,setContainerRef:S,props:C,controls:L})),[h,P,b,C,L]);return o.default.createElement(me.Provider,{value:M},i)}const fe={controlsColor:"#f5f5f5",controlsBg:"#171717",accentColor:"#ffffff",errorColor:"#ed4337",mediaBg:"#171717",textFont:"'Verdana', sans-serif",monoFont:"'Courier', monospace"},ve={dark:fe,light:{...fe,controlsColor:"#171717",controlsBg:"#f5f5f5",accentColor:"#000000",mediaBg:"#f5f5f5"}};function we(e){return Object.fromEntries(Object.entries(e).map((e=>{const[t,r]=e||[];return["--rmp-"+(o=t,o.replace(/([a-z])([A-Z])/g,"$1-$2").replace(/([0-9])([a-zA-Z])/g,"$1-$2").toLowerCase()),r];var o})))}function ge(e){return"string"==typeof e&&Object.prototype.hasOwnProperty.call(ve,e)?ve[e]:"object"==typeof e?Object.fromEntries(Object.entries(e).filter((e=>{let[,t]=e;return"string"==typeof t}))):{}}function ye(e){const t=fe;return(Array.isArray(e)?e:[e]).reduce(((e,t)=>({...e,...ge(t)})),t)}const he=e.createContext(ve.dark);function be(t){const{theme:r={},children:a}=t,n=function(t){const[r,o]=e.useState(ye(t));return e.useEffect((()=>{o(ye(t))}),[JSON.stringify(t)]),r}(r);return o.default.createElement(he.Provider,{value:n},a)}const ke=()=>{const t=e.useContext(D);if(!t)throw new Error("useMediaConfig must be used within a MediaProvider");return t},xe=()=>{const t=e.useContext(he);if(!t)throw new Error("useMediaTheme must be used within a MediaProvider");return t},Ce=()=>{const t=e.useContext(Q);if(!t)throw new Error("useTrack must be used within a MediaProvider");return t.track},Ee=()=>{const t=e.useContext(Q);if(!t)throw new Error("usePlaylist must be used within a MediaProvider");return t.playlist},Pe=()=>{const t=e.useContext(Q);if(!t)throw new Error("usePlaylistState must be used within a MediaProvider");return t.state},Se=()=>{const t=e.useContext(Q);if(!t)throw new Error("usePlaylistControls must be used within a MediaProvider");return t.controls},Le=()=>{const t=e.useContext(ne);if(!t)throw new Error("useMediaState must be used within a MediaProvider");return t},Me=()=>{const t=e.useContext(ce);if(!t)throw new Error("useMediaState must be used within a MediaProvider");return t},Te=()=>{const t=e.useContext(me);if(!t)throw new Error("useMediaElement must be used within a MediaProvider");return{node:t.node,container:t.container,setRef:t.setRef,setContainerRef:t.setContainerRef,props:t.props}},Ne=()=>{const t=e.useContext(me);if(!t)throw new Error("useMediaControls must be used within a MediaProvider");return t.controls};const Ae=t=>{const r=ke(),o=Ne(),a=Se();e.useEffect((()=>{const e=e=>{if(function(e){return"key"in e}(e)&&!e.isComposing&&229!==e.keyCode&&!(e.metaKey||e.ctrlKey||e.altKey||e.shiftKey))switch(e.key){case" ":r.canPause&&(e.preventDefault(),o.togglePlay());break;case"ArrowLeft":r.canSeek&&(e.preventDefault(),o.skip(-10));break;case"ArrowRight":r.canSeek&&(e.preventDefault(),o.skip(10));break;case"ArrowUp":r.canChangeVolume&&(e.preventDefault(),o.setVolume((e=>e+.05)));break;case"ArrowDown":r.canChangeVolume&&(e.preventDefault(),o.setVolume((e=>e-.05)));break;case"m":r.canMute&&(e.preventDefault(),o.toggleMute());break;case"f":r.canFullscreen&&(e.preventDefault(),o.toggleFullscreen());break;case"p":r.canPictureInPicture&&(e.preventDefault(),o.togglePiP());break;case"r":case"l":r.canLoop&&(e.preventDefault(),a.toggleLoop());break;case"s":r.canShuffle&&(e.preventDefault(),a.toggleShuffle())}},n=void 0===t?document:t.current;return n&&r.canControlWithKeyboard&&n.addEventListener("keydown",e),()=>null==n?void 0:n.removeEventListener("keydown",e)}),[t,o,a,r.canControlWithKeyboard,r.canPause,r.canSeek,r.canMute,r.canChangeVolume,r.canFullscreen,r.canPictureInPicture,r.canLoop,r.canShuffle])},je=(t,r)=>{const{breakpoints:o}=ke(),a=y(o,"object"!=typeof t||Array.isArray(t)?[]:Object.keys(t)),[n]=Ce();return e.useMemo((()=>{var e;const o=null!=t?t:r,l="object"!=typeof o||Array.isArray(o)?o:a?o[a]:Object.values(o)[0],i=Array.isArray(l)?null===(e=l.find((e=>Array.isArray(e)&&e[0]===(null==n?void 0:n.type))))||void 0===e?void 0:e[1]:l;return null!=i?i:r}),[t,r,n,a])},ze=["auto","video","artwork","vinyl","controls","artwork-mini","vinyl-mini"],Re=()=>{const[t]=Ce(),{playerMode:r}=ke(),o=je(r,"auto");return e.useMemo((()=>{if("auto"===o){if("video"===(null==t?void 0:t.type))return"video";if("audio"===(null==t?void 0:t.type))return"artwork"}else if(ze.includes(o))return o;return"artwork"}),[o,null==t?void 0:t.type])},Ze=["1:1","2:1","1:2","3:1","1:3","2:3","3:2","4:3","3:4","16:9","9:16","21:9","9:21"],Ie=Ze.reduce(((e,t)=>{const[r,o]=t.split(":");return e[t]=`${r}/${o}`,e}),{});const Fe=()=>{const{aspectRatio:e}=ke(),t=Re(),r=je(e,"stretch");return"auto"===r||"stretch"===r||Ze.includes(r)&&"video"===t?r:"stretch"},$e=()=>{const{controls:t,breakpoints:r}=ke(),o=y(r,"object"!=typeof t||Array.isArray(t)?[]:Object.keys(t));return e.useMemo((()=>{const e=t||[];return("object"!=typeof e||Array.isArray(e)?e:o?e[o]:Object.values(e)[0])||[]}),[t,o])},De=()=>{const{playerBackground:e}=ke();return je(e,"none")};function Oe(e){const{Component:t}=e;return o.default.createElement(t,null)}var Be=o.default.memo(Oe);function Ve(e,t,r){return e(r={path:t,exports:{},require:function(e,t){return function(){throw new Error("Dynamic requires are not currently supported by @rollup/plugin-commonjs")}
/**
* @license React
* react-is.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.
*/(null==t&&r.path)}},r.exports),r.exports}var Ye,qe=Symbol.for("react.element"),Xe=Symbol.for("react.portal"),Ke=Symbol.for("react.fragment"),We=Symbol.for("react.strict_mode"),He=Symbol.for("react.profiler"),Ue=Symbol.for("react.provider"),Je=Symbol.for("react.context"),Ge=Symbol.for("react.server_context"),_e=Symbol.for("react.forward_ref"),Qe=Symbol.for("react.suspense"),et=Symbol.for("react.suspense_list"),tt=Symbol.for("react.memo"),rt=Symbol.for("react.lazy"),ot=Symbol.for("react.offscreen");function at(e){if("object"==typeof e&&null!==e){var t=e.$$typeof;switch(t){case qe:switch(e=e.type){case Ke:case He:case We:case Qe:case et:return e;default:switch(e=e&&e.$$typeof){case Ge:case Je:case _e:case rt:case tt:case Ue:return e;default:return t}}case Xe:return t}}}Ye=Symbol.for("react.module.reference");var nt={ContextConsumer:Je,ContextProvider:Ue,Element:qe,ForwardRef:_e,Fragment:Ke,Lazy:rt,Memo:tt,Portal:Xe,Profiler:He,StrictMode:We,Suspense:Qe,SuspenseList:et,isAsyncMode:function(){return!1},isConcurrentMode:function(){return!1},isContextConsumer:function(e){return at(e)===Je},isContextProvider:function(e){return at(e)===Ue},isElement:function(e){return"object"==typeof e&&null!==e&&e.$$typeof===qe},isForwardRef:function(e){return at(e)===_e},isFragment:function(e){return at(e)===Ke},isLazy:function(e){return at(e)===rt},isMemo:function(e){return at(e)===tt},isPortal:function(e){return at(e)===Xe},isProfiler:function(e){return at(e)===He},isStrictMode:function(e){return at(e)===We},isSuspense:function(e){return at(e)===Qe},isSuspenseList:function(e){return at(e)===et},isValidElementType:function(e){return"string"==typeof e||"function"==typeof e||e===Ke||e===He||e===We||e===Qe||e===et||e===ot||"object"==typeof e&&null!==e&&(e.$$typeof===rt||e.$$typeof===tt||e.$$typeof===Ue||e.$$typeof===Je||e.$$typeof===_e||e.$$typeof===Ye||void 0!==e.getModuleId)},typeOf:at},lt=(Ve((function(e,t){0})),Ve((function(e){e.exports=nt})));var it='<?xml version="1.0" encoding="UTF-8" standalone="no"?>\n<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">\n<svg width="100%" height="100%" viewBox="0 0 416 401" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xml:space="preserve" xmlns:serif="http://www.serif.com/" style="fill-rule:evenodd;clip-rule:evenodd;stroke-linejoin:round;stroke-miterlimit:2;">\n <path id="airplay-alt" d="M272,400.076L144,400.076C132.249,400.027 122.608,390.345 122.608,378.594C122.608,373.93 124.127,369.391 126.933,365.666L190.933,280.61C194.959,275.242 201.29,272.076 208,272.076C214.71,272.076 221.041,275.242 225.067,280.61L289.067,365.666C291.873,369.391 293.392,373.93 293.392,378.594C293.392,390.345 283.751,400.027 272,400.076ZM285.995,226.828C287.376,220.672 288.092,214.385 288.128,208.076C288.128,164.19 252.015,128.076 208.128,128.076C164.241,128.076 128.128,164.19 128.128,208.076C128.165,214.385 128.88,220.672 130.261,226.828C131.923,234.072 138.424,239.251 145.856,239.251C154.634,239.251 161.856,232.028 161.856,223.251C161.856,222.181 161.749,221.114 161.536,220.066C160.6,216.135 160.085,212.116 160,208.076C160,181.744 181.668,160.076 208,160.076C234.332,160.076 256,181.744 256,208.076C255.978,212.109 255.528,216.128 254.656,220.066C252.808,228.637 258.333,237.213 266.901,239.074C268.022,239.321 269.167,239.442 270.315,239.436C277.809,239.427 284.342,234.153 285.931,226.828L285.995,226.828ZM326.528,290.124C343.087,266.096 351.957,237.593 351.957,208.411C351.957,129.415 286.953,64.411 207.957,64.411C128.961,64.411 63.957,129.415 63.957,208.411C63.957,237.593 72.828,266.096 89.387,290.124C92.372,294.451 97.304,297.04 102.56,297.04C111.34,297.04 118.564,289.816 118.564,281.036C118.564,277.79 117.577,274.62 115.733,271.948C102.856,253.26 95.957,231.093 95.957,208.397C95.957,146.956 146.516,96.397 207.957,96.397C269.399,96.397 319.957,146.956 319.957,208.397C319.957,231.093 313.059,253.26 300.181,271.948C298.338,274.62 297.351,277.79 297.351,281.036C297.351,289.816 304.575,297.04 313.355,297.04C318.611,297.04 323.543,294.451 326.528,290.124ZM365.077,344.034C397.803,306.249 415.829,257.901 415.829,207.915C415.829,93.856 321.973,0 207.915,0C93.856,-0 0,93.856 0,207.915C0,207.969 0,208.022 0,208.076C-0.039,258.044 18.046,306.369 50.88,344.034C53.918,347.518 58.321,349.521 62.944,349.521C71.724,349.521 78.949,342.296 78.949,333.516C78.949,329.651 77.548,325.913 75.008,322.999C47.41,291.056 32.213,250.221 32.213,208.007C32.213,111.515 111.615,32.113 208.107,32.113C304.599,32.113 384,111.515 384,208.007C384,208.03 384,208.053 384,208.076C384.036,250.314 368.748,291.162 340.992,322.999C338.452,325.913 337.051,329.651 337.051,333.516C337.051,342.296 344.276,349.521 353.056,349.521C357.679,349.521 362.082,347.518 365.12,344.034L365.077,344.034Z" style="fill-rule:nonzero;"/>\n</svg>\n';function st(e){const[t,r]=function(e){if(!e||"string"!=typeof e)return[0,0];const t=e.match(/viewBox="([^"]*)"/);if(!t)return[0,0];const[r,o]=t[1].split(" ").slice(2).map((e=>parseInt(e)));return[r,o]}(e);return{width:t,height:r,paths:function(e){if(!e||"string"!=typeof e)return[];const t=e.match(/<path( .*)?\/>/g);return t?t.reduce(((e,t)=>{const r=t.match(/ d="([^"]*)"/);return r&&r[1]?(e.push(r[1]),e):e}),[]):[]}(e)}}function ct(e){const{className:t,svg:r,...n}=e,{width:l,height:i,paths:s}=st(r);return o.default.createElement("svg",a({className:t,viewBox:`0 0 ${l} ${i}`},n),s.map(((e,t)=>o.default.createElement("path",{key:t,d:e,fill:"currentColor"}))))}const ut={xs:2,sm:4,md:6,lg:8,xl:10};function dt(e){const{color:t,size:r="md"}=e;return o.default.createElement("div",{className:l(`w-${ut[r]} h-${ut[r]}`)},o.default.createElement(ct,{svg:'<?xml version="1.0" encoding="UTF-8" standalone="no"?>\n<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">\n<svg width="100%" height="100%" viewBox="0 0 486 441" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xml:space="preserve" xmlns:serif="http://www.serif.com/" style="fill-rule:evenodd;clip-rule:evenodd;stroke-linejoin:round;stroke-miterlimit:2;">\n <path d="M476.099,331.325L305.899,36.525C278.099,-12.175 207.799,-12.175 180.099,36.525L9.799,331.325C-18.001,380.025 16.599,440.525 72.699,440.525L412.599,440.525C468.699,440.525 503.899,379.425 476.099,331.325ZM242.899,375.125C228.099,375.125 215.799,362.825 215.799,348.025C215.799,333.225 228.099,320.925 242.899,320.925C257.699,320.925 269.999,333.225 269.399,348.725C270.099,362.825 257.099,375.125 242.899,375.125ZM267.599,199.925C266.399,220.925 265.099,241.825 263.899,262.825C263.299,269.625 263.299,275.825 263.299,282.525C262.699,293.625 253.999,302.225 242.899,302.225C231.799,302.225 223.199,294.225 222.499,283.125C220.699,250.425 218.799,218.325 216.999,185.625C216.399,177.025 215.799,168.325 215.099,159.725C215.099,145.525 223.099,133.825 236.099,130.125C249.099,127.025 261.999,133.225 267.599,145.525C269.499,149.825 270.099,154.125 270.099,159.125C269.499,172.825 268.199,186.425 267.599,199.925Z" style="fill-rule:nonzero;"/>\n</svg>\n',color:t}))}const mt={xs:2,sm:4,md:6,lg:8,xl:10};function pt(e){const{color:t,size:r="md"}=e;return o.default.createElement("div",{className:l("grid grid-cols-2 animate-spin",`w-${mt[r]} h-${mt[r]}`,{"gap-1":"xs"===r||"sm"===r,"gap-2":"md"===r||"lg"===r,"gap-3":"xl"===r})},Array.from({length:4}).map(((e,r)=>o.default.createElement("div",{key:r,className:l("rounded-full",{"bg-controls-color":!t}),style:{backgroundColor:t}}))))}const ft={xs:2,sm:4,md:6,lg:8,xl:10},vt={xs:1,sm:3,md:5,lg:6,xl:9},wt={xs:"xs",sm:"xs",md:"sm",lg:"sm",xl:"md"};function gt(e,t){const{controlKey:r,label:n,icon:i,size:s="md",loading:c=!1,error:u=!1,active:d,...m}=e,p=xe(),f=`w-${ft[s]} h-${ft[s]}`,v=`w-${vt[s]} h-${vt[s]}`,w=r&&p[r]?p[r]:void 0;return u?o.default.createElement("div",{className:l("flex items-center justify-center",f)},o.default.createElement(dt,{color:w||(u?p.errorColor:p.controlsColor),size:s})):c?o.default.createElement("div",{className:l("flex items-center justify-center opacity-50",f)},o.default.createElement(pt,{color:w,size:wt[s]})):o.default.createElement("button",a({},m,{ref:t,className:l("scale-100 transition",!i&&{"rounded-full px-2 text-sm font-bold uppercase":!0,"bg-controls-color text-controls-bg":!w,"hover:bg-accent-color":!w&&!m.disabled},i&&{"text-center":!0,"text-controls-color":!w&&!d,"hover:text-accent-color":!w&&!m.disabled&&!d,"bg-controls-color text-controls-bg":!w&&d,"hover:bg-accent-color":!w&&!m.disabled&&d,"p-0.5 rounded":d},{"hover:scale-105":!m.disabled,"opacity-50":m.disabled||!1===d&&!i},i&&f,m.className),title:i?n:void 0,style:w?{...m.style,[i&&!d?"color":"background"]:w}:m.style}),i&&("string"==typeof i?o.default.createElement(ct,{className:l("svg-icon",d?v:f),svg:i}):i),!i&&n)}var yt=o.default.memo(o.default.forwardRef(gt));function ht(e){var t;const[r,n]=o.default.useState(!1),{canRemotePlay:l}=ke(),{node:i}=Te(),{isPlaying:s}=Le(),{state:c,isAvailable:u,requestRemotePlayback:d}=j(null!==(t=null==i?void 0:i.current)&&void 0!==t?t:null);return o.default.useEffect((()=>{s&&n(!0)}),[s]),u&&l?o.default.createElement(yt,a({},e,{id:"rmp-controls-cast",controlKey:"cast",size:"sm","aria-label":"disconnected"===c?"Stream to a remote device":"Stop streaming to a remote device",icon:it,onClick:d,active:"connected"===c,disabled:"connecting"===c||"disconnected"===c&&!r,title:r?void 0:"You need to start the player before streaming to a remote device"})):null}function bt(e){var t;const{canAirPlay:r}=ke(),{node:n}=Te(),{isActive:l,isAvailable:i,airPlayAPI:s}=A(null!==(t=null==n?void 0:n.current)&&void 0!==t?t:null);return i?r?o.default.createElement(yt,a({},e,{id:"rmp-controls-airplay",controlKey:"airplay",size:"sm","aria-label":l?"Stop streaming to AirPlay device":"Stream