lyb-pixi-js 1.12.79 → 1.12.81

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,21 @@
1
+ import { Container } from "pixi.js";
2
+ import { LibPixiArrangeLinearV2 } from "./LibPixiArrangeLinearV2";
3
+ interface LibBitTextGroupParams {
4
+ /** 字体 */
5
+ family: string;
6
+ /** 文本 */
7
+ text: string;
8
+ /** 字体大小 */
9
+ fontSize: number;
10
+ /** 间隔 */
11
+ gap?: number;
12
+ /** 锚点X */
13
+ anchorX?: number;
14
+ /** 锚点Y */
15
+ anchorY?: number;
16
+ }
17
+ /** @description 美术字组 */
18
+ export declare class LibBitTextGroup extends LibPixiArrangeLinearV2<Container> {
19
+ constructor(params: LibBitTextGroupParams);
20
+ }
21
+ export {};
@@ -0,0 +1,21 @@
1
+ import { LibPixiBitText } from "../Base/LibPixiBitText";
2
+ import { LibPixiArrangeLinearV2 } from "./LibPixiArrangeLinearV2";
3
+ /** @description 美术字组 */
4
+ export class LibBitTextGroup extends LibPixiArrangeLinearV2 {
5
+ constructor(params) {
6
+ const { family, text, fontSize, gap = -3, anchorX = 0.5, anchorY = 0.5, } = params;
7
+ super({
8
+ direction: "x",
9
+ gap,
10
+ anchorX,
11
+ anchorY,
12
+ });
13
+ const bit = new LibPixiBitText(family, fontSize);
14
+ for (const char of text) {
15
+ const bitText = bit.createText(char);
16
+ bitText.anchor.y = 0.5;
17
+ this.push(bit.createText(char));
18
+ }
19
+ this.layout();
20
+ }
21
+ }
@@ -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
@@ -136,7 +136,9 @@ app.stage.addChild(box);
136
136
 
137
137
  \- [LibPixiSlide-滑动页](#LibPixiSlide-滑动页)
138
138
 
139
- \- [LibPixiTable-数字表格](#LibPixiTable-数字表格)
139
+ \- [LibPixiTable-简易表格](#LibPixiTable-简易表格)
140
+
141
+ \- [LibPixiTableV2-自定义表格](#LibPixiTableV2-自定义表格)
140
142
 
141
143
  \- [LibPixiLabelValue-标签值](#LibPixiLabelValue-标签值)
142
144
 
@@ -204,6 +206,8 @@ app.stage.addChild(box);
204
206
 
205
207
  \- [LibPixiIsOutOfView-离开可视区检测](#LibPixiIsOutOfView-离开可视区检测)
206
208
 
209
+ \- [LibBitTextGroup-美术字组](#LibBitTextGroup-美术字组)
210
+
207
211
  ## Base-基础
208
212
 
209
213
  ### LibPixiText-文本
@@ -836,9 +840,9 @@ const three = new LibPixiSlide({
836
840
  });
837
841
  ```
838
842
 
839
- ### LibPixiTable-数字表格
843
+ ### LibPixiTable-简易表格
840
844
 
841
- > 绘制表格并填充数字
845
+ > 绘制表格并填充文本
842
846
 
843
847
  ```ts
844
848
  import { LibPixiTable } from "./path/to/LibPixiTable";
@@ -866,6 +870,88 @@ const table = new LibPixiTable({
866
870
  stage.addChild(table);
867
871
  ```
868
872
 
873
+ ### LibPixiTable-自定义表格
874
+
875
+ > 表格内部样式和文本全由外部提前设置好
876
+
877
+ ```ts
878
+ const fontSize = 28;
879
+ const data = [
880
+ {
881
+ text: new LibPixiText({
882
+ text: "27/11/2025\n14:16:27",
883
+ fontColor: "#C68251",
884
+ fontSize,
885
+ align: "center",
886
+ }),
887
+ bgColor: "#F6D7B4",
888
+ },
889
+ {
890
+ text: new LibPixiText({
891
+ text: "cutepanda",
892
+ fontColor: "#C68251",
893
+ fontSize,
894
+ align: "center",
895
+ }),
896
+ bgColor: "#F6D7B4",
897
+ },
898
+ ];
899
+ const scrollContent = new LibPixiTable({
900
+ lineWidth: 3,
901
+ cellWidth: 248,
902
+ cellHeight: 85,
903
+ cellPadding: 10,
904
+ lineColor: "#B96D39",
905
+ data: [
906
+ [
907
+ {
908
+ text: new LibPixiText({
909
+ text: "Date",
910
+ fontColor: "#B74715",
911
+ fontSize,
912
+ align: "center",
913
+ }),
914
+ bgColor: "#F5BC91",
915
+ },
916
+ {
917
+ text: new LibPixiText({
918
+ text: "Event",
919
+ fontColor: "#B74715",
920
+ fontSize,
921
+ align: "center",
922
+ }),
923
+ bgColor: "#F5BC91",
924
+ },
925
+ ],
926
+ data,
927
+ data,
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
+ ],
951
+ });
952
+ scrollContent.x = 50;
953
+ ```
954
+
869
955
  ### LibPixiLabelValue-标签值
870
956
 
871
957
  > 适用于左边图标右边动态数值锚点在容器正中间的场景
@@ -1287,4 +1373,8 @@ LibPixiEmitContainerEvent(this, "EVENT_NAME", {});
1287
1373
 
1288
1374
  ### LibPixiIsOutOfView-离开可视区检测
1289
1375
 
1290
- > 检测元素是否离开可视区
1376
+ > 检测元素是否离开可视区
1377
+
1378
+ ### LibBitTextGroup-美术字组
1379
+
1380
+ > 通过将美术字的 `fnt` 字体文件,循环创建位图文本进行拼接
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lyb-pixi-js",
3
- "version": "1.12.79",
3
+ "version": "1.12.81",
4
4
  "description": "自用Pixi.JS方法库",
5
5
  "license": "ISC",
6
6
  "exports": {