2022-12-12 22:24:03 +01:00
|
|
|
export const aspectRatio = ({
|
|
|
|
total,
|
|
|
|
index,
|
|
|
|
width,
|
|
|
|
height
|
|
|
|
}: {
|
|
|
|
total: number
|
|
|
|
index?: number
|
|
|
|
width?: number
|
|
|
|
height?: number
|
|
|
|
}): number => {
|
2023-01-15 22:04:25 +01:00
|
|
|
const defaultCrop =
|
2023-02-11 23:46:12 +01:00
|
|
|
height && width
|
|
|
|
? height / width > 3 / 2
|
|
|
|
? 2 / 3
|
|
|
|
: width / height > 4
|
|
|
|
? 4
|
|
|
|
: width / height
|
|
|
|
: 16 / 9
|
2022-12-12 22:24:03 +01:00
|
|
|
|
|
|
|
const isEven = total % 2 == 0
|
|
|
|
if (total > 5) {
|
|
|
|
switch (isEven) {
|
|
|
|
case true:
|
|
|
|
return total / 2 / 2
|
|
|
|
case false:
|
|
|
|
if ((index || -2) + 1 == total) {
|
|
|
|
return Math.ceil(total / 2)
|
|
|
|
} else {
|
|
|
|
return Math.ceil(total / 2) / 2
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
switch (isEven) {
|
|
|
|
case true:
|
2023-01-15 22:04:25 +01:00
|
|
|
return defaultCrop
|
2022-12-12 22:24:03 +01:00
|
|
|
case false:
|
|
|
|
if ((index || -2) + 1 == total) {
|
2023-01-15 22:04:25 +01:00
|
|
|
return defaultCrop * 2
|
2022-12-12 22:24:03 +01:00
|
|
|
} else {
|
2023-01-15 22:04:25 +01:00
|
|
|
return defaultCrop
|
2022-12-12 22:24:03 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|