lyb-pixi-js 1.12.42 → 1.12.43

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.
@@ -2,10 +2,10 @@ import type { Container, DisplayObjectEvents, FederatedPointerEvent } from "pixi
2
2
  export interface LibPixiEventParams {
3
3
  /** 是否只执行一次 */
4
4
  once?: boolean;
5
- /** 是否启用防抖 */
6
- debounce?: boolean;
7
- /** 防抖时长 */
8
- debounceTime?: number;
5
+ /** 是否启用节流 */
6
+ throttle?: boolean;
7
+ /** 节流时长 */
8
+ throttleTime?: number;
9
9
  /** 是否阻止拖动点击 */
10
10
  preventDragClick?: boolean;
11
11
  }
@@ -1,16 +1,11 @@
1
- const debounceImmediate = (func, wait) => {
2
- let timer = null;
3
- let invoked = false;
1
+ const throttleImmediate = (func, wait) => {
2
+ let lastTime = 0;
4
3
  return (...args) => {
5
- if (!invoked) {
4
+ const now = Date.now();
5
+ if (now - lastTime >= wait) {
6
+ lastTime = now;
6
7
  func(...args);
7
- invoked = true;
8
8
  }
9
- if (timer)
10
- clearTimeout(timer);
11
- timer = setTimeout(() => {
12
- invoked = false;
13
- }, wait);
14
9
  };
15
10
  };
16
11
  /** @description 事件注册
@@ -21,7 +16,7 @@ const debounceImmediate = (func, wait) => {
21
16
  * @link 使用方法:https://www.npmjs.com/package/lyb-pixi-js#LibPixiEvent-事件注册
22
17
  */
23
18
  export const libPixiEvent = (v, eventName, callback, params = {}) => {
24
- const { once = false, debounce = false, debounceTime = 1000, preventDragClick = false, } = params;
19
+ const { once = false, throttle = false, throttleTime = 1000, preventDragClick = false, } = params;
25
20
  v.cursor = "pointer";
26
21
  v.eventMode = "static";
27
22
  let lastX = 0;
@@ -55,7 +50,7 @@ export const libPixiEvent = (v, eventName, callback, params = {}) => {
55
50
  return;
56
51
  callback(e);
57
52
  };
58
- const handler = debounce ? debounceImmediate(fn, debounceTime) : fn;
53
+ const handler = throttle ? throttleImmediate(fn, throttleTime) : fn;
59
54
  if (once) {
60
55
  v.once(eventName, handler);
61
56
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lyb-pixi-js",
3
- "version": "1.12.42",
3
+ "version": "1.12.43",
4
4
  "description": "自用Pixi.JS方法库",
5
5
  "license": "ISC",
6
6
  "exports": {