@@ -18,11 +18,11 @@ $_system-level-prefix: sys;
1818/// config map. The config map can have values color, typography, and/or density.
1919///
2020/// If the config map's color value is an Angular Material color palette, it will be used as the
21- /// primary and tertiary colors with a light theme type. Otherwise if the color value is a map,
21+ /// primary and tertiary colors with a `color-scheme` theme type. Otherwise if the color value is a map,
2222/// it must have a `primary` value containing an Angular Material color palette, and optionally
2323/// a different `tertiary` palette (defaults to primary palette) and `theme-type` that is either
24- /// `light` or `dark` (defaults to light ). Color variable definitions will not be emitted if there
25- /// are no color values in the config.
24+ /// `light`, `dark`, or 'color-scheme` (defaults to `color-scheme` ). Color variable definitions will
25+ /// not be emitted if there are no color values in the config.
2626///
2727/// If the config map's typography value is a font family string, it will be used as the
2828/// plain and brand font family with default bold, medium, and regular weights of 700, 500, and 400,
@@ -44,9 +44,14 @@ $_system-level-prefix: sys;
4444 $color : map .get ($config , color );
4545 $color-config : null;
4646 @if ($color ) {
47+ // Default to "color-scheme" theme type if the config's color does not provide one.
48+ @if (meta .type-of ($color ) == ' map' and not map .has-key ($color , theme-type )) {
49+ $color : map .set ($color , theme-type , color-scheme );
50+ }
51+
4752 $color-config : if (meta .type-of ($color ) == ' map' ,
4853 definition .define-colors ($color ),
49- definition .define-colors ((primary: $color )));
54+ definition .define-colors ((primary: $color , theme - type: color-scheme )));
5055 @include system-level-colors ($color-config , $overrides , $_system-fallback-prefix );
5156 @include system-level-elevation ($color-config , $overrides , $_system-fallback-prefix );
5257 }
@@ -126,9 +131,7 @@ $_system-level-prefix: sys;
126131 md- ref- palette: m3-tokens .generate-ref-palette-tokens ($primary , $tertiary , $error )
127132 );
128133
129- $sys-colors : if ($type == dark ,
130- definitions .md-sys-color-values-dark ($ref ),
131- definitions .md-sys-color-values-light ($ref ));
134+ $sys-colors : _generate-sys-colors ($ref , $type );
132135
133136 // Manually insert a subset of palette values that are used directly by components
134137 // instead of system variables.
@@ -144,6 +147,29 @@ $_system-level-prefix: sys;
144147 }
145148}
146149
150+ @function _generate-sys-colors ($ref , $type ) {
151+ $light-sys-colors : definitions .md-sys-color-values-light ($ref );
152+ @if ($type == light ) {
153+ @return $light-sys-colors ;
154+ }
155+
156+ $dark-sys-colors : definitions .md-sys-color-values-dark ($ref );
157+ @if ($type == dark ) {
158+ @return $dark-sys-colors ;
159+ }
160+
161+ @if ($type == color-scheme ) {
162+ $light-dark-sys-colors : ();
163+ @each $name , $light-value in $light-sys-colors {
164+ $dark-value : map .get ($dark-sys-colors , $name );
165+ $light-dark-sys-colors : map .set ($light-dark-sys-colors , $name , light-dark ($light-value , $dark-value ));
166+ }
167+ @return $light-dark-sys-colors ;
168+ }
169+
170+ @error ' Unknown theme-type provided: #{$type } ' ;
171+ }
172+
147173@mixin system-level-typography ($theme , $overrides : (), $prefix : null) {
148174 $font-definition : map .get ($theme , _mat-theming-internals-do-not-access , font-definition );
149175 $brand : map .get ($font-definition , brand );
0 commit comments