@su-labs/scroll-spy 1.0.2 → 19.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 +73 -0
- package/README.md +160 -1
- package/fesm2022/su-labs-scroll-spy.mjs +26 -41
- package/fesm2022/su-labs-scroll-spy.mjs.map +1 -1
- package/index.d.ts +3 -30
- package/lib/scroll-spy.directive.d.ts +21 -0
- package/lib/scroll-spy.service.d.ts +19 -0
- package/package.json +5 -4
- package/public-api.d.ts +2 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project will be documented in this file.
|
|
4
|
+
|
|
5
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
6
|
+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
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
|
+
|
|
28
|
+
## [22.0.0] - 2026-11-04
|
|
29
|
+
|
|
30
|
+
### Changed
|
|
31
|
+
- Upgrade to Angular 22 (peer dependencies now `^22.0.0`)
|
|
32
|
+
- Remove emojis from README.md
|
|
33
|
+
|
|
34
|
+
## [21.0.5] - 2026-02-04
|
|
35
|
+
|
|
36
|
+
### Changed
|
|
37
|
+
- Update README.md
|
|
38
|
+
|
|
39
|
+
## [21.0.4] - 2026-02-03
|
|
40
|
+
|
|
41
|
+
### Changed
|
|
42
|
+
- **BREAKING:** Updated to Angular 21 support. This version requires Angular 21.0.0 or higher.
|
|
43
|
+
- Updated peer dependencies to `@angular/common: ^21.0.0` and `@angular/core: ^21.0.0`.
|
|
44
|
+
- Aligned package version with Angular major version for clearer compatibility (v21.x.x = Angular 21 support).
|
|
45
|
+
|
|
46
|
+
### Notes
|
|
47
|
+
- Projects using Angular 20 or below should continue using version 1.0.3.
|
|
48
|
+
- This release maintains full backward compatibility with the 1.x API - only the Angular version requirement has changed.
|
|
49
|
+
|
|
50
|
+
## [1.0.2] - 2025-08-30
|
|
51
|
+
|
|
52
|
+
### Fixed
|
|
53
|
+
- Ensured `"license": "MIT"` is correctly reflected in the published package metadata.
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
## [1.0.1] - 2025-08-30
|
|
57
|
+
|
|
58
|
+
### Note
|
|
59
|
+
- This version was published with incorrect package content and is deprecated. Please use `1.0.4`.
|
|
60
|
+
|
|
61
|
+
## [1.0.0] - 2024-08-26
|
|
62
|
+
|
|
63
|
+
### Added
|
|
64
|
+
|
|
65
|
+
- Initial public release of the @su-labs/scroll-spy library.
|
|
66
|
+
|
|
67
|
+
- Introduction of ScrollSpyService, a reactive service that uses an Angular Signal to track the currently visible section.
|
|
68
|
+
|
|
69
|
+
- Introduction of ScrollSpyDirective, a standalone directive that uses the browser's native IntersectionObserver to automatically update the ScrollSpyService when a section enters the viewport.
|
|
70
|
+
|
|
71
|
+
- Configurable rootMargin to allow precise control over when the scroll-spy effect is triggered.
|
|
72
|
+
|
|
73
|
+
- Full support for modern Angular applications using @for, @if, and inject().
|
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,6 +49,7 @@ 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
|
|
|
@@ -23,7 +64,40 @@ npm install @su-labs/scroll-spy
|
|
|
23
64
|
This library requires the following peer dependencies:
|
|
24
65
|
|
|
25
66
|
```sh
|
|
26
|
-
npm install @angular/common@^
|
|
67
|
+
npm install @angular/common@^22 @angular/core@^22
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
## Quick Start
|
|
71
|
+
|
|
72
|
+
```typescript
|
|
73
|
+
// 1. Install
|
|
74
|
+
npm install @su-labs/scroll-spy
|
|
75
|
+
|
|
76
|
+
// 2. Add directive to your sections
|
|
77
|
+
@for (section of sections; track section.id) {
|
|
78
|
+
<section [id]="section.id" [appScrollSpy]="section.id">
|
|
79
|
+
<h2>{{ section.name }}</h2>
|
|
80
|
+
</section>
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
// 3. Track active section in navigation
|
|
84
|
+
@for (section of sections; track section.id) {
|
|
85
|
+
<a
|
|
86
|
+
[href]="'#' + section.id"
|
|
87
|
+
[class.active]="activeSection() === section.id"
|
|
88
|
+
>
|
|
89
|
+
{{ section.name }}
|
|
90
|
+
</a>
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
// 4. Inject service in component
|
|
94
|
+
import { Component, inject } from '@angular/core';
|
|
95
|
+
import { ScrollSpyService } from '@su-labs/scroll-spy';
|
|
96
|
+
|
|
97
|
+
export class AppComponent {
|
|
98
|
+
scrollSpyService = inject(ScrollSpyService);
|
|
99
|
+
activeSection = this.scrollSpyService.activeSection;
|
|
100
|
+
}
|
|
27
101
|
```
|
|
28
102
|
|
|
29
103
|
## Usage
|
|
@@ -82,10 +156,95 @@ export class ScrollExampleComponent {
|
|
|
82
156
|
}
|
|
83
157
|
```
|
|
84
158
|
|
|
159
|
+
## API Reference
|
|
160
|
+
|
|
161
|
+
### Service (ScrollSpyService)
|
|
162
|
+
|
|
163
|
+
#### Signals
|
|
164
|
+
|
|
165
|
+
| Signal | Type | Description |
|
|
166
|
+
|--------|------|-------------|
|
|
167
|
+
| `activeSection()` | `string` | ID of currently active section (`''` until a section becomes active) |
|
|
168
|
+
|
|
169
|
+
#### Methods
|
|
170
|
+
|
|
171
|
+
| Method | Parameters | Description |
|
|
172
|
+
|--------|------------|-------------|
|
|
173
|
+
| `setActiveSection(id)` | `string` | Manually set active section |
|
|
174
|
+
|
|
175
|
+
### Directive (ScrollSpyDirective)
|
|
176
|
+
|
|
177
|
+
#### Inputs
|
|
178
|
+
|
|
179
|
+
| Input | Type | Description |
|
|
180
|
+
|-------|------|-------------|
|
|
181
|
+
| `appScrollSpy` | `string` | Section ID to track |
|
|
182
|
+
|
|
183
|
+
#### How to Use
|
|
184
|
+
|
|
185
|
+
```html
|
|
186
|
+
<section [appScrollSpy]="'section-id'">
|
|
187
|
+
<!-- Your content -->
|
|
188
|
+
</section>
|
|
189
|
+
```
|
|
190
|
+
|
|
85
191
|
## How It Works
|
|
86
192
|
|
|
87
193
|
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
194
|
|
|
195
|
+
**Key Benefits:**
|
|
196
|
+
- **Performance**: No scroll event listeners needed
|
|
197
|
+
- **Accuracy**: Precise intersection detection
|
|
198
|
+
- **Efficiency**: Browser-native implementation
|
|
199
|
+
- **Battery Friendly**: Optimized for mobile devices
|
|
200
|
+
|
|
201
|
+
## Browser Compatibility
|
|
202
|
+
|
|
203
|
+
Works in all modern browsers that support:
|
|
204
|
+
- IntersectionObserver API
|
|
205
|
+
- Angular 22+
|
|
206
|
+
- ES2022+
|
|
207
|
+
|
|
208
|
+
| Browser | Version |
|
|
209
|
+
|---------|---------|
|
|
210
|
+
| Chrome | ≥ 58 |
|
|
211
|
+
| Firefox | ≥ 55 |
|
|
212
|
+
| Safari | ≥ 12.1 |
|
|
213
|
+
| Edge | ≥ 16 |
|
|
214
|
+
|
|
215
|
+
## Related Libraries
|
|
216
|
+
|
|
217
|
+
Part of the **@su-labs** suite:
|
|
218
|
+
|
|
219
|
+
- [@su-labs/visit-tracker](https://www.npmjs.com/package/@su-labs/visit-tracker) - User visit tracking
|
|
220
|
+
- [@su-labs/theme](https://www.npmjs.com/package/@su-labs/theme) - Theme management with dark mode support
|
|
221
|
+
- [@su-labs/notifications](https://www.npmjs.com/package/@su-labs/notifications) - Toast notification system
|
|
222
|
+
- [@su-labs/font-size](https://www.npmjs.com/package/@su-labs/font-size) - Accessible font size controls
|
|
223
|
+
|
|
224
|
+
## Troubleshooting
|
|
225
|
+
|
|
226
|
+
### Active section not updating?
|
|
227
|
+
|
|
228
|
+
Make sure you've added the `appScrollSpy` directive to all sections you want to track.
|
|
229
|
+
|
|
230
|
+
### Multiple sections active at once?
|
|
231
|
+
|
|
232
|
+
This shouldn't happen with the default configuration. Check that section IDs are unique.
|
|
233
|
+
|
|
234
|
+
### Directive not found?
|
|
235
|
+
|
|
236
|
+
Make sure you've imported `ScrollSpyDirective` in your component's imports array (for standalone components).
|
|
237
|
+
|
|
238
|
+
### TypeScript errors?
|
|
239
|
+
|
|
240
|
+
Ensure you have Angular 22+ and TypeScript 6.0+ installed.
|
|
241
|
+
|
|
242
|
+
## Support
|
|
243
|
+
|
|
244
|
+
- Found a bug? [Open an issue](https://github.com/Greezaaa/settings-utils-lib/issues)
|
|
245
|
+
- Have a feature request? [Start a discussion](https://github.com/Greezaaa/settings-utils-lib/discussions)
|
|
246
|
+
- Like this library? [Give it a star!](https://github.com/Greezaaa/settings-utils-lib)
|
|
247
|
+
|
|
89
248
|
## Contributing
|
|
90
249
|
|
|
91
250
|
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(''
|
|
11
|
-
|
|
12
|
-
|
|
13
|
+
/** ID of the currently visible section ('' until a section becomes active) */
|
|
14
|
+
activeSection = signal('');
|
|
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: "19.2.25", ngImport: i0, type: ScrollSpyService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
|
|
23
|
+
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "19.2.25", ngImport: i0, type: ScrollSpyService, providedIn: 'root' });
|
|
13
24
|
}
|
|
14
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "
|
|
25
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.25", 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: "
|
|
62
|
-
static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "
|
|
50
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.25", ngImport: i0, type: ScrollSpyDirective, deps: [], target: i0.ɵɵFactoryTarget.Directive });
|
|
51
|
+
static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "19.2.25", type: ScrollSpyDirective, isStandalone: true, selector: "[appScrollSpy]", inputs: { sectionId: ["appScrollSpy", "sectionId"] }, ngImport: i0 });
|
|
63
52
|
}
|
|
64
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "
|
|
53
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.25", 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: "20.1.7", 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-19/build/scroll-spy/src/lib/scroll-spy.service.ts","../../../../compat/angular-19/build/scroll-spy/src/lib/scroll-spy.directive.ts","../../../../compat/angular-19/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,CAAC;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;8BAGwB,SAAS,EAAA,CAAA;sBAA/B,KAAK;uBAAC,cAAc;;;AClBvB;;AAEG;;;;"}
|
package/index.d.ts
CHANGED
|
@@ -1,32 +1,5 @@
|
|
|
1
|
-
import * as i0 from '@angular/core';
|
|
2
|
-
import { OnInit } from '@angular/core';
|
|
3
|
-
|
|
4
1
|
/**
|
|
5
|
-
*
|
|
6
|
-
* Can be injected into components to react to section changes.
|
|
2
|
+
* Generated bundle index. Do not edit.
|
|
7
3
|
*/
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
activeSection: i0.WritableSignal<string>;
|
|
11
|
-
static ɵfac: i0.ɵɵFactoryDeclaration<ScrollSpyService, never>;
|
|
12
|
-
static ɵprov: i0.ɵɵInjectableDeclaration<ScrollSpyService>;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* Directive that observes an element's visibility on the screen
|
|
17
|
-
* and updates ScrollSpyService.activeSection when it enters the viewport.
|
|
18
|
-
*
|
|
19
|
-
* Usage:
|
|
20
|
-
* <section [appScrollSpy]="'home'">...</section>
|
|
21
|
-
*/
|
|
22
|
-
declare class ScrollSpyDirective implements OnInit {
|
|
23
|
-
/** ID of the observed section */
|
|
24
|
-
sectionId: string;
|
|
25
|
-
private readonly el;
|
|
26
|
-
private readonly scrollSpy;
|
|
27
|
-
ngOnInit(): void;
|
|
28
|
-
static ɵfac: i0.ɵɵFactoryDeclaration<ScrollSpyDirective, never>;
|
|
29
|
-
static ɵdir: i0.ɵɵDirectiveDeclaration<ScrollSpyDirective, "[appScrollSpy]", never, { "sectionId": { "alias": "appScrollSpy"; "required": false; }; }, {}, never, never, true, never>;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
export { ScrollSpyDirective, ScrollSpyService };
|
|
4
|
+
/// <amd-module name="@su-labs/scroll-spy" />
|
|
5
|
+
export * from './public-api';
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { OnDestroy, OnInit } from '@angular/core';
|
|
2
|
+
import * as i0 from "@angular/core";
|
|
3
|
+
/**
|
|
4
|
+
* Directive that observes an element's visibility on the screen
|
|
5
|
+
* and updates ScrollSpyService.activeSection when it reaches the vertical center of the viewport.
|
|
6
|
+
*
|
|
7
|
+
* Usage:
|
|
8
|
+
* <section [appScrollSpy]="'home'">...</section>
|
|
9
|
+
*/
|
|
10
|
+
export declare class ScrollSpyDirective implements OnInit, OnDestroy {
|
|
11
|
+
/** ID of the observed section */
|
|
12
|
+
sectionId: string;
|
|
13
|
+
private readonly el;
|
|
14
|
+
private readonly scrollSpy;
|
|
15
|
+
/** Stops observing the section */
|
|
16
|
+
private stopObserving?;
|
|
17
|
+
ngOnInit(): void;
|
|
18
|
+
ngOnDestroy(): void;
|
|
19
|
+
static ɵfac: i0.ɵɵFactoryDeclaration<ScrollSpyDirective, never>;
|
|
20
|
+
static ɵdir: i0.ɵɵDirectiveDeclaration<ScrollSpyDirective, "[appScrollSpy]", never, { "sectionId": { "alias": "appScrollSpy"; "required": false; }; }, {}, never, never, true, never>;
|
|
21
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import * as i0 from "@angular/core";
|
|
2
|
+
/**
|
|
3
|
+
* Service that keeps track of the currently active section while scrolling.
|
|
4
|
+
* Can be injected into components to react to section changes.
|
|
5
|
+
*
|
|
6
|
+
* Sections are tracked by `ScrollSpyDirective`, which uses the framework-agnostic
|
|
7
|
+
* observer from `@su-labs/core/scroll-spy`.
|
|
8
|
+
*/
|
|
9
|
+
export declare class ScrollSpyService {
|
|
10
|
+
/** ID of the currently visible section ('' until a section becomes active) */
|
|
11
|
+
activeSection: import("@angular/core").WritableSignal<string>;
|
|
12
|
+
/**
|
|
13
|
+
* Set the active section manually, for example when a navigation link is clicked.
|
|
14
|
+
* @param id ID of the section.
|
|
15
|
+
*/
|
|
16
|
+
setActiveSection(id: string): void;
|
|
17
|
+
static ɵfac: i0.ɵɵFactoryDeclaration<ScrollSpyService, never>;
|
|
18
|
+
static ɵprov: i0.ɵɵInjectableDeclaration<ScrollSpyService>;
|
|
19
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@su-labs/scroll-spy",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "19.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,15 +24,16 @@
|
|
|
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
|
},
|
|
31
31
|
"peerDependencies": {
|
|
32
|
-
"@angular/common": "^
|
|
33
|
-
"@angular/core": "^
|
|
32
|
+
"@angular/common": "^19.0.0",
|
|
33
|
+
"@angular/core": "^19.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,
|
package/public-api.d.ts
ADDED