@leafer-ui/bounds 1.9.8 → 1.9.10

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.8",
3
+ "version": "1.9.10",
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.8"
25
+ "@leafer/core": "1.9.10"
26
26
  },
27
27
  "devDependencies": {
28
- "@leafer-ui/interface": "1.9.8"
28
+ "@leafer-ui/interface": "1.9.10"
29
29
  }
30
30
  }
package/src/index.ts CHANGED
@@ -1,2 +1 @@
1
1
  export { UIBounds } from "./UIBounds"
2
- export { DragBoundsHelper } from './DragBoundsHelper'
package/types/index.d.ts CHANGED
@@ -1,16 +1,5 @@
1
1
  import { IUIBoundsModule } from '@leafer-ui/interface';
2
- import { ILeaf, IPointData, IBoundsData, IDragBoundsType, ISide } from '@leafer/interface';
3
2
 
4
3
  declare const UIBounds: IUIBoundsModule;
5
4
 
6
- declare const DragBoundsHelper: {
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;
14
- };
15
-
16
- export { DragBoundsHelper, UIBounds };
5
+ export { UIBounds };
@@ -1,96 +0,0 @@
1
- import { IPointData, IBoundsData, IDragBoundsType, ILeaf, ISide } from '@leafer/interface'
2
- import { Bounds, MathHelper } from '@leafer/core'
3
-
4
-
5
- const { float } = MathHelper
6
- const tempContent = new Bounds(), tempMerge = new Bounds(), tempIntersect = new Bounds()
7
-
8
- export const DragBoundsHelper = {
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
-
39
- getValidMove(content: IBoundsData, dragBounds: IBoundsData, dragBoundsType: IDragBoundsType, move: IPointData, change?: boolean): IPointData {
40
- const x = content.x + move.x, y = content.y + move.y, right = x + content.width, bottom = y + content.height
41
- const boundsRight = dragBounds.x + dragBounds.width, boundsBottom = dragBounds.y + dragBounds.height
42
-
43
- if (!change) move = { ...move }
44
-
45
- if (D.isInnerMode(content, dragBounds, dragBoundsType, 'width')) { // inner 模式
46
- if (x > dragBounds.x) move.x += dragBounds.x - x
47
- else if (right < boundsRight) move.x += boundsRight - right
48
- } else { // outer 模式
49
- if (x < dragBounds.x) move.x += dragBounds.x - x
50
- else if (right > boundsRight) move.x += boundsRight - right
51
- }
52
-
53
- if (D.isInnerMode(content, dragBounds, dragBoundsType, 'height')) { // inner 模式
54
- if (y > dragBounds.y) move.y += dragBounds.y - y
55
- else if (bottom < boundsBottom) move.y += boundsBottom - bottom
56
- } else { // outer 模式
57
- if (y < dragBounds.y) move.y += dragBounds.y - y
58
- else if (bottom > boundsBottom) move.y += boundsBottom - bottom
59
- }
60
-
61
- // 避免出现很小为0的小数
62
- move.x = float(move.x)
63
- move.y = float(move.y)
64
-
65
- return move
66
- },
67
-
68
- getValidScaleOf(content: IBoundsData, dragBounds: IBoundsData, dragBoundsType: IDragBoundsType, origin: IPointData, scale: IPointData, change?: boolean): IPointData {
69
- if (!change) scale = { ...scale }
70
-
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
93
- }
94
- }
95
-
96
- const D = DragBoundsHelper