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