import { reset } from "@cssints/reset" with { type: "cssints" };
import * as css from "cssints" with { type: "cssints" };
import { CSS } from "cssints" with { type: "cssints" };
import { page, row, stack } from "./stack.ts" with { type: "cssints" };
reset();
// Names are the CSS properties in camelCase, plus a few short ones (p, m, bg). A bare number is a step of 0.25rem in padding,
// margin, gap and inset, and a plain number elsewhere. flex() and grid() chain their container properties.
const frame = css.cn(page, css.maxWidth("32rem"), css.marginInline("auto"));
const panel = css.cn(
stack,
css.padding(CSS.rem(1), CSS.rem(1.5)),
css.border("1px solid", "#d4d8e1"),
css.borderRadius("12px"),
css.bg("#fafbfd"),
css.color("#0f172a"),
);
const person = css.cn(row, css.minHeight("3rem"));
const avatar = css.cn(
css.width("2.5rem"),
css.height("2.5rem"),
css.borderRadius("50%"),
css.bg("#c7d2fe"),
css.color("#1e1b4b"),
css.flex().alignItems("center").justifyContent("center"),
css.fontWeight(700),
);
const grid = css.cn(
css.grid().templateColumns("repeat(3, 1fr)").gap(2),
css.textAlign("center"),
css.fontSize("0.875rem"),
);
const cell = css.cn(
css.p(2),
css.bg("white"),
css.color("#0f172a"),
css.border("1px solid", "#e5e7eb"),
css.opacity(0.9),
);
const people = ["Ada", "Grace", "Linus"];
export default function App() {
return (
<div className={frame}>
<section className={panel}>
<h2 className={css.cn(css.margin("0"), css.fontSize("1.125rem"))}>Team</h2>
{people.map((name) => (
<div className={person}>
<span className={avatar}>{name[0]}</span>
<span>{name}</span>
</div>
))}
</section>
<section className={grid}>
<span className={cell}>p(2)</span>
<span className={cell}>opacity(0.9)</span>
<span className={cell}>gap(2)</span>
</section>
</div>
);
}import * as css from "cssints" with { type: "cssints" };
// Styles can live in a module of their own: import it with the attribute, as cssints itself.
export const stack = css.flex().direction("column").gap(3);
export const row = css.flex().alignItems("center").gap(3);
export const page = css.cn(css.flex().direction("column").gap(6), css.p(6));with { type: "cssints" } marks code that runs at build time: cssints itself, plugins such as icons, and your own helper modules. The plugin finds call sites by this attribute. Nothing is imported without it: the few runtime lines a module needs (__cx for a cn() with runtime arguments, __cv for a cv()) are imported by the plugin. Using a build-time member without the attribute is a build error.paddingLeft, alignItems, justifyContent), plus a short set: p pt pr pb pl, m mt mr mb ml, bg. Everything is available both as named exports and through the namespace (css.p). There is no items or justify: they were ambiguous (align-items or align-content, justify-content or justify-items).padding*, margin*, gap* and inset* (p(4) is 1rem). In any other property it is a CSS <number>: opacity(0.5), zIndex(3).border("1px solid", accent), padding(CSS.rem(1), CSS.rem(2)), padding("1rem 2rem"). Parts are checked against the mdn grammar in types and again at build time. CSS.px, rem, em, percent, number, CSSUnitValue and CSSColorValue come from cssints, imported with the attribute.padding("2px", "red") puts the error on "red", with the message of the whole value. While a string is not a value yet, the editor offers the keywords of the property that the word under the cursor begins (display("fl…") gives flex, flow, flow-root; border("1px", "so…") gives solid), and all of them in an empty part (border("1px", ""); an empty part is an error). The offer is the keywords of the whole grammar, not only those that fit at that point, it stops once the string is valid, and functions such as rgb( are not offered.calc(), min(), max(), clamp() and the other CSS Values 4 math functions are accepted wherever their type is, as strings (width("calc(100% - 2rem)"), checked by the build: calc(1px + 2s) is an error) and as calls that take tokens (calc(t.space.md, "*", 2), see "Functions").flex() and grid() without arguments set display and chain only their container properties. Names drop only the context prefix: flex().direction("column").wrap("wrap").alignItems("center").justifyContent("space-between"), grid().templateColumns("1fr 2fr").gap(4). Plain styles do not chain; merge them with cn(...), or write the style as a sx() (below), which chains every property. Item properties (flexGrow, alignSelf, gridColumn, order) are plain functions.flex(...parts) and grid(...parts) are the shorthand properties. With at least one argument the call is the flex (or grid) property, checked by its grammar like any member: flex("1"), flex(1) and flex("1 1 0") are flex: 1, flex: 1 and flex: 1 1 0, grid("auto / 1fr 1fr") is grid: auto / 1fr 1fr. A bare number is a <number> here, not a spacing step. The result is a plain style: it sets no display and does not chain. The types tell the two forms apart by overload.container is the condition. container("sidebar (width < 30rem)") is a query; the container shorthand property is written with its longhands containerName and containerType.const, a token or a value from another attributed module works. A value that exists only at runtime (a prop, state) does not: p(n) with n a parameter is a build error (css arguments must be known at build time: n is not defined where the call is evaluated) that points at the call, also when the local is named like a global (open, name) or like a module binding. The types do not catch it: a helper module may take parameters (below), so a string or number is a fine argument there. Choose between styles with cn(base, on && p(4)) (see "Runtime: cn, cv"), a cv variant, or a token set in a style prop. A helper module imported with the attribute may take parameters, because each call of it is a site with its own arguments: stack(4) below is a build-time call in the file that makes it.false && p(4), a branch not taken, a ternary arm) still gets its class string: it is evaluated after the module has loaded, like a call inside a function, so its arguments may use the bindings of the module but not the locals of the branch. A cv(...) at the top of a module works too: during the build it is the same function the browser gets, so button({ size: "lg" }) at the top of a module gives its classes.// stack.ts
import * as import csscss from "cssints" with { type: "cssints" };
export const const stack: (gap: number) => css.Chain<css.FlexMethods>stack = (gap: numbergap: number) => import csscss.const flex: css.Layout
() => css.Chain<css.FlexMethods> (+1 overload)
The layout context: sets `display` and chains its container properties.flex().direction: <readonly ["column"]>(parts_0: "column") => css.Chain<css.FlexMethods>`row | row-reverse | column | column-reverse`. Chrome 29, Edge 12, Firefox 22, Safari 9, iOS 9, Android 29. [MDN](https://developer.mozilla.org/docs/Web/CSS/flex-direction)direction("column").gap: <readonly [number]>(parts_0: number) => css.Chain<css.FlexMethods>`<'row-gap'> <'column-gap'>?`. Chrome 57, Edge 16, Firefox 52, Safari 10.1, iOS 10.3, Android 57. [MDN](https://developer.mozilla.org/docs/Web/CSS/gap)gap(gap: numbergap);
// elsewhere: import { stack } from "./stack.ts" with { type: "cssints" }; ... className={stack(4)}