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

rainbowindex

v0.1.4

Published

A production-ready CSS compiler with utility-first approach

Readme

rainbowindex

The core CSS compiler for Rainbow Index. This package handles parsing, transformation, and generation—everything needed to turn utility classes into CSS.

The compiler has zero runtime dependencies and uses a custom CSS parser. Most projects will interact with Rainbow Index through the Vite plugin or CLI, but direct access to the compiler is useful for building custom tooling or understanding how the system works.

Installation

npm install rainbowindex

Usage

Compile Classes

The most common operation: turn a list of utility class names into CSS.

import { compileClasses, createDesignSystem } from "rainbowindex";

const designSystem = createDesignSystem();

const result = compileClasses(["p-4", "bg-blue-500", "hover:bg-blue-600"], {
    designSystem,
});

console.log(result.css);
// .p-4 { padding: 1rem; }
// .bg-blue-500 { background-color: oklch(55.3% 0.213 253.075); }
// .hover\:bg-blue-600:hover { background-color: oklch(47.4% 0.195 251.802); }

Parse and Print CSS

The parser produces an AST that can be inspected, transformed, or printed back to a string. This is useful for tools that need to analyze or modify CSS programmatically.

import { parse, print } from "rainbowindex";

const { ast } = parse(`
  .button {
    padding: 1rem;
    background: blue;
  }
`);

const output = print(ast);

Transform CSS with Theme

When processing CSS that contains Rainbow Index directives (@theme, @apply, etc.), use transformCSS to expand them.

import { parse, transformCSS, createDesignSystem, print } from "rainbowindex";

const designSystem = createDesignSystem();

const { ast } = parse(`
  @theme {
    --color-primary: oklch(0.6 0.2 250);
  }

  .button {
    background: var(--color-primary);
  }
`);

const transformed = transformCSS(ast, { designSystem });
const output = print(transformed);

Directive Handling

Rainbow Index processes @rainbowindex directives as injection points for generated styles. Unknown at-rules (including @tailwind) are preserved and pass through unchanged, rather than being treated as migration inputs.

API Reference

compileClasses(candidates, options)

Compile utility class names into CSS.

interface CompileOptions {
    designSystem: DesignSystem;
}

interface CompileResult {
    css: string;
    classes: string[];
}

createDesignSystem()

Create a design system instance with the default theme, utilities, and variants. The design system is the central registry that maps class names to CSS output.

interface DesignSystem {
    theme: Theme;
    utilities: Utilities;
    variants: Variants;
    parseCandidate(candidate: string): Candidate[];
    compileAstNodes(candidate: Candidate): AstNode[];
    getClassOrder(classes: string[]): [string, bigint | null][];
}

parse(css, options?)

Parse a CSS string into an AST.

interface ParseOptions {
    from?: string; // Source file path for source maps
}

interface ParseResult {
    ast: AstNode[];
}

print(ast, options?)

Convert an AST back to a CSS string.

interface PrintOptions {
    minify?: boolean;
    indent?: string;
}

transformCSS(ast, options)

Transform a CSS AST, processing @theme, @apply, and other directives.

interface TransformOptions {
    designSystem: DesignSystem;
}

Default Theme

The default theme provides a comprehensive set of design tokens:

Colors — Full OKLCH palette: gray, red, orange, amber, yellow, lime, green, emerald, teal, cyan, sky, blue, indigo, violet, purple, fuchsia, pink, rose.

Spacing — Scale from 0 to 96: 0, 0.5, 1, 1.5, 2, 2.5, 3, 3.5, 4, 5, 6, 7, 8, 9, 10, 11, 12, 14, 16, 20, 24, 28, 32, 36, 40, 44, 48, 52, 56, 60, 64, 72, 80, 96.

Typography — Font sizes, weights, and line heights.

Breakpoints — Numeric (rem-based) and named.

Utilities

Core utilities included:

  • Spacing: p-*, m-*, gap-*, space-*
  • Sizing: w-*, h-*, min-w-*, max-w-*, min-h-*, max-h-*
  • Colors: bg-*, text-*, border-*
  • Typography: font-*, text-*, leading-*, tracking-*
  • Layout: flex, grid, block, inline, hidden
  • Flexbox: flex-*, items-*, justify-*, grow-*, shrink-*
  • Grid: grid-cols-*, grid-rows-*, col-span-*, row-span-*
  • Effects: shadow-*, opacity-*, blur-*
  • Borders: rounded-*, border-*

Variants

Built-in variants:

  • Pseudo-classes: hover, focus, active, visited, disabled, first, last, odd, even
  • Pseudo-elements: before, after, placeholder, selection
  • Media: dark, numeric breakpoints (48:, 64:, etc.)
  • Compound: group-*, peer-*
  • Data/Aria: data-*, aria-*

License

MIT