@leafer/display 1.0.0-rc.9 → 1.0.1

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/display",
3
- "version": "1.0.0-rc.9",
3
+ "version": "1.0.1",
4
4
  "description": "@leafer/display",
5
5
  "author": "Chao (Leafer) Wan",
6
6
  "license": "MIT",
@@ -22,16 +22,16 @@
22
22
  "leaferjs"
23
23
  ],
24
24
  "dependencies": {
25
- "@leafer/math": "1.0.0-rc.9",
26
- "@leafer/data": "1.0.0-rc.9",
27
- "@leafer/layout": "1.0.0-rc.9",
28
- "@leafer/display-module": "1.0.0-rc.9",
29
- "@leafer/event": "1.0.0-rc.9",
30
- "@leafer/decorator": "1.0.0-rc.9",
31
- "@leafer/helper": "1.0.0-rc.9",
32
- "@leafer/platform": "1.0.0-rc.9"
25
+ "@leafer/math": "1.0.1",
26
+ "@leafer/data": "1.0.1",
27
+ "@leafer/layout": "1.0.1",
28
+ "@leafer/display-module": "1.0.1",
29
+ "@leafer/event": "1.0.1",
30
+ "@leafer/decorator": "1.0.1",
31
+ "@leafer/helper": "1.0.1",
32
+ "@leafer/platform": "1.0.1"
33
33
  },
34
34
  "devDependencies": {
35
- "@leafer/interface": "1.0.0-rc.9"
35
+ "@leafer/interface": "1.0.1"
36
36
  }
37
37
  }
package/src/Branch.ts CHANGED
@@ -3,7 +3,7 @@ import { ChildEvent } from '@leafer/event'
3
3
  import { BoundsHelper } from '@leafer/math'
4
4
  import { BranchHelper, LeafBoundsHelper, WaitHelper } from '@leafer/helper'
5
5
  import { useModule } from '@leafer/decorator'
6
- import { BranchRender, LeafMask } from '@leafer/display-module'
6
+ import { BranchRender } from '@leafer/display-module'
7
7
 
8
8
  import { Leaf } from './Leaf'
9
9
 
@@ -14,14 +14,7 @@ const { localBoxBounds, localStrokeBounds, localRenderBounds, maskLocalBoxBounds
14
14
 
15
15
 
16
16
  @useModule(BranchRender)
17
- @useModule(LeafMask)
18
- export class Branch extends Leaf {
19
-
20
- constructor() {
21
- super()
22
- this.isBranch = true
23
- this.children = []
24
- }
17
+ export class Branch extends Leaf { // tip: rewrited Group
25
18
 
26
19
  // overwrite
27
20
 
@@ -70,12 +63,16 @@ export class Branch extends Leaf {
70
63
  }
71
64
 
72
65
  public add(child: ILeaf, index?: number): void {
66
+ if (child === this) return
67
+
73
68
  if (child.parent) child.parent.remove(child)
74
69
  child.parent = this
75
70
 
76
71
  index === undefined ? this.children.push(child) : this.children.splice(index, 0, child)
77
72
  if (child.isBranch) this.__.__childBranchNumber = (this.__.__childBranchNumber || 0) + 1
78
- child.__layout.boundsChanged || child.__layout.matrixChange() // layouted(removed), need update
73
+
74
+ child.__layout.boxChanged || child.__layout.boxChange() // layouted(removed), need update
75
+ child.__layout.matrixChanged || child.__layout.matrixChange() // layouted(removed), need update
79
76
 
80
77
  if (child.__parentWait) WaitHelper.run(child.__parentWait)
81
78
 
@@ -91,7 +88,7 @@ export class Branch extends Leaf {
91
88
  children.forEach(child => this.add(child))
92
89
  }
93
90
 
94
- public remove(child?: Leaf, destroy?: boolean): void {
91
+ public remove(child?: ILeaf, destroy?: boolean): void {
95
92
  if (child) {
96
93
  const index = this.children.indexOf(child)
97
94
  if (index > -1) {
@@ -119,6 +116,10 @@ export class Branch extends Leaf {
119
116
  }
120
117
  }
121
118
 
119
+ public clear(): void {
120
+ this.removeAll(true)
121
+ }
122
+
122
123
  protected __preRemove(): void {
123
124
  if (this.__hasMask) this.__updateMask()
124
125
  if (this.__hasEraser) this.__updateEraser()
package/src/Leaf.ts CHANGED
@@ -1,21 +1,22 @@
1
- import { ILeaferBase, ILeaf, ILeafInputData, ILeafData, ILeaferCanvas, IRenderOptions, IBoundsType, ILocationType, IMatrixWithBoundsData, ILayoutBoundsData, IValue, ILeafLayout, InnerId, IHitCanvas, IRadiusPointData, IEventListenerMap, IEventListener, IEventListenerOptions, IEventListenerId, IEvent, IObject, IFunction, IPointData, IBoundsData, IBranch, IMatrixWithLayoutData, IFindMethod, ILayoutAttr, IMatrixData, IAttrDecorator } from '@leafer/interface'
2
- import { IncrementId, MatrixHelper, PointHelper } from '@leafer/math'
1
+ import { ILeaferBase, ILeaf, ILeafInputData, ILeafData, ILeaferCanvas, IRenderOptions, IBoundsType, ILocationType, IMatrixWithBoundsData, ILayoutBoundsData, IValue, ILeafLayout, InnerId, IHitCanvas, IRadiusPointData, IEventListenerMap, IEventListener, IEventListenerId, IEvent, IObject, IFunction, IPointData, IBoundsData, IBranch, IFindMethod, IMatrixData, IAttrDecorator, IMatrixWithBoundsScaleData, IMatrixWithScaleData, IAlign, IJSONOptions, IEventMap, IEventOption, IAxis } from '@leafer/interface'
2
+ import { BoundsHelper, IncrementId, MatrixHelper, PointHelper } from '@leafer/math'
3
3
  import { LeafData } from '@leafer/data'
4
4
  import { LeafLayout } from '@leafer/layout'
5
- import { LeafDataProxy, LeafMatrix, LeafBounds, LeafHit, LeafEventer, LeafRender } from '@leafer/display-module'
5
+ import { LeafDataProxy, LeafMatrix, LeafBounds, LeafEventer, LeafRender } from '@leafer/display-module'
6
6
  import { boundsType, useModule, defineDataProcessor } from '@leafer/decorator'
7
7
  import { LeafHelper, WaitHelper } from '@leafer/helper'
8
+ import { ChildEvent } from '@leafer/event'
8
9
 
9
10
 
10
11
  const { LEAF, create } = IncrementId
11
- const { toInnerPoint, toOuterPoint } = MatrixHelper
12
- const { tempToOuterOf, copy } = PointHelper
13
- const { moveLocal, zoomOfLocal, rotateOfLocal, skewOfLocal, transform, setTransform, drop } = LeafHelper
12
+ const { toInnerPoint, toOuterPoint, multiplyParent } = MatrixHelper
13
+ const { toOuterOf } = BoundsHelper
14
+ const { copy } = PointHelper
15
+ const { moveLocal, zoomOfLocal, rotateOfLocal, skewOfLocal, moveWorld, zoomOfWorld, rotateOfWorld, skewOfWorld, transform, transformWorld, setTransform, getFlipTransform, getLocalOrigin, getRelativeWorld, drop } = LeafHelper
14
16
 
15
17
  @useModule(LeafDataProxy)
16
18
  @useModule(LeafMatrix)
17
19
  @useModule(LeafBounds)
18
- @useModule(LeafHit)
19
20
  @useModule(LeafEventer)
20
21
  @useModule(LeafRender)
21
22
  export class Leaf implements ILeaf {
@@ -34,27 +35,31 @@ export class Leaf implements ILeaf {
34
35
  public leafer?: ILeaferBase
35
36
  public parent?: ILeaf
36
37
 
37
- public isLeafer: boolean
38
- public isBranch: boolean
39
- public isBranchLeaf: boolean
38
+ public get isLeafer(): boolean { return false }
39
+ public get isBranch(): boolean { return false }
40
+ public get isBranchLeaf(): boolean { return false }
40
41
 
41
42
  public __: ILeafData
42
43
  public __layout: ILeafLayout
43
44
 
44
- public __world: IMatrixWithLayoutData
45
+ public __world: IMatrixWithBoundsScaleData
45
46
  public __local?: IMatrixWithBoundsData // and localStrokeBounds? localRenderBounds?
46
47
 
48
+ public __nowWorld?: IMatrixWithBoundsScaleData // use __world or __cameraWorld render
49
+ public __cameraWorld?: IMatrixWithBoundsScaleData // use camera matrix render
50
+
47
51
  public get __localMatrix(): IMatrixData { return this.__local || this.__layout }
48
- public get __localBounds(): IBoundsData { return this.__local || this.__ as IBoundsData }
52
+ public get __localBoxBounds(): IBoundsData { return this.__local || this.__layout }
49
53
 
50
54
  public __worldOpacity: number
51
55
 
52
56
  // now transform
53
- public get worldTransform(): IMatrixWithLayoutData { return this.__layout.getTransform('world') as IMatrixWithLayoutData }
54
- public get localTransform(): IMatrixWithBoundsData { return this.__layout.getTransform('local') as IMatrixWithBoundsData }
57
+ public get worldTransform(): IMatrixWithScaleData { return this.__layout.getTransform('world') as IMatrixWithScaleData }
58
+ public get localTransform(): IMatrixData { return this.__layout.getTransform('local') }
55
59
 
56
60
  // now bounds
57
61
  public get boxBounds(): IBoundsData { return this.getBounds('box', 'inner') }
62
+ public get renderBounds(): IBoundsData { return this.getBounds('render', 'inner') }
58
63
  public get worldBoxBounds(): IBoundsData { return this.getBounds('box') }
59
64
  public get worldStrokeBounds(): IBoundsData { return this.getBounds('stroke') }
60
65
  public get worldRenderBounds(): IBoundsData { return this.getBounds('render') }
@@ -74,8 +79,13 @@ export class Leaf implements ILeaf {
74
79
 
75
80
  public get __onlyHitMask(): boolean { return this.__hasMask && !this.__.hitChildren }
76
81
  public get __ignoreHitWorld(): boolean { return (this.__hasMask || this.__hasEraser) && this.__.hitChildren }
82
+ public get __inLazyBounds(): boolean { const { leafer } = this; return leafer && leafer.created && leafer.lazyBounds.hit(this.__world) }
83
+
84
+ public get pathInputed(): boolean { return this.__.__pathInputed as unknown as boolean }
77
85
 
78
86
  // event
87
+ public set event(map: IEventMap) { let event; for (let key in map) event = map[key], event instanceof Array ? this.on(key, event[0], event[1]) : this.on(key, event) }
88
+
79
89
  public __captureMap?: IEventListenerMap
80
90
  public __bubbleMap?: IEventListenerMap
81
91
 
@@ -99,7 +109,7 @@ export class Leaf implements ILeaf {
99
109
 
100
110
  public reset(data?: ILeafInputData): void {
101
111
 
102
- this.__world = { a: 1, b: 0, c: 0, d: 1, e: 0, f: 0, x: 0, y: 0, width: 0, height: 0, scaleX: 1, scaleY: 1, rotation: 0, skewX: 0, skewY: 0 }
112
+ this.__world = { a: 1, b: 0, c: 0, d: 1, e: 0, f: 0, x: 0, y: 0, width: 0, height: 0, scaleX: 1, scaleY: 1 }
103
113
  if (data !== null) this.__local = { a: 1, b: 0, c: 0, d: 1, e: 0, f: 0, x: 0, y: 0, width: 0, height: 0 }
104
114
 
105
115
  this.__worldOpacity = 1
@@ -108,7 +118,10 @@ export class Leaf implements ILeaf {
108
118
  this.__layout = new this.__LayoutProcessor(this)
109
119
 
110
120
  if (this.__level) this.resetCustom()
111
- if (data) data.children ? this.set(data) : Object.assign(this, data)
121
+ if (data) {
122
+ if ((data as ILeaf).__) data = (data as ILeaf).toJSON()
123
+ data.children ? this.set(data) : Object.assign(this, data)
124
+ }
112
125
  }
113
126
 
114
127
  public resetCustom(): void {
@@ -117,16 +130,22 @@ export class Leaf implements ILeaf {
117
130
  }
118
131
 
119
132
 
120
- public waitParent(item: IFunction): void {
133
+ public waitParent(item: IFunction, bind?: IObject): void {
134
+ if (bind) item = item.bind(bind)
121
135
  this.parent ? item() : (this.__parentWait ? this.__parentWait.push(item) : this.__parentWait = [item])
122
136
  }
123
137
 
124
- public waitLeafer(item: IFunction): void {
138
+ public waitLeafer(item: IFunction, bind?: IObject): void {
139
+ if (bind) item = item.bind(bind)
125
140
  this.leafer ? item() : (this.__leaferWait ? this.__leaferWait.push(item) : this.__leaferWait = [item])
126
141
  }
127
142
 
128
- public nextRender(item: IFunction): void {
129
- this.leafer ? this.leafer.nextRender(item) : this.waitLeafer(() => this.leafer.nextRender(item))
143
+ public nextRender(item: IFunction, bind?: IObject, off?: 'off'): void {
144
+ this.leafer ? this.leafer.nextRender(item, bind, off) : this.waitLeafer(() => this.leafer.nextRender(item, bind, off))
145
+ }
146
+
147
+ public removeNextRender(item: IFunction): void {
148
+ this.nextRender(item, null, 'off')
130
149
  }
131
150
 
132
151
  public __bindLeafer(leafer: ILeaferBase | null): void {
@@ -155,19 +174,31 @@ export class Leaf implements ILeaf {
155
174
  // data
156
175
 
157
176
  public set(_data: IObject): void { }
158
- public get(): ILeafInputData { return undefined }
177
+ public get(_name?: string): ILeafInputData | IValue { return undefined }
178
+
179
+ public setAttr(name: string, value: any): void { (this as IObject)[name] = value }
180
+ public getAttr(name: string): any { return (this as IObject)[name] }
159
181
 
160
- public toJSON(): IObject {
161
- return this.__.__getInputData()
182
+ public getComputedAttr(name: string): any { return (this.__ as IObject)[name] }
183
+
184
+ public toJSON(options?: IJSONOptions): IObject {
185
+ if (options) this.__layout.update()
186
+ return this.__.__getInputData(null, options)
162
187
  }
163
188
 
164
- public toString(): string {
165
- return JSON.stringify(this.toJSON())
189
+ public toString(options?: IJSONOptions): string {
190
+ return JSON.stringify(this.toJSON(options))
166
191
  }
167
192
 
193
+ public toSVG(): string { return undefined }
194
+
195
+ public __SVG(_data: IObject): void { }
196
+
197
+ public toHTML(): string { return undefined }
198
+
168
199
  // LeafDataProxy rewrite
169
200
 
170
- public __setAttr(_attrName: string, _newValue: IValue): void { }
201
+ public __setAttr(_attrName: string, _newValue: IValue): boolean { return true }
171
202
 
172
203
  public __getAttr(_attrName: string): IValue { return undefined }
173
204
 
@@ -182,10 +213,25 @@ export class Leaf implements ILeaf {
182
213
 
183
214
  public find(_condition: number | string | IFindMethod, _options?: any): ILeaf[] { return undefined }
184
215
 
185
- public findOne(_condition: number | string | IFindMethod, _options?: any): ILeaf { return undefined }
216
+ public findTag(_tag: string | string[]): ILeaf[] { return undefined }
217
+
218
+ public findOne(_condition: number | string | IFindMethod, _options?: any): ILeaf | undefined { return undefined }
219
+
220
+ public findId(_id: number | string): ILeaf | undefined { return undefined }
221
+
222
+ // ---
223
+
224
+
225
+ // state
226
+
227
+ public focus(_value?: boolean): void { }
186
228
 
187
229
  // ---
188
230
 
231
+ public updateLayout(): void {
232
+ this.__layout.update()
233
+ }
234
+
189
235
  public forceUpdate(attrName?: string): void {
190
236
  if (attrName === undefined) attrName = 'width'
191
237
  else if (attrName === 'surface') attrName = 'blendMode'
@@ -194,11 +240,10 @@ export class Leaf implements ILeaf {
194
240
  (this as any)[attrName] = value
195
241
  }
196
242
 
197
- public updateLayout(): void {
198
- this.__layout.update()
243
+ public forceRender(_bounds?: IBoundsData): void {
244
+ this.forceUpdate('surface')
199
245
  }
200
246
 
201
-
202
247
  // LeafMatrix rewrite
203
248
 
204
249
  public __updateWorldMatrix(): void { }
@@ -224,12 +269,17 @@ export class Leaf implements ILeaf {
224
269
 
225
270
  public __updateBoxBounds(): void { }
226
271
 
272
+ public __updateContentBounds(): void { }
273
+
227
274
  public __updateStrokeBounds(): void { }
228
275
 
229
276
  public __updateRenderBounds(): void { }
230
277
 
231
278
 
232
279
  public __updateAutoLayout(): void { }
280
+
281
+ public __updateFlowLayout(): void { }
282
+
233
283
  public __updateNaturalSize(): void { }
234
284
 
235
285
 
@@ -242,28 +292,49 @@ export class Leaf implements ILeaf {
242
292
  // ---
243
293
 
244
294
 
245
- // LeafMask rewrite
295
+ public __updateEraser(value?: boolean): void {
296
+ this.__hasEraser = value ? true : this.children.some(item => item.__.eraser)
297
+ }
246
298
 
247
- public __updateEraser(_value?: boolean): void { }
299
+ public __renderEraser(canvas: ILeaferCanvas, options: IRenderOptions): void { // path eraser
300
+ canvas.save()
301
+ this.__clip(canvas, options)
302
+ const { renderBounds: r } = this.__layout
303
+ canvas.clearRect(r.x, r.y, r.width, r.height)
304
+ canvas.restore()
305
+ }
248
306
 
249
- public __updateMask(_value?: boolean): void { }
307
+ public __updateMask(value?: boolean): void {
308
+ this.__hasMask = value ? true : this.children.some(item => item.__.mask)
309
+ }
250
310
 
251
- public __renderMask(_canvas: ILeaferCanvas, _content: ILeaferCanvas, _mask: ILeaferCanvas, _recycle?: boolean): void { }
311
+ // LeafMask rewrite
312
+
313
+ public __renderMask(_canvas: ILeaferCanvas, _options: IRenderOptions): void { }
252
314
 
253
- public __removeMask(_child?: ILeaf): void { }
254
315
 
255
316
  // ---
256
317
 
257
318
 
258
319
  // convert
259
320
 
260
- public getWorld(attrName: ILayoutAttr): number {
261
- this.__layout.update()
262
- if (attrName === 'x') return this.__world.e
263
- if (attrName === 'y') return this.__world.f
264
- return this.__world[attrName]
321
+ public __getNowWorld(options: IRenderOptions): IMatrixWithBoundsScaleData {
322
+ if (options.matrix) {
323
+ if (!this.__cameraWorld) this.__cameraWorld = {} as IMatrixWithBoundsScaleData
324
+ const cameraWorld = this.__cameraWorld
325
+ multiplyParent(this.__world, options.matrix, cameraWorld, undefined, this.__world)
326
+ toOuterOf(this.__layout.renderBounds, cameraWorld, cameraWorld)
327
+ return cameraWorld
328
+ } else {
329
+ return this.__world
330
+ }
331
+ }
332
+
333
+ public getTransform(relative?: ILocationType | ILeaf): IMatrixData {
334
+ return this.__layout.getTransform(relative || 'local')
265
335
  }
266
336
 
337
+
267
338
  public getBounds(type?: IBoundsType, relative?: ILocationType | ILeaf): IBoundsData {
268
339
  return this.__layout.getBounds(type, relative)
269
340
  }
@@ -277,6 +348,14 @@ export class Leaf implements ILeaf {
277
348
  }
278
349
 
279
350
 
351
+ public getWorldBounds(inner: IBoundsData, relative?: ILeaf, change?: boolean): IBoundsData {
352
+ const matrix = relative ? getRelativeWorld(this, relative) : this.worldTransform
353
+ const to = change ? inner : {} as IBoundsData
354
+ toOuterOf(inner, matrix, to)
355
+ return to
356
+ }
357
+
358
+
280
359
  public worldToLocal(world: IPointData, to?: IPointData, distance?: boolean, relative?: ILeaf): void {
281
360
  if (this.parent) {
282
361
  this.parent.worldToInner(world, to, distance, relative)
@@ -340,8 +419,18 @@ export class Leaf implements ILeaf {
340
419
  return point
341
420
  }
342
421
 
422
+ public getPagePoint(world: IPointData, relative?: ILeaf, distance?: boolean, change?: boolean): IPointData {
423
+ const layer = this.leafer ? this.leafer.zoomLayer : this
424
+ return layer.getInnerPoint(world, relative, distance, change)
425
+ }
426
+
427
+ public getWorldPointByPage(page: IPointData, relative?: ILeaf, distance?: boolean, change?: boolean): IPointData {
428
+ const layer = this.leafer ? this.leafer.zoomLayer : this
429
+ return layer.getWorldPoint(page, relative, distance, change)
430
+ }
431
+
343
432
 
344
- // transform
433
+ // transform
345
434
 
346
435
  public setTransform(matrix: IMatrixData, resize?: boolean): void {
347
436
  setTransform(this, matrix, resize)
@@ -351,47 +440,74 @@ export class Leaf implements ILeaf {
351
440
  transform(this, matrix, resize)
352
441
  }
353
442
 
354
-
355
- public move(x: number, y?: number): void {
443
+ public move(x: number | IPointData, y?: number): void {
356
444
  moveLocal(this, x, y)
357
445
  }
358
446
 
359
- public scaleOf(origin: IPointData, scaleX: number, scaleY?: number, resize?: boolean): void {
360
- zoomOfLocal(this, tempToOuterOf(origin, this.localTransform), scaleX, scaleY, resize)
447
+ public scaleOf(origin: IPointData | IAlign, scaleX: number, scaleY?: number, resize?: boolean): void {
448
+ zoomOfLocal(this, getLocalOrigin(this, origin), scaleX, scaleY, resize)
361
449
  }
362
450
 
363
- public rotateOf(origin: IPointData, rotation: number): void {
364
- rotateOfLocal(this, tempToOuterOf(origin, this.localTransform), rotation)
451
+ public rotateOf(origin: IPointData | IAlign, rotation: number): void {
452
+ rotateOfLocal(this, getLocalOrigin(this, origin), rotation)
365
453
  }
366
454
 
367
- public skewOf(origin: IPointData, skewX: number, skewY?: number, resize?: boolean): void {
368
- skewOfLocal(this, tempToOuterOf(origin, this.localTransform), skewX, skewY, resize)
455
+ public skewOf(origin: IPointData | IAlign, skewX: number, skewY?: number, resize?: boolean): void {
456
+ skewOfLocal(this, getLocalOrigin(this, origin), skewX, skewY, resize)
369
457
  }
370
458
 
459
+ public transformWorld(worldTransform?: IMatrixData, resize?: boolean): void {
460
+ transformWorld(this, worldTransform, resize)
461
+ }
371
462
 
372
- public scaleResize(scaleX: number, scaleY = scaleX, noResize?: boolean): void {
373
- const data = this as ILeaf
374
- if (noResize) {
375
- data.scaleX *= scaleX
376
- data.scaleY *= scaleY
377
- } else {
378
- if (scaleX < 0) data.scaleX *= -1, scaleX = -scaleX
379
- if (scaleY < 0) data.scaleY *= -1, scaleY = -scaleY
380
- this.__scaleResize(scaleX, scaleY)
381
- }
463
+ public moveWorld(x: number | IPointData, y?: number): void {
464
+ moveWorld(this, x, y)
465
+ }
466
+
467
+ public scaleOfWorld(worldOrigin: IPointData, scaleX: number, scaleY?: number, resize?: boolean): void {
468
+ zoomOfWorld(this, worldOrigin, scaleX, scaleY, resize)
382
469
  }
383
470
 
384
- public __scaleResize(scaleX: number, scaleY: number): void {
385
- if (scaleX !== 1) (this as ILeaf).width *= scaleX
386
- if (scaleY !== 1) (this as ILeaf).height *= scaleY // Text auto height
471
+ public rotateOfWorld(worldOrigin: IPointData, rotation: number): void {
472
+ rotateOfWorld(this, worldOrigin, rotation)
387
473
  }
388
474
 
389
- // LeafHit rewrite
475
+ public skewOfWorld(worldOrigin: IPointData, skewX: number, skewY?: number, resize?: boolean): void {
476
+ skewOfWorld(this, worldOrigin, skewX, skewY, resize)
477
+ }
478
+
479
+ public flip(axis: IAxis): void {
480
+ transform(this, getFlipTransform(this, axis))
481
+ }
482
+
483
+
484
+ // @leafer-in/resize rewrite
485
+
486
+ public scaleResize(scaleX: number, scaleY = scaleX, _noResize?: boolean): void {
487
+ (this as ILeaf).scaleX *= scaleX;
488
+ (this as ILeaf).scaleY *= scaleY
489
+ }
490
+
491
+ public __scaleResize(_scaleX: number, _scaleY: number): void { }
492
+
493
+
494
+ public resizeWidth(_width: number): void { }
495
+
496
+ public resizeHeight(_height: number): void { }
497
+
498
+
499
+ // @leafer-ui/hit LeafHit rewrite
390
500
 
391
501
  public __hitWorld(_point: IRadiusPointData): boolean { return true }
392
502
 
393
503
  public __hit(_local: IRadiusPointData): boolean { return true }
394
504
 
505
+ public __hitFill(_inner: IRadiusPointData): boolean { return true }
506
+
507
+ public __hitStroke(_inner: IRadiusPointData, _strokeWidth: number): boolean { return true }
508
+
509
+ public __hitPixel(_inner: IRadiusPointData): boolean { return true }
510
+
395
511
  public __drawHitPath(_canvas: ILeaferCanvas): void { }
396
512
 
397
513
  public __updateHitCanvas(): void { }
@@ -407,7 +523,10 @@ export class Leaf implements ILeaf {
407
523
 
408
524
  public __draw(_canvas: ILeaferCanvas, _options: IRenderOptions): void { }
409
525
 
410
- public __renderShape(_canvas: ILeaferCanvas, _options: IRenderOptions): void { }
526
+
527
+ public __clip(_canvas: ILeaferCanvas, _options: IRenderOptions): void { }
528
+
529
+ public __renderShape(_canvas: ILeaferCanvas, _options: IRenderOptions, _ignoreFill?: boolean, _ignoreStroke?: boolean): void { }
411
530
 
412
531
 
413
532
  public __updateWorldOpacity(): void { }
@@ -447,11 +566,11 @@ export class Leaf implements ILeaf {
447
566
 
448
567
  // LeafEventer rewrite
449
568
 
450
- public on(_type: string | string[], _listener: IEventListener, _options?: IEventListenerOptions | boolean): void { }
569
+ public on(_type: string | string[], _listener: IEventListener, _options?: IEventOption): void { }
451
570
 
452
- public off(_type: string | string[], _listener: IEventListener, _options?: IEventListenerOptions | boolean): void { }
571
+ public off(_type?: string | string[], _listener?: IEventListener, _options?: IEventOption): void { }
453
572
 
454
- public on_(_type: string | string[], _listener: IEventListener, _bind?: IObject, _options?: IEventListenerOptions | boolean): IEventListenerId { return undefined }
573
+ public on_(_type: string | string[], _listener: IEventListener, _bind?: IObject, _options?: IEventOption): IEventListenerId { return undefined }
455
574
 
456
575
  public off_(_id: IEventListenerId | IEventListenerId[]): void { }
457
576
 
@@ -465,8 +584,8 @@ export class Leaf implements ILeaf {
465
584
 
466
585
  // ---
467
586
 
468
- static changeAttr(attrName: string, defaultValue: IValue): void {
469
- defineDataProcessor(this.prototype, attrName, defaultValue)
587
+ static changeAttr(attrName: string, defaultValue: IValue, fn?: IAttrDecorator): void {
588
+ fn ? this.addAttr(attrName, defaultValue, fn) : defineDataProcessor(this.prototype, attrName, defaultValue)
470
589
  }
471
590
 
472
591
  static addAttr(attrName: string, defaultValue: IValue, fn?: IAttrDecorator): void {
@@ -477,8 +596,10 @@ export class Leaf implements ILeaf {
477
596
 
478
597
  public destroy(): void {
479
598
  if (!this.destroyed) {
480
- if (this.parent) this.remove()
599
+ const { parent } = this
600
+ if (parent) this.remove()
481
601
  if (this.children) (this as unknown as IBranch).removeAll(true)
602
+ if (this.hasEvent(ChildEvent.DESTROY)) this.emitEvent(new ChildEvent(ChildEvent.DESTROY, this, parent))
482
603
 
483
604
  this.__.destroy()
484
605
  this.__layout.destroy()
package/types/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { ILeaf, InnerId, ILeaferBase, ILeafData, ILeafLayout, IMatrixWithLayoutData, IMatrixWithBoundsData, IMatrixData, IBoundsData, IHitCanvas, IEventListenerMap, IFunction, ILeafInputData, IObject, IValue, IFindMethod, ILeaferCanvas, ILayoutAttr, IBoundsType, ILocationType, ILayoutBoundsData, IPointData, IRadiusPointData, IRenderOptions, IEventListener, IEventListenerOptions, IEventListenerId, IEvent, IAttrDecorator } from '@leafer/interface';
1
+ import { ILeaf, InnerId, ILeaferBase, ILeafData, ILeafLayout, IMatrixWithBoundsScaleData, IMatrixWithBoundsData, IMatrixData, IBoundsData, IMatrixWithScaleData, IHitCanvas, IEventMap, IEventListenerMap, IFunction, ILeafInputData, IObject, IValue, IJSONOptions, IFindMethod, ILeaferCanvas, IRenderOptions, ILocationType, IBoundsType, ILayoutBoundsData, IPointData, IAlign, IAxis, IRadiusPointData, IEventListener, IEventOption, IEventListenerId, IEvent, IAttrDecorator } from '@leafer/interface';
2
2
  import { LeafData } from '@leafer/data';
3
3
  import { LeafLayout } from '@leafer/layout';
4
4
 
@@ -12,19 +12,22 @@ declare class Leaf implements ILeaf {
12
12
  get __LayoutProcessor(): typeof LeafLayout;
13
13
  leafer?: ILeaferBase;
14
14
  parent?: ILeaf;
15
- isLeafer: boolean;
16
- isBranch: boolean;
17
- isBranchLeaf: boolean;
15
+ get isLeafer(): boolean;
16
+ get isBranch(): boolean;
17
+ get isBranchLeaf(): boolean;
18
18
  __: ILeafData;
19
19
  __layout: ILeafLayout;
20
- __world: IMatrixWithLayoutData;
20
+ __world: IMatrixWithBoundsScaleData;
21
21
  __local?: IMatrixWithBoundsData;
22
+ __nowWorld?: IMatrixWithBoundsScaleData;
23
+ __cameraWorld?: IMatrixWithBoundsScaleData;
22
24
  get __localMatrix(): IMatrixData;
23
- get __localBounds(): IBoundsData;
25
+ get __localBoxBounds(): IBoundsData;
24
26
  __worldOpacity: number;
25
- get worldTransform(): IMatrixWithLayoutData;
26
- get localTransform(): IMatrixWithBoundsData;
27
+ get worldTransform(): IMatrixWithScaleData;
28
+ get localTransform(): IMatrixData;
27
29
  get boxBounds(): IBoundsData;
30
+ get renderBounds(): IBoundsData;
28
31
  get worldBoxBounds(): IBoundsData;
29
32
  get worldStrokeBounds(): IBoundsData;
30
33
  get worldRenderBounds(): IBoundsData;
@@ -38,6 +41,9 @@ declare class Leaf implements ILeaf {
38
41
  __hitCanvas?: IHitCanvas;
39
42
  get __onlyHitMask(): boolean;
40
43
  get __ignoreHitWorld(): boolean;
44
+ get __inLazyBounds(): boolean;
45
+ get pathInputed(): boolean;
46
+ set event(map: IEventMap);
41
47
  __captureMap?: IEventListenerMap;
42
48
  __bubbleMap?: IEventListenerMap;
43
49
  __parentWait?: IFunction[];
@@ -48,22 +54,33 @@ declare class Leaf implements ILeaf {
48
54
  constructor(data?: ILeafInputData);
49
55
  reset(data?: ILeafInputData): void;
50
56
  resetCustom(): void;
51
- waitParent(item: IFunction): void;
52
- waitLeafer(item: IFunction): void;
53
- nextRender(item: IFunction): void;
57
+ waitParent(item: IFunction, bind?: IObject): void;
58
+ waitLeafer(item: IFunction, bind?: IObject): void;
59
+ nextRender(item: IFunction, bind?: IObject, off?: 'off'): void;
60
+ removeNextRender(item: IFunction): void;
54
61
  __bindLeafer(leafer: ILeaferBase | null): void;
55
62
  set(_data: IObject): void;
56
- get(): ILeafInputData;
57
- toJSON(): IObject;
58
- toString(): string;
59
- __setAttr(_attrName: string, _newValue: IValue): void;
63
+ get(_name?: string): ILeafInputData | IValue;
64
+ setAttr(name: string, value: any): void;
65
+ getAttr(name: string): any;
66
+ getComputedAttr(name: string): any;
67
+ toJSON(options?: IJSONOptions): IObject;
68
+ toString(options?: IJSONOptions): string;
69
+ toSVG(): string;
70
+ __SVG(_data: IObject): void;
71
+ toHTML(): string;
72
+ __setAttr(_attrName: string, _newValue: IValue): boolean;
60
73
  __getAttr(_attrName: string): IValue;
61
74
  setProxyAttr(_attrName: string, _newValue: IValue): void;
62
75
  getProxyAttr(_attrName: string): IValue;
63
76
  find(_condition: number | string | IFindMethod, _options?: any): ILeaf[];
64
- findOne(_condition: number | string | IFindMethod, _options?: any): ILeaf;
65
- forceUpdate(attrName?: string): void;
77
+ findTag(_tag: string | string[]): ILeaf[];
78
+ findOne(_condition: number | string | IFindMethod, _options?: any): ILeaf | undefined;
79
+ findId(_id: number | string): ILeaf | undefined;
80
+ focus(_value?: boolean): void;
66
81
  updateLayout(): void;
82
+ forceUpdate(attrName?: string): void;
83
+ forceRender(_bounds?: IBoundsData): void;
67
84
  __updateWorldMatrix(): void;
68
85
  __updateLocalMatrix(): void;
69
86
  __updateWorldBounds(): void;
@@ -72,21 +89,25 @@ declare class Leaf implements ILeaf {
72
89
  __updateLocalStrokeBounds(): void;
73
90
  __updateLocalRenderBounds(): void;
74
91
  __updateBoxBounds(): void;
92
+ __updateContentBounds(): void;
75
93
  __updateStrokeBounds(): void;
76
94
  __updateRenderBounds(): void;
77
95
  __updateAutoLayout(): void;
96
+ __updateFlowLayout(): void;
78
97
  __updateNaturalSize(): void;
79
98
  __updateStrokeSpread(): number;
80
99
  __updateRenderSpread(): number;
81
100
  __onUpdateSize(): void;
82
- __updateEraser(_value?: boolean): void;
83
- __updateMask(_value?: boolean): void;
84
- __renderMask(_canvas: ILeaferCanvas, _content: ILeaferCanvas, _mask: ILeaferCanvas, _recycle?: boolean): void;
85
- __removeMask(_child?: ILeaf): void;
86
- getWorld(attrName: ILayoutAttr): number;
101
+ __updateEraser(value?: boolean): void;
102
+ __renderEraser(canvas: ILeaferCanvas, options: IRenderOptions): void;
103
+ __updateMask(value?: boolean): void;
104
+ __renderMask(_canvas: ILeaferCanvas, _options: IRenderOptions): void;
105
+ __getNowWorld(options: IRenderOptions): IMatrixWithBoundsScaleData;
106
+ getTransform(relative?: ILocationType | ILeaf): IMatrixData;
87
107
  getBounds(type?: IBoundsType, relative?: ILocationType | ILeaf): IBoundsData;
88
108
  getLayoutBounds(type?: IBoundsType, relative?: ILocationType | ILeaf, unscale?: boolean): ILayoutBoundsData;
89
109
  getLayoutPoints(type?: IBoundsType, relative?: ILocationType | ILeaf): IPointData[];
110
+ getWorldBounds(inner: IBoundsData, relative?: ILeaf, change?: boolean): IBoundsData;
90
111
  worldToLocal(world: IPointData, to?: IPointData, distance?: boolean, relative?: ILeaf): void;
91
112
  localToWorld(local: IPointData, to?: IPointData, distance?: boolean, relative?: ILeaf): void;
92
113
  worldToInner(world: IPointData, to?: IPointData, distance?: boolean, relative?: ILeaf): void;
@@ -97,22 +118,36 @@ declare class Leaf implements ILeaf {
97
118
  getLocalPointByInner(inner: IPointData, _relative?: ILeaf, distance?: boolean, change?: boolean): IPointData;
98
119
  getWorldPoint(inner: IPointData, relative?: ILeaf, distance?: boolean, change?: boolean): IPointData;
99
120
  getWorldPointByLocal(local: IPointData, relative?: ILeaf, distance?: boolean, change?: boolean): IPointData;
121
+ getPagePoint(world: IPointData, relative?: ILeaf, distance?: boolean, change?: boolean): IPointData;
122
+ getWorldPointByPage(page: IPointData, relative?: ILeaf, distance?: boolean, change?: boolean): IPointData;
100
123
  setTransform(matrix: IMatrixData, resize?: boolean): void;
101
124
  transform(matrix: IMatrixData, resize?: boolean): void;
102
- move(x: number, y?: number): void;
103
- scaleOf(origin: IPointData, scaleX: number, scaleY?: number, resize?: boolean): void;
104
- rotateOf(origin: IPointData, rotation: number): void;
105
- skewOf(origin: IPointData, skewX: number, skewY?: number, resize?: boolean): void;
106
- scaleResize(scaleX: number, scaleY?: number, noResize?: boolean): void;
107
- __scaleResize(scaleX: number, scaleY: number): void;
125
+ move(x: number | IPointData, y?: number): void;
126
+ scaleOf(origin: IPointData | IAlign, scaleX: number, scaleY?: number, resize?: boolean): void;
127
+ rotateOf(origin: IPointData | IAlign, rotation: number): void;
128
+ skewOf(origin: IPointData | IAlign, skewX: number, skewY?: number, resize?: boolean): void;
129
+ transformWorld(worldTransform?: IMatrixData, resize?: boolean): void;
130
+ moveWorld(x: number | IPointData, y?: number): void;
131
+ scaleOfWorld(worldOrigin: IPointData, scaleX: number, scaleY?: number, resize?: boolean): void;
132
+ rotateOfWorld(worldOrigin: IPointData, rotation: number): void;
133
+ skewOfWorld(worldOrigin: IPointData, skewX: number, skewY?: number, resize?: boolean): void;
134
+ flip(axis: IAxis): void;
135
+ scaleResize(scaleX: number, scaleY?: number, _noResize?: boolean): void;
136
+ __scaleResize(_scaleX: number, _scaleY: number): void;
137
+ resizeWidth(_width: number): void;
138
+ resizeHeight(_height: number): void;
108
139
  __hitWorld(_point: IRadiusPointData): boolean;
109
140
  __hit(_local: IRadiusPointData): boolean;
141
+ __hitFill(_inner: IRadiusPointData): boolean;
142
+ __hitStroke(_inner: IRadiusPointData, _strokeWidth: number): boolean;
143
+ __hitPixel(_inner: IRadiusPointData): boolean;
110
144
  __drawHitPath(_canvas: ILeaferCanvas): void;
111
145
  __updateHitCanvas(): void;
112
146
  __render(_canvas: ILeaferCanvas, _options: IRenderOptions): void;
113
147
  __drawFast(_canvas: ILeaferCanvas, _options: IRenderOptions): void;
114
148
  __draw(_canvas: ILeaferCanvas, _options: IRenderOptions): void;
115
- __renderShape(_canvas: ILeaferCanvas, _options: IRenderOptions): void;
149
+ __clip(_canvas: ILeaferCanvas, _options: IRenderOptions): void;
150
+ __renderShape(_canvas: ILeaferCanvas, _options: IRenderOptions, _ignoreFill?: boolean, _ignoreStroke?: boolean): void;
116
151
  __updateWorldOpacity(): void;
117
152
  __updateChange(): void;
118
153
  __drawPath(_canvas: ILeaferCanvas): void;
@@ -123,21 +158,20 @@ declare class Leaf implements ILeaf {
123
158
  add(_child: ILeaf, _index?: number): void;
124
159
  remove(_child?: ILeaf, destroy?: boolean): void;
125
160
  dropTo(parent: ILeaf, index?: number, resize?: boolean): void;
126
- on(_type: string | string[], _listener: IEventListener, _options?: IEventListenerOptions | boolean): void;
127
- off(_type: string | string[], _listener: IEventListener, _options?: IEventListenerOptions | boolean): void;
128
- on_(_type: string | string[], _listener: IEventListener, _bind?: IObject, _options?: IEventListenerOptions | boolean): IEventListenerId;
161
+ on(_type: string | string[], _listener: IEventListener, _options?: IEventOption): void;
162
+ off(_type?: string | string[], _listener?: IEventListener, _options?: IEventOption): void;
163
+ on_(_type: string | string[], _listener: IEventListener, _bind?: IObject, _options?: IEventOption): IEventListenerId;
129
164
  off_(_id: IEventListenerId | IEventListenerId[]): void;
130
165
  once(_type: string | string[], _listener: IEventListener, _capture?: boolean): void;
131
166
  emit(_type: string, _event?: IEvent | IObject, _capture?: boolean): void;
132
167
  emitEvent(_event?: IEvent, _capture?: boolean): void;
133
168
  hasEvent(_type: string, _capture?: boolean): boolean;
134
- static changeAttr(attrName: string, defaultValue: IValue): void;
169
+ static changeAttr(attrName: string, defaultValue: IValue, fn?: IAttrDecorator): void;
135
170
  static addAttr(attrName: string, defaultValue: IValue, fn?: IAttrDecorator): void;
136
171
  destroy(): void;
137
172
  }
138
173
 
139
174
  declare class Branch extends Leaf {
140
- constructor();
141
175
  __updateStrokeSpread(): number;
142
176
  __updateRenderSpread(): number;
143
177
  __updateBoxBounds(): void;
@@ -146,8 +180,9 @@ declare class Branch extends Leaf {
146
180
  __updateSortChildren(): void;
147
181
  add(child: ILeaf, index?: number): void;
148
182
  addMany(...children: ILeaf[]): void;
149
- remove(child?: Leaf, destroy?: boolean): void;
183
+ remove(child?: ILeaf, destroy?: boolean): void;
150
184
  removeAll(destroy?: boolean): void;
185
+ clear(): void;
151
186
  protected __preRemove(): void;
152
187
  protected __realRemoveChild(child: ILeaf): void;
153
188
  protected __emitChildEvent(type: string, child: ILeaf): void;