@su-labs/font-size 21.0.4 โ 21.0.5
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 +5 -0
- package/README.md +275 -84
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,11 @@ 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
|
+
## [21.0.5] - 2026-02-04
|
|
9
|
+
|
|
10
|
+
### Changed
|
|
11
|
+
- Update README.md
|
|
12
|
+
|
|
8
13
|
## [21.0.4] - 2026-02-03
|
|
9
14
|
|
|
10
15
|
### 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@^21 @angular/core@^21
|
|
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 21+
|
|
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 21+ and TypeScript 5.7+ 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.
|