@su-labs/font-size 21.0.5 → 22.1.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 +20 -0
- package/README.md +127 -166
- package/fesm2022/su-labs-font-size.mjs +69 -183
- package/fesm2022/su-labs-font-size.mjs.map +1 -1
- package/package.json +6 -4
- package/types/su-labs-font-size.d.ts +65 -128
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,26 @@ 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.1.0] - 2026-11-05
|
|
9
|
+
|
|
10
|
+
### Changed
|
|
11
|
+
- Font size logic moved to the framework-agnostic `@su-labs/core/font-size`; `FontSizeService` is now a thin wrapper with the same API
|
|
12
|
+
- `FontSizeConfig` is now a type alias built from the core types (same fields)
|
|
13
|
+
- Change limits and step with `configure()`. Writing to the `minSize`, `maxSize`, `defaultSize` or `step` signals directly no longer affects clamping or `reset()`
|
|
14
|
+
- Added `@su-labs/core` as a dependency
|
|
15
|
+
- README links to the `@su-labs/core` installation guides for non-Angular projects
|
|
16
|
+
|
|
17
|
+
### Fixed
|
|
18
|
+
- Safe to import during server-side rendering (no `localStorage` access without a browser)
|
|
19
|
+
- README now documents the actual API
|
|
20
|
+
- Repair table of contents links in README.md
|
|
21
|
+
|
|
22
|
+
## [22.0.0] - 2026-11-04
|
|
23
|
+
|
|
24
|
+
### Changed
|
|
25
|
+
- Upgrade to Angular 22 (peer dependencies now `^22.0.0`)
|
|
26
|
+
- Remove emojis from README.md
|
|
27
|
+
|
|
8
28
|
## [21.0.5] - 2026-02-04
|
|
9
29
|
|
|
10
30
|
### Changed
|
package/README.md
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
`@su-labs/font-size`
|
|
4
4
|
|
|
5
5
|

|
|
6
|
-

|
|
7
7
|

|
|
8
8
|

|
|
9
9
|

|
|
@@ -13,43 +13,43 @@
|
|
|
13
13
|
|
|
14
14
|
An accessible Angular service for managing font size preferences. Provides reactive controls for text scaling, user preference persistence, and WCAG-compliant font size management.
|
|
15
15
|
|
|
16
|
-
|
|
16
|
+
> **Not using Angular?** The same font size controls are available for React, Svelte and vanilla JavaScript in [`@su-labs/core`](https://www.npmjs.com/package/@su-labs/core). See the [installation guides](https://github.com/Greezaaa/settings-utils-lib/blob/main/docs/README.md).
|
|
17
17
|
|
|
18
|
-
|
|
18
|
+
## Table of Contents
|
|
19
|
+
|
|
20
|
+
- [Why Use This Library?](#why-use-this-library)
|
|
19
21
|
- [Features](#features)
|
|
20
22
|
- [Installation](#installation)
|
|
21
|
-
- [Quick Start](
|
|
23
|
+
- [Quick Start](#quick-start)
|
|
22
24
|
- [Usage](#usage)
|
|
23
|
-
- [API Reference](
|
|
25
|
+
- [API Reference](#api-reference)
|
|
24
26
|
- [Configuration Options](#configuration-options)
|
|
25
27
|
- [Accessibility](#accessibility)
|
|
26
|
-
- [Browser Compatibility](
|
|
27
|
-
- [Related Libraries](
|
|
28
|
-
- [Troubleshooting](
|
|
29
|
-
- [Support](
|
|
28
|
+
- [Browser Compatibility](#browser-compatibility)
|
|
29
|
+
- [Related Libraries](#related-libraries)
|
|
30
|
+
- [Troubleshooting](#troubleshooting)
|
|
31
|
+
- [Support](#support)
|
|
30
32
|
- [Contributing](#contributing)
|
|
31
33
|
- [License](#license)
|
|
32
34
|
|
|
33
|
-
##
|
|
35
|
+
## Why Use This Library?
|
|
34
36
|
|
|
35
|
-
-
|
|
36
|
-
-
|
|
37
|
-
-
|
|
38
|
-
-
|
|
39
|
-
-
|
|
40
|
-
-
|
|
41
|
-
-
|
|
42
|
-
-
|
|
43
|
-
- 📝 **Well Documented** - Clear examples and API docs
|
|
37
|
+
- **Lightweight** - Minimal bundle size
|
|
38
|
+
- **Reactive** - Built with Angular Signals
|
|
39
|
+
- **Accessible** - Helps meet WCAG 2.1 text resizing guidelines
|
|
40
|
+
- **Persistent** - Remembers user preference
|
|
41
|
+
- **CSS Variables** - Modern implementation
|
|
42
|
+
- **SSR Safe** - No browser APIs are touched on the server
|
|
43
|
+
- **Type-Safe** - Full TypeScript support
|
|
44
|
+
- **Well Tested** - Comprehensive test coverage
|
|
44
45
|
|
|
45
46
|
## Features
|
|
46
47
|
|
|
47
|
-
* **Reactive State**:
|
|
48
|
-
* **
|
|
49
|
-
* **
|
|
50
|
-
* **CSS
|
|
51
|
-
* **
|
|
52
|
-
* **Configurable**: Customizable storage keys, CSS variable names, and size scales.
|
|
48
|
+
* **Reactive State**: The size, limits and `isDefault` / `isMin` / `isMax` flags are Angular signals.
|
|
49
|
+
* **Bounded**: The size always stays between the configured minimum and maximum.
|
|
50
|
+
* **Persistence**: Remembers the user's font size in `localStorage`.
|
|
51
|
+
* **CSS Variable**: Applies the size in pixels to a CSS custom property on `<html>`.
|
|
52
|
+
* **Configurable**: Customizable limits, step, storage key and CSS variable name.
|
|
53
53
|
|
|
54
54
|
## Installation
|
|
55
55
|
|
|
@@ -64,202 +64,163 @@ npm install @su-labs/font-size
|
|
|
64
64
|
This library requires the following peer dependencies:
|
|
65
65
|
|
|
66
66
|
```sh
|
|
67
|
-
npm install @angular/common@^
|
|
67
|
+
npm install @angular/common@^22 @angular/core@^22
|
|
68
68
|
```
|
|
69
69
|
|
|
70
|
-
##
|
|
70
|
+
## Quick Start
|
|
71
71
|
|
|
72
|
-
|
|
73
|
-
// 1. Install
|
|
74
|
-
npm install @su-labs/font-size
|
|
72
|
+
1. Initialize the service in `app.config.ts`:
|
|
75
73
|
|
|
76
|
-
|
|
77
|
-
import {
|
|
78
|
-
import {
|
|
74
|
+
```typescript
|
|
75
|
+
import { ApplicationConfig, inject, provideAppInitializer } from '@angular/core';
|
|
76
|
+
import { FontSizeService } from '@su-labs/font-size';
|
|
79
77
|
|
|
80
|
-
export const appConfig = {
|
|
78
|
+
export const appConfig: ApplicationConfig = {
|
|
81
79
|
providers: [
|
|
82
80
|
provideAppInitializer(() => {
|
|
83
|
-
inject(
|
|
81
|
+
inject(FontSizeService).init();
|
|
84
82
|
}),
|
|
85
83
|
],
|
|
86
84
|
};
|
|
87
|
-
|
|
88
|
-
// 3. Create font size controls
|
|
89
|
-
import { Component, inject } from '@angular/core';
|
|
90
|
-
import { SuFontSizeService } from '@su-labs/font-size';
|
|
91
|
-
|
|
92
|
-
@Component({
|
|
93
|
-
template: `
|
|
94
|
-
<button (click)="fontService.setSize('small')">A-</button>
|
|
95
|
-
<button (click)="fontService.setSize('normal')">A</button>
|
|
96
|
-
<button (click)="fontService.setSize('large')">A+</button>
|
|
97
|
-
<p>Current: {{ fontService.size() }}</p>
|
|
98
|
-
`
|
|
99
|
-
})
|
|
100
|
-
export class AppComponent {
|
|
101
|
-
fontService = inject(SuFontSizeService);
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
// 4. Use CSS variables in your styles
|
|
105
|
-
body {
|
|
106
|
-
font-size: var(--su-font-size-base);
|
|
107
|
-
}
|
|
108
85
|
```
|
|
109
86
|
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
### Example 1: Basic Font Size Controls
|
|
87
|
+
2. Add font size controls:
|
|
113
88
|
|
|
114
89
|
```typescript
|
|
115
90
|
import { Component, inject } from '@angular/core';
|
|
116
|
-
import {
|
|
91
|
+
import { FontSizeService } from '@su-labs/font-size';
|
|
117
92
|
|
|
118
93
|
@Component({
|
|
119
94
|
selector: 'app-font-controls',
|
|
120
|
-
standalone: true,
|
|
121
95
|
template: `
|
|
122
|
-
<
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
<button
|
|
127
|
-
(click)="setFontSize(size)"
|
|
128
|
-
[class.active]="fontService.size() === size"
|
|
129
|
-
>
|
|
130
|
-
{{ size | titlecase }}
|
|
131
|
-
</button>
|
|
132
|
-
}
|
|
133
|
-
</div>
|
|
134
|
-
<p>Current size: {{ fontService.size() }}</p>
|
|
135
|
-
</div>
|
|
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>
|
|
136
100
|
`,
|
|
137
|
-
styles: [`
|
|
138
|
-
.button-group button.active {
|
|
139
|
-
background-color: var(--su-theme-primary);
|
|
140
|
-
color: white;
|
|
141
|
-
}
|
|
142
|
-
`]
|
|
143
101
|
})
|
|
144
102
|
export class FontControlsComponent {
|
|
145
|
-
|
|
146
|
-
|
|
103
|
+
protected readonly fontSize = inject(FontSizeService);
|
|
104
|
+
}
|
|
105
|
+
```
|
|
147
106
|
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
107
|
+
3. Use the CSS variable in your styles:
|
|
108
|
+
|
|
109
|
+
```css
|
|
110
|
+
html {
|
|
111
|
+
font-size: var(--base-font-size);
|
|
151
112
|
}
|
|
152
113
|
```
|
|
153
114
|
|
|
154
|
-
|
|
115
|
+
## Usage
|
|
116
|
+
|
|
117
|
+
### Custom Configuration
|
|
118
|
+
|
|
119
|
+
Call `configure()` before `init()`:
|
|
155
120
|
|
|
156
121
|
```typescript
|
|
157
|
-
import {
|
|
158
|
-
import {
|
|
159
|
-
|
|
160
|
-
const fontConfig: SuFontSizeConfig = {
|
|
161
|
-
defaultSize: 'normal',
|
|
162
|
-
storageKey: 'myApp:fontSize',
|
|
163
|
-
cssVarPrefix: '--app-font-',
|
|
164
|
-
sizes: {
|
|
165
|
-
small: '14px',
|
|
166
|
-
normal: '16px',
|
|
167
|
-
large: '18px',
|
|
168
|
-
'x-large': '20px'
|
|
169
|
-
}
|
|
170
|
-
};
|
|
122
|
+
import { ApplicationConfig, inject, provideAppInitializer } from '@angular/core';
|
|
123
|
+
import { FontSizeService } from '@su-labs/font-size';
|
|
171
124
|
|
|
172
|
-
export const appConfig = {
|
|
125
|
+
export const appConfig: ApplicationConfig = {
|
|
173
126
|
providers: [
|
|
174
127
|
provideAppInitializer(() => {
|
|
175
|
-
inject(
|
|
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();
|
|
176
138
|
}),
|
|
177
139
|
],
|
|
178
140
|
};
|
|
179
141
|
```
|
|
180
142
|
|
|
181
|
-
###
|
|
143
|
+
### Using the Size in Your Styles
|
|
182
144
|
|
|
183
|
-
|
|
184
|
-
/* Global styles.css */
|
|
185
|
-
:root {
|
|
186
|
-
--su-font-size-base: 16px;
|
|
187
|
-
--su-font-size-small: 14px;
|
|
188
|
-
--su-font-size-large: 18px;
|
|
189
|
-
}
|
|
145
|
+
Set the variable on the root element and size everything else in `rem`, so the whole page scales:
|
|
190
146
|
|
|
191
|
-
|
|
192
|
-
|
|
147
|
+
```css
|
|
148
|
+
html {
|
|
149
|
+
font-size: var(--base-font-size);
|
|
193
150
|
}
|
|
194
151
|
|
|
195
152
|
h1 {
|
|
196
|
-
font-size:
|
|
153
|
+
font-size: 2rem;
|
|
197
154
|
}
|
|
198
155
|
|
|
199
|
-
|
|
200
|
-
font-size:
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
.small-text {
|
|
204
|
-
font-size: var(--su-font-size-small);
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
.large-text {
|
|
208
|
-
font-size: var(--su-font-size-large);
|
|
156
|
+
small {
|
|
157
|
+
font-size: 0.875rem;
|
|
209
158
|
}
|
|
210
159
|
```
|
|
211
160
|
|
|
212
|
-
##
|
|
161
|
+
## API Reference
|
|
213
162
|
|
|
214
|
-
### Service (
|
|
163
|
+
### Service (FontSizeService)
|
|
215
164
|
|
|
216
165
|
#### Signals
|
|
217
166
|
|
|
218
167
|
| Signal | Type | Description |
|
|
219
168
|
|--------|------|-------------|
|
|
220
|
-
| `
|
|
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.
|
|
221
179
|
|
|
222
180
|
#### Methods
|
|
223
181
|
|
|
224
182
|
| Method | Parameters | Description |
|
|
225
183
|
|--------|------------|-------------|
|
|
226
|
-
| `
|
|
227
|
-
| `
|
|
228
|
-
| `
|
|
229
|
-
| `increase()` |
|
|
230
|
-
| `decrease()` |
|
|
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 |
|
|
231
190
|
|
|
232
191
|
### Types
|
|
233
192
|
|
|
234
193
|
```typescript
|
|
235
|
-
type
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
};
|
|
244
|
-
}
|
|
194
|
+
type FontSizeConfig = {
|
|
195
|
+
defaultSize: number;
|
|
196
|
+
minSize: number;
|
|
197
|
+
maxSize: number;
|
|
198
|
+
step: number;
|
|
199
|
+
storageKey?: string;
|
|
200
|
+
cssVarName?: string;
|
|
201
|
+
};
|
|
245
202
|
```
|
|
246
203
|
|
|
247
204
|
## Configuration Options
|
|
248
205
|
|
|
249
206
|
| Option | Description | Default Value |
|
|
250
207
|
|--------|-------------|---------------|
|
|
251
|
-
| `
|
|
252
|
-
| `
|
|
253
|
-
| `
|
|
254
|
-
| `
|
|
208
|
+
| `defaultSize` | Size used before the user picks one, and after `reset()` | `14` |
|
|
209
|
+
| `minSize` | Smallest allowed size | `10` |
|
|
210
|
+
| `maxSize` | Largest allowed size | `22` |
|
|
211
|
+
| `step` | Pixels added or removed by `increase()` / `decrease()` | `2` |
|
|
212
|
+
| `storageKey` | The key used to persist the size in `localStorage` | `'su:font-size'` |
|
|
213
|
+
| `cssVarName` | CSS custom property set on `<html>` | `'--base-font-size'` |
|
|
214
|
+
|
|
215
|
+
Invalid combinations are corrected: a maximum below the minimum is raised to the minimum, the default is clamped to the range, and a step of zero or less becomes `1`.
|
|
255
216
|
|
|
256
217
|
## Accessibility
|
|
257
218
|
|
|
258
219
|
This library helps meet WCAG 2.1 guidelines:
|
|
259
220
|
|
|
260
|
-
-
|
|
261
|
-
-
|
|
262
|
-
-
|
|
221
|
+
- **Success Criterion 1.4.4** - Text can be resized up to 200% without loss of content or functionality
|
|
222
|
+
- **Success Criterion 1.4.8** - User can select foreground and background colors (when combined with theme management)
|
|
223
|
+
- **Success Criterion 1.4.12** - Text spacing is adjustable
|
|
263
224
|
|
|
264
225
|
### Best Practices
|
|
265
226
|
|
|
@@ -269,13 +230,13 @@ This library helps meet WCAG 2.1 guidelines:
|
|
|
269
230
|
4. **Persist preference** - Always save user preference (enabled by default)
|
|
270
231
|
5. **Respect system settings** - Consider reading system font size preferences
|
|
271
232
|
|
|
272
|
-
##
|
|
233
|
+
## Browser Compatibility
|
|
273
234
|
|
|
274
235
|
Works in all modern browsers that support:
|
|
275
|
-
-
|
|
276
|
-
-
|
|
277
|
-
-
|
|
278
|
-
-
|
|
236
|
+
- CSS Custom Properties
|
|
237
|
+
- localStorage API
|
|
238
|
+
- Angular 22+
|
|
239
|
+
- ES2022+
|
|
279
240
|
|
|
280
241
|
| Browser | Version |
|
|
281
242
|
|---------|---------|
|
|
@@ -284,16 +245,16 @@ Works in all modern browsers that support:
|
|
|
284
245
|
| Safari | ≥ 14 |
|
|
285
246
|
| Edge | ≥ 90 |
|
|
286
247
|
|
|
287
|
-
##
|
|
248
|
+
## Related Libraries
|
|
288
249
|
|
|
289
250
|
Part of the **@su-labs** suite:
|
|
290
251
|
|
|
291
|
-
-
|
|
292
|
-
-
|
|
293
|
-
-
|
|
294
|
-
-
|
|
252
|
+
- [@su-labs/visit-tracker](https://www.npmjs.com/package/@su-labs/visit-tracker) - User visit tracking
|
|
253
|
+
- [@su-labs/theme](https://www.npmjs.com/package/@su-labs/theme) - Theme management with dark mode support
|
|
254
|
+
- [@su-labs/notifications](https://www.npmjs.com/package/@su-labs/notifications) - Toast notification system
|
|
255
|
+
- [@su-labs/scroll-spy](https://www.npmjs.com/package/@su-labs/scroll-spy) - Scroll position tracking
|
|
295
256
|
|
|
296
|
-
##
|
|
257
|
+
## Troubleshooting
|
|
297
258
|
|
|
298
259
|
### Font size not persisting?
|
|
299
260
|
|
|
@@ -301,7 +262,7 @@ Make sure localStorage is enabled and not blocked by privacy settings.
|
|
|
301
262
|
|
|
302
263
|
### CSS variables not updating?
|
|
303
264
|
|
|
304
|
-
Ensure you're using the correct
|
|
265
|
+
Ensure you're using the correct variable name in your CSS (`--base-font-size` by default) and that you've called `init()`.
|
|
305
266
|
|
|
306
267
|
### Layout breaking at larger sizes?
|
|
307
268
|
|
|
@@ -309,13 +270,13 @@ Test your responsive design at all font sizes. Use relative units and flexible l
|
|
|
309
270
|
|
|
310
271
|
### TypeScript errors?
|
|
311
272
|
|
|
312
|
-
Ensure you have Angular
|
|
273
|
+
Ensure you have Angular 22+ and TypeScript 6.0+ installed.
|
|
313
274
|
|
|
314
|
-
##
|
|
275
|
+
## Support
|
|
315
276
|
|
|
316
|
-
-
|
|
317
|
-
-
|
|
318
|
-
-
|
|
277
|
+
- Found a bug? [Open an issue](https://github.com/Greezaaa/settings-utils-lib/issues)
|
|
278
|
+
- Have a feature request? [Start a discussion](https://github.com/Greezaaa/settings-utils-lib/discussions)
|
|
279
|
+
- Like this library? [Give it a star!](https://github.com/Greezaaa/settings-utils-lib)
|
|
319
280
|
|
|
320
281
|
## Contributing
|
|
321
282
|
|
|
@@ -1,184 +1,70 @@
|
|
|
1
|
-
import * as i0 from
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
class FontSizeService {
|
|
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
|
-
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));
|
|
81
|
-
}
|
|
82
|
-
/**
|
|
83
|
-
* Initializes the font size service.
|
|
84
|
-
* Loads the persisted value (if available), clamps it,
|
|
85
|
-
* applies it to the DOM, and updates internal state.
|
|
86
|
-
* Should typically be called once at application startup.
|
|
87
|
-
*/
|
|
88
|
-
init() {
|
|
89
|
-
const size = this.readFromStorage();
|
|
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
|
+
import { SuFontSizeController } from "@su-labs/core/font-size";
|
|
4
|
+
var FontSizeService = class FontSizeService {
|
|
5
|
+
controller = new SuFontSizeController();
|
|
6
|
+
initialLimits = this.controller.limits.get();
|
|
7
|
+
defaultSize = signal(this.initialLimits.defaultSize, ...ngDevMode ? [{ debugName: "defaultSize" }] : /* istanbul ignore next */ []);
|
|
8
|
+
minSize = signal(this.initialLimits.minSize, ...ngDevMode ? [{ debugName: "minSize" }] : /* istanbul ignore next */ []);
|
|
9
|
+
maxSize = signal(this.initialLimits.maxSize, ...ngDevMode ? [{ debugName: "maxSize" }] : /* istanbul ignore next */ []);
|
|
10
|
+
step = signal(this.initialLimits.step, ...ngDevMode ? [{ debugName: "step" }] : /* istanbul ignore next */ []);
|
|
11
|
+
fontSize = signal(this.controller.fontSize.get(), ...ngDevMode ? [{ debugName: "fontSize" }] : /* istanbul ignore next */ []);
|
|
12
|
+
isDefault = computed(() => this.fontSize() === this.defaultSize(), ...ngDevMode ? [{ debugName: "isDefault" }] : /* istanbul ignore next */ []);
|
|
13
|
+
isMax = computed(() => this.fontSize() === this.maxSize(), ...ngDevMode ? [{ debugName: "isMax" }] : /* istanbul ignore next */ []);
|
|
14
|
+
isMin = computed(() => this.fontSize() === this.minSize(), ...ngDevMode ? [{ debugName: "isMin" }] : /* istanbul ignore next */ []);
|
|
15
|
+
unsubscribers = [this.controller.fontSize.subscribe((size) => this.fontSize.set(size)), this.controller.limits.subscribe((limits) => {
|
|
16
|
+
this.defaultSize.set(limits.defaultSize);
|
|
17
|
+
this.minSize.set(limits.minSize);
|
|
18
|
+
this.maxSize.set(limits.maxSize);
|
|
19
|
+
this.step.set(limits.step);
|
|
20
|
+
})];
|
|
21
|
+
configure(cfg = {}) {
|
|
22
|
+
this.controller.configure(cfg);
|
|
23
|
+
}
|
|
24
|
+
init() {
|
|
25
|
+
this.controller.init();
|
|
26
|
+
}
|
|
27
|
+
setFontSize(size) {
|
|
28
|
+
this.controller.setFontSize(size);
|
|
29
|
+
}
|
|
30
|
+
increase(step) {
|
|
31
|
+
this.setFontSize(this.fontSize() + (step ?? this.step()));
|
|
32
|
+
}
|
|
33
|
+
decrease(step) {
|
|
34
|
+
this.setFontSize(this.fontSize() - (step ?? this.step()));
|
|
35
|
+
}
|
|
36
|
+
reset() {
|
|
37
|
+
this.controller.reset();
|
|
38
|
+
}
|
|
39
|
+
ngOnDestroy() {
|
|
40
|
+
this.unsubscribers.forEach((unsubscribe) => unsubscribe());
|
|
41
|
+
}
|
|
42
|
+
static ɵfac = i0.ɵɵngDeclareFactory({
|
|
43
|
+
minVersion: "12.0.0",
|
|
44
|
+
version: "22.2.4",
|
|
45
|
+
ngImport: i0,
|
|
46
|
+
type: FontSizeService,
|
|
47
|
+
deps: [],
|
|
48
|
+
target: i0.ɵɵFactoryTarget.Injectable
|
|
49
|
+
});
|
|
50
|
+
static ɵprov = i0.ɵɵngDeclareInjectable({
|
|
51
|
+
minVersion: "12.0.0",
|
|
52
|
+
version: "22.2.4",
|
|
53
|
+
ngImport: i0,
|
|
54
|
+
type: FontSizeService,
|
|
55
|
+
providedIn: "root"
|
|
56
|
+
});
|
|
57
|
+
};
|
|
58
|
+
i0.ɵɵngDeclareClassMetadata({
|
|
59
|
+
minVersion: "12.0.0",
|
|
60
|
+
version: "22.2.4",
|
|
61
|
+
ngImport: i0,
|
|
62
|
+
type: FontSizeService,
|
|
63
|
+
decorators: [{
|
|
64
|
+
type: Injectable,
|
|
65
|
+
args: [{ providedIn: "root" }]
|
|
66
|
+
}]
|
|
67
|
+
});
|
|
183
68
|
export { FontSizeService };
|
|
184
|
-
|
|
69
|
+
|
|
70
|
+
//# 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 { 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"],"mappings":";;;AAWA,IAAa,kBAAb,MAAa,gBAAe;CAET,aAAa,IAAI,qBAAoB;CAErC,gBAAkC,KAAK,WAAW,OAAO,IAAG;CAG7E,cAAc,OAAO,KAAK,cAAc,aAAY,GAAA,YAAA,CAAA,EAAA,WAAA,cAAA,CAAA,+BAAA,CAAA,CAAA;CAGpD,UAAU,OAAO,KAAK,cAAc,SAAQ,GAAA,YAAA,CAAA,EAAA,WAAA,UAAA,CAAA,+BAAA,CAAA,CAAA;CAG5C,UAAU,OAAO,KAAK,cAAc,SAAQ,GAAA,YAAA,CAAA,EAAA,WAAA,UAAA,CAAA,+BAAA,CAAA,CAAA;CAG5C,OAAO,OAAO,KAAK,cAAc,MAAK,GAAA,YAAA,CAAA,EAAA,WAAA,OAAA,CAAA,+BAAA,CAAA,CAAA;CAGtC,WAAW,OAAe,KAAK,WAAW,SAAS,IAAG,GAAG,GAAA,YAAA,CAAA,EAAA,WAAA,WAAA,CAAA,+BAAA,CAAA,CAAA;CAGzD,YAAY,eAAe,KAAK,SAAQ,MAAO,KAAK,YAAW,GAAG,GAAA,YAAA,CAAA,EAAA,WAAA,YAAA,CAAA,+BAAA,CAAA,CAAA;CAGlE,QAAQ,eAAe,KAAK,SAAQ,MAAO,KAAK,QAAO,GAAG,GAAA,YAAA,CAAA,EAAA,WAAA,QAAA,CAAA,+BAAA,CAAA,CAAA;CAG1D,QAAQ,eAAe,KAAK,SAAQ,MAAO,KAAK,QAAO,GAAG,GAAA,YAAA,CAAA,EAAA,WAAA,QAAA,CAAA,+BAAA,CAAA,CAAA;CAGzC,gBAAgB,CAC/B,KAAK,WAAW,SAAS,WAAW,SAAS,KAAK,SAAS,IAAI,IAAI,CAAC,GACpE,KAAK,WAAW,OAAO,WAAW,WAAU;EAC1C,KAAK,YAAY,IAAI,OAAO,WAAW;EACvC,KAAK,QAAQ,IAAI,OAAO,OAAO;EAC/B,KAAK,QAAQ,IAAI,OAAO,OAAO;EAC/B,KAAK,KAAK,IAAI,OAAO,IAAI;CAC3B,CAAC,CACF;CAMD,UAAU,MAA+B,CAAA,GAAE;EACzC,KAAK,WAAW,UAAU,GAAG;CAC/B;CAMA,OAAI;EACF,KAAK,WAAW,KAAI;CACtB;CAMA,YAAY,MAAY;EACtB,KAAK,WAAW,YAAY,IAAI;CAClC;CAMA,SAAS,MAAa;EACpB,KAAK,YAAY,KAAK,SAAQ,KAAM,QAAQ,KAAK,KAAI,EAAG;CAC1D;CAMA,SAAS,MAAa;EACpB,KAAK,YAAY,KAAK,SAAQ,KAAM,QAAQ,KAAK,KAAI,EAAG;CAC1D;CAGA,QAAK;EACH,KAAK,WAAW,MAAK;CACvB;CAGA,cAAW;EACT,KAAK,cAAc,SAAS,gBAAgB,YAAW,CAAE;CAC3D;CAzFW,OAAA,OAAA,GAAA,mBAAA;EAAA,YAAA;EAAA,SAAA;EAAA,UAAA;EAAA,MAAA;EAAe,MAAA,CAAA;EAAA,QAAA,GAAA,gBAAA;CAAA,CAAA;CAAf,OAAA,QAAA,GAAA,sBAAA;EAAA,YAAA;EAAA,SAAA;EAAA,UAAA;EAAA,MAAA;EAAe,YADF;CAAM,CAAA;;AACnB,GAAA,yBAAA;CAAA,YAAA;CAAA,SAAA;CAAA,UAAA;CAAA,MAAA;CAAe,YAAA,CAAA;EAD3B,MAAA;EAAW,MAAA,CAAA,EAAE,YAAY,OAAM,CAAE"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@su-labs/font-size",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "22.1.0",
|
|
4
4
|
"description": "A lightweight Angular service for dynamic font size management.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"angular",
|
|
@@ -25,10 +25,11 @@
|
|
|
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
|
+
"@su-labs/core": "^1.0.0",
|
|
32
33
|
"tslib": "^2.3.0"
|
|
33
34
|
},
|
|
34
35
|
"repository": {
|
|
@@ -51,5 +52,6 @@
|
|
|
51
52
|
"types": "./types/su-labs-font-size.d.ts",
|
|
52
53
|
"default": "./fesm2022/su-labs-font-size.mjs"
|
|
53
54
|
}
|
|
54
|
-
}
|
|
55
|
+
},
|
|
56
|
+
"type": "module"
|
|
55
57
|
}
|
|
@@ -1,128 +1,65 @@
|
|
|
1
|
-
import * as
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
declare class FontSizeService {
|
|
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
|
-
* 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
|
+
import * as i0 from "@angular/core";
|
|
2
|
+
import { OnDestroy } from "@angular/core";
|
|
3
|
+
import { SuFontSizeConfig, SuFontSizeLimits } from "@su-labs/core/font-size";
|
|
4
|
+
/** Font size configuration: limits and step in pixels, plus optional storage key and CSS variable name */
|
|
5
|
+
export type FontSizeConfig = SuFontSizeLimits & Pick<SuFontSizeConfig, 'storageKey' | 'cssVarName'>;
|
|
6
|
+
/**
|
|
7
|
+
* Angular service for managing the font size.
|
|
8
|
+
*
|
|
9
|
+
* Thin wrapper around the framework-agnostic `SuFontSizeController` from
|
|
10
|
+
* `@su-labs/core/font-size` that exposes the size and limits as Angular signals.
|
|
11
|
+
*/
|
|
12
|
+
export declare class FontSizeService implements OnDestroy {
|
|
13
|
+
/** Framework-agnostic font size logic */
|
|
14
|
+
private readonly controller;
|
|
15
|
+
private readonly initialLimits;
|
|
16
|
+
/** Default font size in pixels. Change it with {@link configure}. */
|
|
17
|
+
defaultSize: import("@angular/core").WritableSignal<number>;
|
|
18
|
+
/** Minimum font size in pixels. Change it with {@link configure}. */
|
|
19
|
+
minSize: import("@angular/core").WritableSignal<number>;
|
|
20
|
+
/** Maximum font size in pixels. Change it with {@link configure}. */
|
|
21
|
+
maxSize: import("@angular/core").WritableSignal<number>;
|
|
22
|
+
/** Default step in pixels for {@link increase} / {@link decrease}. Change it with {@link configure}. */
|
|
23
|
+
step: import("@angular/core").WritableSignal<number>;
|
|
24
|
+
/** Current font size in pixels */
|
|
25
|
+
fontSize: import("@angular/core").WritableSignal<number>;
|
|
26
|
+
/** True if the current size equals the default size */
|
|
27
|
+
isDefault: import("@angular/core").Signal<boolean>;
|
|
28
|
+
/** True if the current size equals the maximum size */
|
|
29
|
+
isMax: import("@angular/core").Signal<boolean>;
|
|
30
|
+
/** True if the current size equals the minimum size */
|
|
31
|
+
isMin: import("@angular/core").Signal<boolean>;
|
|
32
|
+
/** Stop syncing the controller's stores into the signals */
|
|
33
|
+
private readonly unsubscribers;
|
|
34
|
+
/**
|
|
35
|
+
* Update the configuration. Omitted values keep their current setting.
|
|
36
|
+
* @param cfg Partial configuration (limits, step, storage key, CSS variable name).
|
|
37
|
+
*/
|
|
38
|
+
configure(cfg?: Partial<FontSizeConfig>): void;
|
|
39
|
+
/**
|
|
40
|
+
* Load the saved size (or the default), clamp it and apply it to the document.
|
|
41
|
+
* Call once at application startup, after {@link configure}.
|
|
42
|
+
*/
|
|
43
|
+
init(): void;
|
|
44
|
+
/**
|
|
45
|
+
* Set, apply and persist a font size, clamped to the allowed range.
|
|
46
|
+
* @param size Desired font size in pixels.
|
|
47
|
+
*/
|
|
48
|
+
setFontSize(size: number): void;
|
|
49
|
+
/**
|
|
50
|
+
* Increase the font size.
|
|
51
|
+
* @param step Pixels to add. Defaults to {@link step}.
|
|
52
|
+
*/
|
|
53
|
+
increase(step?: number): void;
|
|
54
|
+
/**
|
|
55
|
+
* Decrease the font size.
|
|
56
|
+
* @param step Pixels to remove. Defaults to {@link step}.
|
|
57
|
+
*/
|
|
58
|
+
decrease(step?: number): void;
|
|
59
|
+
/** Return to the default size and remove the saved value from localStorage */
|
|
60
|
+
reset(): void;
|
|
61
|
+
/** Angular lifecycle hook for service destruction */
|
|
62
|
+
ngOnDestroy(): void;
|
|
63
|
+
static ɵfac: i0.ɵɵFactoryDeclaration<FontSizeService, never>;
|
|
64
|
+
static ɵprov: i0.ɵɵInjectableDeclaration<any>;
|
|
65
|
+
}
|