@leafer/helper 1.0.0-rc.6 → 1.0.0-rc.8
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 +24 -18
- package/src/LeafBoundsHelper.ts +4 -4
- package/src/LeafHelper.ts +78 -38
- package/types/index.d.ts +19 -16
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@leafer/helper",
|
|
3
|
-
"version": "1.0.0-rc.
|
|
3
|
+
"version": "1.0.0-rc.8",
|
|
4
4
|
"description": "@leafer/helper",
|
|
5
5
|
"author": "Chao (Leafer) Wan",
|
|
6
6
|
"license": "MIT",
|
|
@@ -22,9 +22,9 @@
|
|
|
22
22
|
"leaferjs"
|
|
23
23
|
],
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@leafer/math": "1.0.0-rc.
|
|
25
|
+
"@leafer/math": "1.0.0-rc.8"
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|
|
28
|
-
"@leafer/interface": "1.0.0-rc.
|
|
28
|
+
"@leafer/interface": "1.0.0-rc.8"
|
|
29
29
|
}
|
|
30
30
|
}
|
package/src/BranchHelper.ts
CHANGED
|
@@ -1,10 +1,8 @@
|
|
|
1
|
-
import { ILeaf, ILeafList } from '@leafer/interface'
|
|
1
|
+
import { ILeaf, ILeafLevelList, ILeafList } from '@leafer/interface'
|
|
2
2
|
|
|
3
|
+
import { LeafHelper } from './LeafHelper'
|
|
3
4
|
|
|
4
|
-
|
|
5
|
-
push(item: ILeaf): void
|
|
6
|
-
}
|
|
7
|
-
|
|
5
|
+
const { updateBounds } = LeafHelper
|
|
8
6
|
|
|
9
7
|
export const BranchHelper = {
|
|
10
8
|
|
|
@@ -14,7 +12,7 @@ export const BranchHelper = {
|
|
|
14
12
|
|
|
15
13
|
// push
|
|
16
14
|
|
|
17
|
-
pushAllChildBranch(branch: ILeaf,
|
|
15
|
+
pushAllChildBranch(branch: ILeaf, leafList: ILeafList | ILeafLevelList): void {
|
|
18
16
|
branch.__tempNumber = 1 // 标识需要更新子Leaf元素的WorldBounds分支 Layouter需使用
|
|
19
17
|
|
|
20
18
|
if (branch.__.__childBranchNumber) {
|
|
@@ -23,19 +21,19 @@ export const BranchHelper = {
|
|
|
23
21
|
branch = children[i]
|
|
24
22
|
if (branch.isBranch) {
|
|
25
23
|
branch.__tempNumber = 1
|
|
26
|
-
|
|
27
|
-
pushAllChildBranch(branch,
|
|
24
|
+
leafList.add(branch)
|
|
25
|
+
pushAllChildBranch(branch, leafList)
|
|
28
26
|
}
|
|
29
27
|
}
|
|
30
28
|
}
|
|
31
29
|
},
|
|
32
30
|
|
|
33
|
-
pushAllParent(leaf: ILeaf,
|
|
34
|
-
const { keys } = (
|
|
31
|
+
pushAllParent(leaf: ILeaf, leafList: ILeafList | ILeafLevelList): void {
|
|
32
|
+
const { keys } = (leafList as ILeafList)
|
|
35
33
|
if (keys) {
|
|
36
34
|
while (leaf.parent) {
|
|
37
35
|
if (keys[leaf.parent.innerId] === undefined) {
|
|
38
|
-
|
|
36
|
+
leafList.add(leaf.parent)
|
|
39
37
|
leaf = leaf.parent
|
|
40
38
|
} else {
|
|
41
39
|
break
|
|
@@ -43,7 +41,7 @@ export const BranchHelper = {
|
|
|
43
41
|
}
|
|
44
42
|
} else {
|
|
45
43
|
while (leaf.parent) {
|
|
46
|
-
|
|
44
|
+
leafList.add(leaf.parent)
|
|
47
45
|
leaf = leaf.parent
|
|
48
46
|
}
|
|
49
47
|
}
|
|
@@ -64,16 +62,24 @@ export const BranchHelper = {
|
|
|
64
62
|
}
|
|
65
63
|
},
|
|
66
64
|
|
|
67
|
-
|
|
68
|
-
|
|
65
|
+
updateBounds(branch: ILeaf, exclude?: ILeaf): void {
|
|
66
|
+
const branchStack: ILeaf[] = [branch]
|
|
67
|
+
pushAllBranchStack(branch, branchStack)
|
|
68
|
+
updateBoundsByBranchStack(branchStack, exclude)
|
|
69
|
+
},
|
|
70
|
+
|
|
71
|
+
updateBoundsByBranchStack(branchStack: ILeaf[], exclude?: ILeaf): void {
|
|
72
|
+
let branch: ILeaf, children: ILeaf[]
|
|
69
73
|
for (let i = branchStack.length - 1; i > -1; i--) {
|
|
70
74
|
branch = branchStack[i]
|
|
71
|
-
|
|
72
|
-
|
|
75
|
+
children = branch.children
|
|
76
|
+
for (let j = 0, len = children.length; j < len; j++) {
|
|
77
|
+
updateBounds(children[j])
|
|
73
78
|
}
|
|
79
|
+
if (exclude && exclude === branch) continue
|
|
80
|
+
updateBounds(branch)
|
|
74
81
|
}
|
|
75
|
-
branch.__updateWorldBounds()
|
|
76
82
|
}
|
|
77
83
|
}
|
|
78
84
|
|
|
79
|
-
const { pushAllChildBranch, pushAllBranchStack } = BranchHelper
|
|
85
|
+
const { pushAllChildBranch, pushAllBranchStack, updateBoundsByBranchStack } = BranchHelper
|
package/src/LeafBoundsHelper.ts
CHANGED
|
@@ -8,10 +8,10 @@ export const LeafBoundsHelper = {
|
|
|
8
8
|
},
|
|
9
9
|
|
|
10
10
|
localBoxBounds(target: ILeaf): IBoundsData {
|
|
11
|
-
return target.__.isEraser ? null : target.__local
|
|
11
|
+
return target.__.isEraser ? null : (target.__local || target.__ as IBoundsData)
|
|
12
12
|
},
|
|
13
13
|
|
|
14
|
-
|
|
14
|
+
localStrokeBounds(target: ILeaf): IBoundsData {
|
|
15
15
|
return target.__.isEraser ? null : target.__layout.localStrokeBounds
|
|
16
16
|
},
|
|
17
17
|
|
|
@@ -20,10 +20,10 @@ export const LeafBoundsHelper = {
|
|
|
20
20
|
},
|
|
21
21
|
|
|
22
22
|
maskLocalBoxBounds(target: ILeaf): IBoundsData {
|
|
23
|
-
return target.__.isMask ? target.
|
|
23
|
+
return target.__.isMask ? target.__localBounds : null
|
|
24
24
|
},
|
|
25
25
|
|
|
26
|
-
|
|
26
|
+
maskLocalStrokeBounds(target: ILeaf): IBoundsData {
|
|
27
27
|
return target.__.isMask ? target.__layout.localStrokeBounds : null
|
|
28
28
|
},
|
|
29
29
|
|
package/src/LeafHelper.ts
CHANGED
|
@@ -1,23 +1,47 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ILeaf, IMatrixData, IPointData } from '@leafer/interface'
|
|
2
2
|
import { MathHelper, MatrixHelper, PointHelper } from '@leafer/math'
|
|
3
3
|
|
|
4
4
|
|
|
5
|
-
const { copy, toInnerPoint, scaleOfOuter, rotateOfOuter, skewOfOuter } = MatrixHelper
|
|
5
|
+
const { copy, toInnerPoint, scaleOfOuter, rotateOfOuter, skewOfOuter, multiplyParent, divideParent, getLayout } = MatrixHelper
|
|
6
6
|
const matrix = {} as IMatrixData
|
|
7
7
|
|
|
8
8
|
export const LeafHelper = {
|
|
9
9
|
|
|
10
|
-
|
|
11
|
-
leaf.
|
|
10
|
+
updateAllMatrix(leaf: ILeaf, checkAutoLayout?: boolean, waitAutoLayout?: boolean): void {
|
|
11
|
+
if (checkAutoLayout && leaf.__hasAutoLayout && leaf.__layout.matrixChanged) waitAutoLayout = true
|
|
12
|
+
|
|
13
|
+
updateMatrix(leaf, checkAutoLayout, waitAutoLayout)
|
|
12
14
|
|
|
13
15
|
if (leaf.isBranch) {
|
|
14
16
|
const { children } = leaf
|
|
15
17
|
for (let i = 0, len = children.length; i < len; i++) {
|
|
16
|
-
|
|
18
|
+
updateAllMatrix(children[i], checkAutoLayout, waitAutoLayout)
|
|
17
19
|
}
|
|
18
20
|
}
|
|
19
21
|
},
|
|
20
22
|
|
|
23
|
+
updateMatrix(leaf: ILeaf, checkAutoLayout?: boolean, waitAutoLayout?: boolean): void {
|
|
24
|
+
const layout = leaf.__layout
|
|
25
|
+
|
|
26
|
+
if (checkAutoLayout) {
|
|
27
|
+
if (waitAutoLayout) {
|
|
28
|
+
layout.waitAutoLayout = true
|
|
29
|
+
if (leaf.__hasAutoLayout) layout.matrixChanged = false // wait updateAutoLayout
|
|
30
|
+
}
|
|
31
|
+
} else if (layout.waitAutoLayout) {
|
|
32
|
+
layout.waitAutoLayout = false
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
if (layout.matrixChanged) leaf.__updateLocalMatrix()
|
|
36
|
+
if (!layout.waitAutoLayout) leaf.__updateWorldMatrix()
|
|
37
|
+
},
|
|
38
|
+
|
|
39
|
+
updateBounds(leaf: ILeaf): void {
|
|
40
|
+
const layout = leaf.__layout
|
|
41
|
+
if (layout.boundsChanged) leaf.__updateLocalBounds()
|
|
42
|
+
if (!layout.waitAutoLayout) leaf.__updateWorldBounds()
|
|
43
|
+
},
|
|
44
|
+
|
|
21
45
|
updateAllWorldOpacity(leaf: ILeaf): void {
|
|
22
46
|
leaf.__updateWorldOpacity()
|
|
23
47
|
|
|
@@ -30,7 +54,6 @@ export const LeafHelper = {
|
|
|
30
54
|
},
|
|
31
55
|
|
|
32
56
|
updateAllChange(leaf: ILeaf): void {
|
|
33
|
-
|
|
34
57
|
updateAllWorldOpacity(leaf)
|
|
35
58
|
|
|
36
59
|
leaf.__updateChange()
|
|
@@ -44,11 +67,9 @@ export const LeafHelper = {
|
|
|
44
67
|
},
|
|
45
68
|
|
|
46
69
|
worldHittable(t: ILeaf): boolean {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
if (!parent.__.hittable || !parent.__.hitChildren) return false
|
|
51
|
-
parent = parent.parent
|
|
70
|
+
while (t) {
|
|
71
|
+
if (!t.__.hittable) return false
|
|
72
|
+
t = t.parent
|
|
52
73
|
}
|
|
53
74
|
return true
|
|
54
75
|
},
|
|
@@ -66,16 +87,15 @@ export const LeafHelper = {
|
|
|
66
87
|
t.y += y
|
|
67
88
|
},
|
|
68
89
|
|
|
69
|
-
zoomOfWorld(t: ILeaf, origin: IPointData, scaleX: number, scaleY?: number): void {
|
|
70
|
-
this.zoomOfLocal(t, getTempLocal(t, origin), scaleX, scaleY)
|
|
90
|
+
zoomOfWorld(t: ILeaf, origin: IPointData, scaleX: number, scaleY?: number, resize?: boolean): void {
|
|
91
|
+
this.zoomOfLocal(t, getTempLocal(t, origin), scaleX, scaleY, resize)
|
|
71
92
|
},
|
|
72
93
|
|
|
73
|
-
zoomOfLocal(t: ILeaf, origin: IPointData, scaleX: number, scaleY: number = scaleX): void {
|
|
74
|
-
copy(matrix, t.
|
|
94
|
+
zoomOfLocal(t: ILeaf, origin: IPointData, scaleX: number, scaleY: number = scaleX, resize?: boolean): void {
|
|
95
|
+
copy(matrix, t.__localMatrix)
|
|
75
96
|
scaleOfOuter(matrix, origin, scaleX, scaleY)
|
|
76
97
|
moveByMatrix(t, matrix)
|
|
77
|
-
t.scaleX
|
|
78
|
-
t.scaleY *= scaleY
|
|
98
|
+
t.scaleResize(scaleX, scaleY, resize !== true)
|
|
79
99
|
},
|
|
80
100
|
|
|
81
101
|
rotateOfWorld(t: ILeaf, origin: IPointData, angle: number): void {
|
|
@@ -83,53 +103,73 @@ export const LeafHelper = {
|
|
|
83
103
|
},
|
|
84
104
|
|
|
85
105
|
rotateOfLocal(t: ILeaf, origin: IPointData, angle: number): void {
|
|
86
|
-
copy(matrix, t.
|
|
106
|
+
copy(matrix, t.__localMatrix)
|
|
87
107
|
rotateOfOuter(matrix, origin, angle)
|
|
88
108
|
moveByMatrix(t, matrix)
|
|
89
109
|
t.rotation = MathHelper.formatRotation(t.rotation + angle)
|
|
90
110
|
},
|
|
91
111
|
|
|
92
|
-
skewOfWorld(t: ILeaf, origin: IPointData, skewX: number, skewY?: number): void {
|
|
93
|
-
this.skewOfLocal(t, getTempLocal(t, origin), skewX, skewY)
|
|
112
|
+
skewOfWorld(t: ILeaf, origin: IPointData, skewX: number, skewY?: number, resize?: boolean): void {
|
|
113
|
+
this.skewOfLocal(t, getTempLocal(t, origin), skewX, skewY, resize)
|
|
94
114
|
},
|
|
95
115
|
|
|
96
|
-
skewOfLocal(t: ILeaf, origin: IPointData, skewX: number, skewY: number): void {
|
|
97
|
-
copy(matrix, t.
|
|
116
|
+
skewOfLocal(t: ILeaf, origin: IPointData, skewX: number, skewY: number = 0, resize?: boolean): void {
|
|
117
|
+
copy(matrix, t.__localMatrix)
|
|
98
118
|
skewOfOuter(matrix, origin, skewX, skewY)
|
|
99
|
-
|
|
100
|
-
t.skewX = MathHelper.formatSkew(t.skewX + skewX)
|
|
101
|
-
t.skewY = MathHelper.formatSkew(t.skewY + skewY)
|
|
119
|
+
L.setTransform(t, matrix, resize)
|
|
102
120
|
},
|
|
103
121
|
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
t.set(position)
|
|
109
|
-
parent.add(t)
|
|
122
|
+
transform(t: ILeaf, transform: IMatrixData, resize?: boolean): void {
|
|
123
|
+
copy(matrix, t.localTransform)
|
|
124
|
+
multiplyParent(matrix, transform)
|
|
125
|
+
L.setTransform(t, matrix, resize)
|
|
110
126
|
},
|
|
111
127
|
|
|
112
|
-
|
|
128
|
+
setTransform(t: ILeaf, transform: IMatrixData, resize?: boolean): void {
|
|
129
|
+
const layout = getLayout(transform)
|
|
130
|
+
if (resize) {
|
|
131
|
+
t.scaleResize(layout.scaleX / t.scaleX, layout.scaleY / t.scaleY, resize !== true)
|
|
132
|
+
delete layout.scaleX
|
|
133
|
+
delete layout.scaleY
|
|
134
|
+
}
|
|
135
|
+
t.set(layout)
|
|
136
|
+
},
|
|
137
|
+
|
|
138
|
+
|
|
139
|
+
drop(t: ILeaf, parent: ILeaf, index?: number, resize?: boolean): void {
|
|
140
|
+
copy(matrix, t.worldTransform)
|
|
141
|
+
divideParent(matrix, parent.worldTransform)
|
|
142
|
+
t.setTransform(matrix, resize)
|
|
143
|
+
parent.add(t, index)
|
|
144
|
+
},
|
|
145
|
+
|
|
146
|
+
hasParent(p: ILeaf, parent: ILeaf): boolean | void {
|
|
113
147
|
if (!parent) return false
|
|
114
|
-
let p = t
|
|
115
148
|
while (p) {
|
|
116
149
|
if (parent === p) return true
|
|
117
150
|
p = p.parent
|
|
118
151
|
}
|
|
119
|
-
|
|
152
|
+
},
|
|
153
|
+
|
|
154
|
+
hasParentAutoLayout(p: ILeaf): boolean | void {
|
|
155
|
+
while (p.parent) {
|
|
156
|
+
p = p.parent
|
|
157
|
+
if (p.__hasAutoLayout) return true
|
|
158
|
+
}
|
|
120
159
|
}
|
|
121
160
|
|
|
122
161
|
}
|
|
123
162
|
|
|
124
163
|
const L = LeafHelper
|
|
125
|
-
const {
|
|
164
|
+
const { updateAllMatrix, updateMatrix, updateAllWorldOpacity, updateAllChange } = L
|
|
126
165
|
|
|
127
166
|
function moveByMatrix(t: ILeaf, matrix: IMatrixData): void {
|
|
128
|
-
|
|
129
|
-
t.
|
|
167
|
+
const { e, f } = t.__localMatrix
|
|
168
|
+
t.x += matrix.e - e
|
|
169
|
+
t.y += matrix.f - f
|
|
130
170
|
}
|
|
131
171
|
|
|
132
172
|
function getTempLocal(t: ILeaf, world: IPointData): IPointData {
|
|
133
|
-
t.__layout.
|
|
173
|
+
t.__layout.update()
|
|
134
174
|
return t.parent ? PointHelper.tempToInnerOf(world, t.parent.__world) : world
|
|
135
175
|
}
|
package/types/index.d.ts
CHANGED
|
@@ -1,41 +1,44 @@
|
|
|
1
|
-
import { ILeaf, IPointData,
|
|
1
|
+
import { ILeaf, IPointData, IMatrixData, IBoundsData, ILeafList, ILeafLevelList, IFunction } from '@leafer/interface';
|
|
2
2
|
|
|
3
3
|
declare const LeafHelper: {
|
|
4
|
-
|
|
4
|
+
updateAllMatrix(leaf: ILeaf, checkAutoLayout?: boolean, waitAutoLayout?: boolean): void;
|
|
5
|
+
updateMatrix(leaf: ILeaf, checkAutoLayout?: boolean, waitAutoLayout?: boolean): void;
|
|
6
|
+
updateBounds(leaf: ILeaf): void;
|
|
5
7
|
updateAllWorldOpacity(leaf: ILeaf): void;
|
|
6
8
|
updateAllChange(leaf: ILeaf): void;
|
|
7
9
|
worldHittable(t: ILeaf): boolean;
|
|
8
10
|
moveWorld(t: ILeaf, x: number, y: number): void;
|
|
9
11
|
moveLocal(t: ILeaf, x: number, y?: number): void;
|
|
10
|
-
zoomOfWorld(t: ILeaf, origin: IPointData, scaleX: number, scaleY?: number): void;
|
|
11
|
-
zoomOfLocal(t: ILeaf, origin: IPointData, scaleX: number, scaleY?: number): void;
|
|
12
|
+
zoomOfWorld(t: ILeaf, origin: IPointData, scaleX: number, scaleY?: number, resize?: boolean): void;
|
|
13
|
+
zoomOfLocal(t: ILeaf, origin: IPointData, scaleX: number, scaleY?: number, resize?: boolean): void;
|
|
12
14
|
rotateOfWorld(t: ILeaf, origin: IPointData, angle: number): void;
|
|
13
15
|
rotateOfLocal(t: ILeaf, origin: IPointData, angle: number): void;
|
|
14
|
-
skewOfWorld(t: ILeaf, origin: IPointData, skewX: number, skewY?: number): void;
|
|
15
|
-
skewOfLocal(t: ILeaf, origin: IPointData, skewX: number, skewY
|
|
16
|
-
|
|
17
|
-
|
|
16
|
+
skewOfWorld(t: ILeaf, origin: IPointData, skewX: number, skewY?: number, resize?: boolean): void;
|
|
17
|
+
skewOfLocal(t: ILeaf, origin: IPointData, skewX: number, skewY?: number, resize?: boolean): void;
|
|
18
|
+
transform(t: ILeaf, transform: IMatrixData, resize?: boolean): void;
|
|
19
|
+
setTransform(t: ILeaf, transform: IMatrixData, resize?: boolean): void;
|
|
20
|
+
drop(t: ILeaf, parent: ILeaf, index?: number, resize?: boolean): void;
|
|
21
|
+
hasParent(p: ILeaf, parent: ILeaf): boolean | void;
|
|
22
|
+
hasParentAutoLayout(p: ILeaf): boolean | void;
|
|
18
23
|
};
|
|
19
24
|
|
|
20
25
|
declare const LeafBoundsHelper: {
|
|
21
26
|
worldBounds(target: ILeaf): IBoundsData;
|
|
22
27
|
localBoxBounds(target: ILeaf): IBoundsData;
|
|
23
|
-
|
|
28
|
+
localStrokeBounds(target: ILeaf): IBoundsData;
|
|
24
29
|
localRenderBounds(target: ILeaf): IBoundsData;
|
|
25
30
|
maskLocalBoxBounds(target: ILeaf): IBoundsData;
|
|
26
|
-
|
|
31
|
+
maskLocalStrokeBounds(target: ILeaf): IBoundsData;
|
|
27
32
|
maskLocalRenderBounds(target: ILeaf): IBoundsData;
|
|
28
33
|
};
|
|
29
34
|
|
|
30
|
-
interface ILeafPushList {
|
|
31
|
-
push(item: ILeaf): void;
|
|
32
|
-
}
|
|
33
35
|
declare const BranchHelper: {
|
|
34
36
|
sort(a: ILeaf, b: ILeaf): number;
|
|
35
|
-
pushAllChildBranch(branch: ILeaf,
|
|
36
|
-
pushAllParent(leaf: ILeaf,
|
|
37
|
+
pushAllChildBranch(branch: ILeaf, leafList: ILeafList | ILeafLevelList): void;
|
|
38
|
+
pushAllParent(leaf: ILeaf, leafList: ILeafList | ILeafLevelList): void;
|
|
37
39
|
pushAllBranchStack(branch: ILeaf, pushList: ILeaf[]): void;
|
|
38
|
-
|
|
40
|
+
updateBounds(branch: ILeaf, exclude?: ILeaf): void;
|
|
41
|
+
updateBoundsByBranchStack(branchStack: ILeaf[], exclude?: ILeaf): void;
|
|
39
42
|
};
|
|
40
43
|
|
|
41
44
|
declare const WaitHelper: {
|