lyb-pixi-js 1.0.22 → 1.1.0

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 (61) hide show
  1. package/README.md +484 -1
  2. package/dist/Components/Custom/LibPixiButtonHover/index.d.ts +32 -0
  3. package/dist/Components/Custom/LibPixiButtonHover/index.js +44 -0
  4. package/dist/Components/Custom/LibPixiCloseBtn/index.d.ts +14 -0
  5. package/dist/Components/Custom/LibPixiCloseBtn/index.js +35 -0
  6. package/dist/Components/Custom/LibPixiDrawer/index.d.ts +16 -0
  7. package/dist/Components/Custom/LibPixiDrawer/index.js +59 -0
  8. package/dist/Components/Custom/LibPixiPerforMon/index.d.ts +31 -0
  9. package/dist/Components/Custom/LibPixiPerforMon/index.js +107 -0
  10. package/dist/Components/Custom/LibPixiProgress/index.d.ts +29 -0
  11. package/dist/Components/Custom/LibPixiProgress/index.js +36 -0
  12. package/dist/Components/Custom/LibPixiScrollContainer/index.d.ts +57 -0
  13. package/dist/Components/Custom/LibPixiScrollContainer/index.js +166 -0
  14. package/dist/Components/Custom/LibPixiScrollNum/index.d.ts +62 -0
  15. package/dist/Components/Custom/LibPixiScrollNum/index.js +146 -0
  16. package/dist/Components/Custom/LibPixiSlider/index.d.ts +45 -0
  17. package/dist/Components/Custom/LibPixiSlider/index.js +111 -0
  18. package/dist/Components/Custom/LibPixiSubAddMinMax/index.d.ts +49 -0
  19. package/dist/Components/Custom/LibPixiSubAddMinMax/index.js +75 -0
  20. package/dist/Components/Custom/LibPixiTable/index.d.ts +52 -0
  21. package/dist/Components/Custom/LibPixiTable/index.js +70 -0
  22. package/dist/Utils/LibPixiAudio/index.d.ts +34 -0
  23. package/dist/Utils/LibPixiAudio/index.js +140 -0
  24. package/dist/Utils/LibPixiCreateNineGrid/index.d.ts +15 -0
  25. package/dist/Utils/LibPixiCreateNineGrid/index.js +19 -0
  26. package/dist/Utils/LibPixiEvent/index.d.ts +9 -0
  27. package/dist/Utils/LibPixiEvent/index.js +22 -0
  28. package/dist/Utils/LibPixiEventControlled/index.d.ts +8 -0
  29. package/dist/Utils/LibPixiEventControlled/index.js +21 -0
  30. package/dist/Utils/LibPixiFilter/index.d.ts +9 -0
  31. package/dist/Utils/LibPixiFilter/index.js +30 -0
  32. package/dist/Utils/LibPixiIntervalTrigger/index.d.ts +6 -0
  33. package/dist/Utils/LibPixiIntervalTrigger/index.js +33 -0
  34. package/dist/Utils/LibPixiOutsideClick/index.d.ts +8 -0
  35. package/dist/Utils/LibPixiOutsideClick/index.js +22 -0
  36. package/dist/Utils/LibPixiOverflowHidden/index.d.ts +6 -0
  37. package/dist/Utils/LibPixiOverflowHidden/index.js +14 -0
  38. package/dist/Utils/LibPixiPromiseTickerTimeout/index.d.ts +6 -0
  39. package/dist/Utils/LibPixiPromiseTickerTimeout/index.js +22 -0
  40. package/dist/Utils/LibPixiScaleContainer/index.d.ts +8 -0
  41. package/dist/Utils/LibPixiScaleContainer/index.js +14 -0
  42. package/dist/Utils/LibPixiShadow/index.d.ts +17 -0
  43. package/dist/Utils/LibPixiShadow/index.js +18 -0
  44. package/dist/Utils/LibPixiTickerTimeout/index.d.ts +6 -0
  45. package/dist/Utils/LibPixiTickerTimeout/index.js +28 -0
  46. package/dist/libPixiJs.d.ts +155 -25
  47. package/dist/libPixiJs.js +166 -25
  48. package/package.json +4 -2
  49. package/umd/lyb-pixi.js +222 -128
  50. /package/dist/{Base → Components/Base}/LibPixiBitText/index.d.ts +0 -0
  51. /package/dist/{Base → Components/Base}/LibPixiBitText/index.js +0 -0
  52. /package/dist/{Base → Components/Base}/LibPixiContainer/index.d.ts +0 -0
  53. /package/dist/{Base → Components/Base}/LibPixiContainer/index.js +0 -0
  54. /package/dist/{Base → Components/Base}/LibPixiParticleMove/index.d.ts +0 -0
  55. /package/dist/{Base → Components/Base}/LibPixiParticleMove/index.js +0 -0
  56. /package/dist/{Base → Components/Base}/LibPixiRectBgColor/index.d.ts +0 -0
  57. /package/dist/{Base → Components/Base}/LibPixiRectBgColor/index.js +0 -0
  58. /package/dist/{Base → Components/Base}/LibPixiSpine/index.d.ts +0 -0
  59. /package/dist/{Base → Components/Base}/LibPixiSpine/index.js +0 -0
  60. /package/dist/{Base → Components/Base}/LibPixiText/index.d.ts +0 -0
  61. /package/dist/{Base → Components/Base}/LibPixiText/index.js +0 -0
@@ -0,0 +1,31 @@
1
+ import { Application, Container } from "pixi.js";
2
+ /** @description 监视帧率、Draw Call、Max Draw Call
3
+ * @link 使用方法:https://www.npmjs.com/package/lyb-pixi-js#LibPixiPerforMon-性能监视器
4
+ */
5
+ export declare class LibPixiPerforMon extends Container {
6
+ /** 数据收集时间间隔 (5秒) */
7
+ private readonly COLLECT_TIME;
8
+ /** 当前时间 */
9
+ private _nowTime;
10
+ /** 上次更新的时间 */
11
+ private _lastTime;
12
+ /** 当前绘制调用次数 */
13
+ private _drawCount;
14
+ /** 最大绘制调用次数 */
15
+ private _maxDrawCount;
16
+ /** 临时最大绘制调用次数 */
17
+ private _tempMaxDrawCount;
18
+ /** 上次收集数据的时间 */
19
+ private _lastCollectTime;
20
+ /** 渲染器 */
21
+ private _renderer;
22
+ /** 存储每个性能指标的文本对象 */
23
+ private _paramTxts;
24
+ /** 原始的 drawElements 方法 */
25
+ private _drawElements;
26
+ constructor(app: Application);
27
+ /** @description 初始化显示性能数据 */
28
+ init(): void;
29
+ /** @description 更新文本信息 */
30
+ private _setTxtInfo;
31
+ }
@@ -0,0 +1,107 @@
1
+ import { Container, UPDATE_PRIORITY, Ticker, } from "pixi.js";
2
+ import { LibPixiText } from "../../Base/LibPixiText";
3
+ /** @description 监视帧率、Draw Call、Max Draw Call
4
+ * @link 使用方法:https://www.npmjs.com/package/lyb-pixi-js#LibPixiPerforMon-性能监视器
5
+ */
6
+ export class LibPixiPerforMon extends Container {
7
+ constructor(app) {
8
+ super();
9
+ /** 数据收集时间间隔 (5秒) */
10
+ this.COLLECT_TIME = 5 * 1000;
11
+ /** 当前时间 */
12
+ this._nowTime = 0;
13
+ /** 上次更新的时间 */
14
+ this._lastTime = 0;
15
+ /** 当前绘制调用次数 */
16
+ this._drawCount = 0;
17
+ /** 最大绘制调用次数 */
18
+ this._maxDrawCount = 0;
19
+ /** 临时最大绘制调用次数 */
20
+ this._tempMaxDrawCount = 0;
21
+ /** 上次收集数据的时间 */
22
+ this._lastCollectTime = 0;
23
+ /** 存储每个性能指标的文本对象 */
24
+ this._paramTxts = [];
25
+ for (let i = 0; i < 3; i++) {
26
+ const txt = new LibPixiText({
27
+ text: "",
28
+ fontWeight: "bold",
29
+ fontSize: 36,
30
+ shadow: ["#000", 45, 3, 5],
31
+ fontColor: "#fff",
32
+ });
33
+ this._paramTxts[i] = txt;
34
+ txt.x = 0;
35
+ txt.y = txt.height * i;
36
+ this.addChild(txt);
37
+ txt.alpha = 0.75;
38
+ }
39
+ this._renderer = app.renderer;
40
+ this._drawElements = this._renderer["gl"].drawElements;
41
+ this.init();
42
+ }
43
+ /** @description 初始化显示性能数据 */
44
+ init() {
45
+ this._renderer["gl"].drawElements = (...args) => {
46
+ this._drawElements.call(this._renderer["gl"], ...args);
47
+ this._drawCount++;
48
+ };
49
+ Ticker.shared.add(() => {
50
+ const fps = Ticker.system.FPS;
51
+ this._nowTime = performance.now();
52
+ if (this._nowTime - this._lastTime >= 100.0) {
53
+ this._setTxtInfo(0, Math.floor(fps).toFixed(0));
54
+ this._lastTime = this._nowTime;
55
+ }
56
+ if (this._nowTime - this._lastCollectTime < this.COLLECT_TIME) {
57
+ if (this._tempMaxDrawCount < this._drawCount) {
58
+ this._tempMaxDrawCount = this._drawCount;
59
+ }
60
+ }
61
+ else {
62
+ this._maxDrawCount = this._tempMaxDrawCount;
63
+ this._tempMaxDrawCount = 0;
64
+ this._lastCollectTime = this._nowTime;
65
+ }
66
+ this._setTxtInfo(1, this._drawCount);
67
+ this._setTxtInfo(2, this._maxDrawCount);
68
+ this._drawCount = 0;
69
+ }, UPDATE_PRIORITY.UTILITY);
70
+ }
71
+ /** @description 更新文本信息 */
72
+ _setTxtInfo(p, v) {
73
+ const fpsColor = (v) => {
74
+ this._paramTxts[p].style.fill = "#fff";
75
+ if (v <= 30) {
76
+ this._paramTxts[p].style.fill = "yellow";
77
+ }
78
+ if (v <= 20) {
79
+ this._paramTxts[p].style.fill = "red";
80
+ }
81
+ };
82
+ const drawCallColor = (v) => {
83
+ this._paramTxts[p].style.fill = "#fff";
84
+ if (v >= 75) {
85
+ this._paramTxts[p].style.fill = "yellow";
86
+ }
87
+ if (v >= 100) {
88
+ this._paramTxts[p].style.fill = "red";
89
+ }
90
+ };
91
+ const paramMapping = [
92
+ () => {
93
+ fpsColor(v);
94
+ return `Fps:${v}`;
95
+ },
96
+ () => {
97
+ drawCallColor(v);
98
+ return `Draw Call:${v}`;
99
+ },
100
+ () => {
101
+ drawCallColor(v);
102
+ return `Max Draw Call:${v}`;
103
+ },
104
+ ];
105
+ this._paramTxts[p].text = paramMapping[p]();
106
+ }
107
+ }
@@ -0,0 +1,29 @@
1
+ import { Container, type Texture } from "pixi.js";
2
+ export interface LibPixiProgressParams {
3
+ /** 背景宽度 */
4
+ bgWidth: number;
5
+ /** 背景高度 */
6
+ bgHeight: number;
7
+ /** 进度条宽度 */
8
+ barWidth: number;
9
+ /** 进度条高度 */
10
+ barHeight: number;
11
+ /** 背景纹理 */
12
+ bgTexture: Texture;
13
+ /** 进度条纹理 */
14
+ barTexture: Texture;
15
+ }
16
+ /** @description 通过裁剪的方式显示进度条
17
+ * @link 使用方法:https://www.npmjs.com/package/lyb-pixi-js#LibPixiProgress-进度条
18
+ */
19
+ export declare class LibPixiProgress extends Container {
20
+ /** 光条图 */
21
+ private _progressBar;
22
+ /** 蒙版 */
23
+ private _maskGraphics;
24
+ constructor(params: LibPixiProgressParams);
25
+ /** @description 更新进度
26
+ * @param progress 进度值,范围从0到1
27
+ */
28
+ setProgress(progress: number): void;
29
+ }
@@ -0,0 +1,36 @@
1
+ import { Container, Graphics, Sprite } from "pixi.js";
2
+ /** @description 通过裁剪的方式显示进度条
3
+ * @link 使用方法:https://www.npmjs.com/package/lyb-pixi-js#LibPixiProgress-进度条
4
+ */
5
+ export class LibPixiProgress extends Container {
6
+ constructor(params) {
7
+ super();
8
+ const { bgWidth, bgHeight, barWidth, barHeight, bgTexture, barTexture } = params;
9
+ // 背景图
10
+ const background = new Sprite(bgTexture);
11
+ this.addChild(background);
12
+ // 光条图
13
+ this._progressBar = new Sprite(barTexture);
14
+ this.addChild(this._progressBar);
15
+ this._progressBar.x = (bgWidth - barWidth) / 2;
16
+ this._progressBar.y = (bgHeight - barHeight) / 2;
17
+ // 创建蒙版
18
+ const mask = new Graphics();
19
+ mask.beginFill(0xffffff);
20
+ mask.drawRect(0, 0, 0, this._progressBar.height);
21
+ mask.endFill();
22
+ this._progressBar.addChild(mask);
23
+ this._progressBar.mask = mask;
24
+ this._maskGraphics = mask;
25
+ }
26
+ /** @description 更新进度
27
+ * @param progress 进度值,范围从0到1
28
+ */
29
+ setProgress(progress) {
30
+ const clampedProgress = Math.max(0, Math.min(1, progress));
31
+ this._maskGraphics.clear();
32
+ this._maskGraphics.beginFill(0xffffff);
33
+ this._maskGraphics.drawRect(0, 0, this._progressBar.width * clampedProgress, this._progressBar.height);
34
+ this._maskGraphics.endFill();
35
+ }
36
+ }
@@ -0,0 +1,57 @@
1
+ import { Container } from "pixi.js";
2
+ import { LibPixiContainer } from "../../Base/LibPixiContainer";
3
+ export interface LibPixiScrollContainerParams {
4
+ /** 宽度 */
5
+ width: number;
6
+ /** 高度 */
7
+ height: number;
8
+ /** 滚动内容 */
9
+ scrollContent: Container;
10
+ /** 底部内边距 */
11
+ bottomMargin?: number;
12
+ }
13
+ /** @description 支持鼠标滚轮滚动、鼠标拖动、手指滑动,支持惯性滚动及回弹
14
+ * @link 使用方法:https://www.npmjs.com/package/lyb-pixi-js#LibPixiScrollContainer-滚动容器
15
+ */
16
+ export declare class LibPixiScrollContainer extends LibPixiContainer {
17
+ /** 开始位置 */
18
+ private _startY;
19
+ /** 惯性速度 */
20
+ private _velocity;
21
+ /** 上一次滚动时间 */
22
+ private _startTime;
23
+ /** 开始位置 */
24
+ private _startPosition;
25
+ /** 滚动速度 */
26
+ private _scrollSpeed;
27
+ /** 是否处于拖动状态 */
28
+ private _isDragging;
29
+ /** 滚动容器 */
30
+ _scrollContent: Container;
31
+ /** 遮罩 */
32
+ private _maskGraphics;
33
+ /** 滚动的内容 */
34
+ private _content;
35
+ constructor(params: LibPixiScrollContainerParams);
36
+ /** @description 设置滚动容器可视区宽高
37
+ * @param width 宽度
38
+ * @param height 高度
39
+ */
40
+ setDimensions(width: number, height: number): void;
41
+ /** @description 返回顶部 */
42
+ scrollToTop(): void;
43
+ /** @description 往滚动内容添加元素 */
44
+ addContent(container: Container): void;
45
+ /** @description 按下 */
46
+ private _onDragStart;
47
+ /** @description 拖动 */
48
+ private _onDragMove;
49
+ /** @description 拖动结束 */
50
+ private _onDragEnd;
51
+ /** @description 滚轮滚动 */
52
+ private _onWheelScroll;
53
+ /** @description 惯性动画 */
54
+ private _applyInertia;
55
+ /** @description 限制滚动范围 */
56
+ private _limitScrollRange;
57
+ }
@@ -0,0 +1,166 @@
1
+ import { Container, Graphics, Sprite, } from "pixi.js";
2
+ import { gsap } from "gsap";
3
+ import { LibPixiContainer } from "../../Base/LibPixiContainer";
4
+ /** @description 支持鼠标滚轮滚动、鼠标拖动、手指滑动,支持惯性滚动及回弹
5
+ * @link 使用方法:https://www.npmjs.com/package/lyb-pixi-js#LibPixiScrollContainer-滚动容器
6
+ */
7
+ export class LibPixiScrollContainer extends LibPixiContainer {
8
+ constructor(params) {
9
+ const { width, height, scrollContent, bottomMargin = 50 } = params;
10
+ super(width, height);
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
+ this._scrollContent = scrollContent;
24
+ // 创建内容容器
25
+ this._content = new Container();
26
+ this.addChild(this._content);
27
+ this._content.addChild(this._scrollContent);
28
+ // 创建底部占位
29
+ if (bottomMargin > 0) {
30
+ const bottom_box = new Sprite();
31
+ this._content.addChild(bottom_box);
32
+ bottom_box.y = this._content.height + bottomMargin;
33
+ }
34
+ // 创建遮罩
35
+ this._maskGraphics = new Graphics();
36
+ this.addChild(this._maskGraphics);
37
+ this._maskGraphics.clear();
38
+ this._maskGraphics.beginFill(0x000000);
39
+ this._maskGraphics.drawRect(0, 0, width, height);
40
+ this._maskGraphics.endFill();
41
+ this.mask = this._maskGraphics;
42
+ // 添加事件监听
43
+ this.eventMode = "static";
44
+ this.on("pointerdown", this._onDragStart, this);
45
+ this.on("pointermove", this._onDragMove, this);
46
+ this.on("pointerup", this._onDragEnd, this);
47
+ this.on("pointerupoutside", this._onDragEnd, this);
48
+ this.on("wheel", this._onWheelScroll, this);
49
+ }
50
+ /** @description 设置滚动容器可视区宽高
51
+ * @param width 宽度
52
+ * @param height 高度
53
+ */
54
+ setDimensions(width, height) {
55
+ // 更新遮罩尺寸
56
+ this._maskGraphics.clear();
57
+ this._maskGraphics.beginFill(0x000000);
58
+ this._maskGraphics.drawRect(0, 0, width, height);
59
+ this._maskGraphics.endFill();
60
+ this.setSize(width, height);
61
+ }
62
+ /** @description 返回顶部 */
63
+ scrollToTop() {
64
+ this._content.y = 0;
65
+ }
66
+ /** @description 往滚动内容添加元素 */
67
+ addContent(container) {
68
+ this._scrollContent.addChild(container);
69
+ }
70
+ /** @description 按下 */
71
+ _onDragStart(event) {
72
+ if (this._content.height <= this._maskGraphics.height)
73
+ return;
74
+ const position = event.getLocalPosition(this);
75
+ this._startY = position.y - this._content.y;
76
+ this._isDragging = true;
77
+ this._velocity = 0;
78
+ this._startTime = Date.now();
79
+ this._startPosition = this._content.y;
80
+ gsap.killTweensOf(this._content);
81
+ }
82
+ /** @description 拖动 */
83
+ _onDragMove(event) {
84
+ if (this._isDragging) {
85
+ const position = event.data.getLocalPosition(this);
86
+ const newPosition = position.y - this._startY;
87
+ this._content.y = newPosition;
88
+ }
89
+ }
90
+ /** @description 拖动结束 */
91
+ _onDragEnd() {
92
+ this._isDragging = false;
93
+ const currentTime = Date.now();
94
+ const deltaTime = currentTime - this._startTime; // 计算停留时间
95
+ if (deltaTime < 250) {
96
+ // 如果停留时间在阈值内,计算惯性速度
97
+ this._velocity = (this._content.y - this._startPosition) / deltaTime;
98
+ this._applyInertia();
99
+ }
100
+ else {
101
+ // 停留时间超出阈值,取消惯性
102
+ this._velocity = 0;
103
+ }
104
+ this._limitScrollRange();
105
+ }
106
+ /** @description 滚轮滚动 */
107
+ _onWheelScroll(event) {
108
+ // 如果内容高度小于遮罩高度,则不滚动
109
+ if (this._content.height <= this._maskGraphics.height)
110
+ return;
111
+ let y = this._content.y - event.deltaY * (this._scrollSpeed / 100);
112
+ //如果到达顶部,则不滚动
113
+ if (y > 0) {
114
+ y = 0;
115
+ }
116
+ //如果到达底部,则不滚动
117
+ else if (Math.abs(y) >= this._content.height - this._maskGraphics.height) {
118
+ y = -(this._content.height - this._maskGraphics.height);
119
+ }
120
+ gsap.to(this._content, {
121
+ duration: 0.25,
122
+ ease: "power1.out",
123
+ y,
124
+ });
125
+ }
126
+ /** @description 惯性动画 */
127
+ _applyInertia() {
128
+ gsap.to(this._content, {
129
+ y: this._content.y + this._velocity * 250,
130
+ duration: 0.5,
131
+ ease: "power1.out",
132
+ onUpdate: this._limitScrollRange.bind(this),
133
+ });
134
+ }
135
+ /** @description 限制滚动范围 */
136
+ _limitScrollRange() {
137
+ //如果内容顶部离开了滚动容器顶部,则归位
138
+ if (this._content.y > 0) {
139
+ gsap.to(this._content, {
140
+ duration: 0.75,
141
+ y: 0,
142
+ ease: "elastic.out",
143
+ });
144
+ }
145
+ // 如果滚动距离大于内容高度减去遮罩高度
146
+ else if (Math.abs(this._content.y) >=
147
+ this._content.height - this._maskGraphics.height) {
148
+ // 如果内容高度大于遮罩高度,则滚动到底部
149
+ if (this._content.height > this._maskGraphics.height) {
150
+ const y = -(this._content.height - this._maskGraphics.height);
151
+ gsap.to(this._content, {
152
+ duration: 0.75,
153
+ y,
154
+ ease: "elastic.out",
155
+ });
156
+ }
157
+ // 否则静止不动
158
+ else {
159
+ gsap.to(this._content, {
160
+ duration: 0.25,
161
+ y: 0,
162
+ });
163
+ }
164
+ }
165
+ }
166
+ }
@@ -0,0 +1,62 @@
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
+ * @param animate 是否需要过渡动画
54
+ */
55
+ slideTo(index: number, animate?: boolean): void;
56
+ /** @description 开始拖动 */
57
+ private _onDragStart;
58
+ /** @description 拖动中 */
59
+ private _onDragMove;
60
+ /** @description 结束拖动 */
61
+ private _onDragEnd;
62
+ }
@@ -0,0 +1,146 @@
1
+ import { Graphics } from "pixi.js";
2
+ import gsap from "gsap";
3
+ import { LibPixiContainer } from "../../Base/LibPixiContainer";
4
+ /** @description 通过鼠标或手指拖动数字列选择数字
5
+ * @link 使用方法:https://www.npmjs.com/package/lyb-pixi-js#LibPixiScrollNum-数字滑动
6
+ */
7
+ export class LibPixiScrollNum extends LibPixiContainer {
8
+ constructor(params) {
9
+ const { width, height, content, slideCallback, scrollCallback, pageNum, pageHeight, } = params;
10
+ super(width, height);
11
+ /** 当前幻灯片索引 */
12
+ this._currentIndex = 0;
13
+ /** 滚动区域高度 */
14
+ this._scrollHeight = 0;
15
+ /** 滑动区域高度 */
16
+ this._slideHeight = 0;
17
+ /** 记录拖动开始时的Y坐标 */
18
+ this._startY = 0;
19
+ /** 偏移量 */
20
+ this._offsetY = 0;
21
+ /** 最大索引 */
22
+ this._pageNum = 0;
23
+ /** 记录开始时间 */
24
+ this._startTime = new Date().getTime();
25
+ /** 是否正在拖动 */
26
+ this._isDragging = false;
27
+ //设置遮罩
28
+ const mask = new Graphics();
29
+ mask.beginFill(0xffffff);
30
+ mask.drawRect(0, 0, this.width, this.height);
31
+ mask.endFill();
32
+ this.addChild(mask);
33
+ this.mask = mask;
34
+ this._scrollHeight = height;
35
+ this._slideHeight = pageHeight;
36
+ this._slideArea = content;
37
+ this._slideCallback = slideCallback;
38
+ this._scrollCallback = scrollCallback;
39
+ this._pageNum = pageNum - 1;
40
+ this.addChild(this._slideArea);
41
+ this._slideArea.x = width / 2;
42
+ this._slideArea.y = this._scrollHeight / 2;
43
+ // 监听拖动事件
44
+ this.eventMode = "static";
45
+ this.cursor = "pointer";
46
+ this.on("pointerdown", this._onDragStart);
47
+ window.addEventListener("pointermove", this._onDragMove.bind(this));
48
+ window.addEventListener("pointerup", this._onDragEnd.bind(this));
49
+ }
50
+ /** @description 更新坐标
51
+ * @param y Y坐标
52
+ * @param index 页数索引
53
+ */
54
+ updatePosition(y, index) {
55
+ this._slideArea.y = y;
56
+ this._currentIndex = index;
57
+ }
58
+ /** @description 滑动到指定索引
59
+ * @param index 页数索引
60
+ * @param animate 是否需要过渡动画
61
+ */
62
+ slideTo(index, animate = true) {
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: animate ? 0.25 : 0.01,
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
+ _onDragStart(event) {
104
+ this._isDragging = true;
105
+ this._startY = event.data.global.y;
106
+ this._offsetY = this._slideArea.y;
107
+ gsap.killTweensOf(this._slideArea);
108
+ this._startTime = new Date().getTime();
109
+ }
110
+ /** @description 拖动中 */
111
+ _onDragMove(event) {
112
+ var _a;
113
+ if (!this._isDragging)
114
+ return;
115
+ const moveY = event.pageY - this._startY;
116
+ this._slideArea.y = this._offsetY + moveY;
117
+ (_a = this._scrollCallback) === null || _a === void 0 ? void 0 : _a.call(this, this._slideArea.y, this._currentIndex);
118
+ }
119
+ /** @description 结束拖动 */
120
+ _onDragEnd(event) {
121
+ if (!this._isDragging)
122
+ return;
123
+ this._isDragging = false;
124
+ const endTime = new Date().getTime() - this._startTime;
125
+ const slide = this._startY - event.pageY; // 计算滑动的距离
126
+ const slideSpeed = Math.abs(slide) / endTime; // 计算滑动速度
127
+ const speedThreshold = 0.275;
128
+ // 计算滑动的页面变化数,根据滑动距离来调整页码
129
+ const slideThreshold = this._slideHeight / 2;
130
+ // 计算实际的翻页增量,使用 `slide / this._slideHeight` 来计算滑动的页数
131
+ const pageChange = Math.round(slide / this._slideHeight);
132
+ // 如果滑动速度足够快,且滑动的距离大于阈值,强制翻页
133
+ if (Math.abs(slide) > slideThreshold || slideSpeed > speedThreshold) {
134
+ this._currentIndex += pageChange; // 这里会根据滑动的方向来增加或减少当前页码
135
+ }
136
+ // 防止超出页面的上下限
137
+ if (this._currentIndex < 0) {
138
+ this._currentIndex = 0; // 保证当前页码不小于 0
139
+ }
140
+ else if (this._currentIndex > this._pageNum) {
141
+ this._currentIndex = this._pageNum; // 保证当前页码不大于最大页码
142
+ }
143
+ // 执行滑动到目标页码
144
+ this.slideTo(this._currentIndex);
145
+ }
146
+ }
@@ -0,0 +1,45 @@
1
+ import { Container } from "pixi.js";
2
+ import { LibPixiContainer } from "../../Base/LibPixiContainer";
3
+ /** @description 类似轮播图,但是不会自动轮播
4
+ * @link 使用方法:https://www.npmjs.com/package/lyb-pixi-js#LibPixiSlider-横向滑动图
5
+ */
6
+ export declare class LibPixiSlider extends LibPixiContainer {
7
+ /** 当前幻灯片索引 */
8
+ private _currentIndex;
9
+ /** 滑动区域宽度 */
10
+ private _slideWidth;
11
+ /** 记录拖动开始时的X坐标 */
12
+ private _startX;
13
+ /** 偏移量 */
14
+ private _offsetX;
15
+ /** 最大索引 */
16
+ private _pageNum;
17
+ /** 记录开始时间 */
18
+ private _startTime;
19
+ private _isDragging;
20
+ /** 滑动内容 */
21
+ private _slideArea;
22
+ /** @description 滑动回调 */
23
+ private slideCallback;
24
+ /**
25
+ * @param width 宽度
26
+ * @param height 高度
27
+ * @param content 内容
28
+ * @param slideCallback 滑动结束回调
29
+ */
30
+ constructor(width: number, height: number, content: Container, slideCallback: (pageIndex: number, _pageNum: number) => void);
31
+ /** @description 上一页 */
32
+ prev(): void;
33
+ /** @description 下一页 */
34
+ next(): void;
35
+ /** @description 滑动到指定索引
36
+ * @param index 索引
37
+ */
38
+ private _slideTo;
39
+ /** @description 开始拖动 */
40
+ private _onDragStart;
41
+ /** @description 拖动中 */
42
+ private _onDragMove;
43
+ /** @description 结束拖动 */
44
+ private _onDragEnd;
45
+ }