react-inlinesvg 4.1.8 → 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 +28 -34
- package/dist/cache-NLB60kAd.d.mts +142 -0
- package/dist/cache-NLB60kAd.d.ts +142 -0
- package/dist/index.d.mts +7 -73
- package/dist/index.d.ts +7 -73
- package/dist/index.js +284 -202
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +280 -206
- package/dist/index.mjs.map +1 -1
- package/dist/provider.d.mts +5 -3
- package/dist/provider.d.ts +5 -3
- package/dist/provider.js +187 -6
- package/dist/provider.js.map +1 -1
- package/dist/provider.mjs +176 -6
- package/dist/provider.mjs.map +1 -1
- package/package.json +25 -41
- package/src/index.tsx +29 -261
- package/src/modules/cache.ts +100 -70
- package/src/modules/helpers.ts +1 -9
- package/src/modules/hooks.tsx +6 -1
- package/src/modules/useInlineSVG.ts +272 -0
- package/src/modules/utils.ts +36 -1
- package/src/provider.tsx +10 -7
- package/src/types.ts +69 -3
- package/src/global.d.ts +0 -6
package/src/types.ts
CHANGED
|
@@ -1,27 +1,93 @@
|
|
|
1
|
-
import { ReactNode,
|
|
1
|
+
import { ReactNode, Ref, SVGProps } from 'react';
|
|
2
2
|
|
|
3
3
|
import { STATUS } from './config';
|
|
4
4
|
|
|
5
|
+
/**
|
|
6
|
+
* Called when loading the SVG fails.
|
|
7
|
+
*/
|
|
5
8
|
export type ErrorCallback = (error: Error | FetchError) => void;
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Called when the SVG loads successfully.
|
|
12
|
+
*/
|
|
6
13
|
export type LoadCallback = (src: string, isCached: boolean) => void;
|
|
7
|
-
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Pre-processes the SVG string before parsing.
|
|
17
|
+
* Must return a string.
|
|
18
|
+
*/
|
|
8
19
|
export type PreProcessorCallback = (code: string) => string;
|
|
9
20
|
|
|
10
21
|
export type Props = Simplify<
|
|
11
22
|
Omit<SVGProps<SVGElement>, 'onLoad' | 'onError' | 'ref'> & {
|
|
23
|
+
/**
|
|
24
|
+
* A URL to prepend to url() references inside the SVG when using `uniquifyIDs`.
|
|
25
|
+
* Only required if your page uses an HTML `<base>` tag.
|
|
26
|
+
*/
|
|
12
27
|
baseURL?: string;
|
|
28
|
+
/**
|
|
29
|
+
* Cache remote SVGs in memory.
|
|
30
|
+
*
|
|
31
|
+
* When used with the CacheProvider, requests are also persisted in the browser cache.
|
|
32
|
+
* @default true
|
|
33
|
+
*/
|
|
13
34
|
cacheRequests?: boolean;
|
|
35
|
+
/**
|
|
36
|
+
* Fallback content rendered on fetch error or unsupported browser.
|
|
37
|
+
*/
|
|
14
38
|
children?: ReactNode;
|
|
39
|
+
/**
|
|
40
|
+
* A description for the SVG.
|
|
41
|
+
* Overrides an existing `<desc>` tag.
|
|
42
|
+
*/
|
|
15
43
|
description?: string;
|
|
44
|
+
/**
|
|
45
|
+
* Custom options for the fetch request.
|
|
46
|
+
*/
|
|
16
47
|
fetchOptions?: RequestInit;
|
|
17
|
-
|
|
48
|
+
/**
|
|
49
|
+
* A ref to the rendered SVG element.
|
|
50
|
+
* Not available on initial render — use `onLoad` instead.
|
|
51
|
+
*/
|
|
52
|
+
innerRef?: Ref<SVGElement | null>;
|
|
53
|
+
/**
|
|
54
|
+
* A component shown while the SVG is loading.
|
|
55
|
+
*/
|
|
18
56
|
loader?: ReactNode;
|
|
57
|
+
/**
|
|
58
|
+
* Called when loading the SVG fails.
|
|
59
|
+
* Receives an `Error` or `FetchError`.
|
|
60
|
+
*/
|
|
19
61
|
onError?: ErrorCallback;
|
|
62
|
+
/**
|
|
63
|
+
* Called when the SVG loads successfully.
|
|
64
|
+
* Receives the `src` and an `isCached` flag.
|
|
65
|
+
*/
|
|
20
66
|
onLoad?: LoadCallback;
|
|
67
|
+
/**
|
|
68
|
+
* A function to pre-process the SVG string before parsing.
|
|
69
|
+
* Must return a string.
|
|
70
|
+
*/
|
|
21
71
|
preProcessor?: PreProcessorCallback;
|
|
72
|
+
/**
|
|
73
|
+
* The SVG to load.
|
|
74
|
+
* Accepts a URL or path, a data URI (base64 or URL-encoded), or a raw SVG string.
|
|
75
|
+
*/
|
|
22
76
|
src: string;
|
|
77
|
+
/**
|
|
78
|
+
* A title for the SVG. Overrides an existing `<title>` tag.
|
|
79
|
+
* Pass `null` to remove it.
|
|
80
|
+
*/
|
|
23
81
|
title?: string | null;
|
|
82
|
+
/**
|
|
83
|
+
* A string to use with `uniquifyIDs`.
|
|
84
|
+
* @default random 8-character alphanumeric string
|
|
85
|
+
*/
|
|
24
86
|
uniqueHash?: string;
|
|
87
|
+
/**
|
|
88
|
+
* Create unique IDs for each icon.
|
|
89
|
+
* @default false
|
|
90
|
+
*/
|
|
25
91
|
uniquifyIDs?: boolean;
|
|
26
92
|
}
|
|
27
93
|
>;
|