feat(node-resizer): add shouldResize option

Signed-off-by: braks <78412429+bcakmakoglu@users.noreply.github.com>
This commit is contained in:
braks
2023-02-02 16:15:20 +01:00
committed by Braks
parent f0043258d0
commit 222b58afd4
5 changed files with 92 additions and 20 deletions
+27
View File
@@ -0,0 +1,27 @@
interface GetDirectionParams {
width: number
prevWidth: number
height: number
prevHeight: number
invertX: boolean
invertY: boolean
}
// returns an array of two numbers (0, 1 or -1) representing the direction of the resize
// 0 = no change, 1 = increase, -1 = decrease
export function getDirection({ width, prevWidth, height, prevHeight, invertX, invertY }: GetDirectionParams) {
const deltaWidth = width - prevWidth
const deltaHeight = height - prevHeight
const direction = [deltaWidth > 0 ? 1 : deltaWidth < 0 ? -1 : 0, deltaHeight > 0 ? 1 : deltaHeight < 0 ? -1 : 0]
if (deltaWidth && invertX) {
direction[0] = direction[0] * -1
}
if (deltaHeight && invertY) {
direction[1] = direction[1] * -1
}
return direction
}