123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109 |
- import { Directive, Input } from '@angular/core';
- import { alreadyHasAThemeSuffix, getNameAndNamespace, isIconDefinition, warn, withSuffix } from '../utils';
- import * as i0 from "@angular/core";
- import * as i1 from "./icon.service";
- function checkMeta(prev, after) {
- return prev.type === after.type && prev.theme === after.theme && prev.twoToneColor === after.twoToneColor;
- }
- class IconDirective {
- constructor(_iconService, _elementRef, _renderer) {
- this._iconService = _iconService;
- this._elementRef = _elementRef;
- this._renderer = _renderer;
- }
- ngOnChanges(changes) {
- if (changes.type || changes.theme || changes.twoToneColor) {
- this._changeIcon();
- }
- }
-
- _changeIcon() {
- return new Promise(resolve => {
- if (!this.type) {
- this._clearSVGElement();
- resolve(null);
- return;
- }
- const beforeMeta = this._getSelfRenderMeta();
- this._iconService.getRenderedContent(this._parseIconType(this.type, this.theme), this.twoToneColor).subscribe(svg => {
-
-
- const afterMeta = this._getSelfRenderMeta();
- if (checkMeta(beforeMeta, afterMeta)) {
- this._setSVGElement(svg);
- resolve(svg);
- }
- else {
- resolve(null);
- }
- });
- });
- }
- _getSelfRenderMeta() {
- return {
- type: this.type,
- theme: this.theme,
- twoToneColor: this.twoToneColor
- };
- }
-
- _parseIconType(type, theme) {
- if (isIconDefinition(type)) {
- return type;
- }
- else {
- const [name, namespace] = getNameAndNamespace(type);
- if (namespace) {
- return type;
- }
- if (alreadyHasAThemeSuffix(name)) {
- if (!!theme) {
- warn(`'type' ${name} already gets a theme inside so 'theme' ${theme} would be ignored`);
- }
- return name;
- }
- else {
- return withSuffix(name, theme || this._iconService.defaultTheme);
- }
- }
- }
- _setSVGElement(svg) {
- this._clearSVGElement();
- this._renderer.appendChild(this._elementRef.nativeElement, svg);
- }
- _clearSVGElement() {
- const el = this._elementRef.nativeElement;
- const children = el.childNodes;
- const length = children.length;
- for (let i = length - 1; i >= 0; i--) {
- const child = children[i];
- if (child.tagName?.toLowerCase() === 'svg') {
- this._renderer.removeChild(el, child);
- }
- }
- }
- static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.0.2", ngImport: i0, type: IconDirective, deps: [{ token: i1.IconService }, { token: i0.ElementRef }, { token: i0.Renderer2 }], target: i0.ɵɵFactoryTarget.Directive }); }
- static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "16.0.2", type: IconDirective, selector: "[antIcon]", inputs: { type: "type", theme: "theme", twoToneColor: "twoToneColor" }, usesOnChanges: true, ngImport: i0 }); }
- }
- export { IconDirective };
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.0.2", ngImport: i0, type: IconDirective, decorators: [{
- type: Directive,
- args: [{
- selector: '[antIcon]'
- }]
- }], ctorParameters: function () { return [{ type: i1.IconService }, { type: i0.ElementRef }, { type: i0.Renderer2 }]; }, propDecorators: { type: [{
- type: Input
- }], theme: [{
- type: Input
- }], twoToneColor: [{
- type: Input
- }] } });
|