@leafer-ui/app 1.0.0-alpha.2 → 1.0.0-alpha.21
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 +8 -7
- package/src/App.ts +84 -0
- package/src/Leafer.ts +49 -48
- package/src/index.ts +1 -1
- package/src/SuperLeafer.ts +0 -68
package/package.json
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@leafer-ui/app",
|
|
3
|
-
"version": "1.0.0-alpha.
|
|
3
|
+
"version": "1.0.0-alpha.21",
|
|
4
4
|
"description": "@leafer-ui/app",
|
|
5
5
|
"author": "Chao (Leafer) Wan",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"main": "src/index.ts",
|
|
8
|
-
"files": [
|
|
8
|
+
"files": [
|
|
9
|
+
"src"
|
|
10
|
+
],
|
|
9
11
|
"repository": {
|
|
10
12
|
"type": "git",
|
|
11
13
|
"url": "https://github.com/leaferjs/ui.git"
|
|
@@ -13,16 +15,15 @@
|
|
|
13
15
|
"homepage": "https://github.com/leaferjs/ui/tree/main/packages/app",
|
|
14
16
|
"bugs": "https://github.com/leaferjs/ui/issues",
|
|
15
17
|
"keywords": [
|
|
16
|
-
"leaferui",
|
|
17
18
|
"leafer-ui",
|
|
18
19
|
"leaferjs"
|
|
19
20
|
],
|
|
20
21
|
"dependencies": {
|
|
21
|
-
"@leafer/core": "1.0.0-alpha.
|
|
22
|
-
"@leafer-ui/display": "1.0.0-alpha.
|
|
22
|
+
"@leafer/core": "1.0.0-alpha.21",
|
|
23
|
+
"@leafer-ui/display": "1.0.0-alpha.21"
|
|
23
24
|
},
|
|
24
25
|
"devDependencies": {
|
|
25
|
-
|
|
26
|
-
|
|
26
|
+
"@leafer/interface": "1.0.0-alpha.21",
|
|
27
|
+
"@leafer-ui/interface": "1.0.0-alpha.21"
|
|
27
28
|
}
|
|
28
29
|
}
|
package/src/App.ts
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { ILeaferConfig, IResizeEvent, ILeaferCanvas, IRenderOptions, IApp } from '@leafer/interface'
|
|
2
|
+
import { DataHelper, LayoutEvent, RenderEvent } from '@leafer/core'
|
|
3
|
+
|
|
4
|
+
import { Leafer } from './Leafer'
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
export class App extends Leafer implements IApp {
|
|
8
|
+
|
|
9
|
+
public get isApp(): boolean { return true }
|
|
10
|
+
|
|
11
|
+
public children: Leafer[] = []
|
|
12
|
+
|
|
13
|
+
constructor(userConfig?: ILeaferConfig) {
|
|
14
|
+
super(userConfig)
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
public start(): void {
|
|
18
|
+
this.children.forEach(leafer => { leafer.start() })
|
|
19
|
+
this.renderer.start()
|
|
20
|
+
this.running = true
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
public stop(): void {
|
|
24
|
+
this.children.forEach(leafer => { leafer.stop() })
|
|
25
|
+
this.renderer.stop()
|
|
26
|
+
this.running = false
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
public addLeafer(merge?: ILeaferConfig): Leafer {
|
|
30
|
+
const leafer = new Leafer(this.__getChildConfig(merge), this)
|
|
31
|
+
this.add(leafer)
|
|
32
|
+
|
|
33
|
+
const { renderer } = this
|
|
34
|
+
|
|
35
|
+
this.__eventIds.push(
|
|
36
|
+
leafer.on__(LayoutEvent.END, this.__onChildLayoutEnd, this),
|
|
37
|
+
leafer.on__(RenderEvent.END, renderer.update, renderer),
|
|
38
|
+
this.on__(LayoutEvent.REQUEST, renderer.mergeBlocks, renderer),
|
|
39
|
+
)
|
|
40
|
+
|
|
41
|
+
return leafer
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
protected __onChildLayoutEnd(event: LayoutEvent): void {
|
|
45
|
+
const { renderer } = this
|
|
46
|
+
if ((event.current as Leafer).config.usePartRender) {
|
|
47
|
+
event.data.map(item => renderer.addBlock(item.updatedBounds))
|
|
48
|
+
} else {
|
|
49
|
+
renderer.addBlock(renderer.canvas.bounds)
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
public __render(canvas: ILeaferCanvas, _options: IRenderOptions): void {
|
|
54
|
+
this.children.forEach(leafer => { canvas.copyWorld(leafer.canvas) })
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
public __onResize(event: IResizeEvent): void {
|
|
58
|
+
this.emitEvent(event)
|
|
59
|
+
this.children.forEach(leafer => { leafer.resize(event) })
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
protected __getChildConfig(userConfig?: ILeaferConfig): ILeaferConfig {
|
|
63
|
+
let old = { ...this.config }
|
|
64
|
+
userConfig = userConfig ? DataHelper.default(userConfig, old) : old
|
|
65
|
+
userConfig.view = null
|
|
66
|
+
if (this.autoLayout) {
|
|
67
|
+
userConfig.width = this.width
|
|
68
|
+
userConfig.height = this.height
|
|
69
|
+
userConfig.pixelRatio = this.pixelRatio
|
|
70
|
+
}
|
|
71
|
+
return userConfig
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
public destory(): void {
|
|
75
|
+
super.destory()
|
|
76
|
+
|
|
77
|
+
const { children } = this
|
|
78
|
+
if (children.length) {
|
|
79
|
+
children.forEach(leafer => leafer.destory())
|
|
80
|
+
children.length = 0
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
}
|
package/src/Leafer.ts
CHANGED
|
@@ -1,19 +1,18 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { IApp, ILeafer, ILeaferCanvas, IRenderer, ILayouter, ICreator, ISelector, IWatcher, IInteraction, ILeaferConfig, ICanvasManager, IHitCanvasManager, IImageManager, IAutoBounds, IScreenSizeData, IResizeEvent, IObject, ILeaf, IEventListenerId, ITransformEventData } from '@leafer/interface'
|
|
2
|
+
import { AutoBounds, LayoutEvent, ResizeEvent, MoveEvent, ZoomEvent, CanvasManager, HitCanvasManager, ImageManager, DataHelper, LeafHelper, Creator, Run } from '@leafer/core'
|
|
3
3
|
|
|
4
4
|
import { Group } from '@leafer-ui/display'
|
|
5
5
|
|
|
6
|
-
import {
|
|
6
|
+
import { App } from './App'
|
|
7
7
|
|
|
8
8
|
|
|
9
|
-
@registerUI()
|
|
10
9
|
export class Leafer extends Group implements ILeafer {
|
|
11
10
|
|
|
12
11
|
public creator: ICreator
|
|
13
12
|
|
|
14
|
-
public get
|
|
13
|
+
public get isApp(): boolean { return false }
|
|
15
14
|
|
|
16
|
-
public parent?:
|
|
15
|
+
public parent?: App
|
|
17
16
|
|
|
18
17
|
public running: boolean
|
|
19
18
|
|
|
@@ -27,9 +26,10 @@ export class Leafer extends Group implements ILeafer {
|
|
|
27
26
|
public pixelRatio: number
|
|
28
27
|
|
|
29
28
|
public config: ILeaferConfig = {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
29
|
+
useZoom: true,
|
|
30
|
+
useMove: true,
|
|
31
|
+
autoStart: true,
|
|
32
|
+
hittable: true,
|
|
33
33
|
pixelRatio: devicePixelRatio
|
|
34
34
|
}
|
|
35
35
|
|
|
@@ -56,56 +56,54 @@ export class Leafer extends Group implements ILeafer {
|
|
|
56
56
|
|
|
57
57
|
protected __eventIds: IEventListenerId[] = []
|
|
58
58
|
|
|
59
|
-
constructor(userConfig?: ILeaferConfig,
|
|
59
|
+
constructor(userConfig?: ILeaferConfig, app?: IApp) {
|
|
60
60
|
super()
|
|
61
61
|
|
|
62
|
-
this.creator = Creator
|
|
63
|
-
|
|
64
|
-
const { config } = this
|
|
65
|
-
|
|
66
62
|
this.__setAsLeafer()
|
|
67
63
|
this.__setConfig(userConfig)
|
|
68
64
|
|
|
65
|
+
const { config } = this
|
|
66
|
+
this.creator = Creator
|
|
67
|
+
this.hittable = config.hittable
|
|
68
|
+
|
|
69
69
|
// render
|
|
70
70
|
this.canvas = Creator.canvas(config)
|
|
71
71
|
this.renderer = Creator.renderer(this, this.canvas, config)
|
|
72
72
|
|
|
73
73
|
// layout
|
|
74
|
-
if (this.
|
|
74
|
+
if (this.isApp) {
|
|
75
75
|
this.__level = 1
|
|
76
76
|
} else {
|
|
77
|
-
|
|
78
77
|
this.watcher = Creator.watcher(this)
|
|
79
78
|
this.layouter = Creator.layouter(this)
|
|
80
|
-
|
|
81
79
|
}
|
|
82
80
|
|
|
83
81
|
this.__checkAutoLayout(config)
|
|
84
82
|
|
|
85
83
|
// interaction / manager
|
|
86
|
-
if (
|
|
84
|
+
if (app) {
|
|
87
85
|
|
|
88
|
-
|
|
86
|
+
app.selector?.defaultPath.unshift(this)
|
|
89
87
|
|
|
90
|
-
this.selector =
|
|
91
|
-
this.interaction =
|
|
88
|
+
this.selector = app.selector
|
|
89
|
+
if (config.hittable) this.interaction = app.interaction
|
|
92
90
|
|
|
93
|
-
this.canvasManager =
|
|
94
|
-
this.hitCanvasManager =
|
|
95
|
-
this.imageManager =
|
|
91
|
+
this.canvasManager = app.canvasManager
|
|
92
|
+
this.hitCanvasManager = app.hitCanvasManager
|
|
93
|
+
this.imageManager = app.imageManager
|
|
96
94
|
|
|
97
|
-
if (
|
|
95
|
+
if (app.running) setTimeout(this.start.bind(this))
|
|
98
96
|
|
|
99
97
|
} else {
|
|
100
98
|
|
|
101
99
|
this.selector = Creator.selector(this)
|
|
102
|
-
this.interaction = Creator.interaction(this, this.canvas, this.selector, config)
|
|
100
|
+
if (config.hittable) this.interaction = Creator.interaction(this, this.canvas, this.selector, config)
|
|
103
101
|
|
|
104
102
|
this.canvasManager = new CanvasManager(this)
|
|
105
103
|
this.hitCanvasManager = new HitCanvasManager(this)
|
|
106
104
|
this.imageManager = new ImageManager(this, config)
|
|
107
|
-
|
|
108
|
-
if (config.
|
|
105
|
+
Run.start('FullCreate')
|
|
106
|
+
if (config.autoStart) setTimeout(this.start.bind(this))
|
|
109
107
|
|
|
110
108
|
}
|
|
111
109
|
|
|
@@ -129,14 +127,17 @@ export class Leafer extends Group implements ILeafer {
|
|
|
129
127
|
protected __checkAutoLayout(config: ILeaferConfig): void {
|
|
130
128
|
if (!config.width || !config.height) {
|
|
131
129
|
this.autoLayout = new AutoBounds(config)
|
|
132
|
-
this.canvas.
|
|
130
|
+
this.canvas.startAutoLayout(this.autoLayout, this.__onResize.bind(this))
|
|
133
131
|
}
|
|
134
132
|
}
|
|
135
133
|
|
|
136
134
|
public start(): void {
|
|
137
135
|
if (!this.running) {
|
|
138
|
-
|
|
139
|
-
this.interaction
|
|
136
|
+
Run.endOfName('FullCreate')
|
|
137
|
+
if (this.interaction) {
|
|
138
|
+
this.__interactiveWindow()
|
|
139
|
+
this.interaction.start()
|
|
140
|
+
}
|
|
140
141
|
this.renderer.start()
|
|
141
142
|
this.layouter.start()
|
|
142
143
|
this.watcher.start()
|
|
@@ -146,7 +147,7 @@ export class Leafer extends Group implements ILeafer {
|
|
|
146
147
|
|
|
147
148
|
public stop(): void {
|
|
148
149
|
if (this.running) {
|
|
149
|
-
this.interaction
|
|
150
|
+
if (this.interaction) this.interaction.stop()
|
|
150
151
|
this.watcher.stop()
|
|
151
152
|
this.layouter.stop()
|
|
152
153
|
this.renderer.stop()
|
|
@@ -155,12 +156,12 @@ export class Leafer extends Group implements ILeafer {
|
|
|
155
156
|
}
|
|
156
157
|
|
|
157
158
|
protected __interactiveWindow(): void {
|
|
158
|
-
const {
|
|
159
|
-
if (
|
|
159
|
+
const { useZoom, useMove } = this.config
|
|
160
|
+
if (useMove) {
|
|
160
161
|
const { MOVE } = MoveEvent
|
|
161
162
|
const { ZOOM } = ZoomEvent
|
|
162
|
-
if (!this.hasEvent(MOVE)) this.__eventIds.push(this.on__(MOVE, (e: MoveEvent) => { LeafHelper.
|
|
163
|
-
if (
|
|
163
|
+
if (!this.hasEvent(MOVE)) this.__eventIds.push(this.on__(MOVE, (e: MoveEvent) => { LeafHelper.moveOfWorld(this, e.moveX, e.moveY) }))
|
|
164
|
+
if (useZoom && !this.hasEvent(ZOOM)) this.__eventIds.push(this.on__(ZOOM, (e: ZoomEvent) => { LeafHelper.zoomOfWorld(this, e.scale, e) }))
|
|
164
165
|
}
|
|
165
166
|
}
|
|
166
167
|
|
|
@@ -197,24 +198,24 @@ export class Leafer extends Group implements ILeafer {
|
|
|
197
198
|
}
|
|
198
199
|
|
|
199
200
|
this.canvas.destroy()
|
|
200
|
-
this.canvas =
|
|
201
|
+
this.canvas = null
|
|
201
202
|
|
|
202
|
-
this.creator =
|
|
203
|
-
this.config =
|
|
203
|
+
this.creator = null
|
|
204
|
+
this.config = null
|
|
204
205
|
|
|
205
|
-
this.interaction =
|
|
206
|
-
this.selector =
|
|
206
|
+
this.interaction = null
|
|
207
|
+
this.selector = null
|
|
207
208
|
|
|
208
209
|
|
|
209
|
-
this.renderer =
|
|
210
|
-
this.watcher =
|
|
211
|
-
this.layouter =
|
|
210
|
+
this.renderer = null
|
|
211
|
+
this.watcher = null
|
|
212
|
+
this.layouter = null
|
|
212
213
|
|
|
213
|
-
this.canvasManager =
|
|
214
|
-
this.hitCanvasManager =
|
|
215
|
-
this.imageManager =
|
|
214
|
+
this.canvasManager = null
|
|
215
|
+
this.hitCanvasManager = null
|
|
216
|
+
this.imageManager = null
|
|
216
217
|
|
|
217
|
-
this.zoomLayer =
|
|
218
|
+
this.zoomLayer = null
|
|
218
219
|
this.moveLayer = undefined
|
|
219
220
|
|
|
220
221
|
this.parent = undefined
|
package/src/index.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export { Leafer } from './Leafer'
|
|
2
|
-
export {
|
|
2
|
+
export { App } from './App'
|
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
|
-
}
|