{
  "version": 3,
  "sources": ["/cdn/shop/t/26/assets/media-gallery.js?u=0.0570629471768495661784441952633"],
  "sourcesContent": ["import { Component } from '@theme/component';\nimport { ThemeEvents, VariantUpdateEvent, ZoomMediaSelectedEvent } from '@theme/events';\n\n/**\n * A custom element that renders a media gallery.\n *\n * @typedef {object} Refs\n * @property {import('./zoom-dialog').ZoomDialog} [zoomDialogComponent] - The zoom dialog component.\n * @property {import('./slideshow').Slideshow} [slideshow] - The slideshow component.\n * @property {HTMLElement[]} [media] - The media elements.\n *\n * @extends Component<Refs>\n */\nexport class MediaGallery extends Component {\n  connectedCallback() {\n    super.connectedCallback();\n\n    const { signal } = this.#controller;\n    const target = this.closest('.shopify-section, dialog');\n\n    target?.addEventListener(ThemeEvents.variantUpdate, this.#handleVariantUpdate, { signal });\n    this.refs.zoomDialogComponent?.addEventListener(ThemeEvents.zoomMediaSelected, this.#handleZoomMediaSelected, {\n      signal,\n    });\n  }\n\n  #controller = new AbortController();\n\n  disconnectedCallback() {\n    super.disconnectedCallback();\n\n    this.#controller.abort();\n  }\n\n  /**\n   * Handles a variant update event by replacing the current media gallery with a new one.\n   *\n   * @param {VariantUpdateEvent} event - The variant update event.\n   */\n  #handleVariantUpdate = (event) => {\n    const source = event.detail.data.html;\n\n    if (!source) return;\n    const newMediaGallery = source.querySelector('media-gallery');\n\n    if (!newMediaGallery) return;\n\n    // On an actual variant change (never on initial page load) point the incoming slideshow at the\n    // selected variant's media so the main image swaps to it. Composite-hero products (e.g. bundles)\n    // open on the hero; other PDPs may map a variant to any slide index.\n    const variantMediaId = event.detail.resource?.featured_media?.id;\n    let targetIndex = -1;\n    if (variantMediaId != null) {\n      const slideshow = newMediaGallery.querySelector('slideshow-component');\n      if (slideshow) {\n        const slides = Array.from(slideshow.querySelectorAll('slideshow-slide'));\n        targetIndex = slides.findIndex((slide) => slide.querySelector(`[data-media-id=\"${variantMediaId}\"]`));\n        if (targetIndex >= 0) slideshow.setAttribute('initial-slide', String(targetIndex));\n      }\n    }\n\n    this.replaceWith(newMediaGallery);\n\n    // Setting initial-slide alone does NOT move the main image to a non-zero slide: Slideshow's\n    // #setupSlideshow pre-sets `current` to initial-slide, so Slideshow#select then early-returns on\n    // its `currentSlide === requestedSlide` guard before it can scroll the viewport. The result is the\n    // thumbnail highlights the variant's slide but the main image stays on slide 0. So once the\n    // reconnected slideshow's scroller is ready, reset `current` and select to force the actual scroll.\n    if (targetIndex > 0) {\n      const slideshow = newMediaGallery.querySelector('slideshow-component');\n      let attempts = 0;\n      const forceSelect = () => {\n        if (!slideshow || attempts++ > 60) return;\n        const { scroller, slides } = slideshow.refs ?? {};\n        if (!scroller || !slides?.length) {\n          requestAnimationFrame(forceSelect);\n          return;\n        }\n        slideshow.current = 0;\n        slideshow.select(targetIndex, undefined, { animate: false });\n        // select() early-returns (leaving `current` unchanged at 0) until the slideshow's internal\n        // scroller is ready. Once it takes effect it sets current = targetIndex and starts the scroll\n        // (which settles asynchronously) \u2014 so retry only while it hasn't taken yet, and never re-fire\n        // afterwards, or we'd restart the in-progress scroll every frame and it would never land.\n        if (slideshow.current !== targetIndex) requestAnimationFrame(forceSelect);\n      };\n      requestAnimationFrame(forceSelect);\n    }\n  };\n\n  /**\n   * Handles the 'zoom-media:selected' event.\n   * @param {ZoomMediaSelectedEvent} event - The zoom-media:selected event.\n   */\n  #handleZoomMediaSelected = async (event) => {\n    this.slideshow?.select(event.detail.index, undefined, { animate: false });\n  };\n\n  /**\n   * Zooms the media gallery.\n   *\n   * @param {number} index - The index of the media to zoom.\n   * @param {PointerEvent} event - The pointer event.\n   */\n  zoom(index, event) {\n    this.refs.zoomDialogComponent?.open(index, event);\n  }\n\n  /**\n   * Preloads an image.\n   * @param {number} index - The index of the media to preload.\n   */\n  preloadImage(index) {\n    const zoomDialogMedia = this.refs.zoomDialogComponent?.refs.media[index];\n    if (!zoomDialogMedia) return;\n\n    this.refs.zoomDialogComponent?.loadHighResolutionImage(zoomDialogMedia);\n  }\n\n  get slideshow() {\n    return this.refs.slideshow;\n  }\n\n  get media() {\n    return this.refs.media;\n  }\n\n  get presentation() {\n    return this.dataset.presentation;\n  }\n}\n\nif (!customElements.get('media-gallery')) {\n  customElements.define('media-gallery', MediaGallery);\n}\n"],
  "mappings": "AAAA,OAAS,cAAiB,mBAC1B,OAAS,gBAA+D,gBAYjE,aAAM,qBAAqB,SAAU,CAC1C,mBAAoB,CAClB,MAAM,kBAAkB,EAExB,KAAM,CAAE,MAAO,EAAI,KAAK,YACT,KAAK,QAAQ,0BAA0B,GAE9C,iBAAiB,YAAY,cAAe,KAAK,qBAAsB,CAAE,MAAO,CAAC,EACzF,KAAK,KAAK,qBAAqB,iBAAiB,YAAY,kBAAmB,KAAK,yBAA0B,CAC5G,MACF,CAAC,CACH,CAEA,YAAc,IAAI,gBAElB,sBAAuB,CACrB,MAAM,qBAAqB,EAE3B,KAAK,YAAY,MAAM,CACzB,CAOA,qBAAwB,OAAU,CAChC,MAAM,OAAS,MAAM,OAAO,KAAK,KAEjC,GAAI,CAAC,OAAQ,OACb,MAAM,gBAAkB,OAAO,cAAc,eAAe,EAE5D,GAAI,CAAC,gBAAiB,OAKtB,MAAM,eAAiB,MAAM,OAAO,UAAU,gBAAgB,GAC9D,IAAI,YAAc,GAClB,GAAI,gBAAkB,KAAM,CAC1B,MAAM,UAAY,gBAAgB,cAAc,qBAAqB,EACjE,YAEF,YADe,MAAM,KAAK,UAAU,iBAAiB,iBAAiB,CAAC,EAClD,UAAW,OAAU,MAAM,cAAc,mBAAmB,cAAc,IAAI,CAAC,EAChG,aAAe,GAAG,UAAU,aAAa,gBAAiB,OAAO,WAAW,CAAC,EAErF,CASA,GAPA,KAAK,YAAY,eAAe,EAO5B,YAAc,EAAG,CACnB,MAAM,UAAY,gBAAgB,cAAc,qBAAqB,EACrE,IAAI,SAAW,EACf,MAAM,YAAc,IAAM,CACxB,GAAI,CAAC,WAAa,WAAa,GAAI,OACnC,KAAM,CAAE,SAAU,MAAO,EAAI,UAAU,MAAQ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