@leafer-ui/app 1.0.0-beta.9 → 1.0.0-rc.11
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 +11 -8
- package/src/App.ts +74 -35
- package/src/index.ts +0 -1
- package/types/index.d.ts +36 -0
- package/src/Leafer.ts +0 -312
package/package.json
CHANGED
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@leafer-ui/app",
|
|
3
|
-
"version": "1.0.0-
|
|
3
|
+
"version": "1.0.0-rc.11",
|
|
4
4
|
"description": "@leafer-ui/app",
|
|
5
5
|
"author": "Chao (Leafer) Wan",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"main": "src/index.ts",
|
|
8
|
+
"types": "types/index.d.ts",
|
|
8
9
|
"files": [
|
|
9
|
-
"src"
|
|
10
|
+
"src",
|
|
11
|
+
"types",
|
|
12
|
+
"dist"
|
|
10
13
|
],
|
|
11
14
|
"repository": {
|
|
12
15
|
"type": "git",
|
|
@@ -19,13 +22,13 @@
|
|
|
19
22
|
"leaferjs"
|
|
20
23
|
],
|
|
21
24
|
"dependencies": {
|
|
22
|
-
"@leafer/core": "1.0.0-
|
|
23
|
-
"@leafer-ui/display": "1.0.0-
|
|
24
|
-
"@leafer-ui/type": "1.0.0-
|
|
25
|
-
"@leafer-ui/data": "1.0.0-
|
|
25
|
+
"@leafer/core": "1.0.0-rc.11",
|
|
26
|
+
"@leafer-ui/display": "1.0.0-rc.11",
|
|
27
|
+
"@leafer-ui/type": "1.0.0-rc.11",
|
|
28
|
+
"@leafer-ui/data": "1.0.0-rc.11"
|
|
26
29
|
},
|
|
27
30
|
"devDependencies": {
|
|
28
|
-
"@leafer/interface": "1.0.0-
|
|
29
|
-
"@leafer-ui/interface": "1.0.0-
|
|
31
|
+
"@leafer/interface": "1.0.0-rc.11",
|
|
32
|
+
"@leafer-ui/interface": "1.0.0-rc.11"
|
|
30
33
|
}
|
|
31
34
|
}
|
package/src/App.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
import { ILeaferConfig, IResizeEvent, ILeaferCanvas, IRenderOptions,
|
|
2
|
-
import { DataHelper, Debug, LayoutEvent,
|
|
1
|
+
import { ILeaferConfig, IResizeEvent, ILeaferCanvas, IRenderOptions, ILeaferBase, IBoundsData } from '@leafer/interface'
|
|
2
|
+
import { Creator, DataHelper, Debug, LayoutEvent, PropertyEvent, RenderEvent, canvasSizeAttrs, registerUI } from '@leafer/core'
|
|
3
3
|
|
|
4
|
-
import {
|
|
4
|
+
import { IApp, IAppConfig, IAppInputData, IEditorBase, ILeafer } from '@leafer-ui/interface'
|
|
5
|
+
|
|
6
|
+
import { Leafer } from '@leafer-ui/draw'
|
|
5
7
|
|
|
6
8
|
|
|
7
9
|
@registerUI()
|
|
@@ -11,10 +13,32 @@ export class App extends Leafer implements IApp {
|
|
|
11
13
|
|
|
12
14
|
public get isApp(): boolean { return true }
|
|
13
15
|
|
|
14
|
-
public children:
|
|
16
|
+
declare public children: ILeafer[]
|
|
15
17
|
|
|
16
18
|
public realCanvas: boolean
|
|
17
19
|
|
|
20
|
+
public ground: ILeafer
|
|
21
|
+
public tree: ILeafer
|
|
22
|
+
public sky: ILeafer
|
|
23
|
+
|
|
24
|
+
constructor(userConfig?: IAppConfig, data?: IAppInputData) {
|
|
25
|
+
super(userConfig, data)
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
public init(userConfig?: IAppConfig, parentApp?: IApp): void {
|
|
29
|
+
super.init(userConfig, parentApp)
|
|
30
|
+
if (userConfig) {
|
|
31
|
+
const { ground, tree, sky, editor } = userConfig
|
|
32
|
+
if (ground) this.ground = this.addLeafer(ground)
|
|
33
|
+
if (tree || editor) this.tree = this.addLeafer(tree)
|
|
34
|
+
if (sky || editor) this.sky = this.addLeafer(sky || { type: 'draw', usePartRender: false })
|
|
35
|
+
if (editor) {
|
|
36
|
+
this.editor = Creator.editor(editor) as IEditorBase
|
|
37
|
+
this.sky.add(this.editor)
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
18
42
|
protected __setApp(): void {
|
|
19
43
|
const { canvas } = this
|
|
20
44
|
const { realCanvas, view } = this.config
|
|
@@ -28,52 +52,66 @@ export class App extends Leafer implements IApp {
|
|
|
28
52
|
this.watcher.disable()
|
|
29
53
|
this.layouter.disable()
|
|
30
54
|
|
|
31
|
-
this.__eventIds.push(
|
|
32
|
-
this.on_(PropertyEvent.CHANGE, () => {
|
|
33
|
-
if (Debug.showHitView) this.children.forEach(leafer => { leafer.forceUpdate('blendMode') })
|
|
34
|
-
})
|
|
35
|
-
)
|
|
55
|
+
this.__eventIds.push(this.on_(PropertyEvent.CHANGE, this.__onPropertyChange, this))
|
|
36
56
|
}
|
|
37
57
|
|
|
38
58
|
public start(): void {
|
|
39
59
|
super.start()
|
|
40
|
-
this.children.forEach(leafer =>
|
|
60
|
+
this.children.forEach(leafer => leafer.start())
|
|
41
61
|
}
|
|
42
62
|
|
|
43
63
|
public stop(): void {
|
|
44
|
-
this.children.forEach(leafer =>
|
|
64
|
+
this.children.forEach(leafer => leafer.stop())
|
|
45
65
|
super.stop()
|
|
46
66
|
}
|
|
47
67
|
|
|
68
|
+
public unlockLayout(): void {
|
|
69
|
+
super.unlockLayout()
|
|
70
|
+
this.children.forEach(leafer => leafer.unlockLayout())
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
public lockLayout(): void {
|
|
74
|
+
super.lockLayout()
|
|
75
|
+
this.children.forEach(leafer => leafer.lockLayout())
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
public forceRender(bounds?: IBoundsData): void {
|
|
79
|
+
this.children.forEach(leafer => leafer.forceRender(bounds))
|
|
80
|
+
}
|
|
81
|
+
|
|
48
82
|
public addLeafer(merge?: ILeaferConfig): Leafer {
|
|
49
83
|
const leafer = new Leafer(merge)
|
|
50
84
|
this.add(leafer)
|
|
51
85
|
return leafer
|
|
52
86
|
}
|
|
53
87
|
|
|
54
|
-
public add(leafer:
|
|
55
|
-
if (!leafer.view)
|
|
88
|
+
public add(leafer: ILeafer): void {
|
|
89
|
+
if (!leafer.view) {
|
|
90
|
+
if (this.realCanvas && !this.canvas.bounds) { // wait miniapp select canvas
|
|
91
|
+
setTimeout(() => this.add(leafer), 10)
|
|
92
|
+
return
|
|
93
|
+
}
|
|
94
|
+
leafer.init(this.__getChildConfig(leafer.userConfig), this)
|
|
95
|
+
}
|
|
96
|
+
|
|
56
97
|
super.add(leafer)
|
|
98
|
+
this.__listenChildEvents(leafer)
|
|
99
|
+
}
|
|
57
100
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
101
|
+
protected __onPropertyChange(): void {
|
|
102
|
+
if (Debug.showHitView) this.children.forEach(leafer => leafer.forceUpdate('surface'))
|
|
103
|
+
}
|
|
61
104
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
105
|
+
protected __onCreated(): void {
|
|
106
|
+
this.created = this.children.every(child => child.created)
|
|
107
|
+
}
|
|
65
108
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
leafer.on_(RenderEvent.END, this.__onChildRenderEnd, this),
|
|
69
|
-
)
|
|
70
|
-
}
|
|
109
|
+
protected __onReady(): void {
|
|
110
|
+
if (this.children.every(child => child.ready)) super.__onReady()
|
|
71
111
|
}
|
|
72
112
|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
this.children.forEach(leafer => { leafer.waitViewLoaded(wait) })
|
|
76
|
-
if (!this.running) this.start()
|
|
113
|
+
protected __onViewReady(): void {
|
|
114
|
+
if (this.children.every(child => child.viewReady)) super.__onViewReady()
|
|
77
115
|
}
|
|
78
116
|
|
|
79
117
|
protected __onChildRenderEnd(e: RenderEvent): void {
|
|
@@ -82,16 +120,16 @@ export class App extends Leafer implements IApp {
|
|
|
82
120
|
}
|
|
83
121
|
|
|
84
122
|
public __render(canvas: ILeaferCanvas, _options: IRenderOptions): void {
|
|
85
|
-
this.children.forEach(leafer =>
|
|
123
|
+
this.children.forEach(leafer => canvas.copyWorld(leafer.canvas))
|
|
86
124
|
}
|
|
87
125
|
|
|
88
126
|
public __onResize(event: IResizeEvent): void {
|
|
89
|
-
this.children.forEach(leafer =>
|
|
127
|
+
this.children.forEach(leafer => leafer.resize(event))
|
|
90
128
|
super.__onResize(event)
|
|
91
129
|
}
|
|
92
130
|
|
|
93
131
|
protected __checkUpdateLayout(): void {
|
|
94
|
-
this.children.forEach(leafer =>
|
|
132
|
+
this.children.forEach(leafer => leafer.__layout.update())
|
|
95
133
|
}
|
|
96
134
|
|
|
97
135
|
protected __getChildConfig(userConfig?: ILeaferConfig): ILeaferConfig {
|
|
@@ -106,10 +144,11 @@ export class App extends Leafer implements IApp {
|
|
|
106
144
|
return config
|
|
107
145
|
}
|
|
108
146
|
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
147
|
+
protected __listenChildEvents(leafer: ILeaferBase): void {
|
|
148
|
+
leafer.once(LayoutEvent.END, () => this.__onReady())
|
|
149
|
+
leafer.once(RenderEvent.START, () => this.__onCreated())
|
|
150
|
+
leafer.once(RenderEvent.END, () => this.__onViewReady())
|
|
151
|
+
if (this.realCanvas) this.__eventIds.push(leafer.on_(RenderEvent.END, this.__onChildRenderEnd, this))
|
|
113
152
|
}
|
|
114
153
|
|
|
115
154
|
}
|
package/src/index.ts
CHANGED
package/types/index.d.ts
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { IBoundsData, ILeaferConfig, ILeaferCanvas, IRenderOptions, IResizeEvent, ILeaferBase } from '@leafer/interface';
|
|
2
|
+
import { RenderEvent } from '@leafer/core';
|
|
3
|
+
import { IApp, ILeafer, IAppConfig, IAppInputData } from '@leafer-ui/interface';
|
|
4
|
+
import { Leafer } from '@leafer-ui/draw';
|
|
5
|
+
|
|
6
|
+
declare class App extends Leafer implements IApp {
|
|
7
|
+
get __tag(): string;
|
|
8
|
+
get isApp(): boolean;
|
|
9
|
+
children: ILeafer[];
|
|
10
|
+
realCanvas: boolean;
|
|
11
|
+
ground: ILeafer;
|
|
12
|
+
tree: ILeafer;
|
|
13
|
+
sky: ILeafer;
|
|
14
|
+
constructor(userConfig?: IAppConfig, data?: IAppInputData);
|
|
15
|
+
init(userConfig?: IAppConfig, parentApp?: IApp): void;
|
|
16
|
+
protected __setApp(): void;
|
|
17
|
+
start(): void;
|
|
18
|
+
stop(): void;
|
|
19
|
+
unlockLayout(): void;
|
|
20
|
+
lockLayout(): void;
|
|
21
|
+
forceRender(bounds?: IBoundsData): void;
|
|
22
|
+
addLeafer(merge?: ILeaferConfig): Leafer;
|
|
23
|
+
add(leafer: ILeafer): void;
|
|
24
|
+
protected __onPropertyChange(): void;
|
|
25
|
+
protected __onCreated(): void;
|
|
26
|
+
protected __onReady(): void;
|
|
27
|
+
protected __onViewReady(): void;
|
|
28
|
+
protected __onChildRenderEnd(e: RenderEvent): void;
|
|
29
|
+
__render(canvas: ILeaferCanvas, _options: IRenderOptions): void;
|
|
30
|
+
__onResize(event: IResizeEvent): void;
|
|
31
|
+
protected __checkUpdateLayout(): void;
|
|
32
|
+
protected __getChildConfig(userConfig?: ILeaferConfig): ILeaferConfig;
|
|
33
|
+
protected __listenChildEvents(leafer: ILeaferBase): void;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export { App };
|
package/src/Leafer.ts
DELETED
|
@@ -1,312 +0,0 @@
|
|
|
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, Platform, PluginManager } from '@leafer/core'
|
|
3
|
-
|
|
4
|
-
import { ILeaferInputData, ILeaferData, IFunction } from '@leafer-ui/interface'
|
|
5
|
-
import { LeaferTypeCreator } from '@leafer-ui/type'
|
|
6
|
-
import { LeaferData } from '@leafer-ui/data'
|
|
7
|
-
import { Group } from '@leafer-ui/display'
|
|
8
|
-
|
|
9
|
-
import { App } from './App'
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
const debug = Debug.get('Leafer')
|
|
13
|
-
|
|
14
|
-
@registerUI()
|
|
15
|
-
export class Leafer extends Group implements ILeafer {
|
|
16
|
-
|
|
17
|
-
public get __tag() { return 'Leafer' }
|
|
18
|
-
|
|
19
|
-
@dataProcessor(LeaferData)
|
|
20
|
-
public __: ILeaferData
|
|
21
|
-
|
|
22
|
-
@boundsType()
|
|
23
|
-
public pixelRatio: number
|
|
24
|
-
|
|
25
|
-
public get isApp(): boolean { return false }
|
|
26
|
-
|
|
27
|
-
public parent?: App
|
|
28
|
-
|
|
29
|
-
public running: boolean
|
|
30
|
-
public ready: boolean
|
|
31
|
-
public viewReady: boolean
|
|
32
|
-
public get viewLoaded(): boolean { return this.viewReady && !this.watcher.changed && this.imageManager.tasker.isComplete }
|
|
33
|
-
|
|
34
|
-
public view: unknown
|
|
35
|
-
|
|
36
|
-
// manager
|
|
37
|
-
public canvas: ILeaferCanvas
|
|
38
|
-
public renderer: IRenderer
|
|
39
|
-
|
|
40
|
-
public watcher: IWatcher
|
|
41
|
-
public layouter: ILayouter
|
|
42
|
-
|
|
43
|
-
public selector?: ISelector
|
|
44
|
-
public interaction?: IInteraction
|
|
45
|
-
|
|
46
|
-
public canvasManager: ICanvasManager
|
|
47
|
-
public hitCanvasManager?: IHitCanvasManager
|
|
48
|
-
public imageManager: IImageManager
|
|
49
|
-
|
|
50
|
-
public zoomLayer: ILeaf = this
|
|
51
|
-
public moveLayer: ILeaf = this
|
|
52
|
-
public transformData?: ITransformEventData
|
|
53
|
-
|
|
54
|
-
public userConfig: ILeaferConfig
|
|
55
|
-
public config: ILeaferConfig = {
|
|
56
|
-
type: 'design',
|
|
57
|
-
start: true,
|
|
58
|
-
hittable: true,
|
|
59
|
-
smooth: true,
|
|
60
|
-
zoom: {
|
|
61
|
-
min: 0.02,
|
|
62
|
-
max: 256
|
|
63
|
-
},
|
|
64
|
-
move: {
|
|
65
|
-
dragOut: true,
|
|
66
|
-
autoDistance: 2
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
public autoLayout?: IAutoBounds
|
|
71
|
-
|
|
72
|
-
public __eventIds: IEventListenerId[] = []
|
|
73
|
-
protected __startTimer: ITimer
|
|
74
|
-
protected __controllers: IControl[] = []
|
|
75
|
-
|
|
76
|
-
constructor(userConfig?: ILeaferConfig, data?: ILeaferInputData) {
|
|
77
|
-
super(data)
|
|
78
|
-
this.userConfig = userConfig
|
|
79
|
-
if (userConfig && (userConfig.view || userConfig.width)) this.init(userConfig)
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
public init(userConfig?: ILeaferConfig, parentApp?: IApp): void {
|
|
83
|
-
if (this.canvas) return
|
|
84
|
-
|
|
85
|
-
this.__setLeafer(this)
|
|
86
|
-
if (userConfig) DataHelper.assign(this.config, userConfig)
|
|
87
|
-
|
|
88
|
-
let start: boolean
|
|
89
|
-
const { config } = this
|
|
90
|
-
LeaferTypeCreator.run(config.type, this)
|
|
91
|
-
|
|
92
|
-
// render / layout
|
|
93
|
-
this.canvas = Creator.canvas(config)
|
|
94
|
-
this.__controllers.push(
|
|
95
|
-
this.renderer = Creator.renderer(this, this.canvas, config),
|
|
96
|
-
this.watcher = Creator.watcher(this, config),
|
|
97
|
-
this.layouter = Creator.layouter(this, config)
|
|
98
|
-
)
|
|
99
|
-
|
|
100
|
-
if (this.isApp) this.__setApp()
|
|
101
|
-
this.__checkAutoLayout(config)
|
|
102
|
-
this.view = this.canvas.view
|
|
103
|
-
|
|
104
|
-
// interaction / manager
|
|
105
|
-
if (parentApp) {
|
|
106
|
-
this.__bindApp(parentApp)
|
|
107
|
-
start = parentApp.running
|
|
108
|
-
} else {
|
|
109
|
-
this.selector = Creator.selector(this)
|
|
110
|
-
this.__controllers.unshift(this.interaction = Creator.interaction(this, this.canvas, this.selector, config))
|
|
111
|
-
|
|
112
|
-
this.canvasManager = new CanvasManager()
|
|
113
|
-
this.hitCanvasManager = new HitCanvasManager()
|
|
114
|
-
this.imageManager = new ImageManager(this, config)
|
|
115
|
-
|
|
116
|
-
start = config.start
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
this.hittable = config.hittable
|
|
120
|
-
this.fill = config.fill
|
|
121
|
-
this.canvasManager.add(this.canvas)
|
|
122
|
-
|
|
123
|
-
this.__listenEvents()
|
|
124
|
-
|
|
125
|
-
if (start) this.__startTimer = setTimeout(this.start.bind(this))
|
|
126
|
-
|
|
127
|
-
PluginManager.onLeafer(this)
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
public start(): void {
|
|
131
|
-
clearTimeout(this.__startTimer)
|
|
132
|
-
if (!this.running && this.canvas) {
|
|
133
|
-
this.ready ? this.emitLeafer(LeaferEvent.RESTART) : this.emitLeafer(LeaferEvent.START)
|
|
134
|
-
this.__controllers.forEach(item => item.start())
|
|
135
|
-
if (!this.isApp) this.renderer.render()
|
|
136
|
-
this.running = true
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
public stop(): void {
|
|
141
|
-
clearTimeout(this.__startTimer)
|
|
142
|
-
if (this.running && this.canvas) {
|
|
143
|
-
this.__controllers.forEach(item => item.stop())
|
|
144
|
-
this.running = false
|
|
145
|
-
this.emitLeafer(LeaferEvent.STOP)
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
public resize(size: IScreenSizeData): void {
|
|
150
|
-
const data = DataHelper.copyAttrs({}, size, canvasSizeAttrs)
|
|
151
|
-
Object.keys(data).forEach(key => (this as any)[key] = data[key])
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
public forceLayout(): void {
|
|
155
|
-
this.__layout.checkUpdate(true)
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
public forceFullRender(): void {
|
|
159
|
-
this.renderer.addBlock(this.canvas.bounds)
|
|
160
|
-
if (this.viewReady) this.renderer.update()
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
protected __doResize(size: IScreenSizeData): void {
|
|
164
|
-
if (!this.canvas || this.canvas.isSameSize(size)) return
|
|
165
|
-
const old = DataHelper.copyAttrs({}, this.canvas, canvasSizeAttrs) as IScreenSizeData
|
|
166
|
-
this.canvas.resize(size)
|
|
167
|
-
this.__onResize(new ResizeEvent(size, old))
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
protected __onResize(event: IResizeEvent): void {
|
|
171
|
-
this.emitEvent(event)
|
|
172
|
-
DataHelper.copyAttrs(this.__, event, canvasSizeAttrs)
|
|
173
|
-
setTimeout(() => { if (this.canvasManager) this.canvasManager.clearRecycled() }, 0)
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
protected __setApp(): void { }
|
|
177
|
-
|
|
178
|
-
protected __bindApp(app: IApp): void {
|
|
179
|
-
this.selector = app.selector
|
|
180
|
-
this.interaction = app.interaction
|
|
181
|
-
|
|
182
|
-
this.canvasManager = app.canvasManager
|
|
183
|
-
this.hitCanvasManager = app.hitCanvasManager
|
|
184
|
-
this.imageManager = app.imageManager
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
public __setLeafer(leafer: ILeafer): void {
|
|
188
|
-
this.leafer = leafer
|
|
189
|
-
this.isLeafer = !!leafer
|
|
190
|
-
this.__level = 1
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
public setZoomLayer(zoomLayer: ILeaf, moveLayer?: ILeaf): void {
|
|
194
|
-
this.zoomLayer = zoomLayer
|
|
195
|
-
this.moveLayer = moveLayer || zoomLayer
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
public waitViewLoaded(fun: IFunction): void {
|
|
199
|
-
let id: IEventListenerId
|
|
200
|
-
const check = () => {
|
|
201
|
-
if (this.viewLoaded) {
|
|
202
|
-
if (id) this.off_(id)
|
|
203
|
-
Platform.requestRender(fun)
|
|
204
|
-
}
|
|
205
|
-
}
|
|
206
|
-
if (!this.running) this.start()
|
|
207
|
-
check()
|
|
208
|
-
if (!this.viewLoaded) id = this.on_(RenderEvent.AFTER, check)
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
protected __checkAutoLayout(config: ILeaferConfig): void {
|
|
212
|
-
if (!config.width || !config.height) {
|
|
213
|
-
this.autoLayout = new AutoBounds(config)
|
|
214
|
-
this.canvas.startAutoLayout(this.autoLayout, this.__onResize.bind(this))
|
|
215
|
-
}
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
public __setAttr(attrName: string, newValue: __Value): void {
|
|
219
|
-
if (this.canvas) {
|
|
220
|
-
if (canvasSizeAttrs.includes(attrName)) {
|
|
221
|
-
this.__changeCanvasSize(attrName, newValue as number)
|
|
222
|
-
} else if (attrName === 'fill') {
|
|
223
|
-
this.__changeFill(newValue as string)
|
|
224
|
-
} else if (attrName === 'hittable') {
|
|
225
|
-
this.canvas.hittable = newValue as boolean
|
|
226
|
-
}
|
|
227
|
-
}
|
|
228
|
-
super.__setAttr(attrName, newValue)
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
public __getAttr(attrName: string): __Value {
|
|
232
|
-
if (this.canvas && canvasSizeAttrs.includes(attrName)) return this.canvas[attrName]
|
|
233
|
-
return super.__getAttr(attrName)
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
protected __changeCanvasSize(attrName: string, newValue: number): void {
|
|
237
|
-
const data = DataHelper.copyAttrs({}, this.canvas, canvasSizeAttrs)
|
|
238
|
-
data[attrName] = (this.config as IObject)[attrName] = newValue
|
|
239
|
-
if (newValue) this.canvas.stopAutoLayout()
|
|
240
|
-
this.__doResize(data as IScreenSizeData)
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
protected __changeFill(newValue: string): void {
|
|
244
|
-
this.config.fill = newValue as string
|
|
245
|
-
if (this.canvas.allowBackgroundColor) {
|
|
246
|
-
this.canvas.backgroundColor = newValue as string
|
|
247
|
-
} else {
|
|
248
|
-
this.forceFullRender()
|
|
249
|
-
}
|
|
250
|
-
}
|
|
251
|
-
|
|
252
|
-
protected __onReady(): void {
|
|
253
|
-
if (this.ready) return
|
|
254
|
-
this.ready = true
|
|
255
|
-
this.emitLeafer(LeaferEvent.BEFORE_READY)
|
|
256
|
-
this.emitLeafer(LeaferEvent.READY)
|
|
257
|
-
this.emitLeafer(LeaferEvent.AFTER_READY)
|
|
258
|
-
}
|
|
259
|
-
|
|
260
|
-
protected __onViewReady(): void {
|
|
261
|
-
if (this.viewReady) return
|
|
262
|
-
this.viewReady = true
|
|
263
|
-
this.emitLeafer(LeaferEvent.VIEW_READY)
|
|
264
|
-
}
|
|
265
|
-
|
|
266
|
-
protected __checkUpdateLayout(): void {
|
|
267
|
-
this.__layout.checkUpdate()
|
|
268
|
-
}
|
|
269
|
-
|
|
270
|
-
protected emitLeafer(type: string): void {
|
|
271
|
-
this.emitEvent(new LeaferEvent(type, this))
|
|
272
|
-
}
|
|
273
|
-
|
|
274
|
-
protected __listenEvents(): void {
|
|
275
|
-
const runId = Run.start('FirstCreate ' + this.innerName)
|
|
276
|
-
this.once(LeaferEvent.START, () => Run.end(runId))
|
|
277
|
-
this.once(LayoutEvent.END, () => this.__onReady())
|
|
278
|
-
this.once(RenderEvent.END, () => this.__onViewReady())
|
|
279
|
-
this.on(LayoutEvent.CHECK_UPDATE, () => this.__checkUpdateLayout())
|
|
280
|
-
}
|
|
281
|
-
|
|
282
|
-
protected __removeListenEvents(): void {
|
|
283
|
-
this.off_(this.__eventIds)
|
|
284
|
-
}
|
|
285
|
-
|
|
286
|
-
public destroy(): void {
|
|
287
|
-
if (this.canvas) {
|
|
288
|
-
try {
|
|
289
|
-
this.stop()
|
|
290
|
-
this.emitEvent(new LeaferEvent(LeaferEvent.END, this))
|
|
291
|
-
this.__removeListenEvents()
|
|
292
|
-
|
|
293
|
-
this.__controllers.forEach(item => item.destroy())
|
|
294
|
-
this.__controllers.length = 0
|
|
295
|
-
|
|
296
|
-
this.selector.destroy()
|
|
297
|
-
this.canvasManager.destroy()
|
|
298
|
-
this.hitCanvasManager.destroy()
|
|
299
|
-
this.imageManager.destroy()
|
|
300
|
-
|
|
301
|
-
this.canvas.destroy()
|
|
302
|
-
this.canvas = null
|
|
303
|
-
|
|
304
|
-
this.config = this.userConfig = this.view = null
|
|
305
|
-
|
|
306
|
-
super.destroy()
|
|
307
|
-
} catch (e) {
|
|
308
|
-
debug.error(e)
|
|
309
|
-
}
|
|
310
|
-
}
|
|
311
|
-
}
|
|
312
|
-
}
|