react-inlinesvg 2.2.1 → 3.0.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 +26 -19
- package/esm/helpers.d.ts +6 -1
- package/esm/helpers.js +28 -8
- package/esm/helpers.js.map +1 -1
- package/esm/index.d.ts +9 -7
- package/esm/index.js +79 -95
- package/esm/index.js.map +1 -1
- package/esm/types.d.ts +2 -3
- package/lib/helpers.d.ts +6 -1
- package/lib/helpers.js +31 -10
- package/lib/helpers.js.map +1 -1
- package/lib/index.d.ts +9 -7
- package/lib/index.js +96 -107
- package/lib/index.js.map +1 -1
- package/lib/types.d.ts +2 -3
- package/package.json +57 -57
- package/src/helpers.ts +35 -7
- package/src/index.tsx +152 -160
- package/src/types.ts +2 -3
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# react-inlinesvg
|
|
2
2
|
|
|
3
|
-
[](https://www.npmjs.com/package/react-inlinesvg) [](https://www.npmjs.com/package/react-inlinesvg) [](https://travis-ci.com/gilbarbara/react-inlinesvg) [](https://codeclimate.com/github/gilbarbara/react-inlinesvg/maintainability) [](https://codeclimate.com/github/gilbarbara/react-inlinesvg/test_coverage)
|
|
4
4
|
|
|
5
5
|
Load inline, local or remote SVGs in your React components.
|
|
6
6
|
|
|
@@ -8,19 +8,19 @@ Load inline, local or remote SVGs in your React components.
|
|
|
8
8
|
|
|
9
9
|
- 🏖 **Easy to use:** Just set the `src`
|
|
10
10
|
- 🛠 **Flexible:** Personalize the options to fit your needs
|
|
11
|
-
- ⚡️ **Smart:** Async requests will be cached.
|
|
11
|
+
- ⚡️ **Smart:** Async requests will be cached.
|
|
12
12
|
- 🚀 **SSR:** Render a loader until the DOM is available
|
|
13
13
|
- 🟦 **Typescript:** Nicely typed
|
|
14
14
|
|
|
15
15
|
## Usage
|
|
16
16
|
|
|
17
|
-
```
|
|
17
|
+
```sh
|
|
18
18
|
npm i react-inlinesvg
|
|
19
19
|
```
|
|
20
20
|
|
|
21
21
|
And import it into your code:
|
|
22
22
|
|
|
23
|
-
```
|
|
23
|
+
```tsx
|
|
24
24
|
import React, { useRef } from 'react';
|
|
25
25
|
import SVG, { Props as SVGProps } from 'react-inlinesvg';
|
|
26
26
|
|
|
@@ -33,8 +33,8 @@ export function App() {
|
|
|
33
33
|
|
|
34
34
|
return (
|
|
35
35
|
<main>
|
|
36
|
+
<SVG src={`${process.env.PUBLIC_URL}/menu.svg`} width={24} height="auto" title="Menu" />
|
|
36
37
|
<Logo ref={logo} src={`${process.env.PUBLIC_URL}/logo.svg`} />
|
|
37
|
-
...
|
|
38
38
|
</main>
|
|
39
39
|
);
|
|
40
40
|
}
|
|
@@ -43,8 +43,8 @@ export function App() {
|
|
|
43
43
|
## Props
|
|
44
44
|
|
|
45
45
|
**src** {string} - **required**.
|
|
46
|
-
The SVG file you want to load. It can be a require,
|
|
47
|
-
|
|
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._
|
|
48
48
|
|
|
49
49
|
**baseURL** {string}
|
|
50
50
|
An URL to prefix each ID in case you are using the `<base>` tag and `uniquifyIDs`.
|
|
@@ -64,12 +64,14 @@ Cache remote SVGs.
|
|
|
64
64
|
**description** {string}
|
|
65
65
|
A description for your SVG. It will override an existing `<desc>` tag.
|
|
66
66
|
|
|
67
|
+
**fetchOptions** {RequestInit}
|
|
68
|
+
Custom options for the [request](https://developer.mozilla.org/en-US/docs/Web/API/Request/Request).
|
|
69
|
+
|
|
67
70
|
**innerRef** {React.Ref}
|
|
68
71
|
Set a ref in SVGElement.
|
|
69
72
|
|
|
70
73
|
**loader** {node}
|
|
71
|
-
A component to be shown while the SVG is loading.
|
|
72
|
-
If you set
|
|
74
|
+
A component to be shown while the SVG is loading.
|
|
73
75
|
|
|
74
76
|
**onError** {function}
|
|
75
77
|
A callback to be invoked if loading the SVG fails.
|
|
@@ -77,7 +79,7 @@ This will receive a single argument with:
|
|
|
77
79
|
|
|
78
80
|
- a `FetchError` with:
|
|
79
81
|
|
|
80
|
-
```
|
|
82
|
+
```typescript
|
|
81
83
|
{
|
|
82
84
|
message: string;
|
|
83
85
|
type: string;
|
|
@@ -88,11 +90,11 @@ This will receive a single argument with:
|
|
|
88
90
|
|
|
89
91
|
- or an `InlineSVGError`, which has the following properties:
|
|
90
92
|
|
|
91
|
-
```
|
|
93
|
+
```typescript
|
|
92
94
|
{
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
95
|
+
name: 'InlineSVGError';
|
|
96
|
+
data: object; // optional
|
|
97
|
+
message: string;
|
|
96
98
|
}
|
|
97
99
|
```
|
|
98
100
|
|
|
@@ -112,7 +114,7 @@ A string to use with `uniquifyIDs`.
|
|
|
112
114
|
**uniquifyIDs** {boolean} ▶︎ `false`
|
|
113
115
|
Create unique IDs for each icon.
|
|
114
116
|
|
|
115
|
-
>
|
|
117
|
+
> Any additional props will be passed down to the SVG element.
|
|
116
118
|
|
|
117
119
|
### Example
|
|
118
120
|
|
|
@@ -122,9 +124,9 @@ Create unique IDs for each icon.
|
|
|
122
124
|
cacheRequests={true}
|
|
123
125
|
description="The React logo"
|
|
124
126
|
loader={<span>Loading...</span>}
|
|
125
|
-
onError={error => console.log(error.message)}
|
|
127
|
+
onError={(error) => console.log(error.message)}
|
|
126
128
|
onLoad={(src, hasCache) => console.log(src, hasCache)}
|
|
127
|
-
preProcessor={code => code.replace(/fill=".*?"/g, 'fill="currentColor"')}
|
|
129
|
+
preProcessor={(code) => code.replace(/fill=".*?"/g, 'fill="currentColor"')}
|
|
128
130
|
src="https://cdn.svgporn.com/logos/react.svg"
|
|
129
131
|
title="React"
|
|
130
132
|
uniqueHash="a1f8d1"
|
|
@@ -132,6 +134,11 @@ Create unique IDs for each icon.
|
|
|
132
134
|
/>
|
|
133
135
|
```
|
|
134
136
|
|
|
137
|
+
## Caching
|
|
138
|
+
|
|
139
|
+
The internal cache is exported as `cacheStore` if you need to debug or pre-cache some files.
|
|
140
|
+
⚠️ Use it at your own risk.
|
|
141
|
+
|
|
135
142
|
## Browser Support
|
|
136
143
|
|
|
137
144
|
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.
|
|
@@ -166,9 +173,9 @@ But there's an alternative that sidesteps these issues: load the SVG with a GET
|
|
|
166
173
|
|
|
167
174
|
### Note
|
|
168
175
|
|
|
169
|
-
The SVG [`<use>`]
|
|
176
|
+
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.
|
|
170
177
|
|
|
171
178
|
## Credits
|
|
172
179
|
|
|
173
180
|
Thanks to [@matthewwithanm](https://github.com/matthewwithanm) for creating this component and so kindly transfer it to me.
|
|
174
|
-
I'll definitely keep the good work! ❤️
|
|
181
|
+
I'll definitely keep the good work! ❤️
|
package/esm/helpers.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { PlainObject } from './types';
|
|
1
2
|
export declare const STATUS: {
|
|
2
3
|
FAILED: string;
|
|
3
4
|
LOADED: string;
|
|
@@ -7,6 +8,10 @@ export declare const STATUS: {
|
|
|
7
8
|
UNSUPPORTED: string;
|
|
8
9
|
};
|
|
9
10
|
export declare function canUseDOM(): boolean;
|
|
10
|
-
export declare function supportsInlineSVG(): boolean;
|
|
11
11
|
export declare function isSupportedEnvironment(): boolean;
|
|
12
|
+
export declare function supportsInlineSVG(): boolean;
|
|
12
13
|
export declare function randomString(length: number): string;
|
|
14
|
+
/**
|
|
15
|
+
* Remove properties from an object
|
|
16
|
+
*/
|
|
17
|
+
export declare function omit<T extends PlainObject, K extends keyof T>(input: T, ...filter: K[]): Omit<T, K>;
|
package/esm/helpers.js
CHANGED
|
@@ -10,6 +10,9 @@ export var STATUS = {
|
|
|
10
10
|
export function canUseDOM() {
|
|
11
11
|
return canUseDOMFlag;
|
|
12
12
|
}
|
|
13
|
+
export function isSupportedEnvironment() {
|
|
14
|
+
return supportsInlineSVG() && typeof window !== 'undefined' && window !== null;
|
|
15
|
+
}
|
|
13
16
|
export function supportsInlineSVG() {
|
|
14
17
|
/* istanbul ignore next */
|
|
15
18
|
if (!document) {
|
|
@@ -17,22 +20,39 @@ export function supportsInlineSVG() {
|
|
|
17
20
|
}
|
|
18
21
|
var div = document.createElement('div');
|
|
19
22
|
div.innerHTML = '<svg />';
|
|
20
|
-
|
|
23
|
+
var svg = div.firstChild;
|
|
24
|
+
return !!svg && svg.namespaceURI === 'http://www.w3.org/2000/svg';
|
|
21
25
|
}
|
|
22
|
-
|
|
23
|
-
return
|
|
26
|
+
function randomCharacter(character) {
|
|
27
|
+
return character[Math.floor(Math.random() * character.length)];
|
|
24
28
|
}
|
|
25
29
|
export function randomString(length) {
|
|
26
30
|
var letters = 'abcdefghijklmnopqrstuvwxyz';
|
|
27
31
|
var numbers = '1234567890';
|
|
28
|
-
var charset = ""
|
|
29
|
-
var randomCharacter = function (character) {
|
|
30
|
-
return character[Math.floor(Math.random() * character.length)];
|
|
31
|
-
};
|
|
32
|
+
var charset = "".concat(letters).concat(letters.toUpperCase()).concat(numbers);
|
|
32
33
|
var R = '';
|
|
33
|
-
for (var
|
|
34
|
+
for (var index = 0; index < length; index++) {
|
|
34
35
|
R += randomCharacter(charset);
|
|
35
36
|
}
|
|
36
37
|
return R;
|
|
37
38
|
}
|
|
39
|
+
/**
|
|
40
|
+
* Remove properties from an object
|
|
41
|
+
*/
|
|
42
|
+
export function omit(input) {
|
|
43
|
+
var filter = [];
|
|
44
|
+
for (var _i = 1; _i < arguments.length; _i++) {
|
|
45
|
+
filter[_i - 1] = arguments[_i];
|
|
46
|
+
}
|
|
47
|
+
var output = {};
|
|
48
|
+
for (var key in input) {
|
|
49
|
+
/* istanbul ignore else */
|
|
50
|
+
if ({}.hasOwnProperty.call(input, key)) {
|
|
51
|
+
if (!filter.includes(key)) {
|
|
52
|
+
output[key] = input[key];
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
return output;
|
|
57
|
+
}
|
|
38
58
|
//# sourceMappingURL=helpers.js.map
|
package/esm/helpers.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"helpers.js","sourceRoot":"","sources":["../src/helpers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,IAAI,aAAa,EAAE,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"helpers.js","sourceRoot":"","sources":["../src/helpers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,IAAI,aAAa,EAAE,MAAM,OAAO,CAAC;AAInD,MAAM,CAAC,IAAM,MAAM,GAAG;IACpB,MAAM,EAAE,QAAQ;IAChB,MAAM,EAAE,QAAQ;IAChB,OAAO,EAAE,SAAS;IAClB,OAAO,EAAE,SAAS;IAClB,KAAK,EAAE,OAAO;IACd,WAAW,EAAE,aAAa;CAC3B,CAAC;AAEF,MAAM,UAAU,SAAS;IACvB,OAAO,aAAa,CAAC;AACvB,CAAC;AAED,MAAM,UAAU,sBAAsB;IACpC,OAAO,iBAAiB,EAAE,IAAI,OAAO,MAAM,KAAK,WAAW,IAAI,MAAM,KAAK,IAAI,CAAC;AACjF,CAAC;AAED,MAAM,UAAU,iBAAiB;IAC/B,0BAA0B;IAC1B,IAAI,CAAC,QAAQ,EAAE;QACb,OAAO,KAAK,CAAC;KACd;IAED,IAAM,GAAG,GAAG,QAAQ,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC;IAE1C,GAAG,CAAC,SAAS,GAAG,SAAS,CAAC;IAC1B,IAAM,GAAG,GAAG,GAAG,CAAC,UAA2B,CAAC;IAE5C,OAAO,CAAC,CAAC,GAAG,IAAI,GAAG,CAAC,YAAY,KAAK,4BAA4B,CAAC;AACpE,CAAC;AAED,SAAS,eAAe,CAAC,SAAiB;IACxC,OAAO,SAAS,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,SAAS,CAAC,MAAM,CAAC,CAAC,CAAC;AACjE,CAAC;AAED,MAAM,UAAU,YAAY,CAAC,MAAc;IACzC,IAAM,OAAO,GAAG,4BAA4B,CAAC;IAC7C,IAAM,OAAO,GAAG,YAAY,CAAC;IAC7B,IAAM,OAAO,GAAG,UAAG,OAAO,SAAG,OAAO,CAAC,WAAW,EAAE,SAAG,OAAO,CAAE,CAAC;IAE/D,IAAI,CAAC,GAAG,EAAE,CAAC;IAEX,KAAK,IAAI,KAAK,GAAG,CAAC,EAAE,KAAK,GAAG,MAAM,EAAE,KAAK,EAAE,EAAE;QAC3C,CAAC,IAAI,eAAe,CAAC,OAAO,CAAC,CAAC;KAC/B;IAED,OAAO,CAAC,CAAC;AACX,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,IAAI,CAClB,KAAQ;IACR,gBAAc;SAAd,UAAc,EAAd,qBAAc,EAAd,IAAc;QAAd,+BAAc;;IAEd,IAAM,MAAM,GAAQ,EAAE,CAAC;IAEvB,KAAK,IAAM,GAAG,IAAI,KAAK,EAAE;QACvB,0BAA0B;QAC1B,IAAI,EAAE,CAAC,cAAc,CAAC,IAAI,CAAC,KAAK,EAAE,GAAG,CAAC,EAAE;YACtC,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,GAAmB,CAAC,EAAE;gBACzC,MAAM,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC,GAAG,CAAC,CAAC;aAC1B;SACF;KACF;IAED,OAAO,MAAoB,CAAC;AAC9B,CAAC"}
|
package/esm/index.d.ts
CHANGED
|
@@ -1,25 +1,27 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
import { Props, State } from './types';
|
|
2
|
+
import { Props, State, StorageItem } from './types';
|
|
3
|
+
export declare const cacheStore: {
|
|
4
|
+
[key: string]: StorageItem;
|
|
5
|
+
};
|
|
3
6
|
export default class InlineSVG extends React.PureComponent<Props, State> {
|
|
4
|
-
constructor(props: Props);
|
|
5
7
|
private isActive;
|
|
6
8
|
private readonly hash;
|
|
7
9
|
static defaultProps: {
|
|
8
10
|
cacheRequests: boolean;
|
|
9
11
|
uniquifyIDs: boolean;
|
|
10
12
|
};
|
|
13
|
+
constructor(props: Props);
|
|
11
14
|
componentDidMount(): void;
|
|
12
|
-
componentDidUpdate(
|
|
15
|
+
componentDidUpdate(previousProps: Props, previousState: State): void;
|
|
13
16
|
componentWillUnmount(): void;
|
|
14
|
-
private processSVG;
|
|
15
|
-
private updateSVGAttributes;
|
|
16
17
|
private getNode;
|
|
17
18
|
private getElement;
|
|
18
|
-
private load;
|
|
19
|
-
private handleCacheQueue;
|
|
20
19
|
private handleLoad;
|
|
21
20
|
private handleError;
|
|
22
21
|
private request;
|
|
22
|
+
private load;
|
|
23
|
+
private updateSVGAttributes;
|
|
24
|
+
private processSVG;
|
|
23
25
|
render(): React.ReactNode;
|
|
24
26
|
}
|
|
25
27
|
export * from './types';
|
package/esm/index.js
CHANGED
|
@@ -6,6 +6,8 @@ var __extends = (this && this.__extends) || (function () {
|
|
|
6
6
|
return extendStatics(d, b);
|
|
7
7
|
};
|
|
8
8
|
return function (d, b) {
|
|
9
|
+
if (typeof b !== "function" && b !== null)
|
|
10
|
+
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
9
11
|
extendStatics(d, b);
|
|
10
12
|
function __() { this.constructor = d; }
|
|
11
13
|
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
@@ -22,17 +24,6 @@ var __assign = (this && this.__assign) || function () {
|
|
|
22
24
|
};
|
|
23
25
|
return __assign.apply(this, arguments);
|
|
24
26
|
};
|
|
25
|
-
var __rest = (this && this.__rest) || function (s, e) {
|
|
26
|
-
var t = {};
|
|
27
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
28
|
-
t[p] = s[p];
|
|
29
|
-
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
30
|
-
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
31
|
-
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
32
|
-
t[p[i]] = s[p[i]];
|
|
33
|
-
}
|
|
34
|
-
return t;
|
|
35
|
-
};
|
|
36
27
|
var __read = (this && this.__read) || function (o, n) {
|
|
37
28
|
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
38
29
|
if (!m) return o;
|
|
@@ -49,27 +40,24 @@ var __read = (this && this.__read) || function (o, n) {
|
|
|
49
40
|
}
|
|
50
41
|
return ar;
|
|
51
42
|
};
|
|
52
|
-
var
|
|
53
|
-
for (var
|
|
54
|
-
|
|
43
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
44
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
45
|
+
if (ar || !(i in from)) {
|
|
46
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
47
|
+
ar[i] = from[i];
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
55
51
|
};
|
|
56
52
|
import * as React from 'react';
|
|
57
53
|
import convert from 'react-from-dom';
|
|
58
|
-
import {
|
|
59
|
-
var cacheStore = Object.create(null);
|
|
54
|
+
import { canUseDOM, isSupportedEnvironment, omit, randomString, STATUS } from './helpers';
|
|
55
|
+
export var cacheStore = Object.create(null);
|
|
60
56
|
var InlineSVG = /** @class */ (function (_super) {
|
|
61
57
|
__extends(InlineSVG, _super);
|
|
62
58
|
function InlineSVG(props) {
|
|
63
59
|
var _this = _super.call(this, props) || this;
|
|
64
60
|
_this.isActive = false;
|
|
65
|
-
_this.handleCacheQueue = function (content) {
|
|
66
|
-
/* istanbul ignore else */
|
|
67
|
-
if (typeof content === 'string') {
|
|
68
|
-
_this.handleLoad(content);
|
|
69
|
-
return;
|
|
70
|
-
}
|
|
71
|
-
_this.handleError(content);
|
|
72
|
-
};
|
|
73
61
|
_this.handleLoad = function (content) {
|
|
74
62
|
/* istanbul ignore else */
|
|
75
63
|
if (_this.isActive) {
|
|
@@ -93,24 +81,32 @@ var InlineSVG = /** @class */ (function (_super) {
|
|
|
93
81
|
}
|
|
94
82
|
};
|
|
95
83
|
_this.request = function () {
|
|
96
|
-
var _a = _this.props, cacheRequests = _a.cacheRequests, src = _a.src;
|
|
84
|
+
var _a = _this.props, cacheRequests = _a.cacheRequests, fetchOptions = _a.fetchOptions, src = _a.src;
|
|
97
85
|
try {
|
|
98
86
|
if (cacheRequests) {
|
|
99
|
-
cacheStore[src] = { content: '', status: STATUS.LOADING
|
|
87
|
+
cacheStore[src] = { content: '', status: STATUS.LOADING };
|
|
100
88
|
}
|
|
101
|
-
return fetch(src)
|
|
89
|
+
return fetch(src, fetchOptions)
|
|
102
90
|
.then(function (response) {
|
|
103
91
|
var contentType = response.headers.get('content-type');
|
|
104
92
|
var _a = __read((contentType || '').split(/ ?; ?/), 1), fileType = _a[0];
|
|
105
93
|
if (response.status > 299) {
|
|
106
94
|
throw new Error('Not found');
|
|
107
95
|
}
|
|
108
|
-
if (!['image/svg+xml', 'text/plain'].some(function (d) { return fileType.
|
|
109
|
-
throw new Error("Content type isn't valid: "
|
|
96
|
+
if (!['image/svg+xml', 'text/plain'].some(function (d) { return fileType.includes(d); })) {
|
|
97
|
+
throw new Error("Content type isn't valid: ".concat(fileType));
|
|
110
98
|
}
|
|
111
99
|
return response.text();
|
|
112
100
|
})
|
|
113
101
|
.then(function (content) {
|
|
102
|
+
var currentSrc = _this.props.src;
|
|
103
|
+
// the current src don't match the previous one, skipping...
|
|
104
|
+
if (src !== currentSrc) {
|
|
105
|
+
if (cacheStore[src].status === STATUS.LOADING) {
|
|
106
|
+
delete cacheStore[src];
|
|
107
|
+
}
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
114
110
|
_this.handleLoad(content);
|
|
115
111
|
/* istanbul ignore else */
|
|
116
112
|
if (cacheRequests) {
|
|
@@ -119,10 +115,6 @@ var InlineSVG = /** @class */ (function (_super) {
|
|
|
119
115
|
if (cache) {
|
|
120
116
|
cache.content = content;
|
|
121
117
|
cache.status = STATUS.LOADED;
|
|
122
|
-
cache.queue = cache.queue.filter(function (cb) {
|
|
123
|
-
cb(content);
|
|
124
|
-
return false;
|
|
125
|
-
});
|
|
126
118
|
}
|
|
127
119
|
}
|
|
128
120
|
})
|
|
@@ -133,9 +125,6 @@ var InlineSVG = /** @class */ (function (_super) {
|
|
|
133
125
|
var cache = cacheStore[src];
|
|
134
126
|
/* istanbul ignore else */
|
|
135
127
|
if (cache) {
|
|
136
|
-
cache.queue.forEach(function (cb) {
|
|
137
|
-
cb(error);
|
|
138
|
-
});
|
|
139
128
|
delete cacheStore[src];
|
|
140
129
|
}
|
|
141
130
|
}
|
|
@@ -179,19 +168,19 @@ var InlineSVG = /** @class */ (function (_super) {
|
|
|
179
168
|
this.handleError(error);
|
|
180
169
|
}
|
|
181
170
|
};
|
|
182
|
-
InlineSVG.prototype.componentDidUpdate = function (
|
|
171
|
+
InlineSVG.prototype.componentDidUpdate = function (previousProps, previousState) {
|
|
183
172
|
if (!canUseDOM()) {
|
|
184
173
|
return;
|
|
185
174
|
}
|
|
186
175
|
var _a = this.state, hasCache = _a.hasCache, status = _a.status;
|
|
187
176
|
var _b = this.props, onLoad = _b.onLoad, src = _b.src;
|
|
188
|
-
if (
|
|
177
|
+
if (previousState.status !== STATUS.READY && status === STATUS.READY) {
|
|
189
178
|
/* istanbul ignore else */
|
|
190
179
|
if (onLoad) {
|
|
191
180
|
onLoad(src, hasCache);
|
|
192
181
|
}
|
|
193
182
|
}
|
|
194
|
-
if (
|
|
183
|
+
if (previousProps.src !== src) {
|
|
195
184
|
if (!src) {
|
|
196
185
|
this.handleError(new Error('Missing src'));
|
|
197
186
|
return;
|
|
@@ -202,49 +191,6 @@ var InlineSVG = /** @class */ (function (_super) {
|
|
|
202
191
|
InlineSVG.prototype.componentWillUnmount = function () {
|
|
203
192
|
this.isActive = false;
|
|
204
193
|
};
|
|
205
|
-
InlineSVG.prototype.processSVG = function () {
|
|
206
|
-
var content = this.state.content;
|
|
207
|
-
var preProcessor = this.props.preProcessor;
|
|
208
|
-
if (preProcessor) {
|
|
209
|
-
return preProcessor(content);
|
|
210
|
-
}
|
|
211
|
-
return content;
|
|
212
|
-
};
|
|
213
|
-
InlineSVG.prototype.updateSVGAttributes = function (node) {
|
|
214
|
-
var _this = this;
|
|
215
|
-
var _a = this.props, _b = _a.baseURL, baseURL = _b === void 0 ? '' : _b, uniquifyIDs = _a.uniquifyIDs;
|
|
216
|
-
var replaceableAttributes = ['id', 'href', 'xlink:href', 'xlink:role', 'xlink:arcrole'];
|
|
217
|
-
var linkAttributes = ['href', 'xlink:href'];
|
|
218
|
-
var isDataValue = function (name, value) {
|
|
219
|
-
return linkAttributes.indexOf(name) >= 0 && (value ? value.indexOf('#') < 0 : false);
|
|
220
|
-
};
|
|
221
|
-
if (!uniquifyIDs) {
|
|
222
|
-
return node;
|
|
223
|
-
}
|
|
224
|
-
__spread(node.children).map(function (d) {
|
|
225
|
-
if (d.attributes && d.attributes.length) {
|
|
226
|
-
var attributes_1 = Object.values(d.attributes).map(function (a) {
|
|
227
|
-
var attr = a;
|
|
228
|
-
var match = a.value.match(/url\((.*?)\)/);
|
|
229
|
-
if (match && match[1]) {
|
|
230
|
-
attr.value = a.value.replace(match[0], "url(" + baseURL + match[1] + "__" + _this.hash + ")");
|
|
231
|
-
}
|
|
232
|
-
return attr;
|
|
233
|
-
});
|
|
234
|
-
replaceableAttributes.forEach(function (r) {
|
|
235
|
-
var attribute = attributes_1.find(function (a) { return a.name === r; });
|
|
236
|
-
if (attribute && !isDataValue(r, attribute.value)) {
|
|
237
|
-
attribute.value = attribute.value + "__" + _this.hash;
|
|
238
|
-
}
|
|
239
|
-
});
|
|
240
|
-
}
|
|
241
|
-
if (d.children.length) {
|
|
242
|
-
return _this.updateSVGAttributes(d);
|
|
243
|
-
}
|
|
244
|
-
return d;
|
|
245
|
-
});
|
|
246
|
-
return node;
|
|
247
|
-
};
|
|
248
194
|
InlineSVG.prototype.getNode = function () {
|
|
249
195
|
var _a = this.props, description = _a.description, title = _a.title;
|
|
250
196
|
try {
|
|
@@ -305,22 +251,16 @@ var InlineSVG = /** @class */ (function (_super) {
|
|
|
305
251
|
}, function () {
|
|
306
252
|
var _a = _this.props, cacheRequests = _a.cacheRequests, src = _a.src;
|
|
307
253
|
var cache = cacheRequests && cacheStore[src];
|
|
308
|
-
if (cache) {
|
|
309
|
-
|
|
310
|
-
if (cache.status === STATUS.LOADING) {
|
|
311
|
-
cache.queue.push(_this.handleCacheQueue);
|
|
312
|
-
}
|
|
313
|
-
else if (cache.status === STATUS.LOADED) {
|
|
314
|
-
_this.handleLoad(cache.content);
|
|
315
|
-
}
|
|
254
|
+
if (cache && cache.status === STATUS.LOADED) {
|
|
255
|
+
_this.handleLoad(cache.content);
|
|
316
256
|
return;
|
|
317
257
|
}
|
|
318
258
|
var dataURI = src.match(/data:image\/svg[^,]*?(;base64)?,(.*)/);
|
|
319
259
|
var inlineSrc;
|
|
320
260
|
if (dataURI) {
|
|
321
|
-
inlineSrc = dataURI[1] ? atob(dataURI[2]) : decodeURIComponent(dataURI[2]);
|
|
261
|
+
inlineSrc = dataURI[1] ? window.atob(dataURI[2]) : decodeURIComponent(dataURI[2]);
|
|
322
262
|
}
|
|
323
|
-
else if (src.
|
|
263
|
+
else if (src.includes('<svg')) {
|
|
324
264
|
inlineSrc = src;
|
|
325
265
|
}
|
|
326
266
|
if (inlineSrc) {
|
|
@@ -331,16 +271,60 @@ var InlineSVG = /** @class */ (function (_super) {
|
|
|
331
271
|
});
|
|
332
272
|
}
|
|
333
273
|
};
|
|
274
|
+
InlineSVG.prototype.updateSVGAttributes = function (node) {
|
|
275
|
+
var _this = this;
|
|
276
|
+
var _a = this.props, _b = _a.baseURL, baseURL = _b === void 0 ? '' : _b, uniquifyIDs = _a.uniquifyIDs;
|
|
277
|
+
var replaceableAttributes = ['id', 'href', 'xlink:href', 'xlink:role', 'xlink:arcrole'];
|
|
278
|
+
var linkAttributes = ['href', 'xlink:href'];
|
|
279
|
+
var isDataValue = function (name, value) {
|
|
280
|
+
return linkAttributes.includes(name) && (value ? !value.includes('#') : false);
|
|
281
|
+
};
|
|
282
|
+
if (!uniquifyIDs) {
|
|
283
|
+
return node;
|
|
284
|
+
}
|
|
285
|
+
__spreadArray([], __read(node.children), false).map(function (d) {
|
|
286
|
+
if (d.attributes && d.attributes.length) {
|
|
287
|
+
var attributes_1 = Object.values(d.attributes).map(function (a) {
|
|
288
|
+
var attribute = a;
|
|
289
|
+
var match = a.value.match(/url\((.*?)\)/);
|
|
290
|
+
if (match && match[1]) {
|
|
291
|
+
attribute.value = a.value.replace(match[0], "url(".concat(baseURL).concat(match[1], "__").concat(_this.hash, ")"));
|
|
292
|
+
}
|
|
293
|
+
return attribute;
|
|
294
|
+
});
|
|
295
|
+
replaceableAttributes.forEach(function (r) {
|
|
296
|
+
var attribute = attributes_1.find(function (a) { return a.name === r; });
|
|
297
|
+
if (attribute && !isDataValue(r, attribute.value)) {
|
|
298
|
+
attribute.value = "".concat(attribute.value, "__").concat(_this.hash);
|
|
299
|
+
}
|
|
300
|
+
});
|
|
301
|
+
}
|
|
302
|
+
if (d.children.length) {
|
|
303
|
+
return _this.updateSVGAttributes(d);
|
|
304
|
+
}
|
|
305
|
+
return d;
|
|
306
|
+
});
|
|
307
|
+
return node;
|
|
308
|
+
};
|
|
309
|
+
InlineSVG.prototype.processSVG = function () {
|
|
310
|
+
var content = this.state.content;
|
|
311
|
+
var preProcessor = this.props.preProcessor;
|
|
312
|
+
if (preProcessor) {
|
|
313
|
+
return preProcessor(content);
|
|
314
|
+
}
|
|
315
|
+
return content;
|
|
316
|
+
};
|
|
334
317
|
InlineSVG.prototype.render = function () {
|
|
335
318
|
var _a = this.state, element = _a.element, status = _a.status;
|
|
336
|
-
var _b = this.props,
|
|
319
|
+
var _b = this.props, _c = _b.children, children = _c === void 0 ? null : _c, innerRef = _b.innerRef, _d = _b.loader, loader = _d === void 0 ? null : _d;
|
|
320
|
+
var elementProps = omit(this.props, 'baseURL', 'cacheRequests', 'children', 'description', 'fetchOptions', 'innerRef', 'loader', 'onError', 'onLoad', 'preProcessor', 'src', 'title', 'uniqueHash', 'uniquifyIDs');
|
|
337
321
|
if (!canUseDOM()) {
|
|
338
322
|
return loader;
|
|
339
323
|
}
|
|
340
324
|
if (element) {
|
|
341
|
-
return React.cloneElement(element, __assign({ ref: innerRef },
|
|
325
|
+
return React.cloneElement(element, __assign({ ref: innerRef }, elementProps));
|
|
342
326
|
}
|
|
343
|
-
if ([STATUS.UNSUPPORTED, STATUS.FAILED].
|
|
327
|
+
if ([STATUS.UNSUPPORTED, STATUS.FAILED].includes(status)) {
|
|
344
328
|
return children;
|
|
345
329
|
}
|
|
346
330
|
return loader;
|
package/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,OAAO,MAAM,gBAAgB,CAAC;AAErC,OAAO,EAAE,SAAS,EAAE,sBAAsB,EAAE,IAAI,EAAE,YAAY,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AAG1F,MAAM,CAAC,IAAM,UAAU,GAAmC,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;AAE9E;IAAuC,6BAAiC;IAStE,mBAAY,KAAY;Q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ACvB,IAAI,CAAC,KAAK,EACV,SAAS,EACT,eAAe,EACf,UAAU,EACV,aAAa,EACb,cAAc,EACd,UAAU,EACV,QAAQ,EACR,SAAS,EACT,QAAQ,EACR,cAAc,EACd,KAAK,EACL,OAAO,EACP,YAAY,EACZ,aAAa,CACd,CAAC;QAEF,IAAI,CAAC,SAAS,EAAE,EAAE;YAChB,OAAO,MAAM,CAAC;SACf;QAED,IAAI,OAAO,EAAE;YACX,OAAO,KAAK,CAAC,YAAY,CAAC,OAA6B,aAAI,GAAG,EAAE,QAAQ,IAAK,YAAY,EAAG,CAAC;SAC9F;QAED,IAAI,CAAC,MAAM,CAAC,WAAW,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE;YACxD,OAAO,QAAQ,CAAC;SACjB;QAED,OAAO,MAAM,CAAC;IAChB,CAAC;IA5Wa,sBAAY,GAAG;QAC3B,aAAa,EAAE,IAAI;QACnB,WAAW,EAAE,KAAK;KACnB,CAAC;IA0WJ,gBAAC;CAAA,AAjXD,CAAuC,KAAK,CAAC,aAAa,GAiXzD;eAjXoB,SAAS;AAmX9B,cAAc,SAAS,CAAC"}
|
package/esm/types.d.ts
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
declare type Callback = (...args: any[]) => void;
|
|
3
2
|
export declare type ErrorCallback = (error: Error | FetchError) => void;
|
|
4
3
|
export declare type LoadCallback = (src: string, isCached: boolean) => void;
|
|
4
|
+
export declare type PlainObject<T = unknown> = Record<string | number | symbol, T>;
|
|
5
5
|
export declare type PreProcessorCallback = (code: string) => string;
|
|
6
6
|
export interface Props extends Omit<React.SVGProps<SVGElement>, 'onLoad' | 'onError' | 'ref'> {
|
|
7
7
|
baseURL?: string;
|
|
8
8
|
cacheRequests?: boolean;
|
|
9
9
|
children?: React.ReactNode;
|
|
10
10
|
description?: string;
|
|
11
|
+
fetchOptions?: RequestInit;
|
|
11
12
|
innerRef?: React.Ref<SVGElement>;
|
|
12
13
|
loader?: React.ReactNode;
|
|
13
14
|
onError?: ErrorCallback;
|
|
@@ -32,7 +33,5 @@ export interface FetchError extends Error {
|
|
|
32
33
|
}
|
|
33
34
|
export interface StorageItem {
|
|
34
35
|
content: string;
|
|
35
|
-
queue: Callback[];
|
|
36
36
|
status: string;
|
|
37
37
|
}
|
|
38
|
-
export {};
|