@leafer/helper 1.0.0-alpha.21 → 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 +3 -3
- package/src/BranchHelper.ts +3 -3
- package/src/LeafBoundsHelper.ts +18 -6
- package/src/LeafHelper.ts +35 -32
- package/src/WaitHelper.ts +8 -0
- package/src/index.ts +1 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@leafer/helper",
|
|
3
|
-
"version": "1.0.0-alpha.
|
|
3
|
+
"version": "1.0.0-alpha.30",
|
|
4
4
|
"description": "@leafer/helper",
|
|
5
5
|
"author": "Chao (Leafer) Wan",
|
|
6
6
|
"license": "MIT",
|
|
@@ -19,9 +19,9 @@
|
|
|
19
19
|
"leaferjs"
|
|
20
20
|
],
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"@leafer/math": "1.0.0-alpha.
|
|
22
|
+
"@leafer/math": "1.0.0-alpha.30"
|
|
23
23
|
},
|
|
24
24
|
"devDependencies": {
|
|
25
|
-
"@leafer/interface": "1.0.0-alpha.
|
|
25
|
+
"@leafer/interface": "1.0.0-alpha.30"
|
|
26
26
|
}
|
|
27
27
|
}
|
package/src/BranchHelper.ts
CHANGED
|
@@ -17,11 +17,11 @@ export const BranchHelper = {
|
|
|
17
17
|
pushAllChildBranch(branch: ILeaf, pushList: ILeafPushList): void {
|
|
18
18
|
branch.__tempNumber = 1 // 标识需要更新子Leaf元素的WorldBounds分支 Layouter需使用
|
|
19
19
|
|
|
20
|
-
if (branch.__childBranchNumber) {
|
|
20
|
+
if (branch.__.__childBranchNumber) {
|
|
21
21
|
const { children } = branch
|
|
22
22
|
for (let i = 0, len = children.length; i < len; i++) {
|
|
23
23
|
branch = children[i]
|
|
24
|
-
if (branch.
|
|
24
|
+
if (branch.isBranch) {
|
|
25
25
|
branch.__tempNumber = 1
|
|
26
26
|
pushList.push(branch)
|
|
27
27
|
pushAllChildBranch(branch, pushList)
|
|
@@ -53,7 +53,7 @@ export const BranchHelper = {
|
|
|
53
53
|
let start = pushList.length
|
|
54
54
|
const { children } = branch
|
|
55
55
|
for (let i = 0, len = children.length; i < len; i++) {
|
|
56
|
-
if (children[i].
|
|
56
|
+
if (children[i].isBranch) {
|
|
57
57
|
pushList.push(children[i])
|
|
58
58
|
}
|
|
59
59
|
}
|
package/src/LeafBoundsHelper.ts
CHANGED
|
@@ -7,16 +7,28 @@ export const LeafBoundsHelper = {
|
|
|
7
7
|
return target.__world
|
|
8
8
|
},
|
|
9
9
|
|
|
10
|
-
|
|
11
|
-
return target.
|
|
10
|
+
localBoxBounds(target: ILeaf): IBoundsData {
|
|
11
|
+
return target.__local
|
|
12
12
|
},
|
|
13
13
|
|
|
14
|
-
|
|
15
|
-
return target.__layout.
|
|
14
|
+
localEventBounds(target: ILeaf): IBoundsData {
|
|
15
|
+
return target.__layout.localStrokeBounds
|
|
16
16
|
},
|
|
17
17
|
|
|
18
|
-
|
|
19
|
-
return target.__layout.
|
|
18
|
+
localRenderBounds(target: ILeaf): IBoundsData {
|
|
19
|
+
return target.__layout.localRenderBounds
|
|
20
|
+
},
|
|
21
|
+
|
|
22
|
+
maskLocalBoxBounds(target: ILeaf): IBoundsData {
|
|
23
|
+
return target.isMask ? target.__local : null
|
|
24
|
+
},
|
|
25
|
+
|
|
26
|
+
maskLocalEventBounds(target: ILeaf): IBoundsData {
|
|
27
|
+
return target.isMask ? target.__layout.localStrokeBounds : null
|
|
28
|
+
},
|
|
29
|
+
|
|
30
|
+
maskLocalRenderBounds(target: ILeaf): IBoundsData {
|
|
31
|
+
return target.isMask ? target.__layout.localRenderBounds : null
|
|
20
32
|
}
|
|
21
33
|
|
|
22
34
|
}
|
package/src/LeafHelper.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ILeaf, IPointData } from '@leafer/interface'
|
|
1
|
+
import { IBranch, ILeaf, IPointData } from '@leafer/interface'
|
|
2
2
|
import { Matrix, MatrixHelper, PointHelper } from '@leafer/math'
|
|
3
3
|
|
|
4
4
|
|
|
@@ -7,7 +7,7 @@ export const LeafHelper = {
|
|
|
7
7
|
updateAllWorldMatrix(leaf: ILeaf): void {
|
|
8
8
|
leaf.__updateWorldMatrix()
|
|
9
9
|
|
|
10
|
-
if (leaf.
|
|
10
|
+
if (leaf.isBranch) {
|
|
11
11
|
const { children } = leaf
|
|
12
12
|
for (let i = 0, len = children.length; i < len; i++) {
|
|
13
13
|
updateAllWorldMatrix(children[i])
|
|
@@ -18,7 +18,7 @@ export const LeafHelper = {
|
|
|
18
18
|
updateAllWorldOpacity(leaf: ILeaf): void {
|
|
19
19
|
leaf.__updateWorldOpacity()
|
|
20
20
|
|
|
21
|
-
if (leaf.
|
|
21
|
+
if (leaf.isBranch) {
|
|
22
22
|
const { children } = leaf
|
|
23
23
|
for (let i = 0, len = children.length; i < len; i++) {
|
|
24
24
|
updateAllWorldOpacity(children[i])
|
|
@@ -32,7 +32,7 @@ export const LeafHelper = {
|
|
|
32
32
|
|
|
33
33
|
leaf.__updateChange()
|
|
34
34
|
|
|
35
|
-
if (leaf.
|
|
35
|
+
if (leaf.isBranch) {
|
|
36
36
|
const { children } = leaf
|
|
37
37
|
for (let i = 0, len = children.length; i < len; i++) {
|
|
38
38
|
updateAllChange(children[i])
|
|
@@ -43,50 +43,53 @@ export const LeafHelper = {
|
|
|
43
43
|
|
|
44
44
|
// transform
|
|
45
45
|
|
|
46
|
-
|
|
47
|
-
const local = { x
|
|
48
|
-
if (t.parent) MatrixHelper.
|
|
49
|
-
L.
|
|
46
|
+
move(t: ILeaf, x: number, y: number): void {
|
|
47
|
+
const local = { x, y }
|
|
48
|
+
if (t.parent) MatrixHelper.toInnerPoint(t.parent.__world, local, local, true)
|
|
49
|
+
L.moveLocal(t, local.x, local.y)
|
|
50
50
|
},
|
|
51
51
|
|
|
52
|
-
|
|
52
|
+
moveLocal(t: ILeaf, x: number, y: number): void {
|
|
53
53
|
t.x = t.__.x + x
|
|
54
54
|
t.y = t.__.y + y
|
|
55
55
|
},
|
|
56
56
|
|
|
57
|
-
|
|
58
|
-
const local = t.parent ? PointHelper.
|
|
59
|
-
this.
|
|
57
|
+
zoomOf(t: ILeaf, center: IPointData, scaleX: number, scaleY?: number, moveLayer?: ILeaf): void {
|
|
58
|
+
const local = t.parent ? PointHelper.tempToInnerOf(center, t.parent.__world) : center
|
|
59
|
+
this.zoomOfLocal(t, local, scaleX, scaleY, moveLayer)
|
|
60
60
|
},
|
|
61
61
|
|
|
62
|
-
|
|
62
|
+
zoomOfLocal(t: ILeaf, center: IPointData, scaleX: number, scaleY?: number, moveLayer?: ILeaf): void {
|
|
63
|
+
if (!scaleY) scaleY = scaleX
|
|
63
64
|
if (!moveLayer) moveLayer = t
|
|
64
65
|
const { x, y } = moveLayer.__
|
|
65
|
-
const
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
moveLayer.y = y - matrix.f
|
|
71
|
-
t.scaleX = scaleX * scale
|
|
72
|
-
t.scaleY = scaleY * scale
|
|
66
|
+
const matrix = new Matrix().translate(x, y).scaleOf(center, scaleX, scaleY)
|
|
67
|
+
moveLayer.x = matrix.e
|
|
68
|
+
moveLayer.y = matrix.f
|
|
69
|
+
t.scaleX = t.__.scaleX * scaleX
|
|
70
|
+
t.scaleY = t.__.scaleY * scaleY
|
|
73
71
|
},
|
|
74
72
|
|
|
75
|
-
|
|
76
|
-
const local = t.parent ? PointHelper.
|
|
77
|
-
this.
|
|
73
|
+
rotateOf(t: ILeaf, center: IPointData, angle: number, moveLayer?: ILeaf): void {
|
|
74
|
+
const local = t.parent ? PointHelper.tempToInnerOf(center, t.parent.__world) : center
|
|
75
|
+
this.rotateOfLocal(t, local, angle, moveLayer)
|
|
78
76
|
},
|
|
79
77
|
|
|
80
|
-
|
|
78
|
+
rotateOfLocal(t: ILeaf, center: IPointData, angle: number, moveLayer?: ILeaf): void {
|
|
81
79
|
if (!moveLayer) moveLayer = t
|
|
82
80
|
const { x, y } = moveLayer.__
|
|
83
|
-
const
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
81
|
+
const matrix = new Matrix().translate(x, y).rotateOf(center, angle)
|
|
82
|
+
moveLayer.x = matrix.e
|
|
83
|
+
moveLayer.y = matrix.f
|
|
84
|
+
t.rotation = t.__.rotation + angle
|
|
85
|
+
},
|
|
86
|
+
|
|
87
|
+
drop(t: ILeaf, parent: IBranch): void {
|
|
88
|
+
const position = { x: t.x, y: t.y }
|
|
89
|
+
t.localToWorld(position)
|
|
90
|
+
parent.worldToInner(position)
|
|
91
|
+
t.set(position)
|
|
92
|
+
parent.add(t)
|
|
90
93
|
}
|
|
91
94
|
|
|
92
95
|
}
|
package/src/index.ts
CHANGED