viconic-react-icons 1.0.8 → 1.1.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/README.md CHANGED
@@ -3,16 +3,17 @@
3
3
  ![NPM Version](https://img.shields.io/npm/v/viconic-react-icons)
4
4
  ![NPM License](https://img.shields.io/npm/l/viconic-react-icons)
5
5
 
6
- The official React component wrapper for [Viconic](https://viconic.io.vn), a modern, hyper-fast, CDN-powered icon system.
6
+ The official React component wrapper for [Viconic](https://viconic.dev), a modern, hyper-fast, CDN-powered icon system.
7
7
 
8
8
  `viconic-react-icons` gives you access to over 200,000+ open-source, pixel-perfect icons grouped in customizable collections. The icons are loaded dynamically from our Smart CDN at runtime, meaning your React bundle stays incredibly lightweight regardless of how many icons you use.
9
9
 
10
10
  ## Highlights
11
- - ? **Zero-Bundle Bloat**: SVGs are fetched magically via our CDN and injected directly into the DOM.
12
- - ?? **Fully Customizable**: Compatible with Tailwind CSS and standard inline styles. Inherits color natively via `currentColor`.
13
- - ?? **Smart Caching**: LocalStorage and Memory caching so icons appear instantly on repeated renders.
14
- - ?? **SSR Ready**: Fully supports Next.js, Vite, and other Server-Side Rendering frameworks.
15
- - ?? **TypeScript Support**: Includes built-in types for easy autocompletion.
11
+ - ðŸŠķ **Zero-Bundle Bloat**: SVGs are fetched magically via our CDN and injected directly into the DOM.
12
+ - ðŸŽĻ **Fully Customizable**: Compatible with Tailwind CSS and standard inline styles. Inherits color natively via `currentColor`.
13
+ - ⚡ **Smart Caching**: LocalStorage and Memory caching so icons appear instantly on repeated renders.
14
+ - 🔧 **Kit Support**: Use your custom icon kit with `initViconic()` — supports multiple kits.
15
+ - ðŸ–Ĩïļ **SSR Ready**: Fully supports Next.js, Vite, and other Server-Side Rendering frameworks.
16
+ - 📘 **TypeScript Support**: Includes built-in types for easy autocompletion.
16
17
 
17
18
  ## Installation
18
19
 
@@ -24,9 +25,9 @@ yarn add viconic-react-icons
24
25
  pnpm add viconic-react-icons
25
26
  ```
26
27
 
27
- ## Quick Start
28
+ ## Quick Start — System Icons
28
29
 
29
- Import the `ViconicIcon` component and pass the unique `name` identifier corresponding to your icon of choice from [viconic.io.vn](https://viconic.io.vn).
30
+ Import the `ViconicIcon` component and pass the unique `name` identifier corresponding to your icon of choice from [viconic.dev](https://viconic.dev).
30
31
 
31
32
  ```jsx
32
33
  import { ViconicIcon } from "viconic-react-icons";
@@ -45,26 +46,74 @@ function App() {
45
46
  </div>
46
47
  );
47
48
  }
49
+ ```
50
+
51
+ ## Quick Start — Custom Kit
52
+
53
+ Use icons from your own kit created at [viconic.dev](https://viconic.dev):
54
+
55
+ ```jsx
56
+ import { initViconic, ViconicIcon } from "viconic-react-icons";
57
+
58
+ // Initialize your kit — call once at app startup (e.g., in main.jsx or App.jsx)
59
+ initViconic({ kitId: "your-kit-uuid-here" });
60
+
61
+ // You can load multiple kits!
62
+ initViconic({ kitId: "another-kit-uuid" });
48
63
 
49
- export default App;
64
+ function App() {
65
+ return (
66
+ <div style={{ display: "flex", gap: "10px" }}>
67
+ {/* Kit icon using @prefix/name format */}
68
+ <ViconicIcon name="@myprefix/home" />
69
+
70
+ {/* Kit icon using prefix:name format (also works) */}
71
+ <ViconicIcon name="myprefix:settings" />
72
+
73
+ {/* Mix kit icons with system icons */}
74
+ <ViconicIcon name="lucide:star" />
75
+ </div>
76
+ );
77
+ }
50
78
  ```
51
79
 
52
80
  ## Props
53
81
 
54
82
  | Prop | Type | Default | Description |
55
83
  | ---- | ---- | ------- | ----------- |
56
- | `name` | `string` | `undefined` | **Required.** The unique icon ID (e.g. `lucide:activity`, `h2:0`). |
84
+ | `name` | `string` | `undefined` | **Required.** The unique icon ID (e.g. `lucide:activity`, `@prefix/name`). |
85
+ | `size` | `string \| number` | `undefined` | Icon size as CSS value (e.g. `"24px"`, `"2rem"`). |
86
+ | `color` | `string` | `undefined` | Icon color as CSS value (e.g. `"red"`, `"#333"`). |
57
87
  | `className` | `string` | `""` | Standard CSS class names (great for Tailwind). |
58
88
  | `style` | `React.CSSProperties` | `{}` | Inline CSS styling. |
59
89
  | `...props` | `HTMLAttributes` | | Spread standard HTML attributes (e.g. `onClick`, `title`). |
60
90
 
91
+ ## API
92
+
93
+ ### `initViconic(options)`
94
+
95
+ Inject a kit's loader script into `<head>`. Call once per kit at app startup.
96
+
97
+ | Option | Type | Default | Description |
98
+ | ------ | ---- | ------- | ----------- |
99
+ | `kitId` | `string` | — | **Required.** UUID of your Viconic Kit. |
100
+ | `cdnBase` | `string` | `"cdn.viconic.dev"` | Custom CDN domain. |
101
+
102
+ ```jsx
103
+ // In your main.jsx or App.jsx
104
+ import { initViconic } from "viconic-react-icons";
105
+
106
+ initViconic({ kitId: "387a6161-cb39-411f-8f13-29a5813e4efd" });
107
+ ```
108
+
61
109
  ## Architecture
62
110
 
63
111
  This package is a React wrapper around `<viconic-icon>` Web Components. The included `copyicons-smart-loader.js` script dynamically monitors the DOM using a `MutationObserver` and rapidly replaces `<viconic-icon>` elements with actual raw `<svg>` code.
64
112
 
113
+ When using kits, `initViconic()` injects the kit's loader.js from CDN, which fetches your kit's icon map and SVGs in parallel.
114
+
65
115
  Because we fetch SVGs in parallel and cache them across user sessions, your frontend performance score will skyrocket compared to packing large icon sets directly into your JS chunks.
66
116
 
67
117
  ## License
68
118
 
69
119
  This project is licensed under the MIT License. Icon licenses depend on the specific icon families you request.
70
-
package/dist/index.js CHANGED
@@ -30,7 +30,8 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
30
30
  var index_exports = {};
31
31
  __export(index_exports, {
32
32
  ViconicIcon: () => ViconicIcon,
33
- default: () => index_default
33
+ default: () => index_default,
34
+ initViconic: () => initViconic
34
35
  });
35
36
  module.exports = __toCommonJS(index_exports);
36
37
  var import_react = __toESM(require("react"));
@@ -219,10 +220,10 @@ var import_react = __toESM(require("react"));
219
220
  }
220
221
  const currentScript = document.currentScript;
221
222
  const config = {
222
- apiBase: (((_a = window.CONFIG) == null ? void 0 : _a.API_BASE) || ((_b = currentScript == null ? void 0 : currentScript.dataset) == null ? void 0 : _b.apiBase) || "https://api.viconic.io.vn").replace(/\/$/, ""),
223
+ apiBase: (((_a = window.CONFIG) == null ? void 0 : _a.API_BASE) || ((_b = currentScript == null ? void 0 : currentScript.dataset) == null ? void 0 : _b.apiBase) || "https://api.viconic.dev").replace(/\/$/, ""),
223
224
  // Batch API for Iconify-style loading (by-prefix endpoint)
224
- batchApiBase: (((_c = window.CONFIG) == null ? void 0 : _c.BATCH_API_BASE) || ((_d = window.CONFIG) == null ? void 0 : _d.API_BASE) || ((_e = currentScript == null ? void 0 : currentScript.dataset) == null ? void 0 : _e.batchApiBase) || "https://api.viconic.io.vn").replace(/\/$/, ""),
225
- cdnDomain: ((_f = currentScript == null ? void 0 : currentScript.dataset) == null ? void 0 : _f.cdnDomain) || ((_g = window.CONFIG) == null ? void 0 : _g.CDN_DOMAIN) || "cdn.viconic.io.vn",
225
+ batchApiBase: (((_c = window.CONFIG) == null ? void 0 : _c.BATCH_API_BASE) || ((_d = window.CONFIG) == null ? void 0 : _d.API_BASE) || ((_e = currentScript == null ? void 0 : currentScript.dataset) == null ? void 0 : _e.batchApiBase) || "https://api.viconic.dev").replace(/\/$/, ""),
226
+ cdnDomain: ((_f = currentScript == null ? void 0 : currentScript.dataset) == null ? void 0 : _f.cdnDomain) || ((_g = window.CONFIG) == null ? void 0 : _g.CDN_DOMAIN) || "cdn.viconic.dev",
226
227
  // Custom domain for R2 CDN via Cloudflare edge (HTTP/2, edge cache)
227
228
  cdnCustomDomain: ((_h = window.CONFIG) == null ? void 0 : _h.CDN_CUSTOM_DOMAIN) || ((_i = currentScript == null ? void 0 : currentScript.dataset) == null ? void 0 : _i.cdnCustomDomain) || "",
228
229
  observe: (currentScript == null ? void 0 : currentScript.hasAttribute("data-observe")) ?? false,
@@ -1944,12 +1945,48 @@ var import_react = __toESM(require("react"));
1944
1945
  })();
1945
1946
 
1946
1947
  // src/index.jsx
1948
+ var _initializedKits = /* @__PURE__ */ new Set();
1949
+ function initViconic({ kitId, cdnBase = "cdn.viconic.dev" }) {
1950
+ if (typeof window === "undefined") return;
1951
+ if (!kitId) {
1952
+ console.warn("[Viconic] initViconic requires a kitId");
1953
+ return;
1954
+ }
1955
+ if (_initializedKits.has(kitId)) return;
1956
+ _initializedKits.add(kitId);
1957
+ const scriptId = `viconic-kit-${kitId}`;
1958
+ if (document.getElementById(scriptId)) return;
1959
+ const script = document.createElement("script");
1960
+ script.id = scriptId;
1961
+ script.src = `https://${cdnBase}/kits/${kitId}/loader.js`;
1962
+ script.async = true;
1963
+ document.head.appendChild(script);
1964
+ }
1947
1965
  var ViconicIcon = ({ name, className, style, size, color, ...props }) => {
1948
1966
  const iconRef = (0, import_react.useRef)(null);
1949
1967
  (0, import_react.useEffect)(() => {
1950
- if (window.CopyIcons && iconRef.current) {
1951
- window.CopyIcons.forceProcess(iconRef.current);
1952
- }
1968
+ const el = iconRef.current;
1969
+ if (!el) return;
1970
+ if (window.CopyIcons && window.CopyIcons.forceProcess) {
1971
+ window.CopyIcons.forceProcess(el);
1972
+ }
1973
+ const isLoaded = el.classList.contains("vi-ok") || el.classList.contains("svg-loaded");
1974
+ if (isLoaded) return;
1975
+ let retries = 0;
1976
+ const maxRetries = 50;
1977
+ const timer = setInterval(() => {
1978
+ retries++;
1979
+ if (el.classList.contains("vi-ok") || el.classList.contains("svg-loaded")) {
1980
+ clearInterval(timer);
1981
+ return;
1982
+ }
1983
+ if (el._u) el._u();
1984
+ if (window.CopyIcons && window.CopyIcons.forceProcess) {
1985
+ window.CopyIcons.forceProcess(el);
1986
+ }
1987
+ if (retries >= maxRetries) clearInterval(timer);
1988
+ }, 100);
1989
+ return () => clearInterval(timer);
1953
1990
  }, [name, className, size, color, style]);
1954
1991
  const combinedStyle = {
1955
1992
  ...size ? { fontSize: size } : {},
@@ -1970,7 +2007,8 @@ var ViconicIcon = ({ name, className, style, size, color, ...props }) => {
1970
2007
  var index_default = ViconicIcon;
1971
2008
  // Annotate the CommonJS export names for ESM import in node:
1972
2009
  0 && (module.exports = {
1973
- ViconicIcon
2010
+ ViconicIcon,
2011
+ initViconic
1974
2012
  });
1975
2013
  /**
1976
2014
  * CopyIcons Smart Loader v8.3 (CDN Smart Fallback + Early Abort)
package/dist/index.mjs CHANGED
@@ -185,10 +185,10 @@ import React, { useEffect, useRef } from "react";
185
185
  }
186
186
  const currentScript = document.currentScript;
187
187
  const config = {
188
- apiBase: (((_a = window.CONFIG) == null ? void 0 : _a.API_BASE) || ((_b = currentScript == null ? void 0 : currentScript.dataset) == null ? void 0 : _b.apiBase) || "https://api.viconic.io.vn").replace(/\/$/, ""),
188
+ apiBase: (((_a = window.CONFIG) == null ? void 0 : _a.API_BASE) || ((_b = currentScript == null ? void 0 : currentScript.dataset) == null ? void 0 : _b.apiBase) || "https://api.viconic.dev").replace(/\/$/, ""),
189
189
  // Batch API for Iconify-style loading (by-prefix endpoint)
190
- batchApiBase: (((_c = window.CONFIG) == null ? void 0 : _c.BATCH_API_BASE) || ((_d = window.CONFIG) == null ? void 0 : _d.API_BASE) || ((_e = currentScript == null ? void 0 : currentScript.dataset) == null ? void 0 : _e.batchApiBase) || "https://api.viconic.io.vn").replace(/\/$/, ""),
191
- cdnDomain: ((_f = currentScript == null ? void 0 : currentScript.dataset) == null ? void 0 : _f.cdnDomain) || ((_g = window.CONFIG) == null ? void 0 : _g.CDN_DOMAIN) || "cdn.viconic.io.vn",
190
+ batchApiBase: (((_c = window.CONFIG) == null ? void 0 : _c.BATCH_API_BASE) || ((_d = window.CONFIG) == null ? void 0 : _d.API_BASE) || ((_e = currentScript == null ? void 0 : currentScript.dataset) == null ? void 0 : _e.batchApiBase) || "https://api.viconic.dev").replace(/\/$/, ""),
191
+ cdnDomain: ((_f = currentScript == null ? void 0 : currentScript.dataset) == null ? void 0 : _f.cdnDomain) || ((_g = window.CONFIG) == null ? void 0 : _g.CDN_DOMAIN) || "cdn.viconic.dev",
192
192
  // Custom domain for R2 CDN via Cloudflare edge (HTTP/2, edge cache)
193
193
  cdnCustomDomain: ((_h = window.CONFIG) == null ? void 0 : _h.CDN_CUSTOM_DOMAIN) || ((_i = currentScript == null ? void 0 : currentScript.dataset) == null ? void 0 : _i.cdnCustomDomain) || "",
194
194
  observe: (currentScript == null ? void 0 : currentScript.hasAttribute("data-observe")) ?? false,
@@ -1910,12 +1910,48 @@ import React, { useEffect, useRef } from "react";
1910
1910
  })();
1911
1911
 
1912
1912
  // src/index.jsx
1913
+ var _initializedKits = /* @__PURE__ */ new Set();
1914
+ function initViconic({ kitId, cdnBase = "cdn.viconic.dev" }) {
1915
+ if (typeof window === "undefined") return;
1916
+ if (!kitId) {
1917
+ console.warn("[Viconic] initViconic requires a kitId");
1918
+ return;
1919
+ }
1920
+ if (_initializedKits.has(kitId)) return;
1921
+ _initializedKits.add(kitId);
1922
+ const scriptId = `viconic-kit-${kitId}`;
1923
+ if (document.getElementById(scriptId)) return;
1924
+ const script = document.createElement("script");
1925
+ script.id = scriptId;
1926
+ script.src = `https://${cdnBase}/kits/${kitId}/loader.js`;
1927
+ script.async = true;
1928
+ document.head.appendChild(script);
1929
+ }
1913
1930
  var ViconicIcon = ({ name, className, style, size, color, ...props }) => {
1914
1931
  const iconRef = useRef(null);
1915
1932
  useEffect(() => {
1916
- if (window.CopyIcons && iconRef.current) {
1917
- window.CopyIcons.forceProcess(iconRef.current);
1918
- }
1933
+ const el = iconRef.current;
1934
+ if (!el) return;
1935
+ if (window.CopyIcons && window.CopyIcons.forceProcess) {
1936
+ window.CopyIcons.forceProcess(el);
1937
+ }
1938
+ const isLoaded = el.classList.contains("vi-ok") || el.classList.contains("svg-loaded");
1939
+ if (isLoaded) return;
1940
+ let retries = 0;
1941
+ const maxRetries = 50;
1942
+ const timer = setInterval(() => {
1943
+ retries++;
1944
+ if (el.classList.contains("vi-ok") || el.classList.contains("svg-loaded")) {
1945
+ clearInterval(timer);
1946
+ return;
1947
+ }
1948
+ if (el._u) el._u();
1949
+ if (window.CopyIcons && window.CopyIcons.forceProcess) {
1950
+ window.CopyIcons.forceProcess(el);
1951
+ }
1952
+ if (retries >= maxRetries) clearInterval(timer);
1953
+ }, 100);
1954
+ return () => clearInterval(timer);
1919
1955
  }, [name, className, size, color, style]);
1920
1956
  const combinedStyle = {
1921
1957
  ...size ? { fontSize: size } : {},
@@ -1936,7 +1972,8 @@ var ViconicIcon = ({ name, className, style, size, color, ...props }) => {
1936
1972
  var index_default = ViconicIcon;
1937
1973
  export {
1938
1974
  ViconicIcon,
1939
- index_default as default
1975
+ index_default as default,
1976
+ initViconic
1940
1977
  };
1941
1978
  /**
1942
1979
  * CopyIcons Smart Loader v8.3 (CDN Smart Fallback + Early Abort)
package/index.d.ts CHANGED
@@ -1,13 +1,30 @@
1
1
  import * as React from 'react';
2
2
 
3
+ export interface InitViconicOptions {
4
+ /** UUID of the Kit to load */
5
+ kitId: string;
6
+ /** Custom CDN domain (default: 'cdn.viconic.dev') */
7
+ cdnBase?: string;
8
+ }
9
+
10
+ /**
11
+ * Initialize a Viconic Kit. Injects the kit's loader script into <head>.
12
+ * Supports multiple kits — call once per kitId.
13
+ * Safe to call on server (no-op during SSR).
14
+ */
15
+ export function initViconic(options: InitViconicOptions): void;
16
+
3
17
  export interface ViconicIconProps extends React.HTMLAttributes<HTMLElement> {
4
- /** The unique icon ID (e.g., 'lucide:activity', 'h2:0'). Required. */
18
+ /** The unique icon ID. Required.
19
+ * - System icons: 'lucide:activity', 'h2:0'
20
+ * - Kit icons: '@prefix/iconName' (after calling initViconic)
21
+ */
5
22
  name: string;
6
23
 
7
- /** Optional icon size, CSS format (e.g., '24px', '1.5rem'). Translates to style.fontSize */
24
+ /** Optional icon size, CSS format (e.g., '24px', '1.5rem'). */
8
25
  size?: string | number;
9
26
 
10
- /** Optional icon color, CSS color value. Translates to style.color */
27
+ /** Optional icon color, CSS color value. */
11
28
  color?: string;
12
29
 
13
30
  style?: React.CSSProperties;
@@ -15,4 +32,3 @@ export interface ViconicIconProps extends React.HTMLAttributes<HTMLElement> {
15
32
 
16
33
  export const ViconicIcon: React.FC<ViconicIconProps>;
17
34
  export default ViconicIcon;
18
-
package/package.json CHANGED
@@ -1,30 +1,33 @@
1
- {
2
- "name": "viconic-react-icons",
3
- "version": "1.0.8",
4
- "description": "Viconic Smart Icons loader for React",
5
- "main": "dist/index.js",
6
- "module": "dist/index.mjs",
7
- "files": [
8
- "dist",
9
- "src",
10
- "index.d.ts"
11
- ],
12
- "scripts": {
13
- "build": "tsup src/index.jsx --format cjs,esm --external react"
14
- },
15
- "peerDependencies": {
16
- "react": ">=16.8.0"
17
- },
18
- "keywords": [
19
- "icons",
20
- "viconic",
21
- "react"
22
- ],
23
- "author": "Viconic Team",
24
- "license": "MIT",
25
- "types": "index.d.ts",
26
- "devDependencies": {
27
- "tsup": "^8.5.1",
28
- "typescript": "^5.9.3"
29
- }
30
- }
1
+ {
2
+ "name": "viconic-react-icons",
3
+ "version": "1.1.0",
4
+ "description": "Viconic Smart Icons loader for React — supports Kit and 200k+ system icons",
5
+ "main": "dist/index.js",
6
+ "module": "dist/index.mjs",
7
+ "files": [
8
+ "dist",
9
+ "src",
10
+ "index.d.ts"
11
+ ],
12
+ "scripts": {
13
+ "build": "tsup src/index.jsx --format cjs,esm --external react"
14
+ },
15
+ "peerDependencies": {
16
+ "react": ">=16.8.0"
17
+ },
18
+ "keywords": [
19
+ "icons",
20
+ "viconic",
21
+ "react",
22
+ "kit",
23
+ "svg",
24
+ "icon-kit"
25
+ ],
26
+ "author": "Viconic Team",
27
+ "license": "MIT",
28
+ "types": "index.d.ts",
29
+ "devDependencies": {
30
+ "tsup": "^8.5.1",
31
+ "typescript": "^5.9.3"
32
+ }
33
+ }