import{getOwnerDocument as e}from"./dom.js";import{warn as t}from"./function.js";import{isActiveElement as o,isInputElement as l}from"./tabbable.js";function r(r,c){void 0===c&&(c={});var{isActive:s=o,nextTick:f,preventScroll:i=!0,selectTextIfInput:u=!0}=c;if(!r||s(r))return-1;function m(){if(r){if(function(){if(null==n){n=!1;try{document.createElement("div").focus({get preventScroll(){return n=!0,!0}})}catch(e){}}return n}())r.focus({preventScroll:i});else if(r.focus(),i)!function(e){for(var{element:t,scrollTop:o,scrollLeft:l}of e)t.scrollTop=o,t.scrollLeft=l}(function(t){var o=e(t),l=t.parentNode,r=[],n=o.scrollingElement||o.documentElement;for(;l instanceof HTMLElement&&l!==n;)(l.offsetHeight<l.scrollHeight||l.offsetWidth<l.scrollWidth)&&r.push({element:l,scrollTop:l.scrollTop,scrollLeft:l.scrollLeft}),l=l.parentNode;n instanceof HTMLElement&&r.push({element:n,scrollTop:n.scrollTop,scrollLeft:n.scrollLeft});return r}(r));l(r)&&u&&r.select()}else t({condition:!0,message:"[chakra-ui]: can't call focus() on `null` or `undefined` element"})}return f?requestAnimationFrame(m):(m(),-1)}var n=null;export{r as focus};
//# sourceMappingURL=focus.js.map
