package webutil import "fmt" // BuildPageScrollByJS returns one immediate JavaScript scroll step for the given // CSS-pixel delta. It resolves the initial target under the viewport center, // walks toward scrollable ancestors that can move in the requested direction, // and hands off to the document when a nested scroller reaches its boundary. // Cross-origin frame contents remain best-effort because elementFromPoint can // only return the accessible frame element from the top-level document. // // The app-level Vim Mode repeater owns held-key cadence; this helper performs // no requestAnimationFrame loop of its own. func BuildPageScrollByJS(dx, dy int) string { return fmt.Sprintf(`(function(){ var dx=%d,dy=%d,doc=document; function hasScrollableOverflow(value){ return value==='auto'||value==='scroll'||value==='overlay'; } function canScroll(el){ if(!el)return false; var style=window.getComputedStyle(el); if(dy!==0){ var overflowY=style.overflowY||style.overflow; var maxTop=el.scrollHeight-el.clientHeight; if(hasScrollableOverflow(overflowY)){ if((dy<0&&el.scrollTop>0)||(dy>0&&el.scrollTop0)||(dx>0&&el.scrollLeft