@leafer/helper 1.0.0-beta.9 → 1.0.0-rc.2
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 +7 -4
- package/src/LeafHelper.ts +43 -18
- package/types/index.d.ts +44 -0
package/package.json
CHANGED
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@leafer/helper",
|
|
3
|
-
"version": "1.0.0-
|
|
3
|
+
"version": "1.0.0-rc.2",
|
|
4
4
|
"description": "@leafer/helper",
|
|
5
5
|
"author": "Chao (Leafer) Wan",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"main": "src/index.ts",
|
|
8
|
+
"types": "types/index.d.ts",
|
|
8
9
|
"files": [
|
|
9
|
-
"src"
|
|
10
|
+
"src",
|
|
11
|
+
"types",
|
|
12
|
+
"dist"
|
|
10
13
|
],
|
|
11
14
|
"repository": {
|
|
12
15
|
"type": "git",
|
|
@@ -19,9 +22,9 @@
|
|
|
19
22
|
"leaferjs"
|
|
20
23
|
],
|
|
21
24
|
"dependencies": {
|
|
22
|
-
"@leafer/math": "1.0.0-
|
|
25
|
+
"@leafer/math": "1.0.0-rc.2"
|
|
23
26
|
},
|
|
24
27
|
"devDependencies": {
|
|
25
|
-
"@leafer/interface": "1.0.0-
|
|
28
|
+
"@leafer/interface": "1.0.0-rc.2"
|
|
26
29
|
}
|
|
27
30
|
}
|
package/src/LeafHelper.ts
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
|
-
import { IBranch, ILeaf, IPointData } from '@leafer/interface'
|
|
2
|
-
import {
|
|
1
|
+
import { IBranch, ILeaf, IMatrixData, IPointData } from '@leafer/interface'
|
|
2
|
+
import { MathHelper, MatrixHelper, PointHelper } from '@leafer/math'
|
|
3
3
|
|
|
4
4
|
|
|
5
|
+
const { copy, translate, toInnerPoint, scaleOfOuter, rotateOfOuter, skewOfOuter } = MatrixHelper
|
|
6
|
+
const matrix = {} as IMatrixData
|
|
7
|
+
|
|
5
8
|
export const LeafHelper = {
|
|
6
9
|
|
|
7
10
|
updateAllWorldMatrix(leaf: ILeaf): void {
|
|
@@ -53,44 +56,66 @@ export const LeafHelper = {
|
|
|
53
56
|
// transform
|
|
54
57
|
|
|
55
58
|
moveWorld(t: ILeaf, x: number, y: number): void {
|
|
59
|
+
t.__layout.checkUpdate()
|
|
56
60
|
const local = { x, y }
|
|
57
|
-
if (t.parent)
|
|
61
|
+
if (t.parent) toInnerPoint(t.parent.__world, local, local, true)
|
|
58
62
|
L.moveLocal(t, local.x, local.y)
|
|
59
63
|
},
|
|
60
64
|
|
|
61
65
|
moveLocal(t: ILeaf, x: number, y: number = 0): void {
|
|
62
|
-
t.x
|
|
63
|
-
t.y
|
|
66
|
+
t.x += x
|
|
67
|
+
t.y += y
|
|
64
68
|
},
|
|
65
69
|
|
|
66
70
|
zoomOfWorld(t: ILeaf, origin: IPointData, scaleX: number, scaleY?: number, moveLayer?: ILeaf): void {
|
|
71
|
+
t.__layout.checkUpdate()
|
|
67
72
|
const local = t.parent ? PointHelper.tempToInnerOf(origin, t.parent.__world) : origin
|
|
68
73
|
this.zoomOfLocal(t, local, scaleX, scaleY, moveLayer)
|
|
69
74
|
},
|
|
70
75
|
|
|
71
|
-
zoomOfLocal(t: ILeaf, origin: IPointData, scaleX: number, scaleY
|
|
72
|
-
|
|
76
|
+
zoomOfLocal(t: ILeaf, origin: IPointData, scaleX: number, scaleY: number = scaleX, moveLayer?: ILeaf): void {
|
|
77
|
+
copy(matrix, t.__local)
|
|
78
|
+
if (moveLayer) translate(matrix, moveLayer.x, moveLayer.y)
|
|
79
|
+
scaleOfOuter(matrix, origin, scaleX, scaleY)
|
|
73
80
|
if (!moveLayer) moveLayer = t
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
t.scaleX = t.__.scaleX * scaleX
|
|
79
|
-
t.scaleY = t.__.scaleY * scaleY
|
|
81
|
+
moveLayer.x += matrix.e - t.__local.e
|
|
82
|
+
moveLayer.y += matrix.f - t.__local.f
|
|
83
|
+
t.scaleX *= scaleX
|
|
84
|
+
t.scaleY *= scaleY
|
|
80
85
|
},
|
|
81
86
|
|
|
82
87
|
rotateOfWorld(t: ILeaf, origin: IPointData, angle: number, moveLayer?: ILeaf): void {
|
|
88
|
+
t.__layout.checkUpdate()
|
|
83
89
|
const local = t.parent ? PointHelper.tempToInnerOf(origin, t.parent.__world) : origin
|
|
84
90
|
this.rotateOfLocal(t, local, angle, moveLayer)
|
|
85
91
|
},
|
|
86
92
|
|
|
87
93
|
rotateOfLocal(t: ILeaf, origin: IPointData, angle: number, moveLayer?: ILeaf): void {
|
|
94
|
+
copy(matrix, t.__local)
|
|
95
|
+
if (moveLayer) translate(matrix, moveLayer.x, moveLayer.y)
|
|
96
|
+
rotateOfOuter(matrix, origin, angle)
|
|
97
|
+
if (!moveLayer) moveLayer = t
|
|
98
|
+
moveLayer.x += matrix.e - t.__local.e
|
|
99
|
+
moveLayer.y += matrix.f - t.__local.f
|
|
100
|
+
t.rotation = MathHelper.formatRotation(t.rotation + angle)
|
|
101
|
+
|
|
102
|
+
},
|
|
103
|
+
|
|
104
|
+
skewOfWorld(t: ILeaf, origin: IPointData, skewX: number, skewY?: number, moveLayer?: ILeaf): void {
|
|
105
|
+
t.__layout.checkUpdate()
|
|
106
|
+
const local = t.parent ? PointHelper.tempToInnerOf(origin, t.parent.__world) : origin
|
|
107
|
+
this.skewOfLocal(t, local, skewX, skewY, moveLayer)
|
|
108
|
+
},
|
|
109
|
+
|
|
110
|
+
skewOfLocal(t: ILeaf, origin: IPointData, skewX: number, skewY: number, moveLayer?: ILeaf): void {
|
|
111
|
+
copy(matrix, t.__local)
|
|
112
|
+
if (moveLayer) translate(matrix, moveLayer.x, moveLayer.y)
|
|
113
|
+
skewOfOuter(matrix, origin, skewX, skewY)
|
|
88
114
|
if (!moveLayer) moveLayer = t
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
t.rotation = t.__.rotation + angle
|
|
115
|
+
moveLayer.x = matrix.e - t.__local.e
|
|
116
|
+
moveLayer.y = matrix.f - t.__local.f
|
|
117
|
+
t.skewX = MathHelper.formatSkew(t.skewX + skewX)
|
|
118
|
+
t.skewY = MathHelper.formatSkew(t.skewY + skewY)
|
|
94
119
|
},
|
|
95
120
|
|
|
96
121
|
drop(t: ILeaf, parent: IBranch): void {
|
package/types/index.d.ts
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { ILeaf, IPointData, IBranch, IBoundsData, IFunction } from '@leafer/interface';
|
|
2
|
+
|
|
3
|
+
declare const LeafHelper: {
|
|
4
|
+
updateAllWorldMatrix(leaf: ILeaf): void;
|
|
5
|
+
updateAllWorldOpacity(leaf: ILeaf): void;
|
|
6
|
+
updateAllChange(leaf: ILeaf): void;
|
|
7
|
+
worldHittable(t: ILeaf): boolean;
|
|
8
|
+
moveWorld(t: ILeaf, x: number, y: number): void;
|
|
9
|
+
moveLocal(t: ILeaf, x: number, y?: number): void;
|
|
10
|
+
zoomOfWorld(t: ILeaf, origin: IPointData, scaleX: number, scaleY?: number, moveLayer?: ILeaf): void;
|
|
11
|
+
zoomOfLocal(t: ILeaf, origin: IPointData, scaleX: number, scaleY?: number, moveLayer?: ILeaf): void;
|
|
12
|
+
rotateOfWorld(t: ILeaf, origin: IPointData, angle: number, moveLayer?: ILeaf): void;
|
|
13
|
+
rotateOfLocal(t: ILeaf, origin: IPointData, angle: number, moveLayer?: ILeaf): void;
|
|
14
|
+
skewOfWorld(t: ILeaf, origin: IPointData, skewX: number, skewY?: number, moveLayer?: ILeaf): void;
|
|
15
|
+
skewOfLocal(t: ILeaf, origin: IPointData, skewX: number, skewY: number, moveLayer?: ILeaf): void;
|
|
16
|
+
drop(t: ILeaf, parent: IBranch): void;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
declare const LeafBoundsHelper: {
|
|
20
|
+
worldBounds(target: ILeaf): IBoundsData;
|
|
21
|
+
localBoxBounds(target: ILeaf): IBoundsData;
|
|
22
|
+
localEventBounds(target: ILeaf): IBoundsData;
|
|
23
|
+
localRenderBounds(target: ILeaf): IBoundsData;
|
|
24
|
+
maskLocalBoxBounds(target: ILeaf): IBoundsData;
|
|
25
|
+
maskLocalEventBounds(target: ILeaf): IBoundsData;
|
|
26
|
+
maskLocalRenderBounds(target: ILeaf): IBoundsData;
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
interface ILeafPushList {
|
|
30
|
+
push(item: ILeaf): void;
|
|
31
|
+
}
|
|
32
|
+
declare const BranchHelper: {
|
|
33
|
+
sort(a: ILeaf, b: ILeaf): number;
|
|
34
|
+
pushAllChildBranch(branch: ILeaf, pushList: ILeafPushList): void;
|
|
35
|
+
pushAllParent(leaf: ILeaf, pushList: ILeafPushList): void;
|
|
36
|
+
pushAllBranchStack(branch: ILeaf, pushList: ILeaf[]): void;
|
|
37
|
+
updateWorldBoundsByBranchStack(branchStack: ILeaf[]): void;
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
declare const WaitHelper: {
|
|
41
|
+
run(wait: IFunction[]): void;
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
export { BranchHelper, LeafBoundsHelper, LeafHelper, WaitHelper };
|