1 | import { Http } from '@angular/http';
|
2 | import { MdError } from '@angular2-material/core';
|
3 | import { Observable } from 'rxjs/Observable';
|
4 | import 'rxjs/add/observable/forkJoin';
|
5 | import 'rxjs/add/observable/of';
|
6 | import 'rxjs/add/operator/map';
|
7 | import 'rxjs/add/operator/filter';
|
8 | import 'rxjs/add/operator/do';
|
9 | import 'rxjs/add/operator/share';
|
10 | import 'rxjs/add/operator/finally';
|
11 | import 'rxjs/add/operator/catch';
|
12 |
|
13 | export declare class MdIconNameNotFoundError extends MdError {
|
14 | constructor(iconName: string);
|
15 | }
|
16 | /**
|
17 | * Exception thrown when attempting to load SVG content that does not contain the expected
|
18 | * <svg> tag.
|
19 | */
|
20 | export declare class MdIconSvgTagNotFoundError extends MdError {
|
21 | constructor();
|
22 | }
|
23 | /**
|
24 | * Service to register and display icons used by the <md-icon> component.
|
25 | * - Registers icon URLs by namespace and name.
|
26 | * - Registers icon set URLs by namespace.
|
27 | * - Registers aliases for CSS classes, for use with icon fonts.
|
28 | * - Loads icons from URLs and extracts individual icons from icon sets.
|
29 | */
|
30 | export declare class MdIconRegistry {
|
31 | private _http;
|
32 | |
33 |
|
34 |
|
35 | private _svgIconConfigs;
|
36 | |
37 |
|
38 |
|
39 |
|
40 | private _iconSetConfigs;
|
41 |
|
42 | private _cachedIconsByUrl;
|
43 |
|
44 | private _inProgressUrlFetches;
|
45 |
|
46 | private _fontCssClassesByAlias;
|
47 | |
48 |
|
49 |
|
50 |
|
51 |
|
52 | private _defaultFontSetClass;
|
53 | constructor(_http: Http);
|
54 | /** Registers an icon by URL in the default namespace. */
|
55 | addSvgIcon(iconName: string, url: string): this;
|
56 | /** Registers an icon by URL in the specified namespace. */
|
57 | addSvgIconInNamespace(namespace: string, iconName: string, url: string): this;
|
58 | /** Registers an icon set by URL in the default namespace. */
|
59 | addSvgIconSet(url: string): this;
|
60 | /** Registers an icon set by URL in the specified namespace. */
|
61 | addSvgIconSetInNamespace(namespace: string, url: string): this;
|
62 | /**
|
63 | * Defines an alias for a CSS class name to be used for icon fonts. Creating an mdIcon
|
64 | * component with the alias as the fontSet input will cause the class name to be applied
|
65 | * to the <md-icon> element.
|
66 | */
|
67 | registerFontClassAlias(alias: string, className?: string): this;
|
68 | /**
|
69 | * Returns the CSS class name associated with the alias by a previous call to
|
70 | * registerFontClassAlias. If no CSS class has been associated, returns the alias unmodified.
|
71 | */
|
72 | classNameForFontAlias(alias: string): string;
|
73 | /**
|
74 | * Sets the CSS class name to be used for icon fonts when an <md-icon> component does not
|
75 | * have a fontSet input value, and is not loading an icon by name or URL.
|
76 | */
|
77 | setDefaultFontSetClass(className: string): this;
|
78 | /**
|
79 | * Returns the CSS class name to be used for icon fonts when an <md-icon> component does not
|
80 | * have a fontSet input value, and is not loading an icon by name or URL.
|
81 | */
|
82 | getDefaultFontSetClass(): string;
|
83 | /**
|
84 | * Returns an Observable that produces the icon (as an <svg> DOM element) from the given URL.
|
85 | * The response from the URL may be cached so this will not always cause an HTTP request, but
|
86 | * the produced element will always be a new copy of the originally fetched icon. (That is,
|
87 | * it will not contain any modifications made to elements previously returned).
|
88 | */
|
89 | getSvgIconFromUrl(url: string): Observable<SVGElement>;
|
90 | /**
|
91 | * Returns an Observable that produces the icon (as an <svg> DOM element) with the given name
|
92 | * and namespace. The icon must have been previously registered with addIcon or addIconSet;
|
93 | * if not, the Observable will throw an MdIconNameNotFoundError.
|
94 | */
|
95 | getNamedSvgIcon(name: string, namespace?: string): Observable<SVGElement>;
|
96 | /**
|
97 | * Returns the cached icon for a SvgIconConfig if available, or fetches it from its URL if not.
|
98 | */
|
99 | private _getSvgFromConfig(config);
|
100 | /**
|
101 | * Attempts to find an icon with the specified name in any of the SVG icon sets.
|
102 | * First searches the available cached icons for a nested element with a matching name, and
|
103 | * if found copies the element to a new <svg> element. If not found, fetches all icon sets
|
104 | * that have not been cached, and searches again after all fetches are completed.
|
105 | * The returned Observable produces the SVG element if possible, and throws
|
106 | * MdIconNameNotFoundError if no icon with the specified name can be found.
|
107 | */
|
108 | private _getSvgFromIconSetConfigs(name, iconSetConfigs);
|
109 | /**
|
110 | * Searches the cached SVG elements for the given icon sets for a nested icon element whose "id"
|
111 | * tag matches the specified name. If found, copies the nested element to a new SVG element and
|
112 | * returns it. Returns null if no matching element is found.
|
113 | */
|
114 | private _extractIconWithNameFromAnySet(iconName, iconSetConfigs);
|
115 | /**
|
116 | * Loads the content of the icon URL specified in the SvgIconConfig and creates an SVG element
|
117 | * from it.
|
118 | */
|
119 | private _loadSvgIconFromConfig(config);
|
120 | /**
|
121 | * Loads the content of the icon set URL specified in the SvgIconConfig and creates an SVG element
|
122 | * from it.
|
123 | */
|
124 | private _loadSvgIconSetFromConfig(config);
|
125 | /**
|
126 | * Creates a DOM element from the given SVG string, and adds default attributes.
|
127 | */
|
128 | private _createSvgElementForSingleIcon(responseText, config);
|
129 | /**
|
130 | * Searches the cached element of the given SvgIconConfig for a nested icon element whose "id"
|
131 | * tag matches the specified name. If found, copies the nested element to a new SVG element and
|
132 | * returns it. Returns null if no matching element is found.
|
133 | */
|
134 | private _extractSvgIconFromSet(iconSet, iconName, config);
|
135 | /**
|
136 | * Creates a DOM element from the given SVG string.
|
137 | */
|
138 | private _svgElementFromString(str);
|
139 | /**
|
140 | * Sets the default attributes for an SVG element to be used as an icon.
|
141 | */
|
142 | private _setSvgAttributes(svg, config);
|
143 | /**
|
144 | * Returns an Observable which produces the string contents of the given URL. Results may be
|
145 | * cached, so future calls with the same URL may not cause another HTTP request.
|
146 | */
|
147 | private _fetchUrl(url);
|
148 | }
|