@angular/material 21.0.0-next.9 → 21.0.0-rc.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 (202) hide show
  1. package/core/tokens/_classes.scss +1 -1
  2. package/core/tokens/m2/_md-sys-color.scss +17 -17
  3. package/fesm2022/_animation-chunk.mjs +10 -16
  4. package/fesm2022/_animation-chunk.mjs.map +1 -1
  5. package/fesm2022/_date-formats-chunk.mjs +68 -164
  6. package/fesm2022/_date-formats-chunk.mjs.map +1 -1
  7. package/fesm2022/_date-range-input-harness-chunk.mjs +284 -463
  8. package/fesm2022/_date-range-input-harness-chunk.mjs.map +1 -1
  9. package/fesm2022/_error-options-chunk.mjs +56 -19
  10. package/fesm2022/_error-options-chunk.mjs.map +1 -1
  11. package/fesm2022/_error-state-chunk.mjs +24 -31
  12. package/fesm2022/_error-state-chunk.mjs.map +1 -1
  13. package/fesm2022/_form-field-chunk.mjs +1224 -1017
  14. package/fesm2022/_form-field-chunk.mjs.map +1 -1
  15. package/fesm2022/_icon-button-chunk.mjs +243 -187
  16. package/fesm2022/_icon-button-chunk.mjs.map +1 -1
  17. package/fesm2022/_icon-registry-chunk.mjs +350 -575
  18. package/fesm2022/_icon-registry-chunk.mjs.map +1 -1
  19. package/fesm2022/_input-harness-chunk.mjs +56 -107
  20. package/fesm2022/_input-harness-chunk.mjs.map +1 -1
  21. package/fesm2022/_input-value-accessor-chunk.mjs +0 -6
  22. package/fesm2022/_input-value-accessor-chunk.mjs.map +1 -1
  23. package/fesm2022/_internal-form-field-chunk.mjs +59 -19
  24. package/fesm2022/_internal-form-field-chunk.mjs.map +1 -1
  25. package/fesm2022/_line-chunk.mjs +83 -43
  26. package/fesm2022/_line-chunk.mjs.map +1 -1
  27. package/fesm2022/_option-chunk.mjs +348 -311
  28. package/fesm2022/_option-chunk.mjs.map +1 -1
  29. package/fesm2022/_option-harness-chunk.mjs +23 -39
  30. package/fesm2022/_option-harness-chunk.mjs.map +1 -1
  31. package/fesm2022/_option-module-chunk.mjs +36 -10
  32. package/fesm2022/_option-module-chunk.mjs.map +1 -1
  33. package/fesm2022/_pseudo-checkbox-chunk.mjs +79 -44
  34. package/fesm2022/_pseudo-checkbox-chunk.mjs.map +1 -1
  35. package/fesm2022/_pseudo-checkbox-module-chunk.mjs +36 -10
  36. package/fesm2022/_pseudo-checkbox-module-chunk.mjs.map +1 -1
  37. package/fesm2022/_public-api-chunk.mjs +71 -134
  38. package/fesm2022/_public-api-chunk.mjs.map +1 -1
  39. package/fesm2022/_ripple-chunk.mjs +504 -600
  40. package/fesm2022/_ripple-chunk.mjs.map +1 -1
  41. package/fesm2022/_ripple-loader-chunk.mjs +120 -138
  42. package/fesm2022/_ripple-loader-chunk.mjs.map +1 -1
  43. package/fesm2022/_ripple-module-chunk.mjs +36 -10
  44. package/fesm2022/_ripple-module-chunk.mjs.map +1 -1
  45. package/fesm2022/_structural-styles-chunk.mjs +37 -10
  46. package/fesm2022/_structural-styles-chunk.mjs.map +1 -1
  47. package/fesm2022/_tooltip-chunk.mjs +810 -888
  48. package/fesm2022/_tooltip-chunk.mjs.map +1 -1
  49. package/fesm2022/autocomplete-testing.mjs +62 -86
  50. package/fesm2022/autocomplete-testing.mjs.map +1 -1
  51. package/fesm2022/autocomplete.mjs +965 -1126
  52. package/fesm2022/autocomplete.mjs.map +1 -1
  53. package/fesm2022/badge-testing.mjs +38 -54
  54. package/fesm2022/badge-testing.mjs.map +1 -1
  55. package/fesm2022/badge.mjs +321 -272
  56. package/fesm2022/badge.mjs.map +1 -1
  57. package/fesm2022/bottom-sheet-testing.mjs +10 -24
  58. package/fesm2022/bottom-sheet-testing.mjs.map +1 -1
  59. package/fesm2022/bottom-sheet.mjs +349 -344
  60. package/fesm2022/bottom-sheet.mjs.map +1 -1
  61. package/fesm2022/button-testing.mjs +60 -94
  62. package/fesm2022/button-testing.mjs.map +1 -1
  63. package/fesm2022/button-toggle-testing.mjs +76 -125
  64. package/fesm2022/button-toggle-testing.mjs.map +1 -1
  65. package/fesm2022/button-toggle.mjs +752 -662
  66. package/fesm2022/button-toggle.mjs.map +1 -1
  67. package/fesm2022/button.mjs +263 -158
  68. package/fesm2022/button.mjs.map +1 -1
  69. package/fesm2022/card-testing.mjs +19 -33
  70. package/fesm2022/card-testing.mjs.map +1 -1
  71. package/fesm2022/card.mjs +576 -272
  72. package/fesm2022/card.mjs.map +1 -1
  73. package/fesm2022/checkbox-testing.mjs +71 -123
  74. package/fesm2022/checkbox-testing.mjs.map +1 -1
  75. package/fesm2022/checkbox.mjs +515 -477
  76. package/fesm2022/checkbox.mjs.map +1 -1
  77. package/fesm2022/chips-testing.mjs +201 -344
  78. package/fesm2022/chips-testing.mjs.map +1 -1
  79. package/fesm2022/chips.mjs +2552 -2289
  80. package/fesm2022/chips.mjs.map +1 -1
  81. package/fesm2022/core-testing.mjs +14 -28
  82. package/fesm2022/core-testing.mjs.map +1 -1
  83. package/fesm2022/core.mjs +357 -328
  84. package/fesm2022/core.mjs.map +1 -1
  85. package/fesm2022/datepicker-testing.mjs +15 -25
  86. package/fesm2022/datepicker-testing.mjs.map +1 -1
  87. package/fesm2022/datepicker.mjs +4826 -4563
  88. package/fesm2022/datepicker.mjs.map +1 -1
  89. package/fesm2022/dialog-testing.mjs +93 -129
  90. package/fesm2022/dialog-testing.mjs.map +1 -1
  91. package/fesm2022/dialog.mjs +810 -829
  92. package/fesm2022/dialog.mjs.map +1 -1
  93. package/fesm2022/divider-testing.mjs +10 -11
  94. package/fesm2022/divider-testing.mjs.map +1 -1
  95. package/fesm2022/divider.mjs +119 -43
  96. package/fesm2022/divider.mjs.map +1 -1
  97. package/fesm2022/expansion-testing.mjs +74 -130
  98. package/fesm2022/expansion-testing.mjs.map +1 -1
  99. package/fesm2022/expansion.mjs +703 -515
  100. package/fesm2022/expansion.mjs.map +1 -1
  101. package/fesm2022/form-field-testing-control.mjs +16 -33
  102. package/fesm2022/form-field-testing-control.mjs.map +1 -1
  103. package/fesm2022/form-field-testing.mjs +118 -179
  104. package/fesm2022/form-field-testing.mjs.map +1 -1
  105. package/fesm2022/form-field.mjs +36 -10
  106. package/fesm2022/form-field.mjs.map +1 -1
  107. package/fesm2022/grid-list-testing.mjs +65 -113
  108. package/fesm2022/grid-list-testing.mjs.map +1 -1
  109. package/fesm2022/grid-list.mjs +559 -494
  110. package/fesm2022/grid-list.mjs.map +1 -1
  111. package/fesm2022/icon-testing.mjs +148 -127
  112. package/fesm2022/icon-testing.mjs.map +1 -1
  113. package/fesm2022/icon.mjs +325 -351
  114. package/fesm2022/icon.mjs.map +1 -1
  115. package/fesm2022/input-testing.mjs +59 -99
  116. package/fesm2022/input-testing.mjs.map +1 -1
  117. package/fesm2022/input.mjs +457 -520
  118. package/fesm2022/input.mjs.map +1 -1
  119. package/fesm2022/list-testing.mjs +251 -434
  120. package/fesm2022/list-testing.mjs.map +1 -1
  121. package/fesm2022/list.mjs +1522 -1204
  122. package/fesm2022/list.mjs.map +1 -1
  123. package/fesm2022/material.mjs +0 -5
  124. package/fesm2022/material.mjs.map +1 -1
  125. package/fesm2022/menu-testing.mjs +159 -228
  126. package/fesm2022/menu-testing.mjs.map +1 -1
  127. package/fesm2022/menu.mjs +1338 -1343
  128. package/fesm2022/menu.mjs.map +1 -1
  129. package/fesm2022/paginator-testing.mjs +55 -79
  130. package/fesm2022/paginator-testing.mjs.map +1 -1
  131. package/fesm2022/paginator.mjs +381 -309
  132. package/fesm2022/paginator.mjs.map +1 -1
  133. package/fesm2022/progress-bar-testing.mjs +12 -21
  134. package/fesm2022/progress-bar-testing.mjs.map +1 -1
  135. package/fesm2022/progress-bar.mjs +224 -169
  136. package/fesm2022/progress-bar.mjs.map +1 -1
  137. package/fesm2022/progress-spinner-testing.mjs +13 -23
  138. package/fesm2022/progress-spinner-testing.mjs.map +1 -1
  139. package/fesm2022/progress-spinner.mjs +235 -160
  140. package/fesm2022/progress-spinner.mjs.map +1 -1
  141. package/fesm2022/radio-testing.mjs +133 -208
  142. package/fesm2022/radio-testing.mjs.map +1 -1
  143. package/fesm2022/radio.mjs +712 -679
  144. package/fesm2022/radio.mjs.map +1 -1
  145. package/fesm2022/select-testing.mjs +83 -117
  146. package/fesm2022/select-testing.mjs.map +1 -1
  147. package/fesm2022/select.mjs +1116 -1246
  148. package/fesm2022/select.mjs.map +1 -1
  149. package/fesm2022/sidenav-testing.mjs +54 -120
  150. package/fesm2022/sidenav-testing.mjs.map +1 -1
  151. package/fesm2022/sidenav.mjs +1078 -995
  152. package/fesm2022/sidenav.mjs.map +1 -1
  153. package/fesm2022/slide-toggle-testing.mjs +57 -92
  154. package/fesm2022/slide-toggle-testing.mjs.map +1 -1
  155. package/fesm2022/slide-toggle.mjs +369 -279
  156. package/fesm2022/slide-toggle.mjs.map +1 -1
  157. package/fesm2022/slider-testing.mjs +90 -138
  158. package/fesm2022/slider-testing.mjs.map +1 -1
  159. package/fesm2022/slider.mjs +1651 -1716
  160. package/fesm2022/slider.mjs.map +1 -1
  161. package/fesm2022/snack-bar-testing.mjs +40 -87
  162. package/fesm2022/snack-bar-testing.mjs.map +1 -1
  163. package/fesm2022/snack-bar.mjs +763 -714
  164. package/fesm2022/snack-bar.mjs.map +1 -1
  165. package/fesm2022/sort-testing.mjs +45 -66
  166. package/fesm2022/sort-testing.mjs.map +1 -1
  167. package/fesm2022/sort.mjs +419 -344
  168. package/fesm2022/sort.mjs.map +1 -1
  169. package/fesm2022/stepper-testing.mjs +78 -154
  170. package/fesm2022/stepper-testing.mjs.map +1 -1
  171. package/fesm2022/stepper.mjs +790 -498
  172. package/fesm2022/stepper.mjs.map +1 -1
  173. package/fesm2022/table-testing.mjs +120 -213
  174. package/fesm2022/table-testing.mjs.map +1 -1
  175. package/fesm2022/table.mjs +1026 -684
  176. package/fesm2022/table.mjs.map +1 -1
  177. package/fesm2022/tabs-testing.mjs +125 -197
  178. package/fesm2022/tabs-testing.mjs.map +1 -1
  179. package/fesm2022/tabs.mjs +2351 -2028
  180. package/fesm2022/tabs.mjs.map +1 -1
  181. package/fesm2022/timepicker-testing.mjs +113 -172
  182. package/fesm2022/timepicker-testing.mjs.map +1 -1
  183. package/fesm2022/timepicker.mjs +1019 -826
  184. package/fesm2022/timepicker.mjs.map +1 -1
  185. package/fesm2022/toolbar-testing.mjs +16 -27
  186. package/fesm2022/toolbar-testing.mjs.map +1 -1
  187. package/fesm2022/toolbar.mjs +163 -78
  188. package/fesm2022/toolbar.mjs.map +1 -1
  189. package/fesm2022/tooltip-testing.mjs +41 -52
  190. package/fesm2022/tooltip-testing.mjs.map +1 -1
  191. package/fesm2022/tooltip.mjs +36 -10
  192. package/fesm2022/tooltip.mjs.map +1 -1
  193. package/fesm2022/tree-testing.mjs +86 -162
  194. package/fesm2022/tree-testing.mjs.map +1 -1
  195. package/fesm2022/tree.mjs +638 -466
  196. package/fesm2022/tree.mjs.map +1 -1
  197. package/package.json +2 -2
  198. package/schematics/ng-add/index.js +1 -1
  199. package/types/expansion.d.ts +4 -2
  200. package/types/menu-testing.d.ts +2 -0
  201. package/types/select.d.ts +1 -1
  202. package/types/timepicker.d.ts +1 -0
@@ -5,606 +5,381 @@ import * as i2 from '@angular/platform-browser';
5
5
  import { of, throwError, forkJoin } from 'rxjs';
6
6
  import { tap, map, catchError, finalize, share } from 'rxjs/operators';
7
7
 
8
- /**
9
- * The Trusted Types policy, or null if Trusted Types are not
10
- * enabled/supported, or undefined if the policy has not been created yet.
11
- */
12
8
  let policy;
13
- /**
14
- * Returns the Trusted Types policy, or null if Trusted Types are not
15
- * enabled/supported. The first call to this function will create the policy.
16
- */
17
9
  function getPolicy() {
18
- if (policy === undefined) {
19
- policy = null;
20
- if (typeof window !== 'undefined') {
21
- const ttWindow = window;
22
- if (ttWindow.trustedTypes !== undefined) {
23
- policy = ttWindow.trustedTypes.createPolicy('angular#components', {
24
- createHTML: (s) => s,
25
- });
26
- }
27
- }
10
+ if (policy === undefined) {
11
+ policy = null;
12
+ if (typeof window !== 'undefined') {
13
+ const ttWindow = window;
14
+ if (ttWindow.trustedTypes !== undefined) {
15
+ policy = ttWindow.trustedTypes.createPolicy('angular#components', {
16
+ createHTML: s => s
17
+ });
18
+ }
28
19
  }
29
- return policy;
20
+ }
21
+ return policy;
30
22
  }
31
- /**
32
- * Unsafely promote a string to a TrustedHTML, falling back to strings when
33
- * Trusted Types are not available.
34
- * @security This is a security-sensitive function; any use of this function
35
- * must go through security review. In particular, it must be assured that the
36
- * provided string will never cause an XSS vulnerability if used in a context
37
- * that will be interpreted as HTML by a browser, e.g. when assigning to
38
- * element.innerHTML.
39
- */
40
23
  function trustedHTMLFromString(html) {
41
- return getPolicy()?.createHTML(html) || html;
24
+ return getPolicy()?.createHTML(html) || html;
42
25
  }
43
26
 
44
- /**
45
- * Returns an exception to be thrown in the case when attempting to
46
- * load an icon with a name that cannot be found.
47
- * @docs-private
48
- */
49
27
  function getMatIconNameNotFoundError(iconName) {
50
- return Error(`Unable to find icon with the name "${iconName}"`);
28
+ return Error(`Unable to find icon with the name "${iconName}"`);
51
29
  }
52
- /**
53
- * Returns an exception to be thrown when the consumer attempts to use
54
- * `<mat-icon>` without including @angular/common/http.
55
- * @docs-private
56
- */
57
30
  function getMatIconNoHttpProviderError() {
58
- return Error('Could not find HttpClient for use with Angular Material icons. ' +
59
- 'Please add provideHttpClient() to your providers.');
31
+ return Error('Could not find HttpClient for use with Angular Material icons. ' + 'Please add provideHttpClient() to your providers.');
60
32
  }
61
- /**
62
- * Returns an exception to be thrown when a URL couldn't be sanitized.
63
- * @param url URL that was attempted to be sanitized.
64
- * @docs-private
65
- */
66
33
  function getMatIconFailedToSanitizeUrlError(url) {
67
- return Error(`The URL provided to MatIconRegistry was not trusted as a resource URL ` +
68
- `via Angular's DomSanitizer. Attempted URL was "${url}".`);
34
+ return Error(`The URL provided to MatIconRegistry was not trusted as a resource URL ` + `via Angular's DomSanitizer. Attempted URL was "${url}".`);
69
35
  }
70
- /**
71
- * Returns an exception to be thrown when a HTML string couldn't be sanitized.
72
- * @param literal HTML that was attempted to be sanitized.
73
- * @docs-private
74
- */
75
36
  function getMatIconFailedToSanitizeLiteralError(literal) {
76
- return Error(`The literal provided to MatIconRegistry was not trusted as safe HTML by ` +
77
- `Angular's DomSanitizer. Attempted literal was "${literal}".`);
37
+ return Error(`The literal provided to MatIconRegistry was not trusted as safe HTML by ` + `Angular's DomSanitizer. Attempted literal was "${literal}".`);
78
38
  }
79
- /**
80
- * Configuration for an icon, including the URL and possibly the cached SVG element.
81
- * @docs-private
82
- */
83
39
  class SvgIconConfig {
84
- url;
85
- svgText;
86
- options;
87
- svgElement;
88
- constructor(url, svgText, options) {
89
- this.url = url;
90
- this.svgText = svgText;
91
- this.options = options;
92
- }
40
+ url;
41
+ svgText;
42
+ options;
43
+ svgElement;
44
+ constructor(url, svgText, options) {
45
+ this.url = url;
46
+ this.svgText = svgText;
47
+ this.options = options;
48
+ }
93
49
  }
94
- /**
95
- * Service to register and display icons used by the `<mat-icon>` component.
96
- * - Registers icon URLs by namespace and name.
97
- * - Registers icon set URLs by namespace.
98
- * - Registers aliases for CSS classes, for use with icon fonts.
99
- * - Loads icons from URLs and extracts individual icons from icon sets.
100
- */
101
50
  class MatIconRegistry {
102
- _httpClient;
103
- _sanitizer;
104
- _errorHandler;
105
- _document;
106
- /**
107
- * URLs and cached SVG elements for individual icons. Keys are of the format "[namespace]:[icon]".
108
- */
109
- _svgIconConfigs = new Map();
110
- /**
111
- * SvgIconConfig objects and cached SVG elements for icon sets, keyed by namespace.
112
- * Multiple icon sets can be registered under the same namespace.
113
- */
114
- _iconSetConfigs = new Map();
115
- /** Cache for icons loaded by direct URLs. */
116
- _cachedIconsByUrl = new Map();
117
- /** In-progress icon fetches. Used to coalesce multiple requests to the same URL. */
118
- _inProgressUrlFetches = new Map();
119
- /** Map from font identifiers to their CSS class names. Used for icon fonts. */
120
- _fontCssClassesByAlias = new Map();
121
- /** Registered icon resolver functions. */
122
- _resolvers = [];
123
- /**
124
- * The CSS classes to apply when an `<mat-icon>` component has no icon name, url, or font
125
- * specified. The default 'material-icons' value assumes that the material icon font has been
126
- * loaded as described at https://google.github.io/material-design-icons/#icon-font-for-the-web
127
- */
128
- _defaultFontSetClass = ['material-icons', 'mat-ligature-font'];
129
- constructor(_httpClient, _sanitizer, document, _errorHandler) {
130
- this._httpClient = _httpClient;
131
- this._sanitizer = _sanitizer;
132
- this._errorHandler = _errorHandler;
133
- this._document = document;
134
- }
135
- /**
136
- * Registers an icon by URL in the default namespace.
137
- * @param iconName Name under which the icon should be registered.
138
- * @param url
139
- */
140
- addSvgIcon(iconName, url, options) {
141
- return this.addSvgIconInNamespace('', iconName, url, options);
142
- }
143
- /**
144
- * Registers an icon using an HTML string in the default namespace.
145
- * @param iconName Name under which the icon should be registered.
146
- * @param literal SVG source of the icon.
147
- */
148
- addSvgIconLiteral(iconName, literal, options) {
149
- return this.addSvgIconLiteralInNamespace('', iconName, literal, options);
150
- }
151
- /**
152
- * Registers an icon by URL in the specified namespace.
153
- * @param namespace Namespace in which the icon should be registered.
154
- * @param iconName Name under which the icon should be registered.
155
- * @param url
156
- */
157
- addSvgIconInNamespace(namespace, iconName, url, options) {
158
- return this._addSvgIconConfig(namespace, iconName, new SvgIconConfig(url, null, options));
159
- }
160
- /**
161
- * Registers an icon resolver function with the registry. The function will be invoked with the
162
- * name and namespace of an icon when the registry tries to resolve the URL from which to fetch
163
- * the icon. The resolver is expected to return a `SafeResourceUrl` that points to the icon,
164
- * an object with the icon URL and icon options, or `null` if the icon is not supported. Resolvers
165
- * will be invoked in the order in which they have been registered.
166
- * @param resolver Resolver function to be registered.
167
- */
168
- addSvgIconResolver(resolver) {
169
- this._resolvers.push(resolver);
170
- return this;
171
- }
172
- /**
173
- * Registers an icon using an HTML string in the specified namespace.
174
- * @param namespace Namespace in which the icon should be registered.
175
- * @param iconName Name under which the icon should be registered.
176
- * @param literal SVG source of the icon.
177
- */
178
- addSvgIconLiteralInNamespace(namespace, iconName, literal, options) {
179
- const cleanLiteral = this._sanitizer.sanitize(SecurityContext.HTML, literal);
180
- // TODO: add an ngDevMode check
181
- if (!cleanLiteral) {
182
- throw getMatIconFailedToSanitizeLiteralError(literal);
51
+ _httpClient;
52
+ _sanitizer;
53
+ _errorHandler;
54
+ _document;
55
+ _svgIconConfigs = new Map();
56
+ _iconSetConfigs = new Map();
57
+ _cachedIconsByUrl = new Map();
58
+ _inProgressUrlFetches = new Map();
59
+ _fontCssClassesByAlias = new Map();
60
+ _resolvers = [];
61
+ _defaultFontSetClass = ['material-icons', 'mat-ligature-font'];
62
+ constructor(_httpClient, _sanitizer, document, _errorHandler) {
63
+ this._httpClient = _httpClient;
64
+ this._sanitizer = _sanitizer;
65
+ this._errorHandler = _errorHandler;
66
+ this._document = document;
67
+ }
68
+ addSvgIcon(iconName, url, options) {
69
+ return this.addSvgIconInNamespace('', iconName, url, options);
70
+ }
71
+ addSvgIconLiteral(iconName, literal, options) {
72
+ return this.addSvgIconLiteralInNamespace('', iconName, literal, options);
73
+ }
74
+ addSvgIconInNamespace(namespace, iconName, url, options) {
75
+ return this._addSvgIconConfig(namespace, iconName, new SvgIconConfig(url, null, options));
76
+ }
77
+ addSvgIconResolver(resolver) {
78
+ this._resolvers.push(resolver);
79
+ return this;
80
+ }
81
+ addSvgIconLiteralInNamespace(namespace, iconName, literal, options) {
82
+ const cleanLiteral = this._sanitizer.sanitize(SecurityContext.HTML, literal);
83
+ if (!cleanLiteral) {
84
+ throw getMatIconFailedToSanitizeLiteralError(literal);
85
+ }
86
+ const trustedLiteral = trustedHTMLFromString(cleanLiteral);
87
+ return this._addSvgIconConfig(namespace, iconName, new SvgIconConfig('', trustedLiteral, options));
88
+ }
89
+ addSvgIconSet(url, options) {
90
+ return this.addSvgIconSetInNamespace('', url, options);
91
+ }
92
+ addSvgIconSetLiteral(literal, options) {
93
+ return this.addSvgIconSetLiteralInNamespace('', literal, options);
94
+ }
95
+ addSvgIconSetInNamespace(namespace, url, options) {
96
+ return this._addSvgIconSetConfig(namespace, new SvgIconConfig(url, null, options));
97
+ }
98
+ addSvgIconSetLiteralInNamespace(namespace, literal, options) {
99
+ const cleanLiteral = this._sanitizer.sanitize(SecurityContext.HTML, literal);
100
+ if (!cleanLiteral) {
101
+ throw getMatIconFailedToSanitizeLiteralError(literal);
102
+ }
103
+ const trustedLiteral = trustedHTMLFromString(cleanLiteral);
104
+ return this._addSvgIconSetConfig(namespace, new SvgIconConfig('', trustedLiteral, options));
105
+ }
106
+ registerFontClassAlias(alias, classNames = alias) {
107
+ this._fontCssClassesByAlias.set(alias, classNames);
108
+ return this;
109
+ }
110
+ classNameForFontAlias(alias) {
111
+ return this._fontCssClassesByAlias.get(alias) || alias;
112
+ }
113
+ setDefaultFontSetClass(...classNames) {
114
+ this._defaultFontSetClass = classNames;
115
+ return this;
116
+ }
117
+ getDefaultFontSetClass() {
118
+ return this._defaultFontSetClass;
119
+ }
120
+ getSvgIconFromUrl(safeUrl) {
121
+ const url = this._sanitizer.sanitize(SecurityContext.RESOURCE_URL, safeUrl);
122
+ if (!url) {
123
+ throw getMatIconFailedToSanitizeUrlError(safeUrl);
124
+ }
125
+ const cachedIcon = this._cachedIconsByUrl.get(url);
126
+ if (cachedIcon) {
127
+ return of(cloneSvg(cachedIcon));
128
+ }
129
+ return this._loadSvgIconFromConfig(new SvgIconConfig(safeUrl, null)).pipe(tap(svg => this._cachedIconsByUrl.set(url, svg)), map(svg => cloneSvg(svg)));
130
+ }
131
+ getNamedSvgIcon(name, namespace = '') {
132
+ const key = iconKey(namespace, name);
133
+ let config = this._svgIconConfigs.get(key);
134
+ if (config) {
135
+ return this._getSvgFromConfig(config);
136
+ }
137
+ config = this._getIconConfigFromResolvers(namespace, name);
138
+ if (config) {
139
+ this._svgIconConfigs.set(key, config);
140
+ return this._getSvgFromConfig(config);
141
+ }
142
+ const iconSetConfigs = this._iconSetConfigs.get(namespace);
143
+ if (iconSetConfigs) {
144
+ return this._getSvgFromIconSetConfigs(name, iconSetConfigs);
145
+ }
146
+ return throwError(getMatIconNameNotFoundError(key));
147
+ }
148
+ ngOnDestroy() {
149
+ this._resolvers = [];
150
+ this._svgIconConfigs.clear();
151
+ this._iconSetConfigs.clear();
152
+ this._cachedIconsByUrl.clear();
153
+ }
154
+ _getSvgFromConfig(config) {
155
+ if (config.svgText) {
156
+ return of(cloneSvg(this._svgElementFromConfig(config)));
157
+ } else {
158
+ return this._loadSvgIconFromConfig(config).pipe(map(svg => cloneSvg(svg)));
159
+ }
160
+ }
161
+ _getSvgFromIconSetConfigs(name, iconSetConfigs) {
162
+ const namedIcon = this._extractIconWithNameFromAnySet(name, iconSetConfigs);
163
+ if (namedIcon) {
164
+ return of(namedIcon);
165
+ }
166
+ const iconSetFetchRequests = iconSetConfigs.filter(iconSetConfig => !iconSetConfig.svgText).map(iconSetConfig => {
167
+ return this._loadSvgIconSetFromConfig(iconSetConfig).pipe(catchError(err => {
168
+ const url = this._sanitizer.sanitize(SecurityContext.RESOURCE_URL, iconSetConfig.url);
169
+ const errorMessage = `Loading icon set URL: ${url} failed: ${err.message}`;
170
+ this._errorHandler.handleError(new Error(errorMessage));
171
+ return of(null);
172
+ }));
173
+ });
174
+ return forkJoin(iconSetFetchRequests).pipe(map(() => {
175
+ const foundIcon = this._extractIconWithNameFromAnySet(name, iconSetConfigs);
176
+ if (!foundIcon) {
177
+ throw getMatIconNameNotFoundError(name);
178
+ }
179
+ return foundIcon;
180
+ }));
181
+ }
182
+ _extractIconWithNameFromAnySet(iconName, iconSetConfigs) {
183
+ for (let i = iconSetConfigs.length - 1; i >= 0; i--) {
184
+ const config = iconSetConfigs[i];
185
+ if (config.svgText && config.svgText.toString().indexOf(iconName) > -1) {
186
+ const svg = this._svgElementFromConfig(config);
187
+ const foundIcon = this._extractSvgIconFromSet(svg, iconName, config.options);
188
+ if (foundIcon) {
189
+ return foundIcon;
183
190
  }
184
- // Security: The literal is passed in as SafeHtml, and is thus trusted.
185
- const trustedLiteral = trustedHTMLFromString(cleanLiteral);
186
- return this._addSvgIconConfig(namespace, iconName, new SvgIconConfig('', trustedLiteral, options));
187
- }
188
- /**
189
- * Registers an icon set by URL in the default namespace.
190
- * @param url
191
- */
192
- addSvgIconSet(url, options) {
193
- return this.addSvgIconSetInNamespace('', url, options);
194
- }
195
- /**
196
- * Registers an icon set using an HTML string in the default namespace.
197
- * @param literal SVG source of the icon set.
198
- */
199
- addSvgIconSetLiteral(literal, options) {
200
- return this.addSvgIconSetLiteralInNamespace('', literal, options);
201
- }
202
- /**
203
- * Registers an icon set by URL in the specified namespace.
204
- * @param namespace Namespace in which to register the icon set.
205
- * @param url
206
- */
207
- addSvgIconSetInNamespace(namespace, url, options) {
208
- return this._addSvgIconSetConfig(namespace, new SvgIconConfig(url, null, options));
209
- }
210
- /**
211
- * Registers an icon set using an HTML string in the specified namespace.
212
- * @param namespace Namespace in which to register the icon set.
213
- * @param literal SVG source of the icon set.
214
- */
215
- addSvgIconSetLiteralInNamespace(namespace, literal, options) {
216
- const cleanLiteral = this._sanitizer.sanitize(SecurityContext.HTML, literal);
217
- if (!cleanLiteral) {
218
- throw getMatIconFailedToSanitizeLiteralError(literal);
219
- }
220
- // Security: The literal is passed in as SafeHtml, and is thus trusted.
221
- const trustedLiteral = trustedHTMLFromString(cleanLiteral);
222
- return this._addSvgIconSetConfig(namespace, new SvgIconConfig('', trustedLiteral, options));
223
- }
224
- /**
225
- * Defines an alias for CSS class names to be used for icon fonts. Creating an matIcon
226
- * component with the alias as the fontSet input will cause the class name to be applied
227
- * to the `<mat-icon>` element.
228
- *
229
- * If the registered font is a ligature font, then don't forget to also include the special
230
- * class `mat-ligature-font` to allow the usage via attribute. So register like this:
231
- *
232
- * ```ts
233
- * iconRegistry.registerFontClassAlias('f1', 'font1 mat-ligature-font');
234
- * ```
235
- *
236
- * And use like this:
237
- *
238
- * ```html
239
- * <mat-icon fontSet="f1" fontIcon="home"></mat-icon>
240
- * ```
241
- *
242
- * @param alias Alias for the font.
243
- * @param classNames Class names override to be used instead of the alias.
244
- */
245
- registerFontClassAlias(alias, classNames = alias) {
246
- this._fontCssClassesByAlias.set(alias, classNames);
247
- return this;
248
- }
249
- /**
250
- * Returns the CSS class name associated with the alias by a previous call to
251
- * registerFontClassAlias. If no CSS class has been associated, returns the alias unmodified.
252
- */
253
- classNameForFontAlias(alias) {
254
- return this._fontCssClassesByAlias.get(alias) || alias;
255
- }
256
- /**
257
- * Sets the CSS classes to be used for icon fonts when an `<mat-icon>` component does not
258
- * have a fontSet input value, and is not loading an icon by name or URL.
259
- */
260
- setDefaultFontSetClass(...classNames) {
261
- this._defaultFontSetClass = classNames;
262
- return this;
263
- }
264
- /**
265
- * Returns the CSS classes to be used for icon fonts when an `<mat-icon>` component does not
266
- * have a fontSet input value, and is not loading an icon by name or URL.
267
- */
268
- getDefaultFontSetClass() {
269
- return this._defaultFontSetClass;
270
- }
271
- /**
272
- * Returns an Observable that produces the icon (as an `<svg>` DOM element) from the given URL.
273
- * The response from the URL may be cached so this will not always cause an HTTP request, but
274
- * the produced element will always be a new copy of the originally fetched icon. (That is,
275
- * it will not contain any modifications made to elements previously returned).
276
- *
277
- * @param safeUrl URL from which to fetch the SVG icon.
278
- */
279
- getSvgIconFromUrl(safeUrl) {
280
- const url = this._sanitizer.sanitize(SecurityContext.RESOURCE_URL, safeUrl);
281
- if (!url) {
282
- throw getMatIconFailedToSanitizeUrlError(safeUrl);
283
- }
284
- const cachedIcon = this._cachedIconsByUrl.get(url);
285
- if (cachedIcon) {
286
- return of(cloneSvg(cachedIcon));
287
- }
288
- return this._loadSvgIconFromConfig(new SvgIconConfig(safeUrl, null)).pipe(tap(svg => this._cachedIconsByUrl.set(url, svg)), map(svg => cloneSvg(svg)));
289
- }
290
- /**
291
- * Returns an Observable that produces the icon (as an `<svg>` DOM element) with the given name
292
- * and namespace. The icon must have been previously registered with addIcon or addIconSet;
293
- * if not, the Observable will throw an error.
294
- *
295
- * @param name Name of the icon to be retrieved.
296
- * @param namespace Namespace in which to look for the icon.
297
- */
298
- getNamedSvgIcon(name, namespace = '') {
299
- const key = iconKey(namespace, name);
300
- let config = this._svgIconConfigs.get(key);
301
- // Return (copy of) cached icon if possible.
302
- if (config) {
303
- return this._getSvgFromConfig(config);
304
- }
305
- // Otherwise try to resolve the config from one of the resolver functions.
306
- config = this._getIconConfigFromResolvers(namespace, name);
307
- if (config) {
308
- this._svgIconConfigs.set(key, config);
309
- return this._getSvgFromConfig(config);
310
- }
311
- // See if we have any icon sets registered for the namespace.
312
- const iconSetConfigs = this._iconSetConfigs.get(namespace);
313
- if (iconSetConfigs) {
314
- return this._getSvgFromIconSetConfigs(name, iconSetConfigs);
315
- }
316
- return throwError(getMatIconNameNotFoundError(key));
317
- }
318
- ngOnDestroy() {
319
- this._resolvers = [];
320
- this._svgIconConfigs.clear();
321
- this._iconSetConfigs.clear();
322
- this._cachedIconsByUrl.clear();
323
- }
324
- /**
325
- * Returns the cached icon for a SvgIconConfig if available, or fetches it from its URL if not.
326
- */
327
- _getSvgFromConfig(config) {
328
- if (config.svgText) {
329
- // We already have the SVG element for this icon, return a copy.
330
- return of(cloneSvg(this._svgElementFromConfig(config)));
331
- }
332
- else {
333
- // Fetch the icon from the config's URL, cache it, and return a copy.
334
- return this._loadSvgIconFromConfig(config).pipe(map(svg => cloneSvg(svg)));
335
- }
336
- }
337
- /**
338
- * Attempts to find an icon with the specified name in any of the SVG icon sets.
339
- * First searches the available cached icons for a nested element with a matching name, and
340
- * if found copies the element to a new `<svg>` element. If not found, fetches all icon sets
341
- * that have not been cached, and searches again after all fetches are completed.
342
- * The returned Observable produces the SVG element if possible, and throws
343
- * an error if no icon with the specified name can be found.
344
- */
345
- _getSvgFromIconSetConfigs(name, iconSetConfigs) {
346
- // For all the icon set SVG elements we've fetched, see if any contain an icon with the
347
- // requested name.
348
- const namedIcon = this._extractIconWithNameFromAnySet(name, iconSetConfigs);
349
- if (namedIcon) {
350
- // We could cache namedIcon in _svgIconConfigs, but since we have to make a copy every
351
- // time anyway, there's probably not much advantage compared to just always extracting
352
- // it from the icon set.
353
- return of(namedIcon);
354
- }
355
- // Not found in any cached icon sets. If there are icon sets with URLs that we haven't
356
- // fetched, fetch them now and look for iconName in the results.
357
- const iconSetFetchRequests = iconSetConfigs
358
- .filter(iconSetConfig => !iconSetConfig.svgText)
359
- .map(iconSetConfig => {
360
- return this._loadSvgIconSetFromConfig(iconSetConfig).pipe(catchError((err) => {
361
- const url = this._sanitizer.sanitize(SecurityContext.RESOURCE_URL, iconSetConfig.url);
362
- // Swallow errors fetching individual URLs so the
363
- // combined Observable won't necessarily fail.
364
- const errorMessage = `Loading icon set URL: ${url} failed: ${err.message}`;
365
- this._errorHandler.handleError(new Error(errorMessage));
366
- return of(null);
367
- }));
368
- });
369
- // Fetch all the icon set URLs. When the requests complete, every IconSet should have a
370
- // cached SVG element (unless the request failed), and we can check again for the icon.
371
- return forkJoin(iconSetFetchRequests).pipe(map(() => {
372
- const foundIcon = this._extractIconWithNameFromAnySet(name, iconSetConfigs);
373
- // TODO: add an ngDevMode check
374
- if (!foundIcon) {
375
- throw getMatIconNameNotFoundError(name);
376
- }
377
- return foundIcon;
378
- }));
379
- }
380
- /**
381
- * Searches the cached SVG elements for the given icon sets for a nested icon element whose "id"
382
- * tag matches the specified name. If found, copies the nested element to a new SVG element and
383
- * returns it. Returns null if no matching element is found.
384
- */
385
- _extractIconWithNameFromAnySet(iconName, iconSetConfigs) {
386
- // Iterate backwards, so icon sets added later have precedence.
387
- for (let i = iconSetConfigs.length - 1; i >= 0; i--) {
388
- const config = iconSetConfigs[i];
389
- // Parsing the icon set's text into an SVG element can be expensive. We can avoid some of
390
- // the parsing by doing a quick check using `indexOf` to see if there's any chance for the
391
- // icon to be in the set. This won't be 100% accurate, but it should help us avoid at least
392
- // some of the parsing.
393
- if (config.svgText && config.svgText.toString().indexOf(iconName) > -1) {
394
- const svg = this._svgElementFromConfig(config);
395
- const foundIcon = this._extractSvgIconFromSet(svg, iconName, config.options);
396
- if (foundIcon) {
397
- return foundIcon;
398
- }
399
- }
400
- }
401
- return null;
402
- }
403
- /**
404
- * Loads the content of the icon URL specified in the SvgIconConfig and creates an SVG element
405
- * from it.
406
- */
407
- _loadSvgIconFromConfig(config) {
408
- return this._fetchIcon(config).pipe(tap(svgText => (config.svgText = svgText)), map(() => this._svgElementFromConfig(config)));
409
- }
410
- /**
411
- * Loads the content of the icon set URL specified in the
412
- * SvgIconConfig and attaches it to the config.
413
- */
414
- _loadSvgIconSetFromConfig(config) {
415
- if (config.svgText) {
416
- return of(null);
417
- }
418
- return this._fetchIcon(config).pipe(tap(svgText => (config.svgText = svgText)));
419
- }
420
- /**
421
- * Searches the cached element of the given SvgIconConfig for a nested icon element whose "id"
422
- * tag matches the specified name. If found, copies the nested element to a new SVG element and
423
- * returns it. Returns null if no matching element is found.
424
- */
425
- _extractSvgIconFromSet(iconSet, iconName, options) {
426
- // Use the `id="iconName"` syntax in order to escape special
427
- // characters in the ID (versus using the #iconName syntax).
428
- const iconSource = iconSet.querySelector(`[id="${iconName}"]`);
429
- if (!iconSource) {
430
- return null;
431
- }
432
- // Clone the element and remove the ID to prevent multiple elements from being added
433
- // to the page with the same ID.
434
- const iconElement = iconSource.cloneNode(true);
435
- iconElement.removeAttribute('id');
436
- // If the icon node is itself an <svg> node, clone and return it directly. If not, set it as
437
- // the content of a new <svg> node.
438
- if (iconElement.nodeName.toLowerCase() === 'svg') {
439
- return this._setSvgAttributes(iconElement, options);
440
- }
441
- // If the node is a <symbol>, it won't be rendered so we have to convert it into <svg>. Note
442
- // that the same could be achieved by referring to it via <use href="#id">, however the <use>
443
- // tag is problematic on Firefox, because it needs to include the current page path.
444
- if (iconElement.nodeName.toLowerCase() === 'symbol') {
445
- return this._setSvgAttributes(this._toSvgElement(iconElement), options);
446
- }
447
- // createElement('SVG') doesn't work as expected; the DOM ends up with
448
- // the correct nodes, but the SVG content doesn't render. Instead we
449
- // have to create an empty SVG node using innerHTML and append its content.
450
- // Elements created using DOMParser.parseFromString have the same problem.
451
- // http://stackoverflow.com/questions/23003278/svg-innerhtml-in-firefox-can-not-display
452
- const svg = this._svgElementFromString(trustedHTMLFromString('<svg></svg>'));
453
- // Clone the node so we don't remove it from the parent icon set element.
454
- svg.appendChild(iconElement);
455
- return this._setSvgAttributes(svg, options);
456
- }
457
- /**
458
- * Creates a DOM element from the given SVG string.
459
- */
460
- _svgElementFromString(str) {
461
- const div = this._document.createElement('DIV');
462
- div.innerHTML = str;
463
- const svg = div.querySelector('svg');
464
- // TODO: add an ngDevMode check
465
- if (!svg) {
466
- throw Error('<svg> tag not found');
467
- }
468
- return svg;
469
- }
470
- /**
471
- * Converts an element into an SVG node by cloning all of its children.
472
- */
473
- _toSvgElement(element) {
474
- const svg = this._svgElementFromString(trustedHTMLFromString('<svg></svg>'));
475
- const attributes = element.attributes;
476
- // Copy over all the attributes from the `symbol` to the new SVG, except the id.
477
- for (let i = 0; i < attributes.length; i++) {
478
- const { name, value } = attributes[i];
479
- if (name !== 'id') {
480
- svg.setAttribute(name, value);
481
- }
482
- }
483
- for (let i = 0; i < element.childNodes.length; i++) {
484
- if (element.childNodes[i].nodeType === this._document.ELEMENT_NODE) {
485
- svg.appendChild(element.childNodes[i].cloneNode(true));
486
- }
487
- }
488
- return svg;
489
- }
490
- /**
491
- * Sets the default attributes for an SVG element to be used as an icon.
492
- */
493
- _setSvgAttributes(svg, options) {
494
- svg.setAttribute('fit', '');
495
- svg.setAttribute('height', '100%');
496
- svg.setAttribute('width', '100%');
497
- svg.setAttribute('preserveAspectRatio', 'xMidYMid meet');
498
- svg.setAttribute('focusable', 'false'); // Disable IE11 default behavior to make SVGs focusable.
499
- if (options && options.viewBox) {
500
- svg.setAttribute('viewBox', options.viewBox);
501
- }
502
- return svg;
503
- }
504
- /**
505
- * Returns an Observable which produces the string contents of the given icon. Results may be
506
- * cached, so future calls with the same URL may not cause another HTTP request.
507
- */
508
- _fetchIcon(iconConfig) {
509
- const { url: safeUrl, options } = iconConfig;
510
- const withCredentials = options?.withCredentials ?? false;
511
- if (!this._httpClient) {
512
- throw getMatIconNoHttpProviderError();
513
- }
514
- // TODO: add an ngDevMode check
515
- if (safeUrl == null) {
516
- throw Error(`Cannot fetch icon from URL "${safeUrl}".`);
517
- }
518
- const url = this._sanitizer.sanitize(SecurityContext.RESOURCE_URL, safeUrl);
519
- // TODO: add an ngDevMode check
520
- if (!url) {
521
- throw getMatIconFailedToSanitizeUrlError(safeUrl);
522
- }
523
- // Store in-progress fetches to avoid sending a duplicate request for a URL when there is
524
- // already a request in progress for that URL. It's necessary to call share() on the
525
- // Observable returned by http.get() so that multiple subscribers don't cause multiple XHRs.
526
- const inProgressFetch = this._inProgressUrlFetches.get(url);
527
- if (inProgressFetch) {
528
- return inProgressFetch;
529
- }
530
- const req = this._httpClient.get(url, { responseType: 'text', withCredentials }).pipe(map(svg => {
531
- // Security: This SVG is fetched from a SafeResourceUrl, and is thus
532
- // trusted HTML.
533
- return trustedHTMLFromString(svg);
534
- }), finalize(() => this._inProgressUrlFetches.delete(url)), share());
535
- this._inProgressUrlFetches.set(url, req);
536
- return req;
537
- }
538
- /**
539
- * Registers an icon config by name in the specified namespace.
540
- * @param namespace Namespace in which to register the icon config.
541
- * @param iconName Name under which to register the config.
542
- * @param config Config to be registered.
543
- */
544
- _addSvgIconConfig(namespace, iconName, config) {
545
- this._svgIconConfigs.set(iconKey(namespace, iconName), config);
546
- return this;
547
- }
548
- /**
549
- * Registers an icon set config in the specified namespace.
550
- * @param namespace Namespace in which to register the icon config.
551
- * @param config Config to be registered.
552
- */
553
- _addSvgIconSetConfig(namespace, config) {
554
- const configNamespace = this._iconSetConfigs.get(namespace);
555
- if (configNamespace) {
556
- configNamespace.push(config);
557
- }
558
- else {
559
- this._iconSetConfigs.set(namespace, [config]);
560
- }
561
- return this;
562
- }
563
- /** Parses a config's text into an SVG element. */
564
- _svgElementFromConfig(config) {
565
- if (!config.svgElement) {
566
- const svg = this._svgElementFromString(config.svgText);
567
- this._setSvgAttributes(svg, config.options);
568
- config.svgElement = svg;
569
- }
570
- return config.svgElement;
571
- }
572
- /** Tries to create an icon config through the registered resolver functions. */
573
- _getIconConfigFromResolvers(namespace, name) {
574
- for (let i = 0; i < this._resolvers.length; i++) {
575
- const result = this._resolvers[i](name, namespace);
576
- if (result) {
577
- return isSafeUrlWithOptions(result)
578
- ? new SvgIconConfig(result.url, null, result.options)
579
- : new SvgIconConfig(result, null);
580
- }
581
- }
582
- return undefined;
583
- }
584
- static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.2.0-next.2", ngImport: i0, type: MatIconRegistry, deps: [{ token: i1.HttpClient, optional: true }, { token: i2.DomSanitizer }, { token: DOCUMENT, optional: true }, { token: i0.ErrorHandler }], target: i0.ɵɵFactoryTarget.Injectable });
585
- static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "20.2.0-next.2", ngImport: i0, type: MatIconRegistry, providedIn: 'root' });
191
+ }
192
+ }
193
+ return null;
194
+ }
195
+ _loadSvgIconFromConfig(config) {
196
+ return this._fetchIcon(config).pipe(tap(svgText => config.svgText = svgText), map(() => this._svgElementFromConfig(config)));
197
+ }
198
+ _loadSvgIconSetFromConfig(config) {
199
+ if (config.svgText) {
200
+ return of(null);
201
+ }
202
+ return this._fetchIcon(config).pipe(tap(svgText => config.svgText = svgText));
203
+ }
204
+ _extractSvgIconFromSet(iconSet, iconName, options) {
205
+ const iconSource = iconSet.querySelector(`[id="${iconName}"]`);
206
+ if (!iconSource) {
207
+ return null;
208
+ }
209
+ const iconElement = iconSource.cloneNode(true);
210
+ iconElement.removeAttribute('id');
211
+ if (iconElement.nodeName.toLowerCase() === 'svg') {
212
+ return this._setSvgAttributes(iconElement, options);
213
+ }
214
+ if (iconElement.nodeName.toLowerCase() === 'symbol') {
215
+ return this._setSvgAttributes(this._toSvgElement(iconElement), options);
216
+ }
217
+ const svg = this._svgElementFromString(trustedHTMLFromString('<svg></svg>'));
218
+ svg.appendChild(iconElement);
219
+ return this._setSvgAttributes(svg, options);
220
+ }
221
+ _svgElementFromString(str) {
222
+ const div = this._document.createElement('DIV');
223
+ div.innerHTML = str;
224
+ const svg = div.querySelector('svg');
225
+ if (!svg) {
226
+ throw Error('<svg> tag not found');
227
+ }
228
+ return svg;
229
+ }
230
+ _toSvgElement(element) {
231
+ const svg = this._svgElementFromString(trustedHTMLFromString('<svg></svg>'));
232
+ const attributes = element.attributes;
233
+ for (let i = 0; i < attributes.length; i++) {
234
+ const {
235
+ name,
236
+ value
237
+ } = attributes[i];
238
+ if (name !== 'id') {
239
+ svg.setAttribute(name, value);
240
+ }
241
+ }
242
+ for (let i = 0; i < element.childNodes.length; i++) {
243
+ if (element.childNodes[i].nodeType === this._document.ELEMENT_NODE) {
244
+ svg.appendChild(element.childNodes[i].cloneNode(true));
245
+ }
246
+ }
247
+ return svg;
248
+ }
249
+ _setSvgAttributes(svg, options) {
250
+ svg.setAttribute('fit', '');
251
+ svg.setAttribute('height', '100%');
252
+ svg.setAttribute('width', '100%');
253
+ svg.setAttribute('preserveAspectRatio', 'xMidYMid meet');
254
+ svg.setAttribute('focusable', 'false');
255
+ if (options && options.viewBox) {
256
+ svg.setAttribute('viewBox', options.viewBox);
257
+ }
258
+ return svg;
259
+ }
260
+ _fetchIcon(iconConfig) {
261
+ const {
262
+ url: safeUrl,
263
+ options
264
+ } = iconConfig;
265
+ const withCredentials = options?.withCredentials ?? false;
266
+ if (!this._httpClient) {
267
+ throw getMatIconNoHttpProviderError();
268
+ }
269
+ if (safeUrl == null) {
270
+ throw Error(`Cannot fetch icon from URL "${safeUrl}".`);
271
+ }
272
+ const url = this._sanitizer.sanitize(SecurityContext.RESOURCE_URL, safeUrl);
273
+ if (!url) {
274
+ throw getMatIconFailedToSanitizeUrlError(safeUrl);
275
+ }
276
+ const inProgressFetch = this._inProgressUrlFetches.get(url);
277
+ if (inProgressFetch) {
278
+ return inProgressFetch;
279
+ }
280
+ const req = this._httpClient.get(url, {
281
+ responseType: 'text',
282
+ withCredentials
283
+ }).pipe(map(svg => {
284
+ return trustedHTMLFromString(svg);
285
+ }), finalize(() => this._inProgressUrlFetches.delete(url)), share());
286
+ this._inProgressUrlFetches.set(url, req);
287
+ return req;
288
+ }
289
+ _addSvgIconConfig(namespace, iconName, config) {
290
+ this._svgIconConfigs.set(iconKey(namespace, iconName), config);
291
+ return this;
292
+ }
293
+ _addSvgIconSetConfig(namespace, config) {
294
+ const configNamespace = this._iconSetConfigs.get(namespace);
295
+ if (configNamespace) {
296
+ configNamespace.push(config);
297
+ } else {
298
+ this._iconSetConfigs.set(namespace, [config]);
299
+ }
300
+ return this;
301
+ }
302
+ _svgElementFromConfig(config) {
303
+ if (!config.svgElement) {
304
+ const svg = this._svgElementFromString(config.svgText);
305
+ this._setSvgAttributes(svg, config.options);
306
+ config.svgElement = svg;
307
+ }
308
+ return config.svgElement;
309
+ }
310
+ _getIconConfigFromResolvers(namespace, name) {
311
+ for (let i = 0; i < this._resolvers.length; i++) {
312
+ const result = this._resolvers[i](name, namespace);
313
+ if (result) {
314
+ return isSafeUrlWithOptions(result) ? new SvgIconConfig(result.url, null, result.options) : new SvgIconConfig(result, null);
315
+ }
316
+ }
317
+ return undefined;
318
+ }
319
+ static ɵfac = i0.ɵɵngDeclareFactory({
320
+ minVersion: "12.0.0",
321
+ version: "20.2.0-next.2",
322
+ ngImport: i0,
323
+ type: MatIconRegistry,
324
+ deps: [{
325
+ token: i1.HttpClient,
326
+ optional: true
327
+ }, {
328
+ token: i2.DomSanitizer
329
+ }, {
330
+ token: DOCUMENT,
331
+ optional: true
332
+ }, {
333
+ token: i0.ErrorHandler
334
+ }],
335
+ target: i0.ɵɵFactoryTarget.Injectable
336
+ });
337
+ static ɵprov = i0.ɵɵngDeclareInjectable({
338
+ minVersion: "12.0.0",
339
+ version: "20.2.0-next.2",
340
+ ngImport: i0,
341
+ type: MatIconRegistry,
342
+ providedIn: 'root'
343
+ });
586
344
  }
587
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.2.0-next.2", ngImport: i0, type: MatIconRegistry, decorators: [{
588
- type: Injectable,
589
- args: [{ providedIn: 'root' }]
590
- }], ctorParameters: () => [{ type: i1.HttpClient, decorators: [{
591
- type: Optional
592
- }] }, { type: i2.DomSanitizer }, { type: undefined, decorators: [{
593
- type: Optional
594
- }, {
595
- type: Inject,
596
- args: [DOCUMENT]
597
- }] }, { type: i0.ErrorHandler }] });
598
- /** Clones an SVGElement while preserving type information. */
345
+ i0.ɵɵngDeclareClassMetadata({
346
+ minVersion: "12.0.0",
347
+ version: "20.2.0-next.2",
348
+ ngImport: i0,
349
+ type: MatIconRegistry,
350
+ decorators: [{
351
+ type: Injectable,
352
+ args: [{
353
+ providedIn: 'root'
354
+ }]
355
+ }],
356
+ ctorParameters: () => [{
357
+ type: i1.HttpClient,
358
+ decorators: [{
359
+ type: Optional
360
+ }]
361
+ }, {
362
+ type: i2.DomSanitizer
363
+ }, {
364
+ type: undefined,
365
+ decorators: [{
366
+ type: Optional
367
+ }, {
368
+ type: Inject,
369
+ args: [DOCUMENT]
370
+ }]
371
+ }, {
372
+ type: i0.ErrorHandler
373
+ }]
374
+ });
599
375
  function cloneSvg(svg) {
600
- return svg.cloneNode(true);
376
+ return svg.cloneNode(true);
601
377
  }
602
- /** Returns the cache key to use for an icon namespace and name. */
603
378
  function iconKey(namespace, name) {
604
- return namespace + ':' + name;
379
+ return namespace + ':' + name;
605
380
  }
606
381
  function isSafeUrlWithOptions(value) {
607
- return !!(value.url && value.options);
382
+ return !!(value.url && value.options);
608
383
  }
609
384
 
610
385
  export { MatIconRegistry, getMatIconFailedToSanitizeLiteralError, getMatIconFailedToSanitizeUrlError, getMatIconNameNotFoundError, getMatIconNoHttpProviderError };