lyb-pixi-js 1.12.40 → 1.12.41
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.
- package/Components/Base/LibPixiArc.d.ts +16 -0
- package/Components/Base/LibPixiArc.js +14 -0
- package/Components/Base/LibPixiBitText.d.ts +20 -0
- package/Components/Base/LibPixiBitText.js +26 -0
- package/Components/Base/LibPixiCircular.d.ts +7 -0
- package/Components/Base/LibPixiCircular.js +12 -0
- package/Components/Base/LibPixiContainer.d.ts +22 -0
- package/Components/Base/LibPixiContainer.js +51 -0
- package/Components/Base/LibPixiHtmlText.d.ts +31 -0
- package/Components/Base/LibPixiHtmlText.js +30 -0
- package/Components/Base/LibPixiOval.d.ts +5 -0
- package/Components/Base/LibPixiOval.js +10 -0
- package/Components/Base/LibPixiParticleMove.d.ts +101 -0
- package/Components/Base/LibPixiParticleMove.js +136 -0
- package/Components/Base/LibPixiPolygon.d.ts +7 -0
- package/Components/Base/LibPixiPolygon.js +15 -0
- package/Components/Base/LibPixiRectBgColor.d.ts +41 -0
- package/Components/Base/LibPixiRectBgColor.js +95 -0
- package/Components/Base/LibPixiRectangle.d.ts +7 -0
- package/Components/Base/LibPixiRectangle.js +15 -0
- package/Components/Base/LibPixiRound.d.ts +5 -0
- package/Components/Base/LibPixiRound.js +9 -0
- package/Components/Base/LibPixiRoundedRect.d.ts +5 -0
- package/Components/Base/LibPixiRoundedRect.js +10 -0
- package/Components/Base/LibPixiSpine.d.ts +58 -0
- package/Components/Base/LibPixiSpine.js +128 -0
- package/Components/Base/LibPixiText.d.ts +37 -0
- package/Components/Base/LibPixiText.js +35 -0
- package/Components/Custom/LibPixiAreaClick.d.ts +6 -0
- package/Components/Custom/LibPixiAreaClick.js +16 -0
- package/Components/Custom/LibPixiArrangeLinearV2.d.ts +25 -0
- package/Components/Custom/LibPixiArrangeLinearV2.js +80 -0
- package/Components/Custom/LibPixiButtonHover.d.ts +40 -0
- package/Components/Custom/LibPixiButtonHover.js +53 -0
- package/Components/Custom/LibPixiCapsule.d.ts +5 -0
- package/Components/Custom/LibPixiCapsule.js +10 -0
- package/Components/Custom/LibPixiCloseBtn.d.ts +14 -0
- package/Components/Custom/LibPixiCloseBtn.js +36 -0
- package/Components/Custom/LibPixiDragLocate.d.ts +36 -0
- package/Components/Custom/LibPixiDragLocate.js +230 -0
- package/Components/Custom/LibPixiDrawer.d.ts +16 -0
- package/Components/Custom/LibPixiDrawer.js +59 -0
- package/Components/Custom/LibPixiGridLayoutV2.d.ts +27 -0
- package/Components/Custom/LibPixiGridLayoutV2.js +37 -0
- package/Components/Custom/LibPixiHeadingParagraphLayout.d.ts +18 -0
- package/Components/Custom/LibPixiHeadingParagraphLayout.js +27 -0
- package/Components/Custom/LibPixiInput.d.ts +77 -0
- package/Components/Custom/LibPixiInput.js +198 -0
- package/Components/Custom/LibPixiLabelValue.d.ts +30 -0
- package/Components/Custom/LibPixiLabelValue.js +26 -0
- package/Components/Custom/LibPixiPerforMon.d.ts +47 -0
- package/Components/Custom/LibPixiPerforMon.js +166 -0
- package/Components/Custom/LibPixiProgress.d.ts +33 -0
- package/Components/Custom/LibPixiProgress.js +47 -0
- package/Components/Custom/LibPixiPuzzleBg.d.ts +7 -0
- package/Components/Custom/LibPixiPuzzleBg.js +46 -0
- package/Components/Custom/LibPixiScrollContainerX.d.ts +71 -0
- package/Components/Custom/LibPixiScrollContainerX.js +198 -0
- package/Components/Custom/LibPixiScrollContainerY.d.ts +109 -0
- package/Components/Custom/LibPixiScrollContainerY.js +340 -0
- package/Components/Custom/LibPixiScrollNum.d.ts +67 -0
- package/Components/Custom/LibPixiScrollNum.js +184 -0
- package/Components/Custom/LibPixiSlide.d.ts +94 -0
- package/Components/Custom/LibPixiSlide.js +285 -0
- package/Components/Custom/LibPixiSlider.d.ts +82 -0
- package/Components/Custom/LibPixiSlider.js +165 -0
- package/Components/Custom/LibPixiTable.d.ts +64 -0
- package/Components/Custom/LibPixiTable.js +76 -0
- package/Components/Custom/LibPixiTextGroupWrap.d.ts +20 -0
- package/Components/Custom/LibPixiTextGroupWrap.js +50 -0
- package/Components/Custom/LibPixiTriangle.d.ts +5 -0
- package/Components/Custom/LibPixiTriangle.js +12 -0
- package/Components/Custom/LibPixiTurntable.d.ts +6 -0
- package/Components/Custom/LibPixiTurntable.js +14 -0
- package/Utils/LibContainerCenter.d.ts +3 -0
- package/Utils/LibContainerCenter.js +10 -0
- package/Utils/LibControlledDelayedCall.d.ts +5 -0
- package/Utils/LibControlledDelayedCall.js +20 -0
- package/Utils/LibPixiArrangeLinear.d.ts +16 -0
- package/Utils/LibPixiArrangeLinear.js +62 -0
- package/Utils/LibPixiAudio.d.ts +53 -0
- package/Utils/LibPixiAudio.js +168 -0
- package/Utils/LibPixiCreateNineGrid.d.ts +15 -0
- package/Utils/LibPixiCreateNineGrid.js +19 -0
- package/Utils/LibPixiDialogManager/index.d.ts +25 -0
- package/Utils/LibPixiDialogManager/index.js +43 -0
- package/Utils/LibPixiDialogManager/ui/LibPixiBaseContainer.d.ts +11 -0
- package/Utils/LibPixiDialogManager/ui/LibPixiBaseContainer.js +31 -0
- package/Utils/LibPixiDialogManager/ui/LibPixiDialog.d.ts +40 -0
- package/Utils/LibPixiDialogManager/ui/LibPixiDialog.js +145 -0
- package/Utils/LibPixiDigitalIncreasingAnimation.d.ts +18 -0
- package/Utils/LibPixiDigitalIncreasingAnimation.js +26 -0
- package/Utils/LibPixiDownScaleAnimation.d.ts +7 -0
- package/Utils/LibPixiDownScaleAnimation.js +33 -0
- package/Utils/LibPixiEmitContainerEvent.d.ts +7 -0
- package/Utils/LibPixiEmitContainerEvent.js +13 -0
- package/Utils/LibPixiEvent.d.ts +19 -0
- package/Utils/LibPixiEvent.js +68 -0
- package/Utils/LibPixiFilter.d.ts +9 -0
- package/Utils/LibPixiFilter.js +34 -0
- package/Utils/LibPixiGlobalUpdater.d.ts +15 -0
- package/Utils/LibPixiGlobalUpdater.js +21 -0
- package/Utils/LibPixiGridLayout.d.ts +10 -0
- package/Utils/LibPixiGridLayout.js +27 -0
- package/Utils/LibPixiHVCenter.d.ts +7 -0
- package/Utils/LibPixiHVCenter.js +14 -0
- package/Utils/LibPixiHVGap.d.ts +8 -0
- package/Utils/LibPixiHVGap.js +26 -0
- package/Utils/LibPixiIntervalTrigger.d.ts +7 -0
- package/Utils/LibPixiIntervalTrigger.js +35 -0
- package/Utils/LibPixiOutsideClick.d.ts +8 -0
- package/Utils/LibPixiOutsideClick.js +22 -0
- package/Utils/LibPixiOverflowHidden.d.ts +6 -0
- package/Utils/LibPixiOverflowHidden.js +14 -0
- package/Utils/LibPixiPolygonDrawTool.d.ts +44 -0
- package/Utils/LibPixiPolygonDrawTool.js +114 -0
- package/Utils/LibPixiPromiseTickerTimeout.d.ts +6 -0
- package/Utils/LibPixiPromiseTickerTimeout.js +22 -0
- package/Utils/LibPixiScaleContainer.d.ts +8 -0
- package/Utils/LibPixiScaleContainer.js +14 -0
- package/Utils/LibPixiShadow.d.ts +17 -0
- package/Utils/LibPixiShadow.js +18 -0
- package/Utils/LibPixiSlideInput.d.ts +55 -0
- package/Utils/LibPixiSlideInput.js +61 -0
- package/Utils/LibPixiTicker.d.ts +14 -0
- package/Utils/LibPixiTicker.js +49 -0
- package/Utils/LibPixiTickerTimeout.d.ts +6 -0
- package/Utils/LibPixiTickerTimeout.js +22 -0
- package/package.json +1 -1
|
@@ -0,0 +1,67 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,184 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { Container } from "pixi.js";
|
|
2
|
+
import { LibPixiContainer } from "../Base/LibPixiContainer";
|
|
3
|
+
export interface LibPixiSlideParams {
|
|
4
|
+
/** 舞台 */
|
|
5
|
+
stage: Container;
|
|
6
|
+
/** 当前方向 */
|
|
7
|
+
direction: "x" | "y";
|
|
8
|
+
/** 滚动区域宽度 */
|
|
9
|
+
width: number;
|
|
10
|
+
/** 滚动区域高度 */
|
|
11
|
+
height: number;
|
|
12
|
+
/** 一页宽度 */
|
|
13
|
+
pageWidth?: number;
|
|
14
|
+
/** 一页高度 */
|
|
15
|
+
pageHeight?: number;
|
|
16
|
+
/** 滚动的容器 */
|
|
17
|
+
content: Container;
|
|
18
|
+
/** 元素列表 */
|
|
19
|
+
itemList: Container[];
|
|
20
|
+
/** 是否启用循环 */
|
|
21
|
+
loop?: boolean;
|
|
22
|
+
/** 景深定制回调,第二参数函数参数景深衰减值,可视区三个元素时,建议0.5,五个元素时,建议0.2 */
|
|
23
|
+
depthCallback?: (container: Container, getValue: (depthAtten: number) => number) => void;
|
|
24
|
+
/** 松手回调 */
|
|
25
|
+
slideCallback?: (index: number) => void;
|
|
26
|
+
/** 滚动回调 */
|
|
27
|
+
scrollCallback?: (x: number, index: number) => void;
|
|
28
|
+
}
|
|
29
|
+
/** @description 滑动页
|
|
30
|
+
* @link 使用方法:https://www.npmjs.com/package/lyb-pixi-js#LibPixiSlide-滑动页
|
|
31
|
+
*/
|
|
32
|
+
export declare class LibPixiSlide extends LibPixiContainer {
|
|
33
|
+
/** 舞台 */
|
|
34
|
+
private _stage;
|
|
35
|
+
/** 滑动加速度触发翻页 */
|
|
36
|
+
private _SPEED_THRESHOLD;
|
|
37
|
+
/** 滑动比例翻页 */
|
|
38
|
+
private _SCROLL_THRESHOLD;
|
|
39
|
+
/** 当前方向 */
|
|
40
|
+
private _direction;
|
|
41
|
+
/** 元素列表 */
|
|
42
|
+
private _itemList;
|
|
43
|
+
/** 一页宽度 */
|
|
44
|
+
private _pageWidth;
|
|
45
|
+
/** 一页高度 */
|
|
46
|
+
private _pageHeight;
|
|
47
|
+
/** 是否循环 */
|
|
48
|
+
private _loop;
|
|
49
|
+
/** 两侧预留格数,如可视区有三个,则两侧预留为1 */
|
|
50
|
+
private _freeGridNum;
|
|
51
|
+
/** 当前幻灯片索引 */
|
|
52
|
+
private _currentIndex;
|
|
53
|
+
/** 记录拖动开始时的X坐标 */
|
|
54
|
+
private _startX;
|
|
55
|
+
/** 记录拖动开始时的Y坐标 */
|
|
56
|
+
private _startY;
|
|
57
|
+
/** 偏移量 */
|
|
58
|
+
private _offsetX;
|
|
59
|
+
/** 偏移量 */
|
|
60
|
+
private _offsetY;
|
|
61
|
+
/** 最大索引 */
|
|
62
|
+
private _pageNum;
|
|
63
|
+
/** 记录开始时间 */
|
|
64
|
+
private _startTime;
|
|
65
|
+
/** 是否正在拖动 */
|
|
66
|
+
private _isDragging;
|
|
67
|
+
/** 滑动内容 */
|
|
68
|
+
private _slideArea;
|
|
69
|
+
/** 景深定制回调 */
|
|
70
|
+
private _depthCallback?;
|
|
71
|
+
/** 滑动回调 */
|
|
72
|
+
private _slideCallback?;
|
|
73
|
+
/** 滚动回调 */
|
|
74
|
+
private _scrollCallback?;
|
|
75
|
+
constructor(params: LibPixiSlideParams);
|
|
76
|
+
/** @description 更新坐标 */
|
|
77
|
+
updatePosition(v: number, index: number): void;
|
|
78
|
+
/** @description 上一页 */
|
|
79
|
+
prev(): void;
|
|
80
|
+
/** @description 下一页 */
|
|
81
|
+
next(): void;
|
|
82
|
+
/** @description 滑动到指定索引 */
|
|
83
|
+
slideTo(index: number): void;
|
|
84
|
+
/** @description 设置滚动景深 */
|
|
85
|
+
private _setDepth;
|
|
86
|
+
/** @description 开始拖动 */
|
|
87
|
+
private _onDragStart;
|
|
88
|
+
/** @description 拖动中 */
|
|
89
|
+
private _onDragMove;
|
|
90
|
+
/** @description 滚动触发 */
|
|
91
|
+
private _onScroll;
|
|
92
|
+
/** @description 结束拖动 */
|
|
93
|
+
private _onDragEnd;
|
|
94
|
+
}
|
|
@@ -0,0 +1,285 @@
|
|
|
1
|
+
import { Graphics } from "pixi.js";
|
|
2
|
+
import gsap from "gsap";
|
|
3
|
+
import { libPixiEvent } from "../../Utils/LibPixiEvent";
|
|
4
|
+
import { LibPixiContainer } from "../Base/LibPixiContainer";
|
|
5
|
+
/** @description 滑动页
|
|
6
|
+
* @link 使用方法:https://www.npmjs.com/package/lyb-pixi-js#LibPixiSlide-滑动页
|
|
7
|
+
*/
|
|
8
|
+
export class LibPixiSlide extends LibPixiContainer {
|
|
9
|
+
constructor(params) {
|
|
10
|
+
const { stage, width, height, content, depthCallback, slideCallback, scrollCallback, pageWidth = 0, pageHeight = 0, itemList, loop = false, direction, } = params;
|
|
11
|
+
super(width, height);
|
|
12
|
+
/** 滑动加速度触发翻页 */
|
|
13
|
+
this._SPEED_THRESHOLD = 0.35;
|
|
14
|
+
/** 滑动比例翻页 */
|
|
15
|
+
this._SCROLL_THRESHOLD = 0.5;
|
|
16
|
+
/** 一页宽度 */
|
|
17
|
+
this._pageWidth = 0;
|
|
18
|
+
/** 一页高度 */
|
|
19
|
+
this._pageHeight = 0;
|
|
20
|
+
/** 是否循环 */
|
|
21
|
+
this._loop = false;
|
|
22
|
+
/** 两侧预留格数,如可视区有三个,则两侧预留为1 */
|
|
23
|
+
this._freeGridNum = 0;
|
|
24
|
+
/** 当前幻灯片索引 */
|
|
25
|
+
this._currentIndex = 0;
|
|
26
|
+
/** 记录拖动开始时的X坐标 */
|
|
27
|
+
this._startX = 0;
|
|
28
|
+
/** 记录拖动开始时的Y坐标 */
|
|
29
|
+
this._startY = 0;
|
|
30
|
+
/** 偏移量 */
|
|
31
|
+
this._offsetX = 0;
|
|
32
|
+
/** 偏移量 */
|
|
33
|
+
this._offsetY = 0;
|
|
34
|
+
/** 最大索引 */
|
|
35
|
+
this._pageNum = 0;
|
|
36
|
+
/** 记录开始时间 */
|
|
37
|
+
this._startTime = new Date().getTime();
|
|
38
|
+
/** 是否正在拖动 */
|
|
39
|
+
this._isDragging = false;
|
|
40
|
+
this._stage = stage;
|
|
41
|
+
const mask = new Graphics();
|
|
42
|
+
mask.beginFill(0xffffff);
|
|
43
|
+
mask.drawRect(0, 0, this.width, this.height);
|
|
44
|
+
mask.endFill();
|
|
45
|
+
this.addChild(mask);
|
|
46
|
+
this.mask = mask;
|
|
47
|
+
this._direction = direction;
|
|
48
|
+
this._pageWidth = pageWidth;
|
|
49
|
+
this._pageHeight = pageHeight;
|
|
50
|
+
this._slideArea = content;
|
|
51
|
+
this._itemList = itemList;
|
|
52
|
+
this._loop = loop;
|
|
53
|
+
this._depthCallback = depthCallback;
|
|
54
|
+
this._slideCallback = slideCallback;
|
|
55
|
+
this._scrollCallback = scrollCallback;
|
|
56
|
+
this._pageNum = itemList.length;
|
|
57
|
+
this.addChild(this._slideArea);
|
|
58
|
+
if (this._direction === "x") {
|
|
59
|
+
this._freeGridNum = Math.floor(width / this._pageWidth / 2);
|
|
60
|
+
this._slideArea.x = this._pageWidth * this._freeGridNum;
|
|
61
|
+
}
|
|
62
|
+
else {
|
|
63
|
+
this._freeGridNum = Math.floor(height / pageHeight / 2);
|
|
64
|
+
this._slideArea.y = this._pageHeight * this._freeGridNum;
|
|
65
|
+
}
|
|
66
|
+
this.eventMode = "static";
|
|
67
|
+
this.cursor = "pointer";
|
|
68
|
+
this._setDepth();
|
|
69
|
+
libPixiEvent(this, "pointerdown", this._onDragStart.bind(this));
|
|
70
|
+
libPixiEvent(stage, "pointermove", this._onDragMove.bind(this));
|
|
71
|
+
libPixiEvent(stage, "pointerup", this._onDragEnd.bind(this));
|
|
72
|
+
}
|
|
73
|
+
/** @description 更新坐标 */
|
|
74
|
+
updatePosition(v, index) {
|
|
75
|
+
this._currentIndex = index;
|
|
76
|
+
this._setDepth();
|
|
77
|
+
if (this._direction === "x") {
|
|
78
|
+
this._slideArea.x = v;
|
|
79
|
+
}
|
|
80
|
+
else {
|
|
81
|
+
this._slideArea.y = v;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
/** @description 上一页 */
|
|
85
|
+
prev() {
|
|
86
|
+
this.slideTo(this._currentIndex - 1);
|
|
87
|
+
}
|
|
88
|
+
/** @description 下一页 */
|
|
89
|
+
next() {
|
|
90
|
+
this.slideTo(this._currentIndex + 1);
|
|
91
|
+
}
|
|
92
|
+
/** @description 滑动到指定索引 */
|
|
93
|
+
slideTo(index) {
|
|
94
|
+
var _a;
|
|
95
|
+
this._currentIndex = index;
|
|
96
|
+
//首尾限制
|
|
97
|
+
if (this._currentIndex < 0) {
|
|
98
|
+
if (this._loop) {
|
|
99
|
+
this._currentIndex = this._pageNum - 1;
|
|
100
|
+
}
|
|
101
|
+
else {
|
|
102
|
+
this._currentIndex = 0;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
else if (this._currentIndex >= this._pageNum) {
|
|
106
|
+
this._currentIndex = this._pageNum;
|
|
107
|
+
if (this._loop) {
|
|
108
|
+
this._currentIndex = 0;
|
|
109
|
+
}
|
|
110
|
+
else {
|
|
111
|
+
this._currentIndex--;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
if (this._direction === "x") {
|
|
115
|
+
gsap.to(this._slideArea, {
|
|
116
|
+
x: -this._currentIndex * this._pageWidth +
|
|
117
|
+
this._pageWidth * this._freeGridNum,
|
|
118
|
+
duration: 0.25,
|
|
119
|
+
onUpdate: () => {
|
|
120
|
+
this._onScroll();
|
|
121
|
+
},
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
else {
|
|
125
|
+
gsap.to(this._slideArea, {
|
|
126
|
+
y: -this._currentIndex * this._pageHeight +
|
|
127
|
+
this._pageHeight * this._freeGridNum,
|
|
128
|
+
duration: 0.25,
|
|
129
|
+
onUpdate: () => {
|
|
130
|
+
this._onScroll();
|
|
131
|
+
},
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
// 触发滑动结束回调
|
|
135
|
+
(_a = this._slideCallback) === null || _a === void 0 ? void 0 : _a.call(this, this._currentIndex);
|
|
136
|
+
}
|
|
137
|
+
/** @description 设置滚动景深 */
|
|
138
|
+
_setDepth() {
|
|
139
|
+
if (!this._depthCallback)
|
|
140
|
+
return;
|
|
141
|
+
let t = 0;
|
|
142
|
+
let currentIndex = 0;
|
|
143
|
+
if (this._direction === "x") {
|
|
144
|
+
const x = this._slideArea.x;
|
|
145
|
+
const startX = this._freeGridNum * this._pageWidth;
|
|
146
|
+
//设置起始位置,获取当前绝对坐标
|
|
147
|
+
const absX = Math.abs(x - startX);
|
|
148
|
+
// 根据滑动宽度计算出当前位置对应的索引
|
|
149
|
+
currentIndex = Math.floor(absX / this._pageWidth);
|
|
150
|
+
// 计算当前索引在一页中的比例,越靠近当前索引的x坐标,值越小,范围0-1
|
|
151
|
+
t = (absX % this._pageWidth) / this._pageWidth;
|
|
152
|
+
//如果在起点的时候还在向左滑,则取反,避免distance显示效果计算错误
|
|
153
|
+
if (x - startX > 0) {
|
|
154
|
+
t = -t;
|
|
155
|
+
currentIndex = -currentIndex;
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
else {
|
|
159
|
+
const y = this._slideArea.y;
|
|
160
|
+
const startY = this._freeGridNum * this._pageHeight;
|
|
161
|
+
//设置起始位置,获取当前绝对坐标
|
|
162
|
+
const absY = Math.abs(y - startY);
|
|
163
|
+
// 根据滑动宽度计算出当前位置对应的索引
|
|
164
|
+
currentIndex = Math.floor(absY / this._pageHeight);
|
|
165
|
+
// 计算当前索引在一页中的比例,越靠近当前索引的x坐标,值越小,范围0-1
|
|
166
|
+
t = (absY % this._pageHeight) / this._pageHeight;
|
|
167
|
+
//如果在起点的时候还在向左滑,则取反,避免distance显示效果计算错误
|
|
168
|
+
if (y - startY > 0) {
|
|
169
|
+
t = -t;
|
|
170
|
+
currentIndex = -currentIndex;
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
this._itemList.forEach((item, i) => {
|
|
174
|
+
var _a;
|
|
175
|
+
// 计算当前项与目标索引之间的索引距离
|
|
176
|
+
const distance = Math.abs(i - currentIndex - t);
|
|
177
|
+
(_a = this._depthCallback) === null || _a === void 0 ? void 0 : _a.call(this, item, (depthAtten) => {
|
|
178
|
+
return Math.max(0, 1 - distance * depthAtten);
|
|
179
|
+
});
|
|
180
|
+
});
|
|
181
|
+
}
|
|
182
|
+
/** @description 开始拖动 */
|
|
183
|
+
_onDragStart(event) {
|
|
184
|
+
const { x, y } = this._stage.toLocal(event.global);
|
|
185
|
+
this._isDragging = true;
|
|
186
|
+
gsap.killTweensOf(this._slideArea);
|
|
187
|
+
this._startTime = new Date().getTime();
|
|
188
|
+
if (this._direction === "x") {
|
|
189
|
+
this._startX = x;
|
|
190
|
+
this._offsetX = this._slideArea.x;
|
|
191
|
+
}
|
|
192
|
+
else {
|
|
193
|
+
this._startY = y;
|
|
194
|
+
this._offsetY = this._slideArea.y;
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
/** @description 拖动中 */
|
|
198
|
+
_onDragMove(event) {
|
|
199
|
+
if (!this._isDragging)
|
|
200
|
+
return;
|
|
201
|
+
const { x, y } = this._stage.toLocal(event.global);
|
|
202
|
+
if (this._direction === "x") {
|
|
203
|
+
const moveX = x - this._startX;
|
|
204
|
+
this._slideArea.x = this._offsetX + moveX;
|
|
205
|
+
}
|
|
206
|
+
else {
|
|
207
|
+
const moveY = y - this._startY;
|
|
208
|
+
this._slideArea.y = this._offsetY + moveY;
|
|
209
|
+
}
|
|
210
|
+
this._onScroll();
|
|
211
|
+
}
|
|
212
|
+
/** @description 滚动触发 */
|
|
213
|
+
_onScroll() {
|
|
214
|
+
var _a, _b;
|
|
215
|
+
this._setDepth();
|
|
216
|
+
if (this._direction === "x") {
|
|
217
|
+
(_a = this._scrollCallback) === null || _a === void 0 ? void 0 : _a.call(this, this._slideArea.x, this._currentIndex);
|
|
218
|
+
}
|
|
219
|
+
else {
|
|
220
|
+
(_b = this._scrollCallback) === null || _b === void 0 ? void 0 : _b.call(this, this._slideArea.y, this._currentIndex);
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
/** @description 结束拖动 */
|
|
224
|
+
_onDragEnd(event) {
|
|
225
|
+
const { x, y } = this._stage.toLocal(event.global);
|
|
226
|
+
if (this._direction === "x") {
|
|
227
|
+
if (!this._isDragging)
|
|
228
|
+
return;
|
|
229
|
+
this._isDragging = false;
|
|
230
|
+
//滑动耗时
|
|
231
|
+
const slideTime = new Date().getTime() - this._startTime;
|
|
232
|
+
//滑动距离
|
|
233
|
+
const slide = this._startX - x;
|
|
234
|
+
//滑动速度
|
|
235
|
+
const slideSpeed = Math.abs(slide) / slideTime;
|
|
236
|
+
//要滑动的页数
|
|
237
|
+
const pageChange = Math.round(slide / this._pageWidth);
|
|
238
|
+
//如果滑动超过阈值,则翻页
|
|
239
|
+
if (Math.abs(slide) > this._pageWidth * this._SCROLL_THRESHOLD) {
|
|
240
|
+
this._currentIndex += pageChange;
|
|
241
|
+
}
|
|
242
|
+
//如果滑动速度大于阈值,则翻页
|
|
243
|
+
else if (slideSpeed > this._SPEED_THRESHOLD) {
|
|
244
|
+
let addIndex = slide / this._pageWidth;
|
|
245
|
+
if (addIndex > 0) {
|
|
246
|
+
addIndex = Math.ceil(addIndex);
|
|
247
|
+
}
|
|
248
|
+
else {
|
|
249
|
+
addIndex = Math.floor(addIndex);
|
|
250
|
+
}
|
|
251
|
+
this._currentIndex += addIndex;
|
|
252
|
+
}
|
|
253
|
+
this.slideTo(this._currentIndex);
|
|
254
|
+
}
|
|
255
|
+
else {
|
|
256
|
+
if (!this._isDragging)
|
|
257
|
+
return;
|
|
258
|
+
this._isDragging = false;
|
|
259
|
+
//滑动耗时
|
|
260
|
+
const slideTime = new Date().getTime() - this._startTime;
|
|
261
|
+
//滑动距离
|
|
262
|
+
const slide = this._startY - y;
|
|
263
|
+
//滑动速度
|
|
264
|
+
const slideSpeed = Math.abs(slide) / slideTime;
|
|
265
|
+
//要滑动的页数
|
|
266
|
+
const pageChange = Math.round(slide / this._pageHeight);
|
|
267
|
+
//如果滑动超过阈值,则翻页
|
|
268
|
+
if (Math.abs(slide) > this._pageHeight * this._SCROLL_THRESHOLD) {
|
|
269
|
+
this._currentIndex += pageChange;
|
|
270
|
+
}
|
|
271
|
+
//如果滑动速度大于阈值,则翻页
|
|
272
|
+
else if (slideSpeed > this._SPEED_THRESHOLD) {
|
|
273
|
+
let addIndex = slide / this._pageHeight;
|
|
274
|
+
if (addIndex > 0) {
|
|
275
|
+
addIndex = Math.ceil(addIndex);
|
|
276
|
+
}
|
|
277
|
+
else {
|
|
278
|
+
addIndex = Math.floor(addIndex);
|
|
279
|
+
}
|
|
280
|
+
this._currentIndex += addIndex;
|
|
281
|
+
}
|
|
282
|
+
this.slideTo(this._currentIndex);
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
}
|