lyb-pixi-js 1.12.35 → 1.12.37

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.
@@ -3,10 +3,10 @@ import { LibPixiBaseContainer } from "./LibPixiBaseContainer";
3
3
  interface Params {
4
4
  /** 是否需要显示黑色背景 */
5
5
  needBg?: boolean;
6
- /** 竖版初始大小 */
7
- size?: number;
8
6
  /** 点击蒙版回调 */
9
7
  onClickMask?: () => void;
8
+ /** 竖版缩放大小 */
9
+ vScale?: number;
10
10
  }
11
11
  /** @description 弹窗组件 */
12
12
  export declare class LibPixiDialog extends LibPixiBaseContainer {
@@ -21,18 +21,20 @@ export declare class LibPixiDialog extends LibPixiBaseContainer {
21
21
  private _maskUI;
22
22
  /** 内容容器 */
23
23
  private _dialogContainer;
24
- /** 当前大小 */
25
- private _size;
26
- /** 竖版初始大小 */
27
- private _initialSize;
24
+ /** 竖版缩放大小 */
25
+ private _vScale;
26
+ /** 上一次是否为横版 */
27
+ private _lastIsH?;
28
28
  /** 停止监听窗口 */
29
29
  private _offResize?;
30
30
  constructor(params?: Params);
31
31
  /** @description 设置弹窗内容 */
32
32
  setDialogContent(content: Container): void;
33
- /** @description 重绘弹窗 */
34
- redraw(w: number, h: number): void;
33
+ /** @description 设置弹窗容器锚点 */
34
+ updatePivot(): void;
35
35
  /** @description 关闭 */
36
36
  close(): Promise<void>;
37
+ /** @description 重绘弹窗 */
38
+ private _redraw;
37
39
  }
38
40
  export {};
@@ -17,10 +17,10 @@ import { LibPixiBaseContainer } from "./LibPixiBaseContainer";
17
17
  export class LibPixiDialog extends LibPixiBaseContainer {
18
18
  constructor(params) {
19
19
  super();
20
- /** 当前大小 */
21
- this._size = 1;
22
- const { size = 1, onClickMask, needBg = true } = params || {};
23
- this._initialSize = size;
20
+ /** 竖版缩放大小 */
21
+ this._vScale = 1;
22
+ const { onClickMask, vScale = 1, needBg = true } = params || {};
23
+ this._vScale = vScale;
24
24
  //蒙版
25
25
  this._maskUI = new LibPixiRectangle(2700, 1080, "#000");
26
26
  this.addChild(this._maskUI);
@@ -41,64 +41,38 @@ export class LibPixiDialog extends LibPixiBaseContainer {
41
41
  this.addChild(this._dialogContainer);
42
42
  this._dialogContainer.eventMode = "static";
43
43
  const resize = new LibJsResizeWatcher(LibPixiDialog.adaptation);
44
- this._offResize = resize.on(this.redraw.bind(this));
44
+ this._offResize = resize.on(this._redraw.bind(this), false);
45
45
  }
46
46
  /** @description 设置弹窗内容 */
47
47
  setDialogContent(content) {
48
48
  this._dialogContainer.addChild(content);
49
- if (LibPixiDialog.adaptation === "h") {
50
- this.redraw(1920, 1080);
51
- }
52
- else if (LibPixiDialog.adaptation === "v") {
53
- this.redraw(1080, 1920);
54
- }
55
- else {
56
- this.redraw(window.innerWidth, window.innerHeight);
57
- }
58
- this._dialogContainer.scale.set(0);
59
49
  this._dialogContainer.alpha = 0;
60
- gsap.to(this._maskUI, {
61
- duration: LibPixiDialog.durationIn,
62
- alpha: LibPixiDialog.bgAlpha,
63
- });
64
- gsap.to(this._dialogContainer, {
65
- duration: LibPixiDialog.durationIn,
66
- alpha: 1,
50
+ requestAnimationFrame(() => {
51
+ this.updatePivot();
52
+ if (LibPixiDialog.adaptation === "h") {
53
+ this._redraw(1920, 1080);
54
+ }
55
+ else if (LibPixiDialog.adaptation === "v") {
56
+ this._redraw(1080, 1920);
57
+ }
58
+ else {
59
+ this._redraw(window.innerWidth, window.innerHeight);
60
+ }
61
+ gsap.to(this._maskUI, {
62
+ duration: LibPixiDialog.durationIn,
63
+ alpha: LibPixiDialog.bgAlpha,
64
+ });
65
+ gsap.to(this._dialogContainer, {
66
+ duration: LibPixiDialog.durationIn,
67
+ alpha: 1,
68
+ });
67
69
  });
68
70
  }
69
- /** @description 重绘弹窗 */
70
- redraw(w, h) {
71
+ /** @description 设置弹窗容器锚点 */
72
+ updatePivot() {
71
73
  const dialogW = this._dialogContainer.width / 2;
72
74
  const dialogH = this._dialogContainer.height / 2;
73
75
  this._dialogContainer.pivot.set(dialogW, dialogH);
74
- const halfW = 1920 / 2;
75
- const halfH = 1080 / 2;
76
- if (w > h) {
77
- this._maskUI.width = 2700;
78
- this._maskUI.height = 1080;
79
- this._maskUI.x = -(2700 - 1920) / 2;
80
- this._dialogContainer.position.set(halfW, halfH);
81
- this._size = 1;
82
- if (this._dialogContainer.scale.x === this._initialSize) {
83
- this._dialogContainer.scale.set(1);
84
- }
85
- }
86
- else {
87
- this._maskUI.width = 1080;
88
- this._maskUI.height = 2700;
89
- this._maskUI.x = 0;
90
- this._dialogContainer.position.set(halfH, halfW);
91
- this._size = this._initialSize;
92
- if (this._dialogContainer.scale.x === 1) {
93
- this._dialogContainer.scale.set(this._initialSize);
94
- }
95
- }
96
- gsap.to(this._dialogContainer.scale, {
97
- duration: LibPixiDialog.durationIn,
98
- ease: "back.out",
99
- x: this._size,
100
- y: this._size,
101
- });
102
76
  }
103
77
  /** @description 关闭 */
104
78
  close() {
@@ -124,6 +98,36 @@ export class LibPixiDialog extends LibPixiBaseContainer {
124
98
  });
125
99
  });
126
100
  }
101
+ /** @description 重绘弹窗 */
102
+ _redraw(w, h) {
103
+ if (this._lastIsH === w > h)
104
+ return;
105
+ this._lastIsH = w > h;
106
+ let scale = 0;
107
+ const halfW = 1920 / 2;
108
+ const halfH = 1080 / 2;
109
+ if (w > h) {
110
+ this._maskUI.width = 2700;
111
+ this._maskUI.height = 1080;
112
+ this._maskUI.x = -(2700 - 1920) / 2;
113
+ this._dialogContainer.position.set(halfW, halfH);
114
+ scale = 1;
115
+ }
116
+ else {
117
+ this._maskUI.width = 1080;
118
+ this._maskUI.height = 2700;
119
+ this._maskUI.x = 0;
120
+ this._dialogContainer.position.set(halfH, halfW);
121
+ scale = this._vScale;
122
+ }
123
+ this._dialogContainer.scale.set(0);
124
+ gsap.to(this._dialogContainer.scale, {
125
+ duration: LibPixiDialog.durationIn,
126
+ ease: "back.out",
127
+ x: scale,
128
+ y: scale,
129
+ });
130
+ }
127
131
  }
128
132
  /** 黑色背景透明度 */
129
133
  LibPixiDialog.bgAlpha = 0.5;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lyb-pixi-js",
3
- "version": "1.12.35",
3
+ "version": "1.12.37",
4
4
  "description": "自用Pixi.JS方法库",
5
5
  "license": "ISC",
6
6
  "exports": {