tiny-essentials 1.18.0 → 1.18.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/legacy/get/countObj.cjs +2 -2
- package/dist/legacy/get/countObj.d.mts +1 -1
- package/dist/legacy/get/countObj.mjs +1 -1
- package/dist/legacy/index.cjs +2 -1
- package/dist/v1/TinyBasicsEs.js +389 -384
- package/dist/v1/TinyBasicsEs.min.js +1 -1
- package/dist/v1/TinyDragger.js +6 -2433
- package/dist/v1/TinyDragger.min.js +1 -2
- package/dist/v1/TinyEssentials.js +47 -42
- package/dist/v1/TinyEssentials.min.js +1 -1
- package/dist/v1/TinyUploadClicker.js +53 -446
- package/dist/v1/TinyUploadClicker.min.js +1 -1
- package/dist/v1/basics/html.cjs +3 -3
- package/dist/v1/basics/html.mjs +1 -1
- package/dist/v1/basics/index.cjs +3 -2
- package/dist/v1/basics/index.d.mts +2 -2
- package/dist/v1/basics/index.mjs +2 -1
- package/dist/v1/basics/objChecker.cjs +46 -0
- package/dist/v1/basics/objChecker.d.mts +29 -0
- package/dist/v1/basics/objChecker.mjs +45 -0
- package/dist/v1/basics/objFilter.cjs +4 -45
- package/dist/v1/basics/objFilter.d.mts +3 -28
- package/dist/v1/basics/objFilter.mjs +2 -45
- package/dist/v1/index.cjs +3 -2
- package/dist/v1/index.d.mts +2 -2
- package/dist/v1/index.mjs +2 -1
- package/dist/v1/libs/TinyDragger.cjs +3 -3
- package/dist/v1/libs/TinyDragger.mjs +1 -1
- package/dist/v1/libs/TinyUploadClicker.cjs +5 -4
- package/docs/v1/README.md +1 -0
- package/docs/v1/basics/objChecker.md +47 -0
- package/docs/v1/basics/objFilter.md +0 -40
- package/package.json +1 -1
- package/dist/v1/TinyDragger.min.js.LICENSE.txt +0 -8
package/dist/v1/TinyBasicsEs.js
CHANGED
|
@@ -2530,207 +2530,11 @@ function formatDayTimer(seconds) {
|
|
|
2530
2530
|
return formatCustomTimer(seconds, 'days', '{days}d {hours}:{minutes}:{seconds}');
|
|
2531
2531
|
}
|
|
2532
2532
|
|
|
2533
|
-
|
|
2534
|
-
var buffer = __webpack_require__(287);
|
|
2535
|
-
;// ./src/v1/basics/objFilter.mjs
|
|
2536
|
-
|
|
2537
|
-
|
|
2538
|
-
const isBrowser = typeof window !== 'undefined' && typeof window.document !== 'undefined';
|
|
2539
|
-
|
|
2540
|
-
/**
|
|
2541
|
-
* An object containing type validation functions and their evaluation order.
|
|
2542
|
-
*
|
|
2543
|
-
* Each item in `typeValidator.items` is a function that receives any value
|
|
2544
|
-
* and returns a boolean indicating whether the value matches the corresponding type.
|
|
2545
|
-
*
|
|
2546
|
-
* The `order` array defines the priority in which types should be checked,
|
|
2547
|
-
* which can be useful for functions that infer types in a consistent manner.
|
|
2548
|
-
*
|
|
2549
|
-
*/
|
|
2550
|
-
const typeValidator = {
|
|
2551
|
-
items: {},
|
|
2552
|
-
/**
|
|
2553
|
-
* Evaluation order of the type checkers.
|
|
2554
|
-
* @type {string[]}
|
|
2555
|
-
* */
|
|
2556
|
-
order: [],
|
|
2557
|
-
};
|
|
2558
|
-
|
|
2559
|
-
/** @typedef {Object.<string, (val: any) => *>} ExtendObjType */
|
|
2560
|
-
/** @typedef {Array<[string, (val: any) => *]>} ExtendObjTypeArray */
|
|
2561
|
-
|
|
2562
|
-
/**
|
|
2563
|
-
* Adds new type checkers to the typeValidator without overwriting existing ones.
|
|
2564
|
-
*
|
|
2565
|
-
* Accepts either an object with named functions or an array of [key, fn] arrays.
|
|
2566
|
-
* If no index is provided, the type is inserted just before 'object' (if it exists), or at the end.
|
|
2567
|
-
*
|
|
2568
|
-
* @param {ExtendObjType|ExtendObjTypeArray} newItems
|
|
2569
|
-
* - New type validators to be added.
|
|
2570
|
-
* @param {number} [index] - Optional. Position at which to insert each new type. Ignored if the type already exists.
|
|
2571
|
-
* @returns {string[]} - A list of successfully added type names.
|
|
2572
|
-
*
|
|
2573
|
-
* @example
|
|
2574
|
-
* extendObjType({
|
|
2575
|
-
* htmlElement2: val => typeof HTMLElement !== 'undefined' && val instanceof HTMLElement
|
|
2576
|
-
* });
|
|
2577
|
-
*
|
|
2578
|
-
* @example
|
|
2579
|
-
* extendObjType([
|
|
2580
|
-
* ['alpha', val => typeof val === 'string'],
|
|
2581
|
-
* ['beta', val => Array.isArray(val)]
|
|
2582
|
-
* ]);
|
|
2583
|
-
*/
|
|
2584
|
-
function extendObjType(newItems, index) {
|
|
2585
|
-
const added = [];
|
|
2586
|
-
|
|
2587
|
-
const entries = Array.isArray(newItems) ? newItems : Object.entries(newItems);
|
|
2588
|
-
for (const [key, fn] of entries) {
|
|
2589
|
-
if (!typeValidator.items.hasOwnProperty(key)) {
|
|
2590
|
-
// @ts-ignore
|
|
2591
|
-
typeValidator.items[key] = fn;
|
|
2592
|
-
|
|
2593
|
-
let insertAt = typeof index === 'number' ? index : -1; // Default to -1 if index isn't provided
|
|
2594
|
-
|
|
2595
|
-
// Default to before 'object', or to the end
|
|
2596
|
-
if (insertAt === -1) {
|
|
2597
|
-
const objectIndex = typeValidator.order.indexOf('object');
|
|
2598
|
-
insertAt = objectIndex > -1 ? objectIndex : typeValidator.order.length;
|
|
2599
|
-
}
|
|
2600
|
-
|
|
2601
|
-
// Ensure insertAt is a valid number and not out of bounds
|
|
2602
|
-
insertAt = Math.min(Math.max(0, insertAt), typeValidator.order.length);
|
|
2603
|
-
|
|
2604
|
-
typeValidator.order.splice(insertAt, 0, key);
|
|
2605
|
-
added.push(key);
|
|
2606
|
-
}
|
|
2607
|
-
}
|
|
2608
|
-
|
|
2609
|
-
return added;
|
|
2610
|
-
}
|
|
2611
|
-
|
|
2612
|
-
/**
|
|
2613
|
-
* Reorders the typeValidator.order array according to a custom new order.
|
|
2614
|
-
* All values in the new order must already exist in the current order.
|
|
2615
|
-
* The function does not mutate the original array structure directly.
|
|
2616
|
-
*
|
|
2617
|
-
* @param {string[]} newOrder - The new order of type names.
|
|
2618
|
-
* @returns {boolean} - Returns true if the reorder was successful, false if invalid keys were found.
|
|
2619
|
-
*
|
|
2620
|
-
* @example
|
|
2621
|
-
* reorderObjTypeOrder([
|
|
2622
|
-
* 'string', 'number', 'array', 'object'
|
|
2623
|
-
* ]);
|
|
2624
|
-
*/
|
|
2625
|
-
function reorderObjTypeOrder(newOrder) {
|
|
2626
|
-
const currentOrder = [...typeValidator.order]; // shallow clone
|
|
2627
|
-
|
|
2628
|
-
// All keys in newOrder must exist in currentOrder
|
|
2629
|
-
const isValid = newOrder.every((type) => currentOrder.includes(type));
|
|
2630
|
-
|
|
2631
|
-
if (!isValid) return false;
|
|
2632
|
-
|
|
2633
|
-
// Reassign only if valid
|
|
2634
|
-
typeValidator.order = newOrder.slice(); // assign shallow copy
|
|
2635
|
-
return true;
|
|
2636
|
-
}
|
|
2637
|
-
|
|
2638
|
-
/**
|
|
2639
|
-
* Returns a cloned version of the `typeValidator.order` array.
|
|
2640
|
-
* The cloned array will not be affected by future changes to the original `order`.
|
|
2641
|
-
*
|
|
2642
|
-
* @returns {string[]} - A new array with the same values as `typeValidator.order`.
|
|
2643
|
-
*/
|
|
2644
|
-
function cloneObjTypeOrder() {
|
|
2645
|
-
return [...typeValidator.order]; // Creates a shallow copy of the array
|
|
2646
|
-
}
|
|
2647
|
-
|
|
2648
|
-
/**
|
|
2649
|
-
* Returns the detected type name of a given value based on predefined type validators.
|
|
2650
|
-
*
|
|
2651
|
-
* This function uses `getType` with a predefined `typeValidator` to determine or compare types safely.
|
|
2652
|
-
* in the specified `typeValidator.order`. The first matching type is returned.
|
|
2653
|
-
*
|
|
2654
|
-
* If `val` is `null`, it immediately returns `'null'`.
|
|
2655
|
-
* If no match is found, it returns `'unknown'`.
|
|
2656
|
-
*
|
|
2657
|
-
* @param {any} val - The value whose type should be determined.
|
|
2658
|
-
* @returns {string} - The type name of the value (e.g., "array", "date", "map"), or "unknown" if no match is found.
|
|
2659
|
-
*
|
|
2660
|
-
* @example
|
|
2661
|
-
* getType([]); // "array"
|
|
2662
|
-
* getType(null); // "null"
|
|
2663
|
-
* getType(new Set()); // "set"
|
|
2664
|
-
* getType(() => {}); // "unknown"
|
|
2665
|
-
*/
|
|
2666
|
-
const getType = (val) => {
|
|
2667
|
-
if (val === null) return 'null';
|
|
2668
|
-
// @ts-ignore
|
|
2669
|
-
for (const name of typeValidator.order) {
|
|
2670
|
-
// @ts-ignore
|
|
2671
|
-
if (typeof typeValidator.items[name] !== 'function' || typeValidator.items[name](val))
|
|
2672
|
-
return name;
|
|
2673
|
-
}
|
|
2674
|
-
return 'unknown';
|
|
2675
|
-
};
|
|
2676
|
-
|
|
2677
|
-
/**
|
|
2678
|
-
* Checks the type of a given object or returns its type as a string.
|
|
2679
|
-
*
|
|
2680
|
-
* @param {*} obj - The object to check or identify.
|
|
2681
|
-
* @param {string} [type] - Optional. If provided, checks whether the object matches this type (e.g., "object", "array", "string").
|
|
2682
|
-
* @returns {boolean|string|null} - Returns `true` if the type matches, `false` if not,
|
|
2683
|
-
* the type string if no type is provided, or `null` if the object is `undefined`.
|
|
2684
|
-
*
|
|
2685
|
-
* @example
|
|
2686
|
-
* objType([], 'array'); // true
|
|
2687
|
-
* objType({}, 'object'); // true
|
|
2688
|
-
* objType('hello'); // "string"
|
|
2689
|
-
* objType(undefined); // null
|
|
2690
|
-
*/
|
|
2691
|
-
function objType(obj, type) {
|
|
2692
|
-
if (typeof obj === 'undefined') return null;
|
|
2693
|
-
const result = getType(obj);
|
|
2694
|
-
if (typeof type === 'string') return result === type.toLowerCase();
|
|
2695
|
-
return result;
|
|
2696
|
-
}
|
|
2697
|
-
|
|
2698
|
-
/**
|
|
2699
|
-
* Checks the type of a given object and returns the validation value if a known type is detected.
|
|
2700
|
-
*
|
|
2701
|
-
* @param {*} obj - The object to check or identify.
|
|
2702
|
-
* @returns {{ valid:*; type: string | null }} - Returns the type result.
|
|
2703
|
-
*/
|
|
2704
|
-
function checkObj(obj) {
|
|
2705
|
-
/** @type {{ valid:*; type: string | null }} */
|
|
2706
|
-
const data = { valid: null, type: null };
|
|
2707
|
-
for (const name of typeValidator.order) {
|
|
2708
|
-
// @ts-ignore
|
|
2709
|
-
if (typeof typeValidator.items[name] === 'function') {
|
|
2710
|
-
// @ts-ignore
|
|
2711
|
-
const result = typeValidator.items[name](obj);
|
|
2712
|
-
if (result) {
|
|
2713
|
-
data.valid = result;
|
|
2714
|
-
data.type = name;
|
|
2715
|
-
break;
|
|
2716
|
-
}
|
|
2717
|
-
}
|
|
2718
|
-
}
|
|
2719
|
-
return data;
|
|
2720
|
-
}
|
|
2721
|
-
|
|
2722
|
-
/**
|
|
2723
|
-
* Creates a clone of the functions from the `typeValidator` object.
|
|
2724
|
-
* It returns a new object where the keys are the same and the values are the cloned functions.
|
|
2725
|
-
*/
|
|
2726
|
-
function getCheckObj() {
|
|
2727
|
-
return Object.fromEntries(Object.entries(typeValidator.items).map(([key, fn]) => [key, fn]));
|
|
2728
|
-
}
|
|
2729
|
-
|
|
2533
|
+
;// ./src/v1/basics/objChecker.mjs
|
|
2730
2534
|
/**
|
|
2731
2535
|
* Counts the number of elements in an array or the number of properties in an object.
|
|
2732
2536
|
*
|
|
2733
|
-
* @param {Array<*>|Record<string|number, any>} obj - The array or object to count.
|
|
2537
|
+
* @param {Array<*>|Record<string | number | symbol, any>} obj - The array or object to count.
|
|
2734
2538
|
* @returns {number} - The count of items (array elements or object keys), or `0` if the input is neither an array nor an object.
|
|
2735
2539
|
*
|
|
2736
2540
|
* @example
|
|
@@ -2742,7 +2546,7 @@ function countObj(obj) {
|
|
|
2742
2546
|
// Is Array
|
|
2743
2547
|
if (Array.isArray(obj)) return obj.length;
|
|
2744
2548
|
// Object
|
|
2745
|
-
if (
|
|
2549
|
+
if (isJsonObject(obj)) return Object.keys(obj).length;
|
|
2746
2550
|
// Nothing
|
|
2747
2551
|
return 0;
|
|
2748
2552
|
}
|
|
@@ -2769,132 +2573,6 @@ function isJsonObject(value) {
|
|
|
2769
2573
|
return true;
|
|
2770
2574
|
}
|
|
2771
2575
|
|
|
2772
|
-
// Insert obj types
|
|
2773
|
-
|
|
2774
|
-
extendObjType([
|
|
2775
|
-
[
|
|
2776
|
-
'undefined',
|
|
2777
|
-
/** @param {*} val @returns {val is undefined} */
|
|
2778
|
-
(val) => typeof val === 'undefined',
|
|
2779
|
-
],
|
|
2780
|
-
[
|
|
2781
|
-
'null',
|
|
2782
|
-
/** @param {*} val @returns {val is null} */
|
|
2783
|
-
(val) => val === null,
|
|
2784
|
-
],
|
|
2785
|
-
[
|
|
2786
|
-
'boolean',
|
|
2787
|
-
/** @param {*} val @returns {val is boolean} */
|
|
2788
|
-
(val) => typeof val === 'boolean',
|
|
2789
|
-
],
|
|
2790
|
-
[
|
|
2791
|
-
'number',
|
|
2792
|
-
/** @param {*} val @returns {val is number} */
|
|
2793
|
-
(val) => typeof val === 'number' && !Number.isNaN(val),
|
|
2794
|
-
],
|
|
2795
|
-
[
|
|
2796
|
-
'bigint',
|
|
2797
|
-
/** @param {*} val @returns {val is bigint} */
|
|
2798
|
-
(val) => typeof val === 'bigint',
|
|
2799
|
-
],
|
|
2800
|
-
[
|
|
2801
|
-
'string',
|
|
2802
|
-
/** @param {*} val @returns {val is string} */
|
|
2803
|
-
(val) => typeof val === 'string',
|
|
2804
|
-
],
|
|
2805
|
-
[
|
|
2806
|
-
'symbol',
|
|
2807
|
-
/** @param {*} val @returns {val is symbol} */
|
|
2808
|
-
(val) => typeof val === 'symbol',
|
|
2809
|
-
],
|
|
2810
|
-
[
|
|
2811
|
-
'function',
|
|
2812
|
-
/** @param {*} val @returns {val is Function} */
|
|
2813
|
-
(val) => typeof val === 'function',
|
|
2814
|
-
],
|
|
2815
|
-
[
|
|
2816
|
-
'array',
|
|
2817
|
-
/** @param {*} val @returns {val is any[]} */
|
|
2818
|
-
(val) => Array.isArray(val),
|
|
2819
|
-
],
|
|
2820
|
-
]);
|
|
2821
|
-
|
|
2822
|
-
if (!isBrowser) {
|
|
2823
|
-
extendObjType([
|
|
2824
|
-
[
|
|
2825
|
-
'buffer',
|
|
2826
|
-
/** @param {*} val @returns {val is Buffer} */
|
|
2827
|
-
(val) => typeof buffer/* Buffer */.hp !== 'undefined' && buffer/* Buffer */.hp.isBuffer(val),
|
|
2828
|
-
],
|
|
2829
|
-
]);
|
|
2830
|
-
}
|
|
2831
|
-
|
|
2832
|
-
if (isBrowser) {
|
|
2833
|
-
extendObjType([
|
|
2834
|
-
[
|
|
2835
|
-
'file',
|
|
2836
|
-
/** @param {*} val @returns {val is File} */
|
|
2837
|
-
(val) => typeof File !== 'undefined' && val instanceof File,
|
|
2838
|
-
],
|
|
2839
|
-
]);
|
|
2840
|
-
}
|
|
2841
|
-
|
|
2842
|
-
extendObjType([
|
|
2843
|
-
[
|
|
2844
|
-
'date',
|
|
2845
|
-
/** @param {*} val @returns {val is Date} */
|
|
2846
|
-
(val) => val instanceof Date,
|
|
2847
|
-
],
|
|
2848
|
-
[
|
|
2849
|
-
'regexp',
|
|
2850
|
-
/** @param {*} val @returns {val is RegExp} */
|
|
2851
|
-
(val) => val instanceof RegExp,
|
|
2852
|
-
],
|
|
2853
|
-
[
|
|
2854
|
-
'map',
|
|
2855
|
-
/** @param {*} val @returns {val is Map<unknown, unknown>} */
|
|
2856
|
-
(val) => val instanceof Map,
|
|
2857
|
-
],
|
|
2858
|
-
[
|
|
2859
|
-
'set',
|
|
2860
|
-
/** @param {*} val @returns {val is Set<unknown>} */
|
|
2861
|
-
(val) => val instanceof Set,
|
|
2862
|
-
],
|
|
2863
|
-
[
|
|
2864
|
-
'weakmap',
|
|
2865
|
-
/** @param {*} val @returns {val is WeakMap<unknown, unknown>} */
|
|
2866
|
-
(val) => val instanceof WeakMap,
|
|
2867
|
-
],
|
|
2868
|
-
[
|
|
2869
|
-
'weakset',
|
|
2870
|
-
/** @param {*} val @returns {val is WeakSet<unknown>} */
|
|
2871
|
-
(val) => val instanceof WeakSet,
|
|
2872
|
-
],
|
|
2873
|
-
[
|
|
2874
|
-
'promise',
|
|
2875
|
-
/** @param {*} val @returns {val is Promise<unknown>} */
|
|
2876
|
-
(val) => val instanceof Promise,
|
|
2877
|
-
],
|
|
2878
|
-
]);
|
|
2879
|
-
|
|
2880
|
-
if (isBrowser) {
|
|
2881
|
-
extendObjType([
|
|
2882
|
-
[
|
|
2883
|
-
'htmlelement',
|
|
2884
|
-
/** @param {*} val @returns {val is HTMLElement} */
|
|
2885
|
-
(val) => typeof HTMLElement !== 'undefined' && val instanceof HTMLElement,
|
|
2886
|
-
],
|
|
2887
|
-
]);
|
|
2888
|
-
}
|
|
2889
|
-
|
|
2890
|
-
extendObjType([
|
|
2891
|
-
[
|
|
2892
|
-
'object',
|
|
2893
|
-
/** @param {*} val @returns {val is Record<string | number | symbol, unknown>} */
|
|
2894
|
-
(val) => isJsonObject(val),
|
|
2895
|
-
],
|
|
2896
|
-
]);
|
|
2897
|
-
|
|
2898
2576
|
;// ./src/v1/basics/html.mjs
|
|
2899
2577
|
|
|
2900
2578
|
|
|
@@ -8791,94 +8469,420 @@ function areHtmlElsPerfColliding(elem1, elem2) {
|
|
|
8791
8469
|
return TinyHtml.isCollPerfWith(elem1, elem2);
|
|
8792
8470
|
}
|
|
8793
8471
|
|
|
8794
|
-
///////////////////////////////////////////////////////////////////////////
|
|
8472
|
+
///////////////////////////////////////////////////////////////////////////
|
|
8473
|
+
|
|
8474
|
+
/**
|
|
8475
|
+
* @typedef {import('../libs/TinyHtml.mjs').HtmlElBoxSides} HtmlElBoxSides
|
|
8476
|
+
*/
|
|
8477
|
+
|
|
8478
|
+
/**
|
|
8479
|
+
* Returns the total border width and individual sides from `border{Side}Width` CSS properties.
|
|
8480
|
+
*
|
|
8481
|
+
* @param {Element} el - The target DOM element.
|
|
8482
|
+
* @returns {HtmlElBoxSides} - Total horizontal (x) and vertical (y) border widths, and each side individually.
|
|
8483
|
+
* @deprecated - Use TinyHtml.borderWidth instead.
|
|
8484
|
+
*/
|
|
8485
|
+
const getHtmlElBordersWidth = (el) => {
|
|
8486
|
+
return libs_TinyHtml.borderWidth(el);
|
|
8487
|
+
};
|
|
8488
|
+
|
|
8489
|
+
/**
|
|
8490
|
+
* Returns the total border size and individual sides from `border{Side}` CSS properties.
|
|
8491
|
+
*
|
|
8492
|
+
* @param {Element} el - The target DOM element.
|
|
8493
|
+
* @returns {HtmlElBoxSides} - Total horizontal (x) and vertical (y) border sizes, and each side individually.
|
|
8494
|
+
* @deprecated - Use TinyHtml.border instead.
|
|
8495
|
+
*/
|
|
8496
|
+
const getHtmlElBorders = (el) => {
|
|
8497
|
+
return libs_TinyHtml.border(el);
|
|
8498
|
+
};
|
|
8499
|
+
|
|
8500
|
+
/**
|
|
8501
|
+
* Returns the total margin and individual sides from `margin{Side}` CSS properties.
|
|
8502
|
+
*
|
|
8503
|
+
* @param {Element} el - The target DOM element.
|
|
8504
|
+
* @returns {HtmlElBoxSides} - Total horizontal (x) and vertical (y) margins, and each side individually.
|
|
8505
|
+
* @deprecated - Use TinyHtml.margin instead.
|
|
8506
|
+
*/
|
|
8507
|
+
const getHtmlElMargin = (el) => {
|
|
8508
|
+
return libs_TinyHtml.margin(el);
|
|
8509
|
+
};
|
|
8510
|
+
|
|
8511
|
+
/**
|
|
8512
|
+
* Returns the total padding and individual sides from `padding{Side}` CSS properties.
|
|
8513
|
+
*
|
|
8514
|
+
* @param {Element} el - The target DOM element.
|
|
8515
|
+
* @returns {HtmlElBoxSides} - Total horizontal (x) and vertical (y) paddings, and each side individually.
|
|
8516
|
+
* @deprecated - Use TinyHtml.padding instead.
|
|
8517
|
+
*/
|
|
8518
|
+
const getHtmlElPadding = (el) => {
|
|
8519
|
+
return libs_TinyHtml.padding(el);
|
|
8520
|
+
};
|
|
8521
|
+
|
|
8522
|
+
/////////////////////////////////////////////////////////////
|
|
8523
|
+
|
|
8524
|
+
// The new version will receive great modifications, the deprecated code has been preserved for non-glitch designs that are using the original code.
|
|
8525
|
+
|
|
8526
|
+
/**
|
|
8527
|
+
* Checks if the given element is at least partially visible in the viewport.
|
|
8528
|
+
*
|
|
8529
|
+
* @param {HTMLElement} element - The DOM element to check.
|
|
8530
|
+
* @returns {boolean} True if the element is partially in the viewport, false otherwise.
|
|
8531
|
+
* @deprecated - Use TinyHtml.isInViewport instead.
|
|
8532
|
+
*/
|
|
8533
|
+
function isInViewport(element) {
|
|
8534
|
+
const elementTop = element.offsetTop;
|
|
8535
|
+
const elementBottom = elementTop + element.offsetHeight;
|
|
8536
|
+
|
|
8537
|
+
const viewportTop = window.scrollY;
|
|
8538
|
+
const viewportBottom = viewportTop + window.innerHeight;
|
|
8539
|
+
|
|
8540
|
+
return elementBottom > viewportTop && elementTop < viewportBottom;
|
|
8541
|
+
}
|
|
8542
|
+
|
|
8543
|
+
/**
|
|
8544
|
+
* Checks if the given element is fully visible in the viewport (top and bottom).
|
|
8545
|
+
*
|
|
8546
|
+
* @param {HTMLElement} element - The DOM element to check.
|
|
8547
|
+
* @returns {boolean} True if the element is fully visible in the viewport, false otherwise.
|
|
8548
|
+
* @deprecated - Use TinyHtml.isScrolledIntoView instead.
|
|
8549
|
+
*/
|
|
8550
|
+
function isScrolledIntoView(element) {
|
|
8551
|
+
const viewportTop = window.scrollY;
|
|
8552
|
+
const viewportBottom = viewportTop + window.innerHeight;
|
|
8553
|
+
|
|
8554
|
+
const elemTop = element.offsetTop;
|
|
8555
|
+
const elemBottom = elemTop + element.offsetHeight;
|
|
8556
|
+
|
|
8557
|
+
return elemBottom <= viewportBottom && elemTop >= viewportTop;
|
|
8558
|
+
}
|
|
8559
|
+
|
|
8560
|
+
// EXTERNAL MODULE: ./node_modules/buffer/index.js
|
|
8561
|
+
var buffer = __webpack_require__(287);
|
|
8562
|
+
;// ./src/v1/basics/objFilter.mjs
|
|
8563
|
+
|
|
8564
|
+
|
|
8565
|
+
|
|
8566
|
+
|
|
8567
|
+
|
|
8568
|
+
const isBrowser = typeof window !== 'undefined' && typeof window.document !== 'undefined';
|
|
8569
|
+
|
|
8570
|
+
/**
|
|
8571
|
+
* An object containing type validation functions and their evaluation order.
|
|
8572
|
+
*
|
|
8573
|
+
* Each item in `typeValidator.items` is a function that receives any value
|
|
8574
|
+
* and returns a boolean indicating whether the value matches the corresponding type.
|
|
8575
|
+
*
|
|
8576
|
+
* The `order` array defines the priority in which types should be checked,
|
|
8577
|
+
* which can be useful for functions that infer types in a consistent manner.
|
|
8578
|
+
*
|
|
8579
|
+
*/
|
|
8580
|
+
const typeValidator = {
|
|
8581
|
+
items: {},
|
|
8582
|
+
/**
|
|
8583
|
+
* Evaluation order of the type checkers.
|
|
8584
|
+
* @type {string[]}
|
|
8585
|
+
* */
|
|
8586
|
+
order: [],
|
|
8587
|
+
};
|
|
8588
|
+
|
|
8589
|
+
/** @typedef {Object.<string, (val: any) => *>} ExtendObjType */
|
|
8590
|
+
/** @typedef {Array<[string, (val: any) => *]>} ExtendObjTypeArray */
|
|
8591
|
+
|
|
8592
|
+
/**
|
|
8593
|
+
* Adds new type checkers to the typeValidator without overwriting existing ones.
|
|
8594
|
+
*
|
|
8595
|
+
* Accepts either an object with named functions or an array of [key, fn] arrays.
|
|
8596
|
+
* If no index is provided, the type is inserted just before 'object' (if it exists), or at the end.
|
|
8597
|
+
*
|
|
8598
|
+
* @param {ExtendObjType|ExtendObjTypeArray} newItems
|
|
8599
|
+
* - New type validators to be added.
|
|
8600
|
+
* @param {number} [index] - Optional. Position at which to insert each new type. Ignored if the type already exists.
|
|
8601
|
+
* @returns {string[]} - A list of successfully added type names.
|
|
8602
|
+
*
|
|
8603
|
+
* @example
|
|
8604
|
+
* extendObjType({
|
|
8605
|
+
* htmlElement2: val => typeof HTMLElement !== 'undefined' && val instanceof HTMLElement
|
|
8606
|
+
* });
|
|
8607
|
+
*
|
|
8608
|
+
* @example
|
|
8609
|
+
* extendObjType([
|
|
8610
|
+
* ['alpha', val => typeof val === 'string'],
|
|
8611
|
+
* ['beta', val => Array.isArray(val)]
|
|
8612
|
+
* ]);
|
|
8613
|
+
*/
|
|
8614
|
+
function extendObjType(newItems, index) {
|
|
8615
|
+
const added = [];
|
|
8616
|
+
|
|
8617
|
+
const entries = Array.isArray(newItems) ? newItems : Object.entries(newItems);
|
|
8618
|
+
for (const [key, fn] of entries) {
|
|
8619
|
+
if (!typeValidator.items.hasOwnProperty(key)) {
|
|
8620
|
+
// @ts-ignore
|
|
8621
|
+
typeValidator.items[key] = fn;
|
|
8622
|
+
|
|
8623
|
+
let insertAt = typeof index === 'number' ? index : -1; // Default to -1 if index isn't provided
|
|
8624
|
+
|
|
8625
|
+
// Default to before 'object', or to the end
|
|
8626
|
+
if (insertAt === -1) {
|
|
8627
|
+
const objectIndex = typeValidator.order.indexOf('object');
|
|
8628
|
+
insertAt = objectIndex > -1 ? objectIndex : typeValidator.order.length;
|
|
8629
|
+
}
|
|
8630
|
+
|
|
8631
|
+
// Ensure insertAt is a valid number and not out of bounds
|
|
8632
|
+
insertAt = Math.min(Math.max(0, insertAt), typeValidator.order.length);
|
|
8633
|
+
|
|
8634
|
+
typeValidator.order.splice(insertAt, 0, key);
|
|
8635
|
+
added.push(key);
|
|
8636
|
+
}
|
|
8637
|
+
}
|
|
8638
|
+
|
|
8639
|
+
return added;
|
|
8640
|
+
}
|
|
8641
|
+
|
|
8642
|
+
/**
|
|
8643
|
+
* Reorders the typeValidator.order array according to a custom new order.
|
|
8644
|
+
* All values in the new order must already exist in the current order.
|
|
8645
|
+
* The function does not mutate the original array structure directly.
|
|
8646
|
+
*
|
|
8647
|
+
* @param {string[]} newOrder - The new order of type names.
|
|
8648
|
+
* @returns {boolean} - Returns true if the reorder was successful, false if invalid keys were found.
|
|
8649
|
+
*
|
|
8650
|
+
* @example
|
|
8651
|
+
* reorderObjTypeOrder([
|
|
8652
|
+
* 'string', 'number', 'array', 'object'
|
|
8653
|
+
* ]);
|
|
8654
|
+
*/
|
|
8655
|
+
function reorderObjTypeOrder(newOrder) {
|
|
8656
|
+
const currentOrder = [...typeValidator.order]; // shallow clone
|
|
8657
|
+
|
|
8658
|
+
// All keys in newOrder must exist in currentOrder
|
|
8659
|
+
const isValid = newOrder.every((type) => currentOrder.includes(type));
|
|
8660
|
+
|
|
8661
|
+
if (!isValid) return false;
|
|
8795
8662
|
|
|
8796
|
-
|
|
8797
|
-
|
|
8798
|
-
|
|
8663
|
+
// Reassign only if valid
|
|
8664
|
+
typeValidator.order = newOrder.slice(); // assign shallow copy
|
|
8665
|
+
return true;
|
|
8666
|
+
}
|
|
8799
8667
|
|
|
8800
8668
|
/**
|
|
8801
|
-
* Returns
|
|
8669
|
+
* Returns a cloned version of the `typeValidator.order` array.
|
|
8670
|
+
* The cloned array will not be affected by future changes to the original `order`.
|
|
8802
8671
|
*
|
|
8803
|
-
* @
|
|
8804
|
-
* @returns {HtmlElBoxSides} - Total horizontal (x) and vertical (y) border widths, and each side individually.
|
|
8805
|
-
* @deprecated - Use TinyHtml.borderWidth instead.
|
|
8672
|
+
* @returns {string[]} - A new array with the same values as `typeValidator.order`.
|
|
8806
8673
|
*/
|
|
8807
|
-
|
|
8808
|
-
return
|
|
8809
|
-
}
|
|
8674
|
+
function cloneObjTypeOrder() {
|
|
8675
|
+
return [...typeValidator.order]; // Creates a shallow copy of the array
|
|
8676
|
+
}
|
|
8810
8677
|
|
|
8811
8678
|
/**
|
|
8812
|
-
* Returns the
|
|
8679
|
+
* Returns the detected type name of a given value based on predefined type validators.
|
|
8813
8680
|
*
|
|
8814
|
-
*
|
|
8815
|
-
*
|
|
8816
|
-
*
|
|
8681
|
+
* This function uses `getType` with a predefined `typeValidator` to determine or compare types safely.
|
|
8682
|
+
* in the specified `typeValidator.order`. The first matching type is returned.
|
|
8683
|
+
*
|
|
8684
|
+
* If `val` is `null`, it immediately returns `'null'`.
|
|
8685
|
+
* If no match is found, it returns `'unknown'`.
|
|
8686
|
+
*
|
|
8687
|
+
* @param {any} val - The value whose type should be determined.
|
|
8688
|
+
* @returns {string} - The type name of the value (e.g., "array", "date", "map"), or "unknown" if no match is found.
|
|
8689
|
+
*
|
|
8690
|
+
* @example
|
|
8691
|
+
* getType([]); // "array"
|
|
8692
|
+
* getType(null); // "null"
|
|
8693
|
+
* getType(new Set()); // "set"
|
|
8694
|
+
* getType(() => {}); // "unknown"
|
|
8817
8695
|
*/
|
|
8818
|
-
const
|
|
8819
|
-
|
|
8696
|
+
const getType = (val) => {
|
|
8697
|
+
if (val === null) return 'null';
|
|
8698
|
+
// @ts-ignore
|
|
8699
|
+
for (const name of typeValidator.order) {
|
|
8700
|
+
// @ts-ignore
|
|
8701
|
+
if (typeof typeValidator.items[name] !== 'function' || typeValidator.items[name](val))
|
|
8702
|
+
return name;
|
|
8703
|
+
}
|
|
8704
|
+
return 'unknown';
|
|
8820
8705
|
};
|
|
8821
8706
|
|
|
8822
8707
|
/**
|
|
8823
|
-
*
|
|
8708
|
+
* Checks the type of a given object or returns its type as a string.
|
|
8824
8709
|
*
|
|
8825
|
-
* @param {
|
|
8826
|
-
* @
|
|
8827
|
-
* @
|
|
8710
|
+
* @param {*} obj - The object to check or identify.
|
|
8711
|
+
* @param {string} [type] - Optional. If provided, checks whether the object matches this type (e.g., "object", "array", "string").
|
|
8712
|
+
* @returns {boolean|string|null} - Returns `true` if the type matches, `false` if not,
|
|
8713
|
+
* the type string if no type is provided, or `null` if the object is `undefined`.
|
|
8714
|
+
*
|
|
8715
|
+
* @example
|
|
8716
|
+
* objType([], 'array'); // true
|
|
8717
|
+
* objType({}, 'object'); // true
|
|
8718
|
+
* objType('hello'); // "string"
|
|
8719
|
+
* objType(undefined); // null
|
|
8828
8720
|
*/
|
|
8829
|
-
|
|
8830
|
-
|
|
8831
|
-
|
|
8721
|
+
function objType(obj, type) {
|
|
8722
|
+
if (typeof obj === 'undefined') return null;
|
|
8723
|
+
const result = getType(obj);
|
|
8724
|
+
if (typeof type === 'string') return result === type.toLowerCase();
|
|
8725
|
+
return result;
|
|
8726
|
+
}
|
|
8832
8727
|
|
|
8833
8728
|
/**
|
|
8834
|
-
*
|
|
8729
|
+
* Checks the type of a given object and returns the validation value if a known type is detected.
|
|
8835
8730
|
*
|
|
8836
|
-
* @param {
|
|
8837
|
-
* @returns {
|
|
8838
|
-
* @deprecated - Use TinyHtml.padding instead.
|
|
8731
|
+
* @param {*} obj - The object to check or identify.
|
|
8732
|
+
* @returns {{ valid:*; type: string | null }} - Returns the type result.
|
|
8839
8733
|
*/
|
|
8840
|
-
|
|
8841
|
-
|
|
8842
|
-
};
|
|
8843
|
-
|
|
8844
|
-
|
|
8845
|
-
|
|
8846
|
-
//
|
|
8734
|
+
function checkObj(obj) {
|
|
8735
|
+
/** @type {{ valid:*; type: string | null }} */
|
|
8736
|
+
const data = { valid: null, type: null };
|
|
8737
|
+
for (const name of typeValidator.order) {
|
|
8738
|
+
// @ts-ignore
|
|
8739
|
+
if (typeof typeValidator.items[name] === 'function') {
|
|
8740
|
+
// @ts-ignore
|
|
8741
|
+
const result = typeValidator.items[name](obj);
|
|
8742
|
+
if (result) {
|
|
8743
|
+
data.valid = result;
|
|
8744
|
+
data.type = name;
|
|
8745
|
+
break;
|
|
8746
|
+
}
|
|
8747
|
+
}
|
|
8748
|
+
}
|
|
8749
|
+
return data;
|
|
8750
|
+
}
|
|
8847
8751
|
|
|
8848
8752
|
/**
|
|
8849
|
-
*
|
|
8850
|
-
*
|
|
8851
|
-
* @param {HTMLElement} element - The DOM element to check.
|
|
8852
|
-
* @returns {boolean} True if the element is partially in the viewport, false otherwise.
|
|
8853
|
-
* @deprecated - Use TinyHtml.isInViewport instead.
|
|
8753
|
+
* Creates a clone of the functions from the `typeValidator` object.
|
|
8754
|
+
* It returns a new object where the keys are the same and the values are the cloned functions.
|
|
8854
8755
|
*/
|
|
8855
|
-
function
|
|
8856
|
-
|
|
8857
|
-
|
|
8756
|
+
function getCheckObj() {
|
|
8757
|
+
return Object.fromEntries(Object.entries(typeValidator.items).map(([key, fn]) => [key, fn]));
|
|
8758
|
+
}
|
|
8858
8759
|
|
|
8859
|
-
|
|
8860
|
-
const viewportBottom = viewportTop + window.innerHeight;
|
|
8760
|
+
// Insert obj types
|
|
8861
8761
|
|
|
8862
|
-
|
|
8762
|
+
extendObjType([
|
|
8763
|
+
[
|
|
8764
|
+
'undefined',
|
|
8765
|
+
/** @param {*} val @returns {val is undefined} */
|
|
8766
|
+
(val) => typeof val === 'undefined',
|
|
8767
|
+
],
|
|
8768
|
+
[
|
|
8769
|
+
'null',
|
|
8770
|
+
/** @param {*} val @returns {val is null} */
|
|
8771
|
+
(val) => val === null,
|
|
8772
|
+
],
|
|
8773
|
+
[
|
|
8774
|
+
'boolean',
|
|
8775
|
+
/** @param {*} val @returns {val is boolean} */
|
|
8776
|
+
(val) => typeof val === 'boolean',
|
|
8777
|
+
],
|
|
8778
|
+
[
|
|
8779
|
+
'number',
|
|
8780
|
+
/** @param {*} val @returns {val is number} */
|
|
8781
|
+
(val) => typeof val === 'number' && !Number.isNaN(val),
|
|
8782
|
+
],
|
|
8783
|
+
[
|
|
8784
|
+
'bigint',
|
|
8785
|
+
/** @param {*} val @returns {val is bigint} */
|
|
8786
|
+
(val) => typeof val === 'bigint',
|
|
8787
|
+
],
|
|
8788
|
+
[
|
|
8789
|
+
'string',
|
|
8790
|
+
/** @param {*} val @returns {val is string} */
|
|
8791
|
+
(val) => typeof val === 'string',
|
|
8792
|
+
],
|
|
8793
|
+
[
|
|
8794
|
+
'symbol',
|
|
8795
|
+
/** @param {*} val @returns {val is symbol} */
|
|
8796
|
+
(val) => typeof val === 'symbol',
|
|
8797
|
+
],
|
|
8798
|
+
[
|
|
8799
|
+
'function',
|
|
8800
|
+
/** @param {*} val @returns {val is Function} */
|
|
8801
|
+
(val) => typeof val === 'function',
|
|
8802
|
+
],
|
|
8803
|
+
[
|
|
8804
|
+
'array',
|
|
8805
|
+
/** @param {*} val @returns {val is any[]} */
|
|
8806
|
+
(val) => Array.isArray(val),
|
|
8807
|
+
],
|
|
8808
|
+
]);
|
|
8809
|
+
|
|
8810
|
+
if (!isBrowser) {
|
|
8811
|
+
extendObjType([
|
|
8812
|
+
[
|
|
8813
|
+
'buffer',
|
|
8814
|
+
/** @param {*} val @returns {val is Buffer} */
|
|
8815
|
+
(val) => typeof buffer/* Buffer */.hp !== 'undefined' && buffer/* Buffer */.hp.isBuffer(val),
|
|
8816
|
+
],
|
|
8817
|
+
]);
|
|
8863
8818
|
}
|
|
8864
8819
|
|
|
8865
|
-
|
|
8866
|
-
|
|
8867
|
-
|
|
8868
|
-
|
|
8869
|
-
|
|
8870
|
-
|
|
8871
|
-
|
|
8872
|
-
|
|
8873
|
-
|
|
8874
|
-
const viewportBottom = viewportTop + window.innerHeight;
|
|
8820
|
+
if (isBrowser) {
|
|
8821
|
+
extendObjType([
|
|
8822
|
+
[
|
|
8823
|
+
'file',
|
|
8824
|
+
/** @param {*} val @returns {val is File} */
|
|
8825
|
+
(val) => typeof File !== 'undefined' && val instanceof File,
|
|
8826
|
+
],
|
|
8827
|
+
]);
|
|
8828
|
+
}
|
|
8875
8829
|
|
|
8876
|
-
|
|
8877
|
-
|
|
8830
|
+
extendObjType([
|
|
8831
|
+
[
|
|
8832
|
+
'date',
|
|
8833
|
+
/** @param {*} val @returns {val is Date} */
|
|
8834
|
+
(val) => val instanceof Date,
|
|
8835
|
+
],
|
|
8836
|
+
[
|
|
8837
|
+
'regexp',
|
|
8838
|
+
/** @param {*} val @returns {val is RegExp} */
|
|
8839
|
+
(val) => val instanceof RegExp,
|
|
8840
|
+
],
|
|
8841
|
+
[
|
|
8842
|
+
'map',
|
|
8843
|
+
/** @param {*} val @returns {val is Map<unknown, unknown>} */
|
|
8844
|
+
(val) => val instanceof Map,
|
|
8845
|
+
],
|
|
8846
|
+
[
|
|
8847
|
+
'set',
|
|
8848
|
+
/** @param {*} val @returns {val is Set<unknown>} */
|
|
8849
|
+
(val) => val instanceof Set,
|
|
8850
|
+
],
|
|
8851
|
+
[
|
|
8852
|
+
'weakmap',
|
|
8853
|
+
/** @param {*} val @returns {val is WeakMap<unknown, unknown>} */
|
|
8854
|
+
(val) => val instanceof WeakMap,
|
|
8855
|
+
],
|
|
8856
|
+
[
|
|
8857
|
+
'weakset',
|
|
8858
|
+
/** @param {*} val @returns {val is WeakSet<unknown>} */
|
|
8859
|
+
(val) => val instanceof WeakSet,
|
|
8860
|
+
],
|
|
8861
|
+
[
|
|
8862
|
+
'promise',
|
|
8863
|
+
/** @param {*} val @returns {val is Promise<unknown>} */
|
|
8864
|
+
(val) => val instanceof Promise,
|
|
8865
|
+
],
|
|
8866
|
+
]);
|
|
8878
8867
|
|
|
8879
|
-
|
|
8868
|
+
if (isBrowser) {
|
|
8869
|
+
extendObjType([
|
|
8870
|
+
[
|
|
8871
|
+
'htmlelement',
|
|
8872
|
+
/** @param {*} val @returns {val is HTMLElement} */
|
|
8873
|
+
(val) => typeof HTMLElement !== 'undefined' && val instanceof HTMLElement,
|
|
8874
|
+
],
|
|
8875
|
+
]);
|
|
8880
8876
|
}
|
|
8881
8877
|
|
|
8878
|
+
extendObjType([
|
|
8879
|
+
[
|
|
8880
|
+
'object',
|
|
8881
|
+
/** @param {*} val @returns {val is Record<string | number | symbol, unknown>} */
|
|
8882
|
+
(val) => isJsonObject(val),
|
|
8883
|
+
],
|
|
8884
|
+
]);
|
|
8885
|
+
|
|
8882
8886
|
;// ./src/v1/basics/fullScreen.mjs
|
|
8883
8887
|
/**
|
|
8884
8888
|
* Checks if the document is currently in fullscreen mode.
|
|
@@ -9315,6 +9319,7 @@ export default KeyPressHandler;
|
|
|
9315
9319
|
|
|
9316
9320
|
|
|
9317
9321
|
|
|
9322
|
+
|
|
9318
9323
|
})();
|
|
9319
9324
|
|
|
9320
9325
|
window.TinyBasicsEs = __webpack_exports__;
|