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
@@ -4358,6 +4358,21 @@ const {
4358
4358
  * @typedef {Element|Window|Document} ElementAndWinAndDoc
4359
4359
  */
4360
4360
 
4361
+ /**
4362
+ * Represents a raw DOM element with document or an instance of TinyHtml.
4363
+ * This type is used to abstract interactions with both plain elements
4364
+ * and wrapped elements via the TinyHtml class.
4365
+ *
4366
+ * @typedef {ElementWithDoc|TinyHtml} TinyElementWithDoc
4367
+ */
4368
+
4369
+ /**
4370
+ * Represents a value that can be either a DOM Element, or the document object.
4371
+ * Useful for functions that operate generically on measurable targets.
4372
+ *
4373
+ * @typedef {Element|Document} ElementWithDoc
4374
+ */
4375
+
4361
4376
  /**
4362
4377
  * A parameter type used for filtering or matching elements.
4363
4378
  * It can be:
@@ -4377,12 +4392,6 @@ const {
4377
4392
  * @typedef {Window|Element|Document|Text} ConstructorElValues
4378
4393
  */
4379
4394
 
4380
- /**
4381
- * The handler function used in event listeners.
4382
- *
4383
- * @typedef {(e: Event) => any} EventRegistryHandle
4384
- */
4385
-
4386
4395
  /**
4387
4396
  * Options passed to `addEventListener` or `removeEventListener`.
4388
4397
  * Can be a boolean or an object of type `AddEventListenerOptions`.
@@ -4394,7 +4403,7 @@ const {
4394
4403
  * Structure describing a registered event callback and its options.
4395
4404
  *
4396
4405
  * @typedef {Object} EventRegistryItem
4397
- * @property {EventRegistryHandle} handler - The function to be executed when the event is triggered.
4406
+ * @property {EventListenerOrEventListenerObject|null} handler - The function to be executed when the event is triggered.
4398
4407
  * @property {EventRegistryOptions} [options] - Optional configuration passed to the listener.
4399
4408
  */
4400
4409
 
@@ -4953,9 +4962,9 @@ class TinyHtml_TinyHtml {
4953
4962
  * Ensures the input is returned as an array.
4954
4963
  * Useful to normalize operations across multiple or single element/window/document elements.
4955
4964
  *
4956
- * @param {TinyElementAndWinAndDoc|TinyElementAndWinAndDoc[]} elems - A single element/window element or array of html elements.
4965
+ * @param {TinyElementAndWinAndDoc|TinyElementAndWinAndDoc[]} elems - A single element/document/window element or array of html elements.
4957
4966
  * @param {string} where - The method or context name where validation is being called.
4958
- * @returns {ElementAndWindow[]} - Always returns an array of element/window elements.
4967
+ * @returns {ElementAndWindow[]} - Always returns an array of element/document/window elements.
4959
4968
  * @readonly
4960
4969
  */
4961
4970
  static _preElemsAndWinAndDoc(elems, where) {
@@ -4972,9 +4981,9 @@ class TinyHtml_TinyHtml {
4972
4981
  * Ensures the input is returned as an single element/window/document element.
4973
4982
  * Useful to normalize operations across multiple or single element/window/document elements.
4974
4983
  *
4975
- * @param {TinyElementAndWinAndDoc|TinyElementAndWinAndDoc[]} elems - A single element/window element or array of html elements.
4984
+ * @param {TinyElementAndWinAndDoc|TinyElementAndWinAndDoc[]} elems - A single element/document/window element or array of html elements.
4976
4985
  * @param {string} where - The method or context name where validation is being called.
4977
- * @returns {ElementAndWindow} - Always returns an single element/window element.
4986
+ * @returns {ElementAndWindow} - Always returns an single element/document/window element.
4978
4987
  * @readonly
4979
4988
  */
4980
4989
  static _preElemAndWinAndDoc(elems, where) {
@@ -4988,6 +4997,32 @@ class TinyHtml_TinyHtml {
4988
4997
  return result;
4989
4998
  }
4990
4999
 
5000
+ /**
5001
+ * Ensures the input is returned as an array.
5002
+ * Useful to normalize operations across multiple or single element with document elements.
5003
+ *
5004
+ * @param {TinyElementWithDoc|TinyElementWithDoc[]} elems - A single element with document element or array of html elements.
5005
+ * @param {string} where - The method or context name where validation is being called.
5006
+ * @returns {ElementWithDoc[]} - Always returns an array of element with document elements.
5007
+ * @readonly
5008
+ */
5009
+ static _preElemsWithDoc(elems, where) {
5010
+ return TinyHtml_TinyHtml._preElemsTemplate(elems, where, [Element, Document], ['Element', 'Document']);
5011
+ }
5012
+
5013
+ /**
5014
+ * Ensures the input is returned as an single element with document element.
5015
+ * Useful to normalize operations across multiple or single element with document elements.
5016
+ *
5017
+ * @param {TinyElementWithDoc|TinyElementWithDoc[]} elems - A single element/window element or array of html elements.
5018
+ * @param {string} where - The method or context name where validation is being called.
5019
+ * @returns {ElementWithDoc} - Always returns an single element/window element.
5020
+ * @readonly
5021
+ */
5022
+ static _preElemWithDoc(elems, where) {
5023
+ return TinyHtml_TinyHtml._preElemTemplate(elems, where, [Element, Document], ['Element', 'Document']);
5024
+ }
5025
+
4991
5026
  /**
4992
5027
  * Normalizes and converts one or more DOM elements (or TinyHtml instances)
4993
5028
  * into an array of `TinyHtml` instances.
@@ -8247,12 +8282,120 @@ class TinyHtml_TinyHtml {
8247
8282
 
8248
8283
  ////////////////////////////////////////////
8249
8284
 
8285
+ /**
8286
+ * Registers a listener for the "paste" event to extract files and text from the clipboard (e.g., when the user presses Ctrl+V).
8287
+ *
8288
+ * This method allows reacting to pasted content by providing separate callbacks for files and plain text.
8289
+ * Useful for building file upload areas, rich-text editors, or input enhancements.
8290
+ *
8291
+ * @param {TinyElementWithDoc|TinyElementWithDoc[]} el - The target element(s) where the "paste" event will be listened.
8292
+ * @param {Object} [settings={}] - Optional callbacks to handle clipboard content.
8293
+ * @param {(data: DataTransferItem, file: File) => void} [settings.onFilePaste] - Called for each file pasted from the clipboard (e.g., images).
8294
+ * @param {(data: DataTransferItem, text: string) => void} [settings.onTextPaste] - Called when plain text is pasted from the clipboard.
8295
+ * @returns {EventListenerOrEventListenerObject} The internal "paste" event handler used.
8296
+ */
8297
+ static listenForPaste(el, { onFilePaste, onTextPaste } = {}) {
8298
+ if (typeof onFilePaste !== 'undefined' && typeof onFilePaste !== 'function')
8299
+ throw new TypeError('onFilePaste must be a function.');
8300
+ if (typeof onTextPaste !== 'undefined' && typeof onTextPaste !== 'function')
8301
+ throw new TypeError('onTextPaste must be a function.');
8302
+
8303
+ /** @type {EventListenerOrEventListenerObject} */
8304
+ const pasteEvent = (event) => {
8305
+ if (!(event instanceof ClipboardEvent)) return;
8306
+ const items = event.clipboardData?.items || [];
8307
+ for (const item of items) {
8308
+ if (item.kind === 'file') {
8309
+ if (typeof onFilePaste === 'function') {
8310
+ const file = item.getAsFile();
8311
+ if (file) onFilePaste(item, file);
8312
+ }
8313
+ } else if (item.kind === 'string') {
8314
+ if (typeof onTextPaste === 'function')
8315
+ item.getAsString((text) => onTextPaste(item, text));
8316
+ }
8317
+ }
8318
+ };
8319
+
8320
+ TinyHtml_TinyHtml._preElemsWithDoc(el, 'listenForPaste').forEach((elem) =>
8321
+ TinyHtml_TinyHtml.on(elem, 'paste', pasteEvent),
8322
+ );
8323
+ return pasteEvent;
8324
+ }
8325
+
8326
+ /**
8327
+ * Registers a listener for the "paste" event to extract files and text from the clipboard (e.g., when the user presses Ctrl+V).
8328
+ *
8329
+ * This method allows reacting to pasted content by providing separate callbacks for files and plain text.
8330
+ * Useful for building file upload areas, rich-text editors, or input enhancements.
8331
+ *
8332
+ * @param {Object} [settings={}] - Optional callbacks to handle clipboard content.
8333
+ * @param {(data: DataTransferItem, file: File) => void} [settings.onFilePaste] - Called for each file pasted from the clipboard (e.g., images).
8334
+ * @param {(data: DataTransferItem, text: string) => void} [settings.onTextPaste] - Called when plain text is pasted from the clipboard.
8335
+ * @returns {EventListenerOrEventListenerObject} The internal "paste" event handler used.
8336
+ */
8337
+ listenForPaste({ onFilePaste, onTextPaste } = {}) {
8338
+ return TinyHtml_TinyHtml.listenForPaste(this, { onFilePaste, onTextPaste });
8339
+ }
8340
+
8341
+ /**
8342
+ * Checks if the element has a listener for a specific event.
8343
+ *
8344
+ * @param {TinyEventTarget} el - The element to check.
8345
+ * @param {string} event - The event name to check.
8346
+ * @returns {boolean}
8347
+ */
8348
+ static hasEventListener(el, event) {
8349
+ const elem = TinyHtml_TinyHtml._preEventTargetElem(el, 'hasEventListener');
8350
+ if (!__eventRegistry.has(elem)) return false;
8351
+ const events = __eventRegistry.get(elem);
8352
+ return !!(events && Array.isArray(events[event]) && events[event].length > 0);
8353
+ }
8354
+
8355
+ /**
8356
+ * Checks if the element has a listener for a specific event.
8357
+ *
8358
+ * @param {string} event - The event name to check.
8359
+ * @returns {boolean}
8360
+ */
8361
+ hasEventListener(event) {
8362
+ return TinyHtml_TinyHtml.hasEventListener(this, event);
8363
+ }
8364
+
8365
+ /**
8366
+ * Checks if the element has the exact handler registered for a specific event.
8367
+ *
8368
+ * @param {TinyEventTarget} el - The element to check.
8369
+ * @param {string} event - The event name to check.
8370
+ * @param {EventListenerOrEventListenerObject} handler - The handler function to check.
8371
+ * @returns {boolean}
8372
+ */
8373
+ static hasExactEventListener(el, event, handler) {
8374
+ const elem = TinyHtml_TinyHtml._preEventTargetElem(el, 'hasExactEventListener');
8375
+ if (typeof handler !== 'function') throw new TypeError('The "handler" must be a function.');
8376
+ if (!__eventRegistry.has(elem)) return false;
8377
+ const events = __eventRegistry.get(elem);
8378
+ if (!events || !Array.isArray(events[event])) return false;
8379
+ return events[event].some((item) => item.handler === handler);
8380
+ }
8381
+
8382
+ /**
8383
+ * Checks if the element has the exact handler registered for a specific event.
8384
+ *
8385
+ * @param {string} event - The event name to check.
8386
+ * @param {EventListenerOrEventListenerObject} handler - The handler function to check.
8387
+ * @returns {boolean}
8388
+ */
8389
+ hasExactEventListener(event, handler) {
8390
+ return TinyHtml_TinyHtml.hasExactEventListener(this, event, handler);
8391
+ }
8392
+
8250
8393
  /**
8251
8394
  * Registers an event listener on the specified element.
8252
8395
  *
8253
8396
  * @param {TinyEventTarget|TinyEventTarget[]} el - The target to listen on.
8254
8397
  * @param {string} event - The event type (e.g. 'click', 'keydown').
8255
- * @param {EventRegistryHandle} handler - The callback function to run on event.
8398
+ * @param {EventListenerOrEventListenerObject|null} handler - The callback function to run on event.
8256
8399
  * @param {EventRegistryOptions} [options] - Optional event listener options.
8257
8400
  * @returns {TinyEventTarget|TinyEventTarget[]}
8258
8401
  */
@@ -8274,7 +8417,7 @@ class TinyHtml_TinyHtml {
8274
8417
  * Registers an event listener on the specified element.
8275
8418
  *
8276
8419
  * @param {string} event - The event type (e.g. 'click', 'keydown').
8277
- * @param {EventRegistryHandle} handler - The callback function to run on event.
8420
+ * @param {EventListenerOrEventListenerObject|null} handler - The callback function to run on event.
8278
8421
  * @param {EventRegistryOptions} [options] - Optional event listener options.
8279
8422
  * @returns {TinyEventTarget|TinyEventTarget[]}
8280
8423
  */
@@ -8287,17 +8430,17 @@ class TinyHtml_TinyHtml {
8287
8430
  *
8288
8431
  * @param {TinyEventTarget|TinyEventTarget[]} el - The target to listen on.
8289
8432
  * @param {string} event - The event type (e.g. 'click', 'keydown').
8290
- * @param {EventRegistryHandle} handler - The callback function to run on event.
8433
+ * @param {EventListenerOrEventListenerObject} handler - The callback function to run on event.
8291
8434
  * @param {EventRegistryOptions} [options={}] - Optional event listener options.
8292
8435
  * @returns {TinyEventTarget|TinyEventTarget[]}
8293
8436
  */
8294
8437
  static once(el, event, handler, options = {}) {
8295
8438
  if (typeof event !== 'string') throw new TypeError('The event name must be a string.');
8296
8439
  TinyHtml_TinyHtml._preEventTargetElems(el, 'once').forEach((elem) => {
8297
- /** @type {EventRegistryHandle} e */
8440
+ /** @type {EventListenerOrEventListenerObject} */
8298
8441
  const wrapped = (e) => {
8299
8442
  TinyHtml_TinyHtml.off(elem, event, wrapped);
8300
- handler(e);
8443
+ if (typeof handler === 'function') handler(e);
8301
8444
  };
8302
8445
 
8303
8446
  TinyHtml_TinyHtml.on(
@@ -8314,7 +8457,7 @@ class TinyHtml_TinyHtml {
8314
8457
  * Registers an event listener that runs only once, then is removed.
8315
8458
  *
8316
8459
  * @param {string} event - The event type (e.g. 'click', 'keydown').
8317
- * @param {EventRegistryHandle} handler - The callback function to run on event.
8460
+ * @param {EventListenerOrEventListenerObject} handler - The callback function to run on event.
8318
8461
  * @param {EventRegistryOptions} [options={}] - Optional event listener options.
8319
8462
  * @returns {TinyEventTarget|TinyEventTarget[]}
8320
8463
  */
@@ -8327,7 +8470,7 @@ class TinyHtml_TinyHtml {
8327
8470
  *
8328
8471
  * @param {TinyEventTarget|TinyEventTarget[]} el - The target element.
8329
8472
  * @param {string} event - The event type.
8330
- * @param {EventRegistryHandle} handler - The function originally bound to the event.
8473
+ * @param {EventListenerOrEventListenerObject|null} handler - The function originally bound to the event.
8331
8474
  * @param {boolean|EventListenerOptions} [options] - Optional listener options.
8332
8475
  * @returns {TinyEventTarget|TinyEventTarget[]}
8333
8476
  */
@@ -8349,7 +8492,7 @@ class TinyHtml_TinyHtml {
8349
8492
  * Removes a specific event listener from an element.
8350
8493
  *
8351
8494
  * @param {string} event - The event type.
8352
- * @param {EventRegistryHandle} handler - The function originally bound to the event.
8495
+ * @param {EventListenerOrEventListenerObject|null} handler - The function originally bound to the event.
8353
8496
  * @param {boolean|EventListenerOptions} [options] - Optional listener options.
8354
8497
  * @returns {TinyEventTarget|TinyEventTarget[]}
8355
8498
  */
@@ -8392,7 +8535,7 @@ class TinyHtml_TinyHtml {
8392
8535
  * Removes all event listeners of all types from the element.
8393
8536
  *
8394
8537
  * @param {TinyEventTarget|TinyEventTarget[]} el - The target element.
8395
- * @param {((handler: EventListenerOrEventListenerObject, event: string) => boolean)|null} [filterFn=null] -
8538
+ * @param {((handler: EventListenerOrEventListenerObject|null, event: string) => boolean)|null} [filterFn=null] -
8396
8539
  * Optional filter function to selectively remove specific handlers.
8397
8540
  * @returns {TinyEventTarget|TinyEventTarget[]}
8398
8541
  */
@@ -8419,7 +8562,7 @@ class TinyHtml_TinyHtml {
8419
8562
  /**
8420
8563
  * Removes all event listeners of all types from the element.
8421
8564
  *
8422
- * @param {((handler: EventListenerOrEventListenerObject, event: string) => boolean)|null} [filterFn=null] -
8565
+ * @param {((handler: EventListenerOrEventListenerObject|null, event: string) => boolean)|null} [filterFn=null] -
8423
8566
  * Optional filter function to selectively remove specific handlers.
8424
8567
  * @returns {TinyEventTarget|TinyEventTarget[]}
8425
8568
  */
@@ -11970,6 +12113,8 @@ class TinySmartScroller {
11970
12113
 
11971
12114
 
11972
12115
 
12116
+
12117
+
11973
12118
 
11974
12119
 
11975
12120