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.
Files changed (60) hide show
  1. package/README.md +1 -0
  2. package/changelog/1/28/0.md +16 -0
  3. package/dist/v1/TinyAdvancedRaffle.min.js +1 -1
  4. package/dist/v1/TinyBasicsEs.min.js +1 -2
  5. package/dist/v1/TinyEssentials.min.js +1 -2
  6. package/dist/v1/TinyIframeEvents.min.js +1 -1
  7. package/dist/v1/TinyLocalStorage.min.js +1 -1
  8. package/dist/v1/TinyMediaPlayer.min.js +1 -1
  9. package/dist/v1/TinyNewWinEvents.min.js +1 -1
  10. package/dist/v1/TinyRadioFm.min.js +1 -1
  11. package/dist/v1/TinySmartScroller.min.js +1 -1
  12. package/dist/v1/TinyUploadClicker.min.js +1 -2
  13. package/dist/v1/basics/extendObjType/Buffer.cjs +13 -0
  14. package/dist/v1/basics/extendObjType/Buffer.d.mts +4 -0
  15. package/dist/v1/basics/extendObjType/Buffer.mjs +8 -0
  16. package/dist/v1/basics/objFilter.cjs +0 -11
  17. package/dist/v1/basics/objFilter.mjs +0 -10
  18. package/dist/v1/index.cjs +0 -2
  19. package/dist/v1/index.d.mts +1 -2
  20. package/dist/v1/index.mjs +1 -2
  21. package/dist/v1/libs/TinyAdvancedRaffle.cjs +7 -205
  22. package/dist/v1/libs/TinyAdvancedRaffle.d.mts +2 -121
  23. package/dist/v1/libs/TinyAdvancedRaffle.mjs +7 -179
  24. package/dist/v1/libs/TinyIframeEvents.cjs +8 -195
  25. package/dist/v1/libs/TinyIframeEvents.d.mts +3 -122
  26. package/dist/v1/libs/TinyIframeEvents.mjs +8 -170
  27. package/dist/v1/libs/TinyLocalStorage.cjs +5 -205
  28. package/dist/v1/libs/TinyLocalStorage.d.mts +3 -130
  29. package/dist/v1/libs/TinyLocalStorage.mjs +5 -178
  30. package/dist/v1/libs/TinyMediaPlayer.cjs +2 -2
  31. package/dist/v1/libs/TinyMediaPlayer.d.mts +2 -2
  32. package/dist/v1/libs/TinyMediaPlayer.mjs +2 -2
  33. package/dist/v1/libs/TinyNewWinEvents.cjs +10 -197
  34. package/dist/v1/libs/TinyNewWinEvents.d.mts +3 -122
  35. package/dist/v1/libs/TinyNewWinEvents.mjs +10 -172
  36. package/dist/v1/libs/TinyRadioFm.cjs +2 -3
  37. package/dist/v1/libs/TinyRadioFm.d.mts +2 -3
  38. package/dist/v1/libs/TinyRadioFm.mjs +2 -3
  39. package/dist/v1/libs/TinySmartScroller.cjs +4 -202
  40. package/dist/v1/libs/TinySmartScroller.d.mts +8 -143
  41. package/dist/v1/libs/TinySmartScroller.mjs +4 -176
  42. package/dist/v1/libs/TinyUploadClicker.cjs +1 -0
  43. package/docs/v1/Exports.md +0 -1
  44. package/docs/v1/README.md +0 -1
  45. package/docs/v1/basics/objFilter.md +1 -1
  46. package/docs/v1/libs/TinyIframeEvents.md +8 -8
  47. package/docs/v1/libs/TinyLocalStorage.md +3 -3
  48. package/docs/v1/libs/TinyNewWinEvents.md +8 -9
  49. package/package.json +6 -5
  50. package/dist/v1/TinyBasicsEs.min.js.LICENSE.txt +0 -8
  51. package/dist/v1/TinyEssentials.min.js.LICENSE.txt +0 -8
  52. package/dist/v1/TinyEvents.min.js +0 -1
  53. package/dist/v1/TinyUploadClicker.min.js.LICENSE.txt +0 -8
  54. package/dist/v1/build/TinyEvents.cjs +0 -7
  55. package/dist/v1/build/TinyEvents.d.mts +0 -3
  56. package/dist/v1/build/TinyEvents.mjs +0 -2
  57. package/dist/v1/libs/TinyEvents.cjs +0 -395
  58. package/dist/v1/libs/TinyEvents.d.mts +0 -164
  59. package/dist/v1/libs/TinyEvents.mjs +0 -360
  60. package/docs/v1/libs/TinyEvents.md +0 -187
package/README.md CHANGED
@@ -59,6 +59,7 @@ Check out the full documentation here:
59
59
  - 🖥️ [**tiny-server-essentials**](https://github.com/Tiny-Essentials/Tiny-Server-Essentials) — Node.js server utilities.
60
60
  - 🪟 [**tiny-electron-essentials**](https://github.com/Tiny-Essentials/Tiny-Electron-Essentials) — Essential tools for Electron apps.
61
61
  - 🗃️ [**puddysql**](https://github.com/Tiny-Essentials/PuddySQL) — Smart SQL engine for structured data, tags, and advanced queries.
62
+ - 📢 [**my-tiny-events**](https://github.com/Tiny-Essentials/My-Tiny-Events) — A event emitter system for JavaScript, inspired by Node.js EventEmitter with support for multi-event handling and listener management.
62
63
 
63
64
  ---
64
65
 
@@ -0,0 +1,16 @@
1
+ ## 🛠️ Summary of Changes
2
+
3
+ ### 💎 `TinyNewWinEvents` & `TinyIframeEvents`
4
+
5
+ * **New Feature:** Added `winEmit` to emit events directly to a window. The standard `emit` function will now fall back to the native `EventEmitter` implementation.
6
+ * **Security & Namespacing:** To enforce strict isolation and improve event tracking, all events dispatched via `winEmit` are now automatically prefixed. They will always return in the format: `win:{EventName}`.
7
+
8
+ ### 📦 `Buffer` Module Optimization
9
+
10
+ * **Breaking Change:** To make the core package lighter, the `Buffer` utility has been **removed** from `objType.mjs`.
11
+ * **How to Restore:** If your project relies on this functionality, you can easily re-introduce it manually by importing it from `basics/extendObjType/Buffer.mjs`.
12
+
13
+ ### 🔄 `TinyEvents` Migration to `MyTinyEvents`
14
+
15
+ * **Repository Migration:** `TinyEvents` has officially been migrated to a dedicated repository. It is now maintained as **MyTinyEvents** at [Tiny-Essentials/My-Tiny-Events](https://github.com/Tiny-Essentials/My-Tiny-Events).
16
+ * **Architecture Update:** All modules within the `tiny-essentials` ecosystem have been refactored to natively use `EventEmitter` for robust and standardized event handling.
@@ -1 +1 @@
1
- (()=>{"use strict";const e={d:(t,r)=>{if(Array.isArray(r))for(var s=0;s<r.length;){var i=r[s++],n=r[s++];e.o(t,i)?0===n&&s++:0===n?Object.defineProperty(t,i,{enumerable:!0,value:r[s++]}):Object.defineProperty(t,i,{enumerable:!0,get:n})}else for(var i in r)e.o(r,i)&&!e.o(t,i)&&Object.defineProperty(t,i,{enumerable:!0,get:r[i]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t)};let t={};e.d(t,{TinyAdvancedRaffle:()=>i});const r=class{#e=new Map;#t=10;#r=!1;#s(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}#i(e,t,{once:r=!1}={}){let s=this.#e.get(e);Array.isArray(s)||(s=[],this.#e.set(e,s)),s.unshift({handler:t,config:{once:r}});const i=this.#t;if(i>0&&s.length>i){const t=`Possible memory leak detected. ${s.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.#s(e,"prependListener");if("function"!=typeof t)throw new TypeError("prependListener(event, handler): handler must be a function");for(const e of r)this.#i(e,t)}prependListenerOnce(e,t){const r=this.#s(e,"prependListenerOnce");if("function"!=typeof t)throw new TypeError("prependListenerOnce(event, handler): handler must be a function");const s=[];for(const e of r){const r=(...s)=>{this.off(e,r),t(...s)};this.#i(e,r,{once:!0}),s.push(r)}return s}#n(e,t,{once:r=!1}={}){const s=this.#s(e,"on");for(const e of s){let s=this.#e.get(e);Array.isArray(s)||(s=[],this.#e.set(e,s)),s.push({handler:t,config:{once:r}});const i=this.#t;if(i>0&&s.length>i){const t=`Possible memory leak detected. ${s.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.#n(e,t)}once(e,t){const r=this.#s(e,"once");if("function"!=typeof t)throw new TypeError("once(event, handler): handler must be a function");const s=[];for(const e of r){const r=(...s)=>{this.off(e,r),t(...s)};this.#n(e,r,{once:!0}),s.push(r)}return s}appendListener(e,t){return this.on(e,t)}appendListenerOnce(e,t){return this.once(e,t)}off(e,t){const r=this.#s(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 s=r.findIndex(e=>e.handler===t);-1!==s&&r.splice(s,1),0===r.length&&this.#e.delete(e)}}offAll(e){const t=this.#s(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.#s(e,"emit"),s=[];for(const e of r){const r=this.#e.get(e);Array.isArray(r)&&0!==r.length?(r.forEach(e=>e.handler(...t)),s.push(!0)):s.push(!1)}return s}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}};class s{#o=new r;#a(e,...t){return this.#o.emit(e,...t)}setThrowOnMaxListeners(e){return this.#o.setThrowOnMaxListeners(e)}getThrowOnMaxListeners(){return this.#o.getThrowOnMaxListeners()}prependListener(e,t){return this.#o.prependListener(e,t)}prependListenerOnce(e,t){return this.#o.prependListenerOnce(e,t)}appendListener(e,t){return this.#o.appendListener(e,t)}appendListenerOnce(e,t){return this.#o.appendListenerOnce(e,t)}on(e,t){return this.#o.on(e,t)}once(e,t){return this.#o.once(e,t)}off(e,t){return this.#o.off(e,t)}offAll(e){return this.#o.offAll(e)}offAllTypes(){return this.#o.offAllTypes()}listenerCount(e){return this.#o.listenerCount(e)}listeners(e){return this.#o.listeners(e)}onceListeners(e){return this.#o.onceListeners(e)}allListeners(e){return this.#o.allListeners(e)}eventNames(){return this.#o.eventNames()}setMaxListeners(e){return this.#o.setMaxListeners(e)}getMaxListeners(){return this.#o.getMaxListeners()}#h=!1;#u;#f;#p=[];#c=[];#m=[];#l=new Map;#y=new Set;#d=new Map;#g;#w=new Map;#b=new Map;get isDestroyed(){return this.#h}get freq(){return Object.fromEntries(this.#b)}get size(){return this.#w.size}get normalization(){return this.#u}set normalization(e){if(this._checkDestroyed(),"string"!=typeof e||!e.trim())throw new TypeError("normalization must be a non-empty string (e.g., 'relative', 'softmax').");this.#u=e}get seed(){return this.#f}set seed(e){if(this._checkDestroyed(),null!==e&&("number"!=typeof e||!Number.isFinite(e)))throw new TypeError("seed must be a finite number or null.");this.#f=e,null!==e&&(this.#g=this._makeSeededRng(e))}get globalModifiers(){return[...this.#p]}set globalModifiers(e){if(this._checkDestroyed(),!Array.isArray(e)||!e.every(e=>"function"==typeof e))throw new TypeError("globalModifiers must be an array of functions (WeightsCallback).");this.#p=e}get temporaryModifiers(){return[...this.#c]}set temporaryModifiers(e){if(this._checkDestroyed(),!Array.isArray(e)||!e.every(e=>e&&"function"==typeof e.fn&&Number.isInteger(e.uses)&&e.uses>0))throw new TypeError("temporaryModifiers must be an array of objects { fn: function, uses: positive integer }.");this.#c=e}get conditionalRules(){return[...this.#m]}set conditionalRules(e){if(this._checkDestroyed(),!Array.isArray(e)||!e.every(e=>"function"==typeof e))throw new TypeError("conditionalRules must be an array of functions (WeightsCallback).");this.#m=e}get pitySystems(){return Object.fromEntries(this.#l)}set pitySystems(e){if(this._checkDestroyed(),!(e instanceof Map&&[...e.values()].every(e=>e&&"number"==typeof e.threshold&&"number"==typeof e.increment&&"number"==typeof e.cap&&"number"==typeof e.counter&&"number"==typeof e.currentAdd)))throw new TypeError("pitySystems must be a Map<string, Pity> with all numeric fields.");this.#l=e}get exclusions(){return Array.from(this.#y)}set exclusions(e){if(this._checkDestroyed(),!(e instanceof Set&&[...e].every(e=>"string"==typeof e)))throw new TypeError("exclusions must be a Set<string>.");this.#y=e}get groups(){const e={};return this.#d.forEach((t,r)=>e[r]=Array.from(t)),e}set groups(e){if(this._checkDestroyed(),!(e instanceof Map&&[...e.values()].every(e=>e instanceof Set&&[...e].every(e=>"string"==typeof e))))throw new TypeError("groups must be a Map<string, Set<string>>.");this.#d=e}get rng(){return this.#g}set rng(e){if(this._checkDestroyed(),"function"!=typeof e||"number"!=typeof e())throw new TypeError("rng must be a function returning a number (RngGenerator).");this.#g=e}get items(){const e={};return this.#w.forEach((t,r)=>{e[r]={...t,groups:Array.from(t.groups)}}),e}set items(e){if(this._checkDestroyed(),!(e instanceof Map&&[...e.values()].every(e=>e&&"string"==typeof e.id&&"string"==typeof e.label&&"number"==typeof e.baseWeight&&e.groups instanceof Set&&"boolean"==typeof e.locked&&"object"==typeof e.meta)))throw new TypeError("items must be a Map<string, ItemData> with valid item structures.");this.clearList(),this.#w=e}constructor(e={}){const{rng:t=null,seed:r=null,normalization:s="relative"}=e;this.#u=s,this.#f=r,"function"==typeof t?this.#g=t:null!==this.#f?this.#g=this._makeSeededRng(this.#f):this.#g=Math.random,this.#f=r??null}_checkDestroyed(){if(this.#h)throw new Error("This instance has been destroyed and can no longer be used.")}hasItem(e){if("string"!=typeof e)throw new TypeError("itemId must be a string");return this.#w.has(e)}addItem(e,t={}){if(this._checkDestroyed(),"string"!=typeof e||!e.trim())throw new TypeError("id must be a non-empty string");if("object"!=typeof t||null===t)throw new TypeError("opts must be an object");let{weight:r=1,label:s=e,meta:i={},groups:n=[]}=t;if("number"!=typeof r||!Number.isFinite(r)||r<0)throw new TypeError("weight must be a non-negative number");if("string"!=typeof s)throw new TypeError("label must be a string");if("object"!=typeof i||null===i)throw new TypeError("meta must be an object");if(!(Array.isArray(n)||n instanceof Set))throw new TypeError("groups must be an array or a Set of strings");n=Array.isArray(n)?n:[...n];for(const e of n)if("string"!=typeof e)throw new TypeError("groups must contain only strings");const o={id:e,label:s,baseWeight:Math.max(0,Number(r)||0),meta:{...i},groups:new Set(n),locked:!1};this.#w.set(e,o);for(const t of n)this._ensureGroup(t).add(e);return this.#a("itemAdded",o),o}removeItem(e){if(this._checkDestroyed(),"string"!=typeof e||!e.trim())throw new TypeError("id must be a non-empty string");const t=this.#w.get(e);if(!t)return!1;for(const r of t.groups){const t=this.#d.get(r);t&&t.delete(e)}return this.#w.delete(e),this.#a("itemRemoved",e),this.resetFreq(e),this.resetPity(e),!0}setBaseWeight(e,t){if(this._checkDestroyed(),"string"!=typeof e||!e.trim())throw new TypeError("id must be a non-empty string");if("number"!=typeof t||!Number.isFinite(t)||t<0)throw new TypeError("weight must be a non-negative number");const r=this.#w.get(e);if(!r)throw new Error("Item not found");r.baseWeight=Math.max(0,Number(t)||0),this.#a("weightChanged",{id:e,weight:r.baseWeight})}getItem(e){if("string"!=typeof e||!e.trim())throw new TypeError("id must be a non-empty string");return this.#w.get(e)??null}listItems(){return Array.from(this.#w.values()).map(e=>({...e}))}clearList(){this._checkDestroyed(),this.#w.clear(),this.clearFreqs(),this.clearPities()}hasGlobalModifier(e){if("function"!=typeof e)throw new TypeError("fn must be a function");return this.#p.includes(e)}addGlobalModifier(e){if(this._checkDestroyed(),"function"!=typeof e)throw new TypeError("fn must be a function");this.#p.push(e)}removeGlobalModifier(e){if(this._checkDestroyed(),"function"!=typeof e)throw new TypeError("fn must be a function");this.#p=this.#p.filter(t=>t!==e)}hasTemporaryModifier(e){if("function"!=typeof e)throw new TypeError("fn must be a function");return this.#c.some(t=>t.fn===e)}addTemporaryModifier(e,t=1){if(this._checkDestroyed(),"function"!=typeof e)throw new TypeError("fn must be a function");if("number"!=typeof t||Number.isNaN(t))throw new TypeError("uses must be a number");this.#c.push({fn:e,uses:Math.max(1,Math.floor(t))})}removeTemporaryModifier(e){if(this._checkDestroyed(),"function"!=typeof e)throw new TypeError("fn must be a function");const t=this.#c.length;return this.#c=this.#c.filter(t=>t.fn!==e),this.#c.length!==t}hasConditionalRule(e){if("function"!=typeof e)throw new TypeError("ruleFn must be a function");return this.#m.includes(e)}addConditionalRule(e){if(this._checkDestroyed(),"function"!=typeof e)throw new TypeError("ruleFn must be a function");this.#m.push(e)}removeConditionalRule(e){if(this._checkDestroyed(),"function"!=typeof e)throw new TypeError("ruleFn must be a function");const t=this.#m.length;return this.#m=this.#m.filter(t=>t!==e),this.#m.length!==t}hasPity(e){if("string"!=typeof e)throw new TypeError("itemId must be a string");return this.#l.has(e)}configurePity(e,t){if(this._checkDestroyed(),!this.#w.has(e))throw new Error("Item not found");if("object"!=typeof t||null===t)throw new TypeError("cfg must be an object");const{threshold:r,increment:s,cap:i=1/0}=t;if("number"!=typeof r||r<=0)throw new TypeError("threshold must be a positive number");if("number"!=typeof s)throw new TypeError("increment must be a number");if("number"!=typeof i)throw new TypeError("cap must be a number");this.#l.set(e,{threshold:Math.max(1,r),increment:Number(s)||0,cap:Number(i)||1/0,counter:0,currentAdd:0})}resetPity(e){if(this._checkDestroyed(),"string"!=typeof e||!e.trim())throw new TypeError("itemId must be a non-empty string");const t=this.#l.get(e);t&&(t.counter=0,t.currentAdd=0)}clearPities(){this._checkDestroyed(),this.#l.clear()}hasExclusion(e){if("string"!=typeof e)throw new TypeError("itemId must be a string");return this.#y.has(e)}excludeItem(e){if(this._checkDestroyed(),"string"!=typeof e)throw new TypeError("itemId must be a string");this.#y.add(e)}includeItem(e){if(this._checkDestroyed(),"string"!=typeof e)throw new TypeError("itemId must be a string");this.#y.delete(e)}_ensureGroup(e){if(this._checkDestroyed(),"string"!=typeof e)throw new TypeError("name must be a string");let t=this.#d.get(e);return t||(t=new Set,this.#d.set(e,t)),t}hasInGroup(e,t){if("string"!=typeof e||"string"!=typeof t)throw new TypeError("itemId and groupName must be strings");const r=this.#d.get(t);return!!r&&r.has(e)}addToGroup(e,t){if(this._checkDestroyed(),"string"!=typeof e||"string"!=typeof t)throw new TypeError("itemId and groupName must be strings");const r=this.#w.get(e);if(!r)throw new Error("Item missing");r.groups.add(t),this._ensureGroup(t).add(e)}removeFromGroup(e,t){if(this._checkDestroyed(),"string"!=typeof e||"string"!=typeof t)throw new TypeError("itemId and groupName must be strings");const r=this.#d.get(t);r&&r.delete(e);const s=this.#w.get(e);s&&s.groups.delete(t)}clearFreqs(){this._checkDestroyed(),this.#b.clear()}resetFreq(e){if(this._checkDestroyed(),"string"!=typeof e)throw new TypeError("itemId must be a string");this.#b.delete(e)}computeEffectiveWeights(e={}){if(this._checkDestroyed(),"object"!=typeof e||null===e)throw new TypeError("computeEffectiveWeights: parameter 'context' must be a non-null object, got "+typeof e);if("previousDraws"in e&&!Array.isArray(e.previousDraws))throw new TypeError("computeEffectiveWeights: context.previousDraws must be an array if provided, got "+typeof e.previousDraws);if("metadata"in e&&void 0!==e.metadata&&("object"!=typeof e.metadata||null===e.metadata))throw new TypeError("computeEffectiveWeights: context.metadata must be a non-null object if provided, got "+typeof e.metadata);const t=new Map;for(const[e,r]of this.#w)t.set(e,r.baseWeight);for(const r of this.#p){const s=r(t,e);if(s instanceof Map)for(const[e,r]of s)t.set(e,Math.max(0,(t.get(e)||0)+r))}for(const r of this.#c){const s=r.fn(t,e);if(s instanceof Map)for(const[e,r]of s)t.set(e,Math.max(0,(t.get(e)||0)+r))}for(const r of this.#m){const s=r(t,e);if(s instanceof Map)for(const[e,r]of s)t.set(e,Math.max(0,(t.get(e)||0)+r))}for(const[e,r]of this.#l)if(t.has(e)&&r.counter>r.threshold){r.currentAdd=Math.min(r.cap,r.currentAdd+r.increment);const s=t.get(e);s&&t.set(e,s+r.currentAdd)}for(const e of this.#y)t.delete(e);for(const[e,r]of Array.from(t.entries()))r>0||t.delete(e);return t}_weightsToDistribution(e){if(this._checkDestroyed(),!(e instanceof Map))throw new TypeError("_weightsToDistribution: parameter 'weights' must be a Map, got "+typeof e);for(const[t,r]of e){if("string"!=typeof t)throw new TypeError("_weightsToDistribution: weights Map key must be string, got "+typeof t);if("number"!=typeof r||!Number.isFinite(r)||r<0)throw new TypeError(`_weightsToDistribution: weights Map value must be finite non-negative number, got ${r} for key ${t}`)}const t=Array.from(e.entries()).map(([e,t])=>({id:e,weight:t}));if(0===t.length)return[];if("softmax"===this.#u){const e=Math.max(...t.map(e=>e.weight)),r=t.map(t=>Math.exp(t.weight-e)),s=r.reduce((e,t)=>e+t,0);let i=0;return t.map((e,t)=>{const n=r[t]/s;return i+=n,{id:e.id,weight:e.weight,p:n,cumulative:i}})}{const e=t.reduce((e,t)=>e+t.weight,0);let r=0;return t.map(t=>{const s=t.weight/e;return r+=s,{id:t.id,weight:t.weight,p:s,cumulative:r}})}}drawOne(e={}){if(this._checkDestroyed(),"object"!=typeof e||null===e)throw new TypeError("drawOne: parameter 'opts' must be a non-null object, got "+typeof e);if("previousDraws"in e&&!Array.isArray(e.previousDraws))throw new TypeError("drawOne: opts.previousDraws must be an array if provided, got "+typeof e.previousDraws);if("metadata"in e&&void 0!==e.metadata&&("object"!=typeof e.metadata||null===e.metadata))throw new TypeError("drawOne: opts.metadata must be a non-null object if provided, got "+typeof e.metadata);const t={previousDraws:e.previousDraws??[],metadata:e.metadata??{},activeModifiers:[...this.#c]},r=this.computeEffectiveWeights(t),s=this._weightsToDistribution(r);if(!s.length)return null;const i=this.#g(),n=s.find(e=>i<=e.cumulative)??s[s.length-1];for(const[e,t]of this.#l)e===n.id?(t.counter=0,t.currentAdd=0):t.counter++;this._consumeTemporaryModifiers();const o=this.#w.get(n.id);if(!o)return null;const a={id:o.id,label:o.label,meta:{...o.meta},prob:n.p};return this.#a("draw",a),a&&this.#b.set(a.id,(this.#b.get(a.id)||0)+1),a}_consumeTemporaryModifiers(){this._checkDestroyed();for(let e=this.#c.length-1;e>=0;--e){const t=this.#c[e];t.uses-=1,t.uses<=0&&this.#c.splice(e,1)}}drawMany(e=1,t={}){if(this._checkDestroyed(),!Number.isInteger(e)||e<=0)throw new TypeError(`drawMany: parameter 'count' must be a positive integer, got ${e}`);if("object"!=typeof t||null===t)throw new TypeError("drawMany: parameter 'opts' must be a non-null object, got "+typeof t);if("withReplacement"in t&&"boolean"!=typeof t.withReplacement)throw new TypeError("drawMany: opts.withReplacement must be boolean if provided, got "+typeof t.withReplacement);if("ensureUnique"in t&&"boolean"!=typeof t.ensureUnique)throw new TypeError("drawMany: opts.ensureUnique must be boolean if provided, got "+typeof t.ensureUnique);if("metadata"in t&&void 0!==t.metadata&&("object"!=typeof t.metadata||null===t.metadata))throw new TypeError("drawMany: opts.metadata must be a non-null object if provided, got "+typeof t.metadata);if("previousDraws"in t&&!Array.isArray(t.previousDraws))throw new TypeError("drawMany: opts.previousDraws must be an array if provided, got "+typeof t.previousDraws);const r=t.withReplacement??!0,s=t.ensureUnique??!1,i=[],n=t.previousDraws??[];if(!r&&s){const r=new Set;for(let s=0;s<e;++s){const e=new Set(this.#y);for(const e of r)this.#y.add(e);const s=this.drawOne({previousDraws:n,metadata:t.metadata});if(this.#y=e,!s)break;i.push(s),r.add(s.id),n.push(s)}return i}for(let s=0;s<e;++s){const e=this.drawOne({previousDraws:n,metadata:t.metadata});if(!e)break;i.push(e),n.push(e),r||this.excludeItem(e.id)}if(!r)for(const e of i)this.includeItem(e.id);return i}exportToJson(){return this._checkDestroyed(),{items:Array.from(this.#w.values()).map(e=>({id:e.id,label:e.label,baseWeight:e.baseWeight,meta:e.meta,groups:Array.from(e.groups),locked:!1})),pity:Array.from(this.#l.entries()),exclusions:Array.from(this.#y),normalization:this.#u,seed:this.#f}}loadFromJson(e){if(this._checkDestroyed(),"object"!=typeof e||null===e)throw new TypeError("data must be a non-null object");if(!Array.isArray(e.items)||!Array.isArray(e.pity)||!Array.isArray(e.exclusions))throw new TypeError("data must have items, pity, and exclusions arrays");if("string"!=typeof e.normalization)throw new TypeError("data.normalization must be a string");if(void 0!==e.seed&&null!==e.seed&&"number"!=typeof e.seed)throw new TypeError("data.seed must be a number, null, or undefined");this.clearList();for(const t of e.items){if("object"!=typeof t||null===t)throw new TypeError("Each item must be a non-null object");if("string"!=typeof t.id||!t.id.trim())throw new TypeError("Each item.id must be a non-empty string");if("string"!=typeof t.label)throw new TypeError(`Item with id "${t.id}" has invalid label; must be string`);if("number"!=typeof t.baseWeight||!Number.isFinite(t.baseWeight)||t.baseWeight<0)throw new TypeError(`Item with id "${t.id}" has invalid baseWeight; must be a finite non-negative number`);if(void 0!==t.groups&&!Array.isArray(t.groups))throw new TypeError(`Item with id "${t.id}" has invalid groups; must be an array of strings`);if(t.groups&&!t.groups.every(e=>"string"==typeof e))throw new TypeError(`Item with id "${t.id}" has groups containing non-string values`);if(void 0!==t.meta&&("object"!=typeof t.meta||null===t.meta))throw new TypeError(`Item with id "${t.id}" has invalid meta; must be an object`);this.#w.set(t.id,{id:t.id,label:t.label,baseWeight:t.baseWeight,meta:t.meta||{},groups:new Set(t.groups||[]),locked:!1});for(const e of t.groups||[])this._ensureGroup(e).add(t.id)}this.pitySystems=new Map(e.pity||[]),this.exclusions=new Set(e.exclusions||[]),this.normalization=e.normalization,void 0!==e.seed&&(this.seed=e.seed)}clone(){this._checkDestroyed();const e=new s;return e.#u=this.#u,e.#f=this.#f,e.#p=[...this.#p],e.#c=this.#c.map(e=>({fn:e.fn,uses:e.uses})),e.#m=[...this.#m],e.#l=new Map([...this.#l.entries()].map(([e,t])=>[e,{...t}])),e.#y=new Set(this.#y),e.#d=new Map([...this.#d.entries()].map(([e,t])=>[e,new Set(t)])),e.#g=this.#g,e.#w=new Map([...this.#w.entries()].map(([e,t])=>[e,{...t,groups:new Set(t.groups),meta:{...t.meta}}])),e.#b=new Map(this.#b),e}_makeSeededRng(e){if(this._checkDestroyed(),"number"!=typeof e||!Number.isFinite(e))throw new TypeError("seed must be a finite number");let t=e>>>0;return function(){t+=1831565813;let e=Math.imul(t^t>>>15,1|t);return e^=e+Math.imul(e^e>>>7,61|e),((e^e>>>14)>>>0)/4294967296}}destroy(){this.#h||(this.#h=!0,this.#l.clear(),this.#y.clear(),this.#d.clear(),this.#w.clear(),this.#b.clear(),this.#p=[],this.#c=[],this.#m=[],this.#f=null)}}const i=s;window.TinyAdvancedRaffle=t.TinyAdvancedRaffle})();
1
+ (()=>{"use strict";var e={7(e){var t,r="object"==typeof Reflect?Reflect:null,i=r&&"function"==typeof r.apply?r.apply:function(e,t,r){return Function.prototype.apply.call(e,t,r)};t=r&&"function"==typeof r.ownKeys?r.ownKeys:Object.getOwnPropertySymbols?function(e){return Object.getOwnPropertyNames(e).concat(Object.getOwnPropertySymbols(e))}:function(e){return Object.getOwnPropertyNames(e)};var o=Number.isNaN||function(e){return e!=e};function s(){s.init.call(this)}e.exports=s,e.exports.once=function(e,t){return new Promise(function(r,i){function o(r){e.removeListener(t,s),i(r)}function s(){"function"==typeof e.removeListener&&e.removeListener("error",o),r([].slice.call(arguments))}d(e,t,s,{once:!0}),"error"!==t&&function(e,t){"function"==typeof e.on&&d(e,"error",t,{once:!0})}(e,o)})},s.EventEmitter=s,s.prototype._events=void 0,s.prototype._eventsCount=0,s.prototype._maxListeners=void 0;var n=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?s.defaultMaxListeners:e._maxListeners}function f(e,t,r,i){var o,s,n,f;if(a(r),void 0===(s=e._events)?(s=e._events=Object.create(null),e._eventsCount=0):(void 0!==s.newListener&&(e.emit("newListener",t,r.listener?r.listener:r),s=e._events),n=s[t]),void 0===n)n=s[t]=r,++e._eventsCount;else if("function"==typeof n?n=s[t]=i?[r,n]:[n,r]:i?n.unshift(r):n.push(r),(o=u(e))>0&&n.length>o&&!n.warned){n.warned=!0;var h=new Error("Possible EventEmitter memory leak detected. "+n.length+" "+String(t)+" listeners added. Use emitter.setMaxListeners() to increase limit");h.name="MaxListenersExceededWarning",h.emitter=e,h.type=t,h.count=n.length,f=h,console&&console.warn&&console.warn(f)}return e}function h(){if(!this.fired)return this.target.removeListener(this.type,this.wrapFn),this.fired=!0,0===arguments.length?this.listener.call(this.target):this.listener.apply(this.target,arguments)}function p(e,t,r){var i={fired:!1,wrapFn:void 0,target:e,type:t,listener:r},o=h.bind(i);return o.listener=r,i.wrapFn=o,o}function c(e,t,r){var i=e._events;if(void 0===i)return[];var o=i[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):y(o,o.length)}function m(e){var t=this._events;if(void 0!==t){var r=t[e];if("function"==typeof r)return 1;if(void 0!==r)return r.length}return 0}function y(e,t){for(var r=new Array(t),i=0;i<t;++i)r[i]=e[i];return r}function d(e,t,r,i){if("function"==typeof e.on)i.once?e.once(t,r):e.on(t,r);else{if("function"!=typeof e.addEventListener)throw new TypeError('The "emitter" argument must be of type EventEmitter. Received type '+typeof e);e.addEventListener(t,function o(s){i.once&&e.removeEventListener(t,o),r(s)})}}Object.defineProperty(s,"defaultMaxListeners",{enumerable:!0,get:function(){return n},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+".");n=e}}),s.init=function(){void 0!==this._events&&this._events!==Object.getPrototypeOf(this)._events||(this._events=Object.create(null),this._eventsCount=0),this._maxListeners=this._maxListeners||void 0},s.prototype.setMaxListeners=function(e){if("number"!=typeof e||e<0||o(e))throw new RangeError('The value of "n" is out of range. It must be a non-negative number. Received '+e+".");return this._maxListeners=e,this},s.prototype.getMaxListeners=function(){return u(this)},s.prototype.emit=function(e){for(var t=[],r=1;r<arguments.length;r++)t.push(arguments[r]);var o="error"===e,s=this._events;if(void 0!==s)o=o&&void 0===s.error;else if(!o)return!1;if(o){var n;if(t.length>0&&(n=t[0]),n instanceof Error)throw n;var a=new Error("Unhandled error."+(n?" ("+n.message+")":""));throw a.context=n,a}var u=s[e];if(void 0===u)return!1;if("function"==typeof u)i(u,this,t);else{var f=u.length,h=y(u,f);for(r=0;r<f;++r)i(h[r],this,t)}return!0},s.prototype.addListener=function(e,t){return f(this,e,t,!1)},s.prototype.on=s.prototype.addListener,s.prototype.prependListener=function(e,t){return f(this,e,t,!0)},s.prototype.once=function(e,t){return a(t),this.on(e,p(this,e,t)),this},s.prototype.prependOnceListener=function(e,t){return a(t),this.prependListener(e,p(this,e,t)),this},s.prototype.removeListener=function(e,t){var r,i,o,s,n;if(a(t),void 0===(i=this._events))return this;if(void 0===(r=i[e]))return this;if(r===t||r.listener===t)0===--this._eventsCount?this._events=Object.create(null):(delete i[e],i.removeListener&&this.emit("removeListener",e,r.listener||t));else if("function"!=typeof r){for(o=-1,s=r.length-1;s>=0;s--)if(r[s]===t||r[s].listener===t){n=r[s].listener,o=s;break}if(o<0)return this;0===o?r.shift():function(e,t){for(;t+1<e.length;t++)e[t]=e[t+1];e.pop()}(r,o),1===r.length&&(i[e]=r[0]),void 0!==i.removeListener&&this.emit("removeListener",e,n||t)}return this},s.prototype.off=s.prototype.removeListener,s.prototype.removeAllListeners=function(e){var t,r,i;if(void 0===(r=this._events))return this;if(void 0===r.removeListener)return 0===arguments.length?(this._events=Object.create(null),this._eventsCount=0):void 0!==r[e]&&(0===--this._eventsCount?this._events=Object.create(null):delete r[e]),this;if(0===arguments.length){var o,s=Object.keys(r);for(i=0;i<s.length;++i)"removeListener"!==(o=s[i])&&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(i=t.length-1;i>=0;i--)this.removeListener(e,t[i]);return this},s.prototype.listeners=function(e){return c(this,e,!0)},s.prototype.rawListeners=function(e){return c(this,e,!1)},s.listenerCount=function(e,t){return"function"==typeof e.listenerCount?e.listenerCount(t):m.call(e,t)},s.prototype.listenerCount=m,s.prototype.eventNames=function(){return this._eventsCount>0?t(this._events):[]}}};const t={};function r(i){const o=t[i];if(void 0!==o)return o.exports;const s=t[i]={exports:{}};return e[i](s,s.exports,r),s.exports}r.d=(e,t)=>{if(Array.isArray(t))for(var i=0;i<t.length;){var o=t[i++],s=t[i++];r.o(e,o)?0===s&&i++:0===s?Object.defineProperty(e,o,{enumerable:!0,value:t[i++]}):Object.defineProperty(e,o,{enumerable:!0,get:s})}else for(var o in t)r.o(t,o)&&!r.o(e,o)&&Object.defineProperty(e,o,{enumerable:!0,get:t[o]})},r.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t);let i={};r.d(i,{TinyAdvancedRaffle:()=>n});var o=r(7);class s extends o.EventEmitter{#e=!1;#t;#r;#i=[];#o=[];#s=[];#n=new Map;#a=new Set;#u=new Map;#f;#h=new Map;#p=new Map;get isDestroyed(){return this.#e}get freq(){return Object.fromEntries(this.#p)}get size(){return this.#h.size}get normalization(){return this.#t}set normalization(e){if(this._checkDestroyed(),"string"!=typeof e||!e.trim())throw new TypeError("normalization must be a non-empty string (e.g., 'relative', 'softmax').");this.#t=e}get seed(){return this.#r}set seed(e){if(this._checkDestroyed(),null!==e&&("number"!=typeof e||!Number.isFinite(e)))throw new TypeError("seed must be a finite number or null.");this.#r=e,null!==e&&(this.#f=this._makeSeededRng(e))}get globalModifiers(){return[...this.#i]}set globalModifiers(e){if(this._checkDestroyed(),!Array.isArray(e)||!e.every(e=>"function"==typeof e))throw new TypeError("globalModifiers must be an array of functions (WeightsCallback).");this.#i=e}get temporaryModifiers(){return[...this.#o]}set temporaryModifiers(e){if(this._checkDestroyed(),!Array.isArray(e)||!e.every(e=>e&&"function"==typeof e.fn&&Number.isInteger(e.uses)&&e.uses>0))throw new TypeError("temporaryModifiers must be an array of objects { fn: function, uses: positive integer }.");this.#o=e}get conditionalRules(){return[...this.#s]}set conditionalRules(e){if(this._checkDestroyed(),!Array.isArray(e)||!e.every(e=>"function"==typeof e))throw new TypeError("conditionalRules must be an array of functions (WeightsCallback).");this.#s=e}get pitySystems(){return Object.fromEntries(this.#n)}set pitySystems(e){if(this._checkDestroyed(),!(e instanceof Map&&[...e.values()].every(e=>e&&"number"==typeof e.threshold&&"number"==typeof e.increment&&"number"==typeof e.cap&&"number"==typeof e.counter&&"number"==typeof e.currentAdd)))throw new TypeError("pitySystems must be a Map<string, Pity> with all numeric fields.");this.#n=e}get exclusions(){return Array.from(this.#a)}set exclusions(e){if(this._checkDestroyed(),!(e instanceof Set&&[...e].every(e=>"string"==typeof e)))throw new TypeError("exclusions must be a Set<string>.");this.#a=e}get groups(){const e={};return this.#u.forEach((t,r)=>e[r]=Array.from(t)),e}set groups(e){if(this._checkDestroyed(),!(e instanceof Map&&[...e.values()].every(e=>e instanceof Set&&[...e].every(e=>"string"==typeof e))))throw new TypeError("groups must be a Map<string, Set<string>>.");this.#u=e}get rng(){return this.#f}set rng(e){if(this._checkDestroyed(),"function"!=typeof e||"number"!=typeof e())throw new TypeError("rng must be a function returning a number (RngGenerator).");this.#f=e}get items(){const e={};return this.#h.forEach((t,r)=>{e[r]={...t,groups:Array.from(t.groups)}}),e}set items(e){if(this._checkDestroyed(),!(e instanceof Map&&[...e.values()].every(e=>e&&"string"==typeof e.id&&"string"==typeof e.label&&"number"==typeof e.baseWeight&&e.groups instanceof Set&&"boolean"==typeof e.locked&&"object"==typeof e.meta)))throw new TypeError("items must be a Map<string, ItemData> with valid item structures.");this.clearList(),this.#h=e}constructor(e={}){super();const{rng:t=null,seed:r=null,normalization:i="relative"}=e;this.#t=i,this.#r=r,"function"==typeof t?this.#f=t:null!==this.#r?this.#f=this._makeSeededRng(this.#r):this.#f=Math.random,this.#r=r??null}_checkDestroyed(){if(this.#e)throw new Error("This instance has been destroyed and can no longer be used.")}hasItem(e){if("string"!=typeof e)throw new TypeError("itemId must be a string");return this.#h.has(e)}addItem(e,t={}){if(this._checkDestroyed(),"string"!=typeof e||!e.trim())throw new TypeError("id must be a non-empty string");if("object"!=typeof t||null===t)throw new TypeError("opts must be an object");let{weight:r=1,label:i=e,meta:o={},groups:s=[]}=t;if("number"!=typeof r||!Number.isFinite(r)||r<0)throw new TypeError("weight must be a non-negative number");if("string"!=typeof i)throw new TypeError("label must be a string");if("object"!=typeof o||null===o)throw new TypeError("meta must be an object");if(!(Array.isArray(s)||s instanceof Set))throw new TypeError("groups must be an array or a Set of strings");s=Array.isArray(s)?s:[...s];for(const e of s)if("string"!=typeof e)throw new TypeError("groups must contain only strings");const n={id:e,label:i,baseWeight:Math.max(0,Number(r)||0),meta:{...o},groups:new Set(s),locked:!1};this.#h.set(e,n);for(const t of s)this._ensureGroup(t).add(e);return this.emit("itemAdded",n),n}removeItem(e){if(this._checkDestroyed(),"string"!=typeof e||!e.trim())throw new TypeError("id must be a non-empty string");const t=this.#h.get(e);if(!t)return!1;for(const r of t.groups){const t=this.#u.get(r);t&&t.delete(e)}return this.#h.delete(e),this.emit("itemRemoved",e),this.resetFreq(e),this.resetPity(e),!0}setBaseWeight(e,t){if(this._checkDestroyed(),"string"!=typeof e||!e.trim())throw new TypeError("id must be a non-empty string");if("number"!=typeof t||!Number.isFinite(t)||t<0)throw new TypeError("weight must be a non-negative number");const r=this.#h.get(e);if(!r)throw new Error("Item not found");r.baseWeight=Math.max(0,Number(t)||0),this.emit("weightChanged",{id:e,weight:r.baseWeight})}getItem(e){if("string"!=typeof e||!e.trim())throw new TypeError("id must be a non-empty string");return this.#h.get(e)??null}listItems(){return Array.from(this.#h.values()).map(e=>({...e}))}clearList(){this._checkDestroyed(),this.#h.clear(),this.clearFreqs(),this.clearPities()}hasGlobalModifier(e){if("function"!=typeof e)throw new TypeError("fn must be a function");return this.#i.includes(e)}addGlobalModifier(e){if(this._checkDestroyed(),"function"!=typeof e)throw new TypeError("fn must be a function");this.#i.push(e)}removeGlobalModifier(e){if(this._checkDestroyed(),"function"!=typeof e)throw new TypeError("fn must be a function");this.#i=this.#i.filter(t=>t!==e)}hasTemporaryModifier(e){if("function"!=typeof e)throw new TypeError("fn must be a function");return this.#o.some(t=>t.fn===e)}addTemporaryModifier(e,t=1){if(this._checkDestroyed(),"function"!=typeof e)throw new TypeError("fn must be a function");if("number"!=typeof t||Number.isNaN(t))throw new TypeError("uses must be a number");this.#o.push({fn:e,uses:Math.max(1,Math.floor(t))})}removeTemporaryModifier(e){if(this._checkDestroyed(),"function"!=typeof e)throw new TypeError("fn must be a function");const t=this.#o.length;return this.#o=this.#o.filter(t=>t.fn!==e),this.#o.length!==t}hasConditionalRule(e){if("function"!=typeof e)throw new TypeError("ruleFn must be a function");return this.#s.includes(e)}addConditionalRule(e){if(this._checkDestroyed(),"function"!=typeof e)throw new TypeError("ruleFn must be a function");this.#s.push(e)}removeConditionalRule(e){if(this._checkDestroyed(),"function"!=typeof e)throw new TypeError("ruleFn must be a function");const t=this.#s.length;return this.#s=this.#s.filter(t=>t!==e),this.#s.length!==t}hasPity(e){if("string"!=typeof e)throw new TypeError("itemId must be a string");return this.#n.has(e)}configurePity(e,t){if(this._checkDestroyed(),!this.#h.has(e))throw new Error("Item not found");if("object"!=typeof t||null===t)throw new TypeError("cfg must be an object");const{threshold:r,increment:i,cap:o=1/0}=t;if("number"!=typeof r||r<=0)throw new TypeError("threshold must be a positive number");if("number"!=typeof i)throw new TypeError("increment must be a number");if("number"!=typeof o)throw new TypeError("cap must be a number");this.#n.set(e,{threshold:Math.max(1,r),increment:Number(i)||0,cap:Number(o)||1/0,counter:0,currentAdd:0})}resetPity(e){if(this._checkDestroyed(),"string"!=typeof e||!e.trim())throw new TypeError("itemId must be a non-empty string");const t=this.#n.get(e);t&&(t.counter=0,t.currentAdd=0)}clearPities(){this._checkDestroyed(),this.#n.clear()}hasExclusion(e){if("string"!=typeof e)throw new TypeError("itemId must be a string");return this.#a.has(e)}excludeItem(e){if(this._checkDestroyed(),"string"!=typeof e)throw new TypeError("itemId must be a string");this.#a.add(e)}includeItem(e){if(this._checkDestroyed(),"string"!=typeof e)throw new TypeError("itemId must be a string");this.#a.delete(e)}_ensureGroup(e){if(this._checkDestroyed(),"string"!=typeof e)throw new TypeError("name must be a string");let t=this.#u.get(e);return t||(t=new Set,this.#u.set(e,t)),t}hasInGroup(e,t){if("string"!=typeof e||"string"!=typeof t)throw new TypeError("itemId and groupName must be strings");const r=this.#u.get(t);return!!r&&r.has(e)}addToGroup(e,t){if(this._checkDestroyed(),"string"!=typeof e||"string"!=typeof t)throw new TypeError("itemId and groupName must be strings");const r=this.#h.get(e);if(!r)throw new Error("Item missing");r.groups.add(t),this._ensureGroup(t).add(e)}removeFromGroup(e,t){if(this._checkDestroyed(),"string"!=typeof e||"string"!=typeof t)throw new TypeError("itemId and groupName must be strings");const r=this.#u.get(t);r&&r.delete(e);const i=this.#h.get(e);i&&i.groups.delete(t)}clearFreqs(){this._checkDestroyed(),this.#p.clear()}resetFreq(e){if(this._checkDestroyed(),"string"!=typeof e)throw new TypeError("itemId must be a string");this.#p.delete(e)}computeEffectiveWeights(e={}){if(this._checkDestroyed(),"object"!=typeof e||null===e)throw new TypeError("computeEffectiveWeights: parameter 'context' must be a non-null object, got "+typeof e);if("previousDraws"in e&&!Array.isArray(e.previousDraws))throw new TypeError("computeEffectiveWeights: context.previousDraws must be an array if provided, got "+typeof e.previousDraws);if("metadata"in e&&void 0!==e.metadata&&("object"!=typeof e.metadata||null===e.metadata))throw new TypeError("computeEffectiveWeights: context.metadata must be a non-null object if provided, got "+typeof e.metadata);const t=new Map;for(const[e,r]of this.#h)t.set(e,r.baseWeight);for(const r of this.#i){const i=r(t,e);if(i instanceof Map)for(const[e,r]of i)t.set(e,Math.max(0,(t.get(e)||0)+r))}for(const r of this.#o){const i=r.fn(t,e);if(i instanceof Map)for(const[e,r]of i)t.set(e,Math.max(0,(t.get(e)||0)+r))}for(const r of this.#s){const i=r(t,e);if(i instanceof Map)for(const[e,r]of i)t.set(e,Math.max(0,(t.get(e)||0)+r))}for(const[e,r]of this.#n)if(t.has(e)&&r.counter>r.threshold){r.currentAdd=Math.min(r.cap,r.currentAdd+r.increment);const i=t.get(e);i&&t.set(e,i+r.currentAdd)}for(const e of this.#a)t.delete(e);for(const[e,r]of Array.from(t.entries()))r>0||t.delete(e);return t}_weightsToDistribution(e){if(this._checkDestroyed(),!(e instanceof Map))throw new TypeError("_weightsToDistribution: parameter 'weights' must be a Map, got "+typeof e);for(const[t,r]of e){if("string"!=typeof t)throw new TypeError("_weightsToDistribution: weights Map key must be string, got "+typeof t);if("number"!=typeof r||!Number.isFinite(r)||r<0)throw new TypeError(`_weightsToDistribution: weights Map value must be finite non-negative number, got ${r} for key ${t}`)}const t=Array.from(e.entries()).map(([e,t])=>({id:e,weight:t}));if(0===t.length)return[];if("softmax"===this.#t){const e=Math.max(...t.map(e=>e.weight)),r=t.map(t=>Math.exp(t.weight-e)),i=r.reduce((e,t)=>e+t,0);let o=0;return t.map((e,t)=>{const s=r[t]/i;return o+=s,{id:e.id,weight:e.weight,p:s,cumulative:o}})}{const e=t.reduce((e,t)=>e+t.weight,0);let r=0;return t.map(t=>{const i=t.weight/e;return r+=i,{id:t.id,weight:t.weight,p:i,cumulative:r}})}}drawOne(e={}){if(this._checkDestroyed(),"object"!=typeof e||null===e)throw new TypeError("drawOne: parameter 'opts' must be a non-null object, got "+typeof e);if("previousDraws"in e&&!Array.isArray(e.previousDraws))throw new TypeError("drawOne: opts.previousDraws must be an array if provided, got "+typeof e.previousDraws);if("metadata"in e&&void 0!==e.metadata&&("object"!=typeof e.metadata||null===e.metadata))throw new TypeError("drawOne: opts.metadata must be a non-null object if provided, got "+typeof e.metadata);const t={previousDraws:e.previousDraws??[],metadata:e.metadata??{},activeModifiers:[...this.#o]},r=this.computeEffectiveWeights(t),i=this._weightsToDistribution(r);if(!i.length)return null;const o=this.#f(),s=i.find(e=>o<=e.cumulative)??i[i.length-1];for(const[e,t]of this.#n)e===s.id?(t.counter=0,t.currentAdd=0):t.counter++;this._consumeTemporaryModifiers();const n=this.#h.get(s.id);if(!n)return null;const a={id:n.id,label:n.label,meta:{...n.meta},prob:s.p};return this.emit("draw",a),a&&this.#p.set(a.id,(this.#p.get(a.id)||0)+1),a}_consumeTemporaryModifiers(){this._checkDestroyed();for(let e=this.#o.length-1;e>=0;--e){const t=this.#o[e];t.uses-=1,t.uses<=0&&this.#o.splice(e,1)}}drawMany(e=1,t={}){if(this._checkDestroyed(),!Number.isInteger(e)||e<=0)throw new TypeError(`drawMany: parameter 'count' must be a positive integer, got ${e}`);if("object"!=typeof t||null===t)throw new TypeError("drawMany: parameter 'opts' must be a non-null object, got "+typeof t);if("withReplacement"in t&&"boolean"!=typeof t.withReplacement)throw new TypeError("drawMany: opts.withReplacement must be boolean if provided, got "+typeof t.withReplacement);if("ensureUnique"in t&&"boolean"!=typeof t.ensureUnique)throw new TypeError("drawMany: opts.ensureUnique must be boolean if provided, got "+typeof t.ensureUnique);if("metadata"in t&&void 0!==t.metadata&&("object"!=typeof t.metadata||null===t.metadata))throw new TypeError("drawMany: opts.metadata must be a non-null object if provided, got "+typeof t.metadata);if("previousDraws"in t&&!Array.isArray(t.previousDraws))throw new TypeError("drawMany: opts.previousDraws must be an array if provided, got "+typeof t.previousDraws);const r=t.withReplacement??!0,i=t.ensureUnique??!1,o=[],s=t.previousDraws??[];if(!r&&i){const r=new Set;for(let i=0;i<e;++i){const e=new Set(this.#a);for(const e of r)this.#a.add(e);const i=this.drawOne({previousDraws:s,metadata:t.metadata});if(this.#a=e,!i)break;o.push(i),r.add(i.id),s.push(i)}return o}for(let i=0;i<e;++i){const e=this.drawOne({previousDraws:s,metadata:t.metadata});if(!e)break;o.push(e),s.push(e),r||this.excludeItem(e.id)}if(!r)for(const e of o)this.includeItem(e.id);return o}exportToJson(){return this._checkDestroyed(),{items:Array.from(this.#h.values()).map(e=>({id:e.id,label:e.label,baseWeight:e.baseWeight,meta:e.meta,groups:Array.from(e.groups),locked:!1})),pity:Array.from(this.#n.entries()),exclusions:Array.from(this.#a),normalization:this.#t,seed:this.#r}}loadFromJson(e){if(this._checkDestroyed(),"object"!=typeof e||null===e)throw new TypeError("data must be a non-null object");if(!Array.isArray(e.items)||!Array.isArray(e.pity)||!Array.isArray(e.exclusions))throw new TypeError("data must have items, pity, and exclusions arrays");if("string"!=typeof e.normalization)throw new TypeError("data.normalization must be a string");if(void 0!==e.seed&&null!==e.seed&&"number"!=typeof e.seed)throw new TypeError("data.seed must be a number, null, or undefined");this.clearList();for(const t of e.items){if("object"!=typeof t||null===t)throw new TypeError("Each item must be a non-null object");if("string"!=typeof t.id||!t.id.trim())throw new TypeError("Each item.id must be a non-empty string");if("string"!=typeof t.label)throw new TypeError(`Item with id "${t.id}" has invalid label; must be string`);if("number"!=typeof t.baseWeight||!Number.isFinite(t.baseWeight)||t.baseWeight<0)throw new TypeError(`Item with id "${t.id}" has invalid baseWeight; must be a finite non-negative number`);if(void 0!==t.groups&&!Array.isArray(t.groups))throw new TypeError(`Item with id "${t.id}" has invalid groups; must be an array of strings`);if(t.groups&&!t.groups.every(e=>"string"==typeof e))throw new TypeError(`Item with id "${t.id}" has groups containing non-string values`);if(void 0!==t.meta&&("object"!=typeof t.meta||null===t.meta))throw new TypeError(`Item with id "${t.id}" has invalid meta; must be an object`);this.#h.set(t.id,{id:t.id,label:t.label,baseWeight:t.baseWeight,meta:t.meta||{},groups:new Set(t.groups||[]),locked:!1});for(const e of t.groups||[])this._ensureGroup(e).add(t.id)}this.pitySystems=new Map(e.pity||[]),this.exclusions=new Set(e.exclusions||[]),this.normalization=e.normalization,void 0!==e.seed&&(this.seed=e.seed)}clone(){this._checkDestroyed();const e=new s;return e.#t=this.#t,e.#r=this.#r,e.#i=[...this.#i],e.#o=this.#o.map(e=>({fn:e.fn,uses:e.uses})),e.#s=[...this.#s],e.#n=new Map([...this.#n.entries()].map(([e,t])=>[e,{...t}])),e.#a=new Set(this.#a),e.#u=new Map([...this.#u.entries()].map(([e,t])=>[e,new Set(t)])),e.#f=this.#f,e.#h=new Map([...this.#h.entries()].map(([e,t])=>[e,{...t,groups:new Set(t.groups),meta:{...t.meta}}])),e.#p=new Map(this.#p),e}_makeSeededRng(e){if(this._checkDestroyed(),"number"!=typeof e||!Number.isFinite(e))throw new TypeError("seed must be a finite number");let t=e>>>0;return function(){t+=1831565813;let e=Math.imul(t^t>>>15,1|t);return e^=e+Math.imul(e^e>>>7,61|e),((e^e>>>14)>>>0)/4294967296}}destroy(){this.#e||(this.#e=!0,this.#n.clear(),this.#a.clear(),this.#u.clear(),this.#h.clear(),this.#p.clear(),this.#i=[],this.#o=[],this.#s=[],this.#r=null)}}const n=s;window.TinyAdvancedRaffle=i.TinyAdvancedRaffle})();
@@ -1,2 +1 @@
1
- /*! For license information please see TinyBasicsEs.min.js.LICENSE.txt */
2
- (()=>{var t={526(t,e){"use strict";e.byteLength=function(t){var e=s(t),r=e[0],n=e[1];return 3*(r+n)/4-n},e.toByteArray=function(t){var e,r,i=s(t),a=i[0],u=i[1],f=new o(function(t,e,r){return 3*(e+r)/4-r}(0,a,u)),l=0,c=u>0?a-4:a;for(r=0;r<c;r+=4)e=n[t.charCodeAt(r)]<<18|n[t.charCodeAt(r+1)]<<12|n[t.charCodeAt(r+2)]<<6|n[t.charCodeAt(r+3)],f[l++]=e>>16&255,f[l++]=e>>8&255,f[l++]=255&e;return 2===u&&(e=n[t.charCodeAt(r)]<<2|n[t.charCodeAt(r+1)]>>4,f[l++]=255&e),1===u&&(e=n[t.charCodeAt(r)]<<10|n[t.charCodeAt(r+1)]<<4|n[t.charCodeAt(r+2)]>>2,f[l++]=e>>8&255,f[l++]=255&e),f},e.fromByteArray=function(t){for(var e,n=t.length,o=n%3,i=[],a=16383,s=0,u=n-o;s<u;s+=a)i.push(f(t,s,s+a>u?u:s+a));return 1===o?(e=t[n-1],i.push(r[e>>2]+r[e<<4&63]+"==")):2===o&&(e=(t[n-2]<<8)+t[n-1],i.push(r[e>>10]+r[e>>4&63]+r[e<<2&63]+"=")),i.join("")};for(var r=[],n=[],o="undefined"!=typeof Uint8Array?Uint8Array:Array,i="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",a=0;a<64;++a)r[a]=i[a],n[i.charCodeAt(a)]=a;function s(t){var e=t.length;if(e%4>0)throw new Error("Invalid string. Length must be a multiple of 4");var r=t.indexOf("=");return-1===r&&(r=e),[r,r===e?0:4-r%4]}function u(t){return r[t>>18&63]+r[t>>12&63]+r[t>>6&63]+r[63&t]}function f(t,e,r){for(var n,o=[],i=e;i<r;i+=3)n=(t[i]<<16&16711680)+(t[i+1]<<8&65280)+(255&t[i+2]),o.push(u(n));return o.join("")}n["-".charCodeAt(0)]=62,n["_".charCodeAt(0)]=63},251(t,e){e.read=function(t,e,r,n,o){var i,a,s=8*o-n-1,u=(1<<s)-1,f=u>>1,l=-7,c=r?o-1:0,h=r?-1:1,p=t[e+c];for(c+=h,i=p&(1<<-l)-1,p>>=-l,l+=s;l>0;i=256*i+t[e+c],c+=h,l-=8);for(a=i&(1<<-l)-1,i>>=-l,l+=n;l>0;a=256*a+t[e+c],c+=h,l-=8);if(0===i)i=1-f;else{if(i===u)return a?NaN:1/0*(p?-1:1);a+=Math.pow(2,n),i-=f}return(p?-1:1)*a*Math.pow(2,i-n)},e.write=function(t,e,r,n,o,i){var a,s,u,f=8*i-o-1,l=(1<<f)-1,c=l>>1,h=23===o?Math.pow(2,-24)-Math.pow(2,-77):0,p=n?0:i-1,d=n?1:-1,y=e<0||0===e&&1/e<0?1:0;for(e=Math.abs(e),isNaN(e)||e===1/0?(s=isNaN(e)?1:0,a=l):(a=Math.floor(Math.log(e)/Math.LN2),e*(u=Math.pow(2,-a))<1&&(a--,u*=2),(e+=a+c>=1?h/u:h*Math.pow(2,1-c))*u>=2&&(a++,u/=2),a+c>=l?(s=0,a=l):a+c>=1?(s=(e*u-1)*Math.pow(2,o),a+=c):(s=e*Math.pow(2,c-1)*Math.pow(2,o),a=0));o>=8;t[r+p]=255&s,p+=d,s/=256,o-=8);for(a=a<<o|s,f+=o;f>0;t[r+p]=255&a,p+=d,a/=256,f-=8);t[r+p-d]|=128*y}},271(t,e,r){"use strict";var n=r(526),o=r(251),i="function"==typeof Symbol&&"function"==typeof Symbol.for?Symbol.for("nodejs.util.inspect.custom"):null;e.hp=u,e.IS=50;var a=2147483647;function s(t){if(t>a)throw new RangeError('The value "'+t+'" is invalid for option "size"');var e=new Uint8Array(t);return Object.setPrototypeOf(e,u.prototype),e}function u(t,e,r){if("number"==typeof t){if("string"==typeof e)throw new TypeError('The "string" argument must be of type string. Received type number');return c(t)}return f(t,e,r)}function f(t,e,r){if("string"==typeof t)return function(t,e){if("string"==typeof e&&""!==e||(e="utf8"),!u.isEncoding(e))throw new TypeError("Unknown encoding: "+e);var r=0|y(t,e),n=s(r),o=n.write(t,e);return o!==r&&(n=n.slice(0,o)),n}(t,e);if(ArrayBuffer.isView(t))return function(t){if(Y(t,Uint8Array)){var e=new Uint8Array(t);return p(e.buffer,e.byteOffset,e.byteLength)}return h(t)}(t);if(null==t)throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof t);if(Y(t,ArrayBuffer)||t&&Y(t.buffer,ArrayBuffer))return p(t,e,r);if("undefined"!=typeof SharedArrayBuffer&&(Y(t,SharedArrayBuffer)||t&&Y(t.buffer,SharedArrayBuffer)))return p(t,e,r);if("number"==typeof t)throw new TypeError('The "value" argument must not be of type number. Received type number');var n=t.valueOf&&t.valueOf();if(null!=n&&n!==t)return u.from(n,e,r);var o=function(t){if(u.isBuffer(t)){var e=0|d(t.length),r=s(e);return 0===r.length||t.copy(r,0,0,e),r}return void 0!==t.length?"number"!=typeof t.length||z(t.length)?s(0):h(t):"Buffer"===t.type&&Array.isArray(t.data)?h(t.data):void 0}(t);if(o)return o;if("undefined"!=typeof Symbol&&null!=Symbol.toPrimitive&&"function"==typeof t[Symbol.toPrimitive])return u.from(t[Symbol.toPrimitive]("string"),e,r);throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof t)}function l(t){if("number"!=typeof t)throw new TypeError('"size" argument must be of type number');if(t<0)throw new RangeError('The value "'+t+'" is invalid for option "size"')}function c(t){return l(t),s(t<0?0:0|d(t))}function h(t){for(var e=t.length<0?0:0|d(t.length),r=s(e),n=0;n<e;n+=1)r[n]=255&t[n];return r}function p(t,e,r){if(e<0||t.byteLength<e)throw new RangeError('"offset" is outside of buffer bounds');if(t.byteLength<e+(r||0))throw new RangeError('"length" is outside of buffer bounds');var n;return n=void 0===e&&void 0===r?new Uint8Array(t):void 0===r?new Uint8Array(t,e):new Uint8Array(t,e,r),Object.setPrototypeOf(n,u.prototype),n}function d(t){if(t>=a)throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+a.toString(16)+" bytes");return 0|t}function y(t,e){if(u.isBuffer(t))return t.length;if(ArrayBuffer.isView(t)||Y(t,ArrayBuffer))return t.byteLength;if("string"!=typeof t)throw new TypeError('The "string" argument must be one of type string, Buffer, or ArrayBuffer. Received type '+typeof t);var r=t.length,n=arguments.length>2&&!0===arguments[2];if(!n&&0===r)return 0;for(var o=!1;;)switch(e){case"ascii":case"latin1":case"binary":return r;case"utf8":case"utf-8":return D(t).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return 2*r;case"hex":return r>>>1;case"base64":return j(t).length;default:if(o)return n?-1:D(t).length;e=(""+e).toLowerCase(),o=!0}}function g(t,e,r){var n=!1;if((void 0===e||e<0)&&(e=0),e>this.length)return"";if((void 0===r||r>this.length)&&(r=this.length),r<=0)return"";if((r>>>=0)<=(e>>>=0))return"";for(t||(t="utf8");;)switch(t){case"hex":return U(this,e,r);case"utf8":case"utf-8":return N(this,e,r);case"ascii":return I(this,e,r);case"latin1":case"binary":return S(this,e,r);case"base64":return M(this,e,r);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return C(this,e,r);default:if(n)throw new TypeError("Unknown encoding: "+t);t=(t+"").toLowerCase(),n=!0}}function m(t,e,r){var n=t[e];t[e]=t[r],t[r]=n}function w(t,e,r,n,o){if(0===t.length)return-1;if("string"==typeof r?(n=r,r=0):r>2147483647?r=2147483647:r<-2147483648&&(r=-2147483648),z(r=+r)&&(r=o?0:t.length-1),r<0&&(r=t.length+r),r>=t.length){if(o)return-1;r=t.length-1}else if(r<0){if(!o)return-1;r=0}if("string"==typeof e&&(e=u.from(e,n)),u.isBuffer(e))return 0===e.length?-1:b(t,e,r,n,o);if("number"==typeof e)return e&=255,"function"==typeof Uint8Array.prototype.indexOf?o?Uint8Array.prototype.indexOf.call(t,e,r):Uint8Array.prototype.lastIndexOf.call(t,e,r):b(t,[e],r,n,o);throw new TypeError("val must be string, number or Buffer")}function b(t,e,r,n,o){var i,a=1,s=t.length,u=e.length;if(void 0!==n&&("ucs2"===(n=String(n).toLowerCase())||"ucs-2"===n||"utf16le"===n||"utf-16le"===n)){if(t.length<2||e.length<2)return-1;a=2,s/=2,u/=2,r/=2}function f(t,e){return 1===a?t[e]:t.readUInt16BE(e*a)}if(o){var l=-1;for(i=r;i<s;i++)if(f(t,i)===f(e,-1===l?0:i-l)){if(-1===l&&(l=i),i-l+1===u)return l*a}else-1!==l&&(i-=i-l),l=-1}else for(r+u>s&&(r=s-u),i=r;i>=0;i--){for(var c=!0,h=0;h<u;h++)if(f(t,i+h)!==f(e,h)){c=!1;break}if(c)return i}return-1}function v(t,e,r,n){r=Number(r)||0;var o=t.length-r;n?(n=Number(n))>o&&(n=o):n=o;var i=e.length;n>i/2&&(n=i/2);for(var a=0;a<n;++a){var s=parseInt(e.substr(2*a,2),16);if(z(s))return a;t[r+a]=s}return a}function E(t,e,r,n){return $(D(e,t.length-r),t,r,n)}function T(t,e,r,n){return $(function(t){for(var e=[],r=0;r<t.length;++r)e.push(255&t.charCodeAt(r));return e}(e),t,r,n)}function A(t,e,r,n){return $(j(e),t,r,n)}function B(t,e,r,n){return $(function(t,e){for(var r,n,o,i=[],a=0;a<t.length&&!((e-=2)<0);++a)n=(r=t.charCodeAt(a))>>8,o=r%256,i.push(o),i.push(n);return i}(e,t.length-r),t,r,n)}function M(t,e,r){return 0===e&&r===t.length?n.fromByteArray(t):n.fromByteArray(t.slice(e,r))}function N(t,e,r){r=Math.min(t.length,r);for(var n=[],o=e;o<r;){var i,a,s,u,f=t[o],l=null,c=f>239?4:f>223?3:f>191?2:1;if(o+c<=r)switch(c){case 1:f<128&&(l=f);break;case 2:128==(192&(i=t[o+1]))&&(u=(31&f)<<6|63&i)>127&&(l=u);break;case 3:i=t[o+1],a=t[o+2],128==(192&i)&&128==(192&a)&&(u=(15&f)<<12|(63&i)<<6|63&a)>2047&&(u<55296||u>57343)&&(l=u);break;case 4:i=t[o+1],a=t[o+2],s=t[o+3],128==(192&i)&&128==(192&a)&&128==(192&s)&&(u=(15&f)<<18|(63&i)<<12|(63&a)<<6|63&s)>65535&&u<1114112&&(l=u)}null===l?(l=65533,c=1):l>65535&&(l-=65536,n.push(l>>>10&1023|55296),l=56320|1023&l),n.push(l),o+=c}return function(t){var e=t.length;if(e<=L)return String.fromCharCode.apply(String,t);for(var r="",n=0;n<e;)r+=String.fromCharCode.apply(String,t.slice(n,n+=L));return r}(n)}u.TYPED_ARRAY_SUPPORT=function(){try{var t=new Uint8Array(1),e={foo:function(){return 42}};return Object.setPrototypeOf(e,Uint8Array.prototype),Object.setPrototypeOf(t,e),42===t.foo()}catch(t){return!1}}(),u.TYPED_ARRAY_SUPPORT||"undefined"==typeof console||"function"!=typeof console.error||console.error("This browser lacks typed array (Uint8Array) support which is required by `buffer` v5.x. Use `buffer` v4.x if you require old browser support."),Object.defineProperty(u.prototype,"parent",{enumerable:!0,get:function(){if(u.isBuffer(this))return this.buffer}}),Object.defineProperty(u.prototype,"offset",{enumerable:!0,get:function(){if(u.isBuffer(this))return this.byteOffset}}),u.poolSize=8192,u.from=function(t,e,r){return f(t,e,r)},Object.setPrototypeOf(u.prototype,Uint8Array.prototype),Object.setPrototypeOf(u,Uint8Array),u.alloc=function(t,e,r){return function(t,e,r){return l(t),t<=0?s(t):void 0!==e?"string"==typeof r?s(t).fill(e,r):s(t).fill(e):s(t)}(t,e,r)},u.allocUnsafe=function(t){return c(t)},u.allocUnsafeSlow=function(t){return c(t)},u.isBuffer=function(t){return null!=t&&!0===t._isBuffer&&t!==u.prototype},u.compare=function(t,e){if(Y(t,Uint8Array)&&(t=u.from(t,t.offset,t.byteLength)),Y(e,Uint8Array)&&(e=u.from(e,e.offset,e.byteLength)),!u.isBuffer(t)||!u.isBuffer(e))throw new TypeError('The "buf1", "buf2" arguments must be one of type Buffer or Uint8Array');if(t===e)return 0;for(var r=t.length,n=e.length,o=0,i=Math.min(r,n);o<i;++o)if(t[o]!==e[o]){r=t[o],n=e[o];break}return r<n?-1:n<r?1:0},u.isEncoding=function(t){switch(String(t).toLowerCase()){case"hex":case"utf8":case"utf-8":case"ascii":case"latin1":case"binary":case"base64":case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return!0;default:return!1}},u.concat=function(t,e){if(!Array.isArray(t))throw new TypeError('"list" argument must be an Array of Buffers');if(0===t.length)return u.alloc(0);var r;if(void 0===e)for(e=0,r=0;r<t.length;++r)e+=t[r].length;var n=u.allocUnsafe(e),o=0;for(r=0;r<t.length;++r){var i=t[r];if(Y(i,Uint8Array))o+i.length>n.length?u.from(i).copy(n,o):Uint8Array.prototype.set.call(n,i,o);else{if(!u.isBuffer(i))throw new TypeError('"list" argument must be an Array of Buffers');i.copy(n,o)}o+=i.length}return n},u.byteLength=y,u.prototype._isBuffer=!0,u.prototype.swap16=function(){var t=this.length;if(t%2!=0)throw new RangeError("Buffer size must be a multiple of 16-bits");for(var e=0;e<t;e+=2)m(this,e,e+1);return this},u.prototype.swap32=function(){var t=this.length;if(t%4!=0)throw new RangeError("Buffer size must be a multiple of 32-bits");for(var e=0;e<t;e+=4)m(this,e,e+3),m(this,e+1,e+2);return this},u.prototype.swap64=function(){var t=this.length;if(t%8!=0)throw new RangeError("Buffer size must be a multiple of 64-bits");for(var e=0;e<t;e+=8)m(this,e,e+7),m(this,e+1,e+6),m(this,e+2,e+5),m(this,e+3,e+4);return this},u.prototype.toString=function(){var t=this.length;return 0===t?"":0===arguments.length?N(this,0,t):g.apply(this,arguments)},u.prototype.toLocaleString=u.prototype.toString,u.prototype.equals=function(t){if(!u.isBuffer(t))throw new TypeError("Argument must be a Buffer");return this===t||0===u.compare(this,t)},u.prototype.inspect=function(){var t="",r=e.IS;return t=this.toString("hex",0,r).replace(/(.{2})/g,"$1 ").trim(),this.length>r&&(t+=" ... "),"<Buffer "+t+">"},i&&(u.prototype[i]=u.prototype.inspect),u.prototype.compare=function(t,e,r,n,o){if(Y(t,Uint8Array)&&(t=u.from(t,t.offset,t.byteLength)),!u.isBuffer(t))throw new TypeError('The "target" argument must be one of type Buffer or Uint8Array. Received type '+typeof t);if(void 0===e&&(e=0),void 0===r&&(r=t?t.length:0),void 0===n&&(n=0),void 0===o&&(o=this.length),e<0||r>t.length||n<0||o>this.length)throw new RangeError("out of range index");if(n>=o&&e>=r)return 0;if(n>=o)return-1;if(e>=r)return 1;if(this===t)return 0;for(var i=(o>>>=0)-(n>>>=0),a=(r>>>=0)-(e>>>=0),s=Math.min(i,a),f=this.slice(n,o),l=t.slice(e,r),c=0;c<s;++c)if(f[c]!==l[c]){i=f[c],a=l[c];break}return i<a?-1:a<i?1:0},u.prototype.includes=function(t,e,r){return-1!==this.indexOf(t,e,r)},u.prototype.indexOf=function(t,e,r){return w(this,t,e,r,!0)},u.prototype.lastIndexOf=function(t,e,r){return w(this,t,e,r,!1)},u.prototype.write=function(t,e,r,n){if(void 0===e)n="utf8",r=this.length,e=0;else if(void 0===r&&"string"==typeof e)n=e,r=this.length,e=0;else{if(!isFinite(e))throw new Error("Buffer.write(string, encoding, offset[, length]) is no longer supported");e>>>=0,isFinite(r)?(r>>>=0,void 0===n&&(n="utf8")):(n=r,r=void 0)}var o=this.length-e;if((void 0===r||r>o)&&(r=o),t.length>0&&(r<0||e<0)||e>this.length)throw new RangeError("Attempt to write outside buffer bounds");n||(n="utf8");for(var i=!1;;)switch(n){case"hex":return v(this,t,e,r);case"utf8":case"utf-8":return E(this,t,e,r);case"ascii":case"latin1":case"binary":return T(this,t,e,r);case"base64":return A(this,t,e,r);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return B(this,t,e,r);default:if(i)throw new TypeError("Unknown encoding: "+n);n=(""+n).toLowerCase(),i=!0}},u.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};var L=4096;function I(t,e,r){var n="";r=Math.min(t.length,r);for(var o=e;o<r;++o)n+=String.fromCharCode(127&t[o]);return n}function S(t,e,r){var n="";r=Math.min(t.length,r);for(var o=e;o<r;++o)n+=String.fromCharCode(t[o]);return n}function U(t,e,r){var n=t.length;(!e||e<0)&&(e=0),(!r||r<0||r>n)&&(r=n);for(var o="",i=e;i<r;++i)o+=H[t[i]];return o}function C(t,e,r){for(var n=t.slice(e,r),o="",i=0;i<n.length-1;i+=2)o+=String.fromCharCode(n[i]+256*n[i+1]);return o}function O(t,e,r){if(t%1!=0||t<0)throw new RangeError("offset is not uint");if(t+e>r)throw new RangeError("Trying to access beyond buffer length")}function k(t,e,r,n,o,i){if(!u.isBuffer(t))throw new TypeError('"buffer" argument must be a Buffer instance');if(e>o||e<i)throw new RangeError('"value" argument is out of bounds');if(r+n>t.length)throw new RangeError("Index out of range")}function x(t,e,r,n,o,i){if(r+n>t.length)throw new RangeError("Index out of range");if(r<0)throw new RangeError("Index out of range")}function R(t,e,r,n,i){return e=+e,r>>>=0,i||x(t,0,r,4),o.write(t,e,r,n,23,4),r+4}function F(t,e,r,n,i){return e=+e,r>>>=0,i||x(t,0,r,8),o.write(t,e,r,n,52,8),r+8}u.prototype.slice=function(t,e){var r=this.length;(t=~~t)<0?(t+=r)<0&&(t=0):t>r&&(t=r),(e=void 0===e?r:~~e)<0?(e+=r)<0&&(e=0):e>r&&(e=r),e<t&&(e=t);var n=this.subarray(t,e);return Object.setPrototypeOf(n,u.prototype),n},u.prototype.readUintLE=u.prototype.readUIntLE=function(t,e,r){t>>>=0,e>>>=0,r||O(t,e,this.length);for(var n=this[t],o=1,i=0;++i<e&&(o*=256);)n+=this[t+i]*o;return n},u.prototype.readUintBE=u.prototype.readUIntBE=function(t,e,r){t>>>=0,e>>>=0,r||O(t,e,this.length);for(var n=this[t+--e],o=1;e>0&&(o*=256);)n+=this[t+--e]*o;return n},u.prototype.readUint8=u.prototype.readUInt8=function(t,e){return t>>>=0,e||O(t,1,this.length),this[t]},u.prototype.readUint16LE=u.prototype.readUInt16LE=function(t,e){return t>>>=0,e||O(t,2,this.length),this[t]|this[t+1]<<8},u.prototype.readUint16BE=u.prototype.readUInt16BE=function(t,e){return t>>>=0,e||O(t,2,this.length),this[t]<<8|this[t+1]},u.prototype.readUint32LE=u.prototype.readUInt32LE=function(t,e){return t>>>=0,e||O(t,4,this.length),(this[t]|this[t+1]<<8|this[t+2]<<16)+16777216*this[t+3]},u.prototype.readUint32BE=u.prototype.readUInt32BE=function(t,e){return t>>>=0,e||O(t,4,this.length),16777216*this[t]+(this[t+1]<<16|this[t+2]<<8|this[t+3])},u.prototype.readIntLE=function(t,e,r){t>>>=0,e>>>=0,r||O(t,e,this.length);for(var n=this[t],o=1,i=0;++i<e&&(o*=256);)n+=this[t+i]*o;return n>=(o*=128)&&(n-=Math.pow(2,8*e)),n},u.prototype.readIntBE=function(t,e,r){t>>>=0,e>>>=0,r||O(t,e,this.length);for(var n=e,o=1,i=this[t+--n];n>0&&(o*=256);)i+=this[t+--n]*o;return i>=(o*=128)&&(i-=Math.pow(2,8*e)),i},u.prototype.readInt8=function(t,e){return t>>>=0,e||O(t,1,this.length),128&this[t]?-1*(255-this[t]+1):this[t]},u.prototype.readInt16LE=function(t,e){t>>>=0,e||O(t,2,this.length);var r=this[t]|this[t+1]<<8;return 32768&r?4294901760|r:r},u.prototype.readInt16BE=function(t,e){t>>>=0,e||O(t,2,this.length);var r=this[t+1]|this[t]<<8;return 32768&r?4294901760|r:r},u.prototype.readInt32LE=function(t,e){return t>>>=0,e||O(t,4,this.length),this[t]|this[t+1]<<8|this[t+2]<<16|this[t+3]<<24},u.prototype.readInt32BE=function(t,e){return t>>>=0,e||O(t,4,this.length),this[t]<<24|this[t+1]<<16|this[t+2]<<8|this[t+3]},u.prototype.readFloatLE=function(t,e){return t>>>=0,e||O(t,4,this.length),o.read(this,t,!0,23,4)},u.prototype.readFloatBE=function(t,e){return t>>>=0,e||O(t,4,this.length),o.read(this,t,!1,23,4)},u.prototype.readDoubleLE=function(t,e){return t>>>=0,e||O(t,8,this.length),o.read(this,t,!0,52,8)},u.prototype.readDoubleBE=function(t,e){return t>>>=0,e||O(t,8,this.length),o.read(this,t,!1,52,8)},u.prototype.writeUintLE=u.prototype.writeUIntLE=function(t,e,r,n){t=+t,e>>>=0,r>>>=0,n||k(this,t,e,r,Math.pow(2,8*r)-1,0);var o=1,i=0;for(this[e]=255&t;++i<r&&(o*=256);)this[e+i]=t/o&255;return e+r},u.prototype.writeUintBE=u.prototype.writeUIntBE=function(t,e,r,n){t=+t,e>>>=0,r>>>=0,n||k(this,t,e,r,Math.pow(2,8*r)-1,0);var o=r-1,i=1;for(this[e+o]=255&t;--o>=0&&(i*=256);)this[e+o]=t/i&255;return e+r},u.prototype.writeUint8=u.prototype.writeUInt8=function(t,e,r){return t=+t,e>>>=0,r||k(this,t,e,1,255,0),this[e]=255&t,e+1},u.prototype.writeUint16LE=u.prototype.writeUInt16LE=function(t,e,r){return t=+t,e>>>=0,r||k(this,t,e,2,65535,0),this[e]=255&t,this[e+1]=t>>>8,e+2},u.prototype.writeUint16BE=u.prototype.writeUInt16BE=function(t,e,r){return t=+t,e>>>=0,r||k(this,t,e,2,65535,0),this[e]=t>>>8,this[e+1]=255&t,e+2},u.prototype.writeUint32LE=u.prototype.writeUInt32LE=function(t,e,r){return t=+t,e>>>=0,r||k(this,t,e,4,4294967295,0),this[e+3]=t>>>24,this[e+2]=t>>>16,this[e+1]=t>>>8,this[e]=255&t,e+4},u.prototype.writeUint32BE=u.prototype.writeUInt32BE=function(t,e,r){return t=+t,e>>>=0,r||k(this,t,e,4,4294967295,0),this[e]=t>>>24,this[e+1]=t>>>16,this[e+2]=t>>>8,this[e+3]=255&t,e+4},u.prototype.writeIntLE=function(t,e,r,n){if(t=+t,e>>>=0,!n){var o=Math.pow(2,8*r-1);k(this,t,e,r,o-1,-o)}var i=0,a=1,s=0;for(this[e]=255&t;++i<r&&(a*=256);)t<0&&0===s&&0!==this[e+i-1]&&(s=1),this[e+i]=(t/a|0)-s&255;return e+r},u.prototype.writeIntBE=function(t,e,r,n){if(t=+t,e>>>=0,!n){var o=Math.pow(2,8*r-1);k(this,t,e,r,o-1,-o)}var i=r-1,a=1,s=0;for(this[e+i]=255&t;--i>=0&&(a*=256);)t<0&&0===s&&0!==this[e+i+1]&&(s=1),this[e+i]=(t/a|0)-s&255;return e+r},u.prototype.writeInt8=function(t,e,r){return t=+t,e>>>=0,r||k(this,t,e,1,127,-128),t<0&&(t=255+t+1),this[e]=255&t,e+1},u.prototype.writeInt16LE=function(t,e,r){return t=+t,e>>>=0,r||k(this,t,e,2,32767,-32768),this[e]=255&t,this[e+1]=t>>>8,e+2},u.prototype.writeInt16BE=function(t,e,r){return t=+t,e>>>=0,r||k(this,t,e,2,32767,-32768),this[e]=t>>>8,this[e+1]=255&t,e+2},u.prototype.writeInt32LE=function(t,e,r){return t=+t,e>>>=0,r||k(this,t,e,4,2147483647,-2147483648),this[e]=255&t,this[e+1]=t>>>8,this[e+2]=t>>>16,this[e+3]=t>>>24,e+4},u.prototype.writeInt32BE=function(t,e,r){return t=+t,e>>>=0,r||k(this,t,e,4,2147483647,-2147483648),t<0&&(t=4294967295+t+1),this[e]=t>>>24,this[e+1]=t>>>16,this[e+2]=t>>>8,this[e+3]=255&t,e+4},u.prototype.writeFloatLE=function(t,e,r){return R(this,t,e,!0,r)},u.prototype.writeFloatBE=function(t,e,r){return R(this,t,e,!1,r)},u.prototype.writeDoubleLE=function(t,e,r){return F(this,t,e,!0,r)},u.prototype.writeDoubleBE=function(t,e,r){return F(this,t,e,!1,r)},u.prototype.copy=function(t,e,r,n){if(!u.isBuffer(t))throw new TypeError("argument should be a Buffer");if(r||(r=0),n||0===n||(n=this.length),e>=t.length&&(e=t.length),e||(e=0),n>0&&n<r&&(n=r),n===r)return 0;if(0===t.length||0===this.length)return 0;if(e<0)throw new RangeError("targetStart out of bounds");if(r<0||r>=this.length)throw new RangeError("Index out of range");if(n<0)throw new RangeError("sourceEnd out of bounds");n>this.length&&(n=this.length),t.length-e<n-r&&(n=t.length-e+r);var o=n-r;return this===t&&"function"==typeof Uint8Array.prototype.copyWithin?this.copyWithin(e,r,n):Uint8Array.prototype.set.call(t,this.subarray(r,n),e),o},u.prototype.fill=function(t,e,r,n){if("string"==typeof t){if("string"==typeof e?(n=e,e=0,r=this.length):"string"==typeof r&&(n=r,r=this.length),void 0!==n&&"string"!=typeof n)throw new TypeError("encoding must be a string");if("string"==typeof n&&!u.isEncoding(n))throw new TypeError("Unknown encoding: "+n);if(1===t.length){var o=t.charCodeAt(0);("utf8"===n&&o<128||"latin1"===n)&&(t=o)}}else"number"==typeof t?t&=255:"boolean"==typeof t&&(t=Number(t));if(e<0||this.length<e||this.length<r)throw new RangeError("Out of range index");if(r<=e)return this;var i;if(e>>>=0,r=void 0===r?this.length:r>>>0,t||(t=0),"number"==typeof t)for(i=e;i<r;++i)this[i]=t;else{var a=u.isBuffer(t)?t:u.from(t,n),s=a.length;if(0===s)throw new TypeError('The value "'+t+'" is invalid for argument "value"');for(i=0;i<r-e;++i)this[i+e]=a[i%s]}return this};var P=/[^+/0-9A-Za-z-_]/g;function D(t,e){var r;e=e||1/0;for(var n=t.length,o=null,i=[],a=0;a<n;++a){if((r=t.charCodeAt(a))>55295&&r<57344){if(!o){if(r>56319){(e-=3)>-1&&i.push(239,191,189);continue}if(a+1===n){(e-=3)>-1&&i.push(239,191,189);continue}o=r;continue}if(r<56320){(e-=3)>-1&&i.push(239,191,189),o=r;continue}r=65536+(o-55296<<10|r-56320)}else o&&(e-=3)>-1&&i.push(239,191,189);if(o=null,r<128){if((e-=1)<0)break;i.push(r)}else if(r<2048){if((e-=2)<0)break;i.push(r>>6|192,63&r|128)}else if(r<65536){if((e-=3)<0)break;i.push(r>>12|224,r>>6&63|128,63&r|128)}else{if(!(r<1114112))throw new Error("Invalid code point");if((e-=4)<0)break;i.push(r>>18|240,r>>12&63|128,r>>6&63|128,63&r|128)}}return i}function j(t){return n.toByteArray(function(t){if((t=(t=t.split("=")[0]).trim().replace(P,"")).length<2)return"";for(;t.length%4!=0;)t+="=";return t}(t))}function $(t,e,r,n){for(var o=0;o<n&&!(o+r>=e.length||o>=t.length);++o)e[o+r]=t[o];return o}function Y(t,e){return t instanceof e||null!=t&&null!=t.constructor&&null!=t.constructor.name&&t.constructor.name===e.name}function z(t){return t!=t}var H=function(){for(var t="0123456789abcdef",e=new Array(256),r=0;r<16;++r)for(var n=16*r,o=0;o<16;++o)e[n+o]=t[r]+t[o];return e}()}};const e={};function r(n){const o=e[n];if(void 0!==o)return o.exports;const i=e[n]={exports:{}};return t[n](i,i.exports,r),i.exports}r.d=(t,e)=>{if(Array.isArray(e))for(var n=0;n<e.length;){var o=e[n++],i=e[n++];r.o(t,o)?0===i&&n++:0===i?Object.defineProperty(t,o,{enumerable:!0,value:e[n++]}):Object.defineProperty(t,o,{enumerable:!0,get:i})}else for(var o in e)r.o(e,o)&&!r.o(t,o)&&Object.defineProperty(t,o,{enumerable:!0,get:e[o]})},r.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e),r.r=t=>{Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})};let n={};(()=>{"use strict";function t(t){let e,r=t.length;for(;0!==r;)e=Math.floor(Math.random()*r),r--,[t[r],t[e]]=[t[e],t[r]];return t}function e(t,e){const r=t.filter(t=>!e.includes(t));return{added:e.filter(e=>!t.includes(e)),removed:r}}function o(t,e=!1){return e?function(e,r){return e[t]>r[t]?-1:e[t]<r[t]?1:0}:function(e,r){return e[t]<r[t]?-1:e[t]>r[t]?1:0}}function i(t=new Date,e="asSeconds",r=null){if(t instanceof Date){const n=r instanceof Date?r:new Date,o=t.getTime()-n.getTime();switch(e){case"asMilliseconds":return o;case"asSeconds":default:return o/1e3;case"asMinutes":return o/6e4;case"asHours":return o/36e5;case"asDays":return o/864e5}}return null}function a(t,e="seconds",r="{time}"){t=Math.max(0,Math.floor(t));const n=["seconds","minutes","hours","days","months","years"].indexOf(e),o=n>=5,i=n>=4,a=n>=3,s=n>=2,u=n>=1,f=n>=0,l={years:o?0:NaN,months:i?0:NaN,days:a?0:NaN,hours:s?0:NaN,minutes:u?0:NaN,seconds:f?0:NaN,total:NaN};let c=t;if(o||i||a){const t=new Date(1980,0,1),e=new Date(t.getTime()+1e3*c),r=new Date(t);if(o)for(;new Date(r.getFullYear()+1,r.getMonth(),r.getDate()).getTime()<=e.getTime();)r.setFullYear(r.getFullYear()+1),l.years++;if(i)for(;new Date(r.getFullYear(),r.getMonth()+1,r.getDate()).getTime()<=e.getTime();)r.setMonth(r.getMonth()+1),l.months++;if(a)for(;new Date(r.getFullYear(),r.getMonth(),r.getDate()+1).getTime()<=e.getTime();)r.setDate(r.getDate()+1),l.days++;c=Math.floor((e.getTime()-r.getTime())/1e3)}s&&(l.hours=Math.floor(c/3600),c%=3600),u&&(l.minutes=Math.floor(c/60),c%=60),f&&(l.seconds=c),i&&(l.years,l.months,l.days),o&&(l.years,l.months,l.days),l.total=+t.toFixed(2).replace(/\.00$/,"");const h=t=>{const e="string"==typeof t?parseInt(t):t;return Number.isNaN(e)?"NaN":String(e).padStart(2,"0")},p=[s?h(l.hours):null,u?h(l.minutes):null,f?h(l.seconds):null].filter(t=>null!==t).join(":");return r.replace(/\{years\}/g,String(l.years)).replace(/\{months\}/g,String(l.months)).replace(/\{days\}/g,String(l.days)).replace(/\{hours\}/g,h(l.hours)).replace(/\{minutes\}/g,h(l.minutes)).replace(/\{seconds\}/g,h(l.seconds)).replace(/\{time\}/g,p).replace(/\{total\}/g,String(l.total)).trim()}function s(t){return a(t,"hours","{hours}:{minutes}:{seconds}")}function u(t){return a(t,"days","{days}d {hours}:{minutes}:{seconds}")}function f(t,e="milliseconds"){t=Math.max(0,Math.floor(t));const r=["milliseconds","seconds","minutes","hours","days","months","years"].indexOf(e),n=r>=6,o=r>=5,i=r>=4,a=r>=3,s=r>=2,u=r>=1,f=r>=0,l={years:n?0:NaN,months:o?0:NaN,days:i?0:NaN,hours:a?0:NaN,minutes:s?0:NaN,seconds:u?0:NaN,milliseconds:f?0:NaN,total:NaN};let c=t;if(n||o||i){const t=new Date(1980,0,1),e=new Date(t.getTime()+c),r=new Date(t);if(n)for(;new Date(r.getFullYear()+1,r.getMonth(),r.getDate()).getTime()<=e.getTime();)r.setFullYear(r.getFullYear()+1),l.years++;if(o)for(;new Date(r.getFullYear(),r.getMonth()+1,r.getDate()).getTime()<=e.getTime();)r.setMonth(r.getMonth()+1),l.months++;if(i)for(;new Date(r.getFullYear(),r.getMonth(),r.getDate()+1).getTime()<=e.getTime();)r.setDate(r.getDate()+1),l.days++;c=e.getTime()-r.getTime()}return a&&(l.hours=Math.floor(c/36e5),c%=36e5),s&&(l.minutes=Math.floor(c/6e4),c%=6e4),u&&(l.seconds=Math.floor(c/1e3),c%=1e3),f&&(l.milliseconds=c),o&&(l.years,l.months,l.days),n&&(l.years,l.months,l.days),l.total=+t,l}function l(t){return Array.isArray(t)?t.length:c(t)?Object.keys(t).length:0}function c(t){return null!==t&&"object"==typeof t&&!Array.isArray(t)&&"[object Object]"===Object.prototype.toString.call(t)}function h(t,e){return new Promise((r,n)=>{const o=new FileReader;o.onload=()=>{try{r(o.result)}catch(t){n(t)}},o.onerror=()=>{n(o.error)},o[e](t)})}function p(t,e=!1){return new Promise((r,n)=>{"string"!=typeof e&&"boolean"!=typeof e&&n(new TypeError("The isDataUrl parameter must be a boolean or a string.")),h(t,"readAsDataURL").then(t=>{if("string"!=typeof t)throw new TypeError("Expected file content to be a string.");const n=t.match(/^data:(.+);base64,(.*)$/);if(!n||!n[2])throw new Error("Invalid data URL format or missing Base64 content.");const[,o,i]=n;if(!/^[\w/+]+=*$/.test(i))throw new Error("Base64 content is malformed.");if("boolean"==typeof e)return r(e?t:i);if(!/^[\w-]+\/[\w.+-]+$/.test(e))throw new Error(`Invalid MIME type string: ${e}`);return r(`data:${e};base64,${i}`)}).catch(n)})}function d(t){return new Promise((e,r)=>h(t,"readAsText").then(t=>{if("string"!=typeof t)throw new TypeError("Expected file content to be a string.");const r=t.trim();if(0===r.length)throw new Error("File is empty or contains only whitespace.");const n=JSON.parse(r);if("object"!=typeof n||null===n)throw new Error("Parsed content is not a valid JSON object or array.");e(n)}).catch(r))}function y(t,e,r=2){const n=JSON.stringify(e,null,r),o=new Blob([n],{type:"application/json"}),i=URL.createObjectURL(o),a=document.createElement("a");a.href=i,a.download=t,document.body.appendChild(a),a.click(),document.body.removeChild(a),URL.revokeObjectURL(i)}function g(t,e){if("function"!=typeof e)throw new TypeError('The "onProgress" argument must be a function.');if(!t.body)return t;const r=t.headers.get("content-length"),n=r?parseInt(r,10):0;let o=0;const i=t.body.getReader(),a=new ReadableStream({async start(t){for(;;){const{done:r,value:a}=await i.read();if(r)break;o+=a.byteLength,e(o,n),t.enqueue(a)}t.close()}});return new Response(a,{headers:t.headers,status:t.status,statusText:t.statusText})}async function m(t,{method:e="GET",body:r,timeout:n=0,retries:o=0,headers:i={},signal:a=null,onProgress:s}={}){if("string"!=typeof t||!t.startsWith("../")&&!t.startsWith("./")&&!t.startsWith("/")&&!t.startsWith("https://")&&!t.startsWith("http://"))throw new Error("Invalid URL: must be a valid http or https address.");if("string"!=typeof e||!e.trim())throw new Error("Invalid method: must be a non-empty string.");if(!a){if("number"!=typeof n||!Number.isFinite(n)||Number.isNaN(n)||n<0)throw new Error("Invalid timeout: must be a positive number.");if("number"!=typeof o||!Number.isFinite(o)||Number.isNaN(o)||o<0)throw new Error("Invalid retries: must be a positive number.")}const u=a?1:o+1;let f=null;for(let l=0;l<u;l++){const u=a?null:new AbortController,h=a||(u?.signal??null),p=!a&&n&&u?setTimeout(()=>u.abort(),n):null;try{const n=await fetch(t,{method:e.toUpperCase(),headers:{Accept:"application/json",...i},body:void 0!==r?c(r)?JSON.stringify(r):r:void 0,signal:h});if(p&&clearTimeout(p),!n.ok)throw new Error(`HTTP error: ${n.status} ${n.statusText}`);return s?g(n,s):n}catch(t){if(f=t,a)break;l<o&&await new Promise(t=>setTimeout(t,300*(l+1)))}}throw new Error(`Failed to fetch JSON from "${t}"${f?`: ${f.message}`:"."}`)}async function w(t,e){return new Promise((r,n)=>{m(t,e).then(async t=>{const e=t.headers.get("content-type")||"";if(!e.includes("application/json"))throw new Error(`Unexpected content-type: ${e}`);const n=await t.json();if(!Array.isArray(n)&&!c(n))throw new Error("Received invalid data instead of valid JSON.");return r(n)}).catch(n)})}async function b(t,e,r){return new Promise((n,o)=>{m(t,r).then(async t=>{const r=t.headers.get("content-type")||"";if(Array.isArray(e)&&e.length>0&&!e.some(t=>r.includes(t)))throw new Error(`Blocked MIME type: ${r}`);const o=await t.text();return n(o)}).catch(o)})}function v({element:t=document.body,hiddenClass:e="windowHidden",visibleClass:r="windowVisible",onVisible:n,onHidden:o}={}){if(!(t instanceof Element))throw new TypeError('"element" must be an instance of Element.');if("string"!=typeof e)throw new TypeError('"hiddenClass" must be a string.');if("string"!=typeof r)throw new TypeError('"visibleClass" must be a string.');if(void 0!==n&&"function"!=typeof n)throw new TypeError('"onVisible" must be a function if provided.');if(void 0!==o&&"function"!=typeof o)throw new TypeError('"onHidden" must be a function if provided.');let i="",a="";const s=()=>{t.classList.remove(e),t.classList.remove(r)};let u=null;const f=["visibilitychange","mozvisibilitychange","webkitvisibilitychange","msvisibilitychange"],l=["hidden","mozHidden","webkitHidden","msHidden"];for(let t=0;t<l.length;t++)if(l[t]in document){u=l[t];break}const c=function(f){s();const l=f?.type,c=u&&document[u];["focus","focusin","pageshow"].includes(l)?(t.classList.add(r),n?.({type:l,oldClass:a,oldType:i}),a=r):["blur","focusout","pagehide"].includes(l)||c?(t.classList.add(e),o?.({type:l,oldClass:a,oldType:i}),a=e):(t.classList.add(r),n?.({type:l,oldClass:a,oldType:i}),a=r),i=l};let h=()=>{};if(u){const t=f[l.indexOf(u)];document.addEventListener(t,c),window.addEventListener("focus",c),window.addEventListener("blur",c),h=()=>{document.removeEventListener(t,c),window.removeEventListener("focus",c),window.removeEventListener("blur",c),s()}}else"onfocusin"in document?(document.onfocusin=document.onfocusout=c,h=()=>{document.onfocusin=document.onfocusout=null,s()}):(window.onpageshow=window.onpagehide=window.onfocus=window.onblur=c,h=()=>{window.onpageshow=window.onpagehide=window.onfocus=window.onblur=null,s()});const p=new Event(u&&document[u]?"blur":"focus");return c(p),h}r.r(n),r.d(n,{addAiMarkerShortcut:()=>X,areElsCollBottom:()=>K,areElsCollLeft:()=>Q,areElsCollPerfBottom:()=>rt,areElsCollPerfLeft:()=>nt,areElsCollPerfRight:()=>ot,areElsCollPerfTop:()=>et,areElsCollRight:()=>tt,areElsCollTop:()=>Z,areElsColliding:()=>it,areElsPerfColliding:()=>at,arraySortPositions:()=>o,asyncReplace:()=>W,breakdownDuration:()=>f,calculateMarketcap:()=>H,cloneObjTypeOrder:()=>N,compareMarketcap:()=>q,countObj:()=>l,diffArrayList:()=>e,diffStrings:()=>V,documentIsFullScreen:()=>S,exitFullScreen:()=>k,extendObjType:()=>B,extractMediaId3Tags:()=>Tt,fetchJson:()=>w,fetchText:()=>b,formatBytes:()=>Y,formatCustomTimer:()=>a,formatDayTimer:()=>u,formatTimer:()=>s,genFibonacciSeq:()=>z,getAge:()=>$,getElsCollDetails:()=>dt,getElsCollDirDepth:()=>pt,getElsCollOverlap:()=>ft,getElsCollOverlapPos:()=>lt,getElsColliding:()=>st,getElsPerfColliding:()=>ut,getElsRelativeCenterOffset:()=>ht,getPercentage:()=>j,getRectCenter:()=>ct,getSimplePerc:()=>D,getTimeDuration:()=>i,installWindowHiddenScript:()=>v,isFullScreenMode:()=>C,isJsonObject:()=>c,isScreenFilled:()=>U,objType:()=>I,offFullScreenChange:()=>F,onFullScreenChange:()=>R,parseMediaMetadata:()=>At,readBase64Blob:()=>p,readFileBlob:()=>h,readJsonBlob:()=>d,reorderObjTypeOrder:()=>M,requestFullScreen:()=>O,ruleOfThree:()=>P,safeTextTrim:()=>G,saveJsonFile:()=>y,shuffleArray:()=>t,toTitleCase:()=>_,toTitleCaseLowerFirst:()=>J,valMediaContentMetadata:()=>vt,valMediaContentMetadataPartial:()=>Et});var E=r(271);const T="undefined"!=typeof window&&void 0!==window.document,A={items:{},order:[]};function B(t,e){const r=[],n=Array.isArray(t)?t:Object.entries(t);for(const[t,o]of n)if(!A.items.hasOwnProperty(t)){A.items[t]=o;let n="number"==typeof e?e:-1;if(-1===n){const t=A.order.indexOf("object");n=t>-1?t:A.order.length}n=Math.min(Math.max(0,n),A.order.length),A.order.splice(n,0,t),r.push(t)}return r}function M(t){const e=[...A.order];return!!t.every(t=>e.includes(t))&&(A.order=t.slice(),!0)}function N(){return[...A.order]}const L=t=>{if(null===t)return"null";for(const e of A.order)if("function"!=typeof A.items[e]||A.items[e](t))return e;return"unknown"};function I(t,e){if(void 0===t)return null;const r=L(t);return"string"==typeof e?r===e.toLowerCase():r}B([["undefined",t=>void 0===t],["null",t=>null===t],["boolean",t=>"boolean"==typeof t],["number",t=>"number"==typeof t&&!Number.isNaN(t)],["bigint",t=>"bigint"==typeof t],["string",t=>"string"==typeof t],["symbol",t=>"symbol"==typeof t],["function",t=>"function"==typeof t],["array",t=>Array.isArray(t)]]),T||B([["buffer",t=>void 0!==E.hp&&E.hp.isBuffer(t)]]),T&&B([["file",t=>"undefined"!=typeof File&&t instanceof File]]),B([["date",t=>t instanceof Date],["regexp",t=>t instanceof RegExp],["map",t=>t instanceof Map],["set",t=>t instanceof Set],["weakmap",t=>t instanceof WeakMap],["weakset",t=>t instanceof WeakSet],["promise",t=>t instanceof Promise]]),T&&B([["htmlelement",t=>"undefined"!=typeof HTMLElement&&t instanceof HTMLElement]]),B([["object",t=>c(t)]]);const S=()=>!!(document.fullscreenElement||document.webkitFullscreenElement||document.mozFullScreenElement||document.msFullscreenElement||document.webkitIsFullScreen||document.mozFullScreen),U=()=>window.innerHeight===screen.height&&window.innerWidth===screen.width,C=()=>S()||U(),O=t=>new Promise(async(e,r)=>{const n=document.documentElement;try{n.requestFullscreen?await n.requestFullscreen(t):n.mozRequestFullScreen?n.mozRequestFullScreen(t):n.webkitRequestFullScreen?n.webkitRequestFullScreen(t):n.msRequestFullscreen&&n.msRequestFullscreen(t),e()}catch(t){r(t)}}),k=()=>new Promise((t,e)=>{if(document.exitFullscreen)document.exitFullscreen().then(t).catch(e);else try{if(document.mozCancelFullScreen)document.mozCancelFullScreen();else if(document.webkitCancelFullScreen)document.webkitCancelFullScreen();else{if(!document.msExitFullscreen)throw new Error("Fullscreen API is not supported");document.msExitFullscreen()}t()}catch(t){e(t)}}),x=["fullscreenchange","webkitfullscreenchange","mozfullscreenchange","MSFullscreenChange"],R=(t,e)=>{x.forEach(r=>{document.addEventListener(r,t,e)})},F=(t,e)=>{x.forEach(r=>{document.removeEventListener(r,t,e)})};function P(t,e,r,n=!1){return n?Number(t*e)/r:Number(r*e)/t}function D(t,e){return t*(e/100)}function j(t,e){return 0===e?0:t/e*100}function $(t=0,e=null){if(null!=t&&0!==t){const r=new Date(t);if(Number.isNaN(r.getTime()))return null;const n=e instanceof Date?e:new Date;let o=n.getFullYear()-r.getFullYear();const i=n.getMonth(),a=r.getMonth(),s=n.getDate(),u=r.getDate();return(i<a||i===a&&s<u)&&o--,Math.abs(o)}return null}function Y(t,e=null,r=null){if("number"!=typeof t||t<0)return{unit:null,value:null};if(0===t)return{unit:"Bytes",value:0};const n=["Bytes","KB","MB","GB","TB","PB","EB","ZB","YB"],o=r&&n.includes(r)?n.indexOf(r):n.length-1,i=Math.min(Math.floor(Math.log(t)/Math.log(1024)),o);let a=t/Math.pow(1024,i);if(null!==e){const t=e<0?0:e;a=parseFloat(a.toFixed(t))}return{unit:n[i],value:a}}function z({baseValues:t=[0,1],length:e=10,combiner:r=(t,e)=>t+e}={}){if(!Array.isArray(t)||2!==t.length)throw new Error("baseValues must be an array of exactly two numbers");const n=[...t.slice(0,2)];for(let t=2;t<e;t++){const e=r(n[t-2],n[t-1],t);n.push(e)}return n}function H(t,e){if(Number.isNaN(t)||!Number.isFinite(t))throw new TypeError("Original market cap must be a number.");if(Number.isNaN(e)||!Number.isFinite(e))throw new TypeError("Circulating supply must be a number.");if(e<=0)throw new Error("Circulating supply must be greater than zero.");return t/e}function q(t,e,r){if(Number.isNaN(r)||!Number.isFinite(r))throw new TypeError("New market cap must be a number.");const n=H(t,e),o="number"==typeof r?r/e:NaN;return{originalPrice:n,newPrice:o,priceChangePercent:"number"==typeof r?(o-n)/n*100:NaN}}async function W(t,e,r){const n=[];t.replace(e,(t,...e)=>(n.push(r(t,...e)),t));const o=await Promise.all(n);return t.replace(e,()=>o.shift())}function _(t){return t.replace(/\w\S*/g,t=>t.charAt(0).toUpperCase()+t.substr(1).toLowerCase())}function J(t){const e=t.replace(/\w\S*/g,t=>t.charAt(0).toUpperCase()+t.substr(1).toLowerCase());return e.charAt(0).toLowerCase()+e.slice(1)}function X({key:t="a",className:e="detect-made-by-ai"}={}){if("undefined"==typeof HTMLElement)throw new Error("[AiMarkerShortcut] Environment does not support the DOM. This function must be run in a browser.");const r=function(r){if(r.ctrlKey&&r.altKey&&r.key.toLowerCase()===t){if(r.preventDefault(),!document.body)return void console.warn("[AiMarkerShortcut] <body> element not found. Cannot toggle class. Ensure the DOM is fully loaded when using the shortcut.");document.body.classList.toggle(e)}};return document.addEventListener("keydown",r),r}function G(t,e,r=.6){if("string"!=typeof t)throw new TypeError("Expected a string for 'text', but received "+typeof t);if(!Number.isInteger(e)||e<=0)throw new TypeError(`Expected 'limit' to be a positive integer, but received ${e}`);if("number"!=typeof r||r<0||r>1)throw new TypeError(`Expected 'safeCutZone' to be a number between 0 and 1, but received ${r}`);let n=t.trim();if(n.length>e){const t=n.lastIndexOf(" ",e);return t>0&&t>=e*r?`${n.substring(0,t).trim()}...`:`${n.substring(0,e).trim()}...`}return n}function V(t,e){const r={added:{},removed:{},modified:{}};for(const n in t)n in e?t[n]!==e[n]&&(r.modified[n]={old:t[n],new:e[n]}):r.removed[n]=t[n];for(const n in e)n in t||(r.added[n]=e[n]);return r}const Z=(t,e)=>t.bottom<e.top,K=(t,e)=>t.top>e.bottom,Q=(t,e)=>t.right<e.left,tt=(t,e)=>t.left>e.right,et=(t,e)=>t.bottom<=e.top,rt=(t,e)=>t.top>=e.bottom,nt=(t,e)=>t.right<=e.left,ot=(t,e)=>t.left>=e.right,it=(t,e)=>!(Q(t,e)||tt(t,e)||Z(t,e)||K(t,e)),at=(t,e)=>!(nt(t,e)||ot(t,e)||et(t,e)||rt(t,e)),st=(t,e)=>Q(t,e)?"left":tt(t,e)?"right":Z(t,e)?"top":K(t,e)?"bottom":null,ut=(t,e)=>nt(t,e)?"left":ot(t,e)?"right":et(t,e)?"top":rt(t,e)?"bottom":null,ft=(t,e)=>({overlapLeft:e.right-t.left,overlapRight:t.right-e.left,overlapTop:e.bottom-t.top,overlapBottom:t.bottom-e.top}),lt=({overlapLeft:t=-1,overlapRight:e=-1,overlapTop:r=-1,overlapBottom:n=-1}={})=>({dirX:t<e?"right":"left",dirY:r<n?"bottom":"top"}),ct=t=>({x:t.left+t.width/2,y:t.top+t.height/2});function ht(t,e){const r=t.left+t.width/2,n=t.top+t.height/2;return{x:e.left+e.width/2-r,y:e.top+e.height/2-n}}function pt(t,e){if(!at(t,e))return{inDir:null,dirX:null,dirY:null,depthX:0,depthY:0};const{overlapLeft:r,overlapRight:n,overlapTop:o,overlapBottom:i}=ft(t,e),{dirX:a,dirY:s}=lt({overlapLeft:r,overlapRight:n,overlapTop:o,overlapBottom:i}),u=Math.min(r,n),f=Math.min(o,i);let l;return l=u<f?a:s,{inDir:l,dirX:a,dirY:s,depthX:u,depthY:f}}function dt(t,e){const r=at(t,e),n={in:null,x:null,y:null},o={y:null,x:null},i={top:0,bottom:0,left:0,right:0},{overlapLeft:a,overlapRight:s,overlapTop:u,overlapBottom:f}=ft(e,t);i.top=u,i.bottom=f,i.left=a,i.right=s;const l=Object.entries(i).filter(([,t])=>t>0).sort((t,e)=>t[1]-e[1]),{dirX:c,dirY:h}=lt({overlapLeft:s,overlapRight:a,overlapTop:f,overlapBottom:u});return n.y=h,n.x=c,i.bottom<0?o.y="bottom":i.top<0&&(o.y="top"),i.left<0?o.x="left":i.right<0&&(o.x="right"),n.in=r?i.top===i.bottom&&i.bottom===i.left&&i.left===i.right?"center":l.length?l[0][0]:"top":null,{dirs:n,depth:i,isNeg:o}}const yt=new Map;class gt extends Error{constructor(t,e,r){super(t),this.name="MediaLoadingError",this.url=e,this.stage=r}}const mt=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)},wt=(t,e="image/jpeg")=>{const r=t=>{const e=URL.createObjectURL(t),r=yt.get(e);return yt.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],o=atob(n),i=new Uint8Array(o.length);for(let t=0;t<o.length;t++)i[t]=o.charCodeAt(t);return r(new Blob([i],{type:e}))}return"string"==typeof t?t:""},bt=(t,e)=>{const r=t=>e&&void 0===t,n=t=>r(t)||"string"==typeof t||null===t,o=(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(i=t.year,!r(i)&&"number"!=typeof i&&null!==i)throw new TypeError('Invalid metadata: "year" must be a number or null.');var i;if(!o(t.albumartists,t=>"string"==typeof t))throw new TypeError('Invalid metadata: "albumartists" must be an array of string.');if(!o(t.genre,t=>"string"==typeof t))throw new TypeError('Invalid metadata: "genre" must be an array of string.');if(!o(t.label,t=>"string"==typeof t))throw new TypeError('Invalid metadata: "label" must be an array of string.');if(!o(t.composer,t=>"string"==typeof t))throw new TypeError('Invalid metadata: "composer" must be an array of string.');if(!o(t.artists,t=>"string"==typeof t))throw new TypeError('Invalid metadata: "artists" must be an array of string.');if(!o(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 a=(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.`)}};a(t.disk,"disk"),a(t.track,"track")},vt=t=>bt(t,!1),Et=t=>bt(t,!0),Tt=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(),o=await e(n);if(!o||"object"!=typeof o.common)throw new TypeError('Invalid metadata: "common" property is missing or not an object.');const i=o.common;return Et(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(t=>({...t,data:wt(t.data,t.format)}))??[]}}catch(t){throw t}},At=async(t,e={},r={},n=t=>new Promise((t,e)=>e(new TypeError("parseFile library not found."))),o={},i="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 a,s="";const u=(e,r)=>{o.onProgress&&o.onProgress({event:r,status:"loading",stage:e,url:s||(t instanceof HTMLMediaElement?t.src:"unknown")})},f=(e,r)=>{o.onError&&o.onError({error:e,url:s||(t instanceof HTMLMediaElement?t.src:"unknown"),stage:r})};try{u("INITIALIZING"),"string"==typeof t?(s=t,a=new Audio(s)):(a=t,s=a.src);try{await new Promise((t,e)=>{const r=t=>u("DOWNLOADING",t),n=()=>{i(),t(void 0)},o=t=>{i(),e(new Error(`HTMLMediaElement failed to load: ${t.message||"Unknown error"}`))},i=()=>{a.removeEventListener("progress",r),a.removeEventListener("loadedmetadata",n),a.removeEventListener("error",o)};a.addEventListener("progress",r),a.addEventListener("loadedmetadata",n),a.addEventListener("error",o),a.readyState>=1&&(i(),t(void 0))}),u("METADATA_LOADED")}catch(t){throw new gt(t instanceof Error?t.message:"UNKNOWN ERROR",s,"METADATA")}const l={id:r.id||await mt(s),duration:Math.floor(1e3*a.duration),url:s,weight:r.weight??1};let c={};u("EXTRACTING_ID3");try{c=await Tt(s,n)}catch(t){f(t instanceof Error?t:new Error("Unknown Error"),"ID3"),console.warn(`[TinyAudioUtils] ID3 extraction failed for ${s}. Falling back to filename.`)}const h=t=>{try{return(t.split(/[?#]/)[0].split("/").pop()??"").replace(/\.[^/.]+$/,"")||"Unknown Track"}catch{return"Unknown Track"}},p={...l,...e,...c,...r,title:c.title||r.title||h(s),artist:c.artist||r.artist||("string"==typeof i?i:String(i()))};return o.onProgress&&o.onProgress({status:"success",stage:"COMPLETE",url:s}),p}catch(t){if(t instanceof gt)throw t;{const e=new gt(t instanceof Error?t.message:"UNKNOWN ERROR",s,"INITIALIZING");throw f(e,"INITIALIZING"),e}}}})(),window.TinyBasicsEs=n})();
1
+ (()=>{"use strict";const e={d:(t,r)=>{if(Array.isArray(r))for(var n=0;n<r.length;){var o=r[n++],i=r[n++];e.o(t,o)?0===i&&n++:0===i?Object.defineProperty(t,o,{enumerable:!0,value:r[n++]}):Object.defineProperty(t,o,{enumerable:!0,get:i})}else for(var o in r)e.o(r,o)&&!e.o(t,o)&&Object.defineProperty(t,o,{enumerable:!0,get:r[o]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r:e=>{Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})}};let t={};function r(e){let t,r=e.length;for(;0!==r;)t=Math.floor(Math.random()*r),r--,[e[r],e[t]]=[e[t],e[r]];return e}function n(e,t){const r=e.filter(e=>!t.includes(e));return{added:t.filter(t=>!e.includes(t)),removed:r}}function o(e,t=!1){return t?function(t,r){return t[e]>r[e]?-1:t[e]<r[e]?1:0}:function(t,r){return t[e]<r[e]?-1:t[e]>r[e]?1:0}}function i(e=new Date,t="asSeconds",r=null){if(e instanceof Date){const n=r instanceof Date?r:new Date,o=e.getTime()-n.getTime();switch(t){case"asMilliseconds":return o;case"asSeconds":default:return o/1e3;case"asMinutes":return o/6e4;case"asHours":return o/36e5;case"asDays":return o/864e5}}return null}function a(e,t="seconds",r="{time}"){e=Math.max(0,Math.floor(e));const n=["seconds","minutes","hours","days","months","years"].indexOf(t),o=n>=5,i=n>=4,a=n>=3,s=n>=2,l=n>=1,u=n>=0,c={years:o?0:NaN,months:i?0:NaN,days:a?0:NaN,hours:s?0:NaN,minutes:l?0:NaN,seconds:u?0:NaN,total:NaN};let d=e;if(o||i||a){const e=new Date(1980,0,1),t=new Date(e.getTime()+1e3*d),r=new Date(e);if(o)for(;new Date(r.getFullYear()+1,r.getMonth(),r.getDate()).getTime()<=t.getTime();)r.setFullYear(r.getFullYear()+1),c.years++;if(i)for(;new Date(r.getFullYear(),r.getMonth()+1,r.getDate()).getTime()<=t.getTime();)r.setMonth(r.getMonth()+1),c.months++;if(a)for(;new Date(r.getFullYear(),r.getMonth(),r.getDate()+1).getTime()<=t.getTime();)r.setDate(r.getDate()+1),c.days++;d=Math.floor((t.getTime()-r.getTime())/1e3)}s&&(c.hours=Math.floor(d/3600),d%=3600),l&&(c.minutes=Math.floor(d/60),d%=60),u&&(c.seconds=d),i&&(c.years,c.months,c.days),o&&(c.years,c.months,c.days),c.total=+e.toFixed(2).replace(/\.00$/,"");const f=e=>{const t="string"==typeof e?parseInt(e):e;return Number.isNaN(t)?"NaN":String(t).padStart(2,"0")},m=[s?f(c.hours):null,l?f(c.minutes):null,u?f(c.seconds):null].filter(e=>null!==e).join(":");return r.replace(/\{years\}/g,String(c.years)).replace(/\{months\}/g,String(c.months)).replace(/\{days\}/g,String(c.days)).replace(/\{hours\}/g,f(c.hours)).replace(/\{minutes\}/g,f(c.minutes)).replace(/\{seconds\}/g,f(c.seconds)).replace(/\{time\}/g,m).replace(/\{total\}/g,String(c.total)).trim()}function s(e){return a(e,"hours","{hours}:{minutes}:{seconds}")}function l(e){return a(e,"days","{days}d {hours}:{minutes}:{seconds}")}function u(e,t="milliseconds"){e=Math.max(0,Math.floor(e));const r=["milliseconds","seconds","minutes","hours","days","months","years"].indexOf(t),n=r>=6,o=r>=5,i=r>=4,a=r>=3,s=r>=2,l=r>=1,u=r>=0,c={years:n?0:NaN,months:o?0:NaN,days:i?0:NaN,hours:a?0:NaN,minutes:s?0:NaN,seconds:l?0:NaN,milliseconds:u?0:NaN,total:NaN};let d=e;if(n||o||i){const e=new Date(1980,0,1),t=new Date(e.getTime()+d),r=new Date(e);if(n)for(;new Date(r.getFullYear()+1,r.getMonth(),r.getDate()).getTime()<=t.getTime();)r.setFullYear(r.getFullYear()+1),c.years++;if(o)for(;new Date(r.getFullYear(),r.getMonth()+1,r.getDate()).getTime()<=t.getTime();)r.setMonth(r.getMonth()+1),c.months++;if(i)for(;new Date(r.getFullYear(),r.getMonth(),r.getDate()+1).getTime()<=t.getTime();)r.setDate(r.getDate()+1),c.days++;d=t.getTime()-r.getTime()}return a&&(c.hours=Math.floor(d/36e5),d%=36e5),s&&(c.minutes=Math.floor(d/6e4),d%=6e4),l&&(c.seconds=Math.floor(d/1e3),d%=1e3),u&&(c.milliseconds=d),o&&(c.years,c.months,c.days),n&&(c.years,c.months,c.days),c.total=+e,c}function c(e){return Array.isArray(e)?e.length:d(e)?Object.keys(e).length:0}function d(e){return null!==e&&"object"==typeof e&&!Array.isArray(e)&&"[object Object]"===Object.prototype.toString.call(e)}function f(e,t){return new Promise((r,n)=>{const o=new FileReader;o.onload=()=>{try{r(o.result)}catch(e){n(e)}},o.onerror=()=>{n(o.error)},o[t](e)})}function m(e,t=!1){return new Promise((r,n)=>{"string"!=typeof t&&"boolean"!=typeof t&&n(new TypeError("The isDataUrl parameter must be a boolean or a string.")),f(e,"readAsDataURL").then(e=>{if("string"!=typeof e)throw new TypeError("Expected file content to be a string.");const n=e.match(/^data:(.+);base64,(.*)$/);if(!n||!n[2])throw new Error("Invalid data URL format or missing Base64 content.");const[,o,i]=n;if(!/^[\w/+]+=*$/.test(i))throw new Error("Base64 content is malformed.");if("boolean"==typeof t)return r(t?e:i);if(!/^[\w-]+\/[\w.+-]+$/.test(t))throw new Error(`Invalid MIME type string: ${t}`);return r(`data:${t};base64,${i}`)}).catch(n)})}function p(e){return new Promise((t,r)=>f(e,"readAsText").then(e=>{if("string"!=typeof e)throw new TypeError("Expected file content to be a string.");const r=e.trim();if(0===r.length)throw new Error("File is empty or contains only whitespace.");const n=JSON.parse(r);if("object"!=typeof n||null===n)throw new Error("Parsed content is not a valid JSON object or array.");t(n)}).catch(r))}function h(e,t,r=2){const n=JSON.stringify(t,null,r),o=new Blob([n],{type:"application/json"}),i=URL.createObjectURL(o),a=document.createElement("a");a.href=i,a.download=e,document.body.appendChild(a),a.click(),document.body.removeChild(a),URL.revokeObjectURL(i)}function g(e,t){if("function"!=typeof t)throw new TypeError('The "onProgress" argument must be a function.');if(!e.body)return e;const r=e.headers.get("content-length"),n=r?parseInt(r,10):0;let o=0;const i=e.body.getReader(),a=new ReadableStream({async start(e){for(;;){const{done:r,value:a}=await i.read();if(r)break;o+=a.byteLength,t(o,n),e.enqueue(a)}e.close()}});return new Response(a,{headers:e.headers,status:e.status,statusText:e.statusText})}async function y(e,{method:t="GET",body:r,timeout:n=0,retries:o=0,headers:i={},signal:a=null,onProgress:s}={}){if("string"!=typeof e||!e.startsWith("../")&&!e.startsWith("./")&&!e.startsWith("/")&&!e.startsWith("https://")&&!e.startsWith("http://"))throw new Error("Invalid URL: must be a valid http or https address.");if("string"!=typeof t||!t.trim())throw new Error("Invalid method: must be a non-empty string.");if(!a){if("number"!=typeof n||!Number.isFinite(n)||Number.isNaN(n)||n<0)throw new Error("Invalid timeout: must be a positive number.");if("number"!=typeof o||!Number.isFinite(o)||Number.isNaN(o)||o<0)throw new Error("Invalid retries: must be a positive number.")}const l=a?1:o+1;let u=null;for(let c=0;c<l;c++){const l=a?null:new AbortController,f=a||(l?.signal??null),m=!a&&n&&l?setTimeout(()=>l.abort(),n):null;try{const n=await fetch(e,{method:t.toUpperCase(),headers:{Accept:"application/json",...i},body:void 0!==r?d(r)?JSON.stringify(r):r:void 0,signal:f});if(m&&clearTimeout(m),!n.ok)throw new Error(`HTTP error: ${n.status} ${n.statusText}`);return s?g(n,s):n}catch(e){if(u=e,a)break;c<o&&await new Promise(e=>setTimeout(e,300*(c+1)))}}throw new Error(`Failed to fetch JSON from "${e}"${u?`: ${u.message}`:"."}`)}async function w(e,t){return new Promise((r,n)=>{y(e,t).then(async e=>{const t=e.headers.get("content-type")||"";if(!t.includes("application/json"))throw new Error(`Unexpected content-type: ${t}`);const n=await e.json();if(!Array.isArray(n)&&!d(n))throw new Error("Received invalid data instead of valid JSON.");return r(n)}).catch(n)})}async function b(e,t,r){return new Promise((n,o)=>{y(e,r).then(async e=>{const r=e.headers.get("content-type")||"";if(Array.isArray(t)&&t.length>0&&!t.some(e=>r.includes(e)))throw new Error(`Blocked MIME type: ${r}`);const o=await e.text();return n(o)}).catch(o)})}function E({element:e=document.body,hiddenClass:t="windowHidden",visibleClass:r="windowVisible",onVisible:n,onHidden:o}={}){if(!(e instanceof Element))throw new TypeError('"element" must be an instance of Element.');if("string"!=typeof t)throw new TypeError('"hiddenClass" must be a string.');if("string"!=typeof r)throw new TypeError('"visibleClass" must be a string.');if(void 0!==n&&"function"!=typeof n)throw new TypeError('"onVisible" must be a function if provided.');if(void 0!==o&&"function"!=typeof o)throw new TypeError('"onHidden" must be a function if provided.');let i="",a="";const s=()=>{e.classList.remove(t),e.classList.remove(r)};let l=null;const u=["visibilitychange","mozvisibilitychange","webkitvisibilitychange","msvisibilitychange"],c=["hidden","mozHidden","webkitHidden","msHidden"];for(let e=0;e<c.length;e++)if(c[e]in document){l=c[e];break}const d=function(u){s();const c=u?.type,d=l&&document[l];["focus","focusin","pageshow"].includes(c)?(e.classList.add(r),n?.({type:c,oldClass:a,oldType:i}),a=r):["blur","focusout","pagehide"].includes(c)||d?(e.classList.add(t),o?.({type:c,oldClass:a,oldType:i}),a=t):(e.classList.add(r),n?.({type:c,oldClass:a,oldType:i}),a=r),i=c};let f=()=>{};if(l){const e=u[c.indexOf(l)];document.addEventListener(e,d),window.addEventListener("focus",d),window.addEventListener("blur",d),f=()=>{document.removeEventListener(e,d),window.removeEventListener("focus",d),window.removeEventListener("blur",d),s()}}else"onfocusin"in document?(document.onfocusin=document.onfocusout=d,f=()=>{document.onfocusin=document.onfocusout=null,s()}):(window.onpageshow=window.onpagehide=window.onfocus=window.onblur=d,f=()=>{window.onpageshow=window.onpagehide=window.onfocus=window.onblur=null,s()});const m=new Event(l&&document[l]?"blur":"focus");return d(m),f}e.r(t),e.d(t,{addAiMarkerShortcut:()=>X,areElsCollBottom:()=>Z,areElsCollLeft:()=>_,areElsCollPerfBottom:()=>te,areElsCollPerfLeft:()=>re,areElsCollPerfRight:()=>ne,areElsCollPerfTop:()=>ee,areElsCollRight:()=>Q,areElsCollTop:()=>V,areElsColliding:()=>oe,areElsPerfColliding:()=>ie,arraySortPositions:()=>o,asyncReplace:()=>q,breakdownDuration:()=>u,calculateMarketcap:()=>H,cloneObjTypeOrder:()=>F,compareMarketcap:()=>W,countObj:()=>c,diffArrayList:()=>n,diffStrings:()=>K,documentIsFullScreen:()=>S,exitFullScreen:()=>I,extendObjType:()=>N,extractMediaId3Tags:()=>ve,fetchJson:()=>w,fetchText:()=>b,formatBytes:()=>U,formatCustomTimer:()=>a,formatDayTimer:()=>l,formatTimer:()=>s,genFibonacciSeq:()=>Y,getAge:()=>$,getElsCollDetails:()=>me,getElsCollDirDepth:()=>fe,getElsCollOverlap:()=>le,getElsCollOverlapPos:()=>ue,getElsColliding:()=>ae,getElsPerfColliding:()=>se,getElsRelativeCenterOffset:()=>de,getPercentage:()=>B,getRectCenter:()=>ce,getSimplePerc:()=>j,getTimeDuration:()=>i,installWindowHiddenScript:()=>E,isFullScreenMode:()=>D,isJsonObject:()=>d,isScreenFilled:()=>C,objType:()=>k,offFullScreenChange:()=>P,onFullScreenChange:()=>x,parseMediaMetadata:()=>Te,readBase64Blob:()=>m,readFileBlob:()=>f,readJsonBlob:()=>p,reorderObjTypeOrder:()=>M,requestFullScreen:()=>A,ruleOfThree:()=>R,safeTextTrim:()=>G,saveJsonFile:()=>h,shuffleArray:()=>r,toTitleCase:()=>z,toTitleCaseLowerFirst:()=>J,valMediaContentMetadata:()=>be,valMediaContentMetadataPartial:()=>Ee});const v="undefined"!=typeof window&&void 0!==window.document,T={items:{},order:[]};function N(e,t){const r=[],n=Array.isArray(e)?e:Object.entries(e);for(const[e,o]of n)if(!T.items.hasOwnProperty(e)){T.items[e]=o;let n="number"==typeof t?t:-1;if(-1===n){const e=T.order.indexOf("object");n=e>-1?e:T.order.length}n=Math.min(Math.max(0,n),T.order.length),T.order.splice(n,0,e),r.push(e)}return r}function M(e){const t=[...T.order];return!!e.every(e=>t.includes(e))&&(T.order=e.slice(),!0)}function F(){return[...T.order]}const L=e=>{if(null===e)return"null";for(const t of T.order)if("function"!=typeof T.items[t]||T.items[t](e))return t;return"unknown"};function k(e,t){if(void 0===e)return null;const r=L(e);return"string"==typeof t?r===t.toLowerCase():r}N([["undefined",e=>void 0===e],["null",e=>null===e],["boolean",e=>"boolean"==typeof e],["number",e=>"number"==typeof e&&!Number.isNaN(e)],["bigint",e=>"bigint"==typeof e],["string",e=>"string"==typeof e],["symbol",e=>"symbol"==typeof e],["function",e=>"function"==typeof e],["array",e=>Array.isArray(e)]]),v&&N([["file",e=>"undefined"!=typeof File&&e instanceof File]]),N([["date",e=>e instanceof Date],["regexp",e=>e instanceof RegExp],["map",e=>e instanceof Map],["set",e=>e instanceof Set],["weakmap",e=>e instanceof WeakMap],["weakset",e=>e instanceof WeakSet],["promise",e=>e instanceof Promise]]),v&&N([["htmlelement",e=>"undefined"!=typeof HTMLElement&&e instanceof HTMLElement]]),N([["object",e=>d(e)]]);const S=()=>!!(document.fullscreenElement||document.webkitFullscreenElement||document.mozFullScreenElement||document.msFullscreenElement||document.webkitIsFullScreen||document.mozFullScreen),C=()=>window.innerHeight===screen.height&&window.innerWidth===screen.width,D=()=>S()||C(),A=e=>new Promise(async(t,r)=>{const n=document.documentElement;try{n.requestFullscreen?await n.requestFullscreen(e):n.mozRequestFullScreen?n.mozRequestFullScreen(e):n.webkitRequestFullScreen?n.webkitRequestFullScreen(e):n.msRequestFullscreen&&n.msRequestFullscreen(e),t()}catch(e){r(e)}}),I=()=>new Promise((e,t)=>{if(document.exitFullscreen)document.exitFullscreen().then(e).catch(t);else try{if(document.mozCancelFullScreen)document.mozCancelFullScreen();else if(document.webkitCancelFullScreen)document.webkitCancelFullScreen();else{if(!document.msExitFullscreen)throw new Error("Fullscreen API is not supported");document.msExitFullscreen()}e()}catch(e){t(e)}}),O=["fullscreenchange","webkitfullscreenchange","mozfullscreenchange","MSFullscreenChange"],x=(e,t)=>{O.forEach(r=>{document.addEventListener(r,e,t)})},P=(e,t)=>{O.forEach(r=>{document.removeEventListener(r,e,t)})};function R(e,t,r,n=!1){return n?Number(e*t)/r:Number(r*t)/e}function j(e,t){return e*(t/100)}function B(e,t){return 0===t?0:e/t*100}function $(e=0,t=null){if(null!=e&&0!==e){const r=new Date(e);if(Number.isNaN(r.getTime()))return null;const n=t instanceof Date?t:new Date;let o=n.getFullYear()-r.getFullYear();const i=n.getMonth(),a=r.getMonth(),s=n.getDate(),l=r.getDate();return(i<a||i===a&&s<l)&&o--,Math.abs(o)}return null}function U(e,t=null,r=null){if("number"!=typeof e||e<0)return{unit:null,value:null};if(0===e)return{unit:"Bytes",value:0};const n=["Bytes","KB","MB","GB","TB","PB","EB","ZB","YB"],o=r&&n.includes(r)?n.indexOf(r):n.length-1,i=Math.min(Math.floor(Math.log(e)/Math.log(1024)),o);let a=e/Math.pow(1024,i);if(null!==t){const e=t<0?0:t;a=parseFloat(a.toFixed(e))}return{unit:n[i],value:a}}function Y({baseValues:e=[0,1],length:t=10,combiner:r=(e,t)=>e+t}={}){if(!Array.isArray(e)||2!==e.length)throw new Error("baseValues must be an array of exactly two numbers");const n=[...e.slice(0,2)];for(let e=2;e<t;e++){const t=r(n[e-2],n[e-1],e);n.push(t)}return n}function H(e,t){if(Number.isNaN(e)||!Number.isFinite(e))throw new TypeError("Original market cap must be a number.");if(Number.isNaN(t)||!Number.isFinite(t))throw new TypeError("Circulating supply must be a number.");if(t<=0)throw new Error("Circulating supply must be greater than zero.");return e/t}function W(e,t,r){if(Number.isNaN(r)||!Number.isFinite(r))throw new TypeError("New market cap must be a number.");const n=H(e,t),o="number"==typeof r?r/t:NaN;return{originalPrice:n,newPrice:o,priceChangePercent:"number"==typeof r?(o-n)/n*100:NaN}}async function q(e,t,r){const n=[];e.replace(t,(e,...t)=>(n.push(r(e,...t)),e));const o=await Promise.all(n);return e.replace(t,()=>o.shift())}function z(e){return e.replace(/\w\S*/g,e=>e.charAt(0).toUpperCase()+e.substr(1).toLowerCase())}function J(e){const t=e.replace(/\w\S*/g,e=>e.charAt(0).toUpperCase()+e.substr(1).toLowerCase());return t.charAt(0).toLowerCase()+t.slice(1)}function X({key:e="a",className:t="detect-made-by-ai"}={}){if("undefined"==typeof HTMLElement)throw new Error("[AiMarkerShortcut] Environment does not support the DOM. This function must be run in a browser.");const r=function(r){if(r.ctrlKey&&r.altKey&&r.key.toLowerCase()===e){if(r.preventDefault(),!document.body)return void console.warn("[AiMarkerShortcut] <body> element not found. Cannot toggle class. Ensure the DOM is fully loaded when using the shortcut.");document.body.classList.toggle(t)}};return document.addEventListener("keydown",r),r}function G(e,t,r=.6){if("string"!=typeof e)throw new TypeError("Expected a string for 'text', but received "+typeof e);if(!Number.isInteger(t)||t<=0)throw new TypeError(`Expected 'limit' to be a positive integer, but received ${t}`);if("number"!=typeof r||r<0||r>1)throw new TypeError(`Expected 'safeCutZone' to be a number between 0 and 1, but received ${r}`);let n=e.trim();if(n.length>t){const e=n.lastIndexOf(" ",t);return e>0&&e>=t*r?`${n.substring(0,e).trim()}...`:`${n.substring(0,t).trim()}...`}return n}function K(e,t){const r={added:{},removed:{},modified:{}};for(const n in e)n in t?e[n]!==t[n]&&(r.modified[n]={old:e[n],new:t[n]}):r.removed[n]=e[n];for(const n in t)n in e||(r.added[n]=t[n]);return r}const V=(e,t)=>e.bottom<t.top,Z=(e,t)=>e.top>t.bottom,_=(e,t)=>e.right<t.left,Q=(e,t)=>e.left>t.right,ee=(e,t)=>e.bottom<=t.top,te=(e,t)=>e.top>=t.bottom,re=(e,t)=>e.right<=t.left,ne=(e,t)=>e.left>=t.right,oe=(e,t)=>!(_(e,t)||Q(e,t)||V(e,t)||Z(e,t)),ie=(e,t)=>!(re(e,t)||ne(e,t)||ee(e,t)||te(e,t)),ae=(e,t)=>_(e,t)?"left":Q(e,t)?"right":V(e,t)?"top":Z(e,t)?"bottom":null,se=(e,t)=>re(e,t)?"left":ne(e,t)?"right":ee(e,t)?"top":te(e,t)?"bottom":null,le=(e,t)=>({overlapLeft:t.right-e.left,overlapRight:e.right-t.left,overlapTop:t.bottom-e.top,overlapBottom:e.bottom-t.top}),ue=({overlapLeft:e=-1,overlapRight:t=-1,overlapTop:r=-1,overlapBottom:n=-1}={})=>({dirX:e<t?"right":"left",dirY:r<n?"bottom":"top"}),ce=e=>({x:e.left+e.width/2,y:e.top+e.height/2});function de(e,t){const r=e.left+e.width/2,n=e.top+e.height/2;return{x:t.left+t.width/2-r,y:t.top+t.height/2-n}}function fe(e,t){if(!ie(e,t))return{inDir:null,dirX:null,dirY:null,depthX:0,depthY:0};const{overlapLeft:r,overlapRight:n,overlapTop:o,overlapBottom:i}=le(e,t),{dirX:a,dirY:s}=ue({overlapLeft:r,overlapRight:n,overlapTop:o,overlapBottom:i}),l=Math.min(r,n),u=Math.min(o,i);let c;return c=l<u?a:s,{inDir:c,dirX:a,dirY:s,depthX:l,depthY:u}}function me(e,t){const r=ie(e,t),n={in:null,x:null,y:null},o={y:null,x:null},i={top:0,bottom:0,left:0,right:0},{overlapLeft:a,overlapRight:s,overlapTop:l,overlapBottom:u}=le(t,e);i.top=l,i.bottom=u,i.left=a,i.right=s;const c=Object.entries(i).filter(([,e])=>e>0).sort((e,t)=>e[1]-t[1]),{dirX:d,dirY:f}=ue({overlapLeft:s,overlapRight:a,overlapTop:u,overlapBottom:l});return n.y=f,n.x=d,i.bottom<0?o.y="bottom":i.top<0&&(o.y="top"),i.left<0?o.x="left":i.right<0&&(o.x="right"),n.in=r?i.top===i.bottom&&i.bottom===i.left&&i.left===i.right?"center":c.length?c[0][0]:"top":null,{dirs:n,depth:i,isNeg:o}}const pe=new Map;class he extends Error{constructor(e,t,r){super(e),this.name="MediaLoadingError",this.url=t,this.stage=r}}const ge=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)},ye=(e,t="image/jpeg")=>{const r=e=>{const t=URL.createObjectURL(e),r=pe.get(t);return pe.set(t,"number"==typeof r?r+1:1),t};if(e instanceof Uint8Array)return r(new Blob([e],{type:t}));if("string"==typeof e&&e.startsWith("data:")){const n=e.split(",")[1],o=atob(n),i=new Uint8Array(o.length);for(let e=0;e<o.length;e++)i[e]=o.charCodeAt(e);return r(new Blob([i],{type:t}))}return"string"==typeof e?e:""},we=(e,t)=>{const r=e=>t&&void 0===e,n=e=>r(e)||"string"==typeof e||null===e,o=(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(!o(e.albumartists,e=>"string"==typeof e))throw new TypeError('Invalid metadata: "albumartists" must be an array of string.');if(!o(e.genre,e=>"string"==typeof e))throw new TypeError('Invalid metadata: "genre" must be an array of string.');if(!o(e.label,e=>"string"==typeof e))throw new TypeError('Invalid metadata: "label" must be an array of string.');if(!o(e.composer,e=>"string"==typeof e))throw new TypeError('Invalid metadata: "composer" must be an array of string.');if(!o(e.artists,e=>"string"==typeof e))throw new TypeError('Invalid metadata: "artists" must be an array of string.');if(!o(e.picture,e=>!(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 a=(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.`)}};a(e.disk,"disk"),a(e.track,"track")},be=e=>we(e,!1),Ee=e=>we(e,!0),ve=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(),o=await t(n);if(!o||"object"!=typeof o.common)throw new TypeError('Invalid metadata: "common" property is missing or not an object.');const i=o.common;return Ee(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:ye(e.data,e.format)}))??[]}}catch(e){throw e}},Te=async(e,t={},r={},n=e=>new Promise((e,t)=>t(new TypeError("parseFile library not found."))),o={},i="null")=>{if("string"!=typeof e&&!(e 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 a,s="";const l=(t,r)=>{o.onProgress&&o.onProgress({event:r,status:"loading",stage:t,url:s||(e instanceof HTMLMediaElement?e.src:"unknown")})},u=(t,r)=>{o.onError&&o.onError({error:t,url:s||(e instanceof HTMLMediaElement?e.src:"unknown"),stage:r})};try{l("INITIALIZING"),"string"==typeof e?(s=e,a=new Audio(s)):(a=e,s=a.src);try{await new Promise((e,t)=>{const r=e=>l("DOWNLOADING",e),n=()=>{i(),e(void 0)},o=e=>{i(),t(new Error(`HTMLMediaElement failed to load: ${e.message||"Unknown error"}`))},i=()=>{a.removeEventListener("progress",r),a.removeEventListener("loadedmetadata",n),a.removeEventListener("error",o)};a.addEventListener("progress",r),a.addEventListener("loadedmetadata",n),a.addEventListener("error",o),a.readyState>=1&&(i(),e(void 0))}),l("METADATA_LOADED")}catch(e){throw new he(e instanceof Error?e.message:"UNKNOWN ERROR",s,"METADATA")}const c={id:r.id||await ge(s),duration:Math.floor(1e3*a.duration),url:s,weight:r.weight??1};let d={};l("EXTRACTING_ID3");try{d=await ve(s,n)}catch(e){u(e instanceof Error?e:new Error("Unknown Error"),"ID3"),console.warn(`[TinyAudioUtils] ID3 extraction failed for ${s}. Falling back to filename.`)}const f=e=>{try{return(e.split(/[?#]/)[0].split("/").pop()??"").replace(/\.[^/.]+$/,"")||"Unknown Track"}catch{return"Unknown Track"}},m={...c,...t,...d,...r,title:d.title||r.title||f(s),artist:d.artist||r.artist||("string"==typeof i?i:String(i()))};return o.onProgress&&o.onProgress({status:"success",stage:"COMPLETE",url:s}),m}catch(e){if(e instanceof he)throw e;{const t=new he(e instanceof Error?e.message:"UNKNOWN ERROR",s,"INITIALIZING");throw u(t,"INITIALIZING"),t}}};window.TinyBasicsEs=t})();