{"version":3,"file":"asImageSrc.cjs","names":["isImageThumbnailFilled"],"sources":["../../src/helpers/asImageSrc.ts"],"sourcesContent":["import type { ImgixURLParams } from \"imgix-url-builder\"\nimport { buildURL } from \"imgix-url-builder\"\n\nimport type { ImageFieldImage } from \"../types/value/image\"\nimport { imageThumbnail as isImageThumbnailFilled } from \"./isFilled\"\n\n/** The return type of `asImageSrc()`. */\ntype AsImageSrcReturnType<Field extends ImageFieldImage | null | undefined> =\n\tField extends ImageFieldImage<\"filled\"> ? string : null\n\n/**\n * Returns the URL of an image field with optional image transformations via imgix URL parameters.\n *\n * @example\n * \t;```ts\n * \tconst src = asImageSrc(document.data.photo, { sat: -100 })\n * \t// => \"https://images.prismic.io/repo/image.png?sat=-100\"\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 to transform the image.\n * @returns The image field's URL with transformations applied, or `null` if the\n * 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 asImageSrc = <Field extends ImageFieldImage | null | undefined>(\n\tfield: Field,\n\tconfig: ImgixURLParams = {},\n): AsImageSrcReturnType<Field> => {\n\tif (field && isImageThumbnailFilled(field)) {\n\t\treturn buildURL(field.url, config) as AsImageSrcReturnType<Field>\n\t} else {\n\t\treturn null as AsImageSrcReturnType<Field>\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AA0BA,MAAa,cACZ,OACA,SAAyB,EAAE,KACM;AACjC,KAAI,SAASA,iBAAAA,eAAuB,MAAM,CACzC,SAAA,GAAA,kBAAA,UAAgB,MAAM,KAAK,OAAO;KAElC,QAAO"}