Skip to content

Extending CROFF

Plugin API reference

The public types and functions.

Plugin APIs are exported from @croff/core.

Stability

Before 1.0, any release can change anything, including the language itself. Nothing below is final.

APIStatus
Utility expressions and the grammarNot final. Changes will be called out in the changelog.
@croff directives, defineConfig, config options, CLI commandsIntended to stay. Changes will be called out in the changelog.
createCroff and its compile and processCss methodsIntended to stay.
parse, expand, the AST and compiled rule shapesUnstable, marked @unstable in the code.
definePlugin, values, utility and variant definitionsUnstable, marked @unstable in the code.
Project, RegistryUnstable, marked @unstable in the code.

Your editor shows @unstable when you hover over one of these. The other @croff/* packages are implementation details: use them through @croff/core.

definePlugin

ts
function definePlugin(plugin: CroffPlugin): CroffPlugin;

CroffPlugin

FieldTypePurpose
namestringRequired. A package-style name, by convention croff-plugin-*.
apiVersionnumberThe targeted plugin API version. Defaults to the current one.
themeThemeConfigTokens and scales.
utilitiesRecord<string, PluginUtility>New utilities, by name.
variantsRecord<string, PluginVariant>New variants, by name.
overridebooleanAllow replacing existing definitions.

PluginUtility

FieldTypePurpose
descriptionstringRequired. Shown in generated docs.
argsArgumentSpec[]Positional arguments. Omit to disable the call form.
propertiesstring[]Properties set to the single resolved value.
compile(input: UtilityInput) => DeclarationsCustom output. Use this or properties.
arbitrarystring[], a function or falseProperties for the bracket form, or a function from the value to declarations. Defaults to properties.
categorystringDocumentation category. Defaults to "plugins".
examplesstring[]Valid example expressions.
notesstringExtra guidance.

PluginVariant

FieldTypePurpose
selectorstringA selector template containing &.
atRulestringAn at-rule, starting with @.
descriptionstringShown in generated docs.

createCroff

The engine, without any file access. It's safe to use in a browser.

ts
import { createCroff } from "@croff/core";

const croff = createCroff({ theme: { colors: { accent: "#ff5c00" } } });
const { css, rules, failures } = croff.compile(["bg(accent)", "md:gap(4)"]);
MemberPurpose
compile(inputs, options)Compiles expressions into CSS. Takes minify, variables, layers, sourceMap and file.
processCss(css, inputs, options)Replaces @croff directives in a stylesheet. Takes minify.
themeThe resolved theme.
registryThe registry, for inspecting utilities and variants.
issuesTheme problems, with { strict: false }.

Project

@croff/core/node adds files on top of the engine. Integrations are built on this.

ts
import { Project } from "@croff/core/node";

const project = await Project.load({ cwd: process.cwd() });
await project.scan();
const { css, diagnostics } = await project.generate({ minify: true });
MemberPurpose
Project.load(options)Loads the config. Takes cwd, configPath and overrides.
scan()Scans, reading only changed files.
updateFile(path)Rescans one file.
generate(options)Compiles what's been found, with diagnostics.
processCss(css, options)Replaces directives, with diagnostics.
watch(onChange, onError)Watches content files.