@su-labs/scroll-spy 21.0.5 → 21.1.2
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 +31 -0
- package/README.md +46 -42
- package/fesm2022/su-labs-scroll-spy.mjs +26 -41
- package/fesm2022/su-labs-scroll-spy.mjs.map +1 -1
- package/package.json +5 -3
- package/types/su-labs-scroll-spy.d.ts +15 -4
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,37 @@ 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.2] - 2026-11-16
|
|
9
|
+
|
|
10
|
+
### Changed
|
|
11
|
+
- Uses `@su-labs/core` 1.9.0 (was 1.8.0), the same version as every other `@su-labs` package, so apps using several of them install core once
|
|
12
|
+
|
|
13
|
+
## [22.1.1] - 2026-11-14
|
|
14
|
+
|
|
15
|
+
### Changed
|
|
16
|
+
- Package homepage now points to the website with a live demo
|
|
17
|
+
- Pins `@su-labs/core` to exactly 1.8.0
|
|
18
|
+
|
|
19
|
+
## [22.1.0] - 2026-11-05
|
|
20
|
+
|
|
21
|
+
### Added
|
|
22
|
+
- `ScrollSpyService.setActiveSection(id)` to set the active section manually (already documented in the README)
|
|
23
|
+
|
|
24
|
+
### Changed
|
|
25
|
+
- Section observing moved to the framework-agnostic `@su-labs/core/scroll-spy`; `ScrollSpyDirective` now uses `observeSuScrollSpySection`
|
|
26
|
+
- Added `@su-labs/core` as a dependency
|
|
27
|
+
- README links to the `@su-labs/core` installation guides for non-Angular projects
|
|
28
|
+
|
|
29
|
+
### Fixed
|
|
30
|
+
- `ScrollSpyDirective` now disconnects its IntersectionObserver when destroyed
|
|
31
|
+
- Repair table of contents links in README.md
|
|
32
|
+
|
|
33
|
+
## [22.0.0] - 2026-11-04
|
|
34
|
+
|
|
35
|
+
### Changed
|
|
36
|
+
- Upgrade to Angular 22 (peer dependencies now `^22.0.0`)
|
|
37
|
+
- Remove emojis from README.md
|
|
38
|
+
|
|
8
39
|
## [21.0.5] - 2026-02-04
|
|
9
40
|
|
|
10
41
|
### Changed
|
package/README.md
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
`@su-labs/scroll-spy`
|
|
4
4
|
|
|
5
5
|

|
|
6
|
-

|
|
7
7
|

|
|
8
8
|

|
|
9
9
|

|
|
@@ -13,32 +13,34 @@
|
|
|
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
|
-
|
|
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
17
|
|
|
18
|
-
|
|
18
|
+
## Table of Contents
|
|
19
|
+
|
|
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
|
|
|
32
|
-
##
|
|
34
|
+
## Why Use This Library?
|
|
33
35
|
|
|
34
|
-
-
|
|
35
|
-
-
|
|
36
|
-
-
|
|
37
|
-
-
|
|
38
|
-
-
|
|
39
|
-
-
|
|
40
|
-
-
|
|
41
|
-
-
|
|
36
|
+
- **Lightweight** - Minimal bundle size
|
|
37
|
+
- **Reactive** - Built with Angular Signals
|
|
38
|
+
- **Performant** - Uses IntersectionObserver API
|
|
39
|
+
- **Flexible** - Works with any layout
|
|
40
|
+
- **Type-Safe** - Full TypeScript support
|
|
41
|
+
- **Zero Dependencies** - No bloat
|
|
42
|
+
- **Well Tested** - Comprehensive test coverage
|
|
43
|
+
- **Well Documented** - Clear examples and API docs
|
|
42
44
|
|
|
43
45
|
## Features
|
|
44
46
|
|
|
@@ -54,9 +56,11 @@ A lightweight Angular service and directive for managing active sections based o
|
|
|
54
56
|
You can install this library via npm:
|
|
55
57
|
|
|
56
58
|
```sh
|
|
57
|
-
npm install @su-labs/scroll-spy
|
|
59
|
+
npm install @su-labs/scroll-spy@ng21
|
|
58
60
|
```
|
|
59
61
|
|
|
62
|
+
This is the Angular 21 version. For the newest Angular, install `@su-labs/scroll-spy` without a tag.
|
|
63
|
+
|
|
60
64
|
## Peer Dependencies
|
|
61
65
|
|
|
62
66
|
This library requires the following peer dependencies:
|
|
@@ -65,11 +69,11 @@ This library requires the following peer dependencies:
|
|
|
65
69
|
npm install @angular/common@^21 @angular/core@^21
|
|
66
70
|
```
|
|
67
71
|
|
|
68
|
-
##
|
|
72
|
+
## Quick Start
|
|
69
73
|
|
|
70
74
|
```typescript
|
|
71
75
|
// 1. Install
|
|
72
|
-
npm install @su-labs/scroll-spy
|
|
76
|
+
npm install @su-labs/scroll-spy@ng21
|
|
73
77
|
|
|
74
78
|
// 2. Add directive to your sections
|
|
75
79
|
@for (section of sections; track section.id) {
|
|
@@ -154,7 +158,7 @@ export class ScrollExampleComponent {
|
|
|
154
158
|
}
|
|
155
159
|
```
|
|
156
160
|
|
|
157
|
-
##
|
|
161
|
+
## API Reference
|
|
158
162
|
|
|
159
163
|
### Service (ScrollSpyService)
|
|
160
164
|
|
|
@@ -162,7 +166,7 @@ export class ScrollExampleComponent {
|
|
|
162
166
|
|
|
163
167
|
| Signal | Type | Description |
|
|
164
168
|
|--------|------|-------------|
|
|
165
|
-
| `activeSection()` | `string
|
|
169
|
+
| `activeSection()` | `string` | ID of currently active section (`''` until a section becomes active) |
|
|
166
170
|
|
|
167
171
|
#### Methods
|
|
168
172
|
|
|
@@ -191,17 +195,17 @@ export class ScrollExampleComponent {
|
|
|
191
195
|
The `ScrollSpyDirective` uses the browser's native [IntersectionObserver API](https://developer.mozilla.org/en-US/docs/Web/API/Intersection_Observer_API) to efficiently monitor when elements enter or exit the viewport. It's configured to trigger when a tracked section is roughly in the vertical center of the screen, providing a smooth and accurate "spy" effect.
|
|
192
196
|
|
|
193
197
|
**Key Benefits:**
|
|
194
|
-
-
|
|
195
|
-
-
|
|
196
|
-
-
|
|
197
|
-
-
|
|
198
|
+
- **Performance**: No scroll event listeners needed
|
|
199
|
+
- **Accuracy**: Precise intersection detection
|
|
200
|
+
- **Efficiency**: Browser-native implementation
|
|
201
|
+
- **Battery Friendly**: Optimized for mobile devices
|
|
198
202
|
|
|
199
|
-
##
|
|
203
|
+
## Browser Compatibility
|
|
200
204
|
|
|
201
205
|
Works in all modern browsers that support:
|
|
202
|
-
-
|
|
203
|
-
-
|
|
204
|
-
-
|
|
206
|
+
- IntersectionObserver API
|
|
207
|
+
- Angular 21
|
|
208
|
+
- ES2022+
|
|
205
209
|
|
|
206
210
|
| Browser | Version |
|
|
207
211
|
|---------|---------|
|
|
@@ -210,16 +214,16 @@ Works in all modern browsers that support:
|
|
|
210
214
|
| Safari | ≥ 12.1 |
|
|
211
215
|
| Edge | ≥ 16 |
|
|
212
216
|
|
|
213
|
-
##
|
|
217
|
+
## Related Libraries
|
|
214
218
|
|
|
215
219
|
Part of the **@su-labs** suite:
|
|
216
220
|
|
|
217
|
-
-
|
|
218
|
-
-
|
|
219
|
-
-
|
|
220
|
-
-
|
|
221
|
+
- [@su-labs/visit-tracker](https://www.npmjs.com/package/@su-labs/visit-tracker) - User visit tracking
|
|
222
|
+
- [@su-labs/theme](https://www.npmjs.com/package/@su-labs/theme) - Theme management with dark mode support
|
|
223
|
+
- [@su-labs/notifications](https://www.npmjs.com/package/@su-labs/notifications) - Toast notification system
|
|
224
|
+
- [@su-labs/font-size](https://www.npmjs.com/package/@su-labs/font-size) - Accessible font size controls
|
|
221
225
|
|
|
222
|
-
##
|
|
226
|
+
## Troubleshooting
|
|
223
227
|
|
|
224
228
|
### Active section not updating?
|
|
225
229
|
|
|
@@ -235,13 +239,13 @@ Make sure you've imported `ScrollSpyDirective` in your component's imports array
|
|
|
235
239
|
|
|
236
240
|
### TypeScript errors?
|
|
237
241
|
|
|
238
|
-
Ensure you have Angular 21
|
|
242
|
+
Ensure you have Angular 21 and TypeScript 5.9+ installed.
|
|
239
243
|
|
|
240
|
-
##
|
|
244
|
+
## Support
|
|
241
245
|
|
|
242
|
-
-
|
|
243
|
-
-
|
|
244
|
-
-
|
|
246
|
+
- Found a bug? [Open an issue](https://github.com/Greezaaa/settings-utils-lib/issues)
|
|
247
|
+
- Have a feature request? [Start a discussion](https://github.com/Greezaaa/settings-utils-lib/discussions)
|
|
248
|
+
- Like this library? [Give it a star!](https://github.com/Greezaaa/settings-utils-lib)
|
|
245
249
|
|
|
246
250
|
## Contributing
|
|
247
251
|
|
|
@@ -1,24 +1,35 @@
|
|
|
1
1
|
import * as i0 from '@angular/core';
|
|
2
2
|
import { signal, Injectable, inject, ElementRef, Input, Directive } from '@angular/core';
|
|
3
|
+
import { observeSuScrollSpySection } from '@su-labs/core/scroll-spy';
|
|
3
4
|
|
|
4
5
|
/**
|
|
5
6
|
* Service that keeps track of the currently active section while scrolling.
|
|
6
7
|
* Can be injected into components to react to section changes.
|
|
8
|
+
*
|
|
9
|
+
* Sections are tracked by `ScrollSpyDirective`, which uses the framework-agnostic
|
|
10
|
+
* observer from `@su-labs/core/scroll-spy`.
|
|
7
11
|
*/
|
|
8
12
|
class ScrollSpyService {
|
|
9
|
-
/** ID of the currently visible section */
|
|
10
|
-
activeSection = signal('', ...(ngDevMode ? [{ debugName: "activeSection" }] : []));
|
|
11
|
-
|
|
12
|
-
|
|
13
|
+
/** ID of the currently visible section ('' until a section becomes active) */
|
|
14
|
+
activeSection = signal('', ...(ngDevMode ? [{ debugName: "activeSection" }] : /* istanbul ignore next */ []));
|
|
15
|
+
/**
|
|
16
|
+
* Set the active section manually, for example when a navigation link is clicked.
|
|
17
|
+
* @param id ID of the section.
|
|
18
|
+
*/
|
|
19
|
+
setActiveSection(id) {
|
|
20
|
+
this.activeSection.set(id);
|
|
21
|
+
}
|
|
22
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.26", ngImport: i0, type: ScrollSpyService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
|
|
23
|
+
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "21.2.26", ngImport: i0, type: ScrollSpyService, providedIn: 'root' });
|
|
13
24
|
}
|
|
14
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.
|
|
25
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.26", ngImport: i0, type: ScrollSpyService, decorators: [{
|
|
15
26
|
type: Injectable,
|
|
16
27
|
args: [{ providedIn: 'root' }]
|
|
17
28
|
}] });
|
|
18
29
|
|
|
19
30
|
/**
|
|
20
31
|
* Directive that observes an element's visibility on the screen
|
|
21
|
-
* and updates ScrollSpyService.activeSection when it
|
|
32
|
+
* and updates ScrollSpyService.activeSection when it reaches the vertical center of the viewport.
|
|
22
33
|
*
|
|
23
34
|
* Usage:
|
|
24
35
|
* <section [appScrollSpy]="'home'">...</section>
|
|
@@ -28,40 +39,18 @@ class ScrollSpyDirective {
|
|
|
28
39
|
sectionId;
|
|
29
40
|
el = inject(ElementRef);
|
|
30
41
|
scrollSpy = inject(ScrollSpyService);
|
|
42
|
+
/** Stops observing the section */
|
|
43
|
+
stopObserving;
|
|
31
44
|
ngOnInit() {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
}, {
|
|
39
|
-
// The viewport used to check visibility.
|
|
40
|
-
// `null` means the browser viewport is used.
|
|
41
|
-
root: null,
|
|
42
|
-
// How much of the element needs to be visible to trigger the observer.
|
|
43
|
-
// `0` means it triggers as soon as even one pixel is visible within the root + rootMargin.
|
|
44
|
-
threshold: 0,
|
|
45
|
-
// rootMargin defines an offset around the viewport that affects when the observer triggers.
|
|
46
|
-
// Format: 'top right bottom left'
|
|
47
|
-
// In this case:
|
|
48
|
-
// - top: -50%
|
|
49
|
-
// - right: 0px
|
|
50
|
-
// - bottom: -50%
|
|
51
|
-
// - left: 0px
|
|
52
|
-
//
|
|
53
|
-
// This means the observer will consider the element "intersecting" only when
|
|
54
|
-
// it is roughly in the vertical center of the viewport.
|
|
55
|
-
// It's perfect for scroll-spy behavior, because it triggers when the section
|
|
56
|
-
// is the main focus on the screen, rather than just appearing at the top.
|
|
57
|
-
rootMargin: '-50% 0px -50% 0px',
|
|
58
|
-
});
|
|
59
|
-
observer.observe(this.el.nativeElement);
|
|
45
|
+
this.stopObserving = observeSuScrollSpySection(this.el.nativeElement, () => this.scrollSpy.setActiveSection(this.sectionId));
|
|
46
|
+
}
|
|
47
|
+
ngOnDestroy() {
|
|
48
|
+
this.stopObserving?.();
|
|
60
49
|
}
|
|
61
|
-
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.
|
|
62
|
-
static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "21.
|
|
50
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.26", ngImport: i0, type: ScrollSpyDirective, deps: [], target: i0.ɵɵFactoryTarget.Directive });
|
|
51
|
+
static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "21.2.26", type: ScrollSpyDirective, isStandalone: true, selector: "[appScrollSpy]", inputs: { sectionId: ["appScrollSpy", "sectionId"] }, ngImport: i0 });
|
|
63
52
|
}
|
|
64
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.
|
|
53
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.26", ngImport: i0, type: ScrollSpyDirective, decorators: [{
|
|
65
54
|
type: Directive,
|
|
66
55
|
args: [{
|
|
67
56
|
selector: '[appScrollSpy]',
|
|
@@ -72,10 +61,6 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.1.2", ngImpor
|
|
|
72
61
|
args: ['appScrollSpy']
|
|
73
62
|
}] } });
|
|
74
63
|
|
|
75
|
-
/*
|
|
76
|
-
* Public API Surface of scroll-spy
|
|
77
|
-
*/
|
|
78
|
-
|
|
79
64
|
/**
|
|
80
65
|
* Generated bundle index. Do not edit.
|
|
81
66
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"su-labs-scroll-spy.mjs","sources":["../../../../
|
|
1
|
+
{"version":3,"file":"su-labs-scroll-spy.mjs","sources":["../../../../compat/angular-21/build/scroll-spy/src/lib/scroll-spy.service.ts","../../../../compat/angular-21/build/scroll-spy/src/lib/scroll-spy.directive.ts","../../../../compat/angular-21/build/scroll-spy/src/su-labs-scroll-spy.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","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public-api';\n"],"names":[],"mappings":";;;;AAEA;;;;;;AAMG;MAEU,gBAAgB,CAAA;;AAE3B,IAAA,aAAa,GAAG,MAAM,CAAS,EAAE,oFAAC;AAElC;;;AAGG;AACH,IAAA,gBAAgB,CAAC,EAAU,EAAA;AACzB,QAAA,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,EAAE,CAAC;IAC5B;wGAVW,gBAAgB,EAAA,IAAA,EAAA,EAAA,EAAA,MAAA,EAAA,EAAA,CAAA,eAAA,CAAA,UAAA,EAAA,CAAA;AAAhB,IAAA,OAAA,KAAA,GAAA,EAAA,CAAA,qBAAA,CAAA,EAAA,UAAA,EAAA,QAAA,EAAA,OAAA,EAAA,SAAA,EAAA,QAAA,EAAA,EAAA,EAAA,IAAA,EAAA,gBAAgB,cADH,MAAM,EAAA,CAAA;;4FACnB,gBAAgB,EAAA,UAAA,EAAA,CAAA;kBAD5B,UAAU;mBAAC,EAAE,UAAU,EAAE,MAAM,EAAE;;;ACJlC;;;;;;AAMG;MAKU,kBAAkB,CAAA;;AAEN,IAAA,SAAS;AAEf,IAAA,EAAE,GAAG,MAAM,CAAsB,UAAU,CAAC;AAC5C,IAAA,SAAS,GAAG,MAAM,CAAC,gBAAgB,CAAC;;AAG7C,IAAA,aAAa;IAErB,QAAQ,GAAA;QACN,IAAI,CAAC,aAAa,GAAG,yBAAyB,CAAC,IAAI,CAAC,EAAE,CAAC,aAAa,EAAE,MACpE,IAAI,CAAC,SAAS,CAAC,gBAAgB,CAAC,IAAI,CAAC,SAAS,CAAC,CAChD;IACH;IAEA,WAAW,GAAA;AACT,QAAA,IAAI,CAAC,aAAa,IAAI;IACxB;wGAlBW,kBAAkB,EAAA,IAAA,EAAA,EAAA,EAAA,MAAA,EAAA,EAAA,CAAA,eAAA,CAAA,SAAA,EAAA,CAAA;4FAAlB,kBAAkB,EAAA,YAAA,EAAA,IAAA,EAAA,QAAA,EAAA,gBAAA,EAAA,MAAA,EAAA,EAAA,SAAA,EAAA,CAAA,cAAA,EAAA,WAAA,CAAA,EAAA,EAAA,QAAA,EAAA,EAAA,EAAA,CAAA;;4FAAlB,kBAAkB,EAAA,UAAA,EAAA,CAAA;kBAJ9B,SAAS;AAAC,YAAA,IAAA,EAAA,CAAA;AACT,oBAAA,QAAQ,EAAE,gBAAgB;AAC1B,oBAAA,UAAU,EAAE,IAAI;AACjB,iBAAA;;sBAGE,KAAK;uBAAC,cAAc;;;AClBvB;;AAEG;;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@su-labs/scroll-spy",
|
|
3
|
-
"version": "21.
|
|
3
|
+
"version": "21.1.2",
|
|
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": "^21.0.0"
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
|
+
"@su-labs/core": "1.9.0",
|
|
36
37
|
"tslib": "^2.3.0"
|
|
37
38
|
},
|
|
38
39
|
"sideEffects": false,
|
|
@@ -47,5 +48,6 @@
|
|
|
47
48
|
"types": "./types/su-labs-scroll-spy.d.ts",
|
|
48
49
|
"default": "./fesm2022/su-labs-scroll-spy.mjs"
|
|
49
50
|
}
|
|
50
|
-
}
|
|
51
|
+
},
|
|
52
|
+
"type": "module"
|
|
51
53
|
}
|
|
@@ -1,30 +1,41 @@
|
|
|
1
1
|
import * as i0 from '@angular/core';
|
|
2
|
-
import { OnInit } from '@angular/core';
|
|
2
|
+
import { OnInit, OnDestroy } from '@angular/core';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Service that keeps track of the currently active section while scrolling.
|
|
6
6
|
* Can be injected into components to react to section changes.
|
|
7
|
+
*
|
|
8
|
+
* Sections are tracked by `ScrollSpyDirective`, which uses the framework-agnostic
|
|
9
|
+
* observer from `@su-labs/core/scroll-spy`.
|
|
7
10
|
*/
|
|
8
11
|
declare class ScrollSpyService {
|
|
9
|
-
/** ID of the currently visible section */
|
|
12
|
+
/** ID of the currently visible section ('' until a section becomes active) */
|
|
10
13
|
activeSection: i0.WritableSignal<string>;
|
|
14
|
+
/**
|
|
15
|
+
* Set the active section manually, for example when a navigation link is clicked.
|
|
16
|
+
* @param id ID of the section.
|
|
17
|
+
*/
|
|
18
|
+
setActiveSection(id: string): void;
|
|
11
19
|
static ɵfac: i0.ɵɵFactoryDeclaration<ScrollSpyService, never>;
|
|
12
20
|
static ɵprov: i0.ɵɵInjectableDeclaration<ScrollSpyService>;
|
|
13
21
|
}
|
|
14
22
|
|
|
15
23
|
/**
|
|
16
24
|
* Directive that observes an element's visibility on the screen
|
|
17
|
-
* and updates ScrollSpyService.activeSection when it
|
|
25
|
+
* and updates ScrollSpyService.activeSection when it reaches the vertical center of the viewport.
|
|
18
26
|
*
|
|
19
27
|
* Usage:
|
|
20
28
|
* <section [appScrollSpy]="'home'">...</section>
|
|
21
29
|
*/
|
|
22
|
-
declare class ScrollSpyDirective implements OnInit {
|
|
30
|
+
declare class ScrollSpyDirective implements OnInit, OnDestroy {
|
|
23
31
|
/** ID of the observed section */
|
|
24
32
|
sectionId: string;
|
|
25
33
|
private readonly el;
|
|
26
34
|
private readonly scrollSpy;
|
|
35
|
+
/** Stops observing the section */
|
|
36
|
+
private stopObserving?;
|
|
27
37
|
ngOnInit(): void;
|
|
38
|
+
ngOnDestroy(): void;
|
|
28
39
|
static ɵfac: i0.ɵɵFactoryDeclaration<ScrollSpyDirective, never>;
|
|
29
40
|
static ɵdir: i0.ɵɵDirectiveDeclaration<ScrollSpyDirective, "[appScrollSpy]", never, { "sectionId": { "alias": "appScrollSpy"; "required": false; }; }, {}, never, never, true, never>;
|
|
30
41
|
}
|