@angular/material-experimental 17.0.4 → 17.0.5

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.
package/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  The MIT License
2
2
 
3
- Copyright (c) 2023 Google LLC.
3
+ Copyright (c) 2024 Google LLC.
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
@@ -7,5 +7,5 @@
7
7
  */
8
8
  import { Version } from '@angular/core';
9
9
  /** Current version of the Material experimental package. */
10
- export const VERSION = new Version('17.0.4');
10
+ export const VERSION = new Version('17.0.5');
11
11
  //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidmVyc2lvbi5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uLy4uLy4uL3NyYy9tYXRlcmlhbC1leHBlcmltZW50YWwvdmVyc2lvbi50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQTs7Ozs7O0dBTUc7QUFFSCxPQUFPLEVBQUMsT0FBTyxFQUFDLE1BQU0sZUFBZSxDQUFDO0FBRXRDLDREQUE0RDtBQUM1RCxNQUFNLENBQUMsTUFBTSxPQUFPLEdBQUcsSUFBSSxPQUFPLENBQUMsbUJBQW1CLENBQUMsQ0FBQyIsInNvdXJjZXNDb250ZW50IjpbIi8qKlxuICogQGxpY2Vuc2VcbiAqIENvcHlyaWdodCBHb29nbGUgTExDIEFsbCBSaWdodHMgUmVzZXJ2ZWQuXG4gKlxuICogVXNlIG9mIHRoaXMgc291cmNlIGNvZGUgaXMgZ292ZXJuZWQgYnkgYW4gTUlULXN0eWxlIGxpY2Vuc2UgdGhhdCBjYW4gYmVcbiAqIGZvdW5kIGluIHRoZSBMSUNFTlNFIGZpbGUgYXQgaHR0cHM6Ly9hbmd1bGFyLmlvL2xpY2Vuc2VcbiAqL1xuXG5pbXBvcnQge1ZlcnNpb259IGZyb20gJ0Bhbmd1bGFyL2NvcmUnO1xuXG4vKiogQ3VycmVudCB2ZXJzaW9uIG9mIHRoZSBNYXRlcmlhbCBleHBlcmltZW50YWwgcGFja2FnZS4gKi9cbmV4cG9ydCBjb25zdCBWRVJTSU9OID0gbmV3IFZlcnNpb24oJzAuMC4wLVBMQUNFSE9MREVSJyk7XG4iXX0=
@@ -1,7 +1,7 @@
1
1
  import { Version } from '@angular/core';
2
2
 
3
3
  /** Current version of the Material experimental package. */
4
- const VERSION = new Version('17.0.4');
4
+ const VERSION = new Version('17.0.5');
5
5
 
6
6
  export { VERSION };
7
7
  //# sourceMappingURL=material-experimental.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"material-experimental.mjs","sources":["../../../../../../src/material-experimental/version.ts"],"sourcesContent":["/**\n * @license\n * Copyright Google LLC All Rights Reserved.\n *\n * Use of this source code is governed by an MIT-style license that can be\n * found in the LICENSE file at https://angular.io/license\n */\n\nimport {Version} from '@angular/core';\n\n/** Current version of the Material experimental package. */\nexport const VERSION = new Version('17.0.4');\n"],"names":[],"mappings":";;AAUA;MACa,OAAO,GAAG,IAAI,OAAO,CAAC,mBAAmB;;;;"}
1
+ {"version":3,"file":"material-experimental.mjs","sources":["../../../../../../src/material-experimental/version.ts"],"sourcesContent":["/**\n * @license\n * Copyright Google LLC All Rights Reserved.\n *\n * Use of this source code is governed by an MIT-style license that can be\n * found in the LICENSE file at https://angular.io/license\n */\n\nimport {Version} from '@angular/core';\n\n/** Current version of the Material experimental package. */\nexport const VERSION = new Version('17.0.5');\n"],"names":[],"mappings":";;AAUA;MACa,OAAO,GAAG,IAAI,OAAO,CAAC,mBAAmB;;;;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@angular/material-experimental",
3
- "version": "17.0.4",
3
+ "version": "17.0.5",
4
4
  "description": "Experimental components for Angular Material",
5
5
  "repository": {
6
6
  "type": "git",
@@ -49,12 +49,12 @@
49
49
  },
50
50
  "peerDependencies": {
51
51
  "@angular/animations": "^17.0.0 || ^18.0.0",
52
- "@angular/cdk": "17.0.4",
52
+ "@angular/cdk": "17.0.5",
53
53
  "@angular/core": "^17.0.0 || ^18.0.0",
54
54
  "@angular/common": "^17.0.0 || ^18.0.0",
55
55
  "@angular/forms": "^17.0.0 || ^18.0.0",
56
56
  "@angular/platform-browser": "^17.0.0 || ^18.0.0",
57
- "@angular/material": "17.0.4"
57
+ "@angular/material": "17.0.5"
58
58
  },
59
59
  "dependencies": {
60
60
  "tslib": "^2.3.0",
@@ -439,8 +439,23 @@
439
439
  /// @param {Boolean} $exclude-hardcoded Whether to exclude hardcoded token values
440
440
  /// @return {Map} A set of custom tokens for the mat-slider
441
441
  @function slider($systems, $exclude-hardcoded) {
442
+ $ripple-color: map.get($systems, md-sys-color, primary);
443
+ $hover-ripple-color: if($ripple-color == null, null, #{rgba($ripple-color, 0.05)});
444
+ $focus-ripple-color: if($ripple-color == null, null, #{rgba($ripple-color, 0.2)});
445
+
442
446
  @return (
447
+ ripple-color: $ripple-color,
448
+ hover-state-layer-color: $hover-ripple-color,
449
+ focus-state-layer-color: $focus-ripple-color,
443
450
  value-indicator-opacity: _hardcode(1, $exclude-hardcoded),
451
+ value-indicator-padding: _hardcode(0, $exclude-hardcoded),
452
+ value-indicator-width: _hardcode(28px, $exclude-hardcoded),
453
+ value-indicator-height: _hardcode(28px, $exclude-hardcoded),
454
+ value-indicator-caret-display: _hardcode(none, $exclude-hardcoded),
455
+ value-indicator-border-radius: _hardcode(50% 50% 50% 0, $exclude-hardcoded),
456
+ value-indicator-text-transform: _hardcode(rotate(45deg), $exclude-hardcoded),
457
+ value-indicator-container-transform:
458
+ _hardcode(translateX(-50%) rotate(-45deg), $exclude-hardcoded)
444
459
  );
445
460
  }
446
461
 
@@ -1,93 +0,0 @@
1
- @use 'sass:color';
2
- @use 'sass:meta';
3
- @use '@angular/material' as mat;
4
- @use './token-resolution';
5
-
6
- // TODO(mmalerba): This should live under material/card when moving out of experimental.
7
-
8
- /// Gets tokens for setting the card's shape.
9
- /// @param {String} $shape The card's shape.
10
- /// @return {Map} A map of tokens for setting the card's shape.
11
- // Note: we use a function rather than simple rename, because we want to map a single shape value to
12
- // multiple tokens, rather than offer separate shape customizations for elevated and outlined cards.
13
- @function _get-tokens-for-card-shape($shape) {
14
- @return (
15
- (mdc, elevated-card): (container-shape: $shape),
16
- (mdc, outline-card): (container-shape: $shape),
17
- );
18
- }
19
-
20
- /// Gets tokens for setting the card's color.
21
- /// @param {String} $shape The card's shape.
22
- /// @return {Map} A map of tokens for setting the card's shape.
23
- @function _get-tokens-for-card-color($color) {
24
- @return (
25
- (mdc, elevated-card): (container-color: $color),
26
- (mdc, outline-card): (container-color: $color),
27
- );
28
- }
29
-
30
- /// Gets a map of card token values that are derived from the theme type.
31
- /// @param {'light' | 'dark'} $theme-type The type of theme.
32
- /// @return {Map} A map of card token values derived from the given theme type.
33
- @function _get-tokens-for-theme-type($theme-type) {
34
- $is-dark: $theme-type == 'dark';
35
- $foreground: if($is-dark, white, black);
36
- $card-color: if($is-dark, mat.get-color-from-palette(mat.$gray-palette, 800), white);
37
- $outline-color: color.change($foreground, $alpha: 0.12);
38
- $subtitle-color: if($is-dark, rgba(white, 0.7), rgba(black, 0.54));
39
-
40
- @return (
41
- (mdc, elevated-card): (
42
- container-color: $card-color,
43
- ),
44
- (mdc, outlined-card): (
45
- container-color: $card-color,
46
- outline-color: $outline-color,
47
- ),
48
- (mat, card): (
49
- subtitle-text-color: $subtitle-color,
50
- ),
51
- );
52
- }
53
-
54
- /// Resolvers for mat-card customizations.
55
- $_customization-resolvers: mat.private-merge-all(
56
- token-resolution.alias((
57
- elevation: container-elevation,
58
- shadow-color: container-shadow-color,
59
- ), (mdc, elevated-card)),
60
- token-resolution.forward((
61
- outline-width,
62
- outline-color
63
- ), (mdc, outlined-card)),
64
- token-resolution.alias((
65
- title-font: title-text-font,
66
- title-line-height: title-text-line-height,
67
- title-font-size: title-text-size,
68
- title-letter-spacing: title-text-tracking,
69
- title-font-weight: title-text-weight,
70
- subtitle-font: subtitle-text-font,
71
- subtitle-line-height: subtitle-text-line-height,
72
- subtitle-font-size: subtitle-text-size,
73
- subtitle-letter-spacing: subtitle-text-tracking,
74
- subtitle-font-weight: subtitle-text-weight,
75
- subtitle-color: subtitle-text-color
76
- ), (mat, card)),
77
- (
78
- background-color: meta.get-function(_get-tokens-for-card-color),
79
- border-radius: meta.get-function(_get-tokens-for-card-shape),
80
- theme-type: meta.get-function(_get-tokens-for-theme-type),
81
- )
82
- );
83
-
84
- /// Configure the mat-card's theme.
85
- /// @param {Map} $customizations [()] A map of custom values to use when theming mat-card.
86
- @function card($customizations: ()) {
87
- @return (
88
- id: 'mat.card',
89
- customizations: token-resolution.resolve-customized-tokens(
90
- 'mat.card', $_customization-resolvers, $customizations),
91
- deps: (),
92
- );
93
- }
@@ -1,109 +0,0 @@
1
- @use 'sass:color';
2
- @use 'sass:map';
3
- @use 'sass:meta';
4
- @use '@angular/material' as mat;
5
- @use '@material/theme/theme-color' as mdc-theme-color;
6
- @use './token-resolution';
7
-
8
- // TODO(mmalerba): This should live under material/checkbox when moving out of experimental.
9
-
10
- // Duplicated from core/tokens/m2/mdc/checkbox
11
- // TODO(mmalerba): Delete duplicated code when this is moved out of experimental.
12
- @function _contrast-tone($value, $light-color: '#fff', $dark-color: '#000') {
13
- @if ($value == 'dark' or $value == 'light' or type-of($value) == 'color') {
14
- @return if(mdc-theme-color.contrast-tone($value) == 'dark', $dark-color, $light-color);
15
- }
16
- @return false;
17
- }
18
-
19
- /// Gets a map of checkbox token values that are derived from the given palette.
20
- /// @param {Map} $palette An Angular Material palette object.
21
- /// @return {Map} A map of checkbox token values derived from the given palette.
22
- @function _get-tokens-for-color-palette($palette) {
23
- $palette-default-color: mat.get-color-from-palette($palette);
24
- $checkmark-color: _contrast-tone($palette-default-color);
25
-
26
- @return (
27
- (mdc, checkbox): (
28
- selected-checkmark-color: $checkmark-color,
29
- selected-focus-icon-color: $palette-default-color,
30
- selected-hover-icon-color: $palette-default-color,
31
- selected-icon-color: $palette-default-color,
32
- selected-pressed-icon-color: $palette-default-color,
33
- selected-focus-state-layer-color: $palette-default-color,
34
- selected-hover-state-layer-color: $palette-default-color,
35
- selected-pressed-state-layer-color: $palette-default-color,
36
- )
37
- );
38
- }
39
-
40
- /// Gets a map of checkbox token values that are derived from the theme type.
41
- /// @param {'light' | 'dark'} $theme-type The type of theme.
42
- /// @return {Map} A map of checkbox token values derived from the given theme type.
43
- @function _get-tokens-for-theme-type($theme-type) {
44
- $is-dark: $theme-type == dark;
45
- $foreground: if($is-dark, white, black);
46
- $disabled-color: color.change($foreground, $alpha: 0.38);
47
- $border-color: color.change($foreground, $alpha: 0.54);
48
- $active-border-color: mat.get-color-from-palette(mat.$gray-palette, if($is-dark, 200, 900));
49
-
50
- @return (
51
- (mdc, checkbox): (
52
- disabled-selected-icon-color: $disabled-color,
53
- disabled-unselected-icon-color: $disabled-color,
54
- unselected-focus-icon-color: $active-border-color,
55
- unselected-hover-icon-color: $active-border-color,
56
- unselected-icon-color: $border-color,
57
- unselected-pressed-icon-color: $border-color,
58
- unselected-focus-state-layer-color: $foreground,
59
- unselected-hover-state-layer-color: $foreground,
60
- unselected-pressed-state-layer-color: $foreground,
61
- )
62
- );
63
- }
64
-
65
- /// Resolvers for mat-checkbox customizations.
66
- $_customization-resolvers: map.merge(
67
- token-resolution.alias((
68
- checkmark-color: selected-checkmark-color,
69
- disabled-checkmark-color: disabled-selected-checkmark-color,
70
- selected-focus-ring-opacity: selected-focus-state-layer-opacity,
71
- selected-hover-ring-opacity: selected-hover-state-layer-opacity,
72
- selected-pressed-ring-opacity: selected-pressed-state-layer-opacity,
73
- unselected-focus-ring-opacity: unselected-focus-state-layer-opacity,
74
- unselected-hover-ring-opacity: unselected-hover-state-layer-opacity,
75
- unselected-pressed-ring-opacity: unselected-pressed-state-layer-opacity,
76
- disabled-selected-box-color: disabled-selected-icon-color,
77
- disabled-unselected-box-color: disabled-unselected-icon-color,
78
- selected-focus-box-color: selected-focus-icon-color,
79
- selected-hover-box-color: selected-hover-icon-color,
80
- selected-box-color: selected-icon-color,
81
- selected-pressed-box-color: selected-pressed-icon-color,
82
- unselected-focus-box-color: unselected-focus-icon-color,
83
- unselected-hover-box-color: unselected-hover-icon-color,
84
- unselected-box-color: unselected-icon-color,
85
- unselected-pressed-box-color: unselected-pressed-icon-color,
86
- selected-focus-ring-color: selected-focus-state-layer-color,
87
- selected-hover-ring-color: selected-hover-state-layer-color,
88
- selected-pressed-ring-color: selected-pressed-state-layer-color,
89
- unselected-focus-ring-color: unselected-focus-state-layer-color,
90
- unselected-hover-ring-color: unselected-hover-state-layer-color,
91
- unselected-pressed-ring-color: unselected-pressed-state-layer-color,
92
- ripple-size: state-layer-size,
93
- ), (mdc, checkbox)),
94
- (
95
- color-palette: meta.get-function(_get-tokens-for-color-palette),
96
- theme-type: meta.get-function(_get-tokens-for-theme-type),
97
- )
98
- );
99
-
100
- /// Configure the mat-checkbox's theme.
101
- /// @param {Map} $customizations [()] A map of custom values to use when theming mat-checkbox.
102
- @function checkbox($customizations: ()) {
103
- @return (
104
- id: 'mat.checkbox',
105
- customizations: token-resolution.resolve-customized-tokens(
106
- 'mat.checkbox', $_customization-resolvers, $customizations),
107
- deps: (),
108
- );
109
- }
@@ -1,146 +0,0 @@
1
- @use 'sass:map';
2
- @use '@angular/material' as mat;
3
- @use '@material/tokens/v0_161' as mdc-tokens;
4
-
5
- /// Picks a submap containing only the given keys out the given map.
6
- /// @param {Map} $map The map to pick from.
7
- /// @param {List} $keys The map keys to pick.
8
- /// @return {Map} A submap containing only the given keys.
9
- @function _pick($map, $keys) {
10
- $result: ();
11
- @each $key in $keys {
12
- @if map.has-key($map, $key) {
13
- $result: map.set($result, $key, map.get($map, $key));
14
- }
15
- }
16
- @return $result;
17
- }
18
-
19
- /// Filters keys with a null value out of the map.
20
- /// @param {Map} $map The map to filter.
21
- /// @return {Map} The given map with all of the null keys filtered out.
22
- @function _filter-nulls($map) {
23
- $result: ();
24
- @each $key, $val in $map {
25
- @if $val != null {
26
- $result: map.set($result, $key, $val);
27
- }
28
- }
29
- @return $result;
30
- }
31
-
32
- /// Gets the MDC tokens for the given prefix, M3 token values, and supported token slots.
33
- /// @param {List} $prefix The token prefix for the given tokens.
34
- /// @param {Map} $m3-values A map of M3 token values for the given prefix.
35
- /// @param {Map} $slots A map of token slots, with null value indicating the token is not supported.
36
- /// @return {Map} A map of fully qualified token names to values, for only the supported tokens.
37
- @function _get-mdc-tokens($prefix, $m3-values, $slots) {
38
- $used-token-names: map.keys(_filter-nulls(map.get($slots, $prefix)));
39
- $used-m3-tokens: _pick($m3-values, $used-token-names);
40
- @return (
41
- $prefix: $used-m3-tokens,
42
- );
43
- }
44
-
45
- /// Sets all of the standard typography tokens for the given token base name to the given typography
46
- /// level.
47
- /// @param {Map} $typography-tokens The MDC system-typescale tokens.
48
- /// @param {String} $base-name The token base name to get the typography tokens for
49
- /// @param {String} $typography-level The typography level to base the token values on.
50
- /// @return {Map} A map containing the typography tokens for the given base token name.
51
- @function _get-typography-tokens($typography-tokens, $base-name, $typography-level) {
52
- $result: ();
53
- @each $prop in (font, line-height, size, tracking, weight) {
54
- $result: map.set(
55
- $result,
56
- #{$base-name}-#{$prop},
57
- map.get($typography-tokens, #{$typography-level}-#{$prop}
58
- ));
59
- }
60
- @return $result;
61
- }
62
-
63
- /// Renames the keys in a map
64
- /// @param {Map} $map The map whose keys should be renamed
65
- /// @param {Map} $rename-keys A map of original key to renamed key to apply to $map
66
- /// @return {Map} The result of applying the given key renames to the given map.
67
- @function _rename-map-keys($map, $rename-keys) {
68
- $result: $map;
69
- @each $old-key-name, $new-key-name in $rename-keys {
70
- @if map.has-key($map, $old-key-name) {
71
- $result: map.set($result, $new-key-name, map.get($map, $old-key-name));
72
- }
73
- }
74
- @return $result;
75
- }
76
-
77
- /// Renames the official checkbox tokens to match the names actually used in MDC's code (which are
78
- /// different). This is a temporary workaround until MDC updates to use the correct names for the
79
- /// tokens.
80
- /// @param {Map} $tokens The map of checkbox tokens with the official tokens names
81
- /// @return {Map} The given tokens, renamed to be compatible with MDC's token implementation.
82
- @function _fix-checkbox-token-names($tokens) {
83
- $rename-keys: (
84
- 'selected-icon-color': 'selected-checkmark-color',
85
- 'selected-disabled-icon-color': 'disabled-selected-checkmark-color',
86
- 'selected-container-color': 'selected-icon-color',
87
- 'selected-hover-container-color': 'selected-hover-icon-color',
88
- 'selected-disabled-container-color': 'disabled-selected-icon-color',
89
- 'selected-disabled-container-opacity': 'disabled-selected-icon-opacity',
90
- 'selected-focus-container-color': 'selected-focus-icon-color',
91
- 'selected-pressed-container-color': 'selected-pressed-icon-color',
92
- 'unselected-disabled-outline-color': 'disabled-unselected-icon-color',
93
- 'unselected-disabled-container-opacity': 'disabled-unselected-icon-opacity',
94
- 'unselected-focus-outline-color': 'unselected-focus-icon-color',
95
- 'unselected-hover-outline-color': 'unselected-hover-icon-color',
96
- 'unselected-outline-color': 'unselected-icon-color',
97
- 'unselected-pressed-outline-color': 'unselected-pressed-icon-color'
98
- );
99
- @return _rename-map-keys($tokens, $rename-keys);
100
- }
101
-
102
- // TODO(mmalerba): We need a way to accept custom M3 token values generated from MDCs theme builder
103
- // or other means. We can't just use them directly without processing them first because we need to
104
- // add our made up tokens,
105
- /// Gets the default token values for M3.
106
- /// @return The default set of M3 tokens.
107
- @function get-m3-tokens() {
108
- $typography: mdc-tokens.md-sys-typescale-values();
109
- $colors: mdc-tokens.md-sys-color-values-light();
110
-
111
- // TODO(mmalerba): Refactor this to not depend on the legacy theme. This is a hack for now because
112
- // there is no good way to get the token slots in material-experimental without exposing them all
113
- // from material.
114
- $fake-theme: mat.define-light-theme((
115
- color: (
116
- primary: mat.define-palette(mat.$red-palette),
117
- accent: mat.define-palette(mat.$red-palette),
118
- warn: mat.define-palette(mat.$red-palette),
119
- ),
120
- typography: mat.define-typography-config(),
121
- density: 0
122
- ));
123
- $token-slots: mat.m2-tokens-from-theme($fake-theme);
124
-
125
- // TODO(mmalerba): Fill in remaining tokens.
126
- @return mat.private-merge-all(
127
- // Fill in official MDC tokens.
128
- _get-mdc-tokens((mdc, checkbox),
129
- _fix-checkbox-token-names(mdc-tokens.md-comp-checkbox-values()), $token-slots),
130
- _get-mdc-tokens((mdc, elevated-card), mdc-tokens.md-comp-elevated-card-values(),
131
- $token-slots),
132
- _get-mdc-tokens((mdc, outlined-card), mdc-tokens.md-comp-outlined-card-values(),
133
- $token-slots),
134
- // Choose values for our made up tokens based on MDC system tokens or sensible hardcoded
135
- // values.
136
- (
137
- (mat, card): mat.private-merge-all(
138
- _get-typography-tokens($typography, title-text, title-large),
139
- _get-typography-tokens($typography, subtitle-text, title-medium),
140
- (
141
- subtitle-text-color: map.get($colors, on-surface)
142
- )
143
- )
144
- ),
145
- );
146
- }
@@ -1,130 +0,0 @@
1
- @use 'sass:list';
2
- @use 'sass:map';
3
- @use 'sass:meta';
4
- @use '@angular/material' as mat;
5
-
6
- /// Whether to throw an error when a required dep is not configured. If false, the dep will be
7
- /// automatically configured instead.
8
- $_error-on-missing-dep: false;
9
-
10
- /// Applies the theme for the given component configuration.
11
- /// @param {Map} $tokens A map containing the default values to use for tokens not explicitly
12
- /// customized in the component config object.
13
- /// @param {List} $component The component config object to emit theme tokens for.
14
- /// @output CSS variables representing the theme tokens for this component.
15
- @mixin _apply-theme($tokens, $component) {
16
- $id: map.get($component, id);
17
- $tokens: map.deep-merge($tokens, map.get($component, customizations));
18
-
19
- // NOTE: for now we use a hardcoded if-chain, but in the future when first-class mixins are
20
- // supported, the configuration data will contain a reference to its own theme mixin.
21
- @if $id == 'mat.card' {
22
- @include mat.private-apply-card-theme-from-tokens($tokens);
23
- }
24
- @else if $id == 'mat.checkbox' {
25
- @include mat.private-apply-checkbox-theme-from-tokens($tokens);
26
- }
27
- @else {
28
- @error 'Unrecognized component theme: #{id}';
29
- }
30
- }
31
-
32
- /// Gets the transitive closure of the given list of component configuration dependencies.
33
- /// @param {List} $components The list of component config objects to get the transitive deps for.
34
- /// @param {Map} $configured [()] A map of already configured component IDs. Used for recursion,
35
- /// should not be passed when calling.
36
- /// @return {List} The transitive closure of configs for the given $components.
37
- // TODO(mmalerba): Currently we use the deps to determine if additional tokens, other than the
38
- // explicitly requested ones need to be emitted, but the deps do not affect the ordering in which
39
- // the various configs are processed. Before moving out of experimental we should think more about
40
- // the ordering behavior we want. For the most part the order shouldn't matter, unless we have 2
41
- // configs trying to set the same token.
42
- @function _get-transitive-deps($components, $configured: ()) {
43
- // Mark the given components as configured.
44
- @each $component in $components {
45
- $configured: map.set($configured, map.get($component, id), true);
46
- }
47
- $new-deps: ();
48
-
49
- // Check each of the given components for new deps.
50
- @each $component in $components {
51
- // Note: Deps are specified as getter functions that return a config object rather than a direct
52
- // config object. This allows us to only call the getter if the dep has not yet been configured.
53
- // This can be useful if we have 2 components that want to require each other to be configured.
54
- // Example: form-field and input. If we used direct config objects in this case, it would cause
55
- // infinite co-recursion.
56
- @each $dep-getter in mat.private-coerce-to-list(map.get($component, deps)) {
57
- $dep: meta.call($dep-getter);
58
- $dep-id: map.get($dep, id);
59
- @if not (map.has-key($configured, $dep-id)) {
60
- @if $_error-on-missing-dep {
61
- @error 'Missing theme: `#{map.get($component, id)}` depends on `#{$dep-id}`.' +
62
- ' Please configure the theme for `#{$dep-id}` in your call to `mat.theme`';
63
- }
64
- @else {
65
- $configured: map.set($configured, $dep-id, true);
66
- $new-deps: list.append($new-deps, $dep);
67
- }
68
- }
69
- }
70
- }
71
-
72
- // Append on the new deps to this list of component configurations and return.
73
- @if list.length($new-deps) > 0 {
74
- $components: list.join($components, _get-transitive-deps($new-deps, $configured));
75
- }
76
- @return $components;
77
- }
78
-
79
- /// Apply the themes for the given component configs with the given ste of fallback token values.
80
- /// @param {Map} $tokens A map of fallback values to use for tokens that are not explicitly
81
- /// customized by one of the component configs.
82
- /// @param {List} $components The list of component configurations to emit tokens for.
83
- /// @output CSS variables representing the theme tokens for the given component configs.
84
- @mixin _theme($tokens, $components) {
85
- // Call the theme mixin for each configured component.
86
- @each $component in $components {
87
- @include _apply-theme($tokens, $component);
88
- }
89
- }
90
-
91
- /// Takes a list of components to configure, and outputs theme tokens for the configured components.
92
- /// @param {List} $components The list of component configurations to emit tokens for.
93
- /// @output CSS variables representing the theme tokens for the given component configs.
94
- @mixin theme($components...) {
95
- $filtered-components: ();
96
- $tokens: null;
97
- @each $component in $components {
98
- @if (map.get($component, id) == 'mat.token-defaults') {
99
- @if $tokens == null {
100
- $tokens: map.get($component, tokens);
101
- }
102
- @else {
103
- @error 'mat.token-defaults specified multiple times in call to mat.theme';
104
- }
105
- }
106
- @else {
107
- $filtered-components: list.append($filtered-components, $component);
108
- }
109
- }
110
- $tokens: $tokens or ();
111
- @if $tokens == () {
112
- @each $component in $filtered-components {
113
- @if (map.get($component, customizations) or ()) == () {
114
- $component-id: map.get($component, id);
115
- @warn 'Call to `#{$component-id}()` will produce no output, this is likely a mistake.' +
116
- ' Did you mean to:'+
117
- '\a 1. Provide default token values with `mat.token-defaults`?' +
118
- '\a 2. Specify customizations in the call to `#{$component-id}`?';
119
- }
120
- }
121
- }
122
- @include _theme($tokens, $filtered-components);
123
- }
124
-
125
- @function token-defaults($tokens) {
126
- @return (
127
- id: 'mat.token-defaults',
128
- tokens: $tokens
129
- );
130
- }
@@ -1,88 +0,0 @@
1
- @use 'sass:list';
2
- @use 'sass:map';
3
- @use 'sass:meta';
4
-
5
- /// Creates a map of short token names to fully qualified token name under the given namespace.
6
- /// @param {List} $tokens A list of tokens to forward under the given namespace.
7
- /// @param {List} $namespace The namespace to use for the forwarded tokens.
8
- /// @return {Map} A map of the short token name to pairs of (namespace, token-name) representing the
9
- /// fully-qualified name
10
- /// @example
11
- /// forward((token1, token2), (mat, my-comp))
12
- /// => (
13
- /// token1: ((mat, my-comp), token1),
14
- /// token2: ((mat, my-comp), token1)
15
- /// )
16
- @function forward($tokens, $namespace) {
17
- $result: ();
18
- @each $token in $tokens {
19
- $result: map.set($result, $token, ($namespace, $token));
20
- }
21
- @return $result;
22
- }
23
-
24
- // Creates a map of token alias names to fully qualified canonical names under the given namespace.
25
- /// @param {Map} $tokens A map of aliases to canonical short names for tokens under the given
26
- /// namespace.
27
- /// @param {List} $namespace The namespace to use for the canonical tokens.
28
- /// @return A map of the token alias name to pairs of (namespace, token-name) representing the
29
- /// fully-qualified canonical name of the token.
30
- /// @example
31
- /// alias((alias1: canonical1, alias2: canonical2), (mat, my-comp))
32
- /// => (
33
- /// alias1: ((mat, my-comp), canonical1),
34
- /// alias2: ((mat, my-comp), canonical2)
35
- /// )
36
- @function alias($tokens, $namespace) {
37
- $result: ();
38
- @each $from, $to in $tokens {
39
- $result: map.set($result, $from, ($namespace, $to));
40
- }
41
- @return $result;
42
- }
43
-
44
- /// Gets the full set of customized tokens from a component configuration's customization map.
45
- /// @param {String} $component-id The id of the component whose customizations are being resolved.
46
- /// Used for error logging purposes.
47
- /// @param {Map} $customization-resolvers A map of resolvers that map customization keys to
48
- /// fully-qualified token names or functions to generate fully-qualified token names.
49
- /// @param {Map} $customizations A map of values for customization keys
50
- /// @return {Map} A map of fully-qualified token values
51
- /// @example
52
- /// resolve-customized-tokens('mat.checkbox',
53
- /// forward(my-color, my-size, (mat, my-comp)),
54
- /// (my-color: red, my-size: 100px)
55
- /// )
56
- /// => (
57
- /// (mat, my-comp): (
58
- /// my-color: red,
59
- /// my-size: 100px
60
- /// )
61
- /// )
62
- @function resolve-customized-tokens($component-id, $customization-resolvers, $customizations) {
63
- $result: ();
64
-
65
- @each $customization, $value in $customizations {
66
- $resolver: map.get($customization-resolvers, $customization);
67
- @if not $resolver {
68
- @error 'Unrecognized customization for #{$component-id}: #{$customization}';
69
- }
70
-
71
- $resolver-type: meta.type-of($resolver);
72
- @if $resolver-type == 'list' {
73
- // If the resolver is a list, it represents the token namespace and name.
74
- $key-and-value: list.append($resolver, $value);
75
- $result: map.deep-merge($result, map.set((), $key-and-value...));
76
- }
77
- @else if $resolver-type == 'function' {
78
- // If the resolver is a function, it should take a value and return a token map.
79
- $result: map.deep-merge($result, meta.call($resolver, $value));
80
- }
81
- @else {
82
- // Anything else is unexpected.
83
- @error 'Invalid customization resolver for `#{$customization}` on #{$component-id}';
84
- }
85
- }
86
-
87
- @return $result;
88
- }