react-inlinesvg 3.0.0 → 3.0.2
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 +12 -12
- package/esm/index.d.ts +1 -0
- package/esm/index.js +318 -230
- package/esm/index.js.map +1 -1
- package/esm/types.d.ts +5 -5
- package/lib/index.d.ts +1 -0
- package/lib/index.js +318 -230
- package/lib/index.js.map +1 -1
- package/lib/types.d.ts +5 -5
- package/package.json +27 -27
- package/src/index.tsx +15 -8
- package/src/types.ts +1 -1
package/README.md
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
# react-inlinesvg
|
|
2
2
|
|
|
3
|
-
[](https://www.npmjs.com/package/react-inlinesvg) [](https://www.npmjs.com/package/react-inlinesvg) [](https://github.com/gilbarbara/react-inlinesvg/actions/workflows/main.yml) [](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
|
|
|
7
|
+
View the [demo](https://codesandbox.io/s/github/gilbarbara/react-inlinesvg/tree/main/demo)
|
|
8
|
+
|
|
7
9
|
## Highlights
|
|
8
10
|
|
|
9
11
|
- 🏖 **Easy to use:** Just set the `src`
|
|
@@ -21,20 +23,18 @@ npm i react-inlinesvg
|
|
|
21
23
|
And import it into your code:
|
|
22
24
|
|
|
23
25
|
```tsx
|
|
24
|
-
import React
|
|
25
|
-
import SVG
|
|
26
|
-
|
|
27
|
-
const Logo = React.forwardRef<SVGElement, SVGProps>((props, ref) => (
|
|
28
|
-
<SVG innerRef={ref} title="MyLogo" {...props} />
|
|
29
|
-
));
|
|
30
|
-
|
|
31
|
-
export function App() {
|
|
32
|
-
const logo = useRef<SVGElement>(null);
|
|
26
|
+
import React from 'react';
|
|
27
|
+
import SVG from 'react-inlinesvg';
|
|
33
28
|
|
|
29
|
+
export default function App() {
|
|
34
30
|
return (
|
|
35
31
|
<main>
|
|
36
|
-
<SVG
|
|
37
|
-
|
|
32
|
+
<SVG
|
|
33
|
+
src="https://cdn.svgporn.com/logos/react.svg"
|
|
34
|
+
width={128}
|
|
35
|
+
height="auto"
|
|
36
|
+
title="React"
|
|
37
|
+
/>
|
|
38
38
|
</main>
|
|
39
39
|
);
|
|
40
40
|
}
|
package/esm/index.d.ts
CHANGED
package/esm/index.js
CHANGED
|
@@ -57,83 +57,117 @@ var InlineSVG = /** @class */ (function (_super) {
|
|
|
57
57
|
__extends(InlineSVG, _super);
|
|
58
58
|
function InlineSVG(props) {
|
|
59
59
|
var _this = _super.call(this, props) || this;
|
|
60
|
-
_this
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
60
|
+
Object.defineProperty(_this, "isInitialized", {
|
|
61
|
+
enumerable: true,
|
|
62
|
+
configurable: true,
|
|
63
|
+
writable: true,
|
|
64
|
+
value: false
|
|
65
|
+
});
|
|
66
|
+
Object.defineProperty(_this, "isActive", {
|
|
67
|
+
enumerable: true,
|
|
68
|
+
configurable: true,
|
|
69
|
+
writable: true,
|
|
70
|
+
value: false
|
|
71
|
+
});
|
|
72
|
+
Object.defineProperty(_this, "hash", {
|
|
73
|
+
enumerable: true,
|
|
74
|
+
configurable: true,
|
|
75
|
+
writable: true,
|
|
76
|
+
value: void 0
|
|
77
|
+
});
|
|
78
|
+
Object.defineProperty(_this, "handleLoad", {
|
|
79
|
+
enumerable: true,
|
|
80
|
+
configurable: true,
|
|
81
|
+
writable: true,
|
|
82
|
+
value: function (content, hasCache) {
|
|
83
|
+
if (hasCache === void 0) { hasCache = false; }
|
|
84
|
+
/* istanbul ignore else */
|
|
85
|
+
if (_this.isActive) {
|
|
86
|
+
_this.setState({
|
|
87
|
+
content: content,
|
|
88
|
+
hasCache: hasCache,
|
|
89
|
+
status: STATUS.LOADED,
|
|
90
|
+
}, _this.getElement);
|
|
91
|
+
}
|
|
81
92
|
}
|
|
82
|
-
};
|
|
83
|
-
_this
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
93
|
+
});
|
|
94
|
+
Object.defineProperty(_this, "handleError", {
|
|
95
|
+
enumerable: true,
|
|
96
|
+
configurable: true,
|
|
97
|
+
writable: true,
|
|
98
|
+
value: function (error) {
|
|
99
|
+
var onError = _this.props.onError;
|
|
100
|
+
var status = error.message === 'Browser does not support SVG' ? STATUS.UNSUPPORTED : STATUS.FAILED;
|
|
101
|
+
/* istanbul ignore else */
|
|
102
|
+
if (_this.isActive) {
|
|
103
|
+
_this.setState({ status: status }, function () {
|
|
104
|
+
/* istanbul ignore else */
|
|
105
|
+
if (typeof onError === 'function') {
|
|
106
|
+
onError(error);
|
|
107
|
+
}
|
|
108
|
+
});
|
|
88
109
|
}
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
110
|
+
}
|
|
111
|
+
});
|
|
112
|
+
Object.defineProperty(_this, "request", {
|
|
113
|
+
enumerable: true,
|
|
114
|
+
configurable: true,
|
|
115
|
+
writable: true,
|
|
116
|
+
value: function () {
|
|
117
|
+
var _a = _this.props, cacheRequests = _a.cacheRequests, fetchOptions = _a.fetchOptions, src = _a.src;
|
|
118
|
+
try {
|
|
119
|
+
if (cacheRequests) {
|
|
120
|
+
cacheStore[src] = { content: '', status: STATUS.LOADING };
|
|
98
121
|
}
|
|
99
|
-
return
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
if (cacheStore[src].status === STATUS.LOADING) {
|
|
106
|
-
delete cacheStore[src];
|
|
122
|
+
return fetch(src, fetchOptions)
|
|
123
|
+
.then(function (response) {
|
|
124
|
+
var contentType = response.headers.get('content-type');
|
|
125
|
+
var _a = __read((contentType || '').split(/ ?; ?/), 1), fileType = _a[0];
|
|
126
|
+
if (response.status > 299) {
|
|
127
|
+
throw new Error('Not found');
|
|
107
128
|
}
|
|
108
|
-
return;
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
129
|
+
if (!['image/svg+xml', 'text/plain'].some(function (d) { return fileType.includes(d); })) {
|
|
130
|
+
throw new Error("Content type isn't valid: ".concat(fileType));
|
|
131
|
+
}
|
|
132
|
+
return response.text();
|
|
133
|
+
})
|
|
134
|
+
.then(function (content) {
|
|
135
|
+
var currentSrc = _this.props.src;
|
|
136
|
+
// the current src don't match the previous one, skipping...
|
|
137
|
+
if (src !== currentSrc) {
|
|
138
|
+
if (cacheStore[src].status === STATUS.LOADING) {
|
|
139
|
+
delete cacheStore[src];
|
|
140
|
+
}
|
|
141
|
+
return;
|
|
142
|
+
}
|
|
143
|
+
_this.handleLoad(content);
|
|
114
144
|
/* istanbul ignore else */
|
|
115
|
-
if (
|
|
116
|
-
cache
|
|
117
|
-
|
|
145
|
+
if (cacheRequests) {
|
|
146
|
+
var cache = cacheStore[src];
|
|
147
|
+
/* istanbul ignore else */
|
|
148
|
+
if (cache) {
|
|
149
|
+
cache.content = content;
|
|
150
|
+
cache.status = STATUS.LOADED;
|
|
151
|
+
}
|
|
118
152
|
}
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
_this.handleError(error);
|
|
123
|
-
/* istanbul ignore else */
|
|
124
|
-
if (cacheRequests) {
|
|
125
|
-
var cache = cacheStore[src];
|
|
153
|
+
})
|
|
154
|
+
.catch(function (error) {
|
|
155
|
+
_this.handleError(error);
|
|
126
156
|
/* istanbul ignore else */
|
|
127
|
-
if (
|
|
128
|
-
|
|
157
|
+
if (cacheRequests) {
|
|
158
|
+
var cache = cacheStore[src];
|
|
159
|
+
/* istanbul ignore else */
|
|
160
|
+
if (cache) {
|
|
161
|
+
delete cacheStore[src];
|
|
162
|
+
}
|
|
129
163
|
}
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
catch (error) {
|
|
167
|
+
return _this.handleError(new Error(error.message));
|
|
168
|
+
}
|
|
135
169
|
}
|
|
136
|
-
};
|
|
170
|
+
});
|
|
137
171
|
_this.state = {
|
|
138
172
|
content: '',
|
|
139
173
|
element: null,
|
|
@@ -143,196 +177,250 @@ var InlineSVG = /** @class */ (function (_super) {
|
|
|
143
177
|
_this.hash = props.uniqueHash || randomString(8);
|
|
144
178
|
return _this;
|
|
145
179
|
}
|
|
146
|
-
InlineSVG.prototype
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
180
|
+
Object.defineProperty(InlineSVG.prototype, "componentDidMount", {
|
|
181
|
+
enumerable: false,
|
|
182
|
+
configurable: true,
|
|
183
|
+
writable: true,
|
|
184
|
+
value: function () {
|
|
185
|
+
this.isActive = true;
|
|
186
|
+
if (!canUseDOM() || this.isInitialized) {
|
|
187
|
+
return;
|
|
188
|
+
}
|
|
189
|
+
var status = this.state.status;
|
|
190
|
+
var src = this.props.src;
|
|
191
|
+
try {
|
|
156
192
|
/* istanbul ignore else */
|
|
157
|
-
if (
|
|
158
|
-
|
|
193
|
+
if (status === STATUS.PENDING) {
|
|
194
|
+
/* istanbul ignore else */
|
|
195
|
+
if (!isSupportedEnvironment()) {
|
|
196
|
+
throw new Error('Browser does not support SVG');
|
|
197
|
+
}
|
|
198
|
+
/* istanbul ignore else */
|
|
199
|
+
if (!src) {
|
|
200
|
+
throw new Error('Missing src');
|
|
201
|
+
}
|
|
202
|
+
this.load();
|
|
159
203
|
}
|
|
204
|
+
}
|
|
205
|
+
catch (error) {
|
|
206
|
+
this.handleError(error);
|
|
207
|
+
}
|
|
208
|
+
this.isInitialized = true;
|
|
209
|
+
}
|
|
210
|
+
});
|
|
211
|
+
Object.defineProperty(InlineSVG.prototype, "componentDidUpdate", {
|
|
212
|
+
enumerable: false,
|
|
213
|
+
configurable: true,
|
|
214
|
+
writable: true,
|
|
215
|
+
value: function (previousProps, previousState) {
|
|
216
|
+
if (!canUseDOM()) {
|
|
217
|
+
return;
|
|
218
|
+
}
|
|
219
|
+
var _a = this.state, hasCache = _a.hasCache, status = _a.status;
|
|
220
|
+
var _b = this.props, onLoad = _b.onLoad, src = _b.src;
|
|
221
|
+
if (previousState.status !== STATUS.READY && status === STATUS.READY) {
|
|
160
222
|
/* istanbul ignore else */
|
|
223
|
+
if (onLoad) {
|
|
224
|
+
onLoad(src, hasCache);
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
if (previousProps.src !== src) {
|
|
161
228
|
if (!src) {
|
|
162
|
-
|
|
229
|
+
this.handleError(new Error('Missing src'));
|
|
230
|
+
return;
|
|
163
231
|
}
|
|
164
232
|
this.load();
|
|
165
233
|
}
|
|
166
234
|
}
|
|
167
|
-
|
|
168
|
-
|
|
235
|
+
});
|
|
236
|
+
Object.defineProperty(InlineSVG.prototype, "componentWillUnmount", {
|
|
237
|
+
enumerable: false,
|
|
238
|
+
configurable: true,
|
|
239
|
+
writable: true,
|
|
240
|
+
value: function () {
|
|
241
|
+
this.isActive = false;
|
|
169
242
|
}
|
|
170
|
-
};
|
|
171
|
-
InlineSVG.prototype
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
243
|
+
});
|
|
244
|
+
Object.defineProperty(InlineSVG.prototype, "getNode", {
|
|
245
|
+
enumerable: false,
|
|
246
|
+
configurable: true,
|
|
247
|
+
writable: true,
|
|
248
|
+
value: function () {
|
|
249
|
+
var _a = this.props, description = _a.description, title = _a.title;
|
|
250
|
+
try {
|
|
251
|
+
var svgText = this.processSVG();
|
|
252
|
+
var node = convert(svgText, { nodeOnly: true });
|
|
253
|
+
if (!node || !(node instanceof SVGSVGElement)) {
|
|
254
|
+
throw new Error('Could not convert the src to a DOM Node');
|
|
255
|
+
}
|
|
256
|
+
var svg = this.updateSVGAttributes(node);
|
|
257
|
+
if (description) {
|
|
258
|
+
var originalDesc = svg.querySelector('desc');
|
|
259
|
+
if (originalDesc && originalDesc.parentNode) {
|
|
260
|
+
originalDesc.parentNode.removeChild(originalDesc);
|
|
261
|
+
}
|
|
262
|
+
var descElement = document.createElementNS('http://www.w3.org/2000/svg', 'desc');
|
|
263
|
+
descElement.innerHTML = description;
|
|
264
|
+
svg.prepend(descElement);
|
|
265
|
+
}
|
|
266
|
+
if (typeof title !== 'undefined') {
|
|
267
|
+
var originalTitle = svg.querySelector('title');
|
|
268
|
+
if (originalTitle && originalTitle.parentNode) {
|
|
269
|
+
originalTitle.parentNode.removeChild(originalTitle);
|
|
270
|
+
}
|
|
271
|
+
if (title) {
|
|
272
|
+
var titleElement = document.createElementNS('http://www.w3.org/2000/svg', 'title');
|
|
273
|
+
titleElement.innerHTML = title;
|
|
274
|
+
svg.prepend(titleElement);
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
return svg;
|
|
181
278
|
}
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
if (!src) {
|
|
185
|
-
this.handleError(new Error('Missing src'));
|
|
186
|
-
return;
|
|
279
|
+
catch (error) {
|
|
280
|
+
return this.handleError(error);
|
|
187
281
|
}
|
|
188
|
-
this.load();
|
|
189
282
|
}
|
|
190
|
-
};
|
|
191
|
-
InlineSVG.prototype
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
}
|
|
202
|
-
var svg = this.updateSVGAttributes(node);
|
|
203
|
-
if (description) {
|
|
204
|
-
var originalDesc = svg.querySelector('desc');
|
|
205
|
-
if (originalDesc && originalDesc.parentNode) {
|
|
206
|
-
originalDesc.parentNode.removeChild(originalDesc);
|
|
283
|
+
});
|
|
284
|
+
Object.defineProperty(InlineSVG.prototype, "getElement", {
|
|
285
|
+
enumerable: false,
|
|
286
|
+
configurable: true,
|
|
287
|
+
writable: true,
|
|
288
|
+
value: function () {
|
|
289
|
+
try {
|
|
290
|
+
var node = this.getNode();
|
|
291
|
+
var element = convert(node);
|
|
292
|
+
if (!element || !React.isValidElement(element)) {
|
|
293
|
+
throw new Error('Could not convert the src to a React element');
|
|
207
294
|
}
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
295
|
+
this.setState({
|
|
296
|
+
element: element,
|
|
297
|
+
status: STATUS.READY,
|
|
298
|
+
});
|
|
211
299
|
}
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
if (originalTitle && originalTitle.parentNode) {
|
|
215
|
-
originalTitle.parentNode.removeChild(originalTitle);
|
|
216
|
-
}
|
|
217
|
-
var titleElement = document.createElement('title');
|
|
218
|
-
titleElement.innerHTML = title;
|
|
219
|
-
svg.prepend(titleElement);
|
|
300
|
+
catch (error) {
|
|
301
|
+
this.handleError(new Error(error.message));
|
|
220
302
|
}
|
|
221
|
-
return svg;
|
|
222
|
-
}
|
|
223
|
-
catch (error) {
|
|
224
|
-
return this.handleError(error);
|
|
225
303
|
}
|
|
226
|
-
};
|
|
227
|
-
InlineSVG.prototype
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
304
|
+
});
|
|
305
|
+
Object.defineProperty(InlineSVG.prototype, "load", {
|
|
306
|
+
enumerable: false,
|
|
307
|
+
configurable: true,
|
|
308
|
+
writable: true,
|
|
309
|
+
value: function () {
|
|
310
|
+
var _this = this;
|
|
311
|
+
/* istanbul ignore else */
|
|
312
|
+
if (this.isActive) {
|
|
313
|
+
this.setState({
|
|
314
|
+
content: '',
|
|
315
|
+
element: null,
|
|
316
|
+
hasCache: false,
|
|
317
|
+
status: STATUS.LOADING,
|
|
318
|
+
}, function () {
|
|
319
|
+
var _a = _this.props, cacheRequests = _a.cacheRequests, src = _a.src;
|
|
320
|
+
var cache = cacheRequests && cacheStore[src];
|
|
321
|
+
if (cache && cache.status === STATUS.LOADED) {
|
|
322
|
+
_this.handleLoad(cache.content, true);
|
|
323
|
+
return;
|
|
324
|
+
}
|
|
325
|
+
var dataURI = src.match(/data:image\/svg[^,]*?(;base64)?,(.*)/);
|
|
326
|
+
var inlineSrc;
|
|
327
|
+
if (dataURI) {
|
|
328
|
+
inlineSrc = dataURI[1] ? window.atob(dataURI[2]) : decodeURIComponent(dataURI[2]);
|
|
329
|
+
}
|
|
330
|
+
else if (src.includes('<svg')) {
|
|
331
|
+
inlineSrc = src;
|
|
332
|
+
}
|
|
333
|
+
if (inlineSrc) {
|
|
334
|
+
_this.handleLoad(inlineSrc);
|
|
335
|
+
return;
|
|
336
|
+
}
|
|
337
|
+
_this.request();
|
|
338
|
+
});
|
|
233
339
|
}
|
|
234
|
-
this.setState({
|
|
235
|
-
element: element,
|
|
236
|
-
status: STATUS.READY,
|
|
237
|
-
});
|
|
238
|
-
}
|
|
239
|
-
catch (error) {
|
|
240
|
-
this.handleError(new Error(error.message));
|
|
241
340
|
}
|
|
242
|
-
};
|
|
243
|
-
InlineSVG.prototype
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
341
|
+
});
|
|
342
|
+
Object.defineProperty(InlineSVG.prototype, "updateSVGAttributes", {
|
|
343
|
+
enumerable: false,
|
|
344
|
+
configurable: true,
|
|
345
|
+
writable: true,
|
|
346
|
+
value: function (node) {
|
|
347
|
+
var _this = this;
|
|
348
|
+
var _a = this.props, _b = _a.baseURL, baseURL = _b === void 0 ? '' : _b, uniquifyIDs = _a.uniquifyIDs;
|
|
349
|
+
var replaceableAttributes = ['id', 'href', 'xlink:href', 'xlink:role', 'xlink:arcrole'];
|
|
350
|
+
var linkAttributes = ['href', 'xlink:href'];
|
|
351
|
+
var isDataValue = function (name, value) {
|
|
352
|
+
return linkAttributes.includes(name) && (value ? !value.includes('#') : false);
|
|
353
|
+
};
|
|
354
|
+
if (!uniquifyIDs) {
|
|
355
|
+
return node;
|
|
356
|
+
}
|
|
357
|
+
__spreadArray([], __read(node.children), false).map(function (d) {
|
|
358
|
+
if (d.attributes && d.attributes.length) {
|
|
359
|
+
var attributes_1 = Object.values(d.attributes).map(function (a) {
|
|
360
|
+
var attribute = a;
|
|
361
|
+
var match = a.value.match(/url\((.*?)\)/);
|
|
362
|
+
if (match && match[1]) {
|
|
363
|
+
attribute.value = a.value.replace(match[0], "url(".concat(baseURL).concat(match[1], "__").concat(_this.hash, ")"));
|
|
364
|
+
}
|
|
365
|
+
return attribute;
|
|
366
|
+
});
|
|
367
|
+
replaceableAttributes.forEach(function (r) {
|
|
368
|
+
var attribute = attributes_1.find(function (a) { return a.name === r; });
|
|
369
|
+
if (attribute && !isDataValue(r, attribute.value)) {
|
|
370
|
+
attribute.value = "".concat(attribute.value, "__").concat(_this.hash);
|
|
371
|
+
}
|
|
372
|
+
});
|
|
265
373
|
}
|
|
266
|
-
if (
|
|
267
|
-
_this.
|
|
268
|
-
return;
|
|
374
|
+
if (d.children.length) {
|
|
375
|
+
return _this.updateSVGAttributes(d);
|
|
269
376
|
}
|
|
270
|
-
|
|
377
|
+
return d;
|
|
271
378
|
});
|
|
272
|
-
}
|
|
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
379
|
return node;
|
|
284
380
|
}
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
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
|
-
});
|
|
381
|
+
});
|
|
382
|
+
Object.defineProperty(InlineSVG.prototype, "processSVG", {
|
|
383
|
+
enumerable: false,
|
|
384
|
+
configurable: true,
|
|
385
|
+
writable: true,
|
|
386
|
+
value: function () {
|
|
387
|
+
var content = this.state.content;
|
|
388
|
+
var preProcessor = this.props.preProcessor;
|
|
389
|
+
if (preProcessor) {
|
|
390
|
+
return preProcessor(content);
|
|
301
391
|
}
|
|
302
|
-
|
|
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);
|
|
392
|
+
return content;
|
|
314
393
|
}
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
394
|
+
});
|
|
395
|
+
Object.defineProperty(InlineSVG.prototype, "render", {
|
|
396
|
+
enumerable: false,
|
|
397
|
+
configurable: true,
|
|
398
|
+
writable: true,
|
|
399
|
+
value: function () {
|
|
400
|
+
var _a = this.state, element = _a.element, status = _a.status;
|
|
401
|
+
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;
|
|
402
|
+
var elementProps = omit(this.props, 'baseURL', 'cacheRequests', 'children', 'description', 'fetchOptions', 'innerRef', 'loader', 'onError', 'onLoad', 'preProcessor', 'src', 'title', 'uniqueHash', 'uniquifyIDs');
|
|
403
|
+
if (!canUseDOM()) {
|
|
404
|
+
return loader;
|
|
405
|
+
}
|
|
406
|
+
if (element) {
|
|
407
|
+
return React.cloneElement(element, __assign({ ref: innerRef }, elementProps));
|
|
408
|
+
}
|
|
409
|
+
if ([STATUS.UNSUPPORTED, STATUS.FAILED].includes(status)) {
|
|
410
|
+
return children;
|
|
411
|
+
}
|
|
322
412
|
return loader;
|
|
323
413
|
}
|
|
324
|
-
|
|
325
|
-
|
|
414
|
+
});
|
|
415
|
+
Object.defineProperty(InlineSVG, "defaultProps", {
|
|
416
|
+
enumerable: true,
|
|
417
|
+
configurable: true,
|
|
418
|
+
writable: true,
|
|
419
|
+
value: {
|
|
420
|
+
cacheRequests: true,
|
|
421
|
+
uniquifyIDs: false,
|
|
326
422
|
}
|
|
327
|
-
|
|
328
|
-
return children;
|
|
329
|
-
}
|
|
330
|
-
return loader;
|
|
331
|
-
};
|
|
332
|
-
InlineSVG.defaultProps = {
|
|
333
|
-
cacheRequests: true,
|
|
334
|
-
uniquifyIDs: false,
|
|
335
|
-
};
|
|
423
|
+
});
|
|
336
424
|
return InlineSVG;
|
|
337
425
|
}(React.PureComponent));
|
|
338
426
|
export default InlineSVG;
|