@whitesev/utils 2.2.1 → 2.2.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.
- package/dist/index.amd.js +177 -40
- package/dist/index.amd.js.map +1 -1
- package/dist/index.cjs.js +177 -40
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +177 -40
- package/dist/index.esm.js.map +1 -1
- package/dist/index.iife.js +177 -40
- package/dist/index.iife.js.map +1 -1
- package/dist/index.system.js +177 -40
- package/dist/index.system.js.map +1 -1
- package/dist/index.umd.js +177 -40
- package/dist/index.umd.js.map +1 -1
- package/dist/types/src/Httpx.d.ts +23 -13
- package/dist/types/src/Utils.d.ts +8 -1
- package/package.json +1 -1
- package/src/Httpx.ts +239 -104
- package/src/Utils.ts +48 -1
package/src/Utils.ts
CHANGED
|
@@ -52,7 +52,7 @@ class Utils {
|
|
|
52
52
|
this.windowApi = new WindowApi(option);
|
|
53
53
|
}
|
|
54
54
|
/** 版本号 */
|
|
55
|
-
version = "2024.9.
|
|
55
|
+
version = "2024.9.4";
|
|
56
56
|
|
|
57
57
|
/**
|
|
58
58
|
* 在页面中增加style元素,如果html节点存在子节点,添加子节点第一个,反之,添加到html节点的子节点最后一个
|
|
@@ -864,6 +864,12 @@ class Utils {
|
|
|
864
864
|
| "yyyy-MM-dd"
|
|
865
865
|
| "yyyyMMdd"
|
|
866
866
|
| "HH:mm:ss"
|
|
867
|
+
| "yyyy"
|
|
868
|
+
| "MM"
|
|
869
|
+
| "dd"
|
|
870
|
+
| "HH"
|
|
871
|
+
| "mm"
|
|
872
|
+
| "ss"
|
|
867
873
|
): string;
|
|
868
874
|
formatTime(text = new Date(), formatType = "yyyy-MM-dd HH:mm:ss") {
|
|
869
875
|
let time = text == null ? new Date() : new Date(text);
|
|
@@ -2513,6 +2519,47 @@ class Utils {
|
|
|
2513
2519
|
}
|
|
2514
2520
|
return mutationObserver;
|
|
2515
2521
|
}
|
|
2522
|
+
/**
|
|
2523
|
+
* 使用观察器观察元素出现在视图内,出现的话触发回调
|
|
2524
|
+
* @param target 目标元素
|
|
2525
|
+
* @param callback 触发的回调
|
|
2526
|
+
* @param options 观察器配置
|
|
2527
|
+
*/
|
|
2528
|
+
mutatuinVisible(
|
|
2529
|
+
target: Element | Element[],
|
|
2530
|
+
callback: (
|
|
2531
|
+
entries: IntersectionObserverEntry[],
|
|
2532
|
+
observer: IntersectionObserver
|
|
2533
|
+
) => void,
|
|
2534
|
+
options?: IntersectionObserverInit
|
|
2535
|
+
) {
|
|
2536
|
+
if (typeof IntersectionObserver === "undefined") {
|
|
2537
|
+
throw new TypeError("IntersectionObserver is not defined");
|
|
2538
|
+
}
|
|
2539
|
+
if (target == null) {
|
|
2540
|
+
throw new TypeError("mutatuinVisible target is null");
|
|
2541
|
+
}
|
|
2542
|
+
let defaultOptions: IntersectionObserverInit = {
|
|
2543
|
+
root: null,
|
|
2544
|
+
rootMargin: "0px 0px 0px 0px",
|
|
2545
|
+
threshold: [0.01, 0.99],
|
|
2546
|
+
};
|
|
2547
|
+
defaultOptions = this.assign(defaultOptions, options || {});
|
|
2548
|
+
let intersectionObserver = new IntersectionObserver((entries, observer) => {
|
|
2549
|
+
if (entries[0].isIntersecting) {
|
|
2550
|
+
if (typeof callback === "function") {
|
|
2551
|
+
callback(entries, observer);
|
|
2552
|
+
}
|
|
2553
|
+
}
|
|
2554
|
+
}, defaultOptions);
|
|
2555
|
+
if (Array.isArray(target)) {
|
|
2556
|
+
target.forEach((item) => {
|
|
2557
|
+
intersectionObserver.observe(item);
|
|
2558
|
+
});
|
|
2559
|
+
} else {
|
|
2560
|
+
intersectionObserver.observe(target);
|
|
2561
|
+
}
|
|
2562
|
+
}
|
|
2516
2563
|
/**
|
|
2517
2564
|
* 去除全局window下的Utils,返回控制权
|
|
2518
2565
|
* @example
|