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.
- package/Components/Base/LibPixiArc.d.ts +16 -0
- package/Components/Base/LibPixiArc.js +14 -0
- package/Components/Base/LibPixiBitText.d.ts +20 -0
- package/Components/Base/LibPixiBitText.js +26 -0
- package/Components/Base/LibPixiCircular.d.ts +7 -0
- package/Components/Base/LibPixiCircular.js +12 -0
- package/Components/Base/LibPixiContainer.d.ts +22 -0
- package/Components/Base/LibPixiContainer.js +51 -0
- package/Components/Base/LibPixiHtmlText.d.ts +31 -0
- package/Components/Base/LibPixiHtmlText.js +30 -0
- package/Components/Base/LibPixiOval.d.ts +5 -0
- package/Components/Base/LibPixiOval.js +10 -0
- package/Components/Base/LibPixiParticleMove.d.ts +101 -0
- package/Components/Base/LibPixiParticleMove.js +136 -0
- package/Components/Base/LibPixiPolygon.d.ts +7 -0
- package/Components/Base/LibPixiPolygon.js +15 -0
- package/Components/Base/LibPixiRectBgColor.d.ts +41 -0
- package/Components/Base/LibPixiRectBgColor.js +95 -0
- package/Components/Base/LibPixiRectangle.d.ts +7 -0
- package/Components/Base/LibPixiRectangle.js +15 -0
- package/Components/Base/LibPixiRound.d.ts +5 -0
- package/Components/Base/LibPixiRound.js +9 -0
- package/Components/Base/LibPixiRoundedRect.d.ts +5 -0
- package/Components/Base/LibPixiRoundedRect.js +10 -0
- package/Components/Base/LibPixiSpine.d.ts +58 -0
- package/Components/Base/LibPixiSpine.js +128 -0
- package/Components/Base/LibPixiText.d.ts +37 -0
- package/Components/Base/LibPixiText.js +35 -0
- package/Components/Custom/LibPixiAreaClick.d.ts +6 -0
- package/Components/Custom/LibPixiAreaClick.js +16 -0
- package/Components/Custom/LibPixiArrangeLinearV2.d.ts +25 -0
- package/Components/Custom/LibPixiArrangeLinearV2.js +80 -0
- package/Components/Custom/LibPixiButtonHover.d.ts +40 -0
- package/Components/Custom/LibPixiButtonHover.js +53 -0
- package/Components/Custom/LibPixiCapsule.d.ts +5 -0
- package/Components/Custom/LibPixiCapsule.js +10 -0
- package/Components/Custom/LibPixiCloseBtn.d.ts +14 -0
- package/Components/Custom/LibPixiCloseBtn.js +36 -0
- package/Components/Custom/LibPixiDragLocate.d.ts +36 -0
- package/Components/Custom/LibPixiDragLocate.js +230 -0
- package/Components/Custom/LibPixiDrawer.d.ts +16 -0
- package/Components/Custom/LibPixiDrawer.js +59 -0
- package/Components/Custom/LibPixiGridLayoutV2.d.ts +27 -0
- package/Components/Custom/LibPixiGridLayoutV2.js +37 -0
- package/Components/Custom/LibPixiHeadingParagraphLayout.d.ts +18 -0
- package/Components/Custom/LibPixiHeadingParagraphLayout.js +27 -0
- package/Components/Custom/LibPixiInput.d.ts +77 -0
- package/Components/Custom/LibPixiInput.js +198 -0
- package/Components/Custom/LibPixiLabelValue.d.ts +30 -0
- package/Components/Custom/LibPixiLabelValue.js +26 -0
- package/Components/Custom/LibPixiPerforMon.d.ts +47 -0
- package/Components/Custom/LibPixiPerforMon.js +166 -0
- package/Components/Custom/LibPixiProgress.d.ts +33 -0
- package/Components/Custom/LibPixiProgress.js +47 -0
- package/Components/Custom/LibPixiPuzzleBg.d.ts +7 -0
- package/Components/Custom/LibPixiPuzzleBg.js +46 -0
- package/Components/Custom/LibPixiScrollContainerX.d.ts +71 -0
- package/Components/Custom/LibPixiScrollContainerX.js +198 -0
- package/Components/Custom/LibPixiScrollContainerY.d.ts +109 -0
- package/Components/Custom/LibPixiScrollContainerY.js +340 -0
- package/Components/Custom/LibPixiScrollNum.d.ts +67 -0
- package/Components/Custom/LibPixiScrollNum.js +184 -0
- package/Components/Custom/LibPixiSlide.d.ts +94 -0
- package/Components/Custom/LibPixiSlide.js +285 -0
- package/Components/Custom/LibPixiSlider.d.ts +82 -0
- package/Components/Custom/LibPixiSlider.js +165 -0
- package/Components/Custom/LibPixiTable.d.ts +64 -0
- package/Components/Custom/LibPixiTable.js +76 -0
- package/Components/Custom/LibPixiTextGroupWrap.d.ts +20 -0
- package/Components/Custom/LibPixiTextGroupWrap.js +50 -0
- package/Components/Custom/LibPixiTriangle.d.ts +5 -0
- package/Components/Custom/LibPixiTriangle.js +12 -0
- package/Components/Custom/LibPixiTurntable.d.ts +6 -0
- package/Components/Custom/LibPixiTurntable.js +14 -0
- package/Utils/LibContainerCenter.d.ts +3 -0
- package/Utils/LibContainerCenter.js +10 -0
- package/Utils/LibControlledDelayedCall.d.ts +5 -0
- package/Utils/LibControlledDelayedCall.js +20 -0
- package/Utils/LibPixiArrangeLinear.d.ts +16 -0
- package/Utils/LibPixiArrangeLinear.js +62 -0
- package/Utils/LibPixiAudio.d.ts +53 -0
- package/Utils/LibPixiAudio.js +168 -0
- package/Utils/LibPixiCreateNineGrid.d.ts +15 -0
- package/Utils/LibPixiCreateNineGrid.js +19 -0
- package/Utils/LibPixiDialogManager/index.d.ts +25 -0
- package/Utils/LibPixiDialogManager/index.js +43 -0
- package/Utils/LibPixiDialogManager/ui/LibPixiBaseContainer.d.ts +11 -0
- package/Utils/LibPixiDialogManager/ui/LibPixiBaseContainer.js +31 -0
- package/Utils/LibPixiDialogManager/ui/LibPixiDialog.d.ts +40 -0
- package/Utils/LibPixiDialogManager/ui/LibPixiDialog.js +145 -0
- package/Utils/LibPixiDigitalIncreasingAnimation.d.ts +18 -0
- package/Utils/LibPixiDigitalIncreasingAnimation.js +26 -0
- package/Utils/LibPixiDownScaleAnimation.d.ts +7 -0
- package/Utils/LibPixiDownScaleAnimation.js +33 -0
- package/Utils/LibPixiEmitContainerEvent.d.ts +7 -0
- package/Utils/LibPixiEmitContainerEvent.js +13 -0
- package/Utils/LibPixiEvent.d.ts +19 -0
- package/Utils/LibPixiEvent.js +68 -0
- package/Utils/LibPixiFilter.d.ts +9 -0
- package/Utils/LibPixiFilter.js +34 -0
- package/Utils/LibPixiGlobalUpdater.d.ts +15 -0
- package/Utils/LibPixiGlobalUpdater.js +21 -0
- package/Utils/LibPixiGridLayout.d.ts +10 -0
- package/Utils/LibPixiGridLayout.js +27 -0
- package/Utils/LibPixiHVCenter.d.ts +7 -0
- package/Utils/LibPixiHVCenter.js +14 -0
- package/Utils/LibPixiHVGap.d.ts +8 -0
- package/Utils/LibPixiHVGap.js +26 -0
- package/Utils/LibPixiIntervalTrigger.d.ts +7 -0
- package/Utils/LibPixiIntervalTrigger.js +35 -0
- package/Utils/LibPixiOutsideClick.d.ts +8 -0
- package/Utils/LibPixiOutsideClick.js +22 -0
- package/Utils/LibPixiOverflowHidden.d.ts +6 -0
- package/Utils/LibPixiOverflowHidden.js +14 -0
- package/Utils/LibPixiPolygonDrawTool.d.ts +44 -0
- package/Utils/LibPixiPolygonDrawTool.js +114 -0
- package/Utils/LibPixiPromiseTickerTimeout.d.ts +6 -0
- package/Utils/LibPixiPromiseTickerTimeout.js +22 -0
- package/Utils/LibPixiScaleContainer.d.ts +8 -0
- package/Utils/LibPixiScaleContainer.js +14 -0
- package/Utils/LibPixiShadow.d.ts +17 -0
- package/Utils/LibPixiShadow.js +18 -0
- package/Utils/LibPixiSlideInput.d.ts +55 -0
- package/Utils/LibPixiSlideInput.js +61 -0
- package/Utils/LibPixiTicker.d.ts +14 -0
- package/Utils/LibPixiTicker.js +49 -0
- package/Utils/LibPixiTickerTimeout.d.ts +6 -0
- package/Utils/LibPixiTickerTimeout.js +22 -0
- package/package.json +1 -1
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { Container } from "pixi.js";
|
|
2
|
+
import { LibPixiContainer } from "../Base/LibPixiContainer";
|
|
3
|
+
interface LibPixiSliderParams {
|
|
4
|
+
/** 滑动区域宽度 */
|
|
5
|
+
width: number;
|
|
6
|
+
/** 滑动区域高度 */
|
|
7
|
+
height: number;
|
|
8
|
+
/** 滑动页列表 */
|
|
9
|
+
slideList: Container[];
|
|
10
|
+
/** 是否启用循环滑动 */
|
|
11
|
+
loop?: boolean;
|
|
12
|
+
/** 是否启用景深 */
|
|
13
|
+
enableDepth?: boolean;
|
|
14
|
+
/** 景深透明度 */
|
|
15
|
+
depthAlpha?: number;
|
|
16
|
+
/** 景深缩放 */
|
|
17
|
+
depthScale?: number;
|
|
18
|
+
/** 滑动回调 */
|
|
19
|
+
slideCallback: (pageIndex: number, _pageNum: number) => void;
|
|
20
|
+
}
|
|
21
|
+
/** @description 类似轮播图,但是不会自动轮播
|
|
22
|
+
* @link 使用方法:https://www.npmjs.com/package/lyb-pixi-js#LibPixiSlider-横向滑动图
|
|
23
|
+
*/
|
|
24
|
+
export declare class LibPixiSlider extends LibPixiContainer {
|
|
25
|
+
/** 当前幻灯片索引 */
|
|
26
|
+
private _currentIndex;
|
|
27
|
+
/** 滑动区域宽度 */
|
|
28
|
+
private _slideWidth;
|
|
29
|
+
/** 滑动区域高度 */
|
|
30
|
+
private _slideHeight;
|
|
31
|
+
/** 是否启用循环 */
|
|
32
|
+
private _loop;
|
|
33
|
+
/** 记录拖动开始时的X坐标 */
|
|
34
|
+
private _startX;
|
|
35
|
+
/** 偏移量 */
|
|
36
|
+
private _offsetX;
|
|
37
|
+
/** 最大索引 */
|
|
38
|
+
private _pageNum;
|
|
39
|
+
/** 记录开始时间 */
|
|
40
|
+
private _startTime;
|
|
41
|
+
private _isDragging;
|
|
42
|
+
/** 滑动内容 */
|
|
43
|
+
private _slideArea;
|
|
44
|
+
/** 是否启用景深 */
|
|
45
|
+
private _enableDepth;
|
|
46
|
+
/** 景深透明度 */
|
|
47
|
+
private _depthAlpha;
|
|
48
|
+
/** 景深缩放 */
|
|
49
|
+
private _depthScale;
|
|
50
|
+
/** 滑动容器列表 */
|
|
51
|
+
private _slideList;
|
|
52
|
+
/** @description 滑动回调 */
|
|
53
|
+
private slideCallback;
|
|
54
|
+
/**
|
|
55
|
+
* @param width 宽度
|
|
56
|
+
* @param height 高度
|
|
57
|
+
* @param content 内容
|
|
58
|
+
* @param slideCallback 滑动结束回调
|
|
59
|
+
*/
|
|
60
|
+
constructor(params: LibPixiSliderParams);
|
|
61
|
+
/** @description 上一页 */
|
|
62
|
+
prev(): void;
|
|
63
|
+
/** @description 下一页 */
|
|
64
|
+
next(): void;
|
|
65
|
+
/** @description 滑动到指定索引
|
|
66
|
+
* @param index 索引
|
|
67
|
+
*/
|
|
68
|
+
private _slideTo;
|
|
69
|
+
/** @description 开始拖动 */
|
|
70
|
+
private _onDragStart;
|
|
71
|
+
/** @description 拖动中 */
|
|
72
|
+
private _onDragMove;
|
|
73
|
+
/** @description 结束拖动 */
|
|
74
|
+
private _onDragEnd;
|
|
75
|
+
/** @description 设置滚动景深
|
|
76
|
+
* @param containerList 元素列表
|
|
77
|
+
* @param y 拖动Y坐标
|
|
78
|
+
* @param startY 内部将y - startY进行计算
|
|
79
|
+
*/
|
|
80
|
+
private _setDepth;
|
|
81
|
+
}
|
|
82
|
+
export {};
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
import { Container } from "pixi.js";
|
|
2
|
+
import gsap from "gsap";
|
|
3
|
+
import { LibJsLerp } from "lyb-js/Math/LibJsLerp.js";
|
|
4
|
+
import { libPixiOverflowHidden } from "../../Utils/LibPixiOverflowHidden";
|
|
5
|
+
import { LibPixiContainer } from "../Base/LibPixiContainer";
|
|
6
|
+
import { libPixiEvent } from "../../Utils/LibPixiEvent";
|
|
7
|
+
/** @description 类似轮播图,但是不会自动轮播
|
|
8
|
+
* @link 使用方法:https://www.npmjs.com/package/lyb-pixi-js#LibPixiSlider-横向滑动图
|
|
9
|
+
*/
|
|
10
|
+
export class LibPixiSlider extends LibPixiContainer {
|
|
11
|
+
/**
|
|
12
|
+
* @param width 宽度
|
|
13
|
+
* @param height 高度
|
|
14
|
+
* @param content 内容
|
|
15
|
+
* @param slideCallback 滑动结束回调
|
|
16
|
+
*/
|
|
17
|
+
constructor(params) {
|
|
18
|
+
const { width, height, slideList, slideCallback, loop = false, enableDepth = false, depthAlpha = 0.5, depthScale = 0.5, } = params;
|
|
19
|
+
super(width, height);
|
|
20
|
+
/** 当前幻灯片索引 */
|
|
21
|
+
this._currentIndex = 0;
|
|
22
|
+
/** 滑动区域宽度 */
|
|
23
|
+
this._slideWidth = 0;
|
|
24
|
+
/** 滑动区域高度 */
|
|
25
|
+
this._slideHeight = 0;
|
|
26
|
+
/** 是否启用循环 */
|
|
27
|
+
this._loop = false;
|
|
28
|
+
/** 记录拖动开始时的X坐标 */
|
|
29
|
+
this._startX = 0;
|
|
30
|
+
/** 偏移量 */
|
|
31
|
+
this._offsetX = 0;
|
|
32
|
+
/** 最大索引 */
|
|
33
|
+
this._pageNum = 0;
|
|
34
|
+
/** 记录开始时间 */
|
|
35
|
+
this._startTime = new Date().getTime();
|
|
36
|
+
/* 是否正在拖动 */
|
|
37
|
+
this._isDragging = false;
|
|
38
|
+
libPixiOverflowHidden(this);
|
|
39
|
+
this._slideArea = new Container();
|
|
40
|
+
this._slideWidth = width;
|
|
41
|
+
this._slideHeight = height;
|
|
42
|
+
this._loop = loop;
|
|
43
|
+
this._slideList = slideList;
|
|
44
|
+
this._enableDepth = enableDepth;
|
|
45
|
+
this._depthAlpha = depthAlpha;
|
|
46
|
+
this._depthScale = depthScale;
|
|
47
|
+
this.slideCallback = slideCallback;
|
|
48
|
+
this._pageNum = slideList.length - 1;
|
|
49
|
+
this._slideList.forEach((item, index) => {
|
|
50
|
+
this._slideArea.addChild(item);
|
|
51
|
+
item.x = index * width + this._slideWidth / 2;
|
|
52
|
+
item.y = this._slideHeight / 2;
|
|
53
|
+
item.pivot.set(this._slideWidth / 2, this._slideHeight / 2);
|
|
54
|
+
});
|
|
55
|
+
this.addChild(this._slideArea);
|
|
56
|
+
libPixiEvent(this, "pointerdown", this._onDragStart.bind(this));
|
|
57
|
+
window.addEventListener("pointermove", this._onDragMove.bind(this));
|
|
58
|
+
window.addEventListener("pointerup", this._onDragEnd.bind(this));
|
|
59
|
+
}
|
|
60
|
+
/** @description 上一页 */
|
|
61
|
+
prev() {
|
|
62
|
+
this._slideTo(this._currentIndex - 1);
|
|
63
|
+
}
|
|
64
|
+
/** @description 下一页 */
|
|
65
|
+
next() {
|
|
66
|
+
this._slideTo(this._currentIndex + 1);
|
|
67
|
+
}
|
|
68
|
+
/** @description 滑动到指定索引
|
|
69
|
+
* @param index 索引
|
|
70
|
+
*/
|
|
71
|
+
_slideTo(index) {
|
|
72
|
+
let x = 0;
|
|
73
|
+
if (this._loop) {
|
|
74
|
+
this._currentIndex =
|
|
75
|
+
(index + this._slideList.length) % this._slideList.length;
|
|
76
|
+
x = -this._currentIndex * this._slideWidth;
|
|
77
|
+
}
|
|
78
|
+
else {
|
|
79
|
+
if (index < 0) {
|
|
80
|
+
// 回弹到第一张
|
|
81
|
+
x = 0;
|
|
82
|
+
this._currentIndex = 0;
|
|
83
|
+
}
|
|
84
|
+
else if (index > this._pageNum) {
|
|
85
|
+
// 回弹到最后一张
|
|
86
|
+
x = -this._pageNum * this._slideWidth;
|
|
87
|
+
this._currentIndex = this._pageNum;
|
|
88
|
+
}
|
|
89
|
+
else {
|
|
90
|
+
// 正常滑动
|
|
91
|
+
x = -index * this._slideWidth;
|
|
92
|
+
this._currentIndex = index;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
gsap.to(this._slideArea, {
|
|
96
|
+
x,
|
|
97
|
+
duration: 0.25,
|
|
98
|
+
onUpdate: () => {
|
|
99
|
+
this._setDepth();
|
|
100
|
+
},
|
|
101
|
+
});
|
|
102
|
+
this.slideCallback(this._currentIndex, this._pageNum);
|
|
103
|
+
}
|
|
104
|
+
/** @description 开始拖动 */
|
|
105
|
+
_onDragStart(event) {
|
|
106
|
+
this._isDragging = true;
|
|
107
|
+
this._startX = event.global.x;
|
|
108
|
+
this._offsetX = this._slideArea.x;
|
|
109
|
+
gsap.killTweensOf(this._slideArea);
|
|
110
|
+
this._startTime = new Date().getTime();
|
|
111
|
+
}
|
|
112
|
+
/** @description 拖动中 */
|
|
113
|
+
_onDragMove(event) {
|
|
114
|
+
if (!this._isDragging)
|
|
115
|
+
return;
|
|
116
|
+
const moveX = event.pageX - this._startX;
|
|
117
|
+
this._slideArea.x = this._offsetX + moveX;
|
|
118
|
+
this._setDepth();
|
|
119
|
+
}
|
|
120
|
+
/** @description 结束拖动 */
|
|
121
|
+
_onDragEnd(event) {
|
|
122
|
+
if (!this._isDragging)
|
|
123
|
+
return;
|
|
124
|
+
this._isDragging = false;
|
|
125
|
+
const endTime = new Date().getTime() - this._startTime;
|
|
126
|
+
const slide = this._startX - event.pageX;
|
|
127
|
+
const slideSpeed = Math.abs(slide) / endTime;
|
|
128
|
+
//滑动距离阈值,滑动到一半以上必定翻页
|
|
129
|
+
const slideThreshold = this._slideWidth / 2;
|
|
130
|
+
//滑动速度阈值,滑动速度大于这个值,必定翻页
|
|
131
|
+
const speedThreshold = 0.275;
|
|
132
|
+
//如果滑动距离大于阈值,或速度大于阈值翻页
|
|
133
|
+
if (Math.abs(slide) > slideThreshold || slideSpeed > speedThreshold) {
|
|
134
|
+
slide > 0 ? this._currentIndex++ : this._currentIndex--;
|
|
135
|
+
}
|
|
136
|
+
this._slideTo(this._currentIndex);
|
|
137
|
+
}
|
|
138
|
+
/** @description 设置滚动景深
|
|
139
|
+
* @param containerList 元素列表
|
|
140
|
+
* @param y 拖动Y坐标
|
|
141
|
+
* @param startY 内部将y - startY进行计算
|
|
142
|
+
*/
|
|
143
|
+
_setDepth() {
|
|
144
|
+
if (!this._enableDepth)
|
|
145
|
+
return;
|
|
146
|
+
const Y = this._slideArea.x;
|
|
147
|
+
const idx = Math.floor(Math.abs(Y) / this._slideWidth);
|
|
148
|
+
const t = (Math.abs(Y) % this._slideWidth) / this._slideWidth;
|
|
149
|
+
const prevIdx = idx - 1;
|
|
150
|
+
const nextIdx = idx + 1;
|
|
151
|
+
const curItem = this._slideList[idx];
|
|
152
|
+
curItem.alpha = LibJsLerp(this._depthAlpha, 1, 1 - t);
|
|
153
|
+
curItem.scale.set(LibJsLerp(this._depthScale, 1, 1 - t));
|
|
154
|
+
if (nextIdx < this._slideList.length) {
|
|
155
|
+
const nextItem = this._slideList[nextIdx];
|
|
156
|
+
nextItem.alpha = LibJsLerp(this._depthAlpha, 1, t);
|
|
157
|
+
nextItem.scale.set(LibJsLerp(this._depthScale, 1, t));
|
|
158
|
+
}
|
|
159
|
+
if (prevIdx >= 0) {
|
|
160
|
+
const prevItem = this._slideList[prevIdx];
|
|
161
|
+
prevItem.alpha = LibJsLerp(this._depthAlpha, 1, 1 - t);
|
|
162
|
+
prevItem.scale.set(LibJsLerp(this._depthScale, 1, 1 - t));
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/** @description 表格绘制并填入数字 */
|
|
2
|
+
import { Container } from "pixi.js";
|
|
3
|
+
export interface LibPixiTableParams {
|
|
4
|
+
/** 表格数据 */
|
|
5
|
+
data: (number | string)[][];
|
|
6
|
+
/** 是否需要表格外框 */
|
|
7
|
+
outsideBorder?: boolean;
|
|
8
|
+
/** 单元格宽度 */
|
|
9
|
+
cellWidth?: number;
|
|
10
|
+
/** 单元格高度 */
|
|
11
|
+
cellHeight?: number;
|
|
12
|
+
/** 字体大小 */
|
|
13
|
+
fontSize?: number;
|
|
14
|
+
/** 字体颜色 */
|
|
15
|
+
fontColor?: string;
|
|
16
|
+
/** 表格第一列字体颜色 */
|
|
17
|
+
firstColumnFontColor?: string;
|
|
18
|
+
/** 是否需要加粗 */
|
|
19
|
+
fontBold?: boolean;
|
|
20
|
+
/** 线条厚度 */
|
|
21
|
+
lineWidth?: number;
|
|
22
|
+
/** 线条颜色 */
|
|
23
|
+
lineColor?: string;
|
|
24
|
+
}
|
|
25
|
+
/** @description 绘制表格并填充数字
|
|
26
|
+
* @link 使用方法:https://www.npmjs.com/package/lyb-pixi-js#LibPixiTable-数字表格
|
|
27
|
+
*/
|
|
28
|
+
export declare class LibPixiTable extends Container {
|
|
29
|
+
/** 行数 */
|
|
30
|
+
private _rows;
|
|
31
|
+
/** 列数 */
|
|
32
|
+
private _cols;
|
|
33
|
+
/** 单元格宽度 */
|
|
34
|
+
private _cellWidth;
|
|
35
|
+
/** 单元格高度 */
|
|
36
|
+
private _cellHeight;
|
|
37
|
+
/** 字体大小 */
|
|
38
|
+
private _fontSize;
|
|
39
|
+
/** 线条宽度 */
|
|
40
|
+
private _lineWidth;
|
|
41
|
+
/** 字体颜色 */
|
|
42
|
+
private _fontColor;
|
|
43
|
+
/** 表格第一列字体颜色 */
|
|
44
|
+
private _firstColumnFontColor;
|
|
45
|
+
/** 线条颜色 */
|
|
46
|
+
private _lineColor;
|
|
47
|
+
/** 是否需要表格外框 */
|
|
48
|
+
private _outsideBorder;
|
|
49
|
+
/** 是否需要加粗 */
|
|
50
|
+
private _fontBold;
|
|
51
|
+
/** 二维数字数组 */
|
|
52
|
+
private _data;
|
|
53
|
+
constructor(params: LibPixiTableParams);
|
|
54
|
+
/** @description 绘制表格 */
|
|
55
|
+
private _drawTable;
|
|
56
|
+
/** @description 填充数字 */
|
|
57
|
+
private fillNumbers;
|
|
58
|
+
/** @description 创建数字文本
|
|
59
|
+
* @param number 数字
|
|
60
|
+
* @param col 列索引
|
|
61
|
+
* @param row 行索引
|
|
62
|
+
*/
|
|
63
|
+
private _createNumberText;
|
|
64
|
+
}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
/** @description 表格绘制并填入数字 */
|
|
2
|
+
import { Container, Graphics, Text } from "pixi.js";
|
|
3
|
+
import { libPixiScaleContainer } from '../../Utils/LibPixiScaleContainer';
|
|
4
|
+
/** @description 绘制表格并填充数字
|
|
5
|
+
* @link 使用方法:https://www.npmjs.com/package/lyb-pixi-js#LibPixiTable-数字表格
|
|
6
|
+
*/
|
|
7
|
+
export class LibPixiTable extends Container {
|
|
8
|
+
constructor(params) {
|
|
9
|
+
super();
|
|
10
|
+
const { data, cellWidth = 130, cellHeight = 100, fontColor = "#fff", firstColumnFontColor = "#fff", fontSize = 30, lineWidth = 2, lineColor = "#5b5b5b", outsideBorder = true, fontBold = true, } = params;
|
|
11
|
+
this._data = data;
|
|
12
|
+
this._rows = data.length;
|
|
13
|
+
this._cols = data[0].length;
|
|
14
|
+
this._cellWidth = cellWidth;
|
|
15
|
+
this._cellHeight = cellHeight;
|
|
16
|
+
this._fontColor = fontColor;
|
|
17
|
+
this._fontSize = fontSize;
|
|
18
|
+
this._lineWidth = lineWidth;
|
|
19
|
+
this._lineColor = lineColor;
|
|
20
|
+
this._outsideBorder = outsideBorder;
|
|
21
|
+
this._fontBold = fontBold;
|
|
22
|
+
this._firstColumnFontColor = firstColumnFontColor;
|
|
23
|
+
this._drawTable();
|
|
24
|
+
this.fillNumbers();
|
|
25
|
+
}
|
|
26
|
+
/** @description 绘制表格 */
|
|
27
|
+
_drawTable() {
|
|
28
|
+
const tableWidth = this._cellWidth * this._cols;
|
|
29
|
+
const tableHeight = this._cellHeight * this._rows;
|
|
30
|
+
const graphics = new Graphics();
|
|
31
|
+
graphics.lineStyle(this._lineWidth, this._lineColor);
|
|
32
|
+
// 绘制表格外框
|
|
33
|
+
if (this._outsideBorder) {
|
|
34
|
+
graphics.drawRect(0, 0, tableWidth, tableHeight);
|
|
35
|
+
}
|
|
36
|
+
// 绘制横线
|
|
37
|
+
for (let i = 1; i < this._rows; i++) {
|
|
38
|
+
graphics.moveTo(0, i * this._cellHeight);
|
|
39
|
+
graphics.lineTo(tableWidth, i * this._cellHeight);
|
|
40
|
+
}
|
|
41
|
+
// 绘制竖线
|
|
42
|
+
for (let j = 1; j < this._cols; j++) {
|
|
43
|
+
graphics.moveTo(j * this._cellWidth, 0);
|
|
44
|
+
graphics.lineTo(j * this._cellWidth, tableHeight);
|
|
45
|
+
}
|
|
46
|
+
this.addChild(graphics);
|
|
47
|
+
}
|
|
48
|
+
/** @description 填充数字 */
|
|
49
|
+
fillNumbers() {
|
|
50
|
+
for (let row = 0; row < this._rows; row++) {
|
|
51
|
+
for (let col = 0; col < this._cols; col++) {
|
|
52
|
+
const number = this._data[row][col];
|
|
53
|
+
this._createNumberText(number, col, row);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
/** @description 创建数字文本
|
|
58
|
+
* @param number 数字
|
|
59
|
+
* @param col 列索引
|
|
60
|
+
* @param row 行索引
|
|
61
|
+
*/
|
|
62
|
+
_createNumberText(number, col, row) {
|
|
63
|
+
const text = new Text(number.toString(), {
|
|
64
|
+
_fontSize: this._fontSize,
|
|
65
|
+
fill: col === 0 ? this._firstColumnFontColor : this._fontColor,
|
|
66
|
+
fontWeight: this._fontBold ? "bold" : "normal",
|
|
67
|
+
});
|
|
68
|
+
// 计算文本的居中位置
|
|
69
|
+
const x = col * this._cellWidth + this._cellWidth / 2;
|
|
70
|
+
const y = row * this._cellHeight + this._cellHeight / 2;
|
|
71
|
+
this.addChild(text);
|
|
72
|
+
text.anchor.set(0.5);
|
|
73
|
+
text.position.set(x, y);
|
|
74
|
+
libPixiScaleContainer(text, this._cellWidth * 0.9);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { Container, type ITextStyle } from "pixi.js";
|
|
2
|
+
interface TextItem {
|
|
3
|
+
text: string;
|
|
4
|
+
style?: Partial<ITextStyle>;
|
|
5
|
+
}
|
|
6
|
+
interface TextGroupOptions {
|
|
7
|
+
items: TextItem[];
|
|
8
|
+
defaultStyle?: Partial<ITextStyle>;
|
|
9
|
+
wordWrapWidth?: number;
|
|
10
|
+
paddingX?: number;
|
|
11
|
+
paddingY?: number;
|
|
12
|
+
align?: "left" | "center" | "right";
|
|
13
|
+
anchorX?: number;
|
|
14
|
+
anchorY?: number;
|
|
15
|
+
}
|
|
16
|
+
/** @description 文本组换行 */
|
|
17
|
+
export declare class LibPixiTextGroupWrap extends Container {
|
|
18
|
+
constructor({ items, defaultStyle, wordWrapWidth, paddingX, paddingY, align, anchorX, anchorY, }: TextGroupOptions);
|
|
19
|
+
}
|
|
20
|
+
export {};
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { Container, Text } from "pixi.js";
|
|
2
|
+
/** @description 文本组换行 */
|
|
3
|
+
export class LibPixiTextGroupWrap extends Container {
|
|
4
|
+
constructor({ items, defaultStyle = {}, wordWrapWidth, paddingX = 0, paddingY = 0, align = "left", anchorX = 0, anchorY = 0, }) {
|
|
5
|
+
super();
|
|
6
|
+
if (!items.length)
|
|
7
|
+
return;
|
|
8
|
+
const lineGroups = [];
|
|
9
|
+
let currentLine = [];
|
|
10
|
+
let x = 0;
|
|
11
|
+
// 分行
|
|
12
|
+
for (const { text, style = {} } of items) {
|
|
13
|
+
const instance = new Text(text, Object.assign(Object.assign({}, defaultStyle), style));
|
|
14
|
+
const w = instance.width;
|
|
15
|
+
if (wordWrapWidth && x + w > wordWrapWidth && x > 0) {
|
|
16
|
+
lineGroups.push(currentLine);
|
|
17
|
+
currentLine = [];
|
|
18
|
+
x = 0;
|
|
19
|
+
}
|
|
20
|
+
currentLine.push(instance);
|
|
21
|
+
x += w + paddingX;
|
|
22
|
+
}
|
|
23
|
+
if (currentLine.length)
|
|
24
|
+
lineGroups.push(currentLine);
|
|
25
|
+
// 布局每行
|
|
26
|
+
let y = 0;
|
|
27
|
+
for (const line of lineGroups) {
|
|
28
|
+
const totalWidth = line.reduce((sum, i) => sum + i.width + paddingX, -paddingX);
|
|
29
|
+
let offsetX = 0;
|
|
30
|
+
if (align === "center" && wordWrapWidth)
|
|
31
|
+
offsetX = (wordWrapWidth - totalWidth) / 2;
|
|
32
|
+
else if (align === "right" && wordWrapWidth)
|
|
33
|
+
offsetX = wordWrapWidth - totalWidth;
|
|
34
|
+
let currentX = offsetX;
|
|
35
|
+
let maxHeight = 0;
|
|
36
|
+
for (const item of line) {
|
|
37
|
+
item.x = currentX;
|
|
38
|
+
item.y = y;
|
|
39
|
+
this.addChild(item);
|
|
40
|
+
currentX += item.width + paddingX;
|
|
41
|
+
if (item.height > maxHeight)
|
|
42
|
+
maxHeight = item.height;
|
|
43
|
+
}
|
|
44
|
+
y += maxHeight + paddingY;
|
|
45
|
+
}
|
|
46
|
+
// 根据 anchor 调整整体偏移
|
|
47
|
+
const bounds = this.getLocalBounds();
|
|
48
|
+
this.pivot.set(bounds.x + bounds.width * anchorX, bounds.y + bounds.height * anchorY);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Graphics } from "pixi.js";
|
|
2
|
+
/** @description 三角形 */
|
|
3
|
+
export class LibPixiTriangle extends Graphics {
|
|
4
|
+
constructor(dots, color) {
|
|
5
|
+
super();
|
|
6
|
+
this.beginFill(color);
|
|
7
|
+
this.moveTo(0, 0);
|
|
8
|
+
this.lineTo(dots[0][0], dots[0][1]);
|
|
9
|
+
this.lineTo(dots[1][0], dots[1][1]);
|
|
10
|
+
this.endFill();
|
|
11
|
+
}
|
|
12
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { libJsConvertAngle } from "lyb-js/Math/LibJsConvertAngle.js";
|
|
2
|
+
/** @description 转盘布局
|
|
3
|
+
* @param num 份数
|
|
4
|
+
* @param distance 中心距离
|
|
5
|
+
* @param layoutCallback 定位计算回调
|
|
6
|
+
*/
|
|
7
|
+
export const LibPixiTurntable = (num, distance, layoutCallback) => {
|
|
8
|
+
for (let i = 0; i < num; i++) {
|
|
9
|
+
const rotation = libJsConvertAngle((360 / num) * i, "rad");
|
|
10
|
+
const cos = Math.cos(rotation + libJsConvertAngle(-90, "rad"));
|
|
11
|
+
const sin = Math.sin(rotation + libJsConvertAngle(-90, "rad"));
|
|
12
|
+
layoutCallback(cos * distance, sin * distance, rotation, i);
|
|
13
|
+
}
|
|
14
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/** @description 当前容器在父容器居中 */
|
|
2
|
+
export const libContainerCenter = (parent, item, centerType = "xy") => {
|
|
3
|
+
const xy = centerType === "xy";
|
|
4
|
+
if (centerType === "x" || xy) {
|
|
5
|
+
item.x = parent.width / 2 - item.width / 2;
|
|
6
|
+
}
|
|
7
|
+
if (centerType === "y" || xy) {
|
|
8
|
+
item.y = parent.height / 2 - item.height / 2;
|
|
9
|
+
}
|
|
10
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { libPixiTickerTimeout } from "./LibPixiTickerTimeout";
|
|
2
|
+
/** @description 可控延迟调用函数 */
|
|
3
|
+
export const libControlledDelayedCall = (time) => {
|
|
4
|
+
let _resolve;
|
|
5
|
+
let timer;
|
|
6
|
+
const start = new Promise((resolve) => {
|
|
7
|
+
_resolve = resolve;
|
|
8
|
+
timer = libPixiTickerTimeout(() => {
|
|
9
|
+
resolve();
|
|
10
|
+
}, time);
|
|
11
|
+
});
|
|
12
|
+
const stop = () => {
|
|
13
|
+
timer();
|
|
14
|
+
_resolve();
|
|
15
|
+
};
|
|
16
|
+
return {
|
|
17
|
+
start,
|
|
18
|
+
stop,
|
|
19
|
+
};
|
|
20
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { Container } from "pixi.js";
|
|
2
|
+
/**
|
|
3
|
+
* @description 线性排列 PIXI.Container 元素(支持横向/纵向排列,多列布局、固定或自定义间隔)
|
|
4
|
+
* @param items 需要排列的容器数组
|
|
5
|
+
* @param gap 间隔,可为固定值或数组(数组长度必须等于 items.length - 1)
|
|
6
|
+
* @param direction 排列方向:"x" 横向排列,"y" 纵向排列
|
|
7
|
+
* @param cols 每行(或每列)最多的元素个数,默认为 Infinity(单行/单列)
|
|
8
|
+
* @example
|
|
9
|
+
* // 横向排列
|
|
10
|
+
* LibPixiArrangeLinear([sprite1, sprite2, sprite3], 10, "x");
|
|
11
|
+
* // 纵向排列
|
|
12
|
+
* LibPixiArrangeLinear([sprite1, sprite2, sprite3], 20, "y");
|
|
13
|
+
* // 两列布局
|
|
14
|
+
* LibPixiArrangeLinear([sprite1, sprite2, sprite3, sprite4], 10, "x", 2);
|
|
15
|
+
*/
|
|
16
|
+
export declare const LibPixiArrangeLinear: (items: Container[], gap: number | number[], direction?: "x" | "y", cols?: number) => void;
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @description 线性排列 PIXI.Container 元素(支持横向/纵向排列,多列布局、固定或自定义间隔)
|
|
3
|
+
* @param items 需要排列的容器数组
|
|
4
|
+
* @param gap 间隔,可为固定值或数组(数组长度必须等于 items.length - 1)
|
|
5
|
+
* @param direction 排列方向:"x" 横向排列,"y" 纵向排列
|
|
6
|
+
* @param cols 每行(或每列)最多的元素个数,默认为 Infinity(单行/单列)
|
|
7
|
+
* @example
|
|
8
|
+
* // 横向排列
|
|
9
|
+
* LibPixiArrangeLinear([sprite1, sprite2, sprite3], 10, "x");
|
|
10
|
+
* // 纵向排列
|
|
11
|
+
* LibPixiArrangeLinear([sprite1, sprite2, sprite3], 20, "y");
|
|
12
|
+
* // 两列布局
|
|
13
|
+
* LibPixiArrangeLinear([sprite1, sprite2, sprite3, sprite4], 10, "x", 2);
|
|
14
|
+
*/
|
|
15
|
+
export const LibPixiArrangeLinear = (items, gap, direction = "x", cols = Infinity) => {
|
|
16
|
+
// 验证 gap 数组长度是否正确
|
|
17
|
+
if (Array.isArray(gap)) {
|
|
18
|
+
if (gap.length !== items.length - 1) {
|
|
19
|
+
console.error(new Error("间隔的数组长度只能等于元素数组长度-1"));
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
let lastRowMax = 0; // 当前行(或列)的最大高度(或宽度),用于多行/多列换行时计算偏移
|
|
24
|
+
let rowOffset = 0; // 累计偏移量,控制换行后的整体偏移位置
|
|
25
|
+
items.forEach((item, index) => {
|
|
26
|
+
var _a, _b;
|
|
27
|
+
const row = Math.floor(index / cols); // 当前行号
|
|
28
|
+
const col = index % cols; // 当前列号
|
|
29
|
+
if (direction === "x") {
|
|
30
|
+
//间隔
|
|
31
|
+
const gapValue = Array.isArray(gap) ? (_a = gap[index - 1]) !== null && _a !== void 0 ? _a : 0 : gap;
|
|
32
|
+
//在每行第一列重置列偏移量
|
|
33
|
+
if (col === 0 && row > 0) {
|
|
34
|
+
rowOffset += lastRowMax + gapValue;
|
|
35
|
+
lastRowMax = 0;
|
|
36
|
+
}
|
|
37
|
+
// 横向位置 = 前一个元素的右侧 + 间隔;首列则从 0 开始
|
|
38
|
+
item.x =
|
|
39
|
+
col === 0 ? 0 : items[index - 1].x + items[index - 1].width + gapValue;
|
|
40
|
+
// 纵向位置 = 当前累计的行偏移
|
|
41
|
+
rowOffset && (item.y = rowOffset);
|
|
42
|
+
// 更新当前行的最大高度
|
|
43
|
+
lastRowMax = Math.max(lastRowMax, item.height);
|
|
44
|
+
}
|
|
45
|
+
else {
|
|
46
|
+
//间隔
|
|
47
|
+
const gapValue = Array.isArray(gap) ? (_b = gap[index - 1]) !== null && _b !== void 0 ? _b : 0 : gap;
|
|
48
|
+
//在每列第一行重置行偏移
|
|
49
|
+
if (col === 0 && row > 0) {
|
|
50
|
+
rowOffset += lastRowMax + gapValue;
|
|
51
|
+
lastRowMax = 0;
|
|
52
|
+
}
|
|
53
|
+
// 纵向位置 = 首列则从 0 开始,其余从前一个元素的y坐标 + 高度 + 间隔;
|
|
54
|
+
item.y =
|
|
55
|
+
col === 0 ? 0 : items[index - 1].y + items[index - 1].height + gapValue;
|
|
56
|
+
// 横向位置 = 当前累计的列偏移
|
|
57
|
+
rowOffset && (item.x = rowOffset);
|
|
58
|
+
// 更新当前列的最大宽度
|
|
59
|
+
lastRowMax = Math.max(lastRowMax, item.width);
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
};
|