function cover(containerSize, elementSize) {
const containerRatio = containerSize.width / containerSize.height
const elementRatio = elementSize.width / elementSize.height
let width, height
if (containerRatio > elementRatio) {
width = containerSize.width
height = containerSize.width / elementRatio
} else {
width = containerSize.height * elementRatio
height = containerSize.height
}
return { width, height }
}
function contain(containerSize, elementSize) {
const containerRatio = containerSize.width / containerSize.height
const elementRatio = elementSize.width / elementSize.height
let width, height
if (containerRatio < elementRatio) {
width = containerSize.width
height = containerSize.width / elementRatio
} else {
width = containerSize.height * elementRatio
height = containerSize.height
}
return { width, height }
}
function fill(containerSize) {
return containerSize
}
function none(elementSize) {
return elementSize
}
function scaleDown(containerSize, elementSize) {
if (elementSize.width > containerSize.width || elementSize.height > containerSize.height) {
return contain(containerSize, elementSize)
} else {
return none(containerSize)
}
}