@leafer-ui/bounds 1.9.5 → 1.9.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/DragBoundsHelper.ts +64 -22
- package/src/UIBounds.ts +2 -2
- package/types/index.d.ts +7 -3
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@leafer-ui/bounds",
|
|
3
|
-
"version": "1.9.
|
|
3
|
+
"version": "1.9.6",
|
|
4
4
|
"description": "@leafer-ui/bounds",
|
|
5
5
|
"author": "Chao (Leafer) Wan",
|
|
6
6
|
"license": "MIT",
|
|
@@ -22,9 +22,9 @@
|
|
|
22
22
|
"leaferjs"
|
|
23
23
|
],
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@leafer/core": "1.9.
|
|
25
|
+
"@leafer/core": "1.9.6"
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|
|
28
|
-
"@leafer-ui/interface": "1.9.
|
|
28
|
+
"@leafer-ui/interface": "1.9.6"
|
|
29
29
|
}
|
|
30
30
|
}
|
package/src/DragBoundsHelper.ts
CHANGED
|
@@ -1,53 +1,95 @@
|
|
|
1
|
-
import { IPointData, IBoundsData, IDragBoundsType, ILeaf } from '@leafer/interface'
|
|
2
|
-
import { MathHelper } from '@leafer/core'
|
|
1
|
+
import { IPointData, IBoundsData, IDragBoundsType, ILeaf, ISide } from '@leafer/interface'
|
|
2
|
+
import { Bounds, MathHelper } from '@leafer/core'
|
|
3
3
|
|
|
4
4
|
|
|
5
|
+
const { float } = MathHelper
|
|
6
|
+
const tempContent = new Bounds(), tempMerge = new Bounds(), tempIntersect = new Bounds()
|
|
7
|
+
|
|
5
8
|
export const DragBoundsHelper = {
|
|
6
9
|
|
|
10
|
+
// 拖拽区域内移动
|
|
11
|
+
limitMove(leaf: ILeaf, move: IPointData): void {
|
|
12
|
+
const { dragBounds, dragBoundsType } = leaf
|
|
13
|
+
if (dragBounds) D.getValidMove(leaf.__localBoxBounds, D.getDragBounds(leaf), dragBoundsType, move, true)
|
|
14
|
+
D.axisMove(leaf, move)
|
|
15
|
+
},
|
|
16
|
+
|
|
17
|
+
// 拖拽区域内缩放
|
|
18
|
+
limitScaleOf(leaf: ILeaf, origin: IPointData, scale: IPointData): void {
|
|
19
|
+
const { dragBounds, dragBoundsType } = leaf
|
|
20
|
+
if (dragBounds) D.getValidScaleOf(leaf.__localBoxBounds, D.getDragBounds(leaf), dragBoundsType, leaf.getLocalPointByInner(leaf.getInnerPointByBox(origin)), scale, true)
|
|
21
|
+
},
|
|
22
|
+
|
|
23
|
+
// 按轴移动
|
|
24
|
+
axisMove(leaf: ILeaf, move: IPointData) {
|
|
25
|
+
const { draggable } = leaf
|
|
26
|
+
if (draggable === 'x') move.y = 0
|
|
27
|
+
if (draggable === 'y') move.x = 0
|
|
28
|
+
},
|
|
29
|
+
|
|
30
|
+
getDragBounds(leaf: ILeaf): IBoundsData {
|
|
31
|
+
const { dragBounds } = leaf
|
|
32
|
+
return dragBounds === 'parent' ? leaf.parent.boxBounds : dragBounds
|
|
33
|
+
},
|
|
34
|
+
|
|
35
|
+
isInnerMode(content: IBoundsData, dragBounds: IBoundsData, dragBoundsType: IDragBoundsType, sideType: ISide): boolean {
|
|
36
|
+
return dragBoundsType === 'inner' || (dragBoundsType === 'auto' && content[sideType] > dragBounds[sideType])
|
|
37
|
+
},
|
|
38
|
+
|
|
7
39
|
getValidMove(content: IBoundsData, dragBounds: IBoundsData, dragBoundsType: IDragBoundsType, move: IPointData, change?: boolean): IPointData {
|
|
8
40
|
const x = content.x + move.x, y = content.y + move.y, right = x + content.width, bottom = y + content.height
|
|
9
41
|
const boundsRight = dragBounds.x + dragBounds.width, boundsBottom = dragBounds.y + dragBounds.height
|
|
10
42
|
|
|
11
43
|
if (!change) move = { ...move }
|
|
12
44
|
|
|
13
|
-
|
|
14
|
-
const isBiggerHeight = content.height > dragBounds.height
|
|
15
|
-
|
|
16
|
-
if (isBiggerWidth && dragBoundsType !== 'outer') { // inner / auto 模式
|
|
45
|
+
if (D.isInnerMode(content, dragBounds, dragBoundsType, 'width')) { // inner 模式
|
|
17
46
|
if (x > dragBounds.x) move.x += dragBounds.x - x
|
|
18
47
|
else if (right < boundsRight) move.x += boundsRight - right
|
|
19
|
-
} else {
|
|
48
|
+
} else { // outer 模式
|
|
20
49
|
if (x < dragBounds.x) move.x += dragBounds.x - x
|
|
21
50
|
else if (right > boundsRight) move.x += boundsRight - right
|
|
22
51
|
}
|
|
23
52
|
|
|
24
|
-
if (
|
|
53
|
+
if (D.isInnerMode(content, dragBounds, dragBoundsType, 'height')) { // inner 模式
|
|
25
54
|
if (y > dragBounds.y) move.y += dragBounds.y - y
|
|
26
55
|
else if (bottom < boundsBottom) move.y += boundsBottom - bottom
|
|
27
|
-
} else {
|
|
56
|
+
} else { // outer 模式
|
|
28
57
|
if (y < dragBounds.y) move.y += dragBounds.y - y
|
|
29
58
|
else if (bottom > boundsBottom) move.y += boundsBottom - bottom
|
|
30
59
|
}
|
|
31
60
|
|
|
32
61
|
// 避免出现很小为0的小数
|
|
33
|
-
move.x =
|
|
34
|
-
move.y =
|
|
62
|
+
move.x = float(move.x)
|
|
63
|
+
move.y = float(move.y)
|
|
35
64
|
|
|
36
65
|
return move
|
|
37
66
|
},
|
|
38
67
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
const { draggable } = leaf
|
|
42
|
-
if (draggable === 'x') move.y = 0
|
|
43
|
-
if (draggable === 'y') move.x = 0
|
|
44
|
-
},
|
|
68
|
+
getValidScaleOf(content: IBoundsData, dragBounds: IBoundsData, dragBoundsType: IDragBoundsType, origin: IPointData, scale: IPointData, change?: boolean): IPointData {
|
|
69
|
+
if (!change) scale = { ...scale }
|
|
45
70
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
71
|
+
let fitScaleX: number, fitScaleY: number
|
|
72
|
+
|
|
73
|
+
tempContent.set(content).scaleOf(origin, scale.x, scale.y).unsign()
|
|
74
|
+
tempMerge.set(tempContent).add(dragBounds)
|
|
75
|
+
tempIntersect.set(tempContent).intersect(dragBounds)
|
|
76
|
+
|
|
77
|
+
if (D.isInnerMode(content, dragBounds, dragBoundsType, 'width')) { // inner 模式
|
|
78
|
+
fitScaleX = tempMerge.width / tempContent.width
|
|
79
|
+
} else { // outer 模式
|
|
80
|
+
fitScaleX = tempIntersect.width / tempContent.width
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
if (D.isInnerMode(content, dragBounds, dragBoundsType, 'height')) { // inner 模式
|
|
84
|
+
fitScaleY = tempMerge.height / tempContent.height
|
|
85
|
+
} else { // outer 模式
|
|
86
|
+
fitScaleY = tempIntersect.height / tempContent.height
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
scale.x = float(tempIntersect.width) ? scale.x * fitScaleX : 1
|
|
90
|
+
scale.y = float(tempIntersect.height) ? scale.y * fitScaleY : 1
|
|
91
|
+
|
|
92
|
+
return scale
|
|
51
93
|
}
|
|
52
94
|
}
|
|
53
95
|
|
package/src/UIBounds.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { IUIBoundsModule } from "@leafer-ui/interface"
|
|
2
2
|
|
|
3
|
-
import { Filter } from '@leafer-ui/external'
|
|
3
|
+
import { Effect, Filter } from '@leafer-ui/external'
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
export const UIBounds: IUIBoundsModule = {
|
|
@@ -35,7 +35,7 @@ export const UIBounds: IUIBoundsModule = {
|
|
|
35
35
|
let width: number = 0
|
|
36
36
|
const { shadow, innerShadow, blur, backgroundBlur, filter, renderSpread } = this.__
|
|
37
37
|
|
|
38
|
-
if (shadow)
|
|
38
|
+
if (shadow) width = Effect.getShadowSpread(this, shadow)
|
|
39
39
|
|
|
40
40
|
if (blur) width = Math.max(width, blur)
|
|
41
41
|
|
package/types/index.d.ts
CHANGED
|
@@ -1,12 +1,16 @@
|
|
|
1
1
|
import { IUIBoundsModule } from '@leafer-ui/interface';
|
|
2
|
-
import { IBoundsData, IDragBoundsType,
|
|
2
|
+
import { ILeaf, IPointData, IBoundsData, IDragBoundsType, ISide } from '@leafer/interface';
|
|
3
3
|
|
|
4
4
|
declare const UIBounds: IUIBoundsModule;
|
|
5
5
|
|
|
6
6
|
declare const DragBoundsHelper: {
|
|
7
|
-
getValidMove(content: IBoundsData, dragBounds: IBoundsData, dragBoundsType: IDragBoundsType, move: IPointData, change?: boolean): IPointData;
|
|
8
|
-
axisMove(leaf: ILeaf, move: IPointData): void;
|
|
9
7
|
limitMove(leaf: ILeaf, move: IPointData): void;
|
|
8
|
+
limitScaleOf(leaf: ILeaf, origin: IPointData, scale: IPointData): void;
|
|
9
|
+
axisMove(leaf: ILeaf, move: IPointData): void;
|
|
10
|
+
getDragBounds(leaf: ILeaf): IBoundsData;
|
|
11
|
+
isInnerMode(content: IBoundsData, dragBounds: IBoundsData, dragBoundsType: IDragBoundsType, sideType: ISide): boolean;
|
|
12
|
+
getValidMove(content: IBoundsData, dragBounds: IBoundsData, dragBoundsType: IDragBoundsType, move: IPointData, change?: boolean): IPointData;
|
|
13
|
+
getValidScaleOf(content: IBoundsData, dragBounds: IBoundsData, dragBoundsType: IDragBoundsType, origin: IPointData, scale: IPointData, change?: boolean): IPointData;
|
|
10
14
|
};
|
|
11
15
|
|
|
12
16
|
export { DragBoundsHelper, UIBounds };
|