icon.js 45 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199
  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 { DOCUMENT } from '@angular/common';
  9. import { HttpClient } from '@angular/common/http';
  10. import { Inject, Injectable, Optional, SecurityContext, SkipSelf, NgModule, Attribute, ChangeDetectionStrategy, Component, ElementRef, Input, ViewEncapsulation, InjectionToken, inject, ɵɵdefineInjectable, ɵɵinject } from '@angular/core';
  11. import { DomSanitizer } from '@angular/platform-browser';
  12. import { forkJoin, of, throwError } from 'rxjs';
  13. import { catchError, finalize, map, share, tap, take } from 'rxjs/operators';
  14. import { mixinColor, MatCommonModule } from '@angular/material/core';
  15. import { coerceBooleanProperty } from '@angular/cdk/coercion';
  16. /**
  17. * @fileoverview added by tsickle
  18. * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  19. */
  20. /**
  21. * Returns an exception to be thrown in the case when attempting to
  22. * load an icon with a name that cannot be found.
  23. * \@docs-private
  24. * @param {?} iconName
  25. * @return {?}
  26. */
  27. function getMatIconNameNotFoundError(iconName) {
  28. return Error(`Unable to find icon with the name "${iconName}"`);
  29. }
  30. /**
  31. * Returns an exception to be thrown when the consumer attempts to use
  32. * `<mat-icon>` without including \@angular/common/http.
  33. * \@docs-private
  34. * @return {?}
  35. */
  36. function getMatIconNoHttpProviderError() {
  37. return Error('Could not find HttpClient provider for use with Angular Material icons. ' +
  38. 'Please include the HttpClientModule from @angular/common/http in your ' +
  39. 'app imports.');
  40. }
  41. /**
  42. * Returns an exception to be thrown when a URL couldn't be sanitized.
  43. * \@docs-private
  44. * @param {?} url URL that was attempted to be sanitized.
  45. * @return {?}
  46. */
  47. function getMatIconFailedToSanitizeUrlError(url) {
  48. return Error(`The URL provided to MatIconRegistry was not trusted as a resource URL ` +
  49. `via Angular's DomSanitizer. Attempted URL was "${url}".`);
  50. }
  51. /**
  52. * Returns an exception to be thrown when a HTML string couldn't be sanitized.
  53. * \@docs-private
  54. * @param {?} literal HTML that was attempted to be sanitized.
  55. * @return {?}
  56. */
  57. function getMatIconFailedToSanitizeLiteralError(literal) {
  58. return Error(`The literal provided to MatIconRegistry was not trusted as safe HTML by ` +
  59. `Angular's DomSanitizer. Attempted literal was "${literal}".`);
  60. }
  61. /**
  62. * Configuration for an icon, including the URL and possibly the cached SVG element.
  63. * \@docs-private
  64. */
  65. class SvgIconConfig {
  66. /**
  67. * @param {?} data
  68. */
  69. constructor(data) {
  70. // Note that we can't use `instanceof SVGElement` here,
  71. // because it'll break during server-side rendering.
  72. if (!!((/** @type {?} */ (data))).nodeName) {
  73. this.svgElement = (/** @type {?} */ (data));
  74. }
  75. else {
  76. this.url = (/** @type {?} */ (data));
  77. }
  78. }
  79. }
  80. /**
  81. * Service to register and display icons used by the `<mat-icon>` component.
  82. * - Registers icon URLs by namespace and name.
  83. * - Registers icon set URLs by namespace.
  84. * - Registers aliases for CSS classes, for use with icon fonts.
  85. * - Loads icons from URLs and extracts individual icons from icon sets.
  86. */
  87. class MatIconRegistry {
  88. /**
  89. * @param {?} _httpClient
  90. * @param {?} _sanitizer
  91. * @param {?} document
  92. */
  93. constructor(_httpClient, _sanitizer, document) {
  94. this._httpClient = _httpClient;
  95. this._sanitizer = _sanitizer;
  96. /**
  97. * URLs and cached SVG elements for individual icons. Keys are of the format "[namespace]:[icon]".
  98. */
  99. this._svgIconConfigs = new Map();
  100. /**
  101. * SvgIconConfig objects and cached SVG elements for icon sets, keyed by namespace.
  102. * Multiple icon sets can be registered under the same namespace.
  103. */
  104. this._iconSetConfigs = new Map();
  105. /**
  106. * Cache for icons loaded by direct URLs.
  107. */
  108. this._cachedIconsByUrl = new Map();
  109. /**
  110. * In-progress icon fetches. Used to coalesce multiple requests to the same URL.
  111. */
  112. this._inProgressUrlFetches = new Map();
  113. /**
  114. * Map from font identifiers to their CSS class names. Used for icon fonts.
  115. */
  116. this._fontCssClassesByAlias = new Map();
  117. /**
  118. * The CSS class to apply when an `<mat-icon>` component has no icon name, url, or font specified.
  119. * The default 'material-icons' value assumes that the material icon font has been loaded as
  120. * described at http://google.github.io/material-design-icons/#icon-font-for-the-web
  121. */
  122. this._defaultFontSetClass = 'material-icons';
  123. this._document = document;
  124. }
  125. /**
  126. * Registers an icon by URL in the default namespace.
  127. * @template THIS
  128. * @this {THIS}
  129. * @param {?} iconName Name under which the icon should be registered.
  130. * @param {?} url
  131. * @return {THIS}
  132. */
  133. addSvgIcon(iconName, url) {
  134. return (/** @type {?} */ (this)).addSvgIconInNamespace('', iconName, url);
  135. }
  136. /**
  137. * Registers an icon using an HTML string in the default namespace.
  138. * @template THIS
  139. * @this {THIS}
  140. * @param {?} iconName Name under which the icon should be registered.
  141. * @param {?} literal SVG source of the icon.
  142. * @return {THIS}
  143. */
  144. addSvgIconLiteral(iconName, literal) {
  145. return (/** @type {?} */ (this)).addSvgIconLiteralInNamespace('', iconName, literal);
  146. }
  147. /**
  148. * Registers an icon by URL in the specified namespace.
  149. * @template THIS
  150. * @this {THIS}
  151. * @param {?} namespace Namespace in which the icon should be registered.
  152. * @param {?} iconName Name under which the icon should be registered.
  153. * @param {?} url
  154. * @return {THIS}
  155. */
  156. addSvgIconInNamespace(namespace, iconName, url) {
  157. return (/** @type {?} */ (this))._addSvgIconConfig(namespace, iconName, new SvgIconConfig(url));
  158. }
  159. /**
  160. * Registers an icon using an HTML string in the specified namespace.
  161. * @template THIS
  162. * @this {THIS}
  163. * @param {?} namespace Namespace in which the icon should be registered.
  164. * @param {?} iconName Name under which the icon should be registered.
  165. * @param {?} literal SVG source of the icon.
  166. * @return {THIS}
  167. */
  168. addSvgIconLiteralInNamespace(namespace, iconName, literal) {
  169. /** @type {?} */
  170. const sanitizedLiteral = (/** @type {?} */ (this))._sanitizer.sanitize(SecurityContext.HTML, literal);
  171. if (!sanitizedLiteral) {
  172. throw getMatIconFailedToSanitizeLiteralError(literal);
  173. }
  174. /** @type {?} */
  175. const svgElement = (/** @type {?} */ (this))._createSvgElementForSingleIcon(sanitizedLiteral);
  176. return (/** @type {?} */ (this))._addSvgIconConfig(namespace, iconName, new SvgIconConfig(svgElement));
  177. }
  178. /**
  179. * Registers an icon set by URL in the default namespace.
  180. * @template THIS
  181. * @this {THIS}
  182. * @param {?} url
  183. * @return {THIS}
  184. */
  185. addSvgIconSet(url) {
  186. return (/** @type {?} */ (this)).addSvgIconSetInNamespace('', url);
  187. }
  188. /**
  189. * Registers an icon set using an HTML string in the default namespace.
  190. * @template THIS
  191. * @this {THIS}
  192. * @param {?} literal SVG source of the icon set.
  193. * @return {THIS}
  194. */
  195. addSvgIconSetLiteral(literal) {
  196. return (/** @type {?} */ (this)).addSvgIconSetLiteralInNamespace('', literal);
  197. }
  198. /**
  199. * Registers an icon set by URL in the specified namespace.
  200. * @template THIS
  201. * @this {THIS}
  202. * @param {?} namespace Namespace in which to register the icon set.
  203. * @param {?} url
  204. * @return {THIS}
  205. */
  206. addSvgIconSetInNamespace(namespace, url) {
  207. return (/** @type {?} */ (this))._addSvgIconSetConfig(namespace, new SvgIconConfig(url));
  208. }
  209. /**
  210. * Registers an icon set using an HTML string in the specified namespace.
  211. * @template THIS
  212. * @this {THIS}
  213. * @param {?} namespace Namespace in which to register the icon set.
  214. * @param {?} literal SVG source of the icon set.
  215. * @return {THIS}
  216. */
  217. addSvgIconSetLiteralInNamespace(namespace, literal) {
  218. /** @type {?} */
  219. const sanitizedLiteral = (/** @type {?} */ (this))._sanitizer.sanitize(SecurityContext.HTML, literal);
  220. if (!sanitizedLiteral) {
  221. throw getMatIconFailedToSanitizeLiteralError(literal);
  222. }
  223. /** @type {?} */
  224. const svgElement = (/** @type {?} */ (this))._svgElementFromString(sanitizedLiteral);
  225. return (/** @type {?} */ (this))._addSvgIconSetConfig(namespace, new SvgIconConfig(svgElement));
  226. }
  227. /**
  228. * Defines an alias for a CSS class name to be used for icon fonts. Creating an matIcon
  229. * component with the alias as the fontSet input will cause the class name to be applied
  230. * to the `<mat-icon>` element.
  231. *
  232. * @template THIS
  233. * @this {THIS}
  234. * @param {?} alias Alias for the font.
  235. * @param {?=} className Class name override to be used instead of the alias.
  236. * @return {THIS}
  237. */
  238. registerFontClassAlias(alias, className = alias) {
  239. (/** @type {?} */ (this))._fontCssClassesByAlias.set(alias, className);
  240. return (/** @type {?} */ (this));
  241. }
  242. /**
  243. * Returns the CSS class name associated with the alias by a previous call to
  244. * registerFontClassAlias. If no CSS class has been associated, returns the alias unmodified.
  245. * @param {?} alias
  246. * @return {?}
  247. */
  248. classNameForFontAlias(alias) {
  249. return this._fontCssClassesByAlias.get(alias) || alias;
  250. }
  251. /**
  252. * Sets the CSS class name to be used for icon fonts when an `<mat-icon>` component does not
  253. * have a fontSet input value, and is not loading an icon by name or URL.
  254. *
  255. * @template THIS
  256. * @this {THIS}
  257. * @param {?} className
  258. * @return {THIS}
  259. */
  260. setDefaultFontSetClass(className) {
  261. (/** @type {?} */ (this))._defaultFontSetClass = className;
  262. return (/** @type {?} */ (this));
  263. }
  264. /**
  265. * Returns the CSS class name to be used for icon fonts when an `<mat-icon>` component does not
  266. * have a fontSet input value, and is not loading an icon by name or URL.
  267. * @return {?}
  268. */
  269. getDefaultFontSetClass() {
  270. return this._defaultFontSetClass;
  271. }
  272. /**
  273. * Returns an Observable that produces the icon (as an `<svg>` DOM element) from the given URL.
  274. * The response from the URL may be cached so this will not always cause an HTTP request, but
  275. * the produced element will always be a new copy of the originally fetched icon. (That is,
  276. * it will not contain any modifications made to elements previously returned).
  277. *
  278. * @param {?} safeUrl URL from which to fetch the SVG icon.
  279. * @return {?}
  280. */
  281. getSvgIconFromUrl(safeUrl) {
  282. /** @type {?} */
  283. const url = this._sanitizer.sanitize(SecurityContext.RESOURCE_URL, safeUrl);
  284. if (!url) {
  285. throw getMatIconFailedToSanitizeUrlError(safeUrl);
  286. }
  287. /** @type {?} */
  288. const cachedIcon = this._cachedIconsByUrl.get(url);
  289. if (cachedIcon) {
  290. return of(cloneSvg(cachedIcon));
  291. }
  292. return this._loadSvgIconFromConfig(new SvgIconConfig(safeUrl)).pipe(tap((/**
  293. * @param {?} svg
  294. * @return {?}
  295. */
  296. svg => this._cachedIconsByUrl.set((/** @type {?} */ (url)), svg))), map((/**
  297. * @param {?} svg
  298. * @return {?}
  299. */
  300. svg => cloneSvg(svg))));
  301. }
  302. /**
  303. * Returns an Observable that produces the icon (as an `<svg>` DOM element) with the given name
  304. * and namespace. The icon must have been previously registered with addIcon or addIconSet;
  305. * if not, the Observable will throw an error.
  306. *
  307. * @param {?} name Name of the icon to be retrieved.
  308. * @param {?=} namespace Namespace in which to look for the icon.
  309. * @return {?}
  310. */
  311. getNamedSvgIcon(name, namespace = '') {
  312. // Return (copy of) cached icon if possible.
  313. /** @type {?} */
  314. const key = iconKey(namespace, name);
  315. /** @type {?} */
  316. const config = this._svgIconConfigs.get(key);
  317. if (config) {
  318. return this._getSvgFromConfig(config);
  319. }
  320. // See if we have any icon sets registered for the namespace.
  321. /** @type {?} */
  322. const iconSetConfigs = this._iconSetConfigs.get(namespace);
  323. if (iconSetConfigs) {
  324. return this._getSvgFromIconSetConfigs(name, iconSetConfigs);
  325. }
  326. return throwError(getMatIconNameNotFoundError(key));
  327. }
  328. /**
  329. * @return {?}
  330. */
  331. ngOnDestroy() {
  332. this._svgIconConfigs.clear();
  333. this._iconSetConfigs.clear();
  334. this._cachedIconsByUrl.clear();
  335. }
  336. /**
  337. * Returns the cached icon for a SvgIconConfig if available, or fetches it from its URL if not.
  338. * @private
  339. * @param {?} config
  340. * @return {?}
  341. */
  342. _getSvgFromConfig(config) {
  343. if (config.svgElement) {
  344. // We already have the SVG element for this icon, return a copy.
  345. return of(cloneSvg(config.svgElement));
  346. }
  347. else {
  348. // Fetch the icon from the config's URL, cache it, and return a copy.
  349. return this._loadSvgIconFromConfig(config).pipe(tap((/**
  350. * @param {?} svg
  351. * @return {?}
  352. */
  353. svg => config.svgElement = svg)), map((/**
  354. * @param {?} svg
  355. * @return {?}
  356. */
  357. svg => cloneSvg(svg))));
  358. }
  359. }
  360. /**
  361. * Attempts to find an icon with the specified name in any of the SVG icon sets.
  362. * First searches the available cached icons for a nested element with a matching name, and
  363. * if found copies the element to a new `<svg>` element. If not found, fetches all icon sets
  364. * that have not been cached, and searches again after all fetches are completed.
  365. * The returned Observable produces the SVG element if possible, and throws
  366. * an error if no icon with the specified name can be found.
  367. * @private
  368. * @param {?} name
  369. * @param {?} iconSetConfigs
  370. * @return {?}
  371. */
  372. _getSvgFromIconSetConfigs(name, iconSetConfigs) {
  373. // For all the icon set SVG elements we've fetched, see if any contain an icon with the
  374. // requested name.
  375. /** @type {?} */
  376. const namedIcon = this._extractIconWithNameFromAnySet(name, iconSetConfigs);
  377. if (namedIcon) {
  378. // We could cache namedIcon in _svgIconConfigs, but since we have to make a copy every
  379. // time anyway, there's probably not much advantage compared to just always extracting
  380. // it from the icon set.
  381. return of(namedIcon);
  382. }
  383. // Not found in any cached icon sets. If there are icon sets with URLs that we haven't
  384. // fetched, fetch them now and look for iconName in the results.
  385. /** @type {?} */
  386. const iconSetFetchRequests = iconSetConfigs
  387. .filter((/**
  388. * @param {?} iconSetConfig
  389. * @return {?}
  390. */
  391. iconSetConfig => !iconSetConfig.svgElement))
  392. .map((/**
  393. * @param {?} iconSetConfig
  394. * @return {?}
  395. */
  396. iconSetConfig => {
  397. return this._loadSvgIconSetFromConfig(iconSetConfig).pipe(catchError((/**
  398. * @param {?} err
  399. * @return {?}
  400. */
  401. (err) => {
  402. /** @type {?} */
  403. const url = this._sanitizer.sanitize(SecurityContext.RESOURCE_URL, iconSetConfig.url);
  404. // Swallow errors fetching individual URLs so the
  405. // combined Observable won't necessarily fail.
  406. console.error(`Loading icon set URL: ${url} failed: ${err.message}`);
  407. return of(null);
  408. })));
  409. }));
  410. // Fetch all the icon set URLs. When the requests complete, every IconSet should have a
  411. // cached SVG element (unless the request failed), and we can check again for the icon.
  412. return forkJoin(iconSetFetchRequests).pipe(map((/**
  413. * @return {?}
  414. */
  415. () => {
  416. /** @type {?} */
  417. const foundIcon = this._extractIconWithNameFromAnySet(name, iconSetConfigs);
  418. if (!foundIcon) {
  419. throw getMatIconNameNotFoundError(name);
  420. }
  421. return foundIcon;
  422. })));
  423. }
  424. /**
  425. * Searches the cached SVG elements for the given icon sets for a nested icon element whose "id"
  426. * tag matches the specified name. If found, copies the nested element to a new SVG element and
  427. * returns it. Returns null if no matching element is found.
  428. * @private
  429. * @param {?} iconName
  430. * @param {?} iconSetConfigs
  431. * @return {?}
  432. */
  433. _extractIconWithNameFromAnySet(iconName, iconSetConfigs) {
  434. // Iterate backwards, so icon sets added later have precedence.
  435. for (let i = iconSetConfigs.length - 1; i >= 0; i--) {
  436. /** @type {?} */
  437. const config = iconSetConfigs[i];
  438. if (config.svgElement) {
  439. /** @type {?} */
  440. const foundIcon = this._extractSvgIconFromSet(config.svgElement, iconName);
  441. if (foundIcon) {
  442. return foundIcon;
  443. }
  444. }
  445. }
  446. return null;
  447. }
  448. /**
  449. * Loads the content of the icon URL specified in the SvgIconConfig and creates an SVG element
  450. * from it.
  451. * @private
  452. * @param {?} config
  453. * @return {?}
  454. */
  455. _loadSvgIconFromConfig(config) {
  456. return this._fetchUrl(config.url)
  457. .pipe(map((/**
  458. * @param {?} svgText
  459. * @return {?}
  460. */
  461. svgText => this._createSvgElementForSingleIcon(svgText))));
  462. }
  463. /**
  464. * Loads the content of the icon set URL specified in the SvgIconConfig and creates an SVG element
  465. * from it.
  466. * @private
  467. * @param {?} config
  468. * @return {?}
  469. */
  470. _loadSvgIconSetFromConfig(config) {
  471. // If the SVG for this icon set has already been parsed, do nothing.
  472. if (config.svgElement) {
  473. return of(config.svgElement);
  474. }
  475. return this._fetchUrl(config.url).pipe(map((/**
  476. * @param {?} svgText
  477. * @return {?}
  478. */
  479. svgText => {
  480. // It is possible that the icon set was parsed and cached by an earlier request, so parsing
  481. // only needs to occur if the cache is yet unset.
  482. if (!config.svgElement) {
  483. config.svgElement = this._svgElementFromString(svgText);
  484. }
  485. return config.svgElement;
  486. })));
  487. }
  488. /**
  489. * Creates a DOM element from the given SVG string, and adds default attributes.
  490. * @private
  491. * @param {?} responseText
  492. * @return {?}
  493. */
  494. _createSvgElementForSingleIcon(responseText) {
  495. /** @type {?} */
  496. const svg = this._svgElementFromString(responseText);
  497. this._setSvgAttributes(svg);
  498. return svg;
  499. }
  500. /**
  501. * Searches the cached element of the given SvgIconConfig for a nested icon element whose "id"
  502. * tag matches the specified name. If found, copies the nested element to a new SVG element and
  503. * returns it. Returns null if no matching element is found.
  504. * @private
  505. * @param {?} iconSet
  506. * @param {?} iconName
  507. * @return {?}
  508. */
  509. _extractSvgIconFromSet(iconSet, iconName) {
  510. // Use the `id="iconName"` syntax in order to escape special
  511. // characters in the ID (versus using the #iconName syntax).
  512. /** @type {?} */
  513. const iconSource = iconSet.querySelector(`[id="${iconName}"]`);
  514. if (!iconSource) {
  515. return null;
  516. }
  517. // Clone the element and remove the ID to prevent multiple elements from being added
  518. // to the page with the same ID.
  519. /** @type {?} */
  520. const iconElement = (/** @type {?} */ (iconSource.cloneNode(true)));
  521. iconElement.removeAttribute('id');
  522. // If the icon node is itself an <svg> node, clone and return it directly. If not, set it as
  523. // the content of a new <svg> node.
  524. if (iconElement.nodeName.toLowerCase() === 'svg') {
  525. return this._setSvgAttributes((/** @type {?} */ (iconElement)));
  526. }
  527. // If the node is a <symbol>, it won't be rendered so we have to convert it into <svg>. Note
  528. // that the same could be achieved by referring to it via <use href="#id">, however the <use>
  529. // tag is problematic on Firefox, because it needs to include the current page path.
  530. if (iconElement.nodeName.toLowerCase() === 'symbol') {
  531. return this._setSvgAttributes(this._toSvgElement(iconElement));
  532. }
  533. // createElement('SVG') doesn't work as expected; the DOM ends up with
  534. // the correct nodes, but the SVG content doesn't render. Instead we
  535. // have to create an empty SVG node using innerHTML and append its content.
  536. // Elements created using DOMParser.parseFromString have the same problem.
  537. // http://stackoverflow.com/questions/23003278/svg-innerhtml-in-firefox-can-not-display
  538. /** @type {?} */
  539. const svg = this._svgElementFromString('<svg></svg>');
  540. // Clone the node so we don't remove it from the parent icon set element.
  541. svg.appendChild(iconElement);
  542. return this._setSvgAttributes(svg);
  543. }
  544. /**
  545. * Creates a DOM element from the given SVG string.
  546. * @private
  547. * @param {?} str
  548. * @return {?}
  549. */
  550. _svgElementFromString(str) {
  551. /** @type {?} */
  552. const div = this._document.createElement('DIV');
  553. div.innerHTML = str;
  554. /** @type {?} */
  555. const svg = (/** @type {?} */ (div.querySelector('svg')));
  556. if (!svg) {
  557. throw Error('<svg> tag not found');
  558. }
  559. return svg;
  560. }
  561. /**
  562. * Converts an element into an SVG node by cloning all of its children.
  563. * @private
  564. * @param {?} element
  565. * @return {?}
  566. */
  567. _toSvgElement(element) {
  568. /** @type {?} */
  569. let svg = this._svgElementFromString('<svg></svg>');
  570. for (let i = 0; i < element.childNodes.length; i++) {
  571. if (element.childNodes[i].nodeType === this._document.ELEMENT_NODE) {
  572. svg.appendChild(element.childNodes[i].cloneNode(true));
  573. }
  574. }
  575. return svg;
  576. }
  577. /**
  578. * Sets the default attributes for an SVG element to be used as an icon.
  579. * @private
  580. * @param {?} svg
  581. * @return {?}
  582. */
  583. _setSvgAttributes(svg) {
  584. svg.setAttribute('fit', '');
  585. svg.setAttribute('height', '100%');
  586. svg.setAttribute('width', '100%');
  587. svg.setAttribute('preserveAspectRatio', 'xMidYMid meet');
  588. svg.setAttribute('focusable', 'false'); // Disable IE11 default behavior to make SVGs focusable.
  589. return svg;
  590. }
  591. /**
  592. * Returns an Observable which produces the string contents of the given URL. Results may be
  593. * cached, so future calls with the same URL may not cause another HTTP request.
  594. * @private
  595. * @param {?} safeUrl
  596. * @return {?}
  597. */
  598. _fetchUrl(safeUrl) {
  599. if (!this._httpClient) {
  600. throw getMatIconNoHttpProviderError();
  601. }
  602. if (safeUrl == null) {
  603. throw Error(`Cannot fetch icon from URL "${safeUrl}".`);
  604. }
  605. /** @type {?} */
  606. const url = this._sanitizer.sanitize(SecurityContext.RESOURCE_URL, safeUrl);
  607. if (!url) {
  608. throw getMatIconFailedToSanitizeUrlError(safeUrl);
  609. }
  610. // Store in-progress fetches to avoid sending a duplicate request for a URL when there is
  611. // already a request in progress for that URL. It's necessary to call share() on the
  612. // Observable returned by http.get() so that multiple subscribers don't cause multiple XHRs.
  613. /** @type {?} */
  614. const inProgressFetch = this._inProgressUrlFetches.get(url);
  615. if (inProgressFetch) {
  616. return inProgressFetch;
  617. }
  618. // TODO(jelbourn): for some reason, the `finalize` operator "loses" the generic type on the
  619. // Observable. Figure out why and fix it.
  620. /** @type {?} */
  621. const req = this._httpClient.get(url, { responseType: 'text' }).pipe(finalize((/**
  622. * @return {?}
  623. */
  624. () => this._inProgressUrlFetches.delete(url))), share());
  625. this._inProgressUrlFetches.set(url, req);
  626. return req;
  627. }
  628. /**
  629. * Registers an icon config by name in the specified namespace.
  630. * @private
  631. * @template THIS
  632. * @this {THIS}
  633. * @param {?} namespace Namespace in which to register the icon config.
  634. * @param {?} iconName Name under which to register the config.
  635. * @param {?} config Config to be registered.
  636. * @return {THIS}
  637. */
  638. _addSvgIconConfig(namespace, iconName, config) {
  639. (/** @type {?} */ (this))._svgIconConfigs.set(iconKey(namespace, iconName), config);
  640. return (/** @type {?} */ (this));
  641. }
  642. /**
  643. * Registers an icon set config in the specified namespace.
  644. * @private
  645. * @template THIS
  646. * @this {THIS}
  647. * @param {?} namespace Namespace in which to register the icon config.
  648. * @param {?} config Config to be registered.
  649. * @return {THIS}
  650. */
  651. _addSvgIconSetConfig(namespace, config) {
  652. /** @type {?} */
  653. const configNamespace = (/** @type {?} */ (this))._iconSetConfigs.get(namespace);
  654. if (configNamespace) {
  655. configNamespace.push(config);
  656. }
  657. else {
  658. (/** @type {?} */ (this))._iconSetConfigs.set(namespace, [config]);
  659. }
  660. return (/** @type {?} */ (this));
  661. }
  662. }
  663. MatIconRegistry.decorators = [
  664. { type: Injectable, args: [{ providedIn: 'root' },] },
  665. ];
  666. /** @nocollapse */
  667. MatIconRegistry.ctorParameters = () => [
  668. { type: HttpClient, decorators: [{ type: Optional }] },
  669. { type: DomSanitizer },
  670. { type: undefined, decorators: [{ type: Optional }, { type: Inject, args: [DOCUMENT,] }] }
  671. ];
  672. /** @nocollapse */ MatIconRegistry.ngInjectableDef = ɵɵdefineInjectable({ factory: function MatIconRegistry_Factory() { return new MatIconRegistry(ɵɵinject(HttpClient, 8), ɵɵinject(DomSanitizer), ɵɵinject(DOCUMENT, 8)); }, token: MatIconRegistry, providedIn: "root" });
  673. /**
  674. * \@docs-private
  675. * @param {?} parentRegistry
  676. * @param {?} httpClient
  677. * @param {?} sanitizer
  678. * @param {?=} document
  679. * @return {?}
  680. */
  681. function ICON_REGISTRY_PROVIDER_FACTORY(parentRegistry, httpClient, sanitizer, document) {
  682. return parentRegistry || new MatIconRegistry(httpClient, sanitizer, document);
  683. }
  684. /**
  685. * \@docs-private
  686. * @type {?}
  687. */
  688. const ICON_REGISTRY_PROVIDER = {
  689. // If there is already an MatIconRegistry available, use that. Otherwise, provide a new one.
  690. provide: MatIconRegistry,
  691. deps: [
  692. [new Optional(), new SkipSelf(), MatIconRegistry],
  693. [new Optional(), HttpClient],
  694. DomSanitizer,
  695. [new Optional(), (/** @type {?} */ (DOCUMENT))],
  696. ],
  697. useFactory: ICON_REGISTRY_PROVIDER_FACTORY,
  698. };
  699. /**
  700. * Clones an SVGElement while preserving type information.
  701. * @param {?} svg
  702. * @return {?}
  703. */
  704. function cloneSvg(svg) {
  705. return (/** @type {?} */ (svg.cloneNode(true)));
  706. }
  707. /**
  708. * Returns the cache key to use for an icon namespace and name.
  709. * @param {?} namespace
  710. * @param {?} name
  711. * @return {?}
  712. */
  713. function iconKey(namespace, name) {
  714. return namespace + ':' + name;
  715. }
  716. /**
  717. * @fileoverview added by tsickle
  718. * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  719. */
  720. // Boilerplate for applying mixins to MatIcon.
  721. /**
  722. * \@docs-private
  723. */
  724. class MatIconBase {
  725. /**
  726. * @param {?} _elementRef
  727. */
  728. constructor(_elementRef) {
  729. this._elementRef = _elementRef;
  730. }
  731. }
  732. /** @type {?} */
  733. const _MatIconMixinBase = mixinColor(MatIconBase);
  734. /**
  735. * Injection token used to provide the current location to `MatIcon`.
  736. * Used to handle server-side rendering and to stub out during unit tests.
  737. * \@docs-private
  738. * @type {?}
  739. */
  740. const MAT_ICON_LOCATION = new InjectionToken('mat-icon-location', {
  741. providedIn: 'root',
  742. factory: MAT_ICON_LOCATION_FACTORY
  743. });
  744. /**
  745. * \@docs-private
  746. * @return {?}
  747. */
  748. function MAT_ICON_LOCATION_FACTORY() {
  749. /** @type {?} */
  750. const _document = inject(DOCUMENT);
  751. /** @type {?} */
  752. const _location = _document ? _document.location : null;
  753. return {
  754. // Note that this needs to be a function, rather than a property, because Angular
  755. // will only resolve it once, but we want the current path on each call.
  756. getPathname: (/**
  757. * @return {?}
  758. */
  759. () => _location ? (_location.pathname + _location.search) : '')
  760. };
  761. }
  762. /**
  763. * SVG attributes that accept a FuncIRI (e.g. `url(<something>)`).
  764. * @type {?}
  765. */
  766. const funcIriAttributes = [
  767. 'clip-path',
  768. 'color-profile',
  769. 'src',
  770. 'cursor',
  771. 'fill',
  772. 'filter',
  773. 'marker',
  774. 'marker-start',
  775. 'marker-mid',
  776. 'marker-end',
  777. 'mask',
  778. 'stroke'
  779. ];
  780. const ɵ0 = /**
  781. * @param {?} attr
  782. * @return {?}
  783. */
  784. attr => `[${attr}]`;
  785. /**
  786. * Selector that can be used to find all elements that are using a `FuncIRI`.
  787. * @type {?}
  788. */
  789. const funcIriAttributeSelector = funcIriAttributes.map((ɵ0)).join(', ');
  790. /**
  791. * Regex that can be used to extract the id out of a FuncIRI.
  792. * @type {?}
  793. */
  794. const funcIriPattern = /^url\(['"]?#(.*?)['"]?\)$/;
  795. /**
  796. * Component to display an icon. It can be used in the following ways:
  797. *
  798. * - Specify the svgIcon input to load an SVG icon from a URL previously registered with the
  799. * addSvgIcon, addSvgIconInNamespace, addSvgIconSet, or addSvgIconSetInNamespace methods of
  800. * MatIconRegistry. If the svgIcon value contains a colon it is assumed to be in the format
  801. * "[namespace]:[name]", if not the value will be the name of an icon in the default namespace.
  802. * Examples:
  803. * `<mat-icon svgIcon="left-arrow"></mat-icon>
  804. * <mat-icon svgIcon="animals:cat"></mat-icon>`
  805. *
  806. * - Use a font ligature as an icon by putting the ligature text in the content of the `<mat-icon>`
  807. * component. By default the Material icons font is used as described at
  808. * http://google.github.io/material-design-icons/#icon-font-for-the-web. You can specify an
  809. * alternate font by setting the fontSet input to either the CSS class to apply to use the
  810. * desired font, or to an alias previously registered with MatIconRegistry.registerFontClassAlias.
  811. * Examples:
  812. * `<mat-icon>home</mat-icon>
  813. * <mat-icon fontSet="myfont">sun</mat-icon>`
  814. *
  815. * - Specify a font glyph to be included via CSS rules by setting the fontSet input to specify the
  816. * font, and the fontIcon input to specify the icon. Typically the fontIcon will specify a
  817. * CSS class which causes the glyph to be displayed via a :before selector, as in
  818. * https://fortawesome.github.io/Font-Awesome/examples/
  819. * Example:
  820. * `<mat-icon fontSet="fa" fontIcon="alarm"></mat-icon>`
  821. */
  822. class MatIcon extends _MatIconMixinBase {
  823. /**
  824. * @param {?} elementRef
  825. * @param {?} _iconRegistry
  826. * @param {?} ariaHidden
  827. * @param {?=} _location
  828. */
  829. constructor(elementRef, _iconRegistry, ariaHidden, _location) {
  830. super(elementRef);
  831. this._iconRegistry = _iconRegistry;
  832. this._location = _location;
  833. this._inline = false;
  834. // If the user has not explicitly set aria-hidden, mark the icon as hidden, as this is
  835. // the right thing to do for the majority of icon use-cases.
  836. if (!ariaHidden) {
  837. elementRef.nativeElement.setAttribute('aria-hidden', 'true');
  838. }
  839. }
  840. /**
  841. * Whether the icon should be inlined, automatically sizing the icon to match the font size of
  842. * the element the icon is contained in.
  843. * @return {?}
  844. */
  845. get inline() {
  846. return this._inline;
  847. }
  848. /**
  849. * @param {?} inline
  850. * @return {?}
  851. */
  852. set inline(inline) {
  853. this._inline = coerceBooleanProperty(inline);
  854. }
  855. /**
  856. * Font set that the icon is a part of.
  857. * @return {?}
  858. */
  859. get fontSet() { return this._fontSet; }
  860. /**
  861. * @param {?} value
  862. * @return {?}
  863. */
  864. set fontSet(value) {
  865. this._fontSet = this._cleanupFontValue(value);
  866. }
  867. /**
  868. * Name of an icon within a font set.
  869. * @return {?}
  870. */
  871. get fontIcon() { return this._fontIcon; }
  872. /**
  873. * @param {?} value
  874. * @return {?}
  875. */
  876. set fontIcon(value) {
  877. this._fontIcon = this._cleanupFontValue(value);
  878. }
  879. /**
  880. * Splits an svgIcon binding value into its icon set and icon name components.
  881. * Returns a 2-element array of [(icon set), (icon name)].
  882. * The separator for the two fields is ':'. If there is no separator, an empty
  883. * string is returned for the icon set and the entire value is returned for
  884. * the icon name. If the argument is falsy, returns an array of two empty strings.
  885. * Throws an error if the name contains two or more ':' separators.
  886. * Examples:
  887. * `'social:cake' -> ['social', 'cake']
  888. * 'penguin' -> ['', 'penguin']
  889. * null -> ['', '']
  890. * 'a:b:c' -> (throws Error)`
  891. * @private
  892. * @param {?} iconName
  893. * @return {?}
  894. */
  895. _splitIconName(iconName) {
  896. if (!iconName) {
  897. return ['', ''];
  898. }
  899. /** @type {?} */
  900. const parts = iconName.split(':');
  901. switch (parts.length) {
  902. case 1: return ['', parts[0]]; // Use default namespace.
  903. case 2: return (/** @type {?} */ (parts));
  904. default: throw Error(`Invalid icon name: "${iconName}"`);
  905. }
  906. }
  907. /**
  908. * @param {?} changes
  909. * @return {?}
  910. */
  911. ngOnChanges(changes) {
  912. // Only update the inline SVG icon if the inputs changed, to avoid unnecessary DOM operations.
  913. /** @type {?} */
  914. const svgIconChanges = changes['svgIcon'];
  915. if (svgIconChanges) {
  916. if (this.svgIcon) {
  917. const [namespace, iconName] = this._splitIconName(this.svgIcon);
  918. this._iconRegistry.getNamedSvgIcon(iconName, namespace).pipe(take(1)).subscribe((/**
  919. * @param {?} svg
  920. * @return {?}
  921. */
  922. svg => this._setSvgElement(svg)), (/**
  923. * @param {?} err
  924. * @return {?}
  925. */
  926. (err) => console.log(`Error retrieving icon: ${err.message}`)));
  927. }
  928. else if (svgIconChanges.previousValue) {
  929. this._clearSvgElement();
  930. }
  931. }
  932. if (this._usingFontIcon()) {
  933. this._updateFontIconClasses();
  934. }
  935. }
  936. /**
  937. * @return {?}
  938. */
  939. ngOnInit() {
  940. // Update font classes because ngOnChanges won't be called if none of the inputs are present,
  941. // e.g. <mat-icon>arrow</mat-icon> In this case we need to add a CSS class for the default font.
  942. if (this._usingFontIcon()) {
  943. this._updateFontIconClasses();
  944. }
  945. }
  946. /**
  947. * @return {?}
  948. */
  949. ngAfterViewChecked() {
  950. /** @type {?} */
  951. const cachedElements = this._elementsWithExternalReferences;
  952. if (cachedElements && this._location && cachedElements.size) {
  953. /** @type {?} */
  954. const newPath = this._location.getPathname();
  955. // We need to check whether the URL has changed on each change detection since
  956. // the browser doesn't have an API that will let us react on link clicks and
  957. // we can't depend on the Angular router. The references need to be updated,
  958. // because while most browsers don't care whether the URL is correct after
  959. // the first render, Safari will break if the user navigates to a different
  960. // page and the SVG isn't re-rendered.
  961. if (newPath !== this._previousPath) {
  962. this._previousPath = newPath;
  963. this._prependPathToReferences(newPath);
  964. }
  965. }
  966. }
  967. /**
  968. * @return {?}
  969. */
  970. ngOnDestroy() {
  971. if (this._elementsWithExternalReferences) {
  972. this._elementsWithExternalReferences.clear();
  973. }
  974. }
  975. /**
  976. * @private
  977. * @return {?}
  978. */
  979. _usingFontIcon() {
  980. return !this.svgIcon;
  981. }
  982. /**
  983. * @private
  984. * @param {?} svg
  985. * @return {?}
  986. */
  987. _setSvgElement(svg) {
  988. this._clearSvgElement();
  989. // Workaround for IE11 and Edge ignoring `style` tags inside dynamically-created SVGs.
  990. // See: https://developer.microsoft.com/en-us/microsoft-edge/platform/issues/10898469/
  991. // Do this before inserting the element into the DOM, in order to avoid a style recalculation.
  992. /** @type {?} */
  993. const styleTags = (/** @type {?} */ (svg.querySelectorAll('style')));
  994. for (let i = 0; i < styleTags.length; i++) {
  995. styleTags[i].textContent += ' ';
  996. }
  997. // Note: we do this fix here, rather than the icon registry, because the
  998. // references have to point to the URL at the time that the icon was created.
  999. if (this._location) {
  1000. /** @type {?} */
  1001. const path = this._location.getPathname();
  1002. this._previousPath = path;
  1003. this._cacheChildrenWithExternalReferences(svg);
  1004. this._prependPathToReferences(path);
  1005. }
  1006. this._elementRef.nativeElement.appendChild(svg);
  1007. }
  1008. /**
  1009. * @private
  1010. * @return {?}
  1011. */
  1012. _clearSvgElement() {
  1013. /** @type {?} */
  1014. const layoutElement = this._elementRef.nativeElement;
  1015. /** @type {?} */
  1016. let childCount = layoutElement.childNodes.length;
  1017. if (this._elementsWithExternalReferences) {
  1018. this._elementsWithExternalReferences.clear();
  1019. }
  1020. // Remove existing non-element child nodes and SVGs, and add the new SVG element. Note that
  1021. // we can't use innerHTML, because IE will throw if the element has a data binding.
  1022. while (childCount--) {
  1023. /** @type {?} */
  1024. const child = layoutElement.childNodes[childCount];
  1025. // 1 corresponds to Node.ELEMENT_NODE. We remove all non-element nodes in order to get rid
  1026. // of any loose text nodes, as well as any SVG elements in order to remove any old icons.
  1027. if (child.nodeType !== 1 || child.nodeName.toLowerCase() === 'svg') {
  1028. layoutElement.removeChild(child);
  1029. }
  1030. }
  1031. }
  1032. /**
  1033. * @private
  1034. * @return {?}
  1035. */
  1036. _updateFontIconClasses() {
  1037. if (!this._usingFontIcon()) {
  1038. return;
  1039. }
  1040. /** @type {?} */
  1041. const elem = this._elementRef.nativeElement;
  1042. /** @type {?} */
  1043. const fontSetClass = this.fontSet ?
  1044. this._iconRegistry.classNameForFontAlias(this.fontSet) :
  1045. this._iconRegistry.getDefaultFontSetClass();
  1046. if (fontSetClass != this._previousFontSetClass) {
  1047. if (this._previousFontSetClass) {
  1048. elem.classList.remove(this._previousFontSetClass);
  1049. }
  1050. if (fontSetClass) {
  1051. elem.classList.add(fontSetClass);
  1052. }
  1053. this._previousFontSetClass = fontSetClass;
  1054. }
  1055. if (this.fontIcon != this._previousFontIconClass) {
  1056. if (this._previousFontIconClass) {
  1057. elem.classList.remove(this._previousFontIconClass);
  1058. }
  1059. if (this.fontIcon) {
  1060. elem.classList.add(this.fontIcon);
  1061. }
  1062. this._previousFontIconClass = this.fontIcon;
  1063. }
  1064. }
  1065. /**
  1066. * Cleans up a value to be used as a fontIcon or fontSet.
  1067. * Since the value ends up being assigned as a CSS class, we
  1068. * have to trim the value and omit space-separated values.
  1069. * @private
  1070. * @param {?} value
  1071. * @return {?}
  1072. */
  1073. _cleanupFontValue(value) {
  1074. return typeof value === 'string' ? value.trim().split(' ')[0] : value;
  1075. }
  1076. /**
  1077. * Prepends the current path to all elements that have an attribute pointing to a `FuncIRI`
  1078. * reference. This is required because WebKit browsers require references to be prefixed with
  1079. * the current path, if the page has a `base` tag.
  1080. * @private
  1081. * @param {?} path
  1082. * @return {?}
  1083. */
  1084. _prependPathToReferences(path) {
  1085. /** @type {?} */
  1086. const elements = this._elementsWithExternalReferences;
  1087. if (elements) {
  1088. elements.forEach((/**
  1089. * @param {?} attrs
  1090. * @param {?} element
  1091. * @return {?}
  1092. */
  1093. (attrs, element) => {
  1094. attrs.forEach((/**
  1095. * @param {?} attr
  1096. * @return {?}
  1097. */
  1098. attr => {
  1099. element.setAttribute(attr.name, `url('${path}#${attr.value}')`);
  1100. }));
  1101. }));
  1102. }
  1103. }
  1104. /**
  1105. * Caches the children of an SVG element that have `url()`
  1106. * references that we need to prefix with the current path.
  1107. * @private
  1108. * @param {?} element
  1109. * @return {?}
  1110. */
  1111. _cacheChildrenWithExternalReferences(element) {
  1112. /** @type {?} */
  1113. const elementsWithFuncIri = element.querySelectorAll(funcIriAttributeSelector);
  1114. /** @type {?} */
  1115. const elements = this._elementsWithExternalReferences =
  1116. this._elementsWithExternalReferences || new Map();
  1117. for (let i = 0; i < elementsWithFuncIri.length; i++) {
  1118. funcIriAttributes.forEach((/**
  1119. * @param {?} attr
  1120. * @return {?}
  1121. */
  1122. attr => {
  1123. /** @type {?} */
  1124. const elementWithReference = elementsWithFuncIri[i];
  1125. /** @type {?} */
  1126. const value = elementWithReference.getAttribute(attr);
  1127. /** @type {?} */
  1128. const match = value ? value.match(funcIriPattern) : null;
  1129. if (match) {
  1130. /** @type {?} */
  1131. let attributes = elements.get(elementWithReference);
  1132. if (!attributes) {
  1133. attributes = [];
  1134. elements.set(elementWithReference, attributes);
  1135. }
  1136. (/** @type {?} */ (attributes)).push({ name: attr, value: match[1] });
  1137. }
  1138. }));
  1139. }
  1140. }
  1141. }
  1142. MatIcon.decorators = [
  1143. { type: Component, args: [{template: '<ng-content></ng-content>',
  1144. selector: 'mat-icon',
  1145. exportAs: 'matIcon',
  1146. styles: [".mat-icon{background-repeat:no-repeat;display:inline-block;fill:currentColor;height:24px;width:24px}.mat-icon.mat-icon-inline{font-size:inherit;height:inherit;line-height:inherit;width:inherit}[dir=rtl] .mat-icon-rtl-mirror{transform:scale(-1,1)}.mat-form-field:not(.mat-form-field-appearance-legacy) .mat-form-field-prefix .mat-icon,.mat-form-field:not(.mat-form-field-appearance-legacy) .mat-form-field-suffix .mat-icon{display:block}.mat-form-field:not(.mat-form-field-appearance-legacy) .mat-form-field-prefix .mat-icon-button .mat-icon,.mat-form-field:not(.mat-form-field-appearance-legacy) .mat-form-field-suffix .mat-icon-button .mat-icon{margin:auto}"],
  1147. inputs: ['color'],
  1148. host: {
  1149. 'role': 'img',
  1150. 'class': 'mat-icon notranslate',
  1151. '[class.mat-icon-inline]': 'inline',
  1152. '[class.mat-icon-no-color]': 'color !== "primary" && color !== "accent" && color !== "warn"',
  1153. },
  1154. encapsulation: ViewEncapsulation.None,
  1155. changeDetection: ChangeDetectionStrategy.OnPush,
  1156. },] },
  1157. ];
  1158. /** @nocollapse */
  1159. MatIcon.ctorParameters = () => [
  1160. { type: ElementRef },
  1161. { type: MatIconRegistry },
  1162. { type: String, decorators: [{ type: Attribute, args: ['aria-hidden',] }] },
  1163. { type: undefined, decorators: [{ type: Optional }, { type: Inject, args: [MAT_ICON_LOCATION,] }] }
  1164. ];
  1165. MatIcon.propDecorators = {
  1166. inline: [{ type: Input }],
  1167. svgIcon: [{ type: Input }],
  1168. fontSet: [{ type: Input }],
  1169. fontIcon: [{ type: Input }]
  1170. };
  1171. /**
  1172. * @fileoverview added by tsickle
  1173. * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  1174. */
  1175. class MatIconModule {
  1176. }
  1177. MatIconModule.decorators = [
  1178. { type: NgModule, args: [{
  1179. imports: [MatCommonModule],
  1180. exports: [MatIcon, MatCommonModule],
  1181. declarations: [MatIcon],
  1182. },] },
  1183. ];
  1184. /**
  1185. * @fileoverview added by tsickle
  1186. * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  1187. */
  1188. /**
  1189. * @fileoverview added by tsickle
  1190. * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  1191. */
  1192. export { MatIconModule, MAT_ICON_LOCATION_FACTORY, MAT_ICON_LOCATION, MatIcon, getMatIconNameNotFoundError, getMatIconNoHttpProviderError, getMatIconFailedToSanitizeUrlError, getMatIconFailedToSanitizeLiteralError, ICON_REGISTRY_PROVIDER_FACTORY, MatIconRegistry, ICON_REGISTRY_PROVIDER };
  1193. //# sourceMappingURL=icon.js.map