jpf 5.0.41 → 5.0.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.
- package/dist/framework/event.d.ts +16 -10
- package/dist/framework/event.js +24 -13
- package/dist/framework/event.js.map +1 -1
- package/package.json +1 -1
- package/src/framework/event.ts +68 -42
|
@@ -1,22 +1,28 @@
|
|
|
1
|
-
export type EventType = typeof Event | typeof KeyboardEvent | typeof PointerEvent;
|
|
2
|
-
export type
|
|
1
|
+
export type EventType = typeof Event | typeof UIEvent | typeof KeyboardEvent | typeof PointerEvent | typeof TouchEvent | typeof MouseEvent | typeof FocusEvent;
|
|
2
|
+
export type UiEventType = "load" | "unload" | "abort" | "error" | "select";
|
|
3
3
|
export type KeyboardEventType = "keydown" | "keyup" | "keypress";
|
|
4
|
-
export type
|
|
4
|
+
export type PointerEventType = "click" | "pointerdown" | "pointerup" | "pointermove";
|
|
5
|
+
export type TouchEventType = "touchstart" | "touchend" | "touchmove" | "touchcancel";
|
|
6
|
+
export type MouseEventType = "contextmenu" | "dblclick" | "mousedown" | "mouseenter" | "mouseleave" | "mousemove" | "mouseout" | "mouseover" | "mouseup";
|
|
7
|
+
export type FocusEventType = "blur" | "focusout" | "focus" | "focusin";
|
|
5
8
|
export interface IEventListener extends AddEventListenerOptions, KeyboardEventInit {
|
|
6
9
|
type: EventType;
|
|
7
10
|
name: string;
|
|
8
11
|
handler: (event: any) => void;
|
|
9
12
|
}
|
|
10
|
-
export declare function createEvent<TEvent>(name: string, handler: (event: TEvent) => void): IEventListener;
|
|
13
|
+
export declare function createEvent<TEvent>(type: EventType, name: string, handler: (event: TEvent) => void): IEventListener;
|
|
14
|
+
export declare function createUiEvent(name: UiEventType, handler: (event: UIEvent) => void): IEventListener;
|
|
15
|
+
export declare function createKeyBoardEvent(name: KeyboardEventType, handler: (event: KeyboardEvent) => void): IEventListener;
|
|
11
16
|
export declare function createPointerEvent(name: PointerEventType, handler: (event: PointerEvent) => void): IEventListener;
|
|
12
17
|
export declare function createClickEvent(handler: (event: PointerEvent) => void): IEventListener;
|
|
13
|
-
export declare function
|
|
14
|
-
export declare function
|
|
18
|
+
export declare function createTouchEvent(name: TouchEventType, handler: (event: TouchEvent) => void): IEventListener;
|
|
19
|
+
export declare function createMouseEvent(name: MouseEventType, handler: (event: MouseEvent) => void): IEventListener;
|
|
20
|
+
export declare function createFocusEvent(name: FocusEventType, handler: (event: FocusEvent) => void): IEventListener;
|
|
15
21
|
interface ISwipeEventOptions {
|
|
16
|
-
leftHandler?: (event:
|
|
17
|
-
rightHandler?: (event:
|
|
18
|
-
upHandler?: (event:
|
|
19
|
-
downHandler?: (event:
|
|
22
|
+
leftHandler?: (event: TouchEvent) => void;
|
|
23
|
+
rightHandler?: (event: TouchEvent) => void;
|
|
24
|
+
upHandler?: (event: TouchEvent) => void;
|
|
25
|
+
downHandler?: (event: TouchEvent) => void;
|
|
20
26
|
distance?: number;
|
|
21
27
|
}
|
|
22
28
|
export declare function createSwipeEvent(options: ISwipeEventOptions): Array<IEventListener>;
|
package/dist/framework/event.js
CHANGED
|
@@ -5,20 +5,29 @@ function createEventListener(type, name, handler) {
|
|
|
5
5
|
handler: handler
|
|
6
6
|
};
|
|
7
7
|
}
|
|
8
|
-
export function createEvent(name, handler) {
|
|
9
|
-
return createEventListener(
|
|
8
|
+
export function createEvent(type, name, handler) {
|
|
9
|
+
return createEventListener(type, name, handler);
|
|
10
|
+
}
|
|
11
|
+
export function createUiEvent(name, handler) {
|
|
12
|
+
return createEventListener(UIEvent, name, handler);
|
|
13
|
+
}
|
|
14
|
+
export function createKeyBoardEvent(name, handler) {
|
|
15
|
+
return createEventListener(KeyboardEvent, name, handler);
|
|
10
16
|
}
|
|
11
17
|
export function createPointerEvent(name, handler) {
|
|
12
18
|
return createEventListener(PointerEvent, name, handler);
|
|
13
19
|
}
|
|
14
20
|
export function createClickEvent(handler) {
|
|
15
|
-
return createPointerEvent("
|
|
21
|
+
return createPointerEvent("click", handler);
|
|
16
22
|
}
|
|
17
|
-
export function
|
|
18
|
-
return createEventListener(
|
|
23
|
+
export function createTouchEvent(name, handler) {
|
|
24
|
+
return createEventListener(TouchEvent, name, handler);
|
|
25
|
+
}
|
|
26
|
+
export function createMouseEvent(name, handler) {
|
|
27
|
+
return createEventListener(MouseEvent, name, handler);
|
|
19
28
|
}
|
|
20
|
-
export function
|
|
21
|
-
return createEventListener(
|
|
29
|
+
export function createFocusEvent(name, handler) {
|
|
30
|
+
return createEventListener(FocusEvent, name, handler);
|
|
22
31
|
}
|
|
23
32
|
export function createSwipeEvent(options) {
|
|
24
33
|
let startX = 0;
|
|
@@ -27,13 +36,15 @@ export function createSwipeEvent(options) {
|
|
|
27
36
|
let endY = 0;
|
|
28
37
|
const distance = options.distance || 50;
|
|
29
38
|
return [
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
39
|
+
createEvent(TouchEvent, "touchstart", (event) => {
|
|
40
|
+
const touch = event.touches[0];
|
|
41
|
+
startX = touch.clientX;
|
|
42
|
+
startY = touch.clientY;
|
|
33
43
|
}),
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
44
|
+
createEvent(TouchEvent, "touchend", (event) => {
|
|
45
|
+
const touch = event.changedTouches[0];
|
|
46
|
+
endX = touch.clientX;
|
|
47
|
+
endY = touch.clientY;
|
|
37
48
|
if (startX > endX + distance) {
|
|
38
49
|
if (options.leftHandler) {
|
|
39
50
|
options.leftHandler(event);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"event.js","sourceRoot":"","sources":["../../src/framework/event.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"event.js","sourceRoot":"","sources":["../../src/framework/event.ts"],"names":[],"mappings":"AAmBA,SAAS,mBAAmB,CAAS,IAAe,EAAE,IAAY,EAAE,OAAgC;IAChG,OAAO;QACH,IAAI,EAAE,IAAI;QACV,IAAI,EAAE,IAAI;QACV,OAAO,EAAE,OAAO;KACnB,CAAC;AACN,C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AAC,CACJ;KACJ,CAAA;AACL,CAAC"}
|
package/package.json
CHANGED
package/src/framework/event.ts
CHANGED
|
@@ -1,9 +1,15 @@
|
|
|
1
1
|
import { key } from "../utilities";
|
|
2
2
|
|
|
3
|
-
export type EventType = typeof Event | typeof KeyboardEvent | typeof PointerEvent;
|
|
4
|
-
|
|
3
|
+
export type EventType = typeof Event | typeof UIEvent | typeof KeyboardEvent | typeof PointerEvent | typeof TouchEvent | typeof MouseEvent | typeof FocusEvent;
|
|
4
|
+
|
|
5
|
+
export type UiEventType = "load" | "unload" | "abort" | "error" | "select";
|
|
5
6
|
export type KeyboardEventType = "keydown" | "keyup" | "keypress";
|
|
6
|
-
export type
|
|
7
|
+
export type PointerEventType = "click" | "pointerdown" | "pointerup" | "pointermove";
|
|
8
|
+
export type TouchEventType = "touchstart" | "touchend" | "touchmove" | "touchcancel";
|
|
9
|
+
export type MouseEventType = "contextmenu" | "dblclick" | "mousedown" | "mouseenter" | "mouseleave" | "mousemove" | "mouseout" | "mouseover" | "mouseup";
|
|
10
|
+
export type FocusEventType = "blur" | "focusout" | "focus" | "focusin";
|
|
11
|
+
|
|
12
|
+
|
|
7
13
|
|
|
8
14
|
export interface IEventListener extends AddEventListenerOptions, KeyboardEventInit {
|
|
9
15
|
type: EventType;
|
|
@@ -19,36 +25,49 @@ function createEventListener<TEvent>(type: EventType, name: string, handler: (ev
|
|
|
19
25
|
};
|
|
20
26
|
}
|
|
21
27
|
|
|
22
|
-
//
|
|
23
|
-
export function createEvent<TEvent>(name: string, handler: (event: TEvent) => void): IEventListener {
|
|
24
|
-
return createEventListener(
|
|
28
|
+
//Event creator
|
|
29
|
+
export function createEvent<TEvent>(type: EventType, name: string, handler: (event: TEvent) => void): IEventListener {
|
|
30
|
+
return createEventListener(type, name, handler);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
//UiEvent creator
|
|
34
|
+
export function createUiEvent(name: UiEventType, handler: (event: UIEvent) => void): IEventListener {
|
|
35
|
+
return createEventListener(UIEvent, name, handler);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// KeyBoard event creator
|
|
39
|
+
export function createKeyBoardEvent(name: KeyboardEventType, handler: (event: KeyboardEvent) => void): IEventListener {
|
|
40
|
+
return createEventListener(KeyboardEvent, name, handler);
|
|
25
41
|
}
|
|
26
42
|
|
|
27
|
-
//
|
|
43
|
+
//PointerEvent creator
|
|
28
44
|
export function createPointerEvent(name: PointerEventType, handler: (event: PointerEvent) => void): IEventListener {
|
|
29
45
|
return createEventListener(PointerEvent, name, handler);
|
|
30
46
|
}
|
|
31
47
|
|
|
32
48
|
// Click event creator for convenience
|
|
33
49
|
export function createClickEvent(handler: (event: PointerEvent) => void): IEventListener {
|
|
34
|
-
return createPointerEvent("
|
|
50
|
+
return createPointerEvent("click", handler);
|
|
35
51
|
}
|
|
36
52
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
53
|
+
export function createTouchEvent(name: TouchEventType, handler: (event: TouchEvent) => void): IEventListener {
|
|
54
|
+
return createEventListener(TouchEvent, name, handler);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export function createMouseEvent(name: MouseEventType, handler: (event: MouseEvent) => void): IEventListener {
|
|
58
|
+
return createEventListener(MouseEvent, name, handler);
|
|
40
59
|
}
|
|
41
60
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
return createEventListener(Event, name, handler);
|
|
61
|
+
export function createFocusEvent(name: FocusEventType, handler: (event: FocusEvent) => void): IEventListener {
|
|
62
|
+
return createEventListener(FocusEvent, name, handler);
|
|
45
63
|
}
|
|
46
64
|
|
|
65
|
+
|
|
47
66
|
interface ISwipeEventOptions {
|
|
48
|
-
leftHandler?: (event:
|
|
49
|
-
rightHandler?: (event:
|
|
50
|
-
upHandler?: (event:
|
|
51
|
-
downHandler?: (event:
|
|
67
|
+
leftHandler?: (event: TouchEvent) => void;
|
|
68
|
+
rightHandler?: (event: TouchEvent) => void;
|
|
69
|
+
upHandler?: (event: TouchEvent) => void;
|
|
70
|
+
downHandler?: (event: TouchEvent) => void;
|
|
52
71
|
distance?: number;
|
|
53
72
|
}
|
|
54
73
|
|
|
@@ -60,33 +79,40 @@ export function createSwipeEvent(options: ISwipeEventOptions): Array<IEventListe
|
|
|
60
79
|
let endY = 0;
|
|
61
80
|
const distance = options.distance || 50;
|
|
62
81
|
return [
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
82
|
+
createEvent(
|
|
83
|
+
TouchEvent,
|
|
84
|
+
"touchstart",
|
|
85
|
+
(event: TouchEvent) => {
|
|
86
|
+
const touch = event.touches[0];
|
|
87
|
+
startX = touch.clientX;
|
|
88
|
+
startY = touch.clientY;
|
|
68
89
|
}
|
|
69
90
|
),
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
91
|
+
createEvent(
|
|
92
|
+
TouchEvent,
|
|
93
|
+
"touchend",
|
|
94
|
+
(event: TouchEvent) => {
|
|
95
|
+
const touch = event.changedTouches[0];
|
|
96
|
+
endX = touch.clientX;
|
|
97
|
+
endY = touch.clientY;
|
|
98
|
+
if (startX > endX + distance) {
|
|
99
|
+
if (options.leftHandler) {
|
|
100
|
+
options.leftHandler(event);
|
|
101
|
+
}
|
|
102
|
+
} else if (endX > startX + distance) {
|
|
103
|
+
if (options.rightHandler) {
|
|
104
|
+
options.rightHandler(event);
|
|
105
|
+
}
|
|
106
|
+
} else if (startY > endY + distance) {
|
|
107
|
+
if (options.upHandler) {
|
|
108
|
+
options.upHandler(event);
|
|
109
|
+
}
|
|
110
|
+
} else if (endY > startY + distance) {
|
|
111
|
+
if (options.downHandler) {
|
|
112
|
+
options.downHandler(event);
|
|
113
|
+
}
|
|
88
114
|
}
|
|
89
115
|
}
|
|
90
|
-
|
|
116
|
+
)
|
|
91
117
|
]
|
|
92
118
|
}
|