@leafer-ui/app 1.0.0-alpha.21 → 1.0.0-alpha.30
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 +5 -5
- package/src/App.ts +61 -39
- package/src/Leafer.ts +179 -146
- package/src/type/LeaferType.ts +36 -0
- package/src/type/design.ts +12 -0
- package/src/type/user.ts +8 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@leafer-ui/app",
|
|
3
|
-
"version": "1.0.0-alpha.
|
|
3
|
+
"version": "1.0.0-alpha.30",
|
|
4
4
|
"description": "@leafer-ui/app",
|
|
5
5
|
"author": "Chao (Leafer) Wan",
|
|
6
6
|
"license": "MIT",
|
|
@@ -19,11 +19,11 @@
|
|
|
19
19
|
"leaferjs"
|
|
20
20
|
],
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"@leafer/core": "1.0.0-alpha.
|
|
23
|
-
"@leafer-ui/display": "1.0.0-alpha.
|
|
22
|
+
"@leafer/core": "1.0.0-alpha.30",
|
|
23
|
+
"@leafer-ui/display": "1.0.0-alpha.30"
|
|
24
24
|
},
|
|
25
25
|
"devDependencies": {
|
|
26
|
-
"@leafer/interface": "1.0.0-alpha.
|
|
27
|
-
"@leafer-ui/interface": "1.0.0-alpha.
|
|
26
|
+
"@leafer/interface": "1.0.0-alpha.30",
|
|
27
|
+
"@leafer-ui/interface": "1.0.0-alpha.30"
|
|
28
28
|
}
|
|
29
29
|
}
|
package/src/App.ts
CHANGED
|
@@ -1,84 +1,106 @@
|
|
|
1
|
-
import { ILeaferConfig, IResizeEvent, ILeaferCanvas, IRenderOptions, IApp } from '@leafer/interface'
|
|
2
|
-
import { DataHelper, LayoutEvent, RenderEvent } from '@leafer/core'
|
|
1
|
+
import { ILeaferConfig, IResizeEvent, ILeaferCanvas, IRenderOptions, IApp, __Value } from '@leafer/interface'
|
|
2
|
+
import { DataHelper, Debug, LayoutEvent, PropertyEvent, RenderEvent, canvasSizeAttrs, registerUI } from '@leafer/core'
|
|
3
3
|
|
|
4
4
|
import { Leafer } from './Leafer'
|
|
5
5
|
|
|
6
6
|
|
|
7
|
+
@registerUI()
|
|
7
8
|
export class App extends Leafer implements IApp {
|
|
8
9
|
|
|
10
|
+
public get __tag() { return 'App' }
|
|
11
|
+
|
|
9
12
|
public get isApp(): boolean { return true }
|
|
10
13
|
|
|
11
14
|
public children: Leafer[] = []
|
|
12
15
|
|
|
13
|
-
|
|
14
|
-
|
|
16
|
+
public realCanvas: boolean
|
|
17
|
+
|
|
18
|
+
protected __setApp(): void {
|
|
19
|
+
const { canvas } = this
|
|
20
|
+
const { realCanvas, view } = this.config
|
|
21
|
+
if (realCanvas || view === this.canvas.view || !canvas.parentView) {
|
|
22
|
+
this.realCanvas = true
|
|
23
|
+
} else {
|
|
24
|
+
canvas.unrealCanvas()
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
this.leafer = this
|
|
28
|
+
this.watcher.disable()
|
|
29
|
+
this.layouter.disable()
|
|
30
|
+
|
|
31
|
+
this.__eventIds.push(
|
|
32
|
+
this.on__(PropertyEvent.CHANGE, () => {
|
|
33
|
+
if (Debug.showHitView) this.children.forEach(leafer => { leafer.forceUpdate('blendMode') })
|
|
34
|
+
})
|
|
35
|
+
)
|
|
15
36
|
}
|
|
16
37
|
|
|
17
38
|
public start(): void {
|
|
39
|
+
super.start()
|
|
18
40
|
this.children.forEach(leafer => { leafer.start() })
|
|
19
|
-
this.renderer.start()
|
|
20
|
-
this.running = true
|
|
21
41
|
}
|
|
22
42
|
|
|
23
43
|
public stop(): void {
|
|
24
44
|
this.children.forEach(leafer => { leafer.stop() })
|
|
25
|
-
|
|
26
|
-
this.running = false
|
|
45
|
+
super.stop()
|
|
27
46
|
}
|
|
28
47
|
|
|
29
48
|
public addLeafer(merge?: ILeaferConfig): Leafer {
|
|
30
|
-
const leafer = new Leafer(
|
|
49
|
+
const leafer = new Leafer(merge)
|
|
31
50
|
this.add(leafer)
|
|
51
|
+
return leafer
|
|
52
|
+
}
|
|
32
53
|
|
|
33
|
-
|
|
54
|
+
public add(leafer: Leafer): void {
|
|
55
|
+
if (!leafer.view) leafer.init(this.__getChildConfig(leafer.userConfig), this)
|
|
56
|
+
super.add(leafer)
|
|
34
57
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
this.on__(LayoutEvent.REQUEST, renderer.mergeBlocks, renderer),
|
|
39
|
-
)
|
|
58
|
+
leafer.once(LayoutEvent.END, () => {
|
|
59
|
+
if (!this.ready && this.children.every(child => child.ready)) this.__onReady()
|
|
60
|
+
})
|
|
40
61
|
|
|
41
|
-
|
|
42
|
-
|
|
62
|
+
leafer.once(RenderEvent.END, () => {
|
|
63
|
+
if (!this.viewReady && this.children.every(child => child.viewReady)) this.__onViewReady()
|
|
64
|
+
})
|
|
43
65
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
} else {
|
|
49
|
-
renderer.addBlock(renderer.canvas.bounds)
|
|
66
|
+
if (this.realCanvas) {
|
|
67
|
+
this.__eventIds.push(
|
|
68
|
+
leafer.on__(RenderEvent.END, this.__onChildRenderEnd, this),
|
|
69
|
+
)
|
|
50
70
|
}
|
|
51
71
|
}
|
|
52
72
|
|
|
73
|
+
protected __onChildRenderEnd(e: RenderEvent): void {
|
|
74
|
+
this.renderer.addBlock(e.renderBounds)
|
|
75
|
+
if (this.viewReady) this.renderer.update()
|
|
76
|
+
}
|
|
77
|
+
|
|
53
78
|
public __render(canvas: ILeaferCanvas, _options: IRenderOptions): void {
|
|
54
79
|
this.children.forEach(leafer => { canvas.copyWorld(leafer.canvas) })
|
|
55
80
|
}
|
|
56
81
|
|
|
57
82
|
public __onResize(event: IResizeEvent): void {
|
|
58
|
-
this.emitEvent(event)
|
|
59
83
|
this.children.forEach(leafer => { leafer.resize(event) })
|
|
84
|
+
super.__onResize(event)
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
protected __checkUpdateLayout(): void {
|
|
88
|
+
this.children.forEach(leafer => { leafer.__layout.checkUpdate() })
|
|
60
89
|
}
|
|
61
90
|
|
|
62
91
|
protected __getChildConfig(userConfig?: ILeaferConfig): ILeaferConfig {
|
|
63
|
-
let
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
userConfig.pixelRatio = this.pixelRatio
|
|
70
|
-
}
|
|
71
|
-
return userConfig
|
|
92
|
+
let config = { ...this.config }
|
|
93
|
+
if (userConfig) DataHelper.assign(config, userConfig)
|
|
94
|
+
config.view = this.realCanvas ? undefined : this.view
|
|
95
|
+
config.fill = config.hittable = config.realCanvas = undefined
|
|
96
|
+
if (this.autoLayout) DataHelper.copyAttrs(config, this, canvasSizeAttrs)
|
|
97
|
+
return config
|
|
72
98
|
}
|
|
73
99
|
|
|
74
100
|
public destory(): void {
|
|
101
|
+
this.children.forEach(leafer => { leafer.destory() })
|
|
102
|
+
this.children.length = 0
|
|
75
103
|
super.destory()
|
|
76
|
-
|
|
77
|
-
const { children } = this
|
|
78
|
-
if (children.length) {
|
|
79
|
-
children.forEach(leafer => leafer.destory())
|
|
80
|
-
children.length = 0
|
|
81
|
-
}
|
|
82
104
|
}
|
|
83
105
|
|
|
84
106
|
}
|
package/src/Leafer.ts
CHANGED
|
@@ -1,42 +1,38 @@
|
|
|
1
|
-
import { IApp, ILeafer, ILeaferCanvas, IRenderer, ILayouter,
|
|
2
|
-
import { AutoBounds, LayoutEvent, ResizeEvent,
|
|
1
|
+
import { IApp, ILeafer, ILeaferCanvas, IRenderer, ILayouter, ISelector, IWatcher, IInteraction, ILeaferConfig, ICanvasManager, IHitCanvasManager, IImageManager, IAutoBounds, IScreenSizeData, IResizeEvent, ILeaf, IEventListenerId, ITransformEventData, ITimer, __Value, IObject, IControl } from '@leafer/interface'
|
|
2
|
+
import { AutoBounds, LayoutEvent, ResizeEvent, LeaferEvent, CanvasManager, HitCanvasManager, ImageManager, DataHelper, Creator, Run, Debug, RenderEvent, registerUI, boundsType, canvasSizeAttrs, dataProcessor } from '@leafer/core'
|
|
3
3
|
|
|
4
|
+
import { ILeaferInputData, ILeaferData } from '@leafer-ui/interface'
|
|
5
|
+
import { LeaferData } from '@leafer-ui/data'
|
|
4
6
|
import { Group } from '@leafer-ui/display'
|
|
5
7
|
|
|
6
8
|
import { App } from './App'
|
|
9
|
+
import { LeaferType } from './type/LeaferType'
|
|
7
10
|
|
|
8
11
|
|
|
12
|
+
const debug = Debug.get('Leafer')
|
|
13
|
+
|
|
14
|
+
@registerUI()
|
|
9
15
|
export class Leafer extends Group implements ILeafer {
|
|
10
16
|
|
|
11
|
-
public
|
|
17
|
+
public get __tag() { return 'Leafer' }
|
|
18
|
+
|
|
19
|
+
@dataProcessor(LeaferData)
|
|
20
|
+
public __: ILeaferData
|
|
21
|
+
|
|
22
|
+
@boundsType()
|
|
23
|
+
public pixelRatio: number
|
|
12
24
|
|
|
13
25
|
public get isApp(): boolean { return false }
|
|
14
26
|
|
|
15
27
|
public parent?: App
|
|
16
28
|
|
|
17
29
|
public running: boolean
|
|
30
|
+
public ready: boolean
|
|
31
|
+
public viewReady: boolean
|
|
18
32
|
|
|
19
|
-
|
|
20
|
-
public width: number
|
|
21
|
-
|
|
22
|
-
@resizeType()
|
|
23
|
-
public height: number
|
|
24
|
-
|
|
25
|
-
@resizeType()
|
|
26
|
-
public pixelRatio: number
|
|
27
|
-
|
|
28
|
-
public config: ILeaferConfig = {
|
|
29
|
-
useZoom: true,
|
|
30
|
-
useMove: true,
|
|
31
|
-
autoStart: true,
|
|
32
|
-
hittable: true,
|
|
33
|
-
pixelRatio: devicePixelRatio
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
public autoLayout?: IAutoBounds
|
|
33
|
+
public view: unknown
|
|
37
34
|
|
|
38
35
|
// manager
|
|
39
|
-
|
|
40
36
|
public canvas: ILeaferCanvas
|
|
41
37
|
public renderer: IRenderer
|
|
42
38
|
|
|
@@ -50,78 +46,128 @@ export class Leafer extends Group implements ILeafer {
|
|
|
50
46
|
public hitCanvasManager?: IHitCanvasManager
|
|
51
47
|
public imageManager: IImageManager
|
|
52
48
|
|
|
53
|
-
public zoomLayer
|
|
54
|
-
public moveLayer
|
|
49
|
+
public zoomLayer: ILeaf = this
|
|
50
|
+
public moveLayer: ILeaf = this
|
|
55
51
|
public transformData?: ITransformEventData
|
|
56
52
|
|
|
57
|
-
|
|
53
|
+
public userConfig: ILeaferConfig
|
|
54
|
+
public config: ILeaferConfig = { type: 'design', start: true, hittable: true }
|
|
58
55
|
|
|
59
|
-
|
|
60
|
-
|
|
56
|
+
public autoLayout?: IAutoBounds
|
|
57
|
+
|
|
58
|
+
public __eventIds: IEventListenerId[] = []
|
|
59
|
+
protected __startTimer: ITimer
|
|
60
|
+
protected __controllers: IControl[] = []
|
|
61
|
+
|
|
62
|
+
constructor(userConfig?: ILeaferConfig, data?: ILeaferInputData) {
|
|
63
|
+
super(data)
|
|
64
|
+
this.userConfig = userConfig
|
|
65
|
+
if (userConfig?.view) this.init(userConfig)
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
public init(userConfig?: ILeaferConfig, parentApp?: IApp): void {
|
|
69
|
+
if (this.canvas) return
|
|
61
70
|
|
|
62
|
-
this.
|
|
63
|
-
this.
|
|
71
|
+
this.__setLeafer(this)
|
|
72
|
+
if (userConfig) DataHelper.assign(this.config, userConfig)
|
|
64
73
|
|
|
74
|
+
let start: boolean
|
|
65
75
|
const { config } = this
|
|
66
|
-
|
|
67
|
-
this.hittable = config.hittable
|
|
76
|
+
LeaferType.run(config.type, this)
|
|
68
77
|
|
|
69
|
-
// render
|
|
78
|
+
// render / layout
|
|
70
79
|
this.canvas = Creator.canvas(config)
|
|
71
|
-
this.
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
} else {
|
|
77
|
-
this.watcher = Creator.watcher(this)
|
|
78
|
-
this.layouter = Creator.layouter(this)
|
|
79
|
-
}
|
|
80
|
+
this.__controllers.push(
|
|
81
|
+
this.renderer = Creator.renderer(this, this.canvas, config),
|
|
82
|
+
this.watcher = Creator.watcher(this, config),
|
|
83
|
+
this.layouter = Creator.layouter(this, config)
|
|
84
|
+
)
|
|
80
85
|
|
|
86
|
+
if (this.isApp) this.__setApp()
|
|
81
87
|
this.__checkAutoLayout(config)
|
|
88
|
+
this.view = this.canvas.view
|
|
82
89
|
|
|
83
90
|
// interaction / manager
|
|
84
|
-
if (
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
this.selector = app.selector
|
|
89
|
-
if (config.hittable) this.interaction = app.interaction
|
|
90
|
-
|
|
91
|
-
this.canvasManager = app.canvasManager
|
|
92
|
-
this.hitCanvasManager = app.hitCanvasManager
|
|
93
|
-
this.imageManager = app.imageManager
|
|
94
|
-
|
|
95
|
-
if (app.running) setTimeout(this.start.bind(this))
|
|
96
|
-
|
|
91
|
+
if (parentApp) {
|
|
92
|
+
this.__bindApp(parentApp)
|
|
93
|
+
start = parentApp.running
|
|
97
94
|
} else {
|
|
98
|
-
|
|
99
95
|
this.selector = Creator.selector(this)
|
|
100
|
-
|
|
96
|
+
this.__controllers.unshift(this.interaction = Creator.interaction(this, this.canvas, this.selector, config))
|
|
101
97
|
|
|
102
|
-
this.canvasManager = new CanvasManager(
|
|
103
|
-
this.hitCanvasManager = new HitCanvasManager(
|
|
98
|
+
this.canvasManager = new CanvasManager()
|
|
99
|
+
this.hitCanvasManager = new HitCanvasManager()
|
|
104
100
|
this.imageManager = new ImageManager(this, config)
|
|
105
|
-
Run.start('FullCreate')
|
|
106
|
-
if (config.autoStart) setTimeout(this.start.bind(this))
|
|
107
101
|
|
|
102
|
+
start = config.start
|
|
108
103
|
}
|
|
109
104
|
|
|
105
|
+
this.hittable = config.hittable
|
|
106
|
+
this.fill = config.fill
|
|
110
107
|
this.canvasManager.add(this.canvas)
|
|
108
|
+
|
|
111
109
|
this.__listenEvents()
|
|
112
110
|
|
|
111
|
+
if (start) this.__startTimer = setTimeout(this.start.bind(this))
|
|
113
112
|
}
|
|
114
113
|
|
|
115
|
-
|
|
116
|
-
|
|
114
|
+
public start(): void {
|
|
115
|
+
clearTimeout(this.__startTimer)
|
|
116
|
+
if (!this.running && this.canvas) {
|
|
117
|
+
this.ready ? this.emitLeafer(LeaferEvent.RESTART) : this.emitLeafer(LeaferEvent.START)
|
|
118
|
+
this.__controllers.forEach(item => item.start())
|
|
119
|
+
if (!this.isApp) this.renderer.render()
|
|
120
|
+
this.running = true
|
|
121
|
+
}
|
|
117
122
|
}
|
|
118
123
|
|
|
119
|
-
|
|
120
|
-
|
|
124
|
+
public stop(): void {
|
|
125
|
+
clearTimeout(this.__startTimer)
|
|
126
|
+
if (this.running && this.canvas) {
|
|
127
|
+
this.__controllers.forEach(item => item.stop())
|
|
128
|
+
this.running = false
|
|
129
|
+
this.emitLeafer(LeaferEvent.STOP)
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
public resize(size: IScreenSizeData): void {
|
|
134
|
+
const data = DataHelper.copyAttrs({}, size, canvasSizeAttrs)
|
|
135
|
+
Object.keys(data).forEach(key => (this as any)[key] = data[key])
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
public forceFullRender(): void {
|
|
139
|
+
this.renderer.addBlock(this.canvas.bounds)
|
|
140
|
+
if (this.viewReady) this.renderer.update()
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
protected __doResize(size: IScreenSizeData): void {
|
|
144
|
+
if (!this.canvas || this.canvas.isSameSize(size)) return
|
|
145
|
+
const old = DataHelper.copyAttrs({}, this.canvas, canvasSizeAttrs) as IScreenSizeData
|
|
146
|
+
this.canvas.resize(size)
|
|
147
|
+
this.__onResize(new ResizeEvent(size, old))
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
protected __onResize(event: IResizeEvent): void {
|
|
151
|
+
this.emitEvent(event)
|
|
152
|
+
DataHelper.copyAttrs(this.__, event, canvasSizeAttrs)
|
|
153
|
+
setTimeout(() => { if (this.canvasManager) this.canvasManager.clearRecycled() }, 0)
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
protected __setApp(): void { }
|
|
157
|
+
|
|
158
|
+
protected __bindApp(app: IApp): void {
|
|
159
|
+
this.selector = app.selector
|
|
160
|
+
this.interaction = app.interaction
|
|
161
|
+
|
|
162
|
+
this.canvasManager = app.canvasManager
|
|
163
|
+
this.hitCanvasManager = app.hitCanvasManager
|
|
164
|
+
this.imageManager = app.imageManager
|
|
121
165
|
}
|
|
122
166
|
|
|
123
|
-
|
|
124
|
-
|
|
167
|
+
public __setLeafer(leafer: ILeafer): void {
|
|
168
|
+
this.leafer = leafer
|
|
169
|
+
this.isLeafer = !!leafer
|
|
170
|
+
this.__level = 1
|
|
125
171
|
}
|
|
126
172
|
|
|
127
173
|
protected __checkAutoLayout(config: ILeaferConfig): void {
|
|
@@ -131,111 +177,98 @@ export class Leafer extends Group implements ILeafer {
|
|
|
131
177
|
}
|
|
132
178
|
}
|
|
133
179
|
|
|
134
|
-
public
|
|
135
|
-
if (
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
this.
|
|
180
|
+
public __setAttr(attrName: string, newValue: __Value): void {
|
|
181
|
+
if (this.canvas) {
|
|
182
|
+
if (canvasSizeAttrs.includes(attrName)) {
|
|
183
|
+
this.__changeCanvasSize(attrName, newValue as number)
|
|
184
|
+
} else if (attrName === 'fill') {
|
|
185
|
+
this.__changeFill(newValue as string)
|
|
186
|
+
} else if (attrName === 'hittable') {
|
|
187
|
+
this.canvas.setHittable(newValue as boolean)
|
|
140
188
|
}
|
|
141
|
-
this.renderer.start()
|
|
142
|
-
this.layouter.start()
|
|
143
|
-
this.watcher.start()
|
|
144
|
-
this.running = true
|
|
145
189
|
}
|
|
190
|
+
super.__setAttr(attrName, newValue)
|
|
146
191
|
}
|
|
147
192
|
|
|
148
|
-
public
|
|
149
|
-
if (this.
|
|
150
|
-
|
|
151
|
-
this.watcher.stop()
|
|
152
|
-
this.layouter.stop()
|
|
153
|
-
this.renderer.stop()
|
|
154
|
-
this.running = false
|
|
155
|
-
}
|
|
193
|
+
public __getAttr(attrName: string): __Value {
|
|
194
|
+
if (this.canvas && canvasSizeAttrs.includes(attrName)) return this.canvas[attrName]
|
|
195
|
+
return super.__getAttr(attrName)
|
|
156
196
|
}
|
|
157
197
|
|
|
158
|
-
protected
|
|
159
|
-
const
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
198
|
+
protected __changeCanvasSize(attrName: string, newValue: number): void {
|
|
199
|
+
const data = DataHelper.copyAttrs({}, this.canvas, canvasSizeAttrs)
|
|
200
|
+
data[attrName] = (this.config as IObject)[attrName] = newValue
|
|
201
|
+
if (newValue) this.canvas.stopAutoLayout()
|
|
202
|
+
this.__doResize(data as IScreenSizeData)
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
protected __changeFill(newValue: string): void {
|
|
206
|
+
this.config.fill = newValue as string
|
|
207
|
+
if (this.canvas.allowBackgroundColor) {
|
|
208
|
+
this.canvas.setBackgroundColor(newValue as string)
|
|
209
|
+
} else {
|
|
210
|
+
this.forceFullRender()
|
|
165
211
|
}
|
|
166
212
|
}
|
|
167
213
|
|
|
168
|
-
|
|
169
|
-
if (this.
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
this.
|
|
173
|
-
this.
|
|
214
|
+
protected __onReady(): void {
|
|
215
|
+
if (this.ready) return
|
|
216
|
+
this.ready = true
|
|
217
|
+
this.emitLeafer(LeaferEvent.BEFORE_READY)
|
|
218
|
+
this.emitLeafer(LeaferEvent.READY)
|
|
219
|
+
this.emitLeafer(LeaferEvent.AFTER_READY)
|
|
174
220
|
}
|
|
175
221
|
|
|
176
|
-
protected
|
|
177
|
-
this.
|
|
178
|
-
|
|
222
|
+
protected __onViewReady(): void {
|
|
223
|
+
if (this.viewReady) return
|
|
224
|
+
this.viewReady = true
|
|
225
|
+
this.emitLeafer(LeaferEvent.VIEW_READY)
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
protected __checkUpdateLayout(): void {
|
|
229
|
+
this.__layout.checkUpdate()
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
protected emitLeafer(type: string): void {
|
|
233
|
+
this.emitEvent(new LeaferEvent(type, this))
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
protected __listenEvents(): void {
|
|
237
|
+
const runId = Run.start('FirstCreate ' + this.innerName)
|
|
238
|
+
this.once(LeaferEvent.START, () => Run.end(runId))
|
|
239
|
+
this.once(LayoutEvent.END, () => this.__onReady())
|
|
240
|
+
this.once(RenderEvent.END, () => this.__onViewReady())
|
|
241
|
+
this.on(LayoutEvent.CHECK_UPDATE, () => this.__checkUpdateLayout())
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
protected __removeListenEvents(): void {
|
|
245
|
+
this.off__(this.__eventIds)
|
|
179
246
|
}
|
|
180
247
|
|
|
181
248
|
public destory(): void {
|
|
182
249
|
if (this.canvas) {
|
|
183
|
-
|
|
250
|
+
try {
|
|
251
|
+
this.stop()
|
|
252
|
+
this.emitEvent(new LeaferEvent(LeaferEvent.END, this))
|
|
253
|
+
this.__removeListenEvents()
|
|
184
254
|
|
|
185
|
-
|
|
255
|
+
this.__controllers.forEach(item => item.destroy())
|
|
256
|
+
this.__controllers.length = 0
|
|
186
257
|
|
|
187
|
-
if (!this.parent) {
|
|
188
|
-
this.interaction?.destroy()
|
|
189
258
|
this.selector.destroy()
|
|
190
|
-
|
|
191
|
-
this.renderer.destroy()
|
|
192
|
-
this.watcher.destroy()
|
|
193
|
-
this.layouter.destroy()
|
|
194
|
-
|
|
195
259
|
this.canvasManager.destory()
|
|
196
260
|
this.hitCanvasManager.destory()
|
|
197
261
|
this.imageManager.destory()
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
this.canvas.destroy()
|
|
201
|
-
this.canvas = null
|
|
202
|
-
|
|
203
|
-
this.creator = null
|
|
204
|
-
this.config = null
|
|
205
|
-
|
|
206
|
-
this.interaction = null
|
|
207
|
-
this.selector = null
|
|
208
|
-
|
|
209
262
|
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
this.layouter = null
|
|
263
|
+
this.canvas.destroy()
|
|
264
|
+
this.canvas = null
|
|
213
265
|
|
|
214
|
-
|
|
215
|
-
this.hitCanvasManager = null
|
|
216
|
-
this.imageManager = null
|
|
217
|
-
|
|
218
|
-
this.zoomLayer = null
|
|
219
|
-
this.moveLayer = undefined
|
|
220
|
-
|
|
221
|
-
this.parent = undefined
|
|
222
|
-
}
|
|
223
|
-
}
|
|
224
|
-
}
|
|
266
|
+
this.config = this.userConfig = this.view = null
|
|
225
267
|
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
get() {
|
|
230
|
-
return (this.canvas as IObject)[key]
|
|
231
|
-
},
|
|
232
|
-
set(value: number) {
|
|
233
|
-
const { width, height, pixelRatio } = this.canvas
|
|
234
|
-
const data = { width, height, pixelRatio } as IObject
|
|
235
|
-
data[key] = value
|
|
236
|
-
this.resize(data as IScreenSizeData)
|
|
268
|
+
super.destroy()
|
|
269
|
+
} catch (e) {
|
|
270
|
+
debug.error(e)
|
|
237
271
|
}
|
|
238
272
|
}
|
|
239
|
-
Object.defineProperty(target, key, property)
|
|
240
273
|
}
|
|
241
274
|
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { ILeafer, ILeaferTypeList, ILeaferTypeFunction } from '@leafer/interface'
|
|
2
|
+
|
|
3
|
+
import { Debug } from '@leafer/debug'
|
|
4
|
+
|
|
5
|
+
import { user } from './user'
|
|
6
|
+
import { design } from './design'
|
|
7
|
+
|
|
8
|
+
const debug = Debug.get('LeaferType')
|
|
9
|
+
|
|
10
|
+
export const LeaferType = {
|
|
11
|
+
|
|
12
|
+
list: {} as ILeaferTypeList,
|
|
13
|
+
|
|
14
|
+
register(name: string, fn: ILeaferTypeFunction): void {
|
|
15
|
+
if (list[name]) {
|
|
16
|
+
debug.error('repeat:', name)
|
|
17
|
+
} else {
|
|
18
|
+
list[name] = fn
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
|
|
22
|
+
run(name: string, leafer: ILeafer): void {
|
|
23
|
+
const fn = LeaferType.list[name]
|
|
24
|
+
if (fn) {
|
|
25
|
+
fn(leafer)
|
|
26
|
+
} else {
|
|
27
|
+
debug.error('no', name)
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const { list } = LeaferType
|
|
34
|
+
|
|
35
|
+
LeaferType.register('user', user)
|
|
36
|
+
LeaferType.register('design', design)
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { MoveEvent, ZoomEvent, LeafHelper } from '@leafer/core'
|
|
2
|
+
import { ILeafer } from '@leafer/interface'
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
export function design(leafer: ILeafer): void {
|
|
6
|
+
const { MOVE } = MoveEvent
|
|
7
|
+
const { ZOOM } = ZoomEvent
|
|
8
|
+
leafer.__eventIds.push(
|
|
9
|
+
leafer.on__(MOVE, (e: MoveEvent) => { LeafHelper.move(leafer.moveLayer, e.moveX, e.moveY) }),
|
|
10
|
+
leafer.on__(ZOOM, (e: ZoomEvent) => { LeafHelper.zoomOf(leafer.zoomLayer, e, e.scale) })
|
|
11
|
+
)
|
|
12
|
+
}
|