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,493 +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
- TinyNotifyCenter: () => (/* reexport */ libs_TinyNotifyCenter)
30
- });
31
-
32
- ;// ./src/v1/libs/TinyNotifyCenter.mjs
33
- /**
34
- * Represents a single notification entry.
35
- *
36
- * A notification can be provided as a simple string (treated as a plain message),
37
- * or as an object with additional data such as a title, an avatar image, and a click handler.
38
- *
39
- * @typedef {string | {
40
- * title?: string, // Optional title displayed above the message
41
- * message: string, // Required message content
42
- * avatar?: string, // Optional avatar image URL (displayed on the left)
43
- * onClick?: (e: MouseEvent) => void // Optional click handler for the entire notification
44
- * }} NotifyData
45
- */
46
-
47
- /**
48
- * A notification center component for displaying interactive alerts in the UI.
49
- *
50
- * This class renders a notification overlay on the page and allows dynamically
51
- * adding, clearing, or interacting with notification items. Notifications can
52
- * contain plain text or HTML, and optionally support click events, titles, and avatars.
53
- *
54
- * Features:
55
- * - Dynamic rendering of notification UI with `insertTemplate()`
56
- * - Supports text and HTML content modes
57
- * - Optional avatars for each notification
58
- * - Callback support on notification click
59
- * - Per-notification close buttons
60
- * - Notification count badge
61
- *
62
- * @class
63
- */
64
- class TinyNotifyCenter {
65
- /**
66
- * Returns the full HTML structure for the notification system as a string.
67
- *
68
- * This includes:
69
- * - A hidden `.notify-overlay` containing the central notification panel (`#notifCenter`),
70
- * which has a header with a "Notifications" label, a "clear all" button, and a close button.
71
- * - A `.list` container for dynamically added notifications.
72
- * - A bell button (`.notify-bell`) to toggle the notification center, with an embedded badge.
73
- *
74
- * This template can be inserted into the DOM using `insertAdjacentHTML()` or parsed dynamically
75
- * into elements using JavaScript or jQuery, depending on the needs of the system.
76
- *
77
- * @returns {string} The complete HTML structure for the notification center.
78
- */
79
- static getTemplate() {
80
- return `
81
- <div class="notify-overlay hidden">
82
- <div class="notify-center" id="notifCenter">
83
- <div class="header">
84
- <div>Notifications</div>
85
- <div class="options">
86
- <button class="clear-all" type="button">
87
- <svg
88
- xmlns="http://www.w3.org/2000/svg"
89
- viewBox="0 0 24 24"
90
- width="24"
91
- height="24"
92
- fill="currentColor"
93
- >
94
- <path
95
- d="M21.6 2.4a1 1 0 0 0-1.4 0L13 9.6l-1.3-1.3a1 1 0 0 0-1.4 0L3 15.6a1 1 0 0 0 0 1.4l4 4a1 1 0 0 0 1.4 0l7.3-7.3a1 1 0 0 0 0-1.4l-1.3-1.3 7.2-7.2a1 1 0 0 0 0-1.4zM6 17l3.5-3.5 1.5 1.5L7.5 18.5 6 17z"
96
- />
97
- </svg>
98
- </button>
99
- <button class="close">×</button>
100
- </div>
101
- </div>
102
- <div class="list"></div>
103
- </div>
104
- </div>
105
-
106
- <button class="notify-bell" aria-label="Open notifications">
107
- <svg
108
- xmlns="http://www.w3.org/2000/svg"
109
- width="20"
110
- height="20"
111
- fill="currentColor"
112
- viewBox="0 0 24 24"
113
- >
114
- <path
115
- d="M12 2C10.3 2 9 3.3 9 5v1.1C6.7 7.2 5 9.4 5 12v5l-1 1v1h16v-1l-1-1v-5c0-2.6-1.7-4.8-4-5.9V5c0-1.7-1.3-3-3-3zm0 20c1.1 0 2-.9 2-2h-4c0 1.1.9 2 2 2z"
116
- />
117
- </svg>
118
- <span class="badge" id="notifBadge">0</span>
119
- </button>
120
- `;
121
- }
122
-
123
- /**
124
- * Inserts the full notification center template into the document body.
125
- *
126
- * The structure is injected directly into the DOM using
127
- * `insertAdjacentHTML`.
128
- *
129
- * The `where` parameter allows control over where inside the `document.body`
130
- * the HTML is inserted:
131
- * - `'afterbegin'` (default): Inserts right after the opening <body> tag.
132
- * - `'beforeend'`: Inserts right before the closing </body> tag.
133
- * - Any valid position accepted by `insertAdjacentHTML`.
134
- *
135
- * @param {'beforebegin'|'afterbegin'|'beforeend'|'afterend'} [where='afterbegin']
136
- * The position relative to `document.body` where the HTML should be inserted.
137
- */
138
- static insertTemplate(where = 'afterbegin') {
139
- document.body.insertAdjacentHTML(where, TinyNotifyCenter.getTemplate());
140
- }
141
-
142
- /** @type {HTMLElement} */
143
- #center;
144
- /** @type {HTMLElement} */
145
- #list;
146
- /** @type {HTMLElement} */
147
- #badge;
148
- /** @type {HTMLElement} */
149
- #button;
150
- /** @type {HTMLElement} */
151
- #overlay;
152
-
153
- #count = 0;
154
- #maxCount = 99;
155
- #removeDelay = 300;
156
- #markAllAsReadOnClose = false;
157
- #modes = new WeakMap();
158
-
159
- /** @param {HTMLElement|ChildNode} item */
160
- #removeItem(item) {
161
- this.#modes.delete(item);
162
- if (item instanceof HTMLElement) {
163
- item.classList.add('removing');
164
-
165
- setTimeout(() => {
166
- this.markAsRead(item);
167
- item.remove();
168
- }, this.#removeDelay);
169
- } else throw new Error('Invalid HTMLElement to clear.');
170
- }
171
-
172
- /**
173
- * Update notify count and badge.
174
- * @param {number} value
175
- */
176
- #updateCount(value) {
177
- this.#count = Math.max(0, value);
178
- this.#badge.setAttribute('data-value', String(this.#count));
179
- this.#badge.textContent =
180
- this.#count > this.#maxCount ? `${this.#maxCount}+` : String(this.#count);
181
- }
182
-
183
- /**
184
- * Options for configuring the NotificationCenter instance.
185
- *
186
- * Allows manual specification of the main elements used by the notification center.
187
- * If not provided, default elements will be selected from the DOM automatically.
188
- *
189
- * @param {Object} options - Configuration object.
190
- * @param {HTMLElement} [options.center=document.getElementById('notifCenter')] - The container element that holds the list of notifications.
191
- * @param {HTMLElement} [options.badge=document.getElementById('notifBadge')] - The badge element used to display the current notification count.
192
- * @param {HTMLElement} [options.button=document.querySelector('.notify-bell')] - The button element that toggles the notification center.
193
- * @param {HTMLElement} [options.overlay=document.querySelector('.notify-overlay')] - The overlay element that covers the screen when the center is visible.
194
- */
195
- constructor(options = {}) {
196
- const {
197
- center = document.getElementById('notifCenter'),
198
- badge = document.getElementById('notifBadge'),
199
- button = document.querySelector('.notify-bell'),
200
- overlay = document.querySelector('.notify-overlay'),
201
- } = options;
202
-
203
- // Element existence and type validation
204
- if (!(center instanceof HTMLElement))
205
- throw new Error(`NotificationCenter: "center" must be an HTMLElement. Got: ${center}`);
206
- if (!(overlay instanceof HTMLElement))
207
- throw new Error(`NotificationCenter: "overlay" must be an HTMLElement. Got: ${overlay}`);
208
- if (!(badge instanceof HTMLElement))
209
- throw new Error(`NotificationCenter: "badge" must be an HTMLElement. Got: ${badge}`);
210
- if (!(button instanceof HTMLElement))
211
- throw new Error(`NotificationCenter: "button" must be an HTMLElement. Got: ${button}`);
212
-
213
- const clearAllBtn = center?.querySelector('.clear-all');
214
- const list = center?.querySelector('.list') ?? null;
215
- if (!(list instanceof HTMLElement))
216
- throw new Error(
217
- `NotificationCenter: ".list" inside center must be an HTMLElement. Got: ${list}`,
218
- );
219
-
220
- this.#center = center;
221
- this.#list = list;
222
- this.#badge = badge;
223
- this.#button = button;
224
- this.#overlay = overlay;
225
-
226
- this.#button.addEventListener('click', () => this.toggle());
227
- this.#center.querySelector('.close')?.addEventListener('click', () => this.close());
228
- if (clearAllBtn) clearAllBtn.addEventListener('click', () => this.clear());
229
- this.#overlay.addEventListener('click', (e) => {
230
- if (e.target === this.#overlay) this.close();
231
- });
232
- }
233
-
234
- /**
235
- * Enable or disable automatic mark-as-read on close.
236
- * @param {boolean} value
237
- */
238
- setMarkAllAsReadOnClose(value) {
239
- if (typeof value !== 'boolean')
240
- throw new TypeError(`Expected boolean for markAllAsReadOnClose, got ${typeof value}`);
241
- this.#markAllAsReadOnClose = value;
242
- }
243
-
244
- /**
245
- * Define how long the remove animation takes (in ms).
246
- * @param {number} ms
247
- */
248
- setRemoveDelay(ms) {
249
- if (typeof ms !== 'number') throw new Error(`NotificationCenter: "ms" must be an number.`);
250
- this.#removeDelay = ms;
251
- }
252
-
253
- /**
254
- * Get rendering mode ('text' or 'html') by index.
255
- * @param {number} index
256
- * @returns {'text' | 'html' | null}
257
- */
258
- getItemMode(index) {
259
- const item = this.getItem(index);
260
- return item ? this.#modes.get(item) : null;
261
- }
262
-
263
- /**
264
- * Get a notify element by index.
265
- * @param {number} index
266
- * @returns {HTMLElement}
267
- */
268
- getItem(index) {
269
- const element = this.#list.children.item(index);
270
- if (!(element instanceof HTMLElement))
271
- throw new Error(`NotificationCenter: "item" must be an HTMLElement. Got: ${element}`);
272
- return element;
273
- }
274
-
275
- /**
276
- * Check if a notify exists at the given index.
277
- * @param {number} index
278
- * @returns {boolean}
279
- */
280
- hasItem(index) {
281
- return index >= 0 && index < this.#list.children.length;
282
- }
283
-
284
- /**
285
- * Mark a notification index as read.
286
- * @param {number|HTMLElement} index
287
- */
288
- markAsRead(index) {
289
- const item = index instanceof HTMLElement ? index : this.getItem(index);
290
- if (item.classList.contains('unread')) {
291
- item.classList.remove('unread');
292
- this.#updateCount(this.#count - 1);
293
- }
294
- }
295
-
296
- /**
297
- * Add a new notify to the center.
298
- *
299
- * @param {NotifyData} message - Notification content or a full object with title, avatar, and callback.
300
- * @param {'text'|'html'} [mode='text'] - How to treat the message content.
301
- */
302
- add(message, mode = 'text') {
303
- const item = document.createElement('div');
304
- item.className = 'item unread';
305
-
306
- let titleText = null;
307
- let messageText = null;
308
- let avatarUrl = null;
309
- let onClick = null;
310
-
311
- if (typeof message === 'object' && message !== null) {
312
- titleText = message.title;
313
- messageText = message.message;
314
- avatarUrl = message.avatar;
315
- onClick = message.onClick;
316
- } else {
317
- messageText = message;
318
- }
319
-
320
- // Optional avatar
321
- if (avatarUrl) {
322
- const avatarElem = document.createElement('div');
323
- avatarElem.className = 'avatar';
324
- avatarElem.style.backgroundImage = `url("${avatarUrl}")`;
325
- item.appendChild(avatarElem);
326
- }
327
-
328
- // Content wrapper
329
- const contentWrapper = document.createElement('div');
330
- contentWrapper.className = 'content';
331
-
332
- // Optional title
333
- if (titleText) {
334
- const titleElem = document.createElement('div');
335
- titleElem.className = 'title';
336
- titleElem.textContent = titleText;
337
- contentWrapper.appendChild(titleElem);
338
- }
339
-
340
- // Message
341
- const messageElem = document.createElement('div');
342
- messageElem.className = 'message';
343
-
344
- if (mode === 'html') {
345
- messageElem.innerHTML = messageText;
346
- } else {
347
- messageElem.textContent = messageText;
348
- }
349
-
350
- contentWrapper.appendChild(messageElem);
351
-
352
- // Action by clicking (if provided)
353
- if (typeof onClick === 'function') {
354
- item.classList.add('clickable');
355
- item.addEventListener('click', (e) => {
356
- // Prevents the close button from clicking
357
- if (e.target instanceof HTMLElement && !e.target.closest('.notify-close')) {
358
- onClick(e);
359
- }
360
- });
361
- }
362
-
363
- // Close button
364
- const closeBtn = document.createElement('button');
365
- closeBtn.className = 'notify-close';
366
- closeBtn.setAttribute('type', 'button');
367
- closeBtn.innerHTML = '&times;';
368
- closeBtn.addEventListener('click', (e) => {
369
- e.stopPropagation(); // prevents propagation for the main onClick
370
- this.#removeItem(item);
371
- });
372
-
373
- item.append(contentWrapper, closeBtn);
374
- this.#list.prepend(item);
375
- this.#modes.set(item, mode);
376
- this.#updateCount(this.#count + 1);
377
- }
378
-
379
- /**
380
- * Remove a notify by index.
381
- * @param {number} index
382
- */
383
- remove(index) {
384
- const item = this.getItem(index);
385
- this.#removeItem(item);
386
- }
387
-
388
- /**
389
- * Clear all notifications safely.
390
- */
391
- clear() {
392
- let needAgain = true;
393
- while (needAgain) {
394
- needAgain = false;
395
- const items = Array.from(this.#list.children);
396
- for (const item of items) {
397
- if (item instanceof HTMLElement && !item.classList.contains('removing')) {
398
- this.#removeItem(item);
399
- needAgain = true;
400
- }
401
- }
402
- }
403
- }
404
-
405
- /**
406
- * Open the notify center.
407
- */
408
- open() {
409
- this.#overlay.classList.remove('hidden');
410
- this.#center.classList.add('open');
411
- }
412
-
413
- /**
414
- * Close the notify center.
415
- */
416
- close() {
417
- this.#overlay.classList.add('hidden');
418
- this.#center.classList.remove('open');
419
- if (this.#markAllAsReadOnClose) {
420
- const items = this.#list.querySelectorAll('.item.unread');
421
- for (const item of items) {
422
- if (item instanceof HTMLElement) this.markAsRead(item);
423
- }
424
- }
425
- }
426
-
427
- /**
428
- * Toggle open/close state.
429
- */
430
- toggle() {
431
- if (this.#center.classList.contains('open')) this.close();
432
- else this.open();
433
- }
434
-
435
- /**
436
- * Recalculate the number of notifications based on the actual DOM list.
437
- */
438
- recount() {
439
- const count = this.#list.querySelectorAll('.item.unread').length;
440
- this.#updateCount(count);
441
- }
442
-
443
- /**
444
- * Get current count.
445
- * @returns {number}
446
- */
447
- get count() {
448
- return this.#count;
449
- }
450
-
451
- /**
452
- * Destroys the notification center instance, removing all event listeners,
453
- * clearing notifications, and optionally removing DOM elements.
454
- *
455
- * Call this when the notification center is no longer needed to prevent memory leaks.
456
- *
457
- * @returns {void}
458
- */
459
- destroy() {
460
- // Remove event listeners
461
- this.#button?.removeEventListener('click', this.toggle);
462
- this.#center?.querySelector('.close')?.removeEventListener('click', this.close);
463
- this.#center?.querySelector('.clear-all')?.removeEventListener('click', this.clear);
464
- this.#overlay?.removeEventListener('click', this.close);
465
-
466
- // Clear all notifications
467
- this.clear();
468
-
469
- this.#center?.remove();
470
- this.#overlay?.remove();
471
- this.#button?.remove();
472
-
473
- // Clean internal references
474
- // this.#center = null;
475
- // this.#list = null;
476
- // this.#badge = null;
477
- // this.#button = null;
478
- // this.#overlay = null;
479
- this.#count = 0;
480
- this.#modes = new WeakMap();
481
- }
482
- }
483
-
484
- /* harmony default export */ const libs_TinyNotifyCenter = (TinyNotifyCenter);
485
-
486
- ;// ./src/v1/build/TinyNotifyCenter.mjs
487
-
488
-
489
-
490
-
491
- window.TinyNotifyCenter = __webpack_exports__.TinyNotifyCenter;
492
- /******/ })()
493
- ;