@wentools/iconic 0.1.0 → 0.1.2
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/icon/Icon.svelte +6 -11
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/resolver/context.d.ts +13 -3
- package/dist/resolver/context.js +15 -6
- package/dist/resolver/create_icon_resolver.d.ts +5 -5
- package/dist/resolver/create_icon_resolver.js +3 -3
- package/dist/resolver/index.d.ts +1 -1
- package/dist/resolver/index.js +1 -1
- package/package.json +2 -1
package/dist/icon/Icon.svelte
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
2
|
import type { Component } from 'svelte'
|
|
3
3
|
import type { IconAnimation } from '../types'
|
|
4
|
-
import
|
|
5
|
-
import { ICON_RESOLVER_KEY } from '../resolver/context'
|
|
6
|
-
import { getContext } from 'svelte'
|
|
4
|
+
import { getIconResolver } from '../resolver/context'
|
|
7
5
|
|
|
8
6
|
interface Props {
|
|
9
7
|
icon: Component | string
|
|
@@ -30,7 +28,7 @@
|
|
|
30
28
|
}: Props = $props()
|
|
31
29
|
|
|
32
30
|
// Get resolver at component init time (top-level), not inside $derived
|
|
33
|
-
const resolver =
|
|
31
|
+
const resolver = getIconResolver()
|
|
34
32
|
|
|
35
33
|
// Resolve icon variant to component if needed
|
|
36
34
|
const Icon = $derived.by(() => {
|
|
@@ -48,12 +46,9 @@
|
|
|
48
46
|
const lucideSize = $derived(typeof size === 'number' ? size : '100%')
|
|
49
47
|
const wrapperSize = $derived(typeof size === 'number' ? `${size}px` : size)
|
|
50
48
|
|
|
51
|
-
// Use the animation prop directly
|
|
52
|
-
const activeAnimation = $derived(animation ?? null)
|
|
53
|
-
|
|
54
49
|
// Build animation CSS custom properties
|
|
55
50
|
const animationCustomProps = $derived.by(() => {
|
|
56
|
-
if (!
|
|
51
|
+
if (!animation) return {}
|
|
57
52
|
|
|
58
53
|
const defaultDurations: Record<IconAnimation, number> = {
|
|
59
54
|
spin: 1,
|
|
@@ -72,8 +67,8 @@
|
|
|
72
67
|
}
|
|
73
68
|
|
|
74
69
|
return {
|
|
75
|
-
'--animation-duration': `${animationDuration ?? defaultDurations[
|
|
76
|
-
'--animation-easing': animationEasing ?? defaultEasings[
|
|
70
|
+
'--animation-duration': `${animationDuration ?? defaultDurations[animation]}s`,
|
|
71
|
+
'--animation-easing': animationEasing ?? defaultEasings[animation],
|
|
77
72
|
'--animation-iterations': animationIterations ?? 'infinite',
|
|
78
73
|
}
|
|
79
74
|
})
|
|
@@ -87,7 +82,7 @@
|
|
|
87
82
|
})
|
|
88
83
|
|
|
89
84
|
// Build class string
|
|
90
|
-
const animationClass = $derived(
|
|
85
|
+
const animationClass = $derived(animation ? `animate-${animation}` : '')
|
|
91
86
|
</script>
|
|
92
87
|
|
|
93
88
|
<div class={animationClass} style:--size={wrapperSize} style:--color={color} style={animationStyle}>
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
export { Icon } from './icon/index';
|
|
2
2
|
export type { IconAnimation, IconAction } from './types';
|
|
3
|
-
export { createIconResolver, setIconResolver, getIconResolver } from './resolver/index';
|
|
3
|
+
export { createIconResolver, setIconResolver, setGlobalIconResolver, getIconResolver } from './resolver/index';
|
|
4
4
|
export type { IconResolver } from './resolver/index';
|
package/dist/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export { Icon } from './icon/index';
|
|
2
|
-
export { createIconResolver, setIconResolver, getIconResolver } from './resolver/index';
|
|
2
|
+
export { createIconResolver, setIconResolver, setGlobalIconResolver, getIconResolver } from './resolver/index';
|
|
@@ -1,5 +1,15 @@
|
|
|
1
|
+
import type { Component } from 'svelte';
|
|
1
2
|
import type { IconResolver } from './create_icon_resolver';
|
|
2
3
|
declare const ICON_RESOLVER_KEY: unique symbol;
|
|
3
|
-
declare
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
declare const setIconResolver: <TVariant extends string>(resolver: {
|
|
5
|
+
resolveToComponent: (variant: TVariant) => Component;
|
|
6
|
+
isIconVariant: (value: string) => value is TVariant;
|
|
7
|
+
iconVariants: readonly TVariant[];
|
|
8
|
+
}) => void;
|
|
9
|
+
declare const setGlobalIconResolver: <TVariant extends string>(resolver: {
|
|
10
|
+
resolveToComponent: (variant: TVariant) => Component;
|
|
11
|
+
isIconVariant: (value: string) => value is TVariant;
|
|
12
|
+
iconVariants: readonly TVariant[];
|
|
13
|
+
}) => void;
|
|
14
|
+
declare const getIconResolver: () => IconResolver | undefined;
|
|
15
|
+
export { ICON_RESOLVER_KEY, setIconResolver, setGlobalIconResolver, getIconResolver };
|
package/dist/resolver/context.js
CHANGED
|
@@ -1,9 +1,18 @@
|
|
|
1
1
|
import { getContext, setContext } from 'svelte';
|
|
2
2
|
const ICON_RESOLVER_KEY = Symbol('icon-resolver');
|
|
3
|
-
|
|
3
|
+
let globalResolver;
|
|
4
|
+
const setIconResolver = (resolver) => {
|
|
4
5
|
setContext(ICON_RESOLVER_KEY, resolver);
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
}
|
|
9
|
-
|
|
6
|
+
};
|
|
7
|
+
const setGlobalIconResolver = (resolver) => {
|
|
8
|
+
globalResolver = resolver;
|
|
9
|
+
};
|
|
10
|
+
const getIconResolver = () => {
|
|
11
|
+
try {
|
|
12
|
+
return getContext(ICON_RESOLVER_KEY) ?? globalResolver;
|
|
13
|
+
}
|
|
14
|
+
catch {
|
|
15
|
+
return globalResolver;
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
export { ICON_RESOLVER_KEY, setIconResolver, setGlobalIconResolver, getIconResolver };
|
|
@@ -4,11 +4,11 @@ interface IconResolver {
|
|
|
4
4
|
isIconVariant: (value: string) => boolean;
|
|
5
5
|
iconVariants: readonly string[];
|
|
6
6
|
}
|
|
7
|
-
declare
|
|
8
|
-
resolveToComponent: (variant: keyof
|
|
9
|
-
isIconVariant: (value: string) => value is keyof
|
|
10
|
-
iconVariants: readonly (keyof
|
|
11
|
-
map:
|
|
7
|
+
declare const createIconResolver: <const TMap extends Record<string, Component>>(map: TMap) => {
|
|
8
|
+
resolveToComponent: (variant: keyof TMap & string) => Component;
|
|
9
|
+
isIconVariant: (value: string) => value is keyof TMap & string;
|
|
10
|
+
iconVariants: readonly (keyof TMap & string)[];
|
|
11
|
+
map: TMap;
|
|
12
12
|
};
|
|
13
13
|
export { createIconResolver };
|
|
14
14
|
export type { IconResolver };
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
|
|
1
|
+
const createIconResolver = (map) => {
|
|
2
2
|
const variants = Object.keys(map);
|
|
3
3
|
const resolveToComponent = (variant) => {
|
|
4
4
|
const component = map[variant];
|
|
5
5
|
if (!component) {
|
|
6
|
-
throw new Error(`Unknown icon variant: "${variant}"`);
|
|
6
|
+
throw new Error(`Unknown icon variant: "${variant}". Valid variants: ${variants.join(', ')}`);
|
|
7
7
|
}
|
|
8
8
|
return component;
|
|
9
9
|
};
|
|
@@ -16,5 +16,5 @@ function createIconResolver(map) {
|
|
|
16
16
|
iconVariants: variants,
|
|
17
17
|
map,
|
|
18
18
|
};
|
|
19
|
-
}
|
|
19
|
+
};
|
|
20
20
|
export { createIconResolver };
|
package/dist/resolver/index.d.ts
CHANGED
package/dist/resolver/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export { createIconResolver } from './create_icon_resolver';
|
|
2
|
-
export { setIconResolver, getIconResolver } from './context';
|
|
2
|
+
export { setIconResolver, setGlobalIconResolver, getIconResolver } from './context';
|
package/package.json
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wentools/iconic",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"description": "Svelte 5 icon component with animations and resolver factory for Lucide icons",
|
|
5
5
|
"type": "module",
|
|
6
|
+
"sideEffects": false,
|
|
6
7
|
"svelte": "./dist/index.js",
|
|
7
8
|
"types": "./dist/index.d.ts",
|
|
8
9
|
"exports": {
|