@@ -34,28 +34,32 @@ export default function useMouse(
34
34
const isRight = / r / . test ( point )
35
35
const newHeight = itemAttrH + ( isTop ? - currY : isBottom ? currY : 0 )
36
36
const newWidth = itemAttrW + ( isLeft ? - currX : isRight ? currX : 0 )
37
- let h = newHeight > 0 ? newHeight : 0
38
- let w = newWidth > 0 ? newWidth : 0
39
- let x = itemAttrX + ( isLeft ? currX : 0 )
40
- let y = itemAttrY + ( isTop ? currY : 0 )
41
-
42
- // if (x > parentWidth - w) {
43
- // w = Math.abs(parentWidth - x)
44
- // x = parentWidth - w
45
- // }
46
- // if (x < 0) {
47
- // w = w - Math.abs(x)
48
- // x = 0
49
- // }
50
- // if (y > parentHeight - h) {
51
- // h = Math.abs(parentHeight - y)
52
- // y = parentHeight - h
53
- // }
54
- // if (y < 0) {
55
- // h = h - Math.abs(y)
56
- // y = 0
57
- // }
58
-
37
+ let h = Math . abs ( newHeight )
38
+ let w = Math . abs ( newWidth )
39
+ let x =
40
+ newWidth > 0
41
+ ? itemAttrX + ( isLeft ? currX : 0 )
42
+ : itemAttrX + ( isLeft ? itemAttrW : newWidth )
43
+ let y =
44
+ newHeight > 0
45
+ ? itemAttrY + ( isTop ? currY : 0 )
46
+ : itemAttrY + ( isTop ? itemAttrH : newHeight )
47
+ if ( parent ) {
48
+ if ( x < 0 ) {
49
+ w = w + x
50
+ x = 0
51
+ }
52
+ if ( y < 0 ) {
53
+ h = h + y
54
+ y = 0
55
+ }
56
+ if ( x + w > parentWidth ) {
57
+ w = parentWidth - x
58
+ }
59
+ if ( y + h > parentHeight ) {
60
+ h = parentHeight - y
61
+ }
62
+ }
59
63
setAttrs ( { x, y, w, h } )
60
64
} )
61
65
}
0 commit comments