react-inlinesvg 2.2.2 → 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/lib/index.js CHANGED
@@ -7,6 +7,8 @@ var __extends = (this && this.__extends) || (function () {
7
7
  return extendStatics(d, b);
8
8
  };
9
9
  return function (d, b) {
10
+ if (typeof b !== "function" && b !== null)
11
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
10
12
  extendStatics(d, b);
11
13
  function __() { this.constructor = d; }
12
14
  d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
@@ -25,7 +27,11 @@ var __assign = (this && this.__assign) || function () {
25
27
  };
26
28
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
27
29
  if (k2 === undefined) k2 = k;
28
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
30
+ var desc = Object.getOwnPropertyDescriptor(m, k);
31
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
32
+ desc = { enumerable: true, get: function() { return m[k]; } };
33
+ }
34
+ Object.defineProperty(o, k2, desc);
29
35
  }) : (function(o, m, k, k2) {
30
36
  if (k2 === undefined) k2 = k;
31
37
  o[k2] = m[k];
@@ -49,308 +55,384 @@ var __read = (this && this.__read) || function (o, n) {
49
55
  }
50
56
  return ar;
51
57
  };
52
- var __spread = (this && this.__spread) || function () {
53
- for (var ar = [], i = 0; i < arguments.length; i++) ar = ar.concat(__read(arguments[i]));
54
- return ar;
58
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
59
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
60
+ if (ar || !(i in from)) {
61
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
62
+ ar[i] = from[i];
63
+ }
64
+ }
65
+ return to.concat(ar || Array.prototype.slice.call(from));
55
66
  };
56
67
  Object.defineProperty(exports, "__esModule", { value: true });
68
+ exports.cacheStore = void 0;
57
69
  var React = require("react");
58
70
  var react_from_dom_1 = require("react-from-dom");
59
71
  var helpers_1 = require("./helpers");
60
- var cacheStore = Object.create(null);
72
+ exports.cacheStore = Object.create(null);
61
73
  var InlineSVG = /** @class */ (function (_super) {
62
74
  __extends(InlineSVG, _super);
63
75
  function InlineSVG(props) {
64
76
  var _this = _super.call(this, props) || this;
65
- _this.isActive = false;
66
- _this.handleCacheQueue = function (content) {
67
- /* istanbul ignore else */
68
- if (typeof content === 'string') {
69
- _this.handleLoad(content);
70
- return;
71
- }
72
- _this.handleError(content);
73
- };
74
- _this.handleLoad = function (content) {
75
- /* istanbul ignore else */
76
- if (_this.isActive) {
77
- _this.setState({
78
- content: content,
79
- status: helpers_1.STATUS.LOADED,
80
- }, _this.getElement);
81
- }
82
- };
83
- _this.handleError = function (error) {
84
- var onError = _this.props.onError;
85
- var status = error.message === 'Browser does not support SVG' ? helpers_1.STATUS.UNSUPPORTED : helpers_1.STATUS.FAILED;
86
- /* istanbul ignore else */
87
- if (_this.isActive) {
88
- _this.setState({ status: status }, function () {
89
- /* istanbul ignore else */
90
- if (typeof onError === 'function') {
91
- onError(error);
92
- }
93
- });
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
+ }
94
107
  }
95
- };
96
- _this.request = function () {
97
- var _a = _this.props, cacheRequests = _a.cacheRequests, src = _a.src;
98
- try {
99
- if (cacheRequests) {
100
- cacheStore[src] = { content: '', status: helpers_1.STATUS.LOADING, queue: [] };
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
+ });
101
124
  }
102
- return fetch(src)
103
- .then(function (response) {
104
- var contentType = response.headers.get('content-type');
105
- var _a = __read((contentType || '').split(/ ?; ?/), 1), fileType = _a[0];
106
- if (response.status > 299) {
107
- throw new Error('Not found');
108
- }
109
- if (!['image/svg+xml', 'text/plain'].some(function (d) { return fileType.indexOf(d) >= 0; })) {
110
- throw new Error("Content type isn't valid: " + fileType);
111
- }
112
- return response.text();
113
- })
114
- .then(function (content) {
115
- _this.handleLoad(content);
116
- /* istanbul ignore else */
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 {
117
134
  if (cacheRequests) {
118
- var cache = cacheStore[src];
135
+ exports.cacheStore[src] = { content: '', status: helpers_1.STATUS.LOADING };
136
+ }
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');
143
+ }
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);
119
159
  /* istanbul ignore else */
120
- if (cache) {
121
- cache.content = content;
122
- cache.status = helpers_1.STATUS.LOADED;
123
- cache.queue = cache.queue.filter(function (cb) {
124
- cb(content);
125
- return false;
126
- });
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
+ }
127
167
  }
128
- }
129
- })
130
- .catch(function (error) {
131
- _this.handleError(error);
132
- /* istanbul ignore else */
133
- if (cacheRequests) {
134
- var cache = cacheStore[src];
168
+ })
169
+ .catch(function (error) {
170
+ _this.handleError(error);
135
171
  /* istanbul ignore else */
136
- if (cache) {
137
- cache.queue.forEach(function (cb) {
138
- cb(error);
139
- });
140
- delete cacheStore[src];
172
+ if (cacheRequests) {
173
+ var cache = exports.cacheStore[src];
174
+ /* istanbul ignore else */
175
+ if (cache) {
176
+ delete exports.cacheStore[src];
177
+ }
141
178
  }
142
- }
143
- });
144
- }
145
- catch (error) {
146
- return _this.handleError(new Error(error.message));
179
+ });
180
+ }
181
+ catch (error) {
182
+ return _this.handleError(new Error(error.message));
183
+ }
147
184
  }
148
- };
185
+ });
149
186
  _this.state = {
150
187
  content: '',
151
188
  element: null,
152
- hasCache: !!props.cacheRequests && !!cacheStore[props.src],
189
+ hasCache: !!props.cacheRequests && !!exports.cacheStore[props.src],
153
190
  status: helpers_1.STATUS.PENDING,
154
191
  };
155
- _this.hash = props.uniqueHash || helpers_1.randomString(8);
192
+ _this.hash = props.uniqueHash || (0, helpers_1.randomString)(8);
156
193
  return _this;
157
194
  }
158
- InlineSVG.prototype.componentDidMount = function () {
159
- this.isActive = true;
160
- if (!helpers_1.canUseDOM()) {
161
- return;
162
- }
163
- var status = this.state.status;
164
- var src = this.props.src;
165
- try {
166
- /* istanbul ignore else */
167
- if (status === helpers_1.STATUS.PENDING) {
168
- /* istanbul ignore else */
169
- if (!helpers_1.isSupportedEnvironment()) {
170
- throw new Error('Browser does not support SVG');
171
- }
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 {
172
207
  /* istanbul ignore else */
173
- if (!src) {
174
- throw new Error('Missing src');
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();
175
218
  }
176
- this.load();
177
219
  }
178
- }
179
- catch (error) {
180
- this.handleError(error);
181
- }
182
- };
183
- InlineSVG.prototype.componentDidUpdate = function (prevProps, prevState) {
184
- if (!helpers_1.canUseDOM()) {
185
- return;
186
- }
187
- var _a = this.state, hasCache = _a.hasCache, status = _a.status;
188
- var _b = this.props, onLoad = _b.onLoad, src = _b.src;
189
- if (prevState.status !== helpers_1.STATUS.READY && status === helpers_1.STATUS.READY) {
190
- /* istanbul ignore else */
191
- if (onLoad) {
192
- onLoad(src, hasCache);
220
+ catch (error) {
221
+ this.handleError(error);
193
222
  }
223
+ this.isInitialized = true;
194
224
  }
195
- if (prevProps.src !== src) {
196
- if (!src) {
197
- this.handleError(new Error('Missing src'));
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)()) {
198
232
  return;
199
233
  }
200
- this.load();
201
- }
202
- };
203
- InlineSVG.prototype.componentWillUnmount = function () {
204
- this.isActive = false;
205
- };
206
- InlineSVG.prototype.processSVG = function () {
207
- var content = this.state.content;
208
- var preProcessor = this.props.preProcessor;
209
- if (preProcessor) {
210
- return preProcessor(content);
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) {
237
+ /* istanbul ignore else */
238
+ if (onLoad) {
239
+ onLoad(src, hasCache);
240
+ }
241
+ }
242
+ if (previousProps.src !== src) {
243
+ if (!src) {
244
+ this.handleError(new Error('Missing src'));
245
+ return;
246
+ }
247
+ this.load();
248
+ }
211
249
  }
212
- return content;
213
- };
214
- InlineSVG.prototype.updateSVGAttributes = function (node) {
215
- var _this = this;
216
- var _a = this.props, _b = _a.baseURL, baseURL = _b === void 0 ? '' : _b, uniquifyIDs = _a.uniquifyIDs;
217
- var replaceableAttributes = ['id', 'href', 'xlink:href', 'xlink:role', 'xlink:arcrole'];
218
- var linkAttributes = ['href', 'xlink:href'];
219
- var isDataValue = function (name, value) {
220
- return linkAttributes.indexOf(name) >= 0 && (value ? value.indexOf('#') < 0 : false);
221
- };
222
- if (!uniquifyIDs) {
223
- return node;
250
+ });
251
+ Object.defineProperty(InlineSVG.prototype, "componentWillUnmount", {
252
+ enumerable: false,
253
+ configurable: true,
254
+ writable: true,
255
+ value: function () {
256
+ this.isActive = false;
224
257
  }
225
- __spread(node.children).map(function (d) {
226
- if (d.attributes && d.attributes.length) {
227
- var attributes_1 = Object.values(d.attributes).map(function (a) {
228
- var attr = a;
229
- var match = a.value.match(/url\((.*?)\)/);
230
- if (match && match[1]) {
231
- attr.value = a.value.replace(match[0], "url(" + baseURL + match[1] + "__" + _this.hash + ")");
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);
232
276
  }
233
- return attr;
234
- });
235
- replaceableAttributes.forEach(function (r) {
236
- var attribute = attributes_1.find(function (a) { return a.name === r; });
237
- if (attribute && !isDataValue(r, attribute.value)) {
238
- attribute.value = attribute.value + "__" + _this.hash;
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);
239
285
  }
240
- });
241
- }
242
- if (d.children.length) {
243
- return _this.updateSVGAttributes(d);
244
- }
245
- return d;
246
- });
247
- return node;
248
- };
249
- InlineSVG.prototype.getNode = function () {
250
- var _a = this.props, description = _a.description, title = _a.title;
251
- try {
252
- var svgText = this.processSVG();
253
- var node = react_from_dom_1.default(svgText, { nodeOnly: true });
254
- if (!node || !(node instanceof SVGSVGElement)) {
255
- throw new Error('Could not convert the src to a DOM Node');
256
- }
257
- var svg = this.updateSVGAttributes(node);
258
- if (description) {
259
- var originalDesc = svg.querySelector('desc');
260
- if (originalDesc && originalDesc.parentNode) {
261
- originalDesc.parentNode.removeChild(originalDesc);
286
+ var titleElement = document.createElement('title');
287
+ titleElement.innerHTML = title;
288
+ svg.prepend(titleElement);
262
289
  }
263
- var descElement = document.createElement('desc');
264
- descElement.innerHTML = description;
265
- svg.prepend(descElement);
290
+ return svg;
266
291
  }
267
- if (title) {
268
- var originalTitle = svg.querySelector('title');
269
- if (originalTitle && originalTitle.parentNode) {
270
- originalTitle.parentNode.removeChild(originalTitle);
271
- }
272
- var titleElement = document.createElement('title');
273
- titleElement.innerHTML = title;
274
- svg.prepend(titleElement);
292
+ catch (error) {
293
+ return this.handleError(error);
275
294
  }
276
- return svg;
277
- }
278
- catch (error) {
279
- return this.handleError(error);
280
295
  }
281
- };
282
- InlineSVG.prototype.getElement = function () {
283
- try {
284
- var node = this.getNode();
285
- var element = react_from_dom_1.default(node);
286
- if (!element || !React.isValidElement(element)) {
287
- throw new Error('Could not convert the src to a React element');
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');
307
+ }
308
+ this.setState({
309
+ element: element,
310
+ status: helpers_1.STATUS.READY,
311
+ });
312
+ }
313
+ catch (error) {
314
+ this.handleError(new Error(error.message));
288
315
  }
289
- this.setState({
290
- element: element,
291
- status: helpers_1.STATUS.READY,
292
- });
293
- }
294
- catch (error) {
295
- this.handleError(new Error(error.message));
296
316
  }
297
- };
298
- InlineSVG.prototype.load = function () {
299
- var _this = this;
300
- /* istanbul ignore else */
301
- if (this.isActive) {
302
- this.setState({
303
- content: '',
304
- element: null,
305
- status: helpers_1.STATUS.LOADING,
306
- }, function () {
307
- var _a = _this.props, cacheRequests = _a.cacheRequests, src = _a.src;
308
- var cache = cacheRequests && cacheStore[src];
309
- if (cache) {
310
- /* istanbul ignore else */
311
- if (cache.status === helpers_1.STATUS.LOADING) {
312
- cache.queue.push(_this.handleCacheQueue);
313
- }
314
- else if (cache.status === helpers_1.STATUS.LOADED) {
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) {
315
334
  _this.handleLoad(cache.content);
335
+ return;
316
336
  }
317
- return;
318
- }
319
- var dataURI = src.match(/data:image\/svg[^,]*?(;base64)?,(.*)/);
320
- var inlineSrc;
321
- if (dataURI) {
322
- inlineSrc = dataURI[1] ? atob(dataURI[2]) : decodeURIComponent(dataURI[2]);
323
- }
324
- else if (src.indexOf('<svg') >= 0) {
325
- inlineSrc = src;
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
+ });
351
+ }
352
+ }
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
+ });
326
385
  }
327
- if (inlineSrc) {
328
- _this.handleLoad(inlineSrc);
329
- return;
386
+ if (d.children.length) {
387
+ return _this.updateSVGAttributes(d);
330
388
  }
331
- _this.request();
389
+ return d;
332
390
  });
391
+ return node;
333
392
  }
334
- };
335
- InlineSVG.prototype.render = function () {
336
- var _a = this.state, element = _a.element, status = _a.status;
337
- 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;
338
- var elementProps = helpers_1.removeProperties(this.props, 'baseURL', 'cacheRequests', 'children', 'description', 'innerRef', 'loader', 'onError', 'onLoad', 'preProcessor', 'src', 'title', 'uniqueHash', 'uniquifyIDs');
339
- if (!helpers_1.canUseDOM()) {
340
- return loader;
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);
403
+ }
404
+ return content;
341
405
  }
342
- if (element) {
343
- return React.cloneElement(element, __assign({ ref: innerRef }, elementProps));
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
+ }
424
+ return loader;
344
425
  }
345
- if ([helpers_1.STATUS.UNSUPPORTED, helpers_1.STATUS.FAILED].indexOf(status) > -1) {
346
- return children;
426
+ });
427
+ Object.defineProperty(InlineSVG, "defaultProps", {
428
+ enumerable: true,
429
+ configurable: true,
430
+ writable: true,
431
+ value: {
432
+ cacheRequests: true,
433
+ uniquifyIDs: false,
347
434
  }
348
- return loader;
349
- };
350
- InlineSVG.defaultProps = {
351
- cacheRequests: true,
352
- uniquifyIDs: false,
353
- };
435
+ });
354
436
  return InlineSVG;
355
437
  }(React.PureComponent));
356
438
  exports.default = InlineSVG;