@angular/material 21.0.0-next.8 → 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.
- package/core/tokens/_classes.scss +1 -1
- package/core/tokens/m2/_md-sys-color.scss +17 -17
- package/fesm2022/_animation-chunk.mjs +10 -16
- package/fesm2022/_animation-chunk.mjs.map +1 -1
- package/fesm2022/_date-formats-chunk.mjs +68 -164
- package/fesm2022/_date-formats-chunk.mjs.map +1 -1
- package/fesm2022/_date-range-input-harness-chunk.mjs +284 -463
- package/fesm2022/_date-range-input-harness-chunk.mjs.map +1 -1
- package/fesm2022/_error-options-chunk.mjs +56 -19
- package/fesm2022/_error-options-chunk.mjs.map +1 -1
- package/fesm2022/_error-state-chunk.mjs +24 -31
- package/fesm2022/_error-state-chunk.mjs.map +1 -1
- package/fesm2022/_form-field-chunk.mjs +1224 -1017
- package/fesm2022/_form-field-chunk.mjs.map +1 -1
- package/fesm2022/_icon-button-chunk.mjs +243 -187
- package/fesm2022/_icon-button-chunk.mjs.map +1 -1
- package/fesm2022/_icon-registry-chunk.mjs +350 -575
- package/fesm2022/_icon-registry-chunk.mjs.map +1 -1
- package/fesm2022/_input-harness-chunk.mjs +56 -107
- package/fesm2022/_input-harness-chunk.mjs.map +1 -1
- package/fesm2022/_input-value-accessor-chunk.mjs +0 -6
- package/fesm2022/_input-value-accessor-chunk.mjs.map +1 -1
- package/fesm2022/_internal-form-field-chunk.mjs +59 -19
- package/fesm2022/_internal-form-field-chunk.mjs.map +1 -1
- package/fesm2022/_line-chunk.mjs +83 -43
- package/fesm2022/_line-chunk.mjs.map +1 -1
- package/fesm2022/_option-chunk.mjs +348 -311
- package/fesm2022/_option-chunk.mjs.map +1 -1
- package/fesm2022/_option-harness-chunk.mjs +23 -39
- package/fesm2022/_option-harness-chunk.mjs.map +1 -1
- package/fesm2022/_option-module-chunk.mjs +36 -10
- package/fesm2022/_option-module-chunk.mjs.map +1 -1
- package/fesm2022/_pseudo-checkbox-chunk.mjs +79 -44
- package/fesm2022/_pseudo-checkbox-chunk.mjs.map +1 -1
- package/fesm2022/_pseudo-checkbox-module-chunk.mjs +36 -10
- package/fesm2022/_pseudo-checkbox-module-chunk.mjs.map +1 -1
- package/fesm2022/_public-api-chunk.mjs +71 -134
- package/fesm2022/_public-api-chunk.mjs.map +1 -1
- package/fesm2022/_ripple-chunk.mjs +504 -600
- package/fesm2022/_ripple-chunk.mjs.map +1 -1
- package/fesm2022/_ripple-loader-chunk.mjs +120 -138
- package/fesm2022/_ripple-loader-chunk.mjs.map +1 -1
- package/fesm2022/_ripple-module-chunk.mjs +36 -10
- package/fesm2022/_ripple-module-chunk.mjs.map +1 -1
- package/fesm2022/_structural-styles-chunk.mjs +37 -10
- package/fesm2022/_structural-styles-chunk.mjs.map +1 -1
- package/fesm2022/_tooltip-chunk.mjs +810 -888
- package/fesm2022/_tooltip-chunk.mjs.map +1 -1
- package/fesm2022/autocomplete-testing.mjs +62 -86
- package/fesm2022/autocomplete-testing.mjs.map +1 -1
- package/fesm2022/autocomplete.mjs +965 -1126
- package/fesm2022/autocomplete.mjs.map +1 -1
- package/fesm2022/badge-testing.mjs +38 -54
- package/fesm2022/badge-testing.mjs.map +1 -1
- package/fesm2022/badge.mjs +321 -272
- package/fesm2022/badge.mjs.map +1 -1
- package/fesm2022/bottom-sheet-testing.mjs +10 -24
- package/fesm2022/bottom-sheet-testing.mjs.map +1 -1
- package/fesm2022/bottom-sheet.mjs +349 -344
- package/fesm2022/bottom-sheet.mjs.map +1 -1
- package/fesm2022/button-testing.mjs +60 -94
- package/fesm2022/button-testing.mjs.map +1 -1
- package/fesm2022/button-toggle-testing.mjs +76 -125
- package/fesm2022/button-toggle-testing.mjs.map +1 -1
- package/fesm2022/button-toggle.mjs +752 -662
- package/fesm2022/button-toggle.mjs.map +1 -1
- package/fesm2022/button.mjs +263 -158
- package/fesm2022/button.mjs.map +1 -1
- package/fesm2022/card-testing.mjs +19 -33
- package/fesm2022/card-testing.mjs.map +1 -1
- package/fesm2022/card.mjs +576 -272
- package/fesm2022/card.mjs.map +1 -1
- package/fesm2022/checkbox-testing.mjs +71 -123
- package/fesm2022/checkbox-testing.mjs.map +1 -1
- package/fesm2022/checkbox.mjs +515 -477
- package/fesm2022/checkbox.mjs.map +1 -1
- package/fesm2022/chips-testing.mjs +201 -350
- package/fesm2022/chips-testing.mjs.map +1 -1
- package/fesm2022/chips.mjs +2552 -2289
- package/fesm2022/chips.mjs.map +1 -1
- package/fesm2022/core-testing.mjs +14 -28
- package/fesm2022/core-testing.mjs.map +1 -1
- package/fesm2022/core.mjs +357 -328
- package/fesm2022/core.mjs.map +1 -1
- package/fesm2022/datepicker-testing.mjs +15 -25
- package/fesm2022/datepicker-testing.mjs.map +1 -1
- package/fesm2022/datepicker.mjs +4826 -4563
- package/fesm2022/datepicker.mjs.map +1 -1
- package/fesm2022/dialog-testing.mjs +93 -129
- package/fesm2022/dialog-testing.mjs.map +1 -1
- package/fesm2022/dialog.mjs +810 -829
- package/fesm2022/dialog.mjs.map +1 -1
- package/fesm2022/divider-testing.mjs +10 -11
- package/fesm2022/divider-testing.mjs.map +1 -1
- package/fesm2022/divider.mjs +119 -43
- package/fesm2022/divider.mjs.map +1 -1
- package/fesm2022/expansion-testing.mjs +74 -130
- package/fesm2022/expansion-testing.mjs.map +1 -1
- package/fesm2022/expansion.mjs +703 -515
- package/fesm2022/expansion.mjs.map +1 -1
- package/fesm2022/form-field-testing-control.mjs +16 -33
- package/fesm2022/form-field-testing-control.mjs.map +1 -1
- package/fesm2022/form-field-testing.mjs +118 -179
- package/fesm2022/form-field-testing.mjs.map +1 -1
- package/fesm2022/form-field.mjs +36 -10
- package/fesm2022/form-field.mjs.map +1 -1
- package/fesm2022/grid-list-testing.mjs +65 -113
- package/fesm2022/grid-list-testing.mjs.map +1 -1
- package/fesm2022/grid-list.mjs +559 -494
- package/fesm2022/grid-list.mjs.map +1 -1
- package/fesm2022/icon-testing.mjs +148 -127
- package/fesm2022/icon-testing.mjs.map +1 -1
- package/fesm2022/icon.mjs +325 -351
- package/fesm2022/icon.mjs.map +1 -1
- package/fesm2022/input-testing.mjs +59 -99
- package/fesm2022/input-testing.mjs.map +1 -1
- package/fesm2022/input.mjs +457 -520
- package/fesm2022/input.mjs.map +1 -1
- package/fesm2022/list-testing.mjs +251 -434
- package/fesm2022/list-testing.mjs.map +1 -1
- package/fesm2022/list.mjs +1522 -1204
- package/fesm2022/list.mjs.map +1 -1
- package/fesm2022/material.mjs +0 -5
- package/fesm2022/material.mjs.map +1 -1
- package/fesm2022/menu-testing.mjs +159 -228
- package/fesm2022/menu-testing.mjs.map +1 -1
- package/fesm2022/menu.mjs +1338 -1343
- package/fesm2022/menu.mjs.map +1 -1
- package/fesm2022/paginator-testing.mjs +55 -79
- package/fesm2022/paginator-testing.mjs.map +1 -1
- package/fesm2022/paginator.mjs +381 -309
- package/fesm2022/paginator.mjs.map +1 -1
- package/fesm2022/progress-bar-testing.mjs +12 -21
- package/fesm2022/progress-bar-testing.mjs.map +1 -1
- package/fesm2022/progress-bar.mjs +224 -169
- package/fesm2022/progress-bar.mjs.map +1 -1
- package/fesm2022/progress-spinner-testing.mjs +13 -23
- package/fesm2022/progress-spinner-testing.mjs.map +1 -1
- package/fesm2022/progress-spinner.mjs +235 -160
- package/fesm2022/progress-spinner.mjs.map +1 -1
- package/fesm2022/radio-testing.mjs +133 -208
- package/fesm2022/radio-testing.mjs.map +1 -1
- package/fesm2022/radio.mjs +712 -679
- package/fesm2022/radio.mjs.map +1 -1
- package/fesm2022/select-testing.mjs +83 -117
- package/fesm2022/select-testing.mjs.map +1 -1
- package/fesm2022/select.mjs +1116 -1246
- package/fesm2022/select.mjs.map +1 -1
- package/fesm2022/sidenav-testing.mjs +54 -120
- package/fesm2022/sidenav-testing.mjs.map +1 -1
- package/fesm2022/sidenav.mjs +1078 -995
- package/fesm2022/sidenav.mjs.map +1 -1
- package/fesm2022/slide-toggle-testing.mjs +57 -92
- package/fesm2022/slide-toggle-testing.mjs.map +1 -1
- package/fesm2022/slide-toggle.mjs +369 -279
- package/fesm2022/slide-toggle.mjs.map +1 -1
- package/fesm2022/slider-testing.mjs +90 -138
- package/fesm2022/slider-testing.mjs.map +1 -1
- package/fesm2022/slider.mjs +1651 -1716
- package/fesm2022/slider.mjs.map +1 -1
- package/fesm2022/snack-bar-testing.mjs +40 -87
- package/fesm2022/snack-bar-testing.mjs.map +1 -1
- package/fesm2022/snack-bar.mjs +763 -714
- package/fesm2022/snack-bar.mjs.map +1 -1
- package/fesm2022/sort-testing.mjs +45 -66
- package/fesm2022/sort-testing.mjs.map +1 -1
- package/fesm2022/sort.mjs +419 -344
- package/fesm2022/sort.mjs.map +1 -1
- package/fesm2022/stepper-testing.mjs +78 -154
- package/fesm2022/stepper-testing.mjs.map +1 -1
- package/fesm2022/stepper.mjs +790 -498
- package/fesm2022/stepper.mjs.map +1 -1
- package/fesm2022/table-testing.mjs +125 -186
- package/fesm2022/table-testing.mjs.map +1 -1
- package/fesm2022/table.mjs +1026 -684
- package/fesm2022/table.mjs.map +1 -1
- package/fesm2022/tabs-testing.mjs +125 -197
- package/fesm2022/tabs-testing.mjs.map +1 -1
- package/fesm2022/tabs.mjs +2351 -2028
- package/fesm2022/tabs.mjs.map +1 -1
- package/fesm2022/timepicker-testing.mjs +113 -172
- package/fesm2022/timepicker-testing.mjs.map +1 -1
- package/fesm2022/timepicker.mjs +1019 -826
- package/fesm2022/timepicker.mjs.map +1 -1
- package/fesm2022/toolbar-testing.mjs +16 -27
- package/fesm2022/toolbar-testing.mjs.map +1 -1
- package/fesm2022/toolbar.mjs +163 -78
- package/fesm2022/toolbar.mjs.map +1 -1
- package/fesm2022/tooltip-testing.mjs +41 -52
- package/fesm2022/tooltip-testing.mjs.map +1 -1
- package/fesm2022/tooltip.mjs +36 -10
- package/fesm2022/tooltip.mjs.map +1 -1
- package/fesm2022/tree-testing.mjs +86 -162
- package/fesm2022/tree-testing.mjs.map +1 -1
- package/fesm2022/tree.mjs +638 -466
- package/fesm2022/tree.mjs.map +1 -1
- package/package.json +2 -2
- package/schematics/ng-add/index.js +1 -1
- package/types/expansion.d.ts +4 -2
- package/types/menu-testing.d.ts +2 -0
- package/types/select.d.ts +1 -1
- package/types/sort.d.ts +1 -1
- package/types/table-testing.d.ts +27 -1
- package/types/timepicker.d.ts +148 -128
|
@@ -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
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
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
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
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
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
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({
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
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
|
-
|
|
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
|
-
|
|
379
|
+
return namespace + ':' + name;
|
|
605
380
|
}
|
|
606
381
|
function isSafeUrlWithOptions(value) {
|
|
607
|
-
|
|
382
|
+
return !!(value.url && value.options);
|
|
608
383
|
}
|
|
609
384
|
|
|
610
385
|
export { MatIconRegistry, getMatIconFailedToSanitizeLiteralError, getMatIconFailedToSanitizeUrlError, getMatIconNameNotFoundError, getMatIconNoHttpProviderError };
|