UNPKG

@prismicio/client

Version:

The official JavaScript + TypeScript client library for Prismic

46 lines (45 loc) 1.62 kB
"use strict"; Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" }); const imgixUrlBuilder = require("imgix-url-builder"); const isFilled = require("./isFilled.cjs"); const DEFAULT_WIDTHS = [640, 828, 1200, 2048, 3840]; const asImageWidthSrcSet = (field, config = {}) => { if (field && isFilled.imageThumbnail(field)) { let { widths = DEFAULT_WIDTHS, // eslint-disable-next-line prefer-const ...imgixParams } = config; const { url, dimensions, id: _id, alt: _alt, copyright: _copyright, edit: _edit, ...responsiveViews } = field; const responsiveViewObjects = Object.values(responsiveViews); if (widths === "thumbnails" && responsiveViewObjects.length < 1) { widths = DEFAULT_WIDTHS; } return { src: imgixUrlBuilder.buildURL(url, imgixParams), srcset: ( // By this point, we know `widths` can only be // `"thubmanils"` if the field has thumbnails. widths === "thumbnails" ? [ imgixUrlBuilder.buildWidthSrcSet(url, { ...imgixParams, widths: [dimensions.width] }), ...responsiveViewObjects.map((thumbnail) => { return imgixUrlBuilder.buildWidthSrcSet(thumbnail.url, { ...imgixParams, widths: [thumbnail.dimensions.width] }); }) ].join(", ") : imgixUrlBuilder.buildWidthSrcSet(field.url, { ...imgixParams, widths }) ) }; } else { return null; } }; exports.asImageWidthSrcSet = asImageWidthSrcSet; //# sourceMappingURL=asImageWidthSrcSet.cjs.map