tiny-essentials 1.28.3 → 1.28.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/changelog/1/28/4.md +4 -0
- package/changelog/1/28/5.md +31 -0
- package/dist/v1/TinyBasicsEs.min.js +1 -1
- package/dist/v1/TinyEssentials.min.js +1 -1
- package/dist/v1/TinyMediaPlayer.min.js +1 -1
- package/dist/v1/TinyTimeout.min.js +1 -1
- package/dist/v1/TinyUploadClicker.min.js +1 -1
- package/dist/v1/basics/index.cjs +4 -0
- package/dist/v1/basics/index.d.mts +3 -2
- package/dist/v1/basics/index.mjs +3 -2
- package/dist/v1/basics/mediaContent.cjs +1 -0
- package/dist/v1/basics/mediaContent.d.mts +4 -0
- package/dist/v1/basics/mediaContent.mjs +1 -0
- package/dist/v1/basics/objChecker.cjs +16 -0
- package/dist/v1/basics/objChecker.d.mts +12 -0
- package/dist/v1/basics/objChecker.mjs +14 -0
- package/dist/v1/basics/objFilter.cjs +21 -30
- package/dist/v1/basics/objFilter.d.mts +0 -2
- package/dist/v1/basics/objFilter.mjs +21 -30
- package/dist/v1/basics/promiseUtils.cjs +101 -0
- package/dist/v1/basics/promiseUtils.d.mts +31 -0
- package/dist/v1/basics/promiseUtils.mjs +89 -0
- package/dist/v1/index.cjs +4 -0
- package/dist/v1/index.d.mts +3 -2
- package/dist/v1/index.mjs +3 -2
- package/dist/v1/libs/TinyMediaPlayer/HtmlAudio.cjs +268 -0
- package/dist/v1/libs/TinyMediaPlayer/HtmlAudio.d.mts +118 -0
- package/dist/v1/libs/TinyMediaPlayer/HtmlAudio.mjs +237 -0
- package/dist/v1/libs/TinyMediaPlayer/HtmlVideo.cjs +265 -0
- package/dist/v1/libs/TinyMediaPlayer/HtmlVideo.d.mts +118 -0
- package/dist/v1/libs/TinyMediaPlayer/HtmlVideo.mjs +234 -0
- package/dist/v1/libs/TinyMediaPlayer/Youtube.cjs +671 -0
- package/dist/v1/libs/TinyMediaPlayer/Youtube.d.mts +259 -0
- package/dist/v1/libs/TinyMediaPlayer/Youtube.mjs +597 -0
- package/dist/v1/libs/TinyMediaPlayer/docs/YouTubePlayer.cjs +546 -0
- package/dist/v1/libs/TinyMediaPlayer/docs/YouTubePlayer.d.mts +657 -0
- package/dist/v1/libs/TinyMediaPlayer/docs/YouTubePlayer.mjs +480 -0
- package/dist/v1/libs/TinyMediaPlayer/index.cjs +165 -0
- package/dist/v1/libs/TinyMediaPlayer/index.d.mts +102 -0
- package/dist/v1/libs/TinyMediaPlayer/index.mjs +144 -0
- package/dist/v1/libs/TinyMediaPlayer.cjs +589 -103
- package/dist/v1/libs/TinyMediaPlayer.d.mts +150 -65
- package/dist/v1/libs/TinyMediaPlayer.mjs +535 -93
- package/dist/v1/libs/TinyTimeout.cjs +4 -14
- package/dist/v1/libs/TinyTimeout.d.mts +1 -0
- package/dist/v1/libs/TinyTimeout.mjs +4 -13
- package/docs/v1/basics/mediaContent.md +1 -1
- package/docs/v1/basics/objChecker.md +13 -0
- package/docs/v1/basics/promiseUtils.md +32 -0
- package/docs/v1/libs/TinyMediaPlayer.md +239 -32
- package/docs/v1/libs/TinyTimeout.md +1 -14
- package/package.json +21 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
(()=>{"use strict";var e={7(e){var t,r="object"==typeof Reflect?Reflect:null,n=r&&"function"==typeof r.apply?r.apply:function(e,t,r){return Function.prototype.apply.call(e,t,r)};t=r&&"function"==typeof r.ownKeys?r.ownKeys:Object.getOwnPropertySymbols?function(e){return Object.getOwnPropertyNames(e).concat(Object.getOwnPropertySymbols(e))}:function(e){return Object.getOwnPropertyNames(e)};var i=Number.isNaN||function(e){return e!=e};function o(){o.init.call(this)}e.exports=o,e.exports.once=function(e,t){return new Promise(function(r,n){function i(r){e.removeListener(t,o),n(r)}function o(){"function"==typeof e.removeListener&&e.removeListener("error",i),r([].slice.call(arguments))}f(e,t,o,{once:!0}),"error"!==t&&function(e,t){"function"==typeof e.on&&f(e,"error",t,{once:!0})}(e,i)})},o.EventEmitter=o,o.prototype._events=void 0,o.prototype._eventsCount=0,o.prototype._maxListeners=void 0;var s=10;function a(e){if("function"!=typeof e)throw new TypeError('The "listener" argument must be of type Function. Received type '+typeof e)}function l(e){return void 0===e._maxListeners?o.defaultMaxListeners:e._maxListeners}function u(e,t,r,n){var i,o,s,u;if(a(r),void 0===(o=e._events)?(o=e._events=Object.create(null),e._eventsCount=0):(void 0!==o.newListener&&(e.emit("newListener",t,r.listener?r.listener:r),o=e._events),s=o[t]),void 0===s)s=o[t]=r,++e._eventsCount;else if("function"==typeof s?s=o[t]=n?[r,s]:[s,r]:n?s.unshift(r):s.push(r),(i=l(e))>0&&s.length>i&&!s.warned){s.warned=!0;var h=new Error("Possible EventEmitter memory leak detected. "+s.length+" "+String(t)+" listeners added. Use emitter.setMaxListeners() to increase limit");h.name="MaxListenersExceededWarning",h.emitter=e,h.type=t,h.count=s.length,u=h,console&&console.warn&&console.warn(u)}return e}function h(){if(!this.fired)return this.target.removeListener(this.type,this.wrapFn),this.fired=!0,0===arguments.length?this.listener.call(this.target):this.listener.apply(this.target,arguments)}function c(e,t,r){var n={fired:!1,wrapFn:void 0,target:e,type:t,listener:r},i=h.bind(n);return i.listener=r,n.wrapFn=i,i}function d(e,t,r){var n=e._events;if(void 0===n)return[];var i=n[t];return void 0===i?[]:"function"==typeof i?r?[i.listener||i]:[i]:r?function(e){for(var t=new Array(e.length),r=0;r<t.length;++r)t[r]=e[r].listener||e[r];return t}(i):y(i,i.length)}function p(e){var t=this._events;if(void 0!==t){var r=t[e];if("function"==typeof r)return 1;if(void 0!==r)return r.length}return 0}function y(e,t){for(var r=new Array(t),n=0;n<t;++n)r[n]=e[n];return r}function f(e,t,r,n){if("function"==typeof e.on)n.once?e.once(t,r):e.on(t,r);else{if("function"!=typeof e.addEventListener)throw new TypeError('The "emitter" argument must be of type EventEmitter. Received type '+typeof e);e.addEventListener(t,function i(o){n.once&&e.removeEventListener(t,i),r(o)})}}Object.defineProperty(o,"defaultMaxListeners",{enumerable:!0,get:function(){return s},set:function(e){if("number"!=typeof e||e<0||i(e))throw new RangeError('The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received '+e+".");s=e}}),o.init=function(){void 0!==this._events&&this._events!==Object.getPrototypeOf(this)._events||(this._events=Object.create(null),this._eventsCount=0),this._maxListeners=this._maxListeners||void 0},o.prototype.setMaxListeners=function(e){if("number"!=typeof e||e<0||i(e))throw new RangeError('The value of "n" is out of range. It must be a non-negative number. Received '+e+".");return this._maxListeners=e,this},o.prototype.getMaxListeners=function(){return l(this)},o.prototype.emit=function(e){for(var t=[],r=1;r<arguments.length;r++)t.push(arguments[r]);var i="error"===e,o=this._events;if(void 0!==o)i=i&&void 0===o.error;else if(!i)return!1;if(i){var s;if(t.length>0&&(s=t[0]),s instanceof Error)throw s;var a=new Error("Unhandled error."+(s?" ("+s.message+")":""));throw a.context=s,a}var l=o[e];if(void 0===l)return!1;if("function"==typeof l)n(l,this,t);else{var u=l.length,h=y(l,u);for(r=0;r<u;++r)n(h[r],this,t)}return!0},o.prototype.addListener=function(e,t){return u(this,e,t,!1)},o.prototype.on=o.prototype.addListener,o.prototype.prependListener=function(e,t){return u(this,e,t,!0)},o.prototype.once=function(e,t){return a(t),this.on(e,c(this,e,t)),this},o.prototype.prependOnceListener=function(e,t){return a(t),this.prependListener(e,c(this,e,t)),this},o.prototype.removeListener=function(e,t){var r,n,i,o,s;if(a(t),void 0===(n=this._events))return this;if(void 0===(r=n[e]))return this;if(r===t||r.listener===t)0===--this._eventsCount?this._events=Object.create(null):(delete n[e],n.removeListener&&this.emit("removeListener",e,r.listener||t));else if("function"!=typeof r){for(i=-1,o=r.length-1;o>=0;o--)if(r[o]===t||r[o].listener===t){s=r[o].listener,i=o;break}if(i<0)return this;0===i?r.shift():function(e,t){for(;t+1<e.length;t++)e[t]=e[t+1];e.pop()}(r,i),1===r.length&&(n[e]=r[0]),void 0!==n.removeListener&&this.emit("removeListener",e,s||t)}return this},o.prototype.off=o.prototype.removeListener,o.prototype.removeAllListeners=function(e){var t,r,n;if(void 0===(r=this._events))return this;if(void 0===r.removeListener)return 0===arguments.length?(this._events=Object.create(null),this._eventsCount=0):void 0!==r[e]&&(0===--this._eventsCount?this._events=Object.create(null):delete r[e]),this;if(0===arguments.length){var i,o=Object.keys(r);for(n=0;n<o.length;++n)"removeListener"!==(i=o[n])&&this.removeAllListeners(i);return this.removeAllListeners("removeListener"),this._events=Object.create(null),this._eventsCount=0,this}if("function"==typeof(t=r[e]))this.removeListener(e,t);else if(void 0!==t)for(n=t.length-1;n>=0;n--)this.removeListener(e,t[n]);return this},o.prototype.listeners=function(e){return d(this,e,!0)},o.prototype.rawListeners=function(e){return d(this,e,!1)},o.listenerCount=function(e,t){return"function"==typeof e.listenerCount?e.listenerCount(t):p.call(e,t)},o.prototype.listenerCount=p,o.prototype.eventNames=function(){return this._eventsCount>0?t(this._events):[]}}};const t={};function r(n){const i=t[n];if(void 0!==i)return i.exports;const o=t[n]={exports:{}};return e[n](o,o.exports,r),o.exports}r.d=(e,t)=>{if(Array.isArray(t))for(var n=0;n<t.length;){var i=t[n++],o=t[n++];r.o(e,i)?0===o&&n++:0===o?Object.defineProperty(e,i,{enumerable:!0,value:t[n++]}):Object.defineProperty(e,i,{enumerable:!0,get:o})}else for(var i in t)r.o(t,i)&&!r.o(e,i)&&Object.defineProperty(e,i,{enumerable:!0,get:t[i]})},r.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t);let n={};r.d(n,{TinyMediaPlayer:()=>w});var i=r(7);const o=(e,t)=>{if("string"!=typeof t)throw new TypeError('Expected "name" to be a string.');if("string"!=typeof e)throw new TypeError(`Expected "${t}" to be a string, but received ${typeof e}.`)},s=(e,t)=>{if("string"!=typeof t)throw new TypeError('Expected "name" to be a string.');if("function"!=typeof e)throw new TypeError(`Expected "${t}" to be a function, but received ${typeof e}.`)},a=(e,t)=>{if("string"!=typeof t)throw new TypeError('Expected "name" to be a string.');if("object"!=typeof e||null===e||Array.isArray(e))throw new TypeError(`Expected "${t}" to be a plain object, but received ${null===e?"null":Array.isArray(e)?"array":typeof e}.`)},l=new Map;class u extends Error{constructor(e,t,r){if(o(e,"message"),o(t,"url"),"string"!=typeof r)throw new TypeError(`Expected "stage" to be a string, but received ${typeof r}.`);super(e),this.name="MediaLoadingError",this.url=t,this.stage=r}}const h=async e=>{o(e,"str");const t=(new TextEncoder).encode(e),r=await crypto.subtle.digest("SHA-1",t);return Array.from(new Uint8Array(r)).map(e=>e.toString(16).padStart(2,"0")).join("").substring(0,8)},c=(e,t="image/jpeg")=>{if(!(e instanceof Uint8Array)&&"string"!=typeof e)throw new TypeError(`Expected "data" to be an instance of Uint8Array or a string, but received ${typeof e}.`);o(t,"format");const r=e=>{const t=URL.createObjectURL(e),r=l.get(t);return l.set(t,"number"==typeof r?r+1:1),t};if(e instanceof Uint8Array)return r(new Blob([e],{type:t}));if("string"==typeof e&&e.startsWith("data:")){const n=e.split(",")[1],i=atob(n),o=new Uint8Array(i.length);for(let e=0;e<i.length;e++)o[e]=i.charCodeAt(e);return r(new Blob([o],{type:t}))}return"string"==typeof e?e:""},d=(e,t)=>{if(a(e,"common"),"boolean"!=typeof t)throw new TypeError('Expected "isPartial" to be a boolean.');const r=e=>t&&void 0===e,n=e=>r(e)||"string"==typeof e||null===e,i=(e,t)=>(s(t,"valueValidator"),!!r(e)||!(!Array.isArray(e)||!e.every(t)));if(!n(e.title))throw new TypeError('Invalid metadata: "title" must be a string or null.');if(!n(e.album))throw new TypeError('Invalid metadata: "album" must be a string or null.');if(!n(e.albumartist))throw new TypeError('Invalid metadata: "albumartist" must be a string or null.');if(!n(e.artist))throw new TypeError('Invalid metadata: "artist" must be a string or null.');if(l=e.year,!r(l)&&"number"!=typeof l&&null!==l)throw new TypeError('Invalid metadata: "year" must be a number or null.');var l;if(!i(e.albumartists,e=>"string"==typeof e))throw new TypeError('Invalid metadata: "albumartists" must be an array of string.');if(!i(e.genre,e=>"string"==typeof e))throw new TypeError('Invalid metadata: "genre" must be an array of string.');if(!i(e.label,e=>"string"==typeof e))throw new TypeError('Invalid metadata: "label" must be an array of string.');if(!i(e.composer,e=>"string"==typeof e))throw new TypeError('Invalid metadata: "composer" must be an array of string.');if(!i(e.artists,e=>"string"==typeof e))throw new TypeError('Invalid metadata: "artists" must be an array of string.');if(!i(e.picture,e=>e&&"object"==typeof e&&(void 0===e.description||"string"==typeof e.description)&&(void 0===e.name||"string"==typeof e.name)&&(void 0===e.type||"string"==typeof e.type)&&"string"==typeof e.format&&(e.data instanceof Uint8Array||"string"==typeof e.data)))throw new TypeError('Invalid metadata: "picture" must be an array of pictures.');const u=(e,t)=>{if(o(e,"name"),!r(t)){if(null==t)throw new TypeError(`Invalid metadata: "${e}" is required.`);if("object"!=typeof t)throw new TypeError(`Invalid metadata: "${e}" must be an object or null.`);if("number"!=typeof t.no&&null!==t.no)throw new TypeError(`Invalid metadata: "${e}.no" must be a number or null.`);if("number"!=typeof t.of&&null!==t.of)throw new TypeError(`Invalid metadata: "${e}.of" must be a number or null.`)}};u("disk",e.disk),u("track",e.track)},p=e=>(a(e,"common"),d(e,!1)),y=e=>{if(e)throw new Error("This TinyMediaPlayer instance has been destroyed and can no longer be used.")};class f{constructor(){if(new.target===f)throw new Error("BaseMediaAdapter is an abstract class and cannot be instantiated directly.")}canHandle(e){throw new Error('Method "canHandle" must be implemented by the subclass.')}async play(e){throw new Error('Method "play" must be implemented by the subclass.')}async pause(){throw new Error('Method "pause" must be implemented by the subclass.')}async stop(){throw new Error('Method "stop" must be implemented by the subclass.')}async seek(e){throw new Error('Method "seek" must be implemented by the subclass.')}getCurrentTime(){throw new Error('Method "getCurrentTime" must be implemented by the subclass.')}setVolume(e){throw new Error('Method "setVolume" must be implemented by the subclass.')}}class m extends i.EventEmitter{static BaseMediaAdapter=f;static#e="Unknown Artist";static get unknownArtist(){return m.#e}static set unknownArtist(e){if("string"!=typeof e&&"function"!=typeof e)throw new TypeError("unknownArtist must have an string or function.");m.#e=e}static async parseContent(e,t,r,n,i){return(async(e,t={},r={},n=e=>{if(!(e instanceof Blob))throw new TypeError('Expected "data" to be a Blob.');return new Promise((e,t)=>t(new TypeError("parseFile library not found.")))},i={},l="null")=>{if("string"!=typeof e&&!(e instanceof HTMLMediaElement))throw new TypeError("Source must be a string or an HTMLMediaElement.");if(a(t,"defaultMetadata"),a(r,"metadata"),s(n,"parseFile"),a(i,"callbacks"),i.onProgress&&"function"!=typeof i.onProgress)throw new TypeError("callbacks.onProgress must be a function.");if(i.onError&&"function"!=typeof i.onError)throw new TypeError("callbacks.onError must be a function.");if("string"!=typeof l&&"function"!=typeof l)throw new TypeError("unknownArtist must be a string or a function returning a string.");let p,y="";const f=(t,r)=>{if(o(t,"stage"),void 0!==r&&!(r instanceof Event))throw new TypeError('Expected "event" to be an Event or undefined.');i.onProgress&&i.onProgress({event:r,status:"loading",stage:t,url:y||(e instanceof HTMLMediaElement?e.src:"unknown")})},m=(t,r)=>{if(!(t instanceof Error))throw new TypeError('Expected "error" to be an Error.');o(r,"stage"),i.onError&&i.onError({error:t,url:y||(e instanceof HTMLMediaElement?e.src:"unknown"),stage:r})};try{f("INITIALIZING"),"string"==typeof e?(y=e,p=new Audio(y)):(p=e,y=p.src);try{await new Promise((e,t)=>{const r=e=>f("DOWNLOADING",e),n=()=>{o(),e(void 0)},i=e=>{o(),t(new Error(`HTMLMediaElement failed to load: ${e.message||"Unknown error"}`))},o=()=>{p.removeEventListener("progress",r),p.removeEventListener("loadedmetadata",n),p.removeEventListener("error",i)};p.addEventListener("progress",r),p.addEventListener("loadedmetadata",n),p.addEventListener("error",i),p.readyState>=1&&(o(),e(void 0))}),f("METADATA_LOADED")}catch(e){throw new u(e instanceof Error?e.message:"UNKNOWN ERROR",y,"METADATA")}const w={id:r.id||await h(y),duration:Math.floor(1e3*p.duration),url:y,weight:r.weight??1};let g={};f("EXTRACTING_ID3");try{g=await(async(e,t)=>{o(e,"url"),s(t,"parseFile");try{const r=await fetch(e);if(!r.ok)throw new Error(`Failed to fetch audio file: ${r.status} ${r.statusText}`);const n=await r.blob(),i=await t(n);if(!i||"object"!=typeof i.common)throw new TypeError('Invalid metadata: "common" property is missing or not an object.');const o=i.common;return(e=>{a(e,"common"),d(e,!0)})(o),{title:o?.title??null,album:o?.album??null,albumartist:o?.albumartist??null,albumartists:o?.albumartists??[],genre:o?.genre??[],label:o?.label??[],composer:o?.composer??[],year:o?.year??null,artist:o?.artist??null,artists:o?.artists??[],disk:o?.disk?{no:o.disk.no,of:o.disk.of}:{no:null,of:null},track:o?.track?{no:o.track.no,of:o.track.of}:{no:null,of:null},picture:o?.picture?.map(e=>({...e,data:c(e.data,e.format)}))??[]}}catch(e){throw e}})(y,n)}catch(e){m(e instanceof Error?e:new Error("Unknown Error"),"ID3"),console.warn(`[TinyAudioUtils] ID3 extraction failed for ${y}. Falling back to filename.`)}const v=e=>{o(e,"url");try{return(e.split(/[?#]/)[0].split("/").pop()??"").replace(/\.[^/.]+$/,"")||"Unknown Track"}catch{return"Unknown Track"}},b={...w,...t,...g,...r,title:g.title||r.title||v(y),artist:g.artist||r.artist||("string"==typeof l?l:String(l()))};return i.onProgress&&i.onProgress({status:"success",stage:"COMPLETE",url:y}),b}catch(e){if(e instanceof u)throw e;{const t=new u(e instanceof Error?e.message:"UNKNOWN ERROR",y,"INITIALIZING");throw m(t,"INITIALIZING"),t}}})(e,t,r,n,i,m.#e)}#t=!1;get destroyed(){return this.#t}#r=new Map;#n=[];#i=-1;#o="NONE";#s=!1;#a=!1;#l=1;#u;#h;constructor(e={}){super(),this.#u=Boolean(e.persistVolume),this.#h="string"==typeof e.volumeStorageKey?e.volumeStorageKey:"tiny_media_player_volume",this.#u&&this.#c()}#c(){try{if("undefined"!=typeof window&&window.localStorage){const e=window.localStorage.getItem(this.#h);if(null!==e){const t=parseFloat(e);!isNaN(t)&&t>=0&&t<=1&&(this.#l=t)}}}catch(e){console.warn("[TinyMediaPlayer] Failed to read volume from localStorage.",e)}}#d(){try{this.#u&&"undefined"!=typeof window&&window.localStorage&&window.localStorage.setItem(this.#h,this.#l.toString())}catch(e){console.warn("[TinyMediaPlayer] Failed to save volume to localStorage.",e)}}_getWeightedRandomIndex(){if(0===this.#n.length)return-1;if(1===this.#n.length)return 0;let e=0;for(let t=0;t<this.#n.length;t++){if(t===this.#i)continue;const r=this.#n[t];e+="number"==typeof r.weight&&r.weight>0?r.weight:1}let t=Math.random()*e;for(let e=0;e<this.#n.length;e++){if(e===this.#i)continue;const r=this.#n[e],n="number"==typeof r.weight&&r.weight>0?r.weight:1;if(t<n)return e;t-=n}return this.#i===this.#n.length-1?0:this.#n.length-1}get playlist(){return y(this.#t),[...this.#n]}set playlist(e){if(y(this.#t),!Array.isArray(e))throw new TypeError("Playlist must be an array of MediaContent objects.");e.forEach(e=>p(e));const t=this.#a;let r=null;if(-1!==this.#i&&this.#n.length>0)try{r=this.#p()}catch(e){}this.#n=e,this.emit("playlistUpdate",this.playlist),0===this.#n.length?this.#i=-1:(this.#i>=this.#n.length||-1===this.#i)&&(this.#i=0),this.emit("trackChange",this.#i),t&&(async()=>{try{r&&await r.stop(),-1!==this.#i&&await this.play()}catch(e){console.warn("[TinyMediaPlayer] Background transition error on playlist update:",e)}})()}get currentIndex(){return y(this.#t),this.#i}set currentIndex(e){if(y(this.#t),"number"!=typeof e)throw new TypeError("Current index must be a number.");if(e<-1||e>=this.#n.length&&this.#n.length>0)throw new RangeError(`Index ${e} is out of bounds for the current playlist.`);if(this.#i===e)return;const t=this.#a;let r=null;if(-1!==this.#i&&this.#n.length>0)try{r=this.#p()}catch(e){}this.#i=e,this.emit("trackChange",this.#i),t&&(async()=>{try{r&&await r.stop(),-1!==this.#i&&await this.play()}catch(e){console.warn("[TinyMediaPlayer] Background transition error on index update:",e)}})()}get loopMode(){return y(this.#t),this.#o}set loopMode(e){y(this.#t);const t=["NONE","TRACK","PLAYLIST"];if(!t.includes(e))throw new TypeError(`Loop mode must be one of: ${t.join(", ")}.`);this.#o=e,this.emit("loopModeChange",this.#o)}get isRandom(){return y(this.#t),this.#s}set isRandom(e){if(y(this.#t),"boolean"!=typeof e)throw new TypeError("Random mode state must be a boolean.");this.#s=e,this.emit("randomModeChange",this.#s)}get isPlaying(){return y(this.#t),this.#a}get volume(){return y(this.#t),this.#l}set volume(e){if(y(this.#t),"number"!=typeof e)throw new TypeError("Volume must be a number.");if(e<0||e>1)throw new RangeError("Volume must be tightly constrained between 0.0 and 1.0.");if(this.#l=e,this.#d(),this.emit("volumeChange",this.#l),-1!==this.#i&&this.#n.length>0)try{const e=this.#p();e&&e.setVolume(this.#l)}catch(e){}}get persistVolume(){return y(this.#t),this.#u}set persistVolume(e){if(y(this.#t),"boolean"!=typeof e)throw new TypeError("Persist volume parameter must be a boolean.");this.#u=e,e&&this.#d()}get volumeStorageKey(){return y(this.#t),this.#h}set volumeStorageKey(e){if(y(this.#t),"string"!=typeof e)throw new TypeError("Volume storage key must be a string.");if(""===e.trim())throw new TypeError("Volume storage key cannot be an empty string.");const t=this.#h;this.#h=e;try{this.#u&&"undefined"!=typeof window&&window.localStorage&&(window.localStorage.removeItem(t),this.#d())}catch(e){console.warn("[TinyMediaPlayer] Failed to migrate volume storage key.",e)}}registerAdapter(e,t){if(y(this.#t),"string"!=typeof e)throw new TypeError("Adapter ID must be a string.");if(!(t instanceof f))throw new TypeError("Adapter must be an instance of BaseMediaAdapter.");this.#r.set(e,t)}#p(){if(-1===this.#i||0===this.#n.length)return null;const e=this.#n[this.#i];for(const t of this.#r.values())if(t.canHandle(e))return t;throw new Error(`No compatible adapter found for content ID: ${e.id}.`)}addTrack(e){if(y(this.#t),!e||"object"!=typeof e||"string"!=typeof e.url)throw new TypeError("Track content must be a valid MediaContent object containing a URL.");const t={id:"",title:"",artist:"",url:"",duration:0,weight:1,title:null,album:null,albumartist:null,albumartists:[],genre:[],label:[],composer:[],year:null,artist:null,artists:[],disk:{no:null,of:null},track:{no:null,of:null},picture:[],...e};p(t);const r=this.#n.push(t);return-1===this.#i&&(this.#i=0,this.emit("trackChange",this.#i)),this.emit("playlistUpdate",this.playlist),r}existsTrack(e){if(y(this.#t),"number"!=typeof e)throw new TypeError("Index must be a number.");return e>=0&&e<this.#n.length}getTrack(e){if(y(this.#t),"number"!=typeof e)throw new TypeError("Index must be a number.");if(!this.existsTrack(e))throw new RangeError(`Index ${e} is out of bounds for the current playlist.`);return this.#n[e]}async removeTrack(e){if(y(this.#t),"number"!=typeof e)throw new TypeError("Index must be a number.");if(!this.existsTrack(e))throw new RangeError(`Index ${e} is out of bounds for the current playlist.`);e===this.#i?(await this.stop(),this.#n.splice(e,1),0===this.#n.length?this.#i=-1:this.#i>=this.#n.length&&(this.#i=0),this.emit("trackChange",this.#i)):(this.#n.splice(e,1),e<this.#i&&(this.#i-=1,this.emit("trackChange",this.#i))),this.emit("playlistUpdate",this.playlist)}searchTrack(e){if(y(this.#t),"string"!=typeof e&&"function"!=typeof e)throw new TypeError("Search query must be a string or a boolean evaluation function.");const t=[];for(let r=0;r<this.#n.length;r++){const n=this.#n[r];let i=!1;if("function"==typeof e)i=Boolean(e(n));else{const t=e.toLowerCase(),r=n.title&&n.title.toLowerCase().includes(t),o=n.artist&&n.artist.toLowerCase().includes(t),s=n.album&&n.album.toLowerCase().includes(t);i=Boolean(r||o||s)}i&&t.push({track:n,index:r})}return t}async clearPlaylist(){y(this.#t),await this.stop(),this.#n=[],this.#i=-1,this.emit("playlistUpdate",this.playlist),this.emit("trackChange",this.#i)}async play(){y(this.#t);const e=this.#p();e&&(e.setVolume(this.#l),await e.play(this.#n[this.#i]),this.#a=!0,this.emit("play",this.#i))}async pause(){y(this.#t);const e=this.#p();e&&(await e.pause(),this.#a=!1,this.emit("pause",this.#i))}async stop(){y(this.#t);const e=this.#p();e&&(await e.stop(),this.#a=!1,this.emit("stop",this.#i))}async next(){if(y(this.#t),0!==this.#n.length)if(await this.stop(),"TRACK"!==this.#o){if(this.#s)this.#i=this._getWeightedRandomIndex();else{let e=this.#i+1;if(e>=this.#n.length){if("PLAYLIST"!==this.#o)return;e=0}this.#i=e}this.emit("trackChange",this.#i),await this.play()}else await this.play()}async prev(){if(y(this.#t),0!==this.#n.length){if(await this.stop(),this.#s)this.#i=this._getWeightedRandomIndex();else{let e=this.#i-1;if(e<0){if("PLAYLIST"!==this.#o)return;e=this.#n.length-1}this.#i=e}this.emit("trackChange",this.#i),await this.play()}}async seek(e){if(y(this.#t),"number"!=typeof e)throw new TypeError("Seek time must be a number in milliseconds.");if(e<0)throw new RangeError("Seek time cannot be negative.");const t=this.#p();t&&(await t.seek(e),this.emit("seek",e))}async step(e){if(y(this.#t),"number"!=typeof e)throw new TypeError("Step amount must be a number in milliseconds.");const t=this.#p();if(!t)return;let r=t.getCurrentTime()+e;r<0&&(r=0),await this.seek(r)}async destroy(){if(!this.#t){try{this.#a&&await this.stop()}catch(e){console.warn("[TinyMediaPlayer] Non-fatal error during playback termination:",e)}this.#n=[],this.#i=-1,this.#a=!1,this.#r.clear(),this.removeAllListeners(),this.#t=!0}}}const w=m;window.TinyMediaPlayer=n.TinyMediaPlayer})();
|
|
1
|
+
(()=>{"use strict";var e={7(e){var t,r="object"==typeof Reflect?Reflect:null,n=r&&"function"==typeof r.apply?r.apply:function(e,t,r){return Function.prototype.apply.call(e,t,r)};t=r&&"function"==typeof r.ownKeys?r.ownKeys:Object.getOwnPropertySymbols?function(e){return Object.getOwnPropertyNames(e).concat(Object.getOwnPropertySymbols(e))}:function(e){return Object.getOwnPropertyNames(e)};var o=Number.isNaN||function(e){return e!=e};function s(){s.init.call(this)}e.exports=s,e.exports.once=function(e,t){return new Promise(function(r,n){function o(r){e.removeListener(t,s),n(r)}function s(){"function"==typeof e.removeListener&&e.removeListener("error",o),r([].slice.call(arguments))}y(e,t,s,{once:!0}),"error"!==t&&function(e,t){"function"==typeof e.on&&y(e,"error",t,{once:!0})}(e,o)})},s.EventEmitter=s,s.prototype._events=void 0,s.prototype._eventsCount=0,s.prototype._maxListeners=void 0;var i=10;function a(e){if("function"!=typeof e)throw new TypeError('The "listener" argument must be of type Function. Received type '+typeof e)}function l(e){return void 0===e._maxListeners?s.defaultMaxListeners:e._maxListeners}function u(e,t,r,n){var o,s,i,u;if(a(r),void 0===(s=e._events)?(s=e._events=Object.create(null),e._eventsCount=0):(void 0!==s.newListener&&(e.emit("newListener",t,r.listener?r.listener:r),s=e._events),i=s[t]),void 0===i)i=s[t]=r,++e._eventsCount;else if("function"==typeof i?i=s[t]=n?[r,i]:[i,r]:n?i.unshift(r):i.push(r),(o=l(e))>0&&i.length>o&&!i.warned){i.warned=!0;var d=new Error("Possible EventEmitter memory leak detected. "+i.length+" "+String(t)+" listeners added. Use emitter.setMaxListeners() to increase limit");d.name="MaxListenersExceededWarning",d.emitter=e,d.type=t,d.count=i.length,u=d,console&&console.warn&&console.warn(u)}return e}function d(){if(!this.fired)return this.target.removeListener(this.type,this.wrapFn),this.fired=!0,0===arguments.length?this.listener.call(this.target):this.listener.apply(this.target,arguments)}function h(e,t,r){var n={fired:!1,wrapFn:void 0,target:e,type:t,listener:r},o=d.bind(n);return o.listener=r,n.wrapFn=o,o}function p(e,t,r){var n=e._events;if(void 0===n)return[];var o=n[t];return void 0===o?[]:"function"==typeof o?r?[o.listener||o]:[o]:r?function(e){for(var t=new Array(e.length),r=0;r<t.length;++r)t[r]=e[r].listener||e[r];return t}(o):m(o,o.length)}function c(e){var t=this._events;if(void 0!==t){var r=t[e];if("function"==typeof r)return 1;if(void 0!==r)return r.length}return 0}function m(e,t){for(var r=new Array(t),n=0;n<t;++n)r[n]=e[n];return r}function y(e,t,r,n){if("function"==typeof e.on)n.once?e.once(t,r):e.on(t,r);else{if("function"!=typeof e.addEventListener)throw new TypeError('The "emitter" argument must be of type EventEmitter. Received type '+typeof e);e.addEventListener(t,function o(s){n.once&&e.removeEventListener(t,o),r(s)})}}Object.defineProperty(s,"defaultMaxListeners",{enumerable:!0,get:function(){return i},set:function(e){if("number"!=typeof e||e<0||o(e))throw new RangeError('The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received '+e+".");i=e}}),s.init=function(){void 0!==this._events&&this._events!==Object.getPrototypeOf(this)._events||(this._events=Object.create(null),this._eventsCount=0),this._maxListeners=this._maxListeners||void 0},s.prototype.setMaxListeners=function(e){if("number"!=typeof e||e<0||o(e))throw new RangeError('The value of "n" is out of range. It must be a non-negative number. Received '+e+".");return this._maxListeners=e,this},s.prototype.getMaxListeners=function(){return l(this)},s.prototype.emit=function(e){for(var t=[],r=1;r<arguments.length;r++)t.push(arguments[r]);var o="error"===e,s=this._events;if(void 0!==s)o=o&&void 0===s.error;else if(!o)return!1;if(o){var i;if(t.length>0&&(i=t[0]),i instanceof Error)throw i;var a=new Error("Unhandled error."+(i?" ("+i.message+")":""));throw a.context=i,a}var l=s[e];if(void 0===l)return!1;if("function"==typeof l)n(l,this,t);else{var u=l.length,d=m(l,u);for(r=0;r<u;++r)n(d[r],this,t)}return!0},s.prototype.addListener=function(e,t){return u(this,e,t,!1)},s.prototype.on=s.prototype.addListener,s.prototype.prependListener=function(e,t){return u(this,e,t,!0)},s.prototype.once=function(e,t){return a(t),this.on(e,h(this,e,t)),this},s.prototype.prependOnceListener=function(e,t){return a(t),this.prependListener(e,h(this,e,t)),this},s.prototype.removeListener=function(e,t){var r,n,o,s,i;if(a(t),void 0===(n=this._events))return this;if(void 0===(r=n[e]))return this;if(r===t||r.listener===t)0===--this._eventsCount?this._events=Object.create(null):(delete n[e],n.removeListener&&this.emit("removeListener",e,r.listener||t));else if("function"!=typeof r){for(o=-1,s=r.length-1;s>=0;s--)if(r[s]===t||r[s].listener===t){i=r[s].listener,o=s;break}if(o<0)return this;0===o?r.shift():function(e,t){for(;t+1<e.length;t++)e[t]=e[t+1];e.pop()}(r,o),1===r.length&&(n[e]=r[0]),void 0!==n.removeListener&&this.emit("removeListener",e,i||t)}return this},s.prototype.off=s.prototype.removeListener,s.prototype.removeAllListeners=function(e){var t,r,n;if(void 0===(r=this._events))return this;if(void 0===r.removeListener)return 0===arguments.length?(this._events=Object.create(null),this._eventsCount=0):void 0!==r[e]&&(0===--this._eventsCount?this._events=Object.create(null):delete r[e]),this;if(0===arguments.length){var o,s=Object.keys(r);for(n=0;n<s.length;++n)"removeListener"!==(o=s[n])&&this.removeAllListeners(o);return this.removeAllListeners("removeListener"),this._events=Object.create(null),this._eventsCount=0,this}if("function"==typeof(t=r[e]))this.removeListener(e,t);else if(void 0!==t)for(n=t.length-1;n>=0;n--)this.removeListener(e,t[n]);return this},s.prototype.listeners=function(e){return p(this,e,!0)},s.prototype.rawListeners=function(e){return p(this,e,!1)},s.listenerCount=function(e,t){return"function"==typeof e.listenerCount?e.listenerCount(t):c.call(e,t)},s.prototype.listenerCount=c,s.prototype.eventNames=function(){return this._eventsCount>0?t(this._events):[]}}};const t={};function r(n){const o=t[n];if(void 0!==o)return o.exports;const s=t[n]={exports:{}};return e[n](s,s.exports,r),s.exports}r.d=(e,t)=>{if(Array.isArray(t))for(var n=0;n<t.length;){var o=t[n++],s=t[n++];r.o(e,o)?0===s&&n++:0===s?Object.defineProperty(e,o,{enumerable:!0,value:t[n++]}):Object.defineProperty(e,o,{enumerable:!0,get:s})}else for(var o in t)r.o(t,o)&&!r.o(e,o)&&Object.defineProperty(e,o,{enumerable:!0,get:t[o]})},r.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t);let n={};r.d(n,{TinyMediaPlayer:()=>b});var o=r(7);const s=(e,t)=>{if("string"!=typeof t)throw new TypeError('Expected "name" to be a string.');if("string"!=typeof e)throw new TypeError(`Expected "${t}" to be a string, but received ${typeof e}.`)},i=(e,t)=>{if("string"!=typeof t)throw new TypeError('Expected "name" to be a string.');if("function"!=typeof e)throw new TypeError(`Expected "${t}" to be a function, but received ${typeof e}.`)},a=(e,t)=>{if("string"!=typeof t)throw new TypeError('Expected "name" to be a string.');if("object"!=typeof e||null===e||Array.isArray(e))throw new TypeError(`Expected "${t}" to be a plain object, but received ${null===e?"null":Array.isArray(e)?"array":typeof e}.`)},l=new Map;class u extends Error{constructor(e,t,r){if(s(e,"message"),s(t,"url"),"string"!=typeof r)throw new TypeError(`Expected "stage" to be a string, but received ${typeof r}.`);super(e),this.name="MediaLoadingError",this.url=t,this.stage=r}}const d=async e=>{s(e,"str");const t=(new TextEncoder).encode(e),r=await crypto.subtle.digest("SHA-1",t);return Array.from(new Uint8Array(r)).map(e=>e.toString(16).padStart(2,"0")).join("").substring(0,8)},h=(e,t="image/jpeg")=>{if(!(e instanceof Uint8Array)&&"string"!=typeof e)throw new TypeError(`Expected "data" to be an instance of Uint8Array or a string, but received ${typeof e}.`);s(t,"format");const r=e=>{const t=URL.createObjectURL(e),r=l.get(t);return l.set(t,"number"==typeof r?r+1:1),t};if(e instanceof Uint8Array)return r(new Blob([e],{type:t}));if("string"==typeof e&&e.startsWith("data:")){const n=e.split(",")[1],o=atob(n),s=new Uint8Array(o.length);for(let e=0;e<o.length;e++)s[e]=o.charCodeAt(e);return r(new Blob([s],{type:t}))}return"string"==typeof e?e:""},p=(e,t)=>{if(a(e,"common"),"boolean"!=typeof t)throw new TypeError('Expected "isPartial" to be a boolean.');const r=e=>t&&void 0===e,n=e=>r(e)||"string"==typeof e||null===e,o=(e,t)=>(i(t,"valueValidator"),!!r(e)||!(!Array.isArray(e)||!e.every(t)));if(!n(e.title))throw new TypeError('Invalid metadata: "title" must be a string or null.');if(!n(e.album))throw new TypeError('Invalid metadata: "album" must be a string or null.');if(!n(e.albumartist))throw new TypeError('Invalid metadata: "albumartist" must be a string or null.');if(!n(e.artist))throw new TypeError('Invalid metadata: "artist" must be a string or null.');if(l=e.year,!r(l)&&"number"!=typeof l&&null!==l)throw new TypeError('Invalid metadata: "year" must be a number or null.');var l;if(!o(e.albumartists,e=>"string"==typeof e))throw new TypeError('Invalid metadata: "albumartists" must be an array of string.');if(!o(e.genre,e=>"string"==typeof e))throw new TypeError('Invalid metadata: "genre" must be an array of string.');if(!o(e.label,e=>"string"==typeof e))throw new TypeError('Invalid metadata: "label" must be an array of string.');if(!o(e.composer,e=>"string"==typeof e))throw new TypeError('Invalid metadata: "composer" must be an array of string.');if(!o(e.artists,e=>"string"==typeof e))throw new TypeError('Invalid metadata: "artists" must be an array of string.');if(!o(e.picture,e=>e&&"object"==typeof e&&(void 0===e.description||"string"==typeof e.description)&&(void 0===e.name||"string"==typeof e.name)&&(void 0===e.type||"string"==typeof e.type)&&"string"==typeof e.format&&(e.data instanceof Uint8Array||"string"==typeof e.data)))throw new TypeError('Invalid metadata: "picture" must be an array of pictures.');const u=(e,t)=>{if(s(e,"name"),!r(t)){if(null==t)throw new TypeError(`Invalid metadata: "${e}" is required.`);if("object"!=typeof t)throw new TypeError(`Invalid metadata: "${e}" must be an object or null.`);if("number"!=typeof t.no&&null!==t.no)throw new TypeError(`Invalid metadata: "${e}.no" must be a number or null.`);if("number"!=typeof t.of&&null!==t.of)throw new TypeError(`Invalid metadata: "${e}.of" must be a number or null.`)}};u("disk",e.disk),u("track",e.track)},c=e=>(a(e,"common"),p(e,!1)),m=e=>t=>{if(t)throw new Error(`This ${e} instance has been destroyed and can no longer be used.`)},y=m("BaseMediaAdapter");class f extends o.EventEmitter{constructor(){if(new.target===f)throw new Error("BaseMediaAdapter is an abstract class and cannot be instantiated directly.");super()}#e=!1;get destroyed(){return this.#e}canHandle(e){throw y(this.#e),new Error('Method "canHandle" must be implemented by the subclass.')}async play(e){throw y(this.#e),new Error('Method "play" must be implemented by the subclass.')}async pause(){throw y(this.#e),new Error('Method "pause" must be implemented by the subclass.')}async stop(){throw y(this.#e),new Error('Method "stop" must be implemented by the subclass.')}async seek(e){throw y(this.#e),new Error('Method "seek" must be implemented by the subclass.')}getCurrentTime(){throw y(this.#e),new Error('Method "getCurrentTime" must be implemented by the subclass.')}getTotalDuration(){throw y(this.#e),new Error('Method "getTotalDuration" must be implemented by the subclass.')}getRemainingTime(){throw y(this.#e),new Error('Method "getRemainingTime" must be implemented by the subclass.')}getPlaybackPercentage(){throw y(this.#e),new Error('Method "getPlaybackPercentage" must be implemented by the subclass.')}getTimeData(){throw y(this.#e),new Error('Method "getTimeData" must be implemented by the subclass.')}setVolume(e){throw y(this.#e),new Error('Method "setVolume" must be implemented by the subclass.')}getVolume(){throw y(this.#e),new Error('Method "getVolume" must be implemented by the subclass.')}destroy(){this.#e||(this.removeAllListeners(),this.#e=!0,this.emit("destroyed"))}}function g(e){return null!==e&&"object"==typeof e&&!Array.isArray(e)}const w=m("TinyMediaPlayer");class v extends o.EventEmitter{static BaseMediaAdapter=f;static#t="Unknown Artist";static get unknownArtist(){return v.#t}static set unknownArtist(e){if("string"!=typeof e&&"function"!=typeof e)throw new TypeError("unknownArtist must be a string or a function.");v.#t=e}static async parseContent(e,t,r,n,o){return(async(e,t={},r={},n=e=>{if(!(e instanceof Blob))throw new TypeError('Expected "data" to be a Blob.');return new Promise((e,t)=>t(new TypeError("parseFile library not found.")))},o={},l="null")=>{if("string"!=typeof e&&!(e instanceof HTMLMediaElement))throw new TypeError("Source must be a string or an HTMLMediaElement.");if(a(t,"defaultMetadata"),a(r,"metadata"),i(n,"parseFile"),a(o,"callbacks"),o.onProgress&&"function"!=typeof o.onProgress)throw new TypeError("callbacks.onProgress must be a function.");if(o.onError&&"function"!=typeof o.onError)throw new TypeError("callbacks.onError must be a function.");if("string"!=typeof l&&"function"!=typeof l)throw new TypeError("unknownArtist must be a string or a function returning a string.");let c,m="";const y=(t,r)=>{if(s(t,"stage"),void 0!==r&&!(r instanceof Event))throw new TypeError('Expected "event" to be an Event or undefined.');o.onProgress&&o.onProgress({event:r,status:"loading",stage:t,url:m||(e instanceof HTMLMediaElement?e.src:"unknown")})},f=(t,r)=>{if(!(t instanceof Error))throw new TypeError('Expected "error" to be an Error.');s(r,"stage"),o.onError&&o.onError({error:t,url:m||(e instanceof HTMLMediaElement?e.src:"unknown"),stage:r})};try{y("INITIALIZING"),"string"==typeof e?(m=e,c=new Audio(m)):(c=e,m=c.src);try{await new Promise((e,t)=>{const r=e=>y("DOWNLOADING",e),n=()=>{s(),e(void 0)},o=e=>{s(),t(new Error(`HTMLMediaElement failed to load: ${e.message||"Unknown error"}`))},s=()=>{c.removeEventListener("progress",r),c.removeEventListener("loadedmetadata",n),c.removeEventListener("error",o)};c.addEventListener("progress",r),c.addEventListener("loadedmetadata",n),c.addEventListener("error",o),c.readyState>=1&&(s(),e(void 0))}),y("METADATA_LOADED")}catch(e){throw new u(e instanceof Error?e.message:"UNKNOWN ERROR",m,"METADATA")}const g={id:r.id||await d(m),duration:Math.floor(1e3*c.duration),url:m,weight:r.weight??1};let w={};y("EXTRACTING_ID3");try{w=await(async(e,t)=>{s(e,"url"),i(t,"parseFile");try{const r=await fetch(e);if(!r.ok)throw new Error(`Failed to fetch audio file: ${r.status} ${r.statusText}`);const n=await r.blob(),o=await t(n);if(!o||"object"!=typeof o.common)throw new TypeError('Invalid metadata: "common" property is missing or not an object.');const s=o.common;return(e=>{a(e,"common"),p(e,!0)})(s),{title:s?.title??null,album:s?.album??null,albumartist:s?.albumartist??null,albumartists:s?.albumartists??[],genre:s?.genre??[],label:s?.label??[],composer:s?.composer??[],year:s?.year??null,artist:s?.artist??null,artists:s?.artists??[],disk:s?.disk?{no:s.disk.no,of:s.disk.of}:{no:null,of:null},track:s?.track?{no:s.track.no,of:s.track.of}:{no:null,of:null},picture:s?.picture?.map(e=>({...e,data:h(e.data,e.format)}))??[]}}catch(e){throw e}})(m,n)}catch(e){f(e instanceof Error?e:new Error("Unknown Error"),"ID3"),console.warn(`[TinyAudioUtils] ID3 extraction failed for ${m}. Falling back to filename.`)}const v=e=>{s(e,"url");try{return(e.split(/[?#]/)[0].split("/").pop()??"").replace(/\.[^/.]+$/,"")||"Unknown Track"}catch{return"Unknown Track"}},b={...g,...t,...w,...r,title:w.title||r.title||v(m),artist:w.artist||r.artist||("string"==typeof l?l:String(l()))};return o.onProgress&&o.onProgress({status:"success",stage:"COMPLETE",url:m}),b}catch(e){if(e instanceof u)throw e;{const t=new u(e instanceof Error?e.message:"UNKNOWN ERROR",m,"INITIALIZING");throw f(t,"INITIALIZING"),t}}})(e,t,r,n,o,v.#t)}#e=!1;get destroyed(){return this.#e}#r=new Set;#n=new WeakMap;#o=[];#s=-1;#i="NONE";#a=!1;#l=!1;#u=1;#d;#h;#p;#c=!1;#m;#y;#f=null;#g=null;#w=300;get fadeVolumeSpeed(){return w(this.#e),this.#w}set fadeVolumeSpeed(e){if(w(this.#e),"number"!=typeof e)throw new TypeError("fadeVolumeSpeed must be a number.");if(e<0)throw new RangeError("fadeVolumeSpeed cannot be negative.");this.#w=e,this.emit("fadeVolumeSpeedChange",this.#w)}#v=2e3;get prevClickTimeoutDuration(){return w(this.#e),this.#v}set prevClickTimeoutDuration(e){if(w(this.#e),"number"!=typeof e)throw new TypeError("prevClickTimeoutDuration must be a number.");if(e<0)throw new RangeError("prevClickTimeoutDuration cannot be negative.");this.#v=e,this.emit("prevClickTimeoutDurationChange",this.#v)}get repeatCurrentOnPrev(){return w(this.#e),this.#p}set repeatCurrentOnPrev(e){if(w(this.#e),"boolean"!=typeof e)throw new TypeError("repeatCurrentOnPrev must be a boolean.");this.#p=e,this.emit("repeatCurrentOnPrevChange",this.#p)}get smoothPlayPauseVolume(){return w(this.#e),this.#m}set smoothPlayPauseVolume(e){if(w(this.#e),"boolean"!=typeof e)throw new TypeError("smoothPlayPauseVolume must be a boolean.");this.#m=e,this.emit("smoothPlayPauseVolumeChange",this.#m)}get smoothStopVolume(){return w(this.#e),this.#y}set smoothStopVolume(e){if(w(this.#e),"boolean"!=typeof e)throw new TypeError("smoothStopVolume must be a boolean.");this.#y=e,this.emit("smoothStopVolumeChange",this.#y)}constructor(e={}){if(super(),!g(e))throw new TypeError("Options must be a non-null object.");if(void 0!==e.persistVolume){if("boolean"!=typeof e.persistVolume)throw new TypeError("persistVolume must be a boolean.");this.#d=e.persistVolume}else this.#d=!1;if(void 0!==e.volumeStorageKey){if("string"!=typeof e.volumeStorageKey)throw new TypeError("volumeStorageKey must be a string.");this.#h=e.volumeStorageKey}else this.#h="tiny_media_player_volume";if(void 0!==e.repeatCurrentOnPrev){if("boolean"!=typeof e.repeatCurrentOnPrev)throw new TypeError("repeatCurrentOnPrev must be a boolean.");this.#p=e.repeatCurrentOnPrev}else this.#p=!1;if(void 0!==e.smoothPlayPauseVolume){if("boolean"!=typeof e.smoothPlayPauseVolume)throw new TypeError("smoothPlayPauseVolume must be a boolean.");this.#m=e.smoothPlayPauseVolume}else this.#m=!1;if(void 0!==e.smoothStopVolume){if("boolean"!=typeof e.smoothStopVolume)throw new TypeError("smoothStopVolume must be a boolean.");this.#y=e.smoothStopVolume}else this.#y=!1;this.#d&&this.#b()}#b(){try{if("undefined"!=typeof window&&window.localStorage){const e=window.localStorage.getItem(this.#h);if(null!==e){const t=parseFloat(e);!isNaN(t)&&t>=0&&t<=1&&(this.#u=t)}}}catch(e){console.warn("[TinyMediaPlayer] Failed to read volume from localStorage.",e)}}#E(){try{this.#d&&"undefined"!=typeof window&&window.localStorage&&window.localStorage.setItem(this.#h,this.#u.toString())}catch(e){console.warn("[TinyMediaPlayer] Failed to save volume to localStorage.",e)}}_getWeightedRandomIndex(){if(0===this.#o.length)return-1;if(1===this.#o.length)return 0;let e=0;for(let t=0;t<this.#o.length;t++){if(t===this.#s)continue;const r=this.#o[t];e+="number"==typeof r.weight&&r.weight>0?r.weight:1}let t=Math.random()*e;for(let e=0;e<this.#o.length;e++){if(e===this.#s)continue;const r=this.#o[e],n="number"==typeof r.weight&&r.weight>0?r.weight:1;if(t<n)return e;t-=n}return this.#s===this.#o.length-1?0:this.#o.length-1}async#T(e){this.#f&&this.#f.abort(),this.#f=new AbortController;const{signal:t}=this.#f,r=this.#A();if(!r)return;const n=r.getVolume(),o=performance.now(),s=this.#w;return new Promise(i=>{const a=l=>{if(t.aborted)return i();const u=l-o,d=Math.min(u/s,1),h=n+(e-n)*d,p=Math.max(0,Math.min(1,h));r.setVolume(p),d<1?requestAnimationFrame(a):(r.setVolume(e),i())};requestAnimationFrame(a)})}get playlist(){return w(this.#e),[...this.#o]}set playlist(e){if(w(this.#e),!Array.isArray(e))throw new TypeError("Playlist must be an array of MediaContent objects.");e.forEach(e=>c(e));const t=this.#l;let r=null;if(-1!==this.#s&&this.#o.length>0)try{r=this.#A()}catch(e){}this.#o=e,this.emit("playlistUpdate",this.playlist),0===this.#o.length?this.#s=-1:(this.#s>=this.#o.length||-1===this.#s)&&(this.#s=0),this.emit("trackChange",this.#s),t&&(async()=>{try{r&&await r.stop(),-1!==this.#s&&await this.play()}catch(e){console.warn("[TinyMediaPlayer] Background transition error on playlist update:",e)}})()}get currentIndex(){return w(this.#e),this.#s}set currentIndex(e){if(w(this.#e),"number"!=typeof e)throw new TypeError("Current index must be a number.");if(e<-1||e>=this.#o.length&&this.#o.length>0)throw new RangeError(`Index ${e} is out of bounds for the current playlist.`);if(this.#s===e)return;const t=this.#l;let r=null;if(-1!==this.#s&&this.#o.length>0)try{r=this.#A()}catch(e){}this.#s=e,this.emit("trackChange",this.#s),t&&(async()=>{try{r&&await r.stop(),-1!==this.#s&&await this.play()}catch(e){console.warn("[TinyMediaPlayer] Background transition error on index update:",e)}})()}get loopMode(){return w(this.#e),this.#i}set loopMode(e){w(this.#e);const t=["NONE","TRACK","PLAYLIST"];if(!t.includes(e))throw new TypeError(`Loop mode must be one of: ${t.join(", ")}.`);this.#i=e,this.emit("loopModeChange",this.#i)}get isRandom(){return w(this.#e),this.#a}set isRandom(e){if(w(this.#e),"boolean"!=typeof e)throw new TypeError("Random mode state must be a boolean.");this.#a=e,this.emit("randomModeChange",this.#a)}get isPlaying(){return w(this.#e),this.#l}get volume(){return w(this.#e),this.#u}set volume(e){if(w(this.#e),"number"!=typeof e)throw new TypeError("Volume must be a number.");if(e<0||e>1)throw new RangeError("Volume must be tightly constrained between 0.0 and 1.0.");if(this.#f&&this.#f.abort(),this.#u=e,this.#E(),this.emit("volumeChange",this.#u),-1!==this.#s&&this.#o.length>0)try{const e=this.#A();e&&e.setVolume(this.#u)}catch(e){}}get persistVolume(){return w(this.#e),this.#d}set persistVolume(e){if(w(this.#e),"boolean"!=typeof e)throw new TypeError("Persist volume parameter must be a boolean.");this.#d=e,e&&this.#E()}get volumeStorageKey(){return w(this.#e),this.#h}set volumeStorageKey(e){if(w(this.#e),"string"!=typeof e)throw new TypeError("Volume storage key must be a string.");if(""===e.trim())throw new TypeError("Volume storage key cannot be an empty string.");const t=this.#h;this.#h=e;try{this.#d&&"undefined"!=typeof window&&window.localStorage&&(window.localStorage.removeItem(t),this.#E())}catch(e){console.warn("[TinyMediaPlayer] Failed to migrate volume storage key.",e)}}get adapters(){return Array.from(this.#r)}get adaptersSize(){return this.#r.size}static#P=["timeupdate","ended"];static get defaultAdapterEventNames(){return structuredClone(v.#P)}static set defaultAdapterEventNames(e){if(!Array.isArray(e)||!e.every(e=>"string"==typeof e))throw new TypeError("TinyMediaPlayer.defaultAdapterEventNames must be an array of strings.");v.#P=[...e]}#x=new Set(v.defaultAdapterEventNames);#I(e){const t=this.#n.get(e);t&&(this.#x.forEach(r=>{const n=t.get(r);n&&e.off(r,n)}),t.clear(),this.#n.delete(e))}registerAdapter(e){if(w(this.#e),!(e instanceof f))throw new TypeError("Adapter must be an instance of BaseMediaAdapter.");const t=new Map;this.#n.set(e,t),this.#x.forEach(t=>{this.#k(e,t)}),this.#r.add(e)}removeAdapter(e){if(w(this.#e),!(e instanceof f))throw new TypeError("Adapter must be an instance of BaseMediaAdapter.");return this.#I(e),this.#r.delete(e)}destroyAdapter(e){if(w(this.#e),!(e instanceof f))throw new TypeError("Adapter must be an instance of BaseMediaAdapter.");this.#I(e);const t=this.#r.delete(e);return t&&e.destroy(),t}hasAdapter(e){if(w(this.#e),!(e instanceof f))throw new TypeError("Adapter must be an instance of BaseMediaAdapter.");return this.#r.has(e)}destroyAllAdapters(){w(this.#e),this.#r.forEach(e=>{this.#I(e),e.destroy()}),this.#r.clear()}clearAdapters(){w(this.#e),this.#r.forEach(e=>this.#I(e)),this.#r.clear()}getMediaAdapter(e){if(!g(e))throw new TypeError("Content must be a valid object.");for(const t of this.#r.values())if(t.canHandle(e))return t;return null}#A(){if(-1===this.#s||0===this.#o.length)return null;const e=this.#o[this.#s],t=this.getMediaAdapter(e);if(t)return t;throw new Error(`No compatible adapter found for content ID: ${e.id}.`)}addAdapterEvent(e){if(w(this.#e),"string"!=typeof e)throw new TypeError("Event name must be a string.");this.#x.has(e)||(this.#x.add(e),this.#r.forEach(t=>{this.#k(t,e)}))}removeAdapterEvent(e){if(w(this.#e),"string"!=typeof e)throw new TypeError("Event name must be a string.");this.#x.has(e)&&(this.#x.delete(e),this.#r.forEach(t=>{this.#C(t,e)}))}resetAdapterEvents(){w(this.#e);const e=v.defaultAdapterEventNames,t=Array.from(this.#x);for(const r of t)e.includes(r)||this.removeAdapterEvent(r);for(const t of e)this.#x.has(t)||this.addAdapterEvent(t)}#k(e,t){const r=this.#n.get(e);if(!r)return;const n=(...e)=>{this.#e||this.emit(t,...e)};e.on(t,n),r.set(t,n)}#C(e,t){const r=this.#n.get(e);if(!r)return;const n=r.get(t);n&&(e.off(t,n),r.delete(t))}addTrack(e){if(w(this.#e),!g(e)||"string"!=typeof e.url)throw new TypeError("Track content must be a valid MediaContent object containing a URL.");const t={id:"",title:"",artist:"",url:"",duration:0,weight:1,title:null,album:null,albumartist:null,albumartists:[],genre:[],label:[],composer:[],year:null,artist:null,artists:[],disk:{no:null,of:null},track:{no:null,of:null},picture:[],...e};c(t);const r=this.#o.push(t);return-1===this.#s&&(this.#s=0,this.emit("trackChange",this.#s)),this.emit("playlistUpdate",this.playlist),r}existsTrack(e){if(w(this.#e),"number"!=typeof e)throw new TypeError("Index must be a number.");return e>=0&&e<this.#o.length}getTrack(e){if(w(this.#e),"number"!=typeof e)throw new TypeError("Index must be a number.");if(!this.existsTrack(e))throw new RangeError(`Index ${e} is out of bounds for the current playlist.`);return this.#o[e]}async removeTrack(e){if(w(this.#e),"number"!=typeof e)throw new TypeError("Index must be a number.");if(!this.existsTrack(e))throw new RangeError(`Index ${e} is out of bounds for the current playlist.`);e===this.#s?(await this.stop(),this.#o.splice(e,1),0===this.#o.length?this.#s=-1:this.#s>=this.#o.length&&(this.#s=0),this.emit("trackChange",this.#s)):(this.#o.splice(e,1),e<this.#s&&(this.#s-=1,this.emit("trackChange",this.#s))),this.emit("playlistUpdate",this.playlist)}searchTrack(e){if(w(this.#e),"string"!=typeof e&&"function"!=typeof e)throw new TypeError("Search query must be a string or a boolean evaluation function.");const t=[];for(let r=0;r<this.#o.length;r++){const n=this.#o[r];let o=!1;if("function"==typeof e)o=Boolean(e(n));else{const t=e.toLowerCase(),r=n.title&&n.title.toLowerCase().includes(t),s=n.artist&&n.artist.toLowerCase().includes(t),i=n.album&&n.album.toLowerCase().includes(t);o=Boolean(r||s||i)}o&&t.push({track:n,index:r})}return t}async clearPlaylist(){w(this.#e),await this.stop(),this.#o=[],this.#s=-1,this.emit("playlistUpdate",this.playlist),this.emit("trackChange",this.#s)}async play(){w(this.#e);const e=this.#A();e&&(this.#m?await this.#T(this.#u):e.setVolume(this.#u),await e.play(this.#o[this.#s]),this.#l=!0,this.emit("play",this.#s))}async pause(){w(this.#e);const e=this.#A();e&&(this.#m&&await this.#T(0),await e.pause(),this.#l=!1,this.emit("pause",this.#s))}async stop(){w(this.#e);const e=this.#A();e&&(this.#y&&await this.#T(0),await e.stop(),this.#l=!1,this.emit("stop",this.#s))}async next(){if(w(this.#e),0!==this.#o.length)if(await this.stop(),"TRACK"!==this.#i){if(this.#a)this.#s=this._getWeightedRandomIndex();else{let e=this.#s+1;if(e>=this.#o.length){if("PLAYLIST"!==this.#i)return;e=0}this.#s=e}this.emit("trackChange",this.#s),await this.play()}else await this.play()}async prev(){if(w(this.#e),0!==this.#o.length){if(this.#p&&!this.#c)return this.#c=!0,this.#g&&clearTimeout(this.#g),this.#g=setTimeout(()=>{this.#c=!1,this.#g=null},2e3),await this.stop(),void await this.play();if(this.#g&&(clearTimeout(this.#g),this.#g=null),this.#c=!1,await this.stop(),this.#a)this.#s=this._getWeightedRandomIndex();else{let e=this.#s-1;if(e<0){if("PLAYLIST"!==this.#i)return;e=this.#o.length-1}this.#s=e}this.emit("trackChange",this.#s),await this.play()}}async seek(e){if(w(this.#e),"number"!=typeof e)throw new TypeError("Seek time must be a number in milliseconds.");if(e<0)throw new RangeError("Seek time cannot be negative.");const t=this.#A();t&&(await t.seek(e),this.emit("seek",e))}async step(e){if(w(this.#e),"number"!=typeof e)throw new TypeError("Step amount must be a number in milliseconds.");const t=this.#A();if(!t)return;let r=t.getCurrentTime()+e;r<0&&(r=0),await this.seek(r)}getCurrentTime(){w(this.#e);try{const e=this.#A();return e?e.getCurrentTime():0}catch{return 0}}getTotalDuration(){w(this.#e);try{const e=this.#A();return e?e.getTotalDuration():0}catch{return 0}}getRemainingTime(){w(this.#e);try{const e=this.#A();return e?e.getRemainingTime():0}catch{return 0}}getPlaybackPercentage(){w(this.#e);try{const e=this.#A();return e?e.getPlaybackPercentage():0}catch{return 0}}async destroy(){if(!this.#e){try{this.#l&&await this.stop()}catch(e){console.warn("[TinyMediaPlayer] Non-fatal error during playback termination:",e)}this.#g&&clearTimeout(this.#g),this.#o=[],this.#s=-1,this.#l=!1,this.#c=!1,this.destroyAllAdapters(),this.removeAllListeners(),this.#x.clear(),this.#e=!0,this.emit("destroyed")}}}const b=v;window.TinyMediaPlayer=n.TinyMediaPlayer})();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
(()=>{"use strict";const e={d:(t,o)=>{if(Array.isArray(o))for(var r=0;r<o.length;){var i=o[r++],n=o[r++];e.o(t,i)?0===n&&r++:0===n?Object.defineProperty(t,i,{enumerable:!0,value:o[r++]}):Object.defineProperty(t,i,{enumerable:!0,get:n})}else for(var i in o)e.o(o,i)&&!e.o(t,i)&&Object.defineProperty(t,i,{enumerable:!0,get:o[i]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t)};let t={};e.d(t,{TinyTimeout:()=>i});const o=e=>{if(e)throw new Error("This TinyTimeout instance has been destroyed and can no longer be used.")};class
|
|
1
|
+
(()=>{"use strict";const e={d:(t,o)=>{if(Array.isArray(o))for(var r=0;r<o.length;){var i=o[r++],n=o[r++];e.o(t,i)?0===n&&r++:0===n?Object.defineProperty(t,i,{enumerable:!0,value:o[r++]}):Object.defineProperty(t,i,{enumerable:!0,get:n})}else for(var i in o)e.o(o,i)&&!e.o(t,i)&&Object.defineProperty(t,i,{enumerable:!0,get:o[i]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t)};let t={};e.d(t,{TinyTimeout:()=>i});const o=(e,t=100)=>{if("function"!=typeof e)throw new TypeError("Expected 'getValue' to be a function.");if(!Number.isFinite(t)||t<=0)throw new TypeError("Expected 'checkInterval' to be a positive number.");return new Promise(o=>{const r=setInterval(()=>{e()&&(clearInterval(r),o())},t)})},r=e=>{if(e)throw new Error("This TinyTimeout instance has been destroyed and can no longer be used.")};const i=class{#e=!1;#t;#o;#r=null;#i=new Map;constructor({cooldownWatcherTime:e=5e3,allowAutoConfigChange:t=!1}={}){if(!Number.isFinite(e)||e<=0)throw new TypeError("Expected 'cooldownWatcherTime' to be a positive number.");if("boolean"!=typeof t)throw new TypeError("Expected 'allowAutoConfigChange' to be a boolean.");this.#o=e,this.#t=t,this.setCooldownWatcherTime(e)}isDestroyed(){return this.#e}getAllowAutoConfigChange(){return r(this.#e),this.#t}getCooldownWatcherTime(){return r(this.#e),this.#o}setAllowAutoConfigChange(e){if(r(this.#e),"boolean"!=typeof e)throw new TypeError("Expected 'value' to be a boolean.");this.#t=e}setCooldownWatcherTime(e){if(r(this.#e),this.#e)throw new Error("TinyTimeout has been destroyed.");if(!Number.isFinite(e)||e<=0)throw new TypeError("Expected 'value' to be a positive number.");this.#o=e,this.#r&&clearInterval(this.#r),this.#r=setInterval(()=>{this.#i.forEach(e=>{e.now>0&&e.now--})},this.#o)}set(e,t,o,i=null){if(r(this.#e),this.#e)throw new Error("TinyTimeout has been destroyed.");if("string"!=typeof e||""===e.trim())throw new TypeError("Expected 'id' to be a non-empty string.");if("function"!=typeof t)throw new TypeError("Expected 'callback' to be a function.");if(!Number.isFinite(o)||o<0)throw new TypeError("Expected 'value' to be a non-negative number.");if(null!==i&&(!Number.isFinite(i)||i<0))throw new TypeError("Expected 'limit' to be null or a non-negative number.");let n=this.#i.get(e);(!n||this.#t&&o!==n.value)&&(n={value:o,now:0},this.#i.set(e,n));const s=n.value*n.now;return n.now++,setTimeout(t,"number"==typeof i?Math.min(s,i):s)}static waitForTrue(e,t=100){return o(e,t)}waitForTrue(e,t=100){if(r(this.#e),this.#e)throw new Error("TinyTimeout has been destroyed.");if("function"!=typeof e)throw new TypeError("Expected 'getValue' to be a function.");if(null!==t&&(!Number.isFinite(t)||t<=0))throw new TypeError("Expected 'checkInterval' to be null or a positive number.");return o(e,t??this.#o)}destroy(){this.#e||(this.#r&&clearInterval(this.#r),this.#r=null,this.#i.clear(),this.#e=!0)}};window.TinyTimeout=t.TinyTimeout})();
|