包页面→ /design/style.html
pages/design/style.html
269 行, 15.7 KB. 直接打开 (在项目中它旁边还有其他文件,这里可能缺失).
文件按包中的原样显示:代码及其注释不做翻译。
- <!--
- ---
- type: Lens
- title: "Style"
- icon: "🎨"
- description: "The project's chosen style as a calm specimen: every token by group in the page's theme, with its name and value; the style's pictures and its own pages."
- template: custom
- lensType: specimen
- sources: ["/design/design.md", "/design/<style>/tokens.json", "/design/<style>/tokens.dark.json", "/design/<style>/*.md"]
- generator: "shtuk run design-lenses build"
- ---
- The style specimen of `design-lenses`: the style chosen in /design/design.md, read from `lib/design/style.data.js`
- (`shtuk run design-lenses build`). One document column, every token in the page's theme; a click on a name copies it.
- -->
- <!doctype html>
- <html lang="en">
- <head>
- <meta charset="utf-8">
- <meta name="viewport" content="width=device-width, initial-scale=1">
- <title>Style</title>
- <link rel="stylesheet" href="../lib/kit.css">
- <script src="../lib/data.js"></script>
- <script src="../lib/design/style.data.js"></script>
- <script>
- // The chosen style's CSS (fonts, tokens) goes in before the kit's CSS: the kit's own skins keep their names, and the
- // skin "Shtukbase" (data-skin="shtukbase") reads the contract names from it, so the lens wears the chosen style.
- (function () {
- const S = window.SB_STYLE, kit = document.querySelector('link[href$="lib/kit.css"]');
- if (!S || !kit) return;
- const root = new URL("../", kit.href).href;
- for (const p of S.css || []) {
- const l = document.createElement("link");
- l.rel = "stylesheet"; l.href = root + p.replace(/^\//, ""); l.dataset.style = S.id;
- kit.before(l);
- }
- })();
- </script>
- <script src="../lib/kit.js"></script>
- <style>
- /* One white document column; separation by spacing and one hairline at most; no cards, no frames. The names below are
- the token contract's (the kit redefines only --card, --accent, --muted and --radius, which this page does not read). */
- .sp { --sp-fg: var(--foreground, #191919); --sp-mute: var(--muted-foreground, #6f6e69); --sp-line: var(--border, #e9e9e7);
- --sp-bg: var(--background, #fff); --sp-mono: var(--font-mono, ui-monospace, monospace);
- box-sizing: border-box; width: 100%; max-width: 880px; margin: 0 auto; padding: 56px 48px 120px; color: var(--sp-fg); }
- .sp *, .sp *::before, .sp *::after { box-sizing: border-box; }
- .sp-head h1 { margin: 0; font-size: 30px; line-height: 1.2; letter-spacing: -.015em; font-weight: 650; }
- .sp-head p { margin: 8px 0 0; color: var(--sp-mute); font-size: 14px; }
- .sp-head a { color: inherit; }
- .sp-sec { margin-top: 56px; scroll-margin-top: 24px; }
- .sp-sec > h2 { margin: 0; font-size: 18px; font-weight: 600; letter-spacing: -.005em; }
- .sp-sec > .sp-sub { margin: 4px 0 18px; color: var(--sp-mute); font-size: 13.5px; max-width: 640px; }
- .sp-warn { margin: 16px 0 0; color: var(--destructive, #e85339); font-size: 13.5px; }
- .sp-empty { color: var(--sp-mute); font-size: 13.5px; }
- /* a token row: swatch, name, value, what it is for */
- .sp-rows { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); column-gap: 40px; }
- .sp-row { display: grid; grid-template-columns: 32px minmax(0, 1fr); column-gap: 14px; align-items: start; padding: 10px 0; }
- .sp-sw { width: 32px; height: 32px; border-radius: 8px; box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--sp-fg) 10%, transparent); }
- .sp-txt { min-width: 0; display: flex; flex-direction: column; gap: 2px; }
- .sp-line1 { display: flex; align-items: baseline; gap: 10px; min-width: 0; }
- .sp-name { font: 500 12.5px/1.4 var(--sp-mono); cursor: copy; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
- .sp-name:hover { text-decoration: underline; text-underline-offset: 3px; text-decoration-color: var(--sp-line); }
- .sp-name.copied::after { content: " copied"; color: var(--sp-mute); font-weight: 400; }
- .sp-val { margin-left: auto; flex: none; font: 12px/1.4 var(--sp-mono); color: var(--sp-mute); max-width: 50%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
- .sp-desc { font-size: 12.5px; line-height: 1.4; color: var(--sp-mute); overflow-wrap: anywhere; }
- /* hues: a table of the steps */
- .sp-hues { display: grid; grid-template-columns: 120px repeat(var(--n, 4), minmax(0, 72px)); gap: 6px 10px; align-items: center; }
- .sp-hues .hd { font-size: 12px; color: var(--sp-mute); }
- .sp-hues .hn { font-size: 13.5px; text-transform: capitalize; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
- .sp-hues .c { height: 28px; border-radius: 6px; cursor: copy; box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--sp-fg) 8%, transparent); }
- .sp-hues .c.copied { outline: 2px solid var(--sp-fg); outline-offset: 1px; }
- /* type */
- .sp-type { display: flex; flex-direction: column; }
- .sp-type > div { padding: 14px 0; }
- .sp-type > div + div { border-top: 1px solid var(--sp-line); }
- .sp-sample { font-size: 28px; line-height: 1.25; letter-spacing: -.01em; overflow-wrap: anywhere; margin-bottom: 6px; }
- /* tiles: radii, shadows, edges, motion */
- .sp-tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 32px 28px; }
- .sp-tile { min-width: 0; display: flex; flex-direction: column; gap: 10px; }
- .sp-tile .sp-val { margin-left: 0; max-width: 100%; }
- .sp-demo { height: 84px; border-radius: 10px; background: var(--sp-bg); }
- .sp-demo.radius { width: 84px; height: 84px; background: color-mix(in srgb, var(--sp-fg) 6%, var(--sp-bg)); }
- .sp-demo.motion { position: relative; background: color-mix(in srgb, var(--sp-fg) 4%, var(--sp-bg)); overflow: hidden; }
- .sp-demo.motion i { position: absolute; left: 12px; top: 50%; width: 14px; height: 14px; margin-top: -7px; border-radius: 50%; background: var(--primary, #e04a72); transition: left var(--t-dur, .3s) var(--t-ease, ease); }
- .sp-tile:hover .sp-demo.motion i { left: calc(100% - 26px); }
- /* pictures */
- .sp-assets { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 20px 16px; }
- .sp-asset { display: flex; flex-direction: column; align-items: center; gap: 8px; text-decoration: none; color: var(--sp-mute); font-size: 11.5px; min-width: 0; }
- .sp-asset img { width: 48px; height: 48px; object-fit: contain; }
- .sp-asset span { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
- .sp-asset:hover { color: var(--sp-fg); }
- /* the style's own pages, in the flow of the document */
- .sp-page .lx-md { max-width: 680px; }
- .sp-src { font: 12px var(--sp-mono); color: var(--sp-mute); }
- /* the contents in the right panel */
- .sp-toc { display: flex; flex-direction: column; margin: 0 -8px; }
- .sp-toc a { display: flex; gap: 8px; align-items: baseline; padding: 5px 8px; border-radius: 6px; color: inherit; text-decoration: none; font-size: 13.5px; }
- .sp-toc a span { margin-left: auto; font-size: 12px; opacity: .55; font-variant-numeric: tabular-nums; }
- .sp-toc a b { font-weight: 400; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
- .sp-toc a:hover { background: color-mix(in srgb, currentColor 6%, transparent); }
- @media (max-width: 900px) { .sp { padding: 32px 24px 80px; } .sp-rows { grid-template-columns: minmax(0, 1fr); } }
- </style>
- <script>
- (function () {
- const { h } = Lens;
- const GROUP_NOTES = {
- Colors: "The theme names: surfaces and the text on them.",
- Charts: "The five chart colours, in order.",
- Sidebar: "The sidebar's own surfaces.",
- Hues: "The palette: each hue and its steps.",
- Type: "Font families.",
- Spacing: "Spacing and sizes.",
- Radii: "Corner radii.",
- Shadows: "Shadows, from a card's edge to a sheet.",
- "Glows and edges": "The card's edge and the rim of the Basic card.",
- Motion: "Durations and easings: hover a tile to play it.",
- Other: "Tokens of no known group.",
- };
- const slug = (s) => s.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-|-$/g, "");
- const href = (p) => Lens.rootHref + String(p).replace(/^\//, "");
- const dark = () => document.documentElement.dataset.theme === "dark";
- const val = (t) => (dark() ? t.dark : t.light);
- // The build writes some dark shadows without commas between the layers; a layer starts with a length after a ")".
- const shadow = (v) => String(v).replace(/\)\s+(?=-?\d)/g, "), ");
- function copy(el, text) {
- const done = () => { el.classList.add("copied"); setTimeout(() => el.classList.remove("copied"), 900); };
- if (navigator.clipboard) navigator.clipboard.writeText(text).then(done, done); else done();
- }
- function nameEl(t) {
- const el = h("span", { class: "sp-name", title: "Copy var(" + t.name + ")" }, t.name);
- el.addEventListener("click", () => copy(el, "var(" + t.name + ")"));
- return el;
- }
- const text = (t, extra) => h("div", { class: "sp-txt" },
- h("div", { class: "sp-line1" }, nameEl(t), extra === false ? null : h("span", { class: "sp-val", title: String(val(t)) }, String(val(t)))),
- t.description ? h("div", { class: "sp-desc" }, t.description) : null);
- function colorRow(t) {
- return h("div", { class: "sp-row sp-tok", "data-name": t.name }, h("div", { class: "sp-sw", style: "background:" + val(t) }), text(t));
- }
- function tile(t, demo) {
- return h("div", { class: "sp-tile sp-tok", "data-name": t.name }, demo,
- h("div", { class: "sp-txt" }, nameEl(t), h("span", { class: "sp-val", title: String(val(t)) }, String(val(t))),
- t.description ? h("div", { class: "sp-desc" }, t.description) : null));
- }
- function hueTable(tokens) {
- // --sb-hue-<n> is a hue, --sb-hue-<n>-<step> its steps; the description of the base names it.
- const hues = [], steps = [];
- for (const t of tokens) {
- const m = /^--[\w-]*?hue-(\d+)(?:-([a-z]+))?$/.exec(t.name);
- if (!m) continue;
- let hu = hues.find((x) => x.n === m[1]);
- if (!hu) hues.push((hu = { n: m[1], name: "", steps: {} }));
- const step = m[2] || "base";
- if (!steps.includes(step)) steps.push(step);
- hu.steps[step] = t;
- if (!m[2]) hu.name = t.description || "hue " + m[1];
- }
- if (!hues.length) return null;
- const cells = [h("span", { class: "hd" }, "")].concat(steps.map((s) => h("span", { class: "hd" }, s)));
- for (const hu of hues) {
- cells.push(h("span", { class: "hn", title: hu.name }, hu.name));
- for (const s of steps) {
- const t = hu.steps[s];
- if (!t) { cells.push(h("span", {})); continue; }
- const c = h("span", { class: "c sp-tok", "data-name": t.name, title: t.name + " " + val(t) + (t.description ? "\n" + t.description : ""), style: "background:" + val(t) });
- c.addEventListener("click", () => copy(c, "var(" + t.name + ")"));
- cells.push(c);
- }
- }
- return h("div", { class: "sp-hues", style: "--n:" + steps.length }, cells);
- }
- function groupBody(g) {
- const t0 = g.tokens[0] || {};
- if (g.title === "Hues") { const tb = hueTable(g.tokens); if (tb) return tb; }
- if (g.tokens.every((t) => t.type === "color")) return h("div", { class: "sp-rows" }, g.tokens.map(colorRow));
- if (t0.type === "fontFamily" || g.title === "Type") {
- return h("div", { class: "sp-type" }, g.tokens.map((t) => h("div", { class: "sp-tok", "data-name": t.name },
- h("div", { class: "sp-sample", style: "font-family:" + val(t) }, "The quick brown fox jumps over 0123"), text(t))));
- }
- return h("div", { class: "sp-tiles" }, g.tokens.map((t) => {
- const v = String(val(t));
- if (t.type === "shadow") return tile(t, h("div", { class: "sp-demo", style: "box-shadow:" + shadow(v) }));
- if (t.type === "dimension" && /radius/.test(t.name)) return tile(t, h("div", { class: "sp-demo radius", style: "border-radius:" + v }));
- if (t.type === "duration") return tile(t, h("div", { class: "sp-demo motion", style: "--t-dur:" + v }, h("i")));
- if (t.type === "cubicBezier") return tile(t, h("div", { class: "sp-demo motion", style: "--t-ease:" + v + ";--t-dur:.6s" }, h("i")));
- if (t.type === "color") return tile(t, h("div", { class: "sp-demo", style: "background:" + v }));
- return tile(t, null);
- }));
- }
- Lens.templates.custom = function (cfg) {
- const ui = Lens.page(cfg);
- const S = window.SB_STYLE;
- if (!S) {
- ui.main.append(h("div", { class: "sp" }, h("p", { class: "sp-warn" }, "There is no style data. Build it from the project root: shtuk run design-lenses build")));
- return;
- }
- const groups = [];
- for (const t of S.tokens) {
- let g = groups.find((x) => x.title === t.group);
- if (!g) groups.push((g = { title: t.group, tokens: [] }));
- g.tokens.push(t);
- }
- const page = h("div", { class: "sp" });
- function draw() {
- page.replaceChildren(h("header", { class: "sp-head" }, h("h1", {}, S.title),
- h("p", {}, S.tokens.length + " tokens in " + groups.length + " groups · chosen in ", h("a", { href: href("/design/design.md") }, "design.md"))));
- for (const p of S.problems || []) page.append(h("p", { class: "sp-warn" }, p));
- for (const g of groups) {
- page.append(h("section", { class: "sp-sec", id: "g-" + slug(g.title) },
- h("h2", {}, g.title), h("p", { class: "sp-sub" }, GROUP_NOTES[g.title] || ""), groupBody(g)));
- }
- if (S.assets && S.assets.length) {
- page.append(h("section", { class: "sp-sec", id: "g-pictures" }, h("h2", {}, "Pictures"),
- h("p", { class: "sp-sub" }, "The mark and the icons of the style."),
- h("div", { class: "sp-assets" }, S.assets.map((a) => h("a", { class: "sp-asset", href: href(a), title: a }, h("img", { src: href(a), alt: "" }), h("span", {}, a.split("/").pop().replace(/\.svg$/, "")))))));
- }
- for (const b of pageBoxes) page.append(b.box);
- }
- const pageBoxes = S.sections.map((s) => {
- const body = h("div", { class: "lx-md" }, h("p", { class: "sp-empty" }, "Loading…"));
- const box = h("section", { class: "sp-sec sp-page", id: "p-" + slug(s.title) }, h("h2", {}, s.title),
- h("p", { class: "sp-sub" }, h("a", { class: "sp-src", href: href(s.page) }, s.page.split("/").pop())), body);
- return { s, body, box };
- });
- if (pageBoxes.length) {
- Lens.loadBodies((ok) => {
- for (const { s, body } of pageBoxes) {
- const r = Lens.rec(s.page);
- body.replaceChildren();
- if (ok && r && r.body) body.append(Lens.wire(h("div", { html: Lens.md(r.body.replace(/^#\s+.*\n+/, ""), s.page) })));
- else body.append(h("p", { class: "sp-empty" }, "The page text is not built: run shtuk run lenses build."));
- }
- });
- }
- draw();
- ui.main.append(page);
- // The values follow the page's theme.
- new MutationObserver(draw).observe(document.documentElement, { attributes: true, attributeFilter: ["data-theme"] });
- // The right panel: the contents of the page, and the other installed styles.
- const go = (id) => (e) => { e.preventDefault(); const el = document.getElementById(id); if (el) el.scrollIntoView({ block: "start", behavior: "smooth" }); };
- const entry = (id, title, n) => h("a", { href: "#" + id, onclick: go(id) }, h("b", {}, title), n == null ? null : h("span", {}, String(n)));
- ui.section("Contents", h("nav", { class: "sp-toc" },
- groups.map((g) => entry("g-" + slug(g.title), g.title, g.tokens.length)),
- S.assets && S.assets.length ? entry("g-pictures", "Pictures", S.assets.length) : null,
- S.sections.map((s) => entry("p-" + slug(s.title), s.title))));
- if (S.styles && S.styles.length > 1) {
- ui.section("Installed styles", h("div", { class: "lx-md small" }, h("p", {}, "Choose one in /design/design.md (style: <id>), then rebuild."),
- h("ul", {}, S.styles.map((x) => h("li", {}, h("code", {}, x.id), x.id === S.id ? " — chosen" : "")))));
- }
- Lens.on("search", (q) => {
- document.querySelectorAll(".sp-tok").forEach((el) => { el.style.visibility = !q || el.dataset.name.includes(q) ? "" : "hidden"; });
- });
- };
- })();
- </script>
- </head>
- <body><p class="lx-missing">The lens "Style". There is no data yet: build it from the project root with <code>shtuk run lenses build</code> and <code>shtuk run design-lenses build</code>.</p></body>
- </html>