@modul-es/icons 0.1.2 → 0.1.4
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/Icon.js +12 -20
- package/package.json +1 -1
package/dist/Icon.js
CHANGED
|
@@ -40,8 +40,6 @@ exports.Icon = Icon;
|
|
|
40
40
|
var jsx_runtime_1 = require("react/jsx-runtime");
|
|
41
41
|
var react_1 = require("react");
|
|
42
42
|
var colors_1 = require("./colors");
|
|
43
|
-
// Cache for loaded SVG content
|
|
44
|
-
var svgCache = new Map();
|
|
45
43
|
function Icon(_a) {
|
|
46
44
|
var _this = this;
|
|
47
45
|
var name = _a.name, _b = _a.color, color = _b === void 0 ? 'currentColor' : _b, stroke = _a.stroke, style = _a.style, _c = _a.set, set = _c === void 0 ? 'huge' : _c, _d = _a.className, className = _d === void 0 ? "w-6 select-none" : _d, size = _a.size;
|
|
@@ -57,21 +55,16 @@ function Icon(_a) {
|
|
|
57
55
|
}
|
|
58
56
|
return iconName;
|
|
59
57
|
}, [name, set, style]);
|
|
60
|
-
var cacheKey = "".concat(set, "/").concat(iconKey);
|
|
61
58
|
(0, react_1.useEffect)(function () {
|
|
62
59
|
var loadSvg = function () { return __awaiter(_this, void 0, void 0, function () {
|
|
63
|
-
var params, colorValue, url, response, svg,
|
|
64
|
-
return __generator(this, function (
|
|
65
|
-
switch (
|
|
60
|
+
var params, colorValue, url, response, svg, _a;
|
|
61
|
+
return __generator(this, function (_b) {
|
|
62
|
+
switch (_b.label) {
|
|
66
63
|
case 0:
|
|
67
|
-
if (svgCache.has(cacheKey)) {
|
|
68
|
-
setSvgContent(svgCache.get(cacheKey));
|
|
69
|
-
return [2 /*return*/];
|
|
70
|
-
}
|
|
71
64
|
setError(false);
|
|
72
|
-
|
|
65
|
+
_b.label = 1;
|
|
73
66
|
case 1:
|
|
74
|
-
|
|
67
|
+
_b.trys.push([1, 6, , 7]);
|
|
75
68
|
params = new URLSearchParams();
|
|
76
69
|
if (color !== 'currentColor') {
|
|
77
70
|
colorValue = (0, colors_1.resolveColor)(color).replace('#', '');
|
|
@@ -79,23 +72,22 @@ function Icon(_a) {
|
|
|
79
72
|
}
|
|
80
73
|
if (stroke)
|
|
81
74
|
params.set('stroke', stroke);
|
|
82
|
-
url = "https://
|
|
83
|
-
return [4 /*yield*/, fetch(url, { mode: 'cors'
|
|
75
|
+
url = "https://modul.es/api/icons/".concat(set, "/").concat(iconKey, ".svg").concat(params.toString() ? "?".concat(params.toString()) : '');
|
|
76
|
+
return [4 /*yield*/, fetch(url, { mode: 'cors' })];
|
|
84
77
|
case 2:
|
|
85
|
-
response =
|
|
78
|
+
response = _b.sent();
|
|
86
79
|
if (!response.ok) return [3 /*break*/, 4];
|
|
87
80
|
return [4 /*yield*/, response.text()];
|
|
88
81
|
case 3:
|
|
89
|
-
svg =
|
|
90
|
-
svgCache.set(cacheKey, svg);
|
|
82
|
+
svg = _b.sent();
|
|
91
83
|
setSvgContent(svg);
|
|
92
84
|
return [3 /*break*/, 5];
|
|
93
85
|
case 4:
|
|
94
86
|
setError(true);
|
|
95
|
-
|
|
87
|
+
_b.label = 5;
|
|
96
88
|
case 5: return [3 /*break*/, 7];
|
|
97
89
|
case 6:
|
|
98
|
-
|
|
90
|
+
_a = _b.sent();
|
|
99
91
|
setError(true);
|
|
100
92
|
return [3 /*break*/, 7];
|
|
101
93
|
case 7: return [2 /*return*/];
|
|
@@ -103,7 +95,7 @@ function Icon(_a) {
|
|
|
103
95
|
});
|
|
104
96
|
}); };
|
|
105
97
|
loadSvg();
|
|
106
|
-
}, [
|
|
98
|
+
}, [color, stroke, set, iconKey]);
|
|
107
99
|
var processedSvg = (0, react_1.useMemo)(function () {
|
|
108
100
|
if (!svgContent)
|
|
109
101
|
return null;
|