@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.
@@ -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.5";
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(nearValue = 50) {
5282
- var scrollTop = this.windowApi.window.pageYOffset ||
5283
- this.windowApi.document.documentElement.scrollTop;
5284
- var windowHeight = this.windowApi.window.innerHeight ||
5285
- this.windowApi.document.documentElement.clientHeight;
5286
- var documentHeight = this.windowApi.document.documentElement.scrollHeight;
5287
- return scrollTop + windowHeight >= documentHeight - nearValue;
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;