@mccaskie-labs/workbench-ui 0.13.0 → 0.13.2
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 +12 -0
- package/dist/cli.d.ts +7 -1
- package/dist/cli.js +31 -8
- package/dist/fonts.d.ts +3 -1
- package/dist/fonts.js +8 -2
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/layouts.d.ts +6 -4
- package/dist/layouts.js +7 -6
- package/dist/theme.d.ts +30 -0
- package/dist/theme.js +61 -0
- package/dist/ui-styles.js +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# @mccaskie-labs/workbench-ui
|
|
2
2
|
|
|
3
|
+
## 0.13.2
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Preview styles (docs/look-studio.md §5.3, step 7a). `npx workbench-ui styles` also writes `public/styles/looks.css`: every look a project may choose (the package's and its own `workbench/looks/`), in light and dark, as token blocks under `:root[data-wb-look][data-wb-scheme]`, with `@font-face` rules for each look's fonts in the latin letters. Those font files are copied into `public/fonts/` beside the project's own, so a preview never calls a font service. `previewAttributes(url, allowed)` reads `?wb-look=` and `?wb-scheme=` for the page frame, only when the caller allows it (a signed-in admin, or outside production), and refuses anything that isn't an id. It also writes `src/site-layout.generated.ts`, whose `SITE_LAYOUT` is the site layout brand.json resolves to, a project's own from `workbench/looks/` too, so the Worker's page frame can use one it can't read at run time. `chooseLayout` now takes any number of choices in order (design mode's trial, the kept setting, the code's option, the answers file) and draws the first the tool has. Additive only.
|
|
8
|
+
|
|
9
|
+
## 0.13.1
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- The style guide keeps a part that is fixed to the screen (the ask button) inside its own sample box, instead of floating over the page: each sample's frame is its own layout container (`contain: layout`) with room for it.
|
|
14
|
+
|
|
3
15
|
## 0.13.0
|
|
4
16
|
|
|
5
17
|
### Minor Changes
|
package/dist/cli.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { type Library } from "./library.ts";
|
|
2
|
+
import { type LayoutItem, type Library } from "./library.ts";
|
|
3
3
|
import { type InstalledStyles } from "./styles.ts";
|
|
4
4
|
/** The styles of each Workbench tool the project at `dir` has installed, and the workbench-ui version. */
|
|
5
5
|
export declare function installedStyles(dir: string): Promise<{
|
|
@@ -11,6 +11,10 @@ export declare const SAMPLE_FILES: {
|
|
|
11
11
|
readonly module: "src/samples.generated.ts";
|
|
12
12
|
readonly guide: "public/styles/style-guide.css";
|
|
13
13
|
};
|
|
14
|
+
/** The project's resolved site layout, for its Worker, which can't read workbench/looks/ at run time. */
|
|
15
|
+
export declare const SITE_LAYOUT_FILE = "src/site-layout.generated.ts";
|
|
16
|
+
/** The generated module holding a project's site layout as data (docs/look-studio.md §6). */
|
|
17
|
+
export declare function siteLayoutModule(layout: LayoutItem): string;
|
|
14
18
|
/** Every Workbench package the project at `dir` depends on whose package.json exports "./samples", sorted. */
|
|
15
19
|
export declare function samplePackages(dir: string): string[];
|
|
16
20
|
/** The generated samples module: one import per package, every ToolSamples it exports, in package order. */
|
|
@@ -52,6 +56,8 @@ export declare function projectTheme(dir: string): {
|
|
|
52
56
|
problems: string[];
|
|
53
57
|
fixes: BrandFix[];
|
|
54
58
|
families: string[];
|
|
59
|
+
library: Library;
|
|
60
|
+
layout: LayoutItem;
|
|
55
61
|
};
|
|
56
62
|
/**
|
|
57
63
|
* Rules in a project's own CSS that take the underline off plain links, so a
|
package/dist/cli.js
CHANGED
|
@@ -23,7 +23,7 @@ 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 { libraryProblems, renderSchemes, renderTheme, resolveAdminTheme, resolveTheme, themeFixes, themeInput, themeProblems } from "./theme.js";
|
|
26
|
+
import { libraryProblems, PREVIEW_FILE, previewFamilies, renderLooks, renderSchemes, resolveSiteLayout, renderTheme, resolveAdminTheme, resolveTheme, themeFixes, themeInput, themeProblems } from "./theme.js";
|
|
27
27
|
import { familiesIn, fontGaps, projectFonts } from "./fonts.js";
|
|
28
28
|
import { findItem, itemProblems, LIBRARY, withProjectItems } from "./library.js";
|
|
29
29
|
import { DEFAULT_THEME_CSS, renderStyles, STYLE_FILES, STYLED_SCOPE, starterProjectCss, unknownMarkupNames, unknownNames } from "./styles.js";
|
|
@@ -72,6 +72,19 @@ export async function installedStyles(dir) {
|
|
|
72
72
|
}
|
|
73
73
|
/** Where the generated list of every installed tool's samples is written, and the style guide's sheet (docs/look-studio.md §5.1, §9.5). */
|
|
74
74
|
export const SAMPLE_FILES = { module: "src/samples.generated.ts", guide: "public/styles/style-guide.css" };
|
|
75
|
+
/** The project's resolved site layout, for its Worker, which can't read workbench/looks/ at run time. */
|
|
76
|
+
export const SITE_LAYOUT_FILE = "src/site-layout.generated.ts";
|
|
77
|
+
/** The generated module holding a project's site layout as data (docs/look-studio.md §6). */
|
|
78
|
+
export function siteLayoutModule(layout) {
|
|
79
|
+
const { id, header, footer, width, spacing, hero } = layout;
|
|
80
|
+
return [
|
|
81
|
+
"// Written by `npx workbench-ui styles`: the site layout brand.json resolves to (its `layout`, else its look's),",
|
|
82
|
+
"// including one from workbench/looks/. Don't edit; `npx workbench-ui styles --check` fails when it is out of date.",
|
|
83
|
+
"",
|
|
84
|
+
`export const SITE_LAYOUT = ${JSON.stringify({ id, header, footer, width, spacing, hero }, null, 2)} as const;`,
|
|
85
|
+
"",
|
|
86
|
+
].join("\n");
|
|
87
|
+
}
|
|
75
88
|
/** Every Workbench package the project at `dir` depends on whose package.json exports "./samples", sorted. */
|
|
76
89
|
export function samplePackages(dir) {
|
|
77
90
|
if (!existsSync(join(dir, "package.json")))
|
|
@@ -198,14 +211,16 @@ export function applyBrandFixes(brandText, fixes) {
|
|
|
198
211
|
export function projectTheme(dir) {
|
|
199
212
|
const at = join(dir, BRAND_FILE);
|
|
200
213
|
const plain = () => familiesIn([resolveTheme().tokens["--wb-font-heading"], resolveTheme().tokens["--wb-font"]]);
|
|
201
|
-
if (!existsSync(at))
|
|
202
|
-
|
|
214
|
+
if (!existsSync(at)) {
|
|
215
|
+
const own = projectLibrary(dir);
|
|
216
|
+
return { css: DEFAULT_THEME_CSS, guide: renderSchemes({}), problems: own.problems, fixes: [], families: plain(), library: own.library, layout: resolveSiteLayout({}, own.library) };
|
|
217
|
+
}
|
|
203
218
|
let brand;
|
|
204
219
|
try {
|
|
205
220
|
brand = JSON.parse(read(at));
|
|
206
221
|
}
|
|
207
222
|
catch {
|
|
208
|
-
return { css: DEFAULT_THEME_CSS, guide: renderSchemes({}), problems: [`${BRAND_FILE} isn't valid JSON`], fixes: [], families: plain() };
|
|
223
|
+
return { css: DEFAULT_THEME_CSS, guide: renderSchemes({}), problems: [`${BRAND_FILE} isn't valid JSON`], fixes: [], families: plain(), library: projectLibrary(dir).library, layout: resolveSiteLayout() };
|
|
209
224
|
}
|
|
210
225
|
const own = projectLibrary(dir);
|
|
211
226
|
const { input, problems } = themeInput(brand, own.library);
|
|
@@ -218,7 +233,7 @@ export function projectTheme(dir) {
|
|
|
218
233
|
problems.push(`${BRAND_FILE}: your colours.${f.field} ${f.from} is too faint for ${f.what}. Nearest that reads: ${f.to} (\`npx workbench-ui styles --fix\` takes it)`);
|
|
219
234
|
for (const f of themeFixes(site).filter((x) => !BRAND_FIELD[x.token]))
|
|
220
235
|
problems.push(`${BRAND_FILE}: the look's ${f.token} ${f.from} doesn't read for ${f.what}: choose another look or palette`);
|
|
221
|
-
return { css: renderTheme(site, resolveAdminTheme(input, own.library), `${look} (from ${BRAND_FILE})`), guide: renderSchemes(input, own.library), problems, fixes, families: familiesIn([site.tokens["--wb-font-heading"], site.tokens["--wb-font"]]) };
|
|
236
|
+
return { css: renderTheme(site, resolveAdminTheme(input, own.library), `${look} (from ${BRAND_FILE})`), guide: renderSchemes(input, own.library), problems, fixes, families: familiesIn([site.tokens["--wb-font-heading"], site.tokens["--wb-font"]]), library: own.library, layout: resolveSiteLayout(input, own.library) };
|
|
222
237
|
}
|
|
223
238
|
/**
|
|
224
239
|
* Rules in a project's own CSS that take the underline off plain links, so a
|
|
@@ -244,14 +259,22 @@ export function planStyles(dir, tools, uiVersion) {
|
|
|
244
259
|
problems.push(...theme.problems);
|
|
245
260
|
const fonts = projectFonts(theme.families);
|
|
246
261
|
const generated = renderStyles(tools, uiVersion, theme.css, fonts.css);
|
|
247
|
-
|
|
262
|
+
// Every look the project may preview, with the latin letters of each look's fonts (docs/look-studio.md §5.3).
|
|
263
|
+
const preview = projectFonts(previewFamilies(theme.library), undefined, ["latin"]);
|
|
264
|
+
const fontFiles = [...fonts.files, ...preview.files.filter((p) => !fonts.files.some((f) => f.path === p.path))];
|
|
265
|
+
for (const f of fontFiles) {
|
|
248
266
|
const bytes = readFileSync(f.from);
|
|
249
267
|
if (existsSync(join(dir, f.path)) && readFileSync(join(dir, f.path)).equals(bytes))
|
|
250
268
|
continue;
|
|
251
269
|
files[f.path] = bytes;
|
|
252
270
|
problems.push(`${f.path} is missing or out of date: the look's fonts are hosted by the project`);
|
|
253
271
|
}
|
|
254
|
-
const derived = {
|
|
272
|
+
const derived = {
|
|
273
|
+
[SAMPLE_FILES.module]: samplesModule(samplePackages(dir)),
|
|
274
|
+
[SAMPLE_FILES.guide]: theme.guide,
|
|
275
|
+
[PREVIEW_FILE.path]: renderLooks(theme.library, preview.css),
|
|
276
|
+
[SITE_LAYOUT_FILE]: siteLayoutModule(theme.layout),
|
|
277
|
+
};
|
|
255
278
|
for (const [path, text] of Object.entries(derived)) {
|
|
256
279
|
if (existsSync(join(dir, path)) && read(join(dir, path)) === text)
|
|
257
280
|
continue;
|
|
@@ -328,7 +351,7 @@ async function main(argv) {
|
|
|
328
351
|
}
|
|
329
352
|
// Writing fixes workbench.css; project.css and the project's own pages are fixed by hand.
|
|
330
353
|
// brand.json's problems are fixed by hand too.
|
|
331
|
-
const left = plan.problems.filter((p) => !p.startsWith(STYLE_FILES.generated) && !Object.values(SAMPLE_FILES).some((f) => p.startsWith(f)) && !p.startsWith("public/fonts/") && !(p.startsWith(STYLE_FILES.project) && plan.files[STYLE_FILES.project]));
|
|
354
|
+
const left = plan.problems.filter((p) => !p.startsWith(STYLE_FILES.generated) && !Object.values(SAMPLE_FILES).some((f) => p.startsWith(f)) && !p.startsWith(PREVIEW_FILE.path) && !p.startsWith(SITE_LAYOUT_FILE) && !p.startsWith("public/fonts/") && !(p.startsWith(STYLE_FILES.project) && plan.files[STYLE_FILES.project]));
|
|
332
355
|
for (const p of left)
|
|
333
356
|
console.error(p);
|
|
334
357
|
return left.length ? 1 : 0;
|
package/dist/fonts.d.ts
CHANGED
|
@@ -30,7 +30,9 @@ export declare function familiesIn(stacks: readonly string[]): string[];
|
|
|
30
30
|
* workbench-ui hosts. A family it doesn't host (an owner's own) is left to its
|
|
31
31
|
* fallback, as before.
|
|
32
32
|
*/
|
|
33
|
-
export declare function projectFonts(families: readonly string[], hosted?: readonly HostedFamily[]
|
|
33
|
+
export declare function projectFonts(families: readonly string[], hosted?: readonly HostedFamily[],
|
|
34
|
+
/** Only these subsets (the preview styles take latin alone); every one when left out. */
|
|
35
|
+
subsets?: readonly string[]): {
|
|
34
36
|
css: string;
|
|
35
37
|
files: {
|
|
36
38
|
path: string;
|
package/dist/fonts.js
CHANGED
|
@@ -32,8 +32,14 @@ const q = (s) => `"${s.replace(/["\\]/g, "")}"`;
|
|
|
32
32
|
* workbench-ui hosts. A family it doesn't host (an owner's own) is left to its
|
|
33
33
|
* fallback, as before.
|
|
34
34
|
*/
|
|
35
|
-
export function projectFonts(families, hosted = hostedFamilies()
|
|
36
|
-
|
|
35
|
+
export function projectFonts(families, hosted = hostedFamilies(),
|
|
36
|
+
/** Only these subsets (the preview styles take latin alone); every one when left out. */
|
|
37
|
+
subsets) {
|
|
38
|
+
const used = families
|
|
39
|
+
.map((f) => hosted.find((h) => h.family === f))
|
|
40
|
+
.filter((h) => !!h)
|
|
41
|
+
.map((h) => (subsets ? { ...h, files: h.files.filter((f) => subsets.includes(f.subset)) } : h))
|
|
42
|
+
.filter((h) => h.files.length > 0);
|
|
37
43
|
if (!used.length)
|
|
38
44
|
return { css: "", files: [] };
|
|
39
45
|
const rules = used.flatMap((h) => h.files.map((f) => `@font-face { font-family: ${q(h.family)}; font-style: normal; font-weight: ${f.weight}; font-display: swap; src: url("${PROJECT_FONTS.url}/${h.id}/${f.file}") format("woff2"); unicode-range: ${f.unicodeRange}; }`));
|
package/dist/index.d.ts
CHANGED
|
@@ -7,7 +7,7 @@ export { chooseLayout, LAYOUT_BREAKPOINT, LAYOUT_KIT, layoutProblems, type Layou
|
|
|
7
7
|
export { classesIn, sampleProblems, type ToolSample, type ToolSamples } from "./samples.ts";
|
|
8
8
|
export { guideView, styleGuide, type GuideView, type StyleGuideOptions } from "./style-guide.ts";
|
|
9
9
|
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";
|
|
10
|
-
export { contrast, DEFAULT_LOOK, LOOKS, fixPalette, libraryProblems, lookById, lookFor, lookOf, looksIn, MIN_PALETTE_DISTANCE, mix, nearestPassing, paletteDistance, renderSchemes, renderTheme, resolveAdminTheme, resolveSiteLayout, resolveTheme, THEME_TOKENS, themeFixes, themeInput, themeProblems, type Look, type LookId, type Palette, type Scheme, type Shape, type Theme, type ThemeFix, type ThemeInput, type ThemeToken, type TokenName, } from "./theme.ts";
|
|
10
|
+
export { contrast, DEFAULT_LOOK, LOOKS, fixPalette, libraryProblems, lookById, lookFor, lookOf, looksIn, MIN_PALETTE_DISTANCE, mix, nearestPassing, paletteDistance, PREVIEW_FILE, previewAttributes, previewFamilies, renderLooks, renderSchemes, renderTheme, resolveAdminTheme, resolveSiteLayout, resolveTheme, THEME_TOKENS, themeFixes, themeInput, themeProblems, type Look, type LookId, type Palette, type Scheme, type Shape, type Theme, type ThemeFix, type ThemeInput, type ThemeToken, type TokenName, } from "./theme.ts";
|
|
11
11
|
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";
|
|
12
12
|
/** Plain text made safe to put in HTML, in text or in a quoted attribute. */
|
|
13
13
|
export declare const escape: (value: string) => string;
|
package/dist/index.js
CHANGED
|
@@ -12,7 +12,7 @@ export { chooseLayout, LAYOUT_BREAKPOINT, LAYOUT_KIT, layoutProblems } from "./l
|
|
|
12
12
|
export { classesIn, sampleProblems } from "./samples.js";
|
|
13
13
|
export { guideView, styleGuide } from "./style-guide.js";
|
|
14
14
|
export { DEFAULT_THEME_CSS, renderStyles, STYLE_FILES, STYLED_SCOPE, styleNames, styleProblems, STYLESHEETS, starterProjectCss, unknownMarkupNames, unknownNames, } from "./styles.js";
|
|
15
|
-
export { contrast, DEFAULT_LOOK, LOOKS, fixPalette, libraryProblems, lookById, lookFor, lookOf, looksIn, MIN_PALETTE_DISTANCE, mix, nearestPassing, paletteDistance, renderSchemes, renderTheme, resolveAdminTheme, resolveSiteLayout, resolveTheme, THEME_TOKENS, themeFixes, themeInput, themeProblems, } from "./theme.js";
|
|
15
|
+
export { contrast, DEFAULT_LOOK, LOOKS, fixPalette, libraryProblems, lookById, lookFor, lookOf, looksIn, MIN_PALETTE_DISTANCE, mix, nearestPassing, paletteDistance, PREVIEW_FILE, previewAttributes, previewFamilies, renderLooks, renderSchemes, renderTheme, resolveAdminTheme, resolveSiteLayout, resolveTheme, THEME_TOKENS, themeFixes, themeInput, themeProblems, } from "./theme.js";
|
|
16
16
|
export { findItem, itemProblems, LIBRARY, LIBRARY_KINDS, libraryOf, SITE_LAYOUT_CHOICES, usable, withProjectItems, } from "./library.js";
|
|
17
17
|
/** Plain text made safe to put in HTML, in text or in a quoted attribute. */
|
|
18
18
|
export const escape = (value) => value.replace(/[&<>"']/g, (c) => `&#${c.charCodeAt(0)};`);
|
package/dist/layouts.d.ts
CHANGED
|
@@ -53,8 +53,10 @@ export declare function layoutProblems(tool: string, prefix: string, classes: Re
|
|
|
53
53
|
/** A tool's layout rules for the generated stylesheet, each under its data-layout, inside one wide-screen media query. */
|
|
54
54
|
export declare function renderLayouts(t: ToolLayouts, comment: (s: string) => string, decls: (css: string, indent: string) => string): string[];
|
|
55
55
|
/**
|
|
56
|
-
* The layout a tool draws in: the
|
|
57
|
-
*
|
|
58
|
-
*
|
|
56
|
+
* The layout a tool draws in: the first of `choices` the tool has, else the
|
|
57
|
+
* tool's own default. This is the one resolver of docs/look-studio.md §7.1
|
|
58
|
+
* and §8, so callers pass, in this order: design mode's trial, the kept
|
|
59
|
+
* setting, the code's own per-use option, the tool's answers file. An id the
|
|
60
|
+
* tool doesn't have (a layout since removed) is passed over, never drawn.
|
|
59
61
|
*/
|
|
60
|
-
export declare function chooseLayout(t: ToolLayouts,
|
|
62
|
+
export declare function chooseLayout(t: ToolLayouts, ...choices: (string | null | undefined)[]): string;
|
package/dist/layouts.js
CHANGED
|
@@ -133,11 +133,12 @@ export function renderLayouts(t, comment, decls) {
|
|
|
133
133
|
return out;
|
|
134
134
|
}
|
|
135
135
|
/**
|
|
136
|
-
* The layout a tool draws in: the
|
|
137
|
-
*
|
|
138
|
-
*
|
|
136
|
+
* The layout a tool draws in: the first of `choices` the tool has, else the
|
|
137
|
+
* tool's own default. This is the one resolver of docs/look-studio.md §7.1
|
|
138
|
+
* and §8, so callers pass, in this order: design mode's trial, the kept
|
|
139
|
+
* setting, the code's own per-use option, the tool's answers file. An id the
|
|
140
|
+
* tool doesn't have (a layout since removed) is passed over, never drawn.
|
|
139
141
|
*/
|
|
140
|
-
export function chooseLayout(t,
|
|
141
|
-
|
|
142
|
-
return has(asked) ? asked : has(projectDefault) ? projectDefault : t.default;
|
|
142
|
+
export function chooseLayout(t, ...choices) {
|
|
143
|
+
return choices.find((id) => !!id && t.layouts.some((l) => l.id === id)) ?? t.default;
|
|
143
144
|
}
|
package/dist/theme.d.ts
CHANGED
|
@@ -140,6 +140,36 @@ export declare function themeInput(brand: unknown, lib?: Library): {
|
|
|
140
140
|
* guide shows both without the project changing its scheme.
|
|
141
141
|
*/
|
|
142
142
|
export declare function renderSchemes(input: ThemeInput, lib?: Library): string;
|
|
143
|
+
/** Where the preview styles go, from a project's root, and their address. */
|
|
144
|
+
export declare const PREVIEW_FILE: {
|
|
145
|
+
readonly path: "public/styles/looks.css";
|
|
146
|
+
readonly url: "/styles/looks.css";
|
|
147
|
+
};
|
|
148
|
+
/**
|
|
149
|
+
* The preview styles (docs/look-studio.md §5.3): every look a project may
|
|
150
|
+
* choose (the package's released and testing ones, then its own), each in
|
|
151
|
+
* light and dark, under `:root[data-wb-look][data-wb-scheme]`. Loaded beside
|
|
152
|
+
* workbench.css, they show the project's real pages in any look once the
|
|
153
|
+
* page frame sets those attributes (previewAttributes), with nothing else
|
|
154
|
+
* changed. Each look is the library's, without brand.json's own colours or
|
|
155
|
+
* fonts: the project's own look is workbench.css itself.
|
|
156
|
+
*/
|
|
157
|
+
export declare function renderLooks(lib?: Library, fontCss?: string): string;
|
|
158
|
+
/** The families a project's preview styles name: every choosable look's heading and body, once each. */
|
|
159
|
+
export declare function previewFamilies(lib?: Library): string[];
|
|
160
|
+
/**
|
|
161
|
+
* The attributes the page frame puts on `<html>` to preview a look, from the
|
|
162
|
+
* page's address (`?wb-look=calm&wb-scheme=dark`). Only when `allowed`: the
|
|
163
|
+
* caller passes true for a signed-in admin or outside production, never for
|
|
164
|
+
* a visitor to the live site. An id that is no look simply matches no block
|
|
165
|
+
* in looks.css, so nothing else is checked. Empty when there is nothing to
|
|
166
|
+
* preview.
|
|
167
|
+
*/
|
|
168
|
+
export declare function previewAttributes(url: URL | string, allowed: boolean): {
|
|
169
|
+
look: string;
|
|
170
|
+
scheme: Scheme;
|
|
171
|
+
html: string;
|
|
172
|
+
} | null;
|
|
143
173
|
/** The project's `@layer workbench.theme`: the public look on :root, the admin look on html.wb-ui-admin. */
|
|
144
174
|
export declare function renderTheme(site: Theme, admin: Theme, source: string): string;
|
|
145
175
|
/** How far apart two palettes are: the mean distance of their background, text and accent in light and dark, 0 to 441. */
|
package/dist/theme.js
CHANGED
|
@@ -420,6 +420,67 @@ export function renderSchemes(input, lib = LIBRARY) {
|
|
|
420
420
|
"",
|
|
421
421
|
].join("\n");
|
|
422
422
|
}
|
|
423
|
+
/** Where the preview styles go, from a project's root, and their address. */
|
|
424
|
+
export const PREVIEW_FILE = { path: "public/styles/looks.css", url: "/styles/looks.css" };
|
|
425
|
+
/**
|
|
426
|
+
* The preview styles (docs/look-studio.md §5.3): every look a project may
|
|
427
|
+
* choose (the package's released and testing ones, then its own), each in
|
|
428
|
+
* light and dark, under `:root[data-wb-look][data-wb-scheme]`. Loaded beside
|
|
429
|
+
* workbench.css, they show the project's real pages in any look once the
|
|
430
|
+
* page frame sets those attributes (previewAttributes), with nothing else
|
|
431
|
+
* changed. Each look is the library's, without brand.json's own colours or
|
|
432
|
+
* fonts: the project's own look is workbench.css itself.
|
|
433
|
+
*/
|
|
434
|
+
export function renderLooks(lib = LIBRARY, fontCss = "") {
|
|
435
|
+
const ids = lib.looks.filter((l) => l.status !== "withdrawn").map((l) => l.id);
|
|
436
|
+
const out = [
|
|
437
|
+
comment("Written by `npx workbench-ui styles` for previewing looks (the previewer and design mode). Don't edit."),
|
|
438
|
+
...(fontCss ? [fontCss] : []),
|
|
439
|
+
"@layer workbench.theme {",
|
|
440
|
+
];
|
|
441
|
+
for (const id of ids) {
|
|
442
|
+
for (const scheme of ["light", "dark"]) {
|
|
443
|
+
out.push(` :root[data-wb-look="${id}"][data-wb-scheme="${scheme}"] {`, ...declarations(resolveTheme({ look: id, scheme }, lib), " "), " }", "");
|
|
444
|
+
}
|
|
445
|
+
}
|
|
446
|
+
if (out.at(-1) === "")
|
|
447
|
+
out.pop();
|
|
448
|
+
out.push("}", "");
|
|
449
|
+
return out.join("\n");
|
|
450
|
+
}
|
|
451
|
+
/** The families a project's preview styles name: every choosable look's heading and body, once each. */
|
|
452
|
+
export function previewFamilies(lib = LIBRARY) {
|
|
453
|
+
const stacks = lib.looks.filter((l) => l.status !== "withdrawn").flatMap((l) => {
|
|
454
|
+
const t = resolveTheme({ look: l.id }, lib).tokens;
|
|
455
|
+
return [t["--wb-font-heading"], t["--wb-font"]];
|
|
456
|
+
});
|
|
457
|
+
const out = [];
|
|
458
|
+
for (const s of stacks) {
|
|
459
|
+
const m = /^\s*"([^"]+)"/.exec(s);
|
|
460
|
+
if (m && !out.includes(m[1]))
|
|
461
|
+
out.push(m[1]);
|
|
462
|
+
}
|
|
463
|
+
return out;
|
|
464
|
+
}
|
|
465
|
+
const PREVIEW_ID = /^[a-z][a-z0-9-]{0,39}$/;
|
|
466
|
+
/**
|
|
467
|
+
* The attributes the page frame puts on `<html>` to preview a look, from the
|
|
468
|
+
* page's address (`?wb-look=calm&wb-scheme=dark`). Only when `allowed`: the
|
|
469
|
+
* caller passes true for a signed-in admin or outside production, never for
|
|
470
|
+
* a visitor to the live site. An id that is no look simply matches no block
|
|
471
|
+
* in looks.css, so nothing else is checked. Empty when there is nothing to
|
|
472
|
+
* preview.
|
|
473
|
+
*/
|
|
474
|
+
export function previewAttributes(url, allowed) {
|
|
475
|
+
if (!allowed)
|
|
476
|
+
return null;
|
|
477
|
+
const u = typeof url === "string" ? new URL(url) : url;
|
|
478
|
+
const look = u.searchParams.get("wb-look");
|
|
479
|
+
if (!look || !PREVIEW_ID.test(look))
|
|
480
|
+
return null;
|
|
481
|
+
const scheme = u.searchParams.get("wb-scheme") === "dark" ? "dark" : "light";
|
|
482
|
+
return { look, scheme, html: ` data-wb-look="${look}" data-wb-scheme="${scheme}"` };
|
|
483
|
+
}
|
|
423
484
|
/** The project's `@layer workbench.theme`: the public look on :root, the admin look on html.wb-ui-admin. */
|
|
424
485
|
export function renderTheme(site, admin, source) {
|
|
425
486
|
return [
|
package/dist/ui-styles.js
CHANGED
|
@@ -331,7 +331,7 @@ export const UI_STYLES = {
|
|
|
331
331
|
{ name: "wb-ui-guide-caption", element: "figcaption", about: "What the sample shows", css: `display:flex;flex-wrap:wrap;gap:.5rem;justify-content:space-between;padding:.5rem .9rem;font-size:.85rem;color:${v("muted")};border-bottom:1px solid ${v("line")}` },
|
|
332
332
|
{ name: "wb-ui-guide-title", element: "span", about: "The sample's name", css: `color:${v("text")}` },
|
|
333
333
|
{ name: "wb-ui-guide-layout", element: "span", about: "The tool layout a sample shows", css: "font-weight:600" },
|
|
334
|
-
{ name: "wb-ui-guide-frame", element: "div", about: "The sample itself, drawn on the page's own background", css: "padding:1.25rem" },
|
|
334
|
+
{ name: "wb-ui-guide-frame", element: "div", about: "The sample itself, drawn on the page's own background; a part fixed to the screen (the ask button) stays inside it", css: "padding:1.25rem;contain:layout;min-height:6rem" },
|
|
335
335
|
{ name: "wb-ui-guide-empty", element: "p", about: "Said when no tool has samples yet", css: `color:${v("muted")}` },
|
|
336
336
|
],
|
|
337
337
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mccaskie-labs/workbench-ui",
|
|
3
|
-
"version": "0.13.
|
|
3
|
+
"version": "0.13.2",
|
|
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",
|