lyb-pixi-js 1.12.2 → 1.12.4
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/Custom/LibPixiPerforMon.js +20 -7
- package/Utils/LibPixiArrangeLinear.d.ts +2 -1
- package/Utils/LibPixiArrangeLinear.js +25 -9
- package/libPixiJs.d.ts +1 -1
- package/lyb-pixi.js +109 -27
- package/package.json +1 -1
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import { LibJsResizeWatcher } from "lyb-js/Base/LibJsResizeWatcher.js";
|
|
1
2
|
import { Container, Ticker, UPDATE_PRIORITY, } from "pixi.js";
|
|
2
|
-
import {
|
|
3
|
+
import { LibPixiRectangle } from "../Base/LibPixiRectangle";
|
|
3
4
|
import { LibPixiText } from "../Base/LibPixiText";
|
|
4
5
|
/** @description 监视帧率、Draw Call、Max Draw Call
|
|
5
6
|
* @link 使用方法:https://www.npmjs.com/package/lyb-pixi-js#LibPixiPerforMon-性能监视器
|
|
@@ -27,12 +28,7 @@ export class LibPixiPerforMon extends Container {
|
|
|
27
28
|
this._containerHeight = 50;
|
|
28
29
|
this.pivot.x = this._containerWidth / 2;
|
|
29
30
|
//创建背景
|
|
30
|
-
this._bg = new
|
|
31
|
-
width: this._containerWidth,
|
|
32
|
-
height: this._containerHeight,
|
|
33
|
-
bgColor: "#000",
|
|
34
|
-
alpha: 0.75,
|
|
35
|
-
});
|
|
31
|
+
this._bg = new LibPixiRectangle(this._containerWidth, this._containerHeight, "#0000007e");
|
|
36
32
|
this.addChild(this._bg);
|
|
37
33
|
//创建内容容器
|
|
38
34
|
const content = new Container();
|
|
@@ -53,6 +49,23 @@ export class LibPixiPerforMon extends Container {
|
|
|
53
49
|
this._renderer = app.renderer;
|
|
54
50
|
this._drawElements = this._renderer["gl"].drawElements;
|
|
55
51
|
this.init();
|
|
52
|
+
if (LibPixiPerforMon.ADAPT_MODE === "h") {
|
|
53
|
+
this.x = 1920 / 2;
|
|
54
|
+
}
|
|
55
|
+
else if (LibPixiPerforMon.ADAPT_MODE === "v") {
|
|
56
|
+
this.x = 1080 / 2;
|
|
57
|
+
}
|
|
58
|
+
else {
|
|
59
|
+
const resize = new LibJsResizeWatcher();
|
|
60
|
+
resize.on((w, h) => {
|
|
61
|
+
if (w > h) {
|
|
62
|
+
this.x = 1920 / 2;
|
|
63
|
+
}
|
|
64
|
+
else {
|
|
65
|
+
this.x = 1080 / 2;
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
}
|
|
56
69
|
}
|
|
57
70
|
/** @description 初始化显示性能数据 */
|
|
58
71
|
init() {
|
|
@@ -4,6 +4,7 @@ import { Container } from "pixi.js";
|
|
|
4
4
|
* @param items 要排列的元素数组。
|
|
5
5
|
* @param gap 元素之间的间隔,可以是固定间隔或自定义的间隔数组。
|
|
6
6
|
* @param direction 排列方向,"x"表示水平,"y"表示垂直,默认为水平。
|
|
7
|
+
* @param cols 列数,默认为元素数量。
|
|
7
8
|
* @link 使用方法:https://www.npmjs.com/package/lyb-pixi-js#LibPixiArrangeLinear-间隔布局
|
|
8
9
|
*/
|
|
9
|
-
export declare const LibPixiArrangeLinear: (items: Container[], gap: number | number[], direction?: "x" | "y") => void;
|
|
10
|
+
export declare const LibPixiArrangeLinear: (items: Container[], gap: number | number[], direction?: "x" | "y", cols?: number) => void;
|
|
@@ -3,27 +3,43 @@
|
|
|
3
3
|
* @param items 要排列的元素数组。
|
|
4
4
|
* @param gap 元素之间的间隔,可以是固定间隔或自定义的间隔数组。
|
|
5
5
|
* @param direction 排列方向,"x"表示水平,"y"表示垂直,默认为水平。
|
|
6
|
+
* @param cols 列数,默认为元素数量。
|
|
6
7
|
* @link 使用方法:https://www.npmjs.com/package/lyb-pixi-js#LibPixiArrangeLinear-间隔布局
|
|
7
8
|
*/
|
|
8
|
-
export const LibPixiArrangeLinear = (items, gap, direction = "x") => {
|
|
9
|
+
export const LibPixiArrangeLinear = (items, gap, direction = "x", cols = Infinity) => {
|
|
9
10
|
if (Array.isArray(gap)) {
|
|
10
11
|
if (gap.length !== items.length - 1) {
|
|
11
12
|
console.error(new Error("间隔的数组长度只能等于元素数组长度-1"));
|
|
12
13
|
return;
|
|
13
14
|
}
|
|
14
15
|
}
|
|
15
|
-
let
|
|
16
|
+
let lastRowMax = 0; // 记录当前行/列最大高度或宽度
|
|
17
|
+
let rowOffset = 0; // 累计偏移量(多行时用)
|
|
16
18
|
items.forEach((item, index) => {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
19
|
+
var _a, _b;
|
|
20
|
+
const row = Math.floor(index / cols);
|
|
21
|
+
const col = index % cols;
|
|
20
22
|
if (direction === "x") {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
+
const gapValue = Array.isArray(gap) ? (_a = gap[index - 1]) !== null && _a !== void 0 ? _a : 0 : gap;
|
|
24
|
+
if (col === 0 && row > 0) {
|
|
25
|
+
rowOffset += lastRowMax + gapValue;
|
|
26
|
+
lastRowMax = 0;
|
|
27
|
+
}
|
|
28
|
+
item.x =
|
|
29
|
+
col === 0 ? 0 : items[index - 1].x + items[index - 1].width + gapValue;
|
|
30
|
+
item.y = rowOffset;
|
|
31
|
+
lastRowMax = Math.max(lastRowMax, item.height);
|
|
23
32
|
}
|
|
24
33
|
else {
|
|
25
|
-
|
|
26
|
-
|
|
34
|
+
const gapValue = Array.isArray(gap) ? (_b = gap[index - 1]) !== null && _b !== void 0 ? _b : 0 : gap;
|
|
35
|
+
if (col === 0 && row > 0) {
|
|
36
|
+
rowOffset += lastRowMax + gapValue;
|
|
37
|
+
lastRowMax = 0;
|
|
38
|
+
}
|
|
39
|
+
item.y =
|
|
40
|
+
col === 0 ? 0 : items[index - 1].y + items[index - 1].height + gapValue;
|
|
41
|
+
item.x = rowOffset;
|
|
42
|
+
lastRowMax = Math.max(lastRowMax, item.width);
|
|
27
43
|
}
|
|
28
44
|
});
|
|
29
45
|
};
|
package/libPixiJs.d.ts
CHANGED
|
@@ -274,7 +274,7 @@ export declare const Utils: {
|
|
|
274
274
|
* @param direction 排列方向,"x"表示水平,"y"表示垂直,默认为水平。
|
|
275
275
|
* @link 使用方法:https://www.npmjs.com/package/lyb-pixi-js#LibPixiArrangeLinear-间隔布局
|
|
276
276
|
*/
|
|
277
|
-
LibPixiArrangeLinear: (items: import("pixi.js").Container[], gap: number | number[], direction?: "x" | "y") => void;
|
|
277
|
+
LibPixiArrangeLinear: (items: import("pixi.js").Container[], gap: number | number[], direction?: "x" | "y", cols?: number) => void;
|
|
278
278
|
/** @description 触发后代监听
|
|
279
279
|
* @param container 容器
|
|
280
280
|
* @param event 事件名称
|
package/lyb-pixi.js
CHANGED
|
@@ -48939,7 +48939,72 @@ void main(void)\r
|
|
|
48939
48939
|
});
|
|
48940
48940
|
}
|
|
48941
48941
|
}
|
|
48942
|
-
class
|
|
48942
|
+
class LibJsResizeWatcher {
|
|
48943
|
+
constructor(mode = "hv") {
|
|
48944
|
+
this._listeners = [];
|
|
48945
|
+
this._handleResize = () => {
|
|
48946
|
+
const w2 = window.innerWidth;
|
|
48947
|
+
const h2 = window.innerHeight;
|
|
48948
|
+
let s2;
|
|
48949
|
+
const orientation = w2 > h2 ? "h" : "v";
|
|
48950
|
+
if (orientation === "h") {
|
|
48951
|
+
s2 = Math.min(w2 / 1920, h2 / 1080);
|
|
48952
|
+
} else {
|
|
48953
|
+
s2 = Math.min(w2 / 1080, h2 / 1920);
|
|
48954
|
+
}
|
|
48955
|
+
this._listeners.forEach(({ cb }) => cb(w2, h2, s2));
|
|
48956
|
+
};
|
|
48957
|
+
this._mode = mode;
|
|
48958
|
+
if (mode === "h" || mode === "v")
|
|
48959
|
+
return;
|
|
48960
|
+
window.addEventListener("resize", this._handleResize);
|
|
48961
|
+
}
|
|
48962
|
+
/**
|
|
48963
|
+
* @description 注册一个窗口尺寸变化的监听器
|
|
48964
|
+
* @param cb 回调函数,参数为当前窗口宽度和高度
|
|
48965
|
+
* @param immediate 是否在注册时立即执行一次回调,默认为 true
|
|
48966
|
+
* @returns 一个函数,用于移除该监听器
|
|
48967
|
+
*/
|
|
48968
|
+
on(cb, immediate = true) {
|
|
48969
|
+
const w2 = window.innerWidth;
|
|
48970
|
+
const h2 = window.innerHeight;
|
|
48971
|
+
const orientation = w2 > h2 ? "h" : "v";
|
|
48972
|
+
if (this._mode === "h") {
|
|
48973
|
+
immediate && cb(1920, 1080, Math.min(w2 / 1920, h2 / 1080));
|
|
48974
|
+
return () => {
|
|
48975
|
+
};
|
|
48976
|
+
} else if (this._mode === "v") {
|
|
48977
|
+
immediate && cb(1080, 1920, Math.min(w2 / 1080, h2 / 1920));
|
|
48978
|
+
return () => {
|
|
48979
|
+
};
|
|
48980
|
+
}
|
|
48981
|
+
let s2;
|
|
48982
|
+
if (orientation === "h") {
|
|
48983
|
+
s2 = Math.min(w2 / 1920, h2 / 1080);
|
|
48984
|
+
} else {
|
|
48985
|
+
s2 = Math.min(w2 / 1080, h2 / 1920);
|
|
48986
|
+
}
|
|
48987
|
+
const item = { cb, immediate };
|
|
48988
|
+
this._listeners.push(item);
|
|
48989
|
+
if (immediate)
|
|
48990
|
+
cb(window.innerWidth, window.innerHeight, s2);
|
|
48991
|
+
return () => {
|
|
48992
|
+
this._listeners = this._listeners.filter((l2) => l2 !== item);
|
|
48993
|
+
};
|
|
48994
|
+
}
|
|
48995
|
+
}
|
|
48996
|
+
class LibPixiRectangle extends Graphics {
|
|
48997
|
+
constructor(width, height, color) {
|
|
48998
|
+
super();
|
|
48999
|
+
this.beginFill(color || 0);
|
|
49000
|
+
this.drawRect(0, 0, width, height);
|
|
49001
|
+
this.endFill();
|
|
49002
|
+
if (!color) {
|
|
49003
|
+
this.alpha = 0;
|
|
49004
|
+
}
|
|
49005
|
+
}
|
|
49006
|
+
}
|
|
49007
|
+
const _LibPixiPerforMon = class _LibPixiPerforMon2 extends Container {
|
|
48943
49008
|
constructor(app) {
|
|
48944
49009
|
super();
|
|
48945
49010
|
this.COLLECT_TIME = 5 * 1e3;
|
|
@@ -48952,12 +49017,11 @@ void main(void)\r
|
|
|
48952
49017
|
this._containerWidth = 590;
|
|
48953
49018
|
this._containerHeight = 50;
|
|
48954
49019
|
this.pivot.x = this._containerWidth / 2;
|
|
48955
|
-
this._bg = new
|
|
48956
|
-
|
|
48957
|
-
|
|
48958
|
-
|
|
48959
|
-
|
|
48960
|
-
});
|
|
49020
|
+
this._bg = new LibPixiRectangle(
|
|
49021
|
+
this._containerWidth,
|
|
49022
|
+
this._containerHeight,
|
|
49023
|
+
"#0000007e"
|
|
49024
|
+
);
|
|
48961
49025
|
this.addChild(this._bg);
|
|
48962
49026
|
const content = new Container();
|
|
48963
49027
|
this.addChild(content);
|
|
@@ -48974,6 +49038,20 @@ void main(void)\r
|
|
|
48974
49038
|
this._renderer = app.renderer;
|
|
48975
49039
|
this._drawElements = this._renderer["gl"].drawElements;
|
|
48976
49040
|
this.init();
|
|
49041
|
+
if (_LibPixiPerforMon2.ADAPT_MODE === "h") {
|
|
49042
|
+
this.x = 1920 / 2;
|
|
49043
|
+
} else if (_LibPixiPerforMon2.ADAPT_MODE === "v") {
|
|
49044
|
+
this.x = 1080 / 2;
|
|
49045
|
+
} else {
|
|
49046
|
+
const resize = new LibJsResizeWatcher();
|
|
49047
|
+
resize.on((w2, h2) => {
|
|
49048
|
+
if (w2 > h2) {
|
|
49049
|
+
this.x = 1920 / 2;
|
|
49050
|
+
} else {
|
|
49051
|
+
this.x = 1080 / 2;
|
|
49052
|
+
}
|
|
49053
|
+
});
|
|
49054
|
+
}
|
|
48977
49055
|
}
|
|
48978
49056
|
/** @description 初始化显示性能数据 */
|
|
48979
49057
|
init() {
|
|
@@ -49039,8 +49117,9 @@ void main(void)\r
|
|
|
49039
49117
|
}
|
|
49040
49118
|
return color;
|
|
49041
49119
|
}
|
|
49042
|
-
}
|
|
49043
|
-
|
|
49120
|
+
};
|
|
49121
|
+
_LibPixiPerforMon.ADAPT_MODE = "hv";
|
|
49122
|
+
let LibPixiPerforMon = _LibPixiPerforMon;
|
|
49044
49123
|
class TextBox extends Container {
|
|
49045
49124
|
constructor(text, fontSize = 26) {
|
|
49046
49125
|
super();
|
|
@@ -49237,17 +49316,6 @@ void main(void)\r
|
|
|
49237
49316
|
}
|
|
49238
49317
|
}
|
|
49239
49318
|
}
|
|
49240
|
-
class LibPixiRectangle extends Graphics {
|
|
49241
|
-
constructor(width, height, color) {
|
|
49242
|
-
super();
|
|
49243
|
-
this.beginFill(color || 0);
|
|
49244
|
-
this.drawRect(0, 0, width, height);
|
|
49245
|
-
this.endFill();
|
|
49246
|
-
if (!color) {
|
|
49247
|
-
this.alpha = 0;
|
|
49248
|
-
}
|
|
49249
|
-
}
|
|
49250
|
-
}
|
|
49251
49319
|
class LibPixiScrollContainerY extends LibPixiContainer {
|
|
49252
49320
|
constructor(params) {
|
|
49253
49321
|
const {
|
|
@@ -55015,22 +55083,36 @@ void main(void){
|
|
|
55015
55083
|
item.y = rowIndex * (itemHeight + gap);
|
|
55016
55084
|
});
|
|
55017
55085
|
};
|
|
55018
|
-
const LibPixiArrangeLinear = (items, gap, direction = "x") => {
|
|
55086
|
+
const LibPixiArrangeLinear = (items, gap, direction = "x", cols = Infinity) => {
|
|
55019
55087
|
if (Array.isArray(gap)) {
|
|
55020
55088
|
if (gap.length !== items.length - 1) {
|
|
55021
55089
|
console.error(new Error("间隔的数组长度只能等于元素数组长度-1"));
|
|
55022
55090
|
return;
|
|
55023
55091
|
}
|
|
55024
55092
|
}
|
|
55025
|
-
let
|
|
55093
|
+
let lastRowMax = 0;
|
|
55094
|
+
let rowOffset = 0;
|
|
55026
55095
|
items.forEach((item, index) => {
|
|
55027
|
-
const
|
|
55096
|
+
const row = Math.floor(index / cols);
|
|
55097
|
+
const col = index % cols;
|
|
55028
55098
|
if (direction === "x") {
|
|
55029
|
-
|
|
55030
|
-
|
|
55099
|
+
const gapValue = Array.isArray(gap) ? gap[index - 1] ?? 0 : gap;
|
|
55100
|
+
if (col === 0 && row > 0) {
|
|
55101
|
+
rowOffset += lastRowMax + gapValue;
|
|
55102
|
+
lastRowMax = 0;
|
|
55103
|
+
}
|
|
55104
|
+
item.x = col === 0 ? 0 : items[index - 1].x + items[index - 1].width + gapValue;
|
|
55105
|
+
item.y = rowOffset;
|
|
55106
|
+
lastRowMax = Math.max(lastRowMax, item.height);
|
|
55031
55107
|
} else {
|
|
55032
|
-
|
|
55033
|
-
|
|
55108
|
+
const gapValue = Array.isArray(gap) ? gap[index - 1] ?? 0 : gap;
|
|
55109
|
+
if (col === 0 && row > 0) {
|
|
55110
|
+
rowOffset += lastRowMax + gapValue;
|
|
55111
|
+
lastRowMax = 0;
|
|
55112
|
+
}
|
|
55113
|
+
item.y = col === 0 ? 0 : items[index - 1].y + items[index - 1].height + gapValue;
|
|
55114
|
+
item.x = rowOffset;
|
|
55115
|
+
lastRowMax = Math.max(lastRowMax, item.width);
|
|
55034
55116
|
}
|
|
55035
55117
|
});
|
|
55036
55118
|
};
|