@angular/material
Version:
Angular Material
10 lines (9 loc) • 14.9 kB
JavaScript
/**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("@angular/common"),require("@angular/common/http"),require("@angular/core"),require("@angular/platform-browser"),require("rxjs"),require("rxjs/operators"),require("@angular/cdk/coercion"),require("@angular/material/core")):"function"==typeof define&&define.amd?define("@angular/material/icon",["exports","@angular/common","@angular/common/http","@angular/core","@angular/platform-browser","rxjs","rxjs/operators","@angular/cdk/coercion","@angular/material/core"],e):e((t.ng=t.ng||{},t.ng.material=t.ng.material||{},t.ng.material.icon={}),t.ng.common,t.ng.common.http,t.ng.core,t.ng.platformBrowser,t.rxjs,t.rxjs.operators,t.ng.cdk.coercion,t.ng.material.core)}(this,function(t,e,n,r,o,i,a,s,c){"use strict";function l(t,e){function n(){this.constructor=t}_(t,e),t.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)}function u(t){return Error('Unable to find icon with the name "'+t+'"')}function p(){return Error("Could not find HttpClient provider for use with Angular Material icons. Please include the HttpClientModule from @angular/common/http in your app imports.")}function f(t){return Error("The URL provided to MatIconRegistry was not trusted as a resource URL via Angular's DomSanitizer. Attempted URL was \""+t+'".')}function h(t){return Error("The literal provided to MatIconRegistry was not trusted as safe HTML by Angular's DomSanitizer. Attempted literal was \""+t+'".')}function g(t,e,n,r,o){return t||new S(e,n,r,o)}function m(t){return t.cloneNode(!0)}function d(t,e){return t+":"+e}function v(){var t=r.inject(e.DOCUMENT),n=t?t.location:null;return{getPathname:function(){return n?n.pathname+n.search:""}}}var _=function(t,e){return(_=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])})(t,e)},y=function(){function t(t,e){this.options=e,t.nodeName?this.svgElement=t:this.url=t}return t}(),S=function(){function t(t,e,n,r){this._httpClient=t,this._sanitizer=e,this._errorHandler=r,this._svgIconConfigs=new Map,this._iconSetConfigs=new Map,this._cachedIconsByUrl=new Map,this._inProgressUrlFetches=new Map,this._fontCssClassesByAlias=new Map,this._defaultFontSetClass="material-icons",this._document=n}return t.prototype.addSvgIcon=function(t,e,n){return this.addSvgIconInNamespace("",t,e,n)},t.prototype.addSvgIconLiteral=function(t,e,n){return this.addSvgIconLiteralInNamespace("",t,e,n)},t.prototype.addSvgIconInNamespace=function(t,e,n,r){return this._addSvgIconConfig(t,e,new y(n,r))},t.prototype.addSvgIconLiteralInNamespace=function(t,e,n,o){var i=this._sanitizer.sanitize(r.SecurityContext.HTML,n);if(!i)throw h(n);var a=this._createSvgElementForSingleIcon(i,o);return this._addSvgIconConfig(t,e,new y(a,o))},t.prototype.addSvgIconSet=function(t,e){return this.addSvgIconSetInNamespace("",t,e)},t.prototype.addSvgIconSetLiteral=function(t,e){return this.addSvgIconSetLiteralInNamespace("",t,e)},t.prototype.addSvgIconSetInNamespace=function(t,e,n){return this._addSvgIconSetConfig(t,new y(e,n))},t.prototype.addSvgIconSetLiteralInNamespace=function(t,e,n){var o=this._sanitizer.sanitize(r.SecurityContext.HTML,e);if(!o)throw h(e);var i=this._svgElementFromString(o);return this._addSvgIconSetConfig(t,new y(i,n))},t.prototype.registerFontClassAlias=function(t,e){return void 0===e&&(e=t),this._fontCssClassesByAlias.set(t,e),this},t.prototype.classNameForFontAlias=function(t){return this._fontCssClassesByAlias.get(t)||t},t.prototype.setDefaultFontSetClass=function(t){return this._defaultFontSetClass=t,this},t.prototype.getDefaultFontSetClass=function(){return this._defaultFontSetClass},t.prototype.getSvgIconFromUrl=function(t){var e=this,n=this._sanitizer.sanitize(r.SecurityContext.RESOURCE_URL,t);if(!n)throw f(t);var o=this._cachedIconsByUrl.get(n);return o?i.of(m(o)):this._loadSvgIconFromConfig(new y(t)).pipe(a.tap(function(t){return e._cachedIconsByUrl.set(n,t)}),a.map(function(t){return m(t)}))},t.prototype.getNamedSvgIcon=function(t,e){void 0===e&&(e="");var n=d(e,t),r=this._svgIconConfigs.get(n);if(r)return this._getSvgFromConfig(r);var o=this._iconSetConfigs.get(e);return o?this._getSvgFromIconSetConfigs(t,o):i.throwError(u(n))},t.prototype.ngOnDestroy=function(){this._svgIconConfigs.clear(),this._iconSetConfigs.clear(),this._cachedIconsByUrl.clear()},t.prototype._getSvgFromConfig=function(t){return t.svgElement?i.of(m(t.svgElement)):this._loadSvgIconFromConfig(t).pipe(a.tap(function(e){return t.svgElement=e}),a.map(function(t){return m(t)}))},t.prototype._getSvgFromIconSetConfigs=function(t,e){var n=this,o=this._extractIconWithNameFromAnySet(t,e);if(o)return i.of(o);var s=e.filter(function(t){return!t.svgElement}).map(function(t){return n._loadSvgIconSetFromConfig(t).pipe(a.catchError(function(e){var o=n._sanitizer.sanitize(r.SecurityContext.RESOURCE_URL,t.url),a="Loading icon set URL: "+o+" failed: "+e.message;return n._errorHandler?n._errorHandler.handleError(new Error(a)):console.error(a),i.of(null)}))});return i.forkJoin(s).pipe(a.map(function(){var r=n._extractIconWithNameFromAnySet(t,e);if(!r)throw u(t);return r}))},t.prototype._extractIconWithNameFromAnySet=function(t,e){for(var n=e.length-1;n>=0;n--){var r=e[n];if(r.svgElement){var o=this._extractSvgIconFromSet(r.svgElement,t,r.options);if(o)return o}}return null},t.prototype._loadSvgIconFromConfig=function(t){var e=this;return this._fetchUrl(t.url).pipe(a.map(function(n){return e._createSvgElementForSingleIcon(n,t.options)}))},t.prototype._loadSvgIconSetFromConfig=function(t){var e=this;return t.svgElement?i.of(t.svgElement):this._fetchUrl(t.url).pipe(a.map(function(n){return t.svgElement||(t.svgElement=e._svgElementFromString(n)),t.svgElement}))},t.prototype._createSvgElementForSingleIcon=function(t,e){var n=this._svgElementFromString(t);return this._setSvgAttributes(n,e),n},t.prototype._extractSvgIconFromSet=function(t,e,n){var r=t.querySelector('[id="'+e+'"]');if(!r)return null;var o=r.cloneNode(!0);if(o.removeAttribute("id"),"svg"===o.nodeName.toLowerCase())return this._setSvgAttributes(o,n);if("symbol"===o.nodeName.toLowerCase())return this._setSvgAttributes(this._toSvgElement(o),n);var i=this._svgElementFromString("<svg></svg>");return i.appendChild(o),this._setSvgAttributes(i,n)},t.prototype._svgElementFromString=function(t){var e=this._document.createElement("DIV");e.innerHTML=t;var n=e.querySelector("svg");if(!n)throw Error("<svg> tag not found");return n},t.prototype._toSvgElement=function(t){for(var e=this._svgElementFromString("<svg></svg>"),n=t.attributes,r=0;r<n.length;r++){var o=n[r],i=o.name,a=o.value;"id"!==i&&e.setAttribute(i,a)}for(var r=0;r<t.childNodes.length;r++)t.childNodes[r].nodeType===this._document.ELEMENT_NODE&&e.appendChild(t.childNodes[r].cloneNode(!0));return e},t.prototype._setSvgAttributes=function(t,e){return t.setAttribute("fit",""),t.setAttribute("height","100%"),t.setAttribute("width","100%"),t.setAttribute("preserveAspectRatio","xMidYMid meet"),t.setAttribute("focusable","false"),e&&e.viewBox&&t.setAttribute("viewBox",e.viewBox),t},t.prototype._fetchUrl=function(t){var e=this;if(!this._httpClient)throw p();if(null==t)throw Error('Cannot fetch icon from URL "'+t+'".');var n=this._sanitizer.sanitize(r.SecurityContext.RESOURCE_URL,t);if(!n)throw f(t);var o=this._inProgressUrlFetches.get(n);if(o)return o;var i=this._httpClient.get(n,{responseType:"text"}).pipe(a.finalize(function(){return e._inProgressUrlFetches.delete(n)}),a.share());return this._inProgressUrlFetches.set(n,i),i},t.prototype._addSvgIconConfig=function(t,e,n){return this._svgIconConfigs.set(d(t,e),n),this},t.prototype._addSvgIconSetConfig=function(t,e){var n=this._iconSetConfigs.get(t);return n?n.push(e):this._iconSetConfigs.set(t,[e]),this},t.decorators=[{type:r.Injectable,args:[{providedIn:"root"}]}],t.ctorParameters=function(){return[{type:n.HttpClient,decorators:[{type:r.Optional}]},{type:o.DomSanitizer},{type:void 0,decorators:[{type:r.Optional},{type:r.Inject,args:[e.DOCUMENT]}]},{type:r.ErrorHandler,decorators:[{type:r.Optional}]}]},t.ngInjectableDef=r.ɵɵdefineInjectable({factory:function(){return new t(r.ɵɵinject(n.HttpClient,8),r.ɵɵinject(o.DomSanitizer),r.ɵɵinject(e.DOCUMENT,8),r.ɵɵinject(r.ErrorHandler,8))},token:t,providedIn:"root"}),t}(),I={provide:S,deps:[[new r.Optional,new r.SkipSelf,S],[new r.Optional,n.HttpClient],o.DomSanitizer,[new r.Optional,r.ErrorHandler],[new r.Optional,e.DOCUMENT]],useFactory:g},C=function(){function t(t){this._elementRef=t}return t}(),E=c.mixinColor(C),F=new r.InjectionToken("mat-icon-location",{providedIn:"root",factory:v}),w=["clip-path","color-profile","src","cursor","fill","filter","marker","marker-start","marker-mid","marker-end","mask","stroke"],R=function(t){return"["+t+"]"},b=w.map(R).join(", "),N=/^url\(['"]?#(.*?)['"]?\)$/,x=function(t){function e(e,n,r,o,i){var a=t.call(this,e)||this;return a._iconRegistry=n,a._location=o,a._errorHandler=i,a._inline=!1,r||e.nativeElement.setAttribute("aria-hidden","true"),a}return l(e,t),Object.defineProperty(e.prototype,"inline",{get:function(){return this._inline},set:function(t){this._inline=s.coerceBooleanProperty(t)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"fontSet",{get:function(){return this._fontSet},set:function(t){this._fontSet=this._cleanupFontValue(t)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"fontIcon",{get:function(){return this._fontIcon},set:function(t){this._fontIcon=this._cleanupFontValue(t)},enumerable:!0,configurable:!0}),e.prototype._splitIconName=function(t){if(!t)return["",""];var e=t.split(":");switch(e.length){case 1:return["",e[0]];case 2:return e;default:throw Error('Invalid icon name: "'+t+'"')}},e.prototype.ngOnChanges=function(t){var e=this,n=t.svgIcon;if(n)if(this.svgIcon){var r=this._splitIconName(this.svgIcon),o=r[0],i=r[1];this._iconRegistry.getNamedSvgIcon(i,o).pipe(a.take(1)).subscribe(function(t){return e._setSvgElement(t)},function(t){var n="Error retrieving icon "+o+":"+i+"! "+t.message;e._errorHandler?e._errorHandler.handleError(new Error(n)):console.error(n)})}else n.previousValue&&this._clearSvgElement();this._usingFontIcon()&&this._updateFontIconClasses()},e.prototype.ngOnInit=function(){this._usingFontIcon()&&this._updateFontIconClasses()},e.prototype.ngAfterViewChecked=function(){var t=this._elementsWithExternalReferences;if(t&&this._location&&t.size){var e=this._location.getPathname();e!==this._previousPath&&(this._previousPath=e,this._prependPathToReferences(e))}},e.prototype.ngOnDestroy=function(){this._elementsWithExternalReferences&&this._elementsWithExternalReferences.clear()},e.prototype._usingFontIcon=function(){return!this.svgIcon},e.prototype._setSvgElement=function(t){this._clearSvgElement();for(var e=t.querySelectorAll("style"),n=0;n<e.length;n++)e[n].textContent+=" ";if(this._location){var r=this._location.getPathname();this._previousPath=r,this._cacheChildrenWithExternalReferences(t),this._prependPathToReferences(r)}this._elementRef.nativeElement.appendChild(t)},e.prototype._clearSvgElement=function(){var t=this._elementRef.nativeElement,e=t.childNodes.length;for(this._elementsWithExternalReferences&&this._elementsWithExternalReferences.clear();e--;){var n=t.childNodes[e];1===n.nodeType&&"svg"!==n.nodeName.toLowerCase()||t.removeChild(n)}},e.prototype._updateFontIconClasses=function(){if(this._usingFontIcon()){var t=this._elementRef.nativeElement,e=this.fontSet?this._iconRegistry.classNameForFontAlias(this.fontSet):this._iconRegistry.getDefaultFontSetClass();e!=this._previousFontSetClass&&(this._previousFontSetClass&&t.classList.remove(this._previousFontSetClass),e&&t.classList.add(e),this._previousFontSetClass=e),this.fontIcon!=this._previousFontIconClass&&(this._previousFontIconClass&&t.classList.remove(this._previousFontIconClass),this.fontIcon&&t.classList.add(this.fontIcon),this._previousFontIconClass=this.fontIcon)}},e.prototype._cleanupFontValue=function(t){return"string"==typeof t?t.trim().split(" ")[0]:t},e.prototype._prependPathToReferences=function(t){var e=this._elementsWithExternalReferences;e&&e.forEach(function(e,n){e.forEach(function(e){n.setAttribute(e.name,"url('"+t+"#"+e.value+"')")})})},e.prototype._cacheChildrenWithExternalReferences=function(t){for(var e=t.querySelectorAll(b),n=this._elementsWithExternalReferences=this._elementsWithExternalReferences||new Map,r=0;r<e.length;r++)!function(t){w.forEach(function(r){var o=e[t],i=o.getAttribute(r),a=i?i.match(N):null;if(a){var s=n.get(o);s||(s=[],n.set(o,s)),s.push({name:r,value:a[1]})}})}(r)},e.decorators=[{type:r.Component,args:[{template:"<ng-content></ng-content>",selector:"mat-icon",exportAs:"matIcon",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}"],inputs:["color"],host:{role:"img",class:"mat-icon notranslate","[class.mat-icon-inline]":"inline","[class.mat-icon-no-color]":'color !== "primary" && color !== "accent" && color !== "warn"'},encapsulation:r.ViewEncapsulation.None,changeDetection:r.ChangeDetectionStrategy.OnPush}]}],e.ctorParameters=function(){return[{type:r.ElementRef},{type:S},{type:String,decorators:[{type:r.Attribute,args:["aria-hidden"]}]},{type:void 0,decorators:[{type:r.Optional},{type:r.Inject,args:[F]}]},{type:r.ErrorHandler,decorators:[{type:r.Optional}]}]},e.propDecorators={inline:[{type:r.Input}],svgIcon:[{type:r.Input}],fontSet:[{type:r.Input}],fontIcon:[{type:r.Input}]},e}(E),A=function(){function t(){}return t.decorators=[{type:r.NgModule,args:[{imports:[c.MatCommonModule],exports:[x,c.MatCommonModule],declarations:[x]}]}],t}();t.MatIconModule=A,t.MAT_ICON_LOCATION_FACTORY=v,t.MAT_ICON_LOCATION=F,t.MatIcon=x,t.getMatIconNameNotFoundError=u,t.getMatIconNoHttpProviderError=p,t.getMatIconFailedToSanitizeUrlError=f,t.getMatIconFailedToSanitizeLiteralError=h,t.ICON_REGISTRY_PROVIDER_FACTORY=g,t.MatIconRegistry=S,t.ICON_REGISTRY_PROVIDER=I,Object.defineProperty(t,"__esModule",{value:!0})});
//# sourceMappingURL=material-icon.umd.min.js.map