iconify.without-api.d.ts 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279
  1. import { IconifyIcon } from '@iconify/types';
  2. import { IconifyJSON } from '@iconify/types';
  3. import { IconifyTransformations } from '@iconify/types';
  4. /**
  5. * Add icon set
  6. */
  7. export declare function addCollection(data: IconifyJSON, provider?: string): boolean;
  8. /**
  9. * Add one icon
  10. */
  11. export declare function addIcon(name: string, data: IconifyIcon): boolean;
  12. /**
  13. * Get SVG attributes and content from icon + customisations
  14. *
  15. * Does not generate style to make it compatible with frameworks that use objects for style, such as React.
  16. * Instead, it generates 'inline' value. If true, rendering engine should add verticalAlign: -0.125em to icon.
  17. *
  18. * Customisations should be normalised by platform specific parser.
  19. * Result should be converted to <svg> by platform specific parser.
  20. * Use replaceIDs to generate unique IDs for body.
  21. */
  22. export declare function buildIcon(icon: IconifyIcon, customisations?: IconifyIconCustomisations_2): IconifyIconBuildResult;
  23. /**
  24. * Calculate second dimension when only 1 dimension is set
  25. */
  26. export declare function calculateSize(size: string, ratio: number, precision?: number): string;
  27. export declare function calculateSize(size: number, ratio: number, precision?: number): number;
  28. export declare function calculateSize(size: string | number, ratio: number, precision?: number): string | number;
  29. /**
  30. * Callback
  31. */
  32. declare type GetHTMLElement = () => HTMLElement | null;
  33. /**
  34. * Get full icon
  35. */
  36. export declare function getIcon(name: string): Required<IconifyIcon> | null;
  37. /**
  38. * Get version
  39. */
  40. export declare function getVersion(): string;
  41. /**
  42. * Check if icon exists
  43. */
  44. export declare function iconExists(name: string): boolean;
  45. /**
  46. * Global variable
  47. */
  48. declare const Iconify: IconifyGlobal;
  49. export default Iconify;
  50. /**
  51. * Interface for exported builder functions
  52. */
  53. export declare interface IconifyBuilderFunctions {
  54. replaceIDs?: (body: string, prefix?: string | (() => string)) => string;
  55. calculateSize: (size: string | number, ratio: number, precision?: number) => string | number;
  56. buildIcon: (icon: IconifyIcon, customisations?: IconifyIconCustomisations_2) => IconifyIconBuildResult;
  57. }
  58. /**
  59. * Iconify interface
  60. */
  61. declare interface IconifyCommonFunctions {
  62. /**
  63. * Get version
  64. */
  65. getVersion: () => string;
  66. /**
  67. * Render icons
  68. */
  69. renderSVG: (name: string, customisations?: IconifyIconCustomisations_2) => SVGElement | null;
  70. renderHTML: (name: string, customisations?: IconifyIconCustomisations_2) => string | null;
  71. /**
  72. * Get icon data
  73. */
  74. renderIcon: (name: string, customisations?: IconifyIconCustomisations_2) => IconifyIconBuildResult | null;
  75. /**
  76. * Scan DOM
  77. */
  78. scan: (root?: HTMLElement) => void;
  79. /**
  80. * Add root node
  81. */
  82. observe: (root: HTMLElement) => void;
  83. /**
  84. * Remove root node
  85. */
  86. stopObserving: (root: HTMLElement) => void;
  87. /**
  88. * Pause observer
  89. */
  90. pauseObserver: (root?: HTMLElement) => void;
  91. /**
  92. * Resume observer
  93. */
  94. resumeObserver: (root?: HTMLElement) => void;
  95. }
  96. /**
  97. * Iconify interface
  98. */
  99. export declare interface IconifyGlobal extends IconifyStorageFunctions, IconifyBuilderFunctions, IconifyCommonFunctions {
  100. }
  101. export { IconifyIcon }
  102. /**
  103. * Interface for getSVGData() result
  104. */
  105. export declare interface IconifyIconBuildResult {
  106. attributes: {
  107. width?: string;
  108. height?: string;
  109. viewBox: string;
  110. };
  111. body: string;
  112. }
  113. /**
  114. * Add inline to customisations
  115. */
  116. export declare interface IconifyIconCustomisations extends IconifyIconCustomisations_2 {
  117. inline?: boolean;
  118. }
  119. /**
  120. * Icon customisations
  121. */
  122. declare interface IconifyIconCustomisations_2 extends IconifyTransformations, IconifyIconSizeCustomisations {
  123. }
  124. /**
  125. * Icon name
  126. */
  127. export declare interface IconifyIconName {
  128. readonly provider: string;
  129. readonly prefix: string;
  130. readonly name: string;
  131. }
  132. /**
  133. * Icon size
  134. */
  135. export declare type IconifyIconSize = null | string | number;
  136. /**
  137. * Dimensions
  138. */
  139. declare interface IconifyIconSizeCustomisations {
  140. width?: IconifyIconSize;
  141. height?: IconifyIconSize;
  142. }
  143. export { IconifyJSON }
  144. /**
  145. * Icon render mode
  146. *
  147. * 'style' = 'bg' or 'mask', depending on icon content
  148. * 'bg' = add inline style to placeholder using `background`
  149. * 'mask' = add inline style to placeholder using `mask`
  150. * 'svg' = <svg>
  151. */
  152. export declare type IconifyRenderMode = 'style' | 'bg' | 'mask' | 'svg';
  153. /**
  154. * Interface for exported storage functions
  155. */
  156. export declare interface IconifyStorageFunctions {
  157. /**
  158. * Check if icon exists
  159. */
  160. iconExists: (name: string) => boolean;
  161. /**
  162. * Get icon data with all properties
  163. */
  164. getIcon: (name: string) => Required<IconifyIcon> | null;
  165. /**
  166. * List all available icons
  167. */
  168. listIcons: (provider?: string, prefix?: string) => string[];
  169. /**
  170. * Add icon to storage
  171. */
  172. addIcon: (name: string, data: IconifyIcon) => boolean;
  173. /**
  174. * Add icon set to storage
  175. */
  176. addCollection: (data: IconifyJSON, provider?: string) => boolean;
  177. }
  178. /**
  179. * List available icons
  180. */
  181. export declare function listIcons(provider?: string, prefix?: string): string[];
  182. /**
  183. * Observe node
  184. */
  185. export declare function observe(root: HTMLElement, autoRemove?: boolean): ObservedNode;
  186. /**
  187. * Observed node type
  188. */
  189. declare interface ObservedNode {
  190. node: HTMLElement | GetHTMLElement;
  191. temporary?: boolean;
  192. observer?: {
  193. instance?: MutationObserver;
  194. paused: number;
  195. pendingScan?: unknown;
  196. };
  197. }
  198. /**
  199. * Pause observer
  200. */
  201. export declare function pauseObserver(root?: HTMLElement): void;
  202. /**
  203. * Generate SVG as string
  204. */
  205. export declare function renderHTML(name: string, customisations?: IconifyIconCustomisations_2): string | null;
  206. /**
  207. * Get rendered icon as object that can be used to create SVG (use replaceIDs on body)
  208. */
  209. export declare function renderIcon(name: string, customisations?: IconifyIconCustomisations_2): IconifyIconBuildResult | null;
  210. /**
  211. * Generate SVG element
  212. */
  213. export declare function renderSVG(name: string, customisations?: IconifyIconCustomisations_2): SVGElement | null;
  214. /**
  215. * IDs usage:
  216. *
  217. * id="{id}"
  218. * xlink:href="#{id}"
  219. * url(#{id})
  220. *
  221. * From SVG animations:
  222. *
  223. * begin="0;{id}.end"
  224. * begin="{id}.end"
  225. * begin="{id}.click"
  226. */
  227. /**
  228. * Replace IDs in SVG output with unique IDs
  229. */
  230. export declare function replaceIDs(body: string, prefix?: string | ((id: string) => string)): string;
  231. /**
  232. * Resume observer
  233. */
  234. export declare function resumeObserver(root?: HTMLElement): void;
  235. /**
  236. * Scan DOM
  237. */
  238. export declare function scan(root?: HTMLElement): void;
  239. /**
  240. * Remove observed node
  241. */
  242. export declare function stopObserving(root: HTMLElement): void;
  243. export { }