@su-labs/font-size 21.0.5 → 21.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +41 -0
- package/README.md +131 -166
- package/fesm2022/su-labs-font-size.mjs +57 -144
- package/fesm2022/su-labs-font-size.mjs.map +1 -1
- package/package.json +5 -3
- package/types/su-labs-font-size.d.ts +36 -94
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.2] - 2026-11-17
|
|
11
|
+
|
|
12
|
+
### Changed
|
|
13
|
+
- Uses `@su-labs/core` 1.10.0 (was 1.9.0), the same version as every other `@su-labs` package, so apps using several of them install core once
|
|
14
|
+
|
|
15
|
+
## [22.2.1] - 2026-11-16
|
|
16
|
+
|
|
17
|
+
### Changed
|
|
18
|
+
- 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
|
|
19
|
+
|
|
20
|
+
## [22.2.0] - 2026-11-07
|
|
21
|
+
|
|
22
|
+
### Added
|
|
23
|
+
- `storage` option: where the size is saved (default: `localStorage`); pass `createSuCookieStorage({ domain })` from `@su-labs/core` to share it across subdomains
|
|
24
|
+
|
|
25
|
+
### Changed
|
|
26
|
+
- Requires `@su-labs/core` 1.1.0 or later
|
|
27
|
+
- Package homepage now points to the website with a live demo
|
|
28
|
+
|
|
29
|
+
## [22.1.0] - 2026-11-05
|
|
30
|
+
|
|
31
|
+
### Changed
|
|
32
|
+
- Font size logic moved to the framework-agnostic `@su-labs/core/font-size`; `FontSizeService` is now a thin wrapper with the same API
|
|
33
|
+
- `FontSizeConfig` is now a type alias built from the core types (same fields)
|
|
34
|
+
- Change limits and step with `configure()`. Writing to the `minSize`, `maxSize`, `defaultSize` or `step` signals directly no longer affects clamping or `reset()`
|
|
35
|
+
- Added `@su-labs/core` as a dependency
|
|
36
|
+
- README links to the `@su-labs/core` installation guides for non-Angular projects
|
|
37
|
+
|
|
38
|
+
### Fixed
|
|
39
|
+
- Safe to import during server-side rendering (no `localStorage` access without a browser)
|
|
40
|
+
- README now documents the actual API
|
|
41
|
+
- Repair table of contents links in README.md
|
|
42
|
+
|
|
43
|
+
## [22.0.0] - 2026-11-04
|
|
44
|
+
|
|
45
|
+
### Changed
|
|
46
|
+
- Upgrade to Angular 22 (peer dependencies now `^22.0.0`)
|
|
47
|
+
- Remove emojis from README.md
|
|
48
|
+
|
|
8
49
|
## [21.0.5] - 2026-02-04
|
|
9
50
|
|
|
10
51
|
### Changed
|
package/README.md
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
`@su-labs/font-size`
|
|
4
4
|
|
|
5
5
|

|
|
6
|
-

|
|
7
7
|

|
|
8
8
|

|
|
9
9
|

|
|
@@ -13,52 +13,54 @@
|
|
|
13
13
|
|
|
14
14
|
An accessible Angular service for managing font size preferences. Provides reactive controls for text scaling, user preference persistence, and WCAG-compliant font size management.
|
|
15
15
|
|
|
16
|
-
|
|
16
|
+
> **Not using Angular?** The same font size controls are available for React, Vue, Svelte and vanilla JavaScript in [`@su-labs/core`](https://www.npmjs.com/package/@su-labs/core). See the [installation guides](https://github.com/Greezaaa/settings-utils-lib/blob/main/docs/README.md).
|
|
17
17
|
|
|
18
|
-
|
|
18
|
+
## Table of Contents
|
|
19
|
+
|
|
20
|
+
- [Why Use This Library?](#why-use-this-library)
|
|
19
21
|
- [Features](#features)
|
|
20
22
|
- [Installation](#installation)
|
|
21
|
-
- [Quick Start](
|
|
23
|
+
- [Quick Start](#quick-start)
|
|
22
24
|
- [Usage](#usage)
|
|
23
|
-
- [API Reference](
|
|
25
|
+
- [API Reference](#api-reference)
|
|
24
26
|
- [Configuration Options](#configuration-options)
|
|
25
27
|
- [Accessibility](#accessibility)
|
|
26
|
-
- [Browser Compatibility](
|
|
27
|
-
- [Related Libraries](
|
|
28
|
-
- [Troubleshooting](
|
|
29
|
-
- [Support](
|
|
28
|
+
- [Browser Compatibility](#browser-compatibility)
|
|
29
|
+
- [Related Libraries](#related-libraries)
|
|
30
|
+
- [Troubleshooting](#troubleshooting)
|
|
31
|
+
- [Support](#support)
|
|
30
32
|
- [Contributing](#contributing)
|
|
31
33
|
- [License](#license)
|
|
32
34
|
|
|
33
|
-
##
|
|
35
|
+
## Why Use This Library?
|
|
34
36
|
|
|
35
|
-
-
|
|
36
|
-
-
|
|
37
|
-
-
|
|
38
|
-
-
|
|
39
|
-
-
|
|
40
|
-
-
|
|
41
|
-
-
|
|
42
|
-
-
|
|
43
|
-
- 📝 **Well Documented** - Clear examples and API docs
|
|
37
|
+
- **Lightweight** - Minimal bundle size
|
|
38
|
+
- **Reactive** - Built with Angular Signals
|
|
39
|
+
- **Accessible** - Helps meet WCAG 2.1 text resizing guidelines
|
|
40
|
+
- **Persistent** - Remembers user preference
|
|
41
|
+
- **CSS Variables** - Modern implementation
|
|
42
|
+
- **SSR Safe** - No browser APIs are touched on the server
|
|
43
|
+
- **Type-Safe** - Full TypeScript support
|
|
44
|
+
- **Well Tested** - Comprehensive test coverage
|
|
44
45
|
|
|
45
46
|
## Features
|
|
46
47
|
|
|
47
|
-
* **Reactive State**:
|
|
48
|
-
* **
|
|
49
|
-
* **
|
|
50
|
-
* **CSS
|
|
51
|
-
* **
|
|
52
|
-
* **Configurable**: Customizable storage keys, CSS variable names, and size scales.
|
|
48
|
+
* **Reactive State**: The size, limits and `isDefault` / `isMin` / `isMax` flags are Angular signals.
|
|
49
|
+
* **Bounded**: The size always stays between the configured minimum and maximum.
|
|
50
|
+
* **Persistence**: Remembers the user's font size in `localStorage`.
|
|
51
|
+
* **CSS Variable**: Applies the size in pixels to a CSS custom property on `<html>`.
|
|
52
|
+
* **Configurable**: Customizable limits, step, storage key and CSS variable name.
|
|
53
53
|
|
|
54
54
|
## Installation
|
|
55
55
|
|
|
56
56
|
You can install this library via npm:
|
|
57
57
|
|
|
58
58
|
```sh
|
|
59
|
-
npm install @su-labs/font-size
|
|
59
|
+
npm install @su-labs/font-size@ng21
|
|
60
60
|
```
|
|
61
61
|
|
|
62
|
+
This is the Angular 21 version. For the newest Angular, install `@su-labs/font-size` without a tag.
|
|
63
|
+
|
|
62
64
|
## Peer Dependencies
|
|
63
65
|
|
|
64
66
|
This library requires the following peer dependencies:
|
|
@@ -67,199 +69,162 @@ This library requires the following peer dependencies:
|
|
|
67
69
|
npm install @angular/common@^21 @angular/core@^21
|
|
68
70
|
```
|
|
69
71
|
|
|
70
|
-
##
|
|
72
|
+
## Quick Start
|
|
71
73
|
|
|
72
|
-
|
|
73
|
-
// 1. Install
|
|
74
|
-
npm install @su-labs/font-size
|
|
74
|
+
1. Initialize the service in `app.config.ts`:
|
|
75
75
|
|
|
76
|
-
|
|
77
|
-
import {
|
|
78
|
-
import {
|
|
76
|
+
```typescript
|
|
77
|
+
import { ApplicationConfig, inject, provideAppInitializer } from '@angular/core';
|
|
78
|
+
import { FontSizeService } from '@su-labs/font-size';
|
|
79
79
|
|
|
80
|
-
export const appConfig = {
|
|
80
|
+
export const appConfig: ApplicationConfig = {
|
|
81
81
|
providers: [
|
|
82
82
|
provideAppInitializer(() => {
|
|
83
|
-
inject(
|
|
83
|
+
inject(FontSizeService).init();
|
|
84
84
|
}),
|
|
85
85
|
],
|
|
86
86
|
};
|
|
87
|
-
|
|
88
|
-
// 3. Create font size controls
|
|
89
|
-
import { Component, inject } from '@angular/core';
|
|
90
|
-
import { SuFontSizeService } from '@su-labs/font-size';
|
|
91
|
-
|
|
92
|
-
@Component({
|
|
93
|
-
template: `
|
|
94
|
-
<button (click)="fontService.setSize('small')">A-</button>
|
|
95
|
-
<button (click)="fontService.setSize('normal')">A</button>
|
|
96
|
-
<button (click)="fontService.setSize('large')">A+</button>
|
|
97
|
-
<p>Current: {{ fontService.size() }}</p>
|
|
98
|
-
`
|
|
99
|
-
})
|
|
100
|
-
export class AppComponent {
|
|
101
|
-
fontService = inject(SuFontSizeService);
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
// 4. Use CSS variables in your styles
|
|
105
|
-
body {
|
|
106
|
-
font-size: var(--su-font-size-base);
|
|
107
|
-
}
|
|
108
87
|
```
|
|
109
88
|
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
### Example 1: Basic Font Size Controls
|
|
89
|
+
2. Add font size controls:
|
|
113
90
|
|
|
114
91
|
```typescript
|
|
115
92
|
import { Component, inject } from '@angular/core';
|
|
116
|
-
import {
|
|
93
|
+
import { FontSizeService } from '@su-labs/font-size';
|
|
117
94
|
|
|
118
95
|
@Component({
|
|
119
96
|
selector: 'app-font-controls',
|
|
120
|
-
standalone: true,
|
|
121
97
|
template: `
|
|
122
|
-
<
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
<button
|
|
127
|
-
(click)="setFontSize(size)"
|
|
128
|
-
[class.active]="fontService.size() === size"
|
|
129
|
-
>
|
|
130
|
-
{{ size | titlecase }}
|
|
131
|
-
</button>
|
|
132
|
-
}
|
|
133
|
-
</div>
|
|
134
|
-
<p>Current size: {{ fontService.size() }}</p>
|
|
135
|
-
</div>
|
|
98
|
+
<button type="button" (click)="fontSize.decrease()" [disabled]="fontSize.isMin()">A-</button>
|
|
99
|
+
<button type="button" (click)="fontSize.reset()" [disabled]="fontSize.isDefault()">A</button>
|
|
100
|
+
<button type="button" (click)="fontSize.increase()" [disabled]="fontSize.isMax()">A+</button>
|
|
101
|
+
<p>Current: {{ fontSize.fontSize() }}px</p>
|
|
136
102
|
`,
|
|
137
|
-
styles: [`
|
|
138
|
-
.button-group button.active {
|
|
139
|
-
background-color: var(--su-theme-primary);
|
|
140
|
-
color: white;
|
|
141
|
-
}
|
|
142
|
-
`]
|
|
143
103
|
})
|
|
144
104
|
export class FontControlsComponent {
|
|
145
|
-
|
|
146
|
-
|
|
105
|
+
protected readonly fontSize = inject(FontSizeService);
|
|
106
|
+
}
|
|
107
|
+
```
|
|
147
108
|
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
109
|
+
3. Use the CSS variable in your styles:
|
|
110
|
+
|
|
111
|
+
```css
|
|
112
|
+
html {
|
|
113
|
+
font-size: var(--base-font-size);
|
|
151
114
|
}
|
|
152
115
|
```
|
|
153
116
|
|
|
154
|
-
|
|
117
|
+
## Usage
|
|
118
|
+
|
|
119
|
+
### Custom Configuration
|
|
120
|
+
|
|
121
|
+
Call `configure()` before `init()`:
|
|
155
122
|
|
|
156
123
|
```typescript
|
|
157
|
-
import {
|
|
158
|
-
import {
|
|
159
|
-
|
|
160
|
-
const fontConfig: SuFontSizeConfig = {
|
|
161
|
-
defaultSize: 'normal',
|
|
162
|
-
storageKey: 'myApp:fontSize',
|
|
163
|
-
cssVarPrefix: '--app-font-',
|
|
164
|
-
sizes: {
|
|
165
|
-
small: '14px',
|
|
166
|
-
normal: '16px',
|
|
167
|
-
large: '18px',
|
|
168
|
-
'x-large': '20px'
|
|
169
|
-
}
|
|
170
|
-
};
|
|
124
|
+
import { ApplicationConfig, inject, provideAppInitializer } from '@angular/core';
|
|
125
|
+
import { FontSizeService } from '@su-labs/font-size';
|
|
171
126
|
|
|
172
|
-
export const appConfig = {
|
|
127
|
+
export const appConfig: ApplicationConfig = {
|
|
173
128
|
providers: [
|
|
174
129
|
provideAppInitializer(() => {
|
|
175
|
-
inject(
|
|
130
|
+
const fontSize = inject(FontSizeService);
|
|
131
|
+
fontSize.configure({
|
|
132
|
+
defaultSize: 16,
|
|
133
|
+
minSize: 12,
|
|
134
|
+
maxSize: 24,
|
|
135
|
+
step: 2,
|
|
136
|
+
storageKey: 'myApp:fontSize',
|
|
137
|
+
cssVarName: '--app-font-size',
|
|
138
|
+
});
|
|
139
|
+
fontSize.init();
|
|
176
140
|
}),
|
|
177
141
|
],
|
|
178
142
|
};
|
|
179
143
|
```
|
|
180
144
|
|
|
181
|
-
###
|
|
145
|
+
### Using the Size in Your Styles
|
|
182
146
|
|
|
183
|
-
|
|
184
|
-
/* Global styles.css */
|
|
185
|
-
:root {
|
|
186
|
-
--su-font-size-base: 16px;
|
|
187
|
-
--su-font-size-small: 14px;
|
|
188
|
-
--su-font-size-large: 18px;
|
|
189
|
-
}
|
|
147
|
+
Set the variable on the root element and size everything else in `rem`, so the whole page scales:
|
|
190
148
|
|
|
191
|
-
|
|
192
|
-
|
|
149
|
+
```css
|
|
150
|
+
html {
|
|
151
|
+
font-size: var(--base-font-size);
|
|
193
152
|
}
|
|
194
153
|
|
|
195
154
|
h1 {
|
|
196
|
-
font-size:
|
|
155
|
+
font-size: 2rem;
|
|
197
156
|
}
|
|
198
157
|
|
|
199
|
-
|
|
200
|
-
font-size:
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
.small-text {
|
|
204
|
-
font-size: var(--su-font-size-small);
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
.large-text {
|
|
208
|
-
font-size: var(--su-font-size-large);
|
|
158
|
+
small {
|
|
159
|
+
font-size: 0.875rem;
|
|
209
160
|
}
|
|
210
161
|
```
|
|
211
162
|
|
|
212
|
-
##
|
|
163
|
+
## API Reference
|
|
213
164
|
|
|
214
|
-
### Service (
|
|
165
|
+
### Service (FontSizeService)
|
|
215
166
|
|
|
216
167
|
#### Signals
|
|
217
168
|
|
|
218
169
|
| Signal | Type | Description |
|
|
219
170
|
|--------|------|-------------|
|
|
220
|
-
| `
|
|
171
|
+
| `fontSize()` | `number` | Current font size in pixels |
|
|
172
|
+
| `defaultSize()` | `number` | Default size |
|
|
173
|
+
| `minSize()` | `number` | Minimum size |
|
|
174
|
+
| `maxSize()` | `number` | Maximum size |
|
|
175
|
+
| `step()` | `number` | Step used by `increase()` / `decrease()` |
|
|
176
|
+
| `isDefault()` | `boolean` | True when the size equals the default |
|
|
177
|
+
| `isMin()` | `boolean` | True when the size equals the minimum |
|
|
178
|
+
| `isMax()` | `boolean` | True when the size equals the maximum |
|
|
179
|
+
|
|
180
|
+
Change the limits and step with `configure()`, not by writing to their signals.
|
|
221
181
|
|
|
222
182
|
#### Methods
|
|
223
183
|
|
|
224
184
|
| Method | Parameters | Description |
|
|
225
185
|
|--------|------------|-------------|
|
|
226
|
-
| `
|
|
227
|
-
| `
|
|
228
|
-
| `
|
|
229
|
-
| `increase()` |
|
|
230
|
-
| `decrease()` |
|
|
186
|
+
| `configure(config?)` | `Partial<FontSizeConfig>` | Update limits, step, storage key or CSS variable name. Omitted values keep their current setting. |
|
|
187
|
+
| `init()` | - | Load the saved size (or the default) and apply it. Call once at startup. |
|
|
188
|
+
| `setFontSize(size)` | `number` | Set, apply and save a size (clamped to the limits) |
|
|
189
|
+
| `increase(step?)` | `number` | Increase by `step` (defaults to the configured step) |
|
|
190
|
+
| `decrease(step?)` | `number` | Decrease by `step` (defaults to the configured step) |
|
|
191
|
+
| `reset()` | - | Return to the default size and remove the saved value |
|
|
231
192
|
|
|
232
193
|
### Types
|
|
233
194
|
|
|
234
195
|
```typescript
|
|
235
|
-
type
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
}
|
|
196
|
+
type FontSizeConfig = {
|
|
197
|
+
defaultSize: number;
|
|
198
|
+
minSize: number;
|
|
199
|
+
maxSize: number;
|
|
200
|
+
step: number;
|
|
201
|
+
storageKey?: string;
|
|
202
|
+
storage?: SuStorage; // Default: localStorage
|
|
203
|
+
cssVarName?: string;
|
|
204
|
+
};
|
|
245
205
|
```
|
|
246
206
|
|
|
247
207
|
## Configuration Options
|
|
248
208
|
|
|
249
209
|
| Option | Description | Default Value |
|
|
250
210
|
|--------|-------------|---------------|
|
|
251
|
-
| `
|
|
252
|
-
| `
|
|
253
|
-
| `
|
|
254
|
-
| `
|
|
211
|
+
| `defaultSize` | Size used before the user picks one, and after `reset()` | `14` |
|
|
212
|
+
| `minSize` | Smallest allowed size | `10` |
|
|
213
|
+
| `maxSize` | Largest allowed size | `22` |
|
|
214
|
+
| `step` | Pixels added or removed by `increase()` / `decrease()` | `2` |
|
|
215
|
+
| `storageKey` | The key used to persist the size | `'su:font-size'` |
|
|
216
|
+
| `storage` | Where the size is saved. Use `createSuCookieStorage({ domain })` from `@su-labs/core` to share it across subdomains | `localStorage` |
|
|
217
|
+
| `cssVarName` | CSS custom property set on `<html>` | `'--base-font-size'` |
|
|
218
|
+
|
|
219
|
+
Invalid combinations are corrected: a maximum below the minimum is raised to the minimum, the default is clamped to the range, and a step of zero or less becomes `1`.
|
|
255
220
|
|
|
256
221
|
## Accessibility
|
|
257
222
|
|
|
258
223
|
This library helps meet WCAG 2.1 guidelines:
|
|
259
224
|
|
|
260
|
-
-
|
|
261
|
-
-
|
|
262
|
-
-
|
|
225
|
+
- **Success Criterion 1.4.4** - Text can be resized up to 200% without loss of content or functionality
|
|
226
|
+
- **Success Criterion 1.4.8** - User can select foreground and background colors (when combined with theme management)
|
|
227
|
+
- **Success Criterion 1.4.12** - Text spacing is adjustable
|
|
263
228
|
|
|
264
229
|
### Best Practices
|
|
265
230
|
|
|
@@ -269,13 +234,13 @@ This library helps meet WCAG 2.1 guidelines:
|
|
|
269
234
|
4. **Persist preference** - Always save user preference (enabled by default)
|
|
270
235
|
5. **Respect system settings** - Consider reading system font size preferences
|
|
271
236
|
|
|
272
|
-
##
|
|
237
|
+
## Browser Compatibility
|
|
273
238
|
|
|
274
239
|
Works in all modern browsers that support:
|
|
275
|
-
-
|
|
276
|
-
-
|
|
277
|
-
-
|
|
278
|
-
-
|
|
240
|
+
- CSS Custom Properties
|
|
241
|
+
- localStorage API
|
|
242
|
+
- Angular 21
|
|
243
|
+
- ES2022+
|
|
279
244
|
|
|
280
245
|
| Browser | Version |
|
|
281
246
|
|---------|---------|
|
|
@@ -284,16 +249,16 @@ Works in all modern browsers that support:
|
|
|
284
249
|
| Safari | ≥ 14 |
|
|
285
250
|
| Edge | ≥ 90 |
|
|
286
251
|
|
|
287
|
-
##
|
|
252
|
+
## Related Libraries
|
|
288
253
|
|
|
289
254
|
Part of the **@su-labs** suite:
|
|
290
255
|
|
|
291
|
-
-
|
|
292
|
-
-
|
|
293
|
-
-
|
|
294
|
-
-
|
|
256
|
+
- [@su-labs/visit-tracker](https://www.npmjs.com/package/@su-labs/visit-tracker) - User visit tracking
|
|
257
|
+
- [@su-labs/theme](https://www.npmjs.com/package/@su-labs/theme) - Theme management with dark mode support
|
|
258
|
+
- [@su-labs/notifications](https://www.npmjs.com/package/@su-labs/notifications) - Toast notification system
|
|
259
|
+
- [@su-labs/scroll-spy](https://www.npmjs.com/package/@su-labs/scroll-spy) - Scroll position tracking
|
|
295
260
|
|
|
296
|
-
##
|
|
261
|
+
## Troubleshooting
|
|
297
262
|
|
|
298
263
|
### Font size not persisting?
|
|
299
264
|
|
|
@@ -301,7 +266,7 @@ Make sure localStorage is enabled and not blocked by privacy settings.
|
|
|
301
266
|
|
|
302
267
|
### CSS variables not updating?
|
|
303
268
|
|
|
304
|
-
Ensure you're using the correct
|
|
269
|
+
Ensure you're using the correct variable name in your CSS (`--base-font-size` by default) and that you've called `init()`.
|
|
305
270
|
|
|
306
271
|
### Layout breaking at larger sizes?
|
|
307
272
|
|
|
@@ -309,13 +274,13 @@ Test your responsive design at all font sizes. Use relative units and flexible l
|
|
|
309
274
|
|
|
310
275
|
### TypeScript errors?
|
|
311
276
|
|
|
312
|
-
Ensure you have Angular 21
|
|
277
|
+
Ensure you have Angular 21 and TypeScript 5.9+ installed.
|
|
313
278
|
|
|
314
|
-
##
|
|
279
|
+
## Support
|
|
315
280
|
|
|
316
|
-
-
|
|
317
|
-
-
|
|
318
|
-
-
|
|
281
|
+
- Found a bug? [Open an issue](https://github.com/Greezaaa/settings-utils-lib/issues)
|
|
282
|
+
- Have a feature request? [Start a discussion](https://github.com/Greezaaa/settings-utils-lib/discussions)
|
|
283
|
+
- Like this library? [Give it a star!](https://github.com/Greezaaa/settings-utils-lib)
|
|
319
284
|
|
|
320
285
|
## Contributing
|
|
321
286
|
|
|
@@ -1,181 +1,94 @@
|
|
|
1
1
|
import * as i0 from '@angular/core';
|
|
2
2
|
import { signal, computed, Injectable } from '@angular/core';
|
|
3
|
+
import { SuFontSizeController } from '@su-labs/core/font-size';
|
|
3
4
|
|
|
5
|
+
/**
|
|
6
|
+
* Angular service for managing the font size.
|
|
7
|
+
*
|
|
8
|
+
* Thin wrapper around the framework-agnostic `SuFontSizeController` from
|
|
9
|
+
* `@su-labs/core/font-size` that exposes the size and limits as Angular signals.
|
|
10
|
+
*/
|
|
4
11
|
class FontSizeService {
|
|
5
|
-
/**
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
defaultSize = signal(
|
|
10
|
-
/**
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
*
|
|
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
|
-
|
|
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
|
-
*
|
|
84
|
-
*
|
|
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
|
-
|
|
90
|
-
this.fontSize.set(this.clamp(size));
|
|
91
|
-
this.applyCssVar(this.fontSize());
|
|
53
|
+
this.controller.init();
|
|
92
54
|
}
|
|
93
55
|
/**
|
|
94
|
-
*
|
|
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
|
-
|
|
100
|
-
this.fontSize.set(clamped);
|
|
101
|
-
this.applyCssVar(clamped);
|
|
102
|
-
this.writeToStorage(clamped);
|
|
60
|
+
this.controller.setFontSize(size);
|
|
103
61
|
}
|
|
104
62
|
/**
|
|
105
|
-
*
|
|
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
|
-
*
|
|
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
|
-
|
|
126
|
-
this.fontSize.set(d);
|
|
127
|
-
this.applyCssVar(d);
|
|
128
|
-
localStorage.removeItem(this.storageKey);
|
|
78
|
+
this.controller.reset();
|
|
129
79
|
}
|
|
130
|
-
/**
|
|
131
|
-
|
|
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
|
-
|
|
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.
|
|
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":["../../../../
|
|
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":"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"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@su-labs/font-size",
|
|
3
|
-
"version": "21.
|
|
3
|
+
"version": "21.2.2",
|
|
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://
|
|
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.10.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
|
-
|
|
4
|
-
|
|
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
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
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
|
-
*
|
|
61
|
-
*
|
|
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
|
-
*
|
|
68
|
-
*
|
|
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
|
-
*
|
|
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
|
-
*
|
|
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
|
-
*
|
|
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
|
-
|
|
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
|
}
|