@su-labs/scroll-spy 21.0.4 → 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 +36 -1
- package/README.md +162 -1
- 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,42 @@ 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
|
+
|
|
39
|
+
## [21.0.5] - 2026-02-04
|
|
40
|
+
|
|
41
|
+
### Changed
|
|
42
|
+
- Update README.md
|
|
43
|
+
|
|
8
44
|
## [21.0.4] - 2026-02-03
|
|
9
45
|
|
|
10
46
|
### Changed
|
|
@@ -16,7 +52,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
16
52
|
- Projects using Angular 20 or below should continue using version 1.0.3.
|
|
17
53
|
- This release maintains full backward compatibility with the 1.x API - only the Angular version requirement has changed.
|
|
18
54
|
|
|
19
|
-
|
|
20
55
|
## [1.0.2] - 2025-08-30
|
|
21
56
|
|
|
22
57
|
### Fixed
|
package/README.md
CHANGED
|
@@ -1,7 +1,47 @@
|
|
|
1
1
|
# ScrollSpy
|
|
2
2
|
|
|
3
|
+
`@su-labs/scroll-spy`
|
|
4
|
+
|
|
5
|
+

|
|
6
|
+

|
|
7
|
+

|
|
8
|
+

|
|
9
|
+

|
|
10
|
+

|
|
11
|
+

|
|
12
|
+

|
|
13
|
+
|
|
3
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.
|
|
4
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
|
+
|
|
18
|
+
## Table of Contents
|
|
19
|
+
|
|
20
|
+
- [Why Use This Library?](#why-use-this-library)
|
|
21
|
+
- [Features](#features)
|
|
22
|
+
- [Installation](#installation)
|
|
23
|
+
- [Quick Start](#quick-start)
|
|
24
|
+
- [Usage](#usage)
|
|
25
|
+
- [API Reference](#api-reference)
|
|
26
|
+
- [How It Works](#how-it-works)
|
|
27
|
+
- [Browser Compatibility](#browser-compatibility)
|
|
28
|
+
- [Related Libraries](#related-libraries)
|
|
29
|
+
- [Troubleshooting](#troubleshooting)
|
|
30
|
+
- [Support](#support)
|
|
31
|
+
- [Contributing](#contributing)
|
|
32
|
+
- [License](#license)
|
|
33
|
+
|
|
34
|
+
## Why Use This Library?
|
|
35
|
+
|
|
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
|
|
44
|
+
|
|
5
45
|
## Features
|
|
6
46
|
|
|
7
47
|
- Track the currently visible section on the page
|
|
@@ -9,15 +49,18 @@ A lightweight Angular service and directive for managing active sections based o
|
|
|
9
49
|
- Works with multiple sections
|
|
10
50
|
- Optional directive to automatically update the active section using IntersectionObserver
|
|
11
51
|
- Fully modular: use the service alone, or combine with the directive for automatic detection
|
|
52
|
+
- Configurable intersection thresholds
|
|
12
53
|
|
|
13
54
|
## Installation
|
|
14
55
|
|
|
15
56
|
You can install this library via npm:
|
|
16
57
|
|
|
17
58
|
```sh
|
|
18
|
-
npm install @su-labs/scroll-spy
|
|
59
|
+
npm install @su-labs/scroll-spy@ng21
|
|
19
60
|
```
|
|
20
61
|
|
|
62
|
+
This is the Angular 21 version. For the newest Angular, install `@su-labs/scroll-spy` without a tag.
|
|
63
|
+
|
|
21
64
|
## Peer Dependencies
|
|
22
65
|
|
|
23
66
|
This library requires the following peer dependencies:
|
|
@@ -26,6 +69,39 @@ This library requires the following peer dependencies:
|
|
|
26
69
|
npm install @angular/common@^21 @angular/core@^21
|
|
27
70
|
```
|
|
28
71
|
|
|
72
|
+
## Quick Start
|
|
73
|
+
|
|
74
|
+
```typescript
|
|
75
|
+
// 1. Install
|
|
76
|
+
npm install @su-labs/scroll-spy@ng21
|
|
77
|
+
|
|
78
|
+
// 2. Add directive to your sections
|
|
79
|
+
@for (section of sections; track section.id) {
|
|
80
|
+
<section [id]="section.id" [appScrollSpy]="section.id">
|
|
81
|
+
<h2>{{ section.name }}</h2>
|
|
82
|
+
</section>
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
// 3. Track active section in navigation
|
|
86
|
+
@for (section of sections; track section.id) {
|
|
87
|
+
<a
|
|
88
|
+
[href]="'#' + section.id"
|
|
89
|
+
[class.active]="activeSection() === section.id"
|
|
90
|
+
>
|
|
91
|
+
{{ section.name }}
|
|
92
|
+
</a>
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
// 4. Inject service in component
|
|
96
|
+
import { Component, inject } from '@angular/core';
|
|
97
|
+
import { ScrollSpyService } from '@su-labs/scroll-spy';
|
|
98
|
+
|
|
99
|
+
export class AppComponent {
|
|
100
|
+
scrollSpyService = inject(ScrollSpyService);
|
|
101
|
+
activeSection = this.scrollSpyService.activeSection;
|
|
102
|
+
}
|
|
103
|
+
```
|
|
104
|
+
|
|
29
105
|
## Usage
|
|
30
106
|
|
|
31
107
|
### Using the service and directive
|
|
@@ -82,10 +158,95 @@ export class ScrollExampleComponent {
|
|
|
82
158
|
}
|
|
83
159
|
```
|
|
84
160
|
|
|
161
|
+
## API Reference
|
|
162
|
+
|
|
163
|
+
### Service (ScrollSpyService)
|
|
164
|
+
|
|
165
|
+
#### Signals
|
|
166
|
+
|
|
167
|
+
| Signal | Type | Description |
|
|
168
|
+
|--------|------|-------------|
|
|
169
|
+
| `activeSection()` | `string` | ID of currently active section (`''` until a section becomes active) |
|
|
170
|
+
|
|
171
|
+
#### Methods
|
|
172
|
+
|
|
173
|
+
| Method | Parameters | Description |
|
|
174
|
+
|--------|------------|-------------|
|
|
175
|
+
| `setActiveSection(id)` | `string` | Manually set active section |
|
|
176
|
+
|
|
177
|
+
### Directive (ScrollSpyDirective)
|
|
178
|
+
|
|
179
|
+
#### Inputs
|
|
180
|
+
|
|
181
|
+
| Input | Type | Description |
|
|
182
|
+
|-------|------|-------------|
|
|
183
|
+
| `appScrollSpy` | `string` | Section ID to track |
|
|
184
|
+
|
|
185
|
+
#### How to Use
|
|
186
|
+
|
|
187
|
+
```html
|
|
188
|
+
<section [appScrollSpy]="'section-id'">
|
|
189
|
+
<!-- Your content -->
|
|
190
|
+
</section>
|
|
191
|
+
```
|
|
192
|
+
|
|
85
193
|
## How It Works
|
|
86
194
|
|
|
87
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.
|
|
88
196
|
|
|
197
|
+
**Key Benefits:**
|
|
198
|
+
- **Performance**: No scroll event listeners needed
|
|
199
|
+
- **Accuracy**: Precise intersection detection
|
|
200
|
+
- **Efficiency**: Browser-native implementation
|
|
201
|
+
- **Battery Friendly**: Optimized for mobile devices
|
|
202
|
+
|
|
203
|
+
## Browser Compatibility
|
|
204
|
+
|
|
205
|
+
Works in all modern browsers that support:
|
|
206
|
+
- IntersectionObserver API
|
|
207
|
+
- Angular 21
|
|
208
|
+
- ES2022+
|
|
209
|
+
|
|
210
|
+
| Browser | Version |
|
|
211
|
+
|---------|---------|
|
|
212
|
+
| Chrome | ≥ 58 |
|
|
213
|
+
| Firefox | ≥ 55 |
|
|
214
|
+
| Safari | ≥ 12.1 |
|
|
215
|
+
| Edge | ≥ 16 |
|
|
216
|
+
|
|
217
|
+
## Related Libraries
|
|
218
|
+
|
|
219
|
+
Part of the **@su-labs** suite:
|
|
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
|
|
225
|
+
|
|
226
|
+
## Troubleshooting
|
|
227
|
+
|
|
228
|
+
### Active section not updating?
|
|
229
|
+
|
|
230
|
+
Make sure you've added the `appScrollSpy` directive to all sections you want to track.
|
|
231
|
+
|
|
232
|
+
### Multiple sections active at once?
|
|
233
|
+
|
|
234
|
+
This shouldn't happen with the default configuration. Check that section IDs are unique.
|
|
235
|
+
|
|
236
|
+
### Directive not found?
|
|
237
|
+
|
|
238
|
+
Make sure you've imported `ScrollSpyDirective` in your component's imports array (for standalone components).
|
|
239
|
+
|
|
240
|
+
### TypeScript errors?
|
|
241
|
+
|
|
242
|
+
Ensure you have Angular 21 and TypeScript 5.9+ installed.
|
|
243
|
+
|
|
244
|
+
## Support
|
|
245
|
+
|
|
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)
|
|
249
|
+
|
|
89
250
|
## Contributing
|
|
90
251
|
|
|
91
252
|
If you find any bugs or have feature requests, please open an issue or submit a pull request on our [**GitHub repository**](https://github.com/Greezaaa/settings-utils-lib.git).
|
|
@@ -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
|
}
|