chore: follow the general comments style
This commit is contained in:
@@ -34,11 +34,17 @@
|
||||
* A breadcrumb item representing a tracked section
|
||||
*/
|
||||
export interface BreadcrumbItem {
|
||||
/** Unique index for ordering */
|
||||
/**
|
||||
* Unique index for ordering
|
||||
*/
|
||||
index: number;
|
||||
/** Display title for the breadcrumb */
|
||||
/**
|
||||
* Display title for the breadcrumb
|
||||
*/
|
||||
title: string;
|
||||
/** DOM element to track */
|
||||
/**
|
||||
* DOM element to track
|
||||
*/
|
||||
element: HTMLElement;
|
||||
}
|
||||
|
||||
@@ -50,21 +56,37 @@ export interface BreadcrumbItem {
|
||||
* past while moving down the page.
|
||||
*/
|
||||
class ScrollBreadcrumbsStore {
|
||||
/** All tracked breadcrumb items */
|
||||
/**
|
||||
* All tracked breadcrumb items
|
||||
*/
|
||||
#items = $state<BreadcrumbItem[]>([]);
|
||||
/** Set of indices that have scrolled past (exited viewport while scrolling down) */
|
||||
/**
|
||||
* Set of indices that have scrolled past (exited viewport while scrolling down)
|
||||
*/
|
||||
#scrolledPast = $state<Set<number>>(new Set());
|
||||
/** Intersection Observer instance */
|
||||
/**
|
||||
* Intersection Observer instance
|
||||
*/
|
||||
#observer: IntersectionObserver | null = null;
|
||||
/** Offset for smooth scrolling (sticky header height) */
|
||||
/**
|
||||
* Offset for smooth scrolling (sticky header height)
|
||||
*/
|
||||
#scrollOffset = 0;
|
||||
/** Current scroll direction */
|
||||
/**
|
||||
* Current scroll direction
|
||||
*/
|
||||
#isScrollingDown = $state(false);
|
||||
/** Previous scroll Y position to determine direction */
|
||||
/**
|
||||
* Previous scroll Y position to determine direction
|
||||
*/
|
||||
#prevScrollY = 0;
|
||||
/** Throttled scroll handler */
|
||||
/**
|
||||
* Throttled scroll handler
|
||||
*/
|
||||
#handleScroll: (() => void) | null = null;
|
||||
/** Listener count for cleanup */
|
||||
/**
|
||||
* Listener count for cleanup
|
||||
*/
|
||||
#listenerCount = 0;
|
||||
|
||||
/**
|
||||
@@ -141,17 +163,23 @@ class ScrollBreadcrumbsStore {
|
||||
this.#detachScrollListener();
|
||||
}
|
||||
|
||||
/** All tracked items sorted by index */
|
||||
/**
|
||||
* All tracked items sorted by index
|
||||
*/
|
||||
get items(): BreadcrumbItem[] {
|
||||
return this.#items.slice().sort((a, b) => a.index - b.index);
|
||||
}
|
||||
|
||||
/** Items that have scrolled past viewport top (visible in breadcrumbs) */
|
||||
/**
|
||||
* Items that have scrolled past viewport top (visible in breadcrumbs)
|
||||
*/
|
||||
get scrolledPastItems(): BreadcrumbItem[] {
|
||||
return this.items.filter(item => this.#scrolledPast.has(item.index));
|
||||
}
|
||||
|
||||
/** Index of the most recently scrolled item (active section) */
|
||||
/**
|
||||
* Index of the most recently scrolled item (active section)
|
||||
*/
|
||||
get activeIndex(): number | null {
|
||||
const past = this.scrolledPastItems;
|
||||
return past.length > 0 ? past[past.length - 1].index : null;
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
/** @vitest-environment jsdom */
|
||||
/**
|
||||
* @vitest-environment jsdom
|
||||
*/
|
||||
import {
|
||||
afterEach,
|
||||
beforeEach,
|
||||
|
||||
Reference in New Issue
Block a user