tiny-essentials 1.12.2 → 1.13.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.
@@ -0,0 +1,213 @@
1
+ /******/ (() => { // webpackBootstrap
2
+ /******/ "use strict";
3
+ /******/ // The require scope
4
+ /******/ var __webpack_require__ = {};
5
+ /******/
6
+ /************************************************************************/
7
+ /******/ /* webpack/runtime/define property getters */
8
+ /******/ (() => {
9
+ /******/ // define getter functions for harmony exports
10
+ /******/ __webpack_require__.d = (exports, definition) => {
11
+ /******/ for(var key in definition) {
12
+ /******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
13
+ /******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
14
+ /******/ }
15
+ /******/ }
16
+ /******/ };
17
+ /******/ })();
18
+ /******/
19
+ /******/ /* webpack/runtime/hasOwnProperty shorthand */
20
+ /******/ (() => {
21
+ /******/ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))
22
+ /******/ })();
23
+ /******/
24
+ /************************************************************************/
25
+ var __webpack_exports__ = {};
26
+
27
+ // EXPORTS
28
+ __webpack_require__.d(__webpack_exports__, {
29
+ TinyDomReadyManager: () => (/* reexport */ libs_TinyDomReadyManager)
30
+ });
31
+
32
+ ;// ./src/v1/libs/TinyDomReadyManager.mjs
33
+ /**
34
+ * A basic function that performs a task when the system is ready.
35
+ * Used for handlers in the readiness queue.
36
+ *
37
+ * @typedef {() => void} Fn
38
+ */
39
+
40
+ /**
41
+ * A function that determines whether a specific handler should be executed.
42
+ * Should return `true` to allow execution, or `false` to skip the handler.
43
+ *
44
+ * @typedef {() => boolean} FnFilter
45
+ */
46
+
47
+ /**
48
+ * @typedef {Object} Handler
49
+ * @property {Fn} fn - Function to execute when ready.
50
+ * @property {boolean} once - Whether to execute only once.
51
+ * @property {number} priority - Execution order (higher priority runs first).
52
+ * @property {FnFilter|null} filter - Optional filter function to determine execution.
53
+ * @property {boolean} domOnly - Whether to run as soon as DOM is ready (before full readiness).
54
+ */
55
+
56
+ class TinyDomReadyManager {
57
+ /** @type {Handler[]} */
58
+ #handlers = [];
59
+
60
+ /** @type {boolean} */
61
+ #isDomReady = false;
62
+
63
+ /** @type {boolean} */
64
+ #isFullyReady = false;
65
+
66
+ /** @type {Promise<any>[]} */
67
+ #promises = [];
68
+
69
+ /**
70
+ * Checks if the DOM is ready and if all Promises have been resolved.
71
+ */
72
+ #checkAllReady() {
73
+ if (this.#isDomReady) {
74
+ Promise.all(this.#promises)
75
+ .then(() => {
76
+ this.#isFullyReady = true;
77
+ this.#runHandlers(false); // run non-domOnly
78
+ })
79
+ .catch((err) => {
80
+ console.error('[TinyDomReadyManager] Promise rejected:', err);
81
+ });
82
+ }
83
+ }
84
+
85
+ /**
86
+ * Executes handlers by filtering them by `domOnly` flag and sorting by priority.
87
+ * @param {boolean} domOnlyOnly - Whether to run only `domOnly` handlers.
88
+ */
89
+ #runHandlers(domOnlyOnly) {
90
+ this.#handlers
91
+ .filter((h) => h.domOnly === domOnlyOnly)
92
+ .sort((a, b) => b.priority - a.priority)
93
+ .forEach((handler) => this.#invokeHandler(handler));
94
+
95
+ this.#handlers = this.#handlers.filter((h) => !(h.once && (domOnlyOnly ? h.domOnly : true)));
96
+ }
97
+
98
+ /**
99
+ * Executes a handler if its filter passes.
100
+ * @param {Handler} handler
101
+ */
102
+ #invokeHandler(handler) {
103
+ if (typeof handler.filter === 'function') {
104
+ try {
105
+ if (!handler.filter()) return;
106
+ } catch (err) {
107
+ console.warn('[TinyDomReadyManager] Filter error:', err);
108
+ return;
109
+ }
110
+ }
111
+
112
+ try {
113
+ handler.fn();
114
+ } catch (err) {
115
+ console.error('[TinyDomReadyManager] Handler error:', err);
116
+ }
117
+ }
118
+
119
+ /**
120
+ * Marks the system as DOM-ready and runs DOM-only handlers.
121
+ * @private
122
+ */
123
+ _markDomReady() {
124
+ this.#isDomReady = true;
125
+ this.#runHandlers(true); // Run domOnly
126
+ this.#checkAllReady(); // Then check for full readiness
127
+ }
128
+
129
+ /**
130
+ * Initializes the manager using `DOMContentLoaded`.
131
+ */
132
+ init() {
133
+ if (this.#isDomReady) throw new Error('[TinyDomReadyManager] init() has already been called.');
134
+
135
+ if (document.readyState === 'interactive' || document.readyState === 'complete') {
136
+ this._markDomReady();
137
+ } else {
138
+ document.addEventListener('DOMContentLoaded', () => this._markDomReady());
139
+ }
140
+ }
141
+
142
+ /**
143
+ * Adds a Promise to delay full readiness.
144
+ * @param {Promise<any>} promise
145
+ * @throws {TypeError}
146
+ */
147
+ addPromise(promise) {
148
+ if (!(promise instanceof Promise))
149
+ throw new TypeError('[TinyDomReadyManager] promise must be a valid Promise.');
150
+
151
+ if (this.#isFullyReady) return;
152
+ this.#promises.push(promise);
153
+ if (this.#isDomReady) this.#checkAllReady();
154
+ }
155
+
156
+ /**
157
+ * Registers a handler to run either after DOM is ready or after full readiness.
158
+ *
159
+ * @param {Fn} fn - Function to execute.
160
+ * @param {Object} [options]
161
+ * @param {boolean} [options.once=true] - Execute only once.
162
+ * @param {number} [options.priority=0] - Higher priority runs first.
163
+ * @param {FnFilter|null} [options.filter=null] - Optional filter function.
164
+ * @param {boolean} [options.domOnly=false] - If true, executes after DOM ready only.
165
+ * @throws {TypeError} If fn is not a function.
166
+ */
167
+ onReady(fn, { once = true, priority = 0, filter = null, domOnly = false } = {}) {
168
+ if (typeof fn !== 'function')
169
+ throw new TypeError('[TinyDomReadyManager] fn must be a function.');
170
+
171
+ const handler = { fn, once, priority, filter, domOnly };
172
+
173
+ if (domOnly && this.#isDomReady) {
174
+ this.#invokeHandler(handler);
175
+ if (!once) this.#handlers.push(handler);
176
+ return;
177
+ }
178
+
179
+ if (!domOnly && this.#isFullyReady) {
180
+ this.#invokeHandler(handler);
181
+ } else {
182
+ this.#handlers.push(handler);
183
+ }
184
+ }
185
+
186
+ /**
187
+ * Returns whether the system is fully ready (DOM + Promises).
188
+ * @returns {boolean}
189
+ */
190
+ isReady() {
191
+ return this.#isFullyReady;
192
+ }
193
+
194
+ /**
195
+ * Returns whether the DOM is ready (DOMContentLoaded has fired).
196
+ * Does not wait for promises.
197
+ * @returns {boolean}
198
+ */
199
+ isDomReady() {
200
+ return this.#isDomReady;
201
+ }
202
+ }
203
+
204
+ /* harmony default export */ const libs_TinyDomReadyManager = (TinyDomReadyManager);
205
+
206
+ ;// ./src/v1/build/TinyDomReadyManager.mjs
207
+
208
+
209
+
210
+
211
+ window.TinyDomReadyManager = __webpack_exports__.TinyDomReadyManager;
212
+ /******/ })()
213
+ ;
@@ -0,0 +1 @@
1
+ (()=>{"use strict";var e={d:(r,i)=>{for(var a in i)e.o(i,a)&&!e.o(r,a)&&Object.defineProperty(r,a,{enumerable:!0,get:i[a]})},o:(e,r)=>Object.prototype.hasOwnProperty.call(e,r)},r={};e.d(r,{TinyDomReadyManager:()=>i});const i=class{#e=[];#r=!1;#i=!1;#a=[];#n(){this.#r&&Promise.all(this.#a).then((()=>{this.#i=!0,this.#o(!1)})).catch((e=>{console.error("[TinyDomReadyManager] Promise rejected:",e)}))}#o(e){this.#e.filter((r=>r.domOnly===e)).sort(((e,r)=>r.priority-e.priority)).forEach((e=>this.#t(e))),this.#e=this.#e.filter((r=>!(r.once&&(!e||r.domOnly))))}#t(e){if("function"==typeof e.filter)try{if(!e.filter())return}catch(e){return void console.warn("[TinyDomReadyManager] Filter error:",e)}try{e.fn()}catch(e){console.error("[TinyDomReadyManager] Handler error:",e)}}_markDomReady(){this.#r=!0,this.#o(!0),this.#n()}init(){if(this.#r)throw new Error("[TinyDomReadyManager] init() has already been called.");"interactive"===document.readyState||"complete"===document.readyState?this._markDomReady():document.addEventListener("DOMContentLoaded",(()=>this._markDomReady()))}addPromise(e){if(!(e instanceof Promise))throw new TypeError("[TinyDomReadyManager] promise must be a valid Promise.");this.#i||(this.#a.push(e),this.#r&&this.#n())}onReady(e,{once:r=!0,priority:i=0,filter:a=null,domOnly:n=!1}={}){if("function"!=typeof e)throw new TypeError("[TinyDomReadyManager] fn must be a function.");const o={fn:e,once:r,priority:i,filter:a,domOnly:n};if(n&&this.#r)return this.#t(o),void(r||this.#e.push(o));!n&&this.#i?this.#t(o):this.#e.push(o)}isReady(){return this.#i}isDomReady(){return this.#r}};window.TinyDomReadyManager=r.TinyDomReadyManager})();
@@ -2886,6 +2886,7 @@ __webpack_require__.r(__webpack_exports__);
2886
2886
  // EXPORTS
2887
2887
  __webpack_require__.d(__webpack_exports__, {
2888
2888
  ColorSafeStringify: () => (/* reexport */ libs_ColorSafeStringify),
2889
+ TinyDomReadyManager: () => (/* reexport */ libs_TinyDomReadyManager),
2889
2890
  TinyDragDropDetector: () => (/* reexport */ libs_TinyDragDropDetector),
2890
2891
  TinyDragger: () => (/* reexport */ libs_TinyDragger),
2891
2892
  TinyLevelUp: () => (/* reexport */ userLevel),
@@ -8200,6 +8201,180 @@ class TinyDragger {
8200
8201
 
8201
8202
  /* harmony default export */ const libs_TinyDragger = (TinyDragger);
8202
8203
 
8204
+ ;// ./src/v1/libs/TinyDomReadyManager.mjs
8205
+ /**
8206
+ * A basic function that performs a task when the system is ready.
8207
+ * Used for handlers in the readiness queue.
8208
+ *
8209
+ * @typedef {() => void} Fn
8210
+ */
8211
+
8212
+ /**
8213
+ * A function that determines whether a specific handler should be executed.
8214
+ * Should return `true` to allow execution, or `false` to skip the handler.
8215
+ *
8216
+ * @typedef {() => boolean} FnFilter
8217
+ */
8218
+
8219
+ /**
8220
+ * @typedef {Object} Handler
8221
+ * @property {Fn} fn - Function to execute when ready.
8222
+ * @property {boolean} once - Whether to execute only once.
8223
+ * @property {number} priority - Execution order (higher priority runs first).
8224
+ * @property {FnFilter|null} filter - Optional filter function to determine execution.
8225
+ * @property {boolean} domOnly - Whether to run as soon as DOM is ready (before full readiness).
8226
+ */
8227
+
8228
+ class TinyDomReadyManager {
8229
+ /** @type {Handler[]} */
8230
+ #handlers = [];
8231
+
8232
+ /** @type {boolean} */
8233
+ #isDomReady = false;
8234
+
8235
+ /** @type {boolean} */
8236
+ #isFullyReady = false;
8237
+
8238
+ /** @type {Promise<any>[]} */
8239
+ #promises = [];
8240
+
8241
+ /**
8242
+ * Checks if the DOM is ready and if all Promises have been resolved.
8243
+ */
8244
+ #checkAllReady() {
8245
+ if (this.#isDomReady) {
8246
+ Promise.all(this.#promises)
8247
+ .then(() => {
8248
+ this.#isFullyReady = true;
8249
+ this.#runHandlers(false); // run non-domOnly
8250
+ })
8251
+ .catch((err) => {
8252
+ console.error('[TinyDomReadyManager] Promise rejected:', err);
8253
+ });
8254
+ }
8255
+ }
8256
+
8257
+ /**
8258
+ * Executes handlers by filtering them by `domOnly` flag and sorting by priority.
8259
+ * @param {boolean} domOnlyOnly - Whether to run only `domOnly` handlers.
8260
+ */
8261
+ #runHandlers(domOnlyOnly) {
8262
+ this.#handlers
8263
+ .filter((h) => h.domOnly === domOnlyOnly)
8264
+ .sort((a, b) => b.priority - a.priority)
8265
+ .forEach((handler) => this.#invokeHandler(handler));
8266
+
8267
+ this.#handlers = this.#handlers.filter((h) => !(h.once && (domOnlyOnly ? h.domOnly : true)));
8268
+ }
8269
+
8270
+ /**
8271
+ * Executes a handler if its filter passes.
8272
+ * @param {Handler} handler
8273
+ */
8274
+ #invokeHandler(handler) {
8275
+ if (typeof handler.filter === 'function') {
8276
+ try {
8277
+ if (!handler.filter()) return;
8278
+ } catch (err) {
8279
+ console.warn('[TinyDomReadyManager] Filter error:', err);
8280
+ return;
8281
+ }
8282
+ }
8283
+
8284
+ try {
8285
+ handler.fn();
8286
+ } catch (err) {
8287
+ console.error('[TinyDomReadyManager] Handler error:', err);
8288
+ }
8289
+ }
8290
+
8291
+ /**
8292
+ * Marks the system as DOM-ready and runs DOM-only handlers.
8293
+ * @private
8294
+ */
8295
+ _markDomReady() {
8296
+ this.#isDomReady = true;
8297
+ this.#runHandlers(true); // Run domOnly
8298
+ this.#checkAllReady(); // Then check for full readiness
8299
+ }
8300
+
8301
+ /**
8302
+ * Initializes the manager using `DOMContentLoaded`.
8303
+ */
8304
+ init() {
8305
+ if (this.#isDomReady) throw new Error('[TinyDomReadyManager] init() has already been called.');
8306
+
8307
+ if (document.readyState === 'interactive' || document.readyState === 'complete') {
8308
+ this._markDomReady();
8309
+ } else {
8310
+ document.addEventListener('DOMContentLoaded', () => this._markDomReady());
8311
+ }
8312
+ }
8313
+
8314
+ /**
8315
+ * Adds a Promise to delay full readiness.
8316
+ * @param {Promise<any>} promise
8317
+ * @throws {TypeError}
8318
+ */
8319
+ addPromise(promise) {
8320
+ if (!(promise instanceof Promise))
8321
+ throw new TypeError('[TinyDomReadyManager] promise must be a valid Promise.');
8322
+
8323
+ if (this.#isFullyReady) return;
8324
+ this.#promises.push(promise);
8325
+ if (this.#isDomReady) this.#checkAllReady();
8326
+ }
8327
+
8328
+ /**
8329
+ * Registers a handler to run either after DOM is ready or after full readiness.
8330
+ *
8331
+ * @param {Fn} fn - Function to execute.
8332
+ * @param {Object} [options]
8333
+ * @param {boolean} [options.once=true] - Execute only once.
8334
+ * @param {number} [options.priority=0] - Higher priority runs first.
8335
+ * @param {FnFilter|null} [options.filter=null] - Optional filter function.
8336
+ * @param {boolean} [options.domOnly=false] - If true, executes after DOM ready only.
8337
+ * @throws {TypeError} If fn is not a function.
8338
+ */
8339
+ onReady(fn, { once = true, priority = 0, filter = null, domOnly = false } = {}) {
8340
+ if (typeof fn !== 'function')
8341
+ throw new TypeError('[TinyDomReadyManager] fn must be a function.');
8342
+
8343
+ const handler = { fn, once, priority, filter, domOnly };
8344
+
8345
+ if (domOnly && this.#isDomReady) {
8346
+ this.#invokeHandler(handler);
8347
+ if (!once) this.#handlers.push(handler);
8348
+ return;
8349
+ }
8350
+
8351
+ if (!domOnly && this.#isFullyReady) {
8352
+ this.#invokeHandler(handler);
8353
+ } else {
8354
+ this.#handlers.push(handler);
8355
+ }
8356
+ }
8357
+
8358
+ /**
8359
+ * Returns whether the system is fully ready (DOM + Promises).
8360
+ * @returns {boolean}
8361
+ */
8362
+ isReady() {
8363
+ return this.#isFullyReady;
8364
+ }
8365
+
8366
+ /**
8367
+ * Returns whether the DOM is ready (DOMContentLoaded has fired).
8368
+ * Does not wait for promises.
8369
+ * @returns {boolean}
8370
+ */
8371
+ isDomReady() {
8372
+ return this.#isDomReady;
8373
+ }
8374
+ }
8375
+
8376
+ /* harmony default export */ const libs_TinyDomReadyManager = (TinyDomReadyManager);
8377
+
8203
8378
  ;// ./src/v1/index.mjs
8204
8379
 
8205
8380
 
@@ -8224,6 +8399,7 @@ class TinyDragger {
8224
8399
 
8225
8400
 
8226
8401
 
8402
+
8227
8403
 
8228
8404
 
8229
8405
  })();