Files
klz-cables.com/.pnpm-store/v10/files/f1/289557cdd27a8e3c7654e93a0df29ad5faf7ef5c7847bdc8aef7033507af66d9b84fc0e8ebbfb8eb0d22d86a87cd4dc606d9d4cf7314a4d7527776865c072e
Marc Mintel 5397309103
Some checks failed
Build & Deploy / 🔍 Prepare (push) Successful in 20s
Build & Deploy / 🧪 QA (push) Failing after 34s
Build & Deploy / 🏗️ Build (push) Has started running
Build & Deploy / 🚀 Deploy (push) Has been cancelled
Build & Deploy / 🧪 Smoke Test (push) Has been cancelled
Build & Deploy / ⚡ Lighthouse (push) Has been cancelled
Build & Deploy / 🔔 Notify (push) Has been cancelled
fix(products): fix breadcrumbs and product filtering (backport from main)
2026-02-24 16:04:21 +01:00

56 lines
2.4 KiB
Plaintext

import { isNumber } from '../../utilities/isNumber.js';
/**
* Determine whether or not to resize the image.
* - resize using image config
* - resize using image config with focal adjustments
* - do not resize at all
*
* `imageResizeConfig.withoutEnlargement`:
* - undefined [default]: uploading images with smaller width AND height than the image size will return null
* - false: always enlarge images to the image size
* - true: if the image is smaller than the image size, return the original image
*
* `imageResizeConfig.withoutReduction`:
* - false [default]: always enlarge images to the image size
* - true: if the image is smaller than the image size, return the original image
*
* @return 'omit' | 'resize' | 'resizeWithFocalPoint'
*/ export const getImageResizeAction = ({ dimensions: originalImage, hasFocalPoint, imageResizeConfig })=>{
const { fit, withoutEnlargement, withoutReduction } = imageResizeConfig;
const targetWidth = imageResizeConfig.width;
const targetHeight = imageResizeConfig.height;
// prevent upscaling by default when x and y are both smaller than target image size
if (targetHeight && targetWidth) {
const originalImageIsSmallerXAndY = originalImage.width < targetWidth && originalImage.height < targetHeight;
if (withoutEnlargement === undefined && originalImageIsSmallerXAndY) {
return 'omit' // prevent image size from being enlarged
;
}
}
if (withoutEnlargement === undefined && (!targetWidth || !targetHeight)) {
if (targetWidth && originalImage.width < targetWidth || targetHeight && originalImage.height < targetHeight) {
return 'omit';
}
}
const originalImageIsSmallerXOrY = originalImage.width < targetWidth || originalImage.height < targetHeight;
if (fit === 'contain' || fit === 'inside') {
return 'resize';
}
if (!isNumber(targetHeight) && !isNumber(targetWidth)) {
return 'resize';
}
const targetAspectRatio = targetWidth / targetHeight;
const originalAspectRatio = originalImage.width / originalImage.height;
if (originalAspectRatio === targetAspectRatio) {
return 'resize';
}
if (withoutEnlargement && originalImageIsSmallerXOrY) {
return 'resize';
}
if (withoutReduction && !originalImageIsSmallerXOrY) {
return 'resize';
}
return hasFocalPoint ? 'resizeWithFocalPoint' : 'resize';
};
//# sourceMappingURL=getImageResizeAction.js.map