Skip to content

Commit ddace46

Browse files
Apply cleanups and also flag color-mix(…) polyfills so they aren't included in IntelliSense output
1 parent 66c2c48 commit ddace46

File tree

7 files changed

+36
-44
lines changed

7 files changed

+36
-44
lines changed

packages/@tailwindcss-postcss/src/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,6 @@ function tailwindcss(opts: PluginOptions = {}): AcceptedPlugin {
279279
DEBUG && I.end('AST -> CSS')
280280

281281
DEBUG && I.start('Lightning CSS')
282-
// @ts-ignore
283282
let ast = optimizeCss(css, {
284283
minify: typeof optimize === 'object' ? optimize.minify : true,
285284
})

packages/tailwindcss/src/ast.ts

Lines changed: 30 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ export function optimizeAst(
325325

326326
// Create fallback values for usages of the `color-mix(…)` function that reference variables
327327
// found in the theme config.
328-
if (node.value.includes('color-mix(')) {
328+
if (polyfills & Polyfills.ColorMix && node.value.includes('color-mix(')) {
329329
let ast = ValueParser.parse(node.value)
330330

331331
let didGenerateFallback = false
@@ -348,10 +348,11 @@ export function optimizeAst(
348348
// `oklab(…)` functions again as their support in Safari <16 is very limited.
349349
let colorspace = node.nodes[2]
350350
if (
351-
(colorspace.kind === 'word' && colorspace.value === 'oklab') ||
352-
colorspace.value === 'oklch' ||
353-
colorspace.value === 'lab' ||
354-
colorspace.value === 'lch'
351+
colorspace.kind === 'word' &&
352+
(colorspace.value === 'oklab' ||
353+
colorspace.value === 'oklch' ||
354+
colorspace.value === 'lab' ||
355+
colorspace.value === 'lch')
355356
) {
356357
colorspace.value = 'srgb'
357358
}
@@ -404,9 +405,8 @@ export function optimizeAst(
404405
return
405406
}
406407

407-
// Collect fallbacks for `@property` rules for Firefox support
408-
// We turn these into rules on `:root` or `*` and some pseudo-elements
409-
// based on the value of `inherits``
408+
// Collect fallbacks for `@property` rules for Firefox support We turn these into rules on
409+
// `:root` or `*` and some pseudo-elements based on the value of `inherits`
410410
if (polyfills & Polyfills.AtProperty) {
411411
let property = node.params
412412
let initialValue = null
@@ -448,8 +448,7 @@ export function optimizeAst(
448448
transform(child, copy.nodes, context, depth + 1)
449449
}
450450

451-
// Only track `@keyframes` that could be removed, when they were defined
452-
// inside of a `@theme`.
451+
// Only track `@keyframes` that could be removed, when they were defined inside of a `@theme`.
453452
if (node.name === '@keyframes' && context.theme) {
454453
keyframes.add(copy)
455454
}
@@ -572,32 +571,30 @@ export function optimizeAst(
572571

573572
// Fallbacks
574573
if (polyfills & Polyfills.AtProperty) {
575-
{
576-
let fallbackAst = []
574+
let fallbackAst = []
577575

578-
if (propertyFallbacksRoot.length > 0) {
579-
fallbackAst.push(rule(':root, :host', propertyFallbacksRoot))
580-
}
576+
if (propertyFallbacksRoot.length > 0) {
577+
fallbackAst.push(rule(':root, :host', propertyFallbacksRoot))
578+
}
581579

582-
if (propertyFallbacksUniversal.length > 0) {
583-
fallbackAst.push(rule('*, ::before, ::after, ::backdrop', propertyFallbacksUniversal))
584-
}
580+
if (propertyFallbacksUniversal.length > 0) {
581+
fallbackAst.push(rule('*, ::before, ::after, ::backdrop', propertyFallbacksUniversal))
582+
}
585583

586-
if (fallbackAst.length > 0) {
587-
let firstNonCommentIndex = newAst.findIndex((item) => item.kind !== 'comment')
588-
if (firstNonCommentIndex === -1) firstNonCommentIndex = 0
589-
newAst.splice(
590-
firstNonCommentIndex,
591-
0,
592-
atRule(
593-
'@supports',
594-
// We can't write a supports query for `@property` directly so we have to test for
595-
// features that are added around the same time in Mozilla and Safari.
596-
'((-webkit-hyphens: none) and (not (margin-trim: inline))) or ((-moz-orient: inline) and (not (color:rgb(from red r g b))))',
597-
[rule('@layer base', fallbackAst)],
598-
),
599-
)
600-
}
584+
if (fallbackAst.length > 0) {
585+
let firstNonCommentIndex = newAst.findIndex((item) => item.kind !== 'comment')
586+
if (firstNonCommentIndex === -1) firstNonCommentIndex = 0
587+
newAst.splice(
588+
firstNonCommentIndex,
589+
0,
590+
atRule(
591+
'@supports',
592+
// We can't write a supports query for `@property` directly so we have to test for
593+
// features that are added around the same time in Mozilla and Safari.
594+
'((-webkit-hyphens: none) and (not (margin-trim: inline))) or ((-moz-orient: inline) and (not (color:rgb(from red r g b))))',
595+
[rule('@layer base', fallbackAst)],
596+
),
597+
)
601598
}
602599
}
603600

packages/tailwindcss/src/index.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5009,7 +5009,7 @@ describe('`@property` polyfill', async () => {
50095009
`)
50105010
})
50115011

5012-
it('can be disabled to not emit fallbacks (necessary for CSS modules)', async () => {
5012+
it('emitting fallbacks can be disabled (necessary for CSS modules)', async () => {
50135013
await expect(
50145014
compileCss(
50155015
css`

packages/tailwindcss/src/index.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,11 @@ export const enum Polyfills {
4343
// Control if fallbacks for `@property` rules are emitted
4444
AtProperty = 1 << 0,
4545

46+
// Control if `color-mix(…)` fallbacks are inserted
47+
ColorMix = 1 << 1,
48+
4649
// Enable all
47-
All = AtProperty,
50+
All = AtProperty | ColorMix,
4851
}
4952

5053
type CompileOptions = {

packages/tailwindcss/src/utilities.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,8 +187,6 @@ export function withAlpha(value: string, alpha: string): string {
187187
* Apply opacity to a color using `color-mix`.
188188
*/
189189
export function replaceAlpha(value: string, alpha: string): string {
190-
if (alpha === null) return value
191-
192190
// Convert numeric values (like `0.5`) to percentages (like `50%`) so they
193191
// work properly with `color-mix`. Assume anything that isn't a number is
194192
// safe to pass through as-is, like `var(--my-opacity)`.

packages/tailwindcss/src/utils/replace-shadow-colors.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ export function replaceShadowColors(
8484
requiresFallback = true
8585
}
8686

87-
shadows.push(replace(replaceAlpha(color ?? 'currentcolor', intensity ?? null)))
87+
shadows.push(replace(replaceAlpha(color ?? 'currentcolor', intensity)))
8888
fallbackShadows.push(replace(color ?? 'currentcolor'))
8989
})
9090

playgrounds/vite/src/app.module.css

Lines changed: 0 additions & 5 deletions
This file was deleted.

0 commit comments

Comments
 (0)