lyb-pixi-js 1.4.10 → 1.5.0
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/README.md +25 -14
- package/Utils/LibPixiEvent.d.ts +10 -4
- package/Utils/LibPixiEvent.js +21 -6
- package/Utils/LibPixiEventControlled.d.ts +2 -2
- package/libPixiJs.d.ts +1 -8
- package/libPixiJs.js +0 -8
- package/lyb-pixi.js +71 -71
- package/package.json +4 -1
package/README.md
CHANGED
|
@@ -122,8 +122,6 @@ app.stage.addChild(box);
|
|
|
122
122
|
|
|
123
123
|
\- [LibPixiEvent-事件注册](#LibPixiEvent-事件注册)
|
|
124
124
|
|
|
125
|
-
\- [LibPixiEventControlled-可关闭的事件](#LibPixiEventControlled-可关闭的事件)
|
|
126
|
-
|
|
127
125
|
\- [LibPixiFilter-滤镜](#LibPixiFilter-滤镜)
|
|
128
126
|
|
|
129
127
|
\- [LibPixiIntervalTrigger-间隔触发](#LibPixiIntervalTrigger-间隔触发)
|
|
@@ -610,21 +608,34 @@ libPixiEvent(
|
|
|
610
608
|
(e) => {
|
|
611
609
|
console.log("Pointer up event triggered", e);
|
|
612
610
|
},
|
|
613
|
-
|
|
611
|
+
{
|
|
612
|
+
once: true,
|
|
613
|
+
}
|
|
614
614
|
);
|
|
615
|
-
```
|
|
616
615
|
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
616
|
+
//防抖
|
|
617
|
+
libPixiEvent(
|
|
618
|
+
container,
|
|
619
|
+
"pointerup",
|
|
620
|
+
(e) => {
|
|
621
|
+
console.log("Pointer up event triggered", e);
|
|
622
|
+
},
|
|
623
|
+
{
|
|
624
|
+
debounce: true,
|
|
625
|
+
debounceTime: 1000,
|
|
626
|
+
}
|
|
627
|
+
);
|
|
625
628
|
|
|
626
|
-
|
|
627
|
-
|
|
629
|
+
//停止监听
|
|
630
|
+
const off = libPixiEvent(
|
|
631
|
+
container,
|
|
632
|
+
"pointerup",
|
|
633
|
+
(e) => {
|
|
634
|
+
console.log("Pointer up event triggered", e);
|
|
635
|
+
},
|
|
636
|
+
true
|
|
637
|
+
);
|
|
638
|
+
off();
|
|
628
639
|
```
|
|
629
640
|
|
|
630
641
|
### LibPixiFilter-滤镜
|
package/Utils/LibPixiEvent.d.ts
CHANGED
|
@@ -1,10 +1,16 @@
|
|
|
1
|
-
import type { Container, DisplayObjectEvents } from "pixi.js";
|
|
1
|
+
import type { Container, DisplayObjectEvents, FederatedPointerEvent } from "pixi.js";
|
|
2
|
+
export interface LibPixiEventParams {
|
|
3
|
+
/** 是否只执行一次 */
|
|
4
|
+
once?: boolean;
|
|
5
|
+
/** 是否启用防抖 */
|
|
6
|
+
debounce?: boolean;
|
|
7
|
+
/** 防抖时长 */
|
|
8
|
+
debounceTime?: number;
|
|
9
|
+
}
|
|
2
10
|
/** @description 事件注册
|
|
3
11
|
* @param v 事件容器
|
|
4
12
|
* @param eventName 事件名称
|
|
5
13
|
* @param callback 回调函数
|
|
6
|
-
* @param once 是否只执行一次
|
|
7
14
|
* @returns 停止监听
|
|
8
|
-
* @link 使用方法:https://www.npmjs.com/package/lyb-pixi-js#LibPixiEvent-事件注册
|
|
9
15
|
*/
|
|
10
|
-
export declare const libPixiEvent: (v: Container, eventName: keyof DisplayObjectEvents, callback: (
|
|
16
|
+
export declare const libPixiEvent: (v: Container, eventName: keyof DisplayObjectEvents, callback: (event: FederatedPointerEvent) => void, params?: LibPixiEventParams) => () => void;
|
package/Utils/LibPixiEvent.js
CHANGED
|
@@ -1,12 +1,26 @@
|
|
|
1
|
+
const debounceImmediate = (func, wait) => {
|
|
2
|
+
let timer = null;
|
|
3
|
+
let invoked = false;
|
|
4
|
+
return (...args) => {
|
|
5
|
+
if (!invoked) {
|
|
6
|
+
func(...args);
|
|
7
|
+
invoked = true;
|
|
8
|
+
}
|
|
9
|
+
if (timer)
|
|
10
|
+
clearTimeout(timer);
|
|
11
|
+
timer = setTimeout(() => {
|
|
12
|
+
invoked = false;
|
|
13
|
+
}, wait);
|
|
14
|
+
};
|
|
15
|
+
};
|
|
1
16
|
/** @description 事件注册
|
|
2
17
|
* @param v 事件容器
|
|
3
18
|
* @param eventName 事件名称
|
|
4
19
|
* @param callback 回调函数
|
|
5
|
-
* @param once 是否只执行一次
|
|
6
20
|
* @returns 停止监听
|
|
7
|
-
* @link 使用方法:https://www.npmjs.com/package/lyb-pixi-js#LibPixiEvent-事件注册
|
|
8
21
|
*/
|
|
9
|
-
export const libPixiEvent = (v, eventName, callback,
|
|
22
|
+
export const libPixiEvent = (v, eventName, callback, params = {}) => {
|
|
23
|
+
const { once = false, debounce = false, debounceTime = 1000 } = params;
|
|
10
24
|
v.cursor = "pointer";
|
|
11
25
|
v.eventMode = "static";
|
|
12
26
|
const fn = (e) => {
|
|
@@ -14,13 +28,14 @@ export const libPixiEvent = (v, eventName, callback, once = false) => {
|
|
|
14
28
|
return;
|
|
15
29
|
callback(e);
|
|
16
30
|
};
|
|
31
|
+
const handler = debounce ? debounceImmediate(fn, debounceTime) : fn;
|
|
17
32
|
if (once) {
|
|
18
|
-
v.once(eventName,
|
|
33
|
+
v.once(eventName, handler);
|
|
19
34
|
}
|
|
20
35
|
else {
|
|
21
|
-
v.on(eventName,
|
|
36
|
+
v.on(eventName, handler);
|
|
22
37
|
}
|
|
23
38
|
return () => {
|
|
24
|
-
v.off(eventName,
|
|
39
|
+
v.off(eventName, handler);
|
|
25
40
|
};
|
|
26
41
|
};
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import type { Container, DisplayObjectEvents } from "pixi.js";
|
|
1
|
+
import type { Container, DisplayObjectEvents, FederatedPointerEvent } from "pixi.js";
|
|
2
2
|
/** @description 设置可关闭的事件监听,调用自身后不再触发
|
|
3
3
|
* @param container 事件容器
|
|
4
4
|
* @param eventName 事件名称
|
|
5
5
|
* @param callback 事件回调
|
|
6
6
|
* @link 使用方法:https://www.npmjs.com/package/lyb-pixi-js#LibPixiEventControlled-可关闭的事件
|
|
7
7
|
*/
|
|
8
|
-
export declare const libPixiEventControlled: (container: Container, eventName: keyof DisplayObjectEvents, callback: (
|
|
8
|
+
export declare const libPixiEventControlled: (container: Container, eventName: keyof DisplayObjectEvents, callback: (e: FederatedPointerEvent) => void) => () => void;
|
package/libPixiJs.d.ts
CHANGED
|
@@ -106,14 +106,7 @@ export declare const Utils: {
|
|
|
106
106
|
* @param once 是否只执行一次
|
|
107
107
|
* @link 使用方法:https://www.npmjs.com/package/lyb-pixi-js#LibPixiEvent-事件注册
|
|
108
108
|
*/
|
|
109
|
-
libPixiEvent: (v: import("pixi.js").Container, eventName: keyof import("pixi.js").DisplayObjectEvents, callback: (
|
|
110
|
-
/** @description 设置可关闭的事件监听,调用自身后不再触发
|
|
111
|
-
* @param container 事件容器
|
|
112
|
-
* @param eventName 事件名称
|
|
113
|
-
* @param callback 事件回调
|
|
114
|
-
* @link 使用方法:https://www.npmjs.com/package/lyb-pixi-js#LibPixiEventControlled-可关闭的事件
|
|
115
|
-
*/
|
|
116
|
-
libPixiEventControlled: (container: import("pixi.js").Container, eventName: keyof import("pixi.js").DisplayObjectEvents, callback: (...args: any) => void) => () => void;
|
|
109
|
+
libPixiEvent: (v: import("pixi.js").Container, eventName: keyof import("pixi.js").DisplayObjectEvents, callback: (event: import("pixi.js").FederatedPointerEvent) => void, params?: import("./Utils/LibPixiEvent").LibPixiEventParams) => () => void;
|
|
117
110
|
/** @description 滤镜
|
|
118
111
|
* @param filterName 滤镜名称
|
|
119
112
|
* @param v 滤镜值
|
package/libPixiJs.js
CHANGED
|
@@ -17,7 +17,6 @@ import { LibPixiTable } from "./Components/Custom/LibPixiTable";
|
|
|
17
17
|
import { LibPixiAudio } from "./Utils/LibPixiAudio";
|
|
18
18
|
import { libPixiCreateNineGrid } from "./Utils/LibPixiCreateNineGrid";
|
|
19
19
|
import { libPixiEvent } from "./Utils/LibPixiEvent";
|
|
20
|
-
import { libPixiEventControlled } from "./Utils/LibPixiEventControlled";
|
|
21
20
|
import { libPixiIntervalTrigger } from "./Utils/LibPixiIntervalTrigger";
|
|
22
21
|
import { libPixiOutsideClick } from "./Utils/LibPixiOutsideClick";
|
|
23
22
|
import { libPixiOverflowHidden } from "./Utils/LibPixiOverflowHidden";
|
|
@@ -118,13 +117,6 @@ export const Utils = {
|
|
|
118
117
|
* @link 使用方法:https://www.npmjs.com/package/lyb-pixi-js#LibPixiEvent-事件注册
|
|
119
118
|
*/
|
|
120
119
|
libPixiEvent,
|
|
121
|
-
/** @description 设置可关闭的事件监听,调用自身后不再触发
|
|
122
|
-
* @param container 事件容器
|
|
123
|
-
* @param eventName 事件名称
|
|
124
|
-
* @param callback 事件回调
|
|
125
|
-
* @link 使用方法:https://www.npmjs.com/package/lyb-pixi-js#LibPixiEventControlled-可关闭的事件
|
|
126
|
-
*/
|
|
127
|
-
libPixiEventControlled,
|
|
128
120
|
/** @description 滤镜
|
|
129
121
|
* @param filterName 滤镜名称
|
|
130
122
|
* @param v 滤镜值
|