tiny-essentials 1.28.5 โ 1.28.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +18 -1
- package/changelog/1/28/6.md +11 -0
- package/dist/v1/TinyAdvancedRaffle.min.js +1 -1
- package/dist/v1/TinyEssentials.min.js +1 -1
- package/dist/v1/TinyIframeEvents.min.js +1 -1
- package/dist/v1/TinyLocalStorage.min.js +1 -1
- package/dist/v1/TinyMediaPlayer.min.js +1 -1
- package/dist/v1/TinyNewWinEvents.min.js +1 -1
- package/dist/v1/TinyRadioFm.min.js +1 -1
- package/dist/v1/TinySmartScroller.min.js +1 -1
- package/dist/v1/TinyUploadClicker.min.js +1 -1
- package/dist/v1/css/TinyLoadingScreen.min.css +1 -1
- package/dist/v1/libs/TinyMediaPlayer/HtmlAudio.cjs +53 -3
- package/dist/v1/libs/TinyMediaPlayer/HtmlAudio.d.mts +25 -0
- package/dist/v1/libs/TinyMediaPlayer/HtmlAudio.mjs +49 -3
- package/dist/v1/libs/TinyMediaPlayer/HtmlVideo.cjs +53 -3
- package/dist/v1/libs/TinyMediaPlayer/HtmlVideo.d.mts +25 -0
- package/dist/v1/libs/TinyMediaPlayer/HtmlVideo.mjs +49 -3
- package/dist/v1/libs/TinyMediaPlayer/SoundCloud.cjs +792 -0
- package/dist/v1/libs/TinyMediaPlayer/SoundCloud.d.mts +300 -0
- package/dist/v1/libs/TinyMediaPlayer/SoundCloud.mjs +697 -0
- package/dist/v1/libs/TinyMediaPlayer/Youtube.cjs +124 -12
- package/dist/v1/libs/TinyMediaPlayer/Youtube.d.mts +96 -0
- package/dist/v1/libs/TinyMediaPlayer/Youtube.mjs +107 -10
- package/dist/v1/libs/TinyMediaPlayer/docs/SoundCloudWidget.cjs +381 -0
- package/dist/v1/libs/TinyMediaPlayer/docs/SoundCloudWidget.d.mts +704 -0
- package/dist/v1/libs/TinyMediaPlayer/docs/SoundCloudWidget.mjs +343 -0
- package/dist/v1/libs/TinyMediaPlayer/index.cjs +52 -1
- package/dist/v1/libs/TinyMediaPlayer/index.d.mts +60 -0
- package/dist/v1/libs/TinyMediaPlayer/index.mjs +47 -1
- package/dist/v1/libs/TinyMediaPlayer.cjs +38 -0
- package/dist/v1/libs/TinyMediaPlayer.d.mts +13 -0
- package/dist/v1/libs/TinyMediaPlayer.mjs +38 -0
- package/docs/v1/libs/TinyMediaPlayer.md +31 -9
- package/package.json +51 -10
package/README.md
CHANGED
|
@@ -33,7 +33,24 @@ You can install Tiny Essentials via npm:
|
|
|
33
33
|
npm install tiny-essentials
|
|
34
34
|
```
|
|
35
35
|
|
|
36
|
-
|
|
36
|
+
### ๐ก Best Practices
|
|
37
|
+
|
|
38
|
+
* **For Package Developers:** If you are using `tiny-essentials` as a dependency to build another package, we recommend installing it as a development dependency:
|
|
39
|
+
```bash
|
|
40
|
+
npm install --save-dev tiny-essentials
|
|
41
|
+
```
|
|
42
|
+
Additionally, utilize the **TinyFork** tool to inject the specific modules you require into your package development.
|
|
43
|
+
|
|
44
|
+
* **For Application Developers:** If you are integrating `tiny-essentials` into a website or a standalone application, a standard installation is recommended.
|
|
45
|
+
|
|
46
|
+
* **Optimization:** To ensure the smallest possible bundle size and optimal performance, avoid importing from the root package. Instead, use specific sub-module imports to allow for efficient tree-shaking:
|
|
47
|
+
```javascript
|
|
48
|
+
// โ Avoid this (imports the entire library)
|
|
49
|
+
import { someFunction } from 'tiny-essentials';
|
|
50
|
+
|
|
51
|
+
// โ
Do this (optimized for bundle size)
|
|
52
|
+
import { someFunction } from 'tiny-essentials/basics/module-path';
|
|
53
|
+
```
|
|
37
54
|
|
|
38
55
|
## ๐งช Module Versions
|
|
39
56
|
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
## ๐ BaseMediaAdapter Release Notes
|
|
2
|
+
|
|
3
|
+
### ๐ New Features
|
|
4
|
+
- **SoundCloud Support:** Introduced `SoundCloudMediaAdapter` to enable seamless SoundCloud integration. ๐ต
|
|
5
|
+
|
|
6
|
+
### ๐ ๏ธ Improvements
|
|
7
|
+
- **Event Synchronization:** The `seek` event for `YouTube`, `HtmlAudio`, and `HtmlVideo` has been updated to correctly align with their respective native API events. ๐
|
|
8
|
+
|
|
9
|
+
### โจ API Enhancements
|
|
10
|
+
- **New Utility Methods:** Added `isReady()`, `getContentData()`, and `waitIsReady()` to provide better control over media states. ๐ ๏ธ
|
|
11
|
+
- **Static Validation:** Added a static `canHandle()` method, allowing for URL validation before adapter instantiation. ๐
|
|
@@ -1 +1 @@
|
|
|
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 s=Number.isNaN||function(e){return e!=e};function o(){o.init.call(this)}e.exports=o,e.exports.once=function(e,t){return new Promise(function(r,i){function s(r){e.removeListener(t,o),i(r)}function o(){"function"==typeof e.removeListener&&e.removeListener("error",s),r([].slice.call(arguments))}l(e,t,o,{once:!0}),"error"!==t&&function(e,t){"function"==typeof e.on&&l(e,"error",t,{once:!0})}(e,s)})},o.EventEmitter=o,o.prototype._events=void 0,o.prototype._eventsCount=0,o.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?o.defaultMaxListeners:e._maxListeners}function f(e,t,r,i){var s,o,n,f;if(a(r),void 0===(o=e._events)?(o=e._events=Object.create(null),e._eventsCount=0):(void 0!==o.newListener&&(e.emit("newListener",t,r.listener?r.listener:r),o=e._events),n=o[t]),void 0===n)n=o[t]=r,++e._eventsCount;else if("function"==typeof n?n=o[t]=i?[r,n]:[n,r]:i?n.unshift(r):n.push(r),(s=u(e))>0&&n.length>s&&!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},s=h.bind(i);return s.listener=r,i.wrapFn=s,s}function y(e,t,r){var i=e._events;if(void 0===i)return[];var s=i[t];return void 0===s?[]:"function"==typeof s?r?[s.listener||s]:[s]: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}(s):d(s,s.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 d(e,t){for(var r=new Array(t),i=0;i<t;++i)r[i]=e[i];return r}function l(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 s(o){i.once&&e.removeEventListener(t,s),r(o)})}}Object.defineProperty(o,"defaultMaxListeners",{enumerable:!0,get:function(){return n},set:function(e){if("number"!=typeof e||e<0||s(e))throw new RangeError('The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received '+e+".");n=e}}),o.init=function(){void 0!==this._events&&this._events!==Object.getPrototypeOf(this)._events||(this._events=Object.create(null),this._eventsCount=0),this._maxListeners=this._maxListeners||void 0},o.prototype.setMaxListeners=function(e){if("number"!=typeof e||e<0||s(e))throw new RangeError('The value of "n" is out of range. It must be a non-negative number. Received '+e+".");return this._maxListeners=e,this},o.prototype.getMaxListeners=function(){return u(this)},o.prototype.emit=function(e){for(var t=[],r=1;r<arguments.length;r++)t.push(arguments[r]);var s="error"===e,o=this._events;if(void 0!==o)s=s&&void 0===o.error;else if(!s)return!1;if(s){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=o[e];if(void 0===u)return!1;if("function"==typeof u)i(u,this,t);else{var f=u.length,h=d(u,f);for(r=0;r<f;++r)i(h[r],this,t)}return!0},o.prototype.addListener=function(e,t){return f(this,e,t,!1)},o.prototype.on=o.prototype.addListener,o.prototype.prependListener=function(e,t){return f(this,e,t,!0)},o.prototype.once=function(e,t){return a(t),this.on(e,p(this,e,t)),this},o.prototype.prependOnceListener=function(e,t){return a(t),this.prependListener(e,p(this,e,t)),this},o.prototype.removeListener=function(e,t){var r,i,s,o,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(s=-1,o=r.length-1;o>=0;o--)if(r[o]===t||r[o].listener===t){n=r[o].listener,s=o;break}if(s<0)return this;0===s?r.shift():function(e,t){for(;t+1<e.length;t++)e[t]=e[t+1];e.pop()}(r,s),1===r.length&&(i[e]=r[0]),void 0!==i.removeListener&&this.emit("removeListener",e,n||t)}return this},o.prototype.off=o.prototype.removeListener,o.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 s,o=Object.keys(r);for(i=0;i<o.length;++i)"removeListener"!==(s=o[i])&&this.removeAllListeners(s);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},o.prototype.listeners=function(e){return y(this,e,!0)},o.prototype.rawListeners=function(e){return y(this,e,!1)},o.listenerCount=function(e,t){return"function"==typeof e.listenerCount?e.listenerCount(t):m.call(e,t)},o.prototype.listenerCount=m,o.prototype.eventNames=function(){return this._eventsCount>0?t(this._events):[]}}};const t={};function r(i){const s=t[i];if(void 0!==s)return s.exports;const o=t[i]={exports:{}};return e[i](o,o.exports,r),o.exports}r.d=(e,t)=>{if(Array.isArray(t))for(var i=0;i<t.length;){var s=t[i++],o=t[i++];r.o(e,s)?0===o&&i++:0===o?Object.defineProperty(e,s,{enumerable:!0,value:t[i++]}):Object.defineProperty(e,s,{enumerable:!0,get:o})}else for(var s in t)r.o(t,s)&&!r.o(e,s)&&Object.defineProperty(e,s,{enumerable:!0,get:t[s]})},r.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t);let i={};r.d(i,{TinyAdvancedRaffle:()=>a});var s=r(7);const o=e=>{if(e)throw new Error("This TinyAdvancedRaffle instance has been destroyed and can no longer be used.")};class n extends s.EventEmitter{#e=!1;#t;#r;#i=[];#s=[];#o=[];#n=new Map;#a=new Set;#u=new Map;#f;#h=new Map;#p=new Map;get isDestroyed(){return this.#e}get freq(){return o(this.#e),Object.fromEntries(this.#p)}get size(){return o(this.#e),this.#h.size}get normalization(){return o(this.#e),this.#t}set normalization(e){if(o(this.#e),"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 o(this.#e),this.#r}set seed(e){if(o(this.#e),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 o(this.#e),[...this.#i]}set globalModifiers(e){if(o(this.#e),!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 o(this.#e),[...this.#s]}set temporaryModifiers(e){if(o(this.#e),!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.#s=e}get conditionalRules(){return o(this.#e),[...this.#o]}set conditionalRules(e){if(o(this.#e),!Array.isArray(e)||!e.every(e=>"function"==typeof e))throw new TypeError("conditionalRules must be an array of functions (WeightsCallback).");this.#o=e}get pitySystems(){return o(this.#e),Object.fromEntries(this.#n)}set pitySystems(e){if(o(this.#e),!(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 o(this.#e),Array.from(this.#a)}set exclusions(e){if(o(this.#e),!(e instanceof Set&&[...e].every(e=>"string"==typeof e)))throw new TypeError("exclusions must be a Set<string>.");this.#a=e}get groups(){o(this.#e);const e={};return this.#u.forEach((t,r)=>e[r]=Array.from(t)),e}set groups(e){if(o(this.#e),!(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 o(this.#e),this.#f}set rng(e){if(o(this.#e),"function"!=typeof e||"number"!=typeof e())throw new TypeError("rng must be a function returning a number (RngGenerator).");this.#f=e}get items(){o(this.#e);const e={};return this.#h.forEach((t,r)=>{e[r]={...t,groups:Array.from(t.groups)}}),e}set items(e){if(o(this.#e),!(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}hasItem(e){if(o(this.#e),"string"!=typeof e)throw new TypeError("itemId must be a string");return this.#h.has(e)}addItem(e,t={}){if(o(this.#e),"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:s={},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 i)throw new TypeError("label must be a string");if("object"!=typeof s||null===s)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 a={id:e,label:i,baseWeight:Math.max(0,Number(r)||0),meta:{...s},groups:new Set(n),locked:!1};this.#h.set(e,a);for(const t of n)this._ensureGroup(t).add(e);return this.emit("itemAdded",a),a}removeItem(e){if(o(this.#e),"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(o(this.#e),"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(o(this.#e),"string"!=typeof e||!e.trim())throw new TypeError("id must be a non-empty string");return this.#h.get(e)??null}listItems(){return o(this.#e),Array.from(this.#h.values()).map(e=>({...e}))}clearList(){o(this.#e),this.#h.clear(),this.clearFreqs(),this.clearPities()}hasGlobalModifier(e){if(o(this.#e),"function"!=typeof e)throw new TypeError("fn must be a function");return this.#i.includes(e)}addGlobalModifier(e){if(o(this.#e),"function"!=typeof e)throw new TypeError("fn must be a function");this.#i.push(e)}removeGlobalModifier(e){if(o(this.#e),"function"!=typeof e)throw new TypeError("fn must be a function");this.#i=this.#i.filter(t=>t!==e)}hasTemporaryModifier(e){if(o(this.#e),"function"!=typeof e)throw new TypeError("fn must be a function");return this.#s.some(t=>t.fn===e)}addTemporaryModifier(e,t=1){if(o(this.#e),"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.#s.push({fn:e,uses:Math.max(1,Math.floor(t))})}removeTemporaryModifier(e){if(o(this.#e),"function"!=typeof e)throw new TypeError("fn must be a function");const t=this.#s.length;return this.#s=this.#s.filter(t=>t.fn!==e),this.#s.length!==t}hasConditionalRule(e){if(o(this.#e),"function"!=typeof e)throw new TypeError("ruleFn must be a function");return this.#o.includes(e)}addConditionalRule(e){if(o(this.#e),"function"!=typeof e)throw new TypeError("ruleFn must be a function");this.#o.push(e)}removeConditionalRule(e){if(o(this.#e),"function"!=typeof e)throw new TypeError("ruleFn must be a function");const t=this.#o.length;return this.#o=this.#o.filter(t=>t!==e),this.#o.length!==t}hasPity(e){if(o(this.#e),"string"!=typeof e)throw new TypeError("itemId must be a string");return this.#n.has(e)}configurePity(e,t){if(o(this.#e),!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:s=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 s)throw new TypeError("cap must be a number");this.#n.set(e,{threshold:Math.max(1,r),increment:Number(i)||0,cap:Number(s)||1/0,counter:0,currentAdd:0})}resetPity(e){if(o(this.#e),"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(){o(this.#e),this.#n.clear()}hasExclusion(e){if(o(this.#e),"string"!=typeof e)throw new TypeError("itemId must be a string");return this.#a.has(e)}excludeItem(e){if(o(this.#e),"string"!=typeof e)throw new TypeError("itemId must be a string");this.#a.add(e)}includeItem(e){if(o(this.#e),"string"!=typeof e)throw new TypeError("itemId must be a string");this.#a.delete(e)}_ensureGroup(e){if(o(this.#e),"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(o(this.#e),"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(o(this.#e),"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(o(this.#e),"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(){o(this.#e),this.#p.clear()}resetFreq(e){if(o(this.#e),"string"!=typeof e)throw new TypeError("itemId must be a string");this.#p.delete(e)}computeEffectiveWeights(e={}){if(o(this.#e),"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.#s){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.#o){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(!(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 s=0;return t.map((e,t)=>{const o=r[t]/i;return s+=o,{id:e.id,weight:e.weight,p:o,cumulative:s}})}{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(o(this.#e),"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.#s]},r=this.computeEffectiveWeights(t),i=this._weightsToDistribution(r);if(!i.length)return null;const s=this.#f(),n=i.find(e=>s<=e.cumulative)??i[i.length-1];for(const[e,t]of this.#n)e===n.id?(t.counter=0,t.currentAdd=0):t.counter++;this._consumeTemporaryModifiers();const a=this.#h.get(n.id);if(!a)return null;const u={id:a.id,label:a.label,meta:{...a.meta},prob:n.p};return this.emit("draw",u),u&&this.#p.set(u.id,(this.#p.get(u.id)||0)+1),u}_consumeTemporaryModifiers(){for(let e=this.#s.length-1;e>=0;--e){const t=this.#s[e];t.uses-=1,t.uses<=0&&this.#s.splice(e,1)}}drawMany(e=1,t={}){if(o(this.#e),!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,s=[],n=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:n,metadata:t.metadata});if(this.#a=e,!i)break;s.push(i),r.add(i.id),n.push(i)}return s}for(let i=0;i<e;++i){const e=this.drawOne({previousDraws:n,metadata:t.metadata});if(!e)break;s.push(e),n.push(e),r||this.excludeItem(e.id)}if(!r)for(const e of s)this.includeItem(e.id);return s}exportToJson(){return o(this.#e),{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(o(this.#e),"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(){o(this.#e);const e=new n;return e.#t=this.#t,e.#r=this.#r,e.#i=[...this.#i],e.#s=this.#s.map(e=>({fn:e.fn,uses:e.uses})),e.#o=[...this.#o],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("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.#n.clear(),this.#a.clear(),this.#u.clear(),this.#h.clear(),this.#p.clear(),this.#i=[],this.#s=[],this.#o=[],this.#r=null,this.#e=!0)}}const a=n;window.TinyAdvancedRaffle=i.TinyAdvancedRaffle})();
|
|
1
|
+
(()=>{"use strict";var e={705(e,t,r){r.d(t,{TinyAdvancedRaffle:()=>n});var i=r.cjs(function(e,t){var r,i="object"==typeof Reflect?Reflect:null,s=i&&"function"==typeof i.apply?i.apply:function(e,t,r){return Function.prototype.apply.call(e,t,r)};r=i&&"function"==typeof i.ownKeys?i.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 n(){n.init.call(this)}e.exports=n,e.exports.once=function(e,t){return new Promise(function(r,i){function s(r){e.removeListener(t,o),i(r)}function o(){"function"==typeof e.removeListener&&e.removeListener("error",s),r([].slice.call(arguments))}c(e,t,o,{once:!0}),"error"!==t&&function(e,t){"function"==typeof e.on&&c(e,"error",t,{once:!0})}(e,s)})},n.EventEmitter=n,n.prototype._events=void 0,n.prototype._eventsCount=0,n.prototype._maxListeners=void 0;var a=10;function u(e){if("function"!=typeof e)throw new TypeError('The "listener" argument must be of type Function. Received type '+typeof e)}function f(e){return void 0===e._maxListeners?n.defaultMaxListeners:e._maxListeners}function h(e,t,r,i){var s,o,n,a;if(u(r),void 0===(o=e._events)?(o=e._events=Object.create(null),e._eventsCount=0):(void 0!==o.newListener&&(e.emit("newListener",t,r.listener?r.listener:r),o=e._events),n=o[t]),void 0===n)n=o[t]=r,++e._eventsCount;else if("function"==typeof n?n=o[t]=i?[r,n]:[n,r]:i?n.unshift(r):n.push(r),(s=f(e))>0&&n.length>s&&!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,a=h,console&&console.warn&&console.warn(a)}return e}function p(){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 y(e,t,r){var i={fired:!1,wrapFn:void 0,target:e,type:t,listener:r},s=p.bind(i);return s.listener=r,i.wrapFn=s,s}function m(e,t,r){var i=e._events;if(void 0===i)return[];var s=i[t];return void 0===s?[]:"function"==typeof s?r?[s.listener||s]:[s]: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}(s):l(s,s.length)}function d(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 l(e,t){for(var r=new Array(t),i=0;i<t;++i)r[i]=e[i];return r}function c(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 s(o){i.once&&e.removeEventListener(t,s),r(o)})}}Object.defineProperty(n,"defaultMaxListeners",{enumerable:!0,get:function(){return a},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+".");a=e}}),n.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},n.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},n.prototype.getMaxListeners=function(){return f(this)},n.prototype.emit=function(e){for(var t=[],r=1;r<arguments.length;r++)t.push(arguments[r]);var i="error"===e,o=this._events;if(void 0!==o)i=i&&void 0===o.error;else if(!i)return!1;if(i){var 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=o[e];if(void 0===u)return!1;if("function"==typeof u)s(u,this,t);else{var f=u.length,h=l(u,f);for(r=0;r<f;++r)s(h[r],this,t)}return!0},n.prototype.addListener=function(e,t){return h(this,e,t,!1)},n.prototype.on=n.prototype.addListener,n.prototype.prependListener=function(e,t){return h(this,e,t,!0)},n.prototype.once=function(e,t){return u(t),this.on(e,y(this,e,t)),this},n.prototype.prependOnceListener=function(e,t){return u(t),this.prependListener(e,y(this,e,t)),this},n.prototype.removeListener=function(e,t){var r,i,s,o,n;if(u(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(s=-1,o=r.length-1;o>=0;o--)if(r[o]===t||r[o].listener===t){n=r[o].listener,s=o;break}if(s<0)return this;0===s?r.shift():function(e,t){for(;t+1<e.length;t++)e[t]=e[t+1];e.pop()}(r,s),1===r.length&&(i[e]=r[0]),void 0!==i.removeListener&&this.emit("removeListener",e,n||t)}return this},n.prototype.off=n.prototype.removeListener,n.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 s,o=Object.keys(r);for(i=0;i<o.length;++i)"removeListener"!==(s=o[i])&&this.removeAllListeners(s);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},n.prototype.listeners=function(e){return m(this,e,!0)},n.prototype.rawListeners=function(e){return m(this,e,!1)},n.listenerCount=function(e,t){return"function"==typeof e.listenerCount?e.listenerCount(t):d.call(e,t)},n.prototype.listenerCount=d,n.prototype.eventNames=function(){return this._eventsCount>0?r(this._events):[]}});const s=e=>{if(e)throw new Error("This TinyAdvancedRaffle instance has been destroyed and can no longer be used.")};class o extends i.EventEmitter{#e=!1;#t;#r;#i=[];#s=[];#o=[];#n=new Map;#a=new Set;#u=new Map;#f;#h=new Map;#p=new Map;get isDestroyed(){return this.#e}get freq(){return s(this.#e),Object.fromEntries(this.#p)}get size(){return s(this.#e),this.#h.size}get normalization(){return s(this.#e),this.#t}set normalization(e){if(s(this.#e),"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 s(this.#e),this.#r}set seed(e){if(s(this.#e),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 s(this.#e),[...this.#i]}set globalModifiers(e){if(s(this.#e),!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 s(this.#e),[...this.#s]}set temporaryModifiers(e){if(s(this.#e),!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.#s=e}get conditionalRules(){return s(this.#e),[...this.#o]}set conditionalRules(e){if(s(this.#e),!Array.isArray(e)||!e.every(e=>"function"==typeof e))throw new TypeError("conditionalRules must be an array of functions (WeightsCallback).");this.#o=e}get pitySystems(){return s(this.#e),Object.fromEntries(this.#n)}set pitySystems(e){if(s(this.#e),!(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 s(this.#e),Array.from(this.#a)}set exclusions(e){if(s(this.#e),!(e instanceof Set&&[...e].every(e=>"string"==typeof e)))throw new TypeError("exclusions must be a Set<string>.");this.#a=e}get groups(){s(this.#e);const e={};return this.#u.forEach((t,r)=>e[r]=Array.from(t)),e}set groups(e){if(s(this.#e),!(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 s(this.#e),this.#f}set rng(e){if(s(this.#e),"function"!=typeof e||"number"!=typeof e())throw new TypeError("rng must be a function returning a number (RngGenerator).");this.#f=e}get items(){s(this.#e);const e={};return this.#h.forEach((t,r)=>{e[r]={...t,groups:Array.from(t.groups)}}),e}set items(e){if(s(this.#e),!(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}hasItem(e){if(s(this.#e),"string"!=typeof e)throw new TypeError("itemId must be a string");return this.#h.has(e)}addItem(e,t={}){if(s(this.#e),"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:n=[]}=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(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 a={id:e,label:i,baseWeight:Math.max(0,Number(r)||0),meta:{...o},groups:new Set(n),locked:!1};this.#h.set(e,a);for(const t of n)this._ensureGroup(t).add(e);return this.emit("itemAdded",a),a}removeItem(e){if(s(this.#e),"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(s(this.#e),"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(s(this.#e),"string"!=typeof e||!e.trim())throw new TypeError("id must be a non-empty string");return this.#h.get(e)??null}listItems(){return s(this.#e),Array.from(this.#h.values()).map(e=>({...e}))}clearList(){s(this.#e),this.#h.clear(),this.clearFreqs(),this.clearPities()}hasGlobalModifier(e){if(s(this.#e),"function"!=typeof e)throw new TypeError("fn must be a function");return this.#i.includes(e)}addGlobalModifier(e){if(s(this.#e),"function"!=typeof e)throw new TypeError("fn must be a function");this.#i.push(e)}removeGlobalModifier(e){if(s(this.#e),"function"!=typeof e)throw new TypeError("fn must be a function");this.#i=this.#i.filter(t=>t!==e)}hasTemporaryModifier(e){if(s(this.#e),"function"!=typeof e)throw new TypeError("fn must be a function");return this.#s.some(t=>t.fn===e)}addTemporaryModifier(e,t=1){if(s(this.#e),"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.#s.push({fn:e,uses:Math.max(1,Math.floor(t))})}removeTemporaryModifier(e){if(s(this.#e),"function"!=typeof e)throw new TypeError("fn must be a function");const t=this.#s.length;return this.#s=this.#s.filter(t=>t.fn!==e),this.#s.length!==t}hasConditionalRule(e){if(s(this.#e),"function"!=typeof e)throw new TypeError("ruleFn must be a function");return this.#o.includes(e)}addConditionalRule(e){if(s(this.#e),"function"!=typeof e)throw new TypeError("ruleFn must be a function");this.#o.push(e)}removeConditionalRule(e){if(s(this.#e),"function"!=typeof e)throw new TypeError("ruleFn must be a function");const t=this.#o.length;return this.#o=this.#o.filter(t=>t!==e),this.#o.length!==t}hasPity(e){if(s(this.#e),"string"!=typeof e)throw new TypeError("itemId must be a string");return this.#n.has(e)}configurePity(e,t){if(s(this.#e),!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(s(this.#e),"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(){s(this.#e),this.#n.clear()}hasExclusion(e){if(s(this.#e),"string"!=typeof e)throw new TypeError("itemId must be a string");return this.#a.has(e)}excludeItem(e){if(s(this.#e),"string"!=typeof e)throw new TypeError("itemId must be a string");this.#a.add(e)}includeItem(e){if(s(this.#e),"string"!=typeof e)throw new TypeError("itemId must be a string");this.#a.delete(e)}_ensureGroup(e){if(s(this.#e),"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(s(this.#e),"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(s(this.#e),"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(s(this.#e),"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(){s(this.#e),this.#p.clear()}resetFreq(e){if(s(this.#e),"string"!=typeof e)throw new TypeError("itemId must be a string");this.#p.delete(e)}computeEffectiveWeights(e={}){if(s(this.#e),"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.#s){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.#o){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(!(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 s=0;return t.map((e,t)=>{const o=r[t]/i;return s+=o,{id:e.id,weight:e.weight,p:o,cumulative:s}})}{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(s(this.#e),"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.#s]},r=this.computeEffectiveWeights(t),i=this._weightsToDistribution(r);if(!i.length)return null;const o=this.#f(),n=i.find(e=>o<=e.cumulative)??i[i.length-1];for(const[e,t]of this.#n)e===n.id?(t.counter=0,t.currentAdd=0):t.counter++;this._consumeTemporaryModifiers();const a=this.#h.get(n.id);if(!a)return null;const u={id:a.id,label:a.label,meta:{...a.meta},prob:n.p};return this.emit("draw",u),u&&this.#p.set(u.id,(this.#p.get(u.id)||0)+1),u}_consumeTemporaryModifiers(){for(let e=this.#s.length-1;e>=0;--e){const t=this.#s[e];t.uses-=1,t.uses<=0&&this.#s.splice(e,1)}}drawMany(e=1,t={}){if(s(this.#e),!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=[],n=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:n,metadata:t.metadata});if(this.#a=e,!i)break;o.push(i),r.add(i.id),n.push(i)}return o}for(let i=0;i<e;++i){const e=this.drawOne({previousDraws:n,metadata:t.metadata});if(!e)break;o.push(e),n.push(e),r||this.excludeItem(e.id)}if(!r)for(const e of o)this.includeItem(e.id);return o}exportToJson(){return s(this.#e),{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(s(this.#e),"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(){s(this.#e);const e=new o;return e.#t=this.#t,e.#r=this.#r,e.#i=[...this.#i],e.#s=this.#s.map(e=>({fn:e.fn,uses:e.uses})),e.#o=[...this.#o],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("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.#n.clear(),this.#a.clear(),this.#u.clear(),this.#h.clear(),this.#p.clear(),this.#i=[],this.#s=[],this.#o=[],this.#r=null,this.#e=!0)}}const n=o}};const t={};function r(i){const s=t[i];if(void 0!==s)return s.exports;const o=t[i]={exports:{}};return e[i](o,o.exports,r),o.exports}r.d=(e,t)=>{if(Array.isArray(t))for(var i=0;i<t.length;){var s=t[i++],o=t[i++];r.o(e,s)?0===o&&i++:0===o?Object.defineProperty(e,s,{enumerable:!0,value:t[i++]}):Object.defineProperty(e,s,{enumerable:!0,get:o})}else for(var s in t)r.o(t,s)&&!r.o(e,s)&&Object.defineProperty(e,s,{enumerable:!0,get:t[s]})},r.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r.cjs=e=>{const t={exports:{}};return e.call(t.exports,t,t.exports),t.exports};let i=r(705);window.TinyAdvancedRaffle=i.TinyAdvancedRaffle})();
|