@@ -54,31 +54,58 @@ for (var prop in fontVariantProperties) {
54
54
}
55
55
}
56
56
57
+ // Find font-feature-settings declaration before given declaration,
58
+ // create if does not exist
59
+ function getFontFeatureSettingsPrevTo ( decl ) {
60
+ var fontFeatureSettings = null ;
61
+ decl . parent . eachDecl ( function ( decl ) {
62
+ if ( decl . prop === "font-feature-settings" ) {
63
+ fontFeatureSettings = decl ;
64
+ }
65
+ } )
66
+
67
+ if ( fontFeatureSettings === null ) {
68
+ fontFeatureSettings = decl . clone ( )
69
+ fontFeatureSettings . prop = "font-feature-settings"
70
+ fontFeatureSettings . value = ""
71
+ decl . parent . insertBefore ( decl , fontFeatureSettings )
72
+ }
73
+ return fontFeatureSettings
74
+ }
75
+
57
76
/**
58
77
* Expose the font-variant plugin.
59
78
*/
60
79
module . exports = function postcssFontVariant ( ) {
61
80
return function ( styles ) {
62
- // read custom media queries
63
- styles . eachDecl ( function ( decl ) {
64
- if ( ! fontVariantProperties [ decl . prop ] ) {
65
- return null
66
- }
81
+ styles . eachRule ( function ( rule ) {
82
+ var fontFeatureSettings = null
83
+ // read custom media queries
84
+ rule . eachDecl ( function ( decl ) {
85
+ if ( ! fontVariantProperties [ decl . prop ] ) {
86
+ return null
87
+ }
67
88
68
- var newValue = decl . value
69
- if ( decl . prop === "font-variant" ) {
70
- newValue = decl . value . split ( / \s + / g) . map ( function ( val ) {
71
- return fontVariantProperties [ "font-variant" ] [ val ]
72
- } ) . join ( ", " )
73
- }
74
- else if ( fontVariantProperties [ decl . prop ] [ decl . value ] ) {
75
- newValue = fontVariantProperties [ decl . prop ] [ decl . value ]
76
- }
89
+ var newValue = decl . value
90
+ if ( decl . prop === "font-variant" ) {
91
+ newValue = decl . value . split ( / \s + / g) . map ( function ( val ) {
92
+ return fontVariantProperties [ "font-variant" ] [ val ]
93
+ } ) . join ( ", " )
94
+ }
95
+ else if ( fontVariantProperties [ decl . prop ] [ decl . value ] ) {
96
+ newValue = fontVariantProperties [ decl . prop ] [ decl . value ]
97
+ }
77
98
78
- var newDecl = decl . clone ( )
79
- newDecl . prop = "font-feature-settings"
80
- newDecl . value = newValue
81
- decl . parent . insertBefore ( decl , newDecl )
99
+ if ( fontFeatureSettings === null ) {
100
+ fontFeatureSettings = getFontFeatureSettingsPrevTo ( decl ) ;
101
+ }
102
+ if ( fontFeatureSettings . value ) {
103
+ fontFeatureSettings . value += ", " + newValue ;
104
+ }
105
+ else {
106
+ fontFeatureSettings . value = newValue ;
107
+ }
108
+ } )
82
109
} )
83
110
}
84
111
}
0 commit comments