Skip to content

Commit 339dc76

Browse files
feat(studio): move every design value into one theme file (#3621)
* feat(studio): move every design value into one theme file Studio's design values lived in three places: a JS Tailwind preset, an inline @theme block, and raw hex and pixel literals in markup and CSS. theme.css is now the single owner. Tailwind v4 turns it into both the utility classes and the CSS custom properties, so markup, plain CSS and canvas code all read the same number. - semantic colour palette (background levels, surfaces, borders, text levels, accent, selection, playhead, danger, media, container), radii, control heights, the micro type scale, font stacks, shadows, easings and motion durations - the stock Tailwind palette is cleared with --color-*: initial, so a colour that is not a Studio token cannot be reached from markup; the entries Studio's markup still names are re-declared as deprecated aliases and removed once the sweep converts them - motion durations ship as @Utility rules that zero themselves under prefers-reduced-motion, since Tailwind has no duration namespace - Phosphor icons get one default size and weight, read off the theme at the app root; icons that pass their own still win - published as @hyperframes/studio/theme.css; the JS preset export stays as a deprecated shim for v3 consumers, with a test that fails if the two drift apart * docs(studio): trim theme token comments to pass the comment-length gate * docs(studio): shorten theme test docblock to fit the comment gate * refactor(studio): collapse the duration utilities into one functional rule * refactor(studio): trim theme.css comments to three lines * test(studio): fail when a legacy palette entry is not a Tailwind default * fix(studio): keep the palette reset out of the exported theme.css * style(studio): format theme.css with the repo formatter * fix(studio): declare theme.css browser-only so the packed-consumer smoke does not import it in node
1 parent f50df37 commit 339dc76

9 files changed

Lines changed: 465 additions & 52 deletions

File tree

‎packages/studio/package-subpaths.json‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,12 @@
1313
"types": "./dist/styles/tailwind-preset.d.ts",
1414
"environments": ["bun", "node"]
1515
},
16+
"./theme.css": {
17+
"source": "./src/styles/theme.css",
18+
"runtime": "./src/styles/theme.css",
19+
"types": null,
20+
"environments": ["browser"]
21+
},
1622
"./package.json": {
1723
"source": "./package.json",
1824
"runtime": "./package.json",

‎packages/studio/package.json‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
"import": "./src/styles/tailwind-preset.ts",
2727
"types": "./src/styles/tailwind-preset.ts"
2828
},
29+
"./theme.css": "./src/styles/theme.css",
2930
"./package.json": "./package.json"
3031
},
3132
"publishConfig": {
@@ -39,6 +40,7 @@
3940
"import": "./dist/styles/tailwind-preset.js",
4041
"types": "./dist/styles/tailwind-preset.d.ts"
4142
},
43+
"./theme.css": "./src/styles/theme.css",
4244
"./package.json": "./package.json"
4345
},
4446
"main": "./dist/index.js",

‎packages/studio/src/main.tsx‎

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import { StrictMode } from "react";
22
import { createRoot } from "react-dom/client";
3+
import { IconContext } from "@phosphor-icons/react";
34
import { StudioApp } from "./App";
45
import { StudioErrorBoundary } from "./components/StudioErrorBoundary";
6+
import { readIconTokens } from "./styles/iconTokens";
57
import { trackStudioEvent } from "./utils/studioTelemetry";
68
import "./styles/studio.css";
79

@@ -93,8 +95,12 @@ window.addEventListener("unhandledrejection", (event) => {
9395

9496
createRoot(document.getElementById("root")!).render(
9597
<StrictMode>
96-
<StudioErrorBoundary>
97-
<StudioApp />
98-
</StudioErrorBoundary>
98+
{/* One icon size and weight for the whole app, taken from the theme file.
99+
Icons that pass their own size or weight still win. */}
100+
<IconContext.Provider value={readIconTokens()}>
101+
<StudioErrorBoundary>
102+
<StudioApp />
103+
</StudioErrorBoundary>
104+
</IconContext.Provider>
99105
</StrictMode>,
100106
);
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import type { IconWeight } from "@phosphor-icons/react";
2+
3+
const WEIGHTS = ["thin", "light", "regular", "bold", "fill", "duotone"] as const;
4+
5+
function asWeight(value: string): IconWeight | null {
6+
return (WEIGHTS as readonly string[]).includes(value) ? (value as IconWeight) : null;
7+
}
8+
9+
/** Studio's Phosphor defaults, read off `theme.css` so size and weight have one
10+
* owner instead of a CSS variable and a JS constant that drift. A missing or
11+
* unrecognized value falls back to Phosphor's own default. */
12+
export function readIconTokens(root: Element = document.documentElement): {
13+
size: string;
14+
weight: IconWeight;
15+
} {
16+
const styles = getComputedStyle(root);
17+
const size = styles.getPropertyValue("--icon-size").trim();
18+
const weight = asWeight(styles.getPropertyValue("--icon-weight").trim());
19+
return { size: size || "1em", weight: weight ?? "regular" };
20+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
/* Studio's own app clears Tailwind's stock palette so only Studio tokens are
2+
* reachable from markup. Kept out of theme.css so a host importing the tokens
3+
* keeps its own colours. Must be imported before theme.css. */
4+
@theme static {
5+
--color-*: initial;
6+
}

‎packages/studio/src/styles/studio.css‎

Lines changed: 10 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,12 @@
11
@import "tailwindcss" source(none);
2+
@import "./palette-reset.css";
3+
@import "./theme.css";
24

35
/* Explicit sources: Studio's own TypeScript and its shell HTML. Automatic
46
* detection would walk up to the repo root and scan `data/projects`, gitignored user content. */
57
@source "../**/*.{ts,tsx}";
68
@source "../../index.html";
79

8-
/* Same palette as tailwind-preset.shared.js's studio/panel exports (kept for
9-
* the published ./tailwind-preset subpath). A later unit merges these into
10-
* one source; until then, update both when a value changes. */
11-
@theme {
12-
--color-studio-bg: #0a0a0a;
13-
--color-studio-surface: #141414;
14-
--color-studio-border: #262626;
15-
--color-studio-text: #e5e5e5;
16-
--color-studio-muted: #737373;
17-
--color-studio-accent: #3ce6ac;
18-
19-
--color-panel-bg: #0c0c0e;
20-
--color-panel-bg-inset: #121214;
21-
--color-panel-input: #161618;
22-
--color-panel-surface: #18181b;
23-
--color-panel-hover: #27272a;
24-
--color-panel-border: #1e1e1e;
25-
--color-panel-border-input: #27272a;
26-
--color-panel-hairline: #1a1a1c;
27-
--color-panel-text-0: #fafafa;
28-
--color-panel-text-1: #e4e4e7;
29-
--color-panel-text-2: #a1a1aa;
30-
--color-panel-text-3: #71717a;
31-
--color-panel-text-4: #52525b;
32-
--color-panel-text-5: #3f3f46;
33-
--color-panel-accent: #3ce6ac;
34-
--color-panel-danger: #ef4444;
35-
--color-panel-media: #00e3ff;
36-
--color-panel-container: #f5a623;
37-
}
38-
3910
/* Tailwind v4 preflight no longer gives enabled buttons a pointer cursor. */
4011
@layer base {
4112
button:not(:disabled),
@@ -56,9 +27,9 @@
5627
body {
5728
margin: 0;
5829
padding: 0;
59-
background: #0a0a0a;
60-
color: #e5e5e5;
61-
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
30+
background: var(--color-bg-0);
31+
color: var(--color-text-body);
32+
font-family: var(--font-sans);
6233
overflow: hidden;
6334
}
6435

@@ -332,7 +303,7 @@ body {
332303
left: 12px;
333304
overflow: hidden;
334305
color: rgba(255, 255, 255, 0.34);
335-
font-family: "SF Mono", "Fira Code", monospace;
306+
font-family: var(--font-mono);
336307
font-size: 9px;
337308
font-variant-numeric: tabular-nums;
338309
line-height: 1;
@@ -370,7 +341,7 @@ body {
370341
}
371342

372343
.cm-editor .cm-scroller {
373-
font-family: "JetBrains Mono", "Fira Code", "SF Mono", monospace;
344+
font-family: var(--font-mono);
374345
}
375346

376347
.cm-editor.cm-focused {
@@ -427,12 +398,7 @@ body {
427398
}
428399

429400
.hf-loader-title {
430-
font-family:
431-
Inter,
432-
-apple-system,
433-
BlinkMacSystemFont,
434-
"Segoe UI",
435-
sans-serif;
401+
font-family: var(--font-sans);
436402
font-size: 1rem;
437403
font-weight: 600;
438404
letter-spacing: 0;
@@ -448,12 +414,7 @@ body {
448414
min-height: 2.5rem;
449415
overflow: hidden;
450416
color: var(--hf-text-secondary, rgba(244, 244, 245, 0.68));
451-
font-family:
452-
Inter,
453-
-apple-system,
454-
BlinkMacSystemFont,
455-
"Segoe UI",
456-
sans-serif;
417+
font-family: var(--font-sans);
457418
font-size: 0.82rem;
458419
line-height: 1.6;
459420
}
@@ -465,7 +426,7 @@ body {
465426
text-overflow: ellipsis;
466427
white-space: nowrap;
467428
color: var(--hf-text-tertiary, rgba(244, 244, 245, 0.46));
468-
font-family: "IBM Plex Mono", "SF Mono", "Fira Code", monospace;
429+
font-family: var(--font-mono);
469430
font-size: 0.75rem;
470431
letter-spacing: 0;
471432
font-variant-numeric: tabular-nums;

‎packages/studio/src/styles/tailwind-preset.shared.js‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
/** @deprecated Superseded by `src/styles/theme.css` (published as
2+
* `@hyperframes/studio/theme.css`); kept one more major for Tailwind v3
3+
* consumers. Values are byte-identical; theme.test.ts fails if they drift. */
14
const studioPreset = {
25
theme: {
36
extend: {

0 commit comments

Comments
 (0)