[6a3a178] | 1 | (function (global, factory) {
|
---|
| 2 | typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@angular/core'), require('@angular/material/core'), require('@angular/cdk/coercion'), require('@angular/common'), require('rxjs'), require('rxjs/operators'), require('@angular/common/http'), require('@angular/platform-browser')) :
|
---|
| 3 | typeof define === 'function' && define.amd ? define('@angular/material/icon', ['exports', '@angular/core', '@angular/material/core', '@angular/cdk/coercion', '@angular/common', 'rxjs', 'rxjs/operators', '@angular/common/http', '@angular/platform-browser'], factory) :
|
---|
| 4 | (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory((global.ng = global.ng || {}, global.ng.material = global.ng.material || {}, global.ng.material.icon = {}), global.ng.core, global.ng.material.core, global.ng.cdk.coercion, global.ng.common, global.rxjs, global.rxjs.operators, global.ng.common.http, global.ng.platformBrowser));
|
---|
| 5 | }(this, (function (exports, i0, core, coercion, i3, rxjs, operators, i1, i2) { 'use strict';
|
---|
| 6 |
|
---|
| 7 | function _interopNamespace(e) {
|
---|
| 8 | if (e && e.__esModule) return e;
|
---|
| 9 | var n = Object.create(null);
|
---|
| 10 | if (e) {
|
---|
| 11 | Object.keys(e).forEach(function (k) {
|
---|
| 12 | if (k !== 'default') {
|
---|
| 13 | var d = Object.getOwnPropertyDescriptor(e, k);
|
---|
| 14 | Object.defineProperty(n, k, d.get ? d : {
|
---|
| 15 | enumerable: true,
|
---|
| 16 | get: function () {
|
---|
| 17 | return e[k];
|
---|
| 18 | }
|
---|
| 19 | });
|
---|
| 20 | }
|
---|
| 21 | });
|
---|
| 22 | }
|
---|
| 23 | n['default'] = e;
|
---|
| 24 | return Object.freeze(n);
|
---|
| 25 | }
|
---|
| 26 |
|
---|
| 27 | var i0__namespace = /*#__PURE__*/_interopNamespace(i0);
|
---|
| 28 | var i3__namespace = /*#__PURE__*/_interopNamespace(i3);
|
---|
| 29 | var i1__namespace = /*#__PURE__*/_interopNamespace(i1);
|
---|
| 30 | var i2__namespace = /*#__PURE__*/_interopNamespace(i2);
|
---|
| 31 |
|
---|
| 32 | /*! *****************************************************************************
|
---|
| 33 | Copyright (c) Microsoft Corporation.
|
---|
| 34 |
|
---|
| 35 | Permission to use, copy, modify, and/or distribute this software for any
|
---|
| 36 | purpose with or without fee is hereby granted.
|
---|
| 37 |
|
---|
| 38 | THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
---|
| 39 | REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
---|
| 40 | AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
---|
| 41 | INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
---|
| 42 | LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
---|
| 43 | OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
---|
| 44 | PERFORMANCE OF THIS SOFTWARE.
|
---|
| 45 | ***************************************************************************** */
|
---|
| 46 | /* global Reflect, Promise */
|
---|
| 47 | var extendStatics = function (d, b) {
|
---|
| 48 | extendStatics = Object.setPrototypeOf ||
|
---|
| 49 | ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
---|
| 50 | function (d, b) { for (var p in b)
|
---|
| 51 | if (Object.prototype.hasOwnProperty.call(b, p))
|
---|
| 52 | d[p] = b[p]; };
|
---|
| 53 | return extendStatics(d, b);
|
---|
| 54 | };
|
---|
| 55 | function __extends(d, b) {
|
---|
| 56 | if (typeof b !== "function" && b !== null)
|
---|
| 57 | throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
---|
| 58 | extendStatics(d, b);
|
---|
| 59 | function __() { this.constructor = d; }
|
---|
| 60 | d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
---|
| 61 | }
|
---|
| 62 | var __assign = function () {
|
---|
| 63 | __assign = Object.assign || function __assign(t) {
|
---|
| 64 | for (var s, i = 1, n = arguments.length; i < n; i++) {
|
---|
| 65 | s = arguments[i];
|
---|
| 66 | for (var p in s)
|
---|
| 67 | if (Object.prototype.hasOwnProperty.call(s, p))
|
---|
| 68 | t[p] = s[p];
|
---|
| 69 | }
|
---|
| 70 | return t;
|
---|
| 71 | };
|
---|
| 72 | return __assign.apply(this, arguments);
|
---|
| 73 | };
|
---|
| 74 | function __rest(s, e) {
|
---|
| 75 | var t = {};
|
---|
| 76 | for (var p in s)
|
---|
| 77 | if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
---|
| 78 | t[p] = s[p];
|
---|
| 79 | if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
---|
| 80 | for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
---|
| 81 | if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
---|
| 82 | t[p[i]] = s[p[i]];
|
---|
| 83 | }
|
---|
| 84 | return t;
|
---|
| 85 | }
|
---|
| 86 | function __decorate(decorators, target, key, desc) {
|
---|
| 87 | var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
---|
| 88 | if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
|
---|
| 89 | r = Reflect.decorate(decorators, target, key, desc);
|
---|
| 90 | else
|
---|
| 91 | for (var i = decorators.length - 1; i >= 0; i--)
|
---|
| 92 | if (d = decorators[i])
|
---|
| 93 | r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
---|
| 94 | return c > 3 && r && Object.defineProperty(target, key, r), r;
|
---|
| 95 | }
|
---|
| 96 | function __param(paramIndex, decorator) {
|
---|
| 97 | return function (target, key) { decorator(target, key, paramIndex); };
|
---|
| 98 | }
|
---|
| 99 | function __metadata(metadataKey, metadataValue) {
|
---|
| 100 | if (typeof Reflect === "object" && typeof Reflect.metadata === "function")
|
---|
| 101 | return Reflect.metadata(metadataKey, metadataValue);
|
---|
| 102 | }
|
---|
| 103 | function __awaiter(thisArg, _arguments, P, generator) {
|
---|
| 104 | function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
---|
| 105 | return new (P || (P = Promise))(function (resolve, reject) {
|
---|
| 106 | function fulfilled(value) { try {
|
---|
| 107 | step(generator.next(value));
|
---|
| 108 | }
|
---|
| 109 | catch (e) {
|
---|
| 110 | reject(e);
|
---|
| 111 | } }
|
---|
| 112 | function rejected(value) { try {
|
---|
| 113 | step(generator["throw"](value));
|
---|
| 114 | }
|
---|
| 115 | catch (e) {
|
---|
| 116 | reject(e);
|
---|
| 117 | } }
|
---|
| 118 | function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
---|
| 119 | step((generator = generator.apply(thisArg, _arguments || [])).next());
|
---|
| 120 | });
|
---|
| 121 | }
|
---|
| 122 | function __generator(thisArg, body) {
|
---|
| 123 | var _ = { label: 0, sent: function () { if (t[0] & 1)
|
---|
| 124 | throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
---|
| 125 | return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function () { return this; }), g;
|
---|
| 126 | function verb(n) { return function (v) { return step([n, v]); }; }
|
---|
| 127 | function step(op) {
|
---|
| 128 | if (f)
|
---|
| 129 | throw new TypeError("Generator is already executing.");
|
---|
| 130 | while (_)
|
---|
| 131 | try {
|
---|
| 132 | if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done)
|
---|
| 133 | return t;
|
---|
| 134 | if (y = 0, t)
|
---|
| 135 | op = [op[0] & 2, t.value];
|
---|
| 136 | switch (op[0]) {
|
---|
| 137 | case 0:
|
---|
| 138 | case 1:
|
---|
| 139 | t = op;
|
---|
| 140 | break;
|
---|
| 141 | case 4:
|
---|
| 142 | _.label++;
|
---|
| 143 | return { value: op[1], done: false };
|
---|
| 144 | case 5:
|
---|
| 145 | _.label++;
|
---|
| 146 | y = op[1];
|
---|
| 147 | op = [0];
|
---|
| 148 | continue;
|
---|
| 149 | case 7:
|
---|
| 150 | op = _.ops.pop();
|
---|
| 151 | _.trys.pop();
|
---|
| 152 | continue;
|
---|
| 153 | default:
|
---|
| 154 | if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
|
---|
| 155 | _ = 0;
|
---|
| 156 | continue;
|
---|
| 157 | }
|
---|
| 158 | if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) {
|
---|
| 159 | _.label = op[1];
|
---|
| 160 | break;
|
---|
| 161 | }
|
---|
| 162 | if (op[0] === 6 && _.label < t[1]) {
|
---|
| 163 | _.label = t[1];
|
---|
| 164 | t = op;
|
---|
| 165 | break;
|
---|
| 166 | }
|
---|
| 167 | if (t && _.label < t[2]) {
|
---|
| 168 | _.label = t[2];
|
---|
| 169 | _.ops.push(op);
|
---|
| 170 | break;
|
---|
| 171 | }
|
---|
| 172 | if (t[2])
|
---|
| 173 | _.ops.pop();
|
---|
| 174 | _.trys.pop();
|
---|
| 175 | continue;
|
---|
| 176 | }
|
---|
| 177 | op = body.call(thisArg, _);
|
---|
| 178 | }
|
---|
| 179 | catch (e) {
|
---|
| 180 | op = [6, e];
|
---|
| 181 | y = 0;
|
---|
| 182 | }
|
---|
| 183 | finally {
|
---|
| 184 | f = t = 0;
|
---|
| 185 | }
|
---|
| 186 | if (op[0] & 5)
|
---|
| 187 | throw op[1];
|
---|
| 188 | return { value: op[0] ? op[1] : void 0, done: true };
|
---|
| 189 | }
|
---|
| 190 | }
|
---|
| 191 | var __createBinding = Object.create ? (function (o, m, k, k2) {
|
---|
| 192 | if (k2 === undefined)
|
---|
| 193 | k2 = k;
|
---|
| 194 | Object.defineProperty(o, k2, { enumerable: true, get: function () { return m[k]; } });
|
---|
| 195 | }) : (function (o, m, k, k2) {
|
---|
| 196 | if (k2 === undefined)
|
---|
| 197 | k2 = k;
|
---|
| 198 | o[k2] = m[k];
|
---|
| 199 | });
|
---|
| 200 | function __exportStar(m, o) {
|
---|
| 201 | for (var p in m)
|
---|
| 202 | if (p !== "default" && !Object.prototype.hasOwnProperty.call(o, p))
|
---|
| 203 | __createBinding(o, m, p);
|
---|
| 204 | }
|
---|
| 205 | function __values(o) {
|
---|
| 206 | var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
---|
| 207 | if (m)
|
---|
| 208 | return m.call(o);
|
---|
| 209 | if (o && typeof o.length === "number")
|
---|
| 210 | return {
|
---|
| 211 | next: function () {
|
---|
| 212 | if (o && i >= o.length)
|
---|
| 213 | o = void 0;
|
---|
| 214 | return { value: o && o[i++], done: !o };
|
---|
| 215 | }
|
---|
| 216 | };
|
---|
| 217 | throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
---|
| 218 | }
|
---|
| 219 | function __read(o, n) {
|
---|
| 220 | var m = typeof Symbol === "function" && o[Symbol.iterator];
|
---|
| 221 | if (!m)
|
---|
| 222 | return o;
|
---|
| 223 | var i = m.call(o), r, ar = [], e;
|
---|
| 224 | try {
|
---|
| 225 | while ((n === void 0 || n-- > 0) && !(r = i.next()).done)
|
---|
| 226 | ar.push(r.value);
|
---|
| 227 | }
|
---|
| 228 | catch (error) {
|
---|
| 229 | e = { error: error };
|
---|
| 230 | }
|
---|
| 231 | finally {
|
---|
| 232 | try {
|
---|
| 233 | if (r && !r.done && (m = i["return"]))
|
---|
| 234 | m.call(i);
|
---|
| 235 | }
|
---|
| 236 | finally {
|
---|
| 237 | if (e)
|
---|
| 238 | throw e.error;
|
---|
| 239 | }
|
---|
| 240 | }
|
---|
| 241 | return ar;
|
---|
| 242 | }
|
---|
| 243 | /** @deprecated */
|
---|
| 244 | function __spread() {
|
---|
| 245 | for (var ar = [], i = 0; i < arguments.length; i++)
|
---|
| 246 | ar = ar.concat(__read(arguments[i]));
|
---|
| 247 | return ar;
|
---|
| 248 | }
|
---|
| 249 | /** @deprecated */
|
---|
| 250 | function __spreadArrays() {
|
---|
| 251 | for (var s = 0, i = 0, il = arguments.length; i < il; i++)
|
---|
| 252 | s += arguments[i].length;
|
---|
| 253 | for (var r = Array(s), k = 0, i = 0; i < il; i++)
|
---|
| 254 | for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
|
---|
| 255 | r[k] = a[j];
|
---|
| 256 | return r;
|
---|
| 257 | }
|
---|
| 258 | function __spreadArray(to, from, pack) {
|
---|
| 259 | if (pack || arguments.length === 2)
|
---|
| 260 | for (var i = 0, l = from.length, ar; i < l; i++) {
|
---|
| 261 | if (ar || !(i in from)) {
|
---|
| 262 | if (!ar)
|
---|
| 263 | ar = Array.prototype.slice.call(from, 0, i);
|
---|
| 264 | ar[i] = from[i];
|
---|
| 265 | }
|
---|
| 266 | }
|
---|
| 267 | return to.concat(ar || from);
|
---|
| 268 | }
|
---|
| 269 | function __await(v) {
|
---|
| 270 | return this instanceof __await ? (this.v = v, this) : new __await(v);
|
---|
| 271 | }
|
---|
| 272 | function __asyncGenerator(thisArg, _arguments, generator) {
|
---|
| 273 | if (!Symbol.asyncIterator)
|
---|
| 274 | throw new TypeError("Symbol.asyncIterator is not defined.");
|
---|
| 275 | var g = generator.apply(thisArg, _arguments || []), i, q = [];
|
---|
| 276 | return i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i;
|
---|
| 277 | function verb(n) { if (g[n])
|
---|
| 278 | i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; }
|
---|
| 279 | function resume(n, v) { try {
|
---|
| 280 | step(g[n](v));
|
---|
| 281 | }
|
---|
| 282 | catch (e) {
|
---|
| 283 | settle(q[0][3], e);
|
---|
| 284 | } }
|
---|
| 285 | function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }
|
---|
| 286 | function fulfill(value) { resume("next", value); }
|
---|
| 287 | function reject(value) { resume("throw", value); }
|
---|
| 288 | function settle(f, v) { if (f(v), q.shift(), q.length)
|
---|
| 289 | resume(q[0][0], q[0][1]); }
|
---|
| 290 | }
|
---|
| 291 | function __asyncDelegator(o) {
|
---|
| 292 | var i, p;
|
---|
| 293 | return i = {}, verb("next"), verb("throw", function (e) { throw e; }), verb("return"), i[Symbol.iterator] = function () { return this; }, i;
|
---|
| 294 | function verb(n, f) { i[n] = o[n] ? function (v) { return (p = !p) ? { value: __await(o[n](v)), done: n === "return" } : f ? f(v) : v; } : f; }
|
---|
| 295 | }
|
---|
| 296 | function __asyncValues(o) {
|
---|
| 297 | if (!Symbol.asyncIterator)
|
---|
| 298 | throw new TypeError("Symbol.asyncIterator is not defined.");
|
---|
| 299 | var m = o[Symbol.asyncIterator], i;
|
---|
| 300 | return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
|
---|
| 301 | function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
|
---|
| 302 | function settle(resolve, reject, d, v) { Promise.resolve(v).then(function (v) { resolve({ value: v, done: d }); }, reject); }
|
---|
| 303 | }
|
---|
| 304 | function __makeTemplateObject(cooked, raw) {
|
---|
| 305 | if (Object.defineProperty) {
|
---|
| 306 | Object.defineProperty(cooked, "raw", { value: raw });
|
---|
| 307 | }
|
---|
| 308 | else {
|
---|
| 309 | cooked.raw = raw;
|
---|
| 310 | }
|
---|
| 311 | return cooked;
|
---|
| 312 | }
|
---|
| 313 | ;
|
---|
| 314 | var __setModuleDefault = Object.create ? (function (o, v) {
|
---|
| 315 | Object.defineProperty(o, "default", { enumerable: true, value: v });
|
---|
| 316 | }) : function (o, v) {
|
---|
| 317 | o["default"] = v;
|
---|
| 318 | };
|
---|
| 319 | function __importStar(mod) {
|
---|
| 320 | if (mod && mod.__esModule)
|
---|
| 321 | return mod;
|
---|
| 322 | var result = {};
|
---|
| 323 | if (mod != null)
|
---|
| 324 | for (var k in mod)
|
---|
| 325 | if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k))
|
---|
| 326 | __createBinding(result, mod, k);
|
---|
| 327 | __setModuleDefault(result, mod);
|
---|
| 328 | return result;
|
---|
| 329 | }
|
---|
| 330 | function __importDefault(mod) {
|
---|
| 331 | return (mod && mod.__esModule) ? mod : { default: mod };
|
---|
| 332 | }
|
---|
| 333 | function __classPrivateFieldGet(receiver, state, kind, f) {
|
---|
| 334 | if (kind === "a" && !f)
|
---|
| 335 | throw new TypeError("Private accessor was defined without a getter");
|
---|
| 336 | if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver))
|
---|
| 337 | throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
---|
| 338 | return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
---|
| 339 | }
|
---|
| 340 | function __classPrivateFieldSet(receiver, state, value, kind, f) {
|
---|
| 341 | if (kind === "m")
|
---|
| 342 | throw new TypeError("Private method is not writable");
|
---|
| 343 | if (kind === "a" && !f)
|
---|
| 344 | throw new TypeError("Private accessor was defined without a setter");
|
---|
| 345 | if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver))
|
---|
| 346 | throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
---|
| 347 | return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
---|
| 348 | }
|
---|
| 349 |
|
---|
| 350 | /**
|
---|
| 351 | * @license
|
---|
| 352 | * Copyright Google LLC All Rights Reserved.
|
---|
| 353 | *
|
---|
| 354 | * Use of this source code is governed by an MIT-style license that can be
|
---|
| 355 | * found in the LICENSE file at https://angular.io/license
|
---|
| 356 | */
|
---|
| 357 | /**
|
---|
| 358 | * Returns an exception to be thrown in the case when attempting to
|
---|
| 359 | * load an icon with a name that cannot be found.
|
---|
| 360 | * @docs-private
|
---|
| 361 | */
|
---|
| 362 | function getMatIconNameNotFoundError(iconName) {
|
---|
| 363 | return Error("Unable to find icon with the name \"" + iconName + "\"");
|
---|
| 364 | }
|
---|
| 365 | /**
|
---|
| 366 | * Returns an exception to be thrown when the consumer attempts to use
|
---|
| 367 | * `<mat-icon>` without including @angular/common/http.
|
---|
| 368 | * @docs-private
|
---|
| 369 | */
|
---|
| 370 | function getMatIconNoHttpProviderError() {
|
---|
| 371 | return Error('Could not find HttpClient provider for use with Angular Material icons. ' +
|
---|
| 372 | 'Please include the HttpClientModule from @angular/common/http in your ' +
|
---|
| 373 | 'app imports.');
|
---|
| 374 | }
|
---|
| 375 | /**
|
---|
| 376 | * Returns an exception to be thrown when a URL couldn't be sanitized.
|
---|
| 377 | * @param url URL that was attempted to be sanitized.
|
---|
| 378 | * @docs-private
|
---|
| 379 | */
|
---|
| 380 | function getMatIconFailedToSanitizeUrlError(url) {
|
---|
| 381 | return Error("The URL provided to MatIconRegistry was not trusted as a resource URL " +
|
---|
| 382 | ("via Angular's DomSanitizer. Attempted URL was \"" + url + "\"."));
|
---|
| 383 | }
|
---|
| 384 | /**
|
---|
| 385 | * Returns an exception to be thrown when a HTML string couldn't be sanitized.
|
---|
| 386 | * @param literal HTML that was attempted to be sanitized.
|
---|
| 387 | * @docs-private
|
---|
| 388 | */
|
---|
| 389 | function getMatIconFailedToSanitizeLiteralError(literal) {
|
---|
| 390 | return Error("The literal provided to MatIconRegistry was not trusted as safe HTML by " +
|
---|
| 391 | ("Angular's DomSanitizer. Attempted literal was \"" + literal + "\"."));
|
---|
| 392 | }
|
---|
| 393 | /**
|
---|
| 394 | * Configuration for an icon, including the URL and possibly the cached SVG element.
|
---|
| 395 | * @docs-private
|
---|
| 396 | */
|
---|
| 397 | var SvgIconConfig = /** @class */ (function () {
|
---|
| 398 | function SvgIconConfig(url, svgText, options) {
|
---|
| 399 | this.url = url;
|
---|
| 400 | this.svgText = svgText;
|
---|
| 401 | this.options = options;
|
---|
| 402 | }
|
---|
| 403 | return SvgIconConfig;
|
---|
| 404 | }());
|
---|
| 405 | /**
|
---|
| 406 | * Service to register and display icons used by the `<mat-icon>` component.
|
---|
| 407 | * - Registers icon URLs by namespace and name.
|
---|
| 408 | * - Registers icon set URLs by namespace.
|
---|
| 409 | * - Registers aliases for CSS classes, for use with icon fonts.
|
---|
| 410 | * - Loads icons from URLs and extracts individual icons from icon sets.
|
---|
| 411 | */
|
---|
| 412 | var MatIconRegistry = /** @class */ (function () {
|
---|
| 413 | function MatIconRegistry(_httpClient, _sanitizer, document, _errorHandler) {
|
---|
| 414 | this._httpClient = _httpClient;
|
---|
| 415 | this._sanitizer = _sanitizer;
|
---|
| 416 | this._errorHandler = _errorHandler;
|
---|
| 417 | /**
|
---|
| 418 | * URLs and cached SVG elements for individual icons. Keys are of the format "[namespace]:[icon]".
|
---|
| 419 | */
|
---|
| 420 | this._svgIconConfigs = new Map();
|
---|
| 421 | /**
|
---|
| 422 | * SvgIconConfig objects and cached SVG elements for icon sets, keyed by namespace.
|
---|
| 423 | * Multiple icon sets can be registered under the same namespace.
|
---|
| 424 | */
|
---|
| 425 | this._iconSetConfigs = new Map();
|
---|
| 426 | /** Cache for icons loaded by direct URLs. */
|
---|
| 427 | this._cachedIconsByUrl = new Map();
|
---|
| 428 | /** In-progress icon fetches. Used to coalesce multiple requests to the same URL. */
|
---|
| 429 | this._inProgressUrlFetches = new Map();
|
---|
| 430 | /** Map from font identifiers to their CSS class names. Used for icon fonts. */
|
---|
| 431 | this._fontCssClassesByAlias = new Map();
|
---|
| 432 | /** Registered icon resolver functions. */
|
---|
| 433 | this._resolvers = [];
|
---|
| 434 | /**
|
---|
| 435 | * The CSS class to apply when an `<mat-icon>` component has no icon name, url, or font specified.
|
---|
| 436 | * The default 'material-icons' value assumes that the material icon font has been loaded as
|
---|
| 437 | * described at http://google.github.io/material-design-icons/#icon-font-for-the-web
|
---|
| 438 | */
|
---|
| 439 | this._defaultFontSetClass = 'material-icons';
|
---|
| 440 | this._document = document;
|
---|
| 441 | }
|
---|
| 442 | /**
|
---|
| 443 | * Registers an icon by URL in the default namespace.
|
---|
| 444 | * @param iconName Name under which the icon should be registered.
|
---|
| 445 | * @param url
|
---|
| 446 | */
|
---|
| 447 | MatIconRegistry.prototype.addSvgIcon = function (iconName, url, options) {
|
---|
| 448 | return this.addSvgIconInNamespace('', iconName, url, options);
|
---|
| 449 | };
|
---|
| 450 | /**
|
---|
| 451 | * Registers an icon using an HTML string in the default namespace.
|
---|
| 452 | * @param iconName Name under which the icon should be registered.
|
---|
| 453 | * @param literal SVG source of the icon.
|
---|
| 454 | */
|
---|
| 455 | MatIconRegistry.prototype.addSvgIconLiteral = function (iconName, literal, options) {
|
---|
| 456 | return this.addSvgIconLiteralInNamespace('', iconName, literal, options);
|
---|
| 457 | };
|
---|
| 458 | /**
|
---|
| 459 | * Registers an icon by URL in the specified namespace.
|
---|
| 460 | * @param namespace Namespace in which the icon should be registered.
|
---|
| 461 | * @param iconName Name under which the icon should be registered.
|
---|
| 462 | * @param url
|
---|
| 463 | */
|
---|
| 464 | MatIconRegistry.prototype.addSvgIconInNamespace = function (namespace, iconName, url, options) {
|
---|
| 465 | return this._addSvgIconConfig(namespace, iconName, new SvgIconConfig(url, null, options));
|
---|
| 466 | };
|
---|
| 467 | /**
|
---|
| 468 | * Registers an icon resolver function with the registry. The function will be invoked with the
|
---|
| 469 | * name and namespace of an icon when the registry tries to resolve the URL from which to fetch
|
---|
| 470 | * the icon. The resolver is expected to return a `SafeResourceUrl` that points to the icon,
|
---|
| 471 | * an object with the icon URL and icon options, or `null` if the icon is not supported. Resolvers
|
---|
| 472 | * will be invoked in the order in which they have been registered.
|
---|
| 473 | * @param resolver Resolver function to be registered.
|
---|
| 474 | */
|
---|
| 475 | MatIconRegistry.prototype.addSvgIconResolver = function (resolver) {
|
---|
| 476 | this._resolvers.push(resolver);
|
---|
| 477 | return this;
|
---|
| 478 | };
|
---|
| 479 | /**
|
---|
| 480 | * Registers an icon using an HTML string in the specified namespace.
|
---|
| 481 | * @param namespace Namespace in which the icon should be registered.
|
---|
| 482 | * @param iconName Name under which the icon should be registered.
|
---|
| 483 | * @param literal SVG source of the icon.
|
---|
| 484 | */
|
---|
| 485 | MatIconRegistry.prototype.addSvgIconLiteralInNamespace = function (namespace, iconName, literal, options) {
|
---|
| 486 | var cleanLiteral = this._sanitizer.sanitize(i0.SecurityContext.HTML, literal);
|
---|
| 487 | // TODO: add an ngDevMode check
|
---|
| 488 | if (!cleanLiteral) {
|
---|
| 489 | throw getMatIconFailedToSanitizeLiteralError(literal);
|
---|
| 490 | }
|
---|
| 491 | return this._addSvgIconConfig(namespace, iconName, new SvgIconConfig('', cleanLiteral, options));
|
---|
| 492 | };
|
---|
| 493 | /**
|
---|
| 494 | * Registers an icon set by URL in the default namespace.
|
---|
| 495 | * @param url
|
---|
| 496 | */
|
---|
| 497 | MatIconRegistry.prototype.addSvgIconSet = function (url, options) {
|
---|
| 498 | return this.addSvgIconSetInNamespace('', url, options);
|
---|
| 499 | };
|
---|
| 500 | /**
|
---|
| 501 | * Registers an icon set using an HTML string in the default namespace.
|
---|
| 502 | * @param literal SVG source of the icon set.
|
---|
| 503 | */
|
---|
| 504 | MatIconRegistry.prototype.addSvgIconSetLiteral = function (literal, options) {
|
---|
| 505 | return this.addSvgIconSetLiteralInNamespace('', literal, options);
|
---|
| 506 | };
|
---|
| 507 | /**
|
---|
| 508 | * Registers an icon set by URL in the specified namespace.
|
---|
| 509 | * @param namespace Namespace in which to register the icon set.
|
---|
| 510 | * @param url
|
---|
| 511 | */
|
---|
| 512 | MatIconRegistry.prototype.addSvgIconSetInNamespace = function (namespace, url, options) {
|
---|
| 513 | return this._addSvgIconSetConfig(namespace, new SvgIconConfig(url, null, options));
|
---|
| 514 | };
|
---|
| 515 | /**
|
---|
| 516 | * Registers an icon set using an HTML string in the specified namespace.
|
---|
| 517 | * @param namespace Namespace in which to register the icon set.
|
---|
| 518 | * @param literal SVG source of the icon set.
|
---|
| 519 | */
|
---|
| 520 | MatIconRegistry.prototype.addSvgIconSetLiteralInNamespace = function (namespace, literal, options) {
|
---|
| 521 | var cleanLiteral = this._sanitizer.sanitize(i0.SecurityContext.HTML, literal);
|
---|
| 522 | if (!cleanLiteral) {
|
---|
| 523 | throw getMatIconFailedToSanitizeLiteralError(literal);
|
---|
| 524 | }
|
---|
| 525 | return this._addSvgIconSetConfig(namespace, new SvgIconConfig('', cleanLiteral, options));
|
---|
| 526 | };
|
---|
| 527 | /**
|
---|
| 528 | * Defines an alias for a CSS class name to be used for icon fonts. Creating an matIcon
|
---|
| 529 | * component with the alias as the fontSet input will cause the class name to be applied
|
---|
| 530 | * to the `<mat-icon>` element.
|
---|
| 531 | *
|
---|
| 532 | * @param alias Alias for the font.
|
---|
| 533 | * @param className Class name override to be used instead of the alias.
|
---|
| 534 | */
|
---|
| 535 | MatIconRegistry.prototype.registerFontClassAlias = function (alias, className) {
|
---|
| 536 | if (className === void 0) { className = alias; }
|
---|
| 537 | this._fontCssClassesByAlias.set(alias, className);
|
---|
| 538 | return this;
|
---|
| 539 | };
|
---|
| 540 | /**
|
---|
| 541 | * Returns the CSS class name associated with the alias by a previous call to
|
---|
| 542 | * registerFontClassAlias. If no CSS class has been associated, returns the alias unmodified.
|
---|
| 543 | */
|
---|
| 544 | MatIconRegistry.prototype.classNameForFontAlias = function (alias) {
|
---|
| 545 | return this._fontCssClassesByAlias.get(alias) || alias;
|
---|
| 546 | };
|
---|
| 547 | /**
|
---|
| 548 | * Sets the CSS class name to be used for icon fonts when an `<mat-icon>` component does not
|
---|
| 549 | * have a fontSet input value, and is not loading an icon by name or URL.
|
---|
| 550 | *
|
---|
| 551 | * @param className
|
---|
| 552 | */
|
---|
| 553 | MatIconRegistry.prototype.setDefaultFontSetClass = function (className) {
|
---|
| 554 | this._defaultFontSetClass = className;
|
---|
| 555 | return this;
|
---|
| 556 | };
|
---|
| 557 | /**
|
---|
| 558 | * Returns the CSS class name to be used for icon fonts when an `<mat-icon>` component does not
|
---|
| 559 | * have a fontSet input value, and is not loading an icon by name or URL.
|
---|
| 560 | */
|
---|
| 561 | MatIconRegistry.prototype.getDefaultFontSetClass = function () {
|
---|
| 562 | return this._defaultFontSetClass;
|
---|
| 563 | };
|
---|
| 564 | /**
|
---|
| 565 | * Returns an Observable that produces the icon (as an `<svg>` DOM element) from the given URL.
|
---|
| 566 | * The response from the URL may be cached so this will not always cause an HTTP request, but
|
---|
| 567 | * the produced element will always be a new copy of the originally fetched icon. (That is,
|
---|
| 568 | * it will not contain any modifications made to elements previously returned).
|
---|
| 569 | *
|
---|
| 570 | * @param safeUrl URL from which to fetch the SVG icon.
|
---|
| 571 | */
|
---|
| 572 | MatIconRegistry.prototype.getSvgIconFromUrl = function (safeUrl) {
|
---|
| 573 | var _this = this;
|
---|
| 574 | var url = this._sanitizer.sanitize(i0.SecurityContext.RESOURCE_URL, safeUrl);
|
---|
| 575 | if (!url) {
|
---|
| 576 | throw getMatIconFailedToSanitizeUrlError(safeUrl);
|
---|
| 577 | }
|
---|
| 578 | var cachedIcon = this._cachedIconsByUrl.get(url);
|
---|
| 579 | if (cachedIcon) {
|
---|
| 580 | return rxjs.of(cloneSvg(cachedIcon));
|
---|
| 581 | }
|
---|
| 582 | return this._loadSvgIconFromConfig(new SvgIconConfig(safeUrl, null)).pipe(operators.tap(function (svg) { return _this._cachedIconsByUrl.set(url, svg); }), operators.map(function (svg) { return cloneSvg(svg); }));
|
---|
| 583 | };
|
---|
| 584 | /**
|
---|
| 585 | * Returns an Observable that produces the icon (as an `<svg>` DOM element) with the given name
|
---|
| 586 | * and namespace. The icon must have been previously registered with addIcon or addIconSet;
|
---|
| 587 | * if not, the Observable will throw an error.
|
---|
| 588 | *
|
---|
| 589 | * @param name Name of the icon to be retrieved.
|
---|
| 590 | * @param namespace Namespace in which to look for the icon.
|
---|
| 591 | */
|
---|
| 592 | MatIconRegistry.prototype.getNamedSvgIcon = function (name, namespace) {
|
---|
| 593 | if (namespace === void 0) { namespace = ''; }
|
---|
| 594 | var key = iconKey(namespace, name);
|
---|
| 595 | var config = this._svgIconConfigs.get(key);
|
---|
| 596 | // Return (copy of) cached icon if possible.
|
---|
| 597 | if (config) {
|
---|
| 598 | return this._getSvgFromConfig(config);
|
---|
| 599 | }
|
---|
| 600 | // Otherwise try to resolve the config from one of the resolver functions.
|
---|
| 601 | config = this._getIconConfigFromResolvers(namespace, name);
|
---|
| 602 | if (config) {
|
---|
| 603 | this._svgIconConfigs.set(key, config);
|
---|
| 604 | return this._getSvgFromConfig(config);
|
---|
| 605 | }
|
---|
| 606 | // See if we have any icon sets registered for the namespace.
|
---|
| 607 | var iconSetConfigs = this._iconSetConfigs.get(namespace);
|
---|
| 608 | if (iconSetConfigs) {
|
---|
| 609 | return this._getSvgFromIconSetConfigs(name, iconSetConfigs);
|
---|
| 610 | }
|
---|
| 611 | return rxjs.throwError(getMatIconNameNotFoundError(key));
|
---|
| 612 | };
|
---|
| 613 | MatIconRegistry.prototype.ngOnDestroy = function () {
|
---|
| 614 | this._resolvers = [];
|
---|
| 615 | this._svgIconConfigs.clear();
|
---|
| 616 | this._iconSetConfigs.clear();
|
---|
| 617 | this._cachedIconsByUrl.clear();
|
---|
| 618 | };
|
---|
| 619 | /**
|
---|
| 620 | * Returns the cached icon for a SvgIconConfig if available, or fetches it from its URL if not.
|
---|
| 621 | */
|
---|
| 622 | MatIconRegistry.prototype._getSvgFromConfig = function (config) {
|
---|
| 623 | if (config.svgText) {
|
---|
| 624 | // We already have the SVG element for this icon, return a copy.
|
---|
| 625 | return rxjs.of(cloneSvg(this._svgElementFromConfig(config)));
|
---|
| 626 | }
|
---|
| 627 | else {
|
---|
| 628 | // Fetch the icon from the config's URL, cache it, and return a copy.
|
---|
| 629 | return this._loadSvgIconFromConfig(config).pipe(operators.map(function (svg) { return cloneSvg(svg); }));
|
---|
| 630 | }
|
---|
| 631 | };
|
---|
| 632 | /**
|
---|
| 633 | * Attempts to find an icon with the specified name in any of the SVG icon sets.
|
---|
| 634 | * First searches the available cached icons for a nested element with a matching name, and
|
---|
| 635 | * if found copies the element to a new `<svg>` element. If not found, fetches all icon sets
|
---|
| 636 | * that have not been cached, and searches again after all fetches are completed.
|
---|
| 637 | * The returned Observable produces the SVG element if possible, and throws
|
---|
| 638 | * an error if no icon with the specified name can be found.
|
---|
| 639 | */
|
---|
| 640 | MatIconRegistry.prototype._getSvgFromIconSetConfigs = function (name, iconSetConfigs) {
|
---|
| 641 | var _this = this;
|
---|
| 642 | // For all the icon set SVG elements we've fetched, see if any contain an icon with the
|
---|
| 643 | // requested name.
|
---|
| 644 | var namedIcon = this._extractIconWithNameFromAnySet(name, iconSetConfigs);
|
---|
| 645 | if (namedIcon) {
|
---|
| 646 | // We could cache namedIcon in _svgIconConfigs, but since we have to make a copy every
|
---|
| 647 | // time anyway, there's probably not much advantage compared to just always extracting
|
---|
| 648 | // it from the icon set.
|
---|
| 649 | return rxjs.of(namedIcon);
|
---|
| 650 | }
|
---|
| 651 | // Not found in any cached icon sets. If there are icon sets with URLs that we haven't
|
---|
| 652 | // fetched, fetch them now and look for iconName in the results.
|
---|
| 653 | var iconSetFetchRequests = iconSetConfigs
|
---|
| 654 | .filter(function (iconSetConfig) { return !iconSetConfig.svgText; })
|
---|
| 655 | .map(function (iconSetConfig) {
|
---|
| 656 | return _this._loadSvgIconSetFromConfig(iconSetConfig).pipe(operators.catchError(function (err) {
|
---|
| 657 | var url = _this._sanitizer.sanitize(i0.SecurityContext.RESOURCE_URL, iconSetConfig.url);
|
---|
| 658 | // Swallow errors fetching individual URLs so the
|
---|
| 659 | // combined Observable won't necessarily fail.
|
---|
| 660 | var errorMessage = "Loading icon set URL: " + url + " failed: " + err.message;
|
---|
| 661 | _this._errorHandler.handleError(new Error(errorMessage));
|
---|
| 662 | return rxjs.of(null);
|
---|
| 663 | }));
|
---|
| 664 | });
|
---|
| 665 | // Fetch all the icon set URLs. When the requests complete, every IconSet should have a
|
---|
| 666 | // cached SVG element (unless the request failed), and we can check again for the icon.
|
---|
| 667 | return rxjs.forkJoin(iconSetFetchRequests).pipe(operators.map(function () {
|
---|
| 668 | var foundIcon = _this._extractIconWithNameFromAnySet(name, iconSetConfigs);
|
---|
| 669 | // TODO: add an ngDevMode check
|
---|
| 670 | if (!foundIcon) {
|
---|
| 671 | throw getMatIconNameNotFoundError(name);
|
---|
| 672 | }
|
---|
| 673 | return foundIcon;
|
---|
| 674 | }));
|
---|
| 675 | };
|
---|
| 676 | /**
|
---|
| 677 | * Searches the cached SVG elements for the given icon sets for a nested icon element whose "id"
|
---|
| 678 | * tag matches the specified name. If found, copies the nested element to a new SVG element and
|
---|
| 679 | * returns it. Returns null if no matching element is found.
|
---|
| 680 | */
|
---|
| 681 | MatIconRegistry.prototype._extractIconWithNameFromAnySet = function (iconName, iconSetConfigs) {
|
---|
| 682 | // Iterate backwards, so icon sets added later have precedence.
|
---|
| 683 | for (var i = iconSetConfigs.length - 1; i >= 0; i--) {
|
---|
| 684 | var config = iconSetConfigs[i];
|
---|
| 685 | // Parsing the icon set's text into an SVG element can be expensive. We can avoid some of
|
---|
| 686 | // the parsing by doing a quick check using `indexOf` to see if there's any chance for the
|
---|
| 687 | // icon to be in the set. This won't be 100% accurate, but it should help us avoid at least
|
---|
| 688 | // some of the parsing.
|
---|
| 689 | if (config.svgText && config.svgText.indexOf(iconName) > -1) {
|
---|
| 690 | var svg = this._svgElementFromConfig(config);
|
---|
| 691 | var foundIcon = this._extractSvgIconFromSet(svg, iconName, config.options);
|
---|
| 692 | if (foundIcon) {
|
---|
| 693 | return foundIcon;
|
---|
| 694 | }
|
---|
| 695 | }
|
---|
| 696 | }
|
---|
| 697 | return null;
|
---|
| 698 | };
|
---|
| 699 | /**
|
---|
| 700 | * Loads the content of the icon URL specified in the SvgIconConfig and creates an SVG element
|
---|
| 701 | * from it.
|
---|
| 702 | */
|
---|
| 703 | MatIconRegistry.prototype._loadSvgIconFromConfig = function (config) {
|
---|
| 704 | var _this = this;
|
---|
| 705 | return this._fetchIcon(config).pipe(operators.tap(function (svgText) { return config.svgText = svgText; }), operators.map(function () { return _this._svgElementFromConfig(config); }));
|
---|
| 706 | };
|
---|
| 707 | /**
|
---|
| 708 | * Loads the content of the icon set URL specified in the
|
---|
| 709 | * SvgIconConfig and attaches it to the config.
|
---|
| 710 | */
|
---|
| 711 | MatIconRegistry.prototype._loadSvgIconSetFromConfig = function (config) {
|
---|
| 712 | if (config.svgText) {
|
---|
| 713 | return rxjs.of(null);
|
---|
| 714 | }
|
---|
| 715 | return this._fetchIcon(config).pipe(operators.tap(function (svgText) { return config.svgText = svgText; }));
|
---|
| 716 | };
|
---|
| 717 | /**
|
---|
| 718 | * Searches the cached element of the given SvgIconConfig for a nested icon element whose "id"
|
---|
| 719 | * tag matches the specified name. If found, copies the nested element to a new SVG element and
|
---|
| 720 | * returns it. Returns null if no matching element is found.
|
---|
| 721 | */
|
---|
| 722 | MatIconRegistry.prototype._extractSvgIconFromSet = function (iconSet, iconName, options) {
|
---|
| 723 | // Use the `id="iconName"` syntax in order to escape special
|
---|
| 724 | // characters in the ID (versus using the #iconName syntax).
|
---|
| 725 | var iconSource = iconSet.querySelector("[id=\"" + iconName + "\"]");
|
---|
| 726 | if (!iconSource) {
|
---|
| 727 | return null;
|
---|
| 728 | }
|
---|
| 729 | // Clone the element and remove the ID to prevent multiple elements from being added
|
---|
| 730 | // to the page with the same ID.
|
---|
| 731 | var iconElement = iconSource.cloneNode(true);
|
---|
| 732 | iconElement.removeAttribute('id');
|
---|
| 733 | // If the icon node is itself an <svg> node, clone and return it directly. If not, set it as
|
---|
| 734 | // the content of a new <svg> node.
|
---|
| 735 | if (iconElement.nodeName.toLowerCase() === 'svg') {
|
---|
| 736 | return this._setSvgAttributes(iconElement, options);
|
---|
| 737 | }
|
---|
| 738 | // If the node is a <symbol>, it won't be rendered so we have to convert it into <svg>. Note
|
---|
| 739 | // that the same could be achieved by referring to it via <use href="#id">, however the <use>
|
---|
| 740 | // tag is problematic on Firefox, because it needs to include the current page path.
|
---|
| 741 | if (iconElement.nodeName.toLowerCase() === 'symbol') {
|
---|
| 742 | return this._setSvgAttributes(this._toSvgElement(iconElement), options);
|
---|
| 743 | }
|
---|
| 744 | // createElement('SVG') doesn't work as expected; the DOM ends up with
|
---|
| 745 | // the correct nodes, but the SVG content doesn't render. Instead we
|
---|
| 746 | // have to create an empty SVG node using innerHTML and append its content.
|
---|
| 747 | // Elements created using DOMParser.parseFromString have the same problem.
|
---|
| 748 | // http://stackoverflow.com/questions/23003278/svg-innerhtml-in-firefox-can-not-display
|
---|
| 749 | var svg = this._svgElementFromString('<svg></svg>');
|
---|
| 750 | // Clone the node so we don't remove it from the parent icon set element.
|
---|
| 751 | svg.appendChild(iconElement);
|
---|
| 752 | return this._setSvgAttributes(svg, options);
|
---|
| 753 | };
|
---|
| 754 | /**
|
---|
| 755 | * Creates a DOM element from the given SVG string.
|
---|
| 756 | */
|
---|
| 757 | MatIconRegistry.prototype._svgElementFromString = function (str) {
|
---|
| 758 | var div = this._document.createElement('DIV');
|
---|
| 759 | div.innerHTML = str;
|
---|
| 760 | var svg = div.querySelector('svg');
|
---|
| 761 | // TODO: add an ngDevMode check
|
---|
| 762 | if (!svg) {
|
---|
| 763 | throw Error('<svg> tag not found');
|
---|
| 764 | }
|
---|
| 765 | return svg;
|
---|
| 766 | };
|
---|
| 767 | /**
|
---|
| 768 | * Converts an element into an SVG node by cloning all of its children.
|
---|
| 769 | */
|
---|
| 770 | MatIconRegistry.prototype._toSvgElement = function (element) {
|
---|
| 771 | var svg = this._svgElementFromString('<svg></svg>');
|
---|
| 772 | var attributes = element.attributes;
|
---|
| 773 | // Copy over all the attributes from the `symbol` to the new SVG, except the id.
|
---|
| 774 | for (var i = 0; i < attributes.length; i++) {
|
---|
| 775 | var _b = attributes[i], name = _b.name, value = _b.value;
|
---|
| 776 | if (name !== 'id') {
|
---|
| 777 | svg.setAttribute(name, value);
|
---|
| 778 | }
|
---|
| 779 | }
|
---|
| 780 | for (var i = 0; i < element.childNodes.length; i++) {
|
---|
| 781 | if (element.childNodes[i].nodeType === this._document.ELEMENT_NODE) {
|
---|
| 782 | svg.appendChild(element.childNodes[i].cloneNode(true));
|
---|
| 783 | }
|
---|
| 784 | }
|
---|
| 785 | return svg;
|
---|
| 786 | };
|
---|
| 787 | /**
|
---|
| 788 | * Sets the default attributes for an SVG element to be used as an icon.
|
---|
| 789 | */
|
---|
| 790 | MatIconRegistry.prototype._setSvgAttributes = function (svg, options) {
|
---|
| 791 | svg.setAttribute('fit', '');
|
---|
| 792 | svg.setAttribute('height', '100%');
|
---|
| 793 | svg.setAttribute('width', '100%');
|
---|
| 794 | svg.setAttribute('preserveAspectRatio', 'xMidYMid meet');
|
---|
| 795 | svg.setAttribute('focusable', 'false'); // Disable IE11 default behavior to make SVGs focusable.
|
---|
| 796 | if (options && options.viewBox) {
|
---|
| 797 | svg.setAttribute('viewBox', options.viewBox);
|
---|
| 798 | }
|
---|
| 799 | return svg;
|
---|
| 800 | };
|
---|
| 801 | /**
|
---|
| 802 | * Returns an Observable which produces the string contents of the given icon. Results may be
|
---|
| 803 | * cached, so future calls with the same URL may not cause another HTTP request.
|
---|
| 804 | */
|
---|
| 805 | MatIconRegistry.prototype._fetchIcon = function (iconConfig) {
|
---|
| 806 | var _this = this;
|
---|
| 807 | var _a;
|
---|
| 808 | var safeUrl = iconConfig.url, options = iconConfig.options;
|
---|
| 809 | var withCredentials = (_a = options === null || options === void 0 ? void 0 : options.withCredentials) !== null && _a !== void 0 ? _a : false;
|
---|
| 810 | if (!this._httpClient) {
|
---|
| 811 | throw getMatIconNoHttpProviderError();
|
---|
| 812 | }
|
---|
| 813 | // TODO: add an ngDevMode check
|
---|
| 814 | if (safeUrl == null) {
|
---|
| 815 | throw Error("Cannot fetch icon from URL \"" + safeUrl + "\".");
|
---|
| 816 | }
|
---|
| 817 | var url = this._sanitizer.sanitize(i0.SecurityContext.RESOURCE_URL, safeUrl);
|
---|
| 818 | // TODO: add an ngDevMode check
|
---|
| 819 | if (!url) {
|
---|
| 820 | throw getMatIconFailedToSanitizeUrlError(safeUrl);
|
---|
| 821 | }
|
---|
| 822 | // Store in-progress fetches to avoid sending a duplicate request for a URL when there is
|
---|
| 823 | // already a request in progress for that URL. It's necessary to call share() on the
|
---|
| 824 | // Observable returned by http.get() so that multiple subscribers don't cause multiple XHRs.
|
---|
| 825 | var inProgressFetch = this._inProgressUrlFetches.get(url);
|
---|
| 826 | if (inProgressFetch) {
|
---|
| 827 | return inProgressFetch;
|
---|
| 828 | }
|
---|
| 829 | var req = this._httpClient.get(url, { responseType: 'text', withCredentials: withCredentials }).pipe(operators.finalize(function () { return _this._inProgressUrlFetches.delete(url); }), operators.share());
|
---|
| 830 | this._inProgressUrlFetches.set(url, req);
|
---|
| 831 | return req;
|
---|
| 832 | };
|
---|
| 833 | /**
|
---|
| 834 | * Registers an icon config by name in the specified namespace.
|
---|
| 835 | * @param namespace Namespace in which to register the icon config.
|
---|
| 836 | * @param iconName Name under which to register the config.
|
---|
| 837 | * @param config Config to be registered.
|
---|
| 838 | */
|
---|
| 839 | MatIconRegistry.prototype._addSvgIconConfig = function (namespace, iconName, config) {
|
---|
| 840 | this._svgIconConfigs.set(iconKey(namespace, iconName), config);
|
---|
| 841 | return this;
|
---|
| 842 | };
|
---|
| 843 | /**
|
---|
| 844 | * Registers an icon set config in the specified namespace.
|
---|
| 845 | * @param namespace Namespace in which to register the icon config.
|
---|
| 846 | * @param config Config to be registered.
|
---|
| 847 | */
|
---|
| 848 | MatIconRegistry.prototype._addSvgIconSetConfig = function (namespace, config) {
|
---|
| 849 | var configNamespace = this._iconSetConfigs.get(namespace);
|
---|
| 850 | if (configNamespace) {
|
---|
| 851 | configNamespace.push(config);
|
---|
| 852 | }
|
---|
| 853 | else {
|
---|
| 854 | this._iconSetConfigs.set(namespace, [config]);
|
---|
| 855 | }
|
---|
| 856 | return this;
|
---|
| 857 | };
|
---|
| 858 | /** Parses a config's text into an SVG element. */
|
---|
| 859 | MatIconRegistry.prototype._svgElementFromConfig = function (config) {
|
---|
| 860 | if (!config.svgElement) {
|
---|
| 861 | var svg = this._svgElementFromString(config.svgText);
|
---|
| 862 | this._setSvgAttributes(svg, config.options);
|
---|
| 863 | config.svgElement = svg;
|
---|
| 864 | }
|
---|
| 865 | return config.svgElement;
|
---|
| 866 | };
|
---|
| 867 | /** Tries to create an icon config through the registered resolver functions. */
|
---|
| 868 | MatIconRegistry.prototype._getIconConfigFromResolvers = function (namespace, name) {
|
---|
| 869 | for (var i = 0; i < this._resolvers.length; i++) {
|
---|
| 870 | var result = this._resolvers[i](name, namespace);
|
---|
| 871 | if (result) {
|
---|
| 872 | return isSafeUrlWithOptions(result) ?
|
---|
| 873 | new SvgIconConfig(result.url, null, result.options) :
|
---|
| 874 | new SvgIconConfig(result, null);
|
---|
| 875 | }
|
---|
| 876 | }
|
---|
| 877 | return undefined;
|
---|
| 878 | };
|
---|
| 879 | return MatIconRegistry;
|
---|
| 880 | }());
|
---|
| 881 | MatIconRegistry.ɵprov = i0__namespace.ɵɵdefineInjectable({ factory: function MatIconRegistry_Factory() { return new MatIconRegistry(i0__namespace.ɵɵinject(i1__namespace.HttpClient, 8), i0__namespace.ɵɵinject(i2__namespace.DomSanitizer), i0__namespace.ɵɵinject(i3__namespace.DOCUMENT, 8), i0__namespace.ɵɵinject(i0__namespace.ErrorHandler)); }, token: MatIconRegistry, providedIn: "root" });
|
---|
| 882 | MatIconRegistry.decorators = [
|
---|
| 883 | { type: i0.Injectable, args: [{ providedIn: 'root' },] }
|
---|
| 884 | ];
|
---|
| 885 | MatIconRegistry.ctorParameters = function () { return [
|
---|
| 886 | { type: i1.HttpClient, decorators: [{ type: i0.Optional }] },
|
---|
| 887 | { type: i2.DomSanitizer },
|
---|
| 888 | { type: undefined, decorators: [{ type: i0.Optional }, { type: i0.Inject, args: [i3.DOCUMENT,] }] },
|
---|
| 889 | { type: i0.ErrorHandler }
|
---|
| 890 | ]; };
|
---|
| 891 | /** @docs-private */
|
---|
| 892 | function ICON_REGISTRY_PROVIDER_FACTORY(parentRegistry, httpClient, sanitizer, errorHandler, document) {
|
---|
| 893 | return parentRegistry || new MatIconRegistry(httpClient, sanitizer, document, errorHandler);
|
---|
| 894 | }
|
---|
| 895 | /** @docs-private */
|
---|
| 896 | var ICON_REGISTRY_PROVIDER = {
|
---|
| 897 | // If there is already an MatIconRegistry available, use that. Otherwise, provide a new one.
|
---|
| 898 | provide: MatIconRegistry,
|
---|
| 899 | deps: [
|
---|
| 900 | [new i0.Optional(), new i0.SkipSelf(), MatIconRegistry],
|
---|
| 901 | [new i0.Optional(), i1.HttpClient],
|
---|
| 902 | i2.DomSanitizer,
|
---|
| 903 | i0.ErrorHandler,
|
---|
| 904 | [new i0.Optional(), i3.DOCUMENT],
|
---|
| 905 | ],
|
---|
| 906 | useFactory: ICON_REGISTRY_PROVIDER_FACTORY,
|
---|
| 907 | };
|
---|
| 908 | /** Clones an SVGElement while preserving type information. */
|
---|
| 909 | function cloneSvg(svg) {
|
---|
| 910 | return svg.cloneNode(true);
|
---|
| 911 | }
|
---|
| 912 | /** Returns the cache key to use for an icon namespace and name. */
|
---|
| 913 | function iconKey(namespace, name) {
|
---|
| 914 | return namespace + ':' + name;
|
---|
| 915 | }
|
---|
| 916 | function isSafeUrlWithOptions(value) {
|
---|
| 917 | return !!(value.url && value.options);
|
---|
| 918 | }
|
---|
| 919 |
|
---|
| 920 | // Boilerplate for applying mixins to MatIcon.
|
---|
| 921 | /** @docs-private */
|
---|
| 922 | var _MatIconBase = core.mixinColor(/** @class */ (function () {
|
---|
| 923 | function class_1(_elementRef) {
|
---|
| 924 | this._elementRef = _elementRef;
|
---|
| 925 | }
|
---|
| 926 | return class_1;
|
---|
| 927 | }()));
|
---|
| 928 | /**
|
---|
| 929 | * Injection token used to provide the current location to `MatIcon`.
|
---|
| 930 | * Used to handle server-side rendering and to stub out during unit tests.
|
---|
| 931 | * @docs-private
|
---|
| 932 | */
|
---|
| 933 | var MAT_ICON_LOCATION = new i0.InjectionToken('mat-icon-location', {
|
---|
| 934 | providedIn: 'root',
|
---|
| 935 | factory: MAT_ICON_LOCATION_FACTORY
|
---|
| 936 | });
|
---|
| 937 | /** @docs-private */
|
---|
| 938 | function MAT_ICON_LOCATION_FACTORY() {
|
---|
| 939 | var _document = i0.inject(i3.DOCUMENT);
|
---|
| 940 | var _location = _document ? _document.location : null;
|
---|
| 941 | return {
|
---|
| 942 | // Note that this needs to be a function, rather than a property, because Angular
|
---|
| 943 | // will only resolve it once, but we want the current path on each call.
|
---|
| 944 | getPathname: function () { return _location ? (_location.pathname + _location.search) : ''; }
|
---|
| 945 | };
|
---|
| 946 | }
|
---|
| 947 | /** SVG attributes that accept a FuncIRI (e.g. `url(<something>)`). */
|
---|
| 948 | var funcIriAttributes = [
|
---|
| 949 | 'clip-path',
|
---|
| 950 | 'color-profile',
|
---|
| 951 | 'src',
|
---|
| 952 | 'cursor',
|
---|
| 953 | 'fill',
|
---|
| 954 | 'filter',
|
---|
| 955 | 'marker',
|
---|
| 956 | 'marker-start',
|
---|
| 957 | 'marker-mid',
|
---|
| 958 | 'marker-end',
|
---|
| 959 | 'mask',
|
---|
| 960 | 'stroke'
|
---|
| 961 | ];
|
---|
| 962 | var ɵ0 = function (attr) { return "[" + attr + "]"; };
|
---|
| 963 | /** Selector that can be used to find all elements that are using a `FuncIRI`. */
|
---|
| 964 | var funcIriAttributeSelector = funcIriAttributes.map(ɵ0).join(', ');
|
---|
| 965 | /** Regex that can be used to extract the id out of a FuncIRI. */
|
---|
| 966 | var funcIriPattern = /^url\(['"]?#(.*?)['"]?\)$/;
|
---|
| 967 | /**
|
---|
| 968 | * Component to display an icon. It can be used in the following ways:
|
---|
| 969 | *
|
---|
| 970 | * - Specify the svgIcon input to load an SVG icon from a URL previously registered with the
|
---|
| 971 | * addSvgIcon, addSvgIconInNamespace, addSvgIconSet, or addSvgIconSetInNamespace methods of
|
---|
| 972 | * MatIconRegistry. If the svgIcon value contains a colon it is assumed to be in the format
|
---|
| 973 | * "[namespace]:[name]", if not the value will be the name of an icon in the default namespace.
|
---|
| 974 | * Examples:
|
---|
| 975 | * `<mat-icon svgIcon="left-arrow"></mat-icon>
|
---|
| 976 | * <mat-icon svgIcon="animals:cat"></mat-icon>`
|
---|
| 977 | *
|
---|
| 978 | * - Use a font ligature as an icon by putting the ligature text in the content of the `<mat-icon>`
|
---|
| 979 | * component. By default the Material icons font is used as described at
|
---|
| 980 | * http://google.github.io/material-design-icons/#icon-font-for-the-web. You can specify an
|
---|
| 981 | * alternate font by setting the fontSet input to either the CSS class to apply to use the
|
---|
| 982 | * desired font, or to an alias previously registered with MatIconRegistry.registerFontClassAlias.
|
---|
| 983 | * Examples:
|
---|
| 984 | * `<mat-icon>home</mat-icon>
|
---|
| 985 | * <mat-icon fontSet="myfont">sun</mat-icon>`
|
---|
| 986 | *
|
---|
| 987 | * - Specify a font glyph to be included via CSS rules by setting the fontSet input to specify the
|
---|
| 988 | * font, and the fontIcon input to specify the icon. Typically the fontIcon will specify a
|
---|
| 989 | * CSS class which causes the glyph to be displayed via a :before selector, as in
|
---|
| 990 | * https://fortawesome.github.io/Font-Awesome/examples/
|
---|
| 991 | * Example:
|
---|
| 992 | * `<mat-icon fontSet="fa" fontIcon="alarm"></mat-icon>`
|
---|
| 993 | */
|
---|
| 994 | var MatIcon = /** @class */ (function (_super) {
|
---|
| 995 | __extends(MatIcon, _super);
|
---|
| 996 | function MatIcon(elementRef, _iconRegistry, ariaHidden, _location, _errorHandler) {
|
---|
| 997 | var _this = _super.call(this, elementRef) || this;
|
---|
| 998 | _this._iconRegistry = _iconRegistry;
|
---|
| 999 | _this._location = _location;
|
---|
| 1000 | _this._errorHandler = _errorHandler;
|
---|
| 1001 | _this._inline = false;
|
---|
| 1002 | /** Subscription to the current in-progress SVG icon request. */
|
---|
| 1003 | _this._currentIconFetch = rxjs.Subscription.EMPTY;
|
---|
| 1004 | // If the user has not explicitly set aria-hidden, mark the icon as hidden, as this is
|
---|
| 1005 | // the right thing to do for the majority of icon use-cases.
|
---|
| 1006 | if (!ariaHidden) {
|
---|
| 1007 | elementRef.nativeElement.setAttribute('aria-hidden', 'true');
|
---|
| 1008 | }
|
---|
| 1009 | return _this;
|
---|
| 1010 | }
|
---|
| 1011 | Object.defineProperty(MatIcon.prototype, "inline", {
|
---|
| 1012 | /**
|
---|
| 1013 | * Whether the icon should be inlined, automatically sizing the icon to match the font size of
|
---|
| 1014 | * the element the icon is contained in.
|
---|
| 1015 | */
|
---|
| 1016 | get: function () {
|
---|
| 1017 | return this._inline;
|
---|
| 1018 | },
|
---|
| 1019 | set: function (inline) {
|
---|
| 1020 | this._inline = coercion.coerceBooleanProperty(inline);
|
---|
| 1021 | },
|
---|
| 1022 | enumerable: false,
|
---|
| 1023 | configurable: true
|
---|
| 1024 | });
|
---|
| 1025 | Object.defineProperty(MatIcon.prototype, "svgIcon", {
|
---|
| 1026 | /** Name of the icon in the SVG icon set. */
|
---|
| 1027 | get: function () { return this._svgIcon; },
|
---|
| 1028 | set: function (value) {
|
---|
| 1029 | if (value !== this._svgIcon) {
|
---|
| 1030 | if (value) {
|
---|
| 1031 | this._updateSvgIcon(value);
|
---|
| 1032 | }
|
---|
| 1033 | else if (this._svgIcon) {
|
---|
| 1034 | this._clearSvgElement();
|
---|
| 1035 | }
|
---|
| 1036 | this._svgIcon = value;
|
---|
| 1037 | }
|
---|
| 1038 | },
|
---|
| 1039 | enumerable: false,
|
---|
| 1040 | configurable: true
|
---|
| 1041 | });
|
---|
| 1042 | Object.defineProperty(MatIcon.prototype, "fontSet", {
|
---|
| 1043 | /** Font set that the icon is a part of. */
|
---|
| 1044 | get: function () { return this._fontSet; },
|
---|
| 1045 | set: function (value) {
|
---|
| 1046 | var newValue = this._cleanupFontValue(value);
|
---|
| 1047 | if (newValue !== this._fontSet) {
|
---|
| 1048 | this._fontSet = newValue;
|
---|
| 1049 | this._updateFontIconClasses();
|
---|
| 1050 | }
|
---|
| 1051 | },
|
---|
| 1052 | enumerable: false,
|
---|
| 1053 | configurable: true
|
---|
| 1054 | });
|
---|
| 1055 | Object.defineProperty(MatIcon.prototype, "fontIcon", {
|
---|
| 1056 | /** Name of an icon within a font set. */
|
---|
| 1057 | get: function () { return this._fontIcon; },
|
---|
| 1058 | set: function (value) {
|
---|
| 1059 | var newValue = this._cleanupFontValue(value);
|
---|
| 1060 | if (newValue !== this._fontIcon) {
|
---|
| 1061 | this._fontIcon = newValue;
|
---|
| 1062 | this._updateFontIconClasses();
|
---|
| 1063 | }
|
---|
| 1064 | },
|
---|
| 1065 | enumerable: false,
|
---|
| 1066 | configurable: true
|
---|
| 1067 | });
|
---|
| 1068 | /**
|
---|
| 1069 | * Splits an svgIcon binding value into its icon set and icon name components.
|
---|
| 1070 | * Returns a 2-element array of [(icon set), (icon name)].
|
---|
| 1071 | * The separator for the two fields is ':'. If there is no separator, an empty
|
---|
| 1072 | * string is returned for the icon set and the entire value is returned for
|
---|
| 1073 | * the icon name. If the argument is falsy, returns an array of two empty strings.
|
---|
| 1074 | * Throws an error if the name contains two or more ':' separators.
|
---|
| 1075 | * Examples:
|
---|
| 1076 | * `'social:cake' -> ['social', 'cake']
|
---|
| 1077 | * 'penguin' -> ['', 'penguin']
|
---|
| 1078 | * null -> ['', '']
|
---|
| 1079 | * 'a:b:c' -> (throws Error)`
|
---|
| 1080 | */
|
---|
| 1081 | MatIcon.prototype._splitIconName = function (iconName) {
|
---|
| 1082 | if (!iconName) {
|
---|
| 1083 | return ['', ''];
|
---|
| 1084 | }
|
---|
| 1085 | var parts = iconName.split(':');
|
---|
| 1086 | switch (parts.length) {
|
---|
| 1087 | case 1: return ['', parts[0]]; // Use default namespace.
|
---|
| 1088 | case 2: return parts;
|
---|
| 1089 | default: throw Error("Invalid icon name: \"" + iconName + "\""); // TODO: add an ngDevMode check
|
---|
| 1090 | }
|
---|
| 1091 | };
|
---|
| 1092 | MatIcon.prototype.ngOnInit = function () {
|
---|
| 1093 | // Update font classes because ngOnChanges won't be called if none of the inputs are present,
|
---|
| 1094 | // e.g. <mat-icon>arrow</mat-icon> In this case we need to add a CSS class for the default font.
|
---|
| 1095 | this._updateFontIconClasses();
|
---|
| 1096 | };
|
---|
| 1097 | MatIcon.prototype.ngAfterViewChecked = function () {
|
---|
| 1098 | var cachedElements = this._elementsWithExternalReferences;
|
---|
| 1099 | if (cachedElements && cachedElements.size) {
|
---|
| 1100 | var newPath = this._location.getPathname();
|
---|
| 1101 | // We need to check whether the URL has changed on each change detection since
|
---|
| 1102 | // the browser doesn't have an API that will let us react on link clicks and
|
---|
| 1103 | // we can't depend on the Angular router. The references need to be updated,
|
---|
| 1104 | // because while most browsers don't care whether the URL is correct after
|
---|
| 1105 | // the first render, Safari will break if the user navigates to a different
|
---|
| 1106 | // page and the SVG isn't re-rendered.
|
---|
| 1107 | if (newPath !== this._previousPath) {
|
---|
| 1108 | this._previousPath = newPath;
|
---|
| 1109 | this._prependPathToReferences(newPath);
|
---|
| 1110 | }
|
---|
| 1111 | }
|
---|
| 1112 | };
|
---|
| 1113 | MatIcon.prototype.ngOnDestroy = function () {
|
---|
| 1114 | this._currentIconFetch.unsubscribe();
|
---|
| 1115 | if (this._elementsWithExternalReferences) {
|
---|
| 1116 | this._elementsWithExternalReferences.clear();
|
---|
| 1117 | }
|
---|
| 1118 | };
|
---|
| 1119 | MatIcon.prototype._usingFontIcon = function () {
|
---|
| 1120 | return !this.svgIcon;
|
---|
| 1121 | };
|
---|
| 1122 | MatIcon.prototype._setSvgElement = function (svg) {
|
---|
| 1123 | this._clearSvgElement();
|
---|
| 1124 | // Workaround for IE11 and Edge ignoring `style` tags inside dynamically-created SVGs.
|
---|
| 1125 | // See: https://developer.microsoft.com/en-us/microsoft-edge/platform/issues/10898469/
|
---|
| 1126 | // Do this before inserting the element into the DOM, in order to avoid a style recalculation.
|
---|
| 1127 | var styleTags = svg.querySelectorAll('style');
|
---|
| 1128 | for (var i = 0; i < styleTags.length; i++) {
|
---|
| 1129 | styleTags[i].textContent += ' ';
|
---|
| 1130 | }
|
---|
| 1131 | // Note: we do this fix here, rather than the icon registry, because the
|
---|
| 1132 | // references have to point to the URL at the time that the icon was created.
|
---|
| 1133 | var path = this._location.getPathname();
|
---|
| 1134 | this._previousPath = path;
|
---|
| 1135 | this._cacheChildrenWithExternalReferences(svg);
|
---|
| 1136 | this._prependPathToReferences(path);
|
---|
| 1137 | this._elementRef.nativeElement.appendChild(svg);
|
---|
| 1138 | };
|
---|
| 1139 | MatIcon.prototype._clearSvgElement = function () {
|
---|
| 1140 | var layoutElement = this._elementRef.nativeElement;
|
---|
| 1141 | var childCount = layoutElement.childNodes.length;
|
---|
| 1142 | if (this._elementsWithExternalReferences) {
|
---|
| 1143 | this._elementsWithExternalReferences.clear();
|
---|
| 1144 | }
|
---|
| 1145 | // Remove existing non-element child nodes and SVGs, and add the new SVG element. Note that
|
---|
| 1146 | // we can't use innerHTML, because IE will throw if the element has a data binding.
|
---|
| 1147 | while (childCount--) {
|
---|
| 1148 | var child = layoutElement.childNodes[childCount];
|
---|
| 1149 | // 1 corresponds to Node.ELEMENT_NODE. We remove all non-element nodes in order to get rid
|
---|
| 1150 | // of any loose text nodes, as well as any SVG elements in order to remove any old icons.
|
---|
| 1151 | if (child.nodeType !== 1 || child.nodeName.toLowerCase() === 'svg') {
|
---|
| 1152 | layoutElement.removeChild(child);
|
---|
| 1153 | }
|
---|
| 1154 | }
|
---|
| 1155 | };
|
---|
| 1156 | MatIcon.prototype._updateFontIconClasses = function () {
|
---|
| 1157 | if (!this._usingFontIcon()) {
|
---|
| 1158 | return;
|
---|
| 1159 | }
|
---|
| 1160 | var elem = this._elementRef.nativeElement;
|
---|
| 1161 | var fontSetClass = this.fontSet ?
|
---|
| 1162 | this._iconRegistry.classNameForFontAlias(this.fontSet) :
|
---|
| 1163 | this._iconRegistry.getDefaultFontSetClass();
|
---|
| 1164 | if (fontSetClass != this._previousFontSetClass) {
|
---|
| 1165 | if (this._previousFontSetClass) {
|
---|
| 1166 | elem.classList.remove(this._previousFontSetClass);
|
---|
| 1167 | }
|
---|
| 1168 | if (fontSetClass) {
|
---|
| 1169 | elem.classList.add(fontSetClass);
|
---|
| 1170 | }
|
---|
| 1171 | this._previousFontSetClass = fontSetClass;
|
---|
| 1172 | }
|
---|
| 1173 | if (this.fontIcon != this._previousFontIconClass) {
|
---|
| 1174 | if (this._previousFontIconClass) {
|
---|
| 1175 | elem.classList.remove(this._previousFontIconClass);
|
---|
| 1176 | }
|
---|
| 1177 | if (this.fontIcon) {
|
---|
| 1178 | elem.classList.add(this.fontIcon);
|
---|
| 1179 | }
|
---|
| 1180 | this._previousFontIconClass = this.fontIcon;
|
---|
| 1181 | }
|
---|
| 1182 | };
|
---|
| 1183 | /**
|
---|
| 1184 | * Cleans up a value to be used as a fontIcon or fontSet.
|
---|
| 1185 | * Since the value ends up being assigned as a CSS class, we
|
---|
| 1186 | * have to trim the value and omit space-separated values.
|
---|
| 1187 | */
|
---|
| 1188 | MatIcon.prototype._cleanupFontValue = function (value) {
|
---|
| 1189 | return typeof value === 'string' ? value.trim().split(' ')[0] : value;
|
---|
| 1190 | };
|
---|
| 1191 | /**
|
---|
| 1192 | * Prepends the current path to all elements that have an attribute pointing to a `FuncIRI`
|
---|
| 1193 | * reference. This is required because WebKit browsers require references to be prefixed with
|
---|
| 1194 | * the current path, if the page has a `base` tag.
|
---|
| 1195 | */
|
---|
| 1196 | MatIcon.prototype._prependPathToReferences = function (path) {
|
---|
| 1197 | var elements = this._elementsWithExternalReferences;
|
---|
| 1198 | if (elements) {
|
---|
| 1199 | elements.forEach(function (attrs, element) {
|
---|
| 1200 | attrs.forEach(function (attr) {
|
---|
| 1201 | element.setAttribute(attr.name, "url('" + path + "#" + attr.value + "')");
|
---|
| 1202 | });
|
---|
| 1203 | });
|
---|
| 1204 | }
|
---|
| 1205 | };
|
---|
| 1206 | /**
|
---|
| 1207 | * Caches the children of an SVG element that have `url()`
|
---|
| 1208 | * references that we need to prefix with the current path.
|
---|
| 1209 | */
|
---|
| 1210 | MatIcon.prototype._cacheChildrenWithExternalReferences = function (element) {
|
---|
| 1211 | var elementsWithFuncIri = element.querySelectorAll(funcIriAttributeSelector);
|
---|
| 1212 | var elements = this._elementsWithExternalReferences =
|
---|
| 1213 | this._elementsWithExternalReferences || new Map();
|
---|
| 1214 | var _loop_1 = function (i) {
|
---|
| 1215 | funcIriAttributes.forEach(function (attr) {
|
---|
| 1216 | var elementWithReference = elementsWithFuncIri[i];
|
---|
| 1217 | var value = elementWithReference.getAttribute(attr);
|
---|
| 1218 | var match = value ? value.match(funcIriPattern) : null;
|
---|
| 1219 | if (match) {
|
---|
| 1220 | var attributes = elements.get(elementWithReference);
|
---|
| 1221 | if (!attributes) {
|
---|
| 1222 | attributes = [];
|
---|
| 1223 | elements.set(elementWithReference, attributes);
|
---|
| 1224 | }
|
---|
| 1225 | attributes.push({ name: attr, value: match[1] });
|
---|
| 1226 | }
|
---|
| 1227 | });
|
---|
| 1228 | };
|
---|
| 1229 | for (var i = 0; i < elementsWithFuncIri.length; i++) {
|
---|
| 1230 | _loop_1(i);
|
---|
| 1231 | }
|
---|
| 1232 | };
|
---|
| 1233 | /** Sets a new SVG icon with a particular name. */
|
---|
| 1234 | MatIcon.prototype._updateSvgIcon = function (rawName) {
|
---|
| 1235 | var _this = this;
|
---|
| 1236 | this._svgNamespace = null;
|
---|
| 1237 | this._svgName = null;
|
---|
| 1238 | this._currentIconFetch.unsubscribe();
|
---|
| 1239 | if (rawName) {
|
---|
| 1240 | var _a = __read(this._splitIconName(rawName), 2), namespace_1 = _a[0], iconName_1 = _a[1];
|
---|
| 1241 | if (namespace_1) {
|
---|
| 1242 | this._svgNamespace = namespace_1;
|
---|
| 1243 | }
|
---|
| 1244 | if (iconName_1) {
|
---|
| 1245 | this._svgName = iconName_1;
|
---|
| 1246 | }
|
---|
| 1247 | this._currentIconFetch = this._iconRegistry.getNamedSvgIcon(iconName_1, namespace_1)
|
---|
| 1248 | .pipe(operators.take(1))
|
---|
| 1249 | .subscribe(function (svg) { return _this._setSvgElement(svg); }, function (err) {
|
---|
| 1250 | var errorMessage = "Error retrieving icon " + namespace_1 + ":" + iconName_1 + "! " + err.message;
|
---|
| 1251 | _this._errorHandler.handleError(new Error(errorMessage));
|
---|
| 1252 | });
|
---|
| 1253 | }
|
---|
| 1254 | };
|
---|
| 1255 | return MatIcon;
|
---|
| 1256 | }(_MatIconBase));
|
---|
| 1257 | MatIcon.decorators = [
|
---|
| 1258 | { type: i0.Component, args: [{
|
---|
| 1259 | template: '<ng-content></ng-content>',
|
---|
| 1260 | selector: 'mat-icon',
|
---|
| 1261 | exportAs: 'matIcon',
|
---|
| 1262 | inputs: ['color'],
|
---|
| 1263 | host: {
|
---|
| 1264 | 'role': 'img',
|
---|
| 1265 | 'class': 'mat-icon notranslate',
|
---|
| 1266 | '[attr.data-mat-icon-type]': '_usingFontIcon() ? "font" : "svg"',
|
---|
| 1267 | '[attr.data-mat-icon-name]': '_svgName || fontIcon',
|
---|
| 1268 | '[attr.data-mat-icon-namespace]': '_svgNamespace || fontSet',
|
---|
| 1269 | '[class.mat-icon-inline]': 'inline',
|
---|
| 1270 | '[class.mat-icon-no-color]': 'color !== "primary" && color !== "accent" && color !== "warn"',
|
---|
| 1271 | },
|
---|
| 1272 | encapsulation: i0.ViewEncapsulation.None,
|
---|
| 1273 | changeDetection: i0.ChangeDetectionStrategy.OnPush,
|
---|
| 1274 | 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}\n"]
|
---|
| 1275 | },] }
|
---|
| 1276 | ];
|
---|
| 1277 | MatIcon.ctorParameters = function () { return [
|
---|
| 1278 | { type: i0.ElementRef },
|
---|
| 1279 | { type: MatIconRegistry },
|
---|
| 1280 | { type: String, decorators: [{ type: i0.Attribute, args: ['aria-hidden',] }] },
|
---|
| 1281 | { type: undefined, decorators: [{ type: i0.Inject, args: [MAT_ICON_LOCATION,] }] },
|
---|
| 1282 | { type: i0.ErrorHandler }
|
---|
| 1283 | ]; };
|
---|
| 1284 | MatIcon.propDecorators = {
|
---|
| 1285 | inline: [{ type: i0.Input }],
|
---|
| 1286 | svgIcon: [{ type: i0.Input }],
|
---|
| 1287 | fontSet: [{ type: i0.Input }],
|
---|
| 1288 | fontIcon: [{ type: i0.Input }]
|
---|
| 1289 | };
|
---|
| 1290 |
|
---|
| 1291 | /**
|
---|
| 1292 | * @license
|
---|
| 1293 | * Copyright Google LLC All Rights Reserved.
|
---|
| 1294 | *
|
---|
| 1295 | * Use of this source code is governed by an MIT-style license that can be
|
---|
| 1296 | * found in the LICENSE file at https://angular.io/license
|
---|
| 1297 | */
|
---|
| 1298 | var MatIconModule = /** @class */ (function () {
|
---|
| 1299 | function MatIconModule() {
|
---|
| 1300 | }
|
---|
| 1301 | return MatIconModule;
|
---|
| 1302 | }());
|
---|
| 1303 | MatIconModule.decorators = [
|
---|
| 1304 | { type: i0.NgModule, args: [{
|
---|
| 1305 | imports: [core.MatCommonModule],
|
---|
| 1306 | exports: [MatIcon, core.MatCommonModule],
|
---|
| 1307 | declarations: [MatIcon],
|
---|
| 1308 | },] }
|
---|
| 1309 | ];
|
---|
| 1310 |
|
---|
| 1311 | /**
|
---|
| 1312 | * @license
|
---|
| 1313 | * Copyright Google LLC All Rights Reserved.
|
---|
| 1314 | *
|
---|
| 1315 | * Use of this source code is governed by an MIT-style license that can be
|
---|
| 1316 | * found in the LICENSE file at https://angular.io/license
|
---|
| 1317 | */
|
---|
| 1318 |
|
---|
| 1319 | /**
|
---|
| 1320 | * Generated bundle index. Do not edit.
|
---|
| 1321 | */
|
---|
| 1322 |
|
---|
| 1323 | exports.ICON_REGISTRY_PROVIDER = ICON_REGISTRY_PROVIDER;
|
---|
| 1324 | exports.ICON_REGISTRY_PROVIDER_FACTORY = ICON_REGISTRY_PROVIDER_FACTORY;
|
---|
| 1325 | exports.MAT_ICON_LOCATION = MAT_ICON_LOCATION;
|
---|
| 1326 | exports.MAT_ICON_LOCATION_FACTORY = MAT_ICON_LOCATION_FACTORY;
|
---|
| 1327 | exports.MatIcon = MatIcon;
|
---|
| 1328 | exports.MatIconModule = MatIconModule;
|
---|
| 1329 | exports.MatIconRegistry = MatIconRegistry;
|
---|
| 1330 | exports.getMatIconFailedToSanitizeLiteralError = getMatIconFailedToSanitizeLiteralError;
|
---|
| 1331 | exports.getMatIconFailedToSanitizeUrlError = getMatIconFailedToSanitizeUrlError;
|
---|
| 1332 | exports.getMatIconNameNotFoundError = getMatIconNameNotFoundError;
|
---|
| 1333 | exports.getMatIconNoHttpProviderError = getMatIconNoHttpProviderError;
|
---|
| 1334 | exports.ɵ0 = ɵ0;
|
---|
| 1335 |
|
---|
| 1336 | Object.defineProperty(exports, '__esModule', { value: true });
|
---|
| 1337 |
|
---|
| 1338 | })));
|
---|
| 1339 | //# sourceMappingURL=material-icon.umd.js.map
|
---|