react-inlinesvg 4.0.1 → 4.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.
- package/dist/index.d.mts +0 -1
- package/dist/index.d.ts +0 -1
- package/dist/index.js +457 -1265
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +9 -5
- package/dist/index.mjs.map +1 -1
- package/dist/provider.d.mts +2 -6
- package/dist/provider.d.ts +2 -6
- package/dist/provider.js +25 -53
- package/dist/provider.js.map +1 -1
- package/dist/provider.mjs +9 -8
- package/dist/provider.mjs.map +1 -1
- package/package.json +4 -5
- package/src/cache.ts +11 -7
- package/src/global.d.ts +6 -0
- package/src/provider.tsx +8 -16
package/dist/index.js
CHANGED
|
@@ -1,1320 +1,512 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
function _array_like_to_array(arr, len) {
|
|
3
|
-
if (len == null || len > arr.length) len = arr.length;
|
|
4
|
-
for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
|
|
5
|
-
return arr2;
|
|
6
|
-
}
|
|
7
|
-
function _array_with_holes(arr) {
|
|
8
|
-
if (Array.isArray(arr)) return arr;
|
|
9
|
-
}
|
|
10
|
-
function _array_without_holes(arr) {
|
|
11
|
-
if (Array.isArray(arr)) return _array_like_to_array(arr);
|
|
12
|
-
}
|
|
13
|
-
function _assert_this_initialized(self) {
|
|
14
|
-
if (self === void 0) {
|
|
15
|
-
throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
|
|
16
|
-
}
|
|
17
|
-
return self;
|
|
18
|
-
}
|
|
19
|
-
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
|
|
20
|
-
try {
|
|
21
|
-
var info = gen[key](arg);
|
|
22
|
-
var value = info.value;
|
|
23
|
-
} catch (error) {
|
|
24
|
-
reject(error);
|
|
25
|
-
return;
|
|
26
|
-
}
|
|
27
|
-
if (info.done) {
|
|
28
|
-
resolve(value);
|
|
29
|
-
} else {
|
|
30
|
-
Promise.resolve(value).then(_next, _throw);
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
function _async_to_generator(fn) {
|
|
34
|
-
return function() {
|
|
35
|
-
var self = this, args = arguments;
|
|
36
|
-
return new Promise(function(resolve, reject) {
|
|
37
|
-
var gen = fn.apply(self, args);
|
|
38
|
-
function _next(value) {
|
|
39
|
-
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
|
|
40
|
-
}
|
|
41
|
-
function _throw(err) {
|
|
42
|
-
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
|
|
43
|
-
}
|
|
44
|
-
_next(undefined);
|
|
45
|
-
});
|
|
46
|
-
};
|
|
47
|
-
}
|
|
48
|
-
function _class_call_check(instance, Constructor) {
|
|
49
|
-
if (!(instance instanceof Constructor)) {
|
|
50
|
-
throw new TypeError("Cannot call a class as a function");
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
function _defineProperties(target, props) {
|
|
54
|
-
for(var i = 0; i < props.length; i++){
|
|
55
|
-
var descriptor = props[i];
|
|
56
|
-
descriptor.enumerable = descriptor.enumerable || false;
|
|
57
|
-
descriptor.configurable = true;
|
|
58
|
-
if ("value" in descriptor) descriptor.writable = true;
|
|
59
|
-
Object.defineProperty(target, descriptor.key, descriptor);
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
function _create_class(Constructor, protoProps, staticProps) {
|
|
63
|
-
if (protoProps) _defineProperties(Constructor.prototype, protoProps);
|
|
64
|
-
if (staticProps) _defineProperties(Constructor, staticProps);
|
|
65
|
-
return Constructor;
|
|
66
|
-
}
|
|
67
|
-
function _define_property(obj, key, value) {
|
|
68
|
-
if (key in obj) {
|
|
69
|
-
Object.defineProperty(obj, key, {
|
|
70
|
-
value: value,
|
|
71
|
-
enumerable: true,
|
|
72
|
-
configurable: true,
|
|
73
|
-
writable: true
|
|
74
|
-
});
|
|
75
|
-
} else {
|
|
76
|
-
obj[key] = value;
|
|
77
|
-
}
|
|
78
|
-
return obj;
|
|
79
|
-
}
|
|
80
|
-
function _get_prototype_of(o) {
|
|
81
|
-
_get_prototype_of = Object.setPrototypeOf ? Object.getPrototypeOf : function getPrototypeOf(o) {
|
|
82
|
-
return o.__proto__ || Object.getPrototypeOf(o);
|
|
83
|
-
};
|
|
84
|
-
return _get_prototype_of(o);
|
|
85
|
-
}
|
|
86
|
-
function _inherits(subClass, superClass) {
|
|
87
|
-
if (typeof superClass !== "function" && superClass !== null) {
|
|
88
|
-
throw new TypeError("Super expression must either be null or a function");
|
|
89
|
-
}
|
|
90
|
-
subClass.prototype = Object.create(superClass && superClass.prototype, {
|
|
91
|
-
constructor: {
|
|
92
|
-
value: subClass,
|
|
93
|
-
writable: true,
|
|
94
|
-
configurable: true
|
|
95
|
-
}
|
|
96
|
-
});
|
|
97
|
-
if (superClass) _set_prototype_of(subClass, superClass);
|
|
98
|
-
}
|
|
99
|
-
function _instanceof(left, right) {
|
|
100
|
-
if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
|
|
101
|
-
return !!right[Symbol.hasInstance](left);
|
|
102
|
-
} else {
|
|
103
|
-
return left instanceof right;
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
function _iterable_to_array(iter) {
|
|
107
|
-
if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
|
|
108
|
-
}
|
|
109
|
-
function _iterable_to_array_limit(arr, i) {
|
|
110
|
-
var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
|
|
111
|
-
if (_i == null) return;
|
|
112
|
-
var _arr = [];
|
|
113
|
-
var _n = true;
|
|
114
|
-
var _d = false;
|
|
115
|
-
var _s, _e;
|
|
116
|
-
try {
|
|
117
|
-
for(_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true){
|
|
118
|
-
_arr.push(_s.value);
|
|
119
|
-
if (i && _arr.length === i) break;
|
|
120
|
-
}
|
|
121
|
-
} catch (err) {
|
|
122
|
-
_d = true;
|
|
123
|
-
_e = err;
|
|
124
|
-
} finally{
|
|
125
|
-
try {
|
|
126
|
-
if (!_n && _i["return"] != null) _i["return"]();
|
|
127
|
-
} finally{
|
|
128
|
-
if (_d) throw _e;
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
return _arr;
|
|
132
|
-
}
|
|
133
|
-
function _non_iterable_rest() {
|
|
134
|
-
throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
135
|
-
}
|
|
136
|
-
function _non_iterable_spread() {
|
|
137
|
-
throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
138
|
-
}
|
|
139
|
-
function _object_spread(target) {
|
|
140
|
-
for(var i = 1; i < arguments.length; i++){
|
|
141
|
-
var source = arguments[i] != null ? arguments[i] : {};
|
|
142
|
-
var ownKeys = Object.keys(source);
|
|
143
|
-
if (typeof Object.getOwnPropertySymbols === "function") {
|
|
144
|
-
ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
|
|
145
|
-
return Object.getOwnPropertyDescriptor(source, sym).enumerable;
|
|
146
|
-
}));
|
|
147
|
-
}
|
|
148
|
-
ownKeys.forEach(function(key) {
|
|
149
|
-
_define_property(target, key, source[key]);
|
|
150
|
-
});
|
|
151
|
-
}
|
|
152
|
-
return target;
|
|
153
|
-
}
|
|
154
|
-
function _possible_constructor_return(self, call) {
|
|
155
|
-
if (call && (_type_of(call) === "object" || typeof call === "function")) {
|
|
156
|
-
return call;
|
|
157
|
-
}
|
|
158
|
-
return _assert_this_initialized(self);
|
|
159
|
-
}
|
|
160
|
-
function _set_prototype_of(o, p) {
|
|
161
|
-
_set_prototype_of = Object.setPrototypeOf || function setPrototypeOf(o, p) {
|
|
162
|
-
o.__proto__ = p;
|
|
163
|
-
return o;
|
|
164
|
-
};
|
|
165
|
-
return _set_prototype_of(o, p);
|
|
166
|
-
}
|
|
167
|
-
function _sliced_to_array(arr, i) {
|
|
168
|
-
return _array_with_holes(arr) || _iterable_to_array_limit(arr, i) || _unsupported_iterable_to_array(arr, i) || _non_iterable_rest();
|
|
169
|
-
}
|
|
170
|
-
function _to_consumable_array(arr) {
|
|
171
|
-
return _array_without_holes(arr) || _iterable_to_array(arr) || _unsupported_iterable_to_array(arr) || _non_iterable_spread();
|
|
172
|
-
}
|
|
173
|
-
function _type_of(obj) {
|
|
174
|
-
"@swc/helpers - typeof";
|
|
175
|
-
return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
|
|
176
|
-
}
|
|
177
|
-
function _unsupported_iterable_to_array(o, minLen) {
|
|
178
|
-
if (!o) return;
|
|
179
|
-
if (typeof o === "string") return _array_like_to_array(o, minLen);
|
|
180
|
-
var n = Object.prototype.toString.call(o).slice(8, -1);
|
|
181
|
-
if (n === "Object" && o.constructor) n = o.constructor.name;
|
|
182
|
-
if (n === "Map" || n === "Set") return Array.from(n);
|
|
183
|
-
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
|
|
184
|
-
}
|
|
185
|
-
function _is_native_reflect_construct() {
|
|
186
|
-
if (typeof Reflect === "undefined" || !Reflect.construct) return false;
|
|
187
|
-
if (Reflect.construct.sham) return false;
|
|
188
|
-
if (typeof Proxy === "function") return true;
|
|
189
|
-
try {
|
|
190
|
-
Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() {}));
|
|
191
|
-
return true;
|
|
192
|
-
} catch (e) {
|
|
193
|
-
return false;
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
function _create_super(Derived) {
|
|
197
|
-
var hasNativeReflectConstruct = _is_native_reflect_construct();
|
|
198
|
-
return function _createSuperInternal() {
|
|
199
|
-
var Super = _get_prototype_of(Derived), result;
|
|
200
|
-
if (hasNativeReflectConstruct) {
|
|
201
|
-
var NewTarget = _get_prototype_of(this).constructor;
|
|
202
|
-
result = Reflect.construct(Super, arguments, NewTarget);
|
|
203
|
-
} else {
|
|
204
|
-
result = Super.apply(this, arguments);
|
|
205
|
-
}
|
|
206
|
-
return _possible_constructor_return(this, result);
|
|
207
|
-
};
|
|
208
|
-
}
|
|
209
|
-
function _ts_generator(thisArg, body) {
|
|
210
|
-
var f, y, t, g, _ = {
|
|
211
|
-
label: 0,
|
|
212
|
-
sent: function() {
|
|
213
|
-
if (t[0] & 1) throw t[1];
|
|
214
|
-
return t[1];
|
|
215
|
-
},
|
|
216
|
-
trys: [],
|
|
217
|
-
ops: []
|
|
218
|
-
};
|
|
219
|
-
return g = {
|
|
220
|
-
next: verb(0),
|
|
221
|
-
"throw": verb(1),
|
|
222
|
-
"return": verb(2)
|
|
223
|
-
}, typeof Symbol === "function" && (g[Symbol.iterator] = function() {
|
|
224
|
-
return this;
|
|
225
|
-
}), g;
|
|
226
|
-
function verb(n) {
|
|
227
|
-
return function(v) {
|
|
228
|
-
return step([
|
|
229
|
-
n,
|
|
230
|
-
v
|
|
231
|
-
]);
|
|
232
|
-
};
|
|
233
|
-
}
|
|
234
|
-
function step(op) {
|
|
235
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
236
|
-
while(_)try {
|
|
237
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
238
|
-
if (y = 0, t) op = [
|
|
239
|
-
op[0] & 2,
|
|
240
|
-
t.value
|
|
241
|
-
];
|
|
242
|
-
switch(op[0]){
|
|
243
|
-
case 0:
|
|
244
|
-
case 1:
|
|
245
|
-
t = op;
|
|
246
|
-
break;
|
|
247
|
-
case 4:
|
|
248
|
-
_.label++;
|
|
249
|
-
return {
|
|
250
|
-
value: op[1],
|
|
251
|
-
done: false
|
|
252
|
-
};
|
|
253
|
-
case 5:
|
|
254
|
-
_.label++;
|
|
255
|
-
y = op[1];
|
|
256
|
-
op = [
|
|
257
|
-
0
|
|
258
|
-
];
|
|
259
|
-
continue;
|
|
260
|
-
case 7:
|
|
261
|
-
op = _.ops.pop();
|
|
262
|
-
_.trys.pop();
|
|
263
|
-
continue;
|
|
264
|
-
default:
|
|
265
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
|
|
266
|
-
_ = 0;
|
|
267
|
-
continue;
|
|
268
|
-
}
|
|
269
|
-
if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
|
|
270
|
-
_.label = op[1];
|
|
271
|
-
break;
|
|
272
|
-
}
|
|
273
|
-
if (op[0] === 6 && _.label < t[1]) {
|
|
274
|
-
_.label = t[1];
|
|
275
|
-
t = op;
|
|
276
|
-
break;
|
|
277
|
-
}
|
|
278
|
-
if (t && _.label < t[2]) {
|
|
279
|
-
_.label = t[2];
|
|
280
|
-
_.ops.push(op);
|
|
281
|
-
break;
|
|
282
|
-
}
|
|
283
|
-
if (t[2]) _.ops.pop();
|
|
284
|
-
_.trys.pop();
|
|
285
|
-
continue;
|
|
286
|
-
}
|
|
287
|
-
op = body.call(thisArg, _);
|
|
288
|
-
} catch (e) {
|
|
289
|
-
op = [
|
|
290
|
-
6,
|
|
291
|
-
e
|
|
292
|
-
];
|
|
293
|
-
y = 0;
|
|
294
|
-
} finally{
|
|
295
|
-
f = t = 0;
|
|
296
|
-
}
|
|
297
|
-
if (op[0] & 5) throw op[1];
|
|
298
|
-
return {
|
|
299
|
-
value: op[0] ? op[1] : void 0,
|
|
300
|
-
done: true
|
|
301
|
-
};
|
|
302
|
-
}
|
|
303
|
-
}
|
|
304
2
|
var __create = Object.create;
|
|
305
3
|
var __defProp = Object.defineProperty;
|
|
306
4
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
307
5
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
308
6
|
var __getProtoOf = Object.getPrototypeOf;
|
|
309
7
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
310
|
-
var __defNormalProp =
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
writable: true,
|
|
315
|
-
value: value
|
|
316
|
-
}) : obj[key] = value;
|
|
317
|
-
};
|
|
318
|
-
var __export = function(target, all) {
|
|
319
|
-
for(var name in all)__defProp(target, name, {
|
|
320
|
-
get: all[name],
|
|
321
|
-
enumerable: true
|
|
322
|
-
});
|
|
323
|
-
};
|
|
324
|
-
var __copyProps = function(to, from, except, desc) {
|
|
325
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
326
|
-
var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
|
|
327
|
-
try {
|
|
328
|
-
var _loop = function() {
|
|
329
|
-
var key = _step.value;
|
|
330
|
-
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
331
|
-
get: function() {
|
|
332
|
-
return from[key];
|
|
333
|
-
},
|
|
334
|
-
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
335
|
-
});
|
|
336
|
-
};
|
|
337
|
-
for(var _iterator = __getOwnPropNames(from)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true)_loop();
|
|
338
|
-
} catch (err) {
|
|
339
|
-
_didIteratorError = true;
|
|
340
|
-
_iteratorError = err;
|
|
341
|
-
} finally{
|
|
342
|
-
try {
|
|
343
|
-
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
344
|
-
_iterator.return();
|
|
345
|
-
}
|
|
346
|
-
} finally{
|
|
347
|
-
if (_didIteratorError) {
|
|
348
|
-
throw _iteratorError;
|
|
349
|
-
}
|
|
350
|
-
}
|
|
351
|
-
}
|
|
352
|
-
}
|
|
353
|
-
return to;
|
|
354
|
-
};
|
|
355
|
-
var __toESM = function(mod, isNodeMode, target) {
|
|
356
|
-
return target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(// If the importer is in node compatibility mode or this is not an ESM
|
|
357
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
358
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
359
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
360
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
361
|
-
value: mod,
|
|
362
|
-
enumerable: true
|
|
363
|
-
}) : target, mod);
|
|
8
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
9
|
+
var __export = (target, all) => {
|
|
10
|
+
for (var name in all)
|
|
11
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
364
12
|
};
|
|
365
|
-
var
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
13
|
+
var __copyProps = (to, from, except, desc) => {
|
|
14
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
15
|
+
for (let key of __getOwnPropNames(from))
|
|
16
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
17
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
18
|
+
}
|
|
19
|
+
return to;
|
|
369
20
|
};
|
|
370
|
-
var
|
|
371
|
-
|
|
372
|
-
|
|
21
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
22
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
23
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
24
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
25
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
26
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
27
|
+
mod
|
|
28
|
+
));
|
|
29
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
30
|
+
var __publicField = (obj, key, value) => {
|
|
31
|
+
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
32
|
+
return value;
|
|
373
33
|
};
|
|
34
|
+
|
|
374
35
|
// src/index.tsx
|
|
375
36
|
var src_exports = {};
|
|
376
37
|
__export(src_exports, {
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
},
|
|
380
|
-
default: function() {
|
|
381
|
-
return InlineSVG;
|
|
382
|
-
}
|
|
38
|
+
cacheStore: () => cacheStore,
|
|
39
|
+
default: () => InlineSVG
|
|
383
40
|
});
|
|
384
41
|
module.exports = __toCommonJS(src_exports);
|
|
385
42
|
var React = __toESM(require("react"));
|
|
386
43
|
var import_react_from_dom = __toESM(require("react-from-dom"));
|
|
44
|
+
|
|
387
45
|
// src/config.ts
|
|
388
46
|
var CACHE_NAME = "react-inlinesvg";
|
|
389
47
|
var CACHE_MAX_RETRIES = 10;
|
|
390
48
|
var STATUS = {
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
49
|
+
IDLE: "idle",
|
|
50
|
+
LOADING: "loading",
|
|
51
|
+
LOADED: "loaded",
|
|
52
|
+
FAILED: "failed",
|
|
53
|
+
READY: "ready",
|
|
54
|
+
UNSUPPORTED: "unsupported"
|
|
397
55
|
};
|
|
56
|
+
|
|
398
57
|
// src/helpers.ts
|
|
399
58
|
function canUseDOM() {
|
|
400
|
-
|
|
59
|
+
return !!(typeof window !== "undefined" && window.document && window.document.createElement);
|
|
401
60
|
}
|
|
402
61
|
function isSupportedEnvironment() {
|
|
403
|
-
|
|
404
|
-
}
|
|
405
|
-
function request(url, options) {
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
_split = _sliced_to_array((contentType || "").split(/ ?; ?/), 1), fileType = _split[0];
|
|
422
|
-
if (response.status > 299) {
|
|
423
|
-
throw new Error("Not found");
|
|
424
|
-
}
|
|
425
|
-
if (![
|
|
426
|
-
"image/svg+xml",
|
|
427
|
-
"text/plain"
|
|
428
|
-
].some(function(d) {
|
|
429
|
-
return fileType.includes(d);
|
|
430
|
-
})) {
|
|
431
|
-
throw new Error("Content type isn't valid: ".concat(fileType));
|
|
432
|
-
}
|
|
433
|
-
return [
|
|
434
|
-
2,
|
|
435
|
-
response.text()
|
|
436
|
-
];
|
|
437
|
-
}
|
|
438
|
-
});
|
|
439
|
-
});
|
|
440
|
-
return _request.apply(this, arguments);
|
|
441
|
-
}
|
|
442
|
-
function sleep() {
|
|
443
|
-
var seconds = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : 1;
|
|
444
|
-
return new Promise(function(resolve) {
|
|
445
|
-
setTimeout(resolve, seconds * 1e3);
|
|
446
|
-
});
|
|
62
|
+
return supportsInlineSVG() && typeof window !== "undefined" && window !== null;
|
|
63
|
+
}
|
|
64
|
+
async function request(url, options) {
|
|
65
|
+
const response = await fetch(url, options);
|
|
66
|
+
const contentType = response.headers.get("content-type");
|
|
67
|
+
const [fileType] = (contentType || "").split(/ ?; ?/);
|
|
68
|
+
if (response.status > 299) {
|
|
69
|
+
throw new Error("Not found");
|
|
70
|
+
}
|
|
71
|
+
if (!["image/svg+xml", "text/plain"].some((d) => fileType.includes(d))) {
|
|
72
|
+
throw new Error(`Content type isn't valid: ${fileType}`);
|
|
73
|
+
}
|
|
74
|
+
return response.text();
|
|
75
|
+
}
|
|
76
|
+
function sleep(seconds = 1) {
|
|
77
|
+
return new Promise((resolve) => {
|
|
78
|
+
setTimeout(resolve, seconds * 1e3);
|
|
79
|
+
});
|
|
447
80
|
}
|
|
448
81
|
function supportsInlineSVG() {
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
82
|
+
if (!document) {
|
|
83
|
+
return false;
|
|
84
|
+
}
|
|
85
|
+
const div = document.createElement("div");
|
|
86
|
+
div.innerHTML = "<svg />";
|
|
87
|
+
const svg = div.firstChild;
|
|
88
|
+
return !!svg && svg.namespaceURI === "http://www.w3.org/2000/svg";
|
|
456
89
|
}
|
|
457
90
|
function randomCharacter(character) {
|
|
458
|
-
|
|
91
|
+
return character[Math.floor(Math.random() * character.length)];
|
|
459
92
|
}
|
|
460
93
|
function randomString(length) {
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
94
|
+
const letters = "abcdefghijklmnopqrstuvwxyz";
|
|
95
|
+
const numbers = "1234567890";
|
|
96
|
+
const charset = `${letters}${letters.toUpperCase()}${numbers}`;
|
|
97
|
+
let R = "";
|
|
98
|
+
for (let index = 0; index < length; index++) {
|
|
99
|
+
R += randomCharacter(charset);
|
|
100
|
+
}
|
|
101
|
+
return R;
|
|
102
|
+
}
|
|
103
|
+
function omit(input, ...filter) {
|
|
104
|
+
const output = {};
|
|
105
|
+
for (const key in input) {
|
|
106
|
+
if ({}.hasOwnProperty.call(input, key)) {
|
|
107
|
+
if (!filter.includes(key)) {
|
|
108
|
+
output[key] = input[key];
|
|
109
|
+
}
|
|
467
110
|
}
|
|
468
|
-
|
|
111
|
+
}
|
|
112
|
+
return output;
|
|
469
113
|
}
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
114
|
+
|
|
115
|
+
// src/cache.ts
|
|
116
|
+
var CacheStore = class {
|
|
117
|
+
constructor() {
|
|
118
|
+
__publicField(this, "cacheApi");
|
|
119
|
+
__publicField(this, "cacheStore");
|
|
120
|
+
__publicField(this, "subscribers", []);
|
|
121
|
+
__publicField(this, "isReady", false);
|
|
122
|
+
this.cacheStore = /* @__PURE__ */ new Map();
|
|
123
|
+
let cacheName = CACHE_NAME;
|
|
124
|
+
let usePersistentCache = false;
|
|
125
|
+
if (canUseDOM()) {
|
|
126
|
+
cacheName = window.REACT_INLINESVG_CACHE_NAME ?? CACHE_NAME;
|
|
127
|
+
usePersistentCache = !!window.REACT_INLINESVG_PERSISTENT_CACHE;
|
|
473
128
|
}
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
129
|
+
if (usePersistentCache) {
|
|
130
|
+
caches.open(cacheName).then((cache) => {
|
|
131
|
+
this.cacheApi = cache;
|
|
132
|
+
this.isReady = true;
|
|
133
|
+
this.subscribers.forEach((callback) => callback());
|
|
134
|
+
});
|
|
135
|
+
} else {
|
|
136
|
+
this.isReady = true;
|
|
481
137
|
}
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
_class_call_check(this, CacheStore);
|
|
489
|
-
__publicField(this, "cacheApi");
|
|
490
|
-
__publicField(this, "cacheStore");
|
|
491
|
-
__publicField(this, "subscribers", []);
|
|
492
|
-
__publicField(this, "usePersistentCache");
|
|
493
|
-
__publicField(this, "isReady", false);
|
|
494
|
-
this.cacheStore = /* @__PURE__ */ new Map();
|
|
495
|
-
this.usePersistentCache = "REACT_INLINESVG_PERSISTENT_CACHE" in window && !!window.REACT_INLINESVG_PERSISTENT_CACHE;
|
|
496
|
-
if (this.usePersistentCache) {
|
|
497
|
-
caches.open(CACHE_NAME).then(function(cache) {
|
|
498
|
-
_this.cacheApi = cache;
|
|
499
|
-
_this.isReady = true;
|
|
500
|
-
_this.subscribers.forEach(function(callback) {
|
|
501
|
-
return callback();
|
|
502
|
-
});
|
|
503
|
-
});
|
|
504
|
-
} else {
|
|
505
|
-
this.isReady = true;
|
|
506
|
-
}
|
|
138
|
+
}
|
|
139
|
+
onReady(callback) {
|
|
140
|
+
if (this.isReady) {
|
|
141
|
+
callback();
|
|
142
|
+
} else {
|
|
143
|
+
this.subscribers.push(callback);
|
|
507
144
|
}
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
6
|
|
602
|
-
];
|
|
603
|
-
_this.cacheStore.set(url, {
|
|
604
|
-
content: "",
|
|
605
|
-
status: STATUS.LOADING
|
|
606
|
-
});
|
|
607
|
-
_state.label = 3;
|
|
608
|
-
case 3:
|
|
609
|
-
_state.trys.push([
|
|
610
|
-
3,
|
|
611
|
-
5,
|
|
612
|
-
,
|
|
613
|
-
6
|
|
614
|
-
]);
|
|
615
|
-
return [
|
|
616
|
-
4,
|
|
617
|
-
request(url, fetchOptions)
|
|
618
|
-
];
|
|
619
|
-
case 4:
|
|
620
|
-
content = _state.sent();
|
|
621
|
-
_this.cacheStore.set(url, {
|
|
622
|
-
content: content,
|
|
623
|
-
status: STATUS.LOADED
|
|
624
|
-
});
|
|
625
|
-
return [
|
|
626
|
-
3,
|
|
627
|
-
6
|
|
628
|
-
];
|
|
629
|
-
case 5:
|
|
630
|
-
error = _state.sent();
|
|
631
|
-
_this.cacheStore.set(url, {
|
|
632
|
-
content: "",
|
|
633
|
-
status: STATUS.FAILED
|
|
634
|
-
});
|
|
635
|
-
throw error;
|
|
636
|
-
case 6:
|
|
637
|
-
return [
|
|
638
|
-
2
|
|
639
|
-
];
|
|
640
|
-
}
|
|
641
|
-
});
|
|
642
|
-
})();
|
|
643
|
-
}
|
|
644
|
-
},
|
|
645
|
-
{
|
|
646
|
-
key: "fetchAndAddToPersistentCache",
|
|
647
|
-
value: function fetchAndAddToPersistentCache(url, fetchOptions) {
|
|
648
|
-
var _this = this;
|
|
649
|
-
return _async_to_generator(function() {
|
|
650
|
-
var _cache, _cache1, _this_cacheApi, cache, data, content, _this_cacheApi1, _this_cacheApi2, _response, response, _ref, content1, error;
|
|
651
|
-
return _ts_generator(this, function(_state) {
|
|
652
|
-
switch(_state.label){
|
|
653
|
-
case 0:
|
|
654
|
-
cache = _this.cacheStore.get(url);
|
|
655
|
-
if (((_cache = cache) === null || _cache === void 0 ? void 0 : _cache.status) === STATUS.LOADED) {
|
|
656
|
-
return [
|
|
657
|
-
2
|
|
658
|
-
];
|
|
659
|
-
}
|
|
660
|
-
if (!(((_cache1 = cache) === null || _cache1 === void 0 ? void 0 : _cache1.status) === STATUS.LOADING)) return [
|
|
661
|
-
3,
|
|
662
|
-
2
|
|
663
|
-
];
|
|
664
|
-
return [
|
|
665
|
-
4,
|
|
666
|
-
_this.handleLoading(url, /*#__PURE__*/ _async_to_generator(function() {
|
|
667
|
-
return _ts_generator(this, function(_state) {
|
|
668
|
-
switch(_state.label){
|
|
669
|
-
case 0:
|
|
670
|
-
_this.cacheStore.set(url, {
|
|
671
|
-
content: "",
|
|
672
|
-
status: STATUS.IDLE
|
|
673
|
-
});
|
|
674
|
-
return [
|
|
675
|
-
4,
|
|
676
|
-
_this.fetchAndAddToPersistentCache(url, fetchOptions)
|
|
677
|
-
];
|
|
678
|
-
case 1:
|
|
679
|
-
_state.sent();
|
|
680
|
-
return [
|
|
681
|
-
2
|
|
682
|
-
];
|
|
683
|
-
}
|
|
684
|
-
});
|
|
685
|
-
}))
|
|
686
|
-
];
|
|
687
|
-
case 1:
|
|
688
|
-
_state.sent();
|
|
689
|
-
return [
|
|
690
|
-
2
|
|
691
|
-
];
|
|
692
|
-
case 2:
|
|
693
|
-
_this.cacheStore.set(url, {
|
|
694
|
-
content: "",
|
|
695
|
-
status: STATUS.LOADING
|
|
696
|
-
});
|
|
697
|
-
return [
|
|
698
|
-
4,
|
|
699
|
-
(_this_cacheApi = _this.cacheApi) === null || _this_cacheApi === void 0 ? void 0 : _this_cacheApi.match(url)
|
|
700
|
-
];
|
|
701
|
-
case 3:
|
|
702
|
-
data = _state.sent();
|
|
703
|
-
if (!data) return [
|
|
704
|
-
3,
|
|
705
|
-
5
|
|
706
|
-
];
|
|
707
|
-
return [
|
|
708
|
-
4,
|
|
709
|
-
data.text()
|
|
710
|
-
];
|
|
711
|
-
case 4:
|
|
712
|
-
content = _state.sent();
|
|
713
|
-
_this.cacheStore.set(url, {
|
|
714
|
-
content: content,
|
|
715
|
-
status: STATUS.LOADED
|
|
716
|
-
});
|
|
717
|
-
return [
|
|
718
|
-
2
|
|
719
|
-
];
|
|
720
|
-
case 5:
|
|
721
|
-
_state.trys.push([
|
|
722
|
-
5,
|
|
723
|
-
9,
|
|
724
|
-
,
|
|
725
|
-
10
|
|
726
|
-
]);
|
|
727
|
-
return [
|
|
728
|
-
4,
|
|
729
|
-
(_this_cacheApi1 = _this.cacheApi) === null || _this_cacheApi1 === void 0 ? void 0 : _this_cacheApi1.add(new Request(url, fetchOptions))
|
|
730
|
-
];
|
|
731
|
-
case 6:
|
|
732
|
-
_state.sent();
|
|
733
|
-
return [
|
|
734
|
-
4,
|
|
735
|
-
(_this_cacheApi2 = _this.cacheApi) === null || _this_cacheApi2 === void 0 ? void 0 : _this_cacheApi2.match(url)
|
|
736
|
-
];
|
|
737
|
-
case 7:
|
|
738
|
-
response = _state.sent();
|
|
739
|
-
return [
|
|
740
|
-
4,
|
|
741
|
-
(_response = response) === null || _response === void 0 ? void 0 : _response.text()
|
|
742
|
-
];
|
|
743
|
-
case 8:
|
|
744
|
-
content1 = (_ref = _state.sent()) !== null && _ref !== void 0 ? _ref : "";
|
|
745
|
-
_this.cacheStore.set(url, {
|
|
746
|
-
content: content1,
|
|
747
|
-
status: STATUS.LOADED
|
|
748
|
-
});
|
|
749
|
-
return [
|
|
750
|
-
3,
|
|
751
|
-
10
|
|
752
|
-
];
|
|
753
|
-
case 9:
|
|
754
|
-
error = _state.sent();
|
|
755
|
-
_this.cacheStore.set(url, {
|
|
756
|
-
content: "",
|
|
757
|
-
status: STATUS.FAILED
|
|
758
|
-
});
|
|
759
|
-
throw error;
|
|
760
|
-
case 10:
|
|
761
|
-
return [
|
|
762
|
-
2
|
|
763
|
-
];
|
|
764
|
-
}
|
|
765
|
-
});
|
|
766
|
-
})();
|
|
767
|
-
}
|
|
768
|
-
},
|
|
769
|
-
{
|
|
770
|
-
key: "handleLoading",
|
|
771
|
-
value: function handleLoading(url, callback) {
|
|
772
|
-
var _this = this;
|
|
773
|
-
return _async_to_generator(function() {
|
|
774
|
-
var _this_cacheStore_get, retryCount;
|
|
775
|
-
return _ts_generator(this, function(_state) {
|
|
776
|
-
switch(_state.label){
|
|
777
|
-
case 0:
|
|
778
|
-
retryCount = 0;
|
|
779
|
-
_state.label = 1;
|
|
780
|
-
case 1:
|
|
781
|
-
if (!(((_this_cacheStore_get = _this.cacheStore.get(url)) === null || _this_cacheStore_get === void 0 ? void 0 : _this_cacheStore_get.status) === STATUS.LOADING && retryCount < CACHE_MAX_RETRIES)) return [
|
|
782
|
-
3,
|
|
783
|
-
3
|
|
784
|
-
];
|
|
785
|
-
return [
|
|
786
|
-
4,
|
|
787
|
-
sleep(0.1)
|
|
788
|
-
];
|
|
789
|
-
case 2:
|
|
790
|
-
_state.sent();
|
|
791
|
-
retryCount += 1;
|
|
792
|
-
return [
|
|
793
|
-
3,
|
|
794
|
-
1
|
|
795
|
-
];
|
|
796
|
-
case 3:
|
|
797
|
-
if (!(retryCount >= CACHE_MAX_RETRIES)) return [
|
|
798
|
-
3,
|
|
799
|
-
5
|
|
800
|
-
];
|
|
801
|
-
return [
|
|
802
|
-
4,
|
|
803
|
-
callback()
|
|
804
|
-
];
|
|
805
|
-
case 4:
|
|
806
|
-
_state.sent();
|
|
807
|
-
_state.label = 5;
|
|
808
|
-
case 5:
|
|
809
|
-
return [
|
|
810
|
-
2
|
|
811
|
-
];
|
|
812
|
-
}
|
|
813
|
-
});
|
|
814
|
-
})();
|
|
815
|
-
}
|
|
816
|
-
},
|
|
817
|
-
{
|
|
818
|
-
key: "keys",
|
|
819
|
-
value: function keys() {
|
|
820
|
-
return _to_consumable_array(this.cacheStore.keys());
|
|
821
|
-
}
|
|
822
|
-
},
|
|
823
|
-
{
|
|
824
|
-
key: "data",
|
|
825
|
-
value: function data() {
|
|
826
|
-
return _to_consumable_array(this.cacheStore.entries()).map(function(param) {
|
|
827
|
-
var _param = _sliced_to_array(param, 2), key = _param[0], value = _param[1];
|
|
828
|
-
return _define_property({}, key, value);
|
|
829
|
-
});
|
|
830
|
-
}
|
|
831
|
-
},
|
|
832
|
-
{
|
|
833
|
-
key: "delete",
|
|
834
|
-
value: function _delete(url) {
|
|
835
|
-
var _this = this;
|
|
836
|
-
return _async_to_generator(function() {
|
|
837
|
-
return _ts_generator(this, function(_state) {
|
|
838
|
-
switch(_state.label){
|
|
839
|
-
case 0:
|
|
840
|
-
if (!_this.cacheApi) return [
|
|
841
|
-
3,
|
|
842
|
-
2
|
|
843
|
-
];
|
|
844
|
-
return [
|
|
845
|
-
4,
|
|
846
|
-
_this.cacheApi.delete(url)
|
|
847
|
-
];
|
|
848
|
-
case 1:
|
|
849
|
-
_state.sent();
|
|
850
|
-
_state.label = 2;
|
|
851
|
-
case 2:
|
|
852
|
-
_this.cacheStore.delete(url);
|
|
853
|
-
return [
|
|
854
|
-
2
|
|
855
|
-
];
|
|
856
|
-
}
|
|
857
|
-
});
|
|
858
|
-
})();
|
|
859
|
-
}
|
|
860
|
-
},
|
|
861
|
-
{
|
|
862
|
-
key: "clear",
|
|
863
|
-
value: function clear() {
|
|
864
|
-
var _this = this;
|
|
865
|
-
return _async_to_generator(function() {
|
|
866
|
-
var keys, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, key, err;
|
|
867
|
-
return _ts_generator(this, function(_state) {
|
|
868
|
-
switch(_state.label){
|
|
869
|
-
case 0:
|
|
870
|
-
if (!_this.cacheApi) return [
|
|
871
|
-
3,
|
|
872
|
-
9
|
|
873
|
-
];
|
|
874
|
-
return [
|
|
875
|
-
4,
|
|
876
|
-
_this.cacheApi.keys()
|
|
877
|
-
];
|
|
878
|
-
case 1:
|
|
879
|
-
keys = _state.sent();
|
|
880
|
-
_iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
|
|
881
|
-
_state.label = 2;
|
|
882
|
-
case 2:
|
|
883
|
-
_state.trys.push([
|
|
884
|
-
2,
|
|
885
|
-
7,
|
|
886
|
-
8,
|
|
887
|
-
9
|
|
888
|
-
]);
|
|
889
|
-
_iterator = keys[Symbol.iterator]();
|
|
890
|
-
_state.label = 3;
|
|
891
|
-
case 3:
|
|
892
|
-
if (!!(_iteratorNormalCompletion = (_step = _iterator.next()).done)) return [
|
|
893
|
-
3,
|
|
894
|
-
6
|
|
895
|
-
];
|
|
896
|
-
key = _step.value;
|
|
897
|
-
return [
|
|
898
|
-
4,
|
|
899
|
-
_this.cacheApi.delete(key)
|
|
900
|
-
];
|
|
901
|
-
case 4:
|
|
902
|
-
_state.sent();
|
|
903
|
-
_state.label = 5;
|
|
904
|
-
case 5:
|
|
905
|
-
_iteratorNormalCompletion = true;
|
|
906
|
-
return [
|
|
907
|
-
3,
|
|
908
|
-
3
|
|
909
|
-
];
|
|
910
|
-
case 6:
|
|
911
|
-
return [
|
|
912
|
-
3,
|
|
913
|
-
9
|
|
914
|
-
];
|
|
915
|
-
case 7:
|
|
916
|
-
err = _state.sent();
|
|
917
|
-
_didIteratorError = true;
|
|
918
|
-
_iteratorError = err;
|
|
919
|
-
return [
|
|
920
|
-
3,
|
|
921
|
-
9
|
|
922
|
-
];
|
|
923
|
-
case 8:
|
|
924
|
-
try {
|
|
925
|
-
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
926
|
-
_iterator.return();
|
|
927
|
-
}
|
|
928
|
-
} finally{
|
|
929
|
-
if (_didIteratorError) {
|
|
930
|
-
throw _iteratorError;
|
|
931
|
-
}
|
|
932
|
-
}
|
|
933
|
-
return [
|
|
934
|
-
7
|
|
935
|
-
];
|
|
936
|
-
case 9:
|
|
937
|
-
_this.cacheStore.clear();
|
|
938
|
-
return [
|
|
939
|
-
2
|
|
940
|
-
];
|
|
941
|
-
}
|
|
942
|
-
});
|
|
943
|
-
})();
|
|
944
|
-
}
|
|
945
|
-
}
|
|
946
|
-
]);
|
|
947
|
-
return CacheStore;
|
|
948
|
-
}();
|
|
145
|
+
}
|
|
146
|
+
async get(url, fetchOptions) {
|
|
147
|
+
await (this.cacheApi ? this.fetchAndAddToPersistentCache(url, fetchOptions) : this.fetchAndAddToInternalCache(url, fetchOptions));
|
|
148
|
+
return this.cacheStore.get(url)?.content ?? "";
|
|
149
|
+
}
|
|
150
|
+
set(url, data) {
|
|
151
|
+
this.cacheStore.set(url, data);
|
|
152
|
+
}
|
|
153
|
+
isCached(url) {
|
|
154
|
+
return this.cacheStore.get(url)?.status === STATUS.LOADED;
|
|
155
|
+
}
|
|
156
|
+
async fetchAndAddToInternalCache(url, fetchOptions) {
|
|
157
|
+
const cache = this.cacheStore.get(url);
|
|
158
|
+
if (cache?.status === STATUS.LOADING) {
|
|
159
|
+
await this.handleLoading(url, async () => {
|
|
160
|
+
this.cacheStore.set(url, { content: "", status: STATUS.IDLE });
|
|
161
|
+
await this.fetchAndAddToInternalCache(url, fetchOptions);
|
|
162
|
+
});
|
|
163
|
+
return;
|
|
164
|
+
}
|
|
165
|
+
if (!cache?.content) {
|
|
166
|
+
this.cacheStore.set(url, { content: "", status: STATUS.LOADING });
|
|
167
|
+
try {
|
|
168
|
+
const content = await request(url, fetchOptions);
|
|
169
|
+
this.cacheStore.set(url, { content, status: STATUS.LOADED });
|
|
170
|
+
} catch (error) {
|
|
171
|
+
this.cacheStore.set(url, { content: "", status: STATUS.FAILED });
|
|
172
|
+
throw error;
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
async fetchAndAddToPersistentCache(url, fetchOptions) {
|
|
177
|
+
const cache = this.cacheStore.get(url);
|
|
178
|
+
if (cache?.status === STATUS.LOADED) {
|
|
179
|
+
return;
|
|
180
|
+
}
|
|
181
|
+
if (cache?.status === STATUS.LOADING) {
|
|
182
|
+
await this.handleLoading(url, async () => {
|
|
183
|
+
this.cacheStore.set(url, { content: "", status: STATUS.IDLE });
|
|
184
|
+
await this.fetchAndAddToPersistentCache(url, fetchOptions);
|
|
185
|
+
});
|
|
186
|
+
return;
|
|
187
|
+
}
|
|
188
|
+
this.cacheStore.set(url, { content: "", status: STATUS.LOADING });
|
|
189
|
+
const data = await this.cacheApi?.match(url);
|
|
190
|
+
if (data) {
|
|
191
|
+
const content = await data.text();
|
|
192
|
+
this.cacheStore.set(url, { content, status: STATUS.LOADED });
|
|
193
|
+
return;
|
|
194
|
+
}
|
|
195
|
+
try {
|
|
196
|
+
await this.cacheApi?.add(new Request(url, fetchOptions));
|
|
197
|
+
const response = await this.cacheApi?.match(url);
|
|
198
|
+
const content = await response?.text() ?? "";
|
|
199
|
+
this.cacheStore.set(url, { content, status: STATUS.LOADED });
|
|
200
|
+
} catch (error) {
|
|
201
|
+
this.cacheStore.set(url, { content: "", status: STATUS.FAILED });
|
|
202
|
+
throw error;
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
async handleLoading(url, callback) {
|
|
206
|
+
let retryCount = 0;
|
|
207
|
+
while (this.cacheStore.get(url)?.status === STATUS.LOADING && retryCount < CACHE_MAX_RETRIES) {
|
|
208
|
+
await sleep(0.1);
|
|
209
|
+
retryCount += 1;
|
|
210
|
+
}
|
|
211
|
+
if (retryCount >= CACHE_MAX_RETRIES) {
|
|
212
|
+
await callback();
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
keys() {
|
|
216
|
+
return [...this.cacheStore.keys()];
|
|
217
|
+
}
|
|
218
|
+
data() {
|
|
219
|
+
return [...this.cacheStore.entries()].map(([key, value]) => ({ [key]: value }));
|
|
220
|
+
}
|
|
221
|
+
async delete(url) {
|
|
222
|
+
if (this.cacheApi) {
|
|
223
|
+
await this.cacheApi.delete(url);
|
|
224
|
+
}
|
|
225
|
+
this.cacheStore.delete(url);
|
|
226
|
+
}
|
|
227
|
+
async clear() {
|
|
228
|
+
if (this.cacheApi) {
|
|
229
|
+
const keys = await this.cacheApi.keys();
|
|
230
|
+
for (const key of keys) {
|
|
231
|
+
await this.cacheApi.delete(key);
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
this.cacheStore.clear();
|
|
235
|
+
}
|
|
236
|
+
};
|
|
237
|
+
|
|
949
238
|
// src/index.tsx
|
|
950
239
|
var import_jsx_runtime = require("react/jsx-runtime");
|
|
951
240
|
var cacheStore;
|
|
952
|
-
var ReactInlineSVG =
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
request(src, fetchOptions)
|
|
972
|
-
];
|
|
973
|
-
case 1:
|
|
974
|
-
content = _state.sent();
|
|
975
|
-
_this1.handleLoad(content);
|
|
976
|
-
return [
|
|
977
|
-
2
|
|
978
|
-
];
|
|
979
|
-
}
|
|
980
|
-
});
|
|
981
|
-
}));
|
|
982
|
-
__publicField(_assert_this_initialized(_this), "handleError", function(error) {
|
|
983
|
-
var onError = _this.props.onError;
|
|
984
|
-
var status = error.message === "Browser does not support SVG" ? STATUS.UNSUPPORTED : STATUS.FAILED;
|
|
985
|
-
if (_this.isActive) {
|
|
986
|
-
_this.setState({
|
|
987
|
-
status: status
|
|
988
|
-
}, function() {
|
|
989
|
-
if (typeof onError === "function") {
|
|
990
|
-
onError(error);
|
|
991
|
-
}
|
|
992
|
-
});
|
|
993
|
-
}
|
|
994
|
-
});
|
|
995
|
-
__publicField(_assert_this_initialized(_this), "handleLoad", function(content) {
|
|
996
|
-
var hasCache = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : false;
|
|
997
|
-
if (_this.isActive) {
|
|
998
|
-
_this.setState({
|
|
999
|
-
content: content,
|
|
1000
|
-
isCached: hasCache,
|
|
1001
|
-
status: STATUS.LOADED
|
|
1002
|
-
}, _this.getElement);
|
|
1003
|
-
}
|
|
241
|
+
var ReactInlineSVG = class extends React.PureComponent {
|
|
242
|
+
constructor(props) {
|
|
243
|
+
super(props);
|
|
244
|
+
__publicField(this, "hash");
|
|
245
|
+
__publicField(this, "isActive", false);
|
|
246
|
+
__publicField(this, "isInitialized", false);
|
|
247
|
+
__publicField(this, "fetchContent", async () => {
|
|
248
|
+
const { fetchOptions, src } = this.props;
|
|
249
|
+
const content = await request(src, fetchOptions);
|
|
250
|
+
this.handleLoad(content);
|
|
251
|
+
});
|
|
252
|
+
__publicField(this, "handleError", (error) => {
|
|
253
|
+
const { onError } = this.props;
|
|
254
|
+
const status = error.message === "Browser does not support SVG" ? STATUS.UNSUPPORTED : STATUS.FAILED;
|
|
255
|
+
if (this.isActive) {
|
|
256
|
+
this.setState({ status }, () => {
|
|
257
|
+
if (typeof onError === "function") {
|
|
258
|
+
onError(error);
|
|
259
|
+
}
|
|
1004
260
|
});
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
261
|
+
}
|
|
262
|
+
});
|
|
263
|
+
__publicField(this, "handleLoad", (content, hasCache = false) => {
|
|
264
|
+
if (this.isActive) {
|
|
265
|
+
this.setState(
|
|
266
|
+
{
|
|
267
|
+
content,
|
|
268
|
+
isCached: hasCache,
|
|
269
|
+
status: STATUS.LOADED
|
|
270
|
+
},
|
|
271
|
+
this.getElement
|
|
272
|
+
);
|
|
273
|
+
}
|
|
274
|
+
});
|
|
275
|
+
this.state = {
|
|
276
|
+
content: "",
|
|
277
|
+
element: null,
|
|
278
|
+
isCached: !!props.cacheRequests && cacheStore.isCached(props.src),
|
|
279
|
+
status: STATUS.IDLE
|
|
280
|
+
};
|
|
281
|
+
this.hash = props.uniqueHash || randomString(8);
|
|
282
|
+
}
|
|
283
|
+
componentDidMount() {
|
|
284
|
+
this.isActive = true;
|
|
285
|
+
if (!canUseDOM() || this.isInitialized) {
|
|
286
|
+
return;
|
|
1013
287
|
}
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
descElement.innerHTML = description;
|
|
1106
|
-
svg.prepend(descElement);
|
|
1107
|
-
}
|
|
1108
|
-
if (typeof title !== "undefined") {
|
|
1109
|
-
var originalTitle = svg.querySelector("title");
|
|
1110
|
-
if (originalTitle && originalTitle.parentNode) {
|
|
1111
|
-
originalTitle.parentNode.removeChild(originalTitle);
|
|
1112
|
-
}
|
|
1113
|
-
if (title) {
|
|
1114
|
-
var titleElement = document.createElementNS("http://www.w3.org/2000/svg", "title");
|
|
1115
|
-
titleElement.innerHTML = title;
|
|
1116
|
-
svg.prepend(titleElement);
|
|
1117
|
-
}
|
|
1118
|
-
}
|
|
1119
|
-
return svg;
|
|
1120
|
-
} catch (error) {
|
|
1121
|
-
return this.handleError(error);
|
|
1122
|
-
}
|
|
1123
|
-
}
|
|
1124
|
-
},
|
|
1125
|
-
{
|
|
1126
|
-
key: "load",
|
|
1127
|
-
value: function load() {
|
|
1128
|
-
if (this.isActive) {
|
|
1129
|
-
var _this = this;
|
|
1130
|
-
this.setState({
|
|
1131
|
-
content: "",
|
|
1132
|
-
element: null,
|
|
1133
|
-
isCached: false,
|
|
1134
|
-
status: STATUS.LOADING
|
|
1135
|
-
}, /*#__PURE__*/ _async_to_generator(function() {
|
|
1136
|
-
var _this_props, cacheRequests, fetchOptions, src, dataURI, inlineSrc, content, error;
|
|
1137
|
-
return _ts_generator(this, function(_state) {
|
|
1138
|
-
switch(_state.label){
|
|
1139
|
-
case 0:
|
|
1140
|
-
_this_props = _this.props, cacheRequests = _this_props.cacheRequests, fetchOptions = _this_props.fetchOptions, src = _this_props.src;
|
|
1141
|
-
dataURI = src.match(RegExp("^data:image\\/svg[^,]*?(;base64)?,(.*)", "u"));
|
|
1142
|
-
if (dataURI) {
|
|
1143
|
-
inlineSrc = dataURI[1] ? window.atob(dataURI[2]) : decodeURIComponent(dataURI[2]);
|
|
1144
|
-
} else if (src.includes("<svg")) {
|
|
1145
|
-
inlineSrc = src;
|
|
1146
|
-
}
|
|
1147
|
-
if (inlineSrc) {
|
|
1148
|
-
_this.handleLoad(inlineSrc);
|
|
1149
|
-
return [
|
|
1150
|
-
2
|
|
1151
|
-
];
|
|
1152
|
-
}
|
|
1153
|
-
_state.label = 1;
|
|
1154
|
-
case 1:
|
|
1155
|
-
_state.trys.push([
|
|
1156
|
-
1,
|
|
1157
|
-
6,
|
|
1158
|
-
,
|
|
1159
|
-
7
|
|
1160
|
-
]);
|
|
1161
|
-
if (!cacheRequests) return [
|
|
1162
|
-
3,
|
|
1163
|
-
3
|
|
1164
|
-
];
|
|
1165
|
-
return [
|
|
1166
|
-
4,
|
|
1167
|
-
cacheStore.get(src, fetchOptions)
|
|
1168
|
-
];
|
|
1169
|
-
case 2:
|
|
1170
|
-
content = _state.sent();
|
|
1171
|
-
_this.handleLoad(content, true);
|
|
1172
|
-
return [
|
|
1173
|
-
3,
|
|
1174
|
-
5
|
|
1175
|
-
];
|
|
1176
|
-
case 3:
|
|
1177
|
-
return [
|
|
1178
|
-
4,
|
|
1179
|
-
_this.fetchContent()
|
|
1180
|
-
];
|
|
1181
|
-
case 4:
|
|
1182
|
-
_state.sent();
|
|
1183
|
-
_state.label = 5;
|
|
1184
|
-
case 5:
|
|
1185
|
-
return [
|
|
1186
|
-
3,
|
|
1187
|
-
7
|
|
1188
|
-
];
|
|
1189
|
-
case 6:
|
|
1190
|
-
error = _state.sent();
|
|
1191
|
-
_this.handleError(error);
|
|
1192
|
-
return [
|
|
1193
|
-
3,
|
|
1194
|
-
7
|
|
1195
|
-
];
|
|
1196
|
-
case 7:
|
|
1197
|
-
return [
|
|
1198
|
-
2
|
|
1199
|
-
];
|
|
1200
|
-
}
|
|
1201
|
-
});
|
|
1202
|
-
}));
|
|
1203
|
-
}
|
|
1204
|
-
}
|
|
1205
|
-
},
|
|
1206
|
-
{
|
|
1207
|
-
key: "processSVG",
|
|
1208
|
-
value: function processSVG() {
|
|
1209
|
-
var content = this.state.content;
|
|
1210
|
-
var preProcessor = this.props.preProcessor;
|
|
1211
|
-
if (preProcessor) {
|
|
1212
|
-
return preProcessor(content);
|
|
1213
|
-
}
|
|
1214
|
-
return content;
|
|
1215
|
-
}
|
|
1216
|
-
},
|
|
288
|
+
const { status } = this.state;
|
|
289
|
+
const { src } = this.props;
|
|
290
|
+
try {
|
|
291
|
+
if (status === STATUS.IDLE) {
|
|
292
|
+
if (!isSupportedEnvironment()) {
|
|
293
|
+
throw new Error("Browser does not support SVG");
|
|
294
|
+
}
|
|
295
|
+
if (!src) {
|
|
296
|
+
throw new Error("Missing src");
|
|
297
|
+
}
|
|
298
|
+
this.load();
|
|
299
|
+
}
|
|
300
|
+
} catch (error) {
|
|
301
|
+
this.handleError(error);
|
|
302
|
+
}
|
|
303
|
+
this.isInitialized = true;
|
|
304
|
+
}
|
|
305
|
+
componentDidUpdate(previousProps, previousState) {
|
|
306
|
+
if (!canUseDOM()) {
|
|
307
|
+
return;
|
|
308
|
+
}
|
|
309
|
+
const { isCached, status } = this.state;
|
|
310
|
+
const { onLoad, src } = this.props;
|
|
311
|
+
if (previousState.status !== STATUS.READY && status === STATUS.READY) {
|
|
312
|
+
if (onLoad) {
|
|
313
|
+
onLoad(src, isCached);
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
if (previousProps.src !== src) {
|
|
317
|
+
if (!src) {
|
|
318
|
+
this.handleError(new Error("Missing src"));
|
|
319
|
+
return;
|
|
320
|
+
}
|
|
321
|
+
this.load();
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
componentWillUnmount() {
|
|
325
|
+
this.isActive = false;
|
|
326
|
+
}
|
|
327
|
+
getElement() {
|
|
328
|
+
try {
|
|
329
|
+
const node = this.getNode();
|
|
330
|
+
const element = (0, import_react_from_dom.default)(node);
|
|
331
|
+
if (!element || !React.isValidElement(element)) {
|
|
332
|
+
throw new Error("Could not convert the src to a React element");
|
|
333
|
+
}
|
|
334
|
+
this.setState({
|
|
335
|
+
element,
|
|
336
|
+
status: STATUS.READY
|
|
337
|
+
});
|
|
338
|
+
} catch (error) {
|
|
339
|
+
this.handleError(new Error(error.message));
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
getNode() {
|
|
343
|
+
const { description, title } = this.props;
|
|
344
|
+
try {
|
|
345
|
+
const svgText = this.processSVG();
|
|
346
|
+
const node = (0, import_react_from_dom.default)(svgText, { nodeOnly: true });
|
|
347
|
+
if (!node || !(node instanceof SVGSVGElement)) {
|
|
348
|
+
throw new Error("Could not convert the src to a DOM Node");
|
|
349
|
+
}
|
|
350
|
+
const svg = this.updateSVGAttributes(node);
|
|
351
|
+
if (description) {
|
|
352
|
+
const originalDesc = svg.querySelector("desc");
|
|
353
|
+
if (originalDesc && originalDesc.parentNode) {
|
|
354
|
+
originalDesc.parentNode.removeChild(originalDesc);
|
|
355
|
+
}
|
|
356
|
+
const descElement = document.createElementNS("http://www.w3.org/2000/svg", "desc");
|
|
357
|
+
descElement.innerHTML = description;
|
|
358
|
+
svg.prepend(descElement);
|
|
359
|
+
}
|
|
360
|
+
if (typeof title !== "undefined") {
|
|
361
|
+
const originalTitle = svg.querySelector("title");
|
|
362
|
+
if (originalTitle && originalTitle.parentNode) {
|
|
363
|
+
originalTitle.parentNode.removeChild(originalTitle);
|
|
364
|
+
}
|
|
365
|
+
if (title) {
|
|
366
|
+
const titleElement = document.createElementNS("http://www.w3.org/2000/svg", "title");
|
|
367
|
+
titleElement.innerHTML = title;
|
|
368
|
+
svg.prepend(titleElement);
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
return svg;
|
|
372
|
+
} catch (error) {
|
|
373
|
+
return this.handleError(error);
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
load() {
|
|
377
|
+
if (this.isActive) {
|
|
378
|
+
this.setState(
|
|
1217
379
|
{
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
var replaceableAttributes = [
|
|
1223
|
-
"id",
|
|
1224
|
-
"href",
|
|
1225
|
-
"xlink:href",
|
|
1226
|
-
"xlink:role",
|
|
1227
|
-
"xlink:arcrole"
|
|
1228
|
-
];
|
|
1229
|
-
var linkAttributes = [
|
|
1230
|
-
"href",
|
|
1231
|
-
"xlink:href"
|
|
1232
|
-
];
|
|
1233
|
-
var isDataValue = function(name, value) {
|
|
1234
|
-
return linkAttributes.includes(name) && (value ? !value.includes("#") : false);
|
|
1235
|
-
};
|
|
1236
|
-
if (!uniquifyIDs) {
|
|
1237
|
-
return node;
|
|
1238
|
-
}
|
|
1239
|
-
_to_consumable_array(node.children).forEach(function(d) {
|
|
1240
|
-
if (d.attributes && d.attributes.length) {
|
|
1241
|
-
var attributes = Object.values(d.attributes).map(function(a) {
|
|
1242
|
-
var attribute = a;
|
|
1243
|
-
var match = a.value.match(/url\((.*?)\)/);
|
|
1244
|
-
if (match && match[1]) {
|
|
1245
|
-
attribute.value = a.value.replace(match[0], "url(".concat(baseURL).concat(match[1], "__").concat(_this.hash, ")"));
|
|
1246
|
-
}
|
|
1247
|
-
return attribute;
|
|
1248
|
-
});
|
|
1249
|
-
replaceableAttributes.forEach(function(r) {
|
|
1250
|
-
var attribute = attributes.find(function(a) {
|
|
1251
|
-
return a.name === r;
|
|
1252
|
-
});
|
|
1253
|
-
if (attribute && !isDataValue(r, attribute.value)) {
|
|
1254
|
-
attribute.value = "".concat(attribute.value, "__").concat(_this.hash);
|
|
1255
|
-
}
|
|
1256
|
-
});
|
|
1257
|
-
}
|
|
1258
|
-
if (d.children.length) {
|
|
1259
|
-
return _this.updateSVGAttributes(d);
|
|
1260
|
-
}
|
|
1261
|
-
return d;
|
|
1262
|
-
});
|
|
1263
|
-
return node;
|
|
1264
|
-
}
|
|
380
|
+
content: "",
|
|
381
|
+
element: null,
|
|
382
|
+
isCached: false,
|
|
383
|
+
status: STATUS.LOADING
|
|
1265
384
|
},
|
|
1266
|
-
{
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
}
|
|
1286
|
-
return loader;
|
|
385
|
+
async () => {
|
|
386
|
+
const { cacheRequests, fetchOptions, src } = this.props;
|
|
387
|
+
const dataURI = src.match(/^data:image\/svg[^,]*?(;base64)?,(.*)/u);
|
|
388
|
+
let inlineSrc;
|
|
389
|
+
if (dataURI) {
|
|
390
|
+
inlineSrc = dataURI[1] ? window.atob(dataURI[2]) : decodeURIComponent(dataURI[2]);
|
|
391
|
+
} else if (src.includes("<svg")) {
|
|
392
|
+
inlineSrc = src;
|
|
393
|
+
}
|
|
394
|
+
if (inlineSrc) {
|
|
395
|
+
this.handleLoad(inlineSrc);
|
|
396
|
+
return;
|
|
397
|
+
}
|
|
398
|
+
try {
|
|
399
|
+
if (cacheRequests) {
|
|
400
|
+
const content = await cacheStore.get(src, fetchOptions);
|
|
401
|
+
this.handleLoad(content, true);
|
|
402
|
+
} else {
|
|
403
|
+
await this.fetchContent();
|
|
1287
404
|
}
|
|
405
|
+
} catch (error) {
|
|
406
|
+
this.handleError(error);
|
|
407
|
+
}
|
|
1288
408
|
}
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
}
|
|
409
|
+
);
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
processSVG() {
|
|
413
|
+
const { content } = this.state;
|
|
414
|
+
const { preProcessor } = this.props;
|
|
415
|
+
if (preProcessor) {
|
|
416
|
+
return preProcessor(content);
|
|
417
|
+
}
|
|
418
|
+
return content;
|
|
419
|
+
}
|
|
420
|
+
updateSVGAttributes(node) {
|
|
421
|
+
const { baseURL = "", uniquifyIDs } = this.props;
|
|
422
|
+
const replaceableAttributes = ["id", "href", "xlink:href", "xlink:role", "xlink:arcrole"];
|
|
423
|
+
const linkAttributes = ["href", "xlink:href"];
|
|
424
|
+
const isDataValue = (name, value) => linkAttributes.includes(name) && (value ? !value.includes("#") : false);
|
|
425
|
+
if (!uniquifyIDs) {
|
|
426
|
+
return node;
|
|
427
|
+
}
|
|
428
|
+
[...node.children].forEach((d) => {
|
|
429
|
+
if (d.attributes && d.attributes.length) {
|
|
430
|
+
const attributes = Object.values(d.attributes).map((a) => {
|
|
431
|
+
const attribute = a;
|
|
432
|
+
const match = a.value.match(/url\((.*?)\)/);
|
|
433
|
+
if (match && match[1]) {
|
|
434
|
+
attribute.value = a.value.replace(match[0], `url(${baseURL}${match[1]}__${this.hash})`);
|
|
435
|
+
}
|
|
436
|
+
return attribute;
|
|
437
|
+
});
|
|
438
|
+
replaceableAttributes.forEach((r) => {
|
|
439
|
+
const attribute = attributes.find((a) => a.name === r);
|
|
440
|
+
if (attribute && !isDataValue(r, attribute.value)) {
|
|
441
|
+
attribute.value = `${attribute.value}__${this.hash}`;
|
|
442
|
+
}
|
|
443
|
+
});
|
|
444
|
+
}
|
|
445
|
+
if (d.children.length) {
|
|
446
|
+
return this.updateSVGAttributes(d);
|
|
447
|
+
}
|
|
448
|
+
return d;
|
|
449
|
+
});
|
|
450
|
+
return node;
|
|
451
|
+
}
|
|
452
|
+
render() {
|
|
453
|
+
const { element, status } = this.state;
|
|
454
|
+
const { children = null, innerRef, loader = null } = this.props;
|
|
455
|
+
const elementProps = omit(
|
|
456
|
+
this.props,
|
|
457
|
+
"baseURL",
|
|
458
|
+
"cacheRequests",
|
|
459
|
+
"children",
|
|
460
|
+
"description",
|
|
461
|
+
"fetchOptions",
|
|
462
|
+
"innerRef",
|
|
463
|
+
"loader",
|
|
464
|
+
"onError",
|
|
465
|
+
"onLoad",
|
|
466
|
+
"preProcessor",
|
|
467
|
+
"src",
|
|
468
|
+
"title",
|
|
469
|
+
"uniqueHash",
|
|
470
|
+
"uniquifyIDs"
|
|
471
|
+
);
|
|
472
|
+
if (!canUseDOM()) {
|
|
473
|
+
return loader;
|
|
474
|
+
}
|
|
475
|
+
if (element) {
|
|
476
|
+
return React.cloneElement(element, { ref: innerRef, ...elementProps });
|
|
477
|
+
}
|
|
478
|
+
if ([STATUS.UNSUPPORTED, STATUS.FAILED].includes(status)) {
|
|
479
|
+
return children;
|
|
480
|
+
}
|
|
481
|
+
return loader;
|
|
482
|
+
}
|
|
483
|
+
};
|
|
1292
484
|
__publicField(ReactInlineSVG, "defaultProps", {
|
|
1293
|
-
|
|
1294
|
-
|
|
485
|
+
cacheRequests: true,
|
|
486
|
+
uniquifyIDs: false
|
|
1295
487
|
});
|
|
1296
488
|
function InlineSVG(props) {
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
}
|
|
1310
|
-
}, []);
|
|
1311
|
-
if (!isReady) {
|
|
1312
|
-
return loader;
|
|
489
|
+
if (!cacheStore) {
|
|
490
|
+
cacheStore = new CacheStore();
|
|
491
|
+
}
|
|
492
|
+
const { loader } = props;
|
|
493
|
+
const hasCallback = React.useRef(false);
|
|
494
|
+
const [isReady, setReady] = React.useState(cacheStore.isReady);
|
|
495
|
+
React.useEffect(() => {
|
|
496
|
+
if (!hasCallback.current) {
|
|
497
|
+
cacheStore.onReady(() => {
|
|
498
|
+
setReady(true);
|
|
499
|
+
});
|
|
500
|
+
hasCallback.current = true;
|
|
1313
501
|
}
|
|
1314
|
-
|
|
502
|
+
}, []);
|
|
503
|
+
if (!isReady) {
|
|
504
|
+
return loader;
|
|
505
|
+
}
|
|
506
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ReactInlineSVG, { ...props });
|
|
1315
507
|
}
|
|
1316
508
|
// Annotate the CommonJS export names for ESM import in node:
|
|
1317
509
|
0 && (module.exports = {
|
|
1318
|
-
|
|
510
|
+
cacheStore
|
|
1319
511
|
});
|
|
1320
512
|
//# sourceMappingURL=index.js.map
|