@angular/material 17.0.0-next.0 → 17.0.0-next.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (204) hide show
  1. package/_index.scss +3 -4
  2. package/autocomplete/_autocomplete-theme.scss +12 -18
  3. package/autocomplete/index.d.ts +15 -24
  4. package/badge/_badge-theme.scss +15 -27
  5. package/badge/index.d.ts +9 -17
  6. package/bottom-sheet/_bottom-sheet-theme.scss +13 -22
  7. package/button/_button-base.scss +3 -3
  8. package/button/_button-theme-private.scss +3 -2
  9. package/button/_button-theme.scss +18 -25
  10. package/button/_fab-theme.scss +31 -49
  11. package/button/_icon-button-theme.scss +19 -26
  12. package/button/index.d.ts +22 -31
  13. package/button-toggle/_button-toggle-theme.scss +17 -28
  14. package/button-toggle/index.d.ts +15 -18
  15. package/card/_card-theme.scss +27 -38
  16. package/checkbox/_checkbox-theme.scss +28 -45
  17. package/checkbox/index.d.ts +21 -27
  18. package/chips/_chips-theme.scss +18 -56
  19. package/core/_core-theme.scss +24 -39
  20. package/core/color/_all-color.scss +7 -15
  21. package/core/density/private/_all-density.scss +34 -39
  22. package/core/focus-indicators/_focus-indicators-theme.scss +6 -8
  23. package/core/focus-indicators/_private.scss +22 -26
  24. package/core/index.d.ts +7 -11
  25. package/core/mdc-helpers/_mdc-helpers.scss +19 -22
  26. package/core/option/_optgroup-theme.scss +13 -23
  27. package/core/option/_option-theme.scss +23 -37
  28. package/core/ripple/_ripple-theme.scss +6 -10
  29. package/core/selection/pseudo-checkbox/_pseudo-checkbox-theme.scss +17 -24
  30. package/core/style/_form-common.scss +7 -7
  31. package/core/style/_private.scss +5 -7
  32. package/core/style/_sass-utils.scss +7 -0
  33. package/core/testing/index.d.ts +2 -1
  34. package/core/theming/_all-theme.scss +41 -41
  35. package/core/theming/_inspection.scss +133 -59
  36. package/core/theming/_m2-inspection.scss +268 -0
  37. package/core/theming/_theming.scss +59 -20
  38. package/core/tokens/m2/mat/_autocomplete.scss +5 -8
  39. package/core/tokens/m2/mat/_badge.scss +12 -15
  40. package/core/tokens/m2/mat/_bottom-sheet.scss +11 -17
  41. package/core/tokens/m2/mat/_card.scss +15 -21
  42. package/core/tokens/m2/mat/_datepicker.scss +28 -38
  43. package/core/tokens/m2/mat/_divider.scss +5 -8
  44. package/core/tokens/m2/mat/_expansion.scss +24 -28
  45. package/core/tokens/m2/mat/_form-field.scss +21 -25
  46. package/core/tokens/m2/mat/_grid-list.scss +8 -8
  47. package/core/tokens/m2/mat/_icon.scss +3 -3
  48. package/core/tokens/m2/mat/_legacy-button-toggle.scss +15 -19
  49. package/core/tokens/m2/mat/_menu.scss +12 -17
  50. package/core/tokens/m2/mat/_optgroup.scss +12 -17
  51. package/core/tokens/m2/mat/_option.scss +16 -28
  52. package/core/tokens/m2/mat/_paginator.scss +16 -18
  53. package/core/tokens/m2/mat/_radio.scss +7 -10
  54. package/core/tokens/m2/mat/_select.scss +15 -29
  55. package/core/tokens/m2/mat/_sidenav.scss +12 -14
  56. package/core/tokens/m2/mat/_slide-toggle.scss +9 -17
  57. package/core/tokens/m2/mat/_slider.scss +5 -5
  58. package/core/tokens/m2/mat/_snack-bar.scss +7 -8
  59. package/core/tokens/m2/mat/_standard-button-toggle.scss +23 -22
  60. package/core/tokens/m2/mat/_stepper.scss +30 -33
  61. package/core/tokens/m2/mat/_tab-header-with-background.scss +6 -8
  62. package/core/tokens/m2/mat/_tab-header.scss +13 -18
  63. package/core/tokens/m2/mat/_table.scss +19 -23
  64. package/core/tokens/m2/mat/_toolbar.scss +12 -16
  65. package/core/tokens/m2/mdc/_checkbox.scss +21 -20
  66. package/core/tokens/m2/mdc/_chip.scss +38 -24
  67. package/core/tokens/m2/mdc/_circular-progress.scss +5 -6
  68. package/core/tokens/m2/mdc/_dialog.scss +16 -30
  69. package/core/tokens/m2/mdc/_elevated-card.scss +6 -9
  70. package/core/tokens/m2/mdc/_extended-fab.scss +8 -17
  71. package/core/tokens/m2/mdc/_fab.scss +6 -7
  72. package/core/tokens/m2/mdc/_filled-text-field.scss +16 -22
  73. package/core/tokens/m2/mdc/_icon-button.scss +3 -3
  74. package/core/tokens/m2/mdc/_linear-progress.scss +9 -10
  75. package/core/tokens/m2/mdc/_list.scss +44 -42
  76. package/core/tokens/m2/mdc/_outlined-card.scss +7 -10
  77. package/core/tokens/m2/mdc/_outlined-text-field.scss +14 -20
  78. package/core/tokens/m2/mdc/_plain-tooltip.scss +9 -22
  79. package/core/tokens/m2/mdc/_radio.scss +11 -11
  80. package/core/tokens/m2/mdc/_slider.scss +16 -23
  81. package/core/tokens/m2/mdc/_snack-bar.scss +10 -23
  82. package/core/tokens/m2/mdc/_switch.scss +16 -19
  83. package/core/tokens/m2/mdc/_tab-indicator.scss +5 -8
  84. package/core/tokens/m2/mdc/_tab.scss +5 -4
  85. package/core/typography/_all-typography.scss +44 -47
  86. package/core/typography/_definition.scss +258 -0
  87. package/core/typography/_property-getters.scss +63 -0
  88. package/core/typography/_typography-utils.scss +9 -69
  89. package/core/typography/_typography.scss +38 -494
  90. package/core/typography/_versioning.scss +91 -0
  91. package/datepicker/_datepicker-theme.scss +20 -34
  92. package/datepicker/index.d.ts +3 -3
  93. package/dialog/_dialog-theme.scss +22 -23
  94. package/dialog/_mdc-dialog-structure-overrides.scss +12 -10
  95. package/dialog/index.d.ts +2 -0
  96. package/divider/_divider-theme.scss +12 -18
  97. package/esm2022/autocomplete/autocomplete-trigger.mjs +5 -17
  98. package/esm2022/autocomplete/autocomplete.mjs +23 -50
  99. package/esm2022/badge/badge.mjs +11 -29
  100. package/esm2022/button/button-base.mjs +32 -27
  101. package/esm2022/button/button.mjs +6 -6
  102. package/esm2022/button/fab.mjs +23 -31
  103. package/esm2022/button/icon-button.mjs +6 -6
  104. package/esm2022/button/testing/button-harness.mjs +3 -3
  105. package/esm2022/button-toggle/button-toggle.mjs +25 -33
  106. package/esm2022/checkbox/checkbox.mjs +32 -39
  107. package/esm2022/core/option/optgroup.mjs +10 -11
  108. package/esm2022/core/option/option.mjs +6 -6
  109. package/esm2022/core/testing/option-harness.mjs +3 -3
  110. package/esm2022/core/version.mjs +1 -1
  111. package/esm2022/datepicker/calendar.mjs +1 -1
  112. package/esm2022/datepicker/datepicker-base.mjs +2 -2
  113. package/esm2022/datepicker/datepicker-toggle.mjs +1 -1
  114. package/esm2022/datepicker/month-view.mjs +2 -2
  115. package/esm2022/datepicker/multi-year-view.mjs +2 -2
  116. package/esm2022/datepicker/year-view.mjs +2 -2
  117. package/esm2022/dialog/dialog-container.mjs +16 -3
  118. package/esm2022/form-field/form-field.mjs +3 -3
  119. package/esm2022/menu/menu-item.mjs +15 -11
  120. package/esm2022/menu/menu.mjs +9 -22
  121. package/esm2022/paginator/paginator.mjs +1 -1
  122. package/esm2022/select/select.mjs +3 -3
  123. package/esm2022/slide-toggle/slide-toggle.mjs +33 -37
  124. package/esm2022/slider/slider-input.mjs +19 -9
  125. package/esm2022/slider/slider.mjs +2 -2
  126. package/esm2022/snack-bar/simple-snack-bar.mjs +1 -1
  127. package/esm2022/tabs/tab-group.mjs +3 -3
  128. package/expansion/_expansion-theme.scss +16 -24
  129. package/fesm2022/autocomplete.mjs +25 -63
  130. package/fesm2022/autocomplete.mjs.map +1 -1
  131. package/fesm2022/badge.mjs +11 -28
  132. package/fesm2022/badge.mjs.map +1 -1
  133. package/fesm2022/button/testing.mjs +2 -2
  134. package/fesm2022/button/testing.mjs.map +1 -1
  135. package/fesm2022/button-toggle.mjs +25 -32
  136. package/fesm2022/button-toggle.mjs.map +1 -1
  137. package/fesm2022/button.mjs +59 -61
  138. package/fesm2022/button.mjs.map +1 -1
  139. package/fesm2022/checkbox.mjs +31 -38
  140. package/fesm2022/checkbox.mjs.map +1 -1
  141. package/fesm2022/core/testing.mjs +2 -2
  142. package/fesm2022/core/testing.mjs.map +1 -1
  143. package/fesm2022/core.mjs +14 -13
  144. package/fesm2022/core.mjs.map +1 -1
  145. package/fesm2022/datepicker.mjs +6 -6
  146. package/fesm2022/datepicker.mjs.map +1 -1
  147. package/fesm2022/dialog.mjs +15 -2
  148. package/fesm2022/dialog.mjs.map +1 -1
  149. package/fesm2022/form-field.mjs +2 -2
  150. package/fesm2022/form-field.mjs.map +1 -1
  151. package/fesm2022/menu.mjs +23 -31
  152. package/fesm2022/menu.mjs.map +1 -1
  153. package/fesm2022/paginator.mjs +1 -1
  154. package/fesm2022/paginator.mjs.map +1 -1
  155. package/fesm2022/select.mjs +2 -2
  156. package/fesm2022/select.mjs.map +1 -1
  157. package/fesm2022/slide-toggle.mjs +33 -36
  158. package/fesm2022/slide-toggle.mjs.map +1 -1
  159. package/fesm2022/slider.mjs +20 -10
  160. package/fesm2022/slider.mjs.map +1 -1
  161. package/fesm2022/snack-bar.mjs +1 -1
  162. package/fesm2022/snack-bar.mjs.map +1 -1
  163. package/fesm2022/tabs.mjs +2 -2
  164. package/fesm2022/tabs.mjs.map +1 -1
  165. package/form-field/_form-field-density.scss +3 -4
  166. package/form-field/_form-field-focus-overlay.scss +1 -1
  167. package/form-field/_form-field-sizing.scss +1 -1
  168. package/form-field/_form-field-theme.scss +24 -34
  169. package/grid-list/_grid-list-theme.scss +12 -19
  170. package/icon/_icon-theme.scss +17 -25
  171. package/input/_input-theme.scss +11 -23
  172. package/list/_list-theme.scss +27 -42
  173. package/menu/_menu-theme.scss +13 -22
  174. package/menu/index.d.ts +12 -18
  175. package/package.json +2 -2
  176. package/paginator/_paginator-theme.scss +15 -24
  177. package/prebuilt-themes/deeppurple-amber.css +1 -1
  178. package/prebuilt-themes/indigo-pink.css +1 -1
  179. package/prebuilt-themes/pink-bluegrey.css +1 -1
  180. package/prebuilt-themes/purple-green.css +1 -1
  181. package/progress-bar/_progress-bar-theme.scss +17 -24
  182. package/progress-spinner/_progress-spinner-theme.scss +18 -24
  183. package/radio/_radio-theme.scss +23 -38
  184. package/schematics/ng-add/index.js +1 -1
  185. package/schematics/ng-add/index.mjs +1 -1
  186. package/schematics/ng-generate/mdc-migration/index_bundled.js +44 -44
  187. package/schematics/ng-generate/mdc-migration/index_bundled.js.map +1 -1
  188. package/schematics/ng-update/index_bundled.js +25 -25
  189. package/select/_select-theme.scss +17 -31
  190. package/sidenav/_sidenav-theme.scss +12 -18
  191. package/slide-toggle/_slide-toggle-theme.scss +23 -40
  192. package/slide-toggle/index.d.ts +20 -23
  193. package/slider/_slider-theme.scss +25 -42
  194. package/snack-bar/_snack-bar-theme.scss +17 -26
  195. package/sort/_sort-theme.scss +13 -22
  196. package/stepper/_stepper-theme.scss +16 -34
  197. package/table/_table-theme.scss +14 -25
  198. package/tabs/_tabs-theme.scss +31 -45
  199. package/toolbar/_toolbar-theme.scss +22 -31
  200. package/tooltip/_tooltip-theme.scss +15 -23
  201. package/tree/_tree-theme.scss +20 -29
  202. package/button-toggle/_button-toggle-variables.scss +0 -16
  203. package/core/typography/_typography-deprecated.scss +0 -39
  204. package/paginator/_paginator-variables.scss +0 -15
@@ -1,17 +1,15 @@
1
- @use 'sass:map';
2
1
  @use './elevation';
2
+ @use '../theming/inspection';
3
3
 
4
- @mixin private-theme-elevation($zValue, $config) {
5
- $foreground: map.get($config, foreground);
6
- $elevation-color: map.get($foreground, elevation);
4
+ @mixin private-theme-elevation($zValue, $theme) {
5
+ $elevation-color: inspection.get-theme-color($theme, foreground, elevation);
7
6
  $elevation-color-or-default: if($elevation-color == null, elevation.$color, $elevation-color);
8
7
 
9
8
  @include elevation.elevation($zValue, $elevation-color-or-default);
10
9
  }
11
10
 
12
- @mixin private-theme-overridable-elevation($zValue, $config) {
13
- $foreground: map.get($config, foreground);
14
- $elevation-color: map.get($foreground, elevation);
11
+ @mixin private-theme-overridable-elevation($zValue, $theme) {
12
+ $elevation-color: inspection.get-theme-color($theme, foreground, elevation);
15
13
  $elevation-color-or-default: if($elevation-color == null, elevation.$color, $elevation-color);
16
14
 
17
15
  @include elevation.overridable-elevation($zValue, $elevation-color-or-default);
@@ -1,3 +1,4 @@
1
+ @use 'sass:color';
1
2
  @use 'sass:map';
2
3
  @use 'sass:meta';
3
4
 
@@ -47,3 +48,9 @@
47
48
  @function coerce-to-list($value) {
48
49
  @return if(meta.type-of($value) != 'list', ($value,), $value);
49
50
  }
51
+
52
+ /// A version of the Sass `color.change` function that is safe ot use with CSS variables.
53
+ @function safe-color-change($color, $args...) {
54
+ $args: meta.keywords($args);
55
+ @return if(meta.type-of($color) == 'color', color.change($color, $args...), $color);
56
+ }
@@ -1,6 +1,7 @@
1
1
  import { BaseHarnessFilters } from '@angular/cdk/testing';
2
2
  import { ComponentHarness } from '@angular/cdk/testing';
3
3
  import { ComponentHarnessConstructor } from '@angular/cdk/testing';
4
+ import { ContentContainerComponentHarness } from '@angular/cdk/testing';
4
5
  import { HarnessPredicate } from '@angular/cdk/testing';
5
6
 
6
7
  /** Harness for interacting with an MDC-based `mat-optgroup` in tests. */
@@ -27,7 +28,7 @@ export declare class MatOptgroupHarness extends ComponentHarness {
27
28
  }
28
29
 
29
30
  /** Harness for interacting with an MDC-based `mat-option` in tests. */
30
- export declare class MatOptionHarness extends ComponentHarness {
31
+ export declare class MatOptionHarness extends ContentContainerComponentHarness {
31
32
  /** Selector used to locate option instances. */
32
33
  static hostSelector: string;
33
34
  /** Element containing the option's text. */
@@ -39,50 +39,50 @@
39
39
  @use './theming';
40
40
 
41
41
  // Create a theme.
42
- @mixin all-component-themes($theme-or-color-config) {
42
+ @mixin all-component-themes($theme) {
43
43
  $dedupe-key: 'angular-material-theme';
44
- @include theming.private-check-duplicate-theme-styles($theme-or-color-config, $dedupe-key) {
45
- @include core-theme.theme($theme-or-color-config);
46
- @include card-theme.theme($theme-or-color-config);
47
- @include progress-bar-theme.theme($theme-or-color-config);
48
- @include tooltip-theme.theme($theme-or-color-config);
49
- @include form-field-theme.theme($theme-or-color-config);
50
- @include input-theme.theme($theme-or-color-config);
51
- @include select-theme.theme($theme-or-color-config);
52
- @include autocomplete-theme.theme($theme-or-color-config);
53
- @include dialog-theme.theme($theme-or-color-config);
54
- @include chips-theme.theme($theme-or-color-config);
55
- @include slide-toggle-theme.theme($theme-or-color-config);
56
- @include radio-theme.theme($theme-or-color-config);
57
- @include slider-theme.theme($theme-or-color-config);
58
- @include menu-theme.theme($theme-or-color-config);
59
- @include list-theme.theme($theme-or-color-config);
60
- @include paginator-theme.theme($theme-or-color-config);
61
- @include tabs-theme.theme($theme-or-color-config);
62
- @include checkbox-theme.theme($theme-or-color-config);
63
- @include button-theme.theme($theme-or-color-config);
64
- @include icon-button-theme.theme($theme-or-color-config);
65
- @include fab-theme.theme($theme-or-color-config);
66
- @include snack-bar-theme.theme($theme-or-color-config);
67
- @include table-theme.theme($theme-or-color-config);
68
- @include progress-spinner-theme.theme($theme-or-color-config);
69
- @include badge-theme.theme($theme-or-color-config);
70
- @include bottom-sheet-theme.theme($theme-or-color-config);
71
- @include button-toggle-theme.theme($theme-or-color-config);
72
- @include datepicker-theme.theme($theme-or-color-config);
73
- @include divider-theme.theme($theme-or-color-config);
74
- @include expansion-theme.theme($theme-or-color-config);
75
- @include grid-list-theme.theme($theme-or-color-config);
76
- @include icon-theme.theme($theme-or-color-config);
77
- @include sidenav-theme.theme($theme-or-color-config);
78
- @include stepper-theme.theme($theme-or-color-config);
79
- @include sort-theme.theme($theme-or-color-config);
80
- @include toolbar-theme.theme($theme-or-color-config);
81
- @include tree-theme.theme($theme-or-color-config);
44
+ @include theming.private-check-duplicate-theme-styles($theme, $dedupe-key) {
45
+ @include core-theme.theme($theme);
46
+ @include card-theme.theme($theme);
47
+ @include progress-bar-theme.theme($theme);
48
+ @include tooltip-theme.theme($theme);
49
+ @include form-field-theme.theme($theme);
50
+ @include input-theme.theme($theme);
51
+ @include select-theme.theme($theme);
52
+ @include autocomplete-theme.theme($theme);
53
+ @include dialog-theme.theme($theme);
54
+ @include chips-theme.theme($theme);
55
+ @include slide-toggle-theme.theme($theme);
56
+ @include radio-theme.theme($theme);
57
+ @include slider-theme.theme($theme);
58
+ @include menu-theme.theme($theme);
59
+ @include list-theme.theme($theme);
60
+ @include paginator-theme.theme($theme);
61
+ @include tabs-theme.theme($theme);
62
+ @include checkbox-theme.theme($theme);
63
+ @include button-theme.theme($theme);
64
+ @include icon-button-theme.theme($theme);
65
+ @include fab-theme.theme($theme);
66
+ @include snack-bar-theme.theme($theme);
67
+ @include table-theme.theme($theme);
68
+ @include progress-spinner-theme.theme($theme);
69
+ @include badge-theme.theme($theme);
70
+ @include bottom-sheet-theme.theme($theme);
71
+ @include button-toggle-theme.theme($theme);
72
+ @include datepicker-theme.theme($theme);
73
+ @include divider-theme.theme($theme);
74
+ @include expansion-theme.theme($theme);
75
+ @include grid-list-theme.theme($theme);
76
+ @include icon-theme.theme($theme);
77
+ @include sidenav-theme.theme($theme);
78
+ @include stepper-theme.theme($theme);
79
+ @include sort-theme.theme($theme);
80
+ @include toolbar-theme.theme($theme);
81
+ @include tree-theme.theme($theme);
82
82
  }
83
83
  }
84
84
 
85
85
  // @deprecated Use `all-component-themes`.
86
- @mixin angular-material-theme($theme-or-color-config) {
87
- @include all-component-themes($theme-or-color-config);
86
+ @mixin angular-material-theme($theme) {
87
+ @include all-component-themes($theme);
88
88
  }
@@ -1,8 +1,7 @@
1
- // This file contains functions used to inspect Angular Material theme objects.
2
-
3
1
  @use 'sass:list';
4
2
  @use 'sass:map';
5
3
  @use '../style/validation';
4
+ @use './m2-inspection';
6
5
 
7
6
  $_internals: _mat-theming-internals-do-not-access;
8
7
 
@@ -48,15 +47,19 @@ $_typography-properties: (font, font-family, line-height, font-size, letter-spac
48
47
  /// @param {Map} $theme The theme
49
48
  /// @return {String} The type of theme (either `light` or `dark`).
50
49
  @function get-theme-type($theme) {
51
- $err: _validate-theme-object($theme);
52
- @if $err {
53
- // TODO(mmalerba): implement for old style theme objects.
54
- @error #{'get-theme-type does not support legacy theme objects.'};
50
+ $version: get-theme-version($theme);
51
+ @if $version == 0 {
52
+ @return m2-inspection.get-theme-type($theme);
55
53
  }
56
- @if not theme-has($theme, color) {
57
- @error 'Color information is not available on this theme.';
54
+ @else if $version == 1 {
55
+ @if not theme-has($theme, color) {
56
+ @error 'Color information is not available on this theme.';
57
+ }
58
+ @return map.get($theme, $_internals, theme-type) or light;
59
+ }
60
+ @else {
61
+ @error #{'Unrecognized theme version:'} $version;
58
62
  }
59
- @return map.get($theme, $_internals, theme-type) or light;
60
63
  }
61
64
 
62
65
  /// Gets a color from a theme object. This function can take 2 or 3 arguments. If 2 arguments are
@@ -70,14 +73,26 @@ $_typography-properties: (font, font-family, line-height, font-size, letter-spac
70
73
  /// interpreted as a palette name).
71
74
  /// @return {Color} The requested theme color.
72
75
  @function get-theme-color($theme, $args...) {
76
+ $version: get-theme-version($theme);
73
77
  $args-count: list.length($args);
74
- @if $args-count == 1 {
75
- @return _get-theme-role-color($theme, $args...);
78
+ @if $args-count != 1 and $args-count != 2 {
79
+ @error #{'Expected 2 or 3 arguments. Got:'} $args-count + 1;
80
+ }
81
+
82
+ @if $version == 0 {
83
+ @return m2-inspection.get-theme-color($theme, $args...);
76
84
  }
77
- @else if $args-count == 2 {
78
- @return _get-theme-palette-color($theme, $args...);
85
+ @else if $version == 1 {
86
+ @if $args-count == 1 {
87
+ @return _get-theme-role-color($theme, $args...);
88
+ }
89
+ @else if $args-count == 2 {
90
+ @return _get-theme-palette-color($theme, $args...);
91
+ }
92
+ }
93
+ @else {
94
+ @error #{'Unrecognized theme version:'} $version;
79
95
  }
80
- @error #{'Expected 2 or 3 arguments. Got:'} $args-count + 1;
81
96
  }
82
97
 
83
98
  /// Gets a role color from a theme object.
@@ -136,45 +151,53 @@ $_typography-properties: (font, font-family, line-height, font-size, letter-spac
136
151
  /// (font, font-family, font-size, font-weight, line-height, or letter-spacing).
137
152
  /// @return {*} The value of the requested font property.
138
153
  @function get-theme-typography($theme, $typescale, $property: font) {
139
- $err: _validate-theme-object($theme);
140
- @if $err {
141
- // TODO(mmalerba): implement for old style theme objects.
142
- @error #{'get-theme-typography does not support legacy theme objects.'};
143
- }
144
- @if not theme-has($theme, typography) {
145
- @error 'Typography information is not available on this theme.';
146
- }
147
- @if not list.index($_m3-typescales, $typescale) {
148
- @error #{'Valid typescales are: #{$_m3-typescales}. Got:'} $typescale;
149
- }
150
- @if not list.index($_typography-properties, $property) {
151
- @error #{'Valid typography properties are: #{$_typography-properties}. Got:'} $property;
152
- }
153
- $property-key: map.get((
154
- font: '',
155
- font-family: '-font',
156
- line-height: '-line-height',
157
- font-size: '-size',
158
- letter-spacing: '-tracking',
159
- font-weight: '-weight'
160
- ), $property);
161
- $token-name: '#{$typescale}#{$property-key}';
162
- @return map.get($theme, $_internals, typography-tokens, (mdc, typography), $token-name);
154
+ $version: get-theme-version($theme);
155
+ @if $version == 0 {
156
+ @return m2-inspection.get-theme-typography($theme, $typescale, $property);
157
+ }
158
+ @else if $version == 1 {
159
+ @if not theme-has($theme, typography) {
160
+ @error 'Typography information is not available on this theme.';
161
+ }
162
+ @if not list.index($_m3-typescales, $typescale) {
163
+ @error #{'Valid typescales are: #{$_m3-typescales}. Got:'} $typescale;
164
+ }
165
+ @if not list.index($_typography-properties, $property) {
166
+ @error #{'Valid typography properties are: #{$_typography-properties}. Got:'} $property;
167
+ }
168
+ $property-key: map.get((
169
+ font: '',
170
+ font-family: '-font',
171
+ line-height: '-line-height',
172
+ font-size: '-size',
173
+ letter-spacing: '-tracking',
174
+ font-weight: '-weight'
175
+ ), $property);
176
+ $token-name: '#{$typescale}#{$property-key}';
177
+ @return map.get($theme, $_internals, typography-tokens, (mdc, typography), $token-name);
178
+ }
179
+ @else {
180
+ @error #{'Unrecognized theme version:'} $version;
181
+ }
163
182
  }
164
183
 
165
184
  /// Gets the density scale from a theme object.
166
185
  /// @param {Map} $theme The theme
167
186
  /// @return {Number} The density scale.
168
187
  @function get-theme-density($theme) {
169
- $err: _validate-theme-object($theme);
170
- @if $err {
171
- // TODO(mmalerba): implement for old style theme objects.
172
- @error #{'get-theme-density does not support legacy theme objects.'};
188
+ $version: get-theme-version($theme);
189
+ @if $version == 0 {
190
+ @return m2-inspection.get-theme-density($theme);
191
+ }
192
+ @else if $version == 1 {
193
+ @if not theme-has($theme, density) {
194
+ @error 'Density information is not available on this theme.';
195
+ }
196
+ @return map.get($theme, $_internals, density-scale);
173
197
  }
174
- @if not theme-has($theme, density) {
175
- @error 'Density information is not available on this theme.';
198
+ @else {
199
+ @error #{'Unrecognized theme version:'} $version;
176
200
  }
177
- @return map.get($theme, $_internals, density-scale);
178
201
  }
179
202
 
180
203
  /// Checks whether the theme has information about given theming system.
@@ -182,26 +205,65 @@ $_typography-properties: (font, font-family, line-height, font-size, letter-spac
182
205
  /// @param {String} $system The system to check
183
206
  /// @param {Boolean} Whether the theme has information about the system.
184
207
  @function theme-has($theme, $system) {
185
- $err: _validate-theme-object($theme);
186
- @if $err {
187
- // TODO(mmalerba): implement for old style theme objects.
188
- @error #{'get-theme-density does not support legacy theme objects.'};
189
- }
190
- @if $system == base {
191
- @return map.get($theme, $_internals, base-tokens) != null;
208
+ $version: get-theme-version($theme);
209
+ @if $version == 0 {
210
+ @return m2-inspection.theme-has($theme, $system);
192
211
  }
193
- @if $system == color {
194
- @return map.get($theme, $_internals, color-tokens) != null and
212
+ @else if $version == 1 {
213
+ @if $system == base {
214
+ @return map.get($theme, $_internals, base-tokens) != null;
215
+ }
216
+ @if $system == color {
217
+ @return map.get($theme, $_internals, color-tokens) != null and
195
218
  map.get($theme, $_internals, theme-type) != null and
196
219
  map.get($theme, $_internals, palettes) != null;
220
+ }
221
+ @if $system == typography {
222
+ @return map.get($theme, $_internals, typography-tokens) != null;
223
+ }
224
+ @if $system == density {
225
+ @return map.get($theme, $_internals, density-scale) != null;
226
+ }
227
+ @error 'Valid systems are: base, color, typography, density. Got:' $system;
197
228
  }
198
- @if $system == typography {
199
- @return map.get($theme, $_internals, typography-tokens) != null;
229
+ @else {
230
+ @error #{'Unrecognized theme version:'} $version;
200
231
  }
201
- @if $system == density {
202
- @return map.get($theme, $_internals, density-scale) != null;
232
+ }
233
+
234
+ /// Removes the information about the given theming system(s) from the given theme.
235
+ /// @param {Map} $theme The theme to remove information from
236
+ /// @param {String...} $systems The systems to remove
237
+ /// @return {Map} A version of the theme without the removed theming systems.
238
+ @function theme-remove($theme, $systems...) {
239
+ $err: validation.validate-allowed-values($systems, color, typography, density, base);
240
+ @if $err {
241
+ @error #{'Expected $systems to contain valid system names (color, typography, density, or'}
242
+ #{'base). Got invalid system names:'} $err;
243
+ }
244
+ $version: get-theme-version($theme);
245
+ @if $version == 0 {
246
+ @return m2-inspection.theme-remove($theme, $systems...);
247
+ }
248
+ @else if $version == 1 {
249
+ @each $system in $systems {
250
+ @if $system == base {
251
+ $theme: map.deep-remove($theme, $_internals, base-tokens);
252
+ }
253
+ @else if $system == color {
254
+ $theme: map.deep-remove($theme, $_internals, color-tokens);
255
+ $theme: map.deep-remove($theme, $_internals, theme-type);
256
+ $theme: map.deep-remove($theme, $_internals, palettes);
257
+ }
258
+ @else if $system == typography {
259
+ $theme: map.deep-remove($theme, $_internals, typography-tokens);
260
+ }
261
+ @else if $system == density {
262
+ $theme: map.deep-remove($theme, $_internals, density-scale);
263
+ }
264
+ }
265
+ @return $theme;
203
266
  }
204
- @error 'Valid systems are: base, color, typography, density. Got:' $system;
205
267
  }
206
268
 
207
269
  /// Gets the set of tokens from the given theme, limited to those affected by the requested theming
@@ -227,3 +289,15 @@ $_typography-properties: (font, font-family, line-height, font-size, letter-spac
227
289
  }
228
290
  @return $result;
229
291
  }
292
+
293
+ /// Gets a version of the theme with a modified typography config that preserves old behavior in
294
+ /// some components that previously used `private-typography-to-2014-config`.
295
+ /// Do not introduce new usages of this, it should be cleaned up and removed.
296
+ /// @deprecated
297
+ @function private-get-typography-back-compat-theme($theme) {
298
+ @return if(
299
+ get-theme-version($theme) == 0,
300
+ m2-inspection.private-get-typography-back-compat-theme($theme),
301
+ $theme
302
+ );
303
+ }
@@ -0,0 +1,268 @@
1
+ @use 'sass:list';
2
+ @use 'sass:map';
3
+ @use 'sass:meta';
4
+ @use './theming';
5
+ @use '../typography/property-getters' as typography-getters;
6
+ @use '../typography/versioning' as typography-versioning;
7
+
8
+ /// Key used to access the Angular Material theme internals.
9
+ $_internals: _mat-theming-internals-do-not-access;
10
+
11
+ /// Keys that indicate a config object is a color config.
12
+ $_color-keys: (
13
+ primary,
14
+ accent,
15
+ warn,
16
+ foreground,
17
+ background,
18
+ is-dark,
19
+ color, /* included for themes that incorrectly nest the color config: (color: (color: (....))) */
20
+ );
21
+
22
+ /// Keys that indicate a config object is a typography config.
23
+ $_typography-keys: (
24
+ headline-1,
25
+ headline-2,
26
+ headline-3,
27
+ headline-4,
28
+ headline-5,
29
+ headline-6,
30
+ subtitle-1,
31
+ font-famiy,
32
+ subtitle-2,
33
+ body-1,
34
+ body-2,
35
+ button,
36
+ caption,
37
+ overline,
38
+ );
39
+
40
+ /// The CSS typography properties supported by the inspection API.
41
+ $_typography-properties: (font, font-family, line-height, font-size, letter-spacing, font-weight);
42
+
43
+ /// Gets the m2-config from the theme.
44
+ @function _get-m2-config($theme) {
45
+ // It is possible for a user to pass a "density theme" that is just a number.
46
+ @if meta.type-of($theme) != 'map' {
47
+ @return $theme;
48
+ }
49
+ $internal: map.get($theme, $_internals, m2-config);
50
+ $theme: map.remove($theme, $_internals);
51
+ @return if(_is-error-theme($theme), $internal, $theme);
52
+ }
53
+
54
+ /// Checks whether the given theme contains error values.
55
+ /// @param {*} $theme The theme to check.
56
+ /// @return {Boolean} true if the theme contains error values, else false.
57
+ @function _is-error-theme($theme) {
58
+ @if meta.type-of($theme) != 'map' {
59
+ @return false;
60
+ }
61
+ @if map.get($theme, ERROR) {
62
+ @return true;
63
+ }
64
+ @return _is-error-theme(list.nth(map.values($theme), 1));
65
+ }
66
+
67
+ /// Checks whether the given theme object has any of the given keys.
68
+ /// @param {Map} $theme The theme to check
69
+ /// @param {List} $keys The keys to check for
70
+ /// @return {Boolean} Whether the theme has any of the given keys.
71
+ @function _has-any-key($theme, $keys) {
72
+ @each $key in $keys {
73
+ @if map.has-key($theme, $key) {
74
+ @return true;
75
+ }
76
+ }
77
+ @return false;
78
+ }
79
+
80
+ /// Checks whether the given theme is a density scale value.
81
+ /// @param {*} $theme The theme to check.
82
+ /// @return {Boolean} true if the theme is a density scale value, else false.
83
+ @function _is-density-value($theme) {
84
+ @return $theme == minimum or $theme == maximum or meta.type-of($theme) == 'number';
85
+ }
86
+
87
+ /// Gets the type of theme represented by a theme object (light or dark).
88
+ /// @param {Map} $theme The theme
89
+ /// @return {String} The type of theme (either `light` or `dark`).
90
+ @function get-theme-type($theme) {
91
+ $theme: _get-m2-config($theme);
92
+ @if not theme-has($theme, color) {
93
+ @error 'Color information is not available on this theme.';
94
+ }
95
+ $colors: theming.get-color-config($theme);
96
+ // Some apps seem to have mistakenly created nested color themes that somehow work with our old
97
+ // theme normalization logic. This check allows those apps to keep working.
98
+ @if theme-has($colors, color) {
99
+ $colors: theming.get-color-config($colors);
100
+ }
101
+ @return if(map.get($colors, is-dark), dark, light);
102
+ }
103
+
104
+ /// Gets a color from a theme object. This function can take 2 or 3 arguments. If 2 arguments are
105
+ /// passed, the second argument is treated as the name of a color role. If 3 arguments are passed,
106
+ /// the second argument is treated as the name of a color palette (primary, secondary, etc.) and the
107
+ /// third is treated as the palette hue (10, 50, etc.)
108
+ /// @param {Map} $theme The theme
109
+ /// @param {String} $palette-name The name of a color palette.
110
+ /// @param {Number} $hue The palette hue to get (passing this argument means the second argument is
111
+ /// interpreted as a palette name).
112
+ /// @return {Color} The requested theme color.
113
+ @function get-theme-color($theme, $palette-name, $args...) {
114
+ $theme: _get-m2-config($theme);
115
+ @if not theme-has($theme, color) {
116
+ @error 'Color information is not available on this theme.';
117
+ }
118
+ $colors: theming.get-color-config($theme);
119
+ // Some apps seem to have mistakenly created nested color themes that somehow work with our old
120
+ // theme normalization logic. This check allows those apps to keep working.
121
+ @if theme-has($colors, color) {
122
+ $colors: theming.get-color-config($colors);
123
+ }
124
+ $palette: map.get($colors, $palette-name);
125
+ @if not $palette {
126
+ @error 'Unrecognized palette name:' $palette-name;
127
+ }
128
+ @return theming.get-color-from-palette($palette, $args...);
129
+ }
130
+
131
+ /// Gets a typography value from a theme object.
132
+ /// @param {Map} $theme The theme
133
+ /// @param {String} $typescale The typescale name.
134
+ /// @param {String} $property The CSS font property to get
135
+ /// (font, font-family, font-size, font-weight, line-height, or letter-spacing).
136
+ /// @return {*} The value of the requested font property.
137
+ @function get-theme-typography($theme, $typescale, $property) {
138
+ $theme: _get-m2-config($theme);
139
+ @if not theme-has($theme, typography) {
140
+ @error 'Typography information is not available on this theme.';
141
+ }
142
+ $typography: typography-versioning.private-typography-to-2018-config(
143
+ theming.get-typography-config($theme));
144
+ @if $property == font {
145
+ $font-weight: typography-getters.font-weight($typography, $typescale);
146
+ $font-size: typography-getters.font-size($typography, $typescale);
147
+ $line-height: typography-getters.line-height($typography, $typescale);
148
+ $font-family: typography-getters.font-family($typography, $typescale);
149
+ @return ($font-weight list.slash($font-size, $line-height) $font-family);
150
+ }
151
+ @else if $property == font-family {
152
+ $result: typography-getters.font-family($typography, $typescale);
153
+ @return $result or typography-getters.font-family($typography);
154
+ }
155
+ @else if $property == font-size {
156
+ @return typography-getters.font-size($typography, $typescale);
157
+ }
158
+ @else if $property == font-weight {
159
+ @return typography-getters.font-weight($typography, $typescale);
160
+ }
161
+ @else if $property == line-height {
162
+ @return typography-getters.line-height($typography, $typescale);
163
+ }
164
+ @else if $property == letter-spacing {
165
+ @return typography-getters.letter-spacing($typography, $typescale);
166
+ }
167
+ @else {
168
+ @error #{'Valid typography properties are: #{$_typography-properties}. Got:'} $property;
169
+ }
170
+ }
171
+
172
+ /// Gets the density scale from a theme object.
173
+ /// @param {Map} $theme The theme
174
+ /// @return {Number} The density scale.
175
+ @function get-theme-density($theme) {
176
+ $theme: _get-m2-config($theme);
177
+ @if not theme-has($theme, density) {
178
+ @error 'Density information is not available on this theme.';
179
+ }
180
+ $scale: theming.get-density-config($theme);
181
+ @return theming.clamp-density($scale, -5);
182
+ }
183
+
184
+ /// Checks whether the theme has information about given theming system.
185
+ /// @param {Map} $theme The theme
186
+ /// @param {String} $system The system to check
187
+ /// @param {Boolean} Whether the theme has information about the system.
188
+ @function theme-has($theme, $system) {
189
+ $theme: _get-m2-config($theme);
190
+ @if $system == base {
191
+ @return true;
192
+ }
193
+ @if $system == color {
194
+ $color: theming.get-color-config($theme);
195
+ @return $color != null and _has-any-key($color, $_color-keys);
196
+ }
197
+ @if $system == typography {
198
+ $typography: theming.get-typography-config($theme);
199
+ @return $typography != null and _has-any-key($typography, $_typography-keys);
200
+ }
201
+ @if $system == density {
202
+ // Backwards compatibility for the case where an explicit, but invalid density is given
203
+ // (this was previously treated as density 0).
204
+ @if meta.type-of($theme) == 'map' and map.get($theme, density) {
205
+ @return true;
206
+ }
207
+ $density: theming.get-density-config($theme);
208
+ @return $density != null and _is-density-value($density);
209
+ }
210
+ @error 'Valid systems are: base, color, typography, density. Got:' $system;
211
+ }
212
+
213
+ /// Removes the information about the given theming system(s) from the given theme.
214
+ /// @param {Map} $theme The theme to remove information from
215
+ /// @param {String...} $systems The systems to remove
216
+ /// @return {Map} A version of the theme without the removed theming systems.
217
+ @function theme-remove($theme, $systems...) {
218
+ $internal: map.get($theme, $_internals, m2-config);
219
+ @each $system in $systems {
220
+ @if $system == color {
221
+ $theme: map.set($theme, color, null);
222
+ }
223
+ @else if $system == typography {
224
+ $theme: map.set($theme, typography, null);
225
+ }
226
+ @else if $system == density {
227
+ $theme: map.set($theme, density, null);
228
+ }
229
+ }
230
+ @if $internal {
231
+ $internal: theme-remove($internal, $systems...);
232
+ $theme: map.set($theme, $_internals, m2-config, $internal);
233
+ }
234
+ @return $theme;
235
+ }
236
+
237
+ /// Gets a version of the theme with a modified typography config that preserves old behavior in
238
+ /// some components that previously used `private-typography-to-2014-config`.
239
+ /// Do not introduce new usages of this, it should be cleaned up and removed.
240
+ /// @deprecated
241
+ @function private-get-typography-back-compat-theme($theme) {
242
+ // It is possible for a user to pass a "density theme" that is just a number.
243
+ @if meta.type-of($theme) != 'map' {
244
+ @return $theme;
245
+ }
246
+ $internal: map.get($theme, $_internals, m2-config);
247
+ $theme: map.remove($theme, $_internals);
248
+ @if theme-has($theme, typography) {
249
+ $typography-config: theming.get-typography-config($theme);
250
+ // gmat configs have both 2018 and 2014 keys.
251
+ @if (not typography-versioning.private-typography-is-2014-config($typography-config)) or
252
+ (not typography-versioning.private-typography-is-2018-config($typography-config)) {
253
+ @return $theme;
254
+ }
255
+ $new-typography-config: typography-versioning.private-typography-to-2018-config(
256
+ $typography-config, true);
257
+ // subtitle-2 is mapped differently by `private-typography-to-2014-config`.
258
+ $new-typography-config: map.set(
259
+ $new-typography-config, subtitle-2, map.get($new-typography-config, body-1));
260
+ $theme: if($theme == $typography-config, $new-typography-config,
261
+ map.set($theme, typography, $new-typography-config));
262
+ }
263
+ @if $internal {
264
+ $internal: private-get-typography-back-compat-theme($internal);
265
+ $theme: map.set($theme, $_internals, m2-config, $internal);
266
+ }
267
+ @return $theme;
268
+ }