UNPKG

@obliczeniowo/elementary

Version:
127 lines (122 loc) 4.23 kB
import * as i0 from '@angular/core'; import { OnDestroy, ElementRef } from '@angular/core'; import { HttpClient } from '@angular/common/http'; import { SafeHtml, DomSanitizer } from '@angular/platform-browser'; import { Observable } from 'rxjs'; import * as i2 from '@angular/common'; interface Icon { svgString?: string; url: SafeHtml; name: string; } /** * Registering icons service for icon.component * * Registering own: * @example * * constructor(private iconResource: IconResourceService) { * iconResource.registerIcon( * this.sanitizer.bypassSecurityTrustHtml('/assets/icons/your-icon.svg'), * 'icon-name' * ); * } * * @ * Use in html with icon component: * * @example * * <obl-icon [width]="20" name="icon-name"></obl-icon> * * @ To correctly work in library component you need to copy assets folder adding script to npm: * * @example * * "copy-assets": "node ./node_modules/@obliczeniowo/elementary/assets/scripts/copy.js ./src/assets/", * * @ and run in console: * * @example * npm run copy-assets */ declare class IconResourceService implements OnDestroy { private readonly http; private readonly sanitizer; private readonly document; protected icons: Map<string, Icon>; protected urls: Map<string, Partial<Partial<Icon>>>; protected loading: Map<string, Promise<string | undefined>>; protected base: string; constructor(http: HttpClient, sanitizer: DomSanitizer, document: Document); /** * Registering own: * @param url SafeHTML object with path to icon in your asset folder * @param name your icon name * * @example * * constructor(private iconResource: IconResourceService) { * iconResource.registerIcon( * this.sanitizer.bypassSecurityTrustHtml('/assets/icons/your-icon.svg'), * 'icon-name' * ); * } * * @ * Use in html with icon component: * * @example * * <obl-icon [width]="20" name="icon-name"></obl-icon> */ registerIcon(url: SafeHtml, name: string): void; /** * Download once icon from server and keep it in buffer * @param name name of icon * @returns observable with SVGSVGElement or undefined */ getIcon(name: string): Observable<SVGSVGElement | undefined>; /** * Register url to SVG file * @param url url string * @returns SVGSVGElement/undefined or throwing error */ fromUrl(url: string): Observable<SVGSVGElement | undefined>; protected _fromUrl(url: string, cb?: (svg: string) => void, cbError?: () => Error): Observable<SVGSVGElement | undefined>; ngOnDestroy(): void; protected err(name?: string, url?: string): Error; protected createSvgFromString(svgString: string): SVGSVGElement | undefined; static ɵfac: i0.ɵɵFactoryDeclaration<IconResourceService, never>; static ɵprov: i0.ɵɵInjectableDeclaration<IconResourceService>; } /** * Icon component that let you display registered icon with IconResourceService * * @example * * <obl-icon name="search" [size]="20"></obl-icon> */ declare class IconComponent { protected iconResource: IconResourceService; protected elementRef: ElementRef<HTMLElement>; /** * registered icon name */ name: i0.InputSignal<string>; /** * Width in px or css like things */ width: i0.InputSignal<string | number>; get widthStyle(): string | number; constructor(iconResource: IconResourceService, elementRef: ElementRef<HTMLElement>); static ɵfac: i0.ɵɵFactoryDeclaration<IconComponent, never>; static ɵcmp: i0.ɵɵComponentDeclaration<IconComponent, "obl-icon", never, { "name": { "alias": "name"; "required": true; "isSignal": true; }; "width": { "alias": "width"; "required": false; "isSignal": true; }; }, {}, never, never, false, never>; } declare class IconsModule { static ɵfac: i0.ɵɵFactoryDeclaration<IconsModule, never>; static ɵmod: i0.ɵɵNgModuleDeclaration<IconsModule, [typeof IconComponent], [typeof i2.CommonModule], [typeof IconComponent]>; static ɵinj: i0.ɵɵInjectorDeclaration<IconsModule>; } export { IconComponent, IconResourceService, IconsModule }; export type { Icon };