sx(): one style without cn()sx() builds one style by chaining properties. Every property is a method, the methods return the chain, and the
build merges the declarations as cn() does. cn() stays the tool for merging runtime values, and for cv() variants.
import { function sx(): ChainStyle`sx().flex().bg("red").p(4)`: one style, one class string, no `cn()`. Every property is a method; `.flex()` and
`.grid()` with no argument set `display`, with parts they are the property. A chain sets each property once: a second
`bg` makes the method `never`, a type error. Merge two chains with `cn()`, which is still the tool for runtime values
and variants.sx, 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 } from "cssints" with { type: "cssints" };
export const const card: string & {
readonly __cssints: "style";
} & ChainMembers & {
readonly display: never;
} & {
readonly flexDirection: never;
} & {
readonly gap: never;
} & {
readonly p: never;
readonly padding: never;
} & {
readonly backgroundColor: never;
readonly bg: never;
}
card = function sx(): ChainStyle`sx().flex().bg("red").p(4)`: one style, one class string, no `cn()`. Every property is a method; `.flex()` and
`.grid()` with no argument set `display`, with parts they are the property. A chain sets each property once: a second
`bg` makes the method `never`, a type error. Merge two chains with `cn()`, which is still the tool for runtime values
and variants.sx().ChainMembers.flex<[]>(): string & {
readonly __cssints: "style";
} & ChainMembers & {
readonly display: never;
} (+1 overload)
`none | [ <'flex-grow'> <'flex-shrink'>? || <'flex-basis'> ]`. Chrome 29, Edge 12, Firefox 22, Safari 9, iOS 9, Android 29. [MDN](https://developer.mozilla.org/docs/Web/CSS/flex)flex().ChainMembers.flexDirection: <readonly ["column"]>(parts_0: "column") => string & {
readonly __cssints: "style";
} & ChainMembers & {
readonly display: never;
} & {
readonly flexDirection: never;
}
flexDirection("column").ChainMembers.gap: <readonly [2]>(parts_0: 2) => string & {
readonly __cssints: "style";
} & ChainMembers & {
readonly display: never;
} & {
readonly flexDirection: never;
} & {
readonly gap: never;
}
gap(2).ChainMembers.p: <readonly [4]>(parts_0: 4) => string & {
readonly __cssints: "style";
} & ChainMembers & {
readonly display: never;
} & {
readonly flexDirection: never;
} & {
readonly gap: never;
} & {
readonly p: never;
readonly padding: never;
}
p(4).ChainMembers.bg: <readonly ["white"]>(parts_0: "white") => string & {
readonly __cssints: "style";
} & ChainMembers & {
readonly display: never;
} & {
readonly flexDirection: never;
} & {
readonly gap: never;
} & {
readonly p: never;
readonly padding: never;
} & {
readonly backgroundColor: never;
readonly bg: never;
}
bg("white");
export const const row: string & {
readonly __cssints: "style";
} & ChainMembers & {
readonly display: never;
} & {
readonly gridTemplateColumns: never;
} & {
readonly gap: never;
}
row = function sx(): ChainStyle`sx().flex().bg("red").p(4)`: one style, one class string, no `cn()`. Every property is a method; `.flex()` and
`.grid()` with no argument set `display`, with parts they are the property. A chain sets each property once: a second
`bg` makes the method `never`, a type error. Merge two chains with `cn()`, which is still the tool for runtime values
and variants.sx().ChainMembers.grid<[]>(): string & {
readonly __cssints: "style";
} & ChainMembers & {
readonly display: never;
} (+1 overload)
`<'grid-template'> | <'grid-template-rows'> / [ auto-flow && dense? ] <'grid-auto-columns'>? | [ auto-flow && dense? ] <'grid-auto-rows'>? / <'grid-template-columns'>`. Chrome 57, Edge 16, Firefox 52, Safari 10.1, iOS 10.3, Android 57. [MDN](https://developer.mozilla.org/docs/Web/CSS/grid)grid().ChainMembers.gridTemplateColumns: <readonly ["1fr 2fr"]>(parts_0: "1fr 2fr") => string & {
readonly __cssints: "style";
} & ChainMembers & {
readonly display: never;
} & {
readonly gridTemplateColumns: never;
}
gridTemplateColumns("1fr 2fr").ChainMembers.gap: <readonly [1]>(parts_0: 1) => string & {
readonly __cssints: "style";
} & ChainMembers & {
readonly display: never;
} & {
readonly gridTemplateColumns: never;
} & {
readonly gap: never;
}
gap(1);
export const const box: Stylebox = 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(function sx(): ChainStyle`sx().flex().bg("red").p(4)`: one style, one class string, no `cn()`. Every property is a method; `.flex()` and
`.grid()` with no argument set `display`, with parts they are the property. A chain sets each property once: a second
`bg` makes the method `never`, a type error. Merge two chains with `cn()`, which is still the tool for runtime values
and variants.sx().ChainMembers.p: <readonly [2]>(parts_0: 2) => string & {
readonly __cssints: "style";
} & ChainMembers & {
readonly p: never;
readonly padding: never;
}
p(2), 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(function sx(): ChainStyle`sx().flex().bg("red").p(4)`: one style, one class string, no `cn()`. Every property is a method; `.flex()` and
`.grid()` with no argument set `display`, with parts they are the property. A chain sets each property once: a second
`bg` makes the method `never`, a type error. Merge two chains with `cn()`, which is still the tool for runtime values
and variants.sx().ChainMembers.bg: <readonly ["blue"]>(parts_0: "blue") => string & {
readonly __cssints: "style";
} & ChainMembers & {
readonly backgroundColor: never;
readonly bg: never;
}
bg("blue")));card is "_1s47490 _1njigwa _g2iyum _lwugp7 _1ebepn0": one class per declaration, one string, no cn().
p, bg, paddingLeft, gridTemplateColumns. .flex() and
.grid() with no argument set display and keep chaining; with parts they are the flex and grid property. A
chain does not drop a prefix the way a context does: sx().flex().flexDirection("column") is the property,
where css.flex().direction("column") drops flex-.never
(This expression is not callable. Type 'never' has no call signatures.), so the rewrite that cn() allows cannot
be written by accident. bg and backgroundColor are one property, as are p and padding, so
sx().bg("red").backgroundColor("blue") and sx().p(4).padding("1rem") fail in either order. A second
.flex() or .grid() is Expected 1 arguments, but got 0, since the no-argument form is what sets display.
Write a later value with cn(), which keeps the later one of a property, or a longhand.sx().p(4).paddingLeft("0.5rem")
is both declarations, which the sheet orders (a longhand after its shorthand), exactly as in cn(). The types do not
compare containment, only the property: sx().bg("red").background("blue") is background-color and
background, not a duplicate.css.* call: it compiles to its class string, so it works in a variable, in cn(),
in a condition (hover(sx().bg("blue"))), and as the base or a variant of cv(). A keyframes() or
positionTry() name in a chain carries its at-rule, as in css.*.hover, media), other builders (cn, keyframes, cv) and plugin members
(frame(), surface(), a scope's members). A build error names the method (cssints: sx() has no .hover()).
Wrap the chain instead: hover(sx().bg("blue")), cn(frame(), sx().p(2)).cssints pays
about 6.7 k more instantiations (bench/unused.ts 46 297 → 53 029, +14.5 %). A chain costs about what the cn()
form of the same declarations costs: 12 chains of five properties are 273 741 instantiations against 264 798 for the
same 60 declarations as cn() calls (+3.4 %, tsc 5.9); bench/chain.ts guards it.