import{i as r,q as c,v as y,w as g}from"./custom-element.js";import{M as L}from"./media-query.js";const f={allowItemHover:!0,position:"bottom"},I=(n,i,a=f)=>{const p={...f,...a};let o=y(!1);const m=g(()=>new L("(max-width: 780px)").current);function h(){const t=n()?.getBoundingClientRect(),e=i()?.getBoundingClientRect();return!t||!e?{}:r(m)?{top:`-${e.height+24}px`,left:`-${e.width-t.width}px`}:{top:a.position==="top"?`-${e.height-t.height}px`:i()?.style.left||"0px"}}function s(t){if(!i||!n)return;const e=t?.relatedTarget;p.allowItemHover&&e&&(i()?.contains(e)||n()?.contains(e))||(i()?.classList.add("mc-sidebar__floating-item--hidden"),c(o,!1),document.removeEventListener("mousedown",d))}function d(t){const e=t.composedPath?t.composedPath():[];!e.includes(n())&&!e.includes(i())&&s(t)}function u(){const t=i();if(t?.classList.toggle("mc-sidebar__floating-item--hidden"),c(o,!t?.classList.contains("mc-sidebar__floating-item--hidden")),!r(o)||!t)return;const{left:e,top:l}=h();l&&(t.style.top=l),e&&(t.style.left=e),c(o,!0),document.addEventListener("mousedown",d)}function w(t){i&&(["ArrowDown","Enter"," "].includes(t.key)&&(t.preventDefault(),u(),b()),t.key==="Tab"&&s())}function b(){i()?.querySelector('button, [href], [tabindex]:not([tabindex="-1"])')?.focus()}function x(t){t.key==="Escape"&&(t.preventDefault(),s(),n()?.focus())}return{floatingItemIsDisplayed:r(o),hideFloatingItem:s,showFloatingItem:u,onTriggerKeydown:w,onListboxKeydown:x}};export{I as u};
//# sourceMappingURL=floating-item.svelte.js.map
