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/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.
|
|
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
|
|
53
|
-
for (var
|
|
54
|
-
|
|
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
|
-
|
|
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
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
};
|
|
83
|
-
_this
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
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
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
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
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
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
|
-
|
|
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 (
|
|
121
|
-
cache
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
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
|
-
|
|
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 (
|
|
137
|
-
cache
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
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
|
-
|
|
146
|
-
|
|
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
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
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 (
|
|
174
|
-
|
|
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
|
-
|
|
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
|
-
|
|
196
|
-
|
|
197
|
-
|
|
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.
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
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
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
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
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
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
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
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
|
-
|
|
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
|
-
|
|
264
|
-
descElement.innerHTML = description;
|
|
265
|
-
svg.prepend(descElement);
|
|
290
|
+
return svg;
|
|
266
291
|
}
|
|
267
|
-
|
|
268
|
-
|
|
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
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
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
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
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
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
inlineSrc
|
|
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 (
|
|
328
|
-
_this.
|
|
329
|
-
return;
|
|
386
|
+
if (d.children.length) {
|
|
387
|
+
return _this.updateSVGAttributes(d);
|
|
330
388
|
}
|
|
331
|
-
|
|
389
|
+
return d;
|
|
332
390
|
});
|
|
391
|
+
return node;
|
|
333
392
|
}
|
|
334
|
-
};
|
|
335
|
-
InlineSVG.prototype
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
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
|
-
|
|
343
|
-
|
|
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
|
-
|
|
346
|
-
|
|
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
|
-
|
|
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;
|