Files
klz-cables.com/.pnpm-store/v10/files/2f/b1510427213d5a133995365c1117891c1744b3301f7aa4d51db81051a9ad05ff3f0eca9f3dd893255149786362cb9303ac2c62c12dc2ed7fe38df5be30e587
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

1 line
3.0 KiB
Plaintext

{"version":3,"sources":["../../src/utilities/getBestFitFromSizes.ts"],"sourcesContent":["/**\n * Takes image sizes and a target range and returns the url of the image within that range.\n * If no images fit within the range, it selects the next smallest adequate image, the original,\n * or the largest smaller image if no better fit exists.\n *\n * @param sizes The given FileSizes.\n * @param targetSizeMax The ideal image maximum width. Defaults to 180.\n * @param targetSizeMin The ideal image minimum width. Defaults to 40.\n * @param thumbnailURL The thumbnail url set in config. If passed a url, will return early with it.\n * @param url The url of the original file.\n * @param width The width of the original file.\n * @returns A url of the best fit file.\n */\nexport const getBestFitFromSizes = ({\n sizes,\n targetSizeMax = 180,\n targetSizeMin = 40,\n thumbnailURL,\n url,\n width,\n}: {\n sizes?: Record<string, { url?: string; width?: number }>\n targetSizeMax?: number\n targetSizeMin?: number\n thumbnailURL?: string\n url: string\n width?: number\n}) => {\n if (thumbnailURL) {\n return thumbnailURL\n }\n\n if (!sizes) {\n return url\n }\n\n const bestFit = Object.values(sizes).reduce<{\n original?: boolean\n url?: string\n width?: number\n }>(\n (closest, current) => {\n if (!current.width || current.width < targetSizeMin) {\n return closest\n }\n\n if (current.width >= targetSizeMin && current.width <= targetSizeMax) {\n return !closest.width ||\n current.width < closest.width ||\n closest.width < targetSizeMin ||\n closest.width > targetSizeMax\n ? current\n : closest\n }\n\n if (\n !closest.width ||\n (!closest.original && closest.width < targetSizeMin && current.width > closest.width) ||\n (closest.width > targetSizeMax && current.width < closest.width)\n ) {\n return current\n }\n\n return closest\n },\n { original: true, url, width },\n )\n\n return bestFit.url || url\n}\n"],"names":["getBestFitFromSizes","sizes","targetSizeMax","targetSizeMin","thumbnailURL","url","width","bestFit","Object","values","reduce","closest","current","original"],"mappings":"AAAA;;;;;;;;;;;;CAYC,GACD,OAAO,MAAMA,sBAAsB,CAAC,EAClCC,KAAK,EACLC,gBAAgB,GAAG,EACnBC,gBAAgB,EAAE,EAClBC,YAAY,EACZC,GAAG,EACHC,KAAK,EAQN;IACC,IAAIF,cAAc;QAChB,OAAOA;IACT;IAEA,IAAI,CAACH,OAAO;QACV,OAAOI;IACT;IAEA,MAAME,UAAUC,OAAOC,MAAM,CAACR,OAAOS,MAAM,CAKzC,CAACC,SAASC;QACR,IAAI,CAACA,QAAQN,KAAK,IAAIM,QAAQN,KAAK,GAAGH,eAAe;YACnD,OAAOQ;QACT;QAEA,IAAIC,QAAQN,KAAK,IAAIH,iBAAiBS,QAAQN,KAAK,IAAIJ,eAAe;YACpE,OAAO,CAACS,QAAQL,KAAK,IACnBM,QAAQN,KAAK,GAAGK,QAAQL,KAAK,IAC7BK,QAAQL,KAAK,GAAGH,iBAChBQ,QAAQL,KAAK,GAAGJ,gBACdU,UACAD;QACN;QAEA,IACE,CAACA,QAAQL,KAAK,IACb,CAACK,QAAQE,QAAQ,IAAIF,QAAQL,KAAK,GAAGH,iBAAiBS,QAAQN,KAAK,GAAGK,QAAQL,KAAK,IACnFK,QAAQL,KAAK,GAAGJ,iBAAiBU,QAAQN,KAAK,GAAGK,QAAQL,KAAK,EAC/D;YACA,OAAOM;QACT;QAEA,OAAOD;IACT,GACA;QAAEE,UAAU;QAAMR;QAAKC;IAAM;IAG/B,OAAOC,QAAQF,GAAG,IAAIA;AACxB,EAAC"}