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 🙏

© 2024 – Pkg Stats / Ryan Hefner

@glare-labs/material-tokens-generator

v0.2.1

Published

Use the @material/material-color-utilities tool to create a set of tokens based on material design.

Downloads

135

Readme

material-tokens-generator

If you find any problems, please report them.

This warehouse uses the @material/material-color-utilities open source warehouse to convert the results generated by @material/material-color-utilities into CSS styles.

  • ESM Supported Only
  • Typescript Supported
npm i @glare-labs/material-tokens-generator @material/material-color-utilities
import {
    EMaterialContrastLevel,
    EMaterialVariant,
    MaterialTokens,
} from "@glare-labs/material-tokens-generator";

const theme = new MaterialTokens(Hct.from(140, 90, 50), {
    contrastLevel: EMaterialContrastLevel.Default,
    variant: EMaterialVariant.Fidelity,
    isDark: false,
    prefix: "my-prefix",
    excludedTokens: [
        "surfaceTint",
    ],
});

Usage

Generate Colors

For example:

import { MaterialTokens } from "@glare-labs/material-tokens-generator";

const theme = new MaterialTokens(Hct.from(140, 90, 50), {
    isDark: false,
});

/**
 * @output
 * ```
 * --md-sys-color-primary-palette-key-color: #278900;
 * --md-sys-color-secondary-palette-key-color: #578245;
 * ...
 * --md-sys-color-on-tertiary-fixed: #001e2b;
 * --md-sys-color-on-tertiary-fixed-variant: #004d67;
 * ```
 */
console.log(theme.cssText());

Generate Palettes

For example:

import { MaterialPalettes } from "@glare-labs/material-tokens-generator";

const palettes = new MaterialPalettes(Hct.from(120, 90, 70), {
    isDark: true,
});

/**
 * @output
 * ```
 * --md-sys-palette-primary-0: #000000;
 * --md-sys-palette-secondary-0: #000000;
 * ...
 * --md-sys-palette-neutral-100: #ffffff;
 * --md-sys-palette-neutralVariant-100: #ffffff;
 * ```
 */
console.log(palettes.cssText());

API

| Classes | Features | | :-------------------------------------------- | --------------------------------------------------------: | | MaterialTokens, MaterialDynamicTokens | Used to create tokens like --md-sys-color-primary. | | MaterialPalettes, MaterialDynamicPalettes | Used to create tokens like --md-sys-palette-primary-40. |

constructor

| Param | Option | Type | Required | | :------------- | :-------------------- | :-------------------------------------------- | -------: | | sourceColorHct | | string | Yes | | options | isDark | boolean | No | | options | variant | 0 \| 1 \| 2 \| 3 \| 4 \| 5 \| 6 \| 7 \| 8 | No | | options | contrastLevel | -1.0 \| 0 \| 0.5 \| 1.0 | No | | options | prefix | string | No | | options | excludedTokens | Array<keyof TMaterialColors> | No | | options | customTokens | Record<keyof TMaterialColors, DynamicColor> | No | | options | primaryPalette | TonalPalette | No | | options | secondaryPalette | TonalPalette | No | | options | tertiaryPalette | TonalPalette | No | | options | neutralPalette | TonalPalette | No | | options | neutralVariantPalette | TonalPalette | No | | options | levels | Array<number> | No |

new MaterialTokens(Hct.from(140, 90, 50));
new MaterialTokens(Hct.from(140, 90, 50), {
    prefix: "my-color",
    variant: EMaterialVariant.Content,
    isDark: true,
    contrastLevel: 0,
    excludedTokens: ["surfaceTint"],
});

new MaterialPalettes(Hct.from(75, 90, 75));
new MaterialPalettes(Hct.from(75, 90, 75), {
    contrastLevel: 0,
    isDark: false,
    levels: [0, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100],
    prefix: "my-palette",
    variant: EMaterialVariant.Rainbow,
});

new MaterialDynamicPalettes({});
new MaterialDynamicPalettes({
    sourceColorHct: Hct.from(75, 90, 75),
    contrastLevel: 0,
    isDark: false,
    levels: [0, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100],
    prefix: "my-palette",
    variant: EMaterialVariant.Rainbow,
    primaryPalette: TonalPalette.fromHueAndChroma(200, 75),
    secondaryPalette: TonalPalette.fromHueAndChroma(120, 75),
    tertiaryPalette: TonalPalette.fromHueAndChroma(140, 75),
    neutralPalette: TonalPalette.fromHueAndChroma(180, 25),
    neutralVariantPalette: TonalPalette.fromHueAndChroma(200, 35),
});

tokens

const theme = new MaterialTokens(Hct.from(140, 90, 50));
const tokens = theme.tokens();
/**
 * @output
 * ```
 * {
 *      background: "#f5fcec",
 *      error: "#ba1a1a",
 *      ...
 *      tertiaryFixedDim: "#77d1fe",
 *      tertiaryPaletteKeyColor: "#0080a9",
 * }
 * ```
 */
console.log(tokens);

/**
 * @output
 * #f5fcec
 */
console.log(tokens.surface);

cssPropertyRecord

const theme = new MaterialTokens(Hct.from(140, 90, 50));

/**
 * @output
 * ```
 * {
 *      background: {
 *          "name": "--md-sys-color-background",
 *          "value": {
 *              "name": "--md-sys-color-background",
 *              "initialValue": "#f5fcec",
 *              "inherits": false,
 *           "syntax": "<color>"
 *           }
 *      }
 *      ...
 * }
 * ```
 */
console.log(theme.cssPropertyRecord());

cssPropertyText

const theme = new MaterialTokens(Hct.from(140, 90, 50));

/**
 * @output
 * ```
 * @property --md-sys-color-primary-palette-key-color { initial-value: #278900; syntax: <color>; inherits: false; }
 * ...
 * @property --md-sys-color-on-tertiary-fixed-variant { initial-value: #004d67; syntax: <color>; inherits: false; }
 * ```
 */
console.log(theme.cssPropertyText());

cssRecord

const theme = new MaterialTokens(Hct.from(140, 90, 50));

/**
 * @output
 * ```
 * {
 *      background: {
 *          "name": "--md-sys-color-background",
 *          "value": "#f5fcec"
 *      },
 *      ...
 * }
 * ...
 * @property --md-sys-color-on-tertiary-fixed-variant { initial-value: #004d67; syntax: <color>; inherits: false; }
 * ```
 */
console.log(theme.cssRecord());

cssText

const theme = new MaterialTokens(Hct.from(140, 90, 50));

/**
 * @output
 * ```
 * --md-sys-color-primary-palette-key-color: #278900;
 * ...
 * --md-sys-color-on-tertiary-fixed-variant: #004d67;
 * ```
 */
console.log(theme.cssText());