@su-labs/font-size 21.0.4 → 22.0.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 +11 -0
- package/README.md +275 -84
- package/fesm2022/su-labs-font-size.mjs +91 -183
- package/fesm2022/su-labs-font-size.mjs.map +1 -1
- package/package.json +5 -4
- package/types/su-labs-font-size.d.ts +122 -127
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,17 @@ All notable changes to this project will be documented in this file.
|
|
|
5
5
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
6
6
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
7
|
|
|
8
|
+
## [22.0.0] - 2026-11-04
|
|
9
|
+
|
|
10
|
+
### Changed
|
|
11
|
+
- Upgrade to Angular 22 (peer dependencies now `^22.0.0`)
|
|
12
|
+
- Remove emojis from README.md
|
|
13
|
+
|
|
14
|
+
## [21.0.5] - 2026-02-04
|
|
15
|
+
|
|
16
|
+
### Changed
|
|
17
|
+
- Update README.md
|
|
18
|
+
|
|
8
19
|
## [21.0.4] - 2026-02-03
|
|
9
20
|
|
|
10
21
|
### Changed
|
package/README.md
CHANGED
|
@@ -1,137 +1,328 @@
|
|
|
1
|
-
#
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
# Font Size
|
|
2
|
+
|
|
3
|
+
`@su-labs/font-size`
|
|
4
|
+
|
|
5
|
+

|
|
6
|
+

|
|
7
|
+

|
|
8
|
+

|
|
9
|
+

|
|
10
|
+

|
|
11
|
+

|
|
12
|
+

|
|
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
|
+
## Table of Contents
|
|
17
|
+
|
|
18
|
+
- [Why Use This Library?](#-why-use-this-library)
|
|
19
|
+
- [Features](#features)
|
|
20
|
+
- [Installation](#installation)
|
|
21
|
+
- [Quick Start](#-quick-start)
|
|
22
|
+
- [Usage](#usage)
|
|
23
|
+
- [API Reference](#-api-reference)
|
|
24
|
+
- [Configuration Options](#configuration-options)
|
|
25
|
+
- [Accessibility](#accessibility)
|
|
26
|
+
- [Browser Compatibility](#-browser-compatibility)
|
|
27
|
+
- [Related Libraries](#-related-libraries)
|
|
28
|
+
- [Troubleshooting](#-troubleshooting)
|
|
29
|
+
- [Support](#-support)
|
|
30
|
+
- [Contributing](#contributing)
|
|
31
|
+
- [License](#license)
|
|
32
|
+
|
|
33
|
+
## Why Use This Library?
|
|
34
|
+
|
|
35
|
+
- **Lightweight** - Minimal bundle size
|
|
36
|
+
- **Reactive** - Built with Angular Signals
|
|
37
|
+
- **Accessible** - WCAG 2.1 AA compliant
|
|
38
|
+
- **Persistent** - Remembers user preference
|
|
39
|
+
- **CSS Variables** - Modern implementation
|
|
40
|
+
- **Type-Safe** - Full TypeScript support
|
|
41
|
+
- **Zero Dependencies** - No bloat
|
|
42
|
+
- **Well Tested** - Comprehensive test coverage
|
|
43
|
+
- **Well Documented** - Clear examples and API docs
|
|
4
44
|
|
|
5
45
|
## Features
|
|
6
46
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
47
|
+
* **Reactive State**: Uses Angular signals for efficient, reactive font size management.
|
|
48
|
+
* **Persistence**: Remembers the user's font size preference using `localStorage`.
|
|
49
|
+
* **Multiple Presets**: Support for small, normal, large, and extra-large font sizes.
|
|
50
|
+
* **CSS Variables**: Applies font sizes using CSS custom properties for maximum flexibility.
|
|
51
|
+
* **Accessibility**: Helps users with visual impairments customize text size for better readability.
|
|
52
|
+
* **Configurable**: Customizable storage keys, CSS variable names, and size scales.
|
|
13
53
|
|
|
14
54
|
## Installation
|
|
15
55
|
|
|
16
56
|
You can install this library via npm:
|
|
17
57
|
|
|
18
|
-
```
|
|
58
|
+
```sh
|
|
19
59
|
npm install @su-labs/font-size
|
|
20
60
|
```
|
|
21
61
|
|
|
22
|
-
|
|
62
|
+
## Peer Dependencies
|
|
23
63
|
|
|
24
|
-
|
|
64
|
+
This library requires the following peer dependencies:
|
|
25
65
|
|
|
26
|
-
```
|
|
27
|
-
|
|
28
|
-
providers: [
|
|
29
|
-
FontSizeService,
|
|
30
|
-
provideAppInitializer(() => {
|
|
31
|
-
|
|
32
|
-
const fontService = inject(FontSizeService);
|
|
33
|
-
fontService.init(); // initializes font size from localStorage and applies CSS variable
|
|
34
|
-
}),
|
|
35
|
-
],
|
|
36
|
-
};
|
|
66
|
+
```sh
|
|
67
|
+
npm install @angular/common@^22 @angular/core@^22
|
|
37
68
|
```
|
|
38
|
-
Using the service in components
|
|
39
69
|
|
|
40
|
-
|
|
70
|
+
## Quick Start
|
|
41
71
|
|
|
42
72
|
```typescript
|
|
43
|
-
|
|
44
|
-
|
|
73
|
+
// 1. Install
|
|
74
|
+
npm install @su-labs/font-size
|
|
45
75
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
<div>
|
|
50
|
-
<p>Current font size: {{ fontSize() }}</p>
|
|
51
|
-
<button (click)="increase()">A+</button>
|
|
52
|
-
<button (click)="decrease()">A-</button>
|
|
53
|
-
<button (click)="reset()">Reset</button>
|
|
54
|
-
</div>` ,
|
|
55
|
-
})
|
|
76
|
+
// 2. Initialize in app.config.ts
|
|
77
|
+
import { provideAppInitializer, inject } from '@angular/core';
|
|
78
|
+
import { SuFontSizeService } from '@su-labs/font-size';
|
|
56
79
|
|
|
57
|
-
export
|
|
58
|
-
|
|
59
|
-
|
|
80
|
+
export const appConfig = {
|
|
81
|
+
providers: [
|
|
82
|
+
provideAppInitializer(() => {
|
|
83
|
+
inject(SuFontSizeService).init();
|
|
84
|
+
}),
|
|
85
|
+
],
|
|
86
|
+
};
|
|
60
87
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
88
|
+
// 3. Create font size controls
|
|
89
|
+
import { Component, inject } from '@angular/core';
|
|
90
|
+
import { SuFontSizeService } from '@su-labs/font-size';
|
|
64
91
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
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
|
+
}
|
|
68
103
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
104
|
+
// 4. Use CSS variables in your styles
|
|
105
|
+
body {
|
|
106
|
+
font-size: var(--su-font-size-base);
|
|
72
107
|
}
|
|
73
108
|
```
|
|
74
109
|
|
|
75
|
-
|
|
110
|
+
## Usage
|
|
76
111
|
|
|
77
|
-
|
|
112
|
+
### Example 1: Basic Font Size Controls
|
|
78
113
|
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
| `maxSize` | The maximum allowed font size in pixels. | `22` |
|
|
83
|
-
| `defaultSize`| The initial font size and the value used for resetting. | `14` |
|
|
84
|
-
| `step` | The number of pixels to increase or decrease the font size by. | `2` |
|
|
85
|
-
| `storageKey` | The key used to persist the font size in `localStorage`. | `'su:font-size'`|
|
|
86
|
-
| `cssVarName` | The name of the CSS custom property that will be applied to the `<html>` element. | `'--base-font-size'`|
|
|
114
|
+
```typescript
|
|
115
|
+
import { Component, inject } from '@angular/core';
|
|
116
|
+
import { SuFontSizeService, FontSize } from '@su-labs/font-size';
|
|
87
117
|
|
|
88
|
-
|
|
118
|
+
@Component({
|
|
119
|
+
selector: 'app-font-controls',
|
|
120
|
+
standalone: true,
|
|
121
|
+
template: `
|
|
122
|
+
<div class="font-controls">
|
|
123
|
+
<h3>Text Size</h3>
|
|
124
|
+
<div class="button-group">
|
|
125
|
+
@for (size of fontSizes; track size) {
|
|
126
|
+
<button
|
|
127
|
+
(click)="setFontSize(size)"
|
|
128
|
+
[class.active]="fontService.size() === size"
|
|
129
|
+
>
|
|
130
|
+
{{ size | titlecase }}
|
|
131
|
+
</button>
|
|
132
|
+
}
|
|
133
|
+
</div>
|
|
134
|
+
<p>Current size: {{ fontService.size() }}</p>
|
|
135
|
+
</div>
|
|
136
|
+
`,
|
|
137
|
+
styles: [`
|
|
138
|
+
.button-group button.active {
|
|
139
|
+
background-color: var(--su-theme-primary);
|
|
140
|
+
color: white;
|
|
141
|
+
}
|
|
142
|
+
`]
|
|
143
|
+
})
|
|
144
|
+
export class FontControlsComponent {
|
|
145
|
+
fontService = inject(SuFontSizeService);
|
|
146
|
+
fontSizes: FontSize[] = ['small', 'normal', 'large', 'x-large'];
|
|
89
147
|
|
|
90
|
-
|
|
91
|
-
this.fontService.
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
defaultSize: 16,
|
|
95
|
-
step: 2,
|
|
96
|
-
storageKey: 'my-app-font-size',
|
|
97
|
-
cssVarName: '--app-font-size'
|
|
98
|
-
});
|
|
148
|
+
setFontSize(size: FontSize) {
|
|
149
|
+
this.fontService.setSize(size);
|
|
150
|
+
}
|
|
151
|
+
}
|
|
99
152
|
```
|
|
100
153
|
|
|
101
|
-
|
|
154
|
+
### Example 2: Custom Configuration
|
|
102
155
|
|
|
103
|
-
|
|
156
|
+
```typescript
|
|
157
|
+
import { provideAppInitializer, inject } from '@angular/core';
|
|
158
|
+
import { SuFontSizeService, SuFontSizeConfig } from '@su-labs/font-size';
|
|
159
|
+
|
|
160
|
+
const fontConfig: SuFontSizeConfig = {
|
|
161
|
+
defaultSize: 'normal',
|
|
162
|
+
storageKey: 'myApp:fontSize',
|
|
163
|
+
cssVarPrefix: '--app-font-',
|
|
164
|
+
sizes: {
|
|
165
|
+
small: '14px',
|
|
166
|
+
normal: '16px',
|
|
167
|
+
large: '18px',
|
|
168
|
+
'x-large': '20px'
|
|
169
|
+
}
|
|
170
|
+
};
|
|
171
|
+
|
|
172
|
+
export const appConfig = {
|
|
173
|
+
providers: [
|
|
174
|
+
provideAppInitializer(() => {
|
|
175
|
+
inject(SuFontSizeService).init(fontConfig);
|
|
176
|
+
}),
|
|
177
|
+
],
|
|
178
|
+
};
|
|
179
|
+
```
|
|
104
180
|
|
|
105
|
-
|
|
181
|
+
### Example 3: Using in Your Styles
|
|
106
182
|
|
|
107
183
|
```css
|
|
184
|
+
/* Global styles.css */
|
|
108
185
|
:root {
|
|
109
|
-
|
|
110
|
-
--
|
|
186
|
+
--su-font-size-base: 16px;
|
|
187
|
+
--su-font-size-small: 14px;
|
|
188
|
+
--su-font-size-large: 18px;
|
|
111
189
|
}
|
|
112
190
|
|
|
113
191
|
body {
|
|
114
|
-
font-size: var(--
|
|
192
|
+
font-size: var(--su-font-size-base);
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
h1 {
|
|
196
|
+
font-size: calc(var(--su-font-size-base) * 2);
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
h2 {
|
|
200
|
+
font-size: calc(var(--su-font-size-base) * 1.5);
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
.small-text {
|
|
204
|
+
font-size: var(--su-font-size-small);
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
.large-text {
|
|
208
|
+
font-size: var(--su-font-size-large);
|
|
115
209
|
}
|
|
116
210
|
```
|
|
117
211
|
|
|
118
|
-
|
|
212
|
+
## API Reference
|
|
119
213
|
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
214
|
+
### Service (SuFontSizeService)
|
|
215
|
+
|
|
216
|
+
#### Signals
|
|
217
|
+
|
|
218
|
+
| Signal | Type | Description |
|
|
219
|
+
|--------|------|-------------|
|
|
220
|
+
| `size()` | `FontSize` | Current font size setting |
|
|
221
|
+
|
|
222
|
+
#### Methods
|
|
223
|
+
|
|
224
|
+
| Method | Parameters | Description |
|
|
225
|
+
|--------|------------|-------------|
|
|
226
|
+
| `init(config?)` | `SuFontSizeConfig` | Initialize with custom configuration |
|
|
227
|
+
| `setSize(size, persist?)` | `FontSize, boolean` | Change font size (persist defaults to true) |
|
|
228
|
+
| `getSize()` | - | Returns current font size |
|
|
229
|
+
| `increase()` | - | Increase to next larger size |
|
|
230
|
+
| `decrease()` | - | Decrease to next smaller size |
|
|
231
|
+
|
|
232
|
+
### Types
|
|
233
|
+
|
|
234
|
+
```typescript
|
|
235
|
+
type FontSize = 'small' | 'normal' | 'large' | 'x-large';
|
|
236
|
+
|
|
237
|
+
interface SuFontSizeConfig {
|
|
238
|
+
storageKey?: string; // Default: 'su:fontSize'
|
|
239
|
+
cssVarPrefix?: string; // Default: '--su-font-size-'
|
|
240
|
+
defaultSize?: FontSize; // Default: 'normal'
|
|
241
|
+
sizes?: {
|
|
242
|
+
[key in FontSize]?: string; // Custom pixel/rem values
|
|
243
|
+
};
|
|
124
244
|
}
|
|
125
245
|
```
|
|
126
246
|
|
|
127
|
-
|
|
247
|
+
## Configuration Options
|
|
248
|
+
|
|
249
|
+
| Option | Description | Default Value |
|
|
250
|
+
|--------|-------------|---------------|
|
|
251
|
+
| `storageKey` | The key used to persist font size in `localStorage` | `'su:fontSize'` |
|
|
252
|
+
| `cssVarPrefix` | Prefix for CSS variables | `'--su-font-size-'` |
|
|
253
|
+
| `defaultSize` | Default font size if none saved | `'normal'` |
|
|
254
|
+
| `sizes` | Custom size values (px, rem, em) | `{ small: '14px', normal: '16px', large: '18px', 'x-large': '20px' }` |
|
|
255
|
+
|
|
256
|
+
## Accessibility
|
|
257
|
+
|
|
258
|
+
This library helps meet WCAG 2.1 guidelines:
|
|
259
|
+
|
|
260
|
+
- **Success Criterion 1.4.4** - Text can be resized up to 200% without loss of content or functionality
|
|
261
|
+
- **Success Criterion 1.4.8** - User can select foreground and background colors (when combined with theme management)
|
|
262
|
+
- **Success Criterion 1.4.12** - Text spacing is adjustable
|
|
263
|
+
|
|
264
|
+
### Best Practices
|
|
265
|
+
|
|
266
|
+
1. **Use relative units** - Consider using `rem` instead of `px` for better scaling
|
|
267
|
+
2. **Test at all sizes** - Ensure your layout works at all font size settings
|
|
268
|
+
3. **Provide clear controls** - Make font size controls easy to find and use
|
|
269
|
+
4. **Persist preference** - Always save user preference (enabled by default)
|
|
270
|
+
5. **Respect system settings** - Consider reading system font size preferences
|
|
271
|
+
|
|
272
|
+
## Browser Compatibility
|
|
273
|
+
|
|
274
|
+
Works in all modern browsers that support:
|
|
275
|
+
- CSS Custom Properties
|
|
276
|
+
- localStorage API
|
|
277
|
+
- Angular 22+
|
|
278
|
+
- ES2022+
|
|
279
|
+
|
|
280
|
+
| Browser | Version |
|
|
281
|
+
|---------|---------|
|
|
282
|
+
| Chrome | ≥ 90 |
|
|
283
|
+
| Firefox | ≥ 88 |
|
|
284
|
+
| Safari | ≥ 14 |
|
|
285
|
+
| Edge | ≥ 90 |
|
|
286
|
+
|
|
287
|
+
## Related Libraries
|
|
288
|
+
|
|
289
|
+
Part of the **@su-labs** suite:
|
|
290
|
+
|
|
291
|
+
- [@su-labs/visit-tracker](https://www.npmjs.com/package/@su-labs/visit-tracker) - User visit tracking
|
|
292
|
+
- [@su-labs/theme](https://www.npmjs.com/package/@su-labs/theme) - Theme management with dark mode support
|
|
293
|
+
- [@su-labs/notifications](https://www.npmjs.com/package/@su-labs/notifications) - Toast notification system
|
|
294
|
+
- [@su-labs/scroll-spy](https://www.npmjs.com/package/@su-labs/scroll-spy) - Scroll position tracking
|
|
295
|
+
|
|
296
|
+
## Troubleshooting
|
|
297
|
+
|
|
298
|
+
### Font size not persisting?
|
|
299
|
+
|
|
300
|
+
Make sure localStorage is enabled and not blocked by privacy settings.
|
|
301
|
+
|
|
302
|
+
### CSS variables not updating?
|
|
303
|
+
|
|
304
|
+
Ensure you're using the correct prefix in your CSS (`--su-font-size-` by default) and that you've initialized the service.
|
|
305
|
+
|
|
306
|
+
### Layout breaking at larger sizes?
|
|
307
|
+
|
|
308
|
+
Test your responsive design at all font sizes. Use relative units and flexible layouts.
|
|
309
|
+
|
|
310
|
+
### TypeScript errors?
|
|
311
|
+
|
|
312
|
+
Ensure you have Angular 22+ and TypeScript 6.0+ installed.
|
|
313
|
+
|
|
314
|
+
## Support
|
|
315
|
+
|
|
316
|
+
- Found a bug? [Open an issue](https://github.com/Greezaaa/settings-utils-lib/issues)
|
|
317
|
+
- Have a feature request? [Start a discussion](https://github.com/Greezaaa/settings-utils-lib/discussions)
|
|
318
|
+
- Like this library? [Give it a star!](https://github.com/Greezaaa/settings-utils-lib)
|
|
128
319
|
|
|
129
320
|
## Contributing
|
|
130
321
|
|
|
131
|
-
If you find any bugs or have feature requests, please open an issue or submit a pull request on our GitHub repository.
|
|
322
|
+
If you find any bugs or have feature requests, please open an issue or submit a pull request on our [**GitHub repository**](https://github.com/Greezaaa/settings-utils-lib.git).
|
|
132
323
|
|
|
133
|
-
To contribute code, please ensure your changes include unit tests
|
|
324
|
+
To contribute code, please ensure your changes include unit tests to maintain code quality. Please see the main repository's `README.md` for details on the monorepo structure.
|
|
134
325
|
|
|
135
326
|
## License
|
|
136
327
|
|
|
137
|
-
This project is licensed under the MIT License. See the [LICENSE](https://github.com/Greezaaa/settings-utils-lib/blob/main/projects/su-labs/font-size/LICENSE) file for details.
|
|
328
|
+
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,184 +1,92 @@
|
|
|
1
|
-
import * as i0 from
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
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
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
this.fontSize.set(this.clamp(size));
|
|
91
|
-
this.applyCssVar(this.fontSize());
|
|
92
|
-
}
|
|
93
|
-
/**
|
|
94
|
-
* Sets the font size to a specific value (clamped within min/max).
|
|
95
|
-
*
|
|
96
|
-
* @param size Desired font size in pixels.
|
|
97
|
-
*/
|
|
98
|
-
setFontSize(size) {
|
|
99
|
-
const clamped = this.clamp(size);
|
|
100
|
-
this.fontSize.set(clamped);
|
|
101
|
-
this.applyCssVar(clamped);
|
|
102
|
-
this.writeToStorage(clamped);
|
|
103
|
-
}
|
|
104
|
-
/**
|
|
105
|
-
* Increases the font size.
|
|
106
|
-
*
|
|
107
|
-
* @param step Optional custom step (pixels). Falls back to configured {@link step} if omitted.
|
|
108
|
-
*/
|
|
109
|
-
increase(step) {
|
|
110
|
-
this.setFontSize(this.fontSize() + (step ?? this.step()));
|
|
111
|
-
}
|
|
112
|
-
/**
|
|
113
|
-
* Decreases the font size.
|
|
114
|
-
*
|
|
115
|
-
* @param step Optional custom step (pixels). Falls back to configured {@link step} if omitted.
|
|
116
|
-
*/
|
|
117
|
-
decrease(step) {
|
|
118
|
-
this.setFontSize(this.fontSize() - (step ?? this.step()));
|
|
119
|
-
}
|
|
120
|
-
/**
|
|
121
|
-
* Resets the font size to the configured {@link defaultSize}.
|
|
122
|
-
* Also removes the persisted value from localStorage.
|
|
123
|
-
*/
|
|
124
|
-
reset() {
|
|
125
|
-
const d = this.defaultSize();
|
|
126
|
-
this.fontSize.set(d);
|
|
127
|
-
this.applyCssVar(d);
|
|
128
|
-
localStorage.removeItem(this.storageKey);
|
|
129
|
-
}
|
|
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());
|
|
138
|
-
}
|
|
139
|
-
/**
|
|
140
|
-
* Reads the font size from localStorage.
|
|
141
|
-
* Falls back to {@link defaultSize} if no value is stored or value is invalid.
|
|
142
|
-
*
|
|
143
|
-
* @returns Stored font size or default.
|
|
144
|
-
*/
|
|
145
|
-
readFromStorage() {
|
|
146
|
-
const stored = localStorage.getItem(this.storageKey);
|
|
147
|
-
const parsed = stored ? Number(stored) : this.defaultSize();
|
|
148
|
-
return Number.isFinite(parsed) ? parsed : this.defaultSize();
|
|
149
|
-
}
|
|
150
|
-
/**
|
|
151
|
-
* Persists the current font size in localStorage.
|
|
152
|
-
*
|
|
153
|
-
* @param size Font size value to persist.
|
|
154
|
-
*/
|
|
155
|
-
writeToStorage(size) {
|
|
156
|
-
localStorage.setItem(this.storageKey, String(size));
|
|
157
|
-
}
|
|
158
|
-
/**
|
|
159
|
-
* Applies the current font size to the DOM
|
|
160
|
-
* using the configured CSS custom property name.
|
|
161
|
-
*
|
|
162
|
-
* @param size Font size value in pixels.
|
|
163
|
-
*/
|
|
164
|
-
applyCssVar(size) {
|
|
165
|
-
document.documentElement.style.setProperty(this.cssVarName, `${size}px`);
|
|
166
|
-
}
|
|
167
|
-
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.1.2", ngImport: i0, type: FontSizeService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
|
|
168
|
-
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "21.1.2", ngImport: i0, type: FontSizeService, providedIn: 'root' });
|
|
169
|
-
}
|
|
170
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.1.2", ngImport: i0, type: FontSizeService, decorators: [{
|
|
171
|
-
type: Injectable,
|
|
172
|
-
args: [{ providedIn: 'root' }]
|
|
173
|
-
}] });
|
|
174
|
-
|
|
175
|
-
/*
|
|
176
|
-
* Public API Surface of font-size
|
|
177
|
-
*/
|
|
178
|
-
|
|
179
|
-
/**
|
|
180
|
-
* Generated bundle index. Do not edit.
|
|
181
|
-
*/
|
|
182
|
-
|
|
1
|
+
import * as i0 from "@angular/core";
|
|
2
|
+
import { Injectable, computed, signal } from "@angular/core";
|
|
3
|
+
var FontSizeService = class FontSizeService {
|
|
4
|
+
defaultSize = signal(14, ...ngDevMode ? [{ debugName: "defaultSize" }] : /* istanbul ignore next */ []);
|
|
5
|
+
minSize = signal(10, ...ngDevMode ? [{ debugName: "minSize" }] : /* istanbul ignore next */ []);
|
|
6
|
+
maxSize = signal(22, ...ngDevMode ? [{ debugName: "maxSize" }] : /* istanbul ignore next */ []);
|
|
7
|
+
step = signal(2, ...ngDevMode ? [{ debugName: "step" }] : /* istanbul ignore next */ []);
|
|
8
|
+
storageKey = "su:font-size";
|
|
9
|
+
cssVarName = "--base-font-size";
|
|
10
|
+
fontSize = signal(this.readFromStorage(), ...ngDevMode ? [{ debugName: "fontSize" }] : /* istanbul ignore next */ []);
|
|
11
|
+
isDefault = computed(() => this.fontSize() === this.defaultSize(), ...ngDevMode ? [{ debugName: "isDefault" }] : /* istanbul ignore next */ []);
|
|
12
|
+
isMax = computed(() => this.fontSize() === this.maxSize(), ...ngDevMode ? [{ debugName: "isMax" }] : /* istanbul ignore next */ []);
|
|
13
|
+
isMin = computed(() => this.fontSize() === this.minSize(), ...ngDevMode ? [{ debugName: "isMin" }] : /* istanbul ignore next */ []);
|
|
14
|
+
configure(cfg = {}) {
|
|
15
|
+
if (cfg.minSize !== void 0) this.minSize.set(cfg.minSize);
|
|
16
|
+
if (cfg.maxSize !== void 0) this.maxSize.set(cfg.maxSize);
|
|
17
|
+
if (cfg.defaultSize !== void 0) this.defaultSize.set(cfg.defaultSize);
|
|
18
|
+
if (cfg.step !== void 0) this.step.set(cfg.step);
|
|
19
|
+
if (cfg.storageKey) this.storageKey = cfg.storageKey;
|
|
20
|
+
if (cfg.cssVarName) this.cssVarName = cfg.cssVarName;
|
|
21
|
+
if (this.minSize() > this.maxSize()) this.maxSize.set(this.minSize());
|
|
22
|
+
if (this.defaultSize() < this.minSize()) this.defaultSize.set(this.minSize());
|
|
23
|
+
if (this.defaultSize() > this.maxSize()) this.defaultSize.set(this.maxSize());
|
|
24
|
+
if (this.step() <= 0 || !Number.isFinite(this.step())) this.step.set(1);
|
|
25
|
+
this.fontSize.update((s) => this.clamp(s));
|
|
26
|
+
}
|
|
27
|
+
init() {
|
|
28
|
+
const size = this.readFromStorage();
|
|
29
|
+
this.fontSize.set(this.clamp(size));
|
|
30
|
+
this.applyCssVar(this.fontSize());
|
|
31
|
+
}
|
|
32
|
+
setFontSize(size) {
|
|
33
|
+
const clamped = this.clamp(size);
|
|
34
|
+
this.fontSize.set(clamped);
|
|
35
|
+
this.applyCssVar(clamped);
|
|
36
|
+
this.writeToStorage(clamped);
|
|
37
|
+
}
|
|
38
|
+
increase(step) {
|
|
39
|
+
this.setFontSize(this.fontSize() + (step ?? this.step()));
|
|
40
|
+
}
|
|
41
|
+
decrease(step) {
|
|
42
|
+
this.setFontSize(this.fontSize() - (step ?? this.step()));
|
|
43
|
+
}
|
|
44
|
+
reset() {
|
|
45
|
+
const d = this.defaultSize();
|
|
46
|
+
this.fontSize.set(d);
|
|
47
|
+
this.applyCssVar(d);
|
|
48
|
+
localStorage.removeItem(this.storageKey);
|
|
49
|
+
}
|
|
50
|
+
clamp(size) {
|
|
51
|
+
return Math.min(Math.max(size, this.minSize()), this.maxSize());
|
|
52
|
+
}
|
|
53
|
+
readFromStorage() {
|
|
54
|
+
const stored = localStorage.getItem(this.storageKey);
|
|
55
|
+
const parsed = stored ? Number(stored) : this.defaultSize();
|
|
56
|
+
return Number.isFinite(parsed) ? parsed : this.defaultSize();
|
|
57
|
+
}
|
|
58
|
+
writeToStorage(size) {
|
|
59
|
+
localStorage.setItem(this.storageKey, String(size));
|
|
60
|
+
}
|
|
61
|
+
applyCssVar(size) {
|
|
62
|
+
document.documentElement.style.setProperty(this.cssVarName, `${size}px`);
|
|
63
|
+
}
|
|
64
|
+
static ɵfac = i0.ɵɵngDeclareFactory({
|
|
65
|
+
minVersion: "12.0.0",
|
|
66
|
+
version: "22.2.4",
|
|
67
|
+
ngImport: i0,
|
|
68
|
+
type: FontSizeService,
|
|
69
|
+
deps: [],
|
|
70
|
+
target: i0.ɵɵFactoryTarget.Injectable
|
|
71
|
+
});
|
|
72
|
+
static ɵprov = i0.ɵɵngDeclareInjectable({
|
|
73
|
+
minVersion: "12.0.0",
|
|
74
|
+
version: "22.2.4",
|
|
75
|
+
ngImport: i0,
|
|
76
|
+
type: FontSizeService,
|
|
77
|
+
providedIn: "root"
|
|
78
|
+
});
|
|
79
|
+
};
|
|
80
|
+
i0.ɵɵngDeclareClassMetadata({
|
|
81
|
+
minVersion: "12.0.0",
|
|
82
|
+
version: "22.2.4",
|
|
83
|
+
ngImport: i0,
|
|
84
|
+
type: FontSizeService,
|
|
85
|
+
decorators: [{
|
|
86
|
+
type: Injectable,
|
|
87
|
+
args: [{ providedIn: "root" }]
|
|
88
|
+
}]
|
|
89
|
+
});
|
|
183
90
|
export { FontSizeService };
|
|
184
|
-
|
|
91
|
+
|
|
92
|
+
//# sourceMappingURL=su-labs-font-size.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"su-labs-font-size.mjs","sources":["../../../../projects/su-labs/font-size/src/lib/font-size.service.ts"
|
|
1
|
+
{"version":3,"file":"su-labs-font-size.mjs","names":[],"sources":["../../../../projects/su-labs/font-size/src/lib/font-size.service.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"],"mappings":"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"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@su-labs/font-size",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "22.0.0",
|
|
4
4
|
"description": "A lightweight Angular service for dynamic font size management.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"angular",
|
|
@@ -25,8 +25,8 @@
|
|
|
25
25
|
"url": "https://github.com/Greezaaa"
|
|
26
26
|
},
|
|
27
27
|
"peerDependencies": {
|
|
28
|
-
"@angular/common": "^
|
|
29
|
-
"@angular/core": "^
|
|
28
|
+
"@angular/common": "^22.0.0",
|
|
29
|
+
"@angular/core": "^22.0.0"
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
32
|
"tslib": "^2.3.0"
|
|
@@ -51,5 +51,6 @@
|
|
|
51
51
|
"types": "./types/su-labs-font-size.d.ts",
|
|
52
52
|
"default": "./fesm2022/su-labs-font-size.mjs"
|
|
53
53
|
}
|
|
54
|
-
}
|
|
54
|
+
},
|
|
55
|
+
"type": "module"
|
|
55
56
|
}
|
|
@@ -1,128 +1,123 @@
|
|
|
1
|
-
import * as
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
cssVarName?: string;
|
|
1
|
+
import * as i0 from "@angular/core";
|
|
2
|
+
export interface FontSizeConfig {
|
|
3
|
+
defaultSize: number;
|
|
4
|
+
minSize: number;
|
|
5
|
+
maxSize: number;
|
|
6
|
+
step: number;
|
|
7
|
+
storageKey?: string;
|
|
8
|
+
cssVarName?: string;
|
|
10
9
|
}
|
|
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
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
export { FontSizeService };
|
|
128
|
-
export type { FontSizeConfig };
|
|
10
|
+
export declare class FontSizeService {
|
|
11
|
+
/**
|
|
12
|
+
* Default font size in pixels.
|
|
13
|
+
* Can be overridden via {@link configure}.
|
|
14
|
+
*/
|
|
15
|
+
defaultSize: import("@angular/core").WritableSignal<number>;
|
|
16
|
+
/**
|
|
17
|
+
* Minimum allowed font size in pixels.
|
|
18
|
+
* Can be overridden via {@link configure}.
|
|
19
|
+
*/
|
|
20
|
+
minSize: import("@angular/core").WritableSignal<number>;
|
|
21
|
+
/**
|
|
22
|
+
* Maximum allowed font size in pixels.
|
|
23
|
+
* Can be overridden via {@link configure}.
|
|
24
|
+
*/
|
|
25
|
+
maxSize: import("@angular/core").WritableSignal<number>;
|
|
26
|
+
/**
|
|
27
|
+
* Default step value (in pixels) for increase/decrease operations.
|
|
28
|
+
* Can be overridden via {@link configure} or per call in {@link increase} / {@link decrease}.
|
|
29
|
+
*/
|
|
30
|
+
step: import("@angular/core").WritableSignal<number>;
|
|
31
|
+
/**
|
|
32
|
+
* Key used for persisting the font size in localStorage.
|
|
33
|
+
* Defaults to `"app:font-size"`.
|
|
34
|
+
*/
|
|
35
|
+
private storageKey;
|
|
36
|
+
/**
|
|
37
|
+
* CSS custom property name where the font size is applied.
|
|
38
|
+
* Defaults to `"--base-font-size"`.
|
|
39
|
+
*/
|
|
40
|
+
private cssVarName;
|
|
41
|
+
/**
|
|
42
|
+
* Current font size state (reactive).
|
|
43
|
+
*/
|
|
44
|
+
fontSize: import("@angular/core").WritableSignal<number>;
|
|
45
|
+
/**
|
|
46
|
+
* True if current font size equals the default size.
|
|
47
|
+
*/
|
|
48
|
+
isDefault: import("@angular/core").Signal<boolean>;
|
|
49
|
+
/**
|
|
50
|
+
* True if current font size equals the maximum size.
|
|
51
|
+
*/
|
|
52
|
+
isMax: import("@angular/core").Signal<boolean>;
|
|
53
|
+
/**
|
|
54
|
+
* True if current font size equals the minimum size.
|
|
55
|
+
*/
|
|
56
|
+
isMin: import("@angular/core").Signal<boolean>;
|
|
57
|
+
/**
|
|
58
|
+
* Updates the configuration for font size handling.
|
|
59
|
+
* Any omitted values will fall back to their defaults.
|
|
60
|
+
*
|
|
61
|
+
* @param cfg Partial configuration object (min, max, default, step, storage key, CSS variable name).
|
|
62
|
+
*/
|
|
63
|
+
configure(cfg?: Partial<FontSizeConfig>): void;
|
|
64
|
+
/**
|
|
65
|
+
* Initializes the font size service.
|
|
66
|
+
* Loads the persisted value (if available), clamps it,
|
|
67
|
+
* applies it to the DOM, and updates internal state.
|
|
68
|
+
* Should typically be called once at application startup.
|
|
69
|
+
*/
|
|
70
|
+
init(): void;
|
|
71
|
+
/**
|
|
72
|
+
* Sets the font size to a specific value (clamped within min/max).
|
|
73
|
+
*
|
|
74
|
+
* @param size Desired font size in pixels.
|
|
75
|
+
*/
|
|
76
|
+
setFontSize(size: number): void;
|
|
77
|
+
/**
|
|
78
|
+
* Increases the font size.
|
|
79
|
+
*
|
|
80
|
+
* @param step Optional custom step (pixels). Falls back to configured {@link step} if omitted.
|
|
81
|
+
*/
|
|
82
|
+
increase(step?: number): void;
|
|
83
|
+
/**
|
|
84
|
+
* Decreases the font size.
|
|
85
|
+
*
|
|
86
|
+
* @param step Optional custom step (pixels). Falls back to configured {@link step} if omitted.
|
|
87
|
+
*/
|
|
88
|
+
decrease(step?: number): void;
|
|
89
|
+
/**
|
|
90
|
+
* Resets the font size to the configured {@link defaultSize}.
|
|
91
|
+
* Also removes the persisted value from localStorage.
|
|
92
|
+
*/
|
|
93
|
+
reset(): void;
|
|
94
|
+
/**
|
|
95
|
+
* Clamps a given value between the configured {@link minSize} and {@link maxSize}.
|
|
96
|
+
*
|
|
97
|
+
* @param size Value to clamp.
|
|
98
|
+
* @returns Clamped value within the allowed range.
|
|
99
|
+
*/
|
|
100
|
+
private clamp;
|
|
101
|
+
/**
|
|
102
|
+
* Reads the font size from localStorage.
|
|
103
|
+
* Falls back to {@link defaultSize} if no value is stored or value is invalid.
|
|
104
|
+
*
|
|
105
|
+
* @returns Stored font size or default.
|
|
106
|
+
*/
|
|
107
|
+
private readFromStorage;
|
|
108
|
+
/**
|
|
109
|
+
* Persists the current font size in localStorage.
|
|
110
|
+
*
|
|
111
|
+
* @param size Font size value to persist.
|
|
112
|
+
*/
|
|
113
|
+
private writeToStorage;
|
|
114
|
+
/**
|
|
115
|
+
* Applies the current font size to the DOM
|
|
116
|
+
* using the configured CSS custom property name.
|
|
117
|
+
*
|
|
118
|
+
* @param size Font size value in pixels.
|
|
119
|
+
*/
|
|
120
|
+
private applyCssVar;
|
|
121
|
+
static ɵfac: i0.ɵɵFactoryDeclaration<FontSizeService, never>;
|
|
122
|
+
static ɵprov: i0.ɵɵInjectableDeclaration<any>;
|
|
123
|
+
}
|