Skip to content

Commit

Permalink
Implement CSS Color level 4 (#95)
Browse files Browse the repository at this point in the history
  • Loading branch information
devongovett authored Mar 2, 2022
1 parent e722636 commit 27e4a3d
Show file tree
Hide file tree
Showing 42 changed files with 4,986 additions and 823 deletions.
26 changes: 24 additions & 2 deletions scripts/build-prefixes.js
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,12 @@ let mdnFeatures = {
logicalPadding: mdn.css.properties['padding-inline-start'].__compat.support,
logicalInset: mdn.css.properties['inset-inline-start'].__compat.support,
logicalSize: mdn.css.properties['inline-size'].__compat.support,
logicalTextAlign: mdn.css.properties['text-align']['flow_relative_values_start_and_end'].__compat.support
logicalTextAlign: mdn.css.properties['text-align']['flow_relative_values_start_and_end'].__compat.support,
labColors: mdn.css.types.color.lab.__compat.support,
lchColors: mdn.css.types.color.lch.__compat.support,
oklabColors: {},
oklchColors: {},
colorFunction: mdn.css.types.color.color.__compat.support
};

for (let feature in mdnFeatures) {
Expand Down Expand Up @@ -213,6 +218,11 @@ for (let feature in mdnFeatures) {
addValue(compat, browserMap, feature);
}

addValue(compat, {
safari: parseVersion('10.1'),
ios_saf: parseVersion('10.3')
}, 'p3Colors');

let prefixMapping = {
webkit: 'WebKit',
moz: 'Moz',
Expand Down Expand Up @@ -308,7 +318,7 @@ let c = `// This file is autogenerated by build-prefixes.js. DO NOT EDIT!
use crate::targets::Browsers;
#[derive(Clone, Copy)]
#[derive(Clone, Copy, PartialEq)]
pub enum Feature {
${[...compat.keys()].flat().map(enumify).sort().join(',\n ')}
}
Expand All @@ -331,6 +341,18 @@ impl Feature {
}
true
}
pub fn is_partially_compatible(&self, targets: Browsers) -> bool {
let mut browsers = Browsers::default();
${allBrowsers.map(browser => `if targets.${browser}.is_some() {
browsers.${browser} = targets.${browser};
if self.is_compatible(browsers) {
return true
}
browsers.${browser} = None;
}\n`).join(' ')}
false
}
}
`;

Expand Down
113 changes: 111 additions & 2 deletions src/compat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@

use crate::targets::Browsers;

#[derive(Clone, Copy)]
#[derive(Clone, Copy, PartialEq)]
pub enum Feature {
Clamp,
ColorFunction,
CssAnyLink,
CssAutofill,
CssCaseInsensitive,
Expand Down Expand Up @@ -34,6 +35,8 @@ pub enum Feature {
DoublePositionGradients,
FormValidation,
Fullscreen,
LabColors,
LchColors,
LogicalBorderRadius,
LogicalBorders,
LogicalInset,
Expand All @@ -43,7 +46,10 @@ pub enum Feature {
LogicalTextAlign,
MediaIntervalSyntax,
MediaRangeSyntax,
OklabColors,
OklchColors,
OverflowShorthand,
P3Colors,
PlaceContent,
PlaceItems,
PlaceSelf,
Expand Down Expand Up @@ -1150,7 +1156,9 @@ impl Feature {
}
Feature::CssNesting |
Feature::CustomMediaQueries |
Feature::MediaIntervalSyntax => {
Feature::MediaIntervalSyntax |
Feature::OklabColors |
Feature::OklchColors => {
return false
}
Feature::DoublePositionGradients => {
Expand Down Expand Up @@ -1606,7 +1614,108 @@ impl Feature {
return false
}
}
Feature::LabColors |
Feature::LchColors |
Feature::ColorFunction => {
if let Some(version) = browsers.safari {
if version < 983040 {
return false
}
}
if let Some(version) = browsers.ios_saf {
if version < 983040 {
return false
}
}
if browsers.android.is_some() || browsers.chrome.is_some() || browsers.edge.is_some() || browsers.firefox.is_some() || browsers.ie.is_some() || browsers.opera.is_some() || browsers.samsung.is_some() {
return false
}
}
Feature::P3Colors => {
if let Some(version) = browsers.safari {
if version < 655616 {
return false
}
}
if let Some(version) = browsers.ios_saf {
if version < 656128 {
return false
}
}
if browsers.android.is_some() || browsers.chrome.is_some() || browsers.edge.is_some() || browsers.firefox.is_some() || browsers.ie.is_some() || browsers.opera.is_some() || browsers.samsung.is_some() {
return false
}
}
}
true
}

pub fn is_partially_compatible(&self, targets: Browsers) -> bool {
let mut browsers = Browsers::default();
if targets.android.is_some() {
browsers.android = targets.android;
if self.is_compatible(browsers) {
return true
}
browsers.android = None;
}
if targets.chrome.is_some() {
browsers.chrome = targets.chrome;
if self.is_compatible(browsers) {
return true
}
browsers.chrome = None;
}
if targets.edge.is_some() {
browsers.edge = targets.edge;
if self.is_compatible(browsers) {
return true
}
browsers.edge = None;
}
if targets.firefox.is_some() {
browsers.firefox = targets.firefox;
if self.is_compatible(browsers) {
return true
}
browsers.firefox = None;
}
if targets.ie.is_some() {
browsers.ie = targets.ie;
if self.is_compatible(browsers) {
return true
}
browsers.ie = None;
}
if targets.ios_saf.is_some() {
browsers.ios_saf = targets.ios_saf;
if self.is_compatible(browsers) {
return true
}
browsers.ios_saf = None;
}
if targets.opera.is_some() {
browsers.opera = targets.opera;
if self.is_compatible(browsers) {
return true
}
browsers.opera = None;
}
if targets.safari.is_some() {
browsers.safari = targets.safari;
if self.is_compatible(browsers) {
return true
}
browsers.safari = None;
}
if targets.samsung.is_some() {
browsers.samsung = targets.samsung;
if self.is_compatible(browsers) {
return true
}
browsers.samsung = None;
}

false
}
}
Loading

0 comments on commit 27e4a3d

Please sign in to comment.