@leafer/display 1.0.0-rc.3 → 1.0.0-rc.30

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.3",
3
+ "version": "1.0.0-rc.30",
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.3",
26
- "@leafer/data": "1.0.0-rc.3",
27
- "@leafer/layout": "1.0.0-rc.3",
28
- "@leafer/display-module": "1.0.0-rc.3",
29
- "@leafer/event": "1.0.0-rc.3",
30
- "@leafer/decorator": "1.0.0-rc.3",
31
- "@leafer/helper": "1.0.0-rc.3",
32
- "@leafer/platform": "1.0.0-rc.3"
25
+ "@leafer/math": "1.0.0-rc.30",
26
+ "@leafer/data": "1.0.0-rc.30",
27
+ "@leafer/layout": "1.0.0-rc.30",
28
+ "@leafer/display-module": "1.0.0-rc.30",
29
+ "@leafer/event": "1.0.0-rc.30",
30
+ "@leafer/decorator": "1.0.0-rc.30",
31
+ "@leafer/helper": "1.0.0-rc.30",
32
+ "@leafer/platform": "1.0.0-rc.30"
33
33
  },
34
34
  "devDependencies": {
35
- "@leafer/interface": "1.0.0-rc.3"
35
+ "@leafer/interface": "1.0.0-rc.30"
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, IMatrixData, IAttrDecorator, IMatrixWithBoundsScaleData, IMatrixWithScaleData, IAlign, IJSONOptions } 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 { tempToOuterOf, copy } = PointHelper
13
- const { moveLocal, zoomOfLocal, rotateOfLocal, skewOfLocal } = 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, 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 {
@@ -31,47 +32,56 @@ 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
72
79
 
73
80
  public get __onlyHitMask(): boolean { return this.__hasMask && !this.__.hitChildren }
74
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 }
75
85
 
76
86
  // event
77
87
  public __captureMap?: IEventListenerMap
@@ -83,52 +93,70 @@ export class Leaf implements ILeaf {
83
93
  // branch
84
94
  public children?: ILeaf[]
85
95
 
96
+ // other
97
+ public noBounds?: boolean
86
98
 
87
99
  public destroyed: boolean
88
100
 
89
101
 
90
102
  constructor(data?: ILeafInputData) {
91
-
92
103
  this.innerId = create(LEAF)
104
+ this.reset(data)
105
+ }
93
106
 
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 }
107
+
108
+ public reset(data?: ILeafInputData): void {
109
+
110
+ 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 }
111
+ 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
112
 
97
113
  this.__worldOpacity = 1
98
114
 
99
115
  this.__ = new this.__DataProcessor(this)
100
116
  this.__layout = new this.__LayoutProcessor(this)
101
117
 
118
+ if (this.__level) this.resetCustom()
102
119
  if (data) {
103
- if (data.children) {
104
- this.set(data)
105
- } else {
106
- Object.assign(this, data)
107
- }
120
+ if ((data as ILeaf).__) data = (data as ILeaf).toJSON()
121
+ data.children ? this.set(data) : Object.assign(this, data)
108
122
  }
109
123
  }
110
124
 
125
+ public resetCustom(): void {
126
+ this.__hasMask = this.__hasEraser = null
127
+ this.forceUpdate()
128
+ }
129
+
111
130
 
112
- public waitParent(item: IFunction): void {
131
+ public waitParent(item: IFunction, bind?: IObject): void {
132
+ if (bind) item = item.bind(bind)
113
133
  this.parent ? item() : (this.__parentWait ? this.__parentWait.push(item) : this.__parentWait = [item])
114
134
  }
115
135
 
116
- public waitLeafer(item: IFunction): void {
136
+ public waitLeafer(item: IFunction, bind?: IObject): void {
137
+ if (bind) item = item.bind(bind)
117
138
  this.leafer ? item() : (this.__leaferWait ? this.__leaferWait.push(item) : this.__leaferWait = [item])
118
139
  }
119
140
 
120
- public nextRender(item: IFunction): void {
121
- this.leafer ? this.leafer.nextRender(item) : this.waitLeafer(() => this.leafer.nextRender(item))
141
+ public nextRender(item: IFunction, bind?: IObject, off?: 'off'): void {
142
+ this.leafer ? this.leafer.nextRender(item, bind, off) : this.waitLeafer(() => this.leafer.nextRender(item, bind, off))
143
+ }
144
+
145
+ public removeNextRender(item: IFunction): void {
146
+ this.nextRender(item, null, 'off')
122
147
  }
123
148
 
124
- public __bindLeafer(leafer: ILeafer | null): void {
149
+ public __bindLeafer(leafer: ILeaferBase | null): void {
125
150
  if (this.isLeafer) {
126
- if (leafer !== null) leafer = this as unknown as ILeafer
151
+ if (leafer !== null) leafer = this as unknown as ILeaferBase
127
152
  }
128
153
 
154
+ if (this.leafer && !leafer) this.leafer.leafs--
155
+
129
156
  this.leafer = leafer
130
157
 
131
158
  if (leafer) {
159
+ leafer.leafs++
132
160
  this.__level = this.parent ? this.parent.__level + 1 : 1
133
161
  if (this.__leaferWait) WaitHelper.run(this.__leaferWait)
134
162
  }
@@ -144,31 +172,75 @@ export class Leaf implements ILeaf {
144
172
  // data
145
173
 
146
174
  public set(_data: IObject): void { }
175
+ public get(_name?: string): ILeafInputData | IValue { return undefined }
176
+
177
+ public setAttr(name: string, value: any): void { (this as IObject)[name] = value }
178
+ public getAttr(name: string): any { return (this as IObject)[name] }
147
179
 
148
- public toJSON(): IObject {
149
- return this.__.__getInputData()
180
+ public getComputedAttr(name: string): any { return (this.__ as IObject)[name] }
181
+
182
+ public toJSON(options?: IJSONOptions): IObject {
183
+ if (options) this.__layout.update()
184
+ return this.__.__getInputData(null, options)
150
185
  }
151
186
 
152
- public toString(): string {
153
- return JSON.stringify(this.toJSON())
187
+ public toString(options?: IJSONOptions): string {
188
+ return JSON.stringify(this.toJSON(options))
154
189
  }
155
190
 
191
+ public toSVG(): string { return undefined }
192
+
193
+ public __SVG(_data: IObject): void { }
194
+
195
+ public toHTML(): string { return undefined }
196
+
156
197
  // LeafDataProxy rewrite
157
198
 
158
- public __setAttr(_attrName: string, _newValue: __Value): void { }
199
+ public __setAttr(_attrName: string, _newValue: IValue): boolean { return true }
200
+
201
+ public __getAttr(_attrName: string): IValue { return undefined }
202
+
203
+ public setProxyAttr(_attrName: string, _newValue: IValue): void { }
204
+
205
+ public getProxyAttr(_attrName: string): IValue { return undefined }
206
+
207
+ // ---
208
+
209
+
210
+ // find
211
+
212
+ public find(_condition: number | string | IFindMethod, _options?: any): ILeaf[] { return undefined }
213
+
214
+ public findTag(_tag: string | string[]): ILeaf[] { return undefined }
215
+
216
+ public findOne(_condition: number | string | IFindMethod, _options?: any): ILeaf | undefined { return undefined }
217
+
218
+ public findId(_id: number | string): ILeaf | undefined { return undefined }
159
219
 
160
- public __getAttr(_attrName: string): __Value { return undefined }
220
+ // ---
221
+
222
+
223
+ // state
224
+
225
+ public focus(_value?: boolean): void { }
161
226
 
162
227
  // ---
163
228
 
229
+ public updateLayout(): void {
230
+ this.__layout.update()
231
+ }
232
+
164
233
  public forceUpdate(attrName?: string): void {
165
- if (attrName === undefined) attrName = 'scaleX'
234
+ if (attrName === undefined) attrName = 'width'
166
235
  else if (attrName === 'surface') attrName = 'blendMode'
167
- const value = this.__.__getInput(attrName)
168
- this.__[attrName] = value === undefined ? null : undefined;
236
+ const value = this.__.__getInput(attrName);
237
+ (this.__ as any)[attrName] = value === undefined ? null : undefined;
169
238
  (this as any)[attrName] = value
170
239
  }
171
240
 
241
+ public forceRender(_bounds?: IBoundsData): void {
242
+ this.forceUpdate('surface')
243
+ }
172
244
 
173
245
  // LeafMatrix rewrite
174
246
 
@@ -182,6 +254,8 @@ export class Leaf implements ILeaf {
182
254
 
183
255
  public __updateWorldBounds(): void { }
184
256
 
257
+ public __updateLocalBounds(): void { }
258
+
185
259
 
186
260
  public __updateLocalBoxBounds(): void { }
187
261
 
@@ -193,11 +267,17 @@ export class Leaf implements ILeaf {
193
267
 
194
268
  public __updateBoxBounds(): void { }
195
269
 
270
+ public __updateContentBounds(): void { }
271
+
196
272
  public __updateStrokeBounds(): void { }
197
273
 
198
274
  public __updateRenderBounds(): void { }
199
275
 
200
276
 
277
+ public __updateAutoLayout(): void { }
278
+
279
+ public __updateFlowLayout(): void { }
280
+
201
281
  public __updateNaturalSize(): void { }
202
282
 
203
283
 
@@ -210,30 +290,67 @@ export class Leaf implements ILeaf {
210
290
  // ---
211
291
 
212
292
 
213
- // LeafMask rewrite
293
+ public __updateEraser(value?: boolean): void {
294
+ this.__hasEraser = value ? true : this.children.some(item => item.__.eraser)
295
+ }
296
+
297
+ public __renderEraser(canvas: ILeaferCanvas, options: IRenderOptions): void { // path eraser
298
+ canvas.save()
299
+ this.__clip(canvas, options)
300
+ const { renderBounds: r } = this.__layout
301
+ canvas.clearRect(r.x, r.y, r.width, r.height)
302
+ canvas.restore()
303
+ }
214
304
 
215
- public __updateEraser(_value?: boolean): void { }
305
+ public __updateMask(value?: boolean): void {
306
+ this.__hasMask = value ? true : this.children.some(item => item.__.mask)
307
+ }
216
308
 
217
- public __updateMask(_value?: boolean): void { }
309
+ // LeafMask rewrite
218
310
 
219
- public __renderMask(_canvas: ILeaferCanvas, _content: ILeaferCanvas, _mask: ILeaferCanvas): void { }
311
+ public __renderMask(_canvas: ILeaferCanvas, _options: IRenderOptions): void { }
220
312
 
221
- public __removeMask(_child?: ILeaf): void { }
222
313
 
223
314
  // ---
224
315
 
225
316
 
226
317
  // convert
227
318
 
228
- public getWorld(attrName: IMatrixDecompositionAttr): number {
229
- this.__layout.checkUpdate()
230
- if (attrName === 'x') return this.__world.e
231
- if (attrName === 'y') return this.__world.f
232
- return this.__world[attrName]
319
+ public __getNowWorld(options: IRenderOptions): IMatrixWithBoundsScaleData {
320
+ if (options.matrix) {
321
+ if (!this.__cameraWorld) this.__cameraWorld = {} as IMatrixWithBoundsScaleData
322
+ const cameraWorld = this.__cameraWorld
323
+ multiplyParent(this.__world, options.matrix, cameraWorld, undefined, this.__world)
324
+ toOuterOf(this.__layout.renderBounds, cameraWorld, cameraWorld)
325
+ return cameraWorld
326
+ } else {
327
+ return this.__world
328
+ }
329
+ }
330
+
331
+ public getTransform(relative?: ILocationType | ILeaf): IMatrixData {
332
+ return this.__layout.getTransform(relative || 'local')
333
+ }
334
+
335
+
336
+ public getBounds(type?: IBoundsType, relative?: ILocationType | ILeaf): IBoundsData {
337
+ return this.__layout.getBounds(type, relative)
233
338
  }
234
339
 
235
- public getBounds(type: ILayoutBoundsType, locationType: ILayoutLocationType = 'world'): IBoundsData {
236
- return this.__layout.getBounds(type, locationType)
340
+ public getLayoutBounds(type?: IBoundsType, relative?: ILocationType | ILeaf, unscale?: boolean): ILayoutBoundsData {
341
+ return this.__layout.getLayoutBounds(type, relative, unscale)
342
+ }
343
+
344
+ public getLayoutPoints(type?: IBoundsType, relative?: ILocationType | ILeaf): IPointData[] {
345
+ return this.__layout.getLayoutPoints(type, relative)
346
+ }
347
+
348
+
349
+ public getWorldBounds(inner: IBoundsData, relative?: ILeaf, change?: boolean): IBoundsData {
350
+ const matrix = relative ? getRelativeWorld(this, relative) : this.worldTransform
351
+ const to = change ? inner : {} as IBoundsData
352
+ toOuterOf(inner, matrix, to)
353
+ return to
237
354
  }
238
355
 
239
356
 
@@ -300,32 +417,91 @@ export class Leaf implements ILeaf {
300
417
  return point
301
418
  }
302
419
 
420
+ public getPagePoint(world: IPointData, relative?: ILeaf, distance?: boolean, change?: boolean): IPointData {
421
+ const layer = this.leafer ? this.leafer.zoomLayer : this
422
+ return layer.getInnerPoint(world, relative, distance, change)
423
+ }
424
+
425
+ public getWorldPointByPage(page: IPointData, relative?: ILeaf, distance?: boolean, change?: boolean): IPointData {
426
+ const layer = this.leafer ? this.leafer.zoomLayer : this
427
+ return layer.getWorldPoint(page, relative, distance, change)
428
+ }
429
+
430
+
431
+ // transform
432
+
433
+ public setTransform(matrix: IMatrixData, resize?: boolean): void {
434
+ setTransform(this, matrix, resize)
435
+ }
303
436
 
304
- // transform
437
+ public transform(matrix: IMatrixData, resize?: boolean): void {
438
+ transform(this, matrix, resize)
439
+ }
305
440
 
306
- public move(x: number, y?: number): void {
441
+ public move(x: number | IPointData, y?: number): void {
307
442
  moveLocal(this, x, y)
308
443
  }
309
444
 
310
- public scaleOf(origin: IPointData, x: number, y?: number): void {
311
- zoomOfLocal(this, tempToOuterOf(origin, this.localTransform), x, y)
445
+ public scaleOf(origin: IPointData | IAlign, scaleX: number, scaleY?: number, resize?: boolean): void {
446
+ zoomOfLocal(this, getLocalOrigin(this, origin), scaleX, scaleY, resize)
447
+ }
448
+
449
+ public rotateOf(origin: IPointData | IAlign, rotation: number): void {
450
+ rotateOfLocal(this, getLocalOrigin(this, origin), rotation)
451
+ }
452
+
453
+ public skewOf(origin: IPointData | IAlign, skewX: number, skewY?: number, resize?: boolean): void {
454
+ skewOfLocal(this, getLocalOrigin(this, origin), skewX, skewY, resize)
455
+ }
456
+
457
+ public transformWorld(worldTransform?: IMatrixData, resize?: boolean): void {
458
+ transformWorld(this, worldTransform, resize)
459
+ }
460
+
461
+ public moveWorld(x: number | IPointData, y?: number): void {
462
+ moveWorld(this, x, y)
463
+ }
464
+
465
+ public scaleOfWorld(worldOrigin: IPointData, scaleX: number, scaleY?: number, resize?: boolean): void {
466
+ zoomOfWorld(this, worldOrigin, scaleX, scaleY, resize)
467
+ }
468
+
469
+ public rotateOfWorld(worldOrigin: IPointData, rotation: number): void {
470
+ rotateOfWorld(this, worldOrigin, rotation)
312
471
  }
313
472
 
314
- public rotateOf(origin: IPointData, angle: number): void {
315
- rotateOfLocal(this, tempToOuterOf(origin, this.localTransform), angle)
473
+ public skewOfWorld(worldOrigin: IPointData, skewX: number, skewY?: number, resize?: boolean): void {
474
+ skewOfWorld(this, worldOrigin, skewX, skewY, resize)
316
475
  }
317
476
 
318
- public skewOf(origin: IPointData, x: number, y: number): void {
319
- skewOfLocal(this, tempToOuterOf(origin, this.localTransform), x, y)
477
+
478
+ // @leafer-in/resize rewrite
479
+
480
+ public scaleResize(scaleX: number, scaleY = scaleX, _noResize?: boolean): void {
481
+ (this as ILeaf).scaleX *= scaleX;
482
+ (this as ILeaf).scaleY *= scaleY
320
483
  }
321
484
 
485
+ public __scaleResize(_scaleX: number, _scaleY: number): void { }
486
+
487
+
488
+ public resizeWidth(_width: number): void { }
489
+
490
+ public resizeHeight(_height: number): void { }
322
491
 
323
- // LeafHit rewrite
492
+
493
+ // @leafer-ui/hit LeafHit rewrite
324
494
 
325
495
  public __hitWorld(_point: IRadiusPointData): boolean { return true }
326
496
 
327
497
  public __hit(_local: IRadiusPointData): boolean { return true }
328
498
 
499
+ public __hitFill(_inner: IRadiusPointData): boolean { return true }
500
+
501
+ public __hitStroke(_inner: IRadiusPointData, _strokeWidth: number): boolean { return true }
502
+
503
+ public __hitPixel(_inner: IRadiusPointData): boolean { return true }
504
+
329
505
  public __drawHitPath(_canvas: ILeaferCanvas): void { }
330
506
 
331
507
  public __updateHitCanvas(): void { }
@@ -341,7 +517,10 @@ export class Leaf implements ILeaf {
341
517
 
342
518
  public __draw(_canvas: ILeaferCanvas, _options: IRenderOptions): void { }
343
519
 
344
- public __renderShape(_canvas: ILeaferCanvas, _options: IRenderOptions): void { }
520
+
521
+ public __clip(_canvas: ILeaferCanvas, _options: IRenderOptions): void { }
522
+
523
+ public __renderShape(_canvas: ILeaferCanvas, _options: IRenderOptions, _ignoreFill?: boolean, _ignoreStroke?: boolean): void { }
345
524
 
346
525
 
347
526
  public __updateWorldOpacity(): void { }
@@ -372,6 +551,10 @@ export class Leaf implements ILeaf {
372
551
  if (this.parent) this.parent.remove(this, destroy)
373
552
  }
374
553
 
554
+ public dropTo(parent: ILeaf, index?: number, resize?: boolean): void {
555
+ drop(this, parent, index, resize)
556
+ }
557
+
375
558
  // ---
376
559
 
377
560
 
@@ -379,7 +562,7 @@ export class Leaf implements ILeaf {
379
562
 
380
563
  public on(_type: string | string[], _listener: IEventListener, _options?: IEventListenerOptions | boolean): void { }
381
564
 
382
- public off(_type: string | string[], _listener: IEventListener, _options?: IEventListenerOptions | boolean): void { }
565
+ public off(_type?: string | string[], _listener?: IEventListener, _options?: IEventListenerOptions | boolean): void { }
383
566
 
384
567
  public on_(_type: string | string[], _listener: IEventListener, _bind?: IObject, _options?: IEventListenerOptions | boolean): IEventListenerId { return undefined }
385
568
 
@@ -395,11 +578,22 @@ export class Leaf implements ILeaf {
395
578
 
396
579
  // ---
397
580
 
581
+ static changeAttr(attrName: string, defaultValue: IValue, fn?: IAttrDecorator): void {
582
+ fn ? this.addAttr(attrName, defaultValue, fn) : defineDataProcessor(this.prototype, attrName, defaultValue)
583
+ }
584
+
585
+ static addAttr(attrName: string, defaultValue: IValue, fn?: IAttrDecorator): void {
586
+ if (!fn) fn = boundsType
587
+ fn(defaultValue)(this.prototype, attrName)
588
+ }
589
+
398
590
 
399
591
  public destroy(): void {
400
592
  if (!this.destroyed) {
401
- if (this.parent) this.remove()
593
+ const { parent } = this
594
+ if (parent) this.remove()
402
595
  if (this.children) (this as unknown as IBranch).removeAll(true)
596
+ if (this.hasEvent(ChildEvent.DESTROY)) this.emitEvent(new ChildEvent(ChildEvent.DESTROY, this, parent))
403
597
 
404
598
  this.__.destroy()
405
599
  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, IJSONOptions, IFindMethod, ILeaferCanvas, IRenderOptions, ILocationType, IBoundsType, ILayoutBoundsData, IPointData, IAlign, 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,103 @@ 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 __inLazyBounds(): boolean;
45
+ get pathInputed(): boolean;
39
46
  __captureMap?: IEventListenerMap;
40
47
  __bubbleMap?: IEventListenerMap;
41
48
  __parentWait?: IFunction[];
42
49
  __leaferWait?: IFunction[];
43
50
  children?: ILeaf[];
51
+ noBounds?: boolean;
44
52
  destroyed: boolean;
45
53
  constructor(data?: ILeafInputData);
46
- waitParent(item: IFunction): void;
47
- waitLeafer(item: IFunction): void;
48
- nextRender(item: IFunction): void;
49
- __bindLeafer(leafer: ILeafer | null): void;
54
+ reset(data?: ILeafInputData): void;
55
+ resetCustom(): void;
56
+ waitParent(item: IFunction, bind?: IObject): void;
57
+ waitLeafer(item: IFunction, bind?: IObject): void;
58
+ nextRender(item: IFunction, bind?: IObject, off?: 'off'): void;
59
+ removeNextRender(item: IFunction): void;
60
+ __bindLeafer(leafer: ILeaferBase | null): void;
50
61
  set(_data: IObject): void;
51
- toJSON(): IObject;
52
- toString(): string;
53
- __setAttr(_attrName: string, _newValue: __Value): void;
54
- __getAttr(_attrName: string): __Value;
62
+ get(_name?: string): ILeafInputData | IValue;
63
+ setAttr(name: string, value: any): void;
64
+ getAttr(name: string): any;
65
+ getComputedAttr(name: string): any;
66
+ toJSON(options?: IJSONOptions): IObject;
67
+ toString(options?: IJSONOptions): string;
68
+ toSVG(): string;
69
+ __SVG(_data: IObject): void;
70
+ toHTML(): string;
71
+ __setAttr(_attrName: string, _newValue: IValue): boolean;
72
+ __getAttr(_attrName: string): IValue;
73
+ setProxyAttr(_attrName: string, _newValue: IValue): void;
74
+ getProxyAttr(_attrName: string): IValue;
75
+ find(_condition: number | string | IFindMethod, _options?: any): ILeaf[];
76
+ findTag(_tag: string | string[]): ILeaf[];
77
+ findOne(_condition: number | string | IFindMethod, _options?: any): ILeaf | undefined;
78
+ findId(_id: number | string): ILeaf | undefined;
79
+ focus(_value?: boolean): void;
80
+ updateLayout(): void;
55
81
  forceUpdate(attrName?: string): void;
82
+ forceRender(_bounds?: IBoundsData): void;
56
83
  __updateWorldMatrix(): void;
57
84
  __updateLocalMatrix(): void;
58
85
  __updateWorldBounds(): void;
86
+ __updateLocalBounds(): void;
59
87
  __updateLocalBoxBounds(): void;
60
88
  __updateLocalStrokeBounds(): void;
61
89
  __updateLocalRenderBounds(): void;
62
90
  __updateBoxBounds(): void;
91
+ __updateContentBounds(): void;
63
92
  __updateStrokeBounds(): void;
64
93
  __updateRenderBounds(): void;
94
+ __updateAutoLayout(): void;
95
+ __updateFlowLayout(): void;
65
96
  __updateNaturalSize(): void;
66
97
  __updateStrokeSpread(): number;
67
98
  __updateRenderSpread(): number;
68
99
  __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;
100
+ __updateEraser(value?: boolean): void;
101
+ __renderEraser(canvas: ILeaferCanvas, options: IRenderOptions): void;
102
+ __updateMask(value?: boolean): void;
103
+ __renderMask(_canvas: ILeaferCanvas, _options: IRenderOptions): void;
104
+ __getNowWorld(options: IRenderOptions): IMatrixWithBoundsScaleData;
105
+ getTransform(relative?: ILocationType | ILeaf): IMatrixData;
106
+ getBounds(type?: IBoundsType, relative?: ILocationType | ILeaf): IBoundsData;
107
+ getLayoutBounds(type?: IBoundsType, relative?: ILocationType | ILeaf, unscale?: boolean): ILayoutBoundsData;
108
+ getLayoutPoints(type?: IBoundsType, relative?: ILocationType | ILeaf): IPointData[];
109
+ getWorldBounds(inner: IBoundsData, relative?: ILeaf, change?: boolean): IBoundsData;
75
110
  worldToLocal(world: IPointData, to?: IPointData, distance?: boolean, relative?: ILeaf): void;
76
111
  localToWorld(local: IPointData, to?: IPointData, distance?: boolean, relative?: ILeaf): void;
77
112
  worldToInner(world: IPointData, to?: IPointData, distance?: boolean, relative?: ILeaf): void;
@@ -82,18 +117,35 @@ declare class Leaf implements ILeaf {
82
117
  getLocalPointByInner(inner: IPointData, _relative?: ILeaf, distance?: boolean, change?: boolean): IPointData;
83
118
  getWorldPoint(inner: IPointData, relative?: ILeaf, distance?: boolean, change?: boolean): IPointData;
84
119
  getWorldPointByLocal(local: IPointData, relative?: ILeaf, distance?: boolean, change?: boolean): IPointData;
85
- 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;
120
+ getPagePoint(world: IPointData, relative?: ILeaf, distance?: boolean, change?: boolean): IPointData;
121
+ getWorldPointByPage(page: IPointData, relative?: ILeaf, distance?: boolean, change?: boolean): IPointData;
122
+ setTransform(matrix: IMatrixData, resize?: boolean): void;
123
+ transform(matrix: IMatrixData, resize?: boolean): void;
124
+ move(x: number | IPointData, y?: number): void;
125
+ scaleOf(origin: IPointData | IAlign, scaleX: number, scaleY?: number, resize?: boolean): void;
126
+ rotateOf(origin: IPointData | IAlign, rotation: number): void;
127
+ skewOf(origin: IPointData | IAlign, skewX: number, skewY?: number, resize?: boolean): void;
128
+ transformWorld(worldTransform?: IMatrixData, resize?: boolean): void;
129
+ moveWorld(x: number | IPointData, y?: number): void;
130
+ scaleOfWorld(worldOrigin: IPointData, scaleX: number, scaleY?: number, resize?: boolean): void;
131
+ rotateOfWorld(worldOrigin: IPointData, rotation: number): void;
132
+ skewOfWorld(worldOrigin: IPointData, skewX: number, skewY?: number, resize?: boolean): void;
133
+ scaleResize(scaleX: number, scaleY?: number, _noResize?: boolean): void;
134
+ __scaleResize(_scaleX: number, _scaleY: number): void;
135
+ resizeWidth(_width: number): void;
136
+ resizeHeight(_height: number): void;
89
137
  __hitWorld(_point: IRadiusPointData): boolean;
90
138
  __hit(_local: IRadiusPointData): boolean;
139
+ __hitFill(_inner: IRadiusPointData): boolean;
140
+ __hitStroke(_inner: IRadiusPointData, _strokeWidth: number): boolean;
141
+ __hitPixel(_inner: IRadiusPointData): boolean;
91
142
  __drawHitPath(_canvas: ILeaferCanvas): void;
92
143
  __updateHitCanvas(): void;
93
144
  __render(_canvas: ILeaferCanvas, _options: IRenderOptions): void;
94
145
  __drawFast(_canvas: ILeaferCanvas, _options: IRenderOptions): void;
95
146
  __draw(_canvas: ILeaferCanvas, _options: IRenderOptions): void;
96
- __renderShape(_canvas: ILeaferCanvas, _options: IRenderOptions): void;
147
+ __clip(_canvas: ILeaferCanvas, _options: IRenderOptions): void;
148
+ __renderShape(_canvas: ILeaferCanvas, _options: IRenderOptions, _ignoreFill?: boolean, _ignoreStroke?: boolean): void;
97
149
  __updateWorldOpacity(): void;
98
150
  __updateChange(): void;
99
151
  __drawPath(_canvas: ILeaferCanvas): void;
@@ -103,19 +155,21 @@ declare class Leaf implements ILeaf {
103
155
  __updateSortChildren(): void;
104
156
  add(_child: ILeaf, _index?: number): void;
105
157
  remove(_child?: ILeaf, destroy?: boolean): void;
158
+ dropTo(parent: ILeaf, index?: number, resize?: boolean): void;
106
159
  on(_type: string | string[], _listener: IEventListener, _options?: IEventListenerOptions | boolean): void;
107
- off(_type: string | string[], _listener: IEventListener, _options?: IEventListenerOptions | boolean): void;
160
+ off(_type?: string | string[], _listener?: IEventListener, _options?: IEventListenerOptions | boolean): void;
108
161
  on_(_type: string | string[], _listener: IEventListener, _bind?: IObject, _options?: IEventListenerOptions | boolean): IEventListenerId;
109
162
  off_(_id: IEventListenerId | IEventListenerId[]): void;
110
163
  once(_type: string | string[], _listener: IEventListener, _capture?: boolean): void;
111
164
  emit(_type: string, _event?: IEvent | IObject, _capture?: boolean): void;
112
165
  emitEvent(_event?: IEvent, _capture?: boolean): void;
113
166
  hasEvent(_type: string, _capture?: boolean): boolean;
167
+ static changeAttr(attrName: string, defaultValue: IValue, fn?: IAttrDecorator): void;
168
+ static addAttr(attrName: string, defaultValue: IValue, fn?: IAttrDecorator): void;
114
169
  destroy(): void;
115
170
  }
116
171
 
117
172
  declare class Branch extends Leaf {
118
- constructor();
119
173
  __updateStrokeSpread(): number;
120
174
  __updateRenderSpread(): number;
121
175
  __updateBoxBounds(): void;
@@ -124,8 +178,9 @@ declare class Branch extends Leaf {
124
178
  __updateSortChildren(): void;
125
179
  add(child: ILeaf, index?: number): void;
126
180
  addMany(...children: ILeaf[]): void;
127
- remove(child?: Leaf, destroy?: boolean): void;
181
+ remove(child?: ILeaf, destroy?: boolean): void;
128
182
  removeAll(destroy?: boolean): void;
183
+ clear(): void;
129
184
  protected __preRemove(): void;
130
185
  protected __realRemoveChild(child: ILeaf): void;
131
186
  protected __emitChildEvent(type: string, child: ILeaf): void;