@getvitops/generator 0.7.0 → 0.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,238 @@
1
1
  # @getvitops/generator
2
2
 
3
+ ## 0.9.0
4
+
5
+ ### Minor Changes
6
+
7
+ - **The `tailwind` format now emits the full role colour vocabulary.** It previously emitted only
8
+ the functional role utilities, so 87 classes — `bg-<role>-x-muted`, `bg-<role>-bold`,
9
+ `bg-<role>-x-bold`, `text-<role>-bold`, `text-<role>-x-bold`,
10
+ `border-<role>-{muted,x-muted,x-bold}`, for every role — existed in the `css` and `bricks`
11
+ outputs and silently did nothing in `tailwind`. Nothing in the test suite built the tailwind
12
+ format, so the divergence was invisible; it was found by a consumer who hand-forked four
13
+ background planes into their own stylesheet to work around the absence.
14
+
15
+ All three formats now render from one emitter (`roleColorUtilities()`), which resolves the
16
+ plane-vs-stop namespace collision explicitly instead of relying on the CSS minifier dropping a
17
+ shadowed rule. No class changes meaning, and the `css`/`bricks` output is unchanged.
18
+
19
+ Also fixed in the tailwind format:
20
+ - `colors.utilities` is now honoured. It was hardcoded to `bg`/`text`/`border`, so enabling
21
+ `outline`/`fill`/`stroke` worked in `css`/`bricks` and was ignored here. (For raw hue scales
22
+ it remains a floor rather than a ceiling — those are `@theme` colours, and Tailwind derives
23
+ every colour family from them on demand.)
24
+ - **Component container queries are no longer stripped.** The pass that drops the framework's
25
+ pre-expanded `md-*` breakpoint utilities (Tailwind regenerates those as `@md:`) matched every
26
+ `@container (min-width: …)` block, including component behaviour — most visibly the
27
+ sitenav's, so `.sitenav--bp-{sm,md,lg,xl}` were removed and the nav stayed in its mobile
28
+ layout at every width.
29
+
30
+ New: **`vitops lint`** reports framework classes in your source that resolve to nothing — the
31
+ failure mode where an unknown utility looks exactly like a working one. It is format-aware
32
+ (`md-flex-row` is a real class in `css`/`bricks` and inert in `tailwind`) and only judges
33
+ classes anchored to your own config, so it stays quiet on Tailwind's utilities and your own.
34
+
35
+ ```
36
+ vitops lint --format tailwind --src src
37
+ ```
38
+
39
+ - **The `css` and `bricks` bundles now ship cascade layers, so a utility can override a pattern.**
40
+
41
+ `class="card bg-danger-muted"` previously tinted the card in the `tailwind` format and silently
42
+ did nothing in `css`/`bricks`: every colour utility was emitted before every pattern and both sat
43
+ at `0-1-0`, so the pattern won on source order. The bundle now emits
44
+
45
+ ```css
46
+ @layer vitops.base, vitops.components, vitops.utilities;
47
+ ```
48
+
49
+ - `vitops.base` — the UA reset and the pure `:root` token blocks
50
+ - `vitops.components` — the animation engine, structural layout, and every pattern
51
+ - `vitops.utilities` — `bg-*`, `text-*`, `border-*`, `drop-shadow-*`, `font-*`, animation
52
+ effects, and the display/`sr-only` families
53
+
54
+ No rule changed — 1482 rules before, 1482 after — only precedence.
55
+
56
+ **What this changes for you.** Unlayered CSS beats every cascade layer regardless of specificity,
57
+ so your own stylesheet, an Astro scoped `<style>`, or a Bricks-authored class now overrides the
58
+ framework with no `!important` and no specificity escalation. That is the intended override story
59
+ and the reason to layer at all.
60
+
61
+ **Migration — only if you ship a reset.** An unlayered reset will now beat the framework
62
+ component rules it used to lose to; a bare `p { margin: 0 }` defeats `.rhythm`. Put it in a layer
63
+ and declare the order **before** the stylesheet loads:
64
+
65
+ ```html
66
+ <style>
67
+ @layer my.reset, vitops.base, vitops.components, vitops.utilities;
68
+ </style>
69
+ <link rel="stylesheet" href="/styles.css" />
70
+ ```
71
+
72
+ Declaring it _after_ the link makes `my.reset` a name introduced later, which sorts **last** —
73
+ highest priority — and the reset wins anyway. That ordering rule is the one non-obvious step.
74
+
75
+ The `tailwind` format is byte-identical. Its utilities are `@utility` definitions, which Tailwind
76
+ already places in a layer above `components` and which are what make `hover:`/`@md:` variants
77
+ work; wrapping them ourselves would win the cascade and lose the variants.
78
+
79
+ Known gap: `layout.css` mixes structural rules (`.rhythm`, `.centered`) with utilities (`.m-*`,
80
+ `.flex`, `.split-*`) in one partial, so it sits in `vitops.components` whole and its utility half
81
+ cannot yet override a pattern. Splitting it is tracked separately.
82
+
83
+ ### Patch Changes
84
+
85
+ - **Fixed: `vitops init` and `vp create` scaffolded configs referencing tokens that no longer
86
+ exist.** `defaultConfig()` and the EmDash template still pointed at `--color-surface-xl` and
87
+ `--color-surface-xxl`, aliases from the named-step colour scale removed in 0.6. A scaffolded
88
+ project therefore got a `card` with no background and an invalid default border colour, with
89
+ nothing reporting it. Both now use `--surface-bg` / `--surface-bg-muted`. The EmDash template
90
+ also dropped its `patterns.radii.card` key, which collided with the `card` pattern on
91
+ `--br-card` — the collision `validate()` has been warning about (the `panel` group already
92
+ supplies the same radius, so nothing changes visually).
93
+
94
+ **Fixed: `.text-reveal` rendered invisible text.** Its gradient consumed
95
+ `--text-reveal-color-from`/`-to` with no defaults, so unless a consumer set both, the `var()`
96
+ substitution failed, `background` became invalid at computed-value time, and the accompanying
97
+ `color: transparent` left the text with no way to render. Both tones now default to the
98
+ functional text tokens.
99
+
100
+ **Fixed: `.bordered` fell back to `currentColor`** via a reference to `--color-surface-xl`,
101
+ which the generator never emitted. It now resolves `--surface-border`.
102
+
103
+ **New: `validate()` warns when a required role is missing.** `colors.roles` is an open map —
104
+ any name works and generates a full token set — but the shipped component CSS references
105
+ `brand-primary`, `danger`, `neutral`, `surface`, `ui-primary` and `warning` with no fallback,
106
+ so omitting one leaves those components uncoloured. This is a warning, not an error; the
107
+ required list is re-derived from the CSS partials by a test so it cannot drift.
108
+
109
+ `vitops docs` and `vitops agents` now surface config warnings (on stderr, so piping `docs` is
110
+ unaffected). They previously discarded them, unlike `generate` and `validate`.
111
+
112
+ Docs corrections, all in the generated bundle:
113
+ - **Raw scale classes are frozen and do not remap in dark mode** — stated explicitly for the
114
+ first time, with a migration table to the role equivalents. The dark-mode guarantee only ever
115
+ applied to functional role tokens, and nothing said so.
116
+ - **Roles are extensible over a required core** — the schema description and class reference
117
+ read as a closed enumeration, which is why a consumer forked their own colour layer rather
118
+ than adding a role.
119
+ - **The `md:` / `@md:` / `md-` distinction** in the tailwind format: `@md:` uses the framework's
120
+ breakpoints, `md:` works but uses Tailwind's (which differ — `sm:` is 40rem, `@sm:` is 30rem),
121
+ and `md-` is silently inert. Plus a note that registering `--container-*` also re-points
122
+ Tailwind's `max-w-*` scale.
123
+ - The css and bricks bundles now carry a `/*!` banner pointing at `npx vitops docs classes`
124
+ (the previous plain comment was stripped by the minifier, so it never reached the file).
125
+
126
+ Contrast checking now covers **every** background plane a role emits (`bg`, `bg-muted`, and
127
+ `bg-bold`), not just `bg` — body text on a `card` was previously unguaranteed.
128
+
129
+ - Docs now name both dark-mode attributes. The generated colour docs still described the
130
+ dark flip as hanging off `:root[data-brx-theme="dark"]` alone, from before the selector
131
+ also matched `:root[data-theme="dark"]` (the attribute `<color-scheme-toggle>` writes) —
132
+ so a non-Bricks consumer reading `vitops docs color` would wire up an attribute that
133
+ nothing matches. The selector moved into `shared.ts` as `DARK_SEL` (also exported from
134
+ the package index) and the docs interpolate it, so the two can't drift again.
135
+ - c949cae: `vitops init` no longer scaffolds a config that warns on its own output.
136
+
137
+ `defaultConfig()` declared `patterns.radii.card`, a key named after the `card` pattern — the exact
138
+ collision `validate()` started reporting in 0.8.0. The primitive won `--br-card`, shadowing the
139
+ pattern's override hook and leaving its `--br-card-group` alias unreachable, so a scaffolded project
140
+ was warned about a config it had just been given.
141
+
142
+ The key is dropped. This is **value-preserving**: `card` belongs to the `panel` group, which already
143
+ carries the same `0.5rem`, so `--br-card-group` → `--br-panel` → `0.5rem` renders identically.
144
+
145
+ **Migration:** none for existing configs — your `design-system.json` is not touched. If you copied
146
+ the scaffold and reference `var(--br-card)` directly in hand-written CSS, note it is now an
147
+ _override hook_ (undefined until you set it) rather than a defined primitive; read `--br-card-group`
148
+ instead, or keep your own `radii` key under a name no pattern uses.
149
+
150
+ - **The theme editor no longer dims the page it's editing.**
151
+
152
+ The panel used `.drawer`'s scrim and `popover="auto"`, which fought the whole purpose of a live
153
+ editor: the page you were tuning sat behind a 4px blur, and the first click on it dismissed the
154
+ panel. It is now modeless — no scrim, and clicking through to the page keeps it open. Escape still
155
+ closes it (wired explicitly, since `popover="manual"` doesn't provide it), as does the × button.
156
+
157
+ **New: `.drawer--modeless`.** The same treatment is available to any drawer — a side panel you work
158
+ _alongside_ rather than through (an inspector, a live editor, a filter rail). Pair it with
159
+ `popover="manual"`:
160
+
161
+ ```html
162
+ <div class="drawer drawer--right drawer--modeless" popover="manual">…</div>
163
+ ```
164
+
165
+ An `auto` popover light-dismisses on the first outside click, which is exactly the interaction a
166
+ modeless panel exists to permit — so `manual` is part of the pattern, not an afterthought. It also
167
+ drops Escape, so give the panel a visible close control.
168
+
169
+ **Added:** a drift guard tying `<wc-theme-editor>`'s dark-override selector to the generator's
170
+ `DARK_SEL`. The two must match or the editor's dark-mode edits land on a rule the page never
171
+ matches — a failure that is invisible in light mode, so nothing would have caught it.
172
+ - @getvitops/utils@0.9.0
173
+
174
+ ## 0.8.0
175
+
176
+ ### Minor Changes
177
+
178
+ - **New: `<wc-theme-editor>`, a live theme editor you can ship with your site.**
179
+
180
+ Tune the whole design system in the browser — palette, semantic roles, type roles, spacing, layout,
181
+ pattern geometry, radii, shadows — with no rebuild. Edits are layered as `:root` custom-property
182
+ overrides, persist to localStorage, and export as CSS or as a `design-system.json` patch. It follows
183
+ your site's colour scheme and drives the same `data-theme` + storage key as `<color-scheme-toggle>`,
184
+ so the two no longer fight.
185
+
186
+ It ships as a **separate, opt-in bundle** (`@getvitops/core/editor`, ~13 kB, no Lit) and is never
187
+ registered in `elements.js`: a page that doesn't ask for it pays nothing.
188
+
189
+ ```js
190
+ // astro.config.mjs
191
+ getvitops({
192
+ css: { input: 'design-system.json', format: 'css', out: 'src/styles' },
193
+ editor: true,
194
+ });
195
+ ```
196
+
197
+ ```html
198
+ <!-- anywhere in your layout -->
199
+ <wc-theme-editor></wc-theme-editor>
200
+ ```
201
+
202
+ `editor: true` copies `editor.js` into `public/vitops/`, loads it from `<Head />`, and mirrors
203
+ `design-manifest.json` to `/vitops/design-manifest.json` (override with the `manifest` attribute).
204
+ Outside Astro, load the bundle yourself and point `manifest` at the file.
205
+
206
+ **Save straight back to your config, in dev.** `@getvitops/vite` now serves a dev-only
207
+ `/__vitops/design-system` endpoint: the editor POSTs its patch, the plugin deep-merges it into your
208
+ `design-system.json`, validates the _merged_ result, writes it back preserving the file's formatting,
209
+ then regenerates and reloads. The endpoint exists only under `vite dev` — on a static deploy the
210
+ editor detects its absence and hides the button, while everything else still works.
211
+
212
+ **Added:** `colors.roleTokens` in `design-manifest.json` — the functional token set (bg / border /
213
+ solid / on-solid / text / emphasis stops) precomputed per hue, in `default` and `surface` variants for
214
+ both appearances. Re-pointing a role at another hue needs these: `solid` is chosen by scanning the hue
215
+ and `on-solid` is a computed contrast value, so neither is derivable by a browser client.
216
+
217
+ **Removed:** the dead `interaction` block from `design-manifest.json` — a hardcoded
218
+ `{duration, easing}` literal with no schema key, no reverse-index entry, and no corresponding CSS
219
+ variable. Nothing could have consumed it meaningfully. The real animation knobs are
220
+ `--animation-duration-*` / `--custom-ease-*`.
221
+
222
+ **Fixed:** a `[popover]` reset in `popover.css` was stripping the background, padding and border from
223
+ any pattern used as a popover. It is imported after `drawer.css`, so at equal specificity it beat
224
+ `.drawer` — and `dialog` (0-0-1) too — leaving a `.drawer[popover]` transparent and unpadded despite
225
+ drawer.css documenting popover as supported. The reset now sits in `:where()` at zero specificity, so
226
+ it still overrides the UA stylesheet but any pattern class takes its surface back. Open/closed
227
+ behaviour is unchanged.
228
+
229
+ **Added:** `input[type="range"]` and `input[type="color"]` now have baseline styling in `forms.css`
230
+ (accent colour from `--ui-primary-solid`; the colour swatch picks up the control border and radius).
231
+
232
+ ### Patch Changes
233
+
234
+ - @getvitops/utils@0.8.0
235
+
3
236
  ## 0.7.0
4
237
 
5
238
  ### Patch Changes
@@ -303,6 +303,16 @@
303
303
  failure leaves readable text rather than blank space. Scroll-timeline is also
304
304
  guarded — without it the text simply shows the final (to) color, still legible. */
305
305
  .text-reveal {
306
+ /* Both tones MUST default, and NOT to currentColor. They are consumed by the
307
+ gradient below, where a var() substitution failure makes `background`
308
+ invalid at computed-value time — which, with the `color: transparent` in
309
+ that same block, renders the text completely invisible rather than
310
+ degrading. currentColor is unusable there for the same reason: inside the
311
+ @supports block it resolves to that transparent value. So default to the
312
+ functional text tokens (they flip with the appearance) with a literal
313
+ backstop, since this is precisely the declaration that must never fail. */
314
+ --_reveal-from: var(--text-reveal-color-from, var(--neutral-text-x-muted, #9099a8));
315
+ --_reveal-to: var(--text-reveal-color-to, var(--neutral-text, #05070d));
306
316
  /* Fallback baseline: ordinary visible text in the start color. */
307
317
  color: var(--text-reveal-color-from, currentColor);
308
318
  }
@@ -313,8 +323,8 @@
313
323
  --text-reveal-background,
314
324
  linear-gradient(
315
325
  var(--text-reveal-slant, 90deg),
316
- var(--text-reveal-color-to) 50%,
317
- var(--text-reveal-color-from) 50%
326
+ var(--_reveal-to) 50%,
327
+ var(--_reveal-from) 50%
318
328
  )
319
329
  );
320
330
  background-size: 200% 100%;
@@ -8,6 +8,16 @@
8
8
  font-size: 100% !important;
9
9
  }
10
10
 
11
+ /* Drop the UA's 8px body margin. The framework owns page gutters via `.centered`
12
+ (--gutter), so the UA default just offsets every full-bleed surface — sticky
13
+ headers and `bg-*` bands end up inset by 8px with a sliver of canvas showing
14
+ around them. This is the only UA reset the framework makes: it deliberately
15
+ does NOT ship a general reset (no global box-sizing change), because that
16
+ would silently reflow existing consumer layouts. */
17
+ body {
18
+ margin: 0;
19
+ }
20
+
11
21
  @media (prefers-reduced-motion: no-preference) {
12
22
  html {
13
23
  scrollbar-gutter: stable;
@@ -56,3 +56,4 @@
56
56
  @import './patterns/nav.css';
57
57
  @import './patterns/carousel.css';
58
58
  @import './patterns/copy.css';
59
+ @import './patterns/theme-editor.css';
@@ -37,15 +37,31 @@ details,
37
37
  rotate: var(--_details-icon-rotate, 90deg);
38
38
  }
39
39
 
40
+ /**
41
+ * Collapse without a transition — deliberately.
42
+ *
43
+ * This carried the canonical open/close animation (`block-size: 0 → auto` with
44
+ * `content-visibility` under `allow-discrete`, backed by the
45
+ * `interpolate-size: allow-keywords` in utilities.css). In Chrome 149 that
46
+ * deadlocks: `content-visibility` stays `hidden`, so the content has no layout,
47
+ * so `auto` resolves to `0`, so the transition has nothing to run — and the
48
+ * disclosure never opens *at all*. Not "opens without animating": every
49
+ * `<details>` on the page becomes inert, which is a total content-loss bug.
50
+ *
51
+ * Verified against a bare `<details>` with only this stylesheet, and bisected:
52
+ * `transition: none` is the only thing that restores it. Transitioning only
53
+ * `block-size`, only `content-visibility`, `calc-size(auto, size)`, and the
54
+ * `grid-template-rows: 0fr → 1fr` technique all fail the same way.
55
+ *
56
+ * So: correctness over motion. Re-add the transition only with a live
57
+ * cross-browser check that a first click actually expands — a passing
58
+ * `@supports` query is not evidence, since the syntax is valid and supported;
59
+ * it's the interaction that breaks.
60
+ */
40
61
  &::details-content {
41
62
  display: block;
42
63
  overflow: hidden;
43
64
  block-size: 0;
44
- opacity: 0;
45
- transition:
46
- block-size 0.3s ease,
47
- opacity 0.3s ease,
48
- content-visibility 0.3s allow-discrete;
49
65
  }
50
66
 
51
67
  > summary + * {
@@ -62,13 +78,16 @@ details,
62
78
 
63
79
  &[open]::details-content {
64
80
  block-size: auto;
65
- opacity: 1;
66
81
  }
67
82
 
83
+ /* Leading marker. The default (trailing) icon uses `margin-inline-start: auto`
84
+ to push itself to the end; the mirrored `margin-inline-end: auto` here did
85
+ the same thing to everything *after* it, so the label got shoved to the
86
+ opposite edge and the variant read as right-aligned text. A leading marker
87
+ just wants both auto margins gone — `gap` on the summary does the spacing. */
68
88
  &.details--marker-start > summary > .details-icon {
69
89
  order: -1;
70
- margin-inline-start: 0;
71
- margin-inline-end: auto;
90
+ margin-inline: 0;
72
91
  }
73
92
 
74
93
  /* Plus/minus variant — toggle two sibling icon elements */
@@ -24,6 +24,21 @@
24
24
  backdrop-filter: blur(4px);
25
25
  }
26
26
 
27
+ /**
28
+ * Modeless — a panel you work *alongside* rather than through. Drops the
29
+ * scrim so the page behind stays legible, which is the whole point for a
30
+ * live editor or an inspector: you're watching what your edits do.
31
+ *
32
+ * Pair with `popover="manual"`. An `auto` popover light-dismisses on the
33
+ * first click outside — i.e. exactly the interaction a modeless panel exists
34
+ * to allow — and `manual` also drops Esc, so give it an explicit close
35
+ * control (and wire Esc yourself if the panel warrants it).
36
+ */
37
+ &.drawer--modeless::backdrop {
38
+ background: none;
39
+ backdrop-filter: none;
40
+ }
41
+
27
42
  &,
28
43
  &.drawer--left {
29
44
  inset-block: 0;
@@ -90,6 +90,37 @@ fieldset.fieldset,
90
90
  background: var(--surface-bg);
91
91
  }
92
92
 
93
+ /* ── Range + colour controls ───────────────────────────────────────────────── */
94
+ /* `accent-color` is the whole job for range: it themes the track fill and thumb
95
+ * natively, in both appearances, with no pseudo-element rewriting. The colour
96
+ * swatch only needs its chrome removed so the well fills the control box. */
97
+ input[type='range'] {
98
+ accent-color: var(--range-accent, var(--ui-primary-solid));
99
+ inline-size: 100%;
100
+ min-inline-size: 0;
101
+ }
102
+
103
+ input[type='color'] {
104
+ --_br: var(--br-input, var(--br-control, var(--br-default)));
105
+
106
+ inline-size: var(--color-swatch-size, 2rem);
107
+ block-size: var(--color-swatch-size, 2rem);
108
+ padding: 0;
109
+ border: var(--b-input, var(--b-control, var(--b-default)));
110
+ border-radius: var(--_br);
111
+ background: none;
112
+ cursor: pointer;
113
+
114
+ &::-webkit-color-swatch-wrapper {
115
+ padding: 2px;
116
+ }
117
+ &::-webkit-color-swatch,
118
+ &::-moz-color-swatch {
119
+ border: none;
120
+ border-radius: calc(var(--_br) - 2px);
121
+ }
122
+ }
123
+
93
124
  /* ── Input group — input flanked by icons/addons ───────────────────────────── */
94
125
  .input-group {
95
126
  --_br: var(--br-input-group, var(--br-control, var(--br-default)));
@@ -9,7 +9,7 @@
9
9
  --_bs: var(--bs, solid);
10
10
  border-width: var(--_bw);
11
11
  border-style: var(--_bs);
12
- border-color: var(--bc, var(--color-surface-xl, currentColor));
12
+ border-color: var(--bc, var(--surface-border, currentColor));
13
13
  }
14
14
 
15
15
  /* ── Group — collapse border-radius (+ shared borders) across direct children ─
@@ -4,14 +4,31 @@
4
4
  */
5
5
 
6
6
  /* ── Popover — native Popover API reset + anchored position variants ───────── */
7
- [popover] {
7
+
8
+ /**
9
+ * The UA gives `[popover]` a padding, border and canvas background; a bare
10
+ * popover wants none of that. But this partial is imported *after* drawer.css /
11
+ * dialog.css, so at plain `[popover]` specificity (0-1-0) the reset also beat
12
+ * `.drawer` (0-1-0, earlier) and `dialog` (0-0-1) — silently stripping the
13
+ * surface off any pattern used as a popover, which is exactly what drawer.css
14
+ * documents itself as supporting.
15
+ *
16
+ * So the reset sits in `:where()` at zero specificity: it still overrides the UA
17
+ * stylesheet, and *any* explicit class takes it back. Same mechanism the `btn`
18
+ * pattern uses with `:where(button, .btn)`. Keep the visual reset here and the
19
+ * open/closed behaviour below — that must stay at real specificity so a
20
+ * component's own rules can't accidentally reveal a closed popover.
21
+ */
22
+ :where([popover]) {
8
23
  padding: 0;
9
24
  border: none;
10
25
  background: transparent;
11
26
  color: inherit;
12
27
  overflow: visible;
13
28
  inset: auto;
29
+ }
14
30
 
31
+ [popover] {
15
32
  &:popover-open {
16
33
  opacity: 1;
17
34
  }
@@ -3,51 +3,97 @@
3
3
  * Consumes the generated token cascade (src/css/generated/tokens.css).
4
4
  */
5
5
 
6
- /* ── Subgrid — content-aligned cards/tables via CSS subgrid ────────────────── */
6
+ /* ── Subgrid — content-aligned cards/tables via CSS subgrid ────────────────────
7
+ *
8
+ * Each item spans `--subgrid-row-span` row tracks of the parent and re-declares
9
+ * them with `grid-template-rows: subgrid`, so the tranches inside every item —
10
+ * head, body, footer — land on the same row lines no matter how much content
11
+ * each one holds.
12
+ *
13
+ * <ul class="subgrid" style="--subgrid-cols: 3; --subgrid-row-span: 3">
14
+ *
15
+ * Public custom properties:
16
+ * --subgrid-cols columns (default 3)
17
+ * --subgrid-row-span row tracks each item spans, i.e. tranches per item (2)
18
+ * --subgrid-gap the grid gap — between columns, and between tranches (1.5rem)
19
+ * --subgrid-row-gap EXTRA space between wrapped rows of items (0); see below
20
+ */
7
21
  .subgrid {
8
- --_items-per-row: var(--items-per-row, 3);
9
- --_rows-per-item: var(--rows-per-item, 2);
10
- --_subgrid-gap: var(--subgrid-gap, 1.5rem);
22
+ --_cols: var(--subgrid-cols, 3);
23
+ --_row-span: var(--subgrid-row-span, 2);
24
+ --_gap: var(--subgrid-gap, 1.5rem);
25
+ --_row-gap: var(--subgrid-row-gap, 0px);
11
26
 
12
27
  display: grid;
13
- grid-template-columns: repeat(var(--_items-per-row), 1fr);
14
- gap: var(--_subgrid-gap);
28
+ grid-template-columns: repeat(var(--_cols), 1fr);
29
+ gap: var(--_gap);
15
30
 
16
31
  > * {
17
- grid-row: span var(--_rows-per-item);
32
+ grid-row: span var(--_row-span);
18
33
  display: grid;
19
34
  grid-template-rows: subgrid;
20
35
  }
21
36
 
37
+ /* Spacing between items is the grid's job, not the flow's — neutralise the
38
+ `.rhythm :where(ul, ol) > li + li` margin, which reaches into any list
39
+ inside a prose container and outweighs `> *` on specificity. */
40
+ &:is(ul, ol) > li + li {
41
+ margin-block-start: 0;
42
+ }
43
+
44
+ /* The grid's own row gap is the gap between an item's *tranches*, so it can't
45
+ also be the gap between *rows of items* — items past the first row take an
46
+ extra margin instead. Computed in CSS rather than from a server-rendered
47
+ index because --_cols can change in a media query. Guarded the same way as
48
+ .stagger (animation.css): sibling-index() lacks only Firefox as of 2026,
49
+ and where it's missing the margin stays 0 and rows fall back to the grid
50
+ gap, rather than producing an invalid margin. The second selector repeats
51
+ the rule at the specificity rhythm forces above. */
52
+ @supports (--x: sibling-index()) {
53
+ > *,
54
+ &:is(ul, ol) > li + li {
55
+ --_row-index: round(down, calc((sibling-index() - 1) / var(--_cols)), 1);
56
+ margin-block-start: calc(clamp(0, var(--_row-index), 1) * var(--_row-gap));
57
+ }
58
+ }
59
+
60
+ /* Markerless when it's a list — a subgrid of cards is a list of things, and
61
+ the markers would sit in the gutter. */
62
+ &:is(ul, ol) {
63
+ list-style: none;
64
+ margin: 0;
65
+ padding: 0;
66
+ }
67
+
22
68
  &.subgrid-cols-1 {
23
- --_items-per-row: 1;
69
+ --_cols: 1;
24
70
  }
25
71
  &.subgrid-cols-2 {
26
- --_items-per-row: 2;
72
+ --_cols: 2;
27
73
  }
28
74
  &.subgrid-cols-3 {
29
- --_items-per-row: 3;
75
+ --_cols: 3;
30
76
  }
31
77
  &.subgrid-cols-4 {
32
- --_items-per-row: 4;
78
+ --_cols: 4;
33
79
  }
34
80
 
35
81
  &.subgrid-rows-2 {
36
- --_rows-per-item: 2;
82
+ --_row-span: 2;
37
83
  }
38
84
  &.subgrid-rows-3 {
39
- --_rows-per-item: 3;
85
+ --_row-span: 3;
40
86
  }
41
87
  &.subgrid-rows-4 {
42
- --_rows-per-item: 4;
88
+ --_row-span: 4;
43
89
  }
44
90
 
45
91
  &.subgrid-responsive {
46
92
  @media (width < 60rem) {
47
- --_items-per-row: min(var(--items-per-row, 3), 2);
93
+ --_cols: min(var(--subgrid-cols, 3), 2);
48
94
  }
49
95
  @media (width < 40rem) {
50
- --_items-per-row: 1;
96
+ --_cols: 1;
51
97
  }
52
98
  }
53
99
  }