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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@su-labs/font-size

v1.0.4

Published

A lightweight Angular service for dynamic font size management.

Readme

FontSizeService

A lightweight Angular service for dynamic font size management. Easily increase, decrease, or reset font sizes in your Angular applications, with persistent settings in localStorage. Designed as a reusable library for multiple projects.

Features

  • Set a default font size and apply it globally.
  • Increase or decrease font size with configurable step.
  • Reset to default font size.
  • Automatically persist user preferences in localStorage.
  • Provides reactive Signals to integrate with Angular's reactive system.
  • Limits font size to configurable minimum and maximum values.

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@^20.1.0 @angular/core@^20.1.0

Usage

Provide the service in your application

You can provide the service in your main.ts (or wherever your ApplicationConfig is defined) and initialize it automatically:

export const appConfig: ApplicationConfig = {
providers: [
	FontSizeService,
	provideAppInitializer(() => {
	
	const fontService = inject(FontSizeService);
	fontService.init(); // initializes font size from localStorage and applies CSS variable
	}),
	],
};

Using the service in components

Inject the service into any component and access reactive signals:

import { Component, effect } from '@angular/core';
import { FontSizeService } from '@su-labs/font-size';

@Component({
selector: 'app-example',
template: `
	<div> 
		<p>Current font size: {{ fontSize() }}</p> 
		<button (click)="increase()">A+</button> 
		<button (click)="decrease()">A-</button> 
		<button (click)="reset()">Reset</button> 
	</div>` ,
})

export class ExampleComponent {
	private fontService = inject(FontSizeService);
	fontSize = computed(() => this.fontService.fontSize());

	increase(step?: number) {
		this.fontService.increase(step);
	}

	decrease(step?: number) {
		this.fontService.decrease(step);
	}

	reset() {
		this.fontService.reset();
	}
}

Optional configuration

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.

| Option | Description | Default Value | |--------------|---------------------------------------------------------------------------------------------------------|-----------------| | minSize | The minimum allowed font size in pixels. | 10 | | maxSize | The maximum allowed font size in pixels. | 22 | | defaultSize| The initial font size and the value used for resetting. | 14 | | step | The number of pixels to increase or decrease the font size by. | 2 | | storageKey | The key used to persist the font size in localStorage. | 'su:font-size'| | cssVarName | The name of the CSS custom property that will be applied to the <html> element. | '--base-font-size'|

Example:

this.fontService.configure({
  minSize: 12,
  maxSize: 24,
  defaultSize: 16,
  step: 2,
  storageKey: 'my-app-font-size',
  cssVarName: '--app-font-size'
});

Styling (CSS)

The service applies the current font size to a CSS custom property (variable) on the <html> element. By default, this is --base-font-size.

To use this feature in your application's CSS, you should use this variable to define your font size, for example, in your styles.scss or styles.css:

:root {
  /* Define a fallback in case the service isn't initialized yet */
  --base-font-size: 14px;
}

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

Or, if you configured a different name:

CSS

body {
  font-size: var(--app-font-size);
}

This setup ensures that your font size is reactive, persistent, and easily configurable across your Angular app.

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 using Vitest to maintain code quality.

License

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