@su-labs/scroll-spy 21.0.5 → 22.0.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.
- package/CHANGELOG.md +6 -0
- package/README.md +33 -33
- package/fesm2022/su-labs-scroll-spy.mjs +80 -83
- package/fesm2022/su-labs-scroll-spy.mjs.map +1 -1
- package/package.json +5 -4
- package/types/su-labs-scroll-spy.d.ts +21 -20
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,12 @@ 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.0.0] - 2026-11-04
|
|
9
|
+
|
|
10
|
+
### Changed
|
|
11
|
+
- Upgrade to Angular 22 (peer dependencies now `^22.0.0`)
|
|
12
|
+
- Remove emojis from README.md
|
|
13
|
+
|
|
8
14
|
## [21.0.5] - 2026-02-04
|
|
9
15
|
|
|
10
16
|
### 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,7 +13,7 @@
|
|
|
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
|
+
## Table of Contents
|
|
17
17
|
|
|
18
18
|
- [Why Use This Library?](#-why-use-this-library)
|
|
19
19
|
- [Features](#features)
|
|
@@ -29,16 +29,16 @@ A lightweight Angular service and directive for managing active sections based o
|
|
|
29
29
|
- [Contributing](#contributing)
|
|
30
30
|
- [License](#license)
|
|
31
31
|
|
|
32
|
-
##
|
|
32
|
+
## Why Use This Library?
|
|
33
33
|
|
|
34
|
-
-
|
|
35
|
-
-
|
|
36
|
-
-
|
|
37
|
-
-
|
|
38
|
-
-
|
|
39
|
-
-
|
|
40
|
-
-
|
|
41
|
-
-
|
|
34
|
+
- **Lightweight** - Minimal bundle size
|
|
35
|
+
- **Reactive** - Built with Angular Signals
|
|
36
|
+
- **Performant** - Uses IntersectionObserver API
|
|
37
|
+
- **Flexible** - Works with any layout
|
|
38
|
+
- **Type-Safe** - Full TypeScript support
|
|
39
|
+
- **Zero Dependencies** - No bloat
|
|
40
|
+
- **Well Tested** - Comprehensive test coverage
|
|
41
|
+
- **Well Documented** - Clear examples and API docs
|
|
42
42
|
|
|
43
43
|
## Features
|
|
44
44
|
|
|
@@ -62,10 +62,10 @@ npm install @su-labs/scroll-spy
|
|
|
62
62
|
This library requires the following peer dependencies:
|
|
63
63
|
|
|
64
64
|
```sh
|
|
65
|
-
npm install @angular/common@^
|
|
65
|
+
npm install @angular/common@^22 @angular/core@^22
|
|
66
66
|
```
|
|
67
67
|
|
|
68
|
-
##
|
|
68
|
+
## Quick Start
|
|
69
69
|
|
|
70
70
|
```typescript
|
|
71
71
|
// 1. Install
|
|
@@ -154,7 +154,7 @@ export class ScrollExampleComponent {
|
|
|
154
154
|
}
|
|
155
155
|
```
|
|
156
156
|
|
|
157
|
-
##
|
|
157
|
+
## API Reference
|
|
158
158
|
|
|
159
159
|
### Service (ScrollSpyService)
|
|
160
160
|
|
|
@@ -191,17 +191,17 @@ export class ScrollExampleComponent {
|
|
|
191
191
|
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
192
|
|
|
193
193
|
**Key Benefits:**
|
|
194
|
-
-
|
|
195
|
-
-
|
|
196
|
-
-
|
|
197
|
-
-
|
|
194
|
+
- **Performance**: No scroll event listeners needed
|
|
195
|
+
- **Accuracy**: Precise intersection detection
|
|
196
|
+
- **Efficiency**: Browser-native implementation
|
|
197
|
+
- **Battery Friendly**: Optimized for mobile devices
|
|
198
198
|
|
|
199
|
-
##
|
|
199
|
+
## Browser Compatibility
|
|
200
200
|
|
|
201
201
|
Works in all modern browsers that support:
|
|
202
|
-
-
|
|
203
|
-
-
|
|
204
|
-
-
|
|
202
|
+
- IntersectionObserver API
|
|
203
|
+
- Angular 22+
|
|
204
|
+
- ES2022+
|
|
205
205
|
|
|
206
206
|
| Browser | Version |
|
|
207
207
|
|---------|---------|
|
|
@@ -210,16 +210,16 @@ Works in all modern browsers that support:
|
|
|
210
210
|
| Safari | ≥ 12.1 |
|
|
211
211
|
| Edge | ≥ 16 |
|
|
212
212
|
|
|
213
|
-
##
|
|
213
|
+
## Related Libraries
|
|
214
214
|
|
|
215
215
|
Part of the **@su-labs** suite:
|
|
216
216
|
|
|
217
|
-
-
|
|
218
|
-
-
|
|
219
|
-
-
|
|
220
|
-
-
|
|
217
|
+
- [@su-labs/visit-tracker](https://www.npmjs.com/package/@su-labs/visit-tracker) - User visit tracking
|
|
218
|
+
- [@su-labs/theme](https://www.npmjs.com/package/@su-labs/theme) - Theme management with dark mode support
|
|
219
|
+
- [@su-labs/notifications](https://www.npmjs.com/package/@su-labs/notifications) - Toast notification system
|
|
220
|
+
- [@su-labs/font-size](https://www.npmjs.com/package/@su-labs/font-size) - Accessible font size controls
|
|
221
221
|
|
|
222
|
-
##
|
|
222
|
+
## Troubleshooting
|
|
223
223
|
|
|
224
224
|
### Active section not updating?
|
|
225
225
|
|
|
@@ -235,13 +235,13 @@ Make sure you've imported `ScrollSpyDirective` in your component's imports array
|
|
|
235
235
|
|
|
236
236
|
### TypeScript errors?
|
|
237
237
|
|
|
238
|
-
Ensure you have Angular
|
|
238
|
+
Ensure you have Angular 22+ and TypeScript 6.0+ installed.
|
|
239
239
|
|
|
240
|
-
##
|
|
240
|
+
## Support
|
|
241
241
|
|
|
242
|
-
-
|
|
243
|
-
-
|
|
244
|
-
-
|
|
242
|
+
- Found a bug? [Open an issue](https://github.com/Greezaaa/settings-utils-lib/issues)
|
|
243
|
+
- Have a feature request? [Start a discussion](https://github.com/Greezaaa/settings-utils-lib/discussions)
|
|
244
|
+
- Like this library? [Give it a star!](https://github.com/Greezaaa/settings-utils-lib)
|
|
245
245
|
|
|
246
246
|
## Contributing
|
|
247
247
|
|
|
@@ -1,84 +1,81 @@
|
|
|
1
|
-
import * as i0 from
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
/**
|
|
80
|
-
* Generated bundle index. Do not edit.
|
|
81
|
-
*/
|
|
82
|
-
|
|
1
|
+
import * as i0 from "@angular/core";
|
|
2
|
+
import { Directive, ElementRef, Injectable, Input, inject, signal } from "@angular/core";
|
|
3
|
+
var ScrollSpyService = class ScrollSpyService {
|
|
4
|
+
activeSection = signal("", ...ngDevMode ? [{ debugName: "activeSection" }] : /* istanbul ignore next */ []);
|
|
5
|
+
static ɵfac = i0.ɵɵngDeclareFactory({
|
|
6
|
+
minVersion: "12.0.0",
|
|
7
|
+
version: "22.2.4",
|
|
8
|
+
ngImport: i0,
|
|
9
|
+
type: ScrollSpyService,
|
|
10
|
+
deps: [],
|
|
11
|
+
target: i0.ɵɵFactoryTarget.Injectable
|
|
12
|
+
});
|
|
13
|
+
static ɵprov = i0.ɵɵngDeclareInjectable({
|
|
14
|
+
minVersion: "12.0.0",
|
|
15
|
+
version: "22.2.4",
|
|
16
|
+
ngImport: i0,
|
|
17
|
+
type: ScrollSpyService,
|
|
18
|
+
providedIn: "root"
|
|
19
|
+
});
|
|
20
|
+
};
|
|
21
|
+
i0.ɵɵngDeclareClassMetadata({
|
|
22
|
+
minVersion: "12.0.0",
|
|
23
|
+
version: "22.2.4",
|
|
24
|
+
ngImport: i0,
|
|
25
|
+
type: ScrollSpyService,
|
|
26
|
+
decorators: [{
|
|
27
|
+
type: Injectable,
|
|
28
|
+
args: [{ providedIn: "root" }]
|
|
29
|
+
}]
|
|
30
|
+
});
|
|
31
|
+
var ScrollSpyDirective = class ScrollSpyDirective {
|
|
32
|
+
sectionId;
|
|
33
|
+
el = inject(ElementRef);
|
|
34
|
+
scrollSpy = inject(ScrollSpyService);
|
|
35
|
+
ngOnInit() {
|
|
36
|
+
new IntersectionObserver((entries) => {
|
|
37
|
+
for (const entry of entries) if (entry.isIntersecting) this.scrollSpy.activeSection.set(this.sectionId);
|
|
38
|
+
}, {
|
|
39
|
+
root: null,
|
|
40
|
+
threshold: 0,
|
|
41
|
+
rootMargin: "-50% 0px -50% 0px"
|
|
42
|
+
}).observe(this.el.nativeElement);
|
|
43
|
+
}
|
|
44
|
+
static ɵfac = i0.ɵɵngDeclareFactory({
|
|
45
|
+
minVersion: "12.0.0",
|
|
46
|
+
version: "22.2.4",
|
|
47
|
+
ngImport: i0,
|
|
48
|
+
type: ScrollSpyDirective,
|
|
49
|
+
deps: [],
|
|
50
|
+
target: i0.ɵɵFactoryTarget.Directive
|
|
51
|
+
});
|
|
52
|
+
static ɵdir = i0.ɵɵngDeclareDirective({
|
|
53
|
+
minVersion: "14.0.0",
|
|
54
|
+
version: "22.2.4",
|
|
55
|
+
type: ScrollSpyDirective,
|
|
56
|
+
isStandalone: true,
|
|
57
|
+
selector: "[appScrollSpy]",
|
|
58
|
+
inputs: { sectionId: ["appScrollSpy", "sectionId"] },
|
|
59
|
+
ngImport: i0
|
|
60
|
+
});
|
|
61
|
+
};
|
|
62
|
+
i0.ɵɵngDeclareClassMetadata({
|
|
63
|
+
minVersion: "12.0.0",
|
|
64
|
+
version: "22.2.4",
|
|
65
|
+
ngImport: i0,
|
|
66
|
+
type: ScrollSpyDirective,
|
|
67
|
+
decorators: [{
|
|
68
|
+
type: Directive,
|
|
69
|
+
args: [{
|
|
70
|
+
selector: "[appScrollSpy]",
|
|
71
|
+
standalone: true
|
|
72
|
+
}]
|
|
73
|
+
}],
|
|
74
|
+
propDecorators: { sectionId: [{
|
|
75
|
+
type: Input,
|
|
76
|
+
args: ["appScrollSpy"]
|
|
77
|
+
}] }
|
|
78
|
+
});
|
|
83
79
|
export { ScrollSpyDirective, ScrollSpyService };
|
|
84
|
-
|
|
80
|
+
|
|
81
|
+
//# sourceMappingURL=su-labs-scroll-spy.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"su-labs-scroll-spy.mjs","sources":["../../../../projects/su-labs/scroll-spy/src/lib/scroll-spy.service.ts","../../../../projects/su-labs/scroll-spy/src/lib/scroll-spy.directive.ts"
|
|
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 enters 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 {\n /** ID of the observed section */\n @Input('appScrollSpy') sectionId!: string;\n\n private readonly el = inject(ElementRef);\n private readonly scrollSpy = inject(ScrollSpyService);\n\n ngOnInit() {\n const observer = new IntersectionObserver(\n (entries) => {\n for (const entry of entries) {\n if (entry.isIntersecting) {\n this.scrollSpy.activeSection.set(this.sectionId);\n }\n }\n },\n {\n // The viewport used to check visibility.\n // `null` means the browser viewport is used.\n root: null,\n // How much of the element needs to be visible to trigger the observer.\n // `0` means it triggers as soon as even one pixel is visible within the root + rootMargin.\n threshold: 0,\n // rootMargin defines an offset around the viewport that affects when the observer triggers.\n // Format: 'top right bottom left'\n // In this case:\n // - top: -50%\n // - right: 0px\n // - bottom: -50%\n // - left: 0px\n //\n // This means the observer will consider the element \"intersecting\" only when\n // it is roughly in the vertical center of the viewport.\n // It's perfect for scroll-spy behavior, because it triggers when the section\n // is the main focus on the screen, rather than just appearing at the top.\n rootMargin: '-50% 0px -50% 0px',\n },\n );\n observer.observe(this.el.nativeElement);\n }\n}\n"],"mappings":";;AAOA,IAAa,mBAAb,MAAa,iBAAgB;CAE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ACV,YAAY;EACb,CAAA;;;EAGE,MAAA;EAAM,MAAA,CAAA,cAAc"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@su-labs/scroll-spy",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "22.0.0",
|
|
4
4
|
"description": "An Angular scroll spy utility based on IntersectionObserver for tracking active sections or menu items.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"angular",
|
|
@@ -29,8 +29,8 @@
|
|
|
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": "^22.0.0",
|
|
33
|
+
"@angular/core": "^22.0.0"
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
36
|
"tslib": "^2.3.0"
|
|
@@ -47,5 +47,6 @@
|
|
|
47
47
|
"types": "./types/su-labs-scroll-spy.d.ts",
|
|
48
48
|
"default": "./fesm2022/su-labs-scroll-spy.mjs"
|
|
49
49
|
}
|
|
50
|
-
}
|
|
50
|
+
},
|
|
51
|
+
"type": "module"
|
|
51
52
|
}
|
|
@@ -1,17 +1,15 @@
|
|
|
1
|
-
import * as i0 from
|
|
2
|
-
import { OnInit } from
|
|
3
|
-
|
|
1
|
+
import * as i0 from "@angular/core";
|
|
2
|
+
import { OnInit } from "@angular/core";
|
|
4
3
|
/**
|
|
5
4
|
* Service that keeps track of the currently active section while scrolling.
|
|
6
5
|
* Can be injected into components to react to section changes.
|
|
7
6
|
*/
|
|
8
|
-
declare class ScrollSpyService {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
7
|
+
export declare class ScrollSpyService {
|
|
8
|
+
/** ID of the currently visible section */
|
|
9
|
+
activeSection: import("@angular/core").WritableSignal<string>;
|
|
10
|
+
static ɵfac: i0.ɵɵFactoryDeclaration<ScrollSpyService, never>;
|
|
11
|
+
static ɵprov: i0.ɵɵInjectableDeclaration<any>;
|
|
13
12
|
}
|
|
14
|
-
|
|
15
13
|
/**
|
|
16
14
|
* Directive that observes an element's visibility on the screen
|
|
17
15
|
* and updates ScrollSpyService.activeSection when it enters the viewport.
|
|
@@ -19,14 +17,17 @@ declare class ScrollSpyService {
|
|
|
19
17
|
* Usage:
|
|
20
18
|
* <section [appScrollSpy]="'home'">...</section>
|
|
21
19
|
*/
|
|
22
|
-
declare class ScrollSpyDirective implements OnInit {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
20
|
+
export declare class ScrollSpyDirective implements OnInit {
|
|
21
|
+
/** ID of the observed section */
|
|
22
|
+
sectionId: string;
|
|
23
|
+
private readonly el;
|
|
24
|
+
private readonly scrollSpy;
|
|
25
|
+
ngOnInit(): void;
|
|
26
|
+
static ɵfac: i0.ɵɵFactoryDeclaration<ScrollSpyDirective, never>;
|
|
27
|
+
static ɵdir: i0.ɵɵDirectiveDeclaration<ScrollSpyDirective, "[appScrollSpy]", never, {
|
|
28
|
+
"sectionId": {
|
|
29
|
+
"alias": "appScrollSpy";
|
|
30
|
+
"required": false;
|
|
31
|
+
};
|
|
32
|
+
}, {}, never, never, true, never>;
|
|
33
|
+
}
|