import{Component}from"@theme/component";import{trapFocus,removeTrapFocus}from"@theme/focus";import{onAnimationEnd}from"@theme/utilities";class HeaderDrawer extends Component{requiredRefs=["details"];connectedCallback(){super.connectedCallback(),this.addEventListener("keyup",this.#onKeyUp),this.#setupAnimatedElementListeners()}disconnectedCallback(){super.disconnectedCallback(),this.removeEventListener("keyup",this.#onKeyUp)}#onKeyUp=event=>{event.key==="Escape"&&this.#close(this.#getDetailsElement(event))};get isOpen(){return this.refs.details.hasAttribute("open")}#getDetailsElement(event){return event?.target instanceof Element?event.target.closest("details")??this.refs.details:this.refs.details}toggle(){return this.isOpen?this.close():this.open()}open(event){const details=this.#getDetailsElement(event),summary=details.querySelector("summary");summary&&(summary.setAttribute("aria-expanded","true"),requestAnimationFrame(()=>{details.classList.add("menu-open"),setTimeout(()=>{trapFocus(details)},0)}))}back(event){this.#close(this.#getDetailsElement(event))}close(){this.#close(this.refs.details)}#close(details){const summary=details.querySelector("summary");summary&&(summary.setAttribute("aria-expanded","false"),details.classList.remove("menu-open"),onAnimationEnd(details,()=>{reset(details),details===this.refs.details?(removeTrapFocus(),this.querySelectorAll("details[open]").forEach(reset)):setTimeout(()=>{trapFocus(this.refs.details)},0)}))}#setupAnimatedElementListeners(){function removeWillChangeOnAnimationEnd(event){const target=event.target;target&&target instanceof HTMLElement&&(target.style.setProperty("will-change","unset"),target.removeEventListener("animationend",removeWillChangeOnAnimationEnd))}this.querySelectorAll(".menu-drawer__animated-element").forEach(element=>{element.addEventListener("animationend",removeWillChangeOnAnimationEnd)})}}customElements.get("header-drawer")||customElements.define("header-drawer",HeaderDrawer);function reset(element){element.classList.remove("menu-open"),element.removeAttribute("open"),element.querySelector("summary")?.setAttribute("aria-expanded","false")} //# sourceMappingURL=/cdn/shop/t/47/assets/header-drawer.js.map?v=38290796699993510201757451905