tiny-essentials 1.17.1 → 1.18.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.
Files changed (39) hide show
  1. package/dist/v1/TinyBasicsEs.js +164 -21
  2. package/dist/v1/TinyBasicsEs.min.js +1 -1
  3. package/dist/v1/TinyClipboard.js +459 -0
  4. package/dist/v1/TinyClipboard.min.js +1 -0
  5. package/dist/v1/TinyDragger.js +164 -21
  6. package/dist/v1/TinyDragger.min.js +1 -1
  7. package/dist/v1/TinyEssentials.js +1046 -21
  8. package/dist/v1/TinyEssentials.min.js +1 -1
  9. package/dist/v1/TinyHtml.js +164 -21
  10. package/dist/v1/TinyHtml.min.js +1 -1
  11. package/dist/v1/TinySmartScroller.js +164 -21
  12. package/dist/v1/TinySmartScroller.min.js +1 -1
  13. package/dist/v1/TinyTextRangeEditor.js +497 -0
  14. package/dist/v1/TinyTextRangeEditor.min.js +1 -0
  15. package/dist/v1/TinyUploadClicker.js +166 -21
  16. package/dist/v1/TinyUploadClicker.min.js +1 -1
  17. package/dist/v1/build/TinyClipboard.cjs +7 -0
  18. package/dist/v1/build/TinyClipboard.d.mts +3 -0
  19. package/dist/v1/build/TinyClipboard.mjs +2 -0
  20. package/dist/v1/build/TinyTextRangeEditor.cjs +7 -0
  21. package/dist/v1/build/TinyTextRangeEditor.d.mts +3 -0
  22. package/dist/v1/build/TinyTextRangeEditor.mjs +2 -0
  23. package/dist/v1/index.cjs +4 -0
  24. package/dist/v1/index.d.mts +3 -1
  25. package/dist/v1/index.mjs +3 -1
  26. package/dist/v1/libs/TinyClipboard.cjs +420 -0
  27. package/dist/v1/libs/TinyClipboard.d.mts +155 -0
  28. package/dist/v1/libs/TinyClipboard.mjs +398 -0
  29. package/dist/v1/libs/TinyHtml.cjs +164 -21
  30. package/dist/v1/libs/TinyHtml.d.mts +150 -27
  31. package/dist/v1/libs/TinyHtml.mjs +158 -20
  32. package/dist/v1/libs/TinyTextRangeEditor.cjs +458 -0
  33. package/dist/v1/libs/TinyTextRangeEditor.d.mts +200 -0
  34. package/dist/v1/libs/TinyTextRangeEditor.mjs +424 -0
  35. package/docs/v1/README.md +2 -0
  36. package/docs/v1/libs/TinyClipboard.md +213 -0
  37. package/docs/v1/libs/TinyHtml.md +112 -15
  38. package/docs/v1/libs/TinyTextRangeEditor.md +208 -0
  39. package/package.json +1 -1
@@ -65,6 +65,17 @@ export type TinyElementAndWinAndDoc = ElementAndWinAndDoc | TinyHtml;
65
65
  * Useful for functions that operate generically on scrollable or measurable targets.
66
66
  */
67
67
  export type ElementAndWinAndDoc = Element | Window | Document;
68
+ /**
69
+ * Represents a raw DOM element with document or an instance of TinyHtml.
70
+ * This type is used to abstract interactions with both plain elements
71
+ * and wrapped elements via the TinyHtml class.
72
+ */
73
+ export type TinyElementWithDoc = ElementWithDoc | TinyHtml;
74
+ /**
75
+ * Represents a value that can be either a DOM Element, or the document object.
76
+ * Useful for functions that operate generically on measurable targets.
77
+ */
78
+ export type ElementWithDoc = Element | Document;
68
79
  /**
69
80
  * A parameter type used for filtering or matching elements.
70
81
  * It can be:
@@ -80,10 +91,6 @@ export type WinnowRequest = string | Element | Element[] | ((index: number, el:
80
91
  * These include common DOM elements and root containers.
81
92
  */
82
93
  export type ConstructorElValues = Window | Element | Document | Text;
83
- /**
84
- * The handler function used in event listeners.
85
- */
86
- export type EventRegistryHandle = (e: Event) => any;
87
94
  /**
88
95
  * Options passed to `addEventListener` or `removeEventListener`.
89
96
  * Can be a boolean or an object of type `AddEventListenerOptions`.
@@ -96,7 +103,7 @@ export type EventRegistryItem = {
96
103
  /**
97
104
  * - The function to be executed when the event is triggered.
98
105
  */
99
- handler: EventRegistryHandle;
106
+ handler: EventListenerOrEventListenerObject | null;
100
107
  /**
101
108
  * - Optional configuration passed to the listener.
102
109
  */
@@ -215,8 +222,41 @@ declare class TinyHtml {
215
222
  areElsCollPerfRight: (rect1: TinyCollision.ObjRect, rect2: TinyCollision.ObjRect) => boolean;
216
223
  areElsColliding: (rect1: TinyCollision.ObjRect, rect2: TinyCollision.ObjRect) => boolean;
217
224
  areElsPerfColliding: (rect1: TinyCollision.ObjRect, rect2: TinyCollision.ObjRect) => boolean;
218
- getElsColliding: (rect1: TinyCollision.ObjRect, rect2: TinyCollision.ObjRect) => string | null;
219
- getElsPerfColliding: (rect1: TinyCollision.ObjRect, rect2: TinyCollision.ObjRect) => "top" | "bottom" | "left" | "right" | null;
225
+ getElsColliding: (
226
+ /**
227
+ * @typedef {'string' | 'date' | 'number'} GetValueTypes
228
+ * Types of value extractors supported by TinyHtml._valTypes.
229
+ */
230
+ /**
231
+ * @typedef {SetValueBase|SetValueBase[]} SetValueList - A single value or an array of values to be assigned to the input element.
232
+ */
233
+ /**
234
+ * A list of HTML form elements that can have a `.value` property used by TinyHtml.
235
+ * Includes common input types used in forms.
236
+ *
237
+ * @typedef {HTMLInputElement|HTMLSelectElement|HTMLTextAreaElement|HTMLOptionElement} InputElement
238
+ */
239
+ /**
240
+ * TinyHtml is a utility class that provides static and instance-level methods
241
+ * for precise dimension and position computations on HTML elements.
242
+ * It mimics some jQuery functionalities while using native browser APIs.
243
+ *
244
+ * Inspired by the jQuery project's open source implementations of element dimension
245
+ * and offset utilities. This class serves as a lightweight alternative using modern DOM APIs.
246
+ *
247
+ * @class
248
+ */
249
+ rect1: TinyCollision.ObjRect, rect2: TinyCollision.ObjRect) => string | null;
250
+ getElsPerfColliding: (rect1: TinyCollision.ObjRect /**
251
+ * TinyHtml is a utility class that provides static and instance-level methods
252
+ * for precise dimension and position computations on HTML elements.
253
+ * It mimics some jQuery functionalities while using native browser APIs.
254
+ *
255
+ * Inspired by the jQuery project's open source implementations of element dimension
256
+ * and offset utilities. This class serves as a lightweight alternative using modern DOM APIs.
257
+ *
258
+ * @class
259
+ */, rect2: TinyCollision.ObjRect) => "top" | "bottom" | "left" | "right" | null;
220
260
  getElsCollOverlap: (rect1: TinyCollision.ObjRect, rect2: TinyCollision.ObjRect) => {
221
261
  overlapLeft: number;
222
262
  overlapRight: number;
@@ -467,9 +507,9 @@ declare class TinyHtml {
467
507
  * Ensures the input is returned as an array.
468
508
  * Useful to normalize operations across multiple or single element/window/document elements.
469
509
  *
470
- * @param {TinyElementAndWinAndDoc|TinyElementAndWinAndDoc[]} elems - A single element/window element or array of html elements.
510
+ * @param {TinyElementAndWinAndDoc|TinyElementAndWinAndDoc[]} elems - A single element/document/window element or array of html elements.
471
511
  * @param {string} where - The method or context name where validation is being called.
472
- * @returns {ElementAndWindow[]} - Always returns an array of element/window elements.
512
+ * @returns {ElementAndWindow[]} - Always returns an array of element/document/window elements.
473
513
  * @readonly
474
514
  */
475
515
  static readonly _preElemsAndWinAndDoc(elems: TinyElementAndWinAndDoc | TinyElementAndWinAndDoc[], where: string): ElementAndWindow[];
@@ -477,12 +517,32 @@ declare class TinyHtml {
477
517
  * Ensures the input is returned as an single element/window/document element.
478
518
  * Useful to normalize operations across multiple or single element/window/document elements.
479
519
  *
480
- * @param {TinyElementAndWinAndDoc|TinyElementAndWinAndDoc[]} elems - A single element/window element or array of html elements.
520
+ * @param {TinyElementAndWinAndDoc|TinyElementAndWinAndDoc[]} elems - A single element/document/window element or array of html elements.
481
521
  * @param {string} where - The method or context name where validation is being called.
482
- * @returns {ElementAndWindow} - Always returns an single element/window element.
522
+ * @returns {ElementAndWindow} - Always returns an single element/document/window element.
483
523
  * @readonly
484
524
  */
485
525
  static readonly _preElemAndWinAndDoc(elems: TinyElementAndWinAndDoc | TinyElementAndWinAndDoc[], where: string): ElementAndWindow;
526
+ /**
527
+ * Ensures the input is returned as an array.
528
+ * Useful to normalize operations across multiple or single element with document elements.
529
+ *
530
+ * @param {TinyElementWithDoc|TinyElementWithDoc[]} elems - A single element with document element or array of html elements.
531
+ * @param {string} where - The method or context name where validation is being called.
532
+ * @returns {ElementWithDoc[]} - Always returns an array of element with document elements.
533
+ * @readonly
534
+ */
535
+ static readonly _preElemsWithDoc(elems: TinyElementWithDoc | TinyElementWithDoc[], where: string): ElementWithDoc[];
536
+ /**
537
+ * Ensures the input is returned as an single element with document element.
538
+ * Useful to normalize operations across multiple or single element with document elements.
539
+ *
540
+ * @param {TinyElementWithDoc|TinyElementWithDoc[]} elems - A single element/window element or array of html elements.
541
+ * @param {string} where - The method or context name where validation is being called.
542
+ * @returns {ElementWithDoc} - Always returns an single element/window element.
543
+ * @readonly
544
+ */
545
+ static readonly _preElemWithDoc(elems: TinyElementWithDoc | TinyElementWithDoc[], where: string): ElementWithDoc;
486
546
  /**
487
547
  * Normalizes and converts one or more DOM elements (or TinyHtml instances)
488
548
  * into an array of `TinyHtml` instances.
@@ -1479,36 +1539,69 @@ declare class TinyHtml {
1479
1539
  * @throws {Error} If the element is not a checkbox/radio input.
1480
1540
  */
1481
1541
  static valBool(el: TinyInputElement): boolean;
1542
+ /**
1543
+ * Registers a listener for the "paste" event to extract files and text from the clipboard (e.g., when the user presses Ctrl+V).
1544
+ *
1545
+ * This method allows reacting to pasted content by providing separate callbacks for files and plain text.
1546
+ * Useful for building file upload areas, rich-text editors, or input enhancements.
1547
+ *
1548
+ * @param {TinyElementWithDoc|TinyElementWithDoc[]} el - The target element(s) where the "paste" event will be listened.
1549
+ * @param {Object} [settings={}] - Optional callbacks to handle clipboard content.
1550
+ * @param {(data: DataTransferItem, file: File) => void} [settings.onFilePaste] - Called for each file pasted from the clipboard (e.g., images).
1551
+ * @param {(data: DataTransferItem, text: string) => void} [settings.onTextPaste] - Called when plain text is pasted from the clipboard.
1552
+ * @returns {EventListenerOrEventListenerObject} The internal "paste" event handler used.
1553
+ */
1554
+ static listenForPaste(el: TinyElementWithDoc | TinyElementWithDoc[], { onFilePaste, onTextPaste }?: {
1555
+ onFilePaste?: ((data: DataTransferItem, file: File) => void) | undefined;
1556
+ onTextPaste?: ((data: DataTransferItem, text: string) => void) | undefined;
1557
+ }): EventListenerOrEventListenerObject;
1558
+ /**
1559
+ * Checks if the element has a listener for a specific event.
1560
+ *
1561
+ * @param {TinyEventTarget} el - The element to check.
1562
+ * @param {string} event - The event name to check.
1563
+ * @returns {boolean}
1564
+ */
1565
+ static hasEventListener(el: TinyEventTarget, event: string): boolean;
1566
+ /**
1567
+ * Checks if the element has the exact handler registered for a specific event.
1568
+ *
1569
+ * @param {TinyEventTarget} el - The element to check.
1570
+ * @param {string} event - The event name to check.
1571
+ * @param {EventListenerOrEventListenerObject} handler - The handler function to check.
1572
+ * @returns {boolean}
1573
+ */
1574
+ static hasExactEventListener(el: TinyEventTarget, event: string, handler: EventListenerOrEventListenerObject): boolean;
1482
1575
  /**
1483
1576
  * Registers an event listener on the specified element.
1484
1577
  *
1485
1578
  * @param {TinyEventTarget|TinyEventTarget[]} el - The target to listen on.
1486
1579
  * @param {string} event - The event type (e.g. 'click', 'keydown').
1487
- * @param {EventRegistryHandle} handler - The callback function to run on event.
1580
+ * @param {EventListenerOrEventListenerObject|null} handler - The callback function to run on event.
1488
1581
  * @param {EventRegistryOptions} [options] - Optional event listener options.
1489
1582
  * @returns {TinyEventTarget|TinyEventTarget[]}
1490
1583
  */
1491
- static on(el: TinyEventTarget | TinyEventTarget[], event: string, handler: EventRegistryHandle, options?: EventRegistryOptions): TinyEventTarget | TinyEventTarget[];
1584
+ static on(el: TinyEventTarget | TinyEventTarget[], event: string, handler: EventListenerOrEventListenerObject | null, options?: EventRegistryOptions): TinyEventTarget | TinyEventTarget[];
1492
1585
  /**
1493
1586
  * Registers an event listener that runs only once, then is removed.
1494
1587
  *
1495
1588
  * @param {TinyEventTarget|TinyEventTarget[]} el - The target to listen on.
1496
1589
  * @param {string} event - The event type (e.g. 'click', 'keydown').
1497
- * @param {EventRegistryHandle} handler - The callback function to run on event.
1590
+ * @param {EventListenerOrEventListenerObject} handler - The callback function to run on event.
1498
1591
  * @param {EventRegistryOptions} [options={}] - Optional event listener options.
1499
1592
  * @returns {TinyEventTarget|TinyEventTarget[]}
1500
1593
  */
1501
- static once(el: TinyEventTarget | TinyEventTarget[], event: string, handler: EventRegistryHandle, options?: EventRegistryOptions): TinyEventTarget | TinyEventTarget[];
1594
+ static once(el: TinyEventTarget | TinyEventTarget[], event: string, handler: EventListenerOrEventListenerObject, options?: EventRegistryOptions): TinyEventTarget | TinyEventTarget[];
1502
1595
  /**
1503
1596
  * Removes a specific event listener from an element.
1504
1597
  *
1505
1598
  * @param {TinyEventTarget|TinyEventTarget[]} el - The target element.
1506
1599
  * @param {string} event - The event type.
1507
- * @param {EventRegistryHandle} handler - The function originally bound to the event.
1600
+ * @param {EventListenerOrEventListenerObject|null} handler - The function originally bound to the event.
1508
1601
  * @param {boolean|EventListenerOptions} [options] - Optional listener options.
1509
1602
  * @returns {TinyEventTarget|TinyEventTarget[]}
1510
1603
  */
1511
- static off(el: TinyEventTarget | TinyEventTarget[], event: string, handler: EventRegistryHandle, options?: boolean | EventListenerOptions): TinyEventTarget | TinyEventTarget[];
1604
+ static off(el: TinyEventTarget | TinyEventTarget[], event: string, handler: EventListenerOrEventListenerObject | null, options?: boolean | EventListenerOptions): TinyEventTarget | TinyEventTarget[];
1512
1605
  /**
1513
1606
  * Removes all event listeners of a specific type from the element.
1514
1607
  *
@@ -1521,11 +1614,11 @@ declare class TinyHtml {
1521
1614
  * Removes all event listeners of all types from the element.
1522
1615
  *
1523
1616
  * @param {TinyEventTarget|TinyEventTarget[]} el - The target element.
1524
- * @param {((handler: EventListenerOrEventListenerObject, event: string) => boolean)|null} [filterFn=null] -
1617
+ * @param {((handler: EventListenerOrEventListenerObject|null, event: string) => boolean)|null} [filterFn=null] -
1525
1618
  * Optional filter function to selectively remove specific handlers.
1526
1619
  * @returns {TinyEventTarget|TinyEventTarget[]}
1527
1620
  */
1528
- static offAllTypes(el: TinyEventTarget | TinyEventTarget[], filterFn?: ((handler: EventListenerOrEventListenerObject, event: string) => boolean) | null): TinyEventTarget | TinyEventTarget[];
1621
+ static offAllTypes(el: TinyEventTarget | TinyEventTarget[], filterFn?: ((handler: EventListenerOrEventListenerObject | null, event: string) => boolean) | null): TinyEventTarget | TinyEventTarget[];
1529
1622
  /**
1530
1623
  * Triggers all handlers associated with a specific event on the given element.
1531
1624
  *
@@ -2398,33 +2491,63 @@ declare class TinyHtml {
2398
2491
  * @throws {Error} If the element is not a checkbox/radio input.
2399
2492
  */
2400
2493
  valBool(): boolean;
2494
+ /**
2495
+ * Registers a listener for the "paste" event to extract files and text from the clipboard (e.g., when the user presses Ctrl+V).
2496
+ *
2497
+ * This method allows reacting to pasted content by providing separate callbacks for files and plain text.
2498
+ * Useful for building file upload areas, rich-text editors, or input enhancements.
2499
+ *
2500
+ * @param {Object} [settings={}] - Optional callbacks to handle clipboard content.
2501
+ * @param {(data: DataTransferItem, file: File) => void} [settings.onFilePaste] - Called for each file pasted from the clipboard (e.g., images).
2502
+ * @param {(data: DataTransferItem, text: string) => void} [settings.onTextPaste] - Called when plain text is pasted from the clipboard.
2503
+ * @returns {EventListenerOrEventListenerObject} The internal "paste" event handler used.
2504
+ */
2505
+ listenForPaste({ onFilePaste, onTextPaste }?: {
2506
+ onFilePaste?: ((data: DataTransferItem, file: File) => void) | undefined;
2507
+ onTextPaste?: ((data: DataTransferItem, text: string) => void) | undefined;
2508
+ }): EventListenerOrEventListenerObject;
2509
+ /**
2510
+ * Checks if the element has a listener for a specific event.
2511
+ *
2512
+ * @param {string} event - The event name to check.
2513
+ * @returns {boolean}
2514
+ */
2515
+ hasEventListener(event: string): boolean;
2516
+ /**
2517
+ * Checks if the element has the exact handler registered for a specific event.
2518
+ *
2519
+ * @param {string} event - The event name to check.
2520
+ * @param {EventListenerOrEventListenerObject} handler - The handler function to check.
2521
+ * @returns {boolean}
2522
+ */
2523
+ hasExactEventListener(event: string, handler: EventListenerOrEventListenerObject): boolean;
2401
2524
  /**
2402
2525
  * Registers an event listener on the specified element.
2403
2526
  *
2404
2527
  * @param {string} event - The event type (e.g. 'click', 'keydown').
2405
- * @param {EventRegistryHandle} handler - The callback function to run on event.
2528
+ * @param {EventListenerOrEventListenerObject|null} handler - The callback function to run on event.
2406
2529
  * @param {EventRegistryOptions} [options] - Optional event listener options.
2407
2530
  * @returns {TinyEventTarget|TinyEventTarget[]}
2408
2531
  */
2409
- on(event: string, handler: EventRegistryHandle, options?: EventRegistryOptions): TinyEventTarget | TinyEventTarget[];
2532
+ on(event: string, handler: EventListenerOrEventListenerObject | null, options?: EventRegistryOptions): TinyEventTarget | TinyEventTarget[];
2410
2533
  /**
2411
2534
  * Registers an event listener that runs only once, then is removed.
2412
2535
  *
2413
2536
  * @param {string} event - The event type (e.g. 'click', 'keydown').
2414
- * @param {EventRegistryHandle} handler - The callback function to run on event.
2537
+ * @param {EventListenerOrEventListenerObject} handler - The callback function to run on event.
2415
2538
  * @param {EventRegistryOptions} [options={}] - Optional event listener options.
2416
2539
  * @returns {TinyEventTarget|TinyEventTarget[]}
2417
2540
  */
2418
- once(event: string, handler: EventRegistryHandle, options?: EventRegistryOptions): TinyEventTarget | TinyEventTarget[];
2541
+ once(event: string, handler: EventListenerOrEventListenerObject, options?: EventRegistryOptions): TinyEventTarget | TinyEventTarget[];
2419
2542
  /**
2420
2543
  * Removes a specific event listener from an element.
2421
2544
  *
2422
2545
  * @param {string} event - The event type.
2423
- * @param {EventRegistryHandle} handler - The function originally bound to the event.
2546
+ * @param {EventListenerOrEventListenerObject|null} handler - The function originally bound to the event.
2424
2547
  * @param {boolean|EventListenerOptions} [options] - Optional listener options.
2425
2548
  * @returns {TinyEventTarget|TinyEventTarget[]}
2426
2549
  */
2427
- off(event: string, handler: EventRegistryHandle, options?: boolean | EventListenerOptions): TinyEventTarget | TinyEventTarget[];
2550
+ off(event: string, handler: EventListenerOrEventListenerObject | null, options?: boolean | EventListenerOptions): TinyEventTarget | TinyEventTarget[];
2428
2551
  /**
2429
2552
  * Removes all event listeners of a specific type from the element.
2430
2553
  *
@@ -2435,11 +2558,11 @@ declare class TinyHtml {
2435
2558
  /**
2436
2559
  * Removes all event listeners of all types from the element.
2437
2560
  *
2438
- * @param {((handler: EventListenerOrEventListenerObject, event: string) => boolean)|null} [filterFn=null] -
2561
+ * @param {((handler: EventListenerOrEventListenerObject|null, event: string) => boolean)|null} [filterFn=null] -
2439
2562
  * Optional filter function to selectively remove specific handlers.
2440
2563
  * @returns {TinyEventTarget|TinyEventTarget[]}
2441
2564
  */
2442
- offAllTypes(filterFn?: ((handler: EventListenerOrEventListenerObject, event: string) => boolean) | null): TinyEventTarget | TinyEventTarget[];
2565
+ offAllTypes(filterFn?: ((handler: EventListenerOrEventListenerObject | null, event: string) => boolean) | null): TinyEventTarget | TinyEventTarget[];
2443
2566
  /**
2444
2567
  * Triggers all handlers associated with a specific event on the given element.
2445
2568
  *
@@ -72,6 +72,19 @@ const { areElsColliding, areElsPerfColliding, areElsCollTop, areElsCollBottom, a
72
72
  *
73
73
  * @typedef {Element|Window|Document} ElementAndWinAndDoc
74
74
  */
75
+ /**
76
+ * Represents a raw DOM element with document or an instance of TinyHtml.
77
+ * This type is used to abstract interactions with both plain elements
78
+ * and wrapped elements via the TinyHtml class.
79
+ *
80
+ * @typedef {ElementWithDoc|TinyHtml} TinyElementWithDoc
81
+ */
82
+ /**
83
+ * Represents a value that can be either a DOM Element, or the document object.
84
+ * Useful for functions that operate generically on measurable targets.
85
+ *
86
+ * @typedef {Element|Document} ElementWithDoc
87
+ */
75
88
  /**
76
89
  * A parameter type used for filtering or matching elements.
77
90
  * It can be:
@@ -89,11 +102,6 @@ const { areElsColliding, areElsPerfColliding, areElsCollTop, areElsCollBottom, a
89
102
  *
90
103
  * @typedef {Window|Element|Document|Text} ConstructorElValues
91
104
  */
92
- /**
93
- * The handler function used in event listeners.
94
- *
95
- * @typedef {(e: Event) => any} EventRegistryHandle
96
- */
97
105
  /**
98
106
  * Options passed to `addEventListener` or `removeEventListener`.
99
107
  * Can be a boolean or an object of type `AddEventListenerOptions`.
@@ -104,7 +112,7 @@ const { areElsColliding, areElsPerfColliding, areElsCollTop, areElsCollBottom, a
104
112
  * Structure describing a registered event callback and its options.
105
113
  *
106
114
  * @typedef {Object} EventRegistryItem
107
- * @property {EventRegistryHandle} handler - The function to be executed when the event is triggered.
115
+ * @property {EventListenerOrEventListenerObject|null} handler - The function to be executed when the event is triggered.
108
116
  * @property {EventRegistryOptions} [options] - Optional configuration passed to the listener.
109
117
  */
110
118
  /**
@@ -595,9 +603,9 @@ class TinyHtml {
595
603
  * Ensures the input is returned as an array.
596
604
  * Useful to normalize operations across multiple or single element/window/document elements.
597
605
  *
598
- * @param {TinyElementAndWinAndDoc|TinyElementAndWinAndDoc[]} elems - A single element/window element or array of html elements.
606
+ * @param {TinyElementAndWinAndDoc|TinyElementAndWinAndDoc[]} elems - A single element/document/window element or array of html elements.
599
607
  * @param {string} where - The method or context name where validation is being called.
600
- * @returns {ElementAndWindow[]} - Always returns an array of element/window elements.
608
+ * @returns {ElementAndWindow[]} - Always returns an array of element/document/window elements.
601
609
  * @readonly
602
610
  */
603
611
  static _preElemsAndWinAndDoc(elems, where) {
@@ -608,9 +616,9 @@ class TinyHtml {
608
616
  * Ensures the input is returned as an single element/window/document element.
609
617
  * Useful to normalize operations across multiple or single element/window/document elements.
610
618
  *
611
- * @param {TinyElementAndWinAndDoc|TinyElementAndWinAndDoc[]} elems - A single element/window element or array of html elements.
619
+ * @param {TinyElementAndWinAndDoc|TinyElementAndWinAndDoc[]} elems - A single element/document/window element or array of html elements.
612
620
  * @param {string} where - The method or context name where validation is being called.
613
- * @returns {ElementAndWindow} - Always returns an single element/window element.
621
+ * @returns {ElementAndWindow} - Always returns an single element/document/window element.
614
622
  * @readonly
615
623
  */
616
624
  static _preElemAndWinAndDoc(elems, where) {
@@ -619,6 +627,30 @@ class TinyHtml {
619
627
  return result.documentElement;
620
628
  return result;
621
629
  }
630
+ /**
631
+ * Ensures the input is returned as an array.
632
+ * Useful to normalize operations across multiple or single element with document elements.
633
+ *
634
+ * @param {TinyElementWithDoc|TinyElementWithDoc[]} elems - A single element with document element or array of html elements.
635
+ * @param {string} where - The method or context name where validation is being called.
636
+ * @returns {ElementWithDoc[]} - Always returns an array of element with document elements.
637
+ * @readonly
638
+ */
639
+ static _preElemsWithDoc(elems, where) {
640
+ return TinyHtml._preElemsTemplate(elems, where, [Element, Document], ['Element', 'Document']);
641
+ }
642
+ /**
643
+ * Ensures the input is returned as an single element with document element.
644
+ * Useful to normalize operations across multiple or single element with document elements.
645
+ *
646
+ * @param {TinyElementWithDoc|TinyElementWithDoc[]} elems - A single element/window element or array of html elements.
647
+ * @param {string} where - The method or context name where validation is being called.
648
+ * @returns {ElementWithDoc} - Always returns an single element/window element.
649
+ * @readonly
650
+ */
651
+ static _preElemWithDoc(elems, where) {
652
+ return TinyHtml._preElemTemplate(elems, where, [Element, Document], ['Element', 'Document']);
653
+ }
622
654
  /**
623
655
  * Normalizes and converts one or more DOM elements (or TinyHtml instances)
624
656
  * into an array of `TinyHtml` instances.
@@ -3581,12 +3613,117 @@ class TinyHtml {
3581
3613
  return TinyHtml.valBool(this);
3582
3614
  }
3583
3615
  ////////////////////////////////////////////
3616
+ /**
3617
+ * Registers a listener for the "paste" event to extract files and text from the clipboard (e.g., when the user presses Ctrl+V).
3618
+ *
3619
+ * This method allows reacting to pasted content by providing separate callbacks for files and plain text.
3620
+ * Useful for building file upload areas, rich-text editors, or input enhancements.
3621
+ *
3622
+ * @param {TinyElementWithDoc|TinyElementWithDoc[]} el - The target element(s) where the "paste" event will be listened.
3623
+ * @param {Object} [settings={}] - Optional callbacks to handle clipboard content.
3624
+ * @param {(data: DataTransferItem, file: File) => void} [settings.onFilePaste] - Called for each file pasted from the clipboard (e.g., images).
3625
+ * @param {(data: DataTransferItem, text: string) => void} [settings.onTextPaste] - Called when plain text is pasted from the clipboard.
3626
+ * @returns {EventListenerOrEventListenerObject} The internal "paste" event handler used.
3627
+ */
3628
+ static listenForPaste(el, { onFilePaste, onTextPaste } = {}) {
3629
+ if (typeof onFilePaste !== 'undefined' && typeof onFilePaste !== 'function')
3630
+ throw new TypeError('onFilePaste must be a function.');
3631
+ if (typeof onTextPaste !== 'undefined' && typeof onTextPaste !== 'function')
3632
+ throw new TypeError('onTextPaste must be a function.');
3633
+ /** @type {EventListenerOrEventListenerObject} */
3634
+ const pasteEvent = (event) => {
3635
+ if (!(event instanceof ClipboardEvent))
3636
+ return;
3637
+ const items = event.clipboardData?.items || [];
3638
+ for (const item of items) {
3639
+ if (item.kind === 'file') {
3640
+ if (typeof onFilePaste === 'function') {
3641
+ const file = item.getAsFile();
3642
+ if (file)
3643
+ onFilePaste(item, file);
3644
+ }
3645
+ }
3646
+ else if (item.kind === 'string') {
3647
+ if (typeof onTextPaste === 'function')
3648
+ item.getAsString((text) => onTextPaste(item, text));
3649
+ }
3650
+ }
3651
+ };
3652
+ TinyHtml._preElemsWithDoc(el, 'listenForPaste').forEach((elem) => TinyHtml.on(elem, 'paste', pasteEvent));
3653
+ return pasteEvent;
3654
+ }
3655
+ /**
3656
+ * Registers a listener for the "paste" event to extract files and text from the clipboard (e.g., when the user presses Ctrl+V).
3657
+ *
3658
+ * This method allows reacting to pasted content by providing separate callbacks for files and plain text.
3659
+ * Useful for building file upload areas, rich-text editors, or input enhancements.
3660
+ *
3661
+ * @param {Object} [settings={}] - Optional callbacks to handle clipboard content.
3662
+ * @param {(data: DataTransferItem, file: File) => void} [settings.onFilePaste] - Called for each file pasted from the clipboard (e.g., images).
3663
+ * @param {(data: DataTransferItem, text: string) => void} [settings.onTextPaste] - Called when plain text is pasted from the clipboard.
3664
+ * @returns {EventListenerOrEventListenerObject} The internal "paste" event handler used.
3665
+ */
3666
+ listenForPaste({ onFilePaste, onTextPaste } = {}) {
3667
+ return TinyHtml.listenForPaste(this, { onFilePaste, onTextPaste });
3668
+ }
3669
+ /**
3670
+ * Checks if the element has a listener for a specific event.
3671
+ *
3672
+ * @param {TinyEventTarget} el - The element to check.
3673
+ * @param {string} event - The event name to check.
3674
+ * @returns {boolean}
3675
+ */
3676
+ static hasEventListener(el, event) {
3677
+ const elem = TinyHtml._preEventTargetElem(el, 'hasEventListener');
3678
+ if (!__eventRegistry.has(elem))
3679
+ return false;
3680
+ const events = __eventRegistry.get(elem);
3681
+ return !!(events && Array.isArray(events[event]) && events[event].length > 0);
3682
+ }
3683
+ /**
3684
+ * Checks if the element has a listener for a specific event.
3685
+ *
3686
+ * @param {string} event - The event name to check.
3687
+ * @returns {boolean}
3688
+ */
3689
+ hasEventListener(event) {
3690
+ return TinyHtml.hasEventListener(this, event);
3691
+ }
3692
+ /**
3693
+ * Checks if the element has the exact handler registered for a specific event.
3694
+ *
3695
+ * @param {TinyEventTarget} el - The element to check.
3696
+ * @param {string} event - The event name to check.
3697
+ * @param {EventListenerOrEventListenerObject} handler - The handler function to check.
3698
+ * @returns {boolean}
3699
+ */
3700
+ static hasExactEventListener(el, event, handler) {
3701
+ const elem = TinyHtml._preEventTargetElem(el, 'hasExactEventListener');
3702
+ if (typeof handler !== 'function')
3703
+ throw new TypeError('The "handler" must be a function.');
3704
+ if (!__eventRegistry.has(elem))
3705
+ return false;
3706
+ const events = __eventRegistry.get(elem);
3707
+ if (!events || !Array.isArray(events[event]))
3708
+ return false;
3709
+ return events[event].some((item) => item.handler === handler);
3710
+ }
3711
+ /**
3712
+ * Checks if the element has the exact handler registered for a specific event.
3713
+ *
3714
+ * @param {string} event - The event name to check.
3715
+ * @param {EventListenerOrEventListenerObject} handler - The handler function to check.
3716
+ * @returns {boolean}
3717
+ */
3718
+ hasExactEventListener(event, handler) {
3719
+ return TinyHtml.hasExactEventListener(this, event, handler);
3720
+ }
3584
3721
  /**
3585
3722
  * Registers an event listener on the specified element.
3586
3723
  *
3587
3724
  * @param {TinyEventTarget|TinyEventTarget[]} el - The target to listen on.
3588
3725
  * @param {string} event - The event type (e.g. 'click', 'keydown').
3589
- * @param {EventRegistryHandle} handler - The callback function to run on event.
3726
+ * @param {EventListenerOrEventListenerObject|null} handler - The callback function to run on event.
3590
3727
  * @param {EventRegistryOptions} [options] - Optional event listener options.
3591
3728
  * @returns {TinyEventTarget|TinyEventTarget[]}
3592
3729
  */
@@ -3610,7 +3747,7 @@ class TinyHtml {
3610
3747
  * Registers an event listener on the specified element.
3611
3748
  *
3612
3749
  * @param {string} event - The event type (e.g. 'click', 'keydown').
3613
- * @param {EventRegistryHandle} handler - The callback function to run on event.
3750
+ * @param {EventListenerOrEventListenerObject|null} handler - The callback function to run on event.
3614
3751
  * @param {EventRegistryOptions} [options] - Optional event listener options.
3615
3752
  * @returns {TinyEventTarget|TinyEventTarget[]}
3616
3753
  */
@@ -3622,7 +3759,7 @@ class TinyHtml {
3622
3759
  *
3623
3760
  * @param {TinyEventTarget|TinyEventTarget[]} el - The target to listen on.
3624
3761
  * @param {string} event - The event type (e.g. 'click', 'keydown').
3625
- * @param {EventRegistryHandle} handler - The callback function to run on event.
3762
+ * @param {EventListenerOrEventListenerObject} handler - The callback function to run on event.
3626
3763
  * @param {EventRegistryOptions} [options={}] - Optional event listener options.
3627
3764
  * @returns {TinyEventTarget|TinyEventTarget[]}
3628
3765
  */
@@ -3630,10 +3767,11 @@ class TinyHtml {
3630
3767
  if (typeof event !== 'string')
3631
3768
  throw new TypeError('The event name must be a string.');
3632
3769
  TinyHtml._preEventTargetElems(el, 'once').forEach((elem) => {
3633
- /** @type {EventRegistryHandle} e */
3770
+ /** @type {EventListenerOrEventListenerObject} */
3634
3771
  const wrapped = (e) => {
3635
3772
  TinyHtml.off(elem, event, wrapped);
3636
- handler(e);
3773
+ if (typeof handler === 'function')
3774
+ handler(e);
3637
3775
  };
3638
3776
  TinyHtml.on(elem, event, wrapped, typeof options === 'boolean' ? options : { ...options, once: true });
3639
3777
  });
@@ -3643,7 +3781,7 @@ class TinyHtml {
3643
3781
  * Registers an event listener that runs only once, then is removed.
3644
3782
  *
3645
3783
  * @param {string} event - The event type (e.g. 'click', 'keydown').
3646
- * @param {EventRegistryHandle} handler - The callback function to run on event.
3784
+ * @param {EventListenerOrEventListenerObject} handler - The callback function to run on event.
3647
3785
  * @param {EventRegistryOptions} [options={}] - Optional event listener options.
3648
3786
  * @returns {TinyEventTarget|TinyEventTarget[]}
3649
3787
  */
@@ -3655,7 +3793,7 @@ class TinyHtml {
3655
3793
  *
3656
3794
  * @param {TinyEventTarget|TinyEventTarget[]} el - The target element.
3657
3795
  * @param {string} event - The event type.
3658
- * @param {EventRegistryHandle} handler - The function originally bound to the event.
3796
+ * @param {EventListenerOrEventListenerObject|null} handler - The function originally bound to the event.
3659
3797
  * @param {boolean|EventListenerOptions} [options] - Optional listener options.
3660
3798
  * @returns {TinyEventTarget|TinyEventTarget[]}
3661
3799
  */
@@ -3677,7 +3815,7 @@ class TinyHtml {
3677
3815
  * Removes a specific event listener from an element.
3678
3816
  *
3679
3817
  * @param {string} event - The event type.
3680
- * @param {EventRegistryHandle} handler - The function originally bound to the event.
3818
+ * @param {EventListenerOrEventListenerObject|null} handler - The function originally bound to the event.
3681
3819
  * @param {boolean|EventListenerOptions} [options] - Optional listener options.
3682
3820
  * @returns {TinyEventTarget|TinyEventTarget[]}
3683
3821
  */
@@ -3718,7 +3856,7 @@ class TinyHtml {
3718
3856
  * Removes all event listeners of all types from the element.
3719
3857
  *
3720
3858
  * @param {TinyEventTarget|TinyEventTarget[]} el - The target element.
3721
- * @param {((handler: EventListenerOrEventListenerObject, event: string) => boolean)|null} [filterFn=null] -
3859
+ * @param {((handler: EventListenerOrEventListenerObject|null, event: string) => boolean)|null} [filterFn=null] -
3722
3860
  * Optional filter function to selectively remove specific handlers.
3723
3861
  * @returns {TinyEventTarget|TinyEventTarget[]}
3724
3862
  */
@@ -3743,7 +3881,7 @@ class TinyHtml {
3743
3881
  /**
3744
3882
  * Removes all event listeners of all types from the element.
3745
3883
  *
3746
- * @param {((handler: EventListenerOrEventListenerObject, event: string) => boolean)|null} [filterFn=null] -
3884
+ * @param {((handler: EventListenerOrEventListenerObject|null, event: string) => boolean)|null} [filterFn=null] -
3747
3885
  * Optional filter function to selectively remove specific handlers.
3748
3886
  * @returns {TinyEventTarget|TinyEventTarget[]}
3749
3887
  */