tiny-essentials 1.22.1 → 1.22.3

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
@@ -6663,6 +6736,31 @@ class TinyHtml {
6663
6736
  return TinyHtml.toggleProp(this, name, force);
6664
6737
  }
6665
6738
 
6739
+ /**
6740
+ * Get properties on an element.
6741
+ *
6742
+ * @param {TinyHtmlElement} el - Target element.
6743
+ * @param {string} name - Property name.
6744
+ * @returns {any} - Property value if getting, otherwise `undefined`.
6745
+ */
6746
+ static prop(el, name) {
6747
+ if (typeof name !== 'string')
6748
+ throw new TypeError('Invalid arguments passed to prop(). Expected string for "name".');
6749
+ const elem = TinyHtml._preElem(el, 'attr');
6750
+ // @ts-ignore
6751
+ return elem[name];
6752
+ }
6753
+
6754
+ /**
6755
+ * Get properties on an element.
6756
+ *
6757
+ * @param {string} name - Property name.
6758
+ * @returns {any} - Property value if getting, otherwise `undefined`.
6759
+ */
6760
+ prop(name) {
6761
+ return TinyHtml.prop(this, name);
6762
+ }
6763
+
6666
6764
  /////////////////////////////////////////////////////
6667
6765
 
6668
6766
  // TITLE: Remove Element
@@ -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.
@@ -2396,6 +2409,14 @@ declare class TinyHtml<TinyHtmlT extends ConstructorElValues | ConstructorElValu
2396
2409
  * @returns {T}
2397
2410
  */
2398
2411
  static toggleProp<T extends TinyElement | TinyElement[]>(el: T, name: string | string[], force?: boolean): T;
2412
+ /**
2413
+ * Get properties on an element.
2414
+ *
2415
+ * @param {TinyHtmlElement} el - Target element.
2416
+ * @param {string} name - Property name.
2417
+ * @returns {any} - Property value if getting, otherwise `undefined`.
2418
+ */
2419
+ static prop(el: TinyHtmlElement, name: string): any;
2399
2420
  /**
2400
2421
  * Removes an element from the DOM.
2401
2422
  * @template {TinyElement|TinyElement[]} T
@@ -3070,6 +3091,18 @@ declare class TinyHtml<TinyHtmlT extends ConstructorElValues | ConstructorElValu
3070
3091
  * @returns {StyleFxResult}
3071
3092
  */
3072
3093
  fadeToggle(ops?: number | KeyframeAnimationOptions | string): StyleFxResult;
3094
+ /**
3095
+ * Animate the opacity of elements to a target value.
3096
+ * If the element is hidden (display:none), it will be made visible first
3097
+ * so the fade animation can occur.
3098
+ *
3099
+ * @param {number} opacity - Final opacity value (between 0 and 1).
3100
+ * @param {number | KeyframeAnimationOptions | string} [ops] - Duration or animation options.
3101
+ * @returns {StyleFxResult}
3102
+ * @throws {TypeError} If opacity is not a number between 0 and 1.
3103
+ * @throws {TypeError} If ops is not number|string|object when provided.
3104
+ */
3105
+ fadeTo(opacity: number, ops?: number | KeyframeAnimationOptions | string): StyleFxResult;
3073
3106
  /**
3074
3107
  * Gets the offset of the element relative to the document.
3075
3108
  * @returns {{top: number, left: number}}
@@ -3529,6 +3562,13 @@ declare class TinyHtml<TinyHtmlT extends ConstructorElValues | ConstructorElValu
3529
3562
  * @returns {this}
3530
3563
  */
3531
3564
  toggleProp(name: string | string[], force?: boolean): this;
3565
+ /**
3566
+ * Get properties on an element.
3567
+ *
3568
+ * @param {string} name - Property name.
3569
+ * @returns {any} - Property value if getting, otherwise `undefined`.
3570
+ */
3571
+ prop(name: string): any;
3532
3572
  /**
3533
3573
  * Removes the element from the DOM.
3534
3574
  * @returns {this}
@@ -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
  /**
@@ -5993,6 +6051,29 @@ class TinyHtml {
5993
6051
  toggleProp(name, force) {
5994
6052
  return TinyHtml.toggleProp(this, name, force);
5995
6053
  }
6054
+ /**
6055
+ * Get properties on an element.
6056
+ *
6057
+ * @param {TinyHtmlElement} el - Target element.
6058
+ * @param {string} name - Property name.
6059
+ * @returns {any} - Property value if getting, otherwise `undefined`.
6060
+ */
6061
+ static prop(el, name) {
6062
+ if (typeof name !== 'string')
6063
+ throw new TypeError('Invalid arguments passed to prop(). Expected string for "name".');
6064
+ const elem = TinyHtml._preElem(el, 'attr');
6065
+ // @ts-ignore
6066
+ return elem[name];
6067
+ }
6068
+ /**
6069
+ * Get properties on an element.
6070
+ *
6071
+ * @param {string} name - Property name.
6072
+ * @returns {any} - Property value if getting, otherwise `undefined`.
6073
+ */
6074
+ prop(name) {
6075
+ return TinyHtml.prop(this, name);
6076
+ }
5996
6077
  /////////////////////////////////////////////////////
5997
6078
  // TITLE: Remove Element
5998
6079
  /**
@@ -2081,11 +2081,12 @@ Safe and type-checked — throws if misuse is detected.
2081
2081
 
2082
2082
  ---
2083
2083
 
2084
- ### 🧲 `.hasProp()` / `.addProp()` / `.removeProp()` / `.toggleProp()`
2084
+ ### 🧲 `.hasProp()` / `.addProp()` / `.removeProp()` / `.toggleProp()` / `.prop()`
2085
2085
 
2086
2086
  Properties
2087
2087
 
2088
2088
  ```js
2089
+ element.prop('scrollHeight'); // get scrollHeight value
2089
2090
  element.hasProp("disabled"); // true/false
2090
2091
  element.addProp("checked"); // set true
2091
2092
  element.removeProp("checked"); // set false
@@ -3141,6 +3142,32 @@ Instance method version.
3141
3142
 
3142
3143
  ---
3143
3144
 
3145
+ ### `static fadeTo(el, opacity, ops?): StyleFxResult`
3146
+
3147
+ Animate the opacity of elements to a target value.
3148
+ If the element is hidden (`display: none`), it will first be made visible before applying the fade animation.
3149
+
3150
+ ```js
3151
+ TinyHtml.fadeTo(el, 0.5, 400); // Fade element to 50% opacity in 400ms
3152
+ TinyHtml.fadeTo(el, 1, "fast"); // Fade element to full opacity using predefined speed
3153
+ ```
3154
+
3155
+ * `el`: The target element(s) to animate.
3156
+ * `opacity`: The final opacity value (between `0` and `1`).
3157
+ * `ops`: Optional duration, animation options, or a predefined speed name.
3158
+
3159
+ Returns a `StyleFxResult` mapping each element to its animation instance.
3160
+
3161
+ ### `fadeTo(opacity, ops?): StyleFxResult`
3162
+
3163
+ Instance method version.
3164
+
3165
+ ```js
3166
+ element.fadeTo(0.3, { duration: 800, easing: "ease-in" });
3167
+ ```
3168
+
3169
+ ---
3170
+
3144
3171
  ## 🖱️ Focus & Blur
3145
3172
 
3146
3173
  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.3",
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",