|
7 | 7 |
|
8 | 8 | $_internals: _mat-theming-internals-do-not-access; |
9 | 9 |
|
| 10 | +$_color-keys: ( |
| 11 | + primary, |
| 12 | + accent, |
| 13 | + warn, |
| 14 | + foreground, |
| 15 | + background, |
| 16 | + is-dark, |
| 17 | + color, /* included for themes that incorrectly nest the color config: (color: (color: (....))) */ |
| 18 | +); |
| 19 | + |
| 20 | +$_typography-keys: ( |
| 21 | + headline-1, |
| 22 | + headline-2, |
| 23 | + headline-3, |
| 24 | + headline-4, |
| 25 | + headline-5, |
| 26 | + headline-6, |
| 27 | + subtitle-1, |
| 28 | + font-famiy, |
| 29 | + subtitle-2, |
| 30 | + body-1, |
| 31 | + body-2, |
| 32 | + button, |
| 33 | + caption, |
| 34 | + overline, |
| 35 | +); |
| 36 | + |
10 | 37 | $_typography-properties: (font, font-family, line-height, font-size, letter-spacing, font-weight); |
11 | 38 |
|
12 | 39 | /// Checks whether the given theme contains error objects. |
@@ -137,22 +164,29 @@ $_typography-properties: (font, font-family, line-height, font-size, letter-spac |
137 | 164 | @return true; |
138 | 165 | } |
139 | 166 | @if $system == color { |
140 | | - @if not theming.private-is-theme-object($theme) { |
141 | | - @return map.has-key($theme, primary); |
142 | | - } |
143 | | - @return theming.get-color-config($theme) != null; |
| 167 | + $color: theming.get-color-config($theme); |
| 168 | + @return $color != null and _has-any-key($color, $_color-keys); |
144 | 169 | } |
145 | 170 | @if $system == typography { |
146 | | - @if not theming.private-is-theme-object($theme) { |
147 | | - @return map.has-key($theme, body-1); |
148 | | - } |
149 | | - @return theming.get-typography-config($theme) != null; |
| 171 | + $typography: theming.get-typography-config($theme); |
| 172 | + @return $typography != null and _has-any-key($typography, $_typography-keys); |
150 | 173 | } |
151 | 174 | @if $system == density { |
152 | | - @if not theming.private-is-theme-object($theme) { |
153 | | - @return $theme == minimum or $theme == maximum or meta.type-of($theme) == 'number'; |
154 | | - } |
155 | | - @return theming.get-density-config($theme) != null; |
| 175 | + $density: theming.get-density-config($theme); |
| 176 | + @return $density != null and _is-density-value($density); |
156 | 177 | } |
157 | 178 | @error 'Valid systems are: base, color, typography, density. Got:' $system; |
158 | 179 | } |
| 180 | + |
| 181 | +@function _has-any-key($theme, $keys) { |
| 182 | + @each $key in $keys { |
| 183 | + @if map.has-key($theme, $key) { |
| 184 | + @return true; |
| 185 | + } |
| 186 | + } |
| 187 | + @return false; |
| 188 | +} |
| 189 | + |
| 190 | +@function _is-density-value($theme) { |
| 191 | + @return $theme == minimum or $theme == maximum or meta.type-of($theme) == 'number'; |
| 192 | +} |
0 commit comments