@leafer-ui/app 1.0.0-rc.6 → 1.0.0-rc.8

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@leafer-ui/app",
3
- "version": "1.0.0-rc.6",
3
+ "version": "1.0.0-rc.8",
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.6",
26
- "@leafer-ui/display": "1.0.0-rc.6",
27
- "@leafer-ui/type": "1.0.0-rc.6",
28
- "@leafer-ui/data": "1.0.0-rc.6"
25
+ "@leafer/core": "1.0.0-rc.8",
26
+ "@leafer-ui/display": "1.0.0-rc.8",
27
+ "@leafer-ui/type": "1.0.0-rc.8",
28
+ "@leafer-ui/data": "1.0.0-rc.8"
29
29
  },
30
30
  "devDependencies": {
31
- "@leafer/interface": "1.0.0-rc.6",
32
- "@leafer-ui/interface": "1.0.0-rc.6"
31
+ "@leafer/interface": "1.0.0-rc.8",
32
+ "@leafer-ui/interface": "1.0.0-rc.8"
33
33
  }
34
34
  }
package/src/App.ts CHANGED
@@ -1,5 +1,7 @@
1
- import { ILeaferConfig, IResizeEvent, ILeaferCanvas, IRenderOptions, IApp, __Value, ILeafer } from '@leafer/interface'
2
- import { DataHelper, Debug, LayoutEvent, PropertyEvent, RenderEvent, canvasSizeAttrs, registerUI } from '@leafer/core'
1
+ import { ILeaferConfig, IResizeEvent, ILeaferCanvas, IRenderOptions, ILeaferBase } from '@leafer/interface'
2
+ import { Creator, DataHelper, Debug, LayoutEvent, PropertyEvent, RenderEvent, canvasSizeAttrs, registerUI } from '@leafer/core'
3
+
4
+ import { IApp, IAppConfig, IAppInputData, IEditorBase, ILeafer } from '@leafer-ui/interface'
3
5
 
4
6
  import { Leafer } from './Leafer'
5
7
 
@@ -11,10 +13,28 @@ export class App extends Leafer implements IApp {
11
13
 
12
14
  public get isApp(): boolean { return true }
13
15
 
14
- declare public children: Leafer[]
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
+ if (userConfig) {
27
+ const { ground, tree, sky, editor } = userConfig
28
+ if (ground) this.ground = this.addLeafer(ground)
29
+ if (tree || editor) this.tree = this.addLeafer(tree)
30
+ if (sky || editor) this.sky = this.addLeafer(sky || { type: 'draw', usePartRender: false })
31
+ if (editor) {
32
+ this.editor = Creator.editor(editor) as IEditorBase
33
+ this.sky.add(this.editor)
34
+ }
35
+ }
36
+ }
37
+
18
38
  protected __setApp(): void {
19
39
  const { canvas } = this
20
40
  const { realCanvas, view } = this.config
@@ -33,21 +53,31 @@ export class App extends Leafer implements IApp {
33
53
 
34
54
  public start(): void {
35
55
  super.start()
36
- this.children.forEach(leafer => { leafer.start() })
56
+ this.children.forEach(leafer => leafer.start())
37
57
  }
38
58
 
39
59
  public stop(): void {
40
- this.children.forEach(leafer => { leafer.stop() })
60
+ this.children.forEach(leafer => leafer.stop())
41
61
  super.stop()
42
62
  }
43
63
 
64
+ public unlockLayout(): void {
65
+ super.unlockLayout()
66
+ this.children.forEach(leafer => leafer.unlockLayout())
67
+ }
68
+
69
+ public lockLayout(): void {
70
+ super.lockLayout()
71
+ this.children.forEach(leafer => leafer.lockLayout())
72
+ }
73
+
44
74
  public addLeafer(merge?: ILeaferConfig): Leafer {
45
75
  const leafer = new Leafer(merge)
46
76
  this.add(leafer)
47
77
  return leafer
48
78
  }
49
79
 
50
- public add(leafer: Leafer): void {
80
+ public add(leafer: ILeafer): void {
51
81
  if (!leafer.view) {
52
82
  if (this.realCanvas && !this.canvas.bounds) { // wait miniapp select canvas
53
83
  setTimeout(() => this.add(leafer), 10)
@@ -61,7 +91,7 @@ export class App extends Leafer implements IApp {
61
91
  }
62
92
 
63
93
  protected __onPropertyChange(): void {
64
- if (Debug.showHitView) this.children.forEach(leafer => { leafer.forceUpdate('surface') })
94
+ if (Debug.showHitView) this.children.forEach(leafer => leafer.forceUpdate('surface'))
65
95
  }
66
96
 
67
97
  protected __onCreated(): void {
@@ -76,26 +106,22 @@ export class App extends Leafer implements IApp {
76
106
  if (this.children.every(child => child.viewReady)) super.__onViewReady()
77
107
  }
78
108
 
79
- protected __checkViewCompleted(): boolean {
80
- return this.children.every(item => item.viewCompleted)
81
- }
82
-
83
109
  protected __onChildRenderEnd(e: RenderEvent): void {
84
110
  this.renderer.addBlock(e.renderBounds)
85
111
  if (this.viewReady) this.renderer.update()
86
112
  }
87
113
 
88
114
  public __render(canvas: ILeaferCanvas, _options: IRenderOptions): void {
89
- this.children.forEach(leafer => { canvas.copyWorld(leafer.canvas) })
115
+ this.children.forEach(leafer => canvas.copyWorld(leafer.canvas))
90
116
  }
91
117
 
92
118
  public __onResize(event: IResizeEvent): void {
93
- this.children.forEach(leafer => { leafer.resize(event) })
119
+ this.children.forEach(leafer => leafer.resize(event))
94
120
  super.__onResize(event)
95
121
  }
96
122
 
97
123
  protected __checkUpdateLayout(): void {
98
- this.children.forEach(leafer => { leafer.__layout.checkUpdate() })
124
+ this.children.forEach(leafer => leafer.__layout.update())
99
125
  }
100
126
 
101
127
  protected __getChildConfig(userConfig?: ILeaferConfig): ILeaferConfig {
@@ -110,10 +136,10 @@ export class App extends Leafer implements IApp {
110
136
  return config
111
137
  }
112
138
 
113
- protected __listenChildEvents(leafer: ILeafer): void {
139
+ protected __listenChildEvents(leafer: ILeaferBase): void {
114
140
  leafer.once(LayoutEvent.END, () => this.__onReady())
115
141
  leafer.once(RenderEvent.START, () => this.__onCreated())
116
- leafer.once(RenderEvent.END, (e) => this.__onRenderEnd(e))
142
+ leafer.once(RenderEvent.END, () => this.__onViewReady())
117
143
  if (this.realCanvas) this.__eventIds.push(leafer.on_(RenderEvent.END, this.__onChildRenderEnd, this))
118
144
  }
119
145
 
package/src/Leafer.ts CHANGED
@@ -1,13 +1,11 @@
1
- import { IApp, ILeafer, ILeaferCanvas, IRenderer, ILayouter, ISelector, IWatcher, IInteraction, ILeaferConfig, ICanvasManager, IHitCanvasManager, IAutoBounds, IScreenSizeData, IResizeEvent, ILeaf, IEventListenerId, ITimer, __Value, IObject, IControl, IPointData } 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'
1
+ import { ILeaferCanvas, IRenderer, ILayouter, ISelector, IWatcher, IInteraction, ILeaferConfig, ICanvasManager, IHitCanvasManager, IAutoBounds, IScreenSizeData, IResizeEvent, ILeaf, IEventListenerId, ITimer, IValue, IObject, IControl, IPointData } from '@leafer/interface'
2
+ import { AutoBounds, LayoutEvent, ResizeEvent, LeaferEvent, CanvasManager, HitCanvasManager, ImageManager, DataHelper, Creator, Run, Debug, RenderEvent, AnimateEvent, registerUI, boundsType, canvasSizeAttrs, dataProcessor, PluginManager, WaitHelper, WatchEvent } from '@leafer/core'
3
3
 
4
- import { ILeaferInputData, ILeaferData, IFunction, IUIInputData } from '@leafer-ui/interface'
4
+ import { ILeaferInputData, ILeaferData, IFunction, IUIInputData, ILeafer, IGroup, IApp, IEditorBase } from '@leafer-ui/interface'
5
5
  import { LeaferTypeCreator } from '@leafer-ui/type'
6
6
  import { LeaferData } from '@leafer-ui/data'
7
7
  import { Group } from '@leafer-ui/display'
8
8
 
9
- import { App } from './App'
10
-
11
9
 
12
10
  const debug = Debug.get('Leafer')
13
11
 
@@ -25,13 +23,15 @@ export class Leafer extends Group implements ILeafer {
25
23
  public get isApp(): boolean { return false }
26
24
  public get app(): ILeafer { return this.parent || this }
27
25
 
28
- declare public parent?: App
26
+ declare public parent?: IApp
29
27
 
30
28
  public running: boolean
31
29
  public created: boolean
32
30
  public ready: boolean
33
31
  public viewReady: boolean
34
32
  public viewCompleted: boolean
33
+ public get imageReady(): boolean { return this.viewReady && ImageManager.isComplete }
34
+ public get layoutLocked() { return !this.layouter.running }
35
35
 
36
36
  public view: unknown
37
37
 
@@ -48,7 +48,10 @@ export class Leafer extends Group implements ILeafer {
48
48
  public canvasManager: ICanvasManager
49
49
  public hitCanvasManager?: IHitCanvasManager
50
50
 
51
- public zoomLayer: ILeaf = this
51
+ // plugin
52
+ public editor: IEditorBase
53
+
54
+ public zoomLayer: IGroup = this
52
55
 
53
56
  public userConfig: ILeaferConfig
54
57
  public config: ILeaferConfig = {
@@ -163,15 +166,21 @@ export class Leafer extends Group implements ILeafer {
163
166
  }
164
167
  }
165
168
 
169
+ public unlockLayout(): void {
170
+ this.layouter.start()
171
+ this.updateLayout()
172
+ }
173
+
174
+ public lockLayout(): void {
175
+ this.updateLayout()
176
+ this.layouter.stop()
177
+ }
178
+
166
179
  public resize(size: IScreenSizeData): void {
167
180
  const data = DataHelper.copyAttrs({}, size, canvasSizeAttrs)
168
181
  Object.keys(data).forEach(key => (this as any)[key] = data[key])
169
182
  }
170
183
 
171
- public forceLayout(): void {
172
- this.__layout.checkUpdate(true)
173
- }
174
-
175
184
  public forceFullRender(): void {
176
185
  this.renderer.addBlock(this.canvas.bounds)
177
186
  if (this.viewReady) this.renderer.update()
@@ -211,7 +220,7 @@ export class Leafer extends Group implements ILeafer {
211
220
  }
212
221
 
213
222
  public setZoomLayer(zoomLayer: ILeaf): void {
214
- this.zoomLayer = zoomLayer
223
+ this.zoomLayer = zoomLayer as IGroup
215
224
  }
216
225
 
217
226
  protected __checkAutoLayout(config: ILeaferConfig): void {
@@ -221,7 +230,7 @@ export class Leafer extends Group implements ILeafer {
221
230
  }
222
231
  }
223
232
 
224
- public __setAttr(attrName: string, newValue: __Value): void {
233
+ public __setAttr(attrName: string, newValue: IValue): void {
225
234
  if (this.canvas) {
226
235
  if (canvasSizeAttrs.includes(attrName)) {
227
236
  this.__changeCanvasSize(attrName, newValue as number)
@@ -234,7 +243,7 @@ export class Leafer extends Group implements ILeafer {
234
243
  super.__setAttr(attrName, newValue)
235
244
  }
236
245
 
237
- public __getAttr(attrName: string): __Value {
246
+ public __getAttr(attrName: string): IValue {
238
247
  if (this.canvas && canvasSizeAttrs.includes(attrName)) return this.canvas[attrName]
239
248
  return super.__getAttr(attrName)
240
249
  }
@@ -275,23 +284,24 @@ export class Leafer extends Group implements ILeafer {
275
284
  WaitHelper.run(this.__viewReadyWait)
276
285
  }
277
286
 
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
- }
287
+ protected __onAnimateFrame(): void {
288
+ if (this.viewReady) {
289
+ if (this.__nextRenderWait.length) WaitHelper.run(this.__nextRenderWait)
285
290
 
286
- protected __checkViewCompleted(): boolean {
287
- return this.viewReady && !this.watcher.changed && ImageManager.isComplete
291
+ const { imageReady } = this
292
+ if (imageReady && !this.viewCompleted) this.__checkViewCompleted()
293
+ if (!imageReady) this.viewCompleted = false
294
+ }
288
295
  }
289
296
 
290
- protected __onViewCompleted(): void {
291
- if (!this.viewCompleted) {
292
- this.emitLeafer(LeaferEvent.VIEW_COMPLETED)
293
- WaitHelper.run(this.__viewCompletedWait)
294
- }
297
+ protected __checkViewCompleted(emit: boolean = true): void {
298
+ this.nextRender(() => {
299
+ if (this.imageReady) {
300
+ if (emit) this.emitLeafer(LeaferEvent.VIEW_COMPLETED)
301
+ WaitHelper.run(this.__viewCompletedWait)
302
+ this.viewCompleted = true
303
+ }
304
+ })
295
305
  }
296
306
 
297
307
  protected __onWatchData(): void {
@@ -309,24 +319,20 @@ export class Leafer extends Group implements ILeafer {
309
319
  }
310
320
 
311
321
  public waitViewCompleted(item: IFunction): void {
322
+ this.__viewCompletedWait.push(item)
312
323
  if (this.viewCompleted) {
313
- item()
324
+ this.__checkViewCompleted(false)
314
325
  } else {
315
- this.__viewCompletedWait.push(item)
316
326
  if (!this.running) this.start()
317
327
  }
318
328
  }
319
329
 
320
330
  public nextRender(item: IFunction): void {
321
- if (this.watcher && !this.watcher.changed) {
322
- item()
323
- } else {
324
- this.__nextRenderWait.push(item)
325
- }
331
+ this.__nextRenderWait.push(item)
326
332
  }
327
333
 
328
334
  protected __checkUpdateLayout(): void {
329
- this.__layout.checkUpdate()
335
+ this.__layout.update()
330
336
  }
331
337
 
332
338
  protected emitLeafer(type: string): void {
@@ -338,9 +344,10 @@ export class Leafer extends Group implements ILeafer {
338
344
  this.once(LeaferEvent.START, () => Run.end(runId))
339
345
  this.once(LayoutEvent.END, () => this.__onReady())
340
346
  this.once(RenderEvent.START, () => this.__onCreated())
347
+ this.once(RenderEvent.END, () => this.__onViewReady())
341
348
  this.__eventIds.push(
342
349
  this.on_(WatchEvent.DATA, this.__onWatchData, this),
343
- this.on_(RenderEvent.END, this.__onRenderEnd, this),
350
+ this.on_(AnimateEvent.FRAME, this.__onAnimateFrame, this),
344
351
  this.on_(LayoutEvent.CHECK_UPDATE, this.__checkUpdateLayout, this)
345
352
  )
346
353
  }
package/types/index.d.ts CHANGED
@@ -1,30 +1,7 @@
1
- import { IApp, ILeaferConfig, ILeaferCanvas, IRenderOptions, IResizeEvent, ILeafer, IRenderer, IWatcher, ILayouter, ISelector, IInteraction, ICanvasManager, IHitCanvasManager, ILeaf, IAutoBounds, IPointData, IEventListenerId, ITimer, IControl, IScreenSizeData, __Value } from '@leafer/interface';
2
- import { RenderEvent } from '@leafer/core';
3
- import { ILeaferData, IFunction, ILeaferInputData, IUIInputData } from '@leafer-ui/interface';
1
+ import { ILeaferCanvas, IRenderer, IWatcher, ILayouter, ISelector, IInteraction, ICanvasManager, IHitCanvasManager, ILeaferConfig, IAutoBounds, IPointData, IEventListenerId, ITimer, IControl, IScreenSizeData, IResizeEvent, ILeaf, IValue, IRenderOptions, ILeaferBase } from '@leafer/interface';
2
+ import { ILeafer, ILeaferData, IApp, IEditorBase, IGroup, IFunction, ILeaferInputData, IUIInputData, IAppConfig, IAppInputData } from '@leafer-ui/interface';
4
3
  import { Group } from '@leafer-ui/display';
5
-
6
- declare class App extends Leafer implements IApp {
7
- get __tag(): string;
8
- get isApp(): boolean;
9
- children: Leafer[];
10
- realCanvas: boolean;
11
- protected __setApp(): void;
12
- start(): void;
13
- stop(): void;
14
- addLeafer(merge?: ILeaferConfig): Leafer;
15
- add(leafer: Leafer): void;
16
- protected __onPropertyChange(): void;
17
- protected __onCreated(): void;
18
- protected __onReady(): void;
19
- protected __onViewReady(): void;
20
- protected __checkViewCompleted(): boolean;
21
- protected __onChildRenderEnd(e: RenderEvent): void;
22
- __render(canvas: ILeaferCanvas, _options: IRenderOptions): void;
23
- __onResize(event: IResizeEvent): void;
24
- protected __checkUpdateLayout(): void;
25
- protected __getChildConfig(userConfig?: ILeaferConfig): ILeaferConfig;
26
- protected __listenChildEvents(leafer: ILeafer): void;
27
- }
4
+ import { RenderEvent } from '@leafer/core';
28
5
 
29
6
  declare class Leafer extends Group implements ILeafer {
30
7
  get __tag(): string;
@@ -32,12 +9,14 @@ declare class Leafer extends Group implements ILeafer {
32
9
  pixelRatio: number;
33
10
  get isApp(): boolean;
34
11
  get app(): ILeafer;
35
- parent?: App;
12
+ parent?: IApp;
36
13
  running: boolean;
37
14
  created: boolean;
38
15
  ready: boolean;
39
16
  viewReady: boolean;
40
17
  viewCompleted: boolean;
18
+ get imageReady(): boolean;
19
+ get layoutLocked(): boolean;
41
20
  view: unknown;
42
21
  canvas: ILeaferCanvas;
43
22
  renderer: IRenderer;
@@ -47,7 +26,8 @@ declare class Leafer extends Group implements ILeafer {
47
26
  interaction?: IInteraction;
48
27
  canvasManager: ICanvasManager;
49
28
  hitCanvasManager?: IHitCanvasManager;
50
- zoomLayer: ILeaf;
29
+ editor: IEditorBase;
30
+ zoomLayer: IGroup;
51
31
  userConfig: ILeaferConfig;
52
32
  config: ILeaferConfig;
53
33
  autoLayout?: IAutoBounds;
@@ -65,8 +45,9 @@ declare class Leafer extends Group implements ILeafer {
65
45
  set(data: IUIInputData): void;
66
46
  start(): void;
67
47
  stop(): void;
48
+ unlockLayout(): void;
49
+ lockLayout(): void;
68
50
  resize(size: IScreenSizeData): void;
69
- forceLayout(): void;
70
51
  forceFullRender(): void;
71
52
  updateCursor(): void;
72
53
  protected __doResize(size: IScreenSizeData): void;
@@ -76,16 +57,15 @@ declare class Leafer extends Group implements ILeafer {
76
57
  __setLeafer(leafer: ILeafer): void;
77
58
  setZoomLayer(zoomLayer: ILeaf): void;
78
59
  protected __checkAutoLayout(config: ILeaferConfig): void;
79
- __setAttr(attrName: string, newValue: __Value): void;
80
- __getAttr(attrName: string): __Value;
60
+ __setAttr(attrName: string, newValue: IValue): void;
61
+ __getAttr(attrName: string): IValue;
81
62
  protected __changeCanvasSize(attrName: string, newValue: number): void;
82
63
  protected __changeFill(newValue: string): void;
83
64
  protected __onCreated(): void;
84
65
  protected __onReady(): void;
85
66
  protected __onViewReady(): void;
86
- protected __onRenderEnd(_e: RenderEvent): void;
87
- protected __checkViewCompleted(): boolean;
88
- protected __onViewCompleted(): void;
67
+ protected __onAnimateFrame(): void;
68
+ protected __checkViewCompleted(emit?: boolean): void;
89
69
  protected __onWatchData(): void;
90
70
  waitReady(item: IFunction): void;
91
71
  waitViewReady(item: IFunction): void;
@@ -98,4 +78,32 @@ declare class Leafer extends Group implements ILeafer {
98
78
  destroy(): void;
99
79
  }
100
80
 
81
+ declare class App extends Leafer implements IApp {
82
+ get __tag(): string;
83
+ get isApp(): boolean;
84
+ children: ILeafer[];
85
+ realCanvas: boolean;
86
+ ground: ILeafer;
87
+ tree: ILeafer;
88
+ sky: ILeafer;
89
+ constructor(userConfig?: IAppConfig, data?: IAppInputData);
90
+ protected __setApp(): void;
91
+ start(): void;
92
+ stop(): void;
93
+ unlockLayout(): void;
94
+ lockLayout(): void;
95
+ addLeafer(merge?: ILeaferConfig): Leafer;
96
+ add(leafer: ILeafer): void;
97
+ protected __onPropertyChange(): void;
98
+ protected __onCreated(): void;
99
+ protected __onReady(): void;
100
+ protected __onViewReady(): void;
101
+ protected __onChildRenderEnd(e: RenderEvent): void;
102
+ __render(canvas: ILeaferCanvas, _options: IRenderOptions): void;
103
+ __onResize(event: IResizeEvent): void;
104
+ protected __checkUpdateLayout(): void;
105
+ protected __getChildConfig(userConfig?: ILeaferConfig): ILeaferConfig;
106
+ protected __listenChildEvents(leafer: ILeaferBase): void;
107
+ }
108
+
101
109
  export { App, Leafer };