@obliczeniowo/elementary
Version:
Library made in Angular version 19
92 lines (91 loc) • 2.9 kB
TypeScript
import { HttpClient } from '@angular/common/http';
import { OnDestroy } from '@angular/core';
import { DomSanitizer, SafeHtml } from '@angular/platform-browser';
import { Observable } from 'rxjs';
import * as i0 from "@angular/core";
export 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
*/
export 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>;
}