import{useCallback as n,useEffect as l}from"react";import{syncScrollWithProject as i}from"../utils/syncScrollWithEditor.js";import{installProgrammaticScrollMarking as s,isProgrammaticScrollEvent as c}from"../utils/programmatic-scroll.js";import{usePostMessage as d}from"../../providers/post-message/use-post-message.js";import{isInIframe as a}from"../../utils/utils.js";const g=()=>{const{sendMessage:e}=d(),o=n(()=>{if(c()||!window.document.querySelector(":hover"))return;const{percentScrolled:r,sequenceNumber:t}=i(window.scrollY);e({type:"editor-scroll-updated",percentScrolled:r,sequenceNumber:t}),e({type:"scroll-updated",position:{absolute:window.scrollY,relative:Math.round(window.scrollY/(window.document.body.clientHeight-window.innerHeight)*100)}})},[e]);l(()=>{if(a())return s(),window.addEventListener("scroll",o,{passive:!0}),()=>{window.removeEventListener("scroll",o)}},[o])};export{g as useScrollTracker};
