Skip to content

Commit 48bc103

Browse files
committed
feat: 支持设计稿转换模式配置
1 parent f1358f6 commit 48bc103

File tree

5 files changed

+14
-1
lines changed

5 files changed

+14
-1
lines changed

index.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ export interface ParseOptions {
1111
designWidth?: number
1212
output?: OutputOptions
1313
allowInherit?: boolean
14+
designMode?: string
1415
}
1516
export interface ParseResult {
1617
code?: string

src/json_writer.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ pub struct JsonWriter {
2020
fonts: Vec<FontFaceItem>,
2121
design_width: Option<i32>,
2222
allow_inherit: Option<bool>,
23+
design_mode: Option<String>,
2324
}
2425

2526
impl JsonWriter {
@@ -30,6 +31,7 @@ impl JsonWriter {
3031
fonts: Vec<FontFaceItem>,
3132
design_width: Option<i32>,
3233
allow_inherit: Option<bool>,
34+
design_mode: Option<String>,
3335
) -> Self {
3436
Self {
3537
styles,
@@ -38,6 +40,7 @@ impl JsonWriter {
3840
fonts,
3941
design_width,
4042
allow_inherit,
43+
design_mode,
4144
}
4245
}
4346

@@ -332,6 +335,10 @@ impl JsonWriter {
332335
let map = json_value.as_object_mut().unwrap();
333336
map.insert("allow_inherit".to_string(), Value::Bool(allow_inherit));
334337
}
338+
if let Some(design_mode) = &self.design_mode {
339+
let map = json_value.as_object_mut().unwrap();
340+
map.insert("design_mode".to_string(), Value::String(design_mode.clone()));
341+
}
335342

336343
// 打印 JSON 值
337344

src/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ pub struct ParseOptions {
3838
pub design_width: Option<i32>,
3939
pub output: Option<OutputOptions>,
4040
pub allow_inherit: Option<bool>,
41+
pub design_mode: Option<String>,
4142
}
4243

4344
#[napi(object)]
@@ -55,6 +56,7 @@ pub fn parse(styles: Vec<String>, options: ParseOptions) -> ParseResult {
5556
};
5657
let design_width = options.design_width;
5758
let allow_inherit = options.allow_inherit;
59+
let design_mode = options.design_mode;
5860
let output = options.output.unwrap_or(OutputOptions {
5961
is_bin: Some(false)
6062
});
@@ -76,6 +78,7 @@ pub fn parse(styles: Vec<String>, options: ParseOptions) -> ParseResult {
7678
style_data.all_fonts.borrow().clone(),
7779
design_width,
7880
allow_inherit,
81+
design_mode
7982
);
8083

8184
let style_json = style_map.to_json();

src/main.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ pub fn main() {
3333
style_data.all_fonts.borrow().clone(),
3434
None,
3535
None,
36+
None,
3637
);
3738

3839
let style_json = style_map.to_json();

src/style_propetries/unit.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,14 +104,15 @@ pub fn generate_expr_by_length_value(length_value: &LengthValue, platform: Platf
104104
}
105105
}
106106
LengthValue::Ch(num) => {
107+
// 大写px
107108
match platform {
108109
Platform::ReactNative => {
109110
handler = Some(RN_CONVERT_STYLE_VU_FN.to_string());
110111
args.push(generate_expr_lit_num!(*num as f64));
111112
args.push(generate_expr_lit_str!("PX"));
112113
}
113114
Platform::Harmony => {
114-
return generate_expr_lit_str!(format!("{}px", num));
115+
return generate_expr_lit_str!(format!("{}vp", num));
115116
// handler = Some(CONVERT_STYLE_PX_FN.to_string());
116117
// args.push(generate_expr_lit_num!(*num as f64));
117118
// args.push(generate_expr_lit_str!("PX"));

0 commit comments

Comments
 (0)