From ca7b10e7d31519192489e08091751cab9d61868c Mon Sep 17 00:00:00 2001 From: Philipp Spiess Date: Thu, 20 Mar 2025 12:51:22 +0100 Subject: [PATCH] =?UTF-8?q?Make=20`--theme(=E2=80=A6)`=20return=20CSS=20va?= =?UTF-8?q?riables=20(#17036)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Closes #16945 This PR changes the `--theme(…)` function now return CSS `var(…)` definitions unless used in places where `var(…)` is not valid CSS (e.g. in `@media (width >= theme(--breakpoint-md))`): ```css /* input */ @theme { --color-red: red; } .red { color: --theme(--color-red); } /* output */ :root, :host { --color-red: red; } .red { color: var(--color-red); } ``` Furthermore, this adds an `--theme(… inline)` option to the `--theme(…)` function to force the resolution to be inline, e.g.: ```css /* input */ @theme { --color-red: red; } .red { color: --theme(--color-red inline); } /* output */ .red { color: red; } ``` This PR also changes preflight and the default theme to use this new `--theme(…)` function to ensure variables are prefixed correctly. ## Test plan - Added unit tests and a test that pulls in the whole preflight under a prefix theme. --- CHANGELOG.md | 5 + .../src/__snapshots__/index.test.ts.snap | 4 - .../src/codemods/migrate-media-screen.ts | 2 +- .../src/template/codemods/legacy-classes.ts | 6 +- packages/tailwindcss/preflight.css | 12 +- .../src/__snapshots__/index.test.ts.snap | 245 ++++++++++++++++++ packages/tailwindcss/src/ast.ts | 7 + .../src/compat/apply-compat-hooks.ts | 10 +- .../tailwindcss/src/css-functions.test.ts | 213 ++++++++++++++- packages/tailwindcss/src/css-functions.ts | 122 ++++++++- packages/tailwindcss/src/design-system.ts | 10 +- packages/tailwindcss/src/index.test.ts | 23 ++ packages/tailwindcss/src/theme.ts | 8 +- packages/tailwindcss/theme.css | 12 +- 14 files changed, 635 insertions(+), 44 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a333cb74d..49c3198dd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -26,6 +26,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Fix `border-[12px_4px]` being interpreted as a `border-color` instead of a `border-width` ([#17248](https://github.com/tailwindlabs/tailwindcss/pull/17248)) - Use the `oklab(…)` function when applying opacity to `currentColor` to work around a crash in Safari 16.4 and 16.5 ([#17247](https://github.com/tailwindlabs/tailwindcss/pull/17247)) - Pre-process `