MCPcopy Create free account
hub / github.com/arktypeio/arktype / activeIndexOf

Function activeIndexOf

ark/docs/components/shell/scrollspy.ts:8–19  ·  view source on GitHub ↗
(headings: (HTMLElement | null)[])

Source from the content-addressed store, hash-verified

6 * a short final section can't scroll that far.
7 */
8const activeIndexOf = (headings: (HTMLElement | null)[]): number => {
9 const root = document.documentElement
10 if (innerHeight + scrollY >= root.scrollHeight - 4) return headings.length - 1
11 const line = parseFloat(getComputedStyle(root).scrollPaddingTop) + 8
12 let active = 0
13 for (const [i, heading] of headings.entries()) {
14 if (!heading) continue
15 if (heading.getBoundingClientRect().top > line) break
16 active = i
17 }
18 return active
19}
20
21/** tracks which of the elements with these ids is being read */
22export const useScrollspy = (ids: readonly string[]): number => {

Callers 1

updateFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected