Primitives / foldkit-primitives/dom
visibleLinks
function · packages/primitives/src/dom/visible-links.ts:33
function visibleLinks(options?: {
readonly atMost?: number
readonly margin?: string
}): Stream.Stream<Url>The address of each same-origin link that scrolls into view, for a
Data.preload before the reader reaches it. Opt-in: merge it into
Site.routing's preload.links beside pointedLinks(); nothing preloads by
visibility unless it is asked for.
Each address is read once per page, and at most atMost (8) addresses per
page, in the order they came into view: a page is the pathname and query
the document shows when a link is read, so a same-document navigation
counts the cap again. margin widens the viewport the way an
IntersectionObserver's rootMargin does. A link with data-preload="none"
is skipped, and so is every link under Save-Data, on a 2g connection, or
while the tab is hidden; a link that came into view then is not read later
unless it leaves and returns. Without a document or an IntersectionObserver
the stream is empty.