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,31 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ import { Container } from "pixi.js";
11
+ /** @description */
12
+ export class LibPixiBaseContainer extends Container {
13
+ constructor() {
14
+ super();
15
+ }
16
+ /** @description 销毁 */
17
+ destroy() {
18
+ const _super = Object.create(null, {
19
+ destroy: { get: () => super.destroy }
20
+ });
21
+ return __awaiter(this, void 0, void 0, function* () {
22
+ var _a;
23
+ yield ((_a = this._onBeforeDestroy) === null || _a === void 0 ? void 0 : _a.call(this));
24
+ requestAnimationFrame(() => {
25
+ var _a;
26
+ _super.destroy.call(this, { children: true });
27
+ (_a = this._onDestroyed) === null || _a === void 0 ? void 0 : _a.call(this);
28
+ });
29
+ });
30
+ }
31
+ }
@@ -0,0 +1,38 @@
1
+ import { Container } from "pixi.js";
2
+ import { LibPixiBaseContainer } from "./LibPixiBaseContainer";
3
+ interface Params {
4
+ /** 是否需要显示黑色背景 */
5
+ needBg?: boolean;
6
+ /** 竖版初始大小 */
7
+ size?: number;
8
+ /** 点击蒙版回调 */
9
+ onClickMask?: () => void;
10
+ }
11
+ /** @description 弹窗组件 */
12
+ export declare class LibPixiDialog extends LibPixiBaseContainer {
13
+ /** 黑色背景透明度 */
14
+ static bgAlpha: number;
15
+ /** 动画时长 */
16
+ static durationIn: number;
17
+ static durationOut: number;
18
+ /** 是否支持横竖版 */
19
+ static adaptation: "hv" | "h" | "v";
20
+ /** 蒙版UI */
21
+ private _maskUI;
22
+ /** 内容容器 */
23
+ private _dialogContainer;
24
+ /** 当前大小 */
25
+ private _size;
26
+ /** 竖版初始大小 */
27
+ private _initialSize;
28
+ /** 停止监听窗口 */
29
+ private _offResize?;
30
+ constructor(params?: Params);
31
+ /** @description 设置弹窗内容 */
32
+ setDialogContent(content: Container): void;
33
+ /** @description 重绘弹窗 */
34
+ redraw(w: number, h: number): void;
35
+ /** @description 关闭 */
36
+ close(): Promise<void>;
37
+ }
38
+ export {};
@@ -0,0 +1,133 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ import { Container } from "pixi.js";
11
+ import gsap from "gsap";
12
+ import { LibJsResizeWatcher } from "lyb-js/Base/LibJsResizeWatcher.js";
13
+ import { LibPixiRectangle } from "../../../Components/Base/LibPixiRectangle";
14
+ import { libPixiEvent } from "../../LibPixiEvent";
15
+ import { LibPixiBaseContainer } from "./LibPixiBaseContainer";
16
+ /** @description 弹窗组件 */
17
+ export class LibPixiDialog extends LibPixiBaseContainer {
18
+ constructor(params) {
19
+ super();
20
+ /** 当前大小 */
21
+ this._size = 1;
22
+ const { size = 1, onClickMask, needBg = true } = params || {};
23
+ this._initialSize = size;
24
+ //蒙版
25
+ this._maskUI = new LibPixiRectangle(2700, 1080, "#000");
26
+ this.addChild(this._maskUI);
27
+ this._maskUI.alpha = 0;
28
+ this._maskUI.eventMode = "static";
29
+ this._maskUI.visible = needBg;
30
+ if (onClickMask) {
31
+ libPixiEvent(this._maskUI, "pointertap", () => {
32
+ var _a;
33
+ onClickMask === null || onClickMask === void 0 ? void 0 : onClickMask();
34
+ (_a = this._offResize) === null || _a === void 0 ? void 0 : _a.call(this);
35
+ }, {
36
+ once: true,
37
+ });
38
+ }
39
+ //弹窗内容容器
40
+ this._dialogContainer = new Container();
41
+ this.addChild(this._dialogContainer);
42
+ this._dialogContainer.eventMode = "static";
43
+ const resize = new LibJsResizeWatcher(LibPixiDialog.adaptation);
44
+ this._offResize = resize.on(this.redraw.bind(this));
45
+ }
46
+ /** @description 设置弹窗内容 */
47
+ setDialogContent(content) {
48
+ this._dialogContainer.addChild(content);
49
+ if (LibPixiDialog.adaptation === "h") {
50
+ this.redraw(1920, 1080);
51
+ }
52
+ else if (LibPixiDialog.adaptation === "v") {
53
+ this.redraw(1080, 1920);
54
+ }
55
+ else {
56
+ this.redraw(window.innerWidth, window.innerHeight);
57
+ }
58
+ this._dialogContainer.scale.set(0);
59
+ this._dialogContainer.alpha = 0;
60
+ gsap.to(this._maskUI, {
61
+ duration: LibPixiDialog.durationIn,
62
+ alpha: LibPixiDialog.bgAlpha,
63
+ });
64
+ gsap.to(this._dialogContainer, {
65
+ duration: LibPixiDialog.durationIn,
66
+ alpha: 1,
67
+ });
68
+ }
69
+ /** @description 重绘弹窗 */
70
+ redraw(w, h) {
71
+ const dialogW = this._dialogContainer.width / 2;
72
+ const dialogH = this._dialogContainer.height / 2;
73
+ this._dialogContainer.pivot.set(dialogW, dialogH);
74
+ const halfW = 1920 / 2;
75
+ const halfH = 1080 / 2;
76
+ if (w > h) {
77
+ this._maskUI.width = 2700;
78
+ this._maskUI.height = 1080;
79
+ this._maskUI.x = -(2700 - 1920) / 2;
80
+ this._dialogContainer.position.set(halfW, halfH);
81
+ this._size = 1;
82
+ if (this._dialogContainer.scale.x === this._initialSize) {
83
+ this._dialogContainer.scale.set(1);
84
+ }
85
+ }
86
+ else {
87
+ this._maskUI.width = 1080;
88
+ this._maskUI.height = 2700;
89
+ this._maskUI.x = 0;
90
+ this._dialogContainer.position.set(halfH, halfW);
91
+ this._size = this._initialSize;
92
+ if (this._dialogContainer.scale.x === 1) {
93
+ this._dialogContainer.scale.set(this._initialSize);
94
+ }
95
+ }
96
+ gsap.to(this._dialogContainer.scale, {
97
+ duration: LibPixiDialog.durationIn,
98
+ ease: "back.out",
99
+ x: this._size,
100
+ y: this._size,
101
+ });
102
+ }
103
+ /** @description 关闭 */
104
+ close() {
105
+ return __awaiter(this, void 0, void 0, function* () {
106
+ var _a;
107
+ (_a = this._offResize) === null || _a === void 0 ? void 0 : _a.call(this);
108
+ gsap.to(this._dialogContainer.scale, {
109
+ duration: LibPixiDialog.durationOut,
110
+ ease: "back.in",
111
+ x: 0,
112
+ y: 0,
113
+ });
114
+ gsap.to(this._dialogContainer, {
115
+ duration: LibPixiDialog.durationOut,
116
+ delay: LibPixiDialog.durationOut / 2,
117
+ alpha: 0,
118
+ });
119
+ yield gsap.to(this._maskUI, {
120
+ duration: LibPixiDialog.durationOut,
121
+ delay: LibPixiDialog.durationOut / 2,
122
+ alpha: 0,
123
+ });
124
+ });
125
+ }
126
+ }
127
+ /** 黑色背景透明度 */
128
+ LibPixiDialog.bgAlpha = 0.5;
129
+ /** 动画时长 */
130
+ LibPixiDialog.durationIn = 0.5;
131
+ LibPixiDialog.durationOut = 0.5;
132
+ /** 是否支持横竖版 */
133
+ LibPixiDialog.adaptation = "hv";
@@ -0,0 +1,18 @@
1
+ export interface LibPixiDigitalIncreasingAnimationParams {
2
+ /** 目标值 */
3
+ value: number;
4
+ /** 开始值 */
5
+ startValue?: number;
6
+ /** 动画时长 */
7
+ duration?: number;
8
+ /** 值改变时触发 */
9
+ onChange: (value: string) => void;
10
+ /** 动画完成后触发 */
11
+ onComplete?: () => void;
12
+ }
13
+ /** @description 数值递增动画
14
+ * @param params 动画参数
15
+ * @returns 设置为目标值并停止动画
16
+ * @link 使用方法:https://www.npmjs.com/package/lyb-pixi-js#LibPixiDigitalIncreasingAnimation-递增动画
17
+ */
18
+ export declare const LibPixiDigitalIncreasingAnimation: (params: LibPixiDigitalIncreasingAnimationParams) => () => void;
@@ -0,0 +1,26 @@
1
+ import { libJsNumComma } from "lyb-js/Formatter/LibJsNumComma.js";
2
+ import gsap from "gsap";
3
+ /** @description 数值递增动画
4
+ * @param params 动画参数
5
+ * @returns 设置为目标值并停止动画
6
+ * @link 使用方法:https://www.npmjs.com/package/lyb-pixi-js#LibPixiDigitalIncreasingAnimation-递增动画
7
+ */
8
+ export const LibPixiDigitalIncreasingAnimation = (params) => {
9
+ const { value, onChange, onComplete, startValue = 0, duration = 4 } = params;
10
+ // 动画递增的目标值
11
+ const animatedValue = { value: startValue };
12
+ // 使用 GSAP 创建递增动画
13
+ gsap.killTweensOf(animatedValue);
14
+ const amountAnimation = gsap.to(animatedValue, {
15
+ value,
16
+ duration,
17
+ ease: "linear",
18
+ onUpdate: () => {
19
+ onChange(libJsNumComma(animatedValue.value, 2));
20
+ },
21
+ onComplete: onComplete,
22
+ });
23
+ return () => {
24
+ amountAnimation.progress(1);
25
+ };
26
+ };
@@ -0,0 +1,7 @@
1
+ import { Container } from "pixi.js";
2
+ /** @description 按下放大
3
+ * @param container 要放大的容器
4
+ * @param type 缩放类型
5
+ * @link 使用方法:https://www.npmjs.com/package/lyb-pixi-js#LibPixiDownScaleAnimation-按下放大
6
+ */
7
+ export declare const LibPixiDownScaleAnimation: (container: Container, type?: "small" | "big") => void;
@@ -0,0 +1,33 @@
1
+ import { libPixiEvent } from "./LibPixiEvent";
2
+ import gsap from "gsap";
3
+ /** @description 按下放大
4
+ * @param container 要放大的容器
5
+ * @param type 缩放类型
6
+ * @link 使用方法:https://www.npmjs.com/package/lyb-pixi-js#LibPixiDownScaleAnimation-按下放大
7
+ */
8
+ export const LibPixiDownScaleAnimation = (container, type = "big") => {
9
+ libPixiEvent(container, "pointerdown", () => {
10
+ gsap.to(container, {
11
+ duration: 0.1,
12
+ pixi: {
13
+ scale: type === "big" ? 1.1 : 0.9,
14
+ },
15
+ });
16
+ });
17
+ libPixiEvent(container, "pointerup", () => {
18
+ gsap.to(container, {
19
+ duration: 0.1,
20
+ pixi: {
21
+ scale: 1,
22
+ },
23
+ });
24
+ });
25
+ libPixiEvent(container, "pointerleave", () => {
26
+ gsap.to(container, {
27
+ duration: 0.1,
28
+ pixi: {
29
+ scale: 1,
30
+ },
31
+ });
32
+ });
33
+ };
@@ -0,0 +1,7 @@
1
+ import { Container } from "pixi.js";
2
+ /** @description 触发后代监听
3
+ * @param container 容器
4
+ * @param event 事件名称
5
+ * @param payload 事件携带数据
6
+ */
7
+ export declare const LibPixiEmitContainerEvent: (container: Container, event: string, payload?: any) => void;
@@ -0,0 +1,13 @@
1
+ /** @description 触发后代监听
2
+ * @param container 容器
3
+ * @param event 事件名称
4
+ * @param payload 事件携带数据
5
+ */
6
+ export const LibPixiEmitContainerEvent = (container, event, payload) => {
7
+ container.children.forEach((child) => {
8
+ child.emit(event, payload);
9
+ if ("children" in child) {
10
+ LibPixiEmitContainerEvent(child, event, payload);
11
+ }
12
+ });
13
+ };
@@ -0,0 +1,19 @@
1
+ import type { Container, DisplayObjectEvents, FederatedPointerEvent } from "pixi.js";
2
+ export interface LibPixiEventParams {
3
+ /** 是否只执行一次 */
4
+ once?: boolean;
5
+ /** 是否启用防抖 */
6
+ debounce?: boolean;
7
+ /** 防抖时长 */
8
+ debounceTime?: number;
9
+ /** 是否阻止拖动点击 */
10
+ preventDragClick?: boolean;
11
+ }
12
+ /** @description 事件注册
13
+ * @param v 事件容器
14
+ * @param eventName 事件名称
15
+ * @param callback 回调函数
16
+ * @returns 停止监听
17
+ * @link 使用方法:https://www.npmjs.com/package/lyb-pixi-js#LibPixiEvent-事件注册
18
+ */
19
+ export declare const libPixiEvent: (v: Container, eventName: keyof DisplayObjectEvents, callback: (event: FederatedPointerEvent) => void, params?: LibPixiEventParams) => () => void;
@@ -0,0 +1,68 @@
1
+ const debounceImmediate = (func, wait) => {
2
+ let timer = null;
3
+ let invoked = false;
4
+ return (...args) => {
5
+ if (!invoked) {
6
+ func(...args);
7
+ invoked = true;
8
+ }
9
+ if (timer)
10
+ clearTimeout(timer);
11
+ timer = setTimeout(() => {
12
+ invoked = false;
13
+ }, wait);
14
+ };
15
+ };
16
+ /** @description 事件注册
17
+ * @param v 事件容器
18
+ * @param eventName 事件名称
19
+ * @param callback 回调函数
20
+ * @returns 停止监听
21
+ * @link 使用方法:https://www.npmjs.com/package/lyb-pixi-js#LibPixiEvent-事件注册
22
+ */
23
+ export const libPixiEvent = (v, eventName, callback, params = {}) => {
24
+ const { once = false, debounce = false, debounceTime = 1000, preventDragClick = false, } = params;
25
+ v.cursor = "pointer";
26
+ v.eventMode = "static";
27
+ let lastX = 0;
28
+ let lastY = 0;
29
+ let isDragging = false;
30
+ if (preventDragClick) {
31
+ v.on("pointerdown", (e) => {
32
+ isDragging = false;
33
+ lastX = e.globalX;
34
+ lastY = e.globalY;
35
+ const threshold = 10; // 阈值像素
36
+ const moveHandler = (ev) => {
37
+ const dx = ev.globalX - lastX;
38
+ const dy = ev.globalY - lastY;
39
+ if (dx * dx + dy * dy > threshold * threshold) {
40
+ isDragging = true;
41
+ }
42
+ };
43
+ const upHandler = () => {
44
+ v.off("pointermove", moveHandler);
45
+ v.off("pointerup", upHandler);
46
+ };
47
+ v.on("pointermove", moveHandler);
48
+ v.on("pointerup", upHandler);
49
+ });
50
+ }
51
+ const fn = (e) => {
52
+ if (isDragging && ["pointertap", "pointerup"].includes(eventName))
53
+ return;
54
+ if (e.button === 2)
55
+ return;
56
+ callback(e);
57
+ };
58
+ const handler = debounce ? debounceImmediate(fn, debounceTime) : fn;
59
+ if (once) {
60
+ v.once(eventName, handler);
61
+ }
62
+ else {
63
+ v.on(eventName, handler);
64
+ }
65
+ return () => {
66
+ v.off(eventName, handler);
67
+ };
68
+ };
@@ -0,0 +1,9 @@
1
+ /** @description 设置滤镜 */
2
+ import { ColorMatrixFilter, BlurFilter } from "pixi.js";
3
+ export type LibPixiSetFilterFilterName = "brightness" | "blur" | "desaturate" | "contrast" | "saturate";
4
+ /** @description 滤镜
5
+ * @param filterName 滤镜名称
6
+ * @param v 滤镜值
7
+ * @link 使用方法:https://www.npmjs.com/package/lyb-pixi-js#LibPixiFilter-滤镜
8
+ */
9
+ export declare const libPixiFilter: (filterName: LibPixiSetFilterFilterName, v?: number) => ColorMatrixFilter | BlurFilter;
@@ -0,0 +1,34 @@
1
+ /** @description 设置滤镜 */
2
+ import { ColorMatrixFilter, BlurFilter } from "pixi.js";
3
+ /** @description 滤镜
4
+ * @param filterName 滤镜名称
5
+ * @param v 滤镜值
6
+ * @link 使用方法:https://www.npmjs.com/package/lyb-pixi-js#LibPixiFilter-滤镜
7
+ */
8
+ export const libPixiFilter = (filterName, v) => {
9
+ let filter;
10
+ if (filterName === "brightness") {
11
+ filter = new ColorMatrixFilter();
12
+ filter.brightness(v, false); // 设置亮度
13
+ }
14
+ else if (filterName === "blur") {
15
+ filter = new BlurFilter();
16
+ }
17
+ else if (filterName === "desaturate") {
18
+ filter = new ColorMatrixFilter();
19
+ filter.desaturate();
20
+ }
21
+ else if (filterName === "contrast") {
22
+ filter = new ColorMatrixFilter();
23
+ filter.contrast(v, false);
24
+ }
25
+ else if (filterName === "saturate") {
26
+ filter = new ColorMatrixFilter();
27
+ filter.saturate(v, false);
28
+ }
29
+ else {
30
+ throw new Error("未知滤镜名称");
31
+ }
32
+ filter.resolution = window.devicePixelRatio || 1;
33
+ return filter;
34
+ };
@@ -0,0 +1,15 @@
1
+ import type { Container } from "pixi.js";
2
+ /** @description 事件总线更新实例汇总 */
3
+ export declare class LibPixiGlobalUpdater<Instances> {
4
+ /** 实例列表 */
5
+ private instances;
6
+ /** @description 存储实例
7
+ * @param key 实例key
8
+ * @param instance 实例
9
+ */
10
+ setInstance(key: Instances, instance: Container): void;
11
+ /** @description 获取实例
12
+ * @param key 实例key
13
+ */
14
+ getInstance<T>(key: Instances): T;
15
+ }
@@ -0,0 +1,21 @@
1
+ /** @description 事件总线更新实例汇总 */
2
+ export class LibPixiGlobalUpdater {
3
+ constructor() {
4
+ /** 实例列表 */
5
+ this.instances = new Map();
6
+ }
7
+ /** @description 存储实例
8
+ * @param key 实例key
9
+ * @param instance 实例
10
+ */
11
+ setInstance(key, instance) {
12
+ this.instances.has(key) && this.instances.delete(key);
13
+ this.instances.set(key, instance);
14
+ }
15
+ /** @description 获取实例
16
+ * @param key 实例key
17
+ */
18
+ getInstance(key) {
19
+ return this.instances.get(key);
20
+ }
21
+ }
@@ -0,0 +1,10 @@
1
+ import { Container } from "pixi.js";
2
+ /**
3
+ * @description 将元素按照指定的列数和间隔排列成网格布局。
4
+ * @param items 要排列的元素数组
5
+ * @param gap 每个元素之间的间隔
6
+ * @param cols 网格的列数,默认为元素数量
7
+ * @link 使用方法:https://www.npmjs.com/package/lyb-pixi-js#LibPixiGridLayout-网格布局
8
+ * @param direction 排列方向: "row" 行优先(默认) | "col" 列优先
9
+ */
10
+ export declare const LibPixiGridLayout: (items: Container[], gap: number, cols?: number, direction?: "row" | "col") => void;
@@ -0,0 +1,27 @@
1
+ /**
2
+ * @description 将元素按照指定的列数和间隔排列成网格布局。
3
+ * @param items 要排列的元素数组
4
+ * @param gap 每个元素之间的间隔
5
+ * @param cols 网格的列数,默认为元素数量
6
+ * @link 使用方法:https://www.npmjs.com/package/lyb-pixi-js#LibPixiGridLayout-网格布局
7
+ * @param direction 排列方向: "row" 行优先(默认) | "col" 列优先
8
+ */
9
+ export const LibPixiGridLayout = (items, gap, cols = items.length, direction = "row") => {
10
+ const rows = Math.ceil(items.length / cols); // 动态计算行数
11
+ items.forEach((item, index) => {
12
+ const itemWidth = item.width || 0;
13
+ const itemHeight = item.height || 0;
14
+ let colIndex = 0;
15
+ let rowIndex = 0;
16
+ if (direction === "row") {
17
+ colIndex = index % cols;
18
+ rowIndex = Math.floor(index / cols);
19
+ }
20
+ else {
21
+ colIndex = Math.floor(index / rows);
22
+ rowIndex = index % rows;
23
+ }
24
+ item.x = colIndex * (itemWidth + gap);
25
+ item.y = rowIndex * (itemHeight + gap);
26
+ });
27
+ };
@@ -0,0 +1,7 @@
1
+ import { Container } from "pixi.js";
2
+ /** @description 列表居中
3
+ * @param parent 父容器
4
+ * @param items 子元素数组
5
+ * @param direction 方向数组,"x"表示水平,"y"表示垂直
6
+ */
7
+ export declare const libPixiHVCenter: (parent: Container, items: Container[], direction: ("x" | "y")[]) => void;
@@ -0,0 +1,14 @@
1
+ /** @description 列表居中
2
+ * @param parent 父容器
3
+ * @param items 子元素数组
4
+ * @param direction 方向数组,"x"表示水平,"y"表示垂直
5
+ */
6
+ export const libPixiHVCenter = (parent, items, direction) => {
7
+ items.forEach((item) => {
8
+ direction.forEach((d) => {
9
+ item[d] =
10
+ parent[d === "x" ? "width" : "height"] / 2 -
11
+ item[d === "x" ? "width" : "height"] / 2;
12
+ });
13
+ });
14
+ };
@@ -0,0 +1,8 @@
1
+ import { Container } from "pixi.js";
2
+ /**
3
+ * @description 按照指定方向(水平或垂直)排列元素,支持固定间隔或自定义每个间隔。
4
+ * @param items 要排列的元素数组。
5
+ * @param gap 元素之间的间隔,可以是固定间隔或自定义的间隔数组。
6
+ * @param direction 排列方向,"x"表示水平,"y"表示垂直,默认为水平。
7
+ */
8
+ export declare const libPixiHVGap: (items: Container[], gap: number | number[], direction?: "x" | "y") => void;
@@ -0,0 +1,26 @@
1
+ /**
2
+ * @description 按照指定方向(水平或垂直)排列元素,支持固定间隔或自定义每个间隔。
3
+ * @param items 要排列的元素数组。
4
+ * @param gap 元素之间的间隔,可以是固定间隔或自定义的间隔数组。
5
+ * @param direction 排列方向,"x"表示水平,"y"表示垂直,默认为水平。
6
+ */
7
+ export const libPixiHVGap = (items, gap, direction = "x") => {
8
+ if (Array.isArray(gap)) {
9
+ if (gap.length !== items.length - 1) {
10
+ console.error(new Error("间隔的数组长度只能等于元素数组长度-1"));
11
+ return;
12
+ }
13
+ }
14
+ let lastPosition = 0;
15
+ items.forEach((item, index) => {
16
+ const position = index === 0 ? 0 : lastPosition + (Array.isArray(gap) ? gap[index - 1] : gap);
17
+ if (direction === "x") {
18
+ item.x = position;
19
+ lastPosition = item.x + item.width;
20
+ }
21
+ else {
22
+ item.y = position;
23
+ lastPosition = item.y + item.height;
24
+ }
25
+ });
26
+ };
@@ -0,0 +1,7 @@
1
+ /** @description 间隔触发
2
+ * @param callback 回调函数
3
+ * @param interval 间隔毫秒,或随机范围
4
+ * @param immediately 是否立即执行一次
5
+ * @link 使用方法:https://www.npmjs.com/package/lyb-pixi-js#LibPixiIntervalTrigger-间隔触发
6
+ */
7
+ export declare const libPixiIntervalTrigger: (callback: () => void, interval: number | [number, number], immediately?: boolean) => () => void;
@@ -0,0 +1,35 @@
1
+ import { Ticker } from "pixi.js"; //@ts-ignore
2
+ import { libJsRandom } from "lyb-js/Random/LibJsRandom.js";
3
+ /** @description 间隔触发
4
+ * @param callback 回调函数
5
+ * @param interval 间隔毫秒,或随机范围
6
+ * @param immediately 是否立即执行一次
7
+ * @link 使用方法:https://www.npmjs.com/package/lyb-pixi-js#LibPixiIntervalTrigger-间隔触发
8
+ */
9
+ export const libPixiIntervalTrigger = (callback, interval, immediately = true) => {
10
+ let elapsedTime = 0;
11
+ // 创建一个新的 Ticker 实例
12
+ const ticker = new Ticker();
13
+ // 创建回调函数
14
+ const tickerCallback = () => {
15
+ elapsedTime += ticker.elapsedMS;
16
+ let intervalNum = 0;
17
+ if (Array.isArray(interval)) {
18
+ intervalNum = libJsRandom(interval[0], interval[1], 2);
19
+ }
20
+ else {
21
+ intervalNum = interval;
22
+ }
23
+ if (elapsedTime >= intervalNum) {
24
+ callback();
25
+ elapsedTime = 0;
26
+ }
27
+ };
28
+ immediately && callback();
29
+ ticker.add(tickerCallback);
30
+ ticker.start();
31
+ return () => {
32
+ ticker.remove(tickerCallback);
33
+ ticker.stop();
34
+ };
35
+ };
@@ -0,0 +1,8 @@
1
+ import type { Container } from "pixi.js";
2
+ /** @description 点击容器外或入口按钮时隐藏
3
+ * @param container 容器
4
+ * @param btn 按钮
5
+ * @param onClose 关闭回调
6
+ * @link 使用方法:https://www.npmjs.com/package/lyb-pixi-js#LibPixiOutsideClick-失焦隐藏
7
+ */
8
+ export declare const libPixiOutsideClick: (container: Container, btn: Container, onClose: () => void) => () => void;
@@ -0,0 +1,22 @@
1
+ /** @description 点击容器外或入口按钮时隐藏
2
+ * @param container 容器
3
+ * @param btn 按钮
4
+ * @param onClose 关闭回调
5
+ * @link 使用方法:https://www.npmjs.com/package/lyb-pixi-js#LibPixiOutsideClick-失焦隐藏
6
+ */
7
+ export const libPixiOutsideClick = (container, btn, onClose) => {
8
+ const outsideClick = (e) => {
9
+ const btnInside = btn.getBounds().contains(e.clientX, e.clientY);
10
+ const containerInside = container
11
+ .getBounds()
12
+ .contains(e.clientX, e.clientY);
13
+ if (!btnInside && !containerInside && container.visible) {
14
+ onClose();
15
+ window.removeEventListener("pointerdown", outsideClick);
16
+ }
17
+ };
18
+ window.addEventListener("pointerdown", outsideClick);
19
+ return () => {
20
+ window.removeEventListener("pointerdown", outsideClick);
21
+ };
22
+ };