@leafer-ui/app 1.0.0-beta.9 → 1.0.0-rc.3

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,12 +1,15 @@
1
1
  {
2
2
  "name": "@leafer-ui/app",
3
- "version": "1.0.0-beta.9",
3
+ "version": "1.0.0-rc.3",
4
4
  "description": "@leafer-ui/app",
5
5
  "author": "Chao (Leafer) Wan",
6
6
  "license": "MIT",
7
7
  "main": "src/index.ts",
8
+ "types": "types/index.d.ts",
8
9
  "files": [
9
- "src"
10
+ "src",
11
+ "types",
12
+ "dist"
10
13
  ],
11
14
  "repository": {
12
15
  "type": "git",
@@ -19,13 +22,13 @@
19
22
  "leaferjs"
20
23
  ],
21
24
  "dependencies": {
22
- "@leafer/core": "1.0.0-beta.9",
23
- "@leafer-ui/display": "1.0.0-beta.9",
24
- "@leafer-ui/type": "1.0.0-beta.9",
25
- "@leafer-ui/data": "1.0.0-beta.9"
25
+ "@leafer/core": "1.0.0-rc.3",
26
+ "@leafer-ui/display": "1.0.0-rc.3",
27
+ "@leafer-ui/type": "1.0.0-rc.3",
28
+ "@leafer-ui/data": "1.0.0-rc.3"
26
29
  },
27
30
  "devDependencies": {
28
- "@leafer/interface": "1.0.0-beta.9",
29
- "@leafer-ui/interface": "1.0.0-beta.9"
31
+ "@leafer/interface": "1.0.0-rc.3",
32
+ "@leafer-ui/interface": "1.0.0-rc.3"
30
33
  }
31
34
  }
package/src/App.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { ILeaferConfig, IResizeEvent, ILeaferCanvas, IRenderOptions, IApp, __Value, IFunction } from '@leafer/interface'
2
- import { DataHelper, Debug, LayoutEvent, Platform, PropertyEvent, RenderEvent, canvasSizeAttrs, registerUI } from '@leafer/core'
1
+ import { ILeaferConfig, IResizeEvent, ILeaferCanvas, IRenderOptions, IApp, __Value, ILeafer } from '@leafer/interface'
2
+ import { DataHelper, Debug, LayoutEvent, PropertyEvent, RenderEvent, canvasSizeAttrs, registerUI } from '@leafer/core'
3
3
 
4
4
  import { Leafer } from './Leafer'
5
5
 
@@ -11,7 +11,7 @@ export class App extends Leafer implements IApp {
11
11
 
12
12
  public get isApp(): boolean { return true }
13
13
 
14
- public children: Leafer[] = []
14
+ declare public children: Leafer[]
15
15
 
16
16
  public realCanvas: boolean
17
17
 
@@ -28,11 +28,7 @@ export class App extends Leafer implements IApp {
28
28
  this.watcher.disable()
29
29
  this.layouter.disable()
30
30
 
31
- this.__eventIds.push(
32
- this.on_(PropertyEvent.CHANGE, () => {
33
- if (Debug.showHitView) this.children.forEach(leafer => { leafer.forceUpdate('blendMode') })
34
- })
35
- )
31
+ this.__eventIds.push(this.on_(PropertyEvent.CHANGE, this.__onPropertyChange, this))
36
32
  }
37
33
 
38
34
  public start(): void {
@@ -52,28 +48,36 @@ export class App extends Leafer implements IApp {
52
48
  }
53
49
 
54
50
  public add(leafer: Leafer): void {
55
- if (!leafer.view) leafer.init(this.__getChildConfig(leafer.userConfig), this)
51
+ if (!leafer.view) {
52
+ if (this.realCanvas && !this.canvas.bounds) { // wait miniapp select canvas
53
+ setTimeout(() => this.add(leafer), 10)
54
+ return
55
+ }
56
+ leafer.init(this.__getChildConfig(leafer.userConfig), this)
57
+ }
58
+
56
59
  super.add(leafer)
60
+ this.__listenChildEvents(leafer)
61
+ }
62
+
63
+ protected __onPropertyChange(): void {
64
+ if (Debug.showHitView) this.children.forEach(leafer => { leafer.forceUpdate('surface') })
65
+ }
57
66
 
58
- leafer.once(LayoutEvent.END, () => {
59
- if (!this.ready && this.children.every(child => child.ready)) this.__onReady()
60
- })
67
+ protected __onCreated(): void {
68
+ this.created = this.children.every(child => child.created)
69
+ }
61
70
 
62
- leafer.once(RenderEvent.END, () => {
63
- if (!this.viewReady && this.children.every(child => child.viewReady)) this.__onViewReady()
64
- })
71
+ protected __onReady(): void {
72
+ if (this.children.every(child => child.ready)) super.__onReady()
73
+ }
65
74
 
66
- if (this.realCanvas) {
67
- this.__eventIds.push(
68
- leafer.on_(RenderEvent.END, this.__onChildRenderEnd, this),
69
- )
70
- }
75
+ protected __onViewReady(): void {
76
+ if (this.children.every(child => child.viewReady)) super.__onViewReady()
71
77
  }
72
78
 
73
- public waitViewLoaded(fun: IFunction): void {
74
- const wait = () => { if (this.children.every(item => item.viewLoaded)) Platform.requestRender(fun) }
75
- this.children.forEach(leafer => { leafer.waitViewLoaded(wait) })
76
- if (!this.running) this.start()
79
+ protected __checkViewCompleted(): boolean {
80
+ return this.children.every(item => item.viewCompleted)
77
81
  }
78
82
 
79
83
  protected __onChildRenderEnd(e: RenderEvent): void {
@@ -106,10 +110,11 @@ export class App extends Leafer implements IApp {
106
110
  return config
107
111
  }
108
112
 
109
- public destroy(): void {
110
- this.children.forEach(leafer => { leafer.destroy() })
111
- this.children.length = 0
112
- super.destroy()
113
+ protected __listenChildEvents(leafer: ILeafer): void {
114
+ leafer.once(LayoutEvent.END, () => this.__onReady())
115
+ leafer.once(RenderEvent.START, () => this.__onCreated())
116
+ leafer.once(RenderEvent.END, (e) => this.__onRenderEnd(e))
117
+ if (this.realCanvas) this.__eventIds.push(leafer.on_(RenderEvent.END, this.__onChildRenderEnd, this))
113
118
  }
114
119
 
115
120
  }
package/src/Leafer.ts CHANGED
@@ -1,7 +1,7 @@
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, Platform, PluginManager } from '@leafer/core'
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
3
 
4
- import { ILeaferInputData, ILeaferData, IFunction } from '@leafer-ui/interface'
4
+ import { ILeaferInputData, ILeaferData, IFunction, IUIInputData } 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'
@@ -17,19 +17,21 @@ export class Leafer extends Group implements ILeafer {
17
17
  public get __tag() { return 'Leafer' }
18
18
 
19
19
  @dataProcessor(LeaferData)
20
- public __: ILeaferData
20
+ declare public __: ILeaferData
21
21
 
22
22
  @boundsType()
23
23
  public pixelRatio: number
24
24
 
25
25
  public get isApp(): boolean { return false }
26
+ public get app(): ILeafer { return this.parent || this }
26
27
 
27
- public parent?: App
28
+ declare public parent?: App
28
29
 
29
30
  public running: boolean
31
+ public created: boolean
30
32
  public ready: boolean
31
33
  public viewReady: boolean
32
- public get viewLoaded(): boolean { return this.viewReady && !this.watcher.changed && this.imageManager.tasker.isComplete }
34
+ public viewCompleted: boolean
33
35
 
34
36
  public view: unknown
35
37
 
@@ -45,7 +47,6 @@ export class Leafer extends Group implements ILeafer {
45
47
 
46
48
  public canvasManager: ICanvasManager
47
49
  public hitCanvasManager?: IHitCanvasManager
48
- public imageManager: IImageManager
49
50
 
50
51
  public zoomLayer: ILeaf = this
51
52
  public moveLayer: ILeaf = this
@@ -62,6 +63,7 @@ export class Leafer extends Group implements ILeafer {
62
63
  max: 256
63
64
  },
64
65
  move: {
66
+ holdSpaceKey: true,
65
67
  dragOut: true,
66
68
  autoDistance: 2
67
69
  }
@@ -73,6 +75,11 @@ export class Leafer extends Group implements ILeafer {
73
75
  protected __startTimer: ITimer
74
76
  protected __controllers: IControl[] = []
75
77
 
78
+ protected __readyWait: IFunction[] = []
79
+ protected __viewReadyWait: IFunction[] = []
80
+ protected __viewCompletedWait: IFunction[] = []
81
+ public __nextRenderWait: IFunction[] = []
82
+
76
83
  constructor(userConfig?: ILeaferConfig, data?: ILeaferInputData) {
77
84
  super(data)
78
85
  this.userConfig = userConfig
@@ -111,7 +118,6 @@ export class Leafer extends Group implements ILeafer {
111
118
 
112
119
  this.canvasManager = new CanvasManager()
113
120
  this.hitCanvasManager = new HitCanvasManager()
114
- this.imageManager = new ImageManager(this, config)
115
121
 
116
122
  start = config.start
117
123
  }
@@ -127,6 +133,16 @@ export class Leafer extends Group implements ILeafer {
127
133
  PluginManager.onLeafer(this)
128
134
  }
129
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
+
130
146
  public start(): void {
131
147
  clearTimeout(this.__startTimer)
132
148
  if (!this.running && this.canvas) {
@@ -160,6 +176,10 @@ export class Leafer extends Group implements ILeafer {
160
176
  if (this.viewReady) this.renderer.update()
161
177
  }
162
178
 
179
+ public updateCursor(): void {
180
+ if (this.interaction) this.interaction.updateCursor()
181
+ }
182
+
163
183
  protected __doResize(size: IScreenSizeData): void {
164
184
  if (!this.canvas || this.canvas.isSameSize(size)) return
165
185
  const old = DataHelper.copyAttrs({}, this.canvas, canvasSizeAttrs) as IScreenSizeData
@@ -181,7 +201,6 @@ export class Leafer extends Group implements ILeafer {
181
201
 
182
202
  this.canvasManager = app.canvasManager
183
203
  this.hitCanvasManager = app.hitCanvasManager
184
- this.imageManager = app.imageManager
185
204
  }
186
205
 
187
206
  public __setLeafer(leafer: ILeafer): void {
@@ -195,19 +214,6 @@ export class Leafer extends Group implements ILeafer {
195
214
  this.moveLayer = moveLayer || zoomLayer
196
215
  }
197
216
 
198
- public waitViewLoaded(fun: IFunction): void {
199
- let id: IEventListenerId
200
- const check = () => {
201
- if (this.viewLoaded) {
202
- if (id) this.off_(id)
203
- Platform.requestRender(fun)
204
- }
205
- }
206
- if (!this.running) this.start()
207
- check()
208
- if (!this.viewLoaded) id = this.on_(RenderEvent.AFTER, check)
209
- }
210
-
211
217
  protected __checkAutoLayout(config: ILeaferConfig): void {
212
218
  if (!config.width || !config.height) {
213
219
  this.autoLayout = new AutoBounds(config)
@@ -249,18 +255,74 @@ export class Leafer extends Group implements ILeafer {
249
255
  }
250
256
  }
251
257
 
258
+ protected __onCreated(): void {
259
+ this.created = true
260
+ }
261
+
252
262
  protected __onReady(): void {
253
263
  if (this.ready) return
254
264
  this.ready = true
255
265
  this.emitLeafer(LeaferEvent.BEFORE_READY)
256
266
  this.emitLeafer(LeaferEvent.READY)
257
267
  this.emitLeafer(LeaferEvent.AFTER_READY)
268
+ WaitHelper.run(this.__readyWait)
258
269
  }
259
270
 
260
271
  protected __onViewReady(): void {
261
272
  if (this.viewReady) return
262
273
  this.viewReady = true
263
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
+ }
264
326
  }
265
327
 
266
328
  protected __checkUpdateLayout(): void {
@@ -275,38 +337,51 @@ export class Leafer extends Group implements ILeafer {
275
337
  const runId = Run.start('FirstCreate ' + this.innerName)
276
338
  this.once(LeaferEvent.START, () => Run.end(runId))
277
339
  this.once(LayoutEvent.END, () => this.__onReady())
278
- this.once(RenderEvent.END, () => this.__onViewReady())
279
- this.on(LayoutEvent.CHECK_UPDATE, () => this.__checkUpdateLayout())
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
+ )
280
346
  }
281
347
 
282
348
  protected __removeListenEvents(): void {
283
349
  this.off_(this.__eventIds)
350
+ this.__eventIds.length = 0
284
351
  }
285
352
 
286
353
  public destroy(): void {
287
- if (this.canvas) {
288
- try {
289
- this.stop()
290
- this.emitEvent(new LeaferEvent(LeaferEvent.END, this))
291
- this.__removeListenEvents()
292
-
293
- this.__controllers.forEach(item => item.destroy())
294
- this.__controllers.length = 0
295
-
296
- this.selector.destroy()
297
- this.canvasManager.destroy()
298
- this.hitCanvasManager.destroy()
299
- this.imageManager.destroy()
300
-
301
- this.canvas.destroy()
302
- this.canvas = null
303
-
304
- this.config = this.userConfig = this.view = null
305
-
306
- super.destroy()
307
- } catch (e) {
308
- debug.error(e)
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
+ }
309
383
  }
310
- }
384
+ })
385
+
311
386
  }
312
387
  }
@@ -0,0 +1,101 @@
1
+ import { IApp, ILeaferConfig, ILeaferCanvas, IRenderOptions, IResizeEvent, ILeafer, IRenderer, IWatcher, ILayouter, ISelector, IInteraction, ICanvasManager, IHitCanvasManager, ILeaf, ITransformEventData, IAutoBounds, IEventListenerId, ITimer, IControl, IScreenSizeData, __Value } from '@leafer/interface';
2
+ import { RenderEvent } from '@leafer/core';
3
+ import { ILeaferData, IFunction, ILeaferInputData, IUIInputData } from '@leafer-ui/interface';
4
+ 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
+ }
28
+
29
+ declare class Leafer extends Group implements ILeafer {
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 };