viconic-react-icons 1.1.8 → 1.3.0
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 +75 -40
- package/dist/index.mjs +75 -40
- package/package.json +1 -1
- package/src/copyicons-smart-loader.js +5 -5
- package/src/index.jsx +105 -55
package/dist/index.js
CHANGED
|
@@ -1978,6 +1978,30 @@ var import_react = __toESM(require("react"));
|
|
|
1978
1978
|
})();
|
|
1979
1979
|
|
|
1980
1980
|
// src/index.jsx
|
|
1981
|
+
(function _preloadKitCache() {
|
|
1982
|
+
if (typeof window === "undefined" || typeof localStorage === "undefined") return;
|
|
1983
|
+
try {
|
|
1984
|
+
const W = window.__viconic = window.__viconic || {};
|
|
1985
|
+
W.icons = W.icons || {};
|
|
1986
|
+
const TTL = 3 * 24 * 60 * 60 * 1e3;
|
|
1987
|
+
for (let i = 0; i < localStorage.length; i++) {
|
|
1988
|
+
const key = localStorage.key(i);
|
|
1989
|
+
if (!key || !key.startsWith("viconic:")) continue;
|
|
1990
|
+
try {
|
|
1991
|
+
const c = JSON.parse(localStorage.getItem(key));
|
|
1992
|
+
if (c && c.d && Date.now() - c.t < TTL) {
|
|
1993
|
+
for (const n in c.d) {
|
|
1994
|
+
if (!Object.prototype.hasOwnProperty.call(c.d, n)) continue;
|
|
1995
|
+
const svg = c.d[n];
|
|
1996
|
+
if (!W.icons[n]) W.icons[n] = svg;
|
|
1997
|
+
}
|
|
1998
|
+
}
|
|
1999
|
+
} catch (e) {
|
|
2000
|
+
}
|
|
2001
|
+
}
|
|
2002
|
+
} catch (e) {
|
|
2003
|
+
}
|
|
2004
|
+
})();
|
|
1981
2005
|
var _initializedKits = /* @__PURE__ */ new Set();
|
|
1982
2006
|
function initViconic(options = {}) {
|
|
1983
2007
|
const { kitId, cdnBase = "cdn.viconic.dev", version } = options;
|
|
@@ -2013,52 +2037,56 @@ var ViconicIcon = ({ name, className, style, size, color, ...props }) => {
|
|
|
2013
2037
|
prevNameRef.current = name;
|
|
2014
2038
|
}
|
|
2015
2039
|
const isKitIcon = name && name.startsWith("@");
|
|
2016
|
-
|
|
2017
|
-
|
|
2018
|
-
|
|
2019
|
-
|
|
2020
|
-
|
|
2021
|
-
|
|
2022
|
-
|
|
2023
|
-
|
|
2024
|
-
|
|
2025
|
-
|
|
2026
|
-
|
|
2027
|
-
|
|
2028
|
-
if (raw) {
|
|
2029
|
-
const c = JSON.parse(raw);
|
|
2030
|
-
if (c && c.d && c.d[iconBaseName]) {
|
|
2031
|
-
el.innerHTML = c.d[iconBaseName];
|
|
2032
|
-
el.classList.add("vi-ok", "svg-loaded");
|
|
2033
|
-
isLoaded = true;
|
|
2034
|
-
break;
|
|
2035
|
-
}
|
|
2036
|
-
}
|
|
2037
|
-
}
|
|
2040
|
+
const prefixMatch = isKitIcon ? name.match(/^@([^/]+)\/(.+)$/) : null;
|
|
2041
|
+
function isInjected() {
|
|
2042
|
+
return el.classList.contains("vi-ok") || el.classList.contains("svg-loaded");
|
|
2043
|
+
}
|
|
2044
|
+
if (!isInjected()) {
|
|
2045
|
+
const W = window.__viconic;
|
|
2046
|
+
if (W && W.icons) {
|
|
2047
|
+
const iconBaseName = prefixMatch ? prefixMatch[2] : null;
|
|
2048
|
+
const svg = iconBaseName && W.icons[iconBaseName] || name && W.icons[name] || null;
|
|
2049
|
+
if (svg) {
|
|
2050
|
+
el.innerHTML = svg;
|
|
2051
|
+
el.classList.add("vi-ok", "svg-loaded");
|
|
2038
2052
|
}
|
|
2039
|
-
} catch (e) {
|
|
2040
2053
|
}
|
|
2041
2054
|
}
|
|
2042
|
-
if (
|
|
2043
|
-
|
|
2044
|
-
|
|
2045
|
-
|
|
2046
|
-
|
|
2047
|
-
|
|
2048
|
-
|
|
2049
|
-
|
|
2050
|
-
|
|
2055
|
+
if (!isInjected() && !isKitIcon) {
|
|
2056
|
+
if (window.CopyIcons && window.CopyIcons.forceProcess) {
|
|
2057
|
+
window.CopyIcons.forceProcess(el);
|
|
2058
|
+
}
|
|
2059
|
+
}
|
|
2060
|
+
if (!isInjected() && el._u) {
|
|
2061
|
+
el._u();
|
|
2062
|
+
}
|
|
2063
|
+
if (isInjected()) return;
|
|
2064
|
+
const delays = [50, 100, 200, 400, 800, 500, 500, 500, 500, 500, 500, 500];
|
|
2065
|
+
let attempt = 0;
|
|
2066
|
+
let timerId = null;
|
|
2067
|
+
let reloadTriggered = false;
|
|
2068
|
+
function tryInject() {
|
|
2069
|
+
if (isInjected()) return;
|
|
2070
|
+
const W = window.__viconic;
|
|
2071
|
+
if (W && W.icons) {
|
|
2072
|
+
const iconBaseName = prefixMatch ? prefixMatch[2] : null;
|
|
2073
|
+
const svg = iconBaseName && W.icons[iconBaseName] || name && W.icons[name] || null;
|
|
2074
|
+
if (svg) {
|
|
2075
|
+
el.innerHTML = svg;
|
|
2076
|
+
el.classList.add("vi-ok", "svg-loaded");
|
|
2077
|
+
return;
|
|
2078
|
+
}
|
|
2051
2079
|
}
|
|
2052
2080
|
if (el._u) el._u();
|
|
2053
|
-
if (window.CopyIcons && window.CopyIcons.forceProcess
|
|
2081
|
+
if (!isKitIcon && window.CopyIcons && window.CopyIcons.forceProcess) {
|
|
2054
2082
|
window.CopyIcons.forceProcess(el);
|
|
2055
2083
|
}
|
|
2056
|
-
if (isKitIcon && !
|
|
2057
|
-
|
|
2084
|
+
if (isKitIcon && !reloadTriggered && attempt >= 4 && prefixMatch) {
|
|
2085
|
+
reloadTriggered = true;
|
|
2058
2086
|
const prefix = prefixMatch[1];
|
|
2059
2087
|
if (window.CopyIconsKit) {
|
|
2060
|
-
for (const
|
|
2061
|
-
const kit = window.CopyIconsKit[
|
|
2088
|
+
for (const kId in window.CopyIconsKit) {
|
|
2089
|
+
const kit = window.CopyIconsKit[kId];
|
|
2062
2090
|
if (kit.config && kit.config.prefix === prefix && typeof kit.reload === "function") {
|
|
2063
2091
|
kit.reload();
|
|
2064
2092
|
break;
|
|
@@ -2066,9 +2094,16 @@ var ViconicIcon = ({ name, className, style, size, color, ...props }) => {
|
|
|
2066
2094
|
}
|
|
2067
2095
|
}
|
|
2068
2096
|
}
|
|
2069
|
-
if (
|
|
2070
|
-
|
|
2071
|
-
|
|
2097
|
+
if (isInjected()) return;
|
|
2098
|
+
attempt++;
|
|
2099
|
+
if (attempt < delays.length) {
|
|
2100
|
+
timerId = setTimeout(tryInject, delays[attempt]);
|
|
2101
|
+
}
|
|
2102
|
+
}
|
|
2103
|
+
timerId = setTimeout(tryInject, delays[0]);
|
|
2104
|
+
return () => {
|
|
2105
|
+
if (timerId) clearTimeout(timerId);
|
|
2106
|
+
};
|
|
2072
2107
|
}, [name, className, size, color, style]);
|
|
2073
2108
|
const combinedStyle = {
|
|
2074
2109
|
...size ? { fontSize: size } : {},
|
package/dist/index.mjs
CHANGED
|
@@ -1943,6 +1943,30 @@ import React, { useEffect, useRef } from "react";
|
|
|
1943
1943
|
})();
|
|
1944
1944
|
|
|
1945
1945
|
// src/index.jsx
|
|
1946
|
+
(function _preloadKitCache() {
|
|
1947
|
+
if (typeof window === "undefined" || typeof localStorage === "undefined") return;
|
|
1948
|
+
try {
|
|
1949
|
+
const W = window.__viconic = window.__viconic || {};
|
|
1950
|
+
W.icons = W.icons || {};
|
|
1951
|
+
const TTL = 3 * 24 * 60 * 60 * 1e3;
|
|
1952
|
+
for (let i = 0; i < localStorage.length; i++) {
|
|
1953
|
+
const key = localStorage.key(i);
|
|
1954
|
+
if (!key || !key.startsWith("viconic:")) continue;
|
|
1955
|
+
try {
|
|
1956
|
+
const c = JSON.parse(localStorage.getItem(key));
|
|
1957
|
+
if (c && c.d && Date.now() - c.t < TTL) {
|
|
1958
|
+
for (const n in c.d) {
|
|
1959
|
+
if (!Object.prototype.hasOwnProperty.call(c.d, n)) continue;
|
|
1960
|
+
const svg = c.d[n];
|
|
1961
|
+
if (!W.icons[n]) W.icons[n] = svg;
|
|
1962
|
+
}
|
|
1963
|
+
}
|
|
1964
|
+
} catch (e) {
|
|
1965
|
+
}
|
|
1966
|
+
}
|
|
1967
|
+
} catch (e) {
|
|
1968
|
+
}
|
|
1969
|
+
})();
|
|
1946
1970
|
var _initializedKits = /* @__PURE__ */ new Set();
|
|
1947
1971
|
function initViconic(options = {}) {
|
|
1948
1972
|
const { kitId, cdnBase = "cdn.viconic.dev", version } = options;
|
|
@@ -1978,52 +2002,56 @@ var ViconicIcon = ({ name, className, style, size, color, ...props }) => {
|
|
|
1978
2002
|
prevNameRef.current = name;
|
|
1979
2003
|
}
|
|
1980
2004
|
const isKitIcon = name && name.startsWith("@");
|
|
1981
|
-
|
|
1982
|
-
|
|
1983
|
-
|
|
1984
|
-
|
|
1985
|
-
|
|
1986
|
-
|
|
1987
|
-
|
|
1988
|
-
|
|
1989
|
-
|
|
1990
|
-
|
|
1991
|
-
|
|
1992
|
-
|
|
1993
|
-
if (raw) {
|
|
1994
|
-
const c = JSON.parse(raw);
|
|
1995
|
-
if (c && c.d && c.d[iconBaseName]) {
|
|
1996
|
-
el.innerHTML = c.d[iconBaseName];
|
|
1997
|
-
el.classList.add("vi-ok", "svg-loaded");
|
|
1998
|
-
isLoaded = true;
|
|
1999
|
-
break;
|
|
2000
|
-
}
|
|
2001
|
-
}
|
|
2002
|
-
}
|
|
2005
|
+
const prefixMatch = isKitIcon ? name.match(/^@([^/]+)\/(.+)$/) : null;
|
|
2006
|
+
function isInjected() {
|
|
2007
|
+
return el.classList.contains("vi-ok") || el.classList.contains("svg-loaded");
|
|
2008
|
+
}
|
|
2009
|
+
if (!isInjected()) {
|
|
2010
|
+
const W = window.__viconic;
|
|
2011
|
+
if (W && W.icons) {
|
|
2012
|
+
const iconBaseName = prefixMatch ? prefixMatch[2] : null;
|
|
2013
|
+
const svg = iconBaseName && W.icons[iconBaseName] || name && W.icons[name] || null;
|
|
2014
|
+
if (svg) {
|
|
2015
|
+
el.innerHTML = svg;
|
|
2016
|
+
el.classList.add("vi-ok", "svg-loaded");
|
|
2003
2017
|
}
|
|
2004
|
-
} catch (e) {
|
|
2005
2018
|
}
|
|
2006
2019
|
}
|
|
2007
|
-
if (
|
|
2008
|
-
|
|
2009
|
-
|
|
2010
|
-
|
|
2011
|
-
|
|
2012
|
-
|
|
2013
|
-
|
|
2014
|
-
|
|
2015
|
-
|
|
2020
|
+
if (!isInjected() && !isKitIcon) {
|
|
2021
|
+
if (window.CopyIcons && window.CopyIcons.forceProcess) {
|
|
2022
|
+
window.CopyIcons.forceProcess(el);
|
|
2023
|
+
}
|
|
2024
|
+
}
|
|
2025
|
+
if (!isInjected() && el._u) {
|
|
2026
|
+
el._u();
|
|
2027
|
+
}
|
|
2028
|
+
if (isInjected()) return;
|
|
2029
|
+
const delays = [50, 100, 200, 400, 800, 500, 500, 500, 500, 500, 500, 500];
|
|
2030
|
+
let attempt = 0;
|
|
2031
|
+
let timerId = null;
|
|
2032
|
+
let reloadTriggered = false;
|
|
2033
|
+
function tryInject() {
|
|
2034
|
+
if (isInjected()) return;
|
|
2035
|
+
const W = window.__viconic;
|
|
2036
|
+
if (W && W.icons) {
|
|
2037
|
+
const iconBaseName = prefixMatch ? prefixMatch[2] : null;
|
|
2038
|
+
const svg = iconBaseName && W.icons[iconBaseName] || name && W.icons[name] || null;
|
|
2039
|
+
if (svg) {
|
|
2040
|
+
el.innerHTML = svg;
|
|
2041
|
+
el.classList.add("vi-ok", "svg-loaded");
|
|
2042
|
+
return;
|
|
2043
|
+
}
|
|
2016
2044
|
}
|
|
2017
2045
|
if (el._u) el._u();
|
|
2018
|
-
if (window.CopyIcons && window.CopyIcons.forceProcess
|
|
2046
|
+
if (!isKitIcon && window.CopyIcons && window.CopyIcons.forceProcess) {
|
|
2019
2047
|
window.CopyIcons.forceProcess(el);
|
|
2020
2048
|
}
|
|
2021
|
-
if (isKitIcon && !
|
|
2022
|
-
|
|
2049
|
+
if (isKitIcon && !reloadTriggered && attempt >= 4 && prefixMatch) {
|
|
2050
|
+
reloadTriggered = true;
|
|
2023
2051
|
const prefix = prefixMatch[1];
|
|
2024
2052
|
if (window.CopyIconsKit) {
|
|
2025
|
-
for (const
|
|
2026
|
-
const kit = window.CopyIconsKit[
|
|
2053
|
+
for (const kId in window.CopyIconsKit) {
|
|
2054
|
+
const kit = window.CopyIconsKit[kId];
|
|
2027
2055
|
if (kit.config && kit.config.prefix === prefix && typeof kit.reload === "function") {
|
|
2028
2056
|
kit.reload();
|
|
2029
2057
|
break;
|
|
@@ -2031,9 +2059,16 @@ var ViconicIcon = ({ name, className, style, size, color, ...props }) => {
|
|
|
2031
2059
|
}
|
|
2032
2060
|
}
|
|
2033
2061
|
}
|
|
2034
|
-
if (
|
|
2035
|
-
|
|
2036
|
-
|
|
2062
|
+
if (isInjected()) return;
|
|
2063
|
+
attempt++;
|
|
2064
|
+
if (attempt < delays.length) {
|
|
2065
|
+
timerId = setTimeout(tryInject, delays[attempt]);
|
|
2066
|
+
}
|
|
2067
|
+
}
|
|
2068
|
+
timerId = setTimeout(tryInject, delays[0]);
|
|
2069
|
+
return () => {
|
|
2070
|
+
if (timerId) clearTimeout(timerId);
|
|
2071
|
+
};
|
|
2037
2072
|
}, [name, className, size, color, style]);
|
|
2038
2073
|
const combinedStyle = {
|
|
2039
2074
|
...size ? { fontSize: size } : {},
|
package/package.json
CHANGED
|
@@ -51,12 +51,12 @@
|
|
|
51
51
|
// already successfully injected. We intercept define() to patch _u()
|
|
52
52
|
// so it skips elements that Smart Loader has already handled.
|
|
53
53
|
const _origCEDefine = customElements.define.bind(customElements);
|
|
54
|
-
customElements.define = function(name, cls, opts) {
|
|
54
|
+
customElements.define = function (name, cls, opts) {
|
|
55
55
|
if (name === 'viconic-icon' && cls && cls.prototype) {
|
|
56
56
|
// Patch _u() to skip elements already handled by Smart Loader
|
|
57
57
|
if (cls.prototype._u) {
|
|
58
58
|
const origU = cls.prototype._u;
|
|
59
|
-
cls.prototype._u = function() {
|
|
59
|
+
cls.prototype._u = function () {
|
|
60
60
|
if (this.classList.contains('svg-loaded')) return;
|
|
61
61
|
return origU.call(this);
|
|
62
62
|
};
|
|
@@ -64,7 +64,7 @@
|
|
|
64
64
|
// Patch connectedCallback to also guard svg-loaded
|
|
65
65
|
if (cls.prototype.connectedCallback) {
|
|
66
66
|
const origCC = cls.prototype.connectedCallback;
|
|
67
|
-
cls.prototype.connectedCallback = function() {
|
|
67
|
+
cls.prototype.connectedCallback = function () {
|
|
68
68
|
if (this.classList.contains('svg-loaded')) return;
|
|
69
69
|
return origCC.call(this);
|
|
70
70
|
};
|
|
@@ -771,13 +771,13 @@
|
|
|
771
771
|
const fillStyle = (originalFill === 'none') ? 'none' : 'currentColor';
|
|
772
772
|
svg.style.cssText = `width:1em;height:1em;fill:${fillStyle};display:inline-block;vertical-align:middle;`;
|
|
773
773
|
}
|
|
774
|
-
|
|
774
|
+
|
|
775
775
|
if (element.getAttribute('animate') === 'trace') {
|
|
776
776
|
const isStrokeBased = (originalFill === 'none');
|
|
777
777
|
svg.style.setProperty('--trace-end-stroke', isStrokeBased ? 'currentColor' : 'transparent');
|
|
778
778
|
svg.style.setProperty('--trace-end-stroke-width', isStrokeBased ? (svg.getAttribute('stroke-width') || '2px') : '0px');
|
|
779
779
|
svg.style.setProperty('--trace-stroke-width', isStrokeBased ? (svg.getAttribute('stroke-width') || '2px') : '1px');
|
|
780
|
-
|
|
780
|
+
|
|
781
781
|
const paths = svg.querySelectorAll('path, ellipse, circle, rect, polygon, polyline');
|
|
782
782
|
for (let i = 0; i < paths.length; i++) {
|
|
783
783
|
const p = paths[i];
|
package/src/index.jsx
CHANGED
|
@@ -1,6 +1,36 @@
|
|
|
1
1
|
import React, { useEffect, useRef } from 'react';
|
|
2
2
|
import './copyicons-smart-loader.js';
|
|
3
3
|
|
|
4
|
+
// ============================================
|
|
5
|
+
// PRE-LOAD KIT CACHE SYNCHRONOUSLY AT MODULE LEVEL
|
|
6
|
+
// Same architecture as kit loader: read localStorage before any render
|
|
7
|
+
// so icons are available instantly when components mount.
|
|
8
|
+
// ============================================
|
|
9
|
+
(function _preloadKitCache() {
|
|
10
|
+
if (typeof window === 'undefined' || typeof localStorage === 'undefined') return;
|
|
11
|
+
try {
|
|
12
|
+
const W = (window.__viconic = window.__viconic || {});
|
|
13
|
+
W.icons = W.icons || {};
|
|
14
|
+
const TTL = 3 * 24 * 60 * 60 * 1000; // 3 days
|
|
15
|
+
for (let i = 0; i < localStorage.length; i++) {
|
|
16
|
+
const key = localStorage.key(i);
|
|
17
|
+
if (!key || !key.startsWith('viconic:')) continue;
|
|
18
|
+
try {
|
|
19
|
+
const c = JSON.parse(localStorage.getItem(key));
|
|
20
|
+
if (c && c.d && Date.now() - c.t < TTL) {
|
|
21
|
+
// Register all icon name variants into W.icons
|
|
22
|
+
for (const n in c.d) {
|
|
23
|
+
if (!Object.prototype.hasOwnProperty.call(c.d, n)) continue;
|
|
24
|
+
const svg = c.d[n];
|
|
25
|
+
// Store by plain name so _u() can find it regardless of prefix
|
|
26
|
+
if (!W.icons[n]) W.icons[n] = svg;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
} catch (e) { /* corrupted entry, skip */ }
|
|
30
|
+
}
|
|
31
|
+
} catch (e) { }
|
|
32
|
+
})();
|
|
33
|
+
|
|
4
34
|
// ============================================
|
|
5
35
|
// Track initialized kits to avoid duplicate scripts
|
|
6
36
|
// ============================================
|
|
@@ -37,14 +67,14 @@ export function initViconic(options = {}) {
|
|
|
37
67
|
|
|
38
68
|
const script = document.createElement('script');
|
|
39
69
|
script.id = scriptId;
|
|
40
|
-
|
|
70
|
+
|
|
41
71
|
// Add cache busting for development or specific version updates
|
|
42
72
|
let url = `https://${cdnBase}/kits/${kitId}/loader.js`;
|
|
43
73
|
if (version) {
|
|
44
74
|
const vQuery = version === 'dev' ? Date.now() : version;
|
|
45
75
|
url += `?v=${vQuery}`;
|
|
46
76
|
}
|
|
47
|
-
|
|
77
|
+
|
|
48
78
|
script.src = url;
|
|
49
79
|
script.async = true;
|
|
50
80
|
document.head.appendChild(script);
|
|
@@ -72,73 +102,87 @@ export const ViconicIcon = ({ name, className, style, size, color, ...props }) =
|
|
|
72
102
|
if (!el) return;
|
|
73
103
|
|
|
74
104
|
// --- FIX DOM REUSE (Reconciliation) ---
|
|
75
|
-
// React reuses DOM nodes. If `name` changes, we must wipe the old state
|
|
76
|
-
// because the DOM node might still have 'svg-loaded' or 'vi-ok'.
|
|
77
105
|
if (prevNameRef.current !== name) {
|
|
78
106
|
el.innerHTML = '';
|
|
79
107
|
el.classList.remove('vi-ok', 'svg-loaded', 'vi-mono', 'ci-multicolor');
|
|
80
108
|
prevNameRef.current = name;
|
|
81
109
|
}
|
|
82
110
|
|
|
83
|
-
// Path 1: Smart loader (system icons with prefix:name format)
|
|
84
111
|
const isKitIcon = name && name.startsWith('@');
|
|
85
|
-
|
|
86
|
-
window.CopyIcons.forceProcess(el);
|
|
87
|
-
}
|
|
112
|
+
const prefixMatch = isKitIcon ? name.match(/^@([^/]+)\/(.+)$/) : null;
|
|
88
113
|
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
let isLoaded = el.classList.contains('vi-ok') || el.classList.contains('svg-loaded');
|
|
93
|
-
const prefixMatch = isKitIcon ? name.match(/^@([^\/]+)\/(.+)$/) : null;
|
|
114
|
+
function isInjected() {
|
|
115
|
+
return el.classList.contains('vi-ok') || el.classList.contains('svg-loaded');
|
|
116
|
+
}
|
|
94
117
|
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
isLoaded = true;
|
|
108
|
-
break;
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
}
|
|
118
|
+
// --- PATH 1: Synchronous inject from W.icons (pre-loaded from localStorage at module init) ---
|
|
119
|
+
if (!isInjected()) {
|
|
120
|
+
const W = window.__viconic;
|
|
121
|
+
if (W && W.icons) {
|
|
122
|
+
// Try all key variants: iconBaseName, @prefix/name, prefix:name, prefix/name
|
|
123
|
+
const iconBaseName = prefixMatch ? prefixMatch[2] : null;
|
|
124
|
+
const svg = (iconBaseName && W.icons[iconBaseName])
|
|
125
|
+
|| (name && W.icons[name])
|
|
126
|
+
|| null;
|
|
127
|
+
if (svg) {
|
|
128
|
+
el.innerHTML = svg;
|
|
129
|
+
el.classList.add('vi-ok', 'svg-loaded');
|
|
112
130
|
}
|
|
113
|
-
}
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
// --- PATH 2: Smart loader for system icons (prefix:name) ---
|
|
135
|
+
if (!isInjected() && !isKitIcon) {
|
|
136
|
+
if (window.CopyIcons && window.CopyIcons.forceProcess) {
|
|
137
|
+
window.CopyIcons.forceProcess(el);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
// --- PATH 3: Custom element _u() call (kit loader registered element) ---
|
|
142
|
+
if (!isInjected() && el._u) {
|
|
143
|
+
el._u();
|
|
114
144
|
}
|
|
115
145
|
|
|
116
|
-
if (
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
146
|
+
if (isInjected()) return;
|
|
147
|
+
|
|
148
|
+
// --- PATH 4: Fallback retry — kit loader script may still be loading async ---
|
|
149
|
+
// Use short exponential backoff: 50ms, 100ms, 200ms, 400ms, 800ms, then every 500ms
|
|
150
|
+
// Max 8 seconds total. Much cheaper than 100 × 100ms polling.
|
|
151
|
+
const delays = [50, 100, 200, 400, 800, 500, 500, 500, 500, 500, 500, 500];
|
|
152
|
+
let attempt = 0;
|
|
153
|
+
let timerId = null;
|
|
154
|
+
let reloadTriggered = false;
|
|
155
|
+
|
|
156
|
+
function tryInject() {
|
|
157
|
+
if (isInjected()) return;
|
|
158
|
+
|
|
159
|
+
// Try W.icons again (kit may have loaded by now)
|
|
160
|
+
const W = window.__viconic;
|
|
161
|
+
if (W && W.icons) {
|
|
162
|
+
const iconBaseName = prefixMatch ? prefixMatch[2] : null;
|
|
163
|
+
const svg = (iconBaseName && W.icons[iconBaseName])
|
|
164
|
+
|| (name && W.icons[name])
|
|
165
|
+
|| null;
|
|
166
|
+
if (svg) {
|
|
167
|
+
el.innerHTML = svg;
|
|
168
|
+
el.classList.add('vi-ok', 'svg-loaded');
|
|
169
|
+
return;
|
|
170
|
+
}
|
|
127
171
|
}
|
|
128
|
-
|
|
172
|
+
|
|
173
|
+
// Try custom element _u()
|
|
129
174
|
if (el._u) el._u();
|
|
130
|
-
|
|
131
|
-
if (window.CopyIcons && window.CopyIcons.forceProcess && !isKitIcon) {
|
|
175
|
+
if (!isKitIcon && window.CopyIcons && window.CopyIcons.forceProcess) {
|
|
132
176
|
window.CopyIcons.forceProcess(el);
|
|
133
177
|
}
|
|
134
|
-
|
|
135
|
-
//
|
|
136
|
-
if (isKitIcon && !
|
|
137
|
-
|
|
178
|
+
|
|
179
|
+
// Trigger kit reload once if still not loaded after ~1s
|
|
180
|
+
if (isKitIcon && !reloadTriggered && attempt >= 4 && prefixMatch) {
|
|
181
|
+
reloadTriggered = true;
|
|
138
182
|
const prefix = prefixMatch[1];
|
|
139
183
|
if (window.CopyIconsKit) {
|
|
140
|
-
for (const
|
|
141
|
-
const kit = window.CopyIconsKit[
|
|
184
|
+
for (const kId in window.CopyIconsKit) {
|
|
185
|
+
const kit = window.CopyIconsKit[kId];
|
|
142
186
|
if (kit.config && kit.config.prefix === prefix && typeof kit.reload === 'function') {
|
|
143
187
|
kit.reload();
|
|
144
188
|
break;
|
|
@@ -146,11 +190,17 @@ export const ViconicIcon = ({ name, className, style, size, color, ...props }) =
|
|
|
146
190
|
}
|
|
147
191
|
}
|
|
148
192
|
}
|
|
149
|
-
|
|
150
|
-
if (retries >= maxRetries) clearInterval(timer);
|
|
151
|
-
}, 100);
|
|
152
193
|
|
|
153
|
-
|
|
194
|
+
if (isInjected()) return;
|
|
195
|
+
|
|
196
|
+
attempt++;
|
|
197
|
+
if (attempt < delays.length) {
|
|
198
|
+
timerId = setTimeout(tryInject, delays[attempt]);
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
timerId = setTimeout(tryInject, delays[0]);
|
|
203
|
+
return () => { if (timerId) clearTimeout(timerId); };
|
|
154
204
|
}, [name, className, size, color, style]);
|
|
155
205
|
|
|
156
206
|
const combinedStyle = {
|