@leafer/display 1.0.0-alpha.23 → 1.0.0-alpha.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 +9 -9
- package/src/Branch.ts +48 -35
- package/src/Leaf.ts +36 -20
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@leafer/display",
|
|
3
|
-
"version": "1.0.0-alpha.
|
|
3
|
+
"version": "1.0.0-alpha.30",
|
|
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-alpha.
|
|
23
|
-
"@leafer/data": "1.0.0-alpha.
|
|
24
|
-
"@leafer/layout": "1.0.0-alpha.
|
|
25
|
-
"@leafer/display-module": "1.0.0-alpha.
|
|
26
|
-
"@leafer/event": "1.0.0-alpha.
|
|
27
|
-
"@leafer/decorator": "1.0.0-alpha.
|
|
28
|
-
"@leafer/helper": "1.0.0-alpha.
|
|
22
|
+
"@leafer/math": "1.0.0-alpha.30",
|
|
23
|
+
"@leafer/data": "1.0.0-alpha.30",
|
|
24
|
+
"@leafer/layout": "1.0.0-alpha.30",
|
|
25
|
+
"@leafer/display-module": "1.0.0-alpha.30",
|
|
26
|
+
"@leafer/event": "1.0.0-alpha.30",
|
|
27
|
+
"@leafer/decorator": "1.0.0-alpha.30",
|
|
28
|
+
"@leafer/helper": "1.0.0-alpha.30"
|
|
29
29
|
},
|
|
30
30
|
"devDependencies": {
|
|
31
|
-
"@leafer/interface": "1.0.0-alpha.
|
|
31
|
+
"@leafer/interface": "1.0.0-alpha.30"
|
|
32
32
|
}
|
|
33
33
|
}
|
package/src/Branch.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { ILeaf, ILeaferCanvas, IRenderOptions } from '@leafer/interface'
|
|
2
2
|
import { ChildEvent } from '@leafer/event'
|
|
3
3
|
import { BoundsHelper } from '@leafer/math'
|
|
4
|
-
import { BranchHelper, LeafBoundsHelper } from '@leafer/helper'
|
|
4
|
+
import { BranchHelper, LeafBoundsHelper, WaitHelper } from '@leafer/helper'
|
|
5
|
+
import { useModule } from '@leafer/decorator'
|
|
6
|
+
import { LeafMask } from '@leafer/display-module'
|
|
5
7
|
|
|
6
8
|
import { Leaf } from './Leaf'
|
|
7
9
|
|
|
@@ -10,11 +12,12 @@ const { setByListWithHandle } = BoundsHelper
|
|
|
10
12
|
const { sort } = BranchHelper
|
|
11
13
|
const { localBoxBounds, localEventBounds, localRenderBounds, maskLocalBoxBounds, maskLocalEventBounds, maskLocalRenderBounds } = LeafBoundsHelper
|
|
12
14
|
|
|
15
|
+
@useModule(LeafMask)
|
|
13
16
|
export class Branch extends Leaf {
|
|
14
17
|
|
|
15
18
|
constructor() {
|
|
16
19
|
super()
|
|
17
|
-
this.
|
|
20
|
+
this.isBranch = true
|
|
18
21
|
this.children = []
|
|
19
22
|
}
|
|
20
23
|
|
|
@@ -36,7 +39,6 @@ export class Branch extends Leaf {
|
|
|
36
39
|
return 0
|
|
37
40
|
}
|
|
38
41
|
|
|
39
|
-
|
|
40
42
|
public __updateBoxBounds(): void {
|
|
41
43
|
setByListWithHandle(this.__layout.boxBounds, this.children, this.__hasMask ? maskLocalBoxBounds : localBoxBounds)
|
|
42
44
|
}
|
|
@@ -73,47 +75,52 @@ export class Branch extends Leaf {
|
|
|
73
75
|
public __render(canvas: ILeaferCanvas, options: IRenderOptions): void {
|
|
74
76
|
|
|
75
77
|
if (this.__worldOpacity) {
|
|
78
|
+
|
|
76
79
|
let child: ILeaf
|
|
77
80
|
const { children } = this
|
|
78
|
-
if (this.__hasMask) {
|
|
79
81
|
|
|
80
|
-
|
|
82
|
+
if (this.__hasMask && children.length > 1) {
|
|
83
|
+
|
|
84
|
+
let mask: boolean
|
|
85
|
+
let maskCanvas = canvas.getSameCanvas()
|
|
86
|
+
let contentCanvas = canvas.getSameCanvas()
|
|
81
87
|
|
|
82
88
|
for (let i = 0, len = children.length; i < len; i++) {
|
|
83
89
|
child = children[i]
|
|
84
90
|
|
|
85
91
|
if (child.isMask) {
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
92
|
+
if (mask) {
|
|
93
|
+
this.__renderMask(canvas, contentCanvas, maskCanvas)
|
|
94
|
+
maskCanvas.clear()
|
|
95
|
+
contentCanvas.clear()
|
|
96
|
+
} else {
|
|
97
|
+
mask = true
|
|
98
|
+
}
|
|
99
|
+
|
|
89
100
|
child.__render(maskCanvas, options)
|
|
90
|
-
//mask = child
|
|
91
101
|
continue
|
|
92
102
|
}
|
|
93
103
|
|
|
94
|
-
child.__render(
|
|
104
|
+
child.__render(contentCanvas, options)
|
|
95
105
|
}
|
|
96
106
|
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
maskCanvas.copyWorld(canvas, this.__world, null, 'source-in')
|
|
101
|
-
|
|
102
|
-
oldCanvas.resetTransform()
|
|
103
|
-
oldCanvas.copyWorld(maskCanvas, this.__world)
|
|
104
|
-
|
|
105
|
-
canvas.recycle()
|
|
106
|
-
maskCanvas.recycle()
|
|
107
|
-
}
|
|
107
|
+
this.__renderMask(canvas, contentCanvas, maskCanvas)
|
|
108
|
+
maskCanvas.recycle()
|
|
109
|
+
contentCanvas.recycle()
|
|
108
110
|
|
|
109
111
|
} else {
|
|
112
|
+
|
|
110
113
|
const { bounds, hideBounds } = options
|
|
114
|
+
|
|
111
115
|
for (let i = 0, len = children.length; i < len; i++) {
|
|
112
116
|
child = children[i]
|
|
117
|
+
|
|
113
118
|
if (bounds && !bounds.hit(child.__world, options.matrix)) continue
|
|
114
|
-
if (hideBounds && hideBounds.includes(child.__world)) continue
|
|
119
|
+
if (hideBounds && hideBounds.includes(child.__world, options.matrix)) continue
|
|
120
|
+
|
|
115
121
|
child.__render(canvas, options)
|
|
116
122
|
}
|
|
123
|
+
|
|
117
124
|
}
|
|
118
125
|
}
|
|
119
126
|
|
|
@@ -122,23 +129,26 @@ export class Branch extends Leaf {
|
|
|
122
129
|
public add(child: ILeaf, index?: number): void {
|
|
123
130
|
|
|
124
131
|
if (child.parent) child.parent.remove(child)
|
|
125
|
-
|
|
126
132
|
child.parent = this
|
|
127
133
|
|
|
128
134
|
index === undefined ? this.children.push(child) : this.children.splice(index, 0, child)
|
|
129
|
-
if (child.
|
|
135
|
+
if (child.isBranch) this.__.__childBranchNumber = (this.__.__childBranchNumber || 0) + 1
|
|
136
|
+
child.__layout.boundsChanged || child.__layout.positionChange() // layouted(removed), need update
|
|
137
|
+
|
|
138
|
+
if (child.__parentWait) WaitHelper.run(child.__parentWait)
|
|
130
139
|
|
|
131
140
|
if (this.leafer) {
|
|
132
141
|
child.__bindLeafer(this.leafer)
|
|
133
142
|
|
|
134
143
|
if (this.leafer.ready) {
|
|
135
|
-
const
|
|
136
|
-
|
|
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)
|
|
137
148
|
this.leafer.emitEvent(event)
|
|
138
149
|
}
|
|
139
150
|
}
|
|
140
151
|
|
|
141
|
-
if (child.__parentWait) child.__runParentWait()
|
|
142
152
|
}
|
|
143
153
|
|
|
144
154
|
public remove(child?: Leaf): void {
|
|
@@ -147,24 +157,27 @@ export class Branch extends Leaf {
|
|
|
147
157
|
const index = this.children.indexOf(child)
|
|
148
158
|
if (index > -1) {
|
|
149
159
|
this.children.splice(index, 1)
|
|
160
|
+
if (this.__hasMask) this.__updateMask()
|
|
161
|
+
this.__layout.boxBoundsChange()
|
|
150
162
|
|
|
151
|
-
if (child.
|
|
163
|
+
if (child.isBranch) this.__.__childBranchNumber = (this.__.__childBranchNumber || 1) - 1
|
|
164
|
+
child.parent = null
|
|
152
165
|
|
|
153
166
|
if (this.leafer) {
|
|
167
|
+
child.__bindLeafer(null)
|
|
168
|
+
|
|
154
169
|
if (this.leafer.ready) {
|
|
155
|
-
const
|
|
156
|
-
|
|
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)
|
|
157
174
|
this.leafer.emitEvent(event)
|
|
158
175
|
}
|
|
159
|
-
|
|
160
|
-
child.__bindLeafer(null)
|
|
161
176
|
}
|
|
162
177
|
|
|
163
|
-
child.parent = null
|
|
164
|
-
this.__layout.boxBoundsChange()
|
|
165
178
|
}
|
|
166
179
|
} else {
|
|
167
|
-
|
|
180
|
+
super.remove()
|
|
168
181
|
}
|
|
169
182
|
|
|
170
183
|
}
|
package/src/Leaf.ts
CHANGED
|
@@ -4,6 +4,7 @@ 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
8
|
|
|
8
9
|
|
|
9
10
|
const { LEAF, create } = IncrementId
|
|
@@ -20,6 +21,7 @@ export class Leaf implements ILeaf {
|
|
|
20
21
|
public get __tag(): string { return 'Leaf' }
|
|
21
22
|
|
|
22
23
|
public readonly innerId: InnerId // 内部唯一标识
|
|
24
|
+
public get innerName(): string { return this.__.name || this.tag + this.innerId }
|
|
23
25
|
|
|
24
26
|
public get __DataProcessor() { return LeafData }
|
|
25
27
|
public get __LayoutProcessor() { return LeafLayout }
|
|
@@ -28,8 +30,8 @@ export class Leaf implements ILeaf {
|
|
|
28
30
|
public parent?: ILeaf
|
|
29
31
|
|
|
30
32
|
public isLeafer: boolean
|
|
31
|
-
public
|
|
32
|
-
public
|
|
33
|
+
public isBranch: boolean
|
|
34
|
+
public isBranchLeaf: boolean
|
|
33
35
|
|
|
34
36
|
public __: ILeafData
|
|
35
37
|
public __layout: ILeafLayout
|
|
@@ -48,19 +50,23 @@ export class Leaf implements ILeaf {
|
|
|
48
50
|
public get worldRenderBounds(): IBoundsData { return this.getBounds('render') }
|
|
49
51
|
|
|
50
52
|
// now opacity
|
|
51
|
-
public get worldOpacity(): number { this.__layout.
|
|
53
|
+
public get worldOpacity(): number { this.__layout.checkUpdate(); return this.__worldOpacity }
|
|
52
54
|
|
|
53
|
-
public __level: number //
|
|
54
|
-
public __tempNumber: number //
|
|
55
|
+
public __level: number // layer level 0 -> branch -> branch -> deep
|
|
56
|
+
public __tempNumber: number // temp sort
|
|
55
57
|
|
|
56
58
|
public __hasMask?: boolean
|
|
57
59
|
public __hitCanvas?: IHitCanvas
|
|
58
60
|
|
|
61
|
+
public get __onlyHitMask(): boolean { return this.__hasMask && !this.__.hitChildren }
|
|
62
|
+
public get __ignoreHitWorld(): boolean { return this.__hasMask && this.__.hitChildren }
|
|
63
|
+
|
|
59
64
|
// event
|
|
60
65
|
public __captureMap?: IEventListenerMap
|
|
61
66
|
public __bubbleMap?: IEventListenerMap
|
|
62
67
|
|
|
63
68
|
public __parentWait?: IFunction[]
|
|
69
|
+
public __leaferWait?: IFunction[]
|
|
64
70
|
|
|
65
71
|
// branch
|
|
66
72
|
public children?: ILeaf[]
|
|
@@ -81,25 +87,24 @@ export class Leaf implements ILeaf {
|
|
|
81
87
|
}
|
|
82
88
|
|
|
83
89
|
|
|
84
|
-
public
|
|
90
|
+
public waitParent(item: IFunction): void {
|
|
85
91
|
this.__parentWait ? this.__parentWait.push(item) : this.__parentWait = [item]
|
|
86
92
|
}
|
|
87
93
|
|
|
88
|
-
public
|
|
89
|
-
|
|
90
|
-
for (let i = 0; i < len; i++) {
|
|
91
|
-
this.__parentWait[i]()
|
|
92
|
-
}
|
|
93
|
-
this.__parentWait = null
|
|
94
|
+
public waitLeafer(item: IFunction): void {
|
|
95
|
+
this.__leaferWait ? this.__leaferWait.push(item) : this.__leaferWait = [item]
|
|
94
96
|
}
|
|
95
97
|
|
|
96
|
-
|
|
98
|
+
|
|
99
|
+
public __bindLeafer(leafer: ILeafer | null): void {
|
|
97
100
|
if (this.isLeafer) leafer = this as unknown as ILeafer
|
|
98
101
|
|
|
99
102
|
this.leafer = leafer
|
|
100
103
|
this.__level = this.parent ? this.parent.__level + 1 : 1
|
|
101
104
|
|
|
102
|
-
if (this.
|
|
105
|
+
if (this.__leaferWait && leafer) WaitHelper.run(this.__leaferWait)
|
|
106
|
+
|
|
107
|
+
if (this.isBranch) {
|
|
103
108
|
const { children } = this
|
|
104
109
|
for (let i = 0, len = children.length; i < len; i++) {
|
|
105
110
|
children[i].__bindLeafer(leafer)
|
|
@@ -118,12 +123,13 @@ export class Leaf implements ILeaf {
|
|
|
118
123
|
|
|
119
124
|
public __getAttr(_attrName: string): __Value { return undefined }
|
|
120
125
|
|
|
121
|
-
public __updateAttr(_attrName?: string, _value?: __Value): void { }
|
|
122
|
-
|
|
123
126
|
// ---
|
|
124
127
|
|
|
125
|
-
public forceUpdate(): void {
|
|
126
|
-
|
|
128
|
+
public forceUpdate(attrName?: string): void {
|
|
129
|
+
if (!attrName) attrName = 'x'
|
|
130
|
+
const value = this.__.__get(attrName)
|
|
131
|
+
this.__[attrName] = (value === null) ? 0 : null;
|
|
132
|
+
(this as any)[attrName] = value
|
|
127
133
|
}
|
|
128
134
|
|
|
129
135
|
|
|
@@ -159,12 +165,22 @@ export class Leaf implements ILeaf {
|
|
|
159
165
|
|
|
160
166
|
public __updateRenderBoundsSpreadWidth(): number { return 0 }
|
|
161
167
|
|
|
162
|
-
|
|
163
168
|
public __onUpdateSize(): void { }
|
|
164
169
|
|
|
165
170
|
// ---
|
|
166
171
|
|
|
167
172
|
|
|
173
|
+
// LeafMask rewrite
|
|
174
|
+
|
|
175
|
+
public __updateMask(): void { }
|
|
176
|
+
|
|
177
|
+
public __renderMask(_canvas: ILeaferCanvas, _content: ILeaferCanvas, _mask: ILeaferCanvas): void { }
|
|
178
|
+
|
|
179
|
+
public __removeMask(_child?: ILeaf): void { }
|
|
180
|
+
|
|
181
|
+
// ---
|
|
182
|
+
|
|
183
|
+
|
|
168
184
|
// convert
|
|
169
185
|
|
|
170
186
|
public getWorld(attrName: IMatrixDecompositionAttr): number {
|
|
@@ -296,7 +312,7 @@ export class Leaf implements ILeaf {
|
|
|
296
312
|
this.__captureMap = null
|
|
297
313
|
this.__bubbleMap = null
|
|
298
314
|
|
|
299
|
-
if (this.
|
|
315
|
+
if (this.children) {
|
|
300
316
|
this.children.forEach(child => { child.destroy() })
|
|
301
317
|
this.children.length = 0
|
|
302
318
|
}
|