@ng-matero/extensions 16.3.0 → 17.0.0

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 +2 -1
  2. package/alert/_alert-theme.scss +54 -24
  3. package/alert/alert.d.ts +3 -6
  4. package/alert/alert.scss +3 -3
  5. package/button/_button-theme.scss +6 -4
  6. package/button/button-loading.d.ts +5 -10
  7. package/button/button-module.d.ts +5 -5
  8. package/checkbox-group/checkbox-group.d.ts +4 -9
  9. package/colorpicker/_colorpicker-theme.scss +62 -34
  10. package/colorpicker/colorpicker-input.d.ts +1 -3
  11. package/colorpicker/colorpicker-toggle.d.ts +2 -3
  12. package/colorpicker/colorpicker.d.ts +5 -6
  13. package/core/color/_all-color.scss +7 -18
  14. package/core/density/_all-density.scss +28 -14
  15. package/core/mdc-helpers/_mdc-helpers.scss +27 -238
  16. package/core/style/_sass-utils.scss +13 -1
  17. package/core/style/_validation.scss +43 -0
  18. package/core/theming/_all-theme.scss +32 -17
  19. package/core/theming/_inspection.scss +303 -0
  20. package/core/theming/_m2-inspection.scss +266 -0
  21. package/core/tokens/_token-utils.scss +4 -5
  22. package/core/tokens/m2/mdc/_plain-tooltip.scss +21 -29
  23. package/core/tokens/m2/mtx/_alert.scss +14 -15
  24. package/core/tokens/m2/mtx/_colorpicker.scss +8 -11
  25. package/core/tokens/m2/mtx/_datetimepicker.scss +38 -47
  26. package/core/tokens/m2/mtx/_drawer.scss +9 -10
  27. package/core/tokens/m2/mtx/_grid.scss +34 -22
  28. package/core/tokens/m2/mtx/_loader.scss +6 -6
  29. package/core/tokens/m2/mtx/_popover.scss +10 -11
  30. package/core/tokens/m2/mtx/_progress.scss +18 -17
  31. package/core/tokens/m2/mtx/_select.scss +65 -25
  32. package/core/tokens/m2/mtx/_split.scss +8 -11
  33. package/core/typography/_all-typography.scss +40 -0
  34. package/core/typography/_typography.scss +1 -579
  35. package/datetimepicker/_datetimepicker-theme.scss +75 -48
  36. package/datetimepicker/calendar.d.ts +7 -14
  37. package/datetimepicker/calendar.scss +16 -4
  38. package/datetimepicker/clock.d.ts +1 -2
  39. package/datetimepicker/datetimepicker-content.scss +3 -3
  40. package/datetimepicker/datetimepicker-input.d.ts +1 -2
  41. package/datetimepicker/datetimepicker-toggle.d.ts +2 -3
  42. package/datetimepicker/datetimepicker.d.ts +15 -26
  43. package/datetimepicker/month-view.d.ts +1 -1
  44. package/datetimepicker/multi-year-view.d.ts +1 -1
  45. package/datetimepicker/time.d.ts +3 -5
  46. package/datetimepicker/time.scss +2 -2
  47. package/datetimepicker/year-view.d.ts +1 -1
  48. package/drawer/_drawer-theme.scss +55 -22
  49. package/drawer/drawer-container.scss +25 -4
  50. package/esm2022/alert/alert-module.mjs +4 -4
  51. package/esm2022/alert/alert.mjs +11 -18
  52. package/esm2022/button/button-loading.mjs +13 -23
  53. package/esm2022/button/button-module.mjs +6 -7
  54. package/esm2022/checkbox-group/checkbox-group-module.mjs +4 -4
  55. package/esm2022/checkbox-group/checkbox-group.mjs +18 -29
  56. package/esm2022/colorpicker/colorpicker-input.mjs +13 -14
  57. package/esm2022/colorpicker/colorpicker-module.mjs +4 -4
  58. package/esm2022/colorpicker/colorpicker-toggle.mjs +18 -18
  59. package/esm2022/colorpicker/colorpicker.mjs +31 -36
  60. package/esm2022/column-resize/column-resize-directives/column-resize-flex.mjs +4 -4
  61. package/esm2022/column-resize/column-resize-directives/column-resize.mjs +4 -4
  62. package/esm2022/column-resize/column-resize-module.mjs +4 -4
  63. package/esm2022/column-resize/column-resize-notifier.mjs +7 -7
  64. package/esm2022/column-resize/column-resize.mjs +3 -3
  65. package/esm2022/column-resize/column-size-store.mjs +3 -3
  66. package/esm2022/column-resize/event-dispatcher.mjs +4 -4
  67. package/esm2022/column-resize/overlay-handle.mjs +3 -3
  68. package/esm2022/column-resize/resizable.mjs +3 -3
  69. package/esm2022/column-resize/resize-strategy.mjs +13 -13
  70. package/esm2022/core/datetime/datetime.module.mjs +8 -8
  71. package/esm2022/core/datetime/native-datetime-adapter.mjs +5 -5
  72. package/esm2022/core/pipes/is-template-ref.pipe.mjs +3 -3
  73. package/esm2022/core/pipes/pipes.module.mjs +4 -4
  74. package/esm2022/core/pipes/to-observable.pipe.mjs +3 -3
  75. package/esm2022/datetimepicker/calendar-body.mjs +5 -6
  76. package/esm2022/datetimepicker/calendar.mjs +30 -47
  77. package/esm2022/datetimepicker/clock.mjs +10 -9
  78. package/esm2022/datetimepicker/datetimepicker-input.mjs +14 -15
  79. package/esm2022/datetimepicker/datetimepicker-intl.mjs +3 -3
  80. package/esm2022/datetimepicker/datetimepicker-module.mjs +4 -4
  81. package/esm2022/datetimepicker/datetimepicker-toggle.mjs +18 -18
  82. package/esm2022/datetimepicker/datetimepicker.mjs +57 -80
  83. package/esm2022/datetimepicker/month-view.mjs +8 -9
  84. package/esm2022/datetimepicker/multi-year-view.mjs +8 -8
  85. package/esm2022/datetimepicker/time.mjs +18 -24
  86. package/esm2022/datetimepicker/year-view.mjs +8 -8
  87. package/esm2022/dialog/dialog-container.mjs +7 -7
  88. package/esm2022/dialog/dialog-module.mjs +4 -4
  89. package/esm2022/dialog/dialog.mjs +4 -4
  90. package/esm2022/drawer/drawer-container.mjs +7 -7
  91. package/esm2022/drawer/drawer-module.mjs +4 -4
  92. package/esm2022/drawer/drawer.mjs +5 -5
  93. package/esm2022/grid/cell.mjs +6 -6
  94. package/esm2022/grid/column-menu.mjs +5 -5
  95. package/esm2022/grid/column-resize/column-resize-directives/column-resize-flex.mjs +4 -4
  96. package/esm2022/grid/column-resize/column-resize-directives/column-resize.mjs +4 -4
  97. package/esm2022/grid/column-resize/column-resize-module.mjs +8 -8
  98. package/esm2022/grid/column-resize/overlay-handle.mjs +6 -6
  99. package/esm2022/grid/column-resize/resizable-directives/resizable.mjs +6 -6
  100. package/esm2022/grid/column-resize/resize-strategy.mjs +5 -5
  101. package/esm2022/grid/expansion-toggle.mjs +5 -5
  102. package/esm2022/grid/grid-module.mjs +4 -4
  103. package/esm2022/grid/grid-pipes.mjs +22 -22
  104. package/esm2022/grid/grid-utils.mjs +4 -4
  105. package/esm2022/grid/grid.mjs +76 -44
  106. package/esm2022/loader/loader-module.mjs +4 -4
  107. package/esm2022/loader/loader.mjs +17 -29
  108. package/esm2022/photoviewer/photoviewer-module.mjs +4 -4
  109. package/esm2022/photoviewer/photoviewer.mjs +7 -7
  110. package/esm2022/popover/popover-content.mjs +8 -8
  111. package/esm2022/popover/popover-module.mjs +4 -4
  112. package/esm2022/popover/popover-target.mjs +4 -4
  113. package/esm2022/popover/popover-trigger.mjs +6 -6
  114. package/esm2022/popover/popover.mjs +52 -137
  115. package/esm2022/progress/progress-module.mjs +4 -4
  116. package/esm2022/progress/progress.mjs +14 -25
  117. package/esm2022/select/option.mjs +11 -17
  118. package/esm2022/select/select-module.mjs +4 -4
  119. package/esm2022/select/select.mjs +13 -13
  120. package/esm2022/select/templates.mjs +44 -44
  121. package/esm2022/split/split-module.mjs +4 -4
  122. package/esm2022/split/split-pane.mjs +5 -5
  123. package/esm2022/split/split.mjs +7 -7
  124. package/esm2022/tooltip/tooltip-module.mjs +4 -4
  125. package/esm2022/tooltip/tooltip.mjs +22 -22
  126. package/fesm2022/mtxAlert.mjs +14 -21
  127. package/fesm2022/mtxAlert.mjs.map +1 -1
  128. package/fesm2022/mtxButton.mjs +17 -28
  129. package/fesm2022/mtxButton.mjs.map +1 -1
  130. package/fesm2022/mtxCheckboxGroup.mjs +21 -32
  131. package/fesm2022/mtxCheckboxGroup.mjs.map +1 -1
  132. package/fesm2022/mtxColorpicker.mjs +61 -64
  133. package/fesm2022/mtxColorpicker.mjs.map +1 -1
  134. package/fesm2022/mtxColumnResize.mjs +48 -48
  135. package/fesm2022/mtxCore.mjs +23 -23
  136. package/fesm2022/mtxDatetimepicker.mjs +150 -190
  137. package/fesm2022/mtxDatetimepicker.mjs.map +1 -1
  138. package/fesm2022/mtxDialog.mjs +14 -14
  139. package/fesm2022/mtxDialog.mjs.map +1 -1
  140. package/fesm2022/mtxDrawer.mjs +17 -17
  141. package/fesm2022/mtxDrawer.mjs.map +1 -1
  142. package/fesm2022/mtxGrid.mjs +150 -118
  143. package/fesm2022/mtxGrid.mjs.map +1 -1
  144. package/fesm2022/mtxLoader.mjs +20 -32
  145. package/fesm2022/mtxLoader.mjs.map +1 -1
  146. package/fesm2022/mtxPhotoviewer.mjs +10 -10
  147. package/fesm2022/mtxPhotoviewer.mjs.map +1 -1
  148. package/fesm2022/mtxPopover.mjs +73 -158
  149. package/fesm2022/mtxPopover.mjs.map +1 -1
  150. package/fesm2022/mtxProgress.mjs +17 -28
  151. package/fesm2022/mtxProgress.mjs.map +1 -1
  152. package/fesm2022/mtxSelect.mjs +68 -73
  153. package/fesm2022/mtxSelect.mjs.map +1 -1
  154. package/fesm2022/mtxSplit.mjs +14 -14
  155. package/fesm2022/mtxSplit.mjs.map +1 -1
  156. package/fesm2022/mtxTooltip.mjs +26 -26
  157. package/fesm2022/mtxTooltip.mjs.map +1 -1
  158. package/grid/_grid-theme.scss +60 -24
  159. package/grid/column-menu.scss +32 -3
  160. package/grid/grid.d.ts +33 -1
  161. package/grid/grid.scss +36 -108
  162. package/loader/_loader-theme.scss +55 -22
  163. package/loader/loader.d.ts +4 -9
  164. package/loader/loader.scss +1 -1
  165. package/package.json +35 -41
  166. package/photoviewer/photoviewer.d.ts +1 -0
  167. package/popover/_popover-theme.scss +55 -22
  168. package/popover/popover.d.ts +23 -54
  169. package/popover/popover.scss +2 -2
  170. package/prebuilt-themes/deeppurple-amber.css +1 -1
  171. package/prebuilt-themes/indigo-pink.css +1 -1
  172. package/prebuilt-themes/pink-bluegrey.css +1 -1
  173. package/prebuilt-themes/purple-green.css +1 -1
  174. package/progress/_progress-theme.scss +60 -22
  175. package/progress/progress.d.ts +4 -9
  176. package/progress/progress.scss +3 -3
  177. package/select/_select-theme.scss +66 -34
  178. package/select/option.d.ts +2 -5
  179. package/select/select.d.ts +1 -3
  180. package/select/select.scss +104 -127
  181. package/split/_split-theme.scss +62 -32
  182. package/split/split.scss +2 -4
  183. package/tooltip/_tooltip-theme.scss +66 -34
  184. package/_theming.scss +0 -16
  185. package/alert/_alert-theme.import.scss +0 -2
  186. package/button/_button-theme.import.scss +0 -2
  187. package/colorpicker/_colorpicker-theme.import.scss +0 -2
  188. package/core/style/_elevation.scss +0 -91
  189. package/core/style/_private.scss +0 -32
  190. package/core/style/_variables.scss +0 -44
  191. package/core/style/_vendor-prefixes.scss +0 -46
  192. package/core/theming/_palette.scss +0 -746
  193. package/core/theming/_theming.scss +0 -463
  194. package/core/typography/_typography-utils.scss +0 -101
  195. package/datetimepicker/_datetimepicker-theme.import.scss +0 -4
  196. package/drawer/_drawer-theme.import.scss +0 -2
  197. package/grid/_grid-theme.import.scss +0 -2
  198. package/loader/_loader-theme.import.scss +0 -2
  199. package/popover/_popover-theme.import.scss +0 -2
  200. package/progress/_progress-theme.import.scss +0 -2
  201. package/select/_select-density.scss +0 -68
  202. package/select/_select-theme.import.scss +0 -3
  203. package/split/_split-theme.import.scss +0 -2
  204. package/tooltip/_tooltip-theme.import.scss +0 -1
@@ -0,0 +1,303 @@
1
+ @use 'sass:list';
2
+ @use 'sass:map';
3
+ @use '../style/validation';
4
+ @use './m2-inspection';
5
+
6
+ $_internals: _mat-theming-internals-do-not-access;
7
+
8
+ $_m3-typescales: (
9
+ display-large,
10
+ display-medium,
11
+ display-small,
12
+ headline-large,
13
+ headline-medium,
14
+ headline-small,
15
+ title-large,
16
+ title-medium,
17
+ title-small,
18
+ label-large,
19
+ label-medium,
20
+ label-small,
21
+ body-large,
22
+ body-medium,
23
+ body-small,
24
+ );
25
+
26
+ $_typography-properties: (font, font-family, line-height, font-size, letter-spacing, font-weight);
27
+
28
+ /// Validates that the given value is a versioned theme object.
29
+ /// @param {Any} $theme The theme object to validate.
30
+ /// @return {Boolean|Null} true if the theme has errors, else null.
31
+ @function _validate-theme-object($theme) {
32
+ $err: validation.validate-type($theme, 'map') or
33
+ map.get($theme, $_internals, theme-version) == null;
34
+ @return if($err, true, null);
35
+ }
36
+
37
+ /// Gets the version number of a theme object. A theme that is not a valid versioned theme object is
38
+ /// considered to be version 0.
39
+ /// @param {Map} $theme The theme to check the version of
40
+ /// @return {Number} The version number of the theme (0 if unknown).
41
+ @function get-theme-version($theme) {
42
+ $err: _validate-theme-object($theme);
43
+ @return if($err, 0, map.get($theme, $_internals, theme-version) or 0);
44
+ }
45
+
46
+ /// Gets the type of theme represented by a theme object (light or dark).
47
+ /// @param {Map} $theme The theme
48
+ /// @return {String} The type of theme (either `light` or `dark`).
49
+ @function get-theme-type($theme) {
50
+ $version: get-theme-version($theme);
51
+ @if $version == 0 {
52
+ @return m2-inspection.get-theme-type($theme);
53
+ }
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;
62
+ }
63
+ }
64
+
65
+ /// Gets a color from a theme object. This function can take 2 or 3 arguments. If 2 arguments are
66
+ /// passed, the second argument is treated as the name of a color role. If 3 arguments are passed,
67
+ /// the second argument is treated as the name of a color palette (primary, secondary, etc.) and the
68
+ /// third is treated as the palette hue (10, 50, etc.)
69
+ /// @param {Map} $theme The theme
70
+ /// @param {String} $color-role-or-palette-name The name of the color role to get, or the name of a
71
+ /// color palette.
72
+ /// @param {Number} $hue The palette hue to get (passing this argument means the second argument is
73
+ /// interpreted as a palette name).
74
+ /// @return {Color} The requested theme color.
75
+ @function get-theme-color($theme, $args...) {
76
+ $version: get-theme-version($theme);
77
+ $args-count: list.length($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...);
84
+ }
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;
95
+ }
96
+ }
97
+
98
+ /// Gets a role color from a theme object.
99
+ /// @param {Map} $theme The theme
100
+ /// @param {String} $color-role-name The name of the color role to get.
101
+ /// @return {Color} The requested role color.
102
+ @function _get-theme-role-color($theme, $color-role-name) {
103
+ $err: _validate-theme-object($theme);
104
+ @if $err {
105
+ // TODO(mmalerba): implement for old style theme objects.
106
+ @error #{'get-theme-color does not support legacy theme objects.'};
107
+ }
108
+ @if not theme-has($theme, color) {
109
+ @error 'Color information is not available on this theme.';
110
+ }
111
+ $color-roles: map.get($theme, $_internals, color-tokens, (mdc, theme));
112
+ $result: map.get($color-roles, $color-role-name);
113
+ @if not $result {
114
+ @error #{'Valid color roles are: #{map.keys($color-roles)}. Got:'} $color-role-name;
115
+ }
116
+ @return $result;
117
+ }
118
+
119
+ /// Gets a palette color from a theme object.
120
+ /// @param {Map} $theme The theme
121
+ /// @param {String} $palette-name The name of the palette to get the color from.
122
+ /// @param {Number} $hue The hue to read from the palette.
123
+ /// @return {Color} The requested palette color.
124
+ @function _get-theme-palette-color($theme, $palette-name, $hue) {
125
+ $err: _validate-theme-object($theme);
126
+ @if $err {
127
+ // TODO(mmalerba): implement for old style theme objects.
128
+ @error #{'get-theme-color does not support legacy theme objects.'};
129
+ }
130
+ @if not theme-has($theme, color) {
131
+ @error 'Color information is not available on this theme.';
132
+ }
133
+ $palettes: map.get($theme, $_internals, palettes);
134
+ $palette: map.get($palettes, $palette-name);
135
+ @if not $palette {
136
+ $supported-palettes: map.keys($palettes);
137
+ @error #{'Valid palettes are: #{$supported-palettes}. Got:'} $palette-name;
138
+ }
139
+ $result: map.get($palette, $hue);
140
+ @if not $result {
141
+ $supported-hues: map.keys($palette);
142
+ @error #{'Valid hues for'} $palette-name #{'are: #{$supported-hues}. Got:'} $hue;
143
+ }
144
+ @return $result;
145
+ }
146
+
147
+ /// Gets a typography value from a theme object.
148
+ /// @param {Map} $theme The theme
149
+ /// @param {String} $typescale The typescale name.
150
+ /// @param {String} $property The CSS font property to get
151
+ /// (font, font-family, font-size, font-weight, line-height, or letter-spacing).
152
+ /// @return {*} The value of the requested font property.
153
+ @function get-theme-typography($theme, $typescale, $property: font) {
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
+ }
182
+ }
183
+
184
+ /// Gets the density scale from a theme object.
185
+ /// @param {Map} $theme The theme
186
+ /// @return {Number} The density scale.
187
+ @function get-theme-density($theme) {
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);
197
+ }
198
+ @else {
199
+ @error #{'Unrecognized theme version:'} $version;
200
+ }
201
+ }
202
+
203
+ /// Checks whether the theme has information about given theming system.
204
+ /// @param {Map} $theme The theme
205
+ /// @param {String} $system The system to check
206
+ /// @param {Boolean} Whether the theme has information about the system.
207
+ @function theme-has($theme, $system) {
208
+ $version: get-theme-version($theme);
209
+ @if $version == 0 {
210
+ @return m2-inspection.theme-has($theme, $system);
211
+ }
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
218
+ map.get($theme, $_internals, theme-type) != null and
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;
228
+ }
229
+ @else {
230
+ @error #{'Unrecognized theme version:'} $version;
231
+ }
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;
266
+ }
267
+ }
268
+
269
+ /// Gets the set of tokens from the given theme, limited to those affected by the requested theming
270
+ /// systems.
271
+ /// @param {Map} $theme The theme to get tokens from.
272
+ /// @param {String...} $systems The theming systems to get tokens for. Valid values are: color,
273
+ /// typography, density, base. If no systems are passed, all tokens will be returned.
274
+ /// @return {Map} The requested tokens for the theme.
275
+ @function get-theme-tokens($theme, $systems...) {
276
+ $systems: if(list.length($systems) == 0, (color, typography, density, base), $systems);
277
+ $err: _validate-theme-object($theme);
278
+ @if $err {
279
+ @error #{'Expected $theme to be an Angular Material theme object. Got:'} $theme;
280
+ }
281
+ $err: validation.validate-allowed-values($systems, color, typography, density, base);
282
+ @if $err {
283
+ @error #{'Expected $systems to contain valid system names (color, typography, density, or'}
284
+ #{'base). Got invalid system names:'} $err;
285
+ }
286
+ $result: ();
287
+ @each $system in $systems {
288
+ $result: map.deep-merge($result, map.get($theme, $_internals, '#{$system}-tokens'));
289
+ }
290
+ @return $result;
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,266 @@
1
+ @use 'sass:list';
2
+ @use 'sass:map';
3
+ @use 'sass:meta';
4
+ @use '@angular/material' as mat;
5
+
6
+ /// Key used to access the Angular Material theme internals.
7
+ $_internals: _mat-theming-internals-do-not-access;
8
+
9
+ /// Keys that indicate a config object is a color config.
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
+ /// Keys that indicate a config object is a typography config.
21
+ $_typography-keys: (
22
+ headline-1,
23
+ headline-2,
24
+ headline-3,
25
+ headline-4,
26
+ headline-5,
27
+ headline-6,
28
+ subtitle-1,
29
+ font-family,
30
+ subtitle-2,
31
+ body-1,
32
+ body-2,
33
+ button,
34
+ caption,
35
+ overline,
36
+ );
37
+
38
+ /// The CSS typography properties supported by the inspection API.
39
+ $_typography-properties: (font, font-family, line-height, font-size, letter-spacing, font-weight);
40
+
41
+ /// Gets the m2-config from the theme.
42
+ @function _get-m2-config($theme) {
43
+ // It is possible for a user to pass a "density theme" that is just a number.
44
+ @if meta.type-of($theme) != 'map' {
45
+ @return $theme;
46
+ }
47
+ $internal: map.get($theme, $_internals, m2-config);
48
+ $theme: map.remove($theme, $_internals);
49
+ @return if(_is-error-theme($theme), $internal, $theme);
50
+ }
51
+
52
+ /// Checks whether the given theme contains error values.
53
+ /// @param {*} $theme The theme to check.
54
+ /// @return {Boolean} true if the theme contains error values, else false.
55
+ @function _is-error-theme($theme) {
56
+ @if meta.type-of($theme) != 'map' {
57
+ @return false;
58
+ }
59
+ @if map.get($theme, ERROR) {
60
+ @return true;
61
+ }
62
+ @return _is-error-theme(list.nth(map.values($theme), 1));
63
+ }
64
+
65
+ /// Checks whether the given theme object has any of the given keys.
66
+ /// @param {Map} $theme The theme to check
67
+ /// @param {List} $keys The keys to check for
68
+ /// @return {Boolean} Whether the theme has any of the given keys.
69
+ @function _has-any-key($theme, $keys) {
70
+ @each $key in $keys {
71
+ @if map.has-key($theme, $key) {
72
+ @return true;
73
+ }
74
+ }
75
+ @return false;
76
+ }
77
+
78
+ /// Checks whether the given theme is a density scale value.
79
+ /// @param {*} $theme The theme to check.
80
+ /// @return {Boolean} true if the theme is a density scale value, else false.
81
+ @function _is-density-value($theme) {
82
+ @return $theme == minimum or $theme == maximum or meta.type-of($theme) == 'number';
83
+ }
84
+
85
+ /// Gets the type of theme represented by a theme object (light or dark).
86
+ /// @param {Map} $theme The theme
87
+ /// @return {String} The type of theme (either `light` or `dark`).
88
+ @function get-theme-type($theme) {
89
+ $theme: _get-m2-config($theme);
90
+ @if not theme-has($theme, color) {
91
+ @error 'Color information is not available on this theme.';
92
+ }
93
+ $colors: mat.get-color-config($theme);
94
+ // Some apps seem to have mistakenly created nested color themes that somehow work with our old
95
+ // theme normalization logic. This check allows those apps to keep working.
96
+ @if theme-has($colors, color) {
97
+ $colors: mat.get-color-config($colors);
98
+ }
99
+ @return if(map.get($colors, is-dark), dark, light);
100
+ }
101
+
102
+ /// Gets a color from a theme object. This function can take 2 or 3 arguments. If 2 arguments are
103
+ /// passed, the second argument is treated as the name of a color role. If 3 arguments are passed,
104
+ /// the second argument is treated as the name of a color palette (primary, secondary, etc.) and the
105
+ /// third is treated as the palette hue (10, 50, etc.)
106
+ /// @param {Map} $theme The theme
107
+ /// @param {String} $palette-name The name of a color palette.
108
+ /// @param {Number} $hue The palette hue to get (passing this argument means the second argument is
109
+ /// interpreted as a palette name).
110
+ /// @return {Color} The requested theme color.
111
+ @function get-theme-color($theme, $palette-name, $args...) {
112
+ $theme: _get-m2-config($theme);
113
+ @if not theme-has($theme, color) {
114
+ @error 'Color information is not available on this theme.';
115
+ }
116
+ $colors: mat.get-color-config($theme);
117
+ // Some apps seem to have mistakenly created nested color themes that somehow work with our old
118
+ // theme normalization logic. This check allows those apps to keep working.
119
+ @if theme-has($colors, color) {
120
+ $colors: mat.get-color-config($colors);
121
+ }
122
+ $palette: map.get($colors, $palette-name);
123
+ @if not $palette {
124
+ @error 'Unrecognized palette name:' $palette-name;
125
+ }
126
+ @return mat.get-color-from-palette($palette, $args...);
127
+ }
128
+
129
+ /// Gets a typography value from a theme object.
130
+ /// @param {Map} $theme The theme
131
+ /// @param {String} $typescale The typescale name.
132
+ /// @param {String} $property The CSS font property to get
133
+ /// (font, font-family, font-size, font-weight, line-height, or letter-spacing).
134
+ /// @return {*} The value of the requested font property.
135
+ @function get-theme-typography($theme, $typescale, $property) {
136
+ $theme: _get-m2-config($theme);
137
+ @if not theme-has($theme, typography) {
138
+ @error 'Typography information is not available on this theme.';
139
+ }
140
+ $typography: mat.private-typography-to-2018-config(
141
+ mat.get-typography-config($theme));
142
+ @if $property == font {
143
+ $font-weight: mat.font-weight($typography, $typescale);
144
+ $font-size: mat.font-size($typography, $typescale);
145
+ $line-height: mat.line-height($typography, $typescale);
146
+ $font-family: mat.font-family($typography, $typescale);
147
+ @return ($font-weight list.slash($font-size, $line-height) $font-family);
148
+ }
149
+ @else if $property == font-family {
150
+ $result: mat.font-family($typography, $typescale);
151
+ @return $result or mat.font-family($typography);
152
+ }
153
+ @else if $property == font-size {
154
+ @return mat.font-size($typography, $typescale);
155
+ }
156
+ @else if $property == font-weight {
157
+ @return mat.font-weight($typography, $typescale);
158
+ }
159
+ @else if $property == line-height {
160
+ @return mat.line-height($typography, $typescale);
161
+ }
162
+ @else if $property == letter-spacing {
163
+ @return mat.letter-spacing($typography, $typescale);
164
+ }
165
+ @else {
166
+ @error #{'Valid typography properties are: #{$_typography-properties}. Got:'} $property;
167
+ }
168
+ }
169
+
170
+ /// Gets the density scale from a theme object.
171
+ /// @param {Map} $theme The theme
172
+ /// @return {Number} The density scale.
173
+ @function get-theme-density($theme) {
174
+ $theme: _get-m2-config($theme);
175
+ @if not theme-has($theme, density) {
176
+ @error 'Density information is not available on this theme.';
177
+ }
178
+ $scale: mat.get-density-config($theme);
179
+ @return mat.clamp-density($scale, -5);
180
+ }
181
+
182
+ /// Checks whether the theme has information about given theming system.
183
+ /// @param {Map} $theme The theme
184
+ /// @param {String} $system The system to check
185
+ /// @param {Boolean} Whether the theme has information about the system.
186
+ @function theme-has($theme, $system) {
187
+ $theme: _get-m2-config($theme);
188
+ @if $system == base {
189
+ @return true;
190
+ }
191
+ @if $system == color {
192
+ $color: mat.get-color-config($theme);
193
+ @return $color != null and _has-any-key($color, $_color-keys);
194
+ }
195
+ @if $system == typography {
196
+ $typography: mat.get-typography-config($theme);
197
+ @return $typography != null and _has-any-key($typography, $_typography-keys);
198
+ }
199
+ @if $system == density {
200
+ // Backwards compatibility for the case where an explicit, but invalid density is given
201
+ // (this was previously treated as density 0).
202
+ @if meta.type-of($theme) == 'map' and map.get($theme, density) {
203
+ @return true;
204
+ }
205
+ $density: mat.get-density-config($theme);
206
+ @return $density != null and _is-density-value($density);
207
+ }
208
+ @error 'Valid systems are: base, color, typography, density. Got:' $system;
209
+ }
210
+
211
+ /// Removes the information about the given theming system(s) from the given theme.
212
+ /// @param {Map} $theme The theme to remove information from
213
+ /// @param {String...} $systems The systems to remove
214
+ /// @return {Map} A version of the theme without the removed theming systems.
215
+ @function theme-remove($theme, $systems...) {
216
+ $internal: map.get($theme, $_internals, m2-config);
217
+ @each $system in $systems {
218
+ @if $system == color {
219
+ $theme: map.set($theme, color, null);
220
+ }
221
+ @else if $system == typography {
222
+ $theme: map.set($theme, typography, null);
223
+ }
224
+ @else if $system == density {
225
+ $theme: map.set($theme, density, null);
226
+ }
227
+ }
228
+ @if $internal {
229
+ $internal: theme-remove($internal, $systems...);
230
+ $theme: map.set($theme, $_internals, m2-config, $internal);
231
+ }
232
+ @return $theme;
233
+ }
234
+
235
+ /// Gets a version of the theme with a modified typography config that preserves old behavior in
236
+ /// some components that previously used `private-typography-to-2014-config`.
237
+ /// Do not introduce new usages of this, it should be cleaned up and removed.
238
+ /// @deprecated
239
+ @function private-get-typography-back-compat-theme($theme) {
240
+ // It is possible for a user to pass a "density theme" that is just a number.
241
+ @if meta.type-of($theme) != 'map' {
242
+ @return $theme;
243
+ }
244
+ $internal: map.get($theme, $_internals, m2-config);
245
+ $theme: map.remove($theme, $_internals);
246
+ @if theme-has($theme, typography) {
247
+ $typography-config: mat.get-typography-config($theme);
248
+ // gmat configs have both 2018 and 2014 keys.
249
+ @if (not mat.private-typography-is-2014-config($typography-config)) or
250
+ (not mat.private-typography-is-2018-config($typography-config)) {
251
+ @return $theme;
252
+ }
253
+ $new-typography-config: mat.private-typography-to-2018-config(
254
+ $typography-config, true);
255
+ // subtitle-2 is mapped differently by `private-typography-to-2014-config`.
256
+ $new-typography-config: map.set(
257
+ $new-typography-config, subtitle-2, map.get($new-typography-config, body-1));
258
+ $theme: if($theme == $typography-config, $new-typography-config,
259
+ map.set($theme, typography, $new-typography-config));
260
+ }
261
+ @if $internal {
262
+ $internal: private-get-typography-back-compat-theme($internal);
263
+ $theme: map.set($theme, $_internals, m2-config, $internal);
264
+ }
265
+ @return $theme;
266
+ }
@@ -3,11 +3,10 @@
3
3
  @use '@material/theme/custom-properties' as mdc-custom-properties;
4
4
  @use '@material/theme/theme' as mdc-theme;
5
5
  @use '@material/theme/keys' as mdc-keys;
6
- @use '../theming/palette';
7
- @use '../theming/theming';
6
+ @use '@angular/material' as mat;
8
7
  @use '../typography/typography';
9
8
 
10
- $_placeholder-color-palette: theming.define-palette(palette.$red-palette);
9
+ $_placeholder-color-palette: mat.define-palette(mat.$red-palette);
11
10
 
12
11
  // Placeholder color config that can be passed to token getter functions when generating token
13
12
  // slots.
@@ -16,8 +15,8 @@ $placeholder-color-config: (
16
15
  accent: $_placeholder-color-palette,
17
16
  warn: $_placeholder-color-palette,
18
17
  is-dark: false,
19
- foreground: palette.$light-theme-foreground-palette,
20
- background: palette.$light-theme-background-palette,
18
+ foreground: mat.$light-theme-foreground-palette,
19
+ background: mat.$light-theme-background-palette,
21
20
  );
22
21
 
23
22
  $_placeholder-typography-level-config: typography.typography-config-level-from-mdc(body1);
@@ -1,7 +1,4 @@
1
- @use 'sass:map';
2
- @use '../../../theming/theming';
3
- @use '../../../typography/typography-utils';
4
- @use '../../../mdc-helpers/mdc-helpers';
1
+ @use '../../../theming/inspection';
5
2
  @use '../../../style/sass-utils';
6
3
  @use '../../token-utils';
7
4
 
@@ -15,7 +12,8 @@ $prefix: (mdc, plain-tooltip);
15
12
  // `null` indicates that we are intentionally choosing not to emit a slot or value for the token in
16
13
  // our CSS.
17
14
  @function get-unthemable-tokens() {
18
- @return ( // Border radius for the tooltip container.
15
+ @return (
16
+ // Border radius for the tooltip container.
19
17
  container-shape: 4px,
20
18
  // Line height of the tooltip text.
21
19
  supporting-text-line-height: 16px,
@@ -25,48 +23,42 @@ $prefix: (mdc, plain-tooltip);
25
23
  }
26
24
 
27
25
  // Tokens that can be configured through Angular Material's color theming API.
28
- @function get-color-tokens($config) {
29
- $background: map.get($config, background);
26
+ @function get-color-tokens($theme) {
30
27
 
31
- @return ( // Color of the tooltip container.
32
- container-color: theming.get-color-from-palette($background, tooltip),
28
+ @return (
29
+ // Color of the tooltip container.
30
+ container-color: inspection.get-theme-color($theme, background, tooltip),
33
31
  // Color of the tooltip text.
34
32
  supporting-text-color: #fff,
35
33
  );
36
34
  }
37
35
 
38
36
  // Tokens that can be configured through Angular Material's typography theming API.
39
- @function get-typography-tokens($config) {
40
-
41
- // TODO(amysorto): The earlier implementation of the tooltip used MDC's APIs to create the
42
- // typography tokens. As a result, we unintentionally allowed `null` typography configs to be
43
- // passed in. Since there a lot of apps that now depend on this pattern, we need this temporary
44
- // fallback.
45
- @if ($config ==null) {
46
- $config: mdc-helpers.private-fallback-typography-from-mdc();
47
- }
48
-
49
- @return ( // Font for the tooltip text.
50
- supporting-text-font: typography-utils.font-family($config, caption) or typography-utils.font-family($config),
37
+ @function get-typography-tokens($theme) {
38
+ @return (
39
+ // Font for the tooltip text.
40
+ supporting-text-font: inspection.get-theme-typography($theme, caption, font-family),
51
41
  // Font size for the tooltip text.
52
- supporting-text-size: typography-utils.font-size($config, caption),
42
+ supporting-text-size: inspection.get-theme-typography($theme, caption, font-size),
53
43
  // Font weight of the tooltip text.
54
- supporting-text-weight: typography-utils.font-weight($config, caption),
44
+ supporting-text-weight: inspection.get-theme-typography($theme, caption, font-weight),
55
45
  // Tracking (space between letters) of the tooltip text.
56
- supporting-text-tracking: typography-utils.letter-spacing($config, caption),
46
+ supporting-text-tracking: inspection.get-theme-typography($theme, caption, letter-spacing),
57
47
  );
58
48
  }
59
49
 
60
50
  // Tokens that can be configured through Angular Material's density theming API.
61
- @function get-density-tokens($config) {
51
+ @function get-density-tokens($theme) {
62
52
  @return ();
63
53
  }
64
54
 
65
55
  // Combines the tokens generated by the above functions into a single map with placeholder values.
66
56
  // This is used to create token slots.
67
57
  @function get-token-slots() {
68
- @return sass-utils.deep-merge-all(get-unthemable-tokens(),
69
- get-color-tokens(token-utils.$placeholder-color-config),
70
- get-typography-tokens(token-utils.$placeholder-typography-config),
71
- get-density-tokens(token-utils.$placeholder-density-config));
58
+ @return sass-utils.deep-merge-all(
59
+ get-unthemable-tokens(),
60
+ get-color-tokens(token-utils.$placeholder-color-config),
61
+ get-typography-tokens(token-utils.$placeholder-typography-config),
62
+ get-density-tokens(token-utils.$placeholder-density-config)
63
+ );
72
64
  }