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
1 line
4.0 KiB
Plaintext
1 line
4.0 KiB
Plaintext
{"version":3,"sources":["../../../src/uploads/image-resizing/getImageResizeAction.ts"],"sourcesContent":["import type { ImageSize, ProbedImageSize } from '../types.js'\n\nimport { isNumber } from '../../utilities/isNumber.js'\n\n/**\n * Determine whether or not to resize the image.\n * - resize using image config\n * - resize using image config with focal adjustments\n * - do not resize at all\n *\n * `imageResizeConfig.withoutEnlargement`:\n * - undefined [default]: uploading images with smaller width AND height than the image size will return null\n * - false: always enlarge images to the image size\n * - true: if the image is smaller than the image size, return the original image\n *\n * `imageResizeConfig.withoutReduction`:\n * - false [default]: always enlarge images to the image size\n * - true: if the image is smaller than the image size, return the original image\n *\n * @return 'omit' | 'resize' | 'resizeWithFocalPoint'\n */\nexport const getImageResizeAction = ({\n dimensions: originalImage,\n hasFocalPoint,\n imageResizeConfig,\n}: {\n dimensions: ProbedImageSize\n hasFocalPoint?: boolean\n imageResizeConfig: ImageSize\n}): 'omit' | 'resize' | 'resizeWithFocalPoint' => {\n const { fit, withoutEnlargement, withoutReduction } = imageResizeConfig\n const targetWidth = imageResizeConfig.width!\n const targetHeight = imageResizeConfig.height!\n\n // prevent upscaling by default when x and y are both smaller than target image size\n if (targetHeight && targetWidth) {\n const originalImageIsSmallerXAndY =\n originalImage.width < targetWidth && originalImage.height < targetHeight\n if (withoutEnlargement === undefined && originalImageIsSmallerXAndY) {\n return 'omit' // prevent image size from being enlarged\n }\n }\n\n if (withoutEnlargement === undefined && (!targetWidth || !targetHeight)) {\n if (\n (targetWidth && originalImage.width < targetWidth) ||\n (targetHeight && originalImage.height < targetHeight)\n ) {\n return 'omit'\n }\n }\n\n const originalImageIsSmallerXOrY =\n originalImage.width < targetWidth || originalImage.height < targetHeight\n if (fit === 'contain' || fit === 'inside') {\n return 'resize'\n }\n if (!isNumber(targetHeight) && !isNumber(targetWidth)) {\n return 'resize'\n }\n\n const targetAspectRatio = targetWidth / targetHeight\n const originalAspectRatio = originalImage.width / originalImage.height\n if (originalAspectRatio === targetAspectRatio) {\n return 'resize'\n }\n\n if (withoutEnlargement && originalImageIsSmallerXOrY) {\n return 'resize'\n }\n if (withoutReduction && !originalImageIsSmallerXOrY) {\n return 'resize'\n }\n\n return hasFocalPoint ? 'resizeWithFocalPoint' : 'resize'\n}\n"],"names":["isNumber","getImageResizeAction","dimensions","originalImage","hasFocalPoint","imageResizeConfig","fit","withoutEnlargement","withoutReduction","targetWidth","width","targetHeight","height","originalImageIsSmallerXAndY","undefined","originalImageIsSmallerXOrY","targetAspectRatio","originalAspectRatio"],"mappings":"AAEA,SAASA,QAAQ,QAAQ,8BAA6B;AAEtD;;;;;;;;;;;;;;;;CAgBC,GACD,OAAO,MAAMC,uBAAuB,CAAC,EACnCC,YAAYC,aAAa,EACzBC,aAAa,EACbC,iBAAiB,EAKlB;IACC,MAAM,EAAEC,GAAG,EAAEC,kBAAkB,EAAEC,gBAAgB,EAAE,GAAGH;IACtD,MAAMI,cAAcJ,kBAAkBK,KAAK;IAC3C,MAAMC,eAAeN,kBAAkBO,MAAM;IAE7C,oFAAoF;IACpF,IAAID,gBAAgBF,aAAa;QAC/B,MAAMI,8BACJV,cAAcO,KAAK,GAAGD,eAAeN,cAAcS,MAAM,GAAGD;QAC9D,IAAIJ,uBAAuBO,aAAaD,6BAA6B;YACnE,OAAO,OAAO,yCAAyC;;QACzD;IACF;IAEA,IAAIN,uBAAuBO,aAAc,CAAA,CAACL,eAAe,CAACE,YAAW,GAAI;QACvE,IACE,AAACF,eAAeN,cAAcO,KAAK,GAAGD,eACrCE,gBAAgBR,cAAcS,MAAM,GAAGD,cACxC;YACA,OAAO;QACT;IACF;IAEA,MAAMI,6BACJZ,cAAcO,KAAK,GAAGD,eAAeN,cAAcS,MAAM,GAAGD;IAC9D,IAAIL,QAAQ,aAAaA,QAAQ,UAAU;QACzC,OAAO;IACT;IACA,IAAI,CAACN,SAASW,iBAAiB,CAACX,SAASS,cAAc;QACrD,OAAO;IACT;IAEA,MAAMO,oBAAoBP,cAAcE;IACxC,MAAMM,sBAAsBd,cAAcO,KAAK,GAAGP,cAAcS,MAAM;IACtE,IAAIK,wBAAwBD,mBAAmB;QAC7C,OAAO;IACT;IAEA,IAAIT,sBAAsBQ,4BAA4B;QACpD,OAAO;IACT;IACA,IAAIP,oBAAoB,CAACO,4BAA4B;QACnD,OAAO;IACT;IAEA,OAAOX,gBAAgB,yBAAyB;AAClD,EAAC"} |