@leafer/event 1.0.0-alpha.1
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 +21 -0
- package/README.md +1 -0
- package/package.json +25 -0
- package/src/AttrEvent.ts +23 -0
- package/src/ChildEvent.ts +22 -0
- package/src/Event.ts +35 -0
- package/src/LayoutEvent.ts +30 -0
- package/src/RenderEvent.ts +23 -0
- package/src/ResizeEvent.ts +40 -0
- package/src/TransformEvent.ts +34 -0
- package/src/WatchEvent.ts +20 -0
- package/src/index.ts +10 -0
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/event
|
package/package.json
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@leafer/event",
|
|
3
|
+
"version": "1.0.0-alpha.1",
|
|
4
|
+
"description": "@leafer/event",
|
|
5
|
+
"author": "Chao (Leafer) Wan",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"main": "src/index.ts",
|
|
8
|
+
"files": ["src"],
|
|
9
|
+
"repository": {
|
|
10
|
+
"type": "git",
|
|
11
|
+
"url": "https://github.com/leaferjs/leafer.git"
|
|
12
|
+
},
|
|
13
|
+
"homepage": "https://github.com/leaferjs/leafer/tree/main/packages/event",
|
|
14
|
+
"bugs": "https://github.com/leaferjs/leafer/issues",
|
|
15
|
+
"keywords": [
|
|
16
|
+
"leafer",
|
|
17
|
+
"leaferjs"
|
|
18
|
+
],
|
|
19
|
+
"dependencies": {
|
|
20
|
+
"@leafer/decorator": "1.0.0-alpha.1"
|
|
21
|
+
},
|
|
22
|
+
"devDependencies": {
|
|
23
|
+
"@leafer/interface": "1.0.0-alpha.1"
|
|
24
|
+
}
|
|
25
|
+
}
|
package/src/AttrEvent.ts
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { IAttrEvent, IEventTarget } from '@leafer/interface'
|
|
2
|
+
import { registerEvent } from '@leafer/decorator'
|
|
3
|
+
|
|
4
|
+
import { Event } from './Event'
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
@registerEvent()
|
|
8
|
+
export class AttrEvent extends Event implements IAttrEvent {
|
|
9
|
+
|
|
10
|
+
static CHANGE = 'attr.change'
|
|
11
|
+
|
|
12
|
+
readonly attrName: string
|
|
13
|
+
readonly oldValue: unknown
|
|
14
|
+
readonly newValue: unknown
|
|
15
|
+
|
|
16
|
+
constructor(type: string, target: IEventTarget, attrName: string, oldValue: unknown, newValue: unknown) {
|
|
17
|
+
super(type, target)
|
|
18
|
+
this.attrName = attrName
|
|
19
|
+
this.oldValue = oldValue
|
|
20
|
+
this.newValue = newValue
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { IChildEvent, ILeaf } from '@leafer/interface'
|
|
2
|
+
import { registerEvent } from '@leafer/decorator'
|
|
3
|
+
|
|
4
|
+
import { Event } from './Event'
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
@registerEvent()
|
|
8
|
+
export class ChildEvent extends Event implements IChildEvent {
|
|
9
|
+
|
|
10
|
+
static ADD = 'child.add'
|
|
11
|
+
static REMOVE = 'child.remove'
|
|
12
|
+
|
|
13
|
+
readonly parent?: ILeaf
|
|
14
|
+
readonly child?: ILeaf
|
|
15
|
+
|
|
16
|
+
constructor(type: string, child?: ILeaf, parent?: ILeaf) {
|
|
17
|
+
super(type, child)
|
|
18
|
+
this.parent = parent
|
|
19
|
+
this.child = child
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
}
|
package/src/Event.ts
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { IEvent, IEventTarget } from '@leafer/interface'
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
export class Event implements IEvent {
|
|
5
|
+
|
|
6
|
+
readonly type: string
|
|
7
|
+
readonly target: IEventTarget
|
|
8
|
+
readonly current: IEventTarget
|
|
9
|
+
|
|
10
|
+
readonly bubbles: boolean = false
|
|
11
|
+
readonly phase: number
|
|
12
|
+
|
|
13
|
+
public isStopDefault: boolean
|
|
14
|
+
public isStop: boolean
|
|
15
|
+
public isStopNow: boolean
|
|
16
|
+
|
|
17
|
+
constructor(type: string, target?: IEventTarget) {
|
|
18
|
+
this.type = type
|
|
19
|
+
if (target) this.target = target
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
public stopDefault(): void {
|
|
23
|
+
this.isStopDefault = true
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
public stopNow(): void {
|
|
27
|
+
this.isStopNow = true
|
|
28
|
+
this.isStop = true
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
public stop(): void {
|
|
32
|
+
this.isStop = true
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { ILayoutEvent, ILayoutBlockData } from '@leafer/interface'
|
|
2
|
+
import { registerEvent } from '@leafer/decorator'
|
|
3
|
+
|
|
4
|
+
import { Event } from './Event'
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
@registerEvent()
|
|
8
|
+
export class LayoutEvent extends Event implements ILayoutEvent {
|
|
9
|
+
|
|
10
|
+
static REQUEST = 'layout.request'
|
|
11
|
+
|
|
12
|
+
static START = 'layout.start'
|
|
13
|
+
|
|
14
|
+
static BEFORE_ONCE = 'layout.before_once'
|
|
15
|
+
static ONCE = 'layout.once'
|
|
16
|
+
static AFTER_ONCE = 'layout.after_once'
|
|
17
|
+
|
|
18
|
+
static AGAIN = 'layout.again'
|
|
19
|
+
|
|
20
|
+
static LAYOUT = 'layout'
|
|
21
|
+
static END = 'layout.end'
|
|
22
|
+
|
|
23
|
+
readonly data: ILayoutBlockData[]
|
|
24
|
+
|
|
25
|
+
constructor(type: string, data?: ILayoutBlockData[]) {
|
|
26
|
+
super(type)
|
|
27
|
+
if (data) this.data = data
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { IRenderEvent } from '@leafer/interface'
|
|
2
|
+
import { registerEvent } from '@leafer/decorator'
|
|
3
|
+
|
|
4
|
+
import { Event } from './Event'
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
@registerEvent()
|
|
8
|
+
export class RenderEvent extends Event implements IRenderEvent {
|
|
9
|
+
|
|
10
|
+
static REQUEST = 'render.request'
|
|
11
|
+
|
|
12
|
+
static START = 'render.start'
|
|
13
|
+
|
|
14
|
+
static BEFORE_ONCE = 'render.before_once'
|
|
15
|
+
static ONCE = 'render.once'
|
|
16
|
+
static AFTER_ONCE = 'render.after_once'
|
|
17
|
+
|
|
18
|
+
static AGAIN = 'render.again'
|
|
19
|
+
|
|
20
|
+
static RENDER = 'render'
|
|
21
|
+
static END = 'render.end'
|
|
22
|
+
|
|
23
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { IResizeEvent, IScreenSizeData } from '@leafer/interface'
|
|
2
|
+
import { registerEvent } from '@leafer/decorator'
|
|
3
|
+
|
|
4
|
+
import { Event } from './Event'
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
@registerEvent()
|
|
8
|
+
export class ResizeEvent extends Event implements IResizeEvent {
|
|
9
|
+
|
|
10
|
+
static RESIZE: string = 'resize'
|
|
11
|
+
|
|
12
|
+
readonly width: number
|
|
13
|
+
readonly height: number
|
|
14
|
+
readonly pixelRatio: number
|
|
15
|
+
|
|
16
|
+
public get bigger(): boolean {
|
|
17
|
+
if (!this.old) return true
|
|
18
|
+
const { width, height } = this.old
|
|
19
|
+
return this.width >= width && this.height >= height
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
public get smaller(): boolean {
|
|
23
|
+
return !this.bigger
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
public get samePixelRatio(): boolean {
|
|
27
|
+
if (!this.old) return true
|
|
28
|
+
return this.pixelRatio === this.old.pixelRatio
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
readonly old: IScreenSizeData
|
|
32
|
+
|
|
33
|
+
constructor(size: IScreenSizeData | string, oldSize?: IScreenSizeData) {
|
|
34
|
+
const realSize = typeof size === 'object'
|
|
35
|
+
super(realSize ? ResizeEvent.RESIZE : size)
|
|
36
|
+
if (realSize) Object.assign(this, size)
|
|
37
|
+
this.old = oldSize
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { ITransformEvent, ITransformEventData } from '@leafer/interface'
|
|
2
|
+
import { registerEvent } from '@leafer/decorator'
|
|
3
|
+
|
|
4
|
+
import { Event } from './Event'
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
@registerEvent()
|
|
8
|
+
export class TransformEvent extends Event implements ITransformEvent {
|
|
9
|
+
|
|
10
|
+
static BEFORE = 'transform.before'
|
|
11
|
+
static CHANGE = 'transform.change'
|
|
12
|
+
static AFTER = 'transform.after'
|
|
13
|
+
|
|
14
|
+
static PRE_BEFORE = 'transform.pre_before'
|
|
15
|
+
static PRE_CHANGE = 'transform.pre_change'
|
|
16
|
+
static PRE_AFTER = 'transform.pre_after'
|
|
17
|
+
|
|
18
|
+
readonly x: number
|
|
19
|
+
readonly y: number
|
|
20
|
+
readonly scaleX: number
|
|
21
|
+
readonly scaleY: number
|
|
22
|
+
readonly rotation: number
|
|
23
|
+
|
|
24
|
+
readonly zooming: boolean
|
|
25
|
+
readonly moving: boolean
|
|
26
|
+
readonly rotating: boolean
|
|
27
|
+
readonly changing: boolean
|
|
28
|
+
|
|
29
|
+
constructor(type: string, params?: ITransformEventData) {
|
|
30
|
+
super(type)
|
|
31
|
+
if (params) Object.assign(this, params)
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { IWatchEvent, IWatchEventData } from '@leafer/interface'
|
|
2
|
+
import { registerEvent } from '@leafer/decorator'
|
|
3
|
+
|
|
4
|
+
import { Event } from './Event'
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
@registerEvent()
|
|
8
|
+
export class WatchEvent extends Event implements IWatchEvent {
|
|
9
|
+
|
|
10
|
+
static REQUEST = 'watch.request'
|
|
11
|
+
static DATA = 'watch.data'
|
|
12
|
+
|
|
13
|
+
readonly data: IWatchEventData
|
|
14
|
+
|
|
15
|
+
constructor(type: string, data?: IWatchEventData) {
|
|
16
|
+
super(type)
|
|
17
|
+
this.data = data
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export { ChildEvent } from './ChildEvent'
|
|
2
|
+
export { AttrEvent } from './AttrEvent'
|
|
3
|
+
export { ResizeEvent } from './ResizeEvent'
|
|
4
|
+
export { TransformEvent } from './TransformEvent'
|
|
5
|
+
export { WatchEvent } from './WatchEvent'
|
|
6
|
+
export { LayoutEvent } from './LayoutEvent'
|
|
7
|
+
export { RenderEvent } from './RenderEvent'
|
|
8
|
+
|
|
9
|
+
export { Event } from './Event'
|
|
10
|
+
|