@@ -11,10 +11,10 @@ use serde::{Deserialize, Serialize};
11
11
12
12
mod html_formatter;
13
13
mod inset;
14
- mod size ;
14
+ mod length ;
15
15
pub use html_formatter:: { format_css, HtmlFormatter } ;
16
16
pub use inset:: Inset ;
17
- pub use size :: Size ;
17
+ pub use length :: Length ;
18
18
19
19
use super :: css_properties:: { absolute_bounding_box, fills_color, stroke_color, CssProperties } ;
20
20
@@ -62,27 +62,27 @@ pub enum StrokeStyle {
62
62
}
63
63
64
64
#[ derive( Debug , Serialize , Deserialize ) ]
65
- pub struct FlexContainer {
65
+ pub struct FlexContainer < ' a > {
66
66
pub align_items : AlignItems ,
67
67
pub direction : FlexDirection ,
68
- pub gap : Size ,
68
+ pub gap : Length < ' a > ,
69
69
#[ serde( skip_serializing_if = "Option::is_none" ) ]
70
70
pub justify_content : Option < JustifyContent > ,
71
71
}
72
72
73
73
#[ derive( Debug , Serialize , Deserialize ) ]
74
- pub struct Location {
75
- pub padding : [ Size ; 4 ] ,
74
+ pub struct Location < ' a > {
75
+ pub padding : [ Length < ' a > ; 4 ] ,
76
76
#[ serde( skip_serializing_if = "Option::is_none" ) ]
77
77
pub align_self : Option < AlignSelf > ,
78
78
#[ serde( skip_serializing_if = "Option::is_none" ) ]
79
79
pub flex_grow : Option < f64 > ,
80
80
#[ serde( skip_serializing_if = "Option::is_none" ) ]
81
81
pub inset : Option < [ Inset ; 4 ] > ,
82
82
#[ serde( skip_serializing_if = "Option::is_none" ) ]
83
- pub height : Option < Size > ,
83
+ pub height : Option < Length < ' a > > ,
84
84
#[ serde( skip_serializing_if = "Option::is_none" ) ]
85
- pub width : Option < Size > ,
85
+ pub width : Option < Length < ' a > > ,
86
86
}
87
87
88
88
#[ derive( Debug , Serialize , Deserialize ) ]
@@ -103,11 +103,11 @@ pub struct Appearance {
103
103
}
104
104
105
105
#[ derive( Debug , Serialize , Deserialize ) ]
106
- pub struct FrameAppearance {
106
+ pub struct FrameAppearance < ' a > {
107
107
#[ serde( skip_serializing_if = "Option::is_none" ) ]
108
108
pub background : Option < String > ,
109
109
#[ serde( skip_serializing_if = "Option::is_none" ) ]
110
- pub border_radius : Option < [ Size ; 4 ] > ,
110
+ pub border_radius : Option < [ Length < ' a > ; 4 ] > ,
111
111
#[ serde( skip_serializing_if = "Option::is_none" ) ]
112
112
pub box_shadow : Option < String > ,
113
113
#[ serde( skip_serializing_if = "Option::is_none" ) ]
@@ -141,10 +141,10 @@ pub struct IntermediateNode<'a> {
141
141
#[ serde( skip_serializing_if = "Option::is_none" ) ]
142
142
pub figma : Option < Figma < ' a > > ,
143
143
#[ serde( skip_serializing_if = "Option::is_none" ) ]
144
- pub flex_container : Option < FlexContainer > ,
145
- pub location : Location ,
144
+ pub flex_container : Option < FlexContainer < ' a > > ,
145
+ pub location : Location < ' a > ,
146
146
pub appearance : Appearance ,
147
- pub frame_appearance : FrameAppearance ,
147
+ pub frame_appearance : FrameAppearance < ' a > ,
148
148
pub node_type : IntermediateNodeType < ' a > ,
149
149
#[ serde( skip_serializing_if = "Option::is_none" ) ]
150
150
pub href : Option < Cow < ' a , str > > ,
@@ -170,7 +170,7 @@ impl<'a> IntermediateNode<'a> {
170
170
Some ( CounterAxisAlignItems :: Max ) => AlignItems :: FlexEnd ,
171
171
Some ( CounterAxisAlignItems :: Baseline ) => AlignItems :: Baseline ,
172
172
} ;
173
- let gap = Size :: Pixels ( node. item_spacing . unwrap_or ( 0.0 ) ) ;
173
+ let gap = Length :: new_from_option_pixels ( node. item_spacing ) ;
174
174
let justify_content = match node. primary_axis_align_items {
175
175
None => None ,
176
176
Some ( PrimaryAxisAlignItems :: Min ) => Some ( JustifyContent :: FlexStart ) ,
@@ -196,10 +196,10 @@ impl<'a> IntermediateNode<'a> {
196
196
} ,
197
197
location : Location {
198
198
padding : [
199
- Size :: Pixels ( node. padding_top . unwrap_or ( 0.0 ) ) ,
200
- Size :: Pixels ( node. padding_right . unwrap_or ( 0.0 ) ) ,
201
- Size :: Pixels ( node. padding_bottom . unwrap_or ( 0.0 ) ) ,
202
- Size :: Pixels ( node. padding_left . unwrap_or ( 0.0 ) ) ,
199
+ Length :: new_from_option_pixels ( node. padding_top ) ,
200
+ Length :: new_from_option_pixels ( node. padding_right ) ,
201
+ Length :: new_from_option_pixels ( node. padding_bottom ) ,
202
+ Length :: new_from_option_pixels ( node. padding_left ) ,
203
203
] ,
204
204
align_self : match (
205
205
parent. and_then ( |p| p. layout_mode . as_ref ( ) ) ,
@@ -277,7 +277,7 @@ impl<'a> IntermediateNode<'a> {
277
277
) if counter_axis_sizing_mode != & Some ( AxisSizingMode :: Fixed ) => None ,
278
278
_ => absolute_bounding_box ( node)
279
279
. and_then ( |b| b. height )
280
- . map ( Size :: Pixels ) ,
280
+ . map ( |h| Length :: new_from_option_pixels ( Some ( h ) ) ) ,
281
281
} ,
282
282
width : match ( parent, node) {
283
283
(
@@ -337,7 +337,7 @@ impl<'a> IntermediateNode<'a> {
337
337
) if counter_axis_sizing_mode != & Some ( AxisSizingMode :: Fixed ) => None ,
338
338
_ => absolute_bounding_box ( node)
339
339
. and_then ( |b| b. width )
340
- . map ( Size :: Pixels ) ,
340
+ . map ( |w| Length :: new_from_option_pixels ( Some ( w ) ) ) ,
341
341
} ,
342
342
} ,
343
343
appearance : Appearance {
@@ -383,10 +383,10 @@ impl<'a> IntermediateNode<'a> {
383
383
. rectangle_corner_radii ( )
384
384
. map ( |[ top, right, bottom, left] | {
385
385
[
386
- Size :: Pixels ( top) ,
387
- Size :: Pixels ( right) ,
388
- Size :: Pixels ( bottom) ,
389
- Size :: Pixels ( left) ,
386
+ Length :: new_from_option_pixels ( Some ( top) ) ,
387
+ Length :: new_from_option_pixels ( Some ( right) ) ,
388
+ Length :: new_from_option_pixels ( Some ( bottom) ) ,
389
+ Length :: new_from_option_pixels ( Some ( left) ) ,
390
390
]
391
391
} ) ,
392
392
box_shadow : node. box_shadow ( ) ,
@@ -508,9 +508,8 @@ impl<'a> IntermediateNode<'a> {
508
508
padding : [ top, right, bottom, left] ,
509
509
..
510
510
} = & self . location ;
511
- if ( top != & Size :: Pixels ( 0.0 ) || bottom != & Size :: Pixels ( 0.0 ) ) && height. is_some ( )
512
- || ( right != & Size :: Pixels ( 0.0 ) || left != & Size :: Pixels ( 0.0 ) )
513
- && width. is_some ( )
511
+ if ( top != & Length :: Zero || bottom != & Length :: Zero ) && height. is_some ( )
512
+ || ( right != & Length :: Zero || left != & Length :: Zero ) && width. is_some ( )
514
513
{
515
514
Some ( Cow :: Borrowed ( "border-box" ) )
516
515
} else {
@@ -540,7 +539,7 @@ impl<'a> IntermediateNode<'a> {
540
539
(
541
540
"gap" ,
542
541
self . flex_container . as_ref ( ) . and_then ( |c| {
543
- if c. gap == Size :: Pixels ( 0.0 ) {
542
+ if c. gap == Length :: Zero {
544
543
None
545
544
} else {
546
545
Some ( Cow :: Owned ( format ! ( "{}" , c. gap) ) )
@@ -610,12 +609,7 @@ impl<'a> IntermediateNode<'a> {
610
609
) ,
611
610
( "padding" , {
612
611
let p = & self . location . padding ;
613
- if p == & [
614
- Size :: Pixels ( 0.0 ) ,
615
- Size :: Pixels ( 0.0 ) ,
616
- Size :: Pixels ( 0.0 ) ,
617
- Size :: Pixels ( 0.0 ) ,
618
- ] {
612
+ if p == & [ Length :: Zero , Length :: Zero , Length :: Zero , Length :: Zero ] {
619
613
None
620
614
} else {
621
615
Some ( Cow :: Owned ( format ! ( "{} {} {} {}" , p[ 0 ] , p[ 1 ] , p[ 2 ] , p[ 3 ] ) ) )
0 commit comments