scv(): slot variantsscv() is one function whose result is the class string of each slot ({ base, label, icon }): slots, variants worth a
style per slot, defaults and compound variants, as in tailwind-variants. The rules are cv()'s, computed per slot.
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 color: Prop<"color">`<color>`. Chrome 1, Edge 12, Firefox 1, Safari 1, iOS 1, Android 18. [MDN](https://developer.mozilla.org/docs/Web/CSS/color)color, 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, const scv: <S extends Record<string, Style>, V extends Record<string, Record<string, ScvValue<S>>> = Record<never, never>>(config: ScvConfig<S, V>) => (props?: CvProps<V>) => { [K in keyof S]: string; }The plugin replaces the call by one runtime function per slot: `button({ size: "lg" })` gives each slot's classes.scv, const width: Prop<"width">`auto | <length-percentage [0,∞]> | min-content | max-content | fit-content | fit-content(<length-percentage [0,∞]>) | <calc-size()> | <anchor-size()>`. Chrome 1, Edge 12, Firefox 1, Safari 1, iOS 1, Android 18. [MDN](https://developer.mozilla.org/docs/Web/CSS/width)width } from "cssints" with { type: "cssints" };
const const button: (props?: CvProps<{
size: {
sm: Style;
lg: {
base: Style;
label: Style;
};
};
tone: {
quiet: Style;
loud: {
base: Style;
icon: Style;
};
};
disabled: {
true: Style;
false: Style;
};
}> | undefined) => {
base: string;
label: string;
icon: string;
}
button = scv<{
base: Style;
label: Style;
icon: Style;
}, {
size: {
sm: Style;
lg: {
base: Style;
label: Style;
};
};
tone: {
quiet: Style;
loud: {
base: Style;
icon: Style;
};
};
disabled: {
true: Style;
false: Style;
};
}>(config: ScvConfig<{
base: Style;
label: Style;
icon: Style;
}, {
size: {
sm: Style;
lg: {
base: Style;
label: Style;
};
};
tone: {
quiet: Style;
loud: {
base: Style;
icon: Style;
};
};
disabled: {
true: Style;
false: Style;
};
}>): (props?: CvProps<...> | undefined) => {
...;
}
The plugin replaces the call by one runtime function per slot: `button({ size: "lg" })` gives each slot's classes.scv({
ScvConfig<{ base: Style; label: Style; icon: Style; }, { size: { sm: Style; lg: { base: Style; label: Style; }; }; tone: { quiet: Style; loud: { base: Style; icon: Style; }; }; disabled: { ...; }; }>.slots: {
base: Style;
label: Style;
icon: Style;
}
The slots it styles, `base` and the others: a variant value that is a style styles `base`.slots: { base: Stylebase: 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), color<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/color)color("white")), label: Stylelabel: 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"), icon: Styleicon: width<readonly ["1rem"]>(parts_0: "1rem"): Style`auto | <length-percentage [0,∞]> | min-content | max-content | fit-content | fit-content(<length-percentage [0,∞]>) | <calc-size()> | <anchor-size()>`. Chrome 1, Edge 12, Firefox 1, Safari 1, iOS 1, Android 18. [MDN](https://developer.mozilla.org/docs/Web/CSS/width)width("1rem") },
ScvConfig<{ base: Style; label: Style; icon: Style; }, { size: { sm: Style; lg: { base: Style; label: Style; }; }; tone: { quiet: Style; loud: { base: Style; icon: Style; }; }; disabled: { ...; }; }>.variants?: {
size: {
sm: Style;
lg: {
base: Style;
label: Style;
};
};
tone: {
quiet: Style;
loud: {
base: Style;
icon: Style;
};
};
disabled: {
true: Style;
false: Style;
};
} | undefined
variants: {
size: {
sm: Style;
lg: {
base: Style;
label: 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: {
base: Style;
label: Style;
}
lg: { base: Stylebase: 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), label: Stylelabel: 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") } },
tone: {
quiet: Style;
loud: {
base: Style;
icon: Style;
};
}
tone: { quiet: Stylequiet: color<readonly ["gray"]>(parts_0: "gray"): Style`<color>`. Chrome 1, Edge 12, Firefox 1, Safari 1, iOS 1, Android 18. [MDN](https://developer.mozilla.org/docs/Web/CSS/color)color("gray"), loud: {
base: Style;
icon: Style;
}
loud: { base: Stylebase: color<readonly ["black"]>(parts_0: "black"): Style`<color>`. Chrome 1, Edge 12, Firefox 1, Safari 1, iOS 1, Android 18. [MDN](https://developer.mozilla.org/docs/Web/CSS/color)color("black"), icon: Styleicon: color<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/color)color("red") } },
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) },
},
ScvConfig<{ base: Style; label: Style; icon: Style; }, { size: { sm: Style; lg: { base: Style; label: Style; }; }; tone: { quiet: Style; loud: { base: Style; icon: Style; }; }; disabled: { ...; }; }>.defaultVariants?: CvProps<NoInfer<{
size: {
sm: Style;
lg: {
base: Style;
label: Style;
};
};
tone: {
quiet: Style;
loud: {
base: Style;
icon: Style;
};
};
disabled: {
true: Style;
false: Style;
};
}>> | undefined
defaultVariants: { size?: "sm" | "lg" | undefinedsize: "sm", disabled?: boolean | undefineddisabled: false },
ScvConfig<{ base: Style; label: Style; icon: Style; }, { size: { sm: Style; lg: { base: Style; label: Style; }; }; tone: { quiet: Style; loud: { base: Style; icon: Style; }; }; disabled: { ...; }; }>.compoundVariants?: (CvProps<NoInfer<{
size: {
sm: Style;
lg: {
base: Style;
label: Style;
};
};
tone: {
quiet: Style;
loud: {
base: Style;
icon: Style;
};
};
disabled: {
true: Style;
false: Style;
};
}>> & {
class: Style;
} & Partial<Record<"base" | "label" | "icon", Style>>)[] | undefined
Styles added when every value named here is active: `class` is the `base` slot, a slot's name styles that slot.compoundVariants: [
{ size?: "sm" | "lg" | undefinedsize: "lg", tone?: "quiet" | "loud" | undefinedtone: "loud", class: Styleclass: p<readonly [6]>(parts_0: 6): 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(6) },
{ size?: "sm" | "lg" | undefinedsize: "lg", class: Styleclass: bg<readonly ["crimson"]>(parts_0: "crimson"): 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("crimson"), label?: Style | undefinedlabel: color<readonly ["blue"]>(parts_0: "blue"): Style`<color>`. Chrome 1, Edge 12, Firefox 1, Safari 1, iOS 1, Android 18. [MDN](https://developer.mozilla.org/docs/Web/CSS/color)color("blue") },
],
});
export const const slots: () => {
base: string;
label: string;
icon: string;
}
slots = () => const button: (props?: CvProps<{
size: {
sm: Style;
lg: {
base: Style;
label: Style;
};
};
tone: {
quiet: Style;
loud: {
base: Style;
icon: Style;
};
};
disabled: {
true: Style;
false: Style;
};
}> | undefined) => {
base: string;
label: string;
icon: string;
}
button({ size?: "sm" | "lg" | undefinedsize: "lg" }); // { base: "...", label: "...", icon: "..." }
export const const bad: () => {
base: string;
label: string;
icon: string;
}
bad = () => const button: (props?: CvProps<{
size: {
sm: Style;
lg: {
base: Style;
label: Style;
};
};
tone: {
quiet: Style;
loud: {
base: Style;
icon: Style;
};
};
disabled: {
true: Style;
false: Style;
};
}> | undefined) => {
base: string;
label: string;
icon: string;
}
button({ size: "xl" }); // error: not a sizeexport const const badSlot: (props?: CvProps<Record<string, Record<string, ScvValue<{
base: Style;
label: Style;
}>>>> | undefined) => {
base: string;
label: string;
}
badSlot = scv<{
base: Style;
label: Style;
}, Record<string, Record<string, ScvValue<{
base: Style;
label: Style;
}>>>>(config: ScvConfig<{
base: Style;
label: Style;
}, Record<string, Record<string, ScvValue<{
base: Style;
label: Style;
}>>>>): (props?: CvProps<Record<string, Record<string, ScvValue<{
base: Style;
label: Style;
}>>>> | undefined) => {
base: string;
label: string;
}
The plugin replaces the call by one runtime function per slot: `button({ size: "lg" })` gives each slot's classes.scv({
ScvConfig<{ base: Style; label: Style; }, Record<string, Record<string, ScvValue<{ base: Style; label: Style; }>>>>.slots: {
base: Style;
label: Style;
}
The slots it styles, `base` and the others: a variant value that is a style styles `base`.slots: { base: Stylebase: 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), label: Stylelabel: 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) },
ScvConfig<{ base: Style; label: Style; }, Record<string, Record<string, ScvValue<{ base: Style; label: Style; }>>>>.variants?: Record<string, Record<string, ScvValue<{
base: Style;
label: Style;
}>>> | undefined
variants: { size: {
sm: {
labl: Style;
};
}
size: { sm: {
labl: Style;
}
sm: { labl: 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) } } }, // error: labl is not a slot});button is __scv({ base: { base, variants, defaultVariants, drops?, compound? }, label: {...}, icon: {...} }),
one cv() config per slot, with import { _scv as __scv } from "cssints" added to the module: class strings only, and
one runtime function per slot, built once when the module loads. scv() works in a function, at the top of a module and
in a library; put the config at the top of the module so the per-slot runtimes are built once.base, so a
config that gives a bare style and has no base slot is a build error; a record styles the slots it names, and a name
that is not a slot is a type error and a build error at the scv() call. In compoundVariants, class is the base
slot and a slot's own name styles that slot.cv()'s, per slot. A variant wins over the slot's base (its class is dropped while active), a compound
wins over both, and two things that can be active together and overlap without containment are a build error. Each
error names the slot, for example cssints: scv() slot base: base and variant active.yes: border-bottom and border-color overlap without one containing the other. A slot a value does not style is simply not in that slot's config, and the compound entries it has no style for keep their index, so the errors name the entry you wrote.cv()'s, typed from variants (CvProps): a typo in a name or a value is a type
error, and a boolean variant takes a boolean. The result is { [K in keyof slots]: string }, so button().label is a
string and a slot that is not there is a type error.cv() function as a slot value, and an scv() in compoundVariants, are not in this release: a slot
value is a css.* style (or a cn()/a chain). A slot may not share its name with a variant: a compound entry would
name both with one key, and the types make that entry impossible to write. A scv() site has no readable class in the
dev overlay yet (a cn() or cv() site has one).A slot that reads another slot's state uses group() and within(), not its class. A class is a mark on the element
it is put on: passing base's class to a condition of label would style label's own state, not the root's. The root
marks itself a group and the other slots read that ancestor's state, one condition each:
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 color: Prop<"color">`<color>`. Chrome 1, Edge 12, Firefox 1, Safari 1, iOS 1, Android 18. [MDN](https://developer.mozilla.org/docs/Web/CSS/color)color,
const focusVisible: StateWrapChrome 86, Edge 86, Firefox 85, Safari 15.4, iOS 15.4, Android 86. [MDN](https://developer.mozilla.org/docs/Web/CSS/:focus-visible)focusVisible,
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 group: <const N extends string = never>(name?: Name<N>) => Style`group()` is the marker class `_g` for the element whose state `within()` reads; `group("row")` is `_g-row`, for a
nested group. It has no CSS of its own.group,
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 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,
const scv: <S extends Record<string, Style>, V extends Record<string, Record<string, ScvValue<S>>> = Record<never, never>>(config: ScvConfig<S, V>) => (props?: CvProps<V>) => { [K in keyof S]: string; }The plugin replaces the call by one runtime function per slot: `button({ size: "lg" })` gives each slot's classes.scv,
const within: <const N extends string = never>(state: StateWrap, name?: Name<N>) => Wrap`within(hover)(color("red"))` is the style while a marked ancestor is hovered: `:where(._g:hover) ._x`, one class of
specificity, one condition. `within(hover, "row")` reads the `group("row")` ancestor.within,
} from "cssints" with { type: "cssints" };
const const card: (props?: CvProps<Record<never, never>> | undefined) => {
base: string;
label: string;
icon: string;
}
card = scv<{
base: Style;
label: Style;
icon: Style;
}, Record<never, never>>(config: ScvConfig<{
base: Style;
label: Style;
icon: Style;
}, Record<never, never>>): (props?: CvProps<Record<never, never>> | undefined) => {
base: string;
label: string;
icon: string;
}
The plugin replaces the call by one runtime function per slot: `button({ size: "lg" })` gives each slot's classes.scv({
ScvConfig<{ base: Style; label: Style; icon: Style; }, Record<never, never>>.slots: {
base: Style;
label: Style;
icon: Style;
}
The slots it styles, `base` and the others: a variant value that is a style styles `base`.slots: {
base: Stylebase: 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(group<never>(name?: undefined): Style`group()` is the marker class `_g` for the element whose state `within()` reads; `group("row")` is `_g-row`, for a
nested group. It has no CSS of its own.group(), 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), 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")),
label: Stylelabel: 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(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"), within<never>(state: StateWrap, name?: undefined): Wrap`within(hover)(color("red"))` is the style while a marked ancestor is hovered: `:where(._g:hover) ._x`, one class of
specificity, one condition. `within(hover, "row")` reads the `group("row")` ancestor.within(const hover: StateWrapChrome 1, Edge 12, Firefox 1, Safari 2, iOS 1, Android 18. [MDN](https://developer.mozilla.org/docs/Web/CSS/:hover)hover)(color<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/color)color("red"))),
icon: Styleicon: within<never>(state: StateWrap, name?: undefined): Wrap`within(hover)(color("red"))` is the style while a marked ancestor is hovered: `:where(._g:hover) ._x`, one class of
specificity, one condition. `within(hover, "row")` reads the `group("row")` ancestor.within(const focusVisible: StateWrapChrome 86, Edge 86, Firefox 85, Safari 15.4, iOS 15.4, Android 86. [MDN](https://developer.mozilla.org/docs/Web/CSS/:focus-visible)focusVisible)(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)),
},
});group() puts _g on the element the base class is on, and within(hover) becomes :where(._g:hover) .label, one
class of specificity, so the sheet's order still decides. group("card") with within(hover, "card") tells nested cards
apart. A slot needs no dependency on another slot's value for this, which is why scv() takes no slot functions.