lyb-pixi-js 1.12.32 → 1.12.33

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 (137) hide show
  1. package/README.md +50 -85
  2. package/index.js +5 -2
  3. package/lyb-pixi.js +208 -196
  4. package/package.json +1 -1
  5. package/Components/Base/LibDestroyContainer.d.ts +0 -11
  6. package/Components/Base/LibDestroyContainer.js +0 -28
  7. package/Components/Base/LibPixiArc.d.ts +0 -16
  8. package/Components/Base/LibPixiArc.js +0 -14
  9. package/Components/Base/LibPixiBitText.d.ts +0 -20
  10. package/Components/Base/LibPixiBitText.js +0 -26
  11. package/Components/Base/LibPixiCircular.d.ts +0 -7
  12. package/Components/Base/LibPixiCircular.js +0 -12
  13. package/Components/Base/LibPixiContainer.d.ts +0 -22
  14. package/Components/Base/LibPixiContainer.js +0 -51
  15. package/Components/Base/LibPixiHtmlText.d.ts +0 -31
  16. package/Components/Base/LibPixiHtmlText.js +0 -30
  17. package/Components/Base/LibPixiOval.d.ts +0 -5
  18. package/Components/Base/LibPixiOval.js +0 -10
  19. package/Components/Base/LibPixiParticleMove.d.ts +0 -101
  20. package/Components/Base/LibPixiParticleMove.js +0 -136
  21. package/Components/Base/LibPixiPolygon.d.ts +0 -7
  22. package/Components/Base/LibPixiPolygon.js +0 -15
  23. package/Components/Base/LibPixiRectBgColor.d.ts +0 -41
  24. package/Components/Base/LibPixiRectBgColor.js +0 -95
  25. package/Components/Base/LibPixiRectangle.d.ts +0 -7
  26. package/Components/Base/LibPixiRectangle.js +0 -15
  27. package/Components/Base/LibPixiRound.d.ts +0 -5
  28. package/Components/Base/LibPixiRound.js +0 -9
  29. package/Components/Base/LibPixiRoundedRect.d.ts +0 -5
  30. package/Components/Base/LibPixiRoundedRect.js +0 -10
  31. package/Components/Base/LibPixiSpine.d.ts +0 -58
  32. package/Components/Base/LibPixiSpine.js +0 -128
  33. package/Components/Base/LibPixiText.d.ts +0 -37
  34. package/Components/Base/LibPixiText.js +0 -35
  35. package/Components/Custom/LibPixiArrangeLinearV2.d.ts +0 -25
  36. package/Components/Custom/LibPixiArrangeLinearV2.js +0 -80
  37. package/Components/Custom/LibPixiButtonHover.d.ts +0 -40
  38. package/Components/Custom/LibPixiButtonHover.js +0 -53
  39. package/Components/Custom/LibPixiCapsule.d.ts +0 -5
  40. package/Components/Custom/LibPixiCapsule.js +0 -10
  41. package/Components/Custom/LibPixiCloseBtn.d.ts +0 -14
  42. package/Components/Custom/LibPixiCloseBtn.js +0 -36
  43. package/Components/Custom/LibPixiDragLocate.d.ts +0 -36
  44. package/Components/Custom/LibPixiDragLocate.js +0 -230
  45. package/Components/Custom/LibPixiDrawer.d.ts +0 -16
  46. package/Components/Custom/LibPixiDrawer.js +0 -59
  47. package/Components/Custom/LibPixiInput.d.ts +0 -75
  48. package/Components/Custom/LibPixiInput.js +0 -186
  49. package/Components/Custom/LibPixiLabelValue.d.ts +0 -30
  50. package/Components/Custom/LibPixiLabelValue.js +0 -26
  51. package/Components/Custom/LibPixiPerforMon.d.ts +0 -47
  52. package/Components/Custom/LibPixiPerforMon.js +0 -166
  53. package/Components/Custom/LibPixiProgress.d.ts +0 -33
  54. package/Components/Custom/LibPixiProgress.js +0 -47
  55. package/Components/Custom/LibPixiPuzzleBg.d.ts +0 -7
  56. package/Components/Custom/LibPixiPuzzleBg.js +0 -46
  57. package/Components/Custom/LibPixiScrollContainerX.d.ts +0 -71
  58. package/Components/Custom/LibPixiScrollContainerX.js +0 -189
  59. package/Components/Custom/LibPixiScrollContainerY.d.ts +0 -109
  60. package/Components/Custom/LibPixiScrollContainerY.js +0 -338
  61. package/Components/Custom/LibPixiScrollNum.d.ts +0 -67
  62. package/Components/Custom/LibPixiScrollNum.js +0 -184
  63. package/Components/Custom/LibPixiSlide.d.ts +0 -94
  64. package/Components/Custom/LibPixiSlide.js +0 -285
  65. package/Components/Custom/LibPixiSlider.d.ts +0 -82
  66. package/Components/Custom/LibPixiSlider.js +0 -165
  67. package/Components/Custom/LibPixiSubAddMinMax.d.ts +0 -40
  68. package/Components/Custom/LibPixiSubAddMinMax.js +0 -56
  69. package/Components/Custom/LibPixiTable.d.ts +0 -64
  70. package/Components/Custom/LibPixiTable.js +0 -76
  71. package/Components/Custom/LibPixiTextGroup.d.ts +0 -20
  72. package/Components/Custom/LibPixiTextGroup.js +0 -50
  73. package/Components/Custom/LibPixiTextGroupWrap.d.ts +0 -20
  74. package/Components/Custom/LibPixiTextGroupWrap.js +0 -50
  75. package/Components/Custom/LibPixiTriangle.d.ts +0 -5
  76. package/Components/Custom/LibPixiTriangle.js +0 -12
  77. package/Components/Custom/LibPixiTurntable.d.ts +0 -6
  78. package/Components/Custom/LibPixiTurntable.js +0 -14
  79. package/Utils/LibContainerCenter.d.ts +0 -3
  80. package/Utils/LibContainerCenter.js +0 -10
  81. package/Utils/LibControlledDelayedCall.d.ts +0 -5
  82. package/Utils/LibControlledDelayedCall.js +0 -20
  83. package/Utils/LibPixiArrangeLinear.d.ts +0 -16
  84. package/Utils/LibPixiArrangeLinear.js +0 -62
  85. package/Utils/LibPixiAudio.d.ts +0 -53
  86. package/Utils/LibPixiAudio.js +0 -168
  87. package/Utils/LibPixiCreateNineGrid.d.ts +0 -15
  88. package/Utils/LibPixiCreateNineGrid.js +0 -19
  89. package/Utils/LibPixiDialogManager/index.d.ts +0 -25
  90. package/Utils/LibPixiDialogManager/index.js +0 -43
  91. package/Utils/LibPixiDialogManager/ui/LibPixiBaseContainer.d.ts +0 -11
  92. package/Utils/LibPixiDialogManager/ui/LibPixiBaseContainer.js +0 -31
  93. package/Utils/LibPixiDialogManager/ui/LibPixiDialog.d.ts +0 -38
  94. package/Utils/LibPixiDialogManager/ui/LibPixiDialog.js +0 -133
  95. package/Utils/LibPixiDigitalIncreasingAnimation.d.ts +0 -18
  96. package/Utils/LibPixiDigitalIncreasingAnimation.js +0 -26
  97. package/Utils/LibPixiDownScaleAnimation.d.ts +0 -7
  98. package/Utils/LibPixiDownScaleAnimation.js +0 -33
  99. package/Utils/LibPixiEmitContainerEvent.d.ts +0 -7
  100. package/Utils/LibPixiEmitContainerEvent.js +0 -13
  101. package/Utils/LibPixiEvent.d.ts +0 -19
  102. package/Utils/LibPixiEvent.js +0 -68
  103. package/Utils/LibPixiFilter.d.ts +0 -9
  104. package/Utils/LibPixiFilter.js +0 -34
  105. package/Utils/LibPixiGlobalUpdater.d.ts +0 -15
  106. package/Utils/LibPixiGlobalUpdater.js +0 -21
  107. package/Utils/LibPixiGridLayout.d.ts +0 -10
  108. package/Utils/LibPixiGridLayout.js +0 -27
  109. package/Utils/LibPixiGridLayoutV2.d.ts +0 -27
  110. package/Utils/LibPixiGridLayoutV2.js +0 -37
  111. package/Utils/LibPixiHVCenter.d.ts +0 -7
  112. package/Utils/LibPixiHVCenter.js +0 -14
  113. package/Utils/LibPixiHVGap.d.ts +0 -8
  114. package/Utils/LibPixiHVGap.js +0 -26
  115. package/Utils/LibPixiIntervalTrigger.d.ts +0 -7
  116. package/Utils/LibPixiIntervalTrigger.js +0 -35
  117. package/Utils/LibPixiOutsideClick.d.ts +0 -8
  118. package/Utils/LibPixiOutsideClick.js +0 -22
  119. package/Utils/LibPixiOverflowHidden.d.ts +0 -6
  120. package/Utils/LibPixiOverflowHidden.js +0 -14
  121. package/Utils/LibPixiPolygonDrawTool.d.ts +0 -44
  122. package/Utils/LibPixiPolygonDrawTool.js +0 -114
  123. package/Utils/LibPixiPromiseTickerTimeout.d.ts +0 -6
  124. package/Utils/LibPixiPromiseTickerTimeout.js +0 -22
  125. package/Utils/LibPixiScaleContainer.d.ts +0 -8
  126. package/Utils/LibPixiScaleContainer.js +0 -14
  127. package/Utils/LibPixiShadow.d.ts +0 -17
  128. package/Utils/LibPixiShadow.js +0 -18
  129. package/Utils/LibPixiSlideInput.d.ts +0 -55
  130. package/Utils/LibPixiSlideInput.js +0 -61
  131. package/Utils/LibPixiTicker.d.ts +0 -14
  132. package/Utils/LibPixiTicker.js +0 -49
  133. package/Utils/LibPixiTickerTimeout.d.ts +0 -6
  134. package/Utils/LibPixiTickerTimeout.js +0 -22
  135. package/index.d.ts +0 -1
  136. package/libPixiJs.d.ts +0 -296
  137. package/libPixiJs.js +0 -315
@@ -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 _startPosition;
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,338 +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._startPosition = 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
- this._bottomMarginBox.x = this._topMargin + this._scrollContent.width;
134
- }
135
- /** @description 按下 */
136
- _onDragStart(event) {
137
- if (this._content.height <= this._maskGraphics.height)
138
- return;
139
- const { y } = event.getLocalPosition(this);
140
- this._startY = y - this._content.y;
141
- this._isDragging = true;
142
- this._velocity = 0;
143
- this._startTime = Date.now();
144
- this._startPosition = this._content.y;
145
- gsap.killTweensOf(this._content);
146
- }
147
- /** @description 拖动 */
148
- _onDragMove(event) {
149
- if (this._isDragging) {
150
- const { y } = event.getLocalPosition(this);
151
- const newPosition = y - this._startY;
152
- this._content.y = newPosition;
153
- this._updateScrollbar();
154
- }
155
- }
156
- /** @description 拖动结束 */
157
- _onDragEnd() {
158
- this._isDragging = false;
159
- this._scrollbarDragging = false;
160
- const currentTime = Date.now();
161
- const deltaTime = currentTime - this._startTime; // 计算停留时间
162
- if (deltaTime < 250) {
163
- // 如果停留时间在阈值内,计算惯性速度
164
- this._velocity = (this._content.y - this._startPosition) / deltaTime;
165
- this._applyInertia();
166
- }
167
- else {
168
- // 停留时间超出阈值,取消惯性
169
- this._velocity = 0;
170
- }
171
- this._limitScrollRange();
172
- gsap.to(this._scrollbar, {
173
- duration: 0.5,
174
- alpha: 0,
175
- delay: 0.25,
176
- });
177
- }
178
- /** @description 滚轮滚动 */
179
- _onWheelScroll(event) {
180
- // 如果内容高度小于遮罩高度,则不滚动
181
- if (this._content.height <= this._maskGraphics.height)
182
- return;
183
- let y = this._content.y - event.deltaY * (this._scrollSpeed / 100);
184
- //如果到达顶部,则不滚动
185
- if (y > 0) {
186
- y = 0;
187
- }
188
- //如果到达底部,则不滚动
189
- else if (Math.abs(y) >= this._content.height - this._maskGraphics.height) {
190
- y = -(this._content.height - this._maskGraphics.height);
191
- }
192
- gsap.to(this._content, {
193
- duration: 0.25,
194
- ease: "power1.out",
195
- y,
196
- onUpdate: () => {
197
- this._updateScrollbar();
198
- },
199
- onComplete: () => {
200
- this._hideScrollbar();
201
- },
202
- });
203
- }
204
- /** @description 惯性动画 */
205
- _applyInertia() {
206
- gsap.to(this._content, {
207
- y: this._content.y + this._velocity * 250,
208
- duration: 0.5,
209
- ease: "power1.out",
210
- onUpdate: () => {
211
- this._limitScrollRange();
212
- this._updateScrollbar();
213
- },
214
- onComplete: () => {
215
- this._hideScrollbar();
216
- },
217
- });
218
- }
219
- /** @description 限制滚动范围 */
220
- _limitScrollRange() {
221
- //如果内容顶部离开了滚动容器顶部,则归位
222
- if (this._content.y > 0) {
223
- gsap.to(this._content, {
224
- duration: 0.75,
225
- y: 0,
226
- ease: "elastic.out",
227
- onUpdate: () => {
228
- this._updateScrollbar();
229
- },
230
- onComplete: () => {
231
- this._hideScrollbar();
232
- },
233
- });
234
- }
235
- // 如果滚动距离大于内容高度减去遮罩高度
236
- else if (Math.abs(this._content.y) >=
237
- this._content.height - this._maskGraphics.height) {
238
- // 如果内容高度大于遮罩高度,则滚动到底部
239
- if (this._content.height > this._maskGraphics.height) {
240
- const y = -(this._content.height - this._maskGraphics.height);
241
- gsap.to(this._content, {
242
- duration: 0.75,
243
- y,
244
- ease: "elastic.out",
245
- onUpdate: () => {
246
- this._updateScrollbar();
247
- },
248
- onComplete: () => {
249
- this._hideScrollbar();
250
- },
251
- });
252
- }
253
- // 否则静止不动
254
- else {
255
- gsap.to(this._content, {
256
- duration: 0.25,
257
- y: 0,
258
- onUpdate: () => {
259
- this._updateScrollbar();
260
- },
261
- onComplete: () => {
262
- this._hideScrollbar();
263
- },
264
- });
265
- }
266
- }
267
- }
268
- /** @description 更新滚动位置 */
269
- _updateScrollbar() {
270
- var _a;
271
- this._scrollbar.alpha = 1;
272
- gsap.killTweensOf(this._scrollbar);
273
- const viewHeight = this._maskGraphics.height;
274
- const contentHeight = this._content.height;
275
- const ratio = viewHeight / contentHeight;
276
- const barHeight = viewHeight * ratio;
277
- const maxScrollY = contentHeight - viewHeight;
278
- const scrollY = Math.min(Math.max(-this._content.y, 0), maxScrollY);
279
- const barY = (scrollY / maxScrollY) * (viewHeight - barHeight);
280
- this._scrollbar.y = barY;
281
- (_a = this._onScroll) === null || _a === void 0 ? void 0 : _a.call(this, this._content.y);
282
- }
283
- /** @description 更新滚动条大小 */
284
- _updateScrollbarSize() {
285
- if (!this._showScrollbar)
286
- return;
287
- const viewHeight = this._maskGraphics.height;
288
- const contentHeight = this._content.height;
289
- if (contentHeight <= viewHeight) {
290
- this._scrollbar.visible = false;
291
- }
292
- else {
293
- this._scrollbar.visible = true;
294
- }
295
- const ratio = viewHeight / contentHeight;
296
- const barHeight = viewHeight * ratio;
297
- this._scrollbar.clear();
298
- this._scrollbar.beginFill(this._scrollbarColor);
299
- this._scrollbar.drawRect(0, 0, 10, barHeight);
300
- this._scrollbar.endFill();
301
- }
302
- /** @description 滚动条按下 */
303
- _onScrollbarDragStart(event) {
304
- event.stopPropagation();
305
- this._scrollbarDragging = true;
306
- this._scrollbarDragOffset = event.getLocalPosition(this._scrollbar).y;
307
- gsap.killTweensOf(this._content);
308
- }
309
- /** @description 滚动条移动 */
310
- _onScrollbarDragMove(event) {
311
- event.stopPropagation();
312
- if (!this._scrollbarDragging)
313
- return;
314
- const localY = event.getLocalPosition(this).y;
315
- const viewHeight = this._maskGraphics.height;
316
- const contentHeight = this._content.height;
317
- const ratio = viewHeight / contentHeight;
318
- const barHeight = viewHeight * ratio;
319
- const maxBarY = viewHeight - barHeight;
320
- const newBarY = Math.min(Math.max(localY - this._scrollbarDragOffset, 0), maxBarY);
321
- const scrollY = (newBarY / maxBarY) * (contentHeight - viewHeight);
322
- this._content.y = -scrollY;
323
- this._updateScrollbar();
324
- }
325
- /** @description 滚动条松开 */
326
- _onScrollbarDragEnd(event) {
327
- event.stopPropagation();
328
- this._scrollbarDragging = false;
329
- }
330
- /** @description 滚动结束一秒后隐藏滚动条 */
331
- _hideScrollbar() {
332
- gsap.to(this._scrollbar, {
333
- duration: 0.5,
334
- alpha: 0,
335
- delay: 0.25,
336
- });
337
- }
338
- }
@@ -1,67 +0,0 @@
1
- import { Container } from "pixi.js";
2
- import { LibPixiContainer } from "../Base/LibPixiContainer";
3
- export interface LibPixiScrollNumParams {
4
- /** 滚动区域宽度 */
5
- width: number;
6
- /** 滚动区域高度 */
7
- height: number;
8
- /** 一页高度 */
9
- pageHeight: number;
10
- /** 滚动的容器 */
11
- content: Container;
12
- /** 总数 */
13
- pageNum: number;
14
- /** 松手回调 */
15
- slideCallback?: (index: number) => void;
16
- /** 滚动回调 */
17
- scrollCallback?: (y: number, index: number) => void;
18
- }
19
- /** @description 通过鼠标或手指拖动数字列选择数字
20
- * @link 使用方法:https://www.npmjs.com/package/lyb-pixi-js#LibPixiScrollNum-数字滑动
21
- */
22
- export declare class LibPixiScrollNum extends LibPixiContainer {
23
- /** 当前幻灯片索引 */
24
- private _currentIndex;
25
- /** 滚动区域高度 */
26
- private _scrollHeight;
27
- /** 滑动区域高度 */
28
- private _slideHeight;
29
- /** 记录拖动开始时的Y坐标 */
30
- private _startY;
31
- /** 偏移量 */
32
- private _offsetY;
33
- /** 最大索引 */
34
- private _pageNum;
35
- /** 记录开始时间 */
36
- private _startTime;
37
- /** 是否正在拖动 */
38
- private _isDragging;
39
- /** 滑动内容 */
40
- private _slideArea;
41
- /** 滑动回调 */
42
- private _slideCallback?;
43
- /** 滚动回调 */
44
- private _scrollCallback?;
45
- constructor(params: LibPixiScrollNumParams);
46
- /** @description 更新坐标
47
- * @param y Y坐标
48
- * @param index 页数索引
49
- */
50
- updatePosition(y: number, index: number): void;
51
- /** @description 滑动到指定索引
52
- * @param index 页数索引
53
- */
54
- slideTo(index: number): void;
55
- /** @description 设置滚动景深
56
- * @param containerList 元素列表
57
- * @param y 拖动Y坐标
58
- * @param startY 内部将y - startY进行计算
59
- */
60
- setDepth(containerList: Container[], y: number, startY?: number): void;
61
- /** @description 开始拖动 */
62
- private _onDragStart;
63
- /** @description 拖动中 */
64
- private _onDragMove;
65
- /** @description 结束拖动 */
66
- private _onDragEnd;
67
- }
@@ -1,184 +0,0 @@
1
- import { Graphics } from "pixi.js";
2
- import gsap from "gsap";
3
- import { LibPixiContainer } from "../Base/LibPixiContainer";
4
- import { LibJsLerp } from "lyb-js/Math/LibJsLerp.js";
5
- /** @description 通过鼠标或手指拖动数字列选择数字
6
- * @link 使用方法:https://www.npmjs.com/package/lyb-pixi-js#LibPixiScrollNum-数字滑动
7
- */
8
- export class LibPixiScrollNum extends LibPixiContainer {
9
- constructor(params) {
10
- const { width, height, content, slideCallback, scrollCallback, pageNum, pageHeight, } = params;
11
- super(width, height);
12
- /** 当前幻灯片索引 */
13
- this._currentIndex = 0;
14
- /** 滚动区域高度 */
15
- this._scrollHeight = 0;
16
- /** 滑动区域高度 */
17
- this._slideHeight = 0;
18
- /** 记录拖动开始时的Y坐标 */
19
- this._startY = 0;
20
- /** 偏移量 */
21
- this._offsetY = 0;
22
- /** 最大索引 */
23
- this._pageNum = 0;
24
- /** 记录开始时间 */
25
- this._startTime = new Date().getTime();
26
- /** 是否正在拖动 */
27
- this._isDragging = false;
28
- //设置遮罩
29
- const mask = new Graphics();
30
- mask.beginFill(0xffffff);
31
- mask.drawRect(0, 0, this.width, this.height);
32
- mask.endFill();
33
- this.addChild(mask);
34
- this.mask = mask;
35
- this._scrollHeight = height;
36
- this._slideHeight = pageHeight;
37
- this._slideArea = content;
38
- this._slideCallback = slideCallback;
39
- this._scrollCallback = scrollCallback;
40
- this._pageNum = pageNum - 1;
41
- this.addChild(this._slideArea);
42
- this._slideArea.x = width / 2;
43
- this._slideArea.y = this._scrollHeight / 2;
44
- // 监听拖动事件
45
- this.eventMode = "static";
46
- this.cursor = "pointer";
47
- this.on("pointerdown", this._onDragStart);
48
- window.addEventListener("pointermove", this._onDragMove.bind(this));
49
- window.addEventListener("pointerup", this._onDragEnd.bind(this));
50
- }
51
- /** @description 更新坐标
52
- * @param y Y坐标
53
- * @param index 页数索引
54
- */
55
- updatePosition(y, index) {
56
- this._slideArea.y = y;
57
- this._currentIndex = index;
58
- }
59
- /** @description 滑动到指定索引
60
- * @param index 页数索引
61
- */
62
- slideTo(index) {
63
- var _a;
64
- if (index < 0) {
65
- // 回弹到第一张
66
- gsap.to(this._slideArea, {
67
- y: this._scrollHeight / 2,
68
- duration: 0.25,
69
- onUpdate: () => {
70
- var _a;
71
- (_a = this._scrollCallback) === null || _a === void 0 ? void 0 : _a.call(this, this._slideArea.y, this._currentIndex);
72
- },
73
- });
74
- this._currentIndex = 0;
75
- }
76
- else if (index > this._pageNum) {
77
- // 回弹到最后一张
78
- gsap.to(this._slideArea, {
79
- y: -this._pageNum * this._slideHeight + this._scrollHeight / 2,
80
- duration: 0.5,
81
- onUpdate: () => {
82
- var _a;
83
- (_a = this._scrollCallback) === null || _a === void 0 ? void 0 : _a.call(this, this._slideArea.y, this._currentIndex);
84
- },
85
- });
86
- this._currentIndex = this._pageNum;
87
- }
88
- else {
89
- // 正常滑动
90
- this._currentIndex = index;
91
- gsap.to(this._slideArea, {
92
- y: -this._currentIndex * this._slideHeight + this._scrollHeight / 2,
93
- duration: 0.1,
94
- onUpdate: () => {
95
- var _a;
96
- (_a = this._scrollCallback) === null || _a === void 0 ? void 0 : _a.call(this, this._slideArea.y, this._currentIndex);
97
- },
98
- });
99
- }
100
- (_a = this._slideCallback) === null || _a === void 0 ? void 0 : _a.call(this, this._currentIndex);
101
- }
102
- /** @description 设置滚动景深
103
- * @param containerList 元素列表
104
- * @param y 拖动Y坐标
105
- * @param startY 内部将y - startY进行计算
106
- */
107
- setDepth(containerList, y, startY = 0) {
108
- const Y = y - startY;
109
- const idx = Math.floor(Math.abs(Y) / this._slideHeight);
110
- const t = (Math.abs(Y) % this._slideHeight) / this._slideHeight;
111
- const prevIdx = idx - 1;
112
- const nextIdx = idx + 1;
113
- const nextIdx2 = idx + 2;
114
- const curItem = containerList[idx];
115
- curItem.alpha = LibJsLerp(0.5, 1, 1 - t);
116
- curItem.scale.y = LibJsLerp(0.85, 1, 1 - t);
117
- if (nextIdx < containerList.length) {
118
- const nextItem = containerList[nextIdx];
119
- nextItem.alpha = LibJsLerp(0.5, 1, t);
120
- nextItem.scale.y = LibJsLerp(0.85, 1, t);
121
- }
122
- if (nextIdx2 < containerList.length) {
123
- const nextItem = containerList[nextIdx2];
124
- nextItem.alpha = LibJsLerp(0.1, 0.5, t);
125
- }
126
- if (prevIdx >= 0) {
127
- const prevItem = containerList[prevIdx];
128
- prevItem.alpha = LibJsLerp(0.1, 0.5, 1 - t);
129
- }
130
- }
131
- /** @description 开始拖动 */
132
- _onDragStart(event) {
133
- this._isDragging = true;
134
- this._startY = event.data.global.y;
135
- this._offsetY = this._slideArea.y;
136
- gsap.killTweensOf(this._slideArea);
137
- this._startTime = new Date().getTime();
138
- }
139
- /** @description 拖动中 */
140
- _onDragMove(event) {
141
- var _a;
142
- if (!this._isDragging)
143
- return;
144
- const moveY = event.pageY - this._startY;
145
- let newY = this._offsetY + moveY;
146
- // 限制滑动区域的上下边界
147
- const minY = this._scrollHeight / 2;
148
- const maxY = -this._pageNum * this._slideHeight + this._scrollHeight / 2;
149
- // 如果超出上下边界,禁止拖动
150
- if (newY > minY)
151
- newY = minY;
152
- if (newY < maxY)
153
- newY = maxY;
154
- this._slideArea.y = newY;
155
- (_a = this._scrollCallback) === null || _a === void 0 ? void 0 : _a.call(this, this._slideArea.y, this._currentIndex);
156
- }
157
- /** @description 结束拖动 */
158
- _onDragEnd(event) {
159
- if (!this._isDragging)
160
- return;
161
- this._isDragging = false;
162
- const endTime = new Date().getTime() - this._startTime;
163
- const slide = this._startY - event.pageY; // 计算滑动的距离
164
- const slideSpeed = Math.abs(slide) / endTime; // 计算滑动速度
165
- const speedThreshold = 0.275;
166
- // 计算滑动的页面变化数,根据滑动距离来调整页码
167
- const slideThreshold = this._slideHeight / 2;
168
- // 计算实际的翻页增量,使用 `slide / this._slideHeight` 来计算滑动的页数
169
- const pageChange = Math.round(slide / this._slideHeight);
170
- // 如果滑动速度足够快,且滑动的距离大于阈值,强制翻页
171
- if (Math.abs(slide) > slideThreshold || slideSpeed > speedThreshold) {
172
- this._currentIndex += pageChange; // 这里会根据滑动的方向来增加或减少当前页码
173
- }
174
- // 防止超出页面的上下限
175
- if (this._currentIndex < 0) {
176
- this._currentIndex = 0; // 保证当前页码不小于 0
177
- }
178
- else if (this._currentIndex > this._pageNum) {
179
- this._currentIndex = this._pageNum; // 保证当前页码不大于最大页码
180
- }
181
- // 执行滑动到目标页码
182
- this.slideTo(this._currentIndex);
183
- }
184
- }