{
  "version": 3,
  "sources": ["/cdn/shop/t/8/assets/header-menu.js?cb=1783080663716"],
  "sourcesContent": ["import { Component } from '@theme/component';\nimport { debounce, onDocumentLoaded, setHeaderMenuStyle } from '@theme/utilities';\nimport { MegaMenuHoverEvent } from '@theme/events';\n\n/**\n * A custom element that manages a header menu.\n *\n * @typedef {Object} State\n * @property {HTMLElement | null} activeItem - The currently active menu item.\n *\n * @typedef {object} Refs\n * @property {HTMLElement} overflowMenu - The overflow menu.\n * @property {HTMLElement[]} [submenu] - The submenu in each respective menu item.\n *\n * @extends {Component<Refs>}\n */\nclass HeaderMenu extends Component {\n  requiredRefs = ['overflowMenu'];\n\n  /**\n   * @type {MutationObserver | null}\n   */\n  #submenuMutationObserver = null;\n  #deactivateTimer = null;\n\n  connectedCallback() {\n    super.connectedCallback();\n\n    onDocumentLoaded(this.#preloadImages);\n    window.addEventListener('resize', this.#resizeListener);\n    this.overflowMenu?.addEventListener('pointerleave', this.#overflowSubmenuListener);\n  }\n\n  disconnectedCallback() {\n    super.disconnectedCallback();\n    window.removeEventListener('resize', this.#resizeListener);\n    this.overflowMenu?.removeEventListener('pointerleave', this.#overflowSubmenuListener);\n    this.#cleanupMutationObserver();\n  }\n\n  /**\n   * Debounced resize event listener to recalculate menu style\n   */\n  #resizeListener = debounce(() => {\n    setHeaderMenuStyle();\n  }, 100);\n\n\n  #overflowSubmenuListener = (event) => {\n    const menu = findSubmenu(this.#state.activeItem);\n    const isMovingToSubmenu = event.relatedTarget instanceof Node && menu?.contains(event.relatedTarget);\n    if (isMovingToSubmenu) return;\n    this.#deactivateTimer = setTimeout(() => this.#deactivate(), 150);\n  };\n\n  /**\n   * @type {State}\n   */\n  #state = {\n    activeItem: null,\n  };\n\n  /**\n   * Get the overflow menu\n   */\n  get overflowMenu() {\n    return /** @type {HTMLElement | null} */ (this.refs.overflowMenu?.shadowRoot?.querySelector('[part=\"overflow\"]'));\n  }\n\n  /**\n   * Whether the overflow list is hovered\n   * @returns {boolean}\n   */\n  get overflowListHovered() {\n    return this.refs.overflowMenu?.shadowRoot?.querySelector('[part=\"overflow-list\"]')?.matches(':hover') ?? false;\n  }\n\n  get headerComponent() {\n    return /** @type {HTMLElement | null} */ (this.closest('header-component'));\n  }\n\n  /**\n   * Activate the selected menu item immediately\n   * @param {PointerEvent | FocusEvent} event\n   */\n  activate = (event) => {\n    this.dispatchEvent(new MegaMenuHoverEvent());\n    clearTimeout(this.#deactivateTimer);\n\n    if (!(event.target instanceof Element) || !this.headerComponent) return;\n\n    let item = findMenuItem(event.target);\n\n    if (!item || item == this.#state.activeItem) return;\n\n    const isDefaultSlot = event.target.slot === '';\n\n    this.dataset.overflowExpanded = (!isDefaultSlot).toString();\n\n    const previouslyActiveItem = this.#state.activeItem;\n\n    if (previouslyActiveItem) {\n      previouslyActiveItem.ariaExpanded = 'false';\n    }\n\n    this.#state.activeItem = item;\n    this.ariaExpanded = 'true';\n    item.ariaExpanded = 'true';\n\n    let submenu = findSubmenu(item);\n    const hasSubmenu = Boolean(submenu);\n\n    if (!hasSubmenu && !isDefaultSlot) {\n      submenu = this.overflowMenu;\n    }\n\n    if (submenu) {\n      // Mark submenu as active for content-visibility optimization\n      submenu.dataset.active = '';\n\n      // Cleanup any existing mutation observer from previous menu activations\n      this.#cleanupMutationObserver();\n\n      // Monitor DOM mutations to catch deferred content injection (from section hydration)\n      this.#submenuMutationObserver = new MutationObserver(() => {\n        requestAnimationFrame(() => {\n          // Double requestAnimationFrame to ensure the height is properly calculated and not defaulting to the contain-intrinsic-size\n          requestAnimationFrame(() => {\n            if (submenu.offsetHeight > 0) {\n              this.headerComponent?.style.setProperty('--submenu-height', `${submenu.offsetHeight}px`);\n              this.#cleanupMutationObserver();\n            }\n          });\n        });\n      });\n      this.#submenuMutationObserver.observe(submenu, {childList: true, subtree: true});\n\n      // Auto-disconnect after 500ms to prevent memory leaks\n      setTimeout(() => {\n        this.#cleanupMutationObserver();\n      }, 500);\n    }\n\n    let finalHeight = submenu?.offsetHeight || 0;\n\n    // For overflow menu, the height needs to be either content of the submenu or the total height of the menu list links\n    if (!isDefaultSlot) {\n      const overflowListHeight = this.#getOverflowListLinksHeight();\n      if (hasSubmenu) {\n        /* Note: When the submenu is inside the overflow menu, its offsetHeight is not valid due to the lack of padding\n         * we could add the padding variables to the submenu.offsetHeight, but measuring the overflowMenu.offsetHeight is just easier */\n        const overflowHeight = this.overflowMenu?.offsetHeight || 0;\n        finalHeight = Math.max(overflowHeight, overflowListHeight);\n      } else {\n        finalHeight = overflowListHeight;\n      }\n    }\n\n    if (!submenu) {\n      // If there is no content to open, don't try to open it\n      finalHeight = 0;\n    }\n\n    this.headerComponent.style.setProperty('--submenu-height', `${finalHeight}px`);\n    this.#setFullOpenHeaderHeight(finalHeight);\n    this.style.setProperty('--submenu-opacity', '1');\n  };\n\n  /**\n   * Deactivate the active item after a delay\n   * @param {PointerEvent | FocusEvent} event\n   */\n  deactivate(event) {\n    if (!(event.target instanceof Element)) return;\n\n    const menu = findSubmenu(this.#state.activeItem);\n    const isMovingWithinMenu = event.relatedTarget instanceof Node && menu?.contains(document.activeElement);\n    const isMovingToSubmenu =\n      event.relatedTarget instanceof Node && menu?.contains(event.relatedTarget);\n    const isMovingToOverflowMenu =\n      event.relatedTarget instanceof Node && event.relatedTarget.parentElement?.matches('[slot=\"overflow\"]');\n\n    if (isMovingWithinMenu || isMovingToOverflowMenu || isMovingToSubmenu) return;\n\n        this.#deactivateTimer = setTimeout(() => this.#deactivate(), 150);\n  }\n\n  /**\n   * Deactivate the active item immediately\n   * @param {HTMLElement | null} [item]\n   */\n  #deactivate = (item = this.#state.activeItem) => {\n    clearTimeout(this.#deactivateTimer);\n    if (!item || item != this.#state.activeItem) return;\n\n    // Don't deactivate if the overflow menu or overflow list is still being hovered\n    if (this.overflowListHovered || this.overflowMenu?.matches(':hover')) return;\n\n    this.headerComponent?.style.setProperty('--submenu-height', '0px');\n    this.#setFullOpenHeaderHeight(0);\n    this.style.setProperty('--submenu-opacity', '0');\n    this.dataset.overflowExpanded = 'false';\n\n    const submenu = findSubmenu(item);\n\n    this.#state.activeItem = null;\n    this.ariaExpanded = 'false';\n    item.ariaExpanded = 'false';\n\n    // Remove active state from submenu after animation completes\n    if (submenu) {\n      delete submenu.dataset.active;\n    }\n  };\n\n  #getOverflowListLinksHeight() {\n    const slottedMenuLinks = this.overflowMenu?.querySelector('slot')?.assignedElements();\n    if (!slottedMenuLinks) return this.overflowMenu?.offsetHeight || 0;\n\n    /**\n     * @param {(submenu: HTMLElement) => void} cb\n     */\n    const mapSubmenus = (cb) => {\n      slottedMenuLinks.forEach((link) => {\n        const submenu = /** @type {HTMLElement | null} */ (link.querySelector('[ref=\"submenu[]\"]'));\n        if (submenu) {\n          cb(submenu);\n        }\n      });\n    }\n\n    mapSubmenus((submenu) => {\n      submenu.style.setProperty('display', 'none');\n    });\n    const height = this.overflowMenu?.offsetHeight || 0;\n    mapSubmenus((submenu) => {\n      submenu.style.removeProperty('display');\n    });\n    return height;\n  }\n\n  /**\n   * Calculate and set the full open header height. If the submenu is not open, the full open header height is 0.\n   * @param {number} submenuHeight\n   */\n  #setFullOpenHeaderHeight(submenuHeight) {\n    if (!this.headerComponent) return;\n\n    const isOverlapSituation = this.headerComponent.hasAttribute('data-submenu-overlap-bottom-row');\n\n    const headerVisibleHeight =\n      isOverlapSituation && this.headerComponent.offsetHeight > 0\n        ? /** @type {HTMLElement | null} */ (this.headerComponent.querySelector('.header__row--top'))?.offsetHeight ?? 0\n        : this.headerComponent.offsetHeight;\n\n    const nothingToOpen = submenuHeight === 0;\n    const fullOpenHeaderHeight = nothingToOpen ? 0 : submenuHeight + (headerVisibleHeight ?? 0);\n\n    this.headerComponent?.style.setProperty('--full-open-header-height', `${fullOpenHeaderHeight}px`);\n  }\n\n  /**\n   * Preload images that are set to load lazily.\n   */\n  #preloadImages = () => {\n    const images = this.querySelectorAll('img[loading=\"lazy\"]');\n    images?.forEach((image) => image.removeAttribute('loading'));\n  };\n\n  #cleanupMutationObserver() {\n    this.#submenuMutationObserver?.disconnect();\n    this.#submenuMutationObserver = null;\n  }\n}\n\nif (!customElements.get('header-menu')) {\n  customElements.define('header-menu', HeaderMenu);\n}\n\n/**\n * Find the closest menu item.\n * @param {Element | null | undefined} element\n * @returns {HTMLElement | null}\n */\nfunction findMenuItem(element) {\n  if (!(element instanceof Element)) return null;\n\n  if (element?.matches('[slot=\"more\"')) {\n    // Select the first overflowing menu item when hovering over the \"More\" item\n    return findMenuItem(element.parentElement?.querySelector('[slot=\"overflow\"]'));\n  }\n\n  return element?.querySelector('[ref=\"menuitem\"]');\n}\n\n/**\n * Find the closest submenu.\n * @param {Element | null | undefined} element\n * @returns {HTMLElement | null}\n */\nfunction findSubmenu(element) {\n  const submenu = element?.parentElement?.querySelector('[ref=\"submenu[]\"]');\n  return submenu instanceof HTMLElement ? submenu : null;\n}\n"],
  "mappings": "AAAA,OAAS,cAAiB,mBAC1B,OAAS,SAAU,iBAAkB,uBAA0B,mBAC/D,OAAS,uBAA0B,gBAcnC,MAAM,mBAAmB,SAAU,CACjC,aAAe,CAAC,cAAc,EAK9B,yBAA2B,KAC3B,iBAAmB,KAEnB,mBAAoB,CAClB,MAAM,kBAAkB,EAExB,iBAAiB,KAAK,cAAc,EACpC,OAAO,iBAAiB,SAAU,KAAK,eAAe,EACtD,KAAK,cAAc,iBAAiB,eAAgB,KAAK,wBAAwB,CACnF,CAEA,sBAAuB,CACrB,MAAM,qBAAqB,EAC3B,OAAO,oBAAoB,SAAU,KAAK,eAAe,EACzD,KAAK,cAAc,oBAAoB,eAAgB,KAAK,wBAAwB,EACpF,KAAK,yBAAyB,CAChC,CAKA,gBAAkB,SAAS,IAAM,CAC/B,mBAAmB,CACrB,EAAG,GAAG,EAGN,yBAA4B,OAAU,CACpC,MAAM,KAAO,YAAY,KAAK,OAAO,UAAU,EACrB,MAAM,yBAAyB,MAAQ,MAAM,SAAS,MAAM,aAAa,IAEnG,KAAK,iBAAmB,WAAW,IAAM,KAAK,YAAY,E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