viconic-react-icons 1.1.8 → 1.4.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 +70 -40
- package/dist/index.mjs +70 -40
- package/package.json +1 -1
- package/src/copyicons-smart-loader.js +5 -5
- package/src/index.jsx +96 -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
|
+
function tryInjectFromEvent() {
|
|
2065
|
+
if (isInjected()) return;
|
|
2066
|
+
const W = window.__viconic;
|
|
2067
|
+
if (W && W.icons) {
|
|
2068
|
+
const iconBaseName = prefixMatch ? prefixMatch[2] : null;
|
|
2069
|
+
const svg = iconBaseName && W.icons[iconBaseName] || name && W.icons[name] || null;
|
|
2070
|
+
if (svg) {
|
|
2071
|
+
el.innerHTML = svg;
|
|
2072
|
+
el.classList.add("vi-ok", "svg-loaded");
|
|
2073
|
+
return;
|
|
2074
|
+
}
|
|
2051
2075
|
}
|
|
2052
2076
|
if (el._u) el._u();
|
|
2053
|
-
if (window.CopyIcons && window.CopyIcons.forceProcess
|
|
2077
|
+
if (!isKitIcon && window.CopyIcons && window.CopyIcons.forceProcess) {
|
|
2054
2078
|
window.CopyIcons.forceProcess(el);
|
|
2055
2079
|
}
|
|
2056
|
-
|
|
2057
|
-
|
|
2080
|
+
}
|
|
2081
|
+
document.addEventListener("viconic:ready", tryInjectFromEvent);
|
|
2082
|
+
const fallbackTimer = setTimeout(() => {
|
|
2083
|
+
if (isInjected()) return;
|
|
2084
|
+
tryInjectFromEvent();
|
|
2085
|
+
if (!isInjected() && isKitIcon && prefixMatch) {
|
|
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,11 @@ var ViconicIcon = ({ name, className, style, size, color, ...props }) => {
|
|
|
2066
2094
|
}
|
|
2067
2095
|
}
|
|
2068
2096
|
}
|
|
2069
|
-
|
|
2070
|
-
|
|
2071
|
-
|
|
2097
|
+
}, 500);
|
|
2098
|
+
return () => {
|
|
2099
|
+
document.removeEventListener("viconic:ready", tryInjectFromEvent);
|
|
2100
|
+
clearTimeout(fallbackTimer);
|
|
2101
|
+
};
|
|
2072
2102
|
}, [name, className, size, color, style]);
|
|
2073
2103
|
const combinedStyle = {
|
|
2074
2104
|
...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
|
+
function tryInjectFromEvent() {
|
|
2030
|
+
if (isInjected()) return;
|
|
2031
|
+
const W = window.__viconic;
|
|
2032
|
+
if (W && W.icons) {
|
|
2033
|
+
const iconBaseName = prefixMatch ? prefixMatch[2] : null;
|
|
2034
|
+
const svg = iconBaseName && W.icons[iconBaseName] || name && W.icons[name] || null;
|
|
2035
|
+
if (svg) {
|
|
2036
|
+
el.innerHTML = svg;
|
|
2037
|
+
el.classList.add("vi-ok", "svg-loaded");
|
|
2038
|
+
return;
|
|
2039
|
+
}
|
|
2016
2040
|
}
|
|
2017
2041
|
if (el._u) el._u();
|
|
2018
|
-
if (window.CopyIcons && window.CopyIcons.forceProcess
|
|
2042
|
+
if (!isKitIcon && window.CopyIcons && window.CopyIcons.forceProcess) {
|
|
2019
2043
|
window.CopyIcons.forceProcess(el);
|
|
2020
2044
|
}
|
|
2021
|
-
|
|
2022
|
-
|
|
2045
|
+
}
|
|
2046
|
+
document.addEventListener("viconic:ready", tryInjectFromEvent);
|
|
2047
|
+
const fallbackTimer = setTimeout(() => {
|
|
2048
|
+
if (isInjected()) return;
|
|
2049
|
+
tryInjectFromEvent();
|
|
2050
|
+
if (!isInjected() && isKitIcon && prefixMatch) {
|
|
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,11 @@ var ViconicIcon = ({ name, className, style, size, color, ...props }) => {
|
|
|
2031
2059
|
}
|
|
2032
2060
|
}
|
|
2033
2061
|
}
|
|
2034
|
-
|
|
2035
|
-
|
|
2036
|
-
|
|
2062
|
+
}, 500);
|
|
2063
|
+
return () => {
|
|
2064
|
+
document.removeEventListener("viconic:ready", tryInjectFromEvent);
|
|
2065
|
+
clearTimeout(fallbackTimer);
|
|
2066
|
+
};
|
|
2037
2067
|
}, [name, className, size, color, style]);
|
|
2038
2068
|
const combinedStyle = {
|
|
2039
2069
|
...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,83 @@ 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
|
+
}
|
|
114
139
|
}
|
|
115
140
|
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
141
|
+
// --- PATH 3: Custom element _u() call (kit loader registered element) ---
|
|
142
|
+
if (!isInjected() && el._u) {
|
|
143
|
+
el._u();
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
if (isInjected()) return;
|
|
147
|
+
|
|
148
|
+
// --- PATH 4: Event-driven — listen for viconic:ready fired by kit loader after register() ---
|
|
149
|
+
// Much faster than polling: icons appear the instant the loader finishes fetching them.
|
|
150
|
+
function tryInjectFromEvent() {
|
|
151
|
+
if (isInjected()) return;
|
|
152
|
+
const W = window.__viconic;
|
|
153
|
+
if (W && W.icons) {
|
|
154
|
+
const iconBaseName = prefixMatch ? prefixMatch[2] : null;
|
|
155
|
+
const svg = (iconBaseName && W.icons[iconBaseName])
|
|
156
|
+
|| (name && W.icons[name])
|
|
157
|
+
|| null;
|
|
158
|
+
if (svg) {
|
|
159
|
+
el.innerHTML = svg;
|
|
160
|
+
el.classList.add('vi-ok', 'svg-loaded');
|
|
161
|
+
return;
|
|
162
|
+
}
|
|
127
163
|
}
|
|
128
|
-
// Trigger custom element update
|
|
129
164
|
if (el._u) el._u();
|
|
130
|
-
|
|
131
|
-
if (window.CopyIcons && window.CopyIcons.forceProcess && !isKitIcon) {
|
|
165
|
+
if (!isKitIcon && window.CopyIcons && window.CopyIcons.forceProcess) {
|
|
132
166
|
window.CopyIcons.forceProcess(el);
|
|
133
167
|
}
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
document.addEventListener('viconic:ready', tryInjectFromEvent);
|
|
171
|
+
|
|
172
|
+
// --- PATH 5: Short-deadline fallback (500ms) in case script already fired before we listened ---
|
|
173
|
+
const fallbackTimer = setTimeout(() => {
|
|
174
|
+
if (isInjected()) return;
|
|
175
|
+
tryInjectFromEvent();
|
|
176
|
+
// If still not loaded after 500ms, trigger kit reload once
|
|
177
|
+
if (!isInjected() && isKitIcon && prefixMatch) {
|
|
138
178
|
const prefix = prefixMatch[1];
|
|
139
179
|
if (window.CopyIconsKit) {
|
|
140
|
-
for (const
|
|
141
|
-
const kit = window.CopyIconsKit[
|
|
180
|
+
for (const kId in window.CopyIconsKit) {
|
|
181
|
+
const kit = window.CopyIconsKit[kId];
|
|
142
182
|
if (kit.config && kit.config.prefix === prefix && typeof kit.reload === 'function') {
|
|
143
183
|
kit.reload();
|
|
144
184
|
break;
|
|
@@ -146,11 +186,12 @@ export const ViconicIcon = ({ name, className, style, size, color, ...props }) =
|
|
|
146
186
|
}
|
|
147
187
|
}
|
|
148
188
|
}
|
|
149
|
-
|
|
150
|
-
if (retries >= maxRetries) clearInterval(timer);
|
|
151
|
-
}, 100);
|
|
189
|
+
}, 500);
|
|
152
190
|
|
|
153
|
-
return () =>
|
|
191
|
+
return () => {
|
|
192
|
+
document.removeEventListener('viconic:ready', tryInjectFromEvent);
|
|
193
|
+
clearTimeout(fallbackTimer);
|
|
194
|
+
};
|
|
154
195
|
}, [name, className, size, color, style]);
|
|
155
196
|
|
|
156
197
|
const combinedStyle = {
|