{"version":3,"file":"ExternalVideo.cjs","sources":["../../src/ExternalVideo.tsx"],"sourcesContent":["import {useMemo} from 'react';\nimport type {ExternalVideo as ExternalVideoType} from './storefront-api-types.js';\nimport type {PartialDeep} from 'type-fest';\n\ninterface BaseProps {\n  /**\n   * An object with fields that correspond to the Storefront API's [ExternalVideo object](https://shopify.dev/api/storefront/reference/products/externalvideo).\n   */\n  data: PartialDeep<ExternalVideoType>;\n  /** An object containing the options available for either\n   * [YouTube](https://developers.google.com/youtube/player_parameters#Parameters) or\n   * [Vimeo](https://vimeo.zendesk.com/hc/en-us/articles/360001494447-Using-Player-Parameters).\n   */\n  options?: YouTube | Vimeo;\n}\n\ntype PropsWeControl = 'src';\n\nexport type ExternalVideoProps = Omit<\n  JSX.IntrinsicElements['iframe'],\n  PropsWeControl\n> &\n  BaseProps;\n\n/**\n * The `ExternalVideo` component renders an embedded video for the Storefront\n * API's [ExternalVideo object](https://shopify.dev/api/storefront/reference/products/externalvideo).\n */\nexport function ExternalVideo(props: ExternalVideoProps) {\n  const {\n    data,\n    options,\n    id = data.id,\n    frameBorder = '0',\n    allow = 'accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture',\n    allowFullScreen = true,\n    loading = 'lazy',\n    ...passthroughProps\n  } = props;\n\n  if (!data.embedUrl) {\n    throw new Error(`<ExternalVideo/> requires the 'embedUrl' property`);\n  }\n\n  const url = useEmbeddedVideoUrl(data.embedUrl, options);\n\n  return (\n    <iframe\n      {...passthroughProps}\n      id={id ?? data.embedUrl}\n      frameBorder={frameBorder}\n      allow={allow}\n      allowFullScreen={allowFullScreen}\n      src={url}\n      loading={loading}\n    ></iframe>\n  );\n}\n\ninterface YouTube {\n  autoplay?: 0 | 1;\n  cc_lang_pref?: string;\n  cc_load_policy?: 1;\n  color?: 'red' | 'white';\n  controls?: 0 | 1;\n  disablekb?: 0 | 1;\n  enablejsapi?: 0 | 1;\n  end?: number;\n  fs?: 0 | 1;\n  hl?: string;\n  iv_load_policy?: 1 | 3;\n  list?: string;\n  list_type?: 'playlist' | 'user_uploads';\n  loop?: 0 | 1;\n  modest_branding?: 1;\n  origin?: string;\n  playlist?: string;\n  plays_inline?: 0 | 1;\n  rel?: 0 | 1;\n  start?: number;\n  widget_referrer?: string;\n}\n\ntype VimeoBoolean = 0 | 1 | boolean;\n\ninterface Vimeo {\n  autopause?: VimeoBoolean;\n  autoplay?: VimeoBoolean;\n  background?: VimeoBoolean;\n  byline?: VimeoBoolean;\n  color?: string;\n  controls?: VimeoBoolean;\n  dnt?: VimeoBoolean;\n  loop?: VimeoBoolean;\n  muted?: VimeoBoolean;\n  pip?: VimeoBoolean;\n  playsinline?: VimeoBoolean;\n  portrait?: VimeoBoolean;\n  quality?: '240p' | '360p' | '540p' | '720p' | '1080p' | '2k' | '4k';\n  speed?: VimeoBoolean;\n  '#t'?: string;\n  texttrack?: string;\n  title?: VimeoBoolean;\n  transparent?: VimeoBoolean;\n}\n\nexport function useEmbeddedVideoUrl(url: string, parameters?: YouTube | Vimeo) {\n  return useMemo(() => {\n    if (!parameters) {\n      return url;\n    }\n\n    return addParametersToEmbeddedVideoUrl(url, parameters);\n  }, [url, parameters]);\n}\n\nexport function addParametersToEmbeddedVideoUrl(\n  url: string,\n  parameters?: YouTube | Vimeo\n) {\n  if (parameters == null) {\n    return url;\n  }\n\n  const params = Object.keys(parameters).reduce((accumulator, param) => {\n    // @ts-expect-error This needs to be fixed when we migrate components from hydrogen to here.\n    const value = parameters[param];\n    if (value == null) {\n      return accumulator;\n    }\n\n    return accumulator + `&${param}=${value}`;\n  }, '');\n\n  return `${url}?${params}`;\n}\n"],"names":["ExternalVideo","props","data","options","id","frameBorder","allow","allowFullScreen","loading","passthroughProps","embedUrl","Error","url","useEmbeddedVideoUrl","parameters","useMemo","addParametersToEmbeddedVideoUrl","params","Object","keys","reduce","accumulator","param","value"],"mappings":";;;;AA4BO,SAASA,cAAcC,OAA2B;AACjD,QAAA;AAAA,IACJC;AAAAA,IACAC;AAAAA,IACAC,KAAKF,KAAKE;AAAAA,IACVC,cAAc;AAAA,IACdC,QAAQ;AAAA,IACRC,kBAAkB;AAAA,IAClBC,UAAU;AAAA,OACPC;AAAAA,EACDR,IAAAA;AAEA,MAAA,CAACC,KAAKQ,UAAU;AACZ,UAAA,IAAIC,MAAO,mDAAX;AAAA,EACP;AAED,QAAMC,MAAMC,oBAAoBX,KAAKQ,UAAUP,OAAhB;AAE/B;OAEQM;AAAAA,IACJ,IAAIL,kBAAMF,KAAKQ;AAAAA,IACf;AAAA,IACA;AAAA,IACA;AAAA,IACA,KAAKE;AAAAA,IACL;AAAA,EAAA,CARJ;AAWD;AAiDeC,SAAAA,oBAAoBD,KAAaE,YAA8B;AAC7E,SAAOC,cAAQ,MAAM;AACnB,QAAI,CAACD,YAAY;AACRF,aAAAA;AAAAA,IACR;AAEMI,WAAAA,gCAAgCJ,KAAKE,UAAN;AAAA,EAAA,GACrC,CAACF,KAAKE,UAAN,CANW;AAOf;AAEeE,SAAAA,gCACdJ,KACAE,YACA;AACA,MAAIA,cAAc,MAAM;AACfF,WAAAA;AAAAA,EACR;AAEKK,QAAAA,SAASC,OAAOC,KAAKL,UAAZ,EAAwBM,OAAO,CAACC,aAAaC,UAAU;AAEpE,UAAMC,QAAQT,WAAWQ;AACzB,QAAIC,SAAS,MAAM;AACVF,aAAAA;AAAAA,IACR;AAEMA,WAAAA,cAAe,IAAGC,SAASC;AAAAA,KACjC,EARY;AAUf,SAAQ,GAAEX,OAAOK;AAClB;;;;"}