tiny-essentials 1.20.0 → 1.20.2

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 (55) hide show
  1. package/README.md +5 -0
  2. package/dist/v1/TinyBasicsEs.min.js +1 -1
  3. package/dist/v1/TinyDragger.min.js +1 -1
  4. package/dist/v1/TinyEssentials.min.js +1 -1
  5. package/dist/v1/TinyHtml.min.js +1 -1
  6. package/dist/v1/TinySmartScroller.min.js +1 -1
  7. package/dist/v1/TinyUploadClicker.min.js +1 -1
  8. package/dist/v1/basics/html.cjs +33 -2
  9. package/dist/v1/basics/html.d.mts +14 -4
  10. package/dist/v1/basics/html.mjs +27 -2
  11. package/dist/v1/basics/index.cjs +2 -0
  12. package/dist/v1/basics/index.d.mts +3 -1
  13. package/dist/v1/basics/index.mjs +3 -3
  14. package/dist/v1/basics/simpleMath.cjs +23 -4
  15. package/dist/v1/basics/simpleMath.d.mts +18 -4
  16. package/dist/v1/basics/simpleMath.mjs +22 -4
  17. package/dist/v1/index.cjs +2 -0
  18. package/dist/v1/index.d.mts +3 -1
  19. package/dist/v1/index.mjs +3 -3
  20. package/dist/v1/libs/TinyDragger.cjs +1 -1
  21. package/dist/v1/libs/TinyDragger.mjs +1 -1
  22. package/dist/v1/libs/TinyHtml.cjs +500 -105
  23. package/dist/v1/libs/TinyHtml.d.mts +251 -42
  24. package/dist/v1/libs/TinyHtml.mjs +448 -96
  25. package/dist/v1/libs/TinyIframeEvents.cjs +2 -1
  26. package/dist/v1/libs/TinyNewWinEvents.cjs +4 -2
  27. package/docs/v1/basics/html.md +78 -22
  28. package/docs/v1/basics/simpleMath.md +22 -4
  29. package/docs/v1/libs/TinyHtml.md +268 -6
  30. package/package.json +1 -1
  31. package/dist/v1/ColorSafeStringify.js +0 -235
  32. package/dist/v1/TinyAfterScrollWatcher.js +0 -219
  33. package/dist/v1/TinyBasicsEs.js +0 -9334
  34. package/dist/v1/TinyClipboard.js +0 -459
  35. package/dist/v1/TinyColorConverter.js +0 -617
  36. package/dist/v1/TinyDomReadyManager.js +0 -213
  37. package/dist/v1/TinyDragDropDetector.js +0 -307
  38. package/dist/v1/TinyDragger.js +0 -6569
  39. package/dist/v1/TinyEssentials.js +0 -20792
  40. package/dist/v1/TinyEvents.js +0 -402
  41. package/dist/v1/TinyHtml.js +0 -5545
  42. package/dist/v1/TinyIframeEvents.js +0 -854
  43. package/dist/v1/TinyLevelUp.js +0 -291
  44. package/dist/v1/TinyLocalStorage.js +0 -1440
  45. package/dist/v1/TinyNewWinEvents.js +0 -888
  46. package/dist/v1/TinyNotifications.js +0 -408
  47. package/dist/v1/TinyNotifyCenter.js +0 -493
  48. package/dist/v1/TinyPromiseQueue.js +0 -299
  49. package/dist/v1/TinyRateLimiter.js +0 -611
  50. package/dist/v1/TinySmartScroller.js +0 -7039
  51. package/dist/v1/TinyTextRangeEditor.js +0 -497
  52. package/dist/v1/TinyTimeout.js +0 -233
  53. package/dist/v1/TinyToastNotify.js +0 -441
  54. package/dist/v1/TinyUploadClicker.js +0 -14353
  55. package/dist/v1/UltraRandomMsgGen.js +0 -995
@@ -1,233 +0,0 @@
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
- TinyTimeout: () => (/* reexport */ libs_TinyTimeout)
30
- });
31
-
32
- ;// ./src/v1/libs/TinyTimeout.mjs
33
- /**
34
- * A utility class to manage dynamically adjusted timeouts based on how often
35
- * each unique ID is triggered. Also provides polling support for asynchronous conditions.
36
- */
37
- class TinyTimeout {
38
- /** @type {boolean} Whether this instance has been destroyed. */
39
- #isDestroyed = false;
40
-
41
- /** @type {boolean} Whether to allow auto-updating an ID's timeout config if `value` changes. */
42
- #allowAutoConfigChange;
43
-
44
- /** @type {number} The interval time (ms) used to decrement cooldown counters. */
45
- #cooldownWatcherTime;
46
-
47
- /** @type {NodeJS.Timeout|null} Reference to the internal cooldown interval. */
48
- #cooldownWatcher = null;
49
-
50
- /**
51
- * Internal map that keeps track of how many times each ID has been triggered,
52
- * along with the base multiplier used to calculate delays.
53
- *
54
- * @type {Map<string, { value: number, now: number }>}
55
- */
56
- #timeoutFixer = new Map();
57
-
58
- /**
59
- * Creates a new instance of TinyTimeout.
60
- *
61
- * @param {Object} [options={}] Optional configuration object.
62
- * @param {number} [options.cooldownWatcherTime=5000] Interval in milliseconds for reducing `now` counters.
63
- * @param {boolean} [options.allowAutoConfigChange=false] Whether to allow auto value changes for existing IDs.
64
- */
65
- constructor({ cooldownWatcherTime = 5000, allowAutoConfigChange = false } = {}) {
66
- if (!Number.isFinite(cooldownWatcherTime) || cooldownWatcherTime <= 0)
67
- throw new TypeError(`Expected 'cooldownWatcherTime' to be a positive number.`);
68
- if (typeof allowAutoConfigChange !== 'boolean')
69
- throw new TypeError(`Expected 'allowAutoConfigChange' to be a boolean.`);
70
- this.#cooldownWatcherTime = cooldownWatcherTime;
71
- this.#allowAutoConfigChange = allowAutoConfigChange;
72
- this.setCooldownWatcherTime(cooldownWatcherTime);
73
- }
74
-
75
- /**
76
- * Whether this instance has been destroyed and is no longer usable.
77
- *
78
- * @returns {boolean}
79
- */
80
- isDestroyed() {
81
- return this.#isDestroyed;
82
- }
83
-
84
- /**
85
- * Whether auto config change is enabled.
86
- *
87
- * @returns {boolean}
88
- */
89
- getAllowAutoConfigChange() {
90
- return this.#allowAutoConfigChange;
91
- }
92
-
93
- /**
94
- * Gets the interval time used for cooldown decrementing.
95
- *
96
- * @returns {number}
97
- */
98
- getCooldownWatcherTime() {
99
- return this.#cooldownWatcherTime;
100
- }
101
-
102
- /**
103
- * Sets whether to allow auto-updating an ID's timeout config if `value` changes.
104
- *
105
- * @param {boolean} value
106
- */
107
- setAllowAutoConfigChange(value) {
108
- if (typeof value !== 'boolean') throw new TypeError(`Expected 'value' to be a boolean.`);
109
- this.#allowAutoConfigChange = value;
110
- }
111
-
112
- /**
113
- * Sets the cooldown watcher interval time.
114
- * Automatically resets the interval if it was already running.
115
- *
116
- * @param {number} value
117
- */
118
- setCooldownWatcherTime(value) {
119
- if (this.#isDestroyed) throw new Error('TinyTimeout has been destroyed.');
120
- if (!Number.isFinite(value) || value <= 0)
121
- throw new TypeError(`Expected 'value' to be a positive number.`);
122
-
123
- this.#cooldownWatcherTime = value;
124
-
125
- if (this.#cooldownWatcher) clearInterval(this.#cooldownWatcher);
126
- this.#cooldownWatcher = setInterval(() => {
127
- this.#timeoutFixer.forEach((data) => {
128
- if (data.now > 0) data.now--;
129
- });
130
- }, this.#cooldownWatcherTime);
131
- }
132
-
133
- /**
134
- * Schedules a callback using a dynamically adjusted timeout based on usage frequency.
135
- * The more often an ID is triggered, the longer the timeout becomes,
136
- * scaled by the provided `value`. Optionally, the delay can be limited by `limit`.
137
- *
138
- * @param {string} id - A unique identifier to track timeout usage.
139
- * @param {Function} callback - The function to execute after the delay.
140
- * @param {number} value - Base delay multiplier in milliseconds.
141
- * @param {number|null} [limit=null] - Optional maximum delay cap.
142
- * @returns {number} Handle to the scheduled timeout.
143
- * @throws {Error} Throws if the instance has been destroyed or arguments are invalid.
144
- */
145
- set(id, callback, value, limit = null) {
146
- if (this.#isDestroyed) throw new Error('TinyTimeout has been destroyed.');
147
- if (typeof id !== 'string' || id.trim() === '')
148
- throw new TypeError(`Expected 'id' to be a non-empty string.`);
149
- if (typeof callback !== 'function')
150
- throw new TypeError(`Expected 'callback' to be a function.`);
151
- if (!Number.isFinite(value) || value < 0)
152
- throw new TypeError(`Expected 'value' to be a non-negative number.`);
153
- if (limit !== null && (!Number.isFinite(limit) || limit < 0))
154
- throw new TypeError(`Expected 'limit' to be null or a non-negative number.`);
155
-
156
- let entry = this.#timeoutFixer.get(id);
157
- if (!entry || (this.#allowAutoConfigChange && value !== entry.value)) {
158
- entry = { value, now: 0 };
159
- this.#timeoutFixer.set(id, entry);
160
- }
161
-
162
- const delay = entry.value * entry.now;
163
- entry.now++;
164
-
165
- return setTimeout(callback, typeof limit === 'number' ? Math.min(delay, limit) : delay);
166
- }
167
-
168
- /**
169
- * Waits until a provided function returns `true`, checking repeatedly at the defined interval.
170
- * Useful for polling asynchronous conditions.
171
- *
172
- * @param {() => boolean} getValue - A function that returns `true` when the condition is met.
173
- * @param {number} [checkInterval=100] - How often (in ms) to check the condition.
174
- * @returns {Promise<void>} Resolves when the condition is met.
175
- * @throws {TypeError} If arguments are invalid.
176
- */
177
- static waitForTrue(getValue, checkInterval = 100) {
178
- if (typeof getValue !== 'function')
179
- throw new TypeError(`Expected 'getValue' to be a function.`);
180
- if (!Number.isFinite(checkInterval) || checkInterval <= 0)
181
- throw new TypeError(`Expected 'checkInterval' to be a positive number.`);
182
-
183
- return new Promise((resolve) => {
184
- const interval = setInterval(() => {
185
- if (getValue()) {
186
- clearInterval(interval);
187
- resolve();
188
- }
189
- }, checkInterval);
190
- });
191
- }
192
-
193
- /**
194
- * Instance version of `waitForTrue`, which defaults to using the instance's
195
- * cooldownWatcherTime if not explicitly provided.
196
- *
197
- * @param {() => boolean} getValue - A function that returns `true` when the condition is met.
198
- * @param {number|null} [checkInterval=100] - How often (in ms) to check the condition.
199
- * @returns {Promise<void>} Resolves when the condition is met.
200
- * @throws {Error} If the instance is destroyed or arguments are invalid.
201
- */
202
- waitForTrue(getValue, checkInterval = 100) {
203
- if (this.#isDestroyed) throw new Error('TinyTimeout has been destroyed.');
204
- if (typeof getValue !== 'function')
205
- throw new TypeError(`Expected 'getValue' to be a function.`);
206
- if (checkInterval !== null && (!Number.isFinite(checkInterval) || checkInterval <= 0))
207
- throw new TypeError(`Expected 'checkInterval' to be null or a positive number.`);
208
- return TinyTimeout.waitForTrue(getValue, checkInterval ?? this.#cooldownWatcherTime);
209
- }
210
-
211
- /**
212
- * Cleans up all internal references and stops the cooldown watcher.
213
- * After calling this, the instance becomes unusable.
214
- */
215
- destroy() {
216
- if (this.#isDestroyed) return;
217
- this.#isDestroyed = true;
218
- if (this.#cooldownWatcher) clearInterval(this.#cooldownWatcher);
219
- this.#cooldownWatcher = null;
220
- this.#timeoutFixer.clear();
221
- }
222
- }
223
-
224
- /* harmony default export */ const libs_TinyTimeout = (TinyTimeout);
225
-
226
- ;// ./src/v1/build/TinyTimeout.mjs
227
-
228
-
229
-
230
-
231
- window.TinyTimeout = __webpack_exports__.TinyTimeout;
232
- /******/ })()
233
- ;
@@ -1,441 +0,0 @@
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
- TinyToastNotify: () => (/* reexport */ libs_TinyToastNotify)
30
- });
31
-
32
- ;// ./src/v1/libs/TinyToastNotify.mjs
33
- /**
34
- * A callback function used to manually close a notification.
35
- * Passed as a second argument to `onClick` handlers, allowing programmatic dismissal of the toast.
36
- *
37
- * @typedef {() => void} CloseToastFunc
38
- */
39
-
40
- /**
41
- * Represents the data used to display a notification.
42
- * Can be a plain string (used as the message), or an object with more customization options.
43
- *
44
- * @typedef {string | {
45
- * message: string, // The main message to display
46
- * title?: string, // Optional title to appear above the message
47
- * onClick?: function(MouseEvent, CloseToastFunc): void, // Optional click handler for the notification
48
- * html?: boolean, // Whether the message should be interpreted as raw HTML
49
- * avatar?: string // Optional URL to an avatar image shown on the left
50
- * }} NotifyData
51
- */
52
-
53
- /**
54
- * A lightweight notification system designed to display timed messages inside a container.
55
- * Supports positioning, timing customization, click actions, HTML content, and optional avatars.
56
- *
57
- * ## Features:
58
- * - Positioning via `x` (`left`, `center`, `right`) and `y` (`top`, `bottom`).
59
- * - Dynamic display time based on message length.
60
- * - Optional `title`, `avatar`, `onClick`, and `html` message rendering.
61
- * - Fade-out animation with customizable duration.
62
- * - Rigid validation of inputs and internal state.
63
- *
64
- * ## Customization via setters:
65
- * - `setX(position)` — horizontal alignment.
66
- * - `setY(position)` — vertical alignment.
67
- * - `setBaseDuration(ms)` — base visible time in milliseconds.
68
- * - `setExtraPerChar(ms)` — extra time added per character.
69
- * - `setFadeOutDuration(ms)` — fade-out animation duration in milliseconds.
70
- *
71
- * @class
72
- */
73
- class TinyToastNotify {
74
- #y;
75
- #x;
76
- #baseDuration;
77
- #extraPerChar;
78
- #fadeOutDuration;
79
-
80
- /** @type {HTMLElement|null} */
81
- #container;
82
-
83
- /**
84
- * @param {'top'|'bottom'} y - 'top' or 'bottom'
85
- * @param {'right'|'left'|'center'} x - 'right', 'left', or 'center'
86
- * @param {number} baseDuration - Base display time in ms
87
- * @param {number} extraPerChar - Extra ms per character
88
- * @param {number} fadeOutDuration - Time in ms for fade-out effect
89
- * @param {string} [selector='.notify-container'] - Base selector for container
90
- */
91
- constructor(
92
- y = 'top',
93
- x = 'right',
94
- baseDuration = 3000,
95
- extraPerChar = 50,
96
- fadeOutDuration = 300,
97
- selector = '.notify-container',
98
- ) {
99
- this.#validateY(y);
100
- this.#validateX(x);
101
- this.#validateTiming(baseDuration, 'baseDuration');
102
- this.#validateTiming(extraPerChar, 'extraPerChar');
103
- this.#validateTiming(fadeOutDuration, 'fadeOutDuration');
104
-
105
- this.#y = y;
106
- this.#x = x;
107
- this.#baseDuration = baseDuration;
108
- this.#extraPerChar = extraPerChar;
109
- this.#fadeOutDuration = fadeOutDuration;
110
- const container = document.querySelector(`${selector}.${y}.${x}`);
111
-
112
- if (!(container instanceof HTMLElement)) {
113
- this.#container = document.createElement('div');
114
- this.#container.className = `notify-container ${y} ${x}`;
115
- document.body.appendChild(this.#container);
116
- } else this.#container = container;
117
- }
118
-
119
- /**
120
- * Returns the notification container element.
121
- * Ensures that the container is a valid HTMLElement.
122
- *
123
- * @returns {HTMLElement} The notification container.
124
- * @throws {Error} If the container is not a valid HTMLElement.
125
- */
126
- getContainer() {
127
- if (!(this.#container instanceof HTMLElement))
128
- throw new Error('Container is not a valid HTMLElement.');
129
- return this.#container;
130
- }
131
-
132
- /**
133
- * Validates the vertical position value.
134
- * Must be either 'top' or 'bottom'.
135
- *
136
- * @param {string} value - The vertical position to validate.
137
- * @throws {Error} If the value is not 'top' or 'bottom'.
138
- */
139
- #validateY(value) {
140
- if (!['top', 'bottom'].includes(value)) {
141
- throw new Error(`Invalid vertical direction "${value}". Expected "top" or "bottom".`);
142
- }
143
- }
144
-
145
- /**
146
- * Validates the horizontal position value.
147
- * Must be 'left', 'right', or 'center'.
148
- *
149
- * @param {string} value - The horizontal position to validate.
150
- * @throws {Error} If the value is not one of the accepted directions.
151
- */
152
- #validateX(value) {
153
- if (!['left', 'right', 'center'].includes(value)) {
154
- throw new Error(
155
- `Invalid horizontal position "${value}". Expected "left", "right" or "center".`,
156
- );
157
- }
158
- }
159
-
160
- /**
161
- * Validates a numeric timing value.
162
- * Must be a non-negative finite number.
163
- *
164
- * @param {number} value - The number to validate.
165
- * @param {string} name - The name of the parameter (used for error messaging).
166
- * @throws {Error} If the number is invalid.
167
- */
168
- #validateTiming(value, name) {
169
- if (typeof value !== 'number' || value < 0 || !Number.isFinite(value)) {
170
- throw new Error(
171
- `Invalid value for "${name}": ${value}. Must be a non-negative finite number.`,
172
- );
173
- }
174
- }
175
-
176
- /**
177
- * Returns the current vertical position.
178
- *
179
- * @returns {'top'|'bottom'} The vertical direction of the notification container.
180
- */
181
- getY() {
182
- return this.#y;
183
- }
184
-
185
- /**
186
- * Sets the vertical position of the notification container.
187
- * Updates the container's class to reflect the new position.
188
- *
189
- * @param {'top'|'bottom'} value - The vertical direction to set.
190
- * @throws {Error} If the value is invalid.
191
- */
192
- setY(value) {
193
- this.#validateY(value);
194
- const container = this.getContainer();
195
- container.classList.remove(this.#y);
196
- container.classList.add(value);
197
-
198
- this.#y = value;
199
- }
200
-
201
- /**
202
- * Returns the current horizontal position.
203
- *
204
- * @returns {'left'|'right'|'center'} The horizontal direction of the notification container.
205
- */
206
- getX() {
207
- return this.#x;
208
- }
209
-
210
- /**
211
- * Sets the horizontal position of the notification container.
212
- * Updates the container's class to reflect the new position.
213
- *
214
- * @param {'left'|'right'|'center'} value - The horizontal direction to set.
215
- * @throws {Error} If the value is invalid.
216
- */
217
- setX(value) {
218
- this.#validateX(value);
219
- const container = this.getContainer();
220
- container.classList.remove(this.#x);
221
- container.classList.add(value);
222
-
223
- this.#x = value;
224
- }
225
-
226
- /**
227
- * Returns the base duration for displaying the notification.
228
- *
229
- * @returns {number} Base time (in milliseconds) that a notification stays on screen.
230
- */
231
- getBaseDuration() {
232
- return this.#baseDuration;
233
- }
234
-
235
- /**
236
- * Sets the base duration for the notification display time.
237
- *
238
- * @param {number} value - Base display time in milliseconds.
239
- * @throws {Error} If the value is not a valid non-negative finite number.
240
- */
241
- setBaseDuration(value) {
242
- this.#validateTiming(value, 'baseDuration');
243
- this.#baseDuration = value;
244
- }
245
-
246
- /**
247
- * Returns the extra display time added per character.
248
- *
249
- * @returns {number} Extra time (in milliseconds) per character in the notification.
250
- */
251
- getExtraPerChar() {
252
- return this.#extraPerChar;
253
- }
254
-
255
- /**
256
- * Sets the additional display time per character.
257
- *
258
- * @param {number} value - Extra time in milliseconds per character.
259
- * @throws {Error} If the value is not a valid non-negative finite number.
260
- */
261
- setExtraPerChar(value) {
262
- this.#validateTiming(value, 'extraPerChar');
263
- this.#extraPerChar = value;
264
- }
265
-
266
- /**
267
- * Returns the fade-out duration.
268
- *
269
- * @returns {number} Time (in milliseconds) used for fade-out transition.
270
- */
271
- getFadeOutDuration() {
272
- return this.#fadeOutDuration;
273
- }
274
-
275
- /**
276
- * Sets the fade-out transition time for notifications.
277
- *
278
- * @param {number} value - Fade-out duration in milliseconds.
279
- * @throws {Error} If the value is not a valid non-negative finite number.
280
- */
281
- setFadeOutDuration(value) {
282
- this.#validateTiming(value, 'fadeOutDuration');
283
- this.#fadeOutDuration = value;
284
- }
285
-
286
- /**
287
- * Displays a notification for a time based on message length.
288
- * Accepts a string or an object with:
289
- * {
290
- * message: string,
291
- * title?: string,
292
- * onClick?: function(MouseEvent, CloseToastFunc): void,
293
- * html?: boolean,
294
- * avatar?: string // Optional avatar image URL
295
- * }
296
- *
297
- * @param {NotifyData} data
298
- */
299
- show(data) {
300
- let message = '';
301
- let title = '';
302
- let onClick = null;
303
- let useHTML = false;
304
- let avatarUrl = null;
305
-
306
- const notify = document.createElement('div');
307
- notify.className = 'notify enter';
308
-
309
- if (typeof data === 'string') {
310
- message = data;
311
- } else if (typeof data === 'object' && data !== null && typeof data.message === 'string') {
312
- message = data.message;
313
- title = typeof data.title === 'string' ? data.title : '';
314
- useHTML = data.html === true;
315
- avatarUrl = typeof data.avatar === 'string' ? data.avatar : null;
316
-
317
- if (data.onClick !== undefined) {
318
- if (typeof data.onClick !== 'function') {
319
- throw new Error('onClick must be a function if defined');
320
- }
321
- onClick = data.onClick;
322
- notify.classList.add('clickable');
323
- }
324
- } else {
325
- throw new Error(
326
- `Invalid argument for show(): expected string or { message: string, title?: string, onClick?: function, html?: boolean, avatar?: string }`,
327
- );
328
- }
329
-
330
- // Add close button
331
- const closeBtn = document.createElement('button');
332
- closeBtn.innerHTML = '&times;';
333
- closeBtn.className = 'close';
334
- closeBtn.setAttribute('aria-label', 'Close');
335
-
336
- // Optional hover effect
337
- closeBtn.addEventListener('mouseenter', () => {
338
- closeBtn.style.color = 'var(--notif-close-color-hover)';
339
- });
340
- closeBtn.addEventListener('mouseleave', () => {
341
- closeBtn.style.color = 'var(--notif-close-color)';
342
- });
343
-
344
- // Avatar
345
- if (avatarUrl) {
346
- const avatar = document.createElement('img');
347
- avatar.src = avatarUrl;
348
- avatar.alt = 'avatar';
349
- avatar.className = 'avatar';
350
- notify.appendChild(avatar);
351
- }
352
-
353
- // Title
354
- if (title) {
355
- const titleElem = document.createElement('strong');
356
- titleElem.textContent = title;
357
- titleElem.style.display = 'block';
358
- notify.appendChild(titleElem);
359
- }
360
-
361
- // Message
362
- if (useHTML) {
363
- const msgWrapper = document.createElement('div');
364
- msgWrapper.innerHTML = message;
365
- notify.appendChild(msgWrapper);
366
- } else {
367
- notify.appendChild(document.createTextNode(message));
368
- }
369
-
370
- notify.appendChild(closeBtn);
371
- this.getContainer().appendChild(notify);
372
-
373
- const visibleTime = this.#baseDuration + message.length * this.#extraPerChar;
374
- const totalTime = visibleTime + this.#fadeOutDuration;
375
-
376
- // Close logic
377
- let removed = false;
378
- const close = () => {
379
- if (removed) return;
380
- removed = true;
381
- notify.classList.remove('enter', 'show');
382
- notify.classList.add('exit');
383
- setTimeout(() => notify.remove(), this.#fadeOutDuration);
384
- };
385
-
386
- // Click handler
387
- if (typeof onClick === 'function') {
388
- notify.addEventListener('click', (e) => {
389
- if (e.target === closeBtn) return;
390
- onClick(e, close);
391
- });
392
- }
393
-
394
- // Close button click
395
- closeBtn.addEventListener('click', (e) => {
396
- e.stopPropagation();
397
- close();
398
- });
399
-
400
- // Transition activation force soon after the element is added
401
- setTimeout(() => {
402
- notify.classList.remove('enter');
403
- notify.classList.add('show');
404
- }, 1);
405
-
406
- setTimeout(() => close(), totalTime);
407
- }
408
-
409
- /**
410
- * Destroys the notification container and removes all active notifications.
411
- * This should be called when the notification system is no longer needed,
412
- * such as when unloading a page or switching views in a single-page app.
413
- *
414
- * @returns {void}
415
- */
416
- destroy() {
417
- if (!(this.#container instanceof HTMLElement)) return;
418
-
419
- // Remove all child notifications
420
- this.#container.querySelectorAll('.notify').forEach((el) => el.remove());
421
-
422
- // Remove the container itself from the DOM
423
- if (this.#container.parentNode) {
424
- this.#container.parentNode.removeChild(this.#container);
425
- }
426
-
427
- // Optional: Clean internal references (safe practice)
428
- this.#container = null;
429
- }
430
- }
431
-
432
- /* harmony default export */ const libs_TinyToastNotify = (TinyToastNotify);
433
-
434
- ;// ./src/v1/build/TinyToastNotify.mjs
435
-
436
-
437
-
438
-
439
- window.TinyToastNotify = __webpack_exports__.TinyToastNotify;
440
- /******/ })()
441
- ;