viconic-react-icons 1.5.5 → 1.5.6

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.js CHANGED
@@ -2052,20 +2052,36 @@ function _dispatchBatchFetch(prefix, iconBaseName, entry) {
2052
2052
  if (!bj || !bj.icons) return;
2053
2053
  const W = window.__viconic = window.__viconic || {};
2054
2054
  W.icons = W.icons || {};
2055
+ const cdnFetches = [];
2055
2056
  for (const n in bj.icons) {
2056
2057
  if (!Object.prototype.hasOwnProperty.call(bj.icons, n)) continue;
2057
2058
  const d = bj.icons[n];
2058
2059
  const svg = d.svg || "";
2059
- if (!svg || !svg.includes("<")) continue;
2060
- W.icons[`@${prefix}/${n}`] = svg;
2061
- W.icons[`${prefix}:${n}`] = svg;
2062
- W.icons[`${prefix}/${n}`] = svg;
2063
- W.icons[n] = W.icons[n] || svg;
2064
- }
2065
- try {
2066
- document.dispatchEvent(new CustomEvent("viconic:ready", { detail: { prefix, kitId } }));
2067
- } catch (e) {
2060
+ if (svg && svg.includes("<")) {
2061
+ W.icons[`@${prefix}/${n}`] = svg;
2062
+ W.icons[`${prefix}:${n}`] = svg;
2063
+ W.icons[`${prefix}/${n}`] = svg;
2064
+ W.icons[n] = W.icons[n] || svg;
2065
+ } else if (d.cdn_url) {
2066
+ cdnFetches.push(
2067
+ fetch(d.cdn_url).then((r) => r.ok ? r.text() : "").then((s) => {
2068
+ if (s && s.includes("<")) {
2069
+ W.icons[`@${prefix}/${n}`] = s;
2070
+ W.icons[`${prefix}:${n}`] = s;
2071
+ W.icons[`${prefix}/${n}`] = s;
2072
+ W.icons[n] = W.icons[n] || s;
2073
+ }
2074
+ }).catch(() => {
2075
+ })
2076
+ );
2077
+ }
2068
2078
  }
2079
+ Promise.all(cdnFetches).then(() => {
2080
+ try {
2081
+ document.dispatchEvent(new CustomEvent("viconic:ready", { detail: { prefix, kitId } }));
2082
+ } catch (e) {
2083
+ }
2084
+ });
2069
2085
  }).catch(() => {
2070
2086
  });
2071
2087
  }, 150);
package/dist/index.mjs CHANGED
@@ -2017,20 +2017,36 @@ function _dispatchBatchFetch(prefix, iconBaseName, entry) {
2017
2017
  if (!bj || !bj.icons) return;
2018
2018
  const W = window.__viconic = window.__viconic || {};
2019
2019
  W.icons = W.icons || {};
2020
+ const cdnFetches = [];
2020
2021
  for (const n in bj.icons) {
2021
2022
  if (!Object.prototype.hasOwnProperty.call(bj.icons, n)) continue;
2022
2023
  const d = bj.icons[n];
2023
2024
  const svg = d.svg || "";
2024
- if (!svg || !svg.includes("<")) continue;
2025
- W.icons[`@${prefix}/${n}`] = svg;
2026
- W.icons[`${prefix}:${n}`] = svg;
2027
- W.icons[`${prefix}/${n}`] = svg;
2028
- W.icons[n] = W.icons[n] || svg;
2029
- }
2030
- try {
2031
- document.dispatchEvent(new CustomEvent("viconic:ready", { detail: { prefix, kitId } }));
2032
- } catch (e) {
2025
+ if (svg && svg.includes("<")) {
2026
+ W.icons[`@${prefix}/${n}`] = svg;
2027
+ W.icons[`${prefix}:${n}`] = svg;
2028
+ W.icons[`${prefix}/${n}`] = svg;
2029
+ W.icons[n] = W.icons[n] || svg;
2030
+ } else if (d.cdn_url) {
2031
+ cdnFetches.push(
2032
+ fetch(d.cdn_url).then((r) => r.ok ? r.text() : "").then((s) => {
2033
+ if (s && s.includes("<")) {
2034
+ W.icons[`@${prefix}/${n}`] = s;
2035
+ W.icons[`${prefix}:${n}`] = s;
2036
+ W.icons[`${prefix}/${n}`] = s;
2037
+ W.icons[n] = W.icons[n] || s;
2038
+ }
2039
+ }).catch(() => {
2040
+ })
2041
+ );
2042
+ }
2033
2043
  }
2044
+ Promise.all(cdnFetches).then(() => {
2045
+ try {
2046
+ document.dispatchEvent(new CustomEvent("viconic:ready", { detail: { prefix, kitId } }));
2047
+ } catch (e) {
2048
+ }
2049
+ });
2034
2050
  }).catch(() => {
2035
2051
  });
2036
2052
  }, 150);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "viconic-react-icons",
3
- "version": "1.5.5",
3
+ "version": "1.5.6",
4
4
  "description": "Viconic Smart Icons loader for React — supports Kit and 200k+ system icons",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
package/src/index.jsx CHANGED
@@ -109,17 +109,37 @@ function _dispatchBatchFetch(prefix, iconBaseName, entry) {
109
109
  if (!bj || !bj.icons) return;
110
110
  const W = (window.__viconic = window.__viconic || {});
111
111
  W.icons = W.icons || {};
112
+ const cdnFetches = [];
112
113
  for (const n in bj.icons) {
113
114
  if (!Object.prototype.hasOwnProperty.call(bj.icons, n)) continue;
114
115
  const d = bj.icons[n];
115
116
  const svg = d.svg || '';
116
- if (!svg || !svg.includes('<')) continue;
117
- W.icons[`@${prefix}/${n}`] = svg;
118
- W.icons[`${prefix}:${n}`] = svg;
119
- W.icons[`${prefix}/${n}`] = svg;
120
- W.icons[n] = W.icons[n] || svg;
117
+ if (svg && svg.includes('<')) {
118
+ W.icons[`@${prefix}/${n}`] = svg;
119
+ W.icons[`${prefix}:${n}`] = svg;
120
+ W.icons[`${prefix}/${n}`] = svg;
121
+ W.icons[n] = W.icons[n] || svg;
122
+ } else if (d.cdn_url) {
123
+ // User-uploaded icon: fetch SVG from CDN and store in W.icons
124
+ // so loader refresh() finds it and doesn't fetch individually
125
+ cdnFetches.push(
126
+ fetch(d.cdn_url)
127
+ .then(r => r.ok ? r.text() : '')
128
+ .then(s => {
129
+ if (s && s.includes('<')) {
130
+ W.icons[`@${prefix}/${n}`] = s;
131
+ W.icons[`${prefix}:${n}`] = s;
132
+ W.icons[`${prefix}/${n}`] = s;
133
+ W.icons[n] = W.icons[n] || s;
134
+ }
135
+ })
136
+ .catch(() => {})
137
+ );
138
+ }
121
139
  }
122
- try { document.dispatchEvent(new CustomEvent('viconic:ready', { detail: { prefix, kitId } })); } catch(e) {}
140
+ Promise.all(cdnFetches).then(() => {
141
+ try { document.dispatchEvent(new CustomEvent('viconic:ready', { detail: { prefix, kitId } })); } catch(e) {}
142
+ });
123
143
  })
124
144
  .catch(() => {});
125
145
  }, 150);