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kU,GACpD","sources":["webpack://lange/../node_modules/@integrabeauty/assert/src/index.ts","webpack://lange/./lib/dom-ready.ts","webpack://lange/./sections/shoppable-videos/shoppable-video-player/index.ts","webpack://lange/./lib/video.ts","webpack://lange/./sections/shoppable-videos/index.ts"],"sourcesContent":["/**\n * Throws an assertion error if the given condition is falsy.\n *\n * @param expression any expression, although one that evaluates to true or false is preferred by\n * convention\n * @param message optional error text\n */\nexport function assert(expression: unknown, message?: string) {\n  if (!expression) {\n    throw new AssertionError(message);\n  }\n}\n\nexport class AssertionError extends Error {\n  constructor(message = 'Assertion error') {\n    super(message);\n    this.name = this.constructor.name;\n  }\n}\n","/**\n * Releases the handle returned from the ready() function.\n *\n * This is idempotent. Additional calls are pointless but harmless.\n */\nexport type ReleaseHandle = () => void;\n\n/**\n * A subset of events that pertain to document ready state.\n */\ntype LoadingEventMap = Pick<DocumentEventMap, 'DOMContentLoaded' | 'load'>;\n\n/**\n * Calls the provided callback when the document is ready. This works both when the document is\n * already ready and when it is not, so callers do not have to care. This exists because it ensures\n * that each caller consistently expresses its dependency on document readiness, and to save a bit\n * of boilerplate.\n *\n * A document is considered ready when it has been parsed. This corresponds to the ready state of\n * 'interactive'. When the document has been fully loaded, the ready state is 'complete'. The\n * callback runs either way, so callers do not have to check which one they are in.\n *\n * Ready means the html is parsed and the DOM is there to query. It does not mean the page's other\n * scripts have run. Deferred scripts and module scripts run after the ready state turns\n * 'interactive' and before DOMContentLoaded fires, so a callback here can run before them. When a\n * caller needs some other script to have run already, this is the wrong tool, and it should wait on\n * whatever that script produces instead.\n *\n * That remedy has a catch of its own when the calling bundle is loaded with async. An async bundle\n * can execute after DOMContentLoaded has already fired, so a plain listener for that event never\n * runs and the work silently never happens. Nothing here can detect that, because by the time this\n * file executes the event is long gone. Catching it needs something registered at parse time,\n * before any bundle loads.\n *\n * There is a second trap right next to that one, and it applies only when waiting for\n * DOMContentLoaded. The ready state stays 'interactive' after DOMContentLoaded has fired, all the\n * way until 'complete', so the ready state cannot tell you whether DOMContentLoaded is still coming\n * or has already gone. Waiting for load is not exposed to this, because the ready state turns\n * 'complete' and load fires in the same task, so seeing 'complete' means load has fired too.\n *\n * When the document is already ready, the callback is invoked via setTimeout. This way, if the\n * callback throws, the error surfaces to the global error handler in a way that is similar to what\n * happens when an event listener throws.\n *\n * We might one day want to move this to an NPM library.\n *\n * Beware of a quirk here. setTimeout yields, and the busier the frontend, the longer it takes to\n * fire. Page load is exactly when the frontend is busiest. The timeout is a floor and not a\n * guarantee, so there is no real bound on how long that yield lasts. What this means is that using\n * this library can introduce more delay than you might expect. Compare code that runs on async load\n * and checks ready state and invokes immediately to code that runs after setTimeout. The former\n * runs in the same tick, the latter runs in \"some later tick\". That later tick can be surprisingly\n * much later. That can cause initial paint issues.\n *\n * @see https://developer.mozilla.org/en-US/docs/Web/API/Document/readyState\n * @see https://developer.mozilla.org/en-US/docs/Web/API/Document/DOMContentLoaded_event\n * @see https://html.spec.whatwg.org/multipage/parsing.html#the-end\n */\nexport function ready(callback: (event?: Event) => void,\n  type: keyof LoadingEventMap = 'DOMContentLoaded') {\n  if (document.readyState === 'complete' || (type === 'DOMContentLoaded' &&\n    document.readyState === 'interactive')) {\n    const timer = setTimeout(callback, 0);\n    const handle: ReleaseHandle = () => clearTimeout(timer);\n    return handle;\n  } else {\n    addEventListener(type, callback);\n    const handle: ReleaseHandle = () => removeEventListener(type, callback);\n    return handle;\n  }\n}\n","import { assert } from '@integrabeauty/assert';\nimport type { CustomElement } from '@integrabeauty/custom-elements';\nimport { ready, type ReleaseHandle } from '../../../lib/dom-ready.js';\nimport { play } from '../../../lib/video.js';\nimport html from './index.html';\nimport styles from './index.scss';\n\ninterface ShoppableVideo {\n  affiliate_display_name: string;\n\n  alt: string | null;\n  aspect_ratio: number;\n\n  /**\n   * url to the .vtt captions file\n   */\n  captions: string;\n\n  /**\n   * millisecond duration of the video\n   */\n  duration: number;\n\n  /**\n   * ID of the video media\n   */\n  id: number;\n\n  /**\n   * type of media file, should be 'video'\n   */\n  media_type: string;\n  metaobject_handle: string;\n  metaobject_id: number;\n  metaobject_type: string;\n  metaobject_url: string | null;\n  position: null;\n\n  /**\n   * URL of the poster image of the video\n   */\n  preview_image: string;\n  primary_variant: {\n    id: number;\n\n    /**\n     * URL of the variant image, or null when the section could not resolve one\n     */\n    image: string | null;\n    options: string;\n    product_id: number;\n  };\n  products: {\n    /**\n     * URL of product image, or null when the section could not resolve one\n     */\n    featured_image: string | null;\n    handle: string;\n    id: number;\n    subtitle: string;\n    title: string;\n  }[];\n  sources: {\n    /**\n     * file type\n     *\n     * @example 'mp4'\n     */\n    format: string;\n    height: number;\n    mime_type: string;\n    url: string;\n    width: number;\n  }[];\n\n  /**\n   * metaobject handles are a snake case composite of metaobject type and a special ID. This field\n   * isolates only the id and strips out the metaobject type. it's an alphanumeric value.\n   *\n   * @example 'r1o6yxen'\n   */\n  video_id: string;\n}\n\ninterface VideoPlayState {\n  [id: string]: 'paused' | 'playing' | 'promise-to-play';\n}\n\n/**\n * A fullscreen feed of short videos, in the style of Instagram/TikTok.\n *\n * Each video has a carousel of the products it features. The tap to view product details of one of\n * the products in the carousel is why this is called \"shoppable\" as that is low friction.\n *\n * It shows as a modal whose open state and current video are tied to the URL and browser history.\n * That lets a shared or advertised link open straight to a specific video, and lets back and\n * forward navigation open, close, or switch the player to match.\n *\n * The video list is read from a JSON script on the page.\n *\n * The shopper moves between videos by keyboard, mouse, or touchscreen.\n *\n * As a video is watched it emits progress events at a few view milestones, which other code\n * consumes for analytics.\n *\n * The player shows and hides itself off `data-modal-state`. The player and its section's script ask\n * the modal manager to open or close it, and the manager sets that attribute.\n */\nclass ShoppableVideoPlayer extends HTMLElement implements CustomElement {\n  public static get observedAttributes() {\n    return [\n      'data-modal-state'\n    ];\n  }\n\n  declare readonly dataset: {\n    /**\n     * Whether the player is shown, as \"open\". Anything else, or no value at all, means closed.\n     *\n     * Set the video id first, since opening reads it to pick the video to play.\n     */\n    modalState: string;\n\n    /**\n     * Play the video with the specified id\n     */\n    videoId: string;\n  };\n\n  private declare videos: ShoppableVideo[];\n  private muted = false;\n  private paused = false;\n  private videoPlayState: VideoPlayState = {};\n  private watchedAnalyticsCache: { [id: string]: boolean; } = {};\n  private declare loaderTimer: ReturnType<typeof setTimeout>;\n  private declare scrollTimer: ReturnType<typeof setTimeout>;\n  private lastKnownScrollPosition = 0;\n  private lastKnownTouchPosition = 0;\n  private lastKnownProductScrollPosition = 0;\n\n  private videoWidth = 600;\n\n  private mouseDownOnProducts = false;\n\n  private onVideoEventBound = this.onVideoEvent.bind(this);\n  private onVideoClickBound = this.onVideoClick.bind(this);\n  private onTimeUpdateBound = this.onTimeUpdate.bind(this);\n  private onPlayClickBound = this.onPlayClick.bind(this);\n  private onCaptionCueChangeBound = this.onCaptionCueChange.bind(this);\n  private onCaptionsControlClickBound = this.onCaptionsControlClick.bind(this);\n  private onCloseClickBound = this.onCloseClick.bind(this);\n  private onMuteClickBound = this.onMuteClick.bind(this);\n  private onPreviousClickBound = this.onPreviousClick.bind(this);\n  private onNextClickBound = this.onNextClick.bind(this);\n  private onWheelBound = this.onWheel.bind(this);\n  private onTouchStartBound = this.onTouchStart.bind(this);\n  private onTouchMoveBound = this.onTouchMove.bind(this);\n  private onMouseDownBound = this.onMouseDown.bind(this);\n  private onMouseMoveBound = this.onMouseMove.bind(this);\n  private onProductMoveBound = this.onProductMove.bind(this);\n  private onProductsWheelBound = this.onProductsWheel.bind(this);\n  private onPopStateBound = this.onPopState.bind(this);\n  private onReadyBound = this.onReady.bind(this);\n  private onWindowResizeBound = this.onWindowResize.bind(this);\n  private onScreenChangeBound = this.onScreenChange.bind(this);\n  private onKeyboardEventBound = this.onKeyboardEvent.bind(this);\n  private onModalDismissRequestedBound = this.onModalDismissRequested.bind(this);\n  private declare releaseReady: ReleaseHandle;\n\n  public connectedCallback() {\n    this.initializeShadowRoot();\n\n    addEventListener('popstate', this.onPopStateBound);\n\n    this.releaseReady = ready(this.onReadyBound);\n\n    this.addEventListener('keydown', this.onKeyboardEventBound);\n    this.addEventListener('keyup', this.onKeyboardEventBound);\n\n    addEventListener('resize', this.onWindowResizeBound);\n    addEventListener('change', this.onScreenChangeBound);\n\n    this.init();\n  }\n\n  public disconnectedCallback() {\n    if (this.releaseReady) {\n      this.releaseReady();\n    }\n\n    removeEventListener('popstate', this.onPopStateBound);\n    removeEventListener('modal-dismiss-requested', this.onModalDismissRequestedBound);\n\n    const playEl = this.shadowRoot.getElementById('play');\n    playEl?.removeEventListener('click', this.onPlayClickBound);\n    playEl?.removeEventListener('mousedown', keepFocusOffOnMouseDown);\n\n    const closeEl = this.shadowRoot.getElementById('close');\n    closeEl?.removeEventListener('click', this.onCloseClickBound);\n\n    const muteEl = this.shadowRoot.getElementById('mute');\n    muteEl?.removeEventListener('click', this.onMuteClickBound);\n\n    const previousEl = this.shadowRoot.getElementById('previous');\n    previousEl?.removeEventListener('click', this.onPreviousClickBound);\n\n    const nextEl = this.shadowRoot.getElementById('next');\n    nextEl?.removeEventListener('click', this.onNextClickBound);\n\n    const videosEl = this.shadowRoot.querySelector<HTMLElement>('.videos');\n    videosEl?.removeEventListener('touchstart', this.onTouchStartBound);\n    videosEl?.removeEventListener('touchmove', this.onTouchMoveBound);\n    videosEl?.removeEventListener('mousedown', this.onMouseDownBound);\n    videosEl?.removeEventListener('mousemove', this.onMouseMoveBound);\n    videosEl?.removeEventListener('wheel', this.onWheelBound);\n\n    const captionsControlEl = this.shadowRoot.getElementById('captions-control');\n    captionsControlEl?.removeEventListener('click', this.onCaptionsControlClickBound);\n\n    this.removeEventListener('keydown', this.onKeyboardEventBound);\n    this.removeEventListener('keyup', this.onKeyboardEventBound);\n\n    removeEventListener('resize', this.onWindowResizeBound);\n    removeEventListener('change', this.onScreenChangeBound);\n\n    const videoEl = this.shadowRoot.querySelector<HTMLVideoElement>('.active video');\n    if (videoEl) {\n      this.removeVideoListeners(videoEl);\n    }\n\n    const productsEl = this.shadowRoot.querySelectorAll<HTMLElement>('.products.scrollable');\n    for (const productEl of productsEl) {\n      productEl.removeEventListener('wheel', this.onProductsWheelBound);\n    }\n  }\n\n  private initializeShadowRoot() {\n    if (!this.shadowRoot) {\n      this.attachShadow({ mode: 'open' });\n      this.shadowRoot.innerHTML = `<style>${styles}</style>${html}`;\n    }\n  }\n\n  private onKeyboardEvent(event: KeyboardEvent) {\n    if (event.type === 'keydown') {\n      return;\n    }\n\n    if (['ArrowLeft', 'ArrowUp'].includes(event.code)) {\n      this.navigateToVideo(false);\n    } else if (['ArrowRight', 'ArrowDown'].includes(event.code)) {\n      this.navigateToVideo(true);\n    }\n  }\n\n  /**\n   * Closes the player when the modal manager asks the open modal to dismiss, which it does on an\n   * escape key press. The player covers the backdrop, so a backdrop click cannot reach it. This\n   * listener is only attached while the player is open.\n   */\n  private onModalDismissRequested(_event: WindowEventMap['modal-dismiss-requested']) {\n    this.closePlayer();\n  }\n\n  private showPlayer() {\n    this.hidden = false;\n\n    const currentSection = this.closest('section');\n    if (currentSection instanceof HTMLElement) {\n      const carousel = currentSection.querySelector('carousel-element');\n\n      if (carousel instanceof HTMLElement) {\n        carousel.inert = true;\n      }\n    }\n\n    // put keyboard focus on the first interactive element\n    const closeButton = this.shadowRoot.querySelector<HTMLButtonElement>('#close');\n    closeButton.focus({ focusVisible: true });\n\n    addEventListener('modal-dismiss-requested', this.onModalDismissRequestedBound);\n  }\n\n  public attributeChangedCallback(name: string, oldValue: string, newValue: string) {\n    this.initializeShadowRoot();\n\n    if (!this.isConnected || name !== 'data-modal-state' || oldValue === newValue) {\n      return;\n    }\n\n    if (newValue === 'open') {\n      this.showPlayer();\n\n      if (!this.videos) {\n        this.init();\n      }\n\n      if (this.dataset.videoId) {\n        // close the player if there are no videos\n        if (this.videos.length === 0) {\n          this.closePlayer();\n          return;\n        }\n\n        let index = this.videos.findIndex(v => v.video_id === this.dataset.videoId);\n        if (index === -1) {\n          // If the video no longer exists (e.g., when a stale URL is shared or advertised), fall\n          // back to showing the first video\n          index = 0;\n        }\n\n        const videoId = this.videos[index].video_id;\n\n        this.activatePlayerAtIndex(index);\n        this.activateVideo(videoId);\n        this.updateVideoContainerWidth({ type: 'attributeChanged' });\n      }\n    } else if (oldValue === 'open') {\n      this.hidePlayer();\n    }\n  }\n\n  private activatePlayerAtIndex(index: number) {\n    let prevIndex = index - 1;\n    if (prevIndex < 0) {\n      prevIndex = this.videos.length - 1;\n    }\n\n    let nextIndex = index + 1;\n    if (nextIndex >= this.videos.length) {\n      nextIndex = 0;\n    }\n\n    const videosEl = this.shadowRoot.querySelector('.videos');\n    const currentVideo = this.createVideoWrapperElement(this.videos[index], index);\n    videosEl.appendChild(currentVideo);\n\n    if (nextIndex !== index) {\n      const nextVideo = this.createVideoWrapperElement(this.videos[nextIndex], nextIndex);\n      videosEl.appendChild(nextVideo);\n    }\n\n    if ((prevIndex !== index) && (prevIndex !== nextIndex)) {\n      // we add previous in the end to allow current to load first\n      const previousVideo = this.createVideoWrapperElement(this.videos[prevIndex], prevIndex);\n      videosEl.insertBefore(previousVideo, currentVideo);\n    }\n  }\n\n  private showLoader() {\n    clearTimeout(this.loaderTimer);\n    this.loaderTimer = setTimeout(() => {\n      const loader = this.shadowRoot.getElementById('loader');\n      loader?.classList.remove('display-hide');\n    }, 300);\n  }\n\n  private hideLoader() {\n    clearTimeout(this.loaderTimer);\n\n    const loader = this.shadowRoot.getElementById('loader');\n    loader?.classList.add('display-hide');\n  }\n\n  private activateVideo(id: string) {\n    assert(id, 'activate video invalid id');\n\n    // Since the onScroll method will activate videos on each event emitted, we must first check if\n    // that video ID is already active before proceeding.\n    const activeEl = this.shadowRoot.querySelector<HTMLElement>('.video.active');\n    if (activeEl?.dataset.id === id) {\n      return;\n    }\n\n    // On load there is no initially active video, so we must confirm the element was found\n    if (activeEl) {\n      activeEl.classList.remove('active');\n      const videoEl = activeEl.querySelector('video');\n      videoEl.pause();\n      videoEl.textTracks[0].mode = 'disabled';\n      this.videoPlayState[videoEl.parentElement.dataset.id] = 'paused';\n      videoEl.currentTime = 0;\n      this.removeVideoListeners(videoEl);\n\n      const products = videoEl.parentElement.querySelector<HTMLElement>('.products');\n      if (products) {\n        products.inert = true;\n      }\n    }\n\n    const targetVideoDiv = this.shadowRoot.querySelector(`[data-id=\"${id}\"]`);\n    if (!targetVideoDiv) {\n      return;\n    }\n\n    targetVideoDiv.classList.add('active');\n\n    // The progress bar is shared by every video, and only the active video's time updates move it.\n    // Without a reset it keeps the previous video's progress until the new one plays, and when the\n    // browser refuses to autoplay the new one, that leftover progress stays on screen.\n    this.updateProgress(0);\n\n    const targetProducts = targetVideoDiv.querySelector<HTMLElement>('.products');\n    if (targetProducts) {\n      targetProducts.inert = false;\n    }\n\n    const video = targetVideoDiv.querySelector('video');\n    this.addVideoListeners(video);\n    video.muted = this.muted;\n    video.textTracks[0].mode = 'showing';\n\n    if (this.dataset.videoId !== id) {\n      this.dataset.videoId = id;\n    }\n\n    updateUrlParamVideoId(id);\n    this.playVideo(video);\n  }\n\n  private navigateToVideo(forward: boolean) {\n    this.hideLoader();\n    const videos = this.shadowRoot.querySelector('.videos');\n    if (!videos) {\n      return;\n    }\n\n    const active = videos.querySelector<HTMLElement>('.video.active');\n    if (!active) {\n      return;\n    }\n\n    // Compute the index to which to navigate\n    let targetIndex = parseInt(active.dataset.index, 10) + (forward ? 1 : -1);\n\n    // Wrap around the index if out of bounds to achieve infinite looping.\n    if (forward) {\n      if (targetIndex >= this.videos.length) {\n        targetIndex = 0;\n      }\n    } else {\n      if (targetIndex < 0) {\n        targetIndex = this.videos.length - 1;\n      }\n    }\n\n    const target = videos.querySelector<HTMLElement>(`.video[data-index=\"${targetIndex}\"`);\n    this.activateVideo(target.dataset.id);\n\n    let addIndex = forward ? targetIndex + 1 : targetIndex - 1;\n    if (addIndex >= this.videos.length) {\n      addIndex = 0;\n    } else if (addIndex < 0) {\n      addIndex = this.videos.length - 1;\n    }\n\n    const toBeRemoved = forward ? videos.firstElementChild : videos.lastElementChild;\n    videos.removeChild(toBeRemoved);\n\n    let toBeAdded: Element;\n\n    if (toBeRemoved.classList.contains('active')) {\n      // if we have less than 4 videos, it can happen that the video to be removed is the active\n      // video; we need to add the active video back; it keeps the listeners and css classes\n      toBeAdded = toBeRemoved;\n    } else {\n      // create a new video element to be added\n      toBeAdded = this.createVideoWrapperElement(this.videos[addIndex], addIndex);\n    }\n\n    if (forward) {\n      videos.appendChild(toBeAdded);\n    } else {\n      videos.prepend(toBeAdded);\n    }\n  }\n\n  private onNextClick(_event: MouseEvent) {\n    this.navigateToVideo(true);\n  }\n\n  private onPreviousClick(_event: MouseEvent) {\n    this.navigateToVideo(false);\n  }\n\n  private onCaptionCueChange(_event: Event) {\n    const activeVideo = this.shadowRoot.querySelector<HTMLVideoElement>('.video.active video');\n    if (!activeVideo) {\n      return;\n    }\n\n    // Carefully obtain the cue. We have to be careful here because of poor browser support and\n    // strange situations where activeCues is undefined. We also have to hard cast the cue type from\n    // the base TextTrackCue type into the VTTCue subtype so as to gain access to the cue.text\n    // property. This hard cast is not safe.\n\n    let cue;\n    if (activeVideo.textTracks?.length > 0) {\n      const track = activeVideo.textTracks[0];\n      if (track?.activeCues?.length > 0) {\n        cue = <VTTCue>track.activeCues[0];\n      }\n    }\n\n    const captions = this.shadowRoot.querySelector('.video.active .captions');\n    captions.textContent = cue?.text || '';\n\n    if (cue?.text) {\n      captions.classList.remove('empty');\n    } else {\n      captions.classList.add('empty');\n    }\n  }\n\n  private onCaptionsControlClick(_event: MouseEvent) {\n    const captionsOffIcon = this.shadowRoot.getElementById('captions-off');\n    const captionsOnIcon = this.shadowRoot.getElementById('captions-on');\n    const videos = this.shadowRoot.querySelector('.videos');\n\n    // Toggle captions\n    if (videos.classList.contains('hide-captions')) {\n      captionsOffIcon.classList.add('display-hide');\n      captionsOnIcon.classList.remove('display-hide');\n      videos.classList.remove('hide-captions');\n      writeCaptionsEnabled(true);\n      this.setVideoStatus('Captions enabled');\n    } else {\n      captionsOffIcon.classList.remove('display-hide');\n      captionsOnIcon.classList.add('display-hide');\n      videos.classList.add('hide-captions');\n      writeCaptionsEnabled(false);\n      this.setVideoStatus('Captions disabled');\n    }\n  }\n\n  private onReady() {\n    if (!this.isConnected) {\n      return;\n    }\n\n    const playEl = this.shadowRoot.getElementById('play');\n    playEl.addEventListener('click', this.onPlayClickBound);\n    playEl.addEventListener('mousedown', keepFocusOffOnMouseDown);\n\n    const closeEl = this.shadowRoot.getElementById('close');\n    closeEl.addEventListener('click', this.onCloseClickBound);\n\n    const muteEl = this.shadowRoot.getElementById('mute');\n    muteEl.addEventListener('click', this.onMuteClickBound);\n\n    const previousEl = this.shadowRoot.getElementById('previous');\n    previousEl.addEventListener('click', this.onPreviousClickBound);\n\n    const nextEl = this.shadowRoot.getElementById('next');\n    nextEl.addEventListener('click', this.onNextClickBound);\n\n    const videosEl = this.shadowRoot.querySelector<HTMLElement>('.videos');\n    videosEl.addEventListener('touchstart', this.onTouchStartBound, { passive: true });\n    videosEl.addEventListener('touchmove', this.onTouchMoveBound, { passive: false });\n    videosEl.addEventListener('mousedown', this.onMouseDownBound);\n    videosEl.addEventListener('mousemove', this.onMouseMoveBound);\n    videosEl.addEventListener('wheel', this.onWheelBound, { passive: false });\n\n    const captionsControlEl = this.shadowRoot.getElementById('captions-control');\n    captionsControlEl.addEventListener('click', this.onCaptionsControlClickBound);\n\n    const captionsEnabled = readCaptionsEnabled();\n    if (captionsEnabled) {\n      const captionsOffIcon = this.shadowRoot.getElementById('captions-off');\n      const captionsOnIcon = this.shadowRoot.getElementById('captions-on');\n      const videos = this.shadowRoot.querySelector('.videos');\n\n      captionsOffIcon.classList.add('display-hide');\n      captionsOnIcon.classList.remove('display-hide');\n      videos.classList.remove('hide-captions');\n    }\n\n    this.updateIconPositions();\n  }\n\n  private onScreenChange(event: Event) {\n    this.updateVideoContainerWidth(event);\n    this.updateIconPositions();\n  }\n\n  private onWindowResize(event: Event) {\n    this.updateVideoContainerWidth(event);\n    this.updateIconPositions();\n  }\n\n  private updateVideoContainerWidth(event: Pick<Event, 'type'>) {\n    const width = Math.floor(innerHeight * 0.56);\n    if (innerWidth < 600) {\n      this.videoWidth = innerWidth;\n    } else if (width < 600) {\n      this.videoWidth = width;\n    } else {\n      this.videoWidth = 600;\n    }\n\n    const containerEl = this.shadowRoot.querySelector<HTMLElement>('.container');\n    containerEl.style.minWidth = `${this.videoWidth}px`;\n\n    const progressEl = this.shadowRoot.querySelector<HTMLElement>('.progress-bar');\n    progressEl.style.maxWidth = `${this.videoWidth}px`;\n\n    const productEl = this.shadowRoot.querySelector<HTMLElement>('.active .product.only-card');\n    if (productEl) {\n      productEl.style.width = `${this.videoWidth - 32}px`;\n    } else {\n      if (event.type === 'resize' || event.type === 'change') {\n        // do not log, this is normal, e.g. when resizing with devtools open\n      }\n    }\n\n    const captionsEl = this.shadowRoot.querySelector<HTMLElement>('.active .captions');\n    if (captionsEl) {\n      captionsEl.style.width = `${this.videoWidth - 32}px`;\n    } else {\n      if (event.type === 'resize' || event.type === 'change') {\n        // do not log, this is normal, e.g. when resizing with devtools open\n      }\n    }\n\n    const box = containerEl.getBoundingClientRect();\n    progressEl.style.left = `${box.left}px`;\n  }\n\n  private updateIconPositions() {\n    const closeEl = this.shadowRoot.getElementById('close');\n    const menuEl = this.shadowRoot.querySelector<HTMLElement>('.menu');\n\n    if (innerWidth > 767) {\n      const offset = (innerWidth - this.videoWidth) / 2 - 60;\n\n      closeEl.style.left = `${offset}px`;\n      menuEl.style.right = `${offset}px`;\n    } else {\n      closeEl.style.left = '16px';\n      menuEl.style.right = '16px';\n    }\n  }\n\n  private onPopState(_event: Event) {\n    const urlParams = new URLSearchParams(location.search);\n    const videoId = urlParams.get('video_id');\n    if (videoId) {\n      this.dataset.videoId = videoId;\n      this.requestOpen();\n    } else {\n      // Go through the modal manager rather than just hiding. Hiding on its own leaves the carousel\n      // inert and leaves the manager thinking a modal is still open, so the backdrop and the scroll\n      // lock stay up with nothing on screen to explain them.\n      this.closePlayer();\n    }\n  }\n\n  private onMouseDown(event: MouseEvent) {\n    const products = this.shadowRoot.querySelector<HTMLElement>('.active .products');\n    if (!products) {\n      return;\n    }\n\n    const bounds = products.getBoundingClientRect();\n\n    if (event.clientY > bounds.y && event.clientY < bounds.y + bounds.height &&\n      event.clientX > bounds.x && event.clientX < bounds.x + bounds.width) {\n      this.lastKnownTouchPosition = event.pageX - products.offsetLeft;\n      this.lastKnownProductScrollPosition = products.scrollLeft;\n      this.mouseDownOnProducts = true;\n\n      return;\n    }\n\n    this.mouseDownOnProducts = false;\n    this.lastKnownTouchPosition = event.clientY;\n  }\n\n  private onMouseMove(event: MouseEvent) {\n    if (event.buttons === 1 && this.mouseDownOnProducts) {\n      return;\n    }\n\n    if (this.mouseDownOnProducts && event.buttons !== 1) {\n      this.mouseDownOnProducts = false;\n    }\n\n    if (event.buttons !== 1 || (this.lastKnownTouchPosition === 0 && !this.mouseDownOnProducts)) {\n      return;\n    }\n\n    clearTimeout(this.scrollTimer);\n\n    this.scrollTimer = setTimeout(() => {\n      if (this.lastKnownTouchPosition < event.clientY) {\n        this.navigateToVideo(false);\n      } else if (this.lastKnownTouchPosition > event.clientY) {\n        this.navigateToVideo(true);\n      }\n\n      this.lastKnownScrollPosition = 0;\n      clearTimeout(this.scrollTimer);\n    }, 100);\n  }\n\n  private onProductMove(event: MouseEvent) {\n    if (event.buttons === 1 && this.mouseDownOnProducts) {\n      event.preventDefault();\n      const products = this.shadowRoot.querySelector<HTMLElement>('.active .products');\n      const x = event.pageX - products.offsetLeft;\n      const walk = (x - this.lastKnownTouchPosition) * 50;\n      const moveTo = this.lastKnownProductScrollPosition - walk;\n\n      products.scrollTo({\n        top: 0,\n        left: moveTo,\n        behavior: 'smooth'\n      });\n    }\n  }\n\n  private onTouchStart(event: TouchEvent) {\n    const products = this.shadowRoot.querySelector('.active .products');\n\n    // For unclear reasons this element is sometimes not found. In this case treat this as an in\n    // bounds touch and do nothing. This is not logged at the warning level because we do not care\n    // about error diagnostics for this error.\n    if (!products) {\n      console.log('active products element not found');\n      this.lastKnownTouchPosition = 0;\n      return;\n    }\n\n    const bounds = products.getBoundingClientRect();\n    if (event.touches[0].clientY > bounds.y &&\n      event.touches[0].clientY < bounds.y + bounds.height &&\n      event.touches[0].clientX > bounds.x &&\n      event.touches[0].clientX < bounds.x + bounds.width) {\n      this.lastKnownTouchPosition = 0;\n      return;\n    }\n\n    this.lastKnownTouchPosition = event.touches[0].clientY;\n  }\n\n  private onTouchMove(event: TouchEvent) {\n    if (this.lastKnownTouchPosition === 0) {\n      return;\n    }\n\n    clearTimeout(this.scrollTimer);\n\n    this.scrollTimer = setTimeout(() => {\n      if (this.lastKnownTouchPosition < event.touches[0].clientY) {\n        this.navigateToVideo(false);\n      } else if (this.lastKnownTouchPosition > event.touches[0].clientY) {\n        this.navigateToVideo(true);\n      }\n\n      this.lastKnownScrollPosition = 0;\n      clearTimeout(this.scrollTimer);\n    }, 100);\n  }\n\n  private isWheelEventInBounds(event: WheelEvent) {\n    const element = this.shadowRoot.querySelector('.active .products');\n    const rect = element.getBoundingClientRect();\n    return event.clientY > rect.y && event.clientY < rect.y + rect.height &&\n      event.clientX > rect.x && event.clientX < rect.x + rect.width;\n  }\n\n  private onWheel(event: WheelEvent) {\n    if (this.isWheelEventInBounds(event)) {\n      return;\n    }\n\n    event.preventDefault();\n    event.stopPropagation();\n\n    clearTimeout(this.scrollTimer);\n\n    if (!(event.target instanceof Element)) {\n      return;\n    }\n\n    if (this.lastKnownScrollPosition === 0) {\n      this.lastKnownScrollPosition = event.target.scrollTop;\n    }\n\n    this.scrollTimer = setTimeout(() => {\n      if (event.deltaY > 0) {\n        this.navigateToVideo(true);\n      } else if (event.deltaY < 0) {\n        this.navigateToVideo(false);\n      }\n\n      this.lastKnownScrollPosition = 0;\n      clearTimeout(this.scrollTimer);\n    }, 100);\n  }\n\n  private onProductsWheel(event: WheelEvent) {\n    if (!this.isWheelEventInBounds(event)) {\n      return;\n    }\n\n    event.preventDefault();\n    event.stopPropagation();\n\n    if (event.deltaY !== 0) {\n      const products = this.shadowRoot.querySelector('.active .products');\n      products.scrollLeft = products.scrollLeft - event.deltaY;\n    }\n  }\n\n  private playVideo(video: HTMLVideoElement) {\n    assert(video);\n\n    if (this.paused) {\n      this.renderPlayButton(false);\n      return;\n    }\n\n    this.renderPlayButton(true);\n\n    if (!video.paused) {\n      return;\n    }\n\n    if (this.hidden) {\n      return;\n    }\n\n    const id = video.parentElement.dataset.id;\n    const playState = this.videoPlayState[id];\n    if (playState && playState !== 'paused') {\n      return;\n    }\n\n    this.videoPlayState[id] = 'promise-to-play';\n\n    play(video)\n      .then(_ => {\n        this.videoPlayState[id] = 'playing';\n        this.setVideoStatus('Playing video ' + this.getVideoNumber(id));\n      })\n      .catch(error => {\n        this.videoPlayState[id] = video.paused || video.ended ?\n          'paused' :\n          undefined;\n\n        // Autoplay is best effort. Restrictive in-app browsers and low power mode refuse it even\n        // after a user gesture, and interrupted or unsupported sources reject too. None of it is\n        // actionable, so keep a debug breadcrumb and never warn.\n        console.debug(error);\n\n        // A refused start leaves the video sitting still with nothing to say why, so offer the play\n        // button for a tap to start it. iPhone Safari refuses a video with sound started from a\n        // swipe with a NotAllowedError. Only the video still on screen gets the button, since the\n        // one the visitor just swiped away from rejects too when the swipe pauses it.\n        if (video.paused && video.parentElement.classList.contains('active')) {\n          this.renderPlayButton(false);\n        }\n      });\n  }\n\n  /**\n   * Get the video number (1-based index) for the given video ID\n   *\n   * We do not have any titles or other identifiers for the videos, so we just use their position in\n   * the list when announcing which video is playing.\n   */\n  private getVideoNumber(id: string) {\n    const index = this.videos.findIndex(v => v.video_id === id);\n    return index + 1;\n  }\n\n  /**\n   * Sets the video status message for screen readers\n   */\n  private setVideoStatus(message: string) {\n    const statusEl = this.shadowRoot.getElementById('video-status');\n    if (statusEl) {\n      statusEl.textContent = message;\n    }\n  }\n\n  private onPlayClick(_event: MouseEvent) {\n    this.togglePlayback();\n  }\n\n  private onVideoClick(_event: MouseEvent) {\n    this.togglePlayback();\n  }\n\n  /**\n   * Plays the active video when it is paused and pauses it when it is playing. A click on the video\n   * and the play button, by mouse or by keyboard, both come here.\n   */\n  private togglePlayback() {\n    const video = this.shadowRoot.querySelector<HTMLVideoElement>('.active video');\n\n    if (video.paused) {\n      this.paused = false;\n      this.playVideo(video);\n    } else {\n      this.pauseVideo(video);\n    }\n  }\n\n  private pauseVideo(video: HTMLVideoElement) {\n    this.paused = true;\n    const videoId = video.parentElement.dataset.id;\n    video.pause();\n    this.videoPlayState[videoId] = 'paused';\n\n    this.setVideoStatus('Video paused');\n\n    this.renderPlayButton(false);\n  }\n\n  /**\n   * Switches the play button between pausing a playing video and playing a paused one. The\n   * stylesheet decides from data-playback which icon shows and when the button is out of sight.\n   */\n  private renderPlayButton(playing: boolean) {\n    const button = this.shadowRoot.getElementById('play');\n    button.dataset.playback = playing ? 'playing' : 'paused';\n    button.setAttribute('aria-label', playing ? 'Pause video' : 'Play video');\n  }\n\n  private onTimeUpdate(event: Event) {\n    const video = event.target;\n\n    if (!(video instanceof HTMLVideoElement)) {\n      return;\n    }\n\n    // iPhone Safari has sent a time update to a video with no parent after the player closed. Why\n    // the video lost its parent is not known.\n    if (!video.parentElement?.classList.contains('active')) {\n      return;\n    }\n\n    // Only the play and playing events switch the play button over to pausing, and only a short\n    // list of other video events hides the loader. Either one can still be put back on screen after\n    // those fire, such as by a late rejection of an interrupted play request, or a stalled event\n    // iPhone Safari sends on a video that keeps playing. Time updates keep firing while the video\n    // plays, so they clear whatever is left over.\n    if (!video.paused) {\n      this.hideLoader();\n      this.renderPlayButton(true);\n    }\n\n    const percentDuration = video.currentTime / video.duration * 100;\n    this.updateProgress(percentDuration);\n    this.trackViewMilestones(video.parentElement.dataset.id, percentDuration);\n  }\n\n  private updateProgress(percentDuration: number) {\n    const progress = this.shadowRoot.querySelector<HTMLElement>('.progress-value');\n    progress.style.width = percentDuration + '%';\n  }\n\n  /**\n   * Dispatches a viewed event the first time playback of a video passes each milestone. The 98\n   * percent milestone is cached under the key suffix 100.\n   */\n  private trackViewMilestones(id: string, percentDuration: number) {\n    const milestones = [\n      { key: `${id}_3`, reached: percentDuration > 3 },\n      { key: `${id}_50`, reached: percentDuration >= 50 },\n      { key: `${id}_100`, reached: percentDuration >= 98 }\n    ];\n\n    const videoObject = this.videos.find(video => video.video_id === id);\n\n    for (const milestone of milestones) {\n      if (this.watchedAnalyticsCache[milestone.key] || !milestone.reached) {\n        continue;\n      }\n\n      this.watchedAnalyticsCache[milestone.key] = true;\n\n      type Detail = WindowEventMap['shoppable-video-viewed']['detail'];\n      const viewEvent = new CustomEvent<Detail>('shoppable-video-viewed', {\n        bubbles: true,\n        composed: true,\n        detail: {\n          affiliate_display_name: videoObject.affiliate_display_name,\n          percent_viewed: percentDuration,\n          video_id: id\n        }\n      });\n      this.dispatchEvent(viewEvent);\n    }\n  }\n\n  private onMuteClick(_event: MouseEvent) {\n    const video = this.shadowRoot.querySelector<HTMLVideoElement>('.active video');\n    if (!video) {\n      return;\n    }\n\n    video.muted = !video.muted;\n    this.muted = video.muted;\n\n    const mute = this.shadowRoot.getElementById('mute');\n    if (video.muted) {\n      mute.querySelector('.volume-off').classList.remove('display-hide');\n      mute.querySelector('.volume-on').classList.add('display-hide');\n      this.setVideoStatus('Video muted');\n    } else {\n      mute.querySelector('.volume-off').classList.add('display-hide');\n      mute.querySelector('.volume-on').classList.remove('display-hide');\n      this.setVideoStatus('Video unmuted');\n    }\n  }\n\n  private onCloseClick(_event: MouseEvent) {\n    this.closePlayer();\n  }\n\n  private onVideoEvent(event: Event) {\n    if (event.type === 'play' || event.type === 'playing') {\n      this.hideLoader();\n      this.renderPlayButton(true);\n      return;\n    }\n\n    // The browser or the system can pause the video without going through the player, such as from\n    // a media key, the lock screen, or a call taking over the audio. The play button has to follow,\n    // and so does the play state we keep, since playVideo skips a video that state still says is\n    // playing, and the video would never start again. Only the active video counts, since switching\n    // videos pauses the one being left after it stops being active.\n    if (event.type === 'pause') {\n      const video = event.target;\n      if (video instanceof HTMLVideoElement && video.parentElement?.classList.contains('active')) {\n        this.videoPlayState[video.parentElement.dataset.id] = 'paused';\n        this.renderPlayButton(false);\n      }\n\n      return;\n    }\n\n    if (['waiting', 'error', 'stalled'].includes(event.type)) {\n      this.showLoader();\n    } else {\n      this.hideLoader();\n    }\n  }\n\n  private init() {\n    const mute = this.shadowRoot.getElementById('mute');\n    if (this.muted) {\n      mute.querySelector('.volume-off').classList.remove('display-hide');\n      mute.querySelector('.volume-on').classList.add('display-hide');\n    } else {\n      mute.querySelector('.volume-off').classList.add('display-hide');\n      mute.querySelector('.volume-on').classList.remove('display-hide');\n    }\n\n    // if already initialized do nothing\n    if (this.videos) {\n      return;\n    }\n\n    const scriptTag = document.getElementById('shoppable-video-data');\n    this.videos = <ShoppableVideo[]> JSON.parse(scriptTag.textContent);\n\n    for (const video of this.videos) {\n      this.videoPlayState[video.video_id] = 'paused';\n    }\n  }\n\n  /**\n   * Asks the modal manager to open the player. The manager sets our data-modal-state, which shows\n   * it.\n   */\n  private requestOpen() {\n    if (this.dataset.modalState === 'open') {\n      return;\n    }\n\n    const event = new Event('modal-open-requested', { bubbles: true, composed: true });\n    this.dispatchEvent(event);\n  }\n\n  private closePlayer() {\n    if (this.dataset.modalState !== 'open') {\n      return;\n    }\n\n    const event = new Event('modal-close-requested', { bubbles: true, composed: true });\n    this.dispatchEvent(event);\n  }\n\n  private hidePlayer() {\n    const id = this.dataset.videoId;\n\n    this.hidden = true;\n    this.dataset.videoId = '';\n\n    const videosEl = this.shadowRoot.querySelector('.videos');\n\n    // Emptying the list does not stop the videos or detach their listeners, so without this their\n    // events keep reaching the player after it closes.\n    for (const video of videosEl.querySelectorAll('video')) {\n      video.pause();\n      this.removeVideoListeners(video);\n    }\n\n    for (const track of videosEl.querySelectorAll('track')) {\n      track.removeEventListener('cuechange', this.onCaptionCueChangeBound);\n    }\n\n    for (const productsEl of videosEl.querySelectorAll<HTMLElement>('.products.scrollable')) {\n      productsEl.removeEventListener('wheel', this.onProductsWheelBound);\n    }\n\n    for (const productEl of videosEl.querySelectorAll<HTMLElement>('.product')) {\n      productEl.removeEventListener('mousemove', this.onProductMoveBound);\n    }\n\n    videosEl.innerHTML = '';\n    this.videoPlayState = {};\n\n    updateUrlParamVideoId();\n\n    type Detail = WindowEventMap['shoppable-video-player-closed']['detail'];\n    const event = new CustomEvent<Detail>('shoppable-video-player-closed', {\n      bubbles: true,\n      composed: true,\n      detail: { video_id: id }\n    });\n    this.dispatchEvent(event);\n\n    const currentSection = this.closest('section');\n    if (currentSection instanceof HTMLElement) {\n      const carousel = currentSection.querySelector('carousel-element');\n\n      if (carousel instanceof HTMLElement) {\n        carousel.inert = false;\n      }\n    }\n\n    removeEventListener('modal-dismiss-requested', this.onModalDismissRequestedBound);\n  }\n\n  /**\n   * @see https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/video#events\n   */\n  private createVideoWrapperElement(video: ShoppableVideo, index: number) {\n    const videoWrapperEl = document.createElement('div');\n    videoWrapperEl.classList.add('video');\n    videoWrapperEl.dataset.id = video.video_id;\n    videoWrapperEl.dataset.index = index.toString();\n\n    const videoEl = this.createVideoElement(video);\n    videoWrapperEl.append(videoEl);\n\n    const productsEl = this.createProductsCarousel(video);\n    videoWrapperEl.append(productsEl);\n\n    const captionsDiv = document.createElement('div');\n    captionsDiv.classList.add('captions');\n    captionsDiv.classList.add('empty');\n\n    videoWrapperEl.append(captionsDiv);\n\n    return videoWrapperEl;\n  }\n\n  private addVideoListeners(videoEl: HTMLVideoElement) {\n    videoEl.addEventListener('click', this.onVideoClickBound);\n    videoEl.addEventListener('timeupdate', this.onTimeUpdateBound);\n    videoEl.addEventListener('canplay', this.onVideoEventBound);\n    videoEl.addEventListener('canplaythrough', this.onVideoEventBound);\n    videoEl.addEventListener('error', this.onVideoEventBound);\n    videoEl.addEventListener('loadeddata', this.onVideoEventBound);\n    videoEl.addEventListener('loadedmetadata', this.onVideoEventBound);\n    videoEl.addEventListener('loadstart', this.onVideoEventBound);\n    videoEl.addEventListener('pause', this.onVideoEventBound);\n    videoEl.addEventListener('play', this.onVideoEventBound);\n    videoEl.addEventListener('playing', this.onVideoEventBound);\n    videoEl.addEventListener('ratechange', this.onVideoEventBound);\n    videoEl.addEventListener('stalled', this.onVideoEventBound);\n    videoEl.addEventListener('suspend', this.onVideoEventBound);\n    videoEl.addEventListener('waiting', this.onVideoEventBound);\n  }\n\n  private removeVideoListeners(videoEl: HTMLVideoElement) {\n    videoEl.removeEventListener('click', this.onVideoClickBound);\n    videoEl.removeEventListener('timeupdate', this.onTimeUpdateBound);\n    videoEl.removeEventListener('canplay', this.onVideoEventBound);\n    videoEl.removeEventListener('canplaythrough', this.onVideoEventBound);\n    videoEl.removeEventListener('error', this.onVideoEventBound);\n    videoEl.removeEventListener('loadeddata', this.onVideoEventBound);\n    videoEl.removeEventListener('loadedmetadata', this.onVideoEventBound);\n    videoEl.removeEventListener('loadstart', this.onVideoEventBound);\n    videoEl.removeEventListener('pause', this.onVideoEventBound);\n    videoEl.removeEventListener('play', this.onVideoEventBound);\n    videoEl.removeEventListener('playing', this.onVideoEventBound);\n    videoEl.removeEventListener('ratechange', this.onVideoEventBound);\n    videoEl.removeEventListener('stalled', this.onVideoEventBound);\n    videoEl.removeEventListener('suspend', this.onVideoEventBound);\n    videoEl.removeEventListener('waiting', this.onVideoEventBound);\n  }\n\n  private createVideoElement(video: ShoppableVideo) {\n    const videoEl = document.createElement('video');\n    videoEl.setAttribute('loop', 'loop');\n    videoEl.setAttribute('poster', video.preview_image);\n    videoEl.setAttribute('preload', 'auto');\n    videoEl.setAttribute('muted', '');\n    videoEl.setAttribute('playsinline', '');\n    videoEl.setAttribute('controlslist', 'nofullscreen');\n    videoEl.setAttribute('disablepictureinpicture', '');\n    videoEl.setAttribute('disableremoteplayback', '');\n\n    videoEl.controls = false;\n\n    const mp4Source = video.sources.find(source => source.mime_type === 'video/mp4');\n    if (mp4Source) {\n      videoEl.setAttribute('src', mp4Source.url);\n    }\n\n    const track = this.createTrackElement(video);\n    videoEl.append(track);\n\n    return videoEl;\n  }\n\n  private createTrackElement(video: ShoppableVideo) {\n    const track = document.createElement('track');\n    track.label = 'English';\n    track.kind = 'metadata';\n    track.srclang = 'en';\n    track.src = video.captions;\n    track.default = true;\n    track.addEventListener('cuechange', this.onCaptionCueChangeBound);\n    return track;\n  }\n\n  private createProductsCarousel(video: ShoppableVideo) {\n    const productsEl = document.createElement('div');\n    productsEl.classList.add('products');\n\n    // this will be cleared once the video becomes active\n    productsEl.inert = true;\n\n    if (video.products.length > 1) {\n      productsEl.classList.add('scrollable');\n      productsEl.addEventListener('wheel', this.onProductsWheelBound, { passive: false });\n    }\n\n    for (const product of video.products) {\n      const productEl = document.createElement('a');\n      productEl.classList.add('product');\n\n      // links and images can be dragged by default, which paints a translucent copy of the card\n      // while the user is trying to swipe the carousel sideways\n      productEl.draggable = false;\n\n      productEl.addEventListener('mousemove', this.onProductMoveBound);\n\n      const url = new URL(product.handle, location.origin);\n      if (video.primary_variant.product_id === product.id) {\n        url.searchParams.set('variant', video.primary_variant.id.toString());\n      }\n\n      productEl.href = url.toString();\n\n      let thumb = product.featured_image;\n      if (video.primary_variant.product_id === product.id) {\n        thumb = video.primary_variant.image;\n      }\n\n      const productImage = document.createElement('img');\n      // thumb is null when the section could not resolve a product image, so skip src rather than\n      // request /null\n      if (thumb) {\n        productImage.src = thumb;\n      }\n\n      productImage.alt = '';\n\n      // turning off drag on the link does not cover the image inside it\n      productImage.draggable = false;\n\n      productEl.append(productImage);\n\n      const titleEl = document.createElement('div');\n      titleEl.classList.add('title-subtitle');\n\n      let title = product.title;\n      if (video.primary_variant.product_id === product.id) {\n        title += ` ${video.primary_variant.options}`;\n      }\n\n      const productTitle = document.createElement('h2');\n      productTitle.innerHTML = title;\n\n      titleEl.appendChild(productTitle);\n\n      const productSubTitle = document.createElement('h3');\n      productSubTitle.textContent = product.subtitle;\n\n      titleEl.appendChild(productSubTitle);\n\n      productEl.append(titleEl);\n\n      productsEl.append(productEl);\n    }\n\n    return productsEl;\n  }\n}\n\nfunction readCaptionsEnabled() {\n  try {\n    return localStorage.getItem('video_captions_enabled') === 'true';\n  } catch (error) {\n    // ignore\n  }\n}\n\nfunction writeCaptionsEnabled(enabled: boolean) {\n  try {\n    localStorage.setItem('video_captions_enabled', enabled ? 'true' : 'false');\n  } catch (error) {\n    // ignore\n  }\n}\n\n/**\n * Either set or clear the video parameter id. There are both use cases to support. For example,\n * when closing the player we want to revert back to the url without the parameter in the url.\n */\nfunction updateUrlParamVideoId(videoId?: string) {\n  const url = new URL(location.href);\n  const data: Record<any, any> = {};\n\n  if (videoId) {\n    url.searchParams.set('video_id', videoId);\n    data.video_id = videoId;\n  } else {\n    url.searchParams.delete('video_id');\n  }\n\n  history.replaceState(data, '', url);\n}\n\ntype ShoppableVideoViewedEvent = CustomEvent<{\n  affiliate_display_name?: string;\n  percent_viewed?: number;\n  video_id: string;\n}>;\n\ntype ShoppableVideoPlayerClosedEvent = CustomEvent<{\n  video_id: string;\n}>;\n\n/**\n * Keeps a mouse click or a tap from focusing the play button, so only Tab ever does. Left focused\n * by a click, the button matches :focus-visible in Chrome as soon as any key is pressed, such as an\n * arrow to change videos, and the pause icon comes up over a playing video for someone who never\n * tabbed to it. The click itself still goes through.\n */\nfunction keepFocusOffOnMouseDown(event: MouseEvent) {\n  event.preventDefault();\n}\n\ndeclare global {\n  interface GlobalEventHandlersEventMap {\n    'shoppable-video-player-closed': ShoppableVideoPlayerClosedEvent;\n    'shoppable-video-viewed': ShoppableVideoViewedEvent;\n  }\n\n  interface HTMLElementTagNameMap {\n    'shoppable-video-player': ShoppableVideoPlayer;\n  }\n}\n\nif (!customElements.get('shoppable-video-player')) {\n  customElements.define('shoppable-video-player', ShoppableVideoPlayer);\n}\n","/**\n * Try to play a video, and always report the outcome as a promise.\n *\n * Do not inline this function. Playing a video is inconsistent across browsers in several ways, and\n * wrapping the call in an async function is what smooths all of them over at once.\n *\n * Some browsers have no `play` function on the element at all, so the call throws a TypeError. Some\n * have one that returns undefined instead of a promise, which is how `play` worked before the spec\n * gained a return value. Some return a promise that rejects later, which is the modern behavior and\n * is how a browser reports that it refused to autoplay. And some throw synchronously, right out of\n * the call, rather than rejecting.\n *\n * An async function turns all four into the same thing. Whatever happens inside it, the caller gets\n * a promise back, so a synchronous throw arrives as a rejection and a missing or non-promise `play`\n * still produces a promise that resolves. That means one `catch` on the call site covers every\n * failure mode, and the caller never has to check whether it got a promise before attaching a\n * handler.\n *\n * Nothing here is actionable, because a refusal is the browser enforcing its own autoplay policy.\n * Restrictive in-app browsers and low power mode refuse even after a user gesture, and interrupted\n * or unsupported sources reject too. The video simply stays paused, so callers should keep a debug\n * breadcrumb and never warn.\n */\nexport async function play(video: HTMLVideoElement) {\n  return video.play();\n}\n","import './shoppable-video-player/index.js';\nimport { ready } from '../../lib/dom-ready.js';\n\nfunction updateVideoId() {\n  const player = document.querySelector('shoppable-video-player');\n\n  // The player element is rendered by the same template that loads this script, so it should always\n  // be present here. In practice we see rare nulls in the wild on iOS Safari, most likely a\n  // navigation or bfcache teardown race firing this deferred handler against a document whose\n  // section subtree is momentarily gone. Guard rather than crash.\n\n  if (!player) {\n    return;\n  }\n\n  const params = new URLSearchParams(location.search);\n  const videoId = params.get('video_id');\n  if (videoId) {\n    player.dataset.videoId = videoId;\n    requestOpen(player);\n  } else {\n    player.dataset.videoId = '';\n  }\n}\n\n/**\n * Asks the modal manager to open the player. The manager sets the player's data-modal-state, which\n * shows it.\n */\nfunction requestOpen(player: HTMLElement) {\n  if (player.dataset.modalState === 'open') {\n    return;\n  }\n\n  const event = new Event('modal-open-requested', { bubbles: true, composed: true });\n  player.dispatchEvent(event);\n}\n\nfunction onSlideClicked(event: GlobalEventHandlersEventMap['carousel-slide-clicked']) {\n  const button = event.detail?.slide.querySelector('button');\n  if (!button?.dataset.videoId) {\n    return;\n  }\n\n  const focusEvent = new Event('focus-stack-push-requested', {\n    bubbles: true,\n    composed: true\n  });\n  button.dispatchEvent(focusEvent);\n\n  const player = document.querySelector('shoppable-video-player');\n  if (player) {\n    player.dataset.videoId = button.dataset.videoId;\n    requestOpen(player);\n  }\n}\n\n/**\n * After the player is closed, moves the carousel back to the slide with the video that was playing.\n */\nfunction onPlayerClosed(event: GlobalEventHandlersEventMap['shoppable-video-player-closed']) {\n  const carousel = document.querySelector<HTMLElement>('#shoppable-videos-carousel');\n  if (!carousel) {\n    return;\n  }\n\n  const videoId = event.detail.video_id;\n  const slides = carousel.querySelectorAll('[data-carousel-slide]');\n  for (const [index, slide] of slides.entries()) {\n    if (slide.querySelector(`[data-video-id=\"${videoId}\"]`)) {\n      carousel.dataset.go = index.toString();\n      return;\n    }\n  }\n}\n\nfunction onReady() {\n  updateVideoId();\n\n  const carousel = document.querySelector<HTMLElement>('#shoppable-videos-carousel');\n  if (!carousel) {\n    return;\n  }\n\n  carousel.addEventListener('carousel-slide-clicked', onSlideClicked);\n  addEventListener('shoppable-video-player-closed', onPlayerClosed);\n}\n\nready(onReady);\n"],"names":["assert","expression","message","AssertionError","Error","constructor","super","this","name","ready","callback","type","document","readyState","timer","setTimeout","clearTimeout","addEventListener","removeEventListener","ShoppableVideoPlayer","HTMLElement","observedAttributes","muted","paused","videoPlayState","watchedAnalyticsCache","lastKnownScrollPosition","lastKnownTouchPosition","lastKnownProductScrollPosition","videoWidth","mouseDownOnProducts","onVideoEventBound","onVideoEvent","bind","onVideoClickBound","onVideoClick","onTimeUpdateBound","onTimeUpdate","onPlayClickBound","onPlayClick","onCaptionCueChangeBound","onCaptionCueChange","onCaptionsControlClickBound","onCaptionsControlClick","onCloseClickBound","onCloseClick","onMuteClickBound","onMuteClick","onPreviousClickBound","onPreviousClick","onNextClickBound","onNextClick","onWheelBound","onWheel","onTouchStartBound","onTouchStart","onTouchMoveBound","onTouchMove","onMouseDownBound","onMouseDown","onMouseMoveBound","onMouseMove","onProductMoveBound","onProductMove","onProductsWheelBound","onProductsWheel","onPopStateBound","onPopState","onReadyBound","onReady","onWindowResizeBound","onWindowResize","onScreenChangeBound","onScreenChange","onKeyboardEventBound","onKeyboardEvent","onModalDismissRequestedBound","onModalDismissRequested","connectedCallback","initializeShadowRoot","releaseReady","init","disconnectedCallback","playEl","shadowRoot","getElementById","keepFocusOffOnMouseDown","closeEl","muteEl","previousEl","nextEl","videosEl","querySelector","captionsControlEl","videoEl","removeVideoListeners","productsEl","querySelectorAll","productEl","attachShadow","mode","innerHTML","event","includes","code","navigateToVideo","_event","closePlayer","showPlayer","hidden","currentSection","closest","carousel","inert","focus","focusVisible","attributeChangedCallback","oldValue","newValue","isConnected","videos","dataset","videoId","length","index","findIndex","v","video_id","activatePlayerAtIndex","activateVideo","updateVideoContainerWidth","hidePlayer","prevIndex","nextIndex","currentVideo","createVideoWrapperElement","appendChild","nextVideo","previousVideo","insertBefore","showLoader","loaderTimer","loader","classList","remove","hideLoader","add","id","activeEl","pause","textTracks","parentElement","currentTime","products","targetVideoDiv","updateProgress","targetProducts","video","addVideoListeners","updateUrlParamVideoId","playVideo","forward","active","targetIndex","parseInt","target","addIndex","toBeRemoved","firstElementChild","lastElementChild","toBeAdded","removeChild","contains","prepend","_activeVideo$textTrac","_cue","_cue2","activeVideo","cue","_track$activeCues","track","activeCues","captions","textContent","text","captionsOffIcon","captionsOnIcon","writeCaptionsEnabled","setVideoStatus","passive","localStorage","getItem","error","readCaptionsEnabled","updateIconPositions","width","Math","floor","innerHeight","innerWidth","containerEl","style","minWidth","progressEl","maxWidth","captionsEl","box","getBoundingClientRect","left","menuEl","offset","right","URLSearchParams","location","search","get","requestOpen","bounds","clientY","y","height","clientX","x","pageX","offsetLeft","scrollLeft","buttons","scrollTimer","preventDefault","walk","moveTo","scrollTo","top","behavior","console","log","touches","isWheelEventInBounds","rect","stopPropagation","Element","scrollTop","deltaY","renderPlayButton","playState","async","play","then","_","getVideoNumber","catch","ended","undefined","debug","statusEl","togglePlayback","pauseVideo","playing","button","playback","setAttribute","_video$parentElement","HTMLVideoElement","percentDuration","duration","trackViewMilestones","milestones","key","reached","videoObject","find","milestone","viewEvent","CustomEvent","bubbles","composed","detail","affiliate_display_name","percent_viewed","dispatchEvent","mute","_video$parentElement2","scriptTag","JSON","parse","modalState","Event","videoWrapperEl","createElement","toString","createVideoElement","append","createProductsCarousel","captionsDiv","preview_image","controls","mp4Source","sources","source","mime_type","url","createTrackElement","label","kind","srclang","src","default","product","draggable","URL","handle","origin","primary_variant","product_id","searchParams","set","href","thumb","featured_image","image","productImage","alt","titleEl","title","options","productTitle","productSubTitle","subtitle","enabled","setItem","data","delete","history","replaceState","player","onSlideClicked","_event$detail","slide","focusEvent","onPlayerClosed","slides","entries","go","customElements","define","updateVideoId"],"sourceRoot":""}