@su-labs/font-size 1.0.4 → 19.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md ADDED
@@ -0,0 +1,81 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project will be documented in this file.
4
+
5
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
+
8
+ ## [Unreleased]
9
+
10
+ ## [22.2.0] - 2026-11-07
11
+
12
+ ### Added
13
+ - `storage` option: where the size is saved (default: `localStorage`); pass `createSuCookieStorage({ domain })` from `@su-labs/core` to share it across subdomains
14
+
15
+ ### Changed
16
+ - Requires `@su-labs/core` 1.1.0 or later
17
+ - Package homepage now points to the website with a live demo
18
+
19
+ ## [22.1.0] - 2026-11-05
20
+
21
+ ### Changed
22
+ - Font size logic moved to the framework-agnostic `@su-labs/core/font-size`; `FontSizeService` is now a thin wrapper with the same API
23
+ - `FontSizeConfig` is now a type alias built from the core types (same fields)
24
+ - Change limits and step with `configure()`. Writing to the `minSize`, `maxSize`, `defaultSize` or `step` signals directly no longer affects clamping or `reset()`
25
+ - Added `@su-labs/core` as a dependency
26
+ - README links to the `@su-labs/core` installation guides for non-Angular projects
27
+
28
+ ### Fixed
29
+ - Safe to import during server-side rendering (no `localStorage` access without a browser)
30
+ - README now documents the actual API
31
+ - Repair table of contents links in README.md
32
+
33
+ ## [22.0.0] - 2026-11-04
34
+
35
+ ### Changed
36
+ - Upgrade to Angular 22 (peer dependencies now `^22.0.0`)
37
+ - Remove emojis from README.md
38
+
39
+ ## [21.0.5] - 2026-02-04
40
+
41
+ ### Changed
42
+ - Update README.md
43
+
44
+ ## [21.0.4] - 2026-02-03
45
+
46
+ ### Changed
47
+ - **BREAKING:** Updated to Angular 21 support. This version requires Angular 21.0.0 or higher.
48
+ - Updated peer dependencies to `@angular/common: ^21.0.0` and `@angular/core: ^21.0.0`.
49
+ - Aligned package version with Angular major version for clearer compatibility (v21.x.x = Angular 21 support).
50
+
51
+ ### Notes
52
+ - Projects using Angular 20 or below should continue using version 1.0.3.
53
+ - This release maintains full backward compatibility with the 1.x API - only the Angular version requirement has changed.
54
+
55
+
56
+ ## [1.0.4] - 2025-08-30
57
+
58
+ ### Fixed
59
+ - Ensured `"license": "MIT"` is correctly reflected in the published package metadata.
60
+
61
+ ## [1.0.3] - 2025-08-30
62
+
63
+ ### Note
64
+ - This version was published with incorrect package content and is deprecated. Please use `1.0.4`.
65
+
66
+ ## [1.0.2] - 2025-08-26
67
+
68
+ ### Changed
69
+ - Refactored project structure to a monorepo, separating `font-size` into its own distributable package.
70
+ - Updated documentation (`README.md`) with comprehensive installation, usage, and configuration guides.
71
+ - Improved `package.json` with standard fields: `keywords`, `author`, `license`, `repository`, `homepage`, and `bugs`.
72
+
73
+ ## [0.0.1] - 2025-08-26
74
+ ### Added
75
+ - Initial release of the `FontSizeService` library.
76
+ - `FontSizeService` with methods for increase, decrease, reset, and configure.
77
+ - `FontSizeConfig` interface for service configuration.
78
+ - Reactive `signals` (`fontSize`, `isDefault`, `isMax`, `isMin`).
79
+ - Persistence of font size in `localStorage`.
80
+ - Application of font size via CSS custom property.
81
+ - Unit tests with Vitest.
package/README.md CHANGED
@@ -1,21 +1,61 @@
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
58
+ ```sh
19
59
  npm install @su-labs/font-size
20
60
  ```
21
61
 
@@ -24,123 +64,228 @@ npm install @su-labs/font-size
24
64
  This library requires the following peer dependencies:
25
65
 
26
66
  ```sh
27
- npm install @angular/common@^20.1.0 @angular/core@^20.1.0
67
+ npm install @angular/common@^22 @angular/core@^22
28
68
  ```
29
69
 
30
- ## Usage
31
- ### Provide the service in your application
70
+ ## Quick Start
32
71
 
33
- You can provide the service in your main.ts (or wherever your ApplicationConfig is defined) and initialize it automatically:
72
+ 1. Initialize the service in `app.config.ts`:
34
73
 
35
74
  ```typescript
75
+ import { ApplicationConfig, inject, provideAppInitializer } from '@angular/core';
76
+ import { FontSizeService } from '@su-labs/font-size';
77
+
36
78
  export const appConfig: ApplicationConfig = {
37
- providers: [
38
- FontSizeService,
39
- provideAppInitializer(() => {
40
-
41
- const fontService = inject(FontSizeService);
42
- fontService.init(); // initializes font size from localStorage and applies CSS variable
43
- }),
44
- ],
79
+ providers: [
80
+ provideAppInitializer(() => {
81
+ inject(FontSizeService).init();
82
+ }),
83
+ ],
45
84
  };
46
85
  ```
47
- Using the service in components
48
86
 
49
- Inject the service into any component and access reactive signals:
87
+ 2. Add font size controls:
50
88
 
51
89
  ```typescript
52
- import { Component, effect } from '@angular/core';
90
+ import { Component, inject } from '@angular/core';
53
91
  import { FontSizeService } from '@su-labs/font-size';
54
92
 
55
93
  @Component({
56
- selector: 'app-example',
57
- template: `
58
- <div>
59
- <p>Current font size: {{ fontSize() }}</p>
60
- <button (click)="increase()">A+</button>
61
- <button (click)="decrease()">A-</button>
62
- <button (click)="reset()">Reset</button>
63
- </div>` ,
94
+ selector: 'app-font-controls',
95
+ template: `
96
+ <button type="button" (click)="fontSize.decrease()" [disabled]="fontSize.isMin()">A-</button>
97
+ <button type="button" (click)="fontSize.reset()" [disabled]="fontSize.isDefault()">A</button>
98
+ <button type="button" (click)="fontSize.increase()" [disabled]="fontSize.isMax()">A+</button>
99
+ <p>Current: {{ fontSize.fontSize() }}px</p>
100
+ `,
64
101
  })
102
+ export class FontControlsComponent {
103
+ protected readonly fontSize = inject(FontSizeService);
104
+ }
105
+ ```
65
106
 
66
- export class ExampleComponent {
67
- private fontService = inject(FontSizeService);
68
- fontSize = computed(() => this.fontService.fontSize());
69
-
70
- increase(step?: number) {
71
- this.fontService.increase(step);
72
- }
73
-
74
- decrease(step?: number) {
75
- this.fontService.decrease(step);
76
- }
107
+ 3. Use the CSS variable in your styles:
77
108
 
78
- reset() {
79
- this.fontService.reset();
80
- }
109
+ ```css
110
+ html {
111
+ font-size: var(--base-font-size);
81
112
  }
82
113
  ```
83
114
 
84
- ### Optional configuration
85
-
86
- 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.
115
+ ## Usage
87
116
 
88
- | Option | Description | Default Value |
89
- |--------------|---------------------------------------------------------------------------------------------------------|-----------------|
90
- | `minSize` | The minimum allowed font size in pixels. | `10` |
91
- | `maxSize` | The maximum allowed font size in pixels. | `22` |
92
- | `defaultSize`| The initial font size and the value used for resetting. | `14` |
93
- | `step` | The number of pixels to increase or decrease the font size by. | `2` |
94
- | `storageKey` | The key used to persist the font size in `localStorage`. | `'su:font-size'`|
95
- | `cssVarName` | The name of the CSS custom property that will be applied to the `<html>` element. | `'--base-font-size'`|
117
+ ### Custom Configuration
96
118
 
97
- **Example:**
119
+ Call `configure()` before `init()`:
98
120
 
99
121
  ```typescript
100
- this.fontService.configure({
101
- minSize: 12,
102
- maxSize: 24,
103
- defaultSize: 16,
104
- step: 2,
105
- storageKey: 'my-app-font-size',
106
- cssVarName: '--app-font-size'
107
- });
108
- ```
122
+ import { ApplicationConfig, inject, provideAppInitializer } from '@angular/core';
123
+ import { FontSizeService } from '@su-labs/font-size';
109
124
 
110
- ## Styling (CSS)
125
+ export const appConfig: ApplicationConfig = {
126
+ providers: [
127
+ provideAppInitializer(() => {
128
+ const fontSize = inject(FontSizeService);
129
+ fontSize.configure({
130
+ defaultSize: 16,
131
+ minSize: 12,
132
+ maxSize: 24,
133
+ step: 2,
134
+ storageKey: 'myApp:fontSize',
135
+ cssVarName: '--app-font-size',
136
+ });
137
+ fontSize.init();
138
+ }),
139
+ ],
140
+ };
141
+ ```
111
142
 
112
- The service applies the current font size to a CSS custom property (variable) on the `<html>` element. By default, this is `--base-font-size`.
143
+ ### Using the Size in Your Styles
113
144
 
114
- 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`:
145
+ Set the variable on the root element and size everything else in `rem`, so the whole page scales:
115
146
 
116
147
  ```css
117
- :root {
118
- /* Define a fallback in case the service isn't initialized yet */
119
- --base-font-size: 14px;
148
+ html {
149
+ font-size: var(--base-font-size);
120
150
  }
121
151
 
122
- body {
123
- font-size: var(--base-font-size);
152
+ h1 {
153
+ font-size: 2rem;
154
+ }
155
+
156
+ small {
157
+ font-size: 0.875rem;
124
158
  }
125
159
  ```
126
160
 
127
- Or, if you configured a different name:
161
+ ## API Reference
128
162
 
129
- CSS
130
- ```css
131
- body {
132
- font-size: var(--app-font-size);
133
- }
163
+ ### Service (FontSizeService)
164
+
165
+ #### Signals
166
+
167
+ | Signal | Type | Description |
168
+ |--------|------|-------------|
169
+ | `fontSize()` | `number` | Current font size in pixels |
170
+ | `defaultSize()` | `number` | Default size |
171
+ | `minSize()` | `number` | Minimum size |
172
+ | `maxSize()` | `number` | Maximum size |
173
+ | `step()` | `number` | Step used by `increase()` / `decrease()` |
174
+ | `isDefault()` | `boolean` | True when the size equals the default |
175
+ | `isMin()` | `boolean` | True when the size equals the minimum |
176
+ | `isMax()` | `boolean` | True when the size equals the maximum |
177
+
178
+ Change the limits and step with `configure()`, not by writing to their signals.
179
+
180
+ #### Methods
181
+
182
+ | Method | Parameters | Description |
183
+ |--------|------------|-------------|
184
+ | `configure(config?)` | `Partial<FontSizeConfig>` | Update limits, step, storage key or CSS variable name. Omitted values keep their current setting. |
185
+ | `init()` | - | Load the saved size (or the default) and apply it. Call once at startup. |
186
+ | `setFontSize(size)` | `number` | Set, apply and save a size (clamped to the limits) |
187
+ | `increase(step?)` | `number` | Increase by `step` (defaults to the configured step) |
188
+ | `decrease(step?)` | `number` | Decrease by `step` (defaults to the configured step) |
189
+ | `reset()` | - | Return to the default size and remove the saved value |
190
+
191
+ ### Types
192
+
193
+ ```typescript
194
+ type FontSizeConfig = {
195
+ defaultSize: number;
196
+ minSize: number;
197
+ maxSize: number;
198
+ step: number;
199
+ storageKey?: string;
200
+ storage?: SuStorage; // Default: localStorage
201
+ cssVarName?: string;
202
+ };
134
203
  ```
135
204
 
136
- This setup ensures that your font size is reactive, persistent, and easily configurable across your Angular app.
205
+ ## Configuration Options
206
+
207
+ | Option | Description | Default Value |
208
+ |--------|-------------|---------------|
209
+ | `defaultSize` | Size used before the user picks one, and after `reset()` | `14` |
210
+ | `minSize` | Smallest allowed size | `10` |
211
+ | `maxSize` | Largest allowed size | `22` |
212
+ | `step` | Pixels added or removed by `increase()` / `decrease()` | `2` |
213
+ | `storageKey` | The key used to persist the size | `'su:font-size'` |
214
+ | `storage` | Where the size is saved. Use `createSuCookieStorage({ domain })` from `@su-labs/core` to share it across subdomains | `localStorage` |
215
+ | `cssVarName` | CSS custom property set on `<html>` | `'--base-font-size'` |
216
+
217
+ 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`.
218
+
219
+ ## Accessibility
220
+
221
+ This library helps meet WCAG 2.1 guidelines:
222
+
223
+ - **Success Criterion 1.4.4** - Text can be resized up to 200% without loss of content or functionality
224
+ - **Success Criterion 1.4.8** - User can select foreground and background colors (when combined with theme management)
225
+ - **Success Criterion 1.4.12** - Text spacing is adjustable
226
+
227
+ ### Best Practices
228
+
229
+ 1. **Use relative units** - Consider using `rem` instead of `px` for better scaling
230
+ 2. **Test at all sizes** - Ensure your layout works at all font size settings
231
+ 3. **Provide clear controls** - Make font size controls easy to find and use
232
+ 4. **Persist preference** - Always save user preference (enabled by default)
233
+ 5. **Respect system settings** - Consider reading system font size preferences
234
+
235
+ ## Browser Compatibility
236
+
237
+ Works in all modern browsers that support:
238
+ - CSS Custom Properties
239
+ - localStorage API
240
+ - Angular 22+
241
+ - ES2022+
242
+
243
+ | Browser | Version |
244
+ |---------|---------|
245
+ | Chrome | ≥ 90 |
246
+ | Firefox | ≥ 88 |
247
+ | Safari | ≥ 14 |
248
+ | Edge | ≥ 90 |
249
+
250
+ ## Related Libraries
251
+
252
+ Part of the **@su-labs** suite:
253
+
254
+ - [@su-labs/visit-tracker](https://www.npmjs.com/package/@su-labs/visit-tracker) - User visit tracking
255
+ - [@su-labs/theme](https://www.npmjs.com/package/@su-labs/theme) - Theme management with dark mode support
256
+ - [@su-labs/notifications](https://www.npmjs.com/package/@su-labs/notifications) - Toast notification system
257
+ - [@su-labs/scroll-spy](https://www.npmjs.com/package/@su-labs/scroll-spy) - Scroll position tracking
258
+
259
+ ## Troubleshooting
260
+
261
+ ### Font size not persisting?
262
+
263
+ Make sure localStorage is enabled and not blocked by privacy settings.
264
+
265
+ ### CSS variables not updating?
266
+
267
+ Ensure you're using the correct variable name in your CSS (`--base-font-size` by default) and that you've called `init()`.
268
+
269
+ ### Layout breaking at larger sizes?
270
+
271
+ Test your responsive design at all font sizes. Use relative units and flexible layouts.
272
+
273
+ ### TypeScript errors?
274
+
275
+ Ensure you have Angular 22+ and TypeScript 6.0+ installed.
276
+
277
+ ## Support
278
+
279
+ - Found a bug? [Open an issue](https://github.com/Greezaaa/settings-utils-lib/issues)
280
+ - Have a feature request? [Start a discussion](https://github.com/Greezaaa/settings-utils-lib/discussions)
281
+ - Like this library? [Give it a star!](https://github.com/Greezaaa/settings-utils-lib)
137
282
 
138
283
  ## Contributing
139
284
 
140
- If you find any bugs or have feature requests, please open an issue or submit a pull request on our GitHub repository.
285
+ 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).
141
286
 
142
- To contribute code, please ensure your changes include unit tests using **Vitest** to maintain code quality.
287
+ 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.
143
288
 
144
289
  ## License
145
290
 
146
- 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.
291
+ 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);
17
+ /** Minimum font size in pixels. Change it with {@link configure}. */
18
+ minSize = signal(this.initialLimits.minSize);
19
+ /** Maximum font size in pixels. Change it with {@link configure}. */
20
+ maxSize = signal(this.initialLimits.maxSize);
21
+ /** Default step in pixels for {@link increase} / {@link decrease}. Change it with {@link configure}. */
22
+ step = signal(this.initialLimits.step);
23
+ /** Current font size in pixels */
24
+ fontSize = signal(this.controller.fontSize.get());
25
+ /** True if the current size equals the default size */
26
+ isDefault = computed(() => this.fontSize() === this.defaultSize());
27
+ /** True if the current size equals the maximum size */
28
+ isMax = computed(() => this.fontSize() === this.maxSize());
29
+ /** True if the current size equals the minimum size */
30
+ isMin = computed(() => this.fontSize() === this.minSize());
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: "20.1.7", ngImport: i0, type: FontSizeService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
168
- static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "20.1.7", ngImport: i0, type: FontSizeService, providedIn: 'root' });
84
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.25", ngImport: i0, type: FontSizeService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
85
+ static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "19.2.25", ngImport: i0, type: FontSizeService, providedIn: 'root' });
169
86
  }
170
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.1.7", ngImport: i0, type: FontSizeService, decorators: [{
87
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.25", 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;YAAE,IAAI,CAAC,OAAO,CAAC,GAA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CAAC,GAAG,CAAC,IAAI,EAAE,IAAI,CAAC,OAAO,EAAE,CAAC,EAAE,IAAI,CAAC,OAAO,EAAE,CAAC;;AAGjE;;;;;AAKG;IACK,eAAe,GAAA;QACrB,MAAM,MAAM,GAAG,YAAY,CAAC,OAAO,CAAC,IAAI,CAAC,UAAU,CAAC;AACpD,QAAA,MAAM,MAAM,GAAG,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC,GAAG,IAAI,CAAC,WAAW,EAAE;AAC3D,QAAA,OAAO,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,GAAG,MAAM,GAAG,IAAI,CAAC,WAAW,EAAE;;AAG9D;;;;AAIG;AACK,IAAA,cAAc,CAAC,IAAY,EAAA;AACjC,QAAA,YAAY,CAAC,OAAO,CAAC,IAAI,CAAC,UAAU,EAAE,MAAM,CAAC,IAAI,CAAC,CAAC;;AAGrD;;;;;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;;uGA9K/D,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-19/build/font-size/src/lib/font-size.service.ts","../../../../compat/angular-19/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,CAAC;;IAGpD,OAAO,GAAG,MAAM,CAAC,IAAI,CAAC,aAAa,CAAC,OAAO,CAAC;;IAG5C,OAAO,GAAG,MAAM,CAAC,IAAI,CAAC,aAAa,CAAC,OAAO,CAAC;;IAG5C,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC;;AAGtC,IAAA,QAAQ,GAAG,MAAM,CAAS,IAAI,CAAC,UAAU,CAAC,QAAQ,CAAC,GAAG,EAAE,CAAC;;AAGzD,IAAA,SAAS,GAAG,QAAQ,CAAC,MAAM,IAAI,CAAC,QAAQ,EAAE,KAAK,IAAI,CAAC,WAAW,EAAE,CAAC;;AAGlE,IAAA,KAAK,GAAG,QAAQ,CAAC,MAAM,IAAI,CAAC,QAAQ,E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AC,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/index.d.ts CHANGED
@@ -1,128 +1,5 @@
1
- import * as _angular_core from '@angular/core';
2
-
3
- interface FontSizeConfig {
4
- defaultSize: number;
5
- minSize: number;
6
- maxSize: number;
7
- step: number;
8
- storageKey?: string;
9
- cssVarName?: string;
10
- }
11
-
12
- declare class FontSizeService {
13
- /**
14
- * Default font size in pixels.
15
- * Can be overridden via {@link configure}.
16
- */
17
- defaultSize: _angular_core.WritableSignal<number>;
18
- /**
19
- * Minimum allowed font size in pixels.
20
- * Can be overridden via {@link configure}.
21
- */
22
- minSize: _angular_core.WritableSignal<number>;
23
- /**
24
- * Maximum allowed font size in pixels.
25
- * Can be overridden via {@link configure}.
26
- */
27
- 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
- */
32
- 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
- */
46
- fontSize: _angular_core.WritableSignal<number>;
47
- /**
48
- * True if current font size equals the default size.
49
- */
50
- isDefault: _angular_core.Signal<boolean>;
51
- /**
52
- * True if current font size equals the maximum size.
53
- */
54
- isMax: _angular_core.Signal<boolean>;
55
- /**
56
- * True if current font size equals the minimum size.
57
- */
58
- isMin: _angular_core.Signal<boolean>;
59
- /**
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).
64
- */
65
- configure(cfg?: Partial<FontSizeConfig>): void;
66
- /**
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.
71
- */
72
- init(): void;
73
- /**
74
- * Sets the font size to a specific value (clamped within min/max).
75
- *
76
- * @param size Desired font size in pixels.
77
- */
78
- setFontSize(size: number): void;
79
- /**
80
- * Increases the font size.
81
- *
82
- * @param step Optional custom step (pixels). Falls back to configured {@link step} if omitted.
83
- */
84
- increase(step?: number): void;
85
- /**
86
- * Decreases the font size.
87
- *
88
- * @param step Optional custom step (pixels). Falls back to configured {@link step} if omitted.
89
- */
90
- decrease(step?: number): void;
91
- /**
92
- * Resets the font size to the configured {@link defaultSize}.
93
- * Also removes the persisted value from localStorage.
94
- */
95
- 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;
123
- static ɵfac: _angular_core.ɵɵFactoryDeclaration<FontSizeService, never>;
124
- static ɵprov: _angular_core.ɵɵInjectableDeclaration<FontSizeService>;
125
- }
126
-
127
- export { FontSizeService };
128
- export type { FontSizeConfig };
1
+ /**
2
+ * Generated bundle index. Do not edit.
3
+ */
4
+ /// <amd-module name="@su-labs/font-size" />
5
+ export * from './public-api';
@@ -0,0 +1,3 @@
1
+ import { SuFontSizeConfig, SuFontSizeLimits } from '@su-labs/core/font-size';
2
+ /** Font size configuration: limits and step in pixels, plus optional storage, storage key and CSS variable name */
3
+ export type FontSizeConfig = SuFontSizeLimits & Pick<SuFontSizeConfig, 'storage' | 'storageKey' | 'cssVarName'>;
@@ -0,0 +1,63 @@
1
+ import { OnDestroy } from '@angular/core';
2
+ import { FontSizeConfig } from './font-size-config.interface';
3
+ import * as i0 from "@angular/core";
4
+ /**
5
+ * Angular service for managing the font size.
6
+ *
7
+ * Thin wrapper around the framework-agnostic `SuFontSizeController` from
8
+ * `@su-labs/core/font-size` that exposes the size and limits as Angular signals.
9
+ */
10
+ export declare class FontSizeService implements OnDestroy {
11
+ /** Framework-agnostic font size logic */
12
+ private readonly controller;
13
+ private readonly initialLimits;
14
+ /** Default font size in pixels. Change it with {@link configure}. */
15
+ defaultSize: import("@angular/core").WritableSignal<number>;
16
+ /** Minimum font size in pixels. Change it with {@link configure}. */
17
+ minSize: import("@angular/core").WritableSignal<number>;
18
+ /** Maximum font size in pixels. Change it with {@link configure}. */
19
+ maxSize: import("@angular/core").WritableSignal<number>;
20
+ /** Default step in pixels for {@link increase} / {@link decrease}. Change it with {@link configure}. */
21
+ step: import("@angular/core").WritableSignal<number>;
22
+ /** Current font size in pixels */
23
+ fontSize: import("@angular/core").WritableSignal<number>;
24
+ /** True if the current size equals the default size */
25
+ isDefault: import("@angular/core").Signal<boolean>;
26
+ /** True if the current size equals the maximum size */
27
+ isMax: import("@angular/core").Signal<boolean>;
28
+ /** True if the current size equals the minimum size */
29
+ isMin: import("@angular/core").Signal<boolean>;
30
+ /** Stop syncing the controller's stores into the signals */
31
+ private readonly unsubscribers;
32
+ /**
33
+ * Update the configuration. Omitted values keep their current setting.
34
+ * @param cfg Partial configuration (limits, step, storage key, CSS variable name).
35
+ */
36
+ configure(cfg?: Partial<FontSizeConfig>): void;
37
+ /**
38
+ * Load the saved size (or the default), clamp it and apply it to the document.
39
+ * Call once at application startup, after {@link configure}.
40
+ */
41
+ init(): void;
42
+ /**
43
+ * Set, apply and persist a font size, clamped to the allowed range.
44
+ * @param size Desired font size in pixels.
45
+ */
46
+ setFontSize(size: number): void;
47
+ /**
48
+ * Increase the font size.
49
+ * @param step Pixels to add. Defaults to {@link step}.
50
+ */
51
+ increase(step?: number): void;
52
+ /**
53
+ * Decrease the font size.
54
+ * @param step Pixels to remove. Defaults to {@link step}.
55
+ */
56
+ decrease(step?: number): void;
57
+ /** Return to the default size and remove the saved value from localStorage */
58
+ reset(): void;
59
+ /** Angular lifecycle hook for service destruction */
60
+ ngOnDestroy(): void;
61
+ static ɵfac: i0.ɵɵFactoryDeclaration<FontSizeService, never>;
62
+ static ɵprov: i0.ɵɵInjectableDeclaration<FontSizeService>;
63
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@su-labs/font-size",
3
- "version": "1.0.4",
3
+ "version": "19.2.0",
4
4
  "description": "A lightweight Angular service for dynamic font size management.",
5
5
  "keywords": [
6
6
  "angular",
@@ -18,17 +18,18 @@
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",
25
25
  "url": "https://github.com/Greezaaa"
26
26
  },
27
27
  "peerDependencies": {
28
- "@angular/common": "^20.1.0",
29
- "@angular/core": "^20.1.0"
28
+ "@angular/common": "^19.0.0",
29
+ "@angular/core": "^19.0.0"
30
30
  },
31
31
  "dependencies": {
32
+ "@su-labs/core": "^1.1.0",
32
33
  "tslib": "^2.3.0"
33
34
  },
34
35
  "repository": {
@@ -0,0 +1,2 @@
1
+ export * from './lib/font-size.service';
2
+ export * from './lib/font-size-config.interface';