Design/ds.ts builds the design-system artifact folder from tokens.toml, parts.css, parts.js
Browse files at this commitf6fdcc18ed8fa265183f97d210588332abbbae66Parent: a44860b- feat
- design/ds.ts builds the design-system artifact folder from tokens.toml, parts.css, parts.js
1 changed file +70 -0
- crates/client/design/ds.ts +70 -0
crates/client/design/ds.tsadded+70 -0
| @@ -0,0 +1,70 @@ | |||
| 1 | +import tokens from "./tokens.toml"; | ||
| 2 | +import { mkdirSync, copyFileSync } from "node:fs"; | ||
| 3 | + | ||
| 4 | +const out = process.argv[2] + "/project/"; | ||
| 5 | +const put = (path: string, text: string) => Bun.write(out + path, text); | ||
| 6 | +const px = (v: number) => `${v}px`; | ||
| 7 | +const themes = Object.keys(tokens.theme); | ||
| 8 | +const NOTES: Record<string, string> = { | ||
| 9 | + ground: "The ink everything sits on. Page and panels.", | ||
| 10 | + raise: "Popovers and sheets lifted off the ground.", | ||
| 11 | + hov: "Hover under a control.", | ||
| 12 | + press: "Pressed or on control behind an icon.", | ||
| 13 | + thread: "Lines that separate: rows, popover edge, empty track.", | ||
| 14 | + off: "A quiet voice line: present, not speaking.", | ||
| 15 | + faint: "Section labels, idle chevrons, off toggles.", | ||
| 16 | + dim: "Secondary text and idle icons.", | ||
| 17 | + paper: "Text and primary marks.", | ||
| 18 | + bad: "A frayed line: loss, lag, danger. Only past a threshold.", | ||
| 19 | +}; | ||
| 20 | +const colors = Object.keys(NOTES).map(name => ({ name, value: Object.fromEntries(themes.map(t => [t, tokens.theme[t][name]])), usage: NOTES[name] })); | ||
| 21 | +const hues = (tokens.hues as string[]).map((hue, i) => ({ name: `h-${hue}`, value: Object.fromEntries(themes.map(t => [t, tokens.theme[t].hue[i]])), usage: `A person's line and name when they pick ${hue}. Life, never chrome.` })); | ||
| 22 | +const list = (scale: string, unit: (v: number) => string) => ({ tokens: Object.entries(tokens[scale]).map(([name, value]) => ({ name: `${scale}-${name}`, value: unit(value as number), usage: `tokens.toml [${scale}] ${name}` })) }); | ||
| 23 | +const weights = [["Regular", 400], ["Medium", 500], ["SemiBold", 600], ["Bold", 700]] as const; | ||
| 24 | +const styles = Object.entries(tokens.text).map(([name, size]) => ({ name: `t-${name}`, fontSize: px(size as number), lineHeight: tokens.leading.text, fontWeight: name === "title" || name === "display" ? 600 : 400 })); | ||
| 25 | +const json = { | ||
| 26 | + name: "yumuş", version: 1, | ||
| 27 | + color: { themes: themes.map(id => ({ id, name: id === "gece" ? "Gece" : "Gün" })), tokens: [...colors, ...hues] }, | ||
| 28 | + type: { | ||
| 29 | + fonts: weights.map(([file, weight]) => ({ family: "Onest", file: `fonts/Onest-${file}.ttf`, weight: String(weight) })), | ||
| 30 | + families: { sans: "Onest, sans-serif" }, | ||
| 31 | + groups: [{ name: "Text", family: "sans", styles }], | ||
| 32 | + }, | ||
| 33 | + spacing: list("space", px), radius: list("radius", px), | ||
| 34 | + stroke: list("stroke", px), text: list("text", px), size: list("size", px), leading: list("leading", String), | ||
| 35 | +}; | ||
| 36 | +await put("tokens.json", JSON.stringify(json, null, 2)); | ||
| 37 | +await put("tokens.css", "/* yumuş — generated from tokens.json */\n" + await Bun.file(new URL("./tokens.css", import.meta.url)).text() | ||
| 38 | + + weights.map(([file, weight]) => `@font-face{font-family:Onest;font-weight:${weight};src:url(fonts/Onest-${file}.ttf)}`).join("\n") + "\n"); | ||
| 39 | +await put("components/bundle.css", await Bun.file(new URL("./parts.css", import.meta.url)).text()); | ||
| 40 | +await put("components/bundle.js", `/* @ds-bundle: {"format":4,"namespace":"Yumush","components":[]} */\n` + await Bun.file(new URL("./parts.js", import.meta.url)).text()); | ||
| 41 | +mkdirSync(out + "fonts", { recursive: true }); | ||
| 42 | +for (const [file] of weights) copyFileSync(new URL(`../assets/fonts/Onest-${file}.ttf`, import.meta.url).pathname, out + `fonts/Onest-${file}.ttf`); | ||
| 43 | + | ||
| 44 | +const card = (group: string, height: number, subtitle: string, body: string) => | ||
| 45 | + `<!-- @dsCard group="${group}" height=${height} subtitle="${subtitle}" -->\n<div id="r" style="padding:16px"></div>\n<script>const {w,icon,chev,toggle,row,opts,track,line,caption,bands,mount}=Yumush;mount(r,${body})</script>\n`; | ||
| 46 | +const parts: [string, string, number, string, string, string][] = [ | ||
| 47 | + ["Line", "Lines", 120, "live · quiet · frayed", "parts::voice_line(bands, Voice, t)", | ||
| 48 | + "`<div class=\"col\" style=\"gap:8px;width:420px\">${caption('alice',line('voice',bands(1),'h-amber'))}${caption('bob',line('voice',null,'off'))}${caption('carol',line('frayed',bands(3),'bad'))}</div>`"], | ||
| 49 | + ["Spark", "Lines", 90, "ping history", "parts::spark(values, slots, color)", | ||
| 50 | + "`<div class=\"band\" style=\"gap:12px;width:420px;height:44px\">${w('ping','caption-t dim')}<div style=\"flex:1;height:100%\">${line('spark',Array.from({length:40},(_,i)=>Math.sin(i*.5)*.3+.5),'paper')}</div>${w('24 ms','strong')}</div>`"], | ||
| 51 | + ["Row", "Rows", 150, "label · trailing", "parts::row(label, trailing, t)", | ||
| 52 | + "`<div class=\"col\" style=\"width:420px\">${row('Noise suppression',toggle(true))}${row('A label long enough to be cut before it pushes the control away',toggle(false))}</div>`"], | ||
| 53 | + ["Toggle", "Rows", 70, "on · off", "parts::toggle(id, on, t, flip)", "`<div class=\"band\" style=\"gap:24px\">${toggle(true)}${toggle(false)}</div>`"], | ||
| 54 | + ["Options", "Rows", 70, "underlined choice", "parts::options(id, items, selected, t, pick)", "opts(['Voice activity','Push to talk'],'Voice activity')"], | ||
| 55 | + ["Track", "Rows", 110, "part · own over total · bad", "parts::track(Fill, bad, t)", | ||
| 56 | + "`<div class=\"col\" style=\"gap:16px;width:300px\">${track(.42)}${track(.09,.31)}${track(.7,null,true)}</div>`"], | ||
| 57 | + ["Button", "Controls", 70, "plain · danger · primary", "parts::button(id, label, Press, t, click)", | ||
| 58 | + "`<div class=\"band\" style=\"gap:24px\"><div class=\"btn\">Change source</div><div class=\"btn danger\">Stop</div><div class=\"btn primary\">Share</div></div>`"], | ||
| 59 | + ["IconButton", "Controls", 70, "idle · on · danger · split", "parts::icon_button(id, IconName, tip, Tone, t, click) + parts::chevron", | ||
| 60 | + "`<div class=\"band\" style=\"gap:4px\">${icon('mic')}${chev(false)}${icon('camera','on')}${chev(true)}${icon('off','danger')}</div>`"], | ||
| 61 | + ["Index", "Controls", 130, "selected = brighter + medium", "parts::index_item(id, label, selected, t, click)", | ||
| 62 | + "`<div class=\"col\" style=\"width:230px\"><div class=\"index\">Profile</div><div class=\"index on\">Voice</div><div class=\"index\">Camera & share</div></div>`"], | ||
| 63 | + ["Popover", "Surfaces", 230, "raise · thread edge", "parts::popover(t)", | ||
| 64 | + "`<div class=\"popover\" style=\"width:300px;gap:8px\"><div class=\"section\">Microphone</div>${w('Shure MV7')}${w('Laptop mic','dim')}<div style=\"height:18px\">${line('voice',bands(1),'h-amber')}</div>${row('Noise suppression',toggle(true))}</div>`"], | ||
| 65 | +]; | ||
| 66 | +for (const [name, group, height, subtitle, rust, body] of parts) { | ||
| 67 | + await put(`components/${name}/preview.html`, card(group, height, subtitle, body)); | ||
| 68 | + await put(`components/${name}/README.md`, `${name}: \`${rust}\` in \`crates/client/src/gui/parts.rs\`, \`.${name.toLowerCase()}\`-family classes in \`design/parts.css\`. Values come only from tokens; the client gallery (\`YUMUSH_GALLERY=parts:<state>\`) is screenshotted against this card.\n`); | ||
| 69 | +} | ||
| 70 | +await put("components/Cover/preview.html", `<!-- @dsCard height=260 page -->\n<div id="r" style="padding:48px;display:flex;flex-direction:column;gap:24px;height:100%"></div>\n<script>const {w,line,bands,mount}=Yumush;mount(r,\`\${w('yumuş','display-t')}<div style="height:40px;width:70%">\${line('voice',bands(2),'h-amber')}</div>\${w('the line a word travels on','dim')}\`)</script>\n`); | ||