-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
restructure writer css values to match as file structure
- Loading branch information
Showing
21 changed files
with
760 additions
and
685 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
use hdx_ast::css::values::{backgrounds::*, Shorthand}; | ||
|
||
use crate::{CssWriter, Result, WriteCss}; | ||
|
||
impl<'a> WriteCss<'a> for LineWidth { | ||
fn write_css<W: CssWriter>(&self, _sink: &mut W) -> Result { | ||
todo!() | ||
} | ||
} | ||
|
||
impl<'a> WriteCss<'a> for BorderShorthand<'a> { | ||
fn write_css<W: CssWriter>(&self, sink: &mut W) -> Result { | ||
if let Shorthand::Explicit(line_width) = &self.line_width { | ||
line_width.write_css(sink)?; | ||
if self.line_style.is_explicit() { | ||
sink.write_char(' ')?; | ||
} | ||
} | ||
if let Shorthand::Explicit(line_style) = &self.line_style { | ||
line_style.write_css(sink)?; | ||
if self.color.is_explicit() { | ||
sink.write_char(' ')?; | ||
} | ||
} | ||
if let Shorthand::Explicit(color) = &self.color { | ||
color.write_css(sink)?; | ||
} | ||
Ok(()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
use hdx_ast::css::values::r#box::*; | ||
|
||
use crate::{Atomizable, CssWriter, Result, WriteCss}; | ||
|
||
impl<'a> WriteCss<'a> for MarginTrimValue { | ||
fn write_css<W: CssWriter>(&self, _sink: &mut W) -> Result { | ||
todo!() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
use hdx_ast::css::values::color::*; | ||
|
||
use crate::{Atomizable, CssWriter, Result, WriteCss}; | ||
|
||
impl<'a> WriteCss<'a> for ColorValue<'a> { | ||
fn write_css<W: CssWriter>(&self, sink: &mut W) -> Result { | ||
match self { | ||
Self::Hex(_) => sink.write_str(&self.to_hex(ToHexStyle::Compact).unwrap()), | ||
Self::Named(named) => sink.write_str(named.to_atom().as_ref()), | ||
_ => todo!(), | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
use hdx_ast::css::values::counter_styles::*; | ||
|
||
use crate::{Atomizable, CssWriter, Result, WriteCss}; | ||
|
||
impl<'a> WriteCss<'a> for CounterStyle<'a> { | ||
fn write_css<W: CssWriter>(&self, sink: &mut W) -> Result { | ||
todo!() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
use hdx_ast::css::values::display::*; | ||
|
||
use crate::{Atomizable, CssWriter, Result, WriteCss}; | ||
|
||
impl<'a> WriteCss<'a> for DisplayValue { | ||
fn write_css<W: CssWriter>(&self, sink: &mut W) -> Result { | ||
if let Some(atom) = self.to_atom() { | ||
sink.write_str(atom.as_ref())?; | ||
} else if let DisplayValue::Pair(outside, inside) = self { | ||
if outside != &DisplayOutside::Implicit { | ||
sink.write_str(outside.to_atom().unwrap().as_ref())?; | ||
sink.write_char(' ')?; | ||
} | ||
sink.write_str(inside.to_atom().unwrap().as_ref())?; | ||
} else if let DisplayValue::PairAndMarker(outside, inside, marker) = self { | ||
if outside != &DisplayOutside::Implicit { | ||
sink.write_str(outside.to_atom().unwrap().as_ref())?; | ||
sink.write_char(' ')?; | ||
} | ||
if inside != &DisplayInside::Implicit { | ||
sink.write_str(inside.to_atom().unwrap().as_ref())?; | ||
sink.write_char(' ')?; | ||
} | ||
sink.write_str(marker.to_atom().unwrap().as_ref())?; | ||
} | ||
Ok(()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
use std::ops::Deref; | ||
|
||
use hdx_ast::css::values::expr::*; | ||
|
||
use crate::{Atomizable, CssWriter, Result, WriteCss}; | ||
|
||
impl<'a, T: WriteCss<'a>> WriteCss<'a> for Expr<'a, T> { | ||
fn write_css<W: CssWriter>(&self, sink: &mut W) -> Result { | ||
match self { | ||
Self::GlobalValue(g) => sink.write_str(g.to_atom().as_ref()), | ||
Self::Literal(val) => val.write_css(sink), | ||
Self::Reference(f) => f.write_css(sink), | ||
} | ||
} | ||
} | ||
|
||
impl<'a, T: WriteCss<'a>> WriteCss<'a> for MathExpr<'a, T> { | ||
fn write_css<W: CssWriter>(&self, sink: &mut W) -> Result { | ||
match self { | ||
Self::GlobalValue(g) => sink.write_str(g.to_atom().as_ref()), | ||
Self::Literal(val) => val.write_css(sink), | ||
Self::Reference(f) => f.write_css(sink), | ||
Self::Math(f) => f.write_css(sink), | ||
} | ||
} | ||
} | ||
|
||
impl<'a, T: WriteCss<'a>> WriteCss<'a> for ExprList<'a, T> { | ||
fn write_css<W: CssWriter>(&self, sink: &mut W) -> Result { | ||
match self { | ||
Self::GlobalValue(g) => sink.write_str(g.to_atom().as_ref()), | ||
Self::Values(v) => { | ||
let mut values = v.iter().peekable(); | ||
while let Some(value) = values.next() { | ||
value.write_css(sink)?; | ||
if values.peek().is_some() { | ||
sink.write_char(',')?; | ||
sink.write_trivia_char(' ')?; | ||
} | ||
} | ||
Ok(()) | ||
} | ||
} | ||
} | ||
} | ||
|
||
impl<'a, T: WriteCss<'a>> WriteCss<'a> for MathExprList<'a, T> { | ||
fn write_css<W: CssWriter>(&self, sink: &mut W) -> Result { | ||
match self { | ||
Self::GlobalValue(g) => sink.write_str(g.to_atom().as_ref()), | ||
Self::Values(v) => { | ||
let mut values = v.iter().peekable(); | ||
while let Some(value) = values.next() { | ||
value.write_css(sink)?; | ||
if values.peek().is_some() { | ||
sink.write_char(',')?; | ||
sink.write_trivia_char(' ')?; | ||
} | ||
} | ||
Ok(()) | ||
} | ||
} | ||
} | ||
} | ||
|
||
impl<'a, T: WriteCss<'a>> WriteCss<'a> for ExprListItem<'a, T> { | ||
fn write_css<W: CssWriter>(&self, sink: &mut W) -> Result { | ||
match self { | ||
Self::Literal(val) => val.write_css(sink), | ||
Self::Reference(f) => f.write_css(sink), | ||
} | ||
} | ||
} | ||
|
||
impl<'a, T: WriteCss<'a>> WriteCss<'a> for MathExprListItem<'a, T> { | ||
fn write_css<W: CssWriter>(&self, sink: &mut W) -> Result { | ||
match self { | ||
Self::Literal(val) => val.write_css(sink), | ||
Self::Reference(f) => f.write_css(sink), | ||
Self::Math(f) => f.write_css(sink), | ||
} | ||
} | ||
} | ||
|
||
impl<'a, T: WriteCss<'a>> WriteCss<'a> for Reference<'a, T> { | ||
fn write_css<W: CssWriter>(&self, sink: &mut W) -> Result { | ||
match self { | ||
Self::Var(atom, opt) => { | ||
sink.write_str("var(")?; | ||
sink.write_str(atom.as_ref())?; | ||
if let Some(val) = opt.deref() { | ||
sink.write_str(",")?; | ||
sink.write_trivia_char(' ')?; | ||
val.write_css(sink)?; | ||
} | ||
sink.write_str(")") | ||
} | ||
Self::Env(atom, opt) => { | ||
sink.write_str("var(")?; | ||
sink.write_str(atom.as_ref())?; | ||
if let Some(val) = opt.deref() { | ||
sink.write_str(",")?; | ||
sink.write_trivia_char(' ')?; | ||
val.write_css(sink)?; | ||
} | ||
sink.write_str(")") | ||
} | ||
} | ||
} | ||
} | ||
|
||
impl<'a> WriteCss<'a> for MathFunc<'a> { | ||
fn write_css<W: CssWriter>(&self, sink: &mut W) -> Result { | ||
todo!() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
use hdx_ast::css::values::{fonts::*, Angle, MathExpr}; | ||
use hdx_syntax::identifier::is_ident_str; | ||
|
||
use crate::{CssWriter, Result, Spanned, WriteCss}; | ||
|
||
impl<'a> WriteCss<'a> for FontWeightValue { | ||
fn write_css<W: CssWriter>(&self, sink: &mut W) -> Result { | ||
match self { | ||
Self::Normal => sink.write_str("normal"), | ||
Self::Bold => sink.write_str("bold"), | ||
Self::Bolder => sink.write_str("bolder"), | ||
Self::Lighter => sink.write_str("lighter"), | ||
Self::Number(num) => sink.write_str(num.to_string().as_str()), | ||
} | ||
} | ||
} | ||
|
||
impl<'a> WriteCss<'a> for FontSizeValue { | ||
fn write_css<W: CssWriter>(&self, sink: &mut W) -> Result { | ||
match self { | ||
Self::Absolute(size) => size.write_css(sink), | ||
Self::Relative(size) => size.write_css(sink), | ||
Self::LengthPercentage(size) => size.write_css(sink), | ||
Self::Math => sink.write_str("math"), | ||
} | ||
} | ||
} | ||
|
||
impl<'a> WriteCss<'a> for FontFamilyValue { | ||
fn write_css<W: CssWriter>(&self, sink: &mut W) -> Result { | ||
match self { | ||
Self::Named(atom) => { | ||
let bare = atom.as_ref().split_ascii_whitespace().all(is_ident_str); | ||
if !bare { | ||
sink.write_char('"')?; | ||
} | ||
sink.write_str(atom.as_ref())?; | ||
if !bare { | ||
sink.write_char('"')?; | ||
} | ||
Ok(()) | ||
} | ||
Self::Serif => sink.write_str("serif"), | ||
Self::SansSerif => sink.write_str("sans-serif"), | ||
Self::Cursive => sink.write_str("cursive"), | ||
Self::Fantasy => sink.write_str("fantasy"), | ||
Self::Monospace => sink.write_str("monospace"), | ||
Self::SystemUi => sink.write_str("system-ui"), | ||
Self::Emoji => sink.write_str("emoji"), | ||
Self::Math => sink.write_str("math"), | ||
Self::Fangsong => sink.write_str("fangsong"), | ||
Self::UiSerif => sink.write_str("ui-serif"), | ||
Self::UiSansSerif => sink.write_str("ui-sans-serif"), | ||
Self::UiMonospace => sink.write_str("ui-monospace"), | ||
Self::UiRounded => sink.write_str("ui-rounded"), | ||
} | ||
} | ||
} | ||
|
||
impl<'a> WriteCss<'a> for FontStyleValue<'a> { | ||
fn write_css<W: CssWriter>(&self, sink: &mut W) -> Result { | ||
match self { | ||
Self::Normal => sink.write_str("normal"), | ||
Self::Italic => sink.write_str("italic"), | ||
Self::Oblique(Spanned { node: angle, .. }) => { | ||
sink.write_str("oblique")?; | ||
match angle { | ||
MathExpr::Literal(Spanned { node: Angle::Deg(deg), .. }) => { | ||
if *deg != 14.0 { | ||
sink.write_char(' ')?; | ||
angle.write_css(sink)?; | ||
} | ||
} | ||
_ => { | ||
sink.write_char(' ')?; | ||
angle.write_css(sink)?; | ||
} | ||
} | ||
Ok(()) | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
use hdx_ast::css::values::images::*; | ||
|
||
use crate::{CssWriter, Result, WriteCss}; | ||
|
||
impl<'a> WriteCss<'a> for Image<'a> { | ||
fn write_css<W: CssWriter>(&self, sink: &mut W) -> Result { | ||
todo!() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
use hdx_ast::css::values::{inline::*, Shorthand}; | ||
|
||
use crate::{Atomizable, CssWriter, Result, WriteCss}; | ||
|
||
impl<'a> WriteCss<'a> for BaselineShiftValue { | ||
fn write_css<W: CssWriter>(&self, sink: &mut W) -> Result { | ||
match self { | ||
Self::Sub => sink.write_str("sub"), | ||
Self::Super => sink.write_str("super"), | ||
Self::Top => sink.write_str("top"), | ||
Self::Center => sink.write_str("center"), | ||
Self::Bottom => sink.write_str("bottom"), | ||
Self::LengthPercentage(val) => val.write_css(sink), | ||
} | ||
} | ||
} | ||
|
||
impl<'a> WriteCss<'a> for VerticalAlignShorthand<'a> { | ||
fn write_css<W: CssWriter>(&self, sink: &mut W) -> Result { | ||
if let Shorthand::Explicit(baseline_source) = &self.baseline_source { | ||
baseline_source.write_css(sink)?; | ||
if self.alignment_baseline.is_explicit() { | ||
sink.write_char(' ')?; | ||
} | ||
} | ||
if let Shorthand::Explicit(alignment_baseline) = &self.alignment_baseline { | ||
alignment_baseline.write_css(sink)?; | ||
if self.baseline_shift.is_explicit() { | ||
sink.write_char(' ')?; | ||
} | ||
} | ||
if let Shorthand::Explicit(baseline_shift) = &self.baseline_shift { | ||
baseline_shift.write_css(sink)?; | ||
} | ||
Ok(()) | ||
} | ||
} | ||
|
||
impl<'a> WriteCss<'a> for LineHeightValue { | ||
fn write_css<W: CssWriter>(&self, sink: &mut W) -> Result { | ||
match self { | ||
Self::Normal => sink.write_str("normal"), | ||
Self::Number(n) => sink.write_str(n.to_string().as_str()), | ||
Self::LengthPercentage(n) => n.write_css(sink), | ||
} | ||
} | ||
} |
Oops, something went wrong.