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