import{getBlocksHeight as s,getArticleOffsetTop as f,getNavHeight as u}from"./getBlocksHeight.js";function m(t,n=0){if(typeof t>"u"){window.scrollTo({top:0,behavior:"smooth"});return}const o=s(),e=u();if(!o[n])return;const{height:r,offset:c}=o[n],i=Math.round(c-e+r*(Math.round(t)/100));window.scrollTo({top:i,behavior:"instant"})}const p=t=>{const n=f(),o=u();if(t<n)return{percentScrolled:0,sequenceNumber:-1};const e=s(),r=h(t+o,e);if(r===-1||!e[r])return{percentScrolled:0,sequenceNumber:-1};const{height:c,offset:i}=e[r];return c<=0?{percentScrolled:0,sequenceNumber:-1}:{percentScrolled:l(Math.round((t+o-i)/c*100)),sequenceNumber:r}};function l(t){return Math.max(0,Math.min(100,t))}function h(t,n){const o=n.findIndex(({offset:e,height:r})=>t>=e&&t<e+r);if(o!==-1)return o;for(let e=n.length-1;e>=0;e--)if(t>=n[e].offset)return e;return-1}export{m as syncScrollWithEditor,p as syncScrollWithProject};
