@@ -53,6 +53,9 @@ $_typography-properties: (font, font-family, line-height, font-size, letter-spac
53
53
// TODO(mmalerba): implement for old style theme objects.
54
54
@error #{' get-theme-type does not support legacy theme objects.' } ;
55
55
}
56
+ @if not theme-has ($theme , color ) {
57
+ @error ' Color information is not available on this theme.' ;
58
+ }
56
59
@return map .get ($theme , $_internals , theme-type ) or light ;
57
60
}
58
61
@@ -86,6 +89,9 @@ $_typography-properties: (font, font-family, line-height, font-size, letter-spac
86
89
// TODO(mmalerba): implement for old style theme objects.
87
90
@error #{' get-theme-color does not support legacy theme objects.' } ;
88
91
}
92
+ @if not theme-has ($theme , color ) {
93
+ @error ' Color information is not available on this theme.' ;
94
+ }
89
95
$color-roles : map .get ($theme , $_internals , color-tokens , (mdc, theme));
90
96
$result : map .get ($color-roles , $color-role-name );
91
97
@if not $result {
@@ -105,6 +111,9 @@ $_typography-properties: (font, font-family, line-height, font-size, letter-spac
105
111
// TODO(mmalerba): implement for old style theme objects.
106
112
@error #{' get-theme-color does not support legacy theme objects.' } ;
107
113
}
114
+ @if not theme-has ($theme , color ) {
115
+ @error ' Color information is not available on this theme.' ;
116
+ }
108
117
$palettes : map .get ($theme , $_internals , palettes );
109
118
$palette : map .get ($palettes , $palette-name );
110
119
@if not $palette {
@@ -131,6 +140,9 @@ $_typography-properties: (font, font-family, line-height, font-size, letter-spac
131
140
// TODO(mmalerba): implement for old style theme objects.
132
141
@error #{' get-theme-typography does not support legacy theme objects.' } ;
133
142
}
143
+ @if not theme-has ($theme , typography ) {
144
+ @error ' Typography information is not available on this theme.' ;
145
+ }
134
146
@if not list .index ($_m3-typescales , $typescale ) {
135
147
@error #{' Valid typescales are: #{$_m3-typescales } . Got:' } $typescale ;
136
148
}
@@ -158,9 +170,39 @@ $_typography-properties: (font, font-family, line-height, font-size, letter-spac
158
170
// TODO(mmalerba): implement for old style theme objects.
159
171
@error #{' get-theme-density does not support legacy theme objects.' } ;
160
172
}
173
+ @if not theme-has ($theme , density ) {
174
+ @error ' Density information is not available on this theme.' ;
175
+ }
161
176
@return map .get ($theme , $_internals , density-scale );
162
177
}
163
178
179
+ /// Checks whether the theme has information about given theming system.
180
+ /// @param {Map} $theme The theme
181
+ /// @param {String} $system The system to check
182
+ /// @param {Boolean} Whether the theme has information about the system.
183
+ @function theme-has ($theme , $system ) {
184
+ $err : _validate-theme-object ($theme );
185
+ @if $err {
186
+ // TODO(mmalerba): implement for old style theme objects.
187
+ @error #{' get-theme-density does not support legacy theme objects.' } ;
188
+ }
189
+ @if $system == base {
190
+ @return map .get ($theme , $_internals , base-tokens ) != null;
191
+ }
192
+ @if $system == color {
193
+ @return map .get ($theme , $_internals , color-tokens ) != null and
194
+ map .get ($theme , $_internals , theme-type ) != null and
195
+ map .get ($theme , $_internals , palettes ) != null;
196
+ }
197
+ @if $system == typography {
198
+ @return map .get ($theme , $_internals , typography-tokens ) != null;
199
+ }
200
+ @if $system == density {
201
+ @return map .get ($theme , $_internals , density-scale ) != null
202
+ }
203
+ @error ' Valid systems are: base, color, typography, density. Got:' $system ;
204
+ }
205
+
164
206
/// Gets the set of tokens from the given theme, limited to those affected by the requested theming
165
207
/// systems.
166
208
/// @param {Map} $theme The theme to get tokens from.
0 commit comments