@leafer/helper 1.0.0-rc.9 → 1.0.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 +4 -4
- package/src/LeafBoundsHelper.ts +13 -7
- package/src/LeafHelper.ts +64 -27
- package/src/WaitHelper.ts +5 -2
- package/types/index.d.ts +9 -4
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@leafer/helper",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.1",
|
|
4
4
|
"description": "@leafer/helper",
|
|
5
5
|
"author": "Chao (Leafer) Wan",
|
|
6
6
|
"license": "MIT",
|
|
@@ -15,16 +15,16 @@
|
|
|
15
15
|
"type": "git",
|
|
16
16
|
"url": "https://github.com/leaferjs/leafer.git"
|
|
17
17
|
},
|
|
18
|
-
"homepage": "https://github.com/leaferjs/leafer/tree/main/packages/helper",
|
|
18
|
+
"homepage": "https://github.com/leaferjs/leafer/tree/main/packages/display-module/helper",
|
|
19
19
|
"bugs": "https://github.com/leaferjs/leafer/issues",
|
|
20
20
|
"keywords": [
|
|
21
21
|
"leafer",
|
|
22
22
|
"leaferjs"
|
|
23
23
|
],
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@leafer/math": "1.0.
|
|
25
|
+
"@leafer/math": "1.0.1"
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|
|
28
|
-
"@leafer/interface": "1.0.
|
|
28
|
+
"@leafer/interface": "1.0.1"
|
|
29
29
|
}
|
|
30
30
|
}
|
package/src/LeafBoundsHelper.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ILeaf, IBoundsData } from '@leafer/interface'
|
|
1
|
+
import { ILeaf, IBoundsData, IRenderOptions } from '@leafer/interface'
|
|
2
2
|
|
|
3
3
|
|
|
4
4
|
export const LeafBoundsHelper = {
|
|
@@ -8,27 +8,33 @@ export const LeafBoundsHelper = {
|
|
|
8
8
|
},
|
|
9
9
|
|
|
10
10
|
localBoxBounds(target: ILeaf): IBoundsData {
|
|
11
|
-
return target.__.
|
|
11
|
+
return target.__.eraser || target.__.visible === 0 ? null : (target.__local || target.__layout)
|
|
12
12
|
},
|
|
13
13
|
|
|
14
14
|
localStrokeBounds(target: ILeaf): IBoundsData {
|
|
15
|
-
return target.__.
|
|
15
|
+
return target.__.eraser || target.__.visible === 0 ? null : target.__layout.localStrokeBounds
|
|
16
16
|
},
|
|
17
17
|
|
|
18
18
|
localRenderBounds(target: ILeaf): IBoundsData {
|
|
19
|
-
return target.__.
|
|
19
|
+
return target.__.eraser || target.__.visible === 0 ? null : target.__layout.localRenderBounds
|
|
20
20
|
},
|
|
21
21
|
|
|
22
22
|
maskLocalBoxBounds(target: ILeaf): IBoundsData {
|
|
23
|
-
return target.__.
|
|
23
|
+
return target.__.mask ? target.__localBoxBounds : null
|
|
24
24
|
},
|
|
25
25
|
|
|
26
26
|
maskLocalStrokeBounds(target: ILeaf): IBoundsData {
|
|
27
|
-
return target.__.
|
|
27
|
+
return target.__.mask ? target.__layout.localStrokeBounds : null
|
|
28
28
|
},
|
|
29
29
|
|
|
30
30
|
maskLocalRenderBounds(target: ILeaf): IBoundsData {
|
|
31
|
-
return target.__.
|
|
31
|
+
return target.__.mask ? target.__layout.localRenderBounds : null
|
|
32
|
+
},
|
|
33
|
+
|
|
34
|
+
excludeRenderBounds(child: ILeaf, options: IRenderOptions): boolean {
|
|
35
|
+
if (options.bounds && !options.bounds.hit(child.__world, options.matrix)) return true
|
|
36
|
+
if (options.hideBounds && options.hideBounds.includes(child.__world, options.matrix)) return true
|
|
37
|
+
return false
|
|
32
38
|
}
|
|
33
39
|
|
|
34
40
|
}
|
package/src/LeafHelper.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { ILeaf, IMatrixData, IPointData } from '@leafer/interface'
|
|
2
|
-
import { MathHelper, MatrixHelper, PointHelper } from '@leafer/math'
|
|
1
|
+
import { IAlign, ILeaf, IMatrixData, IPointData, IAxis } from '@leafer/interface'
|
|
2
|
+
import { MathHelper, MatrixHelper, PointHelper, AroundHelper, getMatrixData } from '@leafer/math'
|
|
3
3
|
|
|
4
4
|
|
|
5
5
|
const { copy, toInnerPoint, scaleOfOuter, rotateOfOuter, skewOfOuter, multiplyParent, divideParent, getLayout } = MatrixHelper
|
|
@@ -76,41 +76,54 @@ export const LeafHelper = {
|
|
|
76
76
|
|
|
77
77
|
// transform
|
|
78
78
|
|
|
79
|
-
moveWorld(t: ILeaf, x: number, y
|
|
80
|
-
const local = { x, y }
|
|
79
|
+
moveWorld(t: ILeaf, x: number | IPointData, y = 0): void {
|
|
80
|
+
const local = typeof x === 'object' ? { ...x } : { x, y }
|
|
81
81
|
if (t.parent) toInnerPoint(t.parent.worldTransform, local, local, true)
|
|
82
82
|
L.moveLocal(t, local.x, local.y)
|
|
83
83
|
},
|
|
84
84
|
|
|
85
|
-
moveLocal(t: ILeaf, x: number, y
|
|
86
|
-
|
|
87
|
-
|
|
85
|
+
moveLocal(t: ILeaf, x: number | IPointData, y = 0): void {
|
|
86
|
+
if (typeof x === 'object') {
|
|
87
|
+
t.x += x.x
|
|
88
|
+
t.y += x.y
|
|
89
|
+
} else {
|
|
90
|
+
t.x += x
|
|
91
|
+
t.y += y
|
|
92
|
+
}
|
|
88
93
|
},
|
|
89
94
|
|
|
90
95
|
zoomOfWorld(t: ILeaf, origin: IPointData, scaleX: number, scaleY?: number, resize?: boolean): void {
|
|
91
|
-
|
|
96
|
+
L.zoomOfLocal(t, getTempLocal(t, origin), scaleX, scaleY, resize)
|
|
92
97
|
},
|
|
93
98
|
|
|
94
99
|
zoomOfLocal(t: ILeaf, origin: IPointData, scaleX: number, scaleY: number = scaleX, resize?: boolean): void {
|
|
95
100
|
copy(matrix, t.__localMatrix)
|
|
96
101
|
scaleOfOuter(matrix, origin, scaleX, scaleY)
|
|
97
|
-
|
|
98
|
-
|
|
102
|
+
if (t.origin || t.around) {
|
|
103
|
+
L.setTransform(t, matrix, resize)
|
|
104
|
+
} else {
|
|
105
|
+
moveByMatrix(t, matrix)
|
|
106
|
+
t.scaleResize(scaleX, scaleY, resize !== true)
|
|
107
|
+
}
|
|
99
108
|
},
|
|
100
109
|
|
|
101
110
|
rotateOfWorld(t: ILeaf, origin: IPointData, angle: number): void {
|
|
102
|
-
|
|
111
|
+
L.rotateOfLocal(t, getTempLocal(t, origin), angle)
|
|
103
112
|
},
|
|
104
113
|
|
|
105
114
|
rotateOfLocal(t: ILeaf, origin: IPointData, angle: number): void {
|
|
106
115
|
copy(matrix, t.__localMatrix)
|
|
107
116
|
rotateOfOuter(matrix, origin, angle)
|
|
108
|
-
|
|
109
|
-
|
|
117
|
+
if (t.origin || t.around) {
|
|
118
|
+
L.setTransform(t, matrix)
|
|
119
|
+
} else {
|
|
120
|
+
moveByMatrix(t, matrix)
|
|
121
|
+
t.rotation = MathHelper.formatRotation(t.rotation + angle)
|
|
122
|
+
}
|
|
110
123
|
},
|
|
111
124
|
|
|
112
125
|
skewOfWorld(t: ILeaf, origin: IPointData, skewX: number, skewY?: number, resize?: boolean): void {
|
|
113
|
-
|
|
126
|
+
L.skewOfLocal(t, getTempLocal(t, origin), skewX, skewY, resize)
|
|
114
127
|
},
|
|
115
128
|
|
|
116
129
|
skewOfLocal(t: ILeaf, origin: IPointData, skewX: number, skewY: number = 0, resize?: boolean): void {
|
|
@@ -119,6 +132,13 @@ export const LeafHelper = {
|
|
|
119
132
|
L.setTransform(t, matrix, resize)
|
|
120
133
|
},
|
|
121
134
|
|
|
135
|
+
transformWorld(t: ILeaf, transform: IMatrixData, resize?: boolean): void {
|
|
136
|
+
copy(matrix, t.worldTransform)
|
|
137
|
+
multiplyParent(matrix, transform)
|
|
138
|
+
if (t.parent) divideParent(matrix, t.parent.worldTransform)
|
|
139
|
+
L.setTransform(t, matrix, resize)
|
|
140
|
+
},
|
|
141
|
+
|
|
122
142
|
transform(t: ILeaf, transform: IMatrixData, resize?: boolean): void {
|
|
123
143
|
copy(matrix, t.localTransform)
|
|
124
144
|
multiplyParent(matrix, transform)
|
|
@@ -126,20 +146,44 @@ export const LeafHelper = {
|
|
|
126
146
|
},
|
|
127
147
|
|
|
128
148
|
setTransform(t: ILeaf, transform: IMatrixData, resize?: boolean): void {
|
|
129
|
-
const layout = getLayout(transform)
|
|
149
|
+
const layout = getLayout(transform, t.origin && L.getInnerOrigin(t, t.origin), t.around && L.getInnerOrigin(t, t.around))
|
|
130
150
|
if (resize) {
|
|
131
|
-
|
|
151
|
+
const scaleX = layout.scaleX / t.scaleX
|
|
152
|
+
const scaleY = layout.scaleY / t.scaleY
|
|
132
153
|
delete layout.scaleX
|
|
133
154
|
delete layout.scaleY
|
|
155
|
+
t.set(layout)
|
|
156
|
+
t.scaleResize(scaleX, scaleY, resize !== true)
|
|
157
|
+
} else {
|
|
158
|
+
t.set(layout)
|
|
134
159
|
}
|
|
135
|
-
t.set(layout)
|
|
136
160
|
},
|
|
137
161
|
|
|
162
|
+
getFlipTransform(t: ILeaf, axis: IAxis): IMatrixData {
|
|
163
|
+
const m = getMatrixData()
|
|
164
|
+
const sign = axis === 'x' ? 1 : -1
|
|
165
|
+
scaleOfOuter(m, L.getLocalOrigin(t, 'center'), -1 * sign, 1 * sign)
|
|
166
|
+
return m
|
|
167
|
+
},
|
|
138
168
|
|
|
139
|
-
|
|
169
|
+
getLocalOrigin(t: ILeaf, origin: IPointData | IAlign): IPointData {
|
|
170
|
+
return PointHelper.tempToOuterOf(L.getInnerOrigin(t, origin), t.localTransform)
|
|
171
|
+
},
|
|
172
|
+
|
|
173
|
+
getInnerOrigin(t: ILeaf, origin: IPointData | IAlign): IPointData {
|
|
174
|
+
const innerOrigin = {} as IPointData
|
|
175
|
+
AroundHelper.toPoint(origin, t.boxBounds, innerOrigin)
|
|
176
|
+
return innerOrigin
|
|
177
|
+
},
|
|
178
|
+
|
|
179
|
+
getRelativeWorld(t: ILeaf, relative: ILeaf, temp?: boolean): IMatrixData {
|
|
140
180
|
copy(matrix, t.worldTransform)
|
|
141
|
-
divideParent(matrix,
|
|
142
|
-
|
|
181
|
+
divideParent(matrix, relative.worldTransform)
|
|
182
|
+
return temp ? matrix : { ...matrix }
|
|
183
|
+
},
|
|
184
|
+
|
|
185
|
+
drop(t: ILeaf, parent: ILeaf, index?: number, resize?: boolean): void {
|
|
186
|
+
t.setTransform(L.getRelativeWorld(t, parent, true), resize)
|
|
143
187
|
parent.add(t, index)
|
|
144
188
|
},
|
|
145
189
|
|
|
@@ -149,13 +193,6 @@ export const LeafHelper = {
|
|
|
149
193
|
if (parent === p) return true
|
|
150
194
|
p = p.parent
|
|
151
195
|
}
|
|
152
|
-
},
|
|
153
|
-
|
|
154
|
-
hasParentAutoLayout(p: ILeaf): boolean | void {
|
|
155
|
-
while (p.parent) {
|
|
156
|
-
p = p.parent
|
|
157
|
-
if (p.__hasAutoLayout) return true
|
|
158
|
-
}
|
|
159
196
|
}
|
|
160
197
|
|
|
161
198
|
}
|
package/src/WaitHelper.ts
CHANGED
|
@@ -2,7 +2,10 @@ import { IFunction } from '@leafer/interface'
|
|
|
2
2
|
|
|
3
3
|
export const WaitHelper = {
|
|
4
4
|
run(wait: IFunction[]): void {
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
if (wait && wait.length) {
|
|
6
|
+
const len = wait.length
|
|
7
|
+
for (let i = 0; i < len; i++) { wait[i]() }
|
|
8
|
+
wait.length === len ? wait.length = 0 : wait.splice(0, len)
|
|
9
|
+
}
|
|
7
10
|
}
|
|
8
11
|
}
|
package/types/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ILeaf, IPointData, IMatrixData, IBoundsData, ILeafList, ILeafLevelList, IFunction } from '@leafer/interface';
|
|
1
|
+
import { ILeaf, IPointData, 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,19 +7,23 @@ 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, y
|
|
11
|
-
moveLocal(t: ILeaf, x: number, y?: number): void;
|
|
10
|
+
moveWorld(t: ILeaf, x: number | IPointData, y?: number): void;
|
|
11
|
+
moveLocal(t: ILeaf, x: number | IPointData, y?: number): void;
|
|
12
12
|
zoomOfWorld(t: ILeaf, origin: IPointData, scaleX: number, scaleY?: number, resize?: boolean): void;
|
|
13
13
|
zoomOfLocal(t: ILeaf, origin: IPointData, scaleX: number, scaleY?: number, resize?: boolean): void;
|
|
14
14
|
rotateOfWorld(t: ILeaf, origin: IPointData, angle: number): void;
|
|
15
15
|
rotateOfLocal(t: ILeaf, origin: IPointData, angle: number): void;
|
|
16
16
|
skewOfWorld(t: ILeaf, origin: IPointData, skewX: number, skewY?: number, resize?: boolean): void;
|
|
17
17
|
skewOfLocal(t: ILeaf, origin: IPointData, skewX: number, skewY?: number, resize?: boolean): void;
|
|
18
|
+
transformWorld(t: ILeaf, transform: IMatrixData, resize?: boolean): void;
|
|
18
19
|
transform(t: ILeaf, transform: IMatrixData, resize?: boolean): void;
|
|
19
20
|
setTransform(t: ILeaf, transform: IMatrixData, resize?: boolean): void;
|
|
21
|
+
getFlipTransform(t: ILeaf, axis: IAxis): IMatrixData;
|
|
22
|
+
getLocalOrigin(t: ILeaf, origin: IPointData | IAlign): IPointData;
|
|
23
|
+
getInnerOrigin(t: ILeaf, origin: IPointData | IAlign): IPointData;
|
|
24
|
+
getRelativeWorld(t: ILeaf, relative: ILeaf, temp?: boolean): IMatrixData;
|
|
20
25
|
drop(t: ILeaf, parent: ILeaf, index?: number, resize?: boolean): void;
|
|
21
26
|
hasParent(p: ILeaf, parent: ILeaf): boolean | void;
|
|
22
|
-
hasParentAutoLayout(p: ILeaf): boolean | void;
|
|
23
27
|
};
|
|
24
28
|
|
|
25
29
|
declare const LeafBoundsHelper: {
|
|
@@ -30,6 +34,7 @@ declare const LeafBoundsHelper: {
|
|
|
30
34
|
maskLocalBoxBounds(target: ILeaf): IBoundsData;
|
|
31
35
|
maskLocalStrokeBounds(target: ILeaf): IBoundsData;
|
|
32
36
|
maskLocalRenderBounds(target: ILeaf): IBoundsData;
|
|
37
|
+
excludeRenderBounds(child: ILeaf, options: IRenderOptions): boolean;
|
|
33
38
|
};
|
|
34
39
|
|
|
35
40
|
declare const BranchHelper: {
|