@su-labs/font-size 21.0.4 → 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,47 @@ 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
+
44
+ ## [21.0.5] - 2026-02-04
45
+
46
+ ### Changed
47
+ - Update README.md
48
+
8
49
  ## [21.0.4] - 2026-02-03
9
50
 
10
51
  ### Changed
package/README.md CHANGED
@@ -1,137 +1,293 @@
1
- # FontSizeService
2
-
3
- A lightweight Angular service for dynamic font size management. Easily increase, decrease, or reset font sizes in your Angular applications, with persistent settings in `localStorage`. Designed as a reusable library for multiple projects.
1
+ # Font Size
2
+
3
+ `@su-labs/font-size`
4
+
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-v22-DD0031?style=for-the-badge&logo=angular&logoColor=white)
7
+ ![TypeScript](https://img.shields.io/badge/TypeScript-007ACC?style=for-the-badge&logo=typescript&logoColor=white)
8
+ ![License](https://img.shields.io/badge/License-MIT-blue.svg?style=for-the-badge)
9
+ ![NPM](https://img.shields.io/badge/NPM-CB3837?style=for-the-badge&logo=npm&logoColor=white)
10
+ ![Size](https://img.shields.io/badge/Size-Small-green.svg?style=for-the-badge)
11
+ ![Downloads](https://img.shields.io/npm/dt/@su-labs/font-size?style=for-the-badge)
12
+ ![Version](https://img.shields.io/npm/v/@su-labs/font-size?style=for-the-badge)
13
+
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
+
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
+
18
+ ## Table of Contents
19
+
20
+ - [Why Use This Library?](#why-use-this-library)
21
+ - [Features](#features)
22
+ - [Installation](#installation)
23
+ - [Quick Start](#quick-start)
24
+ - [Usage](#usage)
25
+ - [API Reference](#api-reference)
26
+ - [Configuration Options](#configuration-options)
27
+ - [Accessibility](#accessibility)
28
+ - [Browser Compatibility](#browser-compatibility)
29
+ - [Related Libraries](#related-libraries)
30
+ - [Troubleshooting](#troubleshooting)
31
+ - [Support](#support)
32
+ - [Contributing](#contributing)
33
+ - [License](#license)
34
+
35
+ ## Why Use This Library?
36
+
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
4
45
 
5
46
  ## Features
6
47
 
7
- - Set a default font size and apply it globally.
8
- - Increase or decrease font size with configurable step.
9
- - Reset to default font size.
10
- - Automatically persist user preferences in `localStorage`.
11
- - Provides reactive `Signal`s to integrate with Angular's reactive system.
12
- - Limits font size to configurable minimum and maximum values.
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.
13
53
 
14
54
  ## Installation
15
55
 
16
56
  You can install this library via npm:
17
57
 
18
- ```bash
19
- npm install @su-labs/font-size
58
+ ```sh
59
+ npm install @su-labs/font-size@ng21
60
+ ```
61
+
62
+ This is the Angular 21 version. For the newest Angular, install `@su-labs/font-size` without a tag.
63
+
64
+ ## Peer Dependencies
65
+
66
+ This library requires the following peer dependencies:
67
+
68
+ ```sh
69
+ npm install @angular/common@^21 @angular/core@^21
20
70
  ```
21
71
 
22
- npm install @angular/common@^21.0.0 @angular/core@^21.0.0
72
+ ## Quick Start
23
73
 
24
- You can provide the service in your main.ts (or wherever your ApplicationConfig is defined) and initialize it automatically:
74
+ 1. Initialize the service in `app.config.ts`:
25
75
 
26
76
  ```typescript
77
+ import { ApplicationConfig, inject, provideAppInitializer } from '@angular/core';
78
+ import { FontSizeService } from '@su-labs/font-size';
79
+
27
80
  export const appConfig: ApplicationConfig = {
28
- providers: [
29
- FontSizeService,
30
- provideAppInitializer(() => {
31
-
32
- const fontService = inject(FontSizeService);
33
- fontService.init(); // initializes font size from localStorage and applies CSS variable
34
- }),
35
- ],
81
+ providers: [
82
+ provideAppInitializer(() => {
83
+ inject(FontSizeService).init();
84
+ }),
85
+ ],
36
86
  };
37
87
  ```
38
- Using the service in components
39
88
 
40
- Inject the service into any component and access reactive signals:
89
+ 2. Add font size controls:
41
90
 
42
91
  ```typescript
43
- import { Component, effect } from '@angular/core';
92
+ import { Component, inject } from '@angular/core';
44
93
  import { FontSizeService } from '@su-labs/font-size';
45
94
 
46
95
  @Component({
47
- selector: 'app-example',
48
- template: `
49
- <div>
50
- <p>Current font size: {{ fontSize() }}</p>
51
- <button (click)="increase()">A+</button>
52
- <button (click)="decrease()">A-</button>
53
- <button (click)="reset()">Reset</button>
54
- </div>` ,
96
+ selector: 'app-font-controls',
97
+ template: `
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>
102
+ `,
55
103
  })
104
+ export class FontControlsComponent {
105
+ protected readonly fontSize = inject(FontSizeService);
106
+ }
107
+ ```
56
108
 
57
- export class ExampleComponent {
58
- private fontService = inject(FontSizeService);
59
- fontSize = computed(() => this.fontService.fontSize());
60
-
61
- increase(step?: number) {
62
- this.fontService.increase(step);
63
- }
64
-
65
- decrease(step?: number) {
66
- this.fontService.decrease(step);
67
- }
109
+ 3. Use the CSS variable in your styles:
68
110
 
69
- reset() {
70
- this.fontService.reset();
71
- }
111
+ ```css
112
+ html {
113
+ font-size: var(--base-font-size);
72
114
  }
73
115
  ```
74
116
 
75
- ### Optional configuration
76
-
77
- The service can be configured to fit your application's needs. You can customize the min/max/default font size, step, storage key, and CSS variable name by calling the `configure` method.
117
+ ## Usage
78
118
 
79
- | Option | Description | Default Value |
80
- |--------------|---------------------------------------------------------------------------------------------------------|-----------------|
81
- | `minSize` | The minimum allowed font size in pixels. | `10` |
82
- | `maxSize` | The maximum allowed font size in pixels. | `22` |
83
- | `defaultSize`| The initial font size and the value used for resetting. | `14` |
84
- | `step` | The number of pixels to increase or decrease the font size by. | `2` |
85
- | `storageKey` | The key used to persist the font size in `localStorage`. | `'su:font-size'`|
86
- | `cssVarName` | The name of the CSS custom property that will be applied to the `<html>` element. | `'--base-font-size'`|
119
+ ### Custom Configuration
87
120
 
88
- **Example:**
121
+ Call `configure()` before `init()`:
89
122
 
90
123
  ```typescript
91
- this.fontService.configure({
92
- minSize: 12,
93
- maxSize: 24,
94
- defaultSize: 16,
95
- step: 2,
96
- storageKey: 'my-app-font-size',
97
- cssVarName: '--app-font-size'
98
- });
99
- ```
124
+ import { ApplicationConfig, inject, provideAppInitializer } from '@angular/core';
125
+ import { FontSizeService } from '@su-labs/font-size';
100
126
 
101
- ## Styling (CSS)
127
+ export const appConfig: ApplicationConfig = {
128
+ providers: [
129
+ provideAppInitializer(() => {
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();
140
+ }),
141
+ ],
142
+ };
143
+ ```
102
144
 
103
- The service applies the current font size to a CSS custom property (variable) on the `<html>` element. By default, this is `--base-font-size`.
145
+ ### Using the Size in Your Styles
104
146
 
105
- To use this feature in your application's CSS, you should use this variable to define your font size, for example, in your `styles.scss` or `styles.css`:
147
+ Set the variable on the root element and size everything else in `rem`, so the whole page scales:
106
148
 
107
149
  ```css
108
- :root {
109
- /* Define a fallback in case the service isn't initialized yet */
110
- --base-font-size: 14px;
150
+ html {
151
+ font-size: var(--base-font-size);
111
152
  }
112
153
 
113
- body {
114
- font-size: var(--base-font-size);
154
+ h1 {
155
+ font-size: 2rem;
156
+ }
157
+
158
+ small {
159
+ font-size: 0.875rem;
115
160
  }
116
161
  ```
117
162
 
118
- Or, if you configured a different name:
163
+ ## API Reference
119
164
 
120
- CSS
121
- ```css
122
- body {
123
- font-size: var(--app-font-size);
124
- }
165
+ ### Service (FontSizeService)
166
+
167
+ #### Signals
168
+
169
+ | Signal | Type | Description |
170
+ |--------|------|-------------|
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.
181
+
182
+ #### Methods
183
+
184
+ | Method | Parameters | Description |
185
+ |--------|------------|-------------|
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 |
192
+
193
+ ### Types
194
+
195
+ ```typescript
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
+ };
125
205
  ```
126
206
 
127
- This setup ensures that your font size is reactive, persistent, and easily configurable across your Angular app.
207
+ ## Configuration Options
208
+
209
+ | Option | Description | Default Value |
210
+ |--------|-------------|---------------|
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`.
220
+
221
+ ## Accessibility
222
+
223
+ This library helps meet WCAG 2.1 guidelines:
224
+
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
228
+
229
+ ### Best Practices
230
+
231
+ 1. **Use relative units** - Consider using `rem` instead of `px` for better scaling
232
+ 2. **Test at all sizes** - Ensure your layout works at all font size settings
233
+ 3. **Provide clear controls** - Make font size controls easy to find and use
234
+ 4. **Persist preference** - Always save user preference (enabled by default)
235
+ 5. **Respect system settings** - Consider reading system font size preferences
236
+
237
+ ## Browser Compatibility
238
+
239
+ Works in all modern browsers that support:
240
+ - CSS Custom Properties
241
+ - localStorage API
242
+ - Angular 21
243
+ - ES2022+
244
+
245
+ | Browser | Version |
246
+ |---------|---------|
247
+ | Chrome | ≥ 90 |
248
+ | Firefox | ≥ 88 |
249
+ | Safari | ≥ 14 |
250
+ | Edge | ≥ 90 |
251
+
252
+ ## Related Libraries
253
+
254
+ Part of the **@su-labs** suite:
255
+
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
260
+
261
+ ## Troubleshooting
262
+
263
+ ### Font size not persisting?
264
+
265
+ Make sure localStorage is enabled and not blocked by privacy settings.
266
+
267
+ ### CSS variables not updating?
268
+
269
+ Ensure you're using the correct variable name in your CSS (`--base-font-size` by default) and that you've called `init()`.
270
+
271
+ ### Layout breaking at larger sizes?
272
+
273
+ Test your responsive design at all font sizes. Use relative units and flexible layouts.
274
+
275
+ ### TypeScript errors?
276
+
277
+ Ensure you have Angular 21 and TypeScript 5.9+ installed.
278
+
279
+ ## Support
280
+
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)
128
284
 
129
285
  ## Contributing
130
286
 
131
- If you find any bugs or have feature requests, please open an issue or submit a pull request on our GitHub repository.
287
+ If you find any bugs or have feature requests, please open an issue or submit a pull request on our [**GitHub repository**](https://github.com/Greezaaa/settings-utils-lib.git).
132
288
 
133
- To contribute code, please ensure your changes include unit tests using **Vitest** to maintain code quality.
289
+ To contribute code, please ensure your changes include unit tests to maintain code quality. Please see the main repository's `README.md` for details on the monorepo structure.
134
290
 
135
291
  ## License
136
292
 
137
- This project is licensed under the MIT License. See the [LICENSE](https://github.com/Greezaaa/settings-utils-lib/blob/main/projects/su-labs/font-size/LICENSE) file for details.
293
+ This project is licensed under the MIT License. See the [**LICENSE**](https://github.com/Greezaaa/settings-utils-lib/blob/main/projects/su-labs/font-size/LICENSE) file for details.
@@ -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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C,MAAM,CAAC,GAAG,MAAM,GAAG,IAAI,CAAC,WAAW,EAAE;IAC9D;AAEA;;;;AAIG;AACK,IAAA,cAAc,CAAC,IAAY,EAAA;AACjC,QAAA,YAAY,CAAC,OAAO,CAAC,IAAI,CAAC,UAAU,EAAE,MAAM,CAAC,IAAI,CAAC,CAAC;IACrD;AAEA;;;;;AAKG;AACK,IAAA,WAAW,CAAC,IAAY,EAAA;AAC9B,QAAA,QAAQ,CAAC,eAAe,CAAC,KAAK,CAAC,WAAW,CAAC,IAAI,CAAC,UAAU,EAAE,CAAA,EAAG,IAAI,CAAA,EAAA,CAAI,CAAC;IAC1E;uGA/KW,eAAe,EAAA,IAAA,EAAA,EAAA,EAAA,MAAA,EAAA,EAAA,CAAA,eAAA,CAAA,UAAA,EAAA,CAAA;AAAf,IAAA,OAAA,KAAA,GAAA,EAAA,CAAA,qBAAA,CAAA,EAAA,UAAA,EAAA,QAAA,EAAA,OAAA,EAAA,QAAA,EAAA,QAAA,EAAA,EAAA,EAAA,IAAA,EAAA,eAAe,cADF,MAAM,EAAA,CAAA;;2FACnB,eAAe,EAAA,UAAA,EAAA,CAAA;kBAD3B,UAAU;mBAAC,EAAE,UAAU,EAAE,MAAM,EAAE;;;ACHlC;;AAEG;;ACFH;;AAEG;;;;"}
1
+ {"version":3,"file":"su-labs-font-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;;IAG5C,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC,aAAa,CAAC,IAAI,EAAA,IAAA,SAAA,GAAA,CAAA,EAAA,SAAA,EAAA,MAAA,EAAA,CAAA,8BAAA,EAAA,CAAA,CAAC;;AAGtC,IAAA,QAAQ,GAAG,MAAM,CAAS,IAAI,CAAC,UAAU,CAAC,QAAQ,CAAC,GAAG,EAAE,EAAA,IAAA,SAAA,GAAA,CAAA,EAAA,SAAA,EAAA,UAAA,EAAA,CAAA,8BAAA,EAAA,CAAA,CAAC;;AAGzD,IAAA,SAAS,GAAG,QAAQ,CAAC,MAAM,IAAI,CAAC,QAAQ,EAAE,KAAK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AAI,EAAE,CAAC,CAAC;IAC3D;AAEA;;;AAGG;AACH,IAAA,QAAQ,CAAC,IAAa,EAAA;AACpB,QAAA,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,QAAQ,EAAE,IAAI,IAAI,IAAI,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC;IAC3D;;IAGA,KAAK,GAAA;AACH,QAAA,IAAI,CAAC,UAAU,CAAC,KAAK,EAAE;IACzB;;IAGA,WAAW,GAAA;AACT,QAAA,IAAI,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC,WAAW,KAAK,WAAW,EAAE,CAAC;IAC5D;wGAzFW,eAAe,EAAA,IAAA,EAAA,EAAA,EAAA,MAAA,EAAA,EAAA,CAAA,eAAA,CAAA,UAAA,EAAA,CAAA;AAAf,IAAA,OAAA,KAAA,GAAA,EAAA,CAAA,qBAAA,CAAA,EAAA,UAAA,EAAA,QAAA,EAAA,OAAA,EAAA,SAAA,EAAA,QAAA,EAAA,EAAA,EAAA,IAAA,EAAA,eAAe,cADF,MAAM,EAAA,CAAA;;4FACnB,eAAe,EAAA,UAAA,EAAA,CAAA;kBAD3B,UAAU;mBAAC,EAAE,UAAU,EAAE,MAAM,EAAE;;;ACVlC;;AAEG;;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@su-labs/font-size",
3
- "version": "21.0.4",
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
  }