Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 23 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,25 +82,37 @@ does not ship (`cmd/palette`'s tests).
Type and layout are tokens too: Geist and Geist Mono (`fonts/`, OFL; declared once for this
repository's pages in `dist/fonts.css`, and a page that declares a face of its own fails
`go test`) at three weights that
say rank (600 a page's title, its verdict, a figure and a section's heading, 500 a button, a label
and a row's name, 400 the rest; `--spin-weight-*`), a 16 px reading size (below it iOS zooms into a
focused input) and 13 px for the dashboard's tables, a dashboard page's six ranks and its figure,
each one size at one weight (`[type].rank`, `--spin-rank-<rank>-{font,size,lh,weight,tracking,case}`),
say rank (600 what a page is and what a person reads first in a row, a card or a control, 500 what
a machine says beside it in the mono, 400 the rest; `--spin-weight-*`), a 16 px reading size (below
it iOS zooms into a focused input) and 13 px for the dashboard, a dashboard page's six ranks and its
figure, each one size at one weight (`[type].rank`, `--spin-rank-<rank>-{font,size,lh,weight,tracking,case}`),
a 72ch measure, 24 px for any pointer target and 44 px on a coarse pointer (WCAG 2.2, 2.5.8 and
2.5.5).
Sizes are variables in every output, so that a consumer has no number of its own to drift from:
a control's three heights (28, 32 and 36 px, `--spin-control-*`), a list's row (36 px,
`--spin-row`), the radius, and the two sidebars, the docs' in rem (`--spin-sidebar`, and
Starlight's `--sl-sidebar-width`) and the app's in px (`--spin-sidebar-app`). Three lines, by what
a control's three heights (28, 32 and 36 px, `--spin-control-*`) and a key hint's cap
(`--spin-kbd`); three corners by what they hold (`--spin-radius-xs`, `-sm` and `--spin-radius`);
the steps a component's parts are spaced by (`--spin-space-*`); a page's frame - the bar over it
(`--spin-bar`), the least a card is (`--spin-width-card-min`), the inspector
(`--spin-width-inspector`), a fact's label (`--spin-width-key`), a search field
(`--spin-width-search`); a state's mark (`--spin-mark`), the spot's signal and figures
(`--spin-signal-*`, `--spin-width-figure`) and a machine's last hour (`--spin-usage-width`,
`--spin-usage-height`); and the two sidebars, the docs' in rem (`--spin-sidebar`, and
Starlight's `--sl-sidebar-width`) and the app's in px (`--spin-sidebar-app`). What a page gives in
room is its density, comfortable on the root and compact under `[data-density='compact']`: its
insets, its gaps, a row of one line, of two and with its tile, and the tile (`--spin-row`,
`--spin-row-two`, `--spin-row-item`, `--spin-tile` and the rest). Three lines, by what
each must be seen against: `hairline` separates on the page and is held against the page alone,
`border` is a line between two surfaces and a secondary button's outline (`--spin-control-border`,
`--control-border`), and `border_strong` is an input's edge at 3:1. `palette.toml` says the rules
that are behaviour: one filled action per view, a list's row as a plane under the pointer with
its actions drawn only then, an icon alone only with its caption, a page's verdict on the spot - a
dark plane in either theme, `--spin-spot-*` - and a row's state as its chip, its mark on its tint.
that are behaviour: one filled action per view; selected, and where you are, as one tint
(`--spin-selected`) with the accent beside it; a card only for what needs the person; an icon alone
only with its caption; a page's verdict on the spot - a dark plane in either theme, with the one
texture in the palette, its grid (`--spin-spot-*`); a state as its tile or its chip, its mark on its
tint (`--spin-*-badge`); and a machine's last hour in its row (`--spin-usage-*`).
Motion is four durations and one easing (`--spin-duration-*`, `--spin-ease`): a movement says
what something does or that it answered a hand, runs once, and is its end state under reduced
motion.
motion. Two things move on their own, each stopping within 5 s: the title's cursor
(`--spin-blink`) and a working task's mark (`--spin-breathe`).

## Where it goes

Expand Down
43 changes: 31 additions & 12 deletions cmd/palette/checks.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,27 +121,40 @@ func holds(p palette) ([]result, error) {
}
for _, s := range []string{"page", "surface"} {
hold("text", "label on "+s, c["label"], c[s], text)
sel := c["accent"].over(c[s], p.Tint.Selected)
hold("text", "accent_text on the selected tint over "+s, c["accent_text"], sel, text)
hold("text", "text on the selected tint over "+s, c["text"], sel, text)
}
// A row's state chip: the state's mark on its tint, wherever a row is - its panel, under the
// pointer, selected. Its word is beside it on the row, in the text's colour.
selected := c["accent"].over(c["surface"], p.Tint.Selected)
// Selected, and where you are: every word keeps its colour on the tint, so nothing on a
// selected row, a selected card or the navigation's current item turns to another.
selected := selectedTint(p, c)
hold("text", "text on the selected tint", c["text"], selected, bodyText)
for _, k := range []string{"muted", "label", "accent_text", "success", "warning", "error"} {
hold("text", k+" on the selected tint", c[k], selected, text)
}
// What says selected is the accent beside the tint: a row's leading edge, a card's edge.
hold("non-text", "the accent (a selection's edge) on the selected tint", c["accent"], selected, nonText)
hold("non-text", "the accent (a selected card's edge) on surface", c["accent"], c["surface"], nonText)
// A state's tile and a row's state chip: the state's icon or mark on its tint, wherever a row
// is - its panel, under the pointer, selected - and at rest, muted's. Its word is beside it
// on the row, in the text's colour.
for _, g := range []struct {
name string
c rgb
}{{"surface", c["surface"]}, {"raised", c["raised"]}, {"the selected tint over surface", selected}} {
for _, st := range []string{"success", "warning", "error", "accent_text"} {
hold("non-text", st+" (a chip's mark) on its tint over "+g.name, c[st], c[st].over(g.c, p.Tint.Badge), nonText)
}{{"surface", c["surface"]}, {"raised", c["raised"]}, {"the selected tint", selected}} {
for _, st := range []string{"success", "warning", "error", "accent_text", "muted"} {
hold("non-text", st+" (a tile's icon, a chip's mark) on its tint over "+g.name, c[st], c[st].over(g.c, p.Tint.Badge), nonText)
}
}
// The spot: its words on it, and a state on it in dark's colour.
// The spot: its words on it, and a state and its accent on it in dark's colour.
hold("text", "spot_text on spot", c["spot_text"], c["spot"], bodyText)
hold("text", "spot_muted (what explains, a label) on spot", c["spot_muted"], c["spot"], text)
for _, st := range []string{"success", "warning", "error"} {
for _, st := range []string{"success", "warning", "error", "accent_text"} {
hold("text", "dark's "+st+" on spot", darkColors[st], c["spot"], text)
}
// A machine's last hour: its line and its own cores' dashes on what it used and what it is
// lent, and on the panel.
lent, used := usageBands(p, c)
hold("non-text", "the usage line (success) on what it used", c["success"], used, nonText)
hold("non-text", "its own cores' dashes (muted) on what it is lent", c["muted"], lent, nonText)
hold("non-text", "its own cores' dashes (muted) on surface", c["muted"], c["surface"], nonText)
hold("text", "on_accent on accent", c["on_accent"], c["accent"], text)
hold("text", "white on destructive", white, c["destructive"], text)
st := controlStates(p, c, m.name == "dark")
Expand Down Expand Up @@ -169,10 +182,16 @@ func holds(p palette) ([]result, error) {
apart("edge", "spot | page", c["spot"], c["page"], 0)
apart("line", "spot_border on spot", c["spot_border"], c["spot"], 0)
apart("line", "spot_border on page", c["spot_border"], c["page"], 0)
// The selected tint is a plane, told from what it sits on as a step under the pointer is;
// the accent at its edge is what is told apart as selected.
for _, s := range []string{"page", "surface"} {
apart("state", "selected tint over "+s+" | "+s, c["accent"].over(c[s], p.Tint.Selected), c[s], 0)
apart("hover", "the selected tint | "+s, selected, c[s], 0)
apart("hover", "hover tint over "+s+" | "+s, c["accent"].over(c[s], p.Tint.Hover), c[s], 0)
}
apart("state", "the accent (a selection's edge) | the selected tint", c["accent"], selected, 0)
apart("line", "a key hint's edge on a fill | the fill", kbdOnFill(p, c), c["accent"], 0)
apart("edge", "what a machine is lent | its panel", lent, c["surface"], 0)
apart("edge", "what a machine used | its panel", used, c["surface"], 0)
apart("hover", "accent under the pointer | accent", st.accentHover, c["accent"], 0)
apart("hover", "destructive under the pointer | destructive", st.destructiveHover, c["destructive"], 0)
apart("hover", "secondary under the pointer | secondary", st.controlHover, st.control, 0)
Expand Down
166 changes: 156 additions & 10 deletions cmd/palette/layout_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,20 +50,33 @@ func blocks(css []byte) []block {
return out
}

// A consumer draws a control, a row, a corner and its navigation at the palette's sizes only if
// the file it copies says them: each output carries each size its consumer draws, as
// A consumer draws a control, a corner, a page's frame and its navigation at the palette's sizes
// only if the file it copies says them: each output carries each size its consumer draws, as
// palette.toml has it.
func TestEveryOutputCarriesTheSizesItsConsumerDraws(t *testing.T) {
p := readPalette(t)
files := written(t, p)
px := func(n int) string { return fmt.Sprintf("%dpx", n) }
app := map[string]string{
"spin-control-sm": px(p.Controls.Sm), "spin-control-md": px(p.Controls.Md), "spin-control-lg": px(p.Controls.Lg),
"spin-row": px(p.Layout.Row), "spin-sidebar-app": px(p.Layout.SidebarApp),
"spin-kbd": px(p.Controls.Kbd), "spin-sidebar-app": px(p.Layout.SidebarApp), "spin-bar": px(p.Layout.Bar),
"spin-radius-xs": px(p.Layout.RadiusXs), "spin-radius-sm": px(p.Layout.RadiusSm), "spin-radius": px(p.Layout.Radius),
"spin-width-card-min": px(p.Layout.WidthCardMin), "spin-width-inspector": px(p.Layout.WidthInspector),
"spin-spot-grid-size": px(p.Layout.SpotGrid),
"spin-signal-width": px(p.Layout.Signal[0]), "spin-signal-height": px(p.Layout.Signal[1]),
"spin-width-figure": px(p.Layout.WidthFigure), "spin-mark": px(p.Layout.Mark),
"spin-width-key": px(p.Layout.WidthKey), "spin-width-search": px(p.Layout.WidthSearch),
"spin-usage-width": px(p.Chart.Usage.Width), "spin-usage-height": px(p.Chart.Usage.Height),
"spin-blink": fmt.Sprintf("%dms", p.Motion.Blink.Period), "spin-blink-times": fmt.Sprint(p.Motion.Blink.Times),
"spin-breathe": fmt.Sprintf("%dms", p.Motion.Breathe.Period), "spin-breathe-times": fmt.Sprint(p.Motion.Breathe.Times),
}
for _, k := range spaceSteps {
app["spin-space-"+k] = px(p.Layout.Space[k])
}
for file, want := range map[string]map[string]string{
"tokens.css": merge(app, map[string]string{"spin-radius-sm": px(p.Layout.RadiusSm), "spin-sidebar": fmt.Sprintf("%drem", p.Layout.Sidebar)}),
"dashboard.css": merge(app, map[string]string{"radius": px(p.Layout.RadiusSm)}),
"tokens.css": merge(app, map[string]string{"spin-sidebar": fmt.Sprintf("%drem", p.Layout.Sidebar)}),
// shadcn's --radius is a card's corner, what holds things.
"dashboard.css": merge(app, map[string]string{"radius": px(p.Layout.Radius)}),
"starlight.css": {"sl-sidebar-width": fmt.Sprintf("%drem", p.Layout.Sidebar)},
} {
got := map[string]string{}
Expand All @@ -80,24 +93,149 @@ func TestEveryOutputCarriesTheSizesItsConsumerDraws(t *testing.T) {
}

var tokens struct {
Layout map[string]int
Layout struct {
SidebarApp, Sidebar, RadiusSm, Radius int
Density map[string]map[string]int
}
Controls map[string]int
}
if err := json.Unmarshal(files["tokens.json"], &tokens); err != nil {
t.Fatal(err)
}
for name, want := range map[string]int{"Row": p.Layout.Row, "SidebarApp": p.Layout.SidebarApp, "Sidebar": p.Layout.Sidebar, "RadiusSm": p.Layout.RadiusSm} {
if tokens.Layout[name] != want {
t.Errorf("tokens.json: layout.%s is %d, want %d", name, tokens.Layout[name], want)
for name, got := range map[string][2]int{
"SidebarApp": {tokens.Layout.SidebarApp, p.Layout.SidebarApp}, "Sidebar": {tokens.Layout.Sidebar, p.Layout.Sidebar},
"RadiusSm": {tokens.Layout.RadiusSm, p.Layout.RadiusSm}, "Radius": {tokens.Layout.Radius, p.Layout.Radius},
"Density.comfortable.row": {tokens.Layout.Density["comfortable"]["row"], p.Layout.Density["comfortable"]["row"]},
} {
if got[0] != got[1] {
t.Errorf("tokens.json: layout.%s is %d, want %d", name, got[0], got[1])
}
}
for name, want := range map[string]int{"Sm": p.Controls.Sm, "Md": p.Controls.Md, "Lg": p.Controls.Lg} {
for name, want := range map[string]int{"Sm": p.Controls.Sm, "Md": p.Controls.Md, "Lg": p.Controls.Lg, "Kbd": p.Controls.Kbd} {
if tokens.Controls[name] != want {
t.Errorf("tokens.json: controls.%s is %d, want %d", name, tokens.Controls[name], want)
}
}
}

// A page drawn in either density has every size: each output that draws a dashboard carries
// comfortable on its root and compact under its attribute, each with every size palette.toml sets.
func TestEveryOutputCarriesBothDensities(t *testing.T) {
p := readPalette(t)
files := written(t, p)
for _, file := range []string{"tokens.css", "dashboard.css"} {
found := map[string]bool{}
for _, b := range blocks(files[file]) {
for _, name := range densities {
sel := fmt.Sprintf("[data-density='%s']", name)
if name == densities[0] {
sel = ":root, " + sel
}
if b.selector != sel {
continue
}
found[name] = true
for _, k := range densitySizes {
want := fmt.Sprintf("%dpx", p.Layout.Density[name][k])
if got := b.vars["spin-"+strings.ReplaceAll(k, "_", "-")]; got != want {
t.Errorf("%s %s: --spin-%s is %q, want %q", file, sel, k, got, want)
}
}
}
}
for _, name := range densities {
if !found[name] {
t.Errorf("%s has no block for %s", file, name)
}
}
}
}

// A density that leaves a size out, a space step that is missing, and a movement that runs for 5 s
// or longer are refused before anything is written.
func TestASizeLeftOutOrAMovementThatDoesNotStopIsRefused(t *testing.T) {
for what, tc := range map[string]struct {
plant func(*palette)
write func(palette) string
}{
"compact without its row": {func(p *palette) { delete(p.Layout.Density["compact"], "row") }, densityBlocks},
"a density nothing writes": {func(p *palette) { p.Layout.Density["roomy"] = p.Layout.Density["compact"] }, densityBlocks},
"a space step missing": {func(p *palette) { delete(p.Layout.Space, "md") }, spaceVars},
"a blink for 6 s": {func(p *palette) { p.Motion.Blink = movement{Period: 1000, Times: 6} }, movementVars},
"a breathe that never runs": {func(p *palette) { p.Motion.Breathe = movement{Period: 2000} }, movementVars},
} {
t.Run(what, func(t *testing.T) {
p := readPalette(t)
tc.plant(&p)
defer func() {
if recover() == nil {
t.Error("written without a complaint")
}
}()
tc.write(p)
})
}
}

// The spot's grid is a texture and never a rule: each of its hairlines is nearer the spot than the
// spot's border is, in both themes, as drawn and in every view.
func TestTheSpotsGridIsNearerTheSpotThanItsBorder(t *testing.T) {
p := readPalette(t)
dark, err := colors(p.Dark)
if err != nil {
t.Fatal(err)
}
for _, m := range []mode{p.Dark, p.Light} {
c, err := colors(m)
if err != nil {
t.Fatal(err)
}
grid := spotGrid(p, c, dark)
for _, v := range views {
g := deltaE00(v.fn(grid.linear()).lab(), v.fn(c["spot"].linear()).lab())
b := deltaE00(v.fn(c["spot_border"].linear()).lab(), v.fn(c["spot"].linear()).lab())
if g == 0 || g >= b {
t.Errorf("spot %s, %s: the grid is ΔE00 %.1f from the spot and its border %.1f", c["spot"].hex(), v.name, g, b)
}
}
}
}

// Each pattern the destination draws has its colour in each output that draws a dashboard, in both
// themes: a consumer that has no variable for one writes its own.
func TestEveryOutputCarriesThePatternsTheDestinationDraws(t *testing.T) {
files := written(t, readPalette(t))
for _, tc := range []struct {
file, theme string
names []string
}{
{"tokens.css", "spin-page", []string{
"spin-selected", "spin-spot-accent", "spin-spot-grid", "spin-kbd-fill-border", "spin-muted-badge",
"spin-usage-own", "spin-usage-lent", "spin-usage-used", "spin-usage-line",
}},
{"dashboard.css", "background", []string{
"selected", "spot-accent", "spot-grid", "kbd-fill-border", "muted-subtle",
"usage-own", "usage-lent", "usage-used", "usage-line",
}},
} {
var themes int
for _, b := range blocks(files[tc.file]) {
if b.vars[tc.theme] == "" {
continue
}
themes++
for _, name := range tc.names {
if b.vars[name] == "" {
t.Errorf("%s %s has no --%s", tc.file, b.selector, name)
}
}
}
if themes != 2 {
t.Errorf("%s: %d themes, want dark and light", tc.file, themes)
}
}
}

func merge(a, b map[string]string) map[string]string {
out := map[string]string{}
for k, v := range a {
Expand Down Expand Up @@ -177,6 +315,14 @@ func TestAQuietLineOrPlaneThatIsNotToldApartFails(t *testing.T) {
{"spot_muted (what explains, a label) on spot", func(m *mode) { m.SpotMuted = m.Spot }},
{"spot_border on spot", func(m *mode) { m.SpotBorder = m.Spot }},
{"dark's error on spot", func(m *mode) { m.Spot = "#EE7BB0" }},
{"dark's accent_text on spot", func(m *mode) { m.Spot = "#54CFF5" }},
// Selected: a plane told from its panel, and every word on it in its own colour.
{"the selected tint | surface", func(m *mode) { m.Accent = m.Surface }},
{"muted on the selected tint", func(m *mode) { m.Muted = m.Surface }},
{"error on the selected tint", func(m *mode) { m.Error = m.Surface }},
// A machine's last hour: its band shows on its panel, and its line on what it used.
{"what a machine is lent | its panel", func(m *mode) { m.Accent = m.Surface }},
{"the usage line (success) on what it used", func(m *mode) { m.Success = m.Surface }},
} {
for _, theme := range []string{"dark", "light"} {
t.Run(theme+" "+tc.pair, func(t *testing.T) {
Expand Down
Loading
Loading