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