@@ -15,63 +15,66 @@ const fs = require('fs');
15
15
16
16
let oClassNameMap = {
17
17
// margin
18
- '.m' : 'margin:$px; ' ,
19
- '.ml' : 'margin-left:$px; ' ,
20
- '.mr' : 'margin-right:$px; ' ,
21
- '.mt' : 'margin-top:$px; ' ,
22
- '.mb' : 'margin-bottom:$px; ' ,
23
- '.mx' : 'margin-left:$px;margin-right:$px; ' ,
24
- '.my' : 'margin-top:$px;margin-bottom:$px; ' ,
18
+ '.m' : 'margin:$px' ,
19
+ '.ml' : 'margin-left:$px' ,
20
+ '.mr' : 'margin-right:$px' ,
21
+ '.mt' : 'margin-top:$px' ,
22
+ '.mb' : 'margin-bottom:$px' ,
23
+ '.mx' : 'margin-left:$px;margin-right:$px' ,
24
+ '.my' : 'margin-top:$px;margin-bottom:$px' ,
25
25
// margin !important
26
- '.mi' : 'margin:$px !important; ' ,
27
- '.mli' : 'margin-left:$px !important; ' ,
28
- '.mri' : 'margin-right:$px !important; ' ,
29
- '.mti' : 'margin-top:$px !important; ' ,
30
- '.mbi' : 'margin-bottom:$px !important; ' ,
31
- '.mxi' : 'margin-left:$px !important;margin-right:$px !important; ' ,
32
- '.myi' : 'margin-top:$px !important;margin-bottom:$px !important; ' ,
26
+ '.mi' : 'margin:$px !important' ,
27
+ '.mli' : 'margin-left:$px !important' ,
28
+ '.mri' : 'margin-right:$px !important' ,
29
+ '.mti' : 'margin-top:$px !important' ,
30
+ '.mbi' : 'margin-bottom:$px !important' ,
31
+ '.mxi' : 'margin-left:$px !important;margin-right:$px !important' ,
32
+ '.myi' : 'margin-top:$px !important;margin-bottom:$px !important' ,
33
33
// padding
34
- '.p' : 'padding:$px; ' ,
35
- '.pl' : 'padding-left:$px; ' ,
36
- '.pr' : 'padding-right:$px; ' ,
37
- '.pt' : 'padding-top:$px; ' ,
38
- '.pb' : 'padding-bottom:$px; ' ,
39
- '.px' : 'padding-left:$px;padding-right:$px; ' ,
40
- '.py' : 'padding-top:$px;padding-bottom:$px; ' ,
34
+ '.p' : 'padding:$px' ,
35
+ '.pl' : 'padding-left:$px' ,
36
+ '.pr' : 'padding-right:$px' ,
37
+ '.pt' : 'padding-top:$px' ,
38
+ '.pb' : 'padding-bottom:$px' ,
39
+ '.px' : 'padding-left:$px;padding-right:$px' ,
40
+ '.py' : 'padding-top:$px;padding-bottom:$px' ,
41
41
// padding !important
42
- '.pi' : 'padding:$px !important; ' ,
43
- '.pli' : 'padding-left:$px !important; ' ,
44
- '.pri' : 'padding-right:$px !important; ' ,
45
- '.pti' : 'padding-top:$px !important; ' ,
46
- '.pbi' : 'padding-bottom:$px !important; ' ,
47
- '.pxi' : 'padding-left:$px !important;padding-right:$px !important; ' ,
48
- '.pyi' : 'padding-top:$px !important;padding-bottom:$px !important; ' ,
42
+ '.pi' : 'padding:$px !important' ,
43
+ '.pli' : 'padding-left:$px !important' ,
44
+ '.pri' : 'padding-right:$px !important' ,
45
+ '.pti' : 'padding-top:$px !important' ,
46
+ '.pbi' : 'padding-bottom:$px !important' ,
47
+ '.pxi' : 'padding-left:$px !important;padding-right:$px !important' ,
48
+ '.pyi' : 'padding-top:$px !important;padding-bottom:$px !important' ,
49
49
// width
50
- '.w' : 'width:$px; ' ,
51
- '.wi' : 'width:$px !important; ' ,
52
- '.mw' : 'min-width:$px; ' ,
53
- '.wp' : 'width:$%; ' ,
54
- '.wpi' : 'width:$% !important; ' ,
50
+ '.w' : 'width:$px' ,
51
+ '.wi' : 'width:$px !important' ,
52
+ '.mw' : 'min-width:$px' ,
53
+ '.wp' : 'width:$%' ,
54
+ '.wpi' : 'width:$% !important' ,
55
55
// height
56
- '.h' : 'height:$px; ' ,
57
- '.hi' : 'height:$px !important; ' ,
58
- '.mh' : 'min-height:$px; ' ,
59
- '.hp' : 'height:$%; ' ,
60
- '.hpi' : 'height:$% !important; ' ,
56
+ '.h' : 'height:$px' ,
57
+ '.hi' : 'height:$px !important' ,
58
+ '.mh' : 'min-height:$px' ,
59
+ '.hp' : 'height:$%' ,
60
+ '.hpi' : 'height:$% !important' ,
61
61
// 四方向
62
- '.l' : 'left:$px; ' ,
63
- '.r' : 'right:$px; ' ,
64
- '.t' : 'top:$px; ' ,
65
- '.b' : 'bottom:$px; ' ,
62
+ '.l' : 'left:$px' ,
63
+ '.r' : 'right:$px' ,
64
+ '.t' : 'top:$px' ,
65
+ '.b' : 'bottom:$px' ,
66
66
// 行高
67
- '.lh' : 'line-height:$px; ' ,
67
+ '.lh' : 'line-height:$px' ,
68
68
// 字体
69
- '.fs' : 'font-size:$px; ' ,
70
- '.fw' : 'font-weight:$; ' ,
69
+ '.fs' : 'font-size:$px' ,
70
+ '.fw' : 'font-weight:$' ,
71
71
// background
72
- '.bgs' : 'background-size:$px; ' ,
72
+ '.bgs' : 'background-size:$px' ,
73
73
// border
74
- '.br' : 'border-radius:$px;'
74
+ '.br' : 'border-radius:$px' ,
75
+ // 颜色
76
+ '.c' : 'color: #' ,
77
+ '.bgc' : 'background-color: #' ,
75
78
} ;
76
79
77
80
let oAtomConfig = { }
@@ -100,6 +103,10 @@ for (let key in oClassNameMap) {
100
103
// 数值原子类的正则
101
104
if ( value . indexOf ( '$' ) != - 1 ) {
102
105
sAtomRegExp += `\\${ key } -[0-9]+|` ;
106
+ }
107
+ // 色值原子类正则
108
+ else if ( value . indexOf ( '#' ) != - 1 ) {
109
+ sAtomRegExp += `\\${ key } -[0-9a-fA-F]+|` ;
103
110
// 通用原子类的正则
104
111
} else {
105
112
sAtomRegExp += `\\${ key } |`
@@ -158,8 +165,16 @@ module.exports = function(sSource) {
158
165
aClassName . forEach ( item => {
159
166
let sKey ;
160
167
161
- if ( / \d + / . test ( item ) ) {
168
+ let bColorFlag = oClassNameMap [ item . split ( '-' ) [ 0 ] ] && oClassNameMap [ item . split ( '-' ) [ 0 ] ] . indexOf ( '#' ) != - 1 ;
169
+
170
+ // 色值类
171
+ if ( bColorFlag ) {
172
+ sKey = item . match ( / \. \w + / ) [ 0 ] ;
173
+ }
174
+ // 数值类
175
+ else if ( / \d + / . test ( item ) ) {
162
176
sKey = item . match ( / \. \w + / ) [ 0 ] ;
177
+ // 通用类
163
178
} else {
164
179
sKey = item ;
165
180
}
@@ -170,10 +185,14 @@ module.exports = function(sSource) {
170
185
if ( [ '.wp' , '.hp' , '.fw' ] . includes ( sKey ) ) {
171
186
nValue = item . match ( / \d + / ) [ 0 ] ;
172
187
} else {
173
- / \d + / . test ( item ) && ( nValue = + item . match ( / \d + / ) [ 0 ] ) ;
188
+ if ( bColorFlag ) {
189
+ nValue = '#' + item . split ( '-' ) [ 1 ]
190
+ } else {
191
+ / \d + / . test ( item ) && ( nValue = + item . match ( / \d + / ) [ 0 ] ) ;
192
+ }
174
193
}
175
194
176
- aStyleStr . push ( `${ item } {${ oClassNameMap [ sKey ] . replace ( / \$ / g, nValue ) } }` ) ;
195
+ aStyleStr . push ( `${ item } {${ oClassNameMap [ sKey ] . replace ( / \$ | \# / g, nValue ) } }` ) ;
177
196
} ) ;
178
197
179
198
// 输出 debug 数据
0 commit comments