lyb-js 1.6.6 → 1.6.7

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.
@@ -2,7 +2,7 @@
2
2
  * @description 用于监听浏览器窗口尺寸变化的类
3
3
  * @link 使用方法:https://www.npmjs.com/package/lyb-js#LibJsResizeWatcher-窗口监听
4
4
  */
5
- type Listener = (w: number, h: number) => void;
5
+ type Listener = (w: number, h: number, s: number) => void;
6
6
  /** @description 监听窗口变化,内部只注册一次resize事件,调用监听自身可取消监听 */
7
7
  export declare class LibJsResizeWatcher {
8
8
  /** 存储所有监听器及其是否需要立即执行的标志 */
@@ -9,7 +9,15 @@ export class LibJsResizeWatcher {
9
9
  this._handleResize = () => {
10
10
  const w = window.innerWidth;
11
11
  const h = window.innerHeight;
12
- this._listeners.forEach(({ cb }) => cb(w, h));
12
+ let s;
13
+ const orientation = w > h ? "h" : "v";
14
+ if (orientation === "h") {
15
+ s = Math.min(w / 1920, h / 1080);
16
+ }
17
+ else {
18
+ s = Math.min(w / 1080, h / 1920);
19
+ }
20
+ this._listeners.forEach(({ cb }) => cb(w, h, s));
13
21
  };
14
22
  this._mode = mode;
15
23
  if (mode === "h" || mode === "v")
@@ -24,18 +32,28 @@ export class LibJsResizeWatcher {
24
32
  * @returns 一个函数,用于移除该监听器
25
33
  */
26
34
  on(cb, immediate = true) {
35
+ const w = window.innerWidth;
36
+ const h = window.innerHeight;
37
+ const orientation = w > h ? "h" : "v";
27
38
  if (this._mode === "h") {
28
- immediate && cb(1920, 1080);
39
+ immediate && cb(1920, 1080, Math.min(w / 1920, h / 1080));
29
40
  return () => { };
30
41
  }
31
42
  else if (this._mode === "v") {
32
- immediate && cb(1080, 1920);
43
+ immediate && cb(1080, 1920, Math.min(w / 1080, h / 1920));
33
44
  return () => { };
34
45
  }
46
+ let s;
47
+ if (orientation === "h") {
48
+ s = Math.min(w / 1920, h / 1080);
49
+ }
50
+ else {
51
+ s = Math.min(w / 1080, h / 1920);
52
+ }
35
53
  const item = { cb, immediate };
36
54
  this._listeners.push(item);
37
55
  if (immediate)
38
- cb(window.innerWidth, window.innerHeight);
56
+ cb(window.innerWidth, window.innerHeight, s);
39
57
  return () => {
40
58
  this._listeners = this._listeners.filter((l) => l !== item);
41
59
  };
package/lyb.js CHANGED
@@ -3529,7 +3529,14 @@ ${log3.label}:`, log3.value];
3529
3529
  this._handleResize = () => {
3530
3530
  const w = window.innerWidth;
3531
3531
  const h = window.innerHeight;
3532
- this._listeners.forEach(({ cb }) => cb(w, h));
3532
+ let s;
3533
+ const orientation = w > h ? "h" : "v";
3534
+ if (orientation === "h") {
3535
+ s = Math.min(w / 1920, h / 1080);
3536
+ } else {
3537
+ s = Math.min(w / 1080, h / 1920);
3538
+ }
3539
+ this._listeners.forEach(({ cb }) => cb(w, h, s));
3533
3540
  };
3534
3541
  this._mode = mode;
3535
3542
  if (mode === "h" || mode === "v")
@@ -3543,19 +3550,28 @@ ${log3.label}:`, log3.value];
3543
3550
  * @returns 一个函数,用于移除该监听器
3544
3551
  */
3545
3552
  on(cb, immediate = true) {
3553
+ const w = window.innerWidth;
3554
+ const h = window.innerHeight;
3555
+ const orientation = w > h ? "h" : "v";
3546
3556
  if (this._mode === "h") {
3547
- immediate && cb(1920, 1080);
3557
+ immediate && cb(1920, 1080, Math.min(w / 1920, h / 1080));
3548
3558
  return () => {
3549
3559
  };
3550
3560
  } else if (this._mode === "v") {
3551
- immediate && cb(1080, 1920);
3561
+ immediate && cb(1080, 1920, Math.min(w / 1080, h / 1920));
3552
3562
  return () => {
3553
3563
  };
3554
3564
  }
3565
+ let s;
3566
+ if (orientation === "h") {
3567
+ s = Math.min(w / 1920, h / 1080);
3568
+ } else {
3569
+ s = Math.min(w / 1080, h / 1920);
3570
+ }
3555
3571
  const item = { cb, immediate };
3556
3572
  this._listeners.push(item);
3557
3573
  if (immediate)
3558
- cb(window.innerWidth, window.innerHeight);
3574
+ cb(window.innerWidth, window.innerHeight, s);
3559
3575
  return () => {
3560
3576
  this._listeners = this._listeners.filter((l) => l !== item);
3561
3577
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lyb-js",
3
- "version": "1.6.6",
3
+ "version": "1.6.7",
4
4
  "description": "自用JS方法库",
5
5
  "license": "ISC",
6
6
  "type": "module",