ShtukbaseStandard
página del paquete→ /design/style.html

pages/design/style.html

269 líneas, 15.7 KB. Abrir tal cual (en un proyecto hay otros archivos a su lado; aquí pueden faltar).

El archivo tal como está en el paquete: el código y sus comentarios no se traducen.

  1. <!--
  2. ---
  3. type: Lens
  4. title: "Style"
  5. icon: "🎨"
  6. 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."
  7. template: custom
  8. lensType: specimen
  9. sources: ["/design/design.md", "/design/<style>/tokens.json", "/design/<style>/tokens.dark.json", "/design/<style>/*.md"]
  10. generator: "shtuk run design-lenses build"
  11. ---
  12. The style specimen of `design-lenses`: the style chosen in /design/design.md, read from `lib/design/style.data.js`
  13. (`shtuk run design-lenses build`). One document column, every token in the page's theme; a click on a name copies it.
  14. -->
  15. <!doctype html>
  16. <html lang="en">
  17. <head>
  18. <meta charset="utf-8">
  19. <meta name="viewport" content="width=device-width, initial-scale=1">
  20. <title>Style</title>
  21. <link rel="stylesheet" href="../lib/kit.css">
  22. <script src="../lib/data.js"></script>
  23. <script src="../lib/design/style.data.js"></script>
  24. <script>
  25. // The chosen style's CSS (fonts, tokens) goes in before the kit's CSS: the kit's own skins keep their names, and the
  26. // skin "Shtukbase" (data-skin="shtukbase") reads the contract names from it, so the lens wears the chosen style.
  27. (function () {
  28. const S = window.SB_STYLE, kit = document.querySelector('link[href$="lib/kit.css"]');
  29. if (!S || !kit) return;
  30. const root = new URL("../", kit.href).href;
  31. for (const p of S.css || []) {
  32. const l = document.createElement("link");
  33. l.rel = "stylesheet"; l.href = root + p.replace(/^\//, ""); l.dataset.style = S.id;
  34. kit.before(l);
  35. }
  36. })();
  37. </script>
  38. <script src="../lib/kit.js"></script>
  39. <style>
  40. /* One white document column; separation by spacing and one hairline at most; no cards, no frames. The names below are
  41. the token contract's (the kit redefines only --card, --accent, --muted and --radius, which this page does not read). */
  42. .sp { --sp-fg: var(--foreground, #191919); --sp-mute: var(--muted-foreground, #6f6e69); --sp-line: var(--border, #e9e9e7);
  43. --sp-bg: var(--background, #fff); --sp-mono: var(--font-mono, ui-monospace, monospace);
  44. box-sizing: border-box; width: 100%; max-width: 880px; margin: 0 auto; padding: 56px 48px 120px; color: var(--sp-fg); }
  45. .sp *, .sp *::before, .sp *::after { box-sizing: border-box; }
  46. .sp-head h1 { margin: 0; font-size: 30px; line-height: 1.2; letter-spacing: -.015em; font-weight: 650; }
  47. .sp-head p { margin: 8px 0 0; color: var(--sp-mute); font-size: 14px; }
  48. .sp-head a { color: inherit; }
  49. .sp-sec { margin-top: 56px; scroll-margin-top: 24px; }
  50. .sp-sec > h2 { margin: 0; font-size: 18px; font-weight: 600; letter-spacing: -.005em; }
  51. .sp-sec > .sp-sub { margin: 4px 0 18px; color: var(--sp-mute); font-size: 13.5px; max-width: 640px; }
  52. .sp-warn { margin: 16px 0 0; color: var(--destructive, #e85339); font-size: 13.5px; }
  53. .sp-empty { color: var(--sp-mute); font-size: 13.5px; }
  54. /* a token row: swatch, name, value, what it is for */
  55. .sp-rows { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); column-gap: 40px; }
  56. .sp-row { display: grid; grid-template-columns: 32px minmax(0, 1fr); column-gap: 14px; align-items: start; padding: 10px 0; }
  57. .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); }
  58. .sp-txt { min-width: 0; display: flex; flex-direction: column; gap: 2px; }
  59. .sp-line1 { display: flex; align-items: baseline; gap: 10px; min-width: 0; }
  60. .sp-name { font: 500 12.5px/1.4 var(--sp-mono); cursor: copy; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
  61. .sp-name:hover { text-decoration: underline; text-underline-offset: 3px; text-decoration-color: var(--sp-line); }
  62. .sp-name.copied::after { content: " copied"; color: var(--sp-mute); font-weight: 400; }
  63. .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; }
  64. .sp-desc { font-size: 12.5px; line-height: 1.4; color: var(--sp-mute); overflow-wrap: anywhere; }
  65. /* hues: a table of the steps */
  66. .sp-hues { display: grid; grid-template-columns: 120px repeat(var(--n, 4), minmax(0, 72px)); gap: 6px 10px; align-items: center; }
  67. .sp-hues .hd { font-size: 12px; color: var(--sp-mute); }
  68. .sp-hues .hn { font-size: 13.5px; text-transform: capitalize; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  69. .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); }
  70. .sp-hues .c.copied { outline: 2px solid var(--sp-fg); outline-offset: 1px; }
  71. /* type */
  72. .sp-type { display: flex; flex-direction: column; }
  73. .sp-type > div { padding: 14px 0; }
  74. .sp-type > div + div { border-top: 1px solid var(--sp-line); }
  75. .sp-sample { font-size: 28px; line-height: 1.25; letter-spacing: -.01em; overflow-wrap: anywhere; margin-bottom: 6px; }
  76. /* tiles: radii, shadows, edges, motion */
  77. .sp-tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 32px 28px; }
  78. .sp-tile { min-width: 0; display: flex; flex-direction: column; gap: 10px; }
  79. .sp-tile .sp-val { margin-left: 0; max-width: 100%; }
  80. .sp-demo { height: 84px; border-radius: 10px; background: var(--sp-bg); }
  81. .sp-demo.radius { width: 84px; height: 84px; background: color-mix(in srgb, var(--sp-fg) 6%, var(--sp-bg)); }
  82. .sp-demo.motion { position: relative; background: color-mix(in srgb, var(--sp-fg) 4%, var(--sp-bg)); overflow: hidden; }
  83. .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); }
  84. .sp-tile:hover .sp-demo.motion i { left: calc(100% - 26px); }
  85. /* pictures */
  86. .sp-assets { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 20px 16px; }
  87. .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; }
  88. .sp-asset img { width: 48px; height: 48px; object-fit: contain; }
  89. .sp-asset span { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  90. .sp-asset:hover { color: var(--sp-fg); }
  91. /* the style's own pages, in the flow of the document */
  92. .sp-page .lx-md { max-width: 680px; }
  93. .sp-src { font: 12px var(--sp-mono); color: var(--sp-mute); }
  94. /* the contents in the right panel */
  95. .sp-toc { display: flex; flex-direction: column; margin: 0 -8px; }
  96. .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; }
  97. .sp-toc a span { margin-left: auto; font-size: 12px; opacity: .55; font-variant-numeric: tabular-nums; }
  98. .sp-toc a b { font-weight: 400; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
  99. .sp-toc a:hover { background: color-mix(in srgb, currentColor 6%, transparent); }
  100. @media (max-width: 900px) { .sp { padding: 32px 24px 80px; } .sp-rows { grid-template-columns: minmax(0, 1fr); } }
  101. </style>
  102. <script>
  103. (function () {
  104. const { h } = Lens;
  105. const GROUP_NOTES = {
  106. Colors: "The theme names: surfaces and the text on them.",
  107. Charts: "The five chart colours, in order.",
  108. Sidebar: "The sidebar's own surfaces.",
  109. Hues: "The palette: each hue and its steps.",
  110. Type: "Font families.",
  111. Spacing: "Spacing and sizes.",
  112. Radii: "Corner radii.",
  113. Shadows: "Shadows, from a card's edge to a sheet.",
  114. "Glows and edges": "The card's edge and the rim of the Basic card.",
  115. Motion: "Durations and easings: hover a tile to play it.",
  116. Other: "Tokens of no known group.",
  117. };
  118. const slug = (s) => s.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-|-$/g, "");
  119. const href = (p) => Lens.rootHref + String(p).replace(/^\//, "");
  120. const dark = () => document.documentElement.dataset.theme === "dark";
  121. const val = (t) => (dark() ? t.dark : t.light);
  122. // The build writes some dark shadows without commas between the layers; a layer starts with a length after a ")".
  123. const shadow = (v) => String(v).replace(/\)\s+(?=-?\d)/g, "), ");
  124. function copy(el, text) {
  125. const done = () => { el.classList.add("copied"); setTimeout(() => el.classList.remove("copied"), 900); };
  126. if (navigator.clipboard) navigator.clipboard.writeText(text).then(done, done); else done();
  127. }
  128. function nameEl(t) {
  129. const el = h("span", { class: "sp-name", title: "Copy var(" + t.name + ")" }, t.name);
  130. el.addEventListener("click", () => copy(el, "var(" + t.name + ")"));
  131. return el;
  132. }
  133. const text = (t, extra) => h("div", { class: "sp-txt" },
  134. h("div", { class: "sp-line1" }, nameEl(t), extra === false ? null : h("span", { class: "sp-val", title: String(val(t)) }, String(val(t)))),
  135. t.description ? h("div", { class: "sp-desc" }, t.description) : null);
  136. function colorRow(t) {
  137. return h("div", { class: "sp-row sp-tok", "data-name": t.name }, h("div", { class: "sp-sw", style: "background:" + val(t) }), text(t));
  138. }
  139. function tile(t, demo) {
  140. return h("div", { class: "sp-tile sp-tok", "data-name": t.name }, demo,
  141. h("div", { class: "sp-txt" }, nameEl(t), h("span", { class: "sp-val", title: String(val(t)) }, String(val(t))),
  142. t.description ? h("div", { class: "sp-desc" }, t.description) : null));
  143. }
  144. function hueTable(tokens) {
  145. // --sb-hue-<n> is a hue, --sb-hue-<n>-<step> its steps; the description of the base names it.
  146. const hues = [], steps = [];
  147. for (const t of tokens) {
  148. const m = /^--[\w-]*?hue-(\d+)(?:-([a-z]+))?$/.exec(t.name);
  149. if (!m) continue;
  150. let hu = hues.find((x) => x.n === m[1]);
  151. if (!hu) hues.push((hu = { n: m[1], name: "", steps: {} }));
  152. const step = m[2] || "base";
  153. if (!steps.includes(step)) steps.push(step);
  154. hu.steps[step] = t;
  155. if (!m[2]) hu.name = t.description || "hue " + m[1];
  156. }
  157. if (!hues.length) return null;
  158. const cells = [h("span", { class: "hd" }, "")].concat(steps.map((s) => h("span", { class: "hd" }, s)));
  159. for (const hu of hues) {
  160. cells.push(h("span", { class: "hn", title: hu.name }, hu.name));
  161. for (const s of steps) {
  162. const t = hu.steps[s];
  163. if (!t) { cells.push(h("span", {})); continue; }
  164. 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) });
  165. c.addEventListener("click", () => copy(c, "var(" + t.name + ")"));
  166. cells.push(c);
  167. }
  168. }
  169. return h("div", { class: "sp-hues", style: "--n:" + steps.length }, cells);
  170. }
  171. function groupBody(g) {
  172. const t0 = g.tokens[0] || {};
  173. if (g.title === "Hues") { const tb = hueTable(g.tokens); if (tb) return tb; }
  174. if (g.tokens.every((t) => t.type === "color")) return h("div", { class: "sp-rows" }, g.tokens.map(colorRow));
  175. if (t0.type === "fontFamily" || g.title === "Type") {
  176. return h("div", { class: "sp-type" }, g.tokens.map((t) => h("div", { class: "sp-tok", "data-name": t.name },
  177. h("div", { class: "sp-sample", style: "font-family:" + val(t) }, "The quick brown fox jumps over 0123"), text(t))));
  178. }
  179. return h("div", { class: "sp-tiles" }, g.tokens.map((t) => {
  180. const v = String(val(t));
  181. if (t.type === "shadow") return tile(t, h("div", { class: "sp-demo", style: "box-shadow:" + shadow(v) }));
  182. if (t.type === "dimension" && /radius/.test(t.name)) return tile(t, h("div", { class: "sp-demo radius", style: "border-radius:" + v }));
  183. if (t.type === "duration") return tile(t, h("div", { class: "sp-demo motion", style: "--t-dur:" + v }, h("i")));
  184. if (t.type === "cubicBezier") return tile(t, h("div", { class: "sp-demo motion", style: "--t-ease:" + v + ";--t-dur:.6s" }, h("i")));
  185. if (t.type === "color") return tile(t, h("div", { class: "sp-demo", style: "background:" + v }));
  186. return tile(t, null);
  187. }));
  188. }
  189. Lens.templates.custom = function (cfg) {
  190. const ui = Lens.page(cfg);
  191. const S = window.SB_STYLE;
  192. if (!S) {
  193. 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")));
  194. return;
  195. }
  196. const groups = [];
  197. for (const t of S.tokens) {
  198. let g = groups.find((x) => x.title === t.group);
  199. if (!g) groups.push((g = { title: t.group, tokens: [] }));
  200. g.tokens.push(t);
  201. }
  202. const page = h("div", { class: "sp" });
  203. function draw() {
  204. page.replaceChildren(h("header", { class: "sp-head" }, h("h1", {}, S.title),
  205. h("p", {}, S.tokens.length + " tokens in " + groups.length + " groups · chosen in ", h("a", { href: href("/design/design.md") }, "design.md"))));
  206. for (const p of S.problems || []) page.append(h("p", { class: "sp-warn" }, p));
  207. for (const g of groups) {
  208. page.append(h("section", { class: "sp-sec", id: "g-" + slug(g.title) },
  209. h("h2", {}, g.title), h("p", { class: "sp-sub" }, GROUP_NOTES[g.title] || ""), groupBody(g)));
  210. }
  211. if (S.assets && S.assets.length) {
  212. page.append(h("section", { class: "sp-sec", id: "g-pictures" }, h("h2", {}, "Pictures"),
  213. h("p", { class: "sp-sub" }, "The mark and the icons of the style."),
  214. 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$/, "")))))));
  215. }
  216. for (const b of pageBoxes) page.append(b.box);
  217. }
  218. const pageBoxes = S.sections.map((s) => {
  219. const body = h("div", { class: "lx-md" }, h("p", { class: "sp-empty" }, "Loading…"));
  220. const box = h("section", { class: "sp-sec sp-page", id: "p-" + slug(s.title) }, h("h2", {}, s.title),
  221. h("p", { class: "sp-sub" }, h("a", { class: "sp-src", href: href(s.page) }, s.page.split("/").pop())), body);
  222. return { s, body, box };
  223. });
  224. if (pageBoxes.length) {
  225. Lens.loadBodies((ok) => {
  226. for (const { s, body } of pageBoxes) {
  227. const r = Lens.rec(s.page);
  228. body.replaceChildren();
  229. if (ok && r && r.body) body.append(Lens.wire(h("div", { html: Lens.md(r.body.replace(/^#\s+.*\n+/, ""), s.page) })));
  230. else body.append(h("p", { class: "sp-empty" }, "The page text is not built: run shtuk run lenses build."));
  231. }
  232. });
  233. }
  234. draw();
  235. ui.main.append(page);
  236. // The values follow the page's theme.
  237. new MutationObserver(draw).observe(document.documentElement, { attributes: true, attributeFilter: ["data-theme"] });
  238. // The right panel: the contents of the page, and the other installed styles.
  239. const go = (id) => (e) => { e.preventDefault(); const el = document.getElementById(id); if (el) el.scrollIntoView({ block: "start", behavior: "smooth" }); };
  240. const entry = (id, title, n) => h("a", { href: "#" + id, onclick: go(id) }, h("b", {}, title), n == null ? null : h("span", {}, String(n)));
  241. ui.section("Contents", h("nav", { class: "sp-toc" },
  242. groups.map((g) => entry("g-" + slug(g.title), g.title, g.tokens.length)),
  243. S.assets && S.assets.length ? entry("g-pictures", "Pictures", S.assets.length) : null,
  244. S.sections.map((s) => entry("p-" + slug(s.title), s.title))));
  245. if (S.styles && S.styles.length > 1) {
  246. ui.section("Installed styles", h("div", { class: "lx-md small" }, h("p", {}, "Choose one in /design/design.md (style: <id>), then rebuild."),
  247. h("ul", {}, S.styles.map((x) => h("li", {}, h("code", {}, x.id), x.id === S.id ? " — chosen" : "")))));
  248. }
  249. Lens.on("search", (q) => {
  250. document.querySelectorAll(".sp-tok").forEach((el) => { el.style.visibility = !q || el.dataset.name.includes(q) ? "" : "hidden"; });
  251. });
  252. };
  253. })();
  254. </script>
  255. </head>
  256. <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>
  257. </html>