@velicons/core 0.3.0 → 0.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/README.md CHANGED
@@ -1,56 +1,54 @@
1
1
  # @velicons/core
2
2
 
3
- Canonical local registry data for Velicons tooling and the Velicons Docs showcase.
3
+ Framework-neutral Velicons catalog and explicit canonical registry API.
4
4
 
5
- ## Installation
5
+ ## Lightweight catalog
6
6
 
7
- ```bash
8
- npm install @velicons/core
9
- ```
7
+ The package root is intentionally metadata-only. Normal tooling can import it without loading the full artwork/integration registry.
8
+
9
+ ```ts
10
+ import { getIcons, getFlags, getLibrary } from "@velicons/core";
10
11
 
11
- ```bash
12
- bun add @velicons/core
12
+ const icons = getIcons();
13
+ const flags = getFlags();
13
14
  ```
14
15
 
15
- ## Usage
16
+ The root catalog contains identity, naming, geometry, search metadata, provenance references, and generated slug/route information.
16
17
 
17
- The package contains the canonical registry as JSON. It does not fetch registry data from the network, so Velicons Docs can use the complete icon and flag registry offline after installation.
18
+ ## Full canonical registry
18
19
 
19
- ### Icons
20
+ Consumers that explicitly need canonical artwork or generated integration data can opt into the heavy registry API:
20
21
 
21
22
  ```ts
22
- import registry from "@velicons/core/icons/registry.json";
23
+ import { getRegistry } from "@velicons/core/registry";
23
24
 
24
- const icon = registry.icons.find((item) => item.id === "...");
25
+ const registry = getRegistry();
25
26
  ```
26
27
 
27
- ### Flags
28
+ The JSON representations are also exposed explicitly:
28
29
 
29
30
  ```ts
30
- import registry from "@velicons/core/flags/registry.json";
31
-
32
- const flag = registry.icons.find((item) => item.id === "...");
31
+ import icons from "@velicons/core/icons/registry.json";
32
+ import flags from "@velicons/core/flags/registry.json";
33
33
  ```
34
34
 
35
- Both registries are generated from the same canonical build cache. `generated.integrations` is preserved in each icon/flag entry, so the showcase can render the exact generated framework integrations without another build or network request.
36
-
37
- Artwork payloads are intentionally omitted from these showcase registries to avoid duplicating the SVG payload in the core package. The canonical metadata, geometry, provenance references, and generated integration data remain available locally.
35
+ These full registries are generated from the same canonical source as the lightweight catalog. They are not imported by the package root.
38
36
 
39
37
  ## Package layout
40
38
 
41
39
  ```text
42
40
  @velicons/core
43
- ├── jsons/
44
- │ ├── icons/registry.json
45
- │ ├── flags/registry.json
46
- ├── provenance.json
47
- └── country-provenance.json
48
- └── dist/
49
- └── index.d.ts
41
+ ├── dist/
42
+ │ ├── index.js # lightweight catalog API
43
+ │ ├── registry.js # explicit full registry API
44
+ └── full-registry.js # explicit compatibility alias
45
+ └── jsons/
46
+ ├── icons/catalog.json
47
+ ├── flags/catalog.json
48
+ ├── icons/registry.json
49
+ └── flags/registry.json
50
50
  ```
51
51
 
52
- The two registry JSON files are the primary data API for Velicons Docs.
53
-
54
52
  ## License
55
53
 
56
- The Velicons package source and generated integration code are distributed under the MIT License. Third-party icon artwork remains subject to its applicable upstream license. Individual icon provenance and licensing information are preserved in the registry metadata.
54
+ The Velicons package source and generated integration code are distributed under the MIT License. Third-party icon artwork remains subject to its applicable upstream license. Individual icon provenance and licensing information are preserved in the canonical registry.
@@ -0,0 +1 @@
1
+ export * from "./registry.js";
@@ -0,0 +1 @@
1
+ export * from "./registry.js";
package/dist/index.d.ts CHANGED
@@ -1,3 +1,21 @@
1
- export * from "./registry.js";
2
- export { default as iconsRegistry } from "../jsons/icons/registry.json";
3
- export { default as flagsRegistry } from "../jsons/flags/registry.json";
1
+ export interface LibraryLicense { name: string; spdx?: string; url?: string; }
2
+ export interface LibraryMetadata { id: string; name: string; [key: string]: unknown; }
3
+ export interface CanonicalGeometry { viewBox: string; width?: number; height?: number; }
4
+ export interface CanonicalPresentation { color?: string; colorMode?: "monochrome" | "multicolor"; }
5
+ export interface CanonicalIcon { id: string; name: string; title: string; family: "icon" | "flag"; set: string; variant: string; aliases?: string[]; categories?: string[]; tags?: string[]; geometry: CanonicalGeometry; presentation?: CanonicalPresentation; metadata?: Record<string, unknown>; generated?: { slug: string; route: string }; [key: string]: unknown; }
6
+ export interface CanonicalIconSet extends LibraryMetadata { path: string; iconCount: number; }
7
+ export interface CanonicalRegistry { version: number; libraries: CanonicalIconSet[]; icons: CanonicalIcon[]; }
8
+ export type VeliconsCatalog = { version: number; icons: CanonicalRegistry; flags: CanonicalRegistry };
9
+ export declare const getIcons: () => CanonicalIcon[];
10
+ export declare const getFlags: () => CanonicalIcon[];
11
+ export declare const getLibraries: () => CanonicalIconSet[];
12
+ export declare const getIcon: (idOrSlug: string, slug?: string) => CanonicalIcon | undefined;
13
+ export declare const getFlag: (idOrSlug: string, slug?: string) => CanonicalIcon | undefined;
14
+ export declare const getIconById: (id: string) => CanonicalIcon | undefined;
15
+ export declare const getFlagById: (id: string) => CanonicalIcon | undefined;
16
+ export declare const getLibrary: (id: string) => CanonicalIconSet | undefined;
17
+ export declare const getIconProp: (iconOrId: CanonicalIcon | string, prop: string) => unknown;
18
+ export declare const getIconProps: (iconOrId: CanonicalIcon | string, props?: readonly string[]) => Record<string, unknown> | CanonicalIcon | undefined;
19
+ export declare const getFlagProp: (flagOrId: CanonicalIcon | string, prop: string) => unknown;
20
+ export declare const getFlagProps: (flagOrId: CanonicalIcon | string, props?: readonly string[]) => Record<string, unknown> | CanonicalIcon | undefined;
21
+ export declare const getCatalog: () => VeliconsCatalog;
package/dist/index.js CHANGED
@@ -1 +1,22 @@
1
- export { getRegistry, getIcons, getFlags, getIcon, getFlag, getIconById, getFlagById, getLibrary, getIconProp, getIconProps, getFlagProp, getFlagProps, iconsRegistry, flagsRegistry } from "./registry.js";
1
+ import iconsCatalog from "../jsons/icons/catalog.json" with { type: "json" };
2
+ import flagsCatalog from "../jsons/flags/catalog.json" with { type: "json" };
3
+ const icons = iconsCatalog.icons;
4
+ const flags = flagsCatalog.icons;
5
+ const decode = (value) => { try { return decodeURIComponent(value); } catch { return value; } };
6
+ const slugOf = (entity) => entity.generated?.slug ?? entity.name;
7
+ const find = (items, a, b) => { const first = decode(a); if (b === undefined) return items.find((entity) => entity.id === first || slugOf(entity) === first || entity.name === first); const second = decode(b); return items.find((entity) => entity.set === first && (entity.id === second || slugOf(entity) === second || entity.name === second)); };
8
+ export const getIcons = () => icons;
9
+ export const getFlags = () => flags;
10
+ export const getLibraries = () => iconsCatalog.libraries;
11
+ export const getIcon = (a, b) => find(icons, a, b);
12
+ export const getFlag = (a, b) => find(flags, a, b);
13
+ export const getIconById = (id) => icons.find((icon) => icon.id === id);
14
+ export const getFlagById = (id) => flags.find((flag) => flag.id === id);
15
+ export const getLibrary = (id) => [...iconsCatalog.libraries, ...flagsCatalog.libraries].find((library) => library.id === id);
16
+ const resolve = (value, items) => value && typeof value === "object" ? value : find(items, value);
17
+ const read = (value, prop) => prop.split(".").reduce((current, key) => current == null ? undefined : current[key], value);
18
+ export const getIconProp = (value, prop) => read(resolve(value, icons), prop);
19
+ export const getIconProps = (value, props) => { const icon = resolve(value, icons); if (!icon) return undefined; return props ? Object.fromEntries(props.map((prop) => [prop, read(icon, prop)])) : icon; };
20
+ export const getFlagProp = (value, prop) => read(resolve(value, flags), prop);
21
+ export const getFlagProps = (value, props) => { const flag = resolve(value, flags); if (!flag) return undefined; return props ? Object.fromEntries(props.map((prop) => [prop, read(flag, prop)])) : flag; };
22
+ export const getCatalog = () => ({ version: 1, icons: iconsCatalog, flags: flagsCatalog });
@@ -1,27 +1,20 @@
1
1
  export interface LibraryLicense { name: string; spdx?: string; url?: string; }
2
2
  export interface LibraryMetadata { id: string; name: string; [key: string]: unknown; }
3
3
  export interface CanonicalGeometry { viewBox: string; width?: number; height?: number; }
4
- export type CanonicalColorMode = "monochrome" | "multicolor";
5
- export interface CanonicalPresentation { color?: string; colorMode?: CanonicalColorMode; }
6
- export interface CanonicalSourceRef { url?: string; file?: string; adapter?: string; library?: string; author?: string; }
7
- export type FrameworkName = "react" | "svelte" | "angular" | "vue" | "solid" | "preact" | "lit" | "web" | "css" | "svg";
8
4
  export interface IntegrationFile { filename: string; language: string; code: string; }
9
- export interface GeneratedIntegration { framework: FrameworkName; files: IntegrationFile[]; }
5
+ export interface GeneratedIntegration { framework: string; files: IntegrationFile[]; }
10
6
  export interface GeneratedData { slug: string; integrations: GeneratedIntegration[]; svg: string; coloredSvg?: string; dataUrl: string; coloredDataUrl?: string; route: string; }
11
7
  export interface CanonicalIcon { [key: string]: unknown; id: string; name: string; title: string; family: "icon" | "flag"; set: string; variant: string; geometry: CanonicalGeometry; artwork: { body: string }; generated?: GeneratedData; }
12
8
  export interface CanonicalIconSet extends LibraryMetadata { path: string; iconCount: number; }
13
9
  export interface CanonicalRegistry { version: 2; libraries: CanonicalIconSet[]; icons: CanonicalIcon[]; }
14
10
  export interface VeliconsRegistry { version: number; icons: CanonicalRegistry; flags: CanonicalRegistry; }
15
- export declare function getRegistry(): VeliconsRegistry;
16
- export declare function getIcons(): CanonicalIcon[];
17
- export declare function getFlags(): CanonicalIcon[];
18
- export declare function getIcon(idOrSlug: string, slug?: string): CanonicalIcon | undefined;
19
- export declare function getFlag(idOrSlug: string, slug?: string): CanonicalIcon | undefined;
20
- export declare function getIconById(id: string): CanonicalIcon | undefined;
21
- export declare function getFlagById(id: string): CanonicalIcon | undefined;
22
- export declare function getLibrary(id: string): CanonicalIconSet | undefined;
23
- export declare function getIconProp<K extends keyof CanonicalIcon>(iconOrId: CanonicalIcon | string, prop: K): CanonicalIcon[K] | undefined;
24
- export declare function getIconProp(iconOrId: CanonicalIcon | string, prop: string): unknown;
25
- export declare function getIconProps<K extends keyof CanonicalIcon>(iconOrId: CanonicalIcon | string, props?: readonly K[]): Pick<CanonicalIcon, K> | CanonicalIcon | undefined;
26
- export declare function getFlagProp<K extends keyof CanonicalIcon>(flagOrId: CanonicalIcon | string, prop: K): CanonicalIcon[K] | undefined;
27
- export declare function getFlagProps<K extends keyof CanonicalIcon>(flagOrId: CanonicalIcon | string, props?: readonly K[]): Pick<CanonicalIcon, K> | CanonicalIcon | undefined;
11
+ export declare const iconsRegistry: CanonicalRegistry;
12
+ export declare const flagsRegistry: CanonicalRegistry;
13
+ export declare const getRegistry: () => VeliconsRegistry;
14
+ export declare const getIcons: () => CanonicalIcon[];
15
+ export declare const getFlags: () => CanonicalIcon[];
16
+ export declare const getIcon: (idOrSlug: string, slug?: string) => CanonicalIcon | undefined;
17
+ export declare const getFlag: (idOrSlug: string, slug?: string) => CanonicalIcon | undefined;
18
+ export declare const getIconById: (id: string) => CanonicalIcon | undefined;
19
+ export declare const getFlagById: (id: string) => CanonicalIcon | undefined;
20
+ export declare const getLibrary: (id: string) => CanonicalIconSet | undefined;
package/dist/registry.js CHANGED
@@ -1,61 +1,8 @@
1
1
  import iconsRegistry from "../jsons/icons/registry.json" with { type: "json" };
2
2
  import flagsRegistry from "../jsons/flags/registry.json" with { type: "json" };
3
-
4
-
5
- const icons = iconsRegistry.icons;
6
- const flags = flagsRegistry.icons;
7
- const registry = { version: 2, icons: iconsRegistry, flags: flagsRegistry };
3
+ const icons = iconsRegistry.icons; const flags = flagsRegistry.icons;
4
+ const decode = (value) => { try { return decodeURIComponent(value); } catch { return value; } }; const slugOf = (entity) => entity.generated?.slug ?? entity.name;
5
+ const find = (items, a, b) => { const first = decode(a); if (b === undefined) return items.find((entity) => entity.id === first || slugOf(entity) === first || entity.name === first); const second = decode(b); return items.find((entity) => entity.set === first && (entity.id === second || slugOf(entity) === second || entity.name === second)); };
8
6
  export { iconsRegistry, flagsRegistry };
9
-
10
- export const getRegistry = () => registry;
11
- export const getIcons = () => icons;
12
- export const getFlags = () => flags;
13
-
14
- function decode(value) {
15
- try { return decodeURIComponent(value); } catch { return value; }
16
- }
17
-
18
- function slugOf(entity) {
19
- return entity.generated?.slug ?? entity.name;
20
- }
21
-
22
- function findEntity(collection, a, b) {
23
- const first = decode(a);
24
- if (b === undefined) {
25
- return collection.find((entity) => entity.id === first || slugOf(entity) === first || entity.name === first);
26
- }
27
- const second = decode(b);
28
- return collection.find((entity) => entity.set === first && (entity.id === second || slugOf(entity) === second || entity.name === second));
29
- }
30
-
31
- export function getIcon(idOrSlug, slug) { return findEntity(icons, idOrSlug, slug); }
32
- export function getFlag(idOrSlug, slug) { return findEntity(flags, idOrSlug, slug); }
33
- export function getIconById(id) { return icons.find((icon) => icon.id === id); }
34
- export function getFlagById(id) { return flags.find((flag) => flag.id === id); }
35
- export function getLibrary(id) {
36
- return iconsRegistry.libraries.find((library) => library.id === id) ?? flagsRegistry.libraries.find((library) => library.id === id);
37
- }
38
-
39
- function resolveEntity(entityOrId, collection) {
40
- if (entityOrId && typeof entityOrId === "object") return entityOrId;
41
- return findEntity(collection, entityOrId);
42
- }
43
-
44
- function readPath(value, path) {
45
- return path.split(".").reduce((current, key) => current == null ? undefined : current[key], value);
46
- }
47
-
48
- export function getIconProp(iconOrId, prop) { return readPath(resolveEntity(iconOrId, icons), prop); }
49
- export function getIconProps(iconOrId, props) {
50
- const icon = resolveEntity(iconOrId, icons);
51
- if (!icon) return undefined;
52
- if (!props) return icon;
53
- return Object.fromEntries(props.map((prop) => [prop, readPath(icon, prop)]));
54
- }
55
- export function getFlagProp(flagOrId, prop) { return readPath(resolveEntity(flagOrId, flags), prop); }
56
- export function getFlagProps(flagOrId, props) {
57
- const flag = resolveEntity(flagOrId, flags);
58
- if (!flag) return undefined;
59
- if (!props) return flag;
60
- return Object.fromEntries(props.map((prop) => [prop, readPath(flag, prop)]));
61
- }
7
+ export const getRegistry = () => ({ version: 2, icons: iconsRegistry, flags: flagsRegistry });
8
+ export const getIcons = () => icons; export const getFlags = () => flags; export const getIcon = (a,b) => find(icons,a,b); export const getFlag = (a,b) => find(flags,a,b); export const getIconById = (id) => icons.find((icon)=>icon.id===id); export const getFlagById = (id) => flags.find((flag)=>flag.id===id); export const getLibrary = (id) => [...iconsRegistry.libraries,...flagsRegistry.libraries].find((library)=>library.id===id);