@leafer/display 1.0.0-beta.9 → 1.0.0-rc.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,12 +1,15 @@
1
1
  {
2
2
  "name": "@leafer/display",
3
- "version": "1.0.0-beta.9",
3
+ "version": "1.0.0-rc.10",
4
4
  "description": "@leafer/display",
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,15 +22,16 @@
19
22
  "leaferjs"
20
23
  ],
21
24
  "dependencies": {
22
- "@leafer/math": "1.0.0-beta.9",
23
- "@leafer/data": "1.0.0-beta.9",
24
- "@leafer/layout": "1.0.0-beta.9",
25
- "@leafer/display-module": "1.0.0-beta.9",
26
- "@leafer/event": "1.0.0-beta.9",
27
- "@leafer/decorator": "1.0.0-beta.9",
28
- "@leafer/helper": "1.0.0-beta.9"
25
+ "@leafer/math": "1.0.0-rc.10",
26
+ "@leafer/data": "1.0.0-rc.10",
27
+ "@leafer/layout": "1.0.0-rc.10",
28
+ "@leafer/display-module": "1.0.0-rc.10",
29
+ "@leafer/event": "1.0.0-rc.10",
30
+ "@leafer/decorator": "1.0.0-rc.10",
31
+ "@leafer/helper": "1.0.0-rc.10",
32
+ "@leafer/platform": "1.0.0-rc.10"
29
33
  },
30
34
  "devDependencies": {
31
- "@leafer/interface": "1.0.0-beta.9"
35
+ "@leafer/interface": "1.0.0-rc.10"
32
36
  }
33
37
  }
package/src/Branch.ts CHANGED
@@ -3,18 +3,17 @@ 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
17
  export class Branch extends Leaf {
19
18
 
20
19
  constructor() {
@@ -42,27 +41,30 @@ export class Branch extends Leaf {
42
41
  }
43
42
 
44
43
  public __updateBoxBounds(): void {
45
- setByListWithHandle(this.__layout.boxBounds, this.children, this.__hasMask ? maskLocalBoxBounds : localBoxBounds)
44
+ setListWithFn(this.__layout.boxBounds, this.children, this.__hasMask ? maskLocalBoxBounds : localBoxBounds)
46
45
  }
47
46
 
48
47
  public __updateStrokeBounds(): void {
49
- setByListWithHandle(this.__layout.strokeBounds, this.children, this.__hasMask ? maskLocalEventBounds : localEventBounds)
48
+ setListWithFn(this.__layout.strokeBounds, this.children, this.__hasMask ? maskLocalStrokeBounds : localStrokeBounds)
50
49
  }
51
50
 
52
51
  public __updateRenderBounds(): void {
53
- setByListWithHandle(this.__layout.renderBounds, this.children, this.__hasMask ? maskLocalRenderBounds : localRenderBounds)
52
+ setListWithFn(this.__layout.renderBounds, this.children, this.__hasMask ? maskLocalRenderBounds : localRenderBounds)
54
53
  }
55
54
 
56
55
 
57
56
  // own
58
57
 
59
58
  public __updateSortChildren(): void {
59
+ let affectSort: boolean
60
60
  const { children } = this
61
61
  if (children.length > 1) {
62
62
  for (let i = 0, len = children.length; i < len; i++) {
63
63
  children[i].__tempNumber = i
64
+ if (children[i].__.zIndex) affectSort = true
64
65
  }
65
66
  children.sort(sort)
67
+ this.__layout.affectChildrenSort = affectSort
66
68
  }
67
69
  }
68
70
 
@@ -72,17 +74,23 @@ export class Branch extends Leaf {
72
74
 
73
75
  index === undefined ? this.children.push(child) : this.children.splice(index, 0, child)
74
76
  if (child.isBranch) this.__.__childBranchNumber = (this.__.__childBranchNumber || 0) + 1
75
- child.__layout.boundsChanged || child.__layout.positionChange() // layouted(removed), need update
77
+ child.__layout.boundsChanged || child.__layout.matrixChange() // layouted(removed), need update
76
78
 
77
79
  if (child.__parentWait) WaitHelper.run(child.__parentWait)
78
80
 
79
81
  if (this.leafer) {
80
82
  child.__bindLeafer(this.leafer)
81
- if (this.leafer.ready) this.__emitChildEvent(ChildEvent.ADD, child)
83
+ if (this.leafer.created) this.__emitChildEvent(ChildEvent.ADD, child)
82
84
  }
85
+
86
+ this.__layout.affectChildrenSort && this.__layout.childrenSortChange()
87
+ }
88
+
89
+ public addMany(...children: ILeaf[]): void {
90
+ children.forEach(child => this.add(child))
83
91
  }
84
92
 
85
- public remove(child?: Leaf): void {
93
+ public remove(child?: Leaf, destroy?: boolean): void {
86
94
  if (child) {
87
95
  const index = this.children.indexOf(child)
88
96
  if (index > -1) {
@@ -90,31 +98,45 @@ export class Branch extends Leaf {
90
98
  if (child.isBranch) this.__.__childBranchNumber = (this.__.__childBranchNumber || 1) - 1
91
99
  this.__preRemove()
92
100
  this.__realRemoveChild(child)
101
+ if (destroy) child.destroy()
93
102
  }
94
103
  } else if (child === undefined) {
95
- super.remove()
104
+ super.remove(null, destroy)
96
105
  }
97
106
  }
98
107
 
99
- public removeAll(): void {
108
+ public removeAll(destroy?: boolean): void {
100
109
  const { children } = this
101
- this.children = []
102
- this.__preRemove()
103
- this.__.__childBranchNumber = 0
104
- children.forEach(child => { this.__realRemoveChild(child) })
110
+ if (children.length) {
111
+ this.children = []
112
+ this.__preRemove()
113
+ this.__.__childBranchNumber = 0
114
+ children.forEach(child => {
115
+ this.__realRemoveChild(child)
116
+ if (destroy) child.destroy()
117
+ })
118
+ }
119
+ }
120
+
121
+ public clear(): void {
122
+ this.removeAll(true)
105
123
  }
106
124
 
107
125
  protected __preRemove(): void {
108
126
  if (this.__hasMask) this.__updateMask()
109
127
  if (this.__hasEraser) this.__updateEraser()
110
128
  this.__layout.boxChange()
129
+ this.__layout.affectChildrenSort && this.__layout.childrenSortChange()
111
130
  }
112
131
 
113
132
  protected __realRemoveChild(child: ILeaf): void {
114
133
  child.parent = null
115
134
  if (this.leafer) {
116
135
  child.__bindLeafer(null)
117
- if (this.leafer.ready) this.__emitChildEvent(ChildEvent.REMOVE, child)
136
+ if (this.leafer.created) {
137
+ this.__emitChildEvent(ChildEvent.REMOVE, child)
138
+ if (this.leafer.hitCanvasManager) this.leafer.hitCanvasManager.clear()
139
+ }
118
140
  }
119
141
  }
120
142
 
@@ -124,4 +146,5 @@ export class Branch extends Leaf {
124
146
  if (this.hasEvent(type) && !this.isLeafer) this.emitEvent(event)
125
147
  this.leafer.emitEvent(event)
126
148
  }
149
+
127
150
  }
package/src/Leaf.ts CHANGED
@@ -1,18 +1,21 @@
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, IMatrixData } 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 } 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
8
 
9
9
 
10
10
  const { LEAF, create } = IncrementId
11
+ const { toInnerPoint, toOuterPoint, multiplyParent } = MatrixHelper
12
+ const { toOuterOf } = BoundsHelper
13
+ const { tempToOuterOf, copy } = PointHelper
14
+ const { moveLocal, zoomOfLocal, rotateOfLocal, skewOfLocal, transform, setTransform, drop } = LeafHelper
11
15
 
12
16
  @useModule(LeafDataProxy)
13
17
  @useModule(LeafMatrix)
14
18
  @useModule(LeafBounds)
15
- @useModule(LeafHit)
16
19
  @useModule(LeafEventer)
17
20
  @useModule(LeafRender)
18
21
  export class Leaf implements ILeaf {
@@ -28,7 +31,7 @@ export class Leaf implements ILeaf {
28
31
  public get __DataProcessor() { return LeafData }
29
32
  public get __LayoutProcessor() { return LeafLayout }
30
33
 
31
- public leafer?: ILeafer
34
+ public leafer?: ILeaferBase
32
35
  public parent?: ILeaf
33
36
 
34
37
  public isLeafer: boolean
@@ -38,8 +41,15 @@ export class Leaf implements ILeaf {
38
41
  public __: ILeafData
39
42
  public __layout: ILeafLayout
40
43
 
41
- public __local: IMatrixWithBoundsData
42
- public __world: IMatrixWithBoundsData
44
+ public __world: IMatrixWithBoundsScaleData
45
+ public __local?: IMatrixWithBoundsData // and localStrokeBounds? localRenderBounds?
46
+
47
+ public __nowWorld?: IMatrixWithBoundsScaleData // use __world or __cameraWorld render
48
+ public __cameraWorld?: IMatrixWithBoundsScaleData // use camera matrix render
49
+
50
+ public get __localMatrix(): IMatrixData { return this.__local || this.__layout }
51
+ public get __localBoxBounds(): IBoundsData { return this.__local || this.__layout }
52
+
43
53
  public __worldOpacity: number
44
54
 
45
55
  // now transform
@@ -47,16 +57,21 @@ export class Leaf implements ILeaf {
47
57
  public get localTransform(): IMatrixData { return this.__layout.getTransform('local') }
48
58
 
49
59
  // now bounds
60
+ public get boxBounds(): IBoundsData { return this.getBounds('box', 'inner') }
61
+ public get renderBounds(): IBoundsData { return this.getBounds('render', 'inner') }
50
62
  public get worldBoxBounds(): IBoundsData { return this.getBounds('box') }
51
63
  public get worldStrokeBounds(): IBoundsData { return this.getBounds('stroke') }
52
64
  public get worldRenderBounds(): IBoundsData { return this.getBounds('render') }
53
65
 
54
66
  // now opacity
55
- public get worldOpacity(): number { this.__layout.checkUpdate(); return this.__worldOpacity }
67
+ public get worldOpacity(): number { this.__layout.update(); return this.__worldOpacity }
56
68
 
57
69
  public __level: number // layer level 0 -> branch -> branch -> deep
58
70
  public __tempNumber: number // temp sort
59
71
 
72
+ public get __worldFlipped(): boolean { return this.__world.scaleX < 0 || this.__world.scaleY < 0 }
73
+
74
+ public __hasAutoLayout?: boolean
60
75
  public __hasMask?: boolean
61
76
  public __hasEraser?: boolean
62
77
  public __hitCanvas?: IHitCanvas
@@ -74,19 +89,35 @@ export class Leaf implements ILeaf {
74
89
  // branch
75
90
  public children?: ILeaf[]
76
91
 
77
- constructor(data?: ILeafInputData) {
92
+ // other
93
+ public noBounds?: boolean
94
+
95
+ public destroyed: boolean
78
96
 
97
+
98
+ constructor(data?: ILeafInputData) {
79
99
  this.innerId = create(LEAF)
100
+ this.reset(data)
101
+ }
80
102
 
81
- this.__local = { a: 1, b: 0, c: 0, d: 1, e: 0, f: 0, x: 0, y: 0, width: 0, height: 0 }
82
- this.__world = { a: 1, b: 0, c: 0, d: 1, e: 0, f: 0, x: 0, y: 0, width: 0, height: 0 }
103
+
104
+ public reset(data?: ILeafInputData): void {
105
+
106
+ 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 }
107
+ 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 }
83
108
 
84
109
  this.__worldOpacity = 1
85
110
 
86
111
  this.__ = new this.__DataProcessor(this)
87
112
  this.__layout = new this.__LayoutProcessor(this)
88
113
 
89
- if (data) Object.assign(this, data)
114
+ if (this.__level) this.resetCustom()
115
+ if (data) data.children ? this.set(data) : Object.assign(this, data)
116
+ }
117
+
118
+ public resetCustom(): void {
119
+ this.__hasMask = this.__hasEraser = null
120
+ this.forceUpdate()
90
121
  }
91
122
 
92
123
 
@@ -98,14 +129,24 @@ export class Leaf implements ILeaf {
98
129
  this.leafer ? item() : (this.__leaferWait ? this.__leaferWait.push(item) : this.__leaferWait = [item])
99
130
  }
100
131
 
132
+ public nextRender(item: IFunction, off?: 'off'): void {
133
+ this.leafer ? this.leafer.nextRender(item, off) : this.waitLeafer(() => this.leafer.nextRender(item, off))
134
+ }
135
+
136
+ public __bindLeafer(leafer: ILeaferBase | null): void {
137
+ if (this.isLeafer) {
138
+ if (leafer !== null) leafer = this as unknown as ILeaferBase
139
+ }
101
140
 
102
- public __bindLeafer(leafer: ILeafer | null): void {
103
- if (this.isLeafer) leafer = this as unknown as ILeafer
141
+ if (this.leafer && !leafer) this.leafer.leafs--
104
142
 
105
143
  this.leafer = leafer
106
- this.__level = this.parent ? this.parent.__level + 1 : 1
107
144
 
108
- if (this.__leaferWait && leafer) WaitHelper.run(this.__leaferWait)
145
+ if (leafer) {
146
+ leafer.leafs++
147
+ this.__level = this.parent ? this.parent.__level + 1 : 1
148
+ if (this.__leaferWait) WaitHelper.run(this.__leaferWait)
149
+ }
109
150
 
110
151
  if (this.isBranch) {
111
152
  const { children } = this
@@ -115,25 +156,52 @@ export class Leaf implements ILeaf {
115
156
  }
116
157
  }
117
158
 
159
+ // data
160
+
118
161
  public set(_data: IObject): void { }
162
+ public get(): ILeafInputData { return undefined }
119
163
 
120
- public get(_attrNames?: string[]): IObject { return undefined }
164
+ public toJSON(): IObject {
165
+ return this.__.__getInputData()
166
+ }
121
167
 
168
+ public toString(): string {
169
+ return JSON.stringify(this.toJSON())
170
+ }
122
171
 
123
172
  // LeafDataProxy rewrite
124
173
 
125
- public __setAttr(_attrName: string, _newValue: __Value): void { }
174
+ public __setAttr(_attrName: string, _newValue: IValue): void { }
175
+
176
+ public __getAttr(_attrName: string): IValue { return undefined }
126
177
 
127
- public __getAttr(_attrName: string): __Value { return undefined }
178
+ public setProxyAttr(_attrName: string, _newValue: IValue): void { }
179
+
180
+ public getProxyAttr(_attrName: string): IValue { return undefined }
181
+
182
+ // ---
183
+
184
+
185
+ // find
186
+
187
+ public find(_condition: number | string | IFindMethod, _options?: any): ILeaf[] { return undefined }
188
+
189
+ public findOne(_condition: number | string | IFindMethod, _options?: any): ILeaf { return undefined }
128
190
 
129
191
  // ---
130
192
 
131
193
  public forceUpdate(attrName?: string): void {
132
- if (!attrName) attrName = 'x'
194
+ if (attrName === undefined) attrName = 'width'
195
+ else if (attrName === 'surface') attrName = 'blendMode'
133
196
  const value = this.__.__getInput(attrName);
197
+ (this.__ as any)[attrName] = value === undefined ? null : undefined;
134
198
  (this as any)[attrName] = value
135
199
  }
136
200
 
201
+ public updateLayout(): void {
202
+ this.__layout.update()
203
+ }
204
+
137
205
 
138
206
  // LeafMatrix rewrite
139
207
 
@@ -147,6 +215,8 @@ export class Leaf implements ILeaf {
147
215
 
148
216
  public __updateWorldBounds(): void { }
149
217
 
218
+ public __updateLocalBounds(): void { }
219
+
150
220
 
151
221
  public __updateLocalBoxBounds(): void { }
152
222
 
@@ -163,6 +233,10 @@ export class Leaf implements ILeaf {
163
233
  public __updateRenderBounds(): void { }
164
234
 
165
235
 
236
+ public __updateAutoLayout(): void { }
237
+ public __updateNaturalSize(): void { }
238
+
239
+
166
240
  public __updateStrokeSpread(): number { return 0 }
167
241
 
168
242
  public __updateRenderSpread(): number { return 0 }
@@ -174,70 +248,163 @@ export class Leaf implements ILeaf {
174
248
 
175
249
  // LeafMask rewrite
176
250
 
177
- public __updateEraser(_value?: boolean): void { }
251
+ public __updateEraser(value?: boolean): void {
252
+ this.__hasEraser = value ? true : this.children.some(item => item.__.eraser)
253
+ }
178
254
 
179
- public __updateMask(_value?: boolean): void { }
255
+ public __updateMask(value?: boolean): void {
256
+ this.__hasMask = value ? true : this.children.some(item => item.__.mask)
257
+ }
180
258
 
181
- public __renderMask(_canvas: ILeaferCanvas, _content: ILeaferCanvas, _mask: ILeaferCanvas): void { }
259
+ public __renderMask(_canvas: ILeaferCanvas, _options: IRenderOptions): void { }
182
260
 
183
- public __removeMask(_child?: ILeaf): void { }
184
261
 
185
262
  // ---
186
263
 
187
264
 
188
265
  // convert
189
266
 
190
- public getWorld(attrName: IMatrixDecompositionAttr): number {
191
- return this.__layout.decomposeTransform('world')[attrName]
267
+ public __getNowWorld(options: IRenderOptions): IMatrixWithBoundsScaleData {
268
+ if (options.matrix) {
269
+ if (!this.__cameraWorld) this.__cameraWorld = {} as IMatrixWithBoundsScaleData
270
+ const cameraWorld = this.__cameraWorld
271
+ multiplyParent(this.__world, options.matrix, cameraWorld, undefined, this.__world)
272
+ toOuterOf(this.__layout.renderBounds, cameraWorld, cameraWorld)
273
+ return cameraWorld
274
+ } else {
275
+ return this.__world
276
+ }
192
277
  }
193
278
 
194
- public getBounds(type: ILayoutBoundsType, locationType: ILayoutLocationType = 'world'): IBoundsData {
195
- return this.__layout.getBounds(type, locationType)
279
+
280
+ public getWorld(attrName: ILayoutAttr): number {
281
+ this.__layout.update()
282
+ if (attrName === 'x') return this.__world.e
283
+ if (attrName === 'y') return this.__world.f
284
+ return this.getLayoutBounds()[attrName]
196
285
  }
197
286
 
287
+ public getBounds(type?: IBoundsType, relative?: ILocationType | ILeaf): IBoundsData {
288
+ return this.__layout.getBounds(type, relative)
289
+ }
198
290
 
199
- public worldToLocal(world: IPointData, to?: IPointData, isMovePoint?: boolean): void {
291
+ public getLayoutBounds(type?: IBoundsType, relative?: ILocationType | ILeaf, unscale?: boolean): ILayoutBoundsData {
292
+ return this.__layout.getLayoutBounds(type, relative, unscale)
293
+ }
294
+
295
+ public getLayoutPoints(type?: IBoundsType, relative?: ILocationType | ILeaf): IPointData[] {
296
+ return this.__layout.getLayoutPoints(type, relative)
297
+ }
298
+
299
+
300
+ public worldToLocal(world: IPointData, to?: IPointData, distance?: boolean, relative?: ILeaf): void {
200
301
  if (this.parent) {
201
- MatrixHelper.toInnerPoint(this.parent.worldTransform, world, to, isMovePoint)
302
+ this.parent.worldToInner(world, to, distance, relative)
202
303
  } else {
203
- if (to) PointHelper.copy(to, world)
304
+ if (to) copy(to, world)
204
305
  }
205
306
  }
206
307
 
207
- public localToWorld(local: IPointData, to?: IPointData, isMovePoint?: boolean): void {
308
+ public localToWorld(local: IPointData, to?: IPointData, distance?: boolean, relative?: ILeaf): void {
208
309
  if (this.parent) {
209
- MatrixHelper.toOuterPoint(this.parent.worldTransform, local, to, isMovePoint)
310
+ this.parent.innerToWorld(local, to, distance, relative)
210
311
  } else {
211
- if (to) PointHelper.copy(to, local)
312
+ if (to) copy(to, local)
212
313
  }
213
314
  }
214
315
 
215
- public worldToInner(world: IPointData, to?: IPointData, isMovePoint?: boolean): void {
216
- MatrixHelper.toInnerPoint(this.worldTransform, world, to, isMovePoint)
316
+ public worldToInner(world: IPointData, to?: IPointData, distance?: boolean, relative?: ILeaf): void {
317
+ if (relative) {
318
+ relative.innerToWorld(world, to, distance)
319
+ world = to ? to : world
320
+ }
321
+ toInnerPoint(this.worldTransform, world, to, distance)
217
322
  }
218
323
 
219
- public innerToWorld(inner: IPointData, to?: IPointData, isMovePoint?: boolean): void {
220
- MatrixHelper.toOuterPoint(this.worldTransform, inner, to, isMovePoint)
324
+ public innerToWorld(inner: IPointData, to?: IPointData, distance?: boolean, relative?: ILeaf): void {
325
+ toOuterPoint(this.worldTransform, inner, to, distance)
326
+ if (relative) relative.worldToInner(to ? to : inner, null, distance)
327
+ }
328
+
329
+ // simple
330
+
331
+ public getInnerPoint(world: IPointData, relative?: ILeaf, distance?: boolean, change?: boolean): IPointData {
332
+ const point = change ? world : {} as IPointData
333
+ this.worldToInner(world, point, distance, relative)
334
+ return point
335
+ }
336
+
337
+ public getInnerPointByLocal(local: IPointData, _relative?: ILeaf, distance?: boolean, change?: boolean): IPointData {
338
+ return this.getInnerPoint(local, this.parent, distance, change)
339
+ }
340
+
341
+ public getLocalPoint(world: IPointData, relative?: ILeaf, distance?: boolean, change?: boolean): IPointData {
342
+ const point = change ? world : {} as IPointData
343
+ this.worldToLocal(world, point, distance, relative)
344
+ return point
345
+ }
346
+
347
+ public getLocalPointByInner(inner: IPointData, _relative?: ILeaf, distance?: boolean, change?: boolean): IPointData {
348
+ return this.getWorldPoint(inner, this.parent, distance, change)
349
+ }
350
+
351
+ public getWorldPoint(inner: IPointData, relative?: ILeaf, distance?: boolean, change?: boolean): IPointData {
352
+ const point = change ? inner : {} as IPointData
353
+ this.innerToWorld(inner, point, distance, relative)
354
+ return point
355
+ }
356
+
357
+ public getWorldPointByLocal(local: IPointData, relative?: ILeaf, distance?: boolean, change?: boolean): IPointData {
358
+ const point = change ? local : {} as IPointData
359
+ this.localToWorld(local, point, distance, relative)
360
+ return point
361
+ }
362
+
363
+ public getPagePoint(world: IPointData, relative?: ILeaf, distance?: boolean, change?: boolean): IPointData {
364
+ const layer = this.leafer ? this.leafer.zoomLayer : this
365
+ return layer.getInnerPoint(world, relative, distance, change)
366
+ }
367
+
368
+ public getWorldPointByPage(page: IPointData, relative?: ILeaf, distance?: boolean, change?: boolean): IPointData {
369
+ const layer = this.leafer ? this.leafer.zoomLayer : this
370
+ return layer.getWorldPoint(page, relative, distance, change)
221
371
  }
222
372
 
223
373
 
224
374
  // transform
225
375
 
376
+ public setTransform(matrix: IMatrixData, resize?: boolean): void {
377
+ setTransform(this, matrix, resize)
378
+ }
379
+
380
+ public transform(matrix: IMatrixData, resize?: boolean): void {
381
+ transform(this, matrix, resize)
382
+ }
383
+
226
384
  public move(x: number, y?: number): void {
227
- LeafHelper.moveLocal(this, x, y)
385
+ moveLocal(this, x, y)
386
+ }
387
+
388
+ public scaleOf(origin: IPointData, scaleX: number, scaleY?: number, resize?: boolean): void {
389
+ zoomOfLocal(this, tempToOuterOf(origin, this.localTransform), scaleX, scaleY, resize)
390
+ }
391
+
392
+ public rotateOf(origin: IPointData, rotation: number): void {
393
+ rotateOfLocal(this, tempToOuterOf(origin, this.localTransform), rotation)
228
394
  }
229
395
 
230
- public scaleOf(origin: IPointData, x: number, y?: number): void {
231
- this.__layout.checkUpdate()
232
- if (y === undefined) y = x
233
- LeafHelper.zoomOfLocal(this, PointHelper.tempToOuterOf(origin, this.__local), x, y)
396
+ public skewOf(origin: IPointData, skewX: number, skewY?: number, resize?: boolean): void {
397
+ skewOfLocal(this, tempToOuterOf(origin, this.localTransform), skewX, skewY, resize)
234
398
  }
235
399
 
236
- public rotateOf(origin: IPointData, angle: number): void {
237
- this.__layout.checkUpdate()
238
- LeafHelper.rotateOfLocal(this, PointHelper.tempToOuterOf(origin, this.__local), angle)
400
+ // @leafer-in/scale rewrite
401
+
402
+ public scaleResize(scaleX: number, scaleY = scaleX, _noResize?: boolean): void {
403
+ (this as ILeaf).scaleX *= scaleX;
404
+ (this as ILeaf).scaleY *= scaleY
239
405
  }
240
406
 
407
+ public __scaleResize(_scaleX: number, _scaleY: number): void { }
241
408
 
242
409
  // LeafHit rewrite
243
410
 
@@ -245,7 +412,17 @@ export class Leaf implements ILeaf {
245
412
 
246
413
  public __hit(_local: IRadiusPointData): boolean { return true }
247
414
 
248
- public __drawHitPath(_canvas: ILeaferCanvas): void { }
415
+ public __hitFill(inner: IRadiusPointData, windingRule?: string): boolean {
416
+ return this.__hitCanvas?.hitFill(inner, windingRule)
417
+ }
418
+
419
+ public __hitStroke(inner: IRadiusPointData, strokeWidth: number): boolean {
420
+ return this.__hitCanvas?.hitStroke(inner, strokeWidth)
421
+ }
422
+
423
+ public __drawHitPath(canvas: ILeaferCanvas): void {
424
+ if (canvas) this.__drawRenderPath(canvas)
425
+ }
249
426
 
250
427
  public __updateHitCanvas(): void { }
251
428
 
@@ -260,6 +437,9 @@ export class Leaf implements ILeaf {
260
437
 
261
438
  public __draw(_canvas: ILeaferCanvas, _options: IRenderOptions): void { }
262
439
 
440
+
441
+ public __clip(_canvas: ILeaferCanvas, _options: IRenderOptions): void { }
442
+
263
443
  public __renderShape(_canvas: ILeaferCanvas, _options: IRenderOptions): void { }
264
444
 
265
445
 
@@ -287,8 +467,12 @@ export class Leaf implements ILeaf {
287
467
 
288
468
  public add(_child: ILeaf, _index?: number): void { }
289
469
 
290
- public remove(_child?: ILeaf): void {
291
- if (this.parent) this.parent.remove(this)
470
+ public remove(_child?: ILeaf, destroy?: boolean): void {
471
+ if (this.parent) this.parent.remove(this, destroy)
472
+ }
473
+
474
+ public dropTo(parent: ILeaf, index?: number, resize?: boolean): void {
475
+ drop(this, parent, index, resize)
292
476
  }
293
477
 
294
478
  // ---
@@ -314,28 +498,26 @@ export class Leaf implements ILeaf {
314
498
 
315
499
  // ---
316
500
 
317
- public destroy(): void {
318
- if (this.__) {
319
- if (this.__hitCanvas) {
320
- this.__hitCanvas.destroy()
321
- this.__hitCanvas = null
322
- }
501
+ static changeAttr(attrName: string, defaultValue: IValue): void {
502
+ defineDataProcessor(this.prototype, attrName, defaultValue)
503
+ }
323
504
 
324
- this.leafer = null
325
- this.parent = null
505
+ static addAttr(attrName: string, defaultValue: IValue, fn?: IAttrDecorator): void {
506
+ if (!fn) fn = boundsType
507
+ fn(defaultValue)(this.prototype, attrName)
508
+ }
509
+
510
+
511
+ public destroy(): void {
512
+ if (!this.destroyed) {
513
+ if (this.parent) this.remove()
514
+ if (this.children) (this as unknown as IBranch).removeAll(true)
326
515
 
327
516
  this.__.destroy()
328
517
  this.__layout.destroy()
329
- this.__ = null
330
- this.__layout = null
331
518
 
332
- this.__captureMap = null
333
- this.__bubbleMap = null
334
-
335
- if (this.children) {
336
- this.children.forEach(child => { child.destroy() })
337
- this.children.length = 0
338
- }
519
+ this.__captureMap = this.__bubbleMap = this.__parentWait = this.__leaferWait = null
520
+ this.destroyed = true
339
521
  }
340
522
  }
341
523
 
@@ -0,0 +1,165 @@
1
+ import { ILeaf, InnerId, ILeaferBase, ILeafData, ILeafLayout, IMatrixWithBoundsScaleData, IMatrixWithBoundsData, IMatrixData, IBoundsData, IHitCanvas, IEventListenerMap, IFunction, ILeafInputData, IObject, IValue, IFindMethod, ILeaferCanvas, IRenderOptions, ILayoutAttr, IBoundsType, ILocationType, ILayoutBoundsData, IPointData, IRadiusPointData, IEventListener, IEventListenerOptions, IEventListenerId, IEvent, IAttrDecorator } from '@leafer/interface';
2
+ import { LeafData } from '@leafer/data';
3
+ import { LeafLayout } from '@leafer/layout';
4
+
5
+ declare class Leaf implements ILeaf {
6
+ get tag(): string;
7
+ set tag(_value: string);
8
+ get __tag(): string;
9
+ readonly innerId: InnerId;
10
+ get innerName(): string;
11
+ get __DataProcessor(): typeof LeafData;
12
+ get __LayoutProcessor(): typeof LeafLayout;
13
+ leafer?: ILeaferBase;
14
+ parent?: ILeaf;
15
+ isLeafer: boolean;
16
+ isBranch: boolean;
17
+ isBranchLeaf: boolean;
18
+ __: ILeafData;
19
+ __layout: ILeafLayout;
20
+ __world: IMatrixWithBoundsScaleData;
21
+ __local?: IMatrixWithBoundsData;
22
+ __nowWorld?: IMatrixWithBoundsScaleData;
23
+ __cameraWorld?: IMatrixWithBoundsScaleData;
24
+ get __localMatrix(): IMatrixData;
25
+ get __localBoxBounds(): IBoundsData;
26
+ __worldOpacity: number;
27
+ get worldTransform(): IMatrixData;
28
+ get localTransform(): IMatrixData;
29
+ get boxBounds(): IBoundsData;
30
+ get renderBounds(): IBoundsData;
31
+ get worldBoxBounds(): IBoundsData;
32
+ get worldStrokeBounds(): IBoundsData;
33
+ get worldRenderBounds(): IBoundsData;
34
+ get worldOpacity(): number;
35
+ __level: number;
36
+ __tempNumber: number;
37
+ get __worldFlipped(): boolean;
38
+ __hasAutoLayout?: boolean;
39
+ __hasMask?: boolean;
40
+ __hasEraser?: boolean;
41
+ __hitCanvas?: IHitCanvas;
42
+ get __onlyHitMask(): boolean;
43
+ get __ignoreHitWorld(): boolean;
44
+ __captureMap?: IEventListenerMap;
45
+ __bubbleMap?: IEventListenerMap;
46
+ __parentWait?: IFunction[];
47
+ __leaferWait?: IFunction[];
48
+ children?: ILeaf[];
49
+ noBounds?: boolean;
50
+ destroyed: boolean;
51
+ constructor(data?: ILeafInputData);
52
+ reset(data?: ILeafInputData): void;
53
+ resetCustom(): void;
54
+ waitParent(item: IFunction): void;
55
+ waitLeafer(item: IFunction): void;
56
+ nextRender(item: IFunction, off?: 'off'): void;
57
+ __bindLeafer(leafer: ILeaferBase | null): void;
58
+ set(_data: IObject): void;
59
+ get(): ILeafInputData;
60
+ toJSON(): IObject;
61
+ toString(): string;
62
+ __setAttr(_attrName: string, _newValue: IValue): void;
63
+ __getAttr(_attrName: string): IValue;
64
+ setProxyAttr(_attrName: string, _newValue: IValue): void;
65
+ getProxyAttr(_attrName: string): IValue;
66
+ find(_condition: number | string | IFindMethod, _options?: any): ILeaf[];
67
+ findOne(_condition: number | string | IFindMethod, _options?: any): ILeaf;
68
+ forceUpdate(attrName?: string): void;
69
+ updateLayout(): void;
70
+ __updateWorldMatrix(): void;
71
+ __updateLocalMatrix(): void;
72
+ __updateWorldBounds(): void;
73
+ __updateLocalBounds(): void;
74
+ __updateLocalBoxBounds(): void;
75
+ __updateLocalStrokeBounds(): void;
76
+ __updateLocalRenderBounds(): void;
77
+ __updateBoxBounds(): void;
78
+ __updateStrokeBounds(): void;
79
+ __updateRenderBounds(): void;
80
+ __updateAutoLayout(): void;
81
+ __updateNaturalSize(): void;
82
+ __updateStrokeSpread(): number;
83
+ __updateRenderSpread(): number;
84
+ __onUpdateSize(): void;
85
+ __updateEraser(value?: boolean): void;
86
+ __updateMask(value?: boolean): void;
87
+ __renderMask(_canvas: ILeaferCanvas, _options: IRenderOptions): void;
88
+ __getNowWorld(options: IRenderOptions): IMatrixWithBoundsScaleData;
89
+ getWorld(attrName: ILayoutAttr): number;
90
+ getBounds(type?: IBoundsType, relative?: ILocationType | ILeaf): IBoundsData;
91
+ getLayoutBounds(type?: IBoundsType, relative?: ILocationType | ILeaf, unscale?: boolean): ILayoutBoundsData;
92
+ getLayoutPoints(type?: IBoundsType, relative?: ILocationType | ILeaf): IPointData[];
93
+ worldToLocal(world: IPointData, to?: IPointData, distance?: boolean, relative?: ILeaf): void;
94
+ localToWorld(local: IPointData, to?: IPointData, distance?: boolean, relative?: ILeaf): void;
95
+ worldToInner(world: IPointData, to?: IPointData, distance?: boolean, relative?: ILeaf): void;
96
+ innerToWorld(inner: IPointData, to?: IPointData, distance?: boolean, relative?: ILeaf): void;
97
+ getInnerPoint(world: IPointData, relative?: ILeaf, distance?: boolean, change?: boolean): IPointData;
98
+ getInnerPointByLocal(local: IPointData, _relative?: ILeaf, distance?: boolean, change?: boolean): IPointData;
99
+ getLocalPoint(world: IPointData, relative?: ILeaf, distance?: boolean, change?: boolean): IPointData;
100
+ getLocalPointByInner(inner: IPointData, _relative?: ILeaf, distance?: boolean, change?: boolean): IPointData;
101
+ getWorldPoint(inner: IPointData, relative?: ILeaf, distance?: boolean, change?: boolean): IPointData;
102
+ getWorldPointByLocal(local: IPointData, relative?: ILeaf, distance?: boolean, change?: boolean): IPointData;
103
+ getPagePoint(world: IPointData, relative?: ILeaf, distance?: boolean, change?: boolean): IPointData;
104
+ getWorldPointByPage(page: IPointData, relative?: ILeaf, distance?: boolean, change?: boolean): IPointData;
105
+ setTransform(matrix: IMatrixData, resize?: boolean): void;
106
+ transform(matrix: IMatrixData, resize?: boolean): void;
107
+ move(x: number, y?: number): void;
108
+ scaleOf(origin: IPointData, scaleX: number, scaleY?: number, resize?: boolean): void;
109
+ rotateOf(origin: IPointData, rotation: number): void;
110
+ skewOf(origin: IPointData, skewX: number, skewY?: number, resize?: boolean): void;
111
+ scaleResize(scaleX: number, scaleY?: number, _noResize?: boolean): void;
112
+ __scaleResize(_scaleX: number, _scaleY: number): void;
113
+ __hitWorld(_point: IRadiusPointData): boolean;
114
+ __hit(_local: IRadiusPointData): boolean;
115
+ __hitFill(inner: IRadiusPointData, windingRule?: string): boolean;
116
+ __hitStroke(inner: IRadiusPointData, strokeWidth: number): boolean;
117
+ __drawHitPath(canvas: ILeaferCanvas): void;
118
+ __updateHitCanvas(): void;
119
+ __render(_canvas: ILeaferCanvas, _options: IRenderOptions): void;
120
+ __drawFast(_canvas: ILeaferCanvas, _options: IRenderOptions): void;
121
+ __draw(_canvas: ILeaferCanvas, _options: IRenderOptions): void;
122
+ __clip(_canvas: ILeaferCanvas, _options: IRenderOptions): void;
123
+ __renderShape(_canvas: ILeaferCanvas, _options: IRenderOptions): void;
124
+ __updateWorldOpacity(): void;
125
+ __updateChange(): void;
126
+ __drawPath(_canvas: ILeaferCanvas): void;
127
+ __drawRenderPath(_canvas: ILeaferCanvas): void;
128
+ __updatePath(): void;
129
+ __updateRenderPath(): void;
130
+ __updateSortChildren(): void;
131
+ add(_child: ILeaf, _index?: number): void;
132
+ remove(_child?: ILeaf, destroy?: boolean): void;
133
+ dropTo(parent: ILeaf, index?: number, resize?: boolean): void;
134
+ on(_type: string | string[], _listener: IEventListener, _options?: IEventListenerOptions | boolean): void;
135
+ off(_type: string | string[], _listener: IEventListener, _options?: IEventListenerOptions | boolean): void;
136
+ on_(_type: string | string[], _listener: IEventListener, _bind?: IObject, _options?: IEventListenerOptions | boolean): IEventListenerId;
137
+ off_(_id: IEventListenerId | IEventListenerId[]): void;
138
+ once(_type: string | string[], _listener: IEventListener, _capture?: boolean): void;
139
+ emit(_type: string, _event?: IEvent | IObject, _capture?: boolean): void;
140
+ emitEvent(_event?: IEvent, _capture?: boolean): void;
141
+ hasEvent(_type: string, _capture?: boolean): boolean;
142
+ static changeAttr(attrName: string, defaultValue: IValue): void;
143
+ static addAttr(attrName: string, defaultValue: IValue, fn?: IAttrDecorator): void;
144
+ destroy(): void;
145
+ }
146
+
147
+ declare class Branch extends Leaf {
148
+ constructor();
149
+ __updateStrokeSpread(): number;
150
+ __updateRenderSpread(): number;
151
+ __updateBoxBounds(): void;
152
+ __updateStrokeBounds(): void;
153
+ __updateRenderBounds(): void;
154
+ __updateSortChildren(): void;
155
+ add(child: ILeaf, index?: number): void;
156
+ addMany(...children: ILeaf[]): void;
157
+ remove(child?: Leaf, destroy?: boolean): void;
158
+ removeAll(destroy?: boolean): void;
159
+ clear(): void;
160
+ protected __preRemove(): void;
161
+ protected __realRemoveChild(child: ILeaf): void;
162
+ protected __emitChildEvent(type: string, child: ILeaf): void;
163
+ }
164
+
165
+ export { Branch, Leaf };