UNPKG

2.41 kBTypeScriptView Raw
1import React, { SVGProps, ReactNode, RefObject } from 'react';
2
3declare const STATUS: {
4 readonly IDLE: "idle";
5 readonly LOADING: "loading";
6 readonly LOADED: "loaded";
7 readonly FAILED: "failed";
8 readonly READY: "ready";
9 readonly UNSUPPORTED: "unsupported";
10};
11
12type ErrorCallback = (error: Error | FetchError) => void;
13type LoadCallback = (src: string, isCached: boolean) => void;
14type PlainObject<T = unknown> = Record<string, T>;
15type PreProcessorCallback = (code: string) => string;
16type Props = Simplify<Omit<SVGProps<SVGElement>, 'onLoad' | 'onError' | 'ref'> & {
17 baseURL?: string;
18 cacheRequests?: boolean;
19 children?: ReactNode;
20 description?: string;
21 fetchOptions?: RequestInit;
22 innerRef?: RefObject<SVGElement | null>;
23 loader?: ReactNode;
24 onError?: ErrorCallback;
25 onLoad?: LoadCallback;
26 preProcessor?: PreProcessorCallback;
27 src: string;
28 title?: string | null;
29 uniqueHash?: string;
30 uniquifyIDs?: boolean;
31}>;
32type Simplify<T> = {
33 [KeyType in keyof T]: T[KeyType];
34} & {};
35type Status = (typeof STATUS)[keyof typeof STATUS];
36interface FetchError extends Error {
37 code: string;
38 errno: string;
39 message: string;
40 type: string;
41}
42interface State {
43 content: string;
44 element: ReactNode;
45 isCached: boolean;
46 status: Status;
47}
48interface StorageItem {
49 content: string;
50 status: Status;
51}
52
53declare class CacheStore {
54 private cacheApi;
55 private readonly cacheStore;
56 private readonly subscribers;
57 isReady: boolean;
58 constructor();
59 onReady(callback: () => void): void;
60 get(url: string, fetchOptions?: RequestInit): Promise<string>;
61 set(url: string, data: StorageItem): void;
62 isCached(url: string): boolean;
63 private fetchAndAddToInternalCache;
64 private fetchAndAddToPersistentCache;
65 private handleLoading;
66 keys(): Array<string>;
67 data(): Array<Record<string, StorageItem>>;
68 delete(url: string): Promise<void>;
69 clear(): Promise<void>;
70}
71
72declare let cacheStore: CacheStore;
73declare function InlineSVG(props: Props): string | number | boolean | Iterable<React.ReactNode> | React.JSX.Element | null | undefined;
74
75export { type ErrorCallback, type FetchError, type LoadCallback, type PlainObject, type PreProcessorCallback, type Props, type Simplify, type State, type Status, type StorageItem, cacheStore, InlineSVG as default };
76export = InlineSVG
\No newline at end of file