@leafer-ui/app 1.0.0-beta → 1.0.0-beta.10

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-beta",
3
+ "version": "1.0.0-beta.10",
4
4
  "description": "@leafer-ui/app",
5
5
  "author": "Chao (Leafer) Wan",
6
6
  "license": "MIT",
@@ -19,12 +19,13 @@
19
19
  "leaferjs"
20
20
  ],
21
21
  "dependencies": {
22
- "@leafer/core": "1.0.0-beta",
23
- "@leafer-ui/display": "1.0.0-beta",
24
- "@leafer-ui/data": "1.0.0-beta"
22
+ "@leafer/core": "1.0.0-beta.10",
23
+ "@leafer-ui/display": "1.0.0-beta.10",
24
+ "@leafer-ui/type": "1.0.0-beta.10",
25
+ "@leafer-ui/data": "1.0.0-beta.10"
25
26
  },
26
27
  "devDependencies": {
27
- "@leafer/interface": "1.0.0-beta",
28
- "@leafer-ui/interface": "1.0.0-beta"
28
+ "@leafer/interface": "1.0.0-beta.10",
29
+ "@leafer-ui/interface": "1.0.0-beta.10"
29
30
  }
30
31
  }
package/src/App.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { ILeaferConfig, IResizeEvent, ILeaferCanvas, IRenderOptions, IApp, __Value } from '@leafer/interface'
2
- import { DataHelper, Debug, LayoutEvent, PropertyEvent, RenderEvent, canvasSizeAttrs, registerUI } from '@leafer/core'
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'
3
3
 
4
4
  import { Leafer } from './Leafer'
5
5
 
@@ -70,6 +70,12 @@ export class App extends Leafer implements IApp {
70
70
  }
71
71
  }
72
72
 
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()
77
+ }
78
+
73
79
  protected __onChildRenderEnd(e: RenderEvent): void {
74
80
  this.renderer.addBlock(e.renderBounds)
75
81
  if (this.viewReady) this.renderer.update()
@@ -90,17 +96,14 @@ export class App extends Leafer implements IApp {
90
96
 
91
97
  protected __getChildConfig(userConfig?: ILeaferConfig): ILeaferConfig {
92
98
  let config = { ...this.config }
99
+ config.hittable = config.realCanvas = undefined
93
100
  if (userConfig) DataHelper.assign(config, userConfig)
94
- config.view = this.realCanvas ? undefined : this.view
95
- config.fill = config.hittable = config.realCanvas = undefined
101
+
102
+ // reset
96
103
  if (this.autoLayout) DataHelper.copyAttrs(config, this, canvasSizeAttrs)
104
+ config.view = this.realCanvas ? undefined : this.view
105
+ config.fill = undefined
97
106
  return config
98
107
  }
99
108
 
100
- public destory(): void {
101
- this.children.forEach(leafer => { leafer.destory() })
102
- this.children.length = 0
103
- super.destory()
104
- }
105
-
106
109
  }
package/src/Leafer.ts CHANGED
@@ -1,12 +1,12 @@
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'
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, Platform, PluginManager, AnimateEvent } from '@leafer/core'
3
3
 
4
- import { ILeaferInputData, ILeaferData } from '@leafer-ui/interface'
4
+ import { ILeaferInputData, ILeaferData, IFunction } from '@leafer-ui/interface'
5
+ import { LeaferTypeCreator } from '@leafer-ui/type'
5
6
  import { LeaferData } from '@leafer-ui/data'
6
7
  import { Group } from '@leafer-ui/display'
7
8
 
8
9
  import { App } from './App'
9
- import { LeaferType } from './type/LeaferType'
10
10
 
11
11
 
12
12
  const debug = Debug.get('Leafer')
@@ -29,6 +29,7 @@ export class Leafer extends Group implements ILeafer {
29
29
  public running: boolean
30
30
  public ready: boolean
31
31
  public viewReady: boolean
32
+ public get viewLoaded(): boolean { return this.viewReady && !this.watcher.changed && ImageManager.isComplete }
32
33
 
33
34
  public view: unknown
34
35
 
@@ -44,7 +45,6 @@ export class Leafer extends Group implements ILeafer {
44
45
 
45
46
  public canvasManager: ICanvasManager
46
47
  public hitCanvasManager?: IHitCanvasManager
47
- public imageManager: IImageManager
48
48
 
49
49
  public zoomLayer: ILeaf = this
50
50
  public moveLayer: ILeaf = this
@@ -55,6 +55,7 @@ export class Leafer extends Group implements ILeafer {
55
55
  type: 'design',
56
56
  start: true,
57
57
  hittable: true,
58
+ smooth: true,
58
59
  zoom: {
59
60
  min: 0.02,
60
61
  max: 256
@@ -74,7 +75,7 @@ export class Leafer extends Group implements ILeafer {
74
75
  constructor(userConfig?: ILeaferConfig, data?: ILeaferInputData) {
75
76
  super(data)
76
77
  this.userConfig = userConfig
77
- if (userConfig?.view) this.init(userConfig)
78
+ if (userConfig && (userConfig.view || userConfig.width)) this.init(userConfig)
78
79
  }
79
80
 
80
81
  public init(userConfig?: ILeaferConfig, parentApp?: IApp): void {
@@ -85,7 +86,7 @@ export class Leafer extends Group implements ILeafer {
85
86
 
86
87
  let start: boolean
87
88
  const { config } = this
88
- LeaferType.run(config.type, this)
89
+ LeaferTypeCreator.run(config.type, this)
89
90
 
90
91
  // render / layout
91
92
  this.canvas = Creator.canvas(config)
@@ -109,7 +110,6 @@ export class Leafer extends Group implements ILeafer {
109
110
 
110
111
  this.canvasManager = new CanvasManager()
111
112
  this.hitCanvasManager = new HitCanvasManager()
112
- this.imageManager = new ImageManager(this, config)
113
113
 
114
114
  start = config.start
115
115
  }
@@ -121,6 +121,8 @@ export class Leafer extends Group implements ILeafer {
121
121
  this.__listenEvents()
122
122
 
123
123
  if (start) this.__startTimer = setTimeout(this.start.bind(this))
124
+
125
+ PluginManager.onLeafer(this)
124
126
  }
125
127
 
126
128
  public start(): void {
@@ -147,6 +149,10 @@ export class Leafer extends Group implements ILeafer {
147
149
  Object.keys(data).forEach(key => (this as any)[key] = data[key])
148
150
  }
149
151
 
152
+ public forceLayout(): void {
153
+ this.__layout.checkUpdate(true)
154
+ }
155
+
150
156
  public forceFullRender(): void {
151
157
  this.renderer.addBlock(this.canvas.bounds)
152
158
  if (this.viewReady) this.renderer.update()
@@ -173,7 +179,6 @@ export class Leafer extends Group implements ILeafer {
173
179
 
174
180
  this.canvasManager = app.canvasManager
175
181
  this.hitCanvasManager = app.hitCanvasManager
176
- this.imageManager = app.imageManager
177
182
  }
178
183
 
179
184
  public __setLeafer(leafer: ILeafer): void {
@@ -187,6 +192,19 @@ export class Leafer extends Group implements ILeafer {
187
192
  this.moveLayer = moveLayer || zoomLayer
188
193
  }
189
194
 
195
+ public waitViewLoaded(fun: IFunction): void {
196
+ let id: IEventListenerId
197
+ const check = () => {
198
+ if (this.viewLoaded) {
199
+ if (id) this.off_(id)
200
+ Platform.requestRender(fun)
201
+ }
202
+ }
203
+ if (!this.running) this.start()
204
+ check()
205
+ if (!this.viewLoaded) id = this.on_(AnimateEvent.FRAME, check)
206
+ }
207
+
190
208
  protected __checkAutoLayout(config: ILeaferConfig): void {
191
209
  if (!config.width || !config.height) {
192
210
  this.autoLayout = new AutoBounds(config)
@@ -201,7 +219,7 @@ export class Leafer extends Group implements ILeafer {
201
219
  } else if (attrName === 'fill') {
202
220
  this.__changeFill(newValue as string)
203
221
  } else if (attrName === 'hittable') {
204
- this.canvas.setHittable(newValue as boolean)
222
+ this.canvas.hittable = newValue as boolean
205
223
  }
206
224
  }
207
225
  super.__setAttr(attrName, newValue)
@@ -222,7 +240,7 @@ export class Leafer extends Group implements ILeafer {
222
240
  protected __changeFill(newValue: string): void {
223
241
  this.config.fill = newValue as string
224
242
  if (this.canvas.allowBackgroundColor) {
225
- this.canvas.setBackgroundColor(newValue as string)
243
+ this.canvas.backgroundColor = newValue as string
226
244
  } else {
227
245
  this.forceFullRender()
228
246
  }
@@ -262,30 +280,37 @@ export class Leafer extends Group implements ILeafer {
262
280
  this.off_(this.__eventIds)
263
281
  }
264
282
 
265
- public destory(): void {
266
- if (this.canvas) {
267
- try {
268
- this.stop()
269
- this.emitEvent(new LeaferEvent(LeaferEvent.END, this))
270
- this.__removeListenEvents()
283
+ public destroy(): void {
284
+ setTimeout(() => {
285
+ if (this.canvas) {
286
+ try {
287
+ this.stop()
288
+ this.emitEvent(new LeaferEvent(LeaferEvent.END, this))
289
+ this.__removeListenEvents()
271
290
 
272
- this.__controllers.forEach(item => item.destroy())
273
- this.__controllers.length = 0
291
+ this.__controllers.forEach(item => {
292
+ if (!(this.parent && item === this.interaction)) item.destroy()
293
+ })
294
+ this.__controllers.length = 0
274
295
 
275
- this.selector.destroy()
276
- this.canvasManager.destory()
277
- this.hitCanvasManager.destory()
278
- this.imageManager.destory()
296
+ if (!this.parent) {
297
+ this.selector.destroy()
298
+ this.canvasManager.destroy()
299
+ this.hitCanvasManager.destroy()
300
+ }
279
301
 
280
- this.canvas.destroy()
281
- this.canvas = null
302
+ this.canvas.destroy()
282
303
 
283
- this.config = this.userConfig = this.view = null
304
+ this.config = this.userConfig = this.canvas = this.view = null
305
+ this.selector = this.interaction = this.canvasManager = this.hitCanvasManager = null
284
306
 
285
- super.destroy()
286
- } catch (e) {
287
- debug.error(e)
307
+ super.destroy()
308
+
309
+ setTimeout(() => { ImageManager.clearRecycled() }, 100)
310
+ } catch (e) {
311
+ debug.error(e)
312
+ }
288
313
  }
289
- }
314
+ }, 0)
290
315
  }
291
316
  }
@@ -1,37 +0,0 @@
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)
@@ -1,19 +0,0 @@
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 DELETED
@@ -1,7 +0,0 @@
1
- import { ILeafer } from '@leafer/interface'
2
-
3
-
4
- export function user(leafer: ILeafer): void {
5
- const { config } = leafer
6
- config.move.dragOut = false
7
- }