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