tiny-essentials 1.22.1 → 1.22.2

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.
@@ -7,6 +7,6 @@ import { extendObjType, reorderObjTypeOrder, cloneObjTypeOrder, objType } from '
7
7
  import { countObj, isJsonObject } from './objChecker.mjs';
8
8
  import { documentIsFullScreen, isScreenFilled, requestFullScreen, exitFullScreen, isFullScreenMode, onFullScreenChange, offFullScreenChange, } from './fullScreen.mjs';
9
9
  import { calculateMarketcap, compareMarketcap, formatBytes, genFibonacciSeq, getAge, getPercentage, getSimplePerc, ruleOfThree, } from './simpleMath.mjs';
10
- import { addAiMarkerShortcut, diffStrings, safeTextTrim, toTitleCase, toTitleCaseLowerFirst } from './text.mjs';
10
+ import { addAiMarkerShortcut, diffStrings, safeTextTrim, toTitleCase, toTitleCaseLowerFirst, } from './text.mjs';
11
11
  import { areElsCollTop, areElsCollBottom, areElsCollLeft, areElsCollRight, areElsCollPerfTop, areElsCollPerfBottom, areElsCollPerfLeft, areElsCollPerfRight, areElsColliding, areElsPerfColliding, getElsColliding, getElsPerfColliding, getElsCollOverlap, getElsCollOverlapPos, getRectCenter, getElsRelativeCenterOffset, getElsCollDirDepth, getElsCollDetails, } from './collision.mjs';
12
12
  export { diffStrings, diffArrayList, breakdownDuration, calculateMarketcap, compareMarketcap, getPercentage, areElsCollTop, areElsCollBottom, areElsCollLeft, areElsCollRight, areElsCollPerfTop, areElsCollPerfBottom, areElsCollPerfLeft, areElsCollPerfRight, areElsColliding, areElsPerfColliding, getElsColliding, getElsPerfColliding, getElsCollOverlap, getElsCollOverlapPos, getRectCenter, getElsRelativeCenterOffset, getElsCollDirDepth, getElsCollDetails, safeTextTrim, installWindowHiddenScript, genFibonacciSeq, fetchJson, fetchText, readJsonBlob, readFileBlob, readBase64Blob, saveJsonFile, documentIsFullScreen, isScreenFilled, requestFullScreen, exitFullScreen, isFullScreenMode, onFullScreenChange, offFullScreenChange, isJsonObject, arraySortPositions, formatBytes, addAiMarkerShortcut, extendObjType, reorderObjTypeOrder, cloneObjTypeOrder, countObj, objType, ruleOfThree, getSimplePerc, asyncReplace, getAge, formatCustomTimer, formatDayTimer, formatTimer, getTimeDuration, shuffleArray, toTitleCase, toTitleCaseLowerFirst, };
@@ -3768,6 +3768,7 @@ class TinyHtml {
3768
3768
  slideUp: 'slideDown',
3769
3769
  fadeIn: 'fadeOut',
3770
3770
  fadeOut: 'fadeIn',
3771
+ fadeTo: 'fadeIn',
3771
3772
  };
3772
3773
 
3773
3774
  /**
@@ -4441,6 +4442,78 @@ class TinyHtml {
4441
4442
  return TinyHtml.fadeToggle(this, ops);
4442
4443
  }
4443
4444
 
4445
+ /**
4446
+ * Animate the opacity of elements to a target value.
4447
+ * If the element is hidden (display:none), it will be made visible first
4448
+ * so the fade animation can occur.
4449
+ *
4450
+ * @param {TinyHtmlElement|TinyHtmlElement[]} el - Target element(s) to fade.
4451
+ * @param {number} opacity - Final opacity value (between 0 and 1).
4452
+ * @param {number | KeyframeAnimationOptions | string} [ops] - Duration or animation options.
4453
+ * @returns {StyleFxResult}
4454
+ * @throws {TypeError} If opacity is not a number between 0 and 1.
4455
+ * @throws {TypeError} If ops is not number|string|object when provided.
4456
+ */
4457
+ static fadeTo(el, opacity, ops) {
4458
+ if (typeof opacity !== 'number' || isNaN(opacity) || opacity < 0 || opacity > 1)
4459
+ throw new TypeError('fadeTo: opacity must be a number between 0 and 1.');
4460
+
4461
+ if (
4462
+ ops !== undefined &&
4463
+ !(
4464
+ typeof ops === 'number' ||
4465
+ typeof ops === 'string' ||
4466
+ (typeof ops === 'object' && ops !== null)
4467
+ )
4468
+ ) {
4469
+ throw new TypeError(
4470
+ 'fadeTo: ops must be a number, string, KeyframeAnimationOptions, or undefined.',
4471
+ );
4472
+ }
4473
+
4474
+ /** @type {StyleFxResult} */
4475
+ const results = new Map();
4476
+ TinyHtml._preHtmlElems(el, 'fadeTo').forEach((elem) => {
4477
+ const style = getComputedStyle(elem);
4478
+ const isHidden = !(el instanceof Element)
4479
+ ? true
4480
+ : !(el.offsetWidth || el.offsetHeight || el.getClientRects().length);
4481
+
4482
+ if (isHidden) {
4483
+ // Ensure element is visible (like jQuery does before fading)
4484
+ const display = TinyHtml.getAnimateData(elem, `origdisplay`);
4485
+ elem.style.display = typeof display === 'string' ? display : 'block';
4486
+ }
4487
+
4488
+ /** @type {AnimationSfxData} */
4489
+ const keyframes = {
4490
+ opacity: [style.opacity, opacity],
4491
+ };
4492
+
4493
+ // Build keyframe objects for Web Animations
4494
+ const kf = keyframes.opacity.map((val) => ({ opacity: val }));
4495
+
4496
+ results.set(elem, TinyHtml.animate(elem, kf, ops, 'fadeTo')[0]);
4497
+ });
4498
+
4499
+ return results;
4500
+ }
4501
+
4502
+ /**
4503
+ * Animate the opacity of elements to a target value.
4504
+ * If the element is hidden (display:none), it will be made visible first
4505
+ * so the fade animation can occur.
4506
+ *
4507
+ * @param {number} opacity - Final opacity value (between 0 and 1).
4508
+ * @param {number | KeyframeAnimationOptions | string} [ops] - Duration or animation options.
4509
+ * @returns {StyleFxResult}
4510
+ * @throws {TypeError} If opacity is not a number between 0 and 1.
4511
+ * @throws {TypeError} If ops is not number|string|object when provided.
4512
+ */
4513
+ fadeTo(opacity, ops) {
4514
+ return TinyHtml.fadeTo(this, opacity, ops);
4515
+ }
4516
+
4444
4517
  ///////////////////////////////////////////////////////////////
4445
4518
 
4446
4519
  // TITLE: DOM Positions
@@ -1698,6 +1698,19 @@ declare class TinyHtml<TinyHtmlT extends ConstructorElValues | ConstructorElValu
1698
1698
  * @returns {StyleFxResult}
1699
1699
  */
1700
1700
  static fadeToggle(el: TinyHtmlElement | TinyHtmlElement[], ops?: number | KeyframeAnimationOptions | string): StyleFxResult;
1701
+ /**
1702
+ * Animate the opacity of elements to a target value.
1703
+ * If the element is hidden (display:none), it will be made visible first
1704
+ * so the fade animation can occur.
1705
+ *
1706
+ * @param {TinyHtmlElement|TinyHtmlElement[]} el - Target element(s) to fade.
1707
+ * @param {number} opacity - Final opacity value (between 0 and 1).
1708
+ * @param {number | KeyframeAnimationOptions | string} [ops] - Duration or animation options.
1709
+ * @returns {StyleFxResult}
1710
+ * @throws {TypeError} If opacity is not a number between 0 and 1.
1711
+ * @throws {TypeError} If ops is not number|string|object when provided.
1712
+ */
1713
+ static fadeTo(el: TinyHtmlElement | TinyHtmlElement[], opacity: number, ops?: number | KeyframeAnimationOptions | string): StyleFxResult;
1701
1714
  /**
1702
1715
  * Gets the offset of the element relative to the document.
1703
1716
  * @param {TinyElement} el - Target element.
@@ -3070,6 +3083,18 @@ declare class TinyHtml<TinyHtmlT extends ConstructorElValues | ConstructorElValu
3070
3083
  * @returns {StyleFxResult}
3071
3084
  */
3072
3085
  fadeToggle(ops?: number | KeyframeAnimationOptions | string): StyleFxResult;
3086
+ /**
3087
+ * Animate the opacity of elements to a target value.
3088
+ * If the element is hidden (display:none), it will be made visible first
3089
+ * so the fade animation can occur.
3090
+ *
3091
+ * @param {number} opacity - Final opacity value (between 0 and 1).
3092
+ * @param {number | KeyframeAnimationOptions | string} [ops] - Duration or animation options.
3093
+ * @returns {StyleFxResult}
3094
+ * @throws {TypeError} If opacity is not a number between 0 and 1.
3095
+ * @throws {TypeError} If ops is not number|string|object when provided.
3096
+ */
3097
+ fadeTo(opacity: number, ops?: number | KeyframeAnimationOptions | string): StyleFxResult;
3073
3098
  /**
3074
3099
  * Gets the offset of the element relative to the document.
3075
3100
  * @returns {{top: number, left: number}}
@@ -3362,6 +3362,7 @@ class TinyHtml {
3362
3362
  slideUp: 'slideDown',
3363
3363
  fadeIn: 'fadeOut',
3364
3364
  fadeOut: 'fadeIn',
3365
+ fadeTo: 'fadeIn',
3365
3366
  };
3366
3367
  /**
3367
3368
  * Get a cloned copy of style inverse values.
@@ -3969,6 +3970,63 @@ class TinyHtml {
3969
3970
  fadeToggle(ops) {
3970
3971
  return TinyHtml.fadeToggle(this, ops);
3971
3972
  }
3973
+ /**
3974
+ * Animate the opacity of elements to a target value.
3975
+ * If the element is hidden (display:none), it will be made visible first
3976
+ * so the fade animation can occur.
3977
+ *
3978
+ * @param {TinyHtmlElement|TinyHtmlElement[]} el - Target element(s) to fade.
3979
+ * @param {number} opacity - Final opacity value (between 0 and 1).
3980
+ * @param {number | KeyframeAnimationOptions | string} [ops] - Duration or animation options.
3981
+ * @returns {StyleFxResult}
3982
+ * @throws {TypeError} If opacity is not a number between 0 and 1.
3983
+ * @throws {TypeError} If ops is not number|string|object when provided.
3984
+ */
3985
+ static fadeTo(el, opacity, ops) {
3986
+ if (typeof opacity !== 'number' || isNaN(opacity) || opacity < 0 || opacity > 1)
3987
+ throw new TypeError('fadeTo: opacity must be a number between 0 and 1.');
3988
+ if (ops !== undefined &&
3989
+ !(typeof ops === 'number' ||
3990
+ typeof ops === 'string' ||
3991
+ (typeof ops === 'object' && ops !== null))) {
3992
+ throw new TypeError('fadeTo: ops must be a number, string, KeyframeAnimationOptions, or undefined.');
3993
+ }
3994
+ /** @type {StyleFxResult} */
3995
+ const results = new Map();
3996
+ TinyHtml._preHtmlElems(el, 'fadeTo').forEach((elem) => {
3997
+ const style = getComputedStyle(elem);
3998
+ const isHidden = !(el instanceof Element)
3999
+ ? true
4000
+ : !(el.offsetWidth || el.offsetHeight || el.getClientRects().length);
4001
+ if (isHidden) {
4002
+ // Ensure element is visible (like jQuery does before fading)
4003
+ const display = TinyHtml.getAnimateData(elem, `origdisplay`);
4004
+ elem.style.display = typeof display === 'string' ? display : 'block';
4005
+ }
4006
+ /** @type {AnimationSfxData} */
4007
+ const keyframes = {
4008
+ opacity: [style.opacity, opacity],
4009
+ };
4010
+ // Build keyframe objects for Web Animations
4011
+ const kf = keyframes.opacity.map((val) => ({ opacity: val }));
4012
+ results.set(elem, TinyHtml.animate(elem, kf, ops, 'fadeTo')[0]);
4013
+ });
4014
+ return results;
4015
+ }
4016
+ /**
4017
+ * Animate the opacity of elements to a target value.
4018
+ * If the element is hidden (display:none), it will be made visible first
4019
+ * so the fade animation can occur.
4020
+ *
4021
+ * @param {number} opacity - Final opacity value (between 0 and 1).
4022
+ * @param {number | KeyframeAnimationOptions | string} [ops] - Duration or animation options.
4023
+ * @returns {StyleFxResult}
4024
+ * @throws {TypeError} If opacity is not a number between 0 and 1.
4025
+ * @throws {TypeError} If ops is not number|string|object when provided.
4026
+ */
4027
+ fadeTo(opacity, ops) {
4028
+ return TinyHtml.fadeTo(this, opacity, ops);
4029
+ }
3972
4030
  ///////////////////////////////////////////////////////////////
3973
4031
  // TITLE: DOM Positions
3974
4032
  /**
@@ -3141,6 +3141,32 @@ Instance method version.
3141
3141
 
3142
3142
  ---
3143
3143
 
3144
+ ### `static fadeTo(el, opacity, ops?): StyleFxResult`
3145
+
3146
+ Animate the opacity of elements to a target value.
3147
+ If the element is hidden (`display: none`), it will first be made visible before applying the fade animation.
3148
+
3149
+ ```js
3150
+ TinyHtml.fadeTo(el, 0.5, 400); // Fade element to 50% opacity in 400ms
3151
+ TinyHtml.fadeTo(el, 1, "fast"); // Fade element to full opacity using predefined speed
3152
+ ```
3153
+
3154
+ * `el`: The target element(s) to animate.
3155
+ * `opacity`: The final opacity value (between `0` and `1`).
3156
+ * `ops`: Optional duration, animation options, or a predefined speed name.
3157
+
3158
+ Returns a `StyleFxResult` mapping each element to its animation instance.
3159
+
3160
+ ### `fadeTo(opacity, ops?): StyleFxResult`
3161
+
3162
+ Instance method version.
3163
+
3164
+ ```js
3165
+ element.fadeTo(0.3, { duration: 800, easing: "ease-in" });
3166
+ ```
3167
+
3168
+ ---
3169
+
3144
3170
  ## 🖱️ Focus & Blur
3145
3171
 
3146
3172
  TinyHtml provides utility methods to programmatically focus or blur HTML elements.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tiny-essentials",
3
- "version": "1.22.1",
3
+ "version": "1.22.2",
4
4
  "description": "Collection of small, essential scripts designed to be used across various projects. These simple utilities are crafted for speed, ease of use, and versatility.",
5
5
  "scripts": {
6
6
  "test": "npm run test:mjs && npm run test:cjs && npm run test:js",