support special fns to single channel rgb/rgba/hsl/hsla

This commit is contained in:
Connor Skees 2021-07-28 03:09:03 -04:00
parent 4b94c8a948
commit eadd7c5041
3 changed files with 39 additions and 3 deletions

View File

@ -6,7 +6,7 @@ use num_traits::One;
use crate::{
args::CallArgs,
color::Color,
common::QuoteKind,
common::{Brackets, ListSeparator, QuoteKind},
error::SassResult,
parse::Parser,
unit::Unit,
@ -35,6 +35,24 @@ fn inner_hsl(name: &'static str, mut args: CallArgs, parser: &mut Parser) -> Sas
.into());
}
if channels.iter().any(Value::is_special_function) {
let channel_sep = if channels.len() < 3 {
ListSeparator::Space
} else {
ListSeparator::Comma
};
return Ok(Value::String(
format!(
"{}({})",
name,
Value::List(channels, channel_sep, Brackets::None)
.to_css_string(args.span(), false)?
),
QuoteKind::None,
));
}
let lightness = match channels.pop() {
Some(Value::Dimension(Some(n), ..)) => n / Number::from(100),
Some(Value::Dimension(None, ..)) => todo!(),

View File

@ -5,7 +5,7 @@ use num_traits::One;
use crate::{
args::CallArgs,
color::Color,
common::QuoteKind,
common::{Brackets, ListSeparator, QuoteKind},
error::SassResult,
parse::Parser,
unit::Unit,
@ -37,6 +37,24 @@ fn inner_rgb(name: &'static str, mut args: CallArgs, parser: &mut Parser) -> Sas
.into());
}
if channels.iter().any(Value::is_special_function) {
let channel_sep = if channels.len() < 3 {
ListSeparator::Space
} else {
ListSeparator::Comma
};
return Ok(Value::String(
format!(
"{}({})",
name,
Value::List(channels, channel_sep, Brackets::None)
.to_css_string(args.span(), false)?
),
QuoteKind::None,
));
}
let blue = match channels.pop() {
Some(Value::Dimension(Some(n), Unit::None, _)) => n,
Some(Value::Dimension(Some(n), Unit::Percent, _)) => {

View File

@ -233,7 +233,7 @@ test!(
"@media (max-width: 0px) {\n a {\n color: red;\n }\n}\n\na {\n color: red;\n}\n"
);
test!(
#[ignore = "we move to top of media"]
#[ignore = "we move to top of media"]
plain_import_inside_media_is_not_moved_to_top,
r#"@media foo {
a {