@su-labs/scroll-spy 22.0.0 → 22.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +20 -0
- package/README.md +10 -8
- package/fesm2022/su-labs-scroll-spy.mjs +9 -7
- package/fesm2022/su-labs-scroll-spy.mjs.map +1 -1
- package/package.json +3 -2
- package/types/su-labs-scroll-spy.d.ts +15 -4
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,26 @@ All notable changes to this project will be documented in this file.
|
|
|
5
5
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
6
6
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
7
|
|
|
8
|
+
## [22.1.1] - 2026-11-14
|
|
9
|
+
|
|
10
|
+
### Changed
|
|
11
|
+
- Package homepage now points to the website with a live demo
|
|
12
|
+
- Pins `@su-labs/core` to exactly 1.8.0
|
|
13
|
+
|
|
14
|
+
## [22.1.0] - 2026-11-05
|
|
15
|
+
|
|
16
|
+
### Added
|
|
17
|
+
- `ScrollSpyService.setActiveSection(id)` to set the active section manually (already documented in the README)
|
|
18
|
+
|
|
19
|
+
### Changed
|
|
20
|
+
- Section observing moved to the framework-agnostic `@su-labs/core/scroll-spy`; `ScrollSpyDirective` now uses `observeSuScrollSpySection`
|
|
21
|
+
- Added `@su-labs/core` as a dependency
|
|
22
|
+
- README links to the `@su-labs/core` installation guides for non-Angular projects
|
|
23
|
+
|
|
24
|
+
### Fixed
|
|
25
|
+
- `ScrollSpyDirective` now disconnects its IntersectionObserver when destroyed
|
|
26
|
+
- Repair table of contents links in README.md
|
|
27
|
+
|
|
8
28
|
## [22.0.0] - 2026-11-04
|
|
9
29
|
|
|
10
30
|
### Changed
|
package/README.md
CHANGED
|
@@ -13,19 +13,21 @@
|
|
|
13
13
|
|
|
14
14
|
A lightweight Angular service and directive for managing active sections based on scroll position. Easily track which section of a page is currently visible and update your UI accordingly. Perfect for navigation menus, table of contents, or one-page scroll applications.
|
|
15
15
|
|
|
16
|
+
> **Not using Angular?** The same scroll spy is available for React, Vue, Svelte and vanilla JavaScript in [`@su-labs/core`](https://www.npmjs.com/package/@su-labs/core). See the [installation guides](https://github.com/Greezaaa/settings-utils-lib/blob/main/docs/README.md).
|
|
17
|
+
|
|
16
18
|
## Table of Contents
|
|
17
19
|
|
|
18
|
-
- [Why Use This Library?](
|
|
20
|
+
- [Why Use This Library?](#why-use-this-library)
|
|
19
21
|
- [Features](#features)
|
|
20
22
|
- [Installation](#installation)
|
|
21
|
-
- [Quick Start](
|
|
23
|
+
- [Quick Start](#quick-start)
|
|
22
24
|
- [Usage](#usage)
|
|
23
|
-
- [API Reference](
|
|
25
|
+
- [API Reference](#api-reference)
|
|
24
26
|
- [How It Works](#how-it-works)
|
|
25
|
-
- [Browser Compatibility](
|
|
26
|
-
- [Related Libraries](
|
|
27
|
-
- [Troubleshooting](
|
|
28
|
-
- [Support](
|
|
27
|
+
- [Browser Compatibility](#browser-compatibility)
|
|
28
|
+
- [Related Libraries](#related-libraries)
|
|
29
|
+
- [Troubleshooting](#troubleshooting)
|
|
30
|
+
- [Support](#support)
|
|
29
31
|
- [Contributing](#contributing)
|
|
30
32
|
- [License](#license)
|
|
31
33
|
|
|
@@ -162,7 +164,7 @@ export class ScrollExampleComponent {
|
|
|
162
164
|
|
|
163
165
|
| Signal | Type | Description |
|
|
164
166
|
|--------|------|-------------|
|
|
165
|
-
| `activeSection()` | `string
|
|
167
|
+
| `activeSection()` | `string` | ID of currently active section (`''` until a section becomes active) |
|
|
166
168
|
|
|
167
169
|
#### Methods
|
|
168
170
|
|
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
import * as i0 from "@angular/core";
|
|
2
2
|
import { Directive, ElementRef, Injectable, Input, inject, signal } from "@angular/core";
|
|
3
|
+
import { observeSuScrollSpySection } from "@su-labs/core/scroll-spy";
|
|
3
4
|
var ScrollSpyService = class ScrollSpyService {
|
|
4
5
|
activeSection = signal("", ...ngDevMode ? [{ debugName: "activeSection" }] : /* istanbul ignore next */ []);
|
|
6
|
+
setActiveSection(id) {
|
|
7
|
+
this.activeSection.set(id);
|
|
8
|
+
}
|
|
5
9
|
static ɵfac = i0.ɵɵngDeclareFactory({
|
|
6
10
|
minVersion: "12.0.0",
|
|
7
11
|
version: "22.2.4",
|
|
@@ -32,14 +36,12 @@ var ScrollSpyDirective = class ScrollSpyDirective {
|
|
|
32
36
|
sectionId;
|
|
33
37
|
el = inject(ElementRef);
|
|
34
38
|
scrollSpy = inject(ScrollSpyService);
|
|
39
|
+
stopObserving;
|
|
35
40
|
ngOnInit() {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
threshold: 0,
|
|
41
|
-
rootMargin: "-50% 0px -50% 0px"
|
|
42
|
-
}).observe(this.el.nativeElement);
|
|
41
|
+
this.stopObserving = observeSuScrollSpySection(this.el.nativeElement, () => this.scrollSpy.setActiveSection(this.sectionId));
|
|
42
|
+
}
|
|
43
|
+
ngOnDestroy() {
|
|
44
|
+
this.stopObserving?.();
|
|
43
45
|
}
|
|
44
46
|
static ɵfac = i0.ɵɵngDeclareFactory({
|
|
45
47
|
minVersion: "12.0.0",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"su-labs-scroll-spy.mjs","names":[],"sources":["../../../../projects/su-labs/scroll-spy/src/lib/scroll-spy.service.ts","../../../../projects/su-labs/scroll-spy/src/lib/scroll-spy.directive.ts"],"sourcesContent":["import { Injectable, signal } from '@angular/core';\n\n/**\n * Service that keeps track of the currently active section while scrolling.\n * Can be injected into components to react to section changes.\n */\n@Injectable({ providedIn: 'root' })\nexport class ScrollSpyService {\n /** ID of the currently visible section */\n activeSection = signal<string>('');\n}\n","import { Directive, ElementRef, inject, Input, OnInit } from '@angular/core';\nimport { ScrollSpyService } from './scroll-spy.service';\n\n/**\n * Directive that observes an element's visibility on the screen\n * and updates ScrollSpyService.activeSection when it
|
|
1
|
+
{"version":3,"file":"su-labs-scroll-spy.mjs","names":[],"sources":["../../../../projects/su-labs/scroll-spy/src/lib/scroll-spy.service.ts","../../../../projects/su-labs/scroll-spy/src/lib/scroll-spy.directive.ts"],"sourcesContent":["import { Injectable, signal } from '@angular/core';\n\n/**\n * Service that keeps track of the currently active section while scrolling.\n * Can be injected into components to react to section changes.\n *\n * Sections are tracked by `ScrollSpyDirective`, which uses the framework-agnostic\n * observer from `@su-labs/core/scroll-spy`.\n */\n@Injectable({ providedIn: 'root' })\nexport class ScrollSpyService {\n /** ID of the currently visible section ('' until a section becomes active) */\n activeSection = signal<string>('');\n\n /**\n * Set the active section manually, for example when a navigation link is clicked.\n * @param id ID of the section.\n */\n setActiveSection(id: string): void {\n this.activeSection.set(id);\n }\n}\n","import { Directive, ElementRef, inject, Input, OnDestroy, OnInit } from '@angular/core';\nimport { observeSuScrollSpySection } from '@su-labs/core/scroll-spy';\nimport { SuUnsubscribe } from '@su-labs/core';\nimport { ScrollSpyService } from './scroll-spy.service';\n\n/**\n * Directive that observes an element's visibility on the screen\n * and updates ScrollSpyService.activeSection when it reaches the vertical center of the viewport.\n *\n * Usage:\n * <section [appScrollSpy]=\"'home'\">...</section>\n */\n@Directive({\n selector: '[appScrollSpy]',\n standalone: true,\n})\nexport class ScrollSpyDirective implements OnInit, OnDestroy {\n /** ID of the observed section */\n @Input('appScrollSpy') sectionId!: string;\n\n private readonly el = inject<ElementRef<Element>>(ElementRef);\n private readonly scrollSpy = inject(ScrollSpyService);\n\n /** Stops observing the section */\n private stopObserving?: SuUnsubscribe;\n\n ngOnInit(): void {\n this.stopObserving = observeSuScrollSpySection(this.el.nativeElement, () =>\n this.scrollSpy.setActiveSection(this.sectionId),\n );\n }\n\n ngOnDestroy(): void {\n this.stopObserving?.();\n }\n}\n"],"mappings":";;;AAUA,IAAa,mBAAb,MAAa,iBAAgB;CAE3B,gBAAgB,OAAe,IAAG,GAAA,YAAA,CAAA,EAAA,WAAA,gBA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|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@su-labs/scroll-spy",
|
|
3
|
-
"version": "22.
|
|
3
|
+
"version": "22.1.1",
|
|
4
4
|
"description": "An Angular scroll spy utility based on IntersectionObserver for tracking active sections or menu items.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"angular",
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
"url": "git+https://github.com/Greezaaa/settings-utils-lib.git",
|
|
25
25
|
"directory": "projects/su-labs/scroll-spy"
|
|
26
26
|
},
|
|
27
|
-
"homepage": "https://
|
|
27
|
+
"homepage": "https://su-labs.dev/scroll-spy/",
|
|
28
28
|
"bugs": {
|
|
29
29
|
"url": "https://github.com/Greezaaa/settings-utils-lib/issues"
|
|
30
30
|
},
|
|
@@ -33,6 +33,7 @@
|
|
|
33
33
|
"@angular/core": "^22.0.0"
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
|
+
"@su-labs/core": "1.8.0",
|
|
36
37
|
"tslib": "^2.3.0"
|
|
37
38
|
},
|
|
38
39
|
"sideEffects": false,
|
|
@@ -1,28 +1,39 @@
|
|
|
1
1
|
import * as i0 from "@angular/core";
|
|
2
|
-
import { OnInit } from "@angular/core";
|
|
2
|
+
import { OnDestroy, OnInit } from "@angular/core";
|
|
3
3
|
/**
|
|
4
4
|
* Service that keeps track of the currently active section while scrolling.
|
|
5
5
|
* Can be injected into components to react to section changes.
|
|
6
|
+
*
|
|
7
|
+
* Sections are tracked by `ScrollSpyDirective`, which uses the framework-agnostic
|
|
8
|
+
* observer from `@su-labs/core/scroll-spy`.
|
|
6
9
|
*/
|
|
7
10
|
export declare class ScrollSpyService {
|
|
8
|
-
/** ID of the currently visible section */
|
|
11
|
+
/** ID of the currently visible section ('' until a section becomes active) */
|
|
9
12
|
activeSection: import("@angular/core").WritableSignal<string>;
|
|
13
|
+
/**
|
|
14
|
+
* Set the active section manually, for example when a navigation link is clicked.
|
|
15
|
+
* @param id ID of the section.
|
|
16
|
+
*/
|
|
17
|
+
setActiveSection(id: string): void;
|
|
10
18
|
static ɵfac: i0.ɵɵFactoryDeclaration<ScrollSpyService, never>;
|
|
11
19
|
static ɵprov: i0.ɵɵInjectableDeclaration<any>;
|
|
12
20
|
}
|
|
13
21
|
/**
|
|
14
22
|
* Directive that observes an element's visibility on the screen
|
|
15
|
-
* and updates ScrollSpyService.activeSection when it
|
|
23
|
+
* and updates ScrollSpyService.activeSection when it reaches the vertical center of the viewport.
|
|
16
24
|
*
|
|
17
25
|
* Usage:
|
|
18
26
|
* <section [appScrollSpy]="'home'">...</section>
|
|
19
27
|
*/
|
|
20
|
-
export declare class ScrollSpyDirective implements OnInit {
|
|
28
|
+
export declare class ScrollSpyDirective implements OnInit, OnDestroy {
|
|
21
29
|
/** ID of the observed section */
|
|
22
30
|
sectionId: string;
|
|
23
31
|
private readonly el;
|
|
24
32
|
private readonly scrollSpy;
|
|
33
|
+
/** Stops observing the section */
|
|
34
|
+
private stopObserving?;
|
|
25
35
|
ngOnInit(): void;
|
|
36
|
+
ngOnDestroy(): void;
|
|
26
37
|
static ɵfac: i0.ɵɵFactoryDeclaration<ScrollSpyDirective, never>;
|
|
27
38
|
static ɵdir: i0.ɵɵDirectiveDeclaration<ScrollSpyDirective, "[appScrollSpy]", never, {
|
|
28
39
|
"sectionId": {
|