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;YACP,KAAI,CAAC,qBAAqB,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;QACzC,CAAC,CAAC;aACD,KAAK,EAAE,CAAC;QACb,IAAI,CAAC,qBAAqB,CAAC,GAAG,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;QACzC,MAAM,CAAC,GAAG,CAAC;IACb,CAAC;IA/TH;QAAC,UAAU,EAAE;;sBAAA;IAgUb,qBAAC;AAAD,CA/TA,AA+TC,IAAA;AAGD,8DAA8D;AAC9D,kBAAkB,GAAe;IAC/B,MAAM,CAAc,GAAG,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;AAC1C,CAAC","file":"icon/icon-registry.js","sourcesContent":["import {Injectable} from '@angular/core';\nimport {Http} from '@angular/http';\nimport {MdError} from '@angular2-material/core';\nimport {Observable} from 'rxjs/Observable';\nimport 'rxjs/add/observable/forkJoin';\nimport 'rxjs/add/observable/of';\nimport 'rxjs/add/operator/map';\nimport 'rxjs/add/operator/filter';\nimport 'rxjs/add/operator/do';\nimport 'rxjs/add/operator/share';\nimport 'rxjs/add/operator/finally';\nimport 'rxjs/add/operator/catch';\n\n\n/** Exception thrown when attempting to load an icon with a name that cannot be found. */\nexport class MdIconNameNotFoundError extends MdError {\n constructor(iconName: string) {\n super(`Unable to find icon with the name \"${iconName}\"`);\n }\n}\n\n/**\n * Exception thrown when attempting to load SVG content that does not contain the expected\n * <svg> tag.\n */\nexport class MdIconSvgTagNotFoundError extends MdError {\n constructor() {\n super('<svg> tag not found');\n }\n}\n\n/** Configuration for an icon, including the URL and possibly the cached SVG element. */\nclass SvgIconConfig {\n svgElement: SVGElement = null;\n constructor(public url: string) { }\n}\n\n/** Returns the cache key to use for an icon namespace and name. */\nconst iconKey = (namespace: string, name: string) => namespace + ':' + name;\n\n/**\n * Service to register and display icons used by the <md-icon> component.\n * - Registers icon URLs by namespace and name.\n * - Registers icon set URLs by namespace.\n * - Registers aliases for CSS classes, for use with icon fonts.\n * - Loads icons from URLs and extracts individual icons from icon sets.\n */\n@Injectable()\nexport class MdIconRegistry {\n /**\n * URLs and cached SVG elements for individual icons. Keys are of the format \"[namespace]:[icon]\".\n */\n private _svgIconConfigs = new Map<string, SvgIconConfig>();\n\n /**\n * SvgIconConfig objects and cached SVG elements for icon sets, keyed by namespace.\n * Multiple icon sets can be registered under the same namespace.\n */\n private _iconSetConfigs = new Map<string, SvgIconConfig[]>();\n\n /** Cache for icons loaded by direct URLs. */\n private _cachedIconsByUrl = new Map<string, SVGElement>();\n\n /** In-progress icon fetches. Used to coalesce multiple requests to the same URL. */\n private _inProgressUrlFetches = new Map<string, Observable<string>>();\n\n /** Map from font identifiers to their CSS class names. Used for icon fonts. */\n private _fontCssClassesByAlias = new Map<string, string>();\n\n /**\n * The CSS class to apply when an <md-icon> component has no icon name, url, or font specified.\n * The default 'material-icons' value assumes that the material icon font has been loaded as\n * described at http://google.github.io/material-design-icons/#icon-font-for-the-web\n */\n private _defaultFontSetClass = 'material-icons';\n\n constructor(private _http: Http) {}\n\n /** Registers an icon by URL in the default namespace. */\n addSvgIcon(iconName: string, url: string): this {\n return this.addSvgIconInNamespace('', iconName, url);\n }\n\n /** Registers an icon by URL in the specified namespace. */\n addSvgIconInNamespace(namespace: string, iconName: string, url: string): this {\n const key = iconKey(namespace, iconName);\n this._svgIconConfigs.set(key, new SvgIconConfig(url));\n return this;\n }\n\n /** Registers an icon set by URL in the default namespace. */\n addSvgIconSet(url: string): this {\n return this.addSvgIconSetInNamespace('', url);\n }\n\n /** Registers an icon set by URL in the specified namespace. */\n addSvgIconSetInNamespace(namespace: string, url: string): this {\n const config = new SvgIconConfig(url);\n if (this._iconSetConfigs.has(namespace)) {\n this._iconSetConfigs.get(namespace).push(config);\n } else {\n this._iconSetConfigs.set(namespace, [config]);\n }\n return this;\n }\n\n /**\n * Defines an alias for a CSS class name to be used for icon fonts. Creating an mdIcon\n * component with the alias as the fontSet input will cause the class name to be applied\n * to the <md-icon> element.\n */\n registerFontClassAlias(alias: string, className = alias): this {\n this._fontCssClassesByAlias.set(alias, className);\n return this;\n }\n\n /**\n * Returns the CSS class name associated with the alias by a previous call to\n * registerFontClassAlias. If no CSS class has been associated, returns the alias unmodified.\n */\n classNameForFontAlias(alias: string): string {\n return this._fontCssClassesByAlias.get(alias) || alias;\n }\n\n /**\n * Sets the CSS class name to be used for icon fonts when an <md-icon> component does not\n * have a fontSet input value, and is not loading an icon by name or URL.\n */\n setDefaultFontSetClass(className: string): this {\n this._defaultFontSetClass = className;\n return this;\n }\n\n /**\n * Returns the CSS class name to be used for icon fonts when an <md-icon> component does not\n * have a fontSet input value, and is not loading an icon by name or URL.\n */\n getDefaultFontSetClass(): string {\n return this._defaultFontSetClass;\n }\n\n /**\n * Returns an Observable that produces the icon (as an <svg> DOM element) from the given URL.\n * The response from the URL may be cached so this will not always cause an HTTP request, but\n * the produced element will always be a new copy of the originally fetched icon. (That is,\n * it will not contain any modifications made to elements previously returned).\n */\n getSvgIconFromUrl(url: string): Observable<SVGElement> {\n if (this._cachedIconsByUrl.has(url)) {\n return Observable.of(cloneSvg(this._cachedIconsByUrl.get(url)));\n }\n return this._loadSvgIconFromConfig(new SvgIconConfig(url))\n .do(svg => this._cachedIconsByUrl.set(url, svg))\n .map(svg => cloneSvg(svg));\n }\n\n /**\n * Returns an Observable that produces the icon (as an <svg> DOM element) with the given name\n * and namespace. The icon must have been previously registered with addIcon or addIconSet;\n * if not, the Observable will throw an MdIconNameNotFoundError.\n */\n getNamedSvgIcon(name: string, namespace = ''): Observable<SVGElement> {\n // Return (copy of) cached icon if possible.\n const key = iconKey(namespace, name);\n if (this._svgIconConfigs.has(key)) {\n return this._getSvgFromConfig(this._svgIconConfigs.get(key));\n }\n // See if we have any icon sets registered for the namespace.\n const iconSetConfigs = this._iconSetConfigs.get(namespace);\n if (iconSetConfigs) {\n return this._getSvgFromIconSetConfigs(name, iconSetConfigs);\n }\n return Observable.throw(new MdIconNameNotFoundError(key));\n }\n\n /**\n * Returns the cached icon for a SvgIconConfig if available, or fetches it from its URL if not.\n */\n private _getSvgFromConfig(config: SvgIconConfig): Observable<SVGElement> {\n if (config.svgElement) {\n // We already have the SVG element for this icon, return a copy.\n return Observable.of(cloneSvg(config.svgElement));\n } else {\n // Fetch the icon from the config's URL, cache it, and return a copy.\n return this._loadSvgIconFromConfig(config)\n .do(svg => config.svgElement = svg)\n .map(svg => cloneSvg(svg));\n }\n }\n\n /**\n * Attempts to find an icon with the specified name in any of the SVG icon sets.\n * First searches the available cached icons for a nested element with a matching name, and\n * if found copies the element to a new <svg> element. If not found, fetches all icon sets\n * that have not been cached, and searches again after all fetches are completed.\n * The returned Observable produces the SVG element if possible, and throws\n * MdIconNameNotFoundError if no icon with the specified name can be found.\n */\n private _getSvgFromIconSetConfigs(name: string, iconSetConfigs: SvgIconConfig[]):\n Observable<SVGElement> {\n // For all the icon set SVG elements we've fetched, see if any contain an icon with the\n // requested name.\n const namedIcon = this._extractIconWithNameFromAnySet(name, iconSetConfigs);\n if (namedIcon) {\n // We could cache namedIcon in _svgIconConfigs, but since we have to make a copy every\n // time anyway, there's probably not much advantage compared to just always extracting\n // it from the icon set.\n return Observable.of(namedIcon);\n }\n // Not found in any cached icon sets. If there are icon sets with URLs that we haven't\n // fetched, fetch them now and look for iconName in the results.\n const iconSetFetchRequests: Observable<SVGElement>[] = iconSetConfigs\n .filter(iconSetConfig => !iconSetConfig.svgElement)\n .map(iconSetConfig =>\n this._loadSvgIconSetFromConfig(iconSetConfig)\n .catch((err: any, caught: Observable<SVGElement>): Observable<SVGElement> => {\n // Swallow errors fetching individual URLs so the combined Observable won't\n // necessarily fail.\n console.log(`Loading icon set URL: ${iconSetConfig.url} failed: ${err}`);\n return Observable.of(null);\n })\n .do(svg => {\n // Cache SVG element.\n if (svg) {\n iconSetConfig.svgElement = svg;\n }\n }));\n // Fetch all the icon set URLs. When the requests complete, every IconSet should have a\n // cached SVG element (unless the request failed), and we can check again for the icon.\n return Observable.forkJoin(iconSetFetchRequests)\n .map((ignoredResults: any) => {\n const foundIcon = this._extractIconWithNameFromAnySet(name, iconSetConfigs);\n if (!foundIcon) {\n throw new MdIconNameNotFoundError(name);\n }\n return foundIcon;\n });\n }\n\n /**\n * Searches the cached SVG elements for the given icon sets for a nested icon element whose \"id\"\n * tag matches the specified name. If found, copies the nested element to a new SVG element and\n * returns it. Returns null if no matching element is found.\n */\n private _extractIconWithNameFromAnySet(iconName: string, iconSetConfigs: SvgIconConfig[]):\n SVGElement {\n // Iterate backwards, so icon sets added later have precedence.\n for (let i = iconSetConfigs.length - 1; i >= 0; i--) {\n const config = iconSetConfigs[i];\n if (config.svgElement) {\n const foundIcon = this._extractSvgIconFromSet(config.svgElement, iconName, config);\n if (foundIcon) {\n return foundIcon;\n }\n }\n }\n return null;\n }\n\n /**\n * Loads the content of the icon URL specified in the SvgIconConfig and creates an SVG element\n * from it.\n */\n private _loadSvgIconFromConfig(config: SvgIconConfig): Observable<SVGElement> {\n return this._fetchUrl(config.url)\n .map(svgText => this._createSvgElementForSingleIcon(svgText, config));\n }\n\n /**\n * Loads the content of the icon set URL specified in the SvgIconConfig and creates an SVG element\n * from it.\n */\n private _loadSvgIconSetFromConfig(config: SvgIconConfig): Observable<SVGElement> {\n // TODO: Document that icons should only be loaded from trusted sources.\n return this._fetchUrl(config.url)\n .map((svgText) => this._svgElementFromString(svgText));\n }\n\n /**\n * Creates a DOM element from the given SVG string, and adds default attributes.\n */\n private _createSvgElementForSingleIcon(responseText: string, config: SvgIconConfig): SVGElement {\n const svg = this._svgElementFromString(responseText);\n this._setSvgAttributes(svg, config);\n return svg;\n }\n\n /**\n * Searches the cached element of the given SvgIconConfig for a nested icon element whose \"id\"\n * tag matches the specified name. If found, copies the nested element to a new SVG element and\n * returns it. Returns null if no matching element is found.\n */\n private _extractSvgIconFromSet(\n iconSet: SVGElement, iconName: string, config: SvgIconConfig): SVGElement {\n const iconNode = iconSet.querySelector('#' + iconName);\n if (!iconNode) {\n return null;\n }\n // If the icon node is itself an <svg> node, clone and return it directly. If not, set it as\n // the content of a new <svg> node.\n if (iconNode.tagName.toLowerCase() == 'svg') {\n return this._setSvgAttributes(<SVGElement>iconNode.cloneNode(true), config);\n }\n // createElement('SVG') doesn't work as expected; the DOM ends up with\n // the correct nodes, but the SVG content doesn't render. Instead we\n // have to create an empty SVG node using innerHTML and append its content.\n // Elements created using DOMParser.parseFromString have the same problem.\n // http://stackoverflow.com/questions/23003278/svg-innerhtml-in-firefox-can-not-display\n const svg = this._svgElementFromString('<svg></svg>');\n // Clone the node so we don't remove it from the parent icon set element.\n svg.appendChild(iconNode.cloneNode(true));\n return this._setSvgAttributes(svg, config);\n }\n\n /**\n * Creates a DOM element from the given SVG string.\n */\n private _svgElementFromString(str: string): SVGElement {\n // TODO: Is there a better way than innerHTML? Renderer doesn't appear to have a method for\n // creating an element from an HTML string.\n const div = document.createElement('DIV');\n div.innerHTML = str;\n const svg = <SVGElement>div.querySelector('svg');\n if (!svg) {\n throw new MdIconSvgTagNotFoundError();\n }\n return svg;\n }\n\n /**\n * Sets the default attributes for an SVG element to be used as an icon.\n */\n private _setSvgAttributes(svg: SVGElement, config: SvgIconConfig): SVGElement {\n if (!svg.getAttribute('xmlns')) {\n svg.setAttribute('xmlns', 'http://www.w3.org/2000/svg');\n }\n svg.setAttribute('fit', '');\n svg.setAttribute('height', '100%');\n svg.setAttribute('width', '100%');\n svg.setAttribute('preserveAspectRatio', 'xMidYMid meet');\n svg.setAttribute('focusable', 'false'); // Disable IE11 default behavior to make SVGs focusable.\n return svg;\n }\n\n /**\n * Returns an Observable which produces the string contents of the given URL. Results may be\n * cached, so future calls with the same URL may not cause another HTTP request.\n */\n private _fetchUrl(url: string): Observable<string> {\n // Store in-progress fetches to avoid sending a duplicate request for a URL when there is\n // already a request in progress for that URL. It's necessary to call share() on the\n // Observable returned by http.get() so that multiple subscribers don't cause multiple XHRs.\n if (this._inProgressUrlFetches.has(url)) {\n return this._inProgressUrlFetches.get(url);\n }\n\n // TODO(jelbourn): for some reason, the `finally` operator \"loses\" the generic type on the\n // Observable. Figure out why and fix it.\n const req = <Observable<string>> this._http.get(url)\n .map(response => response.text())\n .finally(() => {\n this._inProgressUrlFetches.delete(url);\n })\n .share();\n this._inProgressUrlFetches.set(url, req);\n return req;\n }\n}\n\n\n/** Clones an SVGElement while preserving type information. */\nfunction cloneSvg(svg: SVGElement) {\n return <SVGElement> svg.cloneNode(true);\n}\n"],"sourceRoot":"/source/"}
\No newline at end of file