const v=()=>typeof document<"u";let h=!1,i=null,n=!1,c=!1;const f=new Set;function l(e,t){f.forEach(o=>o(e,t))}const b=typeof window<"u"&&window.navigator!=null?/^Mac/.test(window.navigator.platform):!1;function g(e){return!(e.metaKey||!b&&e.altKey||e.ctrlKey||e.key==="Control"||e.key==="Shift"||e.key==="Meta")}function m(e){n=!0,g(e)&&(i="keyboard",l("keyboard",e))}function r(e){if(i="pointer",e.type==="mousedown"||e.type==="pointerdown"){n=!0;const t=e.composedPath?e.composedPath()[0]:e.target;let o=!1;try{o=t.matches(":focus-visible")}catch{}if(o)return;l("pointer",e)}}function L(e){return e.mozInputSource===0&&e.isTrusted?!0:e.detail===0&&!e.pointerType}function k(e){L(e)&&(n=!0,i="virtual")}function S(e){e.target===window||e.target===document||(!n&&!c&&(i="virtual",l("virtual",e)),n=!1,c=!1)}function z(){n=!1,c=!0}function E(){return i!=="pointer"}function x(){if(!v()||h)return;const{focus:e}=HTMLElement.prototype;HTMLElement.prototype.focus=function(...o){n=!0,e.apply(this,o)},document.addEventListener("keydown",m,!0),document.addEventListener("keyup",m,!0),document.addEventListener("click",k,!0),window.addEventListener("focus",S,!0),window.addEventListener("blur",z,!1),typeof PointerEvent<"u"?(document.addEventListener("pointerdown",r,!0),document.addEventListener("pointermove",r,!0),document.addEventListener("pointerup",r,!0)):(document.addEventListener("mousedown",r,!0),document.addEventListener("mousemove",r,!0),document.addEventListener("mouseup",r,!0)),h=!0}function B(e){x(),e(E());const t=()=>e(E());return f.add(t),()=>{f.delete(t)}}function F(e,t){if(!e){t(void 0);return}t({width:e.offsetWidth,height:e.offsetHeight});const o=e.ownerDocument.defaultView??window,p=new o.ResizeObserver(u=>{if(!Array.isArray(u)||!u.length)return;const[y]=u;let d,s;if("borderBoxSize"in y){const a=y.borderBoxSize,w=Array.isArray(a)?a[0]:a;d=w.inlineSize,s=w.blockSize}else d=e.offsetWidth,s=e.offsetHeight;t({width:d,height:s})});return p.observe(e,{box:"border-box"}),()=>p.unobserve(e)}export{F as a,B as t};
