lyb-pixi-js 1.12.40 → 1.12.41

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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/LibPixiHeadingParagraphLayout.d.ts +18 -0
  46. package/Components/Custom/LibPixiHeadingParagraphLayout.js +27 -0
  47. package/Components/Custom/LibPixiInput.d.ts +77 -0
  48. package/Components/Custom/LibPixiInput.js +198 -0
  49. package/Components/Custom/LibPixiLabelValue.d.ts +30 -0
  50. package/Components/Custom/LibPixiLabelValue.js +26 -0
  51. package/Components/Custom/LibPixiPerforMon.d.ts +47 -0
  52. package/Components/Custom/LibPixiPerforMon.js +166 -0
  53. package/Components/Custom/LibPixiProgress.d.ts +33 -0
  54. package/Components/Custom/LibPixiProgress.js +47 -0
  55. package/Components/Custom/LibPixiPuzzleBg.d.ts +7 -0
  56. package/Components/Custom/LibPixiPuzzleBg.js +46 -0
  57. package/Components/Custom/LibPixiScrollContainerX.d.ts +71 -0
  58. package/Components/Custom/LibPixiScrollContainerX.js +198 -0
  59. package/Components/Custom/LibPixiScrollContainerY.d.ts +109 -0
  60. package/Components/Custom/LibPixiScrollContainerY.js +340 -0
  61. package/Components/Custom/LibPixiScrollNum.d.ts +67 -0
  62. package/Components/Custom/LibPixiScrollNum.js +184 -0
  63. package/Components/Custom/LibPixiSlide.d.ts +94 -0
  64. package/Components/Custom/LibPixiSlide.js +285 -0
  65. package/Components/Custom/LibPixiSlider.d.ts +82 -0
  66. package/Components/Custom/LibPixiSlider.js +165 -0
  67. package/Components/Custom/LibPixiTable.d.ts +64 -0
  68. package/Components/Custom/LibPixiTable.js +76 -0
  69. package/Components/Custom/LibPixiTextGroupWrap.d.ts +20 -0
  70. package/Components/Custom/LibPixiTextGroupWrap.js +50 -0
  71. package/Components/Custom/LibPixiTriangle.d.ts +5 -0
  72. package/Components/Custom/LibPixiTriangle.js +12 -0
  73. package/Components/Custom/LibPixiTurntable.d.ts +6 -0
  74. package/Components/Custom/LibPixiTurntable.js +14 -0
  75. package/Utils/LibContainerCenter.d.ts +3 -0
  76. package/Utils/LibContainerCenter.js +10 -0
  77. package/Utils/LibControlledDelayedCall.d.ts +5 -0
  78. package/Utils/LibControlledDelayedCall.js +20 -0
  79. package/Utils/LibPixiArrangeLinear.d.ts +16 -0
  80. package/Utils/LibPixiArrangeLinear.js +62 -0
  81. package/Utils/LibPixiAudio.d.ts +53 -0
  82. package/Utils/LibPixiAudio.js +168 -0
  83. package/Utils/LibPixiCreateNineGrid.d.ts +15 -0
  84. package/Utils/LibPixiCreateNineGrid.js +19 -0
  85. package/Utils/LibPixiDialogManager/index.d.ts +25 -0
  86. package/Utils/LibPixiDialogManager/index.js +43 -0
  87. package/Utils/LibPixiDialogManager/ui/LibPixiBaseContainer.d.ts +11 -0
  88. package/Utils/LibPixiDialogManager/ui/LibPixiBaseContainer.js +31 -0
  89. package/Utils/LibPixiDialogManager/ui/LibPixiDialog.d.ts +40 -0
  90. package/Utils/LibPixiDialogManager/ui/LibPixiDialog.js +145 -0
  91. package/Utils/LibPixiDigitalIncreasingAnimation.d.ts +18 -0
  92. package/Utils/LibPixiDigitalIncreasingAnimation.js +26 -0
  93. package/Utils/LibPixiDownScaleAnimation.d.ts +7 -0
  94. package/Utils/LibPixiDownScaleAnimation.js +33 -0
  95. package/Utils/LibPixiEmitContainerEvent.d.ts +7 -0
  96. package/Utils/LibPixiEmitContainerEvent.js +13 -0
  97. package/Utils/LibPixiEvent.d.ts +19 -0
  98. package/Utils/LibPixiEvent.js +68 -0
  99. package/Utils/LibPixiFilter.d.ts +9 -0
  100. package/Utils/LibPixiFilter.js +34 -0
  101. package/Utils/LibPixiGlobalUpdater.d.ts +15 -0
  102. package/Utils/LibPixiGlobalUpdater.js +21 -0
  103. package/Utils/LibPixiGridLayout.d.ts +10 -0
  104. package/Utils/LibPixiGridLayout.js +27 -0
  105. package/Utils/LibPixiHVCenter.d.ts +7 -0
  106. package/Utils/LibPixiHVCenter.js +14 -0
  107. package/Utils/LibPixiHVGap.d.ts +8 -0
  108. package/Utils/LibPixiHVGap.js +26 -0
  109. package/Utils/LibPixiIntervalTrigger.d.ts +7 -0
  110. package/Utils/LibPixiIntervalTrigger.js +35 -0
  111. package/Utils/LibPixiOutsideClick.d.ts +8 -0
  112. package/Utils/LibPixiOutsideClick.js +22 -0
  113. package/Utils/LibPixiOverflowHidden.d.ts +6 -0
  114. package/Utils/LibPixiOverflowHidden.js +14 -0
  115. package/Utils/LibPixiPolygonDrawTool.d.ts +44 -0
  116. package/Utils/LibPixiPolygonDrawTool.js +114 -0
  117. package/Utils/LibPixiPromiseTickerTimeout.d.ts +6 -0
  118. package/Utils/LibPixiPromiseTickerTimeout.js +22 -0
  119. package/Utils/LibPixiScaleContainer.d.ts +8 -0
  120. package/Utils/LibPixiScaleContainer.js +14 -0
  121. package/Utils/LibPixiShadow.d.ts +17 -0
  122. package/Utils/LibPixiShadow.js +18 -0
  123. package/Utils/LibPixiSlideInput.d.ts +55 -0
  124. package/Utils/LibPixiSlideInput.js +61 -0
  125. package/Utils/LibPixiTicker.d.ts +14 -0
  126. package/Utils/LibPixiTicker.js +49 -0
  127. package/Utils/LibPixiTickerTimeout.d.ts +6 -0
  128. package/Utils/LibPixiTickerTimeout.js +22 -0
  129. package/package.json +1 -1
@@ -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
+ };
@@ -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
+ };