11use once_cell:: sync:: Lazy ;
2- use std:: collections:: HashMap ;
2+ use std:: collections:: { HashMap , HashSet } ;
33use std:: sync:: Mutex ;
44
5+ pub enum SelectorSeparator {
6+ Single ,
7+ Double ,
8+ }
9+
10+ impl SelectorSeparator {
11+ pub fn separator ( & self ) -> & str {
12+ match self {
13+ SelectorSeparator :: Single => ":" ,
14+ SelectorSeparator :: Double => "::" ,
15+ }
16+ }
17+ }
18+
19+ static DOUBLE_SEPARATOR : Lazy < HashSet < & str > > = Lazy :: new ( || {
20+ let mut set = HashSet :: new ( ) ;
21+
22+ for key in [
23+ "placeholder" ,
24+ "before" ,
25+ "after" ,
26+ "highlight" ,
27+ "view-transition" ,
28+ "view-transition-group" ,
29+ "view-transition-image-pair" ,
30+ "view-transition-new" ,
31+ "view-transition-old" ,
32+ ] {
33+ set. insert ( key) ;
34+ }
35+ set
36+ } ) ;
37+
38+ pub fn get_selector_separator ( key : & str ) -> SelectorSeparator {
39+ if DOUBLE_SEPARATOR . contains ( key) {
40+ SelectorSeparator :: Double
41+ } else {
42+ SelectorSeparator :: Single
43+ }
44+ }
45+
546#[ derive( Clone , Debug , PartialEq ) ]
647pub enum PropertyType {
748 Single ( String ) ,
@@ -26,56 +67,54 @@ impl From<[&str; 2]> for PropertyType {
2667 }
2768}
2869
29- static GLOBAL_STYLE_PROPERTY : Lazy < Mutex < HashMap < & str , PropertyType > > > = Lazy :: new ( || {
30- Mutex :: new ( {
31- let mut map = HashMap :: new ( ) ;
70+ static GLOBAL_STYLE_PROPERTY : Lazy < HashMap < & str , PropertyType > > = Lazy :: new ( || {
71+ let mut map = HashMap :: new ( ) ;
3272
33- for ( key, value) in [
34- ( "bg" , "background" ) ,
35- ( "bgAttachment" , "background-attachment" ) ,
36- ( "bgClip" , "background-clip" ) ,
37- ( "bgColor" , "background-color" ) ,
38- ( "bgImage" , "background-image" ) ,
39- ( "bgOrigin" , "background-origin" ) ,
40- ( "bgPosition" , "background-position" ) ,
41- ( "bgPositionX" , "background-position-x" ) ,
42- ( "bgPositionY" , "background-position-y" ) ,
43- ( "bgRepeat" , "background-repeat" ) ,
44- ( "bgSize" , "background-size" ) ,
45- ( "animationDir" , "animation-direction" ) ,
46- ( "flexDir" , "flex-direction" ) ,
47- ( "pos" , "position" ) ,
48- ( "m" , "margin" ) ,
49- ( "mt" , "margin-top" ) ,
50- ( "mr" , "margin-right" ) ,
51- ( "mb" , "margin-bottom" ) ,
52- ( "ml" , "margin-left" ) ,
53- ( "p" , "padding" ) ,
54- ( "pt" , "padding-top" ) ,
55- ( "pr" , "padding-right" ) ,
56- ( "pb" , "padding-bottom" ) ,
57- ( "pl" , "padding-left" ) ,
58- ( "w" , "width" ) ,
59- ( "h" , "height" ) ,
60- ( "minW" , "min-width" ) ,
61- ( "minH" , "min-height" ) ,
62- ( "maxW" , "max-width" ) ,
63- ( "maxH" , "max-height" ) ,
64- ] {
65- map. insert ( key, value. into ( ) ) ;
66- }
73+ for ( key, value) in [
74+ ( "bg" , "background" ) ,
75+ ( "bgAttachment" , "background-attachment" ) ,
76+ ( "bgClip" , "background-clip" ) ,
77+ ( "bgColor" , "background-color" ) ,
78+ ( "bgImage" , "background-image" ) ,
79+ ( "bgOrigin" , "background-origin" ) ,
80+ ( "bgPosition" , "background-position" ) ,
81+ ( "bgPositionX" , "background-position-x" ) ,
82+ ( "bgPositionY" , "background-position-y" ) ,
83+ ( "bgRepeat" , "background-repeat" ) ,
84+ ( "bgSize" , "background-size" ) ,
85+ ( "animationDir" , "animation-direction" ) ,
86+ ( "flexDir" , "flex-direction" ) ,
87+ ( "pos" , "position" ) ,
88+ ( "m" , "margin" ) ,
89+ ( "mt" , "margin-top" ) ,
90+ ( "mr" , "margin-right" ) ,
91+ ( "mb" , "margin-bottom" ) ,
92+ ( "ml" , "margin-left" ) ,
93+ ( "p" , "padding" ) ,
94+ ( "pt" , "padding-top" ) ,
95+ ( "pr" , "padding-right" ) ,
96+ ( "pb" , "padding-bottom" ) ,
97+ ( "pl" , "padding-left" ) ,
98+ ( "w" , "width" ) ,
99+ ( "h" , "height" ) ,
100+ ( "minW" , "min-width" ) ,
101+ ( "minH" , "min-height" ) ,
102+ ( "maxW" , "max-width" ) ,
103+ ( "maxH" , "max-height" ) ,
104+ ] {
105+ map. insert ( key, value. into ( ) ) ;
106+ }
67107
68- for ( key, value) in [
69- ( "mx" , [ "margin-left" , "margin-right" ] ) ,
70- ( "my" , [ "margin-top" , "margin-bottom" ] ) ,
71- ( "px" , [ "padding-left" , "padding-right" ] ) ,
72- ( "py" , [ "padding-top" , "padding-bottom" ] ) ,
73- ( "boxSize" , [ "width" , "height" ] ) ,
74- ] {
75- map. insert ( key, value. into ( ) ) ;
76- }
77- map
78- } )
108+ for ( key, value) in [
109+ ( "mx" , [ "margin-left" , "margin-right" ] ) ,
110+ ( "my" , [ "margin-top" , "margin-bottom" ] ) ,
111+ ( "px" , [ "padding-left" , "padding-right" ] ) ,
112+ ( "py" , [ "padding-top" , "padding-bottom" ] ) ,
113+ ( "boxSize" , [ "width" , "height" ] ) ,
114+ ] {
115+ map. insert ( key, value. into ( ) ) ;
116+ }
117+ map
79118} ) ;
80119
81120static GLOBAL_CLASS_MAP : Lazy < Mutex < HashMap < String , i32 > > > =
@@ -107,8 +146,6 @@ pub fn to_kebab_case(value: &str) -> String {
107146
108147pub fn convert_property ( property : & str ) -> PropertyType {
109148 GLOBAL_STYLE_PROPERTY
110- . lock ( )
111- . unwrap ( )
112149 . get ( property)
113150 . cloned ( )
114151 . unwrap_or_else ( || to_kebab_case ( property) . into ( ) )
0 commit comments