@leafer/helper 1.0.0-rc.4 → 1.0.0-rc.6
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/LeafHelper.ts +36 -32
- package/types/index.d.ts +7 -6
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.6",
|
|
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.6"
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|
|
28
|
-
"@leafer/interface": "1.0.0-rc.
|
|
28
|
+
"@leafer/interface": "1.0.0-rc.6"
|
|
29
29
|
}
|
|
30
30
|
}
|
package/src/LeafHelper.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { IBranch, ILeaf, IMatrixData, IPointData } from '@leafer/interface'
|
|
|
2
2
|
import { MathHelper, MatrixHelper, PointHelper } from '@leafer/math'
|
|
3
3
|
|
|
4
4
|
|
|
5
|
-
const { copy,
|
|
5
|
+
const { copy, toInnerPoint, scaleOfOuter, rotateOfOuter, skewOfOuter } = MatrixHelper
|
|
6
6
|
const matrix = {} as IMatrixData
|
|
7
7
|
|
|
8
8
|
export const LeafHelper = {
|
|
@@ -56,9 +56,8 @@ export const LeafHelper = {
|
|
|
56
56
|
// transform
|
|
57
57
|
|
|
58
58
|
moveWorld(t: ILeaf, x: number, y: number): void {
|
|
59
|
-
t.__layout.checkUpdate()
|
|
60
59
|
const local = { x, y }
|
|
61
|
-
if (t.parent) toInnerPoint(t.parent.
|
|
60
|
+
if (t.parent) toInnerPoint(t.parent.worldTransform, local, local, true)
|
|
62
61
|
L.moveLocal(t, local.x, local.y)
|
|
63
62
|
},
|
|
64
63
|
|
|
@@ -67,53 +66,37 @@ export const LeafHelper = {
|
|
|
67
66
|
t.y += y
|
|
68
67
|
},
|
|
69
68
|
|
|
70
|
-
zoomOfWorld(t: ILeaf, origin: IPointData, scaleX: number, scaleY?: number
|
|
71
|
-
|
|
72
|
-
const local = t.parent ? PointHelper.tempToInnerOf(origin, t.parent.__world) : origin
|
|
73
|
-
this.zoomOfLocal(t, local, scaleX, scaleY, moveLayer)
|
|
69
|
+
zoomOfWorld(t: ILeaf, origin: IPointData, scaleX: number, scaleY?: number): void {
|
|
70
|
+
this.zoomOfLocal(t, getTempLocal(t, origin), scaleX, scaleY)
|
|
74
71
|
},
|
|
75
72
|
|
|
76
|
-
zoomOfLocal(t: ILeaf, origin: IPointData, scaleX: number, scaleY: number = scaleX
|
|
73
|
+
zoomOfLocal(t: ILeaf, origin: IPointData, scaleX: number, scaleY: number = scaleX): void {
|
|
77
74
|
copy(matrix, t.__local)
|
|
78
|
-
if (moveLayer) translate(matrix, moveLayer.x, moveLayer.y)
|
|
79
75
|
scaleOfOuter(matrix, origin, scaleX, scaleY)
|
|
80
|
-
|
|
81
|
-
moveLayer.x += matrix.e - t.__local.e
|
|
82
|
-
moveLayer.y += matrix.f - t.__local.f
|
|
76
|
+
moveByMatrix(t, matrix)
|
|
83
77
|
t.scaleX *= scaleX
|
|
84
78
|
t.scaleY *= scaleY
|
|
85
79
|
},
|
|
86
80
|
|
|
87
|
-
rotateOfWorld(t: ILeaf, origin: IPointData, angle: number
|
|
88
|
-
|
|
89
|
-
const local = t.parent ? PointHelper.tempToInnerOf(origin, t.parent.__world) : origin
|
|
90
|
-
this.rotateOfLocal(t, local, angle, moveLayer)
|
|
81
|
+
rotateOfWorld(t: ILeaf, origin: IPointData, angle: number): void {
|
|
82
|
+
this.rotateOfLocal(t, getTempLocal(t, origin), angle)
|
|
91
83
|
},
|
|
92
84
|
|
|
93
|
-
rotateOfLocal(t: ILeaf, origin: IPointData, angle: number
|
|
85
|
+
rotateOfLocal(t: ILeaf, origin: IPointData, angle: number): void {
|
|
94
86
|
copy(matrix, t.__local)
|
|
95
|
-
if (moveLayer) translate(matrix, moveLayer.x, moveLayer.y)
|
|
96
87
|
rotateOfOuter(matrix, origin, angle)
|
|
97
|
-
|
|
98
|
-
moveLayer.x += matrix.e - t.__local.e
|
|
99
|
-
moveLayer.y += matrix.f - t.__local.f
|
|
88
|
+
moveByMatrix(t, matrix)
|
|
100
89
|
t.rotation = MathHelper.formatRotation(t.rotation + angle)
|
|
101
|
-
|
|
102
90
|
},
|
|
103
91
|
|
|
104
|
-
skewOfWorld(t: ILeaf, origin: IPointData, skewX: number, skewY?: number
|
|
105
|
-
|
|
106
|
-
const local = t.parent ? PointHelper.tempToInnerOf(origin, t.parent.__world) : origin
|
|
107
|
-
this.skewOfLocal(t, local, skewX, skewY, moveLayer)
|
|
92
|
+
skewOfWorld(t: ILeaf, origin: IPointData, skewX: number, skewY?: number): void {
|
|
93
|
+
this.skewOfLocal(t, getTempLocal(t, origin), skewX, skewY)
|
|
108
94
|
},
|
|
109
95
|
|
|
110
|
-
skewOfLocal(t: ILeaf, origin: IPointData, skewX: number, skewY: number
|
|
96
|
+
skewOfLocal(t: ILeaf, origin: IPointData, skewX: number, skewY: number): void {
|
|
111
97
|
copy(matrix, t.__local)
|
|
112
|
-
if (moveLayer) translate(matrix, moveLayer.x, moveLayer.y)
|
|
113
98
|
skewOfOuter(matrix, origin, skewX, skewY)
|
|
114
|
-
|
|
115
|
-
moveLayer.x = matrix.e - t.__local.e
|
|
116
|
-
moveLayer.y = matrix.f - t.__local.f
|
|
99
|
+
moveByMatrix(t, matrix)
|
|
117
100
|
t.skewX = MathHelper.formatSkew(t.skewX + skewX)
|
|
118
101
|
t.skewY = MathHelper.formatSkew(t.skewY + skewY)
|
|
119
102
|
},
|
|
@@ -124,8 +107,29 @@ export const LeafHelper = {
|
|
|
124
107
|
parent.worldToInner(position)
|
|
125
108
|
t.set(position)
|
|
126
109
|
parent.add(t)
|
|
110
|
+
},
|
|
111
|
+
|
|
112
|
+
hasParent(t: ILeaf, parent: ILeaf): boolean {
|
|
113
|
+
if (!parent) return false
|
|
114
|
+
let p = t
|
|
115
|
+
while (p) {
|
|
116
|
+
if (parent === p) return true
|
|
117
|
+
p = p.parent
|
|
118
|
+
}
|
|
119
|
+
return false
|
|
127
120
|
}
|
|
128
121
|
|
|
129
122
|
}
|
|
123
|
+
|
|
130
124
|
const L = LeafHelper
|
|
131
|
-
const { updateAllWorldMatrix, updateAllWorldOpacity, updateAllChange } = L
|
|
125
|
+
const { updateAllWorldMatrix, updateAllWorldOpacity, updateAllChange } = L
|
|
126
|
+
|
|
127
|
+
function moveByMatrix(t: ILeaf, matrix: IMatrixData): void {
|
|
128
|
+
t.x += matrix.e - t.__local.e
|
|
129
|
+
t.y += matrix.f - t.__local.f
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
function getTempLocal(t: ILeaf, world: IPointData): IPointData {
|
|
133
|
+
t.__layout.checkUpdate()
|
|
134
|
+
return t.parent ? PointHelper.tempToInnerOf(world, t.parent.__world) : world
|
|
135
|
+
}
|
package/types/index.d.ts
CHANGED
|
@@ -7,13 +7,14 @@ declare const LeafHelper: {
|
|
|
7
7
|
worldHittable(t: ILeaf): boolean;
|
|
8
8
|
moveWorld(t: ILeaf, x: number, y: number): void;
|
|
9
9
|
moveLocal(t: ILeaf, x: number, y?: number): void;
|
|
10
|
-
zoomOfWorld(t: ILeaf, origin: IPointData, scaleX: number, scaleY?: number
|
|
11
|
-
zoomOfLocal(t: ILeaf, origin: IPointData, scaleX: number, scaleY?: number
|
|
12
|
-
rotateOfWorld(t: ILeaf, origin: IPointData, angle: number
|
|
13
|
-
rotateOfLocal(t: ILeaf, origin: IPointData, angle: number
|
|
14
|
-
skewOfWorld(t: ILeaf, origin: IPointData, skewX: number, skewY?: number
|
|
15
|
-
skewOfLocal(t: ILeaf, origin: IPointData, skewX: number, skewY: number
|
|
10
|
+
zoomOfWorld(t: ILeaf, origin: IPointData, scaleX: number, scaleY?: number): void;
|
|
11
|
+
zoomOfLocal(t: ILeaf, origin: IPointData, scaleX: number, scaleY?: number): void;
|
|
12
|
+
rotateOfWorld(t: ILeaf, origin: IPointData, angle: number): void;
|
|
13
|
+
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: number): void;
|
|
16
16
|
drop(t: ILeaf, parent: IBranch): void;
|
|
17
|
+
hasParent(t: ILeaf, parent: ILeaf): boolean;
|
|
17
18
|
};
|
|
18
19
|
|
|
19
20
|
declare const LeafBoundsHelper: {
|