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

@toned/core

v0.1.0

Published

Minimal core utilities for defining token systems, building stylesheets and runtime style matching rules.

Readme

@toned/core

Minimal core utilities for defining token systems, building stylesheets and runtime style matching rules.

Quick start

  1. Define tokens and units
import { defineToken, defineUnit, defineSystem } from '@toned/core'
  1. Create a system
const color = defineToken({
  values: ['red','blue'] as const,
  resolve: (v) => ({ color: v }),
})

const system = defineSystem({ color })
  1. Optional - inject generated CSS to DOM (browser)
import { generate, inject } from '@toned/core/dom'

const css = generate(system) // returns CSS string
inject(system) // injects into <style id="toned/main">

Stylesheet API

Basic Usage

Create stylesheets with element definitions:

import { stylesheet } from '@toned/systems/base'

export const styles = stylesheet({
  container: {
    textColor: 'on_action',
    bgColor: 'default',
    alignItems: 'flex-start',
    flexLayout: 'column',
  },
  label: { textColor: 'destructive' },
})

Pseudo Classes (Self-Styling)

Add pseudo classes that only affect the element they're defined in:

const styles = stylesheet({
  button: {
    bgColor: 'primary',
    // Pseudo class only affects button itself
    ':hover': {
      bgColor: 'primary_hover',
    },
    ':active': {
      bgColor: 'primary_active',
    },
  },
  label: {
    textColor: 'white',
  },
})

Cross-Element Pseudo Classes

Use flat selectors to affect multiple elements when an element's pseudo state changes:

const styles = stylesheet({
  button: { bgColor: 'primary' },
  icon: { color: 'white' },
  label: { textColor: 'white' },

  // When button is hovered, both button and label change
  'button:hover': {
    button: { bgColor: 'primary_hover' },
    label: { textColor: 'primary_text' },
  },

  // Multiple pseudo classes (must be in alphabetical order)
  'button:active:hover': {
    icon: { color: 'accent' },
  },
})

Breakpoints

Add responsive styles using breakpoint selectors:

const styles = stylesheet({
  container: {
    paddingX: 2,
    // Breakpoint for small screens
    '@sm': {
      paddingX: 4,
    },
    '@md': {
      paddingX: 6,
    },
  },
})

Variants

Use the .variants() chain with a callback for type-safe variant definitions:

const styles = stylesheet({
  container: {
    bgColor: 'default',
    borderRadius: 'medium',
  },
  label: {
    textColor: 'primary',
  },
}).variants<{
  size: 'sm' | 'md' | 'lg'
  variant: 'primary' | 'secondary' | 'danger'
}>(($) => ({
  // Single variant
  [$.size('sm')]: {
    container: { paddingX: 2, paddingY: 1 },
    label: { fontSize: 'small' },
  },

  [$.size('md')]: {
    container: { paddingX: 4, paddingY: 2 },
    label: { fontSize: 'medium' },
  },

  [$.variant('primary')]: {
    container: { bgColor: 'action' },
    label: { textColor: 'on_action' },
  },

  [$.variant('danger')]: {
    container: { bgColor: 'destructive' },
    label: { textColor: 'on_destructive' },
  },

  // Combined variants (order doesn't matter - keys are stable)
  [$.size('sm').variant('primary')]: {
    container: { borderColor: 'primary_border' },
  },
}))

Named Styles and Composition

Use $("name") to define reusable named styles, and $compose to compose them:

const styles = stylesheet({
  centered: {
    justifyContent: 'center',
    alignItems: 'center',
  },
  container: {
    borderRadius: 'medium',
  },
  label: {
    textColor: 'primary',
  },
}).variants<{
  size: 'm' | 's'
  variant: 'accent' | 'danger'
}>(($) => ({
  // Named style definition
  [$('base_button')]: {
    container: { borderWidth: 'thin' },
    label: { fontWeight: 'bold' },
  },

  [$.variant('accent')]: {
    // Compose named style at variant level
    $compose: 'base_button',
    container: {
      bgColor: 'action',
      // Compose elements at element level
      $compose: ['centered'],
    },
    label: {
      textColor: 'on_action',
    },
  },

  // Multi-value selectors (OR semantics)
  [$.size('m').variant('accent', 'danger')]: {
    container: { paddingX: 4 },
  },
}))

Using Styles in React

import { useStyles } from '@toned/react'
import { styles } from './styles'

function Button({ size = 'md', variant = 'primary' }) {
  const s = useStyles(styles, { size, variant })

  return (
    <button {...s.container}>
      <span {...s.label}>Click me</span>
    </button>
  )
}

Type Safety

The API provides full type inference for:

  • Token properties (autocomplete for valid token values)
  • Element names (autocomplete when referencing elements)
  • Pseudo classes (:hover, :active, :focus)
  • Breakpoints (from system configuration)
  • Variant selectors (from .variants<T>() type parameter)

API Reference

stylesheet(rules)

Creates a stylesheet with element definitions.

Parameters:

  • rules - Object with element keys and their token styles

Returns: Pre-variants stylesheet with .variants() method

.variants<Mods>(callback)

Adds variant-based styles to a stylesheet using a type-safe callback.

Type Parameter:

  • Mods - Object type defining variant names and their possible values

Parameters:

  • callback - Function receiving $ selector proxy, returning variant rules

Returns: Final stylesheet ready for use with useStyles

Variant Selector ($) API

| Selector | Description | Example | |----------|-------------|---------| | $("name") | Named style definition | [$("base")]: { ... } | | $.key("value") | Single variant | [$.size("sm")]: { ... } | | $.key("v1", "v2") | Multi-value (OR) | [$.size("sm", "md")]: { ... } | | $.k1("v1").k2("v2") | Combined variants | [$.size("sm").variant("primary")]: { ... } |

Composition ($compose)

| Level | Composes | Example | |-------|----------|---------| | Variant level | Named styles | $compose: "base_button" | | Element level | Other elements | $compose: ["centered", "flex"] |

Base Selector Syntax

| Selector | Description | Example | |----------|-------------|---------| | element | Element definition | container: { ... } | | :pseudo | Pseudo class (self only) | ':hover': { ... } | | @breakpoint | Breakpoint (self only) | '@sm': { ... } | | element:pseudo | Cross-element pseudo | 'container:hover': { ... } |