@dloizides/ui-layout 1.64.0 → 1.65.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs CHANGED
@@ -3545,6 +3545,7 @@ function pickActiveIndex(tops, line) {
3545
3545
  return tops.reduce((picked, top, index) => top <= line ? index : picked, 0);
3546
3546
  }
3547
3547
  function pickSpyIndex(tops, viewport, activationRatio) {
3548
+ if (viewport.atStart) return 0;
3548
3549
  if (viewport.atEnd) return Math.max(tops.length - 1, 0);
3549
3550
  return pickActiveIndex(tops, viewport.top + viewport.height * activationRatio);
3550
3551
  }
@@ -3574,6 +3575,9 @@ function scrollParent(element) {
3574
3575
  }
3575
3576
  return null;
3576
3577
  }
3578
+ function isAtStart(scrolled) {
3579
+ return scrolled <= 0;
3580
+ }
3577
3581
  function isAtEnd(scrolled, visible, total) {
3578
3582
  return scrolled > 0 && scrolled + visible >= total - END_TOLERANCE_PX;
3579
3583
  }
@@ -3581,9 +3585,9 @@ function scrollViewport(anchor) {
3581
3585
  const parent = scrollParent(anchor);
3582
3586
  if (parent === null) {
3583
3587
  const root = document.scrollingElement ?? document.documentElement;
3584
- return { top: 0, height: window.innerHeight, atEnd: isAtEnd(window.scrollY, window.innerHeight, root.scrollHeight) };
3588
+ return { top: 0, height: window.innerHeight, atStart: isAtStart(window.scrollY), atEnd: isAtEnd(window.scrollY, window.innerHeight, root.scrollHeight) };
3585
3589
  }
3586
- return { top: parent.getBoundingClientRect().top, height: parent.clientHeight, atEnd: isAtEnd(parent.scrollTop, parent.clientHeight, parent.scrollHeight) };
3590
+ return { top: parent.getBoundingClientRect().top, height: parent.clientHeight, atStart: isAtStart(parent.scrollTop), atEnd: isAtEnd(parent.scrollTop, parent.clientHeight, parent.scrollHeight) };
3587
3591
  }
3588
3592
 
3589
3593
  // src/SectionIndexLayout/useScrollSpy.ts
@@ -3617,10 +3621,9 @@ function useScrollSpy({ anchorIds, enabled, activationRatio, onActive }) {
3617
3621
  const tops = anchors.map((anchor) => anchor.element.getBoundingClientRect().top);
3618
3622
  const picked = pickSpyIndex(tops, scrollViewport(first.element), activationRatio);
3619
3623
  const index = anchors[picked]?.index ?? 0;
3620
- const primed = last.current !== UNPRIMED;
3621
3624
  if (index === last.current) return;
3622
3625
  last.current = index;
3623
- if (primed || index > 0) onActiveRef.current(index);
3626
+ onActiveRef.current(index);
3624
3627
  };
3625
3628
  document.addEventListener("scroll", evaluate, LISTEN_OPTIONS);
3626
3629
  window.addEventListener("resize", evaluate, LISTEN_OPTIONS);
@@ -3689,7 +3692,7 @@ var SectionIndexLayout = ({
3689
3692
  const wide = useIsWideViewport(fold.wide);
3690
3693
  const stacked = useIsWideViewport(fold.stackFrom);
3691
3694
  const sticky = resolveSticky(stickyIndex);
3692
- const preferredKey = wide ? initialKey : collapsedKey ?? initialKey;
3695
+ const preferredKey = wide ? initialKey : collapsedKey;
3693
3696
  const { activeKey, pick, select } = useSectionSelection({ sections, testID, preferredKey, spyEnabled: wide && sections.length > 1, sticky });
3694
3697
  const dense = density === "dense" /* Dense */;
3695
3698
  const gap = { gap: dense ? DENSE_GAP : COMFORTABLE_GAP };