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.
Files changed (129) hide show
  1. package/Components/Base/LibPixiArc.d.ts +16 -0
  2. package/Components/Base/LibPixiArc.js +14 -0
  3. package/Components/Base/LibPixiBitText.d.ts +20 -0
  4. package/Components/Base/LibPixiBitText.js +26 -0
  5. package/Components/Base/LibPixiCircular.d.ts +7 -0
  6. package/Components/Base/LibPixiCircular.js +12 -0
  7. package/Components/Base/LibPixiContainer.d.ts +22 -0
  8. package/Components/Base/LibPixiContainer.js +51 -0
  9. package/Components/Base/LibPixiHtmlText.d.ts +31 -0
  10. package/Components/Base/LibPixiHtmlText.js +30 -0
  11. package/Components/Base/LibPixiOval.d.ts +5 -0
  12. package/Components/Base/LibPixiOval.js +10 -0
  13. package/Components/Base/LibPixiParticleMove.d.ts +101 -0
  14. package/Components/Base/LibPixiParticleMove.js +136 -0
  15. package/Components/Base/LibPixiPolygon.d.ts +7 -0
  16. package/Components/Base/LibPixiPolygon.js +15 -0
  17. package/Components/Base/LibPixiRectBgColor.d.ts +41 -0
  18. package/Components/Base/LibPixiRectBgColor.js +95 -0
  19. package/Components/Base/LibPixiRectangle.d.ts +7 -0
  20. package/Components/Base/LibPixiRectangle.js +15 -0
  21. package/Components/Base/LibPixiRound.d.ts +5 -0
  22. package/Components/Base/LibPixiRound.js +9 -0
  23. package/Components/Base/LibPixiRoundedRect.d.ts +5 -0
  24. package/Components/Base/LibPixiRoundedRect.js +10 -0
  25. package/Components/Base/LibPixiSpine.d.ts +58 -0
  26. package/Components/Base/LibPixiSpine.js +128 -0
  27. package/Components/Base/LibPixiText.d.ts +37 -0
  28. package/Components/Base/LibPixiText.js +35 -0
  29. package/Components/Custom/LibPixiAreaClick.d.ts +6 -0
  30. package/Components/Custom/LibPixiAreaClick.js +16 -0
  31. package/Components/Custom/LibPixiArrangeLinearV2.d.ts +25 -0
  32. package/Components/Custom/LibPixiArrangeLinearV2.js +80 -0
  33. package/Components/Custom/LibPixiButtonHover.d.ts +40 -0
  34. package/Components/Custom/LibPixiButtonHover.js +53 -0
  35. package/Components/Custom/LibPixiCapsule.d.ts +5 -0
  36. package/Components/Custom/LibPixiCapsule.js +10 -0
  37. package/Components/Custom/LibPixiCloseBtn.d.ts +14 -0
  38. package/Components/Custom/LibPixiCloseBtn.js +36 -0
  39. package/Components/Custom/LibPixiDragLocate.d.ts +36 -0
  40. package/Components/Custom/LibPixiDragLocate.js +230 -0
  41. package/Components/Custom/LibPixiDrawer.d.ts +16 -0
  42. package/Components/Custom/LibPixiDrawer.js +59 -0
  43. package/Components/Custom/LibPixiGridLayoutV2.d.ts +27 -0
  44. package/Components/Custom/LibPixiGridLayoutV2.js +37 -0
  45. package/Components/Custom/LibPixiInput.d.ts +77 -0
  46. package/Components/Custom/LibPixiInput.js +198 -0
  47. package/Components/Custom/LibPixiLabelValue.d.ts +30 -0
  48. package/Components/Custom/LibPixiLabelValue.js +26 -0
  49. package/Components/Custom/LibPixiPerforMon.d.ts +47 -0
  50. package/Components/Custom/LibPixiPerforMon.js +166 -0
  51. package/Components/Custom/LibPixiProgress.d.ts +33 -0
  52. package/Components/Custom/LibPixiProgress.js +47 -0
  53. package/Components/Custom/LibPixiPuzzleBg.d.ts +7 -0
  54. package/Components/Custom/LibPixiPuzzleBg.js +46 -0
  55. package/Components/Custom/LibPixiScrollContainerX.d.ts +71 -0
  56. package/Components/Custom/LibPixiScrollContainerX.js +198 -0
  57. package/Components/Custom/LibPixiScrollContainerY.d.ts +109 -0
  58. package/Components/Custom/LibPixiScrollContainerY.js +340 -0
  59. package/Components/Custom/LibPixiScrollNum.d.ts +67 -0
  60. package/Components/Custom/LibPixiScrollNum.js +184 -0
  61. package/Components/Custom/LibPixiSlide.d.ts +94 -0
  62. package/Components/Custom/LibPixiSlide.js +285 -0
  63. package/Components/Custom/LibPixiSlider.d.ts +82 -0
  64. package/Components/Custom/LibPixiSlider.js +165 -0
  65. package/Components/Custom/LibPixiTable.d.ts +64 -0
  66. package/Components/Custom/LibPixiTable.js +76 -0
  67. package/Components/Custom/LibPixiTextGroupWrap.d.ts +20 -0
  68. package/Components/Custom/LibPixiTextGroupWrap.js +50 -0
  69. package/Components/Custom/LibPixiTriangle.d.ts +5 -0
  70. package/Components/Custom/LibPixiTriangle.js +12 -0
  71. package/Components/Custom/LibPixiTurntable.d.ts +6 -0
  72. package/Components/Custom/LibPixiTurntable.js +14 -0
  73. package/Utils/LibContainerCenter.d.ts +3 -0
  74. package/Utils/LibContainerCenter.js +10 -0
  75. package/Utils/LibControlledDelayedCall.d.ts +5 -0
  76. package/Utils/LibControlledDelayedCall.js +20 -0
  77. package/Utils/LibPixiArrangeLinear.d.ts +16 -0
  78. package/Utils/LibPixiArrangeLinear.js +62 -0
  79. package/Utils/LibPixiAudio.d.ts +53 -0
  80. package/Utils/LibPixiAudio.js +168 -0
  81. package/Utils/LibPixiCreateNineGrid.d.ts +15 -0
  82. package/Utils/LibPixiCreateNineGrid.js +19 -0
  83. package/Utils/LibPixiDialogManager/index.d.ts +25 -0
  84. package/Utils/LibPixiDialogManager/index.js +43 -0
  85. package/Utils/LibPixiDialogManager/ui/LibPixiBaseContainer.d.ts +11 -0
  86. package/Utils/LibPixiDialogManager/ui/LibPixiBaseContainer.js +31 -0
  87. package/Utils/LibPixiDialogManager/ui/LibPixiDialog.d.ts +38 -0
  88. package/Utils/LibPixiDialogManager/ui/LibPixiDialog.js +133 -0
  89. package/Utils/LibPixiDigitalIncreasingAnimation.d.ts +18 -0
  90. package/Utils/LibPixiDigitalIncreasingAnimation.js +26 -0
  91. package/Utils/LibPixiDownScaleAnimation.d.ts +7 -0
  92. package/Utils/LibPixiDownScaleAnimation.js +33 -0
  93. package/Utils/LibPixiEmitContainerEvent.d.ts +7 -0
  94. package/Utils/LibPixiEmitContainerEvent.js +13 -0
  95. package/Utils/LibPixiEvent.d.ts +19 -0
  96. package/Utils/LibPixiEvent.js +68 -0
  97. package/Utils/LibPixiFilter.d.ts +9 -0
  98. package/Utils/LibPixiFilter.js +34 -0
  99. package/Utils/LibPixiGlobalUpdater.d.ts +15 -0
  100. package/Utils/LibPixiGlobalUpdater.js +21 -0
  101. package/Utils/LibPixiGridLayout.d.ts +10 -0
  102. package/Utils/LibPixiGridLayout.js +27 -0
  103. package/Utils/LibPixiHVCenter.d.ts +7 -0
  104. package/Utils/LibPixiHVCenter.js +14 -0
  105. package/Utils/LibPixiHVGap.d.ts +8 -0
  106. package/Utils/LibPixiHVGap.js +26 -0
  107. package/Utils/LibPixiIntervalTrigger.d.ts +7 -0
  108. package/Utils/LibPixiIntervalTrigger.js +35 -0
  109. package/Utils/LibPixiOutsideClick.d.ts +8 -0
  110. package/Utils/LibPixiOutsideClick.js +22 -0
  111. package/Utils/LibPixiOverflowHidden.d.ts +6 -0
  112. package/Utils/LibPixiOverflowHidden.js +14 -0
  113. package/Utils/LibPixiPolygonDrawTool.d.ts +44 -0
  114. package/Utils/LibPixiPolygonDrawTool.js +114 -0
  115. package/Utils/LibPixiPromiseTickerTimeout.d.ts +6 -0
  116. package/Utils/LibPixiPromiseTickerTimeout.js +22 -0
  117. package/Utils/LibPixiScaleContainer.d.ts +8 -0
  118. package/Utils/LibPixiScaleContainer.js +14 -0
  119. package/Utils/LibPixiShadow.d.ts +17 -0
  120. package/Utils/LibPixiShadow.js +18 -0
  121. package/Utils/LibPixiSlideInput.d.ts +55 -0
  122. package/Utils/LibPixiSlideInput.js +61 -0
  123. package/Utils/LibPixiTicker.d.ts +14 -0
  124. package/Utils/LibPixiTicker.js +49 -0
  125. package/Utils/LibPixiTickerTimeout.d.ts +6 -0
  126. package/Utils/LibPixiTickerTimeout.js +22 -0
  127. package/package.json +1 -2
  128. package/index.js +0 -5
  129. package/lyb-pixi.js +0 -58890
@@ -0,0 +1,6 @@
1
+ import { Graphics, type Container } from "pixi.js";
2
+ /** @description 为容器创建并应用一个矩形遮罩,用于隐藏溢出的内容,函数会返回遮罩,可控制是否显示遮罩
3
+ * @param container 需要设置遮罩裁剪的容器
4
+ * @link 使用方法:https://www.npmjs.com/package/lyb-pixi-js#LibPixiOverflowHidden-溢出裁剪
5
+ */
6
+ export declare const libPixiOverflowHidden: (container: Container) => Graphics;
@@ -0,0 +1,14 @@
1
+ import { Graphics } from "pixi.js";
2
+ /** @description 为容器创建并应用一个矩形遮罩,用于隐藏溢出的内容,函数会返回遮罩,可控制是否显示遮罩
3
+ * @param container 需要设置遮罩裁剪的容器
4
+ * @link 使用方法:https://www.npmjs.com/package/lyb-pixi-js#LibPixiOverflowHidden-溢出裁剪
5
+ */
6
+ export const libPixiOverflowHidden = (container) => {
7
+ const mask = new Graphics();
8
+ mask.beginFill(0xffffff);
9
+ mask.drawRect(0, 0, container.width, container.height);
10
+ mask.endFill();
11
+ container.addChild(mask);
12
+ container.mask = mask;
13
+ return mask;
14
+ };
@@ -0,0 +1,44 @@
1
+ import { type Application } from "pixi.js";
2
+ export interface LibPixiPolygonDrawToolParams {
3
+ /** 输出的数组内容格式 */
4
+ outFormat?: "object" | "number";
5
+ /** 圆点半径 */
6
+ dotRadius?: number;
7
+ /** 圆点颜色 */
8
+ dotColor?: string | number;
9
+ /** 多边形颜色 */
10
+ polygonColor?: string | number;
11
+ /** 多边形透明度 */
12
+ polygonAlpha?: number;
13
+ }
14
+ /** @description 多边形绘制工具,绘制时浏览器窗口需要全屏显示,空格键控制开始和结束,开始后鼠标进行点击绘制,退格删除点,空格结束绘制,绘制结果在控制台打印,不满意可再次按空格清空并重新绘制
15
+ * @link 使用方法:https://www.npmjs.com/package/lyb-pixi-js#LibPixiPolygonDrawTool-多边形绘制
16
+ */
17
+ export declare class LibPixiPolygonDrawTool {
18
+ /** App */
19
+ private _app;
20
+ /** 多边形 */
21
+ private _polygon;
22
+ /** 是否正在绘制 */
23
+ private _drawing;
24
+ /** 储点的数组 */
25
+ private _points;
26
+ /** 起始点 */
27
+ private _startPoint;
28
+ /** 实际绘制的点 */
29
+ private _realPoints;
30
+ /** 点元素 */
31
+ private _pointElements;
32
+ /** 参数 */
33
+ private _params;
34
+ constructor(app: Application, params?: LibPixiPolygonDrawToolParams);
35
+ private _setupListeners;
36
+ /** @description 控制绘制开始和结束 */
37
+ private toggleDrawing;
38
+ /** @description 添加点坐标 */
39
+ private _addPoint;
40
+ /** @description 绘制多边形 */
41
+ private _drawPolygon;
42
+ /** @description 绘制一个点 */
43
+ private _drawDot;
44
+ }
@@ -0,0 +1,114 @@
1
+ import { Graphics, } from "pixi.js";
2
+ /** @description 多边形绘制工具,绘制时浏览器窗口需要全屏显示,空格键控制开始和结束,开始后鼠标进行点击绘制,退格删除点,空格结束绘制,绘制结果在控制台打印,不满意可再次按空格清空并重新绘制
3
+ * @link 使用方法:https://www.npmjs.com/package/lyb-pixi-js#LibPixiPolygonDrawTool-多边形绘制
4
+ */
5
+ export class LibPixiPolygonDrawTool {
6
+ constructor(app, params = {}) {
7
+ /** 是否正在绘制 */
8
+ this._drawing = false;
9
+ /** 储点的数组 */
10
+ this._points = [];
11
+ /** 起始点 */
12
+ this._startPoint = [];
13
+ /** 实际绘制的点 */
14
+ this._realPoints = [];
15
+ /** 点元素 */
16
+ this._pointElements = [];
17
+ this._app = app;
18
+ this._params = Object.assign({ outFormat: "number", dotRadius: 2, dotColor: "#fff", polygonColor: "#68CCFF", polygonAlpha: 0.5 }, params);
19
+ this._app.stage.sortableChildren = true;
20
+ this._polygon = new Graphics();
21
+ this._app.stage.addChild(this._polygon);
22
+ this._polygon.zIndex = 999999;
23
+ this._setupListeners();
24
+ }
25
+ _setupListeners() {
26
+ // 监听键盘空格键按下事件
27
+ window.addEventListener("keydown", (event) => {
28
+ if (event.code === "Space") {
29
+ this.toggleDrawing();
30
+ }
31
+ else if (event.code === "Backspace") {
32
+ this._points.pop();
33
+ this._realPoints.pop();
34
+ this._drawPolygon();
35
+ }
36
+ });
37
+ // 监听鼠标点击事件
38
+ this._app.stage.eventMode = "static";
39
+ this._app.stage.on("pointerdown", (event) => {
40
+ if (this._drawing) {
41
+ this._addPoint(event);
42
+ }
43
+ });
44
+ }
45
+ /** @description 控制绘制开始和结束 */
46
+ toggleDrawing() {
47
+ if (this._drawing) {
48
+ alert("绘制结束");
49
+ this._points.push({ x: 0, y: 0 });
50
+ if (this._params.outFormat === "object") {
51
+ console.log(this._points);
52
+ }
53
+ else {
54
+ console.log(this._points.map((item) => [item.x, item.y]).flat());
55
+ }
56
+ }
57
+ else {
58
+ alert("开始绘制");
59
+ this._startPoint = [];
60
+ this._points = [];
61
+ this._realPoints = [];
62
+ this._polygon.clear();
63
+ this._pointElements.forEach((item) => item.destroy());
64
+ this._pointElements = [];
65
+ }
66
+ this._drawing = !this._drawing;
67
+ }
68
+ /** @description 添加点坐标 */
69
+ _addPoint(event) {
70
+ const x = Number(event.clientX.toFixed(0));
71
+ const y = Number(event.clientY.toFixed(0));
72
+ this._realPoints.push({ x, y });
73
+ // 如果是第一个点,记录为原点(0, 0)
74
+ if (this._startPoint.length === 0) {
75
+ this._startPoint = [{ x, y }];
76
+ this._points.push({ x: 0, y: 0 });
77
+ }
78
+ else {
79
+ // 计算相对于第一个点的偏移
80
+ const offsetX = x - this._startPoint[0].x;
81
+ const offsetY = y - this._startPoint[0].y;
82
+ // 将相对坐标添加到数组
83
+ this._points.push({
84
+ x: Number(offsetX.toFixed(0)),
85
+ y: Number(offsetY.toFixed(0)),
86
+ });
87
+ }
88
+ this._drawPolygon();
89
+ }
90
+ /** @description 绘制多边形 */
91
+ _drawPolygon() {
92
+ this._polygon.clear();
93
+ this._polygon.beginFill(this._params.polygonColor);
94
+ this._polygon.drawPolygon(this._realPoints);
95
+ this._polygon.endFill();
96
+ this._polygon.alpha = this._params.polygonAlpha;
97
+ //渲染点
98
+ this._pointElements.forEach((point) => point.destroy());
99
+ this._pointElements = [];
100
+ this._realPoints.forEach((point) => {
101
+ this._pointElements.push(this._drawDot(point.x, point.y));
102
+ });
103
+ }
104
+ /** @description 绘制一个点 */
105
+ _drawDot(x, y) {
106
+ const pointElement = new Graphics();
107
+ pointElement.beginFill(this._params.dotColor);
108
+ pointElement.drawCircle(x, y, this._params.dotRadius || 2);
109
+ pointElement.endFill();
110
+ this._app.stage.addChild(pointElement);
111
+ pointElement.zIndex = 999999;
112
+ return pointElement;
113
+ }
114
+ }
@@ -0,0 +1,6 @@
1
+ /** @description 基于 Ticker 和 Promise 的定时器
2
+ * @param delay 延迟时间
3
+ * @param callback 延迟后执行的函数
4
+ * @link 使用方法:https://www.npmjs.com/package/lyb-pixi-js#LibPixiPromiseTickerTimeout-TickerPromise定时器
5
+ */
6
+ export declare const libPixiPromiseTickerTimeout: (delay?: number, callback?: () => void) => Promise<void>;
@@ -0,0 +1,22 @@
1
+ import { Ticker } from "pixi.js";
2
+ /** @description 基于 Ticker 和 Promise 的定时器
3
+ * @param delay 延迟时间
4
+ * @param callback 延迟后执行的函数
5
+ * @link 使用方法:https://www.npmjs.com/package/lyb-pixi-js#LibPixiPromiseTickerTimeout-TickerPromise定时器
6
+ */
7
+ export const libPixiPromiseTickerTimeout = (delay = 1, callback) => {
8
+ return new Promise((resolve) => {
9
+ let elapsedTime = 0;
10
+ const ticker = Ticker.shared;
11
+ const tickerCallback = () => {
12
+ elapsedTime += ticker.deltaMS;
13
+ if (elapsedTime >= delay) {
14
+ callback === null || callback === void 0 ? void 0 : callback();
15
+ ticker.remove(tickerCallback);
16
+ resolve();
17
+ }
18
+ };
19
+ ticker.add(tickerCallback);
20
+ ticker.start();
21
+ });
22
+ };
@@ -0,0 +1,8 @@
1
+ import type { Container, Sprite, Text } from "pixi.js";
2
+ /** @description 元素超过指定宽度就缩放
3
+ * @param scaleContainer 需要缩放的元素
4
+ * @param maxWidth 最大宽度
5
+ * @param maxHeight 最大高度
6
+ * @link 使用方法:https://www.npmjs.com/package/lyb-pixi-js#LibPixiScaleContainer-超出缩放
7
+ */
8
+ export declare const libPixiScaleContainer: (scaleContainer: Container | Sprite | Text, maxWidth: number, maxHeight?: number) => void;
@@ -0,0 +1,14 @@
1
+ /** @description 元素超过指定宽度就缩放
2
+ * @param scaleContainer 需要缩放的元素
3
+ * @param maxWidth 最大宽度
4
+ * @param maxHeight 最大高度
5
+ * @link 使用方法:https://www.npmjs.com/package/lyb-pixi-js#LibPixiScaleContainer-超出缩放
6
+ */
7
+ export const libPixiScaleContainer = (scaleContainer, maxWidth, maxHeight) => {
8
+ const scaleX = (maxWidth / scaleContainer.width) * scaleContainer.scale.x;
9
+ const scaleY = maxHeight
10
+ ? (maxHeight / scaleContainer.height) * scaleContainer.scale.y
11
+ : scaleX;
12
+ const scale = Math.min(scaleX, scaleY);
13
+ scaleContainer.scale.set(scale > 1 ? 1 : scale);
14
+ };
@@ -0,0 +1,17 @@
1
+ import type { Container } from "pixi.js";
2
+ export interface LibPixiShadowShadowConfig {
3
+ color?: string;
4
+ alpha?: number;
5
+ blur?: number;
6
+ distance?: number;
7
+ offset?: {
8
+ x: number;
9
+ y: number;
10
+ };
11
+ }
12
+ /** @description 为图片或容器设置阴影
13
+ * @param container 需要添加阴影的元素
14
+ * @param config 配置项
15
+ * @link 使用方法:https://www.npmjs.com/package/lyb-pixi-js#LibPixiShadow-阴影
16
+ */
17
+ export declare const libPixiShadow: (container: Container, config?: LibPixiShadowShadowConfig) => void;
@@ -0,0 +1,18 @@
1
+ import { DropShadowFilter } from "@pixi/filter-drop-shadow";
2
+ /** @description 为图片或容器设置阴影
3
+ * @param container 需要添加阴影的元素
4
+ * @param config 配置项
5
+ * @link 使用方法:https://www.npmjs.com/package/lyb-pixi-js#LibPixiShadow-阴影
6
+ */
7
+ export const libPixiShadow = (container, config) => {
8
+ const { color = "#000", alpha = 0.25, blur = 1, distance = 0, offset = { x: 0, y: 0 }, } = config || {};
9
+ const shadowFilter = new DropShadowFilter({
10
+ color: color,
11
+ alpha,
12
+ blur,
13
+ distance,
14
+ offset,
15
+ });
16
+ shadowFilter.resolution = window.devicePixelRatio || 1;
17
+ container.filters = [shadowFilter];
18
+ };
@@ -0,0 +1,55 @@
1
+ import type { Application, Container } from "pixi.js";
2
+ export interface LibPixiSlideInputParams {
3
+ /** App */
4
+ app: Application;
5
+ /** 有效点击范围 */
6
+ clickArea: Container[];
7
+ /** 滑动区域 */
8
+ sideArea: Container;
9
+ /** 最大移动距离 */
10
+ maxMoveDistance: number;
11
+ /** 起点坐标 */
12
+ startX?: number;
13
+ /** 按下回调 */
14
+ onDown?: () => void;
15
+ /** 抬起回调 */
16
+ onUp?: () => void;
17
+ /** 拖动回调 */
18
+ onChange: (x: number, value: number) => void;
19
+ }
20
+ /** @description 滑动选择器核心代码
21
+ * @link 使用方法:https://www.npmjs.com/package/lyb-pixi-js#LibPixiSlideInput-滑动选择值
22
+ */
23
+ export declare class LibPixiSlideInput {
24
+ /** App */
25
+ private _app;
26
+ /** 滑动区域 */
27
+ private _sideArea;
28
+ /** 最大移动距离 */
29
+ private _maxMoveDistance;
30
+ /** 是否处于拖动中 */
31
+ private _isDragging;
32
+ /** 当前移动的位置 */
33
+ private _moveX;
34
+ /** 上次移动的位置 */
35
+ private _lastMoveX;
36
+ /** 当前进度 */
37
+ private _progress;
38
+ /** 按下回调 */
39
+ private _onDown?;
40
+ /** 抬起回调 */
41
+ private _onUp?;
42
+ /** 拖动回调 */
43
+ private _onChange;
44
+ constructor(params: LibPixiSlideInputParams);
45
+ /** @description 设置进度
46
+ * @param value 进度值,范围 0-1
47
+ */
48
+ setValue(value: number): void;
49
+ /** @description 按下触发 */
50
+ private _onDragStart;
51
+ /** @description 移动触发 */
52
+ private _onDragMove;
53
+ /** @description 抬起触发 */
54
+ private _onDragEnd;
55
+ }
@@ -0,0 +1,61 @@
1
+ import { libPixiEvent } from "./LibPixiEvent";
2
+ /** @description 滑动选择器核心代码
3
+ * @link 使用方法:https://www.npmjs.com/package/lyb-pixi-js#LibPixiSlideInput-滑动选择值
4
+ */
5
+ export class LibPixiSlideInput {
6
+ constructor(params) {
7
+ /** 是否处于拖动中 */
8
+ this._isDragging = false;
9
+ /** 当前移动的位置 */
10
+ this._moveX = 0;
11
+ /** 上次移动的位置 */
12
+ this._lastMoveX = 0;
13
+ /** 当前进度 */
14
+ this._progress = 0;
15
+ const { app, clickArea, maxMoveDistance, onChange, onDown, onUp, sideArea, } = params;
16
+ this._app = app;
17
+ this._maxMoveDistance = maxMoveDistance;
18
+ this._onChange = onChange;
19
+ this._onDown = onDown;
20
+ this._onUp = onUp;
21
+ this._sideArea = sideArea;
22
+ clickArea.forEach((item) => {
23
+ libPixiEvent(item, "pointerdown", this._onDragStart.bind(this));
24
+ });
25
+ libPixiEvent(sideArea, "pointerdown", this._onDragMove.bind(this));
26
+ app.stage.on("pointermove", this._onDragMove.bind(this));
27
+ app.stage.on("pointerup", this._onDragEnd.bind(this));
28
+ }
29
+ /** @description 设置进度
30
+ * @param value 进度值,范围 0-1
31
+ */
32
+ setValue(value) {
33
+ this._progress = value;
34
+ this._lastMoveX = this._maxMoveDistance * value;
35
+ this._onChange(this._lastMoveX, value);
36
+ }
37
+ /** @description 按下触发 */
38
+ _onDragStart() {
39
+ var _a;
40
+ this._app.stage.eventMode = "static";
41
+ this._isDragging = true;
42
+ (_a = this._onDown) === null || _a === void 0 ? void 0 : _a.call(this);
43
+ }
44
+ /** @description 移动触发 */
45
+ _onDragMove(event) {
46
+ const position = event.getLocalPosition(this._sideArea);
47
+ if (this._isDragging) {
48
+ this._moveX = Math.max(0, Math.min(position.x, this._maxMoveDistance));
49
+ this._progress = Number((this._moveX / this._maxMoveDistance).toFixed(2));
50
+ this._onChange(this._moveX, this._progress);
51
+ }
52
+ }
53
+ /** @description 抬起触发 */
54
+ _onDragEnd() {
55
+ var _a;
56
+ this._app.stage.eventMode = "auto";
57
+ this._isDragging = false;
58
+ this._lastMoveX = this._moveX;
59
+ (_a = this._onUp) === null || _a === void 0 ? void 0 : _a.call(this);
60
+ }
61
+ }
@@ -0,0 +1,14 @@
1
+ /** @description Ticker管理器 */
2
+ export declare class LibPixiTicker {
3
+ private static _callbacks;
4
+ /** @description 添加回调,重复 ID 会覆盖 */
5
+ static add(id: string, fn: () => void): () => void;
6
+ /** @description 删除回调 */
7
+ static remove(id: string): void;
8
+ /** @description 停止某个回调(pause) */
9
+ static stop(id: string): void;
10
+ /** @description 启动某个回调(resume) */
11
+ static start(id: string): void;
12
+ /** @description 清空所有回调 */
13
+ static clearAll(): void;
14
+ }
@@ -0,0 +1,49 @@
1
+ import { Ticker } from "pixi.js";
2
+ /** @description Ticker管理器 */
3
+ export class LibPixiTicker {
4
+ /** @description 添加回调,重复 ID 会覆盖 */
5
+ static add(id, fn) {
6
+ // 如果已有相同 ID,先移除旧回调
7
+ if (this._callbacks.has(id)) {
8
+ Ticker.shared.remove(this._callbacks.get(id).fn);
9
+ }
10
+ // 默认 active
11
+ this._callbacks.set(id, { fn, active: true });
12
+ Ticker.shared.add(fn);
13
+ return () => {
14
+ LibPixiTicker.remove(id);
15
+ };
16
+ }
17
+ /** @description 删除回调 */
18
+ static remove(id) {
19
+ const cb = this._callbacks.get(id);
20
+ if (cb) {
21
+ Ticker.shared.remove(cb.fn);
22
+ this._callbacks.delete(id);
23
+ }
24
+ }
25
+ /** @description 停止某个回调(pause) */
26
+ static stop(id) {
27
+ const cb = this._callbacks.get(id);
28
+ if (cb && cb.active) {
29
+ Ticker.shared.remove(cb.fn);
30
+ cb.active = false;
31
+ }
32
+ }
33
+ /** @description 启动某个回调(resume) */
34
+ static start(id) {
35
+ const cb = this._callbacks.get(id);
36
+ if (cb && !cb.active) {
37
+ Ticker.shared.add(cb.fn);
38
+ cb.active = true;
39
+ }
40
+ }
41
+ /** @description 清空所有回调 */
42
+ static clearAll() {
43
+ this._callbacks.forEach((cb) => {
44
+ Ticker.shared.remove(cb.fn);
45
+ });
46
+ this._callbacks.clear();
47
+ }
48
+ }
49
+ LibPixiTicker._callbacks = new Map();
@@ -0,0 +1,6 @@
1
+ /** @description 基于 Ticker 的定时器
2
+ * @param callback 延迟后执行的函数
3
+ * @param delay 延迟时间
4
+ * @link 使用方法:https://www.npmjs.com/package/lyb-pixi-js#LibPixiTickerTimeout-Ticker定时器
5
+ */
6
+ export declare const libPixiTickerTimeout: (callback: () => void, delay?: number) => () => void;
@@ -0,0 +1,22 @@
1
+ import { Ticker } from "pixi.js";
2
+ /** @description 基于 Ticker 的定时器
3
+ * @param callback 延迟后执行的函数
4
+ * @param delay 延迟时间
5
+ * @link 使用方法:https://www.npmjs.com/package/lyb-pixi-js#LibPixiTickerTimeout-Ticker定时器
6
+ */
7
+ export const libPixiTickerTimeout = (callback, delay = 1) => {
8
+ let elapsedTime = 0;
9
+ const ticker = Ticker.shared;
10
+ const tickerCallback = () => {
11
+ elapsedTime += ticker.deltaMS;
12
+ if (elapsedTime >= delay) {
13
+ callback === null || callback === void 0 ? void 0 : callback();
14
+ ticker.remove(tickerCallback);
15
+ }
16
+ };
17
+ ticker.add(tickerCallback);
18
+ ticker.start();
19
+ return () => {
20
+ ticker.remove(tickerCallback);
21
+ };
22
+ };
package/package.json CHANGED
@@ -1,10 +1,9 @@
1
1
  {
2
2
  "name": "lyb-pixi-js",
3
- "version": "1.12.33",
3
+ "version": "1.12.34",
4
4
  "description": "自用Pixi.JS方法库",
5
5
  "license": "ISC",
6
6
  "exports": {
7
- ".": "./index.js",
8
7
  "./Components/Base/*": "./Components/Base/*",
9
8
  "./Components/Custom/*": "./Components/Custom/*",
10
9
  "./Utils/*": "./Utils/*"
package/index.js DELETED
@@ -1,5 +0,0 @@
1
- (function(factory) {
2
- typeof define === "function" && define.amd ? define(factory) : factory();
3
- })(function() {
4
- "use strict";
5
- });