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

@magnesium/theme

v5.2.2

Published

Sass toolkit for managing design tokens as CSS custom properties.

Downloads

1,078

Readme

Magnesium

Version Downloads License

Introduction

Sass toolkit for managing design tokens as CSS custom properties. The model is define → emit → consume: declare tokens as plain Sass maps, emit them as scoped, prefixed custom properties, then reference them in your rules.

Magnesium

This README is a quick overview, the full guides and API reference live at magnesium.dev.

Why not plain custom properties?

Writing --button-text-color: darkcyan by hand works right up until the token set grows. Magnesium adds three things on top of it:

  • A typo becomes a build error. theme() checks every token against a reference schema, so a misspelled key stops the compilation instead of quietly emitting a property that nothing ever reads.
  • One source of truth. The same Sass map produces the declarations, the var() references and their fallbacks, so the side that defines a token and the side that consumes it cannot drift apart.
  • One prefix to change. Every custom property is namespaced through $prefix, so renaming it is a single line rather than a find-and-replace across the codebase.

Magnesium ships no theme, no components and no reset — only the plumbing to declare tokens and read them back.

Requirements

| Dependency | Version | |------------|-------------| | Node.js | >= 20 | | Sass | >= 1.97.1 |

Installing

npm install @magnesium/theme

Playground

Try it live on StackBlitz:

Open in StackBlitz

Or run it locally:

npm run dev

Usage

Configure the prefix once, at your compilation entry point, then define, emit and consume tokens:

@use "@magnesium/theme" with ($prefix: "ds");

// 1. Define — plain Sass maps, no output.
$tokens: ("text-color": darkcyan);

// 2. Emit — declare them as custom properties.
:root {
    @include theme.emit($tokens, "button"); // --ds-button-text-color: darkcyan;
}

// 3. Consume — reference them in your rules.
.button {
    color: theme.variable($tokens, "text-color", "button"); // var(--ds-button-text-color)
}

Emit and consume derive the custom property name from the same $prefix and $namespace, so the two sides cannot drift apart.

Options

| Option | Description | |-----------|------------------------------------------------------------------------------------| | $prefix | Global prefix for all custom properties. Set to false to disable. Default: mg. |

Configure $prefix once. Setting it in multiple files causes a Sass error. With the pkg: importer, use @use "pkg:@magnesium/theme".

API

The split follows the model: mixins emit CSS, functions return values.

Define

Tokens are plain Sass maps — there is no API to learn. Nest them freely, nested maps are flattened on emit. One function guards the shape:

| Function | Description | |------------------------------|-------------------------------------------------------------------------------| | validation($refs, $tokens) | Validates tokens against a reference schema; throws @error on unknown keys. |

Emit

| Mixin | Description | |-----------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------| | emit($tokens, $namespace, $include, $exclude, $layer) | Emits CSS custom property declarations. Filter keys with $include / $exclude, wrap in @layer via $layer. | | theme($refs, $tokens, $namespace, $include, $exclude, $layer) | validation() then emit() in one call. Throws @error on unknown tokens. | | scheme($scheme, $selector, $layer) | Scopes @content to a color scheme via @media (prefers-color-scheme), or an explicit $selector. |

Consume

| Function | Description | |----------------------------------------------------|----------------------------------------------------------------------------------------------------------| | variable($tokens, $token, $namespace, $fallback) | Returns a var() reference for a single token. Throws @error if the token is missing from the map. | | ref($token) | Returns a var() reference from a token name alone, without hardcoding the prefix. | | refs($tokens, $namespace) | Transforms a tokens map into var() references with fallbacks. Pass the result to emit() to alias it. | | name($name...) | Builds the hyphenated, prefixed name. Shared by everything above, which keeps emit and consume in sync. |

See magnesium.dev for parameters and examples.

Migration from v4

The v4 API is deprecated and will be removed in v6. Import the compatibility layer to keep it working while you migrate — each deprecated call emits a @warn:

@use "@magnesium/theme/compat" as theme;

| v4 | v5 | |---------------------------------------------------|------------------------------------------------| | config($prefix: "ds") | @use "@magnesium/theme" with ($prefix: "ds") | | create-name("button", "color") | name("button", "color") | | create-theme-vars($tokens, "button") | refs($tokens, "button") | | emit-variable($tokens, "token", true, "button") | variable($tokens, "token", "button", true) | | emit-custom-props($tokens, "button") | emit($tokens, "button") | | emit-theme-vars($refs) | emit($tokens, "button") | | emit-color-scheme("dark") | scheme("dark") |

emit-theme-vars() re-emitted the values carried by a create-theme-vars() map, so it maps back to the raw tokens. Passing a refs() map to emit() is a different operation — it declares aliases pointing at another layer.

See the full migration guide for before/after examples.