MyRepo-Ums/node_modules/@fortawesome/angular-fontawesome/esm2022/icon/icon.component.mjs

168 lines
21 KiB
JavaScript
Raw Normal View History

2024-01-19 10:09:11 +00:00
import { Component, HostBinding, Input, Optional } from '@angular/core';
import { icon, parse, } from '@fortawesome/fontawesome-svg-core';
import { faWarnIfIconDefinitionMissing } from '../shared/errors/warn-if-icon-html-missing';
import { faWarnIfIconSpecMissing } from '../shared/errors/warn-if-icon-spec-missing';
import { faClassList } from '../shared/utils/classlist.util';
import { faNormalizeIconSpec } from '../shared/utils/normalize-icon-spec.util';
import * as i0 from "@angular/core";
import * as i1 from "@angular/platform-browser";
import * as i2 from "../config";
import * as i3 from "../icon-library";
import * as i4 from "../stack/stack-item-size.directive";
import * as i5 from "../stack/stack.component";
export class FaIconComponent {
/**
* @deprecated Use animation="spin" instead. To be removed in 0.14.0.
*/
set spin(value) {
this.animation = value ? 'spin' : undefined;
}
/**
* @deprecated Use animation="spin-pulse" instead. To be removed in 0.14.0.
*/
set pulse(value) {
this.animation = value ? 'spin-pulse' : undefined;
}
constructor(sanitizer, config, iconLibrary, stackItem, stack) {
this.sanitizer = sanitizer;
this.config = config;
this.iconLibrary = iconLibrary;
this.stackItem = stackItem;
/**
* Set `class` attribute on the SVG element rendered by the component.
*
* @deprecated This input breaks view encapsulation and is not recommended.
* For simple cases (like colors), use `class` on the component itself, for
* more complex usages, explicitly opt-in to break the view encapsulation.
* This input is deprecated since 0.12.0 and will be removed in 0.13.0.
*/
this.classes = [];
if (stack != null && stackItem == null) {
console.error('FontAwesome: fa-icon and fa-duotone-icon elements must specify stackItemSize attribute when wrapped into ' +
'fa-stack. Example: <fa-icon stackItemSize="2x"></fa-icon>.');
}
}
ngOnChanges(changes) {
if (this.icon == null && this.config.fallbackIcon == null) {
faWarnIfIconSpecMissing();
return;
}
if (changes) {
const iconToBeRendered = this.icon != null ? this.icon : this.config.fallbackIcon;
const iconDefinition = this.findIconDefinition(iconToBeRendered);
if (iconDefinition != null) {
const params = this.buildParams();
this.renderIcon(iconDefinition, params);
}
}
}
/**
* Programmatically trigger rendering of the icon.
*
* This method is useful, when creating {@link FaIconComponent} dynamically or
* changing its inputs programmatically as in these cases icon won't be
* re-rendered automatically.
*/
render() {
this.ngOnChanges({});
}
findIconDefinition(i) {
const lookup = faNormalizeIconSpec(i, this.config.defaultPrefix);
if ('icon' in lookup) {
return lookup;
}
const definition = this.iconLibrary.getIconDefinition(lookup.prefix, lookup.iconName);
if (definition != null) {
return definition;
}
faWarnIfIconDefinitionMissing(lookup);
return null;
}
buildParams() {
const classOpts = {
flip: this.flip,
animation: this.animation,
border: this.border,
inverse: this.inverse,
size: this.size || null,
pull: this.pull || null,
rotate: this.rotate || null,
fixedWidth: typeof this.fixedWidth === 'boolean' ? this.fixedWidth : this.config.fixedWidth,
stackItemSize: this.stackItem != null ? this.stackItem.stackItemSize : null,
};
const parsedTransform = typeof this.transform === 'string' ? parse.transform(this.transform) : this.transform;
return {
title: this.title,
transform: parsedTransform,
classes: [...faClassList(classOpts), ...this.classes],
mask: this.mask != null ? this.findIconDefinition(this.mask) : null,
styles: this.styles != null ? this.styles : {},
symbol: this.symbol,
attributes: {
role: this.a11yRole,
},
};
}
renderIcon(definition, params) {
const renderedIcon = icon(definition, params);
this.renderedIconHTML = this.sanitizer.bypassSecurityTrustHtml(renderedIcon.html.join('\n'));
}
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.0.0", ngImport: i0, type: FaIconComponent, deps: [{ token: i1.DomSanitizer }, { token: i2.FaConfig }, { token: i3.FaIconLibrary }, { token: i4.FaStackItemSizeDirective, optional: true }, { token: i5.FaStackComponent, optional: true }], target: i0.ɵɵFactoryTarget.Component }); }
static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "17.0.0", type: FaIconComponent, isStandalone: true, selector: "fa-icon", inputs: { icon: "icon", title: "title", animation: "animation", spin: "spin", pulse: "pulse", mask: "mask", styles: "styles", flip: "flip", size: "size", pull: "pull", border: "border", inverse: "inverse", symbol: "symbol", rotate: "rotate", fixedWidth: "fixedWidth", classes: "classes", transform: "transform", a11yRole: "a11yRole" }, host: { properties: { "attr.title": "title", "innerHTML": "this.renderedIconHTML" }, classAttribute: "ng-fa-icon" }, usesOnChanges: true, ngImport: i0, template: ``, isInline: true }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.0.0", ngImport: i0, type: FaIconComponent, decorators: [{
type: Component,
args: [{
selector: 'fa-icon',
standalone: true,
template: ``,
host: {
class: 'ng-fa-icon',
'[attr.title]': 'title',
},
}]
}], ctorParameters: () => [{ type: i1.DomSanitizer }, { type: i2.FaConfig }, { type: i3.FaIconLibrary }, { type: i4.FaStackItemSizeDirective, decorators: [{
type: Optional
}] }, { type: i5.FaStackComponent, decorators: [{
type: Optional
}] }], propDecorators: { icon: [{
type: Input
}], title: [{
type: Input
}], animation: [{
type: Input
}], spin: [{
type: Input
}], pulse: [{
type: Input
}], mask: [{
type: Input
}], styles: [{
type: Input
}], flip: [{
type: Input
}], size: [{
type: Input
}], pull: [{
type: Input
}], border: [{
type: Input
}], inverse: [{
type: Input
}], symbol: [{
type: Input
}], rotate: [{
type: Input
}], fixedWidth: [{
type: Input
}], classes: [{
type: Input
}], transform: [{
type: Input
}], a11yRole: [{
type: Input
}], renderedIconHTML: [{
type: HostBinding,
args: ['innerHTML']
}] } });
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaWNvbi5jb21wb25lbnQuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi8uLi9zcmMvbGliL2ljb24vaWNvbi5jb21wb25lbnQudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsT0FBTyxFQUFFLFNBQVMsRUFBRSxXQUFXLEVBQUUsS0FBSyxFQUFhLFFBQVEsRUFBaUIsTUFBTSxlQUFlLENBQUM7QUFFbEcsT0FBTyxFQUdMLElB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