@leafer/event 1.0.0-beta.15 → 1.0.0-beta.17

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/package.json CHANGED
@@ -1,12 +1,13 @@
1
1
  {
2
2
  "name": "@leafer/event",
3
- "version": "1.0.0-beta.15",
3
+ "version": "1.0.0-beta.17",
4
4
  "description": "@leafer/event",
5
5
  "author": "Chao (Leafer) Wan",
6
6
  "license": "MIT",
7
7
  "main": "src/index.ts",
8
8
  "types": "types/index.d.ts",
9
9
  "files": [
10
+ "src",
10
11
  "types",
11
12
  "dist"
12
13
  ],
@@ -21,9 +22,9 @@
21
22
  "leaferjs"
22
23
  ],
23
24
  "dependencies": {
24
- "@leafer/decorator": "1.0.0-beta.15"
25
+ "@leafer/decorator": "1.0.0-beta.17"
25
26
  },
26
27
  "devDependencies": {
27
- "@leafer/interface": "1.0.0-beta.15"
28
+ "@leafer/interface": "1.0.0-beta.17"
28
29
  }
29
30
  }
@@ -0,0 +1,10 @@
1
+ import { IAnimateEvent } from '@leafer/interface'
2
+
3
+ import { Event } from './Event'
4
+
5
+
6
+ export class AnimateEvent extends Event implements IAnimateEvent {
7
+
8
+ static FRAME = 'animate.frame'
9
+
10
+ }
@@ -0,0 +1,20 @@
1
+ import { IChildEvent, ILeaf } from '@leafer/interface'
2
+
3
+ import { Event } from './Event'
4
+
5
+
6
+ export class ChildEvent extends Event implements IChildEvent {
7
+
8
+ static ADD = 'child.add'
9
+ static REMOVE = 'child.remove'
10
+
11
+ readonly parent?: ILeaf
12
+ readonly child?: ILeaf
13
+
14
+ constructor(type: string, child?: ILeaf, parent?: ILeaf) {
15
+ super(type, child)
16
+ this.parent = parent
17
+ this.child = child
18
+ }
19
+
20
+ }
package/src/Event.ts ADDED
@@ -0,0 +1,34 @@
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
+ }
@@ -0,0 +1,22 @@
1
+ import { IImageEvent, IObject, ILeaferImage } from '@leafer/interface'
2
+
3
+ import { Event } from './Event'
4
+
5
+ export class ImageEvent extends Event implements IImageEvent {
6
+
7
+ static LOAD = 'image.load'
8
+ static LOADED = 'image.loaded'
9
+ static ERROR = 'image.error'
10
+
11
+ readonly image: ILeaferImage
12
+ readonly error: string | IObject
13
+
14
+ readonly attrName: string
15
+ readonly attrValue: IObject
16
+
17
+ constructor(type: string, data: IImageEvent) {
18
+ super(type)
19
+ Object.assign(this, data)
20
+ }
21
+
22
+ }
@@ -0,0 +1,34 @@
1
+ import { ILayoutEvent, ILayoutBlockData } from '@leafer/interface'
2
+
3
+ import { Event } from './Event'
4
+
5
+
6
+ export class LayoutEvent extends Event implements ILayoutEvent {
7
+
8
+ static CHECK_UPDATE = 'layout.check_update'
9
+
10
+ static REQUEST = 'layout.request'
11
+
12
+ static START = 'layout.start'
13
+
14
+ static BEFORE = 'layout.before'
15
+ static LAYOUT = 'layout.layout'
16
+ static AFTER = 'layout.after'
17
+
18
+ static AGAIN = 'layout.again'
19
+
20
+ static END = 'layout.end'
21
+
22
+ readonly data: ILayoutBlockData[]
23
+ readonly times: number
24
+
25
+ constructor(type: string, data?: ILayoutBlockData[], times?: number) {
26
+ super(type)
27
+ if (data) {
28
+ this.data = data
29
+ this.times = times
30
+ }
31
+
32
+ }
33
+
34
+ }
@@ -0,0 +1,24 @@
1
+ import { ILeaferEvent } from '@leafer/interface'
2
+
3
+ import { Event } from './Event'
4
+
5
+
6
+ export class LeaferEvent extends Event implements ILeaferEvent {
7
+
8
+ static START = 'leafer.start'
9
+
10
+ static BEFORE_READY = 'leafer.before_ready'
11
+ static READY = 'leafer.ready'
12
+ static AFTER_READY = 'leafer.after_ready'
13
+
14
+ static VIEW_READY = 'leafer.view_ready'
15
+
16
+ static VIEW_COMPLETED = 'leafer.view_completed'
17
+
18
+ static STOP = 'leafer.stop'
19
+ static RESTART = 'leafer.restart'
20
+
21
+ static END = 'leafer.end'
22
+
23
+
24
+ }
@@ -0,0 +1,21 @@
1
+ import { IPropertyEvent, IEventTarget } from '@leafer/interface'
2
+
3
+ import { Event } from './Event'
4
+
5
+
6
+ export class PropertyEvent extends Event implements IPropertyEvent {
7
+
8
+ static CHANGE = 'property.change'
9
+
10
+ readonly attrName: string
11
+ readonly oldValue: unknown
12
+ readonly newValue: unknown
13
+
14
+ constructor(type: string, target: IEventTarget, attrName: string, oldValue: unknown, newValue: unknown) {
15
+ super(type, target)
16
+ this.attrName = attrName
17
+ this.oldValue = oldValue
18
+ this.newValue = newValue
19
+ }
20
+
21
+ }
@@ -0,0 +1,33 @@
1
+ import { IBounds, IRenderEvent, IRenderOptions } from '@leafer/interface'
2
+
3
+ import { Event } from './Event'
4
+
5
+
6
+ export class RenderEvent extends Event implements IRenderEvent {
7
+
8
+ static REQUEST = 'render.request'
9
+
10
+ static START = 'render.start'
11
+
12
+ static BEFORE = 'render.before'
13
+ static RENDER = 'render'
14
+ static AFTER = 'render.after'
15
+
16
+ static AGAIN = 'render.again'
17
+
18
+ static END = 'render.end'
19
+
20
+ readonly renderBounds: IBounds
21
+ readonly renderOptions: IRenderOptions
22
+ readonly times: number
23
+
24
+ constructor(type: string, times?: number, bounds?: IBounds, options?: IRenderOptions) {
25
+ super(type)
26
+ if (times) this.times = times
27
+ if (bounds) {
28
+ this.renderBounds = bounds
29
+ this.renderOptions = options
30
+ }
31
+ }
32
+
33
+ }
@@ -0,0 +1,41 @@
1
+ import { IResizeEvent, IScreenSizeData } from '@leafer/interface'
2
+
3
+ import { Event } from './Event'
4
+
5
+
6
+ export class ResizeEvent extends Event implements IResizeEvent {
7
+
8
+ static RESIZE: string = 'resize'
9
+
10
+ readonly width: number
11
+ readonly height: number
12
+ readonly pixelRatio: number
13
+
14
+ public get bigger(): boolean {
15
+ if (!this.old) return true
16
+ const { width, height } = this.old
17
+ return this.width >= width && this.height >= height
18
+ }
19
+
20
+ public get smaller(): boolean {
21
+ return !this.bigger
22
+ }
23
+
24
+ public get samePixelRatio(): boolean {
25
+ if (!this.old) return true
26
+ return this.pixelRatio === this.old.pixelRatio
27
+ }
28
+
29
+ readonly old: IScreenSizeData
30
+
31
+ constructor(size: IScreenSizeData | string, oldSize?: IScreenSizeData) {
32
+ if (typeof size === 'object') {
33
+ super(ResizeEvent.RESIZE)
34
+ Object.assign(this, size)
35
+ } else {
36
+ super(size)
37
+ }
38
+ this.old = oldSize
39
+ }
40
+
41
+ }
@@ -0,0 +1,32 @@
1
+ import { ITransformEvent, ITransformEventData } from '@leafer/interface'
2
+
3
+ import { Event } from './Event'
4
+
5
+
6
+ export class TransformEvent extends Event implements ITransformEvent {
7
+
8
+ static START = 'transform.start'
9
+ static CHANGE = 'transform.change'
10
+ static END = 'transform.end'
11
+
12
+ static BEFORE_START = 'transform.before_start'
13
+ static BEFORE_CHANGE = 'transform.before_change'
14
+ static BEFORE_END = 'transform.before_end'
15
+
16
+ readonly x: number
17
+ readonly y: number
18
+ readonly scaleX: number
19
+ readonly scaleY: number
20
+ readonly rotation: number
21
+
22
+ readonly zooming: boolean
23
+ readonly moving: boolean
24
+ readonly rotating: boolean
25
+ readonly changing: boolean
26
+
27
+ constructor(type: string, params?: ITransformEventData) {
28
+ super(type)
29
+ if (params) Object.assign(this, params)
30
+ }
31
+
32
+ }
@@ -0,0 +1,18 @@
1
+ import { IWatchEvent, IWatchEventData } from '@leafer/interface'
2
+
3
+ import { Event } from './Event'
4
+
5
+
6
+ export class WatchEvent extends Event implements IWatchEvent {
7
+
8
+ static REQUEST = 'watch.request'
9
+ static DATA = 'watch.data'
10
+
11
+ readonly data: IWatchEventData
12
+
13
+ constructor(type: string, data?: IWatchEventData) {
14
+ super(type)
15
+ this.data = data
16
+ }
17
+
18
+ }