1 | /**
|
---|
2 | * @license
|
---|
3 | * Copyright Google LLC All Rights Reserved.
|
---|
4 | *
|
---|
5 | * Use of this source code is governed by an MIT-style license that can be
|
---|
6 | * found in the LICENSE file at https://angular.io/license
|
---|
7 | */
|
---|
8 | import { HttpClient } from '@angular/common/http';
|
---|
9 | import { ErrorHandler, Optional, OnDestroy } from '@angular/core';
|
---|
10 | import { DomSanitizer, SafeResourceUrl, SafeHtml } from '@angular/platform-browser';
|
---|
11 | import { Observable } from 'rxjs';
|
---|
12 | /**
|
---|
13 | * Returns an exception to be thrown in the case when attempting to
|
---|
14 | * load an icon with a name that cannot be found.
|
---|
15 | * @docs-private
|
---|
16 | */
|
---|
17 | export declare function getMatIconNameNotFoundError(iconName: string): Error;
|
---|
18 | /**
|
---|
19 | * Returns an exception to be thrown when the consumer attempts to use
|
---|
20 | * `<mat-icon>` without including @angular/common/http.
|
---|
21 | * @docs-private
|
---|
22 | */
|
---|
23 | export declare function getMatIconNoHttpProviderError(): Error;
|
---|
24 | /**
|
---|
25 | * Returns an exception to be thrown when a URL couldn't be sanitized.
|
---|
26 | * @param url URL that was attempted to be sanitized.
|
---|
27 | * @docs-private
|
---|
28 | */
|
---|
29 | export declare function getMatIconFailedToSanitizeUrlError(url: SafeResourceUrl): Error;
|
---|
30 | /**
|
---|
31 | * Returns an exception to be thrown when a HTML string couldn't be sanitized.
|
---|
32 | * @param literal HTML that was attempted to be sanitized.
|
---|
33 | * @docs-private
|
---|
34 | */
|
---|
35 | export declare function getMatIconFailedToSanitizeLiteralError(literal: SafeHtml): Error;
|
---|
36 | /** Options that can be used to configure how an icon or the icons in an icon set are presented. */
|
---|
37 | export interface IconOptions {
|
---|
38 | /** View box to set on the icon. */
|
---|
39 | viewBox?: string;
|
---|
40 | /** Whether or not to fetch the icon or icon set using HTTP credentials. */
|
---|
41 | withCredentials?: boolean;
|
---|
42 | }
|
---|
43 | /**
|
---|
44 | * Function that will be invoked by the icon registry when trying to resolve the
|
---|
45 | * URL from which to fetch an icon. The returned URL will be used to make a request for the icon.
|
---|
46 | */
|
---|
47 | export declare type IconResolver = (name: string, namespace: string) => (SafeResourceUrl | SafeResourceUrlWithIconOptions | null);
|
---|
48 | /** Object that specifies a URL from which to fetch an icon and the options to use for it. */
|
---|
49 | export interface SafeResourceUrlWithIconOptions {
|
---|
50 | url: SafeResourceUrl;
|
---|
51 | options: IconOptions;
|
---|
52 | }
|
---|
53 | /**
|
---|
54 | * Service to register and display icons used by the `<mat-icon>` component.
|
---|
55 | * - Registers icon URLs by namespace and name.
|
---|
56 | * - Registers icon set URLs by namespace.
|
---|
57 | * - Registers aliases for CSS classes, for use with icon fonts.
|
---|
58 | * - Loads icons from URLs and extracts individual icons from icon sets.
|
---|
59 | */
|
---|
60 | export declare class MatIconRegistry implements OnDestroy {
|
---|
61 | private _httpClient;
|
---|
62 | private _sanitizer;
|
---|
63 | private readonly _errorHandler;
|
---|
64 | private _document;
|
---|
65 | /**
|
---|
66 | * URLs and cached SVG elements for individual icons. Keys are of the format "[namespace]:[icon]".
|
---|
67 | */
|
---|
68 | private _svgIconConfigs;
|
---|
69 | /**
|
---|
70 | * SvgIconConfig objects and cached SVG elements for icon sets, keyed by namespace.
|
---|
71 | * Multiple icon sets can be registered under the same namespace.
|
---|
72 | */
|
---|
73 | private _iconSetConfigs;
|
---|
74 | /** Cache for icons loaded by direct URLs. */
|
---|
75 | private _cachedIconsByUrl;
|
---|
76 | /** In-progress icon fetches. Used to coalesce multiple requests to the same URL. */
|
---|
77 | private _inProgressUrlFetches;
|
---|
78 | /** Map from font identifiers to their CSS class names. Used for icon fonts. */
|
---|
79 | private _fontCssClassesByAlias;
|
---|
80 | /** Registered icon resolver functions. */
|
---|
81 | private _resolvers;
|
---|
82 | /**
|
---|
83 | * The CSS class to apply when an `<mat-icon>` component has no icon name, url, or font specified.
|
---|
84 | * The default 'material-icons' value assumes that the material icon font has been loaded as
|
---|
85 | * described at http://google.github.io/material-design-icons/#icon-font-for-the-web
|
---|
86 | */
|
---|
87 | private _defaultFontSetClass;
|
---|
88 | constructor(_httpClient: HttpClient, _sanitizer: DomSanitizer, document: any, _errorHandler: ErrorHandler);
|
---|
89 | /**
|
---|
90 | * Registers an icon by URL in the default namespace.
|
---|
91 | * @param iconName Name under which the icon should be registered.
|
---|
92 | * @param url
|
---|
93 | */
|
---|
94 | addSvgIcon(iconName: string, url: SafeResourceUrl, options?: IconOptions): this;
|
---|
95 | /**
|
---|
96 | * Registers an icon using an HTML string in the default namespace.
|
---|
97 | * @param iconName Name under which the icon should be registered.
|
---|
98 | * @param literal SVG source of the icon.
|
---|
99 | */
|
---|
100 | addSvgIconLiteral(iconName: string, literal: SafeHtml, options?: IconOptions): this;
|
---|
101 | /**
|
---|
102 | * Registers an icon by URL in the specified namespace.
|
---|
103 | * @param namespace Namespace in which the icon should be registered.
|
---|
104 | * @param iconName Name under which the icon should be registered.
|
---|
105 | * @param url
|
---|
106 | */
|
---|
107 | addSvgIconInNamespace(namespace: string, iconName: string, url: SafeResourceUrl, options?: IconOptions): this;
|
---|
108 | /**
|
---|
109 | * Registers an icon resolver function with the registry. The function will be invoked with the
|
---|
110 | * name and namespace of an icon when the registry tries to resolve the URL from which to fetch
|
---|
111 | * the icon. The resolver is expected to return a `SafeResourceUrl` that points to the icon,
|
---|
112 | * an object with the icon URL and icon options, or `null` if the icon is not supported. Resolvers
|
---|
113 | * will be invoked in the order in which they have been registered.
|
---|
114 | * @param resolver Resolver function to be registered.
|
---|
115 | */
|
---|
116 | addSvgIconResolver(resolver: IconResolver): this;
|
---|
117 | /**
|
---|
118 | * Registers an icon using an HTML string in the specified namespace.
|
---|
119 | * @param namespace Namespace in which the icon should be registered.
|
---|
120 | * @param iconName Name under which the icon should be registered.
|
---|
121 | * @param literal SVG source of the icon.
|
---|
122 | */
|
---|
123 | addSvgIconLiteralInNamespace(namespace: string, iconName: string, literal: SafeHtml, options?: IconOptions): this;
|
---|
124 | /**
|
---|
125 | * Registers an icon set by URL in the default namespace.
|
---|
126 | * @param url
|
---|
127 | */
|
---|
128 | addSvgIconSet(url: SafeResourceUrl, options?: IconOptions): this;
|
---|
129 | /**
|
---|
130 | * Registers an icon set using an HTML string in the default namespace.
|
---|
131 | * @param literal SVG source of the icon set.
|
---|
132 | */
|
---|
133 | addSvgIconSetLiteral(literal: SafeHtml, options?: IconOptions): this;
|
---|
134 | /**
|
---|
135 | * Registers an icon set by URL in the specified namespace.
|
---|
136 | * @param namespace Namespace in which to register the icon set.
|
---|
137 | * @param url
|
---|
138 | */
|
---|
139 | addSvgIconSetInNamespace(namespace: string, url: SafeResourceUrl, options?: IconOptions): this;
|
---|
140 | /**
|
---|
141 | * Registers an icon set using an HTML string in the specified namespace.
|
---|
142 | * @param namespace Namespace in which to register the icon set.
|
---|
143 | * @param literal SVG source of the icon set.
|
---|
144 | */
|
---|
145 | addSvgIconSetLiteralInNamespace(namespace: string, literal: SafeHtml, options?: IconOptions): this;
|
---|
146 | /**
|
---|
147 | * Defines an alias for a CSS class name to be used for icon fonts. Creating an matIcon
|
---|
148 | * component with the alias as the fontSet input will cause the class name to be applied
|
---|
149 | * to the `<mat-icon>` element.
|
---|
150 | *
|
---|
151 | * @param alias Alias for the font.
|
---|
152 | * @param className Class name override to be used instead of the alias.
|
---|
153 | */
|
---|
154 | registerFontClassAlias(alias: string, className?: string): this;
|
---|
155 | /**
|
---|
156 | * Returns the CSS class name associated with the alias by a previous call to
|
---|
157 | * registerFontClassAlias. If no CSS class has been associated, returns the alias unmodified.
|
---|
158 | */
|
---|
159 | classNameForFontAlias(alias: string): string;
|
---|
160 | /**
|
---|
161 | * Sets the CSS class name to be used for icon fonts when an `<mat-icon>` component does not
|
---|
162 | * have a fontSet input value, and is not loading an icon by name or URL.
|
---|
163 | *
|
---|
164 | * @param className
|
---|
165 | */
|
---|
166 | setDefaultFontSetClass(className: string): this;
|
---|
167 | /**
|
---|
168 | * Returns the CSS class name to be used for icon fonts when an `<mat-icon>` component does not
|
---|
169 | * have a fontSet input value, and is not loading an icon by name or URL.
|
---|
170 | */
|
---|
171 | getDefaultFontSetClass(): string;
|
---|
172 | /**
|
---|
173 | * Returns an Observable that produces the icon (as an `<svg>` DOM element) from the given URL.
|
---|
174 | * The response from the URL may be cached so this will not always cause an HTTP request, but
|
---|
175 | * the produced element will always be a new copy of the originally fetched icon. (That is,
|
---|
176 | * it will not contain any modifications made to elements previously returned).
|
---|
177 | *
|
---|
178 | * @param safeUrl URL from which to fetch the SVG icon.
|
---|
179 | */
|
---|
180 | getSvgIconFromUrl(safeUrl: SafeResourceUrl): Observable<SVGElement>;
|
---|
181 | /**
|
---|
182 | * Returns an Observable that produces the icon (as an `<svg>` DOM element) with the given name
|
---|
183 | * and namespace. The icon must have been previously registered with addIcon or addIconSet;
|
---|
184 | * if not, the Observable will throw an error.
|
---|
185 | *
|
---|
186 | * @param name Name of the icon to be retrieved.
|
---|
187 | * @param namespace Namespace in which to look for the icon.
|
---|
188 | */
|
---|
189 | getNamedSvgIcon(name: string, namespace?: string): Observable<SVGElement>;
|
---|
190 | ngOnDestroy(): void;
|
---|
191 | /**
|
---|
192 | * Returns the cached icon for a SvgIconConfig if available, or fetches it from its URL if not.
|
---|
193 | */
|
---|
194 | private _getSvgFromConfig;
|
---|
195 | /**
|
---|
196 | * Attempts to find an icon with the specified name in any of the SVG icon sets.
|
---|
197 | * First searches the available cached icons for a nested element with a matching name, and
|
---|
198 | * if found copies the element to a new `<svg>` element. If not found, fetches all icon sets
|
---|
199 | * that have not been cached, and searches again after all fetches are completed.
|
---|
200 | * The returned Observable produces the SVG element if possible, and throws
|
---|
201 | * an error if no icon with the specified name can be found.
|
---|
202 | */
|
---|
203 | private _getSvgFromIconSetConfigs;
|
---|
204 | /**
|
---|
205 | * Searches the cached SVG elements for the given icon sets for a nested icon element whose "id"
|
---|
206 | * tag matches the specified name. If found, copies the nested element to a new SVG element and
|
---|
207 | * returns it. Returns null if no matching element is found.
|
---|
208 | */
|
---|
209 | private _extractIconWithNameFromAnySet;
|
---|
210 | /**
|
---|
211 | * Loads the content of the icon URL specified in the SvgIconConfig and creates an SVG element
|
---|
212 | * from it.
|
---|
213 | */
|
---|
214 | private _loadSvgIconFromConfig;
|
---|
215 | /**
|
---|
216 | * Loads the content of the icon set URL specified in the
|
---|
217 | * SvgIconConfig and attaches it to the config.
|
---|
218 | */
|
---|
219 | private _loadSvgIconSetFromConfig;
|
---|
220 | /**
|
---|
221 | * Searches the cached element of the given SvgIconConfig for a nested icon element whose "id"
|
---|
222 | * tag matches the specified name. If found, copies the nested element to a new SVG element and
|
---|
223 | * returns it. Returns null if no matching element is found.
|
---|
224 | */
|
---|
225 | private _extractSvgIconFromSet;
|
---|
226 | /**
|
---|
227 | * Creates a DOM element from the given SVG string.
|
---|
228 | */
|
---|
229 | private _svgElementFromString;
|
---|
230 | /**
|
---|
231 | * Converts an element into an SVG node by cloning all of its children.
|
---|
232 | */
|
---|
233 | private _toSvgElement;
|
---|
234 | /**
|
---|
235 | * Sets the default attributes for an SVG element to be used as an icon.
|
---|
236 | */
|
---|
237 | private _setSvgAttributes;
|
---|
238 | /**
|
---|
239 | * Returns an Observable which produces the string contents of the given icon. Results may be
|
---|
240 | * cached, so future calls with the same URL may not cause another HTTP request.
|
---|
241 | */
|
---|
242 | private _fetchIcon;
|
---|
243 | /**
|
---|
244 | * Registers an icon config by name in the specified namespace.
|
---|
245 | * @param namespace Namespace in which to register the icon config.
|
---|
246 | * @param iconName Name under which to register the config.
|
---|
247 | * @param config Config to be registered.
|
---|
248 | */
|
---|
249 | private _addSvgIconConfig;
|
---|
250 | /**
|
---|
251 | * Registers an icon set config in the specified namespace.
|
---|
252 | * @param namespace Namespace in which to register the icon config.
|
---|
253 | * @param config Config to be registered.
|
---|
254 | */
|
---|
255 | private _addSvgIconSetConfig;
|
---|
256 | /** Parses a config's text into an SVG element. */
|
---|
257 | private _svgElementFromConfig;
|
---|
258 | /** Tries to create an icon config through the registered resolver functions. */
|
---|
259 | private _getIconConfigFromResolvers;
|
---|
260 | }
|
---|
261 | /** @docs-private */
|
---|
262 | export declare function ICON_REGISTRY_PROVIDER_FACTORY(parentRegistry: MatIconRegistry, httpClient: HttpClient, sanitizer: DomSanitizer, errorHandler: ErrorHandler, document?: any): MatIconRegistry;
|
---|
263 | /** @docs-private */
|
---|
264 | export declare const ICON_REGISTRY_PROVIDER: {
|
---|
265 | provide: typeof MatIconRegistry;
|
---|
266 | deps: (Optional[] | typeof DomSanitizer | typeof ErrorHandler)[];
|
---|
267 | useFactory: typeof ICON_REGISTRY_PROVIDER_FACTORY;
|
---|
268 | };
|
---|