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