@svelte-atoms/core 1.0.0-alpha.25 → 1.0.0-alpha.26
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 +645 -645
- package/dist/components/accordion/accordion-root.svelte +1 -1
- package/dist/components/accordion/item/accordion-item-body.svelte +1 -1
- package/dist/components/accordion/item/accordion-item-header.svelte +5 -1
- package/dist/components/accordion/item/accordion-item-indicator.svelte +1 -1
- package/dist/components/accordion/item/accordion-item-root.svelte +1 -1
- package/dist/components/alert/alert-actions.svelte +1 -1
- package/dist/components/alert/alert-close-button.svelte +1 -1
- package/dist/components/alert/alert-content.svelte +1 -1
- package/dist/components/alert/alert-description.svelte +1 -1
- package/dist/components/alert/alert-icon.svelte +1 -1
- package/dist/components/alert/alert-root.svelte +1 -1
- package/dist/components/alert/alert-title.svelte +1 -1
- package/dist/components/atom/html-atom.svelte +201 -217
- package/dist/components/badge/badge.svelte +1 -1
- package/dist/components/breadcrumb/breadcrumb-item.svelte +1 -1
- package/dist/components/breadcrumb/breadcrumb-root.svelte +1 -1
- package/dist/components/breadcrumb/breadcrumb-separator.svelte +1 -1
- package/dist/components/button/button.stories.svelte +57 -57
- package/dist/components/button/button.svelte +1 -1
- package/dist/components/button/button.svelte.d.ts +4 -1
- package/dist/components/button/types.d.ts +1 -1
- package/dist/components/card/card-body.svelte +1 -1
- package/dist/components/card/card-description.svelte +1 -1
- package/dist/components/card/card-footer.svelte +1 -1
- package/dist/components/card/card-header.svelte +1 -1
- package/dist/components/card/card-media.svelte +1 -1
- package/dist/components/card/card-subtitle.svelte +1 -1
- package/dist/components/card/card-title.svelte +5 -1
- package/dist/components/checkbox/checkbox.svelte +39 -28
- package/dist/components/collapsible/collapsible-body.svelte +1 -1
- package/dist/components/collapsible/collapsible-header.svelte +1 -1
- package/dist/components/collapsible/collapsible-indicator.svelte +1 -1
- package/dist/components/collapsible/collapsible-root.svelte +1 -1
- package/dist/components/combobox/atoms.d.ts +5 -1
- package/dist/components/combobox/atoms.js +5 -1
- package/dist/components/combobox/{combobox-input.svelte → combobox-control.svelte} +3 -3
- package/dist/components/combobox/{combobox-input.svelte.d.ts → combobox-control.svelte.d.ts} +3 -3
- package/dist/components/combobox/combobox-trigger.svelte +1 -1
- package/dist/components/combobox/compobox-item.svelte +1 -1
- package/dist/components/container/container.svelte +1 -1
- package/dist/components/datagrid/datagrid-body.svelte +1 -1
- package/dist/components/datagrid/datagrid-footer.svelte +1 -1
- package/dist/components/datagrid/datagrid-header.svelte +1 -1
- package/dist/components/datagrid/datagrid-root.svelte +1 -1
- package/dist/components/datagrid/datagrid.stories.svelte +75 -75
- package/dist/components/datagrid/td/datagrid-td.svelte +1 -1
- package/dist/components/datagrid/th/datagrid-th-sort-icon.svelte +1 -1
- package/dist/components/datagrid/th/datagrid-th.svelte +1 -1
- package/dist/components/dialog/dialog-body.svelte +1 -1
- package/dist/components/dialog/dialog-close-button.svelte +1 -1
- package/dist/components/dialog/dialog-content.svelte +8 -11
- package/dist/components/dialog/dialog-description.svelte +1 -1
- package/dist/components/dialog/dialog-footer.svelte +1 -1
- package/dist/components/dialog/dialog-header.svelte +1 -1
- package/dist/components/dialog/dialog-root.svelte +123 -120
- package/dist/components/dialog/dialog-root.svelte.d.ts +3 -1
- package/dist/components/dialog/dialog-title.svelte +1 -1
- package/dist/components/drawer/drawer-backdrop.svelte +1 -1
- package/dist/components/drawer/drawer-body.svelte +1 -1
- package/dist/components/drawer/drawer-description.svelte +1 -1
- package/dist/components/drawer/drawer-footer.svelte +1 -1
- package/dist/components/drawer/drawer-header.svelte +1 -1
- package/dist/components/drawer/drawer-root.svelte +118 -113
- package/dist/components/drawer/drawer-root.svelte.d.ts +5 -2
- package/dist/components/drawer/drawer-title.svelte +1 -1
- package/dist/components/dropdown/dropdown-placeholder.svelte +1 -1
- package/dist/components/dropdown/dropdown-query.svelte +1 -1
- package/dist/components/dropdown/dropdown-trigger.svelte +1 -1
- package/dist/components/dropdown/dropdown-value.svelte +1 -3
- package/dist/components/dropdown/item/bond.svelte.d.ts +4 -0
- package/dist/components/dropdown/item/bond.svelte.js +9 -0
- package/dist/components/dropdown/item/dropdown-item.svelte +10 -6
- package/dist/components/form/field/bond.svelte.d.ts +8 -0
- package/dist/components/form/field/bond.svelte.js +13 -1
- package/dist/components/form/field/field-control.svelte +7 -0
- package/dist/components/form/field/field-control.svelte.d.ts +2 -2
- package/dist/components/form/form.stories.svelte +3 -3
- package/dist/components/input/atoms.d.ts +5 -1
- package/dist/components/input/atoms.js +5 -1
- package/dist/components/input/{input-value.svelte → input-control.svelte} +107 -113
- package/dist/components/input/input-control.svelte.d.ts +27 -0
- package/dist/components/input/input-icon.svelte +1 -1
- package/dist/components/input/input-placeholder.svelte +54 -56
- package/dist/components/input/input-root.svelte +5 -12
- package/dist/components/input/input-root.svelte.d.ts +3 -20
- package/dist/components/input/input.stories.svelte +2 -2
- package/dist/components/input/types.d.ts +22 -0
- package/dist/components/input/types.js +1 -0
- package/dist/components/list/list-group.svelte +1 -1
- package/dist/components/list/list-item.svelte +1 -1
- package/dist/components/list/list-root.svelte +6 -1
- package/dist/components/list/list-title.svelte +1 -1
- package/dist/components/menu/menu-list.svelte +1 -1
- package/dist/components/popover/bond.svelte.d.ts +2 -0
- package/dist/components/popover/bond.svelte.js +1 -1
- package/dist/components/popover/popover-arrow.svelte +111 -117
- package/dist/components/popover/popover-arrow.svelte.d.ts +1 -2
- package/dist/components/popover/popover-content.svelte +139 -147
- package/dist/components/popover/popover-content.svelte.d.ts +3 -17
- package/dist/components/popover/popover-indicator.svelte +1 -1
- package/dist/components/popover/popover-root.svelte +49 -63
- package/dist/components/popover/popover-root.svelte.d.ts +1 -15
- package/dist/components/popover/popover-trigger.svelte +47 -56
- package/dist/components/popover/popover-trigger.svelte.d.ts +2 -8
- package/dist/components/popover/types.d.ts +39 -0
- package/dist/components/popover/types.js +1 -0
- package/dist/components/portal/active-portal.svelte +22 -16
- package/dist/components/portal/active-portal.svelte.d.ts +2 -2
- package/dist/components/portal/portal-inner.svelte +1 -1
- package/dist/components/portal/portal-root.svelte +1 -1
- package/dist/components/portal/teleport.svelte +55 -49
- package/dist/components/portal/teleport.svelte.d.ts +3 -2
- package/dist/components/radio/radio-group.stories.svelte +4 -4
- package/dist/components/radio/radio.svelte +3 -3
- package/dist/components/root/root.css +24 -66
- package/dist/components/root/root.svelte +1 -1
- package/dist/components/sidebar/sidebar-content.svelte +2 -16
- package/dist/components/sidebar/sidebar-content.svelte.d.ts +2 -9
- package/dist/components/sidebar/sidebar-root.svelte +4 -23
- package/dist/components/sidebar/sidebar-root.svelte.d.ts +2 -13
- package/dist/components/sidebar/types.d.ts +19 -0
- package/dist/components/sidebar/types.js +1 -0
- package/dist/components/stack/stack-item.svelte +5 -1
- package/dist/components/stack/stack-root.svelte +5 -1
- package/dist/components/tabs/tab/tab-body.svelte +1 -1
- package/dist/components/tabs/tab/tab-description.svelte +1 -1
- package/dist/components/tabs/tab/tab-header.svelte +2 -2
- package/dist/components/tabs/tab/tab-root.svelte +6 -1
- package/dist/components/tabs/tabs-body.svelte +1 -1
- package/dist/components/tabs/tabs-header.svelte +1 -1
- package/dist/components/tabs/tabs-root.svelte +1 -1
- package/dist/components/textarea/textarea-input.svelte +2 -1
- package/dist/components/toast/toast-description.svelte +1 -1
- package/dist/components/toast/toast-root.svelte +1 -1
- package/dist/components/toast/toast-title.svelte +1 -1
- package/dist/components/tree/tree-body.svelte +1 -1
- package/dist/components/tree/tree-header.svelte +1 -1
- package/dist/components/tree/tree-indicator.svelte +1 -1
- package/dist/components/tree/tree-root.svelte +1 -1
- package/dist/context/preset.svelte.d.ts +1 -1
- package/llm/composition.md +395 -395
- package/llm/crafting.md +838 -838
- package/llm/motion.md +970 -970
- package/llm/philosophy.md +23 -23
- package/llm/preset-variant-integration.md +516 -516
- package/llm/preset.md +383 -383
- package/llm/styling.md +216 -216
- package/llm/usage.md +46 -46
- package/llm/variants.md +712 -712
- package/package.json +437 -437
- package/dist/components/input/input-value.svelte.d.ts +0 -19
|
@@ -40,7 +40,11 @@
|
|
|
40
40
|
{as}
|
|
41
41
|
{bond}
|
|
42
42
|
preset="accordion.item.header"
|
|
43
|
-
class={[
|
|
43
|
+
class={[
|
|
44
|
+
'border-border relative box-border flex w-full cursor-pointer items-center',
|
|
45
|
+
'$preset',
|
|
46
|
+
klass
|
|
47
|
+
]}
|
|
44
48
|
onmount={onmount?.bind(bond.state)}
|
|
45
49
|
ondestroy={ondestroy?.bind(bond.state)}
|
|
46
50
|
animate={animate?.bind(bond.state)}
|
|
@@ -42,7 +42,7 @@
|
|
|
42
42
|
|
|
43
43
|
<HtmlAtom
|
|
44
44
|
preset="accordion.item.indicator"
|
|
45
|
-
class={['pointer-events-none flex items-center justify-center', '$preset', klass]}
|
|
45
|
+
class={['border-border pointer-events-none flex items-center justify-center', '$preset', klass]}
|
|
46
46
|
onmount={onmount?.bind(bond.state)}
|
|
47
47
|
ondestroy={ondestroy?.bind(bond.state)}
|
|
48
48
|
animate={animate?.bind(bond.state)}
|
|
@@ -39,7 +39,7 @@
|
|
|
39
39
|
<HtmlAtom
|
|
40
40
|
{bond}
|
|
41
41
|
preset="alert.actions"
|
|
42
|
-
class={['alert-actions mt-3 flex items-center gap-2', '$preset', klass]}
|
|
42
|
+
class={['alert-actions border-border mt-3 flex items-center gap-2', '$preset', klass]}
|
|
43
43
|
onmount={onmount?.bind(bond.state)}
|
|
44
44
|
ondestroy={ondestroy?.bind(bond.state)}
|
|
45
45
|
animate={animate?.bind(bond.state)}
|
|
@@ -45,7 +45,7 @@
|
|
|
45
45
|
{bond}
|
|
46
46
|
preset="alert.close-button"
|
|
47
47
|
class={[
|
|
48
|
-
'alert-close-button absolute top-2 right-2 rounded p-1 transition-colors hover:bg-black/10 dark:hover:bg-white/10',
|
|
48
|
+
'alert-close-button border-border absolute top-2 right-2 rounded p-1 transition-colors hover:bg-black/10 dark:hover:bg-white/10',
|
|
49
49
|
'focus:ring-2 focus:ring-offset-1 focus:outline-none',
|
|
50
50
|
{
|
|
51
51
|
'focus:ring-blue-500': bond?.state.variant === 'info',
|
|
@@ -39,7 +39,7 @@
|
|
|
39
39
|
<HtmlAtom
|
|
40
40
|
{bond}
|
|
41
41
|
preset="alert.content"
|
|
42
|
-
class={['alert-content flex-1 space-y-1', '$preset', klass]}
|
|
42
|
+
class={['alert-content border-border flex-1 space-y-1', '$preset', klass]}
|
|
43
43
|
onmount={onmount?.bind(bond.state)}
|
|
44
44
|
ondestroy={ondestroy?.bind(bond.state)}
|
|
45
45
|
animate={animate?.bind(bond.state)}
|
|
@@ -37,7 +37,7 @@
|
|
|
37
37
|
<HtmlAtom
|
|
38
38
|
{bond}
|
|
39
39
|
preset="alert.description"
|
|
40
|
-
class={['alert-description mt-1 text-sm leading-relaxed', '$preset', klass]}
|
|
40
|
+
class={['alert-description border-border mt-1 text-sm leading-relaxed', '$preset', klass]}
|
|
41
41
|
onmount={onmount?.bind(bond.state)}
|
|
42
42
|
ondestroy={ondestroy?.bind(bond.state)}
|
|
43
43
|
animate={animate?.bind(bond.state)}
|
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
{base}
|
|
41
41
|
preset="alert.icon"
|
|
42
42
|
class={[
|
|
43
|
-
'alert-icon inline-flex aspect-square h-5 items-center justify-center rounded-full text-sm font-medium',
|
|
43
|
+
'alert-icon border-border inline-flex aspect-square h-5 items-center justify-center rounded-full text-sm font-medium',
|
|
44
44
|
'$preset',
|
|
45
45
|
klass
|
|
46
46
|
]}
|
|
@@ -94,7 +94,7 @@
|
|
|
94
94
|
<HtmlAtom
|
|
95
95
|
preset="alert"
|
|
96
96
|
class={[
|
|
97
|
-
'alert relative flex gap-3 rounded-md border p-4 transition-all duration-200',
|
|
97
|
+
'alert border-border relative flex gap-3 rounded-md border p-4 transition-all duration-200',
|
|
98
98
|
// Base styles
|
|
99
99
|
'bg-background text-foreground',
|
|
100
100
|
// State styles
|
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
{as}
|
|
39
39
|
{bond}
|
|
40
40
|
preset="alert.title"
|
|
41
|
-
class={['alert-title text-sm leading-tight font-medium', '$preset', klass]}
|
|
41
|
+
class={['alert-title border-border text-sm leading-tight font-medium', '$preset', klass]}
|
|
42
42
|
onmount={onmount?.bind(bond.state)}
|
|
43
43
|
ondestroy={ondestroy?.bind(bond.state)}
|
|
44
44
|
animate={animate?.bind(bond.state)}
|
|
@@ -1,217 +1,201 @@
|
|
|
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, ComponentBase, HtmlAtomProps, SnippetBase } from './types';
|
|
4
|
-
import { RootBond } from '../root';
|
|
5
|
-
import { HtmlElement } from '../element';
|
|
6
|
-
import {
|
|
7
|
-
cn,
|
|
8
|
-
toClassValue,
|
|
9
|
-
type ClassValue,
|
|
10
|
-
type VariantDefinition
|
|
11
|
-
} from '../../utils';
|
|
12
|
-
import { getPreset } from '../../context';
|
|
13
|
-
import type { PresetModuleName } from '../../context/preset.svelte';
|
|
14
|
-
import type { Bond } from '../../shared';
|
|
15
|
-
|
|
16
|
-
type Element = HTMLElementTagNameMap[E];
|
|
17
|
-
|
|
18
|
-
const rootBond = RootBond.get();
|
|
19
|
-
|
|
20
|
-
let {
|
|
21
|
-
class: klass = '',
|
|
22
|
-
as = 'div',
|
|
23
|
-
base = undefined,
|
|
24
|
-
preset: presetKey = undefined,
|
|
25
|
-
bond = undefined,
|
|
26
|
-
variants = undefined,
|
|
27
|
-
children = undefined,
|
|
28
|
-
...restProps
|
|
29
|
-
}: HtmlAtomProps<E, B> & HTMLAttributes<Element> = $props();
|
|
30
|
-
|
|
31
|
-
const preset = $derived(
|
|
32
|
-
presetKey ? getPreset(presetKey as PresetModuleName)?.apply?.(bond, [bond]) : undefined
|
|
33
|
-
);
|
|
34
|
-
|
|
35
|
-
const presetProps = $derived(preset?.variants);
|
|
36
|
-
|
|
37
|
-
// Resolve local variants - either VariantDefinition or function
|
|
38
|
-
const localVariants = $derived.by(() => {
|
|
39
|
-
if (!variants) return undefined;
|
|
40
|
-
|
|
41
|
-
// If it's a function, call it directly
|
|
42
|
-
if (typeof variants === 'function') {
|
|
43
|
-
return variants(bond as Bond, restProps);
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
// Otherwise it's a VariantDefinition, resolve it
|
|
47
|
-
return resolveVariants(variants, bond as Bond, restProps);
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
// Merge preset variants with local variants
|
|
51
|
-
const mergedVariants = $derived.by(() => {
|
|
52
|
-
// No variants at all
|
|
53
|
-
if (!presetProps && !localVariants) return undefined;
|
|
54
|
-
|
|
55
|
-
// Only preset variants (raw object from preset)
|
|
56
|
-
if (presetProps && !localVariants) {
|
|
57
|
-
// Convert preset variants to VariantDefinition-like structure
|
|
58
|
-
const variantDef = {
|
|
59
|
-
class: preset?.class,
|
|
60
|
-
variants: presetProps,
|
|
61
|
-
compounds: preset?.compounds ?? [],
|
|
62
|
-
defaults: preset?.defaults ?? {}
|
|
63
|
-
};
|
|
64
|
-
return resolveVariants(variantDef, bond as Bond, restProps);
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
// Only local variants
|
|
68
|
-
if (!presetProps && localVariants) {
|
|
69
|
-
return localVariants;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
// Both exist - merge them
|
|
73
|
-
// When both preset and local variants exist, we need to merge the resolved props
|
|
74
|
-
const presetVariantDef = {
|
|
75
|
-
class: preset?.class,
|
|
76
|
-
variants: presetProps,
|
|
77
|
-
compounds: preset?.compounds ?? [],
|
|
78
|
-
defaults: preset?.defaults ?? {}
|
|
79
|
-
};
|
|
80
|
-
|
|
81
|
-
const presetResolved = resolveVariants(presetVariantDef, bond as Bond, restProps);
|
|
82
|
-
|
|
83
|
-
// Merge the resolved variant props
|
|
84
|
-
// Local variant classes and attributes override preset
|
|
85
|
-
const presetClasses = Array.isArray(presetResolved.class)
|
|
86
|
-
? presetResolved.class
|
|
87
|
-
: [presetResolved.class];
|
|
88
|
-
const localClasses = Array.isArray(localVariants?.class)
|
|
89
|
-
? localVariants.class
|
|
90
|
-
: [localVariants?.class];
|
|
91
|
-
|
|
92
|
-
return {
|
|
93
|
-
class: [...presetClasses, ...localClasses].filter(Boolean),
|
|
94
|
-
...presetResolved,
|
|
95
|
-
...localVariants
|
|
96
|
-
};
|
|
97
|
-
});
|
|
98
|
-
|
|
99
|
-
const _klass = $derived(
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
const
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
const
|
|
119
|
-
|
|
120
|
-
const
|
|
121
|
-
|
|
122
|
-
const
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
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
|
-
return {
|
|
205
|
-
class: classes,
|
|
206
|
-
...attributes
|
|
207
|
-
};
|
|
208
|
-
}
|
|
209
|
-
</script>
|
|
210
|
-
|
|
211
|
-
{#if isSnippet}
|
|
212
|
-
{@render snippet({ class: _klass, as: _as, base: _base, children, ..._restProps })}
|
|
213
|
-
{:else}
|
|
214
|
-
<Component class={_klass} as={_as} {..._restProps}>
|
|
215
|
-
{@render children?.()}
|
|
216
|
-
</Component>
|
|
217
|
-
{/if}
|
|
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, ComponentBase, HtmlAtomProps, SnippetBase } from './types';
|
|
4
|
+
import { RootBond } from '../root';
|
|
5
|
+
import { HtmlElement } from '../element';
|
|
6
|
+
import {
|
|
7
|
+
cn,
|
|
8
|
+
toClassValue,
|
|
9
|
+
type ClassValue,
|
|
10
|
+
type VariantDefinition
|
|
11
|
+
} from '../../utils';
|
|
12
|
+
import { getPreset } from '../../context';
|
|
13
|
+
import type { PresetModuleName } from '../../context/preset.svelte';
|
|
14
|
+
import type { Bond } from '../../shared';
|
|
15
|
+
|
|
16
|
+
type Element = HTMLElementTagNameMap[E];
|
|
17
|
+
|
|
18
|
+
const rootBond = RootBond.get();
|
|
19
|
+
|
|
20
|
+
let {
|
|
21
|
+
class: klass = '',
|
|
22
|
+
as = 'div',
|
|
23
|
+
base = undefined,
|
|
24
|
+
preset: presetKey = undefined,
|
|
25
|
+
bond = undefined,
|
|
26
|
+
variants = undefined,
|
|
27
|
+
children = undefined,
|
|
28
|
+
...restProps
|
|
29
|
+
}: HtmlAtomProps<E, B> & HTMLAttributes<Element> = $props();
|
|
30
|
+
|
|
31
|
+
const preset = $derived(
|
|
32
|
+
presetKey ? getPreset(presetKey as PresetModuleName)?.apply?.(bond, [bond]) : undefined
|
|
33
|
+
);
|
|
34
|
+
|
|
35
|
+
const presetProps = $derived(preset?.variants);
|
|
36
|
+
|
|
37
|
+
// Resolve local variants - either VariantDefinition or function
|
|
38
|
+
const localVariants = $derived.by(() => {
|
|
39
|
+
if (!variants) return undefined;
|
|
40
|
+
|
|
41
|
+
// If it's a function, call it directly
|
|
42
|
+
if (typeof variants === 'function') {
|
|
43
|
+
return variants(bond as Bond, restProps);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// Otherwise it's a VariantDefinition, resolve it
|
|
47
|
+
return resolveVariants(variants, bond as Bond, restProps);
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
// Merge preset variants with local variants
|
|
51
|
+
const mergedVariants = $derived.by(() => {
|
|
52
|
+
// No variants at all
|
|
53
|
+
if (!presetProps && !localVariants) return undefined;
|
|
54
|
+
|
|
55
|
+
// Only preset variants (raw object from preset)
|
|
56
|
+
if (presetProps && !localVariants) {
|
|
57
|
+
// Convert preset variants to VariantDefinition-like structure
|
|
58
|
+
const variantDef = {
|
|
59
|
+
class: preset?.class,
|
|
60
|
+
variants: presetProps,
|
|
61
|
+
compounds: preset?.compounds ?? [],
|
|
62
|
+
defaults: preset?.defaults ?? {}
|
|
63
|
+
};
|
|
64
|
+
return resolveVariants(variantDef, bond as Bond, restProps);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
// Only local variants
|
|
68
|
+
if (!presetProps && localVariants) {
|
|
69
|
+
return localVariants;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
// Both exist - merge them
|
|
73
|
+
// When both preset and local variants exist, we need to merge the resolved props
|
|
74
|
+
const presetVariantDef = {
|
|
75
|
+
class: preset?.class,
|
|
76
|
+
variants: presetProps,
|
|
77
|
+
compounds: preset?.compounds ?? [],
|
|
78
|
+
defaults: preset?.defaults ?? {}
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
const presetResolved = resolveVariants(presetVariantDef, bond as Bond, restProps);
|
|
82
|
+
|
|
83
|
+
// Merge the resolved variant props
|
|
84
|
+
// Local variant classes and attributes override preset
|
|
85
|
+
const presetClasses = Array.isArray(presetResolved.class)
|
|
86
|
+
? presetResolved.class
|
|
87
|
+
: [presetResolved.class];
|
|
88
|
+
const localClasses = Array.isArray(localVariants?.class)
|
|
89
|
+
? localVariants.class
|
|
90
|
+
: [localVariants?.class];
|
|
91
|
+
|
|
92
|
+
return {
|
|
93
|
+
class: [...presetClasses, ...localClasses].filter(Boolean),
|
|
94
|
+
...presetResolved,
|
|
95
|
+
...localVariants
|
|
96
|
+
};
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
const _klass = $derived(
|
|
100
|
+
cn(klass, mergedVariants?.class ?? '').replaceAll('$preset', cn(preset?.class))
|
|
101
|
+
);
|
|
102
|
+
|
|
103
|
+
const _base = $derived(base ?? preset?.base);
|
|
104
|
+
const _as = $derived(as ?? preset?.as);
|
|
105
|
+
const _restProps = $derived.by(() => {
|
|
106
|
+
const {
|
|
107
|
+
class: klassPreset,
|
|
108
|
+
base,
|
|
109
|
+
as,
|
|
110
|
+
variants: presetProps,
|
|
111
|
+
...restPresetProps
|
|
112
|
+
} = preset ?? {};
|
|
113
|
+
const { class: variantClass, ...variantsRestProps } = mergedVariants ?? {};
|
|
114
|
+
|
|
115
|
+
return { ...restPresetProps, ...variantsRestProps, ...restProps };
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
const isSnippet = $derived(typeof _base === 'function' && _base.length === 1 && !_base.prototype);
|
|
119
|
+
|
|
120
|
+
const snippet = $derived(_base as SnippetBase);
|
|
121
|
+
|
|
122
|
+
const atom = rootBond?.state?.props?.renderers?.html ?? HtmlElement;
|
|
123
|
+
|
|
124
|
+
const Component = $derived(base ?? atom) as ComponentBase;
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* Resolve variant definition to props
|
|
128
|
+
*/
|
|
129
|
+
function resolveVariants(
|
|
130
|
+
def: VariantDefinition<any>,
|
|
131
|
+
bond: Bond | null | undefined,
|
|
132
|
+
props: Record<string, any>
|
|
133
|
+
): Record<string, any> {
|
|
134
|
+
const { variants: variantMap, compounds, defaults, class: baseClass } = def;
|
|
135
|
+
|
|
136
|
+
// Merge props with defaults
|
|
137
|
+
const finalProps = { ...defaults, ...props };
|
|
138
|
+
|
|
139
|
+
const classes: ClassValue[] = [];
|
|
140
|
+
const attributes: Record<string, any> = {};
|
|
141
|
+
|
|
142
|
+
// Add base class
|
|
143
|
+
if (baseClass) classes.push(baseClass);
|
|
144
|
+
|
|
145
|
+
// Add variant classes
|
|
146
|
+
if (variantMap) {
|
|
147
|
+
for (const [key, value] of Object.entries(finalProps)) {
|
|
148
|
+
const variantValue = variantMap[key]?.[value as string];
|
|
149
|
+
if (variantValue !== undefined) {
|
|
150
|
+
const resolved = typeof variantValue === 'function' ? variantValue(bond) : variantValue;
|
|
151
|
+
|
|
152
|
+
if (typeof resolved === 'string') {
|
|
153
|
+
classes.push(resolved);
|
|
154
|
+
} else if (typeof resolved === 'object' && resolved !== null) {
|
|
155
|
+
if ('class' in resolved) {
|
|
156
|
+
classes.push(resolved.class);
|
|
157
|
+
}
|
|
158
|
+
// Add other attributes
|
|
159
|
+
Object.entries(resolved).forEach(([k, v]) => {
|
|
160
|
+
if (k !== 'class') {
|
|
161
|
+
attributes[k] = v;
|
|
162
|
+
}
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
// Add compound variants
|
|
170
|
+
if (compounds) {
|
|
171
|
+
for (const compound of compounds) {
|
|
172
|
+
const { class: compoundClass, ...compoundProps } = compound;
|
|
173
|
+
const matches = Object.entries(compoundProps).every(
|
|
174
|
+
([key, value]) => finalProps[key] === value
|
|
175
|
+
);
|
|
176
|
+
if (matches) {
|
|
177
|
+
if (compoundClass) classes.push(compoundClass);
|
|
178
|
+
// Add compound attributes
|
|
179
|
+
Object.entries(compound).forEach(([k, v]) => {
|
|
180
|
+
if (k !== 'class' && !Object.keys(compoundProps).includes(k)) {
|
|
181
|
+
attributes[k] = v;
|
|
182
|
+
}
|
|
183
|
+
});
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
return {
|
|
189
|
+
class: classes,
|
|
190
|
+
...attributes
|
|
191
|
+
};
|
|
192
|
+
}
|
|
193
|
+
</script>
|
|
194
|
+
|
|
195
|
+
{#if isSnippet}
|
|
196
|
+
{@render snippet({ class: _klass, as: _as, base: _base, children, ..._restProps })}
|
|
197
|
+
{:else}
|
|
198
|
+
<Component class={_klass} as={_as} {..._restProps}>
|
|
199
|
+
{@render children?.()}
|
|
200
|
+
</Component>
|
|
201
|
+
{/if}
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
<HtmlAtom
|
|
9
9
|
preset="badge"
|
|
10
10
|
class={[
|
|
11
|
-
'bg-foreground/10 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 items-center rounded-full px-2.5 py-0.5 text-xs font-medium',
|
|
12
12
|
'$preset',
|
|
13
13
|
klass
|
|
14
14
|
]}
|