@mccaskie-labs/workbench-ui 0.8.0 → 0.10.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 +13 -0
- package/README.md +31 -0
- package/dist/cli.d.ts +12 -0
- package/dist/cli.js +52 -6
- package/dist/confirm.d.ts +60 -0
- package/dist/confirm.js +85 -0
- package/dist/index.d.ts +14 -1
- package/dist/index.js +14 -1
- package/dist/library.d.ts +100 -0
- package/dist/library.generated.d.ts +432 -0
- package/dist/library.generated.js +473 -0
- package/dist/library.js +134 -0
- package/dist/theme.d.ts +54 -24
- package/dist/theme.js +140 -101
- package/dist/ui-styles.js +8 -2
- package/package.json +3 -2
package/dist/theme.d.ts
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
export type Scheme
|
|
3
|
-
/** How round the corners are. */
|
|
4
|
-
export type Shape = "square" | "soft" | "round";
|
|
1
|
+
import { type Library, type LayoutItem, type LookItem, type Palette, type Scheme, type Shape } from "./library.ts";
|
|
2
|
+
export type { Palette, Scheme, Shape } from "./library.ts";
|
|
5
3
|
/** One shared token: its name and what it sets. */
|
|
6
4
|
export interface ThemeToken {
|
|
7
5
|
name: `--wb-${string}`;
|
|
@@ -18,23 +16,20 @@ export interface Theme {
|
|
|
18
16
|
scheme: Scheme;
|
|
19
17
|
tokens: Record<string, string>;
|
|
20
18
|
}
|
|
21
|
-
/**
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
muted: string;
|
|
26
|
-
accent: string;
|
|
27
|
-
danger: string;
|
|
28
|
-
success: string;
|
|
29
|
-
warning: string;
|
|
30
|
-
}
|
|
31
|
-
/** A ready-made look: a palette for light and for dark, two fonts and a corner shape. */
|
|
19
|
+
/**
|
|
20
|
+
* A look with its parts filled in from the library: a palette for light and
|
|
21
|
+
* for dark, two fonts and a corner shape, plus the ids it names.
|
|
22
|
+
*/
|
|
32
23
|
export interface Look {
|
|
33
24
|
id: LookId;
|
|
34
25
|
title: string;
|
|
35
26
|
feel: string;
|
|
36
27
|
/** The New project gallery's starter groups this look is suggested for. */
|
|
37
28
|
suggestedFor: readonly string[];
|
|
29
|
+
status: LookItem["status"];
|
|
30
|
+
palette: string;
|
|
31
|
+
pairing: string;
|
|
32
|
+
layout: string;
|
|
38
33
|
light: Palette;
|
|
39
34
|
dark: Palette;
|
|
40
35
|
fonts: {
|
|
@@ -43,21 +38,32 @@ export interface Look {
|
|
|
43
38
|
};
|
|
44
39
|
shape: Shape;
|
|
45
40
|
}
|
|
46
|
-
|
|
41
|
+
/** A look's id: one of the library's, or a project's own. */
|
|
42
|
+
export type LookId = string;
|
|
43
|
+
/** A look item with its palette and pairing filled in. */
|
|
44
|
+
export declare function lookOf(item: LookItem, lib?: Library): Look;
|
|
45
|
+
/** The looks a library offers (released, then testing; never withdrawn). */
|
|
46
|
+
export declare function looksIn(lib?: Library, statuses?: readonly LookItem["status"][]): Look[];
|
|
47
47
|
/**
|
|
48
|
-
* The
|
|
49
|
-
* share Clean). Fonts are
|
|
50
|
-
*
|
|
48
|
+
* The released looks in this version of workbench-ui, one suggested per
|
|
49
|
+
* starter group (General and Professional share Clean). Fonts are
|
|
50
|
+
* open-licence families with system fallbacks; the page uses the fallback
|
|
51
|
+
* until the project hosts the font.
|
|
51
52
|
*/
|
|
52
53
|
export declare const LOOKS: readonly Look[];
|
|
53
54
|
/** The look a new project starts with when nothing else is chosen: Clean, light (Robert, 24 November 2026). */
|
|
54
55
|
export declare const DEFAULT_LOOK: LookId;
|
|
55
56
|
/** The look suggested for a starter group of Control's New project gallery, Clean when none fits. */
|
|
56
|
-
export declare function lookFor(group: string): Look;
|
|
57
|
-
|
|
57
|
+
export declare function lookFor(group: string, lib?: Library): Look;
|
|
58
|
+
/** A look by id, whatever its state: a project naming a withdrawn look keeps it. */
|
|
59
|
+
export declare function lookById(id: string, lib?: Library): Look;
|
|
58
60
|
/** What a project says about its look: brand.json's fields, all optional. */
|
|
59
61
|
export interface ThemeInput {
|
|
60
62
|
look?: string;
|
|
63
|
+
/** A palette, pairing or site layout by id, over the look's own. */
|
|
64
|
+
palette?: string;
|
|
65
|
+
pairing?: string;
|
|
66
|
+
layout?: string;
|
|
61
67
|
scheme?: Scheme;
|
|
62
68
|
shape?: Shape;
|
|
63
69
|
colours?: {
|
|
@@ -86,20 +92,44 @@ export declare function contrast(a: string, b: string): number;
|
|
|
86
92
|
* text until it reads; anything else that doesn't read is left for
|
|
87
93
|
* themeProblems to name, since it is the owner's own colour.
|
|
88
94
|
*/
|
|
89
|
-
export declare function resolveTheme(input?: ThemeInput): Theme;
|
|
95
|
+
export declare function resolveTheme(input?: ThemeInput, lib?: Library): Theme;
|
|
90
96
|
/**
|
|
91
97
|
* The look of a project's own admin pages (Robert, 24 November 2026): the
|
|
92
98
|
* project's accent and fonts on Clean's light neutrals, so a busy page stays
|
|
93
99
|
* readable whatever the public look. An accent too pale for white is darkened
|
|
94
100
|
* until it reads.
|
|
95
101
|
*/
|
|
96
|
-
export declare function resolveAdminTheme(input?: ThemeInput): Theme;
|
|
102
|
+
export declare function resolveAdminTheme(input?: ThemeInput, lib?: Library): Theme;
|
|
103
|
+
/** A project's site layout: brand.json's `layout`, else its look's (docs/look-studio.md §6). */
|
|
104
|
+
export declare function resolveSiteLayout(input?: ThemeInput, lib?: Library): LayoutItem;
|
|
97
105
|
/** Every pair of a theme's colours that doesn't read, named in plain words. */
|
|
98
106
|
export declare function themeProblems(theme: Theme): string[];
|
|
99
107
|
/** What brand.json says about the look, read loosely: a field of the wrong kind is named, never guessed. */
|
|
100
|
-
export declare function themeInput(brand: unknown): {
|
|
108
|
+
export declare function themeInput(brand: unknown, lib?: Library): {
|
|
101
109
|
input: ThemeInput;
|
|
102
110
|
problems: string[];
|
|
103
111
|
};
|
|
104
112
|
/** The project's `@layer workbench.theme`: the public look on :root, the admin look on html.wb-ui-admin. */
|
|
105
113
|
export declare function renderTheme(site: Theme, admin: Theme, source: string): string;
|
|
114
|
+
/** How far apart two palettes are: the mean distance of their background, text and accent in light and dark, 0 to 441. */
|
|
115
|
+
export declare function paletteDistance(a: {
|
|
116
|
+
light: Palette;
|
|
117
|
+
dark: Palette;
|
|
118
|
+
}, b: {
|
|
119
|
+
light: Palette;
|
|
120
|
+
dark: Palette;
|
|
121
|
+
}): number;
|
|
122
|
+
/**
|
|
123
|
+
* The least distance a new palette must keep from every other: just under the
|
|
124
|
+
* closest pair of the seven palettes of 24 November 2026 (Sturdy and Warm,
|
|
125
|
+
* 30.6), so a new one is never a near copy.
|
|
126
|
+
*/
|
|
127
|
+
export declare const MIN_PALETTE_DISTANCE = 30;
|
|
128
|
+
/**
|
|
129
|
+
* What breaks the library's rules, in plain words (empty when it keeps them):
|
|
130
|
+
* every palette reads in light, dark and as an admin page; no two palettes
|
|
131
|
+
* are near copies; ids are unique within a kind; a look names parts that
|
|
132
|
+
* exist, and a released look only released ones. Run in the package's tests
|
|
133
|
+
* and by `styles --check` on a project's own look files.
|
|
134
|
+
*/
|
|
135
|
+
export declare function libraryProblems(lib?: Library): string[];
|
package/dist/theme.js
CHANGED
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
//
|
|
9
9
|
// Every value here is worked out to a plain colour (no color-mix or variables),
|
|
10
10
|
// so emails and PDFs can take the same values inline.
|
|
11
|
+
import { findItem, LIBRARY } from "./library.js";
|
|
11
12
|
/** The shared tokens every tool's variables default to, in the order workbench.css lists them. */
|
|
12
13
|
export const THEME_TOKENS = [
|
|
13
14
|
{ name: "--wb-background", about: "Behind the page", from: "set" },
|
|
@@ -35,98 +36,56 @@ export const THEME_TOKENS = [
|
|
|
35
36
|
const SANS = 'system-ui,-apple-system,"Segoe UI",Roboto,sans-serif';
|
|
36
37
|
const SERIF = 'Georgia,"Times New Roman",serif';
|
|
37
38
|
const MONO = 'ui-monospace,"Cascadia Code",Consolas,monospace';
|
|
38
|
-
const
|
|
39
|
-
|
|
40
|
-
const
|
|
41
|
-
|
|
39
|
+
const stack = (f) => `"${f.family}",${f.fallback === "serif" ? SERIF : SANS}`;
|
|
40
|
+
function part(lib, kind, id, of) {
|
|
41
|
+
const item = findItem(lib, kind, id);
|
|
42
|
+
if (!item)
|
|
43
|
+
throw new Error(`${of} names the ${kind} ${id}, which isn't in the library`);
|
|
44
|
+
return item;
|
|
45
|
+
}
|
|
46
|
+
/** A look item with its palette and pairing filled in. */
|
|
47
|
+
export function lookOf(item, lib = LIBRARY) {
|
|
48
|
+
const palette = part(lib, "palette", item.palette, `the look ${item.id}`);
|
|
49
|
+
const pairing = part(lib, "pairing", item.pairing, `the look ${item.id}`);
|
|
50
|
+
part(lib, "layout", item.layout, `the look ${item.id}`);
|
|
51
|
+
return {
|
|
52
|
+
id: item.id,
|
|
53
|
+
title: item.title,
|
|
54
|
+
feel: item.feel,
|
|
55
|
+
suggestedFor: item.suggestedFor,
|
|
56
|
+
status: item.status,
|
|
57
|
+
palette: item.palette,
|
|
58
|
+
pairing: item.pairing,
|
|
59
|
+
layout: item.layout,
|
|
60
|
+
light: palette.light,
|
|
61
|
+
dark: palette.dark,
|
|
62
|
+
fonts: { heading: stack(pairing.heading), body: stack(pairing.body) },
|
|
63
|
+
shape: item.shape,
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
/** The looks a library offers (released, then testing; never withdrawn). */
|
|
67
|
+
export function looksIn(lib = LIBRARY, statuses = ["released"]) {
|
|
68
|
+
return lib.looks.filter((l) => statuses.includes(l.status)).map((l) => lookOf(l, lib));
|
|
69
|
+
}
|
|
42
70
|
/**
|
|
43
|
-
* The
|
|
44
|
-
* share Clean). Fonts are
|
|
45
|
-
*
|
|
71
|
+
* The released looks in this version of workbench-ui, one suggested per
|
|
72
|
+
* starter group (General and Professional share Clean). Fonts are
|
|
73
|
+
* open-licence families with system fallbacks; the page uses the fallback
|
|
74
|
+
* until the project hosts the font.
|
|
46
75
|
*/
|
|
47
|
-
export const LOOKS =
|
|
48
|
-
{
|
|
49
|
-
id: "clean",
|
|
50
|
-
title: "Clean",
|
|
51
|
-
feel: "Plain and trustworthy",
|
|
52
|
-
suggestedFor: ["General", "Professional and creative"],
|
|
53
|
-
light: { background: "#ffffff", text: "#1f2937", muted: "#5b6472", accent: "#2563eb", ...OK_LIGHT },
|
|
54
|
-
dark: { background: "#121214", text: "#e8e8ec", muted: "#a0a0ac", accent: "#6aa1ff", ...OK_DARK },
|
|
55
|
-
fonts: { heading: font("Inter"), body: font("Inter") },
|
|
56
|
-
shape: "soft",
|
|
57
|
-
},
|
|
58
|
-
{
|
|
59
|
-
id: "warm",
|
|
60
|
-
title: "Warm",
|
|
61
|
-
feel: "Welcoming and homely",
|
|
62
|
-
suggestedFor: ["Food and stays"],
|
|
63
|
-
light: { background: "#fbf6ef", text: "#3b2a20", muted: "#6e5a4c", accent: "#a8441f", ...OK_LIGHT },
|
|
64
|
-
dark: { background: "#1c1612", text: "#f3e9df", muted: "#bfae9f", accent: "#f08a5d", ...OK_DARK },
|
|
65
|
-
fonts: { heading: font("Fraunces", SERIF), body: font("Source Sans 3") },
|
|
66
|
-
shape: "soft",
|
|
67
|
-
},
|
|
68
|
-
{
|
|
69
|
-
id: "calm",
|
|
70
|
-
title: "Calm",
|
|
71
|
-
feel: "Quiet and airy",
|
|
72
|
-
suggestedFor: ["Health, beauty and fitness"],
|
|
73
|
-
light: { background: "#f6f4ef", text: "#2b2f2a", muted: "#5d635b", accent: "#4a6b46", ...OK_LIGHT },
|
|
74
|
-
dark: { background: "#161a16", text: "#e6ebe4", muted: "#a7b0a4", accent: "#9cc596", ...OK_DARK },
|
|
75
|
-
fonts: { heading: font("Nunito Sans"), body: font("Nunito Sans") },
|
|
76
|
-
shape: "round",
|
|
77
|
-
},
|
|
78
|
-
{
|
|
79
|
-
id: "sturdy",
|
|
80
|
-
title: "Sturdy",
|
|
81
|
-
feel: "Solid and no-nonsense",
|
|
82
|
-
suggestedFor: ["Trades and home"],
|
|
83
|
-
light: { background: "#ffffff", text: "#14213d", muted: "#4d5873", accent: "#c2410c", ...OK_LIGHT },
|
|
84
|
-
dark: { background: "#0f1626", text: "#e9edf5", muted: "#a3adc2", accent: "#fb8c3c", ...OK_DARK },
|
|
85
|
-
fonts: { heading: font("Barlow Condensed"), body: font("Barlow") },
|
|
86
|
-
shape: "square",
|
|
87
|
-
},
|
|
88
|
-
{
|
|
89
|
-
id: "bold",
|
|
90
|
-
title: "Bold",
|
|
91
|
-
feel: "Lively, for nights out",
|
|
92
|
-
suggestedFor: ["Venues, hire and tours"],
|
|
93
|
-
light: { background: "#ffffff", text: "#121212", muted: "#555555", accent: "#b0136a", ...OK_LIGHT },
|
|
94
|
-
dark: { background: "#121212", text: "#ffffff", muted: "#b3b3b3", accent: "#ff5cb0", ...OK_DARK },
|
|
95
|
-
fonts: { heading: font("Archivo"), body: font("Archivo") },
|
|
96
|
-
shape: "soft",
|
|
97
|
-
},
|
|
98
|
-
{
|
|
99
|
-
id: "bright",
|
|
100
|
-
title: "Bright",
|
|
101
|
-
feel: "Playful and friendly to kids",
|
|
102
|
-
suggestedFor: ["Learning and kids"],
|
|
103
|
-
light: { background: "#ffffff", text: "#1e1b4b", muted: "#55527a", accent: "#1d64c8", ...OK_LIGHT },
|
|
104
|
-
dark: { background: "#151337", text: "#f1f0ff", muted: "#b4b1d9", accent: "#fbbf24", ...OK_DARK },
|
|
105
|
-
fonts: { heading: font("Baloo 2"), body: font("Nunito") },
|
|
106
|
-
shape: "round",
|
|
107
|
-
},
|
|
108
|
-
{
|
|
109
|
-
id: "friendly",
|
|
110
|
-
title: "Friendly",
|
|
111
|
-
feel: "Open, for community groups",
|
|
112
|
-
suggestedFor: ["Community"],
|
|
113
|
-
light: { background: "#fafaf7", text: "#273036", muted: "#58636a", accent: "#0f766e", ...OK_LIGHT },
|
|
114
|
-
dark: { background: "#121a19", text: "#e7efed", muted: "#a5b4b1", accent: "#4fd1c5", ...OK_DARK },
|
|
115
|
-
fonts: { heading: font("Work Sans"), body: font("Work Sans") },
|
|
116
|
-
shape: "soft",
|
|
117
|
-
},
|
|
118
|
-
];
|
|
76
|
+
export const LOOKS = looksIn();
|
|
119
77
|
/** The look a new project starts with when nothing else is chosen: Clean, light (Robert, 24 November 2026). */
|
|
120
78
|
export const DEFAULT_LOOK = "clean";
|
|
121
79
|
/** The look suggested for a starter group of Control's New project gallery, Clean when none fits. */
|
|
122
|
-
export function lookFor(group) {
|
|
123
|
-
return
|
|
80
|
+
export function lookFor(group, lib = LIBRARY) {
|
|
81
|
+
return looksIn(lib).find((l) => l.suggestedFor.includes(group)) ?? lookById(DEFAULT_LOOK, lib);
|
|
124
82
|
}
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
83
|
+
/** A look by id, whatever its state: a project naming a withdrawn look keeps it. */
|
|
84
|
+
export function lookById(id, lib = LIBRARY) {
|
|
85
|
+
const item = findItem(lib, "look", id);
|
|
86
|
+
if (!item)
|
|
87
|
+
throw new Error(`no look called ${id}: choose one of ${looksIn(lib, ["released", "testing"]).map((l) => l.id).join(", ")}`);
|
|
88
|
+
return lookOf(item, lib);
|
|
130
89
|
}
|
|
131
90
|
const RADII = {
|
|
132
91
|
square: { radius: "4px", small: "3px" },
|
|
@@ -206,10 +165,12 @@ const family = (f, fallback) => (f ? `"${f.family.replace(/["\\]/g, "")}",${fall
|
|
|
206
165
|
* text until it reads; anything else that doesn't read is left for
|
|
207
166
|
* themeProblems to name, since it is the owner's own colour.
|
|
208
167
|
*/
|
|
209
|
-
export function resolveTheme(input = {}) {
|
|
210
|
-
const look = lookById(input.look ?? DEFAULT_LOOK);
|
|
168
|
+
export function resolveTheme(input = {}, lib = LIBRARY) {
|
|
169
|
+
const look = lookById(input.look ?? DEFAULT_LOOK, lib);
|
|
211
170
|
const scheme = input.scheme ?? "light";
|
|
212
|
-
const base = look[scheme];
|
|
171
|
+
const base = input.palette ? part(lib, "palette", input.palette, "brand.json")[scheme] : look[scheme];
|
|
172
|
+
const pairing = input.pairing ? part(lib, "pairing", input.pairing, "brand.json") : null;
|
|
173
|
+
const lookFonts = pairing ? { heading: stack(pairing.heading), body: stack(pairing.body) } : look.fonts;
|
|
213
174
|
const c = input.colours ?? {};
|
|
214
175
|
const p = {
|
|
215
176
|
...base,
|
|
@@ -220,8 +181,8 @@ export function resolveTheme(input = {}) {
|
|
|
220
181
|
};
|
|
221
182
|
p.muted = untilContrast(p.muted, p.background, p.text, 4.5);
|
|
222
183
|
const fonts = {
|
|
223
|
-
heading: family(input.fonts?.heading,
|
|
224
|
-
body: family(input.fonts?.body,
|
|
184
|
+
heading: family(input.fonts?.heading, lookFonts.heading) ?? lookFonts.heading,
|
|
185
|
+
body: family(input.fonts?.body, lookFonts.body) ?? lookFonts.body,
|
|
225
186
|
};
|
|
226
187
|
return themeFrom(p, scheme, fonts, input.shape ?? look.shape);
|
|
227
188
|
}
|
|
@@ -231,11 +192,15 @@ export function resolveTheme(input = {}) {
|
|
|
231
192
|
* readable whatever the public look. An accent too pale for white is darkened
|
|
232
193
|
* until it reads.
|
|
233
194
|
*/
|
|
234
|
-
export function resolveAdminTheme(input = {}) {
|
|
235
|
-
const site = resolveTheme(input);
|
|
236
|
-
const clean = lookById("clean").light;
|
|
195
|
+
export function resolveAdminTheme(input = {}, lib = LIBRARY) {
|
|
196
|
+
const site = resolveTheme(input, lib);
|
|
197
|
+
const clean = lookById("clean", lib).light;
|
|
237
198
|
const accent = untilContrast(site.tokens["--wb-accent"], clean.background, "#000000", 4.5);
|
|
238
|
-
return themeFrom({ ...clean, accent }, "light", { heading: site.tokens["--wb-font-heading"], body: site.tokens["--wb-font"] }, input.shape ?? lookById(input.look ?? DEFAULT_LOOK).shape);
|
|
199
|
+
return themeFrom({ ...clean, accent }, "light", { heading: site.tokens["--wb-font-heading"], body: site.tokens["--wb-font"] }, input.shape ?? lookById(input.look ?? DEFAULT_LOOK, lib).shape);
|
|
200
|
+
}
|
|
201
|
+
/** A project's site layout: brand.json's `layout`, else its look's (docs/look-studio.md §6). */
|
|
202
|
+
export function resolveSiteLayout(input = {}, lib = LIBRARY) {
|
|
203
|
+
return part(lib, "layout", input.layout ?? lookById(input.look ?? DEFAULT_LOOK, lib).layout, "brand.json");
|
|
239
204
|
}
|
|
240
205
|
/** Pairs that must read (WCAG 2.2 AA: 4.5:1 for text, 3:1 for a control's edge), each with what it is. */
|
|
241
206
|
const PAIRS = [
|
|
@@ -255,17 +220,26 @@ export function themeProblems(theme) {
|
|
|
255
220
|
return PAIRS.filter(([a, b, ratio]) => contrast(t[a], t[b]) < ratio).map(([a, b, ratio, what]) => `${what} doesn't read: ${a} ${t[a]} on ${b} ${t[b]} is ${contrast(t[a], t[b]).toFixed(2)}:1, needs ${ratio}:1`);
|
|
256
221
|
}
|
|
257
222
|
/** What brand.json says about the look, read loosely: a field of the wrong kind is named, never guessed. */
|
|
258
|
-
export function themeInput(brand) {
|
|
223
|
+
export function themeInput(brand, lib = LIBRARY) {
|
|
259
224
|
const problems = [];
|
|
260
225
|
const input = {};
|
|
261
226
|
if (!brand || typeof brand !== "object")
|
|
262
227
|
return { input, problems: ["brand.json must hold an object"] };
|
|
263
228
|
const b = brand;
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
229
|
+
for (const kind of ["look", "palette", "pairing", "layout"]) {
|
|
230
|
+
const v = b[kind];
|
|
231
|
+
if (v === undefined)
|
|
232
|
+
continue;
|
|
233
|
+
const item = typeof v === "string" ? findItem(lib, kind, v) : undefined;
|
|
234
|
+
if (item) {
|
|
235
|
+
input[kind] = v;
|
|
236
|
+
if (item.status === "withdrawn")
|
|
237
|
+
problems.push(`brand.json: the ${kind} ${v} is withdrawn: it still works, but choose another before it is removed`);
|
|
238
|
+
}
|
|
239
|
+
else {
|
|
240
|
+
const offered = (kind === "look" ? lib.looks : kind === "palette" ? lib.palettes : kind === "pairing" ? lib.pairings : lib.layouts).filter((i) => i.status !== "withdrawn");
|
|
241
|
+
problems.push(`brand.json: ${kind} must be one of ${offered.map((i) => i.id).join(", ")}`);
|
|
242
|
+
}
|
|
269
243
|
}
|
|
270
244
|
if (b.scheme !== undefined) {
|
|
271
245
|
if (b.scheme === "light" || b.scheme === "dark")
|
|
@@ -332,3 +306,68 @@ export function renderTheme(site, admin, source) {
|
|
|
332
306
|
"}",
|
|
333
307
|
].join("\n");
|
|
334
308
|
}
|
|
309
|
+
// ---- the library's own rules (docs/look-studio.md §4) --------------------------------
|
|
310
|
+
const RGB_WEIGHTS = ["background", "text", "accent"];
|
|
311
|
+
/** How far apart two palettes are: the mean distance of their background, text and accent in light and dark, 0 to 441. */
|
|
312
|
+
export function paletteDistance(a, b) {
|
|
313
|
+
let total = 0;
|
|
314
|
+
for (const scheme of ["light", "dark"]) {
|
|
315
|
+
for (const k of RGB_WEIGHTS) {
|
|
316
|
+
const [x, y] = [rgb(a[scheme][k]), rgb(b[scheme][k])];
|
|
317
|
+
total += Math.hypot(x[0] - y[0], x[1] - y[1], x[2] - y[2]);
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
return total / (2 * RGB_WEIGHTS.length);
|
|
321
|
+
}
|
|
322
|
+
/**
|
|
323
|
+
* The least distance a new palette must keep from every other: just under the
|
|
324
|
+
* closest pair of the seven palettes of 24 November 2026 (Sturdy and Warm,
|
|
325
|
+
* 30.6), so a new one is never a near copy.
|
|
326
|
+
*/
|
|
327
|
+
export const MIN_PALETTE_DISTANCE = 30;
|
|
328
|
+
/**
|
|
329
|
+
* What breaks the library's rules, in plain words (empty when it keeps them):
|
|
330
|
+
* every palette reads in light, dark and as an admin page; no two palettes
|
|
331
|
+
* are near copies; ids are unique within a kind; a look names parts that
|
|
332
|
+
* exist, and a released look only released ones. Run in the package's tests
|
|
333
|
+
* and by `styles --check` on a project's own look files.
|
|
334
|
+
*/
|
|
335
|
+
export function libraryProblems(lib = LIBRARY) {
|
|
336
|
+
const out = [];
|
|
337
|
+
for (const kind of ["palettes", "pairings", "layouts", "looks"]) {
|
|
338
|
+
const seen = new Set();
|
|
339
|
+
for (const item of lib[kind]) {
|
|
340
|
+
if (seen.has(item.id))
|
|
341
|
+
out.push(`two ${kind} are called ${item.id}`);
|
|
342
|
+
seen.add(item.id);
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
for (const p of lib.palettes) {
|
|
346
|
+
if (p.status === "withdrawn")
|
|
347
|
+
continue;
|
|
348
|
+
for (const scheme of ["light", "dark"]) {
|
|
349
|
+
for (const problem of themeProblems(themeFrom(p[scheme], scheme, { heading: SANS, body: SANS }, "soft")))
|
|
350
|
+
out.push(`palette ${p.id}, ${scheme}: ${problem}`);
|
|
351
|
+
}
|
|
352
|
+
const accent = untilContrast(p.light.accent, "#ffffff", "#000000", 4.5);
|
|
353
|
+
if (contrast(accent, "#ffffff") < 4.5)
|
|
354
|
+
out.push(`palette ${p.id}: its accent can't be made to read on an admin page`);
|
|
355
|
+
for (const q of lib.palettes) {
|
|
356
|
+
if (q.id >= p.id || q.status === "withdrawn")
|
|
357
|
+
continue;
|
|
358
|
+
const d = paletteDistance(p, q);
|
|
359
|
+
if (d < MIN_PALETTE_DISTANCE)
|
|
360
|
+
out.push(`palettes ${q.id} and ${p.id} are too alike (${d.toFixed(1)}, needs ${MIN_PALETTE_DISTANCE})`);
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
for (const l of lib.looks) {
|
|
364
|
+
for (const kind of ["palette", "pairing", "layout"]) {
|
|
365
|
+
const item = findItem(lib, kind, l[kind]);
|
|
366
|
+
if (!item)
|
|
367
|
+
out.push(`look ${l.id} names the ${kind} ${l[kind]}, which isn't in the library`);
|
|
368
|
+
else if (l.status === "released" && item.status !== "released")
|
|
369
|
+
out.push(`look ${l.id} is released but its ${kind} ${item.id} is ${item.status}`);
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
return out;
|
|
373
|
+
}
|
package/dist/ui-styles.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// The look of what workbench-ui's helpers draw: shell, topBar, card, pill,
|
|
2
2
|
// chip and jumpNav, and the page parts (body, note, message, small, button,
|
|
3
|
-
// actions, field, input, check, table, facts, more and code), so a page needs
|
|
3
|
+
// actions, confirm, field, input, check, table, facts, more and code), so a page needs
|
|
4
4
|
// no markup of its own to look finished (docs/capabilities-manifest.md §10). Every element they put
|
|
5
5
|
// on a page carries one of these classes with a default rule, and the colours
|
|
6
6
|
// and sizes are `--wb-ui-*` variables, so a project restyles a Workbench page
|
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
// a breaking change. The older page conventions for markup a page writes
|
|
9
9
|
// itself (.note, .body, bare tables and buttons) stay in CSS (style.ts) for
|
|
10
10
|
// Workbench's own pages; a project's generated workbench.css leaves them out.
|
|
11
|
+
import { confirmStyles } from "./confirm.js";
|
|
11
12
|
const v = (name) => `var(--wb-ui-${name})`;
|
|
12
13
|
const TONES = ["pass", "refused", "fail", "skip", "running"];
|
|
13
14
|
const RUN = (t) => (t === "running" ? "run" : t);
|
|
@@ -17,6 +18,8 @@ const SAYS = [
|
|
|
17
18
|
["warn", "warn"],
|
|
18
19
|
["fail", "fail"],
|
|
19
20
|
];
|
|
21
|
+
/** The variables the shared "Are you sure?" rules read, as workbench-ui's own. */
|
|
22
|
+
const CONFIRM_VARS = { radius: "corner", sunk: "background", danger: "bad", "on-danger": "accent-text" };
|
|
20
23
|
const FOCUS = `outline:none;box-shadow:0 0 0 3px ${v("focus")}`;
|
|
21
24
|
/** The style hooks of a Workbench page. */
|
|
22
25
|
export const UI_STYLES = {
|
|
@@ -55,6 +58,7 @@ export const UI_STYLES = {
|
|
|
55
58
|
{ name: "--wb-ui-mono", value: "var(--wb-font-mono, ui-monospace, monospace)", about: "Code's font" },
|
|
56
59
|
{ name: "--wb-ui-width", value: "max(64rem,80vw)", about: "Widest the page's column grows" },
|
|
57
60
|
{ name: "--wb-ui-input-width", value: "24rem", about: "Widest a one-line control grows" },
|
|
61
|
+
{ name: "--wb-ui-corner", value: "6px", about: "Corners of the \"Are you sure?\" box, its typed box and its button" },
|
|
58
62
|
],
|
|
59
63
|
classes: [
|
|
60
64
|
{ name: "wb-ui", element: "html", about: "The whole page, in the project's look (Workbench's own pages are always dark)", css: `background:${v("background")};color:${v("text")};font:15px/1.55 ${v("font")}` },
|
|
@@ -216,6 +220,7 @@ export const UI_STYLES = {
|
|
|
216
220
|
{ selector: "[data-kind=link]:hover", about: "A link button under the pointer", css: `background:none;color:${v("accent-hover")}` },
|
|
217
221
|
{ selector: ":disabled", about: "A button that can't be pressed yet", css: "opacity:.45;cursor:not-allowed" },
|
|
218
222
|
{ selector: ":focus-visible", about: "With the keyboard", css: FOCUS },
|
|
223
|
+
{ selector: ":where(summary)", about: "The button that opens \"Are you sure?\", from confirm()", css: "display:inline-flex;align-items:center;width:max-content;max-width:100%" },
|
|
219
224
|
],
|
|
220
225
|
},
|
|
221
226
|
{
|
|
@@ -223,7 +228,7 @@ export const UI_STYLES = {
|
|
|
223
228
|
element: "div",
|
|
224
229
|
about: "A row of buttons and the forms around them, from actions()",
|
|
225
230
|
css: "display:flex;flex-wrap:wrap;align-items:center;gap:.6rem;margin:1rem 0",
|
|
226
|
-
states: [{ selector: " form", about: "A form in the row sits inline", css: "display:inline;margin:0" }],
|
|
231
|
+
states: [{ selector: " form:not(.wb-ui-confirm-form)", about: "A form in the row sits inline (not the form inside \"Are you sure?\")", css: "display:inline;margin:0" }],
|
|
227
232
|
},
|
|
228
233
|
{ name: "wb-ui-option", element: "option", about: "One choice in a drop-down list", css: `background:${v("surface")};color:${v("text")}` },
|
|
229
234
|
{ name: "wb-ui-field", element: "p", about: "One labelled control, from field(): the label over the control, then any hint", css: "display:flex;flex-direction:column;align-items:flex-start;gap:.3rem;margin:0 0 1rem" },
|
|
@@ -293,5 +298,6 @@ export const UI_STYLES = {
|
|
|
293
298
|
about: "Exact text kept as it is, such as a reply or a log line, from code()",
|
|
294
299
|
css: `font:.85rem/1.5 ${v("mono")};white-space:pre-wrap;overflow-wrap:anywhere;padding:.75rem 1rem;margin:.75rem 0;background:${v("surface")};border:1px solid ${v("line")};border-radius:8px;max-height:28rem;overflow:auto`,
|
|
295
300
|
},
|
|
301
|
+
...confirmStyles("wb-ui", (n) => v(CONFIRM_VARS[n] ?? n), { reason: true }),
|
|
296
302
|
],
|
|
297
303
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mccaskie-labs/workbench-ui",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.10.0",
|
|
4
4
|
"description": "Workbench pages: one dark look, a top bar with the environment tag, cards, outcome pills, and one format for times, money and durations.",
|
|
5
5
|
"license": "UNLICENSED",
|
|
6
6
|
"type": "module",
|
|
@@ -39,7 +39,8 @@
|
|
|
39
39
|
"typecheck": "tsc -p tsconfig.json --noEmit && tsc -p test/tsconfig.json",
|
|
40
40
|
"test": "vitest run",
|
|
41
41
|
"build": "node scripts/build.mjs",
|
|
42
|
-
"prepack": "node scripts/build.mjs"
|
|
42
|
+
"prepack": "node scripts/build.mjs",
|
|
43
|
+
"library": "node scripts/library.mjs"
|
|
43
44
|
},
|
|
44
45
|
"devDependencies": {
|
|
45
46
|
"@types/node": "24.19.2",
|