@mccaskie-labs/workbench-ui 0.13.2 → 0.13.3
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 +6 -0
- package/dist/cli.js +3 -2
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/look-preview.d.ts +43 -0
- package/dist/look-preview.js +36 -0
- package/dist/ui-samples.js +8 -0
- package/dist/ui-styles.js +19 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
# @mccaskie-labs/workbench-ui
|
|
2
2
|
|
|
3
|
+
## 0.13.3
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- The look previewer (docs/look-studio.md §9.1, step 7a): `lookPreview({ pages, url, current, live, words })` draws the project's own pages framed side by side, as the site is now and in every look it may choose, with a switch for the page and for light or dark (`lookPreviewView` reads them from the address, kept to the site's own paths). On the live site (`live: true`) it shows only the site as it is, with a note that the other looks show on the test site. New `wb-ui-look*` classes, each with its default style and a sample. The preview fonts are now each look's families in full, not only the latin letters, so a look previewed in another language shows its own letters. Additive only.
|
|
8
|
+
|
|
3
9
|
## 0.13.2
|
|
4
10
|
|
|
5
11
|
### Patch Changes
|
package/dist/cli.js
CHANGED
|
@@ -259,8 +259,9 @@ export function planStyles(dir, tools, uiVersion) {
|
|
|
259
259
|
problems.push(...theme.problems);
|
|
260
260
|
const fonts = projectFonts(theme.families);
|
|
261
261
|
const generated = renderStyles(tools, uiVersion, theme.css, fonts.css);
|
|
262
|
-
// Every look the project may
|
|
263
|
-
|
|
262
|
+
// Every look the project may choose, with each look's fonts in full (docs/look-studio.md §5.3): the previewer and
|
|
263
|
+
// design mode switch looks with no redeploy, and a project started in any look already holds its fonts.
|
|
264
|
+
const preview = projectFonts(previewFamilies(theme.library));
|
|
264
265
|
const fontFiles = [...fonts.files, ...preview.files.filter((p) => !fonts.files.some((f) => f.path === p.path))];
|
|
265
266
|
for (const f of fontFiles) {
|
|
266
267
|
const bytes = readFileSync(f.from);
|
package/dist/index.d.ts
CHANGED
|
@@ -6,6 +6,7 @@ export { FORM_SCRIPT } from "./form-script.ts";
|
|
|
6
6
|
export { chooseLayout, LAYOUT_BREAKPOINT, LAYOUT_KIT, layoutProblems, type LayoutRule, type ToolLayout, type ToolLayouts } from "./layouts.ts";
|
|
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
|
+
export { lookPreview, lookPreviewView, type LookPreviewOptions, type PreviewPage } from "./look-preview.ts";
|
|
9
10
|
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
11
|
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
12
|
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";
|
package/dist/index.js
CHANGED
|
@@ -11,6 +11,7 @@ export { FORM_SCRIPT } from "./form-script.js";
|
|
|
11
11
|
export { chooseLayout, LAYOUT_BREAKPOINT, LAYOUT_KIT, layoutProblems } from "./layouts.js";
|
|
12
12
|
export { classesIn, sampleProblems } from "./samples.js";
|
|
13
13
|
export { guideView, styleGuide } from "./style-guide.js";
|
|
14
|
+
export { lookPreview, lookPreviewView } from "./look-preview.js";
|
|
14
15
|
export { DEFAULT_THEME_CSS, renderStyles, STYLE_FILES, STYLED_SCOPE, styleNames, styleProblems, STYLESHEETS, starterProjectCss, unknownMarkupNames, unknownNames, } from "./styles.js";
|
|
15
16
|
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
17
|
export { findItem, itemProblems, LIBRARY, LIBRARY_KINDS, libraryOf, SITE_LAYOUT_CHOICES, usable, withProjectItems, } from "./library.js";
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { type Library } from "./library.ts";
|
|
2
|
+
import type { Scheme } from "./library.ts";
|
|
3
|
+
/** One of the project's pages the previewer can show. */
|
|
4
|
+
export interface PreviewPage {
|
|
5
|
+
path: string;
|
|
6
|
+
label: string;
|
|
7
|
+
}
|
|
8
|
+
export interface LookPreviewOptions {
|
|
9
|
+
/** The pages to choose between; the first is shown first. Paths only, on the project's own site. */
|
|
10
|
+
pages: readonly PreviewPage[];
|
|
11
|
+
/** The page and scheme asked for (`?page=` and `?scheme=`); see lookPreviewView. */
|
|
12
|
+
page?: string;
|
|
13
|
+
scheme?: Scheme;
|
|
14
|
+
/** The previewer's own address, read for `?page=` and `?scheme=` instead of page and scheme. */
|
|
15
|
+
url?: string | URL;
|
|
16
|
+
/**
|
|
17
|
+
* True on the live site, where a page shows only its own look (the frame
|
|
18
|
+
* reads ?wb-look= only outside production): just the site as it is, with a
|
|
19
|
+
* note that the other looks show on the test site.
|
|
20
|
+
*/
|
|
21
|
+
live?: boolean;
|
|
22
|
+
/** The project's own look, marked as the one in use. */
|
|
23
|
+
current?: string;
|
|
24
|
+
library?: Library;
|
|
25
|
+
/** The switch's and captions' words, in the page's language. */
|
|
26
|
+
words?: {
|
|
27
|
+
pages?: string;
|
|
28
|
+
schemes?: string;
|
|
29
|
+
light?: string;
|
|
30
|
+
dark?: string;
|
|
31
|
+
yours?: string;
|
|
32
|
+
inUse?: string;
|
|
33
|
+
open?: string;
|
|
34
|
+
live?: string;
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
/** The page and scheme a previewer address asks for, kept to the pages offered. */
|
|
38
|
+
export declare function lookPreviewView(url: string | URL, pages: readonly PreviewPage[]): {
|
|
39
|
+
page: string;
|
|
40
|
+
scheme: Scheme;
|
|
41
|
+
};
|
|
42
|
+
/** The previewer's HTML: a switch for the page and the scheme, then one framed page per look. */
|
|
43
|
+
export declare function lookPreview(o: LookPreviewOptions): string;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
// The look previewer's body (docs/look-studio.md §9.1): the project's own
|
|
2
|
+
// pages in every look it may choose, side by side, light or dark. Each page
|
|
3
|
+
// is the real one, drawn by the project's Worker with ?wb-look= and
|
|
4
|
+
// ?wb-scheme= (previewAttributes), so its words, pictures and tools are the
|
|
5
|
+
// project's own. The page around it is the workbench-site recipe /admin/look.
|
|
6
|
+
import { LIBRARY, usable } from "./library.js";
|
|
7
|
+
const esc = (s) => s.replace(/[&<>"']/g, (c) => `&#${c.charCodeAt(0)};`);
|
|
8
|
+
// A page path the previewer may frame: the site's own, never another site's or a script.
|
|
9
|
+
const SAFE_PATH = /^\/(?!\/)[A-Za-z0-9/_.~-]*$/;
|
|
10
|
+
/** The page and scheme a previewer address asks for, kept to the pages offered. */
|
|
11
|
+
export function lookPreviewView(url, pages) {
|
|
12
|
+
const q = new URL(url, "https://x.invalid").searchParams;
|
|
13
|
+
const own = pages.filter((p) => SAFE_PATH.test(p.path));
|
|
14
|
+
const page = own.find((p) => p.path === q.get("page"))?.path ?? own[0]?.path ?? "/";
|
|
15
|
+
return { page, scheme: q.get("scheme") === "dark" ? "dark" : "light" };
|
|
16
|
+
}
|
|
17
|
+
/** The previewer's HTML: a switch for the page and the scheme, then one framed page per look. */
|
|
18
|
+
export function lookPreview(o) {
|
|
19
|
+
const w = { pages: "Page", schemes: "Show", light: "Light", dark: "Dark", yours: "Your site now", inUse: "In use", open: "Open on its own", live: "The other looks show on your test site.", ...o.words };
|
|
20
|
+
const pages = o.pages.filter((p) => SAFE_PATH.test(p.path));
|
|
21
|
+
const asked = o.url !== undefined ? lookPreviewView(o.url, pages) : o;
|
|
22
|
+
const page = pages.find((p) => p.path === asked.page)?.path ?? pages[0]?.path ?? "/";
|
|
23
|
+
const scheme = asked.scheme === "dark" ? "dark" : "light";
|
|
24
|
+
const query = (p, s) => `?page=${encodeURIComponent(p)}&scheme=${s}`;
|
|
25
|
+
const pageSwitch = pages.length > 1 ? `<nav class="wb-ui-look-switch" aria-label="${esc(w.pages)}">${pages.map((p) => `<a class="wb-ui-look-choice" href="${query(p.path, scheme)}"${p.path === page ? ' aria-current="page"' : ""}>${esc(p.label)}</a>`).join("")}</nav>` : "";
|
|
26
|
+
const schemeSwitch = `<nav class="wb-ui-look-switch" aria-label="${esc(w.schemes)}">${["light", "dark"].map((s) => `<a class="wb-ui-look-choice" href="${query(page, s)}"${s === scheme ? ' aria-current="page"' : ""}>${esc(w[s])}</a>`).join("")}</nav>`;
|
|
27
|
+
const sep = page.includes("?") ? "&" : "?";
|
|
28
|
+
const figure = (title, about, src, inUse) => `<figure class="wb-ui-look"><figcaption class="wb-ui-look-caption"><span class="wb-ui-look-title">${esc(title)}</span>${inUse ? `<span class="wb-ui-look-in-use">${esc(w.inUse)}</span>` : ""}<span class="wb-ui-look-about">${esc(about)}</span></figcaption><iframe class="wb-ui-look-frame" src="${src}" title="${esc(title)}" loading="lazy" sandbox="allow-same-origin"></iframe><a class="wb-ui-look-open" href="${src}" target="_blank" rel="noopener">${esc(w.open)}</a></figure>`;
|
|
29
|
+
const looks = o.live ? [] : usable((o.library ?? LIBRARY).looks);
|
|
30
|
+
const figures = [
|
|
31
|
+
figure(w.yours, "", esc(page), false),
|
|
32
|
+
...looks.map((l) => figure(l.title, l.feel, `${esc(page)}${sep}wb-look=${esc(l.id)}&wb-scheme=${scheme}`, l.id === o.current)),
|
|
33
|
+
];
|
|
34
|
+
const live = o.live ? `<p class="wb-ui-look-live">${esc(w.live)}</p>` : "";
|
|
35
|
+
return `<div class="wb-ui-looks">${pageSwitch}${o.live ? "" : schemeSwitch}${live}<div class="wb-ui-look-grid">${figures.join("")}</div></div>`;
|
|
36
|
+
}
|
package/dist/ui-samples.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
// project's pages are built from, drawn by the parts themselves with made-up
|
|
3
3
|
// words. Exported at ./samples beside ./styles.
|
|
4
4
|
import { actions, body, button, card, check, chip, code, confirm, facts, field, input, jumpNav, message, more, note, pill, select, small, table, textarea, topBar } from "./index.js";
|
|
5
|
+
import { lookPreview } from "./look-preview.js";
|
|
5
6
|
import { styleGuide } from "./style-guide.js";
|
|
6
7
|
export const UI_SAMPLES = {
|
|
7
8
|
format: 1,
|
|
@@ -67,5 +68,12 @@ export const UI_SAMPLES = {
|
|
|
67
68
|
html: () => styleGuide([{ format: 1, package: "@mccaskie-labs/workbench-ui", title: "Page parts", prefix: "wb-ui-", samples: [{ id: "note", title: "A note", layout: "stacked", html: () => note("<p>A note.</p>") }] }]) +
|
|
68
69
|
styleGuide([], { view: "dark" }),
|
|
69
70
|
},
|
|
71
|
+
{
|
|
72
|
+
id: "look-preview",
|
|
73
|
+
title: "The look previewer, with its pages left blank, then as the live site shows it",
|
|
74
|
+
// The real one frames the site's own pages; here the frames are empty, so the style guide doesn't load the site inside itself.
|
|
75
|
+
html: () => lookPreview({ pages: [{ path: "/", label: "Home" }, { path: "/classes", label: "Classes" }], current: "calm" }).replace(/ src="[^"]*"/g, ' src="about:blank"').replace(/ href="\/[^"]*wb-look[^"]*"/g, ' href="#"') +
|
|
76
|
+
lookPreview({ pages: [{ path: "/", label: "Home" }], live: true }).replace(/ src="[^"]*"/g, ' src="about:blank"'),
|
|
77
|
+
},
|
|
70
78
|
],
|
|
71
79
|
};
|
package/dist/ui-styles.js
CHANGED
|
@@ -333,5 +333,24 @@ export const UI_STYLES = {
|
|
|
333
333
|
{ name: "wb-ui-guide-layout", element: "span", about: "The tool layout a sample shows", css: "font-weight:600" },
|
|
334
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
|
+
// The look previewer (docs/look-studio.md §9.1): the project's own pages in every look.
|
|
337
|
+
{ name: "wb-ui-looks", element: "div", about: "The look previewer: the site's pages in every look", css: "display:grid;gap:1rem" },
|
|
338
|
+
{ name: "wb-ui-look-switch", element: "nav", about: "A switch: which page, or light and dark", css: "display:flex;flex-wrap:wrap;gap:.5rem" },
|
|
339
|
+
{
|
|
340
|
+
name: "wb-ui-look-choice",
|
|
341
|
+
element: "a",
|
|
342
|
+
about: "One choice in a switch",
|
|
343
|
+
css: `padding:.3rem .8rem;border:1px solid ${v("line")};border-radius:999px;color:${v("text")};text-decoration:none`,
|
|
344
|
+
states: [{ selector: "[aria-current=page]", about: "The choice shown now", css: `background:${v("accent")};border-color:${v("accent")};color:${v("accent-text")}` }, { selector: ":focus-visible", about: "Has focus", css: FOCUS }],
|
|
345
|
+
},
|
|
346
|
+
{ name: "wb-ui-look-live", element: "p", about: "On the live site: where the other looks show", css: `margin:0;color:${v("muted")}` },
|
|
347
|
+
{ name: "wb-ui-look-grid", element: "div", about: "The looks side by side, as many as fit", css: "display:grid;grid-template-columns:repeat(auto-fill,minmax(min(100%,22rem),1fr));gap:1rem" },
|
|
348
|
+
{ name: "wb-ui-look", element: "figure", about: "One look: its name and the page drawn in it", css: `margin:0;display:grid;border:1px solid ${v("line")};border-radius:${v("corner")};overflow:hidden` },
|
|
349
|
+
{ name: "wb-ui-look-caption", element: "figcaption", about: "The look's name and feel", css: `display:flex;flex-wrap:wrap;gap:.25rem .5rem;align-items:baseline;padding:.5rem .9rem;border-bottom:1px solid ${v("line")}` },
|
|
350
|
+
{ name: "wb-ui-look-title", element: "span", about: "The look's name", css: "font-weight:700" },
|
|
351
|
+
{ name: "wb-ui-look-in-use", element: "span", about: "Marks the look the site uses now", css: `font-size:.8rem;padding:.05rem .5rem;border-radius:999px;background:${v("accent")};color:${v("accent-text")}` },
|
|
352
|
+
{ name: "wb-ui-look-about", element: "span", about: "How the look feels", css: `flex-basis:100%;font-size:.85rem;color:${v("muted")}` },
|
|
353
|
+
{ name: "wb-ui-look-frame", element: "iframe", about: "The page itself, in the look", css: "display:block;width:100%;height:26rem;border:0;background:#fff" },
|
|
354
|
+
{ name: "wb-ui-look-open", element: "a", about: "Opens the page in the look on its own", css: `padding:.5rem .9rem;font-size:.85rem;color:${v("accent")}`, states: [{ selector: ":focus-visible", about: "Has focus", css: FOCUS }] },
|
|
336
355
|
],
|
|
337
356
|
};
|
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.3",
|
|
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",
|