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