@keypuncherlabs/style-accelerator
v0.0.4
Published
Convert a W3C Design Tokens (DTCG) file into a scoped variables.css, with one CSS scope per context.
Maintainers
Readme
style-accelerator
Convert a W3C Design Tokens (DTCG) file into a scoped
variables.css — one CSS scope per context (e.g. :root, .dark, .light). Token
references are resolved to literal values, and every non-base context is emitted as an
override-only block.
The core is isomorphic (browser / edge / Node) and imports no node:*. An optional Node
entry and a CLI add file-system conveniences for build-time generation.
Install
npm install @keypuncherlabs/style-acceleratorUsage
Core — tokensToCss (isomorphic, no file system)
import { tokensToCss, type DtcgNode } from "@keypuncherlabs/style-accelerator"
const css: string = tokensToCss(tokens)
const hexCss = tokensToCss(tokens, { colorFormat: "hex" })Node — generateVariablesCss (reads/writes files)
import { generateVariablesCss } from "@keypuncherlabs/style-accelerator/node"
// reads ./design-tokens.json, writes ./variables.css
await generateVariablesCss({ input: "design-tokens.json" })CLI
style-accelerator build [options]Auto-loads a radium.json config from the working directory when present. Run
style-accelerator --help for all options.
API
- Core (
.):tokensToCss,emitCss,resolveCssOptions,getContexts,formatContextsModule,getFonts,formatFontsModule, theDEFAULT_CONTEXTS/DEFAULT_NAME_EXTENSIONdefaults, plus the related types. - Node (
./node): everything above, plusgenerateVariablesCssandresolveOptions.
License
MIT
