Skip to content

Commit a6424cd

Browse files
committed
fix(studio): keep the palette reset out of the exported theme.css
1 parent bcee837 commit a6424cd

4 files changed

Lines changed: 23 additions & 8 deletions

File tree

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: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
@import "tailwindcss" source(none);
2+
@import "./palette-reset.css";
23
@import "./theme.css";
34

45
/* Explicit sources: Studio's own TypeScript and its shell HTML. Automatic

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

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,6 @@
33
* tokens in `:root` so plain CSS and canvas code can still read them. */
44

55
@theme static {
6-
/* Clear Tailwind's stock palette so a colour that is not a Studio token
7-
* cannot be reached from markup. The entries Studio still uses are
8-
* re-declared below as deprecated aliases. */
9-
--color-*: initial;
10-
116
/* ---------------------------------------------------------------- colour */
127

138
/* Background levels, darkest (app shell) to lightest (inset panel body). */

‎packages/studio/src/styles/theme.test.ts‎

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,17 @@ function loadStylesheet(id: string, base: string) {
2727
return { path: file, base: path.dirname(file), content: readFileSync(file, "utf8") };
2828
}
2929

30-
async function build(entry: string, candidates: string[]): Promise<string> {
31-
const compiled = await compile(readFileSync(path.join(STYLES_DIR, entry), "utf8"), {
30+
async function buildSource(source: string, candidates: string[]): Promise<string> {
31+
const compiled = await compile(source, {
3232
base: STYLES_DIR,
3333
loadStylesheet,
3434
});
3535
return compiled.build(candidates);
3636
}
3737

38+
const build = (entry: string, candidates: string[]) =>
39+
buildSource(readFileSync(path.join(STYLES_DIR, entry), "utf8"), candidates);
40+
3841
function rootVariables(css: string): Map<string, string> {
3942
const block = css.match(/:root, :host \{([\s\S]*?)\n {2}\}/);
4043
const vars = new Map<string, string>();
@@ -74,7 +77,7 @@ describe("studio theme", () => {
7477
});
7578

7679
it("drops every Tailwind default color Studio does not use", async () => {
77-
// `--color-*: initial` clears the stock palette. The entries Studio's
80+
// `palette-reset.css` clears the stock palette. The entries Studio's
7881
// markup still references are re-declared as deprecated aliases (U12
7982
// removes them); anything outside that set must no longer resolve.
8083
const css = await build("studio.css", ["bg-neutral-750", "text-teal-500", "bg-neutral-800"]);
@@ -84,6 +87,16 @@ describe("studio theme", () => {
8487
expect(css).toContain(".bg-neutral-800 {");
8588
});
8689

90+
it("leaves a host's stock Tailwind colors alone when only theme.css is imported", async () => {
91+
const css = await buildSource('@import "tailwindcss";\n@import "./theme.css";', [
92+
"bg-teal-500",
93+
"text-accent",
94+
]);
95+
96+
expect(css).toContain(".bg-teal-500 {");
97+
expect(css).toContain(".text-accent {");
98+
});
99+
87100
it("keeps selection, playhead and accent as three distinct colors", () => {
88101
const accent = declaredValue("--color-accent");
89102
const selection = declaredValue("--color-selection");

0 commit comments

Comments
 (0)