UNPKG

tiny-essentials

Version:

Collection of small, essential scripts designed to be used across various projects. These simple utilities are crafted for speed, ease of use, and versatility.

1 lines 2.21 kB
(()=>{"use strict";const e={d:(s,n)=>{if(Array.isArray(n))for(var a=0;a<n.length;){var i=n[a++],r=n[a++];e.o(s,i)?0===r&&a++:0===r?Object.defineProperty(s,i,{enumerable:!0,value:n[a++]}):Object.defineProperty(s,i,{enumerable:!0,get:r})}else for(var i in n)e.o(n,i)&&!e.o(s,i)&&Object.defineProperty(s,i,{enumerable:!0,get:n[i]})},o:(e,s)=>Object.prototype.hasOwnProperty.call(e,s)};let s={};e.d(s,{TinyClassManager:()=>a});class n{#e=new Set;get appliedPlugins(){if(this.#s)throw new Error("[TinyClassManager] Cannot get a consumed manager instance.");return[...this.#e]}#n=[];get appliedPluginClasses(){if(this.#s)throw new Error("[TinyClassManager] Cannot get a consumed manager instance.");return[...this.#n]}get size(){if(this.#s)throw new Error("[TinyClassManager] Cannot get a consumed manager instance.");return this.#n.length}#a;get currentClass(){if(this.#s)throw new Error("[TinyClassManager] Cannot get a consumed manager instance.");return this.#a}#s=!1;get used(){return this.#s}constructor(e,s=[]){this.#a=e,this.#n=[...s,e]}#i(e,s,a){if(this.#s)throw new Error("[TinyClassManager] Cannot reuse a consumed manager instance.");if(this.#e.has(e))throw new Error(`[TinyClassManager] Plugin conflict: "${e}" is already installed.`);for(const n of s)if(!this.#e.has(n))throw new Error(`[TinyClassManager] Missing Dependency: "${e}" requires "${n}" to be installed first.`);const i=new n(a,this.#n);return this.#e.forEach(e=>i.#e.add(e)),i.#e.add(e),this.#s=!0,this.#e.clear(),this.#n=[],i}use(e){const s=e.dependencies||[],n=e.apply(this.#a,this.appliedPluginClasses);return this.#i(e.name,s,n)}insert(e){const s=e(this.#a,this.appliedPluginClasses),n=s._tinyDepName;if(!n)throw new Error("[TinyClassManager] Plugin class must define a static '_tinyDepName' property.");const a=s._tinyDeps??[];if(!Array.isArray(a)||!a.every(e=>"string"==typeof e))throw new Error("[TinyClassManager] Plugin class must define a static array of strings in '_tinyDepName' property.");return this.#i(n,a,s)}build(){if(this.#s)throw new Error("[TinyClassManager] Cannot build from an already finalized manager.");return this.#s=!0,this.#e.clear(),this.#n=[],this.#a}}const a=n;window.TinyClassManager=s.TinyClassManager})();