cn, cvimport { reset } from "@cssints/reset" with { type: "cssints" };
import { bg, cn, flex, p } from "cssints" with { type: "cssints" };
import { button } from "./button.tsx";
reset();
// cn() merges at build time what it can; a runtime argument (a prop) stays a choice made when the code runs, and the later
// part replaces the earlier one it overrides: `p(4)` replaces `p(2)` while `roomy` is true.
const toolbar = (props: { roomy?: boolean; quiet?: boolean }) =>
cn(
flex().alignItems("center").gap(2),
p(2),
props.roomy && p(4),
props.quiet ? bg("#f1f5f9") : bg("#e0e7ff"),
);
export default function App() {
return (
<div className={cn(flex().direction("column").gap(3), p(4))}>
<div className={toolbar({})}>
<button className={button()}>Save</button>
<button className={button({ tone: "danger", size: "lg" })}>Delete</button>
</div>
<div className={toolbar({ roomy: true, quiet: true })}>
<button className={button({ disabled: true })}>Save</button>
<button className={button({ tone: "danger", disabled: true })}>Delete</button>
</div>
</div>
);
}import {
bg,
borderRadius,
cn,
color,
cursor,
cv,
fontSize,
hover,
opacity,
p,
} from "cssints" with { type: "cssints" };
// cv() takes css values and returns the function you call: the props are typed from the variants.
export const button = cv({
base: cn(p(2), borderRadius("8px"), fontSize("1rem"), cursor("pointer"), color("white")),
variants: {
tone: {
primary: cn(bg("#2563eb"), hover(bg("#1d4ed8"))),
danger: cn(bg("#dc2626"), hover(bg("#b91c1c"))),
},
size: { sm: fontSize("0.875rem"), lg: cn(p(4), fontSize("1.25rem")) },
disabled: { true: opacity(0.5), false: opacity(1) },
},
defaultVariants: { tone: "primary", size: "sm", disabled: false },
compoundVariants: [{ tone: "danger", disabled: true, class: opacity(0.3) }],
});cssints itself. You import nothing for the browser. A module with a cn() that has runtime arguments, or a cv()/scv(), gets import { _cx as __cx, _cv as __cv, _scv as __scv } from "cssints" from the plugin (the ones it needs), and those few lines are the only code that ships. @cssints/variants is gone.cn(...) is the one function that merges. Arguments known at build time merge into one class string, as above. An argument that depends on a runtime value is joined when the code runs, and the css.* calls inside it are still class strings made at build time: only the choice is left.import { const bg: Prop<"background-color">`<color>`. Chrome 1, Edge 12, Firefox 1, Safari 1, iOS 1, Android 18. [MDN](https://developer.mozilla.org/docs/Web/CSS/background-color)bg, function cn(...styles: Style[]): Style (+1 overload)Merges styles into one class string. What is known at build time merges (the later property wins); a runtime value
(`on && p(4)`, `props.class`, a state call) is joined when the code runs, and a style in it replaces the classes it
overrides while it is active.cn, const hover: StateWrapChrome 1, Edge 12, Firefox 1, Safari 2, iOS 1, Android 18. [MDN](https://developer.mozilla.org/docs/Web/CSS/:hover)hover, const p: Prop<"padding">`<'padding-top'>{1,4}`. Chrome 1, Edge 12, Firefox 1, Safari 1, iOS 1, Android 18. [MDN](https://developer.mozilla.org/docs/Web/CSS/padding)p } from "cssints" with { type: "cssints" };
export const const box: (props: {
on: boolean;
class?: string;
}) => string
box = (props: {
on: boolean;
class?: string;
}
props: { on: booleanon: boolean; class?: string | undefinedclass?: string }) =>
function cn(...parts: ClassValue[]): string (+1 overload)Merges styles into one class string. What is known at build time merges (the later property wins); a runtime value
(`on && p(4)`, `props.class`, a state call) is joined when the code runs, and a style in it replaces the classes it
overrides while it is active.cn(p<readonly [2]>(parts_0: 2): Style`<'padding-top'>{1,4}`. Chrome 1, Edge 12, Firefox 1, Safari 1, iOS 1, Android 18. [MDN](https://developer.mozilla.org/docs/Web/CSS/padding)p(2), bg<readonly ["white"]>(parts_0: "white"): Style`<color>`. Chrome 1, Edge 12, Firefox 1, Safari 1, iOS 1, Android 18. [MDN](https://developer.mozilla.org/docs/Web/CSS/background-color)bg("white"), props: {
on: boolean;
class?: string;
}
props.on: booleanon && p<readonly [4]>(parts_0: 4): Style`<'padding-top'>{1,4}`. Chrome 1, Edge 12, Firefox 1, Safari 1, iOS 1, Android 18. [MDN](https://developer.mozilla.org/docs/Web/CSS/padding)p(4), function hover(...styles: Style[]): StyleChrome 1, Edge 12, Firefox 1, Safari 2, iOS 1, Android 18. [MDN](https://developer.mozilla.org/docs/Web/CSS/:hover)hover(bg<readonly ["#eee"]>(parts_0: "#eee"): Style`<color>`. Chrome 1, Edge 12, Firefox 1, Safari 1, iOS 1, Android 18. [MDN](https://developer.mozilla.org/docs/Web/CSS/background-color)bg("#eee")), props: {
on: boolean;
class?: string;
}
props.class?: string | undefinedclass);
export const const row: (kind: "a" | "b", items: boolean[]) => stringrow = (kind: "a" | "b"kind: "a" | "b", items: boolean[]items: boolean[]) =>
function cn(...parts: ClassValue[]): string (+1 overload)Merges styles into one class string. What is known at build time merges (the later property wins); a runtime value
(`on && p(4)`, `props.class`, a state call) is joined when the code runs, and a style in it replaces the classes it
overrides while it is active.cn(
p<readonly [1]>(parts_0: 1): Style`<'padding-top'>{1,4}`. Chrome 1, Edge 12, Firefox 1, Safari 1, iOS 1, Android 18. [MDN](https://developer.mozilla.org/docs/Web/CSS/padding)p(1),
kind: "a" | "b"kind === "a" ? p<readonly [2]>(parts_0: 2): Style`<'padding-top'>{1,4}`. Chrome 1, Edge 12, Firefox 1, Safari 1, iOS 1, Android 18. [MDN](https://developer.mozilla.org/docs/Web/CSS/padding)p(2) : bg<readonly ["red"]>(parts_0: "red"): Style`<color>`. Chrome 1, Edge 12, Firefox 1, Safari 1, iOS 1, Android 18. [MDN](https://developer.mozilla.org/docs/Web/CSS/background-color)bg("red"),
items: boolean[]items.Array<boolean>.map<false | Style>(callbackfn: (value: boolean, index: number, array: boolean[]) => false | Style, thisArg?: any): (false | Style)[]Calls a defined callback function on each element of an array, and returns an array that contains the results.map((x: booleanx) => x: booleanx && p<readonly [3]>(parts_0: 3): Style`<'padding-top'>{1,4}`. Chrome 1, Edge 12, Firefox 1, Safari 1, iOS 1, Android 18. [MDN](https://developer.mozilla.org/docs/Web/CSS/padding)p(3)),
);
export const const bad: (n: number) => Stylebad = (n: numbern: number) => function cn(...styles: Style[]): Style (+1 overload)Merges styles into one class string. What is known at build time merges (the later property wins); a runtime value
(`on && p(4)`, `props.class`, a state call) is joined when the code runs, and a style in it replaces the classes it
overrides while it is active.cn(p<readonly [2]>(parts_0: 2): Style`<'padding-top'>{1,4}`. Chrome 1, Edge 12, Firefox 1, Safari 1, iOS 1, Android 18. [MDN](https://developer.mozilla.org/docs/Web/CSS/padding)p(2), p<readonly [number]>(parts_0: number): Style`<'padding-top'>{1,4}`. Chrome 1, Edge 12, Firefox 1, Safari 1, iOS 1, Android 18. [MDN](https://developer.mozilla.org/docs/Web/CSS/padding)p(n: numbern)); // the build refuses it: css arguments must be known at build timeimport { _cx as __cx } from "cssints";
export const box = (props) =>
__cx([["_lwugp7", "_1t8gqy5"]], "_1t8gqy5 _1ebepn0 _16f8jrr", props.on && "_lwugp7", props.class);on && p(4), cond ? a : b, state() && p(4), props.class, items.map(...)), or a string or template literal, or a call of something that is not a css.* member (button({ size }), a cv result: a class string at build time too). Everything else is known at build time, a module const too, and merges. A spread (...list) is judged by what it spreads. Strings, false, null, undefined and 0 are skipped, arrays are flattened; there are no clsx-style objects (cond && style). A false, null or undefined that is known at build time (dev && p(4) with a module const dev = false) is no style and is skipped there.cv): the plugin lists, per class, the classes it drops, and the runtime leaves them out while that class is active. So cn(p(2), on && p(4)) gives p-4 when on and p-2 otherwise, and cn(on && p(4), p(2)) always gives p-2. The sheet order never decides. Under another condition (hover, a media query) a class replaces nothing: cn(p(2), on && hover(p(4))) keeps both, as in a build-time cn. A longhand after a shorthand needs no drop. Two properties that overlap without one containing the other, in parts that can be active together, are a build error as above (cssints: cn() padding-inline and padding-left overlap ...); both arms of cond ? a : b count as active together.props.class, "legacy" or a style held in a variable inside a runtime argument (on && blurred) has no declarations in the argument, so nothing is dropped for it or by it; write the call there (on && p(4)) to have it settled.cn(p(2), p(n)) with n a parameter stays css arguments must be known at build time: n is not defined where the call is evaluated; choose between styles (n > 1 ? p(2) : p(4)), or use a cv variant or a token set in style.__cx(drops, ...parts): drops is a list of [class, "classes it replaces"], empty when nothing conflicts; the parts are class strings, runtime values and arrays. With no static argument there is no static string: cn(props.class) is __cx([], props.class). Nothing is imported when every argument is static.cx is gone. import { cx } from "cssints" is a build error in a module the plugin handles, with or without the attribute: cssints: <file> imports cx from "cssints", which is gone: cn(...) takes runtime values now. Write cn(base, on && p(4)) with cn from "cssints" with { type: "cssints" }, and a type error (the name is now the SVG property cx, which you write css.cx(...)). The fix is mechanical: add cn to the attributed import and write cn( for cx(. Arguments that were only joined are now merged and checked at build time, so cx(p(4), p(2)) (both classes, the sheet decides) is cn(p(4), p(2)) (p(2)).cv(config) takes css.* values, so types check them, and is the function you call: one call, no wrapper. The plugin replaces the site by a call of the small runtime (and imports it for you; _cv is not exported any more) with a config of class strings. The props are typed from variants: a name or a value that is not there is a type error, in the props and in defaultVariants and compoundVariants alike.import { function cn(...styles: Style[]): Style (+1 overload)Merges styles into one class string. What is known at build time merges (the later property wins); a runtime value
(`on && p(4)`, `props.class`, a state call) is joined when the code runs, and a style in it replaces the classes it
overrides while it is active.cn, const cv: <V extends Record<string, Record<string, Style>> = Record<never, never>>(config: CvConfig<V>) => (props?: CvProps<V>) => stringThe plugin replaces the call by a runtime function of class strings: `button({ size: "lg" })` gives the class names.cv, const fontSize: Prop<"font-size">`<absolute-size> | <relative-size> | <length-percentage [0,∞]> | math`. Chrome 1, Edge 12, Firefox 1, Safari 1, iOS 1, Android 18. [MDN](https://developer.mozilla.org/docs/Web/CSS/font-size)fontSize, const opacity: Prop<"opacity">`<opacity-value>`. Chrome 1, Edge 12, Firefox 1, Safari 2, iOS 1, Android 18. [MDN](https://developer.mozilla.org/docs/Web/CSS/opacity)opacity, const p: Prop<"padding">`<'padding-top'>{1,4}`. Chrome 1, Edge 12, Firefox 1, Safari 1, iOS 1, Android 18. [MDN](https://developer.mozilla.org/docs/Web/CSS/padding)p } from "cssints" with { type: "cssints" };
const const button: (props?: CvProps<{
size: {
sm: Style;
lg: Style;
};
disabled: {
true: Style;
false: Style;
};
}> | undefined) => string
button = cv<{
size: {
sm: Style;
lg: Style;
};
disabled: {
true: Style;
false: Style;
};
}>(config: CvConfig<{
size: {
sm: Style;
lg: Style;
};
disabled: {
true: Style;
false: Style;
};
}>): (props?: CvProps<{
size: {
sm: Style;
lg: Style;
};
disabled: {
true: Style;
false: Style;
};
}> | undefined) => string
The plugin replaces the call by a runtime function of class strings: `button({ size: "lg" })` gives the class names.cv({
CvConfig<V extends Record<string, Record<string, Style>>>.base?: Style | undefinedbase: function cn(...styles: Style[]): Style (+1 overload)Merges styles into one class string. What is known at build time merges (the later property wins); a runtime value
(`on && p(4)`, `props.class`, a state call) is joined when the code runs, and a style in it replaces the classes it
overrides while it is active.cn(p<readonly [2]>(parts_0: 2): Style`<'padding-top'>{1,4}`. Chrome 1, Edge 12, Firefox 1, Safari 1, iOS 1, Android 18. [MDN](https://developer.mozilla.org/docs/Web/CSS/padding)p(2), fontSize<readonly ["1rem"]>(parts_0: "1rem"): Style`<absolute-size> | <relative-size> | <length-percentage [0,∞]> | math`. Chrome 1, Edge 12, Firefox 1, Safari 1, iOS 1, Android 18. [MDN](https://developer.mozilla.org/docs/Web/CSS/font-size)fontSize("1rem")),
CvConfig<{ size: { sm: Style; lg: Style; }; disabled: { true: Style; false: Style; }; }>.variants?: {
size: {
sm: Style;
lg: Style;
};
disabled: {
true: Style;
false: Style;
};
} | undefined
variants: {
size: {
sm: Style;
lg: Style;
}
size: { sm: Stylesm: p<readonly [1]>(parts_0: 1): Style`<'padding-top'>{1,4}`. Chrome 1, Edge 12, Firefox 1, Safari 1, iOS 1, Android 18. [MDN](https://developer.mozilla.org/docs/Web/CSS/padding)p(1), lg: Stylelg: function cn(...styles: Style[]): Style (+1 overload)Merges styles into one class string. What is known at build time merges (the later property wins); a runtime value
(`on && p(4)`, `props.class`, a state call) is joined when the code runs, and a style in it replaces the classes it
overrides while it is active.cn(p<readonly [4]>(parts_0: 4): Style`<'padding-top'>{1,4}`. Chrome 1, Edge 12, Firefox 1, Safari 1, iOS 1, Android 18. [MDN](https://developer.mozilla.org/docs/Web/CSS/padding)p(4), fontSize<readonly ["1.25rem"]>(parts_0: "1.25rem"): Style`<absolute-size> | <relative-size> | <length-percentage [0,∞]> | math`. Chrome 1, Edge 12, Firefox 1, Safari 1, iOS 1, Android 18. [MDN](https://developer.mozilla.org/docs/Web/CSS/font-size)fontSize("1.25rem")) },
disabled: {
true: Style;
false: Style;
}
disabled: { true: Styletrue: opacity<readonly [0.5]>(parts_0: 0.5): Style`<opacity-value>`. Chrome 1, Edge 12, Firefox 1, Safari 2, iOS 1, Android 18. [MDN](https://developer.mozilla.org/docs/Web/CSS/opacity)opacity(0.5), false: Stylefalse: opacity<readonly [1]>(parts_0: 1): Style`<opacity-value>`. Chrome 1, Edge 12, Firefox 1, Safari 2, iOS 1, Android 18. [MDN](https://developer.mozilla.org/docs/Web/CSS/opacity)opacity(1) },
},
CvConfig<{ size: { sm: Style; lg: Style; }; disabled: { true: Style; false: Style; }; }>.defaultVariants?: CvProps<NoInfer<{
size: {
sm: Style;
lg: Style;
};
disabled: {
true: Style;
false: Style;
};
}>> | undefined
defaultVariants: { size?: "sm" | "lg" | undefinedsize: "sm", disabled?: boolean | undefineddisabled: false },
CvConfig<{ size: { sm: Style; lg: Style; }; disabled: { true: Style; false: Style; }; }>.compoundVariants?: (CvProps<NoInfer<{
size: {
sm: Style;
lg: Style;
};
disabled: {
true: Style;
false: Style;
};
}>> & {
class: Style;
})[] | undefined
Styles added when every value named here is active, and that win over the variants they combine.compoundVariants: [{ size?: "sm" | "lg" | undefinedsize: "lg", disabled?: boolean | undefineddisabled: true, class: Styleclass: opacity<readonly [0.3]>(parts_0: 0.3): Style`<opacity-value>`. Chrome 1, Edge 12, Firefox 1, Safari 2, iOS 1, Android 18. [MDN](https://developer.mozilla.org/docs/Web/CSS/opacity)opacity(0.3) }],
});
export const const classes: () => stringclasses = () => const button: (props?: CvProps<{
size: {
sm: Style;
lg: Style;
};
disabled: {
true: Style;
false: Style;
};
}> | undefined) => string
button({ size?: "sm" | "lg" | undefinedsize: "lg" }); // "_lwugp7 _z6yj9k _1t0bw2x"
export const const off: () => stringoff = () => const button: (props?: CvProps<{
size: {
sm: Style;
lg: Style;
};
disabled: {
true: Style;
false: Style;
};
}> | undefined) => string
button({ size?: "sm" | "lg" | undefinedsize: "lg", disabled?: boolean | undefineddisabled: true });
export const const bad: () => stringbad = () => const button: (props?: CvProps<{
size: {
sm: Style;
lg: Style;
};
disabled: {
true: Style;
false: Style;
};
}> | undefined) => string
button({ size: "xl" }); // error: not a sizeexport const const bad2: (props?: CvProps<Record<never, never>> | undefined) => stringbad2 = cv<Record<never, never>>(config: CvConfig<Record<never, never>>): (props?: CvProps<Record<never, never>> | undefined) => stringThe plugin replaces the call by a runtime function of class strings: `button({ size: "lg" })` gives the class names.cv({ base: "padding: 1rem" }); // error: a base is a css value, not a CSS stringWhat ships for button is __cv({ base: "_1t8gqy5 _6tpir7", variants: { size: { sm: "_lqk467", lg: "_lwugp7 _z6yj9k" }, ... }, defaultVariants: { size: "sm", disabled: false }, ... }) with import { _cv as __cv } from "cssints" added to the module: class strings only. cv() works in a function, at the top of a module and in a library.
Old code. import { _cv } from "cssints" is a type error (no such export) and, in a module the plugin handles, a build error at the import: cssints: <file> imports _cv from "cssints", which is gone: cv({ ... }) is the function now. Write const button = cv({ base, variants }) .... It does not keep working for a release: _cv(cv(...)) would hand a function to the runtime, and a shim would keep two spellings of one thing. The fix is mechanical: drop _cv( and its closing bracket. A library built the old way fails with the same error, naming its file.
Boolean variants. A variant whose keys are true and false (or only one of them) takes a boolean: button({ disabled: true }), and a default is a boolean too. false is a value, not a missing one: button({ disabled: false }) selects the false key even when the default is true. undefined is the default.
compoundVariants as in cva: each entry names values (any of the variants, a boolean for a boolean one) and the style that is added when all of them are active. The key is class, as in cva, since what the entry adds is a class (a cn or style() key would suggest an inline style, and cssints has style() for that; css is the namespace). Its value is a css.* style like the others, not a string. The values of an entry are one value each, not a list of values.
Values of base and of each variant are one property, cn(...), or a flex()/grid() chain. A CSS string is a build error that shows the new form: cv() base must be a css.* value (cn(...), a flex() chain or one property), got "padding: 1rem". CSS strings are gone: write cn(p(4), fontSize("1rem")).
The variant wins. The function joins the base and the variants that are active at runtime, so the build compares them. Under one condition, a variant that sets what the base sets (the same property, an alias, or a shorthand over a base longhand: pl(2) in the base, p(4) in the variant) replaces it: the base class is dropped from the string while that value is active, which the runtime does from a drops entry in the config (drops: { size: { lg: "_77ujlx" } }, only where there is one). Which rule comes later in the sheet does not decide. A variant longhand inside a base shorthand needs no drop, since the sheet puts a longhand after its shorthand: base border(...) with active: { yes: borderBottomColor(...) } is fine. Under different conditions both stay, as in cn().
Overlap is an error, as in cn(). A base property and a variant property that overlap without one containing the other are a build error at the cv() call: cssints: cv() base and variant active.yes: border-bottom and border-color overlap without one containing the other, so the sheet cannot order them: set one of them, or the longhands (both set border-bottom-color; write borderBottomColor in the variant). The same holds for two variants of different keys, which can be active together. Two such variants that set the same property are an error too, since nothing says which wins: cssints: cv() variants a.x and b.x both set color and can be active together, so nothing says which wins: set it in one of them, or in the base. Values of one key are never compared, since only one is active.
A compound wins over what it combines. It is the most specific style, so under one condition it replaces what it sets again in the base and in the variant values it names (the same rule as a variant over the base): compoundVariants: [{ size: "lg", tone: "loud", class: p(6) }] drops the base's padding, size.lg's padding and tone.loud's padding while both are active, in the compound entry of the config ({ when: { size: "lg", tone: "loud" }, class: "_x", drops: "_a _b" }). The sheet order never decides. What a compound shares with other things that can be active together is compared as for variants: an overlap without containment is an error, and so is the same property in a compound and a variant of a key it does not name (it is active with any of its values), or in two compounds that can be active together (no key they both name with different values). Write the property in one of them, or in the base.