{"version":3,"file":"Video.mjs","sources":["../../src/Video.tsx"],"sourcesContent":["import {type HTMLAttributes} from 'react';\nimport {shopifyImageLoader} from './image-size.js';\nimport type {Video as VideoType} from './storefront-api-types.js';\nimport type {PartialDeep} from 'type-fest';\n\nexport interface VideoProps {\n  /** An object with fields that correspond to the Storefront API's [Video object](https://shopify.dev/api/storefront/latest/objects/video). */\n  data: PartialDeep<VideoType, {recurseIntoArrays: true}>;\n  /** An object of image size options for the video's `previewImage`. Uses `shopifyImageLoader` to generate the `poster` URL. */\n  previewImageOptions?: Parameters<typeof shopifyImageLoader>[0];\n  /** Props that will be passed to the `video` element's `source` children elements. */\n  sourceProps?: HTMLAttributes<HTMLSourceElement> & {\n    'data-testid'?: string;\n  };\n}\n\n/**\n * The `Video` component renders a `video` for the Storefront API's [Video object](https://shopify.dev/api/storefront/reference/products/video).\n */\nexport function Video(props: JSX.IntrinsicElements['video'] & VideoProps) {\n  const {\n    data,\n    previewImageOptions,\n    id = data.id,\n    playsInline = true,\n    controls = true,\n    sourceProps = {},\n    ...passthroughProps\n  } = props;\n\n  const posterUrl = shopifyImageLoader({\n    src: data.previewImage?.url ?? '',\n    ...previewImageOptions,\n  });\n\n  if (!data.sources) {\n    throw new Error(`<Video/> requires a 'data.sources' array`);\n  }\n\n  return (\n    // eslint-disable-next-line jsx-a11y/media-has-caption\n    <video\n      {...passthroughProps}\n      id={id}\n      playsInline={playsInline}\n      controls={controls}\n      poster={posterUrl}\n    >\n      {data.sources.map((source) => {\n        if (!(source?.url && source?.mimeType)) {\n          throw new Error(`<Video/> needs 'source.url' and 'source.mimeType'`);\n        }\n        return (\n          <source\n            {...sourceProps}\n            key={source.url}\n            src={source.url}\n            type={source.mimeType}\n          />\n        );\n      })}\n    </video>\n  );\n}\n"],"names":["Video","props","data","previewImageOptions","id","playsInline","controls","sourceProps","passthroughProps","posterUrl","shopifyImageLoader","src","previewImage","url","sources","Error","map","source","mimeType"],"mappings":";;;AAmBO,SAASA,MAAMC,OAAoD;;AAClE,QAAA;AAAA,IACJC;AAAAA,IACAC;AAAAA,IACAC,KAAKF,KAAKE;AAAAA,IACVC,cAAc;AAAA,IACdC,WAAW;AAAA,IACXC,cAAc,CANV;AAAA,OAODC;AAAAA,EACDP,IAAAA;AAEJ,QAAMQ,YAAYC,mBAAmB;AAAA,IACnCC,MAAKT,gBAAKU,iBAALV,mBAAmBW,QAAnBX,YAA0B;AAAA,IAC/B,GAAGC;AAAAA,EAAAA,CAF+B;AAKhC,MAAA,CAACD,KAAKY,SAAS;AACX,UAAA,IAAIC,MAAO,0CAAX;AAAA,EACP;AAED,6BAEE,SAAA;AAAA,IAAA,GACMP;AAAAA,IACJ;AAAA,IACA;AAAA,IACA;AAAA,IACA,QAAQC;AAAAA,IALV,UAOGP,KAAKY,QAAQE,IAAKC,CAAW,WAAA;AAC5B,UAAI,GAAEA,iCAAQJ,SAAOI,iCAAQC,YAAW;AAChC,cAAA,IAAIH,MAAO,mDAAX;AAAA,MACP;AACD;WAEQR;AAAAA,QACJ,KAAKU,OAAOJ;AAAAA,QACZ,KAAKI,OAAOJ;AAAAA,QACZ,MAAMI,OAAOC;AAAAA,MAAAA,CALjB;AAAA,IAAA,CAJD;AAAA,EAAA,CAPH;AAsBH;"}