lyb-pixi-js 1.12.39 → 1.12.40

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.
Files changed (129) hide show
  1. package/package.json +1 -1
  2. package/Components/Base/LibPixiArc.d.ts +0 -16
  3. package/Components/Base/LibPixiArc.js +0 -14
  4. package/Components/Base/LibPixiBitText.d.ts +0 -20
  5. package/Components/Base/LibPixiBitText.js +0 -26
  6. package/Components/Base/LibPixiCircular.d.ts +0 -7
  7. package/Components/Base/LibPixiCircular.js +0 -12
  8. package/Components/Base/LibPixiContainer.d.ts +0 -22
  9. package/Components/Base/LibPixiContainer.js +0 -51
  10. package/Components/Base/LibPixiHtmlText.d.ts +0 -31
  11. package/Components/Base/LibPixiHtmlText.js +0 -30
  12. package/Components/Base/LibPixiOval.d.ts +0 -5
  13. package/Components/Base/LibPixiOval.js +0 -10
  14. package/Components/Base/LibPixiParticleMove.d.ts +0 -101
  15. package/Components/Base/LibPixiParticleMove.js +0 -136
  16. package/Components/Base/LibPixiPolygon.d.ts +0 -7
  17. package/Components/Base/LibPixiPolygon.js +0 -15
  18. package/Components/Base/LibPixiRectBgColor.d.ts +0 -41
  19. package/Components/Base/LibPixiRectBgColor.js +0 -95
  20. package/Components/Base/LibPixiRectangle.d.ts +0 -7
  21. package/Components/Base/LibPixiRectangle.js +0 -15
  22. package/Components/Base/LibPixiRound.d.ts +0 -5
  23. package/Components/Base/LibPixiRound.js +0 -9
  24. package/Components/Base/LibPixiRoundedRect.d.ts +0 -5
  25. package/Components/Base/LibPixiRoundedRect.js +0 -10
  26. package/Components/Base/LibPixiSpine.d.ts +0 -58
  27. package/Components/Base/LibPixiSpine.js +0 -128
  28. package/Components/Base/LibPixiText.d.ts +0 -37
  29. package/Components/Base/LibPixiText.js +0 -35
  30. package/Components/Custom/LibPixiAreaClick.d.ts +0 -6
  31. package/Components/Custom/LibPixiAreaClick.js +0 -16
  32. package/Components/Custom/LibPixiArrangeLinearV2.d.ts +0 -25
  33. package/Components/Custom/LibPixiArrangeLinearV2.js +0 -80
  34. package/Components/Custom/LibPixiButtonHover.d.ts +0 -40
  35. package/Components/Custom/LibPixiButtonHover.js +0 -53
  36. package/Components/Custom/LibPixiCapsule.d.ts +0 -5
  37. package/Components/Custom/LibPixiCapsule.js +0 -10
  38. package/Components/Custom/LibPixiCloseBtn.d.ts +0 -14
  39. package/Components/Custom/LibPixiCloseBtn.js +0 -36
  40. package/Components/Custom/LibPixiDragLocate.d.ts +0 -36
  41. package/Components/Custom/LibPixiDragLocate.js +0 -230
  42. package/Components/Custom/LibPixiDrawer.d.ts +0 -16
  43. package/Components/Custom/LibPixiDrawer.js +0 -59
  44. package/Components/Custom/LibPixiGridLayoutV2.d.ts +0 -27
  45. package/Components/Custom/LibPixiGridLayoutV2.js +0 -37
  46. package/Components/Custom/LibPixiHeadingParagraphLayout.d.ts +0 -18
  47. package/Components/Custom/LibPixiHeadingParagraphLayout.js +0 -27
  48. package/Components/Custom/LibPixiInput.d.ts +0 -77
  49. package/Components/Custom/LibPixiInput.js +0 -198
  50. package/Components/Custom/LibPixiLabelValue.d.ts +0 -30
  51. package/Components/Custom/LibPixiLabelValue.js +0 -26
  52. package/Components/Custom/LibPixiPerforMon.d.ts +0 -47
  53. package/Components/Custom/LibPixiPerforMon.js +0 -166
  54. package/Components/Custom/LibPixiProgress.d.ts +0 -33
  55. package/Components/Custom/LibPixiProgress.js +0 -47
  56. package/Components/Custom/LibPixiPuzzleBg.d.ts +0 -7
  57. package/Components/Custom/LibPixiPuzzleBg.js +0 -46
  58. package/Components/Custom/LibPixiScrollContainerX.d.ts +0 -71
  59. package/Components/Custom/LibPixiScrollContainerX.js +0 -198
  60. package/Components/Custom/LibPixiScrollContainerY.d.ts +0 -109
  61. package/Components/Custom/LibPixiScrollContainerY.js +0 -340
  62. package/Components/Custom/LibPixiScrollNum.d.ts +0 -67
  63. package/Components/Custom/LibPixiScrollNum.js +0 -184
  64. package/Components/Custom/LibPixiSlide.d.ts +0 -94
  65. package/Components/Custom/LibPixiSlide.js +0 -285
  66. package/Components/Custom/LibPixiSlider.d.ts +0 -82
  67. package/Components/Custom/LibPixiSlider.js +0 -165
  68. package/Components/Custom/LibPixiTable.d.ts +0 -64
  69. package/Components/Custom/LibPixiTable.js +0 -76
  70. package/Components/Custom/LibPixiTextGroupWrap.d.ts +0 -20
  71. package/Components/Custom/LibPixiTextGroupWrap.js +0 -50
  72. package/Components/Custom/LibPixiTriangle.d.ts +0 -5
  73. package/Components/Custom/LibPixiTriangle.js +0 -12
  74. package/Components/Custom/LibPixiTurntable.d.ts +0 -6
  75. package/Components/Custom/LibPixiTurntable.js +0 -14
  76. package/Utils/LibContainerCenter.d.ts +0 -3
  77. package/Utils/LibContainerCenter.js +0 -10
  78. package/Utils/LibControlledDelayedCall.d.ts +0 -5
  79. package/Utils/LibControlledDelayedCall.js +0 -20
  80. package/Utils/LibPixiArrangeLinear.d.ts +0 -16
  81. package/Utils/LibPixiArrangeLinear.js +0 -62
  82. package/Utils/LibPixiAudio.d.ts +0 -53
  83. package/Utils/LibPixiAudio.js +0 -168
  84. package/Utils/LibPixiCreateNineGrid.d.ts +0 -15
  85. package/Utils/LibPixiCreateNineGrid.js +0 -19
  86. package/Utils/LibPixiDialogManager/index.d.ts +0 -25
  87. package/Utils/LibPixiDialogManager/index.js +0 -43
  88. package/Utils/LibPixiDialogManager/ui/LibPixiBaseContainer.d.ts +0 -11
  89. package/Utils/LibPixiDialogManager/ui/LibPixiBaseContainer.js +0 -31
  90. package/Utils/LibPixiDialogManager/ui/LibPixiDialog.d.ts +0 -40
  91. package/Utils/LibPixiDialogManager/ui/LibPixiDialog.js +0 -143
  92. package/Utils/LibPixiDigitalIncreasingAnimation.d.ts +0 -18
  93. package/Utils/LibPixiDigitalIncreasingAnimation.js +0 -26
  94. package/Utils/LibPixiDownScaleAnimation.d.ts +0 -7
  95. package/Utils/LibPixiDownScaleAnimation.js +0 -33
  96. package/Utils/LibPixiEmitContainerEvent.d.ts +0 -7
  97. package/Utils/LibPixiEmitContainerEvent.js +0 -13
  98. package/Utils/LibPixiEvent.d.ts +0 -19
  99. package/Utils/LibPixiEvent.js +0 -68
  100. package/Utils/LibPixiFilter.d.ts +0 -9
  101. package/Utils/LibPixiFilter.js +0 -34
  102. package/Utils/LibPixiGlobalUpdater.d.ts +0 -15
  103. package/Utils/LibPixiGlobalUpdater.js +0 -21
  104. package/Utils/LibPixiGridLayout.d.ts +0 -10
  105. package/Utils/LibPixiGridLayout.js +0 -27
  106. package/Utils/LibPixiHVCenter.d.ts +0 -7
  107. package/Utils/LibPixiHVCenter.js +0 -14
  108. package/Utils/LibPixiHVGap.d.ts +0 -8
  109. package/Utils/LibPixiHVGap.js +0 -26
  110. package/Utils/LibPixiIntervalTrigger.d.ts +0 -7
  111. package/Utils/LibPixiIntervalTrigger.js +0 -35
  112. package/Utils/LibPixiOutsideClick.d.ts +0 -8
  113. package/Utils/LibPixiOutsideClick.js +0 -22
  114. package/Utils/LibPixiOverflowHidden.d.ts +0 -6
  115. package/Utils/LibPixiOverflowHidden.js +0 -14
  116. package/Utils/LibPixiPolygonDrawTool.d.ts +0 -44
  117. package/Utils/LibPixiPolygonDrawTool.js +0 -114
  118. package/Utils/LibPixiPromiseTickerTimeout.d.ts +0 -6
  119. package/Utils/LibPixiPromiseTickerTimeout.js +0 -22
  120. package/Utils/LibPixiScaleContainer.d.ts +0 -8
  121. package/Utils/LibPixiScaleContainer.js +0 -14
  122. package/Utils/LibPixiShadow.d.ts +0 -17
  123. package/Utils/LibPixiShadow.js +0 -18
  124. package/Utils/LibPixiSlideInput.d.ts +0 -55
  125. package/Utils/LibPixiSlideInput.js +0 -61
  126. package/Utils/LibPixiTicker.d.ts +0 -14
  127. package/Utils/LibPixiTicker.js +0 -49
  128. package/Utils/LibPixiTickerTimeout.d.ts +0 -6
  129. package/Utils/LibPixiTickerTimeout.js +0 -22
@@ -1,198 +0,0 @@
1
- import { Container, Sprite, } from "pixi.js";
2
- import { gsap } from "gsap";
3
- import { libPixiEvent } from "../../Utils/LibPixiEvent";
4
- import { LibPixiContainer } from "../Base/LibPixiContainer";
5
- import { LibPixiRectangle } from "../Base/LibPixiRectangle";
6
- /** @description 支持鼠标滚轮滚动、鼠标拖动、手指滑动,支持惯性滚动及回弹 */
7
- export class LibPixiScrollContainerX extends LibPixiContainer {
8
- constructor(params) {
9
- const { width, height, scrollContent, bgColor, maskTexture, maskX = 0, maskY = 0, } = params;
10
- super(width, height, bgColor);
11
- /** 开始位置 */
12
- this._startX = 0;
13
- /** 惯性速度 */
14
- this._velocity = 0;
15
- /** 上一次滚动时间 */
16
- this._startTime = 0;
17
- /** 开始位置 */
18
- this._startContentX = 0;
19
- /** 滚动速度 */
20
- this._scrollSpeed = 200;
21
- /** 是否处于拖动状态 */
22
- this._isDragging = false;
23
- /** 左边距 */
24
- this._leftMargin = 0;
25
- this._scrollContent = scrollContent;
26
- // 创建内容容器
27
- this._content = new Container();
28
- this.addChild(this._content);
29
- this._content.addChild(this._scrollContent);
30
- //自定义遮罩
31
- if (maskTexture) {
32
- this._maskGraphics = new Sprite(maskTexture);
33
- this.addChild(this._maskGraphics);
34
- this._maskGraphics.width = width;
35
- this._maskGraphics.height = height;
36
- this._maskGraphics.position.set(maskX, maskY);
37
- this.mask = this._maskGraphics;
38
- }
39
- else {
40
- this._maskGraphics = new LibPixiRectangle(width, height, "#000");
41
- this.addChild(this._maskGraphics);
42
- this.mask = this._maskGraphics;
43
- }
44
- // 添加事件监听
45
- libPixiEvent(this, "pointerdown", (event) => {
46
- this._onDragStart(event);
47
- });
48
- libPixiEvent(LibPixiScrollContainerX.stage, "pointermove", (event) => {
49
- this._onDragMove(event);
50
- });
51
- libPixiEvent(this, "pointerup", () => {
52
- this._onDragEnd();
53
- });
54
- libPixiEvent(this, "wheel", (event) => {
55
- this._onWheelScroll(event);
56
- });
57
- libPixiEvent(this, "pointerupoutside", () => {
58
- this._onDragEnd();
59
- });
60
- }
61
- /** @description 添加边距 */
62
- addMargin(leftMargin, rightMargin = leftMargin) {
63
- this._leftMargin = leftMargin;
64
- if (leftMargin) {
65
- const leftMarginBox = new Sprite();
66
- this._content.addChild(leftMarginBox);
67
- leftMarginBox.width = leftMargin;
68
- this._scrollContent.x += leftMargin;
69
- }
70
- if (rightMargin) {
71
- this._rightMarginBox = new Sprite();
72
- this._content.addChild(this._rightMarginBox);
73
- this._rightMarginBox.height = rightMargin;
74
- this._rightMarginBox.x = leftMargin + this._scrollContent.width;
75
- }
76
- }
77
- /** @description 设置滚动容器可视区宽高
78
- * @param width 宽度
79
- * @param height 高度
80
- */
81
- setDimensions(width, height) {
82
- this._maskGraphics.width = width;
83
- this._maskGraphics.height = height;
84
- this.setSize(width, height);
85
- this._updateRightMargin();
86
- }
87
- /** @description 返回顶部 */
88
- scrollToTop() {
89
- gsap.killTweensOf(this._content);
90
- this._content.x = 0;
91
- }
92
- /** @description 往滚动内容添加元素 */
93
- addContent(container) {
94
- this._scrollContent.addChild(container);
95
- }
96
- /** @description 更新右边距坐标 */
97
- _updateRightMargin() {
98
- if (!this._rightMarginBox)
99
- return;
100
- this._rightMarginBox.x = this._leftMargin + this._scrollContent.width;
101
- }
102
- /** @description 按下 */
103
- _onDragStart(event) {
104
- if (this._content.width <= this._maskGraphics.width)
105
- return;
106
- const { x } = event.getLocalPosition(this);
107
- this._startX = x - this._content.x;
108
- this._isDragging = true;
109
- this._velocity = 0;
110
- this._startTime = Date.now();
111
- this._startContentX = this._content.x;
112
- gsap.killTweensOf(this._content);
113
- }
114
- /** @description 拖动 */
115
- _onDragMove(event) {
116
- if (this._isDragging) {
117
- const { x } = event.getLocalPosition(this);
118
- const newPosition = x - this._startX;
119
- this._content.x = newPosition;
120
- }
121
- }
122
- /** @description 拖动结束 */
123
- _onDragEnd() {
124
- this._isDragging = false;
125
- const currentTime = Date.now();
126
- const deltaTime = currentTime - this._startTime; // 计算停留时间
127
- if (deltaTime < 250) {
128
- // 如果停留时间在阈值内,计算惯性速度
129
- this._velocity = (this._content.x - this._startContentX) / deltaTime;
130
- this._applyInertia();
131
- }
132
- else {
133
- // 停留时间超出阈值,取消惯性
134
- this._velocity = 0;
135
- }
136
- this._limitScrollRange();
137
- }
138
- /** @description 滚轮滚动 */
139
- _onWheelScroll(event) {
140
- // 如果内容高度小于遮罩高度,则不滚动
141
- if (this._content.width <= this._maskGraphics.width)
142
- return;
143
- let x = this._content.x - event.deltaY * (this._scrollSpeed / 100);
144
- if (x > 0) {
145
- x = 0;
146
- }
147
- else if (Math.abs(x) >= this._content.width - this._maskGraphics.width) {
148
- x = -(this._content.width - this._maskGraphics.width);
149
- }
150
- gsap.to(this._content, {
151
- duration: 0.25,
152
- ease: "power1.out",
153
- x,
154
- });
155
- }
156
- /** @description 惯性动画 */
157
- _applyInertia() {
158
- gsap.to(this._content, {
159
- x: this._content.x + this._velocity * 250,
160
- duration: 0.5,
161
- ease: "power1.out",
162
- onUpdate: this._limitScrollRange.bind(this),
163
- });
164
- }
165
- /** @description 限制滚动范围 */
166
- _limitScrollRange() {
167
- //如果内容顶部离开了滚动容器顶部,则归位
168
- if (this._content.x > 0) {
169
- //回弹
170
- gsap.to(this._content, {
171
- duration: 0.2,
172
- ease: "power1.out",
173
- x: 0,
174
- });
175
- }
176
- // 如果滚动距离大于内容高度减去遮罩高度
177
- else if (Math.abs(this._content.x) >=
178
- this._content.width - this._maskGraphics.width) {
179
- // 如果内容高度大于遮罩高度,则滚动到底部
180
- if (this._content.width > this._maskGraphics.width) {
181
- //回弹
182
- const x = -(this._content.width - this._maskGraphics.width);
183
- gsap.to(this._content, {
184
- duration: 0.2,
185
- ease: "power1.out",
186
- x,
187
- });
188
- }
189
- // 否则静止不动
190
- else {
191
- gsap.to(this._content, {
192
- duration: 0.25,
193
- x: 0,
194
- });
195
- }
196
- }
197
- }
198
- }
@@ -1,109 +0,0 @@
1
- import { Container, Texture } from "pixi.js";
2
- import { LibPixiContainer } from "../Base/LibPixiContainer";
3
- export interface LibPixiScrollContainerYParams {
4
- /** 宽度 */
5
- width: number;
6
- /** 高度 */
7
- height: number;
8
- /** 滚动内容 */
9
- scrollContent: Container;
10
- /** 背景色,用于定位 */
11
- bgColor?: string;
12
- /** 自定义遮罩贴图 */
13
- maskTexture?: Texture;
14
- /** 遮罩X坐标 */
15
- maskX?: number;
16
- /** 遮罩Y坐标 */
17
- maskY?: number;
18
- /** 是否需要滚动条 */
19
- scrollbar?: boolean;
20
- /** 滚动靠右坐标 */
21
- scrollbarRgiht?: number;
22
- /** 滚动条宽度 */
23
- scrollbarWidth?: number;
24
- /** 滚动条颜色 */
25
- scrollbarColor?: string;
26
- /** 滚动触发 */
27
- onScroll?: (y: number) => void;
28
- }
29
- /** @description 支持鼠标滚轮滚动、鼠标拖动、手指滑动,支持惯性滚动及回弹 */
30
- export declare class LibPixiScrollContainerY extends LibPixiContainer {
31
- /** 舞台 */
32
- static stage: Container;
33
- /** 开始位置 */
34
- private _startY;
35
- /** 惯性速度 */
36
- private _velocity;
37
- /** 上一次滚动时间 */
38
- private _startTime;
39
- /** 开始位置 */
40
- private _startContentY;
41
- /** 滚动速度 */
42
- private _scrollSpeed;
43
- /** 是否处于拖动状态 */
44
- private _isDragging;
45
- /** 是否处于滚动状态 */
46
- private _scrollbarDragging;
47
- /** 滚动条拖动偏移量 */
48
- private _scrollbarDragOffset;
49
- /** 滚动条右边距 */
50
- private _scrollbarRgiht;
51
- /** 滚动条宽度 */
52
- private _scrollbarWidth;
53
- /** 上边距 */
54
- private _topMargin;
55
- /** 右边距元素 */
56
- private _bottomMarginBox?;
57
- /** 滚动容器 */
58
- _scrollContent: Container;
59
- /** 遮罩 */
60
- private _maskGraphics;
61
- /** 滚动的内容 */
62
- private _content;
63
- /** 滚动条 */
64
- private _scrollbar;
65
- /** 滚动条颜色 */
66
- private _scrollbarColor;
67
- /** 是否显示滚动条 */
68
- private _showScrollbar;
69
- /** 滚动触发 */
70
- private _onScroll?;
71
- constructor(params: LibPixiScrollContainerYParams);
72
- /** @description 添加边距 */
73
- addMargin(topMargin: number, bottomMargin?: number): void;
74
- /** @description 设置滚动容器可视区宽高
75
- * @param width 宽度
76
- * @param height 高度
77
- */
78
- setDimensions(width: number, height: number): void;
79
- /** @description 返回顶部 */
80
- scrollToTop(): void;
81
- /** @description 往滚动内容添加元素 */
82
- addContent(container: Container): void;
83
- /** @description 更新右边距坐标 */
84
- private _updateBottomMargin;
85
- /** @description 按下 */
86
- private _onDragStart;
87
- /** @description 拖动 */
88
- private _onDragMove;
89
- /** @description 拖动结束 */
90
- private _onDragEnd;
91
- /** @description 滚轮滚动 */
92
- private _onWheelScroll;
93
- /** @description 惯性动画 */
94
- private _applyInertia;
95
- /** @description 限制滚动范围 */
96
- private _limitScrollRange;
97
- /** @description 更新滚动位置 */
98
- private _updateScrollbar;
99
- /** @description 更新滚动条大小 */
100
- private _updateScrollbarSize;
101
- /** @description 滚动条按下 */
102
- private _onScrollbarDragStart;
103
- /** @description 滚动条移动 */
104
- private _onScrollbarDragMove;
105
- /** @description 滚动条松开 */
106
- private _onScrollbarDragEnd;
107
- /** @description 滚动结束一秒后隐藏滚动条 */
108
- private _hideScrollbar;
109
- }
@@ -1,340 +0,0 @@
1
- import { Container, Sprite } from "pixi.js";
2
- import { gsap } from "gsap";
3
- import { libPixiEvent } from "../../Utils/LibPixiEvent";
4
- import { LibPixiContainer } from "../Base/LibPixiContainer";
5
- import { LibPixiRectangle } from "../Base/LibPixiRectangle";
6
- /** @description 支持鼠标滚轮滚动、鼠标拖动、手指滑动,支持惯性滚动及回弹 */
7
- export class LibPixiScrollContainerY extends LibPixiContainer {
8
- constructor(params) {
9
- const { width, height, scrollbar = false, scrollContent, scrollbarRgiht = 0, scrollbarWidth = 10, scrollbarColor = "#ffffff", onScroll, bgColor, maskTexture, maskX = 0, maskY = 0, } = params;
10
- super(width, height, bgColor);
11
- /** 开始位置 */
12
- this._startY = 0;
13
- /** 惯性速度 */
14
- this._velocity = 0;
15
- /** 上一次滚动时间 */
16
- this._startTime = 0;
17
- /** 开始位置 */
18
- this._startContentY = 0;
19
- /** 滚动速度 */
20
- this._scrollSpeed = 200;
21
- /** 是否处于拖动状态 */
22
- this._isDragging = false;
23
- /** 是否处于滚动状态 */
24
- this._scrollbarDragging = false;
25
- /** 滚动条拖动偏移量 */
26
- this._scrollbarDragOffset = 0;
27
- /** 上边距 */
28
- this._topMargin = 0;
29
- this._scrollbarRgiht = scrollbarRgiht;
30
- this._scrollbarWidth = scrollbarWidth;
31
- this._scrollContent = scrollContent;
32
- this._scrollbarColor = scrollbarColor;
33
- this._onScroll = onScroll;
34
- this._showScrollbar = scrollbar;
35
- // 创建内容容器
36
- this._content = new Container();
37
- this.addChild(this._content);
38
- this._content.addChild(this._scrollContent);
39
- //自定义遮罩
40
- if (maskTexture) {
41
- this._maskGraphics = new Sprite(maskTexture);
42
- this.addChild(this._maskGraphics);
43
- this._maskGraphics.width = width;
44
- this._maskGraphics.height = height;
45
- this._maskGraphics.position.set(maskX, maskY);
46
- this.mask = this._maskGraphics;
47
- }
48
- else {
49
- this._maskGraphics = new LibPixiRectangle(width, height, "#000");
50
- this.addChild(this._maskGraphics);
51
- this.mask = this._maskGraphics;
52
- }
53
- // 创建滚动条
54
- this._scrollbar = new LibPixiRectangle(scrollbarWidth, height, this._scrollbarColor);
55
- this._scrollbar.x = width - (scrollbarRgiht || scrollbarWidth);
56
- this.addChild(this._scrollbar);
57
- this._scrollbar.visible = this._showScrollbar;
58
- this._scrollbar.alpha = 0;
59
- this._updateScrollbarSize();
60
- //是否已经离开滚动条
61
- libPixiEvent(this._scrollbar, "pointerdown", this._onScrollbarDragStart.bind(this));
62
- libPixiEvent(this._scrollbar, "pointerenter", () => {
63
- gsap.killTweensOf(this._scrollbar);
64
- this._scrollbar.alpha = 1;
65
- this._updateScrollbarSize();
66
- });
67
- libPixiEvent(this._scrollbar, "pointerleave", () => {
68
- gsap.to(this._scrollbar, {
69
- duration: 0.5,
70
- alpha: 0,
71
- delay: 1,
72
- });
73
- });
74
- // 添加事件监听
75
- libPixiEvent(this, "pointerdown", (event) => {
76
- this._onDragStart(event);
77
- this._updateScrollbarSize();
78
- });
79
- libPixiEvent(LibPixiScrollContainerY.stage, "pointermove", (event) => {
80
- this._onScrollbarDragMove(event);
81
- this._onDragMove(event);
82
- });
83
- libPixiEvent(this, "pointerup", (event) => {
84
- this._onScrollbarDragEnd(event);
85
- this._onDragEnd();
86
- });
87
- libPixiEvent(this, "wheel", (event) => {
88
- this._onWheelScroll(event);
89
- this._updateScrollbarSize();
90
- });
91
- libPixiEvent(this, "pointerupoutside", () => {
92
- this._onDragEnd();
93
- });
94
- }
95
- /** @description 添加边距 */
96
- addMargin(topMargin, bottomMargin = topMargin) {
97
- this._topMargin = topMargin;
98
- if (topMargin) {
99
- const topMarginBox = new Sprite();
100
- this._content.addChild(topMarginBox);
101
- topMarginBox.height = topMargin;
102
- this._scrollContent.y += topMargin;
103
- }
104
- if (bottomMargin) {
105
- this._bottomMarginBox = new Sprite();
106
- this._content.addChild(this._bottomMarginBox);
107
- this._bottomMarginBox.height = bottomMargin;
108
- this._bottomMarginBox.y = topMargin + this._scrollContent.height;
109
- }
110
- }
111
- /** @description 设置滚动容器可视区宽高
112
- * @param width 宽度
113
- * @param height 高度
114
- */
115
- setDimensions(width, height) {
116
- this._maskGraphics.width = width;
117
- this._maskGraphics.height = height;
118
- this.setSize(width, height);
119
- this._scrollbar.x = width - (this._scrollbarRgiht || this._scrollbarWidth);
120
- this._updateBottomMargin();
121
- }
122
- /** @description 返回顶部 */
123
- scrollToTop() {
124
- gsap.killTweensOf(this._content);
125
- this._content.y = 0;
126
- }
127
- /** @description 往滚动内容添加元素 */
128
- addContent(container) {
129
- this._scrollContent.addChild(container);
130
- }
131
- /** @description 更新右边距坐标 */
132
- _updateBottomMargin() {
133
- if (!this._bottomMarginBox)
134
- return;
135
- this._bottomMarginBox.x = this._topMargin + this._scrollContent.width;
136
- }
137
- /** @description 按下 */
138
- _onDragStart(event) {
139
- if (this._content.height <= this._maskGraphics.height)
140
- return;
141
- const { y } = event.getLocalPosition(this);
142
- this._startY = y - this._content.y;
143
- this._isDragging = true;
144
- this._velocity = 0;
145
- this._startTime = Date.now();
146
- this._startContentY = this._content.y;
147
- gsap.killTweensOf(this._content);
148
- }
149
- /** @description 拖动 */
150
- _onDragMove(event) {
151
- if (this._isDragging) {
152
- const { y } = event.getLocalPosition(this);
153
- const newPosition = y - this._startY;
154
- this._content.y = newPosition;
155
- this._updateScrollbar();
156
- }
157
- }
158
- /** @description 拖动结束 */
159
- _onDragEnd() {
160
- this._isDragging = false;
161
- this._scrollbarDragging = false;
162
- const currentTime = Date.now();
163
- const deltaTime = currentTime - this._startTime; // 计算停留时间
164
- if (deltaTime < 250) {
165
- // 如果停留时间在阈值内,计算惯性速度
166
- this._velocity = (this._content.y - this._startContentY) / deltaTime;
167
- this._applyInertia();
168
- }
169
- else {
170
- // 停留时间超出阈值,取消惯性
171
- this._velocity = 0;
172
- }
173
- this._limitScrollRange();
174
- gsap.to(this._scrollbar, {
175
- duration: 0.5,
176
- alpha: 0,
177
- delay: 0.25,
178
- });
179
- }
180
- /** @description 滚轮滚动 */
181
- _onWheelScroll(event) {
182
- // 如果内容高度小于遮罩高度,则不滚动
183
- if (this._content.height <= this._maskGraphics.height)
184
- return;
185
- let y = this._content.y - event.deltaY * (this._scrollSpeed / 100);
186
- //如果到达顶部,则不滚动
187
- if (y > 0) {
188
- y = 0;
189
- }
190
- //如果到达底部,则不滚动
191
- else if (Math.abs(y) >= this._content.height - this._maskGraphics.height) {
192
- y = -(this._content.height - this._maskGraphics.height);
193
- }
194
- gsap.to(this._content, {
195
- duration: 0.25,
196
- ease: "power1.out",
197
- y,
198
- onUpdate: () => {
199
- this._updateScrollbar();
200
- },
201
- onComplete: () => {
202
- this._hideScrollbar();
203
- },
204
- });
205
- }
206
- /** @description 惯性动画 */
207
- _applyInertia() {
208
- gsap.to(this._content, {
209
- y: this._content.y + this._velocity * 250,
210
- duration: 0.5,
211
- ease: "power1.out",
212
- onUpdate: () => {
213
- this._limitScrollRange();
214
- this._updateScrollbar();
215
- },
216
- onComplete: () => {
217
- this._hideScrollbar();
218
- },
219
- });
220
- }
221
- /** @description 限制滚动范围 */
222
- _limitScrollRange() {
223
- //如果内容顶部离开了滚动容器顶部,则归位
224
- if (this._content.y > 0) {
225
- gsap.to(this._content, {
226
- duration: 0.2,
227
- y: 0,
228
- ease: "power1.out",
229
- onUpdate: () => {
230
- this._updateScrollbar();
231
- },
232
- onComplete: () => {
233
- this._hideScrollbar();
234
- },
235
- });
236
- }
237
- // 如果滚动距离大于内容高度减去遮罩高度
238
- else if (Math.abs(this._content.y) >=
239
- this._content.height - this._maskGraphics.height) {
240
- // 如果内容高度大于遮罩高度,则滚动到底部
241
- if (this._content.height > this._maskGraphics.height) {
242
- const y = -(this._content.height - this._maskGraphics.height);
243
- gsap.to(this._content, {
244
- duration: 0.2,
245
- y,
246
- ease: "power1.out",
247
- onUpdate: () => {
248
- this._updateScrollbar();
249
- },
250
- onComplete: () => {
251
- this._hideScrollbar();
252
- },
253
- });
254
- }
255
- // 否则静止不动
256
- else {
257
- gsap.to(this._content, {
258
- duration: 0.25,
259
- y: 0,
260
- onUpdate: () => {
261
- this._updateScrollbar();
262
- },
263
- onComplete: () => {
264
- this._hideScrollbar();
265
- },
266
- });
267
- }
268
- }
269
- }
270
- /** @description 更新滚动位置 */
271
- _updateScrollbar() {
272
- var _a;
273
- this._scrollbar.alpha = 1;
274
- gsap.killTweensOf(this._scrollbar);
275
- const viewHeight = this._maskGraphics.height;
276
- const contentHeight = this._content.height;
277
- const ratio = viewHeight / contentHeight;
278
- const barHeight = viewHeight * ratio;
279
- const maxScrollY = contentHeight - viewHeight;
280
- const scrollY = Math.min(Math.max(-this._content.y, 0), maxScrollY);
281
- const barY = (scrollY / maxScrollY) * (viewHeight - barHeight);
282
- this._scrollbar.y = barY;
283
- (_a = this._onScroll) === null || _a === void 0 ? void 0 : _a.call(this, this._content.y);
284
- }
285
- /** @description 更新滚动条大小 */
286
- _updateScrollbarSize() {
287
- if (!this._showScrollbar)
288
- return;
289
- const viewHeight = this._maskGraphics.height;
290
- const contentHeight = this._content.height;
291
- if (contentHeight <= viewHeight) {
292
- this._scrollbar.visible = false;
293
- }
294
- else {
295
- this._scrollbar.visible = true;
296
- }
297
- const ratio = viewHeight / contentHeight;
298
- const barHeight = viewHeight * ratio;
299
- this._scrollbar.clear();
300
- this._scrollbar.beginFill(this._scrollbarColor);
301
- this._scrollbar.drawRect(0, 0, 10, barHeight);
302
- this._scrollbar.endFill();
303
- }
304
- /** @description 滚动条按下 */
305
- _onScrollbarDragStart(event) {
306
- event.stopPropagation();
307
- this._scrollbarDragging = true;
308
- this._scrollbarDragOffset = event.getLocalPosition(this._scrollbar).y;
309
- gsap.killTweensOf(this._content);
310
- }
311
- /** @description 滚动条移动 */
312
- _onScrollbarDragMove(event) {
313
- event.stopPropagation();
314
- if (!this._scrollbarDragging)
315
- return;
316
- const localY = event.getLocalPosition(this).y;
317
- const viewHeight = this._maskGraphics.height;
318
- const contentHeight = this._content.height;
319
- const ratio = viewHeight / contentHeight;
320
- const barHeight = viewHeight * ratio;
321
- const maxBarY = viewHeight - barHeight;
322
- const newBarY = Math.min(Math.max(localY - this._scrollbarDragOffset, 0), maxBarY);
323
- const scrollY = (newBarY / maxBarY) * (contentHeight - viewHeight);
324
- this._content.y = -scrollY;
325
- this._updateScrollbar();
326
- }
327
- /** @description 滚动条松开 */
328
- _onScrollbarDragEnd(event) {
329
- event.stopPropagation();
330
- this._scrollbarDragging = false;
331
- }
332
- /** @description 滚动结束一秒后隐藏滚动条 */
333
- _hideScrollbar() {
334
- gsap.to(this._scrollbar, {
335
- duration: 0.5,
336
- alpha: 0,
337
- delay: 0.25,
338
- });
339
- }
340
- }