@su-labs/scroll-spy 21.0.5 → 22.1.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 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.0] - 2026-11-05
9
+
10
+ ### Added
11
+ - `ScrollSpyService.setActiveSection(id)` to set the active section manually (already documented in the README)
12
+
13
+ ### Changed
14
+ - Section observing moved to the framework-agnostic `@su-labs/core/scroll-spy`; `ScrollSpyDirective` now uses `observeSuScrollSpySection`
15
+ - Added `@su-labs/core` as a dependency
16
+ - README links to the `@su-labs/core` installation guides for non-Angular projects
17
+
18
+ ### Fixed
19
+ - `ScrollSpyDirective` now disconnects its IntersectionObserver when destroyed
20
+ - Repair table of contents links in README.md
21
+
22
+ ## [22.0.0] - 2026-11-04
23
+
24
+ ### Changed
25
+ - Upgrade to Angular 22 (peer dependencies now `^22.0.0`)
26
+ - Remove emojis from README.md
27
+
8
28
  ## [21.0.5] - 2026-02-04
9
29
 
10
30
  ### Changed
package/README.md CHANGED
@@ -3,7 +3,7 @@
3
3
  `@su-labs/scroll-spy`
4
4
 
5
5
  ![Angular](https://img.shields.io/badge/Angular-DD0031?style=for-the-badge&logo=angular&logoColor=white)
6
- ![Angular Version](https://img.shields.io/badge/Angular-v21-DD0031?style=for-the-badge&logo=angular&logoColor=white)
6
+ ![Angular Version](https://img.shields.io/badge/Angular-v22-DD0031?style=for-the-badge&logo=angular&logoColor=white)
7
7
  ![TypeScript](https://img.shields.io/badge/TypeScript-007ACC?style=for-the-badge&logo=typescript&logoColor=white)
8
8
  ![License](https://img.shields.io/badge/License-MIT-blue.svg?style=for-the-badge)
9
9
  ![NPM](https://img.shields.io/badge/NPM-CB3837?style=for-the-badge&logo=npm&logoColor=white)
@@ -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
- ## 📚 Table of Contents
16
+ > **Not using Angular?** The same scroll spy is available for React, 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
- - [Why Use This Library?](#-why-use-this-library)
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](#-quick-start)
23
+ - [Quick Start](#quick-start)
22
24
  - [Usage](#usage)
23
- - [API Reference](#-api-reference)
25
+ - [API Reference](#api-reference)
24
26
  - [How It Works](#how-it-works)
25
- - [Browser Compatibility](#-browser-compatibility)
26
- - [Related Libraries](#-related-libraries)
27
- - [Troubleshooting](#-troubleshooting)
28
- - [Support](#-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
- ## 💡 Why Use This Library?
34
+ ## Why Use This Library?
33
35
 
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
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
 
@@ -62,10 +64,10 @@ npm install @su-labs/scroll-spy
62
64
  This library requires the following peer dependencies:
63
65
 
64
66
  ```sh
65
- npm install @angular/common@^21 @angular/core@^21
67
+ npm install @angular/common@^22 @angular/core@^22
66
68
  ```
67
69
 
68
- ## 🚀 Quick Start
70
+ ## Quick Start
69
71
 
70
72
  ```typescript
71
73
  // 1. Install
@@ -154,7 +156,7 @@ export class ScrollExampleComponent {
154
156
  }
155
157
  ```
156
158
 
157
- ## 📖 API Reference
159
+ ## API Reference
158
160
 
159
161
  ### Service (ScrollSpyService)
160
162
 
@@ -162,7 +164,7 @@ export class ScrollExampleComponent {
162
164
 
163
165
  | Signal | Type | Description |
164
166
  |--------|------|-------------|
165
- | `activeSection()` | `string \| null` | ID of currently active section |
167
+ | `activeSection()` | `string` | ID of currently active section (`''` until a section becomes active) |
166
168
 
167
169
  #### Methods
168
170
 
@@ -191,17 +193,17 @@ export class ScrollExampleComponent {
191
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.
192
194
 
193
195
  **Key Benefits:**
194
- - 🚀 **Performance**: No scroll event listeners needed
195
- - 🎯 **Accuracy**: Precise intersection detection
196
- - ⚡ **Efficiency**: Browser-native implementation
197
- - 🔋 **Battery Friendly**: Optimized for mobile devices
196
+ - **Performance**: No scroll event listeners needed
197
+ - **Accuracy**: Precise intersection detection
198
+ - **Efficiency**: Browser-native implementation
199
+ - **Battery Friendly**: Optimized for mobile devices
198
200
 
199
- ## 🌐 Browser Compatibility
201
+ ## Browser Compatibility
200
202
 
201
203
  Works in all modern browsers that support:
202
- - ✅ IntersectionObserver API
203
- - ✅ Angular 21+
204
- - ✅ ES2022+
204
+ - IntersectionObserver API
205
+ - Angular 22+
206
+ - ES2022+
205
207
 
206
208
  | Browser | Version |
207
209
  |---------|---------|
@@ -210,16 +212,16 @@ Works in all modern browsers that support:
210
212
  | Safari | ≥ 12.1 |
211
213
  | Edge | ≥ 16 |
212
214
 
213
- ## 🔗 Related Libraries
215
+ ## Related Libraries
214
216
 
215
217
  Part of the **@su-labs** suite:
216
218
 
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
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
221
223
 
222
- ## 🔧 Troubleshooting
224
+ ## Troubleshooting
223
225
 
224
226
  ### Active section not updating?
225
227
 
@@ -235,13 +237,13 @@ Make sure you've imported `ScrollSpyDirective` in your component's imports array
235
237
 
236
238
  ### TypeScript errors?
237
239
 
238
- Ensure you have Angular 21+ and TypeScript 5.7+ installed.
240
+ Ensure you have Angular 22+ and TypeScript 6.0+ installed.
239
241
 
240
- ## 💬 Support
242
+ ## Support
241
243
 
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)
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)
245
247
 
246
248
  ## Contributing
247
249
 
@@ -1,84 +1,83 @@
1
- import * as i0 from '@angular/core';
2
- import { signal, Injectable, inject, ElementRef, Input, Directive } from '@angular/core';
3
-
4
- /**
5
- * Service that keeps track of the currently active section while scrolling.
6
- * Can be injected into components to react to section changes.
7
- */
8
- class ScrollSpyService {
9
- /** ID of the currently visible section */
10
- activeSection = signal('', ...(ngDevMode ? [{ debugName: "activeSection" }] : []));
11
- static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.1.2", ngImport: i0, type: ScrollSpyService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
12
- static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "21.1.2", ngImport: i0, type: ScrollSpyService, providedIn: 'root' });
13
- }
14
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.1.2", ngImport: i0, type: ScrollSpyService, decorators: [{
15
- type: Injectable,
16
- args: [{ providedIn: 'root' }]
17
- }] });
18
-
19
- /**
20
- * Directive that observes an element's visibility on the screen
21
- * and updates ScrollSpyService.activeSection when it enters the viewport.
22
- *
23
- * Usage:
24
- * <section [appScrollSpy]="'home'">...</section>
25
- */
26
- class ScrollSpyDirective {
27
- /** ID of the observed section */
28
- sectionId;
29
- el = inject(ElementRef);
30
- scrollSpy = inject(ScrollSpyService);
31
- ngOnInit() {
32
- const observer = new IntersectionObserver((entries) => {
33
- for (const entry of entries) {
34
- if (entry.isIntersecting) {
35
- this.scrollSpy.activeSection.set(this.sectionId);
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);
60
- }
61
- static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.1.2", ngImport: i0, type: ScrollSpyDirective, deps: [], target: i0.ɵɵFactoryTarget.Directive });
62
- static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "21.1.2", type: ScrollSpyDirective, isStandalone: true, selector: "[appScrollSpy]", inputs: { sectionId: ["appScrollSpy", "sectionId"] }, ngImport: i0 });
63
- }
64
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.1.2", ngImport: i0, type: ScrollSpyDirective, decorators: [{
65
- type: Directive,
66
- args: [{
67
- selector: '[appScrollSpy]',
68
- standalone: true,
69
- }]
70
- }], propDecorators: { sectionId: [{
71
- type: Input,
72
- args: ['appScrollSpy']
73
- }] } });
74
-
75
- /*
76
- * Public API Surface of scroll-spy
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
+ import { observeSuScrollSpySection } from "@su-labs/core/scroll-spy";
4
+ var ScrollSpyService = class ScrollSpyService {
5
+ activeSection = signal("", ...ngDevMode ? [{ debugName: "activeSection" }] : /* istanbul ignore next */ []);
6
+ setActiveSection(id) {
7
+ this.activeSection.set(id);
8
+ }
9
+ static ɵfac = i0.ɵɵngDeclareFactory({
10
+ minVersion: "12.0.0",
11
+ version: "22.2.4",
12
+ ngImport: i0,
13
+ type: ScrollSpyService,
14
+ deps: [],
15
+ target: i0.ɵɵFactoryTarget.Injectable
16
+ });
17
+ static ɵprov = i0.ɵɵngDeclareInjectable({
18
+ minVersion: "12.0.0",
19
+ version: "22.2.4",
20
+ ngImport: i0,
21
+ type: ScrollSpyService,
22
+ providedIn: "root"
23
+ });
24
+ };
25
+ i0.ɵɵngDeclareClassMetadata({
26
+ minVersion: "12.0.0",
27
+ version: "22.2.4",
28
+ ngImport: i0,
29
+ type: ScrollSpyService,
30
+ decorators: [{
31
+ type: Injectable,
32
+ args: [{ providedIn: "root" }]
33
+ }]
34
+ });
35
+ var ScrollSpyDirective = class ScrollSpyDirective {
36
+ sectionId;
37
+ el = inject(ElementRef);
38
+ scrollSpy = inject(ScrollSpyService);
39
+ stopObserving;
40
+ ngOnInit() {
41
+ this.stopObserving = observeSuScrollSpySection(this.el.nativeElement, () => this.scrollSpy.setActiveSection(this.sectionId));
42
+ }
43
+ ngOnDestroy() {
44
+ this.stopObserving?.();
45
+ }
46
+ static ɵfac = i0.ɵɵngDeclareFactory({
47
+ minVersion: "12.0.0",
48
+ version: "22.2.4",
49
+ ngImport: i0,
50
+ type: ScrollSpyDirective,
51
+ deps: [],
52
+ target: i0.ɵɵFactoryTarget.Directive
53
+ });
54
+ static ɵdir = i0.ɵɵngDeclareDirective({
55
+ minVersion: "14.0.0",
56
+ version: "22.2.4",
57
+ type: ScrollSpyDirective,
58
+ isStandalone: true,
59
+ selector: "[appScrollSpy]",
60
+ inputs: { sectionId: ["appScrollSpy", "sectionId"] },
61
+ ngImport: i0
62
+ });
63
+ };
64
+ i0.ɵɵngDeclareClassMetadata({
65
+ minVersion: "12.0.0",
66
+ version: "22.2.4",
67
+ ngImport: i0,
68
+ type: ScrollSpyDirective,
69
+ decorators: [{
70
+ type: Directive,
71
+ args: [{
72
+ selector: "[appScrollSpy]",
73
+ standalone: true
74
+ }]
75
+ }],
76
+ propDecorators: { sectionId: [{
77
+ type: Input,
78
+ args: ["appScrollSpy"]
79
+ }] }
80
+ });
83
81
  export { ScrollSpyDirective, ScrollSpyService };
84
- //# sourceMappingURL=su-labs-scroll-spy.mjs.map
82
+
83
+ //# 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","../../../../projects/su-labs/scroll-spy/src/public-api.ts","../../../../projects/su-labs/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@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","/*\n * Public API Surface of scroll-spy\n */\n\nexport * from './lib/scroll-spy.service';\nexport * from './lib/scroll-spy.directive';\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public-api';\n"],"names":[],"mappings":";;;AAEA;;;AAGG;MAEU,gBAAgB,CAAA;;AAE3B,IAAA,aAAa,GAAG,MAAM,CAAS,EAAE,yDAAC;uGAFvB,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,QAAA,EAAA,QAAA,EAAA,EAAA,EAAA,IAAA,EAAA,gBAAgB,cADH,MAAM,EAAA,CAAA;;2FACnB,gBAAgB,EAAA,UAAA,EAAA,CAAA;kBAD5B,UAAU;mBAAC,EAAE,UAAU,EAAE,MAAM,EAAE;;;ACHlC;;;;;;AAMG;MAKU,kBAAkB,CAAA;;AAEN,IAAA,SAAS;AAEf,IAAA,EAAE,GAAG,MAAM,CAAC,UAAU,CAAC;AACvB,IAAA,SAAS,GAAG,MAAM,CAAC,gBAAgB,CAAC;IAErD,QAAQ,GAAA;QACN,MAAM,QAAQ,GAAG,IAAI,oBAAoB,CACvC,CAAC,OAAO,KAAI;AACV,YAAA,KAAK,MAAM,KAAK,IAAI,OAAO,EAAE;AAC3B,gBAAA,IAAI,KAAK,CAAC,cAAc,EAAE;oBACxB,IAAI,CAAC,SAAS,CAAC,aAAa,CAAC,GAAG,CAAC,IAAI,CAAC,SAAS,CAAC;gBAClD;YACF;AACF,QAAA,CAAC,EACD;;;AAGE,YAAA,IAAI,EAAE,IAAI;;;AAGV,YAAA,SAAS,EAAE,CAAC;;;;;;;;;;;;;AAaZ,YAAA,UAAU,EAAE,mBAAmB;AAChC,SAAA,CACF;QACD,QAAQ,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC,aAAa,CAAC;IACzC;uGAvCW,kBAAkB,EAAA,IAAA,EAAA,EAAA,EAAA,MAAA,EAAA,EAAA,CAAA,eAAA,CAAA,SAAA,EAAA,CAAA;2FAAlB,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;;2FAAlB,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;;;AChBvB;;AAEG;;ACFH;;AAEG;;;;"}
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,gBAAA,CAAA,+BAAA,CAAA,CAAA;CAMlC,iBAAiB,IAAU;EACzB,KAAK,cAAc,IAAI,EAAE;CAC3B;CAVW,OAAA,OAAA,GAAA,mBAAA;EAAA,YAAA;EAAA,SAAA;EAAA,UAAA;EAAA,MAAA;EAAgB,MAAA,CAAA;EAAA,QAAA,GAAA,gBAAA;CAAA,CAAA;CAAhB,OAAA,QAAA,GAAA,sBAAA;EAAA,YAAA;EAAA,SAAA;EAAA,UAAA;EAAA,MAAA;EAAgB,YADH;CAAM,CAAA;;AACnB,GAAA,yBAAA;CAAA,YAAA;CAAA,SAAA;CAAA,UAAA;CAAA,MAAA;CAAgB,YAAA,CAAA;EAD5B,MAAA;EAAW,MAAA,CAAA,EAAE,YAAY,OAAM,CAAE;;;ACOlC,IAAa,qBAAb,MAAa,mBAAkB;CAEN;CAEN,KAAK,OAA4B,UAAU;CAC3C,YAAY,OAAO,gBAAgB;CAG5C;CAER,WAAQ;EACN,KAAK,gBAAgB,0BAA0B,KAAK,GAAG,qBACrD,KAAK,UAAU,iBAAiB,KAAK,SAAS,CAAC;CAEnD;CAEA,cAAW;EACT,KAAK,gBAAe;CACtB;CAlBW,OAAA,OAAA,GAAA,mBAAA;EAAA,YAAA;EAAA,SAAA;EAAA,UAAA;EAAA,MAAA;EAAkB,MAAA,CAAA;EAAA,QAAA,GAAA,gBAAA;CAAA,CAAA;CAAlB,OAAA,OAAA,GAAA,qBAAA;EAAA,YAAA;EAAA,SAAA;EAAA,MAAA;EAAkB,cAAA;EAAA,UAAA;EAAA,QAAA,EAAA,WAAA,CAAA,gBAAA,WAAA,EAAA;EAAA,UAAA;CAAA,CAAA;;AAAlB,GAAA,yBAAA;CAAA,YAAA;CAAA,SAAA;CAAA,UAAA;CAAA,MAAA;CAAkB,YAAA,CAAA;EAJ9B,MAAA;EAAU,MAAA,CAAA;GACT,UAAU;GACV,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": "21.0.5",
3
+ "version": "22.1.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,10 +29,11 @@
29
29
  "url": "https://github.com/Greezaaa/settings-utils-lib/issues"
30
30
  },
31
31
  "peerDependencies": {
32
- "@angular/common": "^21.0.0",
33
- "@angular/core": "^21.0.0"
32
+ "@angular/common": "^22.0.0",
33
+ "@angular/core": "^22.0.0"
34
34
  },
35
35
  "dependencies": {
36
+ "@su-labs/core": "^1.0.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,32 +1,44 @@
1
- import * as i0 from '@angular/core';
2
- import { OnInit } from '@angular/core';
3
-
1
+ import * as i0 from "@angular/core";
2
+ import { OnDestroy, 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.
6
+ *
7
+ * Sections are tracked by `ScrollSpyDirective`, which uses the framework-agnostic
8
+ * observer from `@su-labs/core/scroll-spy`.
7
9
  */
8
- declare class ScrollSpyService {
9
- /** ID of the currently visible section */
10
- activeSection: i0.WritableSignal<string>;
11
- static ɵfac: i0.ɵɵFactoryDeclaration<ScrollSpyService, never>;
12
- static ɵprov: i0.ɵɵInjectableDeclaration<ScrollSpyService>;
10
+ export declare class ScrollSpyService {
11
+ /** ID of the currently visible section ('' until a section becomes active) */
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;
18
+ static ɵfac: i0.ɵɵFactoryDeclaration<ScrollSpyService, never>;
19
+ static ɵprov: i0.ɵɵInjectableDeclaration<any>;
13
20
  }
14
-
15
21
  /**
16
22
  * Directive that observes an element's visibility on the screen
17
- * and updates ScrollSpyService.activeSection when it enters the viewport.
23
+ * and updates ScrollSpyService.activeSection when it reaches the vertical center of the viewport.
18
24
  *
19
25
  * Usage:
20
26
  * <section [appScrollSpy]="'home'">...</section>
21
27
  */
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 };
28
+ export declare class ScrollSpyDirective implements OnInit, OnDestroy {
29
+ /** ID of the observed section */
30
+ sectionId: string;
31
+ private readonly el;
32
+ private readonly scrollSpy;
33
+ /** Stops observing the section */
34
+ private stopObserving?;
35
+ ngOnInit(): void;
36
+ ngOnDestroy(): void;
37
+ static ɵfac: i0.ɵɵFactoryDeclaration<ScrollSpyDirective, never>;
38
+ static ɵdir: i0.ɵɵDirectiveDeclaration<ScrollSpyDirective, "[appScrollSpy]", never, {
39
+ "sectionId": {
40
+ "alias": "appScrollSpy";
41
+ "required": false;
42
+ };
43
+ }, {}, never, never, true, never>;
44
+ }