Skip to content

feat: custom Tailwind configs + CSS Grid Level 1 (Phase A) - #18

Merged
Macawls merged 2 commits into
mainfrom
worktree-tailwind-configs-and-grid
Sep 5, 2026
Merged

Macawls merged 2 commits into
mainfrom
worktree-tailwind-configs-and-grid

Conversation

@Macawls

@Macawls Macawls commented Sep 5, 2026

Copy link
Copy Markdown
Owner

Summary

Two new capabilities threaded through library, CLI, and HTTP server.

Custom Tailwind configs — extend the built-in palette, spacing scale, font stacks, or inject arbitrary classes via three interchangeable surfaces:

  • Go struct (Options.TailwindConfig)
  • Tailwind v4 `@theme` CSS (--tailwind-config theme.css)
  • JSON (tailwindConfig / `tailwindConfigCSS` HTTP payload fields)

Per-config resolver cache keyed by content hash so different configs never share entries; nil-config hot path is unchanged. Renderer.Handler now enforces a 10 MB request-body cap.

CSS Grid — new layout/grid.go implements CSS Grid Level 1 (Phase A):

  • display: grid dispatch alongside flex
  • Track sizing: fixed / percent / fr / auto, repeat(N, ...), minmax(a, b) (max value)
  • Placement: explicit line indices (positive and negative — col-span-full works), span, single-axis definite placement per spec §8.5 minor-axis-definite bucket, and auto-placement with row/column flow, capped at 10k implicit tracks
  • Tailwind utilities: grid, inline-grid, grid-cols-{1..12}, grid-rows-{1..6}, col-span-{N}, col-span-full, col-start/end, row-*, grid-flow-*, auto-cols/rows-*

Also drops the "no build step" wording ("no Tailwind CLI required" everywhere), adds a new CSS Grid guide, and updates the CLI --help to reflect grid support + the new --tailwind-config flag.

Phase A limitations (deferred to follow-ups)

  • minmax() lower bound not enforced
  • min-content / max-content / fit-content() degrade to auto
  • No grid-template-areas, named lines, or subgrid
  • No repeat(auto-fill/auto-fit, ...)
  • Per-cell justify-self / align-self degrades to stretch

Test plan

  • go test ./... — all packages green
  • Grid layout unit tests: fixed 2×2, fr distribution, gap, explicit placement, span, col-span-full, single-axis placement, negative line end, end < start swap, unbounded span cap, auto-flow, percent tracks
  • Tailwind grid class tests: 18 utility → CSS assertions
  • TailwindConfig tests: 20 covering override paths, CSS parser variants, cache isolation
  • End-to-end grid render via CLI (fr + gap + col-span verified)
  • Manual review of PNG output for a real dashboard-style grid template

- Replaces "no build step" with "no Tailwind CLI required" across README,
  site docs, and llms.txt (the old phrasing was ambiguous — every Go
  consumer has a build step).
- Adds "Custom config" section to the Tailwind guide covering the Go
  struct, Tailwind v4 @theme CSS, and JSON payload variants, plus
  precedence rules and trust/immutability notes.
- Adds a new CSS Grid guide covering track sizing, placement, and
  Phase A limitations.
- Adds Grid class tables to the Tailwind reference and mentions grid
  and custom configs in the README feature list.
Two new capabilities, threaded through Options, HTTP handler, server, and
CLI:

TailwindConfig — extends the built-in class table with:
- Custom color palettes (Colors[name][shade])
- Custom spacing keys (Spacing[key])
- Font family utilities (Fonts[key])
- Arbitrary class overrides (Extend[cls][prop])

Three input surfaces:
- Go struct: Options.TailwindConfig
- Tailwind v4 @theme CSS: --tailwind-config theme.css or POST body
- JSON: matching struct schema, --tailwind-config theme.json or POST body

Per-config resolver cache keyed by SHA-256 of sorted maps so distinct
configs never share entries; nil-config path is unchanged. Server cache
key incorporates cfg.Key() so different-config renders don't collide.
Renderer.Handler now enforces a 10 MB request body cap.

CSS Grid — new layout/grid.go implements CSS Grid Level 1 (Phase A):
- display: grid dispatch alongside flex
- Track sizing: fixed length, percent, fr distribution, auto
- Track template parsing: repeat(N, ...), minmax(a, b) (max only),
  auto / min-content / max-content collapse to auto
- Placement: explicit line indices (positive and negative — col-span-full
  works), span shorthand, single-axis definite placement (spec §8.5
  minor-axis-definite bucket), and auto-placement with row/column flow
- Auto-placement bounded at 10,000 implicit tracks to prevent runaway
  growth from pathological input
- Gap, row-gap, column-gap
- Tailwind grid utilities: grid, inline-grid, grid-cols-{1..12},
  grid-rows-{1..6}, col-span-{N}, col-span-full, col-start/end,
  row-span-{N}, row-span-full, row-start/end, grid-flow-*, auto-cols/rows-*

Deferrals (documented in the grid guide):
- minmax lower bound not enforced
- min/max/fit-content degrade to auto
- No grid-template-areas, named lines, or subgrid
- No auto-fill / auto-fit repeat expansion
- justify-self / align-self within cells degrades to stretch
@Macawls
Macawls merged commit f21c86b into main Sep 5, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant