lyb-pixi-js 1.3.7 → 1.3.9

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.
@@ -1,5 +1,5 @@
1
1
  import { Container } from "pixi.js";
2
- import { LibPixiContainer } from '../Base/LibPixiContainer';
2
+ import { LibPixiContainer } from "../Base/LibPixiContainer";
3
3
  export interface LibPixiScrollNumParams {
4
4
  /** 滚动区域宽度 */
5
5
  width: number;
@@ -53,10 +53,22 @@ export declare class LibPixiScrollNum extends LibPixiContainer {
53
53
  * @param animate 是否需要过渡动画
54
54
  */
55
55
  slideTo(index: number, animate?: boolean): void;
56
+ /** @description 设置滚动景深
57
+ * @param containerList 元素列表
58
+ * @param y 拖动Y坐标
59
+ * @param startY 内部将y - startY进行计算
60
+ */
61
+ setDepth(containerList: Container[], y: number, startY?: number): void;
56
62
  /** @description 开始拖动 */
57
63
  private _onDragStart;
58
64
  /** @description 拖动中 */
59
65
  private _onDragMove;
60
66
  /** @description 结束拖动 */
61
67
  private _onDragEnd;
68
+ /** @description 线性插值
69
+ * @param a1 当 t = 0 时,返回 a1
70
+ * @param a2 当 t = 1 时,返回 a2
71
+ * @param t 插值比例,取值范围 0~1
72
+ */
73
+ private lerp;
62
74
  }
@@ -1,6 +1,6 @@
1
1
  import { Graphics } from "pixi.js";
2
2
  import gsap from "gsap";
3
- import { LibPixiContainer } from '../Base/LibPixiContainer';
3
+ import { LibPixiContainer } from "../Base/LibPixiContainer";
4
4
  /** @description 通过鼠标或手指拖动数字列选择数字
5
5
  * @link 使用方法:https://www.npmjs.com/package/lyb-pixi-js#LibPixiScrollNum-数字滑动
6
6
  */
@@ -99,6 +99,35 @@ export class LibPixiScrollNum extends LibPixiContainer {
99
99
  }
100
100
  (_a = this._slideCallback) === null || _a === void 0 ? void 0 : _a.call(this, this._currentIndex);
101
101
  }
102
+ /** @description 设置滚动景深
103
+ * @param containerList 元素列表
104
+ * @param y 拖动Y坐标
105
+ * @param startY 内部将y - startY进行计算
106
+ */
107
+ setDepth(containerList, y, startY = 0) {
108
+ const Y = y - startY;
109
+ const idx = Math.floor(Math.abs(Y) / 70);
110
+ const t = (Math.abs(Y) % 70) / 70;
111
+ const prevIdx = idx - 1;
112
+ const nextIdx = idx + 1;
113
+ const nextIdx2 = idx + 2;
114
+ const curItem = containerList[idx];
115
+ curItem.alpha = this.lerp(0.5, 1, 1 - t);
116
+ curItem.scale.y = this.lerp(0.85, 1, 1 - t);
117
+ if (nextIdx < containerList.length) {
118
+ const nextItem = containerList[nextIdx];
119
+ nextItem.alpha = this.lerp(0.5, 1, t);
120
+ nextItem.scale.y = this.lerp(0.85, 1, t);
121
+ }
122
+ if (nextIdx2 < containerList.length) {
123
+ const nextItem = containerList[nextIdx2];
124
+ nextItem.alpha = this.lerp(0.1, 0.5, t);
125
+ }
126
+ if (prevIdx >= 0) {
127
+ const prevItem = containerList[prevIdx];
128
+ prevItem.alpha = this.lerp(0.1, 0.5, 1 - t);
129
+ }
130
+ }
102
131
  /** @description 开始拖动 */
103
132
  _onDragStart(event) {
104
133
  this._isDragging = true;
@@ -152,4 +181,12 @@ export class LibPixiScrollNum extends LibPixiContainer {
152
181
  // 执行滑动到目标页码
153
182
  this.slideTo(this._currentIndex);
154
183
  }
184
+ /** @description 线性插值
185
+ * @param a1 当 t = 0 时,返回 a1
186
+ * @param a2 当 t = 1 时,返回 a2
187
+ * @param t 插值比例,取值范围 0~1
188
+ */
189
+ lerp(a1, a2, t) {
190
+ return a1 * (1 - t) + a2 * t;
191
+ }
155
192
  }
@@ -3,6 +3,8 @@ import { Container } from "pixi.js";
3
3
  export interface LibPixiTableParams {
4
4
  /** 表格数据 */
5
5
  data: (number | string)[][];
6
+ /** 是否需要表格外框 */
7
+ outsideBorder?: boolean;
6
8
  /** 单元格宽度 */
7
9
  cellWidth?: number;
8
10
  /** 单元格高度 */
@@ -11,6 +13,10 @@ export interface LibPixiTableParams {
11
13
  fontSize?: number;
12
14
  /** 字体颜色 */
13
15
  fontColor?: string;
16
+ /** 表格第一列字体颜色 */
17
+ firstColumnFontColor?: string;
18
+ /** 是否需要加粗 */
19
+ fontBold?: boolean;
14
20
  /** 线条厚度 */
15
21
  lineWidth?: number;
16
22
  /** 线条颜色 */
@@ -34,8 +40,14 @@ export declare class LibPixiTable extends Container {
34
40
  private _lineWidth;
35
41
  /** 字体颜色 */
36
42
  private _fontColor;
43
+ /** 表格第一列字体颜色 */
44
+ private _firstColumnFontColor;
37
45
  /** 线条颜色 */
38
46
  private _lineColor;
47
+ /** 是否需要表格外框 */
48
+ private _outsideBorder;
49
+ /** 是否需要加粗 */
50
+ private _fontBold;
39
51
  /** 二维数字数组 */
40
52
  private _data;
41
53
  constructor(params: LibPixiTableParams);
@@ -1,13 +1,13 @@
1
1
  /** @description 表格绘制并填入数字 */
2
- import { Text, Container, Graphics } from "pixi.js";
3
- import { libPixiScaleContainer } from "../../Utils/LibPixiScaleContainer";
2
+ import { Container, Graphics, Text } from "pixi.js";
3
+ import { libPixiScaleContainer } from '../../Utils/LibPixiScaleContainer';
4
4
  /** @description 绘制表格并填充数字
5
5
  * @link 使用方法:https://www.npmjs.com/package/lyb-pixi-js#LibPixiTable-数字表格
6
6
  */
7
7
  export class LibPixiTable extends Container {
8
8
  constructor(params) {
9
9
  super();
10
- const { data, cellWidth = 130, cellHeight = 100, fontColor = "#B4B4B8", fontSize = 24, lineWidth = 3, lineColor = "#B4B4B8", } = params;
10
+ const { data, cellWidth = 130, cellHeight = 100, fontColor = "#fff", firstColumnFontColor = "#fff", fontSize = 30, lineWidth = 2, lineColor = "#5b5b5b", outsideBorder = true, fontBold = true, } = params;
11
11
  this._data = data;
12
12
  this._rows = data.length;
13
13
  this._cols = data[0].length;
@@ -17,6 +17,9 @@ export class LibPixiTable extends Container {
17
17
  this._fontSize = fontSize;
18
18
  this._lineWidth = lineWidth;
19
19
  this._lineColor = lineColor;
20
+ this._outsideBorder = outsideBorder;
21
+ this._fontBold = fontBold;
22
+ this._firstColumnFontColor = firstColumnFontColor;
20
23
  this._drawTable();
21
24
  this.fillNumbers();
22
25
  }
@@ -27,7 +30,9 @@ export class LibPixiTable extends Container {
27
30
  const graphics = new Graphics();
28
31
  graphics.lineStyle(this._lineWidth, this._lineColor);
29
32
  // 绘制表格外框
30
- graphics.drawRect(0, 0, tableWidth, tableHeight);
33
+ if (this._outsideBorder) {
34
+ graphics.drawRect(0, 0, tableWidth, tableHeight);
35
+ }
31
36
  // 绘制横线
32
37
  for (let i = 1; i < this._rows; i++) {
33
38
  graphics.moveTo(0, i * this._cellHeight);
@@ -57,7 +62,8 @@ export class LibPixiTable extends Container {
57
62
  _createNumberText(number, col, row) {
58
63
  const text = new Text(number.toString(), {
59
64
  _fontSize: this._fontSize,
60
- fill: this._fontColor,
65
+ fill: col === 0 ? this._firstColumnFontColor : this._fontColor,
66
+ fontWeight: this._fontBold ? "bold" : "normal",
61
67
  });
62
68
  // 计算文本的居中位置
63
69
  const x = col * this._cellWidth + this._cellWidth / 2;