{"version":3,"file":"asImagePixelDensitySrcSet.cjs","names":["isImageThumbnailFilled"],"sources":["../../src/helpers/asImagePixelDensitySrcSet.ts"],"sourcesContent":["import type { BuildPixelDensitySrcSetParams } from \"imgix-url-builder\"\nimport { buildPixelDensitySrcSet, buildURL } from \"imgix-url-builder\"\n\nimport type { ImageFieldImage } from \"../types/value/image\"\nimport { imageThumbnail as isImageThumbnailFilled } from \"./isFilled\"\n\n/** The default pixel densities used to generate a `srcset` value. */\nconst DEFAULT_PIXEL_DENSITIES = [1, 2, 3]\n\n/** Configuration for `asImagePixelDensitySrcSet()`. */\ntype AsImagePixelDensitySrcSetConfig = Omit<BuildPixelDensitySrcSetParams, \"pixelDensities\"> &\n\tPartial<Pick<BuildPixelDensitySrcSetParams, \"pixelDensities\">>\n\n/** The return type of `asImagePixelDensitySrcSet()`. */\ntype AsImagePixelDensitySrcSetReturnType<Field extends ImageFieldImage | null | undefined> =\n\tField extends ImageFieldImage<\"filled\">\n\t\t? {\n\t\t\t\t/** The image field's URL with imgix URL parameters (if given). */\n\t\t\t\tsrc: string\n\n\t\t\t\t/**\n\t\t\t\t * A pixel-density-based `srcset` attribute value for the image field with imgix URL\n\t\t\t\t * parameters (if given).\n\t\t\t\t */\n\t\t\t\tsrcset: string\n\t\t\t}\n\t\t: null\n\n/**\n * Creates a pixel-density-based `srcset` from an image field with optional image transformations\n * via imgix URL parameters.\n *\n * If a `pixelDensities` parameter is not given, the following pixel densities will be used by\n * default: 1, 2, 3.\n *\n * @example\n * \t;```ts\n * \tconst srcset = asImagePixelDensitySrcSet(document.data.photo, {\n * \t\tpixelDensities: [1, 2],\n * \t\tsat: -100,\n * \t})\n * \t// => {\n * \t//   src: \"https://images.prismic.io/repo/image.png?sat=-100\",\n * \t//   srcset: \"https://images.prismic.io/repo/image.png?sat=-100&dpr=1 1x, \" +\n * \t//           \"https://images.prismic.io/repo/image.png?sat=-100&dpr=2 2x\"\n * \t// }\n * \t```\n *\n * @param field - An image field (or one of its responsive views) from which to get an image URL.\n * @param config - An object of imgix URL API parameters. The `pixelDensities` parameter defines the\n *   resulting `srcset` pixel densities.\n * @returns A `srcset` attribute value for the image field with imgix URL parameters, or `null` if\n *   the field is empty.\n * @see Learn how to optimize images with imgix: {@link https://prismic.io/docs/fields/image}\n * @see imgix URL parameters reference: {@link https://docs.imgix.com/apis/rendering}\n */\nexport const asImagePixelDensitySrcSet = <Field extends ImageFieldImage | null | undefined>(\n\tfield: Field,\n\tconfig: AsImagePixelDensitySrcSetConfig = {},\n): AsImagePixelDensitySrcSetReturnType<Field> => {\n\tif (field && isImageThumbnailFilled(field)) {\n\t\t// We are using destructuring to omit `pixelDensities` from the\n\t\t// object we will pass to `buildURL()`.\n\t\tconst { pixelDensities = DEFAULT_PIXEL_DENSITIES, ...imgixParams } = config\n\n\t\treturn {\n\t\t\tsrc: buildURL(field.url, imgixParams),\n\t\t\tsrcset: buildPixelDensitySrcSet(field.url, {\n\t\t\t\t...imgixParams,\n\t\t\t\tpixelDensities,\n\t\t\t}),\n\t\t} as AsImagePixelDensitySrcSetReturnType<Field>\n\t} else {\n\t\treturn null as AsImagePixelDensitySrcSetReturnType<Field>\n\t}\n}\n"],"mappings":";;;;AAOA,MAAM,0BAA0B;CAAC;CAAG;CAAG;CAAE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiDzC,MAAa,6BACZ,OACA,SAA0C,EAAE,KACI;AAChD,KAAI,SAASA,iBAAAA,eAAuB,MAAM,EAAE;EAG3C,MAAM,EAAE,iBAAiB,yBAAyB,GAAG,gBAAgB;AAErE,SAAO;GACN,MAAA,GAAA,kBAAA,UAAc,MAAM,KAAK,YAAY;GACrC,SAAA,GAAA,kBAAA,yBAAgC,MAAM,KAAK;IAC1C,GAAG;IACH;IACA,CAAC;GACF;OAED,QAAO"}