react-inlinesvg 4.2.0 → 4.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # react-inlinesvg
2
2
 
3
- [![NPM version](https://badge.fury.io/js/react-inlinesvg.svg)](https://www.npmjs.com/package/react-inlinesvg) [![CI](https://github.com/gilbarbara/react-inlinesvg/actions/workflows/main.yml/badge.svg)](https://github.com/gilbarbara/react-inlinesvg/actions/workflows/main.yml) [![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=gilbarbara_react-inlinesvg&metric=alert_status)](https://sonarcloud.io/summary/new_code?id=gilbarbara_react-inlinesvg) [![Coverage](https://sonarcloud.io/api/project_badges/measure?project=gilbarbara_react-inlinesvg&metric=coverage)](https://sonarcloud.io/summary/new_code?id=gilbarbara_react-inlinesvg)
3
+ [![NPM version](https://badge.fury.io/js/react-inlinesvg.svg)](https://www.npmjs.com/package/react-inlinesvg) [![CI](https://github.com/gilbarbara/react-inlinesvg/actions/workflows/ci.yml/badge.svg)](https://github.com/gilbarbara/react-inlinesvg/actions/workflows/ci.yml) [![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=gilbarbara_react-inlinesvg&metric=alert_status)](https://sonarcloud.io/summary/new_code?id=gilbarbara_react-inlinesvg) [![Coverage](https://sonarcloud.io/api/project_badges/measure?project=gilbarbara_react-inlinesvg&metric=coverage)](https://sonarcloud.io/summary/new_code?id=gilbarbara_react-inlinesvg)
4
4
 
5
5
  Load inline, local, or remote SVGs in your React components.
6
6
 
@@ -11,8 +11,7 @@ View the [demo](https://codesandbox.io/s/github/gilbarbara/react-inlinesvg/tree/
11
11
  - 🏖 **Easy to use:** Just set the `src`
12
12
  - 🛠 **Flexible:** Personalize the options to fit your needs
13
13
  - ⚡️ **Smart:** Async requests will be cached.
14
- - 🚀 **SSR:** Render a loader until the DOM is available
15
- - 🟦 **Typescript:** Nicely typed
14
+ - 🚀 **SSR:** Safe for server-side rendering
16
15
 
17
16
  ## Usage
18
17
 
@@ -23,14 +22,13 @@ npm i react-inlinesvg
23
22
  And import it into your code:
24
23
 
25
24
  ```tsx
26
- import React from 'react';
27
25
  import SVG from 'react-inlinesvg';
28
26
 
29
27
  export default function App() {
30
28
  return (
31
29
  <main>
32
30
  <SVG
33
- src="https://cdn.svgporn.com/logos/react.svg"
31
+ src="https://cdn.svglogos.dev/logos/react.svg"
34
32
  width={128}
35
33
  height="auto"
36
34
  title="React"
@@ -42,12 +40,15 @@ export default function App() {
42
40
 
43
41
  ## Props
44
42
 
45
- **src** {string} - **required**.
46
- The SVG file you want to load. It can be a require, URL, or a string (base64 or URL encoded).
47
- _If you are using create-react-app and your file resides in the `public` directory, you can use the path directly without require._
43
+ **src** {string} - **required**.
44
+ The SVG to load. It accepts:
48
45
 
49
- **baseURL** {string}
50
- An URL to prefix each ID in case you use the `<base>` tag and `uniquifyIDs`.
46
+ - A URL or path to an SVG file (absolute or relative, including from a bundler import)
47
+ - A data URI (base64 or URL-encoded)
48
+ - A raw SVG string
49
+
50
+ **baseURL** {string}
51
+ A URL to prepend to `url()` references inside the SVG when using `uniquifyIDs`. Required if your page uses an HTML `<base>` tag.
51
52
 
52
53
  **children** {ReactNode}
53
54
  The fallback content in case of a fetch error or unsupported browser.
@@ -58,9 +59,8 @@ The fallback content in case of a fetch error or unsupported browser.
58
59
  </SVG>
59
60
  ```
60
61
 
61
- **cacheRequests** {boolean} ▶︎ `true`
62
- Cache remote SVGs.
63
- Starting in version 4.x, you can also cache the files permanently, read more [below](#caching).
62
+ **cacheRequests** {boolean} ▶︎ `true`
63
+ Cache remote SVGs in memory. When used with the [CacheProvider](#caching), requests are also persisted in the browser cache.
64
64
 
65
65
  **description** {string}
66
66
  A description for your SVG. It will override an existing `<desc>` tag.
@@ -68,8 +68,8 @@ A description for your SVG. It will override an existing `<desc>` tag.
68
68
  **fetchOptions** {RequestInit}
69
69
  Custom options for the [request](https://developer.mozilla.org/en-US/docs/Web/API/Request/Request).
70
70
 
71
- **innerRef** {React.Ref}
72
- Set a ref in SVGElement.
71
+ **innerRef** {React.Ref\<SVGElement | null>}
72
+ Set a ref on the SVG element.
73
73
 
74
74
  >The SVG is processed and parsed so the ref won't be set on the initial render.
75
75
  You can use the `onLoad` callback to get and use the ref instead.
@@ -92,22 +92,14 @@ This will receive a single argument with:
92
92
  }
93
93
  ```
94
94
 
95
- - or an `InlineSVGError`, which has the following properties:
96
-
97
- ```typescript
98
- {
99
- name: 'InlineSVGError';
100
- data: object; // optional
101
- message: string;
102
- }
103
- ```
95
+ - or an `Error` for issues like missing `src`, unsupported browser, or invalid SVG content.
104
96
 
105
97
  **onLoad** {function}.
106
98
  A callback to be invoked upon successful load.
107
99
  This will receive 2 arguments: the `src` prop and an `isCached` boolean
108
100
 
109
- **preProcessor** {function} ▶︎ `string`
110
- A function to process the contents of the SVG text before parsing.
101
+ **preProcessor** {function}
102
+ A function to pre-process the SVG string before parsing. Receives the SVG string and must return a string.
111
103
 
112
104
  **title** {string | null}
113
105
  A title for your SVG. It will override an existing `<title>` tag.
@@ -123,7 +115,7 @@ Create unique IDs for each icon.
123
115
 
124
116
  ### Example
125
117
 
126
- ```jsx
118
+ ```tsx
127
119
  <SVG
128
120
  baseURL="/home"
129
121
  cacheRequests={true}
@@ -132,7 +124,7 @@ Create unique IDs for each icon.
132
124
  onError={(error) => console.log(error.message)}
133
125
  onLoad={(src, isCached) => console.log(src, isCached)}
134
126
  preProcessor={(code) => code.replace(/fill=".*?"/g, 'fill="currentColor"')}
135
- src="https://cdn.svgporn.com/logos/react.svg"
127
+ src="https://cdn.svglogos.dev/logos/react.svg"
136
128
  title="React"
137
129
  uniqueHash="a1f8d1"
138
130
  uniquifyIDs={true}
@@ -144,7 +136,7 @@ Create unique IDs for each icon.
144
136
  You can use the browser's cache to store the SVGs permanently.
145
137
  To set it up, wrap your app with the cache provider:
146
138
 
147
- ```typescript
139
+ ```tsx
148
140
  import { createRoot } from 'react-dom/client';
149
141
  import CacheProvider from 'react-inlinesvg/provider';
150
142
  import App from './App';
@@ -156,21 +148,23 @@ createRoot(document.getElementById('root')!).render(
156
148
  );
157
149
  ```
158
150
 
151
+ The `CacheProvider` accepts an optional `name` prop to customize the cache storage name.
152
+
159
153
  > Be aware of the limitations of the [Cache API](https://developer.mozilla.org/en-US/docs/Web/API/Cache).
160
154
 
161
155
  ## Browser Support
162
156
 
163
- Any browsers that support inlining [SVGs](https://developer.mozilla.org/en-US/docs/Web/SVG/Element/svg) and [fetch](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API) will work.
157
+ Any browser that supports inlining [SVGs](https://developer.mozilla.org/en-US/docs/Web/SVG/Element/svg) and [fetch](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API) will work.
164
158
 
165
- If you need to support legacy browsers, include a polyfill for `fetch` and `Number.isNaN` in your app.
159
+ If you need to support legacy browsers, include a polyfill for `fetch` in your app.
166
160
 
167
161
  ## CORS
168
162
 
169
- If you are loading remote SVGs, you must ensure it has [CORS](https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS) support.
163
+ If you are loading remote SVGs, you must ensure they have [CORS](https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS) headers.
170
164
 
171
165
  ## Why do you need this package?
172
166
 
173
- One of the reasons SVGs are awesome is that you can style them with CSS.
167
+ One reason SVGs are awesome is that you can style them with CSS.
174
168
  Unfortunately, this is not useful in practice because the style element has to be in the same document. This leaves you with three bad options:
175
169
 
176
170
  1. Embed the CSS in the SVG document
@@ -192,7 +186,7 @@ But there's an alternative that sidesteps these issues: load the SVG with a GET
192
186
 
193
187
  ### Note
194
188
 
195
- The SVG [`<use>`](http://css-tricks.com/svg-use-external-source) element can be used to achieve something similar to this component. See [this article](http://taye.me/blog/svg/a-guide-to-svg-use-elements) for more information and [this table](https://developer.mozilla.org/en-US/docs/Web/SVG/Element/use#Browser_compatibility) for browser support and caveats.
189
+ The SVG [`<use>`](https://css-tricks.com/svg-use-external-source/) element can be used to achieve something similar to this component. See [this article](https://taye.me/blog/svg/a-guide-to-svg-use-elements) for more information and [this table](https://developer.mozilla.org/en-US/docs/Web/SVG/Element/use#Browser_compatibility) for browser support and caveats.
196
190
 
197
191
  ## Credits
198
192
 
@@ -0,0 +1,142 @@
1
+ import { SVGProps, ReactNode, Ref } from 'react';
2
+
3
+ declare 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
+
12
+ /**
13
+ * Called when loading the SVG fails.
14
+ */
15
+ type ErrorCallback = (error: Error | FetchError) => void;
16
+ /**
17
+ * Called when the SVG loads successfully.
18
+ */
19
+ type LoadCallback = (src: string, isCached: boolean) => void;
20
+ /**
21
+ * Pre-processes the SVG string before parsing.
22
+ * Must return a string.
23
+ */
24
+ type PreProcessorCallback = (code: string) => string;
25
+ type Props = Simplify<Omit<SVGProps<SVGElement>, 'onLoad' | 'onError' | 'ref'> & {
26
+ /**
27
+ * A URL to prepend to url() references inside the SVG when using `uniquifyIDs`.
28
+ * Only required if your page uses an HTML `<base>` tag.
29
+ */
30
+ baseURL?: string;
31
+ /**
32
+ * Cache remote SVGs in memory.
33
+ *
34
+ * When used with the CacheProvider, requests are also persisted in the browser cache.
35
+ * @default true
36
+ */
37
+ cacheRequests?: boolean;
38
+ /**
39
+ * Fallback content rendered on fetch error or unsupported browser.
40
+ */
41
+ children?: ReactNode;
42
+ /**
43
+ * A description for the SVG.
44
+ * Overrides an existing `<desc>` tag.
45
+ */
46
+ description?: string;
47
+ /**
48
+ * Custom options for the fetch request.
49
+ */
50
+ fetchOptions?: RequestInit;
51
+ /**
52
+ * A ref to the rendered SVG element.
53
+ * Not available on initial render — use `onLoad` instead.
54
+ */
55
+ innerRef?: Ref<SVGElement | null>;
56
+ /**
57
+ * A component shown while the SVG is loading.
58
+ */
59
+ loader?: ReactNode;
60
+ /**
61
+ * Called when loading the SVG fails.
62
+ * Receives an `Error` or `FetchError`.
63
+ */
64
+ onError?: ErrorCallback;
65
+ /**
66
+ * Called when the SVG loads successfully.
67
+ * Receives the `src` and an `isCached` flag.
68
+ */
69
+ onLoad?: LoadCallback;
70
+ /**
71
+ * A function to pre-process the SVG string before parsing.
72
+ * Must return a string.
73
+ */
74
+ preProcessor?: PreProcessorCallback;
75
+ /**
76
+ * The SVG to load.
77
+ * Accepts a URL or path, a data URI (base64 or URL-encoded), or a raw SVG string.
78
+ */
79
+ src: string;
80
+ /**
81
+ * A title for the SVG. Overrides an existing `<title>` tag.
82
+ * Pass `null` to remove it.
83
+ */
84
+ title?: string | null;
85
+ /**
86
+ * A string to use with `uniquifyIDs`.
87
+ * @default random 8-character alphanumeric string
88
+ */
89
+ uniqueHash?: string;
90
+ /**
91
+ * Create unique IDs for each icon.
92
+ * @default false
93
+ */
94
+ uniquifyIDs?: boolean;
95
+ }>;
96
+ type Simplify<T> = {
97
+ [KeyType in keyof T]: T[KeyType];
98
+ } & {};
99
+ type Status = (typeof STATUS)[keyof typeof STATUS];
100
+ interface FetchError extends Error {
101
+ code: string;
102
+ errno: string;
103
+ message: string;
104
+ type: string;
105
+ }
106
+ interface State {
107
+ content: string;
108
+ element: ReactNode;
109
+ isCached: boolean;
110
+ status: Status;
111
+ }
112
+ interface StorageItem {
113
+ content: string;
114
+ status: Status;
115
+ }
116
+
117
+ interface CacheStoreOptions {
118
+ name?: string;
119
+ persistent?: boolean;
120
+ }
121
+ declare class CacheStore {
122
+ private cacheApi;
123
+ private readonly cacheStore;
124
+ private readonly subscribers;
125
+ isReady: boolean;
126
+ constructor(options?: CacheStoreOptions);
127
+ onReady(callback: () => void): () => void;
128
+ private waitForReady;
129
+ get(url: string, fetchOptions?: RequestInit): Promise<string>;
130
+ getContent(url: string): string;
131
+ set(url: string, data: StorageItem): void;
132
+ isCached(url: string): boolean;
133
+ private fetchAndCache;
134
+ private fetchFromPersistentCache;
135
+ private handleLoading;
136
+ keys(): Array<string>;
137
+ data(): Array<Record<string, StorageItem>>;
138
+ delete(url: string): Promise<void>;
139
+ clear(): Promise<void>;
140
+ }
141
+
142
+ export { CacheStore as C, type ErrorCallback as E, type FetchError as F, type LoadCallback as L, type Props as P, type Simplify as S, type PreProcessorCallback as a, type State as b, type Status as c, type StorageItem as d };
@@ -0,0 +1,142 @@
1
+ import { SVGProps, ReactNode, Ref } from 'react';
2
+
3
+ declare 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
+
12
+ /**
13
+ * Called when loading the SVG fails.
14
+ */
15
+ type ErrorCallback = (error: Error | FetchError) => void;
16
+ /**
17
+ * Called when the SVG loads successfully.
18
+ */
19
+ type LoadCallback = (src: string, isCached: boolean) => void;
20
+ /**
21
+ * Pre-processes the SVG string before parsing.
22
+ * Must return a string.
23
+ */
24
+ type PreProcessorCallback = (code: string) => string;
25
+ type Props = Simplify<Omit<SVGProps<SVGElement>, 'onLoad' | 'onError' | 'ref'> & {
26
+ /**
27
+ * A URL to prepend to url() references inside the SVG when using `uniquifyIDs`.
28
+ * Only required if your page uses an HTML `<base>` tag.
29
+ */
30
+ baseURL?: string;
31
+ /**
32
+ * Cache remote SVGs in memory.
33
+ *
34
+ * When used with the CacheProvider, requests are also persisted in the browser cache.
35
+ * @default true
36
+ */
37
+ cacheRequests?: boolean;
38
+ /**
39
+ * Fallback content rendered on fetch error or unsupported browser.
40
+ */
41
+ children?: ReactNode;
42
+ /**
43
+ * A description for the SVG.
44
+ * Overrides an existing `<desc>` tag.
45
+ */
46
+ description?: string;
47
+ /**
48
+ * Custom options for the fetch request.
49
+ */
50
+ fetchOptions?: RequestInit;
51
+ /**
52
+ * A ref to the rendered SVG element.
53
+ * Not available on initial render — use `onLoad` instead.
54
+ */
55
+ innerRef?: Ref<SVGElement | null>;
56
+ /**
57
+ * A component shown while the SVG is loading.
58
+ */
59
+ loader?: ReactNode;
60
+ /**
61
+ * Called when loading the SVG fails.
62
+ * Receives an `Error` or `FetchError`.
63
+ */
64
+ onError?: ErrorCallback;
65
+ /**
66
+ * Called when the SVG loads successfully.
67
+ * Receives the `src` and an `isCached` flag.
68
+ */
69
+ onLoad?: LoadCallback;
70
+ /**
71
+ * A function to pre-process the SVG string before parsing.
72
+ * Must return a string.
73
+ */
74
+ preProcessor?: PreProcessorCallback;
75
+ /**
76
+ * The SVG to load.
77
+ * Accepts a URL or path, a data URI (base64 or URL-encoded), or a raw SVG string.
78
+ */
79
+ src: string;
80
+ /**
81
+ * A title for the SVG. Overrides an existing `<title>` tag.
82
+ * Pass `null` to remove it.
83
+ */
84
+ title?: string | null;
85
+ /**
86
+ * A string to use with `uniquifyIDs`.
87
+ * @default random 8-character alphanumeric string
88
+ */
89
+ uniqueHash?: string;
90
+ /**
91
+ * Create unique IDs for each icon.
92
+ * @default false
93
+ */
94
+ uniquifyIDs?: boolean;
95
+ }>;
96
+ type Simplify<T> = {
97
+ [KeyType in keyof T]: T[KeyType];
98
+ } & {};
99
+ type Status = (typeof STATUS)[keyof typeof STATUS];
100
+ interface FetchError extends Error {
101
+ code: string;
102
+ errno: string;
103
+ message: string;
104
+ type: string;
105
+ }
106
+ interface State {
107
+ content: string;
108
+ element: ReactNode;
109
+ isCached: boolean;
110
+ status: Status;
111
+ }
112
+ interface StorageItem {
113
+ content: string;
114
+ status: Status;
115
+ }
116
+
117
+ interface CacheStoreOptions {
118
+ name?: string;
119
+ persistent?: boolean;
120
+ }
121
+ declare class CacheStore {
122
+ private cacheApi;
123
+ private readonly cacheStore;
124
+ private readonly subscribers;
125
+ isReady: boolean;
126
+ constructor(options?: CacheStoreOptions);
127
+ onReady(callback: () => void): () => void;
128
+ private waitForReady;
129
+ get(url: string, fetchOptions?: RequestInit): Promise<string>;
130
+ getContent(url: string): string;
131
+ set(url: string, data: StorageItem): void;
132
+ isCached(url: string): boolean;
133
+ private fetchAndCache;
134
+ private fetchFromPersistentCache;
135
+ private handleLoading;
136
+ keys(): Array<string>;
137
+ data(): Array<Record<string, StorageItem>>;
138
+ delete(url: string): Promise<void>;
139
+ clear(): Promise<void>;
140
+ }
141
+
142
+ export { CacheStore as C, type ErrorCallback as E, type FetchError as F, type LoadCallback as L, type Props as P, type Simplify as S, type PreProcessorCallback as a, type State as b, type Status as c, type StorageItem as d };
package/dist/index.d.mts CHANGED
@@ -1,75 +1,9 @@
1
- import React, { SVGProps, ReactNode, Ref } from 'react';
1
+ import * as react from 'react';
2
+ import { ReactElement } from 'react';
3
+ import { C as CacheStore, P as Props } from './cache-NLB60kAd.mjs';
4
+ export { E as ErrorCallback, F as FetchError, L as LoadCallback, a as PreProcessorCallback, S as Simplify, b as State, c as Status, d as StorageItem } from './cache-NLB60kAd.mjs';
2
5
 
3
- declare 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
- };
6
+ declare const cacheStore: CacheStore;
7
+ declare function InlineSVG(props: Props): string | number | bigint | boolean | ReactElement<unknown, string | react.JSXElementConstructor<any>> | Iterable<react.ReactNode> | Promise<string | number | bigint | boolean | react.ReactPortal | ReactElement<unknown, string | react.JSXElementConstructor<any>> | Iterable<react.ReactNode> | null | undefined> | null;
11
8
 
12
- type ErrorCallback = (error: Error | FetchError) => void;
13
- type LoadCallback = (src: string, isCached: boolean) => void;
14
- type PlainObject<T = unknown> = Record<string, T>;
15
- type PreProcessorCallback = (code: string) => string;
16
- type 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?: Ref<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
- }>;
32
- type Simplify<T> = {
33
- [KeyType in keyof T]: T[KeyType];
34
- } & {};
35
- type Status = (typeof STATUS)[keyof typeof STATUS];
36
- interface FetchError extends Error {
37
- code: string;
38
- errno: string;
39
- message: string;
40
- type: string;
41
- }
42
- interface State {
43
- content: string;
44
- element: ReactNode;
45
- isCached: boolean;
46
- status: Status;
47
- }
48
- interface StorageItem {
49
- content: string;
50
- status: Status;
51
- }
52
-
53
- declare 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
-
72
- declare let cacheStore: CacheStore;
73
- declare function InlineSVG(props: Props): string | number | boolean | Iterable<React.ReactNode> | React.JSX.Element | null | undefined;
74
-
75
- export { type ErrorCallback, type FetchError, type LoadCallback, type PlainObject, type PreProcessorCallback, type Props, type Simplify, type State, type Status, type StorageItem, cacheStore, InlineSVG as default };
9
+ export { Props, cacheStore, InlineSVG as default };
package/dist/index.d.ts CHANGED
@@ -1,76 +1,10 @@
1
- import React, { SVGProps, ReactNode, Ref } from 'react';
1
+ import * as react from 'react';
2
+ import { ReactElement } from 'react';
3
+ import { C as CacheStore, P as Props } from './cache-NLB60kAd.js';
4
+ export { E as ErrorCallback, F as FetchError, L as LoadCallback, a as PreProcessorCallback, S as Simplify, b as State, c as Status, d as StorageItem } from './cache-NLB60kAd.js';
2
5
 
3
- declare 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
- };
6
+ declare const cacheStore: CacheStore;
7
+ declare function InlineSVG(props: Props): string | number | bigint | boolean | ReactElement<unknown, string | react.JSXElementConstructor<any>> | Iterable<react.ReactNode> | Promise<string | number | bigint | boolean | react.ReactPortal | ReactElement<unknown, string | react.JSXElementConstructor<any>> | Iterable<react.ReactNode> | null | undefined> | null;
11
8
 
12
- type ErrorCallback = (error: Error | FetchError) => void;
13
- type LoadCallback = (src: string, isCached: boolean) => void;
14
- type PlainObject<T = unknown> = Record<string, T>;
15
- type PreProcessorCallback = (code: string) => string;
16
- type 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?: Ref<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
- }>;
32
- type Simplify<T> = {
33
- [KeyType in keyof T]: T[KeyType];
34
- } & {};
35
- type Status = (typeof STATUS)[keyof typeof STATUS];
36
- interface FetchError extends Error {
37
- code: string;
38
- errno: string;
39
- message: string;
40
- type: string;
41
- }
42
- interface State {
43
- content: string;
44
- element: ReactNode;
45
- isCached: boolean;
46
- status: Status;
47
- }
48
- interface StorageItem {
49
- content: string;
50
- status: Status;
51
- }
52
-
53
- declare 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
-
72
- declare let cacheStore: CacheStore;
73
- declare function InlineSVG(props: Props): string | number | boolean | Iterable<React.ReactNode> | React.JSX.Element | null | undefined;
74
-
75
- export { type ErrorCallback, type FetchError, type LoadCallback, type PlainObject, type PreProcessorCallback, type Props, type Simplify, type State, type Status, type StorageItem, cacheStore, InlineSVG as default };
9
+ export { Props, cacheStore, InlineSVG as default };
76
10
  export = InlineSVG