{
  "version": 3,
  "sources": ["/cdn/shop/t/8/assets/header-menu.js?vsype=yfmwt"],
  "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\n  connectedCallback() {\n    super.connectedCallback();\n\n    this.overflowMenu?.addEventListener('pointerleave', () => this.#deactivate());\n    // on load, cache the max height of the submenu so you can use it in a translate\n    this.#cacheMaxOverflowMenuHeight();\n\n    onDocumentLoaded(this.#preloadImages);\n    window.addEventListener('resize', this.#resizeListener);\n  }\n\n  disconnectedCallback() {\n    super.disconnectedCallback();\n    window.removeEventListener('resize', this.#resizeListener);\n    this.#cleanupMutationObserver();\n  }\n\n  /**\n   * Debounced resize event listener to recalculate menu style\n   */\n  #resizeListener = debounce(() => {\n    this.#cacheMaxOverflowMenuHeight();\n    setHeaderMenuStyle();\n  }, 100);\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 menu is hovered\n   * @returns {boolean}\n   */\n  get overflowHovered() {\n    return this.refs.overflowMenu?.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\n    if (!(event.target instanceof Element)) 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\n    if (!submenu && !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    const submenuHeight = submenu ? submenu.offsetHeight : 0;\n\n    this.headerComponent?.style.setProperty('--submenu-height', `${submenuHeight}px`);\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 && event.type === 'blur' && 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.#deactivate();\n  }\n\n  /**\n   * Deactivate the active item immediately\n   * @param {HTMLElement | null} [item]\n   */\n  #deactivate = (item = this.#state.activeItem) => {\n    if (!item || item != this.#state.activeItem) return;\n    if (this.overflowHovered) return;\n\n    this.headerComponent?.style.setProperty('--submenu-height', '0px');\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  /**\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  /**\n   * Caches the maximum height of all submenus for consistent animations\n   * Stores the value in a CSS custom property for use in transitions\n   */\n  #cacheMaxOverflowMenuHeight() {\n    const submenus = this.querySelectorAll('[ref=\"submenu[]\"]');\n    const maxHeight = Math.max(\n      ...Array.from(submenus)\n        .filter((submenu) => submenu instanceof HTMLElement)\n        .map((submenu) => submenu.offsetHeight)\n    );\n    this.headerComponent?.style.setProperty('--submenu-max-height', `${maxHeight}px`);\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,KAE3B,mBAAoB,CAClB,MAAM,kBAAkB,EAExB,KAAK,cAAc,iBAAiB,eAAgB,IAAM,KAAK,YAAY,CAAC,EAE5E,KAAK,4BAA4B,EAEjC,iBAAiB,KAAK,cAAc,EACpC,OAAO,iBAAiB,SAAU,KAAK,eAAe,CACxD,CAEA,sBAAuB,CACrB,MAAM,qBAAqB,EAC3B,OAAO,oBAAoB,SAAU,KAAK,eAAe,EACzD,KAAK,yBAAyB,CAChC,CAKA,gBAAkB,SAAS,IAAM,CAC/B,KAAK,4BAA4B,EACjC,mBAAmB,CACrB,EAAG,GAAG,EAKN,OAAS,CACP,WAAY,IACd,EAKA,IAAI,cAAe,CACjB,OAA0C,KAAK,KAAK,cAAc,YAAY,cAAc,mBAAmB,CACjH,CAMA,IAAI,iBAAkB,CACpB,OAAO,KAAK,KAAK,cAAc,QAAQ,QAAQ,GAAK,EACtD,CAEA,IAAI,iBAAkB,CACpB,OAA0C,KAAK,QAAQ,kBAAkB,CAC3E,CAMA,SAAY,OAAU,CAGpB,GAFA,KAAK,cAAc,IAAI,kBAAoB,EAEvC,EAAE,MAAM,kBAAkB,SAAU,OAExC,IAAI,KAAO,aAAa,MAAM,MAAM,EAEp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