(()=>{let r=".wp-block-uicore-a-menu-link",t=".uicore-menu-link[href]",c="uicore-is-active",i="data-uicore-current-page-item",a="data-uicore-current-page-link",u="data-uicore-menu-current-page-ready",n=e=>e&&"/"!==e&&e.replace(/\/+$/,"")||"/",l=(e,t)=>!["http:","https:"].includes(e.protocol)||e.origin!==t.origin||n(e.pathname)!==n(t.pathname)||e.search&&e.search!==t.search?-1:e.hash?e.hash===t.hash?4:-1:e.search?3:2,s=e=>{e.querySelectorAll(`[${i}="true"]`).forEach(e=>{e.classList.remove(c),e.removeAttribute(i)}),e.querySelectorAll(`[${a}="true"]`).forEach(e=>{e.removeAttribute("aria-current"),e.removeAttribute(a)})},o=({menu:e,currentUrl:n})=>{let u=-1,o=[];s(e),e.querySelectorAll(t).forEach(e=>{try{var t=new URL(e.href,n.origin),r=l(t,n);r<u||(r>u&&(u=r,o=[]),0<=r&&o.push(e))}catch(e){}}),o.forEach(e=>{var t=e.closest(r);t?.classList.add(c),t?.setAttribute(i,"true"),e.setAttribute("aria-current","page"),e.setAttribute(a,"true")})},h=({menu:e,currentHref:t,contextWindow:r=e?.ownerDocument?.defaultView})=>{if(!e||"true"===e.getAttribute(u))return null;t=t||r?.location?.href;if(!t)return null;let n;try{n=new URL(t,r?.location?.origin||window.location.origin)}catch(e){return null}return e.setAttribute(u,"true"),o({menu:e,currentUrl:n}),()=>{s(e),e.removeAttribute(u)}},e=({contextDocument:e=document,contextWindow:t=window,currentHref:r=t.location.href}={})=>{e.querySelectorAll(".wp-block-uicore-a-menu.uicore-bl-menu-current-page").forEach(e=>{h({menu:e,currentHref:r,contextWindow:t})})};window.MenuCurrentPage={initCurrentPage:e,initCurrentPageMenu:h},document.addEventListener("DOMContentLoaded",()=>{document.body.classList.contains("block-editor-page")||e()})})();