tooot/src/components/Timeline/Shared/Attachment/dimensions.ts

46 lines
856 B
TypeScript
Raw Normal View History

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
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
case false:
if ((index || -2) + 1 == total) {
2023-01-15 22:04:25 +01:00
return defaultCrop * 2
} else {
2023-01-15 22:04:25 +01:00
return defaultCrop
}
}
}
}