tiny-essentials 1.17.0 → 1.17.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.
- package/dist/v1/TinyBasicsEs.js +172 -24
- package/dist/v1/TinyBasicsEs.min.js +1 -1
- package/dist/v1/TinyDragger.js +172 -24
- package/dist/v1/TinyDragger.min.js +1 -1
- package/dist/v1/TinyEssentials.js +172 -24
- package/dist/v1/TinyEssentials.min.js +1 -1
- package/dist/v1/TinyHtml.js +172 -24
- package/dist/v1/TinyHtml.min.js +1 -1
- package/dist/v1/TinySmartScroller.js +172 -24
- package/dist/v1/TinySmartScroller.min.js +1 -1
- package/dist/v1/TinyUploadClicker.js +172 -24
- package/dist/v1/TinyUploadClicker.min.js +1 -1
- package/dist/v1/libs/TinyHtml.cjs +172 -24
- package/dist/v1/libs/TinyHtml.d.mts +88 -0
- package/dist/v1/libs/TinyHtml.mjs +162 -27
- package/docs/v1/libs/TinyHtml.md +99 -0
- package/package.json +1 -1
|
@@ -4275,6 +4275,19 @@ const {
|
|
|
4275
4275
|
areElsCollRight: TinyHtml_areElsCollRight,
|
|
4276
4276
|
} = collision_namespaceObject;
|
|
4277
4277
|
|
|
4278
|
+
/**
|
|
4279
|
+
* Callback invoked on each animation frame with the current scroll position,
|
|
4280
|
+
* normalized animation time (`0` to `1`), and a completion flag.
|
|
4281
|
+
*
|
|
4282
|
+
* @typedef {(progress: { x: number, y: number, isComplete: boolean, time: number }) => void} OnScrollAnimation
|
|
4283
|
+
*/
|
|
4284
|
+
|
|
4285
|
+
/**
|
|
4286
|
+
* A list of supported easing function names for smooth animations.
|
|
4287
|
+
*
|
|
4288
|
+
* @typedef {'linear' | 'easeInQuad' | 'easeOutQuad' | 'easeInOutQuad' | 'easeInCubic' | 'easeOutCubic' | 'easeInOutCubic'} Easings
|
|
4289
|
+
*/
|
|
4290
|
+
|
|
4278
4291
|
/**
|
|
4279
4292
|
* Represents a raw Node element or an instance of TinyHtml.
|
|
4280
4293
|
* This type is used to abstract interactions with both plain elements
|
|
@@ -6683,7 +6696,7 @@ class TinyHtml_TinyHtml {
|
|
|
6683
6696
|
*/
|
|
6684
6697
|
static setWinScrollTop(value) {
|
|
6685
6698
|
if (typeof value !== 'number') throw new TypeError('The value must be a number.');
|
|
6686
|
-
|
|
6699
|
+
TinyHtml_TinyHtml.setScrollTop(window, value);
|
|
6687
6700
|
}
|
|
6688
6701
|
|
|
6689
6702
|
/**
|
|
@@ -6692,7 +6705,7 @@ class TinyHtml_TinyHtml {
|
|
|
6692
6705
|
*/
|
|
6693
6706
|
static setWinScrollLeft(value) {
|
|
6694
6707
|
if (typeof value !== 'number') throw new TypeError('The value must be a number.');
|
|
6695
|
-
|
|
6708
|
+
TinyHtml_TinyHtml.setScrollLeft(window, value);
|
|
6696
6709
|
}
|
|
6697
6710
|
|
|
6698
6711
|
/**
|
|
@@ -7009,6 +7022,30 @@ class TinyHtml_TinyHtml {
|
|
|
7009
7022
|
|
|
7010
7023
|
//////////////////////////////////////////////////
|
|
7011
7024
|
|
|
7025
|
+
/**
|
|
7026
|
+
* Applies an animation to one or multiple TinyElement instances.
|
|
7027
|
+
*
|
|
7028
|
+
* @param {TinyElement|TinyElement[]} el - A single TinyElement or an array of TinyElements to animate.
|
|
7029
|
+
* @param {Keyframe[] | PropertyIndexedKeyframes | null} keyframes - The keyframes used to define the animation.
|
|
7030
|
+
* @param {number | KeyframeAnimationOptions} [ops] - Timing or configuration options for the animation.
|
|
7031
|
+
* @returns {TinyElement|TinyElement[]}
|
|
7032
|
+
*/
|
|
7033
|
+
static animate(el, keyframes, ops) {
|
|
7034
|
+
TinyHtml_TinyHtml._preElems(el, 'animate').forEach((elem) => elem.animate(keyframes, ops));
|
|
7035
|
+
return el;
|
|
7036
|
+
}
|
|
7037
|
+
|
|
7038
|
+
/**
|
|
7039
|
+
* Applies an animation to one or multiple TinyElement instances.
|
|
7040
|
+
*
|
|
7041
|
+
* @param {Keyframe[] | PropertyIndexedKeyframes | null} keyframes - The keyframes used to define the animation.
|
|
7042
|
+
* @param {number | KeyframeAnimationOptions} [ops] - Timing or configuration options for the animation.
|
|
7043
|
+
* @returns {TinyElement|TinyElement[]}
|
|
7044
|
+
*/
|
|
7045
|
+
animate(keyframes, ops) {
|
|
7046
|
+
return TinyHtml_TinyHtml.animate(this, keyframes, ops);
|
|
7047
|
+
}
|
|
7048
|
+
|
|
7012
7049
|
/**
|
|
7013
7050
|
* Gets the offset of the element relative to the document.
|
|
7014
7051
|
* @param {TinyElement} el - Target element.
|
|
@@ -7164,26 +7201,147 @@ class TinyHtml_TinyHtml {
|
|
|
7164
7201
|
}
|
|
7165
7202
|
|
|
7166
7203
|
/**
|
|
7167
|
-
*
|
|
7168
|
-
*
|
|
7169
|
-
*
|
|
7170
|
-
* @
|
|
7204
|
+
* Collection of easing functions used for scroll and animation calculations.
|
|
7205
|
+
* Each function receives a normalized time value (`t` from 0 to 1) and returns the eased progress.
|
|
7206
|
+
*
|
|
7207
|
+
* @type {Record<string, (t: number) => number>}
|
|
7171
7208
|
*/
|
|
7172
|
-
static
|
|
7173
|
-
|
|
7174
|
-
|
|
7175
|
-
|
|
7176
|
-
|
|
7209
|
+
static easings = {
|
|
7210
|
+
linear: (t) => t,
|
|
7211
|
+
easeInQuad: (t) => t * t,
|
|
7212
|
+
easeOutQuad: (t) => t * (2 - t),
|
|
7213
|
+
easeInOutQuad: (t) => (t < 0.5 ? 2 * t * t : -1 + (4 - 2 * t) * t),
|
|
7214
|
+
easeInCubic: (t) => t * t * t,
|
|
7215
|
+
easeOutCubic: (t) => --t * t * t + 1,
|
|
7216
|
+
easeInOutCubic: (t) => (t < 0.5 ? 4 * t * t * t : (t - 1) * (2 * t - 2) * (2 * t - 2) + 1),
|
|
7217
|
+
};
|
|
7218
|
+
|
|
7219
|
+
/**
|
|
7220
|
+
* Smoothly scrolls one or more elements (or the window) to the specified X and Y coordinates
|
|
7221
|
+
* using a custom duration and easing function.
|
|
7222
|
+
*
|
|
7223
|
+
* If `duration` or a valid `easing` is not provided, the scroll will be performed immediately.
|
|
7224
|
+
*
|
|
7225
|
+
* @param {TinyElementAndWindow | TinyElementAndWindow[]} el - A single element, array of elements, or the window to scroll.
|
|
7226
|
+
* @param {Object} [settings={}] - Configuration object for the scroll animation.
|
|
7227
|
+
* @param {number} [settings.targetX] - The horizontal scroll target in pixels.
|
|
7228
|
+
* @param {number} [settings.targetY] - The vertical scroll target in pixels.
|
|
7229
|
+
* @param {number} [settings.duration] - The duration of the animation in milliseconds.
|
|
7230
|
+
* @param {Easings} [settings.easing] - The easing function name to use for the scroll animation.
|
|
7231
|
+
* @param {OnScrollAnimation} [settings.onAnimation] - Optional callback invoked on each animation
|
|
7232
|
+
* frame with the current scroll position, normalized animation time (`0` to `1`), and a completion flag.
|
|
7233
|
+
* @returns {TinyElementAndWindow|TinyElementAndWindow[]}
|
|
7234
|
+
* @throws {TypeError} If `el` is not a valid element, array, or window.
|
|
7235
|
+
* @throws {TypeError} If `targetX` or `targetY` is defined but not a number.
|
|
7236
|
+
* @throws {TypeError} If `duration` is defined but not a number.
|
|
7237
|
+
* @throws {TypeError} If `easing` is defined but not a valid easing function name.
|
|
7238
|
+
* @throws {TypeError} If `onAnimation` is defined but not a function.
|
|
7239
|
+
*/
|
|
7240
|
+
static scrollToXY(el, { targetX, targetY, duration, easing, onAnimation } = {}) {
|
|
7241
|
+
if (targetX !== undefined && typeof targetX !== 'number')
|
|
7242
|
+
throw new TypeError('`targetX` must be a number if provided.');
|
|
7243
|
+
if (targetY !== undefined && typeof targetY !== 'number')
|
|
7244
|
+
throw new TypeError('`targetY` must be a number if provided.');
|
|
7245
|
+
if (duration !== undefined && typeof duration !== 'number')
|
|
7246
|
+
throw new TypeError('`duration` must be a number if provided.');
|
|
7247
|
+
if (easing !== undefined && typeof easing !== 'string')
|
|
7248
|
+
throw new TypeError('`easing` must be a string if provided.');
|
|
7249
|
+
if (easing !== undefined && typeof TinyHtml_TinyHtml.easings[easing] !== 'function')
|
|
7250
|
+
throw new TypeError(`Unknown easing function: "${easing}".`);
|
|
7251
|
+
if (onAnimation !== undefined && typeof onAnimation !== 'function')
|
|
7252
|
+
throw new TypeError('`onAnimation` must be a function if provided.');
|
|
7253
|
+
|
|
7254
|
+
/**
|
|
7255
|
+
* Performs an instant scroll to the given coordinates.
|
|
7256
|
+
*
|
|
7257
|
+
* @param {ElementAndWindow} elem - The element or window to scroll.
|
|
7258
|
+
* @param {number} newX - The final horizontal scroll position.
|
|
7259
|
+
* @param {number} newY - The final vertical scroll position.
|
|
7260
|
+
* @param {number} time - Normalized progress value.
|
|
7261
|
+
*/
|
|
7262
|
+
const executeScroll = (elem, newX, newY, time) => {
|
|
7263
|
+
if (elem instanceof Window) {
|
|
7264
|
+
window.scrollTo(newX, newY);
|
|
7177
7265
|
} else if (elem.nodeType === 9) {
|
|
7178
7266
|
// @ts-ignore
|
|
7179
|
-
elem.defaultView.scrollTo(
|
|
7267
|
+
elem.defaultView.scrollTo(newX, newY);
|
|
7180
7268
|
} else {
|
|
7181
|
-
elem.
|
|
7269
|
+
const startX = elem instanceof Window ? window.scrollX : elem.scrollLeft;
|
|
7270
|
+
const startY = elem instanceof Window ? window.scrollY : elem.scrollTop;
|
|
7271
|
+
if (startX !== newX) elem.scrollLeft = newX;
|
|
7272
|
+
if (startY !== newY) elem.scrollTop = newY;
|
|
7273
|
+
}
|
|
7274
|
+
if (typeof onAnimation === 'function')
|
|
7275
|
+
onAnimation({ x: newX, y: newY, isComplete: time >= 1, time });
|
|
7276
|
+
};
|
|
7277
|
+
|
|
7278
|
+
TinyHtml_TinyHtml._preElemsAndWindow(el, 'scrollToXY').forEach((elem) => {
|
|
7279
|
+
const startX = elem instanceof Window ? window.scrollX : elem.scrollLeft;
|
|
7280
|
+
const startY = elem instanceof Window ? window.scrollY : elem.scrollTop;
|
|
7281
|
+
const targX = targetX ?? startX;
|
|
7282
|
+
const targY = targetY ?? startY;
|
|
7283
|
+
|
|
7284
|
+
const changeX = targX - startX;
|
|
7285
|
+
const changeY = targY - startY;
|
|
7286
|
+
|
|
7287
|
+
const ease = (typeof easing === 'string' && TinyHtml_TinyHtml.easings[easing]) || null;
|
|
7288
|
+
if (typeof duration !== 'number' || typeof ease !== 'function')
|
|
7289
|
+
return executeScroll(elem, targX, targY, 1);
|
|
7290
|
+
const startTime = performance.now();
|
|
7291
|
+
const dur = duration ?? 0;
|
|
7292
|
+
|
|
7293
|
+
/**
|
|
7294
|
+
* Animates the scroll position based on easing and time.
|
|
7295
|
+
*
|
|
7296
|
+
* @param {number} currentTime - Timestamp provided by requestAnimationFrame.
|
|
7297
|
+
*/
|
|
7298
|
+
function animateScroll(currentTime) {
|
|
7299
|
+
if (typeof ease !== 'function') return;
|
|
7300
|
+
const time = Math.min(1, (currentTime - startTime) / dur);
|
|
7301
|
+
const easedTime = ease(time);
|
|
7302
|
+
|
|
7303
|
+
const newX = startX + changeX * easedTime;
|
|
7304
|
+
const newY = startY + changeY * easedTime;
|
|
7305
|
+
executeScroll(elem, newX, newY, time);
|
|
7306
|
+
|
|
7307
|
+
if (time < 1) requestAnimationFrame(animateScroll);
|
|
7182
7308
|
}
|
|
7309
|
+
|
|
7310
|
+
requestAnimationFrame(animateScroll);
|
|
7183
7311
|
});
|
|
7184
7312
|
return el;
|
|
7185
7313
|
}
|
|
7186
7314
|
|
|
7315
|
+
/**
|
|
7316
|
+
* Smoothly scrolls one or more elements (or the window) to the specified X and Y coordinates
|
|
7317
|
+
* using a custom duration and easing function.
|
|
7318
|
+
*
|
|
7319
|
+
* If `duration` or a valid `easing` is not provided, the scroll will be performed immediately.
|
|
7320
|
+
*
|
|
7321
|
+
* @param {Object} [settings={}] - Configuration object for the scroll animation.
|
|
7322
|
+
* @param {number} [settings.targetX] - The horizontal scroll target in pixels.
|
|
7323
|
+
* @param {number} [settings.targetY] - The vertical scroll target in pixels.
|
|
7324
|
+
* @param {number} [settings.duration] - The duration of the animation in milliseconds.
|
|
7325
|
+
* @param {Easings} [settings.easing] - The easing function name to use for the scroll animation.
|
|
7326
|
+
* @param {OnScrollAnimation} [settings.onAnimation] - Optional callback invoked on each animation
|
|
7327
|
+
* frame with the current scroll position, normalized animation time (`0` to `1`), and a completion flag.
|
|
7328
|
+
* @returns {TinyElementAndWindow|TinyElementAndWindow[]}
|
|
7329
|
+
*/
|
|
7330
|
+
scrollToXY({ targetX, targetY, duration, easing, onAnimation } = {}) {
|
|
7331
|
+
return TinyHtml_TinyHtml.scrollToXY(this, { targetX, targetY, duration, easing, onAnimation });
|
|
7332
|
+
}
|
|
7333
|
+
|
|
7334
|
+
/**
|
|
7335
|
+
* Sets the vertical scroll position.
|
|
7336
|
+
* @param {TinyElementAndWindow|TinyElementAndWindow[]} el - Element or window.
|
|
7337
|
+
* @param {number} value - Scroll top value.
|
|
7338
|
+
* @returns {TinyElementAndWindow|TinyElementAndWindow[]}
|
|
7339
|
+
*/
|
|
7340
|
+
static setScrollTop(el, value) {
|
|
7341
|
+
if (typeof value !== 'number') throw new TypeError('ScrollTop value must be a number.');
|
|
7342
|
+
return TinyHtml_TinyHtml.scrollToXY(el, { targetY: value });
|
|
7343
|
+
}
|
|
7344
|
+
|
|
7187
7345
|
/**
|
|
7188
7346
|
* Sets the vertical scroll position.
|
|
7189
7347
|
* @param {number} value - Scroll top value.
|
|
@@ -7201,17 +7359,7 @@ class TinyHtml_TinyHtml {
|
|
|
7201
7359
|
*/
|
|
7202
7360
|
static setScrollLeft(el, value) {
|
|
7203
7361
|
if (typeof value !== 'number') throw new TypeError('ScrollLeft value must be a number.');
|
|
7204
|
-
TinyHtml_TinyHtml.
|
|
7205
|
-
if (TinyHtml_TinyHtml.isWindow(elem)) {
|
|
7206
|
-
elem.scrollTo(value, elem.pageYOffset);
|
|
7207
|
-
} else if (elem.nodeType === 9) {
|
|
7208
|
-
// @ts-ignore
|
|
7209
|
-
elem.defaultView.scrollTo(value, elem.defaultView.pageYOffset);
|
|
7210
|
-
} else {
|
|
7211
|
-
elem.scrollLeft = value;
|
|
7212
|
-
}
|
|
7213
|
-
});
|
|
7214
|
-
return el;
|
|
7362
|
+
return TinyHtml_TinyHtml.scrollToXY(el, { targetX: value });
|
|
7215
7363
|
}
|
|
7216
7364
|
|
|
7217
7365
|
/**
|