{
  "version": 3,
  "sources": ["/cdn/shop/t/6/assets/overflow-list.js?v=46858356770684902511790720035"],
  "sourcesContent": ["import { ResizeNotifier } from '@theme/utilities';\nimport { DeclarativeShadowElement } from '@theme/component';\n\n/**\n * Event class for overflow minimum items updates\n * @extends {Event}\n */\nexport class OverflowMinimumEvent extends Event {\n  /**\n   * Creates a new OverflowMinimumEvent\n   * @param {boolean} minimumReached - Whether the minimum number of visible items has been reached\n   */\n  constructor(minimumReached) {\n    super('overflowMinimum', { bubbles: true });\n    this.detail = {\n      minimumReached,\n    };\n  }\n}\n\n/**\n * A custom element that wraps a list of items and moves them to an overflow slot when they don't fit.\n * This component is used in the header section and other areas.\n * @attr {string | null} minimum-items When set, the element enters a 'minimum-reached' state when visible items are at or below this number.\n * @example\n * <overflow-list minimum-items=\"2\">\n *   <!-- list items -->\n * </overflow-list>\n */\nexport class OverflowList extends DeclarativeShadowElement {\n  static get observedAttributes() {\n    return ['disabled', 'minimum-items'];\n  }\n\n  /**\n   * @param {string} name\n   * @param {string} oldValue\n   * @param {string} newValue\n   */\n  attributeChangedCallback(name, oldValue, newValue) {\n    if (name === 'disabled') {\n      if (newValue === 'true') {\n        this.#reset();\n      } else {\n        this.#reflowItems();\n      }\n    }\n  }\n\n  async connectedCallback() {\n    super.connectedCallback();\n\n    // Styles for dynamically injected <overflow-list> elements are async.\n    // We need to wait for them to be loaded before initializing the element to properly calculate the overflow.\n    await this.#waitForStyles();\n\n    this.#initialize();\n  }\n\n  #waitForStyles() {\n    /** @type {HTMLLinkElement | null | undefined} */\n    const styles = this.shadowRoot?.querySelector('link[rel=\"stylesheet\"]');\n\n    // No styles or styles are already loaded.\n    if (!styles || styles.sheet) {\n      return Promise.resolve();\n    }\n\n    return new Promise((resolve) => {\n      styles.addEventListener('load', resolve);\n    });\n  }\n\n  /**\n   * Initialize the element\n   */\n  #initialize() {\n    const { shadowRoot } = this;\n\n    if (!shadowRoot) throw new Error('Missing shadow root');\n\n    const defaultSlot = shadowRoot.querySelector('slot:not([name])');\n    const overflowSlot = shadowRoot.querySelector('slot[name=\"overflow\"]');\n    const moreSlot = shadowRoot.querySelector('slot[name=\"more\"]');\n    const overflow = shadowRoot.querySelector('[part=\"overflow\"]');\n    const list = shadowRoot.querySelector('[part=\"list\"]');\n    const placeholder = shadowRoot.querySelector('[part=\"placeholder\"]');\n\n    if (\n      !(defaultSlot instanceof HTMLSlotElement) ||\n      !(overflowSlot instanceof HTMLSlotElement) ||\n      !(moreSlot instanceof HTMLSlotElement) ||\n      !(overflow instanceof HTMLElement) ||\n      !(list instanceof HTMLUListElement) ||\n      !(placeholder instanceof HTMLLIElement)\n    ) {\n      throw new Error('Invalid element types in <OverflowList />');\n    }\n\n    this.#refs = {\n      defaultSlot,\n      overflowSlot,\n      moreSlot,\n      overflow,\n      list,\n      placeholder,\n    };\n\n    // Add event listener for reflow requests\n    this.addEventListener(\n      'reflow',\n      /** @param {CustomEvent<{lastVisibleElement?: HTMLElement}>} event */ (event) => {\n        this.#reflowItems(0, event.detail.lastVisibleElement);\n      }\n    );\n\n    // When <overflow-list> is dynamically injected, the browser doesn't remove its <template> automatically.\n    // In theory, we could get rid of it now, or in DeclarativeShadowElement, but that would invalidate the layout.\n    // Instead, we ignore it for now and remove it later on the first reflow.\n    const elements = defaultSlot.assignedElements().filter((element) => !(element instanceof HTMLTemplateElement));\n    const firstElement = elements[0];\n    const lastElement = elements[elements.length - 1];\n\n    // Observe the first and last elements to trigger a reflow when they are visible.\n    // That way we can get their height from the IntersectionObserver for free (without reflows).\n    if (firstElement) {\n      this.#intersectionObserver.observe(firstElement);\n    }\n    if (lastElement && lastElement !== firstElement) {\n      this.#intersectionObserver.observe(lastElement);\n    }\n  }\n\n  disconnectedCallback() {\n    this.#resizeObserver.disconnect();\n    this.#mutationObserver.disconnect();\n    this.#intersectionObserver.disconnect();\n  }\n\n  get schedule() {\n    return typeof Theme?.utilities?.scheduler?.schedule === 'function'\n      ? Theme.utilities.scheduler.schedule\n      : /** @param {FrameRequestCallback} callback */ (callback) =>\n          requestAnimationFrame(() => setTimeout(callback, 0));\n  }\n\n  #scheduled = false;\n\n  /**\n   * Get the minimum number of items before changing the minimum-reached state\n   * @returns {number | null}\n   */\n  get minimumItems() {\n    const value = this.getAttribute('minimum-items');\n    return value ? parseInt(value, 10) : null;\n  }\n\n  get overflowSlot() {\n    const { overflowSlot } = this.#refs;\n    return overflowSlot;\n  }\n\n  get defaultSlot() {\n    const { defaultSlot } = this.#refs;\n    return defaultSlot;\n  }\n\n  /**\n   * @param {IntersectionObserverEntry[]} entries\n   */\n  #handleIntersection = (entries) => {\n    const entry = entries[0];\n    if (entry?.isIntersecting) {\n      this.#intersectionObserver.disconnect();\n      setTimeout(() => {\n        // Remove the leftover <template> for dynamically injected <overflow-list> elements.\n        this.querySelector(':scope > template[shadowrootmode=\"open\"]')?.remove();\n        this.#reflowItems(entry.boundingClientRect.height);\n      }, 0);\n    }\n  };\n\n  /**\n   * @type {ResizeObserverCallback & MutationCallback}\n   */\n  #handleChange = () => {\n    if (this.#scheduled) return;\n\n    this.#scheduled = true;\n\n    requestAnimationFrame(() =>\n      setTimeout(() => {\n        this.#reflowItems();\n        this.#scheduled = false;\n      }, 0)\n    );\n  };\n\n  /**\n   * Move all items to the default slot.\n   */\n  #moveItemsToDefaultSlot() {\n    const { defaultSlot, overflowSlot } = this.#refs;\n\n    for (const element of overflowSlot.assignedElements()) {\n      if (element.slot !== defaultSlot.name) {\n        element.slot = defaultSlot.name;\n      }\n    }\n  }\n\n  /**\n   * Reset the list to its initial state and disconnect the observers.\n   */\n  #reset() {\n    const { list } = this.#refs;\n\n    this.#unobserveChanges();\n    this.#moveItemsToDefaultSlot();\n\n    list.style.removeProperty('height');\n    this.style.setProperty('--overflow-count', '0');\n  }\n\n  /**\n   * Sets the minimum-reached attribute and dispatches a custom event based on visible elements count\n   * @param {Element[]} visibleElements - The currently visible elements\n   */\n  #updateMinimumReached(visibleElements) {\n    if (this.minimumItems !== null) {\n      const minimumReached = visibleElements.length < this.minimumItems;\n\n      if (minimumReached) {\n        this.setAttribute('minimum-reached', '');\n      } else {\n        this.removeAttribute('minimum-reached');\n      }\n\n      this.dispatchEvent(new OverflowMinimumEvent(minimumReached));\n    }\n  }\n\n  /**\n   * Show all items in the list.\n   */\n  showAll() {\n    const { placeholder } = this.#refs;\n\n    placeholder.style.setProperty('width', '0');\n    placeholder.style.setProperty('display', 'none');\n    this.setAttribute('disabled', 'true');\n  }\n\n  /**\n   * Reflow items based on available space within the list.\n   * @param {number} [listHeight] Initial height of the list\n   * @param {HTMLElement | null} [lastVisibleElement] Optional element to place in last visible position\n   */\n  #reflowItems = (listHeight = 0, lastVisibleElement = null) => {\n    const { defaultSlot, overflowSlot, moreSlot, list, placeholder } = this.#refs;\n\n    this.#unobserveChanges();\n\n    // Reset all elements to the default slot so we can check which ones overflow.\n    this.#moveItemsToDefaultSlot();\n\n    const elements = defaultSlot.assignedElements();\n    const lastElement = elements[elements.length - 1];\n\n    if (!lastElement) {\n      this.#observeChanges();\n      return;\n    }\n\n    /** @type {Element[]} */\n    let visibleElements = [];\n    /** @type {Element[]} */\n    let overflowingElements = [];\n    let placeholderWidth = 0;\n    let hasOverflow = false;\n\n    if (listHeight > 0) {\n      list.style.setProperty('height', `${listHeight}px`);\n    }\n\n    // Enable flex-wrap so overflowing items break to the next line. This makes calculations easier.\n    list.style.setProperty('flex-wrap', 'wrap');\n    placeholder.hidden = true;\n\n    // Putting the \"More\" item (and lastVisibleElement, if provided) at the start of the list lets us see which items will fit on the same row.\n    moreSlot.style.setProperty('order', '-1');\n    moreSlot.hidden = false;\n\n    lastVisibleElement?.style.setProperty('order', '-1');\n\n    const moreSlotRect = moreSlot.getBoundingClientRect();\n\n    elements.forEach((element) => {\n      const elementRect = element.getBoundingClientRect();\n\n      if (elementRect.top > moreSlotRect.top) {\n        if (!overflowingElements.length) {\n          placeholderWidth = elementRect.width;\n        }\n\n        hasOverflow = true;\n        overflowingElements.push(element);\n      } else {\n        visibleElements.push(element);\n      }\n    });\n\n    if (hasOverflow) {\n      moreSlot.style.removeProperty('order');\n    }\n    lastVisibleElement?.style.removeProperty('order');\n\n    // Move the elements to the correct slot.\n    for (const element of elements) {\n      const targetSlot = overflowingElements.includes(element) ? overflowSlot.name : defaultSlot.name;\n      if (element.slot !== targetSlot) {\n        element.slot = targetSlot;\n      }\n    }\n\n    list.style.setProperty('counter-reset', `overflow-count ${overflowingElements.length}`);\n    this.style.setProperty('--overflow-count', `${overflowingElements.length}`);\n\n    // Adjust the \"More\" button visibility.\n    moreSlot.hidden = !hasOverflow;\n\n    if (hasOverflow) {\n      // Set the width and height of the placeholder so the list can grow if there is space.\n      placeholder.style.width = `${placeholderWidth}px`;\n      placeholder.hidden = false;\n    }\n\n    // Reset the overflow property since children elements may need to display outside the list (e.g. dropdowns, popovers).\n    list.style.setProperty('overflow', 'unset');\n\n    hasOverflow && this.#updateMinimumReached(visibleElements);\n\n    this.#observeChanges();\n  };\n\n  #observeChanges() {\n    this.#resizeObserver.observe(this);\n    this.#mutationObserver.observe(this, { childList: true });\n  }\n\n  #unobserveChanges() {\n    this.#resizeObserver.disconnect();\n    this.#mutationObserver.disconnect();\n  }\n\n  /**\n   * @type {{\n   *   defaultSlot: HTMLSlotElement;\n   *   overflowSlot: HTMLSlotElement;\n   *   moreSlot: HTMLSlotElement;\n   *   overflow: HTMLElement;\n   *   list: HTMLUListElement;\n   *   placeholder: HTMLLIElement;\n   * }}\n   */\n  #refs;\n\n  /**\n   * @type {ResizeObserver}\n   */\n  #resizeObserver = new ResizeNotifier(this.#handleChange);\n\n  /**\n   * @type {MutationObserver}\n   */\n  #mutationObserver = new MutationObserver(this.#handleChange);\n\n  #intersectionObserver = new IntersectionObserver(this.#handleIntersection, {\n    // Extend the root margin to around one more viewport of a typical mobile screen.\n    rootMargin: '640px 360px 640px 360px',\n  });\n}\n\nif (!customElements.get('overflow-list')) {\n  customElements.define('overflow-list', OverflowList);\n}\n"],
  "mappings": "AAAA,OAAS,mB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