tiny-essentials 1.27.1 → 1.28.0
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/README.md +1 -0
- package/changelog/1/28/0.md +16 -0
- package/dist/v1/TinyAdvancedRaffle.min.js +1 -1
- package/dist/v1/TinyBasicsEs.min.js +1 -2
- package/dist/v1/TinyEssentials.min.js +1 -2
- package/dist/v1/TinyIframeEvents.min.js +1 -1
- package/dist/v1/TinyLocalStorage.min.js +1 -1
- package/dist/v1/TinyMediaPlayer.min.js +1 -1
- package/dist/v1/TinyNewWinEvents.min.js +1 -1
- package/dist/v1/TinyRadioFm.min.js +1 -1
- package/dist/v1/TinySmartScroller.min.js +1 -1
- package/dist/v1/TinyUploadClicker.min.js +1 -2
- package/dist/v1/basics/extendObjType/Buffer.cjs +13 -0
- package/dist/v1/basics/extendObjType/Buffer.d.mts +4 -0
- package/dist/v1/basics/extendObjType/Buffer.mjs +8 -0
- package/dist/v1/basics/objFilter.cjs +0 -11
- package/dist/v1/basics/objFilter.mjs +0 -10
- package/dist/v1/index.cjs +0 -2
- package/dist/v1/index.d.mts +1 -2
- package/dist/v1/index.mjs +1 -2
- package/dist/v1/libs/TinyAdvancedRaffle.cjs +7 -205
- package/dist/v1/libs/TinyAdvancedRaffle.d.mts +2 -121
- package/dist/v1/libs/TinyAdvancedRaffle.mjs +7 -179
- package/dist/v1/libs/TinyIframeEvents.cjs +8 -195
- package/dist/v1/libs/TinyIframeEvents.d.mts +3 -122
- package/dist/v1/libs/TinyIframeEvents.mjs +8 -170
- package/dist/v1/libs/TinyLocalStorage.cjs +5 -205
- package/dist/v1/libs/TinyLocalStorage.d.mts +3 -130
- package/dist/v1/libs/TinyLocalStorage.mjs +5 -178
- package/dist/v1/libs/TinyMediaPlayer.cjs +2 -2
- package/dist/v1/libs/TinyMediaPlayer.d.mts +2 -2
- package/dist/v1/libs/TinyMediaPlayer.mjs +2 -2
- package/dist/v1/libs/TinyNewWinEvents.cjs +10 -197
- package/dist/v1/libs/TinyNewWinEvents.d.mts +3 -122
- package/dist/v1/libs/TinyNewWinEvents.mjs +10 -172
- package/dist/v1/libs/TinyRadioFm.cjs +2 -3
- package/dist/v1/libs/TinyRadioFm.d.mts +2 -3
- package/dist/v1/libs/TinyRadioFm.mjs +2 -3
- package/dist/v1/libs/TinySmartScroller.cjs +4 -202
- package/dist/v1/libs/TinySmartScroller.d.mts +8 -143
- package/dist/v1/libs/TinySmartScroller.mjs +4 -176
- package/dist/v1/libs/TinyUploadClicker.cjs +1 -0
- package/docs/v1/Exports.md +0 -1
- package/docs/v1/README.md +0 -1
- package/docs/v1/basics/objFilter.md +1 -1
- package/docs/v1/libs/TinyIframeEvents.md +8 -8
- package/docs/v1/libs/TinyLocalStorage.md +3 -3
- package/docs/v1/libs/TinyNewWinEvents.md +8 -9
- package/package.json +6 -5
- package/dist/v1/TinyBasicsEs.min.js.LICENSE.txt +0 -8
- package/dist/v1/TinyEssentials.min.js.LICENSE.txt +0 -8
- package/dist/v1/TinyEvents.min.js +0 -1
- package/dist/v1/TinyUploadClicker.min.js.LICENSE.txt +0 -8
- package/dist/v1/build/TinyEvents.cjs +0 -7
- package/dist/v1/build/TinyEvents.d.mts +0 -3
- package/dist/v1/build/TinyEvents.mjs +0 -2
- package/dist/v1/libs/TinyEvents.cjs +0 -395
- package/dist/v1/libs/TinyEvents.d.mts +0 -164
- package/dist/v1/libs/TinyEvents.mjs +0 -360
- package/docs/v1/libs/TinyEvents.md +0 -187
|
@@ -1 +1 @@
|
|
|
1
|
-
(()=>{"use strict";
|
|
1
|
+
(()=>{"use strict";var e={7(e){var t,n="object"==typeof Reflect?Reflect:null,r=n&&"function"==typeof n.apply?n.apply:function(e,t,n){return Function.prototype.apply.call(e,t,n)};t=n&&"function"==typeof n.ownKeys?n.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 s(){s.init.call(this)}e.exports=s,e.exports.once=function(e,t){return new Promise(function(n,r){function i(n){e.removeListener(t,s),r(n)}function s(){"function"==typeof e.removeListener&&e.removeListener("error",i),n([].slice.call(arguments))}l(e,t,s,{once:!0}),"error"!==t&&function(e,t){"function"==typeof e.on&&l(e,"error",t,{once:!0})}(e,i)})},s.EventEmitter=s,s.prototype._events=void 0,s.prototype._eventsCount=0,s.prototype._maxListeners=void 0;var o=10;function a(e){if("function"!=typeof e)throw new TypeError('The "listener" argument must be of type Function. Received type '+typeof e)}function h(e){return void 0===e._maxListeners?s.defaultMaxListeners:e._maxListeners}function u(e,t,n,r){var i,s,o,u;if(a(n),void 0===(s=e._events)?(s=e._events=Object.create(null),e._eventsCount=0):(void 0!==s.newListener&&(e.emit("newListener",t,n.listener?n.listener:n),s=e._events),o=s[t]),void 0===o)o=s[t]=n,++e._eventsCount;else if("function"==typeof o?o=s[t]=r?[n,o]:[o,n]:r?o.unshift(n):o.push(n),(i=h(e))>0&&o.length>i&&!o.warned){o.warned=!0;var f=new Error("Possible EventEmitter memory leak detected. "+o.length+" "+String(t)+" listeners added. Use emitter.setMaxListeners() to increase limit");f.name="MaxListenersExceededWarning",f.emitter=e,f.type=t,f.count=o.length,u=f,console&&console.warn&&console.warn(u)}return e}function f(){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 d(e,t,n){var r={fired:!1,wrapFn:void 0,target:e,type:t,listener:n},i=f.bind(r);return i.listener=n,r.wrapFn=i,i}function p(e,t,n){var r=e._events;if(void 0===r)return[];var i=r[t];return void 0===i?[]:"function"==typeof i?n?[i.listener||i]:[i]:n?function(e){for(var t=new Array(e.length),n=0;n<t.length;++n)t[n]=e[n].listener||e[n];return t}(i):c(i,i.length)}function v(e){var t=this._events;if(void 0!==t){var n=t[e];if("function"==typeof n)return 1;if(void 0!==n)return n.length}return 0}function c(e,t){for(var n=new Array(t),r=0;r<t;++r)n[r]=e[r];return n}function l(e,t,n,r){if("function"==typeof e.on)r.once?e.once(t,n):e.on(t,n);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(s){r.once&&e.removeEventListener(t,i),n(s)})}}Object.defineProperty(s,"defaultMaxListeners",{enumerable:!0,get:function(){return o},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+".");o=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||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},s.prototype.getMaxListeners=function(){return h(this)},s.prototype.emit=function(e){for(var t=[],n=1;n<arguments.length;n++)t.push(arguments[n]);var i="error"===e,s=this._events;if(void 0!==s)i=i&&void 0===s.error;else if(!i)return!1;if(i){var o;if(t.length>0&&(o=t[0]),o instanceof Error)throw o;var a=new Error("Unhandled error."+(o?" ("+o.message+")":""));throw a.context=o,a}var h=s[e];if(void 0===h)return!1;if("function"==typeof h)r(h,this,t);else{var u=h.length,f=c(h,u);for(n=0;n<u;++n)r(f[n],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,d(this,e,t)),this},s.prototype.prependOnceListener=function(e,t){return a(t),this.prependListener(e,d(this,e,t)),this},s.prototype.removeListener=function(e,t){var n,r,i,s,o;if(a(t),void 0===(r=this._events))return this;if(void 0===(n=r[e]))return this;if(n===t||n.listener===t)0===--this._eventsCount?this._events=Object.create(null):(delete r[e],r.removeListener&&this.emit("removeListener",e,n.listener||t));else if("function"!=typeof n){for(i=-1,s=n.length-1;s>=0;s--)if(n[s]===t||n[s].listener===t){o=n[s].listener,i=s;break}if(i<0)return this;0===i?n.shift():function(e,t){for(;t+1<e.length;t++)e[t]=e[t+1];e.pop()}(n,i),1===n.length&&(r[e]=n[0]),void 0!==r.removeListener&&this.emit("removeListener",e,o||t)}return this},s.prototype.off=s.prototype.removeListener,s.prototype.removeAllListeners=function(e){var t,n,r;if(void 0===(n=this._events))return this;if(void 0===n.removeListener)return 0===arguments.length?(this._events=Object.create(null),this._eventsCount=0):void 0!==n[e]&&(0===--this._eventsCount?this._events=Object.create(null):delete n[e]),this;if(0===arguments.length){var i,s=Object.keys(n);for(r=0;r<s.length;++r)"removeListener"!==(i=s[r])&&this.removeAllListeners(i);return this.removeAllListeners("removeListener"),this._events=Object.create(null),this._eventsCount=0,this}if("function"==typeof(t=n[e]))this.removeListener(e,t);else if(void 0!==t)for(r=t.length-1;r>=0;r--)this.removeListener(e,t[r]);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):v.call(e,t)},s.prototype.listenerCount=v,s.prototype.eventNames=function(){return this._eventsCount>0?t(this._events):[]}}};const t={};function n(r){const i=t[r];if(void 0!==i)return i.exports;const s=t[r]={exports:{}};return e[r](s,s.exports,n),s.exports}n.d=(e,t)=>{if(Array.isArray(t))for(var r=0;r<t.length;){var i=t[r++],s=t[r++];n.o(e,i)?0===s&&r++:0===s?Object.defineProperty(e,i,{enumerable:!0,value:t[r++]}):Object.defineProperty(e,i,{enumerable:!0,get:s})}else for(var i in t)n.o(t,i)&&!n.o(e,i)&&Object.defineProperty(e,i,{enumerable:!0,get:t[i]})},n.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t);let r={};n.d(r,{TinyIframeEvents:()=>h});var i=n(7);function s(e){return null!==e&&"object"==typeof e&&!Array.isArray(e)&&"[object Object]"===Object.prototype.toString.call(e)}const o=new WeakMap;class a extends i.EventEmitter{#e;get targetWindow(){return this.#e}#t;get targetIframeElement(){return this.#t}#n;get targetOrigin(){return this.#n}#r;get selfType(){return this.#r}#i=!1;#s=!1;get ready(){return this.#s}onReady(e){this.#s?e():this.once(this.#o,e)}#a=null;#h=[];#u;#f;#o;#d=null;constructor({targetIframe:e,targetOrigin:t=window.location.origin,secretEventName:n="__tinyIframeEvent__",handshakeEventName:r="__tinyIframeHandshake__",readyEventName:i="__tinyIframeReady__"}={}){if(super(),!(void 0===e||e instanceof HTMLIFrameElement&&e.contentWindow))throw new TypeError('[TinyIframeEvents] Invalid "targetIframe": expected HTMLIFrameElement, received '+typeof e);if("string"!=typeof t)throw new TypeError('[TinyIframeEvents] Invalid "targetOrigin": expected string, received '+typeof t);if(this.#t=e,this.#e=e?.contentWindow??window.parent,this.#n=t,this.#r=e?"parent":"iframe",this.#u=n,this.#f=r,this.#o=i,o.has(this.#e))throw new Error("Duplicate window reference.");this._boundWindowMessage=this.#p.bind(this),this._boundPortMessage=this.#v.bind(this),this.#c(),o.set(this.#e,this)}get secretEventName(){return this.#u}set secretEventName(e){if("string"!=typeof e)throw new TypeError("TinyIframeEvents: secretEventName must be a string.");this.#u=e}get handshakeEventName(){return this.#f}set handshakeEventName(e){if("string"!=typeof e)throw new TypeError("TinyIframeEvents: handshakeEventName must be a string.");this.#f=e}get readyEventName(){return this.#o}set readyEventName(e){if("string"!=typeof e)throw new TypeError("TinyIframeEvents: readyEventName must be a string.");this.#o=e}#c(){"parent"===this.#r?(this.#d=()=>{if(this.#i)return;this.#a&&this.#a.close();const e=new MessageChannel;this.#a=e.port1,this.#a.onmessage=this._boundPortMessage,this.#s=!1,this.#e.postMessage({type:this.#f},this.#n,[e.port2])},this.#t&&(this.#t.addEventListener("load",this.#d),this.#d())):window.addEventListener("message",this._boundWindowMessage,!1)}#p(e){const t=e.data,n=e.ports;s(t)&&t.type===this.#f&&0!==n.length&&(this.#a=n[0],this.#a.onmessage=this._boundPortMessage,window.removeEventListener("message",this._boundWindowMessage),this.#a.postMessage({type:`${this.#f}_ACK`}),this.#l())}#v(e){const t=e.data;if(s(t)&&t.type===`${this.#f}_ACK`)return void this.#l();if(!s(t)||!t[this.#u])return;const n=t.eventName,r=t.payload,i=t.direction;"string"!=typeof n||"iframe"===this.#r&&"iframe"!==i||"parent"===this.#r&&"parent"!==i||this.emit(`win:${n}`,r,e)}#l(){this.#s||(this.#s=!0,this.#m(),this.emit(this.#o))}#m(){for(;this.#h.length>0;){const e=this.#h.shift();e&&this.#a&&this.#a.postMessage(e)}}winEmit(e,t){if("string"!=typeof e)throw new TypeError("Event name must be a string.");if(this.#i)throw new Error("Cannot emit: instance has been destroyed.");const n={[this.#u]:!0,eventName:e,payload:t,direction:"parent"===this.#r?"iframe":"parent"};this.#s&&this.#a?this.#a.postMessage(n):this.#h.push(n)}isDestroyed(){return this.#i}destroy(){this.#i=!0,this.#s=!1,window.removeEventListener("message",this._boundWindowMessage),this.#t&&this.#d&&this.#t.removeEventListener("load",this.#d),this.#a&&(this.#a.close(),this.#a=null),this.removeAllListeners(),this.#h=[],o.delete(this.#e)}}const h=a;window.TinyIframeEvents=r.TinyIframeEvents})();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
(()=>{"use strict";const e={d:(t,r)=>{if(Array.isArray(r))for(var n=0;n<r.length;){var s=r[n++],o=r[n++];e.o(t,s)?0===o&&n++:0===o?Object.defineProperty(t,s,{enumerable:!0,value:r[n++]}):Object.defineProperty(t,s,{enumerable:!0,get:o})}else for(var s in r)e.o(r,s)&&!e.o(t,s)&&Object.defineProperty(t,s,{enumerable:!0,get:r[s]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t)};let t={};function r(e){return null!==e&&"object"==typeof e&&!Array.isArray(e)&&"[object Object]"===Object.prototype.toString.call(e)}e.d(t,{TinyLocalStorage:()=>l});const n=class{#e=new Map;#t=10;#r=!1;#n(e,t){if("string"==typeof e)return[e];if(Array.isArray(e)&&e.every(e=>"string"==typeof e))return e;throw new TypeError(`${t}(event): event must be a string or string[]`)}setThrowOnMaxListeners(e){if("boolean"!=typeof e)throw new TypeError("setThrowOnMaxListeners(value): value must be a boolean");this.#r=e}getThrowOnMaxListeners(){return this.#r}#s(e,t,{once:r=!1}={}){let n=this.#e.get(e);Array.isArray(n)||(n=[],this.#e.set(e,n)),n.unshift({handler:t,config:{once:r}});const s=this.#t;if(s>0&&n.length>s){const t=`Possible memory leak detected. ${n.length} "${e}" listeners added. Use setMaxListeners() to increase limit.`;if(this.#r)throw new Error(t);console.warn(t)}}prependListener(e,t){const r=this.#n(e,"prependListener");if("function"!=typeof t)throw new TypeError("prependListener(event, handler): handler must be a function");for(const e of r)this.#s(e,t)}prependListenerOnce(e,t){const r=this.#n(e,"prependListenerOnce");if("function"!=typeof t)throw new TypeError("prependListenerOnce(event, handler): handler must be a function");const n=[];for(const e of r){const r=(...n)=>{this.off(e,r),t(...n)};this.#s(e,r,{once:!0}),n.push(r)}return n}#o(e,t,{once:r=!1}={}){const n=this.#n(e,"on");for(const e of n){let n=this.#e.get(e);Array.isArray(n)||(n=[],this.#e.set(e,n)),n.push({handler:t,config:{once:r}});const s=this.#t;if(s>0&&n.length>s){const t=`Possible memory leak detected. ${n.length} "${e}" listeners added. Use setMaxListeners() to increase limit.`;if(this.#r)throw new Error(t);console.warn(t)}}}on(e,t){if("function"!=typeof t)throw new TypeError("on(event, handler): handler must be a function");return this.#o(e,t)}once(e,t){const r=this.#n(e,"once");if("function"!=typeof t)throw new TypeError("once(event, handler): handler must be a function");const n=[];for(const e of r){const r=(...n)=>{this.off(e,r),t(...n)};this.#o(e,r,{once:!0}),n.push(r)}return n}appendListener(e,t){return this.on(e,t)}appendListenerOnce(e,t){return this.once(e,t)}off(e,t){const r=this.#n(e,"off");if("function"!=typeof t)throw new TypeError("off(event, handler): handler must be a function");for(const e of r){const r=this.#e.get(e);if(!Array.isArray(r))continue;const n=r.findIndex(e=>e.handler===t);-1!==n&&r.splice(n,1),0===r.length&&this.#e.delete(e)}}offAll(e){const t=this.#n(e,"offAll");for(const e of t)this.#e.delete(e)}offAllTypes(){this.#e.clear()}removeAllListeners(){return this.offAllTypes()}listenerCount(e){if("string"!=typeof e)throw new TypeError("listenerCount(event): event name must be a string");const t=this.#e.get(e);return Array.isArray(t)?t.length:0}listeners(e){if("string"!=typeof e)throw new TypeError("listeners(event): event name must be a string");const t=this.#e.get(e);return Array.isArray(t)?[...t].filter(e=>!e.config.once).map(e=>e.handler):[]}onceListeners(e){if("string"!=typeof e)throw new TypeError("onceListeners(event): event name must be a string");const t=this.#e.get(e);return Array.isArray(t)?[...t].filter(e=>e.config.once).map(e=>e.handler):[]}allListeners(e){if("string"!=typeof e)throw new TypeError("allListeners(event): event name must be a string");const t=this.#e.get(e);return Array.isArray(t)?[...t].map(e=>e.handler):[]}eventNames(){return[...this.#e.keys()]}emit(e,...t){const r=this.#n(e,"emit"),n=[];for(const e of r){const r=this.#e.get(e);Array.isArray(r)&&0!==r.length?(r.forEach(e=>e.handler(...t)),n.push(!0)):n.push(!1)}return n}setMaxListeners(e){if(!Number.isInteger(e)||e<0)throw new TypeError("setMaxListeners(n): n must be a non-negative integer");this.#t=e}getMaxListeners(){return this.#t}},s=new Map,o=new Map,i=new Set(["string","boolean","object","array",String,Boolean,Number,Object,Array,BigInt,Symbol]);class a{#i=new n;setThrowOnMaxListeners(e){return this.#i.setThrowOnMaxListeners(e)}getThrowOnMaxListeners(){return this.#i.getThrowOnMaxListeners()}prependListener(e,t){return this.#i.prependListener(e,t)}prependListenerOnce(e,t){return this.#i.prependListenerOnce(e,t)}appendListener(e,t){return this.#i.appendListener(e,t)}appendListenerOnce(e,t){return this.#i.appendListenerOnce(e,t)}on(e,t){return this.#i.on(e,t)}once(e,t){return this.#i.once(e,t)}off(e,t){return this.#i.off(e,t)}offAll(e){return this.#i.offAll(e)}offAllTypes(){return this.#i.offAllTypes()}listenerCount(e){return this.#i.listenerCount(e)}listeners(e){return this.#i.listeners(e)}onceListeners(e){return this.#i.onceListeners(e)}allListeners(e){return this.#i.allListeners(e)}eventNames(){return this.#i.eventNames()}emit(e,...t){return this.#i.emit(e,...t)}setMaxListeners(e){return this.#i.setMaxListeners(e)}getMaxListeners(){return this.#i.getMaxListeners()}static hasJsonType(e){return s.has(e)&&o.has(e)||i.has(e)}static registerJsonType(e,t,r,n=!1){if(i.has(e))throw new Error(`Cannot register type "${e}" because it is frozen.`);s.set(e,t),o.set(e,r),n&&i.add(e)}static deleteJsonType(e){if(i.has(e))throw new Error(`Cannot remove type "${e}" because it is frozen.`);let t=!1;return s.delete(e)&&(t=!0),o.delete(e)&&(t=!0),t}static encodeSpecialJson(e){if(void 0===e)return{__undefined__:!0};if(null===e)return{__null__:!0};for(const[t,r]of s.entries())if("string"!=typeof t&&e instanceof t||typeof e===t)return r(e,a.encodeSpecialJson);if(Array.isArray(e))return e.map(a.encodeSpecialJson);if(r(e)){const t={};for(const r in e)t[r]=a.encodeSpecialJson(e[r]);return t}return e}static decodeSpecialJson(e){const t=r(e);if(t){if(e.__undefined__)return;if(e.__null__)return null}if(Array.isArray(e))return e.map(a.decodeSpecialJson);if(t){for(const[t,r]of o.entries())if(r.check&&r.check(e))return r.decode(e,a.decodeSpecialJson);const t={};for(const r in e)t[r]=a.decodeSpecialJson(e[r]);return t}return e}#a=window.localStorage;#l=null;#c=0;#h=e=>this.emit("storage",e);constructor(e){if(void 0!==e&&"string"!=typeof e)throw new TypeError("TinyLocalStorage: dbName must be a string if provided.");"string"==typeof e&&(this.#l=`LSDB::${e}`),window.addEventListener("storage",this.#h)}#f(e){if("string"==typeof e&&e.startsWith("LSDB::"))throw new Error(`TinyLocalStorage: Key "${e}" may conflict with reserved dbKeys.`)}updateStorageVersion(e,t){if("string"!=typeof this.#l)throw new Error("TinyLocalStorage: Database key is not initialized. Set a valid dbName in the constructor.");if("number"!=typeof e||Number.isNaN(e)||e<1)throw new TypeError("TinyLocalStorage: version must be a positive number.");if("function"!=typeof t)throw new TypeError("TinyLocalStorage: onUpgrade must be a function.");const r=parseInt(localStorage.getItem(this.#l),10)||0;if("number"!=typeof r||Number.isNaN(r)||r<0)throw new TypeError("TinyLocalStorage: saved version in localStorage is not a valid number.");if(e<r)throw new Error(`TinyLocalStorage: Cannot downgrade database version from ${r} to ${e}.`);e>r&&(t(r,e),localStorage.setItem(this.#l,String(e)),this.#c=e)}getDbKey(){return this.#l}getVersion(){return this.#c}setLocalStorage(e){if(!(e instanceof Storage))throw new TypeError("Argument must be a valid instance of Storage.");this.#a=e}localStorageExists(){return this.#a instanceof Storage}#y(e,t){if("string"!=typeof e||!e.length)throw new TypeError("Key must be a non-empty string.");return a.encodeSpecialJson(t)}setJson(e,t){if(this.#f(e),!(r(t)||Array.isArray(t)||t instanceof Map||t instanceof Set))throw new TypeError("The storage value is not a valid JSON-compatible structure.");const n=this.#y(e,t);return this.emit("setJson",e,t),this.#a.setItem(e,JSON.stringify(n))}#u(e,t){if("string"!=typeof e||!e.length)throw new TypeError("Key must be a non-empty string.");const r=this.#a.getItem(e),n={obj:()=>({}),array:()=>[],map:()=>new Map,set:()=>new Set},s="function"==typeof n[t]?n[t]():null;let o;try{o=JSON.parse(r)}catch{return s}return{decoded:a.decodeSpecialJson(o),fallback:s}}getJson(e,t){const{decoded:n,fallback:s}=this.#u(e,t);return n instanceof Map||n instanceof Set||Array.isArray(n)||r(n)?n:s}setDate(e,t){if(this.#f(e),!(t instanceof Date))throw new TypeError("Value must be a Date.");const r=this.#y(e,t);return this.emit("setDate",e,t),this.#a.setItem(e,JSON.stringify(r))}getDate(e){const t=this.#u(e).decoded;return t instanceof Date?t:null}setRegExp(e,t){if(this.#f(e),!(t instanceof RegExp))throw new TypeError("Value must be a RegExp.");const r=this.#y(e,t);return this.emit("setRegExp",e,t),this.#a.setItem(e,JSON.stringify(r))}getRegExp(e){const t=this.#u(e).decoded;return t instanceof RegExp?t:null}setBigInt(e,t){if(this.#f(e),"bigint"!=typeof t)throw new TypeError("Value must be a BigInt.");const r=this.#y(e,t);return this.emit("setBigInt",e,t),this.#a.setItem(e,JSON.stringify(r))}getBigInt(e){const t=this.#u(e).decoded;return"bigint"==typeof t?t:null}setSymbol(e,t){if(this.#f(e),"symbol"!=typeof t)throw new TypeError("Value must be a Symbol.");const r=this.#y(e,t);return this.emit("setSymbol",e,t),this.#a.setItem(e,JSON.stringify(r))}getSymbol(e){const t=this.#u(e).decoded;return"symbol"==typeof t?t:null}getValue(e){return this.#u(e).decoded??null}setItem(e,t){if(this.#f(e),"string"!=typeof e||!e.length)throw new TypeError("Key must be a non-empty string.");return this.emit("setItem",e,t),this.#a.setItem(e,t)}getItem(e){if("string"!=typeof e||!e.length)throw new TypeError("Key must be a non-empty string.");return this.#a.getItem(e)}setString(e,t){if(this.#f(e),"string"!=typeof e||!e.length)throw new TypeError("Key must be a non-empty string.");if("string"!=typeof t)throw new TypeError("Value must be a string.");return this.emit("setString",e,t),this.#a.setItem(e,JSON.stringify({__string__:!0,value:t}))}getString(e){if("string"!=typeof e||!e.length)throw new TypeError("Key must be a non-empty string.");let t=this.#a.getItem(e);try{if(t=JSON.parse(t),!r(t)||!t.__string__||"string"!=typeof t.value)return null;t=t.value}catch{t=null}return"string"==typeof t?t:null}setNumber(e,t){if(this.#f(e),"string"!=typeof e||!e.length)throw new TypeError("Key must be a non-empty string.");if("number"!=typeof t)throw new TypeError("Value must be a number.");return this.emit("setNumber",e,t),this.#a.setItem(e,String(t))}getNumber(e){if("string"!=typeof e||!e.length)throw new TypeError("Key must be a non-empty string.");let t=this.#a.getItem(e);return"number"==typeof t||"string"==typeof t&&t.length>0&&(t=parseFloat(t),!Number.isNaN(t))?t:null}setBool(e,t){if(this.#f(e),"string"!=typeof e||!e.length)throw new TypeError("Key must be a non-empty string.");if("boolean"!=typeof t)throw new TypeError("Value must be a boolean.");return this.emit("setBool",e,t),this.#a.setItem(e,String(t))}getBool(e){if("string"!=typeof e||!e.length)throw new TypeError("Key must be a non-empty string.");const t=this.#a.getItem(e);if("boolean"==typeof t)return t;if("string"==typeof t){if("true"===t)return!0;if("false"===t)return!1}return null}removeItem(e){if("string"!=typeof e||!e.length)throw new TypeError("Key must be a non-empty string.");return this.emit("removeItem",e),this.#a.removeItem(e)}clearLocalStorage(){return this.#a.clear()}destroy(){window.removeEventListener("storage",this.#h),this.#i.offAllTypes()}}a.registerJsonType(Map,(e,t)=>({__map__:!0,data:Array.from(e.entries()).map(([e,r])=>[e,t(r)])}),{check:e=>e.__map__,decode:(e,t)=>new Map(e.data.map(([e,r])=>[e,t(r)]))},!0),a.registerJsonType(Set,(e,t)=>({__set__:!0,data:Array.from(e).map(t)}),{check:e=>e.__set__,decode:(e,t)=>new Set(e.data.map(t))},!0),a.registerJsonType(Date,e=>({__date__:!0,value:e.toISOString()}),{check:e=>e.__date__,decode:e=>new Date(e.value)},!0),a.registerJsonType(RegExp,e=>({__regexp__:!0,source:e.source,flags:e.flags}),{check:e=>e.__regexp__,decode:e=>new RegExp(e.source,e.flags)},!0),a.registerJsonType("number",e=>({__number__:!0,value:e.toString()}),{check:e=>e.__number__,decode:e=>Number(e.value)},!0),a.registerJsonType("bigint",e=>({__bigint__:!0,value:e.toString()}),{check:e=>e.__bigint__,decode:e=>BigInt(e.value)},!0),a.registerJsonType("symbol",e=>({__symbol__:!0,key:Symbol.keyFor(e)??e.description??null}),{check:e=>e.__symbol__,decode:e=>{const t=e.key;return null!=t?Symbol.for(t):Symbol()}},!0);const l=a;window.TinyLocalStorage=t.TinyLocalStorage})();
|
|
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 i(){i.init.call(this)}e.exports=i,e.exports.once=function(e,t){return new Promise(function(r,n){function o(r){e.removeListener(t,i),n(r)}function i(){"function"==typeof e.removeListener&&e.removeListener("error",o),r([].slice.call(arguments))}h(e,t,i,{once:!0}),"error"!==t&&function(e,t){"function"==typeof e.on&&h(e,"error",t,{once:!0})}(e,o)})},i.EventEmitter=i,i.prototype._events=void 0,i.prototype._eventsCount=0,i.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?i.defaultMaxListeners:e._maxListeners}function c(e,t,r,n){var o,i,s,c;if(a(r),void 0===(i=e._events)?(i=e._events=Object.create(null),e._eventsCount=0):(void 0!==i.newListener&&(e.emit("newListener",t,r.listener?r.listener:r),i=e._events),s=i[t]),void 0===s)s=i[t]=r,++e._eventsCount;else if("function"==typeof s?s=i[t]=n?[r,s]:[s,r]:n?s.unshift(r):s.push(r),(o=l(e))>0&&s.length>o&&!s.warned){s.warned=!0;var u=new Error("Possible EventEmitter memory leak detected. "+s.length+" "+String(t)+" listeners added. Use emitter.setMaxListeners() to increase limit");u.name="MaxListenersExceededWarning",u.emitter=e,u.type=t,u.count=s.length,c=u,console&&console.warn&&console.warn(c)}return e}function u(){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 f(e,t,r){var n={fired:!1,wrapFn:void 0,target:e,type:t,listener:r},o=u.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):g(o,o.length)}function y(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 g(e,t){for(var r=new Array(t),n=0;n<t;++n)r[n]=e[n];return r}function h(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(i){n.once&&e.removeEventListener(t,o),r(i)})}}Object.defineProperty(i,"defaultMaxListeners",{enumerable:!0,get:function(){return s},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+".");s=e}}),i.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},i.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},i.prototype.getMaxListeners=function(){return l(this)},i.prototype.emit=function(e){for(var t=[],r=1;r<arguments.length;r++)t.push(arguments[r]);var o="error"===e,i=this._events;if(void 0!==i)o=o&&void 0===i.error;else if(!o)return!1;if(o){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=i[e];if(void 0===l)return!1;if("function"==typeof l)n(l,this,t);else{var c=l.length,u=g(l,c);for(r=0;r<c;++r)n(u[r],this,t)}return!0},i.prototype.addListener=function(e,t){return c(this,e,t,!1)},i.prototype.on=i.prototype.addListener,i.prototype.prependListener=function(e,t){return c(this,e,t,!0)},i.prototype.once=function(e,t){return a(t),this.on(e,f(this,e,t)),this},i.prototype.prependOnceListener=function(e,t){return a(t),this.prependListener(e,f(this,e,t)),this},i.prototype.removeListener=function(e,t){var r,n,o,i,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(o=-1,i=r.length-1;i>=0;i--)if(r[i]===t||r[i].listener===t){s=r[i].listener,o=i;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,s||t)}return this},i.prototype.off=i.prototype.removeListener,i.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,i=Object.keys(r);for(n=0;n<i.length;++n)"removeListener"!==(o=i[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},i.prototype.listeners=function(e){return p(this,e,!0)},i.prototype.rawListeners=function(e){return p(this,e,!1)},i.listenerCount=function(e,t){return"function"==typeof e.listenerCount?e.listenerCount(t):y.call(e,t)},i.prototype.listenerCount=y,i.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 i=t[n]={exports:{}};return e[n](i,i.exports,r),i.exports}r.d=(e,t)=>{if(Array.isArray(t))for(var n=0;n<t.length;){var o=t[n++],i=t[n++];r.o(e,o)?0===i&&n++:0===i?Object.defineProperty(e,o,{enumerable:!0,value:t[n++]}):Object.defineProperty(e,o,{enumerable:!0,get:i})}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,{TinyLocalStorage:()=>u});var o=r(7);function i(e){return null!==e&&"object"==typeof e&&!Array.isArray(e)&&"[object Object]"===Object.prototype.toString.call(e)}const s=new Map,a=new Map,l=new Set(["string","boolean","object","array",String,Boolean,Number,Object,Array,BigInt,Symbol]);class c extends o.EventEmitter{static hasJsonType(e){return s.has(e)&&a.has(e)||l.has(e)}static registerJsonType(e,t,r,n=!1){if(l.has(e))throw new Error(`Cannot register type "${e}" because it is frozen.`);s.set(e,t),a.set(e,r),n&&l.add(e)}static deleteJsonType(e){if(l.has(e))throw new Error(`Cannot remove type "${e}" because it is frozen.`);let t=!1;return s.delete(e)&&(t=!0),a.delete(e)&&(t=!0),t}static encodeSpecialJson(e){if(void 0===e)return{__undefined__:!0};if(null===e)return{__null__:!0};for(const[t,r]of s.entries())if("string"!=typeof t&&e instanceof t||typeof e===t)return r(e,c.encodeSpecialJson);if(Array.isArray(e))return e.map(c.encodeSpecialJson);if(i(e)){const t={};for(const r in e)t[r]=c.encodeSpecialJson(e[r]);return t}return e}static decodeSpecialJson(e){const t=i(e);if(t){if(e.__undefined__)return;if(e.__null__)return null}if(Array.isArray(e))return e.map(c.decodeSpecialJson);if(t){for(const[t,r]of a.entries())if(r.check&&r.check(e))return r.decode(e,c.decodeSpecialJson);const t={};for(const r in e)t[r]=c.decodeSpecialJson(e[r]);return t}return e}#e=window.localStorage;#t=null;#r=0;#n=e=>this.emit("storage",e);constructor(e){if(super(),void 0!==e&&"string"!=typeof e)throw new TypeError("TinyLocalStorage: dbName must be a string if provided.");"string"==typeof e&&(this.#t=`LSDB::${e}`),window.addEventListener("storage",this.#n)}#o(e){if("string"==typeof e&&e.startsWith("LSDB::"))throw new Error(`TinyLocalStorage: Key "${e}" may conflict with reserved dbKeys.`)}updateStorageVersion(e,t){if("string"!=typeof this.#t)throw new Error("TinyLocalStorage: Database key is not initialized. Set a valid dbName in the constructor.");if("number"!=typeof e||Number.isNaN(e)||e<1)throw new TypeError("TinyLocalStorage: version must be a positive number.");if("function"!=typeof t)throw new TypeError("TinyLocalStorage: onUpgrade must be a function.");const r=parseInt(localStorage.getItem(this.#t),10)||0;if("number"!=typeof r||Number.isNaN(r)||r<0)throw new TypeError("TinyLocalStorage: saved version in localStorage is not a valid number.");if(e<r)throw new Error(`TinyLocalStorage: Cannot downgrade database version from ${r} to ${e}.`);e>r&&(t(r,e),localStorage.setItem(this.#t,String(e)),this.#r=e)}getDbKey(){return this.#t}getVersion(){return this.#r}setLocalStorage(e){if(!(e instanceof Storage))throw new TypeError("Argument must be a valid instance of Storage.");this.#e=e}localStorageExists(){return this.#e instanceof Storage}#i(e,t){if("string"!=typeof e||!e.length)throw new TypeError("Key must be a non-empty string.");return c.encodeSpecialJson(t)}setJson(e,t){if(this.#o(e),!(i(t)||Array.isArray(t)||t instanceof Map||t instanceof Set))throw new TypeError("The storage value is not a valid JSON-compatible structure.");const r=this.#i(e,t);return this.emit("setJson",e,t),this.#e.setItem(e,JSON.stringify(r))}#s(e,t){if("string"!=typeof e||!e.length)throw new TypeError("Key must be a non-empty string.");const r=this.#e.getItem(e),n={obj:()=>({}),array:()=>[],map:()=>new Map,set:()=>new Set},o="function"==typeof n[t]?n[t]():null;let i;try{i=JSON.parse(r)}catch{return o}return{decoded:c.decodeSpecialJson(i),fallback:o}}getJson(e,t){const{decoded:r,fallback:n}=this.#s(e,t);return r instanceof Map||r instanceof Set||Array.isArray(r)||i(r)?r:n}setDate(e,t){if(this.#o(e),!(t instanceof Date))throw new TypeError("Value must be a Date.");const r=this.#i(e,t);return this.emit("setDate",e,t),this.#e.setItem(e,JSON.stringify(r))}getDate(e){const t=this.#s(e).decoded;return t instanceof Date?t:null}setRegExp(e,t){if(this.#o(e),!(t instanceof RegExp))throw new TypeError("Value must be a RegExp.");const r=this.#i(e,t);return this.emit("setRegExp",e,t),this.#e.setItem(e,JSON.stringify(r))}getRegExp(e){const t=this.#s(e).decoded;return t instanceof RegExp?t:null}setBigInt(e,t){if(this.#o(e),"bigint"!=typeof t)throw new TypeError("Value must be a BigInt.");const r=this.#i(e,t);return this.emit("setBigInt",e,t),this.#e.setItem(e,JSON.stringify(r))}getBigInt(e){const t=this.#s(e).decoded;return"bigint"==typeof t?t:null}setSymbol(e,t){if(this.#o(e),"symbol"!=typeof t)throw new TypeError("Value must be a Symbol.");const r=this.#i(e,t);return this.emit("setSymbol",e,t),this.#e.setItem(e,JSON.stringify(r))}getSymbol(e){const t=this.#s(e).decoded;return"symbol"==typeof t?t:null}getValue(e){return this.#s(e).decoded??null}setItem(e,t){if(this.#o(e),"string"!=typeof e||!e.length)throw new TypeError("Key must be a non-empty string.");return this.emit("setItem",e,t),this.#e.setItem(e,t)}getItem(e){if("string"!=typeof e||!e.length)throw new TypeError("Key must be a non-empty string.");return this.#e.getItem(e)}setString(e,t){if(this.#o(e),"string"!=typeof e||!e.length)throw new TypeError("Key must be a non-empty string.");if("string"!=typeof t)throw new TypeError("Value must be a string.");return this.emit("setString",e,t),this.#e.setItem(e,JSON.stringify({__string__:!0,value:t}))}getString(e){if("string"!=typeof e||!e.length)throw new TypeError("Key must be a non-empty string.");let t=this.#e.getItem(e);try{if(t=JSON.parse(t),!i(t)||!t.__string__||"string"!=typeof t.value)return null;t=t.value}catch{t=null}return"string"==typeof t?t:null}setNumber(e,t){if(this.#o(e),"string"!=typeof e||!e.length)throw new TypeError("Key must be a non-empty string.");if("number"!=typeof t)throw new TypeError("Value must be a number.");return this.emit("setNumber",e,t),this.#e.setItem(e,String(t))}getNumber(e){if("string"!=typeof e||!e.length)throw new TypeError("Key must be a non-empty string.");let t=this.#e.getItem(e);return"number"==typeof t||"string"==typeof t&&t.length>0&&(t=parseFloat(t),!Number.isNaN(t))?t:null}setBool(e,t){if(this.#o(e),"string"!=typeof e||!e.length)throw new TypeError("Key must be a non-empty string.");if("boolean"!=typeof t)throw new TypeError("Value must be a boolean.");return this.emit("setBool",e,t),this.#e.setItem(e,String(t))}getBool(e){if("string"!=typeof e||!e.length)throw new TypeError("Key must be a non-empty string.");const t=this.#e.getItem(e);if("boolean"==typeof t)return t;if("string"==typeof t){if("true"===t)return!0;if("false"===t)return!1}return null}removeItem(e){if("string"!=typeof e||!e.length)throw new TypeError("Key must be a non-empty string.");return this.emit("removeItem",e),this.#e.removeItem(e)}clearLocalStorage(){return this.#e.clear()}destroy(){window.removeEventListener("storage",this.#n),this.removeAllListeners()}}c.registerJsonType(Map,(e,t)=>({__map__:!0,data:Array.from(e.entries()).map(([e,r])=>[e,t(r)])}),{check:e=>e.__map__,decode:(e,t)=>new Map(e.data.map(([e,r])=>[e,t(r)]))},!0),c.registerJsonType(Set,(e,t)=>({__set__:!0,data:Array.from(e).map(t)}),{check:e=>e.__set__,decode:(e,t)=>new Set(e.data.map(t))},!0),c.registerJsonType(Date,e=>({__date__:!0,value:e.toISOString()}),{check:e=>e.__date__,decode:e=>new Date(e.value)},!0),c.registerJsonType(RegExp,e=>({__regexp__:!0,source:e.source,flags:e.flags}),{check:e=>e.__regexp__,decode:e=>new RegExp(e.source,e.flags)},!0),c.registerJsonType("number",e=>({__number__:!0,value:e.toString()}),{check:e=>e.__number__,decode:e=>Number(e.value)},!0),c.registerJsonType("bigint",e=>({__bigint__:!0,value:e.toString()}),{check:e=>e.__bigint__,decode:e=>BigInt(e.value)},!0),c.registerJsonType("symbol",e=>({__symbol__:!0,key:Symbol.keyFor(e)??e.description??null}),{check:e=>e.__symbol__,decode:e=>{const t=e.key;return null!=t?Symbol.for(t):Symbol()}},!0);const u=c;window.TinyLocalStorage=n.TinyLocalStorage})();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
(()=>{"use strict";const e={d:(t,r)=>{if(Array.isArray(r))for(var n=0;n<r.length;){var s=r[n++],i=r[n++];e.o(t,s)?0===i&&n++:0===i?Object.defineProperty(t,s,{enumerable:!0,value:r[n++]}):Object.defineProperty(t,s,{enumerable:!0,get:i})}else for(var s in r)e.o(r,s)&&!e.o(t,s)&&Object.defineProperty(t,s,{enumerable:!0,get:r[s]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t)};let t={};e.d(t,{TinyMediaPlayer:()=>c});const r=class{#e=new Map;#t=10;#r=!1;#n(e,t){if("string"==typeof e)return[e];if(Array.isArray(e)&&e.every(e=>"string"==typeof e))return e;throw new TypeError(`${t}(event): event must be a string or string[]`)}setThrowOnMaxListeners(e){if("boolean"!=typeof e)throw new TypeError("setThrowOnMaxListeners(value): value must be a boolean");this.#r=e}getThrowOnMaxListeners(){return this.#r}#s(e,t,{once:r=!1}={}){let n=this.#e.get(e);Array.isArray(n)||(n=[],this.#e.set(e,n)),n.unshift({handler:t,config:{once:r}});const s=this.#t;if(s>0&&n.length>s){const t=`Possible memory leak detected. ${n.length} "${e}" listeners added. Use setMaxListeners() to increase limit.`;if(this.#r)throw new Error(t);console.warn(t)}}prependListener(e,t){const r=this.#n(e,"prependListener");if("function"!=typeof t)throw new TypeError("prependListener(event, handler): handler must be a function");for(const e of r)this.#s(e,t)}prependListenerOnce(e,t){const r=this.#n(e,"prependListenerOnce");if("function"!=typeof t)throw new TypeError("prependListenerOnce(event, handler): handler must be a function");const n=[];for(const e of r){const r=(...n)=>{this.off(e,r),t(...n)};this.#s(e,r,{once:!0}),n.push(r)}return n}#i(e,t,{once:r=!1}={}){const n=this.#n(e,"on");for(const e of n){let n=this.#e.get(e);Array.isArray(n)||(n=[],this.#e.set(e,n)),n.push({handler:t,config:{once:r}});const s=this.#t;if(s>0&&n.length>s){const t=`Possible memory leak detected. ${n.length} "${e}" listeners added. Use setMaxListeners() to increase limit.`;if(this.#r)throw new Error(t);console.warn(t)}}}on(e,t){if("function"!=typeof t)throw new TypeError("on(event, handler): handler must be a function");return this.#i(e,t)}once(e,t){const r=this.#n(e,"once");if("function"!=typeof t)throw new TypeError("once(event, handler): handler must be a function");const n=[];for(const e of r){const r=(...n)=>{this.off(e,r),t(...n)};this.#i(e,r,{once:!0}),n.push(r)}return n}appendListener(e,t){return this.on(e,t)}appendListenerOnce(e,t){return this.once(e,t)}off(e,t){const r=this.#n(e,"off");if("function"!=typeof t)throw new TypeError("off(event, handler): handler must be a function");for(const e of r){const r=this.#e.get(e);if(!Array.isArray(r))continue;const n=r.findIndex(e=>e.handler===t);-1!==n&&r.splice(n,1),0===r.length&&this.#e.delete(e)}}offAll(e){const t=this.#n(e,"offAll");for(const e of t)this.#e.delete(e)}offAllTypes(){this.#e.clear()}removeAllListeners(){return this.offAllTypes()}listenerCount(e){if("string"!=typeof e)throw new TypeError("listenerCount(event): event name must be a string");const t=this.#e.get(e);return Array.isArray(t)?t.length:0}listeners(e){if("string"!=typeof e)throw new TypeError("listeners(event): event name must be a string");const t=this.#e.get(e);return Array.isArray(t)?[...t].filter(e=>!e.config.once).map(e=>e.handler):[]}onceListeners(e){if("string"!=typeof e)throw new TypeError("onceListeners(event): event name must be a string");const t=this.#e.get(e);return Array.isArray(t)?[...t].filter(e=>e.config.once).map(e=>e.handler):[]}allListeners(e){if("string"!=typeof e)throw new TypeError("allListeners(event): event name must be a string");const t=this.#e.get(e);return Array.isArray(t)?[...t].map(e=>e.handler):[]}eventNames(){return[...this.#e.keys()]}emit(e,...t){const r=this.#n(e,"emit"),n=[];for(const e of r){const r=this.#e.get(e);Array.isArray(r)&&0!==r.length?(r.forEach(e=>e.handler(...t)),n.push(!0)):n.push(!1)}return n}setMaxListeners(e){if(!Number.isInteger(e)||e<0)throw new TypeError("setMaxListeners(n): n must be a non-negative integer");this.#t=e}getMaxListeners(){return this.#t}},n=new Map;class s extends Error{constructor(e,t,r){super(e),this.name="MediaLoadingError",this.url=t,this.stage=r}}const i=async e=>{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)},o=(e,t="image/jpeg")=>{const r=e=>{const t=URL.createObjectURL(e),r=n.get(t);return n.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],s=atob(n),i=new Uint8Array(s.length);for(let e=0;e<s.length;e++)i[e]=s.charCodeAt(e);return r(new Blob([i],{type:t}))}return"string"==typeof e?e:""},a=(e,t)=>{const r=e=>t&&void 0===e,n=e=>r(e)||"string"==typeof e||null===e,s=(e,t)=>!!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(i=e.year,!r(i)&&"number"!=typeof i&&null!==i)throw new TypeError('Invalid metadata: "year" must be a number or null.');var i;if(!s(e.albumartists,e=>"string"==typeof e))throw new TypeError('Invalid metadata: "albumartists" must be an array of string.');if(!s(e.genre,e=>"string"==typeof e))throw new TypeError('Invalid metadata: "genre" must be an array of string.');if(!s(e.label,e=>"string"==typeof e))throw new TypeError('Invalid metadata: "label" must be an array of string.');if(!s(e.composer,e=>"string"==typeof e))throw new TypeError('Invalid metadata: "composer" must be an array of string.');if(!s(e.artists,e=>"string"==typeof e))throw new TypeError('Invalid metadata: "artists" must be an array of string.');if(!s(e.picture,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 o=(e,t)=>{if(!r(e)){if(null==e)throw new TypeError(`Invalid metadata: "${t}" is required.`);if("object"!=typeof e)throw new TypeError(`Invalid metadata: "${t}" must be an object or null.`);if("number"!=typeof e.no&&null!==e.no)throw new TypeError(`Invalid metadata: "${t}.no" must be a number or null.`);if("number"!=typeof e.of&&null!==e.of)throw new TypeError(`Invalid metadata: "${t}.of" must be a number or null.`)}};o(e.disk,"disk"),o(e.track,"track")},l=e=>a(e,!1);class h{constructor(){if(new.target===h)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 u extends r{static BaseMediaAdapter=h;static#o="Unknown Artist";static get unknownArtist(){return u.#o}static set unknownArtist(e){if("string"!=typeof e&&"function"!=typeof e)throw new TypeError("unknownArtist must have an string or function.");u.#o=e}static async parseContent(e,t,r,n,l){return(async(e,t={},r={},n=e=>new Promise((e,t)=>t(new TypeError("parseFile library not found."))),l={},h="null")=>{if("string"!=typeof e&&!(e instanceof HTMLMediaElement))throw new TypeError("Source must be a string or an HTMLMediaElement.");if(l.onProgress&&"function"!=typeof l.onProgress)throw new TypeError("callbacks.onProgress must be a function.");if(l.onError&&"function"!=typeof l.onError)throw new TypeError("callbacks.onError must be a function.");let u,c="";const p=(t,r)=>{l.onProgress&&l.onProgress({event:r,status:"loading",stage:t,url:c||(e instanceof HTMLMediaElement?e.src:"unknown")})},d=(t,r)=>{l.onError&&l.onError({error:t,url:c||(e instanceof HTMLMediaElement?e.src:"unknown"),stage:r})};try{p("INITIALIZING"),"string"==typeof e?(c=e,u=new Audio(c)):(u=e,c=u.src);try{await new Promise((e,t)=>{const r=e=>p("DOWNLOADING",e),n=()=>{i(),e(void 0)},s=e=>{i(),t(new Error(`HTMLMediaElement failed to load: ${e.message||"Unknown error"}`))},i=()=>{u.removeEventListener("progress",r),u.removeEventListener("loadedmetadata",n),u.removeEventListener("error",s)};u.addEventListener("progress",r),u.addEventListener("loadedmetadata",n),u.addEventListener("error",s),u.readyState>=1&&(i(),e(void 0))}),p("METADATA_LOADED")}catch(e){throw new s(e instanceof Error?e.message:"UNKNOWN ERROR",c,"METADATA")}const y={id:r.id||await i(c),duration:Math.floor(1e3*u.duration),url:c,weight:r.weight??1};let m={};p("EXTRACTING_ID3");try{m=await(async(e,t)=>{if("string"!=typeof e)throw new TypeError(`Expected url to be a string, but received ${typeof e}.`);if("function"!=typeof t)throw new TypeError(`Expected parseFile to be a function, but received ${typeof t}.`);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(),s=await t(n);if(!s||"object"!=typeof s.common)throw new TypeError('Invalid metadata: "common" property is missing or not an object.');const i=s.common;return(e=>{a(e,!0)})(i),{title:i?.title??null,album:i?.album??null,albumartist:i?.albumartist??null,albumartists:i?.albumartists??[],genre:i?.genre??[],label:i?.label??[],composer:i?.composer??[],year:i?.year??null,artist:i?.artist??null,artists:i?.artists??[],disk:i?.disk?{no:i.disk.no,of:i.disk.of}:{no:null,of:null},track:i?.track?{no:i.track.no,of:i.track.of}:{no:null,of:null},picture:i?.picture?.map(e=>({...e,data:o(e.data,e.format)}))??[]}}catch(e){throw e}})(c,n)}catch(e){d(e instanceof Error?e:new Error("Unknown Error"),"ID3"),console.warn(`[TinyAudioUtils] ID3 extraction failed for ${c}. Falling back to filename.`)}const f=e=>{try{return(e.split(/[?#]/)[0].split("/").pop()??"").replace(/\.[^/.]+$/,"")||"Unknown Track"}catch{return"Unknown Track"}},w={...y,...t,...m,...r,title:m.title||r.title||f(c),artist:m.artist||r.artist||("string"==typeof h?h:String(h()))};return l.onProgress&&l.onProgress({status:"success",stage:"COMPLETE",url:c}),w}catch(e){if(e instanceof s)throw e;{const t=new s(e instanceof Error?e.message:"UNKNOWN ERROR",c,"INITIALIZING");throw d(t,"INITIALIZING"),t}}})(e,t,r,n,l,u.#o)}#a=new Map;#l=[];#h=-1;#u="NONE";#c=!1;#p=!1;#d=1;#y;#m;constructor(e={}){super(),this.#y=Boolean(e.persistVolume),this.#m="string"==typeof e.volumeStorageKey?e.volumeStorageKey:"tiny_media_player_volume",this.#y&&this.#f()}#f(){try{if("undefined"!=typeof window&&window.localStorage){const e=window.localStorage.getItem(this.#m);if(null!==e){const t=parseFloat(e);!isNaN(t)&&t>=0&&t<=1&&(this.#d=t)}}}catch(e){console.warn("[TinyMediaPlayer] Failed to read volume from localStorage.",e)}}#w(){try{this.#y&&"undefined"!=typeof window&&window.localStorage&&window.localStorage.setItem(this.#m,this.#d.toString())}catch(e){console.warn("[TinyMediaPlayer] Failed to save volume to localStorage.",e)}}_getWeightedRandomIndex(){if(0===this.#l.length)return-1;if(1===this.#l.length)return 0;let e=0;for(let t=0;t<this.#l.length;t++){if(t===this.#h)continue;const r=this.#l[t];e+="number"==typeof r.weight&&r.weight>0?r.weight:1}let t=Math.random()*e;for(let e=0;e<this.#l.length;e++){if(e===this.#h)continue;const r=this.#l[e],n="number"==typeof r.weight&&r.weight>0?r.weight:1;if(t<n)return e;t-=n}return this.#h===this.#l.length-1?0:this.#l.length-1}get playlist(){return[...this.#l]}set playlist(e){if(!Array.isArray(e))throw new TypeError("Playlist must be an array of MediaContent objects.");e.forEach(e=>l(e));const t=this.#p;let r=null;if(-1!==this.#h&&this.#l.length>0)try{r=this.#g()}catch(e){}this.#l=e,this.emit("playlistUpdate",this.playlist),0===this.#l.length?this.#h=-1:(this.#h>=this.#l.length||-1===this.#h)&&(this.#h=0),this.emit("trackChange",this.#h),t&&(async()=>{try{r&&await r.stop(),-1!==this.#h&&await this.play()}catch(e){console.warn("[TinyMediaPlayer] Background transition error on playlist update:",e)}})()}get currentIndex(){return this.#h}set currentIndex(e){if("number"!=typeof e)throw new TypeError("Current index must be a number.");if(e<-1||e>=this.#l.length&&this.#l.length>0)throw new RangeError(`Index ${e} is out of bounds for the current playlist.`);if(this.#h===e)return;const t=this.#p;let r=null;if(-1!==this.#h&&this.#l.length>0)try{r=this.#g()}catch(e){}this.#h=e,this.emit("trackChange",this.#h),t&&(async()=>{try{r&&await r.stop(),-1!==this.#h&&await this.play()}catch(e){console.warn("[TinyMediaPlayer] Background transition error on index update:",e)}})()}get loopMode(){return this.#u}set loopMode(e){const t=["NONE","TRACK","PLAYLIST"];if(!t.includes(e))throw new TypeError(`Loop mode must be one of: ${t.join(", ")}.`);this.#u=e,this.emit("loopModeChange",this.#u)}get isRandom(){return this.#c}set isRandom(e){if("boolean"!=typeof e)throw new TypeError("Random mode state must be a boolean.");this.#c=e,this.emit("randomModeChange",this.#c)}get isPlaying(){return this.#p}get volume(){return this.#d}set volume(e){if("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.#d=e,this.#w(),this.emit("volumeChange",this.#d),-1!==this.#h&&this.#l.length>0)try{const e=this.#g();e&&e.setVolume(this.#d)}catch(e){}}get persistVolume(){return this.#y}set persistVolume(e){if("boolean"!=typeof e)throw new TypeError("Persist volume parameter must be a boolean.");this.#y=e,e&&this.#w()}get volumeStorageKey(){return this.#m}set volumeStorageKey(e){if("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.#m;this.#m=e;try{this.#y&&"undefined"!=typeof window&&window.localStorage&&(window.localStorage.removeItem(t),this.#w())}catch(e){console.warn("[TinyMediaPlayer] Failed to migrate volume storage key.",e)}}registerAdapter(e,t){if("string"!=typeof e)throw new TypeError("Adapter ID must be a string.");if(!(t instanceof h))throw new TypeError("Adapter must be an instance of BaseMediaAdapter.");this.#a.set(e,t)}#g(){if(-1===this.#h||0===this.#l.length)return null;const e=this.#l[this.#h];for(const t of this.#a.values())if(t.canHandle(e))return t;throw new Error(`No compatible adapter found for content ID: ${e.id}.`)}addTrack(e){if(!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};l(t);const r=this.#l.push(t);return-1===this.#h&&(this.#h=0,this.emit("trackChange",this.#h)),this.emit("playlistUpdate",this.playlist),r}existsTrack(e){if("number"!=typeof e)throw new TypeError("Index must be a number.");return e>=0&&e<this.#l.length}getTrack(e){if("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.#l[e]}async removeTrack(e){if("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.#h?(await this.stop(),this.#l.splice(e,1),0===this.#l.length?this.#h=-1:this.#h>=this.#l.length&&(this.#h=0),this.emit("trackChange",this.#h)):(this.#l.splice(e,1),e<this.#h&&(this.#h-=1,this.emit("trackChange",this.#h))),this.emit("playlistUpdate",this.playlist)}searchTrack(e){if("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.#l.length;r++){const n=this.#l[r];let s=!1;if("function"==typeof e)s=Boolean(e(n));else{const t=e.toLowerCase(),r=n.title&&n.title.toLowerCase().includes(t),i=n.artist&&n.artist.toLowerCase().includes(t),o=n.album&&n.album.toLowerCase().includes(t);s=Boolean(r||i||o)}s&&t.push({track:n,index:r})}return t}async clearPlaylist(){await this.stop(),this.#l=[],this.#h=-1,this.emit("playlistUpdate",this.playlist),this.emit("trackChange",this.#h)}async play(){const e=this.#g();e&&(e.setVolume(this.#d),await e.play(this.#l[this.#h]),this.#p=!0,this.emit("play",this.#h))}async pause(){const e=this.#g();e&&(await e.pause(),this.#p=!1,this.emit("pause",this.#h))}async stop(){const e=this.#g();e&&(await e.stop(),this.#p=!1,this.emit("stop",this.#h))}async next(){if(0!==this.#l.length)if(await this.stop(),"TRACK"!==this.#u){if(this.#c)this.#h=this._getWeightedRandomIndex();else{let e=this.#h+1;if(e>=this.#l.length){if("PLAYLIST"!==this.#u)return;e=0}this.#h=e}this.emit("trackChange",this.#h),await this.play()}else await this.play()}async prev(){if(0!==this.#l.length){if(await this.stop(),this.#c)this.#h=this._getWeightedRandomIndex();else{let e=this.#h-1;if(e<0){if("PLAYLIST"!==this.#u)return;e=this.#l.length-1}this.#h=e}this.emit("trackChange",this.#h),await this.play()}}async seek(e){if("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.#g();t&&(await t.seek(e),this.emit("seek",e))}async step(e){if("number"!=typeof e)throw new TypeError("Step amount must be a number in milliseconds.");const t=this.#g();if(!t)return;let r=t.getCurrentTime()+e;r<0&&(r=0),await this.seek(r)}}const c=u;window.TinyMediaPlayer=t.TinyMediaPlayer})();
|
|
1
|
+
(()=>{"use strict";var t={7(t){var e,r="object"==typeof Reflect?Reflect:null,n=r&&"function"==typeof r.apply?r.apply:function(t,e,r){return Function.prototype.apply.call(t,e,r)};e=r&&"function"==typeof r.ownKeys?r.ownKeys:Object.getOwnPropertySymbols?function(t){return Object.getOwnPropertyNames(t).concat(Object.getOwnPropertySymbols(t))}:function(t){return Object.getOwnPropertyNames(t)};var i=Number.isNaN||function(t){return t!=t};function o(){o.init.call(this)}t.exports=o,t.exports.once=function(t,e){return new Promise(function(r,n){function i(r){t.removeListener(e,o),n(r)}function o(){"function"==typeof t.removeListener&&t.removeListener("error",i),r([].slice.call(arguments))}f(t,e,o,{once:!0}),"error"!==e&&function(t,e){"function"==typeof t.on&&f(t,"error",e,{once:!0})}(t,i)})},o.EventEmitter=o,o.prototype._events=void 0,o.prototype._eventsCount=0,o.prototype._maxListeners=void 0;var s=10;function a(t){if("function"!=typeof t)throw new TypeError('The "listener" argument must be of type Function. Received type '+typeof t)}function l(t){return void 0===t._maxListeners?o.defaultMaxListeners:t._maxListeners}function u(t,e,r,n){var i,o,s,u;if(a(r),void 0===(o=t._events)?(o=t._events=Object.create(null),t._eventsCount=0):(void 0!==o.newListener&&(t.emit("newListener",e,r.listener?r.listener:r),o=t._events),s=o[e]),void 0===s)s=o[e]=r,++t._eventsCount;else if("function"==typeof s?s=o[e]=n?[r,s]:[s,r]:n?s.unshift(r):s.push(r),(i=l(t))>0&&s.length>i&&!s.warned){s.warned=!0;var c=new Error("Possible EventEmitter memory leak detected. "+s.length+" "+String(e)+" listeners added. Use emitter.setMaxListeners() to increase limit");c.name="MaxListenersExceededWarning",c.emitter=t,c.type=e,c.count=s.length,u=c,console&&console.warn&&console.warn(u)}return t}function c(){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(t,e,r){var n={fired:!1,wrapFn:void 0,target:t,type:e,listener:r},i=c.bind(n);return i.listener=r,n.wrapFn=i,i}function p(t,e,r){var n=t._events;if(void 0===n)return[];var i=n[e];return void 0===i?[]:"function"==typeof i?r?[i.listener||i]:[i]:r?function(t){for(var e=new Array(t.length),r=0;r<e.length;++r)e[r]=t[r].listener||t[r];return e}(i):y(i,i.length)}function d(t){var e=this._events;if(void 0!==e){var r=e[t];if("function"==typeof r)return 1;if(void 0!==r)return r.length}return 0}function y(t,e){for(var r=new Array(e),n=0;n<e;++n)r[n]=t[n];return r}function f(t,e,r,n){if("function"==typeof t.on)n.once?t.once(e,r):t.on(e,r);else{if("function"!=typeof t.addEventListener)throw new TypeError('The "emitter" argument must be of type EventEmitter. Received type '+typeof t);t.addEventListener(e,function i(o){n.once&&t.removeEventListener(e,i),r(o)})}}Object.defineProperty(o,"defaultMaxListeners",{enumerable:!0,get:function(){return s},set:function(t){if("number"!=typeof t||t<0||i(t))throw new RangeError('The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received '+t+".");s=t}}),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(t){if("number"!=typeof t||t<0||i(t))throw new RangeError('The value of "n" is out of range. It must be a non-negative number. Received '+t+".");return this._maxListeners=t,this},o.prototype.getMaxListeners=function(){return l(this)},o.prototype.emit=function(t){for(var e=[],r=1;r<arguments.length;r++)e.push(arguments[r]);var i="error"===t,o=this._events;if(void 0!==o)i=i&&void 0===o.error;else if(!i)return!1;if(i){var s;if(e.length>0&&(s=e[0]),s instanceof Error)throw s;var a=new Error("Unhandled error."+(s?" ("+s.message+")":""));throw a.context=s,a}var l=o[t];if(void 0===l)return!1;if("function"==typeof l)n(l,this,e);else{var u=l.length,c=y(l,u);for(r=0;r<u;++r)n(c[r],this,e)}return!0},o.prototype.addListener=function(t,e){return u(this,t,e,!1)},o.prototype.on=o.prototype.addListener,o.prototype.prependListener=function(t,e){return u(this,t,e,!0)},o.prototype.once=function(t,e){return a(e),this.on(t,h(this,t,e)),this},o.prototype.prependOnceListener=function(t,e){return a(e),this.prependListener(t,h(this,t,e)),this},o.prototype.removeListener=function(t,e){var r,n,i,o,s;if(a(e),void 0===(n=this._events))return this;if(void 0===(r=n[t]))return this;if(r===e||r.listener===e)0===--this._eventsCount?this._events=Object.create(null):(delete n[t],n.removeListener&&this.emit("removeListener",t,r.listener||e));else if("function"!=typeof r){for(i=-1,o=r.length-1;o>=0;o--)if(r[o]===e||r[o].listener===e){s=r[o].listener,i=o;break}if(i<0)return this;0===i?r.shift():function(t,e){for(;e+1<t.length;e++)t[e]=t[e+1];t.pop()}(r,i),1===r.length&&(n[t]=r[0]),void 0!==n.removeListener&&this.emit("removeListener",t,s||e)}return this},o.prototype.off=o.prototype.removeListener,o.prototype.removeAllListeners=function(t){var e,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[t]&&(0===--this._eventsCount?this._events=Object.create(null):delete r[t]),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(e=r[t]))this.removeListener(t,e);else if(void 0!==e)for(n=e.length-1;n>=0;n--)this.removeListener(t,e[n]);return this},o.prototype.listeners=function(t){return p(this,t,!0)},o.prototype.rawListeners=function(t){return p(this,t,!1)},o.listenerCount=function(t,e){return"function"==typeof t.listenerCount?t.listenerCount(e):d.call(t,e)},o.prototype.listenerCount=d,o.prototype.eventNames=function(){return this._eventsCount>0?e(this._events):[]}}};const e={};function r(n){const i=e[n];if(void 0!==i)return i.exports;const o=e[n]={exports:{}};return t[n](o,o.exports,r),o.exports}r.d=(t,e)=>{if(Array.isArray(e))for(var n=0;n<e.length;){var i=e[n++],o=e[n++];r.o(t,i)?0===o&&n++:0===o?Object.defineProperty(t,i,{enumerable:!0,value:e[n++]}):Object.defineProperty(t,i,{enumerable:!0,get:o})}else for(var i in e)r.o(e,i)&&!r.o(t,i)&&Object.defineProperty(t,i,{enumerable:!0,get:e[i]})},r.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e);let n={};r.d(n,{TinyMediaPlayer:()=>d});var i=r(7);const o=new Map;class s extends Error{constructor(t,e,r){super(t),this.name="MediaLoadingError",this.url=e,this.stage=r}}const a=async t=>{const e=(new TextEncoder).encode(t),r=await crypto.subtle.digest("SHA-1",e);return Array.from(new Uint8Array(r)).map(t=>t.toString(16).padStart(2,"0")).join("").substring(0,8)},l=(t,e="image/jpeg")=>{const r=t=>{const e=URL.createObjectURL(t),r=o.get(e);return o.set(e,"number"==typeof r?r+1:1),e};if(t instanceof Uint8Array)return r(new Blob([t],{type:e}));if("string"==typeof t&&t.startsWith("data:")){const n=t.split(",")[1],i=atob(n),o=new Uint8Array(i.length);for(let t=0;t<i.length;t++)o[t]=i.charCodeAt(t);return r(new Blob([o],{type:e}))}return"string"==typeof t?t:""},u=(t,e)=>{const r=t=>e&&void 0===t,n=t=>r(t)||"string"==typeof t||null===t,i=(t,e)=>!!r(t)||!(!Array.isArray(t)||!t.every(e));if(!n(t.title))throw new TypeError('Invalid metadata: "title" must be a string or null.');if(!n(t.album))throw new TypeError('Invalid metadata: "album" must be a string or null.');if(!n(t.albumartist))throw new TypeError('Invalid metadata: "albumartist" must be a string or null.');if(!n(t.artist))throw new TypeError('Invalid metadata: "artist" must be a string or null.');if(o=t.year,!r(o)&&"number"!=typeof o&&null!==o)throw new TypeError('Invalid metadata: "year" must be a number or null.');var o;if(!i(t.albumartists,t=>"string"==typeof t))throw new TypeError('Invalid metadata: "albumartists" must be an array of string.');if(!i(t.genre,t=>"string"==typeof t))throw new TypeError('Invalid metadata: "genre" must be an array of string.');if(!i(t.label,t=>"string"==typeof t))throw new TypeError('Invalid metadata: "label" must be an array of string.');if(!i(t.composer,t=>"string"==typeof t))throw new TypeError('Invalid metadata: "composer" must be an array of string.');if(!i(t.artists,t=>"string"==typeof t))throw new TypeError('Invalid metadata: "artists" must be an array of string.');if(!i(t.picture,t=>!(void 0!==t.description&&"string"!=typeof t.description||void 0!==t.name&&"string"!=typeof t.name||void 0!==t.type&&"string"!=typeof t.type||"string"!=typeof t.format||!(t.data instanceof Uint8Array||"string"==typeof t.data))))throw new TypeError('Invalid metadata: "picture" must be an array of pictures.');const s=(t,e)=>{if(!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.`)}};s(t.disk,"disk"),s(t.track,"track")},c=t=>u(t,!1);class h{constructor(){if(new.target===h)throw new Error("BaseMediaAdapter is an abstract class and cannot be instantiated directly.")}canHandle(t){throw new Error('Method "canHandle" must be implemented by the subclass.')}async play(t){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(t){throw new Error('Method "seek" must be implemented by the subclass.')}getCurrentTime(){throw new Error('Method "getCurrentTime" must be implemented by the subclass.')}setVolume(t){throw new Error('Method "setVolume" must be implemented by the subclass.')}}class p extends i.EventEmitter{static BaseMediaAdapter=h;static#t="Unknown Artist";static get unknownArtist(){return p.#t}static set unknownArtist(t){if("string"!=typeof t&&"function"!=typeof t)throw new TypeError("unknownArtist must have an string or function.");p.#t=t}static async parseContent(t,e,r,n,i){return(async(t,e={},r={},n=t=>new Promise((t,e)=>e(new TypeError("parseFile library not found."))),i={},o="null")=>{if("string"!=typeof t&&!(t instanceof HTMLMediaElement))throw new TypeError("Source must be a string or an HTMLMediaElement.");if(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.");let c,h="";const p=(e,r)=>{i.onProgress&&i.onProgress({event:r,status:"loading",stage:e,url:h||(t instanceof HTMLMediaElement?t.src:"unknown")})},d=(e,r)=>{i.onError&&i.onError({error:e,url:h||(t instanceof HTMLMediaElement?t.src:"unknown"),stage:r})};try{p("INITIALIZING"),"string"==typeof t?(h=t,c=new Audio(h)):(c=t,h=c.src);try{await new Promise((t,e)=>{const r=t=>p("DOWNLOADING",t),n=()=>{o(),t(void 0)},i=t=>{o(),e(new Error(`HTMLMediaElement failed to load: ${t.message||"Unknown error"}`))},o=()=>{c.removeEventListener("progress",r),c.removeEventListener("loadedmetadata",n),c.removeEventListener("error",i)};c.addEventListener("progress",r),c.addEventListener("loadedmetadata",n),c.addEventListener("error",i),c.readyState>=1&&(o(),t(void 0))}),p("METADATA_LOADED")}catch(t){throw new s(t instanceof Error?t.message:"UNKNOWN ERROR",h,"METADATA")}const y={id:r.id||await a(h),duration:Math.floor(1e3*c.duration),url:h,weight:r.weight??1};let f={};p("EXTRACTING_ID3");try{f=await(async(t,e)=>{if("string"!=typeof t)throw new TypeError(`Expected url to be a string, but received ${typeof t}.`);if("function"!=typeof e)throw new TypeError(`Expected parseFile to be a function, but received ${typeof e}.`);try{const r=await fetch(t);if(!r.ok)throw new Error(`Failed to fetch audio file: ${r.status} ${r.statusText}`);const n=await r.blob(),i=await e(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(t=>{u(t,!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(t=>({...t,data:l(t.data,t.format)}))??[]}}catch(t){throw t}})(h,n)}catch(t){d(t instanceof Error?t:new Error("Unknown Error"),"ID3"),console.warn(`[TinyAudioUtils] ID3 extraction failed for ${h}. Falling back to filename.`)}const m=t=>{try{return(t.split(/[?#]/)[0].split("/").pop()??"").replace(/\.[^/.]+$/,"")||"Unknown Track"}catch{return"Unknown Track"}},g={...y,...e,...f,...r,title:f.title||r.title||m(h),artist:f.artist||r.artist||("string"==typeof o?o:String(o()))};return i.onProgress&&i.onProgress({status:"success",stage:"COMPLETE",url:h}),g}catch(t){if(t instanceof s)throw t;{const e=new s(t instanceof Error?t.message:"UNKNOWN ERROR",h,"INITIALIZING");throw d(e,"INITIALIZING"),e}}})(t,e,r,n,i,p.#t)}#e=new Map;#r=[];#n=-1;#i="NONE";#o=!1;#s=!1;#a=1;#l;#u;constructor(t={}){super(),this.#l=Boolean(t.persistVolume),this.#u="string"==typeof t.volumeStorageKey?t.volumeStorageKey:"tiny_media_player_volume",this.#l&&this.#c()}#c(){try{if("undefined"!=typeof window&&window.localStorage){const t=window.localStorage.getItem(this.#u);if(null!==t){const e=parseFloat(t);!isNaN(e)&&e>=0&&e<=1&&(this.#a=e)}}}catch(t){console.warn("[TinyMediaPlayer] Failed to read volume from localStorage.",t)}}#h(){try{this.#l&&"undefined"!=typeof window&&window.localStorage&&window.localStorage.setItem(this.#u,this.#a.toString())}catch(t){console.warn("[TinyMediaPlayer] Failed to save volume to localStorage.",t)}}_getWeightedRandomIndex(){if(0===this.#r.length)return-1;if(1===this.#r.length)return 0;let t=0;for(let e=0;e<this.#r.length;e++){if(e===this.#n)continue;const r=this.#r[e];t+="number"==typeof r.weight&&r.weight>0?r.weight:1}let e=Math.random()*t;for(let t=0;t<this.#r.length;t++){if(t===this.#n)continue;const r=this.#r[t],n="number"==typeof r.weight&&r.weight>0?r.weight:1;if(e<n)return t;e-=n}return this.#n===this.#r.length-1?0:this.#r.length-1}get playlist(){return[...this.#r]}set playlist(t){if(!Array.isArray(t))throw new TypeError("Playlist must be an array of MediaContent objects.");t.forEach(t=>c(t));const e=this.#s;let r=null;if(-1!==this.#n&&this.#r.length>0)try{r=this.#p()}catch(t){}this.#r=t,this.emit("playlistUpdate",this.playlist),0===this.#r.length?this.#n=-1:(this.#n>=this.#r.length||-1===this.#n)&&(this.#n=0),this.emit("trackChange",this.#n),e&&(async()=>{try{r&&await r.stop(),-1!==this.#n&&await this.play()}catch(t){console.warn("[TinyMediaPlayer] Background transition error on playlist update:",t)}})()}get currentIndex(){return this.#n}set currentIndex(t){if("number"!=typeof t)throw new TypeError("Current index must be a number.");if(t<-1||t>=this.#r.length&&this.#r.length>0)throw new RangeError(`Index ${t} is out of bounds for the current playlist.`);if(this.#n===t)return;const e=this.#s;let r=null;if(-1!==this.#n&&this.#r.length>0)try{r=this.#p()}catch(t){}this.#n=t,this.emit("trackChange",this.#n),e&&(async()=>{try{r&&await r.stop(),-1!==this.#n&&await this.play()}catch(t){console.warn("[TinyMediaPlayer] Background transition error on index update:",t)}})()}get loopMode(){return this.#i}set loopMode(t){const e=["NONE","TRACK","PLAYLIST"];if(!e.includes(t))throw new TypeError(`Loop mode must be one of: ${e.join(", ")}.`);this.#i=t,this.emit("loopModeChange",this.#i)}get isRandom(){return this.#o}set isRandom(t){if("boolean"!=typeof t)throw new TypeError("Random mode state must be a boolean.");this.#o=t,this.emit("randomModeChange",this.#o)}get isPlaying(){return this.#s}get volume(){return this.#a}set volume(t){if("number"!=typeof t)throw new TypeError("Volume must be a number.");if(t<0||t>1)throw new RangeError("Volume must be tightly constrained between 0.0 and 1.0.");if(this.#a=t,this.#h(),this.emit("volumeChange",this.#a),-1!==this.#n&&this.#r.length>0)try{const t=this.#p();t&&t.setVolume(this.#a)}catch(t){}}get persistVolume(){return this.#l}set persistVolume(t){if("boolean"!=typeof t)throw new TypeError("Persist volume parameter must be a boolean.");this.#l=t,t&&this.#h()}get volumeStorageKey(){return this.#u}set volumeStorageKey(t){if("string"!=typeof t)throw new TypeError("Volume storage key must be a string.");if(""===t.trim())throw new TypeError("Volume storage key cannot be an empty string.");const e=this.#u;this.#u=t;try{this.#l&&"undefined"!=typeof window&&window.localStorage&&(window.localStorage.removeItem(e),this.#h())}catch(t){console.warn("[TinyMediaPlayer] Failed to migrate volume storage key.",t)}}registerAdapter(t,e){if("string"!=typeof t)throw new TypeError("Adapter ID must be a string.");if(!(e instanceof h))throw new TypeError("Adapter must be an instance of BaseMediaAdapter.");this.#e.set(t,e)}#p(){if(-1===this.#n||0===this.#r.length)return null;const t=this.#r[this.#n];for(const e of this.#e.values())if(e.canHandle(t))return e;throw new Error(`No compatible adapter found for content ID: ${t.id}.`)}addTrack(t){if(!t||"object"!=typeof t||"string"!=typeof t.url)throw new TypeError("Track content must be a valid MediaContent object containing a URL.");const e={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:[],...t};c(e);const r=this.#r.push(e);return-1===this.#n&&(this.#n=0,this.emit("trackChange",this.#n)),this.emit("playlistUpdate",this.playlist),r}existsTrack(t){if("number"!=typeof t)throw new TypeError("Index must be a number.");return t>=0&&t<this.#r.length}getTrack(t){if("number"!=typeof t)throw new TypeError("Index must be a number.");if(!this.existsTrack(t))throw new RangeError(`Index ${t} is out of bounds for the current playlist.`);return this.#r[t]}async removeTrack(t){if("number"!=typeof t)throw new TypeError("Index must be a number.");if(!this.existsTrack(t))throw new RangeError(`Index ${t} is out of bounds for the current playlist.`);t===this.#n?(await this.stop(),this.#r.splice(t,1),0===this.#r.length?this.#n=-1:this.#n>=this.#r.length&&(this.#n=0),this.emit("trackChange",this.#n)):(this.#r.splice(t,1),t<this.#n&&(this.#n-=1,this.emit("trackChange",this.#n))),this.emit("playlistUpdate",this.playlist)}searchTrack(t){if("string"!=typeof t&&"function"!=typeof t)throw new TypeError("Search query must be a string or a boolean evaluation function.");const e=[];for(let r=0;r<this.#r.length;r++){const n=this.#r[r];let i=!1;if("function"==typeof t)i=Boolean(t(n));else{const e=t.toLowerCase(),r=n.title&&n.title.toLowerCase().includes(e),o=n.artist&&n.artist.toLowerCase().includes(e),s=n.album&&n.album.toLowerCase().includes(e);i=Boolean(r||o||s)}i&&e.push({track:n,index:r})}return e}async clearPlaylist(){await this.stop(),this.#r=[],this.#n=-1,this.emit("playlistUpdate",this.playlist),this.emit("trackChange",this.#n)}async play(){const t=this.#p();t&&(t.setVolume(this.#a),await t.play(this.#r[this.#n]),this.#s=!0,this.emit("play",this.#n))}async pause(){const t=this.#p();t&&(await t.pause(),this.#s=!1,this.emit("pause",this.#n))}async stop(){const t=this.#p();t&&(await t.stop(),this.#s=!1,this.emit("stop",this.#n))}async next(){if(0!==this.#r.length)if(await this.stop(),"TRACK"!==this.#i){if(this.#o)this.#n=this._getWeightedRandomIndex();else{let t=this.#n+1;if(t>=this.#r.length){if("PLAYLIST"!==this.#i)return;t=0}this.#n=t}this.emit("trackChange",this.#n),await this.play()}else await this.play()}async prev(){if(0!==this.#r.length){if(await this.stop(),this.#o)this.#n=this._getWeightedRandomIndex();else{let t=this.#n-1;if(t<0){if("PLAYLIST"!==this.#i)return;t=this.#r.length-1}this.#n=t}this.emit("trackChange",this.#n),await this.play()}}async seek(t){if("number"!=typeof t)throw new TypeError("Seek time must be a number in milliseconds.");if(t<0)throw new RangeError("Seek time cannot be negative.");const e=this.#p();e&&(await e.seek(t),this.emit("seek",t))}async step(t){if("number"!=typeof t)throw new TypeError("Step amount must be a number in milliseconds.");const e=this.#p();if(!e)return;let r=e.getCurrentTime()+t;r<0&&(r=0),await this.seek(r)}}const d=p;window.TinyMediaPlayer=n.TinyMediaPlayer})();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
(()=>{"use strict";
|
|
1
|
+
(()=>{"use strict";var e={7(e){var t,n="object"==typeof Reflect?Reflect:null,r=n&&"function"==typeof n.apply?n.apply:function(e,t,n){return Function.prototype.apply.call(e,t,n)};t=n&&"function"==typeof n.ownKeys?n.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(n,r){function i(n){e.removeListener(t,o),r(n)}function o(){"function"==typeof e.removeListener&&e.removeListener("error",i),n([].slice.call(arguments))}c(e,t,o,{once:!0}),"error"!==t&&function(e,t){"function"==typeof e.on&&c(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 u(e){return void 0===e._maxListeners?o.defaultMaxListeners:e._maxListeners}function h(e,t,n,r){var i,o,s,h;if(a(n),void 0===(o=e._events)?(o=e._events=Object.create(null),e._eventsCount=0):(void 0!==o.newListener&&(e.emit("newListener",t,n.listener?n.listener:n),o=e._events),s=o[t]),void 0===s)s=o[t]=n,++e._eventsCount;else if("function"==typeof s?s=o[t]=r?[n,s]:[s,n]:r?s.unshift(n):s.push(n),(i=u(e))>0&&s.length>i&&!s.warned){s.warned=!0;var f=new Error("Possible EventEmitter memory leak detected. "+s.length+" "+String(t)+" listeners added. Use emitter.setMaxListeners() to increase limit");f.name="MaxListenersExceededWarning",f.emitter=e,f.type=t,f.count=s.length,h=f,console&&console.warn&&console.warn(h)}return e}function f(){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 l(e,t,n){var r={fired:!1,wrapFn:void 0,target:e,type:t,listener:n},i=f.bind(r);return i.listener=n,r.wrapFn=i,i}function v(e,t,n){var r=e._events;if(void 0===r)return[];var i=r[t];return void 0===i?[]:"function"==typeof i?n?[i.listener||i]:[i]:n?function(e){for(var t=new Array(e.length),n=0;n<t.length;++n)t[n]=e[n].listener||e[n];return t}(i):p(i,i.length)}function d(e){var t=this._events;if(void 0!==t){var n=t[e];if("function"==typeof n)return 1;if(void 0!==n)return n.length}return 0}function p(e,t){for(var n=new Array(t),r=0;r<t;++r)n[r]=e[r];return n}function c(e,t,n,r){if("function"==typeof e.on)r.once?e.once(t,n):e.on(t,n);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){r.once&&e.removeEventListener(t,i),n(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 u(this)},o.prototype.emit=function(e){for(var t=[],n=1;n<arguments.length;n++)t.push(arguments[n]);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 u=o[e];if(void 0===u)return!1;if("function"==typeof u)r(u,this,t);else{var h=u.length,f=p(u,h);for(n=0;n<h;++n)r(f[n],this,t)}return!0},o.prototype.addListener=function(e,t){return h(this,e,t,!1)},o.prototype.on=o.prototype.addListener,o.prototype.prependListener=function(e,t){return h(this,e,t,!0)},o.prototype.once=function(e,t){return a(t),this.on(e,l(this,e,t)),this},o.prototype.prependOnceListener=function(e,t){return a(t),this.prependListener(e,l(this,e,t)),this},o.prototype.removeListener=function(e,t){var n,r,i,o,s;if(a(t),void 0===(r=this._events))return this;if(void 0===(n=r[e]))return this;if(n===t||n.listener===t)0===--this._eventsCount?this._events=Object.create(null):(delete r[e],r.removeListener&&this.emit("removeListener",e,n.listener||t));else if("function"!=typeof n){for(i=-1,o=n.length-1;o>=0;o--)if(n[o]===t||n[o].listener===t){s=n[o].listener,i=o;break}if(i<0)return this;0===i?n.shift():function(e,t){for(;t+1<e.length;t++)e[t]=e[t+1];e.pop()}(n,i),1===n.length&&(r[e]=n[0]),void 0!==r.removeListener&&this.emit("removeListener",e,s||t)}return this},o.prototype.off=o.prototype.removeListener,o.prototype.removeAllListeners=function(e){var t,n,r;if(void 0===(n=this._events))return this;if(void 0===n.removeListener)return 0===arguments.length?(this._events=Object.create(null),this._eventsCount=0):void 0!==n[e]&&(0===--this._eventsCount?this._events=Object.create(null):delete n[e]),this;if(0===arguments.length){var i,o=Object.keys(n);for(r=0;r<o.length;++r)"removeListener"!==(i=o[r])&&this.removeAllListeners(i);return this.removeAllListeners("removeListener"),this._events=Object.create(null),this._eventsCount=0,this}if("function"==typeof(t=n[e]))this.removeListener(e,t);else if(void 0!==t)for(r=t.length-1;r>=0;r--)this.removeListener(e,t[r]);return this},o.prototype.listeners=function(e){return v(this,e,!0)},o.prototype.rawListeners=function(e){return v(this,e,!1)},o.listenerCount=function(e,t){return"function"==typeof e.listenerCount?e.listenerCount(t):d.call(e,t)},o.prototype.listenerCount=d,o.prototype.eventNames=function(){return this._eventsCount>0?t(this._events):[]}}};const t={};function n(r){const i=t[r];if(void 0!==i)return i.exports;const o=t[r]={exports:{}};return e[r](o,o.exports,n),o.exports}n.d=(e,t)=>{if(Array.isArray(t))for(var r=0;r<t.length;){var i=t[r++],o=t[r++];n.o(e,i)?0===o&&r++:0===o?Object.defineProperty(e,i,{enumerable:!0,value:t[r++]}):Object.defineProperty(e,i,{enumerable:!0,get:o})}else for(var i in t)n.o(t,i)&&!n.o(e,i)&&Object.defineProperty(e,i,{enumerable:!0,get:t[i]})},n.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t);let r={};n.d(r,{TinyNewWinEvents:()=>a});var i=n(7);const o=new WeakMap;class s extends i.EventEmitter{#e;#t;#n=[];#r=!1;#i=!1;#o=null;#s="__TNE_READY__";#a="__TNE_ROUTE__";get readyEventName(){return this.#s}set readyEventName(e){if("string"!=typeof e)throw new TypeError("TinyNewWinEvents: readyEventName must be a string.");this.#s=e}get routeEventName(){return this.#a}set routeEventName(e){if("string"!=typeof e)throw new TypeError("TinyNewWinEvents: routeEventName must be a string.");this.#a=e}constructor({targetOrigin:e,url:t,name:n,features:r}={}){if(super(),"string"==typeof n&&"_blank"===n)throw new Error('TinyNewWinEvents: The window name "_blank" is not supported. Please use a custom name to allow tracking.');if(void 0!==e&&"string"!=typeof e)throw new TypeError('TinyNewWinEvents: The "targetOrigin" option must be a string.');if(void 0!==t&&"string"!=typeof t)throw new TypeError('TinyNewWinEvents: The "url" option must be a string.');if(void 0!==r&&"string"!=typeof r)throw new TypeError('TinyNewWinEvents: The "features" option must be a string if provided.');if(void 0===t?this.#e=window.opener:(this.#e="string"==typeof t?window.open(t,n,r):t,this.#i=!0),!this.#e||o.has(this.#e))throw new Error("Invalid or duplicate window reference.");this.#t=e??window.location.origin,this._handleMessage=this.#u.bind(this),window.addEventListener("message",this._handleMessage,!1),this.#i||(this.#h(this.#s,null),this.#f())}getWin(){return this.#e}#u(e){if(!e.source||this.#e&&e.source!==this.#e)return;const{type:t,route:n,payload:r}=e.data||{};if(t===this.#s)return this.#r=!0,this.#l(),this.#f(),void(this.#i&&this.#h(this.#s,null));t===this.#a&&this.emit(`win:${n}`,r,e)}#l(){for(;this.#n.length;){const e=this.#n.shift();if(e){const{route:t,payload:n}=e;this.winEmit(t,n)}}}#h(e,t,n=""){this.#e&&this.#e.closed||this.#e?.postMessage({type:e,route:n,payload:t},this.#t)}close(){if(!this.#i)throw new Error("Only host can close the window.");this.#e&&!this.#e.closed&&this.#e.close()}winEmit(e,t){if("string"!=typeof e)throw new TypeError("Event name must be a string.");if(this.isDestroyed())throw new Error("Cannot emit: instance has been destroyed.");this.#r?this.#h(this.#a,t,e):this.#n.push({route:e,payload:t})}isConnected(){return!(!this.#r||!this.#e||this.#e.closed)}#f(){this.#e&&!this.#o&&(this.#o=setInterval(()=>{this.#e?.closed&&(this.emit("WINDOW_REF_CLOSED"),this.destroy())},500),o.set(this.#e,this.#o))}onClose(e){this.on("WINDOW_REF_CLOSED",e)}offClose(e){this.off("WINDOW_REF_CLOSED",e)}isDestroyed(){return!this.#e}destroy(){this.#e&&(this.#o&&(clearInterval(this.#o),this.#o=null,o.delete(this.#e)),window.removeEventListener("message",this._handleMessage),this.#n=[],this.#r=!1,this.#e=null,this.removeAllListeners())}}const a=s;window.TinyNewWinEvents=r.TinyNewWinEvents})();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
(()=>{"use strict";const t={d:(e,i)=>{if(Array.isArray(i))for(var n=0;n<i.length;){var r=i[n++],s=i[n++];t.o(e,r)?0===s&&n++:0===s?Object.defineProperty(e,r,{enumerable:!0,value:i[n++]}):Object.defineProperty(e,r,{enumerable:!0,get:s})}else for(var r in i)t.o(i,r)&&!t.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:i[r]})},o:(t,e)=>Object.prototype.hasOwnProperty.call(t,e)};let e={};t.d(e,{TinyRadioFm:()=>d});const i=new Map;class n extends Error{constructor(t,e,i){super(t),this.name="MediaLoadingError",this.url=e,this.stage=i}}const r=async t=>{const e=(new TextEncoder).encode(t),i=await crypto.subtle.digest("SHA-1",e);return Array.from(new Uint8Array(i)).map(t=>t.toString(16).padStart(2,"0")).join("").substring(0,8)},s=(t,e="image/jpeg")=>{const n=t=>{const e=URL.createObjectURL(t),n=i.get(e);return i.set(e,"number"==typeof n?n+1:1),e};if(t instanceof Uint8Array)return n(new Blob([t],{type:e}));if("string"==typeof t&&t.startsWith("data:")){const i=t.split(",")[1],r=atob(i),s=new Uint8Array(r.length);for(let t=0;t<r.length;t++)s[t]=r.charCodeAt(t);return n(new Blob([s],{type:e}))}return"string"==typeof t?t:""},o=async t=>{if("string"!=typeof t||!t.startsWith("blob:"))return t;try{const e=await fetch(t),i=await e.blob();return await new Promise((t,e)=>{const n=new FileReader;n.onloadend=()=>t(String(n.result)),n.onerror=e,n.readAsDataURL(i)})}catch(e){return console.warn(`[TinyAudioUtils] Failed to convert Blob URL to Base64 on export: ${t}`,e),t}},a=t=>{t&&Array.isArray(t.picture)&&t.picture.forEach(t=>{if("string"==typeof t.data&&t.data.startsWith("blob:")){const e=i.get(t.data)??0;e>1?i.set(t.data,e-1):i.delete(t.data),e<=1&&URL.revokeObjectURL(t.data)}})},c=async(t,e)=>{if("string"!=typeof t)throw new TypeError(`Expected url to be a string, but received ${typeof t}.`);if("function"!=typeof e)throw new TypeError(`Expected parseFile to be a function, but received ${typeof e}.`);try{const i=await fetch(t);if(!i.ok)throw new Error(`Failed to fetch audio file: ${i.status} ${i.statusText}`);const n=await i.blob(),r=await e(n);if(!r||"object"!=typeof r.common)throw new TypeError('Invalid metadata: "common" property is missing or not an object.');const o=r.common;return(t=>{((t,e)=>{const i=t=>e&&void 0===t,n=t=>i(t)||"string"==typeof t||null===t,r=(t,e)=>!!i(t)||!(!Array.isArray(t)||!t.every(e));if(!n(t.title))throw new TypeError('Invalid metadata: "title" must be a string or null.');if(!n(t.album))throw new TypeError('Invalid metadata: "album" must be a string or null.');if(!n(t.albumartist))throw new TypeError('Invalid metadata: "albumartist" must be a string or null.');if(!n(t.artist))throw new TypeError('Invalid metadata: "artist" must be a string or null.');if(s=t.year,!i(s)&&"number"!=typeof s&&null!==s)throw new TypeError('Invalid metadata: "year" must be a number or null.');var s;if(!r(t.albumartists,t=>"string"==typeof t))throw new TypeError('Invalid metadata: "albumartists" must be an array of string.');if(!r(t.genre,t=>"string"==typeof t))throw new TypeError('Invalid metadata: "genre" must be an array of string.');if(!r(t.label,t=>"string"==typeof t))throw new TypeError('Invalid metadata: "label" must be an array of string.');if(!r(t.composer,t=>"string"==typeof t))throw new TypeError('Invalid metadata: "composer" must be an array of string.');if(!r(t.artists,t=>"string"==typeof t))throw new TypeError('Invalid metadata: "artists" must be an array of string.');if(!r(t.picture,t=>!(void 0!==t.description&&"string"!=typeof t.description||void 0!==t.name&&"string"!=typeof t.name||void 0!==t.type&&"string"!=typeof t.type||"string"!=typeof t.format||!(t.data instanceof Uint8Array||"string"==typeof t.data))))throw new TypeError('Invalid metadata: "picture" must be an array of pictures.');const o=(t,e)=>{if(!i(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.`)}};o(t.disk,"disk"),o(t.track,"track")})(t,!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(t=>({...t,data:s(t.data,t.format)}))??[]}}catch(t){throw t}},l=class{#t=new Map;#e=10;#i=!1;#n(t,e){if("string"==typeof t)return[t];if(Array.isArray(t)&&t.every(t=>"string"==typeof t))return t;throw new TypeError(`${e}(event): event must be a string or string[]`)}setThrowOnMaxListeners(t){if("boolean"!=typeof t)throw new TypeError("setThrowOnMaxListeners(value): value must be a boolean");this.#i=t}getThrowOnMaxListeners(){return this.#i}#r(t,e,{once:i=!1}={}){let n=this.#t.get(t);Array.isArray(n)||(n=[],this.#t.set(t,n)),n.unshift({handler:e,config:{once:i}});const r=this.#e;if(r>0&&n.length>r){const e=`Possible memory leak detected. ${n.length} "${t}" listeners added. Use setMaxListeners() to increase limit.`;if(this.#i)throw new Error(e);console.warn(e)}}prependListener(t,e){const i=this.#n(t,"prependListener");if("function"!=typeof e)throw new TypeError("prependListener(event, handler): handler must be a function");for(const t of i)this.#r(t,e)}prependListenerOnce(t,e){const i=this.#n(t,"prependListenerOnce");if("function"!=typeof e)throw new TypeError("prependListenerOnce(event, handler): handler must be a function");const n=[];for(const t of i){const i=(...n)=>{this.off(t,i),e(...n)};this.#r(t,i,{once:!0}),n.push(i)}return n}#s(t,e,{once:i=!1}={}){const n=this.#n(t,"on");for(const t of n){let n=this.#t.get(t);Array.isArray(n)||(n=[],this.#t.set(t,n)),n.push({handler:e,config:{once:i}});const r=this.#e;if(r>0&&n.length>r){const e=`Possible memory leak detected. ${n.length} "${t}" listeners added. Use setMaxListeners() to increase limit.`;if(this.#i)throw new Error(e);console.warn(e)}}}on(t,e){if("function"!=typeof e)throw new TypeError("on(event, handler): handler must be a function");return this.#s(t,e)}once(t,e){const i=this.#n(t,"once");if("function"!=typeof e)throw new TypeError("once(event, handler): handler must be a function");const n=[];for(const t of i){const i=(...n)=>{this.off(t,i),e(...n)};this.#s(t,i,{once:!0}),n.push(i)}return n}appendListener(t,e){return this.on(t,e)}appendListenerOnce(t,e){return this.once(t,e)}off(t,e){const i=this.#n(t,"off");if("function"!=typeof e)throw new TypeError("off(event, handler): handler must be a function");for(const t of i){const i=this.#t.get(t);if(!Array.isArray(i))continue;const n=i.findIndex(t=>t.handler===e);-1!==n&&i.splice(n,1),0===i.length&&this.#t.delete(t)}}offAll(t){const e=this.#n(t,"offAll");for(const t of e)this.#t.delete(t)}offAllTypes(){this.#t.clear()}removeAllListeners(){return this.offAllTypes()}listenerCount(t){if("string"!=typeof t)throw new TypeError("listenerCount(event): event name must be a string");const e=this.#t.get(t);return Array.isArray(e)?e.length:0}listeners(t){if("string"!=typeof t)throw new TypeError("listeners(event): event name must be a string");const e=this.#t.get(t);return Array.isArray(e)?[...e].filter(t=>!t.config.once).map(t=>t.handler):[]}onceListeners(t){if("string"!=typeof t)throw new TypeError("onceListeners(event): event name must be a string");const e=this.#t.get(t);return Array.isArray(e)?[...e].filter(t=>t.config.once).map(t=>t.handler):[]}allListeners(t){if("string"!=typeof t)throw new TypeError("allListeners(event): event name must be a string");const e=this.#t.get(t);return Array.isArray(e)?[...e].map(t=>t.handler):[]}eventNames(){return[...this.#t.keys()]}emit(t,...e){const i=this.#n(t,"emit"),n=[];for(const t of i){const i=this.#t.get(t);Array.isArray(i)&&0!==i.length?(i.forEach(t=>t.handler(...e)),n.push(!0)):n.push(!1)}return n}setMaxListeners(t){if(!Number.isInteger(t)||t<0)throw new TypeError("setMaxListeners(n): n must be a non-negative integer");this.#e=t}getMaxListeners(){return this.#e}};class u extends l{static async parseContent(t,e,i,s,o){return(async(t,e={},i={},s=t=>new Promise((t,e)=>e(new TypeError("parseFile library not found."))),o={},a="null")=>{if("string"!=typeof t&&!(t instanceof HTMLMediaElement))throw new TypeError("Source must be a string or an HTMLMediaElement.");if(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.");let l,u="";const d=(e,i)=>{o.onProgress&&o.onProgress({event:i,status:"loading",stage:e,url:u||(t instanceof HTMLMediaElement?t.src:"unknown")})},h=(e,i)=>{o.onError&&o.onError({error:e,url:u||(t instanceof HTMLMediaElement?t.src:"unknown"),stage:i})};try{d("INITIALIZING"),"string"==typeof t?(u=t,l=new Audio(u)):(l=t,u=l.src);try{await new Promise((t,e)=>{const i=t=>d("DOWNLOADING",t),n=()=>{s(),t(void 0)},r=t=>{s(),e(new Error(`HTMLMediaElement failed to load: ${t.message||"Unknown error"}`))},s=()=>{l.removeEventListener("progress",i),l.removeEventListener("loadedmetadata",n),l.removeEventListener("error",r)};l.addEventListener("progress",i),l.addEventListener("loadedmetadata",n),l.addEventListener("error",r),l.readyState>=1&&(s(),t(void 0))}),d("METADATA_LOADED")}catch(t){throw new n(t instanceof Error?t.message:"UNKNOWN ERROR",u,"METADATA")}const m={id:i.id||await r(u),duration:Math.floor(1e3*l.duration),url:u,weight:i.weight??1};let f={};d("EXTRACTING_ID3");try{f=await c(u,s)}catch(t){h(t instanceof Error?t:new Error("Unknown Error"),"ID3"),console.warn(`[TinyAudioUtils] ID3 extraction failed for ${u}. Falling back to filename.`)}const p=t=>{try{return(t.split(/[?#]/)[0].split("/").pop()??"").replace(/\.[^/.]+$/,"")||"Unknown Track"}catch{return"Unknown Track"}},y={...m,...e,...f,...i,title:f.title||i.title||p(u),artist:f.artist||i.artist||("string"==typeof a?a:String(a()))};return o.onProgress&&o.onProgress({status:"success",stage:"COMPLETE",url:u}),y}catch(t){if(t instanceof n)throw t;{const e=new n(t instanceof Error?t.message:"UNKNOWN ERROR",u,"INITIALIZING");throw h(e,"INITIALIZING"),e}}})(t,e,i,s,o,u.#o)}static#o="Unknown Artist";static get unknownArtist(){return u.#o}static set unknownArtist(t){if("string"!=typeof t&&"function"!=typeof t)throw new TypeError("unknownArtist must have an string or function.");u.#o=t}get size(){return this.#a.length+this.#c.length}get musicSize(){return this.#a.length}get voiceSize(){return this.#c.length}get customPosSize(){return this.#l.length}get tasksSize(){return this.#u.length}get cycleCacheSize(){return this.#d.size}#a=[];get musicList(){return structuredClone(this.#a)}#c=[];get voiceList(){return structuredClone(this.#c)}#l=[];get customPositions(){return structuredClone(this.#l)}#u=[];get scheduledTasks(){return structuredClone(this.#u)}get allList(){return[...this.musicList,...this.voiceList]}#h=0;get seed(){return this.#h}set seed(t){if("number"!=typeof t)throw new TypeError("Seed must be a number.");this.#h=t,this.#d.clear(),this.emit("seedChanged",{seed:t})}#m=Date.now();get anchorDate(){return this.#m}#d=new Map;#f={mode:"playlist",voiceMode:"playlist",silenceDuration:0,queryLimit:1e5,voiceAfterMusic:!0,voiceMin:0,voiceMax:1,musicMaxConsecutive:0,voiceMaxConsecutive:0};get config(){return structuredClone(this.#f)}set config(t){this.#p(t),this.#f=structuredClone(t),this.#d.clear(),this.emit("configChanged",{config:this.config})}#p(t){if("object"!=typeof t||null===t)throw new TypeError("Configuration must be a valid object.");const e=["playlist","random"];if(void 0!==t.mode&&!e.includes(t.mode))throw new TypeError(`Invalid mode: "${t.mode}". Must be one of: ${e.join(", ")}.`);if(void 0!==t.voiceMode&&!e.includes(t.voiceMode))throw new TypeError(`Invalid voiceMode: "${t.voiceMode}". Must be one of: ${e.join(", ")}.`);if(void 0!==t.silenceDuration&&("number"!=typeof t.silenceDuration||t.silenceDuration<0))throw new TypeError("silenceDuration must be a non-negative number.");if(void 0!==t.queryLimit&&("number"!=typeof t.queryLimit||t.queryLimit<=0))throw new TypeError("queryLimit must be a positive number.");if(void 0!==t.voiceAfterMusic&&"boolean"!=typeof t.voiceAfterMusic)throw new TypeError("voiceAfterMusic must be a boolean.");if(void 0!==t.voiceMin&&("number"!=typeof t.voiceMin||t.voiceMin<0))throw new TypeError("voiceMin must be a non-negative number.");if(void 0!==t.voiceMax&&("number"!=typeof t.voiceMax||t.voiceMax<0))throw new TypeError("voiceMax must be a non-negative number.");if(void 0!==t.musicMaxConsecutive&&("number"!=typeof t.musicMaxConsecutive||t.musicMaxConsecutive<-1))throw new TypeError("musicMaxConsecutive must be a number >= -1.");if(void 0!==t.voiceMaxConsecutive&&("number"!=typeof t.voiceMaxConsecutive||t.voiceMaxConsecutive<-1))throw new TypeError("voiceMaxConsecutive must be a number >= -1.");const i=t.voiceMin??this.#f.voiceMin,n=t.voiceMax??this.#f.voiceMax;if(n<i)throw new RangeError(`Logical error: voiceMax (${n}) cannot be less than voiceMin (${i}).`)}constructor(t=null,e=0){if(super(),null!==t&&"object"!=typeof t)throw new TypeError("initialData must be an object or null.");if("number"!=typeof e)throw new TypeError("seed must be a number.");this.#h=e,t?this.#y(t):this.#m=Date.now()}add(t,e,i=!0){if(!["music","voice","custom"].includes(t))throw new TypeError('Type must be "music", "voice", or "custom".');if(!e||"string"!=typeof e.id||"number"!=typeof e.duration)throw new TypeError("Content must have a string ID and a valid numerical duration in milliseconds.");if("boolean"!=typeof i)throw new TypeError("smartQueue must be a boolean.");"music"===t?(this.#a.push(e),this.#d.clear()):"voice"===t?(this.#c.push(e),this.#d.clear()):"custom"===t&&this.#g(e,i),this.#w(Date.now()),this.emit("contentAdded",{type:t,data:structuredClone(e)})}scheduleTask(t,e,i,n,r=!0){if("number"!=typeof t||isNaN(t))throw new TypeError("timestamp must be a valid number.");if(!["add","remove","move"].includes(e))throw new TypeError('action must be "add", "remove", or "move".');if(!["music","voice"].includes(i))throw new TypeError('type must be "music" or "voice".');if("boolean"!=typeof r)throw new TypeError("smartQueue must be a boolean.");if("add"===e){if("object"!=typeof n||null===n||"string"!=typeof n.id||"number"!=typeof n.duration)throw new TypeError('Payload for "add" must be a MediaContent object (id: string, duration: number).')}else if("remove"===e){if("string"!=typeof n)throw new TypeError('Payload for "remove" must be a string (the content ID).')}else if("move"===e&&("object"!=typeof n||null===n||"string"!=typeof n.id||"number"!=typeof n.newIndex))throw new TypeError('Payload for "move" must be a ScheduledMovePayload (id: string, newIndex: number).');let s=t;if(r){const e=this.#v(t,t);e&&(s=e.absoluteEnd)}const o={timestamp:s,action:e,type:i,payload:n};this.#u.push(o),this.#w(Date.now()),this.emit("taskScheduled",structuredClone(o))}remove(t){if("string"!=typeof t)throw new TypeError("id must be a string.");this.#a.filter(e=>e.id===t).forEach(t=>a(t)),this.#c.filter(e=>e.id===t).forEach(t=>a(t)),this.#l.filter(e=>e.content?.id===t).forEach(t=>a(t.content));const e=e=>e.id!==t&&e.content?.id!==t;this.#a=this.#a.filter(e),this.#c=this.#c.filter(e),this.#l=this.#l.filter(e),this.#u=this.#u.filter(e=>"add"===e.action&&"object"==typeof e.payload&&null!==e.payload&&"id"in e.payload?e.payload.id!==t||(a(e.payload),!1):e.payload!==t),this.#d.clear(),this.emit("contentRemoved",{id:t})}setConfig(t){this.#p(t);const e={...this.#f,...t};this.#p(e),this.#f=e,this.#d.clear(),this.emit("configChanged",{config:this.config})}getCurrentEvent(){const t=Date.now();return this.#w(t),this.#v(t,t)}queryTimeline(t,e=10){if("number"!=typeof e||isNaN(e))throw new TypeError("Invalid query limit value. Ensure it is a number.");if(e>this.#f.queryLimit||e<=0)throw new RangeError(`Invalid query limit. Ensure it is > 0 and <= ${this.#f.queryLimit}.`);const i=new u(JSON.parse(this._exportState())),n=[];let r=t;for(let s=0;s<e;s++){i.#w(r);const e=i.#b(r,t);if(!e)break;n.push(e),r=e.absoluteEnd}return i.destroy(!1),this.emit("timelineQueried",{targetDate:t,limit:e,resultCount:n.length}),n}searchCustomPositions(){return this.#w(Date.now()),[...this.#l]}async _processListForExport(t){return Promise.all(t.map(async t=>{const e=structuredClone(t);return e.picture&&Array.isArray(e.picture)&&(e.picture=await Promise.all(e.picture.map(async t=>({...t,data:await o(t.data)})))),e}))}_exportState(){return JSON.stringify({music:this.#a,voice:this.#c,custom:this.#l,tasks:this.#u,seed:this.#h,anchorDate:this.#m,config:this.#f})}async exportState(){const t=await this._processListForExport(this.#a),e=await this._processListForExport(this.#c),i=await Promise.all(this.#l.map(async t=>{const e=await this._processListForExport([t.content]);return{...t,content:e[0]}})),n=await Promise.all(this.#u.map(async t=>{if("add"===t.action&&t.payload&&"object"==typeof t.payload&&"title"in t.payload){const e=await this._processListForExport([t.payload]);return{...t,payload:e[0]}}return t}));return JSON.stringify({music:t,voice:e,custom:i,tasks:n,seed:this.#h,anchorDate:this.#m,config:this.#f})}importState(t){let e;if("string"==typeof t)try{e=JSON.parse(t)}catch{throw new TypeError("Provided string is not valid JSON.")}else{if("object"!=typeof t||null===t)throw new TypeError("Import data must be a valid JSON string or an object.");e=t}this.#y(e),this.emit("stateImported",{data:structuredClone(e)})}_prng(t){return function(){let e=t+=1831565813;return e=Math.imul(e^e>>>15,1|e),e^=e+Math.imul(e^e>>>7,61|e),((e^e>>>14)>>>0)/4294967296}}#E(t,e,i,n=0){if(0===t.length)return[];if("random"!==i)return[...t];const r=t.map(t=>({...t,weight:t.weight??1})),s=this._prng(e),o=[];let a=null,c=0;for(;r.length>0;){let t=r;-1!==n&&null!==a&&c>n&&(t=r.filter(t=>t.id!==a),0===t.length&&(t=r));const e=t.reduce((t,e)=>t+e.weight,0);if(e<=0){o.push(...t);break}const i=s()*e;let l=0,u=null,d=-1;for(let e=0;e<t.length;e++)if(l+=t[e].weight,i<=l){u=t[e],d=r.findIndex(t=>u&&t.id===u.id);break}u&&-1!==d||(u=t[0],d=r.findIndex(t=>u&&t.id===u.id)),o.push(u),r.splice(d,1),u.id===a?c++:(a=u.id,c=1)}return o}#T(t){const e=this.#h+t,i=this._prng(10*e),n=this.#E(this.#a,e+1,this.#f.mode,this.#f.musicMaxConsecutive),r=this.#E(this.#c,e+2,this.#f.voiceMode,this.#f.voiceMaxConsecutive),s=[];let o=0,a=0;for(let t=0;t<n.length;t++){const e=n[t];if(s.push({...e,cycleStart:o,cycleEnd:o+e.duration}),o+=e.duration+this.#f.silenceDuration,this.#f.voiceAfterMusic&&r.length>0){const t=this.#f.voiceMax-this.#f.voiceMin+1,e=Math.floor(i()*t)+this.#f.voiceMin;for(let t=0;t<e;t++){const t=r[a%r.length];a++,s.push({...t,cycleStart:o,cycleEnd:o+t.duration}),o+=t.duration+this.#f.silenceDuration}}}return{items:s,duration:o}}#L(t){if(0===this.#a.length)return null;let e=this.#m,i=0;for(;;){if(i>this.#f.queryLimit)throw new Error("Safety limit hit during cycle location.");let n=this.#d.get(i);if(n||(n=this.#T(i),this.#d.set(i,n)),0===n.duration)return null;if(t>=e&&t<e+n.duration)return{block:n,startTimestamp:e,loopIndex:i};e+=n.duration,i++}}#b(t,e){const i=this.#l.filter(e=>e.intendedTimestamp+e.content.duration>t).sort((t,e)=>t.intendedTimestamp-e.intendedTimestamp)[0];let n=null;if(i){const t=Math.max(e,i.intendedTimestamp);n=this.#M(i.content,i.intendedTimestamp,t,!0)}const r=this.#A(t,e);return r||n?r?n?n.absoluteStart<=r.absoluteStart?n:(n.absoluteStart<r.absoluteEnd&&(r.absoluteEnd=n.absoluteStart,r.duration=r.absoluteEnd-r.absoluteStart,r.remainingTime=Math.max(0,r.absoluteEnd-e),r.progress=Math.min(1,r.elapsedTime/r.duration)),r):r:n:null}#A(t,e){let i=this.#L(t);if(!i)return null;const{block:n,startTimestamp:r}=i,s=t-r;let o,a=n.items.find(t=>t.cycleEnd>s);if(a)o=r+a.cycleStart;else{if(i=this.#L(r+n.duration),!i||0===i.block.items.length)return null;a=i.block.items[0],o=i.startTimestamp+a.cycleStart}const c=Math.max(e,o);return this.#M(a,o,c,!1)}#v(t,e){const i=this.#l.find(e=>t>=e.intendedTimestamp&&t<e.intendedTimestamp+e.content.duration);if(i)return this.#M(i.content,i.intendedTimestamp,e,!0);const n=this.#L(t);if(!n)return null;const{block:r,startTimestamp:s}=n,o=t-s,a=r.items.find(t=>o>=t.cycleStart&&o<t.cycleEnd);return a?this.#M(a,s+a.cycleStart,e,!1):null}#M(t,e,i,n){const r=i-e;return{id:t.id,title:t.title,artist:t.artist,duration:t.duration,url:t.url,absoluteStart:e,absoluteEnd:e+t.duration,elapsedTime:r,remainingTime:t.duration-r,progress:Math.min(1,r/t.duration),isCustom:n}}#g(t,e){let i=t.timestamp||Date.now();const n=t.duration;if(e){const t=this.#v(i,i);t&&(i=t.absoluteEnd)}const r=[...this.#l].sort((t,e)=>t.intendedTimestamp-e.intendedTimestamp);let s=i;if(r.some(t=>i<t.intendedTimestamp+t.content.duration&&i+n>t.intendedTimestamp)){const t=[];let e=Date.now();for(const i of r)i.intendedTimestamp>e&&t.push({start:e,end:i.intendedTimestamp}),e=Math.max(e,i.intendedTimestamp+i.content.duration+this.#f.silenceDuration);t.push({start:e,end:1/0});let o=1/0;for(const e of t)if(e.end-e.start>=n){let t=null;if(i>=e.start&&i+n<=e.end?t=i:i<e.start?t=e.start:i>e.end&&(t=e.end-n),null!==t){const e=Math.abs(i-t);e<o&&(o=e,s=t)}}}this.#l.push({content:t,intendedTimestamp:s,originalTimestamp:t.timestamp||Date.now()})}#w(t){const e=this.#u.filter(e=>e.timestamp<=t);this.#u=this.#u.filter(e=>e.timestamp>t);const i=this.#l.filter(e=>e.intendedTimestamp+e.content.duration<=t);this.#l=this.#l.filter(e=>e.intendedTimestamp+e.content.duration>t);let n=!1;i.forEach(t=>{a(t.content),this.#h+=t.content.id.length,n=!0,this.emit("customPositionExpired",{contentId:t.content.id})}),e.length>0&&e.sort((t,e)=>t.timestamp-e.timestamp).forEach(t=>{const e="music"===t.type?this.#a:this.#c;if("add"===t.action)e.push(t.payload);else if("remove"===t.action){const i=t.payload,n=e.findIndex(t=>t.id===i);if(-1!==n){const[t]=e.splice(n,1);a(t)}}else if("move"===t.action){const i=t.payload,n=e.findIndex(t=>t.id===i.id);if(-1!==n){const[t]=e.splice(n,1);e.splice(i.newIndex,0,t)}}this.#m=t.timestamp,this.#h+=1,n=!0,this.emit("taskExecuted",structuredClone(t))}),n&&this.#d.clear()}#y(t){this.#a.forEach(t=>a(t)),this.#c.forEach(t=>a(t)),this.#l.forEach(t=>a(t.content)),this.#u.forEach(t=>{"add"===t.action&&t.payload&&"object"==typeof t.payload&&"title"in t.payload&&a(t.payload)});const e=t=>t.map(t=>{const e={...t};return e.picture&&Array.isArray(e.picture)&&(e.picture=e.picture.map(t=>({...t,data:s(t.data,t.format)}))),e});this.#a=e(t.music),this.#c=e(t.voice),this.#h=t.seed||0,this.#m=t.anchorDate||Date.now(),this.#f={...this.#f,...t.config||{}},this.#l=t.custom.map(t=>({...t,content:e([t.content])[0]})),this.#u=t.tasks.map(t=>"add"===t.action&&t.payload&&"object"==typeof t.payload&&"title"in t.payload?{...t,payload:e([t.payload])[0]}:t)}destroy(t=!0){t&&(this.#a.forEach(t=>a(t)),this.#c.forEach(t=>a(t)),this.#l.forEach(t=>a(t.content)),this.#u.forEach(t=>{"add"===t.action&&t.payload&&"object"==typeof t.payload&&"title"in t.payload&&a(t.payload)})),this.#a=[],this.#c=[],this.#l=[],this.#u=[],this.#d.clear(),this.emit("destroyed",{timestamp:Date.now()}),this.removeAllListeners()}}const d=u;window.TinyRadioFm=e.TinyRadioFm})();
|
|
1
|
+
(()=>{"use strict";var t={7(t){var e,i="object"==typeof Reflect?Reflect:null,n=i&&"function"==typeof i.apply?i.apply:function(t,e,i){return Function.prototype.apply.call(t,e,i)};e=i&&"function"==typeof i.ownKeys?i.ownKeys:Object.getOwnPropertySymbols?function(t){return Object.getOwnPropertyNames(t).concat(Object.getOwnPropertySymbols(t))}:function(t){return Object.getOwnPropertyNames(t)};var r=Number.isNaN||function(t){return t!=t};function o(){o.init.call(this)}t.exports=o,t.exports.once=function(t,e){return new Promise(function(i,n){function r(i){t.removeListener(e,o),n(i)}function o(){"function"==typeof t.removeListener&&t.removeListener("error",r),i([].slice.call(arguments))}p(t,e,o,{once:!0}),"error"!==e&&function(t,e){"function"==typeof t.on&&p(t,"error",e,{once:!0})}(t,r)})},o.EventEmitter=o,o.prototype._events=void 0,o.prototype._eventsCount=0,o.prototype._maxListeners=void 0;var s=10;function a(t){if("function"!=typeof t)throw new TypeError('The "listener" argument must be of type Function. Received type '+typeof t)}function c(t){return void 0===t._maxListeners?o.defaultMaxListeners:t._maxListeners}function u(t,e,i,n){var r,o,s,u;if(a(i),void 0===(o=t._events)?(o=t._events=Object.create(null),t._eventsCount=0):(void 0!==o.newListener&&(t.emit("newListener",e,i.listener?i.listener:i),o=t._events),s=o[e]),void 0===s)s=o[e]=i,++t._eventsCount;else if("function"==typeof s?s=o[e]=n?[i,s]:[s,i]:n?s.unshift(i):s.push(i),(r=c(t))>0&&s.length>r&&!s.warned){s.warned=!0;var l=new Error("Possible EventEmitter memory leak detected. "+s.length+" "+String(e)+" listeners added. Use emitter.setMaxListeners() to increase limit");l.name="MaxListenersExceededWarning",l.emitter=t,l.type=e,l.count=s.length,u=l,console&&console.warn&&console.warn(u)}return t}function l(){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 d(t,e,i){var n={fired:!1,wrapFn:void 0,target:t,type:e,listener:i},r=l.bind(n);return r.listener=i,n.wrapFn=r,r}function h(t,e,i){var n=t._events;if(void 0===n)return[];var r=n[e];return void 0===r?[]:"function"==typeof r?i?[r.listener||r]:[r]:i?function(t){for(var e=new Array(t.length),i=0;i<e.length;++i)e[i]=t[i].listener||t[i];return e}(r):f(r,r.length)}function m(t){var e=this._events;if(void 0!==e){var i=e[t];if("function"==typeof i)return 1;if(void 0!==i)return i.length}return 0}function f(t,e){for(var i=new Array(e),n=0;n<e;++n)i[n]=t[n];return i}function p(t,e,i,n){if("function"==typeof t.on)n.once?t.once(e,i):t.on(e,i);else{if("function"!=typeof t.addEventListener)throw new TypeError('The "emitter" argument must be of type EventEmitter. Received type '+typeof t);t.addEventListener(e,function r(o){n.once&&t.removeEventListener(e,r),i(o)})}}Object.defineProperty(o,"defaultMaxListeners",{enumerable:!0,get:function(){return s},set:function(t){if("number"!=typeof t||t<0||r(t))throw new RangeError('The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received '+t+".");s=t}}),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(t){if("number"!=typeof t||t<0||r(t))throw new RangeError('The value of "n" is out of range. It must be a non-negative number. Received '+t+".");return this._maxListeners=t,this},o.prototype.getMaxListeners=function(){return c(this)},o.prototype.emit=function(t){for(var e=[],i=1;i<arguments.length;i++)e.push(arguments[i]);var r="error"===t,o=this._events;if(void 0!==o)r=r&&void 0===o.error;else if(!r)return!1;if(r){var s;if(e.length>0&&(s=e[0]),s instanceof Error)throw s;var a=new Error("Unhandled error."+(s?" ("+s.message+")":""));throw a.context=s,a}var c=o[t];if(void 0===c)return!1;if("function"==typeof c)n(c,this,e);else{var u=c.length,l=f(c,u);for(i=0;i<u;++i)n(l[i],this,e)}return!0},o.prototype.addListener=function(t,e){return u(this,t,e,!1)},o.prototype.on=o.prototype.addListener,o.prototype.prependListener=function(t,e){return u(this,t,e,!0)},o.prototype.once=function(t,e){return a(e),this.on(t,d(this,t,e)),this},o.prototype.prependOnceListener=function(t,e){return a(e),this.prependListener(t,d(this,t,e)),this},o.prototype.removeListener=function(t,e){var i,n,r,o,s;if(a(e),void 0===(n=this._events))return this;if(void 0===(i=n[t]))return this;if(i===e||i.listener===e)0===--this._eventsCount?this._events=Object.create(null):(delete n[t],n.removeListener&&this.emit("removeListener",t,i.listener||e));else if("function"!=typeof i){for(r=-1,o=i.length-1;o>=0;o--)if(i[o]===e||i[o].listener===e){s=i[o].listener,r=o;break}if(r<0)return this;0===r?i.shift():function(t,e){for(;e+1<t.length;e++)t[e]=t[e+1];t.pop()}(i,r),1===i.length&&(n[t]=i[0]),void 0!==n.removeListener&&this.emit("removeListener",t,s||e)}return this},o.prototype.off=o.prototype.removeListener,o.prototype.removeAllListeners=function(t){var e,i,n;if(void 0===(i=this._events))return this;if(void 0===i.removeListener)return 0===arguments.length?(this._events=Object.create(null),this._eventsCount=0):void 0!==i[t]&&(0===--this._eventsCount?this._events=Object.create(null):delete i[t]),this;if(0===arguments.length){var r,o=Object.keys(i);for(n=0;n<o.length;++n)"removeListener"!==(r=o[n])&&this.removeAllListeners(r);return this.removeAllListeners("removeListener"),this._events=Object.create(null),this._eventsCount=0,this}if("function"==typeof(e=i[t]))this.removeListener(t,e);else if(void 0!==e)for(n=e.length-1;n>=0;n--)this.removeListener(t,e[n]);return this},o.prototype.listeners=function(t){return h(this,t,!0)},o.prototype.rawListeners=function(t){return h(this,t,!1)},o.listenerCount=function(t,e){return"function"==typeof t.listenerCount?t.listenerCount(e):m.call(t,e)},o.prototype.listenerCount=m,o.prototype.eventNames=function(){return this._eventsCount>0?e(this._events):[]}}};const e={};function i(n){const r=e[n];if(void 0!==r)return r.exports;const o=e[n]={exports:{}};return t[n](o,o.exports,i),o.exports}i.d=(t,e)=>{if(Array.isArray(e))for(var n=0;n<e.length;){var r=e[n++],o=e[n++];i.o(t,r)?0===o&&n++:0===o?Object.defineProperty(t,r,{enumerable:!0,value:e[n++]}):Object.defineProperty(t,r,{enumerable:!0,get:o})}else for(var r in e)i.o(e,r)&&!i.o(t,r)&&Object.defineProperty(t,r,{enumerable:!0,get:e[r]})},i.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e);let n={};i.d(n,{TinyRadioFm:()=>m});var r=i(7);const o=new Map;class s extends Error{constructor(t,e,i){super(t),this.name="MediaLoadingError",this.url=e,this.stage=i}}const a=async t=>{const e=(new TextEncoder).encode(t),i=await crypto.subtle.digest("SHA-1",e);return Array.from(new Uint8Array(i)).map(t=>t.toString(16).padStart(2,"0")).join("").substring(0,8)},c=(t,e="image/jpeg")=>{const i=t=>{const e=URL.createObjectURL(t),i=o.get(e);return o.set(e,"number"==typeof i?i+1:1),e};if(t instanceof Uint8Array)return i(new Blob([t],{type:e}));if("string"==typeof t&&t.startsWith("data:")){const n=t.split(",")[1],r=atob(n),o=new Uint8Array(r.length);for(let t=0;t<r.length;t++)o[t]=r.charCodeAt(t);return i(new Blob([o],{type:e}))}return"string"==typeof t?t:""},u=async t=>{if("string"!=typeof t||!t.startsWith("blob:"))return t;try{const e=await fetch(t),i=await e.blob();return await new Promise((t,e)=>{const n=new FileReader;n.onloadend=()=>t(String(n.result)),n.onerror=e,n.readAsDataURL(i)})}catch(e){return console.warn(`[TinyAudioUtils] Failed to convert Blob URL to Base64 on export: ${t}`,e),t}},l=t=>{t&&Array.isArray(t.picture)&&t.picture.forEach(t=>{if("string"==typeof t.data&&t.data.startsWith("blob:")){const e=o.get(t.data)??0;e>1?o.set(t.data,e-1):o.delete(t.data),e<=1&&URL.revokeObjectURL(t.data)}})},d=async(t,e)=>{if("string"!=typeof t)throw new TypeError(`Expected url to be a string, but received ${typeof t}.`);if("function"!=typeof e)throw new TypeError(`Expected parseFile to be a function, but received ${typeof e}.`);try{const i=await fetch(t);if(!i.ok)throw new Error(`Failed to fetch audio file: ${i.status} ${i.statusText}`);const n=await i.blob(),r=await e(n);if(!r||"object"!=typeof r.common)throw new TypeError('Invalid metadata: "common" property is missing or not an object.');const o=r.common;return(t=>{((t,e)=>{const i=t=>e&&void 0===t,n=t=>i(t)||"string"==typeof t||null===t,r=(t,e)=>!!i(t)||!(!Array.isArray(t)||!t.every(e));if(!n(t.title))throw new TypeError('Invalid metadata: "title" must be a string or null.');if(!n(t.album))throw new TypeError('Invalid metadata: "album" must be a string or null.');if(!n(t.albumartist))throw new TypeError('Invalid metadata: "albumartist" must be a string or null.');if(!n(t.artist))throw new TypeError('Invalid metadata: "artist" must be a string or null.');if(o=t.year,!i(o)&&"number"!=typeof o&&null!==o)throw new TypeError('Invalid metadata: "year" must be a number or null.');var o;if(!r(t.albumartists,t=>"string"==typeof t))throw new TypeError('Invalid metadata: "albumartists" must be an array of string.');if(!r(t.genre,t=>"string"==typeof t))throw new TypeError('Invalid metadata: "genre" must be an array of string.');if(!r(t.label,t=>"string"==typeof t))throw new TypeError('Invalid metadata: "label" must be an array of string.');if(!r(t.composer,t=>"string"==typeof t))throw new TypeError('Invalid metadata: "composer" must be an array of string.');if(!r(t.artists,t=>"string"==typeof t))throw new TypeError('Invalid metadata: "artists" must be an array of string.');if(!r(t.picture,t=>!(void 0!==t.description&&"string"!=typeof t.description||void 0!==t.name&&"string"!=typeof t.name||void 0!==t.type&&"string"!=typeof t.type||"string"!=typeof t.format||!(t.data instanceof Uint8Array||"string"==typeof t.data))))throw new TypeError('Invalid metadata: "picture" must be an array of pictures.');const s=(t,e)=>{if(!i(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.`)}};s(t.disk,"disk"),s(t.track,"track")})(t,!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(t=>({...t,data:c(t.data,t.format)}))??[]}}catch(t){throw t}};class h extends r.EventEmitter{static async parseContent(t,e,i,n,r){return(async(t,e={},i={},n=t=>new Promise((t,e)=>e(new TypeError("parseFile library not found."))),r={},o="null")=>{if("string"!=typeof t&&!(t instanceof HTMLMediaElement))throw new TypeError("Source must be a string or an HTMLMediaElement.");if(r.onProgress&&"function"!=typeof r.onProgress)throw new TypeError("callbacks.onProgress must be a function.");if(r.onError&&"function"!=typeof r.onError)throw new TypeError("callbacks.onError must be a function.");let c,u="";const l=(e,i)=>{r.onProgress&&r.onProgress({event:i,status:"loading",stage:e,url:u||(t instanceof HTMLMediaElement?t.src:"unknown")})},h=(e,i)=>{r.onError&&r.onError({error:e,url:u||(t instanceof HTMLMediaElement?t.src:"unknown"),stage:i})};try{l("INITIALIZING"),"string"==typeof t?(u=t,c=new Audio(u)):(c=t,u=c.src);try{await new Promise((t,e)=>{const i=t=>l("DOWNLOADING",t),n=()=>{o(),t(void 0)},r=t=>{o(),e(new Error(`HTMLMediaElement failed to load: ${t.message||"Unknown error"}`))},o=()=>{c.removeEventListener("progress",i),c.removeEventListener("loadedmetadata",n),c.removeEventListener("error",r)};c.addEventListener("progress",i),c.addEventListener("loadedmetadata",n),c.addEventListener("error",r),c.readyState>=1&&(o(),t(void 0))}),l("METADATA_LOADED")}catch(t){throw new s(t instanceof Error?t.message:"UNKNOWN ERROR",u,"METADATA")}const m={id:i.id||await a(u),duration:Math.floor(1e3*c.duration),url:u,weight:i.weight??1};let f={};l("EXTRACTING_ID3");try{f=await d(u,n)}catch(t){h(t instanceof Error?t:new Error("Unknown Error"),"ID3"),console.warn(`[TinyAudioUtils] ID3 extraction failed for ${u}. Falling back to filename.`)}const p=t=>{try{return(t.split(/[?#]/)[0].split("/").pop()??"").replace(/\.[^/.]+$/,"")||"Unknown Track"}catch{return"Unknown Track"}},y={...m,...e,...f,...i,title:f.title||i.title||p(u),artist:f.artist||i.artist||("string"==typeof o?o:String(o()))};return r.onProgress&&r.onProgress({status:"success",stage:"COMPLETE",url:u}),y}catch(t){if(t instanceof s)throw t;{const e=new s(t instanceof Error?t.message:"UNKNOWN ERROR",u,"INITIALIZING");throw h(e,"INITIALIZING"),e}}})(t,e,i,n,r,h.#t)}static#t="Unknown Artist";static get unknownArtist(){return h.#t}static set unknownArtist(t){if("string"!=typeof t&&"function"!=typeof t)throw new TypeError("unknownArtist must have an string or function.");h.#t=t}get size(){return this.#e.length+this.#i.length}get musicSize(){return this.#e.length}get voiceSize(){return this.#i.length}get customPosSize(){return this.#n.length}get tasksSize(){return this.#r.length}get cycleCacheSize(){return this.#o.size}#e=[];get musicList(){return structuredClone(this.#e)}#i=[];get voiceList(){return structuredClone(this.#i)}#n=[];get customPositions(){return structuredClone(this.#n)}#r=[];get scheduledTasks(){return structuredClone(this.#r)}get allList(){return[...this.musicList,...this.voiceList]}#s=0;get seed(){return this.#s}set seed(t){if("number"!=typeof t)throw new TypeError("Seed must be a number.");this.#s=t,this.#o.clear(),this.emit("seedChanged",{seed:t})}#a=Date.now();get anchorDate(){return this.#a}#o=new Map;#c={mode:"playlist",voiceMode:"playlist",silenceDuration:0,queryLimit:1e5,voiceAfterMusic:!0,voiceMin:0,voiceMax:1,musicMaxConsecutive:0,voiceMaxConsecutive:0};get config(){return structuredClone(this.#c)}set config(t){this.#u(t),this.#c=structuredClone(t),this.#o.clear(),this.emit("configChanged",{config:this.config})}#u(t){if("object"!=typeof t||null===t)throw new TypeError("Configuration must be a valid object.");const e=["playlist","random"];if(void 0!==t.mode&&!e.includes(t.mode))throw new TypeError(`Invalid mode: "${t.mode}". Must be one of: ${e.join(", ")}.`);if(void 0!==t.voiceMode&&!e.includes(t.voiceMode))throw new TypeError(`Invalid voiceMode: "${t.voiceMode}". Must be one of: ${e.join(", ")}.`);if(void 0!==t.silenceDuration&&("number"!=typeof t.silenceDuration||t.silenceDuration<0))throw new TypeError("silenceDuration must be a non-negative number.");if(void 0!==t.queryLimit&&("number"!=typeof t.queryLimit||t.queryLimit<=0))throw new TypeError("queryLimit must be a positive number.");if(void 0!==t.voiceAfterMusic&&"boolean"!=typeof t.voiceAfterMusic)throw new TypeError("voiceAfterMusic must be a boolean.");if(void 0!==t.voiceMin&&("number"!=typeof t.voiceMin||t.voiceMin<0))throw new TypeError("voiceMin must be a non-negative number.");if(void 0!==t.voiceMax&&("number"!=typeof t.voiceMax||t.voiceMax<0))throw new TypeError("voiceMax must be a non-negative number.");if(void 0!==t.musicMaxConsecutive&&("number"!=typeof t.musicMaxConsecutive||t.musicMaxConsecutive<-1))throw new TypeError("musicMaxConsecutive must be a number >= -1.");if(void 0!==t.voiceMaxConsecutive&&("number"!=typeof t.voiceMaxConsecutive||t.voiceMaxConsecutive<-1))throw new TypeError("voiceMaxConsecutive must be a number >= -1.");const i=t.voiceMin??this.#c.voiceMin,n=t.voiceMax??this.#c.voiceMax;if(n<i)throw new RangeError(`Logical error: voiceMax (${n}) cannot be less than voiceMin (${i}).`)}constructor(t=null,e=0){if(super(),null!==t&&"object"!=typeof t)throw new TypeError("initialData must be an object or null.");if("number"!=typeof e)throw new TypeError("seed must be a number.");this.#s=e,t?this.#l(t):this.#a=Date.now()}add(t,e,i=!0){if(!["music","voice","custom"].includes(t))throw new TypeError('Type must be "music", "voice", or "custom".');if(!e||"string"!=typeof e.id||"number"!=typeof e.duration)throw new TypeError("Content must have a string ID and a valid numerical duration in milliseconds.");if("boolean"!=typeof i)throw new TypeError("smartQueue must be a boolean.");"music"===t?(this.#e.push(e),this.#o.clear()):"voice"===t?(this.#i.push(e),this.#o.clear()):"custom"===t&&this.#d(e,i),this.#h(Date.now()),this.emit("contentAdded",{type:t,data:structuredClone(e)})}scheduleTask(t,e,i,n,r=!0){if("number"!=typeof t||isNaN(t))throw new TypeError("timestamp must be a valid number.");if(!["add","remove","move"].includes(e))throw new TypeError('action must be "add", "remove", or "move".');if(!["music","voice"].includes(i))throw new TypeError('type must be "music" or "voice".');if("boolean"!=typeof r)throw new TypeError("smartQueue must be a boolean.");if("add"===e){if("object"!=typeof n||null===n||"string"!=typeof n.id||"number"!=typeof n.duration)throw new TypeError('Payload for "add" must be a MediaContent object (id: string, duration: number).')}else if("remove"===e){if("string"!=typeof n)throw new TypeError('Payload for "remove" must be a string (the content ID).')}else if("move"===e&&("object"!=typeof n||null===n||"string"!=typeof n.id||"number"!=typeof n.newIndex))throw new TypeError('Payload for "move" must be a ScheduledMovePayload (id: string, newIndex: number).');let o=t;if(r){const e=this.#m(t,t);e&&(o=e.absoluteEnd)}const s={timestamp:o,action:e,type:i,payload:n};this.#r.push(s),this.#h(Date.now()),this.emit("taskScheduled",structuredClone(s))}remove(t){if("string"!=typeof t)throw new TypeError("id must be a string.");this.#e.filter(e=>e.id===t).forEach(t=>l(t)),this.#i.filter(e=>e.id===t).forEach(t=>l(t)),this.#n.filter(e=>e.content?.id===t).forEach(t=>l(t.content));const e=e=>e.id!==t&&e.content?.id!==t;this.#e=this.#e.filter(e),this.#i=this.#i.filter(e),this.#n=this.#n.filter(e),this.#r=this.#r.filter(e=>"add"===e.action&&"object"==typeof e.payload&&null!==e.payload&&"id"in e.payload?e.payload.id!==t||(l(e.payload),!1):e.payload!==t),this.#o.clear(),this.emit("contentRemoved",{id:t})}setConfig(t){this.#u(t);const e={...this.#c,...t};this.#u(e),this.#c=e,this.#o.clear(),this.emit("configChanged",{config:this.config})}getCurrentEvent(){const t=Date.now();return this.#h(t),this.#m(t,t)}queryTimeline(t,e=10){if("number"!=typeof e||isNaN(e))throw new TypeError("Invalid query limit value. Ensure it is a number.");if(e>this.#c.queryLimit||e<=0)throw new RangeError(`Invalid query limit. Ensure it is > 0 and <= ${this.#c.queryLimit}.`);const i=new h(JSON.parse(this._exportState())),n=[];let r=t;for(let o=0;o<e;o++){i.#h(r);const e=i.#f(r,t);if(!e)break;n.push(e),r=e.absoluteEnd}return i.destroy(!1),this.emit("timelineQueried",{targetDate:t,limit:e,resultCount:n.length}),n}searchCustomPositions(){return this.#h(Date.now()),[...this.#n]}async _processListForExport(t){return Promise.all(t.map(async t=>{const e=structuredClone(t);return e.picture&&Array.isArray(e.picture)&&(e.picture=await Promise.all(e.picture.map(async t=>({...t,data:await u(t.data)})))),e}))}_exportState(){return JSON.stringify({music:this.#e,voice:this.#i,custom:this.#n,tasks:this.#r,seed:this.#s,anchorDate:this.#a,config:this.#c})}async exportState(){const t=await this._processListForExport(this.#e),e=await this._processListForExport(this.#i),i=await Promise.all(this.#n.map(async t=>{const e=await this._processListForExport([t.content]);return{...t,content:e[0]}})),n=await Promise.all(this.#r.map(async t=>{if("add"===t.action&&t.payload&&"object"==typeof t.payload&&"title"in t.payload){const e=await this._processListForExport([t.payload]);return{...t,payload:e[0]}}return t}));return JSON.stringify({music:t,voice:e,custom:i,tasks:n,seed:this.#s,anchorDate:this.#a,config:this.#c})}importState(t){let e;if("string"==typeof t)try{e=JSON.parse(t)}catch{throw new TypeError("Provided string is not valid JSON.")}else{if("object"!=typeof t||null===t)throw new TypeError("Import data must be a valid JSON string or an object.");e=t}this.#l(e),this.emit("stateImported",{data:structuredClone(e)})}_prng(t){return function(){let e=t+=1831565813;return e=Math.imul(e^e>>>15,1|e),e^=e+Math.imul(e^e>>>7,61|e),((e^e>>>14)>>>0)/4294967296}}#p(t,e,i,n=0){if(0===t.length)return[];if("random"!==i)return[...t];const r=t.map(t=>({...t,weight:t.weight??1})),o=this._prng(e),s=[];let a=null,c=0;for(;r.length>0;){let t=r;-1!==n&&null!==a&&c>n&&(t=r.filter(t=>t.id!==a),0===t.length&&(t=r));const e=t.reduce((t,e)=>t+e.weight,0);if(e<=0){s.push(...t);break}const i=o()*e;let u=0,l=null,d=-1;for(let e=0;e<t.length;e++)if(u+=t[e].weight,i<=u){l=t[e],d=r.findIndex(t=>l&&t.id===l.id);break}l&&-1!==d||(l=t[0],d=r.findIndex(t=>l&&t.id===l.id)),s.push(l),r.splice(d,1),l.id===a?c++:(a=l.id,c=1)}return s}#y(t){const e=this.#s+t,i=this._prng(10*e),n=this.#p(this.#e,e+1,this.#c.mode,this.#c.musicMaxConsecutive),r=this.#p(this.#i,e+2,this.#c.voiceMode,this.#c.voiceMaxConsecutive),o=[];let s=0,a=0;for(let t=0;t<n.length;t++){const e=n[t];if(o.push({...e,cycleStart:s,cycleEnd:s+e.duration}),s+=e.duration+this.#c.silenceDuration,this.#c.voiceAfterMusic&&r.length>0){const t=this.#c.voiceMax-this.#c.voiceMin+1,e=Math.floor(i()*t)+this.#c.voiceMin;for(let t=0;t<e;t++){const t=r[a%r.length];a++,o.push({...t,cycleStart:s,cycleEnd:s+t.duration}),s+=t.duration+this.#c.silenceDuration}}}return{items:o,duration:s}}#v(t){if(0===this.#e.length)return null;let e=this.#a,i=0;for(;;){if(i>this.#c.queryLimit)throw new Error("Safety limit hit during cycle location.");let n=this.#o.get(i);if(n||(n=this.#y(i),this.#o.set(i,n)),0===n.duration)return null;if(t>=e&&t<e+n.duration)return{block:n,startTimestamp:e,loopIndex:i};e+=n.duration,i++}}#f(t,e){const i=this.#n.filter(e=>e.intendedTimestamp+e.content.duration>t).sort((t,e)=>t.intendedTimestamp-e.intendedTimestamp)[0];let n=null;if(i){const t=Math.max(e,i.intendedTimestamp);n=this.#g(i.content,i.intendedTimestamp,t,!0)}const r=this.#w(t,e);return r||n?r?n?n.absoluteStart<=r.absoluteStart?n:(n.absoluteStart<r.absoluteEnd&&(r.absoluteEnd=n.absoluteStart,r.duration=r.absoluteEnd-r.absoluteStart,r.remainingTime=Math.max(0,r.absoluteEnd-e),r.progress=Math.min(1,r.elapsedTime/r.duration)),r):r:n:null}#w(t,e){let i=this.#v(t);if(!i)return null;const{block:n,startTimestamp:r}=i,o=t-r;let s,a=n.items.find(t=>t.cycleEnd>o);if(a)s=r+a.cycleStart;else{if(i=this.#v(r+n.duration),!i||0===i.block.items.length)return null;a=i.block.items[0],s=i.startTimestamp+a.cycleStart}const c=Math.max(e,s);return this.#g(a,s,c,!1)}#m(t,e){const i=this.#n.find(e=>t>=e.intendedTimestamp&&t<e.intendedTimestamp+e.content.duration);if(i)return this.#g(i.content,i.intendedTimestamp,e,!0);const n=this.#v(t);if(!n)return null;const{block:r,startTimestamp:o}=n,s=t-o,a=r.items.find(t=>s>=t.cycleStart&&s<t.cycleEnd);return a?this.#g(a,o+a.cycleStart,e,!1):null}#g(t,e,i,n){const r=i-e;return{id:t.id,title:t.title,artist:t.artist,duration:t.duration,url:t.url,absoluteStart:e,absoluteEnd:e+t.duration,elapsedTime:r,remainingTime:t.duration-r,progress:Math.min(1,r/t.duration),isCustom:n}}#d(t,e){let i=t.timestamp||Date.now();const n=t.duration;if(e){const t=this.#m(i,i);t&&(i=t.absoluteEnd)}const r=[...this.#n].sort((t,e)=>t.intendedTimestamp-e.intendedTimestamp);let o=i;if(r.some(t=>i<t.intendedTimestamp+t.content.duration&&i+n>t.intendedTimestamp)){const t=[];let e=Date.now();for(const i of r)i.intendedTimestamp>e&&t.push({start:e,end:i.intendedTimestamp}),e=Math.max(e,i.intendedTimestamp+i.content.duration+this.#c.silenceDuration);t.push({start:e,end:1/0});let s=1/0;for(const e of t)if(e.end-e.start>=n){let t=null;if(i>=e.start&&i+n<=e.end?t=i:i<e.start?t=e.start:i>e.end&&(t=e.end-n),null!==t){const e=Math.abs(i-t);e<s&&(s=e,o=t)}}}this.#n.push({content:t,intendedTimestamp:o,originalTimestamp:t.timestamp||Date.now()})}#h(t){const e=this.#r.filter(e=>e.timestamp<=t);this.#r=this.#r.filter(e=>e.timestamp>t);const i=this.#n.filter(e=>e.intendedTimestamp+e.content.duration<=t);this.#n=this.#n.filter(e=>e.intendedTimestamp+e.content.duration>t);let n=!1;i.forEach(t=>{l(t.content),this.#s+=t.content.id.length,n=!0,this.emit("customPositionExpired",{contentId:t.content.id})}),e.length>0&&e.sort((t,e)=>t.timestamp-e.timestamp).forEach(t=>{const e="music"===t.type?this.#e:this.#i;if("add"===t.action)e.push(t.payload);else if("remove"===t.action){const i=t.payload,n=e.findIndex(t=>t.id===i);if(-1!==n){const[t]=e.splice(n,1);l(t)}}else if("move"===t.action){const i=t.payload,n=e.findIndex(t=>t.id===i.id);if(-1!==n){const[t]=e.splice(n,1);e.splice(i.newIndex,0,t)}}this.#a=t.timestamp,this.#s+=1,n=!0,this.emit("taskExecuted",structuredClone(t))}),n&&this.#o.clear()}#l(t){this.#e.forEach(t=>l(t)),this.#i.forEach(t=>l(t)),this.#n.forEach(t=>l(t.content)),this.#r.forEach(t=>{"add"===t.action&&t.payload&&"object"==typeof t.payload&&"title"in t.payload&&l(t.payload)});const e=t=>t.map(t=>{const e={...t};return e.picture&&Array.isArray(e.picture)&&(e.picture=e.picture.map(t=>({...t,data:c(t.data,t.format)}))),e});this.#e=e(t.music),this.#i=e(t.voice),this.#s=t.seed||0,this.#a=t.anchorDate||Date.now(),this.#c={...this.#c,...t.config||{}},this.#n=t.custom.map(t=>({...t,content:e([t.content])[0]})),this.#r=t.tasks.map(t=>"add"===t.action&&t.payload&&"object"==typeof t.payload&&"title"in t.payload?{...t,payload:e([t.payload])[0]}:t)}destroy(t=!0){t&&(this.#e.forEach(t=>l(t)),this.#i.forEach(t=>l(t)),this.#n.forEach(t=>l(t.content)),this.#r.forEach(t=>{"add"===t.action&&t.payload&&"object"==typeof t.payload&&"title"in t.payload&&l(t.payload)})),this.#e=[],this.#i=[],this.#n=[],this.#r=[],this.#o.clear(),this.emit("destroyed",{timestamp:Date.now()}),this.removeAllListeners()}}const m=h;window.TinyRadioFm=n.TinyRadioFm})();
|