npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@su-labs/font-size

v21.0.5

Published

A lightweight Angular service for dynamic font size management.

Readme

Font Size

@su-labs/font-size

Angular Angular Version TypeScript License NPM Size Downloads Version

An accessible Angular service for managing font size preferences. Provides reactive controls for text scaling, user preference persistence, and WCAG-compliant font size management.

📚 Table of Contents

💡 Why Use This Library?

  • 🎯 Lightweight - Minimal bundle size
  • Reactive - Built with Angular Signals
  • Accessible - WCAG 2.1 AA compliant
  • 💾 Persistent - Remembers user preference
  • 🎨 CSS Variables - Modern implementation
  • 🔒 Type-Safe - Full TypeScript support
  • 📦 Zero Dependencies - No bloat
  • 🧪 Well Tested - Comprehensive test coverage
  • 📝 Well Documented - Clear examples and API docs

Features

  • Reactive State: Uses Angular signals for efficient, reactive font size management.
  • Persistence: Remembers the user's font size preference using localStorage.
  • Multiple Presets: Support for small, normal, large, and extra-large font sizes.
  • CSS Variables: Applies font sizes using CSS custom properties for maximum flexibility.
  • Accessibility: Helps users with visual impairments customize text size for better readability.
  • Configurable: Customizable storage keys, CSS variable names, and size scales.

Installation

You can install this library via npm:

npm install @su-labs/font-size

Peer Dependencies

This library requires the following peer dependencies:

npm install @angular/common@^21 @angular/core@^21

🚀 Quick Start

// 1. Install
npm install @su-labs/font-size

// 2. Initialize in app.config.ts
import { provideAppInitializer, inject } from '@angular/core';
import { SuFontSizeService } from '@su-labs/font-size';

export const appConfig = {
  providers: [
    provideAppInitializer(() => {
      inject(SuFontSizeService).init();
    }),
  ],
};

// 3. Create font size controls
import { Component, inject } from '@angular/core';
import { SuFontSizeService } from '@su-labs/font-size';

@Component({
  template: `
    <button (click)="fontService.setSize('small')">A-</button>
    <button (click)="fontService.setSize('normal')">A</button>
    <button (click)="fontService.setSize('large')">A+</button>
    <p>Current: {{ fontService.size() }}</p>
  `
})
export class AppComponent {
  fontService = inject(SuFontSizeService);
}

// 4. Use CSS variables in your styles
body {
  font-size: var(--su-font-size-base);
}

Usage

Example 1: Basic Font Size Controls

import { Component, inject } from '@angular/core';
import { SuFontSizeService, FontSize } from '@su-labs/font-size';

@Component({
  selector: 'app-font-controls',
  standalone: true,
  template: `
    <div class="font-controls">
      <h3>Text Size</h3>
      <div class="button-group">
        @for (size of fontSizes; track size) {
          <button 
            (click)="setFontSize(size)"
            [class.active]="fontService.size() === size"
          >
            {{ size | titlecase }}
          </button>
        }
      </div>
      <p>Current size: {{ fontService.size() }}</p>
    </div>
  `,
  styles: [`
    .button-group button.active {
      background-color: var(--su-theme-primary);
      color: white;
    }
  `]
})
export class FontControlsComponent {
  fontService = inject(SuFontSizeService);
  fontSizes: FontSize[] = ['small', 'normal', 'large', 'x-large'];

  setFontSize(size: FontSize) {
    this.fontService.setSize(size);
  }
}

Example 2: Custom Configuration

import { provideAppInitializer, inject } from '@angular/core';
import { SuFontSizeService, SuFontSizeConfig } from '@su-labs/font-size';

const fontConfig: SuFontSizeConfig = {
  defaultSize: 'normal',
  storageKey: 'myApp:fontSize',
  cssVarPrefix: '--app-font-',
  sizes: {
    small: '14px',
    normal: '16px',
    large: '18px',
    'x-large': '20px'
  }
};

export const appConfig = {
  providers: [
    provideAppInitializer(() => {
      inject(SuFontSizeService).init(fontConfig);
    }),
  ],
};

Example 3: Using in Your Styles

/* Global styles.css */
:root {
  --su-font-size-base: 16px;
  --su-font-size-small: 14px;
  --su-font-size-large: 18px;
}

body {
  font-size: var(--su-font-size-base);
}

h1 {
  font-size: calc(var(--su-font-size-base) * 2);
}

h2 {
  font-size: calc(var(--su-font-size-base) * 1.5);
}

.small-text {
  font-size: var(--su-font-size-small);
}

.large-text {
  font-size: var(--su-font-size-large);
}

📖 API Reference

Service (SuFontSizeService)

Signals

| Signal | Type | Description | |--------|------|-------------| | size() | FontSize | Current font size setting |

Methods

| Method | Parameters | Description | |--------|------------|-------------| | init(config?) | SuFontSizeConfig | Initialize with custom configuration | | setSize(size, persist?) | FontSize, boolean | Change font size (persist defaults to true) | | getSize() | - | Returns current font size | | increase() | - | Increase to next larger size | | decrease() | - | Decrease to next smaller size |

Types

type FontSize = 'small' | 'normal' | 'large' | 'x-large';

interface SuFontSizeConfig {
  storageKey?: string;           // Default: 'su:fontSize'
  cssVarPrefix?: string;         // Default: '--su-font-size-'
  defaultSize?: FontSize;        // Default: 'normal'
  sizes?: {
    [key in FontSize]?: string;  // Custom pixel/rem values
  };
}

Configuration Options

| Option | Description | Default Value | |--------|-------------|---------------| | storageKey | The key used to persist font size in localStorage | 'su:fontSize' | | cssVarPrefix | Prefix for CSS variables | '--su-font-size-' | | defaultSize | Default font size if none saved | 'normal' | | sizes | Custom size values (px, rem, em) | { small: '14px', normal: '16px', large: '18px', 'x-large': '20px' } |

Accessibility

This library helps meet WCAG 2.1 guidelines:

  • Success Criterion 1.4.4 - Text can be resized up to 200% without loss of content or functionality
  • Success Criterion 1.4.8 - User can select foreground and background colors (when combined with theme management)
  • Success Criterion 1.4.12 - Text spacing is adjustable

Best Practices

  1. Use relative units - Consider using rem instead of px for better scaling
  2. Test at all sizes - Ensure your layout works at all font size settings
  3. Provide clear controls - Make font size controls easy to find and use
  4. Persist preference - Always save user preference (enabled by default)
  5. Respect system settings - Consider reading system font size preferences

🌐 Browser Compatibility

Works in all modern browsers that support:

  • ✅ CSS Custom Properties
  • ✅ localStorage API
  • ✅ Angular 21+
  • ✅ ES2022+

| Browser | Version | |---------|---------| | Chrome | ≥ 90 | | Firefox | ≥ 88 | | Safari | ≥ 14 | | Edge | ≥ 90 |

🔗 Related Libraries

Part of the @su-labs suite:

🔧 Troubleshooting

Font size not persisting?

Make sure localStorage is enabled and not blocked by privacy settings.

CSS variables not updating?

Ensure you're using the correct prefix in your CSS (--su-font-size- by default) and that you've initialized the service.

Layout breaking at larger sizes?

Test your responsive design at all font sizes. Use relative units and flexible layouts.

TypeScript errors?

Ensure you have Angular 21+ and TypeScript 5.7+ installed.

💬 Support

Contributing

If you find any bugs or have feature requests, please open an issue or submit a pull request on our GitHub repository.

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.

License

This project is licensed under the MIT License. See the LICENSE file for details.