tiny-essentials 1.17.1 → 1.18.1

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 (60) hide show
  1. package/dist/legacy/get/countObj.cjs +2 -2
  2. package/dist/legacy/get/countObj.d.mts +1 -1
  3. package/dist/legacy/get/countObj.mjs +1 -1
  4. package/dist/legacy/index.cjs +2 -1
  5. package/dist/v1/TinyBasicsEs.js +559 -411
  6. package/dist/v1/TinyBasicsEs.min.js +1 -1
  7. package/dist/v1/TinyClipboard.js +459 -0
  8. package/dist/v1/TinyClipboard.min.js +1 -0
  9. package/dist/v1/TinyDragger.js +170 -2454
  10. package/dist/v1/TinyDragger.min.js +1 -2
  11. package/dist/v1/TinyEssentials.js +1093 -63
  12. package/dist/v1/TinyEssentials.min.js +1 -1
  13. package/dist/v1/TinyHtml.js +164 -21
  14. package/dist/v1/TinyHtml.min.js +1 -1
  15. package/dist/v1/TinySmartScroller.js +164 -21
  16. package/dist/v1/TinySmartScroller.min.js +1 -1
  17. package/dist/v1/TinyTextRangeEditor.js +497 -0
  18. package/dist/v1/TinyTextRangeEditor.min.js +1 -0
  19. package/dist/v1/TinyUploadClicker.js +219 -467
  20. package/dist/v1/TinyUploadClicker.min.js +1 -1
  21. package/dist/v1/basics/html.cjs +3 -3
  22. package/dist/v1/basics/html.mjs +1 -1
  23. package/dist/v1/basics/index.cjs +3 -2
  24. package/dist/v1/basics/index.d.mts +2 -2
  25. package/dist/v1/basics/index.mjs +2 -1
  26. package/dist/v1/basics/objChecker.cjs +46 -0
  27. package/dist/v1/basics/objChecker.d.mts +29 -0
  28. package/dist/v1/basics/objChecker.mjs +45 -0
  29. package/dist/v1/basics/objFilter.cjs +4 -45
  30. package/dist/v1/basics/objFilter.d.mts +3 -28
  31. package/dist/v1/basics/objFilter.mjs +2 -45
  32. package/dist/v1/build/TinyClipboard.cjs +7 -0
  33. package/dist/v1/build/TinyClipboard.d.mts +3 -0
  34. package/dist/v1/build/TinyClipboard.mjs +2 -0
  35. package/dist/v1/build/TinyTextRangeEditor.cjs +7 -0
  36. package/dist/v1/build/TinyTextRangeEditor.d.mts +3 -0
  37. package/dist/v1/build/TinyTextRangeEditor.mjs +2 -0
  38. package/dist/v1/index.cjs +7 -2
  39. package/dist/v1/index.d.mts +5 -3
  40. package/dist/v1/index.mjs +5 -2
  41. package/dist/v1/libs/TinyClipboard.cjs +420 -0
  42. package/dist/v1/libs/TinyClipboard.d.mts +155 -0
  43. package/dist/v1/libs/TinyClipboard.mjs +398 -0
  44. package/dist/v1/libs/TinyDragger.cjs +3 -3
  45. package/dist/v1/libs/TinyDragger.mjs +1 -1
  46. package/dist/v1/libs/TinyHtml.cjs +164 -21
  47. package/dist/v1/libs/TinyHtml.d.mts +150 -27
  48. package/dist/v1/libs/TinyHtml.mjs +158 -20
  49. package/dist/v1/libs/TinyTextRangeEditor.cjs +458 -0
  50. package/dist/v1/libs/TinyTextRangeEditor.d.mts +200 -0
  51. package/dist/v1/libs/TinyTextRangeEditor.mjs +424 -0
  52. package/dist/v1/libs/TinyUploadClicker.cjs +5 -4
  53. package/docs/v1/README.md +3 -0
  54. package/docs/v1/basics/objChecker.md +47 -0
  55. package/docs/v1/basics/objFilter.md +0 -40
  56. package/docs/v1/libs/TinyClipboard.md +213 -0
  57. package/docs/v1/libs/TinyHtml.md +112 -15
  58. package/docs/v1/libs/TinyTextRangeEditor.md +208 -0
  59. package/package.json +1 -1
  60. package/dist/v1/TinyDragger.min.js.LICENSE.txt +0 -8
@@ -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
  */