@dogsbay/icons 0.2.0-beta.4 → 0.2.0-beta.40
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 +1 -0
- package/dist/index.js +1 -0
- package/dist/registry.js +4 -0
- package/dist/resolve.d.ts +41 -0
- package/dist/resolve.js +71 -0
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
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
|
}
|
|
@@ -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;
|
package/dist/resolve.js
ADDED
|
@@ -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
|
+
}
|