Skip to content

API reference

defineSystem

A system owns the typed token vocabulary, conditions and namespace used by its sheets. Keep the complete returned object for renderers and builds.

system.ts
import { defineSystem, defineToken } from '@toned/core'

export const ui = defineSystem({
  id: 'controls',
  tokens: {
    opacity: defineToken({
      values: [0, 0.5, 1] as const,
      resolve: opacity => ({ opacity }),
    }),
    padding: defineToken({
      values: [2, 4] as const,
      resolve: step => ({ padding: step * 4 }),
    }),
  },
  conditions: {
    media: { compact: 640, wide: 1024 },
    containers: { field: { wide: 448 } },
  },
})

export const { stylesheet } = ui

Sheets import stylesheet from this module. It is bound to the system, so token values and the conditions declared above are checked where they are used:

styles.ts
import { stylesheet } from './system.ts'

export const styles = stylesheet(q => ({
  Root: {
    opacity: 0.5,
    padding: 2,
    [q.media('wide')]: { opacity: 1 },
    [q.container('field', 'wide')]: { padding: 4 },
  },
}))

Token and condition contracts

Token properties use camelCase; named values use kebab-case. Resolvers translate semantic values into output fields and may read the current token snapshot. Declarations and compiled matching plans are immutable.

Descriptor-system media and container thresholds are fixed logical pixels. Query preludes cannot read CSS custom properties. Colocated conditions use the same typed builder in base and variant declarations.

Use the complete system

build.ts
import { buildStyles } from '@toned/core/build'
import { createWebRenderer } from '@toned/core/server'
import { styles } from './styles.ts'
import { ui } from './system.ts'

const artifact = buildStyles(ui, { sheets: [styles] })
const renderer = createWebRenderer(ui, { manifest: artifact.manifest })
const props = renderer.resolve(styles)

The system property is the raw token dictionary. Retaining only that property loses the system's configuration and identity; pass ui to new build/render integrations.

Compatibility

The two-argument defineSystem(tokens, config) form creates a system without a namespace. It composes vocabularies that read unprefixed custom properties, such as @toned/systems/base (see the React web guide), and keeps its spacing-scale container steps for existing consumers. The t utility remains available too. New components should use named sheets and explicit bindings rather than introduce new ambient inline-token calls.