lyb-pixi-js 1.10.7 → 1.10.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.
- package/Components/Custom/LibPixiPuzzleBg.d.ts +7 -0
- package/Components/Custom/LibPixiPuzzleBg.js +45 -0
- package/Components/Custom/LibPixiScrollContainerX.d.ts +1 -1
- package/Components/Custom/LibPixiScrollContainerX.js +1 -1
- package/Components/Custom/LibPixiScrollContainerY.d.ts +1 -1
- package/Components/Custom/LibPixiScrollContainerY.js +1 -1
- package/Utils/LibContainerCenter.d.ts +3 -0
- package/Utils/LibContainerCenter.js +10 -0
- package/Utils/LibPixiHVCenter.d.ts +7 -0
- package/Utils/LibPixiHVCenter.js +14 -0
- package/Utils/{LibArrangeLinear.d.ts → LibPixiHVGap.d.ts} +1 -2
- package/Utils/{LibArrangeLinear.js → LibPixiHVGap.js} +2 -5
- package/libPixiJs.d.ts +20 -0
- package/libPixiJs.js +23 -0
- package/lyb-pixi.js +3075 -618
- package/package.json +1 -1
- package/Utils/LibEmitContainerEvent.d.ts +0 -7
- package/Utils/LibEmitContainerEvent.js +0 -13
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { libJsDecimal } from "lyb-js/Math/LibJsDecimal.js";
|
|
2
|
+
import { Assets, Container, Sprite } from "pixi.js";
|
|
3
|
+
/** @description 设计图背景拼接
|
|
4
|
+
* @link 使用方法:https://www.npmjs.com/package/lyb-pixi-js#LibPixiPuzzleBg-设计图背景拼接
|
|
5
|
+
*/
|
|
6
|
+
export class LibPixiPuzzleBg extends Container {
|
|
7
|
+
constructor() {
|
|
8
|
+
super();
|
|
9
|
+
this.eventMode = "none";
|
|
10
|
+
// 背景
|
|
11
|
+
const bg = new Sprite(Assets.get("preload/bg"));
|
|
12
|
+
this.addChild(bg);
|
|
13
|
+
bg.visible = false;
|
|
14
|
+
//读取配置
|
|
15
|
+
const config = JSON.parse(localStorage.getItem("puzzle_bg_config") || "{}");
|
|
16
|
+
const { alpha, x, y } = config;
|
|
17
|
+
bg.alpha = alpha || 0.25;
|
|
18
|
+
bg.position.set(x || 0, y || 0);
|
|
19
|
+
//监听鼠标空格事件
|
|
20
|
+
document.addEventListener("keydown", (e) => {
|
|
21
|
+
if (e.code === "Space") {
|
|
22
|
+
bg.visible = !bg.visible;
|
|
23
|
+
}
|
|
24
|
+
else if (e.code === "ArrowUp") {
|
|
25
|
+
bg.y -= 2;
|
|
26
|
+
}
|
|
27
|
+
else if (e.code === "ArrowDown") {
|
|
28
|
+
bg.y += 2;
|
|
29
|
+
}
|
|
30
|
+
else if (e.code === "ArrowLeft") {
|
|
31
|
+
bg.x -= 2;
|
|
32
|
+
}
|
|
33
|
+
else if (e.code === "ArrowRight") {
|
|
34
|
+
bg.x += 2;
|
|
35
|
+
}
|
|
36
|
+
if (e.code === "NumpadAdd" && bg.alpha < 1) {
|
|
37
|
+
bg.alpha = libJsDecimal(bg.alpha, 0.1, "+");
|
|
38
|
+
}
|
|
39
|
+
else if (e.code === "NumpadSubtract" && bg.alpha > 0) {
|
|
40
|
+
bg.alpha = libJsDecimal(bg.alpha, 0.1, "-");
|
|
41
|
+
}
|
|
42
|
+
localStorage.setItem("puzzle_bg_config", JSON.stringify({ alpha: bg.alpha, x: bg.x, y: bg.y }));
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
}
|
|
@@ -13,7 +13,7 @@ export interface LibPixiScrollContainerXParams {
|
|
|
13
13
|
rightMargin?: number;
|
|
14
14
|
}
|
|
15
15
|
/** @description 支持鼠标滚轮滚动、鼠标拖动、手指滑动,支持惯性滚动及回弹
|
|
16
|
-
* @link 使用方法:https://www.npmjs.com/package/lyb-pixi-js#LibPixiScrollContainerX-X
|
|
16
|
+
* @link 使用方法:https://www.npmjs.com/package/lyb-pixi-js#LibPixiScrollContainerX-X轴滚动容器
|
|
17
17
|
*/
|
|
18
18
|
export declare class LibPixiScrollContainerX extends LibPixiContainer {
|
|
19
19
|
/** 开始位置 */
|
|
@@ -2,7 +2,7 @@ import { Container, Graphics, Sprite, } from "pixi.js";
|
|
|
2
2
|
import { gsap } from "gsap";
|
|
3
3
|
import { LibPixiContainer } from "../Base/LibPixiContainer";
|
|
4
4
|
/** @description 支持鼠标滚轮滚动、鼠标拖动、手指滑动,支持惯性滚动及回弹
|
|
5
|
-
* @link 使用方法:https://www.npmjs.com/package/lyb-pixi-js#LibPixiScrollContainerX-X
|
|
5
|
+
* @link 使用方法:https://www.npmjs.com/package/lyb-pixi-js#LibPixiScrollContainerX-X轴滚动容器
|
|
6
6
|
*/
|
|
7
7
|
export class LibPixiScrollContainerX extends LibPixiContainer {
|
|
8
8
|
constructor(params) {
|
|
@@ -23,7 +23,7 @@ export interface LibPixiScrollContainerYParams {
|
|
|
23
23
|
onScroll?: (y: number) => void;
|
|
24
24
|
}
|
|
25
25
|
/** @description 支持鼠标滚轮滚动、鼠标拖动、手指滑动,支持惯性滚动及回弹
|
|
26
|
-
* @link 使用方法:https://www.npmjs.com/package/lyb-pixi-js#LibPixiScrollContainerY-Y
|
|
26
|
+
* @link 使用方法:https://www.npmjs.com/package/lyb-pixi-js#LibPixiScrollContainerY-Y轴滚动容器
|
|
27
27
|
*/
|
|
28
28
|
export declare class LibPixiScrollContainerY extends LibPixiContainer {
|
|
29
29
|
/** 开始位置 */
|
|
@@ -4,7 +4,7 @@ import { libPixiEvent } from "../../Utils/LibPixiEvent";
|
|
|
4
4
|
import { LibPixiContainer } from "../Base/LibPixiContainer";
|
|
5
5
|
import { LibPixiRectangle } from "../Base/LibPixiRectangle";
|
|
6
6
|
/** @description 支持鼠标滚轮滚动、鼠标拖动、手指滑动,支持惯性滚动及回弹
|
|
7
|
-
* @link 使用方法:https://www.npmjs.com/package/lyb-pixi-js#LibPixiScrollContainerY-Y
|
|
7
|
+
* @link 使用方法:https://www.npmjs.com/package/lyb-pixi-js#LibPixiScrollContainerY-Y轴滚动容器
|
|
8
8
|
*/
|
|
9
9
|
export class LibPixiScrollContainerY extends LibPixiContainer {
|
|
10
10
|
constructor(params) {
|
|
@@ -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,14 @@
|
|
|
1
|
+
/** @description 列表居中
|
|
2
|
+
* @param parent 父容器
|
|
3
|
+
* @param items 子元素数组
|
|
4
|
+
* @param direction 方向数组,"x"表示水平,"y"表示垂直
|
|
5
|
+
*/
|
|
6
|
+
export const libPixiHVCenter = (parent, items, direction) => {
|
|
7
|
+
items.forEach((item) => {
|
|
8
|
+
direction.forEach((d) => {
|
|
9
|
+
item[d] =
|
|
10
|
+
parent[d === "x" ? "width" : "height"] / 2 -
|
|
11
|
+
item[d === "x" ? "width" : "height"] / 2;
|
|
12
|
+
});
|
|
13
|
+
});
|
|
14
|
+
};
|
|
@@ -4,6 +4,5 @@ import { Container } from "pixi.js";
|
|
|
4
4
|
* @param items 要排列的元素数组。
|
|
5
5
|
* @param gap 元素之间的间隔,可以是固定间隔或自定义的间隔数组。
|
|
6
6
|
* @param direction 排列方向,"x"表示水平,"y"表示垂直,默认为水平。
|
|
7
|
-
* @link 使用方法:https://www.npmjs.com/package/lyb-pixi-js#LibArrangeLinear-间隔布局
|
|
8
7
|
*/
|
|
9
|
-
export declare const
|
|
8
|
+
export declare const libPixiHVGap: (items: Container[], gap: number | number[], direction?: "x" | "y") => void;
|
|
@@ -3,9 +3,8 @@
|
|
|
3
3
|
* @param items 要排列的元素数组。
|
|
4
4
|
* @param gap 元素之间的间隔,可以是固定间隔或自定义的间隔数组。
|
|
5
5
|
* @param direction 排列方向,"x"表示水平,"y"表示垂直,默认为水平。
|
|
6
|
-
* @link 使用方法:https://www.npmjs.com/package/lyb-pixi-js#LibArrangeLinear-间隔布局
|
|
7
6
|
*/
|
|
8
|
-
export const
|
|
7
|
+
export const libPixiHVGap = (items, gap, direction = "x") => {
|
|
9
8
|
if (Array.isArray(gap)) {
|
|
10
9
|
if (gap.length !== items.length - 1) {
|
|
11
10
|
console.error(new Error("间隔的数组长度只能等于元素数组长度-1"));
|
|
@@ -14,9 +13,7 @@ export const LibArrangeLinear = (items, gap, direction = "x") => {
|
|
|
14
13
|
}
|
|
15
14
|
let lastPosition = 0;
|
|
16
15
|
items.forEach((item, index) => {
|
|
17
|
-
const position = index === 0
|
|
18
|
-
? 0
|
|
19
|
-
: lastPosition + (Array.isArray(gap) ? gap[index - 1] : gap);
|
|
16
|
+
const position = index === 0 ? 0 : lastPosition + (Array.isArray(gap) ? gap[index - 1] : gap);
|
|
20
17
|
if (direction === "x") {
|
|
21
18
|
item.x = position;
|
|
22
19
|
lastPosition = item.x + item.width;
|
package/libPixiJs.d.ts
CHANGED
|
@@ -25,6 +25,7 @@ import { LibPixiPolygon } from "./Components/Base/LibPixiPolygon";
|
|
|
25
25
|
import { LibPixiCircular } from "./Components/Base/LibPixiCircular";
|
|
26
26
|
import { LibPixiSlide } from "./Components/Custom/LibPixiSlide";
|
|
27
27
|
import { LibPixiLabelValue } from "./Components/Custom/LibPixiLabelValue";
|
|
28
|
+
import { LibPixiPuzzleBg } from "./Components/Custom/LibPixiPuzzleBg";
|
|
28
29
|
/** @description 组件 */
|
|
29
30
|
export declare const Components: {
|
|
30
31
|
Base: {
|
|
@@ -122,6 +123,10 @@ export declare const Components: {
|
|
|
122
123
|
* @link 使用方法:https://www.npmjs.com/package/lyb-pixi-js#LibPixiLabelValue-标签值
|
|
123
124
|
*/
|
|
124
125
|
LibPixiLabelValue: typeof LibPixiLabelValue;
|
|
126
|
+
/** @description 设计图背景拼接
|
|
127
|
+
* @link 使用方法:https://www.npmjs.com/package/lyb-pixi-js#LibPixiPuzzleBg-设计图背景拼接
|
|
128
|
+
*/
|
|
129
|
+
LibPixiPuzzleBg: typeof LibPixiPuzzleBg;
|
|
125
130
|
};
|
|
126
131
|
};
|
|
127
132
|
/** @description 方法 */
|
|
@@ -236,4 +241,19 @@ export declare const Utils: {
|
|
|
236
241
|
* @param payload 事件携带数据
|
|
237
242
|
*/
|
|
238
243
|
LibPixiEmitContainerEvent: (container: import("pixi.js").Container, event: string, payload?: any) => void;
|
|
244
|
+
/** @description 当前容器在父容器居中 */
|
|
245
|
+
libContainerCenter: (parent: import("pixi.js").Container, item: import("pixi.js").Container, centerType?: "x" | "y" | "xy") => void;
|
|
246
|
+
/** @description 列表居中
|
|
247
|
+
* @param parent 父容器
|
|
248
|
+
* @param items 子元素数组
|
|
249
|
+
* @param direction 方向数组,"x"表示水平,"y"表示垂直
|
|
250
|
+
*/
|
|
251
|
+
libPixiHVCenter: (parent: import("pixi.js").Container, items: import("pixi.js").Container[], direction: ("x" | "y")[]) => void;
|
|
252
|
+
/**
|
|
253
|
+
* @description 按照指定方向(水平或垂直)排列元素,支持固定间隔或自定义每个间隔。
|
|
254
|
+
* @param items 要排列的元素数组。
|
|
255
|
+
* @param gap 元素之间的间隔,可以是固定间隔或自定义的间隔数组。
|
|
256
|
+
* @param direction 排列方向,"x"表示水平,"y"表示垂直,默认为水平。
|
|
257
|
+
*/
|
|
258
|
+
libPixiHVGap: (items: import("pixi.js").Container[], gap: number | number[], direction?: "x" | "y") => void;
|
|
239
259
|
};
|
package/libPixiJs.js
CHANGED
|
@@ -40,6 +40,10 @@ import { LibPixiArrangeLinear } from "./Utils/LibPixiArrangeLinear";
|
|
|
40
40
|
import { LibPixiSlide } from "./Components/Custom/LibPixiSlide";
|
|
41
41
|
import { LibPixiEmitContainerEvent } from "./Utils/LibPixiEmitContainerEvent";
|
|
42
42
|
import { LibPixiLabelValue } from "./Components/Custom/LibPixiLabelValue";
|
|
43
|
+
import { LibPixiPuzzleBg } from "./Components/Custom/LibPixiPuzzleBg";
|
|
44
|
+
import { libContainerCenter } from "./Utils/LibContainerCenter";
|
|
45
|
+
import { libPixiHVCenter } from "./Utils/LibPixiHVCenter";
|
|
46
|
+
import { libPixiHVGap } from "./Utils/LibPixiHVGap";
|
|
43
47
|
/** @description 组件 */
|
|
44
48
|
export const Components = {
|
|
45
49
|
Base: {
|
|
@@ -137,6 +141,10 @@ export const Components = {
|
|
|
137
141
|
* @link 使用方法:https://www.npmjs.com/package/lyb-pixi-js#LibPixiLabelValue-标签值
|
|
138
142
|
*/
|
|
139
143
|
LibPixiLabelValue,
|
|
144
|
+
/** @description 设计图背景拼接
|
|
145
|
+
* @link 使用方法:https://www.npmjs.com/package/lyb-pixi-js#LibPixiPuzzleBg-设计图背景拼接
|
|
146
|
+
*/
|
|
147
|
+
LibPixiPuzzleBg,
|
|
140
148
|
},
|
|
141
149
|
};
|
|
142
150
|
/** @description 方法 */
|
|
@@ -251,4 +259,19 @@ export const Utils = {
|
|
|
251
259
|
* @param payload 事件携带数据
|
|
252
260
|
*/
|
|
253
261
|
LibPixiEmitContainerEvent,
|
|
262
|
+
/** @description 当前容器在父容器居中 */
|
|
263
|
+
libContainerCenter,
|
|
264
|
+
/** @description 列表居中
|
|
265
|
+
* @param parent 父容器
|
|
266
|
+
* @param items 子元素数组
|
|
267
|
+
* @param direction 方向数组,"x"表示水平,"y"表示垂直
|
|
268
|
+
*/
|
|
269
|
+
libPixiHVCenter,
|
|
270
|
+
/**
|
|
271
|
+
* @description 按照指定方向(水平或垂直)排列元素,支持固定间隔或自定义每个间隔。
|
|
272
|
+
* @param items 要排列的元素数组。
|
|
273
|
+
* @param gap 元素之间的间隔,可以是固定间隔或自定义的间隔数组。
|
|
274
|
+
* @param direction 排列方向,"x"表示水平,"y"表示垂直,默认为水平。
|
|
275
|
+
*/
|
|
276
|
+
libPixiHVGap,
|
|
254
277
|
};
|