(()=>{let v=".uicore-menu-panel",w=":scope > .wp-block-uicore-a-menu-wrapper",b=':scope > .wp-block-uicore-a-menu-wrapper > .wp-block-uicore-a-menu-link[data-menu-link-type="submenu"]',h='[data-menu-link-type="submenu"]',y=':scope > .uicore-menu-link .wp-block-uicore-toggle-icon:not([data-menu-toggle="true"])',E='.wp-block-uicore-toggle-icon.uicore-is-active:not([data-menu-toggle="true"])',n=".wp-block-uicore-a-menu-submenu",k=120,f="data-uicore-scale-bg-ready",o=({menuItem:e,contextWindow:t})=>Array.from(e?.querySelectorAll(n)||[]).filter(e=>"true"!==e.getAttribute("aria-hidden")&&"none"!==(e=t.getComputedStyle(e)).display&&"hidden"!==e.visibility),x=({activeItem:e,rootWrapper:t,contextWindow:n})=>{e=o({menuItem:e,contextWindow:n});return e.length?(n=t.getBoundingClientRect().bottom,t=Math.max(...e.map(e=>e.getBoundingClientRect().bottom)),Math.max(Math.ceil(t-n),0)):0},L=({elements:e,events:n,onChange:o})=>(e.forEach(t=>{n.forEach(e=>{t.addEventListener(e,o)})}),()=>{e.forEach(t=>{n.forEach(e=>{t.removeEventListener(e,o)})})}),A=({menu:t,toggles:e,onChange:n,contextDocument:o})=>{let r=e=>{t.contains(e.target)||n()},c=e=>{"Escape"===e.key&&n()};return e.forEach(e=>{e.addEventListener("click",n)}),o.addEventListener("click",r),o.addEventListener("keydown",c),()=>{e.forEach(e=>{e.removeEventListener("click",n)}),o.removeEventListener("click",r),o.removeEventListener("keydown",c)}},r=({menu:t,contextDocument:e=t?.ownerDocument,contextWindow:n=e?.defaultView})=>{if(!t||"true"===t.getAttribute(f))return null;var o=t.querySelector(v);let r=o?.querySelector(w);if(!(o&&r&&e&&n))return null;t.setAttribute(f,"true");let c=null,i=[],u=t.classList.contains("uicore-menu-submenu-hover"),a=Array.from(o.querySelectorAll(b));var o=Array.from(o.querySelectorAll(h)),l=o.map(e=>e.querySelector(y)).filter(Boolean);let m=()=>u?a.find(e=>e.matches(":hover")):a.find(e=>e.querySelector(E)),s=()=>{c&&(n.clearTimeout(c),c=null)},d=(e=0)=>{t.style.setProperty("--uicore-menu-scale-bg-space",e+"px")},p=()=>{var e;t.classList.contains("uicore-is-active")?(s(),d(0)):(e=m())?(s(),d(x({activeItem:e,rootWrapper:r,contextWindow:n}))):(s(),c=n.setTimeout(()=>{d(0),c=null},k))},g=()=>n.requestAnimationFrame(p);return u?i.push(L({elements:o,events:["mouseenter","mouseleave"],onChange:g})):i.push(A({menu:t,toggles:l,onChange:()=>n.requestAnimationFrame(()=>{n.requestAnimationFrame(p)}),contextDocument:e})),n.addEventListener("resize",g),i.push(()=>{n.removeEventListener("resize",g)}),d(0),g(),()=>{s(),i.forEach(e=>e&&e()),d(0),t.removeAttribute(f)}},e=({contextDocument:t=document,contextWindow:n=window}={})=>{t.querySelectorAll(".wp-block-uicore-a-menu.uicore-bl-menu-dropdown-scale-bg").forEach(e=>{r({menu:e,contextDocument:t,contextWindow:n})})};window.MenuScaleBg={initScaleBg:e,initScaleBgMenu:r},document.addEventListener("DOMContentLoaded",()=>{document.body.classList.contains("block-editor-page")||e()})})();