Skip to content

Commit

Permalink
separate compat data for -webkit-fill-available and -moz-available
Browse files Browse the repository at this point in the history
fixes #630
  • Loading branch information
devongovett committed Dec 29, 2023
1 parent aedf6b6 commit 08efeeb
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 17 deletions.
12 changes: 7 additions & 5 deletions scripts/build-prefixes.js
Expand Up @@ -382,11 +382,13 @@ for (let key in mdn.css.properties['width']) {
mdnFeatures[feat] = mdn.css.properties['width'][key].__compat.support;
}

mdnFeatures.FillSize = Object.fromEntries(
Object.entries(mdn.css.properties.width.stretch.__compat.support)
.filter(([, v]) => v.alternative_name)
.map(([k, v]) => [k, {version_added: v.version_added}])
);
Object.entries(mdn.css.properties.width.stretch.__compat.support)
.filter(([, v]) => v.alternative_name)
.forEach(([k, v]) => {
let name = v.alternative_name.slice(1).replace(/[-_]([a-z])/g, (_, l) => l.toUpperCase()) + 'Size';
mdnFeatures[name] ??= {};
mdnFeatures[name][k] = {version_added: v.version_added};
});

for (let feature in mdnFeatures) {
let browserMap = {};
Expand Down
30 changes: 22 additions & 8 deletions src/compat.rs
Expand Up @@ -62,7 +62,6 @@ pub enum Feature {
EthiopicNumericListStyleType,
ExUnit,
ExtendedSystemFonts,
FillSize,
FirstLetter,
FirstLine,
FitContentFunctionSize,
Expand Down Expand Up @@ -135,6 +134,7 @@ pub enum Feature {
MinFunction,
ModFunction,
MongolianListStyleType,
MozAvailableSize,
MyanmarListStyleType,
Namespaces,
Nesting,
Expand Down Expand Up @@ -206,6 +206,7 @@ pub enum Feature {
VmaxUnit,
VminUnit,
VwUnit,
WebkitFillAvailableSize,
XResolutionUnit,
}

Expand Down Expand Up @@ -4801,7 +4802,7 @@ impl Feature {
return false;
}
}
Feature::FillSize => {
Feature::WebkitFillAvailableSize => {
if let Some(version) = browsers.chrome {
if version < 1638400 {
return false;
Expand All @@ -4812,11 +4813,6 @@ impl Feature {
return false;
}
}
if let Some(version) = browsers.firefox {
if version < 262144 {
return false;
}
}
if let Some(version) = browsers.opera {
if version < 917504 {
return false;
Expand All @@ -4842,7 +4838,25 @@ impl Feature {
return false;
}
}
if browsers.ie.is_some() {
if browsers.firefox.is_some() || browsers.ie.is_some() {
return false;
}
}
Feature::MozAvailableSize => {
if let Some(version) = browsers.firefox {
if version < 262144 {
return false;
}
}
if browsers.android.is_some()
|| browsers.chrome.is_some()
|| browsers.edge.is_some()
|| browsers.ie.is_some()
|| browsers.ios_saf.is_some()
|| browsers.opera.is_some()
|| browsers.safari.is_some()
|| browsers.samsung.is_some()
{
return false;
}
}
Expand Down
26 changes: 26 additions & 0 deletions src/lib.rs
Expand Up @@ -3767,6 +3767,32 @@ mod tests {
},
);

prefix_test(
&format!(
r#"
.foo {{
{}: 100vw;
{}: -webkit-fill-available;
}}
"#,
in_prop, in_prop
),
&format!(
indoc! {r#"
.foo {{
{}: 100vw;
{}: -webkit-fill-available;
}}
"#},
out_prop, out_prop
),
Browsers {
safari: Some(8 << 16),
firefox: Some(4 << 16),
..Browsers::default()
},
);

prefix_test(
&format!(
r#"
Expand Down
18 changes: 14 additions & 4 deletions src/properties/size.rs
Expand Up @@ -142,8 +142,13 @@ impl IsCompatible for Size {
FitContentFunction(l) => {
Feature::FitContentFunctionSize.is_compatible(browsers) && l.is_compatible(browsers)
}
Stretch(vp) if *vp == VendorPrefix::None => Feature::StretchSize.is_compatible(browsers),
Stretch(..) => Feature::FillSize.is_compatible(browsers),
Stretch(vp) => match *vp {
VendorPrefix::None => Feature::StretchSize,
VendorPrefix::WebKit => Feature::WebkitFillAvailableSize,
VendorPrefix::Moz => Feature::MozAvailableSize,
_ => return false,
}
.is_compatible(browsers),
Contain => false, // ??? no data in mdn
Auto => true,
}
Expand Down Expand Up @@ -271,8 +276,13 @@ impl IsCompatible for MaxSize {
FitContentFunction(l) => {
Feature::FitContentFunctionSize.is_compatible(browsers) && l.is_compatible(browsers)
}
Stretch(vp) if *vp == VendorPrefix::None => Feature::StretchSize.is_compatible(browsers),
Stretch(..) => Feature::FillSize.is_compatible(browsers),
Stretch(vp) => match *vp {
VendorPrefix::None => Feature::StretchSize,
VendorPrefix::WebKit => Feature::WebkitFillAvailableSize,
VendorPrefix::Moz => Feature::MozAvailableSize,
_ => return false,
}
.is_compatible(browsers),
Contain => false, // ??? no data in mdn
None => true,
}
Expand Down

0 comments on commit 08efeeb

Please sign in to comment.