Skip to content

Commit

Permalink
Add feature flag for light-dark()
Browse files Browse the repository at this point in the history
  • Loading branch information
devongovett committed Dec 21, 2024
1 parent 9b2e8bb commit 3043896
Show file tree
Hide file tree
Showing 9 changed files with 37 additions and 10 deletions.
3 changes: 2 additions & 1 deletion node/flags.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ exports.Features = {
DoublePositionGradients: 131072,
VendorPrefixes: 262144,
LogicalProperties: 524288,
LightDark: 1048576,
Selectors: 31,
MediaQueries: 448,
Colors: 64512,
Colors: 1113088,
};
3 changes: 2 additions & 1 deletion node/targets.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ export const Features: {
DoublePositionGradients: 131072,
VendorPrefixes: 262144,
LogicalProperties: 524288,
LightDark: 1048576,
Selectors: 31,
MediaQueries: 448,
Colors: 64512,
Colors: 1113088,
};
3 changes: 2 additions & 1 deletion scripts/build-prefixes.js
Original file line number Diff line number Diff line change
Expand Up @@ -465,9 +465,10 @@ let flags = [
'DoublePositionGradients',
'VendorPrefixes',
'LogicalProperties',
'LightDark',
['Selectors', ['Nesting', 'NotSelectorList', 'DirSelector', 'LangSelectorList', 'IsSelector']],
['MediaQueries', ['MediaIntervalSyntax', 'MediaRangeSyntax', 'CustomMediaQueries']],
['Colors', ['ColorFunction', 'OklabColors', 'LabColors', 'P3Colors', 'HexAlphaColors', 'SpaceSeparatedColorNotation']],
['Colors', ['ColorFunction', 'OklabColors', 'LabColors', 'P3Colors', 'HexAlphaColors', 'SpaceSeparatedColorNotation', 'LightDark']],
];

let enumify = (f) => f.replace(/^@([a-z])/, (_, x) => 'At' + x.toUpperCase()).replace(/^::([a-z])/, (_, x) => 'PseudoElement' + x.toUpperCase()).replace(/^:([a-z])/, (_, x) => 'PseudoClass' + x.toUpperCase()).replace(/(^|-)([a-z])/g, (_, a, x) => x.toUpperCase())
Expand Down
23 changes: 23 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28323,6 +28323,29 @@ mod tests {
..Browsers::default()
},
);
nesting_test_with_targets(
r#"
.foo { color-scheme: light; }
.bar { color: light-dark(red, green); }
"#,
indoc! {r#"
.foo {
color-scheme: light;
}

.bar {
color: light-dark(red, green);
}
"#},
Targets {
browsers: Some(Browsers {
safari: Some(13 << 16),
..Browsers::default()
}),
include: Features::empty(),
exclude: Features::LightDark,
},
);
}

#[test]
Expand Down
2 changes: 1 addition & 1 deletion src/properties/custom.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1653,7 +1653,7 @@ impl<'i> UnresolvedColor<'i> {
dest.write_char(')')
}
UnresolvedColor::LightDark { light, dark } => {
if !dest.targets.is_compatible(crate::compat::Feature::LightDark) {
if should_compile!(dest.targets, LightDark) {
dest.write_str("var(--lightningcss-light")?;
dest.delim(',', false)?;
light.to_css(dest, is_custom_property)?;
Expand Down
5 changes: 2 additions & 3 deletions src/properties/ui.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
//! CSS properties related to user interface.
use crate::compat::Feature;
use crate::context::PropertyHandlerContext;
use crate::declaration::{DeclarationBlock, DeclarationList};
use crate::error::{ParserError, PrinterError};
use crate::macros::{define_shorthand, enum_property, shorthand_property};
use crate::printer::Printer;
use crate::properties::{Property, PropertyId};
use crate::targets::{Browsers, Targets};
use crate::targets::{should_compile, Browsers, Targets};
use crate::traits::{FallbackValues, IsCompatible, Parse, PropertyHandler, Shorthand, ToCss};
use crate::values::color::CssColor;
use crate::values::number::CSSNumber;
Expand Down Expand Up @@ -548,7 +547,7 @@ impl<'i> PropertyHandler<'i> for ColorSchemeHandler {
) -> bool {
match property {
Property::ColorScheme(color_scheme) => {
if !context.targets.is_compatible(Feature::LightDark) {
if should_compile!(context.targets, LightDark) {
if color_scheme.contains(ColorScheme::Light) {
dest.push(define_var("--lightningcss-light", Token::Ident("initial".into())));
dest.push(define_var("--lightningcss-dark", Token::WhiteSpace(" ".into())));
Expand Down
3 changes: 2 additions & 1 deletion src/targets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,9 +158,10 @@ bitflags! {
const DoublePositionGradients = 1 << 17;
const VendorPrefixes = 1 << 18;
const LogicalProperties = 1 << 19;
const LightDark = 1 << 20;
const Selectors = Self::Nesting.bits() | Self::NotSelectorList.bits() | Self::DirSelector.bits() | Self::LangSelectorList.bits() | Self::IsSelector.bits();
const MediaQueries = Self::MediaIntervalSyntax.bits() | Self::MediaRangeSyntax.bits() | Self::CustomMediaQueries.bits();
const Colors = Self::ColorFunction.bits() | Self::OklabColors.bits() | Self::LabColors.bits() | Self::P3Colors.bits() | Self::HexAlphaColors.bits() | Self::SpaceSeparatedColorNotation.bits();
const Colors = Self::ColorFunction.bits() | Self::OklabColors.bits() | Self::LabColors.bits() | Self::P3Colors.bits() | Self::HexAlphaColors.bits() | Self::SpaceSeparatedColorNotation.bits() | Self::LightDark.bits();
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/values/color.rs
Original file line number Diff line number Diff line change
Expand Up @@ -595,7 +595,7 @@ impl ToCss for CssColor {
CssColor::from(srgb).to_css(dest)
}
CssColor::LightDark(light, dark) => {
if !dest.targets.is_compatible(Feature::LightDark) {
if should_compile!(dest.targets, LightDark) {
dest.write_str("var(--lightningcss-light")?;
dest.delim(',', false)?;
light.to_css(dest)?;
Expand Down
3 changes: 2 additions & 1 deletion website/pages/transpilation.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,13 +108,14 @@ Here is a full list of available flags, described in the sections below:
* `P3Colors`
* `HexAlphaColors`
* `SpaceSeparatedColorNotation`
* `LightDark`
* `FontFamilySystemUi`
* `DoublePositionGradients`
* `VendorPrefixes`
* `LogicalProperties`
* `Selectors` – shorthand for `Nesting | NotSelectorList | DirSelector | LangSelectorList | IsSelector`
* `MediaQueries` – shorthand for `MediaIntervalSyntax | MediaRangeSyntax | CustomMediaQueries`
* `Colors` – shorthand for `ColorFunction | OklabColors | LabColors | P3Colors | HexAlphaColors | SpaceSeparatedColorNotation`
* `Colors` – shorthand for `ColorFunction | OklabColors | LabColors | P3Colors | HexAlphaColors | SpaceSeparatedColorNotation | LightDark`

</div>

Expand Down

0 comments on commit 3043896

Please sign in to comment.