@leafer/display-module 1.0.0-alpha.9 → 1.0.0-beta
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/LeafBounds.ts +48 -39
- package/src/LeafDataProxy.ts +11 -18
- package/src/LeafEventer.ts +6 -4
- package/src/LeafHit.ts +9 -10
- package/src/LeafMask.ts +33 -0
- package/src/LeafMatrix.ts +4 -4
- package/src/LeafRender.ts +1 -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-
|
|
3
|
+
"version": "1.0.0-beta",
|
|
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-
|
|
23
|
-
"@leafer/math": "1.0.0-
|
|
22
|
+
"@leafer/event": "1.0.0-beta",
|
|
23
|
+
"@leafer/math": "1.0.0-beta"
|
|
24
24
|
},
|
|
25
25
|
"devDependencies": {
|
|
26
|
-
"@leafer/interface": "1.0.0-
|
|
26
|
+
"@leafer/interface": "1.0.0-beta"
|
|
27
27
|
}
|
|
28
28
|
}
|
package/src/LeafBounds.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { ILeafBoundsModule } from '@leafer/interface'
|
|
|
2
2
|
import { BoundsHelper } from '@leafer/math'
|
|
3
3
|
|
|
4
4
|
|
|
5
|
-
const {
|
|
5
|
+
const { toOuterOf, copyAndSpread } = BoundsHelper
|
|
6
6
|
|
|
7
7
|
export const LeafBounds: ILeafBoundsModule = {
|
|
8
8
|
|
|
@@ -14,97 +14,98 @@ export const LeafBounds: ILeafBoundsModule = {
|
|
|
14
14
|
const layout = this.__layout
|
|
15
15
|
|
|
16
16
|
|
|
17
|
-
if (layout.
|
|
17
|
+
if (layout.boxChanged) {
|
|
18
18
|
|
|
19
19
|
this.__updatePath()
|
|
20
20
|
this.__updateRenderPath()
|
|
21
21
|
|
|
22
22
|
this.__updateBoxBounds()
|
|
23
|
-
layout.
|
|
23
|
+
layout.boxChanged = false
|
|
24
24
|
resize = true
|
|
25
25
|
}
|
|
26
26
|
|
|
27
27
|
|
|
28
|
-
if (layout.
|
|
28
|
+
if (layout.localBoxChanged) { // position change
|
|
29
29
|
|
|
30
|
-
this.
|
|
31
|
-
layout.
|
|
30
|
+
this.__updateLocalBoxBounds()
|
|
31
|
+
layout.localBoxChanged = false
|
|
32
32
|
|
|
33
|
-
if (layout.
|
|
34
|
-
if (layout.
|
|
35
|
-
this.parent?.__layout.
|
|
33
|
+
if (layout.strokeSpread) layout.strokeChanged = true
|
|
34
|
+
if (layout.renderSpread) layout.renderChanged = true
|
|
35
|
+
this.parent?.__layout.boxChange()
|
|
36
36
|
}
|
|
37
37
|
|
|
38
38
|
|
|
39
|
-
if (layout.
|
|
39
|
+
if (layout.strokeChanged) {
|
|
40
40
|
|
|
41
|
-
layout.
|
|
41
|
+
layout.strokeSpread = this.__updateStrokeSpread()
|
|
42
42
|
|
|
43
|
-
if (layout.
|
|
43
|
+
if (layout.strokeSpread) {
|
|
44
44
|
|
|
45
|
-
if (layout.
|
|
46
|
-
layout.
|
|
45
|
+
if (layout.strokeBounds === layout.boxBounds) {
|
|
46
|
+
layout.spreadStroke()
|
|
47
47
|
}
|
|
48
48
|
|
|
49
|
-
this.
|
|
50
|
-
this.
|
|
51
|
-
layout.eventBoundsChanged = false
|
|
52
|
-
|
|
53
|
-
if (layout.renderBoundsSpreadWidth) layout.renderBoundsChanged = true
|
|
49
|
+
this.__updateStrokeBounds()
|
|
50
|
+
this.__updateLocalStrokeBounds()
|
|
54
51
|
|
|
55
52
|
} else {
|
|
56
|
-
layout.
|
|
53
|
+
layout.spreadStrokeCancel()
|
|
57
54
|
}
|
|
58
55
|
|
|
59
|
-
|
|
56
|
+
layout.strokeChanged = false
|
|
57
|
+
if (layout.renderSpread) layout.renderChanged = true
|
|
58
|
+
|
|
59
|
+
if (this.parent) this.parent.__layout.strokeChange()
|
|
60
60
|
resize || (resize = true)
|
|
61
61
|
}
|
|
62
62
|
|
|
63
63
|
|
|
64
|
-
if (layout.
|
|
64
|
+
if (layout.renderChanged) {
|
|
65
65
|
|
|
66
|
-
layout.
|
|
66
|
+
layout.renderSpread = this.__updateRenderSpread()
|
|
67
67
|
|
|
68
|
-
if (layout.
|
|
68
|
+
if (layout.renderSpread) {
|
|
69
69
|
|
|
70
|
-
if (layout.renderBounds === layout.boxBounds || layout.renderBounds === layout.
|
|
71
|
-
layout.
|
|
70
|
+
if (layout.renderBounds === layout.boxBounds || layout.renderBounds === layout.strokeBounds) {
|
|
71
|
+
layout.spreadRender()
|
|
72
72
|
}
|
|
73
73
|
|
|
74
74
|
this.__updateRenderBounds()
|
|
75
|
-
this.
|
|
76
|
-
layout.renderBoundsChanged = false
|
|
75
|
+
this.__updateLocalRenderBounds()
|
|
77
76
|
|
|
78
77
|
} else {
|
|
79
|
-
layout.
|
|
78
|
+
layout.spreadRenderCancel()
|
|
80
79
|
}
|
|
81
80
|
|
|
82
|
-
|
|
81
|
+
layout.renderChanged = false
|
|
82
|
+
|
|
83
|
+
if (this.parent) this.parent.__layout.renderChange()
|
|
83
84
|
}
|
|
84
85
|
|
|
85
86
|
|
|
86
87
|
layout.boundsChanged = false
|
|
87
88
|
|
|
88
|
-
|
|
89
|
+
toOuterOf(this.__layout.renderBounds, this.__world, this.__world)
|
|
89
90
|
|
|
90
91
|
if (resize) this.__onUpdateSize()
|
|
91
92
|
|
|
92
93
|
} else {
|
|
93
|
-
|
|
94
|
+
toOuterOf(this.__layout.renderBounds, this.__world, this.__world)
|
|
94
95
|
}
|
|
95
96
|
|
|
96
97
|
},
|
|
97
98
|
|
|
98
|
-
|
|
99
|
-
|
|
99
|
+
__updateLocalBoxBounds(): void {
|
|
100
|
+
toOuterOf(this.__layout.boxBounds, this.__local, this.__local)
|
|
100
101
|
},
|
|
101
102
|
|
|
102
|
-
|
|
103
|
-
|
|
103
|
+
__updateLocalStrokeBounds(): void {
|
|
104
|
+
toOuterOf(this.__layout.strokeBounds, this.__local, this.__layout.localStrokeBounds)
|
|
104
105
|
},
|
|
105
106
|
|
|
106
|
-
|
|
107
|
-
|
|
107
|
+
__updateLocalRenderBounds(): void {
|
|
108
|
+
toOuterOf(this.__layout.renderBounds, this.__local, this.__layout.localRenderBounds)
|
|
108
109
|
},
|
|
109
110
|
|
|
110
111
|
|
|
@@ -114,6 +115,14 @@ export const LeafBounds: ILeafBoundsModule = {
|
|
|
114
115
|
b.y = 0
|
|
115
116
|
b.width = this.__.width
|
|
116
117
|
b.height = this.__.height
|
|
117
|
-
}
|
|
118
|
+
},
|
|
119
|
+
|
|
120
|
+
__updateStrokeBounds(): void {
|
|
121
|
+
copyAndSpread(this.__layout.strokeBounds, this.__layout.boxBounds, this.__layout.strokeSpread)
|
|
122
|
+
},
|
|
123
|
+
|
|
124
|
+
__updateRenderBounds(): void {
|
|
125
|
+
copyAndSpread(this.__layout.renderBounds, this.__layout.strokeBounds, this.__layout.renderSpread)
|
|
126
|
+
},
|
|
118
127
|
|
|
119
128
|
}
|
package/src/LeafDataProxy.ts
CHANGED
|
@@ -1,30 +1,23 @@
|
|
|
1
1
|
import { ILeafDataProxyModule } from '@leafer/interface'
|
|
2
|
-
import {
|
|
2
|
+
import { PropertyEvent } from '@leafer/event'
|
|
3
3
|
|
|
4
4
|
|
|
5
5
|
export const LeafDataProxy: ILeafDataProxyModule = {
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
if (this.
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
7
|
+
__setAttr(name: string, newValue: unknown): void {
|
|
8
|
+
if (this.leafer && this.leafer.ready) {
|
|
9
|
+
this.__[name] = newValue
|
|
10
|
+
const { CHANGE } = PropertyEvent
|
|
11
|
+
const event = new PropertyEvent(CHANGE, this, name, this.__.__get(name), newValue)
|
|
12
|
+
if (this.hasEvent(CHANGE) && !this.isLeafer) this.emitEvent(event)
|
|
13
|
+
this.leafer.emitEvent(event)
|
|
14
14
|
} else {
|
|
15
|
-
this.__[
|
|
15
|
+
this.__[name] = newValue
|
|
16
16
|
}
|
|
17
17
|
},
|
|
18
18
|
|
|
19
|
-
|
|
20
|
-
return this.__.
|
|
21
|
-
},
|
|
22
|
-
|
|
23
|
-
__updateAttr(attrName: string): void {
|
|
24
|
-
if (this.root) {
|
|
25
|
-
const value = this.__.__getInput(attrName)
|
|
26
|
-
this.root.emitEvent(new AttrEvent(AttrEvent.CHANGE, this, attrName, value, value))
|
|
27
|
-
}
|
|
19
|
+
__getAttr(name: string): unknown {
|
|
20
|
+
return this.__.__get(name)
|
|
28
21
|
}
|
|
29
22
|
|
|
30
23
|
}
|
package/src/LeafEventer.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { IEventListener, IEventListenerOptions, IEventListenerMap, IEventListenerItem, IEventListenerId, IEvent, IObject, IEventTarget, ILeafEventerModule } from '@leafer/interface'
|
|
2
2
|
|
|
3
|
-
|
|
4
3
|
const empty = {}
|
|
5
4
|
|
|
6
5
|
export const LeafEventer: ILeafEventerModule = {
|
|
@@ -50,13 +49,13 @@ export const LeafEventer: ILeafEventerModule = {
|
|
|
50
49
|
})
|
|
51
50
|
},
|
|
52
51
|
|
|
53
|
-
|
|
52
|
+
on_(type: string | string[], listener: IEventListener, bind?: IObject, options?: IEventListenerOptions | boolean): IEventListenerId {
|
|
54
53
|
if (bind) listener = listener.bind(bind)
|
|
55
54
|
this.on(type, listener, options)
|
|
56
55
|
return { type, listener, options }
|
|
57
56
|
},
|
|
58
57
|
|
|
59
|
-
|
|
58
|
+
off_(id: IEventListenerId | IEventListenerId[]): void {
|
|
60
59
|
if (!id) return
|
|
61
60
|
const list = id instanceof Array ? id : [id]
|
|
62
61
|
list.forEach(item => {
|
|
@@ -77,7 +76,10 @@ export const LeafEventer: ILeafEventerModule = {
|
|
|
77
76
|
for (let i = 0, len = list.length; i < len; i++) {
|
|
78
77
|
item = list[i]
|
|
79
78
|
item.listener(event)
|
|
80
|
-
if (item.once)
|
|
79
|
+
if (item.once) {
|
|
80
|
+
this.off(type, item.listener, capture)
|
|
81
|
+
i--, len--
|
|
82
|
+
}
|
|
81
83
|
if (event && (event as IEvent).isStopNow) break
|
|
82
84
|
}
|
|
83
85
|
}
|
package/src/LeafHit.ts
CHANGED
|
@@ -1,24 +1,23 @@
|
|
|
1
|
-
import { ILeafHitModule, IRadiusPointData } from '@leafer/interface'
|
|
1
|
+
import { ILeafHitModule, IRadiusPointData, ILeaferCanvas } from '@leafer/interface'
|
|
2
2
|
import { PointHelper } from '@leafer/math'
|
|
3
3
|
|
|
4
4
|
|
|
5
|
-
const {
|
|
6
|
-
const
|
|
5
|
+
const { toInnerRadiusPointOf } = PointHelper
|
|
6
|
+
const inner = {} as IRadiusPointData
|
|
7
7
|
|
|
8
8
|
export const LeafHit: ILeafHitModule = {
|
|
9
9
|
|
|
10
|
-
__updateHitCanvas(): void {
|
|
11
|
-
if (!this.__hitCanvas) this.__hitCanvas = this.leafer.hitCanvasManager.getPathType(this)
|
|
12
|
-
this.__drawRenderPath(this.__hitCanvas)
|
|
13
|
-
},
|
|
14
|
-
|
|
15
10
|
__hitWorld(point: IRadiusPointData): boolean {
|
|
16
11
|
if (this.__layout.hitCanvasChanged) {
|
|
17
12
|
this.__updateHitCanvas()
|
|
18
13
|
this.__layout.hitCanvasChanged = false
|
|
19
14
|
}
|
|
20
|
-
|
|
21
|
-
return this.__hit(
|
|
15
|
+
toInnerRadiusPointOf(point, this.__world, inner)
|
|
16
|
+
return this.__hit(inner)
|
|
17
|
+
},
|
|
18
|
+
|
|
19
|
+
__drawHitPath(canvas: ILeaferCanvas): void {
|
|
20
|
+
this.__drawRenderPath(canvas)
|
|
22
21
|
}
|
|
23
22
|
|
|
24
23
|
}
|
package/src/LeafMask.ts
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { ILeaf, ILeaferCanvas, ILeafMaskModule } from '@leafer/interface'
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
export const LeafMask: ILeafMaskModule = {
|
|
5
|
+
|
|
6
|
+
__updateMask(value?: boolean): void {
|
|
7
|
+
this.__hasMask = value ? true : this.children.some(item => item.__.isMask)
|
|
8
|
+
},
|
|
9
|
+
|
|
10
|
+
__renderMask(canvas: ILeaferCanvas, content: ILeaferCanvas, mask: ILeaferCanvas): void {
|
|
11
|
+
content.resetTransform()
|
|
12
|
+
content.useMask(mask)
|
|
13
|
+
canvas.resetTransform()
|
|
14
|
+
canvas.copyWorld(content)
|
|
15
|
+
},
|
|
16
|
+
|
|
17
|
+
__removeMask(child?: ILeaf): void {
|
|
18
|
+
if (child) {
|
|
19
|
+
child.isMask = false
|
|
20
|
+
this.remove(child)
|
|
21
|
+
} else {
|
|
22
|
+
const { children } = this
|
|
23
|
+
for (let i = 0, len = children.length; i < len; i++) {
|
|
24
|
+
child = children[i]
|
|
25
|
+
if (child.isMask) {
|
|
26
|
+
this.__removeMask(child)
|
|
27
|
+
len--, i--
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
}
|
package/src/LeafMatrix.ts
CHANGED
|
@@ -10,10 +10,10 @@ export const LeafMatrix: ILeafMatrixModule = {
|
|
|
10
10
|
__updateWorldMatrix(): void {
|
|
11
11
|
|
|
12
12
|
const pw = this.parent ? this.parent.__world : defaultMatrix
|
|
13
|
-
const r = this.
|
|
13
|
+
const r = this.__local
|
|
14
14
|
const w = this.__world
|
|
15
15
|
|
|
16
|
-
if (this.__layout.matrixChanged) this.
|
|
16
|
+
if (this.__layout.matrixChanged) this.__updateLocalMatrix()
|
|
17
17
|
|
|
18
18
|
if (this.__layout.affectScaleOrRotation) {
|
|
19
19
|
w.a = r.a * pw.a + r.b * pw.c
|
|
@@ -32,9 +32,9 @@ export const LeafMatrix: ILeafMatrixModule = {
|
|
|
32
32
|
}
|
|
33
33
|
},
|
|
34
34
|
|
|
35
|
-
|
|
35
|
+
__updateLocalMatrix(): void {
|
|
36
36
|
|
|
37
|
-
const r = this.
|
|
37
|
+
const r = this.__local
|
|
38
38
|
const layout = this.__layout
|
|
39
39
|
|
|
40
40
|
if (layout.affectScaleOrRotation) {
|
package/src/LeafRender.ts
CHANGED
|
@@ -7,7 +7,7 @@ export const LeafRender: ILeafRenderModule = {
|
|
|
7
7
|
if (this.__worldOpacity) {
|
|
8
8
|
canvas.setWorld(this.__world, options.matrix)
|
|
9
9
|
canvas.opacity = this.__worldOpacity
|
|
10
|
-
this.
|
|
10
|
+
this.__draw(canvas, options)
|
|
11
11
|
}
|
|
12
12
|
},
|
|
13
13
|
|