@su-labs/visit-tracker 21.0.5 → 21.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -5,6 +5,38 @@ All notable changes to this project will be documented in this file.
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
6
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
 
8
+ ## [22.1.2] - 2026-11-16
9
+
10
+ ### Changed
11
+ - Uses `@su-labs/core` 1.9.0 (was 1.8.0), the same version as every other `@su-labs` package, so apps using several of them install core once
12
+
13
+ ## [22.1.1] - 2026-11-14
14
+
15
+ ### Changed
16
+ - Package homepage now points to the website with a live demo
17
+ - Pins `@su-labs/core` to exactly 1.8.0
18
+
19
+ ## [22.1.0] - 2026-11-05
20
+
21
+ ### Changed
22
+ - Visit tracking moved to the framework-agnostic `@su-labs/core/visit-tracker`; `SuVisitTrackerService` is now a thin wrapper with the same API
23
+ - `SuVisitTrackerConfig` and `SuVisitData` are now re-exported from `@su-labs/core/visit-tracker`
24
+ - Added `@su-labs/core` as a dependency
25
+ - README links to the `@su-labs/core` installation guides for non-Angular projects
26
+
27
+ ### Fixed
28
+ - Corrupted or invalid saved data no longer throws; counting starts over
29
+ - `init()` no longer sorts the `milestoneVisits` array passed in the config
30
+ - Safe to call during server-side rendering (no `localStorage` access without a browser)
31
+ - README now documents the actual API (`milestone()` signal, `init()` required)
32
+ - Repair table of contents links in README.md
33
+
34
+ ## [22.0.0] - 2026-11-04
35
+
36
+ ### Changed
37
+ - Upgrade to Angular 22 (peer dependencies now `^22.0.0`)
38
+ - Remove emojis from README.md
39
+
8
40
  ## [21.0.5] - 2026-02-04
9
41
 
10
42
  ### Changed
package/README.md CHANGED
@@ -3,7 +3,7 @@
3
3
  `@su-labs/visit-tracker`
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,36 +13,38 @@
13
13
 
14
14
  A lightweight Angular service to track user visits. Provides reactive signals for visit count, last visit date, and milestone visits.
15
15
 
16
- ## 📚 Table of Contents
16
+ > **Not using Angular?** The same visit tracker 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
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
  - [Configuration Options](#configuration-options)
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** - Only ~5KB minified
35
- - ⚡ **Reactive** - Built with Angular Signals
36
- - 🔒 **Type-Safe** - Full TypeScript support
37
- - 📦 **Zero Dependencies** - No bloat
38
- - 🧪 **Well Tested** - Comprehensive test coverage
39
- - 📝 **Well Documented** - Clear examples and API docs
36
+ - **Lightweight** - Minimal bundle size
37
+ - **Reactive** - Built with Angular Signals
38
+ - **Type-Safe** - Full TypeScript support
39
+ - **SSR Safe** - No browser APIs are touched on the server
40
+ - **Well Tested** - Comprehensive test coverage
41
+ - **Well Documented** - Clear examples and API docs
40
42
 
41
43
  ## Features
42
44
 
43
45
  * Tracks number of visits per user.
44
46
  * Persists visit data in `localStorage`.
45
- * Signals for milestones (e.g., 10th, 100th visit).
47
+ * Milestone signal (e.g., 10th, 100th visit).
46
48
  * Reactive last visit date signal.
47
49
  * Configurable storage key and milestones.
48
50
  * Works seamlessly with standalone components and reactive Angular setups.
@@ -52,9 +54,11 @@ A lightweight Angular service to track user visits. Provides reactive signals fo
52
54
  You can install this library via npm:
53
55
 
54
56
  ```sh
55
- npm install @su-labs/visit-tracker
57
+ npm install @su-labs/visit-tracker@ng21
56
58
  ```
57
59
 
60
+ This is the Angular 21 version. For the newest Angular, install `@su-labs/visit-tracker` without a tag.
61
+
58
62
  ## Peer Dependencies
59
63
 
60
64
  This library requires the following peer dependencies:
@@ -63,45 +67,57 @@ This library requires the following peer dependencies:
63
67
  npm install @angular/common@^21 @angular/core@^21
64
68
  ```
65
69
 
66
- ## 🚀 Quick Start
70
+ ## Quick Start
71
+
72
+ 1. Record the visit once at startup in `app.config.ts`:
67
73
 
68
74
  ```typescript
69
- // 1. Install
70
- npm install @su-labs/visit-tracker
75
+ import { ApplicationConfig, inject, provideAppInitializer } from '@angular/core';
76
+ import { SuVisitTrackerService } from '@su-labs/visit-tracker';
71
77
 
72
- // 2. Inject in your component
78
+ export const appConfig: ApplicationConfig = {
79
+ providers: [
80
+ provideAppInitializer(() => {
81
+ inject(SuVisitTrackerService).init();
82
+ }),
83
+ ],
84
+ };
85
+ ```
86
+
87
+ 2. Read the signals in any component:
88
+
89
+ ```typescript
73
90
  import { Component, inject } from '@angular/core';
74
91
  import { SuVisitTrackerService } from '@su-labs/visit-tracker';
75
92
 
76
93
  @Component({
77
94
  selector: 'app-root',
78
- template: `<p>Visits: {{ visitService.count() }}</p>`
95
+ template: `<p>Visits: {{ visitService.count() }}</p>`,
79
96
  })
80
97
  export class AppComponent {
81
- visitService = inject(SuVisitTrackerService);
98
+ protected readonly visitService = inject(SuVisitTrackerService);
82
99
  }
83
100
  ```
84
101
 
85
102
  ## Usage
86
103
 
87
- ### Example 1: Basic initialization
88
- The service should be provided at the root level. To use it in a component, simply inject it:
104
+ ### Example 1: Welcome back message
105
+ After `init()` has run (see [Quick Start](#quick-start)), inject the service wherever you need it:
89
106
 
90
107
  ```TypeScript
91
108
  import { Component, inject } from '@angular/core';
92
- import { CommonModule, DatePipe } from '@angular/common';
109
+ import { DatePipe } from '@angular/common';
93
110
  import { SuVisitTrackerService } from '@su-labs/visit-tracker';
94
111
 
95
112
  @Component({
96
113
  selector: 'app-root',
97
- standalone: true,
98
- imports: [CommonModule, DatePipe],
114
+ imports: [DatePipe],
99
115
  template: `
100
116
  <h1>Welcome back!</h1>
101
117
  <p>You have visited {{ visitService.count() }} times.</p>
102
- <ng-container *ngIf="visitService.lastVisit() as last">
103
- <p>Last visit: {{ last | date:'medium' }}</p>
104
- </ng-container>
118
+ @if (visitService.lastVisit(); as last) {
119
+ <p>Last visit: {{ last | date: 'medium' }}</p>
120
+ }
105
121
  `,
106
122
  })
107
123
  export class AppComponent {
@@ -109,22 +125,23 @@ export class AppComponent {
109
125
  }
110
126
  ```
111
127
 
112
- ✅ Automatically increments the visit count and updates the last visit timestamp.
128
+ Each `init()` call increments the visit count and saves the start of this visit for next time.
113
129
 
114
130
  ### Example 2: Checking milestone visits
115
- You can reactively check if a milestone visit has been reached:
131
+ `milestone()` holds the milestone reached on this visit, or `null`:
116
132
 
117
133
  ```HTML
118
- @if(visitService.isTenthVisit()){
119
- <p>🎉 Congratulations on your 10th visit!</p>
120
- }
121
-
122
- @if(visitService.isHundredthVisit()){
123
- <p>🏆 100 visits! You're a power user!</p>
134
+ @switch (visitService.milestone()) {
135
+ @case (10) {
136
+ <p>Congratulations on your 10th visit!</p>
137
+ }
138
+ @case (100) {
139
+ <p>100 visits! You're a power user!</p>
140
+ }
124
141
  }
125
142
  ```
126
143
 
127
- Signals `isTenthVisit` and `isHundredthVisit` update automatically on service initialization.
144
+ The signal is set when `init()` runs.
128
145
 
129
146
  ### Example 3: Custom configuration
130
147
  For standalone apps, use provideAppInitializer to initialize the tracker with a custom storage key or milestones:
@@ -148,12 +165,12 @@ export const appConfig = {
148
165
  };
149
166
  ```
150
167
 
151
- ✅ Allows overriding the localStorage key and defining custom milestone visits.
168
+ Allows overriding the localStorage key and defining custom milestone visits.
152
169
 
153
170
  ### Example 4: Using last visit date
154
171
 
155
172
  ```HTML
156
- @if(visitService.lastVisit() as last) {
173
+ @if (visitService.lastVisit(); as last) {
157
174
  <p>
158
175
  Your last visit was on {{ last | date:'fullDate' }} at {{ last | date:'shortTime' }}
159
176
  </p>
@@ -162,22 +179,21 @@ export const appConfig = {
162
179
 
163
180
  The service stores last visit as an ISO string (e.g., "2025-08-25T12:34:56.789Z"), so it can easily be used in Angular date pipes.
164
181
 
165
- ## 📖 API Reference
182
+ ## API Reference
166
183
 
167
184
  ### Signals
168
185
 
169
186
  | Signal | Type | Description |
170
187
  |--------|------|-------------|
171
- | `count()` | `number` | Current visit count |
172
- | `lastVisit()` | `string \| null` | ISO string of last visit date |
173
- | `isTenthVisit()` | `boolean` | True if current count is 10 |
174
- | `isHundredthVisit()` | `boolean` | True if current count is 100 |
188
+ | `count()` | `number` | Visit count including this visit (`0` before `init()`) |
189
+ | `lastVisit()` | `string \| null` | Start of the previous visit as an ISO string, or `null` on the first visit |
190
+ | `milestone()` | `number \| null` | Milestone reached on this visit, or `null` |
175
191
 
176
192
  ### Methods
177
193
 
178
194
  | Method | Parameters | Description |
179
195
  |--------|------------|-------------|
180
- | `init(config?)` | `SuVisitTrackerConfig` | Initialize with custom configuration |
196
+ | `init(config?)` | `SuVisitTrackerConfig` | Record the current visit. Call once at startup. |
181
197
 
182
198
  ### Types
183
199
 
@@ -197,12 +213,12 @@ The service can be configured to fit your application's needs. You can customize
197
213
  | `storageKey` | The key used to persist the visit data in `localStorage`. | `'su:visits'` |
198
214
  | `milestoneVisits` | An array of numbers representing visits to track as milestones. | `[10, 100]` |
199
215
 
200
- ## 🌐 Browser Compatibility
216
+ ## Browser Compatibility
201
217
 
202
218
  Works in all modern browsers that support:
203
- - ✅ localStorage API
204
- - ✅ Angular 21+
205
- - ✅ ES2022+
219
+ - localStorage API
220
+ - Angular 21
221
+ - ES2022+
206
222
 
207
223
  | Browser | Version |
208
224
  |---------|---------|
@@ -211,40 +227,44 @@ Works in all modern browsers that support:
211
227
  | Safari | ≥ 14 |
212
228
  | Edge | ≥ 90 |
213
229
 
214
- ## 🔗 Related Libraries
230
+ ## Related Libraries
215
231
 
216
232
  Part of the **@su-labs** suite:
217
233
 
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/scroll-spy](https://www.npmjs.com/package/@su-labs/scroll-spy) - Scroll position tracking
221
- - 📏 [@su-labs/font-size](https://www.npmjs.com/package/@su-labs/font-size) - Accessible font size controls
234
+ - [@su-labs/theme](https://www.npmjs.com/package/@su-labs/theme) - Theme management with dark mode support
235
+ - [@su-labs/notifications](https://www.npmjs.com/package/@su-labs/notifications) - Toast notification system
236
+ - [@su-labs/scroll-spy](https://www.npmjs.com/package/@su-labs/scroll-spy) - Scroll position tracking
237
+ - [@su-labs/font-size](https://www.npmjs.com/package/@su-labs/font-size) - Accessible font size controls
222
238
 
223
- ## 🔧 Troubleshooting
239
+ ## Troubleshooting
224
240
 
225
241
  ### Visit count not persisting?
226
242
 
227
243
  Make sure localStorage is enabled in your browser and not blocked by privacy settings.
228
244
 
229
- ### Milestone signals not updating?
245
+ ### Count stays at 0?
246
+
247
+ The visit is only recorded when `init()` runs. Call it once at startup, as shown in [Quick Start](#quick-start).
248
+
249
+ ### Milestone signal not updating?
230
250
 
231
- Milestones are only checked during service initialization. Call `init()` to recalculate.
251
+ Milestones are only checked when `init()` runs, once per visit.
232
252
 
233
253
  ### TypeScript errors?
234
254
 
235
- Ensure you have Angular 21+ and TypeScript 5.7+ installed.
255
+ Ensure you have Angular 21 and TypeScript 5.9+ installed.
236
256
 
237
- ## 💬 Support
257
+ ## Support
238
258
 
239
- - 🐛 Found a bug? [Open an issue](https://github.com/Greezaaa/settings-utils-lib/issues)
240
- - 💡 Have a feature request? [Start a discussion](https://github.com/Greezaaa/settings-utils-lib/discussions)
241
- - ⭐ Like this library? [Give it a star!](https://github.com/Greezaaa/settings-utils-lib)
259
+ - Found a bug? [Open an issue](https://github.com/Greezaaa/settings-utils-lib/issues)
260
+ - Have a feature request? [Start a discussion](https://github.com/Greezaaa/settings-utils-lib/discussions)
261
+ - Like this library? [Give it a star!](https://github.com/Greezaaa/settings-utils-lib)
242
262
 
243
263
  ## Notes
244
264
 
245
265
  - **Signals-based API**: Perfect for standalone components and reactive Angular templates.
246
266
  - **Persistence**: Visit count and last visit are automatically stored in localStorage.
247
- - **Lightweight**: No external dependencies and minimal memory footprint.
267
+ - **Lightweight**: Minimal memory footprint.
248
268
  - **Custom milestones**: Track any number of user visit milestones reactively.
249
269
 
250
270
  ## Contributing
@@ -1,52 +1,48 @@
1
1
  import * as i0 from '@angular/core';
2
2
  import { signal, Injectable } from '@angular/core';
3
+ import { SuVisitTrackerController } from '@su-labs/core/visit-tracker';
3
4
 
5
+ /**
6
+ * Angular service for tracking user visits.
7
+ *
8
+ * Thin wrapper around the framework-agnostic `SuVisitTrackerController` from
9
+ * `@su-labs/core/visit-tracker` that exposes the visit data as Angular signals.
10
+ */
4
11
  class SuVisitTrackerService {
5
- /** Key used for localStorage */
6
- storageKey = 'su:visits';
7
- /** Milestones to track */
8
- _milestones = [10, 100];
9
- /** Current visit count */
10
- count = signal(0, ...(ngDevMode ? [{ debugName: "count" }] : []));
11
- /** Last visit date as ISO string */
12
- lastVisit = signal(null, ...(ngDevMode ? [{ debugName: "lastVisit" }] : []));
12
+ /** Framework-agnostic visit tracking logic */
13
+ controller = new SuVisitTrackerController();
14
+ /** Current visit count (0 until {@link init} runs) */
15
+ count = signal(0, ...(ngDevMode ? [{ debugName: "count" }] : /* istanbul ignore next */ []));
16
+ /** Start of the previous visit as an ISO string, or null on the first visit */
17
+ lastVisit = signal(null, ...(ngDevMode ? [{ debugName: "lastVisit" }] : /* istanbul ignore next */ []));
13
18
  /** The number of the milestone reached on the current visit, or null */
14
- milestone = signal(null, ...(ngDevMode ? [{ debugName: "milestone" }] : []));
15
- /** Initialize the service and update signals */
19
+ milestone = signal(null, ...(ngDevMode ? [{ debugName: "milestone" }] : /* istanbul ignore next */ []));
20
+ /** Stops syncing the controller's state into the signals */
21
+ unsubscribe = this.controller.visit.subscribe((visit) => {
22
+ this.count.set(visit.count);
23
+ this.lastVisit.set(visit.lastVisit);
24
+ this.milestone.set(visit.milestone);
25
+ });
26
+ /**
27
+ * Record the current visit and update the signals.
28
+ * Call once at application startup.
29
+ * @param config Optional storage key and milestones.
30
+ */
16
31
  init(config) {
17
- if (config?.storageKey) {
18
- this.storageKey = config.storageKey;
19
- }
20
- if (config?.milestoneVisits && Array.isArray(config.milestoneVisits)) {
21
- this._milestones = config.milestoneVisits.sort((a, b) => a - b);
22
- }
23
- const storedData = localStorage.getItem(this.storageKey);
24
- const stored = storedData ? JSON.parse(storedData) : {};
25
- const prevCount = stored.count ?? 0;
26
- const prevDate = stored.lastVisit ?? null;
27
- const newCount = prevCount + 1;
28
- this.count.set(newCount);
29
- this.lastVisit.set(prevDate);
30
- this.updateMilestone(newCount);
31
- localStorage.setItem(this.storageKey, JSON.stringify({ count: newCount, lastVisit: new Date().toISOString() }));
32
+ this.controller.init(config);
32
33
  }
33
- /** Update the milestone signal based on the current count */
34
- updateMilestone(count) {
35
- const reachedMilestone = this._milestones.find(m => m === count);
36
- this.milestone.set(reachedMilestone ?? null);
34
+ /** Angular lifecycle hook for service destruction */
35
+ ngOnDestroy() {
36
+ this.unsubscribe();
37
37
  }
38
- static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.1.2", ngImport: i0, type: SuVisitTrackerService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
39
- static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "21.1.2", ngImport: i0, type: SuVisitTrackerService, providedIn: 'root' });
38
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.26", ngImport: i0, type: SuVisitTrackerService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
39
+ static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "21.2.26", ngImport: i0, type: SuVisitTrackerService, providedIn: 'root' });
40
40
  }
41
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.1.2", ngImport: i0, type: SuVisitTrackerService, decorators: [{
41
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.26", ngImport: i0, type: SuVisitTrackerService, decorators: [{
42
42
  type: Injectable,
43
43
  args: [{ providedIn: 'root' }]
44
44
  }] });
45
45
 
46
- /*
47
- * Public API Surface of visit-tracker
48
- */
49
-
50
46
  /**
51
47
  * Generated bundle index. Do not edit.
52
48
  */
@@ -1 +1 @@
1
- {"version":3,"file":"su-labs-visit-tracker.mjs","sources":["../../../../projects/su-labs/visit-tracker/src/lib/visit-tracker.service.ts","../../../../projects/su-labs/visit-tracker/src/public-api.ts","../../../../projects/su-labs/visit-tracker/src/su-labs-visit-tracker.ts"],"sourcesContent":["import { Injectable, signal, WritableSignal } from '@angular/core';\nimport { SuVisitData, SuVisitTrackerConfig } from './visit-tracker.types';\n\n@Injectable({ providedIn: 'root' })\nexport class SuVisitTrackerService {\n /** Key used for localStorage */\n private storageKey = 'su:visits';\n\n /** Milestones to track */\n private _milestones: number[] = [10, 100];\n\n /** Current visit count */\n public count: WritableSignal<number> = signal(0);\n\n /** Last visit date as ISO string */\n public lastVisit: WritableSignal<string | null> = signal(null);\n\n /** The number of the milestone reached on the current visit, or null */\n public milestone: WritableSignal<number | null> = signal(null);\n\n /** Initialize the service and update signals */\n public init(config?: SuVisitTrackerConfig): void {\n if (config?.storageKey) {\n this.storageKey = config.storageKey;\n }\n if (config?.milestoneVisits && Array.isArray(config.milestoneVisits)) {\n this._milestones = config.milestoneVisits.sort((a, b) => a - b);\n }\n\n const storedData = localStorage.getItem(this.storageKey);\n const stored: Partial<SuVisitData> = storedData ? JSON.parse(storedData) : {};\n\n const prevCount = stored.count ?? 0;\n const prevDate = stored.lastVisit ?? null;\n const newCount = prevCount + 1;\n\n this.count.set(newCount);\n this.lastVisit.set(prevDate);\n\n this.updateMilestone(newCount);\n\n localStorage.setItem(\n this.storageKey,\n JSON.stringify({ count: newCount, lastVisit: new Date().toISOString() }),\n );\n }\n\n /** Update the milestone signal based on the current count */\n private updateMilestone(count: number): void {\n const reachedMilestone = this._milestones.find(m => m === count);\n this.milestone.set(reachedMilestone ?? null);\n }\n}\n","/*\n * Public API Surface of visit-tracker\n */\n\nexport * from './lib/visit-tracker.types';\nexport * from './lib/visit-tracker.service';\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public-api';\n"],"names":[],"mappings":";;;MAIa,qBAAqB,CAAA;;IAExB,UAAU,GAAG,WAAW;;AAGxB,IAAA,WAAW,GAAa,CAAC,EAAE,EAAE,GAAG,CAAC;;AAGlC,IAAA,KAAK,GAA2B,MAAM,CAAC,CAAC,iDAAC;;AAGzC,IAAA,SAAS,GAAkC,MAAM,CAAC,IAAI,qDAAC;;AAGvD,IAAA,SAAS,GAAkC,MAAM,CAAC,IAAI,qDAAC;;AAGvD,IAAA,IAAI,CAAC,MAA6B,EAAA;AACvC,QAAA,IAAI,MAAM,EAAE,UAAU,EAAE;AACtB,YAAA,IAAI,CAAC,UAAU,GAAG,MAAM,CAAC,UAAU;QACrC;AACA,QAAA,IAAI,MAAM,EAAE,eAAe,IAAI,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,eAAe,CAAC,EAAE;YACpE,IAAI,CAAC,WAAW,GAAG,MAAM,CAAC,eAAe,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;QACjE;QAEA,MAAM,UAAU,GAAG,YAAY,CAAC,OAAO,CAAC,IAAI,CAAC,UAAU,CAAC;AACxD,QAAA,MAAM,MAAM,GAAyB,UAAU,GAAG,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,GAAG,EAAE;AAE7E,QAAA,MAAM,SAAS,GAAG,MAAM,CAAC,KAAK,IAAI,CAAC;AACnC,QAAA,MAAM,QAAQ,GAAG,MAAM,CAAC,SAAS,IAAI,IAAI;AACzC,QAAA,MAAM,QAAQ,GAAG,SAAS,GAAG,CAAC;AAE9B,QAAA,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,QAAQ,CAAC;AACxB,QAAA,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,QAAQ,CAAC;AAE5B,QAAA,IAAI,CAAC,eAAe,CAAC,QAAQ,CAAC;QAE9B,YAAY,CAAC,OAAO,CAClB,IAAI,CAAC,UAAU,EACf,IAAI,CAAC,SAAS,CAAC,EAAE,KAAK,EAAE,QAAQ,EAAE,SAAS,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE,EAAE,CAAC,CACzE;IACH;;AAGQ,IAAA,eAAe,CAAC,KAAa,EAAA;AACnC,QAAA,MAAM,gBAAgB,GAAG,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,KAAK,KAAK,CAAC;QAChE,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,gBAAgB,IAAI,IAAI,CAAC;IAC9C;uGA/CW,qBAAqB,EAAA,IAAA,EAAA,EAAA,EAAA,MAAA,EAAA,EAAA,CAAA,eAAA,CAAA,UAAA,EAAA,CAAA;AAArB,IAAA,OAAA,KAAA,GAAA,EAAA,CAAA,qBAAA,CAAA,EAAA,UAAA,EAAA,QAAA,EAAA,OAAA,EAAA,QAAA,EAAA,QAAA,EAAA,EAAA,EAAA,IAAA,EAAA,qBAAqB,cADR,MAAM,EAAA,CAAA;;2FACnB,qBAAqB,EAAA,UAAA,EAAA,CAAA;kBADjC,UAAU;mBAAC,EAAE,UAAU,EAAE,MAAM,EAAE;;;ACHlC;;AAEG;;ACFH;;AAEG;;;;"}
1
+ {"version":3,"file":"su-labs-visit-tracker.mjs","sources":["../../../../compat/angular-21/build/visit-tracker/src/lib/visit-tracker.service.ts","../../../../compat/angular-21/build/visit-tracker/src/su-labs-visit-tracker.ts"],"sourcesContent":["import { Injectable, OnDestroy, signal, WritableSignal } from '@angular/core';\nimport { SuVisitTrackerConfig, SuVisitTrackerController } from '@su-labs/core/visit-tracker';\n\n/**\n * Angular service for tracking user visits.\n *\n * Thin wrapper around the framework-agnostic `SuVisitTrackerController` from\n * `@su-labs/core/visit-tracker` that exposes the visit data as Angular signals.\n */\n@Injectable({ providedIn: 'root' })\nexport class SuVisitTrackerService implements OnDestroy {\n /** Framework-agnostic visit tracking logic */\n private readonly controller = new SuVisitTrackerController();\n\n /** Current visit count (0 until {@link init} runs) */\n public count: WritableSignal<number> = signal(0);\n\n /** Start of the previous visit as an ISO string, or null on the first visit */\n public lastVisit: WritableSignal<string | null> = signal(null);\n\n /** The number of the milestone reached on the current visit, or null */\n public milestone: WritableSignal<number | null> = signal(null);\n\n /** Stops syncing the controller's state into the signals */\n private readonly unsubscribe = this.controller.visit.subscribe((visit) => {\n this.count.set(visit.count);\n this.lastVisit.set(visit.lastVisit);\n this.milestone.set(visit.milestone);\n });\n\n /**\n * Record the current visit and update the signals.\n * Call once at application startup.\n * @param config Optional storage key and milestones.\n */\n public init(config?: SuVisitTrackerConfig): void {\n this.controller.init(config);\n }\n\n /** Angular lifecycle hook for service destruction */\n ngOnDestroy(): void {\n this.unsubscribe();\n }\n}\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public-api';\n"],"names":[],"mappings":";;;;AAGA;;;;;AAKG;MAEU,qBAAqB,CAAA;;AAEf,IAAA,UAAU,GAAG,IAAI,wBAAwB,EAAE;;AAGrD,IAAA,KAAK,GAA2B,MAAM,CAAC,CAAC,4EAAC;;AAGzC,IAAA,SAAS,GAAkC,MAAM,CAAC,IAAI,gFAAC;;AAGvD,IAAA,SAAS,GAAkC,MAAM,CAAC,IAAI,gFAAC;;AAG7C,IAAA,WAAW,GAAG,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC,KAAK,KAAI;QACvE,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,KAAK,CAAC,KAAK,CAAC;QAC3B,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,KAAK,CAAC,SAAS,CAAC;QACnC,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,KAAK,CAAC,SAAS,CAAC;AACrC,IAAA,CAAC,CAAC;AAEF;;;;AAIG;AACI,IAAA,IAAI,CAAC,MAA6B,EAAA;AACvC,QAAA,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,MAAM,CAAC;IAC9B;;IAGA,WAAW,GAAA;QACT,IAAI,CAAC,WAAW,EAAE;IACpB;wGAhCW,qBAAqB,EAAA,IAAA,EAAA,EAAA,EAAA,MAAA,EAAA,EAAA,CAAA,eAAA,CAAA,UAAA,EAAA,CAAA;AAArB,IAAA,OAAA,KAAA,GAAA,EAAA,CAAA,qBAAA,CAAA,EAAA,UAAA,EAAA,QAAA,EAAA,OAAA,EAAA,SAAA,EAAA,QAAA,EAAA,EAAA,EAAA,IAAA,EAAA,qBAAqB,cADR,MAAM,EAAA,CAAA;;4FACnB,qBAAqB,EAAA,UAAA,EAAA,CAAA;kBADjC,UAAU;mBAAC,EAAE,UAAU,EAAE,MAAM,EAAE;;;ACTlC;;AAEG;;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@su-labs/visit-tracker",
3
- "version": "21.0.5",
3
+ "version": "21.1.2",
4
4
  "keywords": [
5
5
  "angular",
6
6
  "user-tracking",
@@ -18,9 +18,10 @@
18
18
  "@angular/core": "^21.0.0"
19
19
  },
20
20
  "dependencies": {
21
+ "@su-labs/core": "1.9.0",
21
22
  "tslib": "^2.3.0"
22
23
  },
23
- "homepage": "https://github.com/Greezaaa/settings-utils-lib/tree/main/projects/su-labs/font-size#readme",
24
+ "homepage": "https://su-labs.dev/visit-tracker/",
24
25
  "author": {
25
26
  "name": "Yevheniy Alekseyev",
26
27
  "email": "yev.alekseyev@gmail.com",
@@ -29,7 +30,7 @@
29
30
  "repository": {
30
31
  "type": "git",
31
32
  "url": "https://github.com/Greezaaa/settings-utils-lib.git",
32
- "directory": "projects/su-labs/font-size"
33
+ "directory": "projects/su-labs/visit-tracker"
33
34
  },
34
35
  "bugs": {
35
36
  "url": "https://github.com/Greezaaa/settings-utils-lib/issues"
@@ -46,5 +47,6 @@
46
47
  "types": "./types/su-labs-visit-tracker.d.ts",
47
48
  "default": "./fesm2022/su-labs-visit-tracker.mjs"
48
49
  }
49
- }
50
+ },
51
+ "type": "module"
50
52
  }
@@ -1,41 +1,35 @@
1
+ import { SuVisitTrackerConfig } from '@su-labs/core/visit-tracker';
2
+ export { SuVisitData, SuVisitTrackerConfig } from '@su-labs/core/visit-tracker';
1
3
  import * as i0 from '@angular/core';
2
- import { WritableSignal } from '@angular/core';
4
+ import { OnDestroy, WritableSignal } from '@angular/core';
3
5
 
4
6
  /**
5
- * Configuration options for SuVisitTrackerService
7
+ * Angular service for tracking user visits.
8
+ *
9
+ * Thin wrapper around the framework-agnostic `SuVisitTrackerController` from
10
+ * `@su-labs/core/visit-tracker` that exposes the visit data as Angular signals.
6
11
  */
7
- interface SuVisitTrackerConfig {
8
- /** Key used for storing visit data in localStorage (default: 'su:visits') */
9
- storageKey?: string;
10
- /** Milestones to track, e.g., 10th visit, 100th visit */
11
- milestoneVisits?: number[];
12
- }
13
- /**
14
- * Shape of the data stored in localStorage
15
- */
16
- interface SuVisitData {
17
- count: number;
18
- lastVisit: string;
19
- }
20
-
21
- declare class SuVisitTrackerService {
22
- /** Key used for localStorage */
23
- private storageKey;
24
- /** Milestones to track */
25
- private _milestones;
26
- /** Current visit count */
12
+ declare class SuVisitTrackerService implements OnDestroy {
13
+ /** Framework-agnostic visit tracking logic */
14
+ private readonly controller;
15
+ /** Current visit count (0 until {@link init} runs) */
27
16
  count: WritableSignal<number>;
28
- /** Last visit date as ISO string */
17
+ /** Start of the previous visit as an ISO string, or null on the first visit */
29
18
  lastVisit: WritableSignal<string | null>;
30
19
  /** The number of the milestone reached on the current visit, or null */
31
20
  milestone: WritableSignal<number | null>;
32
- /** Initialize the service and update signals */
21
+ /** Stops syncing the controller's state into the signals */
22
+ private readonly unsubscribe;
23
+ /**
24
+ * Record the current visit and update the signals.
25
+ * Call once at application startup.
26
+ * @param config Optional storage key and milestones.
27
+ */
33
28
  init(config?: SuVisitTrackerConfig): void;
34
- /** Update the milestone signal based on the current count */
35
- private updateMilestone;
29
+ /** Angular lifecycle hook for service destruction */
30
+ ngOnDestroy(): void;
36
31
  static ɵfac: i0.ɵɵFactoryDeclaration<SuVisitTrackerService, never>;
37
32
  static ɵprov: i0.ɵɵInjectableDeclaration<SuVisitTrackerService>;
38
33
  }
39
34
 
40
35
  export { SuVisitTrackerService };
41
- export type { SuVisitData, SuVisitTrackerConfig };