(()=>{let y=".wp-block-uicore-a-menu-wrapper",w=":scope > .wp-block-uicore-a-menu-link",L=":scope > .uicore-menu-link",g="uicore-is-active",E="uicore-is-active",f=180,b="data-uicore-menu-magnet-ready",k=e=>{e.style.removeProperty("--intent"),e.style.removeProperty("--item-active-x"),e.style.removeProperty("--item-active-width")},x=(e,t)=>{var t=t.getBoundingClientRect(),n=e.getBoundingClientRect();e.style.setProperty("--item-active-x",t.left-n.left+"px"),e.style.setProperty("--item-active-width",t.width+"px")},n=({menu:t,contextWindow:e=t?.ownerDocument?.defaultView})=>{if(!t||"true"===t.getAttribute(b))return null;let n=t.querySelector(y);if(!n||!e)return null;t.setAttribute(b,"true");let r=null;var o=Array.from(n.querySelectorAll(w));let i=e=>e.querySelector(L);o=o.find(e=>e.classList.contains(g))||null;let l=o?i(o):null,u=e=>{e=e?.closest?.(".wp-block-uicore-a-menu-link");return e?.parentElement===n?e:null},s=()=>{r&&(e.clearTimeout(r),r=null)},c=e=>{t.classList.contains(E)?k(n):(s(),n.style.setProperty("--intent","1"),x(n,e))},a=()=>{s(),n.style.setProperty("--intent","0"),r=e.setTimeout(()=>{k(n),r=null},f)},d=e=>{e=u(e.target),e=e?i(e):null;e&&c(e)},m=e=>{e=u(e.target),e=e?i(e):null;e&&c(e)},v=e=>{e.relatedTarget&&n.contains(e.relatedTarget)||a()},p=()=>{s(),l&&!t.classList.contains(E)?x(n,l):k(n)};return n.addEventListener("pointerover",d),n.addEventListener("focusin",m),n.addEventListener("mouseleave",a),n.addEventListener("focusout",v),e.addEventListener("resize",p),l&&x(n,l),()=>{s(),n.removeEventListener("pointerover",d),n.removeEventListener("focusin",m),n.removeEventListener("mouseleave",a),n.removeEventListener("focusout",v),e.removeEventListener("resize",p),k(n),t.removeAttribute(b)}},e=({contextDocument:e=document,contextWindow:t=window}={})=>{e.querySelectorAll(".wp-block-uicore-a-menu.uicore-bl-menu-magnet-button").forEach(e=>{n({menu:e,contextWindow:t})})};window.MenuMagnetButton={initMagnetButton:e,initMagnetButtonMenu:n},document.addEventListener("DOMContentLoaded",()=>{document.body.classList.contains("block-editor-page")||e()})})();