@leafer/display-module 1.0.0-beta.2 → 1.0.0-beta.5
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 +4 -4
- package/src/BranchRender.ts +87 -0
- package/src/LeafEventer.ts +6 -3
- package/src/LeafMask.ts +5 -0
- package/src/LeafRender.ts +11 -1
- package/src/index.ts +1 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@leafer/display-module",
|
|
3
|
-
"version": "1.0.0-beta.
|
|
3
|
+
"version": "1.0.0-beta.5",
|
|
4
4
|
"description": "@leafer/display-module",
|
|
5
5
|
"author": "Chao (Leafer) Wan",
|
|
6
6
|
"license": "MIT",
|
|
@@ -19,10 +19,10 @@
|
|
|
19
19
|
"leaferjs"
|
|
20
20
|
],
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"@leafer/event": "1.0.0-beta.
|
|
23
|
-
"@leafer/math": "1.0.0-beta.
|
|
22
|
+
"@leafer/event": "1.0.0-beta.5",
|
|
23
|
+
"@leafer/math": "1.0.0-beta.5"
|
|
24
24
|
},
|
|
25
25
|
"devDependencies": {
|
|
26
|
-
"@leafer/interface": "1.0.0-beta.
|
|
26
|
+
"@leafer/interface": "1.0.0-beta.5"
|
|
27
27
|
}
|
|
28
28
|
}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { ILeaf, ILeaferCanvas, IRenderOptions, IBranchRenderModule } from '@leafer/interface'
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
export const BranchRender: IBranchRenderModule = {
|
|
5
|
+
|
|
6
|
+
__updateChange(): void {
|
|
7
|
+
const { __layout: layout } = this
|
|
8
|
+
if (layout.childrenSortChanged) {
|
|
9
|
+
this.__updateSortChildren()
|
|
10
|
+
layout.childrenSortChanged = false
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
this.__.__checkSingle()
|
|
14
|
+
},
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
__render(canvas: ILeaferCanvas, options: IRenderOptions): void {
|
|
18
|
+
if (this.__worldOpacity) {
|
|
19
|
+
|
|
20
|
+
if (this.__.__single) {
|
|
21
|
+
canvas.resetTransform()
|
|
22
|
+
const tempCanvas = canvas.getSameCanvas()
|
|
23
|
+
|
|
24
|
+
this.__renderBranch(tempCanvas, options)
|
|
25
|
+
|
|
26
|
+
canvas.opacity = this.__worldOpacity
|
|
27
|
+
canvas.copyWorld(tempCanvas, this.__world, this.__world, this.__.isEraser ? 'destination-out' : this.__.blendMode)
|
|
28
|
+
tempCanvas.recycle()
|
|
29
|
+
} else {
|
|
30
|
+
this.__renderBranch(canvas, options)
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
}
|
|
34
|
+
},
|
|
35
|
+
|
|
36
|
+
__renderBranch(canvas: ILeaferCanvas, options: IRenderOptions): void {
|
|
37
|
+
|
|
38
|
+
let child: ILeaf
|
|
39
|
+
const { children } = this
|
|
40
|
+
|
|
41
|
+
if (this.__hasMask && children.length > 1) {
|
|
42
|
+
|
|
43
|
+
let mask: boolean
|
|
44
|
+
let maskCanvas = canvas.getSameCanvas()
|
|
45
|
+
let contentCanvas = canvas.getSameCanvas()
|
|
46
|
+
|
|
47
|
+
for (let i = 0, len = children.length; i < len; i++) {
|
|
48
|
+
child = children[i]
|
|
49
|
+
|
|
50
|
+
if (child.isMask) {
|
|
51
|
+
if (mask) {
|
|
52
|
+
this.__renderMask(canvas, contentCanvas, maskCanvas)
|
|
53
|
+
maskCanvas.clear()
|
|
54
|
+
contentCanvas.clear()
|
|
55
|
+
} else {
|
|
56
|
+
mask = true
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
child.__render(maskCanvas, options)
|
|
60
|
+
continue
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
child.__render(contentCanvas, options)
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
this.__renderMask(canvas, contentCanvas, maskCanvas)
|
|
67
|
+
maskCanvas.recycle()
|
|
68
|
+
contentCanvas.recycle()
|
|
69
|
+
|
|
70
|
+
} else {
|
|
71
|
+
|
|
72
|
+
const { bounds, hideBounds } = options
|
|
73
|
+
|
|
74
|
+
for (let i = 0, len = children.length; i < len; i++) {
|
|
75
|
+
child = children[i]
|
|
76
|
+
|
|
77
|
+
if (bounds && !bounds.hit(child.__world, options.matrix)) continue
|
|
78
|
+
if (hideBounds && hideBounds.includes(child.__world, options.matrix)) continue
|
|
79
|
+
|
|
80
|
+
child.__render(canvas, options)
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
}
|
package/src/LeafEventer.ts
CHANGED
|
@@ -7,9 +7,12 @@ export const LeafEventer: ILeafEventerModule = {
|
|
|
7
7
|
on(type: string | string[], listener: IEventListener, options?: IEventListenerOptions | boolean): void {
|
|
8
8
|
let capture: boolean, once: boolean
|
|
9
9
|
if (options) {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
10
|
+
if (typeof options === 'boolean') {
|
|
11
|
+
capture = options
|
|
12
|
+
} else {
|
|
13
|
+
capture = options.capture
|
|
14
|
+
once = options.once
|
|
15
|
+
}
|
|
13
16
|
}
|
|
14
17
|
|
|
15
18
|
let events: IEventListenerItem[]
|
package/src/LeafMask.ts
CHANGED
|
@@ -3,6 +3,10 @@ import { ILeaf, ILeaferCanvas, ILeafMaskModule } from '@leafer/interface'
|
|
|
3
3
|
|
|
4
4
|
export const LeafMask: ILeafMaskModule = {
|
|
5
5
|
|
|
6
|
+
__updateEraser(value?: boolean): void {
|
|
7
|
+
this.__hasEraser = value ? true : this.children.some(item => item.__.isEraser)
|
|
8
|
+
},
|
|
9
|
+
|
|
6
10
|
__updateMask(value?: boolean): void {
|
|
7
11
|
this.__hasMask = value ? true : this.children.some(item => item.__.isMask)
|
|
8
12
|
},
|
|
@@ -11,6 +15,7 @@ export const LeafMask: ILeafMaskModule = {
|
|
|
11
15
|
content.resetTransform()
|
|
12
16
|
content.useMask(mask)
|
|
13
17
|
canvas.resetTransform()
|
|
18
|
+
canvas.opacity = this.__worldOpacity
|
|
14
19
|
canvas.copyWorld(content)
|
|
15
20
|
},
|
|
16
21
|
|
package/src/LeafRender.ts
CHANGED
|
@@ -7,7 +7,17 @@ export const LeafRender: ILeafRenderModule = {
|
|
|
7
7
|
if (this.__worldOpacity) {
|
|
8
8
|
canvas.setWorld(this.__world, options.matrix)
|
|
9
9
|
canvas.opacity = this.__worldOpacity
|
|
10
|
-
|
|
10
|
+
|
|
11
|
+
if (this.__.__single) {
|
|
12
|
+
const tempCanvas = canvas.getSameCanvas(true)
|
|
13
|
+
|
|
14
|
+
this.__draw(tempCanvas, options)
|
|
15
|
+
|
|
16
|
+
canvas.copyWorldToInner(tempCanvas, this.__world, this.__layout.renderBounds, this.__.isEraser ? 'destination-out' : this.__.blendMode)
|
|
17
|
+
tempCanvas.recycle()
|
|
18
|
+
} else {
|
|
19
|
+
this.__draw(canvas, options)
|
|
20
|
+
}
|
|
11
21
|
}
|
|
12
22
|
},
|
|
13
23
|
|
package/src/index.ts
CHANGED