@leafer/display 1.0.0-beta → 1.0.0-beta.11
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 +9 -9
- package/src/Branch.ts +46 -95
- package/src/Leaf.ts +48 -32
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@leafer/display",
|
|
3
|
-
"version": "1.0.0-beta",
|
|
3
|
+
"version": "1.0.0-beta.11",
|
|
4
4
|
"description": "@leafer/display",
|
|
5
5
|
"author": "Chao (Leafer) Wan",
|
|
6
6
|
"license": "MIT",
|
|
@@ -19,15 +19,15 @@
|
|
|
19
19
|
"leaferjs"
|
|
20
20
|
],
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"@leafer/math": "1.0.0-beta",
|
|
23
|
-
"@leafer/data": "1.0.0-beta",
|
|
24
|
-
"@leafer/layout": "1.0.0-beta",
|
|
25
|
-
"@leafer/display-module": "1.0.0-beta",
|
|
26
|
-
"@leafer/event": "1.0.0-beta",
|
|
27
|
-
"@leafer/decorator": "1.0.0-beta",
|
|
28
|
-
"@leafer/helper": "1.0.0-beta"
|
|
22
|
+
"@leafer/math": "1.0.0-beta.11",
|
|
23
|
+
"@leafer/data": "1.0.0-beta.11",
|
|
24
|
+
"@leafer/layout": "1.0.0-beta.11",
|
|
25
|
+
"@leafer/display-module": "1.0.0-beta.11",
|
|
26
|
+
"@leafer/event": "1.0.0-beta.11",
|
|
27
|
+
"@leafer/decorator": "1.0.0-beta.11",
|
|
28
|
+
"@leafer/helper": "1.0.0-beta.11"
|
|
29
29
|
},
|
|
30
30
|
"devDependencies": {
|
|
31
|
-
"@leafer/interface": "1.0.0-beta"
|
|
31
|
+
"@leafer/interface": "1.0.0-beta.11"
|
|
32
32
|
}
|
|
33
33
|
}
|
package/src/Branch.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { ILeaf
|
|
1
|
+
import { ILeaf } from '@leafer/interface'
|
|
2
2
|
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 { LeafMask } from '@leafer/display-module'
|
|
6
|
+
import { BranchRender, LeafMask } from '@leafer/display-module'
|
|
7
7
|
|
|
8
8
|
import { Leaf } from './Leaf'
|
|
9
9
|
|
|
@@ -12,6 +12,8 @@ const { setByListWithHandle } = BoundsHelper
|
|
|
12
12
|
const { sort } = BranchHelper
|
|
13
13
|
const { localBoxBounds, localEventBounds, localRenderBounds, maskLocalBoxBounds, maskLocalEventBounds, maskLocalRenderBounds } = LeafBoundsHelper
|
|
14
14
|
|
|
15
|
+
|
|
16
|
+
@useModule(BranchRender)
|
|
15
17
|
@useModule(LeafMask)
|
|
16
18
|
export class Branch extends Leaf {
|
|
17
19
|
|
|
@@ -51,83 +53,23 @@ export class Branch extends Leaf {
|
|
|
51
53
|
setByListWithHandle(this.__layout.renderBounds, this.children, this.__hasMask ? maskLocalRenderBounds : localRenderBounds)
|
|
52
54
|
}
|
|
53
55
|
|
|
54
|
-
public __updateChange(): void {
|
|
55
|
-
const { __layout: layout } = this
|
|
56
|
-
if (layout.childrenSortChanged) {
|
|
57
|
-
this.__updateSortChildren()
|
|
58
|
-
layout.childrenSortChanged = false
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
|
|
62
56
|
|
|
63
57
|
// own
|
|
64
58
|
|
|
65
59
|
public __updateSortChildren(): void {
|
|
60
|
+
let affectSort: boolean
|
|
66
61
|
const { children } = this
|
|
67
62
|
if (children.length > 1) {
|
|
68
63
|
for (let i = 0, len = children.length; i < len; i++) {
|
|
69
64
|
children[i].__tempNumber = i
|
|
65
|
+
if (children[i].__.zIndex) affectSort = true
|
|
70
66
|
}
|
|
71
67
|
children.sort(sort)
|
|
68
|
+
this.__layout.affectChildrenSort = affectSort
|
|
72
69
|
}
|
|
73
70
|
}
|
|
74
71
|
|
|
75
|
-
public __render(canvas: ILeaferCanvas, options: IRenderOptions): void {
|
|
76
|
-
|
|
77
|
-
if (this.__worldOpacity) {
|
|
78
|
-
|
|
79
|
-
let child: ILeaf
|
|
80
|
-
const { children } = this
|
|
81
|
-
|
|
82
|
-
if (this.__hasMask && children.length > 1) {
|
|
83
|
-
|
|
84
|
-
let mask: boolean
|
|
85
|
-
let maskCanvas = canvas.getSameCanvas()
|
|
86
|
-
let contentCanvas = canvas.getSameCanvas()
|
|
87
|
-
|
|
88
|
-
for (let i = 0, len = children.length; i < len; i++) {
|
|
89
|
-
child = children[i]
|
|
90
|
-
|
|
91
|
-
if (child.isMask) {
|
|
92
|
-
if (mask) {
|
|
93
|
-
this.__renderMask(canvas, contentCanvas, maskCanvas)
|
|
94
|
-
maskCanvas.clear()
|
|
95
|
-
contentCanvas.clear()
|
|
96
|
-
} else {
|
|
97
|
-
mask = true
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
child.__render(maskCanvas, options)
|
|
101
|
-
continue
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
child.__render(contentCanvas, options)
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
this.__renderMask(canvas, contentCanvas, maskCanvas)
|
|
108
|
-
maskCanvas.recycle()
|
|
109
|
-
contentCanvas.recycle()
|
|
110
|
-
|
|
111
|
-
} else {
|
|
112
|
-
|
|
113
|
-
const { bounds, hideBounds } = options
|
|
114
|
-
|
|
115
|
-
for (let i = 0, len = children.length; i < len; i++) {
|
|
116
|
-
child = children[i]
|
|
117
|
-
|
|
118
|
-
if (bounds && !bounds.hit(child.__world, options.matrix)) continue
|
|
119
|
-
if (hideBounds && hideBounds.includes(child.__world, options.matrix)) continue
|
|
120
|
-
|
|
121
|
-
child.__render(canvas, options)
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
}
|
|
128
|
-
|
|
129
72
|
public add(child: ILeaf, index?: number): void {
|
|
130
|
-
|
|
131
73
|
if (child.parent) child.parent.remove(child)
|
|
132
74
|
child.parent = this
|
|
133
75
|
|
|
@@ -139,48 +81,57 @@ export class Branch extends Leaf {
|
|
|
139
81
|
|
|
140
82
|
if (this.leafer) {
|
|
141
83
|
child.__bindLeafer(this.leafer)
|
|
142
|
-
|
|
143
|
-
if (this.leafer.ready) {
|
|
144
|
-
const { ADD } = ChildEvent
|
|
145
|
-
const event = new ChildEvent(ADD, child, this)
|
|
146
|
-
if (child.hasEvent(ADD)) child.emitEvent(event)
|
|
147
|
-
if (this.hasEvent(ADD) && !this.isLeafer) this.emitEvent(event)
|
|
148
|
-
this.leafer.emitEvent(event)
|
|
149
|
-
}
|
|
84
|
+
if (this.leafer.ready) this.__emitChildEvent(ChildEvent.ADD, child)
|
|
150
85
|
}
|
|
151
86
|
|
|
87
|
+
this.__layout.affectChildrenSort && this.__layout.childrenSortChange()
|
|
152
88
|
}
|
|
153
89
|
|
|
154
|
-
public remove(child?: Leaf): void {
|
|
155
|
-
|
|
90
|
+
public remove(child?: Leaf, destroy?: boolean): void {
|
|
156
91
|
if (child) {
|
|
157
92
|
const index = this.children.indexOf(child)
|
|
158
93
|
if (index > -1) {
|
|
159
94
|
this.children.splice(index, 1)
|
|
160
|
-
if (this.__hasMask) this.__updateMask()
|
|
161
|
-
this.__layout.boxChange()
|
|
162
|
-
|
|
163
95
|
if (child.isBranch) this.__.__childBranchNumber = (this.__.__childBranchNumber || 1) - 1
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
if (
|
|
167
|
-
child.__bindLeafer(null)
|
|
168
|
-
|
|
169
|
-
if (this.leafer.ready) {
|
|
170
|
-
const { REMOVE } = ChildEvent
|
|
171
|
-
const event = new ChildEvent(REMOVE, child, this)
|
|
172
|
-
if (child.hasEvent(REMOVE)) child.emitEvent(event)
|
|
173
|
-
if (this.hasEvent(REMOVE) && !this.isLeafer) this.emitEvent(event)
|
|
174
|
-
this.leafer.emitEvent(event)
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
|
|
96
|
+
this.__preRemove()
|
|
97
|
+
this.__realRemoveChild(child)
|
|
98
|
+
if (destroy) child.destroy()
|
|
178
99
|
}
|
|
179
|
-
} else {
|
|
180
|
-
super.remove()
|
|
100
|
+
} else if (child === undefined) {
|
|
101
|
+
super.remove(null, destroy)
|
|
181
102
|
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
public removeAll(destroy?: boolean): void {
|
|
106
|
+
const { children } = this
|
|
107
|
+
this.children = []
|
|
108
|
+
this.__preRemove()
|
|
109
|
+
this.__.__childBranchNumber = 0
|
|
110
|
+
children.forEach(child => {
|
|
111
|
+
this.__realRemoveChild(child)
|
|
112
|
+
if (destroy) child.destroy()
|
|
113
|
+
})
|
|
114
|
+
}
|
|
182
115
|
|
|
116
|
+
protected __preRemove(): void {
|
|
117
|
+
if (this.__hasMask) this.__updateMask()
|
|
118
|
+
if (this.__hasEraser) this.__updateEraser()
|
|
119
|
+
this.__layout.boxChange()
|
|
120
|
+
this.__layout.affectChildrenSort && this.__layout.childrenSortChange()
|
|
183
121
|
}
|
|
184
|
-
}
|
|
185
122
|
|
|
123
|
+
protected __realRemoveChild(child: ILeaf): void {
|
|
124
|
+
child.parent = null
|
|
125
|
+
if (this.leafer) {
|
|
126
|
+
child.__bindLeafer(null)
|
|
127
|
+
if (this.leafer.ready) this.__emitChildEvent(ChildEvent.REMOVE, child)
|
|
128
|
+
}
|
|
129
|
+
}
|
|
186
130
|
|
|
131
|
+
protected __emitChildEvent(type: string, child: ILeaf): void {
|
|
132
|
+
const event = new ChildEvent(type, child, this)
|
|
133
|
+
if (child.hasEvent(type)) child.emitEvent(event)
|
|
134
|
+
if (this.hasEvent(type) && !this.isLeafer) this.emitEvent(event)
|
|
135
|
+
this.leafer.emitEvent(event)
|
|
136
|
+
}
|
|
137
|
+
}
|
package/src/Leaf.ts
CHANGED
|
@@ -1,13 +1,16 @@
|
|
|
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'
|
|
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, IBranch } from '@leafer/interface'
|
|
2
2
|
import { IncrementId, MatrixHelper, PointHelper } from '@leafer/math'
|
|
3
3
|
import { LeafData } from '@leafer/data'
|
|
4
4
|
import { LeafLayout } from '@leafer/layout'
|
|
5
5
|
import { LeafDataProxy, LeafMatrix, LeafBounds, LeafHit, LeafEventer, LeafRender } from '@leafer/display-module'
|
|
6
6
|
import { useModule } from '@leafer/decorator'
|
|
7
|
-
import { WaitHelper } from '@leafer/helper'
|
|
7
|
+
import { LeafHelper, WaitHelper } from '@leafer/helper'
|
|
8
8
|
|
|
9
9
|
|
|
10
10
|
const { LEAF, create } = IncrementId
|
|
11
|
+
const { toInnerPoint, toOuterPoint } = MatrixHelper
|
|
12
|
+
const { tempToOuterOf, copy } = PointHelper
|
|
13
|
+
const { moveLocal, zoomOfLocal, rotateOfLocal } = LeafHelper
|
|
11
14
|
|
|
12
15
|
@useModule(LeafDataProxy)
|
|
13
16
|
@useModule(LeafMatrix)
|
|
@@ -18,6 +21,8 @@ const { LEAF, create } = IncrementId
|
|
|
18
21
|
export class Leaf implements ILeaf {
|
|
19
22
|
|
|
20
23
|
public get tag(): string { return this.__tag }
|
|
24
|
+
public set tag(_value: string) { }
|
|
25
|
+
|
|
21
26
|
public get __tag(): string { return 'Leaf' }
|
|
22
27
|
|
|
23
28
|
public readonly innerId: InnerId // 内部唯一标识
|
|
@@ -56,10 +61,11 @@ export class Leaf implements ILeaf {
|
|
|
56
61
|
public __tempNumber: number // temp sort
|
|
57
62
|
|
|
58
63
|
public __hasMask?: boolean
|
|
64
|
+
public __hasEraser?: boolean
|
|
59
65
|
public __hitCanvas?: IHitCanvas
|
|
60
66
|
|
|
61
67
|
public get __onlyHitMask(): boolean { return this.__hasMask && !this.__.hitChildren }
|
|
62
|
-
public get __ignoreHitWorld(): boolean { return this.__hasMask && this.__.hitChildren }
|
|
68
|
+
public get __ignoreHitWorld(): boolean { return (this.__hasMask || this.__hasEraser) && this.__.hitChildren }
|
|
63
69
|
|
|
64
70
|
// event
|
|
65
71
|
public __captureMap?: IEventListenerMap
|
|
@@ -76,7 +82,7 @@ export class Leaf implements ILeaf {
|
|
|
76
82
|
this.innerId = create(LEAF)
|
|
77
83
|
|
|
78
84
|
this.__local = { a: 1, b: 0, c: 0, d: 1, e: 0, f: 0, x: 0, y: 0, width: 0, height: 0 }
|
|
79
|
-
this.__world = { a: 1, b: 0, c: 0, d: 1, e: 0, f: 0, x: 0, y: 0, width: 0, height: 0 }
|
|
85
|
+
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 }
|
|
80
86
|
|
|
81
87
|
this.__worldOpacity = 1
|
|
82
88
|
|
|
@@ -88,11 +94,11 @@ export class Leaf implements ILeaf {
|
|
|
88
94
|
|
|
89
95
|
|
|
90
96
|
public waitParent(item: IFunction): void {
|
|
91
|
-
this.__parentWait ? this.__parentWait.push(item) : this.__parentWait = [item]
|
|
97
|
+
this.parent ? item() : (this.__parentWait ? this.__parentWait.push(item) : this.__parentWait = [item])
|
|
92
98
|
}
|
|
93
99
|
|
|
94
100
|
public waitLeafer(item: IFunction): void {
|
|
95
|
-
this.__leaferWait ? this.__leaferWait.push(item) : this.__leaferWait = [item]
|
|
101
|
+
this.leafer ? item() : (this.__leaferWait ? this.__leaferWait.push(item) : this.__leaferWait = [item])
|
|
96
102
|
}
|
|
97
103
|
|
|
98
104
|
|
|
@@ -126,9 +132,9 @@ export class Leaf implements ILeaf {
|
|
|
126
132
|
// ---
|
|
127
133
|
|
|
128
134
|
public forceUpdate(attrName?: string): void {
|
|
129
|
-
if (
|
|
130
|
-
|
|
131
|
-
this.__
|
|
135
|
+
if (attrName === undefined) attrName = 'x'
|
|
136
|
+
else if (attrName === 'surface') attrName = 'blendMode'
|
|
137
|
+
const value = this.__.__getInput(attrName);
|
|
132
138
|
(this as any)[attrName] = value
|
|
133
139
|
}
|
|
134
140
|
|
|
@@ -172,7 +178,9 @@ export class Leaf implements ILeaf {
|
|
|
172
178
|
|
|
173
179
|
// LeafMask rewrite
|
|
174
180
|
|
|
175
|
-
public
|
|
181
|
+
public __updateEraser(_value?: boolean): void { }
|
|
182
|
+
|
|
183
|
+
public __updateMask(_value?: boolean): void { }
|
|
176
184
|
|
|
177
185
|
public __renderMask(_canvas: ILeaferCanvas, _content: ILeaferCanvas, _mask: ILeaferCanvas): void { }
|
|
178
186
|
|
|
@@ -194,26 +202,43 @@ export class Leaf implements ILeaf {
|
|
|
194
202
|
|
|
195
203
|
public worldToLocal(world: IPointData, to?: IPointData, isMovePoint?: boolean): void {
|
|
196
204
|
if (this.parent) {
|
|
197
|
-
|
|
205
|
+
toInnerPoint(this.parent.worldTransform, world, to, isMovePoint)
|
|
198
206
|
} else {
|
|
199
|
-
if (to)
|
|
207
|
+
if (to) copy(to, world)
|
|
200
208
|
}
|
|
201
209
|
}
|
|
202
210
|
|
|
203
211
|
public localToWorld(local: IPointData, to?: IPointData, isMovePoint?: boolean): void {
|
|
204
212
|
if (this.parent) {
|
|
205
|
-
|
|
213
|
+
toOuterPoint(this.parent.worldTransform, local, to, isMovePoint)
|
|
206
214
|
} else {
|
|
207
|
-
if (to)
|
|
215
|
+
if (to) copy(to, local)
|
|
208
216
|
}
|
|
209
217
|
}
|
|
210
218
|
|
|
211
219
|
public worldToInner(world: IPointData, to?: IPointData, isMovePoint?: boolean): void {
|
|
212
|
-
|
|
220
|
+
toInnerPoint(this.worldTransform, world, to, isMovePoint)
|
|
213
221
|
}
|
|
214
222
|
|
|
215
223
|
public innerToWorld(inner: IPointData, to?: IPointData, isMovePoint?: boolean): void {
|
|
216
|
-
|
|
224
|
+
toOuterPoint(this.worldTransform, inner, to, isMovePoint)
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
|
|
228
|
+
// transform
|
|
229
|
+
|
|
230
|
+
public move(x: number, y?: number): void {
|
|
231
|
+
moveLocal(this, x, y)
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
public scaleOf(origin: IPointData, x: number, y?: number): void {
|
|
235
|
+
this.__layout.checkUpdate()
|
|
236
|
+
zoomOfLocal(this, tempToOuterOf(origin, this.__local), x, y)
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
public rotateOf(origin: IPointData, angle: number): void {
|
|
240
|
+
this.__layout.checkUpdate()
|
|
241
|
+
rotateOfLocal(this, tempToOuterOf(origin, this.__local), angle)
|
|
217
242
|
}
|
|
218
243
|
|
|
219
244
|
|
|
@@ -265,8 +290,8 @@ export class Leaf implements ILeaf {
|
|
|
265
290
|
|
|
266
291
|
public add(_child: ILeaf, _index?: number): void { }
|
|
267
292
|
|
|
268
|
-
public remove(_child?: ILeaf): void {
|
|
269
|
-
if (this.parent) this.parent.remove(this)
|
|
293
|
+
public remove(_child?: ILeaf, destroy?: boolean): void {
|
|
294
|
+
if (this.parent) this.parent.remove(this, destroy)
|
|
270
295
|
}
|
|
271
296
|
|
|
272
297
|
// ---
|
|
@@ -294,26 +319,17 @@ export class Leaf implements ILeaf {
|
|
|
294
319
|
|
|
295
320
|
public destroy(): void {
|
|
296
321
|
if (this.__) {
|
|
297
|
-
if (this.__hitCanvas) {
|
|
298
|
-
this.__hitCanvas.destroy()
|
|
299
|
-
this.__hitCanvas = null
|
|
300
|
-
}
|
|
301
322
|
|
|
302
|
-
this.
|
|
303
|
-
this.parent
|
|
323
|
+
if (this.children && this.children.length) (this as unknown as IBranch).removeAll(true)
|
|
324
|
+
if (this.parent) this.remove()
|
|
325
|
+
|
|
326
|
+
if (this.__hitCanvas) this.__hitCanvas.destroy()
|
|
304
327
|
|
|
305
328
|
this.__.destroy()
|
|
306
329
|
this.__layout.destroy()
|
|
307
|
-
this.__ = null
|
|
308
|
-
this.__layout = null
|
|
309
330
|
|
|
310
|
-
this.__captureMap = null
|
|
311
|
-
this.__bubbleMap = null
|
|
331
|
+
this.leafer = this.parent = this.__hitCanvas = this.__ = this.__layout = this.__captureMap = this.__bubbleMap = null
|
|
312
332
|
|
|
313
|
-
if (this.children) {
|
|
314
|
-
this.children.forEach(child => { child.destroy() })
|
|
315
|
-
this.children.length = 0
|
|
316
|
-
}
|
|
317
333
|
}
|
|
318
334
|
}
|
|
319
335
|
|