@leafer-ui/bounds 1.9.1 → 1.9.2

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@leafer-ui/bounds",
3
- "version": "1.9.1",
3
+ "version": "1.9.2",
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.1"
25
+ "@leafer/core": "1.9.2"
26
26
  },
27
27
  "devDependencies": {
28
- "@leafer-ui/interface": "1.9.1"
28
+ "@leafer-ui/interface": "1.9.2"
29
29
  }
30
30
  }
@@ -0,0 +1,54 @@
1
+ import { IPointData, IBoundsData, IDragBoundsType, ILeaf } from '@leafer/interface'
2
+ import { MathHelper } from '@leafer/core'
3
+
4
+
5
+ export const DragBoundsHelper = {
6
+
7
+ getValidMove(content: IBoundsData, dragBounds: IBoundsData, dragBoundsType: IDragBoundsType, move: IPointData, change?: boolean): IPointData {
8
+ const x = content.x + move.x, y = content.y + move.y, right = x + content.width, bottom = y + content.height
9
+ const boundsRight = dragBounds.x + dragBounds.width, boundsBottom = dragBounds.y + dragBounds.height
10
+
11
+ if (!change) move = { ...move }
12
+
13
+ const isBiggerWidth = content.width > dragBounds.width
14
+ const isBiggerHeight = content.height > dragBounds.height
15
+
16
+ if (isBiggerWidth && dragBoundsType !== 'outer') { // inner / auto 模式
17
+ if (x > dragBounds.x) move.x += dragBounds.x - x
18
+ else if (right < boundsRight) move.x += boundsRight - right
19
+ } else {
20
+ if (x < dragBounds.x) move.x += dragBounds.x - x
21
+ else if (right > boundsRight) move.x += boundsRight - right
22
+ }
23
+
24
+ if (isBiggerHeight && dragBoundsType !== 'outer') { // inner / auto 模式
25
+ if (y > dragBounds.y) move.y += dragBounds.y - y
26
+ else if (bottom < boundsBottom) move.y += boundsBottom - bottom
27
+ } else {
28
+ if (y < dragBounds.y) move.y += dragBounds.y - y
29
+ else if (bottom > boundsBottom) move.y += boundsBottom - bottom
30
+ }
31
+
32
+ // 避免出现很小为0的小数
33
+ move.x = MathHelper.float(move.x)
34
+ move.y = MathHelper.float(move.y)
35
+
36
+ return move
37
+ },
38
+
39
+ // 按轴移动
40
+ axisMove(leaf: ILeaf, move: IPointData) {
41
+ const { draggable } = leaf
42
+ if (draggable === 'x') move.y = 0
43
+ if (draggable === 'y') move.x = 0
44
+ },
45
+
46
+ // 拖拽区域内移动
47
+ limitMove(leaf: ILeaf, move: IPointData): void {
48
+ const { dragBounds, dragBoundsType } = leaf
49
+ if (dragBounds) D.getValidMove(leaf.__localBoxBounds, dragBounds === 'parent' ? leaf.parent.boxBounds : dragBounds, dragBoundsType, move, true)
50
+ D.axisMove(leaf, move)
51
+ }
52
+ }
53
+
54
+ const D = DragBoundsHelper
package/src/index.ts CHANGED
@@ -1 +1,2 @@
1
1
  export { UIBounds } from "./UIBounds"
2
+ export { DragBoundsHelper } from './DragBoundsHelper'
package/types/index.d.ts CHANGED
@@ -1,5 +1,12 @@
1
1
  import { IUIBoundsModule } from '@leafer-ui/interface';
2
+ import { IBoundsData, IDragBoundsType, IPointData, ILeaf } from '@leafer/interface';
2
3
 
3
4
  declare const UIBounds: IUIBoundsModule;
4
5
 
5
- export { UIBounds };
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
+ limitMove(leaf: ILeaf, move: IPointData): void;
10
+ };
11
+
12
+ export { DragBoundsHelper, UIBounds };