Skip to content

Commit eeb0cf2

Browse files
committed
refactor(material/theming): add inspection compatibility flag
1 parent 685b585 commit eeb0cf2

File tree

4 files changed

+219
-158
lines changed

4 files changed

+219
-158
lines changed

src/material/_index.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
@forward './core/theming/theming' show define-light-theme, define-dark-theme,
33
define-palette, get-contrast-color-from-palette, get-color-from-palette,
44
get-color-config, get-typography-config, get-density-config,
5-
$theme-ignore-duplication-warnings;
5+
$theme-ignore-duplication-warnings, $theme-legacy-inspection-api-compatibility;
66
@forward './core/theming/theming' as private-* show private-clamp-density;
77
@forward './core/theming/palette' show $red-palette, $pink-palette, $indigo-palette,
88
$purple-palette, $deep-purple-palette, $blue-palette, $light-blue-palette, $cyan-palette,

src/material/core/theming/_m2-inspection.scss

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,17 @@
55

66
$_typography-properties: (font, font-family, line-height, font-size, letter-spacing, font-weight);
77

8+
/// Gets the m2-config from the theme.
9+
@function _get-m2-config($theme) {
10+
$internal: map.get($theme, _mat-theming-internals-do-not-access, m2-config);
11+
@return $internal or $theme;
12+
}
13+
814
/// Gets the type of theme represented by a theme object (light or dark).
915
/// @param {Map} $theme The theme
1016
/// @return {String} The type of theme (either `light` or `dark`).
1117
@function get-theme-type($theme) {
18+
$theme: _get-m2-config($theme);
1219
@if not theme-has($theme, color) {
1320
@error 'Color information is not available on this theme.';
1421
}
@@ -26,6 +33,7 @@ $_typography-properties: (font, font-family, line-height, font-size, letter-spac
2633
/// interpreted as a palette name).
2734
/// @return {Color} The requested theme color.
2835
@function get-theme-color($theme, $palette-name, $args...) {
36+
$theme: _get-m2-config($theme);
2937
@if not theme-has($theme, color) {
3038
@error 'Color information is not available on this theme.';
3139
}
@@ -44,6 +52,7 @@ $_typography-properties: (font, font-family, line-height, font-size, letter-spac
4452
/// (font, font-family, font-size, font-weight, line-height, or letter-spacing).
4553
/// @return {*} The value of the requested font property.
4654
@function get-theme-typography($theme, $typescale, $property) {
55+
$theme: _get-m2-config($theme);
4756
@if not theme-has($theme, typography) {
4857
@error 'Typography information is not available on this theme.';
4958
}
@@ -79,14 +88,20 @@ $_typography-properties: (font, font-family, line-height, font-size, letter-spac
7988
/// @param {Map} $theme The theme
8089
/// @return {Number} The density scale.
8190
@function get-theme-density($theme) {
91+
$theme: _get-m2-config($theme);
8292
@if not theme-has($theme, density) {
8393
@error 'Density information is not available on this theme.';
8494
}
8595
$scale: theming.get-density-config($theme);
8696
@return theming.clamp-density($scale, -5);
8797
}
8898

99+
/// Checks whether the theme has information about given theming system.
100+
/// @param {Map} $theme The theme
101+
/// @param {String} $system The system to check
102+
/// @param {Boolean} Whether the theme has information about the system.
89103
@function theme-has($theme, $system) {
104+
$theme: _get-m2-config($theme);
90105
$theme: theming.private-legacy-get-theme($theme);
91106
@if $system == base {
92107
@return true;

src/material/core/theming/_theming.scss

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
@use 'palette';
66
@use '../density/private/compatibility';
77

8+
$theme-legacy-inspection-api-compatibility: true !default;
9+
810
// Whether duplication warnings should be disabled. Warnings enabled by default.
911
$theme-ignore-duplication-warnings: false !default;
1012

@@ -544,7 +546,14 @@ $_internals: _mat-theming-internals-do-not-access;
544546
@return $theme;
545547
}
546548
$color: map.get($theme, color);
547-
@return map.merge($theme, $color);
549+
$m2-config: map.merge($theme, $color);
550+
$theme: (
551+
_mat-theming-internals-do-not-access: (
552+
theme-version: 0,
553+
m2-config: $m2-config,
554+
)
555+
);
556+
@return map.merge(if($theme-legacy-inspection-api-compatibility, $m2-config, ()), $theme);
548557
}
549558

550559
// Gets the theme from the given value that is either already a theme, or a color configuration.

0 commit comments

Comments
 (0)