{
  "version": 3,
  "sources": ["/cdn/shop/t/6/assets/section-renderer.js?cb=20260407-7"],
  "sourcesContent": ["import { morph } from '@theme/morph';\n\n/**\n * A class to re-render sections using the Section Rendering API\n */\nclass SectionRenderer {\n  /**\n   * The cache of section HTML\n   * @type {Map<string, string>}\n   */\n  #cache = new Map();\n\n  /**\n   * The abort controllers by section ID\n   * @type {Map<string, AbortController>}\n   */\n  #abortControllersBySectionId = new Map();\n\n  /**\n   * The pending promises\n   * @type {Map<string, Promise<string>>}\n   */\n  #pendingPromises = new Map();\n\n  constructor() {\n    window.addEventListener('load', this.#cachePageSections.bind(this));\n  }\n\n  /**\n   * Renders a section\n   * @param {string} sectionId - The section ID\n   * @param {Object} [options] - The options\n   * @param {boolean} [options.cache] - Whether to use the cache\n   * @param {URL} [options.url] - The URL to render the section from\n   * @returns {Promise<string>} The rendered section HTML\n   */\n  async renderSection(sectionId, options) {\n    const { cache = !Shopify.designMode } = options ?? {};\n    const { url } = options ?? {};\n    this.#abortPendingMorph(sectionId);\n\n    const abortController = new AbortController();\n    this.#abortControllersBySectionId.set(sectionId, abortController);\n\n    const sectionHTML = await this.getSectionHTML(sectionId, cache, url);\n\n    if (!abortController.signal.aborted) {\n      this.#abortControllersBySectionId.delete(sectionId);\n\n      morphSection(sectionId, sectionHTML);\n    }\n\n    return sectionHTML;\n  }\n\n  /**\n   * Aborts an existing morph for a section\n   * @param {string} sectionId - The section ID\n   */\n  #abortPendingMorph(sectionId) {\n    const existingAbortController = this.#abortControllersBySectionId.get(sectionId);\n    if (existingAbortController) {\n      existingAbortController.abort();\n    }\n  }\n\n  /**\n   * Gets the HTML for a section\n   * @param {string} sectionId - The section ID\n   * @param {boolean} useCache - Whether to use the cache\n   * @param {URL} url - The URL to render the section for\n   * @returns {Promise<string>} The rendered section HTML\n   */\n  async getSectionHTML(sectionId, useCache = true, url = new URL(window.location.href)) {\n    const sectionUrl = buildSectionRenderingURL(sectionId, url);\n\n    let pendingPromise = this.#pendingPromises.get(sectionUrl);\n    if (pendingPromise) return pendingPromise;\n\n    if (useCache) {\n      const cachedHTML = this.#cache.get(sectionUrl);\n\n      if (cachedHTML) return cachedHTML;\n    }\n\n    pendingPromise = fetch(sectionUrl).then((response) => {\n      return response.text();\n    });\n\n    this.#pendingPromises.set(sectionUrl, pendingPromise);\n\n    const sectionHTML = await pendingPromise;\n    this.#pendingPromises.delete(sectionUrl);\n\n    this.#cache.set(sectionUrl, sectionHTML);\n    return sectionHTML;\n  }\n\n  /**\n   * Caches the page sections\n   */\n  #cachePageSections() {\n    for (const section of document.querySelectorAll('.shopify-section')) {\n      const url = buildSectionRenderingURL(section.id);\n      if (this.#cache.get(url)) return;\n      if (containsShadowRoot(section)) return;\n\n      this.#cache.set(url, section.outerHTML);\n    }\n  }\n}\n\nconst SECTION_ID_PREFIX = 'shopify-section-';\n\n/**\n * Builds a section rendering URL\n * @param {string} sectionId - The section ID\n * @param {URL} url - The URL to render the section for\n * @returns {string} The section rendering URL\n */\nfunction buildSectionRenderingURL(sectionId, url = new URL(window.location.href)) {\n  url.searchParams.set('section_id', normalizeSectionId(sectionId));\n  url.searchParams.sort();\n\n  return url.toString();\n}\n\n/**\n * Builds a section selector\n * @param {string} sectionId - The section ID\n * @returns {string} The section selector\n */\nexport function buildSectionSelector(sectionId) {\n  return `${SECTION_ID_PREFIX}${sectionId}`;\n}\n\n/**\n * Normalizes a section ID\n * @param {string} sectionId - The section ID\n * @returns {string} The normalized section ID\n */\nexport function normalizeSectionId(sectionId) {\n  return sectionId.replace(new RegExp(`^${SECTION_ID_PREFIX}`), '');\n}\n\n/**\n * Checks if an element contains a shadow root\n * @param {Element} element - The element to check\n * @returns {boolean} Whether the element contains a shadow root\n */\nfunction containsShadowRoot(element) {\n  return !!element.shadowRoot || Array.from(element.children).some(containsShadowRoot);\n}\n\n/**\n * @typedef {(previousElement: HTMLElement, newElement: HTMLElement) => void} UpdateCallback\n */\n\n/**\n * Morphs the existing section element with the new section contents\n *\n * @param {string} sectionId - The section ID\n * @param {string} html - The new markup the section should morph into\n */\nexport async function morphSection(sectionId, html) {\n  const fragment = new DOMParser().parseFromString(html, 'text/html');\n  const existingElement = document.getElementById(buildSectionSelector(sectionId));\n  const newElement = fragment.getElementById(buildSectionSelector(sectionId));\n\n  if (!existingElement) {\n    throw new Error(`Section ${sectionId} not found`);\n  }\n\n  if (!newElement) {\n    throw new Error(`Section ${sectionId} not found in the section rendering response`);\n  }\n\n  morph(existingElement, newElement);\n}\n\nexport const sectionRenderer = new SectionRenderer();\n"],
  "mappings": "AAAA,OAAS,UAAa,eAKtB,MAAM,eAAgB,CAKpB,OAAS,IAAI,IAMb,6BAA+B,IAAI,IAMnC,iBAAmB,IAAI,IAEvB,aAAc,CACZ,OAAO,iBAAiB,OAAQ,KAAK,mBAAmB,KAAK,IAAI,CAAC,CACpE,CAUA,MAAM,cAAc,UAAW,QAAS,CACtC,KAAM,CAAE,MAAQ,CAAC,QAAQ,UAAW,EAAI,SAAW,CAAC,EAC9C,CAAE,GAAI,EAAI,SAAW,CAAC,EAC5B,KAAK,mBAAmB,SAAS,EAEjC,MAAM,gBAAkB,IAAI,gBAC5B,KAAK,6BAA6B,IAAI,UAAW,eAAe,EAEhE,MAAM,YAAc,MAAM,KAAK,eAAe,UAAW,MAAO,GAAG,EAEnE,OAAK,gBAAgB,OAAO,UAC1B,KAAK,6BAA6B,OAAO,SAAS,EAElD,aAAa,UAAW,WAAW,GAG9B,WACT,CAMA,mBAAmB,UAAW,CAC5B,MAAM,wBAA0B,KAAK,6BAA6B,IAAI,SAAS,EAC3E,yBACF,wBAAwB,MAAM,CAElC,CASA,MAAM,eAAe,UAAW,SAAW,GAAM,IAAM,IAAI,IAAI,OAAO,SAAS,IAAI,EAAG,CACpF,MAAM,WAAa,yBAAyB,UAAW,GAAG,EAE1D,IAAI,eAAiB,KAAK,iBAAiB,IAAI,UAAU,EACzD,GAAI,eAAgB,OAAO,eAE3B,GAAI,SAAU,CACZ,MAAM,WAAa,KAAK,OAAO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