Skip to content

Commit f378247

Browse files
committed
feat: 增加white-space
1 parent 946e38f commit f378247

File tree

6 files changed

+72
-5
lines changed

6 files changed

+72
-5
lines changed

src/parse_style_properties.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use lightningcss::{properties::{custom::TokenOrValue, Property}, stylesheet::Pri
44
use swc_core::{common::DUMMY_SP, ecma::{ast::{self}, utils::quote_ident}};
55
use swc_core::ecma::ast::*;
66

7-
use crate::{style_parser::KeyFrameItem, style_propetries::{animation::Animation, aspect_ratio::AspectRatio, background::Background, background_image::BackgroundImage, background_position::BackgroundPosition, background_repeat::BackgroundRepeat, background_size::BackgroundSize, border::Border, border_color::BorderColor, border_radius::BorderRadius, border_style::BorderStyle, border_width::BorderWidth, box_shadow::BoxShadow, color::ColorProperty, display::Display, flex::Flex, flex_align::FlexAlign, flex_basis::FlexBasis, flex_direction::FlexDirection, flex_wrap::FlexWrap, font_size::FontSize, font_style::FontStyle, font_weight::FontWeight, gap::Gap, item_align::ItemAlign, length_value::LengthValueProperty, letter_spacing::LetterSpacing, line_height::LineHeight, marin_padding::MarginPadding, max_size::MaxSizeProperty, normal::Normal, number::NumberProperty, opacity::Opacity, overflow::Overflow, position::Position, size::SizeProperty, style_property_type::CSSPropertyType, style_value_type::StyleValueType, text_align::TextAlign, text_decoration::TextDecoration, text_overflow::TextOverflow, text_shadow::TextShadow, text_transform::TextTransform, transform::Transform, transform_origin::TransformOrigin, vertical_align::VerticalAlign, visibility::Visibility, word_break::WordBreak}};
7+
use crate::{style_parser::KeyFrameItem, style_propetries::{animation::Animation, aspect_ratio::AspectRatio, background::Background, background_image::BackgroundImage, background_position::BackgroundPosition, background_repeat::BackgroundRepeat, background_size::BackgroundSize, border::Border, border_color::BorderColor, border_radius::BorderRadius, border_style::BorderStyle, border_width::BorderWidth, box_shadow::BoxShadow, color::ColorProperty, display::Display, flex::Flex, flex_align::FlexAlign, flex_basis::FlexBasis, flex_direction::FlexDirection, flex_wrap::FlexWrap, font_size::FontSize, font_style::FontStyle, font_weight::FontWeight, gap::Gap, item_align::ItemAlign, length_value::LengthValueProperty, letter_spacing::LetterSpacing, line_height::LineHeight, marin_padding::MarginPadding, max_size::MaxSizeProperty, normal::Normal, number::NumberProperty, opacity::Opacity, overflow::Overflow, position::Position, size::SizeProperty, style_property_type::CSSPropertyType, style_value_type::StyleValueType, text_align::TextAlign, text_decoration::TextDecoration, text_overflow::TextOverflow, text_shadow::TextShadow, text_transform::TextTransform, transform::Transform, transform_origin::TransformOrigin, vertical_align::VerticalAlign, visibility::Visibility, white_space::WhiteSpace, word_break::WordBreak}};
88

99
pub fn parse_style_properties(properties: &Vec<(String, Property)>, keyframes_map: Option<Rc<RefCell<HashMap<String, Vec<KeyFrameItem>>>>>) -> Vec<StyleValueType> {
1010
let mut final_properties = vec![];
@@ -251,6 +251,9 @@ pub fn parse_style_properties(properties: &Vec<(String, Property)>, keyframes_ma
251251
"wordBreak" => {
252252
final_properties.push(StyleValueType::WordBreak(WordBreak::from(( id.to_string(), value ))))
253253
}
254+
"whiteSpace" => {
255+
final_properties.push(StyleValueType::WhiteSpace(WhiteSpace::from(( id.to_string(), value ))))
256+
}
254257
_ => {
255258
// position、zIndex等... 会自动处理 单位、数字等相关信息
256259
// final_properties.push(StyleValueType::Normal(Normal::new(id.to_string(), value.value_to_css_string(PrinterOptions::default()).unwrap())));

src/style_propetries/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,4 +52,5 @@ pub mod box_shadow;
5252
pub mod position;
5353
pub mod visibility;
5454
pub mod opacity;
55-
pub mod word_break;
55+
pub mod word_break;
56+
pub mod white_space;

src/style_propetries/style_property_enum.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -374,3 +374,11 @@ pub enum Position {
374374
Fixed,
375375
Sticky,
376376
}
377+
378+
379+
#[repr(u32)]
380+
#[derive(Hash, PartialEq, Eq, Debug, Clone, Copy)]
381+
pub enum WhiteSpace {
382+
NoWrap = 0,
383+
Wrap,
384+
}

src/style_propetries/style_property_type.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,5 +91,6 @@ pub enum CSSPropertyType {
9191
transitionProperty = 86,
9292
transitionDuration = 87,
9393
transitionTimingFunction = 88,
94-
transitionDelay = 89
94+
transitionDelay = 89,
95+
WhiteSpace = 90,
9596
}

src/style_propetries/style_value_type.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use crate::generate_expr_based_on_platform;
22

3-
use super::{animation::Animation, aspect_ratio::AspectRatio, background::Background, background_image::BackgroundImage, background_position::BackgroundPosition, background_repeat::BackgroundRepeat, background_size::BackgroundSize, border::Border, border_color::BorderColor, border_radius::BorderRadius, border_style::BorderStyle, border_width::BorderWidth, box_shadow::BoxShadow, color::ColorProperty, display::Display, flex::Flex, flex_align::FlexAlign, flex_basis::FlexBasis, flex_direction::FlexDirection, flex_wrap::FlexWrap, font_size::FontSize, font_style::FontStyle, font_weight::FontWeight, gap::Gap, item_align::ItemAlign, length_value::LengthValueProperty, letter_spacing::LetterSpacing, line_height::LineHeight, marin_padding::MarginPadding, max_size::MaxSizeProperty, normal::Normal, number::NumberProperty, opacity::Opacity, overflow::Overflow, position::Position, size::SizeProperty, text_align::TextAlign, text_decoration::TextDecoration, text_overflow::TextOverflow, text_shadow::TextShadow, text_transform::TextTransform, traits::{ToExpr, ToStyleValue}, transform::Transform, transform_origin::TransformOrigin, unit::{Platform, PropertyTuple}, vertical_align::VerticalAlign, visibility::Visibility, word_break::WordBreak};
3+
use super::{animation::Animation, aspect_ratio::AspectRatio, background::Background, background_image::BackgroundImage, background_position::BackgroundPosition, background_repeat::BackgroundRepeat, background_size::BackgroundSize, border::Border, border_color::BorderColor, border_radius::BorderRadius, border_style::BorderStyle, border_width::BorderWidth, box_shadow::BoxShadow, color::ColorProperty, display::Display, flex::Flex, flex_align::FlexAlign, flex_basis::FlexBasis, flex_direction::FlexDirection, flex_wrap::FlexWrap, font_size::FontSize, font_style::FontStyle, font_weight::FontWeight, gap::Gap, item_align::ItemAlign, length_value::LengthValueProperty, letter_spacing::LetterSpacing, line_height::LineHeight, marin_padding::MarginPadding, max_size::MaxSizeProperty, normal::Normal, number::NumberProperty, opacity::Opacity, overflow::Overflow, position::Position, size::SizeProperty, text_align::TextAlign, text_decoration::TextDecoration, text_overflow::TextOverflow, text_shadow::TextShadow, text_transform::TextTransform, traits::{ToExpr, ToStyleValue}, transform::Transform, transform_origin::TransformOrigin, unit::{Platform, PropertyTuple}, vertical_align::VerticalAlign, visibility::Visibility, white_space::WhiteSpace, word_break::WordBreak};
44

55

66
#[derive(Debug, Clone)]
@@ -51,7 +51,8 @@ pub enum StyleValueType {
5151
Position(Position),
5252
Visibility(Visibility),
5353
Opacity(Opacity),
54-
WordBreak(WordBreak)
54+
WordBreak(WordBreak),
55+
WhiteSpace(WhiteSpace)
5556
}
5657

5758
impl ToStyleValue for StyleValueType {
@@ -198,6 +199,9 @@ impl ToStyleValue for StyleValueType {
198199
StyleValueType::WordBreak(value) => {
199200
generate_expr_based_on_platform!(platform, value)
200201
}
202+
StyleValueType::WhiteSpace(value) => {
203+
generate_expr_based_on_platform!(platform, value)
204+
}
201205
}
202206
}
203207
}

src/style_propetries/white_space.rs

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
use std::default;
2+
3+
use lightningcss::properties::{Property, font};
4+
5+
use crate::{generate_expr_enum, generate_invalid_expr, style_propetries::style_property_enum};
6+
7+
use super::{style_property_type::CSSPropertyType, traits::ToExpr, unit::PropertyTuple};
8+
9+
#[derive(Debug, Clone)]
10+
pub struct WhiteSpace {
11+
pub id: String,
12+
pub value: EnumValue
13+
}
14+
15+
#[derive(Debug, Clone)]
16+
pub enum EnumValue {
17+
NoWrap,
18+
Invalid
19+
}
20+
21+
impl ToExpr for WhiteSpace {
22+
fn to_expr(&self) -> PropertyTuple {
23+
PropertyTuple::One(
24+
CSSPropertyType::WhiteSpace,
25+
{
26+
match self.value {
27+
EnumValue::NoWrap => generate_expr_enum!(style_property_enum::WhiteSpace::NoWrap),
28+
EnumValue::Invalid => generate_invalid_expr!(),
29+
}
30+
}
31+
)
32+
}
33+
}
34+
35+
impl From<(String, &Property<'_>)> for WhiteSpace {
36+
fn from(prop: (String, &Property<'_>)) -> Self {
37+
WhiteSpace {
38+
id: prop.0,
39+
value: match prop.1 {
40+
Property::WhiteSpace(value) => {
41+
match value {
42+
lightningcss::properties::text::WhiteSpace::NoWrap => EnumValue::NoWrap,
43+
_ => EnumValue::Invalid,
44+
}
45+
}
46+
_ => EnumValue::Invalid,
47+
}
48+
}
49+
}
50+
}

0 commit comments

Comments
 (0)