# zRuntime Reference

> Extracted directly from `src/js/runtime/` and `registry/runtime/`. For token-efficient AI consumption, start with [runtime.compact.md](https://next.0build.dev/docs/runtime.compact.md).

## `window.zRuntime` API

| Property / Method | Kind | Signature | Description |
| --- | --- | --- | --- |
| `zRuntime.debug` | config | `boolean (default: false)` | Boolean flag enabling per-plugin diagnostics in the browser console during development. |
| `zRuntime.customRules` | config | `Rule[]` | Array of custom `Rule` definitions merged ahead of style generation (matching selectors replace built-ins). |
| `zRuntime.safelist` | config | `(string \| SafelistDescriptor)[]` | Array of class strings or descriptor objects to pre-generate even when absent from the initial DOM. |
| `zRuntime.refresh` | method | `() => void` | Clears the internal rule cache and runs style generation from scratch. |
| `zRuntime.regenerate` | method | `() => void` | Re-runs style generation while preserving the existing rule cache. |
| `zRuntime.getCache` | method | `() => Map<string, CssRule>` | Returns the internal `Map` of compiled CSS rules keyed by class, state, theme, and breakpoint. |
| `zRuntime.getRules` | method | `() => Rule[]` | Returns the merged array of active built-in and custom `Rule` definitions. |
| `zRuntime.decoder` | helper | `function` | Parses a raw utility class token into a structured `ParsedClass` descriptor. |
| `zRuntime.encoder` | helper | `function` | Serializes a `ParsedClass` descriptor back into a utility class token string. |
| `zRuntime.escaper` | helper | `function` | Escapes special CSS selector characters (such as `:`, `[`, `]`, `/`) for generated rules. |
| `zRuntime.variable` | helper | `function` | Computes the expected CSS custom property name for a class, breakpoint, theme, and state. |

## DOM Events

| Event | Description |
| --- | --- |
| `z-runtime:init` | Dispatched on `document` when the CLS-prevention plugin initializes. |
| `z-runtime:ready` | Dispatched on `document` after runtime styles have been injected and `z-not-ready` has swapped to `z-ready`. |

## Breakpoints

| Prefix | Min-width |
| --- | --- |
| `sm:` | `40rem` |
| `md:` | `48rem` |
| `lg:` | `64rem` |
| `xl:` | `80rem` |
| `2xl:` | `96rem` |

## Pseudo-classes

`:hover`, `:active`, `:focus`, `:focus-visible`, `:focus-within`, `:target`, `:checked`, `:disabled`, `:group-hover`

## Pseudo-elements

`::before`, `::after`

## Colors & Intensities

- **Colors (26):** `red`, `orange`, `amber`, `yellow`, `lime`, `green`, `emerald`, `teal`, `cyan`, `sky`, `blue`, `indigo`, `violet`, `purple`, `fuchsia`, `pink`, `rose`, `slate`, `gray`, `zinc`, `neutral`, `stone`, `taupe`, `mauve`, `mist`, `olive`
- **Intensities (11):** `50`, `100`, `200`, `300`, `400`, `500`, `600`, `700`, `800`, `900`, `950`
- **Cascade layers:** `@layer components`, `@layer styles`, `@layer utilities`

## Built-in Plugins (Execution Order)

| Plugin | Source | Hooks | Config Keys | Events | Description |
| --- | --- | --- | --- | --- | --- |
| `cls-prevention` | `src/js/runtime/plugins/cls-prevention.ts` | `onInit`, `onAfterInject` | — | `z-runtime:init`, `z-runtime:ready` | Dispatches `z-runtime:init` / `z-runtime:ready` and swaps `z-not-ready` to `z-ready` on `<html>` after CSS injection. |
| `custom-rules` | `src/js/runtime/plugins/custom-rules.ts` | `onRulesLoad` | `customRules` | — | Validates and merges `window.zRuntime.customRules` into the active rule list. |
| `inline-vars` | `src/js/runtime/plugins/inline-vars.ts` | `onElementScan` | — | — | Expands `class=value` shorthands (colors, `/o` opacity, auto-bracketed scale redirects) into inline CSS variables and reports missing variables in debug mode. |
| `dom-extractor` | `src/js/runtime/plugins/dom-extractor.ts` | `onElementScan` | — | — | Scans `[class]` elements for interactive pseudo-class/pseudo-element tokens and warns when paired `content-before`/`content-after` classes are missing. |
| `safelist` | `src/js/runtime/plugins/safelist.ts` | `onAdditionalClasses` | `safelist` | — | Expands `window.zRuntime.safelist` strings and `{ class, states, prefixes, dark }` combinations into compiled classes. |
| `arbitrary-properties` | `src/js/runtime/plugins/arbitrary-properties.ts` | `onElementScan` | — | — | Parses `[property]={value}` tokens (including dark, breakpoint, and state variants) and registers one-off rules into `@layer utilities`. |

## `ZRuntimePlugin` Lifecycle Hooks

| Hook | Signature | Description |
| --- | --- | --- |
| `onInit` | `(core: ZRuntimeCore) => void` | Runs immediately when a plugin is registered via `.use(plugin)`. |
| `onRulesLoad` | `(rules: Rule[], core: ZRuntimeCore) => Rule[]` | Transforms or extends the active `Rule[]` array at the start of `generate()`. |
| `onElementScan` | `(element: Element, rules: Rule[], core: ZRuntimeCore) => ParsedClass[]` | Inspects each `[class]` DOM element and returns `ParsedClass[]` entries to compile. |
| `onAdditionalClasses` | `(core: ZRuntimeCore) => ParsedClass[]` | Provides extra `ParsedClass[]` entries not present in the DOM (such as safelists). |
| `onBeforeInject` | `(generatedCss: GeneratedCSS, core: ZRuntimeCore) => GeneratedCSS` | Transforms the grouped `GeneratedCSS` layers right before `<style>` injection. |
| `onAfterInject` | `(core: ZRuntimeCore) => void` | Runs after `<style id="z-interactive-styles">` has been updated. |

## `Rule` Interface Fields

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `selector` | `string` | ✓ | Base utility class name this rule matches (for example `opacity` or `[m]`). |
| `properties` | `string \| string[]` | ✓ | CSS property name or ordered array of property names emitted by the rule. |
| `dark` | `boolean` | — | Whether the rule generates `.dark` scoped variants. |
| `placeholders` | `Record<string, string>` | — | Map of template placeholder tokens (for example `{var}`) in `values` to variable base names. |
| `layer` | `string` | — | Target CSS cascade layer: `components`, `styles` (default), or `utilities`. |
| `impliedPseudo` | `string` | — | Optional pseudo-selector suffix automatically appended to generated rules. |
| `fallback` | `string` | — | Optional CSS fallback value placed inside `var(--name, fallback)` when `arbitrary: true`. |
| `arbitrary` | `boolean` | — | When `true`, emits `var(--...)` directly from the computed CSS variable instead of static `values`. |
| `values` | `string[]` | ✓ | CSS value template(s) corresponding to `properties` (required unless `arbitrary: true`). |

## Cascade Layers

Generated rules are grouped in order: `@layer components` → `@layer styles` → `@layer utilities`.
