@leafer-ui/app 1.0.0-alpha.23 → 1.0.0-alpha.31
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 +53 -56
- package/src/Leafer.ts +157 -187
- 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.31",
|
|
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.31",
|
|
23
|
+
"@leafer-ui/display": "1.0.0-alpha.31"
|
|
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.31",
|
|
27
|
+
"@leafer-ui/interface": "1.0.0-alpha.31"
|
|
28
28
|
}
|
|
29
29
|
}
|
package/src/App.ts
CHANGED
|
@@ -1,45 +1,48 @@
|
|
|
1
1
|
import { ILeaferConfig, IResizeEvent, ILeaferCanvas, IRenderOptions, IApp, __Value } from '@leafer/interface'
|
|
2
|
-
import { DataHelper, LayoutEvent, RenderEvent,
|
|
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
|
|
|
9
|
-
public get
|
|
10
|
-
|
|
11
|
-
public view: unknown
|
|
10
|
+
public get __tag() { return 'App' }
|
|
12
11
|
|
|
13
|
-
public
|
|
12
|
+
public get isApp(): boolean { return true }
|
|
14
13
|
|
|
15
14
|
public children: Leafer[] = []
|
|
16
15
|
|
|
17
|
-
|
|
18
|
-
public hittable: boolean
|
|
16
|
+
public realCanvas: boolean
|
|
19
17
|
|
|
20
18
|
protected __setApp(): void {
|
|
21
|
-
|
|
22
|
-
|
|
19
|
+
const { canvas } = this
|
|
20
|
+
const { realCanvas, view } = this.config
|
|
21
|
+
if (realCanvas || view === this.canvas.view || !canvas.parentView) {
|
|
22
|
+
this.realCanvas = true
|
|
23
23
|
} else {
|
|
24
|
-
|
|
25
|
-
this.view = this.canvas.parentView
|
|
24
|
+
canvas.unrealCanvas()
|
|
26
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
|
+
)
|
|
27
36
|
}
|
|
28
37
|
|
|
29
38
|
public start(): void {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
this.renderer.start()
|
|
33
|
-
this.running = true
|
|
34
|
-
}
|
|
39
|
+
super.start()
|
|
40
|
+
this.children.forEach(leafer => { leafer.start() })
|
|
35
41
|
}
|
|
36
42
|
|
|
37
43
|
public stop(): void {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
this.renderer.stop()
|
|
41
|
-
this.running = false
|
|
42
|
-
}
|
|
44
|
+
this.children.forEach(leafer => { leafer.stop() })
|
|
45
|
+
super.stop()
|
|
43
46
|
}
|
|
44
47
|
|
|
45
48
|
public addLeafer(merge?: ILeaferConfig): Leafer {
|
|
@@ -52,23 +55,24 @@ export class App extends Leafer implements IApp {
|
|
|
52
55
|
if (!leafer.view) leafer.init(this.__getChildConfig(leafer.userConfig), this)
|
|
53
56
|
super.add(leafer)
|
|
54
57
|
|
|
55
|
-
|
|
56
|
-
|
|
58
|
+
leafer.once(LayoutEvent.END, () => {
|
|
59
|
+
if (!this.ready && this.children.every(child => child.ready)) this.__onReady()
|
|
60
|
+
})
|
|
61
|
+
|
|
62
|
+
leafer.once(RenderEvent.END, () => {
|
|
63
|
+
if (!this.viewReady && this.children.every(child => child.viewReady)) this.__onViewReady()
|
|
64
|
+
})
|
|
65
|
+
|
|
66
|
+
if (this.realCanvas) {
|
|
57
67
|
this.__eventIds.push(
|
|
58
|
-
leafer.on__(
|
|
59
|
-
leafer.on__(RenderEvent.END, renderer.update, renderer),
|
|
60
|
-
this.on__(LayoutEvent.REQUEST, renderer.mergeBlocks, renderer)
|
|
68
|
+
leafer.on__(RenderEvent.END, this.__onChildRenderEnd, this),
|
|
61
69
|
)
|
|
62
70
|
}
|
|
63
71
|
}
|
|
64
72
|
|
|
65
|
-
protected
|
|
66
|
-
|
|
67
|
-
if (
|
|
68
|
-
event.data.map(item => renderer.addBlock(item.updatedBounds))
|
|
69
|
-
} else {
|
|
70
|
-
renderer.addBlock(renderer.canvas.bounds)
|
|
71
|
-
}
|
|
73
|
+
protected __onChildRenderEnd(e: RenderEvent): void {
|
|
74
|
+
this.renderer.addBlock(e.renderBounds)
|
|
75
|
+
if (this.viewReady) this.renderer.update()
|
|
72
76
|
}
|
|
73
77
|
|
|
74
78
|
public __render(canvas: ILeaferCanvas, _options: IRenderOptions): void {
|
|
@@ -76,34 +80,27 @@ export class App extends Leafer implements IApp {
|
|
|
76
80
|
}
|
|
77
81
|
|
|
78
82
|
public __onResize(event: IResizeEvent): void {
|
|
79
|
-
this.emitEvent(event)
|
|
80
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() })
|
|
81
89
|
}
|
|
82
90
|
|
|
83
91
|
protected __getChildConfig(userConfig?: ILeaferConfig): ILeaferConfig {
|
|
84
|
-
let
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
if (this.autoLayout)
|
|
89
|
-
|
|
90
|
-
userConfig.height = this.height
|
|
91
|
-
userConfig.pixelRatio = this.pixelRatio
|
|
92
|
-
}
|
|
93
|
-
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
|
|
94
98
|
}
|
|
95
99
|
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
defineLeafAttr(target, key, defaultValue, {
|
|
101
|
-
set(value: __Value) {
|
|
102
|
-
this.__setAttr(key, value)
|
|
103
|
-
this.children.forEach(item => {
|
|
104
|
-
item.hittable = value as boolean
|
|
105
|
-
})
|
|
106
|
-
}
|
|
107
|
-
})
|
|
100
|
+
public destory(): void {
|
|
101
|
+
this.children.forEach(leafer => { leafer.destory() })
|
|
102
|
+
this.children.length = 0
|
|
103
|
+
super.destory()
|
|
108
104
|
}
|
|
105
|
+
|
|
109
106
|
}
|
package/src/Leafer.ts
CHANGED
|
@@ -1,14 +1,26 @@
|
|
|
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
|
|
|
@@ -16,28 +28,7 @@ export class Leafer extends Group implements ILeafer {
|
|
|
16
28
|
|
|
17
29
|
public running: boolean
|
|
18
30
|
public ready: boolean
|
|
19
|
-
|
|
20
|
-
public startTimer: number
|
|
21
|
-
|
|
22
|
-
@resizeType()
|
|
23
|
-
public width: number
|
|
24
|
-
|
|
25
|
-
@resizeType()
|
|
26
|
-
public height: number
|
|
27
|
-
|
|
28
|
-
@resizeType()
|
|
29
|
-
public pixelRatio: number
|
|
30
|
-
|
|
31
|
-
public get bounds(): IBounds { return this.canvas.bounds }
|
|
32
|
-
|
|
33
|
-
public userConfig: ILeaferConfig
|
|
34
|
-
public config: ILeaferConfig = {
|
|
35
|
-
type: 'design',
|
|
36
|
-
start: true,
|
|
37
|
-
hittable: true
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
public autoLayout?: IAutoBounds
|
|
31
|
+
public viewReady: boolean
|
|
41
32
|
|
|
42
33
|
public view: unknown
|
|
43
34
|
|
|
@@ -55,127 +46,130 @@ export class Leafer extends Group implements ILeafer {
|
|
|
55
46
|
public hitCanvasManager?: IHitCanvasManager
|
|
56
47
|
public imageManager: IImageManager
|
|
57
48
|
|
|
58
|
-
public zoomLayer
|
|
59
|
-
public moveLayer
|
|
49
|
+
public zoomLayer: ILeaf = this
|
|
50
|
+
public moveLayer: ILeaf = this
|
|
60
51
|
public transformData?: ITransformEventData
|
|
61
52
|
|
|
62
|
-
|
|
53
|
+
public userConfig: ILeaferConfig
|
|
54
|
+
public config: ILeaferConfig = { type: 'design', start: true, hittable: true }
|
|
63
55
|
|
|
56
|
+
public autoLayout?: IAutoBounds
|
|
64
57
|
|
|
58
|
+
public __eventIds: IEventListenerId[] = []
|
|
59
|
+
protected __startTimer: ITimer
|
|
60
|
+
protected __controllers: IControl[] = []
|
|
65
61
|
|
|
66
|
-
constructor(userConfig?: ILeaferConfig) {
|
|
67
|
-
super()
|
|
62
|
+
constructor(userConfig?: ILeaferConfig, data?: ILeaferInputData) {
|
|
63
|
+
super(data)
|
|
68
64
|
this.userConfig = userConfig
|
|
69
65
|
if (userConfig?.view) this.init(userConfig)
|
|
70
66
|
}
|
|
71
67
|
|
|
72
|
-
public init(userConfig?: ILeaferConfig,
|
|
68
|
+
public init(userConfig?: ILeaferConfig, parentApp?: IApp): void {
|
|
69
|
+
if (this.canvas) return
|
|
70
|
+
|
|
73
71
|
this.__setLeafer(this)
|
|
74
|
-
this.
|
|
72
|
+
if (userConfig) DataHelper.assign(this.config, userConfig)
|
|
75
73
|
|
|
74
|
+
let start: boolean
|
|
76
75
|
const { config } = this
|
|
77
|
-
|
|
78
|
-
this.hittable = config.hittable
|
|
76
|
+
LeaferType.run(config.type, this)
|
|
79
77
|
|
|
80
|
-
// render
|
|
78
|
+
// render / layout
|
|
81
79
|
this.canvas = Creator.canvas(config)
|
|
82
|
-
this.
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
} else {
|
|
88
|
-
// layout
|
|
89
|
-
this.watcher = Creator.watcher(this)
|
|
90
|
-
this.layouter = Creator.layouter(this)
|
|
91
|
-
}
|
|
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
|
+
)
|
|
92
85
|
|
|
86
|
+
if (this.isApp) this.__setApp()
|
|
93
87
|
this.__checkAutoLayout(config)
|
|
88
|
+
this.view = this.canvas.view
|
|
94
89
|
|
|
95
90
|
// interaction / manager
|
|
96
|
-
if (
|
|
97
|
-
this.__bindApp(
|
|
91
|
+
if (parentApp) {
|
|
92
|
+
this.__bindApp(parentApp)
|
|
93
|
+
start = parentApp.running
|
|
98
94
|
} else {
|
|
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
98
|
this.canvasManager = new CanvasManager()
|
|
103
99
|
this.hitCanvasManager = new HitCanvasManager()
|
|
104
100
|
this.imageManager = new ImageManager(this, config)
|
|
105
101
|
|
|
106
|
-
|
|
102
|
+
start = config.start
|
|
107
103
|
}
|
|
108
104
|
|
|
105
|
+
this.hittable = config.hittable
|
|
106
|
+
this.fill = config.fill
|
|
109
107
|
this.canvasManager.add(this.canvas)
|
|
110
108
|
|
|
111
109
|
this.__listenEvents()
|
|
110
|
+
|
|
111
|
+
if (start) this.__startTimer = setTimeout(this.start.bind(this))
|
|
112
112
|
}
|
|
113
113
|
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
this.
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
Run.endOfName('FirstLayout')
|
|
123
|
-
Run.start('FirstRender')
|
|
124
|
-
|
|
125
|
-
this.ready = true
|
|
126
|
-
|
|
127
|
-
this.emit(LeaferEvent.BEFORE_READY)
|
|
128
|
-
this.emit(LeaferEvent.READY)
|
|
129
|
-
this.emit(LeaferEvent.AFTER_READY)
|
|
130
|
-
})
|
|
131
|
-
|
|
132
|
-
this.once(RenderEvent.END, () => {
|
|
133
|
-
Run.endOfName('FirstRender')
|
|
134
|
-
this.emit(LeaferEvent.VIEW_READY)
|
|
135
|
-
})
|
|
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
|
+
}
|
|
136
122
|
}
|
|
137
123
|
|
|
138
|
-
|
|
139
|
-
|
|
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)
|
|
140
154
|
}
|
|
141
155
|
|
|
142
156
|
protected __setApp(): void { }
|
|
143
157
|
|
|
144
158
|
protected __bindApp(app: IApp): void {
|
|
145
|
-
app.selector?.defaultPath.unshift(this)
|
|
146
|
-
|
|
147
159
|
this.selector = app.selector
|
|
148
|
-
|
|
160
|
+
this.interaction = app.interaction
|
|
149
161
|
|
|
150
162
|
this.canvasManager = app.canvasManager
|
|
151
163
|
this.hitCanvasManager = app.hitCanvasManager
|
|
152
164
|
this.imageManager = app.imageManager
|
|
153
|
-
|
|
154
|
-
if (app.running) this.startTimer = setTimeout(this.start.bind(this))
|
|
155
165
|
}
|
|
156
166
|
|
|
157
|
-
|
|
158
167
|
public __setLeafer(leafer: ILeafer): void {
|
|
159
168
|
this.leafer = leafer
|
|
160
169
|
this.isLeafer = !!leafer
|
|
161
170
|
this.__level = 1
|
|
162
171
|
}
|
|
163
172
|
|
|
164
|
-
protected __setConfig(userConfig?: ILeaferConfig): void {
|
|
165
|
-
if (userConfig) {
|
|
166
|
-
this.config = DataHelper.default(userConfig, this.config)
|
|
167
|
-
this.__setAppType(this.config.type)
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
protected __setAppType(type: ILeaferType): void {
|
|
172
|
-
if (type === 'user') {
|
|
173
|
-
const { config } = this
|
|
174
|
-
if (!config.pointer) config.pointer = {}
|
|
175
|
-
config.pointer.autoMoveDistance = 0
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
|
|
179
173
|
protected __checkAutoLayout(config: ILeaferConfig): void {
|
|
180
174
|
if (!config.width || !config.height) {
|
|
181
175
|
this.autoLayout = new AutoBounds(config)
|
|
@@ -183,122 +177,98 @@ export class Leafer extends Group implements ILeafer {
|
|
|
183
177
|
}
|
|
184
178
|
}
|
|
185
179
|
|
|
186
|
-
public
|
|
187
|
-
if (
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
if (this.interaction) {
|
|
196
|
-
this.__interactiveWindow()
|
|
197
|
-
this.interaction.start()
|
|
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)
|
|
198
188
|
}
|
|
199
|
-
|
|
200
|
-
this.renderer.start()
|
|
201
|
-
this.layouter.start()
|
|
202
|
-
this.watcher.start()
|
|
203
|
-
this.running = true
|
|
204
189
|
}
|
|
190
|
+
super.__setAttr(attrName, newValue)
|
|
205
191
|
}
|
|
206
192
|
|
|
207
|
-
public
|
|
208
|
-
if (this.
|
|
209
|
-
|
|
210
|
-
this.watcher.stop()
|
|
211
|
-
this.layouter.stop()
|
|
212
|
-
this.renderer.stop()
|
|
213
|
-
this.running = false
|
|
214
|
-
this.emit(LeaferEvent.STOP)
|
|
215
|
-
}
|
|
193
|
+
public __getAttr(attrName: string): __Value {
|
|
194
|
+
if (this.canvas && canvasSizeAttrs.includes(attrName)) return this.canvas[attrName]
|
|
195
|
+
return super.__getAttr(attrName)
|
|
216
196
|
}
|
|
217
197
|
|
|
218
|
-
protected
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
if (!this.hasEvent(ZOOM)) this.__eventIds.push(this.on__(ZOOM, (e: ZoomEvent) => { LeafHelper.zoomOf(this, e, e.scale) }))
|
|
224
|
-
}
|
|
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)
|
|
225
203
|
}
|
|
226
204
|
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
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()
|
|
211
|
+
}
|
|
233
212
|
}
|
|
234
213
|
|
|
235
|
-
protected
|
|
236
|
-
this.
|
|
237
|
-
|
|
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)
|
|
238
220
|
}
|
|
239
221
|
|
|
240
|
-
|
|
241
|
-
if (this.
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
this.stop()
|
|
247
|
-
this.__removeListenEvents()
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
this.interaction?.destroy()
|
|
251
|
-
this.selector.destroy()
|
|
252
|
-
|
|
253
|
-
this.renderer.destroy()
|
|
254
|
-
this.watcher?.destroy()
|
|
255
|
-
this.layouter?.destroy()
|
|
256
|
-
|
|
257
|
-
this.canvasManager.destory()
|
|
258
|
-
this.hitCanvasManager.destory()
|
|
259
|
-
this.imageManager.destory()
|
|
222
|
+
protected __onViewReady(): void {
|
|
223
|
+
if (this.viewReady) return
|
|
224
|
+
this.viewReady = true
|
|
225
|
+
this.emitLeafer(LeaferEvent.VIEW_READY)
|
|
226
|
+
}
|
|
260
227
|
|
|
261
|
-
|
|
262
|
-
|
|
228
|
+
protected __checkUpdateLayout(): void {
|
|
229
|
+
this.__layout.checkUpdate()
|
|
230
|
+
}
|
|
263
231
|
|
|
264
|
-
|
|
265
|
-
|
|
232
|
+
protected emitLeafer(type: string): void {
|
|
233
|
+
this.emitEvent(new LeaferEvent(type, this))
|
|
234
|
+
}
|
|
266
235
|
|
|
267
|
-
|
|
268
|
-
|
|
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
|
+
}
|
|
269
243
|
|
|
244
|
+
protected __removeListenEvents(): void {
|
|
245
|
+
this.off__(this.__eventIds)
|
|
246
|
+
}
|
|
270
247
|
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
248
|
+
public destory(): void {
|
|
249
|
+
if (this.canvas) {
|
|
250
|
+
try {
|
|
251
|
+
this.stop()
|
|
252
|
+
this.emitEvent(new LeaferEvent(LeaferEvent.END, this))
|
|
253
|
+
this.__removeListenEvents()
|
|
274
254
|
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
this.imageManager = null
|
|
255
|
+
this.__controllers.forEach(item => item.destroy())
|
|
256
|
+
this.__controllers.length = 0
|
|
278
257
|
|
|
279
|
-
|
|
280
|
-
|
|
258
|
+
this.selector.destroy()
|
|
259
|
+
this.canvasManager.destory()
|
|
260
|
+
this.hitCanvasManager.destory()
|
|
261
|
+
this.imageManager.destory()
|
|
281
262
|
|
|
282
|
-
|
|
263
|
+
this.canvas.destroy()
|
|
264
|
+
this.canvas = null
|
|
283
265
|
|
|
284
|
-
|
|
285
|
-
}
|
|
286
|
-
}
|
|
287
|
-
}
|
|
266
|
+
this.config = this.userConfig = this.view = null
|
|
288
267
|
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
get() {
|
|
293
|
-
return (this.canvas as IObject)[key]
|
|
294
|
-
},
|
|
295
|
-
set(value: number) {
|
|
296
|
-
const { width, height, pixelRatio } = this.canvas
|
|
297
|
-
const data = { width, height, pixelRatio } as IObject
|
|
298
|
-
data[key] = value
|
|
299
|
-
this.resize(data as IScreenSizeData)
|
|
268
|
+
super.destroy()
|
|
269
|
+
} catch (e) {
|
|
270
|
+
debug.error(e)
|
|
300
271
|
}
|
|
301
272
|
}
|
|
302
|
-
Object.defineProperty(target, key, property)
|
|
303
273
|
}
|
|
304
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
|
+
}
|