import{dt as e,ft as t,gt as n,n as r}from"../../index.js";import{a as i,i as a,o,r as s}from"./app-router-scroll-state-RqkoQdOY.js";var c=n(t(),1),l=e();r();var u=c.createContext(null),d=[`bottom`,`height`,`left`,`right`,`top`,`width`,`x`,`y`];function f(e){return null}function p(e){let t=getComputedStyle(e).position;if(t===`fixed`||t===`sticky`)return!0;let n=e.getBoundingClientRect();return d.every(e=>n[e]===0)}function m(e,t){let n=e.getClientRects();if(n.length===0)return!1;let r=1/0;for(let e of n)e.top<r&&(r=e.top);return r>=0&&r<=t}function h(e){let t=o(e.startsWith(`#`)?e.slice(1):e);return t===`top`?document.body:document.getElementById(t)??document.getElementsByName(t)[0]??null}function g(e){let t=e.ownerDocument?.head;return t!=null&&t.contains(e)}function _(e){if(!(e instanceof Element)||g(e))return null;let t=e;for(;!(t instanceof HTMLElement)||p(t);){if(t.nextElementSibling===null)return null;t=t.nextElementSibling}return{kind:`element`,element:t}}function v(e,t){if(t!==null){e.scrollIntoView({behavior:`auto`});return}let n=document.documentElement,r=n.clientHeight;m(e,r)||(n.scrollTop=0,m(e,r)||e.scrollIntoView({behavior:`auto`,block:`start`,inline:`nearest`}))}var y=class extends c.Component{scheduledCommitId=null;schedulePotentialScroll=()=>{let e=this.props.commitId;this.scheduledCommitId=e,queueMicrotask(()=>{this.scheduledCommitId===e&&this.handlePotentialScroll()})};handlePotentialScroll=()=>{let e=a();if(e===null||this.props.commitId===null||e.commitId!==this.props.commitId)return;let t;if(t=e.hash===null?null:h(e.hash),t===null){t=f(this);let n=t instanceof Element?t:t?.parentElement;if(t!==null&&n!=null&&g(t)&&!e.headElements?.has(n)){i(e,this.props.commitId);return}}let n=_(t);if(n===null)return;let r=n.element,o=s(e,this.props.commitId);o!==null&&(v(r,o.hash),r.focus())};componentDidMount(){this.schedulePotentialScroll()}componentDidUpdate(){this.schedulePotentialScroll()}componentWillUnmount(){this.scheduledCommitId=null}render(){return this.props.children}};function b({children:e}){return(0,l.jsx)(y,{commitId:c.useContext(u),children:e})}export{b as AppRouterScrollTarget};