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