Skip to content

Commit

Permalink
support all descre media queries, add some webkit prefixes, and other…
Browse files Browse the repository at this point in the history
… stuff
  • Loading branch information
keithamus committed Mar 3, 2024
1 parent 0cbcf11 commit 70a30d1
Show file tree
Hide file tree
Showing 116 changed files with 1,210 additions and 877 deletions.
16 changes: 9 additions & 7 deletions crates/hdx_ast/src/css/properties.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,11 @@ use hdx_parser::{
unexpected, unexpected_ident, Declaration, DeclarationValue, Parse, Parser, Result as ParserResult, State,
};
use hdx_writer::{CssWriter, Result as WriterResult, WriteCss};
#[cfg(feature = "serde")]
use serde::Serialize;

use crate::{css::values, syntax::ComponentValues};

#[derive(PartialEq, Debug, Hash)]
#[cfg_attr(feature = "serde", derive(Serialize), serde())]
#[cfg_attr(feature = "serde", derive(serde::Serialize), serde())]
pub struct Custom<'a>(pub ComponentValues<'a>);

impl<'a> WriteCss<'a> for Custom<'a> {
Expand All @@ -31,7 +29,7 @@ impl<'a> Parse<'a> for Custom<'a> {
}

#[derive(PartialEq, Debug, Hash)]
#[cfg_attr(feature = "serde", derive(Serialize), serde())]
#[cfg_attr(feature = "serde", derive(serde::Serialize), serde())]
pub struct Computed<'a>(pub ComponentValues<'a>);

impl<'a> WriteCss<'a> for Computed<'a> {
Expand All @@ -50,7 +48,7 @@ impl<'a> Parse<'a> for Computed<'a> {
}

#[derive(PartialEq, Debug, Hash)]
#[cfg_attr(feature = "serde", derive(Serialize), serde())]
#[cfg_attr(feature = "serde", derive(serde::Serialize), serde())]
pub struct Unknown<'a>(pub ComponentValues<'a>);

impl<'a> Parse<'a> for Unknown<'a> {
Expand All @@ -69,7 +67,7 @@ impl<'a> WriteCss<'a> for Unknown<'a> {
}

#[derive(PartialEq, Debug, Hash)]
#[cfg_attr(feature = "serde", derive(Serialize), serde())]
#[cfg_attr(feature = "serde", derive(serde::Serialize), serde())]
pub struct Property<'a> {
name: Atom,
value: StyleValue<'a>,
Expand Down Expand Up @@ -186,7 +184,7 @@ macro_rules! properties {
$name: ident$(<$a: lifetime>)?: $atom: pat,
)+ ) => {
#[derive(PartialEq, Debug, Hash)]
#[cfg_attr(feature = "serde", derive(Serialize), serde())]
#[cfg_attr(feature = "serde", derive(serde::Serialize), serde())]
pub enum StyleValue<'a> {
Initial,
Inherit,
Expand Down Expand Up @@ -1328,6 +1326,10 @@ properties! {
Zoom: atom!("zoom"),

// Webkit NonStandards
WebkitAnimationDuration: atom!("-webkit-animation-duration"),
WebkitAnimationDelay: atom!("-webkit-animation-delay"),
WebkitAnimationFillMode: atom!("-webkit-animation-fill-mode"),
WebkitAnimationIterationCount: atom!("-webkit-animation-iteration-count"),
// WebkitTextSizeAdjust: atom!("-webkit-text-size-adjust"),
// WebkitTextDecoration: atom!("-webkit-text-decoration"),
// WebkitTapHighlightColor: atom!("-webkit-tap-highlight-color"),
Expand Down
4 changes: 1 addition & 3 deletions crates/hdx_ast/src/css/rules/charset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,9 @@ use hdx_parser::{
expect, unexpected, Parse, Parser, Result as ParserResult,
};
use hdx_writer::{CssWriter, OutputOption, Result as WriterResult, WriteCss};
#[cfg(feature = "serde")]
use serde::Serialize;

#[derive(Atomizable, Debug, PartialEq, Hash)]
#[cfg_attr(feature = "serde", derive(Serialize), serde(tag = "type"))]
#[cfg_attr(feature = "serde", derive(serde::Serialize), serde(tag = "type"))]
pub enum CharsetRule {
#[atomizable("utf-8")]
Utf8,
Expand Down
30 changes: 30 additions & 0 deletions crates/hdx_ast/src/css/rules/media/features/any_hover.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
use crate::macros::discrete_media_feature;

discrete_media_feature!(AnyHoverMediaFeature[atom!("any-hover")] {
None: atom!("none"),
Hover: atom!("hover"),
});

#[cfg(test)]
mod tests {
use super::*;
use crate::test_helpers::*;

#[test]
fn size_test() {
assert_size!(AnyHoverMediaFeature, 1);
}

#[test]
fn test_writes() {
assert_parse!(AnyHoverMediaFeature, "any-hover");
assert_parse!(AnyHoverMediaFeature, "any-hover: hover");
assert_parse!(AnyHoverMediaFeature, "any-hover: none");
}

#[test]
fn test_minify() {
assert_minify!(AnyHoverMediaFeature, "any-hover: hover", "any-hover:hover");
assert_minify!(AnyHoverMediaFeature, "any-hover: none", "any-hover:none");
}
}
34 changes: 34 additions & 0 deletions crates/hdx_ast/src/css/rules/media/features/any_pointer.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
use crate::macros::discrete_media_feature;

discrete_media_feature!(AnyPointerMediaFeature[atom!("any-pointer")] {
None: atom!("none"),
Coarse: atom!("coarse"),
Fine: atom!("fine"),
});

#[cfg(test)]
mod tests {
use super::*;
use crate::test_helpers::*;

#[test]
fn size_test() {
assert_size!(AnyPointerMediaFeature, 1);
}

#[test]
fn test_writes() {
assert_parse!(AnyPointerMediaFeature, "any-pointer");
assert_parse!(AnyPointerMediaFeature, "any-pointer: none");
assert_parse!(AnyPointerMediaFeature, "any-pointer: coarse");
assert_parse!(AnyPointerMediaFeature, "any-pointer: fine");
}

#[test]
fn test_minify() {
assert_minify!(AnyPointerMediaFeature, "any-pointer", "any-pointer");
assert_minify!(AnyPointerMediaFeature, "any-pointer: none", "any-pointer:none");
assert_minify!(AnyPointerMediaFeature, "any-pointer: coarse", "any-pointer:coarse");
assert_minify!(AnyPointerMediaFeature, "any-pointer: fine", "any-pointer:fine");
}
}
86 changes: 0 additions & 86 deletions crates/hdx_ast/src/css/rules/media/features/anyhover.rs

This file was deleted.

99 changes: 0 additions & 99 deletions crates/hdx_ast/src/css/rules/media/features/anypointer.rs

This file was deleted.

39 changes: 39 additions & 0 deletions crates/hdx_ast/src/css/rules/media/features/color_gamut.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
use crate::macros::discrete_media_feature;

discrete_media_feature!(ColorGamutMediaFeature[atom!("color-gamut")] {
Srgb: atom!("srgb"),
P3: atom!("p3"),
Rec2020: atom!("rec2020"),
});

#[cfg(test)]
mod tests {
use super::*;
use crate::test_helpers::*;

#[test]
fn size_test() {
assert_size!(ColorGamutMediaFeature, 1);
}

#[test]
fn test_writes() {
assert_parse!(ColorGamutMediaFeature, "color-gamut");
assert_parse!(ColorGamutMediaFeature, "color-gamut: srgb");
assert_parse!(ColorGamutMediaFeature, "color-gamut: p3");
assert_parse!(ColorGamutMediaFeature, "color-gamut: rec2020");
}

#[test]
fn test_minify() {
assert_minify!(ColorGamutMediaFeature, "color-gamut: srgb", "color-gamut:srgb");
assert_minify!(ColorGamutMediaFeature, "color-gamut: p3", "color-gamut:p3");
assert_minify!(ColorGamutMediaFeature, "color-gamut: rec2020", "color-gamut:rec2020");
}

#[test]
fn test_errors() {
assert_parse_error!(ColorGamutMediaFeature, "color-gamut:");
assert_parse_error!(ColorGamutMediaFeature, "color-gamut: pointer");
}
}
4 changes: 0 additions & 4 deletions crates/hdx_ast/src/css/rules/media/features/colorgamut.rs

This file was deleted.

Loading

0 comments on commit 70a30d1

Please sign in to comment.