@leafer/helper 1.7.0 → 1.9.0
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 +5 -3
- package/src/BranchHelper.ts +2 -2
- package/src/LeafBoundsHelper.ts +15 -6
- package/src/LeafHelper.ts +30 -4
- package/types/index.d.ts +7 -4
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@leafer/helper",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.9.0",
|
|
4
4
|
"description": "@leafer/helper",
|
|
5
5
|
"author": "Chao (Leafer) Wan",
|
|
6
6
|
"license": "MIT",
|
|
@@ -22,9 +22,11 @@
|
|
|
22
22
|
"leaferjs"
|
|
23
23
|
],
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@leafer/
|
|
25
|
+
"@leafer/data": "1.9.0",
|
|
26
|
+
"@leafer/math": "1.9.0",
|
|
27
|
+
"@leafer/platform": "1.9.0"
|
|
26
28
|
},
|
|
27
29
|
"devDependencies": {
|
|
28
|
-
"@leafer/interface": "1.
|
|
30
|
+
"@leafer/interface": "1.9.0"
|
|
29
31
|
}
|
|
30
32
|
}
|
package/src/BranchHelper.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ILeaf, ILeafLevelList, ILeafList } from '@leafer/interface'
|
|
2
|
-
|
|
2
|
+
import { isUndefined } from '@leafer/data'
|
|
3
3
|
import { LeafHelper } from './LeafHelper'
|
|
4
4
|
|
|
5
5
|
const { updateBounds } = LeafHelper
|
|
@@ -32,7 +32,7 @@ export const BranchHelper = {
|
|
|
32
32
|
const { keys } = (leafList as ILeafList)
|
|
33
33
|
if (keys) {
|
|
34
34
|
while (leaf.parent) {
|
|
35
|
-
if (keys[leaf.parent.innerId]
|
|
35
|
+
if (isUndefined(keys[leaf.parent.innerId])) {
|
|
36
36
|
leafList.add(leaf.parent)
|
|
37
37
|
leaf = leaf.parent
|
|
38
38
|
} else {
|
package/src/LeafBoundsHelper.ts
CHANGED
|
@@ -19,16 +19,16 @@ export const LeafBoundsHelper = {
|
|
|
19
19
|
return target.__.eraser || target.__.visible === 0 ? null : target.__layout.localRenderBounds
|
|
20
20
|
},
|
|
21
21
|
|
|
22
|
-
maskLocalBoxBounds(target: ILeaf): IBoundsData {
|
|
23
|
-
return target
|
|
22
|
+
maskLocalBoxBounds(target: ILeaf, index: number): IBoundsData {
|
|
23
|
+
return checkMask(target, index) && target.__localBoxBounds
|
|
24
24
|
},
|
|
25
25
|
|
|
26
|
-
maskLocalStrokeBounds(target: ILeaf): IBoundsData {
|
|
27
|
-
return target
|
|
26
|
+
maskLocalStrokeBounds(target: ILeaf, index: number): IBoundsData {
|
|
27
|
+
return checkMask(target, index) && target.__layout.localStrokeBounds
|
|
28
28
|
},
|
|
29
29
|
|
|
30
|
-
maskLocalRenderBounds(target: ILeaf): IBoundsData {
|
|
31
|
-
return target
|
|
30
|
+
maskLocalRenderBounds(target: ILeaf, index: number): IBoundsData {
|
|
31
|
+
return checkMask(target, index) && target.__layout.localRenderBounds
|
|
32
32
|
},
|
|
33
33
|
|
|
34
34
|
excludeRenderBounds(child: ILeaf, options: IRenderOptions): boolean {
|
|
@@ -38,3 +38,12 @@ export const LeafBoundsHelper = {
|
|
|
38
38
|
}
|
|
39
39
|
|
|
40
40
|
}
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
let findMask: number
|
|
44
|
+
|
|
45
|
+
function checkMask(target: ILeaf, index: number): boolean {
|
|
46
|
+
if (!index) findMask = 0
|
|
47
|
+
if (target.__.mask) findMask = 1
|
|
48
|
+
return findMask < 0 ? null : (findMask && (findMask = -1), true) // 第一个 mask 元素之后的元素 bounds 可以忽略,返回 null
|
|
49
|
+
}
|
package/src/LeafHelper.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
import { IAlign, ILeaf, IMatrixData, IPointData, IAxis, ITransition } from '@leafer/interface'
|
|
1
|
+
import { IAlign, ILeaf, IMatrixData, IPointData, IAxis, ITransition, ILeaferCanvas, IBoundsData, IMatrixWithBoundsData } from '@leafer/interface'
|
|
2
2
|
import { MathHelper, MatrixHelper, PointHelper, AroundHelper, getMatrixData, BoundsHelper } from '@leafer/math'
|
|
3
|
+
import { Platform } from '@leafer/platform'
|
|
4
|
+
import { isObject, isNumber } from '@leafer/data'
|
|
3
5
|
|
|
4
6
|
|
|
5
7
|
const { copy, toInnerPoint, toOuterPoint, scaleOfOuter, rotateOfOuter, skewOfOuter, multiplyParent, divideParent, getLayout } = MatrixHelper
|
|
@@ -78,16 +80,26 @@ export const LeafHelper = {
|
|
|
78
80
|
return true
|
|
79
81
|
},
|
|
80
82
|
|
|
83
|
+
draggable(t: ILeaf): boolean {
|
|
84
|
+
return (t.draggable || t.editable) && t.hitSelf && !t.locked
|
|
85
|
+
},
|
|
86
|
+
|
|
87
|
+
copyCanvasByWorld(leaf: ILeaf, currentCanvas: ILeaferCanvas, fromCanvas: ILeaferCanvas, fromWorld?: IBoundsData, blendMode?: string, onlyResetTransform?: boolean): void {
|
|
88
|
+
if (!fromWorld) fromWorld = leaf.__nowWorld
|
|
89
|
+
if (leaf.__worldFlipped || Platform.fullImageShadow) currentCanvas.copyWorldByReset(fromCanvas, fromWorld, leaf.__nowWorld, blendMode, onlyResetTransform)
|
|
90
|
+
else currentCanvas.copyWorldToInner(fromCanvas, fromWorld as IMatrixWithBoundsData, leaf.__layout.renderBounds, blendMode)
|
|
91
|
+
},
|
|
92
|
+
|
|
81
93
|
// transform
|
|
82
94
|
|
|
83
95
|
moveWorld(t: ILeaf, x: number | IPointData, y = 0, isInnerPoint?: boolean, transition?: ITransition): void {
|
|
84
|
-
const local =
|
|
96
|
+
const local = isObject(x) ? { ...x } : { x, y }
|
|
85
97
|
isInnerPoint ? toOuterPoint(t.localTransform, local, local, true) : (t.parent && toInnerPoint(t.parent.worldTransform, local, local, true))
|
|
86
98
|
L.moveLocal(t, local.x, local.y, transition)
|
|
87
99
|
},
|
|
88
100
|
|
|
89
101
|
moveLocal(t: ILeaf, x: number | IPointData, y = 0, transition?: ITransition): void {
|
|
90
|
-
if (
|
|
102
|
+
if (isObject(x)) y = x.y, x = x.x
|
|
91
103
|
x += t.x
|
|
92
104
|
y += t.y
|
|
93
105
|
if (t.leafer && t.leafer.config.pointSnap) x = round(x), y = round(y)
|
|
@@ -100,7 +112,7 @@ export const LeafHelper = {
|
|
|
100
112
|
|
|
101
113
|
zoomOfLocal(t: ILeaf, origin: IPointData, scaleX: number, scaleY: number | ITransition = scaleX, resize?: boolean, transition?: ITransition): void {
|
|
102
114
|
const o = t.__localMatrix
|
|
103
|
-
if (
|
|
115
|
+
if (!isNumber(scaleY)) {
|
|
104
116
|
if (scaleY) transition = scaleY
|
|
105
117
|
scaleY = scaleX
|
|
106
118
|
}
|
|
@@ -203,6 +215,20 @@ export const LeafHelper = {
|
|
|
203
215
|
if (parent === p) return true
|
|
204
216
|
p = p.parent
|
|
205
217
|
}
|
|
218
|
+
},
|
|
219
|
+
|
|
220
|
+
// 简单动画操作
|
|
221
|
+
|
|
222
|
+
animateMove(t: ILeaf, move: IPointData, speed = 0.3) {
|
|
223
|
+
if (!move.x && !move.y) return
|
|
224
|
+
if (Math.abs(move.x) < 1 && Math.abs(move.y) < 1) {
|
|
225
|
+
t.move(move)
|
|
226
|
+
} else {
|
|
227
|
+
const x = move.x * speed, y = move.y * speed
|
|
228
|
+
move.x -= x, move.y -= y
|
|
229
|
+
t.move(x, y)
|
|
230
|
+
Platform.requestRender(() => L.animateMove(t, move, speed))
|
|
231
|
+
}
|
|
206
232
|
}
|
|
207
233
|
|
|
208
234
|
}
|
package/types/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ILeaf, IPointData, ITransition, IMatrixData, IAxis, IAlign,
|
|
1
|
+
import { ILeaf, ILeaferCanvas, IBoundsData, IPointData, ITransition, IMatrixData, IAxis, IAlign, IRenderOptions, ILeafList, ILeafLevelList, IFunction } from '@leafer/interface';
|
|
2
2
|
|
|
3
3
|
declare const LeafHelper: {
|
|
4
4
|
updateAllMatrix(leaf: ILeaf, checkAutoLayout?: boolean, waitAutoLayout?: boolean): void;
|
|
@@ -8,6 +8,8 @@ declare const LeafHelper: {
|
|
|
8
8
|
updateChange(leaf: ILeaf): void;
|
|
9
9
|
updateAllChange(leaf: ILeaf): void;
|
|
10
10
|
worldHittable(t: ILeaf): boolean;
|
|
11
|
+
draggable(t: ILeaf): boolean;
|
|
12
|
+
copyCanvasByWorld(leaf: ILeaf, currentCanvas: ILeaferCanvas, fromCanvas: ILeaferCanvas, fromWorld?: IBoundsData, blendMode?: string, onlyResetTransform?: boolean): void;
|
|
11
13
|
moveWorld(t: ILeaf, x: number | IPointData, y?: number, isInnerPoint?: boolean, transition?: ITransition): void;
|
|
12
14
|
moveLocal(t: ILeaf, x: number | IPointData, y?: number, transition?: ITransition): void;
|
|
13
15
|
zoomOfWorld(t: ILeaf, origin: IPointData, scaleX: number, scaleY?: number | ITransition, resize?: boolean, transition?: ITransition): void;
|
|
@@ -25,6 +27,7 @@ declare const LeafHelper: {
|
|
|
25
27
|
getRelativeWorld(t: ILeaf, relative: ILeaf, temp?: boolean): IMatrixData;
|
|
26
28
|
drop(t: ILeaf, parent: ILeaf, index?: number, resize?: boolean): void;
|
|
27
29
|
hasParent(p: ILeaf, parent: ILeaf): boolean | void;
|
|
30
|
+
animateMove(t: ILeaf, move: IPointData, speed?: number): void;
|
|
28
31
|
};
|
|
29
32
|
|
|
30
33
|
declare const LeafBoundsHelper: {
|
|
@@ -32,9 +35,9 @@ declare const LeafBoundsHelper: {
|
|
|
32
35
|
localBoxBounds(target: ILeaf): IBoundsData;
|
|
33
36
|
localStrokeBounds(target: ILeaf): IBoundsData;
|
|
34
37
|
localRenderBounds(target: ILeaf): IBoundsData;
|
|
35
|
-
maskLocalBoxBounds(target: ILeaf): IBoundsData;
|
|
36
|
-
maskLocalStrokeBounds(target: ILeaf): IBoundsData;
|
|
37
|
-
maskLocalRenderBounds(target: ILeaf): IBoundsData;
|
|
38
|
+
maskLocalBoxBounds(target: ILeaf, index: number): IBoundsData;
|
|
39
|
+
maskLocalStrokeBounds(target: ILeaf, index: number): IBoundsData;
|
|
40
|
+
maskLocalRenderBounds(target: ILeaf, index: number): IBoundsData;
|
|
38
41
|
excludeRenderBounds(child: ILeaf, options: IRenderOptions): boolean;
|
|
39
42
|
};
|
|
40
43
|
|