@@ -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 ,
@@ -361,7 +379,8 @@ function ThemingProvider($mdColorPalette, $$mdMetaProvider) {
361
379
/**
362
380
* @ngdoc method
363
381
* @name $mdThemingProvider#setDefaultTheme
364
- * @param {string } theme Default theme name to be applied to elements. Default value is `default`.
382
+ * @param {string } theme Default theme name to be applied to elements.
383
+ * Default value is `default`.
365
384
*/
366
385
setDefaultTheme : function ( theme ) {
367
386
defaultTheme = theme ;
@@ -565,7 +584,7 @@ function ThemingProvider($mdColorPalette, $$mdMetaProvider) {
565
584
Object . keys ( color . hues ) . map ( function ( key ) {
566
585
return color . hues [ key ] ;
567
586
} ) . forEach ( function ( hueValue ) {
568
- if ( VALID_HUE_VALUES . indexOf ( hueValue ) == - 1 ) {
587
+ if ( VALID_HUE_VALUES . indexOf ( hueValue ) === - 1 ) {
569
588
throw new Error ( "Invalid hue value '%1' in theme %2's %3 color %4. Available hue values: %5"
570
589
. replace ( '%1' , hueValue )
571
590
. replace ( '%2' , self . name )
@@ -993,9 +1012,8 @@ function parseRules(theme, colorType, rules) {
993
1012
rules = rules . replace ( / T H E M E _ N A M E / g, theme . name ) ;
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;
998
- var palette = PALETTES [ color . name ] ;
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;
999
1017
var defaultBgHue = theme . colors [ 'background' ] . hues [ 'default' ] ;
1000
1018
var defaultBgContrastType = PALETTES [ theme . colors [ 'background' ] . name ] [ defaultBgHue ] . contrastType ;
1001
1019
@@ -1005,20 +1023,20 @@ function parseRules(theme, colorType, rules) {
1005
1023
rules = rules . replace ( simpleVariableRegex , function ( match , colorType , hue , contrast , opacity ) {
1006
1024
var regexColorType = colorType ;
1007
1025
if ( colorType === 'foreground' ) {
1008
- if ( hue == 'shadow' ) {
1026
+ if ( hue === 'shadow' ) {
1009
1027
return theme . foregroundShadow ;
1010
1028
} else if ( theme . foregroundPalette [ hue ] ) {
1011
1029
// Use user defined palette number (ie: foreground-2)
1012
- return rgba ( colorToRgbaArray ( theme . foregroundPalette [ hue ] ) ) ;
1030
+ return rgba ( colorToRgbaArray ( theme . foregroundPalette [ hue ] ) ) ;
1013
1031
} else if ( theme . foregroundPalette [ '1' ] ) {
1014
- return rgba ( colorToRgbaArray ( theme . foregroundPalette [ '1' ] ) ) ;
1032
+ return rgba ( colorToRgbaArray ( theme . foregroundPalette [ '1' ] ) ) ;
1015
1033
}
1016
1034
// Default to background-default-contrast-{opacity}
1017
1035
colorType = 'background' ;
1018
1036
contrast = 'contrast' ;
1019
1037
if ( ! opacity && hue ) {
1020
- // Convert references to legacy hues to opacities (ie: foreground-4 to *-divider)
1021
- switch ( hue ) {
1038
+ // Convert references to legacy hues to opacities (i.e. foreground-4 to *-divider)
1039
+ switch ( hue ) {
1022
1040
// hue-1 uses default opacity
1023
1041
case '2' :
1024
1042
opacity = 'secondary' ;
@@ -1042,7 +1060,8 @@ function parseRules(theme, colorType, rules) {
1042
1060
var colorDetails = ( PALETTES [ theme . colors [ colorType ] . name ] [ hue ] || '' ) ;
1043
1061
1044
1062
// If user has specified a foreground color, use those
1045
- if ( colorType === 'background' && contrast && regexColorType !== 'foreground' && colorDetails . contrastType == defaultBgContrastType ) {
1063
+ if ( colorType === 'background' && contrast && regexColorType !== 'foreground' &&
1064
+ colorDetails . contrastType === defaultBgContrastType ) {
1046
1065
// Don't process if colorType was changed
1047
1066
switch ( opacity ) {
1048
1067
case 'secondary' :
@@ -1077,8 +1096,6 @@ function parseRules(theme, colorType, rules) {
1077
1096
return rgba ( colorDetails [ contrast ? 'contrast' : 'value' ] , opacity ) ;
1078
1097
} ) ;
1079
1098
1080
- // Matches '{{ primary-color }}', etc
1081
- var hueRegex = new RegExp ( '(\'|")?{{\\s*([a-zA-Z]+)-(color|contrast)-?(\\d\\.?\\d*)?\\s*}}("|\')?' , 'g' ) ;
1082
1099
var generatedRules = [ ] ;
1083
1100
1084
1101
// For each type, generate rules for each hue (ie. default, md-hue-1, md-hue-2, md-hue-3)
@@ -1099,8 +1116,8 @@ function parseRules(theme, colorType, rules) {
1099
1116
1100
1117
// Don't apply a selector rule to the default theme, making it easier to override
1101
1118
// 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;
1119
+ if ( theme . name === 'default' ) {
1120
+ var themeRuleRegex = / ( (?: \s | > | \. | \w | - | : | \( | \) | \[ | ] | " | ' | = ) * ) \. m d - d e f a u l t - t h e m e ( (?: \s | > | \. | \w | - | : | \( | \) | \[ | ] | " | ' | = ) * ) / g;
1104
1121
1105
1122
newRule = newRule . replace ( themeRuleRegex , function ( match , start , end ) {
1106
1123
return match + ', ' + start + end ;
@@ -1134,7 +1151,7 @@ function generateAllThemes($injector, $mdTheming) {
1134
1151
1135
1152
// Break the CSS into individual rules
1136
1153
var rules = themeCss
1137
- . split ( / \ }(? ! ( \} | ' | " | ; ) ) / )
1154
+ . split ( / } (? ! ( [ } ' " ; ] ) ) / )
1138
1155
. filter ( function ( rule ) { return rule && rule . trim ( ) . length ; } )
1139
1156
. map ( function ( rule ) { return rule . trim ( ) + '}' ; } ) ;
1140
1157
@@ -1178,9 +1195,12 @@ function generateAllThemes($injector, $mdTheming) {
1178
1195
// Internal functions
1179
1196
// *************************
1180
1197
1181
- // The user specifies a 'default' contrast color as either light or dark,
1182
- // then explicitly lists which hues are the opposite contrast (eg. A100 has dark, A200 has light)
1183
- function sanitizePalette ( palette , name ) {
1198
+ /**
1199
+ * The user specifies a 'default' contrast color as either light or dark, then explicitly lists
1200
+ * which hues are the opposite contrast (eg. A100 has dark, A200 has light).
1201
+ * @param {!object } palette to sanitize
1202
+ */
1203
+ function sanitizePalette ( palette ) {
1184
1204
var defaultContrast = palette . contrastDefaultColor ;
1185
1205
var lightColors = palette . contrastLightColors || [ ] ;
1186
1206
var strongLightColors = palette . contrastStrongLightColors || [ ] ;
@@ -1207,7 +1227,7 @@ function generateAllThemes($injector, $mdTheming) {
1207
1227
return 'light' ;
1208
1228
}
1209
1229
function getContrastColor ( contrastType ) {
1210
- switch ( contrastType ) {
1230
+ switch ( contrastType ) {
1211
1231
default :
1212
1232
case 'strongLight' :
1213
1233
return STRONG_LIGHT_CONTRAST_COLOR ;
@@ -1218,7 +1238,7 @@ function generateAllThemes($injector, $mdTheming) {
1218
1238
}
1219
1239
}
1220
1240
function getOpacityValues ( contrastType ) {
1221
- switch ( contrastType ) {
1241
+ switch ( contrastType ) {
1222
1242
default :
1223
1243
case 'strongLight' :
1224
1244
return STRONG_LIGHT_CONTRAST_OPACITY ;
@@ -1294,13 +1314,13 @@ function checkValidPalette(theme, colorType) {
1294
1314
}
1295
1315
1296
1316
function colorToRgbaArray ( clr ) {
1297
- if ( angular . isArray ( clr ) && clr . length == 3 ) return clr ;
1317
+ if ( angular . isArray ( clr ) && clr . length === 3 ) return clr ;
1298
1318
if ( / ^ r g b / . test ( clr ) ) {
1299
1319
return clr . replace ( / ( ^ \s * r g b a ? \( | \) \s * $ ) / g, '' ) . split ( ',' ) . map ( function ( value , i ) {
1300
- return i == 3 ? parseFloat ( value , 10 ) : parseInt ( value , 10 ) ;
1320
+ return i === 3 ? parseFloat ( value ) : parseInt ( value , 10 ) ;
1301
1321
} ) ;
1302
1322
}
1303
- if ( clr . charAt ( 0 ) == '#' ) clr = clr . substring ( 1 ) ;
1323
+ if ( clr . charAt ( 0 ) === '#' ) clr = clr . substring ( 1 ) ;
1304
1324
if ( ! / ^ ( [ a - f A - F 0 - 9 ] { 3 } ) { 1 , 2 } $ / g. test ( clr ) ) return ;
1305
1325
1306
1326
var dig = clr . length / 3 ;
@@ -1318,7 +1338,7 @@ function colorToRgbaArray(clr) {
1318
1338
function rgba ( rgbArray , opacity ) {
1319
1339
if ( ! rgbArray ) return "rgb('0,0,0')" ;
1320
1340
1321
- if ( rgbArray . length == 4 ) {
1341
+ if ( rgbArray . length === 4 ) {
1322
1342
rgbArray = angular . copy ( rgbArray ) ;
1323
1343
opacity ? rgbArray . pop ( ) : opacity = rgbArray . pop ( ) ;
1324
1344
}
0 commit comments