@@ -134,9 +134,26 @@ function detectDisabledThemes($mdThemingProvider) {
134
134
* {{primary-contrast}} - Generates .md-hue-1, .md-hue-2, .md-hue-3 with configured contrast (ie. text) color shades set for each hue
135
135
* {{primary-contrast-0.7}} - Apply 0.7 opacity to each of the above rules
136
136
* {{primary-contrast-divider}} - Apply divider opacity to contrast color
137
- * {{background-default-contrast}} - Apply primary text color for contrasting with default background
138
- * {{background-50-contrast-icon}} - Apply contrast color for icon on background's shade 50 hue
139
137
*
138
+ * Foreground expansion: Applies rgba to black/white foreground text
139
+ *
140
+ * Old Foreground Expressions:
141
+ * {{foreground-1}} - used for primary text
142
+ * {{foreground-2}} - used for secondary text/divider
143
+ * {{foreground-3}} - used for disabled text
144
+ * {{foreground-4}} - used for dividers
145
+ *
146
+ * New Foreground Expressions:
147
+ *
148
+ * Apply primary text color for contrasting with default background
149
+ * {{background-default-contrast}} - default opacity
150
+ * {{background-default-contrast-secondary}} - opacity for secondary text
151
+ * {{background-default-contrast-hint}} - opacity for hints and placeholders
152
+ * {{background-default-contrast-disabled}} - opacity for disabled text
153
+ * {{background-default-contrast-divider}} - opacity for dividers
154
+ *
155
+ * Apply contrast color for specific shades
156
+ * {{background-50-contrast-icon}} - Apply contrast color for icon on background's shade 50 hue
140
157
*/
141
158
142
159
// In memory generated CSS rules; registered by theme.name
@@ -190,9 +207,8 @@ var DARK_DEFAULT_HUES = {
190
207
}
191
208
} ;
192
209
193
- // use inactive icon opacity from https://material.google.com/style/color.html#color-text-background-colors
194
- // not inactive icon opacity from https://material.google.com/style/icons.html#icons-system-icons
195
-
210
+ // Icon opacity values (active/inactive) from
211
+ // https://material.io/archive/guidelines/style/icons.html#icons-system-icons
196
212
var DARK_CONTRAST_OPACITY = {
197
213
'icon' : 0.54 ,
198
214
'secondary' : 0.54 ,
@@ -209,6 +225,8 @@ var LIGHT_CONTRAST_OPACITY = {
209
225
'divider' : 0.12
210
226
} ;
211
227
228
+ // Icon opacity values (active/inactive) from
229
+ // https://material.io/archive/guidelines/style/icons.html#icons-system-icons
212
230
var STRONG_LIGHT_CONTRAST_OPACITY = {
213
231
'icon' : 1.0 ,
214
232
'secondary' : 0.7 ,
@@ -991,10 +1009,11 @@ function parseRules(theme, colorType, rules) {
991
1009
checkValidPalette ( theme , colorType ) ;
992
1010
993
1011
rules = rules . replace ( / T H E M E _ N A M E / g, theme . name ) ;
1012
+ var color = theme . colors [ colorType ] ;
994
1013
var themeNameRegex = new RegExp ( '\\.md-' + theme . name + '-theme' , 'g' ) ;
995
1014
// Matches '{{ primary-color }}', etc
996
- var hueRegex = new RegExp ( '(?: \'|")?{{\\s*(' + colorType + ' )-?(color|default)?-?(contrast)?-?((?:\\d\\.?\\d*)|(?:[a-zA-Z]+))?\\s*}}(\ "|\')?', 'g' ) ;
997
- var simpleVariableRegex = / ' ? " ? \{ \ {\s * ( [ a - z A - Z ] + ) - ( A ? \d + | h u e - [ 0 - 3 ] | s h a d o w | d e f a u l t ) - ? ( c o n t r a s t ) ? - ? ( (?: \d \. ? \d * ) | (?: [ a - z A - Z ] + ) ) ? \s * \} \ }' ? " ? / g;
1015
+ var hueRegex = new RegExp ( '(\'|")?{{\\s*([a-zA-Z]+ )-?(color|default)?-?(contrast)?-?((?:\\d\\.?\\d*)|(?:[a-zA-Z]+))?\\s*}}("|\')?' , 'g' ) ;
1016
+ var simpleVariableRegex = / ' ? " ? { { \s * ( [ a - z A - Z ] + ) - ( A ? \d + | h u e - [ 0 - 3 ] | s h a d o w | d e f a u l t ) - ? ( c o n t r a s t ) ? - ? ( (?: \d \. ? \d * ) | (?: [ a - z A - Z ] + ) ) ? \s * } } ' ? " ? / g;
998
1017
var palette = PALETTES [ color . name ] ;
999
1018
var defaultBgHue = theme . colors [ 'background' ] . hues [ 'default' ] ;
1000
1019
var defaultBgContrastType = PALETTES [ theme . colors [ 'background' ] . name ] [ defaultBgHue ] . contrastType ;
@@ -1005,20 +1024,20 @@ function parseRules(theme, colorType, rules) {
1005
1024
rules = rules . replace ( simpleVariableRegex , function ( match , colorType , hue , contrast , opacity ) {
1006
1025
var regexColorType = colorType ;
1007
1026
if ( colorType === 'foreground' ) {
1008
- if ( hue == 'shadow' ) {
1027
+ if ( hue === 'shadow' ) {
1009
1028
return theme . foregroundShadow ;
1010
1029
} else if ( theme . foregroundPalette [ hue ] ) {
1011
1030
// Use user defined palette number (ie: foreground-2)
1012
- return rgba ( colorToRgbaArray ( theme . foregroundPalette [ hue ] ) ) ;
1031
+ return rgba ( colorToRgbaArray ( theme . foregroundPalette [ hue ] ) ) ;
1013
1032
} else if ( theme . foregroundPalette [ '1' ] ) {
1014
- return rgba ( colorToRgbaArray ( theme . foregroundPalette [ '1' ] ) ) ;
1033
+ return rgba ( colorToRgbaArray ( theme . foregroundPalette [ '1' ] ) ) ;
1015
1034
}
1016
1035
// Default to background-default-contrast-{opacity}
1017
1036
colorType = 'background' ;
1018
1037
contrast = 'contrast' ;
1019
1038
if ( ! opacity && hue ) {
1020
- // Convert references to legacy hues to opacities (ie: foreground-4 to *-divider)
1021
- switch ( hue ) {
1039
+ // Convert references to legacy hues to opacities (i.e. foreground-4 to *-divider)
1040
+ switch ( hue ) {
1022
1041
// hue-1 uses default opacity
1023
1042
case '2' :
1024
1043
opacity = 'secondary' ;
@@ -1042,7 +1061,8 @@ function parseRules(theme, colorType, rules) {
1042
1061
var colorDetails = ( PALETTES [ theme . colors [ colorType ] . name ] [ hue ] || '' ) ;
1043
1062
1044
1063
// If user has specified a foreground color, use those
1045
- if ( colorType === 'background' && contrast && regexColorType !== 'foreground' && colorDetails . contrastType == defaultBgContrastType ) {
1064
+ if ( colorType === 'background' && contrast && regexColorType !== 'foreground' &&
1065
+ colorDetails . contrastType === defaultBgContrastType ) {
1046
1066
// Don't process if colorType was changed
1047
1067
switch ( opacity ) {
1048
1068
case 'secondary' :
@@ -1077,8 +1097,6 @@ function parseRules(theme, colorType, rules) {
1077
1097
return rgba ( colorDetails [ contrast ? 'contrast' : 'value' ] , opacity ) ;
1078
1098
} ) ;
1079
1099
1080
- // Matches '{{ primary-color }}', etc
1081
- var hueRegex = new RegExp ( '(\'|")?{{\\s*([a-zA-Z]+)-(color|contrast)-?(\\d\\.?\\d*)?\\s*}}("|\')?' , 'g' ) ;
1082
1100
var generatedRules = [ ] ;
1083
1101
1084
1102
// For each type, generate rules for each hue (ie. default, md-hue-1, md-hue-2, md-hue-3)
@@ -1099,8 +1117,8 @@ function parseRules(theme, colorType, rules) {
1099
1117
1100
1118
// Don't apply a selector rule to the default theme, making it easier to override
1101
1119
// styles of the base-component
1102
- if ( theme . name == 'default' ) {
1103
- var themeRuleRegex = / ( (?: \s | > | \. | \w | - | : | \( | \) | \[ | \ ]| " | ' | = ) * ) \. m d - d e f a u l t - t h e m e ( (?: \s | > | \. | \w | - | : | \( | \) | \[ | \ ]| " | ' | = ) * ) / g;
1120
+ if ( theme . name === 'default' ) {
1121
+ var themeRuleRegex = / ( (?: \s | > | \. | \w | - | : | \( | \) | \[ | ] | " | ' | = ) * ) \. m d - d e f a u l t - t h e m e ( (?: \s | > | \. | \w | - | : | \( | \) | \[ | ] | " | ' | = ) * ) / g;
1104
1122
1105
1123
newRule = newRule . replace ( themeRuleRegex , function ( match , start , end ) {
1106
1124
return match + ', ' + start + end ;
@@ -1134,7 +1152,7 @@ function generateAllThemes($injector, $mdTheming) {
1134
1152
1135
1153
// Break the CSS into individual rules
1136
1154
var rules = themeCss
1137
- . split ( / \ }(? ! ( \ }| ' | " | ; ) ) / )
1155
+ . split ( / } (? ! ( } | ' | " | ; ) ) / )
1138
1156
. filter ( function ( rule ) { return rule && rule . trim ( ) . length ; } )
1139
1157
. map ( function ( rule ) { return rule . trim ( ) + '}' ; } ) ;
1140
1158
@@ -1207,7 +1225,7 @@ function generateAllThemes($injector, $mdTheming) {
1207
1225
return 'light' ;
1208
1226
}
1209
1227
function getContrastColor ( contrastType ) {
1210
- switch ( contrastType ) {
1228
+ switch ( contrastType ) {
1211
1229
default :
1212
1230
case 'strongLight' :
1213
1231
return STRONG_LIGHT_CONTRAST_COLOR ;
@@ -1218,7 +1236,7 @@ function generateAllThemes($injector, $mdTheming) {
1218
1236
}
1219
1237
}
1220
1238
function getOpacityValues ( contrastType ) {
1221
- switch ( contrastType ) {
1239
+ switch ( contrastType ) {
1222
1240
default :
1223
1241
case 'strongLight' :
1224
1242
return STRONG_LIGHT_CONTRAST_OPACITY ;
0 commit comments