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