tiny-essentials 1.17.0 → 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.
- package/dist/v1/TinyBasicsEs.js +336 -45
- package/dist/v1/TinyBasicsEs.min.js +1 -1
- package/dist/v1/TinyClipboard.js +459 -0
- package/dist/v1/TinyClipboard.min.js +1 -0
- package/dist/v1/TinyDragger.js +336 -45
- package/dist/v1/TinyDragger.min.js +1 -1
- package/dist/v1/TinyEssentials.js +1218 -45
- package/dist/v1/TinyEssentials.min.js +1 -1
- package/dist/v1/TinyHtml.js +336 -45
- package/dist/v1/TinyHtml.min.js +1 -1
- package/dist/v1/TinySmartScroller.js +336 -45
- package/dist/v1/TinySmartScroller.min.js +1 -1
- package/dist/v1/TinyTextRangeEditor.js +497 -0
- package/dist/v1/TinyTextRangeEditor.min.js +1 -0
- package/dist/v1/TinyUploadClicker.js +338 -45
- package/dist/v1/TinyUploadClicker.min.js +1 -1
- package/dist/v1/build/TinyClipboard.cjs +7 -0
- package/dist/v1/build/TinyClipboard.d.mts +3 -0
- package/dist/v1/build/TinyClipboard.mjs +2 -0
- package/dist/v1/build/TinyTextRangeEditor.cjs +7 -0
- package/dist/v1/build/TinyTextRangeEditor.d.mts +3 -0
- package/dist/v1/build/TinyTextRangeEditor.mjs +2 -0
- package/dist/v1/index.cjs +4 -0
- package/dist/v1/index.d.mts +3 -1
- package/dist/v1/index.mjs +3 -1
- package/dist/v1/libs/TinyClipboard.cjs +420 -0
- package/dist/v1/libs/TinyClipboard.d.mts +155 -0
- package/dist/v1/libs/TinyClipboard.mjs +398 -0
- package/dist/v1/libs/TinyHtml.cjs +336 -45
- package/dist/v1/libs/TinyHtml.d.mts +238 -27
- package/dist/v1/libs/TinyHtml.mjs +320 -47
- package/dist/v1/libs/TinyTextRangeEditor.cjs +458 -0
- package/dist/v1/libs/TinyTextRangeEditor.d.mts +200 -0
- package/dist/v1/libs/TinyTextRangeEditor.mjs +424 -0
- package/docs/v1/README.md +2 -0
- package/docs/v1/libs/TinyClipboard.md +213 -0
- package/docs/v1/libs/TinyHtml.md +211 -15
- package/docs/v1/libs/TinyTextRangeEditor.md +208 -0
- package/package.json +1 -1
|
@@ -470,6 +470,19 @@ const {
|
|
|
470
470
|
areElsCollRight: TinyHtml_areElsCollRight,
|
|
471
471
|
} = collision_namespaceObject;
|
|
472
472
|
|
|
473
|
+
/**
|
|
474
|
+
* Callback invoked on each animation frame with the current scroll position,
|
|
475
|
+
* normalized animation time (`0` to `1`), and a completion flag.
|
|
476
|
+
*
|
|
477
|
+
* @typedef {(progress: { x: number, y: number, isComplete: boolean, time: number }) => void} OnScrollAnimation
|
|
478
|
+
*/
|
|
479
|
+
|
|
480
|
+
/**
|
|
481
|
+
* A list of supported easing function names for smooth animations.
|
|
482
|
+
*
|
|
483
|
+
* @typedef {'linear' | 'easeInQuad' | 'easeOutQuad' | 'easeInOutQuad' | 'easeInCubic' | 'easeOutCubic' | 'easeInOutCubic'} Easings
|
|
484
|
+
*/
|
|
485
|
+
|
|
473
486
|
/**
|
|
474
487
|
* Represents a raw Node element or an instance of TinyHtml.
|
|
475
488
|
* This type is used to abstract interactions with both plain elements
|
|
@@ -540,6 +553,21 @@ const {
|
|
|
540
553
|
* @typedef {Element|Window|Document} ElementAndWinAndDoc
|
|
541
554
|
*/
|
|
542
555
|
|
|
556
|
+
/**
|
|
557
|
+
* Represents a raw DOM element with document or an instance of TinyHtml.
|
|
558
|
+
* This type is used to abstract interactions with both plain elements
|
|
559
|
+
* and wrapped elements via the TinyHtml class.
|
|
560
|
+
*
|
|
561
|
+
* @typedef {ElementWithDoc|TinyHtml} TinyElementWithDoc
|
|
562
|
+
*/
|
|
563
|
+
|
|
564
|
+
/**
|
|
565
|
+
* Represents a value that can be either a DOM Element, or the document object.
|
|
566
|
+
* Useful for functions that operate generically on measurable targets.
|
|
567
|
+
*
|
|
568
|
+
* @typedef {Element|Document} ElementWithDoc
|
|
569
|
+
*/
|
|
570
|
+
|
|
543
571
|
/**
|
|
544
572
|
* A parameter type used for filtering or matching elements.
|
|
545
573
|
* It can be:
|
|
@@ -559,12 +587,6 @@ const {
|
|
|
559
587
|
* @typedef {Window|Element|Document|Text} ConstructorElValues
|
|
560
588
|
*/
|
|
561
589
|
|
|
562
|
-
/**
|
|
563
|
-
* The handler function used in event listeners.
|
|
564
|
-
*
|
|
565
|
-
* @typedef {(e: Event) => any} EventRegistryHandle
|
|
566
|
-
*/
|
|
567
|
-
|
|
568
590
|
/**
|
|
569
591
|
* Options passed to `addEventListener` or `removeEventListener`.
|
|
570
592
|
* Can be a boolean or an object of type `AddEventListenerOptions`.
|
|
@@ -576,7 +598,7 @@ const {
|
|
|
576
598
|
* Structure describing a registered event callback and its options.
|
|
577
599
|
*
|
|
578
600
|
* @typedef {Object} EventRegistryItem
|
|
579
|
-
* @property {
|
|
601
|
+
* @property {EventListenerOrEventListenerObject|null} handler - The function to be executed when the event is triggered.
|
|
580
602
|
* @property {EventRegistryOptions} [options] - Optional configuration passed to the listener.
|
|
581
603
|
*/
|
|
582
604
|
|
|
@@ -1135,9 +1157,9 @@ class TinyHtml {
|
|
|
1135
1157
|
* Ensures the input is returned as an array.
|
|
1136
1158
|
* Useful to normalize operations across multiple or single element/window/document elements.
|
|
1137
1159
|
*
|
|
1138
|
-
* @param {TinyElementAndWinAndDoc|TinyElementAndWinAndDoc[]} elems - A single element/window element or array of html elements.
|
|
1160
|
+
* @param {TinyElementAndWinAndDoc|TinyElementAndWinAndDoc[]} elems - A single element/document/window element or array of html elements.
|
|
1139
1161
|
* @param {string} where - The method or context name where validation is being called.
|
|
1140
|
-
* @returns {ElementAndWindow[]} - Always returns an array of element/window elements.
|
|
1162
|
+
* @returns {ElementAndWindow[]} - Always returns an array of element/document/window elements.
|
|
1141
1163
|
* @readonly
|
|
1142
1164
|
*/
|
|
1143
1165
|
static _preElemsAndWinAndDoc(elems, where) {
|
|
@@ -1154,9 +1176,9 @@ class TinyHtml {
|
|
|
1154
1176
|
* Ensures the input is returned as an single element/window/document element.
|
|
1155
1177
|
* Useful to normalize operations across multiple or single element/window/document elements.
|
|
1156
1178
|
*
|
|
1157
|
-
* @param {TinyElementAndWinAndDoc|TinyElementAndWinAndDoc[]} elems - A single element/window element or array of html elements.
|
|
1179
|
+
* @param {TinyElementAndWinAndDoc|TinyElementAndWinAndDoc[]} elems - A single element/document/window element or array of html elements.
|
|
1158
1180
|
* @param {string} where - The method or context name where validation is being called.
|
|
1159
|
-
* @returns {ElementAndWindow} - Always returns an single element/window element.
|
|
1181
|
+
* @returns {ElementAndWindow} - Always returns an single element/document/window element.
|
|
1160
1182
|
* @readonly
|
|
1161
1183
|
*/
|
|
1162
1184
|
static _preElemAndWinAndDoc(elems, where) {
|
|
@@ -1170,6 +1192,32 @@ class TinyHtml {
|
|
|
1170
1192
|
return result;
|
|
1171
1193
|
}
|
|
1172
1194
|
|
|
1195
|
+
/**
|
|
1196
|
+
* Ensures the input is returned as an array.
|
|
1197
|
+
* Useful to normalize operations across multiple or single element with document elements.
|
|
1198
|
+
*
|
|
1199
|
+
* @param {TinyElementWithDoc|TinyElementWithDoc[]} elems - A single element with document element or array of html elements.
|
|
1200
|
+
* @param {string} where - The method or context name where validation is being called.
|
|
1201
|
+
* @returns {ElementWithDoc[]} - Always returns an array of element with document elements.
|
|
1202
|
+
* @readonly
|
|
1203
|
+
*/
|
|
1204
|
+
static _preElemsWithDoc(elems, where) {
|
|
1205
|
+
return TinyHtml._preElemsTemplate(elems, where, [Element, Document], ['Element', 'Document']);
|
|
1206
|
+
}
|
|
1207
|
+
|
|
1208
|
+
/**
|
|
1209
|
+
* Ensures the input is returned as an single element with document element.
|
|
1210
|
+
* Useful to normalize operations across multiple or single element with document elements.
|
|
1211
|
+
*
|
|
1212
|
+
* @param {TinyElementWithDoc|TinyElementWithDoc[]} elems - A single element/window element or array of html elements.
|
|
1213
|
+
* @param {string} where - The method or context name where validation is being called.
|
|
1214
|
+
* @returns {ElementWithDoc} - Always returns an single element/window element.
|
|
1215
|
+
* @readonly
|
|
1216
|
+
*/
|
|
1217
|
+
static _preElemWithDoc(elems, where) {
|
|
1218
|
+
return TinyHtml._preElemTemplate(elems, where, [Element, Document], ['Element', 'Document']);
|
|
1219
|
+
}
|
|
1220
|
+
|
|
1173
1221
|
/**
|
|
1174
1222
|
* Normalizes and converts one or more DOM elements (or TinyHtml instances)
|
|
1175
1223
|
* into an array of `TinyHtml` instances.
|
|
@@ -2878,7 +2926,7 @@ class TinyHtml {
|
|
|
2878
2926
|
*/
|
|
2879
2927
|
static setWinScrollTop(value) {
|
|
2880
2928
|
if (typeof value !== 'number') throw new TypeError('The value must be a number.');
|
|
2881
|
-
|
|
2929
|
+
TinyHtml.setScrollTop(window, value);
|
|
2882
2930
|
}
|
|
2883
2931
|
|
|
2884
2932
|
/**
|
|
@@ -2887,7 +2935,7 @@ class TinyHtml {
|
|
|
2887
2935
|
*/
|
|
2888
2936
|
static setWinScrollLeft(value) {
|
|
2889
2937
|
if (typeof value !== 'number') throw new TypeError('The value must be a number.');
|
|
2890
|
-
|
|
2938
|
+
TinyHtml.setScrollLeft(window, value);
|
|
2891
2939
|
}
|
|
2892
2940
|
|
|
2893
2941
|
/**
|
|
@@ -3204,6 +3252,30 @@ class TinyHtml {
|
|
|
3204
3252
|
|
|
3205
3253
|
//////////////////////////////////////////////////
|
|
3206
3254
|
|
|
3255
|
+
/**
|
|
3256
|
+
* Applies an animation to one or multiple TinyElement instances.
|
|
3257
|
+
*
|
|
3258
|
+
* @param {TinyElement|TinyElement[]} el - A single TinyElement or an array of TinyElements to animate.
|
|
3259
|
+
* @param {Keyframe[] | PropertyIndexedKeyframes | null} keyframes - The keyframes used to define the animation.
|
|
3260
|
+
* @param {number | KeyframeAnimationOptions} [ops] - Timing or configuration options for the animation.
|
|
3261
|
+
* @returns {TinyElement|TinyElement[]}
|
|
3262
|
+
*/
|
|
3263
|
+
static animate(el, keyframes, ops) {
|
|
3264
|
+
TinyHtml._preElems(el, 'animate').forEach((elem) => elem.animate(keyframes, ops));
|
|
3265
|
+
return el;
|
|
3266
|
+
}
|
|
3267
|
+
|
|
3268
|
+
/**
|
|
3269
|
+
* Applies an animation to one or multiple TinyElement instances.
|
|
3270
|
+
*
|
|
3271
|
+
* @param {Keyframe[] | PropertyIndexedKeyframes | null} keyframes - The keyframes used to define the animation.
|
|
3272
|
+
* @param {number | KeyframeAnimationOptions} [ops] - Timing or configuration options for the animation.
|
|
3273
|
+
* @returns {TinyElement|TinyElement[]}
|
|
3274
|
+
*/
|
|
3275
|
+
animate(keyframes, ops) {
|
|
3276
|
+
return TinyHtml.animate(this, keyframes, ops);
|
|
3277
|
+
}
|
|
3278
|
+
|
|
3207
3279
|
/**
|
|
3208
3280
|
* Gets the offset of the element relative to the document.
|
|
3209
3281
|
* @param {TinyElement} el - Target element.
|
|
@@ -3359,26 +3431,147 @@ class TinyHtml {
|
|
|
3359
3431
|
}
|
|
3360
3432
|
|
|
3361
3433
|
/**
|
|
3362
|
-
*
|
|
3363
|
-
*
|
|
3364
|
-
*
|
|
3365
|
-
* @
|
|
3434
|
+
* Collection of easing functions used for scroll and animation calculations.
|
|
3435
|
+
* Each function receives a normalized time value (`t` from 0 to 1) and returns the eased progress.
|
|
3436
|
+
*
|
|
3437
|
+
* @type {Record<string, (t: number) => number>}
|
|
3366
3438
|
*/
|
|
3367
|
-
static
|
|
3368
|
-
|
|
3369
|
-
|
|
3370
|
-
|
|
3371
|
-
|
|
3439
|
+
static easings = {
|
|
3440
|
+
linear: (t) => t,
|
|
3441
|
+
easeInQuad: (t) => t * t,
|
|
3442
|
+
easeOutQuad: (t) => t * (2 - t),
|
|
3443
|
+
easeInOutQuad: (t) => (t < 0.5 ? 2 * t * t : -1 + (4 - 2 * t) * t),
|
|
3444
|
+
easeInCubic: (t) => t * t * t,
|
|
3445
|
+
easeOutCubic: (t) => --t * t * t + 1,
|
|
3446
|
+
easeInOutCubic: (t) => (t < 0.5 ? 4 * t * t * t : (t - 1) * (2 * t - 2) * (2 * t - 2) + 1),
|
|
3447
|
+
};
|
|
3448
|
+
|
|
3449
|
+
/**
|
|
3450
|
+
* Smoothly scrolls one or more elements (or the window) to the specified X and Y coordinates
|
|
3451
|
+
* using a custom duration and easing function.
|
|
3452
|
+
*
|
|
3453
|
+
* If `duration` or a valid `easing` is not provided, the scroll will be performed immediately.
|
|
3454
|
+
*
|
|
3455
|
+
* @param {TinyElementAndWindow | TinyElementAndWindow[]} el - A single element, array of elements, or the window to scroll.
|
|
3456
|
+
* @param {Object} [settings={}] - Configuration object for the scroll animation.
|
|
3457
|
+
* @param {number} [settings.targetX] - The horizontal scroll target in pixels.
|
|
3458
|
+
* @param {number} [settings.targetY] - The vertical scroll target in pixels.
|
|
3459
|
+
* @param {number} [settings.duration] - The duration of the animation in milliseconds.
|
|
3460
|
+
* @param {Easings} [settings.easing] - The easing function name to use for the scroll animation.
|
|
3461
|
+
* @param {OnScrollAnimation} [settings.onAnimation] - Optional callback invoked on each animation
|
|
3462
|
+
* frame with the current scroll position, normalized animation time (`0` to `1`), and a completion flag.
|
|
3463
|
+
* @returns {TinyElementAndWindow|TinyElementAndWindow[]}
|
|
3464
|
+
* @throws {TypeError} If `el` is not a valid element, array, or window.
|
|
3465
|
+
* @throws {TypeError} If `targetX` or `targetY` is defined but not a number.
|
|
3466
|
+
* @throws {TypeError} If `duration` is defined but not a number.
|
|
3467
|
+
* @throws {TypeError} If `easing` is defined but not a valid easing function name.
|
|
3468
|
+
* @throws {TypeError} If `onAnimation` is defined but not a function.
|
|
3469
|
+
*/
|
|
3470
|
+
static scrollToXY(el, { targetX, targetY, duration, easing, onAnimation } = {}) {
|
|
3471
|
+
if (targetX !== undefined && typeof targetX !== 'number')
|
|
3472
|
+
throw new TypeError('`targetX` must be a number if provided.');
|
|
3473
|
+
if (targetY !== undefined && typeof targetY !== 'number')
|
|
3474
|
+
throw new TypeError('`targetY` must be a number if provided.');
|
|
3475
|
+
if (duration !== undefined && typeof duration !== 'number')
|
|
3476
|
+
throw new TypeError('`duration` must be a number if provided.');
|
|
3477
|
+
if (easing !== undefined && typeof easing !== 'string')
|
|
3478
|
+
throw new TypeError('`easing` must be a string if provided.');
|
|
3479
|
+
if (easing !== undefined && typeof TinyHtml.easings[easing] !== 'function')
|
|
3480
|
+
throw new TypeError(`Unknown easing function: "${easing}".`);
|
|
3481
|
+
if (onAnimation !== undefined && typeof onAnimation !== 'function')
|
|
3482
|
+
throw new TypeError('`onAnimation` must be a function if provided.');
|
|
3483
|
+
|
|
3484
|
+
/**
|
|
3485
|
+
* Performs an instant scroll to the given coordinates.
|
|
3486
|
+
*
|
|
3487
|
+
* @param {ElementAndWindow} elem - The element or window to scroll.
|
|
3488
|
+
* @param {number} newX - The final horizontal scroll position.
|
|
3489
|
+
* @param {number} newY - The final vertical scroll position.
|
|
3490
|
+
* @param {number} time - Normalized progress value.
|
|
3491
|
+
*/
|
|
3492
|
+
const executeScroll = (elem, newX, newY, time) => {
|
|
3493
|
+
if (elem instanceof Window) {
|
|
3494
|
+
window.scrollTo(newX, newY);
|
|
3372
3495
|
} else if (elem.nodeType === 9) {
|
|
3373
3496
|
// @ts-ignore
|
|
3374
|
-
elem.defaultView.scrollTo(
|
|
3497
|
+
elem.defaultView.scrollTo(newX, newY);
|
|
3375
3498
|
} else {
|
|
3376
|
-
elem.
|
|
3499
|
+
const startX = elem instanceof Window ? window.scrollX : elem.scrollLeft;
|
|
3500
|
+
const startY = elem instanceof Window ? window.scrollY : elem.scrollTop;
|
|
3501
|
+
if (startX !== newX) elem.scrollLeft = newX;
|
|
3502
|
+
if (startY !== newY) elem.scrollTop = newY;
|
|
3377
3503
|
}
|
|
3504
|
+
if (typeof onAnimation === 'function')
|
|
3505
|
+
onAnimation({ x: newX, y: newY, isComplete: time >= 1, time });
|
|
3506
|
+
};
|
|
3507
|
+
|
|
3508
|
+
TinyHtml._preElemsAndWindow(el, 'scrollToXY').forEach((elem) => {
|
|
3509
|
+
const startX = elem instanceof Window ? window.scrollX : elem.scrollLeft;
|
|
3510
|
+
const startY = elem instanceof Window ? window.scrollY : elem.scrollTop;
|
|
3511
|
+
const targX = targetX ?? startX;
|
|
3512
|
+
const targY = targetY ?? startY;
|
|
3513
|
+
|
|
3514
|
+
const changeX = targX - startX;
|
|
3515
|
+
const changeY = targY - startY;
|
|
3516
|
+
|
|
3517
|
+
const ease = (typeof easing === 'string' && TinyHtml.easings[easing]) || null;
|
|
3518
|
+
if (typeof duration !== 'number' || typeof ease !== 'function')
|
|
3519
|
+
return executeScroll(elem, targX, targY, 1);
|
|
3520
|
+
const startTime = performance.now();
|
|
3521
|
+
const dur = duration ?? 0;
|
|
3522
|
+
|
|
3523
|
+
/**
|
|
3524
|
+
* Animates the scroll position based on easing and time.
|
|
3525
|
+
*
|
|
3526
|
+
* @param {number} currentTime - Timestamp provided by requestAnimationFrame.
|
|
3527
|
+
*/
|
|
3528
|
+
function animateScroll(currentTime) {
|
|
3529
|
+
if (typeof ease !== 'function') return;
|
|
3530
|
+
const time = Math.min(1, (currentTime - startTime) / dur);
|
|
3531
|
+
const easedTime = ease(time);
|
|
3532
|
+
|
|
3533
|
+
const newX = startX + changeX * easedTime;
|
|
3534
|
+
const newY = startY + changeY * easedTime;
|
|
3535
|
+
executeScroll(elem, newX, newY, time);
|
|
3536
|
+
|
|
3537
|
+
if (time < 1) requestAnimationFrame(animateScroll);
|
|
3538
|
+
}
|
|
3539
|
+
|
|
3540
|
+
requestAnimationFrame(animateScroll);
|
|
3378
3541
|
});
|
|
3379
3542
|
return el;
|
|
3380
3543
|
}
|
|
3381
3544
|
|
|
3545
|
+
/**
|
|
3546
|
+
* Smoothly scrolls one or more elements (or the window) to the specified X and Y coordinates
|
|
3547
|
+
* using a custom duration and easing function.
|
|
3548
|
+
*
|
|
3549
|
+
* If `duration` or a valid `easing` is not provided, the scroll will be performed immediately.
|
|
3550
|
+
*
|
|
3551
|
+
* @param {Object} [settings={}] - Configuration object for the scroll animation.
|
|
3552
|
+
* @param {number} [settings.targetX] - The horizontal scroll target in pixels.
|
|
3553
|
+
* @param {number} [settings.targetY] - The vertical scroll target in pixels.
|
|
3554
|
+
* @param {number} [settings.duration] - The duration of the animation in milliseconds.
|
|
3555
|
+
* @param {Easings} [settings.easing] - The easing function name to use for the scroll animation.
|
|
3556
|
+
* @param {OnScrollAnimation} [settings.onAnimation] - Optional callback invoked on each animation
|
|
3557
|
+
* frame with the current scroll position, normalized animation time (`0` to `1`), and a completion flag.
|
|
3558
|
+
* @returns {TinyElementAndWindow|TinyElementAndWindow[]}
|
|
3559
|
+
*/
|
|
3560
|
+
scrollToXY({ targetX, targetY, duration, easing, onAnimation } = {}) {
|
|
3561
|
+
return TinyHtml.scrollToXY(this, { targetX, targetY, duration, easing, onAnimation });
|
|
3562
|
+
}
|
|
3563
|
+
|
|
3564
|
+
/**
|
|
3565
|
+
* Sets the vertical scroll position.
|
|
3566
|
+
* @param {TinyElementAndWindow|TinyElementAndWindow[]} el - Element or window.
|
|
3567
|
+
* @param {number} value - Scroll top value.
|
|
3568
|
+
* @returns {TinyElementAndWindow|TinyElementAndWindow[]}
|
|
3569
|
+
*/
|
|
3570
|
+
static setScrollTop(el, value) {
|
|
3571
|
+
if (typeof value !== 'number') throw new TypeError('ScrollTop value must be a number.');
|
|
3572
|
+
return TinyHtml.scrollToXY(el, { targetY: value });
|
|
3573
|
+
}
|
|
3574
|
+
|
|
3382
3575
|
/**
|
|
3383
3576
|
* Sets the vertical scroll position.
|
|
3384
3577
|
* @param {number} value - Scroll top value.
|
|
@@ -3396,17 +3589,7 @@ class TinyHtml {
|
|
|
3396
3589
|
*/
|
|
3397
3590
|
static setScrollLeft(el, value) {
|
|
3398
3591
|
if (typeof value !== 'number') throw new TypeError('ScrollLeft value must be a number.');
|
|
3399
|
-
TinyHtml.
|
|
3400
|
-
if (TinyHtml.isWindow(elem)) {
|
|
3401
|
-
elem.scrollTo(value, elem.pageYOffset);
|
|
3402
|
-
} else if (elem.nodeType === 9) {
|
|
3403
|
-
// @ts-ignore
|
|
3404
|
-
elem.defaultView.scrollTo(value, elem.defaultView.pageYOffset);
|
|
3405
|
-
} else {
|
|
3406
|
-
elem.scrollLeft = value;
|
|
3407
|
-
}
|
|
3408
|
-
});
|
|
3409
|
-
return el;
|
|
3592
|
+
return TinyHtml.scrollToXY(el, { targetX: value });
|
|
3410
3593
|
}
|
|
3411
3594
|
|
|
3412
3595
|
/**
|
|
@@ -4294,12 +4477,120 @@ class TinyHtml {
|
|
|
4294
4477
|
|
|
4295
4478
|
////////////////////////////////////////////
|
|
4296
4479
|
|
|
4480
|
+
/**
|
|
4481
|
+
* Registers a listener for the "paste" event to extract files and text from the clipboard (e.g., when the user presses Ctrl+V).
|
|
4482
|
+
*
|
|
4483
|
+
* This method allows reacting to pasted content by providing separate callbacks for files and plain text.
|
|
4484
|
+
* Useful for building file upload areas, rich-text editors, or input enhancements.
|
|
4485
|
+
*
|
|
4486
|
+
* @param {TinyElementWithDoc|TinyElementWithDoc[]} el - The target element(s) where the "paste" event will be listened.
|
|
4487
|
+
* @param {Object} [settings={}] - Optional callbacks to handle clipboard content.
|
|
4488
|
+
* @param {(data: DataTransferItem, file: File) => void} [settings.onFilePaste] - Called for each file pasted from the clipboard (e.g., images).
|
|
4489
|
+
* @param {(data: DataTransferItem, text: string) => void} [settings.onTextPaste] - Called when plain text is pasted from the clipboard.
|
|
4490
|
+
* @returns {EventListenerOrEventListenerObject} The internal "paste" event handler used.
|
|
4491
|
+
*/
|
|
4492
|
+
static listenForPaste(el, { onFilePaste, onTextPaste } = {}) {
|
|
4493
|
+
if (typeof onFilePaste !== 'undefined' && typeof onFilePaste !== 'function')
|
|
4494
|
+
throw new TypeError('onFilePaste must be a function.');
|
|
4495
|
+
if (typeof onTextPaste !== 'undefined' && typeof onTextPaste !== 'function')
|
|
4496
|
+
throw new TypeError('onTextPaste must be a function.');
|
|
4497
|
+
|
|
4498
|
+
/** @type {EventListenerOrEventListenerObject} */
|
|
4499
|
+
const pasteEvent = (event) => {
|
|
4500
|
+
if (!(event instanceof ClipboardEvent)) return;
|
|
4501
|
+
const items = event.clipboardData?.items || [];
|
|
4502
|
+
for (const item of items) {
|
|
4503
|
+
if (item.kind === 'file') {
|
|
4504
|
+
if (typeof onFilePaste === 'function') {
|
|
4505
|
+
const file = item.getAsFile();
|
|
4506
|
+
if (file) onFilePaste(item, file);
|
|
4507
|
+
}
|
|
4508
|
+
} else if (item.kind === 'string') {
|
|
4509
|
+
if (typeof onTextPaste === 'function')
|
|
4510
|
+
item.getAsString((text) => onTextPaste(item, text));
|
|
4511
|
+
}
|
|
4512
|
+
}
|
|
4513
|
+
};
|
|
4514
|
+
|
|
4515
|
+
TinyHtml._preElemsWithDoc(el, 'listenForPaste').forEach((elem) =>
|
|
4516
|
+
TinyHtml.on(elem, 'paste', pasteEvent),
|
|
4517
|
+
);
|
|
4518
|
+
return pasteEvent;
|
|
4519
|
+
}
|
|
4520
|
+
|
|
4521
|
+
/**
|
|
4522
|
+
* Registers a listener for the "paste" event to extract files and text from the clipboard (e.g., when the user presses Ctrl+V).
|
|
4523
|
+
*
|
|
4524
|
+
* This method allows reacting to pasted content by providing separate callbacks for files and plain text.
|
|
4525
|
+
* Useful for building file upload areas, rich-text editors, or input enhancements.
|
|
4526
|
+
*
|
|
4527
|
+
* @param {Object} [settings={}] - Optional callbacks to handle clipboard content.
|
|
4528
|
+
* @param {(data: DataTransferItem, file: File) => void} [settings.onFilePaste] - Called for each file pasted from the clipboard (e.g., images).
|
|
4529
|
+
* @param {(data: DataTransferItem, text: string) => void} [settings.onTextPaste] - Called when plain text is pasted from the clipboard.
|
|
4530
|
+
* @returns {EventListenerOrEventListenerObject} The internal "paste" event handler used.
|
|
4531
|
+
*/
|
|
4532
|
+
listenForPaste({ onFilePaste, onTextPaste } = {}) {
|
|
4533
|
+
return TinyHtml.listenForPaste(this, { onFilePaste, onTextPaste });
|
|
4534
|
+
}
|
|
4535
|
+
|
|
4536
|
+
/**
|
|
4537
|
+
* Checks if the element has a listener for a specific event.
|
|
4538
|
+
*
|
|
4539
|
+
* @param {TinyEventTarget} el - The element to check.
|
|
4540
|
+
* @param {string} event - The event name to check.
|
|
4541
|
+
* @returns {boolean}
|
|
4542
|
+
*/
|
|
4543
|
+
static hasEventListener(el, event) {
|
|
4544
|
+
const elem = TinyHtml._preEventTargetElem(el, 'hasEventListener');
|
|
4545
|
+
if (!__eventRegistry.has(elem)) return false;
|
|
4546
|
+
const events = __eventRegistry.get(elem);
|
|
4547
|
+
return !!(events && Array.isArray(events[event]) && events[event].length > 0);
|
|
4548
|
+
}
|
|
4549
|
+
|
|
4550
|
+
/**
|
|
4551
|
+
* Checks if the element has a listener for a specific event.
|
|
4552
|
+
*
|
|
4553
|
+
* @param {string} event - The event name to check.
|
|
4554
|
+
* @returns {boolean}
|
|
4555
|
+
*/
|
|
4556
|
+
hasEventListener(event) {
|
|
4557
|
+
return TinyHtml.hasEventListener(this, event);
|
|
4558
|
+
}
|
|
4559
|
+
|
|
4560
|
+
/**
|
|
4561
|
+
* Checks if the element has the exact handler registered for a specific event.
|
|
4562
|
+
*
|
|
4563
|
+
* @param {TinyEventTarget} el - The element to check.
|
|
4564
|
+
* @param {string} event - The event name to check.
|
|
4565
|
+
* @param {EventListenerOrEventListenerObject} handler - The handler function to check.
|
|
4566
|
+
* @returns {boolean}
|
|
4567
|
+
*/
|
|
4568
|
+
static hasExactEventListener(el, event, handler) {
|
|
4569
|
+
const elem = TinyHtml._preEventTargetElem(el, 'hasExactEventListener');
|
|
4570
|
+
if (typeof handler !== 'function') throw new TypeError('The "handler" must be a function.');
|
|
4571
|
+
if (!__eventRegistry.has(elem)) return false;
|
|
4572
|
+
const events = __eventRegistry.get(elem);
|
|
4573
|
+
if (!events || !Array.isArray(events[event])) return false;
|
|
4574
|
+
return events[event].some((item) => item.handler === handler);
|
|
4575
|
+
}
|
|
4576
|
+
|
|
4577
|
+
/**
|
|
4578
|
+
* Checks if the element has the exact handler registered for a specific event.
|
|
4579
|
+
*
|
|
4580
|
+
* @param {string} event - The event name to check.
|
|
4581
|
+
* @param {EventListenerOrEventListenerObject} handler - The handler function to check.
|
|
4582
|
+
* @returns {boolean}
|
|
4583
|
+
*/
|
|
4584
|
+
hasExactEventListener(event, handler) {
|
|
4585
|
+
return TinyHtml.hasExactEventListener(this, event, handler);
|
|
4586
|
+
}
|
|
4587
|
+
|
|
4297
4588
|
/**
|
|
4298
4589
|
* Registers an event listener on the specified element.
|
|
4299
4590
|
*
|
|
4300
4591
|
* @param {TinyEventTarget|TinyEventTarget[]} el - The target to listen on.
|
|
4301
4592
|
* @param {string} event - The event type (e.g. 'click', 'keydown').
|
|
4302
|
-
* @param {
|
|
4593
|
+
* @param {EventListenerOrEventListenerObject|null} handler - The callback function to run on event.
|
|
4303
4594
|
* @param {EventRegistryOptions} [options] - Optional event listener options.
|
|
4304
4595
|
* @returns {TinyEventTarget|TinyEventTarget[]}
|
|
4305
4596
|
*/
|
|
@@ -4321,7 +4612,7 @@ class TinyHtml {
|
|
|
4321
4612
|
* Registers an event listener on the specified element.
|
|
4322
4613
|
*
|
|
4323
4614
|
* @param {string} event - The event type (e.g. 'click', 'keydown').
|
|
4324
|
-
* @param {
|
|
4615
|
+
* @param {EventListenerOrEventListenerObject|null} handler - The callback function to run on event.
|
|
4325
4616
|
* @param {EventRegistryOptions} [options] - Optional event listener options.
|
|
4326
4617
|
* @returns {TinyEventTarget|TinyEventTarget[]}
|
|
4327
4618
|
*/
|
|
@@ -4334,17 +4625,17 @@ class TinyHtml {
|
|
|
4334
4625
|
*
|
|
4335
4626
|
* @param {TinyEventTarget|TinyEventTarget[]} el - The target to listen on.
|
|
4336
4627
|
* @param {string} event - The event type (e.g. 'click', 'keydown').
|
|
4337
|
-
* @param {
|
|
4628
|
+
* @param {EventListenerOrEventListenerObject} handler - The callback function to run on event.
|
|
4338
4629
|
* @param {EventRegistryOptions} [options={}] - Optional event listener options.
|
|
4339
4630
|
* @returns {TinyEventTarget|TinyEventTarget[]}
|
|
4340
4631
|
*/
|
|
4341
4632
|
static once(el, event, handler, options = {}) {
|
|
4342
4633
|
if (typeof event !== 'string') throw new TypeError('The event name must be a string.');
|
|
4343
4634
|
TinyHtml._preEventTargetElems(el, 'once').forEach((elem) => {
|
|
4344
|
-
/** @type {
|
|
4635
|
+
/** @type {EventListenerOrEventListenerObject} */
|
|
4345
4636
|
const wrapped = (e) => {
|
|
4346
4637
|
TinyHtml.off(elem, event, wrapped);
|
|
4347
|
-
handler(e);
|
|
4638
|
+
if (typeof handler === 'function') handler(e);
|
|
4348
4639
|
};
|
|
4349
4640
|
|
|
4350
4641
|
TinyHtml.on(
|
|
@@ -4361,7 +4652,7 @@ class TinyHtml {
|
|
|
4361
4652
|
* Registers an event listener that runs only once, then is removed.
|
|
4362
4653
|
*
|
|
4363
4654
|
* @param {string} event - The event type (e.g. 'click', 'keydown').
|
|
4364
|
-
* @param {
|
|
4655
|
+
* @param {EventListenerOrEventListenerObject} handler - The callback function to run on event.
|
|
4365
4656
|
* @param {EventRegistryOptions} [options={}] - Optional event listener options.
|
|
4366
4657
|
* @returns {TinyEventTarget|TinyEventTarget[]}
|
|
4367
4658
|
*/
|
|
@@ -4374,7 +4665,7 @@ class TinyHtml {
|
|
|
4374
4665
|
*
|
|
4375
4666
|
* @param {TinyEventTarget|TinyEventTarget[]} el - The target element.
|
|
4376
4667
|
* @param {string} event - The event type.
|
|
4377
|
-
* @param {
|
|
4668
|
+
* @param {EventListenerOrEventListenerObject|null} handler - The function originally bound to the event.
|
|
4378
4669
|
* @param {boolean|EventListenerOptions} [options] - Optional listener options.
|
|
4379
4670
|
* @returns {TinyEventTarget|TinyEventTarget[]}
|
|
4380
4671
|
*/
|
|
@@ -4396,7 +4687,7 @@ class TinyHtml {
|
|
|
4396
4687
|
* Removes a specific event listener from an element.
|
|
4397
4688
|
*
|
|
4398
4689
|
* @param {string} event - The event type.
|
|
4399
|
-
* @param {
|
|
4690
|
+
* @param {EventListenerOrEventListenerObject|null} handler - The function originally bound to the event.
|
|
4400
4691
|
* @param {boolean|EventListenerOptions} [options] - Optional listener options.
|
|
4401
4692
|
* @returns {TinyEventTarget|TinyEventTarget[]}
|
|
4402
4693
|
*/
|
|
@@ -4439,7 +4730,7 @@ class TinyHtml {
|
|
|
4439
4730
|
* Removes all event listeners of all types from the element.
|
|
4440
4731
|
*
|
|
4441
4732
|
* @param {TinyEventTarget|TinyEventTarget[]} el - The target element.
|
|
4442
|
-
* @param {((handler: EventListenerOrEventListenerObject, event: string) => boolean)|null} [filterFn=null] -
|
|
4733
|
+
* @param {((handler: EventListenerOrEventListenerObject|null, event: string) => boolean)|null} [filterFn=null] -
|
|
4443
4734
|
* Optional filter function to selectively remove specific handlers.
|
|
4444
4735
|
* @returns {TinyEventTarget|TinyEventTarget[]}
|
|
4445
4736
|
*/
|
|
@@ -4466,7 +4757,7 @@ class TinyHtml {
|
|
|
4466
4757
|
/**
|
|
4467
4758
|
* Removes all event listeners of all types from the element.
|
|
4468
4759
|
*
|
|
4469
|
-
* @param {((handler: EventListenerOrEventListenerObject, event: string) => boolean)|null} [filterFn=null] -
|
|
4760
|
+
* @param {((handler: EventListenerOrEventListenerObject|null, event: string) => boolean)|null} [filterFn=null] -
|
|
4470
4761
|
* Optional filter function to selectively remove specific handlers.
|
|
4471
4762
|
* @returns {TinyEventTarget|TinyEventTarget[]}
|
|
4472
4763
|
*/
|