lyb-pixi-js 1.12.80 → 1.12.82

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.
@@ -0,0 +1,5 @@
1
+ import { BitmapText } from "pixi.js";
2
+ /** @description 自定义位图文本 */
3
+ export declare class LibPixiBit extends BitmapText {
4
+ constructor(fontName: string, text: string | number, fontSize: number);
5
+ }
@@ -0,0 +1,10 @@
1
+ import { BitmapText } from "pixi.js";
2
+ /** @description 自定义位图文本 */
3
+ export class LibPixiBit extends BitmapText {
4
+ constructor(fontName, text, fontSize) {
5
+ super(text.toString(), {
6
+ fontName,
7
+ fontSize,
8
+ });
9
+ }
10
+ }
@@ -0,0 +1,25 @@
1
+ import { Container, Text } from "pixi.js";
2
+ export interface LibPixiTableCell {
3
+ text: Text;
4
+ bgColor?: string;
5
+ }
6
+ export interface LibPixiTableParams {
7
+ /** 表格数据 */
8
+ data: (number | string | LibPixiTableCell)[][];
9
+ /** 是否需要表格外框 */
10
+ outsideBorder?: boolean;
11
+ /** 单元格最小宽度 */
12
+ cellWidth?: number;
13
+ /** 单元格最小高度 */
14
+ cellHeight?: number;
15
+ /** 格子内部内边距 */
16
+ cellPadding?: number;
17
+ /** 线条厚度 */
18
+ lineWidth?: number;
19
+ /** 线条颜色 */
20
+ lineColor?: string;
21
+ }
22
+ /** @description 表格(文本样式完全外部控制) */
23
+ export declare class LibPixiTableV2 extends Container {
24
+ constructor(params: LibPixiTableParams);
25
+ }
@@ -0,0 +1,92 @@
1
+ import { Container, Graphics, Text } from "pixi.js";
2
+ /** @description 表格(文本样式完全外部控制) */
3
+ export class LibPixiTableV2 extends Container {
4
+ constructor(params) {
5
+ var _a;
6
+ super();
7
+ const { data, outsideBorder = true, cellWidth = 80, cellHeight = 30, cellPadding = 6, lineWidth = 1, lineColor = "#cccccc", } = params;
8
+ if (!data || !data.length)
9
+ return;
10
+ // 计算列数
11
+ const cols = data.reduce((max, row) => Math.max(max, row.length), 0);
12
+ // 计算列宽/行高
13
+ const colWidths = Array(cols).fill(cellWidth);
14
+ const rowHeights = Array(data.length).fill(cellHeight);
15
+ for (let r = 0; r < data.length; r += 1) {
16
+ for (let c = 0; c < cols; c += 1) {
17
+ const raw = (_a = (data[r] && data[r][c])) !== null && _a !== void 0 ? _a : "";
18
+ const txt = typeof raw === "object" && "text" in raw ? raw.text : new Text(String(raw)); // 无样式处理
19
+ const w = txt.width + cellPadding * 2;
20
+ const h = txt.height + cellPadding * 2;
21
+ if (w > colWidths[c])
22
+ colWidths[c] = w;
23
+ if (h > rowHeights[r])
24
+ rowHeights[r] = h;
25
+ }
26
+ }
27
+ // 坐标
28
+ const colX = [];
29
+ let accX = 0;
30
+ for (let c = 0; c < cols; c += 1) {
31
+ colX.push(accX);
32
+ accX += colWidths[c];
33
+ }
34
+ const rowY = [];
35
+ let accY = 0;
36
+ for (let r = 0; r < rowHeights.length; r += 1) {
37
+ rowY.push(accY);
38
+ accY += rowHeights[r];
39
+ }
40
+ const totalW = accX;
41
+ const totalH = accY;
42
+ // 背景绘制
43
+ for (let r = 0; r < data.length; r += 1) {
44
+ for (let c = 0; c < cols; c += 1) {
45
+ const raw = data[r][c];
46
+ const bgColor = typeof raw === "object" && "bgColor" in raw ? raw.bgColor : undefined;
47
+ if (bgColor) {
48
+ const bg = new Graphics();
49
+ bg.beginFill(parseInt(bgColor.replace("#", ""), 16));
50
+ bg.drawRect(colX[c], rowY[r], colWidths[c], rowHeights[r]);
51
+ bg.endFill();
52
+ this.addChild(bg);
53
+ }
54
+ }
55
+ }
56
+ // 网格线
57
+ const g = new Graphics();
58
+ g.lineStyle(lineWidth, parseInt(lineColor.replace("#", ""), 16));
59
+ if (outsideBorder) {
60
+ g.drawRect(0, 0, totalW, totalH);
61
+ }
62
+ let xPos = 0;
63
+ for (let c = 1; c < cols; c += 1) {
64
+ xPos += colWidths[c - 1];
65
+ g.moveTo(xPos + lineWidth / 2, 0);
66
+ g.lineTo(xPos + lineWidth / 2, totalH);
67
+ }
68
+ let yPos = 0;
69
+ for (let r = 1; r < rowHeights.length; r += 1) {
70
+ yPos += rowHeights[r - 1];
71
+ g.moveTo(0, yPos + lineWidth / 2);
72
+ g.lineTo(totalW, yPos + lineWidth / 2);
73
+ }
74
+ this.addChild(g);
75
+ // 文本
76
+ for (let r = 0; r < data.length; r += 1) {
77
+ for (let c = 0; c < cols; c += 1) {
78
+ const raw = data[r][c];
79
+ const txt = typeof raw === "object" && "text" in raw ? raw.text : new Text(String(raw));
80
+ const cx = colX[c];
81
+ const cy = rowY[r];
82
+ txt.x = Math.round(cx + (colWidths[c] - txt.width) / 2);
83
+ txt.y = Math.round(cy + (rowHeights[r] - txt.height) / 2);
84
+ this.addChild(txt);
85
+ }
86
+ }
87
+ // @ts-ignore
88
+ this.width = totalW;
89
+ // @ts-ignore
90
+ this.height = totalH;
91
+ }
92
+ }
package/README.md CHANGED
@@ -86,6 +86,8 @@ app.stage.addChild(box);
86
86
 
87
87
  \- [LibPixiHtmlText-富文本](#LibPixiHtmlText-富文本)
88
88
 
89
+ \- [LibPixiBit-位图简化使用](#LibPixiBit-位图简化使用)
90
+
89
91
  \- [LibPixiBitText-位图](#LibPixiBitText-位图)
90
92
 
91
93
  \- [LibPixiContainer-容器](#LibPixiContainer-容器)
@@ -136,7 +138,9 @@ app.stage.addChild(box);
136
138
 
137
139
  \- [LibPixiSlide-滑动页](#LibPixiSlide-滑动页)
138
140
 
139
- \- [LibPixiTable-数字表格](#LibPixiTable-数字表格)
141
+ \- [LibPixiTable-简易表格](#LibPixiTable-简易表格)
142
+
143
+ \- [LibPixiTableV2-自定义表格](#LibPixiTableV2-自定义表格)
140
144
 
141
145
  \- [LibPixiLabelValue-标签值](#LibPixiLabelValue-标签值)
142
146
 
@@ -280,6 +284,8 @@ interface LibPixiHtmlTextParams {
280
284
  }
281
285
  ```
282
286
 
287
+ ### LibPixiBit-位图简化使用
288
+
283
289
  ### LibPixiBitText-位图
284
290
 
285
291
  > 自定义位图文本
@@ -836,9 +842,9 @@ const three = new LibPixiSlide({
836
842
  });
837
843
  ```
838
844
 
839
- ### LibPixiTable-数字表格
845
+ ### LibPixiTable-简易表格
840
846
 
841
- > 绘制表格并填充数字
847
+ > 绘制表格并填充文本
842
848
 
843
849
  ```ts
844
850
  import { LibPixiTable } from "./path/to/LibPixiTable";
@@ -866,6 +872,88 @@ const table = new LibPixiTable({
866
872
  stage.addChild(table);
867
873
  ```
868
874
 
875
+ ### LibPixiTable-自定义表格
876
+
877
+ > 表格内部样式和文本全由外部提前设置好
878
+
879
+ ```ts
880
+ const fontSize = 28;
881
+ const data = [
882
+ {
883
+ text: new LibPixiText({
884
+ text: "27/11/2025\n14:16:27",
885
+ fontColor: "#C68251",
886
+ fontSize,
887
+ align: "center",
888
+ }),
889
+ bgColor: "#F6D7B4",
890
+ },
891
+ {
892
+ text: new LibPixiText({
893
+ text: "cutepanda",
894
+ fontColor: "#C68251",
895
+ fontSize,
896
+ align: "center",
897
+ }),
898
+ bgColor: "#F6D7B4",
899
+ },
900
+ ];
901
+ const scrollContent = new LibPixiTable({
902
+ lineWidth: 3,
903
+ cellWidth: 248,
904
+ cellHeight: 85,
905
+ cellPadding: 10,
906
+ lineColor: "#B96D39",
907
+ data: [
908
+ [
909
+ {
910
+ text: new LibPixiText({
911
+ text: "Date",
912
+ fontColor: "#B74715",
913
+ fontSize,
914
+ align: "center",
915
+ }),
916
+ bgColor: "#F5BC91",
917
+ },
918
+ {
919
+ text: new LibPixiText({
920
+ text: "Event",
921
+ fontColor: "#B74715",
922
+ fontSize,
923
+ align: "center",
924
+ }),
925
+ bgColor: "#F5BC91",
926
+ },
927
+ ],
928
+ data,
929
+ data,
930
+ data,
931
+ data,
932
+ data,
933
+ data,
934
+ data,
935
+ data,
936
+ data,
937
+ data,
938
+ data,
939
+ data,
940
+ data,
941
+ data,
942
+ data,
943
+ data,
944
+ data,
945
+ data,
946
+ data,
947
+ data,
948
+ data,
949
+ data,
950
+ data,
951
+ data,
952
+ ],
953
+ });
954
+ scrollContent.x = 50;
955
+ ```
956
+
869
957
  ### LibPixiLabelValue-标签值
870
958
 
871
959
  > 适用于左边图标右边动态数值锚点在容器正中间的场景
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lyb-pixi-js",
3
- "version": "1.12.80",
3
+ "version": "1.12.82",
4
4
  "description": "自用Pixi.JS方法库",
5
5
  "license": "ISC",
6
6
  "exports": {