@devzwo/ngx-magic-scroll 0.0.1-rc.2 → 1.1.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.
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"devzwo-ngx-magic-scroll.mjs","names":[],"sources":["../../../projects/ngx-magic-scroll/src/lib/navigation/linked-route-fragment.ts","../../../projects/ngx-magic-scroll/src/lib/navigation/inject-scrollable-parent.ts","../../../projects/ngx-magic-scroll/src/lib/navigation/inject-header-size.ts","../../../projects/ngx-magic-scroll/src/lib/navigation/nearest-anchor.provider.ts","../../../projects/ngx-magic-scroll/src/lib/navigation/scroll-service.ts","../../../projects/ngx-magic-scroll/src/lib/facade/magic-scroll-options.ts","../../../projects/ngx-magic-scroll/src/lib/facade/scroll-source.ts","../../../projects/ngx-magic-scroll/src/lib/facade/magic-scroll.directive.ts","../../../projects/ngx-magic-scroll/src/lib/facade/scroll-anchor.directive.ts"],"sourcesContent":["import { effect, inject, linkedSignal, WritableSignal } from '@angular/core';\nimport { toSignal } from '@angular/core/rxjs-interop';\nimport { ActivatedRoute, Router } from '@angular/router';\n\n/**\n * Creates an Angular signal synchronized bidirectionally with the URL fragment (#fragment).\n *\n * Reads the current route fragment as a writable signal (WritableSignal).\n * - Reading reacts to URL fragment changes through ActivatedRoute.fragment.\n * - Writing, for example fragmentSignal.set('anchor-id'), asynchronously updates the URL\n * through Router.navigateByUrl with replaceUrl: true. This preserves query parameters\n * and avoids adding a history entry for each scroll update.\n *\n * @returns A WritableSignal<string | null | undefined> linked to the URL fragment.\n * @example\n * ```ts\n * @Component({ ... })\n * export class MyViewComponent {\n * // Initialize the signal\n * protected readonly routeFragment = linkedRouteFragment();\n *\n * onAnchorReached(anchorId: string) {\n * // Update the URL fragment without adding history entries (#anchorId)\n * this.routeFragment.set(anchorId);\n * }\n * }\n * ```\n */\nexport function linkedRouteFragment(): WritableSignal<string | null | undefined> {\n const route = inject(ActivatedRoute);\n const router = inject(Router);\n const fragment = toSignal(route.fragment);\n\n const actualFragment = linkedSignal(() => fragment());\n\n effect(() => {\n const newFragment = actualFragment();\n if (route.snapshot.fragment !== newFragment) {\n const tree = router.createUrlTree([], {\n relativeTo: route,\n fragment: newFragment ?? undefined,\n queryParamsHandling: 'preserve',\n });\n\n router.navigateByUrl(tree, { replaceUrl: true }).catch((error: Error) => {\n console.log(`Cant set fragment ${newFragment}`, error);\n });\n }\n });\n\n return actualFragment;\n}\n","import { ElementRef, inject } from '@angular/core';\n\n/**\n * Finds the closest scrollable ancestor in the DOM.\n *\n * Walks up the DOM tree looking for overflow-y: auto or overflow-y: scroll.\n * Call within an Angular injection context to start at ElementRef.nativeElement,\n * or pass a hostElement explicitly.\n *\n * @param hostElement - Optional starting element. An explicit element takes precedence;\n * otherwise the starting element is obtained by injecting ElementRef<HTMLElement>.\n * @returns The closest scrollable HTMLElement, or undefined if none exists.\n * @example\n * ```ts\n * // Within an injection context (for example a directive or component constructor):\n * const scrollParent = injectScrollableParentElement();\n *\n * // Outside an injection context:\n * const scrollParent = injectScrollableParentElement(myHtmlElement);\n * ```\n */\nexport function injectScrollableParentElement(\n hostElement?: HTMLElement | null,\n): HTMLElement | undefined {\n function findScrollableParent(el: HTMLElement): HTMLElement | undefined {\n let current = el.parentElement ?? undefined;\n while (current) {\n const overflowY = getComputedStyle(current).overflowY;\n if (\n overflowY === 'auto' ||\n overflowY === 'scroll' /**&& current.scrollHeight > current.clientHeight **/\n ) {\n return current;\n }\n current = current.parentElement ?? undefined;\n }\n return undefined;\n }\n\n return findScrollableParent(\n hostElement ?? (inject(ElementRef<HTMLElement>).nativeElement as HTMLElement),\n );\n}\n","/**\n * Measures the height of a header selected within the supplied document.\n * Used to calculate scroll and anchor offsets so a fixed or sticky header does not\n * cover the scrolled content.\n *\n * @param headerSelector - Header CSS selector, such as '.header' or 'app-header'.\n * @param document - Document instance in which to search, for example injected through DOCUMENT.\n * @returns The absolute header height in pixels, or 0 if the element is not found.\n * @example\n * ```ts\n * const document = inject(DOCUMENT);\n * const height = injectedHeaderHeight('.header', document);\n * ```\n */\nexport function injectedHeaderHeight(headerSelector: string, document: Document): number {\n const boundingBox = document.querySelector<HTMLElement>(headerSelector)?.getBoundingClientRect();\n if (!boundingBox) {\n console.warn('No boundingBox found for headerSelector: ', headerSelector);\n return 0;\n }\n\n return Math.abs(boundingBox.height);\n}\n","import { DOCUMENT } from '@angular/common';\nimport { inject, Injectable } from '@angular/core';\nimport { injectScrollableParentElement } from './inject-scrollable-parent';\nimport { injectedHeaderHeight } from './inject-header-size';\n\n/**\n * Options for finding the nearest anchor.\n */\nexport interface NearestAnchorOptions {\n /** Explicit scroll container, including a host that is itself scrollable. */\n scrollable?: HTMLElement;\n /** Preselected anchor elements (e.g. scoped, explicit anchors in the facade). */\n anchors?: readonly HTMLElement[];\n /**\n * Optional host element within which to find anchor elements.\n * Defaults to searching the entire Document.\n */\n hostElement?: HTMLElement;\n /**\n * CSS selector for eligible anchors, for example '[id^=\"item-card-\"]'.\n * Defaults to '[id]'.\n */\n selector?: string;\n /**\n * Static top offset, in pixels, such as a fixed gap or padding.\n */\n headerOffset?: number;\n /**\n * CSS selector for a fixed or sticky header, for example '.header'.\n * Its measured height is added to the offset so covered elements are not selected\n * as the topmost visible anchor.\n */\n headerSelector?: string;\n /**\n * Static bottom offset, in pixels, such as a sticky footer gap or bottom margin.\n */\n bottomOffset?: number;\n /**\n * Relative activation threshold (0.0 to 1.0) defining the trigger line within the visible reading area.\n */\n activationThreshold?: number;\n}\n\n/**\n * Finds the anchor representing the currently read section based on full containment and activation boundaries.\n *\n * Supports scroll-spy behavior to identify the current section while scrolling and\n * synchronize the URL fragment. A section is activated immediately when fully visible in the\n * viewport below sticky headers, or remains active while scrolling through its content until\n * the next section crosses the activation boundary or becomes fully visible.\n *\n * @remarks\n * This service does not use providedIn: 'root'. Register it in application or component\n * providers when using it internally. The facade provides its own instance.\n */\n@Injectable()\nexport class NearestAnchorProvider {\n private readonly document = inject(DOCUMENT);\n\n /**\n * Calculates the ID of the active anchor based on scroll position and visible area boundaries.\n *\n * 1. Evaluates all eligible anchors within the host or document.\n * 2. Determines the visible reading area (`topBoundary = scrollableTop + headerOffset + headerHeight`, `bottomBoundary = (containerBottom | viewportHeight) - bottomOffset`).\n * 3. Prioritizes fully contained anchors (`top >= topBoundary - 1` and `bottom <= bottomBoundary + 1`), selecting the topmost one.\n * 4. Falls back to the anchor that crossed `triggerLine` most recently (`top <= triggerLine + 1`).\n * 5. Falls back to the first anchor if no anchor has crossed the boundary yet.\n *\n * @param options - Host element, selector, scroll container and header-offset settings.\n * @returns The active anchor's element ID, or undefined if no eligible element exists.\n * @example\n * ```ts\n * const nearestId = nearestAnchorProvider.getNearestAnchor({\n * hostElement: listContainer,\n * selector: '[id^=\"card-\"]',\n * headerSelector: '.app-header',\n * bottomOffset: 40\n * });\n * ```\n */\n public getNearestAnchor(options?: NearestAnchorOptions): string | undefined {\n const host = options?.hostElement ?? this.document;\n const selector = options?.selector ?? '[id]';\n const offset =\n (options?.headerOffset ?? 0) +\n (options?.headerSelector ? injectedHeaderHeight(options.headerSelector, this.document) : 0);\n\n // Collects all HTML elements with an id – these are our potential anchor targets\n const anchors = options?.anchors ?? Array.from(host.querySelectorAll<HTMLElement>(selector));\n if (anchors.length === 0) {\n return undefined;\n }\n\n const scrollable =\n options?.scrollable ??\n (options?.hostElement ? injectScrollableParentElement(options.hostElement) : undefined);\n const isDocument =\n !scrollable ||\n scrollable === this.document.documentElement ||\n scrollable === this.document.body;\n const topBoundary = (isDocument ? 0 : scrollable.getBoundingClientRect().top) + offset;\n const viewportBottom = isDocument\n ? (this.document.defaultView?.innerHeight ?? this.document.documentElement.clientHeight)\n : scrollable.getBoundingClientRect().bottom;\n const bottomBoundary = Math.max(\n topBoundary,\n viewportBottom - Math.max(0, options?.bottomOffset ?? 0),\n );\n\n // 1. Check for fully contained anchors (entire element inside visible reading area)\n const containedAnchors = anchors.filter((el) => {\n const rect = el.getBoundingClientRect();\n return rect.top >= topBoundary - 1 && rect.bottom <= bottomBoundary + 1;\n });\n\n if (containedAnchors.length > 0) {\n // Topmost fully visible anchor\n const topmostContained = containedAnchors.reduce((best, el) =>\n el.getBoundingClientRect().top < best.getBoundingClientRect().top ? el : best,\n );\n return topmostContained.id;\n }\n\n // 2. Reading line fallback: Anchor that crossed triggerLine most recently\n const threshold = Math.max(0, Math.min(1, options?.activationThreshold ?? 0));\n const triggerLine = topBoundary + (bottomBoundary - topBoundary) * threshold;\n const passedAnchors = anchors.filter((el) => el.getBoundingClientRect().top <= triggerLine + 1);\n\n if (passedAnchors.length > 0) {\n // Pick the anchor that crossed the trigger line most recently (highest top <= triggerLine)\n const active = passedAnchors.reduce((best, el) =>\n el.getBoundingClientRect().top > best.getBoundingClientRect().top ? el : best,\n );\n return active.id;\n }\n\n // 3. Before any anchor has reached the boundary, select the first anchor\n const first = anchors.reduce((best, el) =>\n el.getBoundingClientRect().top < best.getBoundingClientRect().top ? el : best,\n );\n return first.id;\n }\n}\n","import { inject, Injectable } from '@angular/core';\nimport { DOCUMENT } from '@angular/common';\n\n/**\n * Options for a scroll operation performed by ScrollService.\n */\nexport interface ScrollOptions {\n /**\n * Scrollable container. Defaults to the document's scrolling element.\n */\n scrollable?: HTMLElement;\n /**\n * Scroll behavior: 'instant' for an immediate jump, 'smooth' for animation,\n * or 'auto' to follow the browser's CSS scroll behavior. Defaults to 'instant'.\n */\n behavior?: ScrollBehavior;\n /**\n * Visibility condition under which scrolling is skipped:\n * - 'none': Always scroll (default).\n * - 'top': Skip when the element's top edge is visible.\n * - 'full': Skip when the entire element is visible.\n * - 'always': Skip when either the top or bottom edge is visible.\n */\n ignoreWhenInView?: 'none' | 'top' | 'full' | 'always';\n /**\n * Additional top offset for the target, in pixels, for example for a header or padding.\n * Defaults to 20 pixels.\n */\n topOffset?: number;\n}\n\n/**\n * Central service for scrolling to DOM elements and anchors.\n *\n * Supports explicit scroll containers or document scrolling, configurable header offsets,\n * visibility checks to avoid unnecessary movement, and smooth or instant scrolling.\n */\n@Injectable({\n providedIn: 'root',\n})\nexport class ScrollService {\n private readonly document = inject<Document>(DOCUMENT);\n private readonly TOP_OFFSET = 20;\n\n /**\n * Scrolls to the element identified by its ID.\n *\n * @param anchor - Target HTML element ID, with or without a leading #.\n * @param options - Scroll container, behavior, offset and visibility settings.\n * @returns True when the target exists and scrolling is initiated; otherwise false.\n * @example\n * ```ts\n * // Simple scrolling\n * scrollService.scroll('section-details');\n *\n * // With options\n * scrollService.scroll('card-123', {\n * scrollable: scrollContainerElement,\n * behavior: 'smooth',\n * topOffset: 80,\n * ignoreWhenInView: 'top'\n * });\n * ```\n */\n scroll(anchor: string, options?: ScrollOptions): boolean {\n const elementId = anchor.startsWith('#') ? anchor.slice(1) : anchor;\n const el = this.document.getElementById(elementId);\n\n if (!el) {\n return false;\n }\n\n const scrollable =\n options?.scrollable ??\n (this.document.scrollingElement as HTMLElement | null) ??\n this.document.documentElement;\n const behavior = options?.behavior ?? 'instant';\n const ignoreWhenInView = options?.ignoreWhenInView ?? 'none';\n const topOffset = options?.topOffset ?? this.TOP_OFFSET;\n\n const rect = el.getBoundingClientRect();\n const isDocument =\n scrollable === this.document.documentElement || scrollable === this.document.body;\n const containerTop = isDocument ? 0 : scrollable.getBoundingClientRect().top;\n const viewportHeight = isDocument\n ? this.document.documentElement.clientHeight\n : scrollable.clientHeight;\n const isTopInView =\n rect.top >= containerTop + topOffset - 1 && rect.top < containerTop + viewportHeight;\n const isBottomInView =\n rect.bottom <= containerTop + viewportHeight && rect.bottom > containerTop;\n\n if (\n (ignoreWhenInView == 'top' && isTopInView) ||\n (ignoreWhenInView == 'full' && isTopInView && isBottomInView) ||\n (ignoreWhenInView == 'always' && (isTopInView || isBottomInView))\n ) {\n return false;\n }\n\n // One operation keeps offsets accurate during smooth scrolling and only moves the selected container.\n scrollable.scrollTo({\n top: scrollable.scrollTop + rect.top - containerTop - topOffset,\n behavior,\n });\n\n return true;\n }\n}\n","import { inject, InjectionToken, Provider } from '@angular/core';\nimport { ScrollOptions } from '../navigation/scroll-service';\n\n/** Defaults for an application or overrides for one `magicScroll` region. */\nexport interface MagicScrollOptions {\n /** All descendant IDs participate when empty. Explicit `scrollAnchor`s also participate. */\n anchorPrefix?: string;\n /** Selector for a fixed/sticky header whose height is measured automatically. */\n headerSelector?: string;\n /** Gap below the header, or the complete top offset when no header is selected. */\n headerOffset?: number;\n /** Bottom offset in pixels to adjust the active reading boundary from the bottom. */\n bottomOffset?: number;\n /** Relative activation threshold (0.0 to 1.0) defining the trigger line within the visible reading area. */\n activationThreshold?: number;\n /** Restoration and deliberate user navigation have separate defaults. */\n behavior?: {\n restoration?: ScrollBehavior;\n interaction?: ScrollBehavior;\n };\n debounceTime?: number;\n ignoreWhenInView?: ScrollOptions['ignoreWhenInView'];\n /** Keep the current anchor visible after later data updates. Defaults to true. */\n restoreOnDataChange?: boolean;\n /** Preserve the current anchor on window resize and measured header-height changes. */\n preserveOnResize?: boolean;\n}\n\nexport interface ResolvedMagicScrollOptions {\n anchorPrefix: string;\n headerSelector: string;\n headerOffset: number;\n bottomOffset: number;\n activationThreshold: number;\n behavior: { restoration: ScrollBehavior; interaction: ScrollBehavior };\n debounceTime: number;\n ignoreWhenInView: NonNullable<ScrollOptions['ignoreWhenInView']>;\n restoreOnDataChange: boolean;\n preserveOnResize: boolean;\n}\n\nconst defaults: ResolvedMagicScrollOptions = {\n anchorPrefix: '',\n headerSelector: '',\n headerOffset: 0,\n bottomOffset: 0,\n activationThreshold: 0,\n behavior: { restoration: 'instant', interaction: 'smooth' },\n debounceTime: 500,\n ignoreWhenInView: 'none',\n restoreOnDataChange: true,\n preserveOnResize: true,\n};\n\nexport function resolveMagicScrollOptions(\n parent: ResolvedMagicScrollOptions,\n options: MagicScrollOptions,\n): ResolvedMagicScrollOptions {\n return {\n anchorPrefix: options.anchorPrefix ?? parent.anchorPrefix,\n headerSelector: options.headerSelector ?? parent.headerSelector,\n headerOffset: options.headerOffset ?? parent.headerOffset,\n bottomOffset: options.bottomOffset ?? parent.bottomOffset,\n activationThreshold: options.activationThreshold ?? parent.activationThreshold,\n behavior: {\n restoration: options.behavior?.restoration ?? parent.behavior.restoration,\n interaction: options.behavior?.interaction ?? parent.behavior.interaction,\n },\n debounceTime: options.debounceTime ?? parent.debounceTime,\n ignoreWhenInView: options.ignoreWhenInView ?? parent.ignoreWhenInView,\n restoreOnDataChange: options.restoreOnDataChange ?? parent.restoreOnDataChange,\n preserveOnResize: options.preserveOnResize ?? parent.preserveOnResize,\n };\n}\n\nexport const MAGIC_SCROLL_OPTIONS = new InjectionToken<ResolvedMagicScrollOptions>(\n 'Magic scroll defaults',\n { providedIn: 'root', factory: () => defaults },\n);\n\n/**\n * Register defaults globally or on a component. Child providers inherit unspecified options.\n * Per-region `scrollOptions` and per-call `scrollTo` options take precedence.\n *\n * @example\n * provideMagicScroll({ anchorPrefix: 'project-', behavior: { interaction: 'smooth' } })\n */\nexport function provideMagicScroll(options: MagicScrollOptions = {}): Provider {\n return {\n provide: MAGIC_SCROLL_OPTIONS,\n useFactory: () =>\n resolveMagicScrollOptions(\n inject(MAGIC_SCROLL_OPTIONS, { skipSelf: true, optional: true }) ?? defaults,\n options,\n ),\n };\n}\n","import { isSignal, Signal } from '@angular/core';\nimport { ScrollDataSource } from '../navigation/scroll-data-source';\n\n/** Structural Angular resource contract; no dependency on a data-fetching provider. */\nexport interface ScrollResource {\n readonly value: () => unknown;\n readonly isLoading: () => boolean;\n readonly hasValue?: () => boolean;\n}\n\n/**\n * Pass a signal (also computed/input/model signals), a resource/rxResource, or\n * reactive data()/isLoading() getters. Plain input values are supported too.\n * For signal forms pass the field's value signal, e.g. `form().value`.\n * Supabase data and loading signals can use the neutral ScrollDataSource contract.\n */\nexport type ScrollSource =\n | Signal<unknown>\n | ScrollResource\n | ScrollDataSource\n | object\n | string\n | number\n | boolean\n | null\n | undefined;\n\nexport const NO_SCROLL_SOURCE = Symbol('Static, already rendered data');\n\n/** Internal readiness adapter. null/undefined wait; [], 0, false and '' are ready. */\nexport function readScrollSource(source: ScrollSource | typeof NO_SCROLL_SOURCE): {\n ready: boolean;\n data: unknown;\n} {\n if (source === NO_SCROLL_SOURCE) return { ready: true, data: source };\n let data: unknown = source;\n while (isSignal(data)) data = data();\n if (data !== null && typeof data === 'object') {\n // Query results may be proxies whose `has` trap reflects the current value.\n // Read the loading getter directly: `isLoading in source` can be false when idle.\n const candidate = data as { isLoading?: unknown; data?: unknown };\n if (typeof candidate.isLoading === 'function') {\n if (candidate.isLoading()) return { ready: false, data: undefined };\n if ('value' in data && typeof data.value === 'function') {\n const resource = data as ScrollResource;\n // Reading an Angular resource's value in an error state can throw.\n data = resource.hasValue && !resource.hasValue() ? undefined : resource.value();\n } else if (typeof candidate.data === 'function') {\n data = candidate.data();\n }\n }\n }\n return { ready: data !== undefined && data !== null, data };\n}\n","import { DOCUMENT } from '@angular/common';\nimport {\n afterNextRender,\n afterRenderEffect,\n computed,\n DestroyRef,\n Directive,\n effect,\n ElementRef,\n inject,\n input,\n signal,\n untracked,\n} from '@angular/core';\nimport { ActivatedRoute } from '@angular/router';\nimport { linkedRouteFragment } from '../navigation/linked-route-fragment';\nimport { injectScrollableParentElement } from '../navigation/inject-scrollable-parent';\nimport { NearestAnchorProvider } from '../navigation/nearest-anchor.provider';\nimport { ScrollOptions, ScrollService } from '../navigation/scroll-service';\nimport {\n MAGIC_SCROLL_OPTIONS,\n MagicScrollOptions,\n resolveMagicScrollOptions,\n} from './magic-scroll-options';\nimport { NO_SCROLL_SOURCE, readScrollSource, ScrollSource } from './scroll-source';\n\n/**\n * Per-action scroll options for programmatic navigation via {@link MagicScrollDirective.scrollTo}.\n * Top offsets and container scoping are resolved automatically by the directive facade.\n */\nexport type MagicScrollToOptions = Pick<\n ScrollOptions,\n 'behavior' | 'topOffset' | 'ignoreWhenInView'\n>;\n\n/**\n * Standard keyboard navigation keys that manipulate viewport scroll position.\n * Used by {@link MagicScrollDirective} to detect manual user scroll intent and cancel\n * pending automatic initial restorations prior to asynchronous data loading readiness.\n */\nconst SCROLL_KEYS = new Set([\n 'ArrowUp',\n 'ArrowDown',\n 'PageUp',\n 'PageDown',\n 'Home',\n 'End',\n ' ',\n 'Spacebar',\n 'Space',\n]);\n\n/**\n * Determines whether a keyboard event target is an interactive or editable text control.\n * Ensures typing and navigating within input fields, textareas, dropdowns, and contenteditable\n * areas do not mistakenly cancel pending initial scroll restoration.\n */\nfunction isEditableTarget(target: EventTarget | null): boolean {\n if (!target || !(target instanceof Element)) return false;\n const tagName = target.tagName.toLowerCase();\n if (tagName === 'input' || tagName === 'textarea' || tagName === 'select') return true;\n const editableHost = target.closest('[contenteditable]');\n const editableValue = editableHost?.getAttribute('contenteditable')?.toLowerCase();\n return Boolean(\n (target as HTMLElement).isContentEditable ||\n target.closest('input, textarea, select') ||\n editableValue === '' ||\n editableValue === 'true' ||\n editableValue === 'plaintext-only',\n );\n}\n\n/**\n * Complete facade directive coordinating anchor scrolling, two-tier route synchronization,\n * user-intent cancellation, data readiness restoration, and layout/data position preservation.\n *\n * @remarks\n * ### Architectural Pillars:\n * 1. **Two-Tier Anchor State Model**:\n * - `liveAnchor`: Immediate per-scroll evaluation representing the visible section currently in view.\n * Used as the source of truth for immediate data and layout realignments.\n * - `fragment` / `activeAnchor`: Debounced (default 500ms) URL router synchronization preventing browser\n * history thrashing during continuous scrolling.\n * 2. **User Intent Detection & Cancellation**:\n * - Captures manual user gestures (`wheel`, `touchstart`, `touchmove`, navigation `keydown`) occurring prior\n * to asynchronous `scrollSource` readiness.\n * - Invalidates pending delayed initial restorations so conscious user navigation is never overridden.\n * - Safely excludes editable form controls (`<input>`, `<textarea>`, `contenteditable`).\n * 3. **Reactive Render Pipeline & Lifecycle Coordination**:\n * - Sequenced `afterRenderEffect` execution blocks guarantee sticky header measurement and `ResizeObserver`\n * monitoring are active before initial fragment restoration and data preservation execute.\n * 4. **Preservation & Realignment Engine**:\n * - Automatic realignments (`preserve('top')`) on data updates and container/header resizes based on the live active section.\n * 5. **Container & Anchor Scoping**:\n * - Automatic scroll container resolution (window vs scrollable element) and hierarchical anchor ownership isolation.\n *\n * @example\n * ```html\n * <div magicScroll #scroll=\"magicScroll\" [scrollSource]=\"projects\">\n * <section id=\"project-1\">...</section>\n * <section id=\"project-2\">...</section>\n * </div>\n * <button (click)=\"scroll.scrollTo('project-2')\">Go to Project 2</button>\n * ```\n */\n@Directive({\n selector: '[magicScroll]',\n exportAs: 'magicScroll',\n providers: [NearestAnchorProvider],\n host: { '[attr.magicScroll]': '\"\"' },\n})\nexport class MagicScrollDirective {\n /**\n * Asynchronous data source or signal determining scroll readiness.\n * - When omitted (`NO_SCROLL_SOURCE`), initial restoration executes on the initial rendered DOM.\n * - When provided, initial restoration waits until `readScrollSource(source).ready === true`.\n * Subsequent ready data updates trigger automatic position preservation when `restoreOnDataChange` is enabled.\n */\n readonly scrollSource = input<ScrollSource | typeof NO_SCROLL_SOURCE, ScrollSource>(\n NO_SCROLL_SOURCE,\n { transform: (value) => value },\n );\n\n /** Configuration overrides merged with global `provideMagicScroll` options. */\n readonly scrollOptions = input<MagicScrollOptions>({});\n\n private readonly defaults = inject(MAGIC_SCROLL_OPTIONS);\n private readonly options = computed(() =>\n resolveMagicScrollOptions(this.defaults, this.scrollOptions()),\n );\n private readonly document = inject(DOCUMENT);\n private readonly host = inject<ElementRef<HTMLElement>>(ElementRef).nativeElement;\n private readonly service = inject(ScrollService);\n private readonly nearest = inject(NearestAnchorProvider);\n\n /** Bidirectional route fragment synchronization signal (debounced URL writer and listener). */\n private readonly fragment = linkedRouteFragment();\n\n /** Initial route URL fragment snapshot captured upon directive instantiation. */\n private readonly initialAnchor = inject(ActivatedRoute).snapshot.fragment;\n\n /** Dynamically measured header height via ResizeObserver. */\n private readonly measuredHeaderHeight = signal(0);\n\n /**\n * Real-time visible section identifier updated per scroll event.\n * Serves as the source of truth for immediate data and layout realignments (`preserve`),\n * decoupling preservation from the debounced URL fragment signal.\n */\n private readonly liveAnchor = signal<string | null | undefined>(null);\n\n /** Current URL anchor, suitable for active-navigation highlighting. */\n readonly activeAnchor = this.fragment.asReadonly();\n\n /** Measured header height, useful for sticky companion panels. */\n readonly headerHeight = this.measuredHeaderHeight.asReadonly();\n\n /** Complete effective top offset, including header height and configured gap. */\n readonly offset = computed(() => this.headerHeight() + this.options().headerOffset);\n\n /** Monotonically increasing revision counter triggering debounced URL fragment updates. */\n private readonly scrollRevision = signal(0);\n\n /** Flag indicating whether the initial restoration phase has been executed. */\n private initialized = false;\n\n /**\n * Flag indicating whether manual user interaction (wheel, touch, or navigation keys) occurred\n * before asynchronous data loading became ready. When true, delayed initial restoration is skipped.\n */\n private userInterrupted = false;\n\n private target?: EventTarget;\n private timer?: ReturnType<typeof setTimeout>;\n\n constructor() {\n const destroyRef = inject(DestroyRef);\n afterNextRender(() => {\n this.refreshTarget();\n this.document.defaultView?.addEventListener('resize', this.onResize);\n });\n destroyRef.onDestroy(() => {\n this.detachListeners();\n this.document.defaultView?.removeEventListener('resize', this.onResize);\n clearTimeout(this.timer);\n });\n\n // Phase 1: Header measurement & ResizeObserver tracking.\n // Sequenced first so accurate header dimensions and offsets are available before initial restoration.\n afterRenderEffect((onCleanup) => {\n const selector = this.options().headerSelector;\n const header = selector ? this.document.querySelector<HTMLElement>(selector) : null;\n const measure = () => {\n const height = header?.getBoundingClientRect().height ?? 0;\n if (height !== this.headerHeight()) {\n this.measuredHeaderHeight.set(height);\n if (this.options().preserveOnResize) this.preserve();\n }\n };\n untracked(measure);\n if (header) {\n const observer = new ResizeObserver(measure);\n observer.observe(header);\n onCleanup(() => observer.disconnect());\n }\n });\n\n // Phase 2: Asynchronous scrollSource readiness, initial restoration, and data-change preservation.\n // Untracked execution guarantees execution triggers strictly on scrollSource readiness transitions.\n afterRenderEffect(() => {\n const source = this.scrollSource();\n const state = readScrollSource(source);\n if (!state.ready) return;\n untracked(() => {\n if (!this.initialized) {\n this.initialized = true;\n if (!this.userInterrupted) {\n this.execute(this.initialAnchor, { behavior: this.options().behavior.restoration });\n } else {\n this.liveAnchor.set(this.calculateNearestAnchor() ?? null);\n }\n } else if (source !== NO_SCROLL_SOURCE && this.options().restoreOnDataChange) {\n this.preserve('top');\n }\n });\n });\n\n // Phase 3: Route fragment synchronization to liveAnchor.\n // When the route fragment changes externally (e.g., router navigation), synchronize liveAnchor.\n effect(() => {\n const frag = this.fragment();\n untracked(() => {\n this.liveAnchor.set(frag);\n });\n });\n\n // Phase 4: Scroll revision debounced publication to URL fragment.\n // Re-evaluates nearest anchor and commits it to the URL router after debounce delay.\n effect(() => {\n if (!this.scrollRevision()) return;\n const anchor = this.calculateNearestAnchor();\n if (anchor) this.fragment.set(anchor);\n });\n }\n\n /**\n * Explicitly scrolls the viewport to the target anchor identifier.\n *\n * @param anchor - Target anchor ID (with or without leading `#`).\n * @param options - Per-call scroll overrides (behavior, top offset, ignoreWhenInView).\n * @returns `true` if the target anchor was found and scrolling initiated; `false` otherwise.\n *\n * @remarks\n * Successful execution immediately synchronizes both `liveAnchor` and the router `fragment`\n * with the target anchor, overriding any in-flight debounce delays.\n */\n scrollTo(anchor: string, options: MagicScrollToOptions = {}): boolean {\n const executed = this.execute(anchor, {\n behavior: this.options().behavior.interaction,\n ignoreWhenInView: this.options().ignoreWhenInView,\n ...options,\n });\n if (executed) {\n const clean = anchor.replace(/^#/, '');\n this.liveAnchor.set(clean);\n this.fragment.set(clean);\n }\n return executed;\n }\n\n /**\n * Queries and returns all eligible scroll anchor elements belonging strictly to this directive instance.\n *\n * @remarks\n * Anchors must possess a non-empty `id` and either match the configured `anchorPrefix` or contain\n * the `data-scroll-anchor` attribute. The `closest('[magicScroll]') === this.host` check prevents\n * nested or parent `magicScroll` directive instances from capturing child anchors across boundaries.\n */\n private anchors(): HTMLElement[] {\n const prefix = this.options().anchorPrefix;\n return Array.from(this.host.querySelectorAll<HTMLElement>('[id]')).filter(\n (el) =>\n !!el.id &&\n (el.hasAttribute('data-scroll-anchor') || el.id.startsWith(prefix)) &&\n el.closest('[magicScroll]') === this.host,\n );\n }\n\n /**\n * Resolves the active scroll container element governing viewport offsets.\n *\n * @returns The scrollable container `HTMLElement`, or `undefined` when scrolling against the document root / window.\n */\n private scrollable(): HTMLElement | undefined {\n const overflow = getComputedStyle(this.host).overflowY;\n const container =\n overflow === 'auto' || overflow === 'scroll'\n ? this.host\n : injectScrollableParentElement(this.host);\n // Root scrolling emits events on document, even when overflow is set on body/html.\n return container === this.document.documentElement || container === this.document.body\n ? undefined\n : container;\n }\n\n /**\n * Computes the nearest visible anchor according to current viewport geometry, header offsets,\n * bottom offsets, and reading direction thresholds.\n */\n private calculateNearestAnchor(): string | undefined {\n return this.nearest.getNearestAnchor({\n hostElement: this.host,\n anchors: this.anchors(),\n scrollable: this.scrollable(),\n headerOffset: this.offset(),\n bottomOffset: this.options().bottomOffset,\n activationThreshold: this.options().activationThreshold,\n });\n }\n\n /**\n * Dispatches scrolling to the underlying {@link ScrollService} after validating target presence.\n */\n private execute(anchor: string | null | undefined, options: MagicScrollToOptions): boolean {\n if (!anchor || !this.anchors().some((el) => el.id === anchor.replace(/^#/, ''))) return false;\n return this.service.scroll(anchor, {\n scrollable: this.scrollable(),\n topOffset: this.offset(),\n ...options,\n });\n }\n\n /**\n * Realigns the viewport instantly to preserve position during asynchronous data updates\n * or container / header dimension changes.\n *\n * @remarks\n * Targets `liveAnchor` (the real-time visible section) rather than `fragment` (the debounced URL fragment)\n * to ensure rapid data or layout shifts during continuous scrolling maintain the user's active view\n * rather than jumping back to a stale URL anchor.\n */\n private preserve(ignoreWhenInView: ScrollOptions['ignoreWhenInView'] = 'none'): void {\n if (this.initialized) {\n this.execute(this.liveAnchor(), { behavior: 'instant', ignoreWhenInView });\n }\n }\n\n /**\n * Updates target container references and re-binds passive event listeners whenever\n * the scroll container shifts dynamically.\n */\n private refreshTarget(): void {\n const target = this.scrollable() ?? this.document;\n if (target !== this.target) {\n this.detachListeners();\n this.target = target;\n this.attachListeners(target);\n }\n }\n\n /**\n * Attaches passive scroll, gesture, and keyboard listeners to track user intent and scroll motion.\n */\n private attachListeners(target: EventTarget): void {\n target.addEventListener('scroll', this.onScroll);\n target.addEventListener('wheel', this.onUserIntent, { passive: true });\n target.addEventListener('touchstart', this.onUserIntent, { passive: true });\n target.addEventListener('touchmove', this.onUserIntent, { passive: true });\n target.addEventListener('keydown', this.onKeyDown);\n this.document.addEventListener('keydown', this.onKeyDown);\n }\n\n /**\n * Detaches all registered event listeners to ensure clean teardown without memory leaks.\n */\n private detachListeners(): void {\n if (!this.target) return;\n this.target.removeEventListener('scroll', this.onScroll);\n this.target.removeEventListener('wheel', this.onUserIntent);\n this.target.removeEventListener('touchstart', this.onUserIntent);\n this.target.removeEventListener('touchmove', this.onUserIntent);\n this.target.removeEventListener('keydown', this.onKeyDown);\n this.document.removeEventListener('keydown', this.onKeyDown);\n }\n\n /**\n * Intercepts manual user gestures (`wheel`, `touchstart`, `touchmove`) to flag user interaction\n * and cancel delayed initial restorations prior to data readiness.\n */\n private readonly onUserIntent = () => {\n this.userInterrupted = true;\n };\n\n /**\n * Intercepts navigation keyboard events (`ArrowUp`, `ArrowDown`, `PageUp`, `PageDown`, `Home`, `End`, `Space`).\n * Cancels pending initial restoration when navigation occurs within the relevant scroll context\n * while safely ignoring interactions on editable input elements.\n */\n private readonly onKeyDown = (event: Event) => {\n if (!(event instanceof KeyboardEvent)) return;\n if (isEditableTarget(event.target)) return;\n if (!SCROLL_KEYS.has(event.key)) return;\n const targetEl = event.target as Element | null;\n const scrollable = this.scrollable();\n const isInsideContext =\n !targetEl ||\n targetEl === this.document.body ||\n targetEl === this.document.documentElement ||\n (scrollable ? scrollable === targetEl || scrollable.contains(targetEl) : true);\n if (isInsideContext) {\n this.userInterrupted = true;\n }\n };\n\n /**\n * Handles scroll events by immediately updating `liveAnchor` for position preservation,\n * while debouncing `scrollRevision` increments to update the browser URL fragment without thrashing history.\n */\n private readonly onScroll = () => {\n if (!this.initialized) return;\n const anchor = this.calculateNearestAnchor();\n if (anchor) this.liveAnchor.set(anchor);\n clearTimeout(this.timer);\n this.timer = setTimeout(\n () => this.scrollRevision.update((revision) => revision + 1),\n this.options().debounceTime,\n );\n };\n\n /**\n * Handles window resize events by re-evaluating targets and optionally realigning the active anchor.\n */\n private readonly onResize = () => {\n this.refreshTarget();\n if (this.options().preserveOnResize) this.preserve();\n };\n}\n","import { Directive, effect, ElementRef, inject, input } from '@angular/core';\n\n/**\n * Optional explicit anchor. Its ID participates even outside the configured prefix.\n * Use `scrollAnchor` alongside an existing id, or `[scrollAnchor]=\"item.id\"` to set it.\n */\n@Directive({\n selector: '[scrollAnchor]',\n host: { '[attr.data-scroll-anchor]': '\"\"' },\n})\nexport class ScrollAnchorDirective {\n readonly scrollAnchor = input('');\n private readonly host = inject<ElementRef<HTMLElement>>(ElementRef);\n constructor() {\n effect(() => {\n const id = this.scrollAnchor();\n if (id) this.host.nativeElement.id = id;\n });\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4BA,SAAgB,sBAAmB;CACjC,MAAM,QAAQ,OAAO,cAAc;CACnC,MAAM,SAAS,OAAO,MAAM;CAC5B,MAAM,WAAW,SAAS,MAAM,QAAQ;CAExC,MAAM,iBAAiB,mBAAmB,SAAQ,GAAG,GAAA,YAAA,CAAA,EAAA,WAAA,iBAAA,CAAA,+BAAA,CAAA,CAAA;CAErD,aAAY;EACV,MAAM,cAAc,eAAc;EAClC,IAAI,MAAM,SAAS,aAAa,aAAa;GAC3C,MAAM,OAAO,OAAO,cAAc,CAAA,GAAI;IACpC,YAAY;IACZ,UAAU,eAAe;IACzB,qBAAqB;GACtB,CAAA;GAED,OAAO,cAAc,MAAM,EAAE,YAAY,KAAI,CAAE,CAAC,CAAC,OAAO,UAAgB;IACtE,QAAQ,IAAI,qBAAqB,eAAe,KAAK;GACvD,CAAC;EACH;CACF,CAAC;CAED,OAAO;AACT;AC9BA,SAAgB,8BACd,aAAgC;CAEhC,SAAS,qBAAqB,IA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EAAA,SAAA;EAAA,MAAA;EAAqB,cAAA;EAAA,UAAA;EAAA,QAAA,EAAA,cAAA;GAAA,mBAAA;GAAA,YAAA;GAAA,UAAA;GAAA,YAAA;GAAA,mBAAA;EAAA,EAAA;EAAA,MAAA,EAAA,YAAA,EAAA,2BAAA,OAAA,EAAA;EAAA,UAAA;CAAA,CAAA;;AAArB,GAAA,yBAAA;CAAA,YAAA;CAAA,SAAA;CAAA,UAAA;CAAA,MAAA;CAAqB,YAAA,CAAA;EAJjC,MAAA;EAAU,MAAA,CAAA;GACT,UAAU;GACV,MAAM,EAAE,6BAA6B,OAAI;EAC1C,CAAA"}
|
|
1
|
+
{"version":3,"file":"devzwo-ngx-magic-scroll.mjs","names":[],"sources":["../../../projects/ngx-magic-scroll/src/lib/navigation/linked-route-fragment.ts","../../../projects/ngx-magic-scroll/src/lib/navigation/inject-scrollable-parent.ts","../../../projects/ngx-magic-scroll/src/lib/navigation/inject-header-size.ts","../../../projects/ngx-magic-scroll/src/lib/navigation/nearest-anchor.provider.ts","../../../projects/ngx-magic-scroll/src/lib/navigation/scroll-service.ts","../../../projects/ngx-magic-scroll/src/lib/facade/magic-scroll-options.ts","../../../projects/ngx-magic-scroll/src/lib/facade/scroll-source.ts","../../../projects/ngx-magic-scroll/src/lib/facade/magic-scroll.directive.ts","../../../projects/ngx-magic-scroll/src/lib/facade/scroll-anchor.directive.ts"],"sourcesContent":["import { effect, inject, linkedSignal, WritableSignal } from '@angular/core';\nimport { toSignal } from '@angular/core/rxjs-interop';\nimport { ActivatedRoute, Router } from '@angular/router';\n\n/**\n * Key used to tag internal library-initiated scroll-spy navigation events.\n */\nexport const MAGIC_SCROLL_ORIGIN_KEY = '__ngx_magic_scroll_origin';\n\n/**\n * Value identifying an internal scroll-spy navigation origin.\n */\nexport const MAGIC_SCROLL_ORIGIN_SCROLL_SPY = 'scroll-spy';\n\n/**\n * Creates an Angular signal synchronized bidirectionally with the URL fragment (#fragment).\n *\n * Reads the current route fragment as a writable signal (WritableSignal).\n * - Reading reacts to URL fragment changes through ActivatedRoute.fragment.\n * - Writing, for example fragmentSignal.set('anchor-id'), asynchronously updates the URL\n * through Router.navigateByUrl with replaceUrl: true and origin tagging. This preserves query parameters\n * and avoids adding a history entry for each scroll update while distinguishing scroll-spy updates from\n * external user navigations.\n *\n * @returns A WritableSignal<string | null | undefined> linked to the URL fragment.\n * @example\n * ```ts\n * @Component({ ... })\n * export class MyViewComponent {\n * // Initialize the signal\n * protected readonly routeFragment = linkedRouteFragment();\n *\n * onAnchorReached(anchorId: string) {\n * // Update the URL fragment without adding history entries (#anchorId)\n * this.routeFragment.set(anchorId);\n * }\n * }\n * ```\n */\nexport function linkedRouteFragment(): WritableSignal<string | null | undefined> {\n const route = inject(ActivatedRoute);\n const router = inject(Router);\n const fragment = toSignal(route.fragment);\n\n const actualFragment = linkedSignal(() => fragment());\n\n effect(() => {\n const newFragment = actualFragment();\n const currentRouteFragment = fragment();\n if (currentRouteFragment !== newFragment) {\n const tree = router.createUrlTree([], {\n relativeTo: route,\n fragment: newFragment ?? undefined,\n queryParamsHandling: 'preserve',\n });\n\n router\n .navigateByUrl(tree, {\n replaceUrl: true,\n state: {\n ...history.state,\n [MAGIC_SCROLL_ORIGIN_KEY]: MAGIC_SCROLL_ORIGIN_SCROLL_SPY,\n },\n info: { [MAGIC_SCROLL_ORIGIN_KEY]: MAGIC_SCROLL_ORIGIN_SCROLL_SPY },\n })\n .catch((error: Error) => {\n console.log(`Cant set fragment ${newFragment}`, error);\n });\n }\n });\n\n return actualFragment;\n}\n","import { ElementRef, inject } from '@angular/core';\n\n/**\n * Finds the closest scrollable ancestor in the DOM.\n *\n * Walks up the DOM tree looking for overflow-y: auto or overflow-y: scroll.\n * Call within an Angular injection context to start at ElementRef.nativeElement,\n * or pass a hostElement explicitly.\n *\n * @param hostElement - Optional starting element. An explicit element takes precedence;\n * otherwise the starting element is obtained by injecting ElementRef<HTMLElement>.\n * @returns The closest scrollable HTMLElement, or undefined if none exists.\n * @example\n * ```ts\n * // Within an injection context (for example a directive or component constructor):\n * const scrollParent = injectScrollableParentElement();\n *\n * // Outside an injection context:\n * const scrollParent = injectScrollableParentElement(myHtmlElement);\n * ```\n */\nexport function injectScrollableParentElement(\n hostElement?: HTMLElement | null,\n): HTMLElement | undefined {\n function findScrollableParent(el: HTMLElement): HTMLElement | undefined {\n let current = el.parentElement ?? undefined;\n while (current) {\n const overflowY = getComputedStyle(current).overflowY;\n if (\n overflowY === 'auto' ||\n overflowY === 'scroll' /**&& current.scrollHeight > current.clientHeight **/\n ) {\n return current;\n }\n current = current.parentElement ?? undefined;\n }\n return undefined;\n }\n\n return findScrollableParent(\n hostElement ?? (inject(ElementRef<HTMLElement>).nativeElement as HTMLElement),\n );\n}\n","/**\n * Measures the height of a header selected within the supplied document.\n * Used to calculate scroll and anchor offsets so a fixed or sticky header does not\n * cover the scrolled content.\n *\n * @param headerSelector - Header CSS selector, such as '.header' or 'app-header'.\n * @param document - Document instance in which to search, for example injected through DOCUMENT.\n * @returns The absolute header height in pixels, or 0 if the element is not found.\n * @example\n * ```ts\n * const document = inject(DOCUMENT);\n * const height = injectedHeaderHeight('.header', document);\n * ```\n */\nexport function injectedHeaderHeight(headerSelector: string, document: Document): number {\n const boundingBox = document.querySelector<HTMLElement>(headerSelector)?.getBoundingClientRect();\n if (!boundingBox) {\n console.warn('No boundingBox found for headerSelector: ', headerSelector);\n return 0;\n }\n\n return Math.abs(boundingBox.height);\n}\n","import { DOCUMENT } from '@angular/common';\nimport { inject, Injectable } from '@angular/core';\nimport { injectScrollableParentElement } from './inject-scrollable-parent';\nimport { injectedHeaderHeight } from './inject-header-size';\n\n/**\n * Options for finding the nearest anchor.\n */\nexport interface NearestAnchorOptions {\n /** Explicit scroll container, including a host that is itself scrollable. */\n scrollable?: HTMLElement;\n /** Preselected anchor elements (e.g. scoped, explicit anchors in the facade). */\n anchors?: readonly HTMLElement[];\n /**\n * Optional host element within which to find anchor elements.\n * Defaults to searching the entire Document.\n */\n hostElement?: HTMLElement;\n /**\n * CSS selector for eligible anchors, for example '[id^=\"item-card-\"]'.\n * Defaults to '[id]'.\n */\n selector?: string;\n /**\n * Static top offset, in pixels, such as a fixed gap or padding.\n */\n headerOffset?: number;\n /**\n * CSS selector for a fixed or sticky header, for example '.header'.\n * Its measured height is added to the offset so covered elements are not selected\n * as the topmost visible anchor.\n */\n headerSelector?: string;\n /**\n * Static bottom offset, in pixels, such as a sticky footer gap or bottom margin.\n */\n bottomOffset?: number;\n /**\n * Relative activation threshold (0.0 to 1.0) defining the trigger line within the visible reading area.\n */\n activationThreshold?: number;\n}\n\n/**\n * Finds the anchor representing the currently read section based on full containment and activation boundaries.\n *\n * Supports scroll-spy behavior to identify the current section while scrolling and\n * synchronize the URL fragment. A section is activated immediately when fully visible in the\n * viewport below sticky headers, or remains active while scrolling through its content until\n * the next section crosses the activation boundary or becomes fully visible.\n *\n * @remarks\n * This service does not use providedIn: 'root'. Register it in application or component\n * providers when using it internally. The facade provides its own instance.\n */\n@Injectable()\nexport class NearestAnchorProvider {\n private readonly document = inject(DOCUMENT);\n\n /**\n * Calculates the ID of the active anchor based on scroll position and visible area boundaries.\n *\n * 1. Evaluates all eligible anchors within the host or document.\n * 2. Determines the visible reading area (`topBoundary = scrollableTop + headerOffset + headerHeight`, `bottomBoundary = (containerBottom | viewportHeight) - bottomOffset`).\n * 3. Prioritizes fully contained anchors (`top >= topBoundary - 1` and `bottom <= bottomBoundary + 1`), selecting the topmost one.\n * 4. Falls back to the anchor that crossed `triggerLine` most recently (`top <= triggerLine + 1`).\n * 5. Falls back to the first anchor if no anchor has crossed the boundary yet.\n *\n * @param options - Host element, selector, scroll container and header-offset settings.\n * @returns The active anchor's element ID, or undefined if no eligible element exists.\n * @example\n * ```ts\n * const nearestId = nearestAnchorProvider.getNearestAnchor({\n * hostElement: listContainer,\n * selector: '[id^=\"card-\"]',\n * headerSelector: '.app-header',\n * bottomOffset: 40\n * });\n * ```\n */\n public getNearestAnchor(options?: NearestAnchorOptions): string | undefined {\n const host = options?.hostElement ?? this.document;\n const selector = options?.selector ?? '[id]';\n const offset =\n (options?.headerOffset ?? 0) +\n (options?.headerSelector ? injectedHeaderHeight(options.headerSelector, this.document) : 0);\n\n // Collects all HTML elements with an id – these are our potential anchor targets\n const anchors = options?.anchors ?? Array.from(host.querySelectorAll<HTMLElement>(selector));\n if (anchors.length === 0) {\n return undefined;\n }\n\n const scrollable =\n options?.scrollable ??\n (options?.hostElement ? injectScrollableParentElement(options.hostElement) : undefined);\n const isDocument =\n !scrollable ||\n scrollable === this.document.documentElement ||\n scrollable === this.document.body;\n const topBoundary = (isDocument ? 0 : scrollable.getBoundingClientRect().top) + offset;\n const viewportBottom = isDocument\n ? (this.document.defaultView?.innerHeight ?? this.document.documentElement.clientHeight)\n : scrollable.getBoundingClientRect().bottom;\n const bottomBoundary = Math.max(\n topBoundary,\n viewportBottom - Math.max(0, options?.bottomOffset ?? 0),\n );\n\n // 1. Check for fully contained anchors (entire element inside visible reading area)\n const containedAnchors = anchors.filter((el) => {\n const rect = el.getBoundingClientRect();\n return rect.top >= topBoundary - 1 && rect.bottom <= bottomBoundary + 1;\n });\n\n if (containedAnchors.length > 0) {\n // Topmost fully visible anchor\n const topmostContained = containedAnchors.reduce((best, el) =>\n el.getBoundingClientRect().top < best.getBoundingClientRect().top ? el : best,\n );\n return topmostContained.id;\n }\n\n // 2. Reading line fallback: Anchor that crossed triggerLine most recently\n const threshold = Math.max(0, Math.min(1, options?.activationThreshold ?? 0));\n const triggerLine = topBoundary + (bottomBoundary - topBoundary) * threshold;\n const passedAnchors = anchors.filter((el) => el.getBoundingClientRect().top <= triggerLine + 1);\n\n if (passedAnchors.length > 0) {\n // Pick the anchor that crossed the trigger line most recently (highest top <= triggerLine)\n const active = passedAnchors.reduce((best, el) =>\n el.getBoundingClientRect().top > best.getBoundingClientRect().top ? el : best,\n );\n return active.id;\n }\n\n // 3. Before any anchor has reached the boundary, select the first anchor\n const first = anchors.reduce((best, el) =>\n el.getBoundingClientRect().top < best.getBoundingClientRect().top ? el : best,\n );\n return first.id;\n }\n}\n","import { inject, Injectable } from '@angular/core';\nimport { DOCUMENT } from '@angular/common';\n\n/**\n * Options for a scroll operation performed by ScrollService.\n */\nexport interface ScrollOptions {\n /**\n * Scrollable container. Defaults to the document's scrolling element.\n */\n scrollable?: HTMLElement;\n /**\n * Scroll behavior: 'instant' for an immediate jump, 'smooth' for animation,\n * or 'auto' to follow the browser's CSS scroll behavior. Defaults to 'instant'.\n */\n behavior?: ScrollBehavior;\n /**\n * Visibility condition under which scrolling is skipped:\n * - 'none': Always scroll (default).\n * - 'top': Skip when the element's top edge is visible.\n * - 'full': Skip when the entire element is visible.\n * - 'always': Skip when either the top or bottom edge is visible.\n */\n ignoreWhenInView?: 'none' | 'top' | 'full' | 'always';\n /**\n * Additional top offset for the target, in pixels, for example for a header or padding.\n * Defaults to 20 pixels.\n */\n topOffset?: number;\n /**\n * Target anchor-relative pixel displacement relative to the top offset boundary.\n * Negative values position the element higher (scrolled into), positive values lower.\n * Defaults to 0 (element top aligned to topOffset).\n */\n displacement?: number;\n /**\n * Whether to transfer DOM focus to the resolved anchor element.\n * Uses `preventScroll: true` and temporary `tabindex=\"-1\"` for non-focusable targets.\n * Defaults to `false`.\n */\n focus?: boolean;\n}\n\n/**\n * Central service for scrolling to DOM elements and anchors.\n *\n * Supports explicit scroll containers or document scrolling, configurable header offsets,\n * visibility checks to avoid unnecessary movement, and smooth or instant scrolling.\n */\n@Injectable({\n providedIn: 'root',\n})\nexport class ScrollService {\n private readonly document = inject<Document>(DOCUMENT);\n private readonly TOP_OFFSET = 20;\n\n /**\n * Scrolls to the element identified by its ID.\n *\n * @param anchor - Target HTML element ID, with or without a leading #.\n * @param options - Scroll container, behavior, offset and visibility settings.\n * @returns True when the target exists and scrolling is initiated; otherwise false.\n * @example\n * ```ts\n * // Simple scrolling\n * scrollService.scroll('section-details');\n *\n * // With options\n * scrollService.scroll('card-123', {\n * scrollable: scrollContainerElement,\n * behavior: 'smooth',\n * topOffset: 80,\n * ignoreWhenInView: 'top'\n * });\n * ```\n */\n scroll(anchor: string, options?: ScrollOptions): boolean {\n const elementId = anchor.startsWith('#') ? anchor.slice(1) : anchor;\n const el = this.document.getElementById(elementId);\n\n if (!el) {\n return false;\n }\n\n const scrollable =\n options?.scrollable ??\n (this.document.scrollingElement as HTMLElement | null) ??\n this.document.documentElement;\n const behavior = options?.behavior ?? 'instant';\n const ignoreWhenInView = options?.ignoreWhenInView ?? 'none';\n const topOffset = options?.topOffset ?? this.TOP_OFFSET;\n\n const rect = el.getBoundingClientRect();\n const isDocument =\n scrollable === this.document.documentElement || scrollable === this.document.body;\n const containerTop = isDocument ? 0 : scrollable.getBoundingClientRect().top;\n const viewportHeight = isDocument\n ? this.document.documentElement.clientHeight\n : scrollable.clientHeight;\n const isTopInView =\n rect.top >= containerTop + topOffset - 1 && rect.top < containerTop + viewportHeight;\n const isBottomInView =\n rect.bottom <= containerTop + viewportHeight && rect.bottom > containerTop;\n\n if (\n (ignoreWhenInView == 'top' && isTopInView) ||\n (ignoreWhenInView == 'full' && isTopInView && isBottomInView) ||\n (ignoreWhenInView == 'always' && (isTopInView || isBottomInView))\n ) {\n return false;\n }\n\n const displacement = options?.displacement ?? 0;\n const currentDisplacement = rect.top - containerTop - topOffset;\n const delta = currentDisplacement - displacement;\n\n // Viewport-relative boundary clamping ensures scrolling stays within valid container limits.\n const maxScrollTop =\n scrollable.scrollHeight > 0 && viewportHeight > 0\n ? Math.max(0, scrollable.scrollHeight - viewportHeight)\n : Infinity;\n const targetScrollTop = Math.min(Math.max(scrollable.scrollTop + delta, 0), maxScrollTop);\n\n // Skip redundant DOM scrollTo dispatch when already aligned (sub-pixel delta < 1px).\n if (Math.abs(targetScrollTop - scrollable.scrollTop) < 1) {\n return true;\n }\n\n // One operation keeps offsets accurate during smooth scrolling and only moves the selected container.\n scrollable.scrollTo({\n top: targetScrollTop,\n behavior,\n });\n\n return true;\n }\n}\n","import { inject, InjectionToken, Provider } from '@angular/core';\nimport { ScrollOptions } from '../navigation/scroll-service';\n\n/**\n * Anchor selection strategy for a `magicScroll` region.\n * - `'all'`: Default strategy. Descendant elements matching any configured `anchorPrefixes`\n * (or all non-empty IDs if no prefix is configured) as well as explicit `scrollAnchor` markers participate.\n * - `'explicit'`: Strict explicit-only mode. Only elements marked with `[scrollAnchor]` or `scrollAnchor`\n * participate, regardless of their element ID or configured prefixes.\n */\nexport type AnchorSelectionMode = 'all' | 'explicit';\n\n/** Defaults for an application or overrides for one `magicScroll` region. */\nexport interface MagicScrollOptions {\n /**\n * Allowed anchor ID prefixes. Descendant elements matching any prefix participate.\n * Explicit `scrollAnchor` markers also participate.\n * Passing an empty array `[]` disables prefix matching so only explicit markers participate.\n */\n anchorPrefixes?: readonly string[] | string[];\n /**\n * Selection strategy for anchor discovery.\n * - `'all'`: Selects elements matching prefixes or explicit markers (default).\n * - `'explicit'`: Selects only elements with explicit `scrollAnchor` markers.\n */\n anchorSelection?: AnchorSelectionMode;\n /** Selector for a fixed/sticky header whose height is measured automatically. */\n headerSelector?: string;\n /** Gap below the header, or the complete top offset when no header is selected. */\n headerOffset?: number;\n /** Bottom offset in pixels to adjust the active reading boundary from the bottom. */\n bottomOffset?: number;\n /** Relative activation threshold (0.0 to 1.0) defining the trigger line within the visible reading area. */\n activationThreshold?: number;\n /** Restoration and deliberate user navigation have separate defaults. */\n behavior?: {\n restoration?: ScrollBehavior;\n interaction?: ScrollBehavior;\n };\n debounceTime?: number;\n ignoreWhenInView?: ScrollOptions['ignoreWhenInView'];\n /** Keep the current anchor visible after later data updates. Defaults to true. */\n restoreOnDataChange?: boolean;\n /** Preserve the current anchor on window resize and measured header-height changes. */\n preserveOnResize?: boolean;\n /**\n * Preserve anchor-relative reading position when region content reflows\n * (e.g. image loads, form expansions, accordion toggles) without changing scrollSource.\n * Defaults to false (explicit opt-in).\n */\n preserveOnLayoutChange?: boolean;\n}\n\nexport interface ResolvedMagicScrollOptions {\n anchorPrefixes: readonly string[];\n anchorSelection: AnchorSelectionMode;\n headerSelector: string;\n headerOffset: number;\n bottomOffset: number;\n activationThreshold: number;\n behavior: { restoration: ScrollBehavior; interaction: ScrollBehavior };\n debounceTime: number;\n ignoreWhenInView: NonNullable<ScrollOptions['ignoreWhenInView']>;\n restoreOnDataChange: boolean;\n preserveOnResize: boolean;\n preserveOnLayoutChange: boolean;\n}\n\nconst defaults: ResolvedMagicScrollOptions = {\n anchorPrefixes: [''],\n anchorSelection: 'all',\n headerSelector: '',\n headerOffset: 0,\n bottomOffset: 0,\n activationThreshold: 0,\n behavior: { restoration: 'instant', interaction: 'smooth' },\n debounceTime: 500,\n ignoreWhenInView: 'none',\n restoreOnDataChange: true,\n preserveOnResize: true,\n preserveOnLayoutChange: false,\n};\n\nexport function resolveMagicScrollOptions(\n parent: ResolvedMagicScrollOptions,\n options: MagicScrollOptions,\n): ResolvedMagicScrollOptions {\n return {\n anchorPrefixes: options.anchorPrefixes ?? parent.anchorPrefixes,\n anchorSelection: options.anchorSelection ?? parent.anchorSelection,\n headerSelector: options.headerSelector ?? parent.headerSelector,\n headerOffset: options.headerOffset ?? parent.headerOffset,\n bottomOffset: options.bottomOffset ?? parent.bottomOffset,\n activationThreshold: options.activationThreshold ?? parent.activationThreshold,\n behavior: {\n restoration: options.behavior?.restoration ?? parent.behavior.restoration,\n interaction: options.behavior?.interaction ?? parent.behavior.interaction,\n },\n debounceTime: options.debounceTime ?? parent.debounceTime,\n ignoreWhenInView: options.ignoreWhenInView ?? parent.ignoreWhenInView,\n restoreOnDataChange: options.restoreOnDataChange ?? parent.restoreOnDataChange,\n preserveOnResize: options.preserveOnResize ?? parent.preserveOnResize,\n preserveOnLayoutChange: options.preserveOnLayoutChange ?? parent.preserveOnLayoutChange,\n };\n}\n\nexport const MAGIC_SCROLL_OPTIONS = new InjectionToken<ResolvedMagicScrollOptions>(\n 'Magic scroll defaults',\n { providedIn: 'root', factory: () => defaults },\n);\n\n/**\n * Register defaults globally or on a component. Child providers inherit unspecified options.\n * Per-region `scrollOptions` and per-call `scrollTo` options take precedence.\n *\n * @example\n * provideMagicScroll({ anchorPrefixes: ['project-'], behavior: { interaction: 'smooth' } })\n */\nexport function provideMagicScroll(options: MagicScrollOptions = {}): Provider {\n return {\n provide: MAGIC_SCROLL_OPTIONS,\n useFactory: () =>\n resolveMagicScrollOptions(\n inject(MAGIC_SCROLL_OPTIONS, { skipSelf: true, optional: true }) ?? defaults,\n options,\n ),\n };\n}\n","import { isSignal, Signal } from '@angular/core';\nimport { ScrollDataSource } from '../navigation/scroll-data-source';\n\n/** Structural Angular resource contract; no dependency on a data-fetching provider. */\nexport interface ScrollResource {\n readonly value: () => unknown;\n readonly isLoading: () => boolean;\n readonly hasValue?: () => boolean;\n}\n\n/**\n * Pass a signal (also computed/input/model signals), a resource/rxResource, or\n * reactive data()/isLoading() getters. Plain input values are supported too.\n * For signal forms pass the field's value signal, e.g. `form().value`.\n * Supabase data and loading signals can use the neutral ScrollDataSource contract.\n */\nexport type ScrollSource =\n | Signal<unknown>\n | ScrollResource\n | ScrollDataSource\n | object\n | string\n | number\n | boolean\n | null\n | undefined;\n\nexport const NO_SCROLL_SOURCE = Symbol('Static, already rendered data');\n\n/** Internal readiness adapter. null/undefined wait; [], 0, false and '' are ready. */\nexport function readScrollSource(source: ScrollSource | typeof NO_SCROLL_SOURCE): {\n ready: boolean;\n data: unknown;\n} {\n if (source === NO_SCROLL_SOURCE) return { ready: true, data: source };\n let data: unknown = source;\n while (isSignal(data)) data = data();\n if (data !== null && typeof data === 'object') {\n // Query results may be proxies whose `has` trap reflects the current value.\n // Read the loading getter directly: `isLoading in source` can be false when idle.\n const candidate = data as { isLoading?: unknown; data?: unknown };\n if (typeof candidate.isLoading === 'function') {\n if (candidate.isLoading()) return { ready: false, data: undefined };\n if ('value' in data && typeof data.value === 'function') {\n const resource = data as ScrollResource;\n // Reading an Angular resource's value in an error state can throw.\n data = resource.hasValue && !resource.hasValue() ? undefined : resource.value();\n } else if (typeof candidate.data === 'function') {\n data = candidate.data();\n }\n }\n }\n return { ready: data !== undefined && data !== null, data };\n}\n","import { DOCUMENT } from '@angular/common';\nimport {\n afterNextRender,\n afterRenderEffect,\n computed,\n DestroyRef,\n Directive,\n effect,\n ElementRef,\n inject,\n input,\n signal,\n untracked,\n} from '@angular/core';\nimport { ActivatedRoute, Navigation, Router } from '@angular/router';\nimport {\n linkedRouteFragment,\n MAGIC_SCROLL_ORIGIN_KEY,\n MAGIC_SCROLL_ORIGIN_SCROLL_SPY,\n} from '../navigation/linked-route-fragment';\nimport { injectScrollableParentElement } from '../navigation/inject-scrollable-parent';\nimport { NearestAnchorProvider } from '../navigation/nearest-anchor.provider';\nimport { ScrollOptions, ScrollService } from '../navigation/scroll-service';\nimport {\n MAGIC_SCROLL_OPTIONS,\n MagicScrollOptions,\n resolveMagicScrollOptions,\n} from './magic-scroll-options';\nimport { NO_SCROLL_SOURCE, readScrollSource, ScrollSource } from './scroll-source';\n\n/**\n * Per-action scroll options for programmatic navigation via {@link MagicScrollDirective.scrollTo}.\n * Top offsets and container scoping are resolved automatically by the directive facade.\n */\nexport type MagicScrollToOptions = Pick<\n ScrollOptions,\n 'behavior' | 'topOffset' | 'ignoreWhenInView' | 'focus'\n>;\n\n/**\n * Standard keyboard navigation keys that manipulate viewport scroll position.\n * Used by {@link MagicScrollDirective} to detect manual user scroll intent and cancel\n * pending automatic initial restorations prior to asynchronous data loading readiness.\n */\nconst SCROLL_KEYS = new Set([\n 'ArrowUp',\n 'ArrowDown',\n 'PageUp',\n 'PageDown',\n 'Home',\n 'End',\n ' ',\n 'Spacebar',\n 'Space',\n]);\n\n/**\n * Determines whether an element is naturally focusable by default or possesses an explicit tabindex.\n */\nfunction isNaturallyFocusable(el: HTMLElement): boolean {\n if (el.hasAttribute('tabindex')) {\n return true;\n }\n const tag = el.tagName.toLowerCase();\n if (tag === 'button' || tag === 'select' || tag === 'textarea') {\n return !(el as HTMLButtonElement | HTMLSelectElement | HTMLTextAreaElement).disabled;\n }\n if (tag === 'input') {\n return (el as HTMLInputElement).type !== 'hidden' && !(el as HTMLInputElement).disabled;\n }\n if (tag === 'a' || tag === 'area') {\n return el.hasAttribute('href');\n }\n if (tag === 'iframe') {\n return true;\n }\n return false;\n}\n\n/**\n * Determines whether a keyboard event target is an interactive or editable text control.\n * Ensures typing and navigating within input fields, textareas, dropdowns, and contenteditable\n * areas do not mistakenly cancel pending initial scroll restoration.\n */\nfunction isEditableTarget(target: EventTarget | null): boolean {\n if (!target || !(target instanceof Element)) return false;\n const tagName = target.tagName.toLowerCase();\n if (tagName === 'input' || tagName === 'textarea' || tagName === 'select') return true;\n const editableHost = target.closest('[contenteditable]');\n const editableValue = editableHost?.getAttribute('contenteditable')?.toLowerCase();\n return Boolean(\n (target as HTMLElement).isContentEditable ||\n target.closest('input, textarea, select') ||\n editableValue === '' ||\n editableValue === 'true' ||\n editableValue === 'plaintext-only',\n );\n}\n\n/**\n * Complete facade directive coordinating anchor scrolling, two-tier route synchronization,\n * user-intent cancellation, data readiness restoration, and layout/data position preservation.\n *\n * @remarks\n * ### Architectural Pillars:\n * 1. **Two-Tier Anchor State Model**:\n * - `liveAnchor`: Immediate per-scroll evaluation representing the visible section currently in view.\n * Used as the source of truth for immediate data and layout realignments.\n * - `fragment` / `activeAnchor`: Debounced (default 500ms) URL router synchronization preventing browser\n * history thrashing during continuous scrolling.\n * 2. **User Intent Detection & Cancellation**:\n * - Captures manual user gestures (`wheel`, `touchstart`, `touchmove`, navigation `keydown`) occurring prior\n * to asynchronous `scrollSource` readiness.\n * - Invalidates pending delayed initial restorations so conscious user navigation is never overridden.\n * - Safely excludes editable form controls (`<input>`, `<textarea>`, `contenteditable`).\n * 3. **Reactive Render Pipeline & Lifecycle Coordination**:\n * - Sequenced `afterRenderEffect` execution blocks guarantee sticky header measurement and `ResizeObserver`\n * monitoring are active before initial fragment restoration and data preservation execute.\n * 4. **Preservation & Realignment Engine**:\n * - Automatic realignments (`preserve()`) on data updates and container/header resizes based on the live active section.\n * 5. **Container & Anchor Scoping**:\n * - Automatic scroll container resolution (window vs scrollable element) and hierarchical anchor ownership isolation.\n *\n * @example\n * ```html\n * <div magicScroll #scroll=\"magicScroll\" [scrollSource]=\"projects\">\n * <section id=\"project-1\">...</section>\n * <section id=\"project-2\">...</section>\n * </div>\n * <button (click)=\"scroll.scrollTo('project-2')\">Go to Project 2</button>\n * ```\n */\n@Directive({\n selector: '[magicScroll]',\n exportAs: 'magicScroll',\n providers: [NearestAnchorProvider],\n host: { '[attr.magicScroll]': '\"\"' },\n})\nexport class MagicScrollDirective {\n /**\n * Asynchronous data source or signal determining scroll readiness.\n * - When omitted (`NO_SCROLL_SOURCE`), initial restoration executes on the initial rendered DOM.\n * - When provided, initial restoration waits until `readScrollSource(source).ready === true`.\n * Subsequent ready data updates trigger automatic position preservation when `restoreOnDataChange` is enabled.\n */\n readonly scrollSource = input<ScrollSource | typeof NO_SCROLL_SOURCE, ScrollSource>(\n NO_SCROLL_SOURCE,\n { transform: (value) => value },\n );\n\n /** Configuration overrides merged with global `provideMagicScroll` options. */\n readonly scrollOptions = input<MagicScrollOptions>({});\n\n private readonly defaults = inject(MAGIC_SCROLL_OPTIONS);\n private readonly options = computed(() =>\n resolveMagicScrollOptions(this.defaults, this.scrollOptions()),\n );\n private readonly document = inject(DOCUMENT);\n private readonly host = inject<ElementRef<HTMLElement>>(ElementRef).nativeElement;\n private readonly service = inject(ScrollService);\n private readonly nearest = inject(NearestAnchorProvider);\n private readonly router = inject(Router, { optional: true });\n\n /** Bidirectional route fragment synchronization signal (debounced URL writer and listener). */\n private readonly fragment = linkedRouteFragment();\n\n /** Initial route URL fragment snapshot captured upon directive instantiation. */\n private readonly initialAnchor = inject(ActivatedRoute).snapshot.fragment;\n\n /** Dynamically measured header height via ResizeObserver. */\n private readonly measuredHeaderHeight = signal(0);\n\n /**\n * Real-time visible section identifier updated per scroll event.\n * Serves as the source of truth for immediate data and layout realignments (`preserve`),\n * decoupling preservation from the debounced URL fragment signal.\n */\n private readonly liveAnchor = signal<string | null | undefined>(null);\n\n /** Current URL anchor, suitable for active-navigation highlighting. */\n readonly activeAnchor = this.fragment.asReadonly();\n\n /** Measured header height, useful for sticky companion panels. */\n readonly headerHeight = this.measuredHeaderHeight.asReadonly();\n\n /** Complete effective top offset, including header height and configured gap. */\n readonly offset = computed(() => this.headerHeight() + this.options().headerOffset);\n\n /** Monotonically increasing revision counter triggering debounced URL fragment updates. */\n private readonly scrollRevision = signal(0);\n\n /** Flag indicating whether the initial restoration phase has been executed. */\n private initialized = false;\n\n /**\n * Flag indicating whether manual user interaction (wheel, touch, or navigation keys) occurred\n * before asynchronous data loading became ready. When true, delayed restoration is skipped.\n */\n private userInterrupted = false;\n\n /**\n * Region-local anchor-relative pixel displacement tracking the distance between\n * the active section's top boundary and the visible activation reading boundary.\n * Preserved during automatic reflows (data prepending, container/header resizing)\n * to keep the reader's view stable without jumping back to section headings.\n */\n private savedDisplacement = 0;\n\n /** Pending destination anchor awaiting data readiness or DOM rendering. */\n private pendingDestination: string | null = this.initialAnchor ?? null;\n\n /** Tracks the last fragment processed from route fragment synchronization. */\n private lastProcessedFragment: string | null | undefined = undefined;\n\n private target?: EventTarget;\n private timer?: ReturnType<typeof setTimeout>;\n /** Active DOM mutation observer used to retry pending scroll destinations once target anchor elements are inserted. */\n private retryObserver?: MutationObserver;\n /** Timeout timer bounding the lifetime of destination retries to prevent memory leaks from non-existent anchors. */\n private retryTimeoutTimer?: ReturnType<typeof setTimeout>;\n /** Handle for the active coalesced requestAnimationFrame layout correction. */\n private layoutCorrectionFrameId?: number;\n /** Cleanups for elements given temporary tabindex=\"-1\" to restore DOM state on blur or directive destruction. */\n private readonly temporaryTabindexCleanups = new Set<() => void>();\n /** Target element pending focus transfer after smooth scroll completion. */\n private pendingFocusTarget?: HTMLElement;\n /** Active scrollend event handler waiting for smooth scroll completion. */\n private scrollEndHandler?: () => void;\n /** Active EventTarget on which scrollEndHandler was registered. */\n private scrollEndTarget?: EventTarget;\n /** Safety timeout preventing a missed scrollend event from retaining a pending focus request. */\n private focusTimeoutTimer?: ReturnType<typeof setTimeout>;\n /** Element focused when the pending focus transfer was initiated. */\n private focusInitiator?: Element | null;\n /** Flag indicating whether programmatic smooth scrolling animation is actively running. */\n private isSmoothNavigating = false;\n /** Flag indicating a deferred layout preservation request while smooth navigation was active. */\n private pendingLayoutPreservation = false;\n /** Active scrollend event handler for programmatic smooth navigation settlement. */\n private smoothNavEndHandler?: () => void;\n /** Event target on which smoothNavEndHandler was registered. */\n private smoothNavTarget?: EventTarget;\n /** Safety timeout timer preventing smooth navigation lock if scrollend does not fire. */\n private smoothNavTimeoutTimer?: ReturnType<typeof setTimeout>;\n\n constructor() {\n const destroyRef = inject(DestroyRef);\n afterNextRender(() => {\n this.refreshTarget();\n this.document.defaultView?.addEventListener('resize', this.onResize);\n });\n destroyRef.onDestroy(() => {\n this.detachListeners();\n this.document.defaultView?.removeEventListener('resize', this.onResize);\n clearTimeout(this.timer);\n this.cancelDestinationRetry();\n this.cancelScheduledFocus();\n this.cancelLayoutPreservation();\n this.cancelSmoothNavigation();\n for (const cleanup of this.temporaryTabindexCleanups) {\n cleanup();\n }\n this.temporaryTabindexCleanups.clear();\n this.pendingDestination = null;\n });\n\n // Phase 1: Header measurement & ResizeObserver tracking.\n // Sequenced first so accurate header dimensions and offsets are available before initial restoration.\n afterRenderEffect((onCleanup) => {\n const selector = this.options().headerSelector;\n const header = selector ? this.document.querySelector<HTMLElement>(selector) : null;\n const measure = () => {\n const height = header?.getBoundingClientRect().height ?? 0;\n if (height !== this.headerHeight()) {\n this.measuredHeaderHeight.set(height);\n if (this.options().preserveOnResize) this.preserve();\n }\n };\n untracked(measure);\n if (header) {\n const observer = new ResizeObserver(measure);\n observer.observe(header);\n onCleanup(() => observer.disconnect());\n }\n });\n\n // Phase 1b: Region and anchor layout reflow observation & animation frame coalesced preservation.\n // Observes host dimensions and region-owned anchors when preserveOnLayoutChange is enabled,\n // coalescing rapid asynchronous layout changes (e.g. image loads, accordion expansions)\n // into a single preservation per frame.\n afterRenderEffect((onCleanup) => {\n this.scrollSource();\n if (\n this.options().preserveOnLayoutChange &&\n typeof ResizeObserver !== 'undefined' &&\n typeof window !== 'undefined'\n ) {\n const observedDimensions = new Map<Element, { width: number; height: number }>();\n const measureAndStore = (el: Element) => {\n const rect = el.getBoundingClientRect();\n const dims = { width: rect.width, height: rect.height };\n observedDimensions.set(el, dims);\n return dims;\n };\n\n const observer = new ResizeObserver((entries?: ResizeObserverEntry[]) => {\n let hasRealChange = false;\n if (!entries || !Array.isArray(entries) || entries.length === 0) {\n hasRealChange = true;\n } else {\n for (const entry of entries) {\n const target = entry.target;\n const prev = observedDimensions.get(target);\n const rect = (target as HTMLElement).getBoundingClientRect?.();\n const width = entry.contentRect?.width ?? rect?.width ?? 0;\n const height = entry.contentRect?.height ?? rect?.height ?? 0;\n if (!prev) {\n observedDimensions.set(target, { width, height });\n } else if (prev.width !== width || prev.height !== height) {\n observedDimensions.set(target, { width, height });\n hasRealChange = true;\n }\n }\n }\n if (hasRealChange) {\n this.scheduleLayoutPreservation();\n }\n });\n\n measureAndStore(this.host);\n observer.observe(this.host);\n for (const anchor of this.anchors()) {\n measureAndStore(anchor);\n observer.observe(anchor);\n }\n\n onCleanup(() => {\n observer.disconnect();\n observedDimensions.clear();\n this.cancelLayoutPreservation();\n });\n }\n });\n\n // Phase 2: Asynchronous scrollSource readiness, initial restoration, and data-change preservation.\n // Untracked execution guarantees execution triggers strictly on scrollSource readiness transitions.\n //\n // Note for developers: When scrollSource resolves (e.g. data loaded), target DOM elements may not\n // yet be rendered into the DOM (e.g. inside @for loops or child components).\n // Rather than discarding pendingDestination when execute() returns false (element not found),\n // we retain pendingDestination and schedule a bounded DOM MutationObserver retry to execute\n // immediately once child elements/anchor attributes are attached to the host DOM.\n afterRenderEffect(() => {\n const source = this.scrollSource();\n const state = readScrollSource(source);\n if (!state.ready) return;\n untracked(() => {\n if (!this.initialized) {\n this.initialized = true;\n if (!this.userInterrupted) {\n if (!this.tryExecutePendingDestination(this.options().behavior.restoration)) {\n if (this.pendingDestination) this.scheduleDestinationRetry();\n }\n } else {\n const nearest = this.calculateNearestAnchor() ?? null;\n this.liveAnchor.set(nearest);\n if (nearest) this.updateSavedDisplacement(nearest);\n this.cancelDestinationRetry();\n }\n } else {\n if (this.pendingDestination && !this.userInterrupted) {\n if (!this.tryExecutePendingDestination(this.options().behavior.restoration)) {\n this.scheduleDestinationRetry();\n }\n } else if (source !== NO_SCROLL_SOURCE && this.options().restoreOnDataChange) {\n this.preserve();\n }\n }\n });\n });\n\n // Phase 3: Route fragment synchronization to liveAnchor and external navigation handling.\n // When the route fragment changes externally (e.g., router navigation), synchronize liveAnchor\n // and trigger scroll restoration to the target element. If the target DOM element is not yet attached,\n // pendingDestination is preserved and scheduled for retry via MutationObserver.\n effect(() => {\n const frag = this.fragment();\n untracked(() => {\n const prev = this.lastProcessedFragment;\n this.lastProcessedFragment = frag;\n this.liveAnchor.set(frag);\n\n if (prev === undefined) {\n return;\n }\n\n if (frag) {\n if (!this.isInternalNavigation()) {\n this.cancelScheduledFocus();\n this.cancelLayoutPreservation();\n this.cancelSmoothNavigation();\n this.pendingLayoutPreservation = false;\n this.userInterrupted = false;\n this.savedDisplacement = 0;\n this.pendingDestination = frag;\n const source = this.scrollSource();\n const state = readScrollSource(source);\n if (this.initialized && state.ready) {\n if (!this.tryExecutePendingDestination(this.options().behavior.restoration)) {\n this.scheduleDestinationRetry();\n }\n } else {\n this.cancelDestinationRetry();\n }\n }\n } else {\n this.cancelScheduledFocus();\n this.cancelLayoutPreservation();\n this.cancelSmoothNavigation();\n this.pendingLayoutPreservation = false;\n this.savedDisplacement = 0;\n this.pendingDestination = null;\n this.cancelDestinationRetry();\n }\n });\n });\n\n // Phase 4: Scroll revision debounced publication to URL fragment.\n // Re-evaluates nearest anchor and commits it to the URL router after debounce delay.\n effect(() => {\n if (!this.scrollRevision()) return;\n const anchor = this.calculateNearestAnchor();\n if (anchor) {\n this.fragment.set(anchor);\n }\n });\n }\n\n /**\n * Determines whether the active router navigation was initiated internally by scroll-spy.\n */\n private isInternalNavigation(): boolean {\n const raw =\n typeof this.router?.getCurrentNavigation === 'function'\n ? (this.router.getCurrentNavigation() ?? this.router.lastSuccessfulNavigation)\n : this.router?.lastSuccessfulNavigation;\n const nav: Navigation | null =\n typeof raw === 'function' ? (raw as () => Navigation | null)() : (raw ?? null);\n const stateOrigin = (nav?.extras?.state as Record<string, unknown> | undefined)?.[\n MAGIC_SCROLL_ORIGIN_KEY\n ];\n const infoOrigin = (nav?.extras?.info as Record<string, unknown> | undefined)?.[\n MAGIC_SCROLL_ORIGIN_KEY\n ];\n return (\n infoOrigin === MAGIC_SCROLL_ORIGIN_SCROLL_SPY ||\n (nav?.trigger !== 'popstate' && stateOrigin === MAGIC_SCROLL_ORIGIN_SCROLL_SPY)\n );\n }\n\n /**\n * Explicitly scrolls the viewport to the target anchor identifier.\n *\n * @param anchor - Target anchor ID (with or without leading `#`).\n * @param options - Per-call scroll overrides (behavior, top offset, ignoreWhenInView, focus).\n * @returns `true` if the target anchor was found and scrolling initiated; `false` otherwise.\n *\n * @remarks\n * Successful execution immediately synchronizes both `liveAnchor` and the router `fragment`\n * with the target anchor, overriding any in-flight debounce delays.\n *\n * When `options.focus` is true, DOM focus is transferred to the resolved anchor element using\n * `preventScroll: true` without triggering secondary browser scrolling. For non-focusable containers,\n * a temporary `tabindex=\"-1\"` is applied and removed upon blur or directive destruction.\n */\n scrollTo(anchor: string, options: MagicScrollToOptions = {}): boolean {\n this.refreshTarget();\n this.cancelScheduledFocus();\n const clean = anchor.replace(/^#/, '');\n const targetEl = this.anchors().find((el) => el.id === clean);\n const willScroll = targetEl ? this.willScroll(targetEl, options) : false;\n const behavior = options.behavior ?? this.options().behavior.interaction;\n const isSmooth = willScroll && this.hasSmoothScrollBehavior(behavior);\n if (isSmooth) {\n this.beginSmoothNavigation();\n } else {\n this.cancelSmoothNavigation();\n }\n const executed = this.execute(anchor, {\n behavior: this.options().behavior.interaction,\n ignoreWhenInView: this.options().ignoreWhenInView,\n ...options,\n displacement: 0,\n });\n if (executed) {\n this.liveAnchor.set(clean);\n this.savedDisplacement = 0;\n this.pendingDestination = null;\n this.cancelDestinationRetry();\n this.cancelLayoutPreservation();\n this.fragment.set(clean);\n }\n if (options.focus && targetEl) {\n if (executed && willScroll && this.hasSmoothScrollBehavior(behavior)) {\n this.scheduleFocus(targetEl);\n } else {\n this.applyFocus(targetEl);\n }\n }\n return executed;\n }\n\n /**\n * Attempts to execute navigation to the pending destination anchor.\n *\n * @param behavior - The scroll animation behavior to apply (`instant` or `smooth`).\n * @returns `true` if the target anchor element was found in the DOM and scrolling was initiated; `false` otherwise.\n *\n * @remarks\n * If execution succeeds, `pendingDestination` is cleared and active retry observers/timers are canceled.\n * If target elements are not yet present in the DOM (e.g. data is ready before DOM elements render),\n * `pendingDestination` remains queued so subsequent DOM updates can retry.\n */\n private tryExecutePendingDestination(behavior: ScrollBehavior): boolean {\n if (!this.pendingDestination) return false;\n const clean = this.pendingDestination.replace(/^#/, '');\n const targetEl = this.anchors().find((el) => el.id === clean);\n const willScroll = targetEl ? this.willScroll(targetEl, { behavior }) : false;\n const isSmooth = willScroll && this.hasSmoothScrollBehavior(behavior);\n if (isSmooth) {\n this.beginSmoothNavigation();\n }\n if (this.execute(this.pendingDestination, { behavior, displacement: 0 })) {\n this.savedDisplacement = 0;\n this.pendingDestination = null;\n this.cancelDestinationRetry();\n return true;\n }\n return false;\n }\n\n /**\n * Schedules a bounded retry mechanism observing DOM additions and attribute modifications\n * within the directive host to re-attempt scrolling when the target anchor element is rendered.\n *\n * @remarks\n * Asynchronous rendering cycles (such as Angular `@for` loops, `@if` blocks, or asynchronous child components)\n * often resolve data/signals (`scrollSource`) before child DOM anchor nodes are attached to the document.\n *\n * To prevent dropped navigations without polling or manual timeouts, a `MutationObserver` watches host mutations\n * for child node insertions and anchor attribute modifications (`id`, `data-scroll-anchor`). When DOM mutations\n * occur and the scroll source is ready, destination execution is re-attempted.\n *\n * A bounded 1000ms safety timeout safeguards against indefinite observation if a non-existent anchor ID was requested.\n */\n private scheduleDestinationRetry(): void {\n if (!this.retryObserver) {\n this.retryObserver = new MutationObserver(() => {\n const state = readScrollSource(this.scrollSource());\n if (state.ready) {\n this.tryExecutePendingDestination(this.options().behavior.restoration);\n }\n });\n this.retryObserver.observe(this.host, {\n childList: true,\n subtree: true,\n attributes: true,\n attributeFilter: ['id', 'data-scroll-anchor'],\n });\n }\n clearTimeout(this.retryTimeoutTimer);\n this.retryTimeoutTimer = setTimeout(() => this.cancelDestinationRetry(), 1000);\n }\n\n /**\n * Disconnects the DOM mutation observer and clears active retry timers.\n *\n * @remarks\n * Invoked whenever destination execution succeeds, a user interrupts navigation (via scroll, touch, or keyboard),\n * an explicit navigation supersedes the pending target, or the directive is destroyed.\n */\n private cancelDestinationRetry(): void {\n if (this.retryObserver) {\n this.retryObserver.disconnect();\n this.retryObserver = undefined;\n }\n clearTimeout(this.retryTimeoutTimer);\n this.retryTimeoutTimer = undefined;\n }\n\n /**\n * Queries and returns all eligible scroll anchor elements belonging strictly to this directive instance.\n *\n * @remarks\n * Anchors must possess a non-empty `id` and satisfy the configured selection strategy:\n * - In `'explicit'` mode: Only elements marked with the `data-scroll-anchor` attribute participate,\n * ignoring prefix rules and excluding generated component/form IDs.\n * - In `'all'` mode (default): Elements matching any configured `anchorPrefixes` OR bearing\n * the `data-scroll-anchor` attribute participate.\n *\n * The `closest('[magicScroll]') === this.host` check guarantees that nested child regions\n * retain strict isolation over their own anchors and do not leak across region boundaries.\n */\n private anchors(): HTMLElement[] {\n const { anchorSelection, anchorPrefixes } = this.options();\n return Array.from(this.host.querySelectorAll<HTMLElement>('[id]')).filter((el) => {\n // 1. Elements must have a non-empty ID and belong directly to this magicScroll host.\n if (!el.id || el.closest('[magicScroll]') !== this.host) {\n return false;\n }\n\n // 2. Strict explicit selection strategy: Ignore prefixes; admit only explicitly marked elements.\n if (anchorSelection === 'explicit') {\n return el.hasAttribute('data-scroll-anchor');\n }\n\n // 3. Default/all selection strategy: Admit explicitly marked elements or elements matching any configured prefix.\n return (\n el.hasAttribute('data-scroll-anchor') ||\n anchorPrefixes.some((prefix) => el.id.startsWith(prefix))\n );\n });\n }\n\n /**\n * Resolves the active scroll container element governing viewport offsets.\n *\n * @returns The scrollable container `HTMLElement`, or `undefined` when scrolling against the document root / window.\n */\n private scrollable(): HTMLElement | undefined {\n const overflow = getComputedStyle(this.host).overflowY;\n const container =\n overflow === 'auto' || overflow === 'scroll'\n ? this.host\n : injectScrollableParentElement(this.host);\n // Root scrolling emits events on document, even when overflow is set on body/html.\n return container === this.document.documentElement || container === this.document.body\n ? undefined\n : container;\n }\n\n /**\n * Computes the nearest visible anchor according to current viewport geometry, header offsets,\n * bottom offsets, and reading direction thresholds.\n */\n private calculateNearestAnchor(): string | undefined {\n return this.nearest.getNearestAnchor({\n hostElement: this.host,\n anchors: this.anchors(),\n scrollable: this.scrollable(),\n headerOffset: this.offset(),\n bottomOffset: this.options().bottomOffset,\n activationThreshold: this.options().activationThreshold,\n });\n }\n\n /**\n * Dispatches scrolling to the underlying {@link ScrollService} after validating target presence.\n */\n private execute(anchor: string | null | undefined, options: ScrollOptions): boolean {\n if (!anchor || !this.anchors().some((el) => el.id === anchor.replace(/^#/, ''))) return false;\n return this.service.scroll(anchor, {\n scrollable: this.scrollable(),\n topOffset: this.offset(),\n ...options,\n });\n }\n\n /**\n * Determines whether the requested navigation will change the scroll position after clamping.\n */\n private willScroll(targetEl: HTMLElement, options: MagicScrollToOptions): boolean {\n const scrollable =\n this.scrollable() ??\n (this.document.scrollingElement as HTMLElement | null) ??\n this.document.documentElement;\n const isDocument =\n scrollable === this.document.documentElement || scrollable === this.document.body;\n const containerTop = isDocument ? 0 : scrollable.getBoundingClientRect().top;\n const viewportHeight = isDocument\n ? this.document.documentElement.clientHeight\n : scrollable.clientHeight;\n const topOffset = options.topOffset ?? this.offset();\n const delta = targetEl.getBoundingClientRect().top - containerTop - topOffset;\n const maxScrollTop =\n scrollable.scrollHeight > 0 && viewportHeight > 0\n ? Math.max(0, scrollable.scrollHeight - viewportHeight)\n : Infinity;\n const targetScrollTop = Math.min(Math.max(scrollable.scrollTop + delta, 0), maxScrollTop);\n return Math.abs(targetScrollTop - scrollable.scrollTop) >= 1;\n }\n\n /**\n * Resolves whether the browser will animate this request, including `auto` with smooth CSS behavior.\n */\n private hasSmoothScrollBehavior(behavior: ScrollBehavior): boolean {\n if (behavior === 'smooth') return true;\n if (behavior !== 'auto') return false;\n const scrollable = this.scrollable() ?? this.document.documentElement;\n return this.document.defaultView?.getComputedStyle(scrollable).scrollBehavior === 'smooth';\n }\n\n /**\n * Realigns the viewport instantly to preserve anchor-relative reading position\n * during asynchronous data updates, container resizes, or header dimension changes.\n *\n * @remarks\n * Targets `liveAnchor` (the real-time visible section) and restores `savedDisplacement`\n * (the pixel offset between the anchor's top and the container's top boundary).\n * If native browser scroll anchoring (`overflow-anchor`) has already adjusted scroll position,\n * delta computes to 0, inherently avoiding double-compensation.\n * If the active anchor element is no longer present in the DOM, realignment is skipped deterministically.\n */\n private preserve(): void {\n if (this.initialized) {\n if (this.isSmoothNavigating) {\n this.pendingLayoutPreservation = true;\n return;\n }\n const anchor = this.liveAnchor();\n if (!anchor) return;\n this.execute(anchor, {\n behavior: 'instant',\n displacement: this.savedDisplacement,\n });\n }\n }\n\n /**\n * Schedules a coalesced layout realignment via requestAnimationFrame.\n * Batches multiple synchronous or rapid descendant reflows into a single correction per frame.\n */\n private scheduleLayoutPreservation(): void {\n if (!this.initialized || typeof window === 'undefined') {\n return;\n }\n if (this.isSmoothNavigating) {\n this.pendingLayoutPreservation = true;\n return;\n }\n if (this.layoutCorrectionFrameId !== undefined) {\n return;\n }\n this.layoutCorrectionFrameId = window.requestAnimationFrame(() => {\n this.layoutCorrectionFrameId = undefined;\n this.preserve();\n });\n }\n\n /**\n * Cancels any pending requestAnimationFrame layout realignment.\n */\n private cancelLayoutPreservation(): void {\n if (this.layoutCorrectionFrameId !== undefined && typeof window !== 'undefined') {\n window.cancelAnimationFrame(this.layoutCorrectionFrameId);\n this.layoutCorrectionFrameId = undefined;\n }\n }\n\n /**\n * Captures and stores the pixel displacement between the active anchor's top edge\n * and the visible activation reading boundary (`containerTop + topOffset`).\n */\n private updateSavedDisplacement(anchorId: string): void {\n const clean = anchorId.replace(/^#/, '');\n const anchorEl = this.anchors().find((el) => el.id === clean);\n if (!anchorEl) return;\n const scrollable = this.scrollable();\n const isDocument =\n !scrollable ||\n scrollable === this.document.documentElement ||\n scrollable === this.document.body;\n const containerTop = isDocument ? 0 : scrollable.getBoundingClientRect().top;\n const topBoundary = containerTop + this.offset();\n this.savedDisplacement = anchorEl.getBoundingClientRect().top - topBoundary;\n }\n\n /**\n * Updates target container references and re-binds passive event listeners whenever\n * the scroll container shifts dynamically.\n */\n private refreshTarget(): void {\n const target = this.scrollable() ?? this.document;\n if (target !== this.target) {\n this.detachListeners();\n this.target = target;\n this.attachListeners(target);\n }\n }\n\n /**\n * Attaches passive scroll, gesture, and keyboard listeners to track user intent and scroll motion.\n */\n private attachListeners(target: EventTarget): void {\n target.addEventListener('scroll', this.onScroll);\n target.addEventListener('wheel', this.onUserIntent, { passive: true });\n target.addEventListener('touchstart', this.onUserIntent, { passive: true });\n target.addEventListener('touchmove', this.onUserIntent, { passive: true });\n target.addEventListener('keydown', this.onKeyDown);\n this.document.addEventListener('keydown', this.onKeyDown);\n }\n\n /**\n * Applies DOM focus safely to the target anchor element using `preventScroll: true`.\n * Automatically assigns a temporary `tabindex=\"-1\"` to non-focusable landmark containers\n * and registers a one-time blur listener to cleanly remove it when focus shifts away.\n */\n private applyFocus(targetEl: HTMLElement): void {\n if (\n !this.document.defaultView ||\n typeof targetEl.focus !== 'function' ||\n !targetEl.isConnected ||\n !this.anchors().includes(targetEl)\n ) {\n return;\n }\n const addedTabindex = !isNaturallyFocusable(targetEl);\n let cleanup: (() => void) | undefined;\n if (addedTabindex) {\n targetEl.setAttribute('tabindex', '-1');\n const onBlur = () => cleanupFn();\n const cleanupFn = () => {\n targetEl.removeEventListener('blur', onBlur);\n if (targetEl.getAttribute('tabindex') === '-1') {\n targetEl.removeAttribute('tabindex');\n }\n this.temporaryTabindexCleanups.delete(cleanupFn);\n };\n cleanup = cleanupFn;\n this.temporaryTabindexCleanups.add(cleanupFn);\n targetEl.addEventListener('blur', onBlur, { once: true });\n }\n targetEl.focus({ preventScroll: true });\n if (this.document.activeElement !== targetEl && cleanup) {\n cleanup();\n }\n }\n\n /**\n * Schedules focus transfer to execute upon smooth scroll completion (`scrollend`).\n */\n private scheduleFocus(targetEl: HTMLElement): void {\n this.refreshTarget();\n this.cancelScheduledFocus();\n this.pendingFocusTarget = targetEl;\n this.focusInitiator = this.document.activeElement;\n this.document.addEventListener('focusin', this.onFocusIn);\n this.document.addEventListener('keydown', this.onFocusTransferKeyDown);\n this.document.addEventListener('pointerdown', this.onFocusTransferPointerDown, true);\n this.document.addEventListener('wheel', this.onFocusScrollIntent, { passive: true });\n this.document.addEventListener('touchstart', this.onFocusScrollIntent, { passive: true });\n this.document.addEventListener('touchmove', this.onFocusScrollIntent, { passive: true });\n const target = this.target!;\n this.scrollEndTarget = target;\n this.scrollEndHandler = () => {\n this.cancelScheduledFocus();\n this.applyFocus(targetEl);\n };\n target.addEventListener('scrollend', this.scrollEndHandler, { once: true });\n this.focusTimeoutTimer = setTimeout(() => this.cancelScheduledFocus(), 5000);\n }\n\n /**\n * Cancels any pending scheduled focus transfer and unregisters the `scrollend` listener.\n */\n private cancelScheduledFocus(): void {\n if (this.scrollEndHandler && this.scrollEndTarget) {\n this.scrollEndTarget.removeEventListener('scrollend', this.scrollEndHandler);\n this.scrollEndHandler = undefined;\n this.scrollEndTarget = undefined;\n }\n clearTimeout(this.focusTimeoutTimer);\n this.focusTimeoutTimer = undefined;\n this.document.removeEventListener('focusin', this.onFocusIn);\n this.document.removeEventListener('keydown', this.onFocusTransferKeyDown);\n this.document.removeEventListener('pointerdown', this.onFocusTransferPointerDown, true);\n this.document.removeEventListener('wheel', this.onFocusScrollIntent);\n this.document.removeEventListener('touchstart', this.onFocusScrollIntent);\n this.document.removeEventListener('touchmove', this.onFocusScrollIntent);\n this.focusInitiator = undefined;\n this.pendingFocusTarget = undefined;\n }\n\n /**\n * Detaches all registered event listeners to ensure clean teardown without memory leaks.\n */\n private detachListeners(): void {\n if (!this.target) return;\n this.cancelScheduledFocus();\n this.cancelSmoothNavigation();\n this.target.removeEventListener('scroll', this.onScroll);\n this.target.removeEventListener('wheel', this.onUserIntent);\n this.target.removeEventListener('touchstart', this.onUserIntent);\n this.target.removeEventListener('touchmove', this.onUserIntent);\n this.target.removeEventListener('keydown', this.onKeyDown);\n this.document.removeEventListener('keydown', this.onKeyDown);\n }\n\n /**\n * Intercepts manual user gestures (`wheel`, `touchstart`, `touchmove`) to flag user interaction\n * and cancel delayed restorations prior to data readiness.\n */\n private readonly onUserIntent = () => {\n this.userInterrupted = true;\n this.pendingDestination = null;\n this.cancelDestinationRetry();\n this.cancelScheduledFocus();\n this.cancelLayoutPreservation();\n this.cancelSmoothNavigation();\n this.pendingLayoutPreservation = false;\n };\n\n /**\n * Intercepts navigation keyboard events (`ArrowUp`, `ArrowDown`, `PageUp`, `PageDown`, `Home`, `End`, `Space`).\n * Cancels pending restoration when navigation occurs within the relevant scroll context\n * while safely ignoring interactions on editable input elements.\n */\n private readonly onKeyDown = (event: Event) => {\n if (!(event instanceof KeyboardEvent)) return;\n if (isEditableTarget(event.target)) return;\n if (!SCROLL_KEYS.has(event.key)) return;\n const targetEl = event.target as Element | null;\n const scrollable = this.scrollable();\n const isInsideContext =\n !targetEl ||\n targetEl === this.document.body ||\n targetEl === this.document.documentElement ||\n (scrollable ? scrollable === targetEl || scrollable.contains(targetEl) : true);\n if (isInsideContext) {\n this.userInterrupted = true;\n this.pendingDestination = null;\n this.cancelDestinationRetry();\n this.cancelScheduledFocus();\n this.cancelLayoutPreservation();\n this.cancelSmoothNavigation();\n this.pendingLayoutPreservation = false;\n }\n };\n\n private readonly onFocusScrollIntent = () => {\n this.cancelScheduledFocus();\n };\n\n private readonly onFocusIn = (event: Event) => {\n if (this.pendingFocusTarget && event.target !== this.focusInitiator) {\n this.cancelScheduledFocus();\n }\n };\n\n private readonly onFocusTransferKeyDown = (event: Event) => {\n if (!(event instanceof KeyboardEvent)) return;\n if (event.key === 'Tab') {\n this.cancelScheduledFocus();\n return;\n }\n if (isEditableTarget(event.target)) return;\n if (SCROLL_KEYS.has(event.key)) {\n this.cancelScheduledFocus();\n }\n };\n\n private readonly onFocusTransferPointerDown = (event: Event) => {\n const target = event.target;\n if (\n this.pendingFocusTarget &&\n target instanceof Node &&\n target !== this.focusInitiator &&\n !this.focusInitiator?.contains(target)\n ) {\n this.cancelScheduledFocus();\n }\n };\n\n /**\n * Handles scroll events by immediately updating `liveAnchor` for position preservation,\n * while debouncing `scrollRevision` increments to update the browser URL fragment without thrashing history.\n */\n private readonly onScroll = () => {\n if (!this.initialized) return;\n if (!this.isSmoothNavigating) {\n const anchor = this.calculateNearestAnchor();\n if (anchor) {\n this.liveAnchor.set(anchor);\n this.updateSavedDisplacement(anchor);\n }\n }\n clearTimeout(this.timer);\n this.timer = setTimeout(\n () => this.scrollRevision.update((revision) => revision + 1),\n this.options().debounceTime,\n );\n };\n\n /**\n * Handles window resize events by re-evaluating targets and optionally realigning the active anchor.\n */\n private readonly onResize = () => {\n this.refreshTarget();\n if (this.options().preserveOnResize) this.preserve();\n };\n\n /**\n * Initiates smooth programmatic navigation protection, deferring layout realignments\n * and intermediate anchor snapping until scrolling completes (`scrollend`) or times out.\n */\n private beginSmoothNavigation(): void {\n this.cancelSmoothNavigation();\n this.isSmoothNavigating = true;\n this.refreshTarget();\n const target = this.target!;\n this.smoothNavTarget = target;\n this.smoothNavEndHandler = () => {\n this.endSmoothNavigation();\n };\n target.addEventListener('scrollend', this.smoothNavEndHandler, { once: true });\n this.smoothNavTimeoutTimer = setTimeout(() => {\n this.endSmoothNavigation();\n }, 3000);\n }\n\n /**\n * Concludes smooth programmatic navigation, updating the reading position\n * at the settled destination and processing any deferred layout preservation requests.\n */\n private endSmoothNavigation(): void {\n this.cancelSmoothNavigation();\n const anchor = this.calculateNearestAnchor();\n if (anchor) {\n this.liveAnchor.set(anchor);\n this.updateSavedDisplacement(anchor);\n }\n if (this.pendingLayoutPreservation) {\n this.pendingLayoutPreservation = false;\n this.scheduleLayoutPreservation();\n }\n }\n\n /**\n * Cancels active smooth navigation tracking and clears timeout timers and scrollend listeners.\n */\n private cancelSmoothNavigation(): void {\n if (this.smoothNavEndHandler && this.smoothNavTarget) {\n this.smoothNavTarget.removeEventListener('scrollend', this.smoothNavEndHandler);\n this.smoothNavEndHandler = undefined;\n this.smoothNavTarget = undefined;\n }\n clearTimeout(this.smoothNavTimeoutTimer);\n this.smoothNavTimeoutTimer = undefined;\n this.isSmoothNavigating = false;\n }\n}\n","import { Directive, effect, ElementRef, inject, input } from '@angular/core';\n\n/**\n * Optional explicit anchor. Its ID participates even outside the configured prefix.\n * Use `scrollAnchor` alongside an existing id, or `[scrollAnchor]=\"item.id\"` to set it.\n */\n@Directive({\n selector: '[scrollAnchor]',\n host: { '[attr.data-scroll-anchor]': '\"\"' },\n})\nexport class ScrollAnchorDirective {\n readonly scrollAnchor = input('');\n private readonly host = inject<ElementRef<HTMLElement>>(ElementRef);\n constructor() {\n effect(() => {\n const id = this.scrollAnchor();\n if (id) this.host.nativeElement.id = id;\n });\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAOA,MAAa,0BAA0B;AAKvC,MAAa,iCAAiC;AA2B9C,SAAgB,sBAAmB;CACjC,MAAM,QAAQ,OAAO,cAAc;CACnC,MAAM,SAAS,OAAO,MAAM;CAC5B,MAAM,WAAW,SAAS,MAAM,QAAQ;CAExC,MAAM,iBAAiB,mBAAmB,SAAQ,GAAG,GAAA,YAAA,CAAA,EAAA,WAAA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