{"version":3,"file":"asImagePixelDensitySrcSet.cjs","sources":["../../src/asImagePixelDensitySrcSet.ts"],"sourcesContent":["import { ImageFieldImage } from \"@prismicio/types\";\nimport {\n\tbuildPixelDensitySrcSet,\n\tBuildPixelDensitySrcSetParams,\n\tbuildURL,\n} from \"imgix-url-builder\";\n\nimport { imageThumbnail as isImageThumbnailFilled } from \"./isFilled\";\n\n/**\n * The default pixel densities used to generate a `srcset` value.\n */\nconst DEFAULT_PIXEL_DENSITIES = [1, 2, 3];\n\n/**\n * Configuration for `asImagePixelDensitySrcSet()`.\n */\ntype AsImagePixelDensitySrcSetConfig = Omit<\n\tBuildPixelDensitySrcSetParams,\n\t\"pixelDensities\"\n> &\n\tPartial<Pick<BuildPixelDensitySrcSetParams, \"pixelDensities\">>;\n\n/**\n * The return type of `asImagePixelDensitySrcSet()`.\n */\ntype AsImagePixelDensitySrcSetReturnType<\n\tField extends ImageFieldImage | null | undefined,\n> = Field extends ImageFieldImage<\"filled\">\n\t? {\n\t\t\t/**\n\t\t\t * The Image field's image URL with Imgix URL parameters (if given).\n\t\t\t */\n\t\t\tsrc: string;\n\n\t\t\t/**\n\t\t\t * A pixel-densitye-based `srcset` attribute value for the Image field's\n\t\t\t * image with Imgix URL parameters (if given).\n\t\t\t */\n\t\t\tsrcset: string;\n\t  }\n\t: null;\n\n/**\n * Creates a pixel-density-based `srcset` from an Image field with optional\n * image transformations (via Imgix URL parameters).\n *\n * If a `pixelDensities` parameter is not given, the following pixel densities\n * will be used by default: 1, 2, 3.\n *\n * @example\n *\n * ```ts\n * const srcset = asImagePixelDensitySrcSet(document.data.imageField, {\n * \tpixelDensities: [1, 2],\n * \tsat: -100,\n * });\n * // => {\n * //   src:    'https://images.prismic.io/repo/image.png?sat=-100',\n * //   srcset: 'https://images.prismic.io/repo/image.png?sat=-100&dpr=1 1x, ' +\n * //           'https://images.prismic.io/repo/image.png?sat=-100&dpr=2 2x'\n * // }\n * ```\n *\n * @param field - Image field (or one of its responsive views) from which to get\n *   an image URL.\n * @param params - An object of Imgix URL API parameters. The `pixelDensities`\n *   parameter defines the resulting `srcset` widths.\n *\n * @returns A `srcset` attribute value for the Image field with Imgix URL\n *   parameters (if given). If the Image field is empty, `null` is returned.\n * @see Imgix URL parameters reference: https://docs.imgix.com/apis/rendering\n */\nexport const asImagePixelDensitySrcSet = <\n\tField extends ImageFieldImage | null | undefined,\n>(\n\tfield: Field,\n\tparams: 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 } = params;\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"],"names":["isImageThumbnailFilled","buildURL","buildPixelDensitySrcSet"],"mappings":";;;;AAYA,MAAM,0BAA0B,CAAC,GAAG,GAAG,CAAC;AA6DjC,MAAM,4BAA4B,CAGxC,OACA,SAA0C,OACK;AAC3C,MAAA,SAASA,wBAAuB,KAAK,GAAG;AAG3C,UAAM,EAAE,iBAAiB,yBAAyB,GAAG,gBAAgB;AAE9D,WAAA;AAAA,MACN,KAAKC,gBAAA,SAAS,MAAM,KAAK,WAAW;AAAA,MACpC,QAAQC,gBAAAA,wBAAwB,MAAM,KAAK;AAAA,QAC1C,GAAG;AAAA,QACH;AAAA,MAAA,CACA;AAAA,IAAA;AAAA,SAEI;AACC,WAAA;AAAA,EACP;AACF;;"}