@su-labs/font-size 21.0.5 → 21.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -5,6 +5,42 @@ 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
+ ## [Unreleased]
9
+
10
+ ## [22.2.1] - 2026-11-16
11
+
12
+ ### Changed
13
+ - Uses `@su-labs/core` 1.9.0 (was ^1.1.0), the same version as every other `@su-labs` package, so apps using several of them install core once
14
+
15
+ ## [22.2.0] - 2026-11-07
16
+
17
+ ### Added
18
+ - `storage` option: where the size is saved (default: `localStorage`); pass `createSuCookieStorage({ domain })` from `@su-labs/core` to share it across subdomains
19
+
20
+ ### Changed
21
+ - Requires `@su-labs/core` 1.1.0 or later
22
+ - Package homepage now points to the website with a live demo
23
+
24
+ ## [22.1.0] - 2026-11-05
25
+
26
+ ### Changed
27
+ - Font size logic moved to the framework-agnostic `@su-labs/core/font-size`; `FontSizeService` is now a thin wrapper with the same API
28
+ - `FontSizeConfig` is now a type alias built from the core types (same fields)
29
+ - Change limits and step with `configure()`. Writing to the `minSize`, `maxSize`, `defaultSize` or `step` signals directly no longer affects clamping or `reset()`
30
+ - Added `@su-labs/core` as a dependency
31
+ - README links to the `@su-labs/core` installation guides for non-Angular projects
32
+
33
+ ### Fixed
34
+ - Safe to import during server-side rendering (no `localStorage` access without a browser)
35
+ - README now documents the actual API
36
+ - Repair table of contents links in README.md
37
+
38
+ ## [22.0.0] - 2026-11-04
39
+
40
+ ### Changed
41
+ - Upgrade to Angular 22 (peer dependencies now `^22.0.0`)
42
+ - Remove emojis from README.md
43
+
8
44
  ## [21.0.5] - 2026-02-04
9
45
 
10
46
  ### Changed
package/README.md CHANGED
@@ -3,7 +3,7 @@
3
3
  `@su-labs/font-size`
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,52 +13,54 @@
13
13
 
14
14
  An accessible Angular service for managing font size preferences. Provides reactive controls for text scaling, user preference persistence, and WCAG-compliant font size management.
15
15
 
16
- ## 📚 Table of Contents
16
+ > **Not using Angular?** The same font size controls are 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
27
  - [Accessibility](#accessibility)
26
- - [Browser Compatibility](#-browser-compatibility)
27
- - [Related Libraries](#-related-libraries)
28
- - [Troubleshooting](#-troubleshooting)
29
- - [Support](#-support)
28
+ - [Browser Compatibility](#browser-compatibility)
29
+ - [Related Libraries](#related-libraries)
30
+ - [Troubleshooting](#troubleshooting)
31
+ - [Support](#support)
30
32
  - [Contributing](#contributing)
31
33
  - [License](#license)
32
34
 
33
- ## 💡 Why Use This Library?
35
+ ## Why Use This Library?
34
36
 
35
- - 🎯 **Lightweight** - Minimal bundle size
36
- - ⚡ **Reactive** - Built with Angular Signals
37
- - ♿ **Accessible** - WCAG 2.1 AA compliant
38
- - 💾 **Persistent** - Remembers user preference
39
- - 🎨 **CSS Variables** - Modern implementation
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
37
+ - **Lightweight** - Minimal bundle size
38
+ - **Reactive** - Built with Angular Signals
39
+ - **Accessible** - Helps meet WCAG 2.1 text resizing guidelines
40
+ - **Persistent** - Remembers user preference
41
+ - **CSS Variables** - Modern implementation
42
+ - **SSR Safe** - No browser APIs are touched on the server
43
+ - **Type-Safe** - Full TypeScript support
44
+ - **Well Tested** - Comprehensive test coverage
44
45
 
45
46
  ## Features
46
47
 
47
- * **Reactive State**: Uses Angular signals for efficient, reactive font size management.
48
- * **Persistence**: Remembers the user's font size preference using `localStorage`.
49
- * **Multiple Presets**: Support for small, normal, large, and extra-large font sizes.
50
- * **CSS Variables**: Applies font sizes using CSS custom properties for maximum flexibility.
51
- * **Accessibility**: Helps users with visual impairments customize text size for better readability.
52
- * **Configurable**: Customizable storage keys, CSS variable names, and size scales.
48
+ * **Reactive State**: The size, limits and `isDefault` / `isMin` / `isMax` flags are Angular signals.
49
+ * **Bounded**: The size always stays between the configured minimum and maximum.
50
+ * **Persistence**: Remembers the user's font size in `localStorage`.
51
+ * **CSS Variable**: Applies the size in pixels to a CSS custom property on `<html>`.
52
+ * **Configurable**: Customizable limits, step, storage key and CSS variable name.
53
53
 
54
54
  ## Installation
55
55
 
56
56
  You can install this library via npm:
57
57
 
58
58
  ```sh
59
- npm install @su-labs/font-size
59
+ npm install @su-labs/font-size@ng21
60
60
  ```
61
61
 
62
+ This is the Angular 21 version. For the newest Angular, install `@su-labs/font-size` without a tag.
63
+
62
64
  ## Peer Dependencies
63
65
 
64
66
  This library requires the following peer dependencies:
@@ -67,199 +69,162 @@ This library requires the following peer dependencies:
67
69
  npm install @angular/common@^21 @angular/core@^21
68
70
  ```
69
71
 
70
- ## 🚀 Quick Start
72
+ ## Quick Start
71
73
 
72
- ```typescript
73
- // 1. Install
74
- npm install @su-labs/font-size
74
+ 1. Initialize the service in `app.config.ts`:
75
75
 
76
- // 2. Initialize in app.config.ts
77
- import { provideAppInitializer, inject } from '@angular/core';
78
- import { SuFontSizeService } from '@su-labs/font-size';
76
+ ```typescript
77
+ import { ApplicationConfig, inject, provideAppInitializer } from '@angular/core';
78
+ import { FontSizeService } from '@su-labs/font-size';
79
79
 
80
- export const appConfig = {
80
+ export const appConfig: ApplicationConfig = {
81
81
  providers: [
82
82
  provideAppInitializer(() => {
83
- inject(SuFontSizeService).init();
83
+ inject(FontSizeService).init();
84
84
  }),
85
85
  ],
86
86
  };
87
-
88
- // 3. Create font size controls
89
- import { Component, inject } from '@angular/core';
90
- import { SuFontSizeService } from '@su-labs/font-size';
91
-
92
- @Component({
93
- template: `
94
- <button (click)="fontService.setSize('small')">A-</button>
95
- <button (click)="fontService.setSize('normal')">A</button>
96
- <button (click)="fontService.setSize('large')">A+</button>
97
- <p>Current: {{ fontService.size() }}</p>
98
- `
99
- })
100
- export class AppComponent {
101
- fontService = inject(SuFontSizeService);
102
- }
103
-
104
- // 4. Use CSS variables in your styles
105
- body {
106
- font-size: var(--su-font-size-base);
107
- }
108
87
  ```
109
88
 
110
- ## Usage
111
-
112
- ### Example 1: Basic Font Size Controls
89
+ 2. Add font size controls:
113
90
 
114
91
  ```typescript
115
92
  import { Component, inject } from '@angular/core';
116
- import { SuFontSizeService, FontSize } from '@su-labs/font-size';
93
+ import { FontSizeService } from '@su-labs/font-size';
117
94
 
118
95
  @Component({
119
96
  selector: 'app-font-controls',
120
- standalone: true,
121
97
  template: `
122
- <div class="font-controls">
123
- <h3>Text Size</h3>
124
- <div class="button-group">
125
- @for (size of fontSizes; track size) {
126
- <button
127
- (click)="setFontSize(size)"
128
- [class.active]="fontService.size() === size"
129
- >
130
- {{ size | titlecase }}
131
- </button>
132
- }
133
- </div>
134
- <p>Current size: {{ fontService.size() }}</p>
135
- </div>
98
+ <button type="button" (click)="fontSize.decrease()" [disabled]="fontSize.isMin()">A-</button>
99
+ <button type="button" (click)="fontSize.reset()" [disabled]="fontSize.isDefault()">A</button>
100
+ <button type="button" (click)="fontSize.increase()" [disabled]="fontSize.isMax()">A+</button>
101
+ <p>Current: {{ fontSize.fontSize() }}px</p>
136
102
  `,
137
- styles: [`
138
- .button-group button.active {
139
- background-color: var(--su-theme-primary);
140
- color: white;
141
- }
142
- `]
143
103
  })
144
104
  export class FontControlsComponent {
145
- fontService = inject(SuFontSizeService);
146
- fontSizes: FontSize[] = ['small', 'normal', 'large', 'x-large'];
105
+ protected readonly fontSize = inject(FontSizeService);
106
+ }
107
+ ```
147
108
 
148
- setFontSize(size: FontSize) {
149
- this.fontService.setSize(size);
150
- }
109
+ 3. Use the CSS variable in your styles:
110
+
111
+ ```css
112
+ html {
113
+ font-size: var(--base-font-size);
151
114
  }
152
115
  ```
153
116
 
154
- ### Example 2: Custom Configuration
117
+ ## Usage
118
+
119
+ ### Custom Configuration
120
+
121
+ Call `configure()` before `init()`:
155
122
 
156
123
  ```typescript
157
- import { provideAppInitializer, inject } from '@angular/core';
158
- import { SuFontSizeService, SuFontSizeConfig } from '@su-labs/font-size';
159
-
160
- const fontConfig: SuFontSizeConfig = {
161
- defaultSize: 'normal',
162
- storageKey: 'myApp:fontSize',
163
- cssVarPrefix: '--app-font-',
164
- sizes: {
165
- small: '14px',
166
- normal: '16px',
167
- large: '18px',
168
- 'x-large': '20px'
169
- }
170
- };
124
+ import { ApplicationConfig, inject, provideAppInitializer } from '@angular/core';
125
+ import { FontSizeService } from '@su-labs/font-size';
171
126
 
172
- export const appConfig = {
127
+ export const appConfig: ApplicationConfig = {
173
128
  providers: [
174
129
  provideAppInitializer(() => {
175
- inject(SuFontSizeService).init(fontConfig);
130
+ const fontSize = inject(FontSizeService);
131
+ fontSize.configure({
132
+ defaultSize: 16,
133
+ minSize: 12,
134
+ maxSize: 24,
135
+ step: 2,
136
+ storageKey: 'myApp:fontSize',
137
+ cssVarName: '--app-font-size',
138
+ });
139
+ fontSize.init();
176
140
  }),
177
141
  ],
178
142
  };
179
143
  ```
180
144
 
181
- ### Example 3: Using in Your Styles
145
+ ### Using the Size in Your Styles
182
146
 
183
- ```css
184
- /* Global styles.css */
185
- :root {
186
- --su-font-size-base: 16px;
187
- --su-font-size-small: 14px;
188
- --su-font-size-large: 18px;
189
- }
147
+ Set the variable on the root element and size everything else in `rem`, so the whole page scales:
190
148
 
191
- body {
192
- font-size: var(--su-font-size-base);
149
+ ```css
150
+ html {
151
+ font-size: var(--base-font-size);
193
152
  }
194
153
 
195
154
  h1 {
196
- font-size: calc(var(--su-font-size-base) * 2);
155
+ font-size: 2rem;
197
156
  }
198
157
 
199
- h2 {
200
- font-size: calc(var(--su-font-size-base) * 1.5);
201
- }
202
-
203
- .small-text {
204
- font-size: var(--su-font-size-small);
205
- }
206
-
207
- .large-text {
208
- font-size: var(--su-font-size-large);
158
+ small {
159
+ font-size: 0.875rem;
209
160
  }
210
161
  ```
211
162
 
212
- ## 📖 API Reference
163
+ ## API Reference
213
164
 
214
- ### Service (SuFontSizeService)
165
+ ### Service (FontSizeService)
215
166
 
216
167
  #### Signals
217
168
 
218
169
  | Signal | Type | Description |
219
170
  |--------|------|-------------|
220
- | `size()` | `FontSize` | Current font size setting |
171
+ | `fontSize()` | `number` | Current font size in pixels |
172
+ | `defaultSize()` | `number` | Default size |
173
+ | `minSize()` | `number` | Minimum size |
174
+ | `maxSize()` | `number` | Maximum size |
175
+ | `step()` | `number` | Step used by `increase()` / `decrease()` |
176
+ | `isDefault()` | `boolean` | True when the size equals the default |
177
+ | `isMin()` | `boolean` | True when the size equals the minimum |
178
+ | `isMax()` | `boolean` | True when the size equals the maximum |
179
+
180
+ Change the limits and step with `configure()`, not by writing to their signals.
221
181
 
222
182
  #### Methods
223
183
 
224
184
  | Method | Parameters | Description |
225
185
  |--------|------------|-------------|
226
- | `init(config?)` | `SuFontSizeConfig` | Initialize with custom configuration |
227
- | `setSize(size, persist?)` | `FontSize, boolean` | Change font size (persist defaults to true) |
228
- | `getSize()` | - | Returns current font size |
229
- | `increase()` | - | Increase to next larger size |
230
- | `decrease()` | - | Decrease to next smaller size |
186
+ | `configure(config?)` | `Partial<FontSizeConfig>` | Update limits, step, storage key or CSS variable name. Omitted values keep their current setting. |
187
+ | `init()` | - | Load the saved size (or the default) and apply it. Call once at startup. |
188
+ | `setFontSize(size)` | `number` | Set, apply and save a size (clamped to the limits) |
189
+ | `increase(step?)` | `number` | Increase by `step` (defaults to the configured step) |
190
+ | `decrease(step?)` | `number` | Decrease by `step` (defaults to the configured step) |
191
+ | `reset()` | - | Return to the default size and remove the saved value |
231
192
 
232
193
  ### Types
233
194
 
234
195
  ```typescript
235
- type FontSize = 'small' | 'normal' | 'large' | 'x-large';
236
-
237
- interface SuFontSizeConfig {
238
- storageKey?: string; // Default: 'su:fontSize'
239
- cssVarPrefix?: string; // Default: '--su-font-size-'
240
- defaultSize?: FontSize; // Default: 'normal'
241
- sizes?: {
242
- [key in FontSize]?: string; // Custom pixel/rem values
243
- };
244
- }
196
+ type FontSizeConfig = {
197
+ defaultSize: number;
198
+ minSize: number;
199
+ maxSize: number;
200
+ step: number;
201
+ storageKey?: string;
202
+ storage?: SuStorage; // Default: localStorage
203
+ cssVarName?: string;
204
+ };
245
205
  ```
246
206
 
247
207
  ## Configuration Options
248
208
 
249
209
  | Option | Description | Default Value |
250
210
  |--------|-------------|---------------|
251
- | `storageKey` | The key used to persist font size in `localStorage` | `'su:fontSize'` |
252
- | `cssVarPrefix` | Prefix for CSS variables | `'--su-font-size-'` |
253
- | `defaultSize` | Default font size if none saved | `'normal'` |
254
- | `sizes` | Custom size values (px, rem, em) | `{ small: '14px', normal: '16px', large: '18px', 'x-large': '20px' }` |
211
+ | `defaultSize` | Size used before the user picks one, and after `reset()` | `14` |
212
+ | `minSize` | Smallest allowed size | `10` |
213
+ | `maxSize` | Largest allowed size | `22` |
214
+ | `step` | Pixels added or removed by `increase()` / `decrease()` | `2` |
215
+ | `storageKey` | The key used to persist the size | `'su:font-size'` |
216
+ | `storage` | Where the size is saved. Use `createSuCookieStorage({ domain })` from `@su-labs/core` to share it across subdomains | `localStorage` |
217
+ | `cssVarName` | CSS custom property set on `<html>` | `'--base-font-size'` |
218
+
219
+ Invalid combinations are corrected: a maximum below the minimum is raised to the minimum, the default is clamped to the range, and a step of zero or less becomes `1`.
255
220
 
256
221
  ## Accessibility
257
222
 
258
223
  This library helps meet WCAG 2.1 guidelines:
259
224
 
260
- - ✅ **Success Criterion 1.4.4** - Text can be resized up to 200% without loss of content or functionality
261
- - ✅ **Success Criterion 1.4.8** - User can select foreground and background colors (when combined with theme management)
262
- - ✅ **Success Criterion 1.4.12** - Text spacing is adjustable
225
+ - **Success Criterion 1.4.4** - Text can be resized up to 200% without loss of content or functionality
226
+ - **Success Criterion 1.4.8** - User can select foreground and background colors (when combined with theme management)
227
+ - **Success Criterion 1.4.12** - Text spacing is adjustable
263
228
 
264
229
  ### Best Practices
265
230
 
@@ -269,13 +234,13 @@ This library helps meet WCAG 2.1 guidelines:
269
234
  4. **Persist preference** - Always save user preference (enabled by default)
270
235
  5. **Respect system settings** - Consider reading system font size preferences
271
236
 
272
- ## 🌐 Browser Compatibility
237
+ ## Browser Compatibility
273
238
 
274
239
  Works in all modern browsers that support:
275
- - ✅ CSS Custom Properties
276
- - ✅ localStorage API
277
- - ✅ Angular 21+
278
- - ✅ ES2022+
240
+ - CSS Custom Properties
241
+ - localStorage API
242
+ - Angular 21
243
+ - ES2022+
279
244
 
280
245
  | Browser | Version |
281
246
  |---------|---------|
@@ -284,16 +249,16 @@ Works in all modern browsers that support:
284
249
  | Safari | ≥ 14 |
285
250
  | Edge | ≥ 90 |
286
251
 
287
- ## 🔗 Related Libraries
252
+ ## Related Libraries
288
253
 
289
254
  Part of the **@su-labs** suite:
290
255
 
291
- - 👀 [@su-labs/visit-tracker](https://www.npmjs.com/package/@su-labs/visit-tracker) - User visit tracking
292
- - 🎨 [@su-labs/theme](https://www.npmjs.com/package/@su-labs/theme) - Theme management with dark mode support
293
- - 🔔 [@su-labs/notifications](https://www.npmjs.com/package/@su-labs/notifications) - Toast notification system
294
- - 🔍 [@su-labs/scroll-spy](https://www.npmjs.com/package/@su-labs/scroll-spy) - Scroll position tracking
256
+ - [@su-labs/visit-tracker](https://www.npmjs.com/package/@su-labs/visit-tracker) - User visit tracking
257
+ - [@su-labs/theme](https://www.npmjs.com/package/@su-labs/theme) - Theme management with dark mode support
258
+ - [@su-labs/notifications](https://www.npmjs.com/package/@su-labs/notifications) - Toast notification system
259
+ - [@su-labs/scroll-spy](https://www.npmjs.com/package/@su-labs/scroll-spy) - Scroll position tracking
295
260
 
296
- ## 🔧 Troubleshooting
261
+ ## Troubleshooting
297
262
 
298
263
  ### Font size not persisting?
299
264
 
@@ -301,7 +266,7 @@ Make sure localStorage is enabled and not blocked by privacy settings.
301
266
 
302
267
  ### CSS variables not updating?
303
268
 
304
- Ensure you're using the correct prefix in your CSS (`--su-font-size-` by default) and that you've initialized the service.
269
+ Ensure you're using the correct variable name in your CSS (`--base-font-size` by default) and that you've called `init()`.
305
270
 
306
271
  ### Layout breaking at larger sizes?
307
272
 
@@ -309,13 +274,13 @@ Test your responsive design at all font sizes. Use relative units and flexible l
309
274
 
310
275
  ### TypeScript errors?
311
276
 
312
- Ensure you have Angular 21+ and TypeScript 5.7+ installed.
277
+ Ensure you have Angular 21 and TypeScript 5.9+ installed.
313
278
 
314
- ## 💬 Support
279
+ ## Support
315
280
 
316
- - 🐛 Found a bug? [Open an issue](https://github.com/Greezaaa/settings-utils-lib/issues)
317
- - 💡 Have a feature request? [Start a discussion](https://github.com/Greezaaa/settings-utils-lib/discussions)
318
- - ⭐ Like this library? [Give it a star!](https://github.com/Greezaaa/settings-utils-lib)
281
+ - Found a bug? [Open an issue](https://github.com/Greezaaa/settings-utils-lib/issues)
282
+ - Have a feature request? [Start a discussion](https://github.com/Greezaaa/settings-utils-lib/discussions)
283
+ - Like this library? [Give it a star!](https://github.com/Greezaaa/settings-utils-lib)
319
284
 
320
285
  ## Contributing
321
286
 
@@ -1,181 +1,94 @@
1
1
  import * as i0 from '@angular/core';
2
2
  import { signal, computed, Injectable } from '@angular/core';
3
+ import { SuFontSizeController } from '@su-labs/core/font-size';
3
4
 
5
+ /**
6
+ * Angular service for managing the font size.
7
+ *
8
+ * Thin wrapper around the framework-agnostic `SuFontSizeController` from
9
+ * `@su-labs/core/font-size` that exposes the size and limits as Angular signals.
10
+ */
4
11
  class FontSizeService {
5
- /**
6
- * Default font size in pixels.
7
- * Can be overridden via {@link configure}.
8
- */
9
- defaultSize = signal(14, ...(ngDevMode ? [{ debugName: "defaultSize" }] : []));
10
- /**
11
- * Minimum allowed font size in pixels.
12
- * Can be overridden via {@link configure}.
13
- */
14
- minSize = signal(10, ...(ngDevMode ? [{ debugName: "minSize" }] : []));
15
- /**
16
- * Maximum allowed font size in pixels.
17
- * Can be overridden via {@link configure}.
18
- */
19
- maxSize = signal(22, ...(ngDevMode ? [{ debugName: "maxSize" }] : []));
20
- /**
21
- * Default step value (in pixels) for increase/decrease operations.
22
- * Can be overridden via {@link configure} or per call in {@link increase} / {@link decrease}.
23
- */
24
- step = signal(2, ...(ngDevMode ? [{ debugName: "step" }] : []));
25
- /**
26
- * Key used for persisting the font size in localStorage.
27
- * Defaults to `"app:font-size"`.
28
- */
29
- storageKey = 'su:font-size';
30
- /**
31
- * CSS custom property name where the font size is applied.
32
- * Defaults to `"--base-font-size"`.
33
- */
34
- cssVarName = '--base-font-size';
35
- /**
36
- * Current font size state (reactive).
37
- */
38
- fontSize = signal(this.readFromStorage(), ...(ngDevMode ? [{ debugName: "fontSize" }] : []));
39
- /**
40
- * True if current font size equals the default size.
41
- */
42
- isDefault = computed(() => this.fontSize() === this.defaultSize(), ...(ngDevMode ? [{ debugName: "isDefault" }] : []));
43
- /**
44
- * True if current font size equals the maximum size.
45
- */
46
- isMax = computed(() => this.fontSize() === this.maxSize(), ...(ngDevMode ? [{ debugName: "isMax" }] : []));
47
- /**
48
- * True if current font size equals the minimum size.
49
- */
50
- isMin = computed(() => this.fontSize() === this.minSize(), ...(ngDevMode ? [{ debugName: "isMin" }] : []));
51
- /**
52
- * Updates the configuration for font size handling.
53
- * Any omitted values will fall back to their defaults.
54
- *
55
- * @param cfg Partial configuration object (min, max, default, step, storage key, CSS variable name).
12
+ /** Framework-agnostic font size logic */
13
+ controller = new SuFontSizeController();
14
+ initialLimits = this.controller.limits.get();
15
+ /** Default font size in pixels. Change it with {@link configure}. */
16
+ defaultSize = signal(this.initialLimits.defaultSize, ...(ngDevMode ? [{ debugName: "defaultSize" }] : /* istanbul ignore next */ []));
17
+ /** Minimum font size in pixels. Change it with {@link configure}. */
18
+ minSize = signal(this.initialLimits.minSize, ...(ngDevMode ? [{ debugName: "minSize" }] : /* istanbul ignore next */ []));
19
+ /** Maximum font size in pixels. Change it with {@link configure}. */
20
+ maxSize = signal(this.initialLimits.maxSize, ...(ngDevMode ? [{ debugName: "maxSize" }] : /* istanbul ignore next */ []));
21
+ /** Default step in pixels for {@link increase} / {@link decrease}. Change it with {@link configure}. */
22
+ step = signal(this.initialLimits.step, ...(ngDevMode ? [{ debugName: "step" }] : /* istanbul ignore next */ []));
23
+ /** Current font size in pixels */
24
+ fontSize = signal(this.controller.fontSize.get(), ...(ngDevMode ? [{ debugName: "fontSize" }] : /* istanbul ignore next */ []));
25
+ /** True if the current size equals the default size */
26
+ isDefault = computed(() => this.fontSize() === this.defaultSize(), ...(ngDevMode ? [{ debugName: "isDefault" }] : /* istanbul ignore next */ []));
27
+ /** True if the current size equals the maximum size */
28
+ isMax = computed(() => this.fontSize() === this.maxSize(), ...(ngDevMode ? [{ debugName: "isMax" }] : /* istanbul ignore next */ []));
29
+ /** True if the current size equals the minimum size */
30
+ isMin = computed(() => this.fontSize() === this.minSize(), ...(ngDevMode ? [{ debugName: "isMin" }] : /* istanbul ignore next */ []));
31
+ /** Stop syncing the controller's stores into the signals */
32
+ unsubscribers = [
33
+ this.controller.fontSize.subscribe((size) => this.fontSize.set(size)),
34
+ this.controller.limits.subscribe((limits) => {
35
+ this.defaultSize.set(limits.defaultSize);
36
+ this.minSize.set(limits.minSize);
37
+ this.maxSize.set(limits.maxSize);
38
+ this.step.set(limits.step);
39
+ }),
40
+ ];
41
+ /**
42
+ * Update the configuration. Omitted values keep their current setting.
43
+ * @param cfg Partial configuration (limits, step, storage key, CSS variable name).
56
44
  */
57
45
  configure(cfg = {}) {
58
- if (cfg.minSize !== undefined)
59
- this.minSize.set(cfg.minSize);
60
- if (cfg.maxSize !== undefined)
61
- this.maxSize.set(cfg.maxSize);
62
- if (cfg.defaultSize !== undefined)
63
- this.defaultSize.set(cfg.defaultSize);
64
- if (cfg.step !== undefined)
65
- this.step.set(cfg.step);
66
- if (cfg.storageKey)
67
- this.storageKey = cfg.storageKey;
68
- if (cfg.cssVarName)
69
- this.cssVarName = cfg.cssVarName;
70
- // Ensure logical invariants
71
- if (this.minSize() > this.maxSize())
72
- this.maxSize.set(this.minSize());
73
- if (this.defaultSize() < this.minSize())
74
- this.defaultSize.set(this.minSize());
75
- if (this.defaultSize() > this.maxSize())
76
- this.defaultSize.set(this.maxSize());
77
- if (this.step() <= 0 || !Number.isFinite(this.step()))
78
- this.step.set(1);
79
- // Clamp current size after configuration changes
80
- this.fontSize.update((s) => this.clamp(s));
46
+ this.controller.configure(cfg);
81
47
  }
82
48
  /**
83
- * Initializes the font size service.
84
- * Loads the persisted value (if available), clamps it,
85
- * applies it to the DOM, and updates internal state.
86
- * Should typically be called once at application startup.
49
+ * Load the saved size (or the default), clamp it and apply it to the document.
50
+ * Call once at application startup, after {@link configure}.
87
51
  */
88
52
  init() {
89
- const size = this.readFromStorage();
90
- this.fontSize.set(this.clamp(size));
91
- this.applyCssVar(this.fontSize());
53
+ this.controller.init();
92
54
  }
93
55
  /**
94
- * Sets the font size to a specific value (clamped within min/max).
95
- *
56
+ * Set, apply and persist a font size, clamped to the allowed range.
96
57
  * @param size Desired font size in pixels.
97
58
  */
98
59
  setFontSize(size) {
99
- const clamped = this.clamp(size);
100
- this.fontSize.set(clamped);
101
- this.applyCssVar(clamped);
102
- this.writeToStorage(clamped);
60
+ this.controller.setFontSize(size);
103
61
  }
104
62
  /**
105
- * Increases the font size.
106
- *
107
- * @param step Optional custom step (pixels). Falls back to configured {@link step} if omitted.
63
+ * Increase the font size.
64
+ * @param step Pixels to add. Defaults to {@link step}.
108
65
  */
109
66
  increase(step) {
110
67
  this.setFontSize(this.fontSize() + (step ?? this.step()));
111
68
  }
112
69
  /**
113
- * Decreases the font size.
114
- *
115
- * @param step Optional custom step (pixels). Falls back to configured {@link step} if omitted.
70
+ * Decrease the font size.
71
+ * @param step Pixels to remove. Defaults to {@link step}.
116
72
  */
117
73
  decrease(step) {
118
74
  this.setFontSize(this.fontSize() - (step ?? this.step()));
119
75
  }
120
- /**
121
- * Resets the font size to the configured {@link defaultSize}.
122
- * Also removes the persisted value from localStorage.
123
- */
76
+ /** Return to the default size and remove the saved value from localStorage */
124
77
  reset() {
125
- const d = this.defaultSize();
126
- this.fontSize.set(d);
127
- this.applyCssVar(d);
128
- localStorage.removeItem(this.storageKey);
78
+ this.controller.reset();
129
79
  }
130
- /**
131
- * Clamps a given value between the configured {@link minSize} and {@link maxSize}.
132
- *
133
- * @param size Value to clamp.
134
- * @returns Clamped value within the allowed range.
135
- */
136
- clamp(size) {
137
- return Math.min(Math.max(size, this.minSize()), this.maxSize());
80
+ /** Angular lifecycle hook for service destruction */
81
+ ngOnDestroy() {
82
+ this.unsubscribers.forEach((unsubscribe) => unsubscribe());
138
83
  }
139
- /**
140
- * Reads the font size from localStorage.
141
- * Falls back to {@link defaultSize} if no value is stored or value is invalid.
142
- *
143
- * @returns Stored font size or default.
144
- */
145
- readFromStorage() {
146
- const stored = localStorage.getItem(this.storageKey);
147
- const parsed = stored ? Number(stored) : this.defaultSize();
148
- return Number.isFinite(parsed) ? parsed : this.defaultSize();
149
- }
150
- /**
151
- * Persists the current font size in localStorage.
152
- *
153
- * @param size Font size value to persist.
154
- */
155
- writeToStorage(size) {
156
- localStorage.setItem(this.storageKey, String(size));
157
- }
158
- /**
159
- * Applies the current font size to the DOM
160
- * using the configured CSS custom property name.
161
- *
162
- * @param size Font size value in pixels.
163
- */
164
- applyCssVar(size) {
165
- document.documentElement.style.setProperty(this.cssVarName, `${size}px`);
166
- }
167
- static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.1.2", ngImport: i0, type: FontSizeService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
168
- static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "21.1.2", ngImport: i0, type: FontSizeService, providedIn: 'root' });
84
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.26", ngImport: i0, type: FontSizeService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
85
+ static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "21.2.26", ngImport: i0, type: FontSizeService, providedIn: 'root' });
169
86
  }
170
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.1.2", ngImport: i0, type: FontSizeService, decorators: [{
87
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.26", ngImport: i0, type: FontSizeService, decorators: [{
171
88
  type: Injectable,
172
89
  args: [{ providedIn: 'root' }]
173
90
  }] });
174
91
 
175
- /*
176
- * Public API Surface of font-size
177
- */
178
-
179
92
  /**
180
93
  * Generated bundle index. Do not edit.
181
94
  */
@@ -1 +1 @@
1
- {"version":3,"file":"su-labs-font-size.mjs","sources":["../../../../projects/su-labs/font-size/src/lib/font-size.service.ts","../../../../projects/su-labs/font-size/src/public-api.ts","../../../../projects/su-labs/font-size/src/su-labs-font-size.ts"],"sourcesContent":["import { Injectable, signal, computed } from '@angular/core';\nimport { FontSizeConfig } from './font-size-config.interface';\n\n@Injectable({ providedIn: 'root' })\nexport class FontSizeService {\n /**\n * Default font size in pixels.\n * Can be overridden via {@link configure}.\n */\n defaultSize = signal(14);\n\n /**\n * Minimum allowed font size in pixels.\n * Can be overridden via {@link configure}.\n */\n minSize = signal(10);\n\n /**\n * Maximum allowed font size in pixels.\n * Can be overridden via {@link configure}.\n */\n maxSize = signal(22);\n\n /**\n * Default step value (in pixels) for increase/decrease operations.\n * Can be overridden via {@link configure} or per call in {@link increase} / {@link decrease}.\n */\n step = signal(2);\n\n /**\n * Key used for persisting the font size in localStorage.\n * Defaults to `\"app:font-size\"`.\n */\n private storageKey = 'su:font-size';\n\n /**\n * CSS custom property name where the font size is applied.\n * Defaults to `\"--base-font-size\"`.\n */\n private cssVarName = '--base-font-size';\n\n /**\n * Current font size state (reactive).\n */\n fontSize = signal<number>(this.readFromStorage());\n\n /**\n * True if current font size equals the default size.\n */\n isDefault = computed(() => this.fontSize() === this.defaultSize());\n\n /**\n * True if current font size equals the maximum size.\n */\n isMax = computed(() => this.fontSize() === this.maxSize());\n\n /**\n * True if current font size equals the minimum size.\n */\n isMin = computed(() => this.fontSize() === this.minSize());\n\n /**\n * Updates the configuration for font size handling.\n * Any omitted values will fall back to their defaults.\n *\n * @param cfg Partial configuration object (min, max, default, step, storage key, CSS variable name).\n */\n configure(cfg: Partial<FontSizeConfig> = {}): void {\n if (cfg.minSize !== undefined) this.minSize.set(cfg.minSize);\n if (cfg.maxSize !== undefined) this.maxSize.set(cfg.maxSize);\n if (cfg.defaultSize !== undefined) this.defaultSize.set(cfg.defaultSize);\n if (cfg.step !== undefined) this.step.set(cfg.step);\n if (cfg.storageKey) this.storageKey = cfg.storageKey;\n if (cfg.cssVarName) this.cssVarName = cfg.cssVarName;\n\n // Ensure logical invariants\n if (this.minSize() > this.maxSize()) this.maxSize.set(this.minSize());\n if (this.defaultSize() < this.minSize())\n this.defaultSize.set(this.minSize());\n if (this.defaultSize() > this.maxSize())\n this.defaultSize.set(this.maxSize());\n if (this.step() <= 0 || !Number.isFinite(this.step())) this.step.set(1);\n\n // Clamp current size after configuration changes\n this.fontSize.update((s) => this.clamp(s));\n }\n\n /**\n * Initializes the font size service.\n * Loads the persisted value (if available), clamps it,\n * applies it to the DOM, and updates internal state.\n * Should typically be called once at application startup.\n */\n init(): void {\n const size = this.readFromStorage();\n this.fontSize.set(this.clamp(size));\n this.applyCssVar(this.fontSize());\n }\n\n /**\n * Sets the font size to a specific value (clamped within min/max).\n *\n * @param size Desired font size in pixels.\n */\n setFontSize(size: number): void {\n const clamped = this.clamp(size);\n this.fontSize.set(clamped);\n this.applyCssVar(clamped);\n this.writeToStorage(clamped);\n }\n\n /**\n * Increases the font size.\n *\n * @param step Optional custom step (pixels). Falls back to configured {@link step} if omitted.\n */\n increase(step?: number): void {\n this.setFontSize(this.fontSize() + (step ?? this.step()));\n }\n\n /**\n * Decreases the font size.\n *\n * @param step Optional custom step (pixels). Falls back to configured {@link step} if omitted.\n */\n decrease(step?: number): void {\n this.setFontSize(this.fontSize() - (step ?? this.step()));\n }\n\n /**\n * Resets the font size to the configured {@link defaultSize}.\n * Also removes the persisted value from localStorage.\n */\n reset(): void {\n const d = this.defaultSize();\n this.fontSize.set(d);\n this.applyCssVar(d);\n localStorage.removeItem(this.storageKey);\n }\n\n /**\n * Clamps a given value between the configured {@link minSize} and {@link maxSize}.\n *\n * @param size Value to clamp.\n * @returns Clamped value within the allowed range.\n */\n private clamp(size: number): number {\n return Math.min(Math.max(size, this.minSize()), this.maxSize());\n }\n\n /**\n * Reads the font size from localStorage.\n * Falls back to {@link defaultSize} if no value is stored or value is invalid.\n *\n * @returns Stored font size or default.\n */\n private readFromStorage(): number {\n const stored = localStorage.getItem(this.storageKey);\n const parsed = stored ? Number(stored) : this.defaultSize();\n return Number.isFinite(parsed) ? parsed : this.defaultSize();\n }\n\n /**\n * Persists the current font size in localStorage.\n *\n * @param size Font size value to persist.\n */\n private writeToStorage(size: number): void {\n localStorage.setItem(this.storageKey, String(size));\n }\n\n /**\n * Applies the current font size to the DOM\n * using the configured CSS custom property name.\n *\n * @param size Font size value in pixels.\n */\n private applyCssVar(size: number): void {\n document.documentElement.style.setProperty(this.cssVarName, `${size}px`);\n }\n}\n","/*\n * Public API Surface of font-size\n */\n\nexport * from './lib/font-size.service';\nexport * from './lib/font-size-config.interface';\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public-api';\n"],"names":[],"mappings":";;;MAIa,eAAe,CAAA;AAC1B;;;AAGG;AACH,IAAA,WAAW,GAAG,MAAM,CAAC,EAAE,uDAAC;AAExB;;;AAGG;AACH,IAAA,OAAO,GAAG,MAAM,CAAC,EAAE,mDAAC;AAEpB;;;AAGG;AACH,IAAA,OAAO,GAAG,MAAM,CAAC,EAAE,mDAAC;AAEpB;;;AAGG;AACH,IAAA,IAAI,GAAG,MAAM,CAAC,CAAC,gDAAC;AAEhB;;;AAGG;IACK,UAAU,GAAG,cAAc;AAEnC;;;AAGG;IACK,UAAU,GAAG,kBAAkB;AAEvC;;AAEG;IACH,QAAQ,GAAG,MAAM,CAAS,IAAI,CAAC,eAAe,EAAE,oDAAC;AAEjD;;AAEG;AACH,IAAA,SAAS,GAAG,QAAQ,CAAC,MAAM,IAAI,CAAC,QAAQ,EAAE,KAAK,IAAI,CAAC,WAAW,EAAE,qDAAC;AAElE;;AAEG;AACH,IAAA,KAAK,GAAG,QAAQ,CAAC,MAAM,IAAI,CAAC,QAAQ,EAAE,KAAK,IAAI,CAAC,OAAO,EAAE,iDAAC;AAE1D;;AAEG;AACH,IAAA,KAAK,GAAG,QAAQ,CAAC,MAAM,IAAI,CAAC,QAAQ,EAAE,KAAK,IAAI,CAAC,OAAO,EAAE,iDAAC;AAE1D;;;;;AAKG;IACH,SAAS,CAAC,MAA+B,EAAE,EAAA;AACzC,QAAA,IAAI,GAAG,CAAC,OAAO,KAAK,SAAS;Y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size.mjs","sources":["../../../../compat/angular-21/build/font-size/src/lib/font-size.service.ts","../../../../compat/angular-21/build/font-size/src/su-labs-font-size.ts"],"sourcesContent":["import { computed, Injectable, OnDestroy, signal } from '@angular/core';\nimport { SuFontSizeController, SuFontSizeLimits } from '@su-labs/core/font-size';\nimport { FontSizeConfig } from './font-size-config.interface';\n\n/**\n * Angular service for managing the font size.\n *\n * Thin wrapper around the framework-agnostic `SuFontSizeController` from\n * `@su-labs/core/font-size` that exposes the size and limits as Angular signals.\n */\n@Injectable({ providedIn: 'root' })\nexport class FontSizeService implements OnDestroy {\n /** Framework-agnostic font size logic */\n private readonly controller = new SuFontSizeController();\n\n private readonly initialLimits: SuFontSizeLimits = this.controller.limits.get();\n\n /** Default font size in pixels. Change it with {@link configure}. */\n defaultSize = signal(this.initialLimits.defaultSize);\n\n /** Minimum font size in pixels. Change it with {@link configure}. */\n minSize = signal(this.initialLimits.minSize);\n\n /** Maximum font size in pixels. Change it with {@link configure}. */\n maxSize = signal(this.initialLimits.maxSize);\n\n /** Default step in pixels for {@link increase} / {@link decrease}. Change it with {@link configure}. */\n step = signal(this.initialLimits.step);\n\n /** Current font size in pixels */\n fontSize = signal<number>(this.controller.fontSize.get());\n\n /** True if the current size equals the default size */\n isDefault = computed(() => this.fontSize() === this.defaultSize());\n\n /** True if the current size equals the maximum size */\n isMax = computed(() => this.fontSize() === this.maxSize());\n\n /** True if the current size equals the minimum size */\n isMin = computed(() => this.fontSize() === this.minSize());\n\n /** Stop syncing the controller's stores into the signals */\n private readonly unsubscribers = [\n this.controller.fontSize.subscribe((size) => this.fontSize.set(size)),\n this.controller.limits.subscribe((limits) => {\n this.defaultSize.set(limits.defaultSize);\n this.minSize.set(limits.minSize);\n this.maxSize.set(limits.maxSize);\n this.step.set(limits.step);\n }),\n ];\n\n /**\n * Update the configuration. Omitted values keep their current setting.\n * @param cfg Partial configuration (limits, step, storage key, CSS variable name).\n */\n configure(cfg: Partial<FontSizeConfig> = {}): void {\n this.controller.configure(cfg);\n }\n\n /**\n * Load the saved size (or the default), clamp it and apply it to the document.\n * Call once at application startup, after {@link configure}.\n */\n init(): void {\n this.controller.init();\n }\n\n /**\n * Set, apply and persist a font size, clamped to the allowed range.\n * @param size Desired font size in pixels.\n */\n setFontSize(size: number): void {\n this.controller.setFontSize(size);\n }\n\n /**\n * Increase the font size.\n * @param step Pixels to add. Defaults to {@link step}.\n */\n increase(step?: number): void {\n this.setFontSize(this.fontSize() + (step ?? this.step()));\n }\n\n /**\n * Decrease the font size.\n * @param step Pixels to remove. Defaults to {@link step}.\n */\n decrease(step?: number): void {\n this.setFontSize(this.fontSize() - (step ?? this.step()));\n }\n\n /** Return to the default size and remove the saved value from localStorage */\n reset(): void {\n this.controller.reset();\n }\n\n /** Angular lifecycle hook for service destruction */\n ngOnDestroy(): void {\n this.unsubscribers.forEach((unsubscribe) => unsubscribe());\n }\n}\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public-api';\n"],"names":[],"mappings":";;;;AAIA;;;;;AAKG;MAEU,eAAe,CAAA;;AAET,IAAA,UAAU,GAAG,IAAI,oBAAoB,EAAE;IAEvC,aAAa,GAAqB,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,GAAG,EAAE;;IAG/E,WAAW,GAAG,MAAM,CAAC,IAAI,CAAC,aAAa,CAAC,WAAW,EAAA,IAAA,SAAA,GAAA,CAAA,EAAA,SAAA,EAAA,aAAA,EAAA,CAAA,8BAAA,EAAA,CAAA,CAAC;;IAGpD,OAAO,GAAG,MAAM,CAAC,IAAI,CAAC,aAAa,CAAC,OAAO,EAAA,IAAA,SAAA,GAAA,CAAA,EAAA,SAAA,EAAA,SAAA,EAAA,CAAA,8BAAA,EAAA,CAAA,CAAC;;IAG5C,OAAO,GAAG,MAAM,CAAC,IAAI,CAAC,aAAa,CAAC,OAAO,EAAA,IAAA,SAAA,GAAA,CAAA,EAAA,SAAA,EAAA,SAAA,EAAA,CAAA,8BAAA,EAAA,CAAA,CAAC;;IA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labs/font-size",
3
- "version": "21.0.5",
3
+ "version": "21.2.1",
4
4
  "description": "A lightweight Angular service for dynamic font size management.",
5
5
  "keywords": [
6
6
  "angular",
@@ -18,7 +18,7 @@
18
18
  "signals",
19
19
  "localstorage"
20
20
  ],
21
- "homepage": "https://github.com/Greezaaa/settings-utils-lib/tree/main/projects/su-labs/font-size#readme",
21
+ "homepage": "https://su-labs.dev/font-size/",
22
22
  "author": {
23
23
  "name": "Yevheniy Alekseyev",
24
24
  "email": "yev.alekseyev@gmail.com",
@@ -29,6 +29,7 @@
29
29
  "@angular/core": "^21.0.0"
30
30
  },
31
31
  "dependencies": {
32
+ "@su-labs/core": "1.9.0",
32
33
  "tslib": "^2.3.0"
33
34
  },
34
35
  "repository": {
@@ -51,5 +52,6 @@
51
52
  "types": "./types/su-labs-font-size.d.ts",
52
53
  "default": "./fesm2022/su-labs-font-size.mjs"
53
54
  }
54
- }
55
+ },
56
+ "type": "module"
55
57
  }
@@ -1,125 +1,67 @@
1
1
  import * as _angular_core from '@angular/core';
2
+ import { OnDestroy } from '@angular/core';
3
+ import { SuFontSizeLimits, SuFontSizeConfig } from '@su-labs/core/font-size';
2
4
 
3
- interface FontSizeConfig {
4
- defaultSize: number;
5
- minSize: number;
6
- maxSize: number;
7
- step: number;
8
- storageKey?: string;
9
- cssVarName?: string;
10
- }
5
+ /** Font size configuration: limits and step in pixels, plus optional storage, storage key and CSS variable name */
6
+ type FontSizeConfig = SuFontSizeLimits & Pick<SuFontSizeConfig, 'storage' | 'storageKey' | 'cssVarName'>;
11
7
 
12
- declare class FontSizeService {
13
- /**
14
- * Default font size in pixels.
15
- * Can be overridden via {@link configure}.
16
- */
8
+ /**
9
+ * Angular service for managing the font size.
10
+ *
11
+ * Thin wrapper around the framework-agnostic `SuFontSizeController` from
12
+ * `@su-labs/core/font-size` that exposes the size and limits as Angular signals.
13
+ */
14
+ declare class FontSizeService implements OnDestroy {
15
+ /** Framework-agnostic font size logic */
16
+ private readonly controller;
17
+ private readonly initialLimits;
18
+ /** Default font size in pixels. Change it with {@link configure}. */
17
19
  defaultSize: _angular_core.WritableSignal<number>;
18
- /**
19
- * Minimum allowed font size in pixels.
20
- * Can be overridden via {@link configure}.
21
- */
20
+ /** Minimum font size in pixels. Change it with {@link configure}. */
22
21
  minSize: _angular_core.WritableSignal<number>;
23
- /**
24
- * Maximum allowed font size in pixels.
25
- * Can be overridden via {@link configure}.
26
- */
22
+ /** Maximum font size in pixels. Change it with {@link configure}. */
27
23
  maxSize: _angular_core.WritableSignal<number>;
28
- /**
29
- * Default step value (in pixels) for increase/decrease operations.
30
- * Can be overridden via {@link configure} or per call in {@link increase} / {@link decrease}.
31
- */
24
+ /** Default step in pixels for {@link increase} / {@link decrease}. Change it with {@link configure}. */
32
25
  step: _angular_core.WritableSignal<number>;
33
- /**
34
- * Key used for persisting the font size in localStorage.
35
- * Defaults to `"app:font-size"`.
36
- */
37
- private storageKey;
38
- /**
39
- * CSS custom property name where the font size is applied.
40
- * Defaults to `"--base-font-size"`.
41
- */
42
- private cssVarName;
43
- /**
44
- * Current font size state (reactive).
45
- */
26
+ /** Current font size in pixels */
46
27
  fontSize: _angular_core.WritableSignal<number>;
47
- /**
48
- * True if current font size equals the default size.
49
- */
28
+ /** True if the current size equals the default size */
50
29
  isDefault: _angular_core.Signal<boolean>;
51
- /**
52
- * True if current font size equals the maximum size.
53
- */
30
+ /** True if the current size equals the maximum size */
54
31
  isMax: _angular_core.Signal<boolean>;
55
- /**
56
- * True if current font size equals the minimum size.
57
- */
32
+ /** True if the current size equals the minimum size */
58
33
  isMin: _angular_core.Signal<boolean>;
34
+ /** Stop syncing the controller's stores into the signals */
35
+ private readonly unsubscribers;
59
36
  /**
60
- * Updates the configuration for font size handling.
61
- * Any omitted values will fall back to their defaults.
62
- *
63
- * @param cfg Partial configuration object (min, max, default, step, storage key, CSS variable name).
37
+ * Update the configuration. Omitted values keep their current setting.
38
+ * @param cfg Partial configuration (limits, step, storage key, CSS variable name).
64
39
  */
65
40
  configure(cfg?: Partial<FontSizeConfig>): void;
66
41
  /**
67
- * Initializes the font size service.
68
- * Loads the persisted value (if available), clamps it,
69
- * applies it to the DOM, and updates internal state.
70
- * Should typically be called once at application startup.
42
+ * Load the saved size (or the default), clamp it and apply it to the document.
43
+ * Call once at application startup, after {@link configure}.
71
44
  */
72
45
  init(): void;
73
46
  /**
74
- * Sets the font size to a specific value (clamped within min/max).
75
- *
47
+ * Set, apply and persist a font size, clamped to the allowed range.
76
48
  * @param size Desired font size in pixels.
77
49
  */
78
50
  setFontSize(size: number): void;
79
51
  /**
80
- * Increases the font size.
81
- *
82
- * @param step Optional custom step (pixels). Falls back to configured {@link step} if omitted.
52
+ * Increase the font size.
53
+ * @param step Pixels to add. Defaults to {@link step}.
83
54
  */
84
55
  increase(step?: number): void;
85
56
  /**
86
- * Decreases the font size.
87
- *
88
- * @param step Optional custom step (pixels). Falls back to configured {@link step} if omitted.
57
+ * Decrease the font size.
58
+ * @param step Pixels to remove. Defaults to {@link step}.
89
59
  */
90
60
  decrease(step?: number): void;
91
- /**
92
- * Resets the font size to the configured {@link defaultSize}.
93
- * Also removes the persisted value from localStorage.
94
- */
61
+ /** Return to the default size and remove the saved value from localStorage */
95
62
  reset(): void;
96
- /**
97
- * Clamps a given value between the configured {@link minSize} and {@link maxSize}.
98
- *
99
- * @param size Value to clamp.
100
- * @returns Clamped value within the allowed range.
101
- */
102
- private clamp;
103
- /**
104
- * Reads the font size from localStorage.
105
- * Falls back to {@link defaultSize} if no value is stored or value is invalid.
106
- *
107
- * @returns Stored font size or default.
108
- */
109
- private readFromStorage;
110
- /**
111
- * Persists the current font size in localStorage.
112
- *
113
- * @param size Font size value to persist.
114
- */
115
- private writeToStorage;
116
- /**
117
- * Applies the current font size to the DOM
118
- * using the configured CSS custom property name.
119
- *
120
- * @param size Font size value in pixels.
121
- */
122
- private applyCssVar;
63
+ /** Angular lifecycle hook for service destruction */
64
+ ngOnDestroy(): void;
123
65
  static ɵfac: _angular_core.ɵɵFactoryDeclaration<FontSizeService, never>;
124
66
  static ɵprov: _angular_core.ɵɵInjectableDeclaration<FontSizeService>;
125
67
  }