@leafer/helper 1.8.0 → 1.9.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 +5 -4
- package/src/BranchHelper.ts +2 -2
- package/src/LeafBoundsHelper.ts +15 -6
- package/src/LeafHelper.ts +22 -3
- package/types/index.d.ts +5 -3
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@leafer/helper",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.9.1",
|
|
4
4
|
"description": "@leafer/helper",
|
|
5
5
|
"author": "Chao (Leafer) Wan",
|
|
6
6
|
"license": "MIT",
|
|
@@ -22,10 +22,11 @@
|
|
|
22
22
|
"leaferjs"
|
|
23
23
|
],
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@leafer/
|
|
26
|
-
"@leafer/
|
|
25
|
+
"@leafer/data": "1.9.1",
|
|
26
|
+
"@leafer/math": "1.9.1",
|
|
27
|
+
"@leafer/platform": "1.9.1"
|
|
27
28
|
},
|
|
28
29
|
"devDependencies": {
|
|
29
|
-
"@leafer/interface": "1.
|
|
30
|
+
"@leafer/interface": "1.9.1"
|
|
30
31
|
}
|
|
31
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,6 +1,7 @@
|
|
|
1
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
3
|
import { Platform } from '@leafer/platform'
|
|
4
|
+
import { isObject, isNumber } from '@leafer/data'
|
|
4
5
|
|
|
5
6
|
|
|
6
7
|
const { copy, toInnerPoint, toOuterPoint, scaleOfOuter, rotateOfOuter, skewOfOuter, multiplyParent, divideParent, getLayout } = MatrixHelper
|
|
@@ -79,6 +80,10 @@ export const LeafHelper = {
|
|
|
79
80
|
return true
|
|
80
81
|
},
|
|
81
82
|
|
|
83
|
+
draggable(t: ILeaf): boolean {
|
|
84
|
+
return (t.draggable || t.editable) && t.hitSelf && !t.locked
|
|
85
|
+
},
|
|
86
|
+
|
|
82
87
|
copyCanvasByWorld(leaf: ILeaf, currentCanvas: ILeaferCanvas, fromCanvas: ILeaferCanvas, fromWorld?: IBoundsData, blendMode?: string, onlyResetTransform?: boolean): void {
|
|
83
88
|
if (!fromWorld) fromWorld = leaf.__nowWorld
|
|
84
89
|
if (leaf.__worldFlipped || Platform.fullImageShadow) currentCanvas.copyWorldByReset(fromCanvas, fromWorld, leaf.__nowWorld, blendMode, onlyResetTransform)
|
|
@@ -88,13 +93,13 @@ export const LeafHelper = {
|
|
|
88
93
|
// transform
|
|
89
94
|
|
|
90
95
|
moveWorld(t: ILeaf, x: number | IPointData, y = 0, isInnerPoint?: boolean, transition?: ITransition): void {
|
|
91
|
-
const local =
|
|
96
|
+
const local = isObject(x) ? { ...x } : { x, y }
|
|
92
97
|
isInnerPoint ? toOuterPoint(t.localTransform, local, local, true) : (t.parent && toInnerPoint(t.parent.worldTransform, local, local, true))
|
|
93
98
|
L.moveLocal(t, local.x, local.y, transition)
|
|
94
99
|
},
|
|
95
100
|
|
|
96
101
|
moveLocal(t: ILeaf, x: number | IPointData, y = 0, transition?: ITransition): void {
|
|
97
|
-
if (
|
|
102
|
+
if (isObject(x)) y = x.y, x = x.x
|
|
98
103
|
x += t.x
|
|
99
104
|
y += t.y
|
|
100
105
|
if (t.leafer && t.leafer.config.pointSnap) x = round(x), y = round(y)
|
|
@@ -107,7 +112,7 @@ export const LeafHelper = {
|
|
|
107
112
|
|
|
108
113
|
zoomOfLocal(t: ILeaf, origin: IPointData, scaleX: number, scaleY: number | ITransition = scaleX, resize?: boolean, transition?: ITransition): void {
|
|
109
114
|
const o = t.__localMatrix
|
|
110
|
-
if (
|
|
115
|
+
if (!isNumber(scaleY)) {
|
|
111
116
|
if (scaleY) transition = scaleY
|
|
112
117
|
scaleY = scaleX
|
|
113
118
|
}
|
|
@@ -210,6 +215,20 @@ export const LeafHelper = {
|
|
|
210
215
|
if (parent === p) return true
|
|
211
216
|
p = p.parent
|
|
212
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
|
+
}
|
|
213
232
|
}
|
|
214
233
|
|
|
215
234
|
}
|
package/types/index.d.ts
CHANGED
|
@@ -8,6 +8,7 @@ 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;
|
|
11
12
|
copyCanvasByWorld(leaf: ILeaf, currentCanvas: ILeaferCanvas, fromCanvas: ILeaferCanvas, fromWorld?: IBoundsData, blendMode?: string, onlyResetTransform?: boolean): void;
|
|
12
13
|
moveWorld(t: ILeaf, x: number | IPointData, y?: number, isInnerPoint?: boolean, transition?: ITransition): void;
|
|
13
14
|
moveLocal(t: ILeaf, x: number | IPointData, y?: number, transition?: ITransition): void;
|
|
@@ -26,6 +27,7 @@ declare const LeafHelper: {
|
|
|
26
27
|
getRelativeWorld(t: ILeaf, relative: ILeaf, temp?: boolean): IMatrixData;
|
|
27
28
|
drop(t: ILeaf, parent: ILeaf, index?: number, resize?: boolean): void;
|
|
28
29
|
hasParent(p: ILeaf, parent: ILeaf): boolean | void;
|
|
30
|
+
animateMove(t: ILeaf, move: IPointData, speed?: number): void;
|
|
29
31
|
};
|
|
30
32
|
|
|
31
33
|
declare const LeafBoundsHelper: {
|
|
@@ -33,9 +35,9 @@ declare const LeafBoundsHelper: {
|
|
|
33
35
|
localBoxBounds(target: ILeaf): IBoundsData;
|
|
34
36
|
localStrokeBounds(target: ILeaf): IBoundsData;
|
|
35
37
|
localRenderBounds(target: ILeaf): IBoundsData;
|
|
36
|
-
maskLocalBoxBounds(target: ILeaf): IBoundsData;
|
|
37
|
-
maskLocalStrokeBounds(target: ILeaf): IBoundsData;
|
|
38
|
-
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;
|
|
39
41
|
excludeRenderBounds(child: ILeaf, options: IRenderOptions): boolean;
|
|
40
42
|
};
|
|
41
43
|
|