lyb-js 1.6.10 → 1.6.11

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.
@@ -0,0 +1,21 @@
1
+ import { LibJsClassObservable } from "./LibJsClassObservable";
2
+ interface PullUpLoadObservable {
3
+ /** 当前加载状态文案 */
4
+ statusText: string;
5
+ /** 加载状态 */
6
+ loadStatus: "idle" | "loading" | "noMore" | "empty";
7
+ }
8
+ interface PullUpLoadParams {
9
+ /** 滚动容器 */
10
+ scrollEl: HTMLElement;
11
+ /** 加载状态元素 */
12
+ loadStatusEl: HTMLElement;
13
+ /** 触发加载回调 */
14
+ onLoad: () => void;
15
+ }
16
+ /** @description 上拉加载 */
17
+ export declare class LibJsPullUpLoad extends LibJsClassObservable<PullUpLoadObservable> {
18
+ constructor(params: PullUpLoadParams);
19
+ private checkAutoLoad;
20
+ }
21
+ export {};
@@ -0,0 +1,47 @@
1
+ import { LibJsClassObservable } from "./LibJsClassObservable";
2
+ /** @description 上拉加载 */
3
+ export class LibJsPullUpLoad extends LibJsClassObservable {
4
+ constructor(params) {
5
+ super({
6
+ statusText: "加载中...",
7
+ loadStatus: "idle",
8
+ });
9
+ const { scrollEl, loadStatusEl, onLoad } = params;
10
+ this.checkAutoLoad(onLoad, scrollEl);
11
+ this.onValue("loadStatus", (v) => {
12
+ if (v === "idle") {
13
+ this.checkAutoLoad(onLoad, scrollEl);
14
+ }
15
+ });
16
+ /** @description 滚动触发 */
17
+ scrollEl.addEventListener("scroll", () => {
18
+ //如果所有数据已加载完毕,则不再触发加载
19
+ if (["noMore", "empty", "loading"].includes(this.getValue("loadStatus")))
20
+ return;
21
+ const y = scrollEl.scrollTop;
22
+ //获取距离加载触发像素值
23
+ const loadDistance = scrollEl.scrollHeight -
24
+ scrollEl.clientHeight -
25
+ y -
26
+ loadStatusEl.offsetHeight;
27
+ if (loadDistance <= 0) {
28
+ this.setValue("loadStatus", "loading");
29
+ this.setValue("statusText", "加载中...");
30
+ setTimeout(() => {
31
+ onLoad();
32
+ }, 500);
33
+ }
34
+ });
35
+ }
36
+ // 1. 新增方法
37
+ checkAutoLoad(onLoad, scrollEl) {
38
+ if (!["noMore", "empty", "loading"].includes(this.getValue("loadStatus")) &&
39
+ scrollEl.scrollHeight <= scrollEl.clientHeight) {
40
+ this.setValue("loadStatus", "loading");
41
+ this.setValue("statusText", "加载中...");
42
+ setTimeout(() => {
43
+ onLoad();
44
+ }, 500);
45
+ }
46
+ }
47
+ }
package/libJs.d.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  import { LibJsNumberStepper } from "./Misc/LibJsNumberStepper";
2
2
  import { LibJsClassObservable } from "./Misc/LibJsClassObservable";
3
3
  import { LibJsResizeWatcher } from "./Base/LibJsResizeWatcher";
4
+ import { LibJsPullUpLoad } from "./Misc/LibJsPullUpLoad";
4
5
  /** @description 基础方法 */
5
6
  export declare const Base: {
6
7
  /**
@@ -278,6 +279,8 @@ export declare const Misc: {
278
279
  * @link 使用方法:https://www.npmjs.com/package/lyb-js#LibJsClassObservable-类属性监听器
279
280
  */
280
281
  LibJsClassObservable: typeof LibJsClassObservable;
282
+ /** @description 上拉加载 */
283
+ LibJsPullUpLoad: typeof LibJsPullUpLoad;
281
284
  };
282
285
  /** @description 随机相关方法 */
283
286
  export declare const Random: {
package/libJs.js CHANGED
@@ -43,6 +43,7 @@ import { LibJsNormalizeInRange } from "./Math/LibJsNormalizeInRange";
43
43
  import { LibJsClassObservable } from "./Misc/LibJsClassObservable";
44
44
  import { libJsCopy } from "./Browser/LibJsCopy";
45
45
  import { LibJsResizeWatcher } from "./Base/LibJsResizeWatcher";
46
+ import { LibJsPullUpLoad } from "./Misc/LibJsPullUpLoad";
46
47
  /** @description 基础方法 */
47
48
  export const Base = {
48
49
  /**
@@ -290,6 +291,8 @@ export const Misc = {
290
291
  * @link 使用方法:https://www.npmjs.com/package/lyb-js#LibJsClassObservable-类属性监听器
291
292
  */
292
293
  LibJsClassObservable,
294
+ /** @description 上拉加载 */
295
+ LibJsPullUpLoad,
293
296
  };
294
297
  /** @description 随机相关方法 */
295
298
  export const Random = {
package/lyb.js CHANGED
@@ -308,10 +308,10 @@ ${log3.label}:`, log3.value];
308
308
  return distance;
309
309
  };
310
310
  /*!
311
- * decimal.js v10.4.3
311
+ * decimal.js v10.5.0
312
312
  * An arbitrary-precision Decimal type for JavaScript.
313
313
  * https://github.com/MikeMcl/decimal.js
314
- * Copyright (c) 2022 Michael Mclaughlin <M8ch88l@gmail.com>
314
+ * Copyright (c) 2025 Michael Mclaughlin <M8ch88l@gmail.com>
315
315
  * MIT Licence
316
316
  */
317
317
  var EXP_LIMIT = 9e15, MAX_DIGITS = 1e9, NUMERALS = "0123456789abcdef", LN10 = "2.3025850929940456840179914546843642076011014886287729760333279009675726096773524802359972050895982983419677840422862486334095254650828067566662873690987816894829072083255546808437998948262331985283935053089653777326288461633662222876982198867465436674744042432743651550489343149393914796194044002221051017141748003688084012647080685567743216228355220114804663715659121373450747856947683463616792101806445070648000277502684916746550586856935673420670581136429224554405758925724208241314695689016758940256776311356919292033376587141660230105703089634572075440370847469940168269282808481184289314848524948644871927809676271275775397027668605952496716674183485704422507197965004714951050492214776567636938662976979522110718264549734772662425709429322582798502585509785265383207606726317164309505995087807523710333101197857547331541421808427543863591778117054309827482385045648019095610299291824318237525357709750539565187697510374970888692180205189339507238539205144634197265287286965110862571492198849978748873771345686209167058", PI = "3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303819644288109756659334461284756482337867831652712019091456485669234603486104543266482133936072602491412737245870066063155881748815209209628292540917153643678925903600113305305488204665213841469519415116094330572703657595919530921861173819326117931051185480744623799627495673518857527248912279381830119491298336733624406566430860213949463952247371907021798609437027705392171762931767523846748184676694051320005681271452635608277857713427577896091736371787214684409012249534301465495853710507922796892589235420199561121290219608640344181598136297747713099605187072113499999983729780499510597317328160963185950244594553469083026425223082533446850352619311881710100031378387528865875332083814206171776691473035982534904287554687311595628638823537875937519577818577805321712268066130019278766111959092164201989380952572010654858632789", DEFAULTS = {
@@ -580,7 +580,7 @@ ${log3.label}:`, log3.value];
580
580
  return divide(x.sinh(), x.cosh(), Ctor.precision = pr, Ctor.rounding = rm);
581
581
  };
582
582
  P.inverseCosine = P.acos = function() {
583
- var halfPi, x = this, Ctor = x.constructor, k = x.abs().cmp(1), pr = Ctor.precision, rm = Ctor.rounding;
583
+ var x = this, Ctor = x.constructor, k = x.abs().cmp(1), pr = Ctor.precision, rm = Ctor.rounding;
584
584
  if (k !== -1) {
585
585
  return k === 0 ? x.isNeg() ? getPi(Ctor, pr, rm) : new Ctor(0) : new Ctor(NaN);
586
586
  }
@@ -588,11 +588,10 @@ ${log3.label}:`, log3.value];
588
588
  return getPi(Ctor, pr + 4, rm).times(0.5);
589
589
  Ctor.precision = pr + 6;
590
590
  Ctor.rounding = 1;
591
- x = x.asin();
592
- halfPi = getPi(Ctor, pr + 4, rm).times(0.5);
591
+ x = new Ctor(1).minus(x).div(x.plus(1)).sqrt().atan();
593
592
  Ctor.precision = pr;
594
593
  Ctor.rounding = rm;
595
- return halfPi.minus(x);
594
+ return x.times(2);
596
595
  };
597
596
  P.inverseHyperbolicCosine = P.acosh = function() {
598
597
  var pr, rm, x = this, Ctor = x.constructor;
@@ -1804,14 +1803,16 @@ ${log3.label}:`, log3.value];
1804
1803
  function isOdd(n) {
1805
1804
  return n.d[n.d.length - 1] & 1;
1806
1805
  }
1807
- function maxOrMin(Ctor, args, ltgt) {
1808
- var y, x = new Ctor(args[0]), i = 0;
1806
+ function maxOrMin(Ctor, args, n) {
1807
+ var k, y, x = new Ctor(args[0]), i = 0;
1809
1808
  for (; ++i < args.length; ) {
1810
1809
  y = new Ctor(args[i]);
1811
1810
  if (!y.s) {
1812
1811
  x = y;
1813
1812
  break;
1814
- } else if (x[ltgt](y)) {
1813
+ }
1814
+ k = x.cmp(y);
1815
+ if (k === n || k === 0 && x.s === n) {
1815
1816
  x = y;
1816
1817
  }
1817
1818
  }
@@ -2392,7 +2393,8 @@ ${log3.label}:`, log3.value];
2392
2393
  x.d = [v];
2393
2394
  }
2394
2395
  return;
2395
- } else if (v * 0 !== 0) {
2396
+ }
2397
+ if (v * 0 !== 0) {
2396
2398
  if (!v)
2397
2399
  x.s = NaN;
2398
2400
  x.e = NaN;
@@ -2400,18 +2402,28 @@ ${log3.label}:`, log3.value];
2400
2402
  return;
2401
2403
  }
2402
2404
  return parseDecimal(x, v.toString());
2403
- } else if (t !== "string") {
2404
- throw Error(invalidArgument + v);
2405
2405
  }
2406
- if ((i2 = v.charCodeAt(0)) === 45) {
2407
- v = v.slice(1);
2408
- x.s = -1;
2409
- } else {
2410
- if (i2 === 43)
2406
+ if (t === "string") {
2407
+ if ((i2 = v.charCodeAt(0)) === 45) {
2411
2408
  v = v.slice(1);
2412
- x.s = 1;
2409
+ x.s = -1;
2410
+ } else {
2411
+ if (i2 === 43)
2412
+ v = v.slice(1);
2413
+ x.s = 1;
2414
+ }
2415
+ return isDecimal.test(v) ? parseDecimal(x, v) : parseOther(x, v);
2416
+ }
2417
+ if (t === "bigint") {
2418
+ if (v < 0) {
2419
+ v = -v;
2420
+ x.s = -1;
2421
+ } else {
2422
+ x.s = 1;
2423
+ }
2424
+ return parseDecimal(x, v.toString());
2413
2425
  }
2414
- return isDecimal.test(v) ? parseDecimal(x, v) : parseOther(x, v);
2426
+ throw Error(invalidArgument + v);
2415
2427
  }
2416
2428
  Decimal2.prototype = P;
2417
2429
  Decimal2.ROUND_UP = 0;
@@ -2521,10 +2533,10 @@ ${log3.label}:`, log3.value];
2521
2533
  return new this(x).log(10);
2522
2534
  }
2523
2535
  function max() {
2524
- return maxOrMin(this, arguments, "lt");
2536
+ return maxOrMin(this, arguments, -1);
2525
2537
  }
2526
2538
  function min() {
2527
- return maxOrMin(this, arguments, "gt");
2539
+ return maxOrMin(this, arguments, 1);
2528
2540
  }
2529
2541
  function mod(x, y) {
2530
2542
  return new this(x).mod(y);
@@ -3555,6 +3567,44 @@ ${log3.label}:`, log3.value];
3555
3567
  };
3556
3568
  }
3557
3569
  }
3570
+ class LibJsPullUpLoad extends LibJsClassObservable {
3571
+ constructor(params) {
3572
+ super({
3573
+ statusText: "加载中...",
3574
+ loadStatus: "idle"
3575
+ });
3576
+ const { scrollEl, loadStatusEl, onLoad } = params;
3577
+ this.checkAutoLoad(onLoad, scrollEl);
3578
+ this.onValue("loadStatus", (v) => {
3579
+ if (v === "idle") {
3580
+ this.checkAutoLoad(onLoad, scrollEl);
3581
+ }
3582
+ });
3583
+ scrollEl.addEventListener("scroll", () => {
3584
+ if (["noMore", "empty", "loading"].includes(this.getValue("loadStatus")))
3585
+ return;
3586
+ const y = scrollEl.scrollTop;
3587
+ const loadDistance = scrollEl.scrollHeight - scrollEl.clientHeight - y - loadStatusEl.offsetHeight;
3588
+ if (loadDistance <= 0) {
3589
+ this.setValue("loadStatus", "loading");
3590
+ this.setValue("statusText", "加载中...");
3591
+ setTimeout(() => {
3592
+ onLoad();
3593
+ }, 500);
3594
+ }
3595
+ });
3596
+ }
3597
+ // 1. 新增方法
3598
+ checkAutoLoad(onLoad, scrollEl) {
3599
+ if (!["noMore", "empty", "loading"].includes(this.getValue("loadStatus")) && scrollEl.scrollHeight <= scrollEl.clientHeight) {
3600
+ this.setValue("loadStatus", "loading");
3601
+ this.setValue("statusText", "加载中...");
3602
+ setTimeout(() => {
3603
+ onLoad();
3604
+ }, 500);
3605
+ }
3606
+ }
3607
+ }
3558
3608
  const Base = {
3559
3609
  /**
3560
3610
  * @description 返回数据类型
@@ -3794,7 +3844,9 @@ ${log3.label}:`, log3.value];
3794
3844
  /** @description 类属性监听器
3795
3845
  * @link 使用方法:https://www.npmjs.com/package/lyb-js#LibJsClassObservable-类属性监听器
3796
3846
  */
3797
- LibJsClassObservable
3847
+ LibJsClassObservable,
3848
+ /** @description 上拉加载 */
3849
+ LibJsPullUpLoad
3798
3850
  };
3799
3851
  const Random = {
3800
3852
  /** @description 百分比概率结果
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lyb-js",
3
- "version": "1.6.10",
3
+ "version": "1.6.11",
4
4
  "description": "自用JS方法库",
5
5
  "license": "ISC",
6
6
  "type": "module",
@@ -1,25 +0,0 @@
1
- type Callback<T> = (newValue: T[keyof T], oldValue: T[keyof T]) => void;
2
- export declare class LibJsObserver<Store> {
3
- /** 递增索引 */
4
- private _index;
5
- private _store;
6
- private _lastData;
7
- private _listeners;
8
- constructor(store: Store);
9
- /** @description 监听
10
- * @param key 要监听的键
11
- * @param callback key值变化时执行的回调函数
12
- * @param immediately 监听时是否立即执行回调函数
13
- * @returns 返回一个函数用于注销监听器
14
- */
15
- on(key: keyof Store, callback: Callback<Store>, immediately?: boolean): () => void;
16
- /** @description 获取数据 */
17
- getData(key: keyof Store): Store[keyof Store];
18
- /** @description 手动更新数据 */
19
- setData(newData: Partial<Store>): void;
20
- /** @description 通知监听器更新 */
21
- private _notifyListeners;
22
- /** @description 判断数据变化并通知监听器 */
23
- private _update;
24
- }
25
- export {};
@@ -1,100 +0,0 @@
1
- export class LibJsObserver {
2
- constructor(store) {
3
- /** 递增索引 */
4
- this._index = 0;
5
- // 监听器映射,用于存储不同键的回调函数
6
- this._listeners = new Map();
7
- this._store = store;
8
- this._lastData = Object.assign({}, store);
9
- }
10
- /** @description 监听
11
- * @param key 要监听的键
12
- * @param callback key值变化时执行的回调函数
13
- * @param immediately 监听时是否立即执行回调函数
14
- * @returns 返回一个函数用于注销监听器
15
- */
16
- on(key, callback, immediately = true) {
17
- this._index += 1;
18
- const index = this._index;
19
- // 如果该键没有对应的监听器集合,则初始化一个新的集合
20
- if (!this._listeners.has(key)) {
21
- this._listeners.set(key, new Map());
22
- }
23
- // 将回调函数添加到对应键的监听器集合中
24
- this._listeners.get(key).set(index, callback);
25
- immediately && callback(this._store[key], this._lastData[key]);
26
- return () => {
27
- // 从特定键的监听器集合中移除指定标识符的回调函数
28
- const listenerMap = this._listeners.get(key);
29
- if (listenerMap) {
30
- listenerMap.delete(index);
31
- }
32
- else {
33
- console.warn(`监听 Key "${key.toString()}" 重复注销事件`);
34
- }
35
- };
36
- }
37
- /** @description 获取数据 */
38
- getData(key) {
39
- return this._store[key];
40
- }
41
- /** @description 手动更新数据 */
42
- setData(newData) {
43
- this._store = Object.assign(Object.assign({}, this._store), newData);
44
- this._update();
45
- }
46
- /** @description 通知监听器更新 */
47
- _notifyListeners(key, newValue, oldValue) {
48
- // 获取特定键的所有监听器
49
- const keyListeners = this._listeners.get(key);
50
- if (keyListeners) {
51
- // 遍历并执行每个监听器的回调函数
52
- keyListeners.forEach((callback) => callback(newValue, oldValue));
53
- }
54
- }
55
- /** @description 判断数据变化并通知监听器 */
56
- _update() {
57
- // 遍历当前数据对象的每个键,检查是否有变化
58
- for (const key in this._store) {
59
- const typedKey = key;
60
- const newValue = this._store[typedKey];
61
- const oldValue = this._lastData[typedKey];
62
- //如果旧值与新值不相等,则通知监听器
63
- if (newValue !== oldValue) {
64
- this._notifyListeners(typedKey, newValue, oldValue);
65
- this._lastData[typedKey] = this._store[typedKey];
66
- }
67
- }
68
- }
69
- }
70
- class LibJsStore extends LibJsObserver {
71
- constructor() {
72
- super({
73
- name: "张三",
74
- age: 20,
75
- });
76
- }
77
- }
78
- const store = new LibJsStore();
79
- const offA = store.on("age", (newValue) => {
80
- console.log(`A收到年龄更新:`, newValue);
81
- });
82
- store.on("age", (newValue) => {
83
- console.log(`B收到年龄更新:`, newValue);
84
- });
85
- // 模拟更新数据
86
- setTimeout(() => {
87
- console.log("尝试更新年龄值为:25");
88
- store.setData({ age: 25 });
89
- setTimeout(() => {
90
- console.warn("注销A监听器");
91
- offA();
92
- setTimeout(() => {
93
- console.warn("尝试更新年龄值为:26");
94
- store.setData({ age: 26 });
95
- setTimeout(() => {
96
- console.log("尝试获取年龄值:", store.getData("age"));
97
- }, 1000);
98
- }, 1000);
99
- }, 1000);
100
- }, 1000);