@leafer/helper 1.3.3 → 1.4.1
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 +33 -36
- package/types/index.d.ts +12 -12
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@leafer/helper",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.4.1",
|
|
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.
|
|
25
|
+
"@leafer/math": "1.4.1"
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|
|
28
|
-
"@leafer/interface": "1.
|
|
28
|
+
"@leafer/interface": "1.4.1"
|
|
29
29
|
}
|
|
30
30
|
}
|
package/src/LeafHelper.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { IAlign, ILeaf, IMatrixData, IPointData, IAxis } from '@leafer/interface'
|
|
1
|
+
import { IAlign, ILeaf, IMatrixData, IPointData, IAxis, ITransition } from '@leafer/interface'
|
|
2
2
|
import { MathHelper, MatrixHelper, PointHelper, AroundHelper, getMatrixData, BoundsHelper } from '@leafer/math'
|
|
3
3
|
|
|
4
4
|
|
|
@@ -76,73 +76,76 @@ export const LeafHelper = {
|
|
|
76
76
|
|
|
77
77
|
// transform
|
|
78
78
|
|
|
79
|
-
moveWorld(t: ILeaf, x: number | IPointData, y = 0, isInnerPoint?: boolean, transition?:
|
|
79
|
+
moveWorld(t: ILeaf, x: number | IPointData, y = 0, isInnerPoint?: boolean, transition?: ITransition): void {
|
|
80
80
|
const local = typeof x === 'object' ? { ...x } : { x, y }
|
|
81
81
|
isInnerPoint ? toOuterPoint(t.localTransform, local, local, true) : (t.parent && toInnerPoint(t.parent.worldTransform, local, local, true))
|
|
82
82
|
L.moveLocal(t, local.x, local.y, transition)
|
|
83
83
|
},
|
|
84
84
|
|
|
85
|
-
moveLocal(t: ILeaf, x: number | IPointData, y = 0, transition?:
|
|
85
|
+
moveLocal(t: ILeaf, x: number | IPointData, y = 0, transition?: ITransition): void {
|
|
86
86
|
if (typeof x === 'object') y = x.y, x = x.x
|
|
87
87
|
x += t.x
|
|
88
88
|
y += t.y
|
|
89
89
|
transition ? t.animate({ x, y }, transition) : (t.x = x, t.y = y)
|
|
90
90
|
},
|
|
91
91
|
|
|
92
|
-
zoomOfWorld(t: ILeaf, origin: IPointData, scaleX: number, scaleY?: number, resize?: boolean): void {
|
|
93
|
-
L.zoomOfLocal(t, getTempLocal(t, origin), scaleX, scaleY, resize)
|
|
92
|
+
zoomOfWorld(t: ILeaf, origin: IPointData, scaleX: number, scaleY?: number | ITransition, resize?: boolean, transition?: ITransition): void {
|
|
93
|
+
L.zoomOfLocal(t, getTempLocal(t, origin), scaleX, scaleY, resize, transition)
|
|
94
94
|
},
|
|
95
95
|
|
|
96
|
-
zoomOfLocal(t: ILeaf, origin: IPointData, scaleX: number, scaleY: number = scaleX, resize?: boolean): void {
|
|
97
|
-
|
|
96
|
+
zoomOfLocal(t: ILeaf, origin: IPointData, scaleX: number, scaleY: number | ITransition = scaleX, resize?: boolean, transition?: ITransition): void {
|
|
97
|
+
const o = t.__localMatrix
|
|
98
|
+
if (typeof scaleY !== 'number') {
|
|
99
|
+
if (scaleY) transition = scaleY
|
|
100
|
+
scaleY = scaleX
|
|
101
|
+
}
|
|
102
|
+
copy(matrix, o)
|
|
98
103
|
scaleOfOuter(matrix, origin, scaleX, scaleY)
|
|
99
104
|
if (t.origin || t.around) {
|
|
100
|
-
L.setTransform(t, matrix, resize)
|
|
105
|
+
L.setTransform(t, matrix, resize, transition)
|
|
101
106
|
} else {
|
|
102
|
-
|
|
103
|
-
t.
|
|
107
|
+
const x = t.x + matrix.e - o.e, y = t.y + matrix.f - o.f
|
|
108
|
+
if (transition && !resize) t.animate({ x, y, scaleX: t.scaleX * scaleX, scaleY: t.scaleY * scaleY }, transition)
|
|
109
|
+
else t.x = x, t.y = y, t.scaleResize(scaleX, scaleY, resize !== true)
|
|
104
110
|
}
|
|
105
111
|
},
|
|
106
112
|
|
|
107
|
-
rotateOfWorld(t: ILeaf, origin: IPointData, angle: number): void {
|
|
108
|
-
L.rotateOfLocal(t, getTempLocal(t, origin), angle)
|
|
113
|
+
rotateOfWorld(t: ILeaf, origin: IPointData, angle: number, transition?: ITransition): void {
|
|
114
|
+
L.rotateOfLocal(t, getTempLocal(t, origin), angle, transition)
|
|
109
115
|
},
|
|
110
116
|
|
|
111
|
-
rotateOfLocal(t: ILeaf, origin: IPointData, angle: number): void {
|
|
112
|
-
|
|
117
|
+
rotateOfLocal(t: ILeaf, origin: IPointData, angle: number, transition?: ITransition): void {
|
|
118
|
+
const o = t.__localMatrix
|
|
119
|
+
copy(matrix, o)
|
|
113
120
|
rotateOfOuter(matrix, origin, angle)
|
|
114
|
-
if (t.origin || t.around)
|
|
115
|
-
|
|
116
|
-
} else {
|
|
117
|
-
moveByMatrix(t, matrix)
|
|
118
|
-
t.rotation = MathHelper.formatRotation(t.rotation + angle)
|
|
119
|
-
}
|
|
121
|
+
if (t.origin || t.around) L.setTransform(t, matrix, false, transition)
|
|
122
|
+
else t.set({ x: t.x + matrix.e - o.e, y: t.y + matrix.f - o.f, rotation: MathHelper.formatRotation(t.rotation + angle) }, transition)
|
|
120
123
|
},
|
|
121
124
|
|
|
122
|
-
skewOfWorld(t: ILeaf, origin: IPointData, skewX: number, skewY?: number, resize?: boolean): void {
|
|
123
|
-
L.skewOfLocal(t, getTempLocal(t, origin), skewX, skewY, resize)
|
|
125
|
+
skewOfWorld(t: ILeaf, origin: IPointData, skewX: number, skewY?: number, resize?: boolean, transition?: ITransition): void {
|
|
126
|
+
L.skewOfLocal(t, getTempLocal(t, origin), skewX, skewY, resize, transition)
|
|
124
127
|
},
|
|
125
128
|
|
|
126
|
-
skewOfLocal(t: ILeaf, origin: IPointData, skewX: number, skewY: number = 0, resize?: boolean): void {
|
|
129
|
+
skewOfLocal(t: ILeaf, origin: IPointData, skewX: number, skewY: number = 0, resize?: boolean, transition?: ITransition): void {
|
|
127
130
|
copy(matrix, t.__localMatrix)
|
|
128
131
|
skewOfOuter(matrix, origin, skewX, skewY)
|
|
129
|
-
L.setTransform(t, matrix, resize)
|
|
132
|
+
L.setTransform(t, matrix, resize, transition)
|
|
130
133
|
},
|
|
131
134
|
|
|
132
|
-
transformWorld(t: ILeaf, transform: IMatrixData, resize?: boolean): void {
|
|
135
|
+
transformWorld(t: ILeaf, transform: IMatrixData, resize?: boolean, transition?: ITransition): void {
|
|
133
136
|
copy(matrix, t.worldTransform)
|
|
134
137
|
multiplyParent(matrix, transform)
|
|
135
138
|
if (t.parent) divideParent(matrix, t.parent.worldTransform)
|
|
136
|
-
L.setTransform(t, matrix, resize)
|
|
139
|
+
L.setTransform(t, matrix, resize, transition)
|
|
137
140
|
},
|
|
138
141
|
|
|
139
|
-
transform(t: ILeaf, transform: IMatrixData, resize?: boolean): void {
|
|
142
|
+
transform(t: ILeaf, transform: IMatrixData, resize?: boolean, transition?: ITransition): void {
|
|
140
143
|
copy(matrix, t.localTransform)
|
|
141
144
|
multiplyParent(matrix, transform)
|
|
142
|
-
L.setTransform(t, matrix, resize)
|
|
145
|
+
L.setTransform(t, matrix, resize, transition)
|
|
143
146
|
},
|
|
144
147
|
|
|
145
|
-
setTransform(t: ILeaf, transform: IMatrixData, resize?: boolean): void {
|
|
148
|
+
setTransform(t: ILeaf, transform: IMatrixData, resize?: boolean, transition?: ITransition): void {
|
|
146
149
|
const data = t.__, originPoint = data.origin && L.getInnerOrigin(t, data.origin)
|
|
147
150
|
const layout = getLayout(transform, originPoint, data.around && L.getInnerOrigin(t, data.around))
|
|
148
151
|
if (resize) {
|
|
@@ -158,7 +161,7 @@ export const LeafHelper = {
|
|
|
158
161
|
t.set(layout)
|
|
159
162
|
t.scaleResize(scaleX, scaleY, false)
|
|
160
163
|
|
|
161
|
-
} else t.set(layout)
|
|
164
|
+
} else t.set(layout, transition)
|
|
162
165
|
},
|
|
163
166
|
|
|
164
167
|
getFlipTransform(t: ILeaf, axis: IAxis): IMatrixData {
|
|
@@ -202,12 +205,6 @@ export const LeafHelper = {
|
|
|
202
205
|
const L = LeafHelper
|
|
203
206
|
const { updateAllMatrix, updateMatrix, updateAllWorldOpacity, updateAllChange } = L
|
|
204
207
|
|
|
205
|
-
function moveByMatrix(t: ILeaf, matrix: IMatrixData): void {
|
|
206
|
-
const { e, f } = t.__localMatrix
|
|
207
|
-
t.x += matrix.e - e
|
|
208
|
-
t.y += matrix.f - f
|
|
209
|
-
}
|
|
210
|
-
|
|
211
208
|
function getTempLocal(t: ILeaf, world: IPointData): IPointData {
|
|
212
209
|
t.__layout.update()
|
|
213
210
|
return t.parent ? PointHelper.tempToInnerOf(world, t.parent.__world) : world
|
package/types/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ILeaf, IPointData, IMatrixData, IAxis, IAlign, IBoundsData, IRenderOptions, ILeafList, ILeafLevelList, IFunction } from '@leafer/interface';
|
|
1
|
+
import { ILeaf, IPointData, ITransition, IMatrixData, IAxis, IAlign, IBoundsData, IRenderOptions, ILeafList, ILeafLevelList, IFunction } from '@leafer/interface';
|
|
2
2
|
|
|
3
3
|
declare const LeafHelper: {
|
|
4
4
|
updateAllMatrix(leaf: ILeaf, checkAutoLayout?: boolean, waitAutoLayout?: boolean): void;
|
|
@@ -7,17 +7,17 @@ declare const LeafHelper: {
|
|
|
7
7
|
updateAllWorldOpacity(leaf: ILeaf): void;
|
|
8
8
|
updateAllChange(leaf: ILeaf): void;
|
|
9
9
|
worldHittable(t: ILeaf): boolean;
|
|
10
|
-
moveWorld(t: ILeaf, x: number | IPointData, y?: number, isInnerPoint?: boolean, transition?:
|
|
11
|
-
moveLocal(t: ILeaf, x: number | IPointData, y?: number, transition?:
|
|
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;
|
|
14
|
-
rotateOfWorld(t: ILeaf, origin: IPointData, angle: number): void;
|
|
15
|
-
rotateOfLocal(t: ILeaf, origin: IPointData, angle: number): void;
|
|
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
|
-
transformWorld(t: ILeaf, transform: IMatrixData, resize?: boolean): void;
|
|
19
|
-
transform(t: ILeaf, transform: IMatrixData, resize?: boolean): void;
|
|
20
|
-
setTransform(t: ILeaf, transform: IMatrixData, resize?: boolean): void;
|
|
10
|
+
moveWorld(t: ILeaf, x: number | IPointData, y?: number, isInnerPoint?: boolean, transition?: ITransition): void;
|
|
11
|
+
moveLocal(t: ILeaf, x: number | IPointData, y?: number, transition?: ITransition): void;
|
|
12
|
+
zoomOfWorld(t: ILeaf, origin: IPointData, scaleX: number, scaleY?: number | ITransition, resize?: boolean, transition?: ITransition): void;
|
|
13
|
+
zoomOfLocal(t: ILeaf, origin: IPointData, scaleX: number, scaleY?: number | ITransition, resize?: boolean, transition?: ITransition): void;
|
|
14
|
+
rotateOfWorld(t: ILeaf, origin: IPointData, angle: number, transition?: ITransition): void;
|
|
15
|
+
rotateOfLocal(t: ILeaf, origin: IPointData, angle: number, transition?: ITransition): void;
|
|
16
|
+
skewOfWorld(t: ILeaf, origin: IPointData, skewX: number, skewY?: number, resize?: boolean, transition?: ITransition): void;
|
|
17
|
+
skewOfLocal(t: ILeaf, origin: IPointData, skewX: number, skewY?: number, resize?: boolean, transition?: ITransition): void;
|
|
18
|
+
transformWorld(t: ILeaf, transform: IMatrixData, resize?: boolean, transition?: ITransition): void;
|
|
19
|
+
transform(t: ILeaf, transform: IMatrixData, resize?: boolean, transition?: ITransition): void;
|
|
20
|
+
setTransform(t: ILeaf, transform: IMatrixData, resize?: boolean, transition?: ITransition): void;
|
|
21
21
|
getFlipTransform(t: ILeaf, axis: IAxis): IMatrixData;
|
|
22
22
|
getLocalOrigin(t: ILeaf, origin: IPointData | IAlign): IPointData;
|
|
23
23
|
getInnerOrigin(t: ILeaf, origin: IPointData | IAlign): IPointData;
|