@mccaskie-labs/workbench-ui 0.9.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 CHANGED
@@ -1,5 +1,11 @@
1
1
  # @mccaskie-labs/workbench-ui
2
2
 
3
+ ## 0.10.0
4
+
5
+ ### Minor Changes
6
+
7
+ - The look library as data (docs/look-studio.md step 1, Robert, 24 November 2026). The seven looks are now split into small checked files in `library/`: seven palettes, seven font pairings, three site layouts (`standard`, `centred`, `showcase`, from `SITE_LAYOUT_CHOICES`) and seven looks that each name one of each plus a corner shape. Every item has a state (`testing`, `released`, `withdrawn`), a `source` and a `since`; `LIBRARY` holds them, `LOOKS` is the released looks with their parts filled in (each now also carries `status`, `palette`, `pairing` and `layout`), and `LookId` is any look's id. Every project's generated theme is byte for byte what it was (tested). New: `resolveTheme`, `resolveAdminTheme`, `lookById`, `lookFor` and `themeInput` take an optional library; `ThemeInput` gains `palette`, `pairing` and `layout` (by id, over the look's own); `resolveSiteLayout` gives a project's site layout; `libraryProblems` checks a library's rules (every palette reads in light, dark and as an admin page; no two palettes nearer than `MIN_PALETTE_DISTANCE` by `paletteDistance`; a released look names only released parts) and `itemProblems` one file's shape, refusing any field it doesn't know. A project may add its own items in `workbench/looks/*.json`: `npx workbench-ui styles` reads them beside the package's, so brand.json can name them, and `--check` names a bad, clashing or unreadable one. A released library file never changes: `library/released.json` keeps each one's fingerprint and `npm run library` refuses to run when one has changed. (brand.json can carry `palette`, `pairing` and `layout` once workbench-config's schema allows them.)
8
+
3
9
  ## 0.9.0
4
10
 
5
11
  ### Minor Changes
package/README.md CHANGED
@@ -81,3 +81,16 @@ Pages are always dark, whatever the computer is set to. A page with its own rule
81
81
  `npx workbench-ui styles` writes the project's `public/styles/workbench.css` from every installed Workbench tool, and `npx workbench-ui styles --check` (in Checks) fails when it is stale, when `project.css` names a `wb-` class or variable no tool draws, or when the project's own pages (`src/`, `public/`) put such a class on an element. The older page conventions (`.body`, `.note`, `.warn`, bare buttons and tables) are only in `STYLE` and `CSS`, for Workbench's own pages: a project's workbench.css leaves them out, so they never reach a client's own markup.
82
82
 
83
83
  Runs on Node 24 and the Cloudflare Workers runtime. No dependencies.
84
+
85
+ ## The look library
86
+
87
+ A project's look comes from the library (`docs/look-studio.md` §4): palettes, font pairings, site layouts and looks as small checked JSON files in `library/<kind>s/<id>.json`, compiled into `src/library.generated.ts` by `npm run library`. Each has a state: `testing`, `released` (never changes again; a change is a new id, kept by `library/released.json`) or `withdrawn` (no longer offered, still works where named).
88
+
89
+ | Export | What it does |
90
+ | --- | --- |
91
+ | `LIBRARY`, `LOOKS` | Every packaged item by kind; the released looks with their palette, fonts and shape filled in |
92
+ | `resolveTheme(input, library?)`, `resolveAdminTheme`, `resolveSiteLayout` | The tokens, the admin tokens and the site layout from brand.json's `look`, `palette`, `pairing`, `layout`, `scheme`, `shape`, `colours` and `fonts` |
93
+ | `itemProblems(file)`, `libraryProblems(library)` | One file's shape (unknown fields refused); the library's rules: contrast in light, dark and admin, no near copies (`paletteDistance`, `MIN_PALETTE_DISTANCE`), looks naming released parts |
94
+ | `withProjectItems(items)` | The packaged library plus a project's own items |
95
+
96
+ A project adds its own items in `workbench/looks/*.json`, the same shape with `"since": "project"`. `npx workbench-ui styles` reads them, so brand.json can name them, and `--check` names any that is bad, clashes with a packaged id or doesn't read.
package/dist/cli.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/env node
2
+ import { type Library } from "./library.ts";
2
3
  import { type InstalledStyles } from "./styles.ts";
3
4
  /** The styles of each Workbench tool the project at `dir` has installed, and the workbench-ui version. */
4
5
  export declare function installedStyles(dir: string): Promise<{
@@ -11,6 +12,17 @@ export declare const MARKUP_DIRS: readonly string[];
11
12
  export declare function markupFiles(dir: string): string[];
12
13
  /** Where a project's brand file sits, from its root (workbench-config's BRAND_FILE). */
13
14
  export declare const BRAND_FILE = "brand.json";
15
+ /** Where a project keeps its own look library items (docs/look-studio.md §4), from its root. */
16
+ export declare const PROJECT_LOOKS_DIR = "workbench/looks";
17
+ /**
18
+ * The library a project sees: the package's, plus the project's own items in
19
+ * workbench/looks/*.json (from the look studio, or written by its Claude), and
20
+ * what is wrong with those files. A bad file is left out, never guessed at.
21
+ */
22
+ export declare function projectLibrary(dir: string): {
23
+ library: Library;
24
+ problems: string[];
25
+ };
14
26
  /**
15
27
  * The theme block for the project at `dir`, from its brand.json (Clean, light,
16
28
  * when it has none), and what is wrong with it: a field of the wrong kind, or
package/dist/cli.js CHANGED
@@ -23,7 +23,8 @@ import { createRequire } from "node:module";
23
23
  import { dirname, join, relative, resolve } from "node:path";
24
24
  import { fileURLToPath, pathToFileURL } from "node:url";
25
25
  import { UI_STYLES } from "./ui-styles.js";
26
- import { renderTheme, resolveAdminTheme, resolveTheme, themeInput, themeProblems } from "./theme.js";
26
+ import { libraryProblems, renderTheme, resolveAdminTheme, resolveTheme, themeInput, themeProblems } from "./theme.js";
27
+ import { findItem, itemProblems, LIBRARY, withProjectItems } from "./library.js";
27
28
  import { DEFAULT_THEME_CSS, renderStyles, STYLE_FILES, STYLED_SCOPE, starterProjectCss, unknownMarkupNames, unknownNames } from "./styles.js";
28
29
  const USAGE = "usage: workbench-ui styles [--check] [dir]";
29
30
  const read = (path) => readFileSync(path, "utf8").replace(/\r\n/g, "\n");
@@ -92,6 +93,49 @@ export function markupFiles(dir) {
92
93
  }
93
94
  /** Where a project's brand file sits, from its root (workbench-config's BRAND_FILE). */
94
95
  export const BRAND_FILE = "brand.json";
96
+ /** Where a project keeps its own look library items (docs/look-studio.md §4), from its root. */
97
+ export const PROJECT_LOOKS_DIR = "workbench/looks";
98
+ /**
99
+ * The library a project sees: the package's, plus the project's own items in
100
+ * workbench/looks/*.json (from the look studio, or written by its Claude), and
101
+ * what is wrong with those files. A bad file is left out, never guessed at.
102
+ */
103
+ export function projectLibrary(dir) {
104
+ const at = join(dir, PROJECT_LOOKS_DIR);
105
+ if (!existsSync(at))
106
+ return { library: LIBRARY, problems: [] };
107
+ const items = [];
108
+ const problems = [];
109
+ for (const name of readdirSync(at).filter((n) => n.endsWith(".json")).sort()) {
110
+ const file = `${PROJECT_LOOKS_DIR}/${name}`;
111
+ let raw;
112
+ try {
113
+ raw = JSON.parse(read(join(at, name)));
114
+ }
115
+ catch {
116
+ problems.push(`${file} isn't valid JSON`);
117
+ continue;
118
+ }
119
+ const bad = itemProblems(raw);
120
+ if (bad.length) {
121
+ problems.push(...bad.map((b) => `${file}: ${b}`));
122
+ continue;
123
+ }
124
+ const item = raw;
125
+ if (findItem(LIBRARY, item.kind, item.id))
126
+ problems.push(`${file}: workbench-ui already has a ${item.kind} called ${item.id}: give yours its own id`);
127
+ else if (items.some((i) => i.kind === item.kind && i.id === item.id))
128
+ problems.push(`${file}: two of the project's files make a ${item.kind} called ${item.id}`);
129
+ else
130
+ items.push(item);
131
+ }
132
+ if (!items.length)
133
+ return { library: LIBRARY, problems };
134
+ const library = withProjectItems(items);
135
+ // The package's own items always keep the rules (tested), so anything left is the project's.
136
+ problems.push(...libraryProblems(library).map((p) => `${PROJECT_LOOKS_DIR}: ${p}`));
137
+ return { library, problems };
138
+ }
95
139
  /**
96
140
  * The theme block for the project at `dir`, from its brand.json (Clean, light,
97
141
  * when it has none), and what is wrong with it: a field of the wrong kind, or
@@ -100,7 +144,7 @@ export const BRAND_FILE = "brand.json";
100
144
  export function projectTheme(dir) {
101
145
  const at = join(dir, BRAND_FILE);
102
146
  if (!existsSync(at))
103
- return { css: DEFAULT_THEME_CSS, problems: [] };
147
+ return { css: DEFAULT_THEME_CSS, problems: projectLibrary(dir).problems };
104
148
  let brand;
105
149
  try {
106
150
  brand = JSON.parse(read(at));
@@ -108,11 +152,13 @@ export function projectTheme(dir) {
108
152
  catch {
109
153
  return { css: DEFAULT_THEME_CSS, problems: [`${BRAND_FILE} isn't valid JSON`] };
110
154
  }
111
- const { input, problems } = themeInput(brand);
112
- const site = resolveTheme(input);
113
- const look = `${input.look ?? "clean"}, ${input.scheme ?? "light"}${input.colours?.primary || input.fonts || input.shape ? ", with brand.json's own choices" : ""}`;
155
+ const own = projectLibrary(dir);
156
+ const { input, problems } = themeInput(brand, own.library);
157
+ problems.unshift(...own.problems);
158
+ const site = resolveTheme(input, own.library);
159
+ const look = `${input.look ?? "clean"}, ${input.scheme ?? "light"}${input.colours?.primary || input.fonts || input.shape || input.palette || input.pairing ? ", with brand.json's own choices" : ""}`;
114
160
  problems.push(...themeProblems(site).map((p) => `${BRAND_FILE}: ${p}`));
115
- return { css: renderTheme(site, resolveAdminTheme(input), `${look} (from ${BRAND_FILE})`), problems };
161
+ return { css: renderTheme(site, resolveAdminTheme(input, own.library), `${look} (from ${BRAND_FILE})`), problems };
116
162
  }
117
163
  /** What `styles` writes in `dir`, and what --check would fail on, without touching the disk. */
118
164
  export function planStyles(dir, tools, uiVersion) {
package/dist/index.d.ts CHANGED
@@ -4,7 +4,8 @@ export { BASE_CSS, CSS, STYLE, UI_CSS } from "./style.ts";
4
4
  export { UI_STYLES } from "./ui-styles.ts";
5
5
  export { FORM_SCRIPT } from "./form-script.ts";
6
6
  export { DEFAULT_THEME_CSS, renderStyles, STYLE_FILES, STYLED_SCOPE, styleNames, styleProblems, STYLESHEETS, starterProjectCss, unknownMarkupNames, unknownNames, type InstalledStyles, type StyleClass, type StyleState, type StyleVariable, type ToolStyles, } from "./styles.ts";
7
- export { contrast, DEFAULT_LOOK, LOOKS, lookById, lookFor, mix, renderTheme, resolveAdminTheme, resolveTheme, THEME_TOKENS, themeInput, themeProblems, type Look, type LookId, type Palette, type Scheme, type Shape, type Theme, type ThemeInput, type ThemeToken, type TokenName, } from "./theme.ts";
7
+ export { contrast, DEFAULT_LOOK, LOOKS, libraryProblems, lookById, lookFor, lookOf, looksIn, MIN_PALETTE_DISTANCE, mix, paletteDistance, renderTheme, resolveAdminTheme, resolveSiteLayout, resolveTheme, THEME_TOKENS, themeInput, themeProblems, type Look, type LookId, type Palette, type Scheme, type Shape, type Theme, type ThemeInput, type ThemeToken, type TokenName, } from "./theme.ts";
8
+ export { findItem, itemProblems, LIBRARY, LIBRARY_KINDS, libraryOf, SITE_LAYOUT_CHOICES, usable, withProjectItems, type FontFallback, type ItemStatus, type LayoutItem, type Library, type LibraryItem, type LibraryKind, type LookItem, type PairingFont, type PairingItem, type PaletteItem, type SiteLayoutChoice, } from "./library.ts";
8
9
  /** Plain text made safe to put in HTML, in text or in a quoted attribute. */
9
10
  export declare const escape: (value: string) => string;
10
11
  /** The outcome colours: a pill's class and, prefixed with o-, a table row's left edge. */
package/dist/index.js CHANGED
@@ -9,7 +9,8 @@ export { BASE_CSS, CSS, STYLE, UI_CSS } from "./style.js";
9
9
  export { UI_STYLES } from "./ui-styles.js";
10
10
  export { FORM_SCRIPT } from "./form-script.js";
11
11
  export { DEFAULT_THEME_CSS, renderStyles, STYLE_FILES, STYLED_SCOPE, styleNames, styleProblems, STYLESHEETS, starterProjectCss, unknownMarkupNames, unknownNames, } from "./styles.js";
12
- export { contrast, DEFAULT_LOOK, LOOKS, lookById, lookFor, mix, renderTheme, resolveAdminTheme, resolveTheme, THEME_TOKENS, themeInput, themeProblems, } from "./theme.js";
12
+ export { contrast, DEFAULT_LOOK, LOOKS, libraryProblems, lookById, lookFor, lookOf, looksIn, MIN_PALETTE_DISTANCE, mix, paletteDistance, renderTheme, resolveAdminTheme, resolveSiteLayout, resolveTheme, THEME_TOKENS, themeInput, themeProblems, } from "./theme.js";
13
+ export { findItem, itemProblems, LIBRARY, LIBRARY_KINDS, libraryOf, SITE_LAYOUT_CHOICES, usable, withProjectItems, } from "./library.js";
13
14
  /** Plain text made safe to put in HTML, in text or in a quoted attribute. */
14
15
  export const escape = (value) => value.replace(/[&<>"']/g, (c) => `&#${c.charCodeAt(0)};`);
15
16
  /** A coloured outcome pill. `text` is plain text. */
@@ -0,0 +1,100 @@
1
+ export type Scheme = "light" | "dark";
2
+ /** How round the corners are. */
3
+ export type Shape = "square" | "soft" | "round";
4
+ export type ItemStatus = "testing" | "released" | "withdrawn";
5
+ /** The colours a palette sets for one scheme. */
6
+ export interface Palette {
7
+ background: string;
8
+ text: string;
9
+ muted: string;
10
+ accent: string;
11
+ danger: string;
12
+ success: string;
13
+ warning: string;
14
+ }
15
+ interface ItemBase {
16
+ id: string;
17
+ title: string;
18
+ status: ItemStatus;
19
+ /** Who or what made it, and when. */
20
+ source: string;
21
+ /** The workbench-ui version it arrived in, or "project" for a project's own file. */
22
+ since: string;
23
+ }
24
+ export interface PaletteItem extends ItemBase {
25
+ kind: "palette";
26
+ /** A colour group, such as "green", for finding near neighbours. */
27
+ group: string;
28
+ /** One line an owner reads. */
29
+ about: string;
30
+ light: Palette;
31
+ dark: Palette;
32
+ }
33
+ export type FontFallback = "sans" | "serif";
34
+ export interface PairingFont {
35
+ family: string;
36
+ fallback: FontFallback;
37
+ }
38
+ export interface PairingItem extends ItemBase {
39
+ kind: "pairing";
40
+ about: string;
41
+ heading: PairingFont;
42
+ body: PairingFont;
43
+ }
44
+ /** The choices a site layout makes (docs/look-studio.md §6), each list's first is the default. */
45
+ export declare const SITE_LAYOUT_CHOICES: {
46
+ readonly header: readonly ["menu-right", "centred", "menu-centre"];
47
+ readonly footer: readonly ["line", "columns", "centred"];
48
+ readonly width: readonly ["standard", "narrow", "wide"];
49
+ readonly spacing: readonly ["standard", "compact", "airy"];
50
+ readonly hero: readonly ["plain", "over-picture", "beside-picture"];
51
+ };
52
+ export type SiteLayoutChoice = keyof typeof SITE_LAYOUT_CHOICES;
53
+ export interface LayoutItem extends ItemBase {
54
+ kind: "layout";
55
+ /** One line an owner reads: what kind of site it suits. */
56
+ bestFor: string;
57
+ header: (typeof SITE_LAYOUT_CHOICES.header)[number];
58
+ footer: (typeof SITE_LAYOUT_CHOICES.footer)[number];
59
+ width: (typeof SITE_LAYOUT_CHOICES.width)[number];
60
+ spacing: (typeof SITE_LAYOUT_CHOICES.spacing)[number];
61
+ hero: (typeof SITE_LAYOUT_CHOICES.hero)[number];
62
+ }
63
+ export interface LookItem extends ItemBase {
64
+ kind: "look";
65
+ feel: string;
66
+ /** The New project gallery's starter groups this look is suggested for. */
67
+ suggestedFor: string[];
68
+ palette: string;
69
+ pairing: string;
70
+ layout: string;
71
+ shape: Shape;
72
+ }
73
+ export type LibraryItem = PaletteItem | PairingItem | LayoutItem | LookItem;
74
+ export type LibraryKind = LibraryItem["kind"];
75
+ export declare const LIBRARY_KINDS: readonly LibraryKind[];
76
+ /** A library: every item by kind. */
77
+ export interface Library {
78
+ palettes: readonly PaletteItem[];
79
+ pairings: readonly PairingItem[];
80
+ layouts: readonly LayoutItem[];
81
+ looks: readonly LookItem[];
82
+ }
83
+ /** Sorts items into a library, by kind then in the order given. */
84
+ export declare function libraryOf(items: readonly LibraryItem[]): Library;
85
+ /** The library that ships in this version of workbench-ui. */
86
+ export declare const LIBRARY: Library;
87
+ /** The package's library with a project's own items added after it. */
88
+ export declare function withProjectItems(items: readonly LibraryItem[], base?: Library): Library;
89
+ export declare function findItem<K extends LibraryKind>(lib: Library, kind: K, id: string): Extract<LibraryItem, {
90
+ kind: K;
91
+ }> | undefined;
92
+ /** Items a project or the New project form may choose: not withdrawn. Released ones first. */
93
+ export declare function usable<T extends LibraryItem>(items: readonly T[]): T[];
94
+ /**
95
+ * What is wrong with one library file's contents, in plain words (empty when
96
+ * it is a good item). Checks shape only; whether its colours read and whether
97
+ * it names real parts are `libraryProblems`'.
98
+ */
99
+ export declare function itemProblems(raw: unknown): string[];
100
+ export {};