Skip to content

Commit fd8fa60

Browse files
committed
feat: 增加 box-orient 解析 && display 增加 -webkit-box 解析
1 parent e5addd7 commit fd8fa60

File tree

9 files changed

+230
-142
lines changed

9 files changed

+230
-142
lines changed

.vscode/settings.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
{
2-
"rust-analyzer.showUnlinkedFileNotification": false
2+
"rust-analyzer.showUnlinkedFileNotification": false,
3+
"editor.tabSize": 2
34
}

src/parse_style_properties.rs

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

6-
use crate::{generate_expr_lit_str, style_parser::KeyFrameItem, style_propetries::{animation::Animation, animation_multi::AnimationMulti, 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, expr::Expr, 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::{string_to_css_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, transition::Transition, unit::{generate_expr_by_length_value, Platform}, vertical_align::VerticalAlign, visibility::Visibility, white_space::WhiteSpace, word_break::WordBreak}, utils::lowercase_first};
6+
use crate::{generate_expr_lit_str, style_parser::KeyFrameItem, style_propetries::{animation::Animation, animation_multi::AnimationMulti, 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_orient::BoxOrient, box_shadow::BoxShadow, color::ColorProperty, display::Display, expr::Expr, 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::{string_to_css_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, transition::Transition, unit::{generate_expr_by_length_value, Platform}, vertical_align::VerticalAlign, visibility::Visibility, white_space::WhiteSpace, word_break::WordBreak}, utils::lowercase_first};
77

88
pub fn parse_style_properties(properties: &Vec<(String, Property)>) -> Vec<StyleValueType> {
99
let mut final_properties = vec![];
@@ -247,6 +247,9 @@ pub fn parse_style_properties(properties: &Vec<(String, Property)>) -> Vec<Style
247247
}
248248
"whiteSpace" => {
249249
final_properties.push(StyleValueType::WhiteSpace(WhiteSpace::from(( id.to_string(), value ))))
250+
},
251+
"boxOrient" => {
252+
final_properties.push(StyleValueType::BoxOrient(BoxOrient::from(( id.to_string(), value ))));
250253
}
251254
_ => {
252255
// position、zIndex等... 会自动处理 单位、数字等相关信息

src/style_propetries/box_orient.rs

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

src/style_propetries/display.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
use lightningcss::properties::{display::{Display::{Keyword, Pair}, DisplayInside, DisplayKeyword, DisplayOutside}, Property};
44

5-
use crate::{generate_expr_enum, generate_expr_lit_str, generate_invalid_expr, style_propetries::style_property_enum};
5+
use crate::{generate_expr_enum, generate_invalid_expr, style_propetries::style_property_enum};
66

77
use super::{style_property_type::CSSPropertyType, traits::ToExpr, unit::PropertyTuple};
88

@@ -18,6 +18,7 @@ pub enum EnumValue {
1818
Flex,
1919
Block,
2020
Invalid,
21+
Box
2122
}
2223

2324
impl From<(String, &Property<'_>)> for Display {
@@ -34,6 +35,8 @@ impl From<(String, &Property<'_>)> for Display {
3435
Pair(value) => {
3536
if let DisplayInside::Flex(_) = value.inside {
3637
EnumValue::Flex
38+
} else if let DisplayInside::Box(_) = value.inside {
39+
EnumValue::Box
3740
} else {
3841
if let DisplayOutside::Block = value.outside {
3942
EnumValue::Block
@@ -60,6 +63,7 @@ impl ToExpr for Display {
6063
EnumValue::None => generate_expr_enum!(style_property_enum::Display::None),
6164
EnumValue::Flex => generate_expr_enum!(style_property_enum::Display::Flex),
6265
EnumValue::Block => generate_expr_enum!(style_property_enum::Display::Block),
66+
EnumValue::Box => generate_expr_enum!(style_property_enum::Display::Box),
6367
EnumValue::Invalid => generate_invalid_expr!(),
6468
}
6569
)

src/style_propetries/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,4 +56,5 @@ pub mod visibility;
5656
pub mod opacity;
5757
pub mod word_break;
5858
pub mod white_space;
59-
pub mod style_media;
59+
pub mod box_orient;
60+
pub mod style_media;

src/style_propetries/style_property_enum.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,7 @@ pub enum Display {
379379
None = 0,
380380
Block,
381381
Flex,
382+
Box,
382383
}
383384

384385
#[repr(u32)]
@@ -398,3 +399,12 @@ pub enum WhiteSpace {
398399
NoWrap = 0,
399400
Wrap,
400401
}
402+
403+
#[repr(u32)]
404+
#[derive(Hash, PartialEq, Eq, Debug, Clone, Copy)]
405+
pub enum BoxOrient {
406+
Horizontal = 0,
407+
Vertical,
408+
InlineAxis,
409+
BlockAxis,
410+
}

src/style_propetries/style_property_type.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ pub enum CSSPropertyType {
103103
Margin = 98,
104104
Padding = 99,
105105
BorderRadius = 100,
106+
BoxOrient = 101,
106107
}
107108

108109
pub fn string_to_css_property_type(property: &str) -> CSSPropertyType {
@@ -207,6 +208,7 @@ pub fn string_to_css_property_type(property: &str) -> CSSPropertyType {
207208
"margin" => CSSPropertyType::Margin,
208209
"padding" => CSSPropertyType::Padding,
209210
"borderRadius" => CSSPropertyType::BorderRadius,
211+
"boxOrient" => CSSPropertyType::BoxOrient,
210212
_ => CSSPropertyType::Invalid,
211213
}
212214
}

src/style_propetries/style_value_type.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
use crate::generate_expr_based_on_platform;
33

4-
use super::{animation::Animation, animation_multi::AnimationMulti, 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, expr::Expr, 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, transition::Transition, unit::{Platform, PropertyTuple}, vertical_align::VerticalAlign, visibility::Visibility, white_space::WhiteSpace, word_break::WordBreak};
4+
use super::{animation::Animation, animation_multi::AnimationMulti, 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_orient::BoxOrient, box_shadow::BoxShadow, color::ColorProperty, display::Display, expr::Expr, 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, transition::Transition, unit::{Platform, PropertyTuple}, vertical_align::VerticalAlign, visibility::Visibility, white_space::WhiteSpace, word_break::WordBreak};
55

66

77
#[derive(Debug, Clone)]
@@ -55,7 +55,8 @@ pub enum StyleValueType {
5555
Visibility(Visibility),
5656
Opacity(Opacity),
5757
WordBreak(WordBreak),
58-
WhiteSpace(WhiteSpace)
58+
WhiteSpace(WhiteSpace),
59+
BoxOrient(BoxOrient),
5960
}
6061

6162
impl ToStyleValue for StyleValueType {
@@ -211,6 +212,9 @@ impl ToStyleValue for StyleValueType {
211212
StyleValueType::WhiteSpace(value) => {
212213
generate_expr_based_on_platform!(platform, value)
213214
}
215+
StyleValueType::BoxOrient(value) => {
216+
generate_expr_based_on_platform!(platform, value)
217+
}
214218
}
215219
}
216220
}

0 commit comments

Comments
 (0)