@leafer/display 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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@leafer/display",
3
- "version": "1.0.0-rc.2",
3
+ "version": "1.0.0-rc.21",
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.2",
26
- "@leafer/data": "1.0.0-rc.2",
27
- "@leafer/layout": "1.0.0-rc.2",
28
- "@leafer/display-module": "1.0.0-rc.2",
29
- "@leafer/event": "1.0.0-rc.2",
30
- "@leafer/decorator": "1.0.0-rc.2",
31
- "@leafer/helper": "1.0.0-rc.2",
32
- "@leafer/platform": "1.0.0-rc.2"
25
+ "@leafer/math": "1.0.0-rc.21",
26
+ "@leafer/data": "1.0.0-rc.21",
27
+ "@leafer/layout": "1.0.0-rc.21",
28
+ "@leafer/display-module": "1.0.0-rc.21",
29
+ "@leafer/event": "1.0.0-rc.21",
30
+ "@leafer/decorator": "1.0.0-rc.21",
31
+ "@leafer/helper": "1.0.0-rc.21",
32
+ "@leafer/platform": "1.0.0-rc.21"
33
33
  },
34
34
  "devDependencies": {
35
- "@leafer/interface": "1.0.0-rc.2"
35
+ "@leafer/interface": "1.0.0-rc.21"
36
36
  }
37
37
  }
package/src/Branch.ts CHANGED
@@ -3,25 +3,18 @@ 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
 
10
10
 
11
- const { setByListWithHandle } = BoundsHelper
11
+ const { setListWithFn } = BoundsHelper
12
12
  const { sort } = BranchHelper
13
- const { localBoxBounds, localEventBounds, localRenderBounds, maskLocalBoxBounds, maskLocalEventBounds, maskLocalRenderBounds } = LeafBoundsHelper
13
+ const { localBoxBounds, localStrokeBounds, localRenderBounds, maskLocalBoxBounds, maskLocalStrokeBounds, maskLocalRenderBounds } = LeafBoundsHelper
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
 
@@ -42,15 +35,15 @@ export class Branch extends Leaf {
42
35
  }
43
36
 
44
37
  public __updateBoxBounds(): void {
45
- setByListWithHandle(this.__layout.boxBounds, this.children, this.__hasMask ? maskLocalBoxBounds : localBoxBounds)
38
+ setListWithFn(this.__layout.boxBounds, this.children, this.__hasMask ? maskLocalBoxBounds : localBoxBounds)
46
39
  }
47
40
 
48
41
  public __updateStrokeBounds(): void {
49
- setByListWithHandle(this.__layout.strokeBounds, this.children, this.__hasMask ? maskLocalEventBounds : localEventBounds)
42
+ setListWithFn(this.__layout.strokeBounds, this.children, this.__hasMask ? maskLocalStrokeBounds : localStrokeBounds)
50
43
  }
51
44
 
52
45
  public __updateRenderBounds(): void {
53
- setByListWithHandle(this.__layout.renderBounds, this.children, this.__hasMask ? maskLocalRenderBounds : localRenderBounds)
46
+ setListWithFn(this.__layout.renderBounds, this.children, this.__hasMask ? maskLocalRenderBounds : localRenderBounds)
54
47
  }
55
48
 
56
49
 
@@ -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.positionChange() // 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 { ILeafer, ILeaf, ILeafInputData, ILeafData, ILeaferCanvas, IRenderOptions, IMatrixWithBoundsData, __Number, __Boolean, __Value, ILeafLayout, InnerId, IHitCanvas, IRadiusPointData, IEventListenerMap, IEventListener, IEventListenerOptions, IEventListenerId, IEvent, IObject, IFunction, __String, IPointData, IMatrixDecompositionAttr, ILayoutBoundsType, ILayoutLocationType, IBoundsData, IBranch, IMatrixWithLayoutData } 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, IEventListenerOptions, IEventListenerId, IEvent, IObject, IFunction, IPointData, IBoundsData, IBranch, IFindMethod, ILayoutAttr, IMatrixData, IAttrDecorator, IMatrixWithBoundsScaleData, IMatrixWithScaleData } 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'
6
- import { useModule } from '@leafer/decorator'
5
+ import { LeafDataProxy, LeafMatrix, LeafBounds, LeafEventer, LeafRender } from '@leafer/display-module'
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 { toInnerPoint, toOuterPoint, multiplyParent } = MatrixHelper
13
+ const { toOuterOf } = BoundsHelper
12
14
  const { tempToOuterOf, copy } = PointHelper
13
- const { moveLocal, zoomOfLocal, rotateOfLocal, skewOfLocal } = LeafHelper
15
+ const { moveLocal, zoomOfLocal, rotateOfLocal, skewOfLocal, moveWorld, zoomOfWorld, rotateOfWorld, skewOfWorld, transform, transformWorld, setTransform, 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 {
@@ -31,41 +32,47 @@ export class Leaf implements ILeaf {
31
32
  public get __DataProcessor() { return LeafData }
32
33
  public get __LayoutProcessor() { return LeafLayout }
33
34
 
34
- public leafer?: ILeafer
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 __local: IMatrixWithBoundsData
45
+ public __world: IMatrixWithBoundsScaleData
46
+ public __local?: IMatrixWithBoundsData // and localStrokeBounds? localRenderBounds?
47
+
48
+ public __nowWorld?: IMatrixWithBoundsScaleData // use __world or __cameraWorld render
49
+ public __cameraWorld?: IMatrixWithBoundsScaleData // use camera matrix render
50
+
51
+ public get __localMatrix(): IMatrixData { return this.__local || this.__layout }
52
+ public get __localBoxBounds(): IBoundsData { return this.__local || this.__layout }
46
53
 
47
54
  public __worldOpacity: number
48
55
 
49
56
  // now transform
50
- public get worldTransform(): IMatrixWithLayoutData { return this.__layout.getTransform('world') as IMatrixWithLayoutData }
51
- 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') }
52
59
 
53
60
  // now bounds
54
61
  public get boxBounds(): IBoundsData { return this.getBounds('box', 'inner') }
62
+ public get renderBounds(): IBoundsData { return this.getBounds('render', 'inner') }
55
63
  public get worldBoxBounds(): IBoundsData { return this.getBounds('box') }
56
64
  public get worldStrokeBounds(): IBoundsData { return this.getBounds('stroke') }
57
65
  public get worldRenderBounds(): IBoundsData { return this.getBounds('render') }
58
66
 
59
67
  // now opacity
60
- public get worldOpacity(): number { this.__layout.checkUpdate(); return this.__worldOpacity }
68
+ public get worldOpacity(): number { this.__layout.update(); return this.__worldOpacity }
61
69
 
62
70
  public __level: number // layer level 0 -> branch -> branch -> deep
63
71
  public __tempNumber: number // temp sort
64
72
 
65
- public get resizeable(): boolean { return true }
66
-
67
- public get __hasMirror(): boolean { return this.__world.scaleX < 0 || this.__world.scaleY < 0 }
73
+ public get __worldFlipped(): boolean { return this.__world.scaleX < 0 || this.__world.scaleY < 0 }
68
74
 
75
+ public __hasAutoLayout?: boolean
69
76
  public __hasMask?: boolean
70
77
  public __hasEraser?: boolean
71
78
  public __hitCanvas?: IHitCanvas
@@ -73,6 +80,8 @@ export class Leaf implements ILeaf {
73
80
  public get __onlyHitMask(): boolean { return this.__hasMask && !this.__.hitChildren }
74
81
  public get __ignoreHitWorld(): boolean { return (this.__hasMask || this.__hasEraser) && this.__.hitChildren }
75
82
 
83
+ public get pathInputed(): boolean { return !!this.__.__pathInputed }
84
+
76
85
  // event
77
86
  public __captureMap?: IEventListenerMap
78
87
  public __bubbleMap?: IEventListenerMap
@@ -83,52 +92,70 @@ export class Leaf implements ILeaf {
83
92
  // branch
84
93
  public children?: ILeaf[]
85
94
 
95
+ // other
96
+ public noBounds?: boolean
86
97
 
87
98
  public destroyed: boolean
88
99
 
89
100
 
90
101
  constructor(data?: ILeafInputData) {
91
-
92
102
  this.innerId = create(LEAF)
103
+ this.reset(data)
104
+ }
93
105
 
94
- 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 }
95
- this.__local = { a: 1, b: 0, c: 0, d: 1, e: 0, f: 0, x: 0, y: 0, width: 0, height: 0 }
106
+
107
+ public reset(data?: ILeafInputData): void {
108
+
109
+ 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 }
110
+ 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 }
96
111
 
97
112
  this.__worldOpacity = 1
98
113
 
99
114
  this.__ = new this.__DataProcessor(this)
100
115
  this.__layout = new this.__LayoutProcessor(this)
101
116
 
117
+ if (this.__level) this.resetCustom()
102
118
  if (data) {
103
- if (data.children) {
104
- this.set(data)
105
- } else {
106
- Object.assign(this, data)
107
- }
119
+ if ((data as ILeaf).__) data = (data as ILeaf).toJSON()
120
+ data.children ? this.set(data) : Object.assign(this, data)
108
121
  }
109
122
  }
110
123
 
124
+ public resetCustom(): void {
125
+ this.__hasMask = this.__hasEraser = null
126
+ this.forceUpdate()
127
+ }
128
+
111
129
 
112
- public waitParent(item: IFunction): void {
130
+ public waitParent(item: IFunction, bind?: IObject): void {
131
+ if (bind) item = item.bind(bind)
113
132
  this.parent ? item() : (this.__parentWait ? this.__parentWait.push(item) : this.__parentWait = [item])
114
133
  }
115
134
 
116
- public waitLeafer(item: IFunction): void {
135
+ public waitLeafer(item: IFunction, bind?: IObject): void {
136
+ if (bind) item = item.bind(bind)
117
137
  this.leafer ? item() : (this.__leaferWait ? this.__leaferWait.push(item) : this.__leaferWait = [item])
118
138
  }
119
139
 
120
- public nextRender(item: IFunction): void {
121
- this.leafer ? this.leafer.nextRender(item) : this.waitLeafer(() => this.leafer.nextRender(item))
140
+ public nextRender(item: IFunction, bind?: IObject, off?: 'off'): void {
141
+ this.leafer ? this.leafer.nextRender(item, bind, off) : this.waitLeafer(() => this.leafer.nextRender(item, bind, off))
122
142
  }
123
143
 
124
- public __bindLeafer(leafer: ILeafer | null): void {
144
+ public removeNextRender(item: IFunction): void {
145
+ this.nextRender(item, null, 'off')
146
+ }
147
+
148
+ public __bindLeafer(leafer: ILeaferBase | null): void {
125
149
  if (this.isLeafer) {
126
- if (leafer !== null) leafer = this as unknown as ILeafer
150
+ if (leafer !== null) leafer = this as unknown as ILeaferBase
127
151
  }
128
152
 
153
+ if (this.leafer && !leafer) this.leafer.leafs--
154
+
129
155
  this.leafer = leafer
130
156
 
131
157
  if (leafer) {
158
+ leafer.leafs++
132
159
  this.__level = this.parent ? this.parent.__level + 1 : 1
133
160
  if (this.__leaferWait) WaitHelper.run(this.__leaferWait)
134
161
  }
@@ -144,6 +171,7 @@ export class Leaf implements ILeaf {
144
171
  // data
145
172
 
146
173
  public set(_data: IObject): void { }
174
+ public get(_name?: string): ILeafInputData | IValue { return undefined }
147
175
 
148
176
  public toJSON(): IObject {
149
177
  return this.__.__getInputData()
@@ -155,20 +183,45 @@ export class Leaf implements ILeaf {
155
183
 
156
184
  // LeafDataProxy rewrite
157
185
 
158
- public __setAttr(_attrName: string, _newValue: __Value): void { }
186
+ public __setAttr(_attrName: string, _newValue: IValue): boolean { return true }
187
+
188
+ public __getAttr(_attrName: string): IValue { return undefined }
189
+
190
+ public setProxyAttr(_attrName: string, _newValue: IValue): void { }
159
191
 
160
- public __getAttr(_attrName: string): __Value { return undefined }
192
+ public getProxyAttr(_attrName: string): IValue { return undefined }
161
193
 
162
194
  // ---
163
195
 
196
+
197
+ // find
198
+
199
+ public find(_condition: number | string | IFindMethod, _options?: any): ILeaf[] { return undefined }
200
+
201
+ public findOne(_condition: number | string | IFindMethod, _options?: any): ILeaf { return undefined }
202
+
203
+ // ---
204
+
205
+
206
+ // state
207
+
208
+ public focus(_value?: boolean): void { }
209
+
210
+ // ---
211
+
212
+
164
213
  public forceUpdate(attrName?: string): void {
165
- if (attrName === undefined) attrName = 'scaleX'
214
+ if (attrName === undefined) attrName = 'width'
166
215
  else if (attrName === 'surface') attrName = 'blendMode'
167
- const value = this.__.__getInput(attrName)
168
- this.__[attrName] = value === undefined ? null : undefined;
216
+ const value = this.__.__getInput(attrName);
217
+ (this.__ as any)[attrName] = value === undefined ? null : undefined;
169
218
  (this as any)[attrName] = value
170
219
  }
171
220
 
221
+ public updateLayout(): void {
222
+ this.__layout.update()
223
+ }
224
+
172
225
 
173
226
  // LeafMatrix rewrite
174
227
 
@@ -182,6 +235,8 @@ export class Leaf implements ILeaf {
182
235
 
183
236
  public __updateWorldBounds(): void { }
184
237
 
238
+ public __updateLocalBounds(): void { }
239
+
185
240
 
186
241
  public __updateLocalBoxBounds(): void { }
187
242
 
@@ -198,6 +253,7 @@ export class Leaf implements ILeaf {
198
253
  public __updateRenderBounds(): void { }
199
254
 
200
255
 
256
+ public __updateAutoLayout(): void { }
201
257
  public __updateNaturalSize(): void { }
202
258
 
203
259
 
@@ -212,28 +268,65 @@ export class Leaf implements ILeaf {
212
268
 
213
269
  // LeafMask rewrite
214
270
 
215
- public __updateEraser(_value?: boolean): void { }
271
+ public __updateEraser(value?: boolean): void {
272
+ this.__hasEraser = value ? true : this.children.some(item => item.__.eraser)
273
+ }
216
274
 
217
- public __updateMask(_value?: boolean): void { }
275
+ public __updateMask(value?: boolean): void {
276
+ this.__hasMask = value ? true : this.children.some(item => item.__.mask)
277
+ }
218
278
 
219
- public __renderMask(_canvas: ILeaferCanvas, _content: ILeaferCanvas, _mask: ILeaferCanvas): void { }
279
+ public __renderMask(_canvas: ILeaferCanvas, _options: IRenderOptions): void { }
220
280
 
221
- public __removeMask(_child?: ILeaf): void { }
222
281
 
223
282
  // ---
224
283
 
225
284
 
226
285
  // convert
227
286
 
228
- public getWorld(attrName: IMatrixDecompositionAttr): number {
229
- this.__layout.checkUpdate()
287
+ public __getNowWorld(options: IRenderOptions): IMatrixWithBoundsScaleData {
288
+ if (options.matrix) {
289
+ if (!this.__cameraWorld) this.__cameraWorld = {} as IMatrixWithBoundsScaleData
290
+ const cameraWorld = this.__cameraWorld
291
+ multiplyParent(this.__world, options.matrix, cameraWorld, undefined, this.__world)
292
+ toOuterOf(this.__layout.renderBounds, cameraWorld, cameraWorld)
293
+ return cameraWorld
294
+ } else {
295
+ return this.__world
296
+ }
297
+ }
298
+
299
+
300
+ public getWorld(attrName: ILayoutAttr): number {
301
+ this.__layout.update()
230
302
  if (attrName === 'x') return this.__world.e
231
303
  if (attrName === 'y') return this.__world.f
232
- return this.__world[attrName]
304
+ return this.getLayoutBounds()[attrName]
305
+ }
306
+
307
+ public getTransform(relative?: ILocationType | ILeaf): IMatrixData {
308
+ return this.__layout.getTransform(relative || 'local')
309
+ }
310
+
311
+
312
+ public getBounds(type?: IBoundsType, relative?: ILocationType | ILeaf): IBoundsData {
313
+ return this.__layout.getBounds(type, relative)
314
+ }
315
+
316
+ public getLayoutBounds(type?: IBoundsType, relative?: ILocationType | ILeaf, unscale?: boolean): ILayoutBoundsData {
317
+ return this.__layout.getLayoutBounds(type, relative, unscale)
233
318
  }
234
319
 
235
- public getBounds(type: ILayoutBoundsType, locationType: ILayoutLocationType = 'world'): IBoundsData {
236
- return this.__layout.getBounds(type, locationType)
320
+ public getLayoutPoints(type?: IBoundsType, relative?: ILocationType | ILeaf): IPointData[] {
321
+ return this.__layout.getLayoutPoints(type, relative)
322
+ }
323
+
324
+
325
+ public getWorldBounds(inner: IBoundsData, relative?: ILeaf, change?: boolean): IBoundsData {
326
+ const matrix = relative ? getRelativeWorld(this, relative) : this.worldTransform
327
+ const to = change ? inner : {} as IBoundsData
328
+ toOuterOf(inner, matrix, to)
329
+ return to
237
330
  }
238
331
 
239
332
 
@@ -300,32 +393,86 @@ export class Leaf implements ILeaf {
300
393
  return point
301
394
  }
302
395
 
396
+ public getPagePoint(world: IPointData, relative?: ILeaf, distance?: boolean, change?: boolean): IPointData {
397
+ const layer = this.leafer ? this.leafer.zoomLayer : this
398
+ return layer.getInnerPoint(world, relative, distance, change)
399
+ }
400
+
401
+ public getWorldPointByPage(page: IPointData, relative?: ILeaf, distance?: boolean, change?: boolean): IPointData {
402
+ const layer = this.leafer ? this.leafer.zoomLayer : this
403
+ return layer.getWorldPoint(page, relative, distance, change)
404
+ }
405
+
303
406
 
304
- // transform
407
+ // transform
408
+
409
+ public setTransform(matrix: IMatrixData, resize?: boolean): void {
410
+ setTransform(this, matrix, resize)
411
+ }
412
+
413
+ public transform(matrix: IMatrixData, resize?: boolean): void {
414
+ transform(this, matrix, resize)
415
+ }
305
416
 
306
417
  public move(x: number, y?: number): void {
307
418
  moveLocal(this, x, y)
308
419
  }
309
420
 
310
- public scaleOf(origin: IPointData, x: number, y?: number): void {
311
- zoomOfLocal(this, tempToOuterOf(origin, this.localTransform), x, y)
421
+ public scaleOf(origin: IPointData, scaleX: number, scaleY?: number, resize?: boolean): void {
422
+ zoomOfLocal(this, tempToOuterOf(origin, this.localTransform), scaleX, scaleY, resize)
423
+ }
424
+
425
+ public rotateOf(origin: IPointData, rotation: number): void {
426
+ rotateOfLocal(this, tempToOuterOf(origin, this.localTransform), rotation)
312
427
  }
313
428
 
314
- public rotateOf(origin: IPointData, angle: number): void {
315
- rotateOfLocal(this, tempToOuterOf(origin, this.localTransform), angle)
429
+ public skewOf(origin: IPointData, skewX: number, skewY?: number, resize?: boolean): void {
430
+ skewOfLocal(this, tempToOuterOf(origin, this.localTransform), skewX, skewY, resize)
316
431
  }
317
432
 
318
- public skewOf(origin: IPointData, x: number, y: number): void {
319
- skewOfLocal(this, tempToOuterOf(origin, this.localTransform), x, y)
433
+
434
+ public transformWorld(worldTransform?: IMatrixData, resize?: boolean): void {
435
+ transformWorld(this, worldTransform, resize)
320
436
  }
321
437
 
438
+ public moveWorld(x: number, y?: number): void {
439
+ moveWorld(this, x, y)
440
+ }
322
441
 
323
- // LeafHit rewrite
442
+ public scaleOfWorld(worldOrigin: IPointData, scaleX: number, scaleY?: number, resize?: boolean): void {
443
+ zoomOfWorld(this, worldOrigin, scaleX, scaleY, resize)
444
+ }
445
+
446
+ public rotateOfWorld(worldOrigin: IPointData, rotation: number): void {
447
+ rotateOfWorld(this, worldOrigin, rotation)
448
+ }
449
+
450
+ public skewOfWorld(worldOrigin: IPointData, skewX: number, skewY?: number, resize?: boolean): void {
451
+ skewOfWorld(this, worldOrigin, skewX, skewY, resize)
452
+ }
453
+
454
+
455
+ // @leafer-ui/scale rewrite
456
+
457
+ public scaleResize(scaleX: number, scaleY = scaleX, _noResize?: boolean): void {
458
+ (this as ILeaf).scaleX *= scaleX;
459
+ (this as ILeaf).scaleY *= scaleY
460
+ }
461
+
462
+ public __scaleResize(_scaleX: number, _scaleY: number): void { }
463
+
464
+ // @leafer-ui/hit LeafHit rewrite
324
465
 
325
466
  public __hitWorld(_point: IRadiusPointData): boolean { return true }
326
467
 
327
468
  public __hit(_local: IRadiusPointData): boolean { return true }
328
469
 
470
+ public __hitFill(_inner: IRadiusPointData): boolean { return true }
471
+
472
+ public __hitStroke(_inner: IRadiusPointData, _strokeWidth: number): boolean { return true }
473
+
474
+ public __hitPixel(_inner: IRadiusPointData): boolean { return true }
475
+
329
476
  public __drawHitPath(_canvas: ILeaferCanvas): void { }
330
477
 
331
478
  public __updateHitCanvas(): void { }
@@ -341,7 +488,10 @@ export class Leaf implements ILeaf {
341
488
 
342
489
  public __draw(_canvas: ILeaferCanvas, _options: IRenderOptions): void { }
343
490
 
344
- public __renderShape(_canvas: ILeaferCanvas, _options: IRenderOptions): void { }
491
+
492
+ public __clip(_canvas: ILeaferCanvas, _options: IRenderOptions): void { }
493
+
494
+ public __renderShape(_canvas: ILeaferCanvas, _options: IRenderOptions, _ignoreFill?: boolean, _ignoreStroke?: boolean): void { }
345
495
 
346
496
 
347
497
  public __updateWorldOpacity(): void { }
@@ -372,6 +522,10 @@ export class Leaf implements ILeaf {
372
522
  if (this.parent) this.parent.remove(this, destroy)
373
523
  }
374
524
 
525
+ public dropTo(parent: ILeaf, index?: number, resize?: boolean): void {
526
+ drop(this, parent, index, resize)
527
+ }
528
+
375
529
  // ---
376
530
 
377
531
 
@@ -395,11 +549,22 @@ export class Leaf implements ILeaf {
395
549
 
396
550
  // ---
397
551
 
552
+ static changeAttr(attrName: string, defaultValue: IValue): void {
553
+ defineDataProcessor(this.prototype, attrName, defaultValue)
554
+ }
555
+
556
+ static addAttr(attrName: string, defaultValue: IValue, fn?: IAttrDecorator): void {
557
+ if (!fn) fn = boundsType
558
+ fn(defaultValue)(this.prototype, attrName)
559
+ }
560
+
398
561
 
399
562
  public destroy(): void {
400
563
  if (!this.destroyed) {
401
- if (this.parent) this.remove()
564
+ const { parent } = this
565
+ if (parent) this.remove()
402
566
  if (this.children) (this as unknown as IBranch).removeAll(true)
567
+ if (this.hasEvent(ChildEvent.DESTROY)) this.emitEvent(new ChildEvent(ChildEvent.DESTROY, this, parent))
403
568
 
404
569
  this.__.destroy()
405
570
  this.__layout.destroy()
package/types/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { ILeaf, InnerId, ILeafer, ILeafData, ILeafLayout, IMatrixWithLayoutData, IMatrixWithBoundsData, IBoundsData, IHitCanvas, IEventListenerMap, IFunction, ILeafInputData, IObject, __Value, ILeaferCanvas, IMatrixDecompositionAttr, ILayoutBoundsType, ILayoutLocationType, IPointData, IRadiusPointData, IRenderOptions, IEventListener, IEventListenerOptions, IEventListenerId, IEvent } from '@leafer/interface';
1
+ import { ILeaf, InnerId, ILeaferBase, ILeafData, ILeafLayout, IMatrixWithBoundsScaleData, IMatrixWithBoundsData, IMatrixData, IBoundsData, IMatrixWithScaleData, IHitCanvas, IEventListenerMap, IFunction, ILeafInputData, IObject, IValue, IFindMethod, ILeaferCanvas, IRenderOptions, ILayoutAttr, ILocationType, IBoundsType, ILayoutBoundsData, IPointData, IRadiusPointData, IEventListener, IEventListenerOptions, IEventListenerId, IEvent, IAttrDecorator } from '@leafer/interface';
2
2
  import { LeafData } from '@leafer/data';
3
3
  import { LeafLayout } from '@leafer/layout';
4
4
 
@@ -10,68 +10,91 @@ declare class Leaf implements ILeaf {
10
10
  get innerName(): string;
11
11
  get __DataProcessor(): typeof LeafData;
12
12
  get __LayoutProcessor(): typeof LeafLayout;
13
- leafer?: ILeafer;
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;
21
- __local: IMatrixWithBoundsData;
20
+ __world: IMatrixWithBoundsScaleData;
21
+ __local?: IMatrixWithBoundsData;
22
+ __nowWorld?: IMatrixWithBoundsScaleData;
23
+ __cameraWorld?: IMatrixWithBoundsScaleData;
24
+ get __localMatrix(): IMatrixData;
25
+ get __localBoxBounds(): IBoundsData;
22
26
  __worldOpacity: number;
23
- get worldTransform(): IMatrixWithLayoutData;
24
- get localTransform(): IMatrixWithBoundsData;
27
+ get worldTransform(): IMatrixWithScaleData;
28
+ get localTransform(): IMatrixData;
25
29
  get boxBounds(): IBoundsData;
30
+ get renderBounds(): IBoundsData;
26
31
  get worldBoxBounds(): IBoundsData;
27
32
  get worldStrokeBounds(): IBoundsData;
28
33
  get worldRenderBounds(): IBoundsData;
29
34
  get worldOpacity(): number;
30
35
  __level: number;
31
36
  __tempNumber: number;
32
- get resizeable(): boolean;
33
- get __hasMirror(): boolean;
37
+ get __worldFlipped(): boolean;
38
+ __hasAutoLayout?: boolean;
34
39
  __hasMask?: boolean;
35
40
  __hasEraser?: boolean;
36
41
  __hitCanvas?: IHitCanvas;
37
42
  get __onlyHitMask(): boolean;
38
43
  get __ignoreHitWorld(): boolean;
44
+ get pathInputed(): boolean;
39
45
  __captureMap?: IEventListenerMap;
40
46
  __bubbleMap?: IEventListenerMap;
41
47
  __parentWait?: IFunction[];
42
48
  __leaferWait?: IFunction[];
43
49
  children?: ILeaf[];
50
+ noBounds?: boolean;
44
51
  destroyed: boolean;
45
52
  constructor(data?: ILeafInputData);
46
- waitParent(item: IFunction): void;
47
- waitLeafer(item: IFunction): void;
48
- nextRender(item: IFunction): void;
49
- __bindLeafer(leafer: ILeafer | null): void;
53
+ reset(data?: ILeafInputData): void;
54
+ resetCustom(): void;
55
+ waitParent(item: IFunction, bind?: IObject): void;
56
+ waitLeafer(item: IFunction, bind?: IObject): void;
57
+ nextRender(item: IFunction, bind?: IObject, off?: 'off'): void;
58
+ removeNextRender(item: IFunction): void;
59
+ __bindLeafer(leafer: ILeaferBase | null): void;
50
60
  set(_data: IObject): void;
61
+ get(_name?: string): ILeafInputData | IValue;
51
62
  toJSON(): IObject;
52
63
  toString(): string;
53
- __setAttr(_attrName: string, _newValue: __Value): void;
54
- __getAttr(_attrName: string): __Value;
64
+ __setAttr(_attrName: string, _newValue: IValue): boolean;
65
+ __getAttr(_attrName: string): IValue;
66
+ setProxyAttr(_attrName: string, _newValue: IValue): void;
67
+ getProxyAttr(_attrName: string): IValue;
68
+ find(_condition: number | string | IFindMethod, _options?: any): ILeaf[];
69
+ findOne(_condition: number | string | IFindMethod, _options?: any): ILeaf;
70
+ focus(_value?: boolean): void;
55
71
  forceUpdate(attrName?: string): void;
72
+ updateLayout(): void;
56
73
  __updateWorldMatrix(): void;
57
74
  __updateLocalMatrix(): void;
58
75
  __updateWorldBounds(): void;
76
+ __updateLocalBounds(): void;
59
77
  __updateLocalBoxBounds(): void;
60
78
  __updateLocalStrokeBounds(): void;
61
79
  __updateLocalRenderBounds(): void;
62
80
  __updateBoxBounds(): void;
63
81
  __updateStrokeBounds(): void;
64
82
  __updateRenderBounds(): void;
83
+ __updateAutoLayout(): void;
65
84
  __updateNaturalSize(): void;
66
85
  __updateStrokeSpread(): number;
67
86
  __updateRenderSpread(): number;
68
87
  __onUpdateSize(): void;
69
- __updateEraser(_value?: boolean): void;
70
- __updateMask(_value?: boolean): void;
71
- __renderMask(_canvas: ILeaferCanvas, _content: ILeaferCanvas, _mask: ILeaferCanvas): void;
72
- __removeMask(_child?: ILeaf): void;
73
- getWorld(attrName: IMatrixDecompositionAttr): number;
74
- getBounds(type: ILayoutBoundsType, locationType?: ILayoutLocationType): IBoundsData;
88
+ __updateEraser(value?: boolean): void;
89
+ __updateMask(value?: boolean): void;
90
+ __renderMask(_canvas: ILeaferCanvas, _options: IRenderOptions): void;
91
+ __getNowWorld(options: IRenderOptions): IMatrixWithBoundsScaleData;
92
+ getWorld(attrName: ILayoutAttr): number;
93
+ getTransform(relative?: ILocationType | ILeaf): IMatrixData;
94
+ getBounds(type?: IBoundsType, relative?: ILocationType | ILeaf): IBoundsData;
95
+ getLayoutBounds(type?: IBoundsType, relative?: ILocationType | ILeaf, unscale?: boolean): ILayoutBoundsData;
96
+ getLayoutPoints(type?: IBoundsType, relative?: ILocationType | ILeaf): IPointData[];
97
+ getWorldBounds(inner: IBoundsData, relative?: ILeaf, change?: boolean): IBoundsData;
75
98
  worldToLocal(world: IPointData, to?: IPointData, distance?: boolean, relative?: ILeaf): void;
76
99
  localToWorld(local: IPointData, to?: IPointData, distance?: boolean, relative?: ILeaf): void;
77
100
  worldToInner(world: IPointData, to?: IPointData, distance?: boolean, relative?: ILeaf): void;
@@ -82,18 +105,33 @@ declare class Leaf implements ILeaf {
82
105
  getLocalPointByInner(inner: IPointData, _relative?: ILeaf, distance?: boolean, change?: boolean): IPointData;
83
106
  getWorldPoint(inner: IPointData, relative?: ILeaf, distance?: boolean, change?: boolean): IPointData;
84
107
  getWorldPointByLocal(local: IPointData, relative?: ILeaf, distance?: boolean, change?: boolean): IPointData;
108
+ getPagePoint(world: IPointData, relative?: ILeaf, distance?: boolean, change?: boolean): IPointData;
109
+ getWorldPointByPage(page: IPointData, relative?: ILeaf, distance?: boolean, change?: boolean): IPointData;
110
+ setTransform(matrix: IMatrixData, resize?: boolean): void;
111
+ transform(matrix: IMatrixData, resize?: boolean): void;
85
112
  move(x: number, y?: number): void;
86
- scaleOf(origin: IPointData, x: number, y?: number): void;
87
- rotateOf(origin: IPointData, angle: number): void;
88
- skewOf(origin: IPointData, x: number, y: number): void;
113
+ scaleOf(origin: IPointData, scaleX: number, scaleY?: number, resize?: boolean): void;
114
+ rotateOf(origin: IPointData, rotation: number): void;
115
+ skewOf(origin: IPointData, skewX: number, skewY?: number, resize?: boolean): void;
116
+ transformWorld(worldTransform?: IMatrixData, resize?: boolean): void;
117
+ moveWorld(x: number, y?: number): void;
118
+ scaleOfWorld(worldOrigin: IPointData, scaleX: number, scaleY?: number, resize?: boolean): void;
119
+ rotateOfWorld(worldOrigin: IPointData, rotation: number): void;
120
+ skewOfWorld(worldOrigin: IPointData, skewX: number, skewY?: number, resize?: boolean): void;
121
+ scaleResize(scaleX: number, scaleY?: number, _noResize?: boolean): void;
122
+ __scaleResize(_scaleX: number, _scaleY: number): void;
89
123
  __hitWorld(_point: IRadiusPointData): boolean;
90
124
  __hit(_local: IRadiusPointData): boolean;
125
+ __hitFill(_inner: IRadiusPointData): boolean;
126
+ __hitStroke(_inner: IRadiusPointData, _strokeWidth: number): boolean;
127
+ __hitPixel(_inner: IRadiusPointData): boolean;
91
128
  __drawHitPath(_canvas: ILeaferCanvas): void;
92
129
  __updateHitCanvas(): void;
93
130
  __render(_canvas: ILeaferCanvas, _options: IRenderOptions): void;
94
131
  __drawFast(_canvas: ILeaferCanvas, _options: IRenderOptions): void;
95
132
  __draw(_canvas: ILeaferCanvas, _options: IRenderOptions): void;
96
- __renderShape(_canvas: ILeaferCanvas, _options: IRenderOptions): void;
133
+ __clip(_canvas: ILeaferCanvas, _options: IRenderOptions): void;
134
+ __renderShape(_canvas: ILeaferCanvas, _options: IRenderOptions, _ignoreFill?: boolean, _ignoreStroke?: boolean): void;
97
135
  __updateWorldOpacity(): void;
98
136
  __updateChange(): void;
99
137
  __drawPath(_canvas: ILeaferCanvas): void;
@@ -103,6 +141,7 @@ declare class Leaf implements ILeaf {
103
141
  __updateSortChildren(): void;
104
142
  add(_child: ILeaf, _index?: number): void;
105
143
  remove(_child?: ILeaf, destroy?: boolean): void;
144
+ dropTo(parent: ILeaf, index?: number, resize?: boolean): void;
106
145
  on(_type: string | string[], _listener: IEventListener, _options?: IEventListenerOptions | boolean): void;
107
146
  off(_type: string | string[], _listener: IEventListener, _options?: IEventListenerOptions | boolean): void;
108
147
  on_(_type: string | string[], _listener: IEventListener, _bind?: IObject, _options?: IEventListenerOptions | boolean): IEventListenerId;
@@ -111,11 +150,12 @@ declare class Leaf implements ILeaf {
111
150
  emit(_type: string, _event?: IEvent | IObject, _capture?: boolean): void;
112
151
  emitEvent(_event?: IEvent, _capture?: boolean): void;
113
152
  hasEvent(_type: string, _capture?: boolean): boolean;
153
+ static changeAttr(attrName: string, defaultValue: IValue): void;
154
+ static addAttr(attrName: string, defaultValue: IValue, fn?: IAttrDecorator): void;
114
155
  destroy(): void;
115
156
  }
116
157
 
117
158
  declare class Branch extends Leaf {
118
- constructor();
119
159
  __updateStrokeSpread(): number;
120
160
  __updateRenderSpread(): number;
121
161
  __updateBoxBounds(): void;
@@ -124,8 +164,9 @@ declare class Branch extends Leaf {
124
164
  __updateSortChildren(): void;
125
165
  add(child: ILeaf, index?: number): void;
126
166
  addMany(...children: ILeaf[]): void;
127
- remove(child?: Leaf, destroy?: boolean): void;
167
+ remove(child?: ILeaf, destroy?: boolean): void;
128
168
  removeAll(destroy?: boolean): void;
169
+ clear(): void;
129
170
  protected __preRemove(): void;
130
171
  protected __realRemoveChild(child: ILeaf): void;
131
172
  protected __emitChildEvent(type: string, child: ILeaf): void;