UNPKG

@angular/material

Version:
10 lines (9 loc) 10.9 kB
/** * @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/core"),require("@angular/material/core"),require("rxjs/operators/take"),require("rxjs/operators/catchError"),require("rxjs/operators/tap"),require("rxjs/operators/finalize"),require("rxjs/operators/map"),require("rxjs/operators/share"),require("@angular/common/http"),require("@angular/platform-browser"),require("rxjs/observable/forkJoin"),require("rxjs/observable/of"),require("rxjs/observable/throw"),require("@angular/common")):"function"==typeof define&&define.amd?define(["exports","@angular/core","@angular/material/core","rxjs/operators/take","rxjs/operators/catchError","rxjs/operators/tap","rxjs/operators/finalize","rxjs/operators/map","rxjs/operators/share","@angular/common/http","@angular/platform-browser","rxjs/observable/forkJoin","rxjs/observable/of","rxjs/observable/throw","@angular/common"],e):e((t.ng=t.ng||{},t.ng.material=t.ng.material||{},t.ng.material.icon=t.ng.material.icon||{}),t.ng.core,t.ng.material.core,t.Rx.operators,t.Rx.operators,t.Rx.operators,t.Rx.operators,t.Rx.operators,t.Rx.operators,t.ng.common.http,t.ng.platformBrowser,t.Rx.Observable,t.Rx.Observable,t.Rx.Observable,t.ng.common)}(this,function(t,e,n,o,r,i,s,a,c,u,l,p,f,g,h){"use strict";function m(t,e){function n(){this.constructor=t}C(t,e),t.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)}function v(t){return Error('Unable to find icon with the name "'+t+'"')}function d(){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 _(t){return Error("The URL provided to MatIconRegistry was not trusted as a resource URL via Angular's DomSanitizer. Attempted URL was \""+t+'".')}function y(t,e,n,o){return t||new F(e,n,o)}function S(t){return t.cloneNode(!0)}function I(t,e){return t+":"+e}var C=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])},E=function(){function t(t){this.url=t,this.svgElement=null}return t}(),F=function(){function t(t,e,n){this._httpClient=t,this._sanitizer=e,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){return this.addSvgIconInNamespace("",t,e)},t.prototype.addSvgIconInNamespace=function(t,e,n){var o=I(t,e);return this._svgIconConfigs.set(o,new E(n)),this},t.prototype.addSvgIconSet=function(t){return this.addSvgIconSetInNamespace("",t)},t.prototype.addSvgIconSetInNamespace=function(t,e){var n=new E(e),o=this._iconSetConfigs.get(t);return o?o.push(n):this._iconSetConfigs.set(t,[n]),this},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 n=this,o=this._sanitizer.sanitize(e.SecurityContext.RESOURCE_URL,t);if(!o)throw _(t);var r=this._cachedIconsByUrl.get(o);return r?f.of(S(r)):this._loadSvgIconFromConfig(new E(t)).pipe(i.tap(function(t){return n._cachedIconsByUrl.set(o,t)}),a.map(function(t){return S(t)}))},t.prototype.getNamedSvgIcon=function(t,e){void 0===e&&(e="");var n=I(e,t),o=this._svgIconConfigs.get(n);if(o)return this._getSvgFromConfig(o);var r=this._iconSetConfigs.get(e);return r?this._getSvgFromIconSetConfigs(t,r):g._throw(v(n))},t.prototype._getSvgFromConfig=function(t){return t.svgElement?f.of(S(t.svgElement)):this._loadSvgIconFromConfig(t).pipe(i.tap(function(e){return t.svgElement=e}),a.map(function(t){return S(t)}))},t.prototype._getSvgFromIconSetConfigs=function(t,n){var o=this,i=this._extractIconWithNameFromAnySet(t,n);if(i)return f.of(i);var s=n.filter(function(t){return!t.svgElement}).map(function(t){return o._loadSvgIconSetFromConfig(t).pipe(r.catchError(function(n){var r=o._sanitizer.sanitize(e.SecurityContext.RESOURCE_URL,t.url);return console.log("Loading icon set URL: "+r+" failed: "+n),f.of(null)}))});return p.forkJoin(s).pipe(a.map(function(){var e=o._extractIconWithNameFromAnySet(t,n);if(!e)throw v(t);return e}))},t.prototype._extractIconWithNameFromAnySet=function(t,e){for(var n=e.length-1;n>=0;n--){var o=e[n];if(o.svgElement){var r=this._extractSvgIconFromSet(o.svgElement,t);if(r)return r}}return null},t.prototype._loadSvgIconFromConfig=function(t){var e=this;return this._fetchUrl(t.url).pipe(a.map(function(t){return e._createSvgElementForSingleIcon(t)}))},t.prototype._loadSvgIconSetFromConfig=function(t){var e=this;return t.svgElement?f.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){var e=this._svgElementFromString(t);return this._setSvgAttributes(e),e},t.prototype._extractSvgIconFromSet=function(t,e){var n=t.querySelector("#"+e);if(!n)return null;var o=n.cloneNode(!0);if(o.id="","svg"===o.nodeName.toLowerCase())return this._setSvgAttributes(o);if("symbol"===o.nodeName.toLowerCase())return this._setSvgAttributes(this._toSvgElement(o));var r=this._svgElementFromString("<svg></svg>");return r.appendChild(o),this._setSvgAttributes(r)},t.prototype._svgElementFromString=function(t){if(this._document||"undefined"!=typeof document){var e=(this._document||document).createElement("DIV");e.innerHTML=t;var n=e.querySelector("svg");if(!n)throw Error("<svg> tag not found");return n}throw new Error("MatIconRegistry could not resolve document.")},t.prototype._toSvgElement=function(t){for(var e=this._svgElementFromString("<svg></svg>"),n=0;n<t.childNodes.length;n++)t.childNodes[n].nodeType===this._document.ELEMENT_NODE&&e.appendChild(t.childNodes[n].cloneNode(!0));return e},t.prototype._setSvgAttributes=function(t){return t.getAttribute("xmlns")||t.setAttribute("xmlns","http://www.w3.org/2000/svg"),t.setAttribute("fit",""),t.setAttribute("height","100%"),t.setAttribute("width","100%"),t.setAttribute("preserveAspectRatio","xMidYMid meet"),t.setAttribute("focusable","false"),t},t.prototype._fetchUrl=function(t){var n=this;if(!this._httpClient)throw d();var o=this._sanitizer.sanitize(e.SecurityContext.RESOURCE_URL,t);if(!o)throw _(t);var r=this._inProgressUrlFetches.get(o);if(r)return r;var i=this._httpClient.get(o,{responseType:"text"}).pipe(s.finalize(function(){return n._inProgressUrlFetches.delete(o)}),c.share());return this._inProgressUrlFetches.set(o,i),i},t.decorators=[{type:e.Injectable}],t.ctorParameters=function(){return[{type:u.HttpClient,decorators:[{type:e.Optional}]},{type:l.DomSanitizer},{type:void 0,decorators:[{type:e.Optional},{type:e.Inject,args:[h.DOCUMENT]}]}]},t}(),b={provide:F,deps:[[new e.Optional,new e.SkipSelf,F],[new e.Optional,u.HttpClient],l.DomSanitizer,[new e.Optional,h.DOCUMENT]],useFactory:y},x=function(){function t(t){this._elementRef=t}return t}(),R=n.mixinColor(x),w=function(t){function n(e,n,o){var r=t.call(this,e)||this;return r._iconRegistry=n,o||e.nativeElement.setAttribute("aria-hidden","true"),r}return m(n,t),Object.defineProperty(n.prototype,"fontSet",{get:function(){return this._fontSet},set:function(t){this._fontSet=this._cleanupFontValue(t)},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"fontIcon",{get:function(){return this._fontIcon},set:function(t){this._fontIcon=this._cleanupFontValue(t)},enumerable:!0,configurable:!0}),n.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+'"')}},n.prototype.ngOnChanges=function(t){var e=this;if(t.svgIcon)if(this.svgIcon){var n=this._splitIconName(this.svgIcon),r=n[0],i=n[1];this._iconRegistry.getNamedSvgIcon(i,r).pipe(o.take(1)).subscribe(function(t){return e._setSvgElement(t)},function(t){return console.log("Error retrieving icon: "+t.message)})}else this._clearSvgElement();this._usingFontIcon()&&this._updateFontIconClasses()},n.prototype.ngOnInit=function(){this._usingFontIcon()&&this._updateFontIconClasses()},n.prototype._usingFontIcon=function(){return!this.svgIcon},n.prototype._setSvgElement=function(t){this._clearSvgElement(),this._elementRef.nativeElement.appendChild(t)},n.prototype._clearSvgElement=function(){for(var t=this._elementRef.nativeElement,e=t.childNodes.length,n=0;n<e;n++)t.removeChild(t.childNodes[n])},n.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)}},n.prototype._cleanupFontValue=function(t){return"string"==typeof t?t.trim().split(" ")[0]:t},n.decorators=[{type:e.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}"],inputs:["color"],host:{role:"img",class:"mat-icon"},encapsulation:e.ViewEncapsulation.None,preserveWhitespaces:!1,changeDetection:e.ChangeDetectionStrategy.OnPush}]}],n.ctorParameters=function(){return[{type:e.ElementRef},{type:F},{type:void 0,decorators:[{type:e.Attribute,args:["aria-hidden"]}]}]},n.propDecorators={svgIcon:[{type:e.Input}],fontSet:[{type:e.Input}],fontIcon:[{type:e.Input}]},n}(R),N=function(){function t(){}return t.decorators=[{type:e.NgModule,args:[{imports:[n.MatCommonModule],exports:[w,n.MatCommonModule],declarations:[w],providers:[b]}]}],t.ctorParameters=function(){return[]},t}();t.MatIconModule=N,t.MatIconBase=x,t._MatIconMixinBase=R,t.MatIcon=w,t.getMatIconNameNotFoundError=v,t.getMatIconNoHttpProviderError=d,t.getMatIconFailedToSanitizeError=_,t.MatIconRegistry=F,t.ICON_REGISTRY_PROVIDER_FACTORY=y,t.ICON_REGISTRY_PROVIDER=b,Object.defineProperty(t,"__esModule",{value:!0})}); //# sourceMappingURL=material-icon.umd.min.js.map