viconic-react-icons 1.1.4 → 1.1.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 +22 -7
- package/dist/index.mjs +22 -7
- package/package.json +1 -1
- package/src/copyicons-smart-loader.js +18 -8
- package/src/index.jsx +10 -0
package/dist/index.js
CHANGED
|
@@ -45,7 +45,7 @@ var import_react = __toESM(require("react"));
|
|
|
45
45
|
}
|
|
46
46
|
if (typeof document !== "undefined") {
|
|
47
47
|
const style = document.createElement("style");
|
|
48
|
-
style.textContent = ":where(viconic-icon) { display: inline-flex; align-items: center; justify-content: center; width: 1em; height: 1em; font-size: inherit; line-height: 1; } :where(viconic-icon):not(.ci-multicolor) svg { width: 100%; height: 100%; display: block; fill: currentColor; } :where(viconic-icon).ci-multicolor svg { width: 100%; height: 100%; display: block; }";
|
|
48
|
+
style.textContent = ":where(viconic-icon) { display: inline-flex; align-items: center; justify-content: center; width: 1em; height: 1em; font-size: inherit; line-height: 1; } :where(viconic-icon):not(.ci-multicolor) svg { width: 100%; height: 100%; display: block; fill: currentColor; } :where(viconic-icon).ci-multicolor svg { width: 100%; height: 100%; display: block; } viconic-icon:not(.vi-ok):not(.svg-loaded) { animation: none !important; background: none !important; }";
|
|
49
49
|
if (document.head.firstChild) {
|
|
50
50
|
document.head.insertBefore(style, document.head.firstChild);
|
|
51
51
|
} else {
|
|
@@ -54,12 +54,21 @@ var import_react = __toESM(require("react"));
|
|
|
54
54
|
}
|
|
55
55
|
const _origCEDefine = customElements.define.bind(customElements);
|
|
56
56
|
customElements.define = function(name, cls, opts) {
|
|
57
|
-
if (name === "viconic-icon" && cls && cls.prototype
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
57
|
+
if (name === "viconic-icon" && cls && cls.prototype) {
|
|
58
|
+
if (cls.prototype._u) {
|
|
59
|
+
const origU = cls.prototype._u;
|
|
60
|
+
cls.prototype._u = function() {
|
|
61
|
+
if (this.classList.contains("svg-loaded")) return;
|
|
62
|
+
return origU.call(this);
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
if (cls.prototype.connectedCallback) {
|
|
66
|
+
const origCC = cls.prototype.connectedCallback;
|
|
67
|
+
cls.prototype.connectedCallback = function() {
|
|
68
|
+
if (this.classList.contains("svg-loaded")) return;
|
|
69
|
+
return origCC.call(this);
|
|
70
|
+
};
|
|
71
|
+
}
|
|
63
72
|
}
|
|
64
73
|
return _origCEDefine(name, cls, opts);
|
|
65
74
|
};
|
|
@@ -1994,9 +2003,15 @@ function initViconic(options = {}) {
|
|
|
1994
2003
|
}
|
|
1995
2004
|
var ViconicIcon = ({ name, className, style, size, color, ...props }) => {
|
|
1996
2005
|
const iconRef = (0, import_react.useRef)(null);
|
|
2006
|
+
const prevNameRef = (0, import_react.useRef)(name);
|
|
1997
2007
|
(0, import_react.useEffect)(() => {
|
|
1998
2008
|
const el = iconRef.current;
|
|
1999
2009
|
if (!el) return;
|
|
2010
|
+
if (prevNameRef.current !== name) {
|
|
2011
|
+
el.innerHTML = "";
|
|
2012
|
+
el.classList.remove("vi-ok", "svg-loaded", "vi-mono", "ci-multicolor");
|
|
2013
|
+
prevNameRef.current = name;
|
|
2014
|
+
}
|
|
2000
2015
|
const isKitIcon = name && name.startsWith("@");
|
|
2001
2016
|
if (window.CopyIcons && window.CopyIcons.forceProcess && !isKitIcon) {
|
|
2002
2017
|
window.CopyIcons.forceProcess(el);
|
package/dist/index.mjs
CHANGED
|
@@ -10,7 +10,7 @@ import React, { useEffect, useRef } from "react";
|
|
|
10
10
|
}
|
|
11
11
|
if (typeof document !== "undefined") {
|
|
12
12
|
const style = document.createElement("style");
|
|
13
|
-
style.textContent = ":where(viconic-icon) { display: inline-flex; align-items: center; justify-content: center; width: 1em; height: 1em; font-size: inherit; line-height: 1; } :where(viconic-icon):not(.ci-multicolor) svg { width: 100%; height: 100%; display: block; fill: currentColor; } :where(viconic-icon).ci-multicolor svg { width: 100%; height: 100%; display: block; }";
|
|
13
|
+
style.textContent = ":where(viconic-icon) { display: inline-flex; align-items: center; justify-content: center; width: 1em; height: 1em; font-size: inherit; line-height: 1; } :where(viconic-icon):not(.ci-multicolor) svg { width: 100%; height: 100%; display: block; fill: currentColor; } :where(viconic-icon).ci-multicolor svg { width: 100%; height: 100%; display: block; } viconic-icon:not(.vi-ok):not(.svg-loaded) { animation: none !important; background: none !important; }";
|
|
14
14
|
if (document.head.firstChild) {
|
|
15
15
|
document.head.insertBefore(style, document.head.firstChild);
|
|
16
16
|
} else {
|
|
@@ -19,12 +19,21 @@ import React, { useEffect, useRef } from "react";
|
|
|
19
19
|
}
|
|
20
20
|
const _origCEDefine = customElements.define.bind(customElements);
|
|
21
21
|
customElements.define = function(name, cls, opts) {
|
|
22
|
-
if (name === "viconic-icon" && cls && cls.prototype
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
22
|
+
if (name === "viconic-icon" && cls && cls.prototype) {
|
|
23
|
+
if (cls.prototype._u) {
|
|
24
|
+
const origU = cls.prototype._u;
|
|
25
|
+
cls.prototype._u = function() {
|
|
26
|
+
if (this.classList.contains("svg-loaded")) return;
|
|
27
|
+
return origU.call(this);
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
if (cls.prototype.connectedCallback) {
|
|
31
|
+
const origCC = cls.prototype.connectedCallback;
|
|
32
|
+
cls.prototype.connectedCallback = function() {
|
|
33
|
+
if (this.classList.contains("svg-loaded")) return;
|
|
34
|
+
return origCC.call(this);
|
|
35
|
+
};
|
|
36
|
+
}
|
|
28
37
|
}
|
|
29
38
|
return _origCEDefine(name, cls, opts);
|
|
30
39
|
};
|
|
@@ -1959,9 +1968,15 @@ function initViconic(options = {}) {
|
|
|
1959
1968
|
}
|
|
1960
1969
|
var ViconicIcon = ({ name, className, style, size, color, ...props }) => {
|
|
1961
1970
|
const iconRef = useRef(null);
|
|
1971
|
+
const prevNameRef = useRef(name);
|
|
1962
1972
|
useEffect(() => {
|
|
1963
1973
|
const el = iconRef.current;
|
|
1964
1974
|
if (!el) return;
|
|
1975
|
+
if (prevNameRef.current !== name) {
|
|
1976
|
+
el.innerHTML = "";
|
|
1977
|
+
el.classList.remove("vi-ok", "svg-loaded", "vi-mono", "ci-multicolor");
|
|
1978
|
+
prevNameRef.current = name;
|
|
1979
|
+
}
|
|
1965
1980
|
const isKitIcon = name && name.startsWith("@");
|
|
1966
1981
|
if (window.CopyIcons && window.CopyIcons.forceProcess && !isKitIcon) {
|
|
1967
1982
|
window.CopyIcons.forceProcess(el);
|
package/package.json
CHANGED
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
if (typeof document !== 'undefined') {
|
|
35
35
|
const style = document.createElement('style');
|
|
36
36
|
// Use :where() to set specificity to 0, so user styles can easily override without !important
|
|
37
|
-
style.textContent = ':where(viconic-icon) { display: inline-flex; align-items: center; justify-content: center; width: 1em; height: 1em; font-size: inherit; line-height: 1; } :where(viconic-icon):not(.ci-multicolor) svg { width: 100%; height: 100%; display: block; fill: currentColor; } :where(viconic-icon).ci-multicolor svg { width: 100%; height: 100%; display: block; }';
|
|
37
|
+
style.textContent = ':where(viconic-icon) { display: inline-flex; align-items: center; justify-content: center; width: 1em; height: 1em; font-size: inherit; line-height: 1; } :where(viconic-icon):not(.ci-multicolor) svg { width: 100%; height: 100%; display: block; fill: currentColor; } :where(viconic-icon).ci-multicolor svg { width: 100%; height: 100%; display: block; } viconic-icon:not(.vi-ok):not(.svg-loaded) { animation: none !important; background: none !important; }';
|
|
38
38
|
if (document.head.firstChild) {
|
|
39
39
|
document.head.insertBefore(style, document.head.firstChild);
|
|
40
40
|
} else {
|
|
@@ -52,13 +52,23 @@
|
|
|
52
52
|
// so it skips elements that Smart Loader has already handled.
|
|
53
53
|
const _origCEDefine = customElements.define.bind(customElements);
|
|
54
54
|
customElements.define = function(name, cls, opts) {
|
|
55
|
-
if (name === 'viconic-icon' && cls && cls.prototype
|
|
56
|
-
|
|
57
|
-
cls.prototype._u
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
55
|
+
if (name === 'viconic-icon' && cls && cls.prototype) {
|
|
56
|
+
// Patch _u() to skip elements already handled by Smart Loader
|
|
57
|
+
if (cls.prototype._u) {
|
|
58
|
+
const origU = cls.prototype._u;
|
|
59
|
+
cls.prototype._u = function() {
|
|
60
|
+
if (this.classList.contains('svg-loaded')) return;
|
|
61
|
+
return origU.call(this);
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
// Patch connectedCallback to also guard svg-loaded
|
|
65
|
+
if (cls.prototype.connectedCallback) {
|
|
66
|
+
const origCC = cls.prototype.connectedCallback;
|
|
67
|
+
cls.prototype.connectedCallback = function() {
|
|
68
|
+
if (this.classList.contains('svg-loaded')) return;
|
|
69
|
+
return origCC.call(this);
|
|
70
|
+
};
|
|
71
|
+
}
|
|
62
72
|
}
|
|
63
73
|
return _origCEDefine(name, cls, opts);
|
|
64
74
|
};
|
package/src/index.jsx
CHANGED
|
@@ -65,11 +65,21 @@ export function initViconic(options = {}) {
|
|
|
65
65
|
*/
|
|
66
66
|
export const ViconicIcon = ({ name, className, style, size, color, ...props }) => {
|
|
67
67
|
const iconRef = useRef(null);
|
|
68
|
+
const prevNameRef = useRef(name);
|
|
68
69
|
|
|
69
70
|
useEffect(() => {
|
|
70
71
|
const el = iconRef.current;
|
|
71
72
|
if (!el) return;
|
|
72
73
|
|
|
74
|
+
// --- 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
|
+
if (prevNameRef.current !== name) {
|
|
78
|
+
el.innerHTML = '';
|
|
79
|
+
el.classList.remove('vi-ok', 'svg-loaded', 'vi-mono', 'ci-multicolor');
|
|
80
|
+
prevNameRef.current = name;
|
|
81
|
+
}
|
|
82
|
+
|
|
73
83
|
// Path 1: Smart loader (system icons with prefix:name format)
|
|
74
84
|
const isKitIcon = name && name.startsWith('@');
|
|
75
85
|
if (window.CopyIcons && window.CopyIcons.forceProcess && !isKitIcon) {
|