@svelte-atoms/core 1.0.0-alpha.29 → 1.0.0-alpha.31
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 +3 -2
- package/dist/attachments/clickout.svelte.d.ts +1 -1
- package/dist/attachments/clickout.svelte.js +2 -2
- package/dist/components/accordion/accordion-root.svelte +65 -61
- package/dist/components/accordion/accordion-root.svelte.d.ts +1 -1
- package/dist/components/accordion/accordion.stories.svelte +70 -134
- package/dist/components/accordion/item/accordion-item-body.svelte +44 -42
- package/dist/components/accordion/item/accordion-item-header.svelte +51 -50
- package/dist/components/accordion/item/accordion-item-indicator.svelte +51 -50
- package/dist/components/accordion/item/accordion-item-root.svelte +66 -65
- package/dist/components/accordion/item/bond.svelte.d.ts +2 -0
- package/dist/components/accordion/item/index.d.ts +3 -0
- package/dist/components/accordion/item/index.js +3 -0
- package/dist/components/accordion/item/motion.svelte.d.ts +15 -0
- package/dist/components/accordion/item/motion.svelte.js +30 -0
- package/dist/components/accordion/item/types.d.ts +7 -24
- package/dist/components/alert/alert-close-button.svelte +66 -70
- package/dist/components/alert/alert-description.svelte +42 -42
- package/dist/components/alert/alert-description.svelte.d.ts +3 -6
- package/dist/components/alert/alert-root.svelte +68 -103
- package/dist/components/alert/alert-root.svelte.d.ts +2 -2
- package/dist/components/alert/alert.stories.svelte +10 -11
- package/dist/components/alert/bond.svelte.d.ts +0 -13
- package/dist/components/alert/bond.svelte.js +0 -32
- package/dist/components/alert/types.d.ts +8 -32
- package/dist/components/atom/html-atom.svelte +261 -207
- package/dist/components/avatar/avatar.stories.svelte +8 -13
- package/dist/components/badge/badge.stories.svelte +1 -6
- package/dist/components/badge/badge.svelte +1 -1
- package/dist/components/breadcrumb/breadcrumb.stories.svelte +16 -21
- package/dist/components/button/button.stories.svelte +1 -34
- package/dist/components/calendar/calendar-day.svelte +9 -4
- package/dist/components/calendar/calendar-header.svelte +29 -29
- package/dist/components/calendar/calendar-root.svelte +206 -206
- package/dist/components/calendar/calendar.stories.svelte +26 -31
- package/dist/components/card/card-body.svelte +1 -1
- package/dist/components/card/card-footer.svelte +1 -1
- package/dist/components/card/card-root.svelte +1 -1
- package/dist/components/card/card.stories.svelte +92 -104
- package/dist/components/checkbox/checkbox.stories.svelte +4 -9
- package/dist/components/checkbox/checkbox.svelte +159 -157
- package/dist/components/collapsible/collapsible.stories.svelte +2 -3
- package/dist/components/combobox/atoms.d.ts +1 -1
- package/dist/components/combobox/atoms.js +1 -1
- package/dist/components/combobox/combobox-root.svelte +1 -1
- package/dist/components/combobox/compobox.stories.svelte +19 -22
- package/dist/components/combobox/index.d.ts +1 -0
- package/dist/components/container/container.stories.svelte +8 -11
- package/dist/components/container/container.svelte.d.ts +1 -1
- package/dist/components/datagrid/datagrid-root.svelte +59 -59
- package/dist/components/datagrid/datagrid.css +5 -5
- package/dist/components/datagrid/datagrid.stories.svelte +47 -50
- package/dist/components/datagrid/tr/bond.svelte.d.ts +4 -2
- package/dist/components/datagrid/tr/bond.svelte.js +9 -7
- package/dist/components/datagrid/tr/datagrid-tr.svelte +90 -88
- package/dist/components/date-picker/date-picker-calendar.svelte +2 -2
- package/dist/components/date-picker/date-picker-header.svelte +100 -100
- package/dist/components/date-picker/date-picker-months.svelte +142 -142
- package/dist/components/date-picker/date-picker-root.svelte +95 -95
- package/dist/components/date-picker/date-picker-years.svelte +205 -205
- package/dist/components/date-picker/date-picker.stories.svelte +35 -42
- package/dist/components/dialog/bond.svelte.d.ts +13 -3
- package/dist/components/dialog/bond.svelte.js +66 -5
- package/dist/components/dialog/dialog-content.svelte +2 -20
- package/dist/components/dialog/dialog-root.svelte +91 -110
- package/dist/components/dialog/dialog.stories.svelte +34 -37
- package/dist/components/dialog/motion.svelte.d.ts +13 -0
- package/dist/components/dialog/motion.svelte.js +44 -0
- package/dist/components/drawer/attachments.svelte.d.ts +1 -1
- package/dist/components/drawer/attachments.svelte.js +7 -10
- package/dist/components/drawer/bond.svelte.d.ts +24 -5
- package/dist/components/drawer/bond.svelte.js +77 -11
- package/dist/components/drawer/drawer-content.svelte +49 -42
- package/dist/components/drawer/drawer.stories.svelte +144 -224
- package/dist/components/drawer/index.d.ts +2 -0
- package/dist/components/drawer/index.js +2 -0
- package/dist/components/drawer/motion.d.ts +15 -0
- package/dist/components/drawer/motion.js +28 -0
- package/dist/components/dropdown/atoms.d.ts +1 -1
- package/dist/components/dropdown/atoms.js +1 -1
- package/dist/components/dropdown/bond.svelte.d.ts +5 -1
- package/dist/components/dropdown/dropdown-root.svelte +1 -1
- package/dist/components/dropdown/dropdown.stories.svelte +38 -41
- package/dist/components/dropdown/index.d.ts +1 -0
- package/dist/components/form/form.stories.svelte +58 -61
- package/dist/components/image/image.stories.svelte +9 -12
- package/dist/components/input/input.stories.svelte +11 -14
- package/dist/components/label/label.stories.svelte +1 -12
- package/dist/components/label/label.stories.svelte.d.ts +24 -4
- package/dist/components/lazy/lazy.stories.svelte +28 -35
- package/dist/components/lazy/lazy.svelte +28 -28
- package/dist/components/link/link.stories.svelte +1 -12
- package/dist/components/link/link.stories.svelte.d.ts +24 -4
- package/dist/components/list/list-item.svelte +20 -20
- package/dist/components/menu/atoms.d.ts +1 -0
- package/dist/components/menu/atoms.js +1 -0
- package/dist/components/menu/index.d.ts +2 -1
- package/dist/components/menu/index.js +1 -1
- package/dist/components/menu/menu-item.svelte +69 -51
- package/dist/components/menu/menu-item.svelte.d.ts +1 -0
- package/dist/components/menu/menu-list.svelte +40 -40
- package/dist/components/menu/menu.stories.svelte +9 -12
- package/dist/components/popover/bond.svelte.d.ts +20 -7
- package/dist/components/popover/bond.svelte.js +104 -45
- package/dist/components/popover/motion.d.ts +6 -0
- package/dist/components/popover/motion.js +56 -0
- package/dist/components/popover/popover-arrow.svelte +4 -4
- package/dist/components/popover/popover-content.svelte +137 -178
- package/dist/components/popover/popover-indicator.svelte +2 -1
- package/dist/components/popover/popover-root.svelte +1 -1
- package/dist/components/popover/popover.stories.svelte +49 -52
- package/dist/components/popover/types.d.ts +9 -7
- package/dist/components/portal/active-portal.svelte +29 -22
- package/dist/components/portal/active-portal.svelte.d.ts +2 -9
- package/dist/components/portal/portal-root.svelte +76 -83
- package/dist/components/portal/portal-root.svelte.d.ts +4 -6
- package/dist/components/portal/teleport.svelte +49 -50
- package/dist/components/portal/teleport.svelte.d.ts +3 -4
- package/dist/components/qr-code/qr-code.stories.svelte +18 -27
- package/dist/components/qr-code/qr-code.svelte +75 -75
- package/dist/components/radio/radio-group.stories.svelte +21 -30
- package/dist/components/radio/radio.stories.svelte +1 -10
- package/dist/components/radio/radio.svelte +109 -109
- package/dist/components/radio/types.d.ts +98 -0
- package/dist/components/radio/types.js +2 -0
- package/dist/components/root/root.svelte +104 -121
- package/dist/components/scrollable/scrollable-root.svelte.d.ts +2 -2
- package/dist/components/scrollable/scrollable.stories.svelte +95 -105
- package/dist/components/sidebar/index.d.ts +2 -0
- package/dist/components/sidebar/index.js +2 -0
- package/dist/components/sidebar/motion.svelte.d.ts +11 -0
- package/dist/components/sidebar/motion.svelte.js +16 -0
- package/dist/components/sidebar/sidebar-content.svelte +3 -2
- package/dist/components/sidebar/sidebar-root.svelte +39 -41
- package/dist/components/sidebar/sidebar.stories.svelte +43 -54
- package/dist/components/sidebar/types.d.ts +3 -12
- package/dist/components/tabs/tab/bond.svelte.d.ts +4 -1
- package/dist/components/tabs/tab/bond.svelte.js +4 -1
- package/dist/components/tabs/tabs.stories.svelte +31 -34
- package/dist/components/textarea/atoms.d.ts +1 -0
- package/dist/components/textarea/atoms.js +1 -0
- package/dist/components/textarea/textarea-input.svelte +9 -6
- package/dist/components/textarea/textarea-root.svelte +9 -9
- package/dist/components/textarea/textarea-root.svelte.d.ts +2 -0
- package/dist/components/tooltip/tooltip-trigger.svelte +39 -37
- package/dist/components/tooltip/tooltip-trigger.svelte.d.ts +1 -0
- package/dist/components/tooltip/tooltip.stories.svelte +7 -10
- package/dist/components/tree/tree.stories.svelte +102 -94
- package/dist/context/preset.svelte.d.ts +3 -3
- package/dist/icons/icon-copy.svelte +6 -0
- package/dist/{components/radio/types.svelte.d.ts → icons/icon-copy.svelte.d.ts} +3 -3
- package/dist/utils/function.d.ts +2 -0
- package/dist/utils/function.js +6 -0
- package/dist/utils/markdown-to-llm.d.ts +28 -0
- package/dist/utils/markdown-to-llm.js +76 -0
- package/package.json +6 -10
- package/dist/actions/animation.svelte.d.ts +0 -6
- package/dist/actions/animation.svelte.js +0 -14
- package/dist/actions/clickout.svelte.d.ts +0 -2
- package/dist/actions/clickout.svelte.js +0 -15
- package/dist/actions/popover.svelte.d.ts +0 -19
- package/dist/actions/popover.svelte.js +0 -81
- package/dist/actions/portal.svelte.d.ts +0 -8
- package/dist/actions/portal.svelte.js +0 -32
- package/dist/attachments/gsap.svelte.d.ts +0 -2
- package/dist/attachments/gsap.svelte.js +0 -26
- package/dist/components/radio/types.svelte +0 -0
- package/llm/composition.md +0 -395
- package/llm/crafting.md +0 -838
- package/llm/motion.md +0 -970
- package/llm/philosophy.md +0 -23
- package/llm/preset-variant-integration.md +0 -516
- package/llm/preset.md +0 -383
- package/llm/styling.md +0 -216
- package/llm/usage.md +0 -46
- package/llm/variants.md +0 -1259
|
@@ -1,207 +1,261 @@
|
|
|
1
|
-
<script lang="ts" generics="E extends keyof HTMLElementTagNameMap = 'div', B extends Base = Base">
|
|
2
|
-
import type { HTMLAttributes } from 'svelte/elements';
|
|
3
|
-
import type { Base, HtmlAtomProps, SnippetBase } from './types';
|
|
4
|
-
import { RootBond } from '../root';
|
|
5
|
-
import { HtmlElement } from '../element';
|
|
6
|
-
import { cn, type ClassValue, type VariantDefinition } from '../../utils';
|
|
7
|
-
import { getPreset } from '../../context';
|
|
8
|
-
import type { PresetModuleName } from '../../context/preset.svelte';
|
|
9
|
-
import type { Bond } from '../../shared';
|
|
10
|
-
import SnippetRenderer from './snippet-renderer.svelte';
|
|
11
|
-
import type { Component } from 'svelte';
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
: [
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
const
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
1
|
+
<script lang="ts" generics="E extends keyof HTMLElementTagNameMap = 'div', B extends Base = Base">
|
|
2
|
+
import type { HTMLAttributes } from 'svelte/elements';
|
|
3
|
+
import type { Base, HtmlAtomProps, SnippetBase } from './types';
|
|
4
|
+
import { RootBond } from '../root';
|
|
5
|
+
import { HtmlElement } from '../element';
|
|
6
|
+
import { cn, type ClassValue, type VariantDefinition } from '../../utils';
|
|
7
|
+
import { getPreset } from '../../context';
|
|
8
|
+
import type { PresetModuleName } from '../../context/preset.svelte';
|
|
9
|
+
import type { Bond } from '../../shared';
|
|
10
|
+
import SnippetRenderer from './snippet-renderer.svelte';
|
|
11
|
+
import type { Component } from 'svelte';
|
|
12
|
+
import { call } from '../../utils/function';
|
|
13
|
+
|
|
14
|
+
type Element = HTMLElementTagNameMap[E];
|
|
15
|
+
|
|
16
|
+
const rootBond = RootBond.get();
|
|
17
|
+
|
|
18
|
+
let {
|
|
19
|
+
class: klass = '',
|
|
20
|
+
as = 'div',
|
|
21
|
+
base = undefined,
|
|
22
|
+
preset: presetKey = undefined,
|
|
23
|
+
bond = undefined,
|
|
24
|
+
variants = undefined,
|
|
25
|
+
children: childrenProp = undefined,
|
|
26
|
+
...restProps
|
|
27
|
+
}: HtmlAtomProps<E, B> & Omit<HTMLAttributes<Element>, 'children'> = $props();
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Resolve variant definition to props
|
|
31
|
+
*/
|
|
32
|
+
// Cache for resolved variants to avoid recomputation
|
|
33
|
+
// Key: JSON stringified combination of variant props
|
|
34
|
+
const variantCache = new Map<string, Record<string, any>>();
|
|
35
|
+
|
|
36
|
+
// Memoize preset resolution - only recompute when presetKey or bond changes
|
|
37
|
+
const preset = $derived.by(() => {
|
|
38
|
+
if (!presetKey) return undefined;
|
|
39
|
+
const result = getPreset(presetKey as PresetModuleName)?.apply?.(bond, [bond]);
|
|
40
|
+
// Handle deferred preset result (factory function)
|
|
41
|
+
return call(result);
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
const presetProps = $derived(preset?.variants);
|
|
45
|
+
|
|
46
|
+
// Resolve local variants - either VariantDefinition or function
|
|
47
|
+
const localVariants = $derived.by(() => {
|
|
48
|
+
if (!variants) return undefined;
|
|
49
|
+
|
|
50
|
+
// If it's a function, call it directly
|
|
51
|
+
if (typeof variants === 'function') {
|
|
52
|
+
return variants(bond as Bond, restProps);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// Otherwise it's a VariantDefinition, resolve it
|
|
56
|
+
return resolveVariants(variants, bond as Bond, restProps);
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
// Merge preset variants with local variants
|
|
60
|
+
// Memoized to avoid recomputation when inputs haven't changed
|
|
61
|
+
const mergedVariants = $derived.by(() => {
|
|
62
|
+
// No variants at all
|
|
63
|
+
if (!presetProps && !localVariants) return undefined;
|
|
64
|
+
|
|
65
|
+
// Only preset variants (raw object from preset)
|
|
66
|
+
if (presetProps && !localVariants) {
|
|
67
|
+
// Convert preset variants to VariantDefinition-like structure
|
|
68
|
+
const variantDef: VariantDefinition<any> = {
|
|
69
|
+
class: preset?.class ?? '',
|
|
70
|
+
variants: presetProps,
|
|
71
|
+
compounds: preset?.compounds ?? [],
|
|
72
|
+
defaults: preset?.defaults ?? {}
|
|
73
|
+
};
|
|
74
|
+
return resolveVariants(variantDef, bond as Bond, restProps);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
// Only local variants
|
|
78
|
+
if (!presetProps && localVariants) {
|
|
79
|
+
return localVariants;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
// Both exist - merge them
|
|
83
|
+
// When both preset and local variants exist, we need to merge the resolved props
|
|
84
|
+
const presetVariantDef: VariantDefinition<any> = {
|
|
85
|
+
class: preset?.class ?? '',
|
|
86
|
+
variants: presetProps ?? {},
|
|
87
|
+
compounds: preset?.compounds ?? [],
|
|
88
|
+
defaults: preset?.defaults ?? {}
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
const presetResolved = resolveVariants(presetVariantDef, bond as Bond, restProps);
|
|
92
|
+
|
|
93
|
+
// Merge the resolved variant props
|
|
94
|
+
// Local variant classes and attributes override preset
|
|
95
|
+
const presetClasses = Array.isArray(presetResolved.class)
|
|
96
|
+
? presetResolved.class
|
|
97
|
+
: [presetResolved.class];
|
|
98
|
+
const localClasses = Array.isArray(localVariants?.class)
|
|
99
|
+
? localVariants.class
|
|
100
|
+
: [localVariants?.class];
|
|
101
|
+
|
|
102
|
+
return {
|
|
103
|
+
class: [...presetClasses, ...localClasses].filter(Boolean),
|
|
104
|
+
...presetResolved,
|
|
105
|
+
...localVariants
|
|
106
|
+
};
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
const presetClassString = $derived(cn(preset?.class));
|
|
110
|
+
|
|
111
|
+
const _klass = $derived.by(() => {
|
|
112
|
+
const klassStr = cn(klass ?? '');
|
|
113
|
+
// Check for $preset placeholder first
|
|
114
|
+
if (!klassStr.includes('$preset')) {
|
|
115
|
+
// No placeholder - normal merge: variants override direct class
|
|
116
|
+
return cn(klass, mergedVariants?.class ?? '');
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
// Has placeholder - calculate position and inject preset classes
|
|
120
|
+
const parts = klassStr.split('$preset');
|
|
121
|
+
|
|
122
|
+
// Only keep the last $preset placeholder
|
|
123
|
+
const beforeLastPlaceholder = parts.slice(0, -1).join('');
|
|
124
|
+
const afterLastPlaceholder = parts[parts.length - 1];
|
|
125
|
+
|
|
126
|
+
// Merge: before + preset + variants + after
|
|
127
|
+
return cn(
|
|
128
|
+
beforeLastPlaceholder,
|
|
129
|
+
presetClassString,
|
|
130
|
+
mergedVariants?.class ?? '',
|
|
131
|
+
afterLastPlaceholder
|
|
132
|
+
);
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
const _base = $derived(base ?? preset?.base);
|
|
136
|
+
const _as = $derived(as ?? preset?.as);
|
|
137
|
+
const _restProps = $derived.by(() => {
|
|
138
|
+
const {
|
|
139
|
+
class: klassPreset,
|
|
140
|
+
base,
|
|
141
|
+
as,
|
|
142
|
+
variants: presetProps,
|
|
143
|
+
...restPresetProps
|
|
144
|
+
} = preset ?? {};
|
|
145
|
+
const { class: variantClass, ...variantsRestProps } = mergedVariants ?? {};
|
|
146
|
+
|
|
147
|
+
return { ...restPresetProps, ...variantsRestProps, ...restProps };
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
const isSnippet = $derived(typeof _base === 'function' && _base.length === 1 && !_base.prototype);
|
|
151
|
+
|
|
152
|
+
const snippet = $derived(_base as SnippetBase);
|
|
153
|
+
|
|
154
|
+
const atom = rootBond?.state?.props?.renderers?.html ?? HtmlElement;
|
|
155
|
+
|
|
156
|
+
const renderer = $derived.by(() => {
|
|
157
|
+
if (isSnippet)
|
|
158
|
+
return {
|
|
159
|
+
component: SnippetRenderer,
|
|
160
|
+
props: { snippet: snippet, class: _klass, as: _as, children: childrenProp, ..._restProps }
|
|
161
|
+
};
|
|
162
|
+
|
|
163
|
+
return {
|
|
164
|
+
component: base ?? atom,
|
|
165
|
+
props: { class: _klass, as: _as, ..._restProps }
|
|
166
|
+
};
|
|
167
|
+
}) as { component: Component; props: Record<string, any> };
|
|
168
|
+
|
|
169
|
+
function resolveVariants(
|
|
170
|
+
def: VariantDefinition<any>,
|
|
171
|
+
bond: Bond | null | undefined,
|
|
172
|
+
props: Record<string, any>
|
|
173
|
+
): Record<string, any> {
|
|
174
|
+
const { variants: variantMap, compounds, defaults, class: baseClass } = def;
|
|
175
|
+
|
|
176
|
+
// Merge props with defaults
|
|
177
|
+
const finalProps = { ...defaults, ...props };
|
|
178
|
+
|
|
179
|
+
// Create cache key from final props (only variant-related props)
|
|
180
|
+
const variantKeys = variantMap ? Object.keys(variantMap) : [];
|
|
181
|
+
const relevantProps = Object.fromEntries(
|
|
182
|
+
Object.entries(finalProps).filter(([key]) => variantKeys.includes(key))
|
|
183
|
+
);
|
|
184
|
+
const cacheKey = JSON.stringify({ relevantProps, baseClass, compounds });
|
|
185
|
+
|
|
186
|
+
// Check cache
|
|
187
|
+
if (variantCache.has(cacheKey)) {
|
|
188
|
+
return variantCache.get(cacheKey)!;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
const classes: ClassValue[] = [];
|
|
192
|
+
const attributes: Record<string, any> = {};
|
|
193
|
+
|
|
194
|
+
// Add base class
|
|
195
|
+
if (baseClass) classes.push(baseClass);
|
|
196
|
+
|
|
197
|
+
// Add variant classes
|
|
198
|
+
if (variantMap) {
|
|
199
|
+
for (const [key, value] of Object.entries(finalProps)) {
|
|
200
|
+
const variantValue = variantMap[key]?.[value as string];
|
|
201
|
+
if (variantValue !== undefined) {
|
|
202
|
+
const resolved = typeof variantValue === 'function' ? variantValue(bond) : variantValue;
|
|
203
|
+
|
|
204
|
+
if (typeof resolved === 'string') {
|
|
205
|
+
classes.push(resolved);
|
|
206
|
+
} else if (typeof resolved === 'object' && resolved !== null) {
|
|
207
|
+
if ('class' in resolved) {
|
|
208
|
+
classes.push(resolved.class);
|
|
209
|
+
}
|
|
210
|
+
// Add other attributes
|
|
211
|
+
Object.entries(resolved).forEach(([k, v]) => {
|
|
212
|
+
if (k !== 'class') {
|
|
213
|
+
attributes[k] = v;
|
|
214
|
+
}
|
|
215
|
+
});
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
// Add compound variants
|
|
222
|
+
if (compounds) {
|
|
223
|
+
for (const compound of compounds) {
|
|
224
|
+
const { class: compoundClass, ...compoundProps } = compound;
|
|
225
|
+
const matches = Object.entries(compoundProps).every(
|
|
226
|
+
([key, value]) => finalProps[key] === value
|
|
227
|
+
);
|
|
228
|
+
if (matches) {
|
|
229
|
+
if (compoundClass) classes.push(compoundClass);
|
|
230
|
+
// Add compound attributes
|
|
231
|
+
Object.entries(compound).forEach(([k, v]) => {
|
|
232
|
+
if (k !== 'class' && !Object.keys(compoundProps).includes(k)) {
|
|
233
|
+
attributes[k] = v;
|
|
234
|
+
}
|
|
235
|
+
});
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
const result = {
|
|
241
|
+
class: classes,
|
|
242
|
+
...attributes
|
|
243
|
+
};
|
|
244
|
+
|
|
245
|
+
// Store in cache (limit cache size to prevent memory leaks)
|
|
246
|
+
if (variantCache.size > 100) {
|
|
247
|
+
// Clear oldest entry (first in Map)
|
|
248
|
+
const firstKey = variantCache.keys().next().value;
|
|
249
|
+
if (firstKey) variantCache.delete(firstKey);
|
|
250
|
+
}
|
|
251
|
+
variantCache.set(cacheKey, result);
|
|
252
|
+
|
|
253
|
+
return result;
|
|
254
|
+
}
|
|
255
|
+
</script>
|
|
256
|
+
|
|
257
|
+
<renderer.component {...renderer.props}>
|
|
258
|
+
{#snippet children(args: any)}
|
|
259
|
+
{@render (childrenProp as any)?.(args)}
|
|
260
|
+
{/snippet}
|
|
261
|
+
</renderer.component>
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
<script module>
|
|
2
2
|
import { defineMeta } from '@storybook/addon-svelte-csf';
|
|
3
3
|
import AvatarCmp from './avatar.svelte';
|
|
4
|
-
import Root from '../root/root.svelte';
|
|
5
4
|
import CalendarRegularIcon from '../../icons/icon-arrow-down.svelte';
|
|
6
5
|
|
|
7
6
|
const { Story } = defineMeta({
|
|
@@ -10,18 +9,14 @@
|
|
|
10
9
|
</script>
|
|
11
10
|
|
|
12
11
|
<Story name="Avatar">
|
|
13
|
-
<
|
|
14
|
-
|
|
15
|
-
<div class="flex h-full w-full items-center justify-center gap-4">
|
|
16
|
-
<AvatarCmp alt="Abdelhalim Riache" />
|
|
12
|
+
<div class="flex h-full w-full items-center justify-center gap-4">
|
|
13
|
+
<AvatarCmp alt="Abdelhalim Riache" />
|
|
17
14
|
|
|
18
|
-
|
|
15
|
+
<AvatarCmp src={CalendarRegularIcon} alt="Abdelhalim Riache" />
|
|
19
16
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
{/snippet}
|
|
26
|
-
</Root>
|
|
17
|
+
<AvatarCmp
|
|
18
|
+
src="https://sevennaturalwonders.org/wp-content/uploads/2023/12/1-Mount-Fuji.jpg"
|
|
19
|
+
alt="Mount Fuji"
|
|
20
|
+
/>
|
|
21
|
+
</div>
|
|
27
22
|
</Story>
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
<script module>
|
|
2
2
|
import { defineMeta } from '@storybook/addon-svelte-csf';
|
|
3
|
-
import Root from '../root/root.svelte';
|
|
4
3
|
import { Badge as BadgeModule } from '.';
|
|
5
4
|
|
|
6
5
|
const { Story } = defineMeta({
|
|
@@ -9,9 +8,5 @@
|
|
|
9
8
|
</script>
|
|
10
9
|
|
|
11
10
|
<Story name="Badge">
|
|
12
|
-
<
|
|
13
|
-
{#snippet children({ args })}
|
|
14
|
-
<BadgeModule>Badge</BadgeModule>
|
|
15
|
-
{/snippet}
|
|
16
|
-
</Root>
|
|
11
|
+
<BadgeModule>Badge</BadgeModule>
|
|
17
12
|
</Story>
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
<HtmlAtom
|
|
9
9
|
preset="badge"
|
|
10
10
|
class={[
|
|
11
|
-
'bg-foreground/10 border-border text-foreground inline-flex h-auto items-center rounded-full px-2.5 py-0.5 text-xs font-medium',
|
|
11
|
+
'bg-foreground/10 border-border text-foreground inline-flex h-auto w-fit items-center rounded-full px-2.5 py-0.5 text-xs font-medium',
|
|
12
12
|
'$preset',
|
|
13
13
|
klass
|
|
14
14
|
]}
|
|
@@ -1,21 +1,16 @@
|
|
|
1
|
-
<script module>
|
|
2
|
-
import { defineMeta } from '@storybook/addon-svelte-csf';
|
|
3
|
-
import
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
<
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
<BreadcrumbModule.Item href="/vehicles">Vehicles</BreadcrumbModule.Item>
|
|
18
|
-
</BreadcrumbModule.Root>
|
|
19
|
-
{/snippet}
|
|
20
|
-
</Root>
|
|
21
|
-
</Story>
|
|
1
|
+
<script module>
|
|
2
|
+
import { defineMeta } from '@storybook/addon-svelte-csf';
|
|
3
|
+
import { Breadcrumb as BreadcrumbModule } from '.';
|
|
4
|
+
|
|
5
|
+
const { Story } = defineMeta({
|
|
6
|
+
title: 'ATOMS/Breadcrumb'
|
|
7
|
+
});
|
|
8
|
+
</script>
|
|
9
|
+
|
|
10
|
+
<Story name="Breadcrumb">
|
|
11
|
+
<BreadcrumbModule.Root>
|
|
12
|
+
<BreadcrumbModule.Item href="/">Home</BreadcrumbModule.Item>
|
|
13
|
+
<BreadcrumbModule.Separator>/</BreadcrumbModule.Separator>
|
|
14
|
+
<BreadcrumbModule.Item href="/vehicles">Vehicles</BreadcrumbModule.Item>
|
|
15
|
+
</BreadcrumbModule.Root>
|
|
16
|
+
</Story>
|
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
<script module>
|
|
2
2
|
import { defineMeta } from '@storybook/addon-svelte-csf';
|
|
3
|
-
import Root from '../root/root.svelte';
|
|
4
3
|
import ButtonCmp from './button.svelte';
|
|
5
|
-
import { defineVariants } from '../../utils/variant';
|
|
6
4
|
|
|
7
5
|
const { Story } = defineMeta({
|
|
8
6
|
title: 'ATOMS/Button',
|
|
@@ -20,41 +18,10 @@
|
|
|
20
18
|
</script>
|
|
21
19
|
|
|
22
20
|
<script lang="ts">
|
|
23
|
-
const variants = defineVariants((bond) => ({
|
|
24
|
-
variants: {
|
|
25
|
-
variant: {
|
|
26
|
-
primary: {
|
|
27
|
-
class: 'bg-primary text-primary-foreground hover:bg-primary/80 active:bg-primary/90'
|
|
28
|
-
},
|
|
29
|
-
secondary: {
|
|
30
|
-
class:
|
|
31
|
-
'bg-secondary text-secondary-foreground hover:bg-secondary/80 active:bg-secondary/90'
|
|
32
|
-
},
|
|
33
|
-
destructive: {
|
|
34
|
-
class:
|
|
35
|
-
'bg-destructive text-destructive-foreground hover:bg-destructive/80 active:bg-destructive/90'
|
|
36
|
-
},
|
|
37
|
-
outline: {
|
|
38
|
-
class:
|
|
39
|
-
'bg-transparent hover:bg-foreground/5 active:bg-foreground/10 border border-border text-foreground'
|
|
40
|
-
},
|
|
41
|
-
ghost: {
|
|
42
|
-
class:
|
|
43
|
-
'bg-transparent text-foreground hover:bg-foreground/5 active:bg-foreground/10 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2'
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
},
|
|
47
|
-
compounds: [],
|
|
48
|
-
defaults: {
|
|
49
|
-
variant: 'destructive'
|
|
50
|
-
}
|
|
51
|
-
}));
|
|
52
21
|
</script>
|
|
53
22
|
|
|
54
23
|
<Story name="Button">
|
|
55
24
|
{#snippet template(args)}
|
|
56
|
-
<
|
|
57
|
-
<ButtonCmp {variants} {...args}>Clicke me</ButtonCmp>
|
|
58
|
-
</Root>
|
|
25
|
+
<ButtonCmp {...args}>Click me</ButtonCmp>
|
|
59
26
|
{/snippet}
|
|
60
27
|
</Story>
|
|
@@ -34,6 +34,8 @@
|
|
|
34
34
|
});
|
|
35
35
|
|
|
36
36
|
function handleClick() {
|
|
37
|
+
if (day.disabled) return;
|
|
38
|
+
|
|
37
39
|
if (isRange) {
|
|
38
40
|
const start = calendarBond?.state.props.start;
|
|
39
41
|
if (!start) {
|
|
@@ -58,13 +60,16 @@
|
|
|
58
60
|
{preset}
|
|
59
61
|
class={[
|
|
60
62
|
'calendar-day text-foreground border-border hover:bg-accent hover:text-accent-foreground h-12 cursor-pointer border-b border-l p-1 transition-colors',
|
|
61
|
-
day.offmonth && 'text-muted-foreground bg-muted/
|
|
62
|
-
day.weekend && 'bg-
|
|
63
|
+
day.offmonth && !day.disabled && 'text-muted-foreground/50 bg-muted/50',
|
|
64
|
+
day.weekend && 'bg-accent',
|
|
63
65
|
isSelected &&
|
|
64
66
|
'bg-primary text-primary-foreground hover:bg-primary hover:text-primary-foreground',
|
|
65
67
|
isSelected && day.offmonth && 'bg-primary/70',
|
|
66
|
-
day.today &&
|
|
67
|
-
|
|
68
|
+
day.today &&
|
|
69
|
+
!day.disabled &&
|
|
70
|
+
!isSelected &&
|
|
71
|
+
'border-primary bg-primary/5 border-2 font-semibold',
|
|
72
|
+
day.disabled && 'pointer-events-none opacity-25',
|
|
68
73
|
klass
|
|
69
74
|
]}
|
|
70
75
|
data-disabled={day.disabled}
|