@leafer-ui/event 1.0.0-rc.10

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2023-present, Chao (Leafer) Wan
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
package/README.md ADDED
@@ -0,0 +1 @@
1
+ # @leafer-ui/event
package/package.json ADDED
@@ -0,0 +1,27 @@
1
+ {
2
+ "name": "@leafer-ui/event",
3
+ "version": "1.0.0-rc.10",
4
+ "description": "@leafer-ui/event",
5
+ "author": "Chao (Leafer) Wan",
6
+ "license": "MIT",
7
+ "main": "src/index.ts",
8
+ "types": "types/index.d.ts",
9
+ "files": [
10
+ "src",
11
+ "types",
12
+ "dist"
13
+ ],
14
+ "repository": {
15
+ "type": "git",
16
+ "url": "https://github.com/leaferjs/ui.git"
17
+ },
18
+ "homepage": "https://github.com/leaferjs/ui/tree/main/packages/event",
19
+ "bugs": "https://github.com/leaferjs/ui/issues",
20
+ "keywords": [
21
+ "leafer-ui",
22
+ "leaferjs"
23
+ ],
24
+ "dependencies": {
25
+ "@leafer/event-ui": "1.0.0-rc.10"
26
+ }
27
+ }
@@ -0,0 +1,73 @@
1
+ import { IDragEvent, IPointData, ILeaf, ILeafList, IObject } from '@leafer/interface'
2
+ import { registerUIEvent, LeafList } from '@leafer/core'
3
+
4
+ import { PointerEvent } from './PointerEvent'
5
+
6
+
7
+ const move = {} as IPointData
8
+
9
+ @registerUIEvent()
10
+ export class DragEvent extends PointerEvent implements IDragEvent {
11
+
12
+ static BEFORE_DRAG = 'drag.before_drag'
13
+
14
+ static START = 'drag.start'
15
+ static DRAG = 'drag'
16
+ static END = 'drag.end'
17
+
18
+ static OVER = 'drag.over'
19
+ static OUT = 'drag.out'
20
+
21
+ static ENTER = 'drag.enter'
22
+ static LEAVE = 'drag.leave'
23
+
24
+ readonly moveX: number
25
+ readonly moveY: number
26
+ readonly totalX: number
27
+ readonly totalY: number
28
+
29
+ static list: ILeafList
30
+ static data: IObject
31
+
32
+ static setList(data: ILeaf | ILeaf[] | ILeafList): void {
33
+ this.list = data instanceof LeafList ? data : new LeafList(data as ILeaf[])
34
+ }
35
+
36
+ static setData(data: IObject): void {
37
+ this.data = data
38
+ }
39
+ public getPageMove(total?: boolean): IPointData {
40
+ this.assignMove(total)
41
+ return this.current.getPagePoint(move, null, true)
42
+ }
43
+
44
+ public getInnerMove(relative?: ILeaf, total?: boolean): IPointData {
45
+ if (!relative) relative = this.current
46
+ this.assignMove(total)
47
+ return relative.getInnerPoint(move, null, true)
48
+ }
49
+
50
+ public getLocalMove(relative?: ILeaf, total?: boolean): IPointData {
51
+ if (!relative) relative = this.current
52
+ this.assignMove(total)
53
+ return relative.getLocalPoint(move, null, true)
54
+ }
55
+
56
+ public getPageTotal(): IPointData {
57
+ return this.getPageMove(true)
58
+ }
59
+
60
+ public getInnerTotal(relative?: ILeaf): IPointData {
61
+ return this.getInnerMove(relative, true)
62
+ }
63
+
64
+ public getLocalTotal(relative?: ILeaf): IPointData {
65
+ return this.getLocalMove(relative, true)
66
+ }
67
+
68
+ protected assignMove(total: boolean): void {
69
+ move.x = total ? this.totalX : this.moveX
70
+ move.y = total ? this.totalY : this.moveY
71
+ }
72
+
73
+ }
@@ -0,0 +1,24 @@
1
+ import { IDropEvent, ILeaf, ILeafList, IObject } from '@leafer/interface'
2
+ import { registerUIEvent } from '@leafer/core'
3
+
4
+ import { PointerEvent } from './PointerEvent'
5
+ import { DragEvent } from './DragEvent'
6
+
7
+
8
+ @registerUIEvent()
9
+ export class DropEvent extends PointerEvent implements IDropEvent {
10
+
11
+ static DROP = 'drop'
12
+
13
+ readonly list: ILeafList
14
+ readonly data: IObject
15
+
16
+ static setList(data: ILeaf | ILeaf[] | ILeafList): void {
17
+ DragEvent.setList(data)
18
+ }
19
+
20
+ static setData(data: IObject): void {
21
+ DragEvent.setData(data)
22
+ }
23
+
24
+ }
@@ -0,0 +1,17 @@
1
+ import { IKeyEvent } from '@leafer/interface'
2
+ import { registerUIEvent } from '@leafer/core'
3
+
4
+ import { UIEvent } from './UIEvent'
5
+
6
+
7
+ @registerUIEvent()
8
+ export class KeyEvent extends UIEvent implements IKeyEvent {
9
+
10
+ static DOWN = 'key.down'
11
+ static HOLD = 'key.hold'
12
+ static UP = 'key.up'
13
+
14
+ public readonly code: string
15
+ public readonly key: string
16
+
17
+ }
@@ -0,0 +1,24 @@
1
+ import { IBooleanMap } from '@leafer/interface'
2
+
3
+
4
+ const downKeyMap: IBooleanMap = {}
5
+
6
+ export const Keyboard = {
7
+
8
+ isHoldSpaceKey(): boolean {
9
+ return Keyboard.isHold('Space')
10
+ },
11
+
12
+ isHold(code: string): boolean {
13
+ return downKeyMap[code]
14
+ },
15
+
16
+ setDownCode(code: string): void {
17
+ if (!downKeyMap[code]) downKeyMap[code] = true
18
+ },
19
+
20
+ setUpCode(code: string): void {
21
+ downKeyMap[code] = false
22
+ }
23
+
24
+ }
@@ -0,0 +1,15 @@
1
+ import { IMoveEvent } from '@leafer/interface'
2
+ import { registerUIEvent } from '@leafer/core'
3
+
4
+ import { DragEvent } from './DragEvent'
5
+
6
+ @registerUIEvent()
7
+ export class MoveEvent extends DragEvent implements IMoveEvent {
8
+
9
+ static BEFORE_MOVE = 'move.before_move'
10
+
11
+ static START = 'move.start'
12
+ static MOVE = 'move'
13
+ static END = 'move.end'
14
+
15
+ }
@@ -0,0 +1,20 @@
1
+ import { IUIEvent } from '@leafer/interface'
2
+
3
+
4
+ export const PointerButton = {
5
+
6
+ LEFT: 1,
7
+
8
+ RIGHT: 2,
9
+
10
+ MIDDLE: 4,
11
+
12
+ defaultLeft(event: IUIEvent): void { if (!event.buttons) event.buttons = 1 },
13
+
14
+ left(event: IUIEvent): boolean { return event.buttons === 1 },
15
+
16
+ right(event: IUIEvent): boolean { return event.buttons === 2 },
17
+
18
+ middle(event: IUIEvent): boolean { return event.buttons === 4 }
19
+
20
+ }
@@ -0,0 +1,47 @@
1
+ import { IPointerEvent, PointerType } from '@leafer/interface'
2
+ import { registerUIEvent } from '@leafer/core'
3
+
4
+ import { UIEvent } from './UIEvent'
5
+
6
+
7
+ @registerUIEvent()
8
+ export class PointerEvent extends UIEvent implements IPointerEvent {
9
+
10
+ static POINTER = 'pointer'
11
+
12
+ static BEFORE_DOWN = 'pointer.before_down'
13
+ static BEFORE_MOVE = 'pointer.before_move'
14
+ static BEFORE_UP = 'pointer.before_up'
15
+
16
+ static DOWN = 'pointer.down'
17
+ static MOVE = 'pointer.move'
18
+ static UP = 'pointer.up'
19
+
20
+ static OVER = 'pointer.over'
21
+ static OUT = 'pointer.out'
22
+
23
+ static ENTER = 'pointer.enter'
24
+ static LEAVE = 'pointer.leave'
25
+
26
+ static TAP = 'tap'
27
+ static DOUBLE_TAP = 'double_tap'
28
+
29
+ static CLICK = 'click'
30
+ static DOUBLE_CLICK = 'double_click'
31
+
32
+ static LONG_PRESS = 'long_press'
33
+ static LONG_TAP = 'long_tap'
34
+
35
+ static MENU = 'pointer.menu'
36
+ static MENU_TAP = 'pointer.menu_tap'
37
+
38
+ public readonly width: number
39
+ public readonly height: number
40
+ public readonly pointerType: PointerType
41
+ public readonly pressure: number
42
+ public readonly tangentialPressure?: number
43
+ public readonly tiltX?: number
44
+ public readonly tiltY?: number
45
+ public readonly twist?: number
46
+
47
+ }
@@ -0,0 +1,18 @@
1
+ import { IRotateEvent } from '@leafer/interface'
2
+ import { registerUIEvent } from '@leafer/core'
3
+
4
+ import { UIEvent } from './UIEvent'
5
+
6
+
7
+ @registerUIEvent()
8
+ export class RotateEvent extends UIEvent implements IRotateEvent {
9
+
10
+ static BEFORE_ROTATE = 'rotate.before_rotate'
11
+
12
+ static START = 'rotate.start'
13
+ static ROTATE = 'rotate'
14
+ static END = 'rotate.end'
15
+
16
+ readonly rotation: number
17
+
18
+ }
@@ -0,0 +1,20 @@
1
+ import { ISwipeEvent } from '@leafer/interface'
2
+ import { registerUIEvent } from '@leafer/core'
3
+
4
+ import { DragEvent } from './DragEvent'
5
+
6
+
7
+ @registerUIEvent()
8
+ export class SwipeEvent extends DragEvent implements ISwipeEvent {
9
+
10
+ static SWIPE = 'swipe'
11
+
12
+ static LEFT = 'swipe.left'
13
+ static RIGHT = 'swipe.right'
14
+ static UP = 'swipe.up'
15
+ static DOWN = 'swipe.down'
16
+
17
+ readonly speed: number
18
+ readonly direction: string
19
+
20
+ }
package/src/UIEvent.ts ADDED
@@ -0,0 +1,54 @@
1
+ import { ILeaf, ILeafList, IPointData, IUIEvent } from '@leafer/interface'
2
+ import { Event, EventCreator } from '@leafer/core'
3
+
4
+ import { Keyboard } from './Keyboard'
5
+ import { PointerButton as B } from './PointerButton'
6
+
7
+
8
+ export class UIEvent extends Event implements IUIEvent {
9
+
10
+ readonly x: number
11
+ readonly y: number
12
+
13
+ readonly path: ILeafList
14
+ readonly throughPath?: ILeafList
15
+
16
+ readonly altKey: boolean
17
+ readonly ctrlKey: boolean
18
+ readonly shiftKey: boolean
19
+ readonly metaKey: boolean
20
+ public get spaceKey(): boolean { return Keyboard.isHoldSpaceKey() }
21
+
22
+ public get left(): boolean { return B.left(this) }
23
+ public get right(): boolean { return B.right(this) }
24
+ public get middle(): boolean { return B.middle(this) }
25
+ readonly buttons: number
26
+
27
+ declare readonly target: ILeaf
28
+ declare readonly current: ILeaf
29
+ readonly bubbles: boolean = true
30
+
31
+ constructor(params: IUIEvent) {
32
+ super(params.type)
33
+ Object.assign(this, params)
34
+ }
35
+
36
+ public getPage(): IPointData {
37
+ return this.current.getPagePoint(this)
38
+ }
39
+
40
+ public getInner(relative?: ILeaf): IPointData {
41
+ if (!relative) relative = this.current
42
+ return relative.getInnerPoint(this)
43
+ }
44
+
45
+ public getLocal(relative?: ILeaf): IPointData {
46
+ if (!relative) relative = this.current
47
+ return relative.getLocalPoint(this)
48
+ }
49
+
50
+ static changeName(oldName: string, newName: string): void {
51
+ EventCreator.changeName(oldName, newName)
52
+ }
53
+
54
+ }
@@ -0,0 +1,17 @@
1
+ import { IZoomEvent } from '@leafer/interface'
2
+ import { registerUIEvent } from '@leafer/core'
3
+
4
+ import { UIEvent } from './UIEvent'
5
+
6
+ @registerUIEvent()
7
+ export class ZoomEvent extends UIEvent implements IZoomEvent {
8
+
9
+ static BEFORE_ZOOM = 'zoom.before_zoom'
10
+
11
+ static START = 'zoom.start'
12
+ static ZOOM = 'zoom'
13
+ static END = 'zoom.end'
14
+
15
+ readonly scale: number
16
+
17
+ }
package/src/index.ts ADDED
@@ -0,0 +1,12 @@
1
+ export { UIEvent } from './UIEvent'
2
+ export { DragEvent } from './DragEvent'
3
+ export { DropEvent } from './DropEvent'
4
+ export { MoveEvent } from './MoveEvent'
5
+ export { PointerEvent } from './PointerEvent'
6
+ export { RotateEvent } from './RotateEvent'
7
+ export { SwipeEvent } from './SwipeEvent'
8
+ export { ZoomEvent } from './ZoomEvent'
9
+ export { KeyEvent } from './KeyEvent'
10
+
11
+ export { Keyboard } from './Keyboard'
12
+ export { PointerButton } from './PointerButton'
@@ -0,0 +1,150 @@
1
+ import { IUIEvent, ILeafList, ILeaf, IPointData, IPointerEvent, PointerType, IDragEvent, IObject, IDropEvent, IMoveEvent, IRotateEvent, ISwipeEvent, IZoomEvent, IKeyEvent } from '@leafer/interface';
2
+ import { Event } from '@leafer/core';
3
+
4
+ declare class UIEvent extends Event implements IUIEvent {
5
+ readonly x: number;
6
+ readonly y: number;
7
+ readonly path: ILeafList;
8
+ readonly throughPath?: ILeafList;
9
+ readonly altKey: boolean;
10
+ readonly ctrlKey: boolean;
11
+ readonly shiftKey: boolean;
12
+ readonly metaKey: boolean;
13
+ get spaceKey(): boolean;
14
+ get left(): boolean;
15
+ get right(): boolean;
16
+ get middle(): boolean;
17
+ readonly buttons: number;
18
+ readonly target: ILeaf;
19
+ readonly current: ILeaf;
20
+ readonly bubbles: boolean;
21
+ constructor(params: IUIEvent);
22
+ getPage(): IPointData;
23
+ getInner(relative?: ILeaf): IPointData;
24
+ getLocal(relative?: ILeaf): IPointData;
25
+ static changeName(oldName: string, newName: string): void;
26
+ }
27
+
28
+ declare class PointerEvent extends UIEvent implements IPointerEvent {
29
+ static POINTER: string;
30
+ static BEFORE_DOWN: string;
31
+ static BEFORE_MOVE: string;
32
+ static BEFORE_UP: string;
33
+ static DOWN: string;
34
+ static MOVE: string;
35
+ static UP: string;
36
+ static OVER: string;
37
+ static OUT: string;
38
+ static ENTER: string;
39
+ static LEAVE: string;
40
+ static TAP: string;
41
+ static DOUBLE_TAP: string;
42
+ static CLICK: string;
43
+ static DOUBLE_CLICK: string;
44
+ static LONG_PRESS: string;
45
+ static LONG_TAP: string;
46
+ static MENU: string;
47
+ static MENU_TAP: string;
48
+ readonly width: number;
49
+ readonly height: number;
50
+ readonly pointerType: PointerType;
51
+ readonly pressure: number;
52
+ readonly tangentialPressure?: number;
53
+ readonly tiltX?: number;
54
+ readonly tiltY?: number;
55
+ readonly twist?: number;
56
+ }
57
+
58
+ declare class DragEvent extends PointerEvent implements IDragEvent {
59
+ static BEFORE_DRAG: string;
60
+ static START: string;
61
+ static DRAG: string;
62
+ static END: string;
63
+ static OVER: string;
64
+ static OUT: string;
65
+ static ENTER: string;
66
+ static LEAVE: string;
67
+ readonly moveX: number;
68
+ readonly moveY: number;
69
+ readonly totalX: number;
70
+ readonly totalY: number;
71
+ static list: ILeafList;
72
+ static data: IObject;
73
+ static setList(data: ILeaf | ILeaf[] | ILeafList): void;
74
+ static setData(data: IObject): void;
75
+ getPageMove(total?: boolean): IPointData;
76
+ getInnerMove(relative?: ILeaf, total?: boolean): IPointData;
77
+ getLocalMove(relative?: ILeaf, total?: boolean): IPointData;
78
+ getPageTotal(): IPointData;
79
+ getInnerTotal(relative?: ILeaf): IPointData;
80
+ getLocalTotal(relative?: ILeaf): IPointData;
81
+ protected assignMove(total: boolean): void;
82
+ }
83
+
84
+ declare class DropEvent extends PointerEvent implements IDropEvent {
85
+ static DROP: string;
86
+ readonly list: ILeafList;
87
+ readonly data: IObject;
88
+ static setList(data: ILeaf | ILeaf[] | ILeafList): void;
89
+ static setData(data: IObject): void;
90
+ }
91
+
92
+ declare class MoveEvent extends DragEvent implements IMoveEvent {
93
+ static BEFORE_MOVE: string;
94
+ static START: string;
95
+ static MOVE: string;
96
+ static END: string;
97
+ }
98
+
99
+ declare class RotateEvent extends UIEvent implements IRotateEvent {
100
+ static BEFORE_ROTATE: string;
101
+ static START: string;
102
+ static ROTATE: string;
103
+ static END: string;
104
+ readonly rotation: number;
105
+ }
106
+
107
+ declare class SwipeEvent extends DragEvent implements ISwipeEvent {
108
+ static SWIPE: string;
109
+ static LEFT: string;
110
+ static RIGHT: string;
111
+ static UP: string;
112
+ static DOWN: string;
113
+ readonly speed: number;
114
+ readonly direction: string;
115
+ }
116
+
117
+ declare class ZoomEvent extends UIEvent implements IZoomEvent {
118
+ static BEFORE_ZOOM: string;
119
+ static START: string;
120
+ static ZOOM: string;
121
+ static END: string;
122
+ readonly scale: number;
123
+ }
124
+
125
+ declare class KeyEvent extends UIEvent implements IKeyEvent {
126
+ static DOWN: string;
127
+ static HOLD: string;
128
+ static UP: string;
129
+ readonly code: string;
130
+ readonly key: string;
131
+ }
132
+
133
+ declare const Keyboard: {
134
+ isHoldSpaceKey(): boolean;
135
+ isHold(code: string): boolean;
136
+ setDownCode(code: string): void;
137
+ setUpCode(code: string): void;
138
+ };
139
+
140
+ declare const PointerButton: {
141
+ LEFT: number;
142
+ RIGHT: number;
143
+ MIDDLE: number;
144
+ defaultLeft(event: IUIEvent): void;
145
+ left(event: IUIEvent): boolean;
146
+ right(event: IUIEvent): boolean;
147
+ middle(event: IUIEvent): boolean;
148
+ };
149
+
150
+ export { DragEvent, DropEvent, KeyEvent, Keyboard, MoveEvent, PointerButton, PointerEvent, RotateEvent, SwipeEvent, UIEvent, ZoomEvent };