react-svg 14.1.19 → 15.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.
@@ -1,857 +1,825 @@
1
1
  (function (global, factory) {
2
- typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('prop-types'), require('react')) :
3
- typeof define === 'function' && define.amd ? define(['exports', 'prop-types', 'react'], factory) :
4
- (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.ReactSVG = {}, global.PropTypes, global.React));
2
+ typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('prop-types'), require('react')) :
3
+ typeof define === 'function' && define.amd ? define(['exports', 'prop-types', 'react'], factory) :
4
+ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.ReactSVG = {}, global.PropTypes, global.React));
5
5
  })(this, (function (exports, PropTypes, React) { 'use strict';
6
6
 
7
- function _interopNamespace(e) {
8
- if (e && e.__esModule) return e;
9
- var n = Object.create(null);
10
- if (e) {
11
- Object.keys(e).forEach(function (k) {
12
- if (k !== 'default') {
13
- var d = Object.getOwnPropertyDescriptor(e, k);
14
- Object.defineProperty(n, k, d.get ? d : {
15
- enumerable: true,
16
- get: function () { return e[k]; }
17
- });
18
- }
19
- });
20
- }
21
- n["default"] = e;
22
- return Object.freeze(n);
23
- }
24
-
25
- var PropTypes__namespace = /*#__PURE__*/_interopNamespace(PropTypes);
26
- var React__namespace = /*#__PURE__*/_interopNamespace(React);
27
-
28
- function unwrapExports (x) {
29
- return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
30
- }
31
-
32
- function createCommonjsModule(fn, module) {
33
- return module = { exports: {} }, fn(module, module.exports), module.exports;
34
- }
35
-
36
- var _extends_1 = createCommonjsModule(function (module) {
37
- function _extends() {
38
- module.exports = _extends = Object.assign || function (target) {
39
- for (var i = 1; i < arguments.length; i++) {
40
- var source = arguments[i];
41
-
42
- for (var key in source) {
43
- if (Object.prototype.hasOwnProperty.call(source, key)) {
44
- target[key] = source[key];
45
- }
46
- }
47
- }
48
-
49
- return target;
50
- }, module.exports.__esModule = true, module.exports["default"] = module.exports;
51
- return _extends.apply(this, arguments);
52
- }
53
-
54
- module.exports = _extends, module.exports.__esModule = true, module.exports["default"] = module.exports;
55
- });
56
-
57
- var _extends = unwrapExports(_extends_1);
58
-
59
- var objectWithoutPropertiesLoose = createCommonjsModule(function (module) {
60
- function _objectWithoutPropertiesLoose(source, excluded) {
61
- if (source == null) return {};
62
- var target = {};
63
- var sourceKeys = Object.keys(source);
64
- var key, i;
65
-
66
- for (i = 0; i < sourceKeys.length; i++) {
67
- key = sourceKeys[i];
68
- if (excluded.indexOf(key) >= 0) continue;
69
- target[key] = source[key];
70
- }
71
-
72
- return target;
73
- }
74
-
75
- module.exports = _objectWithoutPropertiesLoose, module.exports.__esModule = true, module.exports["default"] = module.exports;
76
- });
77
-
78
- var _objectWithoutPropertiesLoose = unwrapExports(objectWithoutPropertiesLoose);
79
-
80
- var setPrototypeOf = createCommonjsModule(function (module) {
81
- function _setPrototypeOf(o, p) {
82
- module.exports = _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) {
83
- o.__proto__ = p;
84
- return o;
85
- }, module.exports.__esModule = true, module.exports["default"] = module.exports;
86
- return _setPrototypeOf(o, p);
87
- }
88
-
89
- module.exports = _setPrototypeOf, module.exports.__esModule = true, module.exports["default"] = module.exports;
90
- });
91
-
92
- unwrapExports(setPrototypeOf);
93
-
94
- var inheritsLoose = createCommonjsModule(function (module) {
95
- function _inheritsLoose(subClass, superClass) {
96
- subClass.prototype = Object.create(superClass.prototype);
97
- subClass.prototype.constructor = subClass;
98
- setPrototypeOf(subClass, superClass);
99
- }
100
-
101
- module.exports = _inheritsLoose, module.exports.__esModule = true, module.exports["default"] = module.exports;
102
- });
103
-
104
- var _inheritsLoose = unwrapExports(inheritsLoose);
105
-
106
- /*! *****************************************************************************
107
- Copyright (c) Microsoft Corporation.
7
+ function _interopNamespace(e) {
8
+ if (e && e.__esModule) return e;
9
+ var n = Object.create(null);
10
+ if (e) {
11
+ Object.keys(e).forEach(function (k) {
12
+ if (k !== 'default') {
13
+ var d = Object.getOwnPropertyDescriptor(e, k);
14
+ Object.defineProperty(n, k, d.get ? d : {
15
+ enumerable: true,
16
+ get: function () { return e[k]; }
17
+ });
18
+ }
19
+ });
20
+ }
21
+ n["default"] = e;
22
+ return Object.freeze(n);
23
+ }
24
+
25
+ var PropTypes__namespace = /*#__PURE__*/_interopNamespace(PropTypes);
26
+ var React__namespace = /*#__PURE__*/_interopNamespace(React);
27
+
28
+ function _extends() {
29
+ _extends = Object.assign ? Object.assign.bind() : function (target) {
30
+ for (var i = 1; i < arguments.length; i++) {
31
+ var source = arguments[i];
32
+
33
+ for (var key in source) {
34
+ if (Object.prototype.hasOwnProperty.call(source, key)) {
35
+ target[key] = source[key];
36
+ }
37
+ }
38
+ }
39
+
40
+ return target;
41
+ };
42
+ return _extends.apply(this, arguments);
43
+ }
44
+
45
+ function _objectWithoutPropertiesLoose(source, excluded) {
46
+ if (source == null) return {};
47
+ var target = {};
48
+ var sourceKeys = Object.keys(source);
49
+ var key, i;
50
+
51
+ for (i = 0; i < sourceKeys.length; i++) {
52
+ key = sourceKeys[i];
53
+ if (excluded.indexOf(key) >= 0) continue;
54
+ target[key] = source[key];
55
+ }
56
+
57
+ return target;
58
+ }
59
+
60
+ function _setPrototypeOf(o, p) {
61
+ _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) {
62
+ o.__proto__ = p;
63
+ return o;
64
+ };
65
+ return _setPrototypeOf(o, p);
66
+ }
67
+
68
+ function _inheritsLoose(subClass, superClass) {
69
+ subClass.prototype = Object.create(superClass.prototype);
70
+ subClass.prototype.constructor = subClass;
71
+ _setPrototypeOf(subClass, superClass);
72
+ }
73
+
74
+ /******************************************************************************
75
+ Copyright (c) Microsoft Corporation.
108
76
 
109
- Permission to use, copy, modify, and/or distribute this software for any
110
- purpose with or without fee is hereby granted.
77
+ Permission to use, copy, modify, and/or distribute this software for any
78
+ purpose with or without fee is hereby granted.
111
79
 
112
- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
113
- REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
114
- AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
115
- INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
116
- LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
117
- OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
118
- PERFORMANCE OF THIS SOFTWARE.
119
- ***************************************************************************** */
80
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
81
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
82
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
83
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
84
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
85
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
86
+ PERFORMANCE OF THIS SOFTWARE.
87
+ ***************************************************************************** */
120
88
 
121
- function __spreadArray(to, from, pack) {
122
- if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
123
- if (ar || !(i in from)) {
124
- if (!ar) ar = Array.prototype.slice.call(from, 0, i);
125
- ar[i] = from[i];
126
- }
127
- }
128
- return to.concat(ar || Array.prototype.slice.call(from));
129
- }
130
-
131
- /*!
132
- * content-type
133
- * Copyright(c) 2015 Douglas Christopher Wilson
134
- * MIT Licensed
135
- */
136
-
137
- /**
138
- * RegExp to match *( ";" parameter ) in RFC 7231 sec 3.1.1.1
139
- *
140
- * parameter = token "=" ( token / quoted-string )
141
- * token = 1*tchar
142
- * tchar = "!" / "#" / "$" / "%" / "&" / "'" / "*"
143
- * / "+" / "-" / "." / "^" / "_" / "`" / "|" / "~"
144
- * / DIGIT / ALPHA
145
- * ; any VCHAR, except delimiters
146
- * quoted-string = DQUOTE *( qdtext / quoted-pair ) DQUOTE
147
- * qdtext = HTAB / SP / %x21 / %x23-5B / %x5D-7E / obs-text
148
- * obs-text = %x80-FF
149
- * quoted-pair = "\" ( HTAB / SP / VCHAR / obs-text )
150
- */
151
- var PARAM_REGEXP = /; *([!#$%&'*+.^_`|~0-9A-Za-z-]+) *= *("(?:[\u000b\u0020\u0021\u0023-\u005b\u005d-\u007e\u0080-\u00ff]|\\[\u000b\u0020-\u00ff])*"|[!#$%&'*+.^_`|~0-9A-Za-z-]+) */g;
152
-
153
- /**
154
- * RegExp to match quoted-pair in RFC 7230 sec 3.2.6
155
- *
156
- * quoted-pair = "\" ( HTAB / SP / VCHAR / obs-text )
157
- * obs-text = %x80-FF
158
- */
159
- var QESC_REGEXP = /\\([\u000b\u0020-\u00ff])/g;
160
-
161
- /**
162
- * RegExp to match type in RFC 7231 sec 3.1.1.1
163
- *
164
- * media-type = type "/" subtype
165
- * type = token
166
- * subtype = token
167
- */
168
- var TYPE_REGEXP = /^[!#$%&'*+.^_`|~0-9A-Za-z-]+\/[!#$%&'*+.^_`|~0-9A-Za-z-]+$/;
169
- var parse_1 = parse;
170
-
171
- /**
172
- * Parse media type to object.
173
- *
174
- * @param {string|object} string
175
- * @return {Object}
176
- * @public
177
- */
178
-
179
- function parse (string) {
180
- if (!string) {
181
- throw new TypeError('argument string is required')
182
- }
183
-
184
- // support req/res-like objects as argument
185
- var header = typeof string === 'object'
186
- ? getcontenttype(string)
187
- : string;
188
-
189
- if (typeof header !== 'string') {
190
- throw new TypeError('argument string is required to be a string')
191
- }
192
-
193
- var index = header.indexOf(';');
194
- var type = index !== -1
195
- ? header.substr(0, index).trim()
196
- : header.trim();
197
-
198
- if (!TYPE_REGEXP.test(type)) {
199
- throw new TypeError('invalid media type')
200
- }
201
-
202
- var obj = new ContentType(type.toLowerCase());
203
-
204
- // parse parameters
205
- if (index !== -1) {
206
- var key;
207
- var match;
208
- var value;
209
-
210
- PARAM_REGEXP.lastIndex = index;
211
-
212
- while ((match = PARAM_REGEXP.exec(header))) {
213
- if (match.index !== index) {
214
- throw new TypeError('invalid parameter format')
215
- }
216
-
217
- index += match[0].length;
218
- key = match[1].toLowerCase();
219
- value = match[2];
220
-
221
- if (value[0] === '"') {
222
- // remove quotes and escapes
223
- value = value
224
- .substr(1, value.length - 2)
225
- .replace(QESC_REGEXP, '$1');
226
- }
227
-
228
- obj.parameters[key] = value;
229
- }
230
-
231
- if (index !== header.length) {
232
- throw new TypeError('invalid parameter format')
233
- }
234
- }
235
-
236
- return obj
237
- }
238
-
239
- /**
240
- * Get content-type from req/res objects.
241
- *
242
- * @param {object}
243
- * @return {Object}
244
- * @private
245
- */
246
-
247
- function getcontenttype (obj) {
248
- var header;
249
-
250
- if (typeof obj.getHeader === 'function') {
251
- // res-like
252
- header = obj.getHeader('content-type');
253
- } else if (typeof obj.headers === 'object') {
254
- // req-like
255
- header = obj.headers && obj.headers['content-type'];
256
- }
257
-
258
- if (typeof header !== 'string') {
259
- throw new TypeError('content-type header is missing from object')
260
- }
261
-
262
- return header
263
- }
264
-
265
- /**
266
- * Class to represent a content type.
267
- * @private
268
- */
269
- function ContentType (type) {
270
- this.parameters = Object.create(null);
271
- this.type = type;
272
- }
273
-
274
- var cache = new Map();
275
-
276
- var cloneSvg = function cloneSvg(sourceSvg) {
277
- return sourceSvg.cloneNode(true);
278
- };
279
-
280
- var isLocal = function isLocal() {
281
- return window.location.protocol === 'file:';
282
- };
283
-
284
- var makeAjaxRequest = function makeAjaxRequest(url, httpRequestWithCredentials, callback) {
285
- var httpRequest = new XMLHttpRequest();
286
-
287
- httpRequest.onreadystatechange = function () {
288
- try {
289
- if (!/\.svg/i.test(url) && httpRequest.readyState === 2) {
290
- var contentType = httpRequest.getResponseHeader('Content-Type');
291
-
292
- if (!contentType) {
293
- throw new Error('Content type not found');
294
- }
295
-
296
- var type = parse_1(contentType).type;
297
-
298
- if (!(type === 'image/svg+xml' || type === 'text/plain')) {
299
- throw new Error("Invalid content type: ".concat(type));
300
- }
301
- }
302
-
303
- if (httpRequest.readyState === 4) {
304
- if (httpRequest.status === 404 || httpRequest.responseXML === null) {
305
- throw new Error(isLocal() ? 'Note: SVG injection ajax calls do not work locally without ' + 'adjusting security settings in your browser. Or consider ' + 'using a local webserver.' : 'Unable to load SVG file: ' + url);
306
- }
307
-
308
- if (httpRequest.status === 200 || isLocal() && httpRequest.status === 0) {
309
- callback(null, httpRequest);
310
- } else {
311
- throw new Error('There was a problem injecting the SVG: ' + httpRequest.status + ' ' + httpRequest.statusText);
312
- }
313
- }
314
- } catch (error) {
315
- httpRequest.abort();
316
-
317
- if (error instanceof Error) {
318
- callback(error, httpRequest);
319
- } else {
320
- throw error;
321
- }
322
- }
323
- };
324
-
325
- httpRequest.open('GET', url);
326
- httpRequest.withCredentials = httpRequestWithCredentials;
327
-
328
- if (httpRequest.overrideMimeType) {
329
- httpRequest.overrideMimeType('text/xml');
330
- }
331
-
332
- httpRequest.send();
333
- };
334
-
335
- var requestQueue = {};
336
- var queueRequest = function queueRequest(url, callback) {
337
- requestQueue[url] = requestQueue[url] || [];
338
- requestQueue[url].push(callback);
339
- };
340
- var processRequestQueue = function processRequestQueue(url) {
341
- var _loop_1 = function _loop_1(i, len) {
342
- setTimeout(function () {
343
- if (Array.isArray(requestQueue[url])) {
344
- var cacheValue = cache.get(url);
345
- var callback = requestQueue[url][i];
346
-
347
- if (cacheValue instanceof SVGSVGElement) {
348
- callback(null, cloneSvg(cacheValue));
349
- }
350
-
351
- if (cacheValue instanceof Error) {
352
- callback(cacheValue);
353
- }
354
-
355
- if (i === requestQueue[url].length - 1) {
356
- delete requestQueue[url];
357
- }
358
- }
359
- }, 0);
360
- };
361
-
362
- for (var i = 0, len = requestQueue[url].length; i < len; i++) {
363
- _loop_1(i);
364
- }
365
- };
366
-
367
- var loadSvgCached = function loadSvgCached(url, httpRequestWithCredentials, callback) {
368
- if (cache.has(url)) {
369
- var cacheValue = cache.get(url);
370
-
371
- if (cacheValue === undefined) {
372
- queueRequest(url, callback);
373
- return;
374
- }
375
-
376
- if (cacheValue instanceof SVGSVGElement) {
377
- callback(null, cloneSvg(cacheValue));
378
- return;
379
- }
380
- }
381
-
382
- cache.set(url, undefined);
383
- queueRequest(url, callback);
384
- makeAjaxRequest(url, httpRequestWithCredentials, function (error, httpRequest) {
385
- if (error) {
386
- cache.set(url, error);
387
- } else if (httpRequest.responseXML instanceof Document && httpRequest.responseXML.documentElement && httpRequest.responseXML.documentElement instanceof SVGSVGElement) {
388
- cache.set(url, httpRequest.responseXML.documentElement);
389
- }
390
-
391
- processRequestQueue(url);
392
- });
393
- };
394
-
395
- var loadSvgUncached = function loadSvgUncached(url, httpRequestWithCredentials, callback) {
396
- makeAjaxRequest(url, httpRequestWithCredentials, function (error, httpRequest) {
397
- if (error) {
398
- callback(error);
399
- } else if (httpRequest.responseXML instanceof Document && httpRequest.responseXML.documentElement && httpRequest.responseXML.documentElement instanceof SVGSVGElement) {
400
- callback(null, httpRequest.responseXML.documentElement);
401
- }
402
- });
403
- };
404
-
405
- var idCounter = 0;
406
-
407
- var uniqueId = function uniqueId() {
408
- return ++idCounter;
409
- };
410
-
411
- var injectedElements = [];
412
- var ranScripts = {};
413
- var svgNamespace$1 = 'http://www.w3.org/2000/svg';
414
- var xlinkNamespace$1 = 'http://www.w3.org/1999/xlink';
415
-
416
- var injectElement = function injectElement(el, evalScripts, renumerateIRIElements, cacheRequests, httpRequestWithCredentials, beforeEach, callback) {
417
- var elUrl = el.getAttribute('data-src') || el.getAttribute('src');
418
-
419
- if (!elUrl) {
420
- callback(new Error('Invalid data-src or src attribute'));
421
- return;
422
- }
423
-
424
- if (injectedElements.indexOf(el) !== -1) {
425
- injectedElements.splice(injectedElements.indexOf(el), 1);
426
- el = null;
427
- return;
428
- }
429
-
430
- injectedElements.push(el);
431
- el.setAttribute('src', '');
432
- var loadSvg = cacheRequests ? loadSvgCached : loadSvgUncached;
433
- loadSvg(elUrl, httpRequestWithCredentials, function (error, svg) {
434
- if (!svg) {
435
- injectedElements.splice(injectedElements.indexOf(el), 1);
436
- el = null;
437
- callback(error);
438
- return;
439
- }
440
-
441
- var elId = el.getAttribute('id');
442
-
443
- if (elId) {
444
- svg.setAttribute('id', elId);
445
- }
446
-
447
- var elTitle = el.getAttribute('title');
448
-
449
- if (elTitle) {
450
- svg.setAttribute('title', elTitle);
451
- }
452
-
453
- var elWidth = el.getAttribute('width');
454
-
455
- if (elWidth) {
456
- svg.setAttribute('width', elWidth);
457
- }
458
-
459
- var elHeight = el.getAttribute('height');
460
-
461
- if (elHeight) {
462
- svg.setAttribute('height', elHeight);
463
- }
464
-
465
- var mergedClasses = Array.from(new Set(__spreadArray(__spreadArray(__spreadArray([], (svg.getAttribute('class') || '').split(' '), true), ['injected-svg'], false), (el.getAttribute('class') || '').split(' '), true))).join(' ').trim();
466
- svg.setAttribute('class', mergedClasses);
467
- var elStyle = el.getAttribute('style');
468
-
469
- if (elStyle) {
470
- svg.setAttribute('style', elStyle);
471
- }
472
-
473
- svg.setAttribute('data-src', elUrl);
474
- var elData = [].filter.call(el.attributes, function (at) {
475
- return /^data-\w[\w-]*$/.test(at.name);
476
- });
477
- Array.prototype.forEach.call(elData, function (dataAttr) {
478
- if (dataAttr.name && dataAttr.value) {
479
- svg.setAttribute(dataAttr.name, dataAttr.value);
480
- }
481
- });
482
-
483
- if (renumerateIRIElements) {
484
- var iriElementsAndProperties_1 = {
485
- clipPath: ['clip-path'],
486
- 'color-profile': ['color-profile'],
487
- cursor: ['cursor'],
488
- filter: ['filter'],
489
- linearGradient: ['fill', 'stroke'],
490
- marker: ['marker', 'marker-start', 'marker-mid', 'marker-end'],
491
- mask: ['mask'],
492
- path: [],
493
- pattern: ['fill', 'stroke'],
494
- radialGradient: ['fill', 'stroke']
495
- };
496
- var element_1;
497
- var elements_1;
498
- var properties_1;
499
- var currentId_1;
500
- var newId_1;
501
- Object.keys(iriElementsAndProperties_1).forEach(function (key) {
502
- element_1 = key;
503
- properties_1 = iriElementsAndProperties_1[key];
504
- elements_1 = svg.querySelectorAll(element_1 + '[id]');
505
-
506
- var _loop_1 = function _loop_1(a, elementsLen) {
507
- currentId_1 = elements_1[a].id;
508
- newId_1 = currentId_1 + '-' + uniqueId();
509
- var referencingElements;
510
- Array.prototype.forEach.call(properties_1, function (property) {
511
- referencingElements = svg.querySelectorAll('[' + property + '*="' + currentId_1 + '"]');
512
-
513
- for (var b = 0, referencingElementLen = referencingElements.length; b < referencingElementLen; b++) {
514
- var attrValue = referencingElements[b].getAttribute(property);
515
-
516
- if (attrValue && !attrValue.match(new RegExp('url\\("?#' + currentId_1 + '"?\\)'))) {
517
- continue;
518
- }
519
-
520
- referencingElements[b].setAttribute(property, 'url(#' + newId_1 + ')');
521
- }
522
- });
523
- var allLinks = svg.querySelectorAll('[*|href]');
524
- var links = [];
525
-
526
- for (var c = 0, allLinksLen = allLinks.length; c < allLinksLen; c++) {
527
- var href = allLinks[c].getAttributeNS(xlinkNamespace$1, 'href');
528
-
529
- if (href && href.toString() === '#' + elements_1[a].id) {
530
- links.push(allLinks[c]);
531
- }
532
- }
533
-
534
- for (var d = 0, linksLen = links.length; d < linksLen; d++) {
535
- links[d].setAttributeNS(xlinkNamespace$1, 'href', '#' + newId_1);
536
- }
537
-
538
- elements_1[a].id = newId_1;
539
- };
540
-
541
- for (var a = 0, elementsLen = elements_1.length; a < elementsLen; a++) {
542
- _loop_1(a);
543
- }
544
- });
545
- }
546
-
547
- svg.removeAttribute('xmlns:a');
548
- var scripts = svg.querySelectorAll('script');
549
- var scriptsToEval = [];
550
- var script;
551
- var scriptType;
552
-
553
- for (var i = 0, scriptsLen = scripts.length; i < scriptsLen; i++) {
554
- scriptType = scripts[i].getAttribute('type');
555
-
556
- if (!scriptType || scriptType === 'application/ecmascript' || scriptType === 'application/javascript' || scriptType === 'text/javascript') {
557
- script = scripts[i].innerText || scripts[i].textContent;
558
-
559
- if (script) {
560
- scriptsToEval.push(script);
561
- }
562
-
563
- svg.removeChild(scripts[i]);
564
- }
565
- }
566
-
567
- if (scriptsToEval.length > 0 && (evalScripts === 'always' || evalScripts === 'once' && !ranScripts[elUrl])) {
568
- for (var l = 0, scriptsToEvalLen = scriptsToEval.length; l < scriptsToEvalLen; l++) {
569
- new Function(scriptsToEval[l])(window);
570
- }
571
-
572
- ranScripts[elUrl] = true;
573
- }
574
-
575
- var styleTags = svg.querySelectorAll('style');
576
- Array.prototype.forEach.call(styleTags, function (styleTag) {
577
- styleTag.textContent += '';
578
- });
579
- svg.setAttribute('xmlns', svgNamespace$1);
580
- svg.setAttribute('xmlns:xlink', xlinkNamespace$1);
581
- beforeEach(svg);
582
-
583
- if (!el.parentNode) {
584
- injectedElements.splice(injectedElements.indexOf(el), 1);
585
- el = null;
586
- callback(new Error('Parent node is null'));
587
- return;
588
- }
589
-
590
- el.parentNode.replaceChild(svg, el);
591
- injectedElements.splice(injectedElements.indexOf(el), 1);
592
- el = null;
593
- callback(null, svg);
594
- });
595
- };
596
-
597
- var SVGInjector = function SVGInjector(elements, _a) {
598
- var _b = _a === void 0 ? {} : _a,
599
- _c = _b.afterAll,
600
- afterAll = _c === void 0 ? function () {
601
- return undefined;
602
- } : _c,
603
- _d = _b.afterEach,
604
- afterEach = _d === void 0 ? function () {
605
- return undefined;
606
- } : _d,
607
- _e = _b.beforeEach,
608
- beforeEach = _e === void 0 ? function () {
609
- return undefined;
610
- } : _e,
611
- _f = _b.cacheRequests,
612
- cacheRequests = _f === void 0 ? true : _f,
613
- _g = _b.evalScripts,
614
- evalScripts = _g === void 0 ? 'never' : _g,
615
- _h = _b.httpRequestWithCredentials,
616
- httpRequestWithCredentials = _h === void 0 ? false : _h,
617
- _j = _b.renumerateIRIElements,
618
- renumerateIRIElements = _j === void 0 ? true : _j;
619
-
620
- if (elements && 'length' in elements) {
621
- var elementsLoaded_1 = 0;
622
-
623
- for (var i = 0, j = elements.length; i < j; i++) {
624
- injectElement(elements[i], evalScripts, renumerateIRIElements, cacheRequests, httpRequestWithCredentials, beforeEach, function (error, svg) {
625
- afterEach(error, svg);
626
-
627
- if (elements && 'length' in elements && elements.length === ++elementsLoaded_1) {
628
- afterAll(elementsLoaded_1);
629
- }
630
- });
631
- }
632
- } else if (elements) {
633
- injectElement(elements, evalScripts, renumerateIRIElements, cacheRequests, httpRequestWithCredentials, beforeEach, function (error, svg) {
634
- afterEach(error, svg);
635
- afterAll(1);
636
- elements = null;
637
- });
638
- } else {
639
- afterAll(0);
640
- }
641
- };
642
-
643
- // Hat-tip: https://github.com/developit/preact-compat/blob/master/src/index.js#L402.
644
- var shallowDiffers = function shallowDiffers(a, b) {
645
- for (var i in a) {
646
- if (!(i in b)) {
647
- return true;
648
- }
649
- }
650
-
651
- for (var _i in b) {
652
- if (a[_i] !== b[_i]) {
653
- return true;
654
- }
655
- }
656
-
657
- return false;
658
- };
659
-
660
- var _excluded = ["afterInjection", "beforeInjection", "evalScripts", "fallback", "httpRequestWithCredentials", "loading", "renumerateIRIElements", "src", "useRequestCache", "wrapper"];
661
- var svgNamespace = 'http://www.w3.org/2000/svg';
662
- var xlinkNamespace = 'http://www.w3.org/1999/xlink';
663
- var ReactSVG = /*#__PURE__*/function (_React$Component) {
664
- _inheritsLoose(ReactSVG, _React$Component);
665
-
666
- function ReactSVG() {
667
- var _this;
668
-
669
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
670
- args[_key] = arguments[_key];
671
- }
672
-
673
- _this = _React$Component.call.apply(_React$Component, [this].concat(args)) || this;
674
- _this.initialState = {
675
- hasError: false,
676
- isLoading: true
677
- };
678
- _this.state = _this.initialState;
679
- _this._isMounted = false;
680
- _this.reactWrapper = void 0;
681
- _this.nonReactWrapper = void 0;
682
-
683
- _this.refCallback = function (reactWrapper) {
684
- _this.reactWrapper = reactWrapper;
685
- };
686
-
687
- return _this;
688
- }
689
-
690
- var _proto = ReactSVG.prototype;
691
-
692
- _proto.renderSVG = function renderSVG() {
693
- var _this2 = this;
694
-
695
- /* istanbul ignore else */
696
- if (this.reactWrapper instanceof Node) {
697
- var _this$props = this.props,
698
- beforeInjection = _this$props.beforeInjection,
699
- evalScripts = _this$props.evalScripts,
700
- httpRequestWithCredentials = _this$props.httpRequestWithCredentials,
701
- renumerateIRIElements = _this$props.renumerateIRIElements,
702
- src = _this$props.src,
703
- useRequestCache = _this$props.useRequestCache;
704
- /* eslint-disable @typescript-eslint/no-non-null-assertion */
705
-
706
- var afterInjection = this.props.afterInjection;
707
- var wrapper = this.props.wrapper;
708
- /* eslint-enable @typescript-eslint/no-non-null-assertion */
709
-
710
- var nonReactWrapper;
711
- var nonReactTarget;
712
-
713
- if (wrapper === 'svg') {
714
- nonReactWrapper = document.createElementNS(svgNamespace, wrapper);
715
- nonReactWrapper.setAttribute('xmlns', svgNamespace);
716
- nonReactWrapper.setAttribute('xmlns:xlink', xlinkNamespace);
717
- nonReactTarget = document.createElementNS(svgNamespace, wrapper);
718
- } else {
719
- nonReactWrapper = document.createElement(wrapper);
720
- nonReactTarget = document.createElement(wrapper);
721
- }
722
-
723
- nonReactWrapper.appendChild(nonReactTarget);
724
- nonReactTarget.dataset.src = src;
725
- this.nonReactWrapper = this.reactWrapper.appendChild(nonReactWrapper);
726
-
727
- var afterEach = function afterEach(error, svg) {
728
- if (error) {
729
- _this2.removeSVG();
730
-
731
- if (!_this2._isMounted) {
732
- afterInjection(error);
733
- return;
734
- }
735
- } // TODO (Tane): It'd be better to cleanly unsubscribe from SVGInjector
736
- // callbacks instead of tracking a property like this.
737
-
738
-
739
- if (_this2._isMounted) {
740
- _this2.setState(function () {
741
- return {
742
- hasError: !!error,
743
- isLoading: false
744
- };
745
- }, function () {
746
- afterInjection(error, svg);
747
- });
748
- }
749
- };
750
-
751
- SVGInjector(nonReactTarget, {
752
- afterEach: afterEach,
753
- beforeEach: beforeInjection,
754
- cacheRequests: useRequestCache,
755
- evalScripts: evalScripts,
756
- httpRequestWithCredentials: httpRequestWithCredentials,
757
- renumerateIRIElements: renumerateIRIElements
758
- });
759
- }
760
- };
761
-
762
- _proto.removeSVG = function removeSVG() {
763
- var _this$nonReactWrapper;
764
-
765
- if ((_this$nonReactWrapper = this.nonReactWrapper) != null && _this$nonReactWrapper.parentNode) {
766
- this.nonReactWrapper.parentNode.removeChild(this.nonReactWrapper);
767
- this.nonReactWrapper = null;
768
- }
769
- };
770
-
771
- _proto.componentDidMount = function componentDidMount() {
772
- this._isMounted = true;
773
- this.renderSVG();
774
- };
775
-
776
- _proto.componentDidUpdate = function componentDidUpdate(prevProps) {
777
- var _this3 = this;
778
-
779
- if (shallowDiffers(prevProps, this.props)) {
780
- this.setState(function () {
781
- return _this3.initialState;
782
- }, function () {
783
- _this3.removeSVG();
784
-
785
- _this3.renderSVG();
786
- });
787
- }
788
- };
789
-
790
- _proto.componentWillUnmount = function componentWillUnmount() {
791
- this._isMounted = false;
792
- this.removeSVG();
793
- };
794
-
795
- _proto.render = function render() {
796
- /* eslint-disable @typescript-eslint/no-unused-vars */
797
- var _this$props2 = this.props;
798
- _this$props2.afterInjection;
799
- _this$props2.beforeInjection;
800
- _this$props2.evalScripts;
801
- var Fallback = _this$props2.fallback;
802
- _this$props2.httpRequestWithCredentials;
803
- var Loading = _this$props2.loading;
804
- _this$props2.renumerateIRIElements;
805
- _this$props2.src;
806
- _this$props2.useRequestCache;
807
- var wrapper = _this$props2.wrapper,
808
- rest = _objectWithoutPropertiesLoose(_this$props2, _excluded);
809
- /* eslint-enable @typescript-eslint/no-unused-vars */
810
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
811
-
812
-
813
- var Wrapper = wrapper;
814
- return /*#__PURE__*/React__namespace.createElement(Wrapper, _extends({}, rest, {
815
- ref: this.refCallback
816
- }, wrapper === 'svg' ? {
817
- xmlns: svgNamespace,
818
- xmlnsXlink: xlinkNamespace
819
- } : {}), this.state.isLoading && Loading && /*#__PURE__*/React__namespace.createElement(Loading, null), this.state.hasError && Fallback && /*#__PURE__*/React__namespace.createElement(Fallback, null));
820
- };
821
-
822
- return ReactSVG;
823
- }(React__namespace.Component);
824
- ReactSVG.defaultProps = {
825
- afterInjection: function afterInjection() {
826
- return undefined;
827
- },
828
- beforeInjection: function beforeInjection() {
829
- return undefined;
830
- },
831
- evalScripts: 'never',
832
- fallback: null,
833
- httpRequestWithCredentials: false,
834
- loading: null,
835
- renumerateIRIElements: true,
836
- useRequestCache: true,
837
- wrapper: 'div'
838
- };
839
- ReactSVG.propTypes = {
840
- afterInjection: PropTypes__namespace.func,
841
- beforeInjection: PropTypes__namespace.func,
842
- evalScripts: PropTypes__namespace.oneOf(['always', 'once', 'never']),
843
- fallback: PropTypes__namespace.oneOfType([PropTypes__namespace.func, PropTypes__namespace.object, PropTypes__namespace.string]),
844
- httpRequestWithCredentials: PropTypes__namespace.bool,
845
- loading: PropTypes__namespace.oneOfType([PropTypes__namespace.func, PropTypes__namespace.object, PropTypes__namespace.string]),
846
- renumerateIRIElements: PropTypes__namespace.bool,
847
- src: PropTypes__namespace.string.isRequired,
848
- useRequestCache: PropTypes__namespace.bool,
849
- wrapper: PropTypes__namespace.oneOf(['div', 'span', 'svg'])
850
- };
851
-
852
- exports.ReactSVG = ReactSVG;
853
-
854
- Object.defineProperty(exports, '__esModule', { value: true });
89
+ function __spreadArray(to, from, pack) {
90
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
91
+ if (ar || !(i in from)) {
92
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
93
+ ar[i] = from[i];
94
+ }
95
+ }
96
+ return to.concat(ar || Array.prototype.slice.call(from));
97
+ }
98
+
99
+ /*!
100
+ * content-type
101
+ * Copyright(c) 2015 Douglas Christopher Wilson
102
+ * MIT Licensed
103
+ */
104
+
105
+ /**
106
+ * RegExp to match *( ";" parameter ) in RFC 7231 sec 3.1.1.1
107
+ *
108
+ * parameter = token "=" ( token / quoted-string )
109
+ * token = 1*tchar
110
+ * tchar = "!" / "#" / "$" / "%" / "&" / "'" / "*"
111
+ * / "+" / "-" / "." / "^" / "_" / "`" / "|" / "~"
112
+ * / DIGIT / ALPHA
113
+ * ; any VCHAR, except delimiters
114
+ * quoted-string = DQUOTE *( qdtext / quoted-pair ) DQUOTE
115
+ * qdtext = HTAB / SP / %x21 / %x23-5B / %x5D-7E / obs-text
116
+ * obs-text = %x80-FF
117
+ * quoted-pair = "\" ( HTAB / SP / VCHAR / obs-text )
118
+ */
119
+ var PARAM_REGEXP = /; *([!#$%&'*+.^_`|~0-9A-Za-z-]+) *= *("(?:[\u000b\u0020\u0021\u0023-\u005b\u005d-\u007e\u0080-\u00ff]|\\[\u000b\u0020-\u00ff])*"|[!#$%&'*+.^_`|~0-9A-Za-z-]+) */g;
120
+
121
+ /**
122
+ * RegExp to match quoted-pair in RFC 7230 sec 3.2.6
123
+ *
124
+ * quoted-pair = "\" ( HTAB / SP / VCHAR / obs-text )
125
+ * obs-text = %x80-FF
126
+ */
127
+ var QESC_REGEXP = /\\([\u000b\u0020-\u00ff])/g;
128
+
129
+ /**
130
+ * RegExp to match type in RFC 7231 sec 3.1.1.1
131
+ *
132
+ * media-type = type "/" subtype
133
+ * type = token
134
+ * subtype = token
135
+ */
136
+ var TYPE_REGEXP = /^[!#$%&'*+.^_`|~0-9A-Za-z-]+\/[!#$%&'*+.^_`|~0-9A-Za-z-]+$/;
137
+ var parse_1 = parse;
138
+
139
+ /**
140
+ * Parse media type to object.
141
+ *
142
+ * @param {string|object} string
143
+ * @return {Object}
144
+ * @public
145
+ */
146
+
147
+ function parse (string) {
148
+ if (!string) {
149
+ throw new TypeError('argument string is required')
150
+ }
151
+
152
+ // support req/res-like objects as argument
153
+ var header = typeof string === 'object'
154
+ ? getcontenttype(string)
155
+ : string;
156
+
157
+ if (typeof header !== 'string') {
158
+ throw new TypeError('argument string is required to be a string')
159
+ }
160
+
161
+ var index = header.indexOf(';');
162
+ var type = index !== -1
163
+ ? header.substr(0, index).trim()
164
+ : header.trim();
165
+
166
+ if (!TYPE_REGEXP.test(type)) {
167
+ throw new TypeError('invalid media type')
168
+ }
169
+
170
+ var obj = new ContentType(type.toLowerCase());
171
+
172
+ // parse parameters
173
+ if (index !== -1) {
174
+ var key;
175
+ var match;
176
+ var value;
177
+
178
+ PARAM_REGEXP.lastIndex = index;
179
+
180
+ while ((match = PARAM_REGEXP.exec(header))) {
181
+ if (match.index !== index) {
182
+ throw new TypeError('invalid parameter format')
183
+ }
184
+
185
+ index += match[0].length;
186
+ key = match[1].toLowerCase();
187
+ value = match[2];
188
+
189
+ if (value[0] === '"') {
190
+ // remove quotes and escapes
191
+ value = value
192
+ .substr(1, value.length - 2)
193
+ .replace(QESC_REGEXP, '$1');
194
+ }
195
+
196
+ obj.parameters[key] = value;
197
+ }
198
+
199
+ if (index !== header.length) {
200
+ throw new TypeError('invalid parameter format')
201
+ }
202
+ }
203
+
204
+ return obj
205
+ }
206
+
207
+ /**
208
+ * Get content-type from req/res objects.
209
+ *
210
+ * @param {object}
211
+ * @return {Object}
212
+ * @private
213
+ */
214
+
215
+ function getcontenttype (obj) {
216
+ var header;
217
+
218
+ if (typeof obj.getHeader === 'function') {
219
+ // res-like
220
+ header = obj.getHeader('content-type');
221
+ } else if (typeof obj.headers === 'object') {
222
+ // req-like
223
+ header = obj.headers && obj.headers['content-type'];
224
+ }
225
+
226
+ if (typeof header !== 'string') {
227
+ throw new TypeError('content-type header is missing from object')
228
+ }
229
+
230
+ return header
231
+ }
232
+
233
+ /**
234
+ * Class to represent a content type.
235
+ * @private
236
+ */
237
+ function ContentType (type) {
238
+ this.parameters = Object.create(null);
239
+ this.type = type;
240
+ }
241
+
242
+ var cache = new Map();
243
+
244
+ var cloneSvg = function cloneSvg(sourceSvg) {
245
+ return sourceSvg.cloneNode(true);
246
+ };
247
+
248
+ var isLocal = function isLocal() {
249
+ return window.location.protocol === 'file:';
250
+ };
251
+
252
+ var makeAjaxRequest = function makeAjaxRequest(url, httpRequestWithCredentials, callback) {
253
+ var httpRequest = new XMLHttpRequest();
254
+
255
+ httpRequest.onreadystatechange = function () {
256
+ try {
257
+ if (!/\.svg/i.test(url) && httpRequest.readyState === 2) {
258
+ var contentType = httpRequest.getResponseHeader('Content-Type');
259
+
260
+ if (!contentType) {
261
+ throw new Error('Content type not found');
262
+ }
263
+
264
+ var type = parse_1(contentType).type;
265
+
266
+ if (!(type === 'image/svg+xml' || type === 'text/plain')) {
267
+ throw new Error("Invalid content type: ".concat(type));
268
+ }
269
+ }
270
+
271
+ if (httpRequest.readyState === 4) {
272
+ if (httpRequest.status === 404 || httpRequest.responseXML === null) {
273
+ throw new Error(isLocal() ? 'Note: SVG injection ajax calls do not work locally without ' + 'adjusting security settings in your browser. Or consider ' + 'using a local webserver.' : 'Unable to load SVG file: ' + url);
274
+ }
275
+
276
+ if (httpRequest.status === 200 || isLocal() && httpRequest.status === 0) {
277
+ callback(null, httpRequest);
278
+ } else {
279
+ throw new Error('There was a problem injecting the SVG: ' + httpRequest.status + ' ' + httpRequest.statusText);
280
+ }
281
+ }
282
+ } catch (error) {
283
+ httpRequest.abort();
284
+
285
+ if (error instanceof Error) {
286
+ callback(error, httpRequest);
287
+ } else {
288
+ throw error;
289
+ }
290
+ }
291
+ };
292
+
293
+ httpRequest.open('GET', url);
294
+ httpRequest.withCredentials = httpRequestWithCredentials;
295
+
296
+ if (httpRequest.overrideMimeType) {
297
+ httpRequest.overrideMimeType('text/xml');
298
+ }
299
+
300
+ httpRequest.send();
301
+ };
302
+
303
+ var requestQueue = {};
304
+ var queueRequest = function queueRequest(url, callback) {
305
+ requestQueue[url] = requestQueue[url] || [];
306
+ requestQueue[url].push(callback);
307
+ };
308
+ var processRequestQueue = function processRequestQueue(url) {
309
+ var _loop_1 = function _loop_1(i, len) {
310
+ setTimeout(function () {
311
+ if (Array.isArray(requestQueue[url])) {
312
+ var cacheValue = cache.get(url);
313
+ var callback = requestQueue[url][i];
314
+
315
+ if (cacheValue instanceof SVGSVGElement) {
316
+ callback(null, cloneSvg(cacheValue));
317
+ }
318
+
319
+ if (cacheValue instanceof Error) {
320
+ callback(cacheValue);
321
+ }
322
+
323
+ if (i === requestQueue[url].length - 1) {
324
+ delete requestQueue[url];
325
+ }
326
+ }
327
+ }, 0);
328
+ };
329
+
330
+ for (var i = 0, len = requestQueue[url].length; i < len; i++) {
331
+ _loop_1(i);
332
+ }
333
+ };
334
+
335
+ var loadSvgCached = function loadSvgCached(url, httpRequestWithCredentials, callback) {
336
+ if (cache.has(url)) {
337
+ var cacheValue = cache.get(url);
338
+
339
+ if (cacheValue === undefined) {
340
+ queueRequest(url, callback);
341
+ return;
342
+ }
343
+
344
+ if (cacheValue instanceof SVGSVGElement) {
345
+ callback(null, cloneSvg(cacheValue));
346
+ return;
347
+ }
348
+ }
349
+
350
+ cache.set(url, undefined);
351
+ queueRequest(url, callback);
352
+ makeAjaxRequest(url, httpRequestWithCredentials, function (error, httpRequest) {
353
+ if (error) {
354
+ cache.set(url, error);
355
+ } else if (httpRequest.responseXML instanceof Document && httpRequest.responseXML.documentElement && httpRequest.responseXML.documentElement instanceof SVGSVGElement) {
356
+ cache.set(url, httpRequest.responseXML.documentElement);
357
+ }
358
+
359
+ processRequestQueue(url);
360
+ });
361
+ };
362
+
363
+ var loadSvgUncached = function loadSvgUncached(url, httpRequestWithCredentials, callback) {
364
+ makeAjaxRequest(url, httpRequestWithCredentials, function (error, httpRequest) {
365
+ if (error) {
366
+ callback(error);
367
+ } else if (httpRequest.responseXML instanceof Document && httpRequest.responseXML.documentElement && httpRequest.responseXML.documentElement instanceof SVGSVGElement) {
368
+ callback(null, httpRequest.responseXML.documentElement);
369
+ }
370
+ });
371
+ };
372
+
373
+ var idCounter = 0;
374
+
375
+ var uniqueId = function uniqueId() {
376
+ return ++idCounter;
377
+ };
378
+
379
+ var injectedElements = [];
380
+ var ranScripts = {};
381
+ var svgNamespace$1 = 'http://www.w3.org/2000/svg';
382
+ var xlinkNamespace$1 = 'http://www.w3.org/1999/xlink';
383
+
384
+ var injectElement = function injectElement(el, evalScripts, renumerateIRIElements, cacheRequests, httpRequestWithCredentials, beforeEach, callback) {
385
+ var elUrl = el.getAttribute('data-src') || el.getAttribute('src');
386
+
387
+ if (!elUrl) {
388
+ callback(new Error('Invalid data-src or src attribute'));
389
+ return;
390
+ }
391
+
392
+ if (injectedElements.indexOf(el) !== -1) {
393
+ injectedElements.splice(injectedElements.indexOf(el), 1);
394
+ el = null;
395
+ return;
396
+ }
397
+
398
+ injectedElements.push(el);
399
+ el.setAttribute('src', '');
400
+ var loadSvg = cacheRequests ? loadSvgCached : loadSvgUncached;
401
+ loadSvg(elUrl, httpRequestWithCredentials, function (error, svg) {
402
+ if (!svg) {
403
+ injectedElements.splice(injectedElements.indexOf(el), 1);
404
+ el = null;
405
+ callback(error);
406
+ return;
407
+ }
408
+
409
+ var elId = el.getAttribute('id');
410
+
411
+ if (elId) {
412
+ svg.setAttribute('id', elId);
413
+ }
414
+
415
+ var elTitle = el.getAttribute('title');
416
+
417
+ if (elTitle) {
418
+ svg.setAttribute('title', elTitle);
419
+ }
420
+
421
+ var elWidth = el.getAttribute('width');
422
+
423
+ if (elWidth) {
424
+ svg.setAttribute('width', elWidth);
425
+ }
426
+
427
+ var elHeight = el.getAttribute('height');
428
+
429
+ if (elHeight) {
430
+ svg.setAttribute('height', elHeight);
431
+ }
432
+
433
+ var mergedClasses = Array.from(new Set(__spreadArray(__spreadArray(__spreadArray([], (svg.getAttribute('class') || '').split(' '), true), ['injected-svg'], false), (el.getAttribute('class') || '').split(' '), true))).join(' ').trim();
434
+ svg.setAttribute('class', mergedClasses);
435
+ var elStyle = el.getAttribute('style');
436
+
437
+ if (elStyle) {
438
+ svg.setAttribute('style', elStyle);
439
+ }
440
+
441
+ svg.setAttribute('data-src', elUrl);
442
+ var elData = [].filter.call(el.attributes, function (at) {
443
+ return /^data-\w[\w-]*$/.test(at.name);
444
+ });
445
+ Array.prototype.forEach.call(elData, function (dataAttr) {
446
+ if (dataAttr.name && dataAttr.value) {
447
+ svg.setAttribute(dataAttr.name, dataAttr.value);
448
+ }
449
+ });
450
+
451
+ if (renumerateIRIElements) {
452
+ var iriElementsAndProperties_1 = {
453
+ clipPath: ['clip-path'],
454
+ 'color-profile': ['color-profile'],
455
+ cursor: ['cursor'],
456
+ filter: ['filter'],
457
+ linearGradient: ['fill', 'stroke'],
458
+ marker: ['marker', 'marker-start', 'marker-mid', 'marker-end'],
459
+ mask: ['mask'],
460
+ path: [],
461
+ pattern: ['fill', 'stroke'],
462
+ radialGradient: ['fill', 'stroke']
463
+ };
464
+ var element_1;
465
+ var elements_1;
466
+ var properties_1;
467
+ var currentId_1;
468
+ var newId_1;
469
+ Object.keys(iriElementsAndProperties_1).forEach(function (key) {
470
+ element_1 = key;
471
+ properties_1 = iriElementsAndProperties_1[key];
472
+ elements_1 = svg.querySelectorAll(element_1 + '[id]');
473
+
474
+ var _loop_1 = function _loop_1(a, elementsLen) {
475
+ currentId_1 = elements_1[a].id;
476
+ newId_1 = currentId_1 + '-' + uniqueId();
477
+ var referencingElements;
478
+ Array.prototype.forEach.call(properties_1, function (property) {
479
+ referencingElements = svg.querySelectorAll('[' + property + '*="' + currentId_1 + '"]');
480
+
481
+ for (var b = 0, referencingElementLen = referencingElements.length; b < referencingElementLen; b++) {
482
+ var attrValue = referencingElements[b].getAttribute(property);
483
+
484
+ if (attrValue && !attrValue.match(new RegExp('url\\("?#' + currentId_1 + '"?\\)'))) {
485
+ continue;
486
+ }
487
+
488
+ referencingElements[b].setAttribute(property, 'url(#' + newId_1 + ')');
489
+ }
490
+ });
491
+ var allLinks = svg.querySelectorAll('[*|href]');
492
+ var links = [];
493
+
494
+ for (var c = 0, allLinksLen = allLinks.length; c < allLinksLen; c++) {
495
+ var href = allLinks[c].getAttributeNS(xlinkNamespace$1, 'href');
496
+
497
+ if (href && href.toString() === '#' + elements_1[a].id) {
498
+ links.push(allLinks[c]);
499
+ }
500
+ }
501
+
502
+ for (var d = 0, linksLen = links.length; d < linksLen; d++) {
503
+ links[d].setAttributeNS(xlinkNamespace$1, 'href', '#' + newId_1);
504
+ }
505
+
506
+ elements_1[a].id = newId_1;
507
+ };
508
+
509
+ for (var a = 0, elementsLen = elements_1.length; a < elementsLen; a++) {
510
+ _loop_1(a);
511
+ }
512
+ });
513
+ }
514
+
515
+ svg.removeAttribute('xmlns:a');
516
+ var scripts = svg.querySelectorAll('script');
517
+ var scriptsToEval = [];
518
+ var script;
519
+ var scriptType;
520
+
521
+ for (var i = 0, scriptsLen = scripts.length; i < scriptsLen; i++) {
522
+ scriptType = scripts[i].getAttribute('type');
523
+
524
+ if (!scriptType || scriptType === 'application/ecmascript' || scriptType === 'application/javascript' || scriptType === 'text/javascript') {
525
+ script = scripts[i].innerText || scripts[i].textContent;
526
+
527
+ if (script) {
528
+ scriptsToEval.push(script);
529
+ }
530
+
531
+ svg.removeChild(scripts[i]);
532
+ }
533
+ }
534
+
535
+ if (scriptsToEval.length > 0 && (evalScripts === 'always' || evalScripts === 'once' && !ranScripts[elUrl])) {
536
+ for (var l = 0, scriptsToEvalLen = scriptsToEval.length; l < scriptsToEvalLen; l++) {
537
+ new Function(scriptsToEval[l])(window);
538
+ }
539
+
540
+ ranScripts[elUrl] = true;
541
+ }
542
+
543
+ var styleTags = svg.querySelectorAll('style');
544
+ Array.prototype.forEach.call(styleTags, function (styleTag) {
545
+ styleTag.textContent += '';
546
+ });
547
+ svg.setAttribute('xmlns', svgNamespace$1);
548
+ svg.setAttribute('xmlns:xlink', xlinkNamespace$1);
549
+ beforeEach(svg);
550
+
551
+ if (!el.parentNode) {
552
+ injectedElements.splice(injectedElements.indexOf(el), 1);
553
+ el = null;
554
+ callback(new Error('Parent node is null'));
555
+ return;
556
+ }
557
+
558
+ el.parentNode.replaceChild(svg, el);
559
+ injectedElements.splice(injectedElements.indexOf(el), 1);
560
+ el = null;
561
+ callback(null, svg);
562
+ });
563
+ };
564
+
565
+ var SVGInjector = function SVGInjector(elements, _a) {
566
+ var _b = _a === void 0 ? {} : _a,
567
+ _c = _b.afterAll,
568
+ afterAll = _c === void 0 ? function () {
569
+ return undefined;
570
+ } : _c,
571
+ _d = _b.afterEach,
572
+ afterEach = _d === void 0 ? function () {
573
+ return undefined;
574
+ } : _d,
575
+ _e = _b.beforeEach,
576
+ beforeEach = _e === void 0 ? function () {
577
+ return undefined;
578
+ } : _e,
579
+ _f = _b.cacheRequests,
580
+ cacheRequests = _f === void 0 ? true : _f,
581
+ _g = _b.evalScripts,
582
+ evalScripts = _g === void 0 ? 'never' : _g,
583
+ _h = _b.httpRequestWithCredentials,
584
+ httpRequestWithCredentials = _h === void 0 ? false : _h,
585
+ _j = _b.renumerateIRIElements,
586
+ renumerateIRIElements = _j === void 0 ? true : _j;
587
+
588
+ if (elements && 'length' in elements) {
589
+ var elementsLoaded_1 = 0;
590
+
591
+ for (var i = 0, j = elements.length; i < j; i++) {
592
+ injectElement(elements[i], evalScripts, renumerateIRIElements, cacheRequests, httpRequestWithCredentials, beforeEach, function (error, svg) {
593
+ afterEach(error, svg);
594
+
595
+ if (elements && 'length' in elements && elements.length === ++elementsLoaded_1) {
596
+ afterAll(elementsLoaded_1);
597
+ }
598
+ });
599
+ }
600
+ } else if (elements) {
601
+ injectElement(elements, evalScripts, renumerateIRIElements, cacheRequests, httpRequestWithCredentials, beforeEach, function (error, svg) {
602
+ afterEach(error, svg);
603
+ afterAll(1);
604
+ elements = null;
605
+ });
606
+ } else {
607
+ afterAll(0);
608
+ }
609
+ };
610
+
611
+ // Hat-tip: https://github.com/developit/preact-compat/blob/master/src/index.js#L402.
612
+ var shallowDiffers = function shallowDiffers(a, b) {
613
+ for (var i in a) {
614
+ if (!(i in b)) {
615
+ return true;
616
+ }
617
+ }
618
+
619
+ for (var _i in b) {
620
+ if (a[_i] !== b[_i]) {
621
+ return true;
622
+ }
623
+ }
624
+
625
+ return false;
626
+ };
627
+
628
+ var _excluded = ["afterInjection", "beforeInjection", "evalScripts", "fallback", "httpRequestWithCredentials", "loading", "renumerateIRIElements", "src", "useRequestCache", "wrapper"];
629
+ var svgNamespace = 'http://www.w3.org/2000/svg';
630
+ var xlinkNamespace = 'http://www.w3.org/1999/xlink';
631
+ var ReactSVG = /*#__PURE__*/function (_React$Component) {
632
+ _inheritsLoose(ReactSVG, _React$Component);
633
+
634
+ function ReactSVG() {
635
+ var _this;
636
+
637
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
638
+ args[_key] = arguments[_key];
639
+ }
640
+
641
+ _this = _React$Component.call.apply(_React$Component, [this].concat(args)) || this;
642
+ _this.initialState = {
643
+ hasError: false,
644
+ isLoading: true
645
+ };
646
+ _this.state = _this.initialState;
647
+ _this._isMounted = false;
648
+ _this.reactWrapper = void 0;
649
+ _this.nonReactWrapper = void 0;
650
+
651
+ _this.refCallback = function (reactWrapper) {
652
+ _this.reactWrapper = reactWrapper;
653
+ };
654
+
655
+ return _this;
656
+ }
657
+
658
+ var _proto = ReactSVG.prototype;
659
+
660
+ _proto.renderSVG = function renderSVG() {
661
+ var _this2 = this;
662
+
663
+ /* istanbul ignore else */
664
+ if (this.reactWrapper instanceof Node) {
665
+ var _this$props = this.props,
666
+ beforeInjection = _this$props.beforeInjection,
667
+ evalScripts = _this$props.evalScripts,
668
+ httpRequestWithCredentials = _this$props.httpRequestWithCredentials,
669
+ renumerateIRIElements = _this$props.renumerateIRIElements,
670
+ src = _this$props.src,
671
+ useRequestCache = _this$props.useRequestCache;
672
+ /* eslint-disable @typescript-eslint/no-non-null-assertion */
673
+
674
+ var afterInjection = this.props.afterInjection;
675
+ var wrapper = this.props.wrapper;
676
+ /* eslint-enable @typescript-eslint/no-non-null-assertion */
677
+
678
+ var nonReactWrapper;
679
+ var nonReactTarget;
680
+
681
+ if (wrapper === 'svg') {
682
+ nonReactWrapper = document.createElementNS(svgNamespace, wrapper);
683
+ nonReactWrapper.setAttribute('xmlns', svgNamespace);
684
+ nonReactWrapper.setAttribute('xmlns:xlink', xlinkNamespace);
685
+ nonReactTarget = document.createElementNS(svgNamespace, wrapper);
686
+ } else {
687
+ nonReactWrapper = document.createElement(wrapper);
688
+ nonReactTarget = document.createElement(wrapper);
689
+ }
690
+
691
+ nonReactWrapper.appendChild(nonReactTarget);
692
+ nonReactTarget.dataset.src = src;
693
+ this.nonReactWrapper = this.reactWrapper.appendChild(nonReactWrapper);
694
+
695
+ var afterEach = function afterEach(error, svg) {
696
+ if (error) {
697
+ _this2.removeSVG();
698
+
699
+ if (!_this2._isMounted) {
700
+ afterInjection(error);
701
+ return;
702
+ }
703
+ } // TODO (Tane): It'd be better to cleanly unsubscribe from SVGInjector
704
+ // callbacks instead of tracking a property like this.
705
+
706
+
707
+ if (_this2._isMounted) {
708
+ _this2.setState(function () {
709
+ return {
710
+ hasError: !!error,
711
+ isLoading: false
712
+ };
713
+ }, function () {
714
+ afterInjection(error, svg);
715
+ });
716
+ }
717
+ };
718
+
719
+ SVGInjector(nonReactTarget, {
720
+ afterEach: afterEach,
721
+ beforeEach: beforeInjection,
722
+ cacheRequests: useRequestCache,
723
+ evalScripts: evalScripts,
724
+ httpRequestWithCredentials: httpRequestWithCredentials,
725
+ renumerateIRIElements: renumerateIRIElements
726
+ });
727
+ }
728
+ };
729
+
730
+ _proto.removeSVG = function removeSVG() {
731
+ var _this$nonReactWrapper;
732
+
733
+ if ((_this$nonReactWrapper = this.nonReactWrapper) != null && _this$nonReactWrapper.parentNode) {
734
+ this.nonReactWrapper.parentNode.removeChild(this.nonReactWrapper);
735
+ this.nonReactWrapper = null;
736
+ }
737
+ };
738
+
739
+ _proto.componentDidMount = function componentDidMount() {
740
+ this._isMounted = true;
741
+ this.renderSVG();
742
+ };
743
+
744
+ _proto.componentDidUpdate = function componentDidUpdate(prevProps) {
745
+ var _this3 = this;
746
+
747
+ if (shallowDiffers(prevProps, this.props)) {
748
+ this.setState(function () {
749
+ return _this3.initialState;
750
+ }, function () {
751
+ _this3.removeSVG();
752
+
753
+ _this3.renderSVG();
754
+ });
755
+ }
756
+ };
757
+
758
+ _proto.componentWillUnmount = function componentWillUnmount() {
759
+ this._isMounted = false;
760
+ this.removeSVG();
761
+ };
762
+
763
+ _proto.render = function render() {
764
+ /* eslint-disable @typescript-eslint/no-unused-vars */
765
+ var _this$props2 = this.props;
766
+ _this$props2.afterInjection;
767
+ _this$props2.beforeInjection;
768
+ _this$props2.evalScripts;
769
+ var Fallback = _this$props2.fallback;
770
+ _this$props2.httpRequestWithCredentials;
771
+ var Loading = _this$props2.loading;
772
+ _this$props2.renumerateIRIElements;
773
+ _this$props2.src;
774
+ _this$props2.useRequestCache;
775
+ var wrapper = _this$props2.wrapper,
776
+ rest = _objectWithoutPropertiesLoose(_this$props2, _excluded);
777
+ /* eslint-enable @typescript-eslint/no-unused-vars */
778
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
779
+
780
+
781
+ var Wrapper = wrapper;
782
+ return /*#__PURE__*/React__namespace.createElement(Wrapper, _extends({}, rest, {
783
+ ref: this.refCallback
784
+ }, wrapper === 'svg' ? {
785
+ xmlns: svgNamespace,
786
+ xmlnsXlink: xlinkNamespace
787
+ } : {}), this.state.isLoading && Loading && /*#__PURE__*/React__namespace.createElement(Loading, null), this.state.hasError && Fallback && /*#__PURE__*/React__namespace.createElement(Fallback, null));
788
+ };
789
+
790
+ return ReactSVG;
791
+ }(React__namespace.Component);
792
+ ReactSVG.defaultProps = {
793
+ afterInjection: function afterInjection() {
794
+ return undefined;
795
+ },
796
+ beforeInjection: function beforeInjection() {
797
+ return undefined;
798
+ },
799
+ evalScripts: 'never',
800
+ fallback: null,
801
+ httpRequestWithCredentials: false,
802
+ loading: null,
803
+ renumerateIRIElements: true,
804
+ useRequestCache: true,
805
+ wrapper: 'div'
806
+ };
807
+ ReactSVG.propTypes = {
808
+ afterInjection: PropTypes__namespace.func,
809
+ beforeInjection: PropTypes__namespace.func,
810
+ evalScripts: PropTypes__namespace.oneOf(['always', 'once', 'never']),
811
+ fallback: PropTypes__namespace.oneOfType([PropTypes__namespace.func, PropTypes__namespace.object, PropTypes__namespace.string]),
812
+ httpRequestWithCredentials: PropTypes__namespace.bool,
813
+ loading: PropTypes__namespace.oneOfType([PropTypes__namespace.func, PropTypes__namespace.object, PropTypes__namespace.string]),
814
+ renumerateIRIElements: PropTypes__namespace.bool,
815
+ src: PropTypes__namespace.string.isRequired,
816
+ useRequestCache: PropTypes__namespace.bool,
817
+ wrapper: PropTypes__namespace.oneOf(['div', 'span', 'svg'])
818
+ };
819
+
820
+ exports.ReactSVG = ReactSVG;
821
+
822
+ Object.defineProperty(exports, '__esModule', { value: true });
855
823
 
856
824
  }));
857
825
  //# sourceMappingURL=react-svg.umd.development.js.map