UNPKG

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