icon.service.d.ts 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. import { HttpBackend, HttpClient } from '@angular/common/http';
  2. import { InjectionToken, Renderer2, RendererFactory2 } from '@angular/core';
  3. import { DomSanitizer } from '@angular/platform-browser';
  4. import { Observable } from 'rxjs';
  5. import { CachedIconDefinition, IconDefinition, ThemeType, TwoToneColorPalette, TwoToneColorPaletteSetter } from '../types';
  6. import * as i0 from "@angular/core";
  7. export declare const ANT_ICONS: InjectionToken<IconDefinition[]>;
  8. export declare class IconService {
  9. protected _rendererFactory: RendererFactory2;
  10. protected _handler: HttpBackend;
  11. protected _document: any;
  12. protected sanitizer: DomSanitizer;
  13. protected _antIcons: IconDefinition[];
  14. defaultTheme: ThemeType;
  15. set twoToneColor({ primaryColor, secondaryColor }: TwoToneColorPaletteSetter);
  16. get twoToneColor(): TwoToneColorPaletteSetter;
  17. protected _renderer: Renderer2;
  18. protected _http: HttpClient;
  19. /**
  20. * Disable dynamic loading (support static loading only).
  21. */
  22. protected get _disableDynamicLoading(): boolean;
  23. /**
  24. * All icon definitions would be registered here.
  25. */
  26. protected readonly _svgDefinitions: Map<string, IconDefinition>;
  27. /**
  28. * Cache all rendered icons. Icons are identified by name, theme,
  29. * and for twotone icons, primary color and secondary color.
  30. */
  31. protected readonly _svgRenderedDefinitions: Map<string, CachedIconDefinition>;
  32. protected _inProgressFetches: Map<string, Observable<IconDefinition | null>>;
  33. /**
  34. * Url prefix for fetching inline SVG by dynamic importing.
  35. */
  36. protected _assetsUrlRoot: string;
  37. protected _twoToneColorPalette: TwoToneColorPalette;
  38. /** A flag indicates whether jsonp loading is enabled. */
  39. private _enableJsonpLoading;
  40. private readonly _jsonpIconLoad$;
  41. constructor(_rendererFactory: RendererFactory2, _handler: HttpBackend, _document: any, sanitizer: DomSanitizer, _antIcons: IconDefinition[]);
  42. /**
  43. * Call this method to switch to jsonp like loading.
  44. */
  45. useJsonpLoading(): void;
  46. /**
  47. * Change the prefix of the inline svg resources, so they could be deployed elsewhere, like CDN.
  48. * @param prefix
  49. */
  50. changeAssetsSource(prefix: string): void;
  51. /**
  52. * Add icons provided by ant design.
  53. * @param icons
  54. */
  55. addIcon(...icons: IconDefinition[]): void;
  56. /**
  57. * Register an icon. Namespace is required.
  58. * @param type
  59. * @param literal
  60. */
  61. addIconLiteral(type: string, literal: string): void;
  62. /**
  63. * Remove all cache.
  64. */
  65. clear(): void;
  66. /**
  67. * Get a rendered `SVGElement`.
  68. * @param icon
  69. * @param twoToneColor
  70. */
  71. getRenderedContent(icon: IconDefinition | string, twoToneColor?: string): Observable<SVGElement>;
  72. getCachedIcons(): Map<string, IconDefinition>;
  73. /**
  74. * Get raw svg and assemble a `IconDefinition` object.
  75. * @param type
  76. */
  77. protected _loadIconDynamically(type: string): Observable<IconDefinition | null>;
  78. protected _loadIconDynamicallyWithJsonp(icon: IconDefinition, url: string): Observable<IconDefinition>;
  79. /**
  80. * Render a new `SVGElement` for a given `IconDefinition`, or make a copy from cache.
  81. * @param icon
  82. * @param twoToneColor
  83. */
  84. protected _loadSVGFromCacheOrCreateNew(icon: IconDefinition, twoToneColor?: string): SVGElement;
  85. protected _createSVGElementFromString(str: string): SVGElement;
  86. protected _setSVGAttribute(svg: SVGElement): SVGElement;
  87. protected _colorizeSVGIcon(svg: SVGElement, twotone: boolean, pri: string, sec: string): SVGElement;
  88. static ɵfac: i0.ɵɵFactoryDeclaration<IconService, [null, { optional: true; }, { optional: true; }, null, { optional: true; }]>;
  89. static ɵprov: i0.ɵɵInjectableDeclaration<IconService>;
  90. }