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

theme-egy

v1.2.1

Published

Modern Angular theme management library powered by Signals. Light/dark mode with CSS custom properties.

Readme

theme-egy

npm version license bundle size

Lightweight Angular theme management powered by Signals. Light/dark mode, CSS custom properties, and configurable persistence — all tree-shakable and SSR-safe.

Features

  • Light/dark mode switching with Signals
  • Configurable color tokens (primary, background, foreground, border + custom)
  • Two color sources: JS config or existing CSS variables
  • Automatic CSS custom property injection
  • data-theme attribute management
  • Runtime color overrides without losing base palette
  • Persistence via localStorage, sessionStorage, or none
  • SSR-safe with full guard coverage
  • Tree-shakable and standalone
  • Zero NgModules

Why theme-egy?

Angular does not ship with a built-in theme system. Implementing light/dark mode requires manually managing mode state, persisting preferences, injecting CSS variables, handling the DOM attribute, and ensuring SSR safety. theme-egy handles all of this in a single, reactive API built on Angular Signals.

Installation

npm install theme-egy

Quick Start

import { provideTheme, injectTheme } from 'theme-egy';

bootstrapApplication(App, {
  providers: [
    provideTheme({
      colors: {
        light: {
          primary: '#2563eb',
          background: '#ffffff',
          foreground: '#111827',
          border: '#e5e7eb',
        },
        dark: {
          primary: '#3b82f6',
          background: '#0f172a',
          foreground: '#f1f5f9',
          border: '#334155',
        },
      },
    }),
  ],
});
@Component({...})
export class AppComponent {
  private theme = injectTheme();

  readonly isDark = this.theme.isDark;

  toggle() {
    this.theme.toggle();
  }
}
<button (click)="toggle()">
  {{ isDark() ? '☀️ Light' : '🌙 Dark' }}
</button>

Configuration

provideTheme(config: ThemeConfig)

| Option | Type | Default | Description | |---|---|---|---| | colors | { light: ColorTokens; dark: ColorTokens } | — | Color palettes for each mode. Required for config source, forbidden for CSS source. | | colorSource | 'config' \| 'css' | 'config' | Where colors originate. | | defaultMode | 'light' \| 'dark' | 'light' | Fallback mode when no stored preference exists. | | storageKey | string | 'theme-egy.mode' | Key for storage persistence. | | storageStrategy | 'local' \| 'session' \| 'none' | 'local' | Which storage API to use. | | autoApply | boolean | true | Auto-write CSS vars and data-theme attribute. | | cssVarPrefix | string | '--theme-' | Prefix for CSS custom properties. |

ColorTokens

interface ColorTokens {
  primary: string;
  background: string;
  foreground: string;
  border: string;
  [key: string]: string; // custom tokens
}

Basic Usage

Inject ThemeService

import { injectTheme } from 'theme-egy';

@Component({...})
export class MyComponent {
  private theme = injectTheme();
}

Read mode

const mode = this.theme.mode;       // Signal<'light' | 'dark'>
const isDark = this.theme.isDark;   // Signal<boolean>

Set mode

this.theme.setMode('dark');
this.theme.setMode('light');
this.theme.toggle(); // switches between light and dark

Read colors

const colors = this.theme.colors; // Signal<ColorTokens>

Override colors at runtime

// Merge overrides on top of current palette
this.theme.updateColors({ primary: '#ef4444' });

// Remove overrides, restoring base palette
this.theme.resetColors();

Force re-read CSS variables (CSS source mode only)

this.theme.refreshColors();

Color Source Modes

Config mode (default)

Colors are defined in the provideTheme() config. The library writes --theme-* CSS custom properties on <html> and manages the data-theme attribute automatically.

provideTheme({
  colors: {
    light: { primary: '#2563eb', background: '#ffffff', /* ... */ },
    dark: { primary: '#3b82f6', background: '#0f172a', /* ... */ },
  },
});

CSS mode

Colors are defined in your stylesheets (Tailwind, plain CSS, design tokens). The library reads them from document.documentElement computed styles and sets data-theme so the CSS cascade handles mode switching.

provideTheme({
  colorSource: 'css',
  cssVarPrefix: '--color-',
});

CSS mode pairs well with Tailwind's @theme directive or any design token system:

@theme {
  --color-primary: #2563eb;
  --color-background: #ffffff;
  /* ... */
}

[data-theme="dark"] {
  --color-primary: #3b82f6;
  --color-background: #0f172a;
}

Architecture

flowchart TD
  A[ThemeConfig]
  B[provideTheme]
  C[ThemeService]
  D[ThemeColorProvider]
  E[ConfigColorProvider]
  F[CssVariableColorProvider]
  G[Effects]

  A --> B
  B --> C
  C --> D
  D --> E
  D --> F
  C --> G
  G --> H[data-theme attribute]
  G --> I[CSS custom properties]
  G --> J[Storage persistence]
  G --> K[Runtime overrides]

Browser Support

  • Angular 20+
  • Standalone applications
  • SSR compatible
  • Zone.js optional (Signals-based)

API Reference

provideTheme(config: ThemeConfig): EnvironmentProviders

Registers the theme configuration. Validates config at runtime — throws if config source without colors, or CSS source with colors.

injectTheme(): ThemeService

Returns the singleton ThemeService instance.

ThemeService

| Member | Type | Description | |---|---|---| | mode | Signal<ThemeMode> | Current theme mode | | isDark | Signal<boolean> | True if current mode is 'dark' | | colors | Signal<ColorTokens> | Active colors (base + runtime overrides) | | setMode(mode) | void | Switch to a specific mode | | toggle() | void | Toggle between light and dark | | updateColors(overrides) | void | Merge partial color overrides | | resetColors() | void | Remove all runtime overrides | | clearRuntimeColors() | void | Alias for resetColors() | | refreshColors() | void | Force re-read CSS variables (CSS mode only) |

ThemeMode

type ThemeMode = 'light' | 'dark';

ColorSource

type ColorSource = 'config' | 'css';

StorageStrategy

type StorageStrategy = 'local' | 'session' | 'none';

ThemeColorProvider

Abstract base class for color providers.

abstract class ThemeColorProvider {
  abstract readonly colors: Signal<ColorTokens>;
}

License

MIT