From 8012d1819bf4dbe098043b32cb22359905b7528e Mon Sep 17 00:00:00 2001 From: Jordan Pittman Date: Wed, 20 Sep 2023 16:34:39 -0400 Subject: [PATCH] Handle variable colors that have variable fallback values (#12049) * Parse colors even when variable has fallback that is a variable * Update changelog --- CHANGELOG.md | 1 + src/util/color.js | 2 +- tests/opacity.test.js | 18 ++++++++++++++++++ 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2edfa43f3..245179b79 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Skip `calc()` normalisation in nested `theme()` calls ([#11705](https://github.com/tailwindlabs/tailwindcss/pull/11705)) - Fix incorrectly generated CSS when using square brackets inside arbitrary properties ([#11709](https://github.com/tailwindlabs/tailwindcss/pull/11709)) - Make `content` optional for presets in TypeScript types ([#11730](https://github.com/tailwindlabs/tailwindcss/pull/11730)) +- Handle variable colors that have variable fallback values ([#12049](https://github.com/tailwindlabs/tailwindcss/pull/12049)) ## [3.3.3] - 2023-07-13 diff --git a/src/util/color.js b/src/util/color.js index ea6f752b3..733ca99ff 100644 --- a/src/util/color.js +++ b/src/util/color.js @@ -5,7 +5,7 @@ let SHORT_HEX = /^#([a-f\d])([a-f\d])([a-f\d])([a-f\d])?$/i let VALUE = /(?:\d+|\d*\.\d+)%?/ let SEP = /(?:\s*,\s*|\s+)/ let ALPHA_SEP = /\s*[,/]\s*/ -let CUSTOM_PROPERTY = /var\(--(?:[^ )]*?)\)/ +let CUSTOM_PROPERTY = /var\(--(?:[^ )]*?)(?:,(?:[^ )]*?|var\(--[^ )]*?\)))?\)/ let RGB = new RegExp( `^(rgba?)\\(\\s*(${VALUE.source}|${CUSTOM_PROPERTY.source})(?:${SEP.source}(${VALUE.source}|${CUSTOM_PROPERTY.source}))?(?:${SEP.source}(${VALUE.source}|${CUSTOM_PROPERTY.source}))?(?:${ALPHA_SEP.source}(${VALUE.source}|${CUSTOM_PROPERTY.source}))?\\s*\\)$` diff --git a/tests/opacity.test.js b/tests/opacity.test.js index 82b437ce8..88b88bd15 100644 --- a/tests/opacity.test.js +++ b/tests/opacity.test.js @@ -1113,3 +1113,21 @@ crosscheck(({ stable, oxide }) => { `) }) }) + +it('variables with variable fallback values can use opacity modifier', async () => { + let config = { + content: [ + { + raw: html`
`, + }, + ], + } + + let result = await run(`@tailwind utilities;`, config) + + expect(result.css).toMatchFormattedCss(css` + .bg-\[rgb\(var\(--some-var\,var\(--some-other-var\)\)\)\]\/50 { + background-color: rgb(var(--some-var, var(--some-other-var)) / 0.5); + } + `) +})