@solidexpert/ngx-page-scroll 0.0.0-stage → 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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2019 Sebastian Fuss
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,257 @@
1
- # Temporary Holding Version
2
-
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
1
+ # @solidexpert/ngx-page-scroll [![npm version](https://img.shields.io/npm/v/@solidexpert/ngx-page-scroll.svg?style=flat)](https://www.npmjs.com/package/@solidexpert/ngx-page-scroll) [![MIT license](http://img.shields.io/badge/license-MIT-brightgreen.svg)](http://opensource.org/licenses/MIT)
2
+
3
+ Animated scrolling functionality for angular written in pure typescript with no additional dependencies
4
+
5
+ Maintained by [solidexpert-ltd](https://github.com/solidexpert-ltd). Fork of [Nolanus/ngx-page-scroll](https://github.com/Nolanus/ngx-page-scroll) by Sebastian Fuss. The original MIT license and copyright are unchanged.
6
+
7
+ [![Build Status](https://github.com/solidexpert-ltd/ngx-page-scroll/actions/workflows/ci.yml/badge.svg)](https://github.com/solidexpert-ltd/ngx-page-scroll/actions/workflows/ci.yml)
8
+
9
+ ## Features
10
+
11
+ - flexible: trigger scroll animations after component load, server response, etc.
12
+ - easy-to-use directive: scroll to an element referenced in the href-attribute
13
+ (`href="#mytarget`) just by adding `pageScroll` directive
14
+ - customizable: adjust duration, offset or whether scrolling stops if the user interrupts
15
+ ([read more](https://github.com/Nolanus/ngx-page-scroll/wiki/Scroll-Interruption-Interference))
16
+ - use custom easing functions to calculate the scroll position over time
17
+ - works across routes (scrolls to target element as soon as the
18
+ routing has finished) and in both directions (horizontal/vertical)
19
+
20
+ ## Table of contents
21
+
22
+ - [ngx-page-scroll](#ngx-page-scroll--)
23
+ - [Features](#features)
24
+ - [Table of contents](#table-of-contents)
25
+ - [Version compatibility](#version-compatibility)
26
+ - [Service](#service)
27
+ - [Setup](#setup)
28
+ - [Usage](#usage)
29
+ - [Configuration](#configuration)
30
+ - [Directive](#directive)
31
+ - [Setup](#setup-1)
32
+ - [Usage](#usage-1)
33
+ - [Directive API](#directive-api)
34
+ - [PageScroll properties](#pagescroll-properties)
35
+ - [PageScroll events](#pagescroll-events)
36
+ - [Example](#example)
37
+ - [FAQ and common problems](#faq-and-common-problems)
38
+ - [License](#license)
39
+
40
+ ### Version compatibility
41
+
42
+ Install later versions in case your app is not running the very latest angular version.
43
+
44
+ | ngx-page-scroll/ngx-page-scroll-core version | compatible angular version | Documentation |
45
+ |----------------------------------------------|----------------------------|-----------------------------------------------------------------------------|
46
+ | @solidexpert 22.0.x | v22 | [README](README.md) |
47
+ | v17.x | v22 | [Nolanus v17](https://github.com/Nolanus/ngx-page-scroll/blob/master/README.md) |
48
+ | v16.x | v21 | [README](https://github.com/Nolanus/ngx-page-scroll/blob/v16.0.0/README.md) |
49
+ | v15.x | v20 | [README](https://github.com/Nolanus/ngx-page-scroll/blob/v15.0.1/README.md) |
50
+ | v14.x | v19 | [README](https://github.com/Nolanus/ngx-page-scroll/blob/v14.0.1/README.md) |
51
+ | v13.x | v18 | [README](https://github.com/Nolanus/ngx-page-scroll/blob/v13.0.0/README.md) |
52
+ | v12.x | v17 | [README](https://github.com/Nolanus/ngx-page-scroll/blob/v12.0.0/README.md) |
53
+ | v11.x | v16 | [README](https://github.com/Nolanus/ngx-page-scroll/blob/v11.0.0/README.md) |
54
+ | v10.x | v15 | [README](https://github.com/Nolanus/ngx-page-scroll/blob/v10.0.0/README.md) |
55
+ | v9.x | v14 | [README](https://github.com/Nolanus/ngx-page-scroll/blob/v9.0.0/README.md) |
56
+ | v8.x | v13 | [README](https://github.com/Nolanus/ngx-page-scroll/blob/v8.0.0/README.md) |
57
+ | v7.x | v12, v11, v10, v9, v8 | [README](https://github.com/Nolanus/ngx-page-scroll/blob/v7.0.6/README.md) |
58
+ | v6.x | v8, v7 | [README](https://github.com/Nolanus/ngx-page-scroll/blob/v6.0.2/README.md) |
59
+ | v5.x | v6 | [README](https://github.com/Nolanus/ngx-page-scroll/blob/v5.0.1/README.md) |
60
+ | v4.x | v5, v4 | [README](https://github.com/Nolanus/ngx-page-scroll/blob/v4.0.2/README.md) |
61
+
62
+ ## Service
63
+
64
+ ### Setup
65
+
66
+ First you need to install the core npm module:
67
+
68
+ ```sh
69
+ npm install @solidexpert/ngx-page-scroll-core --save
70
+ ```
71
+
72
+ Then add the `NgxPageScrollModule` to the imports array of your application module:
73
+
74
+ ```typescript
75
+ import { NgxPageScrollCoreModule } from '@solidexpert/ngx-page-scroll-core';
76
+
77
+ @NgModule({
78
+ imports: [
79
+ /* Other imports here */
80
+ NgxPageScrollCoreModule
81
+ ]
82
+ })
83
+ export class AppModule {
84
+ }
85
+ ```
86
+
87
+ ### Usage
88
+
89
+ Using the `PageScrollService#scroll` method you may trigger scroll animations. Provide an options object that provides a reference to the document and the scroll target. Additional properties are optional.
90
+
91
+ ```typescript
92
+ import { Inject } from '@angular/core';
93
+ import { DOCUMENT } from '@angular/common';
94
+ import { PageScrollService } from '@solidexpert/ngx-page-scroll-core';
95
+
96
+ export class MyComponent {
97
+ constructor(private pageScrollService: PageScrollService, @Inject(DOCUMENT) private document: any) {
98
+ }
99
+
100
+ ngOnInit(): void {
101
+ this.pageScrollService.scroll({
102
+ document: this.document,
103
+ scrollTarget: '.theEnd',
104
+ });
105
+ }
106
+ }
107
+ ```
108
+
109
+ Note: The `scroll()` method is a shorthand from creating a `PageScrollInstance` (an object encapsulating all information
110
+ relevant for performing a scroll animation) using `PageScrollService#create` and starting it using
111
+ the `PageScrollService#start` method.
112
+
113
+ ### Configuration
114
+
115
+ When importing the `PageScrollCoreModule` one can provide option overrides:
116
+
117
+ ```typescript
118
+ imports: [
119
+ ...
120
+ NgxPageScrollCoreModule.forRoot({duration: 2500, easingLogic: ...}),
121
+ ]
122
+ ```
123
+
124
+ Check the [`PageScrollConfig` interface](https://github.com/solidexpert-ltd/ngx-page-scroll/blob/master/projects/ngx-page-scroll-core/src/lib/types/page-scroll.config.ts#L3)
125
+ for possible options and their impact. The default values may be found in the [`defaultPageScrollConfig`](https://github.com/solidexpert-ltd/ngx-page-scroll/blob/master/projects/ngx-page-scroll-core/src/lib/providers/config.provider.ts)
126
+ object.
127
+
128
+ ## Directive
129
+
130
+ For ease of use a directive `pageScroll` exists, which allows you to quickly add scroll animations to your angular app by
131
+ adding a property to your existing HTML a-tags. It can also work cross-routes, meaning it will start the scroll animation
132
+ after the target route has been loaded.
133
+ It utilizes the ngx-page-scroll-core module for that, thus requires it as a peer dependency.
134
+
135
+ ### Setup
136
+
137
+ First you need to install the directive npm module:
138
+
139
+ ```sh
140
+ npm install @solidexpert/ngx-page-scroll --save
141
+ ```
142
+
143
+ Then add the `NgxPageScrollModule` to the imports array of your application module:
144
+
145
+ ```typescript
146
+ import { NgxPageScrollModule } from '@solidexpert/ngx-page-scroll';
147
+
148
+ @NgModule({
149
+ imports: [
150
+ /* Other imports here */
151
+ NgxPageScrollModule
152
+ ]
153
+ })
154
+ export class AppModule {
155
+ }
156
+ ```
157
+
158
+ ### Usage
159
+
160
+ In your template you may add the `pageScroll` attribute to elements with an `href` attribute pointing towards an id on
161
+ the same page (e.g. `#theId`). The `onClick` event will be interrupted and the scroll animation starts.
162
+ Alternatively you may set the optional `pageScrollTarget` property to a valid css selector to specify the
163
+ target element to scroll to.
164
+
165
+ ```typescript
166
+
167
+ @Component({
168
+ ...
169
+ template: `...
170
+ <a pageScroll href="#awesomePart">Take me to the awesomeness</a>
171
+ <!-- Further content here -->
172
+ <h2 id="awesomePart">This is where the awesome happens</h2>
173
+ ...`,
174
+ })
175
+ export class MyComponent {
176
+ }
177
+ ```
178
+
179
+ ### Directive API
180
+
181
+ Additional attributes may be set on an DOM element using the `pageScroll` directive for customization.
182
+ They take precedence over the default settings specified in `PageScrollConfig` class. Thereby it is
183
+ possible to have all page scroll-animations last e.g. 2 seconds, but a specific one should be performed with a custom easing function and a duration
184
+ of only 1 second.
185
+
186
+ #### PageScroll properties
187
+
188
+ | Attribute | Type | Default | Description |
189
+ | ------------------------- | ----------- | ------------ |-------------- |
190
+ | `pageScroll` | | | Attribute adding scroll-animation behavior when the `click`-event happens on the element. |
191
+ | `pageScrollTarget` | string | | Optional attribute to set the element that should be scrolled to. Takes precedence over the ´href´-value |
192
+ | `pageScrollHorizontal` | boolean | false | Whether the scroll should happen in vertical direction (`false`, default) or horizontal (`true`). |
193
+ | `pageScrollOffset` | number | 0 | Pixels to offset from the top of the element when scrolling to (positive value = scrolling will stop given pixels atop the target element). |
194
+ | `pageScrollDuration` | number | 1250 | Duration in milliseconds the whole scroll-animation should last. |
195
+ | `pageScrollSpeed` | number | - | Speed in Pixel/Second the animation should take. Only applied if no duration is set. |
196
+ | `pageScrollInView` | boolean | true | Whether the scroll animation should happen even when the scroll target is already inside the view port (`true`). Set to `false` to skip scroll animation if target is already in view. |
197
+ | `pageScrollInterruptible` | boolean | true | Whether the scroll animation should stop if the user interferes with it (`true`) or not (`false`). |
198
+ | `pageScrollAdjustHash` | boolean | false | Whether the [routes hash/fragment](https://angular.io/docs/ts/latest/guide/router.html#!#query-parameters) should be updated to reflect to section that has been scrolled to |
199
+ | `pageScrollEasing` | EasingLogic | linearEasing | Easing method to be used while calculating the scroll position over time (default is linear easing). |
200
+
201
+ #### PageScroll events
202
+
203
+ | Event | Type | Description |
204
+ | --------------------- | ------- | ------------- |
205
+ | `pageScrollFinish` | boolean | Fired when the scroll-animation stops. Emits a boolean value which indicates whether the scroll animation finished successfully and reached its target (`true`) or not (`false`). Possible reasons for false: target not found or interrupted due to another scroll animation starting or user interaction. |
206
+
207
+ #### Example
208
+
209
+ The following example will check whether the route _Home_ is currently loaded.
210
+ If this is true, the scroll-animation will be performed with the default
211
+ properties. If a different route is loaded, a subscription for route changes
212
+ will be made and the scroll-animation will be performed as soon as the new
213
+ route is loaded.
214
+
215
+ ```html
216
+ <a pageScroll [routerLink]="['Home']" href="#myanchor">Go there</a>
217
+ ```
218
+
219
+ Overriding all possible properties. `doSmth()` and `myEasing` are
220
+ defined in the component
221
+
222
+ ```html
223
+ <a pageScroll [pageScrollOffset]="0" [pageScrollDuration]="2000" [pageScrollEasing]="myEasing" [pageScrollInterruptible]="false" (pageScrollFinish)="doSmth($event)" href="#theanchor">Visit</a>
224
+ ```
225
+
226
+ ```typescript
227
+ public myEasing: EasingLogic = (t: number, b: number, c: number, d: number): number => {
228
+ // easeInOutExpo easing
229
+ if (t === 0) {
230
+ return b;
231
+ }
232
+ if (t === d) {
233
+ return b + c;
234
+ }
235
+ if ((t /= d / 2) < 1) {
236
+ return c / 2 * Math.pow(2, 10 * (t - 1)) + b;
237
+ }
238
+
239
+ return c / 2 * (-Math.pow(2, -10 * --t) + 2) + b;
240
+ }
241
+
242
+ doSmth(reachedTarget: boolean): void {
243
+ if (reachedTarget) {
244
+ console.log('Yeah, we reached our destination');
245
+ } else {
246
+ console.log('Ohoh, something interrupted us');
247
+ }
248
+ }
249
+ ```
250
+
251
+ ## FAQ and common problems
252
+
253
+ Please have a look at the wiki section of the GitHub repo at [https://github.com/Nolanus/ngx-page-scroll/wiki/FAQ](https://github.com/Nolanus/ngx-page-scroll/wiki/FAQ) for frequent questions and problems.
254
+
255
+ ## License
256
+
257
+ [MIT](LICENSE)
@@ -0,0 +1,188 @@
1
+ import * as i0 from "@angular/core";
2
+ import { DOCUMENT, Directive, EventEmitter, Input, NgModule, Output, inject } from "@angular/core";
3
+ import { NgxPageScrollCoreModule, PageScrollService } from "@solidexpert/ngx-page-scroll-core";
4
+ import { NavigationCancel, NavigationEnd, NavigationError, Router } from "@angular/router";
5
+ import { filter, take } from "rxjs/operators";
6
+ var NgxPageScrollDirective = class NgxPageScrollDirective {
7
+ constructor() {
8
+ this.pageScrollService = inject(PageScrollService);
9
+ this.router = inject(Router, { optional: true });
10
+ this.pageScrollAdjustHash = false;
11
+ this.pageScrollFinish = new EventEmitter();
12
+ const document = inject(DOCUMENT);
13
+ this.document = document;
14
+ }
15
+ ngOnChanges(changes) {
16
+ this.pageScrollInstance = void 0;
17
+ }
18
+ ngOnDestroy() {
19
+ if (this.pageScrollInstance) this.pageScrollService.stop(this.pageScrollInstance);
20
+ }
21
+ getPageScrollTarget() {
22
+ return this.pageScrollTarget || this.href || (this.fragment ? "#" + this.fragment : "");
23
+ }
24
+ generatePageScrollInstance() {
25
+ if (this.pageScrollInstance === void 0 || this.pageScrollInstance === null) {
26
+ const options = {
27
+ document: this.document,
28
+ scrollTarget: this.getPageScrollTarget()
29
+ };
30
+ if (this.pageScroll) options.namespace = this.pageScroll;
31
+ if (this.pageScrollHorizontal !== void 0 && this.pageScrollHorizontal !== null) options.verticalScrolling = !this.pageScrollHorizontal;
32
+ if (this.pageScrollOffset !== void 0 && this.pageScrollOffset !== null) options.scrollOffset = this.pageScrollOffset;
33
+ if (this.pageScrollInterruptible !== void 0 && this.pageScrollInterruptible !== null) options.interruptible = this.pageScrollInterruptible;
34
+ if (this.pageScrollInView !== void 0 && this.pageScrollInView !== null) options.scrollInView = this.pageScrollInView;
35
+ if (this.pageScrollEasing) options.easingLogic = this.pageScrollEasing;
36
+ if (this.pageScrollDuration !== void 0 && this.pageScrollDuration !== null) options.duration = this.pageScrollDuration;
37
+ if (this.pageScrollSpeed !== void 0 && this.pageScrollSpeed !== null) options.speed = this.pageScrollSpeed;
38
+ if (this.pageScrollFinish) options.scrollFinishListener = this.pageScrollFinish;
39
+ this.pageScrollInstance = this.pageScrollService.create(options);
40
+ }
41
+ return this.pageScrollInstance;
42
+ }
43
+ pushRouterState() {
44
+ if (this.pageScrollAdjustHash && typeof this.pageScrollInstance.pageScrollOptions.scrollTarget === "string" && this.pageScrollInstance.pageScrollOptions.scrollTarget.substr(0, 1) === "#") this.router.navigate([], {
45
+ fragment: this.pageScrollInstance.pageScrollOptions.scrollTarget.substr(1),
46
+ queryParamsHandling: "preserve"
47
+ });
48
+ }
49
+ scroll() {
50
+ const pageScrollInstance = this.generatePageScrollInstance();
51
+ this.pushRouterState();
52
+ this.pageScrollService.start(pageScrollInstance);
53
+ }
54
+ handleClick(clickEvent) {
55
+ if (this.routerLink && this.router !== null && this.router !== void 0) {
56
+ let urlTree;
57
+ if (typeof this.routerLink === "string") urlTree = this.router.parseUrl(this.routerLink);
58
+ else urlTree = this.router.createUrlTree(this.routerLink);
59
+ if (!this.router.isActive(urlTree, true)) {
60
+ this.router.events.pipe(filter((routerEvent) => {
61
+ return routerEvent instanceof NavigationEnd || routerEvent instanceof NavigationError || routerEvent instanceof NavigationCancel;
62
+ }), take(1)).subscribe((routerEvent) => {
63
+ if (routerEvent instanceof NavigationEnd) setTimeout(() => {
64
+ this.scroll();
65
+ }, 0);
66
+ });
67
+ return false;
68
+ }
69
+ }
70
+ this.scroll();
71
+ return false;
72
+ }
73
+ static {
74
+ this.ɵfac = i0.ɵɵngDeclareFactory({
75
+ minVersion: "12.0.0",
76
+ version: "22.3.0",
77
+ ngImport: i0,
78
+ type: NgxPageScrollDirective,
79
+ deps: [],
80
+ target: i0.ɵɵFactoryTarget.Directive
81
+ });
82
+ }
83
+ static {
84
+ this.ɵdir = i0.ɵɵngDeclareDirective({
85
+ minVersion: "14.0.0",
86
+ version: "22.3.0",
87
+ type: NgxPageScrollDirective,
88
+ isStandalone: true,
89
+ selector: "[pageScroll]",
90
+ inputs: {
91
+ routerLink: "routerLink",
92
+ href: "href",
93
+ fragment: "fragment",
94
+ pageScrollTarget: "pageScrollTarget",
95
+ pageScrollHorizontal: "pageScrollHorizontal",
96
+ pageScrollOffset: "pageScrollOffset",
97
+ pageScrollDuration: "pageScrollDuration",
98
+ pageScrollSpeed: "pageScrollSpeed",
99
+ pageScrollEasing: "pageScrollEasing",
100
+ pageScrollInterruptible: "pageScrollInterruptible",
101
+ pageScrollInView: "pageScrollInView",
102
+ pageScrollAdjustHash: "pageScrollAdjustHash",
103
+ pageScroll: "pageScroll"
104
+ },
105
+ outputs: { pageScrollFinish: "pageScrollFinish" },
106
+ host: { listeners: { "click": "handleClick($event)" } },
107
+ usesOnChanges: true,
108
+ ngImport: i0
109
+ });
110
+ }
111
+ };
112
+ i0.ɵɵngDeclareClassMetadata({
113
+ minVersion: "12.0.0",
114
+ version: "22.3.0",
115
+ ngImport: i0,
116
+ type: NgxPageScrollDirective,
117
+ decorators: [{
118
+ type: Directive,
119
+ args: [{
120
+ selector: "[pageScroll]",
121
+ host: { "(click)": "handleClick($event)" }
122
+ }]
123
+ }],
124
+ ctorParameters: () => [],
125
+ propDecorators: {
126
+ routerLink: [{ type: Input }],
127
+ href: [{ type: Input }],
128
+ fragment: [{ type: Input }],
129
+ pageScrollTarget: [{ type: Input }],
130
+ pageScrollHorizontal: [{ type: Input }],
131
+ pageScrollOffset: [{ type: Input }],
132
+ pageScrollDuration: [{ type: Input }],
133
+ pageScrollSpeed: [{ type: Input }],
134
+ pageScrollEasing: [{ type: Input }],
135
+ pageScrollInterruptible: [{ type: Input }],
136
+ pageScrollInView: [{ type: Input }],
137
+ pageScrollAdjustHash: [{ type: Input }],
138
+ pageScroll: [{ type: Input }],
139
+ pageScrollFinish: [{ type: Output }]
140
+ }
141
+ });
142
+ var NgxPageScrollModule = class NgxPageScrollModule {
143
+ static {
144
+ this.ɵfac = i0.ɵɵngDeclareFactory({
145
+ minVersion: "12.0.0",
146
+ version: "22.3.0",
147
+ ngImport: i0,
148
+ type: NgxPageScrollModule,
149
+ deps: [],
150
+ target: i0.ɵɵFactoryTarget.NgModule
151
+ });
152
+ }
153
+ static {
154
+ this.ɵmod = i0.ɵɵngDeclareNgModule({
155
+ minVersion: "14.0.0",
156
+ version: "22.3.0",
157
+ ngImport: i0,
158
+ type: NgxPageScrollModule,
159
+ imports: [NgxPageScrollCoreModule, NgxPageScrollDirective],
160
+ exports: [NgxPageScrollDirective]
161
+ });
162
+ }
163
+ static {
164
+ this.ɵinj = i0.ɵɵngDeclareInjector({
165
+ minVersion: "12.0.0",
166
+ version: "22.3.0",
167
+ ngImport: i0,
168
+ type: NgxPageScrollModule,
169
+ imports: [NgxPageScrollCoreModule]
170
+ });
171
+ }
172
+ };
173
+ i0.ɵɵngDeclareClassMetadata({
174
+ minVersion: "12.0.0",
175
+ version: "22.3.0",
176
+ ngImport: i0,
177
+ type: NgxPageScrollModule,
178
+ decorators: [{
179
+ type: NgModule,
180
+ args: [{
181
+ imports: [NgxPageScrollCoreModule, NgxPageScrollDirective],
182
+ exports: [NgxPageScrollDirective]
183
+ }]
184
+ }]
185
+ });
186
+ export { NgxPageScrollDirective, NgxPageScrollModule };
187
+
188
+ //# sourceMappingURL=solidexpert-ngx-page-scroll.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"solidexpert-ngx-page-scroll.mjs","names":[],"sources":["../../../projects/ngx-page-scroll/src/lib/ngx-page-scroll.directive.ts","../../../projects/ngx-page-scroll/src/lib/ngx-page-scroll.module.ts"],"sourcesContent":["/* eslint-disable @angular-eslint/directive-selector */\r\n\r\nimport { Directive, EventEmitter, Input, OnChanges, OnDestroy, Output, SimpleChanges, DOCUMENT, inject } from '@angular/core';\r\nimport { NavigationCancel, NavigationEnd, NavigationError, Router, UrlTree } from '@angular/router';\r\n\r\n\r\nimport { EasingLogic, PageScrollInstance, PageScrollOptions, PageScrollService } from '@solidexpert/ngx-page-scroll-core';\r\nimport { filter, take } from 'rxjs/operators';\r\n\r\n@Directive({\r\n selector: '[pageScroll]',\r\n host: {\r\n '(click)': 'handleClick($event)',\r\n }\r\n})\r\nexport class NgxPageScrollDirective implements OnChanges, OnDestroy {\r\n private readonly pageScrollService = inject(PageScrollService);\r\n private readonly router = inject(Router, { optional: true });\r\n\r\n\r\n @Input()\r\n public routerLink;\r\n\r\n @Input()\r\n public href: string;\r\n\r\n @Input()\r\n public fragment: string;\r\n\r\n @Input()\r\n public pageScrollTarget: string;\r\n\r\n @Input()\r\n public pageScrollHorizontal: boolean;\r\n\r\n @Input()\r\n public pageScrollOffset: number;\r\n\r\n @Input()\r\n public pageScrollDuration: number;\r\n\r\n @Input()\r\n public pageScrollSpeed: number;\r\n\r\n @Input()\r\n public pageScrollEasing: EasingLogic;\r\n\r\n @Input()\r\n public pageScrollInterruptible: boolean;\r\n\r\n @Input()\r\n public pageScrollInView: boolean;\r\n\r\n @Input()\r\n public pageScrollAdjustHash = false;\r\n\r\n @Input()\r\n public pageScroll: string;\r\n\r\n @Output()\r\n pageScrollFinish: EventEmitter<boolean> = new EventEmitter<boolean>();\r\n\r\n private pageScrollInstance: PageScrollInstance;\r\n private readonly document: Document;\r\n\r\n constructor() {\r\n const document = inject(DOCUMENT);\r\n\r\n this.document = (document as Document);\r\n }\r\n\r\n ngOnChanges(changes: SimpleChanges): void {// eslint-disable-line @typescript-eslint/no-unused-vars\r\n // Some inputs changed, reset the pageScrollInstance\r\n this.pageScrollInstance = undefined;\r\n }\r\n\r\n ngOnDestroy(): void {\r\n if (this.pageScrollInstance) {\r\n this.pageScrollService.stop(this.pageScrollInstance);\r\n }\r\n }\r\n\r\n private getPageScrollTarget(): string {\r\n return this.pageScrollTarget || this.href || (this.fragment ? '#' + this.fragment : '');\r\n }\r\n\r\n private generatePageScrollInstance(): PageScrollInstance {\r\n if (this.pageScrollInstance === undefined || this.pageScrollInstance === null) {\r\n const options: PageScrollOptions = {\r\n document: this.document,\r\n scrollTarget: this.getPageScrollTarget(),\r\n };\r\n\r\n if (this.pageScroll) {\r\n options.namespace = this.pageScroll;\r\n }\r\n if (this.pageScrollHorizontal !== undefined && this.pageScrollHorizontal !== null) {\r\n options.verticalScrolling = !this.pageScrollHorizontal;\r\n }\r\n if (this.pageScrollOffset !== undefined && this.pageScrollOffset !== null) {\r\n options.scrollOffset = this.pageScrollOffset;\r\n }\r\n if (this.pageScrollInterruptible !== undefined && this.pageScrollInterruptible !== null) {\r\n options.interruptible = this.pageScrollInterruptible;\r\n }\r\n if (this.pageScrollInView !== undefined && this.pageScrollInView !== null) {\r\n options.scrollInView = this.pageScrollInView;\r\n }\r\n if (this.pageScrollEasing) {\r\n options.easingLogic = this.pageScrollEasing;\r\n }\r\n if (this.pageScrollDuration !== undefined && this.pageScrollDuration !== null) {\r\n options.duration = this.pageScrollDuration;\r\n }\r\n if (this.pageScrollSpeed !== undefined && this.pageScrollSpeed !== null) {\r\n options.speed = this.pageScrollSpeed;\r\n }\r\n if (this.pageScrollFinish) {\r\n options.scrollFinishListener = this.pageScrollFinish;\r\n }\r\n this.pageScrollInstance = this.pageScrollService.create(options);\r\n }\r\n\r\n return this.pageScrollInstance;\r\n }\r\n\r\n private pushRouterState(): void {\r\n if (this.pageScrollAdjustHash && typeof this.pageScrollInstance.pageScrollOptions.scrollTarget === 'string'\r\n && (this.pageScrollInstance.pageScrollOptions.scrollTarget as string).substr(0, 1) === '#') {\r\n // \"Navigate\" to the current route again and this time set the fragment/hash\r\n this.router.navigate([], {\r\n fragment: (this.pageScrollInstance.pageScrollOptions.scrollTarget as string).substr(1),\r\n queryParamsHandling: 'preserve',\r\n });\r\n }\r\n }\r\n\r\n private scroll(): void {\r\n const pageScrollInstance = this.generatePageScrollInstance();\r\n this.pushRouterState();\r\n this.pageScrollService.start(pageScrollInstance);\r\n }\r\n\r\n public handleClick(clickEvent: Event): boolean { // eslint-disable-line @typescript-eslint/no-unused-vars\r\n if (this.routerLink && this.router !== null && this.router !== undefined) {\r\n let urlTree: UrlTree;\r\n if (typeof this.routerLink === 'string') {\r\n urlTree = this.router.parseUrl(this.routerLink);\r\n } else {\r\n urlTree = this.router.createUrlTree(this.routerLink);\r\n }\r\n if (!this.router.isActive(urlTree, true)) {\r\n // We need to navigate their first.\r\n // Navigation is handled by the routerLink directive so we only need to listen for route change\r\n this.router.events.pipe(filter(routerEvent => {\r\n // We're only interested in successful navigations or when the navigation fails\r\n return routerEvent instanceof NavigationEnd || routerEvent instanceof NavigationError\r\n || routerEvent instanceof NavigationCancel;\r\n }),\r\n // Consume only one event, automatically \"unsubscribing\" from the event stream afterwards\r\n take(1)\r\n ).subscribe((routerEvent) => {\r\n if (routerEvent instanceof NavigationEnd) {\r\n // use a timeout to start scrolling as soon as the stack is cleared\r\n setTimeout(() => {\r\n this.scroll();\r\n }, 0);\r\n }\r\n });\r\n\r\n return false; // to preventDefault()\r\n }\r\n }\r\n this.scroll();\r\n\r\n return false; // to preventDefault()\r\n }\r\n}\r\n","import { NgModule } from '@angular/core';\r\n\r\nimport { NgxPageScrollCoreModule } from '@solidexpert/ngx-page-scroll-core';\r\n\r\nimport { NgxPageScrollDirective } from './ngx-page-scroll.directive';\r\n\r\n@NgModule({\r\n imports: [\r\n NgxPageScrollCoreModule,\r\n NgxPageScrollDirective,\r\n ],\r\n exports: [\r\n NgxPageScrollDirective,\r\n ],\r\n})\r\nexport class NgxPageScrollModule {\r\n}\r\n"],"mappings":";;;;;AAeA,IAAa,yBAAb,MAAa,uBAAsB;CAkDjC,cAAA;EAjDiB,KAAA,oBAAoB,OAAO,iBAAiB;EAC5C,KAA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N,SAAS,CACL,yBACA,sBACH;GACD,SAAS,CACL,sBACH;EACJ,CAAA"}
package/package.json CHANGED
@@ -1,6 +1,55 @@
1
1
  {
2
2
  "name": "@solidexpert/ngx-page-scroll",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "22.0.0",
4
+ "description": "Convenience directive for animated scrolling functionality for angular written in pure typescript",
5
+ "keywords": [
6
+ "angular",
7
+ "angularjs",
8
+ "page",
9
+ "scroll",
10
+ "pagescroll",
11
+ "animate",
12
+ "move",
13
+ "scrollto",
14
+ "anchor"
15
+ ],
16
+ "author": "Sebastian Fuss <sebastian.fuss@googlemail.com>",
17
+ "license": "MIT",
18
+ "repository": {
19
+ "type": "git",
20
+ "url": "git+https://github.com/solidexpert-ltd/ngx-page-scroll.git"
21
+ },
22
+ "bugs": {
23
+ "url": "https://github.com/solidexpert-ltd/ngx-page-scroll/issues"
24
+ },
25
+ "homepage": "https://github.com/solidexpert-ltd/ngx-page-scroll#readme",
26
+ "engines": {
27
+ "node": "^22.22.3 || ^24.15.0 || >=26"
28
+ },
29
+ "publishConfig": {
30
+ "access": "public"
31
+ },
32
+ "peerDependencies": {
33
+ "@solidexpert/ngx-page-scroll-core": "^22.0.0",
34
+ "@angular/common": "^22.0.0",
35
+ "@angular/core": "^22.0.0",
36
+ "@angular/router": "^22.0.0",
37
+ "rxjs": "^7.8.2"
38
+ },
39
+ "dependencies": {
40
+ "tslib": "^2.6.2"
41
+ },
42
+ "module": "fesm2022/solidexpert-ngx-page-scroll.mjs",
43
+ "typings": "types/solidexpert-ngx-page-scroll.d.ts",
44
+ "exports": {
45
+ "./package.json": {
46
+ "default": "./package.json"
47
+ },
48
+ ".": {
49
+ "types": "./types/solidexpert-ngx-page-scroll.d.ts",
50
+ "default": "./fesm2022/solidexpert-ngx-page-scroll.mjs"
51
+ }
52
+ },
53
+ "sideEffects": false,
54
+ "type": "module"
6
55
  }
@@ -0,0 +1,97 @@
1
+ /**
2
+ * Generated bundle index. Do not edit.
3
+ */
4
+ import * as i0 from "@angular/core";
5
+ import { EventEmitter, OnChanges, OnDestroy, SimpleChanges } from "@angular/core";
6
+ import * as i1 from "@solidexpert/ngx-page-scroll-core";
7
+ import { EasingLogic } from "@solidexpert/ngx-page-scroll-core";
8
+ export declare class NgxPageScrollDirective implements OnChanges, OnDestroy {
9
+ private readonly pageScrollService;
10
+ private readonly router;
11
+ routerLink: any;
12
+ href: string;
13
+ fragment: string;
14
+ pageScrollTarget: string;
15
+ pageScrollHorizontal: boolean;
16
+ pageScrollOffset: number;
17
+ pageScrollDuration: number;
18
+ pageScrollSpeed: number;
19
+ pageScrollEasing: EasingLogic;
20
+ pageScrollInterruptible: boolean;
21
+ pageScrollInView: boolean;
22
+ pageScrollAdjustHash: boolean;
23
+ pageScroll: string;
24
+ pageScrollFinish: EventEmitter<boolean>;
25
+ private pageScrollInstance;
26
+ private readonly document;
27
+ constructor();
28
+ ngOnChanges(changes: SimpleChanges): void;
29
+ ngOnDestroy(): void;
30
+ private getPageScrollTarget;
31
+ private generatePageScrollInstance;
32
+ private pushRouterState;
33
+ private scroll;
34
+ handleClick(clickEvent: Event): boolean;
35
+ static ɵfac: i0.ɵɵFactoryDeclaration<NgxPageScrollDirective, never>;
36
+ static ɵdir: i0.ɵɵDirectiveDeclaration<NgxPageScrollDirective, "[pageScroll]", never, {
37
+ "routerLink": {
38
+ "alias": "routerLink";
39
+ "required": false;
40
+ };
41
+ "href": {
42
+ "alias": "href";
43
+ "required": false;
44
+ };
45
+ "fragment": {
46
+ "alias": "fragment";
47
+ "required": false;
48
+ };
49
+ "pageScrollTarget": {
50
+ "alias": "pageScrollTarget";
51
+ "required": false;
52
+ };
53
+ "pageScrollHorizontal": {
54
+ "alias": "pageScrollHorizontal";
55
+ "required": false;
56
+ };
57
+ "pageScrollOffset": {
58
+ "alias": "pageScrollOffset";
59
+ "required": false;
60
+ };
61
+ "pageScrollDuration": {
62
+ "alias": "pageScrollDuration";
63
+ "required": false;
64
+ };
65
+ "pageScrollSpeed": {
66
+ "alias": "pageScrollSpeed";
67
+ "required": false;
68
+ };
69
+ "pageScrollEasing": {
70
+ "alias": "pageScrollEasing";
71
+ "required": false;
72
+ };
73
+ "pageScrollInterruptible": {
74
+ "alias": "pageScrollInterruptible";
75
+ "required": false;
76
+ };
77
+ "pageScrollInView": {
78
+ "alias": "pageScrollInView";
79
+ "required": false;
80
+ };
81
+ "pageScrollAdjustHash": {
82
+ "alias": "pageScrollAdjustHash";
83
+ "required": false;
84
+ };
85
+ "pageScroll": {
86
+ "alias": "pageScroll";
87
+ "required": false;
88
+ };
89
+ }, {
90
+ "pageScrollFinish": "pageScrollFinish";
91
+ }, never, never, true, never>;
92
+ }
93
+ export declare class NgxPageScrollModule {
94
+ static ɵfac: i0.ɵɵFactoryDeclaration<NgxPageScrollModule, never>;
95
+ static ɵmod: i0.ɵɵNgModuleDeclaration<NgxPageScrollModule, never, [typeof i1.NgxPageScrollCoreModule, typeof NgxPageScrollDirective], [typeof NgxPageScrollDirective]>;
96
+ static ɵinj: i0.ɵɵInjectorDeclaration<NgxPageScrollModule>;
97
+ }