-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathicon-registry.d.ts
148 lines (148 loc) · 6.98 KB
/
icon-registry.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
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
import { Http } from '@angular/http';
import { MdError } from '@angular2-material/core/errors/error';
import { Observable } from 'rxjs/Observable';
import 'rxjs/add/observable/forkJoin';
import 'rxjs/add/observable/of';
import 'rxjs/add/operator/map';
import 'rxjs/add/operator/filter';
import 'rxjs/add/operator/do';
import 'rxjs/add/operator/share';
import 'rxjs/add/operator/finally';
import 'rxjs/add/operator/catch';
/** Exception thrown when attempting to load an icon with a name that cannot be found. */
export declare class MdIconNameNotFoundError extends MdError {
constructor(iconName: string);
}
/**
* Exception thrown when attempting to load SVG content that does not contain the expected
* <svg> tag.
*/
export declare class MdIconSvgTagNotFoundError extends MdError {
constructor();
}
/**
* Service to register and display icons used by the <md-icon> component.
* - Registers icon URLs by namespace and name.
* - Registers icon set URLs by namespace.
* - Registers aliases for CSS classes, for use with icon fonts.
* - Loads icons from URLs and extracts individual icons from icon sets.
*/
export declare class MdIconRegistry {
private _http;
/**
* URLs and cached SVG elements for individual icons. Keys are of the format "[namespace]:[icon]".
*/
private _svgIconConfigs;
/**
* SvgIconConfig objects and cached SVG elements for icon sets, keyed by namespace.
* Multiple icon sets can be registered under the same namespace.
*/
private _iconSetConfigs;
/** Cache for icons loaded by direct URLs. */
private _cachedIconsByUrl;
/** In-progress icon fetches. Used to coalesce multiple requests to the same URL. */
private _inProgressUrlFetches;
/** Map from font identifiers to their CSS class names. Used for icon fonts. */
private _fontCssClassesByAlias;
/**
* The CSS class to apply when an <md-icon> component has no icon name, url, or font specified.
* The default 'material-icons' value assumes that the material icon font has been loaded as
* described at http://google.github.io/material-design-icons/#icon-font-for-the-web
*/
private _defaultFontSetClass;
constructor(_http: Http);
/** Registers an icon by URL in the default namespace. */
addSvgIcon(iconName: string, url: string): this;
/** Registers an icon by URL in the specified namespace. */
addSvgIconInNamespace(namespace: string, iconName: string, url: string): this;
/** Registers an icon set by URL in the default namespace. */
addSvgIconSet(url: string): this;
/** Registers an icon set by URL in the specified namespace. */
addSvgIconSetInNamespace(namespace: string, url: string): this;
/**
* Defines an alias for a CSS class name to be used for icon fonts. Creating an mdIcon
* component with the alias as the fontSet input will cause the class name to be applied
* to the <md-icon> element.
*/
registerFontClassAlias(alias: string, className?: string): this;
/**
* Returns the CSS class name associated with the alias by a previous call to
* registerFontClassAlias. If no CSS class has been associated, returns the alias unmodified.
*/
classNameForFontAlias(alias: string): string;
/**
* Sets the CSS class name to be used for icon fonts when an <md-icon> component does not
* have a fontSet input value, and is not loading an icon by name or URL.
*/
setDefaultFontSetClass(className: string): this;
/**
* Returns the CSS class name to be used for icon fonts when an <md-icon> component does not
* have a fontSet input value, and is not loading an icon by name or URL.
*/
getDefaultFontSetClass(): string;
/**
* Returns an Observable that produces the icon (as an <svg> DOM element) from the given URL.
* The response from the URL may be cached so this will not always cause an HTTP request, but
* the produced element will always be a new copy of the originally fetched icon. (That is,
* it will not contain any modifications made to elements previously returned).
*/
getSvgIconFromUrl(url: string): Observable<SVGElement>;
/**
* Returns an Observable that produces the icon (as an <svg> DOM element) with the given name
* and namespace. The icon must have been previously registered with addIcon or addIconSet;
* if not, the Observable will throw an MdIconNameNotFoundError.
*/
getNamedSvgIcon(name: string, namespace?: string): Observable<SVGElement>;
/**
* Returns the cached icon for a SvgIconConfig if available, or fetches it from its URL if not.
*/
private _getSvgFromConfig(config);
/**
* Attempts to find an icon with the specified name in any of the SVG icon sets.
* First searches the available cached icons for a nested element with a matching name, and
* if found copies the element to a new <svg> element. If not found, fetches all icon sets
* that have not been cached, and searches again after all fetches are completed.
* The returned Observable produces the SVG element if possible, and throws
* MdIconNameNotFoundError if no icon with the specified name can be found.
*/
private _getSvgFromIconSetConfigs(name, iconSetConfigs);
/**
* Searches the cached SVG elements for the given icon sets for a nested icon element whose "id"
* tag matches the specified name. If found, copies the nested element to a new SVG element and
* returns it. Returns null if no matching element is found.
*/
private _extractIconWithNameFromAnySet(iconName, iconSetConfigs);
/**
* Loads the content of the icon URL specified in the SvgIconConfig and creates an SVG element
* from it.
*/
private _loadSvgIconFromConfig(config);
/**
* Loads the content of the icon set URL specified in the SvgIconConfig and creates an SVG element
* from it.
*/
private _loadSvgIconSetFromConfig(config);
/**
* Creates a DOM element from the given SVG string, and adds default attributes.
*/
private _createSvgElementForSingleIcon(responseText, config);
/**
* Searches the cached element of the given SvgIconConfig for a nested icon element whose "id"
* tag matches the specified name. If found, copies the nested element to a new SVG element and
* returns it. Returns null if no matching element is found.
*/
private _extractSvgIconFromSet(iconSet, iconName, config);
/**
* Creates a DOM element from the given SVG string.
*/
private _svgElementFromString(str);
/**
* Sets the default attributes for an SVG element to be used as an icon.
*/
private _setSvgAttributes(svg, config);
/**
* Returns an Observable which produces the string contents of the given URL. Results may be
* cached, so future calls with the same URL may not cause another HTTP request.
*/
private _fetchUrl(url);
}