@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.
Files changed (3) hide show
  1. package/CHANGELOG.md +5 -0
  2. package/README.md +275 -84
  3. 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
- # FontSizeService
2
-
3
- A lightweight Angular service for dynamic font size management. Easily increase, decrease, or reset font sizes in your Angular applications, with persistent settings in `localStorage`. Designed as a reusable library for multiple projects.
1
+ # Font Size
2
+
3
+ `@su-labs/font-size`
4
+
5
+ ![Angular](https://img.shields.io/badge/Angular-DD0031?style=for-the-badge&logo=angular&logoColor=white)
6
+ ![Angular Version](https://img.shields.io/badge/Angular-v21-DD0031?style=for-the-badge&logo=angular&logoColor=white)
7
+ ![TypeScript](https://img.shields.io/badge/TypeScript-007ACC?style=for-the-badge&logo=typescript&logoColor=white)
8
+ ![License](https://img.shields.io/badge/License-MIT-blue.svg?style=for-the-badge)
9
+ ![NPM](https://img.shields.io/badge/NPM-CB3837?style=for-the-badge&logo=npm&logoColor=white)
10
+ ![Size](https://img.shields.io/badge/Size-Small-green.svg?style=for-the-badge)
11
+ ![Downloads](https://img.shields.io/npm/dt/@su-labs/font-size?style=for-the-badge)
12
+ ![Version](https://img.shields.io/npm/v/@su-labs/font-size?style=for-the-badge)
13
+
14
+ An accessible Angular service for managing font size preferences. Provides reactive controls for text scaling, user preference persistence, and WCAG-compliant font size management.
15
+
16
+ ## ๐Ÿ“š 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
- - Set a default font size and apply it globally.
8
- - Increase or decrease font size with configurable step.
9
- - Reset to default font size.
10
- - Automatically persist user preferences in `localStorage`.
11
- - Provides reactive `Signal`s to integrate with Angular's reactive system.
12
- - Limits font size to configurable minimum and maximum values.
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
- ```bash
58
+ ```sh
19
59
  npm install @su-labs/font-size
20
60
  ```
21
61
 
22
- npm install @angular/common@^21.0.0 @angular/core@^21.0.0
62
+ ## Peer Dependencies
23
63
 
24
- You can provide the service in your main.ts (or wherever your ApplicationConfig is defined) and initialize it automatically:
64
+ This library requires the following peer dependencies:
25
65
 
26
- ```typescript
27
- export const appConfig: ApplicationConfig = {
28
- providers: [
29
- FontSizeService,
30
- provideAppInitializer(() => {
31
-
32
- const fontService = inject(FontSizeService);
33
- fontService.init(); // initializes font size from localStorage and applies CSS variable
34
- }),
35
- ],
36
- };
66
+ ```sh
67
+ npm install @angular/common@^21 @angular/core@^21
37
68
  ```
38
- Using the service in components
39
69
 
40
- Inject the service into any component and access reactive signals:
70
+ ## ๐Ÿš€ Quick Start
41
71
 
42
72
  ```typescript
43
- import { Component, effect } from '@angular/core';
44
- import { FontSizeService } from '@su-labs/font-size';
73
+ // 1. Install
74
+ npm install @su-labs/font-size
45
75
 
46
- @Component({
47
- selector: 'app-example',
48
- template: `
49
- <div>
50
- <p>Current font size: {{ fontSize() }}</p>
51
- <button (click)="increase()">A+</button>
52
- <button (click)="decrease()">A-</button>
53
- <button (click)="reset()">Reset</button>
54
- </div>` ,
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 class ExampleComponent {
58
- private fontService = inject(FontSizeService);
59
- fontSize = computed(() => this.fontService.fontSize());
80
+ export const appConfig = {
81
+ providers: [
82
+ provideAppInitializer(() => {
83
+ inject(SuFontSizeService).init();
84
+ }),
85
+ ],
86
+ };
60
87
 
61
- increase(step?: number) {
62
- this.fontService.increase(step);
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
- decrease(step?: number) {
66
- this.fontService.decrease(step);
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
- reset() {
70
- this.fontService.reset();
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
- ### Optional configuration
110
+ ## Usage
76
111
 
77
- The service can be configured to fit your application's needs. You can customize the min/max/default font size, step, storage key, and CSS variable name by calling the `configure` method.
112
+ ### Example 1: Basic Font Size Controls
78
113
 
79
- | Option | Description | Default Value |
80
- |--------------|---------------------------------------------------------------------------------------------------------|-----------------|
81
- | `minSize` | The minimum allowed font size in pixels. | `10` |
82
- | `maxSize` | The maximum allowed font size in pixels. | `22` |
83
- | `defaultSize`| The initial font size and the value used for resetting. | `14` |
84
- | `step` | The number of pixels to increase or decrease the font size by. | `2` |
85
- | `storageKey` | The key used to persist the font size in `localStorage`. | `'su:font-size'`|
86
- | `cssVarName` | The name of the CSS custom property that will be applied to the `<html>` element. | `'--base-font-size'`|
114
+ ```typescript
115
+ import { Component, inject } from '@angular/core';
116
+ import { SuFontSizeService, FontSize } from '@su-labs/font-size';
87
117
 
88
- **Example:**
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
- ```typescript
91
- this.fontService.configure({
92
- minSize: 12,
93
- maxSize: 24,
94
- defaultSize: 16,
95
- step: 2,
96
- storageKey: 'my-app-font-size',
97
- cssVarName: '--app-font-size'
98
- });
148
+ setFontSize(size: FontSize) {
149
+ this.fontService.setSize(size);
150
+ }
151
+ }
99
152
  ```
100
153
 
101
- ## Styling (CSS)
154
+ ### Example 2: Custom Configuration
102
155
 
103
- The service applies the current font size to a CSS custom property (variable) on the `<html>` element. By default, this is `--base-font-size`.
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
- To use this feature in your application's CSS, you should use this variable to define your font size, for example, in your `styles.scss` or `styles.css`:
181
+ ### Example 3: Using in Your Styles
106
182
 
107
183
  ```css
184
+ /* Global styles.css */
108
185
  :root {
109
- /* Define a fallback in case the service isn't initialized yet */
110
- --base-font-size: 14px;
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(--base-font-size);
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
- Or, if you configured a different name:
212
+ ## ๐Ÿ“– API Reference
119
213
 
120
- CSS
121
- ```css
122
- body {
123
- font-size: var(--app-font-size);
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
- This setup ensures that your font size is reactive, persistent, and easily configurable across your Angular app.
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 using **Vitest** to maintain code quality.
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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@su-labs/font-size",
3
- "version": "21.0.4",
3
+ "version": "21.0.5",
4
4
  "description": "A lightweight Angular service for dynamic font size management.",
5
5
  "keywords": [
6
6
  "angular",