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