@whitesev/utils 2.4.6 → 2.4.8
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 +49 -8
- package/dist/index.amd.js.map +1 -1
- package/dist/index.cjs.js +49 -8
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +49 -8
- package/dist/index.esm.js.map +1 -1
- package/dist/index.iife.js +49 -8
- package/dist/index.iife.js.map +1 -1
- package/dist/index.system.js +49 -8
- package/dist/index.system.js.map +1 -1
- package/dist/index.umd.js +49 -8
- package/dist/index.umd.js.map +1 -1
- package/dist/types/src/Utils.d.ts +11 -5
- package/dist/types/src/WindowApi.d.ts +2 -2
- package/dist/types/src/types/WindowApi.d.ts +3 -3
- package/package.json +1 -1
- package/src/Utils.ts +59 -16
- package/src/WindowApi.ts +13 -4
- package/src/types/WindowApi.d.ts +3 -3
|
@@ -13,10 +13,10 @@ import type { DOMUtils_EventType } from "./types/Event";
|
|
|
13
13
|
import type { UtilsAjaxHookResult } from "./types/ajaxHooker";
|
|
14
14
|
import { Vue } from "./Vue";
|
|
15
15
|
import { type ArgsType, type JSTypeNames, type UtilsOwnObject } from "./types/global";
|
|
16
|
-
import type {
|
|
16
|
+
import type { WindowApiOption } from "./types/WindowApi";
|
|
17
17
|
declare class Utils {
|
|
18
18
|
private windowApi;
|
|
19
|
-
constructor(option?:
|
|
19
|
+
constructor(option?: WindowApiOption);
|
|
20
20
|
/** 版本号 */
|
|
21
21
|
version: string;
|
|
22
22
|
/**
|
|
@@ -786,12 +786,18 @@ declare class Utils {
|
|
|
786
786
|
isNativeFunc(target: Function): boolean;
|
|
787
787
|
/**
|
|
788
788
|
* 判断当前的位置是否位于页面底部附近
|
|
789
|
-
* @param
|
|
789
|
+
* @param nearBottomHeight (可选)判断在底部的误差值,默认:50
|
|
790
790
|
* @returns
|
|
791
791
|
* + true 在底部附近
|
|
792
792
|
* + false 不在底部附近
|
|
793
793
|
*/
|
|
794
|
-
isNearBottom(
|
|
794
|
+
isNearBottom(nearBottomHeight?: number): boolean;
|
|
795
|
+
/**
|
|
796
|
+
* 判断元素内当前的位置是否位于元素内底部附近
|
|
797
|
+
* @param target 需要判断的元素
|
|
798
|
+
* @param nearBottomHeight (可选)判断在底部的误差值,默认:50
|
|
799
|
+
*/
|
|
800
|
+
isNearBottom(target: HTMLElement, nearBottomHeight?: number): boolean;
|
|
795
801
|
/**
|
|
796
802
|
* 判断对象是否是元素
|
|
797
803
|
* @param target
|
|
@@ -1720,7 +1726,7 @@ declare class Utils {
|
|
|
1720
1726
|
* @param option
|
|
1721
1727
|
* @returns
|
|
1722
1728
|
*/
|
|
1723
|
-
createUtils(option?:
|
|
1729
|
+
createUtils(option?: WindowApiOption): Utils;
|
|
1724
1730
|
/**
|
|
1725
1731
|
* 将对象转换为FormData
|
|
1726
1732
|
* @param data 待转换的对象
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { WindowApiOption } from "./types/WindowApi";
|
|
2
2
|
declare class WindowApi {
|
|
3
3
|
/** 默认的配置 */
|
|
4
4
|
private defaultApi;
|
|
5
5
|
/** 使用的配置 */
|
|
6
6
|
private api;
|
|
7
|
-
constructor(option?:
|
|
7
|
+
constructor(option?: WindowApiOption);
|
|
8
8
|
get document(): Document;
|
|
9
9
|
get window(): Window & typeof globalThis;
|
|
10
10
|
get globalThis(): typeof globalThis | Window;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* 配置类型
|
|
3
3
|
*/
|
|
4
|
-
export type
|
|
4
|
+
export type WindowApiOption = {
|
|
5
5
|
document: Document;
|
|
6
6
|
window: Window & typeof globalThis;
|
|
7
|
-
globalThis
|
|
8
|
-
self
|
|
7
|
+
globalThis?: typeof globalThis | Window;
|
|
8
|
+
self?: Window & typeof globalThis;
|
|
9
9
|
top: Window;
|
|
10
10
|
};
|
package/package.json
CHANGED
package/src/Utils.ts
CHANGED
|
@@ -21,15 +21,15 @@ import {
|
|
|
21
21
|
type JSTypeNames,
|
|
22
22
|
type UtilsOwnObject,
|
|
23
23
|
} from "./types/global";
|
|
24
|
-
import type {
|
|
24
|
+
import type { WindowApiOption } from "./types/WindowApi";
|
|
25
25
|
|
|
26
26
|
class Utils {
|
|
27
|
-
private windowApi: WindowApi;
|
|
28
|
-
constructor(option?:
|
|
27
|
+
private windowApi: typeof WindowApi.prototype;
|
|
28
|
+
constructor(option?: WindowApiOption) {
|
|
29
29
|
this.windowApi = new WindowApi(option);
|
|
30
30
|
}
|
|
31
31
|
/** 版本号 */
|
|
32
|
-
version = "2024.11.
|
|
32
|
+
version = "2024.11.6";
|
|
33
33
|
|
|
34
34
|
/**
|
|
35
35
|
* 在页面中增加style元素,如果html节点存在子节点,添加子节点第一个,反之,添加到html节点的子节点最后一个
|
|
@@ -1857,21 +1857,64 @@ class Utils {
|
|
|
1857
1857
|
}
|
|
1858
1858
|
/**
|
|
1859
1859
|
* 判断当前的位置是否位于页面底部附近
|
|
1860
|
-
* @param
|
|
1860
|
+
* @param nearBottomHeight (可选)判断在底部的误差值,默认:50
|
|
1861
1861
|
* @returns
|
|
1862
1862
|
* + true 在底部附近
|
|
1863
1863
|
* + false 不在底部附近
|
|
1864
1864
|
*/
|
|
1865
|
-
isNearBottom(
|
|
1866
|
-
|
|
1867
|
-
|
|
1868
|
-
|
|
1869
|
-
|
|
1870
|
-
|
|
1871
|
-
|
|
1872
|
-
|
|
1873
|
-
|
|
1874
|
-
|
|
1865
|
+
isNearBottom(nearBottomHeight?: number): boolean;
|
|
1866
|
+
/**
|
|
1867
|
+
* 判断元素内当前的位置是否位于元素内底部附近
|
|
1868
|
+
* @param target 需要判断的元素
|
|
1869
|
+
* @param nearBottomHeight (可选)判断在底部的误差值,默认:50
|
|
1870
|
+
*/
|
|
1871
|
+
isNearBottom(target: HTMLElement, nearBottomHeight?: number): boolean;
|
|
1872
|
+
isNearBottom(...args: any[]): boolean {
|
|
1873
|
+
let nearBottomHeight = 50;
|
|
1874
|
+
|
|
1875
|
+
let checkWindow = () => {
|
|
1876
|
+
// 已滚动的距离
|
|
1877
|
+
let scrollTop: number =
|
|
1878
|
+
this.windowApi.window.pageYOffset ||
|
|
1879
|
+
this.windowApi.document.documentElement.scrollTop;
|
|
1880
|
+
// 视窗高度
|
|
1881
|
+
let viewportHeight: number =
|
|
1882
|
+
this.windowApi.window.innerHeight ||
|
|
1883
|
+
this.windowApi.document.documentElement.clientHeight;
|
|
1884
|
+
// 最大滚动距离
|
|
1885
|
+
let maxScrollHeight: number =
|
|
1886
|
+
this.windowApi.document.documentElement.scrollHeight - nearBottomHeight;
|
|
1887
|
+
|
|
1888
|
+
return scrollTop + viewportHeight >= maxScrollHeight;
|
|
1889
|
+
};
|
|
1890
|
+
|
|
1891
|
+
let checkNode = ($ele: HTMLElement) => {
|
|
1892
|
+
// 已滚动的距离
|
|
1893
|
+
let scrollTop: number = $ele.scrollTop;
|
|
1894
|
+
// 视窗高度
|
|
1895
|
+
let viewportHeight: number = $ele.clientHeight;
|
|
1896
|
+
// 最大滚动距离
|
|
1897
|
+
let maxScrollHeight: number =
|
|
1898
|
+
$ele.scrollHeight - viewportHeight - nearBottomHeight;
|
|
1899
|
+
|
|
1900
|
+
return scrollTop >= maxScrollHeight;
|
|
1901
|
+
};
|
|
1902
|
+
|
|
1903
|
+
let firstArg = args[0];
|
|
1904
|
+
if (args.length === 0 || typeof args[0] === "number") {
|
|
1905
|
+
// nearBottomHeight
|
|
1906
|
+
//
|
|
1907
|
+
return checkWindow();
|
|
1908
|
+
} else if (typeof args[0] === "object" && args[0] instanceof HTMLElement) {
|
|
1909
|
+
// target
|
|
1910
|
+
// target,nearBottomHeight
|
|
1911
|
+
if (typeof args[1] === "number" && !Number.isNaN(args[1])) {
|
|
1912
|
+
nearBottomHeight = args[1];
|
|
1913
|
+
}
|
|
1914
|
+
return checkNode(args[0]);
|
|
1915
|
+
} else {
|
|
1916
|
+
throw new TypeError("参数1类型错误" + typeof firstArg);
|
|
1917
|
+
}
|
|
1875
1918
|
}
|
|
1876
1919
|
/**
|
|
1877
1920
|
* 判断对象是否是元素
|
|
@@ -4978,7 +5021,7 @@ class Utils {
|
|
|
4978
5021
|
* @param option
|
|
4979
5022
|
* @returns
|
|
4980
5023
|
*/
|
|
4981
|
-
createUtils(option?:
|
|
5024
|
+
createUtils(option?: WindowApiOption) {
|
|
4982
5025
|
return new Utils(option);
|
|
4983
5026
|
}
|
|
4984
5027
|
|
package/src/WindowApi.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { WindowApiOption } from "./types/WindowApi";
|
|
2
2
|
|
|
3
3
|
class WindowApi {
|
|
4
4
|
/** 默认的配置 */
|
|
5
|
-
private defaultApi:
|
|
5
|
+
private defaultApi: Required<WindowApiOption> = {
|
|
6
6
|
document: document,
|
|
7
7
|
window: window,
|
|
8
8
|
globalThis: globalThis,
|
|
@@ -10,11 +10,20 @@ class WindowApi {
|
|
|
10
10
|
top: top!,
|
|
11
11
|
};
|
|
12
12
|
/** 使用的配置 */
|
|
13
|
-
private api:
|
|
14
|
-
constructor(option?:
|
|
13
|
+
private api: Required<WindowApiOption>;
|
|
14
|
+
constructor(option?: WindowApiOption) {
|
|
15
|
+
if (option) {
|
|
16
|
+
if (option.globalThis == null) {
|
|
17
|
+
option.globalThis = option.window;
|
|
18
|
+
}
|
|
19
|
+
if (option.self == null) {
|
|
20
|
+
option.self = option.window;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
15
23
|
if (!option) {
|
|
16
24
|
option = Object.assign({}, this.defaultApi);
|
|
17
25
|
}
|
|
26
|
+
// @ts-ignore
|
|
18
27
|
this.api = Object.assign({}, option);
|
|
19
28
|
}
|
|
20
29
|
get document() {
|
package/src/types/WindowApi.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* 配置类型
|
|
3
3
|
*/
|
|
4
|
-
export type
|
|
4
|
+
export type WindowApiOption = {
|
|
5
5
|
document: Document;
|
|
6
6
|
window: Window & typeof globalThis;
|
|
7
|
-
globalThis
|
|
8
|
-
self
|
|
7
|
+
globalThis?: typeof globalThis | Window;
|
|
8
|
+
self?: Window & typeof globalThis;
|
|
9
9
|
top: Window;
|
|
10
10
|
};
|