@mccaskie-labs/workbench-ui 0.6.0 → 0.7.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 -1
- package/dist/cli.d.ts +11 -0
- package/dist/cli.js +35 -4
- package/dist/index.d.ts +7 -1
- package/dist/index.js +3 -2
- package/dist/styles.d.ts +7 -4
- package/dist/styles.js +23 -7
- package/dist/theme.d.ts +105 -0
- package/dist/theme.js +334 -0
- package/dist/ui-styles.js +1 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# @mccaskie-labs/workbench-ui
|
|
2
2
|
|
|
3
|
+
## 0.7.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- Shared theme tokens and looks (docs/theming.md, Robert, 24 November 2026). `THEME_TOKENS` lists 21 `--wb-*` tokens every tool's variables will default to; `LOOKS` holds seven looks (Clean, Warm, Calm, Sturdy, Bold, Bright, Friendly), each light and dark, with `lookFor(group)` for a starter group; `resolveTheme` works a theme out from brand.json's fields (`look`, `scheme`, `shape`, `colours`, `fonts`; Clean, light, by default) to plain colours, `resolveAdminTheme` gives admin pages the project's accent and fonts on Clean's light neutrals, and `themeProblems` names any pair that fails WCAG AA. `npx workbench-ui styles` writes the tokens first in workbench.css, in a new `@layer workbench.theme` (public look on `:root`, admin look on `:root.wb-ui-admin`), from the project's brand.json; `--check` fails when its colours don't read. project.css may set the tokens, and the starter project.css lists them. `shell({ admin: true })` marks a project's admin page with `wb-ui-admin`. No tool reads the tokens yet, so nothing changes on a page until the tools move onto them.
|
|
8
|
+
|
|
9
|
+
## 0.6.1
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- 33d9dde: The general building blocks stand on their own. workbench-config's component list no longer has availability, onboarding or outreach: a tool like those now comes as an add-on (docs/addons.md), and `workbench/addons.json` may say where each add-on comes from (`"from": { "<name>": "<organisation>/<repo>" }`), so Control's daily update copies it into `addons/<name>/`. workbench-nudges' starter has one rule, quotes with no reply, and its time zone starts as Australia/Sydney (set it from the country pack); `outreachRefresh` and `OutreachLike` are gone, so a project that follows up its own first messages writes its own rule, guide and refresh, as the nudges.what question's "First messages with no reply" answer says. Examples and samples use neutral names.
|
|
14
|
+
|
|
3
15
|
## 0.6.0
|
|
4
16
|
|
|
5
17
|
### Minor Changes
|
|
@@ -10,7 +22,7 @@
|
|
|
10
22
|
|
|
11
23
|
### Patch Changes
|
|
12
24
|
|
|
13
|
-
- `npx workbench-ui styles` takes every `ToolStyles` a package exports at `./styles`, one per tool, each with its own prefix (was exactly one), so
|
|
25
|
+
- `npx workbench-ui styles` takes every `ToolStyles` a package exports at `./styles`, one per tool, each with its own prefix (was exactly one), so a package that draws several tools gets each one into workbench.css.
|
|
14
26
|
|
|
15
27
|
## 0.5.0
|
|
16
28
|
|
package/dist/cli.d.ts
CHANGED
|
@@ -9,6 +9,17 @@ export declare function installedStyles(dir: string): Promise<{
|
|
|
9
9
|
export declare const MARKUP_DIRS: readonly string[];
|
|
10
10
|
/** The project's own source files that can hold markup: code and HTML under src/ and public/, not tests, builds or stylesheets. */
|
|
11
11
|
export declare function markupFiles(dir: string): string[];
|
|
12
|
+
/** Where a project's brand file sits, from its root (workbench-config's BRAND_FILE). */
|
|
13
|
+
export declare const BRAND_FILE = "brand.json";
|
|
14
|
+
/**
|
|
15
|
+
* The theme block for the project at `dir`, from its brand.json (Clean, light,
|
|
16
|
+
* when it has none), and what is wrong with it: a field of the wrong kind, or
|
|
17
|
+
* colours that don't read.
|
|
18
|
+
*/
|
|
19
|
+
export declare function projectTheme(dir: string): {
|
|
20
|
+
css: string;
|
|
21
|
+
problems: string[];
|
|
22
|
+
};
|
|
12
23
|
export interface StylesPlan {
|
|
13
24
|
/** Files to write, by path relative to the project. */
|
|
14
25
|
files: Record<string, string>;
|
package/dist/cli.js
CHANGED
|
@@ -6,7 +6,10 @@
|
|
|
6
6
|
// --check it writes nothing and fails when workbench.css differs from what the
|
|
7
7
|
// installed packages draw, when project.css names a wb- class or variable
|
|
8
8
|
// that no installed tool draws any more (a rename after an update), or when the
|
|
9
|
-
// project's own pages (src/ and public/) put such a class on an element.
|
|
9
|
+
// project's own pages (src/ and public/) put such a class on an element. The
|
|
10
|
+
// shared theme tokens at the top of workbench.css come from the project's
|
|
11
|
+
// brand.json (Clean, light, without one); --check also fails when its colours
|
|
12
|
+
// don't read.
|
|
10
13
|
var __rewriteRelativeImportExtension = (this && this.__rewriteRelativeImportExtension) || function (path, preserveJsx) {
|
|
11
14
|
if (typeof path === "string" && /^\.\.?\//.test(path)) {
|
|
12
15
|
return path.replace(/\.(tsx)$|((?:\.d)?)((?:\.[^./]+?)?)\.([cm]?)ts$/i, function (m, tsx, d, ext, cm) {
|
|
@@ -20,7 +23,8 @@ import { createRequire } from "node:module";
|
|
|
20
23
|
import { dirname, join, relative, resolve } from "node:path";
|
|
21
24
|
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
22
25
|
import { UI_STYLES } from "./ui-styles.js";
|
|
23
|
-
import {
|
|
26
|
+
import { renderTheme, resolveAdminTheme, resolveTheme, themeInput, themeProblems } from "./theme.js";
|
|
27
|
+
import { DEFAULT_THEME_CSS, renderStyles, STYLE_FILES, STYLED_SCOPE, starterProjectCss, unknownMarkupNames, unknownNames } from "./styles.js";
|
|
24
28
|
const USAGE = "usage: workbench-ui styles [--check] [dir]";
|
|
25
29
|
const read = (path) => readFileSync(path, "utf8").replace(/\r\n/g, "\n");
|
|
26
30
|
/** The styles of each Workbench tool the project at `dir` has installed, and the workbench-ui version. */
|
|
@@ -48,7 +52,7 @@ export async function installedStyles(dir) {
|
|
|
48
52
|
continue;
|
|
49
53
|
const mod = (await import(__rewriteRelativeImportExtension(pathToFileURL(req.resolve(`${name}/styles`)).href)));
|
|
50
54
|
const found = Object.values(mod).filter((x) => !!x && typeof x === "object" && x.format === 1 && typeof x.prefix === "string");
|
|
51
|
-
// One ToolStyles per tool the package draws (
|
|
55
|
+
// One ToolStyles per tool the package draws (a package may draw several, such as a calendar and a wizard), each with its own prefix.
|
|
52
56
|
if (found.length === 0)
|
|
53
57
|
throw new Error(`${name}/styles must export at least one ToolStyles`);
|
|
54
58
|
if (new Set(found.map((f) => f.prefix)).size !== found.length)
|
|
@@ -86,11 +90,37 @@ export function markupFiles(dir) {
|
|
|
86
90
|
walk(join(dir, d));
|
|
87
91
|
return out.sort();
|
|
88
92
|
}
|
|
93
|
+
/** Where a project's brand file sits, from its root (workbench-config's BRAND_FILE). */
|
|
94
|
+
export const BRAND_FILE = "brand.json";
|
|
95
|
+
/**
|
|
96
|
+
* The theme block for the project at `dir`, from its brand.json (Clean, light,
|
|
97
|
+
* when it has none), and what is wrong with it: a field of the wrong kind, or
|
|
98
|
+
* colours that don't read.
|
|
99
|
+
*/
|
|
100
|
+
export function projectTheme(dir) {
|
|
101
|
+
const at = join(dir, BRAND_FILE);
|
|
102
|
+
if (!existsSync(at))
|
|
103
|
+
return { css: DEFAULT_THEME_CSS, problems: [] };
|
|
104
|
+
let brand;
|
|
105
|
+
try {
|
|
106
|
+
brand = JSON.parse(read(at));
|
|
107
|
+
}
|
|
108
|
+
catch {
|
|
109
|
+
return { css: DEFAULT_THEME_CSS, problems: [`${BRAND_FILE} isn't valid JSON`] };
|
|
110
|
+
}
|
|
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" : ""}`;
|
|
114
|
+
problems.push(...themeProblems(site).map((p) => `${BRAND_FILE}: ${p}`));
|
|
115
|
+
return { css: renderTheme(site, resolveAdminTheme(input), `${look} (from ${BRAND_FILE})`), problems };
|
|
116
|
+
}
|
|
89
117
|
/** What `styles` writes in `dir`, and what --check would fail on, without touching the disk. */
|
|
90
118
|
export function planStyles(dir, tools, uiVersion) {
|
|
91
119
|
const files = {};
|
|
92
120
|
const problems = [];
|
|
93
|
-
const
|
|
121
|
+
const theme = projectTheme(dir);
|
|
122
|
+
problems.push(...theme.problems);
|
|
123
|
+
const generated = renderStyles(tools, uiVersion, theme.css);
|
|
94
124
|
const genPath = join(dir, STYLE_FILES.generated);
|
|
95
125
|
if (!existsSync(genPath) || read(genPath) !== generated) {
|
|
96
126
|
files[STYLE_FILES.generated] = generated;
|
|
@@ -145,6 +175,7 @@ async function main(argv) {
|
|
|
145
175
|
console.log(`wrote ${path}`);
|
|
146
176
|
}
|
|
147
177
|
// Writing fixes workbench.css; project.css and the project's own pages are fixed by hand.
|
|
178
|
+
// brand.json's problems are fixed by hand too.
|
|
148
179
|
const left = plan.problems.filter((p) => !p.startsWith(STYLE_FILES.generated) && !(p.startsWith(STYLE_FILES.project) && plan.files[STYLE_FILES.project]));
|
|
149
180
|
for (const p of left)
|
|
150
181
|
console.error(p);
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
export { BASE_CSS, CSS, STYLE, UI_CSS } from "./style.ts";
|
|
2
2
|
export { UI_STYLES } from "./ui-styles.ts";
|
|
3
3
|
export { FORM_SCRIPT } from "./form-script.ts";
|
|
4
|
-
export { renderStyles, STYLE_FILES, STYLED_SCOPE, styleNames, styleProblems, STYLESHEETS, starterProjectCss, unknownMarkupNames, unknownNames, type InstalledStyles, type StyleClass, type StyleState, type StyleVariable, type ToolStyles, } from "./styles.ts";
|
|
4
|
+
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";
|
|
5
|
+
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";
|
|
5
6
|
/** Plain text made safe to put in HTML, in text or in a quoted attribute. */
|
|
6
7
|
export declare const escape: (value: string) => string;
|
|
7
8
|
/** The outcome colours: a pill's class and, prefixed with o-, a table row's left edge. */
|
|
@@ -173,6 +174,11 @@ export interface ShellOptions {
|
|
|
173
174
|
stylesheets?: readonly string[];
|
|
174
175
|
/** HTML after the page, such as a <script> with the response's nonce. */
|
|
175
176
|
tail?: string;
|
|
177
|
+
/**
|
|
178
|
+
* A project's own admin page: the page carries wb-ui-admin, so the theme
|
|
179
|
+
* tokens give it the project's accent and fonts on light neutrals.
|
|
180
|
+
*/
|
|
181
|
+
admin?: boolean;
|
|
176
182
|
}
|
|
177
183
|
/** A whole page: the shared look, the top bar, the heading, then `body`. */
|
|
178
184
|
export declare function shell(opts: ShellOptions): string;
|
package/dist/index.js
CHANGED
|
@@ -6,7 +6,8 @@ import { STYLE } from "./style.js";
|
|
|
6
6
|
export { BASE_CSS, CSS, STYLE, UI_CSS } from "./style.js";
|
|
7
7
|
export { UI_STYLES } from "./ui-styles.js";
|
|
8
8
|
export { FORM_SCRIPT } from "./form-script.js";
|
|
9
|
-
export { renderStyles, STYLE_FILES, STYLED_SCOPE, styleNames, styleProblems, STYLESHEETS, starterProjectCss, unknownMarkupNames, unknownNames, } from "./styles.js";
|
|
9
|
+
export { DEFAULT_THEME_CSS, renderStyles, STYLE_FILES, STYLED_SCOPE, styleNames, styleProblems, STYLESHEETS, starterProjectCss, unknownMarkupNames, unknownNames, } from "./styles.js";
|
|
10
|
+
export { contrast, DEFAULT_LOOK, LOOKS, lookById, lookFor, mix, renderTheme, resolveAdminTheme, resolveTheme, THEME_TOKENS, themeInput, themeProblems, } from "./theme.js";
|
|
10
11
|
/** Plain text made safe to put in HTML, in text or in a quoted attribute. */
|
|
11
12
|
export const escape = (value) => value.replace(/[&<>"']/g, (c) => `&#${c.charCodeAt(0)};`);
|
|
12
13
|
/** A coloured outcome pill. `text` is plain text. */
|
|
@@ -240,7 +241,7 @@ export function topBar(opts) {
|
|
|
240
241
|
}
|
|
241
242
|
/** A whole page: the shared look, the top bar, the heading, then `body`. */
|
|
242
243
|
export function shell(opts) {
|
|
243
|
-
return `<!doctype html><html lang="en-AU" class="wb-ui"><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><meta name="color-scheme" content="dark">
|
|
244
|
+
return `<!doctype html><html lang="en-AU" class="wb-ui${opts.admin ? " wb-ui-admin" : ""}"><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><meta name="color-scheme" content="${opts.admin ? "light" : "dark"}">
|
|
244
245
|
<title>${escape(opts.title)} · ${escape(opts.site)}</title>${opts.stylesheets ? opts.stylesheets.map((href) => `<link rel="stylesheet" href="${escape(href)}">`).join("") : STYLE}${opts.head ?? ""}
|
|
245
246
|
${opts.top}
|
|
246
247
|
<main class="wb-ui-main"><h1 class="wb-ui-title">${escape(opts.title)}</h1>${opts.body}</main>${opts.tail ?? ""}</html>`;
|
package/dist/styles.d.ts
CHANGED
|
@@ -48,12 +48,15 @@ export declare const STYLESHEETS: readonly string[];
|
|
|
48
48
|
export declare const STYLED_SCOPE = "@mccaskie-labs/workbench-";
|
|
49
49
|
/** What is wrong with a tool's styles: a name off its prefix, a class with no default rule, a variable used but not listed. */
|
|
50
50
|
export declare function styleProblems(s: ToolStyles): string[];
|
|
51
|
+
/** The theme block when a project has no brand.json: Clean, light. */
|
|
52
|
+
export declare const DEFAULT_THEME_CSS: string;
|
|
51
53
|
/**
|
|
52
|
-
* The project's generated stylesheet:
|
|
53
|
-
* `@layer workbench.
|
|
54
|
-
*
|
|
54
|
+
* The project's generated stylesheet: the shared theme tokens in
|
|
55
|
+
* `@layer workbench.theme` (renderTheme, from brand.json), workbench-ui's page
|
|
56
|
+
* basics (BASE_CSS) in `@layer workbench.page`, then each tool's classes in
|
|
57
|
+
* `@layer workbench.tools`, which wins over both.
|
|
55
58
|
*/
|
|
56
|
-
export declare function renderStyles(tools: readonly InstalledStyles[], uiVersion: string): string;
|
|
59
|
+
export declare function renderStyles(tools: readonly InstalledStyles[], uiVersion: string, themeCss?: string): string;
|
|
57
60
|
/** The starting project.css: empty rules the project fills, with every variable listed in a comment. */
|
|
58
61
|
export declare function starterProjectCss(tools: readonly InstalledStyles[]): string;
|
|
59
62
|
/** Every wb- class and variable the tools draw with: what a project's own CSS may name. */
|
package/dist/styles.js
CHANGED
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
// project's own public/styles/project.css wins without !important. This file
|
|
8
8
|
// renders that stylesheet and lists the names a project may use.
|
|
9
9
|
import { BASE_CSS } from "./style.js";
|
|
10
|
+
import { renderTheme, resolveAdminTheme, resolveTheme, THEME_TOKENS } from "./theme.js";
|
|
10
11
|
/** Where the generated stylesheet and the project's own sit, from the project's root. */
|
|
11
12
|
export const STYLE_FILES = { generated: "public/styles/workbench.css", project: "public/styles/project.css" };
|
|
12
13
|
/** The addresses a page links, in order: Workbench's defaults, then the project's own rules. */
|
|
@@ -92,19 +93,24 @@ const HEADER = [
|
|
|
92
93
|
" * variable, in project.css. It loads after this file and isn't in a layer, so its rules always win.",
|
|
93
94
|
" */",
|
|
94
95
|
];
|
|
96
|
+
/** The theme block when a project has no brand.json: Clean, light. */
|
|
97
|
+
export const DEFAULT_THEME_CSS = renderTheme(resolveTheme(), resolveAdminTheme(), "Clean, light (the project has no brand.json yet)");
|
|
95
98
|
/**
|
|
96
|
-
* The project's generated stylesheet:
|
|
97
|
-
* `@layer workbench.
|
|
98
|
-
*
|
|
99
|
+
* The project's generated stylesheet: the shared theme tokens in
|
|
100
|
+
* `@layer workbench.theme` (renderTheme, from brand.json), workbench-ui's page
|
|
101
|
+
* basics (BASE_CSS) in `@layer workbench.page`, then each tool's classes in
|
|
102
|
+
* `@layer workbench.tools`, which wins over both.
|
|
99
103
|
*/
|
|
100
|
-
export function renderStyles(tools, uiVersion) {
|
|
104
|
+
export function renderStyles(tools, uiVersion, themeCss = DEFAULT_THEME_CSS) {
|
|
101
105
|
const problems = tools.flatMap((t) => styleProblems(t.styles));
|
|
102
106
|
if (problems.length)
|
|
103
107
|
throw new Error(`workbench-ui styles: ${problems.join("; ")}`);
|
|
104
108
|
const page = BASE_CSS.trim().replace(/^/gm, " ");
|
|
105
109
|
return [
|
|
106
110
|
...HEADER,
|
|
107
|
-
"@layer workbench.page, workbench.tools;",
|
|
111
|
+
"@layer workbench.theme, workbench.page, workbench.tools;",
|
|
112
|
+
"",
|
|
113
|
+
themeCss,
|
|
108
114
|
"",
|
|
109
115
|
comment(`Page basics: @mccaskie-labs/workbench-ui ${uiVersion}, only on a page built with shell (html.wb-ui), and of no weight. Everything its helpers draw (cards, notes, buttons, fields, tables) is wb-ui- below.`),
|
|
110
116
|
"@layer workbench.page {",
|
|
@@ -124,7 +130,16 @@ export function starterProjectCss(tools) {
|
|
|
124
130
|
"/*",
|
|
125
131
|
" * This project's own look for what Workbench tools draw. Yours to edit; `npx workbench-ui styles` never",
|
|
126
132
|
" * overwrites it. It loads after workbench.css, which lists every wb- class and variable with its default.",
|
|
127
|
-
" * Rules here always win.
|
|
133
|
+
" * Rules here always win.",
|
|
134
|
+
" *",
|
|
135
|
+
" * To change the whole look (every tool, email and PDF), edit brand.json and run `npx workbench-ui styles`.",
|
|
136
|
+
" * To match this project's own design, map the shared tokens to it here, for example:",
|
|
137
|
+
" *",
|
|
138
|
+
" * :root {",
|
|
139
|
+
...THEME_TOKENS.map((t) => ` * ${t.name}: ...; ${t.about}`),
|
|
140
|
+
" * }",
|
|
141
|
+
" *",
|
|
142
|
+
" * To set one tool apart, restyle by class (.wb-form-submit { ... }) or set its own variable:",
|
|
128
143
|
" *",
|
|
129
144
|
" * :root {",
|
|
130
145
|
...vars,
|
|
@@ -145,6 +160,7 @@ export function styleNames(tools) {
|
|
|
145
160
|
}
|
|
146
161
|
return { classes, variables };
|
|
147
162
|
}
|
|
163
|
+
const TOKEN_NAMES = new Set(THEME_TOKENS.map((t) => t.name));
|
|
148
164
|
/** The wb- classes and variables a project's stylesheet names that no installed tool draws (comments ignored). */
|
|
149
165
|
export function unknownNames(projectCss, tools) {
|
|
150
166
|
const known = styleNames(tools);
|
|
@@ -154,7 +170,7 @@ export function unknownNames(projectCss, tools) {
|
|
|
154
170
|
if (!known.classes.has(m[1]))
|
|
155
171
|
out.add(`.${m[1]}`);
|
|
156
172
|
for (const m of css.matchAll(/(--wb-[a-z0-9-]+)/g))
|
|
157
|
-
if (!known.variables.has(m[1]))
|
|
173
|
+
if (!known.variables.has(m[1]) && !TOKEN_NAMES.has(m[1]))
|
|
158
174
|
out.add(m[1]);
|
|
159
175
|
return [...out];
|
|
160
176
|
}
|
package/dist/theme.d.ts
ADDED
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
/** Light or dark. */
|
|
2
|
+
export type Scheme = "light" | "dark";
|
|
3
|
+
/** How round the corners are. */
|
|
4
|
+
export type Shape = "square" | "soft" | "round";
|
|
5
|
+
/** One shared token: its name and what it sets. */
|
|
6
|
+
export interface ThemeToken {
|
|
7
|
+
name: `--wb-${string}`;
|
|
8
|
+
about: string;
|
|
9
|
+
/** "set" by the look or brand.json, "worked out" from those, or "fixed". */
|
|
10
|
+
from: "set" | "worked out" | "fixed";
|
|
11
|
+
}
|
|
12
|
+
/** The shared tokens every tool's variables default to, in the order workbench.css lists them. */
|
|
13
|
+
export declare const THEME_TOKENS: readonly ThemeToken[];
|
|
14
|
+
/** Every token's name. */
|
|
15
|
+
export type TokenName = (typeof THEME_TOKENS)[number]["name"];
|
|
16
|
+
/** A worked-out theme: a value for every token, and whether it is light or dark. */
|
|
17
|
+
export interface Theme {
|
|
18
|
+
scheme: Scheme;
|
|
19
|
+
tokens: Record<string, string>;
|
|
20
|
+
}
|
|
21
|
+
/** The colours a look sets for one scheme. */
|
|
22
|
+
export interface Palette {
|
|
23
|
+
background: string;
|
|
24
|
+
text: string;
|
|
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. */
|
|
32
|
+
export interface Look {
|
|
33
|
+
id: LookId;
|
|
34
|
+
title: string;
|
|
35
|
+
feel: string;
|
|
36
|
+
/** The New project gallery's starter groups this look is suggested for. */
|
|
37
|
+
suggestedFor: readonly string[];
|
|
38
|
+
light: Palette;
|
|
39
|
+
dark: Palette;
|
|
40
|
+
fonts: {
|
|
41
|
+
heading: string;
|
|
42
|
+
body: string;
|
|
43
|
+
};
|
|
44
|
+
shape: Shape;
|
|
45
|
+
}
|
|
46
|
+
export type LookId = "clean" | "warm" | "calm" | "sturdy" | "bold" | "bright" | "friendly";
|
|
47
|
+
/**
|
|
48
|
+
* The seven looks, one suggested per starter group (General and Professional
|
|
49
|
+
* share Clean). Fonts are open-licence families with system fallbacks; the
|
|
50
|
+
* page uses the fallback until the project hosts the font.
|
|
51
|
+
*/
|
|
52
|
+
export declare const LOOKS: readonly Look[];
|
|
53
|
+
/** The look a new project starts with when nothing else is chosen: Clean, light (Robert, 24 November 2026). */
|
|
54
|
+
export declare const DEFAULT_LOOK: LookId;
|
|
55
|
+
/** 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
|
+
export declare function lookById(id: string): Look;
|
|
58
|
+
/** What a project says about its look: brand.json's fields, all optional. */
|
|
59
|
+
export interface ThemeInput {
|
|
60
|
+
look?: string;
|
|
61
|
+
scheme?: Scheme;
|
|
62
|
+
shape?: Shape;
|
|
63
|
+
colours?: {
|
|
64
|
+
primary?: string;
|
|
65
|
+
text?: string;
|
|
66
|
+
background?: string;
|
|
67
|
+
muted?: string;
|
|
68
|
+
};
|
|
69
|
+
fonts?: {
|
|
70
|
+
heading?: {
|
|
71
|
+
family: string;
|
|
72
|
+
};
|
|
73
|
+
body?: {
|
|
74
|
+
family: string;
|
|
75
|
+
};
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
/** `a` moved `amount` (0 to 1) of the way to `b`. */
|
|
79
|
+
export declare function mix(a: string, b: string, amount: number): string;
|
|
80
|
+
/** The WCAG contrast ratio of two colours, 1 to 21. */
|
|
81
|
+
export declare function contrast(a: string, b: string): number;
|
|
82
|
+
/**
|
|
83
|
+
* A project's public look from what brand.json says: the named look (Clean
|
|
84
|
+
* unless it names another) in its scheme (light unless dark), with brand.json's
|
|
85
|
+
* own colours, fonts and shape over it. The muted colour is pushed towards the
|
|
86
|
+
* text until it reads; anything else that doesn't read is left for
|
|
87
|
+
* themeProblems to name, since it is the owner's own colour.
|
|
88
|
+
*/
|
|
89
|
+
export declare function resolveTheme(input?: ThemeInput): Theme;
|
|
90
|
+
/**
|
|
91
|
+
* The look of a project's own admin pages (Robert, 24 November 2026): the
|
|
92
|
+
* project's accent and fonts on Clean's light neutrals, so a busy page stays
|
|
93
|
+
* readable whatever the public look. An accent too pale for white is darkened
|
|
94
|
+
* until it reads.
|
|
95
|
+
*/
|
|
96
|
+
export declare function resolveAdminTheme(input?: ThemeInput): Theme;
|
|
97
|
+
/** Every pair of a theme's colours that doesn't read, named in plain words. */
|
|
98
|
+
export declare function themeProblems(theme: Theme): string[];
|
|
99
|
+
/** 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): {
|
|
101
|
+
input: ThemeInput;
|
|
102
|
+
problems: string[];
|
|
103
|
+
};
|
|
104
|
+
/** The project's `@layer workbench.theme`: the public look on :root, the admin look on html.wb-ui-admin. */
|
|
105
|
+
export declare function renderTheme(site: Theme, admin: Theme, source: string): string;
|
package/dist/theme.js
ADDED
|
@@ -0,0 +1,334 @@
|
|
|
1
|
+
// One look for every Workbench tool in a project (Robert, 24 November 2026,
|
|
2
|
+
// thread "Design how projects style our tools"). A project's brand.json says
|
|
3
|
+
// what it looks like: a named look, or its own colours, fonts, corner shape and
|
|
4
|
+
// light or dark. `npx workbench-ui styles` turns that into the shared theme
|
|
5
|
+
// tokens below, in `@layer workbench.theme` of workbench.css, and every tool's
|
|
6
|
+
// own --wb-<tool>-* variables default to a token, so one change reaches every
|
|
7
|
+
// form, booking box, email and PDF. project.css still wins over everything.
|
|
8
|
+
//
|
|
9
|
+
// Every value here is worked out to a plain colour (no color-mix or variables),
|
|
10
|
+
// so emails and PDFs can take the same values inline.
|
|
11
|
+
/** The shared tokens every tool's variables default to, in the order workbench.css lists them. */
|
|
12
|
+
export const THEME_TOKENS = [
|
|
13
|
+
{ name: "--wb-background", about: "Behind the page", from: "set" },
|
|
14
|
+
{ name: "--wb-surface", about: "Cards, boxes and inputs", from: "worked out" },
|
|
15
|
+
{ name: "--wb-text", about: "Main text", from: "set" },
|
|
16
|
+
{ name: "--wb-muted", about: "Quieter text: hints, labels, small print", from: "set" },
|
|
17
|
+
{ name: "--wb-line", about: "Borders and rules", from: "worked out" },
|
|
18
|
+
{ name: "--wb-accent", about: "Main buttons, links and the chosen item", from: "set" },
|
|
19
|
+
{ name: "--wb-accent-hover", about: "The accent under the pointer", from: "worked out" },
|
|
20
|
+
{ name: "--wb-on-accent", about: "Text on a filled button", from: "worked out" },
|
|
21
|
+
{ name: "--wb-focus", about: "The ring round the control that has the keyboard", from: "worked out" },
|
|
22
|
+
{ name: "--wb-danger", about: "Problem messages and the border of a field with a problem", from: "set" },
|
|
23
|
+
{ name: "--wb-danger-bg", about: "Behind a problem message", from: "worked out" },
|
|
24
|
+
{ name: "--wb-success", about: "Words that say something worked", from: "set" },
|
|
25
|
+
{ name: "--wb-warning", about: "Words that ask for care", from: "set" },
|
|
26
|
+
{ name: "--wb-font", about: "Body text's font", from: "set" },
|
|
27
|
+
{ name: "--wb-font-heading", about: "Headings' font", from: "set" },
|
|
28
|
+
{ name: "--wb-font-mono", about: "Codes and references", from: "fixed" },
|
|
29
|
+
{ name: "--wb-text-size", about: "Base text size", from: "set" },
|
|
30
|
+
{ name: "--wb-radius", about: "Corner rounding of cards and boxes", from: "set" },
|
|
31
|
+
{ name: "--wb-radius-small", about: "Corner rounding of buttons and fields", from: "set" },
|
|
32
|
+
{ name: "--wb-space", about: "The base gap that spacing multiplies", from: "set" },
|
|
33
|
+
{ name: "--wb-control-height", about: "Least height of a button or field (a touch target)", from: "fixed" },
|
|
34
|
+
];
|
|
35
|
+
const SANS = 'system-ui,-apple-system,"Segoe UI",Roboto,sans-serif';
|
|
36
|
+
const SERIF = 'Georgia,"Times New Roman",serif';
|
|
37
|
+
const MONO = 'ui-monospace,"Cascadia Code",Consolas,monospace';
|
|
38
|
+
const font = (family, fallback = SANS) => `"${family}",${fallback}`;
|
|
39
|
+
// Status colours that pass AA on a light and on a dark background.
|
|
40
|
+
const OK_LIGHT = { danger: "#b42318", success: "#15803d", warning: "#a15c07" };
|
|
41
|
+
const OK_DARK = { danger: "#ff7a73", success: "#5cc87a", warning: "#f0a43a" };
|
|
42
|
+
/**
|
|
43
|
+
* The seven looks, one suggested per starter group (General and Professional
|
|
44
|
+
* share Clean). Fonts are open-licence families with system fallbacks; the
|
|
45
|
+
* page uses the fallback until the project hosts the font.
|
|
46
|
+
*/
|
|
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
|
+
];
|
|
119
|
+
/** The look a new project starts with when nothing else is chosen: Clean, light (Robert, 24 November 2026). */
|
|
120
|
+
export const DEFAULT_LOOK = "clean";
|
|
121
|
+
/** The look suggested for a starter group of Control's New project gallery, Clean when none fits. */
|
|
122
|
+
export function lookFor(group) {
|
|
123
|
+
return LOOKS.find((l) => l.suggestedFor.includes(group)) ?? lookById(DEFAULT_LOOK);
|
|
124
|
+
}
|
|
125
|
+
export function lookById(id) {
|
|
126
|
+
const look = LOOKS.find((l) => l.id === id);
|
|
127
|
+
if (!look)
|
|
128
|
+
throw new Error(`no look called ${id}: choose one of ${LOOKS.map((l) => l.id).join(", ")}`);
|
|
129
|
+
return look;
|
|
130
|
+
}
|
|
131
|
+
const RADII = {
|
|
132
|
+
square: { radius: "4px", small: "3px" },
|
|
133
|
+
soft: { radius: "8px", small: "6px" },
|
|
134
|
+
round: { radius: "16px", small: "12px" },
|
|
135
|
+
};
|
|
136
|
+
// ---- colour arithmetic, on #rrggbb -------------------------------------------------
|
|
137
|
+
const HEX = /^#[0-9a-fA-F]{6}$/;
|
|
138
|
+
function rgb(hex) {
|
|
139
|
+
if (!HEX.test(hex))
|
|
140
|
+
throw new Error(`expected a colour like #1f6feb, not ${hex}`);
|
|
141
|
+
return [0, 2, 4].map((i) => Number.parseInt(hex.slice(1 + i, 3 + i), 16));
|
|
142
|
+
}
|
|
143
|
+
const toHex = (c) => `#${c.map((x) => Math.round(Math.min(255, Math.max(0, x))).toString(16).padStart(2, "0")).join("")}`;
|
|
144
|
+
/** `a` moved `amount` (0 to 1) of the way to `b`. */
|
|
145
|
+
export function mix(a, b, amount) {
|
|
146
|
+
const [x, y] = [rgb(a), rgb(b)];
|
|
147
|
+
return toHex(x.map((v, i) => v + (y[i] - v) * amount));
|
|
148
|
+
}
|
|
149
|
+
function luminance(hex) {
|
|
150
|
+
const lin = rgb(hex).map((v) => {
|
|
151
|
+
const s = v / 255;
|
|
152
|
+
return s <= 0.03928 ? s / 12.92 : ((s + 0.055) / 1.055) ** 2.4;
|
|
153
|
+
});
|
|
154
|
+
return 0.2126 * lin[0] + 0.7152 * lin[1] + 0.0722 * lin[2];
|
|
155
|
+
}
|
|
156
|
+
/** The WCAG contrast ratio of two colours, 1 to 21. */
|
|
157
|
+
export function contrast(a, b) {
|
|
158
|
+
const [l1, l2] = [luminance(a), luminance(b)].sort((p, q) => q - p);
|
|
159
|
+
return (l1 + 0.05) / (l2 + 0.05);
|
|
160
|
+
}
|
|
161
|
+
const rgba = (hex, alpha) => `rgba(${rgb(hex).join(",")},${alpha})`;
|
|
162
|
+
/** `colour` moved towards `towards` in small steps until it reaches `ratio` against `against`. */
|
|
163
|
+
function untilContrast(colour, against, towards, ratio) {
|
|
164
|
+
let c = colour;
|
|
165
|
+
for (let i = 1; i <= 20 && contrast(c, against) < ratio; i++)
|
|
166
|
+
c = mix(colour, towards, i / 20);
|
|
167
|
+
return c;
|
|
168
|
+
}
|
|
169
|
+
// ---- the theme ---------------------------------------------------------------------
|
|
170
|
+
/** Text on a filled accent button: near-black or white, whichever reads better. */
|
|
171
|
+
const onAccent = (accent) => (contrast(accent, "#111111") >= contrast(accent, "#ffffff") ? "#111111" : "#ffffff");
|
|
172
|
+
/** The palette and fonts behind a theme, before the in-between values are worked out. */
|
|
173
|
+
function themeFrom(p, scheme, fonts, shape) {
|
|
174
|
+
const dark = scheme === "dark";
|
|
175
|
+
const { radius, small } = RADII[shape];
|
|
176
|
+
const tokens = {
|
|
177
|
+
"--wb-background": p.background,
|
|
178
|
+
"--wb-surface": mix(p.background, p.text, dark ? 0.07 : 0.035),
|
|
179
|
+
"--wb-text": p.text,
|
|
180
|
+
"--wb-muted": p.muted,
|
|
181
|
+
"--wb-line": mix(p.background, p.text, dark ? 0.22 : 0.18),
|
|
182
|
+
"--wb-accent": p.accent,
|
|
183
|
+
"--wb-accent-hover": mix(p.accent, dark ? "#ffffff" : "#000000", 0.15),
|
|
184
|
+
"--wb-on-accent": onAccent(p.accent),
|
|
185
|
+
"--wb-focus": rgba(p.accent, 0.4),
|
|
186
|
+
"--wb-danger": p.danger,
|
|
187
|
+
"--wb-danger-bg": mix(p.background, p.danger, dark ? 0.16 : 0.08),
|
|
188
|
+
"--wb-success": p.success,
|
|
189
|
+
"--wb-warning": p.warning,
|
|
190
|
+
"--wb-font": fonts.body,
|
|
191
|
+
"--wb-font-heading": fonts.heading,
|
|
192
|
+
"--wb-font-mono": MONO,
|
|
193
|
+
"--wb-text-size": "1rem",
|
|
194
|
+
"--wb-radius": radius,
|
|
195
|
+
"--wb-radius-small": small,
|
|
196
|
+
"--wb-space": "1rem",
|
|
197
|
+
"--wb-control-height": "2.75rem",
|
|
198
|
+
};
|
|
199
|
+
return { scheme, tokens };
|
|
200
|
+
}
|
|
201
|
+
const family = (f, fallback) => (f ? `"${f.family.replace(/["\\]/g, "")}",${fallback}` : null);
|
|
202
|
+
/**
|
|
203
|
+
* A project's public look from what brand.json says: the named look (Clean
|
|
204
|
+
* unless it names another) in its scheme (light unless dark), with brand.json's
|
|
205
|
+
* own colours, fonts and shape over it. The muted colour is pushed towards the
|
|
206
|
+
* text until it reads; anything else that doesn't read is left for
|
|
207
|
+
* themeProblems to name, since it is the owner's own colour.
|
|
208
|
+
*/
|
|
209
|
+
export function resolveTheme(input = {}) {
|
|
210
|
+
const look = lookById(input.look ?? DEFAULT_LOOK);
|
|
211
|
+
const scheme = input.scheme ?? "light";
|
|
212
|
+
const base = look[scheme];
|
|
213
|
+
const c = input.colours ?? {};
|
|
214
|
+
const p = {
|
|
215
|
+
...base,
|
|
216
|
+
background: c.background ?? base.background,
|
|
217
|
+
text: c.text ?? base.text,
|
|
218
|
+
accent: c.primary ?? base.accent,
|
|
219
|
+
muted: c.muted ?? base.muted,
|
|
220
|
+
};
|
|
221
|
+
p.muted = untilContrast(p.muted, p.background, p.text, 4.5);
|
|
222
|
+
const fonts = {
|
|
223
|
+
heading: family(input.fonts?.heading, look.fonts.heading) ?? look.fonts.heading,
|
|
224
|
+
body: family(input.fonts?.body, look.fonts.body) ?? look.fonts.body,
|
|
225
|
+
};
|
|
226
|
+
return themeFrom(p, scheme, fonts, input.shape ?? look.shape);
|
|
227
|
+
}
|
|
228
|
+
/**
|
|
229
|
+
* The look of a project's own admin pages (Robert, 24 November 2026): the
|
|
230
|
+
* project's accent and fonts on Clean's light neutrals, so a busy page stays
|
|
231
|
+
* readable whatever the public look. An accent too pale for white is darkened
|
|
232
|
+
* until it reads.
|
|
233
|
+
*/
|
|
234
|
+
export function resolveAdminTheme(input = {}) {
|
|
235
|
+
const site = resolveTheme(input);
|
|
236
|
+
const clean = lookById("clean").light;
|
|
237
|
+
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);
|
|
239
|
+
}
|
|
240
|
+
/** 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
|
+
const PAIRS = [
|
|
242
|
+
["--wb-text", "--wb-background", 4.5, "text on the page"],
|
|
243
|
+
["--wb-text", "--wb-surface", 4.5, "text in a box or field"],
|
|
244
|
+
["--wb-muted", "--wb-background", 4.5, "quieter text on the page"],
|
|
245
|
+
["--wb-accent", "--wb-background", 4.5, "a link on the page"],
|
|
246
|
+
["--wb-on-accent", "--wb-accent", 4.5, "text on a filled button"],
|
|
247
|
+
["--wb-danger", "--wb-background", 4.5, "a problem message"],
|
|
248
|
+
["--wb-danger", "--wb-danger-bg", 4.5, "a problem message in its box"],
|
|
249
|
+
["--wb-success", "--wb-background", 3, "a done mark"],
|
|
250
|
+
["--wb-warning", "--wb-background", 3, "a take-care mark"],
|
|
251
|
+
];
|
|
252
|
+
/** Every pair of a theme's colours that doesn't read, named in plain words. */
|
|
253
|
+
export function themeProblems(theme) {
|
|
254
|
+
const t = theme.tokens;
|
|
255
|
+
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
|
+
}
|
|
257
|
+
/** What brand.json says about the look, read loosely: a field of the wrong kind is named, never guessed. */
|
|
258
|
+
export function themeInput(brand) {
|
|
259
|
+
const problems = [];
|
|
260
|
+
const input = {};
|
|
261
|
+
if (!brand || typeof brand !== "object")
|
|
262
|
+
return { input, problems: ["brand.json must hold an object"] };
|
|
263
|
+
const b = brand;
|
|
264
|
+
if (b.look !== undefined) {
|
|
265
|
+
if (typeof b.look === "string" && LOOKS.some((l) => l.id === b.look))
|
|
266
|
+
input.look = b.look;
|
|
267
|
+
else
|
|
268
|
+
problems.push(`brand.json: look must be one of ${LOOKS.map((l) => l.id).join(", ")}`);
|
|
269
|
+
}
|
|
270
|
+
if (b.scheme !== undefined) {
|
|
271
|
+
if (b.scheme === "light" || b.scheme === "dark")
|
|
272
|
+
input.scheme = b.scheme;
|
|
273
|
+
else
|
|
274
|
+
problems.push("brand.json: scheme must be light or dark");
|
|
275
|
+
}
|
|
276
|
+
if (b.shape !== undefined) {
|
|
277
|
+
if (b.shape === "square" || b.shape === "soft" || b.shape === "round")
|
|
278
|
+
input.shape = b.shape;
|
|
279
|
+
else
|
|
280
|
+
problems.push("brand.json: shape must be square, soft or round");
|
|
281
|
+
}
|
|
282
|
+
if (b.colours && typeof b.colours === "object") {
|
|
283
|
+
const c = b.colours;
|
|
284
|
+
const colours = {};
|
|
285
|
+
for (const k of ["primary", "text", "background", "muted"]) {
|
|
286
|
+
if (c[k] === undefined)
|
|
287
|
+
continue;
|
|
288
|
+
if (typeof c[k] === "string" && HEX.test(c[k]))
|
|
289
|
+
colours[k] = c[k].toLowerCase();
|
|
290
|
+
else
|
|
291
|
+
problems.push(`brand.json: colours.${k} must be a colour like #1f6feb`);
|
|
292
|
+
}
|
|
293
|
+
input.colours = colours;
|
|
294
|
+
}
|
|
295
|
+
if (b.fonts && typeof b.fonts === "object") {
|
|
296
|
+
const f = b.fonts;
|
|
297
|
+
const fonts = {};
|
|
298
|
+
for (const k of ["heading", "body"]) {
|
|
299
|
+
const v = f[k];
|
|
300
|
+
if (v === undefined)
|
|
301
|
+
continue;
|
|
302
|
+
if (v && typeof v.family === "string" && /^[\w .'-]{1,100}$/.test(v.family))
|
|
303
|
+
fonts[k] = { family: v.family };
|
|
304
|
+
else
|
|
305
|
+
problems.push(`brand.json: fonts.${k}.family must be a font name`);
|
|
306
|
+
}
|
|
307
|
+
input.fonts = fonts;
|
|
308
|
+
}
|
|
309
|
+
return { input, problems };
|
|
310
|
+
}
|
|
311
|
+
const comment = (text) => `/* ${text.replace(/\*\//g, "* /")} */`;
|
|
312
|
+
/** A theme's tokens as declarations, each with its comment. */
|
|
313
|
+
function declarations(theme, indent) {
|
|
314
|
+
const out = [`${indent}color-scheme: ${theme.scheme};`];
|
|
315
|
+
for (const t of THEME_TOKENS)
|
|
316
|
+
out.push(`${indent}${comment(t.about)}`, `${indent}${t.name}: ${theme.tokens[t.name]};`);
|
|
317
|
+
return out;
|
|
318
|
+
}
|
|
319
|
+
/** The project's `@layer workbench.theme`: the public look on :root, the admin look on html.wb-ui-admin. */
|
|
320
|
+
export function renderTheme(site, admin, source) {
|
|
321
|
+
return [
|
|
322
|
+
comment(`The look: ${source}. Every tool's --wb-<tool>-* variables default to these. Change brand.json and run \`npx workbench-ui styles\`, or map a token in project.css.`),
|
|
323
|
+
"@layer workbench.theme {",
|
|
324
|
+
" :root {",
|
|
325
|
+
...declarations(site, " "),
|
|
326
|
+
" }",
|
|
327
|
+
"",
|
|
328
|
+
` ${comment("A project's own admin pages (html.wb-ui-admin): its accent and fonts on Clean's light neutrals.")}`,
|
|
329
|
+
" :root.wb-ui-admin {",
|
|
330
|
+
...declarations(admin, " "),
|
|
331
|
+
" }",
|
|
332
|
+
"}",
|
|
333
|
+
].join("\n");
|
|
334
|
+
}
|
package/dist/ui-styles.js
CHANGED
|
@@ -58,6 +58,7 @@ export const UI_STYLES = {
|
|
|
58
58
|
],
|
|
59
59
|
classes: [
|
|
60
60
|
{ name: "wb-ui", element: "html", about: "The whole page: dark whatever the computer is set to", css: `color-scheme:dark;background:${v("background")};color:${v("text")};font:15px/1.55 ${v("font")}` },
|
|
61
|
+
{ name: "wb-ui-admin", element: "html", about: "A project's own admin page (with wb-ui): its accent and fonts on light neutrals, from the theme tokens", css: "color-scheme:light" },
|
|
61
62
|
{ name: "wb-ui-main", element: "main", about: "The page's column under the top bar", css: `display:block;max-width:${v("width")};margin:0 auto;padding:1.75rem 1rem 3rem` },
|
|
62
63
|
{ name: "wb-ui-title", element: "h1", about: "The page's heading", css: "font-size:1.6rem;line-height:1.2;margin:0 0 .6rem" },
|
|
63
64
|
{ name: "wb-ui-bar", element: "header", about: "The bar that stays on top of the page", css: `position:sticky;top:0;z-index:10;background:${v("bar")};backdrop-filter:blur(8px);border-bottom:1px solid ${v("line")}` },
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mccaskie-labs/workbench-ui",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.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",
|