lyb-pixi-js 1.12.33 → 1.12.34
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/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 +38 -0
- package/Utils/LibPixiDialogManager/ui/LibPixiDialog.js +133 -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 -2
- package/index.js +0 -5
- package/lyb-pixi.js +0 -58890
|
@@ -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
|
+
}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { Container } from "pixi.js";
|
|
2
|
+
import { LibPixiContainer } from "../Base/LibPixiContainer";
|
|
3
|
+
interface LibPixiSliderParams {
|
|
4
|
+
/** 滑动区域宽度 */
|
|
5
|
+
width: number;
|
|
6
|
+
/** 滑动区域高度 */
|
|
7
|
+
height: number;
|
|
8
|
+
/** 滑动页列表 */
|
|
9
|
+
slideList: Container[];
|
|
10
|
+
/** 是否启用循环滑动 */
|
|
11
|
+
loop?: boolean;
|
|
12
|
+
/** 是否启用景深 */
|
|
13
|
+
enableDepth?: boolean;
|
|
14
|
+
/** 景深透明度 */
|
|
15
|
+
depthAlpha?: number;
|
|
16
|
+
/** 景深缩放 */
|
|
17
|
+
depthScale?: number;
|
|
18
|
+
/** 滑动回调 */
|
|
19
|
+
slideCallback: (pageIndex: number, _pageNum: number) => void;
|
|
20
|
+
}
|
|
21
|
+
/** @description 类似轮播图,但是不会自动轮播
|
|
22
|
+
* @link 使用方法:https://www.npmjs.com/package/lyb-pixi-js#LibPixiSlider-横向滑动图
|
|
23
|
+
*/
|
|
24
|
+
export declare class LibPixiSlider extends LibPixiContainer {
|
|
25
|
+
/** 当前幻灯片索引 */
|
|
26
|
+
private _currentIndex;
|
|
27
|
+
/** 滑动区域宽度 */
|
|
28
|
+
private _slideWidth;
|
|
29
|
+
/** 滑动区域高度 */
|
|
30
|
+
private _slideHeight;
|
|
31
|
+
/** 是否启用循环 */
|
|
32
|
+
private _loop;
|
|
33
|
+
/** 记录拖动开始时的X坐标 */
|
|
34
|
+
private _startX;
|
|
35
|
+
/** 偏移量 */
|
|
36
|
+
private _offsetX;
|
|
37
|
+
/** 最大索引 */
|
|
38
|
+
private _pageNum;
|
|
39
|
+
/** 记录开始时间 */
|
|
40
|
+
private _startTime;
|
|
41
|
+
private _isDragging;
|
|
42
|
+
/** 滑动内容 */
|
|
43
|
+
private _slideArea;
|
|
44
|
+
/** 是否启用景深 */
|
|
45
|
+
private _enableDepth;
|
|
46
|
+
/** 景深透明度 */
|
|
47
|
+
private _depthAlpha;
|
|
48
|
+
/** 景深缩放 */
|
|
49
|
+
private _depthScale;
|
|
50
|
+
/** 滑动容器列表 */
|
|
51
|
+
private _slideList;
|
|
52
|
+
/** @description 滑动回调 */
|
|
53
|
+
private slideCallback;
|
|
54
|
+
/**
|
|
55
|
+
* @param width 宽度
|
|
56
|
+
* @param height 高度
|
|
57
|
+
* @param content 内容
|
|
58
|
+
* @param slideCallback 滑动结束回调
|
|
59
|
+
*/
|
|
60
|
+
constructor(params: LibPixiSliderParams);
|
|
61
|
+
/** @description 上一页 */
|
|
62
|
+
prev(): void;
|
|
63
|
+
/** @description 下一页 */
|
|
64
|
+
next(): void;
|
|
65
|
+
/** @description 滑动到指定索引
|
|
66
|
+
* @param index 索引
|
|
67
|
+
*/
|
|
68
|
+
private _slideTo;
|
|
69
|
+
/** @description 开始拖动 */
|
|
70
|
+
private _onDragStart;
|
|
71
|
+
/** @description 拖动中 */
|
|
72
|
+
private _onDragMove;
|
|
73
|
+
/** @description 结束拖动 */
|
|
74
|
+
private _onDragEnd;
|
|
75
|
+
/** @description 设置滚动景深
|
|
76
|
+
* @param containerList 元素列表
|
|
77
|
+
* @param y 拖动Y坐标
|
|
78
|
+
* @param startY 内部将y - startY进行计算
|
|
79
|
+
*/
|
|
80
|
+
private _setDepth;
|
|
81
|
+
}
|
|
82
|
+
export {};
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
import { Container } from "pixi.js";
|
|
2
|
+
import gsap from "gsap";
|
|
3
|
+
import { LibJsLerp } from "lyb-js/Math/LibJsLerp.js";
|
|
4
|
+
import { libPixiOverflowHidden } from "../../Utils/LibPixiOverflowHidden";
|
|
5
|
+
import { LibPixiContainer } from "../Base/LibPixiContainer";
|
|
6
|
+
import { libPixiEvent } from "../../Utils/LibPixiEvent";
|
|
7
|
+
/** @description 类似轮播图,但是不会自动轮播
|
|
8
|
+
* @link 使用方法:https://www.npmjs.com/package/lyb-pixi-js#LibPixiSlider-横向滑动图
|
|
9
|
+
*/
|
|
10
|
+
export class LibPixiSlider extends LibPixiContainer {
|
|
11
|
+
/**
|
|
12
|
+
* @param width 宽度
|
|
13
|
+
* @param height 高度
|
|
14
|
+
* @param content 内容
|
|
15
|
+
* @param slideCallback 滑动结束回调
|
|
16
|
+
*/
|
|
17
|
+
constructor(params) {
|
|
18
|
+
const { width, height, slideList, slideCallback, loop = false, enableDepth = false, depthAlpha = 0.5, depthScale = 0.5, } = params;
|
|
19
|
+
super(width, height);
|
|
20
|
+
/** 当前幻灯片索引 */
|
|
21
|
+
this._currentIndex = 0;
|
|
22
|
+
/** 滑动区域宽度 */
|
|
23
|
+
this._slideWidth = 0;
|
|
24
|
+
/** 滑动区域高度 */
|
|
25
|
+
this._slideHeight = 0;
|
|
26
|
+
/** 是否启用循环 */
|
|
27
|
+
this._loop = false;
|
|
28
|
+
/** 记录拖动开始时的X坐标 */
|
|
29
|
+
this._startX = 0;
|
|
30
|
+
/** 偏移量 */
|
|
31
|
+
this._offsetX = 0;
|
|
32
|
+
/** 最大索引 */
|
|
33
|
+
this._pageNum = 0;
|
|
34
|
+
/** 记录开始时间 */
|
|
35
|
+
this._startTime = new Date().getTime();
|
|
36
|
+
/* 是否正在拖动 */
|
|
37
|
+
this._isDragging = false;
|
|
38
|
+
libPixiOverflowHidden(this);
|
|
39
|
+
this._slideArea = new Container();
|
|
40
|
+
this._slideWidth = width;
|
|
41
|
+
this._slideHeight = height;
|
|
42
|
+
this._loop = loop;
|
|
43
|
+
this._slideList = slideList;
|
|
44
|
+
this._enableDepth = enableDepth;
|
|
45
|
+
this._depthAlpha = depthAlpha;
|
|
46
|
+
this._depthScale = depthScale;
|
|
47
|
+
this.slideCallback = slideCallback;
|
|
48
|
+
this._pageNum = slideList.length - 1;
|
|
49
|
+
this._slideList.forEach((item, index) => {
|
|
50
|
+
this._slideArea.addChild(item);
|
|
51
|
+
item.x = index * width + this._slideWidth / 2;
|
|
52
|
+
item.y = this._slideHeight / 2;
|
|
53
|
+
item.pivot.set(this._slideWidth / 2, this._slideHeight / 2);
|
|
54
|
+
});
|
|
55
|
+
this.addChild(this._slideArea);
|
|
56
|
+
libPixiEvent(this, "pointerdown", this._onDragStart.bind(this));
|
|
57
|
+
window.addEventListener("pointermove", this._onDragMove.bind(this));
|
|
58
|
+
window.addEventListener("pointerup", this._onDragEnd.bind(this));
|
|
59
|
+
}
|
|
60
|
+
/** @description 上一页 */
|
|
61
|
+
prev() {
|
|
62
|
+
this._slideTo(this._currentIndex - 1);
|
|
63
|
+
}
|
|
64
|
+
/** @description 下一页 */
|
|
65
|
+
next() {
|
|
66
|
+
this._slideTo(this._currentIndex + 1);
|
|
67
|
+
}
|
|
68
|
+
/** @description 滑动到指定索引
|
|
69
|
+
* @param index 索引
|
|
70
|
+
*/
|
|
71
|
+
_slideTo(index) {
|
|
72
|
+
let x = 0;
|
|
73
|
+
if (this._loop) {
|
|
74
|
+
this._currentIndex =
|
|
75
|
+
(index + this._slideList.length) % this._slideList.length;
|
|
76
|
+
x = -this._currentIndex * this._slideWidth;
|
|
77
|
+
}
|
|
78
|
+
else {
|
|
79
|
+
if (index < 0) {
|
|
80
|
+
// 回弹到第一张
|
|
81
|
+
x = 0;
|
|
82
|
+
this._currentIndex = 0;
|
|
83
|
+
}
|
|
84
|
+
else if (index > this._pageNum) {
|
|
85
|
+
// 回弹到最后一张
|
|
86
|
+
x = -this._pageNum * this._slideWidth;
|
|
87
|
+
this._currentIndex = this._pageNum;
|
|
88
|
+
}
|
|
89
|
+
else {
|
|
90
|
+
// 正常滑动
|
|
91
|
+
x = -index * this._slideWidth;
|
|
92
|
+
this._currentIndex = index;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
gsap.to(this._slideArea, {
|
|
96
|
+
x,
|
|
97
|
+
duration: 0.25,
|
|
98
|
+
onUpdate: () => {
|
|
99
|
+
this._setDepth();
|
|
100
|
+
},
|
|
101
|
+
});
|
|
102
|
+
this.slideCallback(this._currentIndex, this._pageNum);
|
|
103
|
+
}
|
|
104
|
+
/** @description 开始拖动 */
|
|
105
|
+
_onDragStart(event) {
|
|
106
|
+
this._isDragging = true;
|
|
107
|
+
this._startX = event.global.x;
|
|
108
|
+
this._offsetX = this._slideArea.x;
|
|
109
|
+
gsap.killTweensOf(this._slideArea);
|
|
110
|
+
this._startTime = new Date().getTime();
|
|
111
|
+
}
|
|
112
|
+
/** @description 拖动中 */
|
|
113
|
+
_onDragMove(event) {
|
|
114
|
+
if (!this._isDragging)
|
|
115
|
+
return;
|
|
116
|
+
const moveX = event.pageX - this._startX;
|
|
117
|
+
this._slideArea.x = this._offsetX + moveX;
|
|
118
|
+
this._setDepth();
|
|
119
|
+
}
|
|
120
|
+
/** @description 结束拖动 */
|
|
121
|
+
_onDragEnd(event) {
|
|
122
|
+
if (!this._isDragging)
|
|
123
|
+
return;
|
|
124
|
+
this._isDragging = false;
|
|
125
|
+
const endTime = new Date().getTime() - this._startTime;
|
|
126
|
+
const slide = this._startX - event.pageX;
|
|
127
|
+
const slideSpeed = Math.abs(slide) / endTime;
|
|
128
|
+
//滑动距离阈值,滑动到一半以上必定翻页
|
|
129
|
+
const slideThreshold = this._slideWidth / 2;
|
|
130
|
+
//滑动速度阈值,滑动速度大于这个值,必定翻页
|
|
131
|
+
const speedThreshold = 0.275;
|
|
132
|
+
//如果滑动距离大于阈值,或速度大于阈值翻页
|
|
133
|
+
if (Math.abs(slide) > slideThreshold || slideSpeed > speedThreshold) {
|
|
134
|
+
slide > 0 ? this._currentIndex++ : this._currentIndex--;
|
|
135
|
+
}
|
|
136
|
+
this._slideTo(this._currentIndex);
|
|
137
|
+
}
|
|
138
|
+
/** @description 设置滚动景深
|
|
139
|
+
* @param containerList 元素列表
|
|
140
|
+
* @param y 拖动Y坐标
|
|
141
|
+
* @param startY 内部将y - startY进行计算
|
|
142
|
+
*/
|
|
143
|
+
_setDepth() {
|
|
144
|
+
if (!this._enableDepth)
|
|
145
|
+
return;
|
|
146
|
+
const Y = this._slideArea.x;
|
|
147
|
+
const idx = Math.floor(Math.abs(Y) / this._slideWidth);
|
|
148
|
+
const t = (Math.abs(Y) % this._slideWidth) / this._slideWidth;
|
|
149
|
+
const prevIdx = idx - 1;
|
|
150
|
+
const nextIdx = idx + 1;
|
|
151
|
+
const curItem = this._slideList[idx];
|
|
152
|
+
curItem.alpha = LibJsLerp(this._depthAlpha, 1, 1 - t);
|
|
153
|
+
curItem.scale.set(LibJsLerp(this._depthScale, 1, 1 - t));
|
|
154
|
+
if (nextIdx < this._slideList.length) {
|
|
155
|
+
const nextItem = this._slideList[nextIdx];
|
|
156
|
+
nextItem.alpha = LibJsLerp(this._depthAlpha, 1, t);
|
|
157
|
+
nextItem.scale.set(LibJsLerp(this._depthScale, 1, t));
|
|
158
|
+
}
|
|
159
|
+
if (prevIdx >= 0) {
|
|
160
|
+
const prevItem = this._slideList[prevIdx];
|
|
161
|
+
prevItem.alpha = LibJsLerp(this._depthAlpha, 1, 1 - t);
|
|
162
|
+
prevItem.scale.set(LibJsLerp(this._depthScale, 1, 1 - t));
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/** @description 表格绘制并填入数字 */
|
|
2
|
+
import { Container } from "pixi.js";
|
|
3
|
+
export interface LibPixiTableParams {
|
|
4
|
+
/** 表格数据 */
|
|
5
|
+
data: (number | string)[][];
|
|
6
|
+
/** 是否需要表格外框 */
|
|
7
|
+
outsideBorder?: boolean;
|
|
8
|
+
/** 单元格宽度 */
|
|
9
|
+
cellWidth?: number;
|
|
10
|
+
/** 单元格高度 */
|
|
11
|
+
cellHeight?: number;
|
|
12
|
+
/** 字体大小 */
|
|
13
|
+
fontSize?: number;
|
|
14
|
+
/** 字体颜色 */
|
|
15
|
+
fontColor?: string;
|
|
16
|
+
/** 表格第一列字体颜色 */
|
|
17
|
+
firstColumnFontColor?: string;
|
|
18
|
+
/** 是否需要加粗 */
|
|
19
|
+
fontBold?: boolean;
|
|
20
|
+
/** 线条厚度 */
|
|
21
|
+
lineWidth?: number;
|
|
22
|
+
/** 线条颜色 */
|
|
23
|
+
lineColor?: string;
|
|
24
|
+
}
|
|
25
|
+
/** @description 绘制表格并填充数字
|
|
26
|
+
* @link 使用方法:https://www.npmjs.com/package/lyb-pixi-js#LibPixiTable-数字表格
|
|
27
|
+
*/
|
|
28
|
+
export declare class LibPixiTable extends Container {
|
|
29
|
+
/** 行数 */
|
|
30
|
+
private _rows;
|
|
31
|
+
/** 列数 */
|
|
32
|
+
private _cols;
|
|
33
|
+
/** 单元格宽度 */
|
|
34
|
+
private _cellWidth;
|
|
35
|
+
/** 单元格高度 */
|
|
36
|
+
private _cellHeight;
|
|
37
|
+
/** 字体大小 */
|
|
38
|
+
private _fontSize;
|
|
39
|
+
/** 线条宽度 */
|
|
40
|
+
private _lineWidth;
|
|
41
|
+
/** 字体颜色 */
|
|
42
|
+
private _fontColor;
|
|
43
|
+
/** 表格第一列字体颜色 */
|
|
44
|
+
private _firstColumnFontColor;
|
|
45
|
+
/** 线条颜色 */
|
|
46
|
+
private _lineColor;
|
|
47
|
+
/** 是否需要表格外框 */
|
|
48
|
+
private _outsideBorder;
|
|
49
|
+
/** 是否需要加粗 */
|
|
50
|
+
private _fontBold;
|
|
51
|
+
/** 二维数字数组 */
|
|
52
|
+
private _data;
|
|
53
|
+
constructor(params: LibPixiTableParams);
|
|
54
|
+
/** @description 绘制表格 */
|
|
55
|
+
private _drawTable;
|
|
56
|
+
/** @description 填充数字 */
|
|
57
|
+
private fillNumbers;
|
|
58
|
+
/** @description 创建数字文本
|
|
59
|
+
* @param number 数字
|
|
60
|
+
* @param col 列索引
|
|
61
|
+
* @param row 行索引
|
|
62
|
+
*/
|
|
63
|
+
private _createNumberText;
|
|
64
|
+
}
|