@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
package/dist/index.umd.js
CHANGED
|
@@ -3830,9 +3830,18 @@
|
|
|
3830
3830
|
/** 使用的配置 */
|
|
3831
3831
|
api;
|
|
3832
3832
|
constructor(option) {
|
|
3833
|
+
if (option) {
|
|
3834
|
+
if (option.globalThis == null) {
|
|
3835
|
+
option.globalThis = option.window;
|
|
3836
|
+
}
|
|
3837
|
+
if (option.self == null) {
|
|
3838
|
+
option.self = option.window;
|
|
3839
|
+
}
|
|
3840
|
+
}
|
|
3833
3841
|
if (!option) {
|
|
3834
3842
|
option = Object.assign({}, this.defaultApi);
|
|
3835
3843
|
}
|
|
3844
|
+
// @ts-ignore
|
|
3836
3845
|
this.api = Object.assign({}, option);
|
|
3837
3846
|
}
|
|
3838
3847
|
get document() {
|
|
@@ -4097,7 +4106,7 @@
|
|
|
4097
4106
|
this.windowApi = new WindowApi(option);
|
|
4098
4107
|
}
|
|
4099
4108
|
/** 版本号 */
|
|
4100
|
-
version = "2024.11.
|
|
4109
|
+
version = "2024.11.6";
|
|
4101
4110
|
addStyle(cssText) {
|
|
4102
4111
|
if (typeof cssText !== "string") {
|
|
4103
4112
|
throw new Error("Utils.addStyle 参数cssText 必须为String类型");
|
|
@@ -5281,13 +5290,45 @@
|
|
|
5281
5290
|
isNativeFunc(target) {
|
|
5282
5291
|
return Boolean(target.toString().match(/^function .*\(\) { \[native code\] }$/));
|
|
5283
5292
|
}
|
|
5284
|
-
isNearBottom(
|
|
5285
|
-
|
|
5286
|
-
|
|
5287
|
-
|
|
5288
|
-
this.windowApi.
|
|
5289
|
-
|
|
5290
|
-
|
|
5293
|
+
isNearBottom(...args) {
|
|
5294
|
+
let nearBottomHeight = 50;
|
|
5295
|
+
let checkWindow = () => {
|
|
5296
|
+
// 已滚动的距离
|
|
5297
|
+
let scrollTop = this.windowApi.window.pageYOffset ||
|
|
5298
|
+
this.windowApi.document.documentElement.scrollTop;
|
|
5299
|
+
// 视窗高度
|
|
5300
|
+
let viewportHeight = this.windowApi.window.innerHeight ||
|
|
5301
|
+
this.windowApi.document.documentElement.clientHeight;
|
|
5302
|
+
// 最大滚动距离
|
|
5303
|
+
let maxScrollHeight = this.windowApi.document.documentElement.scrollHeight - nearBottomHeight;
|
|
5304
|
+
return scrollTop + viewportHeight >= maxScrollHeight;
|
|
5305
|
+
};
|
|
5306
|
+
let checkNode = ($ele) => {
|
|
5307
|
+
// 已滚动的距离
|
|
5308
|
+
let scrollTop = $ele.scrollTop;
|
|
5309
|
+
// 视窗高度
|
|
5310
|
+
let viewportHeight = $ele.clientHeight;
|
|
5311
|
+
// 最大滚动距离
|
|
5312
|
+
let maxScrollHeight = $ele.scrollHeight - viewportHeight - nearBottomHeight;
|
|
5313
|
+
return scrollTop >= maxScrollHeight;
|
|
5314
|
+
};
|
|
5315
|
+
let firstArg = args[0];
|
|
5316
|
+
if (args.length === 0 || typeof args[0] === "number") {
|
|
5317
|
+
// nearBottomHeight
|
|
5318
|
+
//
|
|
5319
|
+
return checkWindow();
|
|
5320
|
+
}
|
|
5321
|
+
else if (typeof args[0] === "object" && args[0] instanceof HTMLElement) {
|
|
5322
|
+
// target
|
|
5323
|
+
// target,nearBottomHeight
|
|
5324
|
+
if (typeof args[1] === "number" && !Number.isNaN(args[1])) {
|
|
5325
|
+
nearBottomHeight = args[1];
|
|
5326
|
+
}
|
|
5327
|
+
return checkNode(args[0]);
|
|
5328
|
+
}
|
|
5329
|
+
else {
|
|
5330
|
+
throw new TypeError("参数1类型错误" + typeof firstArg);
|
|
5331
|
+
}
|
|
5291
5332
|
}
|
|
5292
5333
|
isDOM(target) {
|
|
5293
5334
|
return target instanceof Node;
|