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