@dogsbay/icons 0.2.0-beta.6 → 0.2.0-beta.61

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.d.ts CHANGED
@@ -1,2 +1,3 @@
1
1
  export { IconRegistry, createIconRegistry } from "./registry.js";
2
2
  export type { IconResolver } from "./registry.js";
3
+ export { resolveIcon, defaultRegistry } from "./resolve.js";
package/dist/index.js CHANGED
@@ -1 +1,2 @@
1
1
  export { IconRegistry, createIconRegistry } from "./registry.js";
2
+ export { resolveIcon, defaultRegistry } from "./resolve.js";
package/dist/registry.js CHANGED
@@ -118,6 +118,10 @@ export class IconRegistry {
118
118
  }
119
119
  case "octicons": return "octicon";
120
120
  case "simple": return "simple-icons";
121
+ // Lucide is the platform default — used for `{icon=...}` props
122
+ // on cards, the inline `icon` TreeNode, and any `name="rocket"`
123
+ // (no namespace prefix) call. Iconify prefix is "lucide".
124
+ case "lucide": return "lucide";
121
125
  default: return null;
122
126
  }
123
127
  }
@@ -130,8 +134,12 @@ export class IconRegistry {
130
134
  return this.iconifyCache.get(prefix);
131
135
  }
132
136
  try {
133
- // Dynamic require to load icon data
134
- const { icons, width, height } = require(`@iconify/json/json/${prefix}.json`);
137
+ // Dynamic require to load icon data. We depend on the individual
138
+ // per-set packages (@iconify-json/mdi, …/lucide, etc.) rather than
139
+ // the monolithic @iconify/json (399 MB — the whole catalog) so a
140
+ // consuming site only pulls the ~7 sets we map. The prefix equals
141
+ // the package suffix, and each set ships `icons.json` at its root.
142
+ const { icons, width, height } = require(`@iconify-json/${prefix}/icons.json`);
135
143
  const w = width || 24;
136
144
  const h = height || 24;
137
145
  const result = {};
@@ -0,0 +1,41 @@
1
+ /**
2
+ * Convenience resolver for the platform-wide icon shorthand.
3
+ *
4
+ * Components and serializers across the platform use a single
5
+ * shorthand for icon names — `{icon="rocket"}` on cards, the
6
+ * inline `:icon[rocket]` directive, etc. This module gives them
7
+ * one entry point that:
8
+ *
9
+ * - Defaults to Lucide when no `pack:` prefix is supplied
10
+ * (so `rocket` → `lucide:rocket`).
11
+ * - Accepts the `pack:name` shape (`mdi:home`,
12
+ * `simple-icons:github`, `lucide:book-open`) and routes to
13
+ * the right Iconify set.
14
+ * - Returns `null` when the icon doesn't exist — callers
15
+ * decide whether to fall back to text or omit the slot.
16
+ *
17
+ * Built on top of the IconRegistry so emoji shortcodes (`rocket`,
18
+ * `tada`, etc.) and custom resolvers still work alongside the
19
+ * Iconify lookup. The default precedence: emoji map → custom
20
+ * resolver → Iconify pack.
21
+ */
22
+ import { IconRegistry } from "./registry.js";
23
+ export declare function defaultRegistry(): IconRegistry;
24
+ /**
25
+ * Resolve a platform icon shorthand to an SVG string (or
26
+ * Unicode emoji, when the shorthand matches an emoji entry).
27
+ *
28
+ * Examples:
29
+ * - resolveIcon("rocket") → emoji 🚀 (emoji map wins)
30
+ * - resolveIcon("lucide:rocket") → Lucide rocket SVG
31
+ * - resolveIcon("book-open") → Lucide book-open SVG (no emoji entry)
32
+ * - resolveIcon("mdi:home") → Material Design Icons home SVG
33
+ * - resolveIcon("simple-icons:github") → simple-icons GitHub SVG
34
+ * - resolveIcon("nonexistent") → null
35
+ *
36
+ * @param shorthand The icon name. Either bare (`rocket`) or
37
+ * namespaced (`pack:name`).
38
+ * @param registry Optional registry override. Defaults to the
39
+ * process-wide shared instance.
40
+ */
41
+ export declare function resolveIcon(shorthand: string, registry?: IconRegistry): string | null;
@@ -0,0 +1,71 @@
1
+ /**
2
+ * Convenience resolver for the platform-wide icon shorthand.
3
+ *
4
+ * Components and serializers across the platform use a single
5
+ * shorthand for icon names — `{icon="rocket"}` on cards, the
6
+ * inline `:icon[rocket]` directive, etc. This module gives them
7
+ * one entry point that:
8
+ *
9
+ * - Defaults to Lucide when no `pack:` prefix is supplied
10
+ * (so `rocket` → `lucide:rocket`).
11
+ * - Accepts the `pack:name` shape (`mdi:home`,
12
+ * `simple-icons:github`, `lucide:book-open`) and routes to
13
+ * the right Iconify set.
14
+ * - Returns `null` when the icon doesn't exist — callers
15
+ * decide whether to fall back to text or omit the slot.
16
+ *
17
+ * Built on top of the IconRegistry so emoji shortcodes (`rocket`,
18
+ * `tada`, etc.) and custom resolvers still work alongside the
19
+ * Iconify lookup. The default precedence: emoji map → custom
20
+ * resolver → Iconify pack.
21
+ */
22
+ import { createIconRegistry } from "./registry.js";
23
+ /**
24
+ * Lazily-instantiated registry shared by every consumer that
25
+ * doesn't bring its own. The first `resolveIcon` call constructs
26
+ * it; subsequent calls reuse the cached Iconify packs inside.
27
+ */
28
+ let _defaultRegistry = null;
29
+ export function defaultRegistry() {
30
+ if (_defaultRegistry === null) {
31
+ _defaultRegistry = createIconRegistry();
32
+ }
33
+ return _defaultRegistry;
34
+ }
35
+ /**
36
+ * Resolve a platform icon shorthand to an SVG string (or
37
+ * Unicode emoji, when the shorthand matches an emoji entry).
38
+ *
39
+ * Examples:
40
+ * - resolveIcon("rocket") → emoji 🚀 (emoji map wins)
41
+ * - resolveIcon("lucide:rocket") → Lucide rocket SVG
42
+ * - resolveIcon("book-open") → Lucide book-open SVG (no emoji entry)
43
+ * - resolveIcon("mdi:home") → Material Design Icons home SVG
44
+ * - resolveIcon("simple-icons:github") → simple-icons GitHub SVG
45
+ * - resolveIcon("nonexistent") → null
46
+ *
47
+ * @param shorthand The icon name. Either bare (`rocket`) or
48
+ * namespaced (`pack:name`).
49
+ * @param registry Optional registry override. Defaults to the
50
+ * process-wide shared instance.
51
+ */
52
+ export function resolveIcon(shorthand, registry) {
53
+ const reg = registry ?? defaultRegistry();
54
+ const trimmed = shorthand.trim();
55
+ if (trimmed.length === 0)
56
+ return null;
57
+ const colonIdx = trimmed.indexOf(":");
58
+ if (colonIdx > 0) {
59
+ const pack = trimmed.slice(0, colonIdx);
60
+ const name = trimmed.slice(colonIdx + 1);
61
+ return reg.resolve(pack, name);
62
+ }
63
+ // Bare name. Try the emoji map first (so `rocket` → 🚀
64
+ // matches existing behaviour). Fall through to Lucide so SVG
65
+ // names without an emoji equivalent (`book-open`, `settings`)
66
+ // still resolve.
67
+ const emoji = reg.resolve("emoji", trimmed);
68
+ if (emoji !== null)
69
+ return emoji;
70
+ return reg.resolve("lucide", trimmed);
71
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dogsbay/icons",
3
- "version": "0.2.0-beta.6",
3
+ "version": "0.2.0-beta.61",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
@@ -13,7 +13,13 @@
13
13
  "README.md"
14
14
  ],
15
15
  "dependencies": {
16
- "@iconify/json": "^2.2.0"
16
+ "@iconify-json/mdi": "^1.2.0",
17
+ "@iconify-json/fa6-solid": "^1.2.0",
18
+ "@iconify-json/fa6-regular": "^1.2.0",
19
+ "@iconify-json/fa6-brands": "^1.2.0",
20
+ "@iconify-json/octicon": "^1.2.0",
21
+ "@iconify-json/simple-icons": "^1.2.0",
22
+ "@iconify-json/lucide": "^1.2.0"
17
23
  },
18
24
  "devDependencies": {
19
25
  "@types/node": "^22.0.0",