diff --git a/CHANGELOG.md b/CHANGELOG.md index 2d3a50d..d37962f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,15 @@ +## [1.0.14](https://github.com/NervJS/parse-css-to-stylesheet/compare/v1.0.13...v1.0.14) (2025-02-19) + + +### Features + +* 加入媒体查询 ([f3c7ab2](https://github.com/NervJS/parse-css-to-stylesheet/commit/f3c7ab227c7144d11a23ae20f118b39d6a30a194)) +* 将媒体查询下Resolution单位🙆统一 ([c225926](https://github.com/NervJS/parse-css-to-stylesheet/commit/c225926614c7ab3c82ec6018d27907d2b11eb284)) +* 增加规则对env的提前识别 ([22c3327](https://github.com/NervJS/parse-css-to-stylesheet/commit/22c332769c632fb28418eb864c1933ac00611ea9)) +* css支持多animation ([21bc8a9](https://github.com/NervJS/parse-css-to-stylesheet/commit/21bc8a92b94b94f043ba98563411dc4d348af75d)) + + + ## [1.0.13](https://github.com/NervJS/parse-css-to-stylesheet/compare/v1.0.12...v1.0.13) (2024-07-22) diff --git a/npm/android-arm-eabi/package.json b/npm/android-arm-eabi/package.json index 054f6a0..5832621 100644 --- a/npm/android-arm-eabi/package.json +++ b/npm/android-arm-eabi/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/parse-css-to-stylesheet-android-arm-eabi", - "version": "1.0.13", + "version": "1.0.14", "os": [ "android" ], diff --git a/npm/android-arm64/package.json b/npm/android-arm64/package.json index 8f68f2a..dd66ea5 100644 --- a/npm/android-arm64/package.json +++ b/npm/android-arm64/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/parse-css-to-stylesheet-android-arm64", - "version": "1.0.13", + "version": "1.0.14", "os": [ "android" ], diff --git a/npm/darwin-arm64/package.json b/npm/darwin-arm64/package.json index b8c8502..7d49d92 100644 --- a/npm/darwin-arm64/package.json +++ b/npm/darwin-arm64/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/parse-css-to-stylesheet-darwin-arm64", - "version": "1.0.13", + "version": "1.0.14", "os": [ "darwin" ], diff --git a/npm/darwin-universal/package.json b/npm/darwin-universal/package.json index 91614ca..72091b2 100644 --- a/npm/darwin-universal/package.json +++ b/npm/darwin-universal/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/parse-css-to-stylesheet-darwin-universal", - "version": "1.0.13", + "version": "1.0.14", "os": [ "darwin" ], diff --git a/npm/darwin-x64/package.json b/npm/darwin-x64/package.json index d62fe01..77d2960 100644 --- a/npm/darwin-x64/package.json +++ b/npm/darwin-x64/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/parse-css-to-stylesheet-darwin-x64", - "version": "1.0.13", + "version": "1.0.14", "os": [ "darwin" ], diff --git a/npm/linux-arm-gnueabihf/package.json b/npm/linux-arm-gnueabihf/package.json index b7849a6..8c7ccb5 100644 --- a/npm/linux-arm-gnueabihf/package.json +++ b/npm/linux-arm-gnueabihf/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/parse-css-to-stylesheet-linux-arm-gnueabihf", - "version": "1.0.13", + "version": "1.0.14", "os": [ "linux" ], diff --git a/npm/linux-arm64-gnu/package.json b/npm/linux-arm64-gnu/package.json index b2c90a3..99d45fb 100644 --- a/npm/linux-arm64-gnu/package.json +++ b/npm/linux-arm64-gnu/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/parse-css-to-stylesheet-linux-arm64-gnu", - "version": "1.0.13", + "version": "1.0.14", "os": [ "linux" ], diff --git a/npm/linux-arm64-musl/package.json b/npm/linux-arm64-musl/package.json index 0d5c798..2f21dc1 100644 --- a/npm/linux-arm64-musl/package.json +++ b/npm/linux-arm64-musl/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/parse-css-to-stylesheet-linux-arm64-musl", - "version": "1.0.13", + "version": "1.0.14", "os": [ "linux" ], diff --git a/npm/linux-x64-gnu/package.json b/npm/linux-x64-gnu/package.json index 911e995..df5aee5 100644 --- a/npm/linux-x64-gnu/package.json +++ b/npm/linux-x64-gnu/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/parse-css-to-stylesheet-linux-x64-gnu", - "version": "1.0.13", + "version": "1.0.14", "os": [ "linux" ], diff --git a/npm/linux-x64-musl/package.json b/npm/linux-x64-musl/package.json index cb81405..5fc092b 100644 --- a/npm/linux-x64-musl/package.json +++ b/npm/linux-x64-musl/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/parse-css-to-stylesheet-linux-x64-musl", - "version": "1.0.13", + "version": "1.0.14", "os": [ "linux" ], diff --git a/npm/win32-x64-msvc/package.json b/npm/win32-x64-msvc/package.json index 9a8cb19..b2211f2 100644 --- a/npm/win32-x64-msvc/package.json +++ b/npm/win32-x64-msvc/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/parse-css-to-stylesheet-win32-x64-msvc", - "version": "1.0.13", + "version": "1.0.14", "os": [ "win32" ], diff --git a/package.json b/package.json index 991ccae..1425a53 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/parse-css-to-stylesheet", - "version": "1.0.13", + "version": "1.0.14", "main": "index.js", "types": "index.d.ts", "napi": { diff --git a/src/json_writer.rs b/src/json_writer.rs index d7ff28c..26176ae 100644 --- a/src/json_writer.rs +++ b/src/json_writer.rs @@ -5,6 +5,7 @@ use swc_core::common::DUMMY_SP; use swc_core::ecma::ast::*; use crate::constants::{Pseudo, SUPPORT_PSEUDO_KEYS}; +use crate::parse_style_properties::DeclsAndVars; use crate::style_propetries::style_value_type::StyleValueType; use crate::style_propetries::unit::Platform; @@ -14,20 +15,20 @@ use crate::style_parser::KeyFrameItem; use crate::style_propetries::style_media::StyleMedia; pub struct JsonWriter { - styles: IndexMap<(u32, String), Vec>, + styles: IndexMap<(u32, String), DeclsAndVars>, keyframes: IndexMap<(u32, String), Vec>, medias: Vec, } impl JsonWriter { - pub fn new(styles: IndexMap<(u32, String), Vec>, keyframes: IndexMap<(u32, String), Vec>, + pub fn new(styles: IndexMap<(u32, String), DeclsAndVars>, keyframes: IndexMap<(u32, String), Vec>, medias: Vec) -> Self { Self { styles ,keyframes,medias } } pub fn to_json(&self) -> String { - let elems: Vec = self.styles.iter().filter_map(|((media_index,selector), prop_or_spreads)| Some({ + let elems: Vec = self.styles.iter().filter_map(|((media_index,selector), item)| Some({ // 识别伪类 let mut new_selector = selector.clone(); let mut pseudo_key = String::new(); @@ -90,8 +91,12 @@ impl JsonWriter { key: PropName::Ident(Ident::new("declarations".into(), DUMMY_SP)), value: Box::new(Expr::Array(ArrayLit { span: DUMMY_SP, - elems: parse_style_values(prop_or_spreads.clone(), Platform::Harmony) + elems: parse_style_values(item.decls.clone(), Platform::Harmony) })), + }))), + PropOrSpread::Prop(Box::new(Prop::KeyValue(KeyValueProp { + key: PropName::Ident(Ident::new("has_env".into(), DUMMY_SP)), + value: Box::new(Expr::Lit(Lit::Bool(Bool { span: DUMMY_SP, value: item.has_var }))), }))) ]; diff --git a/src/parse_style_properties.rs b/src/parse_style_properties.rs index 97176ae..0461315 100644 --- a/src/parse_style_properties.rs +++ b/src/parse_style_properties.rs @@ -5,8 +5,15 @@ use swc_core::ecma::ast::*; 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}; -pub fn parse_style_properties(properties: &Vec<(String, Property)>) -> Vec { +#[derive(Debug, Clone)] +pub struct DeclsAndVars { + pub decls:Vec, + pub has_var: bool +} + +pub fn parse_style_properties(properties: &Vec<(String, Property)>) -> DeclsAndVars{ let mut final_properties = vec![]; + let mut has_env = false; for (id, value) in properties.iter() { let mut is_env: bool = false; @@ -28,6 +35,7 @@ pub fn parse_style_properties(properties: &Vec<(String, Property)>) -> Vec